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>
7 * This driver is derived from the Linux sym53c8xx driver.
8 * Copyright (C) 1998-2000 Gerard Roudier
10 * The sym53c8xx driver is derived from the ncr53c8xx driver that had been
11 * a port of the FreeBSD ncr driver to Linux-1.2.13.
13 * The original ncr driver has been written for 386bsd and FreeBSD by
14 * Wolfgang Stanglmeier <wolf@cologne.de>
15 * Stefan Esser <se@mi.Uni-Koeln.de>
16 * Copyright (C) 1994 Wolfgang Stanglmeier
18 * Other major contributions:
20 * NVRAM detection and reading.
21 * Copyright (C) 1997 Richard Waltham <dormouse@farsrobt.demon.co.uk>
23 *-----------------------------------------------------------------------------
25 * Redistribution and use in source and binary forms, with or without
26 * modification, are permitted provided that the following conditions
28 * 1. Redistributions of source code must retain the above copyright
29 * notice, this list of conditions and the following disclaimer.
30 * 2. The name of the author may not be used to endorse or promote products
31 * derived from this software without specific prior written permission.
33 * Where this Software is combined with software released under the terms of
34 * the GNU Public License ("GPL") and the terms of the GPL would require the
35 * combined work to also be released under the terms of the GPL, the terms
36 * and conditions of this License will apply in addition to those of the
37 * GPL with the exception of any terms or conditions of this License that
38 * conflict with, or are expressly prohibited by, the GPL.
40 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
41 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
44 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
54 #include <linux/ctype.h>
55 #include <linux/init.h>
56 #include <linux/interrupt.h>
57 #include <linux/module.h>
58 #include <linux/spinlock.h>
59 #include <scsi/scsi.h>
60 #include <scsi/scsi_tcq.h>
61 #include <scsi/scsi_device.h>
62 #include <scsi/scsi_transport.h>
63 #include <scsi/scsi_transport_spi.h>
66 #include "sym_nvram.h"
68 #define NAME53C "sym53c"
69 #define NAME53C8XX "sym53c8xx"
72 pci_get_base_address(struct pci_dev *pdev, int index, u_long *base)
75 #define PCI_BAR_OFFSET(index) (PCI_BASE_ADDRESS_0 + (index<<2))
77 pci_read_config_dword(pdev, PCI_BAR_OFFSET(index), &tmp);
80 if ((tmp & 0x7) == PCI_BASE_ADDRESS_MEM_TYPE_64) {
81 #if BITS_PER_LONG > 32
82 pci_read_config_dword(pdev, PCI_BAR_OFFSET(index), &tmp);
83 *base |= (((u_long)tmp) << 32);
91 /* This lock protects only the memory allocation/free. */
92 spinlock_t sym53c8xx_lock = SPIN_LOCK_UNLOCKED;
94 static struct scsi_transport_template *sym2_transport_template = NULL;
97 * Wrappers to the generic memory allocator.
99 void *sym_calloc(int size, char *name)
103 spin_lock_irqsave(&sym53c8xx_lock, flags);
104 m = sym_calloc_unlocked(size, name);
105 spin_unlock_irqrestore(&sym53c8xx_lock, flags);
109 void sym_mfree(void *m, int size, char *name)
112 spin_lock_irqsave(&sym53c8xx_lock, flags);
113 sym_mfree_unlocked(m, size, name);
114 spin_unlock_irqrestore(&sym53c8xx_lock, flags);
117 void *__sym_calloc_dma(m_pool_ident_t dev_dmat, int size, char *name)
121 spin_lock_irqsave(&sym53c8xx_lock, flags);
122 m = __sym_calloc_dma_unlocked(dev_dmat, size, name);
123 spin_unlock_irqrestore(&sym53c8xx_lock, flags);
127 void __sym_mfree_dma(m_pool_ident_t dev_dmat, void *m, int size, char *name)
130 spin_lock_irqsave(&sym53c8xx_lock, flags);
131 __sym_mfree_dma_unlocked(dev_dmat, m, size, name);
132 spin_unlock_irqrestore(&sym53c8xx_lock, flags);
135 m_addr_t __vtobus(m_pool_ident_t dev_dmat, void *m)
139 spin_lock_irqsave(&sym53c8xx_lock, flags);
140 b = __vtobus_unlocked(dev_dmat, m);
141 spin_unlock_irqrestore(&sym53c8xx_lock, flags);
146 * Driver host data structure.
153 * Used by the eh thread to wait for command completion.
154 * It is allocated on the eh thread stack.
157 struct semaphore sem;
158 struct timer_list timer;
159 void (*old_done)(struct scsi_cmnd *);
165 * Driver private area in the SCSI command structure.
167 struct sym_ucmd { /* Override the SCSI pointer structure */
168 SYM_QUEHEAD link_cmdq; /* Must stay at offset ZERO */
169 dma_addr_t data_mapping;
171 struct sym_eh_wait *eh_wait;
174 #define SYM_UCMD_PTR(cmd) ((struct sym_ucmd *)(&(cmd)->SCp))
175 #define SYM_SCMD_PTR(ucmd) sym_que_entry(ucmd, struct scsi_cmnd, SCp)
176 #define SYM_SOFTC_PTR(cmd) (((struct host_data *)cmd->device->host->hostdata)->ncb)
178 static void __unmap_scsi_data(struct pci_dev *pdev, struct scsi_cmnd *cmd)
180 int dma_dir = cmd->sc_data_direction;
182 switch(SYM_UCMD_PTR(cmd)->data_mapped) {
184 pci_unmap_sg(pdev, cmd->buffer, cmd->use_sg, dma_dir);
187 pci_unmap_single(pdev, SYM_UCMD_PTR(cmd)->data_mapping,
188 cmd->request_bufflen, dma_dir);
191 SYM_UCMD_PTR(cmd)->data_mapped = 0;
194 static dma_addr_t __map_scsi_single_data(struct pci_dev *pdev, struct scsi_cmnd *cmd)
197 int dma_dir = cmd->sc_data_direction;
199 mapping = pci_map_single(pdev, cmd->request_buffer,
200 cmd->request_bufflen, dma_dir);
202 SYM_UCMD_PTR(cmd)->data_mapped = 1;
203 SYM_UCMD_PTR(cmd)->data_mapping = mapping;
209 static int __map_scsi_sg_data(struct pci_dev *pdev, struct scsi_cmnd *cmd)
212 int dma_dir = cmd->sc_data_direction;
214 use_sg = pci_map_sg(pdev, cmd->buffer, cmd->use_sg, dma_dir);
216 SYM_UCMD_PTR(cmd)->data_mapped = 2;
217 SYM_UCMD_PTR(cmd)->data_mapping = use_sg;
223 static void __sync_scsi_data_for_cpu(struct pci_dev *pdev, struct scsi_cmnd *cmd)
225 int dma_dir = cmd->sc_data_direction;
227 switch(SYM_UCMD_PTR(cmd)->data_mapped) {
229 pci_dma_sync_sg_for_cpu(pdev, cmd->buffer, cmd->use_sg, dma_dir);
232 pci_dma_sync_single_for_cpu(pdev, SYM_UCMD_PTR(cmd)->data_mapping,
233 cmd->request_bufflen, dma_dir);
238 static void __sync_scsi_data_for_device(struct pci_dev *pdev, struct scsi_cmnd *cmd)
240 int dma_dir = cmd->sc_data_direction;
242 switch(SYM_UCMD_PTR(cmd)->data_mapped) {
244 pci_dma_sync_sg_for_device(pdev, cmd->buffer, cmd->use_sg, dma_dir);
247 pci_dma_sync_single_for_device(pdev, SYM_UCMD_PTR(cmd)->data_mapping,
248 cmd->request_bufflen, dma_dir);
253 #define unmap_scsi_data(np, cmd) \
254 __unmap_scsi_data(np->s.device, cmd)
255 #define map_scsi_single_data(np, cmd) \
256 __map_scsi_single_data(np->s.device, cmd)
257 #define map_scsi_sg_data(np, cmd) \
258 __map_scsi_sg_data(np->s.device, cmd)
259 #define sync_scsi_data_for_cpu(np, cmd) \
260 __sync_scsi_data_for_cpu(np->s.device, cmd)
261 #define sync_scsi_data_for_device(np, cmd) \
262 __sync_scsi_data_for_device(np->s.device, cmd)
265 * Complete a pending CAM CCB.
267 void sym_xpt_done(struct sym_hcb *np, struct scsi_cmnd *ccb)
269 sym_remque(&SYM_UCMD_PTR(ccb)->link_cmdq);
270 unmap_scsi_data(np, ccb);
274 void sym_xpt_done2(struct sym_hcb *np, struct scsi_cmnd *ccb, int cam_status)
276 sym_set_cam_status(ccb, cam_status);
277 sym_xpt_done(np, ccb);
282 * Print something that identifies the IO.
284 void sym_print_addr(struct sym_ccb *cp)
286 struct scsi_cmnd *cmd = cp->cam_ccb;
288 printf("%s:%d:%d:", sym_name(SYM_SOFTC_PTR(cmd)),
289 cmd->device->id, cmd->device->lun);
293 * Tell the SCSI layer about a BUS RESET.
295 void sym_xpt_async_bus_reset(struct sym_hcb *np)
297 printf_notice("%s: SCSI BUS has been reset.\n", sym_name(np));
298 np->s.settle_time = jiffies + sym_driver_setup.settle_delay * HZ;
299 np->s.settle_time_valid = 1;
300 if (sym_verbose >= 2)
301 printf_info("%s: command processing suspended for %d seconds\n",
302 sym_name(np), sym_driver_setup.settle_delay);
306 * Tell the SCSI layer about a BUS DEVICE RESET message sent.
308 void sym_xpt_async_sent_bdr(struct sym_hcb *np, int target)
310 printf_notice("%s: TARGET %d has been reset.\n", sym_name(np), target);
314 * Tell the SCSI layer about the new transfer parameters.
316 void sym_xpt_async_nego_wide(struct sym_hcb *np, int target)
320 sym_announce_transfer_rate(np, target);
324 * Choose the more appropriate CAM status if
325 * the IO encountered an extended error.
327 static int sym_xerr_cam_status(int cam_status, int x_status)
330 if (x_status & XE_PARITY_ERR)
331 cam_status = DID_PARITY;
332 else if (x_status &(XE_EXTRA_DATA|XE_SODL_UNRUN|XE_SWIDE_OVRUN))
333 cam_status = DID_ERROR;
334 else if (x_status & XE_BAD_PHASE)
335 cam_status = DID_ERROR;
337 cam_status = DID_ERROR;
343 * Build CAM result for a failed or auto-sensed IO.
345 void sym_set_cam_result_error(struct sym_hcb *np, struct sym_ccb *cp, int resid)
347 struct scsi_cmnd *csio = cp->cam_ccb;
348 u_int cam_status, scsi_status, drv_status;
352 scsi_status = cp->ssss_status;
354 if (cp->host_flags & HF_SENSE) {
355 scsi_status = cp->sv_scsi_status;
356 resid = cp->sv_resid;
357 if (sym_verbose && cp->sv_xerr_status)
358 sym_print_xerr(cp, cp->sv_xerr_status);
359 if (cp->host_status == HS_COMPLETE &&
360 cp->ssss_status == S_GOOD &&
361 cp->xerr_status == 0) {
362 cam_status = sym_xerr_cam_status(DID_OK,
364 drv_status = DRIVER_SENSE;
366 * Bounce back the sense data to user.
368 bzero(&csio->sense_buffer, sizeof(csio->sense_buffer));
369 memcpy(csio->sense_buffer, cp->sns_bbuf,
370 min(sizeof(csio->sense_buffer),
371 (size_t)SYM_SNS_BBUF_LEN));
374 * If the device reports a UNIT ATTENTION condition
375 * due to a RESET condition, we should consider all
376 * disconnect CCBs for this unit as aborted.
380 p = (u_char *) csio->sense_data;
381 if (p[0]==0x70 && p[2]==0x6 && p[12]==0x29)
382 sym_clear_tasks(np, DID_ABORT,
383 cp->target,cp->lun, -1);
388 * Error return from our internal request sense. This
389 * is bad: we must clear the contingent allegiance
390 * condition otherwise the device will always return
391 * BUSY. Use a big stick.
393 sym_reset_scsi_target(np, csio->device->id);
394 cam_status = DID_ERROR;
396 } else if (cp->host_status == HS_COMPLETE) /* Bad SCSI status */
398 else if (cp->host_status == HS_SEL_TIMEOUT) /* Selection timeout */
399 cam_status = DID_NO_CONNECT;
400 else if (cp->host_status == HS_UNEXPECTED) /* Unexpected BUS FREE*/
401 cam_status = DID_ERROR;
402 else { /* Extended error */
405 printf ("COMMAND FAILED (%x %x %x).\n",
406 cp->host_status, cp->ssss_status,
410 * Set the most appropriate value for CAM status.
412 cam_status = sym_xerr_cam_status(DID_ERROR, cp->xerr_status);
415 csio->result = (drv_status << 24) + (cam_status << 16) + scsi_status;
420 * Called on successfull INQUIRY response.
422 void sym_sniff_inquiry(struct sym_hcb *np, struct scsi_cmnd *cmd, int resid)
426 if (!cmd || cmd->use_sg)
429 sync_scsi_data_for_cpu(np, cmd);
430 retv = __sym_sniff_inquiry(np, cmd->device->id, cmd->device->lun,
431 (u_char *) cmd->request_buffer,
432 cmd->request_bufflen - resid);
433 sync_scsi_data_for_device(np, cmd);
437 sym_update_trans_settings(np, &np->target[cmd->device->id]);
441 * Build the scatter/gather array for an I/O.
444 static int sym_scatter_no_sglist(struct sym_hcb *np, struct sym_ccb *cp, struct scsi_cmnd *cmd)
446 struct sym_tblmove *data = &cp->phys.data[SYM_CONF_MAX_SG-1];
449 cp->data_len = cmd->request_bufflen;
451 if (cmd->request_bufflen) {
452 dma_addr_t baddr = map_scsi_single_data(np, cmd);
454 sym_build_sge(np, data, baddr, cmd->request_bufflen);
466 static int sym_scatter(struct sym_hcb *np, struct sym_ccb *cp, struct scsi_cmnd *cmd)
469 int use_sg = (int) cmd->use_sg;
474 segment = sym_scatter_no_sglist(np, cp, cmd);
475 else if ((use_sg = map_scsi_sg_data(np, cmd)) > 0) {
476 struct scatterlist *scatter = (struct scatterlist *)cmd->buffer;
477 struct sym_tblmove *data;
479 if (use_sg > SYM_CONF_MAX_SG) {
480 unmap_scsi_data(np, cmd);
484 data = &cp->phys.data[SYM_CONF_MAX_SG - use_sg];
486 for (segment = 0; segment < use_sg; segment++) {
487 dma_addr_t baddr = sg_dma_address(&scatter[segment]);
488 unsigned int len = sg_dma_len(&scatter[segment]);
490 sym_build_sge(np, &data[segment], baddr, len);
501 * Queue a SCSI command.
503 static int sym_queue_command(struct sym_hcb *np, struct scsi_cmnd *ccb)
505 /* struct scsi_device *device = ccb->device; */
512 * Minimal checkings, so that we will not
513 * go outside our tables.
515 if (ccb->device->id == np->myaddr ||
516 ccb->device->id >= SYM_CONF_MAX_TARGET ||
517 ccb->device->lun >= SYM_CONF_MAX_LUN) {
518 sym_xpt_done2(np, ccb, CAM_DEV_NOT_THERE);
523 * Retreive the target descriptor.
525 tp = &np->target[ccb->device->id];
528 * Complete the 1st INQUIRY command with error
529 * condition if the device is flagged NOSCAN
530 * at BOOT in the NVRAM. This may speed up
531 * the boot and maintain coherency with BIOS
532 * device numbering. Clearing the flag allows
533 * user to rescan skipped devices later.
534 * We also return error for devices not flagged
535 * for SCAN LUNS in the NVRAM since some mono-lun
536 * devices behave badly when asked for some non
537 * zero LUN. Btw, this is an absolute hack.:-)
539 if (ccb->cmnd[0] == 0x12 || ccb->cmnd[0] == 0x0) {
540 if ((tp->usrflags & SYM_SCAN_BOOT_DISABLED) ||
541 ((tp->usrflags & SYM_SCAN_LUNS_DISABLED) &&
542 ccb->device->lun != 0)) {
543 tp->usrflags &= ~SYM_SCAN_BOOT_DISABLED;
544 sym_xpt_done2(np, ccb, CAM_DEV_NOT_THERE);
550 * Select tagged/untagged.
552 lp = sym_lp(np, tp, ccb->device->lun);
553 order = (lp && lp->s.reqtags) ? M_SIMPLE_TAG : 0;
558 cp = sym_get_ccb(np, ccb->device->id, ccb->device->lun, order);
560 return 1; /* Means resource shortage */
561 sym_queue_scsiio(np, ccb, cp);
566 * Setup buffers and pointers that address the CDB.
568 static inline int sym_setup_cdb(struct sym_hcb *np, struct scsi_cmnd *ccb, struct sym_ccb *cp)
574 * CDB is 16 bytes max.
576 if (ccb->cmd_len > sizeof(cp->cdb_buf)) {
577 sym_set_cam_status(cp->cam_ccb, CAM_REQ_INVALID);
581 memcpy(cp->cdb_buf, ccb->cmnd, ccb->cmd_len);
582 cmd_ba = CCB_BA (cp, cdb_buf[0]);
583 cmd_len = ccb->cmd_len;
585 cp->phys.cmd.addr = cpu_to_scr(cmd_ba);
586 cp->phys.cmd.size = cpu_to_scr(cmd_len);
592 * Setup pointers that address the data and start the I/O.
594 int sym_setup_data_and_start(struct sym_hcb *np, struct scsi_cmnd *csio, struct sym_ccb *cp)
597 struct sym_tcb *tp = &np->target[cp->target];
598 struct sym_lcb *lp = sym_lp(np, tp, cp->lun);
603 if (sym_setup_cdb(np, csio, cp))
607 * No direction means no data.
609 dir = csio->sc_data_direction;
610 if (dir != DMA_NONE) {
611 cp->segments = sym_scatter(np, cp, csio);
612 if (cp->segments < 0) {
613 if (cp->segments == -2)
614 sym_set_cam_status(csio, CAM_RESRC_UNAVAIL);
616 sym_set_cam_status(csio, CAM_REQ_TOO_BIG);
627 sym_setup_data_pointers(np, cp, dir);
630 * When `#ifed 1', the code below makes the driver
631 * panic on the first attempt to write to a SCSI device.
632 * It is the first test we want to do after a driver
633 * change that does not seem obviously safe. :)
636 switch (cp->cdb_buf[0]) {
637 case 0x0A: case 0x2A: case 0xAA:
638 panic("XXXXXXXXXXXXX WRITE NOT YET ALLOWED XXXXXXXXXXXXXX\n");
650 sym_start_next_ccbs(np, lp, 2);
652 sym_put_start_queue(np, cp);
656 sym_free_ccb(np, cp);
657 sym_xpt_done(np, csio);
665 * Misused to keep the driver running when
666 * interrupts are not configured correctly.
668 static void sym_timer(struct sym_hcb *np)
670 unsigned long thistime = jiffies;
675 np->s.timer.expires = thistime + SYM_CONF_TIMER_INTERVAL;
676 add_timer(&np->s.timer);
679 * If we are resetting the ncr, wait for settle_time before
680 * clearing it. Then command processing will be resumed.
682 if (np->s.settle_time_valid) {
683 if (time_before_eq(np->s.settle_time, thistime)) {
684 if (sym_verbose >= 2 )
685 printk("%s: command processing resumed\n",
687 np->s.settle_time_valid = 0;
693 * Nothing to do for now, but that may come.
695 if (np->s.lasttime + 4*HZ < thistime) {
696 np->s.lasttime = thistime;
699 #ifdef SYM_CONF_PCIQ_MAY_MISS_COMPLETIONS
701 * Some way-broken PCI bridges may lead to
702 * completions being lost when the clearing
703 * of the INTFLY flag by the CPU occurs
704 * concurrently with the chip raising this flag.
705 * If this ever happen, lost completions will
714 * PCI BUS error handler.
716 void sym_log_bus_error(struct sym_hcb *np)
719 pci_read_config_word(np->s.device, PCI_STATUS, &pci_sts);
720 if (pci_sts & 0xf900) {
721 pci_write_config_word(np->s.device, PCI_STATUS, pci_sts);
722 printf("%s: PCI STATUS = 0x%04x\n",
723 sym_name(np), pci_sts & 0xf900);
729 * Requeue awaiting commands.
731 static void sym_requeue_awaiting_cmds(struct sym_hcb *np)
733 struct scsi_cmnd *cmd;
734 struct sym_ucmd *ucp = SYM_UCMD_PTR(cmd);
735 SYM_QUEHEAD tmp_cmdq;
738 sym_que_move(&np->s.wait_cmdq, &tmp_cmdq);
740 while ((ucp = (struct sym_ucmd *) sym_remque_head(&tmp_cmdq)) != 0) {
741 sym_insque_tail(&ucp->link_cmdq, &np->s.busy_cmdq);
742 cmd = SYM_SCMD_PTR(ucp);
743 sts = sym_queue_command(np, cmd);
745 sym_remque(&ucp->link_cmdq);
746 sym_insque_head(&ucp->link_cmdq, &np->s.wait_cmdq);
752 * queuecommand method. Entered with the host adapter lock held and
753 * interrupts disabled.
755 static int sym53c8xx_queue_command(struct scsi_cmnd *cmd,
756 void (*done)(struct scsi_cmnd *))
758 struct sym_hcb *np = SYM_SOFTC_PTR(cmd);
759 struct sym_ucmd *ucp = SYM_UCMD_PTR(cmd);
762 cmd->scsi_done = done;
763 cmd->host_scribble = NULL;
764 memset(ucp, 0, sizeof(*ucp));
767 * Shorten our settle_time if needed for
768 * this command not to time out.
770 if (np->s.settle_time_valid && cmd->timeout_per_command) {
771 unsigned long tlimit = jiffies + cmd->timeout_per_command;
772 tlimit -= SYM_CONF_TIMER_INTERVAL*2;
773 if (time_after(np->s.settle_time, tlimit)) {
774 np->s.settle_time = tlimit;
778 if (np->s.settle_time_valid || !sym_que_empty(&np->s.wait_cmdq)) {
779 sym_insque_tail(&ucp->link_cmdq, &np->s.wait_cmdq);
783 sym_insque_tail(&ucp->link_cmdq, &np->s.busy_cmdq);
784 sts = sym_queue_command(np, cmd);
786 sym_remque(&ucp->link_cmdq);
787 sym_insque_tail(&ucp->link_cmdq, &np->s.wait_cmdq);
794 * Linux entry point of the interrupt handler.
796 static irqreturn_t sym53c8xx_intr(int irq, void *dev_id, struct pt_regs * regs)
799 struct sym_hcb *np = (struct sym_hcb *)dev_id;
801 if (DEBUG_FLAGS & DEBUG_TINY) printf_debug ("[");
803 spin_lock_irqsave(np->s.host->host_lock, flags);
808 * push queue walk-through to tasklet
810 if (!sym_que_empty(&np->s.wait_cmdq) && !np->s.settle_time_valid)
811 sym_requeue_awaiting_cmds(np);
813 spin_unlock_irqrestore(np->s.host->host_lock, flags);
815 if (DEBUG_FLAGS & DEBUG_TINY) printf_debug ("]\n");
821 * Linux entry point of the timer handler
823 static void sym53c8xx_timer(unsigned long npref)
825 struct sym_hcb *np = (struct sym_hcb *)npref;
828 spin_lock_irqsave(np->s.host->host_lock, flags);
832 if (!sym_que_empty(&np->s.wait_cmdq) && !np->s.settle_time_valid)
833 sym_requeue_awaiting_cmds(np);
835 spin_unlock_irqrestore(np->s.host->host_lock, flags);
840 * What the eh thread wants us to perform.
842 #define SYM_EH_ABORT 0
843 #define SYM_EH_DEVICE_RESET 1
844 #define SYM_EH_BUS_RESET 2
845 #define SYM_EH_HOST_RESET 3
848 * What we will do regarding the involved SCSI command.
850 #define SYM_EH_DO_IGNORE 0
851 #define SYM_EH_DO_COMPLETE 1
852 #define SYM_EH_DO_WAIT 2
855 * Our general completion handler.
857 static void __sym_eh_done(struct scsi_cmnd *cmd, int timed_out)
859 struct sym_eh_wait *ep = SYM_UCMD_PTR(cmd)->eh_wait;
863 /* Try to avoid a race here (not 100% safe) */
866 if (ep->to_do == SYM_EH_DO_WAIT && !del_timer(&ep->timer))
870 /* Revert everything */
871 SYM_UCMD_PTR(cmd)->eh_wait = 0;
872 cmd->scsi_done = ep->old_done;
874 /* Wake up the eh thread if it wants to sleep */
875 if (ep->to_do == SYM_EH_DO_WAIT)
880 * scsi_done() alias when error recovery is in progress.
882 static void sym_eh_done(struct scsi_cmnd *cmd) { __sym_eh_done(cmd, 0); }
885 * Some timeout handler to avoid waiting too long.
887 static void sym_eh_timeout(u_long p) { __sym_eh_done((struct scsi_cmnd *)p, 1); }
890 * Generic method for our eh processing.
891 * The 'op' argument tells what we have to do.
893 static int sym_eh_handler(int op, char *opname, struct scsi_cmnd *cmd)
895 struct sym_hcb *np = SYM_SOFTC_PTR(cmd);
897 int to_do = SYM_EH_DO_IGNORE;
899 struct sym_eh_wait eh, *ep = &eh;
902 sprintf(devname, "%s:%d:%d", sym_name(np), cmd->device->id, cmd->device->lun);
904 printf_warning("%s: %s operation started.\n", devname, opname);
907 /* This one should be the result of some race, thus to ignore */
908 if (cmd->serial_number != cmd->serial_number_at_timeout)
912 /* This one is not queued to the core driver -> to complete here */
913 FOR_EACH_QUEUED_ELEMENT(&np->s.wait_cmdq, qp) {
914 if (SYM_SCMD_PTR(qp) == cmd) {
915 to_do = SYM_EH_DO_COMPLETE;
920 /* This one is queued in some place -> to wait for completion */
921 FOR_EACH_QUEUED_ELEMENT(&np->busy_ccbq, qp) {
922 struct sym_ccb *cp = sym_que_entry(qp, struct sym_ccb, link_ccbq);
923 if (cp->cam_ccb == cmd) {
924 to_do = SYM_EH_DO_WAIT;
930 /* Prepare stuff to either ignore, complete or wait for completion */
933 case SYM_EH_DO_IGNORE:
936 init_MUTEX_LOCKED(&ep->sem);
938 case SYM_EH_DO_COMPLETE:
939 ep->old_done = cmd->scsi_done;
940 cmd->scsi_done = sym_eh_done;
941 SYM_UCMD_PTR(cmd)->eh_wait = ep;
944 /* Try to proceed the operation we have been asked for */
948 sts = sym_abort_scsiio(np, cmd, 1);
950 case SYM_EH_DEVICE_RESET:
951 sts = sym_reset_scsi_target(np, cmd->device->id);
953 case SYM_EH_BUS_RESET:
954 sym_reset_scsi_bus(np, 1);
957 case SYM_EH_HOST_RESET:
958 sym_reset_scsi_bus(np, 0);
959 sym_start_up (np, 1);
966 /* On error, restore everything and cross fingers :) */
968 SYM_UCMD_PTR(cmd)->eh_wait = 0;
969 cmd->scsi_done = ep->old_done;
970 to_do = SYM_EH_DO_IGNORE;
974 /* Complete the command with locks held as required by the driver */
975 if (to_do == SYM_EH_DO_COMPLETE)
976 sym_xpt_done2(np, cmd, CAM_REQ_ABORTED);
978 /* Wait for completion with locks released, as required by kernel */
979 if (to_do == SYM_EH_DO_WAIT) {
980 init_timer(&ep->timer);
981 ep->timer.expires = jiffies + (5*HZ);
982 ep->timer.function = sym_eh_timeout;
983 ep->timer.data = (u_long)cmd;
984 ep->timed_out = 1; /* Be pessimistic for once :) */
985 add_timer(&ep->timer);
986 spin_unlock_irq(np->s.host->host_lock);
988 spin_lock_irq(np->s.host->host_lock);
992 printf_warning("%s: %s operation %s.\n", devname, opname,
993 sts==0?"complete":sts==-2?"timed-out":"failed");
994 return sts? SCSI_FAILED : SCSI_SUCCESS;
999 * Error handlers called from the eh thread (one thread per HBA).
1001 static int sym53c8xx_eh_abort_handler(struct scsi_cmnd *cmd)
1003 return sym_eh_handler(SYM_EH_ABORT, "ABORT", cmd);
1006 static int sym53c8xx_eh_device_reset_handler(struct scsi_cmnd *cmd)
1008 return sym_eh_handler(SYM_EH_DEVICE_RESET, "DEVICE RESET", cmd);
1011 static int sym53c8xx_eh_bus_reset_handler(struct scsi_cmnd *cmd)
1013 return sym_eh_handler(SYM_EH_BUS_RESET, "BUS RESET", cmd);
1016 static int sym53c8xx_eh_host_reset_handler(struct scsi_cmnd *cmd)
1018 return sym_eh_handler(SYM_EH_HOST_RESET, "HOST RESET", cmd);
1022 * Tune device queuing depth, according to various limits.
1024 static void sym_tune_dev_queuing(struct sym_hcb *np, int target, int lun, u_short reqtags)
1026 struct sym_tcb *tp = &np->target[target];
1027 struct sym_lcb *lp = sym_lp(np, tp, lun);
1033 oldtags = lp->s.reqtags;
1035 if (reqtags > lp->s.scdev_depth)
1036 reqtags = lp->s.scdev_depth;
1038 lp->started_limit = reqtags ? reqtags : 2;
1039 lp->started_max = 1;
1040 lp->s.reqtags = reqtags;
1042 if (reqtags != oldtags) {
1043 printf_info("%s:%d:%d: "
1044 "tagged command queuing %s, command queue depth %d.\n",
1045 sym_name(np), target, lun,
1046 lp->s.reqtags ? "enabled" : "disabled",
1051 #ifdef SYM_LINUX_BOOT_COMMAND_LINE_SUPPORT
1053 * Linux select queue depths function
1055 #define DEF_DEPTH (sym_driver_setup.max_tag)
1056 #define ALL_TARGETS -2
1057 #define NO_TARGET -1
1061 static int device_queue_depth(struct sym_hcb *np, int target, int lun)
1064 char *p = sym_driver_setup.tag_ctrl;
1070 while ((c = *p++) != 0) {
1071 v = simple_strtoul(p, &ep, 0);
1080 t = (target == v) ? v : NO_TARGET;
1085 u = (lun == v) ? v : NO_LUN;
1088 if (h == np->s.unit &&
1089 (t == ALL_TARGETS || t == target) &&
1090 (u == ALL_LUNS || u == lun))
1105 #define device_queue_depth(np, t, l) (sym_driver_setup.max_tag)
1106 #endif /* SYM_LINUX_BOOT_COMMAND_LINE_SUPPORT */
1109 * Linux entry point for device queue sizing.
1111 static int sym53c8xx_slave_configure(struct scsi_device *device)
1113 struct Scsi_Host *host = device->host;
1117 int reqtags, depth_to_use;
1119 np = ((struct host_data *) host->hostdata)->ncb;
1120 tp = &np->target[device->id];
1123 * Get user settings for transfer parameters.
1125 tp->inq_byte7_valid = (INQ7_SYNC|INQ7_WIDE16);
1126 sym_update_trans_settings(np, tp);
1129 * Allocate the LCB if not yet.
1130 * If it fail, we may well be in the sh*t. :)
1132 lp = sym_alloc_lcb(np, device->id, device->lun);
1139 lp->curr_flags = lp->user_flags;
1142 * Select queue depth from driver setup.
1143 * Donnot use more than configured by user.
1145 * Donnot use more than our maximum.
1147 reqtags = device_queue_depth(np, device->id, device->lun);
1148 if (reqtags > tp->usrtags)
1149 reqtags = tp->usrtags;
1150 if (!device->tagged_supported)
1152 #if 1 /* Avoid to locally queue commands for no good reasons */
1153 if (reqtags > SYM_CONF_MAX_TAG)
1154 reqtags = SYM_CONF_MAX_TAG;
1155 depth_to_use = (reqtags ? reqtags : 2);
1157 depth_to_use = (reqtags ? SYM_CONF_MAX_TAG : 2);
1159 scsi_adjust_queue_depth(device,
1160 (device->tagged_supported ?
1161 MSG_SIMPLE_TAG : 0),
1163 lp->s.scdev_depth = depth_to_use;
1164 sym_tune_dev_queuing(np, device->id, device->lun, reqtags);
1166 spi_dv_device(device);
1172 * Linux entry point for info() function
1174 static const char *sym53c8xx_info (struct Scsi_Host *host)
1176 return sym_driver_name();
1180 #ifdef SYM_LINUX_PROC_INFO_SUPPORT
1182 * Proc file system stuff
1184 * A read operation returns adapter information.
1185 * A write operation is a control command.
1186 * The string is parsed in the driver code and the command is passed
1187 * to the sym_usercmd() function.
1190 #ifdef SYM_LINUX_USER_COMMAND_SUPPORT
1199 #define UC_SETSYNC 10
1200 #define UC_SETTAGS 11
1201 #define UC_SETDEBUG 12
1202 #define UC_SETWIDE 14
1203 #define UC_SETFLAG 15
1204 #define UC_SETVERBOSE 17
1205 #define UC_RESETDEV 18
1206 #define UC_CLEARDEV 19
1208 static void sym_exec_user_command (struct sym_hcb *np, struct sym_usrcmd *uc)
1216 #ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
1218 sym_debug_flags = uc->data;
1222 np->verbose = uc->data;
1226 * We assume that other commands apply to targets.
1227 * This should always be the case and avoid the below
1228 * 4 lines to be repeated 6 times.
1230 for (t = 0; t < SYM_CONF_MAX_TARGET; t++) {
1231 if (!((uc->target >> t) & 1))
1233 tp = &np->target[t];
1238 if (!uc->data || uc->data >= 255) {
1239 tp->tinfo.goal.options = 0;
1240 tp->tinfo.goal.offset = 0;
1243 if (uc->data <= 9 && np->minsync_dt) {
1244 if (uc->data < np->minsync_dt)
1245 uc->data = np->minsync_dt;
1246 tp->tinfo.goal.options = PPR_OPT_DT;
1247 tp->tinfo.goal.width = 1;
1248 tp->tinfo.goal.period = uc->data;
1249 tp->tinfo.goal.offset = np->maxoffs_dt;
1251 if (uc->data < np->minsync)
1252 uc->data = np->minsync;
1253 tp->tinfo.goal.options = 0;
1254 tp->tinfo.goal.period = uc->data;
1255 tp->tinfo.goal.offset = np->maxoffs;
1259 tp->tinfo.goal.width = uc->data ? 1 : 0;
1262 for (l = 0; l < SYM_CONF_MAX_LUN; l++)
1263 sym_tune_dev_queuing(np, t,l, uc->data);
1267 np->istat_sem = SEM;
1268 OUTB (nc_istat, SIGP|SEM);
1271 for (l = 0; l < SYM_CONF_MAX_LUN; l++) {
1272 struct sym_lcb *lp = sym_lp(np, tp, l);
1273 if (lp) lp->to_clear = 1;
1275 np->istat_sem = SEM;
1276 OUTB (nc_istat, SIGP|SEM);
1279 tp->usrflags = uc->data;
1287 #define digit_to_bin(c) ((c) - '0')
1289 static int skip_spaces(char *ptr, int len)
1293 for (cnt = len; cnt > 0 && (c = *ptr++) && isspace(c); cnt--);
1298 static int get_int_arg(char *ptr, int len, u_long *pv)
1303 for (v = 0, cnt = len; cnt > 0 && (c = *ptr++) && isdigit(c); cnt--) {
1304 v = (v * 10) + digit_to_bin(c);
1313 static int is_keyword(char *ptr, int len, char *verb)
1315 int verb_len = strlen(verb);
1317 if (len >= verb_len && !memcmp(verb, ptr, verb_len))
1324 #define SKIP_SPACES(min_spaces) \
1325 if ((arg_len = skip_spaces(ptr, len)) < (min_spaces)) \
1327 ptr += arg_len; len -= arg_len;
1329 #define GET_INT_ARG(v) \
1330 if (!(arg_len = get_int_arg(ptr, len, &(v)))) \
1332 ptr += arg_len; len -= arg_len;
1336 * Parse a control command
1339 static int sym_user_command(struct sym_hcb *np, char *buffer, int length)
1343 struct sym_usrcmd cmd, *uc = &cmd;
1347 bzero(uc, sizeof(*uc));
1349 if (len > 0 && ptr[len-1] == '\n')
1352 if ((arg_len = is_keyword(ptr, len, "setsync")) != 0)
1353 uc->cmd = UC_SETSYNC;
1354 else if ((arg_len = is_keyword(ptr, len, "settags")) != 0)
1355 uc->cmd = UC_SETTAGS;
1356 else if ((arg_len = is_keyword(ptr, len, "setverbose")) != 0)
1357 uc->cmd = UC_SETVERBOSE;
1358 else if ((arg_len = is_keyword(ptr, len, "setwide")) != 0)
1359 uc->cmd = UC_SETWIDE;
1360 #ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
1361 else if ((arg_len = is_keyword(ptr, len, "setdebug")) != 0)
1362 uc->cmd = UC_SETDEBUG;
1364 else if ((arg_len = is_keyword(ptr, len, "setflag")) != 0)
1365 uc->cmd = UC_SETFLAG;
1366 else if ((arg_len = is_keyword(ptr, len, "resetdev")) != 0)
1367 uc->cmd = UC_RESETDEV;
1368 else if ((arg_len = is_keyword(ptr, len, "cleardev")) != 0)
1369 uc->cmd = UC_CLEARDEV;
1373 #ifdef DEBUG_PROC_INFO
1374 printk("sym_user_command: arg_len=%d, cmd=%ld\n", arg_len, uc->cmd);
1379 ptr += arg_len; len -= arg_len;
1389 if ((arg_len = is_keyword(ptr, len, "all")) != 0) {
1390 ptr += arg_len; len -= arg_len;
1393 GET_INT_ARG(target);
1394 uc->target = (1<<target);
1395 #ifdef DEBUG_PROC_INFO
1396 printk("sym_user_command: target=%ld\n", target);
1408 GET_INT_ARG(uc->data);
1409 #ifdef DEBUG_PROC_INFO
1410 printk("sym_user_command: data=%ld\n", uc->data);
1413 #ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
1417 if ((arg_len = is_keyword(ptr, len, "alloc")))
1418 uc->data |= DEBUG_ALLOC;
1419 else if ((arg_len = is_keyword(ptr, len, "phase")))
1420 uc->data |= DEBUG_PHASE;
1421 else if ((arg_len = is_keyword(ptr, len, "queue")))
1422 uc->data |= DEBUG_QUEUE;
1423 else if ((arg_len = is_keyword(ptr, len, "result")))
1424 uc->data |= DEBUG_RESULT;
1425 else if ((arg_len = is_keyword(ptr, len, "scatter")))
1426 uc->data |= DEBUG_SCATTER;
1427 else if ((arg_len = is_keyword(ptr, len, "script")))
1428 uc->data |= DEBUG_SCRIPT;
1429 else if ((arg_len = is_keyword(ptr, len, "tiny")))
1430 uc->data |= DEBUG_TINY;
1431 else if ((arg_len = is_keyword(ptr, len, "timing")))
1432 uc->data |= DEBUG_TIMING;
1433 else if ((arg_len = is_keyword(ptr, len, "nego")))
1434 uc->data |= DEBUG_NEGO;
1435 else if ((arg_len = is_keyword(ptr, len, "tags")))
1436 uc->data |= DEBUG_TAGS;
1437 else if ((arg_len = is_keyword(ptr, len, "pointer")))
1438 uc->data |= DEBUG_POINTER;
1441 ptr += arg_len; len -= arg_len;
1443 #ifdef DEBUG_PROC_INFO
1444 printk("sym_user_command: data=%ld\n", uc->data);
1447 #endif /* SYM_LINUX_DEBUG_CONTROL_SUPPORT */
1451 if ((arg_len = is_keyword(ptr, len, "no_disc")))
1452 uc->data &= ~SYM_DISC_ENABLED;
1455 ptr += arg_len; len -= arg_len;
1465 unsigned long flags;
1467 spin_lock_irqsave(np->s.host->host_lock, flags);
1468 sym_exec_user_command (np, uc);
1469 spin_unlock_irqrestore(np->s.host->host_lock, flags);
1474 #endif /* SYM_LINUX_USER_COMMAND_SUPPORT */
1477 #ifdef SYM_LINUX_USER_INFO_SUPPORT
1479 * Informations through the proc file system.
1488 static void copy_mem_info(struct info_str *info, char *data, int len)
1490 if (info->pos + len > info->length)
1491 len = info->length - info->pos;
1493 if (info->pos + len < info->offset) {
1497 if (info->pos < info->offset) {
1498 data += (info->offset - info->pos);
1499 len -= (info->offset - info->pos);
1503 memcpy(info->buffer + info->pos, data, len);
1508 static int copy_info(struct info_str *info, char *fmt, ...)
1514 va_start(args, fmt);
1515 len = vsprintf(buf, fmt, args);
1518 copy_mem_info(info, buf, len);
1523 * Copy formatted information into the input buffer.
1525 static int sym_host_info(struct sym_hcb *np, char *ptr, off_t offset, int len)
1527 struct info_str info;
1531 info.offset = offset;
1534 copy_info(&info, "Chip " NAME53C "%s, device id 0x%x, "
1535 "revision id 0x%x\n",
1536 np->s.chip_name, np->device_id, np->revision_id);
1537 copy_info(&info, "At PCI address %s, "
1543 pci_name(np->s.device),
1545 __irq_itoa(np->s.irq));
1549 copy_info(&info, "Min. period factor %d, %s SCSI BUS%s\n",
1550 (int) (np->minsync_dt ? np->minsync_dt : np->minsync),
1551 np->maxwide ? "Wide" : "Narrow",
1552 np->minsync_dt ? ", DT capable" : "");
1554 copy_info(&info, "Max. started commands %d, "
1555 "max. commands per LUN %d\n",
1556 SYM_CONF_MAX_START, SYM_CONF_MAX_TAG);
1558 return info.pos > info.offset? info.pos - info.offset : 0;
1560 #endif /* SYM_LINUX_USER_INFO_SUPPORT */
1563 * Entry point of the scsi proc fs of the driver.
1564 * - func = 0 means read (returns adapter infos)
1565 * - func = 1 means write (not yet merget from sym53c8xx)
1567 static int sym53c8xx_proc_info(struct Scsi_Host *host, char *buffer,
1568 char **start, off_t offset, int length, int func)
1570 struct host_data *host_data;
1571 struct sym_hcb *np = 0;
1574 host_data = (struct host_data *) host->hostdata;
1575 np = host_data->ncb;
1580 #ifdef SYM_LINUX_USER_COMMAND_SUPPORT
1581 retv = sym_user_command(np, buffer, length);
1588 #ifdef SYM_LINUX_USER_INFO_SUPPORT
1589 retv = sym_host_info(np, buffer, offset, length);
1597 #endif /* SYM_LINUX_PROC_INFO_SUPPORT */
1600 * Free controller resources.
1602 static void sym_free_resources(struct sym_hcb *np)
1605 * Free O/S specific resources.
1608 free_irq(np->s.irq, np);
1609 #ifndef SYM_CONF_IOMAPPED
1611 iounmap(np->s.mmio_va);
1614 iounmap(np->s.ram_va);
1616 * Free O/S independent resources.
1620 sym_mfree_dma(np, sizeof(*np), "HCB");
1624 * Ask/tell the system about DMA addressing.
1626 static int sym_setup_bus_dma_mask(struct sym_hcb *np)
1628 #if SYM_CONF_DMA_ADDRESSING_MODE == 0
1629 if (pci_set_dma_mask(np->s.device, 0xffffffffUL))
1632 #if SYM_CONF_DMA_ADDRESSING_MODE == 1
1633 #define PciDmaMask 0xffffffffffULL
1634 #elif SYM_CONF_DMA_ADDRESSING_MODE == 2
1635 #define PciDmaMask 0xffffffffffffffffULL
1637 if (np->features & FE_DAC) {
1638 if (!pci_set_dma_mask(np->s.device, PciDmaMask)) {
1640 printf_info("%s: using 64 bit DMA addressing\n",
1643 if (pci_set_dma_mask(np->s.device, 0xffffffffUL))
1652 printf_warning("%s: 32 BIT DMA ADDRESSING NOT SUPPORTED\n",
1658 * Host attach and initialisations.
1660 * Allocate host data and ncb structure.
1661 * Remap MMIO region.
1662 * Do chip initialization.
1663 * If all is OK, install interrupt handling and
1664 * start the timer daemon.
1666 static struct Scsi_Host * __devinit sym_attach(struct scsi_host_template *tpnt,
1667 int unit, struct sym_device *dev)
1669 struct host_data *host_data;
1670 struct sym_hcb *np = NULL;
1671 struct Scsi_Host *instance = NULL;
1672 unsigned long flags;
1676 "sym%d: <%s> rev 0x%x at pci %s "
1682 unit, dev->chip.name, dev->chip.revision_id,
1683 pci_name(dev->pdev),
1685 __irq_itoa(dev->s.irq));
1691 * Get the firmware for this chip.
1693 fw = sym_find_firmware(&dev->chip);
1698 * Allocate host_data structure
1700 instance = scsi_host_alloc(tpnt, sizeof(*host_data));
1703 host_data = (struct host_data *) instance->hostdata;
1706 * Allocate immediately the host control block,
1707 * since we are only expecting to succeed. :)
1708 * We keep track in the HCB of all the resources that
1709 * are to be released on error.
1711 np = __sym_calloc_dma(dev->pdev, sizeof(*np), "HCB");
1714 np->s.device = dev->pdev;
1715 np->bus_dmat = dev->pdev; /* Result in 1 DMA pool per HBA */
1716 host_data->ncb = np;
1717 np->s.host = instance;
1719 pci_set_drvdata(dev->pdev, np);
1722 * Copy some useful infos to the HCB.
1724 np->hcb_ba = vtobus(np);
1725 np->verbose = sym_driver_setup.verbose;
1726 np->s.device = dev->pdev;
1728 np->device_id = dev->chip.device_id;
1729 np->revision_id = dev->chip.revision_id;
1730 np->features = dev->chip.features;
1731 np->clock_divn = dev->chip.nr_divisor;
1732 np->maxoffs = dev->chip.offset_max;
1733 np->maxburst = dev->chip.burst_max;
1734 np->myaddr = dev->host_id;
1739 strlcpy(np->s.chip_name, dev->chip.name, sizeof(np->s.chip_name));
1740 sprintf(np->s.inst_name, "sym%d", np->s.unit);
1743 * Ask/tell the system about DMA addressing.
1745 if (sym_setup_bus_dma_mask(np))
1749 * Try to map the controller chip to
1750 * virtual and physical memory.
1752 np->mmio_ba = (u32)dev->s.base;
1753 np->s.io_ws = (np->features & FE_IO256)? 256 : 128;
1755 #ifndef SYM_CONF_IOMAPPED
1756 np->s.mmio_va = ioremap(dev->s.base_c, np->s.io_ws);
1757 if (!np->s.mmio_va) {
1758 printf_err("%s: can't map PCI MMIO region\n", sym_name(np));
1760 } else if (sym_verbose > 1)
1761 printf_info("%s: using memory mapped IO\n", sym_name(np));
1762 #endif /* !defined SYM_CONF_IOMAPPED */
1764 np->s.io_port = dev->s.io_port;
1767 * Map on-chip RAM if present and supported.
1769 if (!(np->features & FE_RAM))
1771 if (dev->s.base_2) {
1772 np->ram_ba = (u32)dev->s.base_2;
1773 if (np->features & FE_RAM8K)
1777 np->s.ram_va = ioremap(dev->s.base_2_c, np->ram_ws);
1778 if (!np->s.ram_va) {
1779 printf_err("%s: can't map PCI MEMORY region\n",
1786 * Perform O/S independent stuff.
1788 if (sym_hcb_attach(np, fw, dev->nvram))
1793 * Install the interrupt handler.
1794 * If we synchonize the C code with SCRIPTS on interrupt,
1795 * we donnot want to share the INTR line at all.
1797 if (request_irq(dev->s.irq, sym53c8xx_intr, SA_SHIRQ,
1799 printf_err("%s: request irq %d failure\n",
1800 sym_name(np), dev->s.irq);
1803 np->s.irq = dev->s.irq;
1806 * After SCSI devices have been opened, we cannot
1807 * reset the bus safely, so we do it here.
1809 spin_lock_irqsave(instance->host_lock, flags);
1810 if (sym_reset_scsi_bus(np, 0))
1814 * Initialize some queue headers.
1816 sym_que_init(&np->s.wait_cmdq);
1817 sym_que_init(&np->s.busy_cmdq);
1820 * Start the SCRIPTS.
1822 sym_start_up (np, 1);
1825 * Start the timer daemon
1827 init_timer(&np->s.timer);
1828 np->s.timer.data = (unsigned long) np;
1829 np->s.timer.function = sym53c8xx_timer;
1834 * Fill Linux host instance structure
1835 * and return success.
1837 instance->max_channel = 0;
1838 instance->this_id = np->myaddr;
1839 instance->max_id = np->maxwide ? 16 : 8;
1840 instance->max_lun = SYM_CONF_MAX_LUN;
1841 #ifndef SYM_CONF_IOMAPPED
1842 instance->base = (unsigned long) np->s.mmio_va;
1844 instance->irq = np->s.irq;
1845 instance->unique_id = np->s.io_port;
1846 instance->io_port = np->s.io_port;
1847 instance->n_io_port = np->s.io_ws;
1848 instance->dma_channel = 0;
1849 instance->cmd_per_lun = SYM_CONF_MAX_TAG;
1850 instance->can_queue = (SYM_CONF_MAX_START-2);
1851 instance->sg_tablesize = SYM_CONF_MAX_SG;
1852 instance->max_cmd_len = 16;
1853 BUG_ON(sym2_transport_template == NULL);
1854 instance->transportt = sym2_transport_template;
1856 spin_unlock_irqrestore(instance->host_lock, flags);
1861 printf_err("%s: FATAL ERROR: CHECK SCSI BUS - CABLES, "
1862 "TERMINATION, DEVICE POWER etc.!\n", sym_name(np));
1863 spin_unlock_irqrestore(instance->host_lock, flags);
1867 printf_info("%s: giving up ...\n", sym_name(np));
1869 sym_free_resources(np);
1870 scsi_host_put(instance);
1877 * Detect and try to read SYMBIOS and TEKRAM NVRAM.
1879 #if SYM_CONF_NVRAM_SUPPORT
1880 static void __devinit sym_get_nvram(struct sym_device *devp, struct sym_nvram *nvp)
1883 devp->device_id = devp->chip.device_id;
1887 * Get access to chip IO registers
1889 #ifndef SYM_CONF_IOMAPPED
1890 devp->s.mmio_va = ioremap(devp->s.base_c, 128);
1891 if (!devp->s.mmio_va)
1895 sym_read_nvram(devp, nvp);
1898 * Release access to chip IO registers
1900 #ifndef SYM_CONF_IOMAPPED
1901 iounmap(devp->s.mmio_va);
1905 static inline void sym_get_nvram(struct sym_device *devp, struct sym_nvram *nvp)
1908 #endif /* SYM_CONF_NVRAM_SUPPORT */
1911 * Driver setup from the boot command line
1913 #ifdef SYM_LINUX_BOOT_COMMAND_LINE_SUPPORT
1915 static struct sym_driver_setup
1916 sym_driver_safe_setup __initdata = SYM_LINUX_DRIVER_SAFE_SETUP;
1918 char *sym53c8xx = 0; /* command line passed by insmod */
1919 MODULE_PARM(sym53c8xx, "s");
1922 #define OPT_MAX_TAG 1
1923 #define OPT_BURST_ORDER 2
1924 #define OPT_SCSI_LED 3
1925 #define OPT_SCSI_DIFF 4
1926 #define OPT_IRQ_MODE 5
1927 #define OPT_SCSI_BUS_CHECK 6
1928 #define OPT_HOST_ID 7
1929 #define OPT_REVERSE_PROBE 8
1930 #define OPT_VERBOSE 9
1931 #define OPT_DEBUG 10
1932 #define OPT_SETTLE_DELAY 11
1933 #define OPT_USE_NVRAM 12
1934 #define OPT_EXCLUDE 13
1935 #define OPT_SAFE_SETUP 14
1937 static char setup_token[] __initdata =
1941 "hostid:" "revprob:"
1953 static int __init get_setup_token(char *p)
1955 char *cur = setup_token;
1959 while (cur != NULL && (pc = strchr(cur, ':')) != NULL) {
1962 if (!strncmp(p, cur, pc - cur))
1968 #endif /* SYM_LINUX_BOOT_COMMAND_LINE_SUPPORT */
1970 int __init sym53c8xx_setup(char *str)
1972 #ifdef SYM_LINUX_BOOT_COMMAND_LINE_SUPPORT
1979 while (cur != NULL && (pc = strchr(cur, ':')) != NULL) {
1991 val = (int) simple_strtoul(pv, &pe, 0);
1993 switch (get_setup_token(cur)) {
1995 sym_driver_setup.max_tag = val;
1996 if (!(pe && *pe == '/'))
1999 while (*pe && *pe != ARG_SEP &&
2000 i < sizeof(sym_driver_setup.tag_ctrl)-1) {
2001 sym_driver_setup.tag_ctrl[i++] = *pe++;
2003 sym_driver_setup.tag_ctrl[i] = '\0';
2005 case OPT_SAFE_SETUP:
2006 memcpy(&sym_driver_setup, &sym_driver_safe_setup,
2007 sizeof(sym_driver_setup));
2011 sym_driver_setup.excludes[xi++] = val;
2014 #define __SIMPLE_OPTION(NAME, name) \
2015 case OPT_ ## NAME : \
2016 sym_driver_setup.name = val;\
2019 __SIMPLE_OPTION(BURST_ORDER, burst_order)
2020 __SIMPLE_OPTION(SCSI_LED, scsi_led)
2021 __SIMPLE_OPTION(SCSI_DIFF, scsi_diff)
2022 __SIMPLE_OPTION(IRQ_MODE, irq_mode)
2023 __SIMPLE_OPTION(SCSI_BUS_CHECK, scsi_bus_check)
2024 __SIMPLE_OPTION(HOST_ID, host_id)
2025 __SIMPLE_OPTION(REVERSE_PROBE, reverse_probe)
2026 __SIMPLE_OPTION(VERBOSE, verbose)
2027 __SIMPLE_OPTION(DEBUG, debug)
2028 __SIMPLE_OPTION(SETTLE_DELAY, settle_delay)
2029 __SIMPLE_OPTION(USE_NVRAM, use_nvram)
2031 #undef __SIMPLE_OPTION
2034 printk("sym53c8xx_setup: unexpected boot option '%.*s' ignored\n", (int)(pc-cur+1), cur);
2038 if ((cur = strchr(cur, ARG_SEP)) != NULL)
2041 #endif /* SYM_LINUX_BOOT_COMMAND_LINE_SUPPORT */
2046 __setup("sym53c8xx=", sym53c8xx_setup);
2050 * Read and check the PCI configuration for any detected NCR
2051 * boards and save data for attaching after all boards have
2054 static int __devinit
2055 sym53c8xx_pci_init(struct pci_dev *pdev, struct sym_device *device)
2057 struct sym_pci_chip *chip;
2058 u_long base, base_2;
2059 u_long base_c, base_2_c, io_port;
2061 u_short device_id, status_reg;
2064 /* Choose some short name for this device */
2065 sprintf(device->s.inst_name, "sym.%d.%d.%d", pdev->bus->number,
2066 PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
2068 device_id = pdev->device;
2070 io_port = pdev->resource[0].start;
2072 base_c = pdev->resource[1].start;
2073 i = pci_get_base_address(pdev, 1, &base);
2075 base_2_c = pdev->resource[i].start;
2076 pci_get_base_address(pdev, i, &base_2);
2078 base &= PCI_BASE_ADDRESS_MEM_MASK;
2079 base_2 &= PCI_BASE_ADDRESS_MEM_MASK;
2081 pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
2084 * If user excluded this chip, do not initialize it.
2087 for (i = 0 ; i < 8 ; i++) {
2088 if (sym_driver_setup.excludes[i] == io_port)
2094 * Check if the chip is supported.
2096 chip = sym_lookup_pci_chip_table(device_id, revision);
2098 printf_info("%s: device not supported\n", sym_name(device));
2103 * Check if the chip has been assigned resources we need.
2104 * XXX: can this still happen with Linux 2.6's PCI layer?
2106 #ifdef SYM_CONF_IOMAPPED
2108 printf_info("%s: IO base address disabled.\n",
2114 printf_info("%s: MMIO base address disabled.\n",
2121 * Ignore Symbios chips controlled by various RAID controllers.
2122 * These controllers set value 0x52414944 at RAM end - 16.
2124 #if defined(__i386__)
2126 unsigned int ram_size, ram_val;
2129 if (chip->features & FE_RAM8K)
2134 ram_ptr = ioremap(base_2_c, ram_size);
2136 ram_val = readl_raw(ram_ptr + ram_size - 16);
2138 if (ram_val == 0x52414944) {
2139 printf_info("%s: not initializing, "
2140 "driven by RAID controller.\n",
2146 #endif /* i386 and PCI MEMORY accessible */
2149 * Copy the chip description to our device structure,
2150 * so we can make it match the actual device and options.
2152 memcpy(&device->chip, chip, sizeof(device->chip));
2153 device->chip.revision_id = revision;
2156 * Some features are required to be enabled in order to
2157 * work around some chip problems. :) ;)
2158 * (ITEM 12 of a DEL about the 896 I haven't yet).
2159 * We must ensure the chip will use WRITE AND INVALIDATE.
2160 * The revision number limit is for now arbitrary.
2162 if (device_id == PCI_DEVICE_ID_NCR_53C896 && revision < 0x4) {
2163 chip->features |= (FE_WRIE | FE_CLSE);
2166 /* If the chip can do Memory Write Invalidate, enable it */
2167 if (chip->features & FE_WRIE) {
2168 if (pci_set_mwi(pdev))
2173 * Work around for errant bit in 895A. The 66Mhz
2174 * capable bit is set erroneously. Clear this bit.
2177 * Make sure Config space and Features agree.
2179 * Recall: writes are not normal to status register -
2180 * write a 1 to clear and a 0 to leave unchanged.
2181 * Can only reset bits.
2183 pci_read_config_word(pdev, PCI_STATUS, &status_reg);
2184 if (chip->features & FE_66MHZ) {
2185 if (!(status_reg & PCI_STATUS_66MHZ))
2186 chip->features &= ~FE_66MHZ;
2188 if (status_reg & PCI_STATUS_66MHZ) {
2189 status_reg = PCI_STATUS_66MHZ;
2190 pci_write_config_word(pdev, PCI_STATUS, status_reg);
2191 pci_read_config_word(pdev, PCI_STATUS, &status_reg);
2196 * Initialise device structure with items required by sym_attach.
2198 device->pdev = pdev;
2199 device->s.base = base;
2200 device->s.base_2 = base_2;
2201 device->s.base_c = base_c;
2202 device->s.base_2_c = base_2_c;
2203 device->s.io_port = io_port;
2204 device->s.irq = pdev->irq;
2210 * The NCR PQS and PDS cards are constructed as a DEC bridge
2211 * behind which sits a proprietary NCR memory controller and
2212 * either four or two 53c875s as separate devices. We can tell
2213 * if an 875 is part of a PQS/PDS or not since if it is, it will
2214 * be on the same bus as the memory controller. In its usual
2215 * mode of operation, the 875s are slaved to the memory
2216 * controller for all transfers. To operate with the Linux
2217 * driver, the memory controller is disabled and the 875s
2218 * freed to function independently. The only wrinkle is that
2219 * the preset SCSI ID (which may be zero) must be read in from
2220 * a special configuration space register of the 875.
2222 void sym_config_pqs(struct pci_dev *pdev, struct sym_device *sym_dev)
2226 for (slot = 0; slot < 256; slot++) {
2228 struct pci_dev *memc = pci_get_slot(pdev->bus, slot);
2230 if (!memc || memc->vendor != 0x101a || memc->device == 0x0009) {
2236 * We set these bits in the memory controller once per 875.
2237 * This isn't a problem in practice.
2240 /* bit 1: allow individual 875 configuration */
2241 pci_read_config_byte(memc, 0x44, &tmp);
2243 pci_write_config_byte(memc, 0x44, tmp);
2245 /* bit 2: drive individual 875 interrupts to the bus */
2246 pci_read_config_byte(memc, 0x45, &tmp);
2248 pci_write_config_byte(memc, 0x45, tmp);
2250 pci_read_config_byte(pdev, 0x84, &tmp);
2251 sym_dev->host_id = tmp;
2260 * Called before unloading the module.
2262 * We have to free resources and halt the NCR chip.
2264 static int sym_detach(struct sym_hcb *np)
2266 printk("%s: detaching ...\n", sym_name(np));
2268 del_timer_sync(&np->s.timer);
2272 * We should use sym_soft_reset(), but we don't want to do
2273 * so, since we may not be safe if interrupts occur.
2275 printk("%s: resetting chip\n", sym_name(np));
2276 OUTB (nc_istat, SRST);
2280 sym_free_resources(np);
2285 MODULE_LICENSE("Dual BSD/GPL");
2288 * Driver host template.
2290 static struct scsi_host_template sym2_template = {
2291 .module = THIS_MODULE,
2292 .name = "sym53c8xx",
2293 .info = sym53c8xx_info,
2294 .queuecommand = sym53c8xx_queue_command,
2295 .slave_configure = sym53c8xx_slave_configure,
2296 .eh_abort_handler = sym53c8xx_eh_abort_handler,
2297 .eh_device_reset_handler = sym53c8xx_eh_device_reset_handler,
2298 .eh_bus_reset_handler = sym53c8xx_eh_bus_reset_handler,
2299 .eh_host_reset_handler = sym53c8xx_eh_host_reset_handler,
2301 .use_clustering = DISABLE_CLUSTERING,
2302 #ifdef SYM_LINUX_PROC_INFO_SUPPORT
2303 .proc_info = sym53c8xx_proc_info,
2304 .proc_name = NAME53C8XX,
2308 static int attach_count;
2310 static int __devinit sym2_probe(struct pci_dev *pdev,
2311 const struct pci_device_id *ent)
2313 struct sym_device sym_dev;
2314 struct sym_nvram nvram;
2315 struct Scsi_Host *instance;
2317 memset(&sym_dev, 0, sizeof(sym_dev));
2318 memset(&nvram, 0, sizeof(nvram));
2320 if (pci_enable_device(pdev))
2323 pci_set_master(pdev);
2325 if (pci_request_regions(pdev, NAME53C8XX))
2328 sym_dev.host_id = SYM_SETUP_HOST_ID;
2329 if (sym53c8xx_pci_init(pdev, &sym_dev))
2332 sym_config_pqs(pdev, &sym_dev);
2334 sym_get_nvram(&sym_dev, &nvram);
2336 instance = sym_attach(&sym2_template, attach_count, &sym_dev);
2340 if (scsi_add_host(instance, &pdev->dev))
2342 scsi_scan_host(instance);
2349 sym_detach(pci_get_drvdata(pdev));
2351 pci_release_regions(pdev);
2353 pci_disable_device(pdev);
2357 static void __devexit sym2_remove(struct pci_dev *pdev)
2359 struct sym_hcb *np = pci_get_drvdata(pdev);
2360 struct Scsi_Host *host = np->s.host;
2362 scsi_remove_host(host);
2363 scsi_host_put(host);
2367 pci_release_regions(pdev);
2368 pci_disable_device(pdev);
2373 static void sym2_get_offset(struct scsi_device *sdev)
2375 struct sym_hcb *np = ((struct host_data *)sdev->host->hostdata)->ncb;
2376 struct sym_tcb *tp = &np->target[sdev->id];
2378 spi_offset(sdev) = tp->tinfo.curr.offset;
2381 static void sym2_set_offset(struct scsi_device *sdev, int offset)
2383 struct sym_hcb *np = ((struct host_data *)sdev->host->hostdata)->ncb;
2384 struct sym_tcb *tp = &np->target[sdev->id];
2386 if (tp->tinfo.curr.options & PPR_OPT_DT) {
2387 if (offset > np->maxoffs_dt)
2388 offset = np->maxoffs_dt;
2390 if (offset > np->maxoffs)
2391 offset = np->maxoffs;
2393 tp->tinfo.goal.offset = offset;
2397 static void sym2_get_period(struct scsi_device *sdev)
2399 struct sym_hcb *np = ((struct host_data *)sdev->host->hostdata)->ncb;
2400 struct sym_tcb *tp = &np->target[sdev->id];
2402 spi_period(sdev) = tp->tinfo.curr.period;
2405 static void sym2_set_period(struct scsi_device *sdev, int period)
2407 struct sym_hcb *np = ((struct host_data *)sdev->host->hostdata)->ncb;
2408 struct sym_tcb *tp = &np->target[sdev->id];
2410 if (period <= 9 && np->minsync_dt) {
2411 if (period < np->minsync_dt)
2412 period = np->minsync_dt;
2413 tp->tinfo.goal.options = PPR_OPT_DT;
2414 tp->tinfo.goal.period = period;
2415 if (!tp->tinfo.curr.offset ||
2416 tp->tinfo.curr.offset > np->maxoffs_dt)
2417 tp->tinfo.goal.offset = np->maxoffs_dt;
2419 if (period < np->minsync)
2420 period = np->minsync;
2421 tp->tinfo.goal.options = 0;
2422 tp->tinfo.goal.period = period;
2423 if (!tp->tinfo.curr.offset ||
2424 tp->tinfo.curr.offset > np->maxoffs)
2425 tp->tinfo.goal.offset = np->maxoffs;
2429 static void sym2_get_width(struct scsi_device *sdev)
2431 struct sym_hcb *np = ((struct host_data *)sdev->host->hostdata)->ncb;
2432 struct sym_tcb *tp = &np->target[sdev->id];
2434 spi_width(sdev) = tp->tinfo.curr.width ? 1 : 0;
2437 static void sym2_set_width(struct scsi_device *sdev, int width)
2439 struct sym_hcb *np = ((struct host_data *)sdev->host->hostdata)->ncb;
2440 struct sym_tcb *tp = &np->target[sdev->id];
2442 tp->tinfo.goal.width = width;
2445 static void sym2_get_dt(struct scsi_device *sdev)
2447 struct sym_hcb *np = ((struct host_data *)sdev->host->hostdata)->ncb;
2448 struct sym_tcb *tp = &np->target[sdev->id];
2450 spi_dt(sdev) = (tp->tinfo.curr.options & PPR_OPT_DT) ? 1 : 0;
2453 static void sym2_set_dt(struct scsi_device *sdev, int dt)
2455 struct sym_hcb *np = ((struct host_data *)sdev->host->hostdata)->ncb;
2456 struct sym_tcb *tp = &np->target[sdev->id];
2459 /* if clearing DT, then we may need to reduce the
2460 * period and the offset */
2461 if (tp->tinfo.curr.period < np->minsync)
2462 tp->tinfo.goal.period = np->minsync;
2463 if (tp->tinfo.curr.offset > np->maxoffs)
2464 tp->tinfo.goal.offset = np->maxoffs;
2465 tp->tinfo.goal.options &= ~PPR_OPT_DT;
2467 tp->tinfo.goal.options |= PPR_OPT_DT;
2472 static struct spi_function_template sym2_transport_functions = {
2473 .set_offset = sym2_set_offset,
2474 .get_offset = sym2_get_offset,
2476 .set_period = sym2_set_period,
2477 .get_period = sym2_get_period,
2479 .set_width = sym2_set_width,
2480 .get_width = sym2_get_width,
2482 .get_dt = sym2_get_dt,
2483 .set_dt = sym2_set_dt,
2487 static struct pci_device_id sym2_id_table[] __devinitdata = {
2488 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C810,
2489 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2490 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C820,
2491 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, /* new */
2492 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C825,
2493 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2494 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C815,
2495 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2496 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C810AP,
2497 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, /* new */
2498 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C860,
2499 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2500 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1510,
2501 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2502 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C896,
2503 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2504 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C895,
2505 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2506 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C885,
2507 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2508 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C875,
2509 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2510 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C1510,
2511 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, /* new */
2512 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C895A,
2513 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2514 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C875A,
2515 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2516 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1010_33,
2517 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2518 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1010_66,
2519 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2520 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C875J,
2521 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2525 MODULE_DEVICE_TABLE(pci, sym2_id_table);
2527 static struct pci_driver sym2_driver = {
2529 .id_table = sym2_id_table,
2530 .probe = sym2_probe,
2531 .remove = __devexit_p(sym2_remove),
2534 static int __init sym2_init(void)
2536 sym2_transport_template = spi_attach_transport(&sym2_transport_functions);
2537 if (!sym2_transport_template)
2540 pci_register_driver(&sym2_driver);
2544 static void __exit sym2_exit(void)
2546 pci_unregister_driver(&sym2_driver);
2547 spi_release_transport(sym2_transport_template);
2550 module_init(sym2_init);
2551 module_exit(sym2_exit);