Lines Matching +full:always +full:- +full:wait +full:- +full:for +full:- +full:ack
1 // SPDX-License-Identifier: GPL-2.0
4 * to implement 5380 SCSI drivers under Linux with a non-trantor
13 * +1 (303) 666-5836
15 * For more information, please consult
24 * 1+ (719) 578-3400
25 * 1+ (800) 334-5454
35 /* Adapted for the Sun 3 by Sam Creasey. */
42 * transfer - some PC's will use the I/O bus, 68K's must use
45 * As far as command queueing, two queues are maintained for
46 * each 5380 in the system - commands that haven't been issued yet,
51 * allowing multiple commands to propagate all the way to a SCSI-II device
57 * When used in a PIO or pseudo-dma mode, the NCR5380 is a braindead
58 * piece of hardware that requires you to sit in a loop polling for
63 * spend my time optimizing for the normal case.
68 * which is started from a workqueue for each NCR5380 host in the
78 * idle for too long, the system will try to sleep.
95 * This file a skeleton Linux SCSI driver for the NCR 5380 series
101 * NCR5380_read(register) - read from the specified register
103 * NCR5380_write(register, value) - write to the specific register
105 * NCR5380_implementation_fields - additional fields needed for this
110 * NCR5380_dma_xfer_len - determine size of DMA/PDMA transfer
111 * NCR5380_dma_send_setup - execute DMA/PDMA from memory to 5380
112 * NCR5380_dma_recv_setup - execute DMA/PDMA from 5380 to memory
113 * NCR5380_dma_residual - residual byte count
139 * initialize_SCp - init the scsi pointer field
150 ncmd->buffer = scsi_sglist(cmd); in initialize_SCp()
151 ncmd->ptr = sg_virt(ncmd->buffer); in initialize_SCp()
152 ncmd->this_residual = ncmd->buffer->length; in initialize_SCp()
154 ncmd->buffer = NULL; in initialize_SCp()
155 ncmd->ptr = NULL; in initialize_SCp()
156 ncmd->this_residual = 0; in initialize_SCp()
159 ncmd->status = 0; in initialize_SCp()
164 struct scatterlist *s = ncmd->buffer; in advance_sg_buffer()
166 if (!ncmd->this_residual && s && !sg_is_last(s)) { in advance_sg_buffer()
167 ncmd->buffer = sg_next(s); in advance_sg_buffer()
168 ncmd->ptr = sg_virt(ncmd->buffer); in advance_sg_buffer()
169 ncmd->this_residual = ncmd->buffer->length; in advance_sg_buffer()
176 int resid = ncmd->this_residual; in set_resid_from_SCp()
177 struct scatterlist *s = ncmd->buffer; in set_resid_from_SCp()
182 resid += s->length; in set_resid_from_SCp()
188 * NCR5380_poll_politely2 - wait for two chip register values
196 * @wait: Time-out in jiffies, 0 if sleeping is not allowed
198 * Polls the chip in a reasonably efficient manner waiting for an
200 * (if possible). In irq contexts the time-out is arbitrarily limited.
202 * Returns 0 if either or both event(s) occurred otherwise -ETIMEDOUT.
208 unsigned long wait) in NCR5380_poll_politely2() argument
210 unsigned long n = hostdata->poll_loops; in NCR5380_poll_politely2()
211 unsigned long deadline = jiffies + wait; in NCR5380_poll_politely2()
219 } while (n--); in NCR5380_poll_politely2()
221 if (!wait) in NCR5380_poll_politely2()
222 return -ETIMEDOUT; in NCR5380_poll_politely2()
224 /* Repeatedly sleep for 1 ms until deadline */ in NCR5380_poll_politely2()
233 return -ETIMEDOUT; in NCR5380_poll_politely2()
259 {BASR_ACK, "ACK"},
266 {ICR_ASSERT_ACK, "ASSERT ACK"},
286 * NCR5380_print - print scsi bus signals
289 * Print the SCSI bus signals for debugging purposes
303 for (i = 0; signals[i].mask; ++i) in NCR5380_print()
307 for (i = 0; basrs[i].mask; ++i) in NCR5380_print()
311 for (i = 0; icrs[i].mask; ++i) in NCR5380_print()
315 for (i = 0; mrs[i].mask; ++i) in NCR5380_print()
335 * NCR5380_print_phase - show SCSI phase
338 * Print the current SCSI phase for debugging purposes
351 for (i = 0; (phases[i].value != PHASE_UNKNOWN) && in NCR5380_print_phase()
360 * NCR5380_info - report driver and host information
363 * For use as the host template info() handler.
370 return hostdata->info; in NCR5380_info()
374 * NCR5380_init - initialise an NCR5380
384 * Returns 0 for success
394 instance->max_lun = 7; in NCR5380_init()
396 hostdata->host = instance; in NCR5380_init()
397 hostdata->id_mask = 1 << instance->this_id; in NCR5380_init()
398 hostdata->id_higher_mask = 0; in NCR5380_init()
399 for (i = hostdata->id_mask; i <= 0x80; i <<= 1) in NCR5380_init()
400 if (i > hostdata->id_mask) in NCR5380_init()
401 hostdata->id_higher_mask |= i; in NCR5380_init()
402 for (i = 0; i < 8; ++i) in NCR5380_init()
403 hostdata->busy[i] = 0; in NCR5380_init()
404 hostdata->dma_len = 0; in NCR5380_init()
406 spin_lock_init(&hostdata->lock); in NCR5380_init()
407 hostdata->connected = NULL; in NCR5380_init()
408 hostdata->sensing = NULL; in NCR5380_init()
409 INIT_LIST_HEAD(&hostdata->autosense); in NCR5380_init()
410 INIT_LIST_HEAD(&hostdata->unissued); in NCR5380_init()
411 INIT_LIST_HEAD(&hostdata->disconnected); in NCR5380_init()
413 hostdata->flags = flags; in NCR5380_init()
415 INIT_WORK(&hostdata->main_task, NCR5380_main); in NCR5380_init()
416 hostdata->work_q = alloc_workqueue("ncr5380_%d", in NCR5380_init()
418 0, instance->host_no); in NCR5380_init()
419 if (!hostdata->work_q) in NCR5380_init()
420 return -ENOMEM; in NCR5380_init()
422 snprintf(hostdata->info, sizeof(hostdata->info), in NCR5380_init()
424 instance->hostt->name, instance->irq, hostdata->io_port, in NCR5380_init()
425 hostdata->base, instance->can_queue, instance->cmd_per_lun, in NCR5380_init()
426 instance->sg_tablesize, instance->this_id, in NCR5380_init()
427 hostdata->flags & FLAG_DMA_FIXUP ? "DMA_FIXUP " : "", in NCR5380_init()
428 hostdata->flags & FLAG_NO_PSEUDO_DMA ? "NO_PSEUDO_DMA " : "", in NCR5380_init()
429 hostdata->flags & FLAG_TOSHIBA_DELAY ? "TOSHIBA_DELAY " : ""); in NCR5380_init()
449 hostdata->poll_loops = NCR5380_REG_POLL_TIME * accesses_per_ms / 2; in NCR5380_init()
455 * NCR5380_maybe_reset_bus - Detect and correct bus wedge problems.
459 * the SCSI bus busy. Check for BUS FREE phase. If not, try to abort the
465 * Returns 0 if successful, otherwise -ENXIO.
473 for (pass = 1; (NCR5380_read(STATUS_REG) & SR_BSY) && pass <= 6; ++pass) { in NCR5380_maybe_reset_bus()
489 /* Wait after a reset; the SCSI standard calls for in NCR5380_maybe_reset_bus()
490 * 250ms, we wait 500ms to be on the safe side. in NCR5380_maybe_reset_bus()
491 * But some Toshiba CD-ROMs need ten times that. in NCR5380_maybe_reset_bus()
493 if (hostdata->flags & FLAG_TOSHIBA_DELAY) in NCR5380_maybe_reset_bus()
500 return -ENXIO; in NCR5380_maybe_reset_bus()
507 * NCR5380_exit - remove an NCR5380
517 cancel_work_sync(&hostdata->main_task); in NCR5380_exit()
518 destroy_workqueue(hostdata->work_q); in NCR5380_exit()
522 * complete_cmd - finish processing a command and return it to the SCSI ML
534 if (hostdata->sensing == cmd) { in complete_cmd()
537 scsi_eh_restore_cmnd(cmd, &hostdata->ses); in complete_cmd()
539 scsi_eh_restore_cmnd(cmd, &hostdata->ses); in complete_cmd()
542 hostdata->sensing = NULL; in complete_cmd()
549 * NCR5380_queue_command - queue a command
553 * cmd is added to the per-instance issue queue, with minor
566 switch (cmd->cmnd[0]) { in NCR5380_queue_command()
570 cmd->result = (DID_ERROR << 16); in NCR5380_queue_command()
576 cmd->result = 0; in NCR5380_queue_command()
578 spin_lock_irqsave(&hostdata->lock, flags); in NCR5380_queue_command()
581 spin_unlock_irqrestore(&hostdata->lock, flags); in NCR5380_queue_command()
593 if (cmd->cmnd[0] == REQUEST_SENSE) in NCR5380_queue_command()
594 list_add(&ncmd->list, &hostdata->unissued); in NCR5380_queue_command()
596 list_add_tail(&ncmd->list, &hostdata->unissued); in NCR5380_queue_command()
598 spin_unlock_irqrestore(&hostdata->lock, flags); in NCR5380_queue_command()
601 cmd, (cmd->cmnd[0] == REQUEST_SENSE) ? "head" : "tail"); in NCR5380_queue_command()
604 queue_work(hostdata->work_q, &hostdata->main_task); in NCR5380_queue_command()
613 if (list_empty(&hostdata->disconnected) && in maybe_release_dma_irq()
614 list_empty(&hostdata->unissued) && in maybe_release_dma_irq()
615 list_empty(&hostdata->autosense) && in maybe_release_dma_irq()
616 !hostdata->connected && in maybe_release_dma_irq()
617 !hostdata->selecting) { in maybe_release_dma_irq()
623 * dequeue_next_cmd - dequeue a command for processing
629 * Returns a command pointer if a command is found for a target that is
639 if (hostdata->sensing || list_empty(&hostdata->autosense)) { in dequeue_next_cmd()
640 list_for_each_entry(ncmd, &hostdata->unissued, list) { in dequeue_next_cmd()
643 cmd, scmd_id(cmd), hostdata->busy[scmd_id(cmd)], cmd->device->lun); in dequeue_next_cmd()
645 if (!(hostdata->busy[scmd_id(cmd)] & (1 << cmd->device->lun))) { in dequeue_next_cmd()
646 list_del(&ncmd->list); in dequeue_next_cmd()
654 ncmd = list_first_entry(&hostdata->autosense, in dequeue_next_cmd()
656 list_del(&ncmd->list); in dequeue_next_cmd()
660 scsi_eh_prep_cmnd(cmd, &hostdata->ses, NULL, 0, ~0); in dequeue_next_cmd()
661 hostdata->sensing = cmd; in dequeue_next_cmd()
672 if (hostdata->sensing == cmd) { in requeue_cmd()
673 scsi_eh_restore_cmnd(cmd, &hostdata->ses); in requeue_cmd()
674 list_add(&ncmd->list, &hostdata->autosense); in requeue_cmd()
675 hostdata->sensing = NULL; in requeue_cmd()
677 list_add(&ncmd->list, &hostdata->unissued); in requeue_cmd()
681 * NCR5380_main - NCR state machines
693 struct Scsi_Host *instance = hostdata->host; in NCR5380_main()
699 spin_lock_irq(&hostdata->lock); in NCR5380_main()
700 while (!hostdata->connected && !hostdata->selecting) { in NCR5380_main()
710 * On success, instance->hostdata->connected is set. in NCR5380_main()
716 * queueing, even on SCSI-II devices because the in NCR5380_main()
717 * contingent allegiance condition exists for the in NCR5380_main()
729 if (hostdata->connected && !hostdata->dma_len) { in NCR5380_main()
734 if (!hostdata->connected) { in NCR5380_main()
735 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask); in NCR5380_main()
738 spin_unlock_irq(&hostdata->lock); in NCR5380_main()
745 * NCR5380_dma_complete - finish DMA transfer
755 struct NCR5380_cmd *ncmd = NCR5380_to_ncmd(hostdata->connected); in NCR5380_dma_complete()
762 if (hostdata->read_overruns) { in NCR5380_dma_complete()
763 p = ncmd->phase; in NCR5380_dma_complete()
777 if (sun3scsi_dma_finish(hostdata->connected->sc_data_direction)) { in NCR5380_dma_complete()
778 pr_err("scsi%d: overrun in UDC counter -- not prepared to deal with this!\n", in NCR5380_dma_complete()
779 instance->host_no); in NCR5380_dma_complete()
785 pr_err("scsi%d: BASR %02x\n", instance->host_no, in NCR5380_dma_complete()
787 pr_err("scsi%d: bus stuck in data phase -- probably a single byte overrun!\n", in NCR5380_dma_complete()
788 instance->host_no); in NCR5380_dma_complete()
797 transferred = hostdata->dma_len - NCR5380_dma_residual(hostdata); in NCR5380_dma_complete()
798 hostdata->dma_len = 0; in NCR5380_dma_complete()
800 data = (unsigned char **)&ncmd->ptr; in NCR5380_dma_complete()
801 count = &ncmd->this_residual; in NCR5380_dma_complete()
803 *count -= transferred; in NCR5380_dma_complete()
805 if (hostdata->read_overruns) { in NCR5380_dma_complete()
809 cnt = toPIO = hostdata->read_overruns; in NCR5380_dma_complete()
814 (*count)--; in NCR5380_dma_complete()
815 cnt--; in NCR5380_dma_complete()
816 toPIO--; in NCR5380_dma_complete()
822 *count -= toPIO - cnt; in NCR5380_dma_complete()
829 * NCR5380_intr - generic NCR5380 irq handler
840 * - End of DMA (cleared by ending DMA Mode)
841 * - Parity error (cleared by reading RPIR)
842 * - Loss of BSY (cleared by reading RPIR)
844 * - Bus phase mismatch (non-maskable in DMA Mode, cleared by ending DMA Mode)
845 * - Bus reset (non-maskable)
847 * - Selection/reselection
855 * Checking for bus reset by reading RST is futile because of interrupt
856 * latency, but a bus reset will reset chip logic. Checking for parity error
870 spin_lock_irqsave(&hostdata->lock, flags); in NCR5380_intr()
882 * We ack IRQ after clearing Mode Register. Workarounds in NCR5380_intr()
883 * for End of DMA errata need to happen in DMA Mode. in NCR5380_intr()
888 if (hostdata->connected) { in NCR5380_intr()
890 queue_work(hostdata->work_q, &hostdata->main_task); in NCR5380_intr()
895 } else if ((NCR5380_read(CURRENT_SCSI_DATA_REG) & hostdata->id_mask) && in NCR5380_intr()
903 if (!hostdata->connected) { in NCR5380_intr()
905 queue_work(hostdata->work_q, &hostdata->main_task); in NCR5380_intr()
907 if (!hostdata->connected) in NCR5380_intr()
908 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask); in NCR5380_intr()
922 dregs->csr |= CSR_DMA_ENABLE; in NCR5380_intr()
929 dregs->csr |= CSR_DMA_ENABLE; in NCR5380_intr()
933 spin_unlock_irqrestore(&hostdata->lock, flags); in NCR5380_intr()
939 * NCR5380_select - attempt arbitration and selection for a given command
943 * This routine establishes an I_T_L nexus for a SCSI command. This involves
951 * with registers as they should have been on entry - ie
956 * hostdata->connected will be set to cmd.
960 * cmd->result host byte set to DID_BAD_TARGET.
964 __releases(&hostdata->lock) __acquires(&hostdata->lock) in NCR5380_select()
972 bool can_disconnect = instance->irq != NO_IRQ && in NCR5380_select()
973 cmd->cmnd[0] != REQUEST_SENSE && in NCR5380_select()
978 instance->this_id); in NCR5380_select()
982 * lock, so we have to watch out for EH. An exception handler may in NCR5380_select()
987 hostdata->selecting = cmd; in NCR5380_select()
1000 NCR5380_write(OUTPUT_DATA_REG, hostdata->id_mask); in NCR5380_select()
1003 /* The chip now waits for BUS FREE phase. Then after the 800 ns in NCR5380_select()
1007 spin_unlock_irq(&hostdata->lock); in NCR5380_select()
1011 spin_lock_irq(&hostdata->lock); in NCR5380_select()
1016 if (!hostdata->selecting) { in NCR5380_select()
1027 spin_unlock_irq(&hostdata->lock); in NCR5380_select()
1029 /* The SCSI-2 arbitration delay is 2.4 us */ in NCR5380_select()
1032 /* Check for lost arbitration */ in NCR5380_select()
1034 (NCR5380_read(CURRENT_SCSI_DATA_REG) & hostdata->id_higher_mask) || in NCR5380_select()
1038 spin_lock_irq(&hostdata->lock); in NCR5380_select()
1043 * IBM DPES-31080 Version S31Q works now in NCR5380_select()
1044 * Tnx to Thomas_Roesch@m2.maus.de for finding this! (Roman) in NCR5380_select()
1054 if (hostdata->flags & FLAG_TOSHIBA_DELAY) in NCR5380_select()
1059 spin_lock_irq(&hostdata->lock); in NCR5380_select()
1065 if (!hostdata->selecting) { in NCR5380_select()
1078 NCR5380_write(OUTPUT_DATA_REG, hostdata->id_mask | (1 << scmd_id(cmd))); in NCR5380_select()
1096 spin_unlock_irq(&hostdata->lock); in NCR5380_select()
1099 * The initiator shall then wait at least two deskew delays and release in NCR5380_select()
1102 udelay(1); /* wingel -- wait two bus deskew delay >2*45ns */ in NCR5380_select()
1109 * Something weird happens when we cease to drive BSY - looks in NCR5380_select()
1115 * unnecessary jump, making it work on my 386-33/Trantor T128, the in NCR5380_select()
1116 * tighter 'C' code breaks and requires this) solves the problem - in NCR5380_select()
1121 * wingel suggests that this could be due to failing to wait in NCR5380_select()
1130 * The SCSI specification calls for a 250 ms timeout for the actual in NCR5380_select()
1138 spin_lock_irq(&hostdata->lock); in NCR5380_select()
1146 spin_lock_irq(&hostdata->lock); in NCR5380_select()
1150 if (!hostdata->selecting) in NCR5380_select()
1153 cmd->result = DID_BAD_TARGET << 16; in NCR5380_select()
1164 * change the DATA BUS. -wingel in NCR5380_select()
1178 /* Wait for start of REQ/ACK handshake */ in NCR5380_select()
1181 spin_lock_irq(&hostdata->lock); in NCR5380_select()
1187 if (!hostdata->selecting) { in NCR5380_select()
1194 tmp[0] = IDENTIFY(can_disconnect, cmd->device->lun); in NCR5380_select()
1202 cmd->result = DID_ERROR << 16; in NCR5380_select()
1211 hostdata->connected = cmd; in NCR5380_select()
1212 hostdata->busy[cmd->device->id] |= 1 << cmd->device->lun; in NCR5380_select()
1215 dregs->csr |= CSR_INTR; in NCR5380_select()
1223 if (!hostdata->selecting) in NCR5380_select()
1225 hostdata->selecting = NULL; in NCR5380_select()
1230 * NCR5380_transfer_pio() - transfers data in given phase using polled I/O
1242 * IS 100% reliable, and for the actual data transfer where speed
1243 * counts, we will always do a pseudo DMA or DMA transfer.
1265 * Wait for assertion of REQ, after which the phase bits will be in NCR5380_transfer_pio()
1275 /* Check for phase mismatch */ in NCR5380_transfer_pio()
1293 * after REQ has been asserted for the handshake but before in NCR5380_transfer_pio()
1294 * the initiator raises ACK. in NCR5380_transfer_pio()
1322 * We have several special cases to consider during REQ/ACK in NCR5380_transfer_pio()
1326 * the message. ATN must be dropped as ACK is dropped. in NCR5380_transfer_pio()
1329 * message. We must exit with ACK asserted, so that the calling in NCR5380_transfer_pio()
1330 * code may raise ATN before dropping ACK to reject the message. in NCR5380_transfer_pio()
1332 * 3. ACK and ATN are clear & the target may proceed as normal. in NCR5380_transfer_pio()
1340 } while (--c); in NCR5380_transfer_pio()
1348 * asserted or if ACK hasn't been released yet. The latter applies if in NCR5380_transfer_pio()
1358 * do_reset - issue a reset command
1364 * This clears the reset interrupt flag because there may be no handler for
1385 * do_abort - abort the currently established nexus by going to
1404 * Wait for the target to indicate a valid phase by asserting in do_abort()
1438 rc = -ENXIO; in do_abort()
1457 * Inputs : instance - instance of driver, *phase - pointer to
1458 * what phase is expected, *count - pointer to number of
1459 * bytes to transfer, **data - pointer to data pointer.
1461 * Returns : -1 when different phase is entered without transferring
1474 struct NCR5380_cmd *ncmd = NCR5380_to_ncmd(hostdata->connected); in NCR5380_transfer_dma()
1483 return -1; in NCR5380_transfer_dma()
1486 ncmd->phase = p; in NCR5380_transfer_dma()
1489 if (hostdata->read_overruns) in NCR5380_transfer_dma()
1490 c -= hostdata->read_overruns; in NCR5380_transfer_dma()
1491 else if (hostdata->flags & FLAG_DMA_FIXUP) in NCR5380_transfer_dma()
1492 --c; in NCR5380_transfer_dma()
1507 if (!(hostdata->flags & FLAG_LATE_DMA_SETUP)) { in NCR5380_transfer_dma()
1509 * starting the NCR. This is also the cleaner way for the TT. in NCR5380_transfer_dma()
1536 dregs->csr |= CSR_DMA_ENABLE; in NCR5380_transfer_dma()
1541 if (hostdata->flags & FLAG_LATE_DMA_SETUP) { in NCR5380_transfer_dma()
1555 /* For real DMA, result is the byte count. DMA interrupt is expected. */ in NCR5380_transfer_dma()
1557 hostdata->dma_len = result; in NCR5380_transfer_dma()
1562 hostdata->dma_len = c; in NCR5380_transfer_dma()
1565 * A note regarding the DMA errata workarounds for early NMOS silicon. in NCR5380_transfer_dma()
1567 * For DMA sends, we want to wait until the last byte has been in NCR5380_transfer_dma()
1570 * conditions. For non-scatter-gather operations, we can wait until REQ in NCR5380_transfer_dma()
1571 * and ACK both go false, or until a phase mismatch occurs. Gather-sends in NCR5380_transfer_dma()
1576 * older 538[01] this signal does not exist. The workaround for this in NCR5380_transfer_dma()
1577 * lack is a watchdog; we bail out of the wait-loop after a modest in NCR5380_transfer_dma()
1578 * amount of wait-time if the usual exit conditions are not met. in NCR5380_transfer_dma()
1579 * Not a terribly clean or correct solution :-% in NCR5380_transfer_dma()
1584 * and asserting ACK, even if it has _already_ been notified by the in NCR5380_transfer_dma()
1586 * NCR5380 is then taken out of DMA mode, this already-acknowledged in NCR5380_transfer_dma()
1589 * This is not a problem for "one DMA transfer per READ in NCR5380_transfer_dma()
1593 * to a clean halt). However, in order to handle scatter-receive, we in NCR5380_transfer_dma()
1595 * then check for the condition before taking the NCR5380 out of DMA in NCR5380_transfer_dma()
1600 if ((hostdata->flags & FLAG_DMA_FIXUP) && in NCR5380_transfer_dma()
1604 * intended to with the pseudo-DMA receive function, wait for in NCR5380_transfer_dma()
1608 * After REQ is asserted, the NCR5380 asserts DRQ and ACK. in NCR5380_transfer_dma()
1609 * REQ is deasserted when ACK is asserted, and not reasserted in NCR5380_transfer_dma()
1610 * until ACK goes false. Since the NCR5380 won't lower ACK in NCR5380_transfer_dma()
1616 * If sending, wait for the last byte to be sent. If REQ is in NCR5380_transfer_dma()
1617 * being asserted for the byte we're interested, we'll ACK it in NCR5380_transfer_dma()
1627 --ncmd->this_residual; in NCR5380_transfer_dma()
1629 result = -1; in NCR5380_transfer_dma()
1630 scmd_printk(KERN_ERR, hostdata->connected, in NCR5380_transfer_dma()
1635 result = -1; in NCR5380_transfer_dma()
1636 scmd_printk(KERN_ERR, hostdata->connected, in NCR5380_transfer_dma()
1650 * instance->connected.
1652 * Inputs : instance, instance for which we are doing commands
1655 * modified if a command disconnects, *instance->connected will
1660 __releases(&hostdata->lock) __acquires(&hostdata->lock) in NCR5380_information_transfer()
1672 dregs->csr |= CSR_INTR; in NCR5380_information_transfer()
1675 while ((cmd = hostdata->connected)) { in NCR5380_information_transfer()
1696 if (cmd->sc_data_direction == DMA_TO_DEVICE) in NCR5380_information_transfer()
1698 ncmd->ptr, count); in NCR5380_information_transfer()
1701 ncmd->ptr, count); in NCR5380_information_transfer()
1705 dregs->csr |= CSR_INTR; in NCR5380_information_transfer()
1729 cmd->result = DID_ERROR << 16; in NCR5380_information_transfer()
1731 hostdata->connected = NULL; in NCR5380_information_transfer()
1732 hostdata->busy[scmd_id(cmd)] &= ~(1 << cmd->device->lun); in NCR5380_information_transfer()
1738 * scatter-gather list, move onto the next one. in NCR5380_information_transfer()
1744 ncmd->this_residual, in NCR5380_information_transfer()
1745 sg_nents(ncmd->buffer)); in NCR5380_information_transfer()
1749 * PSEUDO-DMA for systems that are strictly PIO, in NCR5380_information_transfer()
1752 * For this to work, we need to know the transfersize in NCR5380_information_transfer()
1753 * ahead of time, since the pseudo-DMA code will sit in NCR5380_information_transfer()
1758 if (!cmd->device->borken) in NCR5380_information_transfer()
1764 &len, (unsigned char **)&ncmd->ptr)) { in NCR5380_information_transfer()
1768 * polled-IO. in NCR5380_information_transfer()
1772 cmd->device->borken = 1; in NCR5380_information_transfer()
1780 transfersize = min(ncmd->this_residual, in NCR5380_information_transfer()
1784 (unsigned char **)&ncmd->ptr, in NCR5380_information_transfer()
1786 ncmd->this_residual -= transfersize - len; in NCR5380_information_transfer()
1806 /* Accept message by clearing ACK */ in NCR5380_information_transfer()
1811 cmd, scmd_id(cmd), cmd->device->lun); in NCR5380_information_transfer()
1813 hostdata->connected = NULL; in NCR5380_information_transfer()
1814 hostdata->busy[scmd_id(cmd)] &= ~(1 << cmd->device->lun); in NCR5380_information_transfer()
1816 set_status_byte(cmd, ncmd->status); in NCR5380_information_transfer()
1820 if (cmd->cmnd[0] == REQUEST_SENSE) in NCR5380_information_transfer()
1823 if (ncmd->status == SAM_STAT_CHECK_CONDITION || in NCR5380_information_transfer()
1824 ncmd->status == SAM_STAT_COMMAND_TERMINATED) { in NCR5380_information_transfer()
1827 list_add_tail(&ncmd->list, in NCR5380_information_transfer()
1828 &hostdata->autosense); in NCR5380_information_transfer()
1841 /* Accept message by clearing ACK */ in NCR5380_information_transfer()
1843 switch (hostdata->last_message) { in NCR5380_information_transfer()
1847 cmd->device->simple_tags = 0; in NCR5380_information_transfer()
1848 hostdata->busy[cmd->device->id] |= (1 << (cmd->device->lun & 0xFF)); in NCR5380_information_transfer()
1855 /* Accept message by clearing ACK */ in NCR5380_information_transfer()
1857 hostdata->connected = NULL; in NCR5380_information_transfer()
1858 list_add(&ncmd->list, &hostdata->disconnected); in NCR5380_information_transfer()
1860 instance, "connected command %p for target %d lun %llu moved to disconnected queue\n", in NCR5380_information_transfer()
1861 cmd, scmd_id(cmd), cmd->device->lun); in NCR5380_information_transfer()
1870 dregs->csr |= CSR_DMA_ENABLE; in NCR5380_information_transfer()
1885 /* Accept message by clearing ACK */ in NCR5380_information_transfer()
1894 /* Accept first byte by clearing ACK */ in NCR5380_information_transfer()
1897 spin_unlock_irq(&hostdata->lock); in NCR5380_information_transfer()
1910 extended_msg[1] <= sizeof(extended_msg) - 2) { in NCR5380_information_transfer()
1911 /* Accept third byte by clearing ACK */ in NCR5380_information_transfer()
1913 len = extended_msg[1] - 1; in NCR5380_information_transfer()
1935 spin_lock_irq(&hostdata->lock); in NCR5380_information_transfer()
1936 if (!hostdata->connected) in NCR5380_information_transfer()
1963 hostdata->last_message = msgout; in NCR5380_information_transfer()
1966 hostdata->connected = NULL; in NCR5380_information_transfer()
1967 hostdata->busy[scmd_id(cmd)] &= ~(1 << cmd->device->lun); in NCR5380_information_transfer()
1968 cmd->result = DID_ERROR << 16; in NCR5380_information_transfer()
1975 len = cmd->cmd_len; in NCR5380_information_transfer()
1976 data = cmd->cmnd; in NCR5380_information_transfer()
1978 * XXX for performance reasons, on machines with a in NCR5380_information_transfer()
1979 * PSEUDO-DMA architecture we should probably in NCR5380_information_transfer()
1986 tmp = ncmd->status; in NCR5380_information_transfer()
1989 ncmd->status = tmp; in NCR5380_information_transfer()
1998 spin_unlock_irq(&hostdata->lock); in NCR5380_information_transfer()
2001 spin_lock_irq(&hostdata->lock); in NCR5380_information_transfer()
2003 if (err < 0 && hostdata->connected && in NCR5380_information_transfer()
2005 scmd_printk(KERN_ERR, hostdata->connected, in NCR5380_information_transfer()
2017 * Purpose : does reselection, initializing the instance->connected
2018 * field to point to the scsi_cmnd for which the I_T_L or I_T_L_Q
2021 * Inputs : instance - this instance of the NCR5380.
2040 target_mask = NCR5380_read(CURRENT_SCSI_DATA_REG) & ~(hostdata->id_mask); in NCR5380_reselect()
2041 if (!target_mask || target_mask & (target_mask - 1)) { in NCR5380_reselect()
2049 * SEL is true and BSY was false for at least one bus settle delay in NCR5380_reselect()
2066 * Wait for target to go into MSGIN. in NCR5380_reselect()
2110 * We need to add code for SCSI-II to track which devices have in NCR5380_reselect()
2121 list_for_each_entry(ncmd, &hostdata->disconnected, list) { in NCR5380_reselect()
2125 lun == (u8)cmd->device->lun) { in NCR5380_reselect()
2126 list_del(&ncmd->list); in NCR5380_reselect()
2136 int target = ffs(target_mask) - 1; in NCR5380_reselect()
2145 hostdata->busy[target] &= ~(1 << lun); in NCR5380_reselect()
2158 if (tmp->sc_data_direction == DMA_TO_DEVICE) in NCR5380_reselect()
2160 ncmd->ptr, count); in NCR5380_reselect()
2163 ncmd->ptr, count); in NCR5380_reselect()
2171 /* Accept message by clearing ACK */ in NCR5380_reselect()
2174 hostdata->connected = tmp; in NCR5380_reselect()
2176 scmd_id(tmp), tmp->device->lun); in NCR5380_reselect()
2180 * list_find_cmd - test for presence of a command in a linked list
2182 * @needle: command to search for
2197 * list_remove_cmd - remove a command from linked list
2208 list_del(&ncmd->list); in list_del_cmd()
2215 * NCR5380_abort - scsi host eh_abort_handler() method
2220 * to abort the command. Nonetheless, the low-level driver must forget about
2221 * the command because the mid-layer reclaims it and it may be re-issued.
2223 * The normal path taken by a command is as follows. For EH we trace this
2226 * unissued -> selecting -> [unissued -> selecting ->]... connected ->
2227 * [disconnected -> connected ->]...
2228 * [autosense -> connected ->] done
2235 * lacks sense data). The mid-layer may re-issue a command that is in error
2240 * to serialize their own execution and prevent their own re-entry.
2245 struct Scsi_Host *instance = cmd->device->host; in NCR5380_abort()
2250 spin_lock_irqsave(&hostdata->lock, flags); in NCR5380_abort()
2258 if (list_del_cmd(&hostdata->unissued, cmd)) { in NCR5380_abort()
2261 cmd->result = DID_ABORT << 16; in NCR5380_abort()
2266 if (hostdata->selecting == cmd) { in NCR5380_abort()
2269 hostdata->selecting = NULL; in NCR5380_abort()
2270 cmd->result = DID_ABORT << 16; in NCR5380_abort()
2275 if (list_del_cmd(&hostdata->disconnected, cmd)) { in NCR5380_abort()
2287 if (hostdata->connected == cmd) { in NCR5380_abort()
2289 hostdata->connected = NULL; in NCR5380_abort()
2290 hostdata->dma_len = 0; in NCR5380_abort()
2302 if (list_del_cmd(&hostdata->autosense, cmd)) { in NCR5380_abort()
2312 hostdata->busy[scmd_id(cmd)] &= ~(1 << cmd->device->lun); in NCR5380_abort()
2316 queue_work(hostdata->work_q, &hostdata->main_task); in NCR5380_abort()
2317 spin_unlock_irqrestore(&hostdata->lock, flags); in NCR5380_abort()
2335 * and no busy units; so clear the low-level status here to avoid in bus_reset_cleanup()
2336 * conflicts when the mid-level code tries to wake up the affected in bus_reset_cleanup()
2340 if (hostdata->selecting) { in bus_reset_cleanup()
2341 hostdata->selecting->result = DID_RESET << 16; in bus_reset_cleanup()
2342 complete_cmd(instance, hostdata->selecting); in bus_reset_cleanup()
2343 hostdata->selecting = NULL; in bus_reset_cleanup()
2346 list_for_each_entry(ncmd, &hostdata->disconnected, list) { in bus_reset_cleanup()
2352 INIT_LIST_HEAD(&hostdata->disconnected); in bus_reset_cleanup()
2354 list_for_each_entry(ncmd, &hostdata->autosense, list) { in bus_reset_cleanup()
2359 INIT_LIST_HEAD(&hostdata->autosense); in bus_reset_cleanup()
2361 if (hostdata->connected) { in bus_reset_cleanup()
2362 set_host_byte(hostdata->connected, DID_RESET); in bus_reset_cleanup()
2363 complete_cmd(instance, hostdata->connected); in bus_reset_cleanup()
2364 hostdata->connected = NULL; in bus_reset_cleanup()
2367 for (i = 0; i < 8; ++i) in bus_reset_cleanup()
2368 hostdata->busy[i] = 0; in bus_reset_cleanup()
2369 hostdata->dma_len = 0; in bus_reset_cleanup()
2371 queue_work(hostdata->work_q, &hostdata->main_task); in bus_reset_cleanup()
2375 * NCR5380_host_reset - reset the SCSI host
2383 struct Scsi_Host *instance = cmd->device->host; in NCR5380_host_reset()
2388 spin_lock_irqsave(&hostdata->lock, flags); in NCR5380_host_reset()
2396 list_for_each_entry(ncmd, &hostdata->unissued, list) { in NCR5380_host_reset()
2399 scmd->result = DID_RESET << 16; in NCR5380_host_reset()
2402 INIT_LIST_HEAD(&hostdata->unissued); in NCR5380_host_reset()
2407 spin_unlock_irqrestore(&hostdata->lock, flags); in NCR5380_host_reset()