RT-AC66 3.0.0.4.374.130 core
[tomato.git] / release / src-rt-6.x / linux / linux-2.6 / drivers / scsi / sym53c8xx_2 / sym_glue.c
blob09845f1d402dfa87c3569062a4b50c4cef2639b1
1 /*
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>
51 #include "sym_glue.h"
52 #include "sym_nvram.h"
54 #define NAME53C "sym53c"
55 #define NAME53C8XX "sym53c8xx"
57 #define IRQ_FMT "%d"
58 #define IRQ_PRM(x) (x)
60 struct sym_driver_setup sym_driver_setup = SYM_LINUX_DRIVER_SETUP;
61 unsigned int sym_debug_flags = 0;
63 static char *excl_string;
64 static char *safe_string;
65 module_param_named(cmd_per_lun, sym_driver_setup.max_tag, ushort, 0);
66 module_param_string(tag_ctrl, sym_driver_setup.tag_ctrl, 100, 0);
67 module_param_named(burst, sym_driver_setup.burst_order, byte, 0);
68 module_param_named(led, sym_driver_setup.scsi_led, byte, 0);
69 module_param_named(diff, sym_driver_setup.scsi_diff, byte, 0);
70 module_param_named(irqm, sym_driver_setup.irq_mode, byte, 0);
71 module_param_named(buschk, sym_driver_setup.scsi_bus_check, byte, 0);
72 module_param_named(hostid, sym_driver_setup.host_id, byte, 0);
73 module_param_named(verb, sym_driver_setup.verbose, byte, 0);
74 module_param_named(debug, sym_debug_flags, uint, 0);
75 module_param_named(settle, sym_driver_setup.settle_delay, byte, 0);
76 module_param_named(nvram, sym_driver_setup.use_nvram, byte, 0);
77 module_param_named(excl, excl_string, charp, 0);
78 module_param_named(safe, safe_string, charp, 0);
80 MODULE_PARM_DESC(cmd_per_lun, "The maximum number of tags to use by default");
81 MODULE_PARM_DESC(tag_ctrl, "More detailed control over tags per LUN");
82 MODULE_PARM_DESC(burst, "Maximum burst. 0 to disable, 255 to read from registers");
83 MODULE_PARM_DESC(led, "Set to 1 to enable LED support");
84 MODULE_PARM_DESC(diff, "0 for no differential mode, 1 for BIOS, 2 for always, 3 for not GPIO3");
85 MODULE_PARM_DESC(irqm, "0 for open drain, 1 to leave alone, 2 for totem pole");
86 MODULE_PARM_DESC(buschk, "0 to not check, 1 for detach on error, 2 for warn on error");
87 MODULE_PARM_DESC(hostid, "The SCSI ID to use for the host adapters");
88 MODULE_PARM_DESC(verb, "0 for minimal verbosity, 1 for normal, 2 for excessive");
89 MODULE_PARM_DESC(debug, "Set bits to enable debugging");
90 MODULE_PARM_DESC(settle, "Settle delay in seconds. Default 3");
91 MODULE_PARM_DESC(nvram, "Option currently not used");
92 MODULE_PARM_DESC(excl, "List ioport addresses here to prevent controllers from being attached");
93 MODULE_PARM_DESC(safe, "Set other settings to a \"safe mode\"");
95 MODULE_LICENSE("GPL");
96 MODULE_VERSION(SYM_VERSION);
97 MODULE_AUTHOR("Matthew Wilcox <matthew@wil.cx>");
98 MODULE_DESCRIPTION("NCR, Symbios and LSI 8xx and 1010 PCI SCSI adapters");
100 static void sym2_setup_params(void)
102 char *p = excl_string;
103 int xi = 0;
105 while (p && (xi < 8)) {
106 char *next_p;
107 int val = (int) simple_strtoul(p, &next_p, 0);
108 sym_driver_setup.excludes[xi++] = val;
109 p = next_p;
112 if (safe_string) {
113 if (*safe_string == 'y') {
114 sym_driver_setup.max_tag = 0;
115 sym_driver_setup.burst_order = 0;
116 sym_driver_setup.scsi_led = 0;
117 sym_driver_setup.scsi_diff = 1;
118 sym_driver_setup.irq_mode = 0;
119 sym_driver_setup.scsi_bus_check = 2;
120 sym_driver_setup.host_id = 7;
121 sym_driver_setup.verbose = 2;
122 sym_driver_setup.settle_delay = 10;
123 sym_driver_setup.use_nvram = 1;
124 } else if (*safe_string != 'n') {
125 printk(KERN_WARNING NAME53C8XX "Ignoring parameter %s"
126 " passed to safe option", safe_string);
131 static struct scsi_transport_template *sym2_transport_template = NULL;
134 * Driver private area in the SCSI command structure.
136 struct sym_ucmd { /* Override the SCSI pointer structure */
137 dma_addr_t data_mapping;
138 unsigned char data_mapped;
139 unsigned char to_do; /* For error handling */
140 void (*old_done)(struct scsi_cmnd *); /* For error handling */
141 struct completion *eh_done; /* For error handling */
144 #define SYM_UCMD_PTR(cmd) ((struct sym_ucmd *)(&(cmd)->SCp))
145 #define SYM_SOFTC_PTR(cmd) sym_get_hcb(cmd->device->host)
147 static void __unmap_scsi_data(struct pci_dev *pdev, struct scsi_cmnd *cmd)
149 int dma_dir = cmd->sc_data_direction;
151 switch(SYM_UCMD_PTR(cmd)->data_mapped) {
152 case 2:
153 pci_unmap_sg(pdev, cmd->request_buffer, cmd->use_sg, dma_dir);
154 break;
155 case 1:
156 pci_unmap_single(pdev, SYM_UCMD_PTR(cmd)->data_mapping,
157 cmd->request_bufflen, dma_dir);
158 break;
160 SYM_UCMD_PTR(cmd)->data_mapped = 0;
163 static dma_addr_t __map_scsi_single_data(struct pci_dev *pdev, struct scsi_cmnd *cmd)
165 dma_addr_t mapping;
166 int dma_dir = cmd->sc_data_direction;
168 mapping = pci_map_single(pdev, cmd->request_buffer,
169 cmd->request_bufflen, dma_dir);
170 if (mapping) {
171 SYM_UCMD_PTR(cmd)->data_mapped = 1;
172 SYM_UCMD_PTR(cmd)->data_mapping = mapping;
175 return mapping;
178 static int __map_scsi_sg_data(struct pci_dev *pdev, struct scsi_cmnd *cmd)
180 int use_sg;
181 int dma_dir = cmd->sc_data_direction;
183 use_sg = pci_map_sg(pdev, cmd->request_buffer, cmd->use_sg, dma_dir);
184 if (use_sg > 0) {
185 SYM_UCMD_PTR(cmd)->data_mapped = 2;
186 SYM_UCMD_PTR(cmd)->data_mapping = use_sg;
189 return use_sg;
192 #define unmap_scsi_data(np, cmd) \
193 __unmap_scsi_data(np->s.device, cmd)
194 #define map_scsi_single_data(np, cmd) \
195 __map_scsi_single_data(np->s.device, cmd)
196 #define map_scsi_sg_data(np, cmd) \
197 __map_scsi_sg_data(np->s.device, cmd)
199 * Complete a pending CAM CCB.
201 void sym_xpt_done(struct sym_hcb *np, struct scsi_cmnd *cmd)
203 unmap_scsi_data(np, cmd);
204 cmd->scsi_done(cmd);
207 static void sym_xpt_done2(struct sym_hcb *np, struct scsi_cmnd *cmd, int cam_status)
209 sym_set_cam_status(cmd, cam_status);
210 sym_xpt_done(np, cmd);
215 * Tell the SCSI layer about a BUS RESET.
217 void sym_xpt_async_bus_reset(struct sym_hcb *np)
219 printf_notice("%s: SCSI BUS has been reset.\n", sym_name(np));
220 np->s.settle_time = jiffies + sym_driver_setup.settle_delay * HZ;
221 np->s.settle_time_valid = 1;
222 if (sym_verbose >= 2)
223 printf_info("%s: command processing suspended for %d seconds\n",
224 sym_name(np), sym_driver_setup.settle_delay);
228 * Tell the SCSI layer about a BUS DEVICE RESET message sent.
230 void sym_xpt_async_sent_bdr(struct sym_hcb *np, int target)
232 printf_notice("%s: TARGET %d has been reset.\n", sym_name(np), target);
236 * Choose the more appropriate CAM status if
237 * the IO encountered an extended error.
239 static int sym_xerr_cam_status(int cam_status, int x_status)
241 if (x_status) {
242 if (x_status & XE_PARITY_ERR)
243 cam_status = DID_PARITY;
244 else if (x_status &(XE_EXTRA_DATA|XE_SODL_UNRUN|XE_SWIDE_OVRUN))
245 cam_status = DID_ERROR;
246 else if (x_status & XE_BAD_PHASE)
247 cam_status = DID_ERROR;
248 else
249 cam_status = DID_ERROR;
251 return cam_status;
255 * Build CAM result for a failed or auto-sensed IO.
257 void sym_set_cam_result_error(struct sym_hcb *np, struct sym_ccb *cp, int resid)
259 struct scsi_cmnd *cmd = cp->cmd;
260 u_int cam_status, scsi_status, drv_status;
262 drv_status = 0;
263 cam_status = DID_OK;
264 scsi_status = cp->ssss_status;
266 if (cp->host_flags & HF_SENSE) {
267 scsi_status = cp->sv_scsi_status;
268 resid = cp->sv_resid;
269 if (sym_verbose && cp->sv_xerr_status)
270 sym_print_xerr(cmd, cp->sv_xerr_status);
271 if (cp->host_status == HS_COMPLETE &&
272 cp->ssss_status == S_GOOD &&
273 cp->xerr_status == 0) {
274 cam_status = sym_xerr_cam_status(DID_OK,
275 cp->sv_xerr_status);
276 drv_status = DRIVER_SENSE;
278 * Bounce back the sense data to user.
280 memset(&cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
281 memcpy(cmd->sense_buffer, cp->sns_bbuf,
282 min(SCSI_SENSE_BUFFERSIZE, SYM_SNS_BBUF_LEN));
283 #if 0
285 * If the device reports a UNIT ATTENTION condition
286 * due to a RESET condition, we should consider all
287 * disconnect CCBs for this unit as aborted.
289 if (1) {
290 u_char *p;
291 p = (u_char *) cmd->sense_data;
292 if (p[0]==0x70 && p[2]==0x6 && p[12]==0x29)
293 sym_clear_tasks(np, DID_ABORT,
294 cp->target,cp->lun, -1);
296 #endif
297 } else {
299 * Error return from our internal request sense. This
300 * is bad: we must clear the contingent allegiance
301 * condition otherwise the device will always return
302 * BUSY. Use a big stick.
304 sym_reset_scsi_target(np, cmd->device->id);
305 cam_status = DID_ERROR;
307 } else if (cp->host_status == HS_COMPLETE) /* Bad SCSI status */
308 cam_status = DID_OK;
309 else if (cp->host_status == HS_SEL_TIMEOUT) /* Selection timeout */
310 cam_status = DID_NO_CONNECT;
311 else if (cp->host_status == HS_UNEXPECTED) /* Unexpected BUS FREE*/
312 cam_status = DID_ERROR;
313 else { /* Extended error */
314 if (sym_verbose) {
315 sym_print_addr(cmd, "COMMAND FAILED (%x %x %x).\n",
316 cp->host_status, cp->ssss_status,
317 cp->xerr_status);
320 * Set the most appropriate value for CAM status.
322 cam_status = sym_xerr_cam_status(DID_ERROR, cp->xerr_status);
324 cmd->resid = resid;
325 cmd->result = (drv_status << 24) + (cam_status << 16) + scsi_status;
330 * Build the scatter/gather array for an I/O.
333 static int sym_scatter_no_sglist(struct sym_hcb *np, struct sym_ccb *cp, struct scsi_cmnd *cmd)
335 struct sym_tblmove *data = &cp->phys.data[SYM_CONF_MAX_SG-1];
336 int segment;
337 unsigned int len = cmd->request_bufflen;
339 if (len) {
340 dma_addr_t baddr = map_scsi_single_data(np, cmd);
341 if (baddr) {
342 if (len & 1) {
343 struct sym_tcb *tp = &np->target[cp->target];
344 if (tp->head.wval & EWS) {
345 len++;
346 cp->odd_byte_adjustment++;
349 cp->data_len = len;
350 sym_build_sge(np, data, baddr, len);
351 segment = 1;
352 } else {
353 segment = -2;
355 } else {
356 segment = 0;
359 return segment;
362 static int sym_scatter(struct sym_hcb *np, struct sym_ccb *cp, struct scsi_cmnd *cmd)
364 int segment;
365 int use_sg = (int) cmd->use_sg;
367 cp->data_len = 0;
369 if (!use_sg)
370 segment = sym_scatter_no_sglist(np, cp, cmd);
371 else if ((use_sg = map_scsi_sg_data(np, cmd)) > 0) {
372 struct scatterlist *scatter = (struct scatterlist *)cmd->request_buffer;
373 struct sym_tcb *tp = &np->target[cp->target];
374 struct sym_tblmove *data;
376 if (use_sg > SYM_CONF_MAX_SG) {
377 unmap_scsi_data(np, cmd);
378 return -1;
381 data = &cp->phys.data[SYM_CONF_MAX_SG - use_sg];
383 for (segment = 0; segment < use_sg; segment++) {
384 dma_addr_t baddr = sg_dma_address(&scatter[segment]);
385 unsigned int len = sg_dma_len(&scatter[segment]);
387 if ((len & 1) && (tp->head.wval & EWS)) {
388 len++;
389 cp->odd_byte_adjustment++;
392 sym_build_sge(np, &data[segment], baddr, len);
393 cp->data_len += len;
395 } else {
396 segment = -2;
399 return segment;
403 * Queue a SCSI command.
405 static int sym_queue_command(struct sym_hcb *np, struct scsi_cmnd *cmd)
407 struct scsi_device *sdev = cmd->device;
408 struct sym_tcb *tp;
409 struct sym_lcb *lp;
410 struct sym_ccb *cp;
411 int order;
414 * Minimal checkings, so that we will not
415 * go outside our tables.
417 if (sdev->id == np->myaddr) {
418 sym_xpt_done2(np, cmd, DID_NO_CONNECT);
419 return 0;
423 * Retrieve the target descriptor.
425 tp = &np->target[sdev->id];
428 * Select tagged/untagged.
430 lp = sym_lp(tp, sdev->lun);
431 order = (lp && lp->s.reqtags) ? M_SIMPLE_TAG : 0;
434 * Queue the SCSI IO.
436 cp = sym_get_ccb(np, cmd, order);
437 if (!cp)
438 return 1; /* Means resource shortage */
439 sym_queue_scsiio(np, cmd, cp);
440 return 0;
444 * Setup buffers and pointers that address the CDB.
446 static inline int sym_setup_cdb(struct sym_hcb *np, struct scsi_cmnd *cmd, struct sym_ccb *cp)
448 memcpy(cp->cdb_buf, cmd->cmnd, cmd->cmd_len);
450 cp->phys.cmd.addr = CCB_BA(cp, cdb_buf[0]);
451 cp->phys.cmd.size = cpu_to_scr(cmd->cmd_len);
453 return 0;
457 * Setup pointers that address the data and start the I/O.
459 int sym_setup_data_and_start(struct sym_hcb *np, struct scsi_cmnd *cmd, struct sym_ccb *cp)
461 u32 lastp, goalp;
462 int dir;
465 * Build the CDB.
467 if (sym_setup_cdb(np, cmd, cp))
468 goto out_abort;
471 * No direction means no data.
473 dir = cmd->sc_data_direction;
474 if (dir != DMA_NONE) {
475 cp->segments = sym_scatter(np, cp, cmd);
476 if (cp->segments < 0) {
477 sym_set_cam_status(cmd, DID_ERROR);
478 goto out_abort;
482 * No segments means no data.
484 if (!cp->segments)
485 dir = DMA_NONE;
486 } else {
487 cp->data_len = 0;
488 cp->segments = 0;
492 * Set the data pointer.
494 switch (dir) {
495 case DMA_BIDIRECTIONAL:
496 printk("%s: got DMA_BIDIRECTIONAL command", sym_name(np));
497 sym_set_cam_status(cmd, DID_ERROR);
498 goto out_abort;
499 case DMA_TO_DEVICE:
500 goalp = SCRIPTA_BA(np, data_out2) + 8;
501 lastp = goalp - 8 - (cp->segments * (2*4));
502 break;
503 case DMA_FROM_DEVICE:
504 cp->host_flags |= HF_DATA_IN;
505 goalp = SCRIPTA_BA(np, data_in2) + 8;
506 lastp = goalp - 8 - (cp->segments * (2*4));
507 break;
508 case DMA_NONE:
509 default:
510 lastp = goalp = SCRIPTB_BA(np, no_data);
511 break;
515 * Set all pointers values needed by SCRIPTS.
517 cp->phys.head.lastp = cpu_to_scr(lastp);
518 cp->phys.head.savep = cpu_to_scr(lastp);
519 cp->startp = cp->phys.head.savep;
520 cp->goalp = cpu_to_scr(goalp);
523 * When `#ifed 1', the code below makes the driver
524 * panic on the first attempt to write to a SCSI device.
525 * It is the first test we want to do after a driver
526 * change that does not seem obviously safe. :)
528 #if 0
529 switch (cp->cdb_buf[0]) {
530 case 0x0A: case 0x2A: case 0xAA:
531 panic("XXXXXXXXXXXXX WRITE NOT YET ALLOWED XXXXXXXXXXXXXX\n");
532 break;
533 default:
534 break;
536 #endif
539 * activate this job.
541 sym_put_start_queue(np, cp);
542 return 0;
544 out_abort:
545 sym_free_ccb(np, cp);
546 sym_xpt_done(np, cmd);
547 return 0;
552 * timer daemon.
554 * Misused to keep the driver running when
555 * interrupts are not configured correctly.
557 static void sym_timer(struct sym_hcb *np)
559 unsigned long thistime = jiffies;
562 * Restart the timer.
564 np->s.timer.expires = thistime + SYM_CONF_TIMER_INTERVAL;
565 add_timer(&np->s.timer);
568 * If we are resetting the ncr, wait for settle_time before
569 * clearing it. Then command processing will be resumed.
571 if (np->s.settle_time_valid) {
572 if (time_before_eq(np->s.settle_time, thistime)) {
573 if (sym_verbose >= 2 )
574 printk("%s: command processing resumed\n",
575 sym_name(np));
576 np->s.settle_time_valid = 0;
578 return;
582 * Nothing to do for now, but that may come.
584 if (np->s.lasttime + 4*HZ < thistime) {
585 np->s.lasttime = thistime;
588 #ifdef SYM_CONF_PCIQ_MAY_MISS_COMPLETIONS
590 * Some way-broken PCI bridges may lead to
591 * completions being lost when the clearing
592 * of the INTFLY flag by the CPU occurs
593 * concurrently with the chip raising this flag.
594 * If this ever happen, lost completions will
595 * be reaped here.
597 sym_wakeup_done(np);
598 #endif
603 * PCI BUS error handler.
605 void sym_log_bus_error(struct sym_hcb *np)
607 u_short pci_sts;
608 pci_read_config_word(np->s.device, PCI_STATUS, &pci_sts);
609 if (pci_sts & 0xf900) {
610 pci_write_config_word(np->s.device, PCI_STATUS, pci_sts);
611 printf("%s: PCI STATUS = 0x%04x\n",
612 sym_name(np), pci_sts & 0xf900);
617 * queuecommand method. Entered with the host adapter lock held and
618 * interrupts disabled.
620 static int sym53c8xx_queue_command(struct scsi_cmnd *cmd,
621 void (*done)(struct scsi_cmnd *))
623 struct sym_hcb *np = SYM_SOFTC_PTR(cmd);
624 struct sym_ucmd *ucp = SYM_UCMD_PTR(cmd);
625 int sts = 0;
627 cmd->scsi_done = done;
628 memset(ucp, 0, sizeof(*ucp));
631 * Shorten our settle_time if needed for
632 * this command not to time out.
634 if (np->s.settle_time_valid && cmd->timeout_per_command) {
635 unsigned long tlimit = jiffies + cmd->timeout_per_command;
636 tlimit -= SYM_CONF_TIMER_INTERVAL*2;
637 if (time_after(np->s.settle_time, tlimit)) {
638 np->s.settle_time = tlimit;
642 if (np->s.settle_time_valid)
643 return SCSI_MLQUEUE_HOST_BUSY;
645 sts = sym_queue_command(np, cmd);
646 if (sts)
647 return SCSI_MLQUEUE_HOST_BUSY;
648 return 0;
652 * Linux entry point of the interrupt handler.
654 static irqreturn_t sym53c8xx_intr(int irq, void *dev_id)
656 unsigned long flags;
657 struct sym_hcb *np = (struct sym_hcb *)dev_id;
659 if (DEBUG_FLAGS & DEBUG_TINY) printf_debug ("[");
661 spin_lock_irqsave(np->s.host->host_lock, flags);
662 sym_interrupt(np);
663 spin_unlock_irqrestore(np->s.host->host_lock, flags);
665 if (DEBUG_FLAGS & DEBUG_TINY) printf_debug ("]\n");
667 return IRQ_HANDLED;
671 * Linux entry point of the timer handler
673 static void sym53c8xx_timer(unsigned long npref)
675 struct sym_hcb *np = (struct sym_hcb *)npref;
676 unsigned long flags;
678 spin_lock_irqsave(np->s.host->host_lock, flags);
679 sym_timer(np);
680 spin_unlock_irqrestore(np->s.host->host_lock, flags);
685 * What the eh thread wants us to perform.
687 #define SYM_EH_ABORT 0
688 #define SYM_EH_DEVICE_RESET 1
689 #define SYM_EH_BUS_RESET 2
690 #define SYM_EH_HOST_RESET 3
693 * What we will do regarding the involved SCSI command.
695 #define SYM_EH_DO_IGNORE 0
696 #define SYM_EH_DO_WAIT 2
699 * scsi_done() alias when error recovery is in progress.
701 static void sym_eh_done(struct scsi_cmnd *cmd)
703 struct sym_ucmd *ucmd = SYM_UCMD_PTR(cmd);
704 BUILD_BUG_ON(sizeof(struct scsi_pointer) < sizeof(struct sym_ucmd));
706 cmd->scsi_done = ucmd->old_done;
708 if (ucmd->to_do == SYM_EH_DO_WAIT)
709 complete(ucmd->eh_done);
713 * Generic method for our eh processing.
714 * The 'op' argument tells what we have to do.
716 static int sym_eh_handler(int op, char *opname, struct scsi_cmnd *cmd)
718 struct sym_hcb *np = SYM_SOFTC_PTR(cmd);
719 struct sym_ucmd *ucmd = SYM_UCMD_PTR(cmd);
720 struct Scsi_Host *host = cmd->device->host;
721 SYM_QUEHEAD *qp;
722 int to_do = SYM_EH_DO_IGNORE;
723 int sts = -1;
724 struct completion eh_done;
726 dev_warn(&cmd->device->sdev_gendev, "%s operation started.\n", opname);
728 spin_lock_irq(host->host_lock);
729 /* This one is queued in some place -> to wait for completion */
730 FOR_EACH_QUEUED_ELEMENT(&np->busy_ccbq, qp) {
731 struct sym_ccb *cp = sym_que_entry(qp, struct sym_ccb, link_ccbq);
732 if (cp->cmd == cmd) {
733 to_do = SYM_EH_DO_WAIT;
734 break;
738 if (to_do == SYM_EH_DO_WAIT) {
739 init_completion(&eh_done);
740 ucmd->old_done = cmd->scsi_done;
741 ucmd->eh_done = &eh_done;
742 wmb();
743 cmd->scsi_done = sym_eh_done;
746 /* Try to proceed the operation we have been asked for */
747 sts = -1;
748 switch(op) {
749 case SYM_EH_ABORT:
750 sts = sym_abort_scsiio(np, cmd, 1);
751 break;
752 case SYM_EH_DEVICE_RESET:
753 sts = sym_reset_scsi_target(np, cmd->device->id);
754 break;
755 case SYM_EH_BUS_RESET:
756 sym_reset_scsi_bus(np, 1);
757 sts = 0;
758 break;
759 case SYM_EH_HOST_RESET:
760 sym_reset_scsi_bus(np, 0);
761 sym_start_up (np, 1);
762 sts = 0;
763 break;
764 default:
765 break;
768 /* On error, restore everything and cross fingers :) */
769 if (sts) {
770 cmd->scsi_done = ucmd->old_done;
771 to_do = SYM_EH_DO_IGNORE;
774 ucmd->to_do = to_do;
775 spin_unlock_irq(host->host_lock);
777 if (to_do == SYM_EH_DO_WAIT) {
778 if (!wait_for_completion_timeout(&eh_done, 5*HZ)) {
779 ucmd->to_do = SYM_EH_DO_IGNORE;
780 wmb();
781 sts = -2;
784 dev_warn(&cmd->device->sdev_gendev, "%s operation %s.\n", opname,
785 sts==0 ? "complete" :sts==-2 ? "timed-out" : "failed");
786 return sts ? SCSI_FAILED : SCSI_SUCCESS;
791 * Error handlers called from the eh thread (one thread per HBA).
793 static int sym53c8xx_eh_abort_handler(struct scsi_cmnd *cmd)
795 return sym_eh_handler(SYM_EH_ABORT, "ABORT", cmd);
798 static int sym53c8xx_eh_device_reset_handler(struct scsi_cmnd *cmd)
800 return sym_eh_handler(SYM_EH_DEVICE_RESET, "DEVICE RESET", cmd);
803 static int sym53c8xx_eh_bus_reset_handler(struct scsi_cmnd *cmd)
805 return sym_eh_handler(SYM_EH_BUS_RESET, "BUS RESET", cmd);
808 static int sym53c8xx_eh_host_reset_handler(struct scsi_cmnd *cmd)
810 return sym_eh_handler(SYM_EH_HOST_RESET, "HOST RESET", cmd);
814 * Tune device queuing depth, according to various limits.
816 static void sym_tune_dev_queuing(struct sym_tcb *tp, int lun, u_short reqtags)
818 struct sym_lcb *lp = sym_lp(tp, lun);
819 u_short oldtags;
821 if (!lp)
822 return;
824 oldtags = lp->s.reqtags;
826 if (reqtags > lp->s.scdev_depth)
827 reqtags = lp->s.scdev_depth;
829 lp->s.reqtags = reqtags;
831 if (reqtags != oldtags) {
832 dev_info(&tp->starget->dev,
833 "tagged command queuing %s, command queue depth %d.\n",
834 lp->s.reqtags ? "enabled" : "disabled", reqtags);
839 * Linux select queue depths function
841 #define DEF_DEPTH (sym_driver_setup.max_tag)
842 #define ALL_TARGETS -2
843 #define NO_TARGET -1
844 #define ALL_LUNS -2
845 #define NO_LUN -1
847 static int device_queue_depth(struct sym_hcb *np, int target, int lun)
849 int c, h, t, u, v;
850 char *p = sym_driver_setup.tag_ctrl;
851 char *ep;
853 h = -1;
854 t = NO_TARGET;
855 u = NO_LUN;
856 while ((c = *p++) != 0) {
857 v = simple_strtoul(p, &ep, 0);
858 switch(c) {
859 case '/':
860 ++h;
861 t = ALL_TARGETS;
862 u = ALL_LUNS;
863 break;
864 case 't':
865 if (t != target)
866 t = (target == v) ? v : NO_TARGET;
867 u = ALL_LUNS;
868 break;
869 case 'u':
870 if (u != lun)
871 u = (lun == v) ? v : NO_LUN;
872 break;
873 case 'q':
874 if (h == np->s.unit &&
875 (t == ALL_TARGETS || t == target) &&
876 (u == ALL_LUNS || u == lun))
877 return v;
878 break;
879 case '-':
880 t = ALL_TARGETS;
881 u = ALL_LUNS;
882 break;
883 default:
884 break;
886 p = ep;
888 return DEF_DEPTH;
891 static int sym53c8xx_slave_alloc(struct scsi_device *sdev)
893 struct sym_hcb *np = sym_get_hcb(sdev->host);
894 struct sym_tcb *tp = &np->target[sdev->id];
895 struct sym_lcb *lp;
897 if (sdev->id >= SYM_CONF_MAX_TARGET || sdev->lun >= SYM_CONF_MAX_LUN)
898 return -ENXIO;
900 tp->starget = sdev->sdev_target;
902 * Fail the device init if the device is flagged NOSCAN at BOOT in
903 * the NVRAM. This may speed up boot and maintain coherency with
904 * BIOS device numbering. Clearing the flag allows the user to
905 * rescan skipped devices later. We also return an error for
906 * devices not flagged for SCAN LUNS in the NVRAM since some single
907 * lun devices behave badly when asked for a non zero LUN.
910 if (tp->usrflags & SYM_SCAN_BOOT_DISABLED) {
911 tp->usrflags &= ~SYM_SCAN_BOOT_DISABLED;
912 starget_printk(KERN_INFO, tp->starget,
913 "Scan at boot disabled in NVRAM\n");
914 return -ENXIO;
917 if (tp->usrflags & SYM_SCAN_LUNS_DISABLED) {
918 if (sdev->lun != 0)
919 return -ENXIO;
920 starget_printk(KERN_INFO, tp->starget,
921 "Multiple LUNs disabled in NVRAM\n");
924 lp = sym_alloc_lcb(np, sdev->id, sdev->lun);
925 if (!lp)
926 return -ENOMEM;
928 spi_min_period(tp->starget) = tp->usr_period;
929 spi_max_width(tp->starget) = tp->usr_width;
931 return 0;
935 * Linux entry point for device queue sizing.
937 static int sym53c8xx_slave_configure(struct scsi_device *sdev)
939 struct sym_hcb *np = sym_get_hcb(sdev->host);
940 struct sym_tcb *tp = &np->target[sdev->id];
941 struct sym_lcb *lp = sym_lp(tp, sdev->lun);
942 int reqtags, depth_to_use;
945 * Get user flags.
947 lp->curr_flags = lp->user_flags;
950 * Select queue depth from driver setup.
951 * Donnot use more than configured by user.
952 * Use at least 2.
953 * Donnot use more than our maximum.
955 reqtags = device_queue_depth(np, sdev->id, sdev->lun);
956 if (reqtags > tp->usrtags)
957 reqtags = tp->usrtags;
958 if (!sdev->tagged_supported)
959 reqtags = 0;
960 #if 1 /* Avoid to locally queue commands for no good reasons */
961 if (reqtags > SYM_CONF_MAX_TAG)
962 reqtags = SYM_CONF_MAX_TAG;
963 depth_to_use = (reqtags ? reqtags : 2);
964 #else
965 depth_to_use = (reqtags ? SYM_CONF_MAX_TAG : 2);
966 #endif
967 scsi_adjust_queue_depth(sdev,
968 (sdev->tagged_supported ?
969 MSG_SIMPLE_TAG : 0),
970 depth_to_use);
971 lp->s.scdev_depth = depth_to_use;
972 sym_tune_dev_queuing(tp, sdev->lun, reqtags);
974 if (!spi_initial_dv(sdev->sdev_target))
975 spi_dv_device(sdev);
977 return 0;
980 static void sym53c8xx_slave_destroy(struct scsi_device *sdev)
982 struct sym_hcb *np = sym_get_hcb(sdev->host);
983 struct sym_lcb *lp = sym_lp(&np->target[sdev->id], sdev->lun);
985 if (lp->itlq_tbl)
986 sym_mfree_dma(lp->itlq_tbl, SYM_CONF_MAX_TASK * 4, "ITLQ_TBL");
987 kfree(lp->cb_tags);
988 sym_mfree_dma(lp, sizeof(*lp), "LCB");
992 * Linux entry point for info() function
994 static const char *sym53c8xx_info (struct Scsi_Host *host)
996 return SYM_DRIVER_NAME;
1000 #ifdef SYM_LINUX_PROC_INFO_SUPPORT
1002 * Proc file system stuff
1004 * A read operation returns adapter information.
1005 * A write operation is a control command.
1006 * The string is parsed in the driver code and the command is passed
1007 * to the sym_usercmd() function.
1010 #ifdef SYM_LINUX_USER_COMMAND_SUPPORT
1012 struct sym_usrcmd {
1013 u_long target;
1014 u_long lun;
1015 u_long data;
1016 u_long cmd;
1019 #define UC_SETSYNC 10
1020 #define UC_SETTAGS 11
1021 #define UC_SETDEBUG 12
1022 #define UC_SETWIDE 14
1023 #define UC_SETFLAG 15
1024 #define UC_SETVERBOSE 17
1025 #define UC_RESETDEV 18
1026 #define UC_CLEARDEV 19
1028 static void sym_exec_user_command (struct sym_hcb *np, struct sym_usrcmd *uc)
1030 struct sym_tcb *tp;
1031 int t, l;
1033 switch (uc->cmd) {
1034 case 0: return;
1036 #ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
1037 case UC_SETDEBUG:
1038 sym_debug_flags = uc->data;
1039 break;
1040 #endif
1041 case UC_SETVERBOSE:
1042 np->verbose = uc->data;
1043 break;
1044 default:
1046 * We assume that other commands apply to targets.
1047 * This should always be the case and avoid the below
1048 * 4 lines to be repeated 6 times.
1050 for (t = 0; t < SYM_CONF_MAX_TARGET; t++) {
1051 if (!((uc->target >> t) & 1))
1052 continue;
1053 tp = &np->target[t];
1055 switch (uc->cmd) {
1057 case UC_SETSYNC:
1058 if (!uc->data || uc->data >= 255) {
1059 tp->tgoal.iu = tp->tgoal.dt =
1060 tp->tgoal.qas = 0;
1061 tp->tgoal.offset = 0;
1062 } else if (uc->data <= 9 && np->minsync_dt) {
1063 if (uc->data < np->minsync_dt)
1064 uc->data = np->minsync_dt;
1065 tp->tgoal.iu = tp->tgoal.dt =
1066 tp->tgoal.qas = 1;
1067 tp->tgoal.width = 1;
1068 tp->tgoal.period = uc->data;
1069 tp->tgoal.offset = np->maxoffs_dt;
1070 } else {
1071 if (uc->data < np->minsync)
1072 uc->data = np->minsync;
1073 tp->tgoal.iu = tp->tgoal.dt =
1074 tp->tgoal.qas = 0;
1075 tp->tgoal.period = uc->data;
1076 tp->tgoal.offset = np->maxoffs;
1078 tp->tgoal.check_nego = 1;
1079 break;
1080 case UC_SETWIDE:
1081 tp->tgoal.width = uc->data ? 1 : 0;
1082 tp->tgoal.check_nego = 1;
1083 break;
1084 case UC_SETTAGS:
1085 for (l = 0; l < SYM_CONF_MAX_LUN; l++)
1086 sym_tune_dev_queuing(tp, l, uc->data);
1087 break;
1088 case UC_RESETDEV:
1089 tp->to_reset = 1;
1090 np->istat_sem = SEM;
1091 OUTB(np, nc_istat, SIGP|SEM);
1092 break;
1093 case UC_CLEARDEV:
1094 for (l = 0; l < SYM_CONF_MAX_LUN; l++) {
1095 struct sym_lcb *lp = sym_lp(tp, l);
1096 if (lp) lp->to_clear = 1;
1098 np->istat_sem = SEM;
1099 OUTB(np, nc_istat, SIGP|SEM);
1100 break;
1101 case UC_SETFLAG:
1102 tp->usrflags = uc->data;
1103 break;
1106 break;
1110 static int skip_spaces(char *ptr, int len)
1112 int cnt, c;
1114 for (cnt = len; cnt > 0 && (c = *ptr++) && isspace(c); cnt--);
1116 return (len - cnt);
1119 static int get_int_arg(char *ptr, int len, u_long *pv)
1121 char *end;
1123 *pv = simple_strtoul(ptr, &end, 10);
1124 return (end - ptr);
1127 static int is_keyword(char *ptr, int len, char *verb)
1129 int verb_len = strlen(verb);
1131 if (len >= verb_len && !memcmp(verb, ptr, verb_len))
1132 return verb_len;
1133 else
1134 return 0;
1137 #define SKIP_SPACES(ptr, len) \
1138 if ((arg_len = skip_spaces(ptr, len)) < 1) \
1139 return -EINVAL; \
1140 ptr += arg_len; len -= arg_len;
1142 #define GET_INT_ARG(ptr, len, v) \
1143 if (!(arg_len = get_int_arg(ptr, len, &(v)))) \
1144 return -EINVAL; \
1145 ptr += arg_len; len -= arg_len;
1149 * Parse a control command
1152 static int sym_user_command(struct sym_hcb *np, char *buffer, int length)
1154 char *ptr = buffer;
1155 int len = length;
1156 struct sym_usrcmd cmd, *uc = &cmd;
1157 int arg_len;
1158 u_long target;
1160 memset(uc, 0, sizeof(*uc));
1162 if (len > 0 && ptr[len-1] == '\n')
1163 --len;
1165 if ((arg_len = is_keyword(ptr, len, "setsync")) != 0)
1166 uc->cmd = UC_SETSYNC;
1167 else if ((arg_len = is_keyword(ptr, len, "settags")) != 0)
1168 uc->cmd = UC_SETTAGS;
1169 else if ((arg_len = is_keyword(ptr, len, "setverbose")) != 0)
1170 uc->cmd = UC_SETVERBOSE;
1171 else if ((arg_len = is_keyword(ptr, len, "setwide")) != 0)
1172 uc->cmd = UC_SETWIDE;
1173 #ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
1174 else if ((arg_len = is_keyword(ptr, len, "setdebug")) != 0)
1175 uc->cmd = UC_SETDEBUG;
1176 #endif
1177 else if ((arg_len = is_keyword(ptr, len, "setflag")) != 0)
1178 uc->cmd = UC_SETFLAG;
1179 else if ((arg_len = is_keyword(ptr, len, "resetdev")) != 0)
1180 uc->cmd = UC_RESETDEV;
1181 else if ((arg_len = is_keyword(ptr, len, "cleardev")) != 0)
1182 uc->cmd = UC_CLEARDEV;
1183 else
1184 arg_len = 0;
1186 #ifdef DEBUG_PROC_INFO
1187 printk("sym_user_command: arg_len=%d, cmd=%ld\n", arg_len, uc->cmd);
1188 #endif
1190 if (!arg_len)
1191 return -EINVAL;
1192 ptr += arg_len; len -= arg_len;
1194 switch(uc->cmd) {
1195 case UC_SETSYNC:
1196 case UC_SETTAGS:
1197 case UC_SETWIDE:
1198 case UC_SETFLAG:
1199 case UC_RESETDEV:
1200 case UC_CLEARDEV:
1201 SKIP_SPACES(ptr, len);
1202 if ((arg_len = is_keyword(ptr, len, "all")) != 0) {
1203 ptr += arg_len; len -= arg_len;
1204 uc->target = ~0;
1205 } else {
1206 GET_INT_ARG(ptr, len, target);
1207 uc->target = (1<<target);
1208 #ifdef DEBUG_PROC_INFO
1209 printk("sym_user_command: target=%ld\n", target);
1210 #endif
1212 break;
1215 switch(uc->cmd) {
1216 case UC_SETVERBOSE:
1217 case UC_SETSYNC:
1218 case UC_SETTAGS:
1219 case UC_SETWIDE:
1220 SKIP_SPACES(ptr, len);
1221 GET_INT_ARG(ptr, len, uc->data);
1222 #ifdef DEBUG_PROC_INFO
1223 printk("sym_user_command: data=%ld\n", uc->data);
1224 #endif
1225 break;
1226 #ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
1227 case UC_SETDEBUG:
1228 while (len > 0) {
1229 SKIP_SPACES(ptr, len);
1230 if ((arg_len = is_keyword(ptr, len, "alloc")))
1231 uc->data |= DEBUG_ALLOC;
1232 else if ((arg_len = is_keyword(ptr, len, "phase")))
1233 uc->data |= DEBUG_PHASE;
1234 else if ((arg_len = is_keyword(ptr, len, "queue")))
1235 uc->data |= DEBUG_QUEUE;
1236 else if ((arg_len = is_keyword(ptr, len, "result")))
1237 uc->data |= DEBUG_RESULT;
1238 else if ((arg_len = is_keyword(ptr, len, "scatter")))
1239 uc->data |= DEBUG_SCATTER;
1240 else if ((arg_len = is_keyword(ptr, len, "script")))
1241 uc->data |= DEBUG_SCRIPT;
1242 else if ((arg_len = is_keyword(ptr, len, "tiny")))
1243 uc->data |= DEBUG_TINY;
1244 else if ((arg_len = is_keyword(ptr, len, "timing")))
1245 uc->data |= DEBUG_TIMING;
1246 else if ((arg_len = is_keyword(ptr, len, "nego")))
1247 uc->data |= DEBUG_NEGO;
1248 else if ((arg_len = is_keyword(ptr, len, "tags")))
1249 uc->data |= DEBUG_TAGS;
1250 else if ((arg_len = is_keyword(ptr, len, "pointer")))
1251 uc->data |= DEBUG_POINTER;
1252 else
1253 return -EINVAL;
1254 ptr += arg_len; len -= arg_len;
1256 #ifdef DEBUG_PROC_INFO
1257 printk("sym_user_command: data=%ld\n", uc->data);
1258 #endif
1259 break;
1260 #endif /* SYM_LINUX_DEBUG_CONTROL_SUPPORT */
1261 case UC_SETFLAG:
1262 while (len > 0) {
1263 SKIP_SPACES(ptr, len);
1264 if ((arg_len = is_keyword(ptr, len, "no_disc")))
1265 uc->data &= ~SYM_DISC_ENABLED;
1266 else
1267 return -EINVAL;
1268 ptr += arg_len; len -= arg_len;
1270 break;
1271 default:
1272 break;
1275 if (len)
1276 return -EINVAL;
1277 else {
1278 unsigned long flags;
1280 spin_lock_irqsave(np->s.host->host_lock, flags);
1281 sym_exec_user_command (np, uc);
1282 spin_unlock_irqrestore(np->s.host->host_lock, flags);
1284 return length;
1287 #endif /* SYM_LINUX_USER_COMMAND_SUPPORT */
1290 #ifdef SYM_LINUX_USER_INFO_SUPPORT
1292 * Informations through the proc file system.
1294 struct info_str {
1295 char *buffer;
1296 int length;
1297 int offset;
1298 int pos;
1301 static void copy_mem_info(struct info_str *info, char *data, int len)
1303 if (info->pos + len > info->length)
1304 len = info->length - info->pos;
1306 if (info->pos + len < info->offset) {
1307 info->pos += len;
1308 return;
1310 if (info->pos < info->offset) {
1311 data += (info->offset - info->pos);
1312 len -= (info->offset - info->pos);
1315 if (len > 0) {
1316 memcpy(info->buffer + info->pos, data, len);
1317 info->pos += len;
1321 static int copy_info(struct info_str *info, char *fmt, ...)
1323 va_list args;
1324 char buf[81];
1325 int len;
1327 va_start(args, fmt);
1328 len = vsprintf(buf, fmt, args);
1329 va_end(args);
1331 copy_mem_info(info, buf, len);
1332 return len;
1336 * Copy formatted information into the input buffer.
1338 static int sym_host_info(struct sym_hcb *np, char *ptr, off_t offset, int len)
1340 struct info_str info;
1342 info.buffer = ptr;
1343 info.length = len;
1344 info.offset = offset;
1345 info.pos = 0;
1347 copy_info(&info, "Chip " NAME53C "%s, device id 0x%x, "
1348 "revision id 0x%x\n",
1349 np->s.chip_name, np->device_id, np->revision_id);
1350 copy_info(&info, "At PCI address %s, IRQ " IRQ_FMT "\n",
1351 pci_name(np->s.device), IRQ_PRM(np->s.irq));
1352 copy_info(&info, "Min. period factor %d, %s SCSI BUS%s\n",
1353 (int) (np->minsync_dt ? np->minsync_dt : np->minsync),
1354 np->maxwide ? "Wide" : "Narrow",
1355 np->minsync_dt ? ", DT capable" : "");
1357 copy_info(&info, "Max. started commands %d, "
1358 "max. commands per LUN %d\n",
1359 SYM_CONF_MAX_START, SYM_CONF_MAX_TAG);
1361 return info.pos > info.offset? info.pos - info.offset : 0;
1363 #endif /* SYM_LINUX_USER_INFO_SUPPORT */
1366 * Entry point of the scsi proc fs of the driver.
1367 * - func = 0 means read (returns adapter infos)
1368 * - func = 1 means write (not yet merget from sym53c8xx)
1370 static int sym53c8xx_proc_info(struct Scsi_Host *host, char *buffer,
1371 char **start, off_t offset, int length, int func)
1373 struct sym_hcb *np = sym_get_hcb(host);
1374 int retv;
1376 if (func) {
1377 #ifdef SYM_LINUX_USER_COMMAND_SUPPORT
1378 retv = sym_user_command(np, buffer, length);
1379 #else
1380 retv = -EINVAL;
1381 #endif
1382 } else {
1383 if (start)
1384 *start = buffer;
1385 #ifdef SYM_LINUX_USER_INFO_SUPPORT
1386 retv = sym_host_info(np, buffer, offset, length);
1387 #else
1388 retv = -EINVAL;
1389 #endif
1392 return retv;
1394 #endif /* SYM_LINUX_PROC_INFO_SUPPORT */
1397 * Free controller resources.
1399 static void sym_free_resources(struct sym_hcb *np, struct pci_dev *pdev)
1402 * Free O/S specific resources.
1404 if (np->s.irq)
1405 free_irq(np->s.irq, np);
1406 if (np->s.ioaddr)
1407 pci_iounmap(pdev, np->s.ioaddr);
1408 if (np->s.ramaddr)
1409 pci_iounmap(pdev, np->s.ramaddr);
1411 * Free O/S independent resources.
1413 sym_hcb_free(np);
1415 sym_mfree_dma(np, sizeof(*np), "HCB");
1419 * Ask/tell the system about DMA addressing.
1421 static int sym_setup_bus_dma_mask(struct sym_hcb *np)
1423 #if SYM_CONF_DMA_ADDRESSING_MODE > 0
1424 #if SYM_CONF_DMA_ADDRESSING_MODE == 1
1425 #define DMA_DAC_MASK DMA_40BIT_MASK
1426 #elif SYM_CONF_DMA_ADDRESSING_MODE == 2
1427 #define DMA_DAC_MASK DMA_64BIT_MASK
1428 #endif
1429 if ((np->features & FE_DAC) &&
1430 !pci_set_dma_mask(np->s.device, DMA_DAC_MASK)) {
1431 np->use_dac = 1;
1432 return 0;
1434 #endif
1436 if (!pci_set_dma_mask(np->s.device, DMA_32BIT_MASK))
1437 return 0;
1439 printf_warning("%s: No suitable DMA available\n", sym_name(np));
1440 return -1;
1444 * Host attach and initialisations.
1446 * Allocate host data and ncb structure.
1447 * Remap MMIO region.
1448 * Do chip initialization.
1449 * If all is OK, install interrupt handling and
1450 * start the timer daemon.
1452 static struct Scsi_Host * __devinit sym_attach(struct scsi_host_template *tpnt,
1453 int unit, struct sym_device *dev)
1455 struct host_data *host_data;
1456 struct sym_hcb *np = NULL;
1457 struct Scsi_Host *instance = NULL;
1458 struct pci_dev *pdev = dev->pdev;
1459 unsigned long flags;
1460 struct sym_fw *fw;
1462 printk(KERN_INFO
1463 "sym%d: <%s> rev 0x%x at pci %s irq " IRQ_FMT "\n",
1464 unit, dev->chip.name, dev->chip.revision_id,
1465 pci_name(pdev), IRQ_PRM(pdev->irq));
1468 * Get the firmware for this chip.
1470 fw = sym_find_firmware(&dev->chip);
1471 if (!fw)
1472 goto attach_failed;
1475 * Allocate host_data structure
1477 instance = scsi_host_alloc(tpnt, sizeof(*host_data));
1478 if (!instance)
1479 goto attach_failed;
1480 host_data = (struct host_data *) instance->hostdata;
1483 * Allocate immediately the host control block,
1484 * since we are only expecting to succeed. :)
1485 * We keep track in the HCB of all the resources that
1486 * are to be released on error.
1488 np = __sym_calloc_dma(&pdev->dev, sizeof(*np), "HCB");
1489 if (!np)
1490 goto attach_failed;
1491 np->s.device = pdev;
1492 np->bus_dmat = &pdev->dev; /* Result in 1 DMA pool per HBA */
1493 host_data->ncb = np;
1494 np->s.host = instance;
1496 pci_set_drvdata(pdev, np);
1499 * Copy some useful infos to the HCB.
1501 np->hcb_ba = vtobus(np);
1502 np->verbose = sym_driver_setup.verbose;
1503 np->s.device = pdev;
1504 np->s.unit = unit;
1505 np->device_id = dev->chip.device_id;
1506 np->revision_id = dev->chip.revision_id;
1507 np->features = dev->chip.features;
1508 np->clock_divn = dev->chip.nr_divisor;
1509 np->maxoffs = dev->chip.offset_max;
1510 np->maxburst = dev->chip.burst_max;
1511 np->myaddr = dev->host_id;
1514 * Edit its name.
1516 strlcpy(np->s.chip_name, dev->chip.name, sizeof(np->s.chip_name));
1517 sprintf(np->s.inst_name, "sym%d", np->s.unit);
1519 if (sym_setup_bus_dma_mask(np))
1520 goto attach_failed;
1523 * Try to map the controller chip to
1524 * virtual and physical memory.
1526 np->mmio_ba = (u32)dev->mmio_base;
1527 np->s.ioaddr = dev->s.ioaddr;
1528 np->s.ramaddr = dev->s.ramaddr;
1529 np->s.io_ws = (np->features & FE_IO256) ? 256 : 128;
1532 * Map on-chip RAM if present and supported.
1534 if (!(np->features & FE_RAM))
1535 dev->ram_base = 0;
1536 if (dev->ram_base) {
1537 np->ram_ba = (u32)dev->ram_base;
1538 np->ram_ws = (np->features & FE_RAM8K) ? 8192 : 4096;
1541 if (sym_hcb_attach(instance, fw, dev->nvram))
1542 goto attach_failed;
1545 * Install the interrupt handler.
1546 * If we synchonize the C code with SCRIPTS on interrupt,
1547 * we do not want to share the INTR line at all.
1549 if (request_irq(pdev->irq, sym53c8xx_intr, IRQF_SHARED, NAME53C8XX, np)) {
1550 printf_err("%s: request irq %d failure\n",
1551 sym_name(np), pdev->irq);
1552 goto attach_failed;
1554 np->s.irq = pdev->irq;
1557 * After SCSI devices have been opened, we cannot
1558 * reset the bus safely, so we do it here.
1560 spin_lock_irqsave(instance->host_lock, flags);
1561 if (sym_reset_scsi_bus(np, 0))
1562 goto reset_failed;
1565 * Start the SCRIPTS.
1567 sym_start_up (np, 1);
1570 * Start the timer daemon
1572 init_timer(&np->s.timer);
1573 np->s.timer.data = (unsigned long) np;
1574 np->s.timer.function = sym53c8xx_timer;
1575 np->s.lasttime=0;
1576 sym_timer (np);
1579 * Fill Linux host instance structure
1580 * and return success.
1582 instance->max_channel = 0;
1583 instance->this_id = np->myaddr;
1584 instance->max_id = np->maxwide ? 16 : 8;
1585 instance->max_lun = SYM_CONF_MAX_LUN;
1586 instance->unique_id = pci_resource_start(pdev, 0);
1587 instance->cmd_per_lun = SYM_CONF_MAX_TAG;
1588 instance->can_queue = (SYM_CONF_MAX_START-2);
1589 instance->sg_tablesize = SYM_CONF_MAX_SG;
1590 instance->max_cmd_len = 16;
1591 BUG_ON(sym2_transport_template == NULL);
1592 instance->transportt = sym2_transport_template;
1594 spin_unlock_irqrestore(instance->host_lock, flags);
1596 return instance;
1598 reset_failed:
1599 printf_err("%s: FATAL ERROR: CHECK SCSI BUS - CABLES, "
1600 "TERMINATION, DEVICE POWER etc.!\n", sym_name(np));
1601 spin_unlock_irqrestore(instance->host_lock, flags);
1602 attach_failed:
1603 if (!instance)
1604 return NULL;
1605 printf_info("%s: giving up ...\n", sym_name(np));
1606 if (np)
1607 sym_free_resources(np, pdev);
1608 scsi_host_put(instance);
1610 return NULL;
1615 * Detect and try to read SYMBIOS and TEKRAM NVRAM.
1617 #if SYM_CONF_NVRAM_SUPPORT
1618 static void __devinit sym_get_nvram(struct sym_device *devp, struct sym_nvram *nvp)
1620 devp->nvram = nvp;
1621 devp->device_id = devp->chip.device_id;
1622 nvp->type = 0;
1624 sym_read_nvram(devp, nvp);
1626 #else
1627 static inline void sym_get_nvram(struct sym_device *devp, struct sym_nvram *nvp)
1630 #endif /* SYM_CONF_NVRAM_SUPPORT */
1632 static int __devinit sym_check_supported(struct sym_device *device)
1634 struct sym_chip *chip;
1635 struct pci_dev *pdev = device->pdev;
1636 u_char revision;
1637 unsigned long io_port = pci_resource_start(pdev, 0);
1638 int i;
1641 * If user excluded this chip, do not initialize it.
1642 * I hate this code so much. Must kill it.
1644 if (io_port) {
1645 for (i = 0 ; i < 8 ; i++) {
1646 if (sym_driver_setup.excludes[i] == io_port)
1647 return -ENODEV;
1652 * Check if the chip is supported. Then copy the chip description
1653 * to our device structure so we can make it match the actual device
1654 * and options.
1656 pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
1657 chip = sym_lookup_chip_table(pdev->device, revision);
1658 if (!chip) {
1659 dev_info(&pdev->dev, "device not supported\n");
1660 return -ENODEV;
1662 memcpy(&device->chip, chip, sizeof(device->chip));
1663 device->chip.revision_id = revision;
1665 return 0;
1669 * Ignore Symbios chips controlled by various RAID controllers.
1670 * These controllers set value 0x52414944 at RAM end - 16.
1672 static int __devinit sym_check_raid(struct sym_device *device)
1674 unsigned int ram_size, ram_val;
1676 if (!device->s.ramaddr)
1677 return 0;
1679 if (device->chip.features & FE_RAM8K)
1680 ram_size = 8192;
1681 else
1682 ram_size = 4096;
1684 ram_val = readl(device->s.ramaddr + ram_size - 16);
1685 if (ram_val != 0x52414944)
1686 return 0;
1688 dev_info(&device->pdev->dev,
1689 "not initializing, driven by RAID controller.\n");
1690 return -ENODEV;
1693 static int __devinit sym_set_workarounds(struct sym_device *device)
1695 struct sym_chip *chip = &device->chip;
1696 struct pci_dev *pdev = device->pdev;
1697 u_short status_reg;
1700 * (ITEM 12 of a DEL about the 896 I haven't yet).
1701 * We must ensure the chip will use WRITE AND INVALIDATE.
1702 * The revision number limit is for now arbitrary.
1704 if (pdev->device == PCI_DEVICE_ID_NCR_53C896 && chip->revision_id < 0x4) {
1705 chip->features |= (FE_WRIE | FE_CLSE);
1708 /* If the chip can do Memory Write Invalidate, enable it */
1709 if (chip->features & FE_WRIE) {
1710 if (pci_set_mwi(pdev))
1711 return -ENODEV;
1715 * Work around for errant bit in 895A. The 66Mhz
1716 * capable bit is set erroneously. Clear this bit.
1717 * (Item 1 DEL 533)
1719 * Make sure Config space and Features agree.
1721 * Recall: writes are not normal to status register -
1722 * write a 1 to clear and a 0 to leave unchanged.
1723 * Can only reset bits.
1725 pci_read_config_word(pdev, PCI_STATUS, &status_reg);
1726 if (chip->features & FE_66MHZ) {
1727 if (!(status_reg & PCI_STATUS_66MHZ))
1728 chip->features &= ~FE_66MHZ;
1729 } else {
1730 if (status_reg & PCI_STATUS_66MHZ) {
1731 status_reg = PCI_STATUS_66MHZ;
1732 pci_write_config_word(pdev, PCI_STATUS, status_reg);
1733 pci_read_config_word(pdev, PCI_STATUS, &status_reg);
1737 return 0;
1741 * Read and check the PCI configuration for any detected NCR
1742 * boards and save data for attaching after all boards have
1743 * been detected.
1745 static void __devinit
1746 sym_init_device(struct pci_dev *pdev, struct sym_device *device)
1748 int i = 2;
1749 struct pci_bus_region bus_addr;
1751 device->host_id = SYM_SETUP_HOST_ID;
1752 device->pdev = pdev;
1754 pcibios_resource_to_bus(pdev, &bus_addr, &pdev->resource[1]);
1755 device->mmio_base = bus_addr.start;
1758 * If the BAR is 64-bit, resource 2 will be occupied by the
1759 * upper 32 bits
1761 if (!pdev->resource[i].flags)
1762 i++;
1763 pcibios_resource_to_bus(pdev, &bus_addr, &pdev->resource[i]);
1764 device->ram_base = bus_addr.start;
1766 #ifdef CONFIG_SCSI_SYM53C8XX_MMIO
1767 if (device->mmio_base)
1768 device->s.ioaddr = pci_iomap(pdev, 1,
1769 pci_resource_len(pdev, 1));
1770 #endif
1771 if (!device->s.ioaddr)
1772 device->s.ioaddr = pci_iomap(pdev, 0,
1773 pci_resource_len(pdev, 0));
1774 if (device->ram_base)
1775 device->s.ramaddr = pci_iomap(pdev, i,
1776 pci_resource_len(pdev, i));
1780 * The NCR PQS and PDS cards are constructed as a DEC bridge
1781 * behind which sits a proprietary NCR memory controller and
1782 * either four or two 53c875s as separate devices. We can tell
1783 * if an 875 is part of a PQS/PDS or not since if it is, it will
1784 * be on the same bus as the memory controller. In its usual
1785 * mode of operation, the 875s are slaved to the memory
1786 * controller for all transfers. To operate with the Linux
1787 * driver, the memory controller is disabled and the 875s
1788 * freed to function independently. The only wrinkle is that
1789 * the preset SCSI ID (which may be zero) must be read in from
1790 * a special configuration space register of the 875.
1792 static void sym_config_pqs(struct pci_dev *pdev, struct sym_device *sym_dev)
1794 int slot;
1795 u8 tmp;
1797 for (slot = 0; slot < 256; slot++) {
1798 struct pci_dev *memc = pci_get_slot(pdev->bus, slot);
1800 if (!memc || memc->vendor != 0x101a || memc->device == 0x0009) {
1801 pci_dev_put(memc);
1802 continue;
1805 /* bit 1: allow individual 875 configuration */
1806 pci_read_config_byte(memc, 0x44, &tmp);
1807 if ((tmp & 0x2) == 0) {
1808 tmp |= 0x2;
1809 pci_write_config_byte(memc, 0x44, tmp);
1812 /* bit 2: drive individual 875 interrupts to the bus */
1813 pci_read_config_byte(memc, 0x45, &tmp);
1814 if ((tmp & 0x4) == 0) {
1815 tmp |= 0x4;
1816 pci_write_config_byte(memc, 0x45, tmp);
1819 pci_dev_put(memc);
1820 break;
1823 pci_read_config_byte(pdev, 0x84, &tmp);
1824 sym_dev->host_id = tmp;
1828 * Called before unloading the module.
1829 * Detach the host.
1830 * We have to free resources and halt the NCR chip.
1832 static int sym_detach(struct sym_hcb *np, struct pci_dev *pdev)
1834 printk("%s: detaching ...\n", sym_name(np));
1836 del_timer_sync(&np->s.timer);
1839 * Reset NCR chip.
1840 * We should use sym_soft_reset(), but we don't want to do
1841 * so, since we may not be safe if interrupts occur.
1843 printk("%s: resetting chip\n", sym_name(np));
1844 OUTB(np, nc_istat, SRST);
1845 INB(np, nc_mbox1);
1846 udelay(10);
1847 OUTB(np, nc_istat, 0);
1849 sym_free_resources(np, pdev);
1851 return 1;
1855 * Driver host template.
1857 static struct scsi_host_template sym2_template = {
1858 .module = THIS_MODULE,
1859 .name = "sym53c8xx",
1860 .info = sym53c8xx_info,
1861 .queuecommand = sym53c8xx_queue_command,
1862 .slave_alloc = sym53c8xx_slave_alloc,
1863 .slave_configure = sym53c8xx_slave_configure,
1864 .slave_destroy = sym53c8xx_slave_destroy,
1865 .eh_abort_handler = sym53c8xx_eh_abort_handler,
1866 .eh_device_reset_handler = sym53c8xx_eh_device_reset_handler,
1867 .eh_bus_reset_handler = sym53c8xx_eh_bus_reset_handler,
1868 .eh_host_reset_handler = sym53c8xx_eh_host_reset_handler,
1869 .this_id = 7,
1870 .use_clustering = ENABLE_CLUSTERING,
1871 .max_sectors = 0xFFFF,
1872 #ifdef SYM_LINUX_PROC_INFO_SUPPORT
1873 .proc_info = sym53c8xx_proc_info,
1874 .proc_name = NAME53C8XX,
1875 #endif
1878 static int attach_count;
1880 static int __devinit sym2_probe(struct pci_dev *pdev,
1881 const struct pci_device_id *ent)
1883 struct sym_device sym_dev;
1884 struct sym_nvram nvram;
1885 struct Scsi_Host *instance;
1887 memset(&sym_dev, 0, sizeof(sym_dev));
1888 memset(&nvram, 0, sizeof(nvram));
1890 if (pci_enable_device(pdev))
1891 goto leave;
1893 pci_set_master(pdev);
1895 if (pci_request_regions(pdev, NAME53C8XX))
1896 goto disable;
1898 sym_init_device(pdev, &sym_dev);
1899 if (sym_check_supported(&sym_dev))
1900 goto free;
1902 if (sym_check_raid(&sym_dev))
1903 goto leave; /* Don't disable the device */
1905 if (sym_set_workarounds(&sym_dev))
1906 goto free;
1908 sym_config_pqs(pdev, &sym_dev);
1910 sym_get_nvram(&sym_dev, &nvram);
1912 instance = sym_attach(&sym2_template, attach_count, &sym_dev);
1913 if (!instance)
1914 goto free;
1916 if (scsi_add_host(instance, &pdev->dev))
1917 goto detach;
1918 scsi_scan_host(instance);
1920 attach_count++;
1922 return 0;
1924 detach:
1925 sym_detach(pci_get_drvdata(pdev), pdev);
1926 free:
1927 pci_release_regions(pdev);
1928 disable:
1929 pci_disable_device(pdev);
1930 leave:
1931 return -ENODEV;
1934 static void __devexit sym2_remove(struct pci_dev *pdev)
1936 struct sym_hcb *np = pci_get_drvdata(pdev);
1937 struct Scsi_Host *host = np->s.host;
1939 scsi_remove_host(host);
1940 scsi_host_put(host);
1942 sym_detach(np, pdev);
1944 pci_release_regions(pdev);
1945 pci_disable_device(pdev);
1947 attach_count--;
1950 static void sym2_get_signalling(struct Scsi_Host *shost)
1952 struct sym_hcb *np = sym_get_hcb(shost);
1953 enum spi_signal_type type;
1955 switch (np->scsi_mode) {
1956 case SMODE_SE:
1957 type = SPI_SIGNAL_SE;
1958 break;
1959 case SMODE_LVD:
1960 type = SPI_SIGNAL_LVD;
1961 break;
1962 case SMODE_HVD:
1963 type = SPI_SIGNAL_HVD;
1964 break;
1965 default:
1966 type = SPI_SIGNAL_UNKNOWN;
1967 break;
1969 spi_signalling(shost) = type;
1972 static void sym2_set_offset(struct scsi_target *starget, int offset)
1974 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1975 struct sym_hcb *np = sym_get_hcb(shost);
1976 struct sym_tcb *tp = &np->target[starget->id];
1978 tp->tgoal.offset = offset;
1979 tp->tgoal.check_nego = 1;
1982 static void sym2_set_period(struct scsi_target *starget, int period)
1984 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1985 struct sym_hcb *np = sym_get_hcb(shost);
1986 struct sym_tcb *tp = &np->target[starget->id];
1988 /* have to have DT for these transfers, but DT will also
1989 * set width, so check that this is allowed */
1990 if (period <= np->minsync && spi_width(starget))
1991 tp->tgoal.dt = 1;
1993 tp->tgoal.period = period;
1994 tp->tgoal.check_nego = 1;
1997 static void sym2_set_width(struct scsi_target *starget, int width)
1999 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
2000 struct sym_hcb *np = sym_get_hcb(shost);
2001 struct sym_tcb *tp = &np->target[starget->id];
2003 /* It is illegal to have DT set on narrow transfers. If DT is
2004 * clear, we must also clear IU and QAS. */
2005 if (width == 0)
2006 tp->tgoal.iu = tp->tgoal.dt = tp->tgoal.qas = 0;
2008 tp->tgoal.width = width;
2009 tp->tgoal.check_nego = 1;
2012 static void sym2_set_dt(struct scsi_target *starget, int dt)
2014 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
2015 struct sym_hcb *np = sym_get_hcb(shost);
2016 struct sym_tcb *tp = &np->target[starget->id];
2018 /* We must clear QAS and IU if DT is clear */
2019 if (dt)
2020 tp->tgoal.dt = 1;
2021 else
2022 tp->tgoal.iu = tp->tgoal.dt = tp->tgoal.qas = 0;
2023 tp->tgoal.check_nego = 1;
2026 #if 0
2027 static void sym2_set_iu(struct scsi_target *starget, int iu)
2029 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
2030 struct sym_hcb *np = sym_get_hcb(shost);
2031 struct sym_tcb *tp = &np->target[starget->id];
2033 if (iu)
2034 tp->tgoal.iu = tp->tgoal.dt = 1;
2035 else
2036 tp->tgoal.iu = 0;
2037 tp->tgoal.check_nego = 1;
2040 static void sym2_set_qas(struct scsi_target *starget, int qas)
2042 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
2043 struct sym_hcb *np = sym_get_hcb(shost);
2044 struct sym_tcb *tp = &np->target[starget->id];
2046 if (qas)
2047 tp->tgoal.dt = tp->tgoal.qas = 1;
2048 else
2049 tp->tgoal.qas = 0;
2050 tp->tgoal.check_nego = 1;
2052 #endif
2054 static struct spi_function_template sym2_transport_functions = {
2055 .set_offset = sym2_set_offset,
2056 .show_offset = 1,
2057 .set_period = sym2_set_period,
2058 .show_period = 1,
2059 .set_width = sym2_set_width,
2060 .show_width = 1,
2061 .set_dt = sym2_set_dt,
2062 .show_dt = 1,
2063 #if 0
2064 .set_iu = sym2_set_iu,
2065 .show_iu = 1,
2066 .set_qas = sym2_set_qas,
2067 .show_qas = 1,
2068 #endif
2069 .get_signalling = sym2_get_signalling,
2072 static struct pci_device_id sym2_id_table[] __devinitdata = {
2073 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C810,
2074 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2075 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C820,
2076 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, /* new */
2077 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C825,
2078 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2079 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C815,
2080 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2081 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C810AP,
2082 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, /* new */
2083 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C860,
2084 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2085 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1510,
2086 PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_SCSI<<8, 0xffff00, 0UL },
2087 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C896,
2088 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2089 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C895,
2090 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2091 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C885,
2092 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2093 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C875,
2094 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2095 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C1510,
2096 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, /* new */
2097 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C895A,
2098 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2099 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C875A,
2100 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2101 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1010_33,
2102 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2103 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1010_66,
2104 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2105 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C875J,
2106 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2107 { 0, }
2110 MODULE_DEVICE_TABLE(pci, sym2_id_table);
2112 static struct pci_driver sym2_driver = {
2113 .name = NAME53C8XX,
2114 .id_table = sym2_id_table,
2115 .probe = sym2_probe,
2116 .remove = __devexit_p(sym2_remove),
2119 static int __init sym2_init(void)
2121 int error;
2123 sym2_setup_params();
2124 sym2_transport_template = spi_attach_transport(&sym2_transport_functions);
2125 if (!sym2_transport_template)
2126 return -ENODEV;
2128 error = pci_register_driver(&sym2_driver);
2129 if (error)
2130 spi_release_transport(sym2_transport_template);
2131 return error;
2134 static void __exit sym2_exit(void)
2136 pci_unregister_driver(&sym2_driver);
2137 spi_release_transport(sym2_transport_template);
2140 module_init(sym2_init);
2141 module_exit(sym2_exit);