1 /* sun3_NCR5380.c -- adapted from atari_NCR5380.c for the sun3 by
4 * NCR 5380 generic driver routines. These should make it *trivial*
5 * to implement 5380 SCSI drivers under Linux with a non-trantor
8 * Note that these routines also work with NR53c400 family chips.
10 * Copyright 1993, Drew Eckhardt
12 * (Unix and Linux consulting and custom programming)
16 * DISTRIBUTION RELEASE 6.
18 * For more information, please consult
21 * SCSI Protocol Controller
24 * NCR Microelectronics
25 * 1635 Aeroplaza Drive
26 * Colorado Springs, CO 80916
32 * ++roman: To port the 5380 driver to the Atari, I had to do some changes in
35 * - Some of the debug statements were incorrect (undefined variables and the
36 * like). I fixed that.
38 * - In information_transfer(), I think a #ifdef was wrong. Looking at the
39 * possible DMA transfer size should also happen for REAL_DMA. I added this
40 * in the #if statement.
42 * - When using real DMA, information_transfer() should return in a DATAOUT
43 * phase after starting the DMA. It has nothing more to do.
45 * - The interrupt service routine should run main after end of DMA, too (not
46 * only after RESELECTION interrupts). Additionally, it should _not_ test
47 * for more interrupts after running main, since a DMA process may have
48 * been started and interrupts are turned on now. The new int could happen
49 * inside the execution of NCR5380_intr(), leading to recursive
52 * - I've deleted all the stuff for AUTOPROBE_IRQ, REAL_DMA_POLL, PSEUDO_DMA
53 * and USLEEP, because these were messing up readability and will never be
54 * needed for Atari SCSI.
56 * - I've revised the NCR5380_main() calling scheme (relax the 'main_running'
57 * stuff), and 'main' is executed in a bottom half if awoken by an
60 * - The code was quite cluttered up by "#if (NDEBUG & NDEBUG_*) printk..."
61 * constructs. In my eyes, this made the source rather unreadable, so I
62 * finally replaced that by the *_PRINTK() macros.
65 #include <scsi/scsi_dbg.h>
66 #include <scsi/scsi_transport_spi.h>
69 * Further development / testing that should be done :
70 * 1. Test linked command handling code after Eric is ready with
71 * the high level code.
74 #if (NDEBUG & NDEBUG_LISTS)
76 { printk("LINE:%d Adding %p to %p\n", __LINE__, (void*)(x), (void*)(y)); \
77 if ((x)==(y)) udelay(5); }
78 #define REMOVE(w,x,y,z) \
79 { printk("LINE:%d Removing: %p->%p %p->%p \n", __LINE__, \
80 (void*)(w), (void*)(x), (void*)(y), (void*)(z)); \
81 if ((x)==(y)) udelay(5); }
84 #define REMOVE(w,x,y,z)
95 * The other Linux SCSI drivers were written when Linux was Intel PC-only,
96 * and specifically for each board rather than each chip. This makes their
97 * adaptation to platforms like the Mac (Some of which use NCR5380's)
98 * more difficult than it has to be.
100 * Also, many of the SCSI drivers were written before the command queuing
101 * routines were implemented, meaning their implementations of queued
102 * commands were hacked on rather than designed in from the start.
104 * When I designed the Linux SCSI drivers I figured that
105 * while having two different SCSI boards in a system might be useful
106 * for debugging things, two of the same type wouldn't be used.
107 * Well, I was wrong and a number of users have mailed me about running
108 * multiple high-performance SCSI boards in a server.
110 * Finally, when I get questions from users, I have no idea what
111 * revision of my driver they are running.
113 * This driver attempts to address these problems :
114 * This is a generic 5380 driver. To use it on a different platform,
115 * one simply writes appropriate system specific macros (ie, data
116 * transfer - some PC's will use the I/O bus, 68K's must use
117 * memory mapped) and drops this file in their 'C' wrapper.
119 * As far as command queueing, two queues are maintained for
120 * each 5380 in the system - commands that haven't been issued yet,
121 * and commands that are currently executing. This means that an
122 * unlimited number of commands may be queued, letting
123 * more commands propagate from the higher driver levels giving higher
124 * throughput. Note that both I_T_L and I_T_L_Q nexuses are supported,
125 * allowing multiple commands to propagate all the way to a SCSI-II device
126 * while a command is already executing.
128 * To solve the multiple-boards-in-the-same-system problem,
129 * there is a separate instance structure for each instance
130 * of a 5380 in the system. So, multiple NCR5380 drivers will
131 * be able to coexist with appropriate changes to the high level
134 * A NCR5380_PUBLIC_REVISION macro is provided, with the release
135 * number (updated for each public release) printed by the
136 * NCR5380_print_options command, which should be called from the
137 * wrapper detect function, so that I know what release of the driver
140 * Issues specific to the NCR5380 :
142 * When used in a PIO or pseudo-dma mode, the NCR5380 is a braindead
143 * piece of hardware that requires you to sit in a loop polling for
144 * the REQ signal as long as you are connected. Some devices are
145 * brain dead (ie, many TEXEL CD ROM drives) and won't disconnect
146 * while doing long seek operations.
148 * The workaround for this is to keep track of devices that have
149 * disconnected. If the device hasn't disconnected, for commands that
150 * should disconnect, we do something like
152 * while (!REQ is asserted) { sleep for N usecs; poll for M usecs }
154 * Some tweaking of N and M needs to be done. An algorithm based
155 * on "time to data" would give the best results as long as short time
156 * to datas (ie, on the same track) were considered, however these
157 * broken devices are the exception rather than the rule and I'd rather
158 * spend my time optimizing for the normal case.
162 * At the heart of the design is a coroutine, NCR5380_main,
163 * which is started when not running by the interrupt handler,
164 * timer, and queue command function. It attempts to establish
165 * I_T_L or I_T_L_Q nexuses by removing the commands from the
166 * issue queue and calling NCR5380_select() if a nexus
167 * is not established.
169 * Once a nexus is established, the NCR5380_information_transfer()
170 * phase goes through the various phases as instructed by the target.
171 * if the target goes into MSG IN and sends a DISCONNECT message,
172 * the command structure is placed into the per instance disconnected
173 * queue, and NCR5380_main tries to find more work. If USLEEP
174 * was defined, and the target is idle for too long, the system
177 * If a command has disconnected, eventually an interrupt will trigger,
178 * calling NCR5380_intr() which will in turn call NCR5380_reselect
179 * to reestablish a nexus. This will run main if necessary.
181 * On command termination, the done function will be called as
184 * SCSI pointers are maintained in the SCp field of SCSI command
185 * structures, being initialized after the command is connected
186 * in NCR5380_select, and set as appropriate in NCR5380_information_transfer.
187 * Note that in violation of the standard, an implicit SAVE POINTERS operation
188 * is done, since some BROKEN disks fail to issue an explicit SAVE POINTERS.
193 * This file a skeleton Linux SCSI driver for the NCR 5380 series
194 * of chips. To use it, you write an architecture specific functions
195 * and macros and include this file in your driver.
197 * These macros control options :
198 * AUTOSENSE - if defined, REQUEST SENSE will be performed automatically
199 * for commands that return with a CHECK CONDITION status.
201 * LINKED - if defined, linked commands are supported.
203 * REAL_DMA - if defined, REAL DMA is used during the data transfer phases.
205 * SUPPORT_TAGS - if defined, SCSI-2 tagged queuing is used where possible
207 * These macros MUST be defined :
209 * NCR5380_read(register) - read from the specified register
211 * NCR5380_write(register, value) - write to the specific register
213 * Either real DMA *or* pseudo DMA may be implemented
215 * NCR5380_REAL_DMA should be defined if real DMA is to be used.
216 * Note that the DMA setup functions should return the number of bytes
217 * that they were able to program the controller for.
219 * Also note that generic i386/PC versions of these macros are
220 * available as NCR5380_i386_dma_write_setup,
221 * NCR5380_i386_dma_read_setup, and NCR5380_i386_dma_residual.
223 * NCR5380_dma_write_setup(instance, src, count) - initialize
224 * NCR5380_dma_read_setup(instance, dst, count) - initialize
225 * NCR5380_dma_residual(instance); - residual count
228 * NCR5380_pwrite(instance, src, count)
229 * NCR5380_pread(instance, dst, count);
231 * If nothing specific to this implementation needs doing (ie, with external
232 * hardware), you must also define
234 * NCR5380_queue_command
239 * to be the global entry points into the specific driver, ie
240 * #define NCR5380_queue_command t128_queue_command.
242 * If this is not done, the routines will be defined as static functions
243 * with the NCR5380* names and the user must provide a globally
244 * accessible wrapper function.
246 * The generic driver is initialized by calling NCR5380_init(instance),
247 * after setting the appropriate host specific fields and ID. If the
248 * driver wishes to autoprobe for an IRQ line, the NCR5380_probe_irq(instance,
249 * possible) function may be used. Before the specific driver initialization
250 * code finishes, NCR5380_print_options should be called.
253 static struct Scsi_Host *first_instance = NULL;
254 static struct scsi_host_template *the_template = NULL;
256 /* Macros ease life... :-) */
257 #define SETUP_HOSTDATA(in) \
258 struct NCR5380_hostdata *hostdata = \
259 (struct NCR5380_hostdata *)(in)->hostdata
260 #define HOSTDATA(in) ((struct NCR5380_hostdata *)(in)->hostdata)
262 #define NEXT(cmd) ((struct scsi_cmnd *)(cmd)->host_scribble)
263 #define SET_NEXT(cmd, next) ((cmd)->host_scribble = (void *)(next))
264 #define NEXTADDR(cmd) ((struct scsi_cmnd **)&((cmd)->host_scribble))
266 #define HOSTNO instance->host_no
267 #define H_NO(cmd) (cmd)->device->host->host_no
269 #define SGADDR(buffer) (void *)(((unsigned long)sg_virt(((buffer)))))
274 * Functions for handling tagged queuing
275 * =====================================
277 * ++roman (01/96): Now I've implemented SCSI-2 tagged queuing. Some notes:
279 * Using consecutive numbers for the tags is no good idea in my eyes. There
280 * could be wrong re-usings if the counter (8 bit!) wraps and some early
281 * command has been preempted for a long time. My solution: a bitfield for
282 * remembering used tags.
284 * There's also the problem that each target has a certain queue size, but we
285 * cannot know it in advance :-( We just see a QUEUE_FULL status being
286 * returned. So, in this case, the driver internal queue size assumption is
287 * reduced to the number of active tags if QUEUE_FULL is returned by the
288 * target. The command is returned to the mid-level, but with status changed
289 * to BUSY, since --as I've seen-- the mid-level can't handle QUEUE_FULL
292 * We're also not allowed running tagged commands as long as an untagged
293 * command is active. And REQUEST SENSE commands after a contingent allegiance
294 * condition _must_ be untagged. To keep track whether an untagged command has
295 * been issued, the host->busy array is still employed, as it is without
296 * support for tagged queuing.
298 * One could suspect that there are possible race conditions between
299 * is_lun_busy(), cmd_get_tag() and cmd_free_tag(). But I think this isn't the
300 * case: is_lun_busy() and cmd_get_tag() are both called from NCR5380_main(),
301 * which already guaranteed to be running at most once. It is also the only
302 * place where tags/LUNs are allocated. So no other allocation can slip
303 * between that pair, there could only happen a reselection, which can free a
304 * tag, but that doesn't hurt. Only the sequence in cmd_free_tag() becomes
305 * important: the tag bit must be cleared before 'nr_allocated' is decreased.
308 /* -1 for TAG_NONE is not possible with unsigned char cmd->tag */
310 #define TAG_NONE 0xff
312 /* For the m68k, the number of bits in 'allocated' must be a multiple of 32! */
313 #if (MAX_TAGS % 32) != 0
314 #error "MAX_TAGS must be a multiple of 32!"
318 char allocated[MAX_TAGS/8];
323 static TAG_ALLOC TagAlloc[8][8]; /* 8 targets and 8 LUNs */
326 static void __init init_tags( void )
331 if (!setup_use_tagged_queuing)
334 for( target = 0; target < 8; ++target ) {
335 for( lun = 0; lun < 8; ++lun ) {
336 ta = &TagAlloc[target][lun];
337 memset( &ta->allocated, 0, MAX_TAGS/8 );
338 ta->nr_allocated = 0;
339 /* At the beginning, assume the maximum queue size we could
340 * support (MAX_TAGS). This value will be decreased if the target
341 * returns QUEUE_FULL status.
343 ta->queue_size = MAX_TAGS;
349 /* Check if we can issue a command to this LUN: First see if the LUN is marked
350 * busy by an untagged command. If the command should use tagged queuing, also
351 * check that there is a free tag and the target's queue won't overflow. This
352 * function should be called with interrupts disabled to avoid race
356 static int is_lun_busy(struct scsi_cmnd *cmd, int should_be_tagged)
358 SETUP_HOSTDATA(cmd->device->host);
360 if (hostdata->busy[cmd->device->id] & (1 << cmd->device->lun))
362 if (!should_be_tagged ||
363 !setup_use_tagged_queuing || !cmd->device->tagged_supported)
365 if (TagAlloc[cmd->device->id][cmd->device->lun].nr_allocated >=
366 TagAlloc[cmd->device->id][cmd->device->lun].queue_size ) {
367 dprintk(NDEBUG_TAGS, "scsi%d: target %d lun %d: no free tags\n",
368 H_NO(cmd), cmd->device->id, cmd->device->lun );
375 /* Allocate a tag for a command (there are no checks anymore, check_lun_busy()
376 * must be called before!), or reserve the LUN in 'busy' if the command is
380 static void cmd_get_tag(struct scsi_cmnd *cmd, int should_be_tagged)
382 SETUP_HOSTDATA(cmd->device->host);
384 /* If we or the target don't support tagged queuing, allocate the LUN for
385 * an untagged command.
387 if (!should_be_tagged ||
388 !setup_use_tagged_queuing || !cmd->device->tagged_supported) {
390 hostdata->busy[cmd->device->id] |= (1 << cmd->device->lun);
391 dprintk(NDEBUG_TAGS, "scsi%d: target %d lun %d now allocated by untagged "
392 "command\n", H_NO(cmd), cmd->device->id, cmd->device->lun );
395 TAG_ALLOC *ta = &TagAlloc[cmd->device->id][cmd->device->lun];
397 cmd->tag = find_first_zero_bit( &ta->allocated, MAX_TAGS );
398 set_bit( cmd->tag, &ta->allocated );
400 dprintk(NDEBUG_TAGS, "scsi%d: using tag %d for target %d lun %d "
401 "(now %d tags in use)\n",
402 H_NO(cmd), cmd->tag, cmd->device->id, cmd->device->lun,
408 /* Mark the tag of command 'cmd' as free, or in case of an untagged command,
412 static void cmd_free_tag(struct scsi_cmnd *cmd)
414 SETUP_HOSTDATA(cmd->device->host);
416 if (cmd->tag == TAG_NONE) {
417 hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
418 dprintk(NDEBUG_TAGS, "scsi%d: target %d lun %d untagged cmd finished\n",
419 H_NO(cmd), cmd->device->id, cmd->device->lun );
421 else if (cmd->tag >= MAX_TAGS) {
422 printk(KERN_NOTICE "scsi%d: trying to free bad tag %d!\n",
423 H_NO(cmd), cmd->tag );
426 TAG_ALLOC *ta = &TagAlloc[cmd->device->id][cmd->device->lun];
427 clear_bit( cmd->tag, &ta->allocated );
429 dprintk(NDEBUG_TAGS, "scsi%d: freed tag %d for target %d lun %d\n",
430 H_NO(cmd), cmd->tag, cmd->device->id, cmd->device->lun );
435 static void free_all_tags( void )
440 if (!setup_use_tagged_queuing)
443 for( target = 0; target < 8; ++target ) {
444 for( lun = 0; lun < 8; ++lun ) {
445 ta = &TagAlloc[target][lun];
446 memset( &ta->allocated, 0, MAX_TAGS/8 );
447 ta->nr_allocated = 0;
452 #endif /* SUPPORT_TAGS */
456 * Function : void initialize_SCp(struct scsi_cmnd *cmd)
458 * Purpose : initialize the saved data pointers for cmd to point to the
459 * start of the buffer.
461 * Inputs : cmd - struct scsi_cmnd structure to have pointers reset.
464 static __inline__ void initialize_SCp(struct scsi_cmnd *cmd)
467 * Initialize the Scsi Pointer field so that all of the commands in the
468 * various queues are valid.
471 if (scsi_bufflen(cmd)) {
472 cmd->SCp.buffer = scsi_sglist(cmd);
473 cmd->SCp.buffers_residual = scsi_sg_count(cmd) - 1;
474 cmd->SCp.ptr = (char *) SGADDR(cmd->SCp.buffer);
475 cmd->SCp.this_residual = cmd->SCp.buffer->length;
477 cmd->SCp.buffer = NULL;
478 cmd->SCp.buffers_residual = 0;
480 cmd->SCp.this_residual = 0;
485 #include <linux/delay.h>
491 signals[] = {{ SR_DBP, "PARITY"}, { SR_RST, "RST" }, { SR_BSY, "BSY" },
492 { SR_REQ, "REQ" }, { SR_MSG, "MSG" }, { SR_CD, "CD" }, { SR_IO, "IO" },
493 { SR_SEL, "SEL" }, {0, NULL}},
494 basrs[] = {{BASR_ATN, "ATN"}, {BASR_ACK, "ACK"}, {0, NULL}},
495 icrs[] = {{ICR_ASSERT_RST, "ASSERT RST"},{ICR_ASSERT_ACK, "ASSERT ACK"},
496 {ICR_ASSERT_BSY, "ASSERT BSY"}, {ICR_ASSERT_SEL, "ASSERT SEL"},
497 {ICR_ASSERT_ATN, "ASSERT ATN"}, {ICR_ASSERT_DATA, "ASSERT DATA"},
499 mrs[] = {{MR_BLOCK_DMA_MODE, "MODE BLOCK DMA"}, {MR_TARGET, "MODE TARGET"},
500 {MR_ENABLE_PAR_CHECK, "MODE PARITY CHECK"}, {MR_ENABLE_PAR_INTR,
501 "MODE PARITY INTR"}, {MR_ENABLE_EOP_INTR,"MODE EOP INTR"},
502 {MR_MONITOR_BSY, "MODE MONITOR BSY"},
503 {MR_DMA_MODE, "MODE DMA"}, {MR_ARBITRATE, "MODE ARBITRATION"},
507 * Function : void NCR5380_print(struct Scsi_Host *instance)
509 * Purpose : print the SCSI bus signals for debugging purposes
511 * Input : instance - which NCR5380
514 static void NCR5380_print(struct Scsi_Host *instance) {
515 unsigned char status, data, basr, mr, icr, i;
518 local_irq_save(flags);
519 data = NCR5380_read(CURRENT_SCSI_DATA_REG);
520 status = NCR5380_read(STATUS_REG);
521 mr = NCR5380_read(MODE_REG);
522 icr = NCR5380_read(INITIATOR_COMMAND_REG);
523 basr = NCR5380_read(BUS_AND_STATUS_REG);
524 local_irq_restore(flags);
525 printk("STATUS_REG: %02x ", status);
526 for (i = 0; signals[i].mask ; ++i)
527 if (status & signals[i].mask)
528 printk(",%s", signals[i].name);
529 printk("\nBASR: %02x ", basr);
530 for (i = 0; basrs[i].mask ; ++i)
531 if (basr & basrs[i].mask)
532 printk(",%s", basrs[i].name);
533 printk("\nICR: %02x ", icr);
534 for (i = 0; icrs[i].mask; ++i)
535 if (icr & icrs[i].mask)
536 printk(",%s", icrs[i].name);
537 printk("\nMODE: %02x ", mr);
538 for (i = 0; mrs[i].mask; ++i)
539 if (mr & mrs[i].mask)
540 printk(",%s", mrs[i].name);
548 {PHASE_DATAOUT, "DATAOUT"}, {PHASE_DATAIN, "DATAIN"}, {PHASE_CMDOUT, "CMDOUT"},
549 {PHASE_STATIN, "STATIN"}, {PHASE_MSGOUT, "MSGOUT"}, {PHASE_MSGIN, "MSGIN"},
550 {PHASE_UNKNOWN, "UNKNOWN"}};
553 * Function : void NCR5380_print_phase(struct Scsi_Host *instance)
555 * Purpose : print the current SCSI phase for debugging purposes
557 * Input : instance - which NCR5380
560 static void NCR5380_print_phase(struct Scsi_Host *instance)
562 unsigned char status;
565 status = NCR5380_read(STATUS_REG);
566 if (!(status & SR_REQ))
567 printk(KERN_DEBUG "scsi%d: REQ not asserted, phase unknown.\n", HOSTNO);
569 for (i = 0; (phases[i].value != PHASE_UNKNOWN) &&
570 (phases[i].value != (status & PHASE_MASK)); ++i);
571 printk(KERN_DEBUG "scsi%d: phase %s\n", HOSTNO, phases[i].name);
578 * ++roman: New scheme of calling NCR5380_main()
580 * If we're not in an interrupt, we can call our main directly, it cannot be
581 * already running. Else, we queue it on a task queue, if not 'main_running'
582 * tells us that a lower level is already executing it. This way,
583 * 'main_running' needs not be protected in a special way.
585 * queue_main() is a utility function for putting our main onto the task
586 * queue, if main_running is false. It should be called only from a
587 * interrupt or bottom half.
590 #include <linux/gfp.h>
591 #include <linux/workqueue.h>
592 #include <linux/interrupt.h>
594 static volatile int main_running = 0;
595 static DECLARE_WORK(NCR5380_tqueue, NCR5380_main);
597 static __inline__ void queue_main(void)
600 /* If in interrupt and NCR5380_main() not already running,
601 queue it on the 'immediate' task queue, to be processed
602 immediately after the current interrupt processing has
604 schedule_work(&NCR5380_tqueue);
606 /* else: nothing to do: the running NCR5380_main() will pick up
607 any newly queued command. */
611 static inline void NCR5380_all_init (void)
615 dprintk(NDEBUG_INIT, "scsi : NCR5380_all_init()\n");
622 * Function : void NCR58380_print_options (struct Scsi_Host *instance)
624 * Purpose : called by probe code indicating the NCR5380 driver
625 * options that were selected.
627 * Inputs : instance, pointer to this instance. Unused.
630 static void __init NCR5380_print_options (struct Scsi_Host *instance)
632 printk(" generic options"
643 " SCSI-2 TAGGED QUEUING"
646 printk(" generic release=%d", NCR5380_PUBLIC_RELEASE);
650 * Function : void NCR5380_print_status (struct Scsi_Host *instance)
652 * Purpose : print commands in the various queues, called from
653 * NCR5380_abort and NCR5380_debug to aid debugging.
655 * Inputs : instance, pointer to this instance.
658 static void lprint_Scsi_Cmnd(Scsi_Cmnd *cmd)
661 unsigned char *command;
662 printk("scsi%d: destination target %d, lun %d\n",
663 H_NO(cmd), cmd->device->id, cmd->device->lun);
664 printk(KERN_CONT " command = ");
666 printk(KERN_CONT "%2d (0x%02x)", command[0], command[0]);
667 for (i = 1, s = COMMAND_SIZE(command[0]); i < s; ++i)
668 printk(KERN_CONT " %02x", command[i]);
672 static void NCR5380_print_status(struct Scsi_Host *instance)
674 struct NCR5380_hostdata *hostdata;
678 NCR5380_dprint(NDEBUG_ANY, instance);
679 NCR5380_dprint_phase(NDEBUG_ANY, instance);
681 hostdata = (struct NCR5380_hostdata *)instance->hostdata;
683 printk("\nNCR5380 core release=%d.\n", NCR5380_PUBLIC_RELEASE);
684 local_irq_save(flags);
685 printk("NCR5380: coroutine is%s running.\n",
686 main_running ? "" : "n't");
687 if (!hostdata->connected)
688 printk("scsi%d: no currently connected command\n", HOSTNO);
690 lprint_Scsi_Cmnd((Scsi_Cmnd *) hostdata->connected);
691 printk("scsi%d: issue_queue\n", HOSTNO);
692 for (ptr = (Scsi_Cmnd *)hostdata->issue_queue; ptr; ptr = NEXT(ptr))
693 lprint_Scsi_Cmnd(ptr);
695 printk("scsi%d: disconnected_queue\n", HOSTNO);
696 for (ptr = (Scsi_Cmnd *) hostdata->disconnected_queue; ptr;
698 lprint_Scsi_Cmnd(ptr);
700 local_irq_restore(flags);
704 static void show_Scsi_Cmnd(Scsi_Cmnd *cmd, struct seq_file *m)
707 unsigned char *command;
708 seq_printf(m, "scsi%d: destination target %d, lun %d\n",
709 H_NO(cmd), cmd->device->id, cmd->device->lun);
710 seq_printf(m, " command = ");
712 seq_printf(m, "%2d (0x%02x)", command[0], command[0]);
713 for (i = 1, s = COMMAND_SIZE(command[0]); i < s; ++i)
714 seq_printf(m, " %02x", command[i]);
718 static int NCR5380_show_info(struct seq_file *m, struct Scsi_Host *instance)
720 struct NCR5380_hostdata *hostdata;
724 hostdata = (struct NCR5380_hostdata *)instance->hostdata;
726 seq_printf(m, "NCR5380 core release=%d.\n", NCR5380_PUBLIC_RELEASE);
727 local_irq_save(flags);
728 seq_printf(m, "NCR5380: coroutine is%s running.\n",
729 main_running ? "" : "n't");
730 if (!hostdata->connected)
731 seq_printf(m, "scsi%d: no currently connected command\n", HOSTNO);
733 show_Scsi_Cmnd((Scsi_Cmnd *) hostdata->connected, m);
734 seq_printf(m, "scsi%d: issue_queue\n", HOSTNO);
735 for (ptr = (Scsi_Cmnd *)hostdata->issue_queue; ptr; ptr = NEXT(ptr))
736 show_Scsi_Cmnd(ptr, m);
738 seq_printf(m, "scsi%d: disconnected_queue\n", HOSTNO);
739 for (ptr = (Scsi_Cmnd *) hostdata->disconnected_queue; ptr;
741 show_Scsi_Cmnd(ptr, m);
743 local_irq_restore(flags);
748 * Function : void NCR5380_init (struct Scsi_Host *instance)
750 * Purpose : initializes *instance and corresponding 5380 chip.
752 * Inputs : instance - instantiation of the 5380 driver.
754 * Notes : I assume that the host, hostno, and id bits have been
755 * set correctly. I don't care about the irq and other fields.
759 static int __init NCR5380_init(struct Scsi_Host *instance, int flags)
762 SETUP_HOSTDATA(instance);
766 hostdata->aborted = 0;
767 hostdata->id_mask = 1 << instance->this_id;
768 hostdata->id_higher_mask = 0;
769 for (i = hostdata->id_mask; i <= 0x80; i <<= 1)
770 if (i > hostdata->id_mask)
771 hostdata->id_higher_mask |= i;
772 for (i = 0; i < 8; ++i)
773 hostdata->busy[i] = 0;
777 #if defined (REAL_DMA)
778 hostdata->dma_len = 0;
780 hostdata->targets_present = 0;
781 hostdata->connected = NULL;
782 hostdata->issue_queue = NULL;
783 hostdata->disconnected_queue = NULL;
784 hostdata->flags = FLAG_CHECK_LAST_BYTE_SENT;
787 the_template = instance->hostt;
788 first_instance = instance;
793 if ((instance->cmd_per_lun > 1) || (instance->can_queue > 1))
794 printk("scsi%d: WARNING : support for multiple outstanding commands enabled\n"
795 " without AUTOSENSE option, contingent allegiance conditions may\n"
796 " be incorrectly cleared.\n", HOSTNO);
797 #endif /* def AUTOSENSE */
799 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
800 NCR5380_write(MODE_REG, MR_BASE);
801 NCR5380_write(TARGET_COMMAND_REG, 0);
802 NCR5380_write(SELECT_ENABLE_REG, 0);
807 static void NCR5380_exit(struct Scsi_Host *instance)
809 /* Empty, as we didn't schedule any delayed work */
813 * Function : int NCR5380_queue_command (struct scsi_cmnd *cmd,
814 * void (*done)(struct scsi_cmnd *))
816 * Purpose : enqueues a SCSI command
818 * Inputs : cmd - SCSI command, done - function called on completion, with
819 * a pointer to the command descriptor.
824 * cmd is added to the per instance issue_queue, with minor
825 * twiddling done to the host specific fields of cmd. If the
826 * main coroutine is not running, it is restarted.
830 /* Only make static if a wrapper function is used */
831 static int NCR5380_queue_command_lck(struct scsi_cmnd *cmd,
832 void (*done)(struct scsi_cmnd *))
834 SETUP_HOSTDATA(cmd->device->host);
835 struct scsi_cmnd *tmp;
838 #if (NDEBUG & NDEBUG_NO_WRITE)
839 switch (cmd->cmnd[0]) {
842 printk(KERN_NOTICE "scsi%d: WRITE attempted with NO_WRITE debugging flag set\n",
844 cmd->result = (DID_ERROR << 16);
848 #endif /* (NDEBUG & NDEBUG_NO_WRITE) */
853 if (!hostdata->connected && !hostdata->issue_queue &&
854 !hostdata->disconnected_queue) {
855 hostdata->timebase = jiffies;
858 # ifdef NCR5380_STAT_LIMIT
859 if (scsi_bufflen(cmd) > NCR5380_STAT_LIMIT)
861 switch (cmd->cmnd[0])
866 hostdata->time_write[cmd->device->id] -= (jiffies - hostdata->timebase);
867 hostdata->bytes_write[cmd->device->id] += scsi_bufflen(cmd);
868 hostdata->pendingw++;
873 hostdata->time_read[cmd->device->id] -= (jiffies - hostdata->timebase);
874 hostdata->bytes_read[cmd->device->id] += scsi_bufflen(cmd);
875 hostdata->pendingr++;
881 * We use the host_scribble field as a pointer to the next command
886 cmd->scsi_done = done;
892 * Insert the cmd into the issue queue. Note that REQUEST SENSE
893 * commands are added to the head of the queue since any command will
894 * clear the contingent allegiance condition that exists and the
895 * sense data is only guaranteed to be valid while the condition exists.
898 local_irq_save(flags);
899 /* ++guenther: now that the issue queue is being set up, we can lock ST-DMA.
900 * Otherwise a running NCR5380_main may steal the lock.
901 * Lock before actually inserting due to fairness reasons explained in
902 * atari_scsi.c. If we insert first, then it's impossible for this driver
903 * to release the lock.
904 * Stop timer for this command while waiting for the lock, or timeouts
905 * may happen (and they really do), and it's no good if the command doesn't
906 * appear in any of the queues.
907 * ++roman: Just disabling the NCR interrupt isn't sufficient here,
908 * because also a timer int can trigger an abort or reset, which would
909 * alter queues and touch the lock.
911 if (!(hostdata->issue_queue) || (cmd->cmnd[0] == REQUEST_SENSE)) {
912 LIST(cmd, hostdata->issue_queue);
913 SET_NEXT(cmd, hostdata->issue_queue);
914 hostdata->issue_queue = cmd;
916 for (tmp = (struct scsi_cmnd *)hostdata->issue_queue;
917 NEXT(tmp); tmp = NEXT(tmp))
923 local_irq_restore(flags);
925 dprintk(NDEBUG_QUEUES, "scsi%d: command added to %s of queue\n", H_NO(cmd),
926 (cmd->cmnd[0] == REQUEST_SENSE) ? "head" : "tail");
928 /* If queue_command() is called from an interrupt (real one or bottom
929 * half), we let queue_main() do the job of taking care about main. If it
930 * is already running, this is a no-op, else main will be queued.
932 * If we're not in an interrupt, we can call NCR5380_main()
933 * unconditionally, because it cannot be already running.
935 if (in_interrupt() || ((flags >> 8) & 7) >= 6)
942 static DEF_SCSI_QCMD(NCR5380_queue_command)
945 * Function : NCR5380_main (void)
947 * Purpose : NCR5380_main is a coroutine that runs as long as more work can
948 * be done on the NCR5380 host adapters in a system. Both
949 * NCR5380_queue_command() and NCR5380_intr() will try to start it
950 * in case it is not running.
952 * NOTE : NCR5380_main exits with interrupts *disabled*, the caller should
953 * reenable them. This prevents reentrancy and kernel stack overflow.
956 static void NCR5380_main (struct work_struct *bl)
958 struct scsi_cmnd *tmp, *prev;
959 struct Scsi_Host *instance = first_instance;
960 struct NCR5380_hostdata *hostdata = HOSTDATA(instance);
965 * We run (with interrupts disabled) until we're sure that none of
966 * the host adapters have anything that can be done, at which point
967 * we set main_running to 0 and exit.
969 * Interrupts are enabled before doing various other internal
970 * instructions, after we've decided that we need to run through
973 * this should prevent any race conditions.
975 * ++roman: Just disabling the NCR interrupt isn't sufficient here,
976 * because also a timer int can trigger an abort or reset, which can
977 * alter queues and touch the Falcon lock.
980 /* Tell int handlers main() is now already executing. Note that
981 no races are possible here. If an int comes in before
982 'main_running' is set here, and queues/executes main via the
983 task queue, it doesn't do any harm, just this instance of main
984 won't find any work left to do. */
989 local_save_flags(flags);
991 local_irq_disable(); /* Freeze request queues */
994 if (!hostdata->connected) {
995 dprintk(NDEBUG_MAIN, "scsi%d: not connected\n", HOSTNO );
997 * Search through the issue_queue for a command destined
998 * for a target that's not busy.
1000 #if (NDEBUG & NDEBUG_LISTS)
1001 for (tmp = (struct scsi_cmnd *) hostdata->issue_queue, prev = NULL;
1002 tmp && (tmp != prev); prev = tmp, tmp = NEXT(tmp))
1004 if ((tmp == prev) && tmp) printk(" LOOP\n");/* else printk("\n");*/
1006 for (tmp = (struct scsi_cmnd *) hostdata->issue_queue,
1007 prev = NULL; tmp; prev = tmp, tmp = NEXT(tmp) ) {
1010 dprintk(NDEBUG_LISTS, "MAIN tmp=%p target=%d busy=%d lun=%d\n", tmp, tmp->device->id, hostdata->busy[tmp->device->id], tmp->device->lun);
1011 /* When we find one, remove it from the issue queue. */
1012 /* ++guenther: possible race with Falcon locking */
1015 !is_lun_busy( tmp, tmp->cmnd[0] != REQUEST_SENSE)
1017 !(hostdata->busy[tmp->device->id] & (1 << tmp->device->lun))
1020 /* ++guenther: just to be sure, this must be atomic */
1021 local_irq_disable();
1023 REMOVE(prev, NEXT(prev), tmp, NEXT(tmp));
1024 SET_NEXT(prev, NEXT(tmp));
1026 REMOVE(-1, hostdata->issue_queue, tmp, NEXT(tmp));
1027 hostdata->issue_queue = NEXT(tmp);
1029 SET_NEXT(tmp, NULL);
1031 /* reenable interrupts after finding one */
1032 local_irq_restore(flags);
1035 * Attempt to establish an I_T_L nexus here.
1036 * On success, instance->hostdata->connected is set.
1037 * On failure, we must add the command back to the
1038 * issue queue so we can keep trying.
1040 dprintk(NDEBUG_MAIN, "scsi%d: main(): command for target %d "
1041 "lun %d removed from issue_queue\n",
1042 HOSTNO, tmp->device->id, tmp->device->lun);
1044 * REQUEST SENSE commands are issued without tagged
1045 * queueing, even on SCSI-II devices because the
1046 * contingent allegiance condition exists for the
1049 /* ++roman: ...and the standard also requires that
1050 * REQUEST SENSE command are untagged.
1054 cmd_get_tag( tmp, tmp->cmnd[0] != REQUEST_SENSE );
1056 if (!NCR5380_select(instance, tmp,
1057 (tmp->cmnd[0] == REQUEST_SENSE) ? TAG_NONE :
1061 local_irq_disable();
1062 LIST(tmp, hostdata->issue_queue);
1063 SET_NEXT(tmp, hostdata->issue_queue);
1064 hostdata->issue_queue = tmp;
1066 cmd_free_tag( tmp );
1068 local_irq_restore(flags);
1069 dprintk(NDEBUG_MAIN, "scsi%d: main(): select() failed, "
1070 "returned to issue_queue\n", HOSTNO);
1071 if (hostdata->connected)
1074 } /* if target/lun/target queue is not busy */
1075 } /* for issue_queue */
1076 } /* if (!hostdata->connected) */
1077 if (hostdata->connected
1079 && !hostdata->dma_len
1082 local_irq_restore(flags);
1083 dprintk(NDEBUG_MAIN, "scsi%d: main: performing information transfer\n",
1085 NCR5380_information_transfer(instance);
1086 dprintk(NDEBUG_MAIN, "scsi%d: main: done set false\n", HOSTNO);
1091 /* Better allow ints _after_ 'main_running' has been cleared, else
1092 an interrupt could believe we'll pick up the work it left for
1093 us, but we won't see it anymore here... */
1095 local_irq_restore(flags);
1101 * Function : void NCR5380_dma_complete (struct Scsi_Host *instance)
1103 * Purpose : Called by interrupt handler when DMA finishes or a phase
1104 * mismatch occurs (which would finish the DMA transfer).
1106 * Inputs : instance - this instance of the NCR5380.
1110 static void NCR5380_dma_complete( struct Scsi_Host *instance )
1112 SETUP_HOSTDATA(instance);
1114 unsigned char **data;
1115 volatile int *count;
1117 if (!hostdata->connected) {
1118 printk(KERN_WARNING "scsi%d: received end of DMA interrupt with "
1119 "no connected cmd\n", HOSTNO);
1123 dprintk(NDEBUG_DMA, "scsi%d: real DMA transfer complete, basr 0x%X, sr 0x%X\n",
1124 HOSTNO, NCR5380_read(BUS_AND_STATUS_REG),
1125 NCR5380_read(STATUS_REG));
1127 if((sun3scsi_dma_finish(rq_data_dir(hostdata->connected->request)))) {
1128 printk("scsi%d: overrun in UDC counter -- not prepared to deal with this!\n", HOSTNO);
1129 printk("please e-mail sammy@sammy.net with a description of how this\n");
1130 printk("error was produced.\n");
1134 /* make sure we're not stuck in a data phase */
1135 if((NCR5380_read(BUS_AND_STATUS_REG) & (BASR_PHASE_MATCH |
1137 (BASR_PHASE_MATCH | BASR_ACK)) {
1138 printk("scsi%d: BASR %02x\n", HOSTNO, NCR5380_read(BUS_AND_STATUS_REG));
1139 printk("scsi%d: bus stuck in data phase -- probably a single byte "
1140 "overrun!\n", HOSTNO);
1141 printk("not prepared for this error!\n");
1142 printk("please e-mail sammy@sammy.net with a description of how this\n");
1143 printk("error was produced.\n");
1149 (void) NCR5380_read(RESET_PARITY_INTERRUPT_REG);
1150 NCR5380_write(MODE_REG, MR_BASE);
1151 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1153 transfered = hostdata->dma_len - NCR5380_dma_residual(instance);
1154 hostdata->dma_len = 0;
1156 data = (unsigned char **) &(hostdata->connected->SCp.ptr);
1157 count = &(hostdata->connected->SCp.this_residual);
1158 *data += transfered;
1159 *count -= transfered;
1162 #endif /* REAL_DMA */
1166 * Function : void NCR5380_intr (int irq)
1168 * Purpose : handle interrupts, reestablishing I_T_L or I_T_L_Q nexuses
1169 * from the disconnected queue, and restarting NCR5380_main()
1172 * Inputs : int irq, irq that caused this interrupt.
1176 static irqreturn_t NCR5380_intr (int irq, void *dev_id)
1178 struct Scsi_Host *instance = first_instance;
1179 int done = 1, handled = 0;
1182 dprintk(NDEBUG_INTR, "scsi%d: NCR5380 irq triggered\n", HOSTNO);
1184 /* Look for pending interrupts */
1185 basr = NCR5380_read(BUS_AND_STATUS_REG);
1186 dprintk(NDEBUG_INTR, "scsi%d: BASR=%02x\n", HOSTNO, basr);
1187 /* dispatch to appropriate routine if found and done=0 */
1188 if (basr & BASR_IRQ) {
1189 NCR5380_dprint(NDEBUG_INTR, instance);
1190 if ((NCR5380_read(STATUS_REG) & (SR_SEL|SR_IO)) == (SR_SEL|SR_IO)) {
1193 dprintk(NDEBUG_INTR, "scsi%d: SEL interrupt\n", HOSTNO);
1194 NCR5380_reselect(instance);
1195 (void) NCR5380_read(RESET_PARITY_INTERRUPT_REG);
1197 else if (basr & BASR_PARITY_ERROR) {
1198 dprintk(NDEBUG_INTR, "scsi%d: PARITY interrupt\n", HOSTNO);
1199 (void) NCR5380_read(RESET_PARITY_INTERRUPT_REG);
1201 else if ((NCR5380_read(STATUS_REG) & SR_RST) == SR_RST) {
1202 dprintk(NDEBUG_INTR, "scsi%d: RESET interrupt\n", HOSTNO);
1203 (void)NCR5380_read(RESET_PARITY_INTERRUPT_REG);
1207 * The rest of the interrupt conditions can occur only during a
1211 #if defined(REAL_DMA)
1213 * We should only get PHASE MISMATCH and EOP interrupts if we have
1214 * DMA enabled, so do a sanity check based on the current setting
1215 * of the MODE register.
1218 if ((NCR5380_read(MODE_REG) & MR_DMA_MODE) &&
1219 ((basr & BASR_END_DMA_TRANSFER) ||
1220 !(basr & BASR_PHASE_MATCH))) {
1222 dprintk(NDEBUG_INTR, "scsi%d: PHASE MISM or EOP interrupt\n", HOSTNO);
1223 NCR5380_dma_complete( instance );
1227 #endif /* REAL_DMA */
1229 /* MS: Ignore unknown phase mismatch interrupts (caused by EOP interrupt) */
1230 if (basr & BASR_PHASE_MATCH)
1231 dprintk(NDEBUG_INTR, "scsi%d: unknown interrupt, "
1232 "BASR 0x%x, MR 0x%x, SR 0x%x\n",
1233 HOSTNO, basr, NCR5380_read(MODE_REG),
1234 NCR5380_read(STATUS_REG));
1235 (void) NCR5380_read(RESET_PARITY_INTERRUPT_REG);
1236 #ifdef SUN3_SCSI_VME
1237 dregs->csr |= CSR_DMA_ENABLE;
1240 } /* if !(SELECTION || PARITY) */
1245 printk(KERN_NOTICE "scsi%d: interrupt without IRQ bit set in BASR, "
1246 "BASR 0x%X, MR 0x%X, SR 0x%x\n", HOSTNO, basr,
1247 NCR5380_read(MODE_REG), NCR5380_read(STATUS_REG));
1248 (void) NCR5380_read(RESET_PARITY_INTERRUPT_REG);
1249 #ifdef SUN3_SCSI_VME
1250 dregs->csr |= CSR_DMA_ENABLE;
1255 dprintk(NDEBUG_INTR, "scsi%d: in int routine, calling main\n", HOSTNO);
1256 /* Put a call to NCR5380_main() on the queue... */
1259 return IRQ_RETVAL(handled);
1262 #ifdef NCR5380_STATS
1263 static void collect_stats(struct NCR5380_hostdata *hostdata,
1264 struct scsi_cmnd *cmd)
1266 # ifdef NCR5380_STAT_LIMIT
1267 if (scsi_bufflen(cmd) > NCR5380_STAT_LIMIT)
1269 switch (cmd->cmnd[0])
1274 hostdata->time_write[cmd->device->id] += (jiffies - hostdata->timebase);
1275 /*hostdata->bytes_write[cmd->device->id] += scsi_bufflen(cmd);*/
1276 hostdata->pendingw--;
1281 hostdata->time_read[cmd->device->id] += (jiffies - hostdata->timebase);
1282 /*hostdata->bytes_read[cmd->device->id] += scsi_bufflen(cmd);*/
1283 hostdata->pendingr--;
1290 * Function : int NCR5380_select(struct Scsi_Host *instance,
1291 * struct scsi_cmnd *cmd, int tag);
1293 * Purpose : establishes I_T_L or I_T_L_Q nexus for new or existing command,
1294 * including ARBITRATION, SELECTION, and initial message out for
1295 * IDENTIFY and queue messages.
1297 * Inputs : instance - instantiation of the 5380 driver on which this
1298 * target lives, cmd - SCSI command to execute, tag - set to TAG_NEXT for
1299 * new tag, TAG_NONE for untagged queueing, otherwise set to the tag for
1300 * the command that is presently connected.
1302 * Returns : -1 if selection could not execute for some reason,
1303 * 0 if selection succeeded or failed because the target
1307 * If bus busy, arbitration failed, etc, NCR5380_select() will exit
1308 * with registers as they should have been on entry - ie
1309 * SELECT_ENABLE will be set appropriately, the NCR5380
1310 * will cease to drive any SCSI bus signals.
1312 * If successful : I_T_L or I_T_L_Q nexus will be established,
1313 * instance->connected will be set to cmd.
1314 * SELECT interrupt will be disabled.
1316 * If failed (no target) : cmd->scsi_done() will be called, and the
1317 * cmd->result host byte set to DID_BAD_TARGET.
1320 static int NCR5380_select(struct Scsi_Host *instance, struct scsi_cmnd *cmd,
1323 SETUP_HOSTDATA(instance);
1324 unsigned char tmp[3], phase;
1325 unsigned char *data;
1327 unsigned long timeout;
1328 unsigned long flags;
1330 hostdata->restart_select = 0;
1331 NCR5380_dprint(NDEBUG_ARBITRATION, instance);
1332 dprintk(NDEBUG_ARBITRATION, "scsi%d: starting arbitration, id = %d\n", HOSTNO,
1336 * Set the phase bits to 0, otherwise the NCR5380 won't drive the
1337 * data bus during SELECTION.
1340 local_irq_save(flags);
1341 if (hostdata->connected) {
1342 local_irq_restore(flags);
1345 NCR5380_write(TARGET_COMMAND_REG, 0);
1349 * Start arbitration.
1352 NCR5380_write(OUTPUT_DATA_REG, hostdata->id_mask);
1353 NCR5380_write(MODE_REG, MR_ARBITRATE);
1355 local_irq_restore(flags);
1357 /* Wait for arbitration logic to complete */
1360 unsigned long timeout = jiffies + 2*NCR_TIMEOUT;
1362 while (!(NCR5380_read(INITIATOR_COMMAND_REG) & ICR_ARBITRATION_PROGRESS)
1363 && time_before(jiffies, timeout) && !hostdata->connected)
1365 if (time_after_eq(jiffies, timeout))
1367 printk("scsi : arbitration timeout at %d\n", __LINE__);
1368 NCR5380_write(MODE_REG, MR_BASE);
1369 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
1373 #else /* NCR_TIMEOUT */
1374 while (!(NCR5380_read(INITIATOR_COMMAND_REG) & ICR_ARBITRATION_PROGRESS)
1375 && !hostdata->connected);
1378 dprintk(NDEBUG_ARBITRATION, "scsi%d: arbitration complete\n", HOSTNO);
1380 if (hostdata->connected) {
1381 NCR5380_write(MODE_REG, MR_BASE);
1385 * The arbitration delay is 2.2us, but this is a minimum and there is
1386 * no maximum so we can safely sleep for ceil(2.2) usecs to accommodate
1387 * the integral nature of udelay().
1393 /* Check for lost arbitration */
1394 if ((NCR5380_read(INITIATOR_COMMAND_REG) & ICR_ARBITRATION_LOST) ||
1395 (NCR5380_read(CURRENT_SCSI_DATA_REG) & hostdata->id_higher_mask) ||
1396 (NCR5380_read(INITIATOR_COMMAND_REG) & ICR_ARBITRATION_LOST) ||
1397 hostdata->connected) {
1398 NCR5380_write(MODE_REG, MR_BASE);
1399 dprintk(NDEBUG_ARBITRATION, "scsi%d: lost arbitration, deasserting MR_ARBITRATE\n",
1404 /* after/during arbitration, BSY should be asserted.
1405 IBM DPES-31080 Version S31Q works now */
1406 /* Tnx to Thomas_Roesch@m2.maus.de for finding this! (Roman) */
1407 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_SEL |
1410 if ((NCR5380_read(INITIATOR_COMMAND_REG) & ICR_ARBITRATION_LOST) ||
1411 hostdata->connected) {
1412 NCR5380_write(MODE_REG, MR_BASE);
1413 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1414 dprintk(NDEBUG_ARBITRATION, "scsi%d: lost arbitration, deasserting ICR_ASSERT_SEL\n",
1420 * Again, bus clear + bus settle time is 1.2us, however, this is
1421 * a minimum so we'll udelay ceil(1.2)
1424 #ifdef CONFIG_ATARI_SCSI_TOSHIBA_DELAY
1425 /* ++roman: But some targets (see above :-) seem to need a bit more... */
1431 if (hostdata->connected) {
1432 NCR5380_write(MODE_REG, MR_BASE);
1433 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1437 dprintk(NDEBUG_ARBITRATION, "scsi%d: won arbitration\n", HOSTNO);
1440 * Now that we have won arbitration, start Selection process, asserting
1441 * the host and target ID's on the SCSI bus.
1444 NCR5380_write(OUTPUT_DATA_REG, (hostdata->id_mask | (1 << cmd->device->id)));
1447 * Raise ATN while SEL is true before BSY goes false from arbitration,
1448 * since this is the only way to guarantee that we'll get a MESSAGE OUT
1449 * phase immediately after selection.
1452 NCR5380_write(INITIATOR_COMMAND_REG, (ICR_BASE | ICR_ASSERT_BSY |
1453 ICR_ASSERT_DATA | ICR_ASSERT_ATN | ICR_ASSERT_SEL ));
1454 NCR5380_write(MODE_REG, MR_BASE);
1457 * Reselect interrupts must be turned off prior to the dropping of BSY,
1458 * otherwise we will trigger an interrupt.
1461 if (hostdata->connected) {
1462 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1466 NCR5380_write(SELECT_ENABLE_REG, 0);
1469 * The initiator shall then wait at least two deskew delays and release
1472 udelay(1); /* wingel -- wait two bus deskew delay >2*45ns */
1475 NCR5380_write(INITIATOR_COMMAND_REG, (ICR_BASE | ICR_ASSERT_DATA |
1476 ICR_ASSERT_ATN | ICR_ASSERT_SEL));
1479 * Something weird happens when we cease to drive BSY - looks
1480 * like the board/chip is letting us do another read before the
1481 * appropriate propagation delay has expired, and we're confusing
1482 * a BSY signal from ourselves as the target's response to SELECTION.
1484 * A small delay (the 'C++' frontend breaks the pipeline with an
1485 * unnecessary jump, making it work on my 386-33/Trantor T128, the
1486 * tighter 'C' code breaks and requires this) solves the problem -
1487 * the 1 us delay is arbitrary, and only used because this delay will
1488 * be the same on other platforms and since it works here, it should
1491 * wingel suggests that this could be due to failing to wait
1497 dprintk(NDEBUG_SELECTION, "scsi%d: selecting target %d\n", HOSTNO, cmd->device->id);
1500 * The SCSI specification calls for a 250 ms timeout for the actual
1504 timeout = jiffies + 25;
1507 * XXX very interesting - we're seeing a bounce where the BSY we
1508 * asserted is being reflected / still asserted (propagation delay?)
1509 * and it's detecting as true. Sigh.
1513 /* ++roman: If a target conformed to the SCSI standard, it wouldn't assert
1514 * IO while SEL is true. But again, there are some disks out the in the
1515 * world that do that nevertheless. (Somebody claimed that this announces
1516 * reselection capability of the target.) So we better skip that test and
1517 * only wait for BSY... (Famous german words: Der Klügere gibt nach :-)
1520 while (time_before(jiffies, timeout) && !(NCR5380_read(STATUS_REG) &
1523 if ((NCR5380_read(STATUS_REG) & (SR_SEL | SR_IO)) ==
1525 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1526 NCR5380_reselect(instance);
1527 printk (KERN_ERR "scsi%d: reselection after won arbitration?\n",
1529 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
1533 while (time_before(jiffies, timeout) && !(NCR5380_read(STATUS_REG) & SR_BSY));
1537 * No less than two deskew delays after the initiator detects the
1538 * BSY signal is true, it shall release the SEL signal and may
1539 * change the DATA BUS. -wingel
1544 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN);
1546 if (!(NCR5380_read(STATUS_REG) & SR_BSY)) {
1547 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1548 if (hostdata->targets_present & (1 << cmd->device->id)) {
1549 printk(KERN_ERR "scsi%d: weirdness\n", HOSTNO);
1550 if (hostdata->restart_select)
1551 printk(KERN_NOTICE "\trestart select\n");
1552 NCR5380_dprint(NDEBUG_ANY, instance);
1553 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
1556 cmd->result = DID_BAD_TARGET << 16;
1557 #ifdef NCR5380_STATS
1558 collect_stats(hostdata, cmd);
1561 cmd_free_tag( cmd );
1563 cmd->scsi_done(cmd);
1564 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
1565 dprintk(NDEBUG_SELECTION, "scsi%d: target did not respond within 250ms\n", HOSTNO);
1566 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
1570 hostdata->targets_present |= (1 << cmd->device->id);
1573 * Since we followed the SCSI spec, and raised ATN while SEL
1574 * was true but before BSY was false during selection, the information
1575 * transfer phase should be a MESSAGE OUT phase so that we can send the
1578 * If SCSI-II tagged queuing is enabled, we also send a SIMPLE_QUEUE_TAG
1579 * message (2 bytes) with a tag ID that we increment with every command
1580 * until it wraps back to 0.
1582 * XXX - it turns out that there are some broken SCSI-II devices,
1583 * which claim to support tagged queuing but fail when more than
1584 * some number of commands are issued at once.
1587 /* Wait for start of REQ/ACK handshake */
1588 while (!(NCR5380_read(STATUS_REG) & SR_REQ));
1590 dprintk(NDEBUG_SELECTION, "scsi%d: target %d selected, going into MESSAGE OUT phase.\n",
1591 HOSTNO, cmd->device->id);
1592 tmp[0] = IDENTIFY(1, cmd->device->lun);
1595 if (cmd->tag != TAG_NONE) {
1596 tmp[1] = hostdata->last_message = SIMPLE_QUEUE_TAG;
1604 #endif /* SUPPORT_TAGS */
1606 /* Send message(s) */
1608 phase = PHASE_MSGOUT;
1609 NCR5380_transfer_pio(instance, &phase, &len, &data);
1610 dprintk(NDEBUG_SELECTION, "scsi%d: nexus established.\n", HOSTNO);
1611 /* XXX need to handle errors here */
1612 hostdata->connected = cmd;
1613 #ifndef SUPPORT_TAGS
1614 hostdata->busy[cmd->device->id] |= (1 << cmd->device->lun);
1616 #ifdef SUN3_SCSI_VME
1617 dregs->csr |= CSR_INTR;
1619 initialize_SCp(cmd);
1626 * Function : int NCR5380_transfer_pio (struct Scsi_Host *instance,
1627 * unsigned char *phase, int *count, unsigned char **data)
1629 * Purpose : transfers data in given phase using polled I/O
1631 * Inputs : instance - instance of driver, *phase - pointer to
1632 * what phase is expected, *count - pointer to number of
1633 * bytes to transfer, **data - pointer to data pointer.
1635 * Returns : -1 when different phase is entered without transferring
1636 * maximum number of bytes, 0 if all bytes are transferred or exit
1639 * Also, *phase, *count, *data are modified in place.
1641 * XXX Note : handling for bus free may be useful.
1645 * Note : this code is not as quick as it could be, however it
1646 * IS 100% reliable, and for the actual data transfer where speed
1647 * counts, we will always do a pseudo DMA or DMA transfer.
1650 static int NCR5380_transfer_pio( struct Scsi_Host *instance,
1651 unsigned char *phase, int *count,
1652 unsigned char **data)
1654 register unsigned char p = *phase, tmp;
1655 register int c = *count;
1656 register unsigned char *d = *data;
1659 * The NCR5380 chip will only drive the SCSI bus when the
1660 * phase specified in the appropriate bits of the TARGET COMMAND
1661 * REGISTER match the STATUS REGISTER
1664 NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(p));
1668 * Wait for assertion of REQ, after which the phase bits will be
1671 while (!((tmp = NCR5380_read(STATUS_REG)) & SR_REQ));
1673 dprintk(NDEBUG_HANDSHAKE, "scsi%d: REQ detected\n", HOSTNO);
1675 /* Check for phase mismatch */
1676 if ((tmp & PHASE_MASK) != p) {
1677 dprintk(NDEBUG_PIO, "scsi%d: phase mismatch\n", HOSTNO);
1678 NCR5380_dprint_phase(NDEBUG_PIO, instance);
1682 /* Do actual transfer from SCSI bus to / from memory */
1684 NCR5380_write(OUTPUT_DATA_REG, *d);
1686 *d = NCR5380_read(CURRENT_SCSI_DATA_REG);
1691 * The SCSI standard suggests that in MSGOUT phase, the initiator
1692 * should drop ATN on the last byte of the message phase
1693 * after REQ has been asserted for the handshake but before
1694 * the initiator raises ACK.
1698 if (!((p & SR_MSG) && c > 1)) {
1699 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
1701 NCR5380_dprint(NDEBUG_PIO, instance);
1702 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
1703 ICR_ASSERT_DATA | ICR_ASSERT_ACK);
1705 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
1706 ICR_ASSERT_DATA | ICR_ASSERT_ATN);
1707 NCR5380_dprint(NDEBUG_PIO, instance);
1708 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
1709 ICR_ASSERT_DATA | ICR_ASSERT_ATN | ICR_ASSERT_ACK);
1712 NCR5380_dprint(NDEBUG_PIO, instance);
1713 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ACK);
1716 while (NCR5380_read(STATUS_REG) & SR_REQ);
1718 dprintk(NDEBUG_HANDSHAKE, "scsi%d: req false, handshake complete\n", HOSTNO);
1721 * We have several special cases to consider during REQ/ACK handshaking :
1722 * 1. We were in MSGOUT phase, and we are on the last byte of the
1723 * message. ATN must be dropped as ACK is dropped.
1725 * 2. We are in a MSGIN phase, and we are on the last byte of the
1726 * message. We must exit with ACK asserted, so that the calling
1727 * code may raise ATN before dropping ACK to reject the message.
1729 * 3. ACK and ATN are clear and the target may proceed as normal.
1731 if (!(p == PHASE_MSGIN && c == 1)) {
1732 if (p == PHASE_MSGOUT && c > 1)
1733 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN);
1735 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1739 dprintk(NDEBUG_PIO, "scsi%d: residual %d\n", HOSTNO, c);
1743 tmp = NCR5380_read(STATUS_REG);
1744 /* The phase read from the bus is valid if either REQ is (already)
1745 * asserted or if ACK hasn't been released yet. The latter is the case if
1746 * we're in MSGIN and all wanted bytes have been received. */
1747 if ((tmp & SR_REQ) || (p == PHASE_MSGIN && c == 0))
1748 *phase = tmp & PHASE_MASK;
1750 *phase = PHASE_UNKNOWN;
1752 if (!c || (*phase == p))
1759 * Function : do_abort (Scsi_Host *host)
1761 * Purpose : abort the currently established nexus. Should only be
1762 * called from a routine which can drop into a
1764 * Returns : 0 on success, -1 on failure.
1767 static int do_abort (struct Scsi_Host *host)
1769 unsigned char tmp, *msgptr, phase;
1772 /* Request message out phase */
1773 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN);
1776 * Wait for the target to indicate a valid phase by asserting
1777 * REQ. Once this happens, we'll have either a MSGOUT phase
1778 * and can immediately send the ABORT message, or we'll have some
1779 * other phase and will have to source/sink data.
1781 * We really don't care what value was on the bus or what value
1782 * the target sees, so we just handshake.
1785 while (!((tmp = NCR5380_read(STATUS_REG)) & SR_REQ));
1787 NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(tmp));
1789 if ((tmp & PHASE_MASK) != PHASE_MSGOUT) {
1790 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN |
1792 while (NCR5380_read(STATUS_REG) & SR_REQ);
1793 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN);
1799 phase = PHASE_MSGOUT;
1800 NCR5380_transfer_pio (host, &phase, &len, &msgptr);
1803 * If we got here, and the command completed successfully,
1804 * we're about to go into bus free state.
1807 return len ? -1 : 0;
1810 #if defined(REAL_DMA)
1812 * Function : int NCR5380_transfer_dma (struct Scsi_Host *instance,
1813 * unsigned char *phase, int *count, unsigned char **data)
1815 * Purpose : transfers data in given phase using either real
1818 * Inputs : instance - instance of driver, *phase - pointer to
1819 * what phase is expected, *count - pointer to number of
1820 * bytes to transfer, **data - pointer to data pointer.
1822 * Returns : -1 when different phase is entered without transferring
1823 * maximum number of bytes, 0 if all bytes or transferred or exit
1826 * Also, *phase, *count, *data are modified in place.
1831 static int NCR5380_transfer_dma( struct Scsi_Host *instance,
1832 unsigned char *phase, int *count,
1833 unsigned char **data)
1835 SETUP_HOSTDATA(instance);
1836 register int c = *count;
1837 register unsigned char p = *phase;
1838 unsigned long flags;
1841 if(!sun3_dma_setup_done) {
1842 printk("scsi%d: transfer_dma without setup!\n", HOSTNO);
1845 hostdata->dma_len = c;
1847 dprintk(NDEBUG_DMA, "scsi%d: initializing DMA for %s, %d bytes %s %p\n",
1848 HOSTNO, (p & SR_IO) ? "reading" : "writing",
1849 c, (p & SR_IO) ? "to" : "from", *data);
1851 /* netbsd turns off ints here, why not be safe and do it too */
1852 local_irq_save(flags);
1854 /* send start chain */
1855 sun3scsi_dma_start(c, *data);
1858 NCR5380_write(TARGET_COMMAND_REG, 1);
1859 NCR5380_read(RESET_PARITY_INTERRUPT_REG);
1860 NCR5380_write(INITIATOR_COMMAND_REG, 0);
1861 NCR5380_write(MODE_REG, (NCR5380_read(MODE_REG) | MR_DMA_MODE | MR_ENABLE_EOP_INTR));
1862 NCR5380_write(START_DMA_INITIATOR_RECEIVE_REG, 0);
1864 NCR5380_write(TARGET_COMMAND_REG, 0);
1865 NCR5380_read(RESET_PARITY_INTERRUPT_REG);
1866 NCR5380_write(INITIATOR_COMMAND_REG, ICR_ASSERT_DATA);
1867 NCR5380_write(MODE_REG, (NCR5380_read(MODE_REG) | MR_DMA_MODE | MR_ENABLE_EOP_INTR));
1868 NCR5380_write(START_DMA_SEND_REG, 0);
1871 #ifdef SUN3_SCSI_VME
1872 dregs->csr |= CSR_DMA_ENABLE;
1875 local_irq_restore(flags);
1877 sun3_dma_active = 1;
1880 #endif /* defined(REAL_DMA) */
1883 * Function : NCR5380_information_transfer (struct Scsi_Host *instance)
1885 * Purpose : run through the various SCSI phases and do as the target
1886 * directs us to. Operates on the currently connected command,
1887 * instance->connected.
1889 * Inputs : instance, instance for which we are doing commands
1891 * Side effects : SCSI things happen, the disconnected queue will be
1892 * modified if a command disconnects, *instance->connected will
1895 * XXX Note : we need to watch for bus free or a reset condition here
1896 * to recover from an unexpected bus free condition.
1899 static void NCR5380_information_transfer (struct Scsi_Host *instance)
1901 SETUP_HOSTDATA(instance);
1902 unsigned long flags;
1903 unsigned char msgout = NOP;
1906 #if defined(REAL_DMA)
1909 unsigned char *data;
1910 unsigned char phase, tmp, extended_msg[10], old_phase=0xff;
1911 struct scsi_cmnd *cmd = (struct scsi_cmnd *) hostdata->connected;
1913 #ifdef SUN3_SCSI_VME
1914 dregs->csr |= CSR_INTR;
1918 tmp = NCR5380_read(STATUS_REG);
1919 /* We only have a valid SCSI phase when REQ is asserted */
1921 phase = (tmp & PHASE_MASK);
1922 if (phase != old_phase) {
1924 NCR5380_dprint_phase(NDEBUG_INFORMATION, instance);
1927 if(phase == PHASE_CMDOUT) {
1929 unsigned long count;
1931 if (!cmd->SCp.this_residual && cmd->SCp.buffers_residual) {
1932 count = cmd->SCp.buffer->length;
1933 d = SGADDR(cmd->SCp.buffer);
1935 count = cmd->SCp.this_residual;
1939 /* this command setup for dma yet? */
1940 if((count > SUN3_DMA_MINSIZE) && (sun3_dma_setup_done
1943 if (cmd->request->cmd_type == REQ_TYPE_FS) {
1944 sun3scsi_dma_setup(d, count,
1945 rq_data_dir(cmd->request));
1946 sun3_dma_setup_done = cmd;
1950 #ifdef SUN3_SCSI_VME
1951 dregs->csr |= CSR_INTR;
1956 if (sink && (phase != PHASE_MSGOUT)) {
1957 NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(tmp));
1959 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN |
1961 while (NCR5380_read(STATUS_REG) & SR_REQ);
1962 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
1970 #if (NDEBUG & NDEBUG_NO_DATAOUT)
1971 printk("scsi%d: NDEBUG_NO_DATAOUT set, attempted DATAOUT "
1972 "aborted\n", HOSTNO);
1975 cmd->result = DID_ERROR << 16;
1976 cmd->scsi_done(cmd);
1981 * If there is no room left in the current buffer in the
1982 * scatter-gather list, move onto the next one.
1984 if (!cmd->SCp.this_residual && cmd->SCp.buffers_residual) {
1986 --cmd->SCp.buffers_residual;
1987 cmd->SCp.this_residual = cmd->SCp.buffer->length;
1988 cmd->SCp.ptr = SGADDR(cmd->SCp.buffer);
1989 dprintk(NDEBUG_INFORMATION, "scsi%d: %d bytes and %d buffers left\n",
1990 HOSTNO, cmd->SCp.this_residual,
1991 cmd->SCp.buffers_residual);
1995 * The preferred transfer method is going to be
1996 * PSEUDO-DMA for systems that are strictly PIO,
1997 * since we can let the hardware do the handshaking.
1999 * For this to work, we need to know the transfersize
2000 * ahead of time, since the pseudo-DMA code will sit
2001 * in an unconditional loop.
2004 /* ++roman: I suggest, this should be
2006 * instead of leaving REAL_DMA out.
2009 #if defined(REAL_DMA)
2010 // if (!cmd->device->borken &&
2012 NCR5380_dma_xfer_len(instance,cmd,phase)) > SUN3_DMA_MINSIZE) {
2014 cmd->SCp.phase = phase;
2016 if (NCR5380_transfer_dma(instance, &phase,
2017 &len, (unsigned char **) &cmd->SCp.ptr)) {
2019 * If the watchdog timer fires, all future
2020 * accesses to this device will use the
2022 printk(KERN_NOTICE "scsi%d: switching target %d "
2023 "lun %d to slow handshake\n", HOSTNO,
2024 cmd->device->id, cmd->device->lun);
2025 cmd->device->borken = 1;
2026 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
2030 cmd->result = DID_ERROR << 16;
2031 cmd->scsi_done(cmd);
2032 /* XXX - need to source or sink data here, as appropriate */
2035 /* ++roman: When using real DMA,
2036 * information_transfer() should return after
2037 * starting DMA since it has nothing more to
2042 cmd->SCp.this_residual -= transfersize - len;
2046 #endif /* defined(REAL_DMA) */
2047 NCR5380_transfer_pio(instance, &phase,
2048 (int *) &cmd->SCp.this_residual, (unsigned char **)
2051 /* if we had intended to dma that command clear it */
2052 if(sun3_dma_setup_done == cmd)
2053 sun3_dma_setup_done = NULL;
2060 NCR5380_write(SELECT_ENABLE_REG, 0); /* disable reselects */
2061 NCR5380_transfer_pio(instance, &phase, &len, &data);
2062 cmd->SCp.Message = tmp;
2066 * Linking lets us reduce the time required to get the
2067 * next command out to the device, hopefully this will
2068 * mean we don't waste another revolution due to the delays
2069 * required by ARBITRATION and another SELECTION.
2071 * In the current implementation proposal, low level drivers
2072 * merely have to start the next command, pointed to by
2073 * next_link, done() is called as with unlinked commands.
2076 case LINKED_CMD_COMPLETE:
2077 case LINKED_FLG_CMD_COMPLETE:
2078 /* Accept message by clearing ACK */
2079 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2081 dprintk(NDEBUG_LINKED, "scsi%d: target %d lun %d linked command "
2082 "complete.\n", HOSTNO, cmd->device->id, cmd->device->lun);
2084 /* Enable reselect interrupts */
2085 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
2087 * Sanity check : A linked command should only terminate
2088 * with one of these messages if there are more linked
2089 * commands available.
2092 if (!cmd->next_link) {
2093 printk(KERN_NOTICE "scsi%d: target %d lun %d "
2094 "linked command complete, no next_link\n",
2095 HOSTNO, cmd->device->id, cmd->device->lun);
2097 do_abort (instance);
2101 initialize_SCp(cmd->next_link);
2102 /* The next command is still part of this process; copy it
2103 * and don't free it! */
2104 cmd->next_link->tag = cmd->tag;
2105 cmd->result = cmd->SCp.Status | (cmd->SCp.Message << 8);
2106 dprintk(NDEBUG_LINKED, "scsi%d: target %d lun %d linked request "
2107 "done, calling scsi_done().\n",
2108 HOSTNO, cmd->device->id, cmd->device->lun);
2109 #ifdef NCR5380_STATS
2110 collect_stats(hostdata, cmd);
2112 cmd->scsi_done(cmd);
2113 cmd = hostdata->connected;
2115 #endif /* def LINKED */
2117 case COMMAND_COMPLETE:
2118 /* Accept message by clearing ACK */
2119 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2120 hostdata->connected = NULL;
2121 dprintk(NDEBUG_QUEUES, "scsi%d: command for target %d, lun %d "
2122 "completed\n", HOSTNO, cmd->device->id, cmd->device->lun);
2124 cmd_free_tag( cmd );
2125 if (status_byte(cmd->SCp.Status) == QUEUE_FULL) {
2126 /* Turn a QUEUE FULL status into BUSY, I think the
2127 * mid level cannot handle QUEUE FULL :-( (The
2128 * command is retried after BUSY). Also update our
2129 * queue size to the number of currently issued
2132 /* ++Andreas: the mid level code knows about
2134 TAG_ALLOC *ta = &TagAlloc[cmd->device->id][cmd->device->lun];
2135 dprintk(NDEBUG_TAGS, "scsi%d: target %d lun %d returned "
2136 "QUEUE_FULL after %d commands\n",
2137 HOSTNO, cmd->device->id, cmd->device->lun,
2139 if (ta->queue_size > ta->nr_allocated)
2140 ta->nr_allocated = ta->queue_size;
2143 hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
2145 /* Enable reselect interrupts */
2146 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
2149 * I'm not sure what the correct thing to do here is :
2151 * If the command that just executed is NOT a request
2152 * sense, the obvious thing to do is to set the result
2153 * code to the values of the stored parameters.
2155 * If it was a REQUEST SENSE command, we need some way to
2156 * differentiate between the failure code of the original
2157 * and the failure code of the REQUEST sense - the obvious
2158 * case is success, where we fall through and leave the
2159 * result code unchanged.
2161 * The non-obvious place is where the REQUEST SENSE failed
2164 if (cmd->cmnd[0] != REQUEST_SENSE)
2165 cmd->result = cmd->SCp.Status | (cmd->SCp.Message << 8);
2166 else if (status_byte(cmd->SCp.Status) != GOOD)
2167 cmd->result = (cmd->result & 0x00ffff) | (DID_ERROR << 16);
2170 if ((cmd->cmnd[0] == REQUEST_SENSE) &&
2171 hostdata->ses.cmd_len) {
2172 scsi_eh_restore_cmnd(cmd, &hostdata->ses);
2173 hostdata->ses.cmd_len = 0 ;
2176 if ((cmd->cmnd[0] != REQUEST_SENSE) &&
2177 (status_byte(cmd->SCp.Status) == CHECK_CONDITION)) {
2178 scsi_eh_prep_cmnd(cmd, &hostdata->ses, NULL, 0, ~0);
2179 dprintk(NDEBUG_AUTOSENSE, "scsi%d: performing request sense\n",
2181 /* this is initialized from initialize_SCp
2182 cmd->SCp.buffer = NULL;
2183 cmd->SCp.buffers_residual = 0;
2186 local_irq_save(flags);
2187 LIST(cmd,hostdata->issue_queue);
2188 SET_NEXT(cmd, hostdata->issue_queue);
2189 hostdata->issue_queue = (struct scsi_cmnd *) cmd;
2190 local_irq_restore(flags);
2191 dprintk(NDEBUG_QUEUES, "scsi%d: REQUEST SENSE added to head of "
2192 "issue queue\n", H_NO(cmd));
2194 #endif /* def AUTOSENSE */
2196 #ifdef NCR5380_STATS
2197 collect_stats(hostdata, cmd);
2199 cmd->scsi_done(cmd);
2202 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
2204 * Restore phase bits to 0 so an interrupted selection,
2205 * arbitration can resume.
2207 NCR5380_write(TARGET_COMMAND_REG, 0);
2209 while ((NCR5380_read(STATUS_REG) & SR_BSY) && !hostdata->connected)
2213 case MESSAGE_REJECT:
2214 /* Accept message by clearing ACK */
2215 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2216 /* Enable reselect interrupts */
2217 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
2218 switch (hostdata->last_message) {
2219 case HEAD_OF_QUEUE_TAG:
2220 case ORDERED_QUEUE_TAG:
2221 case SIMPLE_QUEUE_TAG:
2222 /* The target obviously doesn't support tagged
2223 * queuing, even though it announced this ability in
2224 * its INQUIRY data ?!? (maybe only this LUN?) Ok,
2225 * clear 'tagged_supported' and lock the LUN, since
2226 * the command is treated as untagged further on.
2228 cmd->device->tagged_supported = 0;
2229 hostdata->busy[cmd->device->id] |= (1 << cmd->device->lun);
2230 cmd->tag = TAG_NONE;
2231 dprintk(NDEBUG_TAGS, "scsi%d: target %d lun %d rejected "
2232 "QUEUE_TAG message; tagged queuing "
2234 HOSTNO, cmd->device->id, cmd->device->lun);
2239 /* Accept message by clearing ACK */
2240 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2241 local_irq_save(flags);
2242 cmd->device->disconnect = 1;
2243 LIST(cmd,hostdata->disconnected_queue);
2244 SET_NEXT(cmd, hostdata->disconnected_queue);
2245 hostdata->connected = NULL;
2246 hostdata->disconnected_queue = cmd;
2247 local_irq_restore(flags);
2248 dprintk(NDEBUG_QUEUES, "scsi%d: command for target %d lun %d was "
2249 "moved from connected to the "
2250 "disconnected_queue\n", HOSTNO,
2251 cmd->device->id, cmd->device->lun);
2253 * Restore phase bits to 0 so an interrupted selection,
2254 * arbitration can resume.
2256 NCR5380_write(TARGET_COMMAND_REG, 0);
2258 /* Enable reselect interrupts */
2259 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
2260 /* Wait for bus free to avoid nasty timeouts */
2261 while ((NCR5380_read(STATUS_REG) & SR_BSY) && !hostdata->connected)
2263 #ifdef SUN3_SCSI_VME
2264 dregs->csr |= CSR_DMA_ENABLE;
2268 * The SCSI data pointer is *IMPLICITLY* saved on a disconnect
2269 * operation, in violation of the SCSI spec so we can safely
2270 * ignore SAVE/RESTORE pointers calls.
2272 * Unfortunately, some disks violate the SCSI spec and
2273 * don't issue the required SAVE_POINTERS message before
2274 * disconnecting, and we have to break spec to remain
2278 case RESTORE_POINTERS:
2279 /* Accept message by clearing ACK */
2280 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2281 /* Enable reselect interrupts */
2282 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
2284 case EXTENDED_MESSAGE:
2286 * Extended messages are sent in the following format :
2288 * 0 EXTENDED_MESSAGE == 1
2289 * 1 length (includes one byte for code, doesn't
2290 * include first two bytes)
2292 * 3..length+1 arguments
2294 * Start the extended message buffer with the EXTENDED_MESSAGE
2295 * byte, since spi_print_msg() wants the whole thing.
2297 extended_msg[0] = EXTENDED_MESSAGE;
2298 /* Accept first byte by clearing ACK */
2299 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2301 dprintk(NDEBUG_EXTENDED, "scsi%d: receiving extended message\n", HOSTNO);
2304 data = extended_msg + 1;
2305 phase = PHASE_MSGIN;
2306 NCR5380_transfer_pio(instance, &phase, &len, &data);
2307 dprintk(NDEBUG_EXTENDED, "scsi%d: length=%d, code=0x%02x\n", HOSTNO,
2308 (int)extended_msg[1], (int)extended_msg[2]);
2310 if (!len && extended_msg[1] <=
2311 (sizeof (extended_msg) - 1)) {
2312 /* Accept third byte by clearing ACK */
2313 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2314 len = extended_msg[1] - 1;
2315 data = extended_msg + 3;
2316 phase = PHASE_MSGIN;
2318 NCR5380_transfer_pio(instance, &phase, &len, &data);
2319 dprintk(NDEBUG_EXTENDED, "scsi%d: message received, residual %d\n",
2322 switch (extended_msg[2]) {
2325 case EXTENDED_MODIFY_DATA_POINTER:
2326 case EXTENDED_EXTENDED_IDENTIFY:
2330 printk(KERN_NOTICE "scsi%d: error receiving "
2331 "extended message\n", HOSTNO);
2334 printk(KERN_NOTICE "scsi%d: extended message "
2335 "code %02x length %d is too long\n",
2336 HOSTNO, extended_msg[2], extended_msg[1]);
2339 /* Fall through to reject message */
2342 * If we get something weird that we aren't expecting,
2347 printk(KERN_DEBUG "scsi%d: rejecting message ", HOSTNO);
2348 spi_print_msg(extended_msg);
2350 } else if (tmp != EXTENDED_MESSAGE)
2351 printk(KERN_DEBUG "scsi%d: rejecting unknown "
2352 "message %02x from target %d, lun %d\n",
2353 HOSTNO, tmp, cmd->device->id, cmd->device->lun);
2355 printk(KERN_DEBUG "scsi%d: rejecting unknown "
2357 "code %02x, length %d from target %d, lun %d\n",
2358 HOSTNO, extended_msg[1], extended_msg[0],
2359 cmd->device->id, cmd->device->lun);
2362 msgout = MESSAGE_REJECT;
2363 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
2366 } /* switch (tmp) */
2371 hostdata->last_message = msgout;
2372 NCR5380_transfer_pio(instance, &phase, &len, &data);
2373 if (msgout == ABORT) {
2375 cmd_free_tag( cmd );
2377 hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
2379 hostdata->connected = NULL;
2380 cmd->result = DID_ERROR << 16;
2381 #ifdef NCR5380_STATS
2382 collect_stats(hostdata, cmd);
2384 cmd->scsi_done(cmd);
2385 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
2394 * XXX for performance reasons, on machines with a
2395 * PSEUDO-DMA architecture we should probably
2396 * use the dma transfer function.
2398 NCR5380_transfer_pio(instance, &phase, &len,
2404 NCR5380_transfer_pio(instance, &phase, &len, &data);
2405 cmd->SCp.Status = tmp;
2408 printk("scsi%d: unknown phase\n", HOSTNO);
2409 NCR5380_dprint(NDEBUG_ANY, instance);
2410 } /* switch(phase) */
2411 } /* if (tmp * SR_REQ) */
2416 * Function : void NCR5380_reselect (struct Scsi_Host *instance)
2418 * Purpose : does reselection, initializing the instance->connected
2419 * field to point to the struct scsi_cmnd for which the I_T_L or I_T_L_Q
2420 * nexus has been reestablished,
2422 * Inputs : instance - this instance of the NCR5380.
2426 /* it might eventually prove necessary to do a dma setup on
2427 reselection, but it doesn't seem to be needed now -- sam */
2429 static void NCR5380_reselect (struct Scsi_Host *instance)
2431 SETUP_HOSTDATA(instance);
2432 unsigned char target_mask;
2437 unsigned char msg[3];
2438 struct scsi_cmnd *tmp = NULL, *prev;
2439 /* unsigned long flags; */
2442 * Disable arbitration, etc. since the host adapter obviously
2443 * lost, and tell an interrupted NCR5380_select() to restart.
2446 NCR5380_write(MODE_REG, MR_BASE);
2447 hostdata->restart_select = 1;
2449 target_mask = NCR5380_read(CURRENT_SCSI_DATA_REG) & ~(hostdata->id_mask);
2451 dprintk(NDEBUG_RESELECTION, "scsi%d: reselect\n", HOSTNO);
2454 * At this point, we have detected that our SCSI ID is on the bus,
2455 * SEL is true and BSY was false for at least one bus settle delay
2458 * We must assert BSY ourselves, until the target drops the SEL
2462 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_BSY);
2464 while (NCR5380_read(STATUS_REG) & SR_SEL);
2465 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2468 * Wait for target to go into MSGIN.
2471 while (!(NCR5380_read(STATUS_REG) & SR_REQ));
2474 // acknowledge toggle to MSGIN
2475 NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(PHASE_MSGIN));
2477 // peek at the byte without really hitting the bus
2478 msg[0] = NCR5380_read(CURRENT_SCSI_DATA_REG);
2481 if (!(msg[0] & 0x80)) {
2482 printk(KERN_DEBUG "scsi%d: expecting IDENTIFY message, got ", HOSTNO);
2487 lun = (msg[0] & 0x07);
2490 * Find the command corresponding to the I_T_L or I_T_L_Q nexus we
2491 * just reestablished, and remove it from the disconnected queue.
2494 for (tmp = (struct scsi_cmnd *) hostdata->disconnected_queue, prev = NULL;
2495 tmp; prev = tmp, tmp = NEXT(tmp) ) {
2496 if ((target_mask == (1 << tmp->device->id)) && (lun == tmp->device->lun)
2498 && (tag == tmp->tag)
2502 REMOVE(prev, NEXT(prev), tmp, NEXT(tmp));
2503 SET_NEXT(prev, NEXT(tmp));
2505 REMOVE(-1, hostdata->disconnected_queue, tmp, NEXT(tmp));
2506 hostdata->disconnected_queue = NEXT(tmp);
2508 SET_NEXT(tmp, NULL);
2514 printk(KERN_WARNING "scsi%d: warning: target bitmask %02x lun %d "
2518 "not in disconnected_queue.\n",
2519 HOSTNO, target_mask, lun
2525 * Since we have an established nexus that we can't do anything
2526 * with, we must abort it.
2532 /* engage dma setup for the command we just saw */
2535 unsigned long count;
2537 if (!tmp->SCp.this_residual && tmp->SCp.buffers_residual) {
2538 count = tmp->SCp.buffer->length;
2539 d = SGADDR(tmp->SCp.buffer);
2541 count = tmp->SCp.this_residual;
2545 /* setup this command for dma if not already */
2546 if((count > SUN3_DMA_MINSIZE) && (sun3_dma_setup_done != tmp))
2548 sun3scsi_dma_setup(d, count, rq_data_dir(tmp->request));
2549 sun3_dma_setup_done = tmp;
2555 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ACK);
2556 /* Accept message by clearing ACK */
2557 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2560 /* If the phase is still MSGIN, the target wants to send some more
2561 * messages. In case it supports tagged queuing, this is probably a
2562 * SIMPLE_QUEUE_TAG for the I_T_L_Q nexus.
2565 if (phase == PHASE_MSGIN && setup_use_tagged_queuing) {
2566 /* Accept previous IDENTIFY message by clearing ACK */
2567 NCR5380_write( INITIATOR_COMMAND_REG, ICR_BASE );
2570 if (!NCR5380_transfer_pio(instance, &phase, &len, &data) &&
2571 msg[1] == SIMPLE_QUEUE_TAG)
2573 dprintk(NDEBUG_TAGS, "scsi%d: target mask %02x, lun %d sent tag %d at "
2574 "reselection\n", HOSTNO, target_mask, lun, tag);
2578 hostdata->connected = tmp;
2579 dprintk(NDEBUG_RESELECTION, "scsi%d: nexus established, target = %d, lun = %d, tag = %d\n",
2580 HOSTNO, tmp->device->id, tmp->device->lun, tmp->tag);
2585 * Function : int NCR5380_abort(struct scsi_cmnd *cmd)
2587 * Purpose : abort a command
2589 * Inputs : cmd - the struct scsi_cmnd to abort, code - code to set the
2590 * host byte of the result field to, if zero DID_ABORTED is
2593 * Returns : 0 - success, -1 on failure.
2595 * XXX - there is no way to abort the command that is currently
2596 * connected, you have to wait for it to complete. If this is
2597 * a problem, we could implement longjmp() / setjmp(), setjmp()
2598 * called where the loop started in NCR5380_main().
2601 static int NCR5380_abort(struct scsi_cmnd *cmd)
2603 struct Scsi_Host *instance = cmd->device->host;
2604 SETUP_HOSTDATA(instance);
2605 struct scsi_cmnd *tmp, **prev;
2606 unsigned long flags;
2608 printk(KERN_NOTICE "scsi%d: aborting command\n", HOSTNO);
2609 scsi_print_command(cmd);
2611 NCR5380_print_status (instance);
2613 local_irq_save(flags);
2615 dprintk(NDEBUG_ABORT, "scsi%d: abort called basr 0x%02x, sr 0x%02x\n", HOSTNO,
2616 NCR5380_read(BUS_AND_STATUS_REG),
2617 NCR5380_read(STATUS_REG));
2621 * Case 1 : If the command is the currently executing command,
2622 * we'll set the aborted flag and return control so that
2623 * information transfer routine can exit cleanly.
2626 if (hostdata->connected == cmd) {
2628 dprintk(NDEBUG_ABORT, "scsi%d: aborting connected command\n", HOSTNO);
2630 * We should perform BSY checking, and make sure we haven't slipped
2634 /* NCR5380_write(INITIATOR_COMMAND_REG, ICR_ASSERT_ATN); */
2636 * Since we can't change phases until we've completed the current
2637 * handshake, we have to source or sink a byte of data if the current
2638 * phase is not MSGOUT.
2642 * Return control to the executing NCR drive so we can clear the
2643 * aborted flag and get back into our main loop.
2646 if (do_abort(instance) == 0) {
2647 hostdata->aborted = 1;
2648 hostdata->connected = NULL;
2649 cmd->result = DID_ABORT << 16;
2651 cmd_free_tag( cmd );
2653 hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
2655 local_irq_restore(flags);
2656 cmd->scsi_done(cmd);
2659 /* local_irq_restore(flags); */
2660 printk("scsi%d: abort of connected command failed!\n", HOSTNO);
2667 * Case 2 : If the command hasn't been issued yet, we simply remove it
2668 * from the issue queue.
2670 for (prev = (struct scsi_cmnd **) &(hostdata->issue_queue),
2671 tmp = (struct scsi_cmnd *) hostdata->issue_queue;
2672 tmp; prev = NEXTADDR(tmp), tmp = NEXT(tmp))
2674 REMOVE(5, *prev, tmp, NEXT(tmp));
2675 (*prev) = NEXT(tmp);
2676 SET_NEXT(tmp, NULL);
2677 tmp->result = DID_ABORT << 16;
2678 local_irq_restore(flags);
2679 dprintk(NDEBUG_ABORT, "scsi%d: abort removed command from issue queue.\n",
2681 /* Tagged queuing note: no tag to free here, hasn't been assigned
2683 tmp->scsi_done(tmp);
2688 * Case 3 : If any commands are connected, we're going to fail the abort
2689 * and let the high level SCSI driver retry at a later time or
2692 * Timeouts, and therefore aborted commands, will be highly unlikely
2693 * and handling them cleanly in this situation would make the common
2694 * case of noresets less efficient, and would pollute our code. So,
2698 if (hostdata->connected) {
2699 local_irq_restore(flags);
2700 dprintk(NDEBUG_ABORT, "scsi%d: abort failed, command connected.\n", HOSTNO);
2705 * Case 4: If the command is currently disconnected from the bus, and
2706 * there are no connected commands, we reconnect the I_T_L or
2707 * I_T_L_Q nexus associated with it, go into message out, and send
2710 * This case is especially ugly. In order to reestablish the nexus, we
2711 * need to call NCR5380_select(). The easiest way to implement this
2712 * function was to abort if the bus was busy, and let the interrupt
2713 * handler triggered on the SEL for reselect take care of lost arbitrations
2714 * where necessary, meaning interrupts need to be enabled.
2716 * When interrupts are enabled, the queues may change - so we
2717 * can't remove it from the disconnected queue before selecting it
2718 * because that could cause a failure in hashing the nexus if that
2719 * device reselected.
2721 * Since the queues may change, we can't use the pointers from when we
2724 * So, we must first locate the command, and if NCR5380_select()
2725 * succeeds, then issue the abort, relocate the command and remove
2726 * it from the disconnected queue.
2729 for (tmp = (struct scsi_cmnd *) hostdata->disconnected_queue; tmp;
2732 local_irq_restore(flags);
2733 dprintk(NDEBUG_ABORT, "scsi%d: aborting disconnected command.\n", HOSTNO);
2735 if (NCR5380_select (instance, cmd, (int) cmd->tag))
2738 dprintk(NDEBUG_ABORT, "scsi%d: nexus reestablished.\n", HOSTNO);
2740 do_abort (instance);
2742 local_irq_save(flags);
2743 for (prev = (struct scsi_cmnd **) &(hostdata->disconnected_queue),
2744 tmp = (struct scsi_cmnd *) hostdata->disconnected_queue;
2745 tmp; prev = NEXTADDR(tmp), tmp = NEXT(tmp) )
2747 REMOVE(5, *prev, tmp, NEXT(tmp));
2749 SET_NEXT(tmp, NULL);
2750 tmp->result = DID_ABORT << 16;
2751 /* We must unlock the tag/LUN immediately here, since the
2752 * target goes to BUS FREE and doesn't send us another
2753 * message (COMMAND_COMPLETE or the like)
2756 cmd_free_tag( tmp );
2758 hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
2760 local_irq_restore(flags);
2761 tmp->scsi_done(tmp);
2767 * Case 5 : If we reached this point, the command was not found in any of
2770 * We probably reached this point because of an unlikely race condition
2771 * between the command completing successfully and the abortion code,
2772 * so we won't panic, but we will notify the user in case something really
2776 local_irq_restore(flags);
2777 printk(KERN_INFO "scsi%d: warning : SCSI command probably completed successfully before abortion\n", HOSTNO);
2784 * Function : int NCR5380_bus_reset(struct scsi_cmnd *cmd)
2786 * Purpose : reset the SCSI bus.
2788 * Returns : SUCCESS or FAILURE
2792 static int NCR5380_bus_reset(struct scsi_cmnd *cmd)
2794 SETUP_HOSTDATA(cmd->device->host);
2796 unsigned long flags;
2797 #if defined(RESET_RUN_DONE)
2798 struct scsi_cmnd *connected, *disconnected_queue;
2802 NCR5380_print_status (cmd->device->host);
2805 NCR5380_write( TARGET_COMMAND_REG,
2806 PHASE_SR_TO_TCR( NCR5380_read(STATUS_REG) ));
2808 NCR5380_write( INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_RST );
2810 /* reset NCR registers */
2811 NCR5380_write( INITIATOR_COMMAND_REG, ICR_BASE );
2812 NCR5380_write( MODE_REG, MR_BASE );
2813 NCR5380_write( TARGET_COMMAND_REG, 0 );
2814 NCR5380_write( SELECT_ENABLE_REG, 0 );
2815 /* ++roman: reset interrupt condition! otherwise no interrupts don't get
2816 * through anymore ... */
2817 (void)NCR5380_read( RESET_PARITY_INTERRUPT_REG );
2819 /* MSch 20140115 - looking at the generic NCR5380 driver, all of this
2821 * Catch-22: if we don't clear all queues, the SCSI driver lock will
2822 * not be released by atari_scsi_reset()!
2825 #if defined(RESET_RUN_DONE)
2826 /* XXX Should now be done by midlevel code, but it's broken XXX */
2827 /* XXX see below XXX */
2829 /* MSch: old-style reset: actually abort all command processing here */
2831 /* After the reset, there are no more connected or disconnected commands
2832 * and no busy units; to avoid problems with re-inserting the commands
2833 * into the issue_queue (via scsi_done()), the aborted commands are
2834 * remembered in local variables first.
2836 local_irq_save(flags);
2837 connected = (struct scsi_cmnd *)hostdata->connected;
2838 hostdata->connected = NULL;
2839 disconnected_queue = (struct scsi_cmnd *)hostdata->disconnected_queue;
2840 hostdata->disconnected_queue = NULL;
2844 for( i = 0; i < 8; ++i )
2845 hostdata->busy[i] = 0;
2847 hostdata->dma_len = 0;
2849 local_irq_restore(flags);
2851 /* In order to tell the mid-level code which commands were aborted,
2852 * set the command status to DID_RESET and call scsi_done() !!!
2853 * This ultimately aborts processing of these commands in the mid-level.
2856 if ((cmd = connected)) {
2857 dprintk(NDEBUG_ABORT, "scsi%d: reset aborted a connected command\n", H_NO(cmd));
2858 cmd->result = (cmd->result & 0xffff) | (DID_RESET << 16);
2859 cmd->scsi_done( cmd );
2862 for (i = 0; (cmd = disconnected_queue); ++i) {
2863 disconnected_queue = NEXT(cmd);
2864 SET_NEXT(cmd, NULL);
2865 cmd->result = (cmd->result & 0xffff) | (DID_RESET << 16);
2866 cmd->scsi_done( cmd );
2869 dprintk(NDEBUG_ABORT, "scsi: reset aborted %d disconnected command(s)\n", i);
2872 /* since all commands have been explicitly terminated, we need to tell
2873 * the midlevel code that the reset was SUCCESSFUL, and there is no
2874 * need to 'wake up' the commands by a request_sense
2879 /* MSch: new-style reset handling: let the mid-level do what it can */
2881 /* ++guenther: MID-LEVEL IS STILL BROKEN.
2882 * Mid-level is supposed to requeue all commands that were active on the
2883 * various low-level queues. In fact it does this, but that's not enough
2884 * because all these commands are subject to timeout. And if a timeout
2885 * happens for any removed command, *_abort() is called but all queues
2886 * are now empty. Abort then gives up the falcon lock, which is fatal,
2887 * since the mid-level will queue more commands and must have the lock
2888 * (it's all happening inside timer interrupt handler!!).
2889 * Even worse, abort will return NOT_RUNNING for all those commands not
2890 * on any queue, so they won't be retried ...
2892 * Conclusion: either scsi.c disables timeout for all resetted commands
2893 * immediately, or we lose! As of linux-2.0.20 it doesn't.
2896 /* After the reset, there are no more connected or disconnected commands
2897 * and no busy units; so clear the low-level status here to avoid
2898 * conflicts when the mid-level code tries to wake up the affected
2902 if (hostdata->issue_queue)
2903 dprintk(NDEBUG_ABORT, "scsi%d: reset aborted issued command(s)\n", H_NO(cmd));
2904 if (hostdata->connected)
2905 dprintk(NDEBUG_ABORT, "scsi%d: reset aborted a connected command\n", H_NO(cmd));
2906 if (hostdata->disconnected_queue)
2907 dprintk(NDEBUG_ABORT, "scsi%d: reset aborted disconnected command(s)\n", H_NO(cmd));
2909 local_irq_save(flags);
2910 hostdata->issue_queue = NULL;
2911 hostdata->connected = NULL;
2912 hostdata->disconnected_queue = NULL;
2916 for( i = 0; i < 8; ++i )
2917 hostdata->busy[i] = 0;
2919 hostdata->dma_len = 0;
2921 local_irq_restore(flags);
2923 /* we did no complete reset of all commands, so a wakeup is required */
2928 /* Local Variables: */