1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40#include <linux/ctype.h>
41#include <linux/init.h>
42#include <linux/module.h>
43#include <linux/moduleparam.h>
44#include <linux/spinlock.h>
45#include <scsi/scsi.h>
46#include <scsi/scsi_tcq.h>
47#include <scsi/scsi_device.h>
48#include <scsi/scsi_transport.h>
49
50#include "sym_glue.h"
51#include "sym_nvram.h"
52
53#define NAME53C "sym53c"
54#define NAME53C8XX "sym53c8xx"
55
56struct sym_driver_setup sym_driver_setup = SYM_LINUX_DRIVER_SETUP;
57unsigned int sym_debug_flags = 0;
58
59static char *excl_string;
60static char *safe_string;
61module_param_named(cmd_per_lun, sym_driver_setup.max_tag, ushort, 0);
62module_param_named(burst, sym_driver_setup.burst_order, byte, 0);
63module_param_named(led, sym_driver_setup.scsi_led, byte, 0);
64module_param_named(diff, sym_driver_setup.scsi_diff, byte, 0);
65module_param_named(irqm, sym_driver_setup.irq_mode, byte, 0);
66module_param_named(buschk, sym_driver_setup.scsi_bus_check, byte, 0);
67module_param_named(hostid, sym_driver_setup.host_id, byte, 0);
68module_param_named(verb, sym_driver_setup.verbose, byte, 0);
69module_param_named(debug, sym_debug_flags, uint, 0);
70module_param_named(settle, sym_driver_setup.settle_delay, byte, 0);
71module_param_named(nvram, sym_driver_setup.use_nvram, byte, 0);
72module_param_named(excl, excl_string, charp, 0);
73module_param_named(safe, safe_string, charp, 0);
74
75MODULE_PARM_DESC(cmd_per_lun, "The maximum number of tags to use by default");
76MODULE_PARM_DESC(burst, "Maximum burst. 0 to disable, 255 to read from registers");
77MODULE_PARM_DESC(led, "Set to 1 to enable LED support");
78MODULE_PARM_DESC(diff, "0 for no differential mode, 1 for BIOS, 2 for always, 3 for not GPIO3");
79MODULE_PARM_DESC(irqm, "0 for open drain, 1 to leave alone, 2 for totem pole");
80MODULE_PARM_DESC(buschk, "0 to not check, 1 for detach on error, 2 for warn on error");
81MODULE_PARM_DESC(hostid, "The SCSI ID to use for the host adapters");
82MODULE_PARM_DESC(verb, "0 for minimal verbosity, 1 for normal, 2 for excessive");
83MODULE_PARM_DESC(debug, "Set bits to enable debugging");
84MODULE_PARM_DESC(settle, "Settle delay in seconds. Default 3");
85MODULE_PARM_DESC(nvram, "Option currently not used");
86MODULE_PARM_DESC(excl, "List ioport addresses here to prevent controllers from being attached");
87MODULE_PARM_DESC(safe, "Set other settings to a \"safe mode\"");
88
89MODULE_LICENSE("GPL");
90MODULE_VERSION(SYM_VERSION);
91MODULE_AUTHOR("Matthew Wilcox <matthew@wil.cx>");
92MODULE_DESCRIPTION("NCR, Symbios and LSI 8xx and 1010 PCI SCSI adapters");
93
94static void sym2_setup_params(void)
95{
96 char *p = excl_string;
97 int xi = 0;
98
99 while (p && (xi < 8)) {
100 char *next_p;
101 int val = (int) simple_strtoul(p, &next_p, 0);
102 sym_driver_setup.excludes[xi++] = val;
103 p = next_p;
104 }
105
106 if (safe_string) {
107 if (*safe_string == 'y') {
108 sym_driver_setup.max_tag = 0;
109 sym_driver_setup.burst_order = 0;
110 sym_driver_setup.scsi_led = 0;
111 sym_driver_setup.scsi_diff = 1;
112 sym_driver_setup.irq_mode = 0;
113 sym_driver_setup.scsi_bus_check = 2;
114 sym_driver_setup.host_id = 7;
115 sym_driver_setup.verbose = 2;
116 sym_driver_setup.settle_delay = 10;
117 sym_driver_setup.use_nvram = 1;
118 } else if (*safe_string != 'n') {
119 printk(KERN_WARNING NAME53C8XX "Ignoring parameter %s"
120 " passed to safe option", safe_string);
121 }
122 }
123}
124
125static struct scsi_transport_template *sym2_transport_template = NULL;
126
127
128
129
130struct sym_ucmd {
131 struct completion *eh_done;
132};
133
134#define SYM_UCMD_PTR(cmd) ((struct sym_ucmd *)(&(cmd)->SCp))
135#define SYM_SOFTC_PTR(cmd) sym_get_hcb(cmd->device->host)
136
137
138
139
140void sym_xpt_done(struct sym_hcb *np, struct scsi_cmnd *cmd)
141{
142 struct sym_ucmd *ucmd = SYM_UCMD_PTR(cmd);
143 BUILD_BUG_ON(sizeof(struct scsi_pointer) < sizeof(struct sym_ucmd));
144
145 if (ucmd->eh_done)
146 complete(ucmd->eh_done);
147
148 scsi_dma_unmap(cmd);
149 cmd->scsi_done(cmd);
150}
151
152
153
154
155void sym_xpt_async_bus_reset(struct sym_hcb *np)
156{
157 printf_notice("%s: SCSI BUS has been reset.\n", sym_name(np));
158 np->s.settle_time = jiffies + sym_driver_setup.settle_delay * HZ;
159 np->s.settle_time_valid = 1;
160 if (sym_verbose >= 2)
161 printf_info("%s: command processing suspended for %d seconds\n",
162 sym_name(np), sym_driver_setup.settle_delay);
163}
164
165
166
167
168
169static int sym_xerr_cam_status(int cam_status, int x_status)
170{
171 if (x_status) {
172 if (x_status & XE_PARITY_ERR)
173 cam_status = DID_PARITY;
174 else if (x_status &(XE_EXTRA_DATA|XE_SODL_UNRUN|XE_SWIDE_OVRUN))
175 cam_status = DID_ERROR;
176 else if (x_status & XE_BAD_PHASE)
177 cam_status = DID_ERROR;
178 else
179 cam_status = DID_ERROR;
180 }
181 return cam_status;
182}
183
184
185
186
187void sym_set_cam_result_error(struct sym_hcb *np, struct sym_ccb *cp, int resid)
188{
189 struct scsi_cmnd *cmd = cp->cmd;
190 u_int cam_status, scsi_status, drv_status;
191
192 drv_status = 0;
193 cam_status = DID_OK;
194 scsi_status = cp->ssss_status;
195
196 if (cp->host_flags & HF_SENSE) {
197 scsi_status = cp->sv_scsi_status;
198 resid = cp->sv_resid;
199 if (sym_verbose && cp->sv_xerr_status)
200 sym_print_xerr(cmd, cp->sv_xerr_status);
201 if (cp->host_status == HS_COMPLETE &&
202 cp->ssss_status == S_GOOD &&
203 cp->xerr_status == 0) {
204 cam_status = sym_xerr_cam_status(DID_OK,
205 cp->sv_xerr_status);
206 drv_status = DRIVER_SENSE;
207
208
209
210 memset(cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
211 memcpy(cmd->sense_buffer, cp->sns_bbuf,
212 min(SCSI_SENSE_BUFFERSIZE, SYM_SNS_BBUF_LEN));
213#if 0
214
215
216
217
218
219 if (1) {
220 u_char *p;
221 p = (u_char *) cmd->sense_data;
222 if (p[0]==0x70 && p[2]==0x6 && p[12]==0x29)
223 sym_clear_tasks(np, DID_ABORT,
224 cp->target,cp->lun, -1);
225 }
226#endif
227 } else {
228
229
230
231
232
233
234 sym_reset_scsi_target(np, cmd->device->id);
235 cam_status = DID_ERROR;
236 }
237 } else if (cp->host_status == HS_COMPLETE)
238 cam_status = DID_OK;
239 else if (cp->host_status == HS_SEL_TIMEOUT)
240 cam_status = DID_NO_CONNECT;
241 else if (cp->host_status == HS_UNEXPECTED)
242 cam_status = DID_ERROR;
243 else {
244 if (sym_verbose) {
245 sym_print_addr(cmd, "COMMAND FAILED (%x %x %x).\n",
246 cp->host_status, cp->ssss_status,
247 cp->xerr_status);
248 }
249
250
251
252 cam_status = sym_xerr_cam_status(DID_ERROR, cp->xerr_status);
253 }
254 scsi_set_resid(cmd, resid);
255 cmd->result = (drv_status << 24) | (cam_status << 16) | scsi_status;
256}
257
258static int sym_scatter(struct sym_hcb *np, struct sym_ccb *cp, struct scsi_cmnd *cmd)
259{
260 int segment;
261 int use_sg;
262
263 cp->data_len = 0;
264
265 use_sg = scsi_dma_map(cmd);
266 if (use_sg > 0) {
267 struct scatterlist *sg;
268 struct sym_tcb *tp = &np->target[cp->target];
269 struct sym_tblmove *data;
270
271 if (use_sg > SYM_CONF_MAX_SG) {
272 scsi_dma_unmap(cmd);
273 return -1;
274 }
275
276 data = &cp->phys.data[SYM_CONF_MAX_SG - use_sg];
277
278 scsi_for_each_sg(cmd, sg, use_sg, segment) {
279 dma_addr_t baddr = sg_dma_address(sg);
280 unsigned int len = sg_dma_len(sg);
281
282 if ((len & 1) && (tp->head.wval & EWS)) {
283 len++;
284 cp->odd_byte_adjustment++;
285 }
286
287 sym_build_sge(np, &data[segment], baddr, len);
288 cp->data_len += len;
289 }
290 } else {
291 segment = -2;
292 }
293
294 return segment;
295}
296
297
298
299
300static int sym_queue_command(struct sym_hcb *np, struct scsi_cmnd *cmd)
301{
302 struct scsi_device *sdev = cmd->device;
303 struct sym_tcb *tp;
304 struct sym_lcb *lp;
305 struct sym_ccb *cp;
306 int order;
307
308
309
310
311 tp = &np->target[sdev->id];
312
313
314
315
316 lp = sym_lp(tp, sdev->lun);
317 order = (lp && lp->s.reqtags) ? M_SIMPLE_TAG : 0;
318
319
320
321
322 cp = sym_get_ccb(np, cmd, order);
323 if (!cp)
324 return 1;
325 sym_queue_scsiio(np, cmd, cp);
326 return 0;
327}
328
329
330
331
332static inline int sym_setup_cdb(struct sym_hcb *np, struct scsi_cmnd *cmd, struct sym_ccb *cp)
333{
334 memcpy(cp->cdb_buf, cmd->cmnd, cmd->cmd_len);
335
336 cp->phys.cmd.addr = CCB_BA(cp, cdb_buf[0]);
337 cp->phys.cmd.size = cpu_to_scr(cmd->cmd_len);
338
339 return 0;
340}
341
342
343
344
345int sym_setup_data_and_start(struct sym_hcb *np, struct scsi_cmnd *cmd, struct sym_ccb *cp)
346{
347 u32 lastp, goalp;
348 int dir;
349
350
351
352
353 if (sym_setup_cdb(np, cmd, cp))
354 goto out_abort;
355
356
357
358
359 dir = cmd->sc_data_direction;
360 if (dir != DMA_NONE) {
361 cp->segments = sym_scatter(np, cp, cmd);
362 if (cp->segments < 0) {
363 sym_set_cam_status(cmd, DID_ERROR);
364 goto out_abort;
365 }
366
367
368
369
370 if (!cp->segments)
371 dir = DMA_NONE;
372 } else {
373 cp->data_len = 0;
374 cp->segments = 0;
375 }
376
377
378
379
380 switch (dir) {
381 case DMA_BIDIRECTIONAL:
382 scmd_printk(KERN_INFO, cmd, "got DMA_BIDIRECTIONAL command");
383 sym_set_cam_status(cmd, DID_ERROR);
384 goto out_abort;
385 case DMA_TO_DEVICE:
386 goalp = SCRIPTA_BA(np, data_out2) + 8;
387 lastp = goalp - 8 - (cp->segments * (2*4));
388 break;
389 case DMA_FROM_DEVICE:
390 cp->host_flags |= HF_DATA_IN;
391 goalp = SCRIPTA_BA(np, data_in2) + 8;
392 lastp = goalp - 8 - (cp->segments * (2*4));
393 break;
394 case DMA_NONE:
395 default:
396 lastp = goalp = SCRIPTB_BA(np, no_data);
397 break;
398 }
399
400
401
402
403 cp->phys.head.lastp = cpu_to_scr(lastp);
404 cp->phys.head.savep = cpu_to_scr(lastp);
405 cp->startp = cp->phys.head.savep;
406 cp->goalp = cpu_to_scr(goalp);
407
408
409
410
411
412
413
414#if 0
415 switch (cp->cdb_buf[0]) {
416 case 0x0A: case 0x2A: case 0xAA:
417 panic("XXXXXXXXXXXXX WRITE NOT YET ALLOWED XXXXXXXXXXXXXX\n");
418 break;
419 default:
420 break;
421 }
422#endif
423
424
425
426
427 sym_put_start_queue(np, cp);
428 return 0;
429
430out_abort:
431 sym_free_ccb(np, cp);
432 sym_xpt_done(np, cmd);
433 return 0;
434}
435
436
437
438
439
440
441
442
443static void sym_timer(struct sym_hcb *np)
444{
445 unsigned long thistime = jiffies;
446
447
448
449
450 np->s.timer.expires = thistime + SYM_CONF_TIMER_INTERVAL;
451 add_timer(&np->s.timer);
452
453
454
455
456
457 if (np->s.settle_time_valid) {
458 if (time_before_eq(np->s.settle_time, thistime)) {
459 if (sym_verbose >= 2 )
460 printk("%s: command processing resumed\n",
461 sym_name(np));
462 np->s.settle_time_valid = 0;
463 }
464 return;
465 }
466
467
468
469
470 if (np->s.lasttime + 4*HZ < thistime) {
471 np->s.lasttime = thistime;
472 }
473
474#ifdef SYM_CONF_PCIQ_MAY_MISS_COMPLETIONS
475
476
477
478
479
480
481
482
483 sym_wakeup_done(np);
484#endif
485}
486
487
488
489
490
491void sym_log_bus_error(struct Scsi_Host *shost)
492{
493 struct sym_data *sym_data = shost_priv(shost);
494 struct pci_dev *pdev = sym_data->pdev;
495 unsigned short pci_sts;
496 pci_read_config_word(pdev, PCI_STATUS, &pci_sts);
497 if (pci_sts & 0xf900) {
498 pci_write_config_word(pdev, PCI_STATUS, pci_sts);
499 shost_printk(KERN_WARNING, shost,
500 "PCI bus error: status = 0x%04x\n", pci_sts & 0xf900);
501 }
502}
503
504
505
506
507
508static int sym53c8xx_queue_command_lck(struct scsi_cmnd *cmd,
509 void (*done)(struct scsi_cmnd *))
510{
511 struct sym_hcb *np = SYM_SOFTC_PTR(cmd);
512 struct sym_ucmd *ucp = SYM_UCMD_PTR(cmd);
513 int sts = 0;
514
515 cmd->scsi_done = done;
516 memset(ucp, 0, sizeof(*ucp));
517
518
519
520
521
522 if (np->s.settle_time_valid && cmd->request->timeout) {
523 unsigned long tlimit = jiffies + cmd->request->timeout;
524 tlimit -= SYM_CONF_TIMER_INTERVAL*2;
525 if (time_after(np->s.settle_time, tlimit)) {
526 np->s.settle_time = tlimit;
527 }
528 }
529
530 if (np->s.settle_time_valid)
531 return SCSI_MLQUEUE_HOST_BUSY;
532
533 sts = sym_queue_command(np, cmd);
534 if (sts)
535 return SCSI_MLQUEUE_HOST_BUSY;
536 return 0;
537}
538
539static DEF_SCSI_QCMD(sym53c8xx_queue_command)
540
541
542
543
544static irqreturn_t sym53c8xx_intr(int irq, void *dev_id)
545{
546 struct Scsi_Host *shost = dev_id;
547 struct sym_data *sym_data = shost_priv(shost);
548 irqreturn_t result;
549
550
551 if (pci_channel_offline(sym_data->pdev))
552 return IRQ_NONE;
553
554 if (DEBUG_FLAGS & DEBUG_TINY) printf_debug ("[");
555
556 spin_lock(shost->host_lock);
557 result = sym_interrupt(shost);
558 spin_unlock(shost->host_lock);
559
560 if (DEBUG_FLAGS & DEBUG_TINY) printf_debug ("]\n");
561
562 return result;
563}
564
565
566
567
568static void sym53c8xx_timer(struct timer_list *t)
569{
570 struct sym_hcb *np = from_timer(np, t, s.timer);
571 unsigned long flags;
572
573 spin_lock_irqsave(np->s.host->host_lock, flags);
574 sym_timer(np);
575 spin_unlock_irqrestore(np->s.host->host_lock, flags);
576}
577
578
579
580
581
582#define SYM_EH_ABORT 0
583#define SYM_EH_DEVICE_RESET 1
584#define SYM_EH_BUS_RESET 2
585#define SYM_EH_HOST_RESET 3
586
587
588
589
590
591static int sym_eh_handler(int op, char *opname, struct scsi_cmnd *cmd)
592{
593 struct sym_ucmd *ucmd = SYM_UCMD_PTR(cmd);
594 struct Scsi_Host *shost = cmd->device->host;
595 struct sym_data *sym_data = shost_priv(shost);
596 struct pci_dev *pdev = sym_data->pdev;
597 struct sym_hcb *np = sym_data->ncb;
598 SYM_QUEHEAD *qp;
599 int cmd_queued = 0;
600 int sts = -1;
601 struct completion eh_done;
602
603 scmd_printk(KERN_WARNING, cmd, "%s operation started\n", opname);
604
605
606
607
608
609
610
611#define WAIT_FOR_PCI_RECOVERY 35
612 if (pci_channel_offline(pdev)) {
613 int finished_reset = 0;
614 init_completion(&eh_done);
615 spin_lock_irq(shost->host_lock);
616
617 if (pci_channel_offline(pdev)) {
618 BUG_ON(sym_data->io_reset);
619 sym_data->io_reset = &eh_done;
620 } else {
621 finished_reset = 1;
622 }
623 spin_unlock_irq(shost->host_lock);
624 if (!finished_reset)
625 finished_reset = wait_for_completion_timeout
626 (sym_data->io_reset,
627 WAIT_FOR_PCI_RECOVERY*HZ);
628 spin_lock_irq(shost->host_lock);
629 sym_data->io_reset = NULL;
630 spin_unlock_irq(shost->host_lock);
631 if (!finished_reset)
632 return SCSI_FAILED;
633 }
634
635 spin_lock_irq(shost->host_lock);
636
637 FOR_EACH_QUEUED_ELEMENT(&np->busy_ccbq, qp) {
638 struct sym_ccb *cp = sym_que_entry(qp, struct sym_ccb, link_ccbq);
639 if (cp->cmd == cmd) {
640 cmd_queued = 1;
641 break;
642 }
643 }
644
645
646 sts = -1;
647 switch(op) {
648 case SYM_EH_ABORT:
649 sts = sym_abort_scsiio(np, cmd, 1);
650 break;
651 case SYM_EH_DEVICE_RESET:
652 sts = sym_reset_scsi_target(np, cmd->device->id);
653 break;
654 case SYM_EH_BUS_RESET:
655 sym_reset_scsi_bus(np, 1);
656 sts = 0;
657 break;
658 case SYM_EH_HOST_RESET:
659 sym_reset_scsi_bus(np, 0);
660 sym_start_up(shost, 1);
661 sts = 0;
662 break;
663 default:
664 break;
665 }
666
667
668 if (sts)
669 cmd_queued = 0;
670
671 if (cmd_queued) {
672 init_completion(&eh_done);
673 ucmd->eh_done = &eh_done;
674 spin_unlock_irq(shost->host_lock);
675 if (!wait_for_completion_timeout(&eh_done, 5*HZ)) {
676 ucmd->eh_done = NULL;
677 sts = -2;
678 }
679 } else {
680 spin_unlock_irq(shost->host_lock);
681 }
682
683 dev_warn(&cmd->device->sdev_gendev, "%s operation %s.\n", opname,
684 sts==0 ? "complete" :sts==-2 ? "timed-out" : "failed");
685 return sts ? SCSI_FAILED : SCSI_SUCCESS;
686}
687
688
689
690
691
692static int sym53c8xx_eh_abort_handler(struct scsi_cmnd *cmd)
693{
694 return sym_eh_handler(SYM_EH_ABORT, "ABORT", cmd);
695}
696
697static int sym53c8xx_eh_device_reset_handler(struct scsi_cmnd *cmd)
698{
699 return sym_eh_handler(SYM_EH_DEVICE_RESET, "DEVICE RESET", cmd);
700}
701
702static int sym53c8xx_eh_bus_reset_handler(struct scsi_cmnd *cmd)
703{
704 return sym_eh_handler(SYM_EH_BUS_RESET, "BUS RESET", cmd);
705}
706
707static int sym53c8xx_eh_host_reset_handler(struct scsi_cmnd *cmd)
708{
709 return sym_eh_handler(SYM_EH_HOST_RESET, "HOST RESET", cmd);
710}
711
712
713
714
715static void sym_tune_dev_queuing(struct sym_tcb *tp, int lun, u_short reqtags)
716{
717 struct sym_lcb *lp = sym_lp(tp, lun);
718 u_short oldtags;
719
720 if (!lp)
721 return;
722
723 oldtags = lp->s.reqtags;
724
725 if (reqtags > lp->s.scdev_depth)
726 reqtags = lp->s.scdev_depth;
727
728 lp->s.reqtags = reqtags;
729
730 if (reqtags != oldtags) {
731 dev_info(&tp->starget->dev,
732 "tagged command queuing %s, command queue depth %d.\n",
733 lp->s.reqtags ? "enabled" : "disabled", reqtags);
734 }
735}
736
737static int sym53c8xx_slave_alloc(struct scsi_device *sdev)
738{
739 struct sym_hcb *np = sym_get_hcb(sdev->host);
740 struct sym_tcb *tp = &np->target[sdev->id];
741 struct sym_lcb *lp;
742 unsigned long flags;
743 int error;
744
745 if (sdev->id >= SYM_CONF_MAX_TARGET || sdev->lun >= SYM_CONF_MAX_LUN)
746 return -ENXIO;
747
748 spin_lock_irqsave(np->s.host->host_lock, flags);
749
750
751
752
753
754
755
756
757
758
759 if (tp->usrflags & SYM_SCAN_BOOT_DISABLED) {
760 tp->usrflags &= ~SYM_SCAN_BOOT_DISABLED;
761 starget_printk(KERN_INFO, sdev->sdev_target,
762 "Scan at boot disabled in NVRAM\n");
763 error = -ENXIO;
764 goto out;
765 }
766
767 if (tp->usrflags & SYM_SCAN_LUNS_DISABLED) {
768 if (sdev->lun != 0) {
769 error = -ENXIO;
770 goto out;
771 }
772 starget_printk(KERN_INFO, sdev->sdev_target,
773 "Multiple LUNs disabled in NVRAM\n");
774 }
775
776 lp = sym_alloc_lcb(np, sdev->id, sdev->lun);
777 if (!lp) {
778 error = -ENOMEM;
779 goto out;
780 }
781 if (tp->nlcb == 1)
782 tp->starget = sdev->sdev_target;
783
784 spi_min_period(tp->starget) = tp->usr_period;
785 spi_max_width(tp->starget) = tp->usr_width;
786
787 error = 0;
788out:
789 spin_unlock_irqrestore(np->s.host->host_lock, flags);
790
791 return error;
792}
793
794
795
796
797static int sym53c8xx_slave_configure(struct scsi_device *sdev)
798{
799 struct sym_hcb *np = sym_get_hcb(sdev->host);
800 struct sym_tcb *tp = &np->target[sdev->id];
801 struct sym_lcb *lp = sym_lp(tp, sdev->lun);
802 int reqtags, depth_to_use;
803
804
805
806
807 lp->curr_flags = lp->user_flags;
808
809
810
811
812
813
814
815 reqtags = sym_driver_setup.max_tag;
816 if (reqtags > tp->usrtags)
817 reqtags = tp->usrtags;
818 if (!sdev->tagged_supported)
819 reqtags = 0;
820 if (reqtags > SYM_CONF_MAX_TAG)
821 reqtags = SYM_CONF_MAX_TAG;
822 depth_to_use = reqtags ? reqtags : 1;
823 scsi_change_queue_depth(sdev, depth_to_use);
824 lp->s.scdev_depth = depth_to_use;
825 sym_tune_dev_queuing(tp, sdev->lun, reqtags);
826
827 if (!spi_initial_dv(sdev->sdev_target))
828 spi_dv_device(sdev);
829
830 return 0;
831}
832
833static void sym53c8xx_slave_destroy(struct scsi_device *sdev)
834{
835 struct sym_hcb *np = sym_get_hcb(sdev->host);
836 struct sym_tcb *tp = &np->target[sdev->id];
837 struct sym_lcb *lp = sym_lp(tp, sdev->lun);
838 unsigned long flags;
839
840
841 if (!lp)
842 return;
843
844 spin_lock_irqsave(np->s.host->host_lock, flags);
845
846 if (lp->busy_itlq || lp->busy_itl) {
847
848
849
850
851 starget_printk(KERN_WARNING, tp->starget,
852 "Removing busy LCB (%d)\n", (u8)sdev->lun);
853 sym_reset_scsi_bus(np, 1);
854 }
855
856 if (sym_free_lcb(np, sdev->id, sdev->lun) == 0) {
857
858
859
860 tp->head.sval = 0;
861 tp->head.wval = np->rv_scntl3;
862 tp->head.uval = 0;
863 tp->tgoal.check_nego = 1;
864 tp->starget = NULL;
865 }
866
867 spin_unlock_irqrestore(np->s.host->host_lock, flags);
868}
869
870
871
872
873static const char *sym53c8xx_info (struct Scsi_Host *host)
874{
875 return SYM_DRIVER_NAME;
876}
877
878
879#ifdef SYM_LINUX_PROC_INFO_SUPPORT
880
881
882
883
884
885
886
887
888
889#ifdef SYM_LINUX_USER_COMMAND_SUPPORT
890
891struct sym_usrcmd {
892 u_long target;
893 u_long lun;
894 u_long data;
895 u_long cmd;
896};
897
898#define UC_SETSYNC 10
899#define UC_SETTAGS 11
900#define UC_SETDEBUG 12
901#define UC_SETWIDE 14
902#define UC_SETFLAG 15
903#define UC_SETVERBOSE 17
904#define UC_RESETDEV 18
905#define UC_CLEARDEV 19
906
907static void sym_exec_user_command (struct sym_hcb *np, struct sym_usrcmd *uc)
908{
909 struct sym_tcb *tp;
910 int t, l;
911
912 switch (uc->cmd) {
913 case 0: return;
914
915#ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
916 case UC_SETDEBUG:
917 sym_debug_flags = uc->data;
918 break;
919#endif
920 case UC_SETVERBOSE:
921 np->verbose = uc->data;
922 break;
923 default:
924
925
926
927
928
929 for (t = 0; t < SYM_CONF_MAX_TARGET; t++) {
930 if (!((uc->target >> t) & 1))
931 continue;
932 tp = &np->target[t];
933 if (!tp->nlcb)
934 continue;
935
936 switch (uc->cmd) {
937
938 case UC_SETSYNC:
939 if (!uc->data || uc->data >= 255) {
940 tp->tgoal.iu = tp->tgoal.dt =
941 tp->tgoal.qas = 0;
942 tp->tgoal.offset = 0;
943 } else if (uc->data <= 9 && np->minsync_dt) {
944 if (uc->data < np->minsync_dt)
945 uc->data = np->minsync_dt;
946 tp->tgoal.iu = tp->tgoal.dt =
947 tp->tgoal.qas = 1;
948 tp->tgoal.width = 1;
949 tp->tgoal.period = uc->data;
950 tp->tgoal.offset = np->maxoffs_dt;
951 } else {
952 if (uc->data < np->minsync)
953 uc->data = np->minsync;
954 tp->tgoal.iu = tp->tgoal.dt =
955 tp->tgoal.qas = 0;
956 tp->tgoal.period = uc->data;
957 tp->tgoal.offset = np->maxoffs;
958 }
959 tp->tgoal.check_nego = 1;
960 break;
961 case UC_SETWIDE:
962 tp->tgoal.width = uc->data ? 1 : 0;
963 tp->tgoal.check_nego = 1;
964 break;
965 case UC_SETTAGS:
966 for (l = 0; l < SYM_CONF_MAX_LUN; l++)
967 sym_tune_dev_queuing(tp, l, uc->data);
968 break;
969 case UC_RESETDEV:
970 tp->to_reset = 1;
971 np->istat_sem = SEM;
972 OUTB(np, nc_istat, SIGP|SEM);
973 break;
974 case UC_CLEARDEV:
975 for (l = 0; l < SYM_CONF_MAX_LUN; l++) {
976 struct sym_lcb *lp = sym_lp(tp, l);
977 if (lp) lp->to_clear = 1;
978 }
979 np->istat_sem = SEM;
980 OUTB(np, nc_istat, SIGP|SEM);
981 break;
982 case UC_SETFLAG:
983 tp->usrflags = uc->data;
984 break;
985 }
986 }
987 break;
988 }
989}
990
991static int sym_skip_spaces(char *ptr, int len)
992{
993 int cnt, c;
994
995 for (cnt = len; cnt > 0 && (c = *ptr++) && isspace(c); cnt--);
996
997 return (len - cnt);
998}
999
1000static int get_int_arg(char *ptr, int len, u_long *pv)
1001{
1002 char *end;
1003
1004 *pv = simple_strtoul(ptr, &end, 10);
1005 return (end - ptr);
1006}
1007
1008static int is_keyword(char *ptr, int len, char *verb)
1009{
1010 int verb_len = strlen(verb);
1011
1012 if (len >= verb_len && !memcmp(verb, ptr, verb_len))
1013 return verb_len;
1014 else
1015 return 0;
1016}
1017
1018#define SKIP_SPACES(ptr, len) \
1019 if ((arg_len = sym_skip_spaces(ptr, len)) < 1) \
1020 return -EINVAL; \
1021 ptr += arg_len; len -= arg_len;
1022
1023#define GET_INT_ARG(ptr, len, v) \
1024 if (!(arg_len = get_int_arg(ptr, len, &(v)))) \
1025 return -EINVAL; \
1026 ptr += arg_len; len -= arg_len;
1027
1028
1029
1030
1031
1032
1033static int sym_user_command(struct Scsi_Host *shost, char *buffer, int length)
1034{
1035 struct sym_hcb *np = sym_get_hcb(shost);
1036 char *ptr = buffer;
1037 int len = length;
1038 struct sym_usrcmd cmd, *uc = &cmd;
1039 int arg_len;
1040 u_long target;
1041
1042 memset(uc, 0, sizeof(*uc));
1043
1044 if (len > 0 && ptr[len-1] == '\n')
1045 --len;
1046
1047 if ((arg_len = is_keyword(ptr, len, "setsync")) != 0)
1048 uc->cmd = UC_SETSYNC;
1049 else if ((arg_len = is_keyword(ptr, len, "settags")) != 0)
1050 uc->cmd = UC_SETTAGS;
1051 else if ((arg_len = is_keyword(ptr, len, "setverbose")) != 0)
1052 uc->cmd = UC_SETVERBOSE;
1053 else if ((arg_len = is_keyword(ptr, len, "setwide")) != 0)
1054 uc->cmd = UC_SETWIDE;
1055#ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
1056 else if ((arg_len = is_keyword(ptr, len, "setdebug")) != 0)
1057 uc->cmd = UC_SETDEBUG;
1058#endif
1059 else if ((arg_len = is_keyword(ptr, len, "setflag")) != 0)
1060 uc->cmd = UC_SETFLAG;
1061 else if ((arg_len = is_keyword(ptr, len, "resetdev")) != 0)
1062 uc->cmd = UC_RESETDEV;
1063 else if ((arg_len = is_keyword(ptr, len, "cleardev")) != 0)
1064 uc->cmd = UC_CLEARDEV;
1065 else
1066 arg_len = 0;
1067
1068#ifdef DEBUG_PROC_INFO
1069printk("sym_user_command: arg_len=%d, cmd=%ld\n", arg_len, uc->cmd);
1070#endif
1071
1072 if (!arg_len)
1073 return -EINVAL;
1074 ptr += arg_len; len -= arg_len;
1075
1076 switch(uc->cmd) {
1077 case UC_SETSYNC:
1078 case UC_SETTAGS:
1079 case UC_SETWIDE:
1080 case UC_SETFLAG:
1081 case UC_RESETDEV:
1082 case UC_CLEARDEV:
1083 SKIP_SPACES(ptr, len);
1084 if ((arg_len = is_keyword(ptr, len, "all")) != 0) {
1085 ptr += arg_len; len -= arg_len;
1086 uc->target = ~0;
1087 } else {
1088 GET_INT_ARG(ptr, len, target);
1089 uc->target = (1<<target);
1090#ifdef DEBUG_PROC_INFO
1091printk("sym_user_command: target=%ld\n", target);
1092#endif
1093 }
1094 break;
1095 }
1096
1097 switch(uc->cmd) {
1098 case UC_SETVERBOSE:
1099 case UC_SETSYNC:
1100 case UC_SETTAGS:
1101 case UC_SETWIDE:
1102 SKIP_SPACES(ptr, len);
1103 GET_INT_ARG(ptr, len, uc->data);
1104#ifdef DEBUG_PROC_INFO
1105printk("sym_user_command: data=%ld\n", uc->data);
1106#endif
1107 break;
1108#ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
1109 case UC_SETDEBUG:
1110 while (len > 0) {
1111 SKIP_SPACES(ptr, len);
1112 if ((arg_len = is_keyword(ptr, len, "alloc")))
1113 uc->data |= DEBUG_ALLOC;
1114 else if ((arg_len = is_keyword(ptr, len, "phase")))
1115 uc->data |= DEBUG_PHASE;
1116 else if ((arg_len = is_keyword(ptr, len, "queue")))
1117 uc->data |= DEBUG_QUEUE;
1118 else if ((arg_len = is_keyword(ptr, len, "result")))
1119 uc->data |= DEBUG_RESULT;
1120 else if ((arg_len = is_keyword(ptr, len, "scatter")))
1121 uc->data |= DEBUG_SCATTER;
1122 else if ((arg_len = is_keyword(ptr, len, "script")))
1123 uc->data |= DEBUG_SCRIPT;
1124 else if ((arg_len = is_keyword(ptr, len, "tiny")))
1125 uc->data |= DEBUG_TINY;
1126 else if ((arg_len = is_keyword(ptr, len, "timing")))
1127 uc->data |= DEBUG_TIMING;
1128 else if ((arg_len = is_keyword(ptr, len, "nego")))
1129 uc->data |= DEBUG_NEGO;
1130 else if ((arg_len = is_keyword(ptr, len, "tags")))
1131 uc->data |= DEBUG_TAGS;
1132 else if ((arg_len = is_keyword(ptr, len, "pointer")))
1133 uc->data |= DEBUG_POINTER;
1134 else
1135 return -EINVAL;
1136 ptr += arg_len; len -= arg_len;
1137 }
1138#ifdef DEBUG_PROC_INFO
1139printk("sym_user_command: data=%ld\n", uc->data);
1140#endif
1141 break;
1142#endif
1143 case UC_SETFLAG:
1144 while (len > 0) {
1145 SKIP_SPACES(ptr, len);
1146 if ((arg_len = is_keyword(ptr, len, "no_disc")))
1147 uc->data &= ~SYM_DISC_ENABLED;
1148 else
1149 return -EINVAL;
1150 ptr += arg_len; len -= arg_len;
1151 }
1152 break;
1153 default:
1154 break;
1155 }
1156
1157 if (len)
1158 return -EINVAL;
1159 else {
1160 unsigned long flags;
1161
1162 spin_lock_irqsave(shost->host_lock, flags);
1163 sym_exec_user_command(np, uc);
1164 spin_unlock_irqrestore(shost->host_lock, flags);
1165 }
1166 return length;
1167}
1168
1169#endif
1170
1171
1172
1173
1174
1175static int sym_show_info(struct seq_file *m, struct Scsi_Host *shost)
1176{
1177#ifdef SYM_LINUX_USER_INFO_SUPPORT
1178 struct sym_data *sym_data = shost_priv(shost);
1179 struct pci_dev *pdev = sym_data->pdev;
1180 struct sym_hcb *np = sym_data->ncb;
1181
1182 seq_printf(m, "Chip " NAME53C "%s, device id 0x%x, "
1183 "revision id 0x%x\n", np->s.chip_name,
1184 pdev->device, pdev->revision);
1185 seq_printf(m, "At PCI address %s, IRQ %u\n",
1186 pci_name(pdev), pdev->irq);
1187 seq_printf(m, "Min. period factor %d, %s SCSI BUS%s\n",
1188 (int) (np->minsync_dt ? np->minsync_dt : np->minsync),
1189 np->maxwide ? "Wide" : "Narrow",
1190 np->minsync_dt ? ", DT capable" : "");
1191
1192 seq_printf(m, "Max. started commands %d, "
1193 "max. commands per LUN %d\n",
1194 SYM_CONF_MAX_START, SYM_CONF_MAX_TAG);
1195
1196 return 0;
1197#else
1198 return -EINVAL;
1199#endif
1200}
1201
1202#endif
1203
1204
1205
1206
1207
1208
1209static void sym_iounmap_device(struct sym_device *device)
1210{
1211 if (device->s.ioaddr)
1212 pci_iounmap(device->pdev, device->s.ioaddr);
1213 if (device->s.ramaddr)
1214 pci_iounmap(device->pdev, device->s.ramaddr);
1215}
1216
1217
1218
1219
1220static void sym_free_resources(struct sym_hcb *np, struct pci_dev *pdev,
1221 int do_free_irq)
1222{
1223
1224
1225
1226 if (do_free_irq)
1227 free_irq(pdev->irq, np->s.host);
1228 if (np->s.ioaddr)
1229 pci_iounmap(pdev, np->s.ioaddr);
1230 if (np->s.ramaddr)
1231 pci_iounmap(pdev, np->s.ramaddr);
1232
1233
1234
1235 sym_hcb_free(np);
1236
1237 sym_mfree_dma(np, sizeof(*np), "HCB");
1238}
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249static struct Scsi_Host *sym_attach(struct scsi_host_template *tpnt, int unit,
1250 struct sym_device *dev)
1251{
1252 struct sym_data *sym_data;
1253 struct sym_hcb *np = NULL;
1254 struct Scsi_Host *shost = NULL;
1255 struct pci_dev *pdev = dev->pdev;
1256 unsigned long flags;
1257 struct sym_fw *fw;
1258 int do_free_irq = 0;
1259
1260 printk(KERN_INFO "sym%d: <%s> rev 0x%x at pci %s irq %u\n",
1261 unit, dev->chip.name, pdev->revision, pci_name(pdev),
1262 pdev->irq);
1263
1264
1265
1266
1267 fw = sym_find_firmware(&dev->chip);
1268 if (!fw)
1269 goto attach_failed;
1270
1271 shost = scsi_host_alloc(tpnt, sizeof(*sym_data));
1272 if (!shost)
1273 goto attach_failed;
1274 sym_data = shost_priv(shost);
1275
1276
1277
1278
1279
1280
1281
1282 np = __sym_calloc_dma(&pdev->dev, sizeof(*np), "HCB");
1283 if (!np)
1284 goto attach_failed;
1285 np->bus_dmat = &pdev->dev;
1286 sym_data->ncb = np;
1287 sym_data->pdev = pdev;
1288 np->s.host = shost;
1289
1290 pci_set_drvdata(pdev, shost);
1291
1292
1293
1294
1295 np->hcb_ba = vtobus(np);
1296 np->verbose = sym_driver_setup.verbose;
1297 np->s.unit = unit;
1298 np->features = dev->chip.features;
1299 np->clock_divn = dev->chip.nr_divisor;
1300 np->maxoffs = dev->chip.offset_max;
1301 np->maxburst = dev->chip.burst_max;
1302 np->myaddr = dev->host_id;
1303 np->mmio_ba = (u32)dev->mmio_base;
1304 np->ram_ba = (u32)dev->ram_base;
1305 np->s.ioaddr = dev->s.ioaddr;
1306 np->s.ramaddr = dev->s.ramaddr;
1307
1308
1309
1310
1311 strlcpy(np->s.chip_name, dev->chip.name, sizeof(np->s.chip_name));
1312 sprintf(np->s.inst_name, "sym%d", np->s.unit);
1313
1314 if ((SYM_CONF_DMA_ADDRESSING_MODE > 0) && (np->features & FE_DAC) &&
1315 !pci_set_dma_mask(pdev, DMA_DAC_MASK)) {
1316 set_dac(np);
1317 } else if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
1318 printf_warning("%s: No suitable DMA available\n", sym_name(np));
1319 goto attach_failed;
1320 }
1321
1322 if (sym_hcb_attach(shost, fw, dev->nvram))
1323 goto attach_failed;
1324
1325
1326
1327
1328
1329
1330 if (request_irq(pdev->irq, sym53c8xx_intr, IRQF_SHARED, NAME53C8XX,
1331 shost)) {
1332 printf_err("%s: request irq %u failure\n",
1333 sym_name(np), pdev->irq);
1334 goto attach_failed;
1335 }
1336 do_free_irq = 1;
1337
1338
1339
1340
1341
1342 spin_lock_irqsave(shost->host_lock, flags);
1343 if (sym_reset_scsi_bus(np, 0))
1344 goto reset_failed;
1345
1346
1347
1348
1349 sym_start_up(shost, 1);
1350
1351
1352
1353
1354 timer_setup(&np->s.timer, sym53c8xx_timer, 0);
1355 np->s.lasttime=0;
1356 sym_timer (np);
1357
1358
1359
1360
1361
1362 shost->max_channel = 0;
1363 shost->this_id = np->myaddr;
1364 shost->max_id = np->maxwide ? 16 : 8;
1365 shost->max_lun = SYM_CONF_MAX_LUN;
1366 shost->unique_id = pci_resource_start(pdev, 0);
1367 shost->cmd_per_lun = SYM_CONF_MAX_TAG;
1368 shost->can_queue = (SYM_CONF_MAX_START-2);
1369 shost->sg_tablesize = SYM_CONF_MAX_SG;
1370 shost->max_cmd_len = 16;
1371 BUG_ON(sym2_transport_template == NULL);
1372 shost->transportt = sym2_transport_template;
1373
1374
1375 if (pdev->device == PCI_DEVICE_ID_NCR_53C896 && pdev->revision < 2)
1376 shost->dma_boundary = 0xFFFFFF;
1377
1378 spin_unlock_irqrestore(shost->host_lock, flags);
1379
1380 return shost;
1381
1382 reset_failed:
1383 printf_err("%s: FATAL ERROR: CHECK SCSI BUS - CABLES, "
1384 "TERMINATION, DEVICE POWER etc.!\n", sym_name(np));
1385 spin_unlock_irqrestore(shost->host_lock, flags);
1386 attach_failed:
1387 printf_info("sym%d: giving up ...\n", unit);
1388 if (np)
1389 sym_free_resources(np, pdev, do_free_irq);
1390 else
1391 sym_iounmap_device(dev);
1392 if (shost)
1393 scsi_host_put(shost);
1394
1395 return NULL;
1396}
1397
1398
1399
1400
1401
1402#if SYM_CONF_NVRAM_SUPPORT
1403static void sym_get_nvram(struct sym_device *devp, struct sym_nvram *nvp)
1404{
1405 devp->nvram = nvp;
1406 nvp->type = 0;
1407
1408 sym_read_nvram(devp, nvp);
1409}
1410#else
1411static inline void sym_get_nvram(struct sym_device *devp, struct sym_nvram *nvp)
1412{
1413}
1414#endif
1415
1416static int sym_check_supported(struct sym_device *device)
1417{
1418 struct sym_chip *chip;
1419 struct pci_dev *pdev = device->pdev;
1420 unsigned long io_port = pci_resource_start(pdev, 0);
1421 int i;
1422
1423
1424
1425
1426
1427 if (io_port) {
1428 for (i = 0 ; i < 8 ; i++) {
1429 if (sym_driver_setup.excludes[i] == io_port)
1430 return -ENODEV;
1431 }
1432 }
1433
1434
1435
1436
1437
1438
1439 chip = sym_lookup_chip_table(pdev->device, pdev->revision);
1440 if (!chip) {
1441 dev_info(&pdev->dev, "device not supported\n");
1442 return -ENODEV;
1443 }
1444 memcpy(&device->chip, chip, sizeof(device->chip));
1445
1446 return 0;
1447}
1448
1449
1450
1451
1452
1453static int sym_check_raid(struct sym_device *device)
1454{
1455 unsigned int ram_size, ram_val;
1456
1457 if (!device->s.ramaddr)
1458 return 0;
1459
1460 if (device->chip.features & FE_RAM8K)
1461 ram_size = 8192;
1462 else
1463 ram_size = 4096;
1464
1465 ram_val = readl(device->s.ramaddr + ram_size - 16);
1466 if (ram_val != 0x52414944)
1467 return 0;
1468
1469 dev_info(&device->pdev->dev,
1470 "not initializing, driven by RAID controller.\n");
1471 return -ENODEV;
1472}
1473
1474static int sym_set_workarounds(struct sym_device *device)
1475{
1476 struct sym_chip *chip = &device->chip;
1477 struct pci_dev *pdev = device->pdev;
1478 u_short status_reg;
1479
1480
1481
1482
1483
1484
1485 if (pdev->device == PCI_DEVICE_ID_NCR_53C896 && pdev->revision < 0x4) {
1486 chip->features |= (FE_WRIE | FE_CLSE);
1487 }
1488
1489
1490 if (chip->features & FE_WRIE) {
1491 if (pci_set_mwi(pdev))
1492 return -ENODEV;
1493 }
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506 pci_read_config_word(pdev, PCI_STATUS, &status_reg);
1507 if (chip->features & FE_66MHZ) {
1508 if (!(status_reg & PCI_STATUS_66MHZ))
1509 chip->features &= ~FE_66MHZ;
1510 } else {
1511 if (status_reg & PCI_STATUS_66MHZ) {
1512 status_reg = PCI_STATUS_66MHZ;
1513 pci_write_config_word(pdev, PCI_STATUS, status_reg);
1514 pci_read_config_word(pdev, PCI_STATUS, &status_reg);
1515 }
1516 }
1517
1518 return 0;
1519}
1520
1521
1522
1523
1524static int sym_iomap_device(struct sym_device *device)
1525{
1526 struct pci_dev *pdev = device->pdev;
1527 struct pci_bus_region bus_addr;
1528 int i = 2;
1529
1530 pcibios_resource_to_bus(pdev->bus, &bus_addr, &pdev->resource[1]);
1531 device->mmio_base = bus_addr.start;
1532
1533 if (device->chip.features & FE_RAM) {
1534
1535
1536
1537
1538 if (!pdev->resource[i].flags)
1539 i++;
1540 pcibios_resource_to_bus(pdev->bus, &bus_addr,
1541 &pdev->resource[i]);
1542 device->ram_base = bus_addr.start;
1543 }
1544
1545#ifdef CONFIG_SCSI_SYM53C8XX_MMIO
1546 if (device->mmio_base)
1547 device->s.ioaddr = pci_iomap(pdev, 1,
1548 pci_resource_len(pdev, 1));
1549#endif
1550 if (!device->s.ioaddr)
1551 device->s.ioaddr = pci_iomap(pdev, 0,
1552 pci_resource_len(pdev, 0));
1553 if (!device->s.ioaddr) {
1554 dev_err(&pdev->dev, "could not map registers; giving up.\n");
1555 return -EIO;
1556 }
1557 if (device->ram_base) {
1558 device->s.ramaddr = pci_iomap(pdev, i,
1559 pci_resource_len(pdev, i));
1560 if (!device->s.ramaddr) {
1561 dev_warn(&pdev->dev,
1562 "could not map SRAM; continuing anyway.\n");
1563 device->ram_base = 0;
1564 }
1565 }
1566
1567 return 0;
1568}
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583static void sym_config_pqs(struct pci_dev *pdev, struct sym_device *sym_dev)
1584{
1585 int slot;
1586 u8 tmp;
1587
1588 for (slot = 0; slot < 256; slot++) {
1589 struct pci_dev *memc = pci_get_slot(pdev->bus, slot);
1590
1591 if (!memc || memc->vendor != 0x101a || memc->device == 0x0009) {
1592 pci_dev_put(memc);
1593 continue;
1594 }
1595
1596
1597 pci_read_config_byte(memc, 0x44, &tmp);
1598 if ((tmp & 0x2) == 0) {
1599 tmp |= 0x2;
1600 pci_write_config_byte(memc, 0x44, tmp);
1601 }
1602
1603
1604 pci_read_config_byte(memc, 0x45, &tmp);
1605 if ((tmp & 0x4) == 0) {
1606 tmp |= 0x4;
1607 pci_write_config_byte(memc, 0x45, tmp);
1608 }
1609
1610 pci_dev_put(memc);
1611 break;
1612 }
1613
1614 pci_read_config_byte(pdev, 0x84, &tmp);
1615 sym_dev->host_id = tmp;
1616}
1617
1618
1619
1620
1621
1622
1623static int sym_detach(struct Scsi_Host *shost, struct pci_dev *pdev)
1624{
1625 struct sym_hcb *np = sym_get_hcb(shost);
1626 printk("%s: detaching ...\n", sym_name(np));
1627
1628 del_timer_sync(&np->s.timer);
1629
1630
1631
1632
1633
1634
1635 printk("%s: resetting chip\n", sym_name(np));
1636 OUTB(np, nc_istat, SRST);
1637 INB(np, nc_mbox1);
1638 udelay(10);
1639 OUTB(np, nc_istat, 0);
1640
1641 sym_free_resources(np, pdev, 1);
1642 scsi_host_put(shost);
1643
1644 return 1;
1645}
1646
1647
1648
1649
1650static struct scsi_host_template sym2_template = {
1651 .module = THIS_MODULE,
1652 .name = "sym53c8xx",
1653 .info = sym53c8xx_info,
1654 .queuecommand = sym53c8xx_queue_command,
1655 .slave_alloc = sym53c8xx_slave_alloc,
1656 .slave_configure = sym53c8xx_slave_configure,
1657 .slave_destroy = sym53c8xx_slave_destroy,
1658 .eh_abort_handler = sym53c8xx_eh_abort_handler,
1659 .eh_device_reset_handler = sym53c8xx_eh_device_reset_handler,
1660 .eh_bus_reset_handler = sym53c8xx_eh_bus_reset_handler,
1661 .eh_host_reset_handler = sym53c8xx_eh_host_reset_handler,
1662 .this_id = 7,
1663 .use_clustering = ENABLE_CLUSTERING,
1664 .max_sectors = 0xFFFF,
1665#ifdef SYM_LINUX_PROC_INFO_SUPPORT
1666 .show_info = sym_show_info,
1667#ifdef SYM_LINUX_USER_COMMAND_SUPPORT
1668 .write_info = sym_user_command,
1669#endif
1670 .proc_name = NAME53C8XX,
1671#endif
1672};
1673
1674static int attach_count;
1675
1676static int sym2_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1677{
1678 struct sym_device sym_dev;
1679 struct sym_nvram nvram;
1680 struct Scsi_Host *shost;
1681 int do_iounmap = 0;
1682 int do_disable_device = 1;
1683
1684 memset(&sym_dev, 0, sizeof(sym_dev));
1685 memset(&nvram, 0, sizeof(nvram));
1686 sym_dev.pdev = pdev;
1687 sym_dev.host_id = SYM_SETUP_HOST_ID;
1688
1689 if (pci_enable_device(pdev))
1690 goto leave;
1691
1692 pci_set_master(pdev);
1693
1694 if (pci_request_regions(pdev, NAME53C8XX))
1695 goto disable;
1696
1697 if (sym_check_supported(&sym_dev))
1698 goto free;
1699
1700 if (sym_iomap_device(&sym_dev))
1701 goto free;
1702 do_iounmap = 1;
1703
1704 if (sym_check_raid(&sym_dev)) {
1705 do_disable_device = 0;
1706 goto free;
1707 }
1708
1709 if (sym_set_workarounds(&sym_dev))
1710 goto free;
1711
1712 sym_config_pqs(pdev, &sym_dev);
1713
1714 sym_get_nvram(&sym_dev, &nvram);
1715
1716 do_iounmap = 0;
1717 shost = sym_attach(&sym2_template, attach_count, &sym_dev);
1718 if (!shost)
1719 goto free;
1720
1721 if (scsi_add_host(shost, &pdev->dev))
1722 goto detach;
1723 scsi_scan_host(shost);
1724
1725 attach_count++;
1726
1727 return 0;
1728
1729 detach:
1730 sym_detach(pci_get_drvdata(pdev), pdev);
1731 free:
1732 if (do_iounmap)
1733 sym_iounmap_device(&sym_dev);
1734 pci_release_regions(pdev);
1735 disable:
1736 if (do_disable_device)
1737 pci_disable_device(pdev);
1738 leave:
1739 return -ENODEV;
1740}
1741
1742static void sym2_remove(struct pci_dev *pdev)
1743{
1744 struct Scsi_Host *shost = pci_get_drvdata(pdev);
1745
1746 scsi_remove_host(shost);
1747 sym_detach(shost, pdev);
1748 pci_release_regions(pdev);
1749 pci_disable_device(pdev);
1750
1751 attach_count--;
1752}
1753
1754
1755
1756
1757
1758
1759static pci_ers_result_t sym2_io_error_detected(struct pci_dev *pdev,
1760 enum pci_channel_state state)
1761{
1762
1763 if (state == pci_channel_io_perm_failure) {
1764 sym2_remove(pdev);
1765 return PCI_ERS_RESULT_DISCONNECT;
1766 }
1767
1768 disable_irq(pdev->irq);
1769 pci_disable_device(pdev);
1770
1771
1772 return PCI_ERS_RESULT_CAN_RECOVER;
1773}
1774
1775
1776
1777
1778
1779static pci_ers_result_t sym2_io_slot_dump(struct pci_dev *pdev)
1780{
1781 struct Scsi_Host *shost = pci_get_drvdata(pdev);
1782
1783 sym_dump_registers(shost);
1784
1785
1786 return PCI_ERS_RESULT_NEED_RESET;
1787}
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797static void sym2_reset_workarounds(struct pci_dev *pdev)
1798{
1799 u_short status_reg;
1800 struct sym_chip *chip;
1801
1802 chip = sym_lookup_chip_table(pdev->device, pdev->revision);
1803
1804
1805
1806
1807 pci_read_config_word(pdev, PCI_STATUS, &status_reg);
1808 if (!(chip->features & FE_66MHZ) && (status_reg & PCI_STATUS_66MHZ)) {
1809 status_reg = PCI_STATUS_66MHZ;
1810 pci_write_config_word(pdev, PCI_STATUS, status_reg);
1811 pci_read_config_word(pdev, PCI_STATUS, &status_reg);
1812 }
1813}
1814
1815
1816
1817
1818
1819
1820
1821static pci_ers_result_t sym2_io_slot_reset(struct pci_dev *pdev)
1822{
1823 struct Scsi_Host *shost = pci_get_drvdata(pdev);
1824 struct sym_hcb *np = sym_get_hcb(shost);
1825
1826 printk(KERN_INFO "%s: recovering from a PCI slot reset\n",
1827 sym_name(np));
1828
1829 if (pci_enable_device(pdev)) {
1830 printk(KERN_ERR "%s: Unable to enable after PCI reset\n",
1831 sym_name(np));
1832 return PCI_ERS_RESULT_DISCONNECT;
1833 }
1834
1835 pci_set_master(pdev);
1836 enable_irq(pdev->irq);
1837
1838
1839 if (np->features & FE_WRIE) {
1840 if (pci_set_mwi(pdev))
1841 return PCI_ERS_RESULT_DISCONNECT;
1842 }
1843
1844
1845 sym2_reset_workarounds(pdev);
1846
1847
1848 if (PCI_FUNC(pdev->devfn) == 0) {
1849 if (sym_reset_scsi_bus(np, 0)) {
1850 printk(KERN_ERR "%s: Unable to reset scsi host\n",
1851 sym_name(np));
1852 return PCI_ERS_RESULT_DISCONNECT;
1853 }
1854 sym_start_up(shost, 1);
1855 }
1856
1857 return PCI_ERS_RESULT_RECOVERED;
1858}
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868static void sym2_io_resume(struct pci_dev *pdev)
1869{
1870 struct Scsi_Host *shost = pci_get_drvdata(pdev);
1871 struct sym_data *sym_data = shost_priv(shost);
1872
1873 spin_lock_irq(shost->host_lock);
1874 if (sym_data->io_reset)
1875 complete(sym_data->io_reset);
1876 spin_unlock_irq(shost->host_lock);
1877}
1878
1879static void sym2_get_signalling(struct Scsi_Host *shost)
1880{
1881 struct sym_hcb *np = sym_get_hcb(shost);
1882 enum spi_signal_type type;
1883
1884 switch (np->scsi_mode) {
1885 case SMODE_SE:
1886 type = SPI_SIGNAL_SE;
1887 break;
1888 case SMODE_LVD:
1889 type = SPI_SIGNAL_LVD;
1890 break;
1891 case SMODE_HVD:
1892 type = SPI_SIGNAL_HVD;
1893 break;
1894 default:
1895 type = SPI_SIGNAL_UNKNOWN;
1896 break;
1897 }
1898 spi_signalling(shost) = type;
1899}
1900
1901static void sym2_set_offset(struct scsi_target *starget, int offset)
1902{
1903 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1904 struct sym_hcb *np = sym_get_hcb(shost);
1905 struct sym_tcb *tp = &np->target[starget->id];
1906
1907 tp->tgoal.offset = offset;
1908 tp->tgoal.check_nego = 1;
1909}
1910
1911static void sym2_set_period(struct scsi_target *starget, int period)
1912{
1913 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1914 struct sym_hcb *np = sym_get_hcb(shost);
1915 struct sym_tcb *tp = &np->target[starget->id];
1916
1917
1918
1919 if (period <= np->minsync && spi_width(starget))
1920 tp->tgoal.dt = 1;
1921
1922 tp->tgoal.period = period;
1923 tp->tgoal.check_nego = 1;
1924}
1925
1926static void sym2_set_width(struct scsi_target *starget, int width)
1927{
1928 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1929 struct sym_hcb *np = sym_get_hcb(shost);
1930 struct sym_tcb *tp = &np->target[starget->id];
1931
1932
1933
1934 if (width == 0)
1935 tp->tgoal.iu = tp->tgoal.dt = tp->tgoal.qas = 0;
1936
1937 tp->tgoal.width = width;
1938 tp->tgoal.check_nego = 1;
1939}
1940
1941static void sym2_set_dt(struct scsi_target *starget, int dt)
1942{
1943 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1944 struct sym_hcb *np = sym_get_hcb(shost);
1945 struct sym_tcb *tp = &np->target[starget->id];
1946
1947
1948 if (dt)
1949 tp->tgoal.dt = 1;
1950 else
1951 tp->tgoal.iu = tp->tgoal.dt = tp->tgoal.qas = 0;
1952 tp->tgoal.check_nego = 1;
1953}
1954
1955#if 0
1956static void sym2_set_iu(struct scsi_target *starget, int iu)
1957{
1958 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1959 struct sym_hcb *np = sym_get_hcb(shost);
1960 struct sym_tcb *tp = &np->target[starget->id];
1961
1962 if (iu)
1963 tp->tgoal.iu = tp->tgoal.dt = 1;
1964 else
1965 tp->tgoal.iu = 0;
1966 tp->tgoal.check_nego = 1;
1967}
1968
1969static void sym2_set_qas(struct scsi_target *starget, int qas)
1970{
1971 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1972 struct sym_hcb *np = sym_get_hcb(shost);
1973 struct sym_tcb *tp = &np->target[starget->id];
1974
1975 if (qas)
1976 tp->tgoal.dt = tp->tgoal.qas = 1;
1977 else
1978 tp->tgoal.qas = 0;
1979 tp->tgoal.check_nego = 1;
1980}
1981#endif
1982
1983static struct spi_function_template sym2_transport_functions = {
1984 .set_offset = sym2_set_offset,
1985 .show_offset = 1,
1986 .set_period = sym2_set_period,
1987 .show_period = 1,
1988 .set_width = sym2_set_width,
1989 .show_width = 1,
1990 .set_dt = sym2_set_dt,
1991 .show_dt = 1,
1992#if 0
1993 .set_iu = sym2_set_iu,
1994 .show_iu = 1,
1995 .set_qas = sym2_set_qas,
1996 .show_qas = 1,
1997#endif
1998 .get_signalling = sym2_get_signalling,
1999};
2000
2001static struct pci_device_id sym2_id_table[] = {
2002 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C810,
2003 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2004 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C820,
2005 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2006 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C825,
2007 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2008 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C815,
2009 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2010 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C810AP,
2011 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2012 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C860,
2013 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2014 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1510,
2015 PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_SCSI<<8, 0xffff00, 0UL },
2016 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C896,
2017 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2018 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C895,
2019 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2020 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C885,
2021 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2022 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C875,
2023 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2024 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C1510,
2025 PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_SCSI<<8, 0xffff00, 0UL },
2026 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C895A,
2027 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2028 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C875A,
2029 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2030 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1010_33,
2031 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2032 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1010_66,
2033 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2034 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C875J,
2035 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2036 { 0, }
2037};
2038
2039MODULE_DEVICE_TABLE(pci, sym2_id_table);
2040
2041static const struct pci_error_handlers sym2_err_handler = {
2042 .error_detected = sym2_io_error_detected,
2043 .mmio_enabled = sym2_io_slot_dump,
2044 .slot_reset = sym2_io_slot_reset,
2045 .resume = sym2_io_resume,
2046};
2047
2048static struct pci_driver sym2_driver = {
2049 .name = NAME53C8XX,
2050 .id_table = sym2_id_table,
2051 .probe = sym2_probe,
2052 .remove = sym2_remove,
2053 .err_handler = &sym2_err_handler,
2054};
2055
2056static int __init sym2_init(void)
2057{
2058 int error;
2059
2060 sym2_setup_params();
2061 sym2_transport_template = spi_attach_transport(&sym2_transport_functions);
2062 if (!sym2_transport_template)
2063 return -ENODEV;
2064
2065 error = pci_register_driver(&sym2_driver);
2066 if (error)
2067 spi_release_transport(sym2_transport_template);
2068 return error;
2069}
2070
2071static void __exit sym2_exit(void)
2072{
2073 pci_unregister_driver(&sym2_driver);
2074 spi_release_transport(sym2_transport_template);
2075}
2076
2077module_init(sym2_init);
2078module_exit(sym2_exit);
2079