1 /* $NetBSD: ncr5380.c,v 1.64 2009/07/19 05:43:22 tsutsui Exp $ */
4 * Copyright (c) 1995 Leo Weppelman.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include <sys/cdefs.h>
29 __KERNEL_RCSID(0, "$NetBSD: ncr5380.c,v 1.64 2009/07/19 05:43:22 tsutsui Exp $");
32 * Bit mask of targets you want debugging to be shown
34 u_char dbg_target_mask
= 0x7f;
37 * Set bit for target when parity checking must be disabled.
38 * My (LWP) Maxtor 7245S seems to generate parity errors on about 50%
39 * of all transfers while the data is correct!?
41 u_char ncr5380_no_parchk
= 0xff;
46 * Bit masks of targets that accept linked commands, and those
47 * that we've already checked out. Some devices will report
48 * that they support linked commands when they have problems with
49 * them. By default, don't try them on any devices. Allow an
52 #ifdef TRY_SCSI_LINKED_COMMANDS
53 u_char ncr_test_link
= ((~TRY_SCSI_LINKED_COMMANDS
) & 0x7f);
55 u_char ncr_test_link
= 0x7f;
57 u_char ncr_will_link
= 0x00;
59 #endif /* AUTO_SENSE */
62 * This is the default sense-command we send.
64 static u_char sense_cmd
[] = {
65 SCSI_REQUEST_SENSE
, 0, 0, 0, sizeof(struct scsi_sense_data
), 0
69 * True if the main co-routine is running
71 static volatile int main_running
= 0;
74 * Mask of targets selected
78 static void ncr5380_minphys(struct buf
*bp
);
79 static void ncr5380_scsi_request(struct scsipi_channel
*,
80 scsipi_adapter_req_t
, void *);
81 static void ncr5380_show_scsi_cmd(struct scsipi_xfer
*xs
);
83 static SC_REQ req_queue
[NREQ
];
84 static SC_REQ
*free_head
= NULL
; /* Free request structures */
92 * Wait for request-line to become active. When it doesn't return 0.
93 * Otherwise return != 0.
94 * The timeouts in the 'wait_req_*' functions are arbitrary and rather
95 * large. In 99% of the invocations nearly no timeout is needed but in
96 * some cases (especially when using my tapedrive, a Tandberg 3600) the
97 * device is busy internally and the first SCSI-phase will be delayed.
99 extern inline int wait_req_true(void)
101 int timeout
= 250000;
103 while (!(GET_5380_REG(NCR5380_IDSTAT
) & SC_S_REQ
) && --timeout
)
105 return (GET_5380_REG(NCR5380_IDSTAT
) & SC_S_REQ
);
109 * Wait for request-line to become inactive. When it doesn't return 0.
110 * Otherwise return != 0.
112 extern inline int wait_req_false(void)
114 int timeout
= 250000;
116 while ((GET_5380_REG(NCR5380_IDSTAT
) & SC_S_REQ
) && --timeout
)
118 return (!(GET_5380_REG(NCR5380_IDSTAT
) & SC_S_REQ
));
121 extern inline void ack_message(void)
123 SET_5380_REG(NCR5380_ICOM
, 0);
126 extern inline void nack_message(SC_REQ
*reqp
, u_char msg
)
128 SET_5380_REG(NCR5380_ICOM
, SC_A_ATN
);
132 extern inline void finish_req(SC_REQ
*reqp
)
135 struct scsipi_xfer
*xs
= reqp
->xs
;
139 * If we bounced, free the bounce buffer
141 if (reqp
->dr_flag
& DRIVER_BOUNCING
)
142 free_bounceb(reqp
->bounceb
);
143 #endif /* REAL_DMA */
145 if (dbg_target_mask
& (1 << reqp
->targ_id
))
146 show_request(reqp
, "DONE");
149 if ((dbg_target_mask
& (1 << reqp
->targ_id
)) && (reqp
->xs
->error
!= 0))
150 show_request(reqp
, "ERR_RET");
153 * Return request to free-q
156 reqp
->next
= free_head
;
160 if (!(reqp
->dr_flag
& DRIVER_LINKCHK
))
165 * Auto config stuff....
167 void ncr_attach(struct device
*, struct device
*, void *);
168 int ncr_match(struct device
*, struct cfdata
*, void *);
171 * Tricks to make driver-name configurable
173 #define CFNAME(n) __CONCAT(n,_cd)
174 #define CANAME(n) __CONCAT(n,_ca)
175 #define CFSTRING(n) __STRING(n)
176 #define CFDRNAME(n) n
178 CFATTACH_DECL(CFDRNAME(DRNAME
), sizeof(struct ncr_softc
),
179 ncr_match
, ncr_attach
, NULL
, NULL
);
181 extern struct cfdriver
CFNAME(DRNAME
);
184 ncr_match(struct device
*pdp
, struct cfdata
*cfp
, void *auxp
)
186 return (machine_match(pdp
, cfp
, auxp
, &CFNAME(DRNAME
)));
190 ncr_attach(struct device
*pdp
, struct device
*dp
, void *auxp
)
192 struct ncr_softc
*sc
;
195 sc
= (struct ncr_softc
*)dp
;
197 sc
->sc_adapter
.adapt_dev
= &sc
->sc_dev
;
198 sc
->sc_adapter
.adapt_openings
= 7;
199 sc
->sc_adapter
.adapt_max_periph
= 1;
200 sc
->sc_adapter
.adapt_ioctl
= NULL
;
201 sc
->sc_adapter
.adapt_minphys
= ncr5380_minphys
;
202 sc
->sc_adapter
.adapt_request
= ncr5380_scsi_request
;
204 sc
->sc_channel
.chan_adapter
= &sc
->sc_adapter
;
205 sc
->sc_channel
.chan_bustype
= &scsi_bustype
;
206 sc
->sc_channel
.chan_channel
= 0;
207 sc
->sc_channel
.chan_ntargets
= 8;
208 sc
->sc_channel
.chan_nluns
= 8;
209 sc
->sc_channel
.chan_id
= 7;
218 * Initialize machine-type specific things...
224 * Initialize request queue freelist.
226 for (i
= 0; i
< NREQ
; i
++) {
227 req_queue
[i
].next
= free_head
;
228 free_head
= &req_queue
[i
];
232 * Initialize the host adapter
236 SET_5380_REG(NCR5380_ICOM
, 0);
237 SET_5380_REG(NCR5380_MODE
, IMODE_BASE
);
238 SET_5380_REG(NCR5380_TCOM
, 0);
239 SET_5380_REG(NCR5380_IDSTAT
, 0);
243 * attach all scsi units on us
245 config_found(dp
, &sc
->sc_channel
, scsiprint
);
249 * End of auto config stuff....
253 * Carry out a request from the high level driver.
256 ncr5380_scsi_request(struct scsipi_channel
*chan
, scsipi_adapter_req_t req
, void *arg
)
258 struct scsipi_xfer
*xs
;
259 struct scsipi_periph
*periph
;
260 struct ncr_softc
*sc
= (void *)chan
->chan_adapter
->adapt_dev
;
262 SC_REQ
*reqp
, *link
, *tmp
;
266 case ADAPTER_REQ_RUN_XFER
:
268 periph
= xs
->xs_periph
;
271 * We do not queue RESET commands
273 flags
= xs
->xs_control
;
274 if (flags
& XS_CTL_RESET
) {
275 scsi_reset_verbose(sc
, "Got reset-command");
281 * Get a request block
284 if ((reqp
= free_head
) == 0) {
285 xs
->error
= XS_RESOURCE_SHORTAGE
;
290 free_head
= reqp
->next
;
295 * Initialize our private fields
297 reqp
->dr_flag
= (flags
& XS_CTL_POLL
) ? DRIVER_NOINT
: 0;
298 reqp
->phase
= NR_PHASE
;
299 reqp
->msgout
= MSG_NOOP
;
300 reqp
->status
= SCSGOOD
;
301 reqp
->message
= 0xff;
304 reqp
->targ_id
= xs
->xs_periph
->periph_target
;
305 reqp
->targ_lun
= xs
->xs_periph
->periph_lun
;
306 reqp
->xdata_ptr
= (u_char
*)xs
->data
;
307 reqp
->xdata_len
= xs
->datalen
;
308 memcpy(&reqp
->xcmd
, xs
->cmd
, xs
->cmdlen
);
309 reqp
->xcmd_len
= xs
->cmdlen
;
310 reqp
->xcmd
.bytes
[0] |= reqp
->targ_lun
<< 5;
314 * Check if DMA can be used on this request
316 if (scsi_dmaok(reqp
))
317 reqp
->dr_flag
|= DRIVER_DMAOK
;
318 #endif /* REAL_DMA */
321 * Insert the command into the issue queue. Note that
322 * 'REQUEST SENSE' commands are inserted at the head of the
323 * queue since any command will clear the existing contingent
324 * allegience condition and the sense data is only valid while
325 * the condition exists. When possible, link the command to a
326 * previous command to the same target. This is not very
327 * sensible when AUTO_SENSE is not defined! Interrupts are
328 * disabled while we are fiddling with the issue-queue.
332 if ((issue_q
== NULL
) ||
333 (reqp
->xcmd
.opcode
== SCSI_REQUEST_SENSE
)) {
334 reqp
->next
= issue_q
;
340 if (!link
&& (tmp
->targ_id
== reqp
->targ_id
) && !tmp
->link
)
342 } while (tmp
->next
&& (tmp
= tmp
->next
));
345 if (link
&& (ncr_will_link
& (1<<reqp
->targ_id
))) {
347 link
->xcmd
.bytes
[link
->xs
->cmdlen
-2] |= 1;
353 * If we haven't already, check the target for link support.
354 * Do this by prefixing the current command with a dummy
355 * Request_Sense command, link the dummy to the current
356 * command, and insert the dummy command at the head of the
357 * issue queue. Set the DRIVER_LINKCHK flag so that we'll
358 * ignore the results of the dummy command, since we only
359 * care about whether it was accepted or not.
361 if (!link
&& !(ncr_test_link
& (1<<reqp
->targ_id
)) &&
362 (tmp
= free_head
) && !(reqp
->dr_flag
& DRIVER_NOINT
)) {
363 free_head
= tmp
->next
;
364 tmp
->dr_flag
= (reqp
->dr_flag
& ~DRIVER_DMAOK
) | DRIVER_LINKCHK
;
365 tmp
->phase
= NR_PHASE
;
366 tmp
->msgout
= MSG_NOOP
;
367 tmp
->status
= SCSGOOD
;
369 tmp
->targ_id
= reqp
->targ_id
;
370 tmp
->targ_lun
= reqp
->targ_lun
;
371 memcpy(&tmp
->xcmd
, sense_cmd
, sizeof(sense_cmd
));
372 tmp
->xcmd_len
= sizeof(sense_cmd
);
373 tmp
->xdata_ptr
= (u_char
*)&tmp
->xs
->sense
.scsi_sense
;
374 tmp
->xdata_len
= sizeof(tmp
->xs
->sense
.scsi_sense
);
375 ncr_test_link
|= 1<<tmp
->targ_id
;
377 tmp
->xcmd
.bytes
[sizeof(sense_cmd
)-2] |= 1;
381 if (dbg_target_mask
& (1 << tmp
->targ_id
))
382 show_request(tmp
, "LINKCHK");
389 if (dbg_target_mask
& (1 << reqp
->targ_id
))
391 (reqp
->xcmd
.opcode
== SCSI_REQUEST_SENSE
) ?
398 case ADAPTER_REQ_GROW_RESOURCES
:
399 /* XXX Not supported. */
402 case ADAPTER_REQ_SET_XFER_MODE
:
403 /* XXX Not supported. */
409 ncr5380_minphys(struct buf
*bp
)
411 if (bp
->b_bcount
> MIN_PHYS
)
412 bp
->b_bcount
= MIN_PHYS
;
418 ncr5380_show_scsi_cmd(struct scsipi_xfer
*xs
)
420 u_char
*b
= (u_char
*) xs
->cmd
;
423 scsipi_printaddr(xs
->xs_periph
);
424 if (!(xs
->xs_control
& XS_CTL_RESET
)) {
425 while (i
< xs
->cmdlen
) {
439 * The body of the driver.
442 scsi_main(struct ncr_softc
*sc
)
449 * While running in the driver SCSI-interrupts are disabled.
459 * Check if it is fair keep any exclusive access to DMA
460 * claimed. If not, stop queueing new jobs so the discon_q
461 * will be eventually drained and DMA can be given up.
463 if (!fair_to_keep_dma())
467 * Search through the issue-queue for a command
468 * destined for a target that isn't busy.
471 for (req
=issue_q
; req
!= NULL
; prev
= req
, req
= req
->next
) {
472 if (!(busy
& (1 << req
->targ_id
))) {
474 * Found one, remove it from the issue queue
478 else prev
->next
= req
->next
;
485 * When a request has just ended, we get here before an other
486 * device detects that the bus is free and that it can
487 * reconnect. The problem is that when this happens, we always
488 * baffle the device because our (initiator) id is higher. This
489 * can cause a sort of starvation on slow devices. So we check
490 * for a pending reselection here.
491 * Note that 'connected' will be non-null if the reselection
494 if ((GET_5380_REG(NCR5380_IDSTAT
) & (SC_S_SEL
|SC_S_IO
))
495 == (SC_S_SEL
|SC_S_IO
)){
508 * The host is not connected and there is no request
517 * Re-enable interrupts before handling the request.
522 if (dbg_target_mask
& (1 << req
->targ_id
))
523 show_request(req
, "TARGET");
526 * We found a request. Try to connect to the target. If the
527 * initiator fails arbitration, the command is put back in the
530 if (scsi_select(req
, 0)) {
536 if (dbg_target_mask
& (1 << req
->targ_id
))
537 ncr_tprint(req
, "Select failed\n");
545 * If the host is currently connected but a 'real-DMA' transfer
546 * is in progress, the 'end-of-DMA' interrupt restarts main.
550 if (connected
&& (connected
->dr_flag
& DRIVER_IN_DMA
)) {
557 * Let the target guide us through the bus-phases
559 while (information_transfer(sc
) == -1)
563 /* NEVER TO REACH HERE */
564 show_phase(NULL
, 0); /* XXX: Get rid of not used warning */
565 panic("ncr5380-SCSI: not designed to come here");
569 * We enter here with interrupts disabled. We are about to exit main
570 * so interrupts should be re-enabled. Because interrupts are edge
571 * triggered, we could already have missed the interrupt. Therefore
572 * we check the IRQ-line here and re-enter when we really missed a
579 * If we're not currently connected, enable reselection
583 SET_5380_REG(NCR5380_IDSTAT
, SC_HOST_ID
);
585 if (scsi_ipending()) {
586 if ((itype
= check_intr(sc
)) != INTR_SPURIOUS
) {
591 if (itype
== INTR_RESEL
)
599 panic("Got DMA interrupt without DMA");
613 * The SCSI-DMA interrupt.
614 * This interrupt can only be triggered when running in non-polled DMA
615 * mode. When DMA is not active, it will be silently ignored, it is usually
616 * to late because the EOP interrupt of the controller happens just a tiny
617 * bit earlier. It might become usefull when scatter/gather is implemented,
618 * because in that case only part of the DATAIN/DATAOUT transfer is taken
619 * out of a single buffer.
622 ncr_dma_intr(struct ncr_softc
*sc
)
628 if ((reqp
= connected
) && (reqp
->dr_flag
& DRIVER_IN_DMA
)) {
630 if (!(dma_done
= dma_ready())) {
631 transfer_dma(reqp
, reqp
->phase
, 0);
637 #endif /* REAL_DMA */
640 * The SCSI-controller interrupt. This interrupt occurs on reselections and
641 * at the end of non-polled DMA-interrupts. It is assumed to be called from
642 * the machine-dependent hardware interrupt.
645 ncr_ctrl_intr(struct ncr_softc
*sc
)
650 return; /* scsi_main() should handle this one */
652 while (scsi_ipending()) {
654 if ((itype
= check_intr(sc
)) != INTR_SPURIOUS
) {
655 if (itype
== INTR_RESEL
)
660 if (!(dma_done
= dma_ready())) {
661 transfer_dma(connected
, connected
->phase
, 0);
667 panic("Got DMA interrupt without DMA");
675 PID("ncr_ctrl_intr1");
679 * Initiate a connection path between the host and the target. The function
680 * first goes into arbitration for the SCSI-bus. When this succeeds, the target
681 * is selected and an 'IDENTIFY' message is send.
682 * Returns -1 when the arbitration failed. Otherwise 0 is returned. When
683 * the target does not respond (to either selection or 'MESSAGE OUT') the
684 * 'done' function is executed.
685 * The result code given by the driver can be influenced by setting 'code'
686 * to a non-zero value. This is the case when 'select' is called by abort.
689 scsi_select(SC_REQ
*reqp
, int code
)
697 struct ncr_softc
*sc
;
699 sc
= (void*)reqp
->xs
->xs_periph
->periph_channel
->chan_adapter
->adapt_dev
;
700 DBG_SELPRINT ("Starting arbitration\n", 0);
706 * Prevent a race condition here. If a reslection interrupt occurred
707 * between the decision to pick a new request and the call to select,
708 * we abort the selection.
709 * Interrupts are lowered when the 5380 is setup to arbitrate for the
719 * Set phase bits to 0, otherwise the 5380 won't drive the bus during
722 SET_5380_REG(NCR5380_TCOM
, 0);
723 SET_5380_REG(NCR5380_ICOM
, 0);
726 * Arbitrate for the bus.
728 SET_5380_REG(NCR5380_DATA
, SC_HOST_ID
);
729 SET_5380_REG(NCR5380_MODE
, SC_ARBIT
);
734 while (!(GET_5380_REG(NCR5380_ICOM
) & SC_AIP
) && --cnt
)
737 if (!(GET_5380_REG(NCR5380_ICOM
) & SC_AIP
)) {
738 SET_5380_REG(NCR5380_MODE
, IMODE_BASE
);
739 SET_5380_REG(NCR5380_ICOM
, 0);
740 DBG_SELPRINT ("Arbitration lost, bus not free\n",0);
745 /* The arbitration delay is 2.2 usecs */
749 * Check the result of the arbitration. If we failed, return -1.
751 if (GET_5380_REG(NCR5380_ICOM
) & SC_LA
) {
752 SET_5380_REG(NCR5380_MODE
, IMODE_BASE
);
753 SET_5380_REG(NCR5380_ICOM
, 0);
759 * The spec requires that we should read the data register to
760 * check for higher id's and check the SC_LA again.
762 tmp
[0] = GET_5380_REG(NCR5380_DATA
);
763 if (tmp
[0] & ~((SC_HOST_ID
<< 1) - 1)) {
764 SET_5380_REG(NCR5380_MODE
, IMODE_BASE
);
765 SET_5380_REG(NCR5380_ICOM
, 0);
766 DBG_SELPRINT ("Arbitration lost, higher id present\n",0);
770 if (GET_5380_REG(NCR5380_ICOM
) & SC_LA
) {
771 SET_5380_REG(NCR5380_MODE
, IMODE_BASE
);
772 SET_5380_REG(NCR5380_ICOM
, 0);
773 DBG_SELPRINT ("Arbitration lost,deassert SC_ARBIT\n",0);
777 SET_5380_REG(NCR5380_ICOM
, SC_A_SEL
| SC_A_BSY
);
778 if (GET_5380_REG(NCR5380_ICOM
) & SC_LA
) {
779 SET_5380_REG(NCR5380_MODE
, IMODE_BASE
);
780 SET_5380_REG(NCR5380_ICOM
, 0);
781 DBG_SELPRINT ("Arbitration lost, deassert SC_A_SEL\n", 0);
785 /* Bus settle delay + Bus clear delay = 1.2 usecs */
787 DBG_SELPRINT ("Arbitration complete\n", 0);
790 * Now that we won the arbitration, start the selection.
792 targ_bit
= 1 << reqp
->targ_id
;
793 SET_5380_REG(NCR5380_DATA
, SC_HOST_ID
| targ_bit
);
795 if (sc
->sc_noselatn
& targ_bit
)
801 * Raise ATN while SEL is true before BSY goes false from arbitration,
802 * since this is the only way to guarantee that we'll get a MESSAGE OUT
803 * phase immediately after the selection.
805 SET_5380_REG(NCR5380_ICOM
, SC_A_BSY
| SC_A_SEL
| atn_flag
| SC_ADTB
);
806 SET_5380_REG(NCR5380_MODE
, IMODE_BASE
);
809 * Turn off reselection interrupts
811 SET_5380_REG(NCR5380_IDSTAT
, 0);
814 * Reset BSY. The delay following it, surpresses a glitch in the
815 * 5380 which causes us to see our own BSY signal instead of that of
818 SET_5380_REG(NCR5380_ICOM
, SC_A_SEL
| atn_flag
| SC_ADTB
);
822 * Wait for the target to react, the specs call for a timeout of
826 while (!(GET_5380_REG(NCR5380_IDSTAT
) & SC_S_BSY
) && --cnt
)
829 if (!(GET_5380_REG(NCR5380_IDSTAT
) & SC_S_BSY
)) {
831 * There is no reaction from the target, start the selection
832 * timeout procedure. We release the databus but keep SEL
833 * asserted. After that we wait a 'selection abort time' (200
834 * usecs) and 2 deskew delays (90 ns) and check BSY again.
835 * When BSY is asserted, we assume the selection succeeded,
836 * otherwise we release the bus.
838 SET_5380_REG(NCR5380_ICOM
, SC_A_SEL
| atn_flag
);
840 if (!(GET_5380_REG(NCR5380_IDSTAT
) & SC_S_BSY
)) {
841 SET_5380_REG(NCR5380_ICOM
, 0);
842 reqp
->xs
->error
= code
? code
: XS_SELTIMEOUT
;
843 DBG_SELPRINT ("Target %d not responding to sel\n",
845 if (reqp
->dr_flag
& DRIVER_LINKCHK
)
846 ncr_test_link
&= ~(1<<reqp
->targ_id
);
852 SET_5380_REG(NCR5380_ICOM
, atn_flag
);
854 DBG_SELPRINT ("Target %d responding to select.\n", reqp
->targ_id
);
857 * The SCSI-interrupts are disabled while a request is being handled.
862 * If we did not request ATN, then don't try to send IDENTIFY.
865 reqp
->phase
= PH_CMD
;
866 goto identify_failed
;
870 * Here we prepare to send an 'IDENTIFY' message.
871 * Allow disconnect only when interrupts are allowed.
873 tmp
[0] = MSG_IDENTIFY(reqp
->targ_lun
,
874 (reqp
->dr_flag
& DRIVER_NOINT
) ? 0 : 1);
879 * Since we followed the SCSI-spec and raised ATN while SEL was true
880 * but before BSY was false during the selection, a 'MESSAGE OUT'
881 * phase should follow. Unfortunately, this does not happen on
882 * all targets (Asante ethernet devices, for example), so we must
883 * check the actual mode if the message transfer fails--if the
884 * new phase is PH_CMD and has never been successfully selected
885 * w/ATN in the past, then we assume that it is an old device
886 * that doesn't support select w/ATN.
888 if (transfer_pio(&phase
, tmp
, &cnt
, 0) || cnt
) {
890 if ((phase
== PH_CMD
) && !(sc
->sc_selected
& targ_bit
)) {
891 DBG_SELPRINT ("Target %d: not responding to ATN.\n",
893 sc
->sc_noselatn
|= targ_bit
;
894 reqp
->phase
= PH_CMD
;
895 goto identify_failed
;
898 DBG_SELPRINT ("Target %d: failed to send identify\n",
901 * Try to disconnect from the target. We cannot leave
902 * it just hanging here.
904 if (!reach_msg_out(sc
, sizeof(struct scsipi_generic
))) {
906 u_char phse
= PH_MSGOUT
;
907 u_char msg
= MSG_ABORT
;
909 transfer_pio(&phse
, &msg
, &len
, 0);
911 else scsi_reset_verbose(sc
, "Connected to unidentified target");
913 SET_5380_REG(NCR5380_ICOM
, 0);
914 reqp
->xs
->error
= code
? code
: XS_DRIVER_STUFFUP
;
919 reqp
->phase
= PH_MSGOUT
;
922 sc
->sc_selected
|= targ_bit
;
924 #ifdef notyet /* LWP: Do we need timeouts in the driver? */
926 * Command is connected, start timer ticking.
928 ccb_p
->xtimeout
= ccb_p
->timeout
+ Lbolt
;
933 PID("scsi_select10");
939 * 0: Job has finished or disconnected, find something else
940 * -1: keep on calling information_transfer() from scsi_main()
943 information_transfer(struct ncr_softc
*sc
)
945 SC_REQ
*reqp
= connected
;
951 * Clear pending interrupts from 5380-chip.
956 * The SCSI-spec requires BSY to be true while connected to a target,
957 * loosing it means we lost the target...
958 * Also REQ needs to be asserted here to indicate that the bus-phase
959 * is valid. When the target does not supply REQ within a 'reasonable'
960 * amount of time, it's probably lost in it's own maze of twisting
961 * passages, we have to reset the bus to free it.
963 if (GET_5380_REG(NCR5380_IDSTAT
) & SC_S_BSY
)
965 tmp
= GET_5380_REG(NCR5380_IDSTAT
);
968 if ((tmp
& (SC_S_BSY
|SC_S_REQ
)) != (SC_S_BSY
|SC_S_REQ
)) {
969 busy
&= ~(1 << reqp
->targ_id
);
971 reqp
->xs
->error
= XS_TIMEOUT
;
973 if (!(tmp
& SC_S_REQ
))
974 scsi_reset_verbose(sc
,
975 "Timeout waiting for phase-change");
980 phase
= (tmp
>> 2) & 7;
981 if (phase
!= reqp
->phase
) {
984 if (dbg_target_mask
& (1 << reqp
->targ_id
))
985 DBG_INFPRINT(show_phase
, reqp
, phase
);
990 * Same data-phase. If same error give up
992 if ((reqp
->msgout
== MSG_ABORT
)
993 && ((phase
== PH_DATAOUT
) || (phase
== PH_DATAIN
))) {
994 busy
&= ~(1 << reqp
->targ_id
);
996 reqp
->xs
->error
= XS_TIMEOUT
;
998 scsi_reset_verbose(sc
, "Failure to abort command");
1006 ncr_tprint(reqp
, "NOWRITE set -- write attempt aborted.");
1007 reqp
->msgout
= MSG_ABORT
;
1008 SET_5380_REG(NCR5380_ICOM
, SC_A_ATN
);
1010 #endif /* DBG_NOWRITE */
1012 * If this is the first write using DMA, fill
1013 * the bounce buffer.
1015 if (reqp
->xdata_ptr
== reqp
->xs
->data
) { /* XXX */
1016 if (reqp
->dr_flag
& DRIVER_BOUNCING
)
1017 memcpy(reqp
->bounceb
, reqp
->xdata_ptr
, reqp
->xdata_len
);
1021 if (reqp
->xdata_len
<= 0) {
1023 * Target keeps requesting data. Try to get into
1024 * message-out phase by feeding/taking 100 byte.
1026 ncr_tprint(reqp
, "Target requests too much data\n");
1027 reqp
->msgout
= MSG_ABORT
;
1028 SET_5380_REG(NCR5380_ICOM
, SC_A_ATN
);
1029 reach_msg_out(sc
, 100);
1033 if (reqp
->dr_flag
& DRIVER_DMAOK
) {
1034 int poll
= REAL_DMA_POLL
|(reqp
->dr_flag
& DRIVER_NOINT
);
1035 transfer_dma(reqp
, phase
, poll
);
1042 PID("info_transf3");
1043 len
= reqp
->xdata_len
;
1045 if (transfer_pdma(&phase
, reqp
->xdata_ptr
, &len
) == 0)
1048 transfer_pio(&phase
, reqp
->xdata_ptr
, &len
, 0);
1050 reqp
->xdata_ptr
+= reqp
->xdata_len
- len
;
1051 reqp
->xdata_len
= len
;
1056 * We only expect single byte messages here.
1059 transfer_pio(&phase
, &tmp
, &len
, 1);
1060 reqp
->message
= tmp
;
1061 return (handle_message(reqp
, tmp
));
1064 transfer_pio(&phase
, &reqp
->msgout
, &len
, 0);
1065 if (reqp
->msgout
== MSG_ABORT
) {
1066 busy
&= ~(1 << reqp
->targ_id
);
1068 if (!reqp
->xs
->error
)
1069 reqp
->xs
->error
= XS_DRIVER_STUFFUP
;
1071 PID("info_transf4");
1074 reqp
->msgout
= MSG_NOOP
;
1077 len
= reqp
->xcmd_len
;
1078 transfer_pio(&phase
, (u_char
*)&reqp
->xcmd
, &len
, 0);
1079 PID("info_transf5");
1083 transfer_pio(&phase
, &tmp
, &len
, 0);
1085 PID("info_transf6");
1088 ncr_tprint(reqp
, "Unknown phase\n");
1090 PID("info_transf7");
1095 * Handle the message 'msg' send to us by the target.
1097 * 0 : The current command has completed.
1098 * -1 : Get on to the next phase.
1101 handle_message(SC_REQ
*reqp
, u_int msg
)
1109 * Linking lets us reduce the time required to get
1110 * the next command to the device, skipping the arbitration
1111 * and selection time. In the current implementation,
1112 * we merely have to start the next command pointed
1113 * to by 'next_link'.
1115 case MSG_LINK_CMD_COMPLETE
:
1116 case MSG_LINK_CMD_COMPLETEF
:
1117 if (reqp
->link
== NULL
) {
1118 ncr_tprint(reqp
, "No link for linked command");
1119 nack_message(reqp
, MSG_ABORT
);
1124 if (!(reqp
->dr_flag
& DRIVER_AUTOSEN
)) {
1125 reqp
->xs
->resid
= reqp
->xdata_len
;
1126 reqp
->xs
->error
= 0;
1130 if (check_autosense(reqp
, 1) == -1)
1132 #endif /* AUTO_SENSE */
1135 if (dbg_target_mask
& (1 << reqp
->targ_id
))
1136 show_request(reqp
->link
, "LINK");
1138 connected
= reqp
->link
;
1141 * Unlink the 'linked' request from the issue_q
1146 for (; req
!= NULL
; prev
= req
, req
= req
->next
) {
1147 if (req
== connected
)
1151 panic("Inconsistent issue_q");
1153 issue_q
= req
->next
;
1154 else prev
->next
= req
->next
;
1162 case MSG_CMDCOMPLETE
:
1165 busy
&= ~(1 << reqp
->targ_id
);
1166 if (!(reqp
->dr_flag
& DRIVER_AUTOSEN
)) {
1167 reqp
->xs
->resid
= reqp
->xdata_len
;
1168 reqp
->xs
->error
= 0;
1172 if (check_autosense(reqp
, 0) == -1) {
1176 #endif /* AUTO_SENSE */
1181 case MSG_MESSAGE_REJECT
:
1185 case MSG_DISCONNECT
:
1188 if (dbg_target_mask
& (1 << reqp
->targ_id
))
1189 show_request(reqp
, "DISCON");
1193 reqp
->next
= discon_q
;
1198 case MSG_SAVEDATAPOINTER
:
1199 case MSG_RESTOREPOINTERS
:
1201 * We save pointers implicitely at disconnect.
1202 * So we can ignore these messages.
1208 nack_message(reqp
, MSG_MESSAGE_REJECT
);
1212 if ((msg
& 0x80) && !(msg
& 0x18)) { /* IDENTIFY */
1218 "Unknown message %x. Rejecting.\n",
1220 nack_message(reqp
, MSG_MESSAGE_REJECT
);
1229 * Handle reselection. If a valid reconnection occurs, connected
1230 * points at the reconnected command. The command is removed from the
1231 * disconnected queue.
1234 reselect(struct ncr_softc
*sc
)
1244 target_mask
= GET_5380_REG(NCR5380_DATA
) & ~SC_HOST_ID
;
1247 * At this point, we have detected that our SCSI-id is on the bus,
1248 * SEL is true and BSY was false for at least one bus settle
1250 * We must assert BSY ourselves, until the target drops the SEL signal.
1251 * The SCSI-spec specifies no maximum time for this, so we have to
1252 * choose something long enough to suit all targets.
1254 SET_5380_REG(NCR5380_ICOM
, SC_A_BSY
);
1256 while ((GET_5380_REG(NCR5380_IDSTAT
) & SC_S_SEL
) && (len
> 0)) {
1260 if (GET_5380_REG(NCR5380_IDSTAT
) & SC_S_SEL
) {
1261 /* Damn SEL isn't dropping */
1262 scsi_reset_verbose(sc
, "Target won't drop SEL during Reselect");
1266 SET_5380_REG(NCR5380_ICOM
, 0);
1269 * Check if the reselection is still valid. Check twice because
1270 * of possible line glitches - cheaper than delay(1) and we need
1271 * only a few nanoseconds.
1273 if (!(GET_5380_REG(NCR5380_IDSTAT
) & SC_S_BSY
)) {
1274 if (!(GET_5380_REG(NCR5380_IDSTAT
) & SC_S_BSY
)) {
1275 ncr_aprint(sc
, "Stepped into the reselection timeout\n");
1281 * Get the expected identify message.
1285 transfer_pio(&phase
, &msg
, &len
, 0);
1286 if (len
|| !MSG_ISIDENTIFY(msg
)) {
1287 ncr_aprint(sc
, "Expecting IDENTIFY, got 0x%x\n", msg
);
1293 * Find the command reconnecting
1295 for (tmp
= discon_q
, prev
= NULL
; tmp
; prev
= tmp
, tmp
= tmp
->next
){
1296 if (target_mask
== (1 << tmp
->targ_id
)) {
1298 prev
->next
= tmp
->next
;
1299 else discon_q
= tmp
->next
;
1305 ncr_aprint(sc
, "No disconnected job for targetmask %x\n",
1315 SET_5380_REG(NCR5380_ICOM
, SC_A_ATN
);
1316 if (transfer_pio(&phase
, &msg
, &len
, 0) || len
)
1317 scsi_reset_verbose(sc
, "Failure to abort reselection");
1322 if (dbg_target_mask
& (1 << tmp
->targ_id
))
1323 show_request(tmp
, "RECON");
1330 * Transfer data in a given phase using programmed I/O.
1331 * Returns -1 when a different phase is entered without transferring the
1332 * maximum number of bytes, 0 if all bytes transferred or exit is in the same
1336 transfer_pio(u_char
*phase
, u_char
*data
, u_long
*len
, int dont_drop_ack
)
1340 u_char tmp
, new_icom
;
1342 DBG_PIOPRINT ("SCSI: transfer_pio start: phase: %d, len: %d\n", ph
,cnt
);
1344 SET_5380_REG(NCR5380_TCOM
, ph
);
1346 if (!wait_req_true()) {
1347 DBG_PIOPRINT ("SCSI: transfer_pio: missing REQ\n", 0, 0);
1350 if (((GET_5380_REG(NCR5380_IDSTAT
) >> 2) & 7) != ph
) {
1351 DBG_PIOPRINT ("SCSI: transfer_pio: phase mismatch\n", 0, 0);
1355 *data
++ = GET_5380_REG(NCR5380_DATA
);
1356 SET_5380_REG(NCR5380_ICOM
, SC_A_ACK
);
1357 if ((cnt
== 1) && dont_drop_ack
)
1358 new_icom
= SC_A_ACK
;
1362 SET_5380_REG(NCR5380_DATA
, *data
++);
1365 * The SCSI-standard suggests that in the 'MESSAGE OUT' phase,
1366 * the initiator should drop ATN on the last byte of the
1367 * message phase after REQ has been asserted for the handshake
1368 * but before the initiator raises ACK.
1370 if (!( (ph
== PH_MSGOUT
) && (cnt
> 1) )) {
1371 SET_5380_REG(NCR5380_ICOM
, SC_ADTB
);
1372 SET_5380_REG(NCR5380_ICOM
, SC_ADTB
| SC_A_ACK
);
1376 SET_5380_REG(NCR5380_ICOM
, SC_ADTB
| SC_A_ATN
);
1377 SET_5380_REG(NCR5380_ICOM
, SC_ADTB
|SC_A_ATN
|SC_A_ACK
);
1378 new_icom
= SC_A_ATN
;
1381 if (!wait_req_false()) {
1382 DBG_PIOPRINT ("SCSI: transfer_pio - REQ not dropping\n", 0, 0);
1385 SET_5380_REG(NCR5380_ICOM
, new_icom
);
1389 if ((tmp
= GET_5380_REG(NCR5380_IDSTAT
)) & SC_S_REQ
)
1390 *phase
= (tmp
>> 2) & 7;
1391 else *phase
= NR_PHASE
;
1393 DBG_PIOPRINT ("SCSI: transfer_pio done: phase: %d, len: %d\n",
1396 if (!cnt
|| (*phase
== ph
))
1404 * Start a DMA-transfer on the device using the current pointers.
1405 * If 'poll' is true, the function busy-waits until DMA has completed.
1408 transfer_dma(SC_REQ
*reqp
, u_int phase
, int poll
)
1418 * We should be in phase, otherwise we are not allowed to
1421 SET_5380_REG(NCR5380_TCOM
, phase
);
1424 * Defer interrupts until DMA is fully running.
1429 * Clear pending interrupts and parity errors.
1435 * Enable SCSI interrupts and set IN_DMA flag, set 'mbase'
1436 * to the interrupts we want enabled.
1439 reqp
->dr_flag
|= DRIVER_IN_DMA
;
1440 mbase
= SC_E_EOPI
| SC_MON_BSY
;
1442 else scsi_idisable();
1443 mbase
|= IMODE_BASE
| SC_M_DMA
;
1444 scsi_dma_setup(reqp
, phase
, mbase
);
1450 * On polled-DMA transfers, we wait here until the
1451 * 'end-of-DMA' condition occurs.
1454 if (!(dma_done
= dma_ready()))
1461 * Check results of a DMA data-transfer.
1466 SC_REQ
*reqp
= connected
;
1467 int dmstat
, is_edma
;
1468 long bytes_left
, bytes_done
;
1470 is_edma
= get_dma_result(reqp
, &bytes_left
);
1471 dmstat
= GET_5380_REG(NCR5380_DMSTAT
);
1474 * Check if the call is sensible and not caused by any spurious
1477 if (!is_edma
&& !(dmstat
& (SC_END_DMA
|SC_BSY_ERR
))
1478 && (dmstat
& SC_PHS_MTCH
) ) {
1479 ncr_tprint(reqp
, "dma_ready: spurious call "
1480 "(dm:%x,last_hit: %s)\n",
1482 dmstat
, last_hit
[DBG_PID
-1]);
1490 * Clear all (pending) interrupts.
1495 * Update various transfer-pointers/lengths
1497 bytes_done
= reqp
->dm_cur
->dm_count
- bytes_left
;
1499 if ((reqp
->dr_flag
& DRIVER_BOUNCING
) && (PH_IN(reqp
->phase
))) {
1501 * Copy the bytes read until now from the bounce buffer
1502 * to the 'real' destination. Flush the data-cache
1506 memcpy(reqp
->xdata_ptr
, reqp
->bouncerp
, bytes_done
);
1507 reqp
->bouncerp
+= bytes_done
;
1510 reqp
->xdata_ptr
= &reqp
->xdata_ptr
[bytes_done
]; /* XXX */
1511 reqp
->xdata_len
-= bytes_done
; /* XXX */
1512 if ((reqp
->dm_cur
->dm_count
-= bytes_done
) == 0)
1514 else reqp
->dm_cur
->dm_addr
+= bytes_done
;
1516 if (PH_IN(reqp
->phase
) && (dmstat
& SC_PAR_ERR
)) {
1517 if (!(ncr5380_no_parchk
& (1 << reqp
->targ_id
))) {
1518 ncr_tprint(reqp
, "parity error in data-phase\n");
1519 reqp
->xs
->error
= XS_TIMEOUT
;
1524 * DMA mode should always be reset even when we will continue with the
1525 * next chain. It is also essential to clear the MON_BUSY because
1526 * when LOST_BUSY is unexpectedly set, we will not be able to drive
1529 SET_5380_REG(NCR5380_MODE
, IMODE_BASE
);
1532 if ((dmstat
& SC_BSY_ERR
) || !(dmstat
& SC_PHS_MTCH
)
1533 || (reqp
->dm_cur
> reqp
->dm_last
) || (reqp
->xs
->error
)) {
1536 * Tell interrupt functions DMA mode has ended.
1538 reqp
->dr_flag
&= ~DRIVER_IN_DMA
;
1541 * Clear mode and icom
1543 SET_5380_REG(NCR5380_MODE
, IMODE_BASE
);
1544 SET_5380_REG(NCR5380_ICOM
, 0);
1546 if (dmstat
& SC_BSY_ERR
) {
1547 if (!reqp
->xs
->error
)
1548 reqp
->xs
->error
= XS_TIMEOUT
;
1554 if (reqp
->xs
->error
!= 0) {
1555 ncr_tprint(reqp
, "dma-ready: code = %d\n", reqp
->xs
->error
); /* LWP */
1556 reqp
->msgout
= MSG_ABORT
;
1557 SET_5380_REG(NCR5380_ICOM
, SC_A_ATN
);
1564 #endif /* REAL_DMA */
1567 check_autosense(SC_REQ
*reqp
, int linked
)
1572 * If this is the driver's Link Check for this target, ignore
1573 * the results of the command. All we care about is whether we
1574 * got here from a LINK_CMD_COMPLETE or CMD_COMPLETE message.
1577 if (reqp
->dr_flag
& DRIVER_LINKCHK
) {
1579 ncr_will_link
|= 1<<reqp
->targ_id
;
1580 else ncr_tprint(reqp
, "Does not support linked commands\n");
1584 * If we not executing an auto-sense and the status code
1585 * is request-sense, we automatically issue a request
1589 if (!(reqp
->dr_flag
& DRIVER_AUTOSEN
)) {
1590 switch (reqp
->status
& SCSMASK
) {
1592 memcpy(&reqp
->xcmd
, sense_cmd
, sizeof(sense_cmd
));
1593 reqp
->xcmd_len
= sizeof(sense_cmd
);
1594 reqp
->xdata_ptr
= (u_char
*)&reqp
->xs
->sense
.scsi_sense
;
1595 reqp
->xdata_len
= sizeof(reqp
->xs
->sense
.scsi_sense
);
1596 reqp
->dr_flag
|= DRIVER_AUTOSEN
;
1597 reqp
->dr_flag
&= ~DRIVER_DMAOK
;
1600 reqp
->next
= issue_q
;
1604 else reqp
->xcmd
.bytes
[sizeof(sense_cmd
)-2] |= 1;
1607 memset(reqp
->xdata_ptr
, 0, reqp
->xdata_len
);
1608 if (dbg_target_mask
& (1 << reqp
->targ_id
))
1609 show_request(reqp
, "AUTO-SENSE");
1614 reqp
->xs
->error
= XS_BUSY
;
1620 * An auto-sense has finished
1622 if ((reqp
->status
& SCSMASK
) != SCSGOOD
)
1623 reqp
->xs
->error
= XS_DRIVER_STUFFUP
; /* SC_E_AUTOSEN; */
1624 else reqp
->xs
->error
= XS_SENSE
;
1625 reqp
->status
= SCSCHKC
;
1632 reach_msg_out(struct ncr_softc
*sc
, u_long len
)
1638 ncr_aprint(sc
, "Trying to reach Message-out phase\n");
1639 if ((phase
= GET_5380_REG(NCR5380_IDSTAT
)) & SC_S_REQ
)
1640 phase
= (phase
>> 2) & 7;
1642 ncr_aprint(sc
, "Trying to reach Message-out phase, now: %d\n", phase
);
1643 if (phase
== PH_MSGOUT
)
1646 SET_5380_REG(NCR5380_TCOM
, phase
);
1649 if (!wait_req_true())
1651 if (((GET_5380_REG(NCR5380_IDSTAT
) >> 2) & 7) != phase
)
1654 data
= GET_5380_REG(NCR5380_DATA
);
1655 SET_5380_REG(NCR5380_ICOM
, SC_A_ACK
| SC_A_ATN
);
1658 SET_5380_REG(NCR5380_DATA
, 0);
1659 SET_5380_REG(NCR5380_ICOM
, SC_ADTB
|SC_A_ATN
);
1660 SET_5380_REG(NCR5380_ICOM
, SC_ADTB
|SC_A_ACK
|SC_A_ATN
);
1662 if (!wait_req_false())
1664 SET_5380_REG(NCR5380_ICOM
, SC_A_ATN
);
1667 if ((phase
= GET_5380_REG(NCR5380_IDSTAT
)) & SC_S_REQ
) {
1668 phase
= (phase
>> 2) & 7;
1669 if (phase
== PH_MSGOUT
) {
1670 ncr_aprint(sc
, "Message-out phase reached after "
1671 "%ld bytes.\n", len
- n
);
1674 ncr_aprint(sc
, "Phase now: %d after %ld bytes.\n", phase
,
1689 SET_5380_REG(NCR5380_ICOM
, SC_A_RST
);
1691 SET_5380_REG(NCR5380_ICOM
, 0);
1695 * None of the jobs in the discon_q will ever be reconnected,
1696 * notify this to the higher level code.
1698 for (tmp
= discon_q
; tmp
;) {
1701 tmp
->xs
->error
= XS_TIMEOUT
;
1702 busy
&= ~(1 << tmp
->targ_id
);
1709 * The current job will never finish either.
1710 * The problem is that we can't finish the job because an instance
1711 * of main is running on it. Our best guess is that the job is currently
1712 * doing REAL-DMA. In that case 'dma_ready()' should correctly finish
1713 * the job because it detects BSY-loss.
1715 if ((tmp
= connected
) != NULL
) {
1716 if (tmp
->dr_flag
& DRIVER_IN_DMA
) {
1717 tmp
->xs
->error
= XS_DRIVER_STUFFUP
;
1727 * Give the attached devices some time to handle the reset. This
1728 * value is arbitrary but should be relatively long.
1734 scsi_reset_verbose(struct ncr_softc
*sc
, const char *why
)
1736 ncr_aprint(sc
, "Resetting SCSI-bus (%s)\n", why
);
1742 * Check validity of the IRQ set by the 5380. If the interrupt is valid,
1743 * the appropriate action is carried out (reselection or DMA ready) and
1744 * INTR_RESEL or INTR_DMA is returned. Otherwise a console notice is written
1745 * and INTR_SPURIOUS is returned.
1748 check_intr(struct ncr_softc
*sc
)
1752 if ((GET_5380_REG(NCR5380_IDSTAT
) & (SC_S_SEL
|SC_S_IO
))
1753 ==(SC_S_SEL
|SC_S_IO
))
1754 return (INTR_RESEL
);
1756 if ((reqp
= connected
) && (reqp
->dr_flag
& DRIVER_IN_DMA
)){
1757 reqp
->dr_flag
&= ~DRIVER_IN_DMA
;
1764 ncr_aprint(sc
, "Spurious interrupt.\n");
1765 return (INTR_SPURIOUS
);
1770 * Check if DMA can be used for this request. This function also builds
1774 scsi_dmaok(SC_REQ
*reqp
)
1780 struct dma_chain
*dm
;
1783 * To be safe, do not use DMA for Falcon
1785 if (machineid
& ATARI_FALCON
)
1789 * Initialize locals and requests' DMA-chain.
1791 req_len
= reqp
->xdata_len
;
1792 req_addr
= (void *)reqp
->xdata_ptr
;
1793 dm
= reqp
->dm_cur
= reqp
->dm_last
= reqp
->dm_chain
;
1794 dm
->dm_count
= dm
->dm_addr
= 0;
1795 reqp
->dr_flag
&= ~DRIVER_BOUNCING
;
1798 * Do not accept zero length DMA.
1804 * If DMA is emulated in software, we don't have to breakup the
1805 * request. Just build a chain with a single element and stash in
1806 * the KVA and not the KPA.
1808 if (emulated_dma()) {
1809 dm
->dm_addr
= (u_long
)req_addr
;
1810 dm
->dm_count
= req_len
;
1815 * LWP: I think that this restriction is not strictly nessecary.
1817 if ((req_len
& 0x1) || ((u_int
)req_addr
& 0x3))
1821 * Build the DMA-chain.
1823 dm
->dm_addr
= phy_buf
= kvtop(req_addr
);
1826 (phy_len
= PAGE_SIZE
- ((u_long
)req_addr
& PGOFSET
)))
1829 req_addr
+= phy_len
;
1831 dm
->dm_count
+= phy_len
;
1834 u_long tmp
= kvtop(req_addr
);
1836 if ((phy_buf
+ phy_len
) != tmp
) {
1837 if (wrong_dma_range(reqp
, dm
)) {
1838 if (reqp
->dr_flag
& DRIVER_BOUNCING
)
1843 if (++dm
>= &reqp
->dm_chain
[MAXDMAIO
]) {
1844 ncr_tprint(reqp
,"dmaok: DMA chain too long!\n");
1853 if (wrong_dma_range(reqp
, dm
)) {
1854 if (reqp
->dr_flag
& DRIVER_BOUNCING
)
1862 if ((reqp
->bounceb
= alloc_bounceb(reqp
->xdata_len
)) == NULL
) {
1864 * If we can't get a bounce buffer, forget DMA
1866 reqp
->dr_flag
&= ~DRIVER_BOUNCING
;
1870 * Initialize a single DMA-range containing the bounced request
1872 dm
= reqp
->dm_cur
= reqp
->dm_last
= reqp
->dm_chain
;
1873 dm
->dm_addr
= kvtop(reqp
->bounceb
);
1874 dm
->dm_count
= reqp
->xdata_len
;
1875 reqp
->bouncerp
= reqp
->bounceb
;
1879 #endif /* REAL_DMA */
1882 run_main(struct ncr_softc
*sc
)
1886 if (!main_running
) {
1888 * If shared resources are required, claim them
1889 * before entering 'scsi_main'. If we can't get them
1890 * now, assume 'run_main' will be called when the resource
1891 * becomes available.
1893 if (!claimed_dma()) {
1905 * Prefix message with full target info.
1908 ncr_tprint(SC_REQ
*reqp
, const char *fmt
, ...)
1913 scsipi_printaddr(reqp
->xs
->xs_periph
);
1919 * Prefix message with adapter info.
1922 ncr_aprint(struct ncr_softc
*sc
, const char *fmt
, ...)
1928 vsnprintf(buf
, sizeof(buf
), fmt
, ap
);
1931 printf("%s: %s", sc
->sc_dev
.dv_xname
, buf
);
1933 /****************************************************************************
1934 * Start Debugging Functions *
1935 ****************************************************************************/
1936 static const char *phase_names
[] = {
1937 "DATA_OUT", "DATA_IN", "COMMAND", "STATUS", "NONE", "NONE", "MSG_OUT",
1942 show_phase(SC_REQ
*reqp
, int phase
)
1944 printf("INFTRANS: %d Phase = %s\n", reqp
->targ_id
, phase_names
[phase
]);
1948 show_data_sense(struct scsipi_xfer
*xs
)
1953 p1
= (u_char
*) xs
->cmd
;
1954 p2
= (u_char
*)&xs
->sense
.scsi_sense
;
1956 return; /* No(n)sense */
1957 printf("cmd[%d]: ", xs
->cmdlen
);
1958 for (i
= 0; i
< xs
->cmdlen
; i
++)
1959 printf("%x ", p1
[i
]);
1960 printf("\nsense: ");
1961 for (i
= 0; i
< sizeof(xs
->sense
.scsi_sense
); i
++)
1962 printf("%x ", p2
[i
]);
1967 show_request(SC_REQ
*reqp
, const char *qtxt
)
1969 printf("REQ-%s: %d %p[%ld] cmd[0]=%x S=%x M=%x R=%x resid=%d dr_flag=%x %s\n",
1970 qtxt
, reqp
->targ_id
, reqp
->xdata_ptr
, reqp
->xdata_len
,
1971 reqp
->xcmd
.opcode
, reqp
->status
, reqp
->message
,
1972 reqp
->xs
->error
, reqp
->xs
->resid
, reqp
->dr_flag
,
1973 reqp
->link
? "L":"");
1974 if (reqp
->status
== SCSCHKC
)
1975 show_data_sense(reqp
->xs
);
1978 static const char *sig_names
[] = {
1979 "PAR", "SEL", "I/O", "C/D", "MSG", "REQ", "BSY", "RST",
1980 "ACK", "ATN", "LBSY", "PMATCH", "IRQ", "EPAR", "DREQ", "EDMA"
1984 show_signals(u_char dmstat
, u_char idstat
)
1989 tmp
= idstat
| ((dmstat
& 3) << 8);
1990 printf("Bus signals (%02x/%02x): ", idstat
, dmstat
& 3);
1991 for (mask
= 1, j
= need_pipe
= 0; mask
<= tmp
; mask
<<= 1, j
++) {
1993 printf("%s%s", need_pipe
++ ? "|" : "", sig_names
[j
]);
1995 printf("\nDma status (%02x): ", dmstat
);
1996 for (mask
= 4, j
= 10, need_pipe
= 0; mask
<= dmstat
; mask
<<= 1, j
++) {
1998 printf("%s%s", need_pipe
++ ? "|" : "", sig_names
[j
]);
2007 int sps
= splhigh();
2008 u_char idstat
, dmstat
;
2011 printf("scsi_show: scsi_main is%s running\n",
2012 main_running
? "" : " not");
2013 for (tmp
= issue_q
; tmp
; tmp
= tmp
->next
)
2014 show_request(tmp
, "ISSUED");
2015 for (tmp
= discon_q
; tmp
; tmp
= tmp
->next
)
2016 show_request(tmp
, "DISCONNECTED");
2018 show_request(connected
, "CONNECTED");
2019 if (can_access_5380()) {
2020 idstat
= GET_5380_REG(NCR5380_IDSTAT
);
2021 dmstat
= GET_5380_REG(NCR5380_DMSTAT
);
2022 show_signals(dmstat
, idstat
);
2026 printf("phase = %d, ", connected
->phase
);
2027 printf("busy:%x, spl:%04x\n", busy
, sps
);
2029 for (i
=0; i
<DBG_PID
; i
++)
2030 printf("\t%d\t%s\n", i
, last_hit
[i
]);