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()
160 ncmd->message = 0; in initialize_SCp()
165 struct scatterlist *s = ncmd->buffer; in advance_sg_buffer()
167 if (!ncmd->this_residual && s && !sg_is_last(s)) { in advance_sg_buffer()
168 ncmd->buffer = sg_next(s); in advance_sg_buffer()
169 ncmd->ptr = sg_virt(ncmd->buffer); in advance_sg_buffer()
170 ncmd->this_residual = ncmd->buffer->length; in advance_sg_buffer()
177 int resid = ncmd->this_residual; in set_resid_from_SCp()
178 struct scatterlist *s = ncmd->buffer; in set_resid_from_SCp()
183 resid += s->length; in set_resid_from_SCp()
189 * NCR5380_poll_politely2 - wait for two chip register values
197 * @wait: Time-out in jiffies, 0 if sleeping is not allowed
199 * Polls the chip in a reasonably efficient manner waiting for an
201 * (if possible). In irq contexts the time-out is arbitrarily limited.
204 * Returns 0 if either or both event(s) occurred otherwise -ETIMEDOUT.
210 unsigned long wait) in NCR5380_poll_politely2() argument
212 unsigned long n = hostdata->poll_loops; in NCR5380_poll_politely2()
213 unsigned long deadline = jiffies + wait; in NCR5380_poll_politely2()
221 } while (n--); in NCR5380_poll_politely2()
223 if (!wait) in NCR5380_poll_politely2()
224 return -ETIMEDOUT; in NCR5380_poll_politely2()
226 /* Repeatedly sleep for 1 ms until deadline */ in NCR5380_poll_politely2()
235 return -ETIMEDOUT; in NCR5380_poll_politely2()
261 {BASR_ACK, "ACK"},
268 {ICR_ASSERT_ACK, "ASSERT ACK"},
288 * NCR5380_print - print scsi bus signals
291 * Print the SCSI bus signals for debugging purposes
305 for (i = 0; signals[i].mask; ++i) in NCR5380_print()
309 for (i = 0; basrs[i].mask; ++i) in NCR5380_print()
313 for (i = 0; icrs[i].mask; ++i) in NCR5380_print()
317 for (i = 0; mrs[i].mask; ++i) in NCR5380_print()
337 * NCR5380_print_phase - show SCSI phase
340 * Print the current SCSI phase for debugging purposes
353 for (i = 0; (phases[i].value != PHASE_UNKNOWN) && in NCR5380_print_phase()
362 * NCR5380_info - report driver and host information
365 * For use as the host template info() handler.
372 return hostdata->info; in NCR5380_info()
376 * NCR5380_init - initialise an NCR5380
386 * Returns 0 for success
396 instance->max_lun = 7; in NCR5380_init()
398 hostdata->host = instance; in NCR5380_init()
399 hostdata->id_mask = 1 << instance->this_id; in NCR5380_init()
400 hostdata->id_higher_mask = 0; in NCR5380_init()
401 for (i = hostdata->id_mask; i <= 0x80; i <<= 1) in NCR5380_init()
402 if (i > hostdata->id_mask) in NCR5380_init()
403 hostdata->id_higher_mask |= i; in NCR5380_init()
404 for (i = 0; i < 8; ++i) in NCR5380_init()
405 hostdata->busy[i] = 0; in NCR5380_init()
406 hostdata->dma_len = 0; in NCR5380_init()
408 spin_lock_init(&hostdata->lock); in NCR5380_init()
409 hostdata->connected = NULL; in NCR5380_init()
410 hostdata->sensing = NULL; in NCR5380_init()
411 INIT_LIST_HEAD(&hostdata->autosense); in NCR5380_init()
412 INIT_LIST_HEAD(&hostdata->unissued); in NCR5380_init()
413 INIT_LIST_HEAD(&hostdata->disconnected); in NCR5380_init()
415 hostdata->flags = flags; in NCR5380_init()
417 INIT_WORK(&hostdata->main_task, NCR5380_main); in NCR5380_init()
418 hostdata->work_q = alloc_workqueue("ncr5380_%d", in NCR5380_init()
420 0, instance->host_no); in NCR5380_init()
421 if (!hostdata->work_q) in NCR5380_init()
422 return -ENOMEM; in NCR5380_init()
424 snprintf(hostdata->info, sizeof(hostdata->info), in NCR5380_init()
426 instance->hostt->name, instance->irq, hostdata->io_port, in NCR5380_init()
427 hostdata->base, instance->can_queue, instance->cmd_per_lun, in NCR5380_init()
428 instance->sg_tablesize, instance->this_id, in NCR5380_init()
429 hostdata->flags & FLAG_DMA_FIXUP ? "DMA_FIXUP " : "", in NCR5380_init()
430 hostdata->flags & FLAG_NO_PSEUDO_DMA ? "NO_PSEUDO_DMA " : "", in NCR5380_init()
431 hostdata->flags & FLAG_TOSHIBA_DELAY ? "TOSHIBA_DELAY " : ""); in NCR5380_init()
451 hostdata->poll_loops = NCR5380_REG_POLL_TIME * accesses_per_ms / 2; in NCR5380_init()
457 * NCR5380_maybe_reset_bus - Detect and correct bus wedge problems.
461 * the SCSI bus busy. Check for BUS FREE phase. If not, try to abort the
467 * Returns 0 if successful, otherwise -ENXIO.
475 for (pass = 1; (NCR5380_read(STATUS_REG) & SR_BSY) && pass <= 6; ++pass) { in NCR5380_maybe_reset_bus()
491 /* Wait after a reset; the SCSI standard calls for in NCR5380_maybe_reset_bus()
492 * 250ms, we wait 500ms to be on the safe side. in NCR5380_maybe_reset_bus()
493 * But some Toshiba CD-ROMs need ten times that. in NCR5380_maybe_reset_bus()
495 if (hostdata->flags & FLAG_TOSHIBA_DELAY) in NCR5380_maybe_reset_bus()
502 return -ENXIO; in NCR5380_maybe_reset_bus()
509 * NCR5380_exit - remove an NCR5380
519 cancel_work_sync(&hostdata->main_task); in NCR5380_exit()
520 destroy_workqueue(hostdata->work_q); in NCR5380_exit()
524 * complete_cmd - finish processing a command and return it to the SCSI ML
536 if (hostdata->sensing == cmd) { in complete_cmd()
539 scsi_eh_restore_cmnd(cmd, &hostdata->ses); in complete_cmd()
541 scsi_eh_restore_cmnd(cmd, &hostdata->ses); in complete_cmd()
544 hostdata->sensing = NULL; in complete_cmd()
551 * NCR5380_queue_command - queue a command
555 * cmd is added to the per-instance issue queue, with minor
568 switch (cmd->cmnd[0]) { in NCR5380_queue_command()
572 cmd->result = (DID_ERROR << 16); in NCR5380_queue_command()
578 cmd->result = 0; in NCR5380_queue_command()
580 spin_lock_irqsave(&hostdata->lock, flags); in NCR5380_queue_command()
583 spin_unlock_irqrestore(&hostdata->lock, flags); in NCR5380_queue_command()
595 if (cmd->cmnd[0] == REQUEST_SENSE) in NCR5380_queue_command()
596 list_add(&ncmd->list, &hostdata->unissued); in NCR5380_queue_command()
598 list_add_tail(&ncmd->list, &hostdata->unissued); in NCR5380_queue_command()
600 spin_unlock_irqrestore(&hostdata->lock, flags); in NCR5380_queue_command()
603 cmd, (cmd->cmnd[0] == REQUEST_SENSE) ? "head" : "tail"); in NCR5380_queue_command()
606 queue_work(hostdata->work_q, &hostdata->main_task); in NCR5380_queue_command()
615 if (list_empty(&hostdata->disconnected) && in maybe_release_dma_irq()
616 list_empty(&hostdata->unissued) && in maybe_release_dma_irq()
617 list_empty(&hostdata->autosense) && in maybe_release_dma_irq()
618 !hostdata->connected && in maybe_release_dma_irq()
619 !hostdata->selecting) { in maybe_release_dma_irq()
625 * dequeue_next_cmd - dequeue a command for processing
631 * Returns a command pointer if a command is found for a target that is
641 if (hostdata->sensing || list_empty(&hostdata->autosense)) { in dequeue_next_cmd()
642 list_for_each_entry(ncmd, &hostdata->unissued, list) { in dequeue_next_cmd()
645 cmd, scmd_id(cmd), hostdata->busy[scmd_id(cmd)], cmd->device->lun); in dequeue_next_cmd()
647 if (!(hostdata->busy[scmd_id(cmd)] & (1 << cmd->device->lun))) { in dequeue_next_cmd()
648 list_del(&ncmd->list); in dequeue_next_cmd()
656 ncmd = list_first_entry(&hostdata->autosense, in dequeue_next_cmd()
658 list_del(&ncmd->list); in dequeue_next_cmd()
662 scsi_eh_prep_cmnd(cmd, &hostdata->ses, NULL, 0, ~0); in dequeue_next_cmd()
663 hostdata->sensing = cmd; in dequeue_next_cmd()
674 if (hostdata->sensing == cmd) { in requeue_cmd()
675 scsi_eh_restore_cmnd(cmd, &hostdata->ses); in requeue_cmd()
676 list_add(&ncmd->list, &hostdata->autosense); in requeue_cmd()
677 hostdata->sensing = NULL; in requeue_cmd()
679 list_add(&ncmd->list, &hostdata->unissued); in requeue_cmd()
683 * NCR5380_main - NCR state machines
695 struct Scsi_Host *instance = hostdata->host; in NCR5380_main()
701 spin_lock_irq(&hostdata->lock); in NCR5380_main()
702 while (!hostdata->connected && !hostdata->selecting) { in NCR5380_main()
712 * On success, instance->hostdata->connected is set. in NCR5380_main()
718 * queueing, even on SCSI-II devices because the in NCR5380_main()
719 * contingent allegiance condition exists for the in NCR5380_main()
731 if (hostdata->connected && !hostdata->dma_len) { in NCR5380_main()
736 if (!hostdata->connected) { in NCR5380_main()
737 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask); in NCR5380_main()
740 spin_unlock_irq(&hostdata->lock); in NCR5380_main()
747 * NCR5380_dma_complete - finish DMA transfer
757 struct NCR5380_cmd *ncmd = NCR5380_to_ncmd(hostdata->connected); in NCR5380_dma_complete()
764 if (hostdata->read_overruns) { in NCR5380_dma_complete()
765 p = ncmd->phase; in NCR5380_dma_complete()
779 if (sun3scsi_dma_finish(hostdata->connected->sc_data_direction)) { in NCR5380_dma_complete()
780 pr_err("scsi%d: overrun in UDC counter -- not prepared to deal with this!\n", in NCR5380_dma_complete()
781 instance->host_no); in NCR5380_dma_complete()
787 pr_err("scsi%d: BASR %02x\n", instance->host_no, in NCR5380_dma_complete()
789 pr_err("scsi%d: bus stuck in data phase -- probably a single byte overrun!\n", in NCR5380_dma_complete()
790 instance->host_no); in NCR5380_dma_complete()
799 transferred = hostdata->dma_len - NCR5380_dma_residual(hostdata); in NCR5380_dma_complete()
800 hostdata->dma_len = 0; in NCR5380_dma_complete()
802 data = (unsigned char **)&ncmd->ptr; in NCR5380_dma_complete()
803 count = &ncmd->this_residual; in NCR5380_dma_complete()
805 *count -= transferred; in NCR5380_dma_complete()
807 if (hostdata->read_overruns) { in NCR5380_dma_complete()
811 cnt = toPIO = hostdata->read_overruns; in NCR5380_dma_complete()
816 (*count)--; in NCR5380_dma_complete()
817 cnt--; in NCR5380_dma_complete()
818 toPIO--; in NCR5380_dma_complete()
824 *count -= toPIO - cnt; in NCR5380_dma_complete()
831 * NCR5380_intr - generic NCR5380 irq handler
842 * - End of DMA (cleared by ending DMA Mode)
843 * - Parity error (cleared by reading RPIR)
844 * - Loss of BSY (cleared by reading RPIR)
846 * - Bus phase mismatch (non-maskable in DMA Mode, cleared by ending DMA Mode)
847 * - Bus reset (non-maskable)
849 * - Selection/reselection
857 * Checking for bus reset by reading RST is futile because of interrupt
858 * latency, but a bus reset will reset chip logic. Checking for parity error
872 spin_lock_irqsave(&hostdata->lock, flags); in NCR5380_intr()
884 * We ack IRQ after clearing Mode Register. Workarounds in NCR5380_intr()
885 * for End of DMA errata need to happen in DMA Mode. in NCR5380_intr()
890 if (hostdata->connected) { in NCR5380_intr()
892 queue_work(hostdata->work_q, &hostdata->main_task); in NCR5380_intr()
897 } else if ((NCR5380_read(CURRENT_SCSI_DATA_REG) & hostdata->id_mask) && in NCR5380_intr()
905 if (!hostdata->connected) { in NCR5380_intr()
907 queue_work(hostdata->work_q, &hostdata->main_task); in NCR5380_intr()
909 if (!hostdata->connected) in NCR5380_intr()
910 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask); in NCR5380_intr()
924 dregs->csr |= CSR_DMA_ENABLE; in NCR5380_intr()
931 dregs->csr |= CSR_DMA_ENABLE; in NCR5380_intr()
935 spin_unlock_irqrestore(&hostdata->lock, flags); in NCR5380_intr()
941 * NCR5380_select - attempt arbitration and selection for a given command
945 * This routine establishes an I_T_L nexus for a SCSI command. This involves
953 * with registers as they should have been on entry - ie
958 * hostdata->connected will be set to cmd.
962 * cmd->result host byte set to DID_BAD_TARGET.
966 __releases(&hostdata->lock) __acquires(&hostdata->lock) in NCR5380_select()
974 bool can_disconnect = instance->irq != NO_IRQ && in NCR5380_select()
975 cmd->cmnd[0] != REQUEST_SENSE && in NCR5380_select()
980 instance->this_id); in NCR5380_select()
984 * lock, so we have to watch out for EH. An exception handler may in NCR5380_select()
989 hostdata->selecting = cmd; in NCR5380_select()
1002 NCR5380_write(OUTPUT_DATA_REG, hostdata->id_mask); in NCR5380_select()
1005 /* The chip now waits for BUS FREE phase. Then after the 800 ns in NCR5380_select()
1009 spin_unlock_irq(&hostdata->lock); in NCR5380_select()
1013 spin_lock_irq(&hostdata->lock); in NCR5380_select()
1018 if (!hostdata->selecting) { in NCR5380_select()
1029 spin_unlock_irq(&hostdata->lock); in NCR5380_select()
1031 /* The SCSI-2 arbitration delay is 2.4 us */ in NCR5380_select()
1034 /* Check for lost arbitration */ in NCR5380_select()
1036 (NCR5380_read(CURRENT_SCSI_DATA_REG) & hostdata->id_higher_mask) || in NCR5380_select()
1040 spin_lock_irq(&hostdata->lock); in NCR5380_select()
1045 * IBM DPES-31080 Version S31Q works now in NCR5380_select()
1046 * Tnx to Thomas_Roesch@m2.maus.de for finding this! (Roman) in NCR5380_select()
1056 if (hostdata->flags & FLAG_TOSHIBA_DELAY) in NCR5380_select()
1061 spin_lock_irq(&hostdata->lock); in NCR5380_select()
1067 if (!hostdata->selecting) { in NCR5380_select()
1080 NCR5380_write(OUTPUT_DATA_REG, hostdata->id_mask | (1 << scmd_id(cmd))); in NCR5380_select()
1098 spin_unlock_irq(&hostdata->lock); in NCR5380_select()
1101 * The initiator shall then wait at least two deskew delays and release in NCR5380_select()
1104 udelay(1); /* wingel -- wait two bus deskew delay >2*45ns */ in NCR5380_select()
1111 * Something weird happens when we cease to drive BSY - looks in NCR5380_select()
1117 * unnecessary jump, making it work on my 386-33/Trantor T128, the in NCR5380_select()
1118 * tighter 'C' code breaks and requires this) solves the problem - in NCR5380_select()
1123 * wingel suggests that this could be due to failing to wait in NCR5380_select()
1132 * The SCSI specification calls for a 250 ms timeout for the actual in NCR5380_select()
1140 spin_lock_irq(&hostdata->lock); in NCR5380_select()
1148 spin_lock_irq(&hostdata->lock); in NCR5380_select()
1152 if (!hostdata->selecting) in NCR5380_select()
1155 cmd->result = DID_BAD_TARGET << 16; in NCR5380_select()
1166 * change the DATA BUS. -wingel in NCR5380_select()
1180 /* Wait for start of REQ/ACK handshake */ in NCR5380_select()
1183 spin_lock_irq(&hostdata->lock); in NCR5380_select()
1189 if (!hostdata->selecting) { in NCR5380_select()
1196 tmp[0] = IDENTIFY(can_disconnect, cmd->device->lun); in NCR5380_select()
1204 cmd->result = DID_ERROR << 16; in NCR5380_select()
1213 hostdata->connected = cmd; in NCR5380_select()
1214 hostdata->busy[cmd->device->id] |= 1 << cmd->device->lun; in NCR5380_select()
1217 dregs->csr |= CSR_INTR; in NCR5380_select()
1225 if (!hostdata->selecting) in NCR5380_select()
1227 hostdata->selecting = NULL; in NCR5380_select()
1237 * Inputs : instance - instance of driver, *phase - pointer to
1238 * what phase is expected, *count - pointer to number of
1239 * bytes to transfer, **data - pointer to data pointer,
1240 * can_sleep - 1 or 0 when sleeping is permitted or not, respectively.
1242 * Returns : -1 when different phase is entered without transferring
1248 * XXX Note : handling for bus free may be useful.
1253 * IS 100% reliable, and for the actual data transfer where speed
1254 * counts, we will always do a pseudo DMA or DMA transfer.
1276 * Wait for assertion of REQ, after which the phase bits will be in NCR5380_transfer_pio()
1286 /* Check for phase mismatch */ in NCR5380_transfer_pio()
1304 * after REQ has been asserted for the handshake but before in NCR5380_transfer_pio()
1305 * the initiator raises ACK. in NCR5380_transfer_pio()
1333 * We have several special cases to consider during REQ/ACK handshaking : in NCR5380_transfer_pio()
1335 * message. ATN must be dropped as ACK is dropped. in NCR5380_transfer_pio()
1338 * message. We must exit with ACK asserted, so that the calling in NCR5380_transfer_pio()
1339 * code may raise ATN before dropping ACK to reject the message. in NCR5380_transfer_pio()
1341 * 3. ACK and ATN are clear and the target may proceed as normal. in NCR5380_transfer_pio()
1349 } while (--c); in NCR5380_transfer_pio()
1357 * asserted or if ACK hasn't been released yet. The latter applies if in NCR5380_transfer_pio()
1368 return -1; in NCR5380_transfer_pio()
1372 * do_reset - issue a reset command
1378 * This clears the reset interrupt flag because there may be no handler for
1399 * do_abort - abort the currently established nexus by going to
1418 * Wait for the target to indicate a valid phase by asserting in do_abort()
1452 rc = -ENXIO; in do_abort()
1471 * Inputs : instance - instance of driver, *phase - pointer to
1472 * what phase is expected, *count - pointer to number of
1473 * bytes to transfer, **data - pointer to data pointer.
1475 * Returns : -1 when different phase is entered without transferring
1488 struct NCR5380_cmd *ncmd = NCR5380_to_ncmd(hostdata->connected); in NCR5380_transfer_dma()
1497 return -1; in NCR5380_transfer_dma()
1500 ncmd->phase = p; in NCR5380_transfer_dma()
1503 if (hostdata->read_overruns) in NCR5380_transfer_dma()
1504 c -= hostdata->read_overruns; in NCR5380_transfer_dma()
1505 else if (hostdata->flags & FLAG_DMA_FIXUP) in NCR5380_transfer_dma()
1506 --c; in NCR5380_transfer_dma()
1521 if (!(hostdata->flags & FLAG_LATE_DMA_SETUP)) { in NCR5380_transfer_dma()
1523 * starting the NCR. This is also the cleaner way for the TT. in NCR5380_transfer_dma()
1550 dregs->csr |= CSR_DMA_ENABLE; in NCR5380_transfer_dma()
1555 if (hostdata->flags & FLAG_LATE_DMA_SETUP) { in NCR5380_transfer_dma()
1569 /* For real DMA, result is the byte count. DMA interrupt is expected. */ in NCR5380_transfer_dma()
1571 hostdata->dma_len = result; in NCR5380_transfer_dma()
1576 hostdata->dma_len = c; in NCR5380_transfer_dma()
1579 * A note regarding the DMA errata workarounds for early NMOS silicon. in NCR5380_transfer_dma()
1581 * For DMA sends, we want to wait until the last byte has been in NCR5380_transfer_dma()
1584 * conditions. For non-scatter-gather operations, we can wait until REQ in NCR5380_transfer_dma()
1585 * and ACK both go false, or until a phase mismatch occurs. Gather-sends in NCR5380_transfer_dma()
1590 * this signal does not exist. The workaround for this lack is a watchdog; in NCR5380_transfer_dma()
1591 * we bail out of the wait-loop after a modest amount of wait-time if in NCR5380_transfer_dma()
1593 * correct solution :-% in NCR5380_transfer_dma()
1598 * ACK, even if it has _already_ been notified by the DMA controller that in NCR5380_transfer_dma()
1600 * out of DMA mode, this already-acknowledged byte is lost. This is in NCR5380_transfer_dma()
1601 * not a problem for "one DMA transfer per READ command", because in NCR5380_transfer_dma()
1605 * However, in order to handle scatter-receive, we must work around the in NCR5380_transfer_dma()
1606 * problem. The chosen fix is to DMA fewer bytes, then check for the in NCR5380_transfer_dma()
1612 if ((hostdata->flags & FLAG_DMA_FIXUP) && in NCR5380_transfer_dma()
1616 * intended to with the pseudo-DMA receive function, wait for in NCR5380_transfer_dma()
1620 * After REQ is asserted, the NCR5380 asserts DRQ and ACK. in NCR5380_transfer_dma()
1621 * REQ is deasserted when ACK is asserted, and not reasserted in NCR5380_transfer_dma()
1622 * until ACK goes false. Since the NCR5380 won't lower ACK in NCR5380_transfer_dma()
1628 * If sending, wait for the last byte to be sent. If REQ is in NCR5380_transfer_dma()
1629 * being asserted for the byte we're interested, we'll ACK it in NCR5380_transfer_dma()
1639 --ncmd->this_residual; in NCR5380_transfer_dma()
1641 result = -1; in NCR5380_transfer_dma()
1642 scmd_printk(KERN_ERR, hostdata->connected, in NCR5380_transfer_dma()
1647 result = -1; in NCR5380_transfer_dma()
1648 scmd_printk(KERN_ERR, hostdata->connected, in NCR5380_transfer_dma()
1662 * instance->connected.
1664 * Inputs : instance, instance for which we are doing commands
1667 * modified if a command disconnects, *instance->connected will
1670 * XXX Note : we need to watch for bus free or a reset condition here
1675 __releases(&hostdata->lock) __acquires(&hostdata->lock) in NCR5380_information_transfer()
1687 dregs->csr |= CSR_INTR; in NCR5380_information_transfer()
1690 while ((cmd = hostdata->connected)) { in NCR5380_information_transfer()
1711 if (cmd->sc_data_direction == DMA_TO_DEVICE) in NCR5380_information_transfer()
1713 ncmd->ptr, count); in NCR5380_information_transfer()
1716 ncmd->ptr, count); in NCR5380_information_transfer()
1720 dregs->csr |= CSR_INTR; in NCR5380_information_transfer()
1744 cmd->result = DID_ERROR << 16; in NCR5380_information_transfer()
1746 hostdata->connected = NULL; in NCR5380_information_transfer()
1747 hostdata->busy[scmd_id(cmd)] &= ~(1 << cmd->device->lun); in NCR5380_information_transfer()
1753 * scatter-gather list, move onto the next one. in NCR5380_information_transfer()
1759 ncmd->this_residual, in NCR5380_information_transfer()
1760 sg_nents(ncmd->buffer)); in NCR5380_information_transfer()
1764 * PSEUDO-DMA for systems that are strictly PIO, in NCR5380_information_transfer()
1767 * For this to work, we need to know the transfersize in NCR5380_information_transfer()
1768 * ahead of time, since the pseudo-DMA code will sit in NCR5380_information_transfer()
1773 if (!cmd->device->borken) in NCR5380_information_transfer()
1779 &len, (unsigned char **)&ncmd->ptr)) { in NCR5380_information_transfer()
1783 * polled-IO. in NCR5380_information_transfer()
1787 cmd->device->borken = 1; in NCR5380_information_transfer()
1795 transfersize = min(ncmd->this_residual, in NCR5380_information_transfer()
1799 (unsigned char **)&ncmd->ptr, in NCR5380_information_transfer()
1801 ncmd->this_residual -= transfersize - len; in NCR5380_information_transfer()
1815 ncmd->message = tmp; in NCR5380_information_transfer()
1822 /* Accept message by clearing ACK */ in NCR5380_information_transfer()
1827 cmd, scmd_id(cmd), cmd->device->lun); in NCR5380_information_transfer()
1829 hostdata->connected = NULL; in NCR5380_information_transfer()
1830 hostdata->busy[scmd_id(cmd)] &= ~(1 << cmd->device->lun); in NCR5380_information_transfer()
1832 set_status_byte(cmd, ncmd->status); in NCR5380_information_transfer()
1836 if (cmd->cmnd[0] == REQUEST_SENSE) in NCR5380_information_transfer()
1839 if (ncmd->status == SAM_STAT_CHECK_CONDITION || in NCR5380_information_transfer()
1840 ncmd->status == SAM_STAT_COMMAND_TERMINATED) { in NCR5380_information_transfer()
1843 list_add_tail(&ncmd->list, in NCR5380_information_transfer()
1844 &hostdata->autosense); in NCR5380_information_transfer()
1857 /* Accept message by clearing ACK */ in NCR5380_information_transfer()
1859 switch (hostdata->last_message) { in NCR5380_information_transfer()
1863 cmd->device->simple_tags = 0; in NCR5380_information_transfer()
1864 hostdata->busy[cmd->device->id] |= (1 << (cmd->device->lun & 0xFF)); in NCR5380_information_transfer()
1871 /* Accept message by clearing ACK */ in NCR5380_information_transfer()
1873 hostdata->connected = NULL; in NCR5380_information_transfer()
1874 list_add(&ncmd->list, &hostdata->disconnected); in NCR5380_information_transfer()
1876 instance, "connected command %p for target %d lun %llu moved to disconnected queue\n", in NCR5380_information_transfer()
1877 cmd, scmd_id(cmd), cmd->device->lun); in NCR5380_information_transfer()
1886 dregs->csr |= CSR_DMA_ENABLE; in NCR5380_information_transfer()
1901 /* Accept message by clearing ACK */ in NCR5380_information_transfer()
1910 /* Accept first byte by clearing ACK */ in NCR5380_information_transfer()
1913 spin_unlock_irq(&hostdata->lock); in NCR5380_information_transfer()
1926 extended_msg[1] <= sizeof(extended_msg) - 2) { in NCR5380_information_transfer()
1927 /* Accept third byte by clearing ACK */ in NCR5380_information_transfer()
1929 len = extended_msg[1] - 1; in NCR5380_information_transfer()
1951 spin_lock_irq(&hostdata->lock); in NCR5380_information_transfer()
1952 if (!hostdata->connected) in NCR5380_information_transfer()
1979 hostdata->last_message = msgout; in NCR5380_information_transfer()
1982 hostdata->connected = NULL; in NCR5380_information_transfer()
1983 hostdata->busy[scmd_id(cmd)] &= ~(1 << cmd->device->lun); in NCR5380_information_transfer()
1984 cmd->result = DID_ERROR << 16; in NCR5380_information_transfer()
1991 len = cmd->cmd_len; in NCR5380_information_transfer()
1992 data = cmd->cmnd; in NCR5380_information_transfer()
1994 * XXX for performance reasons, on machines with a in NCR5380_information_transfer()
1995 * PSEUDO-DMA architecture we should probably in NCR5380_information_transfer()
2002 tmp = ncmd->status; in NCR5380_information_transfer()
2005 ncmd->status = tmp; in NCR5380_information_transfer()
2012 spin_unlock_irq(&hostdata->lock); in NCR5380_information_transfer()
2014 spin_lock_irq(&hostdata->lock); in NCR5380_information_transfer()
2022 * Purpose : does reselection, initializing the instance->connected
2023 * field to point to the scsi_cmnd for which the I_T_L or I_T_L_Q
2026 * Inputs : instance - this instance of the NCR5380.
2045 target_mask = NCR5380_read(CURRENT_SCSI_DATA_REG) & ~(hostdata->id_mask); in NCR5380_reselect()
2046 if (!target_mask || target_mask & (target_mask - 1)) { in NCR5380_reselect()
2054 * SEL is true and BSY was false for at least one bus settle delay in NCR5380_reselect()
2071 * Wait for target to go into MSGIN. in NCR5380_reselect()
2115 * We need to add code for SCSI-II to track which devices have in NCR5380_reselect()
2126 list_for_each_entry(ncmd, &hostdata->disconnected, list) { in NCR5380_reselect()
2130 lun == (u8)cmd->device->lun) { in NCR5380_reselect()
2131 list_del(&ncmd->list); in NCR5380_reselect()
2141 int target = ffs(target_mask) - 1; in NCR5380_reselect()
2150 hostdata->busy[target] &= ~(1 << lun); in NCR5380_reselect()
2163 if (tmp->sc_data_direction == DMA_TO_DEVICE) in NCR5380_reselect()
2165 ncmd->ptr, count); in NCR5380_reselect()
2168 ncmd->ptr, count); in NCR5380_reselect()
2176 /* Accept message by clearing ACK */ in NCR5380_reselect()
2179 hostdata->connected = tmp; in NCR5380_reselect()
2181 scmd_id(tmp), tmp->device->lun); in NCR5380_reselect()
2185 * list_find_cmd - test for presence of a command in a linked list
2187 * @needle: command to search for
2202 * list_remove_cmd - remove a command from linked list
2213 list_del(&ncmd->list); in list_del_cmd()
2220 * NCR5380_abort - scsi host eh_abort_handler() method
2225 * to abort the command. Nonetheless, the low-level driver must forget about
2226 * the command because the mid-layer reclaims it and it may be re-issued.
2228 * The normal path taken by a command is as follows. For EH we trace this
2231 * unissued -> selecting -> [unissued -> selecting ->]... connected ->
2232 * [disconnected -> connected ->]...
2233 * [autosense -> connected ->] done
2240 * lacks sense data). The mid-layer may re-issue a command that is in error
2245 * to serialize their own execution and prevent their own re-entry.
2250 struct Scsi_Host *instance = cmd->device->host; in NCR5380_abort()
2255 spin_lock_irqsave(&hostdata->lock, flags); in NCR5380_abort()
2263 if (list_del_cmd(&hostdata->unissued, cmd)) { in NCR5380_abort()
2266 cmd->result = DID_ABORT << 16; in NCR5380_abort()
2271 if (hostdata->selecting == cmd) { in NCR5380_abort()
2274 hostdata->selecting = NULL; in NCR5380_abort()
2275 cmd->result = DID_ABORT << 16; in NCR5380_abort()
2280 if (list_del_cmd(&hostdata->disconnected, cmd)) { in NCR5380_abort()
2292 if (hostdata->connected == cmd) { in NCR5380_abort()
2294 hostdata->connected = NULL; in NCR5380_abort()
2295 hostdata->dma_len = 0; in NCR5380_abort()
2307 if (list_del_cmd(&hostdata->autosense, cmd)) { in NCR5380_abort()
2317 hostdata->busy[scmd_id(cmd)] &= ~(1 << cmd->device->lun); in NCR5380_abort()
2321 queue_work(hostdata->work_q, &hostdata->main_task); in NCR5380_abort()
2322 spin_unlock_irqrestore(&hostdata->lock, flags); in NCR5380_abort()
2340 * and no busy units; so clear the low-level status here to avoid in bus_reset_cleanup()
2341 * conflicts when the mid-level code tries to wake up the affected in bus_reset_cleanup()
2345 if (hostdata->selecting) { in bus_reset_cleanup()
2346 hostdata->selecting->result = DID_RESET << 16; in bus_reset_cleanup()
2347 complete_cmd(instance, hostdata->selecting); in bus_reset_cleanup()
2348 hostdata->selecting = NULL; in bus_reset_cleanup()
2351 list_for_each_entry(ncmd, &hostdata->disconnected, list) { in bus_reset_cleanup()
2357 INIT_LIST_HEAD(&hostdata->disconnected); in bus_reset_cleanup()
2359 list_for_each_entry(ncmd, &hostdata->autosense, list) { in bus_reset_cleanup()
2364 INIT_LIST_HEAD(&hostdata->autosense); in bus_reset_cleanup()
2366 if (hostdata->connected) { in bus_reset_cleanup()
2367 set_host_byte(hostdata->connected, DID_RESET); in bus_reset_cleanup()
2368 complete_cmd(instance, hostdata->connected); in bus_reset_cleanup()
2369 hostdata->connected = NULL; in bus_reset_cleanup()
2372 for (i = 0; i < 8; ++i) in bus_reset_cleanup()
2373 hostdata->busy[i] = 0; in bus_reset_cleanup()
2374 hostdata->dma_len = 0; in bus_reset_cleanup()
2376 queue_work(hostdata->work_q, &hostdata->main_task); in bus_reset_cleanup()
2380 * NCR5380_host_reset - reset the SCSI host
2388 struct Scsi_Host *instance = cmd->device->host; in NCR5380_host_reset()
2393 spin_lock_irqsave(&hostdata->lock, flags); in NCR5380_host_reset()
2401 list_for_each_entry(ncmd, &hostdata->unissued, list) { in NCR5380_host_reset()
2404 scmd->result = DID_RESET << 16; in NCR5380_host_reset()
2407 INIT_LIST_HEAD(&hostdata->unissued); in NCR5380_host_reset()
2412 spin_unlock_irqrestore(&hostdata->lock, flags); in NCR5380_host_reset()