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 struct completion *eh_done; /* For error handling */
140 #define SYM_UCMD_PTR(cmd) ((struct sym_ucmd *)(&(cmd)->SCp))
141 #define SYM_SOFTC_PTR(cmd) sym_get_hcb(cmd->device->host)
144 * Complete a pending CAM CCB.
146 void sym_xpt_done(struct sym_hcb *np, struct scsi_cmnd *cmd)
148 struct sym_ucmd *ucmd = SYM_UCMD_PTR(cmd);
149 BUILD_BUG_ON(sizeof(struct scsi_pointer) < sizeof(struct sym_ucmd));
152 complete(ucmd->eh_done);
159 * Tell the SCSI layer about a BUS RESET.
161 void sym_xpt_async_bus_reset(struct sym_hcb *np)
163 printf_notice("%s: SCSI BUS has been reset.\n", sym_name(np));
164 np->s.settle_time = jiffies + sym_driver_setup.settle_delay * HZ;
165 np->s.settle_time_valid = 1;
166 if (sym_verbose >= 2)
167 printf_info("%s: command processing suspended for %d seconds\n",
168 sym_name(np), sym_driver_setup.settle_delay);
172 * Tell the SCSI layer about a BUS DEVICE RESET message sent.
174 void sym_xpt_async_sent_bdr(struct sym_hcb *np, int target)
176 printf_notice("%s: TARGET %d has been reset.\n", sym_name(np), target);
180 * Choose the more appropriate CAM status if
181 * the IO encountered an extended error.
183 static int sym_xerr_cam_status(int cam_status, int x_status)
186 if (x_status & XE_PARITY_ERR)
187 cam_status = DID_PARITY;
188 else if (x_status &(XE_EXTRA_DATA|XE_SODL_UNRUN|XE_SWIDE_OVRUN))
189 cam_status = DID_ERROR;
190 else if (x_status & XE_BAD_PHASE)
191 cam_status = DID_ERROR;
193 cam_status = DID_ERROR;
199 * Build CAM result for a failed or auto-sensed IO.
201 void sym_set_cam_result_error(struct sym_hcb *np, struct sym_ccb *cp, int resid)
203 struct scsi_cmnd *cmd = cp->cmd;
204 u_int cam_status, scsi_status, drv_status;
208 scsi_status = cp->ssss_status;
210 if (cp->host_flags & HF_SENSE) {
211 scsi_status = cp->sv_scsi_status;
212 resid = cp->sv_resid;
213 if (sym_verbose && cp->sv_xerr_status)
214 sym_print_xerr(cmd, cp->sv_xerr_status);
215 if (cp->host_status == HS_COMPLETE &&
216 cp->ssss_status == S_GOOD &&
217 cp->xerr_status == 0) {
218 cam_status = sym_xerr_cam_status(DID_OK,
220 drv_status = DRIVER_SENSE;
222 * Bounce back the sense data to user.
224 memset(&cmd->sense_buffer, 0, sizeof(cmd->sense_buffer));
225 memcpy(cmd->sense_buffer, cp->sns_bbuf,
226 min(sizeof(cmd->sense_buffer),
227 (size_t)SYM_SNS_BBUF_LEN));
230 * If the device reports a UNIT ATTENTION condition
231 * due to a RESET condition, we should consider all
232 * disconnect CCBs for this unit as aborted.
236 p = (u_char *) cmd->sense_data;
237 if (p[0]==0x70 && p[2]==0x6 && p[12]==0x29)
238 sym_clear_tasks(np, DID_ABORT,
239 cp->target,cp->lun, -1);
244 * Error return from our internal request sense. This
245 * is bad: we must clear the contingent allegiance
246 * condition otherwise the device will always return
247 * BUSY. Use a big stick.
249 sym_reset_scsi_target(np, cmd->device->id);
250 cam_status = DID_ERROR;
252 } else if (cp->host_status == HS_COMPLETE) /* Bad SCSI status */
254 else if (cp->host_status == HS_SEL_TIMEOUT) /* Selection timeout */
255 cam_status = DID_NO_CONNECT;
256 else if (cp->host_status == HS_UNEXPECTED) /* Unexpected BUS FREE*/
257 cam_status = DID_ERROR;
258 else { /* Extended error */
260 sym_print_addr(cmd, "COMMAND FAILED (%x %x %x).\n",
261 cp->host_status, cp->ssss_status,
265 * Set the most appropriate value for CAM status.
267 cam_status = sym_xerr_cam_status(DID_ERROR, cp->xerr_status);
269 scsi_set_resid(cmd, resid);
270 cmd->result = (drv_status << 24) + (cam_status << 16) + scsi_status;
273 static int sym_scatter(struct sym_hcb *np, struct sym_ccb *cp, struct scsi_cmnd *cmd)
280 use_sg = scsi_dma_map(cmd);
282 struct scatterlist *sg;
283 struct sym_tcb *tp = &np->target[cp->target];
284 struct sym_tblmove *data;
286 if (use_sg > SYM_CONF_MAX_SG) {
291 data = &cp->phys.data[SYM_CONF_MAX_SG - use_sg];
293 scsi_for_each_sg(cmd, sg, use_sg, segment) {
294 dma_addr_t baddr = sg_dma_address(sg);
295 unsigned int len = sg_dma_len(sg);
297 if ((len & 1) && (tp->head.wval & EWS)) {
299 cp->odd_byte_adjustment++;
302 sym_build_sge(np, &data[segment], baddr, len);
313 * Queue a SCSI command.
315 static int sym_queue_command(struct sym_hcb *np, struct scsi_cmnd *cmd)
317 struct scsi_device *sdev = cmd->device;
324 * Retrieve the target descriptor.
326 tp = &np->target[sdev->id];
329 * Select tagged/untagged.
331 lp = sym_lp(tp, sdev->lun);
332 order = (lp && lp->s.reqtags) ? M_SIMPLE_TAG : 0;
337 cp = sym_get_ccb(np, cmd, order);
339 return 1; /* Means resource shortage */
340 sym_queue_scsiio(np, cmd, cp);
345 * Setup buffers and pointers that address the CDB.
347 static inline int sym_setup_cdb(struct sym_hcb *np, struct scsi_cmnd *cmd, struct sym_ccb *cp)
349 memcpy(cp->cdb_buf, cmd->cmnd, cmd->cmd_len);
351 cp->phys.cmd.addr = CCB_BA(cp, cdb_buf[0]);
352 cp->phys.cmd.size = cpu_to_scr(cmd->cmd_len);
358 * Setup pointers that address the data and start the I/O.
360 int sym_setup_data_and_start(struct sym_hcb *np, struct scsi_cmnd *cmd, struct sym_ccb *cp)
368 if (sym_setup_cdb(np, cmd, cp))
372 * No direction means no data.
374 dir = cmd->sc_data_direction;
375 if (dir != DMA_NONE) {
376 cp->segments = sym_scatter(np, cp, cmd);
377 if (cp->segments < 0) {
378 sym_set_cam_status(cmd, DID_ERROR);
383 * No segments means no data.
393 * Set the data pointer.
396 case DMA_BIDIRECTIONAL:
397 printk("%s: got DMA_BIDIRECTIONAL command", sym_name(np));
398 sym_set_cam_status(cmd, DID_ERROR);
401 goalp = SCRIPTA_BA(np, data_out2) + 8;
402 lastp = goalp - 8 - (cp->segments * (2*4));
404 case DMA_FROM_DEVICE:
405 cp->host_flags |= HF_DATA_IN;
406 goalp = SCRIPTA_BA(np, data_in2) + 8;
407 lastp = goalp - 8 - (cp->segments * (2*4));
411 lastp = goalp = SCRIPTB_BA(np, no_data);
416 * Set all pointers values needed by SCRIPTS.
418 cp->phys.head.lastp = cpu_to_scr(lastp);
419 cp->phys.head.savep = cpu_to_scr(lastp);
420 cp->startp = cp->phys.head.savep;
421 cp->goalp = cpu_to_scr(goalp);
424 * When `#ifed 1', the code below makes the driver
425 * panic on the first attempt to write to a SCSI device.
426 * It is the first test we want to do after a driver
427 * change that does not seem obviously safe. :)
430 switch (cp->cdb_buf[0]) {
431 case 0x0A: case 0x2A: case 0xAA:
432 panic("XXXXXXXXXXXXX WRITE NOT YET ALLOWED XXXXXXXXXXXXXX\n");
442 sym_put_start_queue(np, cp);
446 sym_free_ccb(np, cp);
447 sym_xpt_done(np, cmd);
455 * Misused to keep the driver running when
456 * interrupts are not configured correctly.
458 static void sym_timer(struct sym_hcb *np)
460 unsigned long thistime = jiffies;
465 np->s.timer.expires = thistime + SYM_CONF_TIMER_INTERVAL;
466 add_timer(&np->s.timer);
469 * If we are resetting the ncr, wait for settle_time before
470 * clearing it. Then command processing will be resumed.
472 if (np->s.settle_time_valid) {
473 if (time_before_eq(np->s.settle_time, thistime)) {
474 if (sym_verbose >= 2 )
475 printk("%s: command processing resumed\n",
477 np->s.settle_time_valid = 0;
483 * Nothing to do for now, but that may come.
485 if (np->s.lasttime + 4*HZ < thistime) {
486 np->s.lasttime = thistime;
489 #ifdef SYM_CONF_PCIQ_MAY_MISS_COMPLETIONS
491 * Some way-broken PCI bridges may lead to
492 * completions being lost when the clearing
493 * of the INTFLY flag by the CPU occurs
494 * concurrently with the chip raising this flag.
495 * If this ever happen, lost completions will
504 * PCI BUS error handler.
506 void sym_log_bus_error(struct sym_hcb *np)
509 pci_read_config_word(np->s.device, PCI_STATUS, &pci_sts);
510 if (pci_sts & 0xf900) {
511 pci_write_config_word(np->s.device, PCI_STATUS, pci_sts);
512 printf("%s: PCI STATUS = 0x%04x\n",
513 sym_name(np), pci_sts & 0xf900);
518 * queuecommand method. Entered with the host adapter lock held and
519 * interrupts disabled.
521 static int sym53c8xx_queue_command(struct scsi_cmnd *cmd,
522 void (*done)(struct scsi_cmnd *))
524 struct sym_hcb *np = SYM_SOFTC_PTR(cmd);
525 struct sym_ucmd *ucp = SYM_UCMD_PTR(cmd);
528 cmd->scsi_done = done;
529 memset(ucp, 0, sizeof(*ucp));
532 * Shorten our settle_time if needed for
533 * this command not to time out.
535 if (np->s.settle_time_valid && cmd->timeout_per_command) {
536 unsigned long tlimit = jiffies + cmd->timeout_per_command;
537 tlimit -= SYM_CONF_TIMER_INTERVAL*2;
538 if (time_after(np->s.settle_time, tlimit)) {
539 np->s.settle_time = tlimit;
543 if (np->s.settle_time_valid)
544 return SCSI_MLQUEUE_HOST_BUSY;
546 sts = sym_queue_command(np, cmd);
548 return SCSI_MLQUEUE_HOST_BUSY;
553 * Linux entry point of the interrupt handler.
555 static irqreturn_t sym53c8xx_intr(int irq, void *dev_id)
557 struct sym_hcb *np = dev_id;
559 if (DEBUG_FLAGS & DEBUG_TINY) printf_debug ("[");
561 spin_lock(np->s.host->host_lock);
563 spin_unlock(np->s.host->host_lock);
565 if (DEBUG_FLAGS & DEBUG_TINY) printf_debug ("]\n");
571 * Linux entry point of the timer handler
573 static void sym53c8xx_timer(unsigned long npref)
575 struct sym_hcb *np = (struct sym_hcb *)npref;
578 spin_lock_irqsave(np->s.host->host_lock, flags);
580 spin_unlock_irqrestore(np->s.host->host_lock, flags);
585 * What the eh thread wants us to perform.
587 #define SYM_EH_ABORT 0
588 #define SYM_EH_DEVICE_RESET 1
589 #define SYM_EH_BUS_RESET 2
590 #define SYM_EH_HOST_RESET 3
593 * Generic method for our eh processing.
594 * The 'op' argument tells what we have to do.
596 static int sym_eh_handler(int op, char *opname, struct scsi_cmnd *cmd)
598 struct sym_hcb *np = SYM_SOFTC_PTR(cmd);
599 struct sym_ucmd *ucmd = SYM_UCMD_PTR(cmd);
600 struct Scsi_Host *host = cmd->device->host;
604 struct completion eh_done;
606 dev_warn(&cmd->device->sdev_gendev, "%s operation started.\n", opname);
608 spin_lock_irq(host->host_lock);
609 /* This one is queued in some place -> to wait for completion */
610 FOR_EACH_QUEUED_ELEMENT(&np->busy_ccbq, qp) {
611 struct sym_ccb *cp = sym_que_entry(qp, struct sym_ccb, link_ccbq);
612 if (cp->cmd == cmd) {
618 /* Try to proceed the operation we have been asked for */
622 sts = sym_abort_scsiio(np, cmd, 1);
624 case SYM_EH_DEVICE_RESET:
625 sts = sym_reset_scsi_target(np, cmd->device->id);
627 case SYM_EH_BUS_RESET:
628 sym_reset_scsi_bus(np, 1);
631 case SYM_EH_HOST_RESET:
632 sym_reset_scsi_bus(np, 0);
633 sym_start_up (np, 1);
640 /* On error, restore everything and cross fingers :) */
645 init_completion(&eh_done);
646 ucmd->eh_done = &eh_done;
647 spin_unlock_irq(host->host_lock);
648 if (!wait_for_completion_timeout(&eh_done, 5*HZ)) {
649 ucmd->eh_done = NULL;
653 spin_unlock_irq(host->host_lock);
656 dev_warn(&cmd->device->sdev_gendev, "%s operation %s.\n", opname,
657 sts==0 ? "complete" :sts==-2 ? "timed-out" : "failed");
658 return sts ? SCSI_FAILED : SCSI_SUCCESS;
663 * Error handlers called from the eh thread (one thread per HBA).
665 static int sym53c8xx_eh_abort_handler(struct scsi_cmnd *cmd)
667 return sym_eh_handler(SYM_EH_ABORT, "ABORT", cmd);
670 static int sym53c8xx_eh_device_reset_handler(struct scsi_cmnd *cmd)
672 return sym_eh_handler(SYM_EH_DEVICE_RESET, "DEVICE RESET", cmd);
675 static int sym53c8xx_eh_bus_reset_handler(struct scsi_cmnd *cmd)
677 return sym_eh_handler(SYM_EH_BUS_RESET, "BUS RESET", cmd);
680 static int sym53c8xx_eh_host_reset_handler(struct scsi_cmnd *cmd)
682 return sym_eh_handler(SYM_EH_HOST_RESET, "HOST RESET", cmd);
686 * Tune device queuing depth, according to various limits.
688 static void sym_tune_dev_queuing(struct sym_tcb *tp, int lun, u_short reqtags)
690 struct sym_lcb *lp = sym_lp(tp, lun);
696 oldtags = lp->s.reqtags;
698 if (reqtags > lp->s.scdev_depth)
699 reqtags = lp->s.scdev_depth;
701 lp->s.reqtags = reqtags;
703 if (reqtags != oldtags) {
704 dev_info(&tp->starget->dev,
705 "tagged command queuing %s, command queue depth %d.\n",
706 lp->s.reqtags ? "enabled" : "disabled", reqtags);
711 * Linux select queue depths function
713 #define DEF_DEPTH (sym_driver_setup.max_tag)
714 #define ALL_TARGETS -2
719 static int device_queue_depth(struct sym_hcb *np, int target, int lun)
722 char *p = sym_driver_setup.tag_ctrl;
728 while ((c = *p++) != 0) {
729 v = simple_strtoul(p, &ep, 0);
738 t = (target == v) ? v : NO_TARGET;
743 u = (lun == v) ? v : NO_LUN;
746 if (h == np->s.unit &&
747 (t == ALL_TARGETS || t == target) &&
748 (u == ALL_LUNS || u == lun))
763 static int sym53c8xx_slave_alloc(struct scsi_device *sdev)
765 struct sym_hcb *np = sym_get_hcb(sdev->host);
766 struct sym_tcb *tp = &np->target[sdev->id];
769 if (sdev->id >= SYM_CONF_MAX_TARGET || sdev->lun >= SYM_CONF_MAX_LUN)
772 tp->starget = sdev->sdev_target;
774 * Fail the device init if the device is flagged NOSCAN at BOOT in
775 * the NVRAM. This may speed up boot and maintain coherency with
776 * BIOS device numbering. Clearing the flag allows the user to
777 * rescan skipped devices later. We also return an error for
778 * devices not flagged for SCAN LUNS in the NVRAM since some single
779 * lun devices behave badly when asked for a non zero LUN.
782 if (tp->usrflags & SYM_SCAN_BOOT_DISABLED) {
783 tp->usrflags &= ~SYM_SCAN_BOOT_DISABLED;
784 starget_printk(KERN_INFO, tp->starget,
785 "Scan at boot disabled in NVRAM\n");
789 if (tp->usrflags & SYM_SCAN_LUNS_DISABLED) {
792 starget_printk(KERN_INFO, tp->starget,
793 "Multiple LUNs disabled in NVRAM\n");
796 lp = sym_alloc_lcb(np, sdev->id, sdev->lun);
800 spi_min_period(tp->starget) = tp->usr_period;
801 spi_max_width(tp->starget) = tp->usr_width;
807 * Linux entry point for device queue sizing.
809 static int sym53c8xx_slave_configure(struct scsi_device *sdev)
811 struct sym_hcb *np = sym_get_hcb(sdev->host);
812 struct sym_tcb *tp = &np->target[sdev->id];
813 struct sym_lcb *lp = sym_lp(tp, sdev->lun);
814 int reqtags, depth_to_use;
819 lp->curr_flags = lp->user_flags;
822 * Select queue depth from driver setup.
823 * Donnot use more than configured by user.
825 * Donnot use more than our maximum.
827 reqtags = device_queue_depth(np, sdev->id, sdev->lun);
828 if (reqtags > tp->usrtags)
829 reqtags = tp->usrtags;
830 if (!sdev->tagged_supported)
832 #if 1 /* Avoid to locally queue commands for no good reasons */
833 if (reqtags > SYM_CONF_MAX_TAG)
834 reqtags = SYM_CONF_MAX_TAG;
835 depth_to_use = (reqtags ? reqtags : 2);
837 depth_to_use = (reqtags ? SYM_CONF_MAX_TAG : 2);
839 scsi_adjust_queue_depth(sdev,
840 (sdev->tagged_supported ?
843 lp->s.scdev_depth = depth_to_use;
844 sym_tune_dev_queuing(tp, sdev->lun, reqtags);
846 if (!spi_initial_dv(sdev->sdev_target))
852 static void sym53c8xx_slave_destroy(struct scsi_device *sdev)
854 struct sym_hcb *np = sym_get_hcb(sdev->host);
855 struct sym_lcb *lp = sym_lp(&np->target[sdev->id], sdev->lun);
858 sym_mfree_dma(lp->itlq_tbl, SYM_CONF_MAX_TASK * 4, "ITLQ_TBL");
860 sym_mfree_dma(lp, sizeof(*lp), "LCB");
864 * Linux entry point for info() function
866 static const char *sym53c8xx_info (struct Scsi_Host *host)
868 return SYM_DRIVER_NAME;
872 #ifdef SYM_LINUX_PROC_INFO_SUPPORT
874 * Proc file system stuff
876 * A read operation returns adapter information.
877 * A write operation is a control command.
878 * The string is parsed in the driver code and the command is passed
879 * to the sym_usercmd() function.
882 #ifdef SYM_LINUX_USER_COMMAND_SUPPORT
891 #define UC_SETSYNC 10
892 #define UC_SETTAGS 11
893 #define UC_SETDEBUG 12
894 #define UC_SETWIDE 14
895 #define UC_SETFLAG 15
896 #define UC_SETVERBOSE 17
897 #define UC_RESETDEV 18
898 #define UC_CLEARDEV 19
900 static void sym_exec_user_command (struct sym_hcb *np, struct sym_usrcmd *uc)
908 #ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
910 sym_debug_flags = uc->data;
914 np->verbose = uc->data;
918 * We assume that other commands apply to targets.
919 * This should always be the case and avoid the below
920 * 4 lines to be repeated 6 times.
922 for (t = 0; t < SYM_CONF_MAX_TARGET; t++) {
923 if (!((uc->target >> t) & 1))
930 if (!uc->data || uc->data >= 255) {
931 tp->tgoal.iu = tp->tgoal.dt =
933 tp->tgoal.offset = 0;
934 } else if (uc->data <= 9 && np->minsync_dt) {
935 if (uc->data < np->minsync_dt)
936 uc->data = np->minsync_dt;
937 tp->tgoal.iu = tp->tgoal.dt =
940 tp->tgoal.period = uc->data;
941 tp->tgoal.offset = np->maxoffs_dt;
943 if (uc->data < np->minsync)
944 uc->data = np->minsync;
945 tp->tgoal.iu = tp->tgoal.dt =
947 tp->tgoal.period = uc->data;
948 tp->tgoal.offset = np->maxoffs;
950 tp->tgoal.check_nego = 1;
953 tp->tgoal.width = uc->data ? 1 : 0;
954 tp->tgoal.check_nego = 1;
957 for (l = 0; l < SYM_CONF_MAX_LUN; l++)
958 sym_tune_dev_queuing(tp, l, uc->data);
963 OUTB(np, nc_istat, SIGP|SEM);
966 for (l = 0; l < SYM_CONF_MAX_LUN; l++) {
967 struct sym_lcb *lp = sym_lp(tp, l);
968 if (lp) lp->to_clear = 1;
971 OUTB(np, nc_istat, SIGP|SEM);
974 tp->usrflags = uc->data;
982 static int skip_spaces(char *ptr, int len)
986 for (cnt = len; cnt > 0 && (c = *ptr++) && isspace(c); cnt--);
991 static int get_int_arg(char *ptr, int len, u_long *pv)
995 *pv = simple_strtoul(ptr, &end, 10);
999 static int is_keyword(char *ptr, int len, char *verb)
1001 int verb_len = strlen(verb);
1003 if (len >= verb_len && !memcmp(verb, ptr, verb_len))
1009 #define SKIP_SPACES(ptr, len) \
1010 if ((arg_len = skip_spaces(ptr, len)) < 1) \
1012 ptr += arg_len; len -= arg_len;
1014 #define GET_INT_ARG(ptr, len, v) \
1015 if (!(arg_len = get_int_arg(ptr, len, &(v)))) \
1017 ptr += arg_len; len -= arg_len;
1021 * Parse a control command
1024 static int sym_user_command(struct sym_hcb *np, char *buffer, int length)
1028 struct sym_usrcmd cmd, *uc = &cmd;
1032 memset(uc, 0, sizeof(*uc));
1034 if (len > 0 && ptr[len-1] == '\n')
1037 if ((arg_len = is_keyword(ptr, len, "setsync")) != 0)
1038 uc->cmd = UC_SETSYNC;
1039 else if ((arg_len = is_keyword(ptr, len, "settags")) != 0)
1040 uc->cmd = UC_SETTAGS;
1041 else if ((arg_len = is_keyword(ptr, len, "setverbose")) != 0)
1042 uc->cmd = UC_SETVERBOSE;
1043 else if ((arg_len = is_keyword(ptr, len, "setwide")) != 0)
1044 uc->cmd = UC_SETWIDE;
1045 #ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
1046 else if ((arg_len = is_keyword(ptr, len, "setdebug")) != 0)
1047 uc->cmd = UC_SETDEBUG;
1049 else if ((arg_len = is_keyword(ptr, len, "setflag")) != 0)
1050 uc->cmd = UC_SETFLAG;
1051 else if ((arg_len = is_keyword(ptr, len, "resetdev")) != 0)
1052 uc->cmd = UC_RESETDEV;
1053 else if ((arg_len = is_keyword(ptr, len, "cleardev")) != 0)
1054 uc->cmd = UC_CLEARDEV;
1058 #ifdef DEBUG_PROC_INFO
1059 printk("sym_user_command: arg_len=%d, cmd=%ld\n", arg_len, uc->cmd);
1064 ptr += arg_len; len -= arg_len;
1073 SKIP_SPACES(ptr, len);
1074 if ((arg_len = is_keyword(ptr, len, "all")) != 0) {
1075 ptr += arg_len; len -= arg_len;
1078 GET_INT_ARG(ptr, len, target);
1079 uc->target = (1<<target);
1080 #ifdef DEBUG_PROC_INFO
1081 printk("sym_user_command: target=%ld\n", target);
1092 SKIP_SPACES(ptr, len);
1093 GET_INT_ARG(ptr, len, uc->data);
1094 #ifdef DEBUG_PROC_INFO
1095 printk("sym_user_command: data=%ld\n", uc->data);
1098 #ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
1101 SKIP_SPACES(ptr, len);
1102 if ((arg_len = is_keyword(ptr, len, "alloc")))
1103 uc->data |= DEBUG_ALLOC;
1104 else if ((arg_len = is_keyword(ptr, len, "phase")))
1105 uc->data |= DEBUG_PHASE;
1106 else if ((arg_len = is_keyword(ptr, len, "queue")))
1107 uc->data |= DEBUG_QUEUE;
1108 else if ((arg_len = is_keyword(ptr, len, "result")))
1109 uc->data |= DEBUG_RESULT;
1110 else if ((arg_len = is_keyword(ptr, len, "scatter")))
1111 uc->data |= DEBUG_SCATTER;
1112 else if ((arg_len = is_keyword(ptr, len, "script")))
1113 uc->data |= DEBUG_SCRIPT;
1114 else if ((arg_len = is_keyword(ptr, len, "tiny")))
1115 uc->data |= DEBUG_TINY;
1116 else if ((arg_len = is_keyword(ptr, len, "timing")))
1117 uc->data |= DEBUG_TIMING;
1118 else if ((arg_len = is_keyword(ptr, len, "nego")))
1119 uc->data |= DEBUG_NEGO;
1120 else if ((arg_len = is_keyword(ptr, len, "tags")))
1121 uc->data |= DEBUG_TAGS;
1122 else if ((arg_len = is_keyword(ptr, len, "pointer")))
1123 uc->data |= DEBUG_POINTER;
1126 ptr += arg_len; len -= arg_len;
1128 #ifdef DEBUG_PROC_INFO
1129 printk("sym_user_command: data=%ld\n", uc->data);
1132 #endif /* SYM_LINUX_DEBUG_CONTROL_SUPPORT */
1135 SKIP_SPACES(ptr, len);
1136 if ((arg_len = is_keyword(ptr, len, "no_disc")))
1137 uc->data &= ~SYM_DISC_ENABLED;
1140 ptr += arg_len; len -= arg_len;
1150 unsigned long flags;
1152 spin_lock_irqsave(np->s.host->host_lock, flags);
1153 sym_exec_user_command (np, uc);
1154 spin_unlock_irqrestore(np->s.host->host_lock, flags);
1159 #endif /* SYM_LINUX_USER_COMMAND_SUPPORT */
1162 #ifdef SYM_LINUX_USER_INFO_SUPPORT
1164 * Informations through the proc file system.
1173 static void copy_mem_info(struct info_str *info, char *data, int len)
1175 if (info->pos + len > info->length)
1176 len = info->length - info->pos;
1178 if (info->pos + len < info->offset) {
1182 if (info->pos < info->offset) {
1183 data += (info->offset - info->pos);
1184 len -= (info->offset - info->pos);
1188 memcpy(info->buffer + info->pos, data, len);
1193 static int copy_info(struct info_str *info, char *fmt, ...)
1199 va_start(args, fmt);
1200 len = vsprintf(buf, fmt, args);
1203 copy_mem_info(info, buf, len);
1208 * Copy formatted information into the input buffer.
1210 static int sym_host_info(struct sym_hcb *np, char *ptr, off_t offset, int len)
1212 struct info_str info;
1216 info.offset = offset;
1219 copy_info(&info, "Chip " NAME53C "%s, device id 0x%x, "
1220 "revision id 0x%x\n",
1221 np->s.chip_name, np->device_id, np->revision_id);
1222 copy_info(&info, "At PCI address %s, IRQ " IRQ_FMT "\n",
1223 pci_name(np->s.device), IRQ_PRM(np->s.device->irq));
1224 copy_info(&info, "Min. period factor %d, %s SCSI BUS%s\n",
1225 (int) (np->minsync_dt ? np->minsync_dt : np->minsync),
1226 np->maxwide ? "Wide" : "Narrow",
1227 np->minsync_dt ? ", DT capable" : "");
1229 copy_info(&info, "Max. started commands %d, "
1230 "max. commands per LUN %d\n",
1231 SYM_CONF_MAX_START, SYM_CONF_MAX_TAG);
1233 return info.pos > info.offset? info.pos - info.offset : 0;
1235 #endif /* SYM_LINUX_USER_INFO_SUPPORT */
1238 * Entry point of the scsi proc fs of the driver.
1239 * - func = 0 means read (returns adapter infos)
1240 * - func = 1 means write (not yet merget from sym53c8xx)
1242 static int sym53c8xx_proc_info(struct Scsi_Host *host, char *buffer,
1243 char **start, off_t offset, int length, int func)
1245 struct sym_hcb *np = sym_get_hcb(host);
1249 #ifdef SYM_LINUX_USER_COMMAND_SUPPORT
1250 retv = sym_user_command(np, buffer, length);
1257 #ifdef SYM_LINUX_USER_INFO_SUPPORT
1258 retv = sym_host_info(np, buffer, offset, length);
1266 #endif /* SYM_LINUX_PROC_INFO_SUPPORT */
1269 * Free controller resources.
1271 static void sym_free_resources(struct sym_hcb *np, struct pci_dev *pdev)
1274 * Free O/S specific resources.
1277 free_irq(pdev->irq, np);
1279 pci_iounmap(pdev, np->s.ioaddr);
1281 pci_iounmap(pdev, np->s.ramaddr);
1283 * Free O/S independent resources.
1287 sym_mfree_dma(np, sizeof(*np), "HCB");
1291 * Ask/tell the system about DMA addressing.
1293 static int sym_setup_bus_dma_mask(struct sym_hcb *np)
1295 #if SYM_CONF_DMA_ADDRESSING_MODE > 0
1296 #if SYM_CONF_DMA_ADDRESSING_MODE == 1
1297 #define DMA_DAC_MASK DMA_40BIT_MASK
1298 #elif SYM_CONF_DMA_ADDRESSING_MODE == 2
1299 #define DMA_DAC_MASK DMA_64BIT_MASK
1301 if ((np->features & FE_DAC) &&
1302 !pci_set_dma_mask(np->s.device, DMA_DAC_MASK)) {
1308 if (!pci_set_dma_mask(np->s.device, DMA_32BIT_MASK))
1311 printf_warning("%s: No suitable DMA available\n", sym_name(np));
1316 * Host attach and initialisations.
1318 * Allocate host data and ncb structure.
1319 * Remap MMIO region.
1320 * Do chip initialization.
1321 * If all is OK, install interrupt handling and
1322 * start the timer daemon.
1324 static struct Scsi_Host * __devinit sym_attach(struct scsi_host_template *tpnt,
1325 int unit, struct sym_device *dev)
1327 struct host_data *host_data;
1328 struct sym_hcb *np = NULL;
1329 struct Scsi_Host *instance = NULL;
1330 struct pci_dev *pdev = dev->pdev;
1331 unsigned long flags;
1335 "sym%d: <%s> rev 0x%x at pci %s irq " IRQ_FMT "\n",
1336 unit, dev->chip.name, dev->chip.revision_id,
1337 pci_name(pdev), IRQ_PRM(pdev->irq));
1340 * Get the firmware for this chip.
1342 fw = sym_find_firmware(&dev->chip);
1347 * Allocate host_data structure
1349 instance = scsi_host_alloc(tpnt, sizeof(*host_data));
1352 host_data = (struct host_data *) instance->hostdata;
1355 * Allocate immediately the host control block,
1356 * since we are only expecting to succeed. :)
1357 * We keep track in the HCB of all the resources that
1358 * are to be released on error.
1360 np = __sym_calloc_dma(&pdev->dev, sizeof(*np), "HCB");
1363 np->s.device = pdev;
1364 np->bus_dmat = &pdev->dev; /* Result in 1 DMA pool per HBA */
1365 host_data->ncb = np;
1366 np->s.host = instance;
1368 pci_set_drvdata(pdev, np);
1371 * Copy some useful infos to the HCB.
1373 np->hcb_ba = vtobus(np);
1374 np->verbose = sym_driver_setup.verbose;
1375 np->s.device = pdev;
1377 np->device_id = dev->chip.device_id;
1378 np->revision_id = dev->chip.revision_id;
1379 np->features = dev->chip.features;
1380 np->clock_divn = dev->chip.nr_divisor;
1381 np->maxoffs = dev->chip.offset_max;
1382 np->maxburst = dev->chip.burst_max;
1383 np->myaddr = dev->host_id;
1388 strlcpy(np->s.chip_name, dev->chip.name, sizeof(np->s.chip_name));
1389 sprintf(np->s.inst_name, "sym%d", np->s.unit);
1391 if (sym_setup_bus_dma_mask(np))
1395 * Try to map the controller chip to
1396 * virtual and physical memory.
1398 np->mmio_ba = (u32)dev->mmio_base;
1399 np->s.ioaddr = dev->s.ioaddr;
1400 np->s.ramaddr = dev->s.ramaddr;
1401 np->s.io_ws = (np->features & FE_IO256) ? 256 : 128;
1404 * Map on-chip RAM if present and supported.
1406 if (!(np->features & FE_RAM))
1408 if (dev->ram_base) {
1409 np->ram_ba = (u32)dev->ram_base;
1410 np->ram_ws = (np->features & FE_RAM8K) ? 8192 : 4096;
1413 if (sym_hcb_attach(instance, fw, dev->nvram))
1417 * Install the interrupt handler.
1418 * If we synchonize the C code with SCRIPTS on interrupt,
1419 * we do not want to share the INTR line at all.
1421 if (request_irq(pdev->irq, sym53c8xx_intr, IRQF_SHARED, NAME53C8XX, np)) {
1422 printf_err("%s: request irq %d failure\n",
1423 sym_name(np), pdev->irq);
1428 * After SCSI devices have been opened, we cannot
1429 * reset the bus safely, so we do it here.
1431 spin_lock_irqsave(instance->host_lock, flags);
1432 if (sym_reset_scsi_bus(np, 0))
1436 * Start the SCRIPTS.
1438 sym_start_up (np, 1);
1441 * Start the timer daemon
1443 init_timer(&np->s.timer);
1444 np->s.timer.data = (unsigned long) np;
1445 np->s.timer.function = sym53c8xx_timer;
1450 * Fill Linux host instance structure
1451 * and return success.
1453 instance->max_channel = 0;
1454 instance->this_id = np->myaddr;
1455 instance->max_id = np->maxwide ? 16 : 8;
1456 instance->max_lun = SYM_CONF_MAX_LUN;
1457 instance->unique_id = pci_resource_start(pdev, 0);
1458 instance->cmd_per_lun = SYM_CONF_MAX_TAG;
1459 instance->can_queue = (SYM_CONF_MAX_START-2);
1460 instance->sg_tablesize = SYM_CONF_MAX_SG;
1461 instance->max_cmd_len = 16;
1462 BUG_ON(sym2_transport_template == NULL);
1463 instance->transportt = sym2_transport_template;
1465 /* 53c896 rev 1 errata: DMA may not cross 16MB boundary */
1466 if (pdev->device == PCI_DEVICE_ID_NCR_53C896 && np->revision_id < 2)
1467 instance->dma_boundary = 0xFFFFFF;
1469 spin_unlock_irqrestore(instance->host_lock, flags);
1474 printf_err("%s: FATAL ERROR: CHECK SCSI BUS - CABLES, "
1475 "TERMINATION, DEVICE POWER etc.!\n", sym_name(np));
1476 spin_unlock_irqrestore(instance->host_lock, flags);
1480 printf_info("%s: giving up ...\n", sym_name(np));
1482 sym_free_resources(np, pdev);
1483 scsi_host_put(instance);
1490 * Detect and try to read SYMBIOS and TEKRAM NVRAM.
1492 #if SYM_CONF_NVRAM_SUPPORT
1493 static void __devinit sym_get_nvram(struct sym_device *devp, struct sym_nvram *nvp)
1496 devp->device_id = devp->chip.device_id;
1499 sym_read_nvram(devp, nvp);
1502 static inline void sym_get_nvram(struct sym_device *devp, struct sym_nvram *nvp)
1505 #endif /* SYM_CONF_NVRAM_SUPPORT */
1507 static int __devinit sym_check_supported(struct sym_device *device)
1509 struct sym_chip *chip;
1510 struct pci_dev *pdev = device->pdev;
1512 unsigned long io_port = pci_resource_start(pdev, 0);
1516 * If user excluded this chip, do not initialize it.
1517 * I hate this code so much. Must kill it.
1520 for (i = 0 ; i < 8 ; i++) {
1521 if (sym_driver_setup.excludes[i] == io_port)
1527 * Check if the chip is supported. Then copy the chip description
1528 * to our device structure so we can make it match the actual device
1531 pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
1532 chip = sym_lookup_chip_table(pdev->device, revision);
1534 dev_info(&pdev->dev, "device not supported\n");
1537 memcpy(&device->chip, chip, sizeof(device->chip));
1538 device->chip.revision_id = revision;
1544 * Ignore Symbios chips controlled by various RAID controllers.
1545 * These controllers set value 0x52414944 at RAM end - 16.
1547 static int __devinit sym_check_raid(struct sym_device *device)
1549 unsigned int ram_size, ram_val;
1551 if (!device->s.ramaddr)
1554 if (device->chip.features & FE_RAM8K)
1559 ram_val = readl(device->s.ramaddr + ram_size - 16);
1560 if (ram_val != 0x52414944)
1563 dev_info(&device->pdev->dev,
1564 "not initializing, driven by RAID controller.\n");
1568 static int __devinit sym_set_workarounds(struct sym_device *device)
1570 struct sym_chip *chip = &device->chip;
1571 struct pci_dev *pdev = device->pdev;
1575 * (ITEM 12 of a DEL about the 896 I haven't yet).
1576 * We must ensure the chip will use WRITE AND INVALIDATE.
1577 * The revision number limit is for now arbitrary.
1579 if (pdev->device == PCI_DEVICE_ID_NCR_53C896 && chip->revision_id < 0x4) {
1580 chip->features |= (FE_WRIE | FE_CLSE);
1583 /* If the chip can do Memory Write Invalidate, enable it */
1584 if (chip->features & FE_WRIE) {
1585 if (pci_set_mwi(pdev))
1590 * Work around for errant bit in 895A. The 66Mhz
1591 * capable bit is set erroneously. Clear this bit.
1594 * Make sure Config space and Features agree.
1596 * Recall: writes are not normal to status register -
1597 * write a 1 to clear and a 0 to leave unchanged.
1598 * Can only reset bits.
1600 pci_read_config_word(pdev, PCI_STATUS, &status_reg);
1601 if (chip->features & FE_66MHZ) {
1602 if (!(status_reg & PCI_STATUS_66MHZ))
1603 chip->features &= ~FE_66MHZ;
1605 if (status_reg & PCI_STATUS_66MHZ) {
1606 status_reg = PCI_STATUS_66MHZ;
1607 pci_write_config_word(pdev, PCI_STATUS, status_reg);
1608 pci_read_config_word(pdev, PCI_STATUS, &status_reg);
1616 * Read and check the PCI configuration for any detected NCR
1617 * boards and save data for attaching after all boards have
1620 static void __devinit
1621 sym_init_device(struct pci_dev *pdev, struct sym_device *device)
1624 struct pci_bus_region bus_addr;
1626 device->host_id = SYM_SETUP_HOST_ID;
1627 device->pdev = pdev;
1629 pcibios_resource_to_bus(pdev, &bus_addr, &pdev->resource[1]);
1630 device->mmio_base = bus_addr.start;
1633 * If the BAR is 64-bit, resource 2 will be occupied by the
1636 if (!pdev->resource[i].flags)
1638 pcibios_resource_to_bus(pdev, &bus_addr, &pdev->resource[i]);
1639 device->ram_base = bus_addr.start;
1641 #ifdef CONFIG_SCSI_SYM53C8XX_MMIO
1642 if (device->mmio_base)
1643 device->s.ioaddr = pci_iomap(pdev, 1,
1644 pci_resource_len(pdev, 1));
1646 if (!device->s.ioaddr)
1647 device->s.ioaddr = pci_iomap(pdev, 0,
1648 pci_resource_len(pdev, 0));
1649 if (device->ram_base)
1650 device->s.ramaddr = pci_iomap(pdev, i,
1651 pci_resource_len(pdev, i));
1655 * The NCR PQS and PDS cards are constructed as a DEC bridge
1656 * behind which sits a proprietary NCR memory controller and
1657 * either four or two 53c875s as separate devices. We can tell
1658 * if an 875 is part of a PQS/PDS or not since if it is, it will
1659 * be on the same bus as the memory controller. In its usual
1660 * mode of operation, the 875s are slaved to the memory
1661 * controller for all transfers. To operate with the Linux
1662 * driver, the memory controller is disabled and the 875s
1663 * freed to function independently. The only wrinkle is that
1664 * the preset SCSI ID (which may be zero) must be read in from
1665 * a special configuration space register of the 875.
1667 static void sym_config_pqs(struct pci_dev *pdev, struct sym_device *sym_dev)
1672 for (slot = 0; slot < 256; slot++) {
1673 struct pci_dev *memc = pci_get_slot(pdev->bus, slot);
1675 if (!memc || memc->vendor != 0x101a || memc->device == 0x0009) {
1680 /* bit 1: allow individual 875 configuration */
1681 pci_read_config_byte(memc, 0x44, &tmp);
1682 if ((tmp & 0x2) == 0) {
1684 pci_write_config_byte(memc, 0x44, tmp);
1687 /* bit 2: drive individual 875 interrupts to the bus */
1688 pci_read_config_byte(memc, 0x45, &tmp);
1689 if ((tmp & 0x4) == 0) {
1691 pci_write_config_byte(memc, 0x45, tmp);
1698 pci_read_config_byte(pdev, 0x84, &tmp);
1699 sym_dev->host_id = tmp;
1703 * Called before unloading the module.
1705 * We have to free resources and halt the NCR chip.
1707 static int sym_detach(struct sym_hcb *np, struct pci_dev *pdev)
1709 printk("%s: detaching ...\n", sym_name(np));
1711 del_timer_sync(&np->s.timer);
1715 * We should use sym_soft_reset(), but we don't want to do
1716 * so, since we may not be safe if interrupts occur.
1718 printk("%s: resetting chip\n", sym_name(np));
1719 OUTB(np, nc_istat, SRST);
1722 OUTB(np, nc_istat, 0);
1724 sym_free_resources(np, pdev);
1730 * Driver host template.
1732 static struct scsi_host_template sym2_template = {
1733 .module = THIS_MODULE,
1734 .name = "sym53c8xx",
1735 .info = sym53c8xx_info,
1736 .queuecommand = sym53c8xx_queue_command,
1737 .slave_alloc = sym53c8xx_slave_alloc,
1738 .slave_configure = sym53c8xx_slave_configure,
1739 .slave_destroy = sym53c8xx_slave_destroy,
1740 .eh_abort_handler = sym53c8xx_eh_abort_handler,
1741 .eh_device_reset_handler = sym53c8xx_eh_device_reset_handler,
1742 .eh_bus_reset_handler = sym53c8xx_eh_bus_reset_handler,
1743 .eh_host_reset_handler = sym53c8xx_eh_host_reset_handler,
1745 .use_clustering = ENABLE_CLUSTERING,
1746 .use_sg_chaining = ENABLE_SG_CHAINING,
1747 .max_sectors = 0xFFFF,
1748 #ifdef SYM_LINUX_PROC_INFO_SUPPORT
1749 .proc_info = sym53c8xx_proc_info,
1750 .proc_name = NAME53C8XX,
1754 static int attach_count;
1756 static int __devinit sym2_probe(struct pci_dev *pdev,
1757 const struct pci_device_id *ent)
1759 struct sym_device sym_dev;
1760 struct sym_nvram nvram;
1761 struct Scsi_Host *instance;
1763 memset(&sym_dev, 0, sizeof(sym_dev));
1764 memset(&nvram, 0, sizeof(nvram));
1766 if (pci_enable_device(pdev))
1769 pci_set_master(pdev);
1771 if (pci_request_regions(pdev, NAME53C8XX))
1774 sym_init_device(pdev, &sym_dev);
1775 if (sym_check_supported(&sym_dev))
1778 if (sym_check_raid(&sym_dev))
1779 goto leave; /* Don't disable the device */
1781 if (sym_set_workarounds(&sym_dev))
1784 sym_config_pqs(pdev, &sym_dev);
1786 sym_get_nvram(&sym_dev, &nvram);
1788 instance = sym_attach(&sym2_template, attach_count, &sym_dev);
1792 if (scsi_add_host(instance, &pdev->dev))
1794 scsi_scan_host(instance);
1801 sym_detach(pci_get_drvdata(pdev), pdev);
1803 pci_release_regions(pdev);
1805 pci_disable_device(pdev);
1810 static void __devexit sym2_remove(struct pci_dev *pdev)
1812 struct sym_hcb *np = pci_get_drvdata(pdev);
1813 struct Scsi_Host *host = np->s.host;
1815 scsi_remove_host(host);
1816 scsi_host_put(host);
1818 sym_detach(np, pdev);
1820 pci_release_regions(pdev);
1821 pci_disable_device(pdev);
1826 static void sym2_get_signalling(struct Scsi_Host *shost)
1828 struct sym_hcb *np = sym_get_hcb(shost);
1829 enum spi_signal_type type;
1831 switch (np->scsi_mode) {
1833 type = SPI_SIGNAL_SE;
1836 type = SPI_SIGNAL_LVD;
1839 type = SPI_SIGNAL_HVD;
1842 type = SPI_SIGNAL_UNKNOWN;
1845 spi_signalling(shost) = type;
1848 static void sym2_set_offset(struct scsi_target *starget, int offset)
1850 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1851 struct sym_hcb *np = sym_get_hcb(shost);
1852 struct sym_tcb *tp = &np->target[starget->id];
1854 tp->tgoal.offset = offset;
1855 tp->tgoal.check_nego = 1;
1858 static void sym2_set_period(struct scsi_target *starget, int period)
1860 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1861 struct sym_hcb *np = sym_get_hcb(shost);
1862 struct sym_tcb *tp = &np->target[starget->id];
1864 /* have to have DT for these transfers, but DT will also
1865 * set width, so check that this is allowed */
1866 if (period <= np->minsync && spi_width(starget))
1869 tp->tgoal.period = period;
1870 tp->tgoal.check_nego = 1;
1873 static void sym2_set_width(struct scsi_target *starget, int width)
1875 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1876 struct sym_hcb *np = sym_get_hcb(shost);
1877 struct sym_tcb *tp = &np->target[starget->id];
1879 /* It is illegal to have DT set on narrow transfers. If DT is
1880 * clear, we must also clear IU and QAS. */
1882 tp->tgoal.iu = tp->tgoal.dt = tp->tgoal.qas = 0;
1884 tp->tgoal.width = width;
1885 tp->tgoal.check_nego = 1;
1888 static void sym2_set_dt(struct scsi_target *starget, int dt)
1890 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1891 struct sym_hcb *np = sym_get_hcb(shost);
1892 struct sym_tcb *tp = &np->target[starget->id];
1894 /* We must clear QAS and IU if DT is clear */
1898 tp->tgoal.iu = tp->tgoal.dt = tp->tgoal.qas = 0;
1899 tp->tgoal.check_nego = 1;
1903 static void sym2_set_iu(struct scsi_target *starget, int iu)
1905 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1906 struct sym_hcb *np = sym_get_hcb(shost);
1907 struct sym_tcb *tp = &np->target[starget->id];
1910 tp->tgoal.iu = tp->tgoal.dt = 1;
1913 tp->tgoal.check_nego = 1;
1916 static void sym2_set_qas(struct scsi_target *starget, int qas)
1918 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1919 struct sym_hcb *np = sym_get_hcb(shost);
1920 struct sym_tcb *tp = &np->target[starget->id];
1923 tp->tgoal.dt = tp->tgoal.qas = 1;
1926 tp->tgoal.check_nego = 1;
1930 static struct spi_function_template sym2_transport_functions = {
1931 .set_offset = sym2_set_offset,
1933 .set_period = sym2_set_period,
1935 .set_width = sym2_set_width,
1937 .set_dt = sym2_set_dt,
1940 .set_iu = sym2_set_iu,
1942 .set_qas = sym2_set_qas,
1945 .get_signalling = sym2_get_signalling,
1948 static struct pci_device_id sym2_id_table[] __devinitdata = {
1949 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C810,
1950 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
1951 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C820,
1952 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, /* new */
1953 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C825,
1954 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
1955 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C815,
1956 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
1957 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C810AP,
1958 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, /* new */
1959 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C860,
1960 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
1961 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1510,
1962 PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_SCSI<<8, 0xffff00, 0UL },
1963 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C896,
1964 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
1965 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C895,
1966 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
1967 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C885,
1968 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
1969 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C875,
1970 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
1971 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C1510,
1972 PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_SCSI<<8, 0xffff00, 0UL }, /* new */
1973 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C895A,
1974 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
1975 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C875A,
1976 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
1977 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1010_33,
1978 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
1979 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1010_66,
1980 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
1981 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C875J,
1982 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
1986 MODULE_DEVICE_TABLE(pci, sym2_id_table);
1988 static struct pci_driver sym2_driver = {
1990 .id_table = sym2_id_table,
1991 .probe = sym2_probe,
1992 .remove = __devexit_p(sym2_remove),
1995 static int __init sym2_init(void)
1999 sym2_setup_params();
2000 sym2_transport_template = spi_attach_transport(&sym2_transport_functions);
2001 if (!sym2_transport_template)
2004 error = pci_register_driver(&sym2_driver);
2006 spi_release_transport(sym2_transport_template);
2010 static void __exit sym2_exit(void)
2012 pci_unregister_driver(&sym2_driver);
2013 spi_release_transport(sym2_transport_template);
2016 module_init(sym2_init);
2017 module_exit(sym2_exit);