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"
57 /* SPARC just has to be different ... */
60 #define IRQ_PRM(x) __irq_itoa(x)
63 #define IRQ_PRM(x) (x)
66 struct sym_driver_setup sym_driver_setup = SYM_LINUX_DRIVER_SETUP;
67 unsigned int sym_debug_flags = 0;
69 static char *excl_string;
70 static char *safe_string;
71 module_param_named(cmd_per_lun, sym_driver_setup.max_tag, ushort, 0);
72 module_param_string(tag_ctrl, sym_driver_setup.tag_ctrl, 100, 0);
73 module_param_named(burst, sym_driver_setup.burst_order, byte, 0);
74 module_param_named(led, sym_driver_setup.scsi_led, byte, 0);
75 module_param_named(diff, sym_driver_setup.scsi_diff, byte, 0);
76 module_param_named(irqm, sym_driver_setup.irq_mode, byte, 0);
77 module_param_named(buschk, sym_driver_setup.scsi_bus_check, byte, 0);
78 module_param_named(hostid, sym_driver_setup.host_id, byte, 0);
79 module_param_named(verb, sym_driver_setup.verbose, byte, 0);
80 module_param_named(debug, sym_debug_flags, uint, 0);
81 module_param_named(settle, sym_driver_setup.settle_delay, byte, 0);
82 module_param_named(nvram, sym_driver_setup.use_nvram, byte, 0);
83 module_param_named(excl, excl_string, charp, 0);
84 module_param_named(safe, safe_string, charp, 0);
86 MODULE_PARM_DESC(cmd_per_lun, "The maximum number of tags to use by default");
87 MODULE_PARM_DESC(tag_ctrl, "More detailed control over tags per LUN");
88 MODULE_PARM_DESC(burst, "Maximum burst. 0 to disable, 255 to read from registers");
89 MODULE_PARM_DESC(led, "Set to 1 to enable LED support");
90 MODULE_PARM_DESC(diff, "0 for no differential mode, 1 for BIOS, 2 for always, 3 for not GPIO3");
91 MODULE_PARM_DESC(irqm, "0 for open drain, 1 to leave alone, 2 for totem pole");
92 MODULE_PARM_DESC(buschk, "0 to not check, 1 for detach on error, 2 for warn on error");
93 MODULE_PARM_DESC(hostid, "The SCSI ID to use for the host adapters");
94 MODULE_PARM_DESC(verb, "0 for minimal verbosity, 1 for normal, 2 for excessive");
95 MODULE_PARM_DESC(debug, "Set bits to enable debugging");
96 MODULE_PARM_DESC(settle, "Settle delay in seconds. Default 3");
97 MODULE_PARM_DESC(nvram, "Option currently not used");
98 MODULE_PARM_DESC(excl, "List ioport addresses here to prevent controllers from being attached");
99 MODULE_PARM_DESC(safe, "Set other settings to a \"safe mode\"");
101 MODULE_LICENSE("GPL");
102 MODULE_VERSION(SYM_VERSION);
103 MODULE_AUTHOR("Matthew Wilcox <matthew@wil.cx>");
104 MODULE_DESCRIPTION("NCR, Symbios and LSI 8xx and 1010 PCI SCSI adapters");
106 static void sym2_setup_params(void)
108 char *p = excl_string;
111 while (p && (xi < 8)) {
113 int val = (int) simple_strtoul(p, &next_p, 0);
114 sym_driver_setup.excludes[xi++] = val;
119 if (*safe_string == 'y') {
120 sym_driver_setup.max_tag = 0;
121 sym_driver_setup.burst_order = 0;
122 sym_driver_setup.scsi_led = 0;
123 sym_driver_setup.scsi_diff = 1;
124 sym_driver_setup.irq_mode = 0;
125 sym_driver_setup.scsi_bus_check = 2;
126 sym_driver_setup.host_id = 7;
127 sym_driver_setup.verbose = 2;
128 sym_driver_setup.settle_delay = 10;
129 sym_driver_setup.use_nvram = 1;
130 } else if (*safe_string != 'n') {
131 printk(KERN_WARNING NAME53C8XX "Ignoring parameter %s"
132 " passed to safe option", safe_string);
137 static struct scsi_transport_template *sym2_transport_template = NULL;
140 * Driver private area in the SCSI command structure.
142 struct sym_ucmd { /* Override the SCSI pointer structure */
143 dma_addr_t data_mapping;
144 unsigned char data_mapped;
145 unsigned char to_do; /* For error handling */
146 void (*old_done)(struct scsi_cmnd *); /* For error handling */
147 struct completion *eh_done; /* For error handling */
150 #define SYM_UCMD_PTR(cmd) ((struct sym_ucmd *)(&(cmd)->SCp))
151 #define SYM_SOFTC_PTR(cmd) sym_get_hcb(cmd->device->host)
153 static void __unmap_scsi_data(struct pci_dev *pdev, struct scsi_cmnd *cmd)
155 int dma_dir = cmd->sc_data_direction;
157 switch(SYM_UCMD_PTR(cmd)->data_mapped) {
159 pci_unmap_sg(pdev, cmd->buffer, cmd->use_sg, dma_dir);
162 pci_unmap_single(pdev, SYM_UCMD_PTR(cmd)->data_mapping,
163 cmd->request_bufflen, dma_dir);
166 SYM_UCMD_PTR(cmd)->data_mapped = 0;
169 static dma_addr_t __map_scsi_single_data(struct pci_dev *pdev, struct scsi_cmnd *cmd)
172 int dma_dir = cmd->sc_data_direction;
174 mapping = pci_map_single(pdev, cmd->request_buffer,
175 cmd->request_bufflen, dma_dir);
177 SYM_UCMD_PTR(cmd)->data_mapped = 1;
178 SYM_UCMD_PTR(cmd)->data_mapping = mapping;
184 static int __map_scsi_sg_data(struct pci_dev *pdev, struct scsi_cmnd *cmd)
187 int dma_dir = cmd->sc_data_direction;
189 use_sg = pci_map_sg(pdev, cmd->buffer, cmd->use_sg, dma_dir);
191 SYM_UCMD_PTR(cmd)->data_mapped = 2;
192 SYM_UCMD_PTR(cmd)->data_mapping = use_sg;
198 #define unmap_scsi_data(np, cmd) \
199 __unmap_scsi_data(np->s.device, cmd)
200 #define map_scsi_single_data(np, cmd) \
201 __map_scsi_single_data(np->s.device, cmd)
202 #define map_scsi_sg_data(np, cmd) \
203 __map_scsi_sg_data(np->s.device, cmd)
205 * Complete a pending CAM CCB.
207 void sym_xpt_done(struct sym_hcb *np, struct scsi_cmnd *cmd)
209 unmap_scsi_data(np, cmd);
213 static void sym_xpt_done2(struct sym_hcb *np, struct scsi_cmnd *cmd, int cam_status)
215 sym_set_cam_status(cmd, cam_status);
216 sym_xpt_done(np, cmd);
221 * Tell the SCSI layer about a BUS RESET.
223 void sym_xpt_async_bus_reset(struct sym_hcb *np)
225 printf_notice("%s: SCSI BUS has been reset.\n", sym_name(np));
226 np->s.settle_time = jiffies + sym_driver_setup.settle_delay * HZ;
227 np->s.settle_time_valid = 1;
228 if (sym_verbose >= 2)
229 printf_info("%s: command processing suspended for %d seconds\n",
230 sym_name(np), sym_driver_setup.settle_delay);
234 * Tell the SCSI layer about a BUS DEVICE RESET message sent.
236 void sym_xpt_async_sent_bdr(struct sym_hcb *np, int target)
238 printf_notice("%s: TARGET %d has been reset.\n", sym_name(np), target);
242 * Choose the more appropriate CAM status if
243 * the IO encountered an extended error.
245 static int sym_xerr_cam_status(int cam_status, int x_status)
248 if (x_status & XE_PARITY_ERR)
249 cam_status = DID_PARITY;
250 else if (x_status &(XE_EXTRA_DATA|XE_SODL_UNRUN|XE_SWIDE_OVRUN))
251 cam_status = DID_ERROR;
252 else if (x_status & XE_BAD_PHASE)
253 cam_status = DID_ERROR;
255 cam_status = DID_ERROR;
261 * Build CAM result for a failed or auto-sensed IO.
263 void sym_set_cam_result_error(struct sym_hcb *np, struct sym_ccb *cp, int resid)
265 struct scsi_cmnd *cmd = cp->cmd;
266 u_int cam_status, scsi_status, drv_status;
270 scsi_status = cp->ssss_status;
272 if (cp->host_flags & HF_SENSE) {
273 scsi_status = cp->sv_scsi_status;
274 resid = cp->sv_resid;
275 if (sym_verbose && cp->sv_xerr_status)
276 sym_print_xerr(cmd, cp->sv_xerr_status);
277 if (cp->host_status == HS_COMPLETE &&
278 cp->ssss_status == S_GOOD &&
279 cp->xerr_status == 0) {
280 cam_status = sym_xerr_cam_status(DID_OK,
282 drv_status = DRIVER_SENSE;
284 * Bounce back the sense data to user.
286 memset(&cmd->sense_buffer, 0, sizeof(cmd->sense_buffer));
287 memcpy(cmd->sense_buffer, cp->sns_bbuf,
288 min(sizeof(cmd->sense_buffer),
289 (size_t)SYM_SNS_BBUF_LEN));
292 * If the device reports a UNIT ATTENTION condition
293 * due to a RESET condition, we should consider all
294 * disconnect CCBs for this unit as aborted.
298 p = (u_char *) cmd->sense_data;
299 if (p[0]==0x70 && p[2]==0x6 && p[12]==0x29)
300 sym_clear_tasks(np, DID_ABORT,
301 cp->target,cp->lun, -1);
306 * Error return from our internal request sense. This
307 * is bad: we must clear the contingent allegiance
308 * condition otherwise the device will always return
309 * BUSY. Use a big stick.
311 sym_reset_scsi_target(np, cmd->device->id);
312 cam_status = DID_ERROR;
314 } else if (cp->host_status == HS_COMPLETE) /* Bad SCSI status */
316 else if (cp->host_status == HS_SEL_TIMEOUT) /* Selection timeout */
317 cam_status = DID_NO_CONNECT;
318 else if (cp->host_status == HS_UNEXPECTED) /* Unexpected BUS FREE*/
319 cam_status = DID_ERROR;
320 else { /* Extended error */
322 sym_print_addr(cmd, "COMMAND FAILED (%x %x %x).\n",
323 cp->host_status, cp->ssss_status,
327 * Set the most appropriate value for CAM status.
329 cam_status = sym_xerr_cam_status(DID_ERROR, cp->xerr_status);
332 cmd->result = (drv_status << 24) + (cam_status << 16) + scsi_status;
337 * Build the scatter/gather array for an I/O.
340 static int sym_scatter_no_sglist(struct sym_hcb *np, struct sym_ccb *cp, struct scsi_cmnd *cmd)
342 struct sym_tblmove *data = &cp->phys.data[SYM_CONF_MAX_SG-1];
344 unsigned int len = cmd->request_bufflen;
347 dma_addr_t baddr = map_scsi_single_data(np, cmd);
350 struct sym_tcb *tp = &np->target[cp->target];
351 if (tp->head.wval & EWS) {
353 cp->odd_byte_adjustment++;
357 sym_build_sge(np, data, baddr, len);
369 static int sym_scatter(struct sym_hcb *np, struct sym_ccb *cp, struct scsi_cmnd *cmd)
372 int use_sg = (int) cmd->use_sg;
377 segment = sym_scatter_no_sglist(np, cp, cmd);
378 else if ((use_sg = map_scsi_sg_data(np, cmd)) > 0) {
379 struct scatterlist *scatter = (struct scatterlist *)cmd->buffer;
380 struct sym_tcb *tp = &np->target[cp->target];
381 struct sym_tblmove *data;
383 if (use_sg > SYM_CONF_MAX_SG) {
384 unmap_scsi_data(np, cmd);
388 data = &cp->phys.data[SYM_CONF_MAX_SG - use_sg];
390 for (segment = 0; segment < use_sg; segment++) {
391 dma_addr_t baddr = sg_dma_address(&scatter[segment]);
392 unsigned int len = sg_dma_len(&scatter[segment]);
394 if ((len & 1) && (tp->head.wval & EWS)) {
396 cp->odd_byte_adjustment++;
399 sym_build_sge(np, &data[segment], baddr, len);
410 * Queue a SCSI command.
412 static int sym_queue_command(struct sym_hcb *np, struct scsi_cmnd *cmd)
414 struct scsi_device *sdev = cmd->device;
421 * Minimal checkings, so that we will not
422 * go outside our tables.
424 if (sdev->id == np->myaddr) {
425 sym_xpt_done2(np, cmd, DID_NO_CONNECT);
430 * Retrieve the target descriptor.
432 tp = &np->target[sdev->id];
435 * Select tagged/untagged.
437 lp = sym_lp(tp, sdev->lun);
438 order = (lp && lp->s.reqtags) ? M_SIMPLE_TAG : 0;
443 cp = sym_get_ccb(np, cmd, order);
445 return 1; /* Means resource shortage */
446 sym_queue_scsiio(np, cmd, cp);
451 * Setup buffers and pointers that address the CDB.
453 static inline int sym_setup_cdb(struct sym_hcb *np, struct scsi_cmnd *cmd, struct sym_ccb *cp)
455 memcpy(cp->cdb_buf, cmd->cmnd, cmd->cmd_len);
457 cp->phys.cmd.addr = CCB_BA(cp, cdb_buf[0]);
458 cp->phys.cmd.size = cpu_to_scr(cmd->cmd_len);
464 * Setup pointers that address the data and start the I/O.
466 int sym_setup_data_and_start(struct sym_hcb *np, struct scsi_cmnd *cmd, struct sym_ccb *cp)
474 if (sym_setup_cdb(np, cmd, cp))
478 * No direction means no data.
480 dir = cmd->sc_data_direction;
481 if (dir != DMA_NONE) {
482 cp->segments = sym_scatter(np, cp, cmd);
483 if (cp->segments < 0) {
484 sym_set_cam_status(cmd, DID_ERROR);
489 * No segments means no data.
499 * Set the data pointer.
502 case DMA_BIDIRECTIONAL:
503 printk("%s: got DMA_BIDIRECTIONAL command", sym_name(np));
504 sym_set_cam_status(cmd, DID_ERROR);
507 goalp = SCRIPTA_BA(np, data_out2) + 8;
508 lastp = goalp - 8 - (cp->segments * (2*4));
510 case DMA_FROM_DEVICE:
511 cp->host_flags |= HF_DATA_IN;
512 goalp = SCRIPTA_BA(np, data_in2) + 8;
513 lastp = goalp - 8 - (cp->segments * (2*4));
517 lastp = goalp = SCRIPTB_BA(np, no_data);
522 * Set all pointers values needed by SCRIPTS.
524 cp->phys.head.lastp = cpu_to_scr(lastp);
525 cp->phys.head.savep = cpu_to_scr(lastp);
526 cp->startp = cp->phys.head.savep;
527 cp->goalp = cpu_to_scr(goalp);
530 * When `#ifed 1', the code below makes the driver
531 * panic on the first attempt to write to a SCSI device.
532 * It is the first test we want to do after a driver
533 * change that does not seem obviously safe. :)
536 switch (cp->cdb_buf[0]) {
537 case 0x0A: case 0x2A: case 0xAA:
538 panic("XXXXXXXXXXXXX WRITE NOT YET ALLOWED XXXXXXXXXXXXXX\n");
548 sym_put_start_queue(np, cp);
552 sym_free_ccb(np, cp);
553 sym_xpt_done(np, cmd);
561 * Misused to keep the driver running when
562 * interrupts are not configured correctly.
564 static void sym_timer(struct sym_hcb *np)
566 unsigned long thistime = jiffies;
571 np->s.timer.expires = thistime + SYM_CONF_TIMER_INTERVAL;
572 add_timer(&np->s.timer);
575 * If we are resetting the ncr, wait for settle_time before
576 * clearing it. Then command processing will be resumed.
578 if (np->s.settle_time_valid) {
579 if (time_before_eq(np->s.settle_time, thistime)) {
580 if (sym_verbose >= 2 )
581 printk("%s: command processing resumed\n",
583 np->s.settle_time_valid = 0;
589 * Nothing to do for now, but that may come.
591 if (np->s.lasttime + 4*HZ < thistime) {
592 np->s.lasttime = thistime;
595 #ifdef SYM_CONF_PCIQ_MAY_MISS_COMPLETIONS
597 * Some way-broken PCI bridges may lead to
598 * completions being lost when the clearing
599 * of the INTFLY flag by the CPU occurs
600 * concurrently with the chip raising this flag.
601 * If this ever happen, lost completions will
610 * PCI BUS error handler.
612 void sym_log_bus_error(struct sym_hcb *np)
615 pci_read_config_word(np->s.device, PCI_STATUS, &pci_sts);
616 if (pci_sts & 0xf900) {
617 pci_write_config_word(np->s.device, PCI_STATUS, pci_sts);
618 printf("%s: PCI STATUS = 0x%04x\n",
619 sym_name(np), pci_sts & 0xf900);
624 * queuecommand method. Entered with the host adapter lock held and
625 * interrupts disabled.
627 static int sym53c8xx_queue_command(struct scsi_cmnd *cmd,
628 void (*done)(struct scsi_cmnd *))
630 struct sym_hcb *np = SYM_SOFTC_PTR(cmd);
631 struct sym_ucmd *ucp = SYM_UCMD_PTR(cmd);
634 cmd->scsi_done = done;
635 memset(ucp, 0, sizeof(*ucp));
638 * Shorten our settle_time if needed for
639 * this command not to time out.
641 if (np->s.settle_time_valid && cmd->timeout_per_command) {
642 unsigned long tlimit = jiffies + cmd->timeout_per_command;
643 tlimit -= SYM_CONF_TIMER_INTERVAL*2;
644 if (time_after(np->s.settle_time, tlimit)) {
645 np->s.settle_time = tlimit;
649 if (np->s.settle_time_valid)
650 return SCSI_MLQUEUE_HOST_BUSY;
652 sts = sym_queue_command(np, cmd);
654 return SCSI_MLQUEUE_HOST_BUSY;
659 * Linux entry point of the interrupt handler.
661 static irqreturn_t sym53c8xx_intr(int irq, void *dev_id, struct pt_regs * regs)
664 struct sym_hcb *np = (struct sym_hcb *)dev_id;
666 if (DEBUG_FLAGS & DEBUG_TINY) printf_debug ("[");
668 spin_lock_irqsave(np->s.host->host_lock, flags);
670 spin_unlock_irqrestore(np->s.host->host_lock, flags);
672 if (DEBUG_FLAGS & DEBUG_TINY) printf_debug ("]\n");
678 * Linux entry point of the timer handler
680 static void sym53c8xx_timer(unsigned long npref)
682 struct sym_hcb *np = (struct sym_hcb *)npref;
685 spin_lock_irqsave(np->s.host->host_lock, flags);
687 spin_unlock_irqrestore(np->s.host->host_lock, flags);
692 * What the eh thread wants us to perform.
694 #define SYM_EH_ABORT 0
695 #define SYM_EH_DEVICE_RESET 1
696 #define SYM_EH_BUS_RESET 2
697 #define SYM_EH_HOST_RESET 3
700 * What we will do regarding the involved SCSI command.
702 #define SYM_EH_DO_IGNORE 0
703 #define SYM_EH_DO_WAIT 2
706 * scsi_done() alias when error recovery is in progress.
708 static void sym_eh_done(struct scsi_cmnd *cmd)
710 struct sym_ucmd *ucmd = SYM_UCMD_PTR(cmd);
711 BUILD_BUG_ON(sizeof(struct scsi_pointer) < sizeof(struct sym_ucmd));
713 cmd->scsi_done = ucmd->old_done;
715 if (ucmd->to_do == SYM_EH_DO_WAIT)
716 complete(ucmd->eh_done);
720 * Generic method for our eh processing.
721 * The 'op' argument tells what we have to do.
723 static int sym_eh_handler(int op, char *opname, struct scsi_cmnd *cmd)
725 struct sym_hcb *np = SYM_SOFTC_PTR(cmd);
726 struct sym_ucmd *ucmd = SYM_UCMD_PTR(cmd);
727 struct Scsi_Host *host = cmd->device->host;
729 int to_do = SYM_EH_DO_IGNORE;
731 struct completion eh_done;
733 dev_warn(&cmd->device->sdev_gendev, "%s operation started.\n", opname);
735 spin_lock_irq(host->host_lock);
736 /* This one is queued in some place -> to wait for completion */
737 FOR_EACH_QUEUED_ELEMENT(&np->busy_ccbq, qp) {
738 struct sym_ccb *cp = sym_que_entry(qp, struct sym_ccb, link_ccbq);
739 if (cp->cmd == cmd) {
740 to_do = SYM_EH_DO_WAIT;
745 if (to_do == SYM_EH_DO_WAIT) {
746 init_completion(&eh_done);
747 ucmd->old_done = cmd->scsi_done;
748 ucmd->eh_done = &eh_done;
750 cmd->scsi_done = sym_eh_done;
753 /* Try to proceed the operation we have been asked for */
757 sts = sym_abort_scsiio(np, cmd, 1);
759 case SYM_EH_DEVICE_RESET:
760 sts = sym_reset_scsi_target(np, cmd->device->id);
762 case SYM_EH_BUS_RESET:
763 sym_reset_scsi_bus(np, 1);
766 case SYM_EH_HOST_RESET:
767 sym_reset_scsi_bus(np, 0);
768 sym_start_up (np, 1);
775 /* On error, restore everything and cross fingers :) */
777 cmd->scsi_done = ucmd->old_done;
778 to_do = SYM_EH_DO_IGNORE;
782 spin_unlock_irq(host->host_lock);
784 if (to_do == SYM_EH_DO_WAIT) {
785 if (!wait_for_completion_timeout(&eh_done, 5*HZ)) {
786 ucmd->to_do = SYM_EH_DO_IGNORE;
791 dev_warn(&cmd->device->sdev_gendev, "%s operation %s.\n", opname,
792 sts==0 ? "complete" :sts==-2 ? "timed-out" : "failed");
793 return sts ? SCSI_FAILED : SCSI_SUCCESS;
798 * Error handlers called from the eh thread (one thread per HBA).
800 static int sym53c8xx_eh_abort_handler(struct scsi_cmnd *cmd)
802 return sym_eh_handler(SYM_EH_ABORT, "ABORT", cmd);
805 static int sym53c8xx_eh_device_reset_handler(struct scsi_cmnd *cmd)
807 return sym_eh_handler(SYM_EH_DEVICE_RESET, "DEVICE RESET", cmd);
810 static int sym53c8xx_eh_bus_reset_handler(struct scsi_cmnd *cmd)
812 return sym_eh_handler(SYM_EH_BUS_RESET, "BUS RESET", cmd);
815 static int sym53c8xx_eh_host_reset_handler(struct scsi_cmnd *cmd)
817 return sym_eh_handler(SYM_EH_HOST_RESET, "HOST RESET", cmd);
821 * Tune device queuing depth, according to various limits.
823 static void sym_tune_dev_queuing(struct sym_tcb *tp, int lun, u_short reqtags)
825 struct sym_lcb *lp = sym_lp(tp, lun);
831 oldtags = lp->s.reqtags;
833 if (reqtags > lp->s.scdev_depth)
834 reqtags = lp->s.scdev_depth;
836 lp->s.reqtags = reqtags;
838 if (reqtags != oldtags) {
839 dev_info(&tp->starget->dev,
840 "tagged command queuing %s, command queue depth %d.\n",
841 lp->s.reqtags ? "enabled" : "disabled", reqtags);
846 * Linux select queue depths function
848 #define DEF_DEPTH (sym_driver_setup.max_tag)
849 #define ALL_TARGETS -2
854 static int device_queue_depth(struct sym_hcb *np, int target, int lun)
857 char *p = sym_driver_setup.tag_ctrl;
863 while ((c = *p++) != 0) {
864 v = simple_strtoul(p, &ep, 0);
873 t = (target == v) ? v : NO_TARGET;
878 u = (lun == v) ? v : NO_LUN;
881 if (h == np->s.unit &&
882 (t == ALL_TARGETS || t == target) &&
883 (u == ALL_LUNS || u == lun))
898 static int sym53c8xx_slave_alloc(struct scsi_device *sdev)
900 struct sym_hcb *np = sym_get_hcb(sdev->host);
901 struct sym_tcb *tp = &np->target[sdev->id];
904 if (sdev->id >= SYM_CONF_MAX_TARGET || sdev->lun >= SYM_CONF_MAX_LUN)
907 tp->starget = sdev->sdev_target;
909 * Fail the device init if the device is flagged NOSCAN at BOOT in
910 * the NVRAM. This may speed up boot and maintain coherency with
911 * BIOS device numbering. Clearing the flag allows the user to
912 * rescan skipped devices later. We also return an error for
913 * devices not flagged for SCAN LUNS in the NVRAM since some single
914 * lun devices behave badly when asked for a non zero LUN.
917 if (tp->usrflags & SYM_SCAN_BOOT_DISABLED) {
918 tp->usrflags &= ~SYM_SCAN_BOOT_DISABLED;
919 starget_printk(KERN_INFO, tp->starget,
920 "Scan at boot disabled in NVRAM\n");
924 if (tp->usrflags & SYM_SCAN_LUNS_DISABLED) {
927 starget_printk(KERN_INFO, tp->starget,
928 "Multiple LUNs disabled in NVRAM\n");
931 lp = sym_alloc_lcb(np, sdev->id, sdev->lun);
935 spi_min_period(tp->starget) = tp->usr_period;
936 spi_max_width(tp->starget) = tp->usr_width;
942 * Linux entry point for device queue sizing.
944 static int sym53c8xx_slave_configure(struct scsi_device *sdev)
946 struct sym_hcb *np = sym_get_hcb(sdev->host);
947 struct sym_tcb *tp = &np->target[sdev->id];
948 struct sym_lcb *lp = sym_lp(tp, sdev->lun);
949 int reqtags, depth_to_use;
954 lp->curr_flags = lp->user_flags;
957 * Select queue depth from driver setup.
958 * Donnot use more than configured by user.
960 * Donnot use more than our maximum.
962 reqtags = device_queue_depth(np, sdev->id, sdev->lun);
963 if (reqtags > tp->usrtags)
964 reqtags = tp->usrtags;
965 if (!sdev->tagged_supported)
967 #if 1 /* Avoid to locally queue commands for no good reasons */
968 if (reqtags > SYM_CONF_MAX_TAG)
969 reqtags = SYM_CONF_MAX_TAG;
970 depth_to_use = (reqtags ? reqtags : 2);
972 depth_to_use = (reqtags ? SYM_CONF_MAX_TAG : 2);
974 scsi_adjust_queue_depth(sdev,
975 (sdev->tagged_supported ?
978 lp->s.scdev_depth = depth_to_use;
979 sym_tune_dev_queuing(tp, sdev->lun, reqtags);
981 if (!spi_initial_dv(sdev->sdev_target))
987 static void sym53c8xx_slave_destroy(struct scsi_device *sdev)
989 struct sym_hcb *np = sym_get_hcb(sdev->host);
990 struct sym_lcb *lp = sym_lp(&np->target[sdev->id], sdev->lun);
993 sym_mfree_dma(lp->itlq_tbl, SYM_CONF_MAX_TASK * 4, "ITLQ_TBL");
995 sym_mfree_dma(lp, sizeof(*lp), "LCB");
999 * Linux entry point for info() function
1001 static const char *sym53c8xx_info (struct Scsi_Host *host)
1003 return SYM_DRIVER_NAME;
1007 #ifdef SYM_LINUX_PROC_INFO_SUPPORT
1009 * Proc file system stuff
1011 * A read operation returns adapter information.
1012 * A write operation is a control command.
1013 * The string is parsed in the driver code and the command is passed
1014 * to the sym_usercmd() function.
1017 #ifdef SYM_LINUX_USER_COMMAND_SUPPORT
1026 #define UC_SETSYNC 10
1027 #define UC_SETTAGS 11
1028 #define UC_SETDEBUG 12
1029 #define UC_SETWIDE 14
1030 #define UC_SETFLAG 15
1031 #define UC_SETVERBOSE 17
1032 #define UC_RESETDEV 18
1033 #define UC_CLEARDEV 19
1035 static void sym_exec_user_command (struct sym_hcb *np, struct sym_usrcmd *uc)
1043 #ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
1045 sym_debug_flags = uc->data;
1049 np->verbose = uc->data;
1053 * We assume that other commands apply to targets.
1054 * This should always be the case and avoid the below
1055 * 4 lines to be repeated 6 times.
1057 for (t = 0; t < SYM_CONF_MAX_TARGET; t++) {
1058 if (!((uc->target >> t) & 1))
1060 tp = &np->target[t];
1065 if (!uc->data || uc->data >= 255) {
1066 tp->tgoal.iu = tp->tgoal.dt =
1068 tp->tgoal.offset = 0;
1069 } else if (uc->data <= 9 && np->minsync_dt) {
1070 if (uc->data < np->minsync_dt)
1071 uc->data = np->minsync_dt;
1072 tp->tgoal.iu = tp->tgoal.dt =
1074 tp->tgoal.width = 1;
1075 tp->tgoal.period = uc->data;
1076 tp->tgoal.offset = np->maxoffs_dt;
1078 if (uc->data < np->minsync)
1079 uc->data = np->minsync;
1080 tp->tgoal.iu = tp->tgoal.dt =
1082 tp->tgoal.period = uc->data;
1083 tp->tgoal.offset = np->maxoffs;
1085 tp->tgoal.check_nego = 1;
1088 tp->tgoal.width = uc->data ? 1 : 0;
1089 tp->tgoal.check_nego = 1;
1092 for (l = 0; l < SYM_CONF_MAX_LUN; l++)
1093 sym_tune_dev_queuing(tp, l, uc->data);
1097 np->istat_sem = SEM;
1098 OUTB(np, nc_istat, SIGP|SEM);
1101 for (l = 0; l < SYM_CONF_MAX_LUN; l++) {
1102 struct sym_lcb *lp = sym_lp(tp, l);
1103 if (lp) lp->to_clear = 1;
1105 np->istat_sem = SEM;
1106 OUTB(np, nc_istat, SIGP|SEM);
1109 tp->usrflags = uc->data;
1117 static int skip_spaces(char *ptr, int len)
1121 for (cnt = len; cnt > 0 && (c = *ptr++) && isspace(c); cnt--);
1126 static int get_int_arg(char *ptr, int len, u_long *pv)
1130 *pv = simple_strtoul(ptr, &end, 10);
1134 static int is_keyword(char *ptr, int len, char *verb)
1136 int verb_len = strlen(verb);
1138 if (len >= verb_len && !memcmp(verb, ptr, verb_len))
1144 #define SKIP_SPACES(ptr, len) \
1145 if ((arg_len = skip_spaces(ptr, len)) < 1) \
1147 ptr += arg_len; len -= arg_len;
1149 #define GET_INT_ARG(ptr, len, v) \
1150 if (!(arg_len = get_int_arg(ptr, len, &(v)))) \
1152 ptr += arg_len; len -= arg_len;
1156 * Parse a control command
1159 static int sym_user_command(struct sym_hcb *np, char *buffer, int length)
1163 struct sym_usrcmd cmd, *uc = &cmd;
1167 memset(uc, 0, sizeof(*uc));
1169 if (len > 0 && ptr[len-1] == '\n')
1172 if ((arg_len = is_keyword(ptr, len, "setsync")) != 0)
1173 uc->cmd = UC_SETSYNC;
1174 else if ((arg_len = is_keyword(ptr, len, "settags")) != 0)
1175 uc->cmd = UC_SETTAGS;
1176 else if ((arg_len = is_keyword(ptr, len, "setverbose")) != 0)
1177 uc->cmd = UC_SETVERBOSE;
1178 else if ((arg_len = is_keyword(ptr, len, "setwide")) != 0)
1179 uc->cmd = UC_SETWIDE;
1180 #ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
1181 else if ((arg_len = is_keyword(ptr, len, "setdebug")) != 0)
1182 uc->cmd = UC_SETDEBUG;
1184 else if ((arg_len = is_keyword(ptr, len, "setflag")) != 0)
1185 uc->cmd = UC_SETFLAG;
1186 else if ((arg_len = is_keyword(ptr, len, "resetdev")) != 0)
1187 uc->cmd = UC_RESETDEV;
1188 else if ((arg_len = is_keyword(ptr, len, "cleardev")) != 0)
1189 uc->cmd = UC_CLEARDEV;
1193 #ifdef DEBUG_PROC_INFO
1194 printk("sym_user_command: arg_len=%d, cmd=%ld\n", arg_len, uc->cmd);
1199 ptr += arg_len; len -= arg_len;
1208 SKIP_SPACES(ptr, len);
1209 if ((arg_len = is_keyword(ptr, len, "all")) != 0) {
1210 ptr += arg_len; len -= arg_len;
1213 GET_INT_ARG(ptr, len, target);
1214 uc->target = (1<<target);
1215 #ifdef DEBUG_PROC_INFO
1216 printk("sym_user_command: target=%ld\n", target);
1227 SKIP_SPACES(ptr, len);
1228 GET_INT_ARG(ptr, len, uc->data);
1229 #ifdef DEBUG_PROC_INFO
1230 printk("sym_user_command: data=%ld\n", uc->data);
1233 #ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
1236 SKIP_SPACES(ptr, len);
1237 if ((arg_len = is_keyword(ptr, len, "alloc")))
1238 uc->data |= DEBUG_ALLOC;
1239 else if ((arg_len = is_keyword(ptr, len, "phase")))
1240 uc->data |= DEBUG_PHASE;
1241 else if ((arg_len = is_keyword(ptr, len, "queue")))
1242 uc->data |= DEBUG_QUEUE;
1243 else if ((arg_len = is_keyword(ptr, len, "result")))
1244 uc->data |= DEBUG_RESULT;
1245 else if ((arg_len = is_keyword(ptr, len, "scatter")))
1246 uc->data |= DEBUG_SCATTER;
1247 else if ((arg_len = is_keyword(ptr, len, "script")))
1248 uc->data |= DEBUG_SCRIPT;
1249 else if ((arg_len = is_keyword(ptr, len, "tiny")))
1250 uc->data |= DEBUG_TINY;
1251 else if ((arg_len = is_keyword(ptr, len, "timing")))
1252 uc->data |= DEBUG_TIMING;
1253 else if ((arg_len = is_keyword(ptr, len, "nego")))
1254 uc->data |= DEBUG_NEGO;
1255 else if ((arg_len = is_keyword(ptr, len, "tags")))
1256 uc->data |= DEBUG_TAGS;
1257 else if ((arg_len = is_keyword(ptr, len, "pointer")))
1258 uc->data |= DEBUG_POINTER;
1261 ptr += arg_len; len -= arg_len;
1263 #ifdef DEBUG_PROC_INFO
1264 printk("sym_user_command: data=%ld\n", uc->data);
1267 #endif /* SYM_LINUX_DEBUG_CONTROL_SUPPORT */
1270 SKIP_SPACES(ptr, len);
1271 if ((arg_len = is_keyword(ptr, len, "no_disc")))
1272 uc->data &= ~SYM_DISC_ENABLED;
1275 ptr += arg_len; len -= arg_len;
1285 unsigned long flags;
1287 spin_lock_irqsave(np->s.host->host_lock, flags);
1288 sym_exec_user_command (np, uc);
1289 spin_unlock_irqrestore(np->s.host->host_lock, flags);
1294 #endif /* SYM_LINUX_USER_COMMAND_SUPPORT */
1297 #ifdef SYM_LINUX_USER_INFO_SUPPORT
1299 * Informations through the proc file system.
1308 static void copy_mem_info(struct info_str *info, char *data, int len)
1310 if (info->pos + len > info->length)
1311 len = info->length - info->pos;
1313 if (info->pos + len < info->offset) {
1317 if (info->pos < info->offset) {
1318 data += (info->offset - info->pos);
1319 len -= (info->offset - info->pos);
1323 memcpy(info->buffer + info->pos, data, len);
1328 static int copy_info(struct info_str *info, char *fmt, ...)
1334 va_start(args, fmt);
1335 len = vsprintf(buf, fmt, args);
1338 copy_mem_info(info, buf, len);
1343 * Copy formatted information into the input buffer.
1345 static int sym_host_info(struct sym_hcb *np, char *ptr, off_t offset, int len)
1347 struct info_str info;
1351 info.offset = offset;
1354 copy_info(&info, "Chip " NAME53C "%s, device id 0x%x, "
1355 "revision id 0x%x\n",
1356 np->s.chip_name, np->device_id, np->revision_id);
1357 copy_info(&info, "At PCI address %s, IRQ " IRQ_FMT "\n",
1358 pci_name(np->s.device), IRQ_PRM(np->s.irq));
1359 copy_info(&info, "Min. period factor %d, %s SCSI BUS%s\n",
1360 (int) (np->minsync_dt ? np->minsync_dt : np->minsync),
1361 np->maxwide ? "Wide" : "Narrow",
1362 np->minsync_dt ? ", DT capable" : "");
1364 copy_info(&info, "Max. started commands %d, "
1365 "max. commands per LUN %d\n",
1366 SYM_CONF_MAX_START, SYM_CONF_MAX_TAG);
1368 return info.pos > info.offset? info.pos - info.offset : 0;
1370 #endif /* SYM_LINUX_USER_INFO_SUPPORT */
1373 * Entry point of the scsi proc fs of the driver.
1374 * - func = 0 means read (returns adapter infos)
1375 * - func = 1 means write (not yet merget from sym53c8xx)
1377 static int sym53c8xx_proc_info(struct Scsi_Host *host, char *buffer,
1378 char **start, off_t offset, int length, int func)
1380 struct sym_hcb *np = sym_get_hcb(host);
1384 #ifdef SYM_LINUX_USER_COMMAND_SUPPORT
1385 retv = sym_user_command(np, buffer, length);
1392 #ifdef SYM_LINUX_USER_INFO_SUPPORT
1393 retv = sym_host_info(np, buffer, offset, length);
1401 #endif /* SYM_LINUX_PROC_INFO_SUPPORT */
1404 * Free controller resources.
1406 static void sym_free_resources(struct sym_hcb *np, struct pci_dev *pdev)
1409 * Free O/S specific resources.
1412 free_irq(np->s.irq, np);
1414 pci_iounmap(pdev, np->s.ioaddr);
1416 pci_iounmap(pdev, np->s.ramaddr);
1418 * Free O/S independent resources.
1422 sym_mfree_dma(np, sizeof(*np), "HCB");
1426 * Ask/tell the system about DMA addressing.
1428 static int sym_setup_bus_dma_mask(struct sym_hcb *np)
1430 #if SYM_CONF_DMA_ADDRESSING_MODE > 0
1431 #if SYM_CONF_DMA_ADDRESSING_MODE == 1
1432 #define DMA_DAC_MASK DMA_40BIT_MASK
1433 #elif SYM_CONF_DMA_ADDRESSING_MODE == 2
1434 #define DMA_DAC_MASK DMA_64BIT_MASK
1436 if ((np->features & FE_DAC) &&
1437 !pci_set_dma_mask(np->s.device, DMA_DAC_MASK)) {
1443 if (!pci_set_dma_mask(np->s.device, DMA_32BIT_MASK))
1446 printf_warning("%s: No suitable DMA available\n", sym_name(np));
1451 * Host attach and initialisations.
1453 * Allocate host data and ncb structure.
1454 * Remap MMIO region.
1455 * Do chip initialization.
1456 * If all is OK, install interrupt handling and
1457 * start the timer daemon.
1459 static struct Scsi_Host * __devinit sym_attach(struct scsi_host_template *tpnt,
1460 int unit, struct sym_device *dev)
1462 struct host_data *host_data;
1463 struct sym_hcb *np = NULL;
1464 struct Scsi_Host *instance = NULL;
1465 struct pci_dev *pdev = dev->pdev;
1466 unsigned long flags;
1470 "sym%d: <%s> rev 0x%x at pci %s irq " IRQ_FMT "\n",
1471 unit, dev->chip.name, dev->chip.revision_id,
1472 pci_name(pdev), IRQ_PRM(pdev->irq));
1475 * Get the firmware for this chip.
1477 fw = sym_find_firmware(&dev->chip);
1482 * Allocate host_data structure
1484 instance = scsi_host_alloc(tpnt, sizeof(*host_data));
1487 host_data = (struct host_data *) instance->hostdata;
1490 * Allocate immediately the host control block,
1491 * since we are only expecting to succeed. :)
1492 * We keep track in the HCB of all the resources that
1493 * are to be released on error.
1495 np = __sym_calloc_dma(&pdev->dev, sizeof(*np), "HCB");
1498 np->s.device = pdev;
1499 np->bus_dmat = &pdev->dev; /* Result in 1 DMA pool per HBA */
1500 host_data->ncb = np;
1501 np->s.host = instance;
1503 pci_set_drvdata(pdev, np);
1506 * Copy some useful infos to the HCB.
1508 np->hcb_ba = vtobus(np);
1509 np->verbose = sym_driver_setup.verbose;
1510 np->s.device = pdev;
1512 np->device_id = dev->chip.device_id;
1513 np->revision_id = dev->chip.revision_id;
1514 np->features = dev->chip.features;
1515 np->clock_divn = dev->chip.nr_divisor;
1516 np->maxoffs = dev->chip.offset_max;
1517 np->maxburst = dev->chip.burst_max;
1518 np->myaddr = dev->host_id;
1523 strlcpy(np->s.chip_name, dev->chip.name, sizeof(np->s.chip_name));
1524 sprintf(np->s.inst_name, "sym%d", np->s.unit);
1526 if (sym_setup_bus_dma_mask(np))
1530 * Try to map the controller chip to
1531 * virtual and physical memory.
1533 np->mmio_ba = (u32)dev->mmio_base;
1534 np->s.ioaddr = dev->s.ioaddr;
1535 np->s.ramaddr = dev->s.ramaddr;
1536 np->s.io_ws = (np->features & FE_IO256) ? 256 : 128;
1539 * Map on-chip RAM if present and supported.
1541 if (!(np->features & FE_RAM))
1543 if (dev->ram_base) {
1544 np->ram_ba = (u32)dev->ram_base;
1545 np->ram_ws = (np->features & FE_RAM8K) ? 8192 : 4096;
1548 if (sym_hcb_attach(instance, fw, dev->nvram))
1552 * Install the interrupt handler.
1553 * If we synchonize the C code with SCRIPTS on interrupt,
1554 * we do not want to share the INTR line at all.
1556 if (request_irq(pdev->irq, sym53c8xx_intr, SA_SHIRQ, NAME53C8XX, np)) {
1557 printf_err("%s: request irq %d failure\n",
1558 sym_name(np), pdev->irq);
1561 np->s.irq = pdev->irq;
1564 * After SCSI devices have been opened, we cannot
1565 * reset the bus safely, so we do it here.
1567 spin_lock_irqsave(instance->host_lock, flags);
1568 if (sym_reset_scsi_bus(np, 0))
1572 * Start the SCRIPTS.
1574 sym_start_up (np, 1);
1577 * Start the timer daemon
1579 init_timer(&np->s.timer);
1580 np->s.timer.data = (unsigned long) np;
1581 np->s.timer.function = sym53c8xx_timer;
1586 * Fill Linux host instance structure
1587 * and return success.
1589 instance->max_channel = 0;
1590 instance->this_id = np->myaddr;
1591 instance->max_id = np->maxwide ? 16 : 8;
1592 instance->max_lun = SYM_CONF_MAX_LUN;
1593 instance->unique_id = pci_resource_start(pdev, 0);
1594 instance->cmd_per_lun = SYM_CONF_MAX_TAG;
1595 instance->can_queue = (SYM_CONF_MAX_START-2);
1596 instance->sg_tablesize = SYM_CONF_MAX_SG;
1597 instance->max_cmd_len = 16;
1598 BUG_ON(sym2_transport_template == NULL);
1599 instance->transportt = sym2_transport_template;
1601 spin_unlock_irqrestore(instance->host_lock, flags);
1606 printf_err("%s: FATAL ERROR: CHECK SCSI BUS - CABLES, "
1607 "TERMINATION, DEVICE POWER etc.!\n", sym_name(np));
1608 spin_unlock_irqrestore(instance->host_lock, flags);
1612 printf_info("%s: giving up ...\n", sym_name(np));
1614 sym_free_resources(np, pdev);
1615 scsi_host_put(instance);
1622 * Detect and try to read SYMBIOS and TEKRAM NVRAM.
1624 #if SYM_CONF_NVRAM_SUPPORT
1625 static void __devinit sym_get_nvram(struct sym_device *devp, struct sym_nvram *nvp)
1628 devp->device_id = devp->chip.device_id;
1631 sym_read_nvram(devp, nvp);
1634 static inline void sym_get_nvram(struct sym_device *devp, struct sym_nvram *nvp)
1637 #endif /* SYM_CONF_NVRAM_SUPPORT */
1639 static int __devinit sym_check_supported(struct sym_device *device)
1641 struct sym_chip *chip;
1642 struct pci_dev *pdev = device->pdev;
1644 unsigned long io_port = pci_resource_start(pdev, 0);
1648 * If user excluded this chip, do not initialize it.
1649 * I hate this code so much. Must kill it.
1652 for (i = 0 ; i < 8 ; i++) {
1653 if (sym_driver_setup.excludes[i] == io_port)
1659 * Check if the chip is supported. Then copy the chip description
1660 * to our device structure so we can make it match the actual device
1663 pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
1664 chip = sym_lookup_chip_table(pdev->device, revision);
1666 dev_info(&pdev->dev, "device not supported\n");
1669 memcpy(&device->chip, chip, sizeof(device->chip));
1670 device->chip.revision_id = revision;
1676 * Ignore Symbios chips controlled by various RAID controllers.
1677 * These controllers set value 0x52414944 at RAM end - 16.
1679 static int __devinit sym_check_raid(struct sym_device *device)
1681 unsigned int ram_size, ram_val;
1683 if (!device->s.ramaddr)
1686 if (device->chip.features & FE_RAM8K)
1691 ram_val = readl(device->s.ramaddr + ram_size - 16);
1692 if (ram_val != 0x52414944)
1695 dev_info(&device->pdev->dev,
1696 "not initializing, driven by RAID controller.\n");
1700 static int __devinit sym_set_workarounds(struct sym_device *device)
1702 struct sym_chip *chip = &device->chip;
1703 struct pci_dev *pdev = device->pdev;
1707 * (ITEM 12 of a DEL about the 896 I haven't yet).
1708 * We must ensure the chip will use WRITE AND INVALIDATE.
1709 * The revision number limit is for now arbitrary.
1711 if (pdev->device == PCI_DEVICE_ID_NCR_53C896 && chip->revision_id < 0x4) {
1712 chip->features |= (FE_WRIE | FE_CLSE);
1715 /* If the chip can do Memory Write Invalidate, enable it */
1716 if (chip->features & FE_WRIE) {
1717 if (pci_set_mwi(pdev))
1722 * Work around for errant bit in 895A. The 66Mhz
1723 * capable bit is set erroneously. Clear this bit.
1726 * Make sure Config space and Features agree.
1728 * Recall: writes are not normal to status register -
1729 * write a 1 to clear and a 0 to leave unchanged.
1730 * Can only reset bits.
1732 pci_read_config_word(pdev, PCI_STATUS, &status_reg);
1733 if (chip->features & FE_66MHZ) {
1734 if (!(status_reg & PCI_STATUS_66MHZ))
1735 chip->features &= ~FE_66MHZ;
1737 if (status_reg & PCI_STATUS_66MHZ) {
1738 status_reg = PCI_STATUS_66MHZ;
1739 pci_write_config_word(pdev, PCI_STATUS, status_reg);
1740 pci_read_config_word(pdev, PCI_STATUS, &status_reg);
1748 * Read and check the PCI configuration for any detected NCR
1749 * boards and save data for attaching after all boards have
1752 static void __devinit
1753 sym_init_device(struct pci_dev *pdev, struct sym_device *device)
1756 struct pci_bus_region bus_addr;
1758 device->host_id = SYM_SETUP_HOST_ID;
1759 device->pdev = pdev;
1761 pcibios_resource_to_bus(pdev, &bus_addr, &pdev->resource[1]);
1762 device->mmio_base = bus_addr.start;
1765 * If the BAR is 64-bit, resource 2 will be occupied by the
1768 if (!pdev->resource[i].flags)
1770 pcibios_resource_to_bus(pdev, &bus_addr, &pdev->resource[i]);
1771 device->ram_base = bus_addr.start;
1773 #ifdef CONFIG_SCSI_SYM53C8XX_MMIO
1774 if (device->mmio_base)
1775 device->s.ioaddr = pci_iomap(pdev, 1,
1776 pci_resource_len(pdev, 1));
1778 if (!device->s.ioaddr)
1779 device->s.ioaddr = pci_iomap(pdev, 0,
1780 pci_resource_len(pdev, 0));
1781 if (device->ram_base)
1782 device->s.ramaddr = pci_iomap(pdev, i,
1783 pci_resource_len(pdev, i));
1787 * The NCR PQS and PDS cards are constructed as a DEC bridge
1788 * behind which sits a proprietary NCR memory controller and
1789 * either four or two 53c875s as separate devices. We can tell
1790 * if an 875 is part of a PQS/PDS or not since if it is, it will
1791 * be on the same bus as the memory controller. In its usual
1792 * mode of operation, the 875s are slaved to the memory
1793 * controller for all transfers. To operate with the Linux
1794 * driver, the memory controller is disabled and the 875s
1795 * freed to function independently. The only wrinkle is that
1796 * the preset SCSI ID (which may be zero) must be read in from
1797 * a special configuration space register of the 875.
1799 static void sym_config_pqs(struct pci_dev *pdev, struct sym_device *sym_dev)
1804 for (slot = 0; slot < 256; slot++) {
1805 struct pci_dev *memc = pci_get_slot(pdev->bus, slot);
1807 if (!memc || memc->vendor != 0x101a || memc->device == 0x0009) {
1812 /* bit 1: allow individual 875 configuration */
1813 pci_read_config_byte(memc, 0x44, &tmp);
1814 if ((tmp & 0x2) == 0) {
1816 pci_write_config_byte(memc, 0x44, tmp);
1819 /* bit 2: drive individual 875 interrupts to the bus */
1820 pci_read_config_byte(memc, 0x45, &tmp);
1821 if ((tmp & 0x4) == 0) {
1823 pci_write_config_byte(memc, 0x45, tmp);
1830 pci_read_config_byte(pdev, 0x84, &tmp);
1831 sym_dev->host_id = tmp;
1835 * Called before unloading the module.
1837 * We have to free resources and halt the NCR chip.
1839 static int sym_detach(struct sym_hcb *np, struct pci_dev *pdev)
1841 printk("%s: detaching ...\n", sym_name(np));
1843 del_timer_sync(&np->s.timer);
1847 * We should use sym_soft_reset(), but we don't want to do
1848 * so, since we may not be safe if interrupts occur.
1850 printk("%s: resetting chip\n", sym_name(np));
1851 OUTB(np, nc_istat, SRST);
1854 OUTB(np, nc_istat, 0);
1856 sym_free_resources(np, pdev);
1862 * Driver host template.
1864 static struct scsi_host_template sym2_template = {
1865 .module = THIS_MODULE,
1866 .name = "sym53c8xx",
1867 .info = sym53c8xx_info,
1868 .queuecommand = sym53c8xx_queue_command,
1869 .slave_alloc = sym53c8xx_slave_alloc,
1870 .slave_configure = sym53c8xx_slave_configure,
1871 .slave_destroy = sym53c8xx_slave_destroy,
1872 .eh_abort_handler = sym53c8xx_eh_abort_handler,
1873 .eh_device_reset_handler = sym53c8xx_eh_device_reset_handler,
1874 .eh_bus_reset_handler = sym53c8xx_eh_bus_reset_handler,
1875 .eh_host_reset_handler = sym53c8xx_eh_host_reset_handler,
1877 .use_clustering = ENABLE_CLUSTERING,
1878 .max_sectors = 0xFFFF,
1879 #ifdef SYM_LINUX_PROC_INFO_SUPPORT
1880 .proc_info = sym53c8xx_proc_info,
1881 .proc_name = NAME53C8XX,
1885 static int attach_count;
1887 static int __devinit sym2_probe(struct pci_dev *pdev,
1888 const struct pci_device_id *ent)
1890 struct sym_device sym_dev;
1891 struct sym_nvram nvram;
1892 struct Scsi_Host *instance;
1894 memset(&sym_dev, 0, sizeof(sym_dev));
1895 memset(&nvram, 0, sizeof(nvram));
1897 if (pci_enable_device(pdev))
1900 pci_set_master(pdev);
1902 if (pci_request_regions(pdev, NAME53C8XX))
1905 sym_init_device(pdev, &sym_dev);
1906 if (sym_check_supported(&sym_dev))
1909 if (sym_check_raid(&sym_dev))
1910 goto leave; /* Don't disable the device */
1912 if (sym_set_workarounds(&sym_dev))
1915 sym_config_pqs(pdev, &sym_dev);
1917 sym_get_nvram(&sym_dev, &nvram);
1919 instance = sym_attach(&sym2_template, attach_count, &sym_dev);
1923 if (scsi_add_host(instance, &pdev->dev))
1925 scsi_scan_host(instance);
1932 sym_detach(pci_get_drvdata(pdev), pdev);
1934 pci_release_regions(pdev);
1936 pci_disable_device(pdev);
1941 static void __devexit sym2_remove(struct pci_dev *pdev)
1943 struct sym_hcb *np = pci_get_drvdata(pdev);
1944 struct Scsi_Host *host = np->s.host;
1946 scsi_remove_host(host);
1947 scsi_host_put(host);
1949 sym_detach(np, pdev);
1951 pci_release_regions(pdev);
1952 pci_disable_device(pdev);
1957 static void sym2_get_signalling(struct Scsi_Host *shost)
1959 struct sym_hcb *np = sym_get_hcb(shost);
1960 enum spi_signal_type type;
1962 switch (np->scsi_mode) {
1964 type = SPI_SIGNAL_SE;
1967 type = SPI_SIGNAL_LVD;
1970 type = SPI_SIGNAL_HVD;
1973 type = SPI_SIGNAL_UNKNOWN;
1976 spi_signalling(shost) = type;
1979 static void sym2_set_offset(struct scsi_target *starget, int offset)
1981 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1982 struct sym_hcb *np = sym_get_hcb(shost);
1983 struct sym_tcb *tp = &np->target[starget->id];
1985 tp->tgoal.offset = offset;
1986 tp->tgoal.check_nego = 1;
1989 static void sym2_set_period(struct scsi_target *starget, int period)
1991 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1992 struct sym_hcb *np = sym_get_hcb(shost);
1993 struct sym_tcb *tp = &np->target[starget->id];
1995 /* have to have DT for these transfers, but DT will also
1996 * set width, so check that this is allowed */
1997 if (period <= np->minsync && spi_width(starget))
2000 tp->tgoal.period = period;
2001 tp->tgoal.check_nego = 1;
2004 static void sym2_set_width(struct scsi_target *starget, int width)
2006 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
2007 struct sym_hcb *np = sym_get_hcb(shost);
2008 struct sym_tcb *tp = &np->target[starget->id];
2010 /* It is illegal to have DT set on narrow transfers. If DT is
2011 * clear, we must also clear IU and QAS. */
2013 tp->tgoal.iu = tp->tgoal.dt = tp->tgoal.qas = 0;
2015 tp->tgoal.width = width;
2016 tp->tgoal.check_nego = 1;
2019 static void sym2_set_dt(struct scsi_target *starget, int dt)
2021 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
2022 struct sym_hcb *np = sym_get_hcb(shost);
2023 struct sym_tcb *tp = &np->target[starget->id];
2025 /* We must clear QAS and IU if DT is clear */
2029 tp->tgoal.iu = tp->tgoal.dt = tp->tgoal.qas = 0;
2030 tp->tgoal.check_nego = 1;
2034 static void sym2_set_iu(struct scsi_target *starget, int iu)
2036 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
2037 struct sym_hcb *np = sym_get_hcb(shost);
2038 struct sym_tcb *tp = &np->target[starget->id];
2041 tp->tgoal.iu = tp->tgoal.dt = 1;
2044 tp->tgoal.check_nego = 1;
2047 static void sym2_set_qas(struct scsi_target *starget, int qas)
2049 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
2050 struct sym_hcb *np = sym_get_hcb(shost);
2051 struct sym_tcb *tp = &np->target[starget->id];
2054 tp->tgoal.dt = tp->tgoal.qas = 1;
2057 tp->tgoal.check_nego = 1;
2061 static struct spi_function_template sym2_transport_functions = {
2062 .set_offset = sym2_set_offset,
2064 .set_period = sym2_set_period,
2066 .set_width = sym2_set_width,
2068 .set_dt = sym2_set_dt,
2071 .set_iu = sym2_set_iu,
2073 .set_qas = sym2_set_qas,
2076 .get_signalling = sym2_get_signalling,
2079 static struct pci_device_id sym2_id_table[] __devinitdata = {
2080 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C810,
2081 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2082 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C820,
2083 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, /* new */
2084 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C825,
2085 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2086 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C815,
2087 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2088 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C810AP,
2089 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, /* new */
2090 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C860,
2091 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2092 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1510,
2093 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2094 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C896,
2095 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2096 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C895,
2097 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2098 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C885,
2099 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2100 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C875,
2101 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2102 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C1510,
2103 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, /* new */
2104 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C895A,
2105 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2106 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C875A,
2107 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2108 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1010_33,
2109 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2110 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1010_66,
2111 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2112 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C875J,
2113 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2117 MODULE_DEVICE_TABLE(pci, sym2_id_table);
2119 static struct pci_driver sym2_driver = {
2121 .id_table = sym2_id_table,
2122 .probe = sym2_probe,
2123 .remove = __devexit_p(sym2_remove),
2126 static int __init sym2_init(void)
2130 sym2_setup_params();
2131 sym2_transport_template = spi_attach_transport(&sym2_transport_functions);
2132 if (!sym2_transport_template)
2135 error = pci_register_driver(&sym2_driver);
2137 spi_release_transport(sym2_transport_template);
2141 static void __exit sym2_exit(void)
2143 pci_unregister_driver(&sym2_driver);
2144 spi_release_transport(sym2_transport_template);
2147 module_init(sym2_init);
2148 module_exit(sym2_exit);