2 * Core routines and tables shareable across OS platforms.
4 * Copyright (c) 1994-2002 Justin T. Gibbs.
5 * Copyright (c) 2000-2003 Adaptec Inc.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions, and the following disclaimer,
13 * without modification.
14 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
15 * substantially similar to the "NO WARRANTY" disclaimer below
16 * ("Disclaimer") and any redistribution must be conditioned upon
17 * including a substantially similar Disclaimer requirement for further
18 * binary redistribution.
19 * 3. Neither the names of the above-listed copyright holders nor the names
20 * of any contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
23 * Alternatively, this software may be distributed under the terms of the
24 * GNU General Public License ("GPL") version 2 as published by the Free
25 * Software Foundation.
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
36 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
37 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGES.
40 * $Id: //depot/aic7xxx/aic7xxx/aic79xx.c#250 $
44 #include "aic79xx_osm.h"
45 #include "aic79xx_inline.h"
46 #include "aicasm/aicasm_insformat.h"
48 #include <dev/aic7xxx/aic79xx_osm.h>
49 #include <dev/aic7xxx/aic79xx_inline.h>
50 #include <dev/aic7xxx/aicasm/aicasm_insformat.h>
54 /***************************** Lookup Tables **********************************/
55 char *ahd_chip_names
[] =
62 static const u_int num_chip_names
= ARRAY_SIZE(ahd_chip_names
);
65 * Hardware error codes.
67 struct ahd_hard_error_entry
{
72 static struct ahd_hard_error_entry ahd_hard_errors
[] = {
73 { DSCTMOUT
, "Discard Timer has timed out" },
74 { ILLOPCODE
, "Illegal Opcode in sequencer program" },
75 { SQPARERR
, "Sequencer Parity Error" },
76 { DPARERR
, "Data-path Parity Error" },
77 { MPARERR
, "Scratch or SCB Memory Parity Error" },
78 { CIOPARERR
, "CIOBUS Parity Error" },
80 static const u_int num_errors
= ARRAY_SIZE(ahd_hard_errors
);
82 static struct ahd_phase_table_entry ahd_phase_table
[] =
84 { P_DATAOUT
, MSG_NOOP
, "in Data-out phase" },
85 { P_DATAIN
, MSG_INITIATOR_DET_ERR
, "in Data-in phase" },
86 { P_DATAOUT_DT
, MSG_NOOP
, "in DT Data-out phase" },
87 { P_DATAIN_DT
, MSG_INITIATOR_DET_ERR
, "in DT Data-in phase" },
88 { P_COMMAND
, MSG_NOOP
, "in Command phase" },
89 { P_MESGOUT
, MSG_NOOP
, "in Message-out phase" },
90 { P_STATUS
, MSG_INITIATOR_DET_ERR
, "in Status phase" },
91 { P_MESGIN
, MSG_PARITY_ERROR
, "in Message-in phase" },
92 { P_BUSFREE
, MSG_NOOP
, "while idle" },
93 { 0, MSG_NOOP
, "in unknown phase" }
97 * In most cases we only wish to itterate over real phases, so
98 * exclude the last element from the count.
100 static const u_int num_phases
= ARRAY_SIZE(ahd_phase_table
) - 1;
102 /* Our Sequencer Program */
103 #include "aic79xx_seq.h"
105 /**************************** Function Declarations ***************************/
106 static void ahd_handle_transmission_error(struct ahd_softc
*ahd
);
107 static void ahd_handle_lqiphase_error(struct ahd_softc
*ahd
,
109 static int ahd_handle_pkt_busfree(struct ahd_softc
*ahd
,
111 static int ahd_handle_nonpkt_busfree(struct ahd_softc
*ahd
);
112 static void ahd_handle_proto_violation(struct ahd_softc
*ahd
);
113 static void ahd_force_renegotiation(struct ahd_softc
*ahd
,
114 struct ahd_devinfo
*devinfo
);
116 static struct ahd_tmode_tstate
*
117 ahd_alloc_tstate(struct ahd_softc
*ahd
,
118 u_int scsi_id
, char channel
);
119 #ifdef AHD_TARGET_MODE
120 static void ahd_free_tstate(struct ahd_softc
*ahd
,
121 u_int scsi_id
, char channel
, int force
);
123 static void ahd_devlimited_syncrate(struct ahd_softc
*ahd
,
124 struct ahd_initiator_tinfo
*,
128 static void ahd_update_neg_table(struct ahd_softc
*ahd
,
129 struct ahd_devinfo
*devinfo
,
130 struct ahd_transinfo
*tinfo
);
131 static void ahd_update_pending_scbs(struct ahd_softc
*ahd
);
132 static void ahd_fetch_devinfo(struct ahd_softc
*ahd
,
133 struct ahd_devinfo
*devinfo
);
134 static void ahd_scb_devinfo(struct ahd_softc
*ahd
,
135 struct ahd_devinfo
*devinfo
,
137 static void ahd_setup_initiator_msgout(struct ahd_softc
*ahd
,
138 struct ahd_devinfo
*devinfo
,
140 static void ahd_build_transfer_msg(struct ahd_softc
*ahd
,
141 struct ahd_devinfo
*devinfo
);
142 static void ahd_construct_sdtr(struct ahd_softc
*ahd
,
143 struct ahd_devinfo
*devinfo
,
144 u_int period
, u_int offset
);
145 static void ahd_construct_wdtr(struct ahd_softc
*ahd
,
146 struct ahd_devinfo
*devinfo
,
148 static void ahd_construct_ppr(struct ahd_softc
*ahd
,
149 struct ahd_devinfo
*devinfo
,
150 u_int period
, u_int offset
,
151 u_int bus_width
, u_int ppr_options
);
152 static void ahd_clear_msg_state(struct ahd_softc
*ahd
);
153 static void ahd_handle_message_phase(struct ahd_softc
*ahd
);
159 static int ahd_sent_msg(struct ahd_softc
*ahd
, ahd_msgtype type
,
160 u_int msgval
, int full
);
161 static int ahd_parse_msg(struct ahd_softc
*ahd
,
162 struct ahd_devinfo
*devinfo
);
163 static int ahd_handle_msg_reject(struct ahd_softc
*ahd
,
164 struct ahd_devinfo
*devinfo
);
165 static void ahd_handle_ign_wide_residue(struct ahd_softc
*ahd
,
166 struct ahd_devinfo
*devinfo
);
167 static void ahd_reinitialize_dataptrs(struct ahd_softc
*ahd
);
168 static void ahd_handle_devreset(struct ahd_softc
*ahd
,
169 struct ahd_devinfo
*devinfo
,
170 u_int lun
, cam_status status
,
171 char *message
, int verbose_level
);
172 #ifdef AHD_TARGET_MODE
173 static void ahd_setup_target_msgin(struct ahd_softc
*ahd
,
174 struct ahd_devinfo
*devinfo
,
178 static u_int
ahd_sglist_size(struct ahd_softc
*ahd
);
179 static u_int
ahd_sglist_allocsize(struct ahd_softc
*ahd
);
180 static bus_dmamap_callback_t
182 static void ahd_initialize_hscbs(struct ahd_softc
*ahd
);
183 static int ahd_init_scbdata(struct ahd_softc
*ahd
);
184 static void ahd_fini_scbdata(struct ahd_softc
*ahd
);
185 static void ahd_setup_iocell_workaround(struct ahd_softc
*ahd
);
186 static void ahd_iocell_first_selection(struct ahd_softc
*ahd
);
187 static void ahd_add_col_list(struct ahd_softc
*ahd
,
188 struct scb
*scb
, u_int col_idx
);
189 static void ahd_rem_col_list(struct ahd_softc
*ahd
,
191 static void ahd_chip_init(struct ahd_softc
*ahd
);
192 static void ahd_qinfifo_requeue(struct ahd_softc
*ahd
,
193 struct scb
*prev_scb
,
195 static int ahd_qinfifo_count(struct ahd_softc
*ahd
);
196 static int ahd_search_scb_list(struct ahd_softc
*ahd
, int target
,
197 char channel
, int lun
, u_int tag
,
198 role_t role
, uint32_t status
,
199 ahd_search_action action
,
200 u_int
*list_head
, u_int
*list_tail
,
202 static void ahd_stitch_tid_list(struct ahd_softc
*ahd
,
203 u_int tid_prev
, u_int tid_cur
,
205 static void ahd_add_scb_to_free_list(struct ahd_softc
*ahd
,
207 static u_int
ahd_rem_wscb(struct ahd_softc
*ahd
, u_int scbid
,
208 u_int prev
, u_int next
, u_int tid
);
209 static void ahd_reset_current_bus(struct ahd_softc
*ahd
);
210 static ahd_callback_t ahd_stat_timer
;
212 static void ahd_dumpseq(struct ahd_softc
*ahd
);
214 static void ahd_loadseq(struct ahd_softc
*ahd
);
215 static int ahd_check_patch(struct ahd_softc
*ahd
,
216 struct patch
**start_patch
,
217 u_int start_instr
, u_int
*skip_addr
);
218 static u_int
ahd_resolve_seqaddr(struct ahd_softc
*ahd
,
220 static void ahd_download_instr(struct ahd_softc
*ahd
,
221 u_int instrptr
, uint8_t *dconsts
);
222 static int ahd_probe_stack_size(struct ahd_softc
*ahd
);
223 static int ahd_scb_active_in_fifo(struct ahd_softc
*ahd
,
225 static void ahd_run_data_fifo(struct ahd_softc
*ahd
,
228 #ifdef AHD_TARGET_MODE
229 static void ahd_queue_lstate_event(struct ahd_softc
*ahd
,
230 struct ahd_tmode_lstate
*lstate
,
234 static void ahd_update_scsiid(struct ahd_softc
*ahd
,
236 static int ahd_handle_target_cmd(struct ahd_softc
*ahd
,
237 struct target_cmd
*cmd
);
240 /******************************** Private Inlines *****************************/
241 static __inline
void ahd_assert_atn(struct ahd_softc
*ahd
);
242 static __inline
int ahd_currently_packetized(struct ahd_softc
*ahd
);
243 static __inline
int ahd_set_active_fifo(struct ahd_softc
*ahd
);
246 ahd_assert_atn(struct ahd_softc
*ahd
)
248 ahd_outb(ahd
, SCSISIGO
, ATNO
);
252 * Determine if the current connection has a packetized
253 * agreement. This does not necessarily mean that we
254 * are currently in a packetized transfer. We could
255 * just as easily be sending or receiving a message.
258 ahd_currently_packetized(struct ahd_softc
*ahd
)
260 ahd_mode_state saved_modes
;
263 saved_modes
= ahd_save_modes(ahd
);
264 if ((ahd
->bugs
& AHD_PKTIZED_STATUS_BUG
) != 0) {
266 * The packetized bit refers to the last
267 * connection, not the current one. Check
268 * for non-zero LQISTATE instead.
270 ahd_set_modes(ahd
, AHD_MODE_CFG
, AHD_MODE_CFG
);
271 packetized
= ahd_inb(ahd
, LQISTATE
) != 0;
273 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
274 packetized
= ahd_inb(ahd
, LQISTAT2
) & PACKETIZED
;
276 ahd_restore_modes(ahd
, saved_modes
);
281 ahd_set_active_fifo(struct ahd_softc
*ahd
)
285 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
286 active_fifo
= ahd_inb(ahd
, DFFSTAT
) & CURRFIFO
;
287 switch (active_fifo
) {
290 ahd_set_modes(ahd
, active_fifo
, active_fifo
);
297 /************************* Sequencer Execution Control ************************/
299 * Restart the sequencer program from address zero
302 ahd_restart(struct ahd_softc
*ahd
)
307 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
309 /* No more pending messages */
310 ahd_clear_msg_state(ahd
);
311 ahd_outb(ahd
, SCSISIGO
, 0); /* De-assert BSY */
312 ahd_outb(ahd
, MSG_OUT
, MSG_NOOP
); /* No message to send */
313 ahd_outb(ahd
, SXFRCTL1
, ahd_inb(ahd
, SXFRCTL1
) & ~BITBUCKET
);
314 ahd_outb(ahd
, SEQINTCTL
, 0);
315 ahd_outb(ahd
, LASTPHASE
, P_BUSFREE
);
316 ahd_outb(ahd
, SEQ_FLAGS
, 0);
317 ahd_outb(ahd
, SAVED_SCSIID
, 0xFF);
318 ahd_outb(ahd
, SAVED_LUN
, 0xFF);
321 * Ensure that the sequencer's idea of TQINPOS
322 * matches our own. The sequencer increments TQINPOS
323 * only after it sees a DMA complete and a reset could
324 * occur before the increment leaving the kernel to believe
325 * the command arrived but the sequencer to not.
327 ahd_outb(ahd
, TQINPOS
, ahd
->tqinfifonext
);
329 /* Always allow reselection */
330 ahd_outb(ahd
, SCSISEQ1
,
331 ahd_inb(ahd
, SCSISEQ_TEMPLATE
) & (ENSELI
|ENRSELI
|ENAUTOATNP
));
332 ahd_set_modes(ahd
, AHD_MODE_CCHAN
, AHD_MODE_CCHAN
);
335 * Clear any pending sequencer interrupt. It is no
336 * longer relevant since we're resetting the Program
339 ahd_outb(ahd
, CLRINT
, CLRSEQINT
);
341 ahd_outb(ahd
, SEQCTL0
, FASTMODE
|SEQRESET
);
346 ahd_clear_fifo(struct ahd_softc
*ahd
, u_int fifo
)
348 ahd_mode_state saved_modes
;
351 if ((ahd_debug
& AHD_SHOW_FIFOS
) != 0)
352 printf("%s: Clearing FIFO %d\n", ahd_name(ahd
), fifo
);
354 saved_modes
= ahd_save_modes(ahd
);
355 ahd_set_modes(ahd
, fifo
, fifo
);
356 ahd_outb(ahd
, DFFSXFRCTL
, RSTCHN
|CLRSHCNT
);
357 if ((ahd_inb(ahd
, SG_STATE
) & FETCH_INPROG
) != 0)
358 ahd_outb(ahd
, CCSGCTL
, CCSGRESET
);
359 ahd_outb(ahd
, LONGJMP_ADDR
+ 1, INVALID_ADDR
);
360 ahd_outb(ahd
, SG_STATE
, 0);
361 ahd_restore_modes(ahd
, saved_modes
);
364 /************************* Input/Output Queues ********************************/
366 * Flush and completed commands that are sitting in the command
367 * complete queues down on the chip but have yet to be dma'ed back up.
370 ahd_flush_qoutfifo(struct ahd_softc
*ahd
)
373 ahd_mode_state saved_modes
;
379 saved_modes
= ahd_save_modes(ahd
);
382 * Flush the good status FIFO for completed packetized commands.
384 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
385 saved_scbptr
= ahd_get_scbptr(ahd
);
386 while ((ahd_inb(ahd
, LQISTAT2
) & LQIGSAVAIL
) != 0) {
390 scbid
= ahd_inw(ahd
, GSFIFO
);
391 scb
= ahd_lookup_scb(ahd
, scbid
);
393 printf("%s: Warning - GSFIFO SCB %d invalid\n",
394 ahd_name(ahd
), scbid
);
398 * Determine if this transaction is still active in
399 * any FIFO. If it is, we must flush that FIFO to
400 * the host before completing the command.
404 for (i
= 0; i
< 2; i
++) {
405 /* Toggle to the other mode. */
407 ahd_set_modes(ahd
, fifo_mode
, fifo_mode
);
409 if (ahd_scb_active_in_fifo(ahd
, scb
) == 0)
412 ahd_run_data_fifo(ahd
, scb
);
415 * Running this FIFO may cause a CFG4DATA for
416 * this same transaction to assert in the other
417 * FIFO or a new snapshot SAVEPTRS interrupt
418 * in this FIFO. Even running a FIFO may not
419 * clear the transaction if we are still waiting
420 * for data to drain to the host. We must loop
421 * until the transaction is not active in either
422 * FIFO just to be sure. Reset our loop counter
423 * so we will visit both FIFOs again before
424 * declaring this transaction finished. We
425 * also delay a bit so that status has a chance
426 * to change before we look at this FIFO again.
431 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
432 ahd_set_scbptr(ahd
, scbid
);
433 if ((ahd_inb_scbram(ahd
, SCB_SGPTR
) & SG_LIST_NULL
) == 0
434 && ((ahd_inb_scbram(ahd
, SCB_SGPTR
) & SG_FULL_RESID
) != 0
435 || (ahd_inb_scbram(ahd
, SCB_RESIDUAL_SGPTR
)
436 & SG_LIST_NULL
) != 0)) {
440 * The transfer completed with a residual.
441 * Place this SCB on the complete DMA list
442 * so that we update our in-core copy of the
443 * SCB before completing the command.
445 ahd_outb(ahd
, SCB_SCSI_STATUS
, 0);
446 ahd_outb(ahd
, SCB_SGPTR
,
447 ahd_inb_scbram(ahd
, SCB_SGPTR
)
449 ahd_outw(ahd
, SCB_TAG
, scbid
);
450 ahd_outw(ahd
, SCB_NEXT_COMPLETE
, SCB_LIST_NULL
);
451 comp_head
= ahd_inw(ahd
, COMPLETE_DMA_SCB_HEAD
);
452 if (SCBID_IS_NULL(comp_head
)) {
453 ahd_outw(ahd
, COMPLETE_DMA_SCB_HEAD
, scbid
);
454 ahd_outw(ahd
, COMPLETE_DMA_SCB_TAIL
, scbid
);
458 tail
= ahd_inw(ahd
, COMPLETE_DMA_SCB_TAIL
);
459 ahd_set_scbptr(ahd
, tail
);
460 ahd_outw(ahd
, SCB_NEXT_COMPLETE
, scbid
);
461 ahd_outw(ahd
, COMPLETE_DMA_SCB_TAIL
, scbid
);
462 ahd_set_scbptr(ahd
, scbid
);
465 ahd_complete_scb(ahd
, scb
);
467 ahd_set_scbptr(ahd
, saved_scbptr
);
470 * Setup for command channel portion of flush.
472 ahd_set_modes(ahd
, AHD_MODE_CCHAN
, AHD_MODE_CCHAN
);
475 * Wait for any inprogress DMA to complete and clear DMA state
476 * if this if for an SCB in the qinfifo.
478 while (((ccscbctl
= ahd_inb(ahd
, CCSCBCTL
)) & (CCARREN
|CCSCBEN
)) != 0) {
480 if ((ccscbctl
& (CCSCBDIR
|CCARREN
)) == (CCSCBDIR
|CCARREN
)) {
481 if ((ccscbctl
& ARRDONE
) != 0)
483 } else if ((ccscbctl
& CCSCBDONE
) != 0)
488 * We leave the sequencer to cleanup in the case of DMA's to
489 * update the qoutfifo. In all other cases (DMA's to the
490 * chip or a push of an SCB from the COMPLETE_DMA_SCB list),
491 * we disable the DMA engine so that the sequencer will not
492 * attempt to handle the DMA completion.
494 if ((ccscbctl
& CCSCBDIR
) != 0 || (ccscbctl
& ARRDONE
) != 0)
495 ahd_outb(ahd
, CCSCBCTL
, ccscbctl
& ~(CCARREN
|CCSCBEN
));
498 * Complete any SCBs that just finished
499 * being DMA'ed into the qoutfifo.
501 ahd_run_qoutfifo(ahd
);
503 saved_scbptr
= ahd_get_scbptr(ahd
);
505 * Manually update/complete any completed SCBs that are waiting to be
506 * DMA'ed back up to the host.
508 scbid
= ahd_inw(ahd
, COMPLETE_DMA_SCB_HEAD
);
509 while (!SCBID_IS_NULL(scbid
)) {
513 ahd_set_scbptr(ahd
, scbid
);
514 next_scbid
= ahd_inw_scbram(ahd
, SCB_NEXT_COMPLETE
);
515 scb
= ahd_lookup_scb(ahd
, scbid
);
517 printf("%s: Warning - DMA-up and complete "
518 "SCB %d invalid\n", ahd_name(ahd
), scbid
);
521 hscb_ptr
= (uint8_t *)scb
->hscb
;
522 for (i
= 0; i
< sizeof(struct hardware_scb
); i
++)
523 *hscb_ptr
++ = ahd_inb_scbram(ahd
, SCB_BASE
+ i
);
525 ahd_complete_scb(ahd
, scb
);
528 ahd_outw(ahd
, COMPLETE_DMA_SCB_HEAD
, SCB_LIST_NULL
);
529 ahd_outw(ahd
, COMPLETE_DMA_SCB_TAIL
, SCB_LIST_NULL
);
531 scbid
= ahd_inw(ahd
, COMPLETE_ON_QFREEZE_HEAD
);
532 while (!SCBID_IS_NULL(scbid
)) {
534 ahd_set_scbptr(ahd
, scbid
);
535 next_scbid
= ahd_inw_scbram(ahd
, SCB_NEXT_COMPLETE
);
536 scb
= ahd_lookup_scb(ahd
, scbid
);
538 printf("%s: Warning - Complete Qfrz SCB %d invalid\n",
539 ahd_name(ahd
), scbid
);
543 ahd_complete_scb(ahd
, scb
);
546 ahd_outw(ahd
, COMPLETE_ON_QFREEZE_HEAD
, SCB_LIST_NULL
);
548 scbid
= ahd_inw(ahd
, COMPLETE_SCB_HEAD
);
549 while (!SCBID_IS_NULL(scbid
)) {
551 ahd_set_scbptr(ahd
, scbid
);
552 next_scbid
= ahd_inw_scbram(ahd
, SCB_NEXT_COMPLETE
);
553 scb
= ahd_lookup_scb(ahd
, scbid
);
555 printf("%s: Warning - Complete SCB %d invalid\n",
556 ahd_name(ahd
), scbid
);
560 ahd_complete_scb(ahd
, scb
);
563 ahd_outw(ahd
, COMPLETE_SCB_HEAD
, SCB_LIST_NULL
);
568 ahd_set_scbptr(ahd
, saved_scbptr
);
569 ahd_restore_modes(ahd
, saved_modes
);
570 ahd
->flags
|= AHD_UPDATE_PEND_CMDS
;
574 * Determine if an SCB for a packetized transaction
575 * is active in a FIFO.
578 ahd_scb_active_in_fifo(struct ahd_softc
*ahd
, struct scb
*scb
)
582 * The FIFO is only active for our transaction if
583 * the SCBPTR matches the SCB's ID and the firmware
584 * has installed a handler for the FIFO or we have
585 * a pending SAVEPTRS or CFG4DATA interrupt.
587 if (ahd_get_scbptr(ahd
) != SCB_GET_TAG(scb
)
588 || ((ahd_inb(ahd
, LONGJMP_ADDR
+1) & INVALID_ADDR
) != 0
589 && (ahd_inb(ahd
, SEQINTSRC
) & (CFG4DATA
|SAVEPTRS
)) == 0))
596 * Run a data fifo to completion for a transaction we know
597 * has completed across the SCSI bus (good status has been
598 * received). We are already set to the correct FIFO mode
599 * on entry to this routine.
601 * This function attempts to operate exactly as the firmware
602 * would when running this FIFO. Care must be taken to update
603 * this routine any time the firmware's FIFO algorithm is
607 ahd_run_data_fifo(struct ahd_softc
*ahd
, struct scb
*scb
)
611 seqintsrc
= ahd_inb(ahd
, SEQINTSRC
);
612 if ((seqintsrc
& CFG4DATA
) != 0) {
617 * Clear full residual flag.
619 sgptr
= ahd_inl_scbram(ahd
, SCB_SGPTR
) & ~SG_FULL_RESID
;
620 ahd_outb(ahd
, SCB_SGPTR
, sgptr
);
623 * Load datacnt and address.
625 datacnt
= ahd_inl_scbram(ahd
, SCB_DATACNT
);
626 if ((datacnt
& AHD_DMA_LAST_SEG
) != 0) {
628 ahd_outb(ahd
, SG_STATE
, 0);
630 ahd_outb(ahd
, SG_STATE
, LOADING_NEEDED
);
631 ahd_outq(ahd
, HADDR
, ahd_inq_scbram(ahd
, SCB_DATAPTR
));
632 ahd_outl(ahd
, HCNT
, datacnt
& AHD_SG_LEN_MASK
);
633 ahd_outb(ahd
, SG_CACHE_PRE
, sgptr
);
634 ahd_outb(ahd
, DFCNTRL
, PRELOADEN
|SCSIEN
|HDMAEN
);
637 * Initialize Residual Fields.
639 ahd_outb(ahd
, SCB_RESIDUAL_DATACNT
+3, datacnt
>> 24);
640 ahd_outl(ahd
, SCB_RESIDUAL_SGPTR
, sgptr
& SG_PTR_MASK
);
643 * Mark the SCB as having a FIFO in use.
645 ahd_outb(ahd
, SCB_FIFO_USE_COUNT
,
646 ahd_inb_scbram(ahd
, SCB_FIFO_USE_COUNT
) + 1);
649 * Install a "fake" handler for this FIFO.
651 ahd_outw(ahd
, LONGJMP_ADDR
, 0);
654 * Notify the hardware that we have satisfied
655 * this sequencer interrupt.
657 ahd_outb(ahd
, CLRSEQINTSRC
, CLRCFG4DATA
);
658 } else if ((seqintsrc
& SAVEPTRS
) != 0) {
662 if ((ahd_inb(ahd
, LONGJMP_ADDR
+1)&INVALID_ADDR
) != 0) {
664 * Snapshot Save Pointers. All that
665 * is necessary to clear the snapshot
672 * Disable S/G fetch so the DMA engine
673 * is available to future users.
675 if ((ahd_inb(ahd
, SG_STATE
) & FETCH_INPROG
) != 0)
676 ahd_outb(ahd
, CCSGCTL
, 0);
677 ahd_outb(ahd
, SG_STATE
, 0);
680 * Flush the data FIFO. Strickly only
681 * necessary for Rev A parts.
683 ahd_outb(ahd
, DFCNTRL
, ahd_inb(ahd
, DFCNTRL
) | FIFOFLUSH
);
686 * Calculate residual.
688 sgptr
= ahd_inl_scbram(ahd
, SCB_RESIDUAL_SGPTR
);
689 resid
= ahd_inl(ahd
, SHCNT
);
690 resid
|= ahd_inb_scbram(ahd
, SCB_RESIDUAL_DATACNT
+3) << 24;
691 ahd_outl(ahd
, SCB_RESIDUAL_DATACNT
, resid
);
692 if ((ahd_inb(ahd
, SG_CACHE_SHADOW
) & LAST_SEG
) == 0) {
694 * Must back up to the correct S/G element.
695 * Typically this just means resetting our
696 * low byte to the offset in the SG_CACHE,
697 * but if we wrapped, we have to correct
698 * the other bytes of the sgptr too.
700 if ((ahd_inb(ahd
, SG_CACHE_SHADOW
) & 0x80) != 0
701 && (sgptr
& 0x80) == 0)
704 sgptr
|= ahd_inb(ahd
, SG_CACHE_SHADOW
)
706 ahd_outl(ahd
, SCB_RESIDUAL_SGPTR
, sgptr
);
707 ahd_outb(ahd
, SCB_RESIDUAL_DATACNT
+ 3, 0);
708 } else if ((resid
& AHD_SG_LEN_MASK
) == 0) {
709 ahd_outb(ahd
, SCB_RESIDUAL_SGPTR
,
710 sgptr
| SG_LIST_NULL
);
715 ahd_outq(ahd
, SCB_DATAPTR
, ahd_inq(ahd
, SHADDR
));
716 ahd_outl(ahd
, SCB_DATACNT
, resid
);
717 ahd_outl(ahd
, SCB_SGPTR
, sgptr
);
718 ahd_outb(ahd
, CLRSEQINTSRC
, CLRSAVEPTRS
);
719 ahd_outb(ahd
, SEQIMODE
,
720 ahd_inb(ahd
, SEQIMODE
) | ENSAVEPTRS
);
722 * If the data is to the SCSI bus, we are
723 * done, otherwise wait for FIFOEMP.
725 if ((ahd_inb(ahd
, DFCNTRL
) & DIRECTION
) != 0)
727 } else if ((ahd_inb(ahd
, SG_STATE
) & LOADING_NEEDED
) != 0) {
734 * Disable S/G fetch so the DMA engine
735 * is available to future users. We won't
736 * be using the DMA engine to load segments.
738 if ((ahd_inb(ahd
, SG_STATE
) & FETCH_INPROG
) != 0) {
739 ahd_outb(ahd
, CCSGCTL
, 0);
740 ahd_outb(ahd
, SG_STATE
, LOADING_NEEDED
);
744 * Wait for the DMA engine to notice that the
745 * host transfer is enabled and that there is
746 * space in the S/G FIFO for new segments before
747 * loading more segments.
749 if ((ahd_inb(ahd
, DFSTATUS
) & PRELOAD_AVAIL
) != 0
750 && (ahd_inb(ahd
, DFCNTRL
) & HDMAENACK
) != 0) {
753 * Determine the offset of the next S/G
756 sgptr
= ahd_inl_scbram(ahd
, SCB_RESIDUAL_SGPTR
);
757 sgptr
&= SG_PTR_MASK
;
758 if ((ahd
->flags
& AHD_64BIT_ADDRESSING
) != 0) {
759 struct ahd_dma64_seg
*sg
;
761 sg
= ahd_sg_bus_to_virt(ahd
, scb
, sgptr
);
762 data_addr
= sg
->addr
;
764 sgptr
+= sizeof(*sg
);
766 struct ahd_dma_seg
*sg
;
768 sg
= ahd_sg_bus_to_virt(ahd
, scb
, sgptr
);
769 data_addr
= sg
->len
& AHD_SG_HIGH_ADDR_MASK
;
771 data_addr
|= sg
->addr
;
773 sgptr
+= sizeof(*sg
);
777 * Update residual information.
779 ahd_outb(ahd
, SCB_RESIDUAL_DATACNT
+3, data_len
>> 24);
780 ahd_outl(ahd
, SCB_RESIDUAL_SGPTR
, sgptr
);
785 if (data_len
& AHD_DMA_LAST_SEG
) {
787 ahd_outb(ahd
, SG_STATE
, 0);
789 ahd_outq(ahd
, HADDR
, data_addr
);
790 ahd_outl(ahd
, HCNT
, data_len
& AHD_SG_LEN_MASK
);
791 ahd_outb(ahd
, SG_CACHE_PRE
, sgptr
& 0xFF);
794 * Advertise the segment to the hardware.
796 dfcntrl
= ahd_inb(ahd
, DFCNTRL
)|PRELOADEN
|HDMAEN
;
797 if ((ahd
->features
& AHD_NEW_DFCNTRL_OPTS
) != 0) {
799 * Use SCSIENWRDIS so that SCSIEN
800 * is never modified by this
803 dfcntrl
|= SCSIENWRDIS
;
805 ahd_outb(ahd
, DFCNTRL
, dfcntrl
);
807 } else if ((ahd_inb(ahd
, SG_CACHE_SHADOW
) & LAST_SEG_DONE
) != 0) {
810 * Transfer completed to the end of SG list
811 * and has flushed to the host.
813 ahd_outb(ahd
, SCB_SGPTR
,
814 ahd_inb_scbram(ahd
, SCB_SGPTR
) | SG_LIST_NULL
);
816 } else if ((ahd_inb(ahd
, DFSTATUS
) & FIFOEMP
) != 0) {
819 * Clear any handler for this FIFO, decrement
820 * the FIFO use count for the SCB, and release
823 ahd_outb(ahd
, LONGJMP_ADDR
+ 1, INVALID_ADDR
);
824 ahd_outb(ahd
, SCB_FIFO_USE_COUNT
,
825 ahd_inb_scbram(ahd
, SCB_FIFO_USE_COUNT
) - 1);
826 ahd_outb(ahd
, DFFSXFRCTL
, CLRCHN
);
831 * Look for entries in the QoutFIFO that have completed.
832 * The valid_tag completion field indicates the validity
833 * of the entry - the valid value toggles each time through
834 * the queue. We use the sg_status field in the completion
835 * entry to avoid referencing the hscb if the completion
836 * occurred with no errors and no residual. sg_status is
837 * a copy of the first byte (little endian) of the sgptr
841 ahd_run_qoutfifo(struct ahd_softc
*ahd
)
843 struct ahd_completion
*completion
;
847 if ((ahd
->flags
& AHD_RUNNING_QOUTFIFO
) != 0)
848 panic("ahd_run_qoutfifo recursion");
849 ahd
->flags
|= AHD_RUNNING_QOUTFIFO
;
850 ahd_sync_qoutfifo(ahd
, BUS_DMASYNC_POSTREAD
);
852 completion
= &ahd
->qoutfifo
[ahd
->qoutfifonext
];
854 if (completion
->valid_tag
!= ahd
->qoutfifonext_valid_tag
)
857 scb_index
= ahd_le16toh(completion
->tag
);
858 scb
= ahd_lookup_scb(ahd
, scb_index
);
860 printf("%s: WARNING no command for scb %d "
861 "(cmdcmplt)\nQOUTPOS = %d\n",
862 ahd_name(ahd
), scb_index
,
864 ahd_dump_card_state(ahd
);
865 } else if ((completion
->sg_status
& SG_STATUS_VALID
) != 0) {
866 ahd_handle_scb_status(ahd
, scb
);
871 ahd
->qoutfifonext
= (ahd
->qoutfifonext
+1) & (AHD_QOUT_SIZE
-1);
872 if (ahd
->qoutfifonext
== 0)
873 ahd
->qoutfifonext_valid_tag
^= QOUTFIFO_ENTRY_VALID
;
875 ahd
->flags
&= ~AHD_RUNNING_QOUTFIFO
;
878 /************************* Interrupt Handling *********************************/
880 ahd_handle_hwerrint(struct ahd_softc
*ahd
)
883 * Some catastrophic hardware error has occurred.
884 * Print it for the user and disable the controller.
889 error
= ahd_inb(ahd
, ERROR
);
890 for (i
= 0; i
< num_errors
; i
++) {
891 if ((error
& ahd_hard_errors
[i
].errno
) != 0)
892 printf("%s: hwerrint, %s\n",
893 ahd_name(ahd
), ahd_hard_errors
[i
].errmesg
);
896 ahd_dump_card_state(ahd
);
899 /* Tell everyone that this HBA is no longer available */
900 ahd_abort_scbs(ahd
, CAM_TARGET_WILDCARD
, ALL_CHANNELS
,
901 CAM_LUN_WILDCARD
, SCB_LIST_NULL
, ROLE_UNKNOWN
,
904 /* Tell the system that this controller has gone away. */
909 ahd_handle_seqint(struct ahd_softc
*ahd
, u_int intstat
)
914 * Save the sequencer interrupt code and clear the SEQINT
915 * bit. We will unpause the sequencer, if appropriate,
916 * after servicing the request.
918 seqintcode
= ahd_inb(ahd
, SEQINTCODE
);
919 ahd_outb(ahd
, CLRINT
, CLRSEQINT
);
920 if ((ahd
->bugs
& AHD_INTCOLLISION_BUG
) != 0) {
922 * Unpause the sequencer and let it clear
923 * SEQINT by writing NO_SEQINT to it. This
924 * will cause the sequencer to be paused again,
925 * which is the expected state of this routine.
928 while (!ahd_is_paused(ahd
))
930 ahd_outb(ahd
, CLRINT
, CLRSEQINT
);
932 ahd_update_modes(ahd
);
934 if ((ahd_debug
& AHD_SHOW_MISC
) != 0)
935 printf("%s: Handle Seqint Called for code %d\n",
936 ahd_name(ahd
), seqintcode
);
938 switch (seqintcode
) {
939 case ENTERING_NONPACK
:
944 AHD_ASSERT_MODES(ahd
, ~(AHD_MODE_UNKNOWN_MSK
|AHD_MODE_CFG_MSK
),
945 ~(AHD_MODE_UNKNOWN_MSK
|AHD_MODE_CFG_MSK
));
946 scbid
= ahd_get_scbptr(ahd
);
947 scb
= ahd_lookup_scb(ahd
, scbid
);
950 * Somehow need to know if this
951 * is from a selection or reselection.
952 * From that, we can determine target
953 * ID so we at least have an I_T nexus.
956 ahd_outb(ahd
, SAVED_SCSIID
, scb
->hscb
->scsiid
);
957 ahd_outb(ahd
, SAVED_LUN
, scb
->hscb
->lun
);
958 ahd_outb(ahd
, SEQ_FLAGS
, 0x0);
960 if ((ahd_inb(ahd
, LQISTAT2
) & LQIPHASE_OUTPKT
) != 0
961 && (ahd_inb(ahd
, SCSISIGO
) & ATNO
) != 0) {
963 * Phase change after read stream with
964 * CRC error with P0 asserted on last
968 if ((ahd_debug
& AHD_SHOW_RECOVERY
) != 0)
969 printf("%s: Assuming LQIPHASE_NLQ with "
970 "P0 assertion\n", ahd_name(ahd
));
974 if ((ahd_debug
& AHD_SHOW_RECOVERY
) != 0)
975 printf("%s: Entering NONPACK\n", ahd_name(ahd
));
980 printf("%s: Invalid Sequencer interrupt occurred, "
981 "resetting channel.\n",
984 if ((ahd_debug
& AHD_SHOW_RECOVERY
) != 0)
985 ahd_dump_card_state(ahd
);
987 ahd_reset_channel(ahd
, 'A', /*Initiate Reset*/TRUE
);
994 scbid
= ahd_get_scbptr(ahd
);
995 scb
= ahd_lookup_scb(ahd
, scbid
);
997 ahd_print_path(ahd
, scb
);
999 printf("%s: ", ahd_name(ahd
));
1000 printf("SCB %d Packetized Status Overrun", scbid
);
1001 ahd_dump_card_state(ahd
);
1002 ahd_reset_channel(ahd
, 'A', /*Initiate Reset*/TRUE
);
1005 case CFG4ISTAT_INTR
:
1010 scbid
= ahd_get_scbptr(ahd
);
1011 scb
= ahd_lookup_scb(ahd
, scbid
);
1013 ahd_dump_card_state(ahd
);
1014 printf("CFG4ISTAT: Free SCB %d referenced", scbid
);
1015 panic("For safety");
1017 ahd_outq(ahd
, HADDR
, scb
->sense_busaddr
);
1018 ahd_outw(ahd
, HCNT
, AHD_SENSE_BUFSIZE
);
1019 ahd_outb(ahd
, HCNT
+ 2, 0);
1020 ahd_outb(ahd
, SG_CACHE_PRE
, SG_LAST_SEG
);
1021 ahd_outb(ahd
, DFCNTRL
, PRELOADEN
|SCSIEN
|HDMAEN
);
1028 bus_phase
= ahd_inb(ahd
, SCSISIGI
) & PHASE_MASK
;
1029 printf("%s: ILLEGAL_PHASE 0x%x\n",
1030 ahd_name(ahd
), bus_phase
);
1032 switch (bus_phase
) {
1040 ahd_reset_channel(ahd
, 'A', /*Initiate Reset*/TRUE
);
1041 printf("%s: Issued Bus Reset.\n", ahd_name(ahd
));
1045 struct ahd_devinfo devinfo
;
1047 struct ahd_initiator_tinfo
*targ_info
;
1048 struct ahd_tmode_tstate
*tstate
;
1049 struct ahd_transinfo
*tinfo
;
1053 * If a target takes us into the command phase
1054 * assume that it has been externally reset and
1055 * has thus lost our previous packetized negotiation
1057 * Revert to async/narrow transfers until we
1058 * can renegotiate with the device and notify
1059 * the OSM about the reset.
1061 scbid
= ahd_get_scbptr(ahd
);
1062 scb
= ahd_lookup_scb(ahd
, scbid
);
1064 printf("Invalid phase with no valid SCB. "
1065 "Resetting bus.\n");
1066 ahd_reset_channel(ahd
, 'A',
1067 /*Initiate Reset*/TRUE
);
1070 ahd_compile_devinfo(&devinfo
, SCB_GET_OUR_ID(scb
),
1071 SCB_GET_TARGET(ahd
, scb
),
1073 SCB_GET_CHANNEL(ahd
, scb
),
1075 targ_info
= ahd_fetch_transinfo(ahd
,
1080 tinfo
= &targ_info
->curr
;
1081 ahd_set_width(ahd
, &devinfo
, MSG_EXT_WDTR_BUS_8_BIT
,
1082 AHD_TRANS_ACTIVE
, /*paused*/TRUE
);
1083 ahd_set_syncrate(ahd
, &devinfo
, /*period*/0,
1084 /*offset*/0, /*ppr_options*/0,
1085 AHD_TRANS_ACTIVE
, /*paused*/TRUE
);
1086 scb
->flags
|= SCB_EXTERNAL_RESET
;
1087 ahd_freeze_devq(ahd
, scb
);
1088 ahd_set_transaction_status(scb
, CAM_REQUEUE_REQ
);
1089 ahd_freeze_scb(scb
);
1092 ahd_send_async(ahd
, devinfo
.channel
, devinfo
.target
,
1093 CAM_LUN_WILDCARD
, AC_SENT_BDR
);
1096 * Allow the sequencer to continue with
1097 * non-pack processing.
1099 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
1100 ahd_outb(ahd
, CLRLQOINT1
, CLRLQOPHACHGINPKT
);
1101 if ((ahd
->bugs
& AHD_CLRLQO_AUTOCLR_BUG
) != 0) {
1102 ahd_outb(ahd
, CLRLQOINT1
, 0);
1105 if ((ahd_debug
& AHD_SHOW_RECOVERY
) != 0) {
1106 ahd_print_path(ahd
, scb
);
1107 printf("Unexpected command phase from "
1108 "packetized target\n");
1122 if ((ahd_debug
& AHD_SHOW_RECOVERY
) != 0) {
1123 printf("%s: CFG4OVERRUN mode = %x\n", ahd_name(ahd
),
1124 ahd_inb(ahd
, MODE_PTR
));
1127 scb_index
= ahd_get_scbptr(ahd
);
1128 scb
= ahd_lookup_scb(ahd
, scb_index
);
1131 * Attempt to transfer to an SCB that is
1134 ahd_assert_atn(ahd
);
1135 ahd_outb(ahd
, MSG_OUT
, HOST_MSG
);
1136 ahd
->msgout_buf
[0] = MSG_ABORT_TASK
;
1137 ahd
->msgout_len
= 1;
1138 ahd
->msgout_index
= 0;
1139 ahd
->msg_type
= MSG_TYPE_INITIATOR_MSGOUT
;
1141 * Clear status received flag to prevent any
1142 * attempt to complete this bogus SCB.
1144 ahd_outb(ahd
, SCB_CONTROL
,
1145 ahd_inb_scbram(ahd
, SCB_CONTROL
)
1150 case DUMP_CARD_STATE
:
1152 ahd_dump_card_state(ahd
);
1158 if ((ahd_debug
& AHD_SHOW_RECOVERY
) != 0) {
1159 printf("%s: PDATA_REINIT - DFCNTRL = 0x%x "
1160 "SG_CACHE_SHADOW = 0x%x\n",
1161 ahd_name(ahd
), ahd_inb(ahd
, DFCNTRL
),
1162 ahd_inb(ahd
, SG_CACHE_SHADOW
));
1165 ahd_reinitialize_dataptrs(ahd
);
1170 struct ahd_devinfo devinfo
;
1173 * The sequencer has encountered a message phase
1174 * that requires host assistance for completion.
1175 * While handling the message phase(s), we will be
1176 * notified by the sequencer after each byte is
1177 * transfered so we can track bus phase changes.
1179 * If this is the first time we've seen a HOST_MSG_LOOP
1180 * interrupt, initialize the state of the host message
1183 ahd_fetch_devinfo(ahd
, &devinfo
);
1184 if (ahd
->msg_type
== MSG_TYPE_NONE
) {
1189 bus_phase
= ahd_inb(ahd
, SCSISIGI
) & PHASE_MASK
;
1190 if (bus_phase
!= P_MESGIN
1191 && bus_phase
!= P_MESGOUT
) {
1192 printf("ahd_intr: HOST_MSG_LOOP bad "
1193 "phase 0x%x\n", bus_phase
);
1195 * Probably transitioned to bus free before
1196 * we got here. Just punt the message.
1198 ahd_dump_card_state(ahd
);
1199 ahd_clear_intstat(ahd
);
1204 scb_index
= ahd_get_scbptr(ahd
);
1205 scb
= ahd_lookup_scb(ahd
, scb_index
);
1206 if (devinfo
.role
== ROLE_INITIATOR
) {
1207 if (bus_phase
== P_MESGOUT
)
1208 ahd_setup_initiator_msgout(ahd
,
1213 MSG_TYPE_INITIATOR_MSGIN
;
1214 ahd
->msgin_index
= 0;
1217 #ifdef AHD_TARGET_MODE
1219 if (bus_phase
== P_MESGOUT
) {
1221 MSG_TYPE_TARGET_MSGOUT
;
1222 ahd
->msgin_index
= 0;
1225 ahd_setup_target_msgin(ahd
,
1232 ahd_handle_message_phase(ahd
);
1237 /* Ensure we don't leave the selection hardware on */
1238 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
1239 ahd_outb(ahd
, SCSISEQ0
, ahd_inb(ahd
, SCSISEQ0
) & ~ENSELO
);
1241 printf("%s:%c:%d: no active SCB for reconnecting "
1242 "target - issuing BUS DEVICE RESET\n",
1243 ahd_name(ahd
), 'A', ahd_inb(ahd
, SELID
) >> 4);
1244 printf("SAVED_SCSIID == 0x%x, SAVED_LUN == 0x%x, "
1245 "REG0 == 0x%x ACCUM = 0x%x\n",
1246 ahd_inb(ahd
, SAVED_SCSIID
), ahd_inb(ahd
, SAVED_LUN
),
1247 ahd_inw(ahd
, REG0
), ahd_inb(ahd
, ACCUM
));
1248 printf("SEQ_FLAGS == 0x%x, SCBPTR == 0x%x, BTT == 0x%x, "
1250 ahd_inb(ahd
, SEQ_FLAGS
), ahd_get_scbptr(ahd
),
1251 ahd_find_busy_tcl(ahd
,
1252 BUILD_TCL(ahd_inb(ahd
, SAVED_SCSIID
),
1253 ahd_inb(ahd
, SAVED_LUN
))),
1254 ahd_inw(ahd
, SINDEX
));
1255 printf("SELID == 0x%x, SCB_SCSIID == 0x%x, SCB_LUN == 0x%x, "
1256 "SCB_CONTROL == 0x%x\n",
1257 ahd_inb(ahd
, SELID
), ahd_inb_scbram(ahd
, SCB_SCSIID
),
1258 ahd_inb_scbram(ahd
, SCB_LUN
),
1259 ahd_inb_scbram(ahd
, SCB_CONTROL
));
1260 printf("SCSIBUS[0] == 0x%x, SCSISIGI == 0x%x\n",
1261 ahd_inb(ahd
, SCSIBUS
), ahd_inb(ahd
, SCSISIGI
));
1262 printf("SXFRCTL0 == 0x%x\n", ahd_inb(ahd
, SXFRCTL0
));
1263 printf("SEQCTL0 == 0x%x\n", ahd_inb(ahd
, SEQCTL0
));
1264 ahd_dump_card_state(ahd
);
1265 ahd
->msgout_buf
[0] = MSG_BUS_DEV_RESET
;
1266 ahd
->msgout_len
= 1;
1267 ahd
->msgout_index
= 0;
1268 ahd
->msg_type
= MSG_TYPE_INITIATOR_MSGOUT
;
1269 ahd_outb(ahd
, MSG_OUT
, HOST_MSG
);
1270 ahd_assert_atn(ahd
);
1273 case PROTO_VIOLATION
:
1275 ahd_handle_proto_violation(ahd
);
1280 struct ahd_devinfo devinfo
;
1282 ahd_fetch_devinfo(ahd
, &devinfo
);
1283 ahd_handle_ign_wide_residue(ahd
, &devinfo
);
1290 lastphase
= ahd_inb(ahd
, LASTPHASE
);
1291 printf("%s:%c:%d: unknown scsi bus phase %x, "
1292 "lastphase = 0x%x. Attempting to continue\n",
1294 SCSIID_TARGET(ahd
, ahd_inb(ahd
, SAVED_SCSIID
)),
1295 lastphase
, ahd_inb(ahd
, SCSISIGI
));
1298 case MISSED_BUSFREE
:
1302 lastphase
= ahd_inb(ahd
, LASTPHASE
);
1303 printf("%s:%c:%d: Missed busfree. "
1304 "Lastphase = 0x%x, Curphase = 0x%x\n",
1306 SCSIID_TARGET(ahd
, ahd_inb(ahd
, SAVED_SCSIID
)),
1307 lastphase
, ahd_inb(ahd
, SCSISIGI
));
1314 * When the sequencer detects an overrun, it
1315 * places the controller in "BITBUCKET" mode
1316 * and allows the target to complete its transfer.
1317 * Unfortunately, none of the counters get updated
1318 * when the controller is in this mode, so we have
1319 * no way of knowing how large the overrun was.
1327 scbindex
= ahd_get_scbptr(ahd
);
1328 scb
= ahd_lookup_scb(ahd
, scbindex
);
1330 lastphase
= ahd_inb(ahd
, LASTPHASE
);
1331 if ((ahd_debug
& AHD_SHOW_RECOVERY
) != 0) {
1332 ahd_print_path(ahd
, scb
);
1333 printf("data overrun detected %s. Tag == 0x%x.\n",
1334 ahd_lookup_phase_entry(lastphase
)->phasemsg
,
1336 ahd_print_path(ahd
, scb
);
1337 printf("%s seen Data Phase. Length = %ld. "
1339 ahd_inb(ahd
, SEQ_FLAGS
) & DPHASE
1340 ? "Have" : "Haven't",
1341 ahd_get_transfer_length(scb
), scb
->sg_count
);
1342 ahd_dump_sglist(scb
);
1347 * Set this and it will take effect when the
1348 * target does a command complete.
1350 ahd_freeze_devq(ahd
, scb
);
1351 ahd_set_transaction_status(scb
, CAM_DATA_RUN_ERR
);
1352 ahd_freeze_scb(scb
);
1357 struct ahd_devinfo devinfo
;
1361 ahd_fetch_devinfo(ahd
, &devinfo
);
1362 printf("%s:%c:%d:%d: Attempt to issue message failed\n",
1363 ahd_name(ahd
), devinfo
.channel
, devinfo
.target
,
1365 scbid
= ahd_get_scbptr(ahd
);
1366 scb
= ahd_lookup_scb(ahd
, scbid
);
1368 && (scb
->flags
& SCB_RECOVERY_SCB
) != 0)
1370 * Ensure that we didn't put a second instance of this
1371 * SCB into the QINFIFO.
1373 ahd_search_qinfifo(ahd
, SCB_GET_TARGET(ahd
, scb
),
1374 SCB_GET_CHANNEL(ahd
, scb
),
1375 SCB_GET_LUN(scb
), SCB_GET_TAG(scb
),
1376 ROLE_INITIATOR
, /*status*/0,
1378 ahd_outb(ahd
, SCB_CONTROL
,
1379 ahd_inb_scbram(ahd
, SCB_CONTROL
) & ~MK_MESSAGE
);
1382 case TASKMGMT_FUNC_COMPLETE
:
1387 scbid
= ahd_get_scbptr(ahd
);
1388 scb
= ahd_lookup_scb(ahd
, scbid
);
1394 ahd_print_path(ahd
, scb
);
1395 printf("Task Management Func 0x%x Complete\n",
1396 scb
->hscb
->task_management
);
1397 lun
= CAM_LUN_WILDCARD
;
1398 tag
= SCB_LIST_NULL
;
1400 switch (scb
->hscb
->task_management
) {
1401 case SIU_TASKMGMT_ABORT_TASK
:
1402 tag
= SCB_GET_TAG(scb
);
1403 case SIU_TASKMGMT_ABORT_TASK_SET
:
1404 case SIU_TASKMGMT_CLEAR_TASK_SET
:
1405 lun
= scb
->hscb
->lun
;
1406 error
= CAM_REQ_ABORTED
;
1407 ahd_abort_scbs(ahd
, SCB_GET_TARGET(ahd
, scb
),
1408 'A', lun
, tag
, ROLE_INITIATOR
,
1411 case SIU_TASKMGMT_LUN_RESET
:
1412 lun
= scb
->hscb
->lun
;
1413 case SIU_TASKMGMT_TARGET_RESET
:
1415 struct ahd_devinfo devinfo
;
1417 ahd_scb_devinfo(ahd
, &devinfo
, scb
);
1418 error
= CAM_BDR_SENT
;
1419 ahd_handle_devreset(ahd
, &devinfo
, lun
,
1421 lun
!= CAM_LUN_WILDCARD
1424 /*verbose_level*/0);
1428 panic("Unexpected TaskMgmt Func\n");
1434 case TASKMGMT_CMD_CMPLT_OKAY
:
1440 * An ABORT TASK TMF failed to be delivered before
1441 * the targeted command completed normally.
1443 scbid
= ahd_get_scbptr(ahd
);
1444 scb
= ahd_lookup_scb(ahd
, scbid
);
1447 * Remove the second instance of this SCB from
1448 * the QINFIFO if it is still there.
1450 ahd_print_path(ahd
, scb
);
1451 printf("SCB completes before TMF\n");
1453 * Handle losing the race. Wait until any
1454 * current selection completes. We will then
1455 * set the TMF back to zero in this SCB so that
1456 * the sequencer doesn't bother to issue another
1457 * sequencer interrupt for its completion.
1459 while ((ahd_inb(ahd
, SCSISEQ0
) & ENSELO
) != 0
1460 && (ahd_inb(ahd
, SSTAT0
) & SELDO
) == 0
1461 && (ahd_inb(ahd
, SSTAT1
) & SELTO
) == 0)
1463 ahd_outb(ahd
, SCB_TASK_MANAGEMENT
, 0);
1464 ahd_search_qinfifo(ahd
, SCB_GET_TARGET(ahd
, scb
),
1465 SCB_GET_CHANNEL(ahd
, scb
),
1466 SCB_GET_LUN(scb
), SCB_GET_TAG(scb
),
1467 ROLE_INITIATOR
, /*status*/0,
1476 printf("%s: Tracepoint %d\n", ahd_name(ahd
),
1477 seqintcode
- TRACEPOINT0
);
1482 ahd_handle_hwerrint(ahd
);
1485 printf("%s: Unexpected SEQINTCODE %d\n", ahd_name(ahd
),
1490 * The sequencer is paused immediately on
1491 * a SEQINT, so we should restart it when
1498 ahd_handle_scsiint(struct ahd_softc
*ahd
, u_int intstat
)
1509 ahd_update_modes(ahd
);
1510 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
1512 status3
= ahd_inb(ahd
, SSTAT3
) & (NTRAMPERR
|OSRAMPERR
);
1513 status0
= ahd_inb(ahd
, SSTAT0
) & (IOERR
|OVERRUN
|SELDI
|SELDO
);
1514 status
= ahd_inb(ahd
, SSTAT1
) & (SELTO
|SCSIRSTI
|BUSFREE
|SCSIPERR
);
1515 lqistat1
= ahd_inb(ahd
, LQISTAT1
);
1516 lqostat0
= ahd_inb(ahd
, LQOSTAT0
);
1517 busfreetime
= ahd_inb(ahd
, SSTAT2
) & BUSFREETIME
;
1520 * Ignore external resets after a bus reset.
1522 if (((status
& SCSIRSTI
) != 0) && (ahd
->flags
& AHD_BUS_RESET_ACTIVE
))
1526 * Clear bus reset flag
1528 ahd
->flags
&= ~AHD_BUS_RESET_ACTIVE
;
1530 if ((status0
& (SELDI
|SELDO
)) != 0) {
1533 ahd_set_modes(ahd
, AHD_MODE_CFG
, AHD_MODE_CFG
);
1534 simode0
= ahd_inb(ahd
, SIMODE0
);
1535 status0
&= simode0
& (IOERR
|OVERRUN
|SELDI
|SELDO
);
1536 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
1538 scbid
= ahd_get_scbptr(ahd
);
1539 scb
= ahd_lookup_scb(ahd
, scbid
);
1541 && (ahd_inb(ahd
, SEQ_FLAGS
) & NOT_IDENTIFIED
) != 0)
1544 if ((status0
& IOERR
) != 0) {
1547 now_lvd
= ahd_inb(ahd
, SBLKCTL
) & ENAB40
;
1548 printf("%s: Transceiver State Has Changed to %s mode\n",
1549 ahd_name(ahd
), now_lvd
? "LVD" : "SE");
1550 ahd_outb(ahd
, CLRSINT0
, CLRIOERR
);
1552 * A change in I/O mode is equivalent to a bus reset.
1554 ahd_reset_channel(ahd
, 'A', /*Initiate Reset*/TRUE
);
1556 ahd_setup_iocell_workaround(ahd
);
1558 } else if ((status0
& OVERRUN
) != 0) {
1560 printf("%s: SCSI offset overrun detected. Resetting bus.\n",
1562 ahd_reset_channel(ahd
, 'A', /*Initiate Reset*/TRUE
);
1563 } else if ((status
& SCSIRSTI
) != 0) {
1565 printf("%s: Someone reset channel A\n", ahd_name(ahd
));
1566 ahd_reset_channel(ahd
, 'A', /*Initiate Reset*/FALSE
);
1567 } else if ((status
& SCSIPERR
) != 0) {
1569 /* Make sure the sequencer is in a safe location. */
1570 ahd_clear_critical_section(ahd
);
1572 ahd_handle_transmission_error(ahd
);
1573 } else if (lqostat0
!= 0) {
1575 printf("%s: lqostat0 == 0x%x!\n", ahd_name(ahd
), lqostat0
);
1576 ahd_outb(ahd
, CLRLQOINT0
, lqostat0
);
1577 if ((ahd
->bugs
& AHD_CLRLQO_AUTOCLR_BUG
) != 0)
1578 ahd_outb(ahd
, CLRLQOINT1
, 0);
1579 } else if ((status
& SELTO
) != 0) {
1582 /* Stop the selection */
1583 ahd_outb(ahd
, SCSISEQ0
, 0);
1585 /* Make sure the sequencer is in a safe location. */
1586 ahd_clear_critical_section(ahd
);
1588 /* No more pending messages */
1589 ahd_clear_msg_state(ahd
);
1591 /* Clear interrupt state */
1592 ahd_outb(ahd
, CLRSINT1
, CLRSELTIMEO
|CLRBUSFREE
|CLRSCSIPERR
);
1595 * Although the driver does not care about the
1596 * 'Selection in Progress' status bit, the busy
1597 * LED does. SELINGO is only cleared by a sucessfull
1598 * selection, so we must manually clear it to insure
1599 * the LED turns off just incase no future successful
1600 * selections occur (e.g. no devices on the bus).
1602 ahd_outb(ahd
, CLRSINT0
, CLRSELINGO
);
1604 scbid
= ahd_inw(ahd
, WAITING_TID_HEAD
);
1605 scb
= ahd_lookup_scb(ahd
, scbid
);
1607 printf("%s: ahd_intr - referenced scb not "
1608 "valid during SELTO scb(0x%x)\n",
1609 ahd_name(ahd
), scbid
);
1610 ahd_dump_card_state(ahd
);
1612 struct ahd_devinfo devinfo
;
1614 if ((ahd_debug
& AHD_SHOW_SELTO
) != 0) {
1615 ahd_print_path(ahd
, scb
);
1616 printf("Saw Selection Timeout for SCB 0x%x\n",
1620 ahd_scb_devinfo(ahd
, &devinfo
, scb
);
1621 ahd_set_transaction_status(scb
, CAM_SEL_TIMEOUT
);
1622 ahd_freeze_devq(ahd
, scb
);
1625 * Cancel any pending transactions on the device
1626 * now that it seems to be missing. This will
1627 * also revert us to async/narrow transfers until
1628 * we can renegotiate with the device.
1630 ahd_handle_devreset(ahd
, &devinfo
,
1633 "Selection Timeout",
1634 /*verbose_level*/1);
1636 ahd_outb(ahd
, CLRINT
, CLRSCSIINT
);
1637 ahd_iocell_first_selection(ahd
);
1639 } else if ((status0
& (SELDI
|SELDO
)) != 0) {
1641 ahd_iocell_first_selection(ahd
);
1643 } else if (status3
!= 0) {
1644 printf("%s: SCSI Cell parity error SSTAT3 == 0x%x\n",
1645 ahd_name(ahd
), status3
);
1646 ahd_outb(ahd
, CLRSINT3
, status3
);
1647 } else if ((lqistat1
& (LQIPHASE_LQ
|LQIPHASE_NLQ
)) != 0) {
1649 /* Make sure the sequencer is in a safe location. */
1650 ahd_clear_critical_section(ahd
);
1652 ahd_handle_lqiphase_error(ahd
, lqistat1
);
1653 } else if ((lqistat1
& LQICRCI_NLQ
) != 0) {
1655 * This status can be delayed during some
1656 * streaming operations. The SCSIPHASE
1657 * handler has already dealt with this case
1658 * so just clear the error.
1660 ahd_outb(ahd
, CLRLQIINT1
, CLRLQICRCI_NLQ
);
1661 } else if ((status
& BUSFREE
) != 0
1662 || (lqistat1
& LQOBUSFREE
) != 0) {
1670 * Clear our selection hardware as soon as possible.
1671 * We may have an entry in the waiting Q for this target,
1672 * that is affected by this busfree and we don't want to
1673 * go about selecting the target while we handle the event.
1675 ahd_outb(ahd
, SCSISEQ0
, 0);
1677 /* Make sure the sequencer is in a safe location. */
1678 ahd_clear_critical_section(ahd
);
1681 * Determine what we were up to at the time of
1684 mode
= AHD_MODE_SCSI
;
1685 busfreetime
= ahd_inb(ahd
, SSTAT2
) & BUSFREETIME
;
1686 lqostat1
= ahd_inb(ahd
, LQOSTAT1
);
1687 switch (busfreetime
) {
1694 mode
= busfreetime
== BUSFREE_DFF0
1695 ? AHD_MODE_DFF0
: AHD_MODE_DFF1
;
1696 ahd_set_modes(ahd
, mode
, mode
);
1697 scbid
= ahd_get_scbptr(ahd
);
1698 scb
= ahd_lookup_scb(ahd
, scbid
);
1700 printf("%s: Invalid SCB %d in DFF%d "
1701 "during unexpected busfree\n",
1702 ahd_name(ahd
), scbid
, mode
);
1705 packetized
= (scb
->flags
& SCB_PACKETIZED
) != 0;
1715 packetized
= (lqostat1
& LQOBUSFREE
) != 0;
1717 && ahd_inb(ahd
, LASTPHASE
) == P_BUSFREE
1718 && (ahd_inb(ahd
, SSTAT0
) & SELDI
) == 0
1719 && ((ahd_inb(ahd
, SSTAT0
) & SELDO
) == 0
1720 || (ahd_inb(ahd
, SCSISEQ0
) & ENSELO
) == 0))
1722 * Assume packetized if we are not
1723 * on the bus in a non-packetized
1724 * capacity and any pending selection
1725 * was a packetized selection.
1732 if ((ahd_debug
& AHD_SHOW_MISC
) != 0)
1733 printf("Saw Busfree. Busfreetime = 0x%x.\n",
1737 * Busfrees that occur in non-packetized phases are
1738 * handled by the nonpkt_busfree handler.
1740 if (packetized
&& ahd_inb(ahd
, LASTPHASE
) == P_BUSFREE
) {
1741 restart
= ahd_handle_pkt_busfree(ahd
, busfreetime
);
1744 restart
= ahd_handle_nonpkt_busfree(ahd
);
1747 * Clear the busfree interrupt status. The setting of
1748 * the interrupt is a pulse, so in a perfect world, we
1749 * would not need to muck with the ENBUSFREE logic. This
1750 * would ensure that if the bus moves on to another
1751 * connection, busfree protection is still in force. If
1752 * BUSFREEREV is broken, however, we must manually clear
1753 * the ENBUSFREE if the busfree occurred during a non-pack
1754 * connection so that we don't get false positives during
1755 * future, packetized, connections.
1757 ahd_outb(ahd
, CLRSINT1
, CLRBUSFREE
);
1759 && (ahd
->bugs
& AHD_BUSFREEREV_BUG
) != 0)
1760 ahd_outb(ahd
, SIMODE1
,
1761 ahd_inb(ahd
, SIMODE1
) & ~ENBUSFREE
);
1764 ahd_clear_fifo(ahd
, mode
);
1766 ahd_clear_msg_state(ahd
);
1767 ahd_outb(ahd
, CLRINT
, CLRSCSIINT
);
1774 printf("%s: Missing case in ahd_handle_scsiint. status = %x\n",
1775 ahd_name(ahd
), status
);
1776 ahd_dump_card_state(ahd
);
1777 ahd_clear_intstat(ahd
);
1783 ahd_handle_transmission_error(struct ahd_softc
*ahd
)
1797 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
1798 lqistat1
= ahd_inb(ahd
, LQISTAT1
) & ~(LQIPHASE_LQ
|LQIPHASE_NLQ
);
1799 lqistat2
= ahd_inb(ahd
, LQISTAT2
);
1800 if ((lqistat1
& (LQICRCI_NLQ
|LQICRCI_LQ
)) == 0
1801 && (ahd
->bugs
& AHD_NLQICRC_DELAYED_BUG
) != 0) {
1804 ahd_set_modes(ahd
, AHD_MODE_CFG
, AHD_MODE_CFG
);
1805 lqistate
= ahd_inb(ahd
, LQISTATE
);
1806 if ((lqistate
>= 0x1E && lqistate
<= 0x24)
1807 || (lqistate
== 0x29)) {
1809 if ((ahd_debug
& AHD_SHOW_RECOVERY
) != 0) {
1810 printf("%s: NLQCRC found via LQISTATE\n",
1814 lqistat1
|= LQICRCI_NLQ
;
1816 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
1819 ahd_outb(ahd
, CLRLQIINT1
, lqistat1
);
1820 lastphase
= ahd_inb(ahd
, LASTPHASE
);
1821 curphase
= ahd_inb(ahd
, SCSISIGI
) & PHASE_MASK
;
1822 perrdiag
= ahd_inb(ahd
, PERRDIAG
);
1823 msg_out
= MSG_INITIATOR_DET_ERR
;
1824 ahd_outb(ahd
, CLRSINT1
, CLRSCSIPERR
);
1827 * Try to find the SCB associated with this error.
1831 || (lqistat1
& LQICRCI_NLQ
) != 0) {
1832 if ((lqistat1
& (LQICRCI_NLQ
|LQIOVERI_NLQ
)) != 0)
1833 ahd_set_active_fifo(ahd
);
1834 scbid
= ahd_get_scbptr(ahd
);
1835 scb
= ahd_lookup_scb(ahd
, scbid
);
1836 if (scb
!= NULL
&& SCB_IS_SILENT(scb
))
1841 if (silent
== FALSE
) {
1842 printf("%s: Transmission error detected\n", ahd_name(ahd
));
1843 ahd_lqistat1_print(lqistat1
, &cur_col
, 50);
1844 ahd_lastphase_print(lastphase
, &cur_col
, 50);
1845 ahd_scsisigi_print(curphase
, &cur_col
, 50);
1846 ahd_perrdiag_print(perrdiag
, &cur_col
, 50);
1848 ahd_dump_card_state(ahd
);
1851 if ((lqistat1
& (LQIOVERI_LQ
|LQIOVERI_NLQ
)) != 0) {
1852 if (silent
== FALSE
) {
1853 printf("%s: Gross protocol error during incoming "
1854 "packet. lqistat1 == 0x%x. Resetting bus.\n",
1855 ahd_name(ahd
), lqistat1
);
1857 ahd_reset_channel(ahd
, 'A', /*Initiate Reset*/TRUE
);
1859 } else if ((lqistat1
& LQICRCI_LQ
) != 0) {
1861 * A CRC error has been detected on an incoming LQ.
1862 * The bus is currently hung on the last ACK.
1863 * Hit LQIRETRY to release the last ack, and
1864 * wait for the sequencer to determine that ATNO
1865 * is asserted while in message out to take us
1866 * to our host message loop. No NONPACKREQ or
1867 * LQIPHASE type errors will occur in this
1868 * scenario. After this first LQIRETRY, the LQI
1869 * manager will be in ISELO where it will
1870 * happily sit until another packet phase begins.
1871 * Unexpected bus free detection is enabled
1872 * through any phases that occur after we release
1873 * this last ack until the LQI manager sees a
1874 * packet phase. This implies we may have to
1875 * ignore a perfectly valid "unexected busfree"
1876 * after our "initiator detected error" message is
1877 * sent. A busfree is the expected response after
1878 * we tell the target that it's L_Q was corrupted.
1879 * (SPI4R09 10.7.3.3.3)
1881 ahd_outb(ahd
, LQCTL2
, LQIRETRY
);
1882 printf("LQIRetry for LQICRCI_LQ to release ACK\n");
1883 } else if ((lqistat1
& LQICRCI_NLQ
) != 0) {
1885 * We detected a CRC error in a NON-LQ packet.
1886 * The hardware has varying behavior in this situation
1887 * depending on whether this packet was part of a
1891 * The hardware has already acked the complete packet.
1892 * If the target honors our outstanding ATN condition,
1893 * we should be (or soon will be) in MSGOUT phase.
1894 * This will trigger the LQIPHASE_LQ status bit as the
1895 * hardware was expecting another LQ. Unexpected
1896 * busfree detection is enabled. Once LQIPHASE_LQ is
1897 * true (first entry into host message loop is much
1898 * the same), we must clear LQIPHASE_LQ and hit
1899 * LQIRETRY so the hardware is ready to handle
1900 * a future LQ. NONPACKREQ will not be asserted again
1901 * once we hit LQIRETRY until another packet is
1902 * processed. The target may either go busfree
1903 * or start another packet in response to our message.
1905 * Read Streaming P0 asserted:
1906 * If we raise ATN and the target completes the entire
1907 * stream (P0 asserted during the last packet), the
1908 * hardware will ack all data and return to the ISTART
1909 * state. When the target reponds to our ATN condition,
1910 * LQIPHASE_LQ will be asserted. We should respond to
1911 * this with an LQIRETRY to prepare for any future
1912 * packets. NONPACKREQ will not be asserted again
1913 * once we hit LQIRETRY until another packet is
1914 * processed. The target may either go busfree or
1915 * start another packet in response to our message.
1916 * Busfree detection is enabled.
1918 * Read Streaming P0 not asserted:
1919 * If we raise ATN and the target transitions to
1920 * MSGOUT in or after a packet where P0 is not
1921 * asserted, the hardware will assert LQIPHASE_NLQ.
1922 * We should respond to the LQIPHASE_NLQ with an
1923 * LQIRETRY. Should the target stay in a non-pkt
1924 * phase after we send our message, the hardware
1925 * will assert LQIPHASE_LQ. Recovery is then just as
1926 * listed above for the read streaming with P0 asserted.
1927 * Busfree detection is enabled.
1929 if (silent
== FALSE
)
1930 printf("LQICRC_NLQ\n");
1932 printf("%s: No SCB valid for LQICRC_NLQ. "
1933 "Resetting bus\n", ahd_name(ahd
));
1934 ahd_reset_channel(ahd
, 'A', /*Initiate Reset*/TRUE
);
1937 } else if ((lqistat1
& LQIBADLQI
) != 0) {
1938 printf("Need to handle BADLQI!\n");
1939 ahd_reset_channel(ahd
, 'A', /*Initiate Reset*/TRUE
);
1941 } else if ((perrdiag
& (PARITYERR
|PREVPHASE
)) == PARITYERR
) {
1942 if ((curphase
& ~P_DATAIN_DT
) != 0) {
1943 /* Ack the byte. So we can continue. */
1944 if (silent
== FALSE
)
1945 printf("Acking %s to clear perror\n",
1946 ahd_lookup_phase_entry(curphase
)->phasemsg
);
1947 ahd_inb(ahd
, SCSIDAT
);
1950 if (curphase
== P_MESGIN
)
1951 msg_out
= MSG_PARITY_ERROR
;
1955 * We've set the hardware to assert ATN if we
1956 * get a parity error on "in" phases, so all we
1957 * need to do is stuff the message buffer with
1958 * the appropriate message. "In" phases have set
1959 * mesg_out to something other than MSG_NOP.
1961 ahd
->send_msg_perror
= msg_out
;
1962 if (scb
!= NULL
&& msg_out
== MSG_INITIATOR_DET_ERR
)
1963 scb
->flags
|= SCB_TRANSMISSION_ERROR
;
1964 ahd_outb(ahd
, MSG_OUT
, HOST_MSG
);
1965 ahd_outb(ahd
, CLRINT
, CLRSCSIINT
);
1970 ahd_handle_lqiphase_error(struct ahd_softc
*ahd
, u_int lqistat1
)
1973 * Clear the sources of the interrupts.
1975 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
1976 ahd_outb(ahd
, CLRLQIINT1
, lqistat1
);
1979 * If the "illegal" phase changes were in response
1980 * to our ATN to flag a CRC error, AND we ended up
1981 * on packet boundaries, clear the error, restart the
1982 * LQI manager as appropriate, and go on our merry
1983 * way toward sending the message. Otherwise, reset
1984 * the bus to clear the error.
1986 ahd_set_active_fifo(ahd
);
1987 if ((ahd_inb(ahd
, SCSISIGO
) & ATNO
) != 0
1988 && (ahd_inb(ahd
, MDFFSTAT
) & DLZERO
) != 0) {
1989 if ((lqistat1
& LQIPHASE_LQ
) != 0) {
1990 printf("LQIRETRY for LQIPHASE_LQ\n");
1991 ahd_outb(ahd
, LQCTL2
, LQIRETRY
);
1992 } else if ((lqistat1
& LQIPHASE_NLQ
) != 0) {
1993 printf("LQIRETRY for LQIPHASE_NLQ\n");
1994 ahd_outb(ahd
, LQCTL2
, LQIRETRY
);
1996 panic("ahd_handle_lqiphase_error: No phase errors\n");
1997 ahd_dump_card_state(ahd
);
1998 ahd_outb(ahd
, CLRINT
, CLRSCSIINT
);
2001 printf("Reseting Channel for LQI Phase error\n");
2002 ahd_dump_card_state(ahd
);
2003 ahd_reset_channel(ahd
, 'A', /*Initiate Reset*/TRUE
);
2008 * Packetized unexpected or expected busfree.
2009 * Entered in mode based on busfreetime.
2012 ahd_handle_pkt_busfree(struct ahd_softc
*ahd
, u_int busfreetime
)
2016 AHD_ASSERT_MODES(ahd
, ~(AHD_MODE_UNKNOWN_MSK
|AHD_MODE_CFG_MSK
),
2017 ~(AHD_MODE_UNKNOWN_MSK
|AHD_MODE_CFG_MSK
));
2018 lqostat1
= ahd_inb(ahd
, LQOSTAT1
);
2019 if ((lqostat1
& LQOBUSFREE
) != 0) {
2028 * The LQO manager detected an unexpected busfree
2031 * 1) During an outgoing LQ.
2032 * 2) After an outgoing LQ but before the first
2033 * REQ of the command packet.
2034 * 3) During an outgoing command packet.
2036 * In all cases, CURRSCB is pointing to the
2037 * SCB that encountered the failure. Clean
2038 * up the queue, clear SELDO and LQOBUSFREE,
2039 * and allow the sequencer to restart the select
2040 * out at its lesure.
2042 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
2043 scbid
= ahd_inw(ahd
, CURRSCB
);
2044 scb
= ahd_lookup_scb(ahd
, scbid
);
2046 panic("SCB not valid during LQOBUSFREE");
2050 ahd_outb(ahd
, CLRLQOINT1
, CLRLQOBUSFREE
);
2051 if ((ahd
->bugs
& AHD_CLRLQO_AUTOCLR_BUG
) != 0)
2052 ahd_outb(ahd
, CLRLQOINT1
, 0);
2053 ahd_outb(ahd
, SCSISEQ0
, ahd_inb(ahd
, SCSISEQ0
) & ~ENSELO
);
2054 ahd_flush_device_writes(ahd
);
2055 ahd_outb(ahd
, CLRSINT0
, CLRSELDO
);
2058 * Return the LQO manager to its idle loop. It will
2059 * not do this automatically if the busfree occurs
2060 * after the first REQ of either the LQ or command
2061 * packet or between the LQ and command packet.
2063 ahd_outb(ahd
, LQCTL2
, ahd_inb(ahd
, LQCTL2
) | LQOTOIDLE
);
2066 * Update the waiting for selection queue so
2067 * we restart on the correct SCB.
2069 waiting_h
= ahd_inw(ahd
, WAITING_TID_HEAD
);
2070 saved_scbptr
= ahd_get_scbptr(ahd
);
2071 if (waiting_h
!= scbid
) {
2073 ahd_outw(ahd
, WAITING_TID_HEAD
, scbid
);
2074 waiting_t
= ahd_inw(ahd
, WAITING_TID_TAIL
);
2075 if (waiting_t
== waiting_h
) {
2076 ahd_outw(ahd
, WAITING_TID_TAIL
, scbid
);
2077 next
= SCB_LIST_NULL
;
2079 ahd_set_scbptr(ahd
, waiting_h
);
2080 next
= ahd_inw_scbram(ahd
, SCB_NEXT2
);
2082 ahd_set_scbptr(ahd
, scbid
);
2083 ahd_outw(ahd
, SCB_NEXT2
, next
);
2085 ahd_set_scbptr(ahd
, saved_scbptr
);
2086 if (scb
->crc_retry_count
< AHD_MAX_LQ_CRC_ERRORS
) {
2087 if (SCB_IS_SILENT(scb
) == FALSE
) {
2088 ahd_print_path(ahd
, scb
);
2089 printf("Probable outgoing LQ CRC error. "
2090 "Retrying command\n");
2092 scb
->crc_retry_count
++;
2094 ahd_set_transaction_status(scb
, CAM_UNCOR_PARITY
);
2095 ahd_freeze_scb(scb
);
2096 ahd_freeze_devq(ahd
, scb
);
2098 /* Return unpausing the sequencer. */
2100 } else if ((ahd_inb(ahd
, PERRDIAG
) & PARITYERR
) != 0) {
2102 * Ignore what are really parity errors that
2103 * occur on the last REQ of a free running
2104 * clock prior to going busfree. Some drives
2105 * do not properly active negate just before
2106 * going busfree resulting in a parity glitch.
2108 ahd_outb(ahd
, CLRSINT1
, CLRSCSIPERR
|CLRBUSFREE
);
2110 if ((ahd_debug
& AHD_SHOW_MASKED_ERRORS
) != 0)
2111 printf("%s: Parity on last REQ detected "
2112 "during busfree phase.\n",
2115 /* Return unpausing the sequencer. */
2118 if (ahd
->src_mode
!= AHD_MODE_SCSI
) {
2122 scbid
= ahd_get_scbptr(ahd
);
2123 scb
= ahd_lookup_scb(ahd
, scbid
);
2124 ahd_print_path(ahd
, scb
);
2125 printf("Unexpected PKT busfree condition\n");
2126 ahd_dump_card_state(ahd
);
2127 ahd_abort_scbs(ahd
, SCB_GET_TARGET(ahd
, scb
), 'A',
2128 SCB_GET_LUN(scb
), SCB_GET_TAG(scb
),
2129 ROLE_INITIATOR
, CAM_UNEXP_BUSFREE
);
2131 /* Return restarting the sequencer. */
2134 printf("%s: Unexpected PKT busfree condition\n", ahd_name(ahd
));
2135 ahd_dump_card_state(ahd
);
2136 /* Restart the sequencer. */
2141 * Non-packetized unexpected or expected busfree.
2144 ahd_handle_nonpkt_busfree(struct ahd_softc
*ahd
)
2146 struct ahd_devinfo devinfo
;
2152 u_int initiator_role_id
;
2158 * Look at what phase we were last in. If its message out,
2159 * chances are pretty good that the busfree was in response
2160 * to one of our abort requests.
2162 lastphase
= ahd_inb(ahd
, LASTPHASE
);
2163 saved_scsiid
= ahd_inb(ahd
, SAVED_SCSIID
);
2164 saved_lun
= ahd_inb(ahd
, SAVED_LUN
);
2165 target
= SCSIID_TARGET(ahd
, saved_scsiid
);
2166 initiator_role_id
= SCSIID_OUR_ID(saved_scsiid
);
2167 ahd_compile_devinfo(&devinfo
, initiator_role_id
,
2168 target
, saved_lun
, 'A', ROLE_INITIATOR
);
2171 scbid
= ahd_get_scbptr(ahd
);
2172 scb
= ahd_lookup_scb(ahd
, scbid
);
2174 && (ahd_inb(ahd
, SEQ_FLAGS
) & NOT_IDENTIFIED
) != 0)
2177 ppr_busfree
= (ahd
->msg_flags
& MSG_FLAG_EXPECT_PPR_BUSFREE
) != 0;
2178 if (lastphase
== P_MESGOUT
) {
2181 tag
= SCB_LIST_NULL
;
2182 if (ahd_sent_msg(ahd
, AHDMSG_1B
, MSG_ABORT_TAG
, TRUE
)
2183 || ahd_sent_msg(ahd
, AHDMSG_1B
, MSG_ABORT
, TRUE
)) {
2188 ahd_print_devinfo(ahd
, &devinfo
);
2189 printf("Abort for unidentified "
2190 "connection completed.\n");
2191 /* restart the sequencer. */
2194 sent_msg
= ahd
->msgout_buf
[ahd
->msgout_index
- 1];
2195 ahd_print_path(ahd
, scb
);
2196 printf("SCB %d - Abort%s Completed.\n",
2198 sent_msg
== MSG_ABORT_TAG
? "" : " Tag");
2200 if (sent_msg
== MSG_ABORT_TAG
)
2201 tag
= SCB_GET_TAG(scb
);
2203 found
= ahd_abort_scbs(ahd
, target
, 'A', saved_lun
,
2204 tag
, ROLE_INITIATOR
,
2206 printf("found == 0x%x\n", found
);
2208 } else if (ahd_sent_msg(ahd
, AHDMSG_1B
,
2209 MSG_BUS_DEV_RESET
, TRUE
)) {
2212 * Don't mark the user's request for this BDR
2213 * as completing with CAM_BDR_SENT. CAM3
2214 * specifies CAM_REQ_CMP.
2217 && scb
->io_ctx
->ccb_h
.func_code
== XPT_RESET_DEV
2218 && ahd_match_scb(ahd
, scb
, target
, 'A',
2219 CAM_LUN_WILDCARD
, SCB_LIST_NULL
,
2221 ahd_set_transaction_status(scb
, CAM_REQ_CMP
);
2223 ahd_handle_devreset(ahd
, &devinfo
, CAM_LUN_WILDCARD
,
2224 CAM_BDR_SENT
, "Bus Device Reset",
2225 /*verbose_level*/0);
2227 } else if (ahd_sent_msg(ahd
, AHDMSG_EXT
, MSG_EXT_PPR
, FALSE
)
2228 && ppr_busfree
== 0) {
2229 struct ahd_initiator_tinfo
*tinfo
;
2230 struct ahd_tmode_tstate
*tstate
;
2235 * If the previous negotiation was packetized,
2236 * this could be because the device has been
2237 * reset without our knowledge. Force our
2238 * current negotiation to async and retry the
2239 * negotiation. Otherwise retry the command
2240 * with non-ppr negotiation.
2243 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
2244 printf("PPR negotiation rejected busfree.\n");
2246 tinfo
= ahd_fetch_transinfo(ahd
, devinfo
.channel
,
2248 devinfo
.target
, &tstate
);
2249 if ((tinfo
->curr
.ppr_options
& MSG_EXT_PPR_IU_REQ
)!=0) {
2250 ahd_set_width(ahd
, &devinfo
,
2251 MSG_EXT_WDTR_BUS_8_BIT
,
2254 ahd_set_syncrate(ahd
, &devinfo
,
2255 /*period*/0, /*offset*/0,
2260 * The expect PPR busfree handler below
2261 * will effect the retry and necessary
2265 tinfo
->curr
.transport_version
= 2;
2266 tinfo
->goal
.transport_version
= 2;
2267 tinfo
->goal
.ppr_options
= 0;
2269 * Remove any SCBs in the waiting for selection
2270 * queue that may also be for this target so
2271 * that command ordering is preserved.
2273 ahd_freeze_devq(ahd
, scb
);
2274 ahd_qinfifo_requeue_tail(ahd
, scb
);
2277 } else if (ahd_sent_msg(ahd
, AHDMSG_EXT
, MSG_EXT_WDTR
, FALSE
)
2278 && ppr_busfree
== 0) {
2280 * Negotiation Rejected. Go-narrow and
2284 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
2285 printf("WDTR negotiation rejected busfree.\n");
2287 ahd_set_width(ahd
, &devinfo
,
2288 MSG_EXT_WDTR_BUS_8_BIT
,
2289 AHD_TRANS_CUR
|AHD_TRANS_GOAL
,
2292 * Remove any SCBs in the waiting for selection
2293 * queue that may also be for this target so that
2294 * command ordering is preserved.
2296 ahd_freeze_devq(ahd
, scb
);
2297 ahd_qinfifo_requeue_tail(ahd
, scb
);
2299 } else if (ahd_sent_msg(ahd
, AHDMSG_EXT
, MSG_EXT_SDTR
, FALSE
)
2300 && ppr_busfree
== 0) {
2302 * Negotiation Rejected. Go-async and
2306 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
2307 printf("SDTR negotiation rejected busfree.\n");
2309 ahd_set_syncrate(ahd
, &devinfo
,
2310 /*period*/0, /*offset*/0,
2312 AHD_TRANS_CUR
|AHD_TRANS_GOAL
,
2315 * Remove any SCBs in the waiting for selection
2316 * queue that may also be for this target so that
2317 * command ordering is preserved.
2319 ahd_freeze_devq(ahd
, scb
);
2320 ahd_qinfifo_requeue_tail(ahd
, scb
);
2322 } else if ((ahd
->msg_flags
& MSG_FLAG_EXPECT_IDE_BUSFREE
) != 0
2323 && ahd_sent_msg(ahd
, AHDMSG_1B
,
2324 MSG_INITIATOR_DET_ERR
, TRUE
)) {
2327 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
2328 printf("Expected IDE Busfree\n");
2331 } else if ((ahd
->msg_flags
& MSG_FLAG_EXPECT_QASREJ_BUSFREE
)
2332 && ahd_sent_msg(ahd
, AHDMSG_1B
,
2333 MSG_MESSAGE_REJECT
, TRUE
)) {
2336 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
2337 printf("Expected QAS Reject Busfree\n");
2344 * The busfree required flag is honored at the end of
2345 * the message phases. We check it last in case we
2346 * had to send some other message that caused a busfree.
2349 && (lastphase
== P_MESGIN
|| lastphase
== P_MESGOUT
)
2350 && ((ahd
->msg_flags
& MSG_FLAG_EXPECT_PPR_BUSFREE
) != 0)) {
2352 ahd_freeze_devq(ahd
, scb
);
2353 ahd_set_transaction_status(scb
, CAM_REQUEUE_REQ
);
2354 ahd_freeze_scb(scb
);
2355 if ((ahd
->msg_flags
& MSG_FLAG_IU_REQ_CHANGED
) != 0) {
2356 ahd_abort_scbs(ahd
, SCB_GET_TARGET(ahd
, scb
),
2357 SCB_GET_CHANNEL(ahd
, scb
),
2358 SCB_GET_LUN(scb
), SCB_LIST_NULL
,
2359 ROLE_INITIATOR
, CAM_REQ_ABORTED
);
2362 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
2363 printf("PPR Negotiation Busfree.\n");
2369 if (printerror
!= 0) {
2376 if ((scb
->hscb
->control
& TAG_ENB
) != 0)
2377 tag
= SCB_GET_TAG(scb
);
2379 tag
= SCB_LIST_NULL
;
2380 ahd_print_path(ahd
, scb
);
2381 aborted
= ahd_abort_scbs(ahd
, target
, 'A',
2382 SCB_GET_LUN(scb
), tag
,
2387 * We had not fully identified this connection,
2388 * so we cannot abort anything.
2390 printf("%s: ", ahd_name(ahd
));
2392 printf("Unexpected busfree %s, %d SCBs aborted, "
2393 "PRGMCNT == 0x%x\n",
2394 ahd_lookup_phase_entry(lastphase
)->phasemsg
,
2396 ahd_inw(ahd
, PRGMCNT
));
2397 ahd_dump_card_state(ahd
);
2398 if (lastphase
!= P_BUSFREE
)
2399 ahd_force_renegotiation(ahd
, &devinfo
);
2401 /* Always restart the sequencer. */
2406 ahd_handle_proto_violation(struct ahd_softc
*ahd
)
2408 struct ahd_devinfo devinfo
;
2416 ahd_fetch_devinfo(ahd
, &devinfo
);
2417 scbid
= ahd_get_scbptr(ahd
);
2418 scb
= ahd_lookup_scb(ahd
, scbid
);
2419 seq_flags
= ahd_inb(ahd
, SEQ_FLAGS
);
2420 curphase
= ahd_inb(ahd
, SCSISIGI
) & PHASE_MASK
;
2421 lastphase
= ahd_inb(ahd
, LASTPHASE
);
2422 if ((seq_flags
& NOT_IDENTIFIED
) != 0) {
2425 * The reconnecting target either did not send an
2426 * identify message, or did, but we didn't find an SCB
2429 ahd_print_devinfo(ahd
, &devinfo
);
2430 printf("Target did not send an IDENTIFY message. "
2431 "LASTPHASE = 0x%x.\n", lastphase
);
2433 } else if (scb
== NULL
) {
2435 * We don't seem to have an SCB active for this
2436 * transaction. Print an error and reset the bus.
2438 ahd_print_devinfo(ahd
, &devinfo
);
2439 printf("No SCB found during protocol violation\n");
2440 goto proto_violation_reset
;
2442 ahd_set_transaction_status(scb
, CAM_SEQUENCE_FAIL
);
2443 if ((seq_flags
& NO_CDB_SENT
) != 0) {
2444 ahd_print_path(ahd
, scb
);
2445 printf("No or incomplete CDB sent to device.\n");
2446 } else if ((ahd_inb_scbram(ahd
, SCB_CONTROL
)
2447 & STATUS_RCVD
) == 0) {
2449 * The target never bothered to provide status to
2450 * us prior to completing the command. Since we don't
2451 * know the disposition of this command, we must attempt
2452 * to abort it. Assert ATN and prepare to send an abort
2455 ahd_print_path(ahd
, scb
);
2456 printf("Completed command without status.\n");
2458 ahd_print_path(ahd
, scb
);
2459 printf("Unknown protocol violation.\n");
2460 ahd_dump_card_state(ahd
);
2463 if ((lastphase
& ~P_DATAIN_DT
) == 0
2464 || lastphase
== P_COMMAND
) {
2465 proto_violation_reset
:
2467 * Target either went directly to data
2468 * phase or didn't respond to our ATN.
2469 * The only safe thing to do is to blow
2470 * it away with a bus reset.
2472 found
= ahd_reset_channel(ahd
, 'A', TRUE
);
2473 printf("%s: Issued Channel %c Bus Reset. "
2474 "%d SCBs aborted\n", ahd_name(ahd
), 'A', found
);
2477 * Leave the selection hardware off in case
2478 * this abort attempt will affect yet to
2481 ahd_outb(ahd
, SCSISEQ0
,
2482 ahd_inb(ahd
, SCSISEQ0
) & ~ENSELO
);
2483 ahd_assert_atn(ahd
);
2484 ahd_outb(ahd
, MSG_OUT
, HOST_MSG
);
2486 ahd_print_devinfo(ahd
, &devinfo
);
2487 ahd
->msgout_buf
[0] = MSG_ABORT_TASK
;
2488 ahd
->msgout_len
= 1;
2489 ahd
->msgout_index
= 0;
2490 ahd
->msg_type
= MSG_TYPE_INITIATOR_MSGOUT
;
2492 ahd_print_path(ahd
, scb
);
2493 scb
->flags
|= SCB_ABORT
;
2495 printf("Protocol violation %s. Attempting to abort.\n",
2496 ahd_lookup_phase_entry(curphase
)->phasemsg
);
2501 * Force renegotiation to occur the next time we initiate
2502 * a command to the current device.
2505 ahd_force_renegotiation(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
)
2507 struct ahd_initiator_tinfo
*targ_info
;
2508 struct ahd_tmode_tstate
*tstate
;
2511 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0) {
2512 ahd_print_devinfo(ahd
, devinfo
);
2513 printf("Forcing renegotiation\n");
2516 targ_info
= ahd_fetch_transinfo(ahd
,
2518 devinfo
->our_scsiid
,
2521 ahd_update_neg_request(ahd
, devinfo
, tstate
,
2522 targ_info
, AHD_NEG_IF_NON_ASYNC
);
2525 #define AHD_MAX_STEPS 2000
2527 ahd_clear_critical_section(struct ahd_softc
*ahd
)
2529 ahd_mode_state saved_modes
;
2541 if (ahd
->num_critical_sections
== 0)
2554 saved_modes
= ahd_save_modes(ahd
);
2560 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
2561 seqaddr
= ahd_inw(ahd
, CURADDR
);
2563 cs
= ahd
->critical_sections
;
2564 for (i
= 0; i
< ahd
->num_critical_sections
; i
++, cs
++) {
2566 if (cs
->begin
< seqaddr
&& cs
->end
>= seqaddr
)
2570 if (i
== ahd
->num_critical_sections
)
2573 if (steps
> AHD_MAX_STEPS
) {
2574 printf("%s: Infinite loop in critical section\n"
2575 "%s: First Instruction 0x%x now 0x%x\n",
2576 ahd_name(ahd
), ahd_name(ahd
), first_instr
,
2578 ahd_dump_card_state(ahd
);
2579 panic("critical section loop");
2584 if ((ahd_debug
& AHD_SHOW_MISC
) != 0)
2585 printf("%s: Single stepping at 0x%x\n", ahd_name(ahd
),
2588 if (stepping
== FALSE
) {
2590 first_instr
= seqaddr
;
2591 ahd_set_modes(ahd
, AHD_MODE_CFG
, AHD_MODE_CFG
);
2592 simode0
= ahd_inb(ahd
, SIMODE0
);
2593 simode3
= ahd_inb(ahd
, SIMODE3
);
2594 lqimode0
= ahd_inb(ahd
, LQIMODE0
);
2595 lqimode1
= ahd_inb(ahd
, LQIMODE1
);
2596 lqomode0
= ahd_inb(ahd
, LQOMODE0
);
2597 lqomode1
= ahd_inb(ahd
, LQOMODE1
);
2598 ahd_outb(ahd
, SIMODE0
, 0);
2599 ahd_outb(ahd
, SIMODE3
, 0);
2600 ahd_outb(ahd
, LQIMODE0
, 0);
2601 ahd_outb(ahd
, LQIMODE1
, 0);
2602 ahd_outb(ahd
, LQOMODE0
, 0);
2603 ahd_outb(ahd
, LQOMODE1
, 0);
2604 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
2605 simode1
= ahd_inb(ahd
, SIMODE1
);
2607 * We don't clear ENBUSFREE. Unfortunately
2608 * we cannot re-enable busfree detection within
2609 * the current connection, so we must leave it
2610 * on while single stepping.
2612 ahd_outb(ahd
, SIMODE1
, simode1
& ENBUSFREE
);
2613 ahd_outb(ahd
, SEQCTL0
, ahd_inb(ahd
, SEQCTL0
) | STEP
);
2616 ahd_outb(ahd
, CLRSINT1
, CLRBUSFREE
);
2617 ahd_outb(ahd
, CLRINT
, CLRSCSIINT
);
2618 ahd_set_modes(ahd
, ahd
->saved_src_mode
, ahd
->saved_dst_mode
);
2619 ahd_outb(ahd
, HCNTRL
, ahd
->unpause
);
2620 while (!ahd_is_paused(ahd
))
2622 ahd_update_modes(ahd
);
2625 ahd_set_modes(ahd
, AHD_MODE_CFG
, AHD_MODE_CFG
);
2626 ahd_outb(ahd
, SIMODE0
, simode0
);
2627 ahd_outb(ahd
, SIMODE3
, simode3
);
2628 ahd_outb(ahd
, LQIMODE0
, lqimode0
);
2629 ahd_outb(ahd
, LQIMODE1
, lqimode1
);
2630 ahd_outb(ahd
, LQOMODE0
, lqomode0
);
2631 ahd_outb(ahd
, LQOMODE1
, lqomode1
);
2632 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
2633 ahd_outb(ahd
, SEQCTL0
, ahd_inb(ahd
, SEQCTL0
) & ~STEP
);
2634 ahd_outb(ahd
, SIMODE1
, simode1
);
2636 * SCSIINT seems to glitch occassionally when
2637 * the interrupt masks are restored. Clear SCSIINT
2638 * one more time so that only persistent errors
2639 * are seen as a real interrupt.
2641 ahd_outb(ahd
, CLRINT
, CLRSCSIINT
);
2643 ahd_restore_modes(ahd
, saved_modes
);
2647 * Clear any pending interrupt status.
2650 ahd_clear_intstat(struct ahd_softc
*ahd
)
2652 AHD_ASSERT_MODES(ahd
, ~(AHD_MODE_UNKNOWN_MSK
|AHD_MODE_CFG_MSK
),
2653 ~(AHD_MODE_UNKNOWN_MSK
|AHD_MODE_CFG_MSK
));
2654 /* Clear any interrupt conditions this may have caused */
2655 ahd_outb(ahd
, CLRLQIINT0
, CLRLQIATNQAS
|CLRLQICRCT1
|CLRLQICRCT2
2656 |CLRLQIBADLQT
|CLRLQIATNLQ
|CLRLQIATNCMD
);
2657 ahd_outb(ahd
, CLRLQIINT1
, CLRLQIPHASE_LQ
|CLRLQIPHASE_NLQ
|CLRLIQABORT
2658 |CLRLQICRCI_LQ
|CLRLQICRCI_NLQ
|CLRLQIBADLQI
2659 |CLRLQIOVERI_LQ
|CLRLQIOVERI_NLQ
|CLRNONPACKREQ
);
2660 ahd_outb(ahd
, CLRLQOINT0
, CLRLQOTARGSCBPERR
|CLRLQOSTOPT2
|CLRLQOATNLQ
2661 |CLRLQOATNPKT
|CLRLQOTCRC
);
2662 ahd_outb(ahd
, CLRLQOINT1
, CLRLQOINITSCBPERR
|CLRLQOSTOPI2
|CLRLQOBADQAS
2663 |CLRLQOBUSFREE
|CLRLQOPHACHGINPKT
);
2664 if ((ahd
->bugs
& AHD_CLRLQO_AUTOCLR_BUG
) != 0) {
2665 ahd_outb(ahd
, CLRLQOINT0
, 0);
2666 ahd_outb(ahd
, CLRLQOINT1
, 0);
2668 ahd_outb(ahd
, CLRSINT3
, CLRNTRAMPERR
|CLROSRAMPERR
);
2669 ahd_outb(ahd
, CLRSINT1
, CLRSELTIMEO
|CLRATNO
|CLRSCSIRSTI
2670 |CLRBUSFREE
|CLRSCSIPERR
|CLRREQINIT
);
2671 ahd_outb(ahd
, CLRSINT0
, CLRSELDO
|CLRSELDI
|CLRSELINGO
2672 |CLRIOERR
|CLROVERRUN
);
2673 ahd_outb(ahd
, CLRINT
, CLRSCSIINT
);
2676 /**************************** Debugging Routines ******************************/
2678 uint32_t ahd_debug
= AHD_DEBUG_OPTS
;
2681 ahd_print_scb(struct scb
*scb
)
2683 struct hardware_scb
*hscb
;
2687 printf("scb:%p control:0x%x scsiid:0x%x lun:%d cdb_len:%d\n",
2693 printf("Shared Data: ");
2694 for (i
= 0; i
< sizeof(hscb
->shared_data
.idata
.cdb
); i
++)
2695 printf("%#02x", hscb
->shared_data
.idata
.cdb
[i
]);
2696 printf(" dataptr:%#x%x datacnt:%#x sgptr:%#x tag:%#x\n",
2697 (uint32_t)((ahd_le64toh(hscb
->dataptr
) >> 32) & 0xFFFFFFFF),
2698 (uint32_t)(ahd_le64toh(hscb
->dataptr
) & 0xFFFFFFFF),
2699 ahd_le32toh(hscb
->datacnt
),
2700 ahd_le32toh(hscb
->sgptr
),
2702 ahd_dump_sglist(scb
);
2706 ahd_dump_sglist(struct scb
*scb
)
2710 if (scb
->sg_count
> 0) {
2711 if ((scb
->ahd_softc
->flags
& AHD_64BIT_ADDRESSING
) != 0) {
2712 struct ahd_dma64_seg
*sg_list
;
2714 sg_list
= (struct ahd_dma64_seg
*)scb
->sg_list
;
2715 for (i
= 0; i
< scb
->sg_count
; i
++) {
2719 addr
= ahd_le64toh(sg_list
[i
].addr
);
2720 len
= ahd_le32toh(sg_list
[i
].len
);
2721 printf("sg[%d] - Addr 0x%x%x : Length %d%s\n",
2723 (uint32_t)((addr
>> 32) & 0xFFFFFFFF),
2724 (uint32_t)(addr
& 0xFFFFFFFF),
2725 sg_list
[i
].len
& AHD_SG_LEN_MASK
,
2726 (sg_list
[i
].len
& AHD_DMA_LAST_SEG
)
2730 struct ahd_dma_seg
*sg_list
;
2732 sg_list
= (struct ahd_dma_seg
*)scb
->sg_list
;
2733 for (i
= 0; i
< scb
->sg_count
; i
++) {
2736 len
= ahd_le32toh(sg_list
[i
].len
);
2737 printf("sg[%d] - Addr 0x%x%x : Length %d%s\n",
2739 (len
& AHD_SG_HIGH_ADDR_MASK
) >> 24,
2740 ahd_le32toh(sg_list
[i
].addr
),
2741 len
& AHD_SG_LEN_MASK
,
2742 len
& AHD_DMA_LAST_SEG
? " Last" : "");
2748 /************************* Transfer Negotiation *******************************/
2750 * Allocate per target mode instance (ID we respond to as a target)
2751 * transfer negotiation data structures.
2753 static struct ahd_tmode_tstate
*
2754 ahd_alloc_tstate(struct ahd_softc
*ahd
, u_int scsi_id
, char channel
)
2756 struct ahd_tmode_tstate
*master_tstate
;
2757 struct ahd_tmode_tstate
*tstate
;
2760 master_tstate
= ahd
->enabled_targets
[ahd
->our_id
];
2761 if (ahd
->enabled_targets
[scsi_id
] != NULL
2762 && ahd
->enabled_targets
[scsi_id
] != master_tstate
)
2763 panic("%s: ahd_alloc_tstate - Target already allocated",
2765 tstate
= malloc(sizeof(*tstate
), M_DEVBUF
, M_NOWAIT
);
2770 * If we have allocated a master tstate, copy user settings from
2771 * the master tstate (taken from SRAM or the EEPROM) for this
2772 * channel, but reset our current and goal settings to async/narrow
2773 * until an initiator talks to us.
2775 if (master_tstate
!= NULL
) {
2776 memcpy(tstate
, master_tstate
, sizeof(*tstate
));
2777 memset(tstate
->enabled_luns
, 0, sizeof(tstate
->enabled_luns
));
2778 for (i
= 0; i
< 16; i
++) {
2779 memset(&tstate
->transinfo
[i
].curr
, 0,
2780 sizeof(tstate
->transinfo
[i
].curr
));
2781 memset(&tstate
->transinfo
[i
].goal
, 0,
2782 sizeof(tstate
->transinfo
[i
].goal
));
2785 memset(tstate
, 0, sizeof(*tstate
));
2786 ahd
->enabled_targets
[scsi_id
] = tstate
;
2790 #ifdef AHD_TARGET_MODE
2792 * Free per target mode instance (ID we respond to as a target)
2793 * transfer negotiation data structures.
2796 ahd_free_tstate(struct ahd_softc
*ahd
, u_int scsi_id
, char channel
, int force
)
2798 struct ahd_tmode_tstate
*tstate
;
2801 * Don't clean up our "master" tstate.
2802 * It has our default user settings.
2804 if (scsi_id
== ahd
->our_id
2808 tstate
= ahd
->enabled_targets
[scsi_id
];
2810 free(tstate
, M_DEVBUF
);
2811 ahd
->enabled_targets
[scsi_id
] = NULL
;
2816 * Called when we have an active connection to a target on the bus,
2817 * this function finds the nearest period to the input period limited
2818 * by the capabilities of the bus connectivity of and sync settings for
2822 ahd_devlimited_syncrate(struct ahd_softc
*ahd
,
2823 struct ahd_initiator_tinfo
*tinfo
,
2824 u_int
*period
, u_int
*ppr_options
, role_t role
)
2826 struct ahd_transinfo
*transinfo
;
2829 if ((ahd_inb(ahd
, SBLKCTL
) & ENAB40
) != 0
2830 && (ahd_inb(ahd
, SSTAT2
) & EXP_ACTIVE
) == 0) {
2831 maxsync
= AHD_SYNCRATE_PACED
;
2833 maxsync
= AHD_SYNCRATE_ULTRA
;
2834 /* Can't do DT related options on an SE bus */
2835 *ppr_options
&= MSG_EXT_PPR_QAS_REQ
;
2838 * Never allow a value higher than our current goal
2839 * period otherwise we may allow a target initiated
2840 * negotiation to go above the limit as set by the
2841 * user. In the case of an initiator initiated
2842 * sync negotiation, we limit based on the user
2843 * setting. This allows the system to still accept
2844 * incoming negotiations even if target initiated
2845 * negotiation is not performed.
2847 if (role
== ROLE_TARGET
)
2848 transinfo
= &tinfo
->user
;
2850 transinfo
= &tinfo
->goal
;
2851 *ppr_options
&= (transinfo
->ppr_options
|MSG_EXT_PPR_PCOMP_EN
);
2852 if (transinfo
->width
== MSG_EXT_WDTR_BUS_8_BIT
) {
2853 maxsync
= MAX(maxsync
, AHD_SYNCRATE_ULTRA2
);
2854 *ppr_options
&= ~MSG_EXT_PPR_DT_REQ
;
2856 if (transinfo
->period
== 0) {
2860 *period
= MAX(*period
, transinfo
->period
);
2861 ahd_find_syncrate(ahd
, period
, ppr_options
, maxsync
);
2866 * Look up the valid period to SCSIRATE conversion in our table.
2867 * Return the period and offset that should be sent to the target
2868 * if this was the beginning of an SDTR.
2871 ahd_find_syncrate(struct ahd_softc
*ahd
, u_int
*period
,
2872 u_int
*ppr_options
, u_int maxsync
)
2874 if (*period
< maxsync
)
2877 if ((*ppr_options
& MSG_EXT_PPR_DT_REQ
) != 0
2878 && *period
> AHD_SYNCRATE_MIN_DT
)
2879 *ppr_options
&= ~MSG_EXT_PPR_DT_REQ
;
2881 if (*period
> AHD_SYNCRATE_MIN
)
2884 /* Honor PPR option conformance rules. */
2885 if (*period
> AHD_SYNCRATE_PACED
)
2886 *ppr_options
&= ~MSG_EXT_PPR_RTI
;
2888 if ((*ppr_options
& MSG_EXT_PPR_IU_REQ
) == 0)
2889 *ppr_options
&= (MSG_EXT_PPR_DT_REQ
|MSG_EXT_PPR_QAS_REQ
);
2891 if ((*ppr_options
& MSG_EXT_PPR_DT_REQ
) == 0)
2892 *ppr_options
&= MSG_EXT_PPR_QAS_REQ
;
2894 /* Skip all PACED only entries if IU is not available */
2895 if ((*ppr_options
& MSG_EXT_PPR_IU_REQ
) == 0
2896 && *period
< AHD_SYNCRATE_DT
)
2897 *period
= AHD_SYNCRATE_DT
;
2899 /* Skip all DT only entries if DT is not available */
2900 if ((*ppr_options
& MSG_EXT_PPR_DT_REQ
) == 0
2901 && *period
< AHD_SYNCRATE_ULTRA2
)
2902 *period
= AHD_SYNCRATE_ULTRA2
;
2906 * Truncate the given synchronous offset to a value the
2907 * current adapter type and syncrate are capable of.
2910 ahd_validate_offset(struct ahd_softc
*ahd
,
2911 struct ahd_initiator_tinfo
*tinfo
,
2912 u_int period
, u_int
*offset
, int wide
,
2917 /* Limit offset to what we can do */
2920 else if (period
<= AHD_SYNCRATE_PACED
) {
2921 if ((ahd
->bugs
& AHD_PACED_NEGTABLE_BUG
) != 0)
2922 maxoffset
= MAX_OFFSET_PACED_BUG
;
2924 maxoffset
= MAX_OFFSET_PACED
;
2926 maxoffset
= MAX_OFFSET_NON_PACED
;
2927 *offset
= MIN(*offset
, maxoffset
);
2928 if (tinfo
!= NULL
) {
2929 if (role
== ROLE_TARGET
)
2930 *offset
= MIN(*offset
, tinfo
->user
.offset
);
2932 *offset
= MIN(*offset
, tinfo
->goal
.offset
);
2937 * Truncate the given transfer width parameter to a value the
2938 * current adapter type is capable of.
2941 ahd_validate_width(struct ahd_softc
*ahd
, struct ahd_initiator_tinfo
*tinfo
,
2942 u_int
*bus_width
, role_t role
)
2944 switch (*bus_width
) {
2946 if (ahd
->features
& AHD_WIDE
) {
2948 *bus_width
= MSG_EXT_WDTR_BUS_16_BIT
;
2952 case MSG_EXT_WDTR_BUS_8_BIT
:
2953 *bus_width
= MSG_EXT_WDTR_BUS_8_BIT
;
2956 if (tinfo
!= NULL
) {
2957 if (role
== ROLE_TARGET
)
2958 *bus_width
= MIN(tinfo
->user
.width
, *bus_width
);
2960 *bus_width
= MIN(tinfo
->goal
.width
, *bus_width
);
2965 * Update the bitmask of targets for which the controller should
2966 * negotiate with at the next convenient oportunity. This currently
2967 * means the next time we send the initial identify messages for
2968 * a new transaction.
2971 ahd_update_neg_request(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
,
2972 struct ahd_tmode_tstate
*tstate
,
2973 struct ahd_initiator_tinfo
*tinfo
, ahd_neg_type neg_type
)
2975 u_int auto_negotiate_orig
;
2977 auto_negotiate_orig
= tstate
->auto_negotiate
;
2978 if (neg_type
== AHD_NEG_ALWAYS
) {
2980 * Force our "current" settings to be
2981 * unknown so that unless a bus reset
2982 * occurs the need to renegotiate is
2983 * recorded persistently.
2985 if ((ahd
->features
& AHD_WIDE
) != 0)
2986 tinfo
->curr
.width
= AHD_WIDTH_UNKNOWN
;
2987 tinfo
->curr
.period
= AHD_PERIOD_UNKNOWN
;
2988 tinfo
->curr
.offset
= AHD_OFFSET_UNKNOWN
;
2990 if (tinfo
->curr
.period
!= tinfo
->goal
.period
2991 || tinfo
->curr
.width
!= tinfo
->goal
.width
2992 || tinfo
->curr
.offset
!= tinfo
->goal
.offset
2993 || tinfo
->curr
.ppr_options
!= tinfo
->goal
.ppr_options
2994 || (neg_type
== AHD_NEG_IF_NON_ASYNC
2995 && (tinfo
->goal
.offset
!= 0
2996 || tinfo
->goal
.width
!= MSG_EXT_WDTR_BUS_8_BIT
2997 || tinfo
->goal
.ppr_options
!= 0)))
2998 tstate
->auto_negotiate
|= devinfo
->target_mask
;
3000 tstate
->auto_negotiate
&= ~devinfo
->target_mask
;
3002 return (auto_negotiate_orig
!= tstate
->auto_negotiate
);
3006 * Update the user/goal/curr tables of synchronous negotiation
3007 * parameters as well as, in the case of a current or active update,
3008 * any data structures on the host controller. In the case of an
3009 * active update, the specified target is currently talking to us on
3010 * the bus, so the transfer parameter update must take effect
3014 ahd_set_syncrate(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
,
3015 u_int period
, u_int offset
, u_int ppr_options
,
3016 u_int type
, int paused
)
3018 struct ahd_initiator_tinfo
*tinfo
;
3019 struct ahd_tmode_tstate
*tstate
;
3026 active
= (type
& AHD_TRANS_ACTIVE
) == AHD_TRANS_ACTIVE
;
3029 if (period
== 0 || offset
== 0) {
3034 tinfo
= ahd_fetch_transinfo(ahd
, devinfo
->channel
, devinfo
->our_scsiid
,
3035 devinfo
->target
, &tstate
);
3037 if ((type
& AHD_TRANS_USER
) != 0) {
3038 tinfo
->user
.period
= period
;
3039 tinfo
->user
.offset
= offset
;
3040 tinfo
->user
.ppr_options
= ppr_options
;
3043 if ((type
& AHD_TRANS_GOAL
) != 0) {
3044 tinfo
->goal
.period
= period
;
3045 tinfo
->goal
.offset
= offset
;
3046 tinfo
->goal
.ppr_options
= ppr_options
;
3049 old_period
= tinfo
->curr
.period
;
3050 old_offset
= tinfo
->curr
.offset
;
3051 old_ppr
= tinfo
->curr
.ppr_options
;
3053 if ((type
& AHD_TRANS_CUR
) != 0
3054 && (old_period
!= period
3055 || old_offset
!= offset
3056 || old_ppr
!= ppr_options
)) {
3060 tinfo
->curr
.period
= period
;
3061 tinfo
->curr
.offset
= offset
;
3062 tinfo
->curr
.ppr_options
= ppr_options
;
3064 ahd_send_async(ahd
, devinfo
->channel
, devinfo
->target
,
3065 CAM_LUN_WILDCARD
, AC_TRANSFER_NEG
);
3070 printf("%s: target %d synchronous with "
3071 "period = 0x%x, offset = 0x%x",
3072 ahd_name(ahd
), devinfo
->target
,
3075 if ((ppr_options
& MSG_EXT_PPR_RD_STRM
) != 0) {
3079 if ((ppr_options
& MSG_EXT_PPR_DT_REQ
) != 0) {
3080 printf("%s", options
? "|DT" : "(DT");
3083 if ((ppr_options
& MSG_EXT_PPR_IU_REQ
) != 0) {
3084 printf("%s", options
? "|IU" : "(IU");
3087 if ((ppr_options
& MSG_EXT_PPR_RTI
) != 0) {
3088 printf("%s", options
? "|RTI" : "(RTI");
3091 if ((ppr_options
& MSG_EXT_PPR_QAS_REQ
) != 0) {
3092 printf("%s", options
? "|QAS" : "(QAS");
3100 printf("%s: target %d using "
3101 "asynchronous transfers%s\n",
3102 ahd_name(ahd
), devinfo
->target
,
3103 (ppr_options
& MSG_EXT_PPR_QAS_REQ
) != 0
3109 * Always refresh the neg-table to handle the case of the
3110 * sequencer setting the ENATNO bit for a MK_MESSAGE request.
3111 * We will always renegotiate in that case if this is a
3112 * packetized request. Also manage the busfree expected flag
3113 * from this common routine so that we catch changes due to
3114 * WDTR or SDTR messages.
3116 if ((type
& AHD_TRANS_CUR
) != 0) {
3119 ahd_update_neg_table(ahd
, devinfo
, &tinfo
->curr
);
3122 if (ahd
->msg_type
!= MSG_TYPE_NONE
) {
3123 if ((old_ppr
& MSG_EXT_PPR_IU_REQ
)
3124 != (ppr_options
& MSG_EXT_PPR_IU_REQ
)) {
3126 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0) {
3127 ahd_print_devinfo(ahd
, devinfo
);
3128 printf("Expecting IU Change busfree\n");
3131 ahd
->msg_flags
|= MSG_FLAG_EXPECT_PPR_BUSFREE
3132 | MSG_FLAG_IU_REQ_CHANGED
;
3134 if ((old_ppr
& MSG_EXT_PPR_IU_REQ
) != 0) {
3136 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
3137 printf("PPR with IU_REQ outstanding\n");
3139 ahd
->msg_flags
|= MSG_FLAG_EXPECT_PPR_BUSFREE
;
3144 update_needed
+= ahd_update_neg_request(ahd
, devinfo
, tstate
,
3145 tinfo
, AHD_NEG_TO_GOAL
);
3147 if (update_needed
&& active
)
3148 ahd_update_pending_scbs(ahd
);
3152 * Update the user/goal/curr tables of wide negotiation
3153 * parameters as well as, in the case of a current or active update,
3154 * any data structures on the host controller. In the case of an
3155 * active update, the specified target is currently talking to us on
3156 * the bus, so the transfer parameter update must take effect
3160 ahd_set_width(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
,
3161 u_int width
, u_int type
, int paused
)
3163 struct ahd_initiator_tinfo
*tinfo
;
3164 struct ahd_tmode_tstate
*tstate
;
3169 active
= (type
& AHD_TRANS_ACTIVE
) == AHD_TRANS_ACTIVE
;
3171 tinfo
= ahd_fetch_transinfo(ahd
, devinfo
->channel
, devinfo
->our_scsiid
,
3172 devinfo
->target
, &tstate
);
3174 if ((type
& AHD_TRANS_USER
) != 0)
3175 tinfo
->user
.width
= width
;
3177 if ((type
& AHD_TRANS_GOAL
) != 0)
3178 tinfo
->goal
.width
= width
;
3180 oldwidth
= tinfo
->curr
.width
;
3181 if ((type
& AHD_TRANS_CUR
) != 0 && oldwidth
!= width
) {
3185 tinfo
->curr
.width
= width
;
3186 ahd_send_async(ahd
, devinfo
->channel
, devinfo
->target
,
3187 CAM_LUN_WILDCARD
, AC_TRANSFER_NEG
);
3189 printf("%s: target %d using %dbit transfers\n",
3190 ahd_name(ahd
), devinfo
->target
,
3191 8 * (0x01 << width
));
3195 if ((type
& AHD_TRANS_CUR
) != 0) {
3198 ahd_update_neg_table(ahd
, devinfo
, &tinfo
->curr
);
3203 update_needed
+= ahd_update_neg_request(ahd
, devinfo
, tstate
,
3204 tinfo
, AHD_NEG_TO_GOAL
);
3205 if (update_needed
&& active
)
3206 ahd_update_pending_scbs(ahd
);
3211 * Update the current state of tagged queuing for a given target.
3214 ahd_set_tags(struct ahd_softc
*ahd
, struct scsi_cmnd
*cmd
,
3215 struct ahd_devinfo
*devinfo
, ahd_queue_alg alg
)
3217 struct scsi_device
*sdev
= cmd
->device
;
3219 ahd_platform_set_tags(ahd
, sdev
, devinfo
, alg
);
3220 ahd_send_async(ahd
, devinfo
->channel
, devinfo
->target
,
3221 devinfo
->lun
, AC_TRANSFER_NEG
);
3225 ahd_update_neg_table(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
,
3226 struct ahd_transinfo
*tinfo
)
3228 ahd_mode_state saved_modes
;
3233 u_int saved_negoaddr
;
3234 uint8_t iocell_opts
[sizeof(ahd
->iocell_opts
)];
3236 saved_modes
= ahd_save_modes(ahd
);
3237 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
3239 saved_negoaddr
= ahd_inb(ahd
, NEGOADDR
);
3240 ahd_outb(ahd
, NEGOADDR
, devinfo
->target
);
3241 period
= tinfo
->period
;
3242 offset
= tinfo
->offset
;
3243 memcpy(iocell_opts
, ahd
->iocell_opts
, sizeof(ahd
->iocell_opts
));
3244 ppr_opts
= tinfo
->ppr_options
& (MSG_EXT_PPR_QAS_REQ
|MSG_EXT_PPR_DT_REQ
3245 |MSG_EXT_PPR_IU_REQ
|MSG_EXT_PPR_RTI
);
3248 period
= AHD_SYNCRATE_ASYNC
;
3249 if (period
== AHD_SYNCRATE_160
) {
3251 if ((ahd
->bugs
& AHD_PACED_NEGTABLE_BUG
) != 0) {
3253 * When the SPI4 spec was finalized, PACE transfers
3254 * was not made a configurable option in the PPR
3255 * message. Instead it is assumed to be enabled for
3256 * any syncrate faster than 80MHz. Nevertheless,
3257 * Harpoon2A4 allows this to be configurable.
3259 * Harpoon2A4 also assumes at most 2 data bytes per
3260 * negotiated REQ/ACK offset. Paced transfers take
3261 * 4, so we must adjust our offset.
3263 ppr_opts
|= PPROPT_PACE
;
3267 * Harpoon2A assumed that there would be a
3268 * fallback rate between 160MHz and 80Mhz,
3269 * so 7 is used as the period factor rather
3270 * than 8 for 160MHz.
3272 period
= AHD_SYNCRATE_REVA_160
;
3274 if ((tinfo
->ppr_options
& MSG_EXT_PPR_PCOMP_EN
) == 0)
3275 iocell_opts
[AHD_PRECOMP_SLEW_INDEX
] &=
3279 * Precomp should be disabled for non-paced transfers.
3281 iocell_opts
[AHD_PRECOMP_SLEW_INDEX
] &= ~AHD_PRECOMP_MASK
;
3283 if ((ahd
->features
& AHD_NEW_IOCELL_OPTS
) != 0
3284 && (ppr_opts
& MSG_EXT_PPR_DT_REQ
) != 0
3285 && (ppr_opts
& MSG_EXT_PPR_IU_REQ
) == 0) {
3287 * Slow down our CRC interval to be
3288 * compatible with non-packetized
3289 * U160 devices that can't handle a
3290 * CRC at full speed.
3292 con_opts
|= ENSLOWCRC
;
3295 if ((ahd
->bugs
& AHD_PACED_NEGTABLE_BUG
) != 0) {
3297 * On H2A4, revert to a slower slewrate
3298 * on non-paced transfers.
3300 iocell_opts
[AHD_PRECOMP_SLEW_INDEX
] &=
3305 ahd_outb(ahd
, ANNEXCOL
, AHD_ANNEXCOL_PRECOMP_SLEW
);
3306 ahd_outb(ahd
, ANNEXDAT
, iocell_opts
[AHD_PRECOMP_SLEW_INDEX
]);
3307 ahd_outb(ahd
, ANNEXCOL
, AHD_ANNEXCOL_AMPLITUDE
);
3308 ahd_outb(ahd
, ANNEXDAT
, iocell_opts
[AHD_AMPLITUDE_INDEX
]);
3310 ahd_outb(ahd
, NEGPERIOD
, period
);
3311 ahd_outb(ahd
, NEGPPROPTS
, ppr_opts
);
3312 ahd_outb(ahd
, NEGOFFSET
, offset
);
3314 if (tinfo
->width
== MSG_EXT_WDTR_BUS_16_BIT
)
3315 con_opts
|= WIDEXFER
;
3318 * Slow down our CRC interval to be
3319 * compatible with packetized U320 devices
3320 * that can't handle a CRC at full speed
3322 if (ahd
->features
& AHD_AIC79XXB_SLOWCRC
) {
3323 con_opts
|= ENSLOWCRC
;
3327 * During packetized transfers, the target will
3328 * give us the oportunity to send command packets
3329 * without us asserting attention.
3331 if ((tinfo
->ppr_options
& MSG_EXT_PPR_IU_REQ
) == 0)
3332 con_opts
|= ENAUTOATNO
;
3333 ahd_outb(ahd
, NEGCONOPTS
, con_opts
);
3334 ahd_outb(ahd
, NEGOADDR
, saved_negoaddr
);
3335 ahd_restore_modes(ahd
, saved_modes
);
3339 * When the transfer settings for a connection change, setup for
3340 * negotiation in pending SCBs to effect the change as quickly as
3341 * possible. We also cancel any negotiations that are scheduled
3342 * for inflight SCBs that have not been started yet.
3345 ahd_update_pending_scbs(struct ahd_softc
*ahd
)
3347 struct scb
*pending_scb
;
3348 int pending_scb_count
;
3351 ahd_mode_state saved_modes
;
3354 * Traverse the pending SCB list and ensure that all of the
3355 * SCBs there have the proper settings. We can only safely
3356 * clear the negotiation required flag (setting requires the
3357 * execution queue to be modified) and this is only possible
3358 * if we are not already attempting to select out for this
3359 * SCB. For this reason, all callers only call this routine
3360 * if we are changing the negotiation settings for the currently
3361 * active transaction on the bus.
3363 pending_scb_count
= 0;
3364 LIST_FOREACH(pending_scb
, &ahd
->pending_scbs
, pending_links
) {
3365 struct ahd_devinfo devinfo
;
3366 struct ahd_initiator_tinfo
*tinfo
;
3367 struct ahd_tmode_tstate
*tstate
;
3369 ahd_scb_devinfo(ahd
, &devinfo
, pending_scb
);
3370 tinfo
= ahd_fetch_transinfo(ahd
, devinfo
.channel
,
3372 devinfo
.target
, &tstate
);
3373 if ((tstate
->auto_negotiate
& devinfo
.target_mask
) == 0
3374 && (pending_scb
->flags
& SCB_AUTO_NEGOTIATE
) != 0) {
3375 pending_scb
->flags
&= ~SCB_AUTO_NEGOTIATE
;
3376 pending_scb
->hscb
->control
&= ~MK_MESSAGE
;
3378 ahd_sync_scb(ahd
, pending_scb
,
3379 BUS_DMASYNC_PREREAD
|BUS_DMASYNC_PREWRITE
);
3380 pending_scb_count
++;
3383 if (pending_scb_count
== 0)
3386 if (ahd_is_paused(ahd
)) {
3394 * Force the sequencer to reinitialize the selection for
3395 * the command at the head of the execution queue if it
3396 * has already been setup. The negotiation changes may
3397 * effect whether we select-out with ATN. It is only
3398 * safe to clear ENSELO when the bus is not free and no
3399 * selection is in progres or completed.
3401 saved_modes
= ahd_save_modes(ahd
);
3402 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
3403 if ((ahd_inb(ahd
, SCSISIGI
) & BSYI
) != 0
3404 && (ahd_inb(ahd
, SSTAT0
) & (SELDO
|SELINGO
)) == 0)
3405 ahd_outb(ahd
, SCSISEQ0
, ahd_inb(ahd
, SCSISEQ0
) & ~ENSELO
);
3406 saved_scbptr
= ahd_get_scbptr(ahd
);
3407 /* Ensure that the hscbs down on the card match the new information */
3408 LIST_FOREACH(pending_scb
, &ahd
->pending_scbs
, pending_links
) {
3412 scb_tag
= SCB_GET_TAG(pending_scb
);
3413 ahd_set_scbptr(ahd
, scb_tag
);
3414 control
= ahd_inb_scbram(ahd
, SCB_CONTROL
);
3415 control
&= ~MK_MESSAGE
;
3416 control
|= pending_scb
->hscb
->control
& MK_MESSAGE
;
3417 ahd_outb(ahd
, SCB_CONTROL
, control
);
3419 ahd_set_scbptr(ahd
, saved_scbptr
);
3420 ahd_restore_modes(ahd
, saved_modes
);
3426 /**************************** Pathing Information *****************************/
3428 ahd_fetch_devinfo(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
)
3430 ahd_mode_state saved_modes
;
3435 saved_modes
= ahd_save_modes(ahd
);
3436 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
3438 if (ahd_inb(ahd
, SSTAT0
) & TARGET
)
3441 role
= ROLE_INITIATOR
;
3443 if (role
== ROLE_TARGET
3444 && (ahd_inb(ahd
, SEQ_FLAGS
) & CMDPHASE_PENDING
) != 0) {
3445 /* We were selected, so pull our id from TARGIDIN */
3446 our_id
= ahd_inb(ahd
, TARGIDIN
) & OID
;
3447 } else if (role
== ROLE_TARGET
)
3448 our_id
= ahd_inb(ahd
, TOWNID
);
3450 our_id
= ahd_inb(ahd
, IOWNID
);
3452 saved_scsiid
= ahd_inb(ahd
, SAVED_SCSIID
);
3453 ahd_compile_devinfo(devinfo
,
3455 SCSIID_TARGET(ahd
, saved_scsiid
),
3456 ahd_inb(ahd
, SAVED_LUN
),
3457 SCSIID_CHANNEL(ahd
, saved_scsiid
),
3459 ahd_restore_modes(ahd
, saved_modes
);
3463 ahd_print_devinfo(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
)
3465 printf("%s:%c:%d:%d: ", ahd_name(ahd
), 'A',
3466 devinfo
->target
, devinfo
->lun
);
3469 struct ahd_phase_table_entry
*
3470 ahd_lookup_phase_entry(int phase
)
3472 struct ahd_phase_table_entry
*entry
;
3473 struct ahd_phase_table_entry
*last_entry
;
3476 * num_phases doesn't include the default entry which
3477 * will be returned if the phase doesn't match.
3479 last_entry
= &ahd_phase_table
[num_phases
];
3480 for (entry
= ahd_phase_table
; entry
< last_entry
; entry
++) {
3481 if (phase
== entry
->phase
)
3488 ahd_compile_devinfo(struct ahd_devinfo
*devinfo
, u_int our_id
, u_int target
,
3489 u_int lun
, char channel
, role_t role
)
3491 devinfo
->our_scsiid
= our_id
;
3492 devinfo
->target
= target
;
3494 devinfo
->target_offset
= target
;
3495 devinfo
->channel
= channel
;
3496 devinfo
->role
= role
;
3498 devinfo
->target_offset
+= 8;
3499 devinfo
->target_mask
= (0x01 << devinfo
->target_offset
);
3503 ahd_scb_devinfo(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
,
3509 our_id
= SCSIID_OUR_ID(scb
->hscb
->scsiid
);
3510 role
= ROLE_INITIATOR
;
3511 if ((scb
->hscb
->control
& TARGET_SCB
) != 0)
3513 ahd_compile_devinfo(devinfo
, our_id
, SCB_GET_TARGET(ahd
, scb
),
3514 SCB_GET_LUN(scb
), SCB_GET_CHANNEL(ahd
, scb
), role
);
3518 /************************ Message Phase Processing ****************************/
3520 * When an initiator transaction with the MK_MESSAGE flag either reconnects
3521 * or enters the initial message out phase, we are interrupted. Fill our
3522 * outgoing message buffer with the appropriate message and beging handing
3523 * the message phase(s) manually.
3526 ahd_setup_initiator_msgout(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
,
3530 * To facilitate adding multiple messages together,
3531 * each routine should increment the index and len
3532 * variables instead of setting them explicitly.
3534 ahd
->msgout_index
= 0;
3535 ahd
->msgout_len
= 0;
3537 if (ahd_currently_packetized(ahd
))
3538 ahd
->msg_flags
|= MSG_FLAG_PACKETIZED
;
3540 if (ahd
->send_msg_perror
3541 && ahd_inb(ahd
, MSG_OUT
) == HOST_MSG
) {
3542 ahd
->msgout_buf
[ahd
->msgout_index
++] = ahd
->send_msg_perror
;
3544 ahd
->msg_type
= MSG_TYPE_INITIATOR_MSGOUT
;
3546 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
3547 printf("Setting up for Parity Error delivery\n");
3550 } else if (scb
== NULL
) {
3551 printf("%s: WARNING. No pending message for "
3552 "I_T msgin. Issuing NO-OP\n", ahd_name(ahd
));
3553 ahd
->msgout_buf
[ahd
->msgout_index
++] = MSG_NOOP
;
3555 ahd
->msg_type
= MSG_TYPE_INITIATOR_MSGOUT
;
3559 if ((scb
->flags
& SCB_DEVICE_RESET
) == 0
3560 && (scb
->flags
& SCB_PACKETIZED
) == 0
3561 && ahd_inb(ahd
, MSG_OUT
) == MSG_IDENTIFYFLAG
) {
3564 identify_msg
= MSG_IDENTIFYFLAG
| SCB_GET_LUN(scb
);
3565 if ((scb
->hscb
->control
& DISCENB
) != 0)
3566 identify_msg
|= MSG_IDENTIFY_DISCFLAG
;
3567 ahd
->msgout_buf
[ahd
->msgout_index
++] = identify_msg
;
3570 if ((scb
->hscb
->control
& TAG_ENB
) != 0) {
3571 ahd
->msgout_buf
[ahd
->msgout_index
++] =
3572 scb
->hscb
->control
& (TAG_ENB
|SCB_TAG_TYPE
);
3573 ahd
->msgout_buf
[ahd
->msgout_index
++] = SCB_GET_TAG(scb
);
3574 ahd
->msgout_len
+= 2;
3578 if (scb
->flags
& SCB_DEVICE_RESET
) {
3579 ahd
->msgout_buf
[ahd
->msgout_index
++] = MSG_BUS_DEV_RESET
;
3581 ahd_print_path(ahd
, scb
);
3582 printf("Bus Device Reset Message Sent\n");
3584 * Clear our selection hardware in advance of
3585 * the busfree. We may have an entry in the waiting
3586 * Q for this target, and we don't want to go about
3587 * selecting while we handle the busfree and blow it
3590 ahd_outb(ahd
, SCSISEQ0
, 0);
3591 } else if ((scb
->flags
& SCB_ABORT
) != 0) {
3593 if ((scb
->hscb
->control
& TAG_ENB
) != 0) {
3594 ahd
->msgout_buf
[ahd
->msgout_index
++] = MSG_ABORT_TAG
;
3596 ahd
->msgout_buf
[ahd
->msgout_index
++] = MSG_ABORT
;
3599 ahd_print_path(ahd
, scb
);
3600 printf("Abort%s Message Sent\n",
3601 (scb
->hscb
->control
& TAG_ENB
) != 0 ? " Tag" : "");
3603 * Clear our selection hardware in advance of
3604 * the busfree. We may have an entry in the waiting
3605 * Q for this target, and we don't want to go about
3606 * selecting while we handle the busfree and blow it
3609 ahd_outb(ahd
, SCSISEQ0
, 0);
3610 } else if ((scb
->flags
& (SCB_AUTO_NEGOTIATE
|SCB_NEGOTIATE
)) != 0) {
3611 ahd_build_transfer_msg(ahd
, devinfo
);
3613 * Clear our selection hardware in advance of potential
3614 * PPR IU status change busfree. We may have an entry in
3615 * the waiting Q for this target, and we don't want to go
3616 * about selecting while we handle the busfree and blow
3619 ahd_outb(ahd
, SCSISEQ0
, 0);
3621 printf("ahd_intr: AWAITING_MSG for an SCB that "
3622 "does not have a waiting message\n");
3623 printf("SCSIID = %x, target_mask = %x\n", scb
->hscb
->scsiid
,
3624 devinfo
->target_mask
);
3625 panic("SCB = %d, SCB Control = %x:%x, MSG_OUT = %x "
3626 "SCB flags = %x", SCB_GET_TAG(scb
), scb
->hscb
->control
,
3627 ahd_inb_scbram(ahd
, SCB_CONTROL
), ahd_inb(ahd
, MSG_OUT
),
3632 * Clear the MK_MESSAGE flag from the SCB so we aren't
3633 * asked to send this message again.
3635 ahd_outb(ahd
, SCB_CONTROL
,
3636 ahd_inb_scbram(ahd
, SCB_CONTROL
) & ~MK_MESSAGE
);
3637 scb
->hscb
->control
&= ~MK_MESSAGE
;
3638 ahd
->msgout_index
= 0;
3639 ahd
->msg_type
= MSG_TYPE_INITIATOR_MSGOUT
;
3643 * Build an appropriate transfer negotiation message for the
3644 * currently active target.
3647 ahd_build_transfer_msg(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
)
3650 * We need to initiate transfer negotiations.
3651 * If our current and goal settings are identical,
3652 * we want to renegotiate due to a check condition.
3654 struct ahd_initiator_tinfo
*tinfo
;
3655 struct ahd_tmode_tstate
*tstate
;
3663 tinfo
= ahd_fetch_transinfo(ahd
, devinfo
->channel
, devinfo
->our_scsiid
,
3664 devinfo
->target
, &tstate
);
3666 * Filter our period based on the current connection.
3667 * If we can't perform DT transfers on this segment (not in LVD
3668 * mode for instance), then our decision to issue a PPR message
3671 period
= tinfo
->goal
.period
;
3672 offset
= tinfo
->goal
.offset
;
3673 ppr_options
= tinfo
->goal
.ppr_options
;
3674 /* Target initiated PPR is not allowed in the SCSI spec */
3675 if (devinfo
->role
== ROLE_TARGET
)
3677 ahd_devlimited_syncrate(ahd
, tinfo
, &period
,
3678 &ppr_options
, devinfo
->role
);
3679 dowide
= tinfo
->curr
.width
!= tinfo
->goal
.width
;
3680 dosync
= tinfo
->curr
.offset
!= offset
|| tinfo
->curr
.period
!= period
;
3682 * Only use PPR if we have options that need it, even if the device
3683 * claims to support it. There might be an expander in the way
3686 doppr
= ppr_options
!= 0;
3688 if (!dowide
&& !dosync
&& !doppr
) {
3689 dowide
= tinfo
->goal
.width
!= MSG_EXT_WDTR_BUS_8_BIT
;
3690 dosync
= tinfo
->goal
.offset
!= 0;
3693 if (!dowide
&& !dosync
&& !doppr
) {
3695 * Force async with a WDTR message if we have a wide bus,
3696 * or just issue an SDTR with a 0 offset.
3698 if ((ahd
->features
& AHD_WIDE
) != 0)
3704 ahd_print_devinfo(ahd
, devinfo
);
3705 printf("Ensuring async\n");
3708 /* Target initiated PPR is not allowed in the SCSI spec */
3709 if (devinfo
->role
== ROLE_TARGET
)
3713 * Both the PPR message and SDTR message require the
3714 * goal syncrate to be limited to what the target device
3715 * is capable of handling (based on whether an LVD->SE
3716 * expander is on the bus), so combine these two cases.
3717 * Regardless, guarantee that if we are using WDTR and SDTR
3718 * messages that WDTR comes first.
3720 if (doppr
|| (dosync
&& !dowide
)) {
3722 offset
= tinfo
->goal
.offset
;
3723 ahd_validate_offset(ahd
, tinfo
, period
, &offset
,
3724 doppr
? tinfo
->goal
.width
3725 : tinfo
->curr
.width
,
3728 ahd_construct_ppr(ahd
, devinfo
, period
, offset
,
3729 tinfo
->goal
.width
, ppr_options
);
3731 ahd_construct_sdtr(ahd
, devinfo
, period
, offset
);
3734 ahd_construct_wdtr(ahd
, devinfo
, tinfo
->goal
.width
);
3739 * Build a synchronous negotiation message in our message
3740 * buffer based on the input parameters.
3743 ahd_construct_sdtr(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
,
3744 u_int period
, u_int offset
)
3747 period
= AHD_ASYNC_XFER_PERIOD
;
3748 ahd
->msgout_index
+= spi_populate_sync_msg(
3749 ahd
->msgout_buf
+ ahd
->msgout_index
, period
, offset
);
3750 ahd
->msgout_len
+= 5;
3752 printf("(%s:%c:%d:%d): Sending SDTR period %x, offset %x\n",
3753 ahd_name(ahd
), devinfo
->channel
, devinfo
->target
,
3754 devinfo
->lun
, period
, offset
);
3759 * Build a wide negotiateion message in our message
3760 * buffer based on the input parameters.
3763 ahd_construct_wdtr(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
,
3766 ahd
->msgout_index
+= spi_populate_width_msg(
3767 ahd
->msgout_buf
+ ahd
->msgout_index
, bus_width
);
3768 ahd
->msgout_len
+= 4;
3770 printf("(%s:%c:%d:%d): Sending WDTR %x\n",
3771 ahd_name(ahd
), devinfo
->channel
, devinfo
->target
,
3772 devinfo
->lun
, bus_width
);
3777 * Build a parallel protocol request message in our message
3778 * buffer based on the input parameters.
3781 ahd_construct_ppr(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
,
3782 u_int period
, u_int offset
, u_int bus_width
,
3786 * Always request precompensation from
3787 * the other target if we are running
3788 * at paced syncrates.
3790 if (period
<= AHD_SYNCRATE_PACED
)
3791 ppr_options
|= MSG_EXT_PPR_PCOMP_EN
;
3793 period
= AHD_ASYNC_XFER_PERIOD
;
3794 ahd
->msgout_index
+= spi_populate_ppr_msg(
3795 ahd
->msgout_buf
+ ahd
->msgout_index
, period
, offset
,
3796 bus_width
, ppr_options
);
3797 ahd
->msgout_len
+= 8;
3799 printf("(%s:%c:%d:%d): Sending PPR bus_width %x, period %x, "
3800 "offset %x, ppr_options %x\n", ahd_name(ahd
),
3801 devinfo
->channel
, devinfo
->target
, devinfo
->lun
,
3802 bus_width
, period
, offset
, ppr_options
);
3807 * Clear any active message state.
3810 ahd_clear_msg_state(struct ahd_softc
*ahd
)
3812 ahd_mode_state saved_modes
;
3814 saved_modes
= ahd_save_modes(ahd
);
3815 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
3816 ahd
->send_msg_perror
= 0;
3817 ahd
->msg_flags
= MSG_FLAG_NONE
;
3818 ahd
->msgout_len
= 0;
3819 ahd
->msgin_index
= 0;
3820 ahd
->msg_type
= MSG_TYPE_NONE
;
3821 if ((ahd_inb(ahd
, SCSISIGO
) & ATNO
) != 0) {
3823 * The target didn't care to respond to our
3824 * message request, so clear ATN.
3826 ahd_outb(ahd
, CLRSINT1
, CLRATNO
);
3828 ahd_outb(ahd
, MSG_OUT
, MSG_NOOP
);
3829 ahd_outb(ahd
, SEQ_FLAGS2
,
3830 ahd_inb(ahd
, SEQ_FLAGS2
) & ~TARGET_MSG_PENDING
);
3831 ahd_restore_modes(ahd
, saved_modes
);
3835 * Manual message loop handler.
3838 ahd_handle_message_phase(struct ahd_softc
*ahd
)
3840 struct ahd_devinfo devinfo
;
3844 ahd_fetch_devinfo(ahd
, &devinfo
);
3845 end_session
= FALSE
;
3846 bus_phase
= ahd_inb(ahd
, LASTPHASE
);
3848 if ((ahd_inb(ahd
, LQISTAT2
) & LQIPHASE_OUTPKT
) != 0) {
3849 printf("LQIRETRY for LQIPHASE_OUTPKT\n");
3850 ahd_outb(ahd
, LQCTL2
, LQIRETRY
);
3853 switch (ahd
->msg_type
) {
3854 case MSG_TYPE_INITIATOR_MSGOUT
:
3860 if (ahd
->msgout_len
== 0 && ahd
->send_msg_perror
== 0)
3861 panic("HOST_MSG_LOOP interrupt with no active message");
3864 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0) {
3865 ahd_print_devinfo(ahd
, &devinfo
);
3866 printf("INITIATOR_MSG_OUT");
3869 phasemis
= bus_phase
!= P_MESGOUT
;
3872 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0) {
3873 printf(" PHASEMIS %s\n",
3874 ahd_lookup_phase_entry(bus_phase
)
3878 if (bus_phase
== P_MESGIN
) {
3880 * Change gears and see if
3881 * this messages is of interest to
3882 * us or should be passed back to
3885 ahd_outb(ahd
, CLRSINT1
, CLRATNO
);
3886 ahd
->send_msg_perror
= 0;
3887 ahd
->msg_type
= MSG_TYPE_INITIATOR_MSGIN
;
3888 ahd
->msgin_index
= 0;
3895 if (ahd
->send_msg_perror
) {
3896 ahd_outb(ahd
, CLRSINT1
, CLRATNO
);
3897 ahd_outb(ahd
, CLRSINT1
, CLRREQINIT
);
3899 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
3900 printf(" byte 0x%x\n", ahd
->send_msg_perror
);
3903 * If we are notifying the target of a CRC error
3904 * during packetized operations, the target is
3905 * within its rights to acknowledge our message
3908 if ((ahd
->msg_flags
& MSG_FLAG_PACKETIZED
) != 0
3909 && ahd
->send_msg_perror
== MSG_INITIATOR_DET_ERR
)
3910 ahd
->msg_flags
|= MSG_FLAG_EXPECT_IDE_BUSFREE
;
3912 ahd_outb(ahd
, RETURN_2
, ahd
->send_msg_perror
);
3913 ahd_outb(ahd
, RETURN_1
, CONT_MSG_LOOP_WRITE
);
3917 msgdone
= ahd
->msgout_index
== ahd
->msgout_len
;
3920 * The target has requested a retry.
3921 * Re-assert ATN, reset our message index to
3924 ahd
->msgout_index
= 0;
3925 ahd_assert_atn(ahd
);
3928 lastbyte
= ahd
->msgout_index
== (ahd
->msgout_len
- 1);
3930 /* Last byte is signified by dropping ATN */
3931 ahd_outb(ahd
, CLRSINT1
, CLRATNO
);
3935 * Clear our interrupt status and present
3936 * the next byte on the bus.
3938 ahd_outb(ahd
, CLRSINT1
, CLRREQINIT
);
3940 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
3941 printf(" byte 0x%x\n",
3942 ahd
->msgout_buf
[ahd
->msgout_index
]);
3944 ahd_outb(ahd
, RETURN_2
, ahd
->msgout_buf
[ahd
->msgout_index
++]);
3945 ahd_outb(ahd
, RETURN_1
, CONT_MSG_LOOP_WRITE
);
3948 case MSG_TYPE_INITIATOR_MSGIN
:
3954 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0) {
3955 ahd_print_devinfo(ahd
, &devinfo
);
3956 printf("INITIATOR_MSG_IN");
3959 phasemis
= bus_phase
!= P_MESGIN
;
3962 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0) {
3963 printf(" PHASEMIS %s\n",
3964 ahd_lookup_phase_entry(bus_phase
)
3968 ahd
->msgin_index
= 0;
3969 if (bus_phase
== P_MESGOUT
3970 && (ahd
->send_msg_perror
!= 0
3971 || (ahd
->msgout_len
!= 0
3972 && ahd
->msgout_index
== 0))) {
3973 ahd
->msg_type
= MSG_TYPE_INITIATOR_MSGOUT
;
3980 /* Pull the byte in without acking it */
3981 ahd
->msgin_buf
[ahd
->msgin_index
] = ahd_inb(ahd
, SCSIBUS
);
3983 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
3984 printf(" byte 0x%x\n",
3985 ahd
->msgin_buf
[ahd
->msgin_index
]);
3988 message_done
= ahd_parse_msg(ahd
, &devinfo
);
3992 * Clear our incoming message buffer in case there
3993 * is another message following this one.
3995 ahd
->msgin_index
= 0;
3998 * If this message illicited a response,
3999 * assert ATN so the target takes us to the
4000 * message out phase.
4002 if (ahd
->msgout_len
!= 0) {
4004 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0) {
4005 ahd_print_devinfo(ahd
, &devinfo
);
4006 printf("Asserting ATN for response\n");
4009 ahd_assert_atn(ahd
);
4014 if (message_done
== MSGLOOP_TERMINATED
) {
4018 ahd_outb(ahd
, CLRSINT1
, CLRREQINIT
);
4019 ahd_outb(ahd
, RETURN_1
, CONT_MSG_LOOP_READ
);
4023 case MSG_TYPE_TARGET_MSGIN
:
4029 * By default, the message loop will continue.
4031 ahd_outb(ahd
, RETURN_1
, CONT_MSG_LOOP_TARG
);
4033 if (ahd
->msgout_len
== 0)
4034 panic("Target MSGIN with no active message");
4037 * If we interrupted a mesgout session, the initiator
4038 * will not know this until our first REQ. So, we
4039 * only honor mesgout requests after we've sent our
4042 if ((ahd_inb(ahd
, SCSISIGI
) & ATNI
) != 0
4043 && ahd
->msgout_index
> 0)
4044 msgout_request
= TRUE
;
4046 msgout_request
= FALSE
;
4048 if (msgout_request
) {
4051 * Change gears and see if
4052 * this messages is of interest to
4053 * us or should be passed back to
4056 ahd
->msg_type
= MSG_TYPE_TARGET_MSGOUT
;
4057 ahd_outb(ahd
, SCSISIGO
, P_MESGOUT
| BSYO
);
4058 ahd
->msgin_index
= 0;
4059 /* Dummy read to REQ for first byte */
4060 ahd_inb(ahd
, SCSIDAT
);
4061 ahd_outb(ahd
, SXFRCTL0
,
4062 ahd_inb(ahd
, SXFRCTL0
) | SPIOEN
);
4066 msgdone
= ahd
->msgout_index
== ahd
->msgout_len
;
4068 ahd_outb(ahd
, SXFRCTL0
,
4069 ahd_inb(ahd
, SXFRCTL0
) & ~SPIOEN
);
4075 * Present the next byte on the bus.
4077 ahd_outb(ahd
, SXFRCTL0
, ahd_inb(ahd
, SXFRCTL0
) | SPIOEN
);
4078 ahd_outb(ahd
, SCSIDAT
, ahd
->msgout_buf
[ahd
->msgout_index
++]);
4081 case MSG_TYPE_TARGET_MSGOUT
:
4087 * By default, the message loop will continue.
4089 ahd_outb(ahd
, RETURN_1
, CONT_MSG_LOOP_TARG
);
4092 * The initiator signals that this is
4093 * the last byte by dropping ATN.
4095 lastbyte
= (ahd_inb(ahd
, SCSISIGI
) & ATNI
) == 0;
4098 * Read the latched byte, but turn off SPIOEN first
4099 * so that we don't inadvertently cause a REQ for the
4102 ahd_outb(ahd
, SXFRCTL0
, ahd_inb(ahd
, SXFRCTL0
) & ~SPIOEN
);
4103 ahd
->msgin_buf
[ahd
->msgin_index
] = ahd_inb(ahd
, SCSIDAT
);
4104 msgdone
= ahd_parse_msg(ahd
, &devinfo
);
4105 if (msgdone
== MSGLOOP_TERMINATED
) {
4107 * The message is *really* done in that it caused
4108 * us to go to bus free. The sequencer has already
4109 * been reset at this point, so pull the ejection
4118 * XXX Read spec about initiator dropping ATN too soon
4119 * and use msgdone to detect it.
4121 if (msgdone
== MSGLOOP_MSGCOMPLETE
) {
4122 ahd
->msgin_index
= 0;
4125 * If this message illicited a response, transition
4126 * to the Message in phase and send it.
4128 if (ahd
->msgout_len
!= 0) {
4129 ahd_outb(ahd
, SCSISIGO
, P_MESGIN
| BSYO
);
4130 ahd_outb(ahd
, SXFRCTL0
,
4131 ahd_inb(ahd
, SXFRCTL0
) | SPIOEN
);
4132 ahd
->msg_type
= MSG_TYPE_TARGET_MSGIN
;
4133 ahd
->msgin_index
= 0;
4141 /* Ask for the next byte. */
4142 ahd_outb(ahd
, SXFRCTL0
,
4143 ahd_inb(ahd
, SXFRCTL0
) | SPIOEN
);
4149 panic("Unknown REQINIT message type");
4153 if ((ahd
->msg_flags
& MSG_FLAG_PACKETIZED
) != 0) {
4154 printf("%s: Returning to Idle Loop\n",
4156 ahd_clear_msg_state(ahd
);
4159 * Perform the equivalent of a clear_target_state.
4161 ahd_outb(ahd
, LASTPHASE
, P_BUSFREE
);
4162 ahd_outb(ahd
, SEQ_FLAGS
, NOT_IDENTIFIED
|NO_CDB_SENT
);
4163 ahd_outb(ahd
, SEQCTL0
, FASTMODE
|SEQRESET
);
4165 ahd_clear_msg_state(ahd
);
4166 ahd_outb(ahd
, RETURN_1
, EXIT_MSG_LOOP
);
4172 * See if we sent a particular extended message to the target.
4173 * If "full" is true, return true only if the target saw the full
4174 * message. If "full" is false, return true if the target saw at
4175 * least the first byte of the message.
4178 ahd_sent_msg(struct ahd_softc
*ahd
, ahd_msgtype type
, u_int msgval
, int full
)
4186 while (index
< ahd
->msgout_len
) {
4187 if (ahd
->msgout_buf
[index
] == MSG_EXTENDED
) {
4190 end_index
= index
+ 1 + ahd
->msgout_buf
[index
+ 1];
4191 if (ahd
->msgout_buf
[index
+2] == msgval
4192 && type
== AHDMSG_EXT
) {
4195 if (ahd
->msgout_index
> end_index
)
4197 } else if (ahd
->msgout_index
> index
)
4201 } else if (ahd
->msgout_buf
[index
] >= MSG_SIMPLE_TASK
4202 && ahd
->msgout_buf
[index
] <= MSG_IGN_WIDE_RESIDUE
) {
4204 /* Skip tag type and tag id or residue param*/
4207 /* Single byte message */
4208 if (type
== AHDMSG_1B
4209 && ahd
->msgout_index
> index
4210 && (ahd
->msgout_buf
[index
] == msgval
4211 || ((ahd
->msgout_buf
[index
] & MSG_IDENTIFYFLAG
) != 0
4212 && msgval
== MSG_IDENTIFYFLAG
)))
4224 * Wait for a complete incoming message, parse it, and respond accordingly.
4227 ahd_parse_msg(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
)
4229 struct ahd_initiator_tinfo
*tinfo
;
4230 struct ahd_tmode_tstate
*tstate
;
4235 done
= MSGLOOP_IN_PROG
;
4238 tinfo
= ahd_fetch_transinfo(ahd
, devinfo
->channel
, devinfo
->our_scsiid
,
4239 devinfo
->target
, &tstate
);
4242 * Parse as much of the message as is available,
4243 * rejecting it if we don't support it. When
4244 * the entire message is available and has been
4245 * handled, return MSGLOOP_MSGCOMPLETE, indicating
4246 * that we have parsed an entire message.
4248 * In the case of extended messages, we accept the length
4249 * byte outright and perform more checking once we know the
4250 * extended message type.
4252 switch (ahd
->msgin_buf
[0]) {
4253 case MSG_DISCONNECT
:
4254 case MSG_SAVEDATAPOINTER
:
4255 case MSG_CMDCOMPLETE
:
4256 case MSG_RESTOREPOINTERS
:
4257 case MSG_IGN_WIDE_RESIDUE
:
4259 * End our message loop as these are messages
4260 * the sequencer handles on its own.
4262 done
= MSGLOOP_TERMINATED
;
4264 case MSG_MESSAGE_REJECT
:
4265 response
= ahd_handle_msg_reject(ahd
, devinfo
);
4268 done
= MSGLOOP_MSGCOMPLETE
;
4272 /* Wait for enough of the message to begin validation */
4273 if (ahd
->msgin_index
< 2)
4275 switch (ahd
->msgin_buf
[2]) {
4283 if (ahd
->msgin_buf
[1] != MSG_EXT_SDTR_LEN
) {
4289 * Wait until we have both args before validating
4290 * and acting on this message.
4292 * Add one to MSG_EXT_SDTR_LEN to account for
4293 * the extended message preamble.
4295 if (ahd
->msgin_index
< (MSG_EXT_SDTR_LEN
+ 1))
4298 period
= ahd
->msgin_buf
[3];
4300 saved_offset
= offset
= ahd
->msgin_buf
[4];
4301 ahd_devlimited_syncrate(ahd
, tinfo
, &period
,
4302 &ppr_options
, devinfo
->role
);
4303 ahd_validate_offset(ahd
, tinfo
, period
, &offset
,
4304 tinfo
->curr
.width
, devinfo
->role
);
4306 printf("(%s:%c:%d:%d): Received "
4307 "SDTR period %x, offset %x\n\t"
4308 "Filtered to period %x, offset %x\n",
4309 ahd_name(ahd
), devinfo
->channel
,
4310 devinfo
->target
, devinfo
->lun
,
4311 ahd
->msgin_buf
[3], saved_offset
,
4314 ahd_set_syncrate(ahd
, devinfo
, period
,
4315 offset
, ppr_options
,
4316 AHD_TRANS_ACTIVE
|AHD_TRANS_GOAL
,
4320 * See if we initiated Sync Negotiation
4321 * and didn't have to fall down to async
4324 if (ahd_sent_msg(ahd
, AHDMSG_EXT
, MSG_EXT_SDTR
, TRUE
)) {
4326 if (saved_offset
!= offset
) {
4327 /* Went too low - force async */
4332 * Send our own SDTR in reply
4335 && devinfo
->role
== ROLE_INITIATOR
) {
4336 printf("(%s:%c:%d:%d): Target "
4338 ahd_name(ahd
), devinfo
->channel
,
4339 devinfo
->target
, devinfo
->lun
);
4341 ahd
->msgout_index
= 0;
4342 ahd
->msgout_len
= 0;
4343 ahd_construct_sdtr(ahd
, devinfo
,
4345 ahd
->msgout_index
= 0;
4348 done
= MSGLOOP_MSGCOMPLETE
;
4355 u_int sending_reply
;
4357 sending_reply
= FALSE
;
4358 if (ahd
->msgin_buf
[1] != MSG_EXT_WDTR_LEN
) {
4364 * Wait until we have our arg before validating
4365 * and acting on this message.
4367 * Add one to MSG_EXT_WDTR_LEN to account for
4368 * the extended message preamble.
4370 if (ahd
->msgin_index
< (MSG_EXT_WDTR_LEN
+ 1))
4373 bus_width
= ahd
->msgin_buf
[3];
4374 saved_width
= bus_width
;
4375 ahd_validate_width(ahd
, tinfo
, &bus_width
,
4378 printf("(%s:%c:%d:%d): Received WDTR "
4379 "%x filtered to %x\n",
4380 ahd_name(ahd
), devinfo
->channel
,
4381 devinfo
->target
, devinfo
->lun
,
4382 saved_width
, bus_width
);
4385 if (ahd_sent_msg(ahd
, AHDMSG_EXT
, MSG_EXT_WDTR
, TRUE
)) {
4387 * Don't send a WDTR back to the
4388 * target, since we asked first.
4389 * If the width went higher than our
4390 * request, reject it.
4392 if (saved_width
> bus_width
) {
4394 printf("(%s:%c:%d:%d): requested %dBit "
4395 "transfers. Rejecting...\n",
4396 ahd_name(ahd
), devinfo
->channel
,
4397 devinfo
->target
, devinfo
->lun
,
4398 8 * (0x01 << bus_width
));
4403 * Send our own WDTR in reply
4406 && devinfo
->role
== ROLE_INITIATOR
) {
4407 printf("(%s:%c:%d:%d): Target "
4409 ahd_name(ahd
), devinfo
->channel
,
4410 devinfo
->target
, devinfo
->lun
);
4412 ahd
->msgout_index
= 0;
4413 ahd
->msgout_len
= 0;
4414 ahd_construct_wdtr(ahd
, devinfo
, bus_width
);
4415 ahd
->msgout_index
= 0;
4417 sending_reply
= TRUE
;
4420 * After a wide message, we are async, but
4421 * some devices don't seem to honor this portion
4422 * of the spec. Force a renegotiation of the
4423 * sync component of our transfer agreement even
4424 * if our goal is async. By updating our width
4425 * after forcing the negotiation, we avoid
4426 * renegotiating for width.
4428 ahd_update_neg_request(ahd
, devinfo
, tstate
,
4429 tinfo
, AHD_NEG_ALWAYS
);
4430 ahd_set_width(ahd
, devinfo
, bus_width
,
4431 AHD_TRANS_ACTIVE
|AHD_TRANS_GOAL
,
4433 if (sending_reply
== FALSE
&& reject
== FALSE
) {
4436 * We will always have an SDTR to send.
4438 ahd
->msgout_index
= 0;
4439 ahd
->msgout_len
= 0;
4440 ahd_build_transfer_msg(ahd
, devinfo
);
4441 ahd
->msgout_index
= 0;
4444 done
= MSGLOOP_MSGCOMPLETE
;
4455 u_int saved_ppr_options
;
4457 if (ahd
->msgin_buf
[1] != MSG_EXT_PPR_LEN
) {
4463 * Wait until we have all args before validating
4464 * and acting on this message.
4466 * Add one to MSG_EXT_PPR_LEN to account for
4467 * the extended message preamble.
4469 if (ahd
->msgin_index
< (MSG_EXT_PPR_LEN
+ 1))
4472 period
= ahd
->msgin_buf
[3];
4473 offset
= ahd
->msgin_buf
[5];
4474 bus_width
= ahd
->msgin_buf
[6];
4475 saved_width
= bus_width
;
4476 ppr_options
= ahd
->msgin_buf
[7];
4478 * According to the spec, a DT only
4479 * period factor with no DT option
4480 * set implies async.
4482 if ((ppr_options
& MSG_EXT_PPR_DT_REQ
) == 0
4485 saved_ppr_options
= ppr_options
;
4486 saved_offset
= offset
;
4489 * Transfer options are only available if we
4490 * are negotiating wide.
4493 ppr_options
&= MSG_EXT_PPR_QAS_REQ
;
4495 ahd_validate_width(ahd
, tinfo
, &bus_width
,
4497 ahd_devlimited_syncrate(ahd
, tinfo
, &period
,
4498 &ppr_options
, devinfo
->role
);
4499 ahd_validate_offset(ahd
, tinfo
, period
, &offset
,
4500 bus_width
, devinfo
->role
);
4502 if (ahd_sent_msg(ahd
, AHDMSG_EXT
, MSG_EXT_PPR
, TRUE
)) {
4504 * If we are unable to do any of the
4505 * requested options (we went too low),
4506 * then we'll have to reject the message.
4508 if (saved_width
> bus_width
4509 || saved_offset
!= offset
4510 || saved_ppr_options
!= ppr_options
) {
4518 if (devinfo
->role
!= ROLE_TARGET
)
4519 printf("(%s:%c:%d:%d): Target "
4521 ahd_name(ahd
), devinfo
->channel
,
4522 devinfo
->target
, devinfo
->lun
);
4524 printf("(%s:%c:%d:%d): Initiator "
4526 ahd_name(ahd
), devinfo
->channel
,
4527 devinfo
->target
, devinfo
->lun
);
4528 ahd
->msgout_index
= 0;
4529 ahd
->msgout_len
= 0;
4530 ahd_construct_ppr(ahd
, devinfo
, period
, offset
,
4531 bus_width
, ppr_options
);
4532 ahd
->msgout_index
= 0;
4536 printf("(%s:%c:%d:%d): Received PPR width %x, "
4537 "period %x, offset %x,options %x\n"
4538 "\tFiltered to width %x, period %x, "
4539 "offset %x, options %x\n",
4540 ahd_name(ahd
), devinfo
->channel
,
4541 devinfo
->target
, devinfo
->lun
,
4542 saved_width
, ahd
->msgin_buf
[3],
4543 saved_offset
, saved_ppr_options
,
4544 bus_width
, period
, offset
, ppr_options
);
4546 ahd_set_width(ahd
, devinfo
, bus_width
,
4547 AHD_TRANS_ACTIVE
|AHD_TRANS_GOAL
,
4549 ahd_set_syncrate(ahd
, devinfo
, period
,
4550 offset
, ppr_options
,
4551 AHD_TRANS_ACTIVE
|AHD_TRANS_GOAL
,
4554 done
= MSGLOOP_MSGCOMPLETE
;
4558 /* Unknown extended message. Reject it. */
4564 #ifdef AHD_TARGET_MODE
4565 case MSG_BUS_DEV_RESET
:
4566 ahd_handle_devreset(ahd
, devinfo
, CAM_LUN_WILDCARD
,
4568 "Bus Device Reset Received",
4569 /*verbose_level*/0);
4571 done
= MSGLOOP_TERMINATED
;
4575 case MSG_CLEAR_QUEUE
:
4579 /* Target mode messages */
4580 if (devinfo
->role
!= ROLE_TARGET
) {
4584 tag
= SCB_LIST_NULL
;
4585 if (ahd
->msgin_buf
[0] == MSG_ABORT_TAG
)
4586 tag
= ahd_inb(ahd
, INITIATOR_TAG
);
4587 ahd_abort_scbs(ahd
, devinfo
->target
, devinfo
->channel
,
4588 devinfo
->lun
, tag
, ROLE_TARGET
,
4591 tstate
= ahd
->enabled_targets
[devinfo
->our_scsiid
];
4592 if (tstate
!= NULL
) {
4593 struct ahd_tmode_lstate
* lstate
;
4595 lstate
= tstate
->enabled_luns
[devinfo
->lun
];
4596 if (lstate
!= NULL
) {
4597 ahd_queue_lstate_event(ahd
, lstate
,
4598 devinfo
->our_scsiid
,
4601 ahd_send_lstate_events(ahd
, lstate
);
4605 done
= MSGLOOP_TERMINATED
;
4609 case MSG_QAS_REQUEST
:
4611 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
4612 printf("%s: QAS request. SCSISIGI == 0x%x\n",
4613 ahd_name(ahd
), ahd_inb(ahd
, SCSISIGI
));
4615 ahd
->msg_flags
|= MSG_FLAG_EXPECT_QASREJ_BUSFREE
;
4617 case MSG_TERM_IO_PROC
:
4625 * Setup to reject the message.
4627 ahd
->msgout_index
= 0;
4628 ahd
->msgout_len
= 1;
4629 ahd
->msgout_buf
[0] = MSG_MESSAGE_REJECT
;
4630 done
= MSGLOOP_MSGCOMPLETE
;
4634 if (done
!= MSGLOOP_IN_PROG
&& !response
)
4635 /* Clear the outgoing message buffer */
4636 ahd
->msgout_len
= 0;
4642 * Process a message reject message.
4645 ahd_handle_msg_reject(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
)
4648 * What we care about here is if we had an
4649 * outstanding SDTR or WDTR message for this
4650 * target. If we did, this is a signal that
4651 * the target is refusing negotiation.
4654 struct ahd_initiator_tinfo
*tinfo
;
4655 struct ahd_tmode_tstate
*tstate
;
4660 scb_index
= ahd_get_scbptr(ahd
);
4661 scb
= ahd_lookup_scb(ahd
, scb_index
);
4662 tinfo
= ahd_fetch_transinfo(ahd
, devinfo
->channel
,
4663 devinfo
->our_scsiid
,
4664 devinfo
->target
, &tstate
);
4665 /* Might be necessary */
4666 last_msg
= ahd_inb(ahd
, LAST_MSG
);
4668 if (ahd_sent_msg(ahd
, AHDMSG_EXT
, MSG_EXT_PPR
, /*full*/FALSE
)) {
4669 if (ahd_sent_msg(ahd
, AHDMSG_EXT
, MSG_EXT_PPR
, /*full*/TRUE
)
4670 && tinfo
->goal
.period
<= AHD_SYNCRATE_PACED
) {
4672 * Target may not like our SPI-4 PPR Options.
4673 * Attempt to negotiate 80MHz which will turn
4674 * off these options.
4677 printf("(%s:%c:%d:%d): PPR Rejected. "
4678 "Trying simple U160 PPR\n",
4679 ahd_name(ahd
), devinfo
->channel
,
4680 devinfo
->target
, devinfo
->lun
);
4682 tinfo
->goal
.period
= AHD_SYNCRATE_DT
;
4683 tinfo
->goal
.ppr_options
&= MSG_EXT_PPR_IU_REQ
4684 | MSG_EXT_PPR_QAS_REQ
4685 | MSG_EXT_PPR_DT_REQ
;
4688 * Target does not support the PPR message.
4689 * Attempt to negotiate SPI-2 style.
4692 printf("(%s:%c:%d:%d): PPR Rejected. "
4693 "Trying WDTR/SDTR\n",
4694 ahd_name(ahd
), devinfo
->channel
,
4695 devinfo
->target
, devinfo
->lun
);
4697 tinfo
->goal
.ppr_options
= 0;
4698 tinfo
->curr
.transport_version
= 2;
4699 tinfo
->goal
.transport_version
= 2;
4701 ahd
->msgout_index
= 0;
4702 ahd
->msgout_len
= 0;
4703 ahd_build_transfer_msg(ahd
, devinfo
);
4704 ahd
->msgout_index
= 0;
4706 } else if (ahd_sent_msg(ahd
, AHDMSG_EXT
, MSG_EXT_WDTR
, /*full*/FALSE
)) {
4708 /* note 8bit xfers */
4709 printf("(%s:%c:%d:%d): refuses WIDE negotiation. Using "
4710 "8bit transfers\n", ahd_name(ahd
),
4711 devinfo
->channel
, devinfo
->target
, devinfo
->lun
);
4712 ahd_set_width(ahd
, devinfo
, MSG_EXT_WDTR_BUS_8_BIT
,
4713 AHD_TRANS_ACTIVE
|AHD_TRANS_GOAL
,
4716 * No need to clear the sync rate. If the target
4717 * did not accept the command, our syncrate is
4718 * unaffected. If the target started the negotiation,
4719 * but rejected our response, we already cleared the
4720 * sync rate before sending our WDTR.
4722 if (tinfo
->goal
.offset
!= tinfo
->curr
.offset
) {
4724 /* Start the sync negotiation */
4725 ahd
->msgout_index
= 0;
4726 ahd
->msgout_len
= 0;
4727 ahd_build_transfer_msg(ahd
, devinfo
);
4728 ahd
->msgout_index
= 0;
4731 } else if (ahd_sent_msg(ahd
, AHDMSG_EXT
, MSG_EXT_SDTR
, /*full*/FALSE
)) {
4732 /* note asynch xfers and clear flag */
4733 ahd_set_syncrate(ahd
, devinfo
, /*period*/0,
4734 /*offset*/0, /*ppr_options*/0,
4735 AHD_TRANS_ACTIVE
|AHD_TRANS_GOAL
,
4737 printf("(%s:%c:%d:%d): refuses synchronous negotiation. "
4738 "Using asynchronous transfers\n",
4739 ahd_name(ahd
), devinfo
->channel
,
4740 devinfo
->target
, devinfo
->lun
);
4741 } else if ((scb
->hscb
->control
& MSG_SIMPLE_TASK
) != 0) {
4745 tag_type
= (scb
->hscb
->control
& MSG_SIMPLE_TASK
);
4747 if (tag_type
== MSG_SIMPLE_TASK
) {
4748 printf("(%s:%c:%d:%d): refuses tagged commands. "
4749 "Performing non-tagged I/O\n", ahd_name(ahd
),
4750 devinfo
->channel
, devinfo
->target
, devinfo
->lun
);
4751 ahd_set_tags(ahd
, scb
->io_ctx
, devinfo
, AHD_QUEUE_NONE
);
4754 printf("(%s:%c:%d:%d): refuses %s tagged commands. "
4755 "Performing simple queue tagged I/O only\n",
4756 ahd_name(ahd
), devinfo
->channel
, devinfo
->target
,
4757 devinfo
->lun
, tag_type
== MSG_ORDERED_TASK
4758 ? "ordered" : "head of queue");
4759 ahd_set_tags(ahd
, scb
->io_ctx
, devinfo
, AHD_QUEUE_BASIC
);
4764 * Resend the identify for this CCB as the target
4765 * may believe that the selection is invalid otherwise.
4767 ahd_outb(ahd
, SCB_CONTROL
,
4768 ahd_inb_scbram(ahd
, SCB_CONTROL
) & mask
);
4769 scb
->hscb
->control
&= mask
;
4770 ahd_set_transaction_tag(scb
, /*enabled*/FALSE
,
4771 /*type*/MSG_SIMPLE_TASK
);
4772 ahd_outb(ahd
, MSG_OUT
, MSG_IDENTIFYFLAG
);
4773 ahd_assert_atn(ahd
);
4774 ahd_busy_tcl(ahd
, BUILD_TCL(scb
->hscb
->scsiid
, devinfo
->lun
),
4778 * Requeue all tagged commands for this target
4779 * currently in our posession so they can be
4780 * converted to untagged commands.
4782 ahd_search_qinfifo(ahd
, SCB_GET_TARGET(ahd
, scb
),
4783 SCB_GET_CHANNEL(ahd
, scb
),
4784 SCB_GET_LUN(scb
), /*tag*/SCB_LIST_NULL
,
4785 ROLE_INITIATOR
, CAM_REQUEUE_REQ
,
4787 } else if (ahd_sent_msg(ahd
, AHDMSG_1B
, MSG_IDENTIFYFLAG
, TRUE
)) {
4789 * Most likely the device believes that we had
4790 * previously negotiated packetized.
4792 ahd
->msg_flags
|= MSG_FLAG_EXPECT_PPR_BUSFREE
4793 | MSG_FLAG_IU_REQ_CHANGED
;
4795 ahd_force_renegotiation(ahd
, devinfo
);
4796 ahd
->msgout_index
= 0;
4797 ahd
->msgout_len
= 0;
4798 ahd_build_transfer_msg(ahd
, devinfo
);
4799 ahd
->msgout_index
= 0;
4803 * Otherwise, we ignore it.
4805 printf("%s:%c:%d: Message reject for %x -- ignored\n",
4806 ahd_name(ahd
), devinfo
->channel
, devinfo
->target
,
4813 * Process an ingnore wide residue message.
4816 ahd_handle_ign_wide_residue(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
)
4821 scb_index
= ahd_get_scbptr(ahd
);
4822 scb
= ahd_lookup_scb(ahd
, scb_index
);
4824 * XXX Actually check data direction in the sequencer?
4825 * Perhaps add datadir to some spare bits in the hscb?
4827 if ((ahd_inb(ahd
, SEQ_FLAGS
) & DPHASE
) == 0
4828 || ahd_get_transfer_dir(scb
) != CAM_DIR_IN
) {
4830 * Ignore the message if we haven't
4831 * seen an appropriate data phase yet.
4835 * If the residual occurred on the last
4836 * transfer and the transfer request was
4837 * expected to end on an odd count, do
4838 * nothing. Otherwise, subtract a byte
4839 * and update the residual count accordingly.
4843 sgptr
= ahd_inb_scbram(ahd
, SCB_RESIDUAL_SGPTR
);
4844 if ((sgptr
& SG_LIST_NULL
) != 0
4845 && (ahd_inb_scbram(ahd
, SCB_TASK_ATTRIBUTE
)
4846 & SCB_XFERLEN_ODD
) != 0) {
4848 * If the residual occurred on the last
4849 * transfer and the transfer request was
4850 * expected to end on an odd count, do
4858 /* Pull in the rest of the sgptr */
4859 sgptr
= ahd_inl_scbram(ahd
, SCB_RESIDUAL_SGPTR
);
4860 data_cnt
= ahd_inl_scbram(ahd
, SCB_RESIDUAL_DATACNT
);
4861 if ((sgptr
& SG_LIST_NULL
) != 0) {
4863 * The residual data count is not updated
4864 * for the command run to completion case.
4865 * Explicitly zero the count.
4867 data_cnt
&= ~AHD_SG_LEN_MASK
;
4869 data_addr
= ahd_inq(ahd
, SHADDR
);
4872 sgptr
&= SG_PTR_MASK
;
4873 if ((ahd
->flags
& AHD_64BIT_ADDRESSING
) != 0) {
4874 struct ahd_dma64_seg
*sg
;
4876 sg
= ahd_sg_bus_to_virt(ahd
, scb
, sgptr
);
4879 * The residual sg ptr points to the next S/G
4880 * to load so we must go back one.
4883 sglen
= ahd_le32toh(sg
->len
) & AHD_SG_LEN_MASK
;
4884 if (sg
!= scb
->sg_list
4885 && sglen
< (data_cnt
& AHD_SG_LEN_MASK
)) {
4888 sglen
= ahd_le32toh(sg
->len
);
4890 * Preserve High Address and SG_LIST
4891 * bits while setting the count to 1.
4893 data_cnt
= 1|(sglen
&(~AHD_SG_LEN_MASK
));
4894 data_addr
= ahd_le64toh(sg
->addr
)
4895 + (sglen
& AHD_SG_LEN_MASK
)
4899 * Increment sg so it points to the
4903 sgptr
= ahd_sg_virt_to_bus(ahd
, scb
,
4907 struct ahd_dma_seg
*sg
;
4909 sg
= ahd_sg_bus_to_virt(ahd
, scb
, sgptr
);
4912 * The residual sg ptr points to the next S/G
4913 * to load so we must go back one.
4916 sglen
= ahd_le32toh(sg
->len
) & AHD_SG_LEN_MASK
;
4917 if (sg
!= scb
->sg_list
4918 && sglen
< (data_cnt
& AHD_SG_LEN_MASK
)) {
4921 sglen
= ahd_le32toh(sg
->len
);
4923 * Preserve High Address and SG_LIST
4924 * bits while setting the count to 1.
4926 data_cnt
= 1|(sglen
&(~AHD_SG_LEN_MASK
));
4927 data_addr
= ahd_le32toh(sg
->addr
)
4928 + (sglen
& AHD_SG_LEN_MASK
)
4932 * Increment sg so it points to the
4936 sgptr
= ahd_sg_virt_to_bus(ahd
, scb
,
4941 * Toggle the "oddness" of the transfer length
4942 * to handle this mid-transfer ignore wide
4943 * residue. This ensures that the oddness is
4944 * correct for subsequent data transfers.
4946 ahd_outb(ahd
, SCB_TASK_ATTRIBUTE
,
4947 ahd_inb_scbram(ahd
, SCB_TASK_ATTRIBUTE
)
4950 ahd_outl(ahd
, SCB_RESIDUAL_SGPTR
, sgptr
);
4951 ahd_outl(ahd
, SCB_RESIDUAL_DATACNT
, data_cnt
);
4953 * The FIFO's pointers will be updated if/when the
4954 * sequencer re-enters a data phase.
4962 * Reinitialize the data pointers for the active transfer
4963 * based on its current residual.
4966 ahd_reinitialize_dataptrs(struct ahd_softc
*ahd
)
4969 ahd_mode_state saved_modes
;
4976 AHD_ASSERT_MODES(ahd
, AHD_MODE_DFF0_MSK
|AHD_MODE_DFF1_MSK
,
4977 AHD_MODE_DFF0_MSK
|AHD_MODE_DFF1_MSK
);
4979 scb_index
= ahd_get_scbptr(ahd
);
4980 scb
= ahd_lookup_scb(ahd
, scb_index
);
4983 * Release and reacquire the FIFO so we
4984 * have a clean slate.
4986 ahd_outb(ahd
, DFFSXFRCTL
, CLRCHN
);
4988 while (--wait
&& !(ahd_inb(ahd
, MDFFSTAT
) & FIFOFREE
))
4991 ahd_print_path(ahd
, scb
);
4992 printf("ahd_reinitialize_dataptrs: Forcing FIFO free.\n");
4993 ahd_outb(ahd
, DFFSXFRCTL
, RSTCHN
|CLRSHCNT
);
4995 saved_modes
= ahd_save_modes(ahd
);
4996 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
4997 ahd_outb(ahd
, DFFSTAT
,
4998 ahd_inb(ahd
, DFFSTAT
)
4999 | (saved_modes
== 0x11 ? CURRFIFO_1
: CURRFIFO_0
));
5002 * Determine initial values for data_addr and data_cnt
5003 * for resuming the data phase.
5005 sgptr
= ahd_inl_scbram(ahd
, SCB_RESIDUAL_SGPTR
);
5006 sgptr
&= SG_PTR_MASK
;
5008 resid
= (ahd_inb_scbram(ahd
, SCB_RESIDUAL_DATACNT
+ 2) << 16)
5009 | (ahd_inb_scbram(ahd
, SCB_RESIDUAL_DATACNT
+ 1) << 8)
5010 | ahd_inb_scbram(ahd
, SCB_RESIDUAL_DATACNT
);
5012 if ((ahd
->flags
& AHD_64BIT_ADDRESSING
) != 0) {
5013 struct ahd_dma64_seg
*sg
;
5015 sg
= ahd_sg_bus_to_virt(ahd
, scb
, sgptr
);
5017 /* The residual sg_ptr always points to the next sg */
5020 dataptr
= ahd_le64toh(sg
->addr
)
5021 + (ahd_le32toh(sg
->len
) & AHD_SG_LEN_MASK
)
5023 ahd_outl(ahd
, HADDR
+ 4, dataptr
>> 32);
5025 struct ahd_dma_seg
*sg
;
5027 sg
= ahd_sg_bus_to_virt(ahd
, scb
, sgptr
);
5029 /* The residual sg_ptr always points to the next sg */
5032 dataptr
= ahd_le32toh(sg
->addr
)
5033 + (ahd_le32toh(sg
->len
) & AHD_SG_LEN_MASK
)
5035 ahd_outb(ahd
, HADDR
+ 4,
5036 (ahd_le32toh(sg
->len
) & ~AHD_SG_LEN_MASK
) >> 24);
5038 ahd_outl(ahd
, HADDR
, dataptr
);
5039 ahd_outb(ahd
, HCNT
+ 2, resid
>> 16);
5040 ahd_outb(ahd
, HCNT
+ 1, resid
>> 8);
5041 ahd_outb(ahd
, HCNT
, resid
);
5045 * Handle the effects of issuing a bus device reset message.
5048 ahd_handle_devreset(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
,
5049 u_int lun
, cam_status status
, char *message
,
5052 #ifdef AHD_TARGET_MODE
5053 struct ahd_tmode_tstate
* tstate
;
5057 found
= ahd_abort_scbs(ahd
, devinfo
->target
, devinfo
->channel
,
5058 lun
, SCB_LIST_NULL
, devinfo
->role
,
5061 #ifdef AHD_TARGET_MODE
5063 * Send an immediate notify ccb to all target mord peripheral
5064 * drivers affected by this action.
5066 tstate
= ahd
->enabled_targets
[devinfo
->our_scsiid
];
5067 if (tstate
!= NULL
) {
5071 if (lun
!= CAM_LUN_WILDCARD
) {
5073 max_lun
= AHD_NUM_LUNS
- 1;
5078 for (cur_lun
<= max_lun
; cur_lun
++) {
5079 struct ahd_tmode_lstate
* lstate
;
5081 lstate
= tstate
->enabled_luns
[cur_lun
];
5085 ahd_queue_lstate_event(ahd
, lstate
, devinfo
->our_scsiid
,
5086 MSG_BUS_DEV_RESET
, /*arg*/0);
5087 ahd_send_lstate_events(ahd
, lstate
);
5093 * Go back to async/narrow transfers and renegotiate.
5095 ahd_set_width(ahd
, devinfo
, MSG_EXT_WDTR_BUS_8_BIT
,
5096 AHD_TRANS_CUR
, /*paused*/TRUE
);
5097 ahd_set_syncrate(ahd
, devinfo
, /*period*/0, /*offset*/0,
5098 /*ppr_options*/0, AHD_TRANS_CUR
,
5101 if (status
!= CAM_SEL_TIMEOUT
)
5102 ahd_send_async(ahd
, devinfo
->channel
, devinfo
->target
,
5103 CAM_LUN_WILDCARD
, AC_SENT_BDR
);
5105 if (message
!= NULL
&& bootverbose
)
5106 printf("%s: %s on %c:%d. %d SCBs aborted\n", ahd_name(ahd
),
5107 message
, devinfo
->channel
, devinfo
->target
, found
);
5110 #ifdef AHD_TARGET_MODE
5112 ahd_setup_target_msgin(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
,
5117 * To facilitate adding multiple messages together,
5118 * each routine should increment the index and len
5119 * variables instead of setting them explicitly.
5121 ahd
->msgout_index
= 0;
5122 ahd
->msgout_len
= 0;
5124 if (scb
!= NULL
&& (scb
->flags
& SCB_AUTO_NEGOTIATE
) != 0)
5125 ahd_build_transfer_msg(ahd
, devinfo
);
5127 panic("ahd_intr: AWAITING target message with no message");
5129 ahd
->msgout_index
= 0;
5130 ahd
->msg_type
= MSG_TYPE_TARGET_MSGIN
;
5133 /**************************** Initialization **********************************/
5135 ahd_sglist_size(struct ahd_softc
*ahd
)
5137 bus_size_t list_size
;
5139 list_size
= sizeof(struct ahd_dma_seg
) * AHD_NSEG
;
5140 if ((ahd
->flags
& AHD_64BIT_ADDRESSING
) != 0)
5141 list_size
= sizeof(struct ahd_dma64_seg
) * AHD_NSEG
;
5146 * Calculate the optimum S/G List allocation size. S/G elements used
5147 * for a given transaction must be physically contiguous. Assume the
5148 * OS will allocate full pages to us, so it doesn't make sense to request
5152 ahd_sglist_allocsize(struct ahd_softc
*ahd
)
5154 bus_size_t sg_list_increment
;
5155 bus_size_t sg_list_size
;
5156 bus_size_t max_list_size
;
5157 bus_size_t best_list_size
;
5159 /* Start out with the minimum required for AHD_NSEG. */
5160 sg_list_increment
= ahd_sglist_size(ahd
);
5161 sg_list_size
= sg_list_increment
;
5163 /* Get us as close as possible to a page in size. */
5164 while ((sg_list_size
+ sg_list_increment
) <= PAGE_SIZE
)
5165 sg_list_size
+= sg_list_increment
;
5168 * Try to reduce the amount of wastage by allocating
5171 best_list_size
= sg_list_size
;
5172 max_list_size
= roundup(sg_list_increment
, PAGE_SIZE
);
5173 if (max_list_size
< 4 * PAGE_SIZE
)
5174 max_list_size
= 4 * PAGE_SIZE
;
5175 if (max_list_size
> (AHD_SCB_MAX_ALLOC
* sg_list_increment
))
5176 max_list_size
= (AHD_SCB_MAX_ALLOC
* sg_list_increment
);
5177 while ((sg_list_size
+ sg_list_increment
) <= max_list_size
5178 && (sg_list_size
% PAGE_SIZE
) != 0) {
5180 bus_size_t best_mod
;
5182 sg_list_size
+= sg_list_increment
;
5183 new_mod
= sg_list_size
% PAGE_SIZE
;
5184 best_mod
= best_list_size
% PAGE_SIZE
;
5185 if (new_mod
> best_mod
|| new_mod
== 0) {
5186 best_list_size
= sg_list_size
;
5189 return (best_list_size
);
5193 * Allocate a controller structure for a new device
5194 * and perform initial initializion.
5197 ahd_alloc(void *platform_arg
, char *name
)
5199 struct ahd_softc
*ahd
;
5202 ahd
= malloc(sizeof(*ahd
), M_DEVBUF
, M_NOWAIT
);
5204 printf("aic7xxx: cannot malloc softc!\n");
5205 free(name
, M_DEVBUF
);
5209 ahd
= device_get_softc((device_t
)platform_arg
);
5211 memset(ahd
, 0, sizeof(*ahd
));
5212 ahd
->seep_config
= malloc(sizeof(*ahd
->seep_config
),
5213 M_DEVBUF
, M_NOWAIT
);
5214 if (ahd
->seep_config
== NULL
) {
5216 free(ahd
, M_DEVBUF
);
5218 free(name
, M_DEVBUF
);
5221 LIST_INIT(&ahd
->pending_scbs
);
5222 /* We don't know our unit number until the OSM sets it */
5225 ahd
->description
= NULL
;
5226 ahd
->bus_description
= NULL
;
5228 ahd
->chip
= AHD_NONE
;
5229 ahd
->features
= AHD_FENONE
;
5230 ahd
->bugs
= AHD_BUGNONE
;
5231 ahd
->flags
= AHD_SPCHK_ENB_A
|AHD_RESET_BUS_A
|AHD_TERM_ENB_A
5232 | AHD_EXTENDED_TRANS_A
|AHD_STPWLEVEL_A
;
5233 ahd_timer_init(&ahd
->reset_timer
);
5234 ahd_timer_init(&ahd
->stat_timer
);
5235 ahd
->int_coalescing_timer
= AHD_INT_COALESCING_TIMER_DEFAULT
;
5236 ahd
->int_coalescing_maxcmds
= AHD_INT_COALESCING_MAXCMDS_DEFAULT
;
5237 ahd
->int_coalescing_mincmds
= AHD_INT_COALESCING_MINCMDS_DEFAULT
;
5238 ahd
->int_coalescing_threshold
= AHD_INT_COALESCING_THRESHOLD_DEFAULT
;
5239 ahd
->int_coalescing_stop_threshold
=
5240 AHD_INT_COALESCING_STOP_THRESHOLD_DEFAULT
;
5242 if (ahd_platform_alloc(ahd
, platform_arg
) != 0) {
5247 if ((ahd_debug
& AHD_SHOW_MEMORY
) != 0) {
5248 printf("%s: scb size = 0x%x, hscb size = 0x%x\n",
5249 ahd_name(ahd
), (u_int
)sizeof(struct scb
),
5250 (u_int
)sizeof(struct hardware_scb
));
5257 ahd_softc_init(struct ahd_softc
*ahd
)
5266 ahd_set_unit(struct ahd_softc
*ahd
, int unit
)
5272 ahd_set_name(struct ahd_softc
*ahd
, char *name
)
5274 if (ahd
->name
!= NULL
)
5275 free(ahd
->name
, M_DEVBUF
);
5280 ahd_free(struct ahd_softc
*ahd
)
5284 switch (ahd
->init_level
) {
5290 ahd_dmamap_unload(ahd
, ahd
->shared_data_dmat
,
5291 ahd
->shared_data_map
.dmamap
);
5294 ahd_dmamem_free(ahd
, ahd
->shared_data_dmat
, ahd
->qoutfifo
,
5295 ahd
->shared_data_map
.dmamap
);
5296 ahd_dmamap_destroy(ahd
, ahd
->shared_data_dmat
,
5297 ahd
->shared_data_map
.dmamap
);
5300 ahd_dma_tag_destroy(ahd
, ahd
->shared_data_dmat
);
5303 ahd_dma_tag_destroy(ahd
, ahd
->buffer_dmat
);
5311 ahd_dma_tag_destroy(ahd
, ahd
->parent_dmat
);
5313 ahd_platform_free(ahd
);
5314 ahd_fini_scbdata(ahd
);
5315 for (i
= 0; i
< AHD_NUM_TARGETS
; i
++) {
5316 struct ahd_tmode_tstate
*tstate
;
5318 tstate
= ahd
->enabled_targets
[i
];
5319 if (tstate
!= NULL
) {
5320 #ifdef AHD_TARGET_MODE
5323 for (j
= 0; j
< AHD_NUM_LUNS
; j
++) {
5324 struct ahd_tmode_lstate
*lstate
;
5326 lstate
= tstate
->enabled_luns
[j
];
5327 if (lstate
!= NULL
) {
5328 xpt_free_path(lstate
->path
);
5329 free(lstate
, M_DEVBUF
);
5333 free(tstate
, M_DEVBUF
);
5336 #ifdef AHD_TARGET_MODE
5337 if (ahd
->black_hole
!= NULL
) {
5338 xpt_free_path(ahd
->black_hole
->path
);
5339 free(ahd
->black_hole
, M_DEVBUF
);
5342 if (ahd
->name
!= NULL
)
5343 free(ahd
->name
, M_DEVBUF
);
5344 if (ahd
->seep_config
!= NULL
)
5345 free(ahd
->seep_config
, M_DEVBUF
);
5346 if (ahd
->saved_stack
!= NULL
)
5347 free(ahd
->saved_stack
, M_DEVBUF
);
5349 free(ahd
, M_DEVBUF
);
5355 ahd_shutdown(void *arg
)
5357 struct ahd_softc
*ahd
;
5359 ahd
= (struct ahd_softc
*)arg
;
5362 * Stop periodic timer callbacks.
5364 ahd_timer_stop(&ahd
->reset_timer
);
5365 ahd_timer_stop(&ahd
->stat_timer
);
5367 /* This will reset most registers to 0, but not all */
5368 ahd_reset(ahd
, /*reinit*/FALSE
);
5372 * Reset the controller and record some information about it
5373 * that is only available just after a reset. If "reinit" is
5374 * non-zero, this reset occured after initial configuration
5375 * and the caller requests that the chip be fully reinitialized
5376 * to a runable state. Chip interrupts are *not* enabled after
5377 * a reinitialization. The caller must enable interrupts via
5378 * ahd_intr_enable().
5381 ahd_reset(struct ahd_softc
*ahd
, int reinit
)
5388 * Preserve the value of the SXFRCTL1 register for all channels.
5389 * It contains settings that affect termination and we don't want
5390 * to disturb the integrity of the bus.
5393 ahd_update_modes(ahd
);
5394 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
5395 sxfrctl1
= ahd_inb(ahd
, SXFRCTL1
);
5397 cmd
= ahd_pci_read_config(ahd
->dev_softc
, PCIR_COMMAND
, /*bytes*/2);
5398 if ((ahd
->bugs
& AHD_PCIX_CHIPRST_BUG
) != 0) {
5403 * During the assertion of CHIPRST, the chip
5404 * does not disable its parity logic prior to
5405 * the start of the reset. This may cause a
5406 * parity error to be detected and thus a
5407 * spurious SERR or PERR assertion. Disble
5408 * PERR and SERR responses during the CHIPRST.
5410 mod_cmd
= cmd
& ~(PCIM_CMD_PERRESPEN
|PCIM_CMD_SERRESPEN
);
5411 ahd_pci_write_config(ahd
->dev_softc
, PCIR_COMMAND
,
5412 mod_cmd
, /*bytes*/2);
5414 ahd_outb(ahd
, HCNTRL
, CHIPRST
| ahd
->pause
);
5417 * Ensure that the reset has finished. We delay 1000us
5418 * prior to reading the register to make sure the chip
5419 * has sufficiently completed its reset to handle register
5425 } while (--wait
&& !(ahd_inb(ahd
, HCNTRL
) & CHIPRSTACK
));
5428 printf("%s: WARNING - Failed chip reset! "
5429 "Trying to initialize anyway.\n", ahd_name(ahd
));
5431 ahd_outb(ahd
, HCNTRL
, ahd
->pause
);
5433 if ((ahd
->bugs
& AHD_PCIX_CHIPRST_BUG
) != 0) {
5435 * Clear any latched PCI error status and restore
5436 * previous SERR and PERR response enables.
5438 ahd_pci_write_config(ahd
->dev_softc
, PCIR_STATUS
+ 1,
5440 ahd_pci_write_config(ahd
->dev_softc
, PCIR_COMMAND
,
5445 * Mode should be SCSI after a chip reset, but lets
5446 * set it just to be safe. We touch the MODE_PTR
5447 * register directly so as to bypass the lazy update
5448 * code in ahd_set_modes().
5450 ahd_known_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
5451 ahd_outb(ahd
, MODE_PTR
,
5452 ahd_build_mode_state(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
));
5457 * We must always initialize STPWEN to 1 before we
5458 * restore the saved values. STPWEN is initialized
5459 * to a tri-state condition which can only be cleared
5462 ahd_outb(ahd
, SXFRCTL1
, sxfrctl1
|STPWEN
);
5463 ahd_outb(ahd
, SXFRCTL1
, sxfrctl1
);
5465 /* Determine chip configuration */
5466 ahd
->features
&= ~AHD_WIDE
;
5467 if ((ahd_inb(ahd
, SBLKCTL
) & SELWIDE
) != 0)
5468 ahd
->features
|= AHD_WIDE
;
5471 * If a recovery action has forced a chip reset,
5472 * re-initialize the chip to our liking.
5481 * Determine the number of SCBs available on the controller
5484 ahd_probe_scbs(struct ahd_softc
*ahd
) {
5487 AHD_ASSERT_MODES(ahd
, ~(AHD_MODE_UNKNOWN_MSK
|AHD_MODE_CFG_MSK
),
5488 ~(AHD_MODE_UNKNOWN_MSK
|AHD_MODE_CFG_MSK
));
5489 for (i
= 0; i
< AHD_SCB_MAX
; i
++) {
5492 ahd_set_scbptr(ahd
, i
);
5493 ahd_outw(ahd
, SCB_BASE
, i
);
5494 for (j
= 2; j
< 64; j
++)
5495 ahd_outb(ahd
, SCB_BASE
+j
, 0);
5496 /* Start out life as unallocated (needing an abort) */
5497 ahd_outb(ahd
, SCB_CONTROL
, MK_MESSAGE
);
5498 if (ahd_inw_scbram(ahd
, SCB_BASE
) != i
)
5500 ahd_set_scbptr(ahd
, 0);
5501 if (ahd_inw_scbram(ahd
, SCB_BASE
) != 0)
5508 ahd_dmamap_cb(void *arg
, bus_dma_segment_t
*segs
, int nseg
, int error
)
5512 baddr
= (dma_addr_t
*)arg
;
5513 *baddr
= segs
->ds_addr
;
5517 ahd_initialize_hscbs(struct ahd_softc
*ahd
)
5521 for (i
= 0; i
< ahd
->scb_data
.maxhscbs
; i
++) {
5522 ahd_set_scbptr(ahd
, i
);
5524 /* Clear the control byte. */
5525 ahd_outb(ahd
, SCB_CONTROL
, 0);
5527 /* Set the next pointer */
5528 ahd_outw(ahd
, SCB_NEXT
, SCB_LIST_NULL
);
5533 ahd_init_scbdata(struct ahd_softc
*ahd
)
5535 struct scb_data
*scb_data
;
5538 scb_data
= &ahd
->scb_data
;
5539 TAILQ_INIT(&scb_data
->free_scbs
);
5540 for (i
= 0; i
< AHD_NUM_TARGETS
* AHD_NUM_LUNS_NONPKT
; i
++)
5541 LIST_INIT(&scb_data
->free_scb_lists
[i
]);
5542 LIST_INIT(&scb_data
->any_dev_free_scb_list
);
5543 SLIST_INIT(&scb_data
->hscb_maps
);
5544 SLIST_INIT(&scb_data
->sg_maps
);
5545 SLIST_INIT(&scb_data
->sense_maps
);
5547 /* Determine the number of hardware SCBs and initialize them */
5548 scb_data
->maxhscbs
= ahd_probe_scbs(ahd
);
5549 if (scb_data
->maxhscbs
== 0) {
5550 printf("%s: No SCB space found\n", ahd_name(ahd
));
5554 ahd_initialize_hscbs(ahd
);
5557 * Create our DMA tags. These tags define the kinds of device
5558 * accessible memory allocations and memory mappings we will
5559 * need to perform during normal operation.
5561 * Unless we need to further restrict the allocation, we rely
5562 * on the restrictions of the parent dmat, hence the common
5563 * use of MAXADDR and MAXSIZE.
5566 /* DMA tag for our hardware scb structures */
5567 if (ahd_dma_tag_create(ahd
, ahd
->parent_dmat
, /*alignment*/1,
5568 /*boundary*/BUS_SPACE_MAXADDR_32BIT
+ 1,
5569 /*lowaddr*/BUS_SPACE_MAXADDR_32BIT
,
5570 /*highaddr*/BUS_SPACE_MAXADDR
,
5571 /*filter*/NULL
, /*filterarg*/NULL
,
5572 PAGE_SIZE
, /*nsegments*/1,
5573 /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT
,
5574 /*flags*/0, &scb_data
->hscb_dmat
) != 0) {
5578 scb_data
->init_level
++;
5580 /* DMA tag for our S/G structures. */
5581 if (ahd_dma_tag_create(ahd
, ahd
->parent_dmat
, /*alignment*/8,
5582 /*boundary*/BUS_SPACE_MAXADDR_32BIT
+ 1,
5583 /*lowaddr*/BUS_SPACE_MAXADDR_32BIT
,
5584 /*highaddr*/BUS_SPACE_MAXADDR
,
5585 /*filter*/NULL
, /*filterarg*/NULL
,
5586 ahd_sglist_allocsize(ahd
), /*nsegments*/1,
5587 /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT
,
5588 /*flags*/0, &scb_data
->sg_dmat
) != 0) {
5592 if ((ahd_debug
& AHD_SHOW_MEMORY
) != 0)
5593 printf("%s: ahd_sglist_allocsize = 0x%x\n", ahd_name(ahd
),
5594 ahd_sglist_allocsize(ahd
));
5597 scb_data
->init_level
++;
5599 /* DMA tag for our sense buffers. We allocate in page sized chunks */
5600 if (ahd_dma_tag_create(ahd
, ahd
->parent_dmat
, /*alignment*/1,
5601 /*boundary*/BUS_SPACE_MAXADDR_32BIT
+ 1,
5602 /*lowaddr*/BUS_SPACE_MAXADDR_32BIT
,
5603 /*highaddr*/BUS_SPACE_MAXADDR
,
5604 /*filter*/NULL
, /*filterarg*/NULL
,
5605 PAGE_SIZE
, /*nsegments*/1,
5606 /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT
,
5607 /*flags*/0, &scb_data
->sense_dmat
) != 0) {
5611 scb_data
->init_level
++;
5613 /* Perform initial CCB allocation */
5614 ahd_alloc_scbs(ahd
);
5616 if (scb_data
->numscbs
== 0) {
5617 printf("%s: ahd_init_scbdata - "
5618 "Unable to allocate initial scbs\n",
5624 * Note that we were successfull
5634 ahd_find_scb_by_tag(struct ahd_softc
*ahd
, u_int tag
)
5639 * Look on the pending list.
5641 LIST_FOREACH(scb
, &ahd
->pending_scbs
, pending_links
) {
5642 if (SCB_GET_TAG(scb
) == tag
)
5647 * Then on all of the collision free lists.
5649 TAILQ_FOREACH(scb
, &ahd
->scb_data
.free_scbs
, links
.tqe
) {
5650 struct scb
*list_scb
;
5654 if (SCB_GET_TAG(list_scb
) == tag
)
5656 list_scb
= LIST_NEXT(list_scb
, collision_links
);
5661 * And finally on the generic free list.
5663 LIST_FOREACH(scb
, &ahd
->scb_data
.any_dev_free_scb_list
, links
.le
) {
5664 if (SCB_GET_TAG(scb
) == tag
)
5672 ahd_fini_scbdata(struct ahd_softc
*ahd
)
5674 struct scb_data
*scb_data
;
5676 scb_data
= &ahd
->scb_data
;
5677 if (scb_data
== NULL
)
5680 switch (scb_data
->init_level
) {
5684 struct map_node
*sns_map
;
5686 while ((sns_map
= SLIST_FIRST(&scb_data
->sense_maps
)) != NULL
) {
5687 SLIST_REMOVE_HEAD(&scb_data
->sense_maps
, links
);
5688 ahd_dmamap_unload(ahd
, scb_data
->sense_dmat
,
5690 ahd_dmamem_free(ahd
, scb_data
->sense_dmat
,
5691 sns_map
->vaddr
, sns_map
->dmamap
);
5692 free(sns_map
, M_DEVBUF
);
5694 ahd_dma_tag_destroy(ahd
, scb_data
->sense_dmat
);
5699 struct map_node
*sg_map
;
5701 while ((sg_map
= SLIST_FIRST(&scb_data
->sg_maps
)) != NULL
) {
5702 SLIST_REMOVE_HEAD(&scb_data
->sg_maps
, links
);
5703 ahd_dmamap_unload(ahd
, scb_data
->sg_dmat
,
5705 ahd_dmamem_free(ahd
, scb_data
->sg_dmat
,
5706 sg_map
->vaddr
, sg_map
->dmamap
);
5707 free(sg_map
, M_DEVBUF
);
5709 ahd_dma_tag_destroy(ahd
, scb_data
->sg_dmat
);
5714 struct map_node
*hscb_map
;
5716 while ((hscb_map
= SLIST_FIRST(&scb_data
->hscb_maps
)) != NULL
) {
5717 SLIST_REMOVE_HEAD(&scb_data
->hscb_maps
, links
);
5718 ahd_dmamap_unload(ahd
, scb_data
->hscb_dmat
,
5720 ahd_dmamem_free(ahd
, scb_data
->hscb_dmat
,
5721 hscb_map
->vaddr
, hscb_map
->dmamap
);
5722 free(hscb_map
, M_DEVBUF
);
5724 ahd_dma_tag_destroy(ahd
, scb_data
->hscb_dmat
);
5737 * DSP filter Bypass must be enabled until the first selection
5738 * after a change in bus mode (Razor #491 and #493).
5741 ahd_setup_iocell_workaround(struct ahd_softc
*ahd
)
5743 ahd_mode_state saved_modes
;
5745 saved_modes
= ahd_save_modes(ahd
);
5746 ahd_set_modes(ahd
, AHD_MODE_CFG
, AHD_MODE_CFG
);
5747 ahd_outb(ahd
, DSPDATACTL
, ahd_inb(ahd
, DSPDATACTL
)
5748 | BYPASSENAB
| RCVROFFSTDIS
| XMITOFFSTDIS
);
5749 ahd_outb(ahd
, SIMODE0
, ahd_inb(ahd
, SIMODE0
) | (ENSELDO
|ENSELDI
));
5751 if ((ahd_debug
& AHD_SHOW_MISC
) != 0)
5752 printf("%s: Setting up iocell workaround\n", ahd_name(ahd
));
5754 ahd_restore_modes(ahd
, saved_modes
);
5755 ahd
->flags
&= ~AHD_HAD_FIRST_SEL
;
5759 ahd_iocell_first_selection(struct ahd_softc
*ahd
)
5761 ahd_mode_state saved_modes
;
5764 if ((ahd
->flags
& AHD_HAD_FIRST_SEL
) != 0)
5766 saved_modes
= ahd_save_modes(ahd
);
5767 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
5768 sblkctl
= ahd_inb(ahd
, SBLKCTL
);
5769 ahd_set_modes(ahd
, AHD_MODE_CFG
, AHD_MODE_CFG
);
5771 if ((ahd_debug
& AHD_SHOW_MISC
) != 0)
5772 printf("%s: iocell first selection\n", ahd_name(ahd
));
5774 if ((sblkctl
& ENAB40
) != 0) {
5775 ahd_outb(ahd
, DSPDATACTL
,
5776 ahd_inb(ahd
, DSPDATACTL
) & ~BYPASSENAB
);
5778 if ((ahd_debug
& AHD_SHOW_MISC
) != 0)
5779 printf("%s: BYPASS now disabled\n", ahd_name(ahd
));
5782 ahd_outb(ahd
, SIMODE0
, ahd_inb(ahd
, SIMODE0
) & ~(ENSELDO
|ENSELDI
));
5783 ahd_outb(ahd
, CLRINT
, CLRSCSIINT
);
5784 ahd_restore_modes(ahd
, saved_modes
);
5785 ahd
->flags
|= AHD_HAD_FIRST_SEL
;
5788 /*************************** SCB Management ***********************************/
5790 ahd_add_col_list(struct ahd_softc
*ahd
, struct scb
*scb
, u_int col_idx
)
5792 struct scb_list
*free_list
;
5793 struct scb_tailq
*free_tailq
;
5794 struct scb
*first_scb
;
5796 scb
->flags
|= SCB_ON_COL_LIST
;
5797 AHD_SET_SCB_COL_IDX(scb
, col_idx
);
5798 free_list
= &ahd
->scb_data
.free_scb_lists
[col_idx
];
5799 free_tailq
= &ahd
->scb_data
.free_scbs
;
5800 first_scb
= LIST_FIRST(free_list
);
5801 if (first_scb
!= NULL
) {
5802 LIST_INSERT_AFTER(first_scb
, scb
, collision_links
);
5804 LIST_INSERT_HEAD(free_list
, scb
, collision_links
);
5805 TAILQ_INSERT_TAIL(free_tailq
, scb
, links
.tqe
);
5810 ahd_rem_col_list(struct ahd_softc
*ahd
, struct scb
*scb
)
5812 struct scb_list
*free_list
;
5813 struct scb_tailq
*free_tailq
;
5814 struct scb
*first_scb
;
5817 scb
->flags
&= ~SCB_ON_COL_LIST
;
5818 col_idx
= AHD_GET_SCB_COL_IDX(ahd
, scb
);
5819 free_list
= &ahd
->scb_data
.free_scb_lists
[col_idx
];
5820 free_tailq
= &ahd
->scb_data
.free_scbs
;
5821 first_scb
= LIST_FIRST(free_list
);
5822 if (first_scb
== scb
) {
5823 struct scb
*next_scb
;
5826 * Maintain order in the collision free
5827 * lists for fairness if this device has
5828 * other colliding tags active.
5830 next_scb
= LIST_NEXT(scb
, collision_links
);
5831 if (next_scb
!= NULL
) {
5832 TAILQ_INSERT_AFTER(free_tailq
, scb
,
5833 next_scb
, links
.tqe
);
5835 TAILQ_REMOVE(free_tailq
, scb
, links
.tqe
);
5837 LIST_REMOVE(scb
, collision_links
);
5841 * Get a free scb. If there are none, see if we can allocate a new SCB.
5844 ahd_get_scb(struct ahd_softc
*ahd
, u_int col_idx
)
5851 TAILQ_FOREACH(scb
, &ahd
->scb_data
.free_scbs
, links
.tqe
) {
5852 if (AHD_GET_SCB_COL_IDX(ahd
, scb
) != col_idx
) {
5853 ahd_rem_col_list(ahd
, scb
);
5857 if ((scb
= LIST_FIRST(&ahd
->scb_data
.any_dev_free_scb_list
)) == NULL
) {
5861 ahd_alloc_scbs(ahd
);
5864 LIST_REMOVE(scb
, links
.le
);
5865 if (col_idx
!= AHD_NEVER_COL_IDX
5866 && (scb
->col_scb
!= NULL
)
5867 && (scb
->col_scb
->flags
& SCB_ACTIVE
) == 0) {
5868 LIST_REMOVE(scb
->col_scb
, links
.le
);
5869 ahd_add_col_list(ahd
, scb
->col_scb
, col_idx
);
5872 scb
->flags
|= SCB_ACTIVE
;
5877 * Return an SCB resource to the free list.
5880 ahd_free_scb(struct ahd_softc
*ahd
, struct scb
*scb
)
5883 /* Clean up for the next user */
5884 scb
->flags
= SCB_FLAG_NONE
;
5885 scb
->hscb
->control
= 0;
5886 ahd
->scb_data
.scbindex
[SCB_GET_TAG(scb
)] = NULL
;
5888 if (scb
->col_scb
== NULL
) {
5891 * No collision possible. Just free normally.
5893 LIST_INSERT_HEAD(&ahd
->scb_data
.any_dev_free_scb_list
,
5895 } else if ((scb
->col_scb
->flags
& SCB_ON_COL_LIST
) != 0) {
5898 * The SCB we might have collided with is on
5899 * a free collision list. Put both SCBs on
5902 ahd_rem_col_list(ahd
, scb
->col_scb
);
5903 LIST_INSERT_HEAD(&ahd
->scb_data
.any_dev_free_scb_list
,
5905 LIST_INSERT_HEAD(&ahd
->scb_data
.any_dev_free_scb_list
,
5906 scb
->col_scb
, links
.le
);
5907 } else if ((scb
->col_scb
->flags
5908 & (SCB_PACKETIZED
|SCB_ACTIVE
)) == SCB_ACTIVE
5909 && (scb
->col_scb
->hscb
->control
& TAG_ENB
) != 0) {
5912 * The SCB we might collide with on the next allocation
5913 * is still active in a non-packetized, tagged, context.
5914 * Put us on the SCB collision list.
5916 ahd_add_col_list(ahd
, scb
,
5917 AHD_GET_SCB_COL_IDX(ahd
, scb
->col_scb
));
5920 * The SCB we might collide with on the next allocation
5921 * is either active in a packetized context, or free.
5922 * Since we can't collide, put this SCB on the generic
5925 LIST_INSERT_HEAD(&ahd
->scb_data
.any_dev_free_scb_list
,
5929 ahd_platform_scb_free(ahd
, scb
);
5933 ahd_alloc_scbs(struct ahd_softc
*ahd
)
5935 struct scb_data
*scb_data
;
5936 struct scb
*next_scb
;
5937 struct hardware_scb
*hscb
;
5938 struct map_node
*hscb_map
;
5939 struct map_node
*sg_map
;
5940 struct map_node
*sense_map
;
5942 uint8_t *sense_data
;
5943 dma_addr_t hscb_busaddr
;
5944 dma_addr_t sg_busaddr
;
5945 dma_addr_t sense_busaddr
;
5949 scb_data
= &ahd
->scb_data
;
5950 if (scb_data
->numscbs
>= AHD_SCB_MAX_ALLOC
)
5951 /* Can't allocate any more */
5954 if (scb_data
->scbs_left
!= 0) {
5957 offset
= (PAGE_SIZE
/ sizeof(*hscb
)) - scb_data
->scbs_left
;
5958 hscb_map
= SLIST_FIRST(&scb_data
->hscb_maps
);
5959 hscb
= &((struct hardware_scb
*)hscb_map
->vaddr
)[offset
];
5960 hscb_busaddr
= hscb_map
->physaddr
+ (offset
* sizeof(*hscb
));
5962 hscb_map
= malloc(sizeof(*hscb_map
), M_DEVBUF
, M_NOWAIT
);
5964 if (hscb_map
== NULL
)
5967 /* Allocate the next batch of hardware SCBs */
5968 if (ahd_dmamem_alloc(ahd
, scb_data
->hscb_dmat
,
5969 (void **)&hscb_map
->vaddr
,
5970 BUS_DMA_NOWAIT
, &hscb_map
->dmamap
) != 0) {
5971 free(hscb_map
, M_DEVBUF
);
5975 SLIST_INSERT_HEAD(&scb_data
->hscb_maps
, hscb_map
, links
);
5977 ahd_dmamap_load(ahd
, scb_data
->hscb_dmat
, hscb_map
->dmamap
,
5978 hscb_map
->vaddr
, PAGE_SIZE
, ahd_dmamap_cb
,
5979 &hscb_map
->physaddr
, /*flags*/0);
5981 hscb
= (struct hardware_scb
*)hscb_map
->vaddr
;
5982 hscb_busaddr
= hscb_map
->physaddr
;
5983 scb_data
->scbs_left
= PAGE_SIZE
/ sizeof(*hscb
);
5986 if (scb_data
->sgs_left
!= 0) {
5989 offset
= ((ahd_sglist_allocsize(ahd
) / ahd_sglist_size(ahd
))
5990 - scb_data
->sgs_left
) * ahd_sglist_size(ahd
);
5991 sg_map
= SLIST_FIRST(&scb_data
->sg_maps
);
5992 segs
= sg_map
->vaddr
+ offset
;
5993 sg_busaddr
= sg_map
->physaddr
+ offset
;
5995 sg_map
= malloc(sizeof(*sg_map
), M_DEVBUF
, M_NOWAIT
);
6000 /* Allocate the next batch of S/G lists */
6001 if (ahd_dmamem_alloc(ahd
, scb_data
->sg_dmat
,
6002 (void **)&sg_map
->vaddr
,
6003 BUS_DMA_NOWAIT
, &sg_map
->dmamap
) != 0) {
6004 free(sg_map
, M_DEVBUF
);
6008 SLIST_INSERT_HEAD(&scb_data
->sg_maps
, sg_map
, links
);
6010 ahd_dmamap_load(ahd
, scb_data
->sg_dmat
, sg_map
->dmamap
,
6011 sg_map
->vaddr
, ahd_sglist_allocsize(ahd
),
6012 ahd_dmamap_cb
, &sg_map
->physaddr
, /*flags*/0);
6014 segs
= sg_map
->vaddr
;
6015 sg_busaddr
= sg_map
->physaddr
;
6016 scb_data
->sgs_left
=
6017 ahd_sglist_allocsize(ahd
) / ahd_sglist_size(ahd
);
6019 if (ahd_debug
& AHD_SHOW_MEMORY
)
6020 printf("Mapped SG data\n");
6024 if (scb_data
->sense_left
!= 0) {
6027 offset
= PAGE_SIZE
- (AHD_SENSE_BUFSIZE
* scb_data
->sense_left
);
6028 sense_map
= SLIST_FIRST(&scb_data
->sense_maps
);
6029 sense_data
= sense_map
->vaddr
+ offset
;
6030 sense_busaddr
= sense_map
->physaddr
+ offset
;
6032 sense_map
= malloc(sizeof(*sense_map
), M_DEVBUF
, M_NOWAIT
);
6034 if (sense_map
== NULL
)
6037 /* Allocate the next batch of sense buffers */
6038 if (ahd_dmamem_alloc(ahd
, scb_data
->sense_dmat
,
6039 (void **)&sense_map
->vaddr
,
6040 BUS_DMA_NOWAIT
, &sense_map
->dmamap
) != 0) {
6041 free(sense_map
, M_DEVBUF
);
6045 SLIST_INSERT_HEAD(&scb_data
->sense_maps
, sense_map
, links
);
6047 ahd_dmamap_load(ahd
, scb_data
->sense_dmat
, sense_map
->dmamap
,
6048 sense_map
->vaddr
, PAGE_SIZE
, ahd_dmamap_cb
,
6049 &sense_map
->physaddr
, /*flags*/0);
6051 sense_data
= sense_map
->vaddr
;
6052 sense_busaddr
= sense_map
->physaddr
;
6053 scb_data
->sense_left
= PAGE_SIZE
/ AHD_SENSE_BUFSIZE
;
6055 if (ahd_debug
& AHD_SHOW_MEMORY
)
6056 printf("Mapped sense data\n");
6060 newcount
= MIN(scb_data
->sense_left
, scb_data
->scbs_left
);
6061 newcount
= MIN(newcount
, scb_data
->sgs_left
);
6062 newcount
= MIN(newcount
, (AHD_SCB_MAX_ALLOC
- scb_data
->numscbs
));
6063 for (i
= 0; i
< newcount
; i
++) {
6064 struct scb_platform_data
*pdata
;
6070 next_scb
= (struct scb
*)malloc(sizeof(*next_scb
),
6071 M_DEVBUF
, M_NOWAIT
);
6072 if (next_scb
== NULL
)
6075 pdata
= (struct scb_platform_data
*)malloc(sizeof(*pdata
),
6076 M_DEVBUF
, M_NOWAIT
);
6077 if (pdata
== NULL
) {
6078 free(next_scb
, M_DEVBUF
);
6081 next_scb
->platform_data
= pdata
;
6082 next_scb
->hscb_map
= hscb_map
;
6083 next_scb
->sg_map
= sg_map
;
6084 next_scb
->sense_map
= sense_map
;
6085 next_scb
->sg_list
= segs
;
6086 next_scb
->sense_data
= sense_data
;
6087 next_scb
->sense_busaddr
= sense_busaddr
;
6088 memset(hscb
, 0, sizeof(*hscb
));
6089 next_scb
->hscb
= hscb
;
6090 hscb
->hscb_busaddr
= ahd_htole32(hscb_busaddr
);
6093 * The sequencer always starts with the second entry.
6094 * The first entry is embedded in the scb.
6096 next_scb
->sg_list_busaddr
= sg_busaddr
;
6097 if ((ahd
->flags
& AHD_64BIT_ADDRESSING
) != 0)
6098 next_scb
->sg_list_busaddr
6099 += sizeof(struct ahd_dma64_seg
);
6101 next_scb
->sg_list_busaddr
+= sizeof(struct ahd_dma_seg
);
6102 next_scb
->ahd_softc
= ahd
;
6103 next_scb
->flags
= SCB_FLAG_NONE
;
6105 error
= ahd_dmamap_create(ahd
, ahd
->buffer_dmat
, /*flags*/0,
6108 free(next_scb
, M_DEVBUF
);
6109 free(pdata
, M_DEVBUF
);
6113 next_scb
->hscb
->tag
= ahd_htole16(scb_data
->numscbs
);
6114 col_tag
= scb_data
->numscbs
^ 0x100;
6115 next_scb
->col_scb
= ahd_find_scb_by_tag(ahd
, col_tag
);
6116 if (next_scb
->col_scb
!= NULL
)
6117 next_scb
->col_scb
->col_scb
= next_scb
;
6118 ahd_free_scb(ahd
, next_scb
);
6120 hscb_busaddr
+= sizeof(*hscb
);
6121 segs
+= ahd_sglist_size(ahd
);
6122 sg_busaddr
+= ahd_sglist_size(ahd
);
6123 sense_data
+= AHD_SENSE_BUFSIZE
;
6124 sense_busaddr
+= AHD_SENSE_BUFSIZE
;
6125 scb_data
->numscbs
++;
6126 scb_data
->sense_left
--;
6127 scb_data
->scbs_left
--;
6128 scb_data
->sgs_left
--;
6133 ahd_controller_info(struct ahd_softc
*ahd
, char *buf
)
6139 len
= sprintf(buf
, "%s: ", ahd_chip_names
[ahd
->chip
& AHD_CHIPID_MASK
]);
6142 speed
= "Ultra320 ";
6143 if ((ahd
->features
& AHD_WIDE
) != 0) {
6148 len
= sprintf(buf
, "%s%sChannel %c, SCSI Id=%d, ",
6149 speed
, type
, ahd
->channel
, ahd
->our_id
);
6152 sprintf(buf
, "%s, %d SCBs", ahd
->bus_description
,
6153 ahd
->scb_data
.maxhscbs
);
6156 static const char *channel_strings
[] = {
6163 static const char *termstat_strings
[] = {
6164 "Terminated Correctly",
6171 * Start the board, ready for normal operation
6174 ahd_init(struct ahd_softc
*ahd
)
6176 uint8_t *next_vaddr
;
6177 dma_addr_t next_baddr
;
6178 size_t driver_data_size
;
6182 uint8_t current_sensing
;
6185 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
6187 ahd
->stack_size
= ahd_probe_stack_size(ahd
);
6188 ahd
->saved_stack
= malloc(ahd
->stack_size
* sizeof(uint16_t),
6189 M_DEVBUF
, M_NOWAIT
);
6190 if (ahd
->saved_stack
== NULL
)
6194 * Verify that the compiler hasn't over-agressively
6195 * padded important structures.
6197 if (sizeof(struct hardware_scb
) != 64)
6198 panic("Hardware SCB size is incorrect");
6201 if ((ahd_debug
& AHD_DEBUG_SEQUENCER
) != 0)
6202 ahd
->flags
|= AHD_SEQUENCER_DEBUG
;
6206 * Default to allowing initiator operations.
6208 ahd
->flags
|= AHD_INITIATORROLE
;
6211 * Only allow target mode features if this unit has them enabled.
6213 if ((AHD_TMODE_ENABLE
& (0x1 << ahd
->unit
)) == 0)
6214 ahd
->features
&= ~AHD_TARGETMODE
;
6217 /* DMA tag for mapping buffers into device visible space. */
6218 if (ahd_dma_tag_create(ahd
, ahd
->parent_dmat
, /*alignment*/1,
6219 /*boundary*/BUS_SPACE_MAXADDR_32BIT
+ 1,
6220 /*lowaddr*/ahd
->flags
& AHD_39BIT_ADDRESSING
6221 ? (dma_addr_t
)0x7FFFFFFFFFULL
6222 : BUS_SPACE_MAXADDR_32BIT
,
6223 /*highaddr*/BUS_SPACE_MAXADDR
,
6224 /*filter*/NULL
, /*filterarg*/NULL
,
6225 /*maxsize*/(AHD_NSEG
- 1) * PAGE_SIZE
,
6226 /*nsegments*/AHD_NSEG
,
6227 /*maxsegsz*/AHD_MAXTRANSFER_SIZE
,
6228 /*flags*/BUS_DMA_ALLOCNOW
,
6229 &ahd
->buffer_dmat
) != 0) {
6237 * DMA tag for our command fifos and other data in system memory
6238 * the card's sequencer must be able to access. For initiator
6239 * roles, we need to allocate space for the qoutfifo. When providing
6240 * for the target mode role, we must additionally provide space for
6241 * the incoming target command fifo.
6243 driver_data_size
= AHD_SCB_MAX
* sizeof(*ahd
->qoutfifo
)
6244 + sizeof(struct hardware_scb
);
6245 if ((ahd
->features
& AHD_TARGETMODE
) != 0)
6246 driver_data_size
+= AHD_TMODE_CMDS
* sizeof(struct target_cmd
);
6247 if ((ahd
->bugs
& AHD_PKT_BITBUCKET_BUG
) != 0)
6248 driver_data_size
+= PKT_OVERRUN_BUFSIZE
;
6249 if (ahd_dma_tag_create(ahd
, ahd
->parent_dmat
, /*alignment*/1,
6250 /*boundary*/BUS_SPACE_MAXADDR_32BIT
+ 1,
6251 /*lowaddr*/BUS_SPACE_MAXADDR_32BIT
,
6252 /*highaddr*/BUS_SPACE_MAXADDR
,
6253 /*filter*/NULL
, /*filterarg*/NULL
,
6256 /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT
,
6257 /*flags*/0, &ahd
->shared_data_dmat
) != 0) {
6263 /* Allocation of driver data */
6264 if (ahd_dmamem_alloc(ahd
, ahd
->shared_data_dmat
,
6265 (void **)&ahd
->shared_data_map
.vaddr
,
6267 &ahd
->shared_data_map
.dmamap
) != 0) {
6273 /* And permanently map it in */
6274 ahd_dmamap_load(ahd
, ahd
->shared_data_dmat
, ahd
->shared_data_map
.dmamap
,
6275 ahd
->shared_data_map
.vaddr
, driver_data_size
,
6276 ahd_dmamap_cb
, &ahd
->shared_data_map
.physaddr
,
6278 ahd
->qoutfifo
= (struct ahd_completion
*)ahd
->shared_data_map
.vaddr
;
6279 next_vaddr
= (uint8_t *)&ahd
->qoutfifo
[AHD_QOUT_SIZE
];
6280 next_baddr
= ahd
->shared_data_map
.physaddr
6281 + AHD_QOUT_SIZE
*sizeof(struct ahd_completion
);
6282 if ((ahd
->features
& AHD_TARGETMODE
) != 0) {
6283 ahd
->targetcmds
= (struct target_cmd
*)next_vaddr
;
6284 next_vaddr
+= AHD_TMODE_CMDS
* sizeof(struct target_cmd
);
6285 next_baddr
+= AHD_TMODE_CMDS
* sizeof(struct target_cmd
);
6288 if ((ahd
->bugs
& AHD_PKT_BITBUCKET_BUG
) != 0) {
6289 ahd
->overrun_buf
= next_vaddr
;
6290 next_vaddr
+= PKT_OVERRUN_BUFSIZE
;
6291 next_baddr
+= PKT_OVERRUN_BUFSIZE
;
6295 * We need one SCB to serve as the "next SCB". Since the
6296 * tag identifier in this SCB will never be used, there is
6297 * no point in using a valid HSCB tag from an SCB pulled from
6298 * the standard free pool. So, we allocate this "sentinel"
6299 * specially from the DMA safe memory chunk used for the QOUTFIFO.
6301 ahd
->next_queued_hscb
= (struct hardware_scb
*)next_vaddr
;
6302 ahd
->next_queued_hscb_map
= &ahd
->shared_data_map
;
6303 ahd
->next_queued_hscb
->hscb_busaddr
= ahd_htole32(next_baddr
);
6307 /* Allocate SCB data now that buffer_dmat is initialized */
6308 if (ahd_init_scbdata(ahd
) != 0)
6311 if ((ahd
->flags
& AHD_INITIATORROLE
) == 0)
6312 ahd
->flags
&= ~AHD_RESET_BUS_A
;
6315 * Before committing these settings to the chip, give
6316 * the OSM one last chance to modify our configuration.
6318 ahd_platform_init(ahd
);
6320 /* Bring up the chip. */
6323 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
6325 if ((ahd
->flags
& AHD_CURRENT_SENSING
) == 0)
6329 * Verify termination based on current draw and
6330 * warn user if the bus is over/under terminated.
6332 error
= ahd_write_flexport(ahd
, FLXADDR_ROMSTAT_CURSENSECTL
,
6335 printf("%s: current sensing timeout 1\n", ahd_name(ahd
));
6338 for (i
= 20, fstat
= FLX_FSTAT_BUSY
;
6339 (fstat
& FLX_FSTAT_BUSY
) != 0 && i
; i
--) {
6340 error
= ahd_read_flexport(ahd
, FLXADDR_FLEXSTAT
, &fstat
);
6342 printf("%s: current sensing timeout 2\n",
6348 printf("%s: Timedout during current-sensing test\n",
6353 /* Latch Current Sensing status. */
6354 error
= ahd_read_flexport(ahd
, FLXADDR_CURRENT_STAT
, ¤t_sensing
);
6356 printf("%s: current sensing timeout 3\n", ahd_name(ahd
));
6360 /* Diable current sensing. */
6361 ahd_write_flexport(ahd
, FLXADDR_ROMSTAT_CURSENSECTL
, 0);
6364 if ((ahd_debug
& AHD_SHOW_TERMCTL
) != 0) {
6365 printf("%s: current_sensing == 0x%x\n",
6366 ahd_name(ahd
), current_sensing
);
6370 for (i
= 0; i
< 4; i
++, current_sensing
>>= FLX_CSTAT_SHIFT
) {
6373 term_stat
= (current_sensing
& FLX_CSTAT_MASK
);
6374 switch (term_stat
) {
6375 case FLX_CSTAT_OVER
:
6376 case FLX_CSTAT_UNDER
:
6378 case FLX_CSTAT_INVALID
:
6379 case FLX_CSTAT_OKAY
:
6380 if (warn_user
== 0 && bootverbose
== 0)
6382 printf("%s: %s Channel %s\n", ahd_name(ahd
),
6383 channel_strings
[i
], termstat_strings
[term_stat
]);
6388 printf("%s: WARNING. Termination is not configured correctly.\n"
6389 "%s: WARNING. SCSI bus operations may FAIL.\n",
6390 ahd_name(ahd
), ahd_name(ahd
));
6394 ahd_timer_reset(&ahd
->stat_timer
, AHD_STAT_UPDATE_US
,
6395 ahd_stat_timer
, ahd
);
6400 * (Re)initialize chip state after a chip reset.
6403 ahd_chip_init(struct ahd_softc
*ahd
)
6407 u_int scsiseq_template
;
6412 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
6414 * Take the LED out of diagnostic mode
6416 ahd_outb(ahd
, SBLKCTL
, ahd_inb(ahd
, SBLKCTL
) & ~(DIAGLEDEN
|DIAGLEDON
));
6419 * Return HS_MAILBOX to its default value.
6421 ahd
->hs_mailbox
= 0;
6422 ahd_outb(ahd
, HS_MAILBOX
, 0);
6424 /* Set the SCSI Id, SXFRCTL0, SXFRCTL1, and SIMODE1. */
6425 ahd_outb(ahd
, IOWNID
, ahd
->our_id
);
6426 ahd_outb(ahd
, TOWNID
, ahd
->our_id
);
6427 sxfrctl1
= (ahd
->flags
& AHD_TERM_ENB_A
) != 0 ? STPWEN
: 0;
6428 sxfrctl1
|= (ahd
->flags
& AHD_SPCHK_ENB_A
) != 0 ? ENSPCHK
: 0;
6429 if ((ahd
->bugs
& AHD_LONG_SETIMO_BUG
)
6430 && (ahd
->seltime
!= STIMESEL_MIN
)) {
6432 * The selection timer duration is twice as long
6433 * as it should be. Halve it by adding "1" to
6434 * the user specified setting.
6436 sxfrctl1
|= ahd
->seltime
+ STIMESEL_BUG_ADJ
;
6438 sxfrctl1
|= ahd
->seltime
;
6441 ahd_outb(ahd
, SXFRCTL0
, DFON
);
6442 ahd_outb(ahd
, SXFRCTL1
, sxfrctl1
|ahd
->seltime
|ENSTIMER
|ACTNEGEN
);
6443 ahd_outb(ahd
, SIMODE1
, ENSELTIMO
|ENSCSIRST
|ENSCSIPERR
);
6446 * Now that termination is set, wait for up
6447 * to 500ms for our transceivers to settle. If
6448 * the adapter does not have a cable attached,
6449 * the transceivers may never settle, so don't
6450 * complain if we fail here.
6453 (ahd_inb(ahd
, SBLKCTL
) & (ENAB40
|ENAB20
)) == 0 && wait
;
6457 /* Clear any false bus resets due to the transceivers settling */
6458 ahd_outb(ahd
, CLRSINT1
, CLRSCSIRSTI
);
6459 ahd_outb(ahd
, CLRINT
, CLRSCSIINT
);
6461 /* Initialize mode specific S/G state. */
6462 for (i
= 0; i
< 2; i
++) {
6463 ahd_set_modes(ahd
, AHD_MODE_DFF0
+ i
, AHD_MODE_DFF0
+ i
);
6464 ahd_outb(ahd
, LONGJMP_ADDR
+ 1, INVALID_ADDR
);
6465 ahd_outb(ahd
, SG_STATE
, 0);
6466 ahd_outb(ahd
, CLRSEQINTSRC
, 0xFF);
6467 ahd_outb(ahd
, SEQIMODE
,
6468 ENSAVEPTRS
|ENCFG4DATA
|ENCFG4ISTAT
6469 |ENCFG4TSTAT
|ENCFG4ICMD
|ENCFG4TCMD
);
6472 ahd_set_modes(ahd
, AHD_MODE_CFG
, AHD_MODE_CFG
);
6473 ahd_outb(ahd
, DSCOMMAND0
, ahd_inb(ahd
, DSCOMMAND0
)|MPARCKEN
|CACHETHEN
);
6474 ahd_outb(ahd
, DFF_THRSH
, RD_DFTHRSH_75
|WR_DFTHRSH_75
);
6475 ahd_outb(ahd
, SIMODE0
, ENIOERR
|ENOVERRUN
);
6476 ahd_outb(ahd
, SIMODE3
, ENNTRAMPERR
|ENOSRAMPERR
);
6477 if ((ahd
->bugs
& AHD_BUSFREEREV_BUG
) != 0) {
6478 ahd_outb(ahd
, OPTIONMODE
, AUTOACKEN
|AUTO_MSGOUT_DE
);
6480 ahd_outb(ahd
, OPTIONMODE
, AUTOACKEN
|BUSFREEREV
|AUTO_MSGOUT_DE
);
6482 ahd_outb(ahd
, SCSCHKN
, CURRFIFODEF
|WIDERESEN
|SHVALIDSTDIS
);
6483 if ((ahd
->chip
& AHD_BUS_MASK
) == AHD_PCIX
)
6485 * Do not issue a target abort when a split completion
6486 * error occurs. Let our PCIX interrupt handler deal
6487 * with it instead. H2A4 Razor #625
6489 ahd_outb(ahd
, PCIXCTL
, ahd_inb(ahd
, PCIXCTL
) | SPLTSTADIS
);
6491 if ((ahd
->bugs
& AHD_LQOOVERRUN_BUG
) != 0)
6492 ahd_outb(ahd
, LQOSCSCTL
, LQONOCHKOVER
);
6495 * Tweak IOCELL settings.
6497 if ((ahd
->flags
& AHD_HP_BOARD
) != 0) {
6498 for (i
= 0; i
< NUMDSPS
; i
++) {
6499 ahd_outb(ahd
, DSPSELECT
, i
);
6500 ahd_outb(ahd
, WRTBIASCTL
, WRTBIASCTL_HP_DEFAULT
);
6503 if ((ahd_debug
& AHD_SHOW_MISC
) != 0)
6504 printf("%s: WRTBIASCTL now 0x%x\n", ahd_name(ahd
),
6505 WRTBIASCTL_HP_DEFAULT
);
6508 ahd_setup_iocell_workaround(ahd
);
6511 * Enable LQI Manager interrupts.
6513 ahd_outb(ahd
, LQIMODE1
, ENLQIPHASE_LQ
|ENLQIPHASE_NLQ
|ENLIQABORT
6514 | ENLQICRCI_LQ
|ENLQICRCI_NLQ
|ENLQIBADLQI
6515 | ENLQIOVERI_LQ
|ENLQIOVERI_NLQ
);
6516 ahd_outb(ahd
, LQOMODE0
, ENLQOATNLQ
|ENLQOATNPKT
|ENLQOTCRC
);
6518 * We choose to have the sequencer catch LQOPHCHGINPKT errors
6519 * manually for the command phase at the start of a packetized
6520 * selection case. ENLQOBUSFREE should be made redundant by
6521 * the BUSFREE interrupt, but it seems that some LQOBUSFREE
6522 * events fail to assert the BUSFREE interrupt so we must
6523 * also enable LQOBUSFREE interrupts.
6525 ahd_outb(ahd
, LQOMODE1
, ENLQOBUSFREE
);
6528 * Setup sequencer interrupt handlers.
6530 ahd_outw(ahd
, INTVEC1_ADDR
, ahd_resolve_seqaddr(ahd
, LABEL_seq_isr
));
6531 ahd_outw(ahd
, INTVEC2_ADDR
, ahd_resolve_seqaddr(ahd
, LABEL_timer_isr
));
6534 * Setup SCB Offset registers.
6536 if ((ahd
->bugs
& AHD_PKT_LUN_BUG
) != 0) {
6537 ahd_outb(ahd
, LUNPTR
, offsetof(struct hardware_scb
,
6540 ahd_outb(ahd
, LUNPTR
, offsetof(struct hardware_scb
, lun
));
6542 ahd_outb(ahd
, CMDLENPTR
, offsetof(struct hardware_scb
, cdb_len
));
6543 ahd_outb(ahd
, ATTRPTR
, offsetof(struct hardware_scb
, task_attribute
));
6544 ahd_outb(ahd
, FLAGPTR
, offsetof(struct hardware_scb
, task_management
));
6545 ahd_outb(ahd
, CMDPTR
, offsetof(struct hardware_scb
,
6546 shared_data
.idata
.cdb
));
6547 ahd_outb(ahd
, QNEXTPTR
,
6548 offsetof(struct hardware_scb
, next_hscb_busaddr
));
6549 ahd_outb(ahd
, ABRTBITPTR
, MK_MESSAGE_BIT_OFFSET
);
6550 ahd_outb(ahd
, ABRTBYTEPTR
, offsetof(struct hardware_scb
, control
));
6551 if ((ahd
->bugs
& AHD_PKT_LUN_BUG
) != 0) {
6552 ahd_outb(ahd
, LUNLEN
,
6553 sizeof(ahd
->next_queued_hscb
->pkt_long_lun
) - 1);
6555 ahd_outb(ahd
, LUNLEN
, LUNLEN_SINGLE_LEVEL_LUN
);
6557 ahd_outb(ahd
, CDBLIMIT
, SCB_CDB_LEN_PTR
- 1);
6558 ahd_outb(ahd
, MAXCMD
, 0xFF);
6559 ahd_outb(ahd
, SCBAUTOPTR
,
6560 AUSCBPTR_EN
| offsetof(struct hardware_scb
, tag
));
6562 /* We haven't been enabled for target mode yet. */
6563 ahd_outb(ahd
, MULTARGID
, 0);
6564 ahd_outb(ahd
, MULTARGID
+ 1, 0);
6566 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
6567 /* Initialize the negotiation table. */
6568 if ((ahd
->features
& AHD_NEW_IOCELL_OPTS
) == 0) {
6570 * Clear the spare bytes in the neg table to avoid
6571 * spurious parity errors.
6573 for (target
= 0; target
< AHD_NUM_TARGETS
; target
++) {
6574 ahd_outb(ahd
, NEGOADDR
, target
);
6575 ahd_outb(ahd
, ANNEXCOL
, AHD_ANNEXCOL_PER_DEV0
);
6576 for (i
= 0; i
< AHD_NUM_PER_DEV_ANNEXCOLS
; i
++)
6577 ahd_outb(ahd
, ANNEXDAT
, 0);
6580 for (target
= 0; target
< AHD_NUM_TARGETS
; target
++) {
6581 struct ahd_devinfo devinfo
;
6582 struct ahd_initiator_tinfo
*tinfo
;
6583 struct ahd_tmode_tstate
*tstate
;
6585 tinfo
= ahd_fetch_transinfo(ahd
, 'A', ahd
->our_id
,
6587 ahd_compile_devinfo(&devinfo
, ahd
->our_id
,
6588 target
, CAM_LUN_WILDCARD
,
6589 'A', ROLE_INITIATOR
);
6590 ahd_update_neg_table(ahd
, &devinfo
, &tinfo
->curr
);
6593 ahd_outb(ahd
, CLRSINT3
, NTRAMPERR
|OSRAMPERR
);
6594 ahd_outb(ahd
, CLRINT
, CLRSCSIINT
);
6596 #ifdef NEEDS_MORE_TESTING
6598 * Always enable abort on incoming L_Qs if this feature is
6599 * supported. We use this to catch invalid SCB references.
6601 if ((ahd
->bugs
& AHD_ABORT_LQI_BUG
) == 0)
6602 ahd_outb(ahd
, LQCTL1
, ABORTPENDING
);
6605 ahd_outb(ahd
, LQCTL1
, 0);
6607 /* All of our queues are empty */
6608 ahd
->qoutfifonext
= 0;
6609 ahd
->qoutfifonext_valid_tag
= QOUTFIFO_ENTRY_VALID
;
6610 ahd_outb(ahd
, QOUTFIFO_ENTRY_VALID_TAG
, QOUTFIFO_ENTRY_VALID
);
6611 for (i
= 0; i
< AHD_QOUT_SIZE
; i
++)
6612 ahd
->qoutfifo
[i
].valid_tag
= 0;
6613 ahd_sync_qoutfifo(ahd
, BUS_DMASYNC_PREREAD
);
6615 ahd
->qinfifonext
= 0;
6616 for (i
= 0; i
< AHD_QIN_SIZE
; i
++)
6617 ahd
->qinfifo
[i
] = SCB_LIST_NULL
;
6619 if ((ahd
->features
& AHD_TARGETMODE
) != 0) {
6620 /* All target command blocks start out invalid. */
6621 for (i
= 0; i
< AHD_TMODE_CMDS
; i
++)
6622 ahd
->targetcmds
[i
].cmd_valid
= 0;
6623 ahd_sync_tqinfifo(ahd
, BUS_DMASYNC_PREREAD
);
6624 ahd
->tqinfifonext
= 1;
6625 ahd_outb(ahd
, KERNEL_TQINPOS
, ahd
->tqinfifonext
- 1);
6626 ahd_outb(ahd
, TQINPOS
, ahd
->tqinfifonext
);
6629 /* Initialize Scratch Ram. */
6630 ahd_outb(ahd
, SEQ_FLAGS
, 0);
6631 ahd_outb(ahd
, SEQ_FLAGS2
, 0);
6633 /* We don't have any waiting selections */
6634 ahd_outw(ahd
, WAITING_TID_HEAD
, SCB_LIST_NULL
);
6635 ahd_outw(ahd
, WAITING_TID_TAIL
, SCB_LIST_NULL
);
6636 ahd_outw(ahd
, MK_MESSAGE_SCB
, SCB_LIST_NULL
);
6637 ahd_outw(ahd
, MK_MESSAGE_SCSIID
, 0xFF);
6638 for (i
= 0; i
< AHD_NUM_TARGETS
; i
++)
6639 ahd_outw(ahd
, WAITING_SCB_TAILS
+ (2 * i
), SCB_LIST_NULL
);
6642 * Nobody is waiting to be DMAed into the QOUTFIFO.
6644 ahd_outw(ahd
, COMPLETE_SCB_HEAD
, SCB_LIST_NULL
);
6645 ahd_outw(ahd
, COMPLETE_SCB_DMAINPROG_HEAD
, SCB_LIST_NULL
);
6646 ahd_outw(ahd
, COMPLETE_DMA_SCB_HEAD
, SCB_LIST_NULL
);
6647 ahd_outw(ahd
, COMPLETE_DMA_SCB_TAIL
, SCB_LIST_NULL
);
6648 ahd_outw(ahd
, COMPLETE_ON_QFREEZE_HEAD
, SCB_LIST_NULL
);
6651 * The Freeze Count is 0.
6653 ahd
->qfreeze_cnt
= 0;
6654 ahd_outw(ahd
, QFREEZE_COUNT
, 0);
6655 ahd_outw(ahd
, KERNEL_QFREEZE_COUNT
, 0);
6658 * Tell the sequencer where it can find our arrays in memory.
6660 busaddr
= ahd
->shared_data_map
.physaddr
;
6661 ahd_outl(ahd
, SHARED_DATA_ADDR
, busaddr
);
6662 ahd_outl(ahd
, QOUTFIFO_NEXT_ADDR
, busaddr
);
6665 * Setup the allowed SCSI Sequences based on operational mode.
6666 * If we are a target, we'll enable select in operations once
6667 * we've had a lun enabled.
6669 scsiseq_template
= ENAUTOATNP
;
6670 if ((ahd
->flags
& AHD_INITIATORROLE
) != 0)
6671 scsiseq_template
|= ENRSELI
;
6672 ahd_outb(ahd
, SCSISEQ_TEMPLATE
, scsiseq_template
);
6674 /* There are no busy SCBs yet. */
6675 for (target
= 0; target
< AHD_NUM_TARGETS
; target
++) {
6678 for (lun
= 0; lun
< AHD_NUM_LUNS_NONPKT
; lun
++)
6679 ahd_unbusy_tcl(ahd
, BUILD_TCL_RAW(target
, 'A', lun
));
6683 * Initialize the group code to command length table.
6684 * Vendor Unique codes are set to 0 so we only capture
6685 * the first byte of the cdb. These can be overridden
6686 * when target mode is enabled.
6688 ahd_outb(ahd
, CMDSIZE_TABLE
, 5);
6689 ahd_outb(ahd
, CMDSIZE_TABLE
+ 1, 9);
6690 ahd_outb(ahd
, CMDSIZE_TABLE
+ 2, 9);
6691 ahd_outb(ahd
, CMDSIZE_TABLE
+ 3, 0);
6692 ahd_outb(ahd
, CMDSIZE_TABLE
+ 4, 15);
6693 ahd_outb(ahd
, CMDSIZE_TABLE
+ 5, 11);
6694 ahd_outb(ahd
, CMDSIZE_TABLE
+ 6, 0);
6695 ahd_outb(ahd
, CMDSIZE_TABLE
+ 7, 0);
6697 /* Tell the sequencer of our initial queue positions */
6698 ahd_set_modes(ahd
, AHD_MODE_CCHAN
, AHD_MODE_CCHAN
);
6699 ahd_outb(ahd
, QOFF_CTLSTA
, SCB_QSIZE_512
);
6700 ahd
->qinfifonext
= 0;
6701 ahd_set_hnscb_qoff(ahd
, ahd
->qinfifonext
);
6702 ahd_set_hescb_qoff(ahd
, 0);
6703 ahd_set_snscb_qoff(ahd
, 0);
6704 ahd_set_sescb_qoff(ahd
, 0);
6705 ahd_set_sdscb_qoff(ahd
, 0);
6708 * Tell the sequencer which SCB will be the next one it receives.
6710 busaddr
= ahd_le32toh(ahd
->next_queued_hscb
->hscb_busaddr
);
6711 ahd_outl(ahd
, NEXT_QUEUED_SCB_ADDR
, busaddr
);
6714 * Default to coalescing disabled.
6716 ahd_outw(ahd
, INT_COALESCING_CMDCOUNT
, 0);
6717 ahd_outw(ahd
, CMDS_PENDING
, 0);
6718 ahd_update_coalescing_values(ahd
, ahd
->int_coalescing_timer
,
6719 ahd
->int_coalescing_maxcmds
,
6720 ahd
->int_coalescing_mincmds
);
6721 ahd_enable_coalescing(ahd
, FALSE
);
6724 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
6726 if (ahd
->features
& AHD_AIC79XXB_SLOWCRC
) {
6727 u_int negodat3
= ahd_inb(ahd
, NEGCONOPTS
);
6729 negodat3
|= ENSLOWCRC
;
6730 ahd_outb(ahd
, NEGCONOPTS
, negodat3
);
6731 negodat3
= ahd_inb(ahd
, NEGCONOPTS
);
6732 if (!(negodat3
& ENSLOWCRC
))
6733 printf("aic79xx: failed to set the SLOWCRC bit\n");
6735 printf("aic79xx: SLOWCRC bit set\n");
6740 * Setup default device and controller settings.
6741 * This should only be called if our probe has
6742 * determined that no configuration data is available.
6745 ahd_default_config(struct ahd_softc
*ahd
)
6752 * Allocate a tstate to house information for our
6753 * initiator presence on the bus as well as the user
6754 * data for any target mode initiator.
6756 if (ahd_alloc_tstate(ahd
, ahd
->our_id
, 'A') == NULL
) {
6757 printf("%s: unable to allocate ahd_tmode_tstate. "
6758 "Failing attach\n", ahd_name(ahd
));
6762 for (targ
= 0; targ
< AHD_NUM_TARGETS
; targ
++) {
6763 struct ahd_devinfo devinfo
;
6764 struct ahd_initiator_tinfo
*tinfo
;
6765 struct ahd_tmode_tstate
*tstate
;
6766 uint16_t target_mask
;
6768 tinfo
= ahd_fetch_transinfo(ahd
, 'A', ahd
->our_id
,
6771 * We support SPC2 and SPI4.
6773 tinfo
->user
.protocol_version
= 4;
6774 tinfo
->user
.transport_version
= 4;
6776 target_mask
= 0x01 << targ
;
6777 ahd
->user_discenable
|= target_mask
;
6778 tstate
->discenable
|= target_mask
;
6779 ahd
->user_tagenable
|= target_mask
;
6780 #ifdef AHD_FORCE_160
6781 tinfo
->user
.period
= AHD_SYNCRATE_DT
;
6783 tinfo
->user
.period
= AHD_SYNCRATE_160
;
6785 tinfo
->user
.offset
= MAX_OFFSET
;
6786 tinfo
->user
.ppr_options
= MSG_EXT_PPR_RD_STRM
6787 | MSG_EXT_PPR_WR_FLOW
6788 | MSG_EXT_PPR_HOLD_MCS
6789 | MSG_EXT_PPR_IU_REQ
6790 | MSG_EXT_PPR_QAS_REQ
6791 | MSG_EXT_PPR_DT_REQ
;
6792 if ((ahd
->features
& AHD_RTI
) != 0)
6793 tinfo
->user
.ppr_options
|= MSG_EXT_PPR_RTI
;
6795 tinfo
->user
.width
= MSG_EXT_WDTR_BUS_16_BIT
;
6798 * Start out Async/Narrow/Untagged and with
6799 * conservative protocol support.
6801 tinfo
->goal
.protocol_version
= 2;
6802 tinfo
->goal
.transport_version
= 2;
6803 tinfo
->curr
.protocol_version
= 2;
6804 tinfo
->curr
.transport_version
= 2;
6805 ahd_compile_devinfo(&devinfo
, ahd
->our_id
,
6806 targ
, CAM_LUN_WILDCARD
,
6807 'A', ROLE_INITIATOR
);
6808 tstate
->tagenable
&= ~target_mask
;
6809 ahd_set_width(ahd
, &devinfo
, MSG_EXT_WDTR_BUS_8_BIT
,
6810 AHD_TRANS_CUR
|AHD_TRANS_GOAL
, /*paused*/TRUE
);
6811 ahd_set_syncrate(ahd
, &devinfo
, /*period*/0, /*offset*/0,
6812 /*ppr_options*/0, AHD_TRANS_CUR
|AHD_TRANS_GOAL
,
6819 * Parse device configuration information.
6822 ahd_parse_cfgdata(struct ahd_softc
*ahd
, struct seeprom_config
*sc
)
6827 max_targ
= sc
->max_targets
& CFMAXTARG
;
6828 ahd
->our_id
= sc
->brtime_id
& CFSCSIID
;
6831 * Allocate a tstate to house information for our
6832 * initiator presence on the bus as well as the user
6833 * data for any target mode initiator.
6835 if (ahd_alloc_tstate(ahd
, ahd
->our_id
, 'A') == NULL
) {
6836 printf("%s: unable to allocate ahd_tmode_tstate. "
6837 "Failing attach\n", ahd_name(ahd
));
6841 for (targ
= 0; targ
< max_targ
; targ
++) {
6842 struct ahd_devinfo devinfo
;
6843 struct ahd_initiator_tinfo
*tinfo
;
6844 struct ahd_transinfo
*user_tinfo
;
6845 struct ahd_tmode_tstate
*tstate
;
6846 uint16_t target_mask
;
6848 tinfo
= ahd_fetch_transinfo(ahd
, 'A', ahd
->our_id
,
6850 user_tinfo
= &tinfo
->user
;
6853 * We support SPC2 and SPI4.
6855 tinfo
->user
.protocol_version
= 4;
6856 tinfo
->user
.transport_version
= 4;
6858 target_mask
= 0x01 << targ
;
6859 ahd
->user_discenable
&= ~target_mask
;
6860 tstate
->discenable
&= ~target_mask
;
6861 ahd
->user_tagenable
&= ~target_mask
;
6862 if (sc
->device_flags
[targ
] & CFDISC
) {
6863 tstate
->discenable
|= target_mask
;
6864 ahd
->user_discenable
|= target_mask
;
6865 ahd
->user_tagenable
|= target_mask
;
6868 * Cannot be packetized without disconnection.
6870 sc
->device_flags
[targ
] &= ~CFPACKETIZED
;
6873 user_tinfo
->ppr_options
= 0;
6874 user_tinfo
->period
= (sc
->device_flags
[targ
] & CFXFER
);
6875 if (user_tinfo
->period
< CFXFER_ASYNC
) {
6876 if (user_tinfo
->period
<= AHD_PERIOD_10MHz
)
6877 user_tinfo
->ppr_options
|= MSG_EXT_PPR_DT_REQ
;
6878 user_tinfo
->offset
= MAX_OFFSET
;
6880 user_tinfo
->offset
= 0;
6881 user_tinfo
->period
= AHD_ASYNC_XFER_PERIOD
;
6883 #ifdef AHD_FORCE_160
6884 if (user_tinfo
->period
<= AHD_SYNCRATE_160
)
6885 user_tinfo
->period
= AHD_SYNCRATE_DT
;
6888 if ((sc
->device_flags
[targ
] & CFPACKETIZED
) != 0) {
6889 user_tinfo
->ppr_options
|= MSG_EXT_PPR_RD_STRM
6890 | MSG_EXT_PPR_WR_FLOW
6891 | MSG_EXT_PPR_HOLD_MCS
6892 | MSG_EXT_PPR_IU_REQ
;
6893 if ((ahd
->features
& AHD_RTI
) != 0)
6894 user_tinfo
->ppr_options
|= MSG_EXT_PPR_RTI
;
6897 if ((sc
->device_flags
[targ
] & CFQAS
) != 0)
6898 user_tinfo
->ppr_options
|= MSG_EXT_PPR_QAS_REQ
;
6900 if ((sc
->device_flags
[targ
] & CFWIDEB
) != 0)
6901 user_tinfo
->width
= MSG_EXT_WDTR_BUS_16_BIT
;
6903 user_tinfo
->width
= MSG_EXT_WDTR_BUS_8_BIT
;
6905 if ((ahd_debug
& AHD_SHOW_MISC
) != 0)
6906 printf("(%d): %x:%x:%x:%x\n", targ
, user_tinfo
->width
,
6907 user_tinfo
->period
, user_tinfo
->offset
,
6908 user_tinfo
->ppr_options
);
6911 * Start out Async/Narrow/Untagged and with
6912 * conservative protocol support.
6914 tstate
->tagenable
&= ~target_mask
;
6915 tinfo
->goal
.protocol_version
= 2;
6916 tinfo
->goal
.transport_version
= 2;
6917 tinfo
->curr
.protocol_version
= 2;
6918 tinfo
->curr
.transport_version
= 2;
6919 ahd_compile_devinfo(&devinfo
, ahd
->our_id
,
6920 targ
, CAM_LUN_WILDCARD
,
6921 'A', ROLE_INITIATOR
);
6922 ahd_set_width(ahd
, &devinfo
, MSG_EXT_WDTR_BUS_8_BIT
,
6923 AHD_TRANS_CUR
|AHD_TRANS_GOAL
, /*paused*/TRUE
);
6924 ahd_set_syncrate(ahd
, &devinfo
, /*period*/0, /*offset*/0,
6925 /*ppr_options*/0, AHD_TRANS_CUR
|AHD_TRANS_GOAL
,
6929 ahd
->flags
&= ~AHD_SPCHK_ENB_A
;
6930 if (sc
->bios_control
& CFSPARITY
)
6931 ahd
->flags
|= AHD_SPCHK_ENB_A
;
6933 ahd
->flags
&= ~AHD_RESET_BUS_A
;
6934 if (sc
->bios_control
& CFRESETB
)
6935 ahd
->flags
|= AHD_RESET_BUS_A
;
6937 ahd
->flags
&= ~AHD_EXTENDED_TRANS_A
;
6938 if (sc
->bios_control
& CFEXTEND
)
6939 ahd
->flags
|= AHD_EXTENDED_TRANS_A
;
6941 ahd
->flags
&= ~AHD_BIOS_ENABLED
;
6942 if ((sc
->bios_control
& CFBIOSSTATE
) == CFBS_ENABLED
)
6943 ahd
->flags
|= AHD_BIOS_ENABLED
;
6945 ahd
->flags
&= ~AHD_STPWLEVEL_A
;
6946 if ((sc
->adapter_control
& CFSTPWLEVEL
) != 0)
6947 ahd
->flags
|= AHD_STPWLEVEL_A
;
6953 * Parse device configuration information.
6956 ahd_parse_vpddata(struct ahd_softc
*ahd
, struct vpd_config
*vpd
)
6960 error
= ahd_verify_vpd_cksum(vpd
);
6963 if ((vpd
->bios_flags
& VPDBOOTHOST
) != 0)
6964 ahd
->flags
|= AHD_BOOT_CHANNEL
;
6969 ahd_intr_enable(struct ahd_softc
*ahd
, int enable
)
6973 hcntrl
= ahd_inb(ahd
, HCNTRL
);
6975 ahd
->pause
&= ~INTEN
;
6976 ahd
->unpause
&= ~INTEN
;
6979 ahd
->pause
|= INTEN
;
6980 ahd
->unpause
|= INTEN
;
6982 ahd_outb(ahd
, HCNTRL
, hcntrl
);
6986 ahd_update_coalescing_values(struct ahd_softc
*ahd
, u_int timer
, u_int maxcmds
,
6989 if (timer
> AHD_TIMER_MAX_US
)
6990 timer
= AHD_TIMER_MAX_US
;
6991 ahd
->int_coalescing_timer
= timer
;
6993 if (maxcmds
> AHD_INT_COALESCING_MAXCMDS_MAX
)
6994 maxcmds
= AHD_INT_COALESCING_MAXCMDS_MAX
;
6995 if (mincmds
> AHD_INT_COALESCING_MINCMDS_MAX
)
6996 mincmds
= AHD_INT_COALESCING_MINCMDS_MAX
;
6997 ahd
->int_coalescing_maxcmds
= maxcmds
;
6998 ahd_outw(ahd
, INT_COALESCING_TIMER
, timer
/ AHD_TIMER_US_PER_TICK
);
6999 ahd_outb(ahd
, INT_COALESCING_MAXCMDS
, -maxcmds
);
7000 ahd_outb(ahd
, INT_COALESCING_MINCMDS
, -mincmds
);
7004 ahd_enable_coalescing(struct ahd_softc
*ahd
, int enable
)
7007 ahd
->hs_mailbox
&= ~ENINT_COALESCE
;
7009 ahd
->hs_mailbox
|= ENINT_COALESCE
;
7010 ahd_outb(ahd
, HS_MAILBOX
, ahd
->hs_mailbox
);
7011 ahd_flush_device_writes(ahd
);
7012 ahd_run_qoutfifo(ahd
);
7016 * Ensure that the card is paused in a location
7017 * outside of all critical sections and that all
7018 * pending work is completed prior to returning.
7019 * This routine should only be called from outside
7020 * an interrupt context.
7023 ahd_pause_and_flushwork(struct ahd_softc
*ahd
)
7029 ahd
->flags
|= AHD_ALL_INTERRUPTS
;
7032 * Freeze the outgoing selections. We do this only
7033 * until we are safely paused without further selections
7037 ahd_outw(ahd
, KERNEL_QFREEZE_COUNT
, ahd
->qfreeze_cnt
);
7038 ahd_outb(ahd
, SEQ_FLAGS2
, ahd_inb(ahd
, SEQ_FLAGS2
) | SELECTOUT_QFROZEN
);
7043 * Give the sequencer some time to service
7044 * any active selections.
7050 intstat
= ahd_inb(ahd
, INTSTAT
);
7051 if ((intstat
& INT_PEND
) == 0) {
7052 ahd_clear_critical_section(ahd
);
7053 intstat
= ahd_inb(ahd
, INTSTAT
);
7056 && (intstat
!= 0xFF || (ahd
->features
& AHD_REMOVABLE
) == 0)
7057 && ((intstat
& INT_PEND
) != 0
7058 || (ahd_inb(ahd
, SCSISEQ0
) & ENSELO
) != 0
7059 || (ahd_inb(ahd
, SSTAT0
) & (SELDO
|SELINGO
)) != 0));
7061 if (maxloops
== 0) {
7062 printf("Infinite interrupt loop, INTSTAT = %x",
7063 ahd_inb(ahd
, INTSTAT
));
7066 ahd_outw(ahd
, KERNEL_QFREEZE_COUNT
, ahd
->qfreeze_cnt
);
7068 ahd_flush_qoutfifo(ahd
);
7070 ahd
->flags
&= ~AHD_ALL_INTERRUPTS
;
7074 ahd_suspend(struct ahd_softc
*ahd
)
7077 ahd_pause_and_flushwork(ahd
);
7079 if (LIST_FIRST(&ahd
->pending_scbs
) != NULL
) {
7088 ahd_resume(struct ahd_softc
*ahd
)
7091 ahd_reset(ahd
, /*reinit*/TRUE
);
7092 ahd_intr_enable(ahd
, TRUE
);
7097 /************************** Busy Target Table *********************************/
7099 * Set SCBPTR to the SCB that contains the busy
7100 * table entry for TCL. Return the offset into
7101 * the SCB that contains the entry for TCL.
7102 * saved_scbid is dereferenced and set to the
7103 * scbid that should be restored once manipualtion
7104 * of the TCL entry is complete.
7106 static __inline u_int
7107 ahd_index_busy_tcl(struct ahd_softc
*ahd
, u_int
*saved_scbid
, u_int tcl
)
7110 * Index to the SCB that contains the busy entry.
7112 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
7113 *saved_scbid
= ahd_get_scbptr(ahd
);
7114 ahd_set_scbptr(ahd
, TCL_LUN(tcl
)
7115 | ((TCL_TARGET_OFFSET(tcl
) & 0xC) << 4));
7118 * And now calculate the SCB offset to the entry.
7119 * Each entry is 2 bytes wide, hence the
7120 * multiplication by 2.
7122 return (((TCL_TARGET_OFFSET(tcl
) & 0x3) << 1) + SCB_DISCONNECTED_LISTS
);
7126 * Return the untagged transaction id for a given target/channel lun.
7129 ahd_find_busy_tcl(struct ahd_softc
*ahd
, u_int tcl
)
7135 scb_offset
= ahd_index_busy_tcl(ahd
, &saved_scbptr
, tcl
);
7136 scbid
= ahd_inw_scbram(ahd
, scb_offset
);
7137 ahd_set_scbptr(ahd
, saved_scbptr
);
7142 ahd_busy_tcl(struct ahd_softc
*ahd
, u_int tcl
, u_int scbid
)
7147 scb_offset
= ahd_index_busy_tcl(ahd
, &saved_scbptr
, tcl
);
7148 ahd_outw(ahd
, scb_offset
, scbid
);
7149 ahd_set_scbptr(ahd
, saved_scbptr
);
7152 /************************** SCB and SCB queue management **********************/
7154 ahd_match_scb(struct ahd_softc
*ahd
, struct scb
*scb
, int target
,
7155 char channel
, int lun
, u_int tag
, role_t role
)
7157 int targ
= SCB_GET_TARGET(ahd
, scb
);
7158 char chan
= SCB_GET_CHANNEL(ahd
, scb
);
7159 int slun
= SCB_GET_LUN(scb
);
7162 match
= ((chan
== channel
) || (channel
== ALL_CHANNELS
));
7164 match
= ((targ
== target
) || (target
== CAM_TARGET_WILDCARD
));
7166 match
= ((lun
== slun
) || (lun
== CAM_LUN_WILDCARD
));
7168 #ifdef AHD_TARGET_MODE
7171 group
= XPT_FC_GROUP(scb
->io_ctx
->ccb_h
.func_code
);
7172 if (role
== ROLE_INITIATOR
) {
7173 match
= (group
!= XPT_FC_GROUP_TMODE
)
7174 && ((tag
== SCB_GET_TAG(scb
))
7175 || (tag
== SCB_LIST_NULL
));
7176 } else if (role
== ROLE_TARGET
) {
7177 match
= (group
== XPT_FC_GROUP_TMODE
)
7178 && ((tag
== scb
->io_ctx
->csio
.tag_id
)
7179 || (tag
== SCB_LIST_NULL
));
7181 #else /* !AHD_TARGET_MODE */
7182 match
= ((tag
== SCB_GET_TAG(scb
)) || (tag
== SCB_LIST_NULL
));
7183 #endif /* AHD_TARGET_MODE */
7190 ahd_freeze_devq(struct ahd_softc
*ahd
, struct scb
*scb
)
7196 target
= SCB_GET_TARGET(ahd
, scb
);
7197 lun
= SCB_GET_LUN(scb
);
7198 channel
= SCB_GET_CHANNEL(ahd
, scb
);
7200 ahd_search_qinfifo(ahd
, target
, channel
, lun
,
7201 /*tag*/SCB_LIST_NULL
, ROLE_UNKNOWN
,
7202 CAM_REQUEUE_REQ
, SEARCH_COMPLETE
);
7204 ahd_platform_freeze_devq(ahd
, scb
);
7208 ahd_qinfifo_requeue_tail(struct ahd_softc
*ahd
, struct scb
*scb
)
7210 struct scb
*prev_scb
;
7211 ahd_mode_state saved_modes
;
7213 saved_modes
= ahd_save_modes(ahd
);
7214 ahd_set_modes(ahd
, AHD_MODE_CCHAN
, AHD_MODE_CCHAN
);
7216 if (ahd_qinfifo_count(ahd
) != 0) {
7220 prev_pos
= AHD_QIN_WRAP(ahd
->qinfifonext
- 1);
7221 prev_tag
= ahd
->qinfifo
[prev_pos
];
7222 prev_scb
= ahd_lookup_scb(ahd
, prev_tag
);
7224 ahd_qinfifo_requeue(ahd
, prev_scb
, scb
);
7225 ahd_set_hnscb_qoff(ahd
, ahd
->qinfifonext
);
7226 ahd_restore_modes(ahd
, saved_modes
);
7230 ahd_qinfifo_requeue(struct ahd_softc
*ahd
, struct scb
*prev_scb
,
7233 if (prev_scb
== NULL
) {
7236 busaddr
= ahd_le32toh(scb
->hscb
->hscb_busaddr
);
7237 ahd_outl(ahd
, NEXT_QUEUED_SCB_ADDR
, busaddr
);
7239 prev_scb
->hscb
->next_hscb_busaddr
= scb
->hscb
->hscb_busaddr
;
7240 ahd_sync_scb(ahd
, prev_scb
,
7241 BUS_DMASYNC_PREREAD
|BUS_DMASYNC_PREWRITE
);
7243 ahd
->qinfifo
[AHD_QIN_WRAP(ahd
->qinfifonext
)] = SCB_GET_TAG(scb
);
7245 scb
->hscb
->next_hscb_busaddr
= ahd
->next_queued_hscb
->hscb_busaddr
;
7246 ahd_sync_scb(ahd
, scb
, BUS_DMASYNC_PREREAD
|BUS_DMASYNC_PREWRITE
);
7250 ahd_qinfifo_count(struct ahd_softc
*ahd
)
7254 u_int wrap_qinfifonext
;
7256 AHD_ASSERT_MODES(ahd
, AHD_MODE_CCHAN_MSK
, AHD_MODE_CCHAN_MSK
);
7257 qinpos
= ahd_get_snscb_qoff(ahd
);
7258 wrap_qinpos
= AHD_QIN_WRAP(qinpos
);
7259 wrap_qinfifonext
= AHD_QIN_WRAP(ahd
->qinfifonext
);
7260 if (wrap_qinfifonext
>= wrap_qinpos
)
7261 return (wrap_qinfifonext
- wrap_qinpos
);
7263 return (wrap_qinfifonext
7264 + ARRAY_SIZE(ahd
->qinfifo
) - wrap_qinpos
);
7268 ahd_reset_cmds_pending(struct ahd_softc
*ahd
)
7271 ahd_mode_state saved_modes
;
7274 saved_modes
= ahd_save_modes(ahd
);
7275 ahd_set_modes(ahd
, AHD_MODE_CCHAN
, AHD_MODE_CCHAN
);
7278 * Don't count any commands as outstanding that the
7279 * sequencer has already marked for completion.
7281 ahd_flush_qoutfifo(ahd
);
7284 LIST_FOREACH(scb
, &ahd
->pending_scbs
, pending_links
) {
7287 ahd_outw(ahd
, CMDS_PENDING
, pending_cmds
- ahd_qinfifo_count(ahd
));
7288 ahd_restore_modes(ahd
, saved_modes
);
7289 ahd
->flags
&= ~AHD_UPDATE_PEND_CMDS
;
7293 ahd_done_with_status(struct ahd_softc
*ahd
, struct scb
*scb
, uint32_t status
)
7298 ostat
= ahd_get_transaction_status(scb
);
7299 if (ostat
== CAM_REQ_INPROG
)
7300 ahd_set_transaction_status(scb
, status
);
7301 cstat
= ahd_get_transaction_status(scb
);
7302 if (cstat
!= CAM_REQ_CMP
)
7303 ahd_freeze_scb(scb
);
7308 ahd_search_qinfifo(struct ahd_softc
*ahd
, int target
, char channel
,
7309 int lun
, u_int tag
, role_t role
, uint32_t status
,
7310 ahd_search_action action
)
7313 struct scb
*mk_msg_scb
;
7314 struct scb
*prev_scb
;
7315 ahd_mode_state saved_modes
;
7328 /* Must be in CCHAN mode */
7329 saved_modes
= ahd_save_modes(ahd
);
7330 ahd_set_modes(ahd
, AHD_MODE_CCHAN
, AHD_MODE_CCHAN
);
7333 * Halt any pending SCB DMA. The sequencer will reinitiate
7334 * this dma if the qinfifo is not empty once we unpause.
7336 if ((ahd_inb(ahd
, CCSCBCTL
) & (CCARREN
|CCSCBEN
|CCSCBDIR
))
7337 == (CCARREN
|CCSCBEN
|CCSCBDIR
)) {
7338 ahd_outb(ahd
, CCSCBCTL
,
7339 ahd_inb(ahd
, CCSCBCTL
) & ~(CCARREN
|CCSCBEN
));
7340 while ((ahd_inb(ahd
, CCSCBCTL
) & (CCARREN
|CCSCBEN
)) != 0)
7343 /* Determine sequencer's position in the qinfifo. */
7344 qintail
= AHD_QIN_WRAP(ahd
->qinfifonext
);
7345 qinstart
= ahd_get_snscb_qoff(ahd
);
7346 qinpos
= AHD_QIN_WRAP(qinstart
);
7350 if (action
== SEARCH_PRINT
) {
7351 printf("qinstart = %d qinfifonext = %d\nQINFIFO:",
7352 qinstart
, ahd
->qinfifonext
);
7356 * Start with an empty queue. Entries that are not chosen
7357 * for removal will be re-added to the queue as we go.
7359 ahd
->qinfifonext
= qinstart
;
7360 busaddr
= ahd_le32toh(ahd
->next_queued_hscb
->hscb_busaddr
);
7361 ahd_outl(ahd
, NEXT_QUEUED_SCB_ADDR
, busaddr
);
7363 while (qinpos
!= qintail
) {
7364 scb
= ahd_lookup_scb(ahd
, ahd
->qinfifo
[qinpos
]);
7366 printf("qinpos = %d, SCB index = %d\n",
7367 qinpos
, ahd
->qinfifo
[qinpos
]);
7371 if (ahd_match_scb(ahd
, scb
, target
, channel
, lun
, tag
, role
)) {
7373 * We found an scb that needs to be acted on.
7377 case SEARCH_COMPLETE
:
7378 if ((scb
->flags
& SCB_ACTIVE
) == 0)
7379 printf("Inactive SCB in qinfifo\n");
7380 ahd_done_with_status(ahd
, scb
, status
);
7385 printf(" 0x%x", ahd
->qinfifo
[qinpos
]);
7388 ahd_qinfifo_requeue(ahd
, prev_scb
, scb
);
7393 ahd_qinfifo_requeue(ahd
, prev_scb
, scb
);
7396 qinpos
= AHD_QIN_WRAP(qinpos
+1);
7399 ahd_set_hnscb_qoff(ahd
, ahd
->qinfifonext
);
7401 if (action
== SEARCH_PRINT
)
7402 printf("\nWAITING_TID_QUEUES:\n");
7405 * Search waiting for selection lists. We traverse the
7406 * list of "their ids" waiting for selection and, if
7407 * appropriate, traverse the SCBs of each "their id"
7408 * looking for matches.
7410 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
7411 seq_flags2
= ahd_inb(ahd
, SEQ_FLAGS2
);
7412 if ((seq_flags2
& PENDING_MK_MESSAGE
) != 0) {
7413 scbid
= ahd_inw(ahd
, MK_MESSAGE_SCB
);
7414 mk_msg_scb
= ahd_lookup_scb(ahd
, scbid
);
7417 savedscbptr
= ahd_get_scbptr(ahd
);
7418 tid_next
= ahd_inw(ahd
, WAITING_TID_HEAD
);
7419 tid_prev
= SCB_LIST_NULL
;
7421 for (scbid
= tid_next
; !SCBID_IS_NULL(scbid
); scbid
= tid_next
) {
7426 if (targets
> AHD_NUM_TARGETS
)
7427 panic("TID LIST LOOP");
7429 if (scbid
>= ahd
->scb_data
.numscbs
) {
7430 printf("%s: Waiting TID List inconsistency. "
7431 "SCB index == 0x%x, yet numscbs == 0x%x.",
7432 ahd_name(ahd
), scbid
, ahd
->scb_data
.numscbs
);
7433 ahd_dump_card_state(ahd
);
7434 panic("for safety");
7436 scb
= ahd_lookup_scb(ahd
, scbid
);
7438 printf("%s: SCB = 0x%x Not Active!\n",
7439 ahd_name(ahd
), scbid
);
7440 panic("Waiting TID List traversal\n");
7442 ahd_set_scbptr(ahd
, scbid
);
7443 tid_next
= ahd_inw_scbram(ahd
, SCB_NEXT2
);
7444 if (ahd_match_scb(ahd
, scb
, target
, channel
, CAM_LUN_WILDCARD
,
7445 SCB_LIST_NULL
, ROLE_UNKNOWN
) == 0) {
7451 * We found a list of scbs that needs to be searched.
7453 if (action
== SEARCH_PRINT
)
7454 printf(" %d ( ", SCB_GET_TARGET(ahd
, scb
));
7456 found
+= ahd_search_scb_list(ahd
, target
, channel
,
7457 lun
, tag
, role
, status
,
7458 action
, &tid_head
, &tid_tail
,
7459 SCB_GET_TARGET(ahd
, scb
));
7461 * Check any MK_MESSAGE SCB that is still waiting to
7462 * enter this target's waiting for selection queue.
7464 if (mk_msg_scb
!= NULL
7465 && ahd_match_scb(ahd
, mk_msg_scb
, target
, channel
,
7469 * We found an scb that needs to be acted on.
7473 case SEARCH_COMPLETE
:
7474 if ((mk_msg_scb
->flags
& SCB_ACTIVE
) == 0)
7475 printf("Inactive SCB pending MK_MSG\n");
7476 ahd_done_with_status(ahd
, mk_msg_scb
, status
);
7482 printf("Removing MK_MSG scb\n");
7485 * Reset our tail to the tail of the
7486 * main per-target list.
7488 tail_offset
= WAITING_SCB_TAILS
7489 + (2 * SCB_GET_TARGET(ahd
, mk_msg_scb
));
7490 ahd_outw(ahd
, tail_offset
, tid_tail
);
7492 seq_flags2
&= ~PENDING_MK_MESSAGE
;
7493 ahd_outb(ahd
, SEQ_FLAGS2
, seq_flags2
);
7494 ahd_outw(ahd
, CMDS_PENDING
,
7495 ahd_inw(ahd
, CMDS_PENDING
)-1);
7500 printf(" 0x%x", SCB_GET_TAG(scb
));
7507 if (mk_msg_scb
!= NULL
7508 && SCBID_IS_NULL(tid_head
)
7509 && ahd_match_scb(ahd
, scb
, target
, channel
, CAM_LUN_WILDCARD
,
7510 SCB_LIST_NULL
, ROLE_UNKNOWN
)) {
7513 * When removing the last SCB for a target
7514 * queue with a pending MK_MESSAGE scb, we
7515 * must queue the MK_MESSAGE scb.
7517 printf("Queueing mk_msg_scb\n");
7518 tid_head
= ahd_inw(ahd
, MK_MESSAGE_SCB
);
7519 seq_flags2
&= ~PENDING_MK_MESSAGE
;
7520 ahd_outb(ahd
, SEQ_FLAGS2
, seq_flags2
);
7523 if (tid_head
!= scbid
)
7524 ahd_stitch_tid_list(ahd
, tid_prev
, tid_head
, tid_next
);
7525 if (!SCBID_IS_NULL(tid_head
))
7526 tid_prev
= tid_head
;
7527 if (action
== SEARCH_PRINT
)
7531 /* Restore saved state. */
7532 ahd_set_scbptr(ahd
, savedscbptr
);
7533 ahd_restore_modes(ahd
, saved_modes
);
7538 ahd_search_scb_list(struct ahd_softc
*ahd
, int target
, char channel
,
7539 int lun
, u_int tag
, role_t role
, uint32_t status
,
7540 ahd_search_action action
, u_int
*list_head
,
7541 u_int
*list_tail
, u_int tid
)
7549 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
7551 prev
= SCB_LIST_NULL
;
7553 *list_tail
= SCB_LIST_NULL
;
7554 for (scbid
= next
; !SCBID_IS_NULL(scbid
); scbid
= next
) {
7555 if (scbid
>= ahd
->scb_data
.numscbs
) {
7556 printf("%s:SCB List inconsistency. "
7557 "SCB == 0x%x, yet numscbs == 0x%x.",
7558 ahd_name(ahd
), scbid
, ahd
->scb_data
.numscbs
);
7559 ahd_dump_card_state(ahd
);
7560 panic("for safety");
7562 scb
= ahd_lookup_scb(ahd
, scbid
);
7564 printf("%s: SCB = %d Not Active!\n",
7565 ahd_name(ahd
), scbid
);
7566 panic("Waiting List traversal\n");
7568 ahd_set_scbptr(ahd
, scbid
);
7570 next
= ahd_inw_scbram(ahd
, SCB_NEXT
);
7571 if (ahd_match_scb(ahd
, scb
, target
, channel
,
7572 lun
, SCB_LIST_NULL
, role
) == 0) {
7578 case SEARCH_COMPLETE
:
7579 if ((scb
->flags
& SCB_ACTIVE
) == 0)
7580 printf("Inactive SCB in Waiting List\n");
7581 ahd_done_with_status(ahd
, scb
, status
);
7584 ahd_rem_wscb(ahd
, scbid
, prev
, next
, tid
);
7586 if (SCBID_IS_NULL(prev
))
7590 printf("0x%x ", scbid
);
7595 if (found
> AHD_SCB_MAX
)
7596 panic("SCB LIST LOOP");
7598 if (action
== SEARCH_COMPLETE
7599 || action
== SEARCH_REMOVE
)
7600 ahd_outw(ahd
, CMDS_PENDING
, ahd_inw(ahd
, CMDS_PENDING
) - found
);
7605 ahd_stitch_tid_list(struct ahd_softc
*ahd
, u_int tid_prev
,
7606 u_int tid_cur
, u_int tid_next
)
7608 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
7610 if (SCBID_IS_NULL(tid_cur
)) {
7612 /* Bypass current TID list */
7613 if (SCBID_IS_NULL(tid_prev
)) {
7614 ahd_outw(ahd
, WAITING_TID_HEAD
, tid_next
);
7616 ahd_set_scbptr(ahd
, tid_prev
);
7617 ahd_outw(ahd
, SCB_NEXT2
, tid_next
);
7619 if (SCBID_IS_NULL(tid_next
))
7620 ahd_outw(ahd
, WAITING_TID_TAIL
, tid_prev
);
7623 /* Stitch through tid_cur */
7624 if (SCBID_IS_NULL(tid_prev
)) {
7625 ahd_outw(ahd
, WAITING_TID_HEAD
, tid_cur
);
7627 ahd_set_scbptr(ahd
, tid_prev
);
7628 ahd_outw(ahd
, SCB_NEXT2
, tid_cur
);
7630 ahd_set_scbptr(ahd
, tid_cur
);
7631 ahd_outw(ahd
, SCB_NEXT2
, tid_next
);
7633 if (SCBID_IS_NULL(tid_next
))
7634 ahd_outw(ahd
, WAITING_TID_TAIL
, tid_cur
);
7639 * Manipulate the waiting for selection list and return the
7640 * scb that follows the one that we remove.
7643 ahd_rem_wscb(struct ahd_softc
*ahd
, u_int scbid
,
7644 u_int prev
, u_int next
, u_int tid
)
7648 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
7649 if (!SCBID_IS_NULL(prev
)) {
7650 ahd_set_scbptr(ahd
, prev
);
7651 ahd_outw(ahd
, SCB_NEXT
, next
);
7655 * SCBs that have MK_MESSAGE set in them may
7656 * cause the tail pointer to be updated without
7657 * setting the next pointer of the previous tail.
7658 * Only clear the tail if the removed SCB was
7661 tail_offset
= WAITING_SCB_TAILS
+ (2 * tid
);
7662 if (SCBID_IS_NULL(next
)
7663 && ahd_inw(ahd
, tail_offset
) == scbid
)
7664 ahd_outw(ahd
, tail_offset
, prev
);
7666 ahd_add_scb_to_free_list(ahd
, scbid
);
7671 * Add the SCB as selected by SCBPTR onto the on chip list of
7672 * free hardware SCBs. This list is empty/unused if we are not
7673 * performing SCB paging.
7676 ahd_add_scb_to_free_list(struct ahd_softc
*ahd
, u_int scbid
)
7678 /* XXX Need some other mechanism to designate "free". */
7680 * Invalidate the tag so that our abort
7681 * routines don't think it's active.
7682 ahd_outb(ahd, SCB_TAG, SCB_LIST_NULL);
7686 /******************************** Error Handling ******************************/
7688 * Abort all SCBs that match the given description (target/channel/lun/tag),
7689 * setting their status to the passed in status if the status has not already
7690 * been modified from CAM_REQ_INPROG. This routine assumes that the sequencer
7691 * is paused before it is called.
7694 ahd_abort_scbs(struct ahd_softc
*ahd
, int target
, char channel
,
7695 int lun
, u_int tag
, role_t role
, uint32_t status
)
7698 struct scb
*scbp_next
;
7704 ahd_mode_state saved_modes
;
7706 /* restore this when we're done */
7707 saved_modes
= ahd_save_modes(ahd
);
7708 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
7710 found
= ahd_search_qinfifo(ahd
, target
, channel
, lun
, SCB_LIST_NULL
,
7711 role
, CAM_REQUEUE_REQ
, SEARCH_COMPLETE
);
7714 * Clean out the busy target table for any untagged commands.
7718 if (target
!= CAM_TARGET_WILDCARD
) {
7725 if (lun
== CAM_LUN_WILDCARD
) {
7727 maxlun
= AHD_NUM_LUNS_NONPKT
;
7728 } else if (lun
>= AHD_NUM_LUNS_NONPKT
) {
7729 minlun
= maxlun
= 0;
7735 if (role
!= ROLE_TARGET
) {
7736 for (;i
< maxtarget
; i
++) {
7737 for (j
= minlun
;j
< maxlun
; j
++) {
7741 tcl
= BUILD_TCL_RAW(i
, 'A', j
);
7742 scbid
= ahd_find_busy_tcl(ahd
, tcl
);
7743 scbp
= ahd_lookup_scb(ahd
, scbid
);
7745 || ahd_match_scb(ahd
, scbp
, target
, channel
,
7746 lun
, tag
, role
) == 0)
7748 ahd_unbusy_tcl(ahd
, BUILD_TCL_RAW(i
, 'A', j
));
7754 * Don't abort commands that have already completed,
7755 * but haven't quite made it up to the host yet.
7757 ahd_flush_qoutfifo(ahd
);
7760 * Go through the pending CCB list and look for
7761 * commands for this target that are still active.
7762 * These are other tagged commands that were
7763 * disconnected when the reset occurred.
7765 scbp_next
= LIST_FIRST(&ahd
->pending_scbs
);
7766 while (scbp_next
!= NULL
) {
7768 scbp_next
= LIST_NEXT(scbp
, pending_links
);
7769 if (ahd_match_scb(ahd
, scbp
, target
, channel
, lun
, tag
, role
)) {
7772 ostat
= ahd_get_transaction_status(scbp
);
7773 if (ostat
== CAM_REQ_INPROG
)
7774 ahd_set_transaction_status(scbp
, status
);
7775 if (ahd_get_transaction_status(scbp
) != CAM_REQ_CMP
)
7776 ahd_freeze_scb(scbp
);
7777 if ((scbp
->flags
& SCB_ACTIVE
) == 0)
7778 printf("Inactive SCB on pending list\n");
7779 ahd_done(ahd
, scbp
);
7783 ahd_restore_modes(ahd
, saved_modes
);
7784 ahd_platform_abort_scbs(ahd
, target
, channel
, lun
, tag
, role
, status
);
7785 ahd
->flags
|= AHD_UPDATE_PEND_CMDS
;
7790 ahd_reset_current_bus(struct ahd_softc
*ahd
)
7794 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
7795 ahd_outb(ahd
, SIMODE1
, ahd_inb(ahd
, SIMODE1
) & ~ENSCSIRST
);
7796 scsiseq
= ahd_inb(ahd
, SCSISEQ0
) & ~(ENSELO
|ENARBO
|SCSIRSTO
);
7797 ahd_outb(ahd
, SCSISEQ0
, scsiseq
| SCSIRSTO
);
7798 ahd_flush_device_writes(ahd
);
7799 ahd_delay(AHD_BUSRESET_DELAY
);
7800 /* Turn off the bus reset */
7801 ahd_outb(ahd
, SCSISEQ0
, scsiseq
);
7802 ahd_flush_device_writes(ahd
);
7803 ahd_delay(AHD_BUSRESET_DELAY
);
7804 if ((ahd
->bugs
& AHD_SCSIRST_BUG
) != 0) {
7807 * Certain chip state is not cleared for
7808 * SCSI bus resets that we initiate, so
7809 * we must reset the chip.
7811 ahd_reset(ahd
, /*reinit*/TRUE
);
7812 ahd_intr_enable(ahd
, /*enable*/TRUE
);
7813 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
7816 ahd_clear_intstat(ahd
);
7820 ahd_reset_channel(struct ahd_softc
*ahd
, char channel
, int initiate_reset
)
7822 struct ahd_devinfo devinfo
;
7832 * Check if the last bus reset is cleared
7834 if (ahd
->flags
& AHD_BUS_RESET_ACTIVE
) {
7835 printf("%s: bus reset still active\n",
7839 ahd
->flags
|= AHD_BUS_RESET_ACTIVE
;
7841 ahd
->pending_device
= NULL
;
7843 ahd_compile_devinfo(&devinfo
,
7844 CAM_TARGET_WILDCARD
,
7845 CAM_TARGET_WILDCARD
,
7847 channel
, ROLE_UNKNOWN
);
7850 /* Make sure the sequencer is in a safe location. */
7851 ahd_clear_critical_section(ahd
);
7854 * Run our command complete fifos to ensure that we perform
7855 * completion processing on any commands that 'completed'
7856 * before the reset occurred.
7858 ahd_run_qoutfifo(ahd
);
7859 #ifdef AHD_TARGET_MODE
7860 if ((ahd
->flags
& AHD_TARGETROLE
) != 0) {
7861 ahd_run_tqinfifo(ahd
, /*paused*/TRUE
);
7864 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
7867 * Disable selections so no automatic hardware
7868 * functions will modify chip state.
7870 ahd_outb(ahd
, SCSISEQ0
, 0);
7871 ahd_outb(ahd
, SCSISEQ1
, 0);
7874 * Safely shut down our DMA engines. Always start with
7875 * the FIFO that is not currently active (if any are
7876 * actively connected).
7878 next_fifo
= fifo
= ahd_inb(ahd
, DFFSTAT
) & CURRFIFO
;
7879 if (next_fifo
> CURRFIFO_1
)
7880 /* If disconneced, arbitrarily start with FIFO1. */
7881 next_fifo
= fifo
= 0;
7883 next_fifo
^= CURRFIFO_1
;
7884 ahd_set_modes(ahd
, next_fifo
, next_fifo
);
7885 ahd_outb(ahd
, DFCNTRL
,
7886 ahd_inb(ahd
, DFCNTRL
) & ~(SCSIEN
|HDMAEN
));
7887 while ((ahd_inb(ahd
, DFCNTRL
) & HDMAENACK
) != 0)
7890 * Set CURRFIFO to the now inactive channel.
7892 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
7893 ahd_outb(ahd
, DFFSTAT
, next_fifo
);
7894 } while (next_fifo
!= fifo
);
7897 * Reset the bus if we are initiating this reset
7899 ahd_clear_msg_state(ahd
);
7900 ahd_outb(ahd
, SIMODE1
,
7901 ahd_inb(ahd
, SIMODE1
) & ~(ENBUSFREE
|ENSCSIRST
));
7904 ahd_reset_current_bus(ahd
);
7906 ahd_clear_intstat(ahd
);
7909 * Clean up all the state information for the
7910 * pending transactions on this bus.
7912 found
= ahd_abort_scbs(ahd
, CAM_TARGET_WILDCARD
, channel
,
7913 CAM_LUN_WILDCARD
, SCB_LIST_NULL
,
7914 ROLE_UNKNOWN
, CAM_SCSI_BUS_RESET
);
7917 * Cleanup anything left in the FIFOs.
7919 ahd_clear_fifo(ahd
, 0);
7920 ahd_clear_fifo(ahd
, 1);
7923 * Reenable selections
7925 ahd_outb(ahd
, SIMODE1
, ahd_inb(ahd
, SIMODE1
) | ENSCSIRST
);
7926 scsiseq
= ahd_inb(ahd
, SCSISEQ_TEMPLATE
);
7927 ahd_outb(ahd
, SCSISEQ1
, scsiseq
& (ENSELI
|ENRSELI
|ENAUTOATNP
));
7929 max_scsiid
= (ahd
->features
& AHD_WIDE
) ? 15 : 7;
7930 #ifdef AHD_TARGET_MODE
7932 * Send an immediate notify ccb to all target more peripheral
7933 * drivers affected by this action.
7935 for (target
= 0; target
<= max_scsiid
; target
++) {
7936 struct ahd_tmode_tstate
* tstate
;
7939 tstate
= ahd
->enabled_targets
[target
];
7942 for (lun
= 0; lun
< AHD_NUM_LUNS
; lun
++) {
7943 struct ahd_tmode_lstate
* lstate
;
7945 lstate
= tstate
->enabled_luns
[lun
];
7949 ahd_queue_lstate_event(ahd
, lstate
, CAM_TARGET_WILDCARD
,
7950 EVENT_TYPE_BUS_RESET
, /*arg*/0);
7951 ahd_send_lstate_events(ahd
, lstate
);
7955 /* Notify the XPT that a bus reset occurred */
7956 ahd_send_async(ahd
, devinfo
.channel
, CAM_TARGET_WILDCARD
,
7957 CAM_LUN_WILDCARD
, AC_BUS_RESET
);
7960 * Revert to async/narrow transfers until we renegotiate.
7962 for (target
= 0; target
<= max_scsiid
; target
++) {
7964 if (ahd
->enabled_targets
[target
] == NULL
)
7966 for (initiator
= 0; initiator
<= max_scsiid
; initiator
++) {
7967 struct ahd_devinfo devinfo
;
7969 ahd_compile_devinfo(&devinfo
, target
, initiator
,
7972 ahd_set_width(ahd
, &devinfo
, MSG_EXT_WDTR_BUS_8_BIT
,
7973 AHD_TRANS_CUR
, /*paused*/TRUE
);
7974 ahd_set_syncrate(ahd
, &devinfo
, /*period*/0,
7975 /*offset*/0, /*ppr_options*/0,
7976 AHD_TRANS_CUR
, /*paused*/TRUE
);
7985 /**************************** Statistics Processing ***************************/
7987 ahd_stat_timer(void *arg
)
7989 struct ahd_softc
*ahd
= arg
;
7995 enint_coal
= ahd
->hs_mailbox
& ENINT_COALESCE
;
7996 if (ahd
->cmdcmplt_total
> ahd
->int_coalescing_threshold
)
7997 enint_coal
|= ENINT_COALESCE
;
7998 else if (ahd
->cmdcmplt_total
< ahd
->int_coalescing_stop_threshold
)
7999 enint_coal
&= ~ENINT_COALESCE
;
8001 if (enint_coal
!= (ahd
->hs_mailbox
& ENINT_COALESCE
)) {
8002 ahd_enable_coalescing(ahd
, enint_coal
);
8004 if ((ahd_debug
& AHD_SHOW_INT_COALESCING
) != 0)
8005 printf("%s: Interrupt coalescing "
8006 "now %sabled. Cmds %d\n",
8008 (enint_coal
& ENINT_COALESCE
) ? "en" : "dis",
8009 ahd
->cmdcmplt_total
);
8013 ahd
->cmdcmplt_bucket
= (ahd
->cmdcmplt_bucket
+1) & (AHD_STAT_BUCKETS
-1);
8014 ahd
->cmdcmplt_total
-= ahd
->cmdcmplt_counts
[ahd
->cmdcmplt_bucket
];
8015 ahd
->cmdcmplt_counts
[ahd
->cmdcmplt_bucket
] = 0;
8016 ahd_timer_reset(&ahd
->stat_timer
, AHD_STAT_UPDATE_US
,
8017 ahd_stat_timer
, ahd
);
8018 ahd_unlock(ahd
, &s
);
8021 /****************************** Status Processing *****************************/
8023 ahd_handle_scb_status(struct ahd_softc
*ahd
, struct scb
*scb
)
8025 if (scb
->hscb
->shared_data
.istatus
.scsi_status
!= 0) {
8026 ahd_handle_scsi_status(ahd
, scb
);
8028 ahd_calc_residual(ahd
, scb
);
8034 ahd_handle_scsi_status(struct ahd_softc
*ahd
, struct scb
*scb
)
8036 struct hardware_scb
*hscb
;
8040 * The sequencer freezes its select-out queue
8041 * anytime a SCSI status error occurs. We must
8042 * handle the error and increment our qfreeze count
8043 * to allow the sequencer to continue. We don't
8044 * bother clearing critical sections here since all
8045 * operations are on data structures that the sequencer
8046 * is not touching once the queue is frozen.
8050 if (ahd_is_paused(ahd
)) {
8057 /* Freeze the queue until the client sees the error. */
8058 ahd_freeze_devq(ahd
, scb
);
8059 ahd_freeze_scb(scb
);
8061 ahd_outw(ahd
, KERNEL_QFREEZE_COUNT
, ahd
->qfreeze_cnt
);
8066 /* Don't want to clobber the original sense code */
8067 if ((scb
->flags
& SCB_SENSE
) != 0) {
8069 * Clear the SCB_SENSE Flag and perform
8070 * a normal command completion.
8072 scb
->flags
&= ~SCB_SENSE
;
8073 ahd_set_transaction_status(scb
, CAM_AUTOSENSE_FAIL
);
8077 ahd_set_transaction_status(scb
, CAM_SCSI_STATUS_ERROR
);
8078 ahd_set_scsi_status(scb
, hscb
->shared_data
.istatus
.scsi_status
);
8079 switch (hscb
->shared_data
.istatus
.scsi_status
) {
8080 case STATUS_PKT_SENSE
:
8082 struct scsi_status_iu_header
*siu
;
8084 ahd_sync_sense(ahd
, scb
, BUS_DMASYNC_POSTREAD
);
8085 siu
= (struct scsi_status_iu_header
*)scb
->sense_data
;
8086 ahd_set_scsi_status(scb
, siu
->status
);
8088 if ((ahd_debug
& AHD_SHOW_SENSE
) != 0) {
8089 ahd_print_path(ahd
, scb
);
8090 printf("SCB 0x%x Received PKT Status of 0x%x\n",
8091 SCB_GET_TAG(scb
), siu
->status
);
8092 printf("\tflags = 0x%x, sense len = 0x%x, "
8094 siu
->flags
, scsi_4btoul(siu
->sense_length
),
8095 scsi_4btoul(siu
->pkt_failures_length
));
8098 if ((siu
->flags
& SIU_RSPVALID
) != 0) {
8099 ahd_print_path(ahd
, scb
);
8100 if (scsi_4btoul(siu
->pkt_failures_length
) < 4) {
8101 printf("Unable to parse pkt_failures\n");
8104 switch (SIU_PKTFAIL_CODE(siu
)) {
8106 printf("No packet failure found\n");
8108 case SIU_PFC_CIU_FIELDS_INVALID
:
8109 printf("Invalid Command IU Field\n");
8111 case SIU_PFC_TMF_NOT_SUPPORTED
:
8112 printf("TMF not supportd\n");
8114 case SIU_PFC_TMF_FAILED
:
8115 printf("TMF failed\n");
8117 case SIU_PFC_INVALID_TYPE_CODE
:
8118 printf("Invalid L_Q Type code\n");
8120 case SIU_PFC_ILLEGAL_REQUEST
:
8121 printf("Illegal request\n");
8126 if (siu
->status
== SCSI_STATUS_OK
)
8127 ahd_set_transaction_status(scb
,
8130 if ((siu
->flags
& SIU_SNSVALID
) != 0) {
8131 scb
->flags
|= SCB_PKT_SENSE
;
8133 if ((ahd_debug
& AHD_SHOW_SENSE
) != 0)
8134 printf("Sense data available\n");
8140 case SCSI_STATUS_CMD_TERMINATED
:
8141 case SCSI_STATUS_CHECK_COND
:
8143 struct ahd_devinfo devinfo
;
8144 struct ahd_dma_seg
*sg
;
8145 struct scsi_sense
*sc
;
8146 struct ahd_initiator_tinfo
*targ_info
;
8147 struct ahd_tmode_tstate
*tstate
;
8148 struct ahd_transinfo
*tinfo
;
8150 if (ahd_debug
& AHD_SHOW_SENSE
) {
8151 ahd_print_path(ahd
, scb
);
8152 printf("SCB %d: requests Check Status\n",
8157 if (ahd_perform_autosense(scb
) == 0)
8160 ahd_compile_devinfo(&devinfo
, SCB_GET_OUR_ID(scb
),
8161 SCB_GET_TARGET(ahd
, scb
),
8163 SCB_GET_CHANNEL(ahd
, scb
),
8165 targ_info
= ahd_fetch_transinfo(ahd
,
8170 tinfo
= &targ_info
->curr
;
8172 sc
= (struct scsi_sense
*)hscb
->shared_data
.idata
.cdb
;
8174 * Save off the residual if there is one.
8176 ahd_update_residual(ahd
, scb
);
8178 if (ahd_debug
& AHD_SHOW_SENSE
) {
8179 ahd_print_path(ahd
, scb
);
8180 printf("Sending Sense\n");
8184 sg
= ahd_sg_setup(ahd
, scb
, sg
, ahd_get_sense_bufaddr(ahd
, scb
),
8185 ahd_get_sense_bufsize(ahd
, scb
),
8187 sc
->opcode
= REQUEST_SENSE
;
8189 if (tinfo
->protocol_version
<= SCSI_REV_2
8190 && SCB_GET_LUN(scb
) < 8)
8191 sc
->byte2
= SCB_GET_LUN(scb
) << 5;
8194 sc
->length
= ahd_get_sense_bufsize(ahd
, scb
);
8198 * We can't allow the target to disconnect.
8199 * This will be an untagged transaction and
8200 * having the target disconnect will make this
8201 * transaction indestinguishable from outstanding
8202 * tagged transactions.
8207 * This request sense could be because the
8208 * the device lost power or in some other
8209 * way has lost our transfer negotiations.
8210 * Renegotiate if appropriate. Unit attention
8211 * errors will be reported before any data
8214 if (ahd_get_residual(scb
) == ahd_get_transfer_length(scb
)) {
8215 ahd_update_neg_request(ahd
, &devinfo
,
8217 AHD_NEG_IF_NON_ASYNC
);
8219 if (tstate
->auto_negotiate
& devinfo
.target_mask
) {
8220 hscb
->control
|= MK_MESSAGE
;
8222 ~(SCB_NEGOTIATE
|SCB_ABORT
|SCB_DEVICE_RESET
);
8223 scb
->flags
|= SCB_AUTO_NEGOTIATE
;
8225 hscb
->cdb_len
= sizeof(*sc
);
8226 ahd_setup_data_scb(ahd
, scb
);
8227 scb
->flags
|= SCB_SENSE
;
8228 ahd_queue_scb(ahd
, scb
);
8231 case SCSI_STATUS_OK
:
8232 printf("%s: Interrupted for staus of 0???\n",
8242 * Calculate the residual for a just completed SCB.
8245 ahd_calc_residual(struct ahd_softc
*ahd
, struct scb
*scb
)
8247 struct hardware_scb
*hscb
;
8248 struct initiator_status
*spkt
;
8250 uint32_t resid_sgptr
;
8256 * SG_STATUS_VALID clear in sgptr.
8257 * 2) Transferless command
8258 * 3) Never performed any transfers.
8259 * sgptr has SG_FULL_RESID set.
8260 * 4) No residual but target did not
8261 * save data pointers after the
8262 * last transfer, so sgptr was
8264 * 5) We have a partial residual.
8265 * Use residual_sgptr to determine
8270 sgptr
= ahd_le32toh(hscb
->sgptr
);
8271 if ((sgptr
& SG_STATUS_VALID
) == 0)
8274 sgptr
&= ~SG_STATUS_VALID
;
8276 if ((sgptr
& SG_LIST_NULL
) != 0)
8281 * Residual fields are the same in both
8282 * target and initiator status packets,
8283 * so we can always use the initiator fields
8284 * regardless of the role for this SCB.
8286 spkt
= &hscb
->shared_data
.istatus
;
8287 resid_sgptr
= ahd_le32toh(spkt
->residual_sgptr
);
8288 if ((sgptr
& SG_FULL_RESID
) != 0) {
8290 resid
= ahd_get_transfer_length(scb
);
8291 } else if ((resid_sgptr
& SG_LIST_NULL
) != 0) {
8294 } else if ((resid_sgptr
& SG_OVERRUN_RESID
) != 0) {
8295 ahd_print_path(ahd
, scb
);
8296 printf("data overrun detected Tag == 0x%x.\n",
8298 ahd_freeze_devq(ahd
, scb
);
8299 ahd_set_transaction_status(scb
, CAM_DATA_RUN_ERR
);
8300 ahd_freeze_scb(scb
);
8302 } else if ((resid_sgptr
& ~SG_PTR_MASK
) != 0) {
8303 panic("Bogus resid sgptr value 0x%x\n", resid_sgptr
);
8306 struct ahd_dma_seg
*sg
;
8309 * Remainder of the SG where the transfer
8312 resid
= ahd_le32toh(spkt
->residual_datacnt
) & AHD_SG_LEN_MASK
;
8313 sg
= ahd_sg_bus_to_virt(ahd
, scb
, resid_sgptr
& SG_PTR_MASK
);
8315 /* The residual sg_ptr always points to the next sg */
8319 * Add up the contents of all residual
8320 * SG segments that are after the SG where
8321 * the transfer stopped.
8323 while ((ahd_le32toh(sg
->len
) & AHD_DMA_LAST_SEG
) == 0) {
8325 resid
+= ahd_le32toh(sg
->len
) & AHD_SG_LEN_MASK
;
8328 if ((scb
->flags
& SCB_SENSE
) == 0)
8329 ahd_set_residual(scb
, resid
);
8331 ahd_set_sense_residual(scb
, resid
);
8334 if ((ahd_debug
& AHD_SHOW_MISC
) != 0) {
8335 ahd_print_path(ahd
, scb
);
8336 printf("Handled %sResidual of %d bytes\n",
8337 (scb
->flags
& SCB_SENSE
) ? "Sense " : "", resid
);
8342 /******************************* Target Mode **********************************/
8343 #ifdef AHD_TARGET_MODE
8345 * Add a target mode event to this lun's queue
8348 ahd_queue_lstate_event(struct ahd_softc
*ahd
, struct ahd_tmode_lstate
*lstate
,
8349 u_int initiator_id
, u_int event_type
, u_int event_arg
)
8351 struct ahd_tmode_event
*event
;
8354 xpt_freeze_devq(lstate
->path
, /*count*/1);
8355 if (lstate
->event_w_idx
>= lstate
->event_r_idx
)
8356 pending
= lstate
->event_w_idx
- lstate
->event_r_idx
;
8358 pending
= AHD_TMODE_EVENT_BUFFER_SIZE
+ 1
8359 - (lstate
->event_r_idx
- lstate
->event_w_idx
);
8361 if (event_type
== EVENT_TYPE_BUS_RESET
8362 || event_type
== MSG_BUS_DEV_RESET
) {
8364 * Any earlier events are irrelevant, so reset our buffer.
8365 * This has the effect of allowing us to deal with reset
8366 * floods (an external device holding down the reset line)
8367 * without losing the event that is really interesting.
8369 lstate
->event_r_idx
= 0;
8370 lstate
->event_w_idx
= 0;
8371 xpt_release_devq(lstate
->path
, pending
, /*runqueue*/FALSE
);
8374 if (pending
== AHD_TMODE_EVENT_BUFFER_SIZE
) {
8375 xpt_print_path(lstate
->path
);
8376 printf("immediate event %x:%x lost\n",
8377 lstate
->event_buffer
[lstate
->event_r_idx
].event_type
,
8378 lstate
->event_buffer
[lstate
->event_r_idx
].event_arg
);
8379 lstate
->event_r_idx
++;
8380 if (lstate
->event_r_idx
== AHD_TMODE_EVENT_BUFFER_SIZE
)
8381 lstate
->event_r_idx
= 0;
8382 xpt_release_devq(lstate
->path
, /*count*/1, /*runqueue*/FALSE
);
8385 event
= &lstate
->event_buffer
[lstate
->event_w_idx
];
8386 event
->initiator_id
= initiator_id
;
8387 event
->event_type
= event_type
;
8388 event
->event_arg
= event_arg
;
8389 lstate
->event_w_idx
++;
8390 if (lstate
->event_w_idx
== AHD_TMODE_EVENT_BUFFER_SIZE
)
8391 lstate
->event_w_idx
= 0;
8395 * Send any target mode events queued up waiting
8396 * for immediate notify resources.
8399 ahd_send_lstate_events(struct ahd_softc
*ahd
, struct ahd_tmode_lstate
*lstate
)
8401 struct ccb_hdr
*ccbh
;
8402 struct ccb_immed_notify
*inot
;
8404 while (lstate
->event_r_idx
!= lstate
->event_w_idx
8405 && (ccbh
= SLIST_FIRST(&lstate
->immed_notifies
)) != NULL
) {
8406 struct ahd_tmode_event
*event
;
8408 event
= &lstate
->event_buffer
[lstate
->event_r_idx
];
8409 SLIST_REMOVE_HEAD(&lstate
->immed_notifies
, sim_links
.sle
);
8410 inot
= (struct ccb_immed_notify
*)ccbh
;
8411 switch (event
->event_type
) {
8412 case EVENT_TYPE_BUS_RESET
:
8413 ccbh
->status
= CAM_SCSI_BUS_RESET
|CAM_DEV_QFRZN
;
8416 ccbh
->status
= CAM_MESSAGE_RECV
|CAM_DEV_QFRZN
;
8417 inot
->message_args
[0] = event
->event_type
;
8418 inot
->message_args
[1] = event
->event_arg
;
8421 inot
->initiator_id
= event
->initiator_id
;
8422 inot
->sense_len
= 0;
8423 xpt_done((union ccb
*)inot
);
8424 lstate
->event_r_idx
++;
8425 if (lstate
->event_r_idx
== AHD_TMODE_EVENT_BUFFER_SIZE
)
8426 lstate
->event_r_idx
= 0;
8431 /******************** Sequencer Program Patching/Download *********************/
8435 ahd_dumpseq(struct ahd_softc
* ahd
)
8442 ahd_outb(ahd
, SEQCTL0
, PERRORDIS
|FAILDIS
|FASTMODE
|LOADRAM
);
8443 ahd_outw(ahd
, PRGMCNT
, 0);
8444 for (i
= 0; i
< max_prog
; i
++) {
8445 uint8_t ins_bytes
[4];
8447 ahd_insb(ahd
, SEQRAM
, ins_bytes
, 4);
8448 printf("0x%08x\n", ins_bytes
[0] << 24
8449 | ins_bytes
[1] << 16
8457 ahd_loadseq(struct ahd_softc
*ahd
)
8459 struct cs cs_table
[num_critical_sections
];
8460 u_int begin_set
[num_critical_sections
];
8461 u_int end_set
[num_critical_sections
];
8462 struct patch
*cur_patch
;
8468 u_int sg_prefetch_cnt
;
8469 u_int sg_prefetch_cnt_limit
;
8470 u_int sg_prefetch_align
;
8472 u_int cacheline_mask
;
8473 uint8_t download_consts
[DOWNLOAD_CONST_COUNT
];
8476 printf("%s: Downloading Sequencer Program...",
8479 #if DOWNLOAD_CONST_COUNT != 8
8480 #error "Download Const Mismatch"
8483 * Start out with 0 critical sections
8484 * that apply to this firmware load.
8488 memset(begin_set
, 0, sizeof(begin_set
));
8489 memset(end_set
, 0, sizeof(end_set
));
8492 * Setup downloadable constant table.
8494 * The computation for the S/G prefetch variables is
8495 * a bit complicated. We would like to always fetch
8496 * in terms of cachelined sized increments. However,
8497 * if the cacheline is not an even multiple of the
8498 * SG element size or is larger than our SG RAM, using
8499 * just the cache size might leave us with only a portion
8500 * of an SG element at the tail of a prefetch. If the
8501 * cacheline is larger than our S/G prefetch buffer less
8502 * the size of an SG element, we may round down to a cacheline
8503 * that doesn't contain any or all of the S/G of interest
8504 * within the bounds of our S/G ram. Provide variables to
8505 * the sequencer that will allow it to handle these edge
8508 /* Start by aligning to the nearest cacheline. */
8509 sg_prefetch_align
= ahd
->pci_cachesize
;
8510 if (sg_prefetch_align
== 0)
8511 sg_prefetch_align
= 8;
8512 /* Round down to the nearest power of 2. */
8513 while (powerof2(sg_prefetch_align
) == 0)
8514 sg_prefetch_align
--;
8516 cacheline_mask
= sg_prefetch_align
- 1;
8519 * If the cacheline boundary is greater than half our prefetch RAM
8520 * we risk not being able to fetch even a single complete S/G
8521 * segment if we align to that boundary.
8523 if (sg_prefetch_align
> CCSGADDR_MAX
/2)
8524 sg_prefetch_align
= CCSGADDR_MAX
/2;
8525 /* Start by fetching a single cacheline. */
8526 sg_prefetch_cnt
= sg_prefetch_align
;
8528 * Increment the prefetch count by cachelines until
8529 * at least one S/G element will fit.
8531 sg_size
= sizeof(struct ahd_dma_seg
);
8532 if ((ahd
->flags
& AHD_64BIT_ADDRESSING
) != 0)
8533 sg_size
= sizeof(struct ahd_dma64_seg
);
8534 while (sg_prefetch_cnt
< sg_size
)
8535 sg_prefetch_cnt
+= sg_prefetch_align
;
8537 * If the cacheline is not an even multiple of
8538 * the S/G size, we may only get a partial S/G when
8539 * we align. Add a cacheline if this is the case.
8541 if ((sg_prefetch_align
% sg_size
) != 0
8542 && (sg_prefetch_cnt
< CCSGADDR_MAX
))
8543 sg_prefetch_cnt
+= sg_prefetch_align
;
8545 * Lastly, compute a value that the sequencer can use
8546 * to determine if the remainder of the CCSGRAM buffer
8547 * has a full S/G element in it.
8549 sg_prefetch_cnt_limit
= -(sg_prefetch_cnt
- sg_size
+ 1);
8550 download_consts
[SG_PREFETCH_CNT
] = sg_prefetch_cnt
;
8551 download_consts
[SG_PREFETCH_CNT_LIMIT
] = sg_prefetch_cnt_limit
;
8552 download_consts
[SG_PREFETCH_ALIGN_MASK
] = ~(sg_prefetch_align
- 1);
8553 download_consts
[SG_PREFETCH_ADDR_MASK
] = (sg_prefetch_align
- 1);
8554 download_consts
[SG_SIZEOF
] = sg_size
;
8555 download_consts
[PKT_OVERRUN_BUFOFFSET
] =
8556 (ahd
->overrun_buf
- (uint8_t *)ahd
->qoutfifo
) / 256;
8557 download_consts
[SCB_TRANSFER_SIZE
] = SCB_TRANSFER_SIZE_1BYTE_LUN
;
8558 download_consts
[CACHELINE_MASK
] = cacheline_mask
;
8559 cur_patch
= patches
;
8562 ahd_outb(ahd
, SEQCTL0
, PERRORDIS
|FAILDIS
|FASTMODE
|LOADRAM
);
8563 ahd_outw(ahd
, PRGMCNT
, 0);
8565 for (i
= 0; i
< sizeof(seqprog
)/4; i
++) {
8566 if (ahd_check_patch(ahd
, &cur_patch
, i
, &skip_addr
) == 0) {
8568 * Don't download this instruction as it
8569 * is in a patch that was removed.
8574 * Move through the CS table until we find a CS
8575 * that might apply to this instruction.
8577 for (; cur_cs
< num_critical_sections
; cur_cs
++) {
8578 if (critical_sections
[cur_cs
].end
<= i
) {
8579 if (begin_set
[cs_count
] == TRUE
8580 && end_set
[cs_count
] == FALSE
) {
8581 cs_table
[cs_count
].end
= downloaded
;
8582 end_set
[cs_count
] = TRUE
;
8587 if (critical_sections
[cur_cs
].begin
<= i
8588 && begin_set
[cs_count
] == FALSE
) {
8589 cs_table
[cs_count
].begin
= downloaded
;
8590 begin_set
[cs_count
] = TRUE
;
8594 ahd_download_instr(ahd
, i
, download_consts
);
8598 ahd
->num_critical_sections
= cs_count
;
8599 if (cs_count
!= 0) {
8601 cs_count
*= sizeof(struct cs
);
8602 ahd
->critical_sections
= malloc(cs_count
, M_DEVBUF
, M_NOWAIT
);
8603 if (ahd
->critical_sections
== NULL
)
8604 panic("ahd_loadseq: Could not malloc");
8605 memcpy(ahd
->critical_sections
, cs_table
, cs_count
);
8607 ahd_outb(ahd
, SEQCTL0
, PERRORDIS
|FAILDIS
|FASTMODE
);
8610 printf(" %d instructions downloaded\n", downloaded
);
8611 printf("%s: Features 0x%x, Bugs 0x%x, Flags 0x%x\n",
8612 ahd_name(ahd
), ahd
->features
, ahd
->bugs
, ahd
->flags
);
8617 ahd_check_patch(struct ahd_softc
*ahd
, struct patch
**start_patch
,
8618 u_int start_instr
, u_int
*skip_addr
)
8620 struct patch
*cur_patch
;
8621 struct patch
*last_patch
;
8624 num_patches
= ARRAY_SIZE(patches
);
8625 last_patch
= &patches
[num_patches
];
8626 cur_patch
= *start_patch
;
8628 while (cur_patch
< last_patch
&& start_instr
== cur_patch
->begin
) {
8630 if (cur_patch
->patch_func(ahd
) == 0) {
8632 /* Start rejecting code */
8633 *skip_addr
= start_instr
+ cur_patch
->skip_instr
;
8634 cur_patch
+= cur_patch
->skip_patch
;
8636 /* Accepted this patch. Advance to the next
8637 * one and wait for our intruction pointer to
8644 *start_patch
= cur_patch
;
8645 if (start_instr
< *skip_addr
)
8646 /* Still skipping */
8653 ahd_resolve_seqaddr(struct ahd_softc
*ahd
, u_int address
)
8655 struct patch
*cur_patch
;
8661 cur_patch
= patches
;
8664 for (i
= 0; i
< address
;) {
8666 ahd_check_patch(ahd
, &cur_patch
, i
, &skip_addr
);
8668 if (skip_addr
> i
) {
8671 end_addr
= MIN(address
, skip_addr
);
8672 address_offset
+= end_addr
- i
;
8678 return (address
- address_offset
);
8682 ahd_download_instr(struct ahd_softc
*ahd
, u_int instrptr
, uint8_t *dconsts
)
8684 union ins_formats instr
;
8685 struct ins_format1
*fmt1_ins
;
8686 struct ins_format3
*fmt3_ins
;
8690 * The firmware is always compiled into a little endian format.
8692 instr
.integer
= ahd_le32toh(*(uint32_t*)&seqprog
[instrptr
* 4]);
8694 fmt1_ins
= &instr
.format1
;
8697 /* Pull the opcode */
8698 opcode
= instr
.format1
.opcode
;
8709 fmt3_ins
= &instr
.format3
;
8710 fmt3_ins
->address
= ahd_resolve_seqaddr(ahd
, fmt3_ins
->address
);
8719 if (fmt1_ins
->parity
!= 0) {
8720 fmt1_ins
->immediate
= dconsts
[fmt1_ins
->immediate
];
8722 fmt1_ins
->parity
= 0;
8728 /* Calculate odd parity for the instruction */
8729 for (i
= 0, count
= 0; i
< 31; i
++) {
8733 if ((instr
.integer
& mask
) != 0)
8736 if ((count
& 0x01) == 0)
8737 instr
.format1
.parity
= 1;
8739 /* The sequencer is a little endian cpu */
8740 instr
.integer
= ahd_htole32(instr
.integer
);
8741 ahd_outsb(ahd
, SEQRAM
, instr
.bytes
, 4);
8745 panic("Unknown opcode encountered in seq program");
8751 ahd_probe_stack_size(struct ahd_softc
*ahd
)
8760 * We avoid using 0 as a pattern to avoid
8761 * confusion if the stack implementation
8762 * "back-fills" with zeros when "poping'
8765 for (i
= 1; i
<= last_probe
+1; i
++) {
8766 ahd_outb(ahd
, STACK
, i
& 0xFF);
8767 ahd_outb(ahd
, STACK
, (i
>> 8) & 0xFF);
8771 for (i
= last_probe
+1; i
> 0; i
--) {
8774 stack_entry
= ahd_inb(ahd
, STACK
)
8775 |(ahd_inb(ahd
, STACK
) << 8);
8776 if (stack_entry
!= i
)
8782 return (last_probe
);
8786 ahd_print_register(ahd_reg_parse_entry_t
*table
, u_int num_entries
,
8787 const char *name
, u_int address
, u_int value
,
8788 u_int
*cur_column
, u_int wrap_point
)
8793 if (cur_column
!= NULL
&& *cur_column
>= wrap_point
) {
8797 printed
= printf("%s[0x%x]", name
, value
);
8798 if (table
== NULL
) {
8799 printed
+= printf(" ");
8800 *cur_column
+= printed
;
8804 while (printed_mask
!= 0xFF) {
8807 for (entry
= 0; entry
< num_entries
; entry
++) {
8808 if (((value
& table
[entry
].mask
)
8809 != table
[entry
].value
)
8810 || ((printed_mask
& table
[entry
].mask
)
8811 == table
[entry
].mask
))
8814 printed
+= printf("%s%s",
8815 printed_mask
== 0 ? ":(" : "|",
8817 printed_mask
|= table
[entry
].mask
;
8821 if (entry
>= num_entries
)
8824 if (printed_mask
!= 0)
8825 printed
+= printf(") ");
8827 printed
+= printf(" ");
8828 if (cur_column
!= NULL
)
8829 *cur_column
+= printed
;
8834 ahd_dump_card_state(struct ahd_softc
*ahd
)
8837 ahd_mode_state saved_modes
;
8841 u_int saved_scb_index
;
8845 if (ahd_is_paused(ahd
)) {
8851 saved_modes
= ahd_save_modes(ahd
);
8852 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
8853 printf(">>>>>>>>>>>>>>>>>> Dump Card State Begins <<<<<<<<<<<<<<<<<\n"
8854 "%s: Dumping Card State at program address 0x%x Mode 0x%x\n",
8856 ahd_inw(ahd
, CURADDR
),
8857 ahd_build_mode_state(ahd
, ahd
->saved_src_mode
,
8858 ahd
->saved_dst_mode
));
8860 printf("Card was paused\n");
8862 if (ahd_check_cmdcmpltqueues(ahd
))
8863 printf("Completions are pending\n");
8866 * Mode independent registers.
8869 ahd_intstat_print(ahd_inb(ahd
, INTSTAT
), &cur_col
, 50);
8870 ahd_seloid_print(ahd_inb(ahd
, SELOID
), &cur_col
, 50);
8871 ahd_selid_print(ahd_inb(ahd
, SELID
), &cur_col
, 50);
8872 ahd_hs_mailbox_print(ahd_inb(ahd
, LOCAL_HS_MAILBOX
), &cur_col
, 50);
8873 ahd_intctl_print(ahd_inb(ahd
, INTCTL
), &cur_col
, 50);
8874 ahd_seqintstat_print(ahd_inb(ahd
, SEQINTSTAT
), &cur_col
, 50);
8875 ahd_saved_mode_print(ahd_inb(ahd
, SAVED_MODE
), &cur_col
, 50);
8876 ahd_dffstat_print(ahd_inb(ahd
, DFFSTAT
), &cur_col
, 50);
8877 ahd_scsisigi_print(ahd_inb(ahd
, SCSISIGI
), &cur_col
, 50);
8878 ahd_scsiphase_print(ahd_inb(ahd
, SCSIPHASE
), &cur_col
, 50);
8879 ahd_scsibus_print(ahd_inb(ahd
, SCSIBUS
), &cur_col
, 50);
8880 ahd_lastphase_print(ahd_inb(ahd
, LASTPHASE
), &cur_col
, 50);
8881 ahd_scsiseq0_print(ahd_inb(ahd
, SCSISEQ0
), &cur_col
, 50);
8882 ahd_scsiseq1_print(ahd_inb(ahd
, SCSISEQ1
), &cur_col
, 50);
8883 ahd_seqctl0_print(ahd_inb(ahd
, SEQCTL0
), &cur_col
, 50);
8884 ahd_seqintctl_print(ahd_inb(ahd
, SEQINTCTL
), &cur_col
, 50);
8885 ahd_seq_flags_print(ahd_inb(ahd
, SEQ_FLAGS
), &cur_col
, 50);
8886 ahd_seq_flags2_print(ahd_inb(ahd
, SEQ_FLAGS2
), &cur_col
, 50);
8887 ahd_qfreeze_count_print(ahd_inw(ahd
, QFREEZE_COUNT
), &cur_col
, 50);
8888 ahd_kernel_qfreeze_count_print(ahd_inw(ahd
, KERNEL_QFREEZE_COUNT
),
8890 ahd_mk_message_scb_print(ahd_inw(ahd
, MK_MESSAGE_SCB
), &cur_col
, 50);
8891 ahd_mk_message_scsiid_print(ahd_inb(ahd
, MK_MESSAGE_SCSIID
),
8893 ahd_sstat0_print(ahd_inb(ahd
, SSTAT0
), &cur_col
, 50);
8894 ahd_sstat1_print(ahd_inb(ahd
, SSTAT1
), &cur_col
, 50);
8895 ahd_sstat2_print(ahd_inb(ahd
, SSTAT2
), &cur_col
, 50);
8896 ahd_sstat3_print(ahd_inb(ahd
, SSTAT3
), &cur_col
, 50);
8897 ahd_perrdiag_print(ahd_inb(ahd
, PERRDIAG
), &cur_col
, 50);
8898 ahd_simode1_print(ahd_inb(ahd
, SIMODE1
), &cur_col
, 50);
8899 ahd_lqistat0_print(ahd_inb(ahd
, LQISTAT0
), &cur_col
, 50);
8900 ahd_lqistat1_print(ahd_inb(ahd
, LQISTAT1
), &cur_col
, 50);
8901 ahd_lqistat2_print(ahd_inb(ahd
, LQISTAT2
), &cur_col
, 50);
8902 ahd_lqostat0_print(ahd_inb(ahd
, LQOSTAT0
), &cur_col
, 50);
8903 ahd_lqostat1_print(ahd_inb(ahd
, LQOSTAT1
), &cur_col
, 50);
8904 ahd_lqostat2_print(ahd_inb(ahd
, LQOSTAT2
), &cur_col
, 50);
8906 printf("\nSCB Count = %d CMDS_PENDING = %d LASTSCB 0x%x "
8907 "CURRSCB 0x%x NEXTSCB 0x%x\n",
8908 ahd
->scb_data
.numscbs
, ahd_inw(ahd
, CMDS_PENDING
),
8909 ahd_inw(ahd
, LASTSCB
), ahd_inw(ahd
, CURRSCB
),
8910 ahd_inw(ahd
, NEXTSCB
));
8913 ahd_search_qinfifo(ahd
, CAM_TARGET_WILDCARD
, ALL_CHANNELS
,
8914 CAM_LUN_WILDCARD
, SCB_LIST_NULL
,
8915 ROLE_UNKNOWN
, /*status*/0, SEARCH_PRINT
);
8916 saved_scb_index
= ahd_get_scbptr(ahd
);
8917 printf("Pending list:");
8919 LIST_FOREACH(scb
, &ahd
->pending_scbs
, pending_links
) {
8920 if (i
++ > AHD_SCB_MAX
)
8922 cur_col
= printf("\n%3d FIFO_USE[0x%x] ", SCB_GET_TAG(scb
),
8923 ahd_inb_scbram(ahd
, SCB_FIFO_USE_COUNT
));
8924 ahd_set_scbptr(ahd
, SCB_GET_TAG(scb
));
8925 ahd_scb_control_print(ahd_inb_scbram(ahd
, SCB_CONTROL
),
8927 ahd_scb_scsiid_print(ahd_inb_scbram(ahd
, SCB_SCSIID
),
8930 printf("\nTotal %d\n", i
);
8932 printf("Kernel Free SCB list: ");
8934 TAILQ_FOREACH(scb
, &ahd
->scb_data
.free_scbs
, links
.tqe
) {
8935 struct scb
*list_scb
;
8939 printf("%d ", SCB_GET_TAG(list_scb
));
8940 list_scb
= LIST_NEXT(list_scb
, collision_links
);
8941 } while (list_scb
&& i
++ < AHD_SCB_MAX
);
8944 LIST_FOREACH(scb
, &ahd
->scb_data
.any_dev_free_scb_list
, links
.le
) {
8945 if (i
++ > AHD_SCB_MAX
)
8947 printf("%d ", SCB_GET_TAG(scb
));
8951 printf("Sequencer Complete DMA-inprog list: ");
8952 scb_index
= ahd_inw(ahd
, COMPLETE_SCB_DMAINPROG_HEAD
);
8954 while (!SCBID_IS_NULL(scb_index
) && i
++ < AHD_SCB_MAX
) {
8955 ahd_set_scbptr(ahd
, scb_index
);
8956 printf("%d ", scb_index
);
8957 scb_index
= ahd_inw_scbram(ahd
, SCB_NEXT_COMPLETE
);
8961 printf("Sequencer Complete list: ");
8962 scb_index
= ahd_inw(ahd
, COMPLETE_SCB_HEAD
);
8964 while (!SCBID_IS_NULL(scb_index
) && i
++ < AHD_SCB_MAX
) {
8965 ahd_set_scbptr(ahd
, scb_index
);
8966 printf("%d ", scb_index
);
8967 scb_index
= ahd_inw_scbram(ahd
, SCB_NEXT_COMPLETE
);
8972 printf("Sequencer DMA-Up and Complete list: ");
8973 scb_index
= ahd_inw(ahd
, COMPLETE_DMA_SCB_HEAD
);
8975 while (!SCBID_IS_NULL(scb_index
) && i
++ < AHD_SCB_MAX
) {
8976 ahd_set_scbptr(ahd
, scb_index
);
8977 printf("%d ", scb_index
);
8978 scb_index
= ahd_inw_scbram(ahd
, SCB_NEXT_COMPLETE
);
8981 printf("Sequencer On QFreeze and Complete list: ");
8982 scb_index
= ahd_inw(ahd
, COMPLETE_ON_QFREEZE_HEAD
);
8984 while (!SCBID_IS_NULL(scb_index
) && i
++ < AHD_SCB_MAX
) {
8985 ahd_set_scbptr(ahd
, scb_index
);
8986 printf("%d ", scb_index
);
8987 scb_index
= ahd_inw_scbram(ahd
, SCB_NEXT_COMPLETE
);
8990 ahd_set_scbptr(ahd
, saved_scb_index
);
8991 dffstat
= ahd_inb(ahd
, DFFSTAT
);
8992 for (i
= 0; i
< 2; i
++) {
8994 struct scb
*fifo_scb
;
8998 ahd_set_modes(ahd
, AHD_MODE_DFF0
+ i
, AHD_MODE_DFF0
+ i
);
8999 fifo_scbptr
= ahd_get_scbptr(ahd
);
9000 printf("\n\n%s: FIFO%d %s, LONGJMP == 0x%x, SCB 0x%x\n",
9002 (dffstat
& (FIFO0FREE
<< i
)) ? "Free" : "Active",
9003 ahd_inw(ahd
, LONGJMP_ADDR
), fifo_scbptr
);
9005 ahd_seqimode_print(ahd_inb(ahd
, SEQIMODE
), &cur_col
, 50);
9006 ahd_seqintsrc_print(ahd_inb(ahd
, SEQINTSRC
), &cur_col
, 50);
9007 ahd_dfcntrl_print(ahd_inb(ahd
, DFCNTRL
), &cur_col
, 50);
9008 ahd_dfstatus_print(ahd_inb(ahd
, DFSTATUS
), &cur_col
, 50);
9009 ahd_sg_cache_shadow_print(ahd_inb(ahd
, SG_CACHE_SHADOW
),
9011 ahd_sg_state_print(ahd_inb(ahd
, SG_STATE
), &cur_col
, 50);
9012 ahd_dffsxfrctl_print(ahd_inb(ahd
, DFFSXFRCTL
), &cur_col
, 50);
9013 ahd_soffcnt_print(ahd_inb(ahd
, SOFFCNT
), &cur_col
, 50);
9014 ahd_mdffstat_print(ahd_inb(ahd
, MDFFSTAT
), &cur_col
, 50);
9019 cur_col
+= printf("SHADDR = 0x%x%x, SHCNT = 0x%x ",
9020 ahd_inl(ahd
, SHADDR
+4),
9021 ahd_inl(ahd
, SHADDR
),
9022 (ahd_inb(ahd
, SHCNT
)
9023 | (ahd_inb(ahd
, SHCNT
+ 1) << 8)
9024 | (ahd_inb(ahd
, SHCNT
+ 2) << 16)));
9029 cur_col
+= printf("HADDR = 0x%x%x, HCNT = 0x%x ",
9030 ahd_inl(ahd
, HADDR
+4),
9031 ahd_inl(ahd
, HADDR
),
9033 | (ahd_inb(ahd
, HCNT
+ 1) << 8)
9034 | (ahd_inb(ahd
, HCNT
+ 2) << 16)));
9035 ahd_ccsgctl_print(ahd_inb(ahd
, CCSGCTL
), &cur_col
, 50);
9037 if ((ahd_debug
& AHD_SHOW_SG
) != 0) {
9038 fifo_scb
= ahd_lookup_scb(ahd
, fifo_scbptr
);
9039 if (fifo_scb
!= NULL
)
9040 ahd_dump_sglist(fifo_scb
);
9045 for (i
= 0; i
< 20; i
++)
9046 printf("0x%x ", ahd_inb(ahd
, LQIN
+ i
));
9048 ahd_set_modes(ahd
, AHD_MODE_CFG
, AHD_MODE_CFG
);
9049 printf("%s: LQISTATE = 0x%x, LQOSTATE = 0x%x, OPTIONMODE = 0x%x\n",
9050 ahd_name(ahd
), ahd_inb(ahd
, LQISTATE
), ahd_inb(ahd
, LQOSTATE
),
9051 ahd_inb(ahd
, OPTIONMODE
));
9052 printf("%s: OS_SPACE_CNT = 0x%x MAXCMDCNT = 0x%x\n",
9053 ahd_name(ahd
), ahd_inb(ahd
, OS_SPACE_CNT
),
9054 ahd_inb(ahd
, MAXCMDCNT
));
9055 printf("%s: SAVED_SCSIID = 0x%x SAVED_LUN = 0x%x\n",
9056 ahd_name(ahd
), ahd_inb(ahd
, SAVED_SCSIID
),
9057 ahd_inb(ahd
, SAVED_LUN
));
9058 ahd_simode0_print(ahd_inb(ahd
, SIMODE0
), &cur_col
, 50);
9060 ahd_set_modes(ahd
, AHD_MODE_CCHAN
, AHD_MODE_CCHAN
);
9062 ahd_ccscbctl_print(ahd_inb(ahd
, CCSCBCTL
), &cur_col
, 50);
9064 ahd_set_modes(ahd
, ahd
->saved_src_mode
, ahd
->saved_dst_mode
);
9065 printf("%s: REG0 == 0x%x, SINDEX = 0x%x, DINDEX = 0x%x\n",
9066 ahd_name(ahd
), ahd_inw(ahd
, REG0
), ahd_inw(ahd
, SINDEX
),
9067 ahd_inw(ahd
, DINDEX
));
9068 printf("%s: SCBPTR == 0x%x, SCB_NEXT == 0x%x, SCB_NEXT2 == 0x%x\n",
9069 ahd_name(ahd
), ahd_get_scbptr(ahd
),
9070 ahd_inw_scbram(ahd
, SCB_NEXT
),
9071 ahd_inw_scbram(ahd
, SCB_NEXT2
));
9072 printf("CDB %x %x %x %x %x %x\n",
9073 ahd_inb_scbram(ahd
, SCB_CDB_STORE
),
9074 ahd_inb_scbram(ahd
, SCB_CDB_STORE
+1),
9075 ahd_inb_scbram(ahd
, SCB_CDB_STORE
+2),
9076 ahd_inb_scbram(ahd
, SCB_CDB_STORE
+3),
9077 ahd_inb_scbram(ahd
, SCB_CDB_STORE
+4),
9078 ahd_inb_scbram(ahd
, SCB_CDB_STORE
+5));
9080 for (i
= 0; i
< ahd
->stack_size
; i
++) {
9081 ahd
->saved_stack
[i
] =
9082 ahd_inb(ahd
, STACK
)|(ahd_inb(ahd
, STACK
) << 8);
9083 printf(" 0x%x", ahd
->saved_stack
[i
]);
9085 for (i
= ahd
->stack_size
-1; i
>= 0; i
--) {
9086 ahd_outb(ahd
, STACK
, ahd
->saved_stack
[i
] & 0xFF);
9087 ahd_outb(ahd
, STACK
, (ahd
->saved_stack
[i
] >> 8) & 0xFF);
9089 printf("\n<<<<<<<<<<<<<<<<< Dump Card State Ends >>>>>>>>>>>>>>>>>>\n");
9090 ahd_restore_modes(ahd
, saved_modes
);
9096 ahd_dump_scbs(struct ahd_softc
*ahd
)
9098 ahd_mode_state saved_modes
;
9099 u_int saved_scb_index
;
9102 saved_modes
= ahd_save_modes(ahd
);
9103 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
9104 saved_scb_index
= ahd_get_scbptr(ahd
);
9105 for (i
= 0; i
< AHD_SCB_MAX
; i
++) {
9106 ahd_set_scbptr(ahd
, i
);
9108 printf("(CTRL 0x%x ID 0x%x N 0x%x N2 0x%x SG 0x%x, RSG 0x%x)\n",
9109 ahd_inb_scbram(ahd
, SCB_CONTROL
),
9110 ahd_inb_scbram(ahd
, SCB_SCSIID
),
9111 ahd_inw_scbram(ahd
, SCB_NEXT
),
9112 ahd_inw_scbram(ahd
, SCB_NEXT2
),
9113 ahd_inl_scbram(ahd
, SCB_SGPTR
),
9114 ahd_inl_scbram(ahd
, SCB_RESIDUAL_SGPTR
));
9117 ahd_set_scbptr(ahd
, saved_scb_index
);
9118 ahd_restore_modes(ahd
, saved_modes
);
9121 /**************************** Flexport Logic **********************************/
9123 * Read count 16bit words from 16bit word address start_addr from the
9124 * SEEPROM attached to the controller, into buf, using the controller's
9125 * SEEPROM reading state machine. Optionally treat the data as a byte
9126 * stream in terms of byte order.
9129 ahd_read_seeprom(struct ahd_softc
*ahd
, uint16_t *buf
,
9130 u_int start_addr
, u_int count
, int bytestream
)
9137 * If we never make it through the loop even once,
9138 * we were passed invalid arguments.
9141 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
9142 end_addr
= start_addr
+ count
;
9143 for (cur_addr
= start_addr
; cur_addr
< end_addr
; cur_addr
++) {
9145 ahd_outb(ahd
, SEEADR
, cur_addr
);
9146 ahd_outb(ahd
, SEECTL
, SEEOP_READ
| SEESTART
);
9148 error
= ahd_wait_seeprom(ahd
);
9151 if (bytestream
!= 0) {
9152 uint8_t *bytestream_ptr
;
9154 bytestream_ptr
= (uint8_t *)buf
;
9155 *bytestream_ptr
++ = ahd_inb(ahd
, SEEDAT
);
9156 *bytestream_ptr
= ahd_inb(ahd
, SEEDAT
+1);
9159 * ahd_inw() already handles machine byte order.
9161 *buf
= ahd_inw(ahd
, SEEDAT
);
9169 * Write count 16bit words from buf, into SEEPROM attache to the
9170 * controller starting at 16bit word address start_addr, using the
9171 * controller's SEEPROM writing state machine.
9174 ahd_write_seeprom(struct ahd_softc
*ahd
, uint16_t *buf
,
9175 u_int start_addr
, u_int count
)
9182 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
9185 /* Place the chip into write-enable mode */
9186 ahd_outb(ahd
, SEEADR
, SEEOP_EWEN_ADDR
);
9187 ahd_outb(ahd
, SEECTL
, SEEOP_EWEN
| SEESTART
);
9188 error
= ahd_wait_seeprom(ahd
);
9193 * Write the data. If we don't get throught the loop at
9194 * least once, the arguments were invalid.
9197 end_addr
= start_addr
+ count
;
9198 for (cur_addr
= start_addr
; cur_addr
< end_addr
; cur_addr
++) {
9199 ahd_outw(ahd
, SEEDAT
, *buf
++);
9200 ahd_outb(ahd
, SEEADR
, cur_addr
);
9201 ahd_outb(ahd
, SEECTL
, SEEOP_WRITE
| SEESTART
);
9203 retval
= ahd_wait_seeprom(ahd
);
9211 ahd_outb(ahd
, SEEADR
, SEEOP_EWDS_ADDR
);
9212 ahd_outb(ahd
, SEECTL
, SEEOP_EWDS
| SEESTART
);
9213 error
= ahd_wait_seeprom(ahd
);
9220 * Wait ~100us for the serial eeprom to satisfy our request.
9223 ahd_wait_seeprom(struct ahd_softc
*ahd
)
9228 while ((ahd_inb(ahd
, SEESTAT
) & (SEEARBACK
|SEEBUSY
)) != 0 && --cnt
)
9237 * Validate the two checksums in the per_channel
9238 * vital product data struct.
9241 ahd_verify_vpd_cksum(struct vpd_config
*vpd
)
9248 vpdarray
= (uint8_t *)vpd
;
9249 maxaddr
= offsetof(struct vpd_config
, vpd_checksum
);
9251 for (i
= offsetof(struct vpd_config
, resource_type
); i
< maxaddr
; i
++)
9252 checksum
= checksum
+ vpdarray
[i
];
9254 || (-checksum
& 0xFF) != vpd
->vpd_checksum
)
9258 maxaddr
= offsetof(struct vpd_config
, checksum
);
9259 for (i
= offsetof(struct vpd_config
, default_target_flags
);
9261 checksum
= checksum
+ vpdarray
[i
];
9263 || (-checksum
& 0xFF) != vpd
->checksum
)
9269 ahd_verify_cksum(struct seeprom_config
*sc
)
9276 maxaddr
= (sizeof(*sc
)/2) - 1;
9278 scarray
= (uint16_t *)sc
;
9280 for (i
= 0; i
< maxaddr
; i
++)
9281 checksum
= checksum
+ scarray
[i
];
9283 || (checksum
& 0xFFFF) != sc
->checksum
) {
9291 ahd_acquire_seeprom(struct ahd_softc
*ahd
)
9294 * We should be able to determine the SEEPROM type
9295 * from the flexport logic, but unfortunately not
9296 * all implementations have this logic and there is
9297 * no programatic method for determining if the logic
9305 error
= ahd_read_flexport(ahd
, FLXADDR_ROMSTAT_CURSENSECTL
, &seetype
);
9307 || ((seetype
& FLX_ROMSTAT_SEECFG
) == FLX_ROMSTAT_SEE_NONE
))
9314 ahd_release_seeprom(struct ahd_softc
*ahd
)
9316 /* Currently a no-op */
9320 ahd_write_flexport(struct ahd_softc
*ahd
, u_int addr
, u_int value
)
9324 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
9326 panic("ahd_write_flexport: address out of range");
9327 ahd_outb(ahd
, BRDCTL
, BRDEN
|(addr
<< 3));
9328 error
= ahd_wait_flexport(ahd
);
9331 ahd_outb(ahd
, BRDDAT
, value
);
9332 ahd_flush_device_writes(ahd
);
9333 ahd_outb(ahd
, BRDCTL
, BRDSTB
|BRDEN
|(addr
<< 3));
9334 ahd_flush_device_writes(ahd
);
9335 ahd_outb(ahd
, BRDCTL
, BRDEN
|(addr
<< 3));
9336 ahd_flush_device_writes(ahd
);
9337 ahd_outb(ahd
, BRDCTL
, 0);
9338 ahd_flush_device_writes(ahd
);
9343 ahd_read_flexport(struct ahd_softc
*ahd
, u_int addr
, uint8_t *value
)
9347 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
9349 panic("ahd_read_flexport: address out of range");
9350 ahd_outb(ahd
, BRDCTL
, BRDRW
|BRDEN
|(addr
<< 3));
9351 error
= ahd_wait_flexport(ahd
);
9354 *value
= ahd_inb(ahd
, BRDDAT
);
9355 ahd_outb(ahd
, BRDCTL
, 0);
9356 ahd_flush_device_writes(ahd
);
9361 * Wait at most 2 seconds for flexport arbitration to succeed.
9364 ahd_wait_flexport(struct ahd_softc
*ahd
)
9368 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
9369 cnt
= 1000000 * 2 / 5;
9370 while ((ahd_inb(ahd
, BRDCTL
) & FLXARBACK
) == 0 && --cnt
)
9378 /************************* Target Mode ****************************************/
9379 #ifdef AHD_TARGET_MODE
9381 ahd_find_tmode_devs(struct ahd_softc
*ahd
, struct cam_sim
*sim
, union ccb
*ccb
,
9382 struct ahd_tmode_tstate
**tstate
,
9383 struct ahd_tmode_lstate
**lstate
,
9384 int notfound_failure
)
9387 if ((ahd
->features
& AHD_TARGETMODE
) == 0)
9388 return (CAM_REQ_INVALID
);
9391 * Handle the 'black hole' device that sucks up
9392 * requests to unattached luns on enabled targets.
9394 if (ccb
->ccb_h
.target_id
== CAM_TARGET_WILDCARD
9395 && ccb
->ccb_h
.target_lun
== CAM_LUN_WILDCARD
) {
9397 *lstate
= ahd
->black_hole
;
9401 max_id
= (ahd
->features
& AHD_WIDE
) ? 16 : 8;
9402 if (ccb
->ccb_h
.target_id
>= max_id
)
9403 return (CAM_TID_INVALID
);
9405 if (ccb
->ccb_h
.target_lun
>= AHD_NUM_LUNS
)
9406 return (CAM_LUN_INVALID
);
9408 *tstate
= ahd
->enabled_targets
[ccb
->ccb_h
.target_id
];
9410 if (*tstate
!= NULL
)
9412 (*tstate
)->enabled_luns
[ccb
->ccb_h
.target_lun
];
9415 if (notfound_failure
!= 0 && *lstate
== NULL
)
9416 return (CAM_PATH_INVALID
);
9418 return (CAM_REQ_CMP
);
9422 ahd_handle_en_lun(struct ahd_softc
*ahd
, struct cam_sim
*sim
, union ccb
*ccb
)
9425 struct ahd_tmode_tstate
*tstate
;
9426 struct ahd_tmode_lstate
*lstate
;
9427 struct ccb_en_lun
*cel
;
9435 status
= ahd_find_tmode_devs(ahd
, sim
, ccb
, &tstate
, &lstate
,
9436 /*notfound_failure*/FALSE
);
9438 if (status
!= CAM_REQ_CMP
) {
9439 ccb
->ccb_h
.status
= status
;
9443 if ((ahd
->features
& AHD_MULTIROLE
) != 0) {
9446 our_id
= ahd
->our_id
;
9447 if (ccb
->ccb_h
.target_id
!= our_id
) {
9448 if ((ahd
->features
& AHD_MULTI_TID
) != 0
9449 && (ahd
->flags
& AHD_INITIATORROLE
) != 0) {
9451 * Only allow additional targets if
9452 * the initiator role is disabled.
9453 * The hardware cannot handle a re-select-in
9454 * on the initiator id during a re-select-out
9455 * on a different target id.
9457 status
= CAM_TID_INVALID
;
9458 } else if ((ahd
->flags
& AHD_INITIATORROLE
) != 0
9459 || ahd
->enabled_luns
> 0) {
9461 * Only allow our target id to change
9462 * if the initiator role is not configured
9463 * and there are no enabled luns which
9464 * are attached to the currently registered
9467 status
= CAM_TID_INVALID
;
9472 if (status
!= CAM_REQ_CMP
) {
9473 ccb
->ccb_h
.status
= status
;
9478 * We now have an id that is valid.
9479 * If we aren't in target mode, switch modes.
9481 if ((ahd
->flags
& AHD_TARGETROLE
) == 0
9482 && ccb
->ccb_h
.target_id
!= CAM_TARGET_WILDCARD
) {
9485 printf("Configuring Target Mode\n");
9487 if (LIST_FIRST(&ahd
->pending_scbs
) != NULL
) {
9488 ccb
->ccb_h
.status
= CAM_BUSY
;
9489 ahd_unlock(ahd
, &s
);
9492 ahd
->flags
|= AHD_TARGETROLE
;
9493 if ((ahd
->features
& AHD_MULTIROLE
) == 0)
9494 ahd
->flags
&= ~AHD_INITIATORROLE
;
9498 ahd_unlock(ahd
, &s
);
9501 target
= ccb
->ccb_h
.target_id
;
9502 lun
= ccb
->ccb_h
.target_lun
;
9503 channel
= SIM_CHANNEL(ahd
, sim
);
9504 target_mask
= 0x01 << target
;
9508 if (cel
->enable
!= 0) {
9511 /* Are we already enabled?? */
9512 if (lstate
!= NULL
) {
9513 xpt_print_path(ccb
->ccb_h
.path
);
9514 printf("Lun already enabled\n");
9515 ccb
->ccb_h
.status
= CAM_LUN_ALRDY_ENA
;
9519 if (cel
->grp6_len
!= 0
9520 || cel
->grp7_len
!= 0) {
9522 * Don't (yet?) support vendor
9523 * specific commands.
9525 ccb
->ccb_h
.status
= CAM_REQ_INVALID
;
9526 printf("Non-zero Group Codes\n");
9532 * Setup our data structures.
9534 if (target
!= CAM_TARGET_WILDCARD
&& tstate
== NULL
) {
9535 tstate
= ahd_alloc_tstate(ahd
, target
, channel
);
9536 if (tstate
== NULL
) {
9537 xpt_print_path(ccb
->ccb_h
.path
);
9538 printf("Couldn't allocate tstate\n");
9539 ccb
->ccb_h
.status
= CAM_RESRC_UNAVAIL
;
9543 lstate
= malloc(sizeof(*lstate
), M_DEVBUF
, M_NOWAIT
);
9544 if (lstate
== NULL
) {
9545 xpt_print_path(ccb
->ccb_h
.path
);
9546 printf("Couldn't allocate lstate\n");
9547 ccb
->ccb_h
.status
= CAM_RESRC_UNAVAIL
;
9550 memset(lstate
, 0, sizeof(*lstate
));
9551 status
= xpt_create_path(&lstate
->path
, /*periph*/NULL
,
9552 xpt_path_path_id(ccb
->ccb_h
.path
),
9553 xpt_path_target_id(ccb
->ccb_h
.path
),
9554 xpt_path_lun_id(ccb
->ccb_h
.path
));
9555 if (status
!= CAM_REQ_CMP
) {
9556 free(lstate
, M_DEVBUF
);
9557 xpt_print_path(ccb
->ccb_h
.path
);
9558 printf("Couldn't allocate path\n");
9559 ccb
->ccb_h
.status
= CAM_RESRC_UNAVAIL
;
9562 SLIST_INIT(&lstate
->accept_tios
);
9563 SLIST_INIT(&lstate
->immed_notifies
);
9566 if (target
!= CAM_TARGET_WILDCARD
) {
9567 tstate
->enabled_luns
[lun
] = lstate
;
9568 ahd
->enabled_luns
++;
9570 if ((ahd
->features
& AHD_MULTI_TID
) != 0) {
9573 targid_mask
= ahd_inw(ahd
, TARGID
);
9574 targid_mask
|= target_mask
;
9575 ahd_outw(ahd
, TARGID
, targid_mask
);
9576 ahd_update_scsiid(ahd
, targid_mask
);
9581 channel
= SIM_CHANNEL(ahd
, sim
);
9582 our_id
= SIM_SCSI_ID(ahd
, sim
);
9585 * This can only happen if selections
9588 if (target
!= our_id
) {
9593 sblkctl
= ahd_inb(ahd
, SBLKCTL
);
9594 cur_channel
= (sblkctl
& SELBUSB
)
9596 if ((ahd
->features
& AHD_TWIN
) == 0)
9598 swap
= cur_channel
!= channel
;
9599 ahd
->our_id
= target
;
9602 ahd_outb(ahd
, SBLKCTL
,
9605 ahd_outb(ahd
, SCSIID
, target
);
9608 ahd_outb(ahd
, SBLKCTL
, sblkctl
);
9612 ahd
->black_hole
= lstate
;
9613 /* Allow select-in operations */
9614 if (ahd
->black_hole
!= NULL
&& ahd
->enabled_luns
> 0) {
9615 scsiseq1
= ahd_inb(ahd
, SCSISEQ_TEMPLATE
);
9617 ahd_outb(ahd
, SCSISEQ_TEMPLATE
, scsiseq1
);
9618 scsiseq1
= ahd_inb(ahd
, SCSISEQ1
);
9620 ahd_outb(ahd
, SCSISEQ1
, scsiseq1
);
9623 ahd_unlock(ahd
, &s
);
9624 ccb
->ccb_h
.status
= CAM_REQ_CMP
;
9625 xpt_print_path(ccb
->ccb_h
.path
);
9626 printf("Lun now enabled for target mode\n");
9631 if (lstate
== NULL
) {
9632 ccb
->ccb_h
.status
= CAM_LUN_INVALID
;
9638 ccb
->ccb_h
.status
= CAM_REQ_CMP
;
9639 LIST_FOREACH(scb
, &ahd
->pending_scbs
, pending_links
) {
9640 struct ccb_hdr
*ccbh
;
9642 ccbh
= &scb
->io_ctx
->ccb_h
;
9643 if (ccbh
->func_code
== XPT_CONT_TARGET_IO
9644 && !xpt_path_comp(ccbh
->path
, ccb
->ccb_h
.path
)){
9645 printf("CTIO pending\n");
9646 ccb
->ccb_h
.status
= CAM_REQ_INVALID
;
9647 ahd_unlock(ahd
, &s
);
9652 if (SLIST_FIRST(&lstate
->accept_tios
) != NULL
) {
9653 printf("ATIOs pending\n");
9654 ccb
->ccb_h
.status
= CAM_REQ_INVALID
;
9657 if (SLIST_FIRST(&lstate
->immed_notifies
) != NULL
) {
9658 printf("INOTs pending\n");
9659 ccb
->ccb_h
.status
= CAM_REQ_INVALID
;
9662 if (ccb
->ccb_h
.status
!= CAM_REQ_CMP
) {
9663 ahd_unlock(ahd
, &s
);
9667 xpt_print_path(ccb
->ccb_h
.path
);
9668 printf("Target mode disabled\n");
9669 xpt_free_path(lstate
->path
);
9670 free(lstate
, M_DEVBUF
);
9673 /* Can we clean up the target too? */
9674 if (target
!= CAM_TARGET_WILDCARD
) {
9675 tstate
->enabled_luns
[lun
] = NULL
;
9676 ahd
->enabled_luns
--;
9677 for (empty
= 1, i
= 0; i
< 8; i
++)
9678 if (tstate
->enabled_luns
[i
] != NULL
) {
9684 ahd_free_tstate(ahd
, target
, channel
,
9686 if (ahd
->features
& AHD_MULTI_TID
) {
9689 targid_mask
= ahd_inw(ahd
, TARGID
);
9690 targid_mask
&= ~target_mask
;
9691 ahd_outw(ahd
, TARGID
, targid_mask
);
9692 ahd_update_scsiid(ahd
, targid_mask
);
9697 ahd
->black_hole
= NULL
;
9700 * We can't allow selections without
9701 * our black hole device.
9705 if (ahd
->enabled_luns
== 0) {
9706 /* Disallow select-in */
9709 scsiseq1
= ahd_inb(ahd
, SCSISEQ_TEMPLATE
);
9710 scsiseq1
&= ~ENSELI
;
9711 ahd_outb(ahd
, SCSISEQ_TEMPLATE
, scsiseq1
);
9712 scsiseq1
= ahd_inb(ahd
, SCSISEQ1
);
9713 scsiseq1
&= ~ENSELI
;
9714 ahd_outb(ahd
, SCSISEQ1
, scsiseq1
);
9716 if ((ahd
->features
& AHD_MULTIROLE
) == 0) {
9717 printf("Configuring Initiator Mode\n");
9718 ahd
->flags
&= ~AHD_TARGETROLE
;
9719 ahd
->flags
|= AHD_INITIATORROLE
;
9724 * Unpaused. The extra unpause
9725 * that follows is harmless.
9730 ahd_unlock(ahd
, &s
);
9736 ahd_update_scsiid(struct ahd_softc
*ahd
, u_int targid_mask
)
9742 if ((ahd
->features
& AHD_MULTI_TID
) == 0)
9743 panic("ahd_update_scsiid called on non-multitid unit\n");
9746 * Since we will rely on the TARGID mask
9747 * for selection enables, ensure that OID
9748 * in SCSIID is not set to some other ID
9749 * that we don't want to allow selections on.
9751 if ((ahd
->features
& AHD_ULTRA2
) != 0)
9752 scsiid
= ahd_inb(ahd
, SCSIID_ULTRA2
);
9754 scsiid
= ahd_inb(ahd
, SCSIID
);
9755 scsiid_mask
= 0x1 << (scsiid
& OID
);
9756 if ((targid_mask
& scsiid_mask
) == 0) {
9759 /* ffs counts from 1 */
9760 our_id
= ffs(targid_mask
);
9762 our_id
= ahd
->our_id
;
9768 if ((ahd
->features
& AHD_ULTRA2
) != 0)
9769 ahd_outb(ahd
, SCSIID_ULTRA2
, scsiid
);
9771 ahd_outb(ahd
, SCSIID
, scsiid
);
9776 ahd_run_tqinfifo(struct ahd_softc
*ahd
, int paused
)
9778 struct target_cmd
*cmd
;
9780 ahd_sync_tqinfifo(ahd
, BUS_DMASYNC_POSTREAD
);
9781 while ((cmd
= &ahd
->targetcmds
[ahd
->tqinfifonext
])->cmd_valid
!= 0) {
9784 * Only advance through the queue if we
9785 * have the resources to process the command.
9787 if (ahd_handle_target_cmd(ahd
, cmd
) != 0)
9791 ahd_dmamap_sync(ahd
, ahd
->shared_data_dmat
,
9792 ahd
->shared_data_map
.dmamap
,
9793 ahd_targetcmd_offset(ahd
, ahd
->tqinfifonext
),
9794 sizeof(struct target_cmd
),
9795 BUS_DMASYNC_PREREAD
);
9796 ahd
->tqinfifonext
++;
9799 * Lazily update our position in the target mode incoming
9800 * command queue as seen by the sequencer.
9802 if ((ahd
->tqinfifonext
& (HOST_TQINPOS
- 1)) == 1) {
9805 hs_mailbox
= ahd_inb(ahd
, HS_MAILBOX
);
9806 hs_mailbox
&= ~HOST_TQINPOS
;
9807 hs_mailbox
|= ahd
->tqinfifonext
& HOST_TQINPOS
;
9808 ahd_outb(ahd
, HS_MAILBOX
, hs_mailbox
);
9814 ahd_handle_target_cmd(struct ahd_softc
*ahd
, struct target_cmd
*cmd
)
9816 struct ahd_tmode_tstate
*tstate
;
9817 struct ahd_tmode_lstate
*lstate
;
9818 struct ccb_accept_tio
*atio
;
9824 initiator
= SCSIID_TARGET(ahd
, cmd
->scsiid
);
9825 target
= SCSIID_OUR_ID(cmd
->scsiid
);
9826 lun
= (cmd
->identify
& MSG_IDENTIFY_LUNMASK
);
9829 tstate
= ahd
->enabled_targets
[target
];
9832 lstate
= tstate
->enabled_luns
[lun
];
9835 * Commands for disabled luns go to the black hole driver.
9838 lstate
= ahd
->black_hole
;
9840 atio
= (struct ccb_accept_tio
*)SLIST_FIRST(&lstate
->accept_tios
);
9842 ahd
->flags
|= AHD_TQINFIFO_BLOCKED
;
9844 * Wait for more ATIOs from the peripheral driver for this lun.
9848 ahd
->flags
&= ~AHD_TQINFIFO_BLOCKED
;
9850 if ((ahd_debug
& AHD_SHOW_TQIN
) != 0)
9851 printf("Incoming command from %d for %d:%d%s\n",
9852 initiator
, target
, lun
,
9853 lstate
== ahd
->black_hole
? "(Black Holed)" : "");
9855 SLIST_REMOVE_HEAD(&lstate
->accept_tios
, sim_links
.sle
);
9857 if (lstate
== ahd
->black_hole
) {
9858 /* Fill in the wildcards */
9859 atio
->ccb_h
.target_id
= target
;
9860 atio
->ccb_h
.target_lun
= lun
;
9864 * Package it up and send it off to
9865 * whomever has this lun enabled.
9867 atio
->sense_len
= 0;
9868 atio
->init_id
= initiator
;
9869 if (byte
[0] != 0xFF) {
9870 /* Tag was included */
9871 atio
->tag_action
= *byte
++;
9872 atio
->tag_id
= *byte
++;
9873 atio
->ccb_h
.flags
= CAM_TAG_ACTION_VALID
;
9875 atio
->ccb_h
.flags
= 0;
9879 /* Okay. Now determine the cdb size based on the command code */
9880 switch (*byte
>> CMD_GROUP_CODE_SHIFT
) {
9896 /* Only copy the opcode. */
9898 printf("Reserved or VU command code type encountered\n");
9902 memcpy(atio
->cdb_io
.cdb_bytes
, byte
, atio
->cdb_len
);
9904 atio
->ccb_h
.status
|= CAM_CDB_RECVD
;
9906 if ((cmd
->identify
& MSG_IDENTIFY_DISCFLAG
) == 0) {
9908 * We weren't allowed to disconnect.
9909 * We're hanging on the bus until a
9910 * continue target I/O comes in response
9911 * to this accept tio.
9914 if ((ahd_debug
& AHD_SHOW_TQIN
) != 0)
9915 printf("Received Immediate Command %d:%d:%d - %p\n",
9916 initiator
, target
, lun
, ahd
->pending_device
);
9918 ahd
->pending_device
= lstate
;
9919 ahd_freeze_ccb((union ccb
*)atio
);
9920 atio
->ccb_h
.flags
|= CAM_DIS_DISCONNECT
;
9922 xpt_done((union ccb
*)atio
);