1 #include <linux/module.h>
2 #include <linux/delay.h>
3 #include <linux/signal.h>
4 #include <linux/sched.h>
5 #include <linux/errno.h>
7 #include <linux/string.h>
9 #include <linux/init.h>
10 #include <linux/spinlock.h>
13 #include <asm/system.h>
18 #include "constants.h"
21 /* AM53/79C974 (PCscsi) driver release 0.5
23 * The architecture and much of the code of this device
24 * driver was originally developed by Drew Eckhardt for
25 * the NCR5380. The following copyrights apply:
26 * For the architecture and all pieces of code which can also be found
27 * in the NCR5380 device driver:
28 * Copyright 1993, Drew Eckhardt
30 * (Unix and Linux consulting and custom programming)
34 * The AM53C974_nobios_detect code was originally developed by
35 * Robin Cutshaw (robin@xfree86.org) and is used here in a
36 * slightly modified form.
38 * PCI detection rewritten by Martin Mares <mj@atrey.karlin.mff.cuni.cz>
40 * For the remaining code:
41 * Copyright 1994, D. Frieauff
42 * EMail: fri@rsx42sun0.dofn.de
43 * Phone: x49-7545-8-2256 , x49-7541-42305
47 * $Log: AM53C974.c,v $
52 #ifdef AM53C974_DEBUG_KEYWAIT
53 #define KEYWAIT() AM53C974_keywait()
57 #ifdef AM53C974_DEBUG_INIT
62 #ifdef AM53C974_DEBUG_MSG
67 #ifdef AM53C974_DEB_RESEL
68 #define DEB_RESEL(x) x
72 #ifdef AM53C974_DEBUG_QUEUE
73 #define DEB_QUEUE(x) x
74 #define LIST(x,y) {printk("LINE:%d Adding %p to %p\n", __LINE__, (void*)(x), (void*)(y)); if ((x)==(y)) udelay(5); }
75 #define REMOVE(w,x,y,z) {printk("LINE:%d Removing: %p->%p %p->%p \n", __LINE__, (void*)(w), (void*)(x), (void*)(y), (void*)(z)); if ((x)==(y)) udelay(5); }
79 #define REMOVE(w,x,y,z)
81 #ifdef AM53C974_DEBUG_INFO
86 #ifdef AM53C974_DEBUG_LINKED
87 #define DEB_LINKED(x) x
91 #ifdef AM53C974_DEBUG_INTR
101 #define REMOVE(w,x,y,z)
103 #define DEB_LINKED(x)
109 #ifdef AM53C974_DEBUG_ABORT
110 #define DEB_ABORT(x) x
115 #ifdef VERBOSE_AM53C974_DEBUG
121 #define INSIDE(x,l,h) ( ((x) >= (l)) && ((x) <= (h)) )
124 #include <scsi/scsicam.h>
126 /***************************************************************************************
127 * Default setting of the controller's SCSI id. Edit and uncomment this only if your *
128 * BIOS does not correctly initialize the controller's SCSI id. *
129 * If you don't get a warning during boot, it is correctly initialized. *
130 ****************************************************************************************/
131 /* #define AM53C974_SCSI_ID 7 */
133 /***************************************************************************************
134 * Default settings for sync. negotiation enable, transfer rate and sync. offset. *
135 * These settings can be replaced by LILO overrides (append) with the following syntax: *
136 * AM53C974=host-scsi-id, target-scsi-id, max-rate, max-offset *
137 * Sync. negotiation is disabled by default and will be enabled for those targets which *
138 * are specified in the LILO override *
139 ****************************************************************************************/
140 #define DEFAULT_SYNC_NEGOTIATION_ENABLED 0 /* 0 or 1 */
141 #define DEFAULT_RATE 5 /* MHz, min: 3; max: 10 */
142 #define DEFAULT_SYNC_OFFSET 0 /* bytes, min: 0; max: 15; use 0 for async. mode */
144 /***************************************************************************************
145 * If defined, don't allow targets to disconnect during commands. This will reduce *
146 * performance, but may be worthwhile if you suspect the driver of corrupting data when *
147 * a disconnect happens. *
148 ***************************************************************************************/
149 #define AM53C974_PROHIBIT_DISCONNECT
151 /* --------------------- don't edit below here --------------------- */
153 #define AM53C974_DRIVER_REVISION_MAJOR 0
154 #define AM53C974_DRIVER_REVISION_MINOR 5
155 #define SEPARATOR_LINE \
156 "--------------------------------------------------------------------------\n"
159 /* #define AM53C974_DEBUG */
160 /* #define AM53C974_DEBUG_MSG */
161 /* #define AM53C974_DEBUG_KEYWAIT */
162 /* #define AM53C974_DEBUG_INIT */
163 /* #define AM53C974_DEBUG_QUEUE */
164 /* #define AM53C974_DEBUG_INFO */
165 /* #define AM53C974_DEBUG_LINKED */
166 /* #define VERBOSE_AM53C974_DEBUG */
167 /* #define AM53C974_DEBUG_INTR */
168 /* #define AM53C974_DEB_RESEL */
169 #define AM53C974_DEBUG_ABORT
170 /* #define AM53C974_OPTION_DEBUG_PROBE_ONLY */
172 /* special options/constants */
173 #define DEF_CLK 40 /* chip clock freq. in MHz */
174 #define MIN_PERIOD 4 /* for negotiation: min. number of clocks per cycle */
175 #define MAX_PERIOD 13 /* for negotiation: max. number of clocks per cycle */
176 #define MAX_OFFSET 15 /* for negotiation: max. offset (0=async) */
178 #define DEF_SCSI_TIMEOUT 245 /* STIMREG value, 40 Mhz */
179 #define DEF_STP 8 /* STPREG value assuming 5.0 MB/sec, FASTCLK, FASTSCSI */
180 #define DEF_SOF_RAD 0 /* REQ/ACK deassertion delay */
181 #define DEF_SOF_RAA 0 /* REQ/ACK assertion delay */
182 #define DEF_ETM 0 /* CNTLREG1, ext. timing mode */
183 #define DEF_PERE 1 /* CNTLREG1, parity error reporting */
184 #define DEF_CLKF 0 /* CLKFREG, 0=40 Mhz */
185 #define DEF_ENF 1 /* CNTLREG2, enable features */
186 #define DEF_ADIDCHK 0 /* CNTLREG3, additional ID check */
187 #define DEF_FASTSCSI 1 /* CNTLREG3, fast SCSI */
188 #define DEF_FASTCLK 1 /* CNTLREG3, fast clocking, 5 MB/sec at 40MHz chip clk */
189 #define DEF_GLITCH 1 /* CNTLREG4, glitch eater, 0=12ns, 1=35ns, 2=25ns, 3=off */
190 #define DEF_PWD 0 /* CNTLREG4, reduced power feature */
191 #define DEF_RAE 0 /* CNTLREG4, RAE active negation on REQ, ACK only */
192 #define DEF_RADE 1 /* 1CNTLREG4, active negation on REQ, ACK and data */
195 #define CTCLREG 0x00 /* r current transf. count, low byte */
196 #define CTCMREG 0x04 /* r current transf. count, middle byte */
197 #define CTCHREG 0x38 /* r current transf. count, high byte */
198 #define STCLREG 0x00 /* w start transf. count, low byte */
199 #define STCMREG 0x04 /* w start transf. count, middle byte */
200 #define STCHREG 0x38 /* w start transf. count, high byte */
201 #define FFREG 0x08 /* rw SCSI FIFO reg. */
202 #define STIMREG 0x14 /* w SCSI timeout reg. */
204 #define SDIDREG 0x10 /* w SCSI destination ID reg. */
205 #define SDIREG_MASK 0x07 /* mask */
207 #define STPREG 0x18 /* w synchronous transf. period reg. */
208 #define STPREG_STP 0x1F /* synchr. transfer period */
210 #define CLKFREG 0x24 /* w clock factor reg. */
211 #define CLKFREG_MASK 0x07 /* mask */
213 #define CMDREG 0x0C /* rw SCSI command reg. */
214 #define CMDREG_DMA 0x80 /* set DMA mode (set together with opcodes below) */
215 #define CMDREG_IT 0x10 /* information transfer */
216 #define CMDREG_ICCS 0x11 /* initiator command complete steps */
217 #define CMDREG_MA 0x12 /* message accepted */
218 #define CMDREG_TPB 0x98 /* transfer pad bytes, DMA mode only */
219 #define CMDREG_SATN 0x1A /* set ATN */
220 #define CMDREG_RATN 0x1B /* reset ATN */
221 #define CMDREG_SOAS 0x41 /* select without ATN steps */
222 #define CMDREG_SAS 0x42 /* select with ATN steps (1 msg byte) */
223 #define CMDREG_SASS 0x43 /* select with ATN and stop steps */
224 #define CMDREG_ESR 0x44 /* enable selection/reselection */
225 #define CMDREG_DSR 0x45 /* disable selection/reselection */
226 #define CMDREG_SA3S 0x46 /* select with ATN 3 steps (3 msg bytes) */
227 #define CMDREG_NOP 0x00 /* no operation */
228 #define CMDREG_CFIFO 0x01 /* clear FIFO */
229 #define CMDREG_RDEV 0x02 /* reset device */
230 #define CMDREG_RBUS 0x03 /* reset SCSI bus */
232 #define STATREG 0x10 /* r SCSI status reg. */
233 #define STATREG_INT 0x80 /* SCSI interrupt condition detected */
234 #define STATREG_IOE 0x40 /* SCSI illegal operation error detected */
235 #define STATREG_PE 0x20 /* SCSI parity error detected */
236 #define STATREG_CTZ 0x10 /* CTC reg decremented to zero */
237 #define STATREG_MSG 0x04 /* SCSI MSG phase (latched?) */
238 #define STATREG_CD 0x02 /* SCSI C/D phase (latched?) */
239 #define STATREG_IO 0x01 /* SCSI I/O phase (latched?) */
240 #define STATREG_PHASE 0x07 /* SCSI phase mask */
242 #define INSTREG 0x14 /* r interrupt status reg. */
243 #define INSTREG_SRST 0x80 /* SCSI reset detected */
244 #define INSTREG_ICMD 0x40 /* SCSI invalid command detected */
245 #define INSTREG_DIS 0x20 /* target disconnected or sel/resel timeout */
246 #define INSTREG_SR 0x10 /* device on bus has service request */
247 #define INSTREG_SO 0x08 /* successful operation */
248 #define INSTREG_RESEL 0x04 /* device reselected as initiator */
250 #define ISREG 0x18 /* r internal state reg. */
251 #define ISREG_SOF 0x08 /* synchronous offset flag (act. low) */
252 #define ISREG_IS 0x07 /* status of intermediate op. */
253 #define ISREG_OK_NO_STOP 0x04 /* selection successful */
254 #define ISREG_OK_STOP 0x01 /* selection successful */
256 #define CFIREG 0x1C /* r current FIFO/internal state reg. */
257 #define CFIREG_IS 0xE0 /* status of intermediate op. */
258 #define CFIREG_CF 0x1F /* number of bytes in SCSI FIFO */
260 #define SOFREG 0x1C /* w synchr. offset reg. */
261 #define SOFREG_RAD 0xC0 /* REQ/ACK deassertion delay (sync.) */
262 #define SOFREG_RAA 0x30 /* REQ/ACK assertion delay (sync.) */
263 #define SOFREG_SO 0x0F /* synch. offset (sync.) */
265 #define CNTLREG1 0x20 /* rw control register one */
266 #define CNTLREG1_ETM 0x80 /* set extended timing mode */
267 #define CNTLREG1_DISR 0x40 /* disable interrupt on SCSI reset */
268 #define CNTLREG1_PERE 0x10 /* enable parity error reporting */
269 #define CNTLREG1_SID 0x07 /* host adapter SCSI ID */
271 #define CNTLREG2 0x2C /* rw control register two */
272 #define CNTLREG2_ENF 0x40 /* enable features */
274 #define CNTLREG3 0x30 /* rw control register three */
275 #define CNTLREG3_ADIDCHK 0x80 /* additional ID check */
276 #define CNTLREG3_FASTSCSI 0x10 /* fast SCSI */
277 #define CNTLREG3_FASTCLK 0x08 /* fast SCSI clocking */
279 #define CNTLREG4 0x34 /* rw control register four */
280 #define CNTLREG4_GLITCH 0xC0 /* glitch eater */
281 #define CNTLREG4_PWD 0x20 /* reduced power feature */
282 #define CNTLREG4_RAE 0x08 /* write only, active negot. ctrl. */
283 #define CNTLREG4_RADE 0x04 /* active negot. ctrl. */
284 #define CNTLREG4_RES 0x10 /* reserved bit, must be 1 */
287 #define DMACMD 0x40 /* rw command */
288 #define DMACMD_DIR 0x80 /* transfer direction (1=read from device) */
289 #define DMACMD_INTE_D 0x40 /* DMA transfer interrupt enable */
290 #define DMACMD_INTE_P 0x20 /* page transfer interrupt enable */
291 #define DMACMD_MDL 0x10 /* map to memory descriptor list */
292 #define DMACMD_DIAG 0x04 /* diagnostics, set to 0 */
293 #define DMACMD_IDLE 0x00 /* idle cmd */
294 #define DMACMD_BLAST 0x01 /* flush FIFO to memory */
295 #define DMACMD_ABORT 0x02 /* terminate DMA */
296 #define DMACMD_START 0x03 /* start DMA */
298 #define DMASTATUS 0x54 /* r status register */
299 #define DMASTATUS_BCMPLT 0x20 /* BLAST complete */
300 #define DMASTATUS_SCSIINT 0x10 /* SCSI interrupt pending */
301 #define DMASTATUS_DONE 0x08 /* DMA transfer terminated */
302 #define DMASTATUS_ABORT 0x04 /* DMA transfer aborted */
303 #define DMASTATUS_ERROR 0x02 /* DMA transfer error */
304 #define DMASTATUS_PWDN 0x02 /* power down indicator */
306 #define DMASTC 0x44 /* rw starting transfer count */
307 #define DMASPA 0x48 /* rw starting physical address */
308 #define DMAWBC 0x4C /* r working byte counter */
309 #define DMAWAC 0x50 /* r working address counter */
310 #define DMASMDLA 0x58 /* rw starting MDL address */
311 #define DMAWMAC 0x5C /* r working MDL counter */
313 /*** SCSI phases ***/
314 #define PHASE_MSGIN 0x07
315 #define PHASE_MSGOUT 0x06
316 #define PHASE_RES_1 0x05
317 #define PHASE_RES_0 0x04
318 #define PHASE_STATIN 0x03
319 #define PHASE_CMDOUT 0x02
320 #define PHASE_DATAIN 0x01
321 #define PHASE_DATAOUT 0x00
324 #define AM53C974_local_declare() unsigned long io_port
325 #define AM53C974_setio(instance) io_port = instance->io_port
326 #define AM53C974_read_8(addr) inb(io_port + (addr))
327 #define AM53C974_write_8(addr,x) outb((x), io_port + (addr))
328 #define AM53C974_read_16(addr) inw(io_port + (addr))
329 #define AM53C974_write_16(addr,x) outw((x), io_port + (addr))
330 #define AM53C974_read_32(addr) inl(io_port + (addr))
331 #define AM53C974_write_32(addr,x) outl((x), io_port + (addr))
333 #define AM53C974_poll_int() { do { statreg = AM53C974_read_8(STATREG); } \
334 while (!(statreg & STATREG_INT)) ; \
335 AM53C974_read_8(INSTREG) ; } /* clear int */
336 #define AM53C974_cfifo() (AM53C974_read_8(CFIREG) & CFIREG_CF)
338 /* These are "special" values for the tag parameter passed to AM53C974_select. */
339 #define TAG_NEXT -1 /* Use next free tag */
340 #define TAG_NONE -2 /* Establish I_T_L nexus instead of I_T_L_Q
341 * even on SCSI-II devices */
343 /************ LILO overrides *************/
344 typedef struct _override_t {
345 int host_scsi_id; /* SCSI id of the bus controller */
346 int target_scsi_id; /* SCSI id of target */
347 int max_rate; /* max. transfer rate */
348 int max_offset; /* max. sync. offset, 0 = asynchronous */
352 #ifdef AM53C974_DEBUG
353 static void AM53C974_print_phase(struct Scsi_Host *instance);
354 static void AM53C974_print_queues(struct Scsi_Host *instance);
355 #endif /* AM53C974_DEBUG */
356 static void AM53C974_print(struct Scsi_Host *instance);
357 static void AM53C974_keywait(void);
358 static __inline__ int AM53C974_pci_detect(Scsi_Host_Template * tpnt);
359 static int AM53C974_init(Scsi_Host_Template * tpnt, struct pci_dev *pdev);
360 static void AM53C974_config_after_reset(struct Scsi_Host *instance);
361 static __inline__ void initialize_SCp(Scsi_Cmnd * cmd);
362 static __inline__ void run_main(void);
363 static void AM53C974_main(void);
364 static void AM53C974_intr(int irq, void *dev_id, struct pt_regs *regs);
365 static void do_AM53C974_intr(int irq, void *dev_id, struct pt_regs *regs);
366 static void AM53C974_intr_disconnect(struct Scsi_Host *instance);
367 static int AM53C974_sync_neg(struct Scsi_Host *instance, int target, unsigned char *msg);
368 static __inline__ void AM53C974_set_async(struct Scsi_Host *instance, int target);
369 static __inline__ void AM53C974_set_sync(struct Scsi_Host *instance, int target);
370 static void AM53C974_information_transfer(struct Scsi_Host *instance,
371 unsigned char statreg, unsigned char isreg,
372 unsigned char instreg, unsigned char cfifo,
373 unsigned char dmastatus);
374 static int AM53C974_message(struct Scsi_Host *instance, Scsi_Cmnd * cmd, unsigned char msg);
375 static void AM53C974_select(struct Scsi_Host *instance, Scsi_Cmnd * cmd, int tag);
376 static void AM53C974_intr_reselect(struct Scsi_Host *instance, unsigned char statreg);
377 static __inline__ void AM53C974_transfer_dma(struct Scsi_Host *instance, short dir,
378 unsigned long length, char *data);
379 static void AM53C974_dma_blast(struct Scsi_Host *instance, unsigned char dmastatus,
380 unsigned char statreg);
381 static void AM53C974_intr_bus_reset(struct Scsi_Host *instance);
383 static struct Scsi_Host *first_instance;
384 static Scsi_Host_Template *the_template;
385 static struct Scsi_Host *first_host; /* Head of list of AMD boards */
386 static volatile int main_running;
387 static int commandline_current;
388 override_t overrides[7] =
390 {-1, 0, 0, 0},}; /* LILO overrides */
392 #ifdef AM53C974_DEBUG
393 static int deb_stop = 1;
401 PHASE_DATAOUT, "DATAOUT"
403 PHASE_DATAIN, "DATAIN"
405 PHASE_CMDOUT, "CMDOUT"
408 PHASE_STATIN, "STATIN"
410 PHASE_MSGOUT, "MSGOUT"
415 PHASE_RES_0, "RESERVED 0"
417 PHASE_RES_1, "RESERVED 1"
421 /**************************************************************************
422 * Function : void AM53C974_print_phase(struct Scsi_Host *instance)
424 * Purpose : print the current SCSI phase for debugging purposes
426 * Input : instance - which AM53C974
427 **************************************************************************/
428 static void AM53C974_print_phase(struct Scsi_Host *instance)
430 AM53C974_local_declare();
431 unsigned char statreg, latched;
433 AM53C974_setio(instance);
435 latched = (AM53C974_read_8(CNTLREG2)) & CNTLREG2_ENF;
436 statreg = AM53C974_read_8(STATREG);
437 for (i = 0; (phases[i].value != PHASE_RES_1) &&
438 (phases[i].value != (statreg & STATREG_PHASE)); ++i);
440 printk("scsi%d : phase %s, latched at end of last command\n", instance->host_no, phases[i].name);
442 printk("scsi%d : phase %s, real time\n", instance->host_no, phases[i].name);
445 /**************************************************************************
446 * Function : void AM53C974_print_queues(struct Scsi_Host *instance)
448 * Purpose : print commands in the various queues
450 * Inputs : instance - which AM53C974
451 **************************************************************************/
452 static void AM53C974_print_queues(struct Scsi_Host *instance)
455 struct AM53C974_hostdata *hostdata = (struct AM53C974_hostdata *) instance->hostdata;
458 printk("AM53C974: coroutine is%s running.\n", main_running ? "" : "n't");
463 if (!hostdata->connected) {
464 printk("scsi%d: no currently connected command\n", instance->host_no);
466 print_Scsi_Cmnd((Scsi_Cmnd *) hostdata->connected);
468 if (!hostdata->sel_cmd) {
469 printk("scsi%d: no currently arbitrating command\n", instance->host_no);
471 print_Scsi_Cmnd((Scsi_Cmnd *) hostdata->sel_cmd);
474 printk("scsi%d: issue_queue ", instance->host_no);
475 if (!hostdata->issue_queue)
479 for (ptr = (Scsi_Cmnd *) hostdata->issue_queue; ptr; ptr = (Scsi_Cmnd *) ptr->host_scribble)
480 print_Scsi_Cmnd(ptr);
483 printk("scsi%d: disconnected_queue ", instance->host_no);
484 if (!hostdata->disconnected_queue)
488 for (ptr = (Scsi_Cmnd *) hostdata->disconnected_queue; ptr; ptr = (Scsi_Cmnd *) ptr->host_scribble)
489 print_Scsi_Cmnd(ptr);
492 restore_flags(flags);
495 #endif /* AM53C974_DEBUG */
497 /**************************************************************************
498 * Function : void AM53C974_print(struct Scsi_Host *instance)
500 * Purpose : dump the chip registers for debugging purposes
502 * Input : instance - which AM53C974
503 **************************************************************************/
504 static void AM53C974_print(struct Scsi_Host *instance)
506 AM53C974_local_declare();
508 unsigned long ctcreg, dmastc, dmaspa, dmawbc, dmawac;
509 unsigned char cmdreg, statreg, isreg, cfireg, cntlreg[4], dmacmd,
511 AM53C974_setio(instance);
515 ctcreg = AM53C974_read_8(CTCHREG) << 16;
516 ctcreg |= AM53C974_read_8(CTCMREG) << 8;
517 ctcreg |= AM53C974_read_8(CTCLREG);
518 cmdreg = AM53C974_read_8(CMDREG);
519 statreg = AM53C974_read_8(STATREG);
520 isreg = AM53C974_read_8(ISREG);
521 cfireg = AM53C974_read_8(CFIREG);
522 cntlreg[0] = AM53C974_read_8(CNTLREG1);
523 cntlreg[1] = AM53C974_read_8(CNTLREG2);
524 cntlreg[2] = AM53C974_read_8(CNTLREG3);
525 cntlreg[3] = AM53C974_read_8(CNTLREG4);
526 dmacmd = AM53C974_read_8(DMACMD);
527 dmastc = AM53C974_read_32(DMASTC);
528 dmaspa = AM53C974_read_32(DMASPA);
529 dmawbc = AM53C974_read_32(DMAWBC);
530 dmawac = AM53C974_read_32(DMAWAC);
531 dmastatus = AM53C974_read_8(DMASTATUS);
532 restore_flags(flags);
534 printk("AM53C974 register dump:\n");
535 printk("IO base: 0x%04lx; CTCREG: 0x%04lx; CMDREG: 0x%02x; STATREG: 0x%02x; ISREG: 0x%02x\n",
536 io_port, ctcreg, cmdreg, statreg, isreg);
537 printk("CFIREG: 0x%02x; CNTLREG1-4: 0x%02x; 0x%02x; 0x%02x; 0x%02x\n",
538 cfireg, cntlreg[0], cntlreg[1], cntlreg[2], cntlreg[3]);
539 printk("DMACMD: 0x%02x; DMASTC: 0x%04lx; DMASPA: 0x%04lx\n", dmacmd, dmastc, dmaspa);
540 printk("DMAWBC: 0x%04lx; DMAWAC: 0x%04lx; DMASTATUS: 0x%02x\n", dmawbc, dmawac, dmastatus);
541 printk("---------------------------------------------------------\n");
544 /**************************************************************************
545 * Function : void AM53C974_keywait(void)
547 * Purpose : wait until a key is pressed, if it was the 'r' key leave singlestep mode;
548 * this function is used for debugging only
551 **************************************************************************/
552 static void AM53C974_keywait(void)
555 #ifdef AM53C974_DEBUG
564 while ((inb_p(0x64) & 0x01) != 0x01);
565 #ifdef AM53C974_DEBUG
568 deb_stop = 0; /* don't stop if 'r' was pressed */
570 restore_flags(flags);
574 /**************************************************************************
575 * Function : AM53C974_setup(char *str)
577 * Purpose : LILO command line initialization of the overrides array,
579 * Input : str - parameter string.
583 * NOTE : this function needs to be declared as an external function
584 * in init/main.c and included there in the bootsetups list
585 ***************************************************************************/
586 static int AM53C974_setup(char *str)
590 get_options(str, ARRAY_SIZE(ints), ints);
593 printk("AM53C974_setup: wrong number of parameters;\n correct syntax is: AM53C974=host-scsi-id, target-scsi-id, max-rate, max-offset\n");
595 if (commandline_current < (sizeof(overrides) / sizeof(override_t))) {
596 if ((ints[1] < 0) || (ints[1] > 7) ||
597 (ints[2] < 0) || (ints[2] > 7) ||
598 (ints[1] == ints[2]) ||
599 (ints[3] < (DEF_CLK / MAX_PERIOD)) || (ints[3] > (DEF_CLK / MIN_PERIOD)) ||
600 (ints[4] < 0) || (ints[4] > MAX_OFFSET))
601 printk("AM53C974_setup: illegal parameter\n");
603 overrides[commandline_current].host_scsi_id = ints[1];
604 overrides[commandline_current].target_scsi_id = ints[2];
605 overrides[commandline_current].max_rate = ints[3];
606 overrides[commandline_current].max_offset = ints[4];
607 commandline_current++;
610 printk("AM53C974_setup: too many overrides\n");
615 __setup("AM53C974=", AM53C974_setup);
619 /**************************************************************************
620 * Function : int AM53C974_pci_detect(Scsi_Host_Template *tpnt)
622 * Purpose : detects and initializes AM53C974 SCSI chips with PCI Bios
624 * Inputs : tpnt - host template
626 * Returns : number of host adapters detected
627 **************************************************************************/
628 static int __init AM53C974_pci_detect(Scsi_Host_Template * tpnt)
630 int count = 0; /* number of boards detected */
631 struct pci_dev *pdev = NULL;
632 unsigned short command;
634 while ((pdev = pci_find_device(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_SCSI, pdev))) {
635 if (pci_enable_device(pdev))
637 pci_read_config_word(pdev, PCI_COMMAND, &command);
639 /* check whether device is I/O mapped -- should be */
640 if (!(command & PCI_COMMAND_IO))
643 pci_set_master (pdev);
645 /* everything seems OK now, so initialize */
646 if (AM53C974_init(tpnt, pdev))
652 /**************************************************************************
653 * Function : int AM53C974_init(Scsi_Host_Template *tpnt, struct pci_dev *pdev)
655 * Purpose : initializes instance and corresponding AM53/79C974 chip,
657 * Inputs : tpnt - template, pci_config - PCI configuration,
659 * Returns : 1 on success, 0 on failure.
661 * NOTE: If no override for the controller's SCSI id is given and AM53C974_SCSI_ID
662 * is not defined we assume that the SCSI address of this controller is correctly
663 * set up by the BIOS (as reflected by contents of register CNTLREG1).
664 * This is the only BIOS assistance we need.
665 **************************************************************************/
666 static int __init AM53C974_init(Scsi_Host_Template * tpnt, struct pci_dev *pdev)
668 AM53C974_local_declare();
670 struct Scsi_Host *instance, *search;
671 struct AM53C974_hostdata *hostdata;
673 #ifdef AM53C974_OPTION_DEBUG_PROBE_ONLY
674 printk("AM53C974: probe only enabled, aborting initialization\n");
678 instance = scsi_register(tpnt, sizeof(struct AM53C974_hostdata));
680 printk(KERN_WARNING "AM53C974: Unable to register host, aborting.\n");
683 scsi_set_pci_device(instance, pdev);
684 hostdata = (struct AM53C974_hostdata *) instance->hostdata;
686 instance->io_port = pci_resource_start(pdev, 0);
687 instance->irq = pdev->irq;
688 instance->dma_channel = -1;
689 AM53C974_setio(instance);
691 #ifdef AM53C974_SCSI_ID
692 instance->this_id = AM53C974_SCSI_ID;
693 AM53C974_write_8(CNTLREG1, instance->this_id & CNTLREG1_SID);
695 instance->this_id = AM53C974_read_8(CNTLREG1) & CNTLREG1_SID;
696 if (instance->this_id != 7)
697 printk("scsi%d: WARNING: unusual hostadapter SCSI id %d; please verify!\n",
698 instance->host_no, instance->this_id);
701 for (i = 0; i < sizeof(hostdata->msgout); i++) {
702 hostdata->msgout[i] = NOP;
703 hostdata->last_message[i] = NOP;
705 for (i = 0; i < 8; i++) {
706 hostdata->busy[i] = 0;
707 hostdata->sync_per[i] = DEF_STP;
708 hostdata->sync_off[i] = 0;
709 hostdata->sync_neg[i] = 0;
710 hostdata->sync_en[i] = DEFAULT_SYNC_NEGOTIATION_ENABLED;
711 hostdata->max_rate[i] = DEFAULT_RATE;
712 hostdata->max_offset[i] = DEFAULT_SYNC_OFFSET;
715 /* overwrite defaults by LILO overrides */
716 for (i = 0; i < commandline_current; i++) {
717 if (overrides[i].host_scsi_id == instance->this_id) {
718 j = overrides[i].target_scsi_id;
719 hostdata->sync_en[j] = 1;
720 hostdata->max_rate[j] = overrides[i].max_rate;
721 hostdata->max_offset[j] = overrides[i].max_offset;
725 hostdata->sel_cmd = NULL;
726 hostdata->connected = NULL;
727 hostdata->issue_queue = NULL;
728 hostdata->disconnected_queue = NULL;
729 hostdata->in_reset = 0;
730 hostdata->aborted = 0;
731 hostdata->selecting = 0;
732 hostdata->disconnecting = 0;
733 hostdata->dma_busy = 0;
735 /* Set up an interrupt handler if we aren't already sharing an IRQ with another board */
736 for (search = first_host;
737 search && (((the_template != NULL) && (search->hostt != the_template)) ||
738 (search->irq != instance->irq) || (search == instance));
739 search = search->next);
741 if (request_irq(instance->irq, do_AM53C974_intr, SA_SHIRQ, "AM53C974", instance)) {
742 printk("scsi%d: IRQ%d not free, detaching\n", instance->host_no, instance->irq);
743 scsi_unregister(instance);
747 printk("scsi%d: using interrupt handler previously installed for scsi%d\n",
748 instance->host_no, search->host_no);
752 the_template = instance->hostt;
753 first_instance = instance;
756 AM53C974_write_8(CMDREG, CMDREG_RDEV); /* reset device */
758 AM53C974_write_8(CMDREG, CMDREG_NOP);
759 AM53C974_write_8(CNTLREG1, CNTLREG1_DISR | instance->this_id);
760 AM53C974_write_8(CMDREG, CMDREG_RBUS); /* reset SCSI bus */
762 AM53C974_config_after_reset(instance);
767 /*********************************************************************
768 * Function : AM53C974_config_after_reset(struct Scsi_Host *instance) *
770 * Purpose : initializes chip registers after reset *
772 * Inputs : instance - which AM53C974 *
774 * Returns : nothing *
775 **********************************************************************/
776 static void AM53C974_config_after_reset(struct Scsi_Host *instance)
778 AM53C974_local_declare();
779 AM53C974_setio(instance);
781 /* clear SCSI FIFO */
782 AM53C974_write_8(CMDREG, CMDREG_CFIFO);
784 /* configure device */
785 AM53C974_write_8(STIMREG, DEF_SCSI_TIMEOUT);
786 AM53C974_write_8(STPREG, DEF_STP & STPREG_STP);
787 AM53C974_write_8(SOFREG, (DEF_SOF_RAD << 6) | (DEF_SOF_RAA << 4));
788 AM53C974_write_8(CLKFREG, DEF_CLKF & CLKFREG_MASK);
789 AM53C974_write_8(CNTLREG1, (DEF_ETM << 7) | CNTLREG1_DISR | (DEF_PERE << 4) | instance->this_id);
790 AM53C974_write_8(CNTLREG2, (DEF_ENF << 6));
791 AM53C974_write_8(CNTLREG3, (DEF_ADIDCHK << 7) | (DEF_FASTSCSI << 4) | (DEF_FASTCLK << 3));
792 AM53C974_write_8(CNTLREG4, (DEF_GLITCH << 6) | (DEF_PWD << 5) | (DEF_RAE << 3) | (DEF_RADE << 2) | CNTLREG4_RES);
795 /***********************************************************************
796 * Function : const char *AM53C974_info(struct Scsi_Host *instance) *
798 * Purpose : return device driver information *
800 * Inputs : instance - which AM53C974 *
802 * Returns : info string *
803 ************************************************************************/
804 static const char *AM53C974_info(struct Scsi_Host *instance)
806 static char info[100];
808 sprintf(info, "AM53/79C974 PCscsi driver rev. %d.%d; host I/O address: 0x%lx; irq: %d\n",
809 AM53C974_DRIVER_REVISION_MAJOR, AM53C974_DRIVER_REVISION_MINOR,
810 instance->io_port, instance->irq);
814 /**************************************************************************
815 * Function : int AM53C974_command (Scsi_Cmnd *SCpnt) *
817 * Purpose : the unqueued SCSI command function, replaced by the *
818 * AM53C974_queue_command function *
820 * Inputs : SCpnt - pointer to command structure *
822 * Returns :status, see hosts.h for details *
823 ***************************************************************************/
824 static int AM53C974_command(Scsi_Cmnd * SCpnt)
826 DEB(printk("AM53C974_command called\n"));
830 /**************************************************************************
831 * Function : void initialize_SCp(Scsi_Cmnd *cmd) *
833 * Purpose : initialize the saved data pointers for cmd to point to the *
834 * start of the buffer. *
836 * Inputs : cmd - Scsi_Cmnd structure to have pointers reset. *
838 * Returns : nothing *
839 **************************************************************************/
840 static __inline__ void initialize_SCp(Scsi_Cmnd * cmd)
843 cmd->SCp.buffer = (struct scatterlist *) cmd->buffer;
844 cmd->SCp.buffers_residual = cmd->use_sg - 1;
845 cmd->SCp.ptr = (char *) cmd->SCp.buffer->address;
846 cmd->SCp.this_residual = cmd->SCp.buffer->length;
848 cmd->SCp.buffer = NULL;
849 cmd->SCp.buffers_residual = 0;
850 cmd->SCp.ptr = (char *) cmd->request_buffer;
851 cmd->SCp.this_residual = cmd->request_bufflen;
855 /**************************************************************************
856 * Function : run_main(void) *
858 * Purpose : insure that the coroutine is running and will process our *
859 * request. main_running is checked/set here (in an inline *
860 * function rather than in AM53C974_main itself to reduce the *
861 * chances of stack overflow. *
866 * Returns : nothing *
867 **************************************************************************/
868 static __inline__ void run_main(void)
874 /* main_running is cleared in AM53C974_main once it can't do
875 more work, and AM53C974_main exits with interrupts disabled. */
879 restore_flags(flags);
882 /**************************************************************************
883 * Function : int AM53C974_queue_command(Scsi_Cmnd *cmd, void (*done)(Scsi_Cmnd *))
885 * Purpose : writes SCSI command into AM53C974 FIFO
887 * Inputs : cmd - SCSI command, done - function called on completion, with
888 * a pointer to the command descriptor.
890 * Returns : status, see hosts.h for details
893 * cmd is added to the per instance issue_queue, with minor
894 * twiddling done to the host specific fields of cmd. If the
895 * main coroutine is not running, it is restarted.
896 **************************************************************************/
897 static int AM53C974_queue_command(Scsi_Cmnd * cmd, void (*done) (Scsi_Cmnd *))
900 struct Scsi_Host *instance = cmd->host;
901 struct AM53C974_hostdata *hostdata = (struct AM53C974_hostdata *) instance->hostdata;
906 DEB_QUEUE(printk(SEPARATOR_LINE));
907 DEB_QUEUE(printk("scsi%d: AM53C974_queue_command called\n", instance->host_no));
908 DEB_QUEUE(printk("cmd=%02x target=%02x lun=%02x bufflen=%d use_sg = %02x\n",
909 cmd->cmnd[0], cmd->target, cmd->lun, cmd->request_bufflen, cmd->use_sg));
911 /* We use the host_scribble field as a pointer to the next command in a queue */
912 cmd->host_scribble = NULL;
913 cmd->scsi_done = done;
915 cmd->device->disconnect = 0;
917 /* Insert the cmd into the issue queue. Note that REQUEST SENSE
918 * commands are added to the head of the queue since any command will
919 * clear the contingent allegiance condition that exists and the
920 * sense data is only guaranteed to be valid while the condition exists. */
921 if (!(hostdata->issue_queue) || (cmd->cmnd[0] == REQUEST_SENSE)) {
922 LIST(cmd, hostdata->issue_queue);
923 cmd->host_scribble = (unsigned char *) hostdata->issue_queue;
924 hostdata->issue_queue = cmd;
926 for (tmp = (Scsi_Cmnd *) hostdata->issue_queue; tmp->host_scribble;
927 tmp = (Scsi_Cmnd *) tmp->host_scribble);
929 tmp->host_scribble = (unsigned char *) cmd;
932 DEB_QUEUE(printk("scsi%d : command added to %s of queue\n", instance->host_no,
933 (cmd->cmnd[0] == REQUEST_SENSE) ? "head" : "tail"));
935 /* Run the coroutine if it isn't already running. */
937 restore_flags(flags);
941 /**************************************************************************
942 * Function : AM53C974_main (void)
944 * Purpose : AM53C974_main is a coroutine that runs as long as more work can
945 * be done on the AM53C974 host adapters in a system. Both
946 * AM53C974_queue_command() and AM53C974_intr() will try to start it
947 * in case it is not running.
949 * NOTE : AM53C974_main exits with interrupts *disabled*, the caller should
950 * reenable them. This prevents reentrancy and kernel stack overflow.
951 **************************************************************************/
952 static void AM53C974_main(void)
954 AM53C974_local_declare();
956 Scsi_Cmnd *tmp, *prev;
957 struct Scsi_Host *instance;
958 struct AM53C974_hostdata *hostdata;
961 /* We run (with interrupts disabled) until we're sure that none of
962 * the host adapters have anything that can be done, at which point
963 * we set main_running to 0 and exit. */
966 cli(); /* Freeze request queues */
969 for (instance = first_instance; instance && instance->hostt == the_template;
970 instance = instance->next) {
971 hostdata = (struct AM53C974_hostdata *) instance->hostdata;
972 AM53C974_setio(instance);
973 /* start to select target if we are not connected and not in the
975 if (!hostdata->connected && !hostdata->sel_cmd) {
976 /* Search through the issue_queue for a command destined for a target
978 for (tmp = (Scsi_Cmnd *) hostdata->issue_queue, prev = NULL; tmp;
979 prev = tmp, tmp = (Scsi_Cmnd *) tmp->host_scribble) {
980 /* When we find one, remove it from the issue queue. */
981 if (!(hostdata->busy[tmp->target] & (1 << tmp->lun))) {
983 REMOVE(prev, (Scsi_Cmnd *) (prev->host_scribble), tmp,
984 (Scsi_Cmnd *) (tmp->host_scribble));
985 prev->host_scribble = tmp->host_scribble;
987 REMOVE(-1, hostdata->issue_queue, tmp, tmp->host_scribble);
988 hostdata->issue_queue = (Scsi_Cmnd *) tmp->host_scribble;
990 tmp->host_scribble = NULL;
992 /* go into selection mode, disable reselection and wait for
993 SO interrupt which will continue with the selection process */
994 hostdata->selecting = 1;
995 hostdata->sel_cmd = tmp;
996 AM53C974_write_8(CMDREG, CMDREG_DSR);
998 } /* if target/lun is not busy */
1001 /* if (!hostdata->connected) */
1003 DEB(printk("main: connected; cmd = 0x%lx, sel_cmd = 0x%lx\n",
1004 (long) hostdata->connected, (long) hostdata->sel_cmd));
1006 } /* for instance */
1009 restore_flags(flags);
1012 /************************************************************************
1013 * Function : AM53C974_intr(int irq, void *dev_id, struct pt_regs *regs) *
1015 * Purpose : interrupt handler *
1017 * Inputs : irq - interrupt line, regs - ? *
1019 * Returns : nothing *
1020 ************************************************************************/
1021 static void do_AM53C974_intr(int irq, void *dev_id, struct pt_regs *regs)
1023 unsigned long flags;
1025 spin_lock_irqsave(&io_request_lock, flags);
1026 AM53C974_intr(irq, dev_id, regs);
1027 spin_unlock_irqrestore(&io_request_lock, flags);
1030 /**************************************************************************
1031 * Function : AM53C974_set_async(struct Scsi_Host *instance, int target)
1033 * Purpose : put controller into async. mode
1035 * Inputs : instance -- which AM53C974
1036 * target -- which SCSI target to deal with
1039 **************************************************************************/
1040 static __inline__ void AM53C974_set_async(struct Scsi_Host *instance, int target)
1042 AM53C974_local_declare();
1043 struct AM53C974_hostdata *hostdata = (struct AM53C974_hostdata *) instance->hostdata;
1044 AM53C974_setio(instance);
1046 AM53C974_write_8(STPREG, hostdata->sync_per[target]);
1047 AM53C974_write_8(SOFREG, (DEF_SOF_RAD << 6) | (DEF_SOF_RAA << 4));
1050 /**************************************************************************
1051 * Function : AM53C974_set_sync(struct Scsi_Host *instance, int target)
1053 * Purpose : put controller into sync. mode
1055 * Inputs : instance -- which AM53C974
1056 * target -- which SCSI target to deal with
1059 **************************************************************************/
1060 static __inline__ void AM53C974_set_sync(struct Scsi_Host *instance, int target)
1062 AM53C974_local_declare();
1063 struct AM53C974_hostdata *hostdata = (struct AM53C974_hostdata *) instance->hostdata;
1064 AM53C974_setio(instance);
1066 AM53C974_write_8(STPREG, hostdata->sync_per[target]);
1067 AM53C974_write_8(SOFREG, (SOFREG_SO & hostdata->sync_off[target]) |
1068 (DEF_SOF_RAD << 6) | (DEF_SOF_RAA << 4));
1071 /**************************************************************************
1072 * Function : AM53C974_transfer_dma(struct Scsi_Host *instance, short dir,
1073 * unsigned long length, char *data)
1075 * Purpose : setup DMA transfer
1077 * Inputs : instance -- which AM53C974
1078 * dir -- direction flag, 0: write to device, read from memory;
1079 * 1: read from device, write to memory
1080 * length -- number of bytes to transfer to from buffer
1081 * data -- pointer to data buffer
1084 **************************************************************************/
1085 static __inline__ void AM53C974_transfer_dma(struct Scsi_Host *instance, short dir,
1086 unsigned long length, char *data)
1088 AM53C974_local_declare();
1089 AM53C974_setio(instance);
1091 AM53C974_write_8(CMDREG, CMDREG_NOP);
1092 AM53C974_write_8(DMACMD, (dir << 7) | DMACMD_INTE_D); /* idle command */
1093 AM53C974_write_8(STCLREG, (unsigned char) (length & 0xff));
1094 AM53C974_write_8(STCMREG, (unsigned char) ((length & 0xff00) >> 8));
1095 AM53C974_write_8(STCHREG, (unsigned char) ((length & 0xff0000) >> 16));
1096 AM53C974_write_32(DMASTC, length & 0xffffff);
1097 AM53C974_write_32(DMASPA, virt_to_bus(data));
1098 AM53C974_write_8(CMDREG, CMDREG_IT | CMDREG_DMA);
1099 AM53C974_write_8(DMACMD, (dir << 7) | DMACMD_INTE_D | DMACMD_START);
1102 /************************************************************************
1103 * Function : AM53C974_intr(int irq, void *dev_id, struct pt_regs *regs) *
1105 * Purpose : interrupt handler *
1107 * Inputs : irq - interrupt line, regs - ? *
1109 * Returns : nothing *
1110 ************************************************************************/
1111 static void AM53C974_intr(int irq, void *dev_id, struct pt_regs *regs)
1113 AM53C974_local_declare();
1114 struct Scsi_Host *instance;
1115 struct AM53C974_hostdata *hostdata;
1116 unsigned char cmdreg, dmastatus, statreg, isreg, instreg, cfifo;
1118 /* find AM53C974 hostadapter responsible for this interrupt */
1119 for (instance = first_instance; instance; instance = instance->next)
1120 if ((instance->irq == irq) && (instance->hostt == the_template))
1124 /* found; now decode and process */
1126 hostdata = (struct AM53C974_hostdata *) instance->hostdata;
1127 AM53C974_setio(instance);
1128 dmastatus = AM53C974_read_8(DMASTATUS);
1130 DEB_INTR(printk(SEPARATOR_LINE));
1131 DEB_INTR(printk("AM53C974 interrupt; dmastatus=0x%02x\n", dmastatus));
1134 /*** DMA related interrupts ***/
1135 if (hostdata->connected && (dmastatus & (DMASTATUS_ERROR | DMASTATUS_PWDN |
1136 DMASTATUS_ABORT))) {
1137 /* DMA error or POWERDOWN */
1138 printk("scsi%d: DMA error or powerdown; dmastatus: 0x%02x\n",
1139 instance->host_no, dmastatus);
1140 #ifdef AM53C974_DEBUG
1143 panic("scsi%d: cannot recover\n", instance->host_no);
1145 if (hostdata->connected && (dmastatus & DMASTATUS_DONE)) {
1146 /* DMA transfer done */
1147 unsigned long residual;
1148 unsigned long flags;
1151 if (!(AM53C974_read_8(DMACMD) & DMACMD_DIR)) {
1153 dmastatus = AM53C974_read_8(DMASTATUS);
1154 residual = AM53C974_read_8(CTCLREG) | (AM53C974_read_8(CTCMREG) << 8) |
1155 (AM53C974_read_8(CTCHREG) << 16);
1156 residual += AM53C974_read_8(CFIREG) & CFIREG_CF;
1157 } while (!(dmastatus & DMASTATUS_SCSIINT) && residual);
1158 residual = AM53C974_read_8(CTCLREG) | (AM53C974_read_8(CTCMREG) << 8) |
1159 (AM53C974_read_8(CTCHREG) << 16);
1160 residual += AM53C974_read_8(CFIREG) & CFIREG_CF;
1163 hostdata->connected->SCp.ptr += hostdata->connected->SCp.this_residual - residual;
1164 hostdata->connected->SCp.this_residual = residual;
1166 AM53C974_write_8(DMACMD, DMACMD_IDLE);
1168 /* if service request missed before, process it now (ugly) */
1169 if (hostdata->dma_busy) {
1170 hostdata->dma_busy = 0;
1171 cmdreg = AM53C974_read_8(CMDREG);
1172 statreg = AM53C974_read_8(STATREG);
1173 isreg = AM53C974_read_8(ISREG);
1174 instreg = AM53C974_read_8(INSTREG);
1175 cfifo = AM53C974_cfifo();
1176 AM53C974_information_transfer(instance, statreg, isreg, instreg, cfifo,
1179 restore_flags(flags);
1181 if (!(dmastatus & DMASTATUS_SCSIINT)) {
1184 /*** SCSI related interrupts ***/
1185 cmdreg = AM53C974_read_8(CMDREG);
1186 statreg = AM53C974_read_8(STATREG);
1187 isreg = AM53C974_read_8(ISREG);
1188 instreg = AM53C974_read_8(INSTREG);
1189 cfifo = AM53C974_cfifo();
1191 DEB_INTR(printk("scsi%d: statreg: 0x%02x; isreg: 0x%02x; instreg: 0x%02x; cfifo: 0x%02x\n",
1192 instance->host_no, statreg, isreg, instreg, cfifo));
1194 if (statreg & STATREG_PE) {
1196 #ifdef AM53C974_DEBUG
1199 printk("scsi%d : PARITY error\n", instance->host_no);
1200 if (hostdata->connected)
1201 hostdata->sync_off[hostdata->connected->target] = 0; /* setup asynchronous transfer */
1202 hostdata->aborted = 1;
1204 if (statreg & STATREG_IOE) {
1205 /* illegal operation error */
1206 #ifdef AM53C974_DEBUG
1209 printk("scsi%d : ILLEGAL OPERATION error\n", instance->host_no);
1210 printk("cmdreg: 0x%02x; dmacmd: 0x%02x; statreg: 0x%02x; \n"
1211 "isreg: 0x%02x; instreg: 0x%02x; cfifo: 0x%02x\n",
1212 cmdreg, AM53C974_read_8(DMACMD), statreg, isreg, instreg, cfifo);
1214 if (hostdata->in_reset && (instreg & INSTREG_SRST)) {
1215 unsigned long flags;
1216 /* RESET INTERRUPT */
1217 #ifdef AM53C974_DEBUG
1220 DEB(printk("Bus reset interrupt received\n"));
1221 AM53C974_intr_bus_reset(instance);
1224 if (hostdata->connected) {
1225 hostdata->connected->result = DID_RESET << 16;
1226 hostdata->connected->scsi_done((Scsi_Cmnd *) hostdata->connected);
1227 hostdata->connected = NULL;
1229 if (hostdata->sel_cmd) {
1230 hostdata->sel_cmd->result = DID_RESET << 16;
1231 hostdata->sel_cmd->scsi_done((Scsi_Cmnd *) hostdata->sel_cmd);
1232 hostdata->sel_cmd = NULL;
1235 restore_flags(flags);
1236 if (hostdata->in_reset == 1)
1241 if (instreg & INSTREG_ICMD) {
1242 /* INVALID COMMAND INTERRUPT */
1243 #ifdef AM53C974_DEBUG
1246 printk("scsi%d: Invalid command interrupt\n", instance->host_no);
1247 printk("cmdreg: 0x%02x; dmacmd: 0x%02x; statreg: 0x%02x; dmastatus: 0x%02x; \n"
1248 "isreg: 0x%02x; instreg: 0x%02x; cfifo: 0x%02x\n",
1249 cmdreg, AM53C974_read_8(DMACMD), statreg, dmastatus, isreg, instreg, cfifo);
1250 panic("scsi%d: cannot recover\n", instance->host_no);
1252 if (instreg & INSTREG_DIS) {
1253 unsigned long flags;
1254 /* DISCONNECT INTERRUPT */
1255 DEB_INTR(printk("Disconnect interrupt received; "));
1258 AM53C974_intr_disconnect(instance);
1259 restore_flags(flags);
1262 if (instreg & INSTREG_RESEL) {
1263 unsigned long flags;
1264 /* RESELECTION INTERRUPT */
1265 DEB_INTR(printk("Reselection interrupt received\n"));
1268 AM53C974_intr_reselect(instance, statreg);
1269 restore_flags(flags);
1272 if (instreg & INSTREG_SO) {
1273 DEB_INTR(printk("Successful operation interrupt received\n"));
1274 if (hostdata->selecting) {
1275 unsigned long flags;
1276 DEB_INTR(printk("DSR completed, starting select\n"));
1279 AM53C974_select(instance, (Scsi_Cmnd *) hostdata->sel_cmd,
1280 (hostdata->sel_cmd->cmnd[0] == REQUEST_SENSE) ?
1281 TAG_NONE : TAG_NEXT);
1282 hostdata->selecting = 0;
1283 AM53C974_set_sync(instance, hostdata->sel_cmd->target);
1284 restore_flags(flags);
1287 if (hostdata->sel_cmd != NULL) {
1288 if (((isreg & ISREG_IS) != ISREG_OK_NO_STOP) &&
1289 ((isreg & ISREG_IS) != ISREG_OK_STOP)) {
1290 unsigned long flags;
1291 /* UNSUCCESSFUL SELECTION */
1292 DEB_INTR(printk("unsuccessful selection\n"));
1295 hostdata->dma_busy = 0;
1296 LIST(hostdata->sel_cmd, hostdata->issue_queue);
1297 hostdata->sel_cmd->host_scribble = (unsigned char *) hostdata->issue_queue;
1298 hostdata->issue_queue = hostdata->sel_cmd;
1299 hostdata->sel_cmd = NULL;
1300 hostdata->selecting = 0;
1301 restore_flags(flags);
1304 unsigned long flags;
1305 /* SUCCESSFUL SELECTION */
1306 DEB(printk("successful selection; cmd=0x%02lx\n", (long) hostdata->sel_cmd));
1309 hostdata->dma_busy = 0;
1310 hostdata->disconnecting = 0;
1311 hostdata->connected = hostdata->sel_cmd;
1312 hostdata->sel_cmd = NULL;
1313 hostdata->selecting = 0;
1315 if (!hostdata->connected->device->tagged_queue)
1317 hostdata->busy[hostdata->connected->target] |= (1 << hostdata->connected->lun);
1318 /* very strange -- use_sg is sometimes nonzero for request sense commands !! */
1319 if ((hostdata->connected->cmnd[0] == REQUEST_SENSE) && hostdata->connected->use_sg) {
1320 DEB(printk("scsi%d: REQUEST_SENSE command with nonzero use_sg\n", instance->host_no));
1322 hostdata->connected->use_sg = 0;
1324 initialize_SCp((Scsi_Cmnd *) hostdata->connected);
1325 hostdata->connected->SCp.phase = PHASE_CMDOUT;
1326 AM53C974_information_transfer(instance, statreg, isreg, instreg, cfifo, dmastatus);
1327 restore_flags(flags);
1331 unsigned long flags;
1334 AM53C974_information_transfer(instance, statreg, isreg, instreg, cfifo, dmastatus);
1335 restore_flags(flags);
1339 if (instreg & INSTREG_SR) {
1340 DEB_INTR(printk("Service request interrupt received, "));
1341 if (hostdata->connected) {
1342 unsigned long flags;
1343 DEB_INTR(printk("calling information_transfer\n"));
1346 AM53C974_information_transfer(instance, statreg, isreg, instreg, cfifo, dmastatus);
1347 restore_flags(flags);
1349 printk("scsi%d: weird: service request when no command connected\n", instance->host_no);
1350 AM53C974_write_8(CMDREG, CMDREG_CFIFO);
1355 DEB_INTR(printk("intr: starting main\n"));
1357 DEB_INTR(printk("end of intr\n"));
1360 /**************************************************************************
1361 * Function : AM53C974_intr_disconnect(struct Scsi_Host *instance)
1363 * Purpose : manage target disconnection
1365 * Inputs : instance -- which AM53C974
1368 **************************************************************************/
1369 static void AM53C974_intr_disconnect(struct Scsi_Host *instance)
1371 AM53C974_local_declare();
1372 struct AM53C974_hostdata *hostdata = (struct AM53C974_hostdata *) instance->hostdata;
1374 AM53C974_setio(instance);
1376 if (hostdata->sel_cmd != NULL) {
1377 /* normal selection timeout, typical for nonexisting targets */
1378 cmd = (Scsi_Cmnd *) hostdata->sel_cmd;
1379 DEB_INTR(printk("bad target\n"));
1380 cmd->result = DID_BAD_TARGET << 16;
1383 if (!hostdata->connected) {
1384 /* can happen if controller was reset, a device tried to reconnect,
1385 failed and disconnects now */
1386 AM53C974_write_8(CMDREG, CMDREG_CFIFO);
1389 if (hostdata->disconnecting) {
1390 /* target sent disconnect message, so we are prepared */
1391 cmd = (Scsi_Cmnd *) hostdata->connected;
1392 AM53C974_set_async(instance, cmd->target);
1393 DEB_INTR(printk("scsi%d : disc. from cmnd %d for ta %d, lun %d\n",
1394 instance->host_no, cmd->cmnd[0], cmd->target, cmd->lun));
1395 if (cmd->device->disconnect) {
1396 /* target wants to reselect later */
1397 DEB_INTR(printk("ok, re-enabling selection\n"));
1398 LIST(cmd, hostdata->disconnected_queue);
1399 cmd->host_scribble = (unsigned char *) hostdata->disconnected_queue;
1400 hostdata->disconnected_queue = cmd;
1401 DEB_QUEUE(printk("scsi%d : command for target %d lun %d this %d was moved from connected to"
1402 " the disconnected_queue\n", instance->host_no, cmd->target,
1403 cmd->lun, hostdata->disconnected_queue->SCp.this_residual));
1404 DEB_QUEUE(AM53C974_print_queues(instance));
1405 goto EXIT_UNFINISHED;
1407 /* target does not want to reselect later, we are really finished */
1408 #ifdef AM53C974_DEBUG
1409 if (cmd->cmnd[0] == REQUEST_SENSE) {
1411 printk("Request sense data dump:\n");
1412 for (i = 0; i < cmd->request_bufflen; i++) {
1413 printk("%02x ", *((char *) (cmd->request_buffer) + i));
1421 } /* !cmd->device->disconnect */
1422 } /* if (hostdata->disconnecting) */
1423 /* no disconnect message received; unexpected disconnection */
1424 cmd = (Scsi_Cmnd *) hostdata->connected;
1426 #ifdef AM53C974_DEBUG
1429 AM53C974_set_async(instance, cmd->target);
1430 printk("scsi%d: Unexpected disconnect; phase: %d; target: %d; this_residual: %d; buffers_residual: %d; message: %d\n",
1431 instance->host_no, cmd->SCp.phase, cmd->target, cmd->SCp.this_residual, cmd->SCp.buffers_residual,
1433 printk("cmdreg: 0x%02x; statreg: 0x%02x; isreg: 0x%02x; cfifo: 0x%02x\n",
1434 AM53C974_read_8(CMDREG), AM53C974_read_8(STATREG), AM53C974_read_8(ISREG),
1435 AM53C974_read_8(CFIREG) & CFIREG_CF);
1437 if ((hostdata->last_message[0] == EXTENDED_MESSAGE) &&
1438 (hostdata->last_message[2] == EXTENDED_SDTR)) {
1439 /* sync. negotiation was aborted, setup asynchronous transfer with target */
1440 hostdata->sync_off[cmd->target] = 0;
1442 if (hostdata->aborted || hostdata->msgout[0] == ABORT)
1443 cmd->result = DID_ABORT << 16;
1445 cmd->result = DID_ERROR << 16;
1449 hostdata->aborted = 0;
1450 hostdata->msgout[0] = NOP;
1451 hostdata->sel_cmd = NULL;
1452 hostdata->connected = NULL;
1453 hostdata->selecting = 0;
1454 hostdata->disconnecting = 0;
1455 hostdata->dma_busy = 0;
1456 hostdata->busy[cmd->target] &= ~(1 << cmd->lun);
1457 AM53C974_write_8(CMDREG, CMDREG_CFIFO);
1458 DEB(printk("disconnect; issue_queue: 0x%lx, disconnected_queue: 0x%lx\n",
1459 (long) hostdata->issue_queue, (long) hostdata->disconnected_queue));
1460 cmd->scsi_done(cmd);
1462 if (!hostdata->selecting) {
1463 AM53C974_set_async(instance, cmd->target);
1464 AM53C974_write_8(CMDREG, CMDREG_ESR);
1465 } /* allow reselect */
1469 hostdata->msgout[0] = NOP;
1470 hostdata->sel_cmd = NULL;
1471 hostdata->connected = NULL;
1472 hostdata->aborted = 0;
1473 hostdata->selecting = 0;
1474 hostdata->disconnecting = 0;
1475 hostdata->dma_busy = 0;
1476 DEB(printk("disconnect; issue_queue: 0x%lx, disconnected_queue: 0x%lx\n",
1477 (long) hostdata->issue_queue, (long) hostdata->disconnected_queue));
1478 if (!hostdata->selecting) {
1479 AM53C974_set_async(instance, cmd->target);
1480 AM53C974_write_8(CMDREG, CMDREG_ESR);
1481 } /* allow reselect */
1485 /**************************************************************************
1486 * Function : int AM53C974_sync_neg(struct Scsi_Host *instance, int target, unsigned char *msg)
1488 * Purpose : setup message string for sync. negotiation
1490 * Inputs : instance -- which AM53C974
1491 * target -- which SCSI target to deal with
1492 * msg -- input message string
1494 * Returns : 0 if parameters accepted or 1 if not accepted
1496 * Side effects: hostdata is changed
1498 * Note: we assume here that fastclk is enabled
1499 **************************************************************************/
1500 static int AM53C974_sync_neg(struct Scsi_Host *instance, int target, unsigned char *msg)
1502 AM53C974_local_declare();
1503 struct AM53C974_hostdata *hostdata = (struct AM53C974_hostdata *) instance->hostdata;
1504 int period, offset, i, rate, rate_rem;
1505 AM53C974_setio(instance);
1507 period = (DEF_CLK * msg[3] * 8 + 1000) / 2000;
1508 if (period < MIN_PERIOD) {
1509 period = MIN_PERIOD;
1510 hostdata->msgout[3] = period / 4;
1511 } else if (period > MAX_PERIOD) {
1512 period = MAX_PERIOD;
1513 hostdata->msgout[3] = period / 4;
1515 hostdata->msgout[3] = msg[3];
1517 if (offset > MAX_OFFSET)
1518 offset = MAX_OFFSET;
1519 hostdata->msgout[4] = offset;
1520 hostdata->sync_per[target] = period;
1521 hostdata->sync_off[target] = offset;
1522 for (i = 0; i < 3; i++)
1523 hostdata->msgout[i] = msg[i];
1524 if ((hostdata->msgout[3] != msg[3]) || (msg[4] != offset))
1527 rate = DEF_CLK / period;
1528 rate_rem = 10 * (DEF_CLK - period * rate) / period;
1531 printk("\ntarget %d: rate=%d.%d Mhz, synchronous, sync offset=%d bytes\n",
1532 target, rate, rate_rem, offset);
1534 printk("\ntarget %d: rate=%d.%d Mhz, asynchronous\n", target, rate, rate_rem);
1539 /***********************************************************************
1540 * Function : AM53C974_information_transfer(struct Scsi_Host *instance, *
1541 * unsigned char statreg, unsigned char isreg, *
1542 * unsigned char instreg, unsigned char cfifo, *
1543 * unsigned char dmastatus) *
1545 * Purpose : handle phase changes *
1547 * Inputs : instance - which AM53C974 *
1548 * statreg - status register *
1549 * isreg - internal state register *
1550 * instreg - interrupt status register *
1551 * cfifo - number of bytes in FIFO *
1552 * dmastatus - dma status register *
1554 * Returns : nothing *
1555 ************************************************************************/
1556 static void AM53C974_information_transfer(struct Scsi_Host *instance,
1557 unsigned char statreg, unsigned char isreg,
1558 unsigned char instreg, unsigned char cfifo,
1559 unsigned char dmastatus)
1561 AM53C974_local_declare();
1562 struct AM53C974_hostdata *hostdata = (struct AM53C974_hostdata *) instance->hostdata;
1563 Scsi_Cmnd *cmd = (Scsi_Cmnd *) hostdata->connected;
1564 int ret, i, len, residual = -1;
1565 AM53C974_setio(instance);
1567 DEB_INFO(printk(SEPARATOR_LINE));
1568 switch (statreg & STATREG_PHASE) { /* scsi phase */
1570 DEB_INFO(printk("Dataout phase; cmd=0x%lx, sel_cmd=0x%lx, this_residual=%d, buffers_residual=%d\n",
1571 (long) hostdata->connected, (long) hostdata->sel_cmd, cmd->SCp.this_residual, cmd->SCp.buffers_residual));
1572 cmd->SCp.phase = PHASE_DATAOUT;
1576 DEB_INFO(printk("Datain phase; cmd=0x%lx, sel_cmd=0x%lx, this_residual=%d, buffers_residual=%d\n",
1577 (long) hostdata->connected, (long) hostdata->sel_cmd, cmd->SCp.this_residual, cmd->SCp.buffers_residual));
1578 cmd->SCp.phase = PHASE_DATAIN;
1580 if (hostdata->aborted) {
1581 AM53C974_write_8(DMACMD, DMACMD_IDLE);
1582 AM53C974_write_8(CMDREG, CMDREG_CFIFO);
1583 AM53C974_write_8(CMDREG, CMDREG_SATN);
1586 if ((!cmd->SCp.this_residual) && cmd->SCp.buffers_residual) {
1588 cmd->SCp.buffers_residual--;
1589 cmd->SCp.ptr = (unsigned char *) cmd->SCp.buffer->address;
1590 cmd->SCp.this_residual = cmd->SCp.buffer->length;
1592 if (cmd->SCp.this_residual) {
1593 if (!(AM53C974_read_8(DMACMD) & DMACMD_START)) {
1594 hostdata->dma_busy = 0;
1595 AM53C974_transfer_dma(instance, statreg & STATREG_IO,
1596 (unsigned long) cmd->SCp.this_residual,
1599 hostdata->dma_busy = 1;
1604 DEB_INFO(printk("Message-In phase; cmd=0x%lx, sel_cmd=0x%lx\n",
1605 (long) hostdata->connected, (long) hostdata->sel_cmd));
1606 AM53C974_set_async(instance, cmd->target);
1607 if (cmd->SCp.phase == PHASE_DATAIN)
1608 AM53C974_dma_blast(instance, dmastatus, statreg);
1609 if ((cmd->SCp.phase == PHASE_DATAOUT) && (AM53C974_read_8(DMACMD) & DMACMD_START)) {
1610 AM53C974_write_8(DMACMD, DMACMD_IDLE);
1611 residual = cfifo + (AM53C974_read_8(CTCLREG) | (AM53C974_read_8(CTCMREG) << 8) |
1612 (AM53C974_read_8(CTCHREG) << 16));
1613 cmd->SCp.ptr += cmd->SCp.this_residual - residual;
1614 cmd->SCp.this_residual = residual;
1616 AM53C974_write_8(CMDREG, CMDREG_CFIFO);
1620 if (cmd->SCp.phase == PHASE_STATIN) {
1621 while ((AM53C974_read_8(CFIREG) & CFIREG_CF) < 2);
1622 cmd->SCp.Status = AM53C974_read_8(FFREG);
1623 cmd->SCp.Message = AM53C974_read_8(FFREG);
1624 DEB_INFO(printk("Message-In phase; status=0x%02x, message=0x%02x\n",
1625 cmd->SCp.Status, cmd->SCp.Message));
1626 ret = AM53C974_message(instance, cmd, cmd->SCp.Message);
1629 AM53C974_write_8(CMDREG, CMDREG_IT);
1630 AM53C974_poll_int();
1631 cmd->SCp.Message = AM53C974_read_8(FFREG);
1633 ret = AM53C974_message(instance, cmd, cmd->SCp.Message);
1635 cmd->SCp.phase = PHASE_MSGIN;
1636 AM53C974_set_sync(instance, cmd->target);
1639 DEB_INFO(printk("Message-Out phase; cfifo=%d; msgout[0]=0x%02x\n",
1640 AM53C974_read_8(CFIREG) & CFIREG_CF, hostdata->msgout[0]));
1641 AM53C974_write_8(DMACMD, DMACMD_IDLE);
1642 AM53C974_set_async(instance, cmd->target);
1643 for (i = 0; i < sizeof(hostdata->last_message); i++)
1644 hostdata->last_message[i] = hostdata->msgout[i];
1645 if ((hostdata->msgout[0] == 0) || INSIDE(hostdata->msgout[0], 0x02, 0x1F) ||
1646 INSIDE(hostdata->msgout[0], 0x80, 0xFF))
1649 if (hostdata->msgout[0] == EXTENDED_MESSAGE) {
1650 #ifdef AM53C974_DEBUG_INFO
1651 printk("Extended message dump:\n");
1652 for (i = 0; i < hostdata->msgout[1] + 2; i++) {
1653 printk("%02x ", hostdata->msgout[i]);
1659 len = hostdata->msgout[1] + 2;
1663 for (i = 0; i < len; i++)
1664 AM53C974_write_8(FFREG, hostdata->msgout[i]);
1665 AM53C974_write_8(CMDREG, CMDREG_IT);
1666 cmd->SCp.phase = PHASE_MSGOUT;
1667 hostdata->msgout[0] = NOP;
1668 AM53C974_set_sync(instance, cmd->target);
1672 DEB_INFO(printk("Command-Out phase\n"));
1673 AM53C974_set_async(instance, cmd->target);
1674 for (i = 0; i < cmd->cmd_len; i++)
1675 AM53C974_write_8(FFREG, cmd->cmnd[i]);
1676 AM53C974_write_8(CMDREG, CMDREG_IT);
1677 cmd->SCp.phase = PHASE_CMDOUT;
1678 AM53C974_set_sync(instance, cmd->target);
1682 DEB_INFO(printk("Status phase\n"));
1683 if (cmd->SCp.phase == PHASE_DATAIN)
1684 AM53C974_dma_blast(instance, dmastatus, statreg);
1685 AM53C974_set_async(instance, cmd->target);
1686 if (cmd->SCp.phase == PHASE_DATAOUT) {
1687 unsigned long residual;
1689 if (AM53C974_read_8(DMACMD) & DMACMD_START) {
1690 AM53C974_write_8(DMACMD, DMACMD_IDLE);
1691 residual = cfifo + (AM53C974_read_8(CTCLREG) | (AM53C974_read_8(CTCMREG) << 8) |
1692 (AM53C974_read_8(CTCHREG) << 16));
1693 cmd->SCp.ptr += cmd->SCp.this_residual - residual;
1694 cmd->SCp.this_residual = residual;
1697 AM53C974_write_8(CMDREG, CMDREG_CFIFO);
1701 cmd->SCp.phase = PHASE_STATIN;
1702 AM53C974_write_8(CMDREG, CMDREG_ICCS); /* command complete */
1707 #ifdef AM53C974_DEBUG
1710 DEB_INFO(printk("Reserved phase\n"));
1716 /******************************************************************************
1717 * Function : int AM53C974_message(struct Scsi_Host *instance, Scsi_Cmnd *cmd,
1718 * unsigned char msg)
1720 * Purpose : handle SCSI messages
1722 * Inputs : instance -- which AM53C974
1723 * cmd -- SCSI command the message belongs to
1724 * msg -- message id byte
1726 * Returns : 1 on success, 0 on failure.
1727 **************************************************************************/
1728 static int AM53C974_message(struct Scsi_Host *instance, Scsi_Cmnd * cmd,
1731 AM53C974_local_declare();
1732 static unsigned char extended_msg[10];
1733 unsigned char statreg;
1736 #ifdef AM53C974_DEBUG_MSG
1739 struct AM53C974_hostdata *hostdata = (struct AM53C974_hostdata *) instance->hostdata;
1740 AM53C974_setio(instance);
1742 DEB_MSG(printk(SEPARATOR_LINE));
1744 /* Linking lets us reduce the time required to get the
1745 * next command out to the device, hopefully this will
1746 * mean we don't waste another revolution due to the delays
1747 * required by ARBITRATION and another SELECTION.
1748 * In the current implementation proposal, low level drivers
1749 * merely have to start the next command, pointed to by
1750 * next_link, done() is called as with unlinked commands. */
1753 case LINKED_CMD_COMPLETE:
1754 case LINKED_FLG_CMD_COMPLETE:
1755 /* Accept message by releasing ACK */
1756 DEB_LINKED(printk("scsi%d : target %d lun %d linked command complete.\n",
1757 instance->host_no, cmd->target, cmd->lun));
1758 /* Sanity check : A linked command should only terminate with
1759 * one of these messages if there are more linked commands available. */
1760 if (!cmd->next_link) {
1761 printk("scsi%d : target %d lun %d linked command complete, no next_link\n"
1762 instance->host_no, cmd->target, cmd->lun);
1763 hostdata->aborted = 1;
1764 AM53C974_write_8(CMDREG, CMDREG_SATN);
1765 AM53C974_write_8(CMDREG, CMDREG_MA);
1768 if (hostdata->aborted) {
1769 DEB_ABORT(printk("ATN set for cmnd %d upon reception of LINKED_CMD_COMPLETE or"
1770 "LINKED_FLG_CMD_COMPLETE message\n", cmd->cmnd[0]));
1771 AM53C974_write_8(CMDREG, CMDREG_SATN);
1773 AM53C974_write_8(CMDREG, CMDREG_MA);
1775 initialize_SCp(cmd->next_link);
1776 /* The next command is still part of this process */
1777 cmd->next_link->tag = cmd->tag;
1778 cmd->result = cmd->SCp.Status | (cmd->SCp.Message << 8);
1779 DEB_LINKED(printk("scsi%d : target %d lun %d linked request done, calling scsi_done().\n",
1780 instance->host_no, cmd->target, cmd->lun));
1781 cmd->scsi_done(cmd);
1782 cmd = hostdata->connected;
1785 #endif /* def LINKED */
1788 case COMMAND_COMPLETE:
1789 DEB_MSG(printk("scsi%d: command complete message received; cmd %d for target %d, lun %d\n",
1790 instance->host_no, cmd->cmnd[0], cmd->target, cmd->lun));
1791 hostdata->disconnecting = 1;
1792 cmd->device->disconnect = 0;
1794 /* I'm not sure what the correct thing to do here is :
1796 * If the command that just executed is NOT a request
1797 * sense, the obvious thing to do is to set the result
1798 * code to the values of the stored parameters.
1799 * If it was a REQUEST SENSE command, we need some way
1800 * to differentiate between the failure code of the original
1801 * and the failure code of the REQUEST sense - the obvious
1802 * case is success, where we fall through and leave the result
1805 * The non-obvious place is where the REQUEST SENSE failed */
1806 if (cmd->cmnd[0] != REQUEST_SENSE)
1807 cmd->result = cmd->SCp.Status | (cmd->SCp.Message << 8);
1808 else if (cmd->SCp.Status != GOOD)
1809 cmd->result = (cmd->result & 0x00ffff) | (DID_ERROR << 16);
1810 if (hostdata->aborted) {
1811 AM53C974_write_8(CMDREG, CMDREG_SATN);
1812 AM53C974_write_8(CMDREG, CMDREG_MA);
1813 DEB_ABORT(printk("ATN set for cmnd %d upon reception of ABORT or"
1814 "COMMAND_COMPLETE message\n", cmd->cmnd[0]));
1817 if ((cmd->cmnd[0] != REQUEST_SENSE) && (cmd->SCp.Status == CHECK_CONDITION)) {
1818 DEB_MSG(printk("scsi%d : performing request sense\n", instance->host_no));
1819 cmd->cmnd[0] = REQUEST_SENSE;
1820 cmd->cmnd[1] &= 0xe0;
1823 cmd->cmnd[4] = sizeof(cmd->sense_buffer);
1825 cmd->SCp.buffer = NULL;
1826 cmd->SCp.buffers_residual = 0;
1827 cmd->SCp.ptr = (char *) cmd->sense_buffer;
1828 cmd->SCp.this_residual = sizeof(cmd->sense_buffer);
1829 LIST(cmd, hostdata->issue_queue);
1830 cmd->host_scribble = (unsigned char *) hostdata->issue_queue;
1831 hostdata->issue_queue = (Scsi_Cmnd *) cmd;
1832 DEB_MSG(printk("scsi%d : REQUEST SENSE added to head of issue queue\n", instance->host_no));
1834 /* Accept message by clearing ACK */
1835 AM53C974_write_8(CMDREG, CMDREG_MA);
1838 case MESSAGE_REJECT:
1839 DEB_MSG(printk("scsi%d: reject message received; cmd %d for target %d, lun %d\n",
1840 instance->host_no, cmd->cmnd[0], cmd->target, cmd->lun));
1841 switch (hostdata->last_message[0]) {
1842 case EXTENDED_MESSAGE:
1843 if (hostdata->last_message[2] == EXTENDED_SDTR) {
1844 /* sync. negotiation was rejected, setup asynchronous transfer with target */
1845 printk("\ntarget %d: rate=%d Mhz, asynchronous (sync. negotiation rejected)\n",
1846 cmd->target, DEF_CLK / DEF_STP);
1847 hostdata->sync_off[cmd->target] = 0;
1848 hostdata->sync_per[cmd->target] = DEF_STP;
1851 case HEAD_OF_QUEUE_TAG:
1852 case ORDERED_QUEUE_TAG:
1853 case SIMPLE_QUEUE_TAG:
1854 cmd->device->tagged_queue = 0;
1855 hostdata->busy[cmd->target] |= (1 << cmd->lun);
1860 if (hostdata->aborted)
1861 AM53C974_write_8(CMDREG, CMDREG_SATN);
1862 AM53C974_write_8(CMDREG, CMDREG_MA);
1866 DEB_MSG(printk("scsi%d: disconnect message received; cmd %d for target %d, lun %d\n",
1867 instance->host_no, cmd->cmnd[0], cmd->target, cmd->lun));
1868 cmd->device->disconnect = 1;
1869 hostdata->disconnecting = 1;
1870 AM53C974_write_8(CMDREG, CMDREG_MA); /* Accept message by clearing ACK */
1874 case RESTORE_POINTERS:
1875 DEB_MSG(printk("scsi%d: save/restore pointers message received; cmd %d for target %d, lun %d\n",
1876 instance->host_no, cmd->cmnd[0], cmd->target, cmd->lun));
1877 /* The SCSI data pointer is *IMPLICITLY* saved on a disconnect
1878 * operation, in violation of the SCSI spec so we can safely
1879 * ignore SAVE/RESTORE pointers calls.
1881 * Unfortunately, some disks violate the SCSI spec and
1882 * don't issue the required SAVE_POINTERS message before
1883 * disconnecting, and we have to break spec to remain
1885 if (hostdata->aborted) {
1886 DEB_ABORT(printk("ATN set for cmnd %d upon reception of SAVE/REST. POINTERS message\n",
1888 AM53C974_write_8(CMDREG, CMDREG_SATN);
1890 AM53C974_write_8(CMDREG, CMDREG_MA);
1893 case EXTENDED_MESSAGE:
1894 DEB_MSG(printk("scsi%d: extended message received; cmd %d for target %d, lun %d\n",
1895 instance->host_no, cmd->cmnd[0], cmd->target, cmd->lun));
1896 /* Extended messages are sent in the following format :
1898 * 0 EXTENDED_MESSAGE == 1
1899 * 1 length (includes one byte for code, doesn't include first two bytes)
1901 * 3..length+1 arguments
1903 /* BEWARE!! THIS CODE IS EXTREMELY UGLY */
1904 extended_msg[0] = EXTENDED_MESSAGE;
1905 AM53C974_read_8(INSTREG); /* clear int */
1906 AM53C974_write_8(CMDREG, CMDREG_MA); /* ack. msg byte, then wait for SO */
1907 AM53C974_poll_int();
1909 AM53C974_write_8(CMDREG, CMDREG_IT);
1910 AM53C974_poll_int();
1911 AM53C974_write_8(CMDREG, CMDREG_MA); /* ack. msg byte, then wait for SO */
1912 AM53C974_poll_int();
1913 extended_msg[1] = len = AM53C974_read_8(FFREG); /* get length */
1914 p = extended_msg + 2;
1915 /* read the remaining (len) bytes */
1917 AM53C974_write_8(CMDREG, CMDREG_IT);
1918 AM53C974_poll_int();
1920 AM53C974_write_8(CMDREG, CMDREG_MA); /* ack. msg byte, then wait for SO */
1921 AM53C974_poll_int();
1923 *p = AM53C974_read_8(FFREG);
1928 #ifdef AM53C974_DEBUG_MSG
1929 printk("scsi%d: received extended message: ", instance->host_no);
1930 for (j = 0; j < extended_msg[1] + 2; j++) {
1931 printk("0x%02x ", extended_msg[j]);
1939 if (extended_msg[2] == EXTENDED_SDTR)
1940 ret = AM53C974_sync_neg(instance, cmd->target, extended_msg);
1941 if (ret || hostdata->aborted)
1942 AM53C974_write_8(CMDREG, CMDREG_SATN);
1944 AM53C974_write_8(CMDREG, CMDREG_MA);
1948 printk("scsi%d: unknown message 0x%02x received\n", instance->host_no, msg);
1949 #ifdef AM53C974_DEBUG
1952 /* reject message */
1953 hostdata->msgout[0] = MESSAGE_REJECT;
1954 AM53C974_write_8(CMDREG, CMDREG_SATN);
1955 AM53C974_write_8(CMDREG, CMDREG_MA);
1959 } /* switch (msg) */
1964 /**************************************************************************
1965 * Function : AM53C974_select(struct Scsi_Host *instance, Scsi_Cmnd *cmd, int tag)
1967 * Purpose : try to establish nexus for the command;
1968 * start sync negotiation via start stop and transfer the command in
1969 * cmdout phase in case of an inquiry or req. sense command with no
1970 * sync. neg. performed yet
1972 * Inputs : instance -- which AM53C974
1973 * cmd -- command which requires the selection
1974 * tag -- tagged queueing
1978 * Note: this function initializes the selection process, which is continued
1979 * in the interrupt handler
1980 **************************************************************************/
1981 static void AM53C974_select(struct Scsi_Host *instance, Scsi_Cmnd * cmd, int tag)
1983 AM53C974_local_declare();
1984 struct AM53C974_hostdata *hostdata = (struct AM53C974_hostdata *) instance->hostdata;
1985 unsigned char cfifo, tmp[3];
1986 unsigned int i, len, cmd_size = COMMAND_SIZE(cmd->cmnd[0]);
1987 AM53C974_setio(instance);
1989 cfifo = AM53C974_cfifo();
1991 printk("scsi%d: select error; %d residual bytes in FIFO\n", instance->host_no, cfifo);
1992 AM53C974_write_8(CMDREG, CMDREG_CFIFO); /* clear FIFO */
1994 #ifdef AM53C974_PROHIBIT_DISCONNECT
1995 tmp[0] = IDENTIFY(0, cmd->lun);
1997 tmp[0] = IDENTIFY(1, cmd->lun);
2001 if (cmd->device->tagged_queue && (tag != TAG_NONE)) {
2002 tmp[1] = SIMPLE_QUEUE_TAG;
2003 if (tag == TAG_NEXT) {
2004 /* 0 is TAG_NONE, used to imply no tag for this command */
2005 if (cmd->device->current_tag == 0)
2006 cmd->device->current_tag = 1;
2007 cmd->tag = cmd->device->current_tag;
2008 cmd->device->current_tag++;
2010 cmd->tag = (unsigned char) tag;
2012 hostdata->last_message[0] = SIMPLE_QUEUE_TAG;
2014 AM53C974_write_8(FFREG, tmp[0]);
2015 AM53C974_write_8(FFREG, tmp[1]);
2016 AM53C974_write_8(FFREG, tmp[2]);
2018 #endif /* def SCSI2 */
2021 AM53C974_write_8(FFREG, tmp[0]);
2025 /* in case of an inquiry or req. sense command with no sync. neg performed yet, we start
2026 sync negotiation via start stops and transfer the command in cmdout phase */
2027 if (((cmd->cmnd[0] == INQUIRY) || (cmd->cmnd[0] == REQUEST_SENSE)) &&
2028 !(hostdata->sync_neg[cmd->target]) && hostdata->sync_en[cmd->target]) {
2029 hostdata->sync_neg[cmd->target] = 1;
2030 hostdata->msgout[0] = EXTENDED_MESSAGE;
2031 hostdata->msgout[1] = 3;
2032 hostdata->msgout[2] = EXTENDED_SDTR;
2033 hostdata->msgout[3] = 250 / (int) hostdata->max_rate[cmd->target];
2034 hostdata->msgout[4] = hostdata->max_offset[cmd->target];
2037 AM53C974_write_8(SDIDREG, SDIREG_MASK & cmd->target); /* setup dest. id */
2038 AM53C974_write_8(STIMREG, DEF_SCSI_TIMEOUT); /* setup timeout reg */
2041 for (i = 0; i < cmd_size; i++)
2042 AM53C974_write_8(FFREG, cmd->cmnd[i]);
2043 AM53C974_write_8(CMDREG, CMDREG_SAS); /* select with ATN, 1 msg byte */
2044 hostdata->msgout[0] = NOP;
2047 for (i = 0; i < cmd_size; i++)
2048 AM53C974_write_8(FFREG, cmd->cmnd[i]);
2049 AM53C974_write_8(CMDREG, CMDREG_SA3S); /* select with ATN, 3 msg bytes */
2050 hostdata->msgout[0] = NOP;
2053 AM53C974_write_8(CMDREG, CMDREG_SASS); /* select with ATN, stop steps; continue in message out phase */
2058 /**************************************************************************
2059 * Function : AM53C974_intr_select(struct Scsi_Host *instance, unsigned char statreg)
2061 * Purpose : handle reselection
2063 * Inputs : instance -- which AM53C974
2064 * statreg -- status register
2068 * side effects: manipulates hostdata
2069 **************************************************************************/
2070 static void AM53C974_intr_reselect(struct Scsi_Host *instance, unsigned char statreg)
2072 AM53C974_local_declare();
2073 struct AM53C974_hostdata *hostdata = (struct AM53C974_hostdata *) instance->hostdata;
2074 unsigned char cfifo, msg[3], lun, t, target = 0;
2078 Scsi_Cmnd *tmp = NULL, *prev;
2079 AM53C974_setio(instance);
2081 cfifo = AM53C974_cfifo();
2083 if (hostdata->selecting) {
2084 /* caught reselect interrupt in selection process;
2085 put selecting command back into the issue queue and continue with the
2086 reselecting command */
2087 DEB_RESEL(printk("AM53C974_intr_reselect: in selection process\n"));
2088 LIST(hostdata->sel_cmd, hostdata->issue_queue);
2089 hostdata->sel_cmd->host_scribble = (unsigned char *) hostdata->issue_queue;
2090 hostdata->issue_queue = hostdata->sel_cmd;
2091 hostdata->sel_cmd = NULL;
2092 hostdata->selecting = 0;
2094 /* 2 bytes must be in the FIFO now */
2096 printk("scsi %d: error: %d bytes in fifo, 2 expected\n", instance->host_no, cfifo);
2097 hostdata->aborted = 1;
2100 /* determine target which reselected */
2101 t = AM53C974_read_8(FFREG);
2102 if (!(t & (1 << instance->this_id))) {
2103 printk("scsi %d: error: invalid host id\n", instance->host_no);
2104 hostdata->aborted = 1;
2107 t ^= (1 << instance->this_id);
2113 DEB_RESEL(printk("scsi %d: reselect; target: %d\n", instance->host_no, target));
2115 if (hostdata->aborted)
2118 if ((statreg & STATREG_PHASE) != PHASE_MSGIN) {
2119 printk("scsi %d: error: upon reselection interrupt not in MSGIN\n", instance->host_no);
2120 hostdata->aborted = 1;
2123 msg[0] = AM53C974_read_8(FFREG);
2124 if (!msg[0] & 0x80) {
2125 printk("scsi%d: error: expecting IDENTIFY message, got ", instance->host_no);
2127 hostdata->aborted = 1;
2130 lun = (msg[0] & 0x07);
2132 /* We need to add code for SCSI-II to track which devices have
2133 * I_T_L_Q nexuses established, and which have simple I_T_L
2134 * nexuses so we can chose to do additional data transfer. */
2136 #error "SCSI-II tagged queueing is not supported yet"
2139 /* Find the command corresponding to the I_T_L or I_T_L_Q nexus we
2140 * just reestablished, and remove it from the disconnected queue. */
2141 for (tmp = (Scsi_Cmnd *) hostdata->disconnected_queue, prev = NULL;
2142 tmp; prev = tmp, tmp = (Scsi_Cmnd *) tmp->host_scribble)
2143 if ((target == tmp->target) && (lun == tmp->lun)
2145 && (tag == tmp->tag)
2149 REMOVE(prev, (Scsi_Cmnd *) (prev->host_scribble), tmp,
2150 (Scsi_Cmnd *) (tmp->host_scribble));
2151 prev->host_scribble = tmp->host_scribble;
2153 REMOVE(-1, hostdata->disconnected_queue, tmp, tmp->host_scribble);
2154 hostdata->disconnected_queue = (Scsi_Cmnd *) tmp->host_scribble;
2156 tmp->host_scribble = NULL;
2157 hostdata->connected = tmp;
2162 printk("scsi%d: warning : target %d lun %d tag %d not in disconnect_queue.\n",
2163 instance->host_no, target, lun, tag);
2165 printk("scsi%d: warning : target %d lun %d not in disconnect_queue.\n",
2166 instance->host_no, target, lun);
2168 /* Since we have an established nexus that we can't do anything with, we must abort it. */
2169 hostdata->aborted = 1;
2170 DEB(AM53C974_keywait());
2176 AM53C974_write_8(CMDREG, CMDREG_SATN);
2177 AM53C974_write_8(CMDREG, CMDREG_MA);
2181 DEB_RESEL(printk("scsi%d: nexus established, target = %d, lun = %d, tag = %d\n",
2182 instance->host_no, target, tmp->lun, tmp->tag));
2183 AM53C974_set_sync(instance, target);
2184 AM53C974_write_8(SDIDREG, SDIREG_MASK & target); /* setup dest. id */
2185 AM53C974_write_8(CMDREG, CMDREG_MA);
2186 hostdata->dma_busy = 0;
2187 hostdata->connected->SCp.phase = PHASE_CMDOUT;
2190 /**************************************************************************
2191 * Function : AM53C974_dma_blast(struct Scsi_Host *instance, unsigned char dmastatus,
2192 * unsigned char statreg)
2194 * Purpose : cleanup DMA transfer
2196 * Inputs : instance -- which AM53C974
2197 * dmastatus -- dma status register
2198 * statreg -- status register
2201 **************************************************************************/
2202 static void AM53C974_dma_blast(struct Scsi_Host *instance, unsigned char dmastatus,
2203 unsigned char statreg)
2205 AM53C974_local_declare();
2206 struct AM53C974_hostdata *hostdata = (struct AM53C974_hostdata *) instance->hostdata;
2207 unsigned long ctcreg;
2208 int dir = statreg & STATREG_IO;
2209 int cfifo, pio, i = 0;
2210 AM53C974_setio(instance);
2213 cfifo = AM53C974_cfifo();
2215 } while (cfifo && (i < 50000));
2216 pio = (i == 50000) ? 1 : 0;
2218 if (statreg & STATREG_CTZ) {
2219 AM53C974_write_8(DMACMD, DMACMD_IDLE);
2222 if (dmastatus & DMASTATUS_DONE) {
2223 AM53C974_write_8(DMACMD, DMACMD_IDLE);
2226 AM53C974_write_8(DMACMD, ((dir << 7) & DMACMD_DIR) | DMACMD_BLAST);
2227 while (!(AM53C974_read_8(DMASTATUS) & DMASTATUS_BCMPLT));
2228 AM53C974_write_8(DMACMD, DMACMD_IDLE);
2231 /* transfer residual bytes via PIO */
2232 unsigned char *wac = (unsigned char *) AM53C974_read_32(DMAWAC);
2233 printk("pio mode, residual=%d\n", AM53C974_read_8(CFIREG) & CFIREG_CF);
2234 while (AM53C974_read_8(CFIREG) & CFIREG_CF)
2235 *(wac++) = AM53C974_read_8(FFREG);
2237 ctcreg = AM53C974_read_8(CTCLREG) | (AM53C974_read_8(CTCMREG) << 8) |
2238 (AM53C974_read_8(CTCHREG) << 16);
2240 hostdata->connected->SCp.ptr += hostdata->connected->SCp.this_residual - ctcreg;
2241 hostdata->connected->SCp.this_residual = ctcreg;
2244 /**************************************************************************
2245 * Function : AM53C974_intr_bus_reset(struct Scsi_Host *instance)
2247 * Purpose : handle bus reset interrupt
2249 * Inputs : instance -- which AM53C974
2252 **************************************************************************/
2253 static void AM53C974_intr_bus_reset(struct Scsi_Host *instance)
2255 AM53C974_local_declare();
2256 unsigned char cntlreg1;
2257 AM53C974_setio(instance);
2259 AM53C974_write_8(CMDREG, CMDREG_CFIFO);
2260 AM53C974_write_8(CMDREG, CMDREG_NOP);
2262 cntlreg1 = AM53C974_read_8(CNTLREG1);
2263 AM53C974_write_8(CNTLREG1, cntlreg1 | CNTLREG1_DISR);
2266 /**************************************************************************
2267 * Function : int AM53C974_abort(Scsi_Cmnd *cmd)
2269 * Purpose : abort a command
2271 * Inputs : cmd - the Scsi_Cmnd to abort, code - code to set the
2272 * host byte of the result field to, if zero DID_ABORTED is
2275 * Returns : 0 - success, -1 on failure.
2276 **************************************************************************/
2277 static int AM53C974_abort(Scsi_Cmnd * cmd)
2279 AM53C974_local_declare();
2280 unsigned long flags;
2281 struct Scsi_Host *instance = cmd->host;
2282 struct AM53C974_hostdata *hostdata = (struct AM53C974_hostdata *) instance->hostdata;
2283 Scsi_Cmnd *tmp, **prev;
2285 #ifdef AM53C974_DEBUG
2290 AM53C974_setio(instance);
2292 DEB_ABORT(printk(SEPARATOR_LINE));
2293 DEB_ABORT(printk("scsi%d : AM53C974_abort called -- trouble starts!!\n", instance->host_no));
2294 DEB_ABORT(AM53C974_print(instance));
2295 DEB_ABORT(AM53C974_keywait());
2297 /* Case 1 : If the command is the currently executing command,
2298 we'll set the aborted flag and return control so that the
2299 information transfer routine can exit cleanly. */
2300 if ((hostdata->connected == cmd) || (hostdata->sel_cmd == cmd)) {
2301 DEB_ABORT(printk("scsi%d: aborting connected command\n", instance->host_no));
2302 hostdata->aborted = 1;
2303 hostdata->msgout[0] = ABORT;
2304 restore_flags(flags);
2305 return (SCSI_ABORT_PENDING);
2307 /* Case 2 : If the command hasn't been issued yet,
2308 we simply remove it from the issue queue. */
2309 for (prev = (Scsi_Cmnd **) & (hostdata->issue_queue),
2310 tmp = (Scsi_Cmnd *) hostdata->issue_queue; tmp;
2311 prev = (Scsi_Cmnd **) & (tmp->host_scribble),
2312 tmp = (Scsi_Cmnd *) tmp->host_scribble) {
2314 DEB_ABORT(printk("scsi%d : abort removed command from issue queue.\n", instance->host_no));
2315 REMOVE(5, *prev, tmp, tmp->host_scribble);
2316 (*prev) = (Scsi_Cmnd *) tmp->host_scribble;
2317 tmp->host_scribble = NULL;
2318 tmp->result = DID_ABORT << 16;
2319 restore_flags(flags);
2321 return (SCSI_ABORT_SUCCESS);
2323 #ifdef AM53C974_DEBUG_ABORT
2325 if (prev == (Scsi_Cmnd **) tmp)
2326 printk("scsi%d : LOOP\n", instance->host_no);
2331 /* Case 3 : If any commands are connected, we're going to fail the abort
2332 * and let the high level SCSI driver retry at a later time or
2335 * Timeouts, and therefore aborted commands, will be highly unlikely
2336 * and handling them cleanly in this situation would make the common
2337 * case of noresets less efficient, and would pollute our code. So,
2339 if (hostdata->connected || hostdata->sel_cmd) {
2340 DEB_ABORT(printk("scsi%d : abort failed, other command connected.\n", instance->host_no));
2341 restore_flags(flags);
2342 return (SCSI_ABORT_NOT_RUNNING);
2344 /* Case 4: If the command is currently disconnected from the bus, and
2345 * there are no connected commands, we reconnect the I_T_L or
2346 * I_T_L_Q nexus associated with it, go into message out, and send
2347 * an abort message. */
2348 for (tmp = (Scsi_Cmnd *) hostdata->disconnected_queue; tmp;
2349 tmp = (Scsi_Cmnd *) tmp->host_scribble) {
2351 DEB_ABORT(printk("scsi%d: aborting disconnected command\n", instance->host_no));
2352 hostdata->aborted = 1;
2353 hostdata->msgout[0] = ABORT;
2354 hostdata->selecting = 1;
2355 hostdata->sel_cmd = tmp;
2356 AM53C974_write_8(CMDREG, CMDREG_DSR);
2357 restore_flags(flags);
2358 return (SCSI_ABORT_PENDING);
2362 /* Case 5 : If we reached this point, the command was not found in any of
2365 * We probably reached this point because of an unlikely race condition
2366 * between the command completing successfully and the abortion code,
2367 * so we won't panic, but we will notify the user in case something really
2369 DEB_ABORT(printk("scsi%d : abort failed, command not found.\n", instance->host_no));
2370 restore_flags(flags);
2371 return (SCSI_ABORT_NOT_RUNNING);
2374 /**************************************************************************
2375 * Function : int AM53C974_reset(Scsi_Cmnd *cmd)
2377 * Purpose : reset the SCSI controller and bus
2379 * Inputs : cmd -- which command within the command block was responsible for the reset
2381 * Returns : status (SCSI_ABORT_SUCCESS)
2383 * FIXME(eric) the reset_flags are ignored.
2384 **************************************************************************/
2385 static int AM53C974_reset(Scsi_Cmnd * cmd, unsigned int reset_flags)
2387 AM53C974_local_declare();
2388 unsigned long flags;
2390 struct Scsi_Host *instance = cmd->host;
2391 struct AM53C974_hostdata *hostdata = (struct AM53C974_hostdata *) instance->hostdata;
2392 AM53C974_setio(instance);
2396 DEB(printk("AM53C974_reset called; "));
2398 printk("AM53C974_reset called\n");
2399 AM53C974_print(instance);
2403 AM53C974_write_8(CMDREG, CMDREG_RDEV);
2404 AM53C974_write_8(CMDREG, CMDREG_NOP);
2405 hostdata->msgout[0] = NOP;
2406 for (i = 0; i < 8; i++) {
2407 hostdata->busy[i] = 0;
2408 hostdata->sync_per[i] = DEF_STP;
2409 hostdata->sync_off[i] = 0;
2410 hostdata->sync_neg[i] = 0;
2412 hostdata->last_message[0] = NOP;
2413 hostdata->sel_cmd = NULL;
2414 hostdata->connected = NULL;
2415 hostdata->issue_queue = NULL;
2416 hostdata->disconnected_queue = NULL;
2417 hostdata->in_reset = 0;
2418 hostdata->aborted = 0;
2419 hostdata->selecting = 0;
2420 hostdata->disconnecting = 0;
2421 hostdata->dma_busy = 0;
2424 AM53C974_write_8(CNTLREG1, CNTLREG1_DISR | instance->this_id); /* disable interrupt upon SCSI RESET */
2425 AM53C974_write_8(CMDREG, CMDREG_RBUS); /* reset SCSI bus */
2427 AM53C974_config_after_reset(instance);
2429 restore_flags(flags);
2430 cmd->result = DID_RESET << 16;
2431 cmd->scsi_done(cmd);
2432 return SCSI_ABORT_SUCCESS;
2437 * AM53C974_release()
2439 * Release resources allocated for a single AM53C974 adapter.
2441 static int AM53C974_release(struct Scsi_Host *shp)
2443 free_irq(shp->irq, shp);
2444 scsi_unregister(shp);
2449 /* You can specify overrides=a,b,c,d in the same format at AM53C974=a,b,c,d
2451 MODULE_PARM(overrides, "1-32i");
2452 MODULE_LICENSE("GPL");
2455 static Scsi_Host_Template driver_template = AM53C974;
2456 #include "scsi_module.c"