1 /* $NetBSD: ncr5380.c,v 1.62 2006/02/25 00:58:35 wiz 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.62 2006/02/25 00:58:35 wiz 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 u_char ncr_will_link
= 0x00;
53 #ifdef TRY_SCSI_LINKED_COMMANDS
54 u_char ncr_test_link
= ((~TRY_SCSI_LINKED_COMMANDS
) & 0x7f);
56 u_char ncr_test_link
= 0x7f;
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
*);
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
*);
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 * -- A sleeping Fujitsu M2512 is even worse; try 2.5 sec -hf 20 Jun
101 extern inline int wait_req_true(void)
103 int timeout
= 2500000;
105 while (!(GET_5380_REG(NCR5380_IDSTAT
) & SC_S_REQ
) && --timeout
)
107 return (GET_5380_REG(NCR5380_IDSTAT
) & SC_S_REQ
);
111 * Wait for request-line to become inactive. When it doesn't return 0.
112 * Otherwise return != 0.
114 extern inline int wait_req_false(void)
116 int timeout
= 2500000;
118 while ((GET_5380_REG(NCR5380_IDSTAT
) & SC_S_REQ
) && --timeout
)
120 return (!(GET_5380_REG(NCR5380_IDSTAT
) & SC_S_REQ
));
123 extern inline void ack_message(void)
125 SET_5380_REG(NCR5380_ICOM
, 0);
128 extern inline void nack_message(SC_REQ
*reqp
, u_char msg
)
130 SET_5380_REG(NCR5380_ICOM
, SC_A_ATN
);
134 extern inline void finish_req(SC_REQ
*reqp
)
137 struct scsipi_xfer
*xs
= reqp
->xs
;
141 * If we bounced, free the bounce buffer
143 if (reqp
->dr_flag
& DRIVER_BOUNCING
)
144 free_bounceb(reqp
->bounceb
);
145 #endif /* REAL_DMA */
147 if (dbg_target_mask
& (1 << reqp
->targ_id
))
148 show_request(reqp
, "DONE");
151 if (reqp
->xs
->error
!= 0)
152 show_request(reqp
, "ERR_RET");
155 * Return request to free-q
158 reqp
->next
= free_head
;
162 xs
->xs_status
|= XS_STS_DONE
;
163 if (!(reqp
->dr_flag
& DRIVER_LINKCHK
))
168 * Auto config stuff....
170 void ncr_attach(struct device
*, struct device
*, void *);
171 int ncr_match(struct device
*, struct cfdata
*, void *);
174 * Tricks to make driver-name configurable
176 #define CFNAME(n) __CONCAT(n,_cd)
177 #define CANAME(n) __CONCAT(n,_ca)
178 #define CFSTRING(n) __STRING(n)
179 #define CFDRNAME(n) n
181 CFATTACH_DECL(CFDRNAME(DRNAME
), sizeof(struct ncr_softc
),
182 ncr_match
, ncr_attach
, NULL
, NULL
);
184 extern struct cfdriver
CFNAME(DRNAME
);
187 ncr_match(struct device
*parent
, struct cfdata
*cf
, void *aux
)
189 return (machine_match(parent
, cf
, aux
, &CFNAME(DRNAME
)));
193 ncr_attach(struct device
*pdp
, struct device
*dp
, void *auxp
)
195 struct ncr_softc
*sc
;
198 sc
= (struct ncr_softc
*)dp
;
200 sc
->sc_adapter
.adapt_dev
= &sc
->sc_dev
;
201 sc
->sc_adapter
.adapt_openings
= 7;
202 sc
->sc_adapter
.adapt_max_periph
= 1;
203 sc
->sc_adapter
.adapt_ioctl
= NULL
;
204 sc
->sc_adapter
.adapt_minphys
= ncr5380_minphys
;
205 sc
->sc_adapter
.adapt_request
= ncr5380_scsi_request
;
207 sc
->sc_channel
.chan_adapter
= &sc
->sc_adapter
;
208 sc
->sc_channel
.chan_bustype
= &scsi_bustype
;
209 sc
->sc_channel
.chan_channel
= 0;
210 sc
->sc_channel
.chan_ntargets
= 8;
211 sc
->sc_channel
.chan_nluns
= 8;
212 sc
->sc_channel
.chan_id
= 7;
221 * Initialize machine-type specific things...
227 * Initialize request queue freelist.
229 for (i
= 0; i
< NREQ
; i
++) {
230 req_queue
[i
].next
= free_head
;
231 free_head
= &req_queue
[i
];
235 * Initialize the host adapter
239 SET_5380_REG(NCR5380_ICOM
, 0);
240 SET_5380_REG(NCR5380_MODE
, IMODE_BASE
);
241 SET_5380_REG(NCR5380_TCOM
, 0);
242 SET_5380_REG(NCR5380_IDSTAT
, 0);
246 * attach all scsi units on us
248 config_found(dp
, &sc
->sc_channel
, scsiprint
);
252 * End of auto config stuff....
256 * Carry out a request from the high level driver.
259 ncr5380_scsi_request(struct scsipi_channel
*chan
, scsipi_adapter_req_t req
,
262 struct scsipi_xfer
*xs
;
263 struct scsipi_periph
*periph
;
264 struct ncr_softc
*sc
= (void *)chan
->chan_adapter
->adapt_dev
;
266 SC_REQ
*reqp
, *link
, *tmp
;
269 case ADAPTER_REQ_RUN_XFER
:
271 flags
= xs
->xs_control
;
272 periph
= xs
->xs_periph
;
275 * We do not queue RESET commands
277 if (flags
& XS_CTL_RESET
) {
278 scsi_reset_verbose(sc
, "Got reset-command");
284 * Get a request block
287 if ((reqp
= free_head
) == 0) {
288 xs
->error
= XS_RESOURCE_SHORTAGE
;
292 free_head
= reqp
->next
;
297 * Initialize our private fields
299 reqp
->dr_flag
= (flags
& XS_CTL_POLL
) ? DRIVER_NOINT
: 0;
300 reqp
->phase
= NR_PHASE
;
301 reqp
->msgout
= MSG_NOOP
;
302 reqp
->status
= SCSGOOD
;
303 reqp
->message
= 0xff;
306 reqp
->targ_id
= xs
->xs_periph
->periph_target
;
307 reqp
->targ_lun
= xs
->xs_periph
->periph_lun
;
308 reqp
->xdata_ptr
= (u_char
*)xs
->data
;
309 reqp
->xdata_len
= xs
->datalen
;
310 memcpy(&reqp
->xcmd
, xs
->cmd
, xs
->cmdlen
);
311 reqp
->xcmd_len
= xs
->cmdlen
;
312 reqp
->xcmd
.bytes
[0] |= reqp
->targ_lun
<< 5;
316 * Check if DMA can be used on this request
318 if (scsi_dmaok(reqp
))
319 reqp
->dr_flag
|= DRIVER_DMAOK
;
320 #endif /* REAL_DMA */
323 * Insert the command into the issue queue. Note that
324 * 'REQUEST SENSE' commands are inserted at the head of the
325 * queue since any command will clear the existing contingent
326 * allegience condition and the sense data is only valid while
327 * the condition exists.
328 * When possible, link the command to a previous command to
329 * the same target. This is not very sensible when AUTO_SENSE
330 * is not defined! Interrupts are disabled while we are
331 * fiddling with the issue-queue.
335 if ((issue_q
== NULL
) ||
336 (reqp
->xcmd
.opcode
== SCSI_REQUEST_SENSE
)) {
337 reqp
->next
= issue_q
;
342 if (!link
&& (tmp
->targ_id
== reqp
->targ_id
) &&
345 } while (tmp
->next
&& (tmp
= tmp
->next
));
348 if (link
&& (ncr_will_link
& (1<<reqp
->targ_id
))) {
350 link
->xcmd
.bytes
[link
->xs
->cmdlen
-2] |= 1;
356 * If we haven't already, check the target for link support.
357 * Do this by prefixing the current command with a dummy
358 * Request_Sense command, link the dummy to the current
359 * command, and insert the dummy command at the head of the
360 * issue queue. Set the DRIVER_LINKCHK flag so that we'll
361 * ignore the results of the dummy command, since we only
362 * care about whether it was accepted or not.
364 if (!link
&& !(ncr_test_link
& (1<<reqp
->targ_id
)) &&
365 (tmp
= free_head
) && !(reqp
->dr_flag
& DRIVER_NOINT
)) {
366 free_head
= tmp
->next
;
368 (reqp
->dr_flag
& ~DRIVER_DMAOK
) | DRIVER_LINKCHK
;
369 tmp
->phase
= NR_PHASE
;
370 tmp
->msgout
= MSG_NOOP
;
371 tmp
->status
= SCSGOOD
;
373 tmp
->targ_id
= reqp
->targ_id
;
374 tmp
->targ_lun
= reqp
->targ_lun
;
375 memcpy(&tmp
->xcmd
, sense_cmd
, sizeof(sense_cmd
));
376 tmp
->xcmd_len
= sizeof(sense_cmd
);
377 tmp
->xdata_ptr
= (u_char
*)&tmp
->xs
->sense
.scsi_sense
;
378 tmp
->xdata_len
= sizeof(tmp
->xs
->sense
.scsi_sense
);
379 ncr_test_link
|= 1<<tmp
->targ_id
;
381 tmp
->xcmd
.bytes
[sizeof(sense_cmd
)-2] |= 1;
385 if (dbg_target_mask
& (1 << tmp
->targ_id
))
386 show_request(tmp
, "LINKCHK");
393 if (dbg_target_mask
& (1 << reqp
->targ_id
))
395 (reqp
->xcmd
.opcode
== SCSI_REQUEST_SENSE
) ?
402 case ADAPTER_REQ_GROW_RESOURCES
:
403 /* XXX Not supported. */
406 case ADAPTER_REQ_SET_XFER_MODE
:
407 /* XXX Not supported. */
413 ncr5380_minphys(struct buf
*bp
)
415 if (bp
->b_bcount
> MIN_PHYS
)
416 bp
->b_bcount
= MIN_PHYS
;
422 ncr5380_show_scsi_cmd(struct scsipi_xfer
*xs
)
424 u_char
*b
= (u_char
*) xs
->cmd
;
427 scsipi_printaddr(xs
->xs_periph
);
428 if (!(xs
->xs_control
& XS_CTL_RESET
)) {
429 while (i
< xs
->cmdlen
) {
442 * The body of the driver.
445 scsi_main(struct ncr_softc
*sc
)
452 * While running in the driver SCSI-interrupts are disabled.
462 * Check if it is fair keep any exclusive access to DMA
463 * claimed. If not, stop queueing new jobs so the discon_q
464 * will be eventually drained and DMA can be given up.
466 if (!fair_to_keep_dma())
470 * Search through the issue-queue for a command
471 * destined for a target that isn't busy.
474 for (req
=issue_q
; req
!= NULL
; prev
= req
, req
= req
->next
) {
475 if (!(busy
& (1 << req
->targ_id
))) {
477 * Found one, remove it from the issue queue
481 else prev
->next
= req
->next
;
488 * When a request has just ended, we get here before an other
489 * device detects that the bus is free and that it can
490 * reconnect. The problem is that when this happens, we always
491 * baffle the device because our (initiator) id is higher. This
492 * can cause a sort of starvation on slow devices. So we check
493 * for a pending reselection here.
494 * Note that 'connected' will be non-null if the reselection
497 if ((GET_5380_REG(NCR5380_IDSTAT
) & (SC_S_SEL
|SC_S_IO
))
498 == (SC_S_SEL
|SC_S_IO
)){
511 * The host is not connected and there is no request
520 * Re-enable interrupts before handling the request.
525 if (dbg_target_mask
& (1 << req
->targ_id
))
526 show_request(req
, "TARGET");
529 * We found a request. Try to connect to the target. If the
530 * initiator fails arbitration, the command is put back in the
533 if (scsi_select(req
, 0)) {
539 if (dbg_target_mask
& (1 << req
->targ_id
))
540 ncr_tprint(req
, "Select failed\n");
548 * If the host is currently connected but a 'real-DMA' transfer
549 * is in progress, the 'end-of-DMA' interrupt restarts main.
553 if (connected
&& (connected
->dr_flag
& DRIVER_IN_DMA
)) {
560 * Let the target guide us through the bus-phases
562 while (information_transfer(sc
) == -1)
566 /* NEVER TO REACH HERE */
567 panic("ncr5380-SCSI: not designed to come here");
571 * We enter here with interrupts disabled. We are about to exit main
572 * so interrupts should be re-enabled. Because interrupts are edge
573 * triggered, we could already have missed the interrupt. Therefore
574 * we check the IRQ-line here and re-enter when we really missed a
581 * If we're not currently connected, enable reselection
585 SET_5380_REG(NCR5380_IDSTAT
, SC_HOST_ID
);
587 if (scsi_ipending()) {
588 if ((itype
= check_intr(sc
)) != INTR_SPURIOUS
) {
592 if (itype
== INTR_RESEL
)
600 panic("Got DMA interrupt without DMA");
616 * The SCSI-DMA interrupt.
617 * This interrupt can only be triggered when running in non-polled DMA
618 * mode. When DMA is not active, it will be silently ignored, it is usually
619 * to late because the EOP interrupt of the controller happens just a tiny
620 * bit earlier. It might become usefull when scatter/gather is implemented,
621 * because in that case only part of the DATAIN/DATAOUT transfer is taken
622 * out of a single buffer.
625 ncr_dma_intr(struct ncr_softc
*sc
)
631 if ((reqp
= connected
) && (reqp
->dr_flag
& DRIVER_IN_DMA
)) {
633 if (!(dma_done
= dma_ready())) {
634 transfer_dma(reqp
, reqp
->phase
, 0);
640 #endif /* REAL_DMA */
643 * The SCSI-controller interrupt. This interrupt occurs on reselections and
644 * at the end of non-polled DMA-interrupts. It is assumed to be called from
645 * the machine-dependent hardware interrupt.
648 ncr_ctrl_intr(struct ncr_softc
*sc
)
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 tphase
= PH_MSGOUT
;
907 u_char msg
= MSG_ABORT
;
909 transfer_pio(&tphase
, &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
) {
983 DBG_INFPRINT(show_phase
, reqp
, phase
);
987 * Same data-phase. If same error give up
989 if ((reqp
->msgout
== MSG_ABORT
)
990 && ((phase
== PH_DATAOUT
) || (phase
== PH_DATAIN
))) {
991 busy
&= ~(1 << reqp
->targ_id
);
994 scsi_reset_verbose(sc
, "Failure to abort command");
1002 ncr_tprint(reqp
, "NOWRITE set -- write attempt aborted.");
1003 reqp
->msgout
= MSG_ABORT
;
1004 SET_5380_REG(NCR5380_ICOM
, SC_A_ATN
);
1006 #endif /* DBG_NOWRITE */
1008 * If this is the first write using DMA, fill
1009 * the bounce buffer.
1011 if (reqp
->xdata_ptr
== reqp
->xs
->data
) { /* XXX */
1012 if (reqp
->dr_flag
& DRIVER_BOUNCING
)
1013 memcpy(reqp
->bounceb
, reqp
->xdata_ptr
, reqp
->xdata_len
);
1017 if (reqp
->xdata_len
<= 0) {
1019 * Target keeps requesting data. Try to get into
1020 * message-out phase by feeding/taking 100 byte.
1022 ncr_tprint(reqp
, "Target requests too much data\n");
1023 reqp
->msgout
= MSG_ABORT
;
1024 SET_5380_REG(NCR5380_ICOM
, SC_A_ATN
);
1025 reach_msg_out(sc
, 100);
1029 if (reqp
->dr_flag
& DRIVER_DMAOK
) {
1030 int poll
= REAL_DMA_POLL
|(reqp
->dr_flag
& DRIVER_NOINT
);
1031 transfer_dma(reqp
, phase
, poll
);
1038 PID("info_transf3");
1039 len
= reqp
->xdata_len
;
1041 if (transfer_pdma(&phase
, reqp
->xdata_ptr
, &len
) == 0)
1044 transfer_pio(&phase
, reqp
->xdata_ptr
, &len
, 0);
1046 reqp
->xdata_ptr
+= reqp
->xdata_len
- len
;
1047 reqp
->xdata_len
= len
;
1052 * We only expect single byte messages here.
1055 transfer_pio(&phase
, &tmp
, &len
, 1);
1056 reqp
->message
= tmp
;
1057 return (handle_message(reqp
, tmp
));
1060 transfer_pio(&phase
, &reqp
->msgout
, &len
, 0);
1061 if (reqp
->msgout
== MSG_ABORT
) {
1062 busy
&= ~(1 << reqp
->targ_id
);
1064 if (!reqp
->xs
->error
)
1065 reqp
->xs
->error
= XS_DRIVER_STUFFUP
;
1067 PID("info_transf4");
1070 reqp
->msgout
= MSG_NOOP
;
1073 len
= reqp
->xcmd_len
;
1074 transfer_pio(&phase
, (u_char
*)&reqp
->xcmd
, &len
, 0);
1075 PID("info_transf5");
1079 transfer_pio(&phase
, &tmp
, &len
, 0);
1081 PID("info_transf6");
1084 ncr_tprint(reqp
, "Unknown phase\n");
1086 PID("info_transf7");
1091 * Handle the message 'msg' send to us by the target.
1093 * 0 : The current command has completed.
1094 * -1 : Get on to the next phase.
1097 handle_message(SC_REQ
*reqp
, u_int msg
)
1105 * Linking lets us reduce the time required to get
1106 * the next command to the device, skipping the arbitration
1107 * and selection time. In the current implementation,
1108 * we merely have to start the next command pointed
1109 * to by 'next_link'.
1111 case MSG_LINK_CMD_COMPLETE
:
1112 case MSG_LINK_CMD_COMPLETEF
:
1113 if (reqp
->link
== NULL
) {
1114 ncr_tprint(reqp
, "No link for linked command");
1115 nack_message(reqp
, MSG_ABORT
);
1120 if (!(reqp
->dr_flag
& DRIVER_AUTOSEN
)) {
1121 reqp
->xs
->resid
= reqp
->xdata_len
;
1122 reqp
->xs
->error
= 0;
1126 if (check_autosense(reqp
, 1) == -1)
1128 #endif /* AUTO_SENSE */
1131 if (dbg_target_mask
& (1 << reqp
->targ_id
))
1132 show_request(reqp
->link
, "LINK");
1134 connected
= reqp
->link
;
1137 * Unlink the 'linked' request from the issue_q
1142 for (; req
!= NULL
; prev
= req
, req
= req
->next
) {
1143 if (req
== connected
)
1147 panic("Inconsistent issue_q");
1149 issue_q
= req
->next
;
1150 else prev
->next
= req
->next
;
1158 case MSG_CMDCOMPLETE
:
1161 busy
&= ~(1 << reqp
->targ_id
);
1162 if (!(reqp
->dr_flag
& DRIVER_AUTOSEN
)) {
1163 reqp
->xs
->resid
= reqp
->xdata_len
;
1164 reqp
->xs
->error
= 0;
1168 if (check_autosense(reqp
, 0) == -1) {
1172 #endif /* AUTO_SENSE */
1177 case MSG_MESSAGE_REJECT
:
1181 case MSG_DISCONNECT
:
1184 if (dbg_target_mask
& (1 << reqp
->targ_id
))
1185 show_request(reqp
, "DISCON");
1189 reqp
->next
= discon_q
;
1194 case MSG_SAVEDATAPOINTER
:
1195 case MSG_RESTOREPOINTERS
:
1197 * We save pointers implicitely at disconnect.
1198 * So we can ignore these messages.
1204 nack_message(reqp
, MSG_MESSAGE_REJECT
);
1208 if ((msg
& 0x80) && !(msg
& 0x18)) { /* IDENTIFY */
1214 "Unknown message %x. Rejecting.\n",
1216 nack_message(reqp
, MSG_MESSAGE_REJECT
);
1225 * Handle reselection. If a valid reconnection occurs, connected
1226 * points at the reconnected command. The command is removed from the
1227 * disconnected queue.
1230 reselect(struct ncr_softc
*sc
)
1240 target_mask
= GET_5380_REG(NCR5380_DATA
) & ~SC_HOST_ID
;
1243 * At this point, we have detected that our SCSI-id is on the bus,
1244 * SEL is true and BSY was false for at least one bus settle
1246 * We must assert BSY ourselves, until the target drops the SEL signal.
1247 * The SCSI-spec specifies no maximum time for this, so we have to
1248 * choose something long enough to suit all targets.
1250 SET_5380_REG(NCR5380_ICOM
, SC_A_BSY
);
1252 while ((GET_5380_REG(NCR5380_IDSTAT
) & SC_S_SEL
) && (len
> 0)) {
1256 if (GET_5380_REG(NCR5380_IDSTAT
) & SC_S_SEL
) {
1257 /* Damn SEL isn't dropping */
1258 scsi_reset_verbose(sc
, "Target won't drop SEL during Reselect");
1262 SET_5380_REG(NCR5380_ICOM
, 0);
1265 * Check if the reselection is still valid. Check twice because
1266 * of possible line glitches - cheaper than delay(1) and we need
1267 * only a few nanoseconds.
1269 if (!(GET_5380_REG(NCR5380_IDSTAT
) & SC_S_BSY
)) {
1270 if (!(GET_5380_REG(NCR5380_IDSTAT
) & SC_S_BSY
)) {
1271 ncr_aprint(sc
, "Stepped into the reselection timeout\n");
1277 * Get the expected identify message.
1281 transfer_pio(&phase
, &msg
, &len
, 0);
1282 if (len
|| !MSG_ISIDENTIFY(msg
)) {
1283 ncr_aprint(sc
, "Expecting IDENTIFY, got 0x%x\n", msg
);
1289 * Find the command reconnecting
1291 for (tmp
= discon_q
, prev
= NULL
; tmp
; prev
= tmp
, tmp
= tmp
->next
){
1292 if (target_mask
== (1 << tmp
->targ_id
)) {
1294 prev
->next
= tmp
->next
;
1295 else discon_q
= tmp
->next
;
1301 ncr_aprint(sc
, "No disconnected job for targetmask %x\n",
1311 SET_5380_REG(NCR5380_ICOM
, SC_A_ATN
);
1312 if (transfer_pio(&phase
, &msg
, &len
, 0) || len
)
1313 scsi_reset_verbose(sc
, "Failure to abort reselection");
1318 if (dbg_target_mask
& (1 << tmp
->targ_id
))
1319 show_request(tmp
, "RECON");
1326 * Transfer data in a given phase using programmed I/O.
1327 * Returns -1 when a different phase is entered without transferring the
1328 * maximum number of bytes, 0 if all bytes transferred or exit is in the same
1332 transfer_pio(u_char
*phase
, u_char
*data
, u_long
*len
, int dont_drop_ack
)
1336 u_char tmp
, new_icom
;
1338 DBG_PIOPRINT ("SCSI: transfer_pio start: phase: %d, len: %d\n", ph
,cnt
);
1340 SET_5380_REG(NCR5380_TCOM
, ph
);
1342 if (!wait_req_true()) {
1343 DBG_PIOPRINT ("SCSI: transfer_pio: missing REQ\n", 0, 0);
1346 if (((GET_5380_REG(NCR5380_IDSTAT
) >> 2) & 7) != ph
) {
1347 DBG_PIOPRINT ("SCSI: transfer_pio: phase mismatch\n", 0, 0);
1351 *data
++ = GET_5380_REG(NCR5380_DATA
);
1352 SET_5380_REG(NCR5380_ICOM
, SC_A_ACK
);
1353 if ((cnt
== 1) && dont_drop_ack
)
1354 new_icom
= SC_A_ACK
;
1358 SET_5380_REG(NCR5380_DATA
, *data
++);
1361 * The SCSI-standard suggests that in the 'MESSAGE OUT' phase,
1362 * the initiator should drop ATN on the last byte of the
1363 * message phase after REQ has been asserted for the handshake
1364 * but before the initiator raises ACK.
1366 if (!( (ph
== PH_MSGOUT
) && (cnt
> 1) )) {
1367 SET_5380_REG(NCR5380_ICOM
, SC_ADTB
);
1368 SET_5380_REG(NCR5380_ICOM
, SC_ADTB
| SC_A_ACK
);
1372 SET_5380_REG(NCR5380_ICOM
, SC_ADTB
| SC_A_ATN
);
1373 SET_5380_REG(NCR5380_ICOM
, SC_ADTB
|SC_A_ATN
|SC_A_ACK
);
1374 new_icom
= SC_A_ATN
;
1377 if (!wait_req_false()) {
1378 DBG_PIOPRINT ("SCSI: transfer_pio - REQ not dropping\n", 0, 0);
1381 SET_5380_REG(NCR5380_ICOM
, new_icom
);
1385 if ((tmp
= GET_5380_REG(NCR5380_IDSTAT
)) & SC_S_REQ
)
1386 *phase
= (tmp
>> 2) & 7;
1387 else *phase
= NR_PHASE
;
1389 DBG_PIOPRINT ("SCSI: transfer_pio done: phase: %d, len: %d\n",
1392 if (!cnt
|| (*phase
== ph
))
1399 * Start a DMA-transfer on the device using the current pointers.
1400 * If 'poll' is true, the function busy-waits until DMA has completed.
1403 transfer_dma(SC_REQ
*reqp
, u_int phase
, int poll
)
1413 * We should be in phase, otherwise we are not allowed to
1416 SET_5380_REG(NCR5380_TCOM
, phase
);
1419 * Defer interrupts until DMA is fully running.
1424 * Clear pending interrupts and parity errors.
1430 * Enable SCSI interrupts and set IN_DMA flag, set 'mbase'
1431 * to the interrupts we want enabled.
1434 reqp
->dr_flag
|= DRIVER_IN_DMA
;
1435 mbase
= SC_E_EOPI
| SC_MON_BSY
;
1437 else scsi_idisable();
1438 mbase
|= IMODE_BASE
| SC_M_DMA
;
1439 scsi_dma_setup(reqp
, phase
, mbase
);
1445 * On polled-DMA transfers, we wait here until the
1446 * 'end-of-DMA' condition occurs.
1449 if (!(dma_done
= dma_ready()))
1456 * Check results of a DMA data-transfer.
1461 SC_REQ
*reqp
= connected
;
1462 int dmstat
, is_edma
;
1463 long bytes_left
, bytes_done
;
1465 is_edma
= get_dma_result(reqp
, &bytes_left
);
1466 dmstat
= GET_5380_REG(NCR5380_DMSTAT
);
1469 * Check if the call is sensible and not caused by any spurious
1472 if (!is_edma
&& !(dmstat
& (SC_END_DMA
|SC_BSY_ERR
))
1473 && (dmstat
& SC_PHS_MTCH
) ) {
1474 ncr_tprint(reqp
, "dma_ready: spurious call "
1475 "(dm:%x,last_hit: %s)\n",
1477 dmstat
, last_hit
[DBG_PID
-1]);
1485 * Clear all (pending) interrupts.
1490 * Update various transfer-pointers/lengths
1492 bytes_done
= reqp
->dm_cur
->dm_count
- bytes_left
;
1494 if ((reqp
->dr_flag
& DRIVER_BOUNCING
) && (PH_IN(reqp
->phase
))) {
1496 * Copy the bytes read until now from the bounce buffer
1497 * to the 'real' destination. Flush the data-cache
1501 memcpy(reqp
->xdata_ptr
, reqp
->bouncerp
, bytes_done
);
1502 reqp
->bouncerp
+= bytes_done
;
1505 reqp
->xdata_ptr
= &reqp
->xdata_ptr
[bytes_done
]; /* XXX */
1506 reqp
->xdata_len
-= bytes_done
; /* XXX */
1507 if ((reqp
->dm_cur
->dm_count
-= bytes_done
) == 0)
1509 else reqp
->dm_cur
->dm_addr
+= bytes_done
;
1511 if (PH_IN(reqp
->phase
) && (dmstat
& SC_PAR_ERR
)) {
1512 if (!(ncr5380_no_parchk
& (1 << reqp
->targ_id
))) {
1513 ncr_tprint(reqp
, "parity error in data-phase\n");
1514 reqp
->xs
->error
= XS_TIMEOUT
;
1519 * DMA mode should always be reset even when we will continue with the
1520 * next chain. It is also essential to clear the MON_BUSY because
1521 * when LOST_BUSY is unexpectedly set, we will not be able to drive
1524 SET_5380_REG(NCR5380_MODE
, IMODE_BASE
);
1527 if ((dmstat
& SC_BSY_ERR
) || !(dmstat
& SC_PHS_MTCH
)
1528 || (reqp
->dm_cur
> reqp
->dm_last
) || (reqp
->xs
->error
)) {
1531 * Tell interrupt functions DMA mode has ended.
1533 reqp
->dr_flag
&= ~DRIVER_IN_DMA
;
1536 * Clear mode and icom
1538 SET_5380_REG(NCR5380_MODE
, IMODE_BASE
);
1539 SET_5380_REG(NCR5380_ICOM
, 0);
1541 if (dmstat
& SC_BSY_ERR
) {
1542 if (!reqp
->xs
->error
)
1543 reqp
->xs
->error
= XS_TIMEOUT
;
1549 if (reqp
->xs
->error
!= 0) {
1550 ncr_tprint(reqp
, "dma-ready: code = %d\n", reqp
->xs
->error
); /* LWP */
1551 reqp
->msgout
= MSG_ABORT
;
1552 SET_5380_REG(NCR5380_ICOM
, SC_A_ATN
);
1559 #endif /* REAL_DMA */
1562 check_autosense(SC_REQ
*reqp
, int linked
)
1567 * If this is the driver's Link Check for this target, ignore
1568 * the results of the command. All we care about is whether we
1569 * got here from a LINK_CMD_COMPLETE or CMD_COMPLETE message.
1572 if (reqp
->dr_flag
& DRIVER_LINKCHK
) {
1574 ncr_will_link
|= 1<<reqp
->targ_id
;
1575 else ncr_tprint(reqp
, "Does not support linked commands\n");
1579 * If we not executing an auto-sense and the status code
1580 * is request-sense, we automatically issue a request
1584 if (!(reqp
->dr_flag
& DRIVER_AUTOSEN
)) {
1585 switch (reqp
->status
& SCSMASK
) {
1587 memcpy(&reqp
->xcmd
, sense_cmd
, sizeof(sense_cmd
));
1588 reqp
->xcmd_len
= sizeof(sense_cmd
);
1589 reqp
->xdata_ptr
= (u_char
*)&reqp
->xs
->sense
.scsi_sense
;
1590 reqp
->xdata_len
= sizeof(reqp
->xs
->sense
.scsi_sense
);
1591 reqp
->dr_flag
|= DRIVER_AUTOSEN
;
1592 reqp
->dr_flag
&= ~DRIVER_DMAOK
;
1595 reqp
->next
= issue_q
;
1599 else reqp
->xcmd
.bytes
[sizeof(sense_cmd
)-2] |= 1;
1602 memset(reqp
->xdata_ptr
, 0, reqp
->xdata_len
);
1603 if (dbg_target_mask
& (1 << reqp
->targ_id
))
1604 show_request(reqp
, "AUTO-SENSE");
1609 reqp
->xs
->error
= XS_BUSY
;
1615 * An auto-sense has finished
1617 if ((reqp
->status
& SCSMASK
) != SCSGOOD
)
1618 reqp
->xs
->error
= XS_DRIVER_STUFFUP
; /* SC_E_AUTOSEN; */
1619 else reqp
->xs
->error
= XS_SENSE
;
1620 reqp
->status
= SCSCHKC
;
1627 reach_msg_out(struct ncr_softc
*sc
, u_long len
)
1633 ncr_aprint(sc
, "Trying to reach Message-out phase\n");
1634 if ((phase
= GET_5380_REG(NCR5380_IDSTAT
)) & SC_S_REQ
)
1635 phase
= (phase
>> 2) & 7;
1637 ncr_aprint(sc
, "Trying to reach Message-out phase, now: %d\n", phase
);
1638 if (phase
== PH_MSGOUT
)
1641 SET_5380_REG(NCR5380_TCOM
, phase
);
1644 if (!wait_req_true())
1646 if (((GET_5380_REG(NCR5380_IDSTAT
) >> 2) & 7) != phase
)
1649 data
= GET_5380_REG(NCR5380_DATA
);
1650 SET_5380_REG(NCR5380_ICOM
, SC_A_ACK
| SC_A_ATN
);
1653 SET_5380_REG(NCR5380_DATA
, 0);
1654 SET_5380_REG(NCR5380_ICOM
, SC_ADTB
|SC_A_ACK
|SC_A_ATN
);
1656 if (!wait_req_false())
1658 SET_5380_REG(NCR5380_ICOM
, SC_A_ATN
);
1661 if ((phase
= GET_5380_REG(NCR5380_IDSTAT
)) & SC_S_REQ
) {
1662 phase
= (phase
>> 2) & 7;
1663 if (phase
== PH_MSGOUT
) {
1664 ncr_aprint(sc
, "Message-out phase reached after "
1665 "%ld bytes.\n", len
- n
);
1680 SET_5380_REG(NCR5380_ICOM
, SC_A_RST
);
1682 SET_5380_REG(NCR5380_ICOM
, 0);
1686 * None of the jobs in the discon_q will ever be reconnected,
1687 * notify this to the higher level code.
1689 for (tmp
= discon_q
; tmp
;) {
1692 tmp
->xs
->error
= XS_TIMEOUT
;
1693 busy
&= ~(1 << tmp
->targ_id
);
1700 * The current job will never finish either.
1701 * The problem is that we can't finish the job because an instance
1702 * of main is running on it. Our best guess is that the job is currently
1703 * doing REAL-DMA. In that case 'dma_ready()' should correctly finish
1704 * the job because it detects BSY-loss.
1706 if ((tmp
= connected
) != NULL
) {
1707 if (tmp
->dr_flag
& DRIVER_IN_DMA
) {
1708 tmp
->xs
->error
= XS_DRIVER_STUFFUP
;
1718 * Give the attached devices some time to handle the reset. This
1719 * value is arbitrary but should be relatively long.
1725 scsi_reset_verbose(struct ncr_softc
*sc
, const char *why
)
1727 ncr_aprint(sc
, "Resetting SCSI-bus (%s)\n", why
);
1733 * Check validity of the IRQ set by the 5380. If the interrupt is valid,
1734 * the appropriate action is carried out (reselection or DMA ready) and
1735 * INTR_RESEL or INTR_DMA is returned. Otherwise a console notice is written
1736 * and INTR_SPURIOUS is returned.
1739 check_intr(struct ncr_softc
*sc
)
1743 if ((GET_5380_REG(NCR5380_IDSTAT
) & (SC_S_SEL
|SC_S_IO
))
1744 ==(SC_S_SEL
|SC_S_IO
))
1745 return (INTR_RESEL
);
1747 if ((reqp
= connected
) && (reqp
->dr_flag
& DRIVER_IN_DMA
)){
1748 reqp
->dr_flag
&= ~DRIVER_IN_DMA
;
1755 ncr_aprint(sc
, "Spurious interrupt.\n");
1756 return (INTR_SPURIOUS
);
1761 * Check if DMA can be used for this request. This function also builds
1765 scsi_dmaok(SC_REQ
*reqp
)
1771 struct dma_chain
*dm
;
1774 * Initialize locals and requests' DMA-chain.
1776 req_len
= reqp
->xdata_len
;
1777 req_addr
= (void*)reqp
->xdata_ptr
;
1778 dm
= reqp
->dm_cur
= reqp
->dm_last
= reqp
->dm_chain
;
1779 dm
->dm_count
= dm
->dm_addr
= 0;
1780 reqp
->dr_flag
&= ~DRIVER_BOUNCING
;
1783 * Do not accept zero length DMA.
1789 * LWP: I think that this restriction is not strictly nessecary.
1791 if ((req_len
& 0x1) || ((u_int
)req_addr
& 0x3))
1795 * Build the DMA-chain.
1797 dm
->dm_addr
= phy_buf
= kvtop(req_addr
);
1800 (phy_len
= PAGE_SIZE
- m68k_page_offset(req_addr
)))
1803 req_addr
+= phy_len
;
1805 dm
->dm_count
+= phy_len
;
1808 u_long tmp
= kvtop(req_addr
);
1810 if ((phy_buf
+ phy_len
) != tmp
) {
1811 if (wrong_dma_range(reqp
, dm
)) {
1812 if (reqp
->dr_flag
& DRIVER_BOUNCING
)
1817 if (++dm
>= &reqp
->dm_chain
[MAXDMAIO
]) {
1818 ncr_tprint(reqp
,"dmaok: DMA chain too long!\n");
1827 if (wrong_dma_range(reqp
, dm
)) {
1828 if (reqp
->dr_flag
& DRIVER_BOUNCING
)
1836 if ((reqp
->bounceb
= alloc_bounceb(reqp
->xdata_len
)) == NULL
) {
1838 * If we can't get a bounce buffer, forget DMA
1840 reqp
->dr_flag
&= ~DRIVER_BOUNCING
;
1844 * Initialize a single DMA-range containing the bounced request
1846 dm
= reqp
->dm_cur
= reqp
->dm_last
= reqp
->dm_chain
;
1847 dm
->dm_addr
= kvtop(reqp
->bounceb
);
1848 dm
->dm_count
= reqp
->xdata_len
;
1849 reqp
->bouncerp
= reqp
->bounceb
;
1853 #endif /* REAL_DMA */
1856 run_main(struct ncr_softc
*sc
)
1860 if (!main_running
) {
1862 * If shared resources are required, claim them
1863 * before entering 'scsi_main'. If we can't get them
1864 * now, assume 'run_main' will be called when the resource
1865 * becomes available.
1867 if (!claimed_dma()) {
1879 * Prefix message with full target info.
1882 ncr_tprint(SC_REQ
*reqp
, const char *fmt
, ...)
1887 scsipi_printaddr(reqp
->xs
->xs_periph
);
1893 * Prefix message with adapter info.
1896 ncr_aprint(struct ncr_softc
*sc
, const char *fmt
, ...)
1901 printf("%s: ", sc
->sc_dev
.dv_xname
);
1905 /****************************************************************************
1906 * Start Debugging Functions *
1907 ****************************************************************************/
1909 show_data_sense(struct scsipi_xfer
*xs
)
1914 p1
= (u_char
*) xs
->cmd
;
1915 p2
= (u_char
*)&xs
->sense
.scsi_sense
;
1917 return; /* No(n)sense */
1918 printf("cmd[%d]: ", xs
->cmdlen
);
1919 for (i
= 0; i
< xs
->cmdlen
; i
++)
1920 printf("%x ", p1
[i
]);
1921 printf("\nsense: ");
1922 for (i
= 0; i
< sizeof(xs
->sense
.scsi_sense
); i
++)
1923 printf("%x ", p2
[i
]);
1928 show_request(SC_REQ
*reqp
, const char *qtxt
)
1930 printf("REQ-%s: %d %p[%ld] cmd[0]=%x S=%x M=%x R=%x resid=%d dr_flag=%x %s\n",
1931 qtxt
, reqp
->targ_id
, reqp
->xdata_ptr
, reqp
->xdata_len
,
1932 reqp
->xcmd
.opcode
, reqp
->status
, reqp
->message
,
1933 reqp
->xs
->error
, reqp
->xs
->resid
, reqp
->dr_flag
,
1934 reqp
->link
? "L":"");
1935 if (reqp
->status
== SCSCHKC
)
1936 show_data_sense(reqp
->xs
);
1939 static const char *sig_names
[] = {
1940 "PAR", "SEL", "I/O", "C/D", "MSG", "REQ", "BSY", "RST",
1941 "ACK", "ATN", "LBSY", "PMATCH", "IRQ", "EPAR", "DREQ", "EDMA"
1945 show_signals(u_char dmstat
, u_char idstat
)
1950 tmp
= idstat
| ((dmstat
& 3) << 8);
1951 printf("Bus signals (%02x/%02x): ", idstat
, dmstat
& 3);
1952 for (mask
= 1, j
= need_pipe
= 0; mask
<= tmp
; mask
<<= 1, j
++) {
1954 printf("%s%s", need_pipe
++ ? "|" : "", sig_names
[j
]);
1956 printf("\nDma status (%02x): ", dmstat
);
1957 for (mask
= 4, j
= 10, need_pipe
= 0; mask
<= dmstat
; mask
<<= 1, j
++) {
1959 printf("%s%s", need_pipe
++ ? "|" : "", sig_names
[j
]);
1968 int sps
= splhigh();
1969 u_char idstat
, dmstat
;
1974 printf("scsi_show: scsi_main is%s running\n",
1975 main_running
? "" : " not");
1976 for (tmp
= issue_q
; tmp
; tmp
= tmp
->next
)
1977 show_request(tmp
, "ISSUED");
1978 for (tmp
= discon_q
; tmp
; tmp
= tmp
->next
)
1979 show_request(tmp
, "DISCONNECTED");
1981 show_request(connected
, "CONNECTED");
1982 idstat
= GET_5380_REG(NCR5380_IDSTAT
);
1983 dmstat
= GET_5380_REG(NCR5380_DMSTAT
);
1984 show_signals(dmstat
, idstat
);
1986 printf("phase = %d, ", connected
->phase
);
1987 printf("busy:%x, spl:%04x\n", busy
, sps
);
1989 for (i
=0; i
<DBG_PID
; i
++)
1990 printf("\t%d\t%s\n", i
, last_hit
[i
]);