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 $
48 * Revision 1.1.1.1 2005/04/11 02:50:35 jack
51 * Revision 1.1.1.1 2005/01/10 13:16:34 jack
58 #ifdef AM53C974_DEBUG_KEYWAIT
59 #define KEYWAIT() AM53C974_keywait()
63 #ifdef AM53C974_DEBUG_INIT
68 #ifdef AM53C974_DEBUG_MSG
73 #ifdef AM53C974_DEB_RESEL
74 #define DEB_RESEL(x) x
78 #ifdef AM53C974_DEBUG_QUEUE
79 #define DEB_QUEUE(x) x
80 #define LIST(x,y) {printk("LINE:%d Adding %p to %p\n", __LINE__, (void*)(x), (void*)(y)); if ((x)==(y)) udelay(5); }
81 #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); }
85 #define REMOVE(w,x,y,z)
87 #ifdef AM53C974_DEBUG_INFO
92 #ifdef AM53C974_DEBUG_LINKED
93 #define DEB_LINKED(x) x
97 #ifdef AM53C974_DEBUG_INTR
107 #define REMOVE(w,x,y,z)
109 #define DEB_LINKED(x)
115 #ifdef AM53C974_DEBUG_ABORT
116 #define DEB_ABORT(x) x
121 #ifdef VERBOSE_AM53C974_DEBUG
127 #define INSIDE(x,l,h) ( ((x) >= (l)) && ((x) <= (h)) )
130 #include <scsi/scsicam.h>
132 /***************************************************************************************
133 * Default setting of the controller's SCSI id. Edit and uncomment this only if your *
134 * BIOS does not correctly initialize the controller's SCSI id. *
135 * If you don't get a warning during boot, it is correctly initialized. *
136 ****************************************************************************************/
137 /* #define AM53C974_SCSI_ID 7 */
139 /***************************************************************************************
140 * Default settings for sync. negotiation enable, transfer rate and sync. offset. *
141 * These settings can be replaced by LILO overrides (append) with the following syntax: *
142 * AM53C974=host-scsi-id, target-scsi-id, max-rate, max-offset *
143 * Sync. negotiation is disabled by default and will be enabled for those targets which *
144 * are specified in the LILO override *
145 ****************************************************************************************/
146 #define DEFAULT_SYNC_NEGOTIATION_ENABLED 0 /* 0 or 1 */
147 #define DEFAULT_RATE 5 /* MHz, min: 3; max: 10 */
148 #define DEFAULT_SYNC_OFFSET 0 /* bytes, min: 0; max: 15; use 0 for async. mode */
150 /***************************************************************************************
151 * If defined, don't allow targets to disconnect during commands. This will reduce *
152 * performance, but may be worthwhile if you suspect the driver of corrupting data when *
153 * a disconnect happens. *
154 ***************************************************************************************/
155 #define AM53C974_PROHIBIT_DISCONNECT
157 /* --------------------- don't edit below here --------------------- */
159 #define AM53C974_DRIVER_REVISION_MAJOR 0
160 #define AM53C974_DRIVER_REVISION_MINOR 5
161 #define SEPARATOR_LINE \
162 "--------------------------------------------------------------------------\n"
165 /* #define AM53C974_DEBUG */
166 /* #define AM53C974_DEBUG_MSG */
167 /* #define AM53C974_DEBUG_KEYWAIT */
168 /* #define AM53C974_DEBUG_INIT */
169 /* #define AM53C974_DEBUG_QUEUE */
170 /* #define AM53C974_DEBUG_INFO */
171 /* #define AM53C974_DEBUG_LINKED */
172 /* #define VERBOSE_AM53C974_DEBUG */
173 /* #define AM53C974_DEBUG_INTR */
174 /* #define AM53C974_DEB_RESEL */
175 #define AM53C974_DEBUG_ABORT
176 /* #define AM53C974_OPTION_DEBUG_PROBE_ONLY */
178 /* special options/constants */
179 #define DEF_CLK 40 /* chip clock freq. in MHz */
180 #define MIN_PERIOD 4 /* for negotiation: min. number of clocks per cycle */
181 #define MAX_PERIOD 13 /* for negotiation: max. number of clocks per cycle */
182 #define MAX_OFFSET 15 /* for negotiation: max. offset (0=async) */
184 #define DEF_SCSI_TIMEOUT 245 /* STIMREG value, 40 Mhz */
185 #define DEF_STP 8 /* STPREG value assuming 5.0 MB/sec, FASTCLK, FASTSCSI */
186 #define DEF_SOF_RAD 0 /* REQ/ACK deassertion delay */
187 #define DEF_SOF_RAA 0 /* REQ/ACK assertion delay */
188 #define DEF_ETM 0 /* CNTLREG1, ext. timing mode */
189 #define DEF_PERE 1 /* CNTLREG1, parity error reporting */
190 #define DEF_CLKF 0 /* CLKFREG, 0=40 Mhz */
191 #define DEF_ENF 1 /* CNTLREG2, enable features */
192 #define DEF_ADIDCHK 0 /* CNTLREG3, additional ID check */
193 #define DEF_FASTSCSI 1 /* CNTLREG3, fast SCSI */
194 #define DEF_FASTCLK 1 /* CNTLREG3, fast clocking, 5 MB/sec at 40MHz chip clk */
195 #define DEF_GLITCH 1 /* CNTLREG4, glitch eater, 0=12ns, 1=35ns, 2=25ns, 3=off */
196 #define DEF_PWD 0 /* CNTLREG4, reduced power feature */
197 #define DEF_RAE 0 /* CNTLREG4, RAE active negation on REQ, ACK only */
198 #define DEF_RADE 1 /* 1CNTLREG4, active negation on REQ, ACK and data */
201 #define CTCLREG 0x00 /* r current transf. count, low byte */
202 #define CTCMREG 0x04 /* r current transf. count, middle byte */
203 #define CTCHREG 0x38 /* r current transf. count, high byte */
204 #define STCLREG 0x00 /* w start transf. count, low byte */
205 #define STCMREG 0x04 /* w start transf. count, middle byte */
206 #define STCHREG 0x38 /* w start transf. count, high byte */
207 #define FFREG 0x08 /* rw SCSI FIFO reg. */
208 #define STIMREG 0x14 /* w SCSI timeout reg. */
210 #define SDIDREG 0x10 /* w SCSI destination ID reg. */
211 #define SDIREG_MASK 0x07 /* mask */
213 #define STPREG 0x18 /* w synchronous transf. period reg. */
214 #define STPREG_STP 0x1F /* synchr. transfer period */
216 #define CLKFREG 0x24 /* w clock factor reg. */
217 #define CLKFREG_MASK 0x07 /* mask */
219 #define CMDREG 0x0C /* rw SCSI command reg. */
220 #define CMDREG_DMA 0x80 /* set DMA mode (set together with opcodes below) */
221 #define CMDREG_IT 0x10 /* information transfer */
222 #define CMDREG_ICCS 0x11 /* initiator command complete steps */
223 #define CMDREG_MA 0x12 /* message accepted */
224 #define CMDREG_TPB 0x98 /* transfer pad bytes, DMA mode only */
225 #define CMDREG_SATN 0x1A /* set ATN */
226 #define CMDREG_RATN 0x1B /* reset ATN */
227 #define CMDREG_SOAS 0x41 /* select without ATN steps */
228 #define CMDREG_SAS 0x42 /* select with ATN steps (1 msg byte) */
229 #define CMDREG_SASS 0x43 /* select with ATN and stop steps */
230 #define CMDREG_ESR 0x44 /* enable selection/reselection */
231 #define CMDREG_DSR 0x45 /* disable selection/reselection */
232 #define CMDREG_SA3S 0x46 /* select with ATN 3 steps (3 msg bytes) */
233 #define CMDREG_NOP 0x00 /* no operation */
234 #define CMDREG_CFIFO 0x01 /* clear FIFO */
235 #define CMDREG_RDEV 0x02 /* reset device */
236 #define CMDREG_RBUS 0x03 /* reset SCSI bus */
238 #define STATREG 0x10 /* r SCSI status reg. */
239 #define STATREG_INT 0x80 /* SCSI interrupt condition detected */
240 #define STATREG_IOE 0x40 /* SCSI illegal operation error detected */
241 #define STATREG_PE 0x20 /* SCSI parity error detected */
242 #define STATREG_CTZ 0x10 /* CTC reg decremented to zero */
243 #define STATREG_MSG 0x04 /* SCSI MSG phase (latched?) */
244 #define STATREG_CD 0x02 /* SCSI C/D phase (latched?) */
245 #define STATREG_IO 0x01 /* SCSI I/O phase (latched?) */
246 #define STATREG_PHASE 0x07 /* SCSI phase mask */
248 #define INSTREG 0x14 /* r interrupt status reg. */
249 #define INSTREG_SRST 0x80 /* SCSI reset detected */
250 #define INSTREG_ICMD 0x40 /* SCSI invalid command detected */
251 #define INSTREG_DIS 0x20 /* target disconnected or sel/resel timeout */
252 #define INSTREG_SR 0x10 /* device on bus has service request */
253 #define INSTREG_SO 0x08 /* successful operation */
254 #define INSTREG_RESEL 0x04 /* device reselected as initiator */
256 #define ISREG 0x18 /* r internal state reg. */
257 #define ISREG_SOF 0x08 /* synchronous offset flag (act. low) */
258 #define ISREG_IS 0x07 /* status of intermediate op. */
259 #define ISREG_OK_NO_STOP 0x04 /* selection successful */
260 #define ISREG_OK_STOP 0x01 /* selection successful */
262 #define CFIREG 0x1C /* r current FIFO/internal state reg. */
263 #define CFIREG_IS 0xE0 /* status of intermediate op. */
264 #define CFIREG_CF 0x1F /* number of bytes in SCSI FIFO */
266 #define SOFREG 0x1C /* w synchr. offset reg. */
267 #define SOFREG_RAD 0xC0 /* REQ/ACK deassertion delay (sync.) */
268 #define SOFREG_RAA 0x30 /* REQ/ACK assertion delay (sync.) */
269 #define SOFREG_SO 0x0F /* synch. offset (sync.) */
271 #define CNTLREG1 0x20 /* rw control register one */
272 #define CNTLREG1_ETM 0x80 /* set extended timing mode */
273 #define CNTLREG1_DISR 0x40 /* disable interrupt on SCSI reset */
274 #define CNTLREG1_PERE 0x10 /* enable parity error reporting */
275 #define CNTLREG1_SID 0x07 /* host adapter SCSI ID */
277 #define CNTLREG2 0x2C /* rw control register two */
278 #define CNTLREG2_ENF 0x40 /* enable features */
280 #define CNTLREG3 0x30 /* rw control register three */
281 #define CNTLREG3_ADIDCHK 0x80 /* additional ID check */
282 #define CNTLREG3_FASTSCSI 0x10 /* fast SCSI */
283 #define CNTLREG3_FASTCLK 0x08 /* fast SCSI clocking */
285 #define CNTLREG4 0x34 /* rw control register four */
286 #define CNTLREG4_GLITCH 0xC0 /* glitch eater */
287 #define CNTLREG4_PWD 0x20 /* reduced power feature */
288 #define CNTLREG4_RAE 0x08 /* write only, active negot. ctrl. */
289 #define CNTLREG4_RADE 0x04 /* active negot. ctrl. */
290 #define CNTLREG4_RES 0x10 /* reserved bit, must be 1 */
293 #define DMACMD 0x40 /* rw command */
294 #define DMACMD_DIR 0x80 /* transfer direction (1=read from device) */
295 #define DMACMD_INTE_D 0x40 /* DMA transfer interrupt enable */
296 #define DMACMD_INTE_P 0x20 /* page transfer interrupt enable */
297 #define DMACMD_MDL 0x10 /* map to memory descriptor list */
298 #define DMACMD_DIAG 0x04 /* diagnostics, set to 0 */
299 #define DMACMD_IDLE 0x00 /* idle cmd */
300 #define DMACMD_BLAST 0x01 /* flush FIFO to memory */
301 #define DMACMD_ABORT 0x02 /* terminate DMA */
302 #define DMACMD_START 0x03 /* start DMA */
304 #define DMASTATUS 0x54 /* r status register */
305 #define DMASTATUS_BCMPLT 0x20 /* BLAST complete */
306 #define DMASTATUS_SCSIINT 0x10 /* SCSI interrupt pending */
307 #define DMASTATUS_DONE 0x08 /* DMA transfer terminated */
308 #define DMASTATUS_ABORT 0x04 /* DMA transfer aborted */
309 #define DMASTATUS_ERROR 0x02 /* DMA transfer error */
310 #define DMASTATUS_PWDN 0x02 /* power down indicator */
312 #define DMASTC 0x44 /* rw starting transfer count */
313 #define DMASPA 0x48 /* rw starting physical address */
314 #define DMAWBC 0x4C /* r working byte counter */
315 #define DMAWAC 0x50 /* r working address counter */
316 #define DMASMDLA 0x58 /* rw starting MDL address */
317 #define DMAWMAC 0x5C /* r working MDL counter */
319 /*** SCSI phases ***/
320 #define PHASE_MSGIN 0x07
321 #define PHASE_MSGOUT 0x06
322 #define PHASE_RES_1 0x05
323 #define PHASE_RES_0 0x04
324 #define PHASE_STATIN 0x03
325 #define PHASE_CMDOUT 0x02
326 #define PHASE_DATAIN 0x01
327 #define PHASE_DATAOUT 0x00
330 #define AM53C974_local_declare() unsigned long io_port
331 #define AM53C974_setio(instance) io_port = instance->io_port
332 #define AM53C974_read_8(addr) inb(io_port + (addr))
333 #define AM53C974_write_8(addr,x) outb((x), io_port + (addr))
334 #define AM53C974_read_16(addr) inw(io_port + (addr))
335 #define AM53C974_write_16(addr,x) outw((x), io_port + (addr))
336 #define AM53C974_read_32(addr) inl(io_port + (addr))
337 #define AM53C974_write_32(addr,x) outl((x), io_port + (addr))
339 #define AM53C974_poll_int() { do { statreg = AM53C974_read_8(STATREG); } \
340 while (!(statreg & STATREG_INT)) ; \
341 AM53C974_read_8(INSTREG) ; } /* clear int */
342 #define AM53C974_cfifo() (AM53C974_read_8(CFIREG) & CFIREG_CF)
344 /* These are "special" values for the tag parameter passed to AM53C974_select. */
345 #define TAG_NEXT -1 /* Use next free tag */
346 #define TAG_NONE -2 /* Establish I_T_L nexus instead of I_T_L_Q
347 * even on SCSI-II devices */
349 /************ LILO overrides *************/
350 typedef struct _override_t {
351 int host_scsi_id; /* SCSI id of the bus controller */
352 int target_scsi_id; /* SCSI id of target */
353 int max_rate; /* max. transfer rate */
354 int max_offset; /* max. sync. offset, 0 = asynchronous */
358 #ifdef AM53C974_DEBUG
359 static void AM53C974_print_phase(struct Scsi_Host *instance);
360 static void AM53C974_print_queues(struct Scsi_Host *instance);
361 #endif /* AM53C974_DEBUG */
362 static void AM53C974_print(struct Scsi_Host *instance);
363 static void AM53C974_keywait(void);
364 static __inline__ int AM53C974_pci_detect(Scsi_Host_Template * tpnt);
365 static int AM53C974_init(Scsi_Host_Template * tpnt, struct pci_dev *pdev);
366 static void AM53C974_config_after_reset(struct Scsi_Host *instance);
367 static __inline__ void initialize_SCp(Scsi_Cmnd * cmd);
368 static __inline__ void run_main(void);
369 static void AM53C974_main(void);
370 static void AM53C974_intr(int irq, void *dev_id, struct pt_regs *regs);
371 static void do_AM53C974_intr(int irq, void *dev_id, struct pt_regs *regs);
372 static void AM53C974_intr_disconnect(struct Scsi_Host *instance);
373 static int AM53C974_sync_neg(struct Scsi_Host *instance, int target, unsigned char *msg);
374 static __inline__ void AM53C974_set_async(struct Scsi_Host *instance, int target);
375 static __inline__ void AM53C974_set_sync(struct Scsi_Host *instance, int target);
376 static void AM53C974_information_transfer(struct Scsi_Host *instance,
377 unsigned char statreg, unsigned char isreg,
378 unsigned char instreg, unsigned char cfifo,
379 unsigned char dmastatus);
380 static int AM53C974_message(struct Scsi_Host *instance, Scsi_Cmnd * cmd, unsigned char msg);
381 static void AM53C974_select(struct Scsi_Host *instance, Scsi_Cmnd * cmd, int tag);
382 static void AM53C974_intr_reselect(struct Scsi_Host *instance, unsigned char statreg);
383 static __inline__ void AM53C974_transfer_dma(struct Scsi_Host *instance, short dir,
384 unsigned long length, char *data);
385 static void AM53C974_dma_blast(struct Scsi_Host *instance, unsigned char dmastatus,
386 unsigned char statreg);
387 static void AM53C974_intr_bus_reset(struct Scsi_Host *instance);
389 static struct Scsi_Host *first_instance;
390 static Scsi_Host_Template *the_template;
391 static struct Scsi_Host *first_host; /* Head of list of AMD boards */
392 static volatile int main_running;
393 static int commandline_current;
394 override_t overrides[7] =
396 {-1, 0, 0, 0},}; /* LILO overrides */
398 #ifdef AM53C974_DEBUG
399 static int deb_stop = 1;
407 PHASE_DATAOUT, "DATAOUT"
409 PHASE_DATAIN, "DATAIN"
411 PHASE_CMDOUT, "CMDOUT"
414 PHASE_STATIN, "STATIN"
416 PHASE_MSGOUT, "MSGOUT"
421 PHASE_RES_0, "RESERVED 0"
423 PHASE_RES_1, "RESERVED 1"
427 /**************************************************************************
428 * Function : void AM53C974_print_phase(struct Scsi_Host *instance)
430 * Purpose : print the current SCSI phase for debugging purposes
432 * Input : instance - which AM53C974
433 **************************************************************************/
434 static void AM53C974_print_phase(struct Scsi_Host *instance)
436 AM53C974_local_declare();
437 unsigned char statreg, latched;
439 AM53C974_setio(instance);
441 latched = (AM53C974_read_8(CNTLREG2)) & CNTLREG2_ENF;
442 statreg = AM53C974_read_8(STATREG);
443 for (i = 0; (phases[i].value != PHASE_RES_1) &&
444 (phases[i].value != (statreg & STATREG_PHASE)); ++i);
446 printk("scsi%d : phase %s, latched at end of last command\n", instance->host_no, phases[i].name);
448 printk("scsi%d : phase %s, real time\n", instance->host_no, phases[i].name);
451 /**************************************************************************
452 * Function : void AM53C974_print_queues(struct Scsi_Host *instance)
454 * Purpose : print commands in the various queues
456 * Inputs : instance - which AM53C974
457 **************************************************************************/
458 static void AM53C974_print_queues(struct Scsi_Host *instance)
461 struct AM53C974_hostdata *hostdata = (struct AM53C974_hostdata *) instance->hostdata;
464 printk("AM53C974: coroutine is%s running.\n", main_running ? "" : "n't");
469 if (!hostdata->connected) {
470 printk("scsi%d: no currently connected command\n", instance->host_no);
472 print_Scsi_Cmnd((Scsi_Cmnd *) hostdata->connected);
474 if (!hostdata->sel_cmd) {
475 printk("scsi%d: no currently arbitrating command\n", instance->host_no);
477 print_Scsi_Cmnd((Scsi_Cmnd *) hostdata->sel_cmd);
480 printk("scsi%d: issue_queue ", instance->host_no);
481 if (!hostdata->issue_queue)
485 for (ptr = (Scsi_Cmnd *) hostdata->issue_queue; ptr; ptr = (Scsi_Cmnd *) ptr->host_scribble)
486 print_Scsi_Cmnd(ptr);
489 printk("scsi%d: disconnected_queue ", instance->host_no);
490 if (!hostdata->disconnected_queue)
494 for (ptr = (Scsi_Cmnd *) hostdata->disconnected_queue; ptr; ptr = (Scsi_Cmnd *) ptr->host_scribble)
495 print_Scsi_Cmnd(ptr);
498 restore_flags(flags);
501 #endif /* AM53C974_DEBUG */
503 /**************************************************************************
504 * Function : void AM53C974_print(struct Scsi_Host *instance)
506 * Purpose : dump the chip registers for debugging purposes
508 * Input : instance - which AM53C974
509 **************************************************************************/
510 static void AM53C974_print(struct Scsi_Host *instance)
512 AM53C974_local_declare();
514 unsigned long ctcreg, dmastc, dmaspa, dmawbc, dmawac;
515 unsigned char cmdreg, statreg, isreg, cfireg, cntlreg[4], dmacmd,
517 AM53C974_setio(instance);
521 ctcreg = AM53C974_read_8(CTCHREG) << 16;
522 ctcreg |= AM53C974_read_8(CTCMREG) << 8;
523 ctcreg |= AM53C974_read_8(CTCLREG);
524 cmdreg = AM53C974_read_8(CMDREG);
525 statreg = AM53C974_read_8(STATREG);
526 isreg = AM53C974_read_8(ISREG);
527 cfireg = AM53C974_read_8(CFIREG);
528 cntlreg[0] = AM53C974_read_8(CNTLREG1);
529 cntlreg[1] = AM53C974_read_8(CNTLREG2);
530 cntlreg[2] = AM53C974_read_8(CNTLREG3);
531 cntlreg[3] = AM53C974_read_8(CNTLREG4);
532 dmacmd = AM53C974_read_8(DMACMD);
533 dmastc = AM53C974_read_32(DMASTC);
534 dmaspa = AM53C974_read_32(DMASPA);
535 dmawbc = AM53C974_read_32(DMAWBC);
536 dmawac = AM53C974_read_32(DMAWAC);
537 dmastatus = AM53C974_read_8(DMASTATUS);
538 restore_flags(flags);
540 printk("AM53C974 register dump:\n");
541 printk("IO base: 0x%04lx; CTCREG: 0x%04lx; CMDREG: 0x%02x; STATREG: 0x%02x; ISREG: 0x%02x\n",
542 io_port, ctcreg, cmdreg, statreg, isreg);
543 printk("CFIREG: 0x%02x; CNTLREG1-4: 0x%02x; 0x%02x; 0x%02x; 0x%02x\n",
544 cfireg, cntlreg[0], cntlreg[1], cntlreg[2], cntlreg[3]);
545 printk("DMACMD: 0x%02x; DMASTC: 0x%04lx; DMASPA: 0x%04lx\n", dmacmd, dmastc, dmaspa);
546 printk("DMAWBC: 0x%04lx; DMAWAC: 0x%04lx; DMASTATUS: 0x%02x\n", dmawbc, dmawac, dmastatus);
547 printk("---------------------------------------------------------\n");
550 /**************************************************************************
551 * Function : void AM53C974_keywait(void)
553 * Purpose : wait until a key is pressed, if it was the 'r' key leave singlestep mode;
554 * this function is used for debugging only
557 **************************************************************************/
558 static void AM53C974_keywait(void)
561 #ifdef AM53C974_DEBUG
570 while ((inb_p(0x64) & 0x01) != 0x01);
571 #ifdef AM53C974_DEBUG
574 deb_stop = 0; /* don't stop if 'r' was pressed */
576 restore_flags(flags);
580 /**************************************************************************
581 * Function : AM53C974_setup(char *str)
583 * Purpose : LILO command line initialization of the overrides array,
585 * Input : str - parameter string.
589 * NOTE : this function needs to be declared as an external function
590 * in init/main.c and included there in the bootsetups list
591 ***************************************************************************/
592 static int AM53C974_setup(char *str)
596 get_options(str, ARRAY_SIZE(ints), ints);
599 printk("AM53C974_setup: wrong number of parameters;\n correct syntax is: AM53C974=host-scsi-id, target-scsi-id, max-rate, max-offset\n");
601 if (commandline_current < (sizeof(overrides) / sizeof(override_t))) {
602 if ((ints[1] < 0) || (ints[1] > 7) ||
603 (ints[2] < 0) || (ints[2] > 7) ||
604 (ints[1] == ints[2]) ||
605 (ints[3] < (DEF_CLK / MAX_PERIOD)) || (ints[3] > (DEF_CLK / MIN_PERIOD)) ||
606 (ints[4] < 0) || (ints[4] > MAX_OFFSET))
607 printk("AM53C974_setup: illegal parameter\n");
609 overrides[commandline_current].host_scsi_id = ints[1];
610 overrides[commandline_current].target_scsi_id = ints[2];
611 overrides[commandline_current].max_rate = ints[3];
612 overrides[commandline_current].max_offset = ints[4];
613 commandline_current++;
616 printk("AM53C974_setup: too many overrides\n");
621 __setup("AM53C974=", AM53C974_setup);
625 /**************************************************************************
626 * Function : int AM53C974_pci_detect(Scsi_Host_Template *tpnt)
628 * Purpose : detects and initializes AM53C974 SCSI chips with PCI Bios
630 * Inputs : tpnt - host template
632 * Returns : number of host adapters detected
633 **************************************************************************/
634 static int __init AM53C974_pci_detect(Scsi_Host_Template * tpnt)
636 int count = 0; /* number of boards detected */
637 struct pci_dev *pdev = NULL;
638 unsigned short command;
640 while ((pdev = pci_find_device(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_SCSI, pdev))) {
641 if (pci_enable_device(pdev))
643 pci_read_config_word(pdev, PCI_COMMAND, &command);
645 /* check whether device is I/O mapped -- should be */
646 if (!(command & PCI_COMMAND_IO))
649 pci_set_master (pdev);
651 /* everything seems OK now, so initialize */
652 if (AM53C974_init(tpnt, pdev))
658 /**************************************************************************
659 * Function : int AM53C974_init(Scsi_Host_Template *tpnt, struct pci_dev *pdev)
661 * Purpose : initializes instance and corresponding AM53/79C974 chip,
663 * Inputs : tpnt - template, pci_config - PCI configuration,
665 * Returns : 1 on success, 0 on failure.
667 * NOTE: If no override for the controller's SCSI id is given and AM53C974_SCSI_ID
668 * is not defined we assume that the SCSI address of this controller is correctly
669 * set up by the BIOS (as reflected by contents of register CNTLREG1).
670 * This is the only BIOS assistance we need.
671 **************************************************************************/
672 static int __init AM53C974_init(Scsi_Host_Template * tpnt, struct pci_dev *pdev)
674 AM53C974_local_declare();
676 struct Scsi_Host *instance, *search;
677 struct AM53C974_hostdata *hostdata;
679 #ifdef AM53C974_OPTION_DEBUG_PROBE_ONLY
680 printk("AM53C974: probe only enabled, aborting initialization\n");
684 instance = scsi_register(tpnt, sizeof(struct AM53C974_hostdata));
686 printk(KERN_WARNING "AM53C974: Unable to register host, aborting.\n");
689 scsi_set_pci_device(instance, pdev);
690 hostdata = (struct AM53C974_hostdata *) instance->hostdata;
692 instance->io_port = pci_resource_start(pdev, 0);
693 instance->irq = pdev->irq;
694 instance->dma_channel = -1;
695 AM53C974_setio(instance);
697 #ifdef AM53C974_SCSI_ID
698 instance->this_id = AM53C974_SCSI_ID;
699 AM53C974_write_8(CNTLREG1, instance->this_id & CNTLREG1_SID);
701 instance->this_id = AM53C974_read_8(CNTLREG1) & CNTLREG1_SID;
702 if (instance->this_id != 7)
703 printk("scsi%d: WARNING: unusual hostadapter SCSI id %d; please verify!\n",
704 instance->host_no, instance->this_id);
707 for (i = 0; i < sizeof(hostdata->msgout); i++) {
708 hostdata->msgout[i] = NOP;
709 hostdata->last_message[i] = NOP;
711 for (i = 0; i < 8; i++) {
712 hostdata->busy[i] = 0;
713 hostdata->sync_per[i] = DEF_STP;
714 hostdata->sync_off[i] = 0;
715 hostdata->sync_neg[i] = 0;
716 hostdata->sync_en[i] = DEFAULT_SYNC_NEGOTIATION_ENABLED;
717 hostdata->max_rate[i] = DEFAULT_RATE;
718 hostdata->max_offset[i] = DEFAULT_SYNC_OFFSET;
721 /* overwrite defaults by LILO overrides */
722 for (i = 0; i < commandline_current; i++) {
723 if (overrides[i].host_scsi_id == instance->this_id) {
724 j = overrides[i].target_scsi_id;
725 hostdata->sync_en[j] = 1;
726 hostdata->max_rate[j] = overrides[i].max_rate;
727 hostdata->max_offset[j] = overrides[i].max_offset;
731 hostdata->sel_cmd = NULL;
732 hostdata->connected = NULL;
733 hostdata->issue_queue = NULL;
734 hostdata->disconnected_queue = NULL;
735 hostdata->in_reset = 0;
736 hostdata->aborted = 0;
737 hostdata->selecting = 0;
738 hostdata->disconnecting = 0;
739 hostdata->dma_busy = 0;
741 /* Set up an interrupt handler if we aren't already sharing an IRQ with another board */
742 for (search = first_host;
743 search && (((the_template != NULL) && (search->hostt != the_template)) ||
744 (search->irq != instance->irq) || (search == instance));
745 search = search->next);
747 if (request_irq(instance->irq, do_AM53C974_intr, SA_SHIRQ, "AM53C974", instance)) {
748 printk("scsi%d: IRQ%d not free, detaching\n", instance->host_no, instance->irq);
749 scsi_unregister(instance);
753 printk("scsi%d: using interrupt handler previously installed for scsi%d\n",
754 instance->host_no, search->host_no);
758 the_template = instance->hostt;
759 first_instance = instance;
762 AM53C974_write_8(CMDREG, CMDREG_RDEV); /* reset device */
764 AM53C974_write_8(CMDREG, CMDREG_NOP);
765 AM53C974_write_8(CNTLREG1, CNTLREG1_DISR | instance->this_id);
766 AM53C974_write_8(CMDREG, CMDREG_RBUS); /* reset SCSI bus */
768 AM53C974_config_after_reset(instance);
773 /*********************************************************************
774 * Function : AM53C974_config_after_reset(struct Scsi_Host *instance) *
776 * Purpose : initializes chip registers after reset *
778 * Inputs : instance - which AM53C974 *
780 * Returns : nothing *
781 **********************************************************************/
782 static void AM53C974_config_after_reset(struct Scsi_Host *instance)
784 AM53C974_local_declare();
785 AM53C974_setio(instance);
787 /* clear SCSI FIFO */
788 AM53C974_write_8(CMDREG, CMDREG_CFIFO);
790 /* configure device */
791 AM53C974_write_8(STIMREG, DEF_SCSI_TIMEOUT);
792 AM53C974_write_8(STPREG, DEF_STP & STPREG_STP);
793 AM53C974_write_8(SOFREG, (DEF_SOF_RAD << 6) | (DEF_SOF_RAA << 4));
794 AM53C974_write_8(CLKFREG, DEF_CLKF & CLKFREG_MASK);
795 AM53C974_write_8(CNTLREG1, (DEF_ETM << 7) | CNTLREG1_DISR | (DEF_PERE << 4) | instance->this_id);
796 AM53C974_write_8(CNTLREG2, (DEF_ENF << 6));
797 AM53C974_write_8(CNTLREG3, (DEF_ADIDCHK << 7) | (DEF_FASTSCSI << 4) | (DEF_FASTCLK << 3));
798 AM53C974_write_8(CNTLREG4, (DEF_GLITCH << 6) | (DEF_PWD << 5) | (DEF_RAE << 3) | (DEF_RADE << 2) | CNTLREG4_RES);
801 /***********************************************************************
802 * Function : const char *AM53C974_info(struct Scsi_Host *instance) *
804 * Purpose : return device driver information *
806 * Inputs : instance - which AM53C974 *
808 * Returns : info string *
809 ************************************************************************/
810 static const char *AM53C974_info(struct Scsi_Host *instance)
812 static char info[100];
814 sprintf(info, "AM53/79C974 PCscsi driver rev. %d.%d; host I/O address: 0x%lx; irq: %d\n",
815 AM53C974_DRIVER_REVISION_MAJOR, AM53C974_DRIVER_REVISION_MINOR,
816 instance->io_port, instance->irq);
820 /**************************************************************************
821 * Function : int AM53C974_command (Scsi_Cmnd *SCpnt) *
823 * Purpose : the unqueued SCSI command function, replaced by the *
824 * AM53C974_queue_command function *
826 * Inputs : SCpnt - pointer to command structure *
828 * Returns :status, see hosts.h for details *
829 ***************************************************************************/
830 static int AM53C974_command(Scsi_Cmnd * SCpnt)
832 DEB(printk("AM53C974_command called\n"));
836 /**************************************************************************
837 * Function : void initialize_SCp(Scsi_Cmnd *cmd) *
839 * Purpose : initialize the saved data pointers for cmd to point to the *
840 * start of the buffer. *
842 * Inputs : cmd - Scsi_Cmnd structure to have pointers reset. *
844 * Returns : nothing *
845 **************************************************************************/
846 static __inline__ void initialize_SCp(Scsi_Cmnd * cmd)
849 cmd->SCp.buffer = (struct scatterlist *) cmd->buffer;
850 cmd->SCp.buffers_residual = cmd->use_sg - 1;
851 cmd->SCp.ptr = (char *) cmd->SCp.buffer->address;
852 cmd->SCp.this_residual = cmd->SCp.buffer->length;
854 cmd->SCp.buffer = NULL;
855 cmd->SCp.buffers_residual = 0;
856 cmd->SCp.ptr = (char *) cmd->request_buffer;
857 cmd->SCp.this_residual = cmd->request_bufflen;
861 /**************************************************************************
862 * Function : run_main(void) *
864 * Purpose : insure that the coroutine is running and will process our *
865 * request. main_running is checked/set here (in an inline *
866 * function rather than in AM53C974_main itself to reduce the *
867 * chances of stack overflow. *
872 * Returns : nothing *
873 **************************************************************************/
874 static __inline__ void run_main(void)
880 /* main_running is cleared in AM53C974_main once it can't do
881 more work, and AM53C974_main exits with interrupts disabled. */
885 restore_flags(flags);
888 /**************************************************************************
889 * Function : int AM53C974_queue_command(Scsi_Cmnd *cmd, void (*done)(Scsi_Cmnd *))
891 * Purpose : writes SCSI command into AM53C974 FIFO
893 * Inputs : cmd - SCSI command, done - function called on completion, with
894 * a pointer to the command descriptor.
896 * Returns : status, see hosts.h for details
899 * cmd is added to the per instance issue_queue, with minor
900 * twiddling done to the host specific fields of cmd. If the
901 * main coroutine is not running, it is restarted.
902 **************************************************************************/
903 static int AM53C974_queue_command(Scsi_Cmnd * cmd, void (*done) (Scsi_Cmnd *))
906 struct Scsi_Host *instance = cmd->host;
907 struct AM53C974_hostdata *hostdata = (struct AM53C974_hostdata *) instance->hostdata;
912 DEB_QUEUE(printk(SEPARATOR_LINE));
913 DEB_QUEUE(printk("scsi%d: AM53C974_queue_command called\n", instance->host_no));
914 DEB_QUEUE(printk("cmd=%02x target=%02x lun=%02x bufflen=%d use_sg = %02x\n",
915 cmd->cmnd[0], cmd->target, cmd->lun, cmd->request_bufflen, cmd->use_sg));
917 /* We use the host_scribble field as a pointer to the next command in a queue */
918 cmd->host_scribble = NULL;
919 cmd->scsi_done = done;
921 cmd->device->disconnect = 0;
923 /* Insert the cmd into the issue queue. Note that REQUEST SENSE
924 * commands are added to the head of the queue since any command will
925 * clear the contingent allegiance condition that exists and the
926 * sense data is only guaranteed to be valid while the condition exists. */
927 if (!(hostdata->issue_queue) || (cmd->cmnd[0] == REQUEST_SENSE)) {
928 LIST(cmd, hostdata->issue_queue);
929 cmd->host_scribble = (unsigned char *) hostdata->issue_queue;
930 hostdata->issue_queue = cmd;
932 for (tmp = (Scsi_Cmnd *) hostdata->issue_queue; tmp->host_scribble;
933 tmp = (Scsi_Cmnd *) tmp->host_scribble);
935 tmp->host_scribble = (unsigned char *) cmd;
938 DEB_QUEUE(printk("scsi%d : command added to %s of queue\n", instance->host_no,
939 (cmd->cmnd[0] == REQUEST_SENSE) ? "head" : "tail"));
941 /* Run the coroutine if it isn't already running. */
943 restore_flags(flags);
947 /**************************************************************************
948 * Function : AM53C974_main (void)
950 * Purpose : AM53C974_main is a coroutine that runs as long as more work can
951 * be done on the AM53C974 host adapters in a system. Both
952 * AM53C974_queue_command() and AM53C974_intr() will try to start it
953 * in case it is not running.
955 * NOTE : AM53C974_main exits with interrupts *disabled*, the caller should
956 * reenable them. This prevents reentrancy and kernel stack overflow.
957 **************************************************************************/
958 static void AM53C974_main(void)
960 AM53C974_local_declare();
962 Scsi_Cmnd *tmp, *prev;
963 struct Scsi_Host *instance;
964 struct AM53C974_hostdata *hostdata;
967 /* We run (with interrupts disabled) until we're sure that none of
968 * the host adapters have anything that can be done, at which point
969 * we set main_running to 0 and exit. */
972 cli(); /* Freeze request queues */
975 for (instance = first_instance; instance && instance->hostt == the_template;
976 instance = instance->next) {
977 hostdata = (struct AM53C974_hostdata *) instance->hostdata;
978 AM53C974_setio(instance);
979 /* start to select target if we are not connected and not in the
981 if (!hostdata->connected && !hostdata->sel_cmd) {
982 /* Search through the issue_queue for a command destined for a target
984 for (tmp = (Scsi_Cmnd *) hostdata->issue_queue, prev = NULL; tmp;
985 prev = tmp, tmp = (Scsi_Cmnd *) tmp->host_scribble) {
986 /* When we find one, remove it from the issue queue. */
987 if (!(hostdata->busy[tmp->target] & (1 << tmp->lun))) {
989 REMOVE(prev, (Scsi_Cmnd *) (prev->host_scribble), tmp,
990 (Scsi_Cmnd *) (tmp->host_scribble));
991 prev->host_scribble = tmp->host_scribble;
993 REMOVE(-1, hostdata->issue_queue, tmp, tmp->host_scribble);
994 hostdata->issue_queue = (Scsi_Cmnd *) tmp->host_scribble;
996 tmp->host_scribble = NULL;
998 /* go into selection mode, disable reselection and wait for
999 SO interrupt which will continue with the selection process */
1000 hostdata->selecting = 1;
1001 hostdata->sel_cmd = tmp;
1002 AM53C974_write_8(CMDREG, CMDREG_DSR);
1004 } /* if target/lun is not busy */
1007 /* if (!hostdata->connected) */
1009 DEB(printk("main: connected; cmd = 0x%lx, sel_cmd = 0x%lx\n",
1010 (long) hostdata->connected, (long) hostdata->sel_cmd));
1012 } /* for instance */
1015 restore_flags(flags);
1018 /************************************************************************
1019 * Function : AM53C974_intr(int irq, void *dev_id, struct pt_regs *regs) *
1021 * Purpose : interrupt handler *
1023 * Inputs : irq - interrupt line, regs - ? *
1025 * Returns : nothing *
1026 ************************************************************************/
1027 static void do_AM53C974_intr(int irq, void *dev_id, struct pt_regs *regs)
1029 unsigned long flags;
1031 spin_lock_irqsave(&io_request_lock, flags);
1032 AM53C974_intr(irq, dev_id, regs);
1033 spin_unlock_irqrestore(&io_request_lock, flags);
1036 /************************************************************************
1037 * Function : AM53C974_intr(int irq, void *dev_id, struct pt_regs *regs) *
1039 * Purpose : interrupt handler *
1041 * Inputs : irq - interrupt line, regs - ? *
1043 * Returns : nothing *
1044 ************************************************************************/
1045 static void AM53C974_intr(int irq, void *dev_id, struct pt_regs *regs)
1047 AM53C974_local_declare();
1048 struct Scsi_Host *instance;
1049 struct AM53C974_hostdata *hostdata;
1050 unsigned char cmdreg, dmastatus, statreg, isreg, instreg, cfifo;
1052 /* find AM53C974 hostadapter responsible for this interrupt */
1053 for (instance = first_instance; instance; instance = instance->next)
1054 if ((instance->irq == irq) && (instance->hostt == the_template))
1058 /* found; now decode and process */
1060 hostdata = (struct AM53C974_hostdata *) instance->hostdata;
1061 AM53C974_setio(instance);
1062 dmastatus = AM53C974_read_8(DMASTATUS);
1064 DEB_INTR(printk(SEPARATOR_LINE));
1065 DEB_INTR(printk("AM53C974 interrupt; dmastatus=0x%02x\n", dmastatus));
1068 /*** DMA related interrupts ***/
1069 if (hostdata->connected && (dmastatus & (DMASTATUS_ERROR | DMASTATUS_PWDN |
1070 DMASTATUS_ABORT))) {
1071 /* DMA error or POWERDOWN */
1072 printk("scsi%d: DMA error or powerdown; dmastatus: 0x%02x\n",
1073 instance->host_no, dmastatus);
1074 #ifdef AM53C974_DEBUG
1077 panic("scsi%d: cannot recover\n", instance->host_no);
1079 if (hostdata->connected && (dmastatus & DMASTATUS_DONE)) {
1080 /* DMA transfer done */
1081 unsigned long residual;
1082 unsigned long flags;
1085 if (!(AM53C974_read_8(DMACMD) & DMACMD_DIR)) {
1087 dmastatus = AM53C974_read_8(DMASTATUS);
1088 residual = AM53C974_read_8(CTCLREG) | (AM53C974_read_8(CTCMREG) << 8) |
1089 (AM53C974_read_8(CTCHREG) << 16);
1090 residual += AM53C974_read_8(CFIREG) & CFIREG_CF;
1091 } while (!(dmastatus & DMASTATUS_SCSIINT) && residual);
1092 residual = AM53C974_read_8(CTCLREG) | (AM53C974_read_8(CTCMREG) << 8) |
1093 (AM53C974_read_8(CTCHREG) << 16);
1094 residual += AM53C974_read_8(CFIREG) & CFIREG_CF;
1097 hostdata->connected->SCp.ptr += hostdata->connected->SCp.this_residual - residual;
1098 hostdata->connected->SCp.this_residual = residual;
1100 AM53C974_write_8(DMACMD, DMACMD_IDLE);
1102 /* if service request missed before, process it now (ugly) */
1103 if (hostdata->dma_busy) {
1104 hostdata->dma_busy = 0;
1105 cmdreg = AM53C974_read_8(CMDREG);
1106 statreg = AM53C974_read_8(STATREG);
1107 isreg = AM53C974_read_8(ISREG);
1108 instreg = AM53C974_read_8(INSTREG);
1109 cfifo = AM53C974_cfifo();
1110 AM53C974_information_transfer(instance, statreg, isreg, instreg, cfifo,
1113 restore_flags(flags);
1115 if (!(dmastatus & DMASTATUS_SCSIINT)) {
1118 /*** SCSI related interrupts ***/
1119 cmdreg = AM53C974_read_8(CMDREG);
1120 statreg = AM53C974_read_8(STATREG);
1121 isreg = AM53C974_read_8(ISREG);
1122 instreg = AM53C974_read_8(INSTREG);
1123 cfifo = AM53C974_cfifo();
1125 DEB_INTR(printk("scsi%d: statreg: 0x%02x; isreg: 0x%02x; instreg: 0x%02x; cfifo: 0x%02x\n",
1126 instance->host_no, statreg, isreg, instreg, cfifo));
1128 if (statreg & STATREG_PE) {
1130 #ifdef AM53C974_DEBUG
1133 printk("scsi%d : PARITY error\n", instance->host_no);
1134 if (hostdata->connected)
1135 hostdata->sync_off[hostdata->connected->target] = 0; /* setup asynchronous transfer */
1136 hostdata->aborted = 1;
1138 if (statreg & STATREG_IOE) {
1139 /* illegal operation error */
1140 #ifdef AM53C974_DEBUG
1143 printk("scsi%d : ILLEGAL OPERATION error\n", instance->host_no);
1144 printk("cmdreg: 0x%02x; dmacmd: 0x%02x; statreg: 0x%02x; \n"
1145 "isreg: 0x%02x; instreg: 0x%02x; cfifo: 0x%02x\n",
1146 cmdreg, AM53C974_read_8(DMACMD), statreg, isreg, instreg, cfifo);
1148 if (hostdata->in_reset && (instreg & INSTREG_SRST)) {
1149 unsigned long flags;
1150 /* RESET INTERRUPT */
1151 #ifdef AM53C974_DEBUG
1154 DEB(printk("Bus reset interrupt received\n"));
1155 AM53C974_intr_bus_reset(instance);
1158 if (hostdata->connected) {
1159 hostdata->connected->result = DID_RESET << 16;
1160 hostdata->connected->scsi_done((Scsi_Cmnd *) hostdata->connected);
1161 hostdata->connected = NULL;
1163 if (hostdata->sel_cmd) {
1164 hostdata->sel_cmd->result = DID_RESET << 16;
1165 hostdata->sel_cmd->scsi_done((Scsi_Cmnd *) hostdata->sel_cmd);
1166 hostdata->sel_cmd = NULL;
1169 restore_flags(flags);
1170 if (hostdata->in_reset == 1)
1175 if (instreg & INSTREG_ICMD) {
1176 /* INVALID COMMAND INTERRUPT */
1177 #ifdef AM53C974_DEBUG
1180 printk("scsi%d: Invalid command interrupt\n", instance->host_no);
1181 printk("cmdreg: 0x%02x; dmacmd: 0x%02x; statreg: 0x%02x; dmastatus: 0x%02x; \n"
1182 "isreg: 0x%02x; instreg: 0x%02x; cfifo: 0x%02x\n",
1183 cmdreg, AM53C974_read_8(DMACMD), statreg, dmastatus, isreg, instreg, cfifo);
1184 panic("scsi%d: cannot recover\n", instance->host_no);
1186 if (instreg & INSTREG_DIS) {
1187 unsigned long flags;
1188 /* DISCONNECT INTERRUPT */
1189 DEB_INTR(printk("Disconnect interrupt received; "));
1192 AM53C974_intr_disconnect(instance);
1193 restore_flags(flags);
1196 if (instreg & INSTREG_RESEL) {
1197 unsigned long flags;
1198 /* RESELECTION INTERRUPT */
1199 DEB_INTR(printk("Reselection interrupt received\n"));
1202 AM53C974_intr_reselect(instance, statreg);
1203 restore_flags(flags);
1206 if (instreg & INSTREG_SO) {
1207 DEB_INTR(printk("Successful operation interrupt received\n"));
1208 if (hostdata->selecting) {
1209 unsigned long flags;
1210 DEB_INTR(printk("DSR completed, starting select\n"));
1213 AM53C974_select(instance, (Scsi_Cmnd *) hostdata->sel_cmd,
1214 (hostdata->sel_cmd->cmnd[0] == REQUEST_SENSE) ?
1215 TAG_NONE : TAG_NEXT);
1216 hostdata->selecting = 0;
1217 AM53C974_set_sync(instance, hostdata->sel_cmd->target);
1218 restore_flags(flags);
1221 if (hostdata->sel_cmd != NULL) {
1222 if (((isreg & ISREG_IS) != ISREG_OK_NO_STOP) &&
1223 ((isreg & ISREG_IS) != ISREG_OK_STOP)) {
1224 unsigned long flags;
1225 /* UNSUCCESSFUL SELECTION */
1226 DEB_INTR(printk("unsuccessful selection\n"));
1229 hostdata->dma_busy = 0;
1230 LIST(hostdata->sel_cmd, hostdata->issue_queue);
1231 hostdata->sel_cmd->host_scribble = (unsigned char *) hostdata->issue_queue;
1232 hostdata->issue_queue = hostdata->sel_cmd;
1233 hostdata->sel_cmd = NULL;
1234 hostdata->selecting = 0;
1235 restore_flags(flags);
1238 unsigned long flags;
1239 /* SUCCESSFUL SELECTION */
1240 DEB(printk("successful selection; cmd=0x%02lx\n", (long) hostdata->sel_cmd));
1243 hostdata->dma_busy = 0;
1244 hostdata->disconnecting = 0;
1245 hostdata->connected = hostdata->sel_cmd;
1246 hostdata->sel_cmd = NULL;
1247 hostdata->selecting = 0;
1249 if (!hostdata->connected->device->tagged_queue)
1251 hostdata->busy[hostdata->connected->target] |= (1 << hostdata->connected->lun);
1252 /* very strange -- use_sg is sometimes nonzero for request sense commands !! */
1253 if ((hostdata->connected->cmnd[0] == REQUEST_SENSE) && hostdata->connected->use_sg) {
1254 DEB(printk("scsi%d: REQUEST_SENSE command with nonzero use_sg\n", instance->host_no));
1256 hostdata->connected->use_sg = 0;
1258 initialize_SCp((Scsi_Cmnd *) hostdata->connected);
1259 hostdata->connected->SCp.phase = PHASE_CMDOUT;
1260 AM53C974_information_transfer(instance, statreg, isreg, instreg, cfifo, dmastatus);
1261 restore_flags(flags);
1265 unsigned long flags;
1268 AM53C974_information_transfer(instance, statreg, isreg, instreg, cfifo, dmastatus);
1269 restore_flags(flags);
1273 if (instreg & INSTREG_SR) {
1274 DEB_INTR(printk("Service request interrupt received, "));
1275 if (hostdata->connected) {
1276 unsigned long flags;
1277 DEB_INTR(printk("calling information_transfer\n"));
1280 AM53C974_information_transfer(instance, statreg, isreg, instreg, cfifo, dmastatus);
1281 restore_flags(flags);
1283 printk("scsi%d: weird: service request when no command connected\n", instance->host_no);
1284 AM53C974_write_8(CMDREG, CMDREG_CFIFO);
1289 DEB_INTR(printk("intr: starting main\n"));
1291 DEB_INTR(printk("end of intr\n"));
1294 /**************************************************************************
1295 * Function : AM53C974_intr_disconnect(struct Scsi_Host *instance)
1297 * Purpose : manage target disconnection
1299 * Inputs : instance -- which AM53C974
1302 **************************************************************************/
1303 static void AM53C974_intr_disconnect(struct Scsi_Host *instance)
1305 AM53C974_local_declare();
1306 struct AM53C974_hostdata *hostdata = (struct AM53C974_hostdata *) instance->hostdata;
1308 AM53C974_setio(instance);
1310 if (hostdata->sel_cmd != NULL) {
1311 /* normal selection timeout, typical for nonexisting targets */
1312 cmd = (Scsi_Cmnd *) hostdata->sel_cmd;
1313 DEB_INTR(printk("bad target\n"));
1314 cmd->result = DID_BAD_TARGET << 16;
1317 if (!hostdata->connected) {
1318 /* can happen if controller was reset, a device tried to reconnect,
1319 failed and disconnects now */
1320 AM53C974_write_8(CMDREG, CMDREG_CFIFO);
1323 if (hostdata->disconnecting) {
1324 /* target sent disconnect message, so we are prepared */
1325 cmd = (Scsi_Cmnd *) hostdata->connected;
1326 AM53C974_set_async(instance, cmd->target);
1327 DEB_INTR(printk("scsi%d : disc. from cmnd %d for ta %d, lun %d\n",
1328 instance->host_no, cmd->cmnd[0], cmd->target, cmd->lun));
1329 if (cmd->device->disconnect) {
1330 /* target wants to reselect later */
1331 DEB_INTR(printk("ok, re-enabling selection\n"));
1332 LIST(cmd, hostdata->disconnected_queue);
1333 cmd->host_scribble = (unsigned char *) hostdata->disconnected_queue;
1334 hostdata->disconnected_queue = cmd;
1335 DEB_QUEUE(printk("scsi%d : command for target %d lun %d this %d was moved from connected to"
1336 " the disconnected_queue\n", instance->host_no, cmd->target,
1337 cmd->lun, hostdata->disconnected_queue->SCp.this_residual));
1338 DEB_QUEUE(AM53C974_print_queues(instance));
1339 goto EXIT_UNFINISHED;
1341 /* target does not want to reselect later, we are really finished */
1342 #ifdef AM53C974_DEBUG
1343 if (cmd->cmnd[0] == REQUEST_SENSE) {
1345 printk("Request sense data dump:\n");
1346 for (i = 0; i < cmd->request_bufflen; i++) {
1347 printk("%02x ", *((char *) (cmd->request_buffer) + i));
1355 } /* !cmd->device->disconnect */
1356 } /* if (hostdata->disconnecting) */
1357 /* no disconnect message received; unexpected disconnection */
1358 cmd = (Scsi_Cmnd *) hostdata->connected;
1360 #ifdef AM53C974_DEBUG
1363 AM53C974_set_async(instance, cmd->target);
1364 printk("scsi%d: Unexpected disconnect; phase: %d; target: %d; this_residual: %d; buffers_residual: %d; message: %d\n",
1365 instance->host_no, cmd->SCp.phase, cmd->target, cmd->SCp.this_residual, cmd->SCp.buffers_residual,
1367 printk("cmdreg: 0x%02x; statreg: 0x%02x; isreg: 0x%02x; cfifo: 0x%02x\n",
1368 AM53C974_read_8(CMDREG), AM53C974_read_8(STATREG), AM53C974_read_8(ISREG),
1369 AM53C974_read_8(CFIREG) & CFIREG_CF);
1371 if ((hostdata->last_message[0] == EXTENDED_MESSAGE) &&
1372 (hostdata->last_message[2] == EXTENDED_SDTR)) {
1373 /* sync. negotiation was aborted, setup asynchronous transfer with target */
1374 hostdata->sync_off[cmd->target] = 0;
1376 if (hostdata->aborted || hostdata->msgout[0] == ABORT)
1377 cmd->result = DID_ABORT << 16;
1379 cmd->result = DID_ERROR << 16;
1383 hostdata->aborted = 0;
1384 hostdata->msgout[0] = NOP;
1385 hostdata->sel_cmd = NULL;
1386 hostdata->connected = NULL;
1387 hostdata->selecting = 0;
1388 hostdata->disconnecting = 0;
1389 hostdata->dma_busy = 0;
1390 hostdata->busy[cmd->target] &= ~(1 << cmd->lun);
1391 AM53C974_write_8(CMDREG, CMDREG_CFIFO);
1392 DEB(printk("disconnect; issue_queue: 0x%lx, disconnected_queue: 0x%lx\n",
1393 (long) hostdata->issue_queue, (long) hostdata->disconnected_queue));
1394 cmd->scsi_done(cmd);
1396 if (!hostdata->selecting) {
1397 AM53C974_set_async(instance, cmd->target);
1398 AM53C974_write_8(CMDREG, CMDREG_ESR);
1399 } /* allow reselect */
1403 hostdata->msgout[0] = NOP;
1404 hostdata->sel_cmd = NULL;
1405 hostdata->connected = NULL;
1406 hostdata->aborted = 0;
1407 hostdata->selecting = 0;
1408 hostdata->disconnecting = 0;
1409 hostdata->dma_busy = 0;
1410 DEB(printk("disconnect; issue_queue: 0x%lx, disconnected_queue: 0x%lx\n",
1411 (long) hostdata->issue_queue, (long) hostdata->disconnected_queue));
1412 if (!hostdata->selecting) {
1413 AM53C974_set_async(instance, cmd->target);
1414 AM53C974_write_8(CMDREG, CMDREG_ESR);
1415 } /* allow reselect */
1419 /**************************************************************************
1420 * Function : int AM53C974_sync_neg(struct Scsi_Host *instance, int target, unsigned char *msg)
1422 * Purpose : setup message string for sync. negotiation
1424 * Inputs : instance -- which AM53C974
1425 * target -- which SCSI target to deal with
1426 * msg -- input message string
1428 * Returns : 0 if parameters accepted or 1 if not accepted
1430 * Side effects: hostdata is changed
1432 * Note: we assume here that fastclk is enabled
1433 **************************************************************************/
1434 static int AM53C974_sync_neg(struct Scsi_Host *instance, int target, unsigned char *msg)
1436 AM53C974_local_declare();
1437 struct AM53C974_hostdata *hostdata = (struct AM53C974_hostdata *) instance->hostdata;
1438 int period, offset, i, rate, rate_rem;
1439 AM53C974_setio(instance);
1441 period = (DEF_CLK * msg[3] * 8 + 1000) / 2000;
1442 if (period < MIN_PERIOD) {
1443 period = MIN_PERIOD;
1444 hostdata->msgout[3] = period / 4;
1445 } else if (period > MAX_PERIOD) {
1446 period = MAX_PERIOD;
1447 hostdata->msgout[3] = period / 4;
1449 hostdata->msgout[3] = msg[3];
1451 if (offset > MAX_OFFSET)
1452 offset = MAX_OFFSET;
1453 hostdata->msgout[4] = offset;
1454 hostdata->sync_per[target] = period;
1455 hostdata->sync_off[target] = offset;
1456 for (i = 0; i < 3; i++)
1457 hostdata->msgout[i] = msg[i];
1458 if ((hostdata->msgout[3] != msg[3]) || (msg[4] != offset))
1461 rate = DEF_CLK / period;
1462 rate_rem = 10 * (DEF_CLK - period * rate) / period;
1465 printk("\ntarget %d: rate=%d.%d Mhz, synchronous, sync offset=%d bytes\n",
1466 target, rate, rate_rem, offset);
1468 printk("\ntarget %d: rate=%d.%d Mhz, asynchronous\n", target, rate, rate_rem);
1473 /**************************************************************************
1474 * Function : AM53C974_set_async(struct Scsi_Host *instance, int target)
1476 * Purpose : put controller into async. mode
1478 * Inputs : instance -- which AM53C974
1479 * target -- which SCSI target to deal with
1482 **************************************************************************/
1483 static __inline__ void AM53C974_set_async(struct Scsi_Host *instance, int target)
1485 AM53C974_local_declare();
1486 struct AM53C974_hostdata *hostdata = (struct AM53C974_hostdata *) instance->hostdata;
1487 AM53C974_setio(instance);
1489 AM53C974_write_8(STPREG, hostdata->sync_per[target]);
1490 AM53C974_write_8(SOFREG, (DEF_SOF_RAD << 6) | (DEF_SOF_RAA << 4));
1493 /**************************************************************************
1494 * Function : AM53C974_set_sync(struct Scsi_Host *instance, int target)
1496 * Purpose : put controller into sync. mode
1498 * Inputs : instance -- which AM53C974
1499 * target -- which SCSI target to deal with
1502 **************************************************************************/
1503 static __inline__ void AM53C974_set_sync(struct Scsi_Host *instance, int target)
1505 AM53C974_local_declare();
1506 struct AM53C974_hostdata *hostdata = (struct AM53C974_hostdata *) instance->hostdata;
1507 AM53C974_setio(instance);
1509 AM53C974_write_8(STPREG, hostdata->sync_per[target]);
1510 AM53C974_write_8(SOFREG, (SOFREG_SO & hostdata->sync_off[target]) |
1511 (DEF_SOF_RAD << 6) | (DEF_SOF_RAA << 4));
1514 /***********************************************************************
1515 * Function : AM53C974_information_transfer(struct Scsi_Host *instance, *
1516 * unsigned char statreg, unsigned char isreg, *
1517 * unsigned char instreg, unsigned char cfifo, *
1518 * unsigned char dmastatus) *
1520 * Purpose : handle phase changes *
1522 * Inputs : instance - which AM53C974 *
1523 * statreg - status register *
1524 * isreg - internal state register *
1525 * instreg - interrupt status register *
1526 * cfifo - number of bytes in FIFO *
1527 * dmastatus - dma status register *
1529 * Returns : nothing *
1530 ************************************************************************/
1531 static void AM53C974_information_transfer(struct Scsi_Host *instance,
1532 unsigned char statreg, unsigned char isreg,
1533 unsigned char instreg, unsigned char cfifo,
1534 unsigned char dmastatus)
1536 AM53C974_local_declare();
1537 struct AM53C974_hostdata *hostdata = (struct AM53C974_hostdata *) instance->hostdata;
1538 Scsi_Cmnd *cmd = (Scsi_Cmnd *) hostdata->connected;
1539 int ret, i, len, residual = -1;
1540 AM53C974_setio(instance);
1542 DEB_INFO(printk(SEPARATOR_LINE));
1543 switch (statreg & STATREG_PHASE) { /* scsi phase */
1545 DEB_INFO(printk("Dataout phase; cmd=0x%lx, sel_cmd=0x%lx, this_residual=%d, buffers_residual=%d\n",
1546 (long) hostdata->connected, (long) hostdata->sel_cmd, cmd->SCp.this_residual, cmd->SCp.buffers_residual));
1547 cmd->SCp.phase = PHASE_DATAOUT;
1551 DEB_INFO(printk("Datain phase; cmd=0x%lx, sel_cmd=0x%lx, this_residual=%d, buffers_residual=%d\n",
1552 (long) hostdata->connected, (long) hostdata->sel_cmd, cmd->SCp.this_residual, cmd->SCp.buffers_residual));
1553 cmd->SCp.phase = PHASE_DATAIN;
1555 if (hostdata->aborted) {
1556 AM53C974_write_8(DMACMD, DMACMD_IDLE);
1557 AM53C974_write_8(CMDREG, CMDREG_CFIFO);
1558 AM53C974_write_8(CMDREG, CMDREG_SATN);
1561 if ((!cmd->SCp.this_residual) && cmd->SCp.buffers_residual) {
1563 cmd->SCp.buffers_residual--;
1564 cmd->SCp.ptr = (unsigned char *) cmd->SCp.buffer->address;
1565 cmd->SCp.this_residual = cmd->SCp.buffer->length;
1567 if (cmd->SCp.this_residual) {
1568 if (!(AM53C974_read_8(DMACMD) & DMACMD_START)) {
1569 hostdata->dma_busy = 0;
1570 AM53C974_transfer_dma(instance, statreg & STATREG_IO,
1571 (unsigned long) cmd->SCp.this_residual,
1574 hostdata->dma_busy = 1;
1579 DEB_INFO(printk("Message-In phase; cmd=0x%lx, sel_cmd=0x%lx\n",
1580 (long) hostdata->connected, (long) hostdata->sel_cmd));
1581 AM53C974_set_async(instance, cmd->target);
1582 if (cmd->SCp.phase == PHASE_DATAIN)
1583 AM53C974_dma_blast(instance, dmastatus, statreg);
1584 if ((cmd->SCp.phase == PHASE_DATAOUT) && (AM53C974_read_8(DMACMD) & DMACMD_START)) {
1585 AM53C974_write_8(DMACMD, DMACMD_IDLE);
1586 residual = cfifo + (AM53C974_read_8(CTCLREG) | (AM53C974_read_8(CTCMREG) << 8) |
1587 (AM53C974_read_8(CTCHREG) << 16));
1588 cmd->SCp.ptr += cmd->SCp.this_residual - residual;
1589 cmd->SCp.this_residual = residual;
1591 AM53C974_write_8(CMDREG, CMDREG_CFIFO);
1595 if (cmd->SCp.phase == PHASE_STATIN) {
1596 while ((AM53C974_read_8(CFIREG) & CFIREG_CF) < 2);
1597 cmd->SCp.Status = AM53C974_read_8(FFREG);
1598 cmd->SCp.Message = AM53C974_read_8(FFREG);
1599 DEB_INFO(printk("Message-In phase; status=0x%02x, message=0x%02x\n",
1600 cmd->SCp.Status, cmd->SCp.Message));
1601 ret = AM53C974_message(instance, cmd, cmd->SCp.Message);
1604 AM53C974_write_8(CMDREG, CMDREG_IT);
1605 AM53C974_poll_int();
1606 cmd->SCp.Message = AM53C974_read_8(FFREG);
1608 ret = AM53C974_message(instance, cmd, cmd->SCp.Message);
1610 cmd->SCp.phase = PHASE_MSGIN;
1611 AM53C974_set_sync(instance, cmd->target);
1614 DEB_INFO(printk("Message-Out phase; cfifo=%d; msgout[0]=0x%02x\n",
1615 AM53C974_read_8(CFIREG) & CFIREG_CF, hostdata->msgout[0]));
1616 AM53C974_write_8(DMACMD, DMACMD_IDLE);
1617 AM53C974_set_async(instance, cmd->target);
1618 for (i = 0; i < sizeof(hostdata->last_message); i++)
1619 hostdata->last_message[i] = hostdata->msgout[i];
1620 if ((hostdata->msgout[0] == 0) || INSIDE(hostdata->msgout[0], 0x02, 0x1F) ||
1621 INSIDE(hostdata->msgout[0], 0x80, 0xFF))
1624 if (hostdata->msgout[0] == EXTENDED_MESSAGE) {
1625 #ifdef AM53C974_DEBUG_INFO
1626 printk("Extended message dump:\n");
1627 for (i = 0; i < hostdata->msgout[1] + 2; i++) {
1628 printk("%02x ", hostdata->msgout[i]);
1634 len = hostdata->msgout[1] + 2;
1638 for (i = 0; i < len; i++)
1639 AM53C974_write_8(FFREG, hostdata->msgout[i]);
1640 AM53C974_write_8(CMDREG, CMDREG_IT);
1641 cmd->SCp.phase = PHASE_MSGOUT;
1642 hostdata->msgout[0] = NOP;
1643 AM53C974_set_sync(instance, cmd->target);
1647 DEB_INFO(printk("Command-Out phase\n"));
1648 AM53C974_set_async(instance, cmd->target);
1649 for (i = 0; i < cmd->cmd_len; i++)
1650 AM53C974_write_8(FFREG, cmd->cmnd[i]);
1651 AM53C974_write_8(CMDREG, CMDREG_IT);
1652 cmd->SCp.phase = PHASE_CMDOUT;
1653 AM53C974_set_sync(instance, cmd->target);
1657 DEB_INFO(printk("Status phase\n"));
1658 if (cmd->SCp.phase == PHASE_DATAIN)
1659 AM53C974_dma_blast(instance, dmastatus, statreg);
1660 AM53C974_set_async(instance, cmd->target);
1661 if (cmd->SCp.phase == PHASE_DATAOUT) {
1662 unsigned long residual;
1664 if (AM53C974_read_8(DMACMD) & DMACMD_START) {
1665 AM53C974_write_8(DMACMD, DMACMD_IDLE);
1666 residual = cfifo + (AM53C974_read_8(CTCLREG) | (AM53C974_read_8(CTCMREG) << 8) |
1667 (AM53C974_read_8(CTCHREG) << 16));
1668 cmd->SCp.ptr += cmd->SCp.this_residual - residual;
1669 cmd->SCp.this_residual = residual;
1672 AM53C974_write_8(CMDREG, CMDREG_CFIFO);
1676 cmd->SCp.phase = PHASE_STATIN;
1677 AM53C974_write_8(CMDREG, CMDREG_ICCS); /* command complete */
1682 #ifdef AM53C974_DEBUG
1685 DEB_INFO(printk("Reserved phase\n"));
1691 /******************************************************************************
1692 * Function : int AM53C974_message(struct Scsi_Host *instance, Scsi_Cmnd *cmd,
1693 * unsigned char msg)
1695 * Purpose : handle SCSI messages
1697 * Inputs : instance -- which AM53C974
1698 * cmd -- SCSI command the message belongs to
1699 * msg -- message id byte
1701 * Returns : 1 on success, 0 on failure.
1702 **************************************************************************/
1703 static int AM53C974_message(struct Scsi_Host *instance, Scsi_Cmnd * cmd,
1706 AM53C974_local_declare();
1707 static unsigned char extended_msg[10];
1708 unsigned char statreg;
1711 #ifdef AM53C974_DEBUG_MSG
1714 struct AM53C974_hostdata *hostdata = (struct AM53C974_hostdata *) instance->hostdata;
1715 AM53C974_setio(instance);
1717 DEB_MSG(printk(SEPARATOR_LINE));
1719 /* Linking lets us reduce the time required to get the
1720 * next command out to the device, hopefully this will
1721 * mean we don't waste another revolution due to the delays
1722 * required by ARBITRATION and another SELECTION.
1723 * In the current implementation proposal, low level drivers
1724 * merely have to start the next command, pointed to by
1725 * next_link, done() is called as with unlinked commands. */
1728 case LINKED_CMD_COMPLETE:
1729 case LINKED_FLG_CMD_COMPLETE:
1730 /* Accept message by releasing ACK */
1731 DEB_LINKED(printk("scsi%d : target %d lun %d linked command complete.\n",
1732 instance->host_no, cmd->target, cmd->lun));
1733 /* Sanity check : A linked command should only terminate with
1734 * one of these messages if there are more linked commands available. */
1735 if (!cmd->next_link) {
1736 printk("scsi%d : target %d lun %d linked command complete, no next_link\n"
1737 instance->host_no, cmd->target, cmd->lun);
1738 hostdata->aborted = 1;
1739 AM53C974_write_8(CMDREG, CMDREG_SATN);
1740 AM53C974_write_8(CMDREG, CMDREG_MA);
1743 if (hostdata->aborted) {
1744 DEB_ABORT(printk("ATN set for cmnd %d upon reception of LINKED_CMD_COMPLETE or"
1745 "LINKED_FLG_CMD_COMPLETE message\n", cmd->cmnd[0]));
1746 AM53C974_write_8(CMDREG, CMDREG_SATN);
1748 AM53C974_write_8(CMDREG, CMDREG_MA);
1750 initialize_SCp(cmd->next_link);
1751 /* The next command is still part of this process */
1752 cmd->next_link->tag = cmd->tag;
1753 cmd->result = cmd->SCp.Status | (cmd->SCp.Message << 8);
1754 DEB_LINKED(printk("scsi%d : target %d lun %d linked request done, calling scsi_done().\n",
1755 instance->host_no, cmd->target, cmd->lun));
1756 cmd->scsi_done(cmd);
1757 cmd = hostdata->connected;
1760 #endif /* def LINKED */
1763 case COMMAND_COMPLETE:
1764 DEB_MSG(printk("scsi%d: command complete message received; cmd %d for target %d, lun %d\n",
1765 instance->host_no, cmd->cmnd[0], cmd->target, cmd->lun));
1766 hostdata->disconnecting = 1;
1767 cmd->device->disconnect = 0;
1769 /* I'm not sure what the correct thing to do here is :
1771 * If the command that just executed is NOT a request
1772 * sense, the obvious thing to do is to set the result
1773 * code to the values of the stored parameters.
1774 * If it was a REQUEST SENSE command, we need some way
1775 * to differentiate between the failure code of the original
1776 * and the failure code of the REQUEST sense - the obvious
1777 * case is success, where we fall through and leave the result
1780 * The non-obvious place is where the REQUEST SENSE failed */
1781 if (cmd->cmnd[0] != REQUEST_SENSE)
1782 cmd->result = cmd->SCp.Status | (cmd->SCp.Message << 8);
1783 else if (cmd->SCp.Status != GOOD)
1784 cmd->result = (cmd->result & 0x00ffff) | (DID_ERROR << 16);
1785 if (hostdata->aborted) {
1786 AM53C974_write_8(CMDREG, CMDREG_SATN);
1787 AM53C974_write_8(CMDREG, CMDREG_MA);
1788 DEB_ABORT(printk("ATN set for cmnd %d upon reception of ABORT or"
1789 "COMMAND_COMPLETE message\n", cmd->cmnd[0]));
1792 if ((cmd->cmnd[0] != REQUEST_SENSE) && (cmd->SCp.Status == CHECK_CONDITION)) {
1793 DEB_MSG(printk("scsi%d : performing request sense\n", instance->host_no));
1794 cmd->cmnd[0] = REQUEST_SENSE;
1795 cmd->cmnd[1] &= 0xe0;
1798 cmd->cmnd[4] = sizeof(cmd->sense_buffer);
1800 cmd->SCp.buffer = NULL;
1801 cmd->SCp.buffers_residual = 0;
1802 cmd->SCp.ptr = (char *) cmd->sense_buffer;
1803 cmd->SCp.this_residual = sizeof(cmd->sense_buffer);
1804 LIST(cmd, hostdata->issue_queue);
1805 cmd->host_scribble = (unsigned char *) hostdata->issue_queue;
1806 hostdata->issue_queue = (Scsi_Cmnd *) cmd;
1807 DEB_MSG(printk("scsi%d : REQUEST SENSE added to head of issue queue\n", instance->host_no));
1809 /* Accept message by clearing ACK */
1810 AM53C974_write_8(CMDREG, CMDREG_MA);
1813 case MESSAGE_REJECT:
1814 DEB_MSG(printk("scsi%d: reject message received; cmd %d for target %d, lun %d\n",
1815 instance->host_no, cmd->cmnd[0], cmd->target, cmd->lun));
1816 switch (hostdata->last_message[0]) {
1817 case EXTENDED_MESSAGE:
1818 if (hostdata->last_message[2] == EXTENDED_SDTR) {
1819 /* sync. negotiation was rejected, setup asynchronous transfer with target */
1820 printk("\ntarget %d: rate=%d Mhz, asynchronous (sync. negotiation rejected)\n",
1821 cmd->target, DEF_CLK / DEF_STP);
1822 hostdata->sync_off[cmd->target] = 0;
1823 hostdata->sync_per[cmd->target] = DEF_STP;
1826 case HEAD_OF_QUEUE_TAG:
1827 case ORDERED_QUEUE_TAG:
1828 case SIMPLE_QUEUE_TAG:
1829 cmd->device->tagged_queue = 0;
1830 hostdata->busy[cmd->target] |= (1 << cmd->lun);
1835 if (hostdata->aborted)
1836 AM53C974_write_8(CMDREG, CMDREG_SATN);
1837 AM53C974_write_8(CMDREG, CMDREG_MA);
1841 DEB_MSG(printk("scsi%d: disconnect message received; cmd %d for target %d, lun %d\n",
1842 instance->host_no, cmd->cmnd[0], cmd->target, cmd->lun));
1843 cmd->device->disconnect = 1;
1844 hostdata->disconnecting = 1;
1845 AM53C974_write_8(CMDREG, CMDREG_MA); /* Accept message by clearing ACK */
1849 case RESTORE_POINTERS:
1850 DEB_MSG(printk("scsi%d: save/restore pointers message received; cmd %d for target %d, lun %d\n",
1851 instance->host_no, cmd->cmnd[0], cmd->target, cmd->lun));
1852 /* The SCSI data pointer is *IMPLICITLY* saved on a disconnect
1853 * operation, in violation of the SCSI spec so we can safely
1854 * ignore SAVE/RESTORE pointers calls.
1856 * Unfortunately, some disks violate the SCSI spec and
1857 * don't issue the required SAVE_POINTERS message before
1858 * disconnecting, and we have to break spec to remain
1860 if (hostdata->aborted) {
1861 DEB_ABORT(printk("ATN set for cmnd %d upon reception of SAVE/REST. POINTERS message\n",
1863 AM53C974_write_8(CMDREG, CMDREG_SATN);
1865 AM53C974_write_8(CMDREG, CMDREG_MA);
1868 case EXTENDED_MESSAGE:
1869 DEB_MSG(printk("scsi%d: extended message received; cmd %d for target %d, lun %d\n",
1870 instance->host_no, cmd->cmnd[0], cmd->target, cmd->lun));
1871 /* Extended messages are sent in the following format :
1873 * 0 EXTENDED_MESSAGE == 1
1874 * 1 length (includes one byte for code, doesn't include first two bytes)
1876 * 3..length+1 arguments
1878 /* BEWARE!! THIS CODE IS EXTREMELY UGLY */
1879 extended_msg[0] = EXTENDED_MESSAGE;
1880 AM53C974_read_8(INSTREG); /* clear int */
1881 AM53C974_write_8(CMDREG, CMDREG_MA); /* ack. msg byte, then wait for SO */
1882 AM53C974_poll_int();
1884 AM53C974_write_8(CMDREG, CMDREG_IT);
1885 AM53C974_poll_int();
1886 AM53C974_write_8(CMDREG, CMDREG_MA); /* ack. msg byte, then wait for SO */
1887 AM53C974_poll_int();
1888 extended_msg[1] = len = AM53C974_read_8(FFREG); /* get length */
1889 p = extended_msg + 2;
1890 /* read the remaining (len) bytes */
1892 AM53C974_write_8(CMDREG, CMDREG_IT);
1893 AM53C974_poll_int();
1895 AM53C974_write_8(CMDREG, CMDREG_MA); /* ack. msg byte, then wait for SO */
1896 AM53C974_poll_int();
1898 *p = AM53C974_read_8(FFREG);
1903 #ifdef AM53C974_DEBUG_MSG
1904 printk("scsi%d: received extended message: ", instance->host_no);
1905 for (j = 0; j < extended_msg[1] + 2; j++) {
1906 printk("0x%02x ", extended_msg[j]);
1914 if (extended_msg[2] == EXTENDED_SDTR)
1915 ret = AM53C974_sync_neg(instance, cmd->target, extended_msg);
1916 if (ret || hostdata->aborted)
1917 AM53C974_write_8(CMDREG, CMDREG_SATN);
1919 AM53C974_write_8(CMDREG, CMDREG_MA);
1923 printk("scsi%d: unknown message 0x%02x received\n", instance->host_no, msg);
1924 #ifdef AM53C974_DEBUG
1927 /* reject message */
1928 hostdata->msgout[0] = MESSAGE_REJECT;
1929 AM53C974_write_8(CMDREG, CMDREG_SATN);
1930 AM53C974_write_8(CMDREG, CMDREG_MA);
1934 } /* switch (msg) */
1939 /**************************************************************************
1940 * Function : AM53C974_select(struct Scsi_Host *instance, Scsi_Cmnd *cmd, int tag)
1942 * Purpose : try to establish nexus for the command;
1943 * start sync negotiation via start stop and transfer the command in
1944 * cmdout phase in case of an inquiry or req. sense command with no
1945 * sync. neg. performed yet
1947 * Inputs : instance -- which AM53C974
1948 * cmd -- command which requires the selection
1949 * tag -- tagged queueing
1953 * Note: this function initializes the selection process, which is continued
1954 * in the interrupt handler
1955 **************************************************************************/
1956 static void AM53C974_select(struct Scsi_Host *instance, Scsi_Cmnd * cmd, int tag)
1958 AM53C974_local_declare();
1959 struct AM53C974_hostdata *hostdata = (struct AM53C974_hostdata *) instance->hostdata;
1960 unsigned char cfifo, tmp[3];
1961 unsigned int i, len, cmd_size = COMMAND_SIZE(cmd->cmnd[0]);
1962 AM53C974_setio(instance);
1964 cfifo = AM53C974_cfifo();
1966 printk("scsi%d: select error; %d residual bytes in FIFO\n", instance->host_no, cfifo);
1967 AM53C974_write_8(CMDREG, CMDREG_CFIFO); /* clear FIFO */
1969 #ifdef AM53C974_PROHIBIT_DISCONNECT
1970 tmp[0] = IDENTIFY(0, cmd->lun);
1972 tmp[0] = IDENTIFY(1, cmd->lun);
1976 if (cmd->device->tagged_queue && (tag != TAG_NONE)) {
1977 tmp[1] = SIMPLE_QUEUE_TAG;
1978 if (tag == TAG_NEXT) {
1979 /* 0 is TAG_NONE, used to imply no tag for this command */
1980 if (cmd->device->current_tag == 0)
1981 cmd->device->current_tag = 1;
1982 cmd->tag = cmd->device->current_tag;
1983 cmd->device->current_tag++;
1985 cmd->tag = (unsigned char) tag;
1987 hostdata->last_message[0] = SIMPLE_QUEUE_TAG;
1989 AM53C974_write_8(FFREG, tmp[0]);
1990 AM53C974_write_8(FFREG, tmp[1]);
1991 AM53C974_write_8(FFREG, tmp[2]);
1993 #endif /* def SCSI2 */
1996 AM53C974_write_8(FFREG, tmp[0]);
2000 /* in case of an inquiry or req. sense command with no sync. neg performed yet, we start
2001 sync negotiation via start stops and transfer the command in cmdout phase */
2002 if (((cmd->cmnd[0] == INQUIRY) || (cmd->cmnd[0] == REQUEST_SENSE)) &&
2003 !(hostdata->sync_neg[cmd->target]) && hostdata->sync_en[cmd->target]) {
2004 hostdata->sync_neg[cmd->target] = 1;
2005 hostdata->msgout[0] = EXTENDED_MESSAGE;
2006 hostdata->msgout[1] = 3;
2007 hostdata->msgout[2] = EXTENDED_SDTR;
2008 hostdata->msgout[3] = 250 / (int) hostdata->max_rate[cmd->target];
2009 hostdata->msgout[4] = hostdata->max_offset[cmd->target];
2012 AM53C974_write_8(SDIDREG, SDIREG_MASK & cmd->target); /* setup dest. id */
2013 AM53C974_write_8(STIMREG, DEF_SCSI_TIMEOUT); /* setup timeout reg */
2016 for (i = 0; i < cmd_size; i++)
2017 AM53C974_write_8(FFREG, cmd->cmnd[i]);
2018 AM53C974_write_8(CMDREG, CMDREG_SAS); /* select with ATN, 1 msg byte */
2019 hostdata->msgout[0] = NOP;
2022 for (i = 0; i < cmd_size; i++)
2023 AM53C974_write_8(FFREG, cmd->cmnd[i]);
2024 AM53C974_write_8(CMDREG, CMDREG_SA3S); /* select with ATN, 3 msg bytes */
2025 hostdata->msgout[0] = NOP;
2028 AM53C974_write_8(CMDREG, CMDREG_SASS); /* select with ATN, stop steps; continue in message out phase */
2033 /**************************************************************************
2034 * Function : AM53C974_intr_select(struct Scsi_Host *instance, unsigned char statreg)
2036 * Purpose : handle reselection
2038 * Inputs : instance -- which AM53C974
2039 * statreg -- status register
2043 * side effects: manipulates hostdata
2044 **************************************************************************/
2045 static void AM53C974_intr_reselect(struct Scsi_Host *instance, unsigned char statreg)
2047 AM53C974_local_declare();
2048 struct AM53C974_hostdata *hostdata = (struct AM53C974_hostdata *) instance->hostdata;
2049 unsigned char cfifo, msg[3], lun, t, target = 0;
2053 Scsi_Cmnd *tmp = NULL, *prev;
2054 AM53C974_setio(instance);
2056 cfifo = AM53C974_cfifo();
2058 if (hostdata->selecting) {
2059 /* caught reselect interrupt in selection process;
2060 put selecting command back into the issue queue and continue with the
2061 reselecting command */
2062 DEB_RESEL(printk("AM53C974_intr_reselect: in selection process\n"));
2063 LIST(hostdata->sel_cmd, hostdata->issue_queue);
2064 hostdata->sel_cmd->host_scribble = (unsigned char *) hostdata->issue_queue;
2065 hostdata->issue_queue = hostdata->sel_cmd;
2066 hostdata->sel_cmd = NULL;
2067 hostdata->selecting = 0;
2069 /* 2 bytes must be in the FIFO now */
2071 printk("scsi %d: error: %d bytes in fifo, 2 expected\n", instance->host_no, cfifo);
2072 hostdata->aborted = 1;
2075 /* determine target which reselected */
2076 t = AM53C974_read_8(FFREG);
2077 if (!(t & (1 << instance->this_id))) {
2078 printk("scsi %d: error: invalid host id\n", instance->host_no);
2079 hostdata->aborted = 1;
2082 t ^= (1 << instance->this_id);
2088 DEB_RESEL(printk("scsi %d: reselect; target: %d\n", instance->host_no, target));
2090 if (hostdata->aborted)
2093 if ((statreg & STATREG_PHASE) != PHASE_MSGIN) {
2094 printk("scsi %d: error: upon reselection interrupt not in MSGIN\n", instance->host_no);
2095 hostdata->aborted = 1;
2098 msg[0] = AM53C974_read_8(FFREG);
2099 if (!msg[0] & 0x80) {
2100 printk("scsi%d: error: expecting IDENTIFY message, got ", instance->host_no);
2102 hostdata->aborted = 1;
2105 lun = (msg[0] & 0x07);
2107 /* We need to add code for SCSI-II to track which devices have
2108 * I_T_L_Q nexuses established, and which have simple I_T_L
2109 * nexuses so we can chose to do additional data transfer. */
2111 #error "SCSI-II tagged queueing is not supported yet"
2114 /* Find the command corresponding to the I_T_L or I_T_L_Q nexus we
2115 * just reestablished, and remove it from the disconnected queue. */
2116 for (tmp = (Scsi_Cmnd *) hostdata->disconnected_queue, prev = NULL;
2117 tmp; prev = tmp, tmp = (Scsi_Cmnd *) tmp->host_scribble)
2118 if ((target == tmp->target) && (lun == tmp->lun)
2120 && (tag == tmp->tag)
2124 REMOVE(prev, (Scsi_Cmnd *) (prev->host_scribble), tmp,
2125 (Scsi_Cmnd *) (tmp->host_scribble));
2126 prev->host_scribble = tmp->host_scribble;
2128 REMOVE(-1, hostdata->disconnected_queue, tmp, tmp->host_scribble);
2129 hostdata->disconnected_queue = (Scsi_Cmnd *) tmp->host_scribble;
2131 tmp->host_scribble = NULL;
2132 hostdata->connected = tmp;
2137 printk("scsi%d: warning : target %d lun %d tag %d not in disconnect_queue.\n",
2138 instance->host_no, target, lun, tag);
2140 printk("scsi%d: warning : target %d lun %d not in disconnect_queue.\n",
2141 instance->host_no, target, lun);
2143 /* Since we have an established nexus that we can't do anything with, we must abort it. */
2144 hostdata->aborted = 1;
2145 DEB(AM53C974_keywait());
2151 AM53C974_write_8(CMDREG, CMDREG_SATN);
2152 AM53C974_write_8(CMDREG, CMDREG_MA);
2156 DEB_RESEL(printk("scsi%d: nexus established, target = %d, lun = %d, tag = %d\n",
2157 instance->host_no, target, tmp->lun, tmp->tag));
2158 AM53C974_set_sync(instance, target);
2159 AM53C974_write_8(SDIDREG, SDIREG_MASK & target); /* setup dest. id */
2160 AM53C974_write_8(CMDREG, CMDREG_MA);
2161 hostdata->dma_busy = 0;
2162 hostdata->connected->SCp.phase = PHASE_CMDOUT;
2165 /**************************************************************************
2166 * Function : AM53C974_transfer_dma(struct Scsi_Host *instance, short dir,
2167 * unsigned long length, char *data)
2169 * Purpose : setup DMA transfer
2171 * Inputs : instance -- which AM53C974
2172 * dir -- direction flag, 0: write to device, read from memory;
2173 * 1: read from device, write to memory
2174 * length -- number of bytes to transfer to from buffer
2175 * data -- pointer to data buffer
2178 **************************************************************************/
2179 static __inline__ void AM53C974_transfer_dma(struct Scsi_Host *instance, short dir,
2180 unsigned long length, char *data)
2182 AM53C974_local_declare();
2183 AM53C974_setio(instance);
2185 AM53C974_write_8(CMDREG, CMDREG_NOP);
2186 AM53C974_write_8(DMACMD, (dir << 7) | DMACMD_INTE_D); /* idle command */
2187 AM53C974_write_8(STCLREG, (unsigned char) (length & 0xff));
2188 AM53C974_write_8(STCMREG, (unsigned char) ((length & 0xff00) >> 8));
2189 AM53C974_write_8(STCHREG, (unsigned char) ((length & 0xff0000) >> 16));
2190 AM53C974_write_32(DMASTC, length & 0xffffff);
2191 AM53C974_write_32(DMASPA, virt_to_bus(data));
2192 AM53C974_write_8(CMDREG, CMDREG_IT | CMDREG_DMA);
2193 AM53C974_write_8(DMACMD, (dir << 7) | DMACMD_INTE_D | DMACMD_START);
2196 /**************************************************************************
2197 * Function : AM53C974_dma_blast(struct Scsi_Host *instance, unsigned char dmastatus,
2198 * unsigned char statreg)
2200 * Purpose : cleanup DMA transfer
2202 * Inputs : instance -- which AM53C974
2203 * dmastatus -- dma status register
2204 * statreg -- status register
2207 **************************************************************************/
2208 static void AM53C974_dma_blast(struct Scsi_Host *instance, unsigned char dmastatus,
2209 unsigned char statreg)
2211 AM53C974_local_declare();
2212 struct AM53C974_hostdata *hostdata = (struct AM53C974_hostdata *) instance->hostdata;
2213 unsigned long ctcreg;
2214 int dir = statreg & STATREG_IO;
2215 int cfifo, pio, i = 0;
2216 AM53C974_setio(instance);
2219 cfifo = AM53C974_cfifo();
2221 } while (cfifo && (i < 50000));
2222 pio = (i == 50000) ? 1 : 0;
2224 if (statreg & STATREG_CTZ) {
2225 AM53C974_write_8(DMACMD, DMACMD_IDLE);
2228 if (dmastatus & DMASTATUS_DONE) {
2229 AM53C974_write_8(DMACMD, DMACMD_IDLE);
2232 AM53C974_write_8(DMACMD, ((dir << 7) & DMACMD_DIR) | DMACMD_BLAST);
2233 while (!(AM53C974_read_8(DMASTATUS) & DMASTATUS_BCMPLT));
2234 AM53C974_write_8(DMACMD, DMACMD_IDLE);
2237 /* transfer residual bytes via PIO */
2238 unsigned char *wac = (unsigned char *) AM53C974_read_32(DMAWAC);
2239 printk("pio mode, residual=%d\n", AM53C974_read_8(CFIREG) & CFIREG_CF);
2240 while (AM53C974_read_8(CFIREG) & CFIREG_CF)
2241 *(wac++) = AM53C974_read_8(FFREG);
2243 ctcreg = AM53C974_read_8(CTCLREG) | (AM53C974_read_8(CTCMREG) << 8) |
2244 (AM53C974_read_8(CTCHREG) << 16);
2246 hostdata->connected->SCp.ptr += hostdata->connected->SCp.this_residual - ctcreg;
2247 hostdata->connected->SCp.this_residual = ctcreg;
2250 /**************************************************************************
2251 * Function : AM53C974_intr_bus_reset(struct Scsi_Host *instance)
2253 * Purpose : handle bus reset interrupt
2255 * Inputs : instance -- which AM53C974
2258 **************************************************************************/
2259 static void AM53C974_intr_bus_reset(struct Scsi_Host *instance)
2261 AM53C974_local_declare();
2262 unsigned char cntlreg1;
2263 AM53C974_setio(instance);
2265 AM53C974_write_8(CMDREG, CMDREG_CFIFO);
2266 AM53C974_write_8(CMDREG, CMDREG_NOP);
2268 cntlreg1 = AM53C974_read_8(CNTLREG1);
2269 AM53C974_write_8(CNTLREG1, cntlreg1 | CNTLREG1_DISR);
2272 /**************************************************************************
2273 * Function : int AM53C974_abort(Scsi_Cmnd *cmd)
2275 * Purpose : abort a command
2277 * Inputs : cmd - the Scsi_Cmnd to abort, code - code to set the
2278 * host byte of the result field to, if zero DID_ABORTED is
2281 * Returns : 0 - success, -1 on failure.
2282 **************************************************************************/
2283 static int AM53C974_abort(Scsi_Cmnd * cmd)
2285 AM53C974_local_declare();
2286 unsigned long flags;
2287 struct Scsi_Host *instance = cmd->host;
2288 struct AM53C974_hostdata *hostdata = (struct AM53C974_hostdata *) instance->hostdata;
2289 Scsi_Cmnd *tmp, **prev;
2291 #ifdef AM53C974_DEBUG
2296 AM53C974_setio(instance);
2298 DEB_ABORT(printk(SEPARATOR_LINE));
2299 DEB_ABORT(printk("scsi%d : AM53C974_abort called -- trouble starts!!\n", instance->host_no));
2300 DEB_ABORT(AM53C974_print(instance));
2301 DEB_ABORT(AM53C974_keywait());
2303 /* Case 1 : If the command is the currently executing command,
2304 we'll set the aborted flag and return control so that the
2305 information transfer routine can exit cleanly. */
2306 if ((hostdata->connected == cmd) || (hostdata->sel_cmd == cmd)) {
2307 DEB_ABORT(printk("scsi%d: aborting connected command\n", instance->host_no));
2308 hostdata->aborted = 1;
2309 hostdata->msgout[0] = ABORT;
2310 restore_flags(flags);
2311 return (SCSI_ABORT_PENDING);
2313 /* Case 2 : If the command hasn't been issued yet,
2314 we simply remove it from the issue queue. */
2315 for (prev = (Scsi_Cmnd **) & (hostdata->issue_queue),
2316 tmp = (Scsi_Cmnd *) hostdata->issue_queue; tmp;
2317 prev = (Scsi_Cmnd **) & (tmp->host_scribble),
2318 tmp = (Scsi_Cmnd *) tmp->host_scribble) {
2320 DEB_ABORT(printk("scsi%d : abort removed command from issue queue.\n", instance->host_no));
2321 REMOVE(5, *prev, tmp, tmp->host_scribble);
2322 (*prev) = (Scsi_Cmnd *) tmp->host_scribble;
2323 tmp->host_scribble = NULL;
2324 tmp->result = DID_ABORT << 16;
2325 restore_flags(flags);
2327 return (SCSI_ABORT_SUCCESS);
2329 #ifdef AM53C974_DEBUG_ABORT
2331 if (prev == (Scsi_Cmnd **) tmp)
2332 printk("scsi%d : LOOP\n", instance->host_no);
2337 /* Case 3 : If any commands are connected, we're going to fail the abort
2338 * and let the high level SCSI driver retry at a later time or
2341 * Timeouts, and therefore aborted commands, will be highly unlikely
2342 * and handling them cleanly in this situation would make the common
2343 * case of noresets less efficient, and would pollute our code. So,
2345 if (hostdata->connected || hostdata->sel_cmd) {
2346 DEB_ABORT(printk("scsi%d : abort failed, other command connected.\n", instance->host_no));
2347 restore_flags(flags);
2348 return (SCSI_ABORT_NOT_RUNNING);
2350 /* Case 4: If the command is currently disconnected from the bus, and
2351 * there are no connected commands, we reconnect the I_T_L or
2352 * I_T_L_Q nexus associated with it, go into message out, and send
2353 * an abort message. */
2354 for (tmp = (Scsi_Cmnd *) hostdata->disconnected_queue; tmp;
2355 tmp = (Scsi_Cmnd *) tmp->host_scribble) {
2357 DEB_ABORT(printk("scsi%d: aborting disconnected command\n", instance->host_no));
2358 hostdata->aborted = 1;
2359 hostdata->msgout[0] = ABORT;
2360 hostdata->selecting = 1;
2361 hostdata->sel_cmd = tmp;
2362 AM53C974_write_8(CMDREG, CMDREG_DSR);
2363 restore_flags(flags);
2364 return (SCSI_ABORT_PENDING);
2368 /* Case 5 : If we reached this point, the command was not found in any of
2371 * We probably reached this point because of an unlikely race condition
2372 * between the command completing successfully and the abortion code,
2373 * so we won't panic, but we will notify the user in case something really
2375 DEB_ABORT(printk("scsi%d : abort failed, command not found.\n", instance->host_no));
2376 restore_flags(flags);
2377 return (SCSI_ABORT_NOT_RUNNING);
2380 /**************************************************************************
2381 * Function : int AM53C974_reset(Scsi_Cmnd *cmd)
2383 * Purpose : reset the SCSI controller and bus
2385 * Inputs : cmd -- which command within the command block was responsible for the reset
2387 * Returns : status (SCSI_ABORT_SUCCESS)
2389 * FIXME(eric) the reset_flags are ignored.
2390 **************************************************************************/
2391 static int AM53C974_reset(Scsi_Cmnd * cmd, unsigned int reset_flags)
2393 AM53C974_local_declare();
2394 unsigned long flags;
2396 struct Scsi_Host *instance = cmd->host;
2397 struct AM53C974_hostdata *hostdata = (struct AM53C974_hostdata *) instance->hostdata;
2398 AM53C974_setio(instance);
2402 DEB(printk("AM53C974_reset called; "));
2404 printk("AM53C974_reset called\n");
2405 AM53C974_print(instance);
2409 AM53C974_write_8(CMDREG, CMDREG_RDEV);
2410 AM53C974_write_8(CMDREG, CMDREG_NOP);
2411 hostdata->msgout[0] = NOP;
2412 for (i = 0; i < 8; i++) {
2413 hostdata->busy[i] = 0;
2414 hostdata->sync_per[i] = DEF_STP;
2415 hostdata->sync_off[i] = 0;
2416 hostdata->sync_neg[i] = 0;
2418 hostdata->last_message[0] = NOP;
2419 hostdata->sel_cmd = NULL;
2420 hostdata->connected = NULL;
2421 hostdata->issue_queue = NULL;
2422 hostdata->disconnected_queue = NULL;
2423 hostdata->in_reset = 0;
2424 hostdata->aborted = 0;
2425 hostdata->selecting = 0;
2426 hostdata->disconnecting = 0;
2427 hostdata->dma_busy = 0;
2430 AM53C974_write_8(CNTLREG1, CNTLREG1_DISR | instance->this_id); /* disable interrupt upon SCSI RESET */
2431 AM53C974_write_8(CMDREG, CMDREG_RBUS); /* reset SCSI bus */
2433 AM53C974_config_after_reset(instance);
2435 restore_flags(flags);
2436 cmd->result = DID_RESET << 16;
2437 cmd->scsi_done(cmd);
2438 return SCSI_ABORT_SUCCESS;
2443 * AM53C974_release()
2445 * Release resources allocated for a single AM53C974 adapter.
2447 static int AM53C974_release(struct Scsi_Host *shp)
2449 free_irq(shp->irq, shp);
2450 scsi_unregister(shp);
2455 /* You can specify overrides=a,b,c,d in the same format at AM53C974=a,b,c,d
2457 MODULE_PARM(overrides, "1-32i");
2458 MODULE_LICENSE("GPL");
2461 static Scsi_Host_Template driver_template = AM53C974;
2462 #include "scsi_module.c"