2 * Device driver for the SYMBIOS/LSILOGIC 53C8XX and 53C1010 family
3 * of PCI-SCSI IO processors.
5 * Copyright (C) 1999-2001 Gerard Roudier <groudier@free.fr>
6 * Copyright (c) 2003-2005 Matthew Wilcox <matthew@wil.cx>
8 * This driver is derived from the Linux sym53c8xx driver.
9 * Copyright (C) 1998-2000 Gerard Roudier
11 * The sym53c8xx driver is derived from the ncr53c8xx driver that had been
12 * a port of the FreeBSD ncr driver to Linux-1.2.13.
14 * The original ncr driver has been written for 386bsd and FreeBSD by
15 * Wolfgang Stanglmeier <wolf@cologne.de>
16 * Stefan Esser <se@mi.Uni-Koeln.de>
17 * Copyright (C) 1994 Wolfgang Stanglmeier
19 * Other major contributions:
21 * NVRAM detection and reading.
22 * Copyright (C) 1997 Richard Waltham <dormouse@farsrobt.demon.co.uk>
24 *-----------------------------------------------------------------------------
26 * This program is free software; you can redistribute it and/or modify
27 * it under the terms of the GNU General Public License as published by
28 * the Free Software Foundation; either version 2 of the License, or
29 * (at your option) any later version.
31 * This program is distributed in the hope that it will be useful,
32 * but WITHOUT ANY WARRANTY; without even the implied warranty of
33 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 * GNU General Public License for more details.
36 * You should have received a copy of the GNU General Public License
37 * along with this program; if not, write to the Free Software
38 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
40 #include <linux/ctype.h>
41 #include <linux/init.h>
42 #include <linux/interrupt.h>
43 #include <linux/module.h>
44 #include <linux/moduleparam.h>
45 #include <linux/spinlock.h>
46 #include <scsi/scsi.h>
47 #include <scsi/scsi_tcq.h>
48 #include <scsi/scsi_device.h>
49 #include <scsi/scsi_transport.h>
52 #include "sym_nvram.h"
54 #define NAME53C "sym53c"
55 #define NAME53C8XX "sym53c8xx"
58 #define IRQ_PRM(x) (x)
60 struct sym_driver_setup sym_driver_setup = SYM_LINUX_DRIVER_SETUP;
61 unsigned int sym_debug_flags = 0;
63 static char *excl_string;
64 static char *safe_string;
65 module_param_named(cmd_per_lun, sym_driver_setup.max_tag, ushort, 0);
66 module_param_string(tag_ctrl, sym_driver_setup.tag_ctrl, 100, 0);
67 module_param_named(burst, sym_driver_setup.burst_order, byte, 0);
68 module_param_named(led, sym_driver_setup.scsi_led, byte, 0);
69 module_param_named(diff, sym_driver_setup.scsi_diff, byte, 0);
70 module_param_named(irqm, sym_driver_setup.irq_mode, byte, 0);
71 module_param_named(buschk, sym_driver_setup.scsi_bus_check, byte, 0);
72 module_param_named(hostid, sym_driver_setup.host_id, byte, 0);
73 module_param_named(verb, sym_driver_setup.verbose, byte, 0);
74 module_param_named(debug, sym_debug_flags, uint, 0);
75 module_param_named(settle, sym_driver_setup.settle_delay, byte, 0);
76 module_param_named(nvram, sym_driver_setup.use_nvram, byte, 0);
77 module_param_named(excl, excl_string, charp, 0);
78 module_param_named(safe, safe_string, charp, 0);
80 MODULE_PARM_DESC(cmd_per_lun, "The maximum number of tags to use by default");
81 MODULE_PARM_DESC(tag_ctrl, "More detailed control over tags per LUN");
82 MODULE_PARM_DESC(burst, "Maximum burst. 0 to disable, 255 to read from registers");
83 MODULE_PARM_DESC(led, "Set to 1 to enable LED support");
84 MODULE_PARM_DESC(diff, "0 for no differential mode, 1 for BIOS, 2 for always, 3 for not GPIO3");
85 MODULE_PARM_DESC(irqm, "0 for open drain, 1 to leave alone, 2 for totem pole");
86 MODULE_PARM_DESC(buschk, "0 to not check, 1 for detach on error, 2 for warn on error");
87 MODULE_PARM_DESC(hostid, "The SCSI ID to use for the host adapters");
88 MODULE_PARM_DESC(verb, "0 for minimal verbosity, 1 for normal, 2 for excessive");
89 MODULE_PARM_DESC(debug, "Set bits to enable debugging");
90 MODULE_PARM_DESC(settle, "Settle delay in seconds. Default 3");
91 MODULE_PARM_DESC(nvram, "Option currently not used");
92 MODULE_PARM_DESC(excl, "List ioport addresses here to prevent controllers from being attached");
93 MODULE_PARM_DESC(safe, "Set other settings to a \"safe mode\"");
95 MODULE_LICENSE("GPL");
96 MODULE_VERSION(SYM_VERSION);
97 MODULE_AUTHOR("Matthew Wilcox <matthew@wil.cx>");
98 MODULE_DESCRIPTION("NCR, Symbios and LSI 8xx and 1010 PCI SCSI adapters");
100 static void sym2_setup_params(void)
102 char *p = excl_string;
105 while (p && (xi < 8)) {
107 int val = (int) simple_strtoul(p, &next_p, 0);
108 sym_driver_setup.excludes[xi++] = val;
113 if (*safe_string == 'y') {
114 sym_driver_setup.max_tag = 0;
115 sym_driver_setup.burst_order = 0;
116 sym_driver_setup.scsi_led = 0;
117 sym_driver_setup.scsi_diff = 1;
118 sym_driver_setup.irq_mode = 0;
119 sym_driver_setup.scsi_bus_check = 2;
120 sym_driver_setup.host_id = 7;
121 sym_driver_setup.verbose = 2;
122 sym_driver_setup.settle_delay = 10;
123 sym_driver_setup.use_nvram = 1;
124 } else if (*safe_string != 'n') {
125 printk(KERN_WARNING NAME53C8XX "Ignoring parameter %s"
126 " passed to safe option", safe_string);
131 static struct scsi_transport_template *sym2_transport_template = NULL;
134 * Driver private area in the SCSI command structure.
136 struct sym_ucmd { /* Override the SCSI pointer structure */
137 unsigned char to_do; /* For error handling */
138 void (*old_done)(struct scsi_cmnd *); /* For error handling */
139 struct completion *eh_done; /* For error handling */
142 #define SYM_UCMD_PTR(cmd) ((struct sym_ucmd *)(&(cmd)->SCp))
143 #define SYM_SOFTC_PTR(cmd) sym_get_hcb(cmd->device->host)
146 * Complete a pending CAM CCB.
148 void sym_xpt_done(struct sym_hcb *np, struct scsi_cmnd *cmd)
154 static void sym_xpt_done2(struct sym_hcb *np, struct scsi_cmnd *cmd, int cam_status)
156 sym_set_cam_status(cmd, cam_status);
157 sym_xpt_done(np, cmd);
162 * Tell the SCSI layer about a BUS RESET.
164 void sym_xpt_async_bus_reset(struct sym_hcb *np)
166 printf_notice("%s: SCSI BUS has been reset.\n", sym_name(np));
167 np->s.settle_time = jiffies + sym_driver_setup.settle_delay * HZ;
168 np->s.settle_time_valid = 1;
169 if (sym_verbose >= 2)
170 printf_info("%s: command processing suspended for %d seconds\n",
171 sym_name(np), sym_driver_setup.settle_delay);
175 * Tell the SCSI layer about a BUS DEVICE RESET message sent.
177 void sym_xpt_async_sent_bdr(struct sym_hcb *np, int target)
179 printf_notice("%s: TARGET %d has been reset.\n", sym_name(np), target);
183 * Choose the more appropriate CAM status if
184 * the IO encountered an extended error.
186 static int sym_xerr_cam_status(int cam_status, int x_status)
189 if (x_status & XE_PARITY_ERR)
190 cam_status = DID_PARITY;
191 else if (x_status &(XE_EXTRA_DATA|XE_SODL_UNRUN|XE_SWIDE_OVRUN))
192 cam_status = DID_ERROR;
193 else if (x_status & XE_BAD_PHASE)
194 cam_status = DID_ERROR;
196 cam_status = DID_ERROR;
202 * Build CAM result for a failed or auto-sensed IO.
204 void sym_set_cam_result_error(struct sym_hcb *np, struct sym_ccb *cp, int resid)
206 struct scsi_cmnd *cmd = cp->cmd;
207 u_int cam_status, scsi_status, drv_status;
211 scsi_status = cp->ssss_status;
213 if (cp->host_flags & HF_SENSE) {
214 scsi_status = cp->sv_scsi_status;
215 resid = cp->sv_resid;
216 if (sym_verbose && cp->sv_xerr_status)
217 sym_print_xerr(cmd, cp->sv_xerr_status);
218 if (cp->host_status == HS_COMPLETE &&
219 cp->ssss_status == S_GOOD &&
220 cp->xerr_status == 0) {
221 cam_status = sym_xerr_cam_status(DID_OK,
223 drv_status = DRIVER_SENSE;
225 * Bounce back the sense data to user.
227 memset(&cmd->sense_buffer, 0, sizeof(cmd->sense_buffer));
228 memcpy(cmd->sense_buffer, cp->sns_bbuf,
229 min(sizeof(cmd->sense_buffer),
230 (size_t)SYM_SNS_BBUF_LEN));
233 * If the device reports a UNIT ATTENTION condition
234 * due to a RESET condition, we should consider all
235 * disconnect CCBs for this unit as aborted.
239 p = (u_char *) cmd->sense_data;
240 if (p[0]==0x70 && p[2]==0x6 && p[12]==0x29)
241 sym_clear_tasks(np, DID_ABORT,
242 cp->target,cp->lun, -1);
247 * Error return from our internal request sense. This
248 * is bad: we must clear the contingent allegiance
249 * condition otherwise the device will always return
250 * BUSY. Use a big stick.
252 sym_reset_scsi_target(np, cmd->device->id);
253 cam_status = DID_ERROR;
255 } else if (cp->host_status == HS_COMPLETE) /* Bad SCSI status */
257 else if (cp->host_status == HS_SEL_TIMEOUT) /* Selection timeout */
258 cam_status = DID_NO_CONNECT;
259 else if (cp->host_status == HS_UNEXPECTED) /* Unexpected BUS FREE*/
260 cam_status = DID_ERROR;
261 else { /* Extended error */
263 sym_print_addr(cmd, "COMMAND FAILED (%x %x %x).\n",
264 cp->host_status, cp->ssss_status,
268 * Set the most appropriate value for CAM status.
270 cam_status = sym_xerr_cam_status(DID_ERROR, cp->xerr_status);
272 scsi_set_resid(cmd, resid);
273 cmd->result = (drv_status << 24) + (cam_status << 16) + scsi_status;
276 static int sym_scatter(struct sym_hcb *np, struct sym_ccb *cp, struct scsi_cmnd *cmd)
283 use_sg = scsi_dma_map(cmd);
285 struct scatterlist *sg;
286 struct sym_tcb *tp = &np->target[cp->target];
287 struct sym_tblmove *data;
289 if (use_sg > SYM_CONF_MAX_SG) {
294 data = &cp->phys.data[SYM_CONF_MAX_SG - use_sg];
296 scsi_for_each_sg(cmd, sg, use_sg, segment) {
297 dma_addr_t baddr = sg_dma_address(sg);
298 unsigned int len = sg_dma_len(sg);
300 if ((len & 1) && (tp->head.wval & EWS)) {
302 cp->odd_byte_adjustment++;
305 sym_build_sge(np, &data[segment], baddr, len);
316 * Queue a SCSI command.
318 static int sym_queue_command(struct sym_hcb *np, struct scsi_cmnd *cmd)
320 struct scsi_device *sdev = cmd->device;
327 * Minimal checkings, so that we will not
328 * go outside our tables.
330 if (sdev->id == np->myaddr) {
331 sym_xpt_done2(np, cmd, DID_NO_CONNECT);
336 * Retrieve the target descriptor.
338 tp = &np->target[sdev->id];
341 * Select tagged/untagged.
343 lp = sym_lp(tp, sdev->lun);
344 order = (lp && lp->s.reqtags) ? M_SIMPLE_TAG : 0;
349 cp = sym_get_ccb(np, cmd, order);
351 return 1; /* Means resource shortage */
352 sym_queue_scsiio(np, cmd, cp);
357 * Setup buffers and pointers that address the CDB.
359 static inline int sym_setup_cdb(struct sym_hcb *np, struct scsi_cmnd *cmd, struct sym_ccb *cp)
361 memcpy(cp->cdb_buf, cmd->cmnd, cmd->cmd_len);
363 cp->phys.cmd.addr = CCB_BA(cp, cdb_buf[0]);
364 cp->phys.cmd.size = cpu_to_scr(cmd->cmd_len);
370 * Setup pointers that address the data and start the I/O.
372 int sym_setup_data_and_start(struct sym_hcb *np, struct scsi_cmnd *cmd, struct sym_ccb *cp)
380 if (sym_setup_cdb(np, cmd, cp))
384 * No direction means no data.
386 dir = cmd->sc_data_direction;
387 if (dir != DMA_NONE) {
388 cp->segments = sym_scatter(np, cp, cmd);
389 if (cp->segments < 0) {
390 sym_set_cam_status(cmd, DID_ERROR);
395 * No segments means no data.
405 * Set the data pointer.
408 case DMA_BIDIRECTIONAL:
409 printk("%s: got DMA_BIDIRECTIONAL command", sym_name(np));
410 sym_set_cam_status(cmd, DID_ERROR);
413 goalp = SCRIPTA_BA(np, data_out2) + 8;
414 lastp = goalp - 8 - (cp->segments * (2*4));
416 case DMA_FROM_DEVICE:
417 cp->host_flags |= HF_DATA_IN;
418 goalp = SCRIPTA_BA(np, data_in2) + 8;
419 lastp = goalp - 8 - (cp->segments * (2*4));
423 lastp = goalp = SCRIPTB_BA(np, no_data);
428 * Set all pointers values needed by SCRIPTS.
430 cp->phys.head.lastp = cpu_to_scr(lastp);
431 cp->phys.head.savep = cpu_to_scr(lastp);
432 cp->startp = cp->phys.head.savep;
433 cp->goalp = cpu_to_scr(goalp);
436 * When `#ifed 1', the code below makes the driver
437 * panic on the first attempt to write to a SCSI device.
438 * It is the first test we want to do after a driver
439 * change that does not seem obviously safe. :)
442 switch (cp->cdb_buf[0]) {
443 case 0x0A: case 0x2A: case 0xAA:
444 panic("XXXXXXXXXXXXX WRITE NOT YET ALLOWED XXXXXXXXXXXXXX\n");
454 sym_put_start_queue(np, cp);
458 sym_free_ccb(np, cp);
459 sym_xpt_done(np, cmd);
467 * Misused to keep the driver running when
468 * interrupts are not configured correctly.
470 static void sym_timer(struct sym_hcb *np)
472 unsigned long thistime = jiffies;
477 np->s.timer.expires = thistime + SYM_CONF_TIMER_INTERVAL;
478 add_timer(&np->s.timer);
481 * If we are resetting the ncr, wait for settle_time before
482 * clearing it. Then command processing will be resumed.
484 if (np->s.settle_time_valid) {
485 if (time_before_eq(np->s.settle_time, thistime)) {
486 if (sym_verbose >= 2 )
487 printk("%s: command processing resumed\n",
489 np->s.settle_time_valid = 0;
495 * Nothing to do for now, but that may come.
497 if (np->s.lasttime + 4*HZ < thistime) {
498 np->s.lasttime = thistime;
501 #ifdef SYM_CONF_PCIQ_MAY_MISS_COMPLETIONS
503 * Some way-broken PCI bridges may lead to
504 * completions being lost when the clearing
505 * of the INTFLY flag by the CPU occurs
506 * concurrently with the chip raising this flag.
507 * If this ever happen, lost completions will
516 * PCI BUS error handler.
518 void sym_log_bus_error(struct sym_hcb *np)
521 pci_read_config_word(np->s.device, PCI_STATUS, &pci_sts);
522 if (pci_sts & 0xf900) {
523 pci_write_config_word(np->s.device, PCI_STATUS, pci_sts);
524 printf("%s: PCI STATUS = 0x%04x\n",
525 sym_name(np), pci_sts & 0xf900);
530 * queuecommand method. Entered with the host adapter lock held and
531 * interrupts disabled.
533 static int sym53c8xx_queue_command(struct scsi_cmnd *cmd,
534 void (*done)(struct scsi_cmnd *))
536 struct sym_hcb *np = SYM_SOFTC_PTR(cmd);
537 struct sym_ucmd *ucp = SYM_UCMD_PTR(cmd);
540 cmd->scsi_done = done;
541 memset(ucp, 0, sizeof(*ucp));
544 * Shorten our settle_time if needed for
545 * this command not to time out.
547 if (np->s.settle_time_valid && cmd->timeout_per_command) {
548 unsigned long tlimit = jiffies + cmd->timeout_per_command;
549 tlimit -= SYM_CONF_TIMER_INTERVAL*2;
550 if (time_after(np->s.settle_time, tlimit)) {
551 np->s.settle_time = tlimit;
555 if (np->s.settle_time_valid)
556 return SCSI_MLQUEUE_HOST_BUSY;
558 sts = sym_queue_command(np, cmd);
560 return SCSI_MLQUEUE_HOST_BUSY;
565 * Linux entry point of the interrupt handler.
567 static irqreturn_t sym53c8xx_intr(int irq, void *dev_id)
570 struct sym_hcb *np = (struct sym_hcb *)dev_id;
572 if (DEBUG_FLAGS & DEBUG_TINY) printf_debug ("[");
574 spin_lock_irqsave(np->s.host->host_lock, flags);
576 spin_unlock_irqrestore(np->s.host->host_lock, flags);
578 if (DEBUG_FLAGS & DEBUG_TINY) printf_debug ("]\n");
584 * Linux entry point of the timer handler
586 static void sym53c8xx_timer(unsigned long npref)
588 struct sym_hcb *np = (struct sym_hcb *)npref;
591 spin_lock_irqsave(np->s.host->host_lock, flags);
593 spin_unlock_irqrestore(np->s.host->host_lock, flags);
598 * What the eh thread wants us to perform.
600 #define SYM_EH_ABORT 0
601 #define SYM_EH_DEVICE_RESET 1
602 #define SYM_EH_BUS_RESET 2
603 #define SYM_EH_HOST_RESET 3
606 * What we will do regarding the involved SCSI command.
608 #define SYM_EH_DO_IGNORE 0
609 #define SYM_EH_DO_WAIT 2
612 * scsi_done() alias when error recovery is in progress.
614 static void sym_eh_done(struct scsi_cmnd *cmd)
616 struct sym_ucmd *ucmd = SYM_UCMD_PTR(cmd);
617 BUILD_BUG_ON(sizeof(struct scsi_pointer) < sizeof(struct sym_ucmd));
619 cmd->scsi_done = ucmd->old_done;
621 if (ucmd->to_do == SYM_EH_DO_WAIT)
622 complete(ucmd->eh_done);
626 * Generic method for our eh processing.
627 * The 'op' argument tells what we have to do.
629 static int sym_eh_handler(int op, char *opname, struct scsi_cmnd *cmd)
631 struct sym_hcb *np = SYM_SOFTC_PTR(cmd);
632 struct sym_ucmd *ucmd = SYM_UCMD_PTR(cmd);
633 struct Scsi_Host *host = cmd->device->host;
635 int to_do = SYM_EH_DO_IGNORE;
637 struct completion eh_done;
639 dev_warn(&cmd->device->sdev_gendev, "%s operation started.\n", opname);
641 spin_lock_irq(host->host_lock);
642 /* This one is queued in some place -> to wait for completion */
643 FOR_EACH_QUEUED_ELEMENT(&np->busy_ccbq, qp) {
644 struct sym_ccb *cp = sym_que_entry(qp, struct sym_ccb, link_ccbq);
645 if (cp->cmd == cmd) {
646 to_do = SYM_EH_DO_WAIT;
651 if (to_do == SYM_EH_DO_WAIT) {
652 init_completion(&eh_done);
653 ucmd->old_done = cmd->scsi_done;
654 ucmd->eh_done = &eh_done;
656 cmd->scsi_done = sym_eh_done;
659 /* Try to proceed the operation we have been asked for */
663 sts = sym_abort_scsiio(np, cmd, 1);
665 case SYM_EH_DEVICE_RESET:
666 sts = sym_reset_scsi_target(np, cmd->device->id);
668 case SYM_EH_BUS_RESET:
669 sym_reset_scsi_bus(np, 1);
672 case SYM_EH_HOST_RESET:
673 sym_reset_scsi_bus(np, 0);
674 sym_start_up (np, 1);
681 /* On error, restore everything and cross fingers :) */
683 cmd->scsi_done = ucmd->old_done;
684 to_do = SYM_EH_DO_IGNORE;
688 spin_unlock_irq(host->host_lock);
690 if (to_do == SYM_EH_DO_WAIT) {
691 if (!wait_for_completion_timeout(&eh_done, 5*HZ)) {
692 ucmd->to_do = SYM_EH_DO_IGNORE;
697 dev_warn(&cmd->device->sdev_gendev, "%s operation %s.\n", opname,
698 sts==0 ? "complete" :sts==-2 ? "timed-out" : "failed");
699 return sts ? SCSI_FAILED : SCSI_SUCCESS;
704 * Error handlers called from the eh thread (one thread per HBA).
706 static int sym53c8xx_eh_abort_handler(struct scsi_cmnd *cmd)
708 return sym_eh_handler(SYM_EH_ABORT, "ABORT", cmd);
711 static int sym53c8xx_eh_device_reset_handler(struct scsi_cmnd *cmd)
713 return sym_eh_handler(SYM_EH_DEVICE_RESET, "DEVICE RESET", cmd);
716 static int sym53c8xx_eh_bus_reset_handler(struct scsi_cmnd *cmd)
718 return sym_eh_handler(SYM_EH_BUS_RESET, "BUS RESET", cmd);
721 static int sym53c8xx_eh_host_reset_handler(struct scsi_cmnd *cmd)
723 return sym_eh_handler(SYM_EH_HOST_RESET, "HOST RESET", cmd);
727 * Tune device queuing depth, according to various limits.
729 static void sym_tune_dev_queuing(struct sym_tcb *tp, int lun, u_short reqtags)
731 struct sym_lcb *lp = sym_lp(tp, lun);
737 oldtags = lp->s.reqtags;
739 if (reqtags > lp->s.scdev_depth)
740 reqtags = lp->s.scdev_depth;
742 lp->s.reqtags = reqtags;
744 if (reqtags != oldtags) {
745 dev_info(&tp->starget->dev,
746 "tagged command queuing %s, command queue depth %d.\n",
747 lp->s.reqtags ? "enabled" : "disabled", reqtags);
752 * Linux select queue depths function
754 #define DEF_DEPTH (sym_driver_setup.max_tag)
755 #define ALL_TARGETS -2
760 static int device_queue_depth(struct sym_hcb *np, int target, int lun)
763 char *p = sym_driver_setup.tag_ctrl;
769 while ((c = *p++) != 0) {
770 v = simple_strtoul(p, &ep, 0);
779 t = (target == v) ? v : NO_TARGET;
784 u = (lun == v) ? v : NO_LUN;
787 if (h == np->s.unit &&
788 (t == ALL_TARGETS || t == target) &&
789 (u == ALL_LUNS || u == lun))
804 static int sym53c8xx_slave_alloc(struct scsi_device *sdev)
806 struct sym_hcb *np = sym_get_hcb(sdev->host);
807 struct sym_tcb *tp = &np->target[sdev->id];
810 if (sdev->id >= SYM_CONF_MAX_TARGET || sdev->lun >= SYM_CONF_MAX_LUN)
813 tp->starget = sdev->sdev_target;
815 * Fail the device init if the device is flagged NOSCAN at BOOT in
816 * the NVRAM. This may speed up boot and maintain coherency with
817 * BIOS device numbering. Clearing the flag allows the user to
818 * rescan skipped devices later. We also return an error for
819 * devices not flagged for SCAN LUNS in the NVRAM since some single
820 * lun devices behave badly when asked for a non zero LUN.
823 if (tp->usrflags & SYM_SCAN_BOOT_DISABLED) {
824 tp->usrflags &= ~SYM_SCAN_BOOT_DISABLED;
825 starget_printk(KERN_INFO, tp->starget,
826 "Scan at boot disabled in NVRAM\n");
830 if (tp->usrflags & SYM_SCAN_LUNS_DISABLED) {
833 starget_printk(KERN_INFO, tp->starget,
834 "Multiple LUNs disabled in NVRAM\n");
837 lp = sym_alloc_lcb(np, sdev->id, sdev->lun);
841 spi_min_period(tp->starget) = tp->usr_period;
842 spi_max_width(tp->starget) = tp->usr_width;
848 * Linux entry point for device queue sizing.
850 static int sym53c8xx_slave_configure(struct scsi_device *sdev)
852 struct sym_hcb *np = sym_get_hcb(sdev->host);
853 struct sym_tcb *tp = &np->target[sdev->id];
854 struct sym_lcb *lp = sym_lp(tp, sdev->lun);
855 int reqtags, depth_to_use;
860 lp->curr_flags = lp->user_flags;
863 * Select queue depth from driver setup.
864 * Donnot use more than configured by user.
866 * Donnot use more than our maximum.
868 reqtags = device_queue_depth(np, sdev->id, sdev->lun);
869 if (reqtags > tp->usrtags)
870 reqtags = tp->usrtags;
871 if (!sdev->tagged_supported)
873 #if 1 /* Avoid to locally queue commands for no good reasons */
874 if (reqtags > SYM_CONF_MAX_TAG)
875 reqtags = SYM_CONF_MAX_TAG;
876 depth_to_use = (reqtags ? reqtags : 2);
878 depth_to_use = (reqtags ? SYM_CONF_MAX_TAG : 2);
880 scsi_adjust_queue_depth(sdev,
881 (sdev->tagged_supported ?
884 lp->s.scdev_depth = depth_to_use;
885 sym_tune_dev_queuing(tp, sdev->lun, reqtags);
887 if (!spi_initial_dv(sdev->sdev_target))
893 static void sym53c8xx_slave_destroy(struct scsi_device *sdev)
895 struct sym_hcb *np = sym_get_hcb(sdev->host);
896 struct sym_lcb *lp = sym_lp(&np->target[sdev->id], sdev->lun);
899 sym_mfree_dma(lp->itlq_tbl, SYM_CONF_MAX_TASK * 4, "ITLQ_TBL");
901 sym_mfree_dma(lp, sizeof(*lp), "LCB");
905 * Linux entry point for info() function
907 static const char *sym53c8xx_info (struct Scsi_Host *host)
909 return SYM_DRIVER_NAME;
913 #ifdef SYM_LINUX_PROC_INFO_SUPPORT
915 * Proc file system stuff
917 * A read operation returns adapter information.
918 * A write operation is a control command.
919 * The string is parsed in the driver code and the command is passed
920 * to the sym_usercmd() function.
923 #ifdef SYM_LINUX_USER_COMMAND_SUPPORT
932 #define UC_SETSYNC 10
933 #define UC_SETTAGS 11
934 #define UC_SETDEBUG 12
935 #define UC_SETWIDE 14
936 #define UC_SETFLAG 15
937 #define UC_SETVERBOSE 17
938 #define UC_RESETDEV 18
939 #define UC_CLEARDEV 19
941 static void sym_exec_user_command (struct sym_hcb *np, struct sym_usrcmd *uc)
949 #ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
951 sym_debug_flags = uc->data;
955 np->verbose = uc->data;
959 * We assume that other commands apply to targets.
960 * This should always be the case and avoid the below
961 * 4 lines to be repeated 6 times.
963 for (t = 0; t < SYM_CONF_MAX_TARGET; t++) {
964 if (!((uc->target >> t) & 1))
971 if (!uc->data || uc->data >= 255) {
972 tp->tgoal.iu = tp->tgoal.dt =
974 tp->tgoal.offset = 0;
975 } else if (uc->data <= 9 && np->minsync_dt) {
976 if (uc->data < np->minsync_dt)
977 uc->data = np->minsync_dt;
978 tp->tgoal.iu = tp->tgoal.dt =
981 tp->tgoal.period = uc->data;
982 tp->tgoal.offset = np->maxoffs_dt;
984 if (uc->data < np->minsync)
985 uc->data = np->minsync;
986 tp->tgoal.iu = tp->tgoal.dt =
988 tp->tgoal.period = uc->data;
989 tp->tgoal.offset = np->maxoffs;
991 tp->tgoal.check_nego = 1;
994 tp->tgoal.width = uc->data ? 1 : 0;
995 tp->tgoal.check_nego = 1;
998 for (l = 0; l < SYM_CONF_MAX_LUN; l++)
999 sym_tune_dev_queuing(tp, l, uc->data);
1003 np->istat_sem = SEM;
1004 OUTB(np, nc_istat, SIGP|SEM);
1007 for (l = 0; l < SYM_CONF_MAX_LUN; l++) {
1008 struct sym_lcb *lp = sym_lp(tp, l);
1009 if (lp) lp->to_clear = 1;
1011 np->istat_sem = SEM;
1012 OUTB(np, nc_istat, SIGP|SEM);
1015 tp->usrflags = uc->data;
1023 static int skip_spaces(char *ptr, int len)
1027 for (cnt = len; cnt > 0 && (c = *ptr++) && isspace(c); cnt--);
1032 static int get_int_arg(char *ptr, int len, u_long *pv)
1036 *pv = simple_strtoul(ptr, &end, 10);
1040 static int is_keyword(char *ptr, int len, char *verb)
1042 int verb_len = strlen(verb);
1044 if (len >= verb_len && !memcmp(verb, ptr, verb_len))
1050 #define SKIP_SPACES(ptr, len) \
1051 if ((arg_len = skip_spaces(ptr, len)) < 1) \
1053 ptr += arg_len; len -= arg_len;
1055 #define GET_INT_ARG(ptr, len, v) \
1056 if (!(arg_len = get_int_arg(ptr, len, &(v)))) \
1058 ptr += arg_len; len -= arg_len;
1062 * Parse a control command
1065 static int sym_user_command(struct sym_hcb *np, char *buffer, int length)
1069 struct sym_usrcmd cmd, *uc = &cmd;
1073 memset(uc, 0, sizeof(*uc));
1075 if (len > 0 && ptr[len-1] == '\n')
1078 if ((arg_len = is_keyword(ptr, len, "setsync")) != 0)
1079 uc->cmd = UC_SETSYNC;
1080 else if ((arg_len = is_keyword(ptr, len, "settags")) != 0)
1081 uc->cmd = UC_SETTAGS;
1082 else if ((arg_len = is_keyword(ptr, len, "setverbose")) != 0)
1083 uc->cmd = UC_SETVERBOSE;
1084 else if ((arg_len = is_keyword(ptr, len, "setwide")) != 0)
1085 uc->cmd = UC_SETWIDE;
1086 #ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
1087 else if ((arg_len = is_keyword(ptr, len, "setdebug")) != 0)
1088 uc->cmd = UC_SETDEBUG;
1090 else if ((arg_len = is_keyword(ptr, len, "setflag")) != 0)
1091 uc->cmd = UC_SETFLAG;
1092 else if ((arg_len = is_keyword(ptr, len, "resetdev")) != 0)
1093 uc->cmd = UC_RESETDEV;
1094 else if ((arg_len = is_keyword(ptr, len, "cleardev")) != 0)
1095 uc->cmd = UC_CLEARDEV;
1099 #ifdef DEBUG_PROC_INFO
1100 printk("sym_user_command: arg_len=%d, cmd=%ld\n", arg_len, uc->cmd);
1105 ptr += arg_len; len -= arg_len;
1114 SKIP_SPACES(ptr, len);
1115 if ((arg_len = is_keyword(ptr, len, "all")) != 0) {
1116 ptr += arg_len; len -= arg_len;
1119 GET_INT_ARG(ptr, len, target);
1120 uc->target = (1<<target);
1121 #ifdef DEBUG_PROC_INFO
1122 printk("sym_user_command: target=%ld\n", target);
1133 SKIP_SPACES(ptr, len);
1134 GET_INT_ARG(ptr, len, uc->data);
1135 #ifdef DEBUG_PROC_INFO
1136 printk("sym_user_command: data=%ld\n", uc->data);
1139 #ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
1142 SKIP_SPACES(ptr, len);
1143 if ((arg_len = is_keyword(ptr, len, "alloc")))
1144 uc->data |= DEBUG_ALLOC;
1145 else if ((arg_len = is_keyword(ptr, len, "phase")))
1146 uc->data |= DEBUG_PHASE;
1147 else if ((arg_len = is_keyword(ptr, len, "queue")))
1148 uc->data |= DEBUG_QUEUE;
1149 else if ((arg_len = is_keyword(ptr, len, "result")))
1150 uc->data |= DEBUG_RESULT;
1151 else if ((arg_len = is_keyword(ptr, len, "scatter")))
1152 uc->data |= DEBUG_SCATTER;
1153 else if ((arg_len = is_keyword(ptr, len, "script")))
1154 uc->data |= DEBUG_SCRIPT;
1155 else if ((arg_len = is_keyword(ptr, len, "tiny")))
1156 uc->data |= DEBUG_TINY;
1157 else if ((arg_len = is_keyword(ptr, len, "timing")))
1158 uc->data |= DEBUG_TIMING;
1159 else if ((arg_len = is_keyword(ptr, len, "nego")))
1160 uc->data |= DEBUG_NEGO;
1161 else if ((arg_len = is_keyword(ptr, len, "tags")))
1162 uc->data |= DEBUG_TAGS;
1163 else if ((arg_len = is_keyword(ptr, len, "pointer")))
1164 uc->data |= DEBUG_POINTER;
1167 ptr += arg_len; len -= arg_len;
1169 #ifdef DEBUG_PROC_INFO
1170 printk("sym_user_command: data=%ld\n", uc->data);
1173 #endif /* SYM_LINUX_DEBUG_CONTROL_SUPPORT */
1176 SKIP_SPACES(ptr, len);
1177 if ((arg_len = is_keyword(ptr, len, "no_disc")))
1178 uc->data &= ~SYM_DISC_ENABLED;
1181 ptr += arg_len; len -= arg_len;
1191 unsigned long flags;
1193 spin_lock_irqsave(np->s.host->host_lock, flags);
1194 sym_exec_user_command (np, uc);
1195 spin_unlock_irqrestore(np->s.host->host_lock, flags);
1200 #endif /* SYM_LINUX_USER_COMMAND_SUPPORT */
1203 #ifdef SYM_LINUX_USER_INFO_SUPPORT
1205 * Informations through the proc file system.
1214 static void copy_mem_info(struct info_str *info, char *data, int len)
1216 if (info->pos + len > info->length)
1217 len = info->length - info->pos;
1219 if (info->pos + len < info->offset) {
1223 if (info->pos < info->offset) {
1224 data += (info->offset - info->pos);
1225 len -= (info->offset - info->pos);
1229 memcpy(info->buffer + info->pos, data, len);
1234 static int copy_info(struct info_str *info, char *fmt, ...)
1240 va_start(args, fmt);
1241 len = vsprintf(buf, fmt, args);
1244 copy_mem_info(info, buf, len);
1249 * Copy formatted information into the input buffer.
1251 static int sym_host_info(struct sym_hcb *np, char *ptr, off_t offset, int len)
1253 struct info_str info;
1257 info.offset = offset;
1260 copy_info(&info, "Chip " NAME53C "%s, device id 0x%x, "
1261 "revision id 0x%x\n",
1262 np->s.chip_name, np->device_id, np->revision_id);
1263 copy_info(&info, "At PCI address %s, IRQ " IRQ_FMT "\n",
1264 pci_name(np->s.device), IRQ_PRM(np->s.device->irq));
1265 copy_info(&info, "Min. period factor %d, %s SCSI BUS%s\n",
1266 (int) (np->minsync_dt ? np->minsync_dt : np->minsync),
1267 np->maxwide ? "Wide" : "Narrow",
1268 np->minsync_dt ? ", DT capable" : "");
1270 copy_info(&info, "Max. started commands %d, "
1271 "max. commands per LUN %d\n",
1272 SYM_CONF_MAX_START, SYM_CONF_MAX_TAG);
1274 return info.pos > info.offset? info.pos - info.offset : 0;
1276 #endif /* SYM_LINUX_USER_INFO_SUPPORT */
1279 * Entry point of the scsi proc fs of the driver.
1280 * - func = 0 means read (returns adapter infos)
1281 * - func = 1 means write (not yet merget from sym53c8xx)
1283 static int sym53c8xx_proc_info(struct Scsi_Host *host, char *buffer,
1284 char **start, off_t offset, int length, int func)
1286 struct sym_hcb *np = sym_get_hcb(host);
1290 #ifdef SYM_LINUX_USER_COMMAND_SUPPORT
1291 retv = sym_user_command(np, buffer, length);
1298 #ifdef SYM_LINUX_USER_INFO_SUPPORT
1299 retv = sym_host_info(np, buffer, offset, length);
1307 #endif /* SYM_LINUX_PROC_INFO_SUPPORT */
1310 * Free controller resources.
1312 static void sym_free_resources(struct sym_hcb *np, struct pci_dev *pdev)
1315 * Free O/S specific resources.
1318 free_irq(pdev->irq, np);
1320 pci_iounmap(pdev, np->s.ioaddr);
1322 pci_iounmap(pdev, np->s.ramaddr);
1324 * Free O/S independent resources.
1328 sym_mfree_dma(np, sizeof(*np), "HCB");
1332 * Ask/tell the system about DMA addressing.
1334 static int sym_setup_bus_dma_mask(struct sym_hcb *np)
1336 #if SYM_CONF_DMA_ADDRESSING_MODE > 0
1337 #if SYM_CONF_DMA_ADDRESSING_MODE == 1
1338 #define DMA_DAC_MASK DMA_40BIT_MASK
1339 #elif SYM_CONF_DMA_ADDRESSING_MODE == 2
1340 #define DMA_DAC_MASK DMA_64BIT_MASK
1342 if ((np->features & FE_DAC) &&
1343 !pci_set_dma_mask(np->s.device, DMA_DAC_MASK)) {
1349 if (!pci_set_dma_mask(np->s.device, DMA_32BIT_MASK))
1352 printf_warning("%s: No suitable DMA available\n", sym_name(np));
1357 * Host attach and initialisations.
1359 * Allocate host data and ncb structure.
1360 * Remap MMIO region.
1361 * Do chip initialization.
1362 * If all is OK, install interrupt handling and
1363 * start the timer daemon.
1365 static struct Scsi_Host * __devinit sym_attach(struct scsi_host_template *tpnt,
1366 int unit, struct sym_device *dev)
1368 struct host_data *host_data;
1369 struct sym_hcb *np = NULL;
1370 struct Scsi_Host *instance = NULL;
1371 struct pci_dev *pdev = dev->pdev;
1372 unsigned long flags;
1376 "sym%d: <%s> rev 0x%x at pci %s irq " IRQ_FMT "\n",
1377 unit, dev->chip.name, dev->chip.revision_id,
1378 pci_name(pdev), IRQ_PRM(pdev->irq));
1381 * Get the firmware for this chip.
1383 fw = sym_find_firmware(&dev->chip);
1388 * Allocate host_data structure
1390 instance = scsi_host_alloc(tpnt, sizeof(*host_data));
1393 host_data = (struct host_data *) instance->hostdata;
1396 * Allocate immediately the host control block,
1397 * since we are only expecting to succeed. :)
1398 * We keep track in the HCB of all the resources that
1399 * are to be released on error.
1401 np = __sym_calloc_dma(&pdev->dev, sizeof(*np), "HCB");
1404 np->s.device = pdev;
1405 np->bus_dmat = &pdev->dev; /* Result in 1 DMA pool per HBA */
1406 host_data->ncb = np;
1407 np->s.host = instance;
1409 pci_set_drvdata(pdev, np);
1412 * Copy some useful infos to the HCB.
1414 np->hcb_ba = vtobus(np);
1415 np->verbose = sym_driver_setup.verbose;
1416 np->s.device = pdev;
1418 np->device_id = dev->chip.device_id;
1419 np->revision_id = dev->chip.revision_id;
1420 np->features = dev->chip.features;
1421 np->clock_divn = dev->chip.nr_divisor;
1422 np->maxoffs = dev->chip.offset_max;
1423 np->maxburst = dev->chip.burst_max;
1424 np->myaddr = dev->host_id;
1429 strlcpy(np->s.chip_name, dev->chip.name, sizeof(np->s.chip_name));
1430 sprintf(np->s.inst_name, "sym%d", np->s.unit);
1432 if (sym_setup_bus_dma_mask(np))
1436 * Try to map the controller chip to
1437 * virtual and physical memory.
1439 np->mmio_ba = (u32)dev->mmio_base;
1440 np->s.ioaddr = dev->s.ioaddr;
1441 np->s.ramaddr = dev->s.ramaddr;
1442 np->s.io_ws = (np->features & FE_IO256) ? 256 : 128;
1445 * Map on-chip RAM if present and supported.
1447 if (!(np->features & FE_RAM))
1449 if (dev->ram_base) {
1450 np->ram_ba = (u32)dev->ram_base;
1451 np->ram_ws = (np->features & FE_RAM8K) ? 8192 : 4096;
1454 if (sym_hcb_attach(instance, fw, dev->nvram))
1458 * Install the interrupt handler.
1459 * If we synchonize the C code with SCRIPTS on interrupt,
1460 * we do not want to share the INTR line at all.
1462 if (request_irq(pdev->irq, sym53c8xx_intr, IRQF_SHARED, NAME53C8XX, np)) {
1463 printf_err("%s: request irq %d failure\n",
1464 sym_name(np), pdev->irq);
1469 * After SCSI devices have been opened, we cannot
1470 * reset the bus safely, so we do it here.
1472 spin_lock_irqsave(instance->host_lock, flags);
1473 if (sym_reset_scsi_bus(np, 0))
1477 * Start the SCRIPTS.
1479 sym_start_up (np, 1);
1482 * Start the timer daemon
1484 init_timer(&np->s.timer);
1485 np->s.timer.data = (unsigned long) np;
1486 np->s.timer.function = sym53c8xx_timer;
1491 * Fill Linux host instance structure
1492 * and return success.
1494 instance->max_channel = 0;
1495 instance->this_id = np->myaddr;
1496 instance->max_id = np->maxwide ? 16 : 8;
1497 instance->max_lun = SYM_CONF_MAX_LUN;
1498 instance->unique_id = pci_resource_start(pdev, 0);
1499 instance->cmd_per_lun = SYM_CONF_MAX_TAG;
1500 instance->can_queue = (SYM_CONF_MAX_START-2);
1501 instance->sg_tablesize = SYM_CONF_MAX_SG;
1502 instance->max_cmd_len = 16;
1503 BUG_ON(sym2_transport_template == NULL);
1504 instance->transportt = sym2_transport_template;
1506 /* 53c896 rev 1 errata: DMA may not cross 16MB boundary */
1507 if (pdev->device == PCI_DEVICE_ID_NCR_53C896 && np->revision_id < 2)
1508 instance->dma_boundary = 0xFFFFFF;
1510 spin_unlock_irqrestore(instance->host_lock, flags);
1515 printf_err("%s: FATAL ERROR: CHECK SCSI BUS - CABLES, "
1516 "TERMINATION, DEVICE POWER etc.!\n", sym_name(np));
1517 spin_unlock_irqrestore(instance->host_lock, flags);
1521 printf_info("%s: giving up ...\n", sym_name(np));
1523 sym_free_resources(np, pdev);
1524 scsi_host_put(instance);
1531 * Detect and try to read SYMBIOS and TEKRAM NVRAM.
1533 #if SYM_CONF_NVRAM_SUPPORT
1534 static void __devinit sym_get_nvram(struct sym_device *devp, struct sym_nvram *nvp)
1537 devp->device_id = devp->chip.device_id;
1540 sym_read_nvram(devp, nvp);
1543 static inline void sym_get_nvram(struct sym_device *devp, struct sym_nvram *nvp)
1546 #endif /* SYM_CONF_NVRAM_SUPPORT */
1548 static int __devinit sym_check_supported(struct sym_device *device)
1550 struct sym_chip *chip;
1551 struct pci_dev *pdev = device->pdev;
1553 unsigned long io_port = pci_resource_start(pdev, 0);
1557 * If user excluded this chip, do not initialize it.
1558 * I hate this code so much. Must kill it.
1561 for (i = 0 ; i < 8 ; i++) {
1562 if (sym_driver_setup.excludes[i] == io_port)
1568 * Check if the chip is supported. Then copy the chip description
1569 * to our device structure so we can make it match the actual device
1572 pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
1573 chip = sym_lookup_chip_table(pdev->device, revision);
1575 dev_info(&pdev->dev, "device not supported\n");
1578 memcpy(&device->chip, chip, sizeof(device->chip));
1579 device->chip.revision_id = revision;
1585 * Ignore Symbios chips controlled by various RAID controllers.
1586 * These controllers set value 0x52414944 at RAM end - 16.
1588 static int __devinit sym_check_raid(struct sym_device *device)
1590 unsigned int ram_size, ram_val;
1592 if (!device->s.ramaddr)
1595 if (device->chip.features & FE_RAM8K)
1600 ram_val = readl(device->s.ramaddr + ram_size - 16);
1601 if (ram_val != 0x52414944)
1604 dev_info(&device->pdev->dev,
1605 "not initializing, driven by RAID controller.\n");
1609 static int __devinit sym_set_workarounds(struct sym_device *device)
1611 struct sym_chip *chip = &device->chip;
1612 struct pci_dev *pdev = device->pdev;
1616 * (ITEM 12 of a DEL about the 896 I haven't yet).
1617 * We must ensure the chip will use WRITE AND INVALIDATE.
1618 * The revision number limit is for now arbitrary.
1620 if (pdev->device == PCI_DEVICE_ID_NCR_53C896 && chip->revision_id < 0x4) {
1621 chip->features |= (FE_WRIE | FE_CLSE);
1624 /* If the chip can do Memory Write Invalidate, enable it */
1625 if (chip->features & FE_WRIE) {
1626 if (pci_set_mwi(pdev))
1631 * Work around for errant bit in 895A. The 66Mhz
1632 * capable bit is set erroneously. Clear this bit.
1635 * Make sure Config space and Features agree.
1637 * Recall: writes are not normal to status register -
1638 * write a 1 to clear and a 0 to leave unchanged.
1639 * Can only reset bits.
1641 pci_read_config_word(pdev, PCI_STATUS, &status_reg);
1642 if (chip->features & FE_66MHZ) {
1643 if (!(status_reg & PCI_STATUS_66MHZ))
1644 chip->features &= ~FE_66MHZ;
1646 if (status_reg & PCI_STATUS_66MHZ) {
1647 status_reg = PCI_STATUS_66MHZ;
1648 pci_write_config_word(pdev, PCI_STATUS, status_reg);
1649 pci_read_config_word(pdev, PCI_STATUS, &status_reg);
1657 * Read and check the PCI configuration for any detected NCR
1658 * boards and save data for attaching after all boards have
1661 static void __devinit
1662 sym_init_device(struct pci_dev *pdev, struct sym_device *device)
1665 struct pci_bus_region bus_addr;
1667 device->host_id = SYM_SETUP_HOST_ID;
1668 device->pdev = pdev;
1670 pcibios_resource_to_bus(pdev, &bus_addr, &pdev->resource[1]);
1671 device->mmio_base = bus_addr.start;
1674 * If the BAR is 64-bit, resource 2 will be occupied by the
1677 if (!pdev->resource[i].flags)
1679 pcibios_resource_to_bus(pdev, &bus_addr, &pdev->resource[i]);
1680 device->ram_base = bus_addr.start;
1682 #ifdef CONFIG_SCSI_SYM53C8XX_MMIO
1683 if (device->mmio_base)
1684 device->s.ioaddr = pci_iomap(pdev, 1,
1685 pci_resource_len(pdev, 1));
1687 if (!device->s.ioaddr)
1688 device->s.ioaddr = pci_iomap(pdev, 0,
1689 pci_resource_len(pdev, 0));
1690 if (device->ram_base)
1691 device->s.ramaddr = pci_iomap(pdev, i,
1692 pci_resource_len(pdev, i));
1696 * The NCR PQS and PDS cards are constructed as a DEC bridge
1697 * behind which sits a proprietary NCR memory controller and
1698 * either four or two 53c875s as separate devices. We can tell
1699 * if an 875 is part of a PQS/PDS or not since if it is, it will
1700 * be on the same bus as the memory controller. In its usual
1701 * mode of operation, the 875s are slaved to the memory
1702 * controller for all transfers. To operate with the Linux
1703 * driver, the memory controller is disabled and the 875s
1704 * freed to function independently. The only wrinkle is that
1705 * the preset SCSI ID (which may be zero) must be read in from
1706 * a special configuration space register of the 875.
1708 static void sym_config_pqs(struct pci_dev *pdev, struct sym_device *sym_dev)
1713 for (slot = 0; slot < 256; slot++) {
1714 struct pci_dev *memc = pci_get_slot(pdev->bus, slot);
1716 if (!memc || memc->vendor != 0x101a || memc->device == 0x0009) {
1721 /* bit 1: allow individual 875 configuration */
1722 pci_read_config_byte(memc, 0x44, &tmp);
1723 if ((tmp & 0x2) == 0) {
1725 pci_write_config_byte(memc, 0x44, tmp);
1728 /* bit 2: drive individual 875 interrupts to the bus */
1729 pci_read_config_byte(memc, 0x45, &tmp);
1730 if ((tmp & 0x4) == 0) {
1732 pci_write_config_byte(memc, 0x45, tmp);
1739 pci_read_config_byte(pdev, 0x84, &tmp);
1740 sym_dev->host_id = tmp;
1744 * Called before unloading the module.
1746 * We have to free resources and halt the NCR chip.
1748 static int sym_detach(struct sym_hcb *np, struct pci_dev *pdev)
1750 printk("%s: detaching ...\n", sym_name(np));
1752 del_timer_sync(&np->s.timer);
1756 * We should use sym_soft_reset(), but we don't want to do
1757 * so, since we may not be safe if interrupts occur.
1759 printk("%s: resetting chip\n", sym_name(np));
1760 OUTB(np, nc_istat, SRST);
1763 OUTB(np, nc_istat, 0);
1765 sym_free_resources(np, pdev);
1771 * Driver host template.
1773 static struct scsi_host_template sym2_template = {
1774 .module = THIS_MODULE,
1775 .name = "sym53c8xx",
1776 .info = sym53c8xx_info,
1777 .queuecommand = sym53c8xx_queue_command,
1778 .slave_alloc = sym53c8xx_slave_alloc,
1779 .slave_configure = sym53c8xx_slave_configure,
1780 .slave_destroy = sym53c8xx_slave_destroy,
1781 .eh_abort_handler = sym53c8xx_eh_abort_handler,
1782 .eh_device_reset_handler = sym53c8xx_eh_device_reset_handler,
1783 .eh_bus_reset_handler = sym53c8xx_eh_bus_reset_handler,
1784 .eh_host_reset_handler = sym53c8xx_eh_host_reset_handler,
1786 .use_clustering = ENABLE_CLUSTERING,
1787 .use_sg_chaining = ENABLE_SG_CHAINING,
1788 .max_sectors = 0xFFFF,
1789 #ifdef SYM_LINUX_PROC_INFO_SUPPORT
1790 .proc_info = sym53c8xx_proc_info,
1791 .proc_name = NAME53C8XX,
1795 static int attach_count;
1797 static int __devinit sym2_probe(struct pci_dev *pdev,
1798 const struct pci_device_id *ent)
1800 struct sym_device sym_dev;
1801 struct sym_nvram nvram;
1802 struct Scsi_Host *instance;
1804 memset(&sym_dev, 0, sizeof(sym_dev));
1805 memset(&nvram, 0, sizeof(nvram));
1807 if (pci_enable_device(pdev))
1810 pci_set_master(pdev);
1812 if (pci_request_regions(pdev, NAME53C8XX))
1815 sym_init_device(pdev, &sym_dev);
1816 if (sym_check_supported(&sym_dev))
1819 if (sym_check_raid(&sym_dev))
1820 goto leave; /* Don't disable the device */
1822 if (sym_set_workarounds(&sym_dev))
1825 sym_config_pqs(pdev, &sym_dev);
1827 sym_get_nvram(&sym_dev, &nvram);
1829 instance = sym_attach(&sym2_template, attach_count, &sym_dev);
1833 if (scsi_add_host(instance, &pdev->dev))
1835 scsi_scan_host(instance);
1842 sym_detach(pci_get_drvdata(pdev), pdev);
1844 pci_release_regions(pdev);
1846 pci_disable_device(pdev);
1851 static void __devexit sym2_remove(struct pci_dev *pdev)
1853 struct sym_hcb *np = pci_get_drvdata(pdev);
1854 struct Scsi_Host *host = np->s.host;
1856 scsi_remove_host(host);
1857 scsi_host_put(host);
1859 sym_detach(np, pdev);
1861 pci_release_regions(pdev);
1862 pci_disable_device(pdev);
1867 static void sym2_get_signalling(struct Scsi_Host *shost)
1869 struct sym_hcb *np = sym_get_hcb(shost);
1870 enum spi_signal_type type;
1872 switch (np->scsi_mode) {
1874 type = SPI_SIGNAL_SE;
1877 type = SPI_SIGNAL_LVD;
1880 type = SPI_SIGNAL_HVD;
1883 type = SPI_SIGNAL_UNKNOWN;
1886 spi_signalling(shost) = type;
1889 static void sym2_set_offset(struct scsi_target *starget, int offset)
1891 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1892 struct sym_hcb *np = sym_get_hcb(shost);
1893 struct sym_tcb *tp = &np->target[starget->id];
1895 tp->tgoal.offset = offset;
1896 tp->tgoal.check_nego = 1;
1899 static void sym2_set_period(struct scsi_target *starget, int period)
1901 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1902 struct sym_hcb *np = sym_get_hcb(shost);
1903 struct sym_tcb *tp = &np->target[starget->id];
1905 /* have to have DT for these transfers, but DT will also
1906 * set width, so check that this is allowed */
1907 if (period <= np->minsync && spi_width(starget))
1910 tp->tgoal.period = period;
1911 tp->tgoal.check_nego = 1;
1914 static void sym2_set_width(struct scsi_target *starget, int width)
1916 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1917 struct sym_hcb *np = sym_get_hcb(shost);
1918 struct sym_tcb *tp = &np->target[starget->id];
1920 /* It is illegal to have DT set on narrow transfers. If DT is
1921 * clear, we must also clear IU and QAS. */
1923 tp->tgoal.iu = tp->tgoal.dt = tp->tgoal.qas = 0;
1925 tp->tgoal.width = width;
1926 tp->tgoal.check_nego = 1;
1929 static void sym2_set_dt(struct scsi_target *starget, int dt)
1931 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1932 struct sym_hcb *np = sym_get_hcb(shost);
1933 struct sym_tcb *tp = &np->target[starget->id];
1935 /* We must clear QAS and IU if DT is clear */
1939 tp->tgoal.iu = tp->tgoal.dt = tp->tgoal.qas = 0;
1940 tp->tgoal.check_nego = 1;
1944 static void sym2_set_iu(struct scsi_target *starget, int iu)
1946 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1947 struct sym_hcb *np = sym_get_hcb(shost);
1948 struct sym_tcb *tp = &np->target[starget->id];
1951 tp->tgoal.iu = tp->tgoal.dt = 1;
1954 tp->tgoal.check_nego = 1;
1957 static void sym2_set_qas(struct scsi_target *starget, int qas)
1959 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1960 struct sym_hcb *np = sym_get_hcb(shost);
1961 struct sym_tcb *tp = &np->target[starget->id];
1964 tp->tgoal.dt = tp->tgoal.qas = 1;
1967 tp->tgoal.check_nego = 1;
1971 static struct spi_function_template sym2_transport_functions = {
1972 .set_offset = sym2_set_offset,
1974 .set_period = sym2_set_period,
1976 .set_width = sym2_set_width,
1978 .set_dt = sym2_set_dt,
1981 .set_iu = sym2_set_iu,
1983 .set_qas = sym2_set_qas,
1986 .get_signalling = sym2_get_signalling,
1989 static struct pci_device_id sym2_id_table[] __devinitdata = {
1990 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C810,
1991 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
1992 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C820,
1993 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, /* new */
1994 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C825,
1995 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
1996 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C815,
1997 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
1998 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C810AP,
1999 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, /* new */
2000 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C860,
2001 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2002 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1510,
2003 PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_SCSI<<8, 0xffff00, 0UL },
2004 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C896,
2005 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2006 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C895,
2007 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2008 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C885,
2009 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2010 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C875,
2011 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2012 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C1510,
2013 PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_SCSI<<8, 0xffff00, 0UL }, /* new */
2014 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C895A,
2015 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2016 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C875A,
2017 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2018 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1010_33,
2019 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2020 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1010_66,
2021 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2022 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C875J,
2023 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2027 MODULE_DEVICE_TABLE(pci, sym2_id_table);
2029 static struct pci_driver sym2_driver = {
2031 .id_table = sym2_id_table,
2032 .probe = sym2_probe,
2033 .remove = __devexit_p(sym2_remove),
2036 static int __init sym2_init(void)
2040 sym2_setup_params();
2041 sym2_transport_template = spi_attach_transport(&sym2_transport_functions);
2042 if (!sym2_transport_template)
2045 error = pci_register_driver(&sym2_driver);
2047 spi_release_transport(sym2_transport_template);
2051 static void __exit sym2_exit(void)
2053 pci_unregister_driver(&sym2_driver);
2054 spi_release_transport(sym2_transport_template);
2057 module_init(sym2_init);
2058 module_exit(sym2_exit);