]> err.no Git - linux-2.6/blob - drivers/scsi/sym53c8xx_2/sym_glue.c
[SCSI] sym53c8xx: Remove unnecessary check in queuecommand
[linux-2.6] / drivers / scsi / sym53c8xx_2 / sym_glue.c
1 /*
2  * Device driver for the SYMBIOS/LSILOGIC 53C8XX and 53C1010 family 
3  * of PCI-SCSI IO processors.
4  *
5  * Copyright (C) 1999-2001  Gerard Roudier <groudier@free.fr>
6  * Copyright (c) 2003-2005  Matthew Wilcox <matthew@wil.cx>
7  *
8  * This driver is derived from the Linux sym53c8xx driver.
9  * Copyright (C) 1998-2000  Gerard Roudier
10  *
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.
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
18  *
19  * Other major contributions:
20  *
21  * NVRAM detection and reading.
22  * Copyright (C) 1997 Richard Waltham <dormouse@farsrobt.demon.co.uk>
23  *
24  *-----------------------------------------------------------------------------
25  *
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.
30  *
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.
35  *
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
39  */
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>
50
51 #include "sym_glue.h"
52 #include "sym_nvram.h"
53
54 #define NAME53C         "sym53c"
55 #define NAME53C8XX      "sym53c8xx"
56
57 #define IRQ_FMT "%d"
58 #define IRQ_PRM(x) (x)
59
60 struct sym_driver_setup sym_driver_setup = SYM_LINUX_DRIVER_SETUP;
61 unsigned int sym_debug_flags = 0;
62
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);
79
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\"");
94
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");
99
100 static void sym2_setup_params(void)
101 {
102         char *p = excl_string;
103         int xi = 0;
104
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;
110         }
111
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);
127                 }
128         }
129 }
130
131 static struct scsi_transport_template *sym2_transport_template = NULL;
132
133 /*
134  *  Driver private area in the SCSI command structure.
135  */
136 struct sym_ucmd {               /* Override the SCSI pointer structure */
137         unsigned char   to_do;                  /* For error handling */
138         void (*old_done)(struct scsi_cmnd *);   /* For error handling */
139         struct completion *eh_done;             /* For error handling */
140 };
141
142 #define SYM_UCMD_PTR(cmd)  ((struct sym_ucmd *)(&(cmd)->SCp))
143 #define SYM_SOFTC_PTR(cmd) sym_get_hcb(cmd->device->host)
144
145 /*
146  *  Complete a pending CAM CCB.
147  */
148 void sym_xpt_done(struct sym_hcb *np, struct scsi_cmnd *cmd)
149 {
150         scsi_dma_unmap(cmd);
151         cmd->scsi_done(cmd);
152 }
153
154 /*
155  *  Tell the SCSI layer about a BUS RESET.
156  */
157 void sym_xpt_async_bus_reset(struct sym_hcb *np)
158 {
159         printf_notice("%s: SCSI BUS has been reset.\n", sym_name(np));
160         np->s.settle_time = jiffies + sym_driver_setup.settle_delay * HZ;
161         np->s.settle_time_valid = 1;
162         if (sym_verbose >= 2)
163                 printf_info("%s: command processing suspended for %d seconds\n",
164                             sym_name(np), sym_driver_setup.settle_delay);
165 }
166
167 /*
168  *  Tell the SCSI layer about a BUS DEVICE RESET message sent.
169  */
170 void sym_xpt_async_sent_bdr(struct sym_hcb *np, int target)
171 {
172         printf_notice("%s: TARGET %d has been reset.\n", sym_name(np), target);
173 }
174
175 /*
176  *  Choose the more appropriate CAM status if 
177  *  the IO encountered an extended error.
178  */
179 static int sym_xerr_cam_status(int cam_status, int x_status)
180 {
181         if (x_status) {
182                 if      (x_status & XE_PARITY_ERR)
183                         cam_status = DID_PARITY;
184                 else if (x_status &(XE_EXTRA_DATA|XE_SODL_UNRUN|XE_SWIDE_OVRUN))
185                         cam_status = DID_ERROR;
186                 else if (x_status & XE_BAD_PHASE)
187                         cam_status = DID_ERROR;
188                 else
189                         cam_status = DID_ERROR;
190         }
191         return cam_status;
192 }
193
194 /*
195  *  Build CAM result for a failed or auto-sensed IO.
196  */
197 void sym_set_cam_result_error(struct sym_hcb *np, struct sym_ccb *cp, int resid)
198 {
199         struct scsi_cmnd *cmd = cp->cmd;
200         u_int cam_status, scsi_status, drv_status;
201
202         drv_status  = 0;
203         cam_status  = DID_OK;
204         scsi_status = cp->ssss_status;
205
206         if (cp->host_flags & HF_SENSE) {
207                 scsi_status = cp->sv_scsi_status;
208                 resid = cp->sv_resid;
209                 if (sym_verbose && cp->sv_xerr_status)
210                         sym_print_xerr(cmd, cp->sv_xerr_status);
211                 if (cp->host_status == HS_COMPLETE &&
212                     cp->ssss_status == S_GOOD &&
213                     cp->xerr_status == 0) {
214                         cam_status = sym_xerr_cam_status(DID_OK,
215                                                          cp->sv_xerr_status);
216                         drv_status = DRIVER_SENSE;
217                         /*
218                          *  Bounce back the sense data to user.
219                          */
220                         memset(&cmd->sense_buffer, 0, sizeof(cmd->sense_buffer));
221                         memcpy(cmd->sense_buffer, cp->sns_bbuf,
222                               min(sizeof(cmd->sense_buffer),
223                                   (size_t)SYM_SNS_BBUF_LEN));
224 #if 0
225                         /*
226                          *  If the device reports a UNIT ATTENTION condition 
227                          *  due to a RESET condition, we should consider all 
228                          *  disconnect CCBs for this unit as aborted.
229                          */
230                         if (1) {
231                                 u_char *p;
232                                 p  = (u_char *) cmd->sense_data;
233                                 if (p[0]==0x70 && p[2]==0x6 && p[12]==0x29)
234                                         sym_clear_tasks(np, DID_ABORT,
235                                                         cp->target,cp->lun, -1);
236                         }
237 #endif
238                 } else {
239                         /*
240                          * Error return from our internal request sense.  This
241                          * is bad: we must clear the contingent allegiance
242                          * condition otherwise the device will always return
243                          * BUSY.  Use a big stick.
244                          */
245                         sym_reset_scsi_target(np, cmd->device->id);
246                         cam_status = DID_ERROR;
247                 }
248         } else if (cp->host_status == HS_COMPLETE)      /* Bad SCSI status */
249                 cam_status = DID_OK;
250         else if (cp->host_status == HS_SEL_TIMEOUT)     /* Selection timeout */
251                 cam_status = DID_NO_CONNECT;
252         else if (cp->host_status == HS_UNEXPECTED)      /* Unexpected BUS FREE*/
253                 cam_status = DID_ERROR;
254         else {                                          /* Extended error */
255                 if (sym_verbose) {
256                         sym_print_addr(cmd, "COMMAND FAILED (%x %x %x).\n",
257                                 cp->host_status, cp->ssss_status,
258                                 cp->xerr_status);
259                 }
260                 /*
261                  *  Set the most appropriate value for CAM status.
262                  */
263                 cam_status = sym_xerr_cam_status(DID_ERROR, cp->xerr_status);
264         }
265         scsi_set_resid(cmd, resid);
266         cmd->result = (drv_status << 24) + (cam_status << 16) + scsi_status;
267 }
268
269 static int sym_scatter(struct sym_hcb *np, struct sym_ccb *cp, struct scsi_cmnd *cmd)
270 {
271         int segment;
272         int use_sg;
273
274         cp->data_len = 0;
275
276         use_sg = scsi_dma_map(cmd);
277         if (use_sg > 0) {
278                 struct scatterlist *sg;
279                 struct sym_tcb *tp = &np->target[cp->target];
280                 struct sym_tblmove *data;
281
282                 if (use_sg > SYM_CONF_MAX_SG) {
283                         scsi_dma_unmap(cmd);
284                         return -1;
285                 }
286
287                 data = &cp->phys.data[SYM_CONF_MAX_SG - use_sg];
288
289                 scsi_for_each_sg(cmd, sg, use_sg, segment) {
290                         dma_addr_t baddr = sg_dma_address(sg);
291                         unsigned int len = sg_dma_len(sg);
292
293                         if ((len & 1) && (tp->head.wval & EWS)) {
294                                 len++;
295                                 cp->odd_byte_adjustment++;
296                         }
297
298                         sym_build_sge(np, &data[segment], baddr, len);
299                         cp->data_len += len;
300                 }
301         } else {
302                 segment = -2;
303         }
304
305         return segment;
306 }
307
308 /*
309  *  Queue a SCSI command.
310  */
311 static int sym_queue_command(struct sym_hcb *np, struct scsi_cmnd *cmd)
312 {
313         struct scsi_device *sdev = cmd->device;
314         struct sym_tcb *tp;
315         struct sym_lcb *lp;
316         struct sym_ccb *cp;
317         int     order;
318
319         /*
320          *  Retrieve the target descriptor.
321          */
322         tp = &np->target[sdev->id];
323
324         /*
325          *  Select tagged/untagged.
326          */
327         lp = sym_lp(tp, sdev->lun);
328         order = (lp && lp->s.reqtags) ? M_SIMPLE_TAG : 0;
329
330         /*
331          *  Queue the SCSI IO.
332          */
333         cp = sym_get_ccb(np, cmd, order);
334         if (!cp)
335                 return 1;       /* Means resource shortage */
336         sym_queue_scsiio(np, cmd, cp);
337         return 0;
338 }
339
340 /*
341  *  Setup buffers and pointers that address the CDB.
342  */
343 static inline int sym_setup_cdb(struct sym_hcb *np, struct scsi_cmnd *cmd, struct sym_ccb *cp)
344 {
345         memcpy(cp->cdb_buf, cmd->cmnd, cmd->cmd_len);
346
347         cp->phys.cmd.addr = CCB_BA(cp, cdb_buf[0]);
348         cp->phys.cmd.size = cpu_to_scr(cmd->cmd_len);
349
350         return 0;
351 }
352
353 /*
354  *  Setup pointers that address the data and start the I/O.
355  */
356 int sym_setup_data_and_start(struct sym_hcb *np, struct scsi_cmnd *cmd, struct sym_ccb *cp)
357 {
358         u32 lastp, goalp;
359         int dir;
360
361         /*
362          *  Build the CDB.
363          */
364         if (sym_setup_cdb(np, cmd, cp))
365                 goto out_abort;
366
367         /*
368          *  No direction means no data.
369          */
370         dir = cmd->sc_data_direction;
371         if (dir != DMA_NONE) {
372                 cp->segments = sym_scatter(np, cp, cmd);
373                 if (cp->segments < 0) {
374                         sym_set_cam_status(cmd, DID_ERROR);
375                         goto out_abort;
376                 }
377
378                 /*
379                  *  No segments means no data.
380                  */
381                 if (!cp->segments)
382                         dir = DMA_NONE;
383         } else {
384                 cp->data_len = 0;
385                 cp->segments = 0;
386         }
387
388         /*
389          *  Set the data pointer.
390          */
391         switch (dir) {
392         case DMA_BIDIRECTIONAL:
393                 printk("%s: got DMA_BIDIRECTIONAL command", sym_name(np));
394                 sym_set_cam_status(cmd, DID_ERROR);
395                 goto out_abort;
396         case DMA_TO_DEVICE:
397                 goalp = SCRIPTA_BA(np, data_out2) + 8;
398                 lastp = goalp - 8 - (cp->segments * (2*4));
399                 break;
400         case DMA_FROM_DEVICE:
401                 cp->host_flags |= HF_DATA_IN;
402                 goalp = SCRIPTA_BA(np, data_in2) + 8;
403                 lastp = goalp - 8 - (cp->segments * (2*4));
404                 break;
405         case DMA_NONE:
406         default:
407                 lastp = goalp = SCRIPTB_BA(np, no_data);
408                 break;
409         }
410
411         /*
412          *  Set all pointers values needed by SCRIPTS.
413          */
414         cp->phys.head.lastp = cpu_to_scr(lastp);
415         cp->phys.head.savep = cpu_to_scr(lastp);
416         cp->startp          = cp->phys.head.savep;
417         cp->goalp           = cpu_to_scr(goalp);
418
419         /*
420          *  When `#ifed 1', the code below makes the driver 
421          *  panic on the first attempt to write to a SCSI device.
422          *  It is the first test we want to do after a driver 
423          *  change that does not seem obviously safe. :)
424          */
425 #if 0
426         switch (cp->cdb_buf[0]) {
427         case 0x0A: case 0x2A: case 0xAA:
428                 panic("XXXXXXXXXXXXX WRITE NOT YET ALLOWED XXXXXXXXXXXXXX\n");
429                 break;
430         default:
431                 break;
432         }
433 #endif
434
435         /*
436          *      activate this job.
437          */
438         sym_put_start_queue(np, cp);
439         return 0;
440
441 out_abort:
442         sym_free_ccb(np, cp);
443         sym_xpt_done(np, cmd);
444         return 0;
445 }
446
447
448 /*
449  *  timer daemon.
450  *
451  *  Misused to keep the driver running when
452  *  interrupts are not configured correctly.
453  */
454 static void sym_timer(struct sym_hcb *np)
455 {
456         unsigned long thistime = jiffies;
457
458         /*
459          *  Restart the timer.
460          */
461         np->s.timer.expires = thistime + SYM_CONF_TIMER_INTERVAL;
462         add_timer(&np->s.timer);
463
464         /*
465          *  If we are resetting the ncr, wait for settle_time before 
466          *  clearing it. Then command processing will be resumed.
467          */
468         if (np->s.settle_time_valid) {
469                 if (time_before_eq(np->s.settle_time, thistime)) {
470                         if (sym_verbose >= 2 )
471                                 printk("%s: command processing resumed\n",
472                                        sym_name(np));
473                         np->s.settle_time_valid = 0;
474                 }
475                 return;
476         }
477
478         /*
479          *      Nothing to do for now, but that may come.
480          */
481         if (np->s.lasttime + 4*HZ < thistime) {
482                 np->s.lasttime = thistime;
483         }
484
485 #ifdef SYM_CONF_PCIQ_MAY_MISS_COMPLETIONS
486         /*
487          *  Some way-broken PCI bridges may lead to 
488          *  completions being lost when the clearing 
489          *  of the INTFLY flag by the CPU occurs 
490          *  concurrently with the chip raising this flag.
491          *  If this ever happen, lost completions will 
492          * be reaped here.
493          */
494         sym_wakeup_done(np);
495 #endif
496 }
497
498
499 /*
500  *  PCI BUS error handler.
501  */
502 void sym_log_bus_error(struct sym_hcb *np)
503 {
504         u_short pci_sts;
505         pci_read_config_word(np->s.device, PCI_STATUS, &pci_sts);
506         if (pci_sts & 0xf900) {
507                 pci_write_config_word(np->s.device, PCI_STATUS, pci_sts);
508                 printf("%s: PCI STATUS = 0x%04x\n",
509                         sym_name(np), pci_sts & 0xf900);
510         }
511 }
512
513 /*
514  * queuecommand method.  Entered with the host adapter lock held and
515  * interrupts disabled.
516  */
517 static int sym53c8xx_queue_command(struct scsi_cmnd *cmd,
518                                         void (*done)(struct scsi_cmnd *))
519 {
520         struct sym_hcb *np = SYM_SOFTC_PTR(cmd);
521         struct sym_ucmd *ucp = SYM_UCMD_PTR(cmd);
522         int sts = 0;
523
524         cmd->scsi_done = done;
525         memset(ucp, 0, sizeof(*ucp));
526
527         /*
528          *  Shorten our settle_time if needed for 
529          *  this command not to time out.
530          */
531         if (np->s.settle_time_valid && cmd->timeout_per_command) {
532                 unsigned long tlimit = jiffies + cmd->timeout_per_command;
533                 tlimit -= SYM_CONF_TIMER_INTERVAL*2;
534                 if (time_after(np->s.settle_time, tlimit)) {
535                         np->s.settle_time = tlimit;
536                 }
537         }
538
539         if (np->s.settle_time_valid)
540                 return SCSI_MLQUEUE_HOST_BUSY;
541
542         sts = sym_queue_command(np, cmd);
543         if (sts)
544                 return SCSI_MLQUEUE_HOST_BUSY;
545         return 0;
546 }
547
548 /*
549  *  Linux entry point of the interrupt handler.
550  */
551 static irqreturn_t sym53c8xx_intr(int irq, void *dev_id)
552 {
553         unsigned long flags;
554         struct sym_hcb *np = (struct sym_hcb *)dev_id;
555
556         if (DEBUG_FLAGS & DEBUG_TINY) printf_debug ("[");
557
558         spin_lock_irqsave(np->s.host->host_lock, flags);
559         sym_interrupt(np);
560         spin_unlock_irqrestore(np->s.host->host_lock, flags);
561
562         if (DEBUG_FLAGS & DEBUG_TINY) printf_debug ("]\n");
563
564         return IRQ_HANDLED;
565 }
566
567 /*
568  *  Linux entry point of the timer handler
569  */
570 static void sym53c8xx_timer(unsigned long npref)
571 {
572         struct sym_hcb *np = (struct sym_hcb *)npref;
573         unsigned long flags;
574
575         spin_lock_irqsave(np->s.host->host_lock, flags);
576         sym_timer(np);
577         spin_unlock_irqrestore(np->s.host->host_lock, flags);
578 }
579
580
581 /*
582  *  What the eh thread wants us to perform.
583  */
584 #define SYM_EH_ABORT            0
585 #define SYM_EH_DEVICE_RESET     1
586 #define SYM_EH_BUS_RESET        2
587 #define SYM_EH_HOST_RESET       3
588
589 /*
590  *  What we will do regarding the involved SCSI command.
591  */
592 #define SYM_EH_DO_IGNORE        0
593 #define SYM_EH_DO_WAIT          2
594
595 /*
596  *  scsi_done() alias when error recovery is in progress.
597  */
598 static void sym_eh_done(struct scsi_cmnd *cmd)
599 {
600         struct sym_ucmd *ucmd = SYM_UCMD_PTR(cmd);
601         BUILD_BUG_ON(sizeof(struct scsi_pointer) < sizeof(struct sym_ucmd));
602
603         cmd->scsi_done = ucmd->old_done;
604
605         if (ucmd->to_do == SYM_EH_DO_WAIT)
606                 complete(ucmd->eh_done);
607 }
608
609 /*
610  *  Generic method for our eh processing.
611  *  The 'op' argument tells what we have to do.
612  */
613 static int sym_eh_handler(int op, char *opname, struct scsi_cmnd *cmd)
614 {
615         struct sym_hcb *np = SYM_SOFTC_PTR(cmd);
616         struct sym_ucmd *ucmd = SYM_UCMD_PTR(cmd);
617         struct Scsi_Host *host = cmd->device->host;
618         SYM_QUEHEAD *qp;
619         int to_do = SYM_EH_DO_IGNORE;
620         int sts = -1;
621         struct completion eh_done;
622
623         dev_warn(&cmd->device->sdev_gendev, "%s operation started.\n", opname);
624
625         spin_lock_irq(host->host_lock);
626         /* This one is queued in some place -> to wait for completion */
627         FOR_EACH_QUEUED_ELEMENT(&np->busy_ccbq, qp) {
628                 struct sym_ccb *cp = sym_que_entry(qp, struct sym_ccb, link_ccbq);
629                 if (cp->cmd == cmd) {
630                         to_do = SYM_EH_DO_WAIT;
631                         break;
632                 }
633         }
634
635         if (to_do == SYM_EH_DO_WAIT) {
636                 init_completion(&eh_done);
637                 ucmd->old_done = cmd->scsi_done;
638                 ucmd->eh_done = &eh_done;
639                 wmb();
640                 cmd->scsi_done = sym_eh_done;
641         }
642
643         /* Try to proceed the operation we have been asked for */
644         sts = -1;
645         switch(op) {
646         case SYM_EH_ABORT:
647                 sts = sym_abort_scsiio(np, cmd, 1);
648                 break;
649         case SYM_EH_DEVICE_RESET:
650                 sts = sym_reset_scsi_target(np, cmd->device->id);
651                 break;
652         case SYM_EH_BUS_RESET:
653                 sym_reset_scsi_bus(np, 1);
654                 sts = 0;
655                 break;
656         case SYM_EH_HOST_RESET:
657                 sym_reset_scsi_bus(np, 0);
658                 sym_start_up (np, 1);
659                 sts = 0;
660                 break;
661         default:
662                 break;
663         }
664
665         /* On error, restore everything and cross fingers :) */
666         if (sts) {
667                 cmd->scsi_done = ucmd->old_done;
668                 to_do = SYM_EH_DO_IGNORE;
669         }
670
671         ucmd->to_do = to_do;
672         spin_unlock_irq(host->host_lock);
673
674         if (to_do == SYM_EH_DO_WAIT) {
675                 if (!wait_for_completion_timeout(&eh_done, 5*HZ)) {
676                         ucmd->to_do = SYM_EH_DO_IGNORE;
677                         wmb();
678                         sts = -2;
679                 }
680         }
681         dev_warn(&cmd->device->sdev_gendev, "%s operation %s.\n", opname,
682                         sts==0 ? "complete" :sts==-2 ? "timed-out" : "failed");
683         return sts ? SCSI_FAILED : SCSI_SUCCESS;
684 }
685
686
687 /*
688  * Error handlers called from the eh thread (one thread per HBA).
689  */
690 static int sym53c8xx_eh_abort_handler(struct scsi_cmnd *cmd)
691 {
692         return sym_eh_handler(SYM_EH_ABORT, "ABORT", cmd);
693 }
694
695 static int sym53c8xx_eh_device_reset_handler(struct scsi_cmnd *cmd)
696 {
697         return sym_eh_handler(SYM_EH_DEVICE_RESET, "DEVICE RESET", cmd);
698 }
699
700 static int sym53c8xx_eh_bus_reset_handler(struct scsi_cmnd *cmd)
701 {
702         return sym_eh_handler(SYM_EH_BUS_RESET, "BUS RESET", cmd);
703 }
704
705 static int sym53c8xx_eh_host_reset_handler(struct scsi_cmnd *cmd)
706 {
707         return sym_eh_handler(SYM_EH_HOST_RESET, "HOST RESET", cmd);
708 }
709
710 /*
711  *  Tune device queuing depth, according to various limits.
712  */
713 static void sym_tune_dev_queuing(struct sym_tcb *tp, int lun, u_short reqtags)
714 {
715         struct sym_lcb *lp = sym_lp(tp, lun);
716         u_short oldtags;
717
718         if (!lp)
719                 return;
720
721         oldtags = lp->s.reqtags;
722
723         if (reqtags > lp->s.scdev_depth)
724                 reqtags = lp->s.scdev_depth;
725
726         lp->s.reqtags     = reqtags;
727
728         if (reqtags != oldtags) {
729                 dev_info(&tp->starget->dev,
730                          "tagged command queuing %s, command queue depth %d.\n",
731                           lp->s.reqtags ? "enabled" : "disabled", reqtags);
732         }
733 }
734
735 /*
736  *  Linux select queue depths function
737  */
738 #define DEF_DEPTH       (sym_driver_setup.max_tag)
739 #define ALL_TARGETS     -2
740 #define NO_TARGET       -1
741 #define ALL_LUNS        -2
742 #define NO_LUN          -1
743
744 static int device_queue_depth(struct sym_hcb *np, int target, int lun)
745 {
746         int c, h, t, u, v;
747         char *p = sym_driver_setup.tag_ctrl;
748         char *ep;
749
750         h = -1;
751         t = NO_TARGET;
752         u = NO_LUN;
753         while ((c = *p++) != 0) {
754                 v = simple_strtoul(p, &ep, 0);
755                 switch(c) {
756                 case '/':
757                         ++h;
758                         t = ALL_TARGETS;
759                         u = ALL_LUNS;
760                         break;
761                 case 't':
762                         if (t != target)
763                                 t = (target == v) ? v : NO_TARGET;
764                         u = ALL_LUNS;
765                         break;
766                 case 'u':
767                         if (u != lun)
768                                 u = (lun == v) ? v : NO_LUN;
769                         break;
770                 case 'q':
771                         if (h == np->s.unit &&
772                                 (t == ALL_TARGETS || t == target) &&
773                                 (u == ALL_LUNS    || u == lun))
774                                 return v;
775                         break;
776                 case '-':
777                         t = ALL_TARGETS;
778                         u = ALL_LUNS;
779                         break;
780                 default:
781                         break;
782                 }
783                 p = ep;
784         }
785         return DEF_DEPTH;
786 }
787
788 static int sym53c8xx_slave_alloc(struct scsi_device *sdev)
789 {
790         struct sym_hcb *np = sym_get_hcb(sdev->host);
791         struct sym_tcb *tp = &np->target[sdev->id];
792         struct sym_lcb *lp;
793
794         if (sdev->id >= SYM_CONF_MAX_TARGET || sdev->lun >= SYM_CONF_MAX_LUN)
795                 return -ENXIO;
796
797         tp->starget = sdev->sdev_target;
798         /*
799          * Fail the device init if the device is flagged NOSCAN at BOOT in
800          * the NVRAM.  This may speed up boot and maintain coherency with
801          * BIOS device numbering.  Clearing the flag allows the user to
802          * rescan skipped devices later.  We also return an error for
803          * devices not flagged for SCAN LUNS in the NVRAM since some single
804          * lun devices behave badly when asked for a non zero LUN.
805          */
806
807         if (tp->usrflags & SYM_SCAN_BOOT_DISABLED) {
808                 tp->usrflags &= ~SYM_SCAN_BOOT_DISABLED;
809                 starget_printk(KERN_INFO, tp->starget,
810                                 "Scan at boot disabled in NVRAM\n");
811                 return -ENXIO;
812         }
813
814         if (tp->usrflags & SYM_SCAN_LUNS_DISABLED) {
815                 if (sdev->lun != 0)
816                         return -ENXIO;
817                 starget_printk(KERN_INFO, tp->starget,
818                                 "Multiple LUNs disabled in NVRAM\n");
819         }
820
821         lp = sym_alloc_lcb(np, sdev->id, sdev->lun);
822         if (!lp)
823                 return -ENOMEM;
824
825         spi_min_period(tp->starget) = tp->usr_period;
826         spi_max_width(tp->starget) = tp->usr_width;
827
828         return 0;
829 }
830
831 /*
832  * Linux entry point for device queue sizing.
833  */
834 static int sym53c8xx_slave_configure(struct scsi_device *sdev)
835 {
836         struct sym_hcb *np = sym_get_hcb(sdev->host);
837         struct sym_tcb *tp = &np->target[sdev->id];
838         struct sym_lcb *lp = sym_lp(tp, sdev->lun);
839         int reqtags, depth_to_use;
840
841         /*
842          *  Get user flags.
843          */
844         lp->curr_flags = lp->user_flags;
845
846         /*
847          *  Select queue depth from driver setup.
848          *  Donnot use more than configured by user.
849          *  Use at least 2.
850          *  Donnot use more than our maximum.
851          */
852         reqtags = device_queue_depth(np, sdev->id, sdev->lun);
853         if (reqtags > tp->usrtags)
854                 reqtags = tp->usrtags;
855         if (!sdev->tagged_supported)
856                 reqtags = 0;
857 #if 1 /* Avoid to locally queue commands for no good reasons */
858         if (reqtags > SYM_CONF_MAX_TAG)
859                 reqtags = SYM_CONF_MAX_TAG;
860         depth_to_use = (reqtags ? reqtags : 2);
861 #else
862         depth_to_use = (reqtags ? SYM_CONF_MAX_TAG : 2);
863 #endif
864         scsi_adjust_queue_depth(sdev,
865                                 (sdev->tagged_supported ?
866                                  MSG_SIMPLE_TAG : 0),
867                                 depth_to_use);
868         lp->s.scdev_depth = depth_to_use;
869         sym_tune_dev_queuing(tp, sdev->lun, reqtags);
870
871         if (!spi_initial_dv(sdev->sdev_target))
872                 spi_dv_device(sdev);
873
874         return 0;
875 }
876
877 static void sym53c8xx_slave_destroy(struct scsi_device *sdev)
878 {
879         struct sym_hcb *np = sym_get_hcb(sdev->host);
880         struct sym_lcb *lp = sym_lp(&np->target[sdev->id], sdev->lun);
881
882         if (lp->itlq_tbl)
883                 sym_mfree_dma(lp->itlq_tbl, SYM_CONF_MAX_TASK * 4, "ITLQ_TBL");
884         kfree(lp->cb_tags);
885         sym_mfree_dma(lp, sizeof(*lp), "LCB");
886 }
887
888 /*
889  *  Linux entry point for info() function
890  */
891 static const char *sym53c8xx_info (struct Scsi_Host *host)
892 {
893         return SYM_DRIVER_NAME;
894 }
895
896
897 #ifdef SYM_LINUX_PROC_INFO_SUPPORT
898 /*
899  *  Proc file system stuff
900  *
901  *  A read operation returns adapter information.
902  *  A write operation is a control command.
903  *  The string is parsed in the driver code and the command is passed 
904  *  to the sym_usercmd() function.
905  */
906
907 #ifdef SYM_LINUX_USER_COMMAND_SUPPORT
908
909 struct  sym_usrcmd {
910         u_long  target;
911         u_long  lun;
912         u_long  data;
913         u_long  cmd;
914 };
915
916 #define UC_SETSYNC      10
917 #define UC_SETTAGS      11
918 #define UC_SETDEBUG     12
919 #define UC_SETWIDE      14
920 #define UC_SETFLAG      15
921 #define UC_SETVERBOSE   17
922 #define UC_RESETDEV     18
923 #define UC_CLEARDEV     19
924
925 static void sym_exec_user_command (struct sym_hcb *np, struct sym_usrcmd *uc)
926 {
927         struct sym_tcb *tp;
928         int t, l;
929
930         switch (uc->cmd) {
931         case 0: return;
932
933 #ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
934         case UC_SETDEBUG:
935                 sym_debug_flags = uc->data;
936                 break;
937 #endif
938         case UC_SETVERBOSE:
939                 np->verbose = uc->data;
940                 break;
941         default:
942                 /*
943                  * We assume that other commands apply to targets.
944                  * This should always be the case and avoid the below 
945                  * 4 lines to be repeated 6 times.
946                  */
947                 for (t = 0; t < SYM_CONF_MAX_TARGET; t++) {
948                         if (!((uc->target >> t) & 1))
949                                 continue;
950                         tp = &np->target[t];
951
952                         switch (uc->cmd) {
953
954                         case UC_SETSYNC:
955                                 if (!uc->data || uc->data >= 255) {
956                                         tp->tgoal.iu = tp->tgoal.dt =
957                                                 tp->tgoal.qas = 0;
958                                         tp->tgoal.offset = 0;
959                                 } else if (uc->data <= 9 && np->minsync_dt) {
960                                         if (uc->data < np->minsync_dt)
961                                                 uc->data = np->minsync_dt;
962                                         tp->tgoal.iu = tp->tgoal.dt =
963                                                 tp->tgoal.qas = 1;
964                                         tp->tgoal.width = 1;
965                                         tp->tgoal.period = uc->data;
966                                         tp->tgoal.offset = np->maxoffs_dt;
967                                 } else {
968                                         if (uc->data < np->minsync)
969                                                 uc->data = np->minsync;
970                                         tp->tgoal.iu = tp->tgoal.dt =
971                                                 tp->tgoal.qas = 0;
972                                         tp->tgoal.period = uc->data;
973                                         tp->tgoal.offset = np->maxoffs;
974                                 }
975                                 tp->tgoal.check_nego = 1;
976                                 break;
977                         case UC_SETWIDE:
978                                 tp->tgoal.width = uc->data ? 1 : 0;
979                                 tp->tgoal.check_nego = 1;
980                                 break;
981                         case UC_SETTAGS:
982                                 for (l = 0; l < SYM_CONF_MAX_LUN; l++)
983                                         sym_tune_dev_queuing(tp, l, uc->data);
984                                 break;
985                         case UC_RESETDEV:
986                                 tp->to_reset = 1;
987                                 np->istat_sem = SEM;
988                                 OUTB(np, nc_istat, SIGP|SEM);
989                                 break;
990                         case UC_CLEARDEV:
991                                 for (l = 0; l < SYM_CONF_MAX_LUN; l++) {
992                                         struct sym_lcb *lp = sym_lp(tp, l);
993                                         if (lp) lp->to_clear = 1;
994                                 }
995                                 np->istat_sem = SEM;
996                                 OUTB(np, nc_istat, SIGP|SEM);
997                                 break;
998                         case UC_SETFLAG:
999                                 tp->usrflags = uc->data;
1000                                 break;
1001                         }
1002                 }
1003                 break;
1004         }
1005 }
1006
1007 static int skip_spaces(char *ptr, int len)
1008 {
1009         int cnt, c;
1010
1011         for (cnt = len; cnt > 0 && (c = *ptr++) && isspace(c); cnt--);
1012
1013         return (len - cnt);
1014 }
1015
1016 static int get_int_arg(char *ptr, int len, u_long *pv)
1017 {
1018         char *end;
1019
1020         *pv = simple_strtoul(ptr, &end, 10);
1021         return (end - ptr);
1022 }
1023
1024 static int is_keyword(char *ptr, int len, char *verb)
1025 {
1026         int verb_len = strlen(verb);
1027
1028         if (len >= verb_len && !memcmp(verb, ptr, verb_len))
1029                 return verb_len;
1030         else
1031                 return 0;
1032 }
1033
1034 #define SKIP_SPACES(ptr, len)                                           \
1035         if ((arg_len = skip_spaces(ptr, len)) < 1)                      \
1036                 return -EINVAL;                                         \
1037         ptr += arg_len; len -= arg_len;
1038
1039 #define GET_INT_ARG(ptr, len, v)                                        \
1040         if (!(arg_len = get_int_arg(ptr, len, &(v))))                   \
1041                 return -EINVAL;                                         \
1042         ptr += arg_len; len -= arg_len;
1043
1044
1045 /*
1046  * Parse a control command
1047  */
1048
1049 static int sym_user_command(struct sym_hcb *np, char *buffer, int length)
1050 {
1051         char *ptr       = buffer;
1052         int len         = length;
1053         struct sym_usrcmd cmd, *uc = &cmd;
1054         int             arg_len;
1055         u_long          target;
1056
1057         memset(uc, 0, sizeof(*uc));
1058
1059         if (len > 0 && ptr[len-1] == '\n')
1060                 --len;
1061
1062         if      ((arg_len = is_keyword(ptr, len, "setsync")) != 0)
1063                 uc->cmd = UC_SETSYNC;
1064         else if ((arg_len = is_keyword(ptr, len, "settags")) != 0)
1065                 uc->cmd = UC_SETTAGS;
1066         else if ((arg_len = is_keyword(ptr, len, "setverbose")) != 0)
1067                 uc->cmd = UC_SETVERBOSE;
1068         else if ((arg_len = is_keyword(ptr, len, "setwide")) != 0)
1069                 uc->cmd = UC_SETWIDE;
1070 #ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
1071         else if ((arg_len = is_keyword(ptr, len, "setdebug")) != 0)
1072                 uc->cmd = UC_SETDEBUG;
1073 #endif
1074         else if ((arg_len = is_keyword(ptr, len, "setflag")) != 0)
1075                 uc->cmd = UC_SETFLAG;
1076         else if ((arg_len = is_keyword(ptr, len, "resetdev")) != 0)
1077                 uc->cmd = UC_RESETDEV;
1078         else if ((arg_len = is_keyword(ptr, len, "cleardev")) != 0)
1079                 uc->cmd = UC_CLEARDEV;
1080         else
1081                 arg_len = 0;
1082
1083 #ifdef DEBUG_PROC_INFO
1084 printk("sym_user_command: arg_len=%d, cmd=%ld\n", arg_len, uc->cmd);
1085 #endif
1086
1087         if (!arg_len)
1088                 return -EINVAL;
1089         ptr += arg_len; len -= arg_len;
1090
1091         switch(uc->cmd) {
1092         case UC_SETSYNC:
1093         case UC_SETTAGS:
1094         case UC_SETWIDE:
1095         case UC_SETFLAG:
1096         case UC_RESETDEV:
1097         case UC_CLEARDEV:
1098                 SKIP_SPACES(ptr, len);
1099                 if ((arg_len = is_keyword(ptr, len, "all")) != 0) {
1100                         ptr += arg_len; len -= arg_len;
1101                         uc->target = ~0;
1102                 } else {
1103                         GET_INT_ARG(ptr, len, target);
1104                         uc->target = (1<<target);
1105 #ifdef DEBUG_PROC_INFO
1106 printk("sym_user_command: target=%ld\n", target);
1107 #endif
1108                 }
1109                 break;
1110         }
1111
1112         switch(uc->cmd) {
1113         case UC_SETVERBOSE:
1114         case UC_SETSYNC:
1115         case UC_SETTAGS:
1116         case UC_SETWIDE:
1117                 SKIP_SPACES(ptr, len);
1118                 GET_INT_ARG(ptr, len, uc->data);
1119 #ifdef DEBUG_PROC_INFO
1120 printk("sym_user_command: data=%ld\n", uc->data);
1121 #endif
1122                 break;
1123 #ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
1124         case UC_SETDEBUG:
1125                 while (len > 0) {
1126                         SKIP_SPACES(ptr, len);
1127                         if      ((arg_len = is_keyword(ptr, len, "alloc")))
1128                                 uc->data |= DEBUG_ALLOC;
1129                         else if ((arg_len = is_keyword(ptr, len, "phase")))
1130                                 uc->data |= DEBUG_PHASE;
1131                         else if ((arg_len = is_keyword(ptr, len, "queue")))
1132                                 uc->data |= DEBUG_QUEUE;
1133                         else if ((arg_len = is_keyword(ptr, len, "result")))
1134                                 uc->data |= DEBUG_RESULT;
1135                         else if ((arg_len = is_keyword(ptr, len, "scatter")))
1136                                 uc->data |= DEBUG_SCATTER;
1137                         else if ((arg_len = is_keyword(ptr, len, "script")))
1138                                 uc->data |= DEBUG_SCRIPT;
1139                         else if ((arg_len = is_keyword(ptr, len, "tiny")))
1140                                 uc->data |= DEBUG_TINY;
1141                         else if ((arg_len = is_keyword(ptr, len, "timing")))
1142                                 uc->data |= DEBUG_TIMING;
1143                         else if ((arg_len = is_keyword(ptr, len, "nego")))
1144                                 uc->data |= DEBUG_NEGO;
1145                         else if ((arg_len = is_keyword(ptr, len, "tags")))
1146                                 uc->data |= DEBUG_TAGS;
1147                         else if ((arg_len = is_keyword(ptr, len, "pointer")))
1148                                 uc->data |= DEBUG_POINTER;
1149                         else
1150                                 return -EINVAL;
1151                         ptr += arg_len; len -= arg_len;
1152                 }
1153 #ifdef DEBUG_PROC_INFO
1154 printk("sym_user_command: data=%ld\n", uc->data);
1155 #endif
1156                 break;
1157 #endif /* SYM_LINUX_DEBUG_CONTROL_SUPPORT */
1158         case UC_SETFLAG:
1159                 while (len > 0) {
1160                         SKIP_SPACES(ptr, len);
1161                         if      ((arg_len = is_keyword(ptr, len, "no_disc")))
1162                                 uc->data &= ~SYM_DISC_ENABLED;
1163                         else
1164                                 return -EINVAL;
1165                         ptr += arg_len; len -= arg_len;
1166                 }
1167                 break;
1168         default:
1169                 break;
1170         }
1171
1172         if (len)
1173                 return -EINVAL;
1174         else {
1175                 unsigned long flags;
1176
1177                 spin_lock_irqsave(np->s.host->host_lock, flags);
1178                 sym_exec_user_command (np, uc);
1179                 spin_unlock_irqrestore(np->s.host->host_lock, flags);
1180         }
1181         return length;
1182 }
1183
1184 #endif  /* SYM_LINUX_USER_COMMAND_SUPPORT */
1185
1186
1187 #ifdef SYM_LINUX_USER_INFO_SUPPORT
1188 /*
1189  *  Informations through the proc file system.
1190  */
1191 struct info_str {
1192         char *buffer;
1193         int length;
1194         int offset;
1195         int pos;
1196 };
1197
1198 static void copy_mem_info(struct info_str *info, char *data, int len)
1199 {
1200         if (info->pos + len > info->length)
1201                 len = info->length - info->pos;
1202
1203         if (info->pos + len < info->offset) {
1204                 info->pos += len;
1205                 return;
1206         }
1207         if (info->pos < info->offset) {
1208                 data += (info->offset - info->pos);
1209                 len  -= (info->offset - info->pos);
1210         }
1211
1212         if (len > 0) {
1213                 memcpy(info->buffer + info->pos, data, len);
1214                 info->pos += len;
1215         }
1216 }
1217
1218 static int copy_info(struct info_str *info, char *fmt, ...)
1219 {
1220         va_list args;
1221         char buf[81];
1222         int len;
1223
1224         va_start(args, fmt);
1225         len = vsprintf(buf, fmt, args);
1226         va_end(args);
1227
1228         copy_mem_info(info, buf, len);
1229         return len;
1230 }
1231
1232 /*
1233  *  Copy formatted information into the input buffer.
1234  */
1235 static int sym_host_info(struct sym_hcb *np, char *ptr, off_t offset, int len)
1236 {
1237         struct info_str info;
1238
1239         info.buffer     = ptr;
1240         info.length     = len;
1241         info.offset     = offset;
1242         info.pos        = 0;
1243
1244         copy_info(&info, "Chip " NAME53C "%s, device id 0x%x, "
1245                          "revision id 0x%x\n",
1246                          np->s.chip_name, np->device_id, np->revision_id);
1247         copy_info(&info, "At PCI address %s, IRQ " IRQ_FMT "\n",
1248                 pci_name(np->s.device), IRQ_PRM(np->s.device->irq));
1249         copy_info(&info, "Min. period factor %d, %s SCSI BUS%s\n",
1250                          (int) (np->minsync_dt ? np->minsync_dt : np->minsync),
1251                          np->maxwide ? "Wide" : "Narrow",
1252                          np->minsync_dt ? ", DT capable" : "");
1253
1254         copy_info(&info, "Max. started commands %d, "
1255                          "max. commands per LUN %d\n",
1256                          SYM_CONF_MAX_START, SYM_CONF_MAX_TAG);
1257
1258         return info.pos > info.offset? info.pos - info.offset : 0;
1259 }
1260 #endif /* SYM_LINUX_USER_INFO_SUPPORT */
1261
1262 /*
1263  *  Entry point of the scsi proc fs of the driver.
1264  *  - func = 0 means read  (returns adapter infos)
1265  *  - func = 1 means write (not yet merget from sym53c8xx)
1266  */
1267 static int sym53c8xx_proc_info(struct Scsi_Host *host, char *buffer,
1268                         char **start, off_t offset, int length, int func)
1269 {
1270         struct sym_hcb *np = sym_get_hcb(host);
1271         int retv;
1272
1273         if (func) {
1274 #ifdef  SYM_LINUX_USER_COMMAND_SUPPORT
1275                 retv = sym_user_command(np, buffer, length);
1276 #else
1277                 retv = -EINVAL;
1278 #endif
1279         } else {
1280                 if (start)
1281                         *start = buffer;
1282 #ifdef SYM_LINUX_USER_INFO_SUPPORT
1283                 retv = sym_host_info(np, buffer, offset, length);
1284 #else
1285                 retv = -EINVAL;
1286 #endif
1287         }
1288
1289         return retv;
1290 }
1291 #endif /* SYM_LINUX_PROC_INFO_SUPPORT */
1292
1293 /*
1294  *      Free controller resources.
1295  */
1296 static void sym_free_resources(struct sym_hcb *np, struct pci_dev *pdev)
1297 {
1298         /*
1299          *  Free O/S specific resources.
1300          */
1301         if (pdev->irq)
1302                 free_irq(pdev->irq, np);
1303         if (np->s.ioaddr)
1304                 pci_iounmap(pdev, np->s.ioaddr);
1305         if (np->s.ramaddr)
1306                 pci_iounmap(pdev, np->s.ramaddr);
1307         /*
1308          *  Free O/S independent resources.
1309          */
1310         sym_hcb_free(np);
1311
1312         sym_mfree_dma(np, sizeof(*np), "HCB");
1313 }
1314
1315 /*
1316  *  Ask/tell the system about DMA addressing.
1317  */
1318 static int sym_setup_bus_dma_mask(struct sym_hcb *np)
1319 {
1320 #if SYM_CONF_DMA_ADDRESSING_MODE > 0
1321 #if   SYM_CONF_DMA_ADDRESSING_MODE == 1
1322 #define DMA_DAC_MASK    DMA_40BIT_MASK
1323 #elif SYM_CONF_DMA_ADDRESSING_MODE == 2
1324 #define DMA_DAC_MASK    DMA_64BIT_MASK
1325 #endif
1326         if ((np->features & FE_DAC) &&
1327                         !pci_set_dma_mask(np->s.device, DMA_DAC_MASK)) {
1328                 np->use_dac = 1;
1329                 return 0;
1330         }
1331 #endif
1332
1333         if (!pci_set_dma_mask(np->s.device, DMA_32BIT_MASK))
1334                 return 0;
1335
1336         printf_warning("%s: No suitable DMA available\n", sym_name(np));
1337         return -1;
1338 }
1339
1340 /*
1341  *  Host attach and initialisations.
1342  *
1343  *  Allocate host data and ncb structure.
1344  *  Remap MMIO region.
1345  *  Do chip initialization.
1346  *  If all is OK, install interrupt handling and
1347  *  start the timer daemon.
1348  */
1349 static struct Scsi_Host * __devinit sym_attach(struct scsi_host_template *tpnt,
1350                 int unit, struct sym_device *dev)
1351 {
1352         struct host_data *host_data;
1353         struct sym_hcb *np = NULL;
1354         struct Scsi_Host *instance = NULL;
1355         struct pci_dev *pdev = dev->pdev;
1356         unsigned long flags;
1357         struct sym_fw *fw;
1358
1359         printk(KERN_INFO
1360                 "sym%d: <%s> rev 0x%x at pci %s irq " IRQ_FMT "\n",
1361                 unit, dev->chip.name, dev->chip.revision_id,
1362                 pci_name(pdev), IRQ_PRM(pdev->irq));
1363
1364         /*
1365          *  Get the firmware for this chip.
1366          */
1367         fw = sym_find_firmware(&dev->chip);
1368         if (!fw)
1369                 goto attach_failed;
1370
1371         /*
1372          *      Allocate host_data structure
1373          */
1374         instance = scsi_host_alloc(tpnt, sizeof(*host_data));
1375         if (!instance)
1376                 goto attach_failed;
1377         host_data = (struct host_data *) instance->hostdata;
1378
1379         /*
1380          *  Allocate immediately the host control block, 
1381          *  since we are only expecting to succeed. :)
1382          *  We keep track in the HCB of all the resources that 
1383          *  are to be released on error.
1384          */
1385         np = __sym_calloc_dma(&pdev->dev, sizeof(*np), "HCB");
1386         if (!np)
1387                 goto attach_failed;
1388         np->s.device = pdev;
1389         np->bus_dmat = &pdev->dev; /* Result in 1 DMA pool per HBA */
1390         host_data->ncb = np;
1391         np->s.host = instance;
1392
1393         pci_set_drvdata(pdev, np);
1394
1395         /*
1396          *  Copy some useful infos to the HCB.
1397          */
1398         np->hcb_ba      = vtobus(np);
1399         np->verbose     = sym_driver_setup.verbose;
1400         np->s.device    = pdev;
1401         np->s.unit      = unit;
1402         np->device_id   = dev->chip.device_id;
1403         np->revision_id = dev->chip.revision_id;
1404         np->features    = dev->chip.features;
1405         np->clock_divn  = dev->chip.nr_divisor;
1406         np->maxoffs     = dev->chip.offset_max;
1407         np->maxburst    = dev->chip.burst_max;
1408         np->myaddr      = dev->host_id;
1409
1410         /*
1411          *  Edit its name.
1412          */
1413         strlcpy(np->s.chip_name, dev->chip.name, sizeof(np->s.chip_name));
1414         sprintf(np->s.inst_name, "sym%d", np->s.unit);
1415
1416         if (sym_setup_bus_dma_mask(np))
1417                 goto attach_failed;
1418
1419         /*
1420          *  Try to map the controller chip to
1421          *  virtual and physical memory.
1422          */
1423         np->mmio_ba = (u32)dev->mmio_base;
1424         np->s.ioaddr    = dev->s.ioaddr;
1425         np->s.ramaddr   = dev->s.ramaddr;
1426         np->s.io_ws = (np->features & FE_IO256) ? 256 : 128;
1427
1428         /*
1429          *  Map on-chip RAM if present and supported.
1430          */
1431         if (!(np->features & FE_RAM))
1432                 dev->ram_base = 0;
1433         if (dev->ram_base) {
1434                 np->ram_ba = (u32)dev->ram_base;
1435                 np->ram_ws = (np->features & FE_RAM8K) ? 8192 : 4096;
1436         }
1437
1438         if (sym_hcb_attach(instance, fw, dev->nvram))
1439                 goto attach_failed;
1440
1441         /*
1442          *  Install the interrupt handler.
1443          *  If we synchonize the C code with SCRIPTS on interrupt, 
1444          *  we do not want to share the INTR line at all.
1445          */
1446         if (request_irq(pdev->irq, sym53c8xx_intr, IRQF_SHARED, NAME53C8XX, np)) {
1447                 printf_err("%s: request irq %d failure\n",
1448                         sym_name(np), pdev->irq);
1449                 goto attach_failed;
1450         }
1451
1452         /*
1453          *  After SCSI devices have been opened, we cannot
1454          *  reset the bus safely, so we do it here.
1455          */
1456         spin_lock_irqsave(instance->host_lock, flags);
1457         if (sym_reset_scsi_bus(np, 0))
1458                 goto reset_failed;
1459
1460         /*
1461          *  Start the SCRIPTS.
1462          */
1463         sym_start_up (np, 1);
1464
1465         /*
1466          *  Start the timer daemon
1467          */
1468         init_timer(&np->s.timer);
1469         np->s.timer.data     = (unsigned long) np;
1470         np->s.timer.function = sym53c8xx_timer;
1471         np->s.lasttime=0;
1472         sym_timer (np);
1473
1474         /*
1475          *  Fill Linux host instance structure
1476          *  and return success.
1477          */
1478         instance->max_channel   = 0;
1479         instance->this_id       = np->myaddr;
1480         instance->max_id        = np->maxwide ? 16 : 8;
1481         instance->max_lun       = SYM_CONF_MAX_LUN;
1482         instance->unique_id     = pci_resource_start(pdev, 0);
1483         instance->cmd_per_lun   = SYM_CONF_MAX_TAG;
1484         instance->can_queue     = (SYM_CONF_MAX_START-2);
1485         instance->sg_tablesize  = SYM_CONF_MAX_SG;
1486         instance->max_cmd_len   = 16;
1487         BUG_ON(sym2_transport_template == NULL);
1488         instance->transportt    = sym2_transport_template;
1489
1490         /* 53c896 rev 1 errata: DMA may not cross 16MB boundary */
1491         if (pdev->device == PCI_DEVICE_ID_NCR_53C896 && np->revision_id < 2)
1492                 instance->dma_boundary = 0xFFFFFF;
1493
1494         spin_unlock_irqrestore(instance->host_lock, flags);
1495
1496         return instance;
1497
1498  reset_failed:
1499         printf_err("%s: FATAL ERROR: CHECK SCSI BUS - CABLES, "
1500                    "TERMINATION, DEVICE POWER etc.!\n", sym_name(np));
1501         spin_unlock_irqrestore(instance->host_lock, flags);
1502  attach_failed:
1503         if (!instance)
1504                 return NULL;
1505         printf_info("%s: giving up ...\n", sym_name(np));
1506         if (np)
1507                 sym_free_resources(np, pdev);
1508         scsi_host_put(instance);
1509
1510         return NULL;
1511  }
1512
1513
1514 /*
1515  *    Detect and try to read SYMBIOS and TEKRAM NVRAM.
1516  */
1517 #if SYM_CONF_NVRAM_SUPPORT
1518 static void __devinit sym_get_nvram(struct sym_device *devp, struct sym_nvram *nvp)
1519 {
1520         devp->nvram = nvp;
1521         devp->device_id = devp->chip.device_id;
1522         nvp->type = 0;
1523
1524         sym_read_nvram(devp, nvp);
1525 }
1526 #else
1527 static inline void sym_get_nvram(struct sym_device *devp, struct sym_nvram *nvp)
1528 {
1529 }
1530 #endif  /* SYM_CONF_NVRAM_SUPPORT */
1531
1532 static int __devinit sym_check_supported(struct sym_device *device)
1533 {
1534         struct sym_chip *chip;
1535         struct pci_dev *pdev = device->pdev;
1536         u_char revision;
1537         unsigned long io_port = pci_resource_start(pdev, 0);
1538         int i;
1539
1540         /*
1541          *  If user excluded this chip, do not initialize it.
1542          *  I hate this code so much.  Must kill it.
1543          */
1544         if (io_port) {
1545                 for (i = 0 ; i < 8 ; i++) {
1546                         if (sym_driver_setup.excludes[i] == io_port)
1547                                 return -ENODEV;
1548                 }
1549         }
1550
1551         /*
1552          * Check if the chip is supported.  Then copy the chip description
1553          * to our device structure so we can make it match the actual device
1554          * and options.
1555          */
1556         pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
1557         chip = sym_lookup_chip_table(pdev->device, revision);
1558         if (!chip) {
1559                 dev_info(&pdev->dev, "device not supported\n");
1560                 return -ENODEV;
1561         }
1562         memcpy(&device->chip, chip, sizeof(device->chip));
1563         device->chip.revision_id = revision;
1564
1565         return 0;
1566 }
1567
1568 /*
1569  * Ignore Symbios chips controlled by various RAID controllers.
1570  * These controllers set value 0x52414944 at RAM end - 16.
1571  */
1572 static int __devinit sym_check_raid(struct sym_device *device)
1573 {
1574         unsigned int ram_size, ram_val;
1575
1576         if (!device->s.ramaddr)
1577                 return 0;
1578
1579         if (device->chip.features & FE_RAM8K)
1580                 ram_size = 8192;
1581         else
1582                 ram_size = 4096;
1583
1584         ram_val = readl(device->s.ramaddr + ram_size - 16);
1585         if (ram_val != 0x52414944)
1586                 return 0;
1587
1588         dev_info(&device->pdev->dev,
1589                         "not initializing, driven by RAID controller.\n");
1590         return -ENODEV;
1591 }
1592
1593 static int __devinit sym_set_workarounds(struct sym_device *device)
1594 {
1595         struct sym_chip *chip = &device->chip;
1596         struct pci_dev *pdev = device->pdev;
1597         u_short status_reg;
1598
1599         /*
1600          *  (ITEM 12 of a DEL about the 896 I haven't yet).
1601          *  We must ensure the chip will use WRITE AND INVALIDATE.
1602          *  The revision number limit is for now arbitrary.
1603          */
1604         if (pdev->device == PCI_DEVICE_ID_NCR_53C896 && chip->revision_id < 0x4) {
1605                 chip->features  |= (FE_WRIE | FE_CLSE);
1606         }
1607
1608         /* If the chip can do Memory Write Invalidate, enable it */
1609         if (chip->features & FE_WRIE) {
1610                 if (pci_set_mwi(pdev))
1611                         return -ENODEV;
1612         }
1613
1614         /*
1615          *  Work around for errant bit in 895A. The 66Mhz
1616          *  capable bit is set erroneously. Clear this bit.
1617          *  (Item 1 DEL 533)
1618          *
1619          *  Make sure Config space and Features agree.
1620          *
1621          *  Recall: writes are not normal to status register -
1622          *  write a 1 to clear and a 0 to leave unchanged.
1623          *  Can only reset bits.
1624          */
1625         pci_read_config_word(pdev, PCI_STATUS, &status_reg);
1626         if (chip->features & FE_66MHZ) {
1627                 if (!(status_reg & PCI_STATUS_66MHZ))
1628                         chip->features &= ~FE_66MHZ;
1629         } else {
1630                 if (status_reg & PCI_STATUS_66MHZ) {
1631                         status_reg = PCI_STATUS_66MHZ;
1632                         pci_write_config_word(pdev, PCI_STATUS, status_reg);
1633                         pci_read_config_word(pdev, PCI_STATUS, &status_reg);
1634                 }
1635         }
1636
1637         return 0;
1638 }
1639
1640 /*
1641  *  Read and check the PCI configuration for any detected NCR 
1642  *  boards and save data for attaching after all boards have 
1643  *  been detected.
1644  */
1645 static void __devinit
1646 sym_init_device(struct pci_dev *pdev, struct sym_device *device)
1647 {
1648         int i = 2;
1649         struct pci_bus_region bus_addr;
1650
1651         device->host_id = SYM_SETUP_HOST_ID;
1652         device->pdev = pdev;
1653
1654         pcibios_resource_to_bus(pdev, &bus_addr, &pdev->resource[1]);
1655         device->mmio_base = bus_addr.start;
1656
1657         /*
1658          * If the BAR is 64-bit, resource 2 will be occupied by the
1659          * upper 32 bits
1660          */
1661         if (!pdev->resource[i].flags)
1662                 i++;
1663         pcibios_resource_to_bus(pdev, &bus_addr, &pdev->resource[i]);
1664         device->ram_base = bus_addr.start;
1665
1666 #ifdef CONFIG_SCSI_SYM53C8XX_MMIO
1667         if (device->mmio_base)
1668                 device->s.ioaddr = pci_iomap(pdev, 1,
1669                                                 pci_resource_len(pdev, 1));
1670 #endif
1671         if (!device->s.ioaddr)
1672                 device->s.ioaddr = pci_iomap(pdev, 0,
1673                                                 pci_resource_len(pdev, 0));
1674         if (device->ram_base)
1675                 device->s.ramaddr = pci_iomap(pdev, i,
1676                                                 pci_resource_len(pdev, i));
1677 }
1678
1679 /*
1680  * The NCR PQS and PDS cards are constructed as a DEC bridge
1681  * behind which sits a proprietary NCR memory controller and
1682  * either four or two 53c875s as separate devices.  We can tell
1683  * if an 875 is part of a PQS/PDS or not since if it is, it will
1684  * be on the same bus as the memory controller.  In its usual
1685  * mode of operation, the 875s are slaved to the memory
1686  * controller for all transfers.  To operate with the Linux
1687  * driver, the memory controller is disabled and the 875s
1688  * freed to function independently.  The only wrinkle is that
1689  * the preset SCSI ID (which may be zero) must be read in from
1690  * a special configuration space register of the 875.
1691  */
1692 static void sym_config_pqs(struct pci_dev *pdev, struct sym_device *sym_dev)
1693 {
1694         int slot;
1695         u8 tmp;
1696
1697         for (slot = 0; slot < 256; slot++) {
1698                 struct pci_dev *memc = pci_get_slot(pdev->bus, slot);
1699
1700                 if (!memc || memc->vendor != 0x101a || memc->device == 0x0009) {
1701                         pci_dev_put(memc);
1702                         continue;
1703                 }
1704
1705                 /* bit 1: allow individual 875 configuration */
1706                 pci_read_config_byte(memc, 0x44, &tmp);
1707                 if ((tmp & 0x2) == 0) {
1708                         tmp |= 0x2;
1709                         pci_write_config_byte(memc, 0x44, tmp);
1710                 }
1711
1712                 /* bit 2: drive individual 875 interrupts to the bus */
1713                 pci_read_config_byte(memc, 0x45, &tmp);
1714                 if ((tmp & 0x4) == 0) {
1715                         tmp |= 0x4;
1716                         pci_write_config_byte(memc, 0x45, tmp);
1717                 }
1718
1719                 pci_dev_put(memc);
1720                 break;
1721         }
1722
1723         pci_read_config_byte(pdev, 0x84, &tmp);
1724         sym_dev->host_id = tmp;
1725 }
1726
1727 /*
1728  *  Called before unloading the module.
1729  *  Detach the host.
1730  *  We have to free resources and halt the NCR chip.
1731  */
1732 static int sym_detach(struct sym_hcb *np, struct pci_dev *pdev)
1733 {
1734         printk("%s: detaching ...\n", sym_name(np));
1735
1736         del_timer_sync(&np->s.timer);
1737
1738         /*
1739          * Reset NCR chip.
1740          * We should use sym_soft_reset(), but we don't want to do 
1741          * so, since we may not be safe if interrupts occur.
1742          */
1743         printk("%s: resetting chip\n", sym_name(np));
1744         OUTB(np, nc_istat, SRST);
1745         INB(np, nc_mbox1);
1746         udelay(10);
1747         OUTB(np, nc_istat, 0);
1748
1749         sym_free_resources(np, pdev);
1750
1751         return 1;
1752 }
1753
1754 /*
1755  * Driver host template.
1756  */
1757 static struct scsi_host_template sym2_template = {
1758         .module                 = THIS_MODULE,
1759         .name                   = "sym53c8xx",
1760         .info                   = sym53c8xx_info, 
1761         .queuecommand           = sym53c8xx_queue_command,
1762         .slave_alloc            = sym53c8xx_slave_alloc,
1763         .slave_configure        = sym53c8xx_slave_configure,
1764         .slave_destroy          = sym53c8xx_slave_destroy,
1765         .eh_abort_handler       = sym53c8xx_eh_abort_handler,
1766         .eh_device_reset_handler = sym53c8xx_eh_device_reset_handler,
1767         .eh_bus_reset_handler   = sym53c8xx_eh_bus_reset_handler,
1768         .eh_host_reset_handler  = sym53c8xx_eh_host_reset_handler,
1769         .this_id                = 7,
1770         .use_clustering         = ENABLE_CLUSTERING,
1771         .use_sg_chaining        = ENABLE_SG_CHAINING,
1772         .max_sectors            = 0xFFFF,
1773 #ifdef SYM_LINUX_PROC_INFO_SUPPORT
1774         .proc_info              = sym53c8xx_proc_info,
1775         .proc_name              = NAME53C8XX,
1776 #endif
1777 };
1778
1779 static int attach_count;
1780
1781 static int __devinit sym2_probe(struct pci_dev *pdev,
1782                                 const struct pci_device_id *ent)
1783 {
1784         struct sym_device sym_dev;
1785         struct sym_nvram nvram;
1786         struct Scsi_Host *instance;
1787
1788         memset(&sym_dev, 0, sizeof(sym_dev));
1789         memset(&nvram, 0, sizeof(nvram));
1790
1791         if (pci_enable_device(pdev))
1792                 goto leave;
1793
1794         pci_set_master(pdev);
1795
1796         if (pci_request_regions(pdev, NAME53C8XX))
1797                 goto disable;
1798
1799         sym_init_device(pdev, &sym_dev);
1800         if (sym_check_supported(&sym_dev))
1801                 goto free;
1802
1803         if (sym_check_raid(&sym_dev))
1804                 goto leave;     /* Don't disable the device */
1805
1806         if (sym_set_workarounds(&sym_dev))
1807                 goto free;
1808
1809         sym_config_pqs(pdev, &sym_dev);
1810
1811         sym_get_nvram(&sym_dev, &nvram);
1812
1813         instance = sym_attach(&sym2_template, attach_count, &sym_dev);
1814         if (!instance)
1815                 goto free;
1816
1817         if (scsi_add_host(instance, &pdev->dev))
1818                 goto detach;
1819         scsi_scan_host(instance);
1820
1821         attach_count++;
1822
1823         return 0;
1824
1825  detach:
1826         sym_detach(pci_get_drvdata(pdev), pdev);
1827  free:
1828         pci_release_regions(pdev);
1829  disable:
1830         pci_disable_device(pdev);
1831  leave:
1832         return -ENODEV;
1833 }
1834
1835 static void __devexit sym2_remove(struct pci_dev *pdev)
1836 {
1837         struct sym_hcb *np = pci_get_drvdata(pdev);
1838         struct Scsi_Host *host = np->s.host;
1839
1840         scsi_remove_host(host);
1841         scsi_host_put(host);
1842
1843         sym_detach(np, pdev);
1844
1845         pci_release_regions(pdev);
1846         pci_disable_device(pdev);
1847
1848         attach_count--;
1849 }
1850
1851 static void sym2_get_signalling(struct Scsi_Host *shost)
1852 {
1853         struct sym_hcb *np = sym_get_hcb(shost);
1854         enum spi_signal_type type;
1855
1856         switch (np->scsi_mode) {
1857         case SMODE_SE:
1858                 type = SPI_SIGNAL_SE;
1859                 break;
1860         case SMODE_LVD:
1861                 type = SPI_SIGNAL_LVD;
1862                 break;
1863         case SMODE_HVD:
1864                 type = SPI_SIGNAL_HVD;
1865                 break;
1866         default:
1867                 type = SPI_SIGNAL_UNKNOWN;
1868                 break;
1869         }
1870         spi_signalling(shost) = type;
1871 }
1872
1873 static void sym2_set_offset(struct scsi_target *starget, int offset)
1874 {
1875         struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1876         struct sym_hcb *np = sym_get_hcb(shost);
1877         struct sym_tcb *tp = &np->target[starget->id];
1878
1879         tp->tgoal.offset = offset;
1880         tp->tgoal.check_nego = 1;
1881 }
1882
1883 static void sym2_set_period(struct scsi_target *starget, int period)
1884 {
1885         struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1886         struct sym_hcb *np = sym_get_hcb(shost);
1887         struct sym_tcb *tp = &np->target[starget->id];
1888
1889         /* have to have DT for these transfers, but DT will also
1890          * set width, so check that this is allowed */
1891         if (period <= np->minsync && spi_width(starget))
1892                 tp->tgoal.dt = 1;
1893
1894         tp->tgoal.period = period;
1895         tp->tgoal.check_nego = 1;
1896 }
1897
1898 static void sym2_set_width(struct scsi_target *starget, int width)
1899 {
1900         struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1901         struct sym_hcb *np = sym_get_hcb(shost);
1902         struct sym_tcb *tp = &np->target[starget->id];
1903
1904         /* It is illegal to have DT set on narrow transfers.  If DT is
1905          * clear, we must also clear IU and QAS.  */
1906         if (width == 0)
1907                 tp->tgoal.iu = tp->tgoal.dt = tp->tgoal.qas = 0;
1908
1909         tp->tgoal.width = width;
1910         tp->tgoal.check_nego = 1;
1911 }
1912
1913 static void sym2_set_dt(struct scsi_target *starget, int dt)
1914 {
1915         struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1916         struct sym_hcb *np = sym_get_hcb(shost);
1917         struct sym_tcb *tp = &np->target[starget->id];
1918
1919         /* We must clear QAS and IU if DT is clear */
1920         if (dt)
1921                 tp->tgoal.dt = 1;
1922         else
1923                 tp->tgoal.iu = tp->tgoal.dt = tp->tgoal.qas = 0;
1924         tp->tgoal.check_nego = 1;
1925 }
1926
1927 #if 0
1928 static void sym2_set_iu(struct scsi_target *starget, int iu)
1929 {
1930         struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1931         struct sym_hcb *np = sym_get_hcb(shost);
1932         struct sym_tcb *tp = &np->target[starget->id];
1933
1934         if (iu)
1935                 tp->tgoal.iu = tp->tgoal.dt = 1;
1936         else
1937                 tp->tgoal.iu = 0;
1938         tp->tgoal.check_nego = 1;
1939 }
1940
1941 static void sym2_set_qas(struct scsi_target *starget, int qas)
1942 {
1943         struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1944         struct sym_hcb *np = sym_get_hcb(shost);
1945         struct sym_tcb *tp = &np->target[starget->id];
1946
1947         if (qas)
1948                 tp->tgoal.dt = tp->tgoal.qas = 1;
1949         else
1950                 tp->tgoal.qas = 0;
1951         tp->tgoal.check_nego = 1;
1952 }
1953 #endif
1954
1955 static struct spi_function_template sym2_transport_functions = {
1956         .set_offset     = sym2_set_offset,
1957         .show_offset    = 1,
1958         .set_period     = sym2_set_period,
1959         .show_period    = 1,
1960         .set_width      = sym2_set_width,
1961         .show_width     = 1,
1962         .set_dt         = sym2_set_dt,
1963         .show_dt        = 1,
1964 #if 0
1965         .set_iu         = sym2_set_iu,
1966         .show_iu        = 1,
1967         .set_qas        = sym2_set_qas,
1968         .show_qas       = 1,
1969 #endif
1970         .get_signalling = sym2_get_signalling,
1971 };
1972
1973 static struct pci_device_id sym2_id_table[] __devinitdata = {
1974         { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C810,
1975           PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
1976         { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C820,
1977           PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, /* new */
1978         { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C825,
1979           PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
1980         { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C815,
1981           PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
1982         { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C810AP,
1983           PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, /* new */
1984         { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C860,
1985           PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
1986         { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1510,
1987           PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_SCSI<<8,  0xffff00, 0UL },
1988         { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C896,
1989           PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
1990         { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C895,
1991           PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
1992         { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C885,
1993           PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
1994         { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C875,
1995           PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
1996         { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C1510,
1997           PCI_ANY_ID, PCI_ANY_ID,  PCI_CLASS_STORAGE_SCSI<<8,  0xffff00, 0UL }, /* new */
1998         { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C895A,
1999           PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2000         { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C875A,
2001           PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2002         { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1010_33,
2003           PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2004         { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1010_66,
2005           PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2006         { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C875J,
2007           PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2008         { 0, }
2009 };
2010
2011 MODULE_DEVICE_TABLE(pci, sym2_id_table);
2012
2013 static struct pci_driver sym2_driver = {
2014         .name           = NAME53C8XX,
2015         .id_table       = sym2_id_table,
2016         .probe          = sym2_probe,
2017         .remove         = __devexit_p(sym2_remove),
2018 };
2019
2020 static int __init sym2_init(void)
2021 {
2022         int error;
2023
2024         sym2_setup_params();
2025         sym2_transport_template = spi_attach_transport(&sym2_transport_functions);
2026         if (!sym2_transport_template)
2027                 return -ENODEV;
2028
2029         error = pci_register_driver(&sym2_driver);
2030         if (error)
2031                 spi_release_transport(sym2_transport_template);
2032         return error;
2033 }
2034
2035 static void __exit sym2_exit(void)
2036 {
2037         pci_unregister_driver(&sym2_driver);
2038         spi_release_transport(sym2_transport_template);
2039 }
2040
2041 module_init(sym2_init);
2042 module_exit(sym2_exit);