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#202 $
46 #include "aic79xx_osm.h"
47 #include "aic79xx_inline.h"
48 #include "aicasm/aicasm_insformat.h"
50 #include <dev/aic7xxx/aic79xx_osm.h>
51 #include <dev/aic7xxx/aic79xx_inline.h>
52 #include <dev/aic7xxx/aicasm/aicasm_insformat.h>
55 /******************************** Globals *************************************/
56 struct ahd_softc_tailq ahd_tailq
= TAILQ_HEAD_INITIALIZER(ahd_tailq
);
58 /***************************** Lookup Tables **********************************/
59 char *ahd_chip_names
[] =
66 static const u_int num_chip_names
= NUM_ELEMENTS(ahd_chip_names
);
69 * Hardware error codes.
71 struct ahd_hard_error_entry
{
76 static struct ahd_hard_error_entry ahd_hard_errors
[] = {
77 { DSCTMOUT
, "Discard Timer has timed out" },
78 { ILLOPCODE
, "Illegal Opcode in sequencer program" },
79 { SQPARERR
, "Sequencer Parity Error" },
80 { DPARERR
, "Data-path Parity Error" },
81 { MPARERR
, "Scratch or SCB Memory Parity Error" },
82 { CIOPARERR
, "CIOBUS Parity Error" },
84 static const u_int num_errors
= NUM_ELEMENTS(ahd_hard_errors
);
86 static struct ahd_phase_table_entry ahd_phase_table
[] =
88 { P_DATAOUT
, MSG_NOOP
, "in Data-out phase" },
89 { P_DATAIN
, MSG_INITIATOR_DET_ERR
, "in Data-in phase" },
90 { P_DATAOUT_DT
, MSG_NOOP
, "in DT Data-out phase" },
91 { P_DATAIN_DT
, MSG_INITIATOR_DET_ERR
, "in DT Data-in phase" },
92 { P_COMMAND
, MSG_NOOP
, "in Command phase" },
93 { P_MESGOUT
, MSG_NOOP
, "in Message-out phase" },
94 { P_STATUS
, MSG_INITIATOR_DET_ERR
, "in Status phase" },
95 { P_MESGIN
, MSG_PARITY_ERROR
, "in Message-in phase" },
96 { P_BUSFREE
, MSG_NOOP
, "while idle" },
97 { 0, MSG_NOOP
, "in unknown phase" }
101 * In most cases we only wish to itterate over real phases, so
102 * exclude the last element from the count.
104 static const u_int num_phases
= NUM_ELEMENTS(ahd_phase_table
) - 1;
106 /* Our Sequencer Program */
107 #include "aic79xx_seq.h"
109 /**************************** Function Declarations ***************************/
110 static void ahd_handle_transmission_error(struct ahd_softc
*ahd
);
111 static void ahd_handle_lqiphase_error(struct ahd_softc
*ahd
,
113 static int ahd_handle_pkt_busfree(struct ahd_softc
*ahd
,
115 static int ahd_handle_nonpkt_busfree(struct ahd_softc
*ahd
);
116 static void ahd_handle_proto_violation(struct ahd_softc
*ahd
);
117 static void ahd_force_renegotiation(struct ahd_softc
*ahd
,
118 struct ahd_devinfo
*devinfo
);
120 static struct ahd_tmode_tstate
*
121 ahd_alloc_tstate(struct ahd_softc
*ahd
,
122 u_int scsi_id
, char channel
);
123 #ifdef AHD_TARGET_MODE
124 static void ahd_free_tstate(struct ahd_softc
*ahd
,
125 u_int scsi_id
, char channel
, int force
);
127 static void ahd_devlimited_syncrate(struct ahd_softc
*ahd
,
128 struct ahd_initiator_tinfo
*,
132 static void ahd_update_neg_table(struct ahd_softc
*ahd
,
133 struct ahd_devinfo
*devinfo
,
134 struct ahd_transinfo
*tinfo
);
135 static void ahd_update_pending_scbs(struct ahd_softc
*ahd
);
136 static void ahd_fetch_devinfo(struct ahd_softc
*ahd
,
137 struct ahd_devinfo
*devinfo
);
138 static void ahd_scb_devinfo(struct ahd_softc
*ahd
,
139 struct ahd_devinfo
*devinfo
,
141 static void ahd_setup_initiator_msgout(struct ahd_softc
*ahd
,
142 struct ahd_devinfo
*devinfo
,
144 static void ahd_build_transfer_msg(struct ahd_softc
*ahd
,
145 struct ahd_devinfo
*devinfo
);
146 static void ahd_construct_sdtr(struct ahd_softc
*ahd
,
147 struct ahd_devinfo
*devinfo
,
148 u_int period
, u_int offset
);
149 static void ahd_construct_wdtr(struct ahd_softc
*ahd
,
150 struct ahd_devinfo
*devinfo
,
152 static void ahd_construct_ppr(struct ahd_softc
*ahd
,
153 struct ahd_devinfo
*devinfo
,
154 u_int period
, u_int offset
,
155 u_int bus_width
, u_int ppr_options
);
156 static void ahd_clear_msg_state(struct ahd_softc
*ahd
);
157 static void ahd_handle_message_phase(struct ahd_softc
*ahd
);
163 static int ahd_sent_msg(struct ahd_softc
*ahd
, ahd_msgtype type
,
164 u_int msgval
, int full
);
165 static int ahd_parse_msg(struct ahd_softc
*ahd
,
166 struct ahd_devinfo
*devinfo
);
167 static int ahd_handle_msg_reject(struct ahd_softc
*ahd
,
168 struct ahd_devinfo
*devinfo
);
169 static void ahd_handle_ign_wide_residue(struct ahd_softc
*ahd
,
170 struct ahd_devinfo
*devinfo
);
171 static void ahd_reinitialize_dataptrs(struct ahd_softc
*ahd
);
172 static void ahd_handle_devreset(struct ahd_softc
*ahd
,
173 struct ahd_devinfo
*devinfo
,
174 u_int lun
, cam_status status
,
175 char *message
, int verbose_level
);
176 #ifdef AHD_TARGET_MODE
177 static void ahd_setup_target_msgin(struct ahd_softc
*ahd
,
178 struct ahd_devinfo
*devinfo
,
182 static u_int
ahd_sglist_size(struct ahd_softc
*ahd
);
183 static u_int
ahd_sglist_allocsize(struct ahd_softc
*ahd
);
184 static bus_dmamap_callback_t
186 static void ahd_initialize_hscbs(struct ahd_softc
*ahd
);
187 static int ahd_init_scbdata(struct ahd_softc
*ahd
);
188 static void ahd_fini_scbdata(struct ahd_softc
*ahd
);
189 static void ahd_setup_iocell_workaround(struct ahd_softc
*ahd
);
190 static void ahd_iocell_first_selection(struct ahd_softc
*ahd
);
191 static void ahd_add_col_list(struct ahd_softc
*ahd
,
192 struct scb
*scb
, u_int col_idx
);
193 static void ahd_rem_col_list(struct ahd_softc
*ahd
,
195 static void ahd_chip_init(struct ahd_softc
*ahd
);
196 static void ahd_qinfifo_requeue(struct ahd_softc
*ahd
,
197 struct scb
*prev_scb
,
199 static int ahd_qinfifo_count(struct ahd_softc
*ahd
);
200 static int ahd_search_scb_list(struct ahd_softc
*ahd
, int target
,
201 char channel
, int lun
, u_int tag
,
202 role_t role
, uint32_t status
,
203 ahd_search_action action
,
204 u_int
*list_head
, u_int tid
);
205 static void ahd_stitch_tid_list(struct ahd_softc
*ahd
,
206 u_int tid_prev
, u_int tid_cur
,
208 static void ahd_add_scb_to_free_list(struct ahd_softc
*ahd
,
210 static u_int
ahd_rem_wscb(struct ahd_softc
*ahd
, u_int scbid
,
211 u_int prev
, u_int next
, u_int tid
);
212 static void ahd_reset_current_bus(struct ahd_softc
*ahd
);
213 static ahd_callback_t ahd_reset_poll
;
214 static ahd_callback_t ahd_stat_timer
;
216 static void ahd_dumpseq(struct ahd_softc
*ahd
);
218 static void ahd_loadseq(struct ahd_softc
*ahd
);
219 static int ahd_check_patch(struct ahd_softc
*ahd
,
220 struct patch
**start_patch
,
221 u_int start_instr
, u_int
*skip_addr
);
222 static u_int
ahd_resolve_seqaddr(struct ahd_softc
*ahd
,
224 static void ahd_download_instr(struct ahd_softc
*ahd
,
225 u_int instrptr
, uint8_t *dconsts
);
226 static int ahd_probe_stack_size(struct ahd_softc
*ahd
);
227 static int ahd_scb_active_in_fifo(struct ahd_softc
*ahd
,
229 static void ahd_run_data_fifo(struct ahd_softc
*ahd
,
232 #ifdef AHD_TARGET_MODE
233 static void ahd_queue_lstate_event(struct ahd_softc
*ahd
,
234 struct ahd_tmode_lstate
*lstate
,
238 static void ahd_update_scsiid(struct ahd_softc
*ahd
,
240 static int ahd_handle_target_cmd(struct ahd_softc
*ahd
,
241 struct target_cmd
*cmd
);
244 /******************************** Private Inlines *****************************/
245 static __inline
void ahd_assert_atn(struct ahd_softc
*ahd
);
246 static __inline
int ahd_currently_packetized(struct ahd_softc
*ahd
);
247 static __inline
int ahd_set_active_fifo(struct ahd_softc
*ahd
);
250 ahd_assert_atn(struct ahd_softc
*ahd
)
252 ahd_outb(ahd
, SCSISIGO
, ATNO
);
256 * Determine if the current connection has a packetized
257 * agreement. This does not necessarily mean that we
258 * are currently in a packetized transfer. We could
259 * just as easily be sending or receiving a message.
262 ahd_currently_packetized(struct ahd_softc
*ahd
)
264 ahd_mode_state saved_modes
;
267 saved_modes
= ahd_save_modes(ahd
);
268 if ((ahd
->bugs
& AHD_PKTIZED_STATUS_BUG
) != 0) {
270 * The packetized bit refers to the last
271 * connection, not the current one. Check
272 * for non-zero LQISTATE instead.
274 ahd_set_modes(ahd
, AHD_MODE_CFG
, AHD_MODE_CFG
);
275 packetized
= ahd_inb(ahd
, LQISTATE
) != 0;
277 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
278 packetized
= ahd_inb(ahd
, LQISTAT2
) & PACKETIZED
;
280 ahd_restore_modes(ahd
, saved_modes
);
285 ahd_set_active_fifo(struct ahd_softc
*ahd
)
289 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
290 active_fifo
= ahd_inb(ahd
, DFFSTAT
) & CURRFIFO
;
291 switch (active_fifo
) {
294 ahd_set_modes(ahd
, active_fifo
, active_fifo
);
301 /************************* Sequencer Execution Control ************************/
303 * Restart the sequencer program from address zero
306 ahd_restart(struct ahd_softc
*ahd
)
311 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
313 /* No more pending messages */
314 ahd_clear_msg_state(ahd
);
315 ahd_outb(ahd
, SCSISIGO
, 0); /* De-assert BSY */
316 ahd_outb(ahd
, MSG_OUT
, MSG_NOOP
); /* No message to send */
317 ahd_outb(ahd
, SXFRCTL1
, ahd_inb(ahd
, SXFRCTL1
) & ~BITBUCKET
);
318 ahd_outb(ahd
, SEQINTCTL
, 0);
319 ahd_outb(ahd
, LASTPHASE
, P_BUSFREE
);
320 ahd_outb(ahd
, SEQ_FLAGS
, 0);
321 ahd_outb(ahd
, SAVED_SCSIID
, 0xFF);
322 ahd_outb(ahd
, SAVED_LUN
, 0xFF);
325 * Ensure that the sequencer's idea of TQINPOS
326 * matches our own. The sequencer increments TQINPOS
327 * only after it sees a DMA complete and a reset could
328 * occur before the increment leaving the kernel to believe
329 * the command arrived but the sequencer to not.
331 ahd_outb(ahd
, TQINPOS
, ahd
->tqinfifonext
);
333 /* Always allow reselection */
334 ahd_outb(ahd
, SCSISEQ1
,
335 ahd_inb(ahd
, SCSISEQ_TEMPLATE
) & (ENSELI
|ENRSELI
|ENAUTOATNP
));
336 ahd_set_modes(ahd
, AHD_MODE_CCHAN
, AHD_MODE_CCHAN
);
337 ahd_outb(ahd
, SEQCTL0
, FASTMODE
|SEQRESET
);
342 ahd_clear_fifo(struct ahd_softc
*ahd
, u_int fifo
)
344 ahd_mode_state saved_modes
;
347 if ((ahd_debug
& AHD_SHOW_FIFOS
) != 0)
348 printf("%s: Clearing FIFO %d\n", ahd_name(ahd
), fifo
);
350 saved_modes
= ahd_save_modes(ahd
);
351 ahd_set_modes(ahd
, fifo
, fifo
);
352 ahd_outb(ahd
, DFFSXFRCTL
, RSTCHN
|CLRSHCNT
);
353 if ((ahd_inb(ahd
, SG_STATE
) & FETCH_INPROG
) != 0)
354 ahd_outb(ahd
, CCSGCTL
, CCSGRESET
);
355 ahd_outb(ahd
, LONGJMP_ADDR
+ 1, INVALID_ADDR
);
356 ahd_outb(ahd
, SG_STATE
, 0);
357 ahd_restore_modes(ahd
, saved_modes
);
360 /************************* Input/Output Queues ********************************/
362 * Flush and completed commands that are sitting in the command
363 * complete queues down on the chip but have yet to be dma'ed back up.
366 ahd_flush_qoutfifo(struct ahd_softc
*ahd
)
369 ahd_mode_state saved_modes
;
375 saved_modes
= ahd_save_modes(ahd
);
378 * Complete any SCBs that just finished being
379 * DMA'ed into the qoutfifo.
381 ahd_run_qoutfifo(ahd
);
384 * Flush the good status FIFO for compelted packetized commands.
386 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
387 saved_scbptr
= ahd_get_scbptr(ahd
);
388 while ((ahd_inb(ahd
, LQISTAT2
) & LQIGSAVAIL
) != 0) {
392 scbid
= (ahd_inb(ahd
, GSFIFO
+1) << 8)
393 | ahd_inb(ahd
, GSFIFO
);
394 scb
= ahd_lookup_scb(ahd
, scbid
);
396 printf("%s: Warning - GSFIFO SCB %d invalid\n",
397 ahd_name(ahd
), scbid
);
401 * Determine if this transaction is still active in
402 * any FIFO. If it is, we must flush that FIFO to
403 * the host before completing the command.
406 for (i
= 0; i
< 2; i
++) {
407 /* Toggle to the other mode. */
409 ahd_set_modes(ahd
, fifo_mode
, fifo_mode
);
410 if (ahd_scb_active_in_fifo(ahd
, scb
) == 0)
413 ahd_run_data_fifo(ahd
, scb
);
416 * Clearing this transaction in this FIFO may
417 * cause a CFG4DATA for this same transaction
418 * to assert in the other FIFO. Make sure we
419 * loop one more time and check the other FIFO.
423 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
424 ahd_set_scbptr(ahd
, scbid
);
425 if ((ahd_inb_scbram(ahd
, SCB_SGPTR
) & SG_LIST_NULL
) == 0
426 && ((ahd_inb_scbram(ahd
, SCB_SGPTR
) & SG_FULL_RESID
) != 0
427 || (ahd_inb_scbram(ahd
, SCB_RESIDUAL_SGPTR
)
428 & SG_LIST_NULL
) != 0)) {
432 * The transfer completed with a residual.
433 * Place this SCB on the complete DMA list
434 * so that we Update our in-core copy of the
435 * SCB before completing the command.
437 ahd_outb(ahd
, SCB_SCSI_STATUS
, 0);
438 ahd_outb(ahd
, SCB_SGPTR
,
439 ahd_inb_scbram(ahd
, SCB_SGPTR
)
441 ahd_outw(ahd
, SCB_TAG
, SCB_GET_TAG(scb
));
442 comp_head
= ahd_inw(ahd
, COMPLETE_DMA_SCB_HEAD
);
443 ahd_outw(ahd
, SCB_NEXT_COMPLETE
, comp_head
);
444 if (SCBID_IS_NULL(comp_head
))
445 ahd_outw(ahd
, COMPLETE_DMA_SCB_HEAD
,
448 ahd_complete_scb(ahd
, scb
);
450 ahd_set_scbptr(ahd
, saved_scbptr
);
453 * Setup for command channel portion of flush.
455 ahd_set_modes(ahd
, AHD_MODE_CCHAN
, AHD_MODE_CCHAN
);
458 * Wait for any inprogress DMA to complete and clear DMA state
459 * if this if for an SCB in the qinfifo.
461 while (((ccscbctl
= ahd_inb(ahd
, CCSCBCTL
)) & (CCARREN
|CCSCBEN
)) != 0) {
463 if ((ccscbctl
& (CCSCBDIR
|CCARREN
)) == (CCSCBDIR
|CCARREN
)) {
464 if ((ccscbctl
& ARRDONE
) != 0)
466 } else if ((ccscbctl
& CCSCBDONE
) != 0)
470 if ((ccscbctl
& CCSCBDIR
) != 0)
471 ahd_outb(ahd
, CCSCBCTL
, ccscbctl
& ~(CCARREN
|CCSCBEN
));
473 saved_scbptr
= ahd_get_scbptr(ahd
);
475 * Manually update/complete any completed SCBs that are waiting to be
476 * DMA'ed back up to the host.
478 scbid
= ahd_inw(ahd
, COMPLETE_DMA_SCB_HEAD
);
479 while (!SCBID_IS_NULL(scbid
)) {
483 ahd_set_scbptr(ahd
, scbid
);
484 next_scbid
= ahd_inw_scbram(ahd
, SCB_NEXT_COMPLETE
);
485 scb
= ahd_lookup_scb(ahd
, scbid
);
487 printf("%s: Warning - DMA-up and complete "
488 "SCB %d invalid\n", ahd_name(ahd
), scbid
);
491 hscb_ptr
= (uint8_t *)scb
->hscb
;
492 for (i
= 0; i
< sizeof(struct hardware_scb
); i
++)
493 *hscb_ptr
++ = ahd_inb_scbram(ahd
, SCB_BASE
+ i
);
495 ahd_complete_scb(ahd
, scb
);
498 ahd_outw(ahd
, COMPLETE_DMA_SCB_HEAD
, SCB_LIST_NULL
);
500 scbid
= ahd_inw(ahd
, COMPLETE_SCB_HEAD
);
501 while (!SCBID_IS_NULL(scbid
)) {
503 ahd_set_scbptr(ahd
, scbid
);
504 next_scbid
= ahd_inw_scbram(ahd
, SCB_NEXT_COMPLETE
);
505 scb
= ahd_lookup_scb(ahd
, scbid
);
507 printf("%s: Warning - Complete SCB %d invalid\n",
508 ahd_name(ahd
), scbid
);
512 ahd_complete_scb(ahd
, scb
);
515 ahd_outw(ahd
, COMPLETE_SCB_HEAD
, SCB_LIST_NULL
);
520 ahd_set_scbptr(ahd
, saved_scbptr
);
521 ahd_restore_modes(ahd
, saved_modes
);
522 ahd
->flags
|= AHD_UPDATE_PEND_CMDS
;
526 * Determine if an SCB for a packetized transaction
527 * is active in a FIFO.
530 ahd_scb_active_in_fifo(struct ahd_softc
*ahd
, struct scb
*scb
)
534 * The FIFO is only active for our transaction if
535 * the SCBPTR matches the SCB's ID and the firmware
536 * has installed a handler for the FIFO or we have
537 * a pending SAVEPTRS or CFG4DATA interrupt.
539 if (ahd_get_scbptr(ahd
) != SCB_GET_TAG(scb
)
540 || ((ahd_inb(ahd
, LONGJMP_ADDR
+1) & INVALID_ADDR
) != 0
541 && (ahd_inb(ahd
, SEQINTSRC
) & (CFG4DATA
|SAVEPTRS
)) == 0))
548 * Run a data fifo to completion for a transaction we know
549 * has completed across the SCSI bus (good status has been
550 * received). We are already set to the correct FIFO mode
551 * on entry to this routine.
553 * This function attempts to operate exactly as the firmware
554 * would when running this FIFO. Care must be taken to update
555 * this routine any time the firmware's FIFO algorithm is
559 ahd_run_data_fifo(struct ahd_softc
*ahd
, struct scb
*scb
)
564 seqintsrc
= ahd_inb(ahd
, SEQINTSRC
);
565 if ((seqintsrc
& CFG4DATA
) != 0) {
570 * Clear full residual flag.
572 sgptr
= ahd_inl_scbram(ahd
, SCB_SGPTR
) & ~SG_FULL_RESID
;
573 ahd_outb(ahd
, SCB_SGPTR
, sgptr
);
576 * Load datacnt and address.
578 datacnt
= ahd_inl_scbram(ahd
, SCB_DATACNT
);
579 if ((datacnt
& AHD_DMA_LAST_SEG
) != 0) {
581 ahd_outb(ahd
, SG_STATE
, 0);
583 ahd_outb(ahd
, SG_STATE
, LOADING_NEEDED
);
584 ahd_outq(ahd
, HADDR
, ahd_inq_scbram(ahd
, SCB_DATAPTR
));
585 ahd_outl(ahd
, HCNT
, datacnt
& AHD_SG_LEN_MASK
);
586 ahd_outb(ahd
, SG_CACHE_PRE
, sgptr
);
587 ahd_outb(ahd
, DFCNTRL
, PRELOADEN
|SCSIEN
|HDMAEN
);
590 * Initialize Residual Fields.
592 ahd_outb(ahd
, SCB_RESIDUAL_DATACNT
+3, datacnt
>> 24);
593 ahd_outl(ahd
, SCB_RESIDUAL_SGPTR
, sgptr
& SG_PTR_MASK
);
596 * Mark the SCB as having a FIFO in use.
598 ahd_outb(ahd
, SCB_FIFO_USE_COUNT
,
599 ahd_inb_scbram(ahd
, SCB_FIFO_USE_COUNT
) + 1);
602 * Install a "fake" handler for this FIFO.
604 ahd_outw(ahd
, LONGJMP_ADDR
, 0);
607 * Notify the hardware that we have satisfied
608 * this sequencer interrupt.
610 ahd_outb(ahd
, CLRSEQINTSRC
, CLRCFG4DATA
);
611 } else if ((seqintsrc
& SAVEPTRS
) != 0) {
615 if ((ahd_inb(ahd
, LONGJMP_ADDR
+1)&INVALID_ADDR
) != 0) {
617 * Snapshot Save Pointers. Clear
618 * the snapshot and continue.
620 ahd_outb(ahd
, DFFSXFRCTL
, CLRCHN
);
625 * Disable S/G fetch so the DMA engine
626 * is available to future users.
628 if ((ahd_inb(ahd
, SG_STATE
) & FETCH_INPROG
) != 0)
629 ahd_outb(ahd
, CCSGCTL
, 0);
630 ahd_outb(ahd
, SG_STATE
, 0);
633 * Flush the data FIFO. Strickly only
634 * necessary for Rev A parts.
636 ahd_outb(ahd
, DFCNTRL
,
637 ahd_inb(ahd
, DFCNTRL
) | FIFOFLUSH
);
640 * Calculate residual.
642 sgptr
= ahd_inl_scbram(ahd
, SCB_RESIDUAL_SGPTR
);
643 resid
= ahd_inl(ahd
, SHCNT
);
645 ahd_inb_scbram(ahd
, SCB_RESIDUAL_DATACNT
+3) << 24;
646 ahd_outl(ahd
, SCB_RESIDUAL_DATACNT
, resid
);
647 if ((ahd_inb(ahd
, SG_CACHE_SHADOW
) & LAST_SEG
) == 0) {
649 * Must back up to the correct S/G element.
650 * Typically this just means resetting our
651 * low byte to the offset in the SG_CACHE,
652 * but if we wrapped, we have to correct
653 * the other bytes of the sgptr too.
655 if ((ahd_inb(ahd
, SG_CACHE_SHADOW
) & 0x80) != 0
656 && (sgptr
& 0x80) == 0)
659 sgptr
|= ahd_inb(ahd
, SG_CACHE_SHADOW
)
661 ahd_outl(ahd
, SCB_RESIDUAL_SGPTR
, sgptr
);
662 ahd_outb(ahd
, SCB_RESIDUAL_DATACNT
+ 3, 0);
663 } else if ((resid
& AHD_SG_LEN_MASK
) == 0) {
664 ahd_outb(ahd
, SCB_RESIDUAL_SGPTR
,
665 sgptr
| SG_LIST_NULL
);
670 ahd_outq(ahd
, SCB_DATAPTR
, ahd_inq(ahd
, SHADDR
));
671 ahd_outl(ahd
, SCB_DATACNT
, resid
);
672 ahd_outl(ahd
, SCB_SGPTR
, sgptr
);
673 ahd_outb(ahd
, CLRSEQINTSRC
, CLRSAVEPTRS
);
674 ahd_outb(ahd
, SEQIMODE
,
675 ahd_inb(ahd
, SEQIMODE
) | ENSAVEPTRS
);
677 * If the data is to the SCSI bus, we are
678 * done, otherwise wait for FIFOEMP.
680 if ((ahd_inb(ahd
, DFCNTRL
) & DIRECTION
) != 0)
682 } else if ((ahd_inb(ahd
, SG_STATE
) & LOADING_NEEDED
) != 0) {
689 * Disable S/G fetch so the DMA engine
690 * is available to future users.
692 if ((ahd_inb(ahd
, SG_STATE
) & FETCH_INPROG
) != 0) {
693 ahd_outb(ahd
, CCSGCTL
, 0);
694 ahd_outb(ahd
, SG_STATE
, LOADING_NEEDED
);
698 * Wait for the DMA engine to notice that the
699 * host transfer is enabled and that there is
700 * space in the S/G FIFO for new segments before
701 * loading more segments.
703 if ((ahd_inb(ahd
, DFSTATUS
) & PRELOAD_AVAIL
) == 0)
705 if ((ahd_inb(ahd
, DFCNTRL
) & HDMAENACK
) == 0)
709 * Determine the offset of the next S/G
712 sgptr
= ahd_inl_scbram(ahd
, SCB_RESIDUAL_SGPTR
);
713 sgptr
&= SG_PTR_MASK
;
714 if ((ahd
->flags
& AHD_64BIT_ADDRESSING
) != 0) {
715 struct ahd_dma64_seg
*sg
;
717 sg
= ahd_sg_bus_to_virt(ahd
, scb
, sgptr
);
718 data_addr
= sg
->addr
;
720 sgptr
+= sizeof(*sg
);
722 struct ahd_dma_seg
*sg
;
724 sg
= ahd_sg_bus_to_virt(ahd
, scb
, sgptr
);
725 data_addr
= sg
->len
& AHD_SG_HIGH_ADDR_MASK
;
727 data_addr
|= sg
->addr
;
729 sgptr
+= sizeof(*sg
);
733 * Update residual information.
735 ahd_outb(ahd
, SCB_RESIDUAL_DATACNT
+3, data_len
>> 24);
736 ahd_outl(ahd
, SCB_RESIDUAL_SGPTR
, sgptr
);
741 if (data_len
& AHD_DMA_LAST_SEG
) {
743 ahd_outb(ahd
, SG_STATE
, 0);
745 ahd_outq(ahd
, HADDR
, data_addr
);
746 ahd_outl(ahd
, HCNT
, data_len
& AHD_SG_LEN_MASK
);
747 ahd_outb(ahd
, SG_CACHE_PRE
, sgptr
& 0xFF);
750 * Advertise the segment to the hardware.
752 dfcntrl
= ahd_inb(ahd
, DFCNTRL
)|PRELOADEN
|HDMAEN
;
753 if ((ahd
->features
& AHD_NEW_DFCNTRL_OPTS
)!=0) {
755 * Use SCSIENWRDIS so that SCSIEN
756 * is never modified by this
759 dfcntrl
|= SCSIENWRDIS
;
761 ahd_outb(ahd
, DFCNTRL
, dfcntrl
);
762 } else if ((ahd_inb(ahd
, SG_CACHE_SHADOW
)
763 & LAST_SEG_DONE
) != 0) {
766 * Transfer completed to the end of SG list
767 * and has flushed to the host.
769 ahd_outb(ahd
, SCB_SGPTR
,
770 ahd_inb_scbram(ahd
, SCB_SGPTR
) | SG_LIST_NULL
);
772 } else if ((ahd_inb(ahd
, DFSTATUS
) & FIFOEMP
) != 0) {
778 * Clear any handler for this FIFO, decrement
779 * the FIFO use count for the SCB, and release
782 ahd_outb(ahd
, LONGJMP_ADDR
+ 1, INVALID_ADDR
);
783 ahd_outb(ahd
, SCB_FIFO_USE_COUNT
,
784 ahd_inb_scbram(ahd
, SCB_FIFO_USE_COUNT
) - 1);
785 ahd_outb(ahd
, DFFSXFRCTL
, CLRCHN
);
789 ahd_run_qoutfifo(struct ahd_softc
*ahd
)
794 if ((ahd
->flags
& AHD_RUNNING_QOUTFIFO
) != 0)
795 panic("ahd_run_qoutfifo recursion");
796 ahd
->flags
|= AHD_RUNNING_QOUTFIFO
;
797 ahd_sync_qoutfifo(ahd
, BUS_DMASYNC_POSTREAD
);
798 while ((ahd
->qoutfifo
[ahd
->qoutfifonext
]
799 & QOUTFIFO_ENTRY_VALID_LE
) == ahd
->qoutfifonext_valid_tag
) {
801 scb_index
= ahd_le16toh(ahd
->qoutfifo
[ahd
->qoutfifonext
]
802 & ~QOUTFIFO_ENTRY_VALID_LE
);
803 scb
= ahd_lookup_scb(ahd
, scb_index
);
805 printf("%s: WARNING no command for scb %d "
806 "(cmdcmplt)\nQOUTPOS = %d\n",
807 ahd_name(ahd
), scb_index
,
809 ahd_dump_card_state(ahd
);
811 ahd_complete_scb(ahd
, scb
);
813 ahd
->qoutfifonext
= (ahd
->qoutfifonext
+1) & (AHD_QOUT_SIZE
-1);
814 if (ahd
->qoutfifonext
== 0)
815 ahd
->qoutfifonext_valid_tag
^= QOUTFIFO_ENTRY_VALID_LE
;
817 ahd
->flags
&= ~AHD_RUNNING_QOUTFIFO
;
820 /************************* Interrupt Handling *********************************/
822 ahd_handle_hwerrint(struct ahd_softc
*ahd
)
825 * Some catastrophic hardware error has occurred.
826 * Print it for the user and disable the controller.
831 error
= ahd_inb(ahd
, ERROR
);
832 for (i
= 0; i
< num_errors
; i
++) {
833 if ((error
& ahd_hard_errors
[i
].errno
) != 0)
834 printf("%s: hwerrint, %s\n",
835 ahd_name(ahd
), ahd_hard_errors
[i
].errmesg
);
838 ahd_dump_card_state(ahd
);
841 /* Tell everyone that this HBA is no longer available */
842 ahd_abort_scbs(ahd
, CAM_TARGET_WILDCARD
, ALL_CHANNELS
,
843 CAM_LUN_WILDCARD
, SCB_LIST_NULL
, ROLE_UNKNOWN
,
846 /* Tell the system that this controller has gone away. */
851 ahd_handle_seqint(struct ahd_softc
*ahd
, u_int intstat
)
856 * Save the sequencer interrupt code and clear the SEQINT
857 * bit. We will unpause the sequencer, if appropriate,
858 * after servicing the request.
860 seqintcode
= ahd_inb(ahd
, SEQINTCODE
);
861 ahd_outb(ahd
, CLRINT
, CLRSEQINT
);
862 if ((ahd
->bugs
& AHD_INTCOLLISION_BUG
) != 0) {
864 * Unpause the sequencer and let it clear
865 * SEQINT by writing NO_SEQINT to it. This
866 * will cause the sequencer to be paused again,
867 * which is the expected state of this routine.
870 while (!ahd_is_paused(ahd
))
872 ahd_outb(ahd
, CLRINT
, CLRSEQINT
);
874 ahd_update_modes(ahd
);
876 if ((ahd_debug
& AHD_SHOW_MISC
) != 0)
877 printf("%s: Handle Seqint Called for code %d\n",
878 ahd_name(ahd
), seqintcode
);
880 switch (seqintcode
) {
887 scbid
= ahd_get_scbptr(ahd
);
888 scb
= ahd_lookup_scb(ahd
, scbid
);
890 ahd_complete_scb(ahd
, scb
);
892 printf("%s: WARNING no command for scb %d "
893 "(bad status)\n", ahd_name(ahd
), scbid
);
894 ahd_dump_card_state(ahd
);
896 cmds_pending
= ahd_inw(ahd
, CMDS_PENDING
);
897 if (cmds_pending
> 0)
898 ahd_outw(ahd
, CMDS_PENDING
, cmds_pending
- 1);
901 case ENTERING_NONPACK
:
906 AHD_ASSERT_MODES(ahd
, ~(AHD_MODE_UNKNOWN_MSK
|AHD_MODE_CFG_MSK
),
907 ~(AHD_MODE_UNKNOWN_MSK
|AHD_MODE_CFG_MSK
));
908 scbid
= ahd_get_scbptr(ahd
);
909 scb
= ahd_lookup_scb(ahd
, scbid
);
912 * Somehow need to know if this
913 * is from a selection or reselection.
914 * From that, we can determine target
915 * ID so we at least have an I_T nexus.
918 ahd_outb(ahd
, SAVED_SCSIID
, scb
->hscb
->scsiid
);
919 ahd_outb(ahd
, SAVED_LUN
, scb
->hscb
->lun
);
920 ahd_outb(ahd
, SEQ_FLAGS
, 0x0);
922 if ((ahd_inb(ahd
, LQISTAT2
) & LQIPHASE_OUTPKT
) != 0
923 && (ahd_inb(ahd
, SCSISIGO
) & ATNO
) != 0) {
925 * Phase change after read stream with
926 * CRC error with P0 asserted on last
930 if ((ahd_debug
& AHD_SHOW_RECOVERY
) != 0)
931 printf("%s: Assuming LQIPHASE_NLQ with "
932 "P0 assertion\n", ahd_name(ahd
));
936 if ((ahd_debug
& AHD_SHOW_RECOVERY
) != 0)
937 printf("%s: Entering NONPACK\n", ahd_name(ahd
));
942 printf("%s: Invalid Sequencer interrupt occurred.\n",
944 ahd_dump_card_state(ahd
);
945 ahd_reset_channel(ahd
, 'A', /*Initiate Reset*/TRUE
);
952 scbid
= ahd_get_scbptr(ahd
);
953 scb
= ahd_lookup_scb(ahd
, scbid
);
955 ahd_print_path(ahd
, scb
);
957 printf("%s: ", ahd_name(ahd
));
958 printf("SCB %d Packetized Status Overrun", scbid
);
959 ahd_dump_card_state(ahd
);
960 ahd_reset_channel(ahd
, 'A', /*Initiate Reset*/TRUE
);
968 scbid
= ahd_get_scbptr(ahd
);
969 scb
= ahd_lookup_scb(ahd
, scbid
);
971 ahd_dump_card_state(ahd
);
972 printf("CFG4ISTAT: Free SCB %d referenced", scbid
);
975 ahd_outq(ahd
, HADDR
, scb
->sense_busaddr
);
976 ahd_outw(ahd
, HCNT
, AHD_SENSE_BUFSIZE
);
977 ahd_outb(ahd
, HCNT
+ 2, 0);
978 ahd_outb(ahd
, SG_CACHE_PRE
, SG_LAST_SEG
);
979 ahd_outb(ahd
, DFCNTRL
, PRELOADEN
|SCSIEN
|HDMAEN
);
986 bus_phase
= ahd_inb(ahd
, SCSISIGI
) & PHASE_MASK
;
987 printf("%s: ILLEGAL_PHASE 0x%x\n",
988 ahd_name(ahd
), bus_phase
);
998 ahd_reset_channel(ahd
, 'A', /*Initiate Reset*/TRUE
);
999 printf("%s: Issued Bus Reset.\n", ahd_name(ahd
));
1003 struct ahd_devinfo devinfo
;
1005 struct ahd_initiator_tinfo
*targ_info
;
1006 struct ahd_tmode_tstate
*tstate
;
1007 struct ahd_transinfo
*tinfo
;
1011 * If a target takes us into the command phase
1012 * assume that it has been externally reset and
1013 * has thus lost our previous packetized negotiation
1014 * agreement. Since we have not sent an identify
1015 * message and may not have fully qualified the
1016 * connection, we change our command to TUR, assert
1017 * ATN and ABORT the task when we go to message in
1018 * phase. The OSM will see the REQUEUE_REQUEST
1019 * status and retry the command.
1021 scbid
= ahd_get_scbptr(ahd
);
1022 scb
= ahd_lookup_scb(ahd
, scbid
);
1024 printf("Invalid phase with no valid SCB. "
1025 "Resetting bus.\n");
1026 ahd_reset_channel(ahd
, 'A',
1027 /*Initiate Reset*/TRUE
);
1030 ahd_compile_devinfo(&devinfo
, SCB_GET_OUR_ID(scb
),
1031 SCB_GET_TARGET(ahd
, scb
),
1033 SCB_GET_CHANNEL(ahd
, scb
),
1035 targ_info
= ahd_fetch_transinfo(ahd
,
1040 tinfo
= &targ_info
->curr
;
1041 ahd_set_width(ahd
, &devinfo
, MSG_EXT_WDTR_BUS_8_BIT
,
1042 AHD_TRANS_ACTIVE
, /*paused*/TRUE
);
1043 ahd_set_syncrate(ahd
, &devinfo
, /*period*/0,
1044 /*offset*/0, /*ppr_options*/0,
1045 AHD_TRANS_ACTIVE
, /*paused*/TRUE
);
1046 ahd_outb(ahd
, SCB_CDB_STORE
, 0);
1047 ahd_outb(ahd
, SCB_CDB_STORE
+1, 0);
1048 ahd_outb(ahd
, SCB_CDB_STORE
+2, 0);
1049 ahd_outb(ahd
, SCB_CDB_STORE
+3, 0);
1050 ahd_outb(ahd
, SCB_CDB_STORE
+4, 0);
1051 ahd_outb(ahd
, SCB_CDB_STORE
+5, 0);
1052 ahd_outb(ahd
, SCB_CDB_LEN
, 6);
1053 scb
->hscb
->control
&= ~(TAG_ENB
|SCB_TAG_TYPE
);
1054 scb
->hscb
->control
|= MK_MESSAGE
;
1055 ahd_outb(ahd
, SCB_CONTROL
, scb
->hscb
->control
);
1056 ahd_outb(ahd
, MSG_OUT
, HOST_MSG
);
1057 ahd_outb(ahd
, SAVED_SCSIID
, scb
->hscb
->scsiid
);
1059 * The lun is 0, regardless of the SCB's lun
1060 * as we have not sent an identify message.
1062 ahd_outb(ahd
, SAVED_LUN
, 0);
1063 ahd_outb(ahd
, SEQ_FLAGS
, 0);
1064 ahd_assert_atn(ahd
);
1065 scb
->flags
&= ~(SCB_PACKETIZED
);
1066 scb
->flags
|= SCB_ABORT
|SCB_CMDPHASE_ABORT
;
1067 ahd_freeze_devq(ahd
, scb
);
1068 ahd_set_transaction_status(scb
, CAM_REQUEUE_REQ
);
1069 ahd_freeze_scb(scb
);
1072 * Allow the sequencer to continue with
1073 * non-pack processing.
1075 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
1076 ahd_outb(ahd
, CLRLQOINT1
, CLRLQOPHACHGINPKT
);
1077 if ((ahd
->bugs
& AHD_CLRLQO_AUTOCLR_BUG
) != 0) {
1078 ahd_outb(ahd
, CLRLQOINT1
, 0);
1081 if ((ahd_debug
& AHD_SHOW_RECOVERY
) != 0) {
1082 ahd_print_path(ahd
, scb
);
1083 printf("Unexpected command phase from "
1084 "packetized target\n");
1098 if ((ahd_debug
& AHD_SHOW_RECOVERY
) != 0) {
1099 printf("%s: CFG4OVERRUN mode = %x\n", ahd_name(ahd
),
1100 ahd_inb(ahd
, MODE_PTR
));
1103 scb_index
= ahd_get_scbptr(ahd
);
1104 scb
= ahd_lookup_scb(ahd
, scb_index
);
1107 * Attempt to transfer to an SCB that is
1110 ahd_assert_atn(ahd
);
1111 ahd_outb(ahd
, MSG_OUT
, HOST_MSG
);
1112 ahd
->msgout_buf
[0] = MSG_ABORT_TASK
;
1113 ahd
->msgout_len
= 1;
1114 ahd
->msgout_index
= 0;
1115 ahd
->msg_type
= MSG_TYPE_INITIATOR_MSGOUT
;
1117 * Clear status received flag to prevent any
1118 * attempt to complete this bogus SCB.
1120 ahd_outb(ahd
, SCB_CONTROL
,
1121 ahd_inb_scbram(ahd
, SCB_CONTROL
)
1126 case DUMP_CARD_STATE
:
1128 ahd_dump_card_state(ahd
);
1134 if ((ahd_debug
& AHD_SHOW_RECOVERY
) != 0) {
1135 printf("%s: PDATA_REINIT - DFCNTRL = 0x%x "
1136 "SG_CACHE_SHADOW = 0x%x\n",
1137 ahd_name(ahd
), ahd_inb(ahd
, DFCNTRL
),
1138 ahd_inb(ahd
, SG_CACHE_SHADOW
));
1141 ahd_reinitialize_dataptrs(ahd
);
1146 struct ahd_devinfo devinfo
;
1149 * The sequencer has encountered a message phase
1150 * that requires host assistance for completion.
1151 * While handling the message phase(s), we will be
1152 * notified by the sequencer after each byte is
1153 * transfered so we can track bus phase changes.
1155 * If this is the first time we've seen a HOST_MSG_LOOP
1156 * interrupt, initialize the state of the host message
1159 ahd_fetch_devinfo(ahd
, &devinfo
);
1160 if (ahd
->msg_type
== MSG_TYPE_NONE
) {
1165 bus_phase
= ahd_inb(ahd
, SCSISIGI
) & PHASE_MASK
;
1166 if (bus_phase
!= P_MESGIN
1167 && bus_phase
!= P_MESGOUT
) {
1168 printf("ahd_intr: HOST_MSG_LOOP bad "
1169 "phase 0x%x\n", bus_phase
);
1171 * Probably transitioned to bus free before
1172 * we got here. Just punt the message.
1174 ahd_dump_card_state(ahd
);
1175 ahd_clear_intstat(ahd
);
1180 scb_index
= ahd_get_scbptr(ahd
);
1181 scb
= ahd_lookup_scb(ahd
, scb_index
);
1182 if (devinfo
.role
== ROLE_INITIATOR
) {
1183 if (bus_phase
== P_MESGOUT
)
1184 ahd_setup_initiator_msgout(ahd
,
1189 MSG_TYPE_INITIATOR_MSGIN
;
1190 ahd
->msgin_index
= 0;
1193 #ifdef AHD_TARGET_MODE
1195 if (bus_phase
== P_MESGOUT
) {
1197 MSG_TYPE_TARGET_MSGOUT
;
1198 ahd
->msgin_index
= 0;
1201 ahd_setup_target_msgin(ahd
,
1208 ahd_handle_message_phase(ahd
);
1213 /* Ensure we don't leave the selection hardware on */
1214 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
1215 ahd_outb(ahd
, SCSISEQ0
, ahd_inb(ahd
, SCSISEQ0
) & ~ENSELO
);
1217 printf("%s:%c:%d: no active SCB for reconnecting "
1218 "target - issuing BUS DEVICE RESET\n",
1219 ahd_name(ahd
), 'A', ahd_inb(ahd
, SELID
) >> 4);
1220 printf("SAVED_SCSIID == 0x%x, SAVED_LUN == 0x%x, "
1221 "REG0 == 0x%x ACCUM = 0x%x\n",
1222 ahd_inb(ahd
, SAVED_SCSIID
), ahd_inb(ahd
, SAVED_LUN
),
1223 ahd_inw(ahd
, REG0
), ahd_inb(ahd
, ACCUM
));
1224 printf("SEQ_FLAGS == 0x%x, SCBPTR == 0x%x, BTT == 0x%x, "
1226 ahd_inb(ahd
, SEQ_FLAGS
), ahd_get_scbptr(ahd
),
1227 ahd_find_busy_tcl(ahd
,
1228 BUILD_TCL(ahd_inb(ahd
, SAVED_SCSIID
),
1229 ahd_inb(ahd
, SAVED_LUN
))),
1230 ahd_inw(ahd
, SINDEX
));
1231 printf("SELID == 0x%x, SCB_SCSIID == 0x%x, SCB_LUN == 0x%x, "
1232 "SCB_CONTROL == 0x%x\n",
1233 ahd_inb(ahd
, SELID
), ahd_inb_scbram(ahd
, SCB_SCSIID
),
1234 ahd_inb_scbram(ahd
, SCB_LUN
),
1235 ahd_inb_scbram(ahd
, SCB_CONTROL
));
1236 printf("SCSIBUS[0] == 0x%x, SCSISIGI == 0x%x\n",
1237 ahd_inb(ahd
, SCSIBUS
), ahd_inb(ahd
, SCSISIGI
));
1238 printf("SXFRCTL0 == 0x%x\n", ahd_inb(ahd
, SXFRCTL0
));
1239 printf("SEQCTL0 == 0x%x\n", ahd_inb(ahd
, SEQCTL0
));
1240 ahd_dump_card_state(ahd
);
1241 ahd
->msgout_buf
[0] = MSG_BUS_DEV_RESET
;
1242 ahd
->msgout_len
= 1;
1243 ahd
->msgout_index
= 0;
1244 ahd
->msg_type
= MSG_TYPE_INITIATOR_MSGOUT
;
1245 ahd_outb(ahd
, MSG_OUT
, HOST_MSG
);
1246 ahd_assert_atn(ahd
);
1249 case PROTO_VIOLATION
:
1251 ahd_handle_proto_violation(ahd
);
1256 struct ahd_devinfo devinfo
;
1258 ahd_fetch_devinfo(ahd
, &devinfo
);
1259 ahd_handle_ign_wide_residue(ahd
, &devinfo
);
1266 lastphase
= ahd_inb(ahd
, LASTPHASE
);
1267 printf("%s:%c:%d: unknown scsi bus phase %x, "
1268 "lastphase = 0x%x. Attempting to continue\n",
1270 SCSIID_TARGET(ahd
, ahd_inb(ahd
, SAVED_SCSIID
)),
1271 lastphase
, ahd_inb(ahd
, SCSISIGI
));
1274 case MISSED_BUSFREE
:
1278 lastphase
= ahd_inb(ahd
, LASTPHASE
);
1279 printf("%s:%c:%d: Missed busfree. "
1280 "Lastphase = 0x%x, Curphase = 0x%x\n",
1282 SCSIID_TARGET(ahd
, ahd_inb(ahd
, SAVED_SCSIID
)),
1283 lastphase
, ahd_inb(ahd
, SCSISIGI
));
1290 * When the sequencer detects an overrun, it
1291 * places the controller in "BITBUCKET" mode
1292 * and allows the target to complete its transfer.
1293 * Unfortunately, none of the counters get updated
1294 * when the controller is in this mode, so we have
1295 * no way of knowing how large the overrun was.
1303 scbindex
= ahd_get_scbptr(ahd
);
1304 scb
= ahd_lookup_scb(ahd
, scbindex
);
1306 lastphase
= ahd_inb(ahd
, LASTPHASE
);
1307 if ((ahd_debug
& AHD_SHOW_RECOVERY
) != 0) {
1308 ahd_print_path(ahd
, scb
);
1309 printf("data overrun detected %s. Tag == 0x%x.\n",
1310 ahd_lookup_phase_entry(lastphase
)->phasemsg
,
1312 ahd_print_path(ahd
, scb
);
1313 printf("%s seen Data Phase. Length = %ld. "
1315 ahd_inb(ahd
, SEQ_FLAGS
) & DPHASE
1316 ? "Have" : "Haven't",
1317 ahd_get_transfer_length(scb
), scb
->sg_count
);
1318 ahd_dump_sglist(scb
);
1323 * Set this and it will take effect when the
1324 * target does a command complete.
1326 ahd_freeze_devq(ahd
, scb
);
1327 ahd_set_transaction_status(scb
, CAM_DATA_RUN_ERR
);
1328 ahd_freeze_scb(scb
);
1333 struct ahd_devinfo devinfo
;
1337 ahd_fetch_devinfo(ahd
, &devinfo
);
1338 printf("%s:%c:%d:%d: Attempt to issue message failed\n",
1339 ahd_name(ahd
), devinfo
.channel
, devinfo
.target
,
1341 scbid
= ahd_get_scbptr(ahd
);
1342 scb
= ahd_lookup_scb(ahd
, scbid
);
1344 && (scb
->flags
& SCB_RECOVERY_SCB
) != 0)
1346 * Ensure that we didn't put a second instance of this
1347 * SCB into the QINFIFO.
1349 ahd_search_qinfifo(ahd
, SCB_GET_TARGET(ahd
, scb
),
1350 SCB_GET_CHANNEL(ahd
, scb
),
1351 SCB_GET_LUN(scb
), SCB_GET_TAG(scb
),
1352 ROLE_INITIATOR
, /*status*/0,
1354 ahd_outb(ahd
, SCB_CONTROL
,
1355 ahd_inb_scbram(ahd
, SCB_CONTROL
) & ~MK_MESSAGE
);
1358 case TASKMGMT_FUNC_COMPLETE
:
1363 scbid
= ahd_get_scbptr(ahd
);
1364 scb
= ahd_lookup_scb(ahd
, scbid
);
1370 ahd_print_path(ahd
, scb
);
1371 printf("Task Management Func 0x%x Complete\n",
1372 scb
->hscb
->task_management
);
1373 lun
= CAM_LUN_WILDCARD
;
1374 tag
= SCB_LIST_NULL
;
1376 switch (scb
->hscb
->task_management
) {
1377 case SIU_TASKMGMT_ABORT_TASK
:
1378 tag
= SCB_GET_TAG(scb
);
1379 case SIU_TASKMGMT_ABORT_TASK_SET
:
1380 case SIU_TASKMGMT_CLEAR_TASK_SET
:
1381 lun
= scb
->hscb
->lun
;
1382 error
= CAM_REQ_ABORTED
;
1383 ahd_abort_scbs(ahd
, SCB_GET_TARGET(ahd
, scb
),
1384 'A', lun
, tag
, ROLE_INITIATOR
,
1387 case SIU_TASKMGMT_LUN_RESET
:
1388 lun
= scb
->hscb
->lun
;
1389 case SIU_TASKMGMT_TARGET_RESET
:
1391 struct ahd_devinfo devinfo
;
1393 ahd_scb_devinfo(ahd
, &devinfo
, scb
);
1394 error
= CAM_BDR_SENT
;
1395 ahd_handle_devreset(ahd
, &devinfo
, lun
,
1397 lun
!= CAM_LUN_WILDCARD
1400 /*verbose_level*/0);
1404 panic("Unexpected TaskMgmt Func\n");
1410 case TASKMGMT_CMD_CMPLT_OKAY
:
1416 * An ABORT TASK TMF failed to be delivered before
1417 * the targeted command completed normally.
1419 scbid
= ahd_get_scbptr(ahd
);
1420 scb
= ahd_lookup_scb(ahd
, scbid
);
1423 * Remove the second instance of this SCB from
1424 * the QINFIFO if it is still there.
1426 ahd_print_path(ahd
, scb
);
1427 printf("SCB completes before TMF\n");
1429 * Handle losing the race. Wait until any
1430 * current selection completes. We will then
1431 * set the TMF back to zero in this SCB so that
1432 * the sequencer doesn't bother to issue another
1433 * sequencer interrupt for its completion.
1435 while ((ahd_inb(ahd
, SCSISEQ0
) & ENSELO
) != 0
1436 && (ahd_inb(ahd
, SSTAT0
) & SELDO
) == 0
1437 && (ahd_inb(ahd
, SSTAT1
) & SELTO
) == 0)
1439 ahd_outb(ahd
, SCB_TASK_MANAGEMENT
, 0);
1440 ahd_search_qinfifo(ahd
, SCB_GET_TARGET(ahd
, scb
),
1441 SCB_GET_CHANNEL(ahd
, scb
),
1442 SCB_GET_LUN(scb
), SCB_GET_TAG(scb
),
1443 ROLE_INITIATOR
, /*status*/0,
1452 printf("%s: Tracepoint %d\n", ahd_name(ahd
),
1453 seqintcode
- TRACEPOINT0
);
1458 ahd_handle_hwerrint(ahd
);
1461 printf("%s: Unexpected SEQINTCODE %d\n", ahd_name(ahd
),
1466 * The sequencer is paused immediately on
1467 * a SEQINT, so we should restart it when
1474 ahd_handle_scsiint(struct ahd_softc
*ahd
, u_int intstat
)
1485 ahd_update_modes(ahd
);
1486 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
1488 status3
= ahd_inb(ahd
, SSTAT3
) & (NTRAMPERR
|OSRAMPERR
);
1489 status0
= ahd_inb(ahd
, SSTAT0
) & (IOERR
|OVERRUN
|SELDI
|SELDO
);
1490 status
= ahd_inb(ahd
, SSTAT1
) & (SELTO
|SCSIRSTI
|BUSFREE
|SCSIPERR
);
1491 lqistat1
= ahd_inb(ahd
, LQISTAT1
);
1492 lqostat0
= ahd_inb(ahd
, LQOSTAT0
);
1493 busfreetime
= ahd_inb(ahd
, SSTAT2
) & BUSFREETIME
;
1494 if ((status0
& (SELDI
|SELDO
)) != 0) {
1497 ahd_set_modes(ahd
, AHD_MODE_CFG
, AHD_MODE_CFG
);
1498 simode0
= ahd_inb(ahd
, SIMODE0
);
1499 status0
&= simode0
& (IOERR
|OVERRUN
|SELDI
|SELDO
);
1500 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
1502 scbid
= ahd_get_scbptr(ahd
);
1503 scb
= ahd_lookup_scb(ahd
, scbid
);
1505 && (ahd_inb(ahd
, SEQ_FLAGS
) & NOT_IDENTIFIED
) != 0)
1508 /* Make sure the sequencer is in a safe location. */
1509 ahd_clear_critical_section(ahd
);
1511 if ((status0
& IOERR
) != 0) {
1514 now_lvd
= ahd_inb(ahd
, SBLKCTL
) & ENAB40
;
1515 printf("%s: Transceiver State Has Changed to %s mode\n",
1516 ahd_name(ahd
), now_lvd
? "LVD" : "SE");
1517 ahd_outb(ahd
, CLRSINT0
, CLRIOERR
);
1519 * A change in I/O mode is equivalent to a bus reset.
1521 ahd_reset_channel(ahd
, 'A', /*Initiate Reset*/TRUE
);
1523 ahd_setup_iocell_workaround(ahd
);
1525 } else if ((status0
& OVERRUN
) != 0) {
1526 printf("%s: SCSI offset overrun detected. Resetting bus.\n",
1528 ahd_reset_channel(ahd
, 'A', /*Initiate Reset*/TRUE
);
1529 } else if ((status
& SCSIRSTI
) != 0) {
1530 printf("%s: Someone reset channel A\n", ahd_name(ahd
));
1531 ahd_reset_channel(ahd
, 'A', /*Initiate Reset*/FALSE
);
1532 } else if ((status
& SCSIPERR
) != 0) {
1533 ahd_handle_transmission_error(ahd
);
1534 } else if (lqostat0
!= 0) {
1535 printf("%s: lqostat0 == 0x%x!\n", ahd_name(ahd
), lqostat0
);
1536 ahd_outb(ahd
, CLRLQOINT0
, lqostat0
);
1537 if ((ahd
->bugs
& AHD_CLRLQO_AUTOCLR_BUG
) != 0) {
1538 ahd_outb(ahd
, CLRLQOINT1
, 0);
1540 } else if ((status
& SELTO
) != 0) {
1543 /* Stop the selection */
1544 ahd_outb(ahd
, SCSISEQ0
, 0);
1546 /* No more pending messages */
1547 ahd_clear_msg_state(ahd
);
1549 /* Clear interrupt state */
1550 ahd_outb(ahd
, CLRSINT1
, CLRSELTIMEO
|CLRBUSFREE
|CLRSCSIPERR
);
1553 * Although the driver does not care about the
1554 * 'Selection in Progress' status bit, the busy
1555 * LED does. SELINGO is only cleared by a sucessfull
1556 * selection, so we must manually clear it to insure
1557 * the LED turns off just incase no future successful
1558 * selections occur (e.g. no devices on the bus).
1560 ahd_outb(ahd
, CLRSINT0
, CLRSELINGO
);
1562 scbid
= ahd_inw(ahd
, WAITING_TID_HEAD
);
1563 scb
= ahd_lookup_scb(ahd
, scbid
);
1565 printf("%s: ahd_intr - referenced scb not "
1566 "valid during SELTO scb(0x%x)\n",
1567 ahd_name(ahd
), scbid
);
1568 ahd_dump_card_state(ahd
);
1570 struct ahd_devinfo devinfo
;
1572 if ((ahd_debug
& AHD_SHOW_SELTO
) != 0) {
1573 ahd_print_path(ahd
, scb
);
1574 printf("Saw Selection Timeout for SCB 0x%x\n",
1579 * Force a renegotiation with this target just in
1580 * case the cable was pulled and will later be
1581 * re-attached. The target may forget its negotiation
1582 * settings with us should it attempt to reselect
1583 * during the interruption. The target will not issue
1584 * a unit attention in this case, so we must always
1587 ahd_scb_devinfo(ahd
, &devinfo
, scb
);
1588 ahd_force_renegotiation(ahd
, &devinfo
);
1589 ahd_set_transaction_status(scb
, CAM_SEL_TIMEOUT
);
1590 ahd_freeze_devq(ahd
, scb
);
1592 ahd_outb(ahd
, CLRINT
, CLRSCSIINT
);
1593 ahd_iocell_first_selection(ahd
);
1595 } else if ((status0
& (SELDI
|SELDO
)) != 0) {
1596 ahd_iocell_first_selection(ahd
);
1598 } else if (status3
!= 0) {
1599 printf("%s: SCSI Cell parity error SSTAT3 == 0x%x\n",
1600 ahd_name(ahd
), status3
);
1601 ahd_outb(ahd
, CLRSINT3
, status3
);
1602 } else if ((lqistat1
& (LQIPHASE_LQ
|LQIPHASE_NLQ
)) != 0) {
1603 ahd_handle_lqiphase_error(ahd
, lqistat1
);
1604 } else if ((lqistat1
& LQICRCI_NLQ
) != 0) {
1606 * This status can be delayed during some
1607 * streaming operations. The SCSIPHASE
1608 * handler has already dealt with this case
1609 * so just clear the error.
1611 ahd_outb(ahd
, CLRLQIINT1
, CLRLQICRCI_NLQ
);
1612 } else if ((status
& BUSFREE
) != 0) {
1620 * Clear our selection hardware as soon as possible.
1621 * We may have an entry in the waiting Q for this target,
1622 * that is affected by this busfree and we don't want to
1623 * go about selecting the target while we handle the event.
1625 ahd_outb(ahd
, SCSISEQ0
, 0);
1628 * Determine what we were up to at the time of
1631 mode
= AHD_MODE_SCSI
;
1632 busfreetime
= ahd_inb(ahd
, SSTAT2
) & BUSFREETIME
;
1633 lqostat1
= ahd_inb(ahd
, LQOSTAT1
);
1634 switch (busfreetime
) {
1641 mode
= busfreetime
== BUSFREE_DFF0
1642 ? AHD_MODE_DFF0
: AHD_MODE_DFF1
;
1643 ahd_set_modes(ahd
, mode
, mode
);
1644 scbid
= ahd_get_scbptr(ahd
);
1645 scb
= ahd_lookup_scb(ahd
, scbid
);
1647 printf("%s: Invalid SCB %d in DFF%d "
1648 "during unexpected busfree\n",
1649 ahd_name(ahd
), scbid
, mode
);
1652 packetized
= (scb
->flags
& SCB_PACKETIZED
) != 0;
1662 packetized
= (lqostat1
& LQOBUSFREE
) != 0;
1664 && ahd_inb(ahd
, LASTPHASE
) == P_BUSFREE
)
1670 if ((ahd_debug
& AHD_SHOW_MISC
) != 0)
1671 printf("Saw Busfree. Busfreetime = 0x%x.\n",
1675 * Busfrees that occur in non-packetized phases are
1676 * handled by the nonpkt_busfree handler.
1678 if (packetized
&& ahd_inb(ahd
, LASTPHASE
) == P_BUSFREE
) {
1679 restart
= ahd_handle_pkt_busfree(ahd
, busfreetime
);
1682 restart
= ahd_handle_nonpkt_busfree(ahd
);
1685 * Clear the busfree interrupt status. The setting of
1686 * the interrupt is a pulse, so in a perfect world, we
1687 * would not need to muck with the ENBUSFREE logic. This
1688 * would ensure that if the bus moves on to another
1689 * connection, busfree protection is still in force. If
1690 * BUSFREEREV is broken, however, we must manually clear
1691 * the ENBUSFREE if the busfree occurred during a non-pack
1692 * connection so that we don't get false positives during
1693 * future, packetized, connections.
1695 ahd_outb(ahd
, CLRSINT1
, CLRBUSFREE
);
1697 && (ahd
->bugs
& AHD_BUSFREEREV_BUG
) != 0)
1698 ahd_outb(ahd
, SIMODE1
,
1699 ahd_inb(ahd
, SIMODE1
) & ~ENBUSFREE
);
1702 ahd_clear_fifo(ahd
, mode
);
1704 ahd_clear_msg_state(ahd
);
1705 ahd_outb(ahd
, CLRINT
, CLRSCSIINT
);
1712 printf("%s: Missing case in ahd_handle_scsiint. status = %x\n",
1713 ahd_name(ahd
), status
);
1714 ahd_dump_card_state(ahd
);
1715 ahd_clear_intstat(ahd
);
1721 ahd_handle_transmission_error(struct ahd_softc
*ahd
)
1735 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
1736 lqistat1
= ahd_inb(ahd
, LQISTAT1
) & ~(LQIPHASE_LQ
|LQIPHASE_NLQ
);
1737 lqistat2
= ahd_inb(ahd
, LQISTAT2
);
1738 if ((lqistat1
& (LQICRCI_NLQ
|LQICRCI_LQ
)) == 0
1739 && (ahd
->bugs
& AHD_NLQICRC_DELAYED_BUG
) != 0) {
1742 ahd_set_modes(ahd
, AHD_MODE_CFG
, AHD_MODE_CFG
);
1743 lqistate
= ahd_inb(ahd
, LQISTATE
);
1744 if ((lqistate
>= 0x1E && lqistate
<= 0x24)
1745 || (lqistate
== 0x29)) {
1747 if ((ahd_debug
& AHD_SHOW_RECOVERY
) != 0) {
1748 printf("%s: NLQCRC found via LQISTATE\n",
1752 lqistat1
|= LQICRCI_NLQ
;
1754 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
1757 ahd_outb(ahd
, CLRLQIINT1
, lqistat1
);
1758 lastphase
= ahd_inb(ahd
, LASTPHASE
);
1759 curphase
= ahd_inb(ahd
, SCSISIGI
) & PHASE_MASK
;
1760 perrdiag
= ahd_inb(ahd
, PERRDIAG
);
1761 msg_out
= MSG_INITIATOR_DET_ERR
;
1762 ahd_outb(ahd
, CLRSINT1
, CLRSCSIPERR
);
1765 * Try to find the SCB associated with this error.
1769 || (lqistat1
& LQICRCI_NLQ
) != 0) {
1770 if ((lqistat1
& (LQICRCI_NLQ
|LQIOVERI_NLQ
)) != 0)
1771 ahd_set_active_fifo(ahd
);
1772 scbid
= ahd_get_scbptr(ahd
);
1773 scb
= ahd_lookup_scb(ahd
, scbid
);
1774 if (scb
!= NULL
&& SCB_IS_SILENT(scb
))
1779 if (silent
== FALSE
) {
1780 printf("%s: Transmission error detected\n", ahd_name(ahd
));
1781 ahd_lqistat1_print(lqistat1
, &cur_col
, 50);
1782 ahd_lastphase_print(lastphase
, &cur_col
, 50);
1783 ahd_scsisigi_print(curphase
, &cur_col
, 50);
1784 ahd_perrdiag_print(perrdiag
, &cur_col
, 50);
1786 ahd_dump_card_state(ahd
);
1789 if ((lqistat1
& (LQIOVERI_LQ
|LQIOVERI_NLQ
)) != 0) {
1790 if (silent
== FALSE
) {
1791 printf("%s: Gross protocol error during incoming "
1792 "packet. lqistat1 == 0x%x. Resetting bus.\n",
1793 ahd_name(ahd
), lqistat1
);
1795 ahd_reset_channel(ahd
, 'A', /*Initiate Reset*/TRUE
);
1797 } else if ((lqistat1
& LQICRCI_LQ
) != 0) {
1799 * A CRC error has been detected on an incoming LQ.
1800 * The bus is currently hung on the last ACK.
1801 * Hit LQIRETRY to release the last ack, and
1802 * wait for the sequencer to determine that ATNO
1803 * is asserted while in message out to take us
1804 * to our host message loop. No NONPACKREQ or
1805 * LQIPHASE type errors will occur in this
1806 * scenario. After this first LQIRETRY, the LQI
1807 * manager will be in ISELO where it will
1808 * happily sit until another packet phase begins.
1809 * Unexpected bus free detection is enabled
1810 * through any phases that occur after we release
1811 * this last ack until the LQI manager sees a
1812 * packet phase. This implies we may have to
1813 * ignore a perfectly valid "unexected busfree"
1814 * after our "initiator detected error" message is
1815 * sent. A busfree is the expected response after
1816 * we tell the target that it's L_Q was corrupted.
1817 * (SPI4R09 10.7.3.3.3)
1819 ahd_outb(ahd
, LQCTL2
, LQIRETRY
);
1820 printf("LQIRetry for LQICRCI_LQ to release ACK\n");
1821 } else if ((lqistat1
& LQICRCI_NLQ
) != 0) {
1823 * We detected a CRC error in a NON-LQ packet.
1824 * The hardware has varying behavior in this situation
1825 * depending on whether this packet was part of a
1829 * The hardware has already acked the complete packet.
1830 * If the target honors our outstanding ATN condition,
1831 * we should be (or soon will be) in MSGOUT phase.
1832 * This will trigger the LQIPHASE_LQ status bit as the
1833 * hardware was expecting another LQ. Unexpected
1834 * busfree detection is enabled. Once LQIPHASE_LQ is
1835 * true (first entry into host message loop is much
1836 * the same), we must clear LQIPHASE_LQ and hit
1837 * LQIRETRY so the hardware is ready to handle
1838 * a future LQ. NONPACKREQ will not be asserted again
1839 * once we hit LQIRETRY until another packet is
1840 * processed. The target may either go busfree
1841 * or start another packet in response to our message.
1843 * Read Streaming P0 asserted:
1844 * If we raise ATN and the target completes the entire
1845 * stream (P0 asserted during the last packet), the
1846 * hardware will ack all data and return to the ISTART
1847 * state. When the target reponds to our ATN condition,
1848 * LQIPHASE_LQ will be asserted. We should respond to
1849 * this with an LQIRETRY to prepare for any future
1850 * packets. NONPACKREQ will not be asserted again
1851 * once we hit LQIRETRY until another packet is
1852 * processed. The target may either go busfree or
1853 * start another packet in response to our message.
1854 * Busfree detection is enabled.
1856 * Read Streaming P0 not asserted:
1857 * If we raise ATN and the target transitions to
1858 * MSGOUT in or after a packet where P0 is not
1859 * asserted, the hardware will assert LQIPHASE_NLQ.
1860 * We should respond to the LQIPHASE_NLQ with an
1861 * LQIRETRY. Should the target stay in a non-pkt
1862 * phase after we send our message, the hardware
1863 * will assert LQIPHASE_LQ. Recovery is then just as
1864 * listed above for the read streaming with P0 asserted.
1865 * Busfree detection is enabled.
1867 if (silent
== FALSE
)
1868 printf("LQICRC_NLQ\n");
1870 printf("%s: No SCB valid for LQICRC_NLQ. "
1871 "Resetting bus\n", ahd_name(ahd
));
1872 ahd_reset_channel(ahd
, 'A', /*Initiate Reset*/TRUE
);
1875 } else if ((lqistat1
& LQIBADLQI
) != 0) {
1876 printf("Need to handle BADLQI!\n");
1877 ahd_reset_channel(ahd
, 'A', /*Initiate Reset*/TRUE
);
1879 } else if ((perrdiag
& (PARITYERR
|PREVPHASE
)) == PARITYERR
) {
1880 if ((curphase
& ~P_DATAIN_DT
) != 0) {
1881 /* Ack the byte. So we can continue. */
1882 if (silent
== FALSE
)
1883 printf("Acking %s to clear perror\n",
1884 ahd_lookup_phase_entry(curphase
)->phasemsg
);
1885 ahd_inb(ahd
, SCSIDAT
);
1888 if (curphase
== P_MESGIN
)
1889 msg_out
= MSG_PARITY_ERROR
;
1893 * We've set the hardware to assert ATN if we
1894 * get a parity error on "in" phases, so all we
1895 * need to do is stuff the message buffer with
1896 * the appropriate message. "In" phases have set
1897 * mesg_out to something other than MSG_NOP.
1899 ahd
->send_msg_perror
= msg_out
;
1900 if (scb
!= NULL
&& msg_out
== MSG_INITIATOR_DET_ERR
)
1901 scb
->flags
|= SCB_TRANSMISSION_ERROR
;
1902 ahd_outb(ahd
, MSG_OUT
, HOST_MSG
);
1903 ahd_outb(ahd
, CLRINT
, CLRSCSIINT
);
1908 ahd_handle_lqiphase_error(struct ahd_softc
*ahd
, u_int lqistat1
)
1911 * Clear the sources of the interrupts.
1913 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
1914 ahd_outb(ahd
, CLRLQIINT1
, lqistat1
);
1917 * If the "illegal" phase changes were in response
1918 * to our ATN to flag a CRC error, AND we ended up
1919 * on packet boundaries, clear the error, restart the
1920 * LQI manager as appropriate, and go on our merry
1921 * way toward sending the message. Otherwise, reset
1922 * the bus to clear the error.
1924 ahd_set_active_fifo(ahd
);
1925 if ((ahd_inb(ahd
, SCSISIGO
) & ATNO
) != 0
1926 && (ahd_inb(ahd
, MDFFSTAT
) & DLZERO
) != 0) {
1927 if ((lqistat1
& LQIPHASE_LQ
) != 0) {
1928 printf("LQIRETRY for LQIPHASE_LQ\n");
1929 ahd_outb(ahd
, LQCTL2
, LQIRETRY
);
1930 } else if ((lqistat1
& LQIPHASE_NLQ
) != 0) {
1931 printf("LQIRETRY for LQIPHASE_NLQ\n");
1932 ahd_outb(ahd
, LQCTL2
, LQIRETRY
);
1934 panic("ahd_handle_lqiphase_error: No phase errors\n");
1935 ahd_dump_card_state(ahd
);
1936 ahd_outb(ahd
, CLRINT
, CLRSCSIINT
);
1939 printf("Reseting Channel for LQI Phase error\n");
1940 ahd_dump_card_state(ahd
);
1941 ahd_reset_channel(ahd
, 'A', /*Initiate Reset*/TRUE
);
1946 * Packetized unexpected or expected busfree.
1947 * Entered in mode based on busfreetime.
1950 ahd_handle_pkt_busfree(struct ahd_softc
*ahd
, u_int busfreetime
)
1954 AHD_ASSERT_MODES(ahd
, ~(AHD_MODE_UNKNOWN_MSK
|AHD_MODE_CFG_MSK
),
1955 ~(AHD_MODE_UNKNOWN_MSK
|AHD_MODE_CFG_MSK
));
1956 lqostat1
= ahd_inb(ahd
, LQOSTAT1
);
1957 if ((lqostat1
& LQOBUSFREE
) != 0) {
1965 if ((busfreetime
& BUSFREE_LQO
) == 0)
1966 printf("%s: Warning, BUSFREE time is 0x%x. "
1967 "Expected BUSFREE_LQO.\n",
1968 ahd_name(ahd
), busfreetime
);
1970 * The LQO manager detected an unexpected busfree
1973 * 1) During an outgoing LQ.
1974 * 2) After an outgoing LQ but before the first
1975 * REQ of the command packet.
1976 * 3) During an outgoing command packet.
1978 * In all cases, CURRSCB is pointing to the
1979 * SCB that encountered the failure. Clean
1980 * up the queue, clear SELDO and LQOBUSFREE,
1981 * and allow the sequencer to restart the select
1982 * out at its lesure.
1984 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
1985 scbid
= ahd_inw(ahd
, CURRSCB
);
1986 scb
= ahd_lookup_scb(ahd
, scbid
);
1988 panic("SCB not valid during LQOBUSFREE");
1992 ahd_outb(ahd
, CLRLQOINT1
, CLRLQOBUSFREE
);
1993 if ((ahd
->bugs
& AHD_CLRLQO_AUTOCLR_BUG
) != 0)
1994 ahd_outb(ahd
, CLRLQOINT1
, 0);
1995 ahd_outb(ahd
, SCSISEQ0
, ahd_inb(ahd
, SCSISEQ0
) & ~ENSELO
);
1996 ahd_flush_device_writes(ahd
);
1997 ahd_outb(ahd
, CLRSINT0
, CLRSELDO
);
2000 * Return the LQO manager to its idle loop. It will
2001 * not do this automatically if the busfree occurs
2002 * after the first REQ of either the LQ or command
2003 * packet or between the LQ and command packet.
2005 ahd_outb(ahd
, LQCTL2
, ahd_inb(ahd
, LQCTL2
) | LQOTOIDLE
);
2008 * Update the waiting for selection queue so
2009 * we restart on the correct SCB.
2011 waiting_h
= ahd_inw(ahd
, WAITING_TID_HEAD
);
2012 saved_scbptr
= ahd_get_scbptr(ahd
);
2013 if (waiting_h
!= scbid
) {
2015 ahd_outw(ahd
, WAITING_TID_HEAD
, scbid
);
2016 waiting_t
= ahd_inw(ahd
, WAITING_TID_TAIL
);
2017 if (waiting_t
== waiting_h
) {
2018 ahd_outw(ahd
, WAITING_TID_TAIL
, scbid
);
2019 next
= SCB_LIST_NULL
;
2021 ahd_set_scbptr(ahd
, waiting_h
);
2022 next
= ahd_inw_scbram(ahd
, SCB_NEXT2
);
2024 ahd_set_scbptr(ahd
, scbid
);
2025 ahd_outw(ahd
, SCB_NEXT2
, next
);
2027 ahd_set_scbptr(ahd
, saved_scbptr
);
2028 if (scb
->crc_retry_count
< AHD_MAX_LQ_CRC_ERRORS
) {
2029 if (SCB_IS_SILENT(scb
) == FALSE
) {
2030 ahd_print_path(ahd
, scb
);
2031 printf("Probable outgoing LQ CRC error. "
2032 "Retrying command\n");
2034 scb
->crc_retry_count
++;
2036 ahd_set_transaction_status(scb
, CAM_UNCOR_PARITY
);
2037 ahd_freeze_scb(scb
);
2038 ahd_freeze_devq(ahd
, scb
);
2040 /* Return unpausing the sequencer. */
2042 } else if ((ahd_inb(ahd
, PERRDIAG
) & PARITYERR
) != 0) {
2044 * Ignore what are really parity errors that
2045 * occur on the last REQ of a free running
2046 * clock prior to going busfree. Some drives
2047 * do not properly active negate just before
2048 * going busfree resulting in a parity glitch.
2050 ahd_outb(ahd
, CLRSINT1
, CLRSCSIPERR
|CLRBUSFREE
);
2052 if ((ahd_debug
& AHD_SHOW_MASKED_ERRORS
) != 0)
2053 printf("%s: Parity on last REQ detected "
2054 "during busfree phase.\n",
2057 /* Return unpausing the sequencer. */
2060 if (ahd
->src_mode
!= AHD_MODE_SCSI
) {
2064 scbid
= ahd_get_scbptr(ahd
);
2065 scb
= ahd_lookup_scb(ahd
, scbid
);
2066 ahd_print_path(ahd
, scb
);
2067 printf("Unexpected PKT busfree condition\n");
2068 ahd_dump_card_state(ahd
);
2069 ahd_abort_scbs(ahd
, SCB_GET_TARGET(ahd
, scb
), 'A',
2070 SCB_GET_LUN(scb
), SCB_GET_TAG(scb
),
2071 ROLE_INITIATOR
, CAM_UNEXP_BUSFREE
);
2073 /* Return restarting the sequencer. */
2076 printf("%s: Unexpected PKT busfree condition\n", ahd_name(ahd
));
2077 ahd_dump_card_state(ahd
);
2078 /* Restart the sequencer. */
2083 * Non-packetized unexpected or expected busfree.
2086 ahd_handle_nonpkt_busfree(struct ahd_softc
*ahd
)
2088 struct ahd_devinfo devinfo
;
2094 u_int initiator_role_id
;
2100 * Look at what phase we were last in. If its message out,
2101 * chances are pretty good that the busfree was in response
2102 * to one of our abort requests.
2104 lastphase
= ahd_inb(ahd
, LASTPHASE
);
2105 saved_scsiid
= ahd_inb(ahd
, SAVED_SCSIID
);
2106 saved_lun
= ahd_inb(ahd
, SAVED_LUN
);
2107 target
= SCSIID_TARGET(ahd
, saved_scsiid
);
2108 initiator_role_id
= SCSIID_OUR_ID(saved_scsiid
);
2109 ahd_compile_devinfo(&devinfo
, initiator_role_id
,
2110 target
, saved_lun
, 'A', ROLE_INITIATOR
);
2113 scbid
= ahd_get_scbptr(ahd
);
2114 scb
= ahd_lookup_scb(ahd
, scbid
);
2116 && (ahd_inb(ahd
, SEQ_FLAGS
) & NOT_IDENTIFIED
) != 0)
2119 ppr_busfree
= (ahd
->msg_flags
& MSG_FLAG_EXPECT_PPR_BUSFREE
) != 0;
2120 if (lastphase
== P_MESGOUT
) {
2123 tag
= SCB_LIST_NULL
;
2124 if (ahd_sent_msg(ahd
, AHDMSG_1B
, MSG_ABORT_TAG
, TRUE
)
2125 || ahd_sent_msg(ahd
, AHDMSG_1B
, MSG_ABORT
, TRUE
)) {
2130 ahd_print_devinfo(ahd
, &devinfo
);
2131 printf("Abort for unidentified "
2132 "connection completed.\n");
2133 /* restart the sequencer. */
2136 sent_msg
= ahd
->msgout_buf
[ahd
->msgout_index
- 1];
2137 ahd_print_path(ahd
, scb
);
2138 printf("SCB %d - Abort%s Completed.\n",
2140 sent_msg
== MSG_ABORT_TAG
? "" : " Tag");
2142 if (sent_msg
== MSG_ABORT_TAG
)
2143 tag
= SCB_GET_TAG(scb
);
2145 if ((scb
->flags
& SCB_CMDPHASE_ABORT
) != 0) {
2147 * This abort is in response to an
2148 * unexpected switch to command phase
2149 * for a packetized connection. Since
2150 * the identify message was never sent,
2151 * "saved lun" is 0. We really want to
2152 * abort only the SCB that encountered
2153 * this error, which could have a different
2154 * lun. The SCB will be retried so the OS
2155 * will see the UA after renegotiating to
2158 tag
= SCB_GET_TAG(scb
);
2159 saved_lun
= scb
->hscb
->lun
;
2161 found
= ahd_abort_scbs(ahd
, target
, 'A', saved_lun
,
2162 tag
, ROLE_INITIATOR
,
2164 printf("found == 0x%x\n", found
);
2166 } else if (ahd_sent_msg(ahd
, AHDMSG_1B
,
2167 MSG_BUS_DEV_RESET
, TRUE
)) {
2170 * Don't mark the user's request for this BDR
2171 * as completing with CAM_BDR_SENT. CAM3
2172 * specifies CAM_REQ_CMP.
2175 && scb
->io_ctx
->ccb_h
.func_code
== XPT_RESET_DEV
2176 && ahd_match_scb(ahd
, scb
, target
, 'A',
2177 CAM_LUN_WILDCARD
, SCB_LIST_NULL
,
2179 ahd_set_transaction_status(scb
, CAM_REQ_CMP
);
2181 ahd_handle_devreset(ahd
, &devinfo
, CAM_LUN_WILDCARD
,
2182 CAM_BDR_SENT
, "Bus Device Reset",
2183 /*verbose_level*/0);
2185 } else if (ahd_sent_msg(ahd
, AHDMSG_EXT
, MSG_EXT_PPR
, FALSE
)
2186 && ppr_busfree
== 0) {
2187 struct ahd_initiator_tinfo
*tinfo
;
2188 struct ahd_tmode_tstate
*tstate
;
2191 * PPR Rejected. Try non-ppr negotiation
2192 * and retry command.
2195 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
2196 printf("PPR negotiation rejected busfree.\n");
2198 tinfo
= ahd_fetch_transinfo(ahd
, devinfo
.channel
,
2200 devinfo
.target
, &tstate
);
2201 tinfo
->curr
.transport_version
= 2;
2202 tinfo
->goal
.transport_version
= 2;
2203 tinfo
->goal
.ppr_options
= 0;
2204 ahd_qinfifo_requeue_tail(ahd
, scb
);
2206 } else if (ahd_sent_msg(ahd
, AHDMSG_EXT
, MSG_EXT_WDTR
, FALSE
)
2207 && ppr_busfree
== 0) {
2209 * Negotiation Rejected. Go-narrow and
2213 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
2214 printf("WDTR negotiation rejected busfree.\n");
2216 ahd_set_width(ahd
, &devinfo
,
2217 MSG_EXT_WDTR_BUS_8_BIT
,
2218 AHD_TRANS_CUR
|AHD_TRANS_GOAL
,
2220 ahd_qinfifo_requeue_tail(ahd
, scb
);
2222 } else if (ahd_sent_msg(ahd
, AHDMSG_EXT
, MSG_EXT_SDTR
, FALSE
)
2223 && ppr_busfree
== 0) {
2225 * Negotiation Rejected. Go-async and
2229 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
2230 printf("SDTR negotiation rejected busfree.\n");
2232 ahd_set_syncrate(ahd
, &devinfo
,
2233 /*period*/0, /*offset*/0,
2235 AHD_TRANS_CUR
|AHD_TRANS_GOAL
,
2237 ahd_qinfifo_requeue_tail(ahd
, scb
);
2239 } else if ((ahd
->msg_flags
& MSG_FLAG_EXPECT_IDE_BUSFREE
) != 0
2240 && ahd_sent_msg(ahd
, AHDMSG_1B
,
2241 MSG_INITIATOR_DET_ERR
, TRUE
)) {
2244 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
2245 printf("Expected IDE Busfree\n");
2248 } else if ((ahd
->msg_flags
& MSG_FLAG_EXPECT_QASREJ_BUSFREE
)
2249 && ahd_sent_msg(ahd
, AHDMSG_1B
,
2250 MSG_MESSAGE_REJECT
, TRUE
)) {
2253 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
2254 printf("Expected QAS Reject Busfree\n");
2261 * The busfree required flag is honored at the end of
2262 * the message phases. We check it last in case we
2263 * had to send some other message that caused a busfree.
2266 && (lastphase
== P_MESGIN
|| lastphase
== P_MESGOUT
)
2267 && ((ahd
->msg_flags
& MSG_FLAG_EXPECT_PPR_BUSFREE
) != 0)) {
2269 ahd_freeze_devq(ahd
, scb
);
2270 ahd_set_transaction_status(scb
, CAM_REQUEUE_REQ
);
2271 ahd_freeze_scb(scb
);
2272 if ((ahd
->msg_flags
& MSG_FLAG_IU_REQ_CHANGED
) != 0) {
2273 ahd_abort_scbs(ahd
, SCB_GET_TARGET(ahd
, scb
),
2274 SCB_GET_CHANNEL(ahd
, scb
),
2275 SCB_GET_LUN(scb
), SCB_LIST_NULL
,
2276 ROLE_INITIATOR
, CAM_REQ_ABORTED
);
2279 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
2280 printf("PPR Negotiation Busfree.\n");
2286 if (printerror
!= 0) {
2293 if ((scb
->hscb
->control
& TAG_ENB
) != 0)
2294 tag
= SCB_GET_TAG(scb
);
2296 tag
= SCB_LIST_NULL
;
2297 ahd_print_path(ahd
, scb
);
2298 aborted
= ahd_abort_scbs(ahd
, target
, 'A',
2299 SCB_GET_LUN(scb
), tag
,
2304 * We had not fully identified this connection,
2305 * so we cannot abort anything.
2307 printf("%s: ", ahd_name(ahd
));
2309 if (lastphase
!= P_BUSFREE
)
2310 ahd_force_renegotiation(ahd
, &devinfo
);
2311 printf("Unexpected busfree %s, %d SCBs aborted, "
2312 "PRGMCNT == 0x%x\n",
2313 ahd_lookup_phase_entry(lastphase
)->phasemsg
,
2315 ahd_inb(ahd
, PRGMCNT
)
2316 | (ahd_inb(ahd
, PRGMCNT
+1) << 8));
2317 ahd_dump_card_state(ahd
);
2319 /* Always restart the sequencer. */
2324 ahd_handle_proto_violation(struct ahd_softc
*ahd
)
2326 struct ahd_devinfo devinfo
;
2334 ahd_fetch_devinfo(ahd
, &devinfo
);
2335 scbid
= ahd_get_scbptr(ahd
);
2336 scb
= ahd_lookup_scb(ahd
, scbid
);
2337 seq_flags
= ahd_inb(ahd
, SEQ_FLAGS
);
2338 curphase
= ahd_inb(ahd
, SCSISIGI
) & PHASE_MASK
;
2339 lastphase
= ahd_inb(ahd
, LASTPHASE
);
2340 if ((seq_flags
& NOT_IDENTIFIED
) != 0) {
2343 * The reconnecting target either did not send an
2344 * identify message, or did, but we didn't find an SCB
2347 ahd_print_devinfo(ahd
, &devinfo
);
2348 printf("Target did not send an IDENTIFY message. "
2349 "LASTPHASE = 0x%x.\n", lastphase
);
2351 } else if (scb
== NULL
) {
2353 * We don't seem to have an SCB active for this
2354 * transaction. Print an error and reset the bus.
2356 ahd_print_devinfo(ahd
, &devinfo
);
2357 printf("No SCB found during protocol violation\n");
2358 goto proto_violation_reset
;
2360 ahd_set_transaction_status(scb
, CAM_SEQUENCE_FAIL
);
2361 if ((seq_flags
& NO_CDB_SENT
) != 0) {
2362 ahd_print_path(ahd
, scb
);
2363 printf("No or incomplete CDB sent to device.\n");
2364 } else if ((ahd_inb_scbram(ahd
, SCB_CONTROL
)
2365 & STATUS_RCVD
) == 0) {
2367 * The target never bothered to provide status to
2368 * us prior to completing the command. Since we don't
2369 * know the disposition of this command, we must attempt
2370 * to abort it. Assert ATN and prepare to send an abort
2373 ahd_print_path(ahd
, scb
);
2374 printf("Completed command without status.\n");
2376 ahd_print_path(ahd
, scb
);
2377 printf("Unknown protocol violation.\n");
2378 ahd_dump_card_state(ahd
);
2381 if ((lastphase
& ~P_DATAIN_DT
) == 0
2382 || lastphase
== P_COMMAND
) {
2383 proto_violation_reset
:
2385 * Target either went directly to data
2386 * phase or didn't respond to our ATN.
2387 * The only safe thing to do is to blow
2388 * it away with a bus reset.
2390 found
= ahd_reset_channel(ahd
, 'A', TRUE
);
2391 printf("%s: Issued Channel %c Bus Reset. "
2392 "%d SCBs aborted\n", ahd_name(ahd
), 'A', found
);
2395 * Leave the selection hardware off in case
2396 * this abort attempt will affect yet to
2399 ahd_outb(ahd
, SCSISEQ0
,
2400 ahd_inb(ahd
, SCSISEQ0
) & ~ENSELO
);
2401 ahd_assert_atn(ahd
);
2402 ahd_outb(ahd
, MSG_OUT
, HOST_MSG
);
2404 ahd_print_devinfo(ahd
, &devinfo
);
2405 ahd
->msgout_buf
[0] = MSG_ABORT_TASK
;
2406 ahd
->msgout_len
= 1;
2407 ahd
->msgout_index
= 0;
2408 ahd
->msg_type
= MSG_TYPE_INITIATOR_MSGOUT
;
2410 ahd_print_path(ahd
, scb
);
2411 scb
->flags
|= SCB_ABORT
;
2413 printf("Protocol violation %s. Attempting to abort.\n",
2414 ahd_lookup_phase_entry(curphase
)->phasemsg
);
2419 * Force renegotiation to occur the next time we initiate
2420 * a command to the current device.
2423 ahd_force_renegotiation(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
)
2425 struct ahd_initiator_tinfo
*targ_info
;
2426 struct ahd_tmode_tstate
*tstate
;
2429 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0) {
2430 ahd_print_devinfo(ahd
, devinfo
);
2431 printf("Forcing renegotiation\n");
2434 targ_info
= ahd_fetch_transinfo(ahd
,
2436 devinfo
->our_scsiid
,
2439 ahd_update_neg_request(ahd
, devinfo
, tstate
,
2440 targ_info
, AHD_NEG_IF_NON_ASYNC
);
2443 #define AHD_MAX_STEPS 2000
2445 ahd_clear_critical_section(struct ahd_softc
*ahd
)
2447 ahd_mode_state saved_modes
;
2459 if (ahd
->num_critical_sections
== 0)
2472 saved_modes
= ahd_save_modes(ahd
);
2478 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
2479 seqaddr
= ahd_inb(ahd
, CURADDR
)
2480 | (ahd_inb(ahd
, CURADDR
+1) << 8);
2482 cs
= ahd
->critical_sections
;
2483 for (i
= 0; i
< ahd
->num_critical_sections
; i
++, cs
++) {
2485 if (cs
->begin
< seqaddr
&& cs
->end
>= seqaddr
)
2489 if (i
== ahd
->num_critical_sections
)
2492 if (steps
> AHD_MAX_STEPS
) {
2493 printf("%s: Infinite loop in critical section\n"
2494 "%s: First Instruction 0x%x now 0x%x\n",
2495 ahd_name(ahd
), ahd_name(ahd
), first_instr
,
2497 ahd_dump_card_state(ahd
);
2498 panic("critical section loop");
2503 if ((ahd_debug
& AHD_SHOW_MISC
) != 0)
2504 printf("%s: Single stepping at 0x%x\n", ahd_name(ahd
),
2507 if (stepping
== FALSE
) {
2509 first_instr
= seqaddr
;
2510 ahd_set_modes(ahd
, AHD_MODE_CFG
, AHD_MODE_CFG
);
2511 simode0
= ahd_inb(ahd
, SIMODE0
);
2512 simode3
= ahd_inb(ahd
, SIMODE3
);
2513 lqimode0
= ahd_inb(ahd
, LQIMODE0
);
2514 lqimode1
= ahd_inb(ahd
, LQIMODE1
);
2515 lqomode0
= ahd_inb(ahd
, LQOMODE0
);
2516 lqomode1
= ahd_inb(ahd
, LQOMODE1
);
2517 ahd_outb(ahd
, SIMODE0
, 0);
2518 ahd_outb(ahd
, SIMODE3
, 0);
2519 ahd_outb(ahd
, LQIMODE0
, 0);
2520 ahd_outb(ahd
, LQIMODE1
, 0);
2521 ahd_outb(ahd
, LQOMODE0
, 0);
2522 ahd_outb(ahd
, LQOMODE1
, 0);
2523 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
2524 simode1
= ahd_inb(ahd
, SIMODE1
);
2526 * We don't clear ENBUSFREE. Unfortunately
2527 * we cannot re-enable busfree detection within
2528 * the current connection, so we must leave it
2529 * on while single stepping.
2531 ahd_outb(ahd
, SIMODE1
, simode1
& ENBUSFREE
);
2532 ahd_outb(ahd
, SEQCTL0
, ahd_inb(ahd
, SEQCTL0
) | STEP
);
2535 ahd_outb(ahd
, CLRSINT1
, CLRBUSFREE
);
2536 ahd_outb(ahd
, CLRINT
, CLRSCSIINT
);
2537 ahd_set_modes(ahd
, ahd
->saved_src_mode
, ahd
->saved_dst_mode
);
2538 ahd_outb(ahd
, HCNTRL
, ahd
->unpause
);
2539 while (!ahd_is_paused(ahd
))
2541 ahd_update_modes(ahd
);
2544 ahd_set_modes(ahd
, AHD_MODE_CFG
, AHD_MODE_CFG
);
2545 ahd_outb(ahd
, SIMODE0
, simode0
);
2546 ahd_outb(ahd
, SIMODE3
, simode3
);
2547 ahd_outb(ahd
, LQIMODE0
, lqimode0
);
2548 ahd_outb(ahd
, LQIMODE1
, lqimode1
);
2549 ahd_outb(ahd
, LQOMODE0
, lqomode0
);
2550 ahd_outb(ahd
, LQOMODE1
, lqomode1
);
2551 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
2552 ahd_outb(ahd
, SEQCTL0
, ahd_inb(ahd
, SEQCTL0
) & ~STEP
);
2553 ahd_outb(ahd
, SIMODE1
, simode1
);
2555 * SCSIINT seems to glitch occassionally when
2556 * the interrupt masks are restored. Clear SCSIINT
2557 * one more time so that only persistent errors
2558 * are seen as a real interrupt.
2560 ahd_outb(ahd
, CLRINT
, CLRSCSIINT
);
2562 ahd_restore_modes(ahd
, saved_modes
);
2566 * Clear any pending interrupt status.
2569 ahd_clear_intstat(struct ahd_softc
*ahd
)
2571 AHD_ASSERT_MODES(ahd
, ~(AHD_MODE_UNKNOWN_MSK
|AHD_MODE_CFG_MSK
),
2572 ~(AHD_MODE_UNKNOWN_MSK
|AHD_MODE_CFG_MSK
));
2573 /* Clear any interrupt conditions this may have caused */
2574 ahd_outb(ahd
, CLRLQIINT0
, CLRLQIATNQAS
|CLRLQICRCT1
|CLRLQICRCT2
2575 |CLRLQIBADLQT
|CLRLQIATNLQ
|CLRLQIATNCMD
);
2576 ahd_outb(ahd
, CLRLQIINT1
, CLRLQIPHASE_LQ
|CLRLQIPHASE_NLQ
|CLRLIQABORT
2577 |CLRLQICRCI_LQ
|CLRLQICRCI_NLQ
|CLRLQIBADLQI
2578 |CLRLQIOVERI_LQ
|CLRLQIOVERI_NLQ
|CLRNONPACKREQ
);
2579 ahd_outb(ahd
, CLRLQOINT0
, CLRLQOTARGSCBPERR
|CLRLQOSTOPT2
|CLRLQOATNLQ
2580 |CLRLQOATNPKT
|CLRLQOTCRC
);
2581 ahd_outb(ahd
, CLRLQOINT1
, CLRLQOINITSCBPERR
|CLRLQOSTOPI2
|CLRLQOBADQAS
2582 |CLRLQOBUSFREE
|CLRLQOPHACHGINPKT
);
2583 if ((ahd
->bugs
& AHD_CLRLQO_AUTOCLR_BUG
) != 0) {
2584 ahd_outb(ahd
, CLRLQOINT0
, 0);
2585 ahd_outb(ahd
, CLRLQOINT1
, 0);
2587 ahd_outb(ahd
, CLRSINT3
, CLRNTRAMPERR
|CLROSRAMPERR
);
2588 ahd_outb(ahd
, CLRSINT1
, CLRSELTIMEO
|CLRATNO
|CLRSCSIRSTI
2589 |CLRBUSFREE
|CLRSCSIPERR
|CLRREQINIT
);
2590 ahd_outb(ahd
, CLRSINT0
, CLRSELDO
|CLRSELDI
|CLRSELINGO
2591 |CLRIOERR
|CLROVERRUN
);
2592 ahd_outb(ahd
, CLRINT
, CLRSCSIINT
);
2595 /**************************** Debugging Routines ******************************/
2597 uint32_t ahd_debug
= AHD_DEBUG_OPTS
;
2600 ahd_print_scb(struct scb
*scb
)
2602 struct hardware_scb
*hscb
;
2606 printf("scb:%p control:0x%x scsiid:0x%x lun:%d cdb_len:%d\n",
2612 printf("Shared Data: ");
2613 for (i
= 0; i
< sizeof(hscb
->shared_data
.idata
.cdb
); i
++)
2614 printf("%#02x", hscb
->shared_data
.idata
.cdb
[i
]);
2615 printf(" dataptr:%#x%x datacnt:%#x sgptr:%#x tag:%#x\n",
2616 (uint32_t)((ahd_le64toh(hscb
->dataptr
) >> 32) & 0xFFFFFFFF),
2617 (uint32_t)(ahd_le64toh(hscb
->dataptr
) & 0xFFFFFFFF),
2618 ahd_le32toh(hscb
->datacnt
),
2619 ahd_le32toh(hscb
->sgptr
),
2621 ahd_dump_sglist(scb
);
2625 ahd_dump_sglist(struct scb
*scb
)
2629 if (scb
->sg_count
> 0) {
2630 if ((scb
->ahd_softc
->flags
& AHD_64BIT_ADDRESSING
) != 0) {
2631 struct ahd_dma64_seg
*sg_list
;
2633 sg_list
= (struct ahd_dma64_seg
*)scb
->sg_list
;
2634 for (i
= 0; i
< scb
->sg_count
; i
++) {
2638 addr
= ahd_le64toh(sg_list
[i
].addr
);
2639 len
= ahd_le32toh(sg_list
[i
].len
);
2640 printf("sg[%d] - Addr 0x%x%x : Length %d%s\n",
2642 (uint32_t)((addr
>> 32) & 0xFFFFFFFF),
2643 (uint32_t)(addr
& 0xFFFFFFFF),
2644 sg_list
[i
].len
& AHD_SG_LEN_MASK
,
2645 (sg_list
[i
].len
& AHD_DMA_LAST_SEG
)
2649 struct ahd_dma_seg
*sg_list
;
2651 sg_list
= (struct ahd_dma_seg
*)scb
->sg_list
;
2652 for (i
= 0; i
< scb
->sg_count
; i
++) {
2655 len
= ahd_le32toh(sg_list
[i
].len
);
2656 printf("sg[%d] - Addr 0x%x%x : Length %d%s\n",
2658 (len
& AHD_SG_HIGH_ADDR_MASK
) >> 24,
2659 ahd_le32toh(sg_list
[i
].addr
),
2660 len
& AHD_SG_LEN_MASK
,
2661 len
& AHD_DMA_LAST_SEG
? " Last" : "");
2667 /************************* Transfer Negotiation *******************************/
2669 * Allocate per target mode instance (ID we respond to as a target)
2670 * transfer negotiation data structures.
2672 static struct ahd_tmode_tstate
*
2673 ahd_alloc_tstate(struct ahd_softc
*ahd
, u_int scsi_id
, char channel
)
2675 struct ahd_tmode_tstate
*master_tstate
;
2676 struct ahd_tmode_tstate
*tstate
;
2679 master_tstate
= ahd
->enabled_targets
[ahd
->our_id
];
2680 if (ahd
->enabled_targets
[scsi_id
] != NULL
2681 && ahd
->enabled_targets
[scsi_id
] != master_tstate
)
2682 panic("%s: ahd_alloc_tstate - Target already allocated",
2684 tstate
= malloc(sizeof(*tstate
), M_DEVBUF
, M_NOWAIT
);
2689 * If we have allocated a master tstate, copy user settings from
2690 * the master tstate (taken from SRAM or the EEPROM) for this
2691 * channel, but reset our current and goal settings to async/narrow
2692 * until an initiator talks to us.
2694 if (master_tstate
!= NULL
) {
2695 memcpy(tstate
, master_tstate
, sizeof(*tstate
));
2696 memset(tstate
->enabled_luns
, 0, sizeof(tstate
->enabled_luns
));
2697 for (i
= 0; i
< 16; i
++) {
2698 memset(&tstate
->transinfo
[i
].curr
, 0,
2699 sizeof(tstate
->transinfo
[i
].curr
));
2700 memset(&tstate
->transinfo
[i
].goal
, 0,
2701 sizeof(tstate
->transinfo
[i
].goal
));
2704 memset(tstate
, 0, sizeof(*tstate
));
2705 ahd
->enabled_targets
[scsi_id
] = tstate
;
2709 #ifdef AHD_TARGET_MODE
2711 * Free per target mode instance (ID we respond to as a target)
2712 * transfer negotiation data structures.
2715 ahd_free_tstate(struct ahd_softc
*ahd
, u_int scsi_id
, char channel
, int force
)
2717 struct ahd_tmode_tstate
*tstate
;
2720 * Don't clean up our "master" tstate.
2721 * It has our default user settings.
2723 if (scsi_id
== ahd
->our_id
2727 tstate
= ahd
->enabled_targets
[scsi_id
];
2729 free(tstate
, M_DEVBUF
);
2730 ahd
->enabled_targets
[scsi_id
] = NULL
;
2735 * Called when we have an active connection to a target on the bus,
2736 * this function finds the nearest period to the input period limited
2737 * by the capabilities of the bus connectivity of and sync settings for
2741 ahd_devlimited_syncrate(struct ahd_softc
*ahd
,
2742 struct ahd_initiator_tinfo
*tinfo
,
2743 u_int
*period
, u_int
*ppr_options
, role_t role
)
2745 struct ahd_transinfo
*transinfo
;
2748 if ((ahd_inb(ahd
, SBLKCTL
) & ENAB40
) != 0
2749 && (ahd_inb(ahd
, SSTAT2
) & EXP_ACTIVE
) == 0) {
2750 maxsync
= AHD_SYNCRATE_PACED
;
2752 maxsync
= AHD_SYNCRATE_ULTRA
;
2753 /* Can't do DT related options on an SE bus */
2754 *ppr_options
&= MSG_EXT_PPR_QAS_REQ
;
2757 * Never allow a value higher than our current goal
2758 * period otherwise we may allow a target initiated
2759 * negotiation to go above the limit as set by the
2760 * user. In the case of an initiator initiated
2761 * sync negotiation, we limit based on the user
2762 * setting. This allows the system to still accept
2763 * incoming negotiations even if target initiated
2764 * negotiation is not performed.
2766 if (role
== ROLE_TARGET
)
2767 transinfo
= &tinfo
->user
;
2769 transinfo
= &tinfo
->goal
;
2770 *ppr_options
&= (transinfo
->ppr_options
|MSG_EXT_PPR_PCOMP_EN
);
2771 if (transinfo
->width
== MSG_EXT_WDTR_BUS_8_BIT
) {
2772 maxsync
= MAX(maxsync
, AHD_SYNCRATE_ULTRA2
);
2773 *ppr_options
&= ~MSG_EXT_PPR_DT_REQ
;
2775 if (transinfo
->period
== 0) {
2779 *period
= MAX(*period
, transinfo
->period
);
2780 ahd_find_syncrate(ahd
, period
, ppr_options
, maxsync
);
2785 * Look up the valid period to SCSIRATE conversion in our table.
2786 * Return the period and offset that should be sent to the target
2787 * if this was the beginning of an SDTR.
2790 ahd_find_syncrate(struct ahd_softc
*ahd
, u_int
*period
,
2791 u_int
*ppr_options
, u_int maxsync
)
2793 if (*period
< maxsync
)
2796 if ((*ppr_options
& MSG_EXT_PPR_DT_REQ
) != 0
2797 && *period
> AHD_SYNCRATE_MIN_DT
)
2798 *ppr_options
&= ~MSG_EXT_PPR_DT_REQ
;
2800 if (*period
> AHD_SYNCRATE_MIN
)
2803 /* Honor PPR option conformance rules. */
2804 if (*period
> AHD_SYNCRATE_PACED
)
2805 *ppr_options
&= ~MSG_EXT_PPR_RTI
;
2807 if ((*ppr_options
& MSG_EXT_PPR_IU_REQ
) == 0)
2808 *ppr_options
&= (MSG_EXT_PPR_DT_REQ
|MSG_EXT_PPR_QAS_REQ
);
2810 if ((*ppr_options
& MSG_EXT_PPR_DT_REQ
) == 0)
2811 *ppr_options
&= MSG_EXT_PPR_QAS_REQ
;
2813 /* Skip all PACED only entries if IU is not available */
2814 if ((*ppr_options
& MSG_EXT_PPR_IU_REQ
) == 0
2815 && *period
< AHD_SYNCRATE_DT
)
2816 *period
= AHD_SYNCRATE_DT
;
2818 /* Skip all DT only entries if DT is not available */
2819 if ((*ppr_options
& MSG_EXT_PPR_DT_REQ
) == 0
2820 && *period
< AHD_SYNCRATE_ULTRA2
)
2821 *period
= AHD_SYNCRATE_ULTRA2
;
2825 * Truncate the given synchronous offset to a value the
2826 * current adapter type and syncrate are capable of.
2829 ahd_validate_offset(struct ahd_softc
*ahd
,
2830 struct ahd_initiator_tinfo
*tinfo
,
2831 u_int period
, u_int
*offset
, int wide
,
2836 /* Limit offset to what we can do */
2839 else if (period
<= AHD_SYNCRATE_PACED
) {
2840 if ((ahd
->bugs
& AHD_PACED_NEGTABLE_BUG
) != 0)
2841 maxoffset
= MAX_OFFSET_PACED_BUG
;
2843 maxoffset
= MAX_OFFSET_PACED
;
2845 maxoffset
= MAX_OFFSET_NON_PACED
;
2846 *offset
= MIN(*offset
, maxoffset
);
2847 if (tinfo
!= NULL
) {
2848 if (role
== ROLE_TARGET
)
2849 *offset
= MIN(*offset
, tinfo
->user
.offset
);
2851 *offset
= MIN(*offset
, tinfo
->goal
.offset
);
2856 * Truncate the given transfer width parameter to a value the
2857 * current adapter type is capable of.
2860 ahd_validate_width(struct ahd_softc
*ahd
, struct ahd_initiator_tinfo
*tinfo
,
2861 u_int
*bus_width
, role_t role
)
2863 switch (*bus_width
) {
2865 if (ahd
->features
& AHD_WIDE
) {
2867 *bus_width
= MSG_EXT_WDTR_BUS_16_BIT
;
2871 case MSG_EXT_WDTR_BUS_8_BIT
:
2872 *bus_width
= MSG_EXT_WDTR_BUS_8_BIT
;
2875 if (tinfo
!= NULL
) {
2876 if (role
== ROLE_TARGET
)
2877 *bus_width
= MIN(tinfo
->user
.width
, *bus_width
);
2879 *bus_width
= MIN(tinfo
->goal
.width
, *bus_width
);
2884 * Update the bitmask of targets for which the controller should
2885 * negotiate with at the next convenient oportunity. This currently
2886 * means the next time we send the initial identify messages for
2887 * a new transaction.
2890 ahd_update_neg_request(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
,
2891 struct ahd_tmode_tstate
*tstate
,
2892 struct ahd_initiator_tinfo
*tinfo
, ahd_neg_type neg_type
)
2894 u_int auto_negotiate_orig
;
2896 auto_negotiate_orig
= tstate
->auto_negotiate
;
2897 if (neg_type
== AHD_NEG_ALWAYS
) {
2899 * Force our "current" settings to be
2900 * unknown so that unless a bus reset
2901 * occurs the need to renegotiate is
2902 * recorded persistently.
2904 if ((ahd
->features
& AHD_WIDE
) != 0)
2905 tinfo
->curr
.width
= AHD_WIDTH_UNKNOWN
;
2906 tinfo
->curr
.period
= AHD_PERIOD_UNKNOWN
;
2907 tinfo
->curr
.offset
= AHD_OFFSET_UNKNOWN
;
2909 if (tinfo
->curr
.period
!= tinfo
->goal
.period
2910 || tinfo
->curr
.width
!= tinfo
->goal
.width
2911 || tinfo
->curr
.offset
!= tinfo
->goal
.offset
2912 || tinfo
->curr
.ppr_options
!= tinfo
->goal
.ppr_options
2913 || (neg_type
== AHD_NEG_IF_NON_ASYNC
2914 && (tinfo
->goal
.offset
!= 0
2915 || tinfo
->goal
.width
!= MSG_EXT_WDTR_BUS_8_BIT
2916 || tinfo
->goal
.ppr_options
!= 0)))
2917 tstate
->auto_negotiate
|= devinfo
->target_mask
;
2919 tstate
->auto_negotiate
&= ~devinfo
->target_mask
;
2921 return (auto_negotiate_orig
!= tstate
->auto_negotiate
);
2925 * Update the user/goal/curr tables of synchronous negotiation
2926 * parameters as well as, in the case of a current or active update,
2927 * any data structures on the host controller. In the case of an
2928 * active update, the specified target is currently talking to us on
2929 * the bus, so the transfer parameter update must take effect
2933 ahd_set_syncrate(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
,
2934 u_int period
, u_int offset
, u_int ppr_options
,
2935 u_int type
, int paused
)
2937 struct ahd_initiator_tinfo
*tinfo
;
2938 struct ahd_tmode_tstate
*tstate
;
2945 active
= (type
& AHD_TRANS_ACTIVE
) == AHD_TRANS_ACTIVE
;
2948 if (period
== 0 || offset
== 0) {
2953 tinfo
= ahd_fetch_transinfo(ahd
, devinfo
->channel
, devinfo
->our_scsiid
,
2954 devinfo
->target
, &tstate
);
2956 if ((type
& AHD_TRANS_USER
) != 0) {
2957 tinfo
->user
.period
= period
;
2958 tinfo
->user
.offset
= offset
;
2959 tinfo
->user
.ppr_options
= ppr_options
;
2962 if ((type
& AHD_TRANS_GOAL
) != 0) {
2963 tinfo
->goal
.period
= period
;
2964 tinfo
->goal
.offset
= offset
;
2965 tinfo
->goal
.ppr_options
= ppr_options
;
2968 old_period
= tinfo
->curr
.period
;
2969 old_offset
= tinfo
->curr
.offset
;
2970 old_ppr
= tinfo
->curr
.ppr_options
;
2972 if ((type
& AHD_TRANS_CUR
) != 0
2973 && (old_period
!= period
2974 || old_offset
!= offset
2975 || old_ppr
!= ppr_options
)) {
2979 tinfo
->curr
.period
= period
;
2980 tinfo
->curr
.offset
= offset
;
2981 tinfo
->curr
.ppr_options
= ppr_options
;
2983 ahd_send_async(ahd
, devinfo
->channel
, devinfo
->target
,
2984 CAM_LUN_WILDCARD
, AC_TRANSFER_NEG
, NULL
);
2989 printf("%s: target %d synchronous with "
2990 "period = 0x%x, offset = 0x%x",
2991 ahd_name(ahd
), devinfo
->target
,
2994 if ((ppr_options
& MSG_EXT_PPR_RD_STRM
) != 0) {
2998 if ((ppr_options
& MSG_EXT_PPR_DT_REQ
) != 0) {
2999 printf("%s", options
? "|DT" : "(DT");
3002 if ((ppr_options
& MSG_EXT_PPR_IU_REQ
) != 0) {
3003 printf("%s", options
? "|IU" : "(IU");
3006 if ((ppr_options
& MSG_EXT_PPR_RTI
) != 0) {
3007 printf("%s", options
? "|RTI" : "(RTI");
3010 if ((ppr_options
& MSG_EXT_PPR_QAS_REQ
) != 0) {
3011 printf("%s", options
? "|QAS" : "(QAS");
3019 printf("%s: target %d using "
3020 "asynchronous transfers%s\n",
3021 ahd_name(ahd
), devinfo
->target
,
3022 (ppr_options
& MSG_EXT_PPR_QAS_REQ
) != 0
3028 * Always refresh the neg-table to handle the case of the
3029 * sequencer setting the ENATNO bit for a MK_MESSAGE request.
3030 * We will always renegotiate in that case if this is a
3031 * packetized request. Also manage the busfree expected flag
3032 * from this common routine so that we catch changes due to
3033 * WDTR or SDTR messages.
3035 if ((type
& AHD_TRANS_CUR
) != 0) {
3038 ahd_update_neg_table(ahd
, devinfo
, &tinfo
->curr
);
3041 if (ahd
->msg_type
!= MSG_TYPE_NONE
) {
3042 if ((old_ppr
& MSG_EXT_PPR_IU_REQ
)
3043 != (ppr_options
& MSG_EXT_PPR_IU_REQ
)) {
3045 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0) {
3046 ahd_print_devinfo(ahd
, devinfo
);
3047 printf("Expecting IU Change busfree\n");
3050 ahd
->msg_flags
|= MSG_FLAG_EXPECT_PPR_BUSFREE
3051 | MSG_FLAG_IU_REQ_CHANGED
;
3053 if ((old_ppr
& MSG_EXT_PPR_IU_REQ
) != 0) {
3055 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
3056 printf("PPR with IU_REQ outstanding\n");
3058 ahd
->msg_flags
|= MSG_FLAG_EXPECT_PPR_BUSFREE
;
3063 update_needed
+= ahd_update_neg_request(ahd
, devinfo
, tstate
,
3064 tinfo
, AHD_NEG_TO_GOAL
);
3066 if (update_needed
&& active
)
3067 ahd_update_pending_scbs(ahd
);
3071 * Update the user/goal/curr tables of wide negotiation
3072 * parameters as well as, in the case of a current or active update,
3073 * any data structures on the host controller. In the case of an
3074 * active update, the specified target is currently talking to us on
3075 * the bus, so the transfer parameter update must take effect
3079 ahd_set_width(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
,
3080 u_int width
, u_int type
, int paused
)
3082 struct ahd_initiator_tinfo
*tinfo
;
3083 struct ahd_tmode_tstate
*tstate
;
3088 active
= (type
& AHD_TRANS_ACTIVE
) == AHD_TRANS_ACTIVE
;
3090 tinfo
= ahd_fetch_transinfo(ahd
, devinfo
->channel
, devinfo
->our_scsiid
,
3091 devinfo
->target
, &tstate
);
3093 if ((type
& AHD_TRANS_USER
) != 0)
3094 tinfo
->user
.width
= width
;
3096 if ((type
& AHD_TRANS_GOAL
) != 0)
3097 tinfo
->goal
.width
= width
;
3099 oldwidth
= tinfo
->curr
.width
;
3100 if ((type
& AHD_TRANS_CUR
) != 0 && oldwidth
!= width
) {
3104 tinfo
->curr
.width
= width
;
3105 ahd_send_async(ahd
, devinfo
->channel
, devinfo
->target
,
3106 CAM_LUN_WILDCARD
, AC_TRANSFER_NEG
, NULL
);
3108 printf("%s: target %d using %dbit transfers\n",
3109 ahd_name(ahd
), devinfo
->target
,
3110 8 * (0x01 << width
));
3114 if ((type
& AHD_TRANS_CUR
) != 0) {
3117 ahd_update_neg_table(ahd
, devinfo
, &tinfo
->curr
);
3122 update_needed
+= ahd_update_neg_request(ahd
, devinfo
, tstate
,
3123 tinfo
, AHD_NEG_TO_GOAL
);
3124 if (update_needed
&& active
)
3125 ahd_update_pending_scbs(ahd
);
3130 * Update the current state of tagged queuing for a given target.
3133 ahd_set_tags(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
,
3136 ahd_platform_set_tags(ahd
, devinfo
, alg
);
3137 ahd_send_async(ahd
, devinfo
->channel
, devinfo
->target
,
3138 devinfo
->lun
, AC_TRANSFER_NEG
, &alg
);
3142 ahd_update_neg_table(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
,
3143 struct ahd_transinfo
*tinfo
)
3145 ahd_mode_state saved_modes
;
3150 u_int saved_negoaddr
;
3151 uint8_t iocell_opts
[sizeof(ahd
->iocell_opts
)];
3153 saved_modes
= ahd_save_modes(ahd
);
3154 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
3156 saved_negoaddr
= ahd_inb(ahd
, NEGOADDR
);
3157 ahd_outb(ahd
, NEGOADDR
, devinfo
->target
);
3158 period
= tinfo
->period
;
3159 offset
= tinfo
->offset
;
3160 memcpy(iocell_opts
, ahd
->iocell_opts
, sizeof(ahd
->iocell_opts
));
3161 ppr_opts
= tinfo
->ppr_options
& (MSG_EXT_PPR_QAS_REQ
|MSG_EXT_PPR_DT_REQ
3162 |MSG_EXT_PPR_IU_REQ
|MSG_EXT_PPR_RTI
);
3165 period
= AHD_SYNCRATE_ASYNC
;
3166 if (period
== AHD_SYNCRATE_160
) {
3168 if ((ahd
->bugs
& AHD_PACED_NEGTABLE_BUG
) != 0) {
3170 * When the SPI4 spec was finalized, PACE transfers
3171 * was not made a configurable option in the PPR
3172 * message. Instead it is assumed to be enabled for
3173 * any syncrate faster than 80MHz. Nevertheless,
3174 * Harpoon2A4 allows this to be configurable.
3176 * Harpoon2A4 also assumes at most 2 data bytes per
3177 * negotiated REQ/ACK offset. Paced transfers take
3178 * 4, so we must adjust our offset.
3180 ppr_opts
|= PPROPT_PACE
;
3184 * Harpoon2A assumed that there would be a
3185 * fallback rate between 160MHz and 80Mhz,
3186 * so 7 is used as the period factor rather
3187 * than 8 for 160MHz.
3189 period
= AHD_SYNCRATE_REVA_160
;
3191 if ((tinfo
->ppr_options
& MSG_EXT_PPR_PCOMP_EN
) == 0)
3192 iocell_opts
[AHD_PRECOMP_SLEW_INDEX
] &=
3196 * Precomp should be disabled for non-paced transfers.
3198 iocell_opts
[AHD_PRECOMP_SLEW_INDEX
] &= ~AHD_PRECOMP_MASK
;
3200 if ((ahd
->features
& AHD_NEW_IOCELL_OPTS
) != 0
3201 && (ppr_opts
& MSG_EXT_PPR_DT_REQ
) != 0) {
3203 * Slow down our CRC interval to be
3204 * compatible with devices that can't
3205 * handle a CRC at full speed.
3207 con_opts
|= ENSLOWCRC
;
3211 ahd_outb(ahd
, ANNEXCOL
, AHD_ANNEXCOL_PRECOMP_SLEW
);
3212 ahd_outb(ahd
, ANNEXDAT
, iocell_opts
[AHD_PRECOMP_SLEW_INDEX
]);
3213 ahd_outb(ahd
, ANNEXCOL
, AHD_ANNEXCOL_AMPLITUDE
);
3214 ahd_outb(ahd
, ANNEXDAT
, iocell_opts
[AHD_AMPLITUDE_INDEX
]);
3216 ahd_outb(ahd
, NEGPERIOD
, period
);
3217 ahd_outb(ahd
, NEGPPROPTS
, ppr_opts
);
3218 ahd_outb(ahd
, NEGOFFSET
, offset
);
3220 if (tinfo
->width
== MSG_EXT_WDTR_BUS_16_BIT
)
3221 con_opts
|= WIDEXFER
;
3224 * During packetized transfers, the target will
3225 * give us the oportunity to send command packets
3226 * without us asserting attention.
3228 if ((tinfo
->ppr_options
& MSG_EXT_PPR_IU_REQ
) == 0)
3229 con_opts
|= ENAUTOATNO
;
3230 ahd_outb(ahd
, NEGCONOPTS
, con_opts
);
3231 ahd_outb(ahd
, NEGOADDR
, saved_negoaddr
);
3232 ahd_restore_modes(ahd
, saved_modes
);
3236 * When the transfer settings for a connection change, setup for
3237 * negotiation in pending SCBs to effect the change as quickly as
3238 * possible. We also cancel any negotiations that are scheduled
3239 * for inflight SCBs that have not been started yet.
3242 ahd_update_pending_scbs(struct ahd_softc
*ahd
)
3244 struct scb
*pending_scb
;
3245 int pending_scb_count
;
3249 ahd_mode_state saved_modes
;
3252 * Traverse the pending SCB list and ensure that all of the
3253 * SCBs there have the proper settings. We can only safely
3254 * clear the negotiation required flag (setting requires the
3255 * execution queue to be modified) and this is only possible
3256 * if we are not already attempting to select out for this
3257 * SCB. For this reason, all callers only call this routine
3258 * if we are changing the negotiation settings for the currently
3259 * active transaction on the bus.
3261 pending_scb_count
= 0;
3262 LIST_FOREACH(pending_scb
, &ahd
->pending_scbs
, pending_links
) {
3263 struct ahd_devinfo devinfo
;
3264 struct hardware_scb
*pending_hscb
;
3265 struct ahd_initiator_tinfo
*tinfo
;
3266 struct ahd_tmode_tstate
*tstate
;
3268 ahd_scb_devinfo(ahd
, &devinfo
, pending_scb
);
3269 tinfo
= ahd_fetch_transinfo(ahd
, devinfo
.channel
,
3271 devinfo
.target
, &tstate
);
3272 pending_hscb
= pending_scb
->hscb
;
3273 if ((tstate
->auto_negotiate
& devinfo
.target_mask
) == 0
3274 && (pending_scb
->flags
& SCB_AUTO_NEGOTIATE
) != 0) {
3275 pending_scb
->flags
&= ~SCB_AUTO_NEGOTIATE
;
3276 pending_hscb
->control
&= ~MK_MESSAGE
;
3278 ahd_sync_scb(ahd
, pending_scb
,
3279 BUS_DMASYNC_PREREAD
|BUS_DMASYNC_PREWRITE
);
3280 pending_scb_count
++;
3283 if (pending_scb_count
== 0)
3286 if (ahd_is_paused(ahd
)) {
3294 * Force the sequencer to reinitialize the selection for
3295 * the command at the head of the execution queue if it
3296 * has already been setup. The negotiation changes may
3297 * effect whether we select-out with ATN.
3299 saved_modes
= ahd_save_modes(ahd
);
3300 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
3301 ahd_outb(ahd
, SCSISEQ0
, ahd_inb(ahd
, SCSISEQ0
) & ~ENSELO
);
3302 saved_scbptr
= ahd_get_scbptr(ahd
);
3303 /* Ensure that the hscbs down on the card match the new information */
3304 for (scb_tag
= 0; scb_tag
< ahd
->scb_data
.maxhscbs
; scb_tag
++) {
3305 struct hardware_scb
*pending_hscb
;
3308 pending_scb
= ahd_lookup_scb(ahd
, scb_tag
);
3309 if (pending_scb
== NULL
)
3311 ahd_set_scbptr(ahd
, scb_tag
);
3312 pending_hscb
= pending_scb
->hscb
;
3313 control
= ahd_inb_scbram(ahd
, SCB_CONTROL
);
3314 control
&= ~MK_MESSAGE
;
3315 control
|= pending_hscb
->control
& MK_MESSAGE
;
3316 ahd_outb(ahd
, SCB_CONTROL
, control
);
3318 ahd_set_scbptr(ahd
, saved_scbptr
);
3319 ahd_restore_modes(ahd
, saved_modes
);
3325 /**************************** Pathing Information *****************************/
3327 ahd_fetch_devinfo(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
)
3329 ahd_mode_state saved_modes
;
3334 saved_modes
= ahd_save_modes(ahd
);
3335 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
3337 if (ahd_inb(ahd
, SSTAT0
) & TARGET
)
3340 role
= ROLE_INITIATOR
;
3342 if (role
== ROLE_TARGET
3343 && (ahd_inb(ahd
, SEQ_FLAGS
) & CMDPHASE_PENDING
) != 0) {
3344 /* We were selected, so pull our id from TARGIDIN */
3345 our_id
= ahd_inb(ahd
, TARGIDIN
) & OID
;
3346 } else if (role
== ROLE_TARGET
)
3347 our_id
= ahd_inb(ahd
, TOWNID
);
3349 our_id
= ahd_inb(ahd
, IOWNID
);
3351 saved_scsiid
= ahd_inb(ahd
, SAVED_SCSIID
);
3352 ahd_compile_devinfo(devinfo
,
3354 SCSIID_TARGET(ahd
, saved_scsiid
),
3355 ahd_inb(ahd
, SAVED_LUN
),
3356 SCSIID_CHANNEL(ahd
, saved_scsiid
),
3358 ahd_restore_modes(ahd
, saved_modes
);
3362 ahd_print_devinfo(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
)
3364 printf("%s:%c:%d:%d: ", ahd_name(ahd
), 'A',
3365 devinfo
->target
, devinfo
->lun
);
3368 struct ahd_phase_table_entry
*
3369 ahd_lookup_phase_entry(int phase
)
3371 struct ahd_phase_table_entry
*entry
;
3372 struct ahd_phase_table_entry
*last_entry
;
3375 * num_phases doesn't include the default entry which
3376 * will be returned if the phase doesn't match.
3378 last_entry
= &ahd_phase_table
[num_phases
];
3379 for (entry
= ahd_phase_table
; entry
< last_entry
; entry
++) {
3380 if (phase
== entry
->phase
)
3387 ahd_compile_devinfo(struct ahd_devinfo
*devinfo
, u_int our_id
, u_int target
,
3388 u_int lun
, char channel
, role_t role
)
3390 devinfo
->our_scsiid
= our_id
;
3391 devinfo
->target
= target
;
3393 devinfo
->target_offset
= target
;
3394 devinfo
->channel
= channel
;
3395 devinfo
->role
= role
;
3397 devinfo
->target_offset
+= 8;
3398 devinfo
->target_mask
= (0x01 << devinfo
->target_offset
);
3402 ahd_scb_devinfo(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
,
3408 our_id
= SCSIID_OUR_ID(scb
->hscb
->scsiid
);
3409 role
= ROLE_INITIATOR
;
3410 if ((scb
->hscb
->control
& TARGET_SCB
) != 0)
3412 ahd_compile_devinfo(devinfo
, our_id
, SCB_GET_TARGET(ahd
, scb
),
3413 SCB_GET_LUN(scb
), SCB_GET_CHANNEL(ahd
, scb
), role
);
3417 /************************ Message Phase Processing ****************************/
3419 * When an initiator transaction with the MK_MESSAGE flag either reconnects
3420 * or enters the initial message out phase, we are interrupted. Fill our
3421 * outgoing message buffer with the appropriate message and beging handing
3422 * the message phase(s) manually.
3425 ahd_setup_initiator_msgout(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
,
3429 * To facilitate adding multiple messages together,
3430 * each routine should increment the index and len
3431 * variables instead of setting them explicitly.
3433 ahd
->msgout_index
= 0;
3434 ahd
->msgout_len
= 0;
3436 if (ahd_currently_packetized(ahd
))
3437 ahd
->msg_flags
|= MSG_FLAG_PACKETIZED
;
3439 if (ahd
->send_msg_perror
3440 && ahd_inb(ahd
, MSG_OUT
) == HOST_MSG
) {
3441 ahd
->msgout_buf
[ahd
->msgout_index
++] = ahd
->send_msg_perror
;
3443 ahd
->msg_type
= MSG_TYPE_INITIATOR_MSGOUT
;
3445 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
3446 printf("Setting up for Parity Error delivery\n");
3449 } else if (scb
== NULL
) {
3450 printf("%s: WARNING. No pending message for "
3451 "I_T msgin. Issuing NO-OP\n", ahd_name(ahd
));
3452 ahd
->msgout_buf
[ahd
->msgout_index
++] = MSG_NOOP
;
3454 ahd
->msg_type
= MSG_TYPE_INITIATOR_MSGOUT
;
3458 if ((scb
->flags
& SCB_DEVICE_RESET
) == 0
3459 && (scb
->flags
& SCB_PACKETIZED
) == 0
3460 && ahd_inb(ahd
, MSG_OUT
) == MSG_IDENTIFYFLAG
) {
3463 identify_msg
= MSG_IDENTIFYFLAG
| SCB_GET_LUN(scb
);
3464 if ((scb
->hscb
->control
& DISCENB
) != 0)
3465 identify_msg
|= MSG_IDENTIFY_DISCFLAG
;
3466 ahd
->msgout_buf
[ahd
->msgout_index
++] = identify_msg
;
3469 if ((scb
->hscb
->control
& TAG_ENB
) != 0) {
3470 ahd
->msgout_buf
[ahd
->msgout_index
++] =
3471 scb
->hscb
->control
& (TAG_ENB
|SCB_TAG_TYPE
);
3472 ahd
->msgout_buf
[ahd
->msgout_index
++] = SCB_GET_TAG(scb
);
3473 ahd
->msgout_len
+= 2;
3477 if (scb
->flags
& SCB_DEVICE_RESET
) {
3478 ahd
->msgout_buf
[ahd
->msgout_index
++] = MSG_BUS_DEV_RESET
;
3480 ahd_print_path(ahd
, scb
);
3481 printf("Bus Device Reset Message Sent\n");
3483 * Clear our selection hardware in advance of
3484 * the busfree. We may have an entry in the waiting
3485 * Q for this target, and we don't want to go about
3486 * selecting while we handle the busfree and blow it
3489 ahd_outb(ahd
, SCSISEQ0
, 0);
3490 } else if ((scb
->flags
& SCB_ABORT
) != 0) {
3492 if ((scb
->hscb
->control
& TAG_ENB
) != 0) {
3493 ahd
->msgout_buf
[ahd
->msgout_index
++] = MSG_ABORT_TAG
;
3495 ahd
->msgout_buf
[ahd
->msgout_index
++] = MSG_ABORT
;
3498 ahd_print_path(ahd
, scb
);
3499 printf("Abort%s Message Sent\n",
3500 (scb
->hscb
->control
& TAG_ENB
) != 0 ? " Tag" : "");
3502 * Clear our selection hardware in advance of
3503 * the busfree. We may have an entry in the waiting
3504 * Q for this target, and we don't want to go about
3505 * selecting while we handle the busfree and blow it
3508 ahd_outb(ahd
, SCSISEQ0
, 0);
3509 } else if ((scb
->flags
& (SCB_AUTO_NEGOTIATE
|SCB_NEGOTIATE
)) != 0) {
3510 ahd_build_transfer_msg(ahd
, devinfo
);
3512 * Clear our selection hardware in advance of potential
3513 * PPR IU status change busfree. We may have an entry in
3514 * the waiting Q for this target, and we don't want to go
3515 * about selecting while we handle the busfree and blow
3518 ahd_outb(ahd
, SCSISEQ0
, 0);
3520 printf("ahd_intr: AWAITING_MSG for an SCB that "
3521 "does not have a waiting message\n");
3522 printf("SCSIID = %x, target_mask = %x\n", scb
->hscb
->scsiid
,
3523 devinfo
->target_mask
);
3524 panic("SCB = %d, SCB Control = %x:%x, MSG_OUT = %x "
3525 "SCB flags = %x", SCB_GET_TAG(scb
), scb
->hscb
->control
,
3526 ahd_inb_scbram(ahd
, SCB_CONTROL
), ahd_inb(ahd
, MSG_OUT
),
3531 * Clear the MK_MESSAGE flag from the SCB so we aren't
3532 * asked to send this message again.
3534 ahd_outb(ahd
, SCB_CONTROL
,
3535 ahd_inb_scbram(ahd
, SCB_CONTROL
) & ~MK_MESSAGE
);
3536 scb
->hscb
->control
&= ~MK_MESSAGE
;
3537 ahd
->msgout_index
= 0;
3538 ahd
->msg_type
= MSG_TYPE_INITIATOR_MSGOUT
;
3542 * Build an appropriate transfer negotiation message for the
3543 * currently active target.
3546 ahd_build_transfer_msg(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
)
3549 * We need to initiate transfer negotiations.
3550 * If our current and goal settings are identical,
3551 * we want to renegotiate due to a check condition.
3553 struct ahd_initiator_tinfo
*tinfo
;
3554 struct ahd_tmode_tstate
*tstate
;
3562 tinfo
= ahd_fetch_transinfo(ahd
, devinfo
->channel
, devinfo
->our_scsiid
,
3563 devinfo
->target
, &tstate
);
3565 * Filter our period based on the current connection.
3566 * If we can't perform DT transfers on this segment (not in LVD
3567 * mode for instance), then our decision to issue a PPR message
3570 period
= tinfo
->goal
.period
;
3571 offset
= tinfo
->goal
.offset
;
3572 ppr_options
= tinfo
->goal
.ppr_options
;
3573 /* Target initiated PPR is not allowed in the SCSI spec */
3574 if (devinfo
->role
== ROLE_TARGET
)
3576 ahd_devlimited_syncrate(ahd
, tinfo
, &period
,
3577 &ppr_options
, devinfo
->role
);
3578 dowide
= tinfo
->curr
.width
!= tinfo
->goal
.width
;
3579 dosync
= tinfo
->curr
.offset
!= offset
|| tinfo
->curr
.period
!= period
;
3581 * Only use PPR if we have options that need it, even if the device
3582 * claims to support it. There might be an expander in the way
3585 doppr
= ppr_options
!= 0;
3587 if (!dowide
&& !dosync
&& !doppr
) {
3588 dowide
= tinfo
->goal
.width
!= MSG_EXT_WDTR_BUS_8_BIT
;
3589 dosync
= tinfo
->goal
.offset
!= 0;
3592 if (!dowide
&& !dosync
&& !doppr
) {
3594 * Force async with a WDTR message if we have a wide bus,
3595 * or just issue an SDTR with a 0 offset.
3597 if ((ahd
->features
& AHD_WIDE
) != 0)
3603 ahd_print_devinfo(ahd
, devinfo
);
3604 printf("Ensuring async\n");
3607 /* Target initiated PPR is not allowed in the SCSI spec */
3608 if (devinfo
->role
== ROLE_TARGET
)
3612 * Both the PPR message and SDTR message require the
3613 * goal syncrate to be limited to what the target device
3614 * is capable of handling (based on whether an LVD->SE
3615 * expander is on the bus), so combine these two cases.
3616 * Regardless, guarantee that if we are using WDTR and SDTR
3617 * messages that WDTR comes first.
3619 if (doppr
|| (dosync
&& !dowide
)) {
3621 offset
= tinfo
->goal
.offset
;
3622 ahd_validate_offset(ahd
, tinfo
, period
, &offset
,
3623 doppr
? tinfo
->goal
.width
3624 : tinfo
->curr
.width
,
3627 ahd_construct_ppr(ahd
, devinfo
, period
, offset
,
3628 tinfo
->goal
.width
, ppr_options
);
3630 ahd_construct_sdtr(ahd
, devinfo
, period
, offset
);
3633 ahd_construct_wdtr(ahd
, devinfo
, tinfo
->goal
.width
);
3638 * Build a synchronous negotiation message in our message
3639 * buffer based on the input parameters.
3642 ahd_construct_sdtr(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
,
3643 u_int period
, u_int offset
)
3646 period
= AHD_ASYNC_XFER_PERIOD
;
3647 ahd
->msgout_buf
[ahd
->msgout_index
++] = MSG_EXTENDED
;
3648 ahd
->msgout_buf
[ahd
->msgout_index
++] = MSG_EXT_SDTR_LEN
;
3649 ahd
->msgout_buf
[ahd
->msgout_index
++] = MSG_EXT_SDTR
;
3650 ahd
->msgout_buf
[ahd
->msgout_index
++] = period
;
3651 ahd
->msgout_buf
[ahd
->msgout_index
++] = offset
;
3652 ahd
->msgout_len
+= 5;
3654 printf("(%s:%c:%d:%d): Sending SDTR period %x, offset %x\n",
3655 ahd_name(ahd
), devinfo
->channel
, devinfo
->target
,
3656 devinfo
->lun
, period
, offset
);
3661 * Build a wide negotiateion message in our message
3662 * buffer based on the input parameters.
3665 ahd_construct_wdtr(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
,
3668 ahd
->msgout_buf
[ahd
->msgout_index
++] = MSG_EXTENDED
;
3669 ahd
->msgout_buf
[ahd
->msgout_index
++] = MSG_EXT_WDTR_LEN
;
3670 ahd
->msgout_buf
[ahd
->msgout_index
++] = MSG_EXT_WDTR
;
3671 ahd
->msgout_buf
[ahd
->msgout_index
++] = bus_width
;
3672 ahd
->msgout_len
+= 4;
3674 printf("(%s:%c:%d:%d): Sending WDTR %x\n",
3675 ahd_name(ahd
), devinfo
->channel
, devinfo
->target
,
3676 devinfo
->lun
, bus_width
);
3681 * Build a parallel protocol request message in our message
3682 * buffer based on the input parameters.
3685 ahd_construct_ppr(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
,
3686 u_int period
, u_int offset
, u_int bus_width
,
3690 * Always request precompensation from
3691 * the other target if we are running
3692 * at paced syncrates.
3694 if (period
<= AHD_SYNCRATE_PACED
)
3695 ppr_options
|= MSG_EXT_PPR_PCOMP_EN
;
3697 period
= AHD_ASYNC_XFER_PERIOD
;
3698 ahd
->msgout_buf
[ahd
->msgout_index
++] = MSG_EXTENDED
;
3699 ahd
->msgout_buf
[ahd
->msgout_index
++] = MSG_EXT_PPR_LEN
;
3700 ahd
->msgout_buf
[ahd
->msgout_index
++] = MSG_EXT_PPR
;
3701 ahd
->msgout_buf
[ahd
->msgout_index
++] = period
;
3702 ahd
->msgout_buf
[ahd
->msgout_index
++] = 0;
3703 ahd
->msgout_buf
[ahd
->msgout_index
++] = offset
;
3704 ahd
->msgout_buf
[ahd
->msgout_index
++] = bus_width
;
3705 ahd
->msgout_buf
[ahd
->msgout_index
++] = ppr_options
;
3706 ahd
->msgout_len
+= 8;
3708 printf("(%s:%c:%d:%d): Sending PPR bus_width %x, period %x, "
3709 "offset %x, ppr_options %x\n", ahd_name(ahd
),
3710 devinfo
->channel
, devinfo
->target
, devinfo
->lun
,
3711 bus_width
, period
, offset
, ppr_options
);
3716 * Clear any active message state.
3719 ahd_clear_msg_state(struct ahd_softc
*ahd
)
3721 ahd_mode_state saved_modes
;
3723 saved_modes
= ahd_save_modes(ahd
);
3724 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
3725 ahd
->send_msg_perror
= 0;
3726 ahd
->msg_flags
= MSG_FLAG_NONE
;
3727 ahd
->msgout_len
= 0;
3728 ahd
->msgin_index
= 0;
3729 ahd
->msg_type
= MSG_TYPE_NONE
;
3730 if ((ahd_inb(ahd
, SCSISIGO
) & ATNO
) != 0) {
3732 * The target didn't care to respond to our
3733 * message request, so clear ATN.
3735 ahd_outb(ahd
, CLRSINT1
, CLRATNO
);
3737 ahd_outb(ahd
, MSG_OUT
, MSG_NOOP
);
3738 ahd_outb(ahd
, SEQ_FLAGS2
,
3739 ahd_inb(ahd
, SEQ_FLAGS2
) & ~TARGET_MSG_PENDING
);
3740 ahd_restore_modes(ahd
, saved_modes
);
3744 * Manual message loop handler.
3747 ahd_handle_message_phase(struct ahd_softc
*ahd
)
3749 struct ahd_devinfo devinfo
;
3753 ahd_fetch_devinfo(ahd
, &devinfo
);
3754 end_session
= FALSE
;
3755 bus_phase
= ahd_inb(ahd
, LASTPHASE
);
3757 if ((ahd_inb(ahd
, LQISTAT2
) & LQIPHASE_OUTPKT
) != 0) {
3758 printf("LQIRETRY for LQIPHASE_OUTPKT\n");
3759 ahd_outb(ahd
, LQCTL2
, LQIRETRY
);
3762 switch (ahd
->msg_type
) {
3763 case MSG_TYPE_INITIATOR_MSGOUT
:
3769 if (ahd
->msgout_len
== 0 && ahd
->send_msg_perror
== 0)
3770 panic("HOST_MSG_LOOP interrupt with no active message");
3773 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0) {
3774 ahd_print_devinfo(ahd
, &devinfo
);
3775 printf("INITIATOR_MSG_OUT");
3778 phasemis
= bus_phase
!= P_MESGOUT
;
3781 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0) {
3782 printf(" PHASEMIS %s\n",
3783 ahd_lookup_phase_entry(bus_phase
)
3787 if (bus_phase
== P_MESGIN
) {
3789 * Change gears and see if
3790 * this messages is of interest to
3791 * us or should be passed back to
3794 ahd_outb(ahd
, CLRSINT1
, CLRATNO
);
3795 ahd
->send_msg_perror
= 0;
3796 ahd
->msg_type
= MSG_TYPE_INITIATOR_MSGIN
;
3797 ahd
->msgin_index
= 0;
3804 if (ahd
->send_msg_perror
) {
3805 ahd_outb(ahd
, CLRSINT1
, CLRATNO
);
3806 ahd_outb(ahd
, CLRSINT1
, CLRREQINIT
);
3808 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
3809 printf(" byte 0x%x\n", ahd
->send_msg_perror
);
3812 * If we are notifying the target of a CRC error
3813 * during packetized operations, the target is
3814 * within its rights to acknowledge our message
3817 if ((ahd
->msg_flags
& MSG_FLAG_PACKETIZED
) != 0
3818 && ahd
->send_msg_perror
== MSG_INITIATOR_DET_ERR
)
3819 ahd
->msg_flags
|= MSG_FLAG_EXPECT_IDE_BUSFREE
;
3821 ahd_outb(ahd
, RETURN_2
, ahd
->send_msg_perror
);
3822 ahd_outb(ahd
, RETURN_1
, CONT_MSG_LOOP_WRITE
);
3826 msgdone
= ahd
->msgout_index
== ahd
->msgout_len
;
3829 * The target has requested a retry.
3830 * Re-assert ATN, reset our message index to
3833 ahd
->msgout_index
= 0;
3834 ahd_assert_atn(ahd
);
3837 lastbyte
= ahd
->msgout_index
== (ahd
->msgout_len
- 1);
3839 /* Last byte is signified by dropping ATN */
3840 ahd_outb(ahd
, CLRSINT1
, CLRATNO
);
3844 * Clear our interrupt status and present
3845 * the next byte on the bus.
3847 ahd_outb(ahd
, CLRSINT1
, CLRREQINIT
);
3849 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
3850 printf(" byte 0x%x\n",
3851 ahd
->msgout_buf
[ahd
->msgout_index
]);
3853 ahd_outb(ahd
, RETURN_2
, ahd
->msgout_buf
[ahd
->msgout_index
++]);
3854 ahd_outb(ahd
, RETURN_1
, CONT_MSG_LOOP_WRITE
);
3857 case MSG_TYPE_INITIATOR_MSGIN
:
3863 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0) {
3864 ahd_print_devinfo(ahd
, &devinfo
);
3865 printf("INITIATOR_MSG_IN");
3868 phasemis
= bus_phase
!= P_MESGIN
;
3871 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0) {
3872 printf(" PHASEMIS %s\n",
3873 ahd_lookup_phase_entry(bus_phase
)
3877 ahd
->msgin_index
= 0;
3878 if (bus_phase
== P_MESGOUT
3879 && (ahd
->send_msg_perror
!= 0
3880 || (ahd
->msgout_len
!= 0
3881 && ahd
->msgout_index
== 0))) {
3882 ahd
->msg_type
= MSG_TYPE_INITIATOR_MSGOUT
;
3889 /* Pull the byte in without acking it */
3890 ahd
->msgin_buf
[ahd
->msgin_index
] = ahd_inb(ahd
, SCSIBUS
);
3892 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
3893 printf(" byte 0x%x\n",
3894 ahd
->msgin_buf
[ahd
->msgin_index
]);
3897 message_done
= ahd_parse_msg(ahd
, &devinfo
);
3901 * Clear our incoming message buffer in case there
3902 * is another message following this one.
3904 ahd
->msgin_index
= 0;
3907 * If this message illicited a response,
3908 * assert ATN so the target takes us to the
3909 * message out phase.
3911 if (ahd
->msgout_len
!= 0) {
3913 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0) {
3914 ahd_print_devinfo(ahd
, &devinfo
);
3915 printf("Asserting ATN for response\n");
3918 ahd_assert_atn(ahd
);
3923 if (message_done
== MSGLOOP_TERMINATED
) {
3927 ahd_outb(ahd
, CLRSINT1
, CLRREQINIT
);
3928 ahd_outb(ahd
, RETURN_1
, CONT_MSG_LOOP_READ
);
3932 case MSG_TYPE_TARGET_MSGIN
:
3938 * By default, the message loop will continue.
3940 ahd_outb(ahd
, RETURN_1
, CONT_MSG_LOOP_TARG
);
3942 if (ahd
->msgout_len
== 0)
3943 panic("Target MSGIN with no active message");
3946 * If we interrupted a mesgout session, the initiator
3947 * will not know this until our first REQ. So, we
3948 * only honor mesgout requests after we've sent our
3951 if ((ahd_inb(ahd
, SCSISIGI
) & ATNI
) != 0
3952 && ahd
->msgout_index
> 0)
3953 msgout_request
= TRUE
;
3955 msgout_request
= FALSE
;
3957 if (msgout_request
) {
3960 * Change gears and see if
3961 * this messages is of interest to
3962 * us or should be passed back to
3965 ahd
->msg_type
= MSG_TYPE_TARGET_MSGOUT
;
3966 ahd_outb(ahd
, SCSISIGO
, P_MESGOUT
| BSYO
);
3967 ahd
->msgin_index
= 0;
3968 /* Dummy read to REQ for first byte */
3969 ahd_inb(ahd
, SCSIDAT
);
3970 ahd_outb(ahd
, SXFRCTL0
,
3971 ahd_inb(ahd
, SXFRCTL0
) | SPIOEN
);
3975 msgdone
= ahd
->msgout_index
== ahd
->msgout_len
;
3977 ahd_outb(ahd
, SXFRCTL0
,
3978 ahd_inb(ahd
, SXFRCTL0
) & ~SPIOEN
);
3984 * Present the next byte on the bus.
3986 ahd_outb(ahd
, SXFRCTL0
, ahd_inb(ahd
, SXFRCTL0
) | SPIOEN
);
3987 ahd_outb(ahd
, SCSIDAT
, ahd
->msgout_buf
[ahd
->msgout_index
++]);
3990 case MSG_TYPE_TARGET_MSGOUT
:
3996 * By default, the message loop will continue.
3998 ahd_outb(ahd
, RETURN_1
, CONT_MSG_LOOP_TARG
);
4001 * The initiator signals that this is
4002 * the last byte by dropping ATN.
4004 lastbyte
= (ahd_inb(ahd
, SCSISIGI
) & ATNI
) == 0;
4007 * Read the latched byte, but turn off SPIOEN first
4008 * so that we don't inadvertently cause a REQ for the
4011 ahd_outb(ahd
, SXFRCTL0
, ahd_inb(ahd
, SXFRCTL0
) & ~SPIOEN
);
4012 ahd
->msgin_buf
[ahd
->msgin_index
] = ahd_inb(ahd
, SCSIDAT
);
4013 msgdone
= ahd_parse_msg(ahd
, &devinfo
);
4014 if (msgdone
== MSGLOOP_TERMINATED
) {
4016 * The message is *really* done in that it caused
4017 * us to go to bus free. The sequencer has already
4018 * been reset at this point, so pull the ejection
4027 * XXX Read spec about initiator dropping ATN too soon
4028 * and use msgdone to detect it.
4030 if (msgdone
== MSGLOOP_MSGCOMPLETE
) {
4031 ahd
->msgin_index
= 0;
4034 * If this message illicited a response, transition
4035 * to the Message in phase and send it.
4037 if (ahd
->msgout_len
!= 0) {
4038 ahd_outb(ahd
, SCSISIGO
, P_MESGIN
| BSYO
);
4039 ahd_outb(ahd
, SXFRCTL0
,
4040 ahd_inb(ahd
, SXFRCTL0
) | SPIOEN
);
4041 ahd
->msg_type
= MSG_TYPE_TARGET_MSGIN
;
4042 ahd
->msgin_index
= 0;
4050 /* Ask for the next byte. */
4051 ahd_outb(ahd
, SXFRCTL0
,
4052 ahd_inb(ahd
, SXFRCTL0
) | SPIOEN
);
4058 panic("Unknown REQINIT message type");
4062 if ((ahd
->msg_flags
& MSG_FLAG_PACKETIZED
) != 0) {
4063 printf("%s: Returning to Idle Loop\n",
4065 ahd_clear_msg_state(ahd
);
4068 * Perform the equivalent of a clear_target_state.
4070 ahd_outb(ahd
, LASTPHASE
, P_BUSFREE
);
4071 ahd_outb(ahd
, SEQ_FLAGS
, NOT_IDENTIFIED
|NO_CDB_SENT
);
4072 ahd_outb(ahd
, SEQCTL0
, FASTMODE
|SEQRESET
);
4074 ahd_clear_msg_state(ahd
);
4075 ahd_outb(ahd
, RETURN_1
, EXIT_MSG_LOOP
);
4081 * See if we sent a particular extended message to the target.
4082 * If "full" is true, return true only if the target saw the full
4083 * message. If "full" is false, return true if the target saw at
4084 * least the first byte of the message.
4087 ahd_sent_msg(struct ahd_softc
*ahd
, ahd_msgtype type
, u_int msgval
, int full
)
4095 while (index
< ahd
->msgout_len
) {
4096 if (ahd
->msgout_buf
[index
] == MSG_EXTENDED
) {
4099 end_index
= index
+ 1 + ahd
->msgout_buf
[index
+ 1];
4100 if (ahd
->msgout_buf
[index
+2] == msgval
4101 && type
== AHDMSG_EXT
) {
4104 if (ahd
->msgout_index
> end_index
)
4106 } else if (ahd
->msgout_index
> index
)
4110 } else if (ahd
->msgout_buf
[index
] >= MSG_SIMPLE_TASK
4111 && ahd
->msgout_buf
[index
] <= MSG_IGN_WIDE_RESIDUE
) {
4113 /* Skip tag type and tag id or residue param*/
4116 /* Single byte message */
4117 if (type
== AHDMSG_1B
4118 && ahd
->msgout_index
> index
4119 && (ahd
->msgout_buf
[index
] == msgval
4120 || ((ahd
->msgout_buf
[index
] & MSG_IDENTIFYFLAG
) != 0
4121 && msgval
== MSG_IDENTIFYFLAG
)))
4133 * Wait for a complete incoming message, parse it, and respond accordingly.
4136 ahd_parse_msg(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
)
4138 struct ahd_initiator_tinfo
*tinfo
;
4139 struct ahd_tmode_tstate
*tstate
;
4144 done
= MSGLOOP_IN_PROG
;
4147 tinfo
= ahd_fetch_transinfo(ahd
, devinfo
->channel
, devinfo
->our_scsiid
,
4148 devinfo
->target
, &tstate
);
4151 * Parse as much of the message as is available,
4152 * rejecting it if we don't support it. When
4153 * the entire message is available and has been
4154 * handled, return MSGLOOP_MSGCOMPLETE, indicating
4155 * that we have parsed an entire message.
4157 * In the case of extended messages, we accept the length
4158 * byte outright and perform more checking once we know the
4159 * extended message type.
4161 switch (ahd
->msgin_buf
[0]) {
4162 case MSG_DISCONNECT
:
4163 case MSG_SAVEDATAPOINTER
:
4164 case MSG_CMDCOMPLETE
:
4165 case MSG_RESTOREPOINTERS
:
4166 case MSG_IGN_WIDE_RESIDUE
:
4168 * End our message loop as these are messages
4169 * the sequencer handles on its own.
4171 done
= MSGLOOP_TERMINATED
;
4173 case MSG_MESSAGE_REJECT
:
4174 response
= ahd_handle_msg_reject(ahd
, devinfo
);
4177 done
= MSGLOOP_MSGCOMPLETE
;
4181 /* Wait for enough of the message to begin validation */
4182 if (ahd
->msgin_index
< 2)
4184 switch (ahd
->msgin_buf
[2]) {
4192 if (ahd
->msgin_buf
[1] != MSG_EXT_SDTR_LEN
) {
4198 * Wait until we have both args before validating
4199 * and acting on this message.
4201 * Add one to MSG_EXT_SDTR_LEN to account for
4202 * the extended message preamble.
4204 if (ahd
->msgin_index
< (MSG_EXT_SDTR_LEN
+ 1))
4207 period
= ahd
->msgin_buf
[3];
4209 saved_offset
= offset
= ahd
->msgin_buf
[4];
4210 ahd_devlimited_syncrate(ahd
, tinfo
, &period
,
4211 &ppr_options
, devinfo
->role
);
4212 ahd_validate_offset(ahd
, tinfo
, period
, &offset
,
4213 tinfo
->curr
.width
, devinfo
->role
);
4215 printf("(%s:%c:%d:%d): Received "
4216 "SDTR period %x, offset %x\n\t"
4217 "Filtered to period %x, offset %x\n",
4218 ahd_name(ahd
), devinfo
->channel
,
4219 devinfo
->target
, devinfo
->lun
,
4220 ahd
->msgin_buf
[3], saved_offset
,
4223 ahd_set_syncrate(ahd
, devinfo
, period
,
4224 offset
, ppr_options
,
4225 AHD_TRANS_ACTIVE
|AHD_TRANS_GOAL
,
4229 * See if we initiated Sync Negotiation
4230 * and didn't have to fall down to async
4233 if (ahd_sent_msg(ahd
, AHDMSG_EXT
, MSG_EXT_SDTR
, TRUE
)) {
4235 if (saved_offset
!= offset
) {
4236 /* Went too low - force async */
4241 * Send our own SDTR in reply
4244 && devinfo
->role
== ROLE_INITIATOR
) {
4245 printf("(%s:%c:%d:%d): Target "
4247 ahd_name(ahd
), devinfo
->channel
,
4248 devinfo
->target
, devinfo
->lun
);
4250 ahd
->msgout_index
= 0;
4251 ahd
->msgout_len
= 0;
4252 ahd_construct_sdtr(ahd
, devinfo
,
4254 ahd
->msgout_index
= 0;
4257 done
= MSGLOOP_MSGCOMPLETE
;
4264 u_int sending_reply
;
4266 sending_reply
= FALSE
;
4267 if (ahd
->msgin_buf
[1] != MSG_EXT_WDTR_LEN
) {
4273 * Wait until we have our arg before validating
4274 * and acting on this message.
4276 * Add one to MSG_EXT_WDTR_LEN to account for
4277 * the extended message preamble.
4279 if (ahd
->msgin_index
< (MSG_EXT_WDTR_LEN
+ 1))
4282 bus_width
= ahd
->msgin_buf
[3];
4283 saved_width
= bus_width
;
4284 ahd_validate_width(ahd
, tinfo
, &bus_width
,
4287 printf("(%s:%c:%d:%d): Received WDTR "
4288 "%x filtered to %x\n",
4289 ahd_name(ahd
), devinfo
->channel
,
4290 devinfo
->target
, devinfo
->lun
,
4291 saved_width
, bus_width
);
4294 if (ahd_sent_msg(ahd
, AHDMSG_EXT
, MSG_EXT_WDTR
, TRUE
)) {
4296 * Don't send a WDTR back to the
4297 * target, since we asked first.
4298 * If the width went higher than our
4299 * request, reject it.
4301 if (saved_width
> bus_width
) {
4303 printf("(%s:%c:%d:%d): requested %dBit "
4304 "transfers. Rejecting...\n",
4305 ahd_name(ahd
), devinfo
->channel
,
4306 devinfo
->target
, devinfo
->lun
,
4307 8 * (0x01 << bus_width
));
4312 * Send our own WDTR in reply
4315 && devinfo
->role
== ROLE_INITIATOR
) {
4316 printf("(%s:%c:%d:%d): Target "
4318 ahd_name(ahd
), devinfo
->channel
,
4319 devinfo
->target
, devinfo
->lun
);
4321 ahd
->msgout_index
= 0;
4322 ahd
->msgout_len
= 0;
4323 ahd_construct_wdtr(ahd
, devinfo
, bus_width
);
4324 ahd
->msgout_index
= 0;
4326 sending_reply
= TRUE
;
4329 * After a wide message, we are async, but
4330 * some devices don't seem to honor this portion
4331 * of the spec. Force a renegotiation of the
4332 * sync component of our transfer agreement even
4333 * if our goal is async. By updating our width
4334 * after forcing the negotiation, we avoid
4335 * renegotiating for width.
4337 ahd_update_neg_request(ahd
, devinfo
, tstate
,
4338 tinfo
, AHD_NEG_ALWAYS
);
4339 ahd_set_width(ahd
, devinfo
, bus_width
,
4340 AHD_TRANS_ACTIVE
|AHD_TRANS_GOAL
,
4342 if (sending_reply
== FALSE
&& reject
== FALSE
) {
4345 * We will always have an SDTR to send.
4347 ahd
->msgout_index
= 0;
4348 ahd
->msgout_len
= 0;
4349 ahd_build_transfer_msg(ahd
, devinfo
);
4350 ahd
->msgout_index
= 0;
4353 done
= MSGLOOP_MSGCOMPLETE
;
4364 u_int saved_ppr_options
;
4366 if (ahd
->msgin_buf
[1] != MSG_EXT_PPR_LEN
) {
4372 * Wait until we have all args before validating
4373 * and acting on this message.
4375 * Add one to MSG_EXT_PPR_LEN to account for
4376 * the extended message preamble.
4378 if (ahd
->msgin_index
< (MSG_EXT_PPR_LEN
+ 1))
4381 period
= ahd
->msgin_buf
[3];
4382 offset
= ahd
->msgin_buf
[5];
4383 bus_width
= ahd
->msgin_buf
[6];
4384 saved_width
= bus_width
;
4385 ppr_options
= ahd
->msgin_buf
[7];
4387 * According to the spec, a DT only
4388 * period factor with no DT option
4389 * set implies async.
4391 if ((ppr_options
& MSG_EXT_PPR_DT_REQ
) == 0
4394 saved_ppr_options
= ppr_options
;
4395 saved_offset
= offset
;
4398 * Transfer options are only available if we
4399 * are negotiating wide.
4402 ppr_options
&= MSG_EXT_PPR_QAS_REQ
;
4404 ahd_validate_width(ahd
, tinfo
, &bus_width
,
4406 ahd_devlimited_syncrate(ahd
, tinfo
, &period
,
4407 &ppr_options
, devinfo
->role
);
4408 ahd_validate_offset(ahd
, tinfo
, period
, &offset
,
4409 bus_width
, devinfo
->role
);
4411 if (ahd_sent_msg(ahd
, AHDMSG_EXT
, MSG_EXT_PPR
, TRUE
)) {
4413 * If we are unable to do any of the
4414 * requested options (we went too low),
4415 * then we'll have to reject the message.
4417 if (saved_width
> bus_width
4418 || saved_offset
!= offset
4419 || saved_ppr_options
!= ppr_options
) {
4427 if (devinfo
->role
!= ROLE_TARGET
)
4428 printf("(%s:%c:%d:%d): Target "
4430 ahd_name(ahd
), devinfo
->channel
,
4431 devinfo
->target
, devinfo
->lun
);
4433 printf("(%s:%c:%d:%d): Initiator "
4435 ahd_name(ahd
), devinfo
->channel
,
4436 devinfo
->target
, devinfo
->lun
);
4437 ahd
->msgout_index
= 0;
4438 ahd
->msgout_len
= 0;
4439 ahd_construct_ppr(ahd
, devinfo
, period
, offset
,
4440 bus_width
, ppr_options
);
4441 ahd
->msgout_index
= 0;
4445 printf("(%s:%c:%d:%d): Received PPR width %x, "
4446 "period %x, offset %x,options %x\n"
4447 "\tFiltered to width %x, period %x, "
4448 "offset %x, options %x\n",
4449 ahd_name(ahd
), devinfo
->channel
,
4450 devinfo
->target
, devinfo
->lun
,
4451 saved_width
, ahd
->msgin_buf
[3],
4452 saved_offset
, saved_ppr_options
,
4453 bus_width
, period
, offset
, ppr_options
);
4455 ahd_set_width(ahd
, devinfo
, bus_width
,
4456 AHD_TRANS_ACTIVE
|AHD_TRANS_GOAL
,
4458 ahd_set_syncrate(ahd
, devinfo
, period
,
4459 offset
, ppr_options
,
4460 AHD_TRANS_ACTIVE
|AHD_TRANS_GOAL
,
4463 done
= MSGLOOP_MSGCOMPLETE
;
4467 /* Unknown extended message. Reject it. */
4473 #ifdef AHD_TARGET_MODE
4474 case MSG_BUS_DEV_RESET
:
4475 ahd_handle_devreset(ahd
, devinfo
, CAM_LUN_WILDCARD
,
4477 "Bus Device Reset Received",
4478 /*verbose_level*/0);
4480 done
= MSGLOOP_TERMINATED
;
4484 case MSG_CLEAR_QUEUE
:
4488 /* Target mode messages */
4489 if (devinfo
->role
!= ROLE_TARGET
) {
4493 tag
= SCB_LIST_NULL
;
4494 if (ahd
->msgin_buf
[0] == MSG_ABORT_TAG
)
4495 tag
= ahd_inb(ahd
, INITIATOR_TAG
);
4496 ahd_abort_scbs(ahd
, devinfo
->target
, devinfo
->channel
,
4497 devinfo
->lun
, tag
, ROLE_TARGET
,
4500 tstate
= ahd
->enabled_targets
[devinfo
->our_scsiid
];
4501 if (tstate
!= NULL
) {
4502 struct ahd_tmode_lstate
* lstate
;
4504 lstate
= tstate
->enabled_luns
[devinfo
->lun
];
4505 if (lstate
!= NULL
) {
4506 ahd_queue_lstate_event(ahd
, lstate
,
4507 devinfo
->our_scsiid
,
4510 ahd_send_lstate_events(ahd
, lstate
);
4514 done
= MSGLOOP_TERMINATED
;
4518 case MSG_QAS_REQUEST
:
4520 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
4521 printf("%s: QAS request. SCSISIGI == 0x%x\n",
4522 ahd_name(ahd
), ahd_inb(ahd
, SCSISIGI
));
4524 ahd
->msg_flags
|= MSG_FLAG_EXPECT_QASREJ_BUSFREE
;
4526 case MSG_TERM_IO_PROC
:
4534 * Setup to reject the message.
4536 ahd
->msgout_index
= 0;
4537 ahd
->msgout_len
= 1;
4538 ahd
->msgout_buf
[0] = MSG_MESSAGE_REJECT
;
4539 done
= MSGLOOP_MSGCOMPLETE
;
4543 if (done
!= MSGLOOP_IN_PROG
&& !response
)
4544 /* Clear the outgoing message buffer */
4545 ahd
->msgout_len
= 0;
4551 * Process a message reject message.
4554 ahd_handle_msg_reject(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
)
4557 * What we care about here is if we had an
4558 * outstanding SDTR or WDTR message for this
4559 * target. If we did, this is a signal that
4560 * the target is refusing negotiation.
4563 struct ahd_initiator_tinfo
*tinfo
;
4564 struct ahd_tmode_tstate
*tstate
;
4569 scb_index
= ahd_get_scbptr(ahd
);
4570 scb
= ahd_lookup_scb(ahd
, scb_index
);
4571 tinfo
= ahd_fetch_transinfo(ahd
, devinfo
->channel
,
4572 devinfo
->our_scsiid
,
4573 devinfo
->target
, &tstate
);
4574 /* Might be necessary */
4575 last_msg
= ahd_inb(ahd
, LAST_MSG
);
4577 if (ahd_sent_msg(ahd
, AHDMSG_EXT
, MSG_EXT_PPR
, /*full*/FALSE
)) {
4578 if (ahd_sent_msg(ahd
, AHDMSG_EXT
, MSG_EXT_PPR
, /*full*/TRUE
)
4579 && tinfo
->goal
.period
<= AHD_SYNCRATE_PACED
) {
4581 * Target may not like our SPI-4 PPR Options.
4582 * Attempt to negotiate 80MHz which will turn
4583 * off these options.
4586 printf("(%s:%c:%d:%d): PPR Rejected. "
4587 "Trying simple U160 PPR\n",
4588 ahd_name(ahd
), devinfo
->channel
,
4589 devinfo
->target
, devinfo
->lun
);
4591 tinfo
->goal
.period
= AHD_SYNCRATE_DT
;
4592 tinfo
->goal
.ppr_options
&= MSG_EXT_PPR_IU_REQ
4593 | MSG_EXT_PPR_QAS_REQ
4594 | MSG_EXT_PPR_DT_REQ
;
4597 * Target does not support the PPR message.
4598 * Attempt to negotiate SPI-2 style.
4601 printf("(%s:%c:%d:%d): PPR Rejected. "
4602 "Trying WDTR/SDTR\n",
4603 ahd_name(ahd
), devinfo
->channel
,
4604 devinfo
->target
, devinfo
->lun
);
4606 tinfo
->goal
.ppr_options
= 0;
4607 tinfo
->curr
.transport_version
= 2;
4608 tinfo
->goal
.transport_version
= 2;
4610 ahd
->msgout_index
= 0;
4611 ahd
->msgout_len
= 0;
4612 ahd_build_transfer_msg(ahd
, devinfo
);
4613 ahd
->msgout_index
= 0;
4615 } else if (ahd_sent_msg(ahd
, AHDMSG_EXT
, MSG_EXT_WDTR
, /*full*/FALSE
)) {
4617 /* note 8bit xfers */
4618 printf("(%s:%c:%d:%d): refuses WIDE negotiation. Using "
4619 "8bit transfers\n", ahd_name(ahd
),
4620 devinfo
->channel
, devinfo
->target
, devinfo
->lun
);
4621 ahd_set_width(ahd
, devinfo
, MSG_EXT_WDTR_BUS_8_BIT
,
4622 AHD_TRANS_ACTIVE
|AHD_TRANS_GOAL
,
4625 * No need to clear the sync rate. If the target
4626 * did not accept the command, our syncrate is
4627 * unaffected. If the target started the negotiation,
4628 * but rejected our response, we already cleared the
4629 * sync rate before sending our WDTR.
4631 if (tinfo
->goal
.offset
!= tinfo
->curr
.offset
) {
4633 /* Start the sync negotiation */
4634 ahd
->msgout_index
= 0;
4635 ahd
->msgout_len
= 0;
4636 ahd_build_transfer_msg(ahd
, devinfo
);
4637 ahd
->msgout_index
= 0;
4640 } else if (ahd_sent_msg(ahd
, AHDMSG_EXT
, MSG_EXT_SDTR
, /*full*/FALSE
)) {
4641 /* note asynch xfers and clear flag */
4642 ahd_set_syncrate(ahd
, devinfo
, /*period*/0,
4643 /*offset*/0, /*ppr_options*/0,
4644 AHD_TRANS_ACTIVE
|AHD_TRANS_GOAL
,
4646 printf("(%s:%c:%d:%d): refuses synchronous negotiation. "
4647 "Using asynchronous transfers\n",
4648 ahd_name(ahd
), devinfo
->channel
,
4649 devinfo
->target
, devinfo
->lun
);
4650 } else if ((scb
->hscb
->control
& MSG_SIMPLE_TASK
) != 0) {
4654 tag_type
= (scb
->hscb
->control
& MSG_SIMPLE_TASK
);
4656 if (tag_type
== MSG_SIMPLE_TASK
) {
4657 printf("(%s:%c:%d:%d): refuses tagged commands. "
4658 "Performing non-tagged I/O\n", ahd_name(ahd
),
4659 devinfo
->channel
, devinfo
->target
, devinfo
->lun
);
4660 ahd_set_tags(ahd
, devinfo
, AHD_QUEUE_NONE
);
4663 printf("(%s:%c:%d:%d): refuses %s tagged commands. "
4664 "Performing simple queue tagged I/O only\n",
4665 ahd_name(ahd
), devinfo
->channel
, devinfo
->target
,
4666 devinfo
->lun
, tag_type
== MSG_ORDERED_TASK
4667 ? "ordered" : "head of queue");
4668 ahd_set_tags(ahd
, devinfo
, AHD_QUEUE_BASIC
);
4673 * Resend the identify for this CCB as the target
4674 * may believe that the selection is invalid otherwise.
4676 ahd_outb(ahd
, SCB_CONTROL
,
4677 ahd_inb_scbram(ahd
, SCB_CONTROL
) & mask
);
4678 scb
->hscb
->control
&= mask
;
4679 ahd_set_transaction_tag(scb
, /*enabled*/FALSE
,
4680 /*type*/MSG_SIMPLE_TASK
);
4681 ahd_outb(ahd
, MSG_OUT
, MSG_IDENTIFYFLAG
);
4682 ahd_assert_atn(ahd
);
4683 ahd_busy_tcl(ahd
, BUILD_TCL(scb
->hscb
->scsiid
, devinfo
->lun
),
4687 * Requeue all tagged commands for this target
4688 * currently in our posession so they can be
4689 * converted to untagged commands.
4691 ahd_search_qinfifo(ahd
, SCB_GET_TARGET(ahd
, scb
),
4692 SCB_GET_CHANNEL(ahd
, scb
),
4693 SCB_GET_LUN(scb
), /*tag*/SCB_LIST_NULL
,
4694 ROLE_INITIATOR
, CAM_REQUEUE_REQ
,
4696 } else if (ahd_sent_msg(ahd
, AHDMSG_1B
, MSG_IDENTIFYFLAG
, TRUE
)) {
4698 * Most likely the device believes that we had
4699 * previously negotiated packetized.
4701 ahd
->msg_flags
|= MSG_FLAG_EXPECT_PPR_BUSFREE
4702 | MSG_FLAG_IU_REQ_CHANGED
;
4704 ahd_force_renegotiation(ahd
, devinfo
);
4705 ahd
->msgout_index
= 0;
4706 ahd
->msgout_len
= 0;
4707 ahd_build_transfer_msg(ahd
, devinfo
);
4708 ahd
->msgout_index
= 0;
4712 * Otherwise, we ignore it.
4714 printf("%s:%c:%d: Message reject for %x -- ignored\n",
4715 ahd_name(ahd
), devinfo
->channel
, devinfo
->target
,
4722 * Process an ingnore wide residue message.
4725 ahd_handle_ign_wide_residue(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
)
4730 scb_index
= ahd_get_scbptr(ahd
);
4731 scb
= ahd_lookup_scb(ahd
, scb_index
);
4733 * XXX Actually check data direction in the sequencer?
4734 * Perhaps add datadir to some spare bits in the hscb?
4736 if ((ahd_inb(ahd
, SEQ_FLAGS
) & DPHASE
) == 0
4737 || ahd_get_transfer_dir(scb
) != CAM_DIR_IN
) {
4739 * Ignore the message if we haven't
4740 * seen an appropriate data phase yet.
4744 * If the residual occurred on the last
4745 * transfer and the transfer request was
4746 * expected to end on an odd count, do
4747 * nothing. Otherwise, subtract a byte
4748 * and update the residual count accordingly.
4752 sgptr
= ahd_inb_scbram(ahd
, SCB_RESIDUAL_SGPTR
);
4753 if ((sgptr
& SG_LIST_NULL
) != 0
4754 && (ahd_inb_scbram(ahd
, SCB_TASK_ATTRIBUTE
)
4755 & SCB_XFERLEN_ODD
) != 0) {
4757 * If the residual occurred on the last
4758 * transfer and the transfer request was
4759 * expected to end on an odd count, do
4767 /* Pull in the rest of the sgptr */
4768 sgptr
= ahd_inl_scbram(ahd
, SCB_RESIDUAL_SGPTR
);
4769 data_cnt
= ahd_inl_scbram(ahd
, SCB_RESIDUAL_DATACNT
);
4770 if ((sgptr
& SG_LIST_NULL
) != 0) {
4772 * The residual data count is not updated
4773 * for the command run to completion case.
4774 * Explicitly zero the count.
4776 data_cnt
&= ~AHD_SG_LEN_MASK
;
4778 data_addr
= ahd_inq(ahd
, SHADDR
);
4781 sgptr
&= SG_PTR_MASK
;
4782 if ((ahd
->flags
& AHD_64BIT_ADDRESSING
) != 0) {
4783 struct ahd_dma64_seg
*sg
;
4785 sg
= ahd_sg_bus_to_virt(ahd
, scb
, sgptr
);
4788 * The residual sg ptr points to the next S/G
4789 * to load so we must go back one.
4792 sglen
= ahd_le32toh(sg
->len
) & AHD_SG_LEN_MASK
;
4793 if (sg
!= scb
->sg_list
4794 && sglen
< (data_cnt
& AHD_SG_LEN_MASK
)) {
4797 sglen
= ahd_le32toh(sg
->len
);
4799 * Preserve High Address and SG_LIST
4800 * bits while setting the count to 1.
4802 data_cnt
= 1|(sglen
&(~AHD_SG_LEN_MASK
));
4803 data_addr
= ahd_le64toh(sg
->addr
)
4804 + (sglen
& AHD_SG_LEN_MASK
)
4808 * Increment sg so it points to the
4812 sgptr
= ahd_sg_virt_to_bus(ahd
, scb
,
4816 struct ahd_dma_seg
*sg
;
4818 sg
= ahd_sg_bus_to_virt(ahd
, scb
, sgptr
);
4821 * The residual sg ptr points to the next S/G
4822 * to load so we must go back one.
4825 sglen
= ahd_le32toh(sg
->len
) & AHD_SG_LEN_MASK
;
4826 if (sg
!= scb
->sg_list
4827 && sglen
< (data_cnt
& AHD_SG_LEN_MASK
)) {
4830 sglen
= ahd_le32toh(sg
->len
);
4832 * Preserve High Address and SG_LIST
4833 * bits while setting the count to 1.
4835 data_cnt
= 1|(sglen
&(~AHD_SG_LEN_MASK
));
4836 data_addr
= ahd_le32toh(sg
->addr
)
4837 + (sglen
& AHD_SG_LEN_MASK
)
4841 * Increment sg so it points to the
4845 sgptr
= ahd_sg_virt_to_bus(ahd
, scb
,
4850 * Toggle the "oddness" of the transfer length
4851 * to handle this mid-transfer ignore wide
4852 * residue. This ensures that the oddness is
4853 * correct for subsequent data transfers.
4855 ahd_outb(ahd
, SCB_TASK_ATTRIBUTE
,
4856 ahd_inb_scbram(ahd
, SCB_TASK_ATTRIBUTE
)
4859 ahd_outl(ahd
, SCB_RESIDUAL_SGPTR
, sgptr
);
4860 ahd_outl(ahd
, SCB_RESIDUAL_DATACNT
, data_cnt
);
4862 * The FIFO's pointers will be updated if/when the
4863 * sequencer re-enters a data phase.
4871 * Reinitialize the data pointers for the active transfer
4872 * based on its current residual.
4875 ahd_reinitialize_dataptrs(struct ahd_softc
*ahd
)
4878 ahd_mode_state saved_modes
;
4885 AHD_ASSERT_MODES(ahd
, AHD_MODE_DFF0_MSK
|AHD_MODE_DFF1_MSK
,
4886 AHD_MODE_DFF0_MSK
|AHD_MODE_DFF1_MSK
);
4888 scb_index
= ahd_get_scbptr(ahd
);
4889 scb
= ahd_lookup_scb(ahd
, scb_index
);
4892 * Release and reacquire the FIFO so we
4893 * have a clean slate.
4895 ahd_outb(ahd
, DFFSXFRCTL
, CLRCHN
);
4897 while (--wait
&& !(ahd_inb(ahd
, MDFFSTAT
) & FIFOFREE
))
4900 ahd_print_path(ahd
, scb
);
4901 printf("ahd_reinitialize_dataptrs: Forcing FIFO free.\n");
4902 ahd_outb(ahd
, DFFSXFRCTL
, RSTCHN
|CLRSHCNT
);
4904 saved_modes
= ahd_save_modes(ahd
);
4905 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
4906 ahd_outb(ahd
, DFFSTAT
,
4907 ahd_inb(ahd
, DFFSTAT
)
4908 | (saved_modes
== 0x11 ? CURRFIFO_1
: CURRFIFO_0
));
4911 * Determine initial values for data_addr and data_cnt
4912 * for resuming the data phase.
4914 sgptr
= (ahd_inb_scbram(ahd
, SCB_RESIDUAL_SGPTR
+ 3) << 24)
4915 | (ahd_inb_scbram(ahd
, SCB_RESIDUAL_SGPTR
+ 2) << 16)
4916 | (ahd_inb_scbram(ahd
, SCB_RESIDUAL_SGPTR
+ 1) << 8)
4917 | ahd_inb_scbram(ahd
, SCB_RESIDUAL_SGPTR
);
4918 sgptr
&= SG_PTR_MASK
;
4920 resid
= (ahd_inb_scbram(ahd
, SCB_RESIDUAL_DATACNT
+ 2) << 16)
4921 | (ahd_inb_scbram(ahd
, SCB_RESIDUAL_DATACNT
+ 1) << 8)
4922 | ahd_inb_scbram(ahd
, SCB_RESIDUAL_DATACNT
);
4924 if ((ahd
->flags
& AHD_64BIT_ADDRESSING
) != 0) {
4925 struct ahd_dma64_seg
*sg
;
4927 sg
= ahd_sg_bus_to_virt(ahd
, scb
, sgptr
);
4929 /* The residual sg_ptr always points to the next sg */
4932 dataptr
= ahd_le64toh(sg
->addr
)
4933 + (ahd_le32toh(sg
->len
) & AHD_SG_LEN_MASK
)
4935 ahd_outb(ahd
, HADDR
+ 7, dataptr
>> 56);
4936 ahd_outb(ahd
, HADDR
+ 6, dataptr
>> 48);
4937 ahd_outb(ahd
, HADDR
+ 5, dataptr
>> 40);
4938 ahd_outb(ahd
, HADDR
+ 4, dataptr
>> 32);
4940 struct ahd_dma_seg
*sg
;
4942 sg
= ahd_sg_bus_to_virt(ahd
, scb
, sgptr
);
4944 /* The residual sg_ptr always points to the next sg */
4947 dataptr
= ahd_le32toh(sg
->addr
)
4948 + (ahd_le32toh(sg
->len
) & AHD_SG_LEN_MASK
)
4950 ahd_outb(ahd
, HADDR
+ 4,
4951 (ahd_le32toh(sg
->len
) & ~AHD_SG_LEN_MASK
) >> 24);
4953 ahd_outb(ahd
, HADDR
+ 3, dataptr
>> 24);
4954 ahd_outb(ahd
, HADDR
+ 2, dataptr
>> 16);
4955 ahd_outb(ahd
, HADDR
+ 1, dataptr
>> 8);
4956 ahd_outb(ahd
, HADDR
, dataptr
);
4957 ahd_outb(ahd
, HCNT
+ 2, resid
>> 16);
4958 ahd_outb(ahd
, HCNT
+ 1, resid
>> 8);
4959 ahd_outb(ahd
, HCNT
, resid
);
4963 * Handle the effects of issuing a bus device reset message.
4966 ahd_handle_devreset(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
,
4967 u_int lun
, cam_status status
, char *message
,
4970 #ifdef AHD_TARGET_MODE
4971 struct ahd_tmode_tstate
* tstate
;
4975 found
= ahd_abort_scbs(ahd
, devinfo
->target
, devinfo
->channel
,
4976 lun
, SCB_LIST_NULL
, devinfo
->role
,
4979 #ifdef AHD_TARGET_MODE
4981 * Send an immediate notify ccb to all target mord peripheral
4982 * drivers affected by this action.
4984 tstate
= ahd
->enabled_targets
[devinfo
->our_scsiid
];
4985 if (tstate
!= NULL
) {
4989 if (lun
!= CAM_LUN_WILDCARD
) {
4991 max_lun
= AHD_NUM_LUNS
- 1;
4996 for (cur_lun
<= max_lun
; cur_lun
++) {
4997 struct ahd_tmode_lstate
* lstate
;
4999 lstate
= tstate
->enabled_luns
[cur_lun
];
5003 ahd_queue_lstate_event(ahd
, lstate
, devinfo
->our_scsiid
,
5004 MSG_BUS_DEV_RESET
, /*arg*/0);
5005 ahd_send_lstate_events(ahd
, lstate
);
5011 * Go back to async/narrow transfers and renegotiate.
5013 ahd_set_width(ahd
, devinfo
, MSG_EXT_WDTR_BUS_8_BIT
,
5014 AHD_TRANS_CUR
, /*paused*/TRUE
);
5015 ahd_set_syncrate(ahd
, devinfo
, /*period*/0, /*offset*/0,
5016 /*ppr_options*/0, AHD_TRANS_CUR
, /*paused*/TRUE
);
5018 ahd_send_async(ahd
, devinfo
->channel
, devinfo
->target
,
5019 lun
, AC_SENT_BDR
, NULL
);
5022 && (verbose_level
<= bootverbose
))
5023 printf("%s: %s on %c:%d. %d SCBs aborted\n", ahd_name(ahd
),
5024 message
, devinfo
->channel
, devinfo
->target
, found
);
5027 #ifdef AHD_TARGET_MODE
5029 ahd_setup_target_msgin(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
,
5034 * To facilitate adding multiple messages together,
5035 * each routine should increment the index and len
5036 * variables instead of setting them explicitly.
5038 ahd
->msgout_index
= 0;
5039 ahd
->msgout_len
= 0;
5041 if (scb
!= NULL
&& (scb
->flags
& SCB_AUTO_NEGOTIATE
) != 0)
5042 ahd_build_transfer_msg(ahd
, devinfo
);
5044 panic("ahd_intr: AWAITING target message with no message");
5046 ahd
->msgout_index
= 0;
5047 ahd
->msg_type
= MSG_TYPE_TARGET_MSGIN
;
5050 /**************************** Initialization **********************************/
5052 ahd_sglist_size(struct ahd_softc
*ahd
)
5054 bus_size_t list_size
;
5056 list_size
= sizeof(struct ahd_dma_seg
) * AHD_NSEG
;
5057 if ((ahd
->flags
& AHD_64BIT_ADDRESSING
) != 0)
5058 list_size
= sizeof(struct ahd_dma64_seg
) * AHD_NSEG
;
5063 * Calculate the optimum S/G List allocation size. S/G elements used
5064 * for a given transaction must be physically contiguous. Assume the
5065 * OS will allocate full pages to us, so it doesn't make sense to request
5069 ahd_sglist_allocsize(struct ahd_softc
*ahd
)
5071 bus_size_t sg_list_increment
;
5072 bus_size_t sg_list_size
;
5073 bus_size_t max_list_size
;
5074 bus_size_t best_list_size
;
5076 /* Start out with the minimum required for AHD_NSEG. */
5077 sg_list_increment
= ahd_sglist_size(ahd
);
5078 sg_list_size
= sg_list_increment
;
5080 /* Get us as close as possible to a page in size. */
5081 while ((sg_list_size
+ sg_list_increment
) <= PAGE_SIZE
)
5082 sg_list_size
+= sg_list_increment
;
5085 * Try to reduce the amount of wastage by allocating
5088 best_list_size
= sg_list_size
;
5089 max_list_size
= roundup(sg_list_increment
, PAGE_SIZE
);
5090 if (max_list_size
< 4 * PAGE_SIZE
)
5091 max_list_size
= 4 * PAGE_SIZE
;
5092 if (max_list_size
> (AHD_SCB_MAX_ALLOC
* sg_list_increment
))
5093 max_list_size
= (AHD_SCB_MAX_ALLOC
* sg_list_increment
);
5094 while ((sg_list_size
+ sg_list_increment
) <= max_list_size
5095 && (sg_list_size
% PAGE_SIZE
) != 0) {
5097 bus_size_t best_mod
;
5099 sg_list_size
+= sg_list_increment
;
5100 new_mod
= sg_list_size
% PAGE_SIZE
;
5101 best_mod
= best_list_size
% PAGE_SIZE
;
5102 if (new_mod
> best_mod
|| new_mod
== 0) {
5103 best_list_size
= sg_list_size
;
5106 return (best_list_size
);
5110 * Allocate a controller structure for a new device
5111 * and perform initial initializion.
5114 ahd_alloc(void *platform_arg
, char *name
)
5116 struct ahd_softc
*ahd
;
5119 ahd
= malloc(sizeof(*ahd
), M_DEVBUF
, M_NOWAIT
);
5121 printf("aic7xxx: cannot malloc softc!\n");
5122 free(name
, M_DEVBUF
);
5126 ahd
= device_get_softc((device_t
)platform_arg
);
5128 memset(ahd
, 0, sizeof(*ahd
));
5129 ahd
->seep_config
= malloc(sizeof(*ahd
->seep_config
),
5130 M_DEVBUF
, M_NOWAIT
);
5131 if (ahd
->seep_config
== NULL
) {
5133 free(ahd
, M_DEVBUF
);
5135 free(name
, M_DEVBUF
);
5138 LIST_INIT(&ahd
->pending_scbs
);
5139 /* We don't know our unit number until the OSM sets it */
5142 ahd
->description
= NULL
;
5143 ahd
->bus_description
= NULL
;
5145 ahd
->chip
= AHD_NONE
;
5146 ahd
->features
= AHD_FENONE
;
5147 ahd
->bugs
= AHD_BUGNONE
;
5148 ahd
->flags
= AHD_SPCHK_ENB_A
|AHD_RESET_BUS_A
|AHD_TERM_ENB_A
5149 | AHD_EXTENDED_TRANS_A
|AHD_STPWLEVEL_A
;
5150 ahd_timer_init(&ahd
->reset_timer
);
5151 ahd_timer_init(&ahd
->stat_timer
);
5152 ahd
->int_coalescing_timer
= AHD_INT_COALESCING_TIMER_DEFAULT
;
5153 ahd
->int_coalescing_maxcmds
= AHD_INT_COALESCING_MAXCMDS_DEFAULT
;
5154 ahd
->int_coalescing_mincmds
= AHD_INT_COALESCING_MINCMDS_DEFAULT
;
5155 ahd
->int_coalescing_threshold
= AHD_INT_COALESCING_THRESHOLD_DEFAULT
;
5156 ahd
->int_coalescing_stop_threshold
=
5157 AHD_INT_COALESCING_STOP_THRESHOLD_DEFAULT
;
5159 if (ahd_platform_alloc(ahd
, platform_arg
) != 0) {
5164 if ((ahd_debug
& AHD_SHOW_MEMORY
) != 0) {
5165 printf("%s: scb size = 0x%x, hscb size = 0x%x\n",
5166 ahd_name(ahd
), (u_int
)sizeof(struct scb
),
5167 (u_int
)sizeof(struct hardware_scb
));
5174 ahd_softc_init(struct ahd_softc
*ahd
)
5183 ahd_softc_insert(struct ahd_softc
*ahd
)
5185 struct ahd_softc
*list_ahd
;
5187 #if AHD_PCI_CONFIG > 0
5189 * Second Function PCI devices need to inherit some
5190 * settings from function 0.
5192 if ((ahd
->features
& AHD_MULTI_FUNC
) != 0) {
5193 TAILQ_FOREACH(list_ahd
, &ahd_tailq
, links
) {
5194 ahd_dev_softc_t list_pci
;
5195 ahd_dev_softc_t pci
;
5197 list_pci
= list_ahd
->dev_softc
;
5198 pci
= ahd
->dev_softc
;
5199 if (ahd_get_pci_slot(list_pci
) == ahd_get_pci_slot(pci
)
5200 && ahd_get_pci_bus(list_pci
) == ahd_get_pci_bus(pci
)) {
5201 struct ahd_softc
*master
;
5202 struct ahd_softc
*slave
;
5204 if (ahd_get_pci_function(list_pci
) == 0) {
5211 slave
->flags
&= ~AHD_BIOS_ENABLED
;
5213 master
->flags
& AHD_BIOS_ENABLED
;
5221 * Insertion sort into our list of softcs.
5223 list_ahd
= TAILQ_FIRST(&ahd_tailq
);
5224 while (list_ahd
!= NULL
5225 && ahd_softc_comp(ahd
, list_ahd
) <= 0)
5226 list_ahd
= TAILQ_NEXT(list_ahd
, links
);
5227 if (list_ahd
!= NULL
)
5228 TAILQ_INSERT_BEFORE(list_ahd
, ahd
, links
);
5230 TAILQ_INSERT_TAIL(&ahd_tailq
, ahd
, links
);
5235 * Verify that the passed in softc pointer is for a
5236 * controller that is still configured.
5239 ahd_find_softc(struct ahd_softc
*ahd
)
5241 struct ahd_softc
*list_ahd
;
5243 TAILQ_FOREACH(list_ahd
, &ahd_tailq
, links
) {
5244 if (list_ahd
== ahd
)
5251 ahd_set_unit(struct ahd_softc
*ahd
, int unit
)
5257 ahd_set_name(struct ahd_softc
*ahd
, char *name
)
5259 if (ahd
->name
!= NULL
)
5260 free(ahd
->name
, M_DEVBUF
);
5265 ahd_free(struct ahd_softc
*ahd
)
5269 switch (ahd
->init_level
) {
5275 ahd_dmamap_unload(ahd
, ahd
->shared_data_dmat
,
5276 ahd
->shared_data_dmamap
);
5279 ahd_dmamem_free(ahd
, ahd
->shared_data_dmat
, ahd
->qoutfifo
,
5280 ahd
->shared_data_dmamap
);
5281 ahd_dmamap_destroy(ahd
, ahd
->shared_data_dmat
,
5282 ahd
->shared_data_dmamap
);
5285 ahd_dma_tag_destroy(ahd
, ahd
->shared_data_dmat
);
5288 ahd_dma_tag_destroy(ahd
, ahd
->buffer_dmat
);
5296 ahd_dma_tag_destroy(ahd
, ahd
->parent_dmat
);
5298 ahd_platform_free(ahd
);
5299 ahd_fini_scbdata(ahd
);
5300 for (i
= 0; i
< AHD_NUM_TARGETS
; i
++) {
5301 struct ahd_tmode_tstate
*tstate
;
5303 tstate
= ahd
->enabled_targets
[i
];
5304 if (tstate
!= NULL
) {
5305 #ifdef AHD_TARGET_MODE
5308 for (j
= 0; j
< AHD_NUM_LUNS
; j
++) {
5309 struct ahd_tmode_lstate
*lstate
;
5311 lstate
= tstate
->enabled_luns
[j
];
5312 if (lstate
!= NULL
) {
5313 xpt_free_path(lstate
->path
);
5314 free(lstate
, M_DEVBUF
);
5318 free(tstate
, M_DEVBUF
);
5321 #ifdef AHD_TARGET_MODE
5322 if (ahd
->black_hole
!= NULL
) {
5323 xpt_free_path(ahd
->black_hole
->path
);
5324 free(ahd
->black_hole
, M_DEVBUF
);
5327 if (ahd
->name
!= NULL
)
5328 free(ahd
->name
, M_DEVBUF
);
5329 if (ahd
->seep_config
!= NULL
)
5330 free(ahd
->seep_config
, M_DEVBUF
);
5331 if (ahd
->saved_stack
!= NULL
)
5332 free(ahd
->saved_stack
, M_DEVBUF
);
5334 free(ahd
, M_DEVBUF
);
5340 ahd_shutdown(void *arg
)
5342 struct ahd_softc
*ahd
;
5344 ahd
= (struct ahd_softc
*)arg
;
5347 * Stop periodic timer callbacks.
5349 ahd_timer_stop(&ahd
->reset_timer
);
5350 ahd_timer_stop(&ahd
->stat_timer
);
5352 /* This will reset most registers to 0, but not all */
5353 ahd_reset(ahd
, /*reinit*/FALSE
);
5357 * Reset the controller and record some information about it
5358 * that is only available just after a reset. If "reinit" is
5359 * non-zero, this reset occured after initial configuration
5360 * and the caller requests that the chip be fully reinitialized
5361 * to a runable state. Chip interrupts are *not* enabled after
5362 * a reinitialization. The caller must enable interrupts via
5363 * ahd_intr_enable().
5366 ahd_reset(struct ahd_softc
*ahd
, int reinit
)
5373 * Preserve the value of the SXFRCTL1 register for all channels.
5374 * It contains settings that affect termination and we don't want
5375 * to disturb the integrity of the bus.
5378 ahd_update_modes(ahd
);
5379 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
5380 sxfrctl1
= ahd_inb(ahd
, SXFRCTL1
);
5382 cmd
= ahd_pci_read_config(ahd
->dev_softc
, PCIR_COMMAND
, /*bytes*/2);
5383 if ((ahd
->bugs
& AHD_PCIX_CHIPRST_BUG
) != 0) {
5388 * During the assertion of CHIPRST, the chip
5389 * does not disable its parity logic prior to
5390 * the start of the reset. This may cause a
5391 * parity error to be detected and thus a
5392 * spurious SERR or PERR assertion. Disble
5393 * PERR and SERR responses during the CHIPRST.
5395 mod_cmd
= cmd
& ~(PCIM_CMD_PERRESPEN
|PCIM_CMD_SERRESPEN
);
5396 ahd_pci_write_config(ahd
->dev_softc
, PCIR_COMMAND
,
5397 mod_cmd
, /*bytes*/2);
5399 ahd_outb(ahd
, HCNTRL
, CHIPRST
| ahd
->pause
);
5402 * Ensure that the reset has finished. We delay 1000us
5403 * prior to reading the register to make sure the chip
5404 * has sufficiently completed its reset to handle register
5410 } while (--wait
&& !(ahd_inb(ahd
, HCNTRL
) & CHIPRSTACK
));
5413 printf("%s: WARNING - Failed chip reset! "
5414 "Trying to initialize anyway.\n", ahd_name(ahd
));
5416 ahd_outb(ahd
, HCNTRL
, ahd
->pause
);
5418 if ((ahd
->bugs
& AHD_PCIX_CHIPRST_BUG
) != 0) {
5420 * Clear any latched PCI error status and restore
5421 * previous SERR and PERR response enables.
5423 ahd_pci_write_config(ahd
->dev_softc
, PCIR_STATUS
+ 1,
5425 ahd_pci_write_config(ahd
->dev_softc
, PCIR_COMMAND
,
5430 * Mode should be SCSI after a chip reset, but lets
5431 * set it just to be safe. We touch the MODE_PTR
5432 * register directly so as to bypass the lazy update
5433 * code in ahd_set_modes().
5435 ahd_known_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
5436 ahd_outb(ahd
, MODE_PTR
,
5437 ahd_build_mode_state(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
));
5442 * We must always initialize STPWEN to 1 before we
5443 * restore the saved values. STPWEN is initialized
5444 * to a tri-state condition which can only be cleared
5447 ahd_outb(ahd
, SXFRCTL1
, sxfrctl1
|STPWEN
);
5448 ahd_outb(ahd
, SXFRCTL1
, sxfrctl1
);
5450 /* Determine chip configuration */
5451 ahd
->features
&= ~AHD_WIDE
;
5452 if ((ahd_inb(ahd
, SBLKCTL
) & SELWIDE
) != 0)
5453 ahd
->features
|= AHD_WIDE
;
5456 * If a recovery action has forced a chip reset,
5457 * re-initialize the chip to our liking.
5466 * Determine the number of SCBs available on the controller
5469 ahd_probe_scbs(struct ahd_softc
*ahd
) {
5472 AHD_ASSERT_MODES(ahd
, ~(AHD_MODE_UNKNOWN_MSK
|AHD_MODE_CFG_MSK
),
5473 ~(AHD_MODE_UNKNOWN_MSK
|AHD_MODE_CFG_MSK
));
5474 for (i
= 0; i
< AHD_SCB_MAX
; i
++) {
5477 ahd_set_scbptr(ahd
, i
);
5478 ahd_outw(ahd
, SCB_BASE
, i
);
5479 for (j
= 2; j
< 64; j
++)
5480 ahd_outb(ahd
, SCB_BASE
+j
, 0);
5481 /* Start out life as unallocated (needing an abort) */
5482 ahd_outb(ahd
, SCB_CONTROL
, MK_MESSAGE
);
5483 if (ahd_inw_scbram(ahd
, SCB_BASE
) != i
)
5485 ahd_set_scbptr(ahd
, 0);
5486 if (ahd_inw_scbram(ahd
, SCB_BASE
) != 0)
5493 ahd_dmamap_cb(void *arg
, bus_dma_segment_t
*segs
, int nseg
, int error
)
5497 baddr
= (dma_addr_t
*)arg
;
5498 *baddr
= segs
->ds_addr
;
5502 ahd_initialize_hscbs(struct ahd_softc
*ahd
)
5506 for (i
= 0; i
< ahd
->scb_data
.maxhscbs
; i
++) {
5507 ahd_set_scbptr(ahd
, i
);
5509 /* Clear the control byte. */
5510 ahd_outb(ahd
, SCB_CONTROL
, 0);
5512 /* Set the next pointer */
5513 ahd_outw(ahd
, SCB_NEXT
, SCB_LIST_NULL
);
5518 ahd_init_scbdata(struct ahd_softc
*ahd
)
5520 struct scb_data
*scb_data
;
5523 scb_data
= &ahd
->scb_data
;
5524 TAILQ_INIT(&scb_data
->free_scbs
);
5525 for (i
= 0; i
< AHD_NUM_TARGETS
* AHD_NUM_LUNS_NONPKT
; i
++)
5526 LIST_INIT(&scb_data
->free_scb_lists
[i
]);
5527 LIST_INIT(&scb_data
->any_dev_free_scb_list
);
5528 SLIST_INIT(&scb_data
->hscb_maps
);
5529 SLIST_INIT(&scb_data
->sg_maps
);
5530 SLIST_INIT(&scb_data
->sense_maps
);
5532 /* Determine the number of hardware SCBs and initialize them */
5533 scb_data
->maxhscbs
= ahd_probe_scbs(ahd
);
5534 if (scb_data
->maxhscbs
== 0) {
5535 printf("%s: No SCB space found\n", ahd_name(ahd
));
5539 ahd_initialize_hscbs(ahd
);
5542 * Create our DMA tags. These tags define the kinds of device
5543 * accessible memory allocations and memory mappings we will
5544 * need to perform during normal operation.
5546 * Unless we need to further restrict the allocation, we rely
5547 * on the restrictions of the parent dmat, hence the common
5548 * use of MAXADDR and MAXSIZE.
5551 /* DMA tag for our hardware scb structures */
5552 if (ahd_dma_tag_create(ahd
, ahd
->parent_dmat
, /*alignment*/1,
5553 /*boundary*/BUS_SPACE_MAXADDR_32BIT
+ 1,
5554 /*lowaddr*/BUS_SPACE_MAXADDR_32BIT
,
5555 /*highaddr*/BUS_SPACE_MAXADDR
,
5556 /*filter*/NULL
, /*filterarg*/NULL
,
5557 PAGE_SIZE
, /*nsegments*/1,
5558 /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT
,
5559 /*flags*/0, &scb_data
->hscb_dmat
) != 0) {
5563 scb_data
->init_level
++;
5565 /* DMA tag for our S/G structures. */
5566 if (ahd_dma_tag_create(ahd
, ahd
->parent_dmat
, /*alignment*/8,
5567 /*boundary*/BUS_SPACE_MAXADDR_32BIT
+ 1,
5568 /*lowaddr*/BUS_SPACE_MAXADDR_32BIT
,
5569 /*highaddr*/BUS_SPACE_MAXADDR
,
5570 /*filter*/NULL
, /*filterarg*/NULL
,
5571 ahd_sglist_allocsize(ahd
), /*nsegments*/1,
5572 /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT
,
5573 /*flags*/0, &scb_data
->sg_dmat
) != 0) {
5577 if ((ahd_debug
& AHD_SHOW_MEMORY
) != 0)
5578 printf("%s: ahd_sglist_allocsize = 0x%x\n", ahd_name(ahd
),
5579 ahd_sglist_allocsize(ahd
));
5582 scb_data
->init_level
++;
5584 /* DMA tag for our sense buffers. We allocate in page sized chunks */
5585 if (ahd_dma_tag_create(ahd
, ahd
->parent_dmat
, /*alignment*/1,
5586 /*boundary*/BUS_SPACE_MAXADDR_32BIT
+ 1,
5587 /*lowaddr*/BUS_SPACE_MAXADDR_32BIT
,
5588 /*highaddr*/BUS_SPACE_MAXADDR
,
5589 /*filter*/NULL
, /*filterarg*/NULL
,
5590 PAGE_SIZE
, /*nsegments*/1,
5591 /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT
,
5592 /*flags*/0, &scb_data
->sense_dmat
) != 0) {
5596 scb_data
->init_level
++;
5598 /* Perform initial CCB allocation */
5599 ahd_alloc_scbs(ahd
);
5601 if (scb_data
->numscbs
== 0) {
5602 printf("%s: ahd_init_scbdata - "
5603 "Unable to allocate initial scbs\n",
5609 * Note that we were successfull
5619 ahd_find_scb_by_tag(struct ahd_softc
*ahd
, u_int tag
)
5624 * Look on the pending list.
5626 LIST_FOREACH(scb
, &ahd
->pending_scbs
, pending_links
) {
5627 if (SCB_GET_TAG(scb
) == tag
)
5632 * Then on all of the collision free lists.
5634 TAILQ_FOREACH(scb
, &ahd
->scb_data
.free_scbs
, links
.tqe
) {
5635 struct scb
*list_scb
;
5639 if (SCB_GET_TAG(list_scb
) == tag
)
5641 list_scb
= LIST_NEXT(list_scb
, collision_links
);
5646 * And finally on the generic free list.
5648 LIST_FOREACH(scb
, &ahd
->scb_data
.any_dev_free_scb_list
, links
.le
) {
5649 if (SCB_GET_TAG(scb
) == tag
)
5657 ahd_fini_scbdata(struct ahd_softc
*ahd
)
5659 struct scb_data
*scb_data
;
5661 scb_data
= &ahd
->scb_data
;
5662 if (scb_data
== NULL
)
5665 switch (scb_data
->init_level
) {
5669 struct map_node
*sns_map
;
5671 while ((sns_map
= SLIST_FIRST(&scb_data
->sense_maps
)) != NULL
) {
5672 SLIST_REMOVE_HEAD(&scb_data
->sense_maps
, links
);
5673 ahd_dmamap_unload(ahd
, scb_data
->sense_dmat
,
5675 ahd_dmamem_free(ahd
, scb_data
->sense_dmat
,
5676 sns_map
->vaddr
, sns_map
->dmamap
);
5677 free(sns_map
, M_DEVBUF
);
5679 ahd_dma_tag_destroy(ahd
, scb_data
->sense_dmat
);
5684 struct map_node
*sg_map
;
5686 while ((sg_map
= SLIST_FIRST(&scb_data
->sg_maps
)) != NULL
) {
5687 SLIST_REMOVE_HEAD(&scb_data
->sg_maps
, links
);
5688 ahd_dmamap_unload(ahd
, scb_data
->sg_dmat
,
5690 ahd_dmamem_free(ahd
, scb_data
->sg_dmat
,
5691 sg_map
->vaddr
, sg_map
->dmamap
);
5692 free(sg_map
, M_DEVBUF
);
5694 ahd_dma_tag_destroy(ahd
, scb_data
->sg_dmat
);
5699 struct map_node
*hscb_map
;
5701 while ((hscb_map
= SLIST_FIRST(&scb_data
->hscb_maps
)) != NULL
) {
5702 SLIST_REMOVE_HEAD(&scb_data
->hscb_maps
, links
);
5703 ahd_dmamap_unload(ahd
, scb_data
->hscb_dmat
,
5705 ahd_dmamem_free(ahd
, scb_data
->hscb_dmat
,
5706 hscb_map
->vaddr
, hscb_map
->dmamap
);
5707 free(hscb_map
, M_DEVBUF
);
5709 ahd_dma_tag_destroy(ahd
, scb_data
->hscb_dmat
);
5722 * DSP filter Bypass must be enabled until the first selection
5723 * after a change in bus mode (Razor #491 and #493).
5726 ahd_setup_iocell_workaround(struct ahd_softc
*ahd
)
5728 ahd_mode_state saved_modes
;
5730 saved_modes
= ahd_save_modes(ahd
);
5731 ahd_set_modes(ahd
, AHD_MODE_CFG
, AHD_MODE_CFG
);
5732 ahd_outb(ahd
, DSPDATACTL
, ahd_inb(ahd
, DSPDATACTL
)
5733 | BYPASSENAB
| RCVROFFSTDIS
| XMITOFFSTDIS
);
5734 ahd_outb(ahd
, SIMODE0
, ahd_inb(ahd
, SIMODE0
) | (ENSELDO
|ENSELDI
));
5736 if ((ahd_debug
& AHD_SHOW_MISC
) != 0)
5737 printf("%s: Setting up iocell workaround\n", ahd_name(ahd
));
5739 ahd_restore_modes(ahd
, saved_modes
);
5740 ahd
->flags
&= ~AHD_HAD_FIRST_SEL
;
5744 ahd_iocell_first_selection(struct ahd_softc
*ahd
)
5746 ahd_mode_state saved_modes
;
5749 if ((ahd
->flags
& AHD_HAD_FIRST_SEL
) != 0)
5751 saved_modes
= ahd_save_modes(ahd
);
5752 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
5753 sblkctl
= ahd_inb(ahd
, SBLKCTL
);
5754 ahd_set_modes(ahd
, AHD_MODE_CFG
, AHD_MODE_CFG
);
5756 if ((ahd_debug
& AHD_SHOW_MISC
) != 0)
5757 printf("%s: iocell first selection\n", ahd_name(ahd
));
5759 if ((sblkctl
& ENAB40
) != 0) {
5760 ahd_outb(ahd
, DSPDATACTL
,
5761 ahd_inb(ahd
, DSPDATACTL
) & ~BYPASSENAB
);
5763 if ((ahd_debug
& AHD_SHOW_MISC
) != 0)
5764 printf("%s: BYPASS now disabled\n", ahd_name(ahd
));
5767 ahd_outb(ahd
, SIMODE0
, ahd_inb(ahd
, SIMODE0
) & ~(ENSELDO
|ENSELDI
));
5768 ahd_outb(ahd
, CLRINT
, CLRSCSIINT
);
5769 ahd_restore_modes(ahd
, saved_modes
);
5770 ahd
->flags
|= AHD_HAD_FIRST_SEL
;
5773 /*************************** SCB Management ***********************************/
5775 ahd_add_col_list(struct ahd_softc
*ahd
, struct scb
*scb
, u_int col_idx
)
5777 struct scb_list
*free_list
;
5778 struct scb_tailq
*free_tailq
;
5779 struct scb
*first_scb
;
5781 scb
->flags
|= SCB_ON_COL_LIST
;
5782 AHD_SET_SCB_COL_IDX(scb
, col_idx
);
5783 free_list
= &ahd
->scb_data
.free_scb_lists
[col_idx
];
5784 free_tailq
= &ahd
->scb_data
.free_scbs
;
5785 first_scb
= LIST_FIRST(free_list
);
5786 if (first_scb
!= NULL
) {
5787 LIST_INSERT_AFTER(first_scb
, scb
, collision_links
);
5789 LIST_INSERT_HEAD(free_list
, scb
, collision_links
);
5790 TAILQ_INSERT_TAIL(free_tailq
, scb
, links
.tqe
);
5795 ahd_rem_col_list(struct ahd_softc
*ahd
, struct scb
*scb
)
5797 struct scb_list
*free_list
;
5798 struct scb_tailq
*free_tailq
;
5799 struct scb
*first_scb
;
5802 scb
->flags
&= ~SCB_ON_COL_LIST
;
5803 col_idx
= AHD_GET_SCB_COL_IDX(ahd
, scb
);
5804 free_list
= &ahd
->scb_data
.free_scb_lists
[col_idx
];
5805 free_tailq
= &ahd
->scb_data
.free_scbs
;
5806 first_scb
= LIST_FIRST(free_list
);
5807 if (first_scb
== scb
) {
5808 struct scb
*next_scb
;
5811 * Maintain order in the collision free
5812 * lists for fairness if this device has
5813 * other colliding tags active.
5815 next_scb
= LIST_NEXT(scb
, collision_links
);
5816 if (next_scb
!= NULL
) {
5817 TAILQ_INSERT_AFTER(free_tailq
, scb
,
5818 next_scb
, links
.tqe
);
5820 TAILQ_REMOVE(free_tailq
, scb
, links
.tqe
);
5822 LIST_REMOVE(scb
, collision_links
);
5826 * Get a free scb. If there are none, see if we can allocate a new SCB.
5829 ahd_get_scb(struct ahd_softc
*ahd
, u_int col_idx
)
5836 TAILQ_FOREACH(scb
, &ahd
->scb_data
.free_scbs
, links
.tqe
) {
5837 if (AHD_GET_SCB_COL_IDX(ahd
, scb
) != col_idx
) {
5838 ahd_rem_col_list(ahd
, scb
);
5842 if ((scb
= LIST_FIRST(&ahd
->scb_data
.any_dev_free_scb_list
)) == NULL
) {
5846 ahd_alloc_scbs(ahd
);
5849 LIST_REMOVE(scb
, links
.le
);
5850 if (col_idx
!= AHD_NEVER_COL_IDX
5851 && (scb
->col_scb
!= NULL
)
5852 && (scb
->col_scb
->flags
& SCB_ACTIVE
) == 0) {
5853 LIST_REMOVE(scb
->col_scb
, links
.le
);
5854 ahd_add_col_list(ahd
, scb
->col_scb
, col_idx
);
5857 scb
->flags
|= SCB_ACTIVE
;
5862 * Return an SCB resource to the free list.
5865 ahd_free_scb(struct ahd_softc
*ahd
, struct scb
*scb
)
5868 /* Clean up for the next user */
5869 scb
->flags
= SCB_FLAG_NONE
;
5870 scb
->hscb
->control
= 0;
5871 ahd
->scb_data
.scbindex
[SCB_GET_TAG(scb
)] = NULL
;
5873 if (scb
->col_scb
== NULL
) {
5876 * No collision possible. Just free normally.
5878 LIST_INSERT_HEAD(&ahd
->scb_data
.any_dev_free_scb_list
,
5880 } else if ((scb
->col_scb
->flags
& SCB_ON_COL_LIST
) != 0) {
5883 * The SCB we might have collided with is on
5884 * a free collision list. Put both SCBs on
5887 ahd_rem_col_list(ahd
, scb
->col_scb
);
5888 LIST_INSERT_HEAD(&ahd
->scb_data
.any_dev_free_scb_list
,
5890 LIST_INSERT_HEAD(&ahd
->scb_data
.any_dev_free_scb_list
,
5891 scb
->col_scb
, links
.le
);
5892 } else if ((scb
->col_scb
->flags
5893 & (SCB_PACKETIZED
|SCB_ACTIVE
)) == SCB_ACTIVE
5894 && (scb
->col_scb
->hscb
->control
& TAG_ENB
) != 0) {
5897 * The SCB we might collide with on the next allocation
5898 * is still active in a non-packetized, tagged, context.
5899 * Put us on the SCB collision list.
5901 ahd_add_col_list(ahd
, scb
,
5902 AHD_GET_SCB_COL_IDX(ahd
, scb
->col_scb
));
5905 * The SCB we might collide with on the next allocation
5906 * is either active in a packetized context, or free.
5907 * Since we can't collide, put this SCB on the generic
5910 LIST_INSERT_HEAD(&ahd
->scb_data
.any_dev_free_scb_list
,
5914 ahd_platform_scb_free(ahd
, scb
);
5918 ahd_alloc_scbs(struct ahd_softc
*ahd
)
5920 struct scb_data
*scb_data
;
5921 struct scb
*next_scb
;
5922 struct hardware_scb
*hscb
;
5923 struct map_node
*hscb_map
;
5924 struct map_node
*sg_map
;
5925 struct map_node
*sense_map
;
5927 uint8_t *sense_data
;
5928 dma_addr_t hscb_busaddr
;
5929 dma_addr_t sg_busaddr
;
5930 dma_addr_t sense_busaddr
;
5934 scb_data
= &ahd
->scb_data
;
5935 if (scb_data
->numscbs
>= AHD_SCB_MAX_ALLOC
)
5936 /* Can't allocate any more */
5939 if (scb_data
->scbs_left
!= 0) {
5942 offset
= (PAGE_SIZE
/ sizeof(*hscb
)) - scb_data
->scbs_left
;
5943 hscb_map
= SLIST_FIRST(&scb_data
->hscb_maps
);
5944 hscb
= &((struct hardware_scb
*)hscb_map
->vaddr
)[offset
];
5945 hscb_busaddr
= hscb_map
->physaddr
+ (offset
* sizeof(*hscb
));
5947 hscb_map
= malloc(sizeof(*hscb_map
), M_DEVBUF
, M_NOWAIT
);
5949 if (hscb_map
== NULL
)
5952 /* Allocate the next batch of hardware SCBs */
5953 if (ahd_dmamem_alloc(ahd
, scb_data
->hscb_dmat
,
5954 (void **)&hscb_map
->vaddr
,
5955 BUS_DMA_NOWAIT
, &hscb_map
->dmamap
) != 0) {
5956 free(hscb_map
, M_DEVBUF
);
5960 SLIST_INSERT_HEAD(&scb_data
->hscb_maps
, hscb_map
, links
);
5962 ahd_dmamap_load(ahd
, scb_data
->hscb_dmat
, hscb_map
->dmamap
,
5963 hscb_map
->vaddr
, PAGE_SIZE
, ahd_dmamap_cb
,
5964 &hscb_map
->physaddr
, /*flags*/0);
5966 hscb
= (struct hardware_scb
*)hscb_map
->vaddr
;
5967 hscb_busaddr
= hscb_map
->physaddr
;
5968 scb_data
->scbs_left
= PAGE_SIZE
/ sizeof(*hscb
);
5971 if (scb_data
->sgs_left
!= 0) {
5974 offset
= ((ahd_sglist_allocsize(ahd
) / ahd_sglist_size(ahd
))
5975 - scb_data
->sgs_left
) * ahd_sglist_size(ahd
);
5976 sg_map
= SLIST_FIRST(&scb_data
->sg_maps
);
5977 segs
= sg_map
->vaddr
+ offset
;
5978 sg_busaddr
= sg_map
->physaddr
+ offset
;
5980 sg_map
= malloc(sizeof(*sg_map
), M_DEVBUF
, M_NOWAIT
);
5985 /* Allocate the next batch of S/G lists */
5986 if (ahd_dmamem_alloc(ahd
, scb_data
->sg_dmat
,
5987 (void **)&sg_map
->vaddr
,
5988 BUS_DMA_NOWAIT
, &sg_map
->dmamap
) != 0) {
5989 free(sg_map
, M_DEVBUF
);
5993 SLIST_INSERT_HEAD(&scb_data
->sg_maps
, sg_map
, links
);
5995 ahd_dmamap_load(ahd
, scb_data
->sg_dmat
, sg_map
->dmamap
,
5996 sg_map
->vaddr
, ahd_sglist_allocsize(ahd
),
5997 ahd_dmamap_cb
, &sg_map
->physaddr
, /*flags*/0);
5999 segs
= sg_map
->vaddr
;
6000 sg_busaddr
= sg_map
->physaddr
;
6001 scb_data
->sgs_left
=
6002 ahd_sglist_allocsize(ahd
) / ahd_sglist_size(ahd
);
6004 if (ahd_debug
& AHD_SHOW_MEMORY
)
6005 printf("Mapped SG data\n");
6009 if (scb_data
->sense_left
!= 0) {
6012 offset
= PAGE_SIZE
- (AHD_SENSE_BUFSIZE
* scb_data
->sense_left
);
6013 sense_map
= SLIST_FIRST(&scb_data
->sense_maps
);
6014 sense_data
= sense_map
->vaddr
+ offset
;
6015 sense_busaddr
= sense_map
->physaddr
+ offset
;
6017 sense_map
= malloc(sizeof(*sense_map
), M_DEVBUF
, M_NOWAIT
);
6019 if (sense_map
== NULL
)
6022 /* Allocate the next batch of sense buffers */
6023 if (ahd_dmamem_alloc(ahd
, scb_data
->sense_dmat
,
6024 (void **)&sense_map
->vaddr
,
6025 BUS_DMA_NOWAIT
, &sense_map
->dmamap
) != 0) {
6026 free(sense_map
, M_DEVBUF
);
6030 SLIST_INSERT_HEAD(&scb_data
->sense_maps
, sense_map
, links
);
6032 ahd_dmamap_load(ahd
, scb_data
->sense_dmat
, sense_map
->dmamap
,
6033 sense_map
->vaddr
, PAGE_SIZE
, ahd_dmamap_cb
,
6034 &sense_map
->physaddr
, /*flags*/0);
6036 sense_data
= sense_map
->vaddr
;
6037 sense_busaddr
= sense_map
->physaddr
;
6038 scb_data
->sense_left
= PAGE_SIZE
/ AHD_SENSE_BUFSIZE
;
6040 if (ahd_debug
& AHD_SHOW_MEMORY
)
6041 printf("Mapped sense data\n");
6045 newcount
= MIN(scb_data
->sense_left
, scb_data
->scbs_left
);
6046 newcount
= MIN(newcount
, scb_data
->sgs_left
);
6047 newcount
= MIN(newcount
, (AHD_SCB_MAX_ALLOC
- scb_data
->numscbs
));
6048 scb_data
->sense_left
-= newcount
;
6049 scb_data
->scbs_left
-= newcount
;
6050 scb_data
->sgs_left
-= newcount
;
6051 for (i
= 0; i
< newcount
; i
++) {
6054 struct scb_platform_data
*pdata
;
6058 next_scb
= (struct scb
*)malloc(sizeof(*next_scb
),
6059 M_DEVBUF
, M_NOWAIT
);
6060 if (next_scb
== NULL
)
6063 pdata
= (struct scb_platform_data
*)malloc(sizeof(*pdata
),
6064 M_DEVBUF
, M_NOWAIT
);
6065 if (pdata
== NULL
) {
6066 free(next_scb
, M_DEVBUF
);
6069 next_scb
->platform_data
= pdata
;
6070 next_scb
->hscb_map
= hscb_map
;
6071 next_scb
->sg_map
= sg_map
;
6072 next_scb
->sense_map
= sense_map
;
6073 next_scb
->sg_list
= segs
;
6074 next_scb
->sense_data
= sense_data
;
6075 next_scb
->sense_busaddr
= sense_busaddr
;
6076 memset(hscb
, 0, sizeof(*hscb
));
6077 next_scb
->hscb
= hscb
;
6078 hscb
->hscb_busaddr
= ahd_htole32(hscb_busaddr
);
6081 * The sequencer always starts with the second entry.
6082 * The first entry is embedded in the scb.
6084 next_scb
->sg_list_busaddr
= sg_busaddr
;
6085 if ((ahd
->flags
& AHD_64BIT_ADDRESSING
) != 0)
6086 next_scb
->sg_list_busaddr
6087 += sizeof(struct ahd_dma64_seg
);
6089 next_scb
->sg_list_busaddr
+= sizeof(struct ahd_dma_seg
);
6090 next_scb
->ahd_softc
= ahd
;
6091 next_scb
->flags
= SCB_FLAG_NONE
;
6093 error
= ahd_dmamap_create(ahd
, ahd
->buffer_dmat
, /*flags*/0,
6096 free(next_scb
, M_DEVBUF
);
6097 free(pdata
, M_DEVBUF
);
6101 next_scb
->hscb
->tag
= ahd_htole16(scb_data
->numscbs
);
6102 col_tag
= scb_data
->numscbs
^ 0x100;
6103 next_scb
->col_scb
= ahd_find_scb_by_tag(ahd
, col_tag
);
6104 if (next_scb
->col_scb
!= NULL
)
6105 next_scb
->col_scb
->col_scb
= next_scb
;
6106 ahd_free_scb(ahd
, next_scb
);
6108 hscb_busaddr
+= sizeof(*hscb
);
6109 segs
+= ahd_sglist_size(ahd
);
6110 sg_busaddr
+= ahd_sglist_size(ahd
);
6111 sense_data
+= AHD_SENSE_BUFSIZE
;
6112 sense_busaddr
+= AHD_SENSE_BUFSIZE
;
6113 scb_data
->numscbs
++;
6118 ahd_controller_info(struct ahd_softc
*ahd
, char *buf
)
6124 len
= sprintf(buf
, "%s: ", ahd_chip_names
[ahd
->chip
& AHD_CHIPID_MASK
]);
6127 speed
= "Ultra320 ";
6128 if ((ahd
->features
& AHD_WIDE
) != 0) {
6133 len
= sprintf(buf
, "%s%sChannel %c, SCSI Id=%d, ",
6134 speed
, type
, ahd
->channel
, ahd
->our_id
);
6137 sprintf(buf
, "%s, %d SCBs", ahd
->bus_description
,
6138 ahd
->scb_data
.maxhscbs
);
6141 static const char *channel_strings
[] = {
6148 static const char *termstat_strings
[] = {
6149 "Terminated Correctly",
6156 * Start the board, ready for normal operation
6159 ahd_init(struct ahd_softc
*ahd
)
6161 uint8_t *base_vaddr
;
6162 uint8_t *next_vaddr
;
6163 dma_addr_t next_baddr
;
6164 size_t driver_data_size
;
6168 uint8_t current_sensing
;
6171 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
6173 ahd
->stack_size
= ahd_probe_stack_size(ahd
);
6174 ahd
->saved_stack
= malloc(ahd
->stack_size
* sizeof(uint16_t),
6175 M_DEVBUF
, M_NOWAIT
);
6176 if (ahd
->saved_stack
== NULL
)
6180 * Verify that the compiler hasn't over-agressively
6181 * padded important structures.
6183 if (sizeof(struct hardware_scb
) != 64)
6184 panic("Hardware SCB size is incorrect");
6187 if ((ahd_debug
& AHD_DEBUG_SEQUENCER
) != 0)
6188 ahd
->flags
|= AHD_SEQUENCER_DEBUG
;
6192 * Default to allowing initiator operations.
6194 ahd
->flags
|= AHD_INITIATORROLE
;
6197 * Only allow target mode features if this unit has them enabled.
6199 if ((AHD_TMODE_ENABLE
& (0x1 << ahd
->unit
)) == 0)
6200 ahd
->features
&= ~AHD_TARGETMODE
;
6203 /* DMA tag for mapping buffers into device visible space. */
6204 if (ahd_dma_tag_create(ahd
, ahd
->parent_dmat
, /*alignment*/1,
6205 /*boundary*/BUS_SPACE_MAXADDR_32BIT
+ 1,
6206 /*lowaddr*/ahd
->flags
& AHD_39BIT_ADDRESSING
6207 ? (dma_addr_t
)0x7FFFFFFFFFULL
6208 : BUS_SPACE_MAXADDR_32BIT
,
6209 /*highaddr*/BUS_SPACE_MAXADDR
,
6210 /*filter*/NULL
, /*filterarg*/NULL
,
6211 /*maxsize*/(AHD_NSEG
- 1) * PAGE_SIZE
,
6212 /*nsegments*/AHD_NSEG
,
6213 /*maxsegsz*/AHD_MAXTRANSFER_SIZE
,
6214 /*flags*/BUS_DMA_ALLOCNOW
,
6215 &ahd
->buffer_dmat
) != 0) {
6223 * DMA tag for our command fifos and other data in system memory
6224 * the card's sequencer must be able to access. For initiator
6225 * roles, we need to allocate space for the qoutfifo. When providing
6226 * for the target mode role, we must additionally provide space for
6227 * the incoming target command fifo.
6229 driver_data_size
= AHD_SCB_MAX
* sizeof(uint16_t)
6230 + sizeof(struct hardware_scb
);
6231 if ((ahd
->features
& AHD_TARGETMODE
) != 0)
6232 driver_data_size
+= AHD_TMODE_CMDS
* sizeof(struct target_cmd
);
6233 if ((ahd
->bugs
& AHD_PKT_BITBUCKET_BUG
) != 0)
6234 driver_data_size
+= PKT_OVERRUN_BUFSIZE
;
6235 if (ahd_dma_tag_create(ahd
, ahd
->parent_dmat
, /*alignment*/1,
6236 /*boundary*/BUS_SPACE_MAXADDR_32BIT
+ 1,
6237 /*lowaddr*/BUS_SPACE_MAXADDR_32BIT
,
6238 /*highaddr*/BUS_SPACE_MAXADDR
,
6239 /*filter*/NULL
, /*filterarg*/NULL
,
6242 /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT
,
6243 /*flags*/0, &ahd
->shared_data_dmat
) != 0) {
6249 /* Allocation of driver data */
6250 if (ahd_dmamem_alloc(ahd
, ahd
->shared_data_dmat
,
6251 (void **)&base_vaddr
,
6252 BUS_DMA_NOWAIT
, &ahd
->shared_data_dmamap
) != 0) {
6258 /* And permanently map it in */
6259 ahd_dmamap_load(ahd
, ahd
->shared_data_dmat
, ahd
->shared_data_dmamap
,
6260 base_vaddr
, driver_data_size
, ahd_dmamap_cb
,
6261 &ahd
->shared_data_busaddr
, /*flags*/0);
6262 ahd
->qoutfifo
= (uint16_t *)base_vaddr
;
6263 next_vaddr
= (uint8_t *)&ahd
->qoutfifo
[AHD_QOUT_SIZE
];
6264 next_baddr
= ahd
->shared_data_busaddr
+ AHD_QOUT_SIZE
*sizeof(uint16_t);
6265 if ((ahd
->features
& AHD_TARGETMODE
) != 0) {
6266 ahd
->targetcmds
= (struct target_cmd
*)next_vaddr
;
6267 next_vaddr
+= AHD_TMODE_CMDS
* sizeof(struct target_cmd
);
6268 next_baddr
+= AHD_TMODE_CMDS
* sizeof(struct target_cmd
);
6271 if ((ahd
->bugs
& AHD_PKT_BITBUCKET_BUG
) != 0) {
6272 ahd
->overrun_buf
= next_vaddr
;
6273 next_vaddr
+= PKT_OVERRUN_BUFSIZE
;
6274 next_baddr
+= PKT_OVERRUN_BUFSIZE
;
6278 * We need one SCB to serve as the "next SCB". Since the
6279 * tag identifier in this SCB will never be used, there is
6280 * no point in using a valid HSCB tag from an SCB pulled from
6281 * the standard free pool. So, we allocate this "sentinel"
6282 * specially from the DMA safe memory chunk used for the QOUTFIFO.
6284 ahd
->next_queued_hscb
= (struct hardware_scb
*)next_vaddr
;
6285 ahd
->next_queued_hscb
->hscb_busaddr
= ahd_htole32(next_baddr
);
6289 /* Allocate SCB data now that buffer_dmat is initialized */
6290 if (ahd_init_scbdata(ahd
) != 0)
6293 if ((ahd
->flags
& AHD_INITIATORROLE
) == 0)
6294 ahd
->flags
&= ~AHD_RESET_BUS_A
;
6297 * Before committing these settings to the chip, give
6298 * the OSM one last chance to modify our configuration.
6300 ahd_platform_init(ahd
);
6302 /* Bring up the chip. */
6305 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
6307 if ((ahd
->flags
& AHD_CURRENT_SENSING
) == 0)
6311 * Verify termination based on current draw and
6312 * warn user if the bus is over/under terminated.
6314 error
= ahd_write_flexport(ahd
, FLXADDR_ROMSTAT_CURSENSECTL
,
6317 printf("%s: current sensing timeout 1\n", ahd_name(ahd
));
6320 for (i
= 20, fstat
= FLX_FSTAT_BUSY
;
6321 (fstat
& FLX_FSTAT_BUSY
) != 0 && i
; i
--) {
6322 error
= ahd_read_flexport(ahd
, FLXADDR_FLEXSTAT
, &fstat
);
6324 printf("%s: current sensing timeout 2\n",
6330 printf("%s: Timedout during current-sensing test\n",
6335 /* Latch Current Sensing status. */
6336 error
= ahd_read_flexport(ahd
, FLXADDR_CURRENT_STAT
, ¤t_sensing
);
6338 printf("%s: current sensing timeout 3\n", ahd_name(ahd
));
6342 /* Diable current sensing. */
6343 ahd_write_flexport(ahd
, FLXADDR_ROMSTAT_CURSENSECTL
, 0);
6346 if ((ahd_debug
& AHD_SHOW_TERMCTL
) != 0) {
6347 printf("%s: current_sensing == 0x%x\n",
6348 ahd_name(ahd
), current_sensing
);
6352 for (i
= 0; i
< 4; i
++, current_sensing
>>= FLX_CSTAT_SHIFT
) {
6355 term_stat
= (current_sensing
& FLX_CSTAT_MASK
);
6356 switch (term_stat
) {
6357 case FLX_CSTAT_OVER
:
6358 case FLX_CSTAT_UNDER
:
6360 case FLX_CSTAT_INVALID
:
6361 case FLX_CSTAT_OKAY
:
6362 if (warn_user
== 0 && bootverbose
== 0)
6364 printf("%s: %s Channel %s\n", ahd_name(ahd
),
6365 channel_strings
[i
], termstat_strings
[term_stat
]);
6370 printf("%s: WARNING. Termination is not configured correctly.\n"
6371 "%s: WARNING. SCSI bus operations may FAIL.\n",
6372 ahd_name(ahd
), ahd_name(ahd
));
6376 ahd_timer_reset(&ahd
->stat_timer
, AHD_STAT_UPDATE_US
,
6377 ahd_stat_timer
, ahd
);
6382 * (Re)initialize chip state after a chip reset.
6385 ahd_chip_init(struct ahd_softc
*ahd
)
6389 u_int scsiseq_template
;
6394 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
6396 * Take the LED out of diagnostic mode
6398 ahd_outb(ahd
, SBLKCTL
, ahd_inb(ahd
, SBLKCTL
) & ~(DIAGLEDEN
|DIAGLEDON
));
6401 * Return HS_MAILBOX to its default value.
6403 ahd
->hs_mailbox
= 0;
6404 ahd_outb(ahd
, HS_MAILBOX
, 0);
6406 /* Set the SCSI Id, SXFRCTL0, SXFRCTL1, and SIMODE1. */
6407 ahd_outb(ahd
, IOWNID
, ahd
->our_id
);
6408 ahd_outb(ahd
, TOWNID
, ahd
->our_id
);
6409 sxfrctl1
= (ahd
->flags
& AHD_TERM_ENB_A
) != 0 ? STPWEN
: 0;
6410 sxfrctl1
|= (ahd
->flags
& AHD_SPCHK_ENB_A
) != 0 ? ENSPCHK
: 0;
6411 if ((ahd
->bugs
& AHD_LONG_SETIMO_BUG
)
6412 && (ahd
->seltime
!= STIMESEL_MIN
)) {
6414 * The selection timer duration is twice as long
6415 * as it should be. Halve it by adding "1" to
6416 * the user specified setting.
6418 sxfrctl1
|= ahd
->seltime
+ STIMESEL_BUG_ADJ
;
6420 sxfrctl1
|= ahd
->seltime
;
6423 ahd_outb(ahd
, SXFRCTL0
, DFON
);
6424 ahd_outb(ahd
, SXFRCTL1
, sxfrctl1
|ahd
->seltime
|ENSTIMER
|ACTNEGEN
);
6425 ahd_outb(ahd
, SIMODE1
, ENSELTIMO
|ENSCSIRST
|ENSCSIPERR
);
6428 * Now that termination is set, wait for up
6429 * to 500ms for our transceivers to settle. If
6430 * the adapter does not have a cable attached,
6431 * the transceivers may never settle, so don't
6432 * complain if we fail here.
6435 (ahd_inb(ahd
, SBLKCTL
) & (ENAB40
|ENAB20
)) == 0 && wait
;
6439 /* Clear any false bus resets due to the transceivers settling */
6440 ahd_outb(ahd
, CLRSINT1
, CLRSCSIRSTI
);
6441 ahd_outb(ahd
, CLRINT
, CLRSCSIINT
);
6443 /* Initialize mode specific S/G state. */
6444 for (i
= 0; i
< 2; i
++) {
6445 ahd_set_modes(ahd
, AHD_MODE_DFF0
+ i
, AHD_MODE_DFF0
+ i
);
6446 ahd_outb(ahd
, LONGJMP_ADDR
+ 1, INVALID_ADDR
);
6447 ahd_outb(ahd
, SG_STATE
, 0);
6448 ahd_outb(ahd
, CLRSEQINTSRC
, 0xFF);
6449 ahd_outb(ahd
, SEQIMODE
,
6450 ENSAVEPTRS
|ENCFG4DATA
|ENCFG4ISTAT
6451 |ENCFG4TSTAT
|ENCFG4ICMD
|ENCFG4TCMD
);
6454 ahd_set_modes(ahd
, AHD_MODE_CFG
, AHD_MODE_CFG
);
6455 ahd_outb(ahd
, DSCOMMAND0
, ahd_inb(ahd
, DSCOMMAND0
)|MPARCKEN
|CACHETHEN
);
6456 ahd_outb(ahd
, DFF_THRSH
, RD_DFTHRSH_75
|WR_DFTHRSH_75
);
6457 ahd_outb(ahd
, SIMODE0
, ENIOERR
|ENOVERRUN
);
6458 ahd_outb(ahd
, SIMODE3
, ENNTRAMPERR
|ENOSRAMPERR
);
6459 if ((ahd
->bugs
& AHD_BUSFREEREV_BUG
) != 0) {
6460 ahd_outb(ahd
, OPTIONMODE
, AUTOACKEN
|AUTO_MSGOUT_DE
);
6462 ahd_outb(ahd
, OPTIONMODE
, AUTOACKEN
|BUSFREEREV
|AUTO_MSGOUT_DE
);
6464 ahd_outb(ahd
, SCSCHKN
, CURRFIFODEF
|WIDERESEN
|SHVALIDSTDIS
);
6465 if ((ahd
->chip
& AHD_BUS_MASK
) == AHD_PCIX
)
6467 * Do not issue a target abort when a split completion
6468 * error occurs. Let our PCIX interrupt handler deal
6469 * with it instead. H2A4 Razor #625
6471 ahd_outb(ahd
, PCIXCTL
, ahd_inb(ahd
, PCIXCTL
) | SPLTSTADIS
);
6473 if ((ahd
->bugs
& AHD_LQOOVERRUN_BUG
) != 0)
6474 ahd_outb(ahd
, LQOSCSCTL
, LQONOCHKOVER
);
6477 * Tweak IOCELL settings.
6479 if ((ahd
->flags
& AHD_HP_BOARD
) != 0) {
6480 for (i
= 0; i
< NUMDSPS
; i
++) {
6481 ahd_outb(ahd
, DSPSELECT
, i
);
6482 ahd_outb(ahd
, WRTBIASCTL
, WRTBIASCTL_HP_DEFAULT
);
6485 if ((ahd_debug
& AHD_SHOW_MISC
) != 0)
6486 printf("%s: WRTBIASCTL now 0x%x\n", ahd_name(ahd
),
6487 WRTBIASCTL_HP_DEFAULT
);
6490 ahd_setup_iocell_workaround(ahd
);
6493 * Enable LQI Manager interrupts.
6495 ahd_outb(ahd
, LQIMODE1
, ENLQIPHASE_LQ
|ENLQIPHASE_NLQ
|ENLIQABORT
6496 | ENLQICRCI_LQ
|ENLQICRCI_NLQ
|ENLQIBADLQI
6497 | ENLQIOVERI_LQ
|ENLQIOVERI_NLQ
);
6498 ahd_outb(ahd
, LQOMODE0
, ENLQOATNLQ
|ENLQOATNPKT
|ENLQOTCRC
);
6500 * An interrupt from LQOBUSFREE is made redundant by the
6501 * BUSFREE interrupt. We choose to have the sequencer catch
6502 * LQOPHCHGINPKT errors manually for the command phase at the
6503 * start of a packetized selection case.
6504 ahd_outb(ahd, LQOMODE1, ENLQOBUSFREE|ENLQOPHACHGINPKT);
6506 ahd_outb(ahd
, LQOMODE1
, 0);
6509 * Setup sequencer interrupt handlers.
6511 ahd_outw(ahd
, INTVEC1_ADDR
, ahd_resolve_seqaddr(ahd
, LABEL_seq_isr
));
6512 ahd_outw(ahd
, INTVEC2_ADDR
, ahd_resolve_seqaddr(ahd
, LABEL_timer_isr
));
6515 * Setup SCB Offset registers.
6517 if ((ahd
->bugs
& AHD_PKT_LUN_BUG
) != 0) {
6518 ahd_outb(ahd
, LUNPTR
, offsetof(struct hardware_scb
,
6521 ahd_outb(ahd
, LUNPTR
, offsetof(struct hardware_scb
, lun
));
6523 ahd_outb(ahd
, CMDLENPTR
, offsetof(struct hardware_scb
, cdb_len
));
6524 ahd_outb(ahd
, ATTRPTR
, offsetof(struct hardware_scb
, task_attribute
));
6525 ahd_outb(ahd
, FLAGPTR
, offsetof(struct hardware_scb
, task_management
));
6526 ahd_outb(ahd
, CMDPTR
, offsetof(struct hardware_scb
,
6527 shared_data
.idata
.cdb
));
6528 ahd_outb(ahd
, QNEXTPTR
,
6529 offsetof(struct hardware_scb
, next_hscb_busaddr
));
6530 ahd_outb(ahd
, ABRTBITPTR
, MK_MESSAGE_BIT_OFFSET
);
6531 ahd_outb(ahd
, ABRTBYTEPTR
, offsetof(struct hardware_scb
, control
));
6532 if ((ahd
->bugs
& AHD_PKT_LUN_BUG
) != 0) {
6533 ahd_outb(ahd
, LUNLEN
,
6534 sizeof(ahd
->next_queued_hscb
->pkt_long_lun
) - 1);
6536 ahd_outb(ahd
, LUNLEN
, LUNLEN_SINGLE_LEVEL_LUN
);
6538 ahd_outb(ahd
, CDBLIMIT
, SCB_CDB_LEN_PTR
- 1);
6539 ahd_outb(ahd
, MAXCMD
, 0xFF);
6540 ahd_outb(ahd
, SCBAUTOPTR
,
6541 AUSCBPTR_EN
| offsetof(struct hardware_scb
, tag
));
6543 /* We haven't been enabled for target mode yet. */
6544 ahd_outb(ahd
, MULTARGID
, 0);
6545 ahd_outb(ahd
, MULTARGID
+ 1, 0);
6547 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
6548 /* Initialize the negotiation table. */
6549 if ((ahd
->features
& AHD_NEW_IOCELL_OPTS
) == 0) {
6551 * Clear the spare bytes in the neg table to avoid
6552 * spurious parity errors.
6554 for (target
= 0; target
< AHD_NUM_TARGETS
; target
++) {
6555 ahd_outb(ahd
, NEGOADDR
, target
);
6556 ahd_outb(ahd
, ANNEXCOL
, AHD_ANNEXCOL_PER_DEV0
);
6557 for (i
= 0; i
< AHD_NUM_PER_DEV_ANNEXCOLS
; i
++)
6558 ahd_outb(ahd
, ANNEXDAT
, 0);
6561 for (target
= 0; target
< AHD_NUM_TARGETS
; target
++) {
6562 struct ahd_devinfo devinfo
;
6563 struct ahd_initiator_tinfo
*tinfo
;
6564 struct ahd_tmode_tstate
*tstate
;
6566 tinfo
= ahd_fetch_transinfo(ahd
, 'A', ahd
->our_id
,
6568 ahd_compile_devinfo(&devinfo
, ahd
->our_id
,
6569 target
, CAM_LUN_WILDCARD
,
6570 'A', ROLE_INITIATOR
);
6571 ahd_update_neg_table(ahd
, &devinfo
, &tinfo
->curr
);
6574 ahd_outb(ahd
, CLRSINT3
, NTRAMPERR
|OSRAMPERR
);
6575 ahd_outb(ahd
, CLRINT
, CLRSCSIINT
);
6577 #ifdef NEEDS_MORE_TESTING
6579 * Always enable abort on incoming L_Qs if this feature is
6580 * supported. We use this to catch invalid SCB references.
6582 if ((ahd
->bugs
& AHD_ABORT_LQI_BUG
) == 0)
6583 ahd_outb(ahd
, LQCTL1
, ABORTPENDING
);
6586 ahd_outb(ahd
, LQCTL1
, 0);
6588 /* All of our queues are empty */
6589 ahd
->qoutfifonext
= 0;
6590 ahd
->qoutfifonext_valid_tag
= QOUTFIFO_ENTRY_VALID_LE
;
6591 ahd_outb(ahd
, QOUTFIFO_ENTRY_VALID_TAG
, QOUTFIFO_ENTRY_VALID
>> 8);
6592 for (i
= 0; i
< AHD_QOUT_SIZE
; i
++)
6593 ahd
->qoutfifo
[i
] = 0;
6594 ahd_sync_qoutfifo(ahd
, BUS_DMASYNC_PREREAD
);
6596 ahd
->qinfifonext
= 0;
6597 for (i
= 0; i
< AHD_QIN_SIZE
; i
++)
6598 ahd
->qinfifo
[i
] = SCB_LIST_NULL
;
6600 if ((ahd
->features
& AHD_TARGETMODE
) != 0) {
6601 /* All target command blocks start out invalid. */
6602 for (i
= 0; i
< AHD_TMODE_CMDS
; i
++)
6603 ahd
->targetcmds
[i
].cmd_valid
= 0;
6604 ahd_sync_tqinfifo(ahd
, BUS_DMASYNC_PREREAD
);
6605 ahd
->tqinfifonext
= 1;
6606 ahd_outb(ahd
, KERNEL_TQINPOS
, ahd
->tqinfifonext
- 1);
6607 ahd_outb(ahd
, TQINPOS
, ahd
->tqinfifonext
);
6610 /* Initialize Scratch Ram. */
6611 ahd_outb(ahd
, SEQ_FLAGS
, 0);
6612 ahd_outb(ahd
, SEQ_FLAGS2
, 0);
6614 /* We don't have any waiting selections */
6615 ahd_outw(ahd
, WAITING_TID_HEAD
, SCB_LIST_NULL
);
6616 ahd_outw(ahd
, WAITING_TID_TAIL
, SCB_LIST_NULL
);
6617 for (i
= 0; i
< AHD_NUM_TARGETS
; i
++)
6618 ahd_outw(ahd
, WAITING_SCB_TAILS
+ (2 * i
), SCB_LIST_NULL
);
6621 * Nobody is waiting to be DMAed into the QOUTFIFO.
6623 ahd_outw(ahd
, COMPLETE_SCB_HEAD
, SCB_LIST_NULL
);
6624 ahd_outw(ahd
, COMPLETE_SCB_DMAINPROG_HEAD
, SCB_LIST_NULL
);
6625 ahd_outw(ahd
, COMPLETE_DMA_SCB_HEAD
, SCB_LIST_NULL
);
6628 * The Freeze Count is 0.
6630 ahd_outw(ahd
, QFREEZE_COUNT
, 0);
6633 * Tell the sequencer where it can find our arrays in memory.
6635 busaddr
= ahd
->shared_data_busaddr
;
6636 ahd_outb(ahd
, SHARED_DATA_ADDR
, busaddr
& 0xFF);
6637 ahd_outb(ahd
, SHARED_DATA_ADDR
+ 1, (busaddr
>> 8) & 0xFF);
6638 ahd_outb(ahd
, SHARED_DATA_ADDR
+ 2, (busaddr
>> 16) & 0xFF);
6639 ahd_outb(ahd
, SHARED_DATA_ADDR
+ 3, (busaddr
>> 24) & 0xFF);
6640 ahd_outb(ahd
, QOUTFIFO_NEXT_ADDR
, busaddr
& 0xFF);
6641 ahd_outb(ahd
, QOUTFIFO_NEXT_ADDR
+ 1, (busaddr
>> 8) & 0xFF);
6642 ahd_outb(ahd
, QOUTFIFO_NEXT_ADDR
+ 2, (busaddr
>> 16) & 0xFF);
6643 ahd_outb(ahd
, QOUTFIFO_NEXT_ADDR
+ 3, (busaddr
>> 24) & 0xFF);
6646 * Setup the allowed SCSI Sequences based on operational mode.
6647 * If we are a target, we'll enable select in operations once
6648 * we've had a lun enabled.
6650 scsiseq_template
= ENAUTOATNP
;
6651 if ((ahd
->flags
& AHD_INITIATORROLE
) != 0)
6652 scsiseq_template
|= ENRSELI
;
6653 ahd_outb(ahd
, SCSISEQ_TEMPLATE
, scsiseq_template
);
6655 /* There are no busy SCBs yet. */
6656 for (target
= 0; target
< AHD_NUM_TARGETS
; target
++) {
6659 for (lun
= 0; lun
< AHD_NUM_LUNS_NONPKT
; lun
++)
6660 ahd_unbusy_tcl(ahd
, BUILD_TCL_RAW(target
, 'A', lun
));
6664 * Initialize the group code to command length table.
6665 * Vendor Unique codes are set to 0 so we only capture
6666 * the first byte of the cdb. These can be overridden
6667 * when target mode is enabled.
6669 ahd_outb(ahd
, CMDSIZE_TABLE
, 5);
6670 ahd_outb(ahd
, CMDSIZE_TABLE
+ 1, 9);
6671 ahd_outb(ahd
, CMDSIZE_TABLE
+ 2, 9);
6672 ahd_outb(ahd
, CMDSIZE_TABLE
+ 3, 0);
6673 ahd_outb(ahd
, CMDSIZE_TABLE
+ 4, 15);
6674 ahd_outb(ahd
, CMDSIZE_TABLE
+ 5, 11);
6675 ahd_outb(ahd
, CMDSIZE_TABLE
+ 6, 0);
6676 ahd_outb(ahd
, CMDSIZE_TABLE
+ 7, 0);
6678 /* Tell the sequencer of our initial queue positions */
6679 ahd_set_modes(ahd
, AHD_MODE_CCHAN
, AHD_MODE_CCHAN
);
6680 ahd_outb(ahd
, QOFF_CTLSTA
, SCB_QSIZE_512
);
6681 ahd
->qinfifonext
= 0;
6682 ahd_set_hnscb_qoff(ahd
, ahd
->qinfifonext
);
6683 ahd_set_hescb_qoff(ahd
, 0);
6684 ahd_set_snscb_qoff(ahd
, 0);
6685 ahd_set_sescb_qoff(ahd
, 0);
6686 ahd_set_sdscb_qoff(ahd
, 0);
6689 * Tell the sequencer which SCB will be the next one it receives.
6691 busaddr
= ahd_le32toh(ahd
->next_queued_hscb
->hscb_busaddr
);
6692 ahd_outb(ahd
, NEXT_QUEUED_SCB_ADDR
+ 0, busaddr
& 0xFF);
6693 ahd_outb(ahd
, NEXT_QUEUED_SCB_ADDR
+ 1, (busaddr
>> 8) & 0xFF);
6694 ahd_outb(ahd
, NEXT_QUEUED_SCB_ADDR
+ 2, (busaddr
>> 16) & 0xFF);
6695 ahd_outb(ahd
, NEXT_QUEUED_SCB_ADDR
+ 3, (busaddr
>> 24) & 0xFF);
6698 * Default to coalescing disabled.
6700 ahd_outw(ahd
, INT_COALESCING_CMDCOUNT
, 0);
6701 ahd_outw(ahd
, CMDS_PENDING
, 0);
6702 ahd_update_coalescing_values(ahd
, ahd
->int_coalescing_timer
,
6703 ahd
->int_coalescing_maxcmds
,
6704 ahd
->int_coalescing_mincmds
);
6705 ahd_enable_coalescing(ahd
, FALSE
);
6708 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
6712 * Setup default device and controller settings.
6713 * This should only be called if our probe has
6714 * determined that no configuration data is available.
6717 ahd_default_config(struct ahd_softc
*ahd
)
6724 * Allocate a tstate to house information for our
6725 * initiator presence on the bus as well as the user
6726 * data for any target mode initiator.
6728 if (ahd_alloc_tstate(ahd
, ahd
->our_id
, 'A') == NULL
) {
6729 printf("%s: unable to allocate ahd_tmode_tstate. "
6730 "Failing attach\n", ahd_name(ahd
));
6734 for (targ
= 0; targ
< AHD_NUM_TARGETS
; targ
++) {
6735 struct ahd_devinfo devinfo
;
6736 struct ahd_initiator_tinfo
*tinfo
;
6737 struct ahd_tmode_tstate
*tstate
;
6738 uint16_t target_mask
;
6740 tinfo
= ahd_fetch_transinfo(ahd
, 'A', ahd
->our_id
,
6743 * We support SPC2 and SPI4.
6745 tinfo
->user
.protocol_version
= 4;
6746 tinfo
->user
.transport_version
= 4;
6748 target_mask
= 0x01 << targ
;
6749 ahd
->user_discenable
|= target_mask
;
6750 tstate
->discenable
|= target_mask
;
6751 ahd
->user_tagenable
|= target_mask
;
6752 #ifdef AHD_FORCE_160
6753 tinfo
->user
.period
= AHD_SYNCRATE_DT
;
6755 tinfo
->user
.period
= AHD_SYNCRATE_160
;
6757 tinfo
->user
.offset
= MAX_OFFSET
;
6758 tinfo
->user
.ppr_options
= MSG_EXT_PPR_RD_STRM
6759 | MSG_EXT_PPR_WR_FLOW
6760 | MSG_EXT_PPR_HOLD_MCS
6761 | MSG_EXT_PPR_IU_REQ
6762 | MSG_EXT_PPR_QAS_REQ
6763 | MSG_EXT_PPR_DT_REQ
;
6764 if ((ahd
->features
& AHD_RTI
) != 0)
6765 tinfo
->user
.ppr_options
|= MSG_EXT_PPR_RTI
;
6767 tinfo
->user
.width
= MSG_EXT_WDTR_BUS_16_BIT
;
6770 * Start out Async/Narrow/Untagged and with
6771 * conservative protocol support.
6773 tinfo
->goal
.protocol_version
= 2;
6774 tinfo
->goal
.transport_version
= 2;
6775 tinfo
->curr
.protocol_version
= 2;
6776 tinfo
->curr
.transport_version
= 2;
6777 ahd_compile_devinfo(&devinfo
, ahd
->our_id
,
6778 targ
, CAM_LUN_WILDCARD
,
6779 'A', ROLE_INITIATOR
);
6780 tstate
->tagenable
&= ~target_mask
;
6781 ahd_set_width(ahd
, &devinfo
, MSG_EXT_WDTR_BUS_8_BIT
,
6782 AHD_TRANS_CUR
|AHD_TRANS_GOAL
, /*paused*/TRUE
);
6783 ahd_set_syncrate(ahd
, &devinfo
, /*period*/0, /*offset*/0,
6784 /*ppr_options*/0, AHD_TRANS_CUR
|AHD_TRANS_GOAL
,
6791 * Parse device configuration information.
6794 ahd_parse_cfgdata(struct ahd_softc
*ahd
, struct seeprom_config
*sc
)
6799 max_targ
= sc
->max_targets
& CFMAXTARG
;
6800 ahd
->our_id
= sc
->brtime_id
& CFSCSIID
;
6803 * Allocate a tstate to house information for our
6804 * initiator presence on the bus as well as the user
6805 * data for any target mode initiator.
6807 if (ahd_alloc_tstate(ahd
, ahd
->our_id
, 'A') == NULL
) {
6808 printf("%s: unable to allocate ahd_tmode_tstate. "
6809 "Failing attach\n", ahd_name(ahd
));
6813 for (targ
= 0; targ
< max_targ
; targ
++) {
6814 struct ahd_devinfo devinfo
;
6815 struct ahd_initiator_tinfo
*tinfo
;
6816 struct ahd_transinfo
*user_tinfo
;
6817 struct ahd_tmode_tstate
*tstate
;
6818 uint16_t target_mask
;
6820 tinfo
= ahd_fetch_transinfo(ahd
, 'A', ahd
->our_id
,
6822 user_tinfo
= &tinfo
->user
;
6825 * We support SPC2 and SPI4.
6827 tinfo
->user
.protocol_version
= 4;
6828 tinfo
->user
.transport_version
= 4;
6830 target_mask
= 0x01 << targ
;
6831 ahd
->user_discenable
&= ~target_mask
;
6832 tstate
->discenable
&= ~target_mask
;
6833 ahd
->user_tagenable
&= ~target_mask
;
6834 if (sc
->device_flags
[targ
] & CFDISC
) {
6835 tstate
->discenable
|= target_mask
;
6836 ahd
->user_discenable
|= target_mask
;
6837 ahd
->user_tagenable
|= target_mask
;
6840 * Cannot be packetized without disconnection.
6842 sc
->device_flags
[targ
] &= ~CFPACKETIZED
;
6845 user_tinfo
->ppr_options
= 0;
6846 user_tinfo
->period
= (sc
->device_flags
[targ
] & CFXFER
);
6847 if (user_tinfo
->period
< CFXFER_ASYNC
) {
6848 if (user_tinfo
->period
<= AHD_PERIOD_10MHz
)
6849 user_tinfo
->ppr_options
|= MSG_EXT_PPR_DT_REQ
;
6850 user_tinfo
->offset
= MAX_OFFSET
;
6852 user_tinfo
->offset
= 0;
6853 user_tinfo
->period
= AHD_ASYNC_XFER_PERIOD
;
6855 #ifdef AHD_FORCE_160
6856 if (user_tinfo
->period
<= AHD_SYNCRATE_160
)
6857 user_tinfo
->period
= AHD_SYNCRATE_DT
;
6860 if ((sc
->device_flags
[targ
] & CFPACKETIZED
) != 0) {
6861 user_tinfo
->ppr_options
|= MSG_EXT_PPR_RD_STRM
6862 | MSG_EXT_PPR_WR_FLOW
6863 | MSG_EXT_PPR_HOLD_MCS
6864 | MSG_EXT_PPR_IU_REQ
;
6865 if ((ahd
->features
& AHD_RTI
) != 0)
6866 user_tinfo
->ppr_options
|= MSG_EXT_PPR_RTI
;
6869 if ((sc
->device_flags
[targ
] & CFQAS
) != 0)
6870 user_tinfo
->ppr_options
|= MSG_EXT_PPR_QAS_REQ
;
6872 if ((sc
->device_flags
[targ
] & CFWIDEB
) != 0)
6873 user_tinfo
->width
= MSG_EXT_WDTR_BUS_16_BIT
;
6875 user_tinfo
->width
= MSG_EXT_WDTR_BUS_8_BIT
;
6877 if ((ahd_debug
& AHD_SHOW_MISC
) != 0)
6878 printf("(%d): %x:%x:%x:%x\n", targ
, user_tinfo
->width
,
6879 user_tinfo
->period
, user_tinfo
->offset
,
6880 user_tinfo
->ppr_options
);
6883 * Start out Async/Narrow/Untagged and with
6884 * conservative protocol support.
6886 tstate
->tagenable
&= ~target_mask
;
6887 tinfo
->goal
.protocol_version
= 2;
6888 tinfo
->goal
.transport_version
= 2;
6889 tinfo
->curr
.protocol_version
= 2;
6890 tinfo
->curr
.transport_version
= 2;
6891 ahd_compile_devinfo(&devinfo
, ahd
->our_id
,
6892 targ
, CAM_LUN_WILDCARD
,
6893 'A', ROLE_INITIATOR
);
6894 ahd_set_width(ahd
, &devinfo
, MSG_EXT_WDTR_BUS_8_BIT
,
6895 AHD_TRANS_CUR
|AHD_TRANS_GOAL
, /*paused*/TRUE
);
6896 ahd_set_syncrate(ahd
, &devinfo
, /*period*/0, /*offset*/0,
6897 /*ppr_options*/0, AHD_TRANS_CUR
|AHD_TRANS_GOAL
,
6901 ahd
->flags
&= ~AHD_SPCHK_ENB_A
;
6902 if (sc
->bios_control
& CFSPARITY
)
6903 ahd
->flags
|= AHD_SPCHK_ENB_A
;
6905 ahd
->flags
&= ~AHD_RESET_BUS_A
;
6906 if (sc
->bios_control
& CFRESETB
)
6907 ahd
->flags
|= AHD_RESET_BUS_A
;
6909 ahd
->flags
&= ~AHD_EXTENDED_TRANS_A
;
6910 if (sc
->bios_control
& CFEXTEND
)
6911 ahd
->flags
|= AHD_EXTENDED_TRANS_A
;
6913 ahd
->flags
&= ~AHD_BIOS_ENABLED
;
6914 if ((sc
->bios_control
& CFBIOSSTATE
) == CFBS_ENABLED
)
6915 ahd
->flags
|= AHD_BIOS_ENABLED
;
6917 ahd
->flags
&= ~AHD_STPWLEVEL_A
;
6918 if ((sc
->adapter_control
& CFSTPWLEVEL
) != 0)
6919 ahd
->flags
|= AHD_STPWLEVEL_A
;
6925 * Parse device configuration information.
6928 ahd_parse_vpddata(struct ahd_softc
*ahd
, struct vpd_config
*vpd
)
6932 error
= ahd_verify_vpd_cksum(vpd
);
6935 if ((vpd
->bios_flags
& VPDBOOTHOST
) != 0)
6936 ahd
->flags
|= AHD_BOOT_CHANNEL
;
6941 ahd_intr_enable(struct ahd_softc
*ahd
, int enable
)
6945 hcntrl
= ahd_inb(ahd
, HCNTRL
);
6947 ahd
->pause
&= ~INTEN
;
6948 ahd
->unpause
&= ~INTEN
;
6951 ahd
->pause
|= INTEN
;
6952 ahd
->unpause
|= INTEN
;
6954 ahd_outb(ahd
, HCNTRL
, hcntrl
);
6958 ahd_update_coalescing_values(struct ahd_softc
*ahd
, u_int timer
, u_int maxcmds
,
6961 if (timer
> AHD_TIMER_MAX_US
)
6962 timer
= AHD_TIMER_MAX_US
;
6963 ahd
->int_coalescing_timer
= timer
;
6965 if (maxcmds
> AHD_INT_COALESCING_MAXCMDS_MAX
)
6966 maxcmds
= AHD_INT_COALESCING_MAXCMDS_MAX
;
6967 if (mincmds
> AHD_INT_COALESCING_MINCMDS_MAX
)
6968 mincmds
= AHD_INT_COALESCING_MINCMDS_MAX
;
6969 ahd
->int_coalescing_maxcmds
= maxcmds
;
6970 ahd_outw(ahd
, INT_COALESCING_TIMER
, timer
/ AHD_TIMER_US_PER_TICK
);
6971 ahd_outb(ahd
, INT_COALESCING_MAXCMDS
, -maxcmds
);
6972 ahd_outb(ahd
, INT_COALESCING_MINCMDS
, -mincmds
);
6976 ahd_enable_coalescing(struct ahd_softc
*ahd
, int enable
)
6979 ahd
->hs_mailbox
&= ~ENINT_COALESCE
;
6981 ahd
->hs_mailbox
|= ENINT_COALESCE
;
6982 ahd_outb(ahd
, HS_MAILBOX
, ahd
->hs_mailbox
);
6983 ahd_flush_device_writes(ahd
);
6984 ahd_run_qoutfifo(ahd
);
6988 * Ensure that the card is paused in a location
6989 * outside of all critical sections and that all
6990 * pending work is completed prior to returning.
6991 * This routine should only be called from outside
6992 * an interrupt context.
6995 ahd_pause_and_flushwork(struct ahd_softc
*ahd
)
7002 ahd
->flags
|= AHD_ALL_INTERRUPTS
;
7005 * Increment the QFreeze Count so that the sequencer
7006 * will not start new selections. We do this only
7007 * until we are safely paused without further selections
7010 ahd_outw(ahd
, QFREEZE_COUNT
, ahd_inw(ahd
, QFREEZE_COUNT
) + 1);
7011 ahd_outb(ahd
, SEQ_FLAGS2
, ahd_inb(ahd
, SEQ_FLAGS2
) | SELECTOUT_QFROZEN
);
7013 struct scb
*waiting_scb
;
7018 ahd_clear_critical_section(ahd
);
7019 intstat
= ahd_inb(ahd
, INTSTAT
);
7020 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
7021 if ((ahd_inb(ahd
, SSTAT0
) & (SELDO
|SELINGO
)) == 0)
7022 ahd_outb(ahd
, SCSISEQ0
,
7023 ahd_inb(ahd
, SCSISEQ0
) & ~ENSELO
);
7025 * In the non-packetized case, the sequencer (for Rev A),
7026 * relies on ENSELO remaining set after SELDO. The hardware
7027 * auto-clears ENSELO in the packetized case.
7029 waiting_scb
= ahd_lookup_scb(ahd
,
7030 ahd_inw(ahd
, WAITING_TID_HEAD
));
7031 if (waiting_scb
!= NULL
7032 && (waiting_scb
->flags
& SCB_PACKETIZED
) == 0
7033 && (ahd_inb(ahd
, SSTAT0
) & (SELDO
|SELINGO
)) != 0)
7034 ahd_outb(ahd
, SCSISEQ0
,
7035 ahd_inb(ahd
, SCSISEQ0
) | ENSELO
);
7037 && (intstat
!= 0xFF || (ahd
->features
& AHD_REMOVABLE
) == 0)
7038 && ((intstat
& INT_PEND
) != 0
7039 || (ahd_inb(ahd
, SCSISEQ0
) & ENSELO
) != 0
7040 || (ahd_inb(ahd
, SSTAT0
) & (SELDO
|SELINGO
)) != 0));
7042 if (maxloops
== 0) {
7043 printf("Infinite interrupt loop, INTSTAT = %x",
7044 ahd_inb(ahd
, INTSTAT
));
7046 qfreeze_cnt
= ahd_inw(ahd
, QFREEZE_COUNT
);
7047 if (qfreeze_cnt
== 0) {
7048 printf("%s: ahd_pause_and_flushwork with 0 qfreeze count!\n",
7053 ahd_outw(ahd
, QFREEZE_COUNT
, qfreeze_cnt
);
7054 if (qfreeze_cnt
== 0)
7055 ahd_outb(ahd
, SEQ_FLAGS2
,
7056 ahd_inb(ahd
, SEQ_FLAGS2
) & ~SELECTOUT_QFROZEN
);
7058 ahd_flush_qoutfifo(ahd
);
7060 ahd_platform_flushwork(ahd
);
7061 ahd
->flags
&= ~AHD_ALL_INTERRUPTS
;
7065 ahd_suspend(struct ahd_softc
*ahd
)
7068 ahd_pause_and_flushwork(ahd
);
7070 if (LIST_FIRST(&ahd
->pending_scbs
) != NULL
) {
7079 ahd_resume(struct ahd_softc
*ahd
)
7082 ahd_reset(ahd
, /*reinit*/TRUE
);
7083 ahd_intr_enable(ahd
, TRUE
);
7088 /************************** Busy Target Table *********************************/
7090 * Set SCBPTR to the SCB that contains the busy
7091 * table entry for TCL. Return the offset into
7092 * the SCB that contains the entry for TCL.
7093 * saved_scbid is dereferenced and set to the
7094 * scbid that should be restored once manipualtion
7095 * of the TCL entry is complete.
7097 static __inline u_int
7098 ahd_index_busy_tcl(struct ahd_softc
*ahd
, u_int
*saved_scbid
, u_int tcl
)
7101 * Index to the SCB that contains the busy entry.
7103 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
7104 *saved_scbid
= ahd_get_scbptr(ahd
);
7105 ahd_set_scbptr(ahd
, TCL_LUN(tcl
)
7106 | ((TCL_TARGET_OFFSET(tcl
) & 0xC) << 4));
7109 * And now calculate the SCB offset to the entry.
7110 * Each entry is 2 bytes wide, hence the
7111 * multiplication by 2.
7113 return (((TCL_TARGET_OFFSET(tcl
) & 0x3) << 1) + SCB_DISCONNECTED_LISTS
);
7117 * Return the untagged transaction id for a given target/channel lun.
7120 ahd_find_busy_tcl(struct ahd_softc
*ahd
, u_int tcl
)
7126 scb_offset
= ahd_index_busy_tcl(ahd
, &saved_scbptr
, tcl
);
7127 scbid
= ahd_inw_scbram(ahd
, scb_offset
);
7128 ahd_set_scbptr(ahd
, saved_scbptr
);
7133 ahd_busy_tcl(struct ahd_softc
*ahd
, u_int tcl
, u_int scbid
)
7138 scb_offset
= ahd_index_busy_tcl(ahd
, &saved_scbptr
, tcl
);
7139 ahd_outw(ahd
, scb_offset
, scbid
);
7140 ahd_set_scbptr(ahd
, saved_scbptr
);
7143 /************************** SCB and SCB queue management **********************/
7145 ahd_match_scb(struct ahd_softc
*ahd
, struct scb
*scb
, int target
,
7146 char channel
, int lun
, u_int tag
, role_t role
)
7148 int targ
= SCB_GET_TARGET(ahd
, scb
);
7149 char chan
= SCB_GET_CHANNEL(ahd
, scb
);
7150 int slun
= SCB_GET_LUN(scb
);
7153 match
= ((chan
== channel
) || (channel
== ALL_CHANNELS
));
7155 match
= ((targ
== target
) || (target
== CAM_TARGET_WILDCARD
));
7157 match
= ((lun
== slun
) || (lun
== CAM_LUN_WILDCARD
));
7159 #ifdef AHD_TARGET_MODE
7162 group
= XPT_FC_GROUP(scb
->io_ctx
->ccb_h
.func_code
);
7163 if (role
== ROLE_INITIATOR
) {
7164 match
= (group
!= XPT_FC_GROUP_TMODE
)
7165 && ((tag
== SCB_GET_TAG(scb
))
7166 || (tag
== SCB_LIST_NULL
));
7167 } else if (role
== ROLE_TARGET
) {
7168 match
= (group
== XPT_FC_GROUP_TMODE
)
7169 && ((tag
== scb
->io_ctx
->csio
.tag_id
)
7170 || (tag
== SCB_LIST_NULL
));
7172 #else /* !AHD_TARGET_MODE */
7173 match
= ((tag
== SCB_GET_TAG(scb
)) || (tag
== SCB_LIST_NULL
));
7174 #endif /* AHD_TARGET_MODE */
7181 ahd_freeze_devq(struct ahd_softc
*ahd
, struct scb
*scb
)
7187 target
= SCB_GET_TARGET(ahd
, scb
);
7188 lun
= SCB_GET_LUN(scb
);
7189 channel
= SCB_GET_CHANNEL(ahd
, scb
);
7191 ahd_search_qinfifo(ahd
, target
, channel
, lun
,
7192 /*tag*/SCB_LIST_NULL
, ROLE_UNKNOWN
,
7193 CAM_REQUEUE_REQ
, SEARCH_COMPLETE
);
7195 ahd_platform_freeze_devq(ahd
, scb
);
7199 ahd_qinfifo_requeue_tail(struct ahd_softc
*ahd
, struct scb
*scb
)
7201 struct scb
*prev_scb
;
7202 ahd_mode_state saved_modes
;
7204 saved_modes
= ahd_save_modes(ahd
);
7205 ahd_set_modes(ahd
, AHD_MODE_CCHAN
, AHD_MODE_CCHAN
);
7207 if (ahd_qinfifo_count(ahd
) != 0) {
7211 prev_pos
= AHD_QIN_WRAP(ahd
->qinfifonext
- 1);
7212 prev_tag
= ahd
->qinfifo
[prev_pos
];
7213 prev_scb
= ahd_lookup_scb(ahd
, prev_tag
);
7215 ahd_qinfifo_requeue(ahd
, prev_scb
, scb
);
7216 ahd_set_hnscb_qoff(ahd
, ahd
->qinfifonext
);
7217 ahd_restore_modes(ahd
, saved_modes
);
7221 ahd_qinfifo_requeue(struct ahd_softc
*ahd
, struct scb
*prev_scb
,
7224 if (prev_scb
== NULL
) {
7227 busaddr
= ahd_le32toh(scb
->hscb
->hscb_busaddr
);
7228 ahd_outb(ahd
, NEXT_QUEUED_SCB_ADDR
+ 0, busaddr
& 0xFF);
7229 ahd_outb(ahd
, NEXT_QUEUED_SCB_ADDR
+ 1, (busaddr
>> 8) & 0xFF);
7230 ahd_outb(ahd
, NEXT_QUEUED_SCB_ADDR
+ 2, (busaddr
>> 16) & 0xFF);
7231 ahd_outb(ahd
, NEXT_QUEUED_SCB_ADDR
+ 3, (busaddr
>> 24) & 0xFF);
7233 prev_scb
->hscb
->next_hscb_busaddr
= scb
->hscb
->hscb_busaddr
;
7234 ahd_sync_scb(ahd
, prev_scb
,
7235 BUS_DMASYNC_PREREAD
|BUS_DMASYNC_PREWRITE
);
7237 ahd
->qinfifo
[AHD_QIN_WRAP(ahd
->qinfifonext
)] = SCB_GET_TAG(scb
);
7239 scb
->hscb
->next_hscb_busaddr
= ahd
->next_queued_hscb
->hscb_busaddr
;
7240 ahd_sync_scb(ahd
, scb
, BUS_DMASYNC_PREREAD
|BUS_DMASYNC_PREWRITE
);
7244 ahd_qinfifo_count(struct ahd_softc
*ahd
)
7248 u_int wrap_qinfifonext
;
7250 AHD_ASSERT_MODES(ahd
, AHD_MODE_CCHAN_MSK
, AHD_MODE_CCHAN_MSK
);
7251 qinpos
= ahd_get_snscb_qoff(ahd
);
7252 wrap_qinpos
= AHD_QIN_WRAP(qinpos
);
7253 wrap_qinfifonext
= AHD_QIN_WRAP(ahd
->qinfifonext
);
7254 if (wrap_qinfifonext
>= wrap_qinpos
)
7255 return (wrap_qinfifonext
- wrap_qinpos
);
7257 return (wrap_qinfifonext
7258 + NUM_ELEMENTS(ahd
->qinfifo
) - wrap_qinpos
);
7262 ahd_reset_cmds_pending(struct ahd_softc
*ahd
)
7265 ahd_mode_state saved_modes
;
7268 saved_modes
= ahd_save_modes(ahd
);
7269 ahd_set_modes(ahd
, AHD_MODE_CCHAN
, AHD_MODE_CCHAN
);
7272 * Don't count any commands as outstanding that the
7273 * sequencer has already marked for completion.
7275 ahd_flush_qoutfifo(ahd
);
7278 LIST_FOREACH(scb
, &ahd
->pending_scbs
, pending_links
) {
7281 ahd_outw(ahd
, CMDS_PENDING
, pending_cmds
- ahd_qinfifo_count(ahd
));
7282 ahd_restore_modes(ahd
, saved_modes
);
7283 ahd
->flags
&= ~AHD_UPDATE_PEND_CMDS
;
7287 ahd_search_qinfifo(struct ahd_softc
*ahd
, int target
, char channel
,
7288 int lun
, u_int tag
, role_t role
, uint32_t status
,
7289 ahd_search_action action
)
7292 struct scb
*prev_scb
;
7293 ahd_mode_state saved_modes
;
7305 /* Must be in CCHAN mode */
7306 saved_modes
= ahd_save_modes(ahd
);
7307 ahd_set_modes(ahd
, AHD_MODE_CCHAN
, AHD_MODE_CCHAN
);
7310 * Halt any pending SCB DMA. The sequencer will reinitiate
7311 * this dma if the qinfifo is not empty once we unpause.
7313 if ((ahd_inb(ahd
, CCSCBCTL
) & (CCARREN
|CCSCBEN
|CCSCBDIR
))
7314 == (CCARREN
|CCSCBEN
|CCSCBDIR
)) {
7315 ahd_outb(ahd
, CCSCBCTL
,
7316 ahd_inb(ahd
, CCSCBCTL
) & ~(CCARREN
|CCSCBEN
));
7317 while ((ahd_inb(ahd
, CCSCBCTL
) & (CCARREN
|CCSCBEN
)) != 0)
7320 /* Determine sequencer's position in the qinfifo. */
7321 qintail
= AHD_QIN_WRAP(ahd
->qinfifonext
);
7322 qinstart
= ahd_get_snscb_qoff(ahd
);
7323 qinpos
= AHD_QIN_WRAP(qinstart
);
7327 if (action
== SEARCH_PRINT
) {
7328 printf("qinstart = %d qinfifonext = %d\nQINFIFO:",
7329 qinstart
, ahd
->qinfifonext
);
7333 * Start with an empty queue. Entries that are not chosen
7334 * for removal will be re-added to the queue as we go.
7336 ahd
->qinfifonext
= qinstart
;
7337 busaddr
= ahd_le32toh(ahd
->next_queued_hscb
->hscb_busaddr
);
7338 ahd_outb(ahd
, NEXT_QUEUED_SCB_ADDR
+ 0, busaddr
& 0xFF);
7339 ahd_outb(ahd
, NEXT_QUEUED_SCB_ADDR
+ 1, (busaddr
>> 8) & 0xFF);
7340 ahd_outb(ahd
, NEXT_QUEUED_SCB_ADDR
+ 2, (busaddr
>> 16) & 0xFF);
7341 ahd_outb(ahd
, NEXT_QUEUED_SCB_ADDR
+ 3, (busaddr
>> 24) & 0xFF);
7343 while (qinpos
!= qintail
) {
7344 scb
= ahd_lookup_scb(ahd
, ahd
->qinfifo
[qinpos
]);
7346 printf("qinpos = %d, SCB index = %d\n",
7347 qinpos
, ahd
->qinfifo
[qinpos
]);
7351 if (ahd_match_scb(ahd
, scb
, target
, channel
, lun
, tag
, role
)) {
7353 * We found an scb that needs to be acted on.
7357 case SEARCH_COMPLETE
:
7362 ostat
= ahd_get_transaction_status(scb
);
7363 if (ostat
== CAM_REQ_INPROG
)
7364 ahd_set_transaction_status(scb
,
7366 cstat
= ahd_get_transaction_status(scb
);
7367 if (cstat
!= CAM_REQ_CMP
)
7368 ahd_freeze_scb(scb
);
7369 if ((scb
->flags
& SCB_ACTIVE
) == 0)
7370 printf("Inactive SCB in qinfifo\n");
7378 printf(" 0x%x", ahd
->qinfifo
[qinpos
]);
7381 ahd_qinfifo_requeue(ahd
, prev_scb
, scb
);
7386 ahd_qinfifo_requeue(ahd
, prev_scb
, scb
);
7389 qinpos
= AHD_QIN_WRAP(qinpos
+1);
7392 ahd_set_hnscb_qoff(ahd
, ahd
->qinfifonext
);
7394 if (action
== SEARCH_PRINT
)
7395 printf("\nWAITING_TID_QUEUES:\n");
7398 * Search waiting for selection lists. We traverse the
7399 * list of "their ids" waiting for selection and, if
7400 * appropriate, traverse the SCBs of each "their id"
7401 * looking for matches.
7403 savedscbptr
= ahd_get_scbptr(ahd
);
7404 tid_next
= ahd_inw(ahd
, WAITING_TID_HEAD
);
7405 tid_prev
= SCB_LIST_NULL
;
7407 for (scbid
= tid_next
; !SCBID_IS_NULL(scbid
); scbid
= tid_next
) {
7411 * We limit based on the number of SCBs since
7412 * MK_MESSAGE SCBs are not in the per-tid lists.
7415 if (targets
> AHD_SCB_MAX
) {
7416 panic("TID LIST LOOP");
7418 if (scbid
>= ahd
->scb_data
.numscbs
) {
7419 printf("%s: Waiting TID List inconsistency. "
7420 "SCB index == 0x%x, yet numscbs == 0x%x.",
7421 ahd_name(ahd
), scbid
, ahd
->scb_data
.numscbs
);
7422 ahd_dump_card_state(ahd
);
7423 panic("for safety");
7425 scb
= ahd_lookup_scb(ahd
, scbid
);
7427 printf("%s: SCB = 0x%x Not Active!\n",
7428 ahd_name(ahd
), scbid
);
7429 panic("Waiting TID List traversal\n");
7431 ahd_set_scbptr(ahd
, scbid
);
7432 tid_next
= ahd_inw_scbram(ahd
, SCB_NEXT2
);
7433 if (ahd_match_scb(ahd
, scb
, target
, channel
, CAM_LUN_WILDCARD
,
7434 SCB_LIST_NULL
, ROLE_UNKNOWN
) == 0) {
7440 * We found a list of scbs that needs to be searched.
7442 if (action
== SEARCH_PRINT
)
7443 printf(" %d ( ", SCB_GET_TARGET(ahd
, scb
));
7445 found
+= ahd_search_scb_list(ahd
, target
, channel
,
7446 lun
, tag
, role
, status
,
7448 SCB_GET_TARGET(ahd
, scb
));
7449 if (tid_head
!= scbid
)
7450 ahd_stitch_tid_list(ahd
, tid_prev
, tid_head
, tid_next
);
7451 if (!SCBID_IS_NULL(tid_head
))
7452 tid_prev
= tid_head
;
7453 if (action
== SEARCH_PRINT
)
7456 ahd_set_scbptr(ahd
, savedscbptr
);
7457 ahd_restore_modes(ahd
, saved_modes
);
7462 ahd_search_scb_list(struct ahd_softc
*ahd
, int target
, char channel
,
7463 int lun
, u_int tag
, role_t role
, uint32_t status
,
7464 ahd_search_action action
, u_int
*list_head
, u_int tid
)
7472 AHD_ASSERT_MODES(ahd
, AHD_MODE_CCHAN_MSK
, AHD_MODE_CCHAN_MSK
);
7474 prev
= SCB_LIST_NULL
;
7476 for (scbid
= next
; !SCBID_IS_NULL(scbid
); scbid
= next
) {
7477 if (scbid
>= ahd
->scb_data
.numscbs
) {
7478 printf("%s:SCB List inconsistency. "
7479 "SCB == 0x%x, yet numscbs == 0x%x.",
7480 ahd_name(ahd
), scbid
, ahd
->scb_data
.numscbs
);
7481 ahd_dump_card_state(ahd
);
7482 panic("for safety");
7484 scb
= ahd_lookup_scb(ahd
, scbid
);
7486 printf("%s: SCB = %d Not Active!\n",
7487 ahd_name(ahd
), scbid
);
7488 panic("Waiting List traversal\n");
7490 ahd_set_scbptr(ahd
, scbid
);
7491 next
= ahd_inw_scbram(ahd
, SCB_NEXT
);
7492 if (ahd_match_scb(ahd
, scb
, target
, channel
,
7493 lun
, SCB_LIST_NULL
, role
) == 0) {
7499 case SEARCH_COMPLETE
:
7504 ostat
= ahd_get_transaction_status(scb
);
7505 if (ostat
== CAM_REQ_INPROG
)
7506 ahd_set_transaction_status(scb
, status
);
7507 cstat
= ahd_get_transaction_status(scb
);
7508 if (cstat
!= CAM_REQ_CMP
)
7509 ahd_freeze_scb(scb
);
7510 if ((scb
->flags
& SCB_ACTIVE
) == 0)
7511 printf("Inactive SCB in Waiting List\n");
7516 ahd_rem_wscb(ahd
, scbid
, prev
, next
, tid
);
7517 if (prev
== SCB_LIST_NULL
)
7521 printf("0x%x ", scbid
);
7526 if (found
> AHD_SCB_MAX
)
7527 panic("SCB LIST LOOP");
7529 if (action
== SEARCH_COMPLETE
7530 || action
== SEARCH_REMOVE
)
7531 ahd_outw(ahd
, CMDS_PENDING
, ahd_inw(ahd
, CMDS_PENDING
) - found
);
7536 ahd_stitch_tid_list(struct ahd_softc
*ahd
, u_int tid_prev
,
7537 u_int tid_cur
, u_int tid_next
)
7539 AHD_ASSERT_MODES(ahd
, AHD_MODE_CCHAN_MSK
, AHD_MODE_CCHAN_MSK
);
7541 if (SCBID_IS_NULL(tid_cur
)) {
7543 /* Bypass current TID list */
7544 if (SCBID_IS_NULL(tid_prev
)) {
7545 ahd_outw(ahd
, WAITING_TID_HEAD
, tid_next
);
7547 ahd_set_scbptr(ahd
, tid_prev
);
7548 ahd_outw(ahd
, SCB_NEXT2
, tid_next
);
7550 if (SCBID_IS_NULL(tid_next
))
7551 ahd_outw(ahd
, WAITING_TID_TAIL
, tid_prev
);
7554 /* Stitch through tid_cur */
7555 if (SCBID_IS_NULL(tid_prev
)) {
7556 ahd_outw(ahd
, WAITING_TID_HEAD
, tid_cur
);
7558 ahd_set_scbptr(ahd
, tid_prev
);
7559 ahd_outw(ahd
, SCB_NEXT2
, tid_cur
);
7561 ahd_set_scbptr(ahd
, tid_cur
);
7562 ahd_outw(ahd
, SCB_NEXT2
, tid_next
);
7564 if (SCBID_IS_NULL(tid_next
))
7565 ahd_outw(ahd
, WAITING_TID_TAIL
, tid_cur
);
7570 * Manipulate the waiting for selection list and return the
7571 * scb that follows the one that we remove.
7574 ahd_rem_wscb(struct ahd_softc
*ahd
, u_int scbid
,
7575 u_int prev
, u_int next
, u_int tid
)
7579 AHD_ASSERT_MODES(ahd
, AHD_MODE_CCHAN_MSK
, AHD_MODE_CCHAN_MSK
);
7580 if (!SCBID_IS_NULL(prev
)) {
7581 ahd_set_scbptr(ahd
, prev
);
7582 ahd_outw(ahd
, SCB_NEXT
, next
);
7586 * SCBs that had MK_MESSAGE set in them will not
7587 * be queued to the per-target lists, so don't
7588 * blindly clear the tail pointer.
7590 tail_offset
= WAITING_SCB_TAILS
+ (2 * tid
);
7591 if (SCBID_IS_NULL(next
)
7592 && ahd_inw(ahd
, tail_offset
) == scbid
)
7593 ahd_outw(ahd
, tail_offset
, prev
);
7594 ahd_add_scb_to_free_list(ahd
, scbid
);
7599 * Add the SCB as selected by SCBPTR onto the on chip list of
7600 * free hardware SCBs. This list is empty/unused if we are not
7601 * performing SCB paging.
7604 ahd_add_scb_to_free_list(struct ahd_softc
*ahd
, u_int scbid
)
7606 /* XXX Need some other mechanism to designate "free". */
7608 * Invalidate the tag so that our abort
7609 * routines don't think it's active.
7610 ahd_outb(ahd, SCB_TAG, SCB_LIST_NULL);
7614 /******************************** Error Handling ******************************/
7616 * Abort all SCBs that match the given description (target/channel/lun/tag),
7617 * setting their status to the passed in status if the status has not already
7618 * been modified from CAM_REQ_INPROG. This routine assumes that the sequencer
7619 * is paused before it is called.
7622 ahd_abort_scbs(struct ahd_softc
*ahd
, int target
, char channel
,
7623 int lun
, u_int tag
, role_t role
, uint32_t status
)
7626 struct scb
*scbp_next
;
7632 ahd_mode_state saved_modes
;
7634 /* restore this when we're done */
7635 saved_modes
= ahd_save_modes(ahd
);
7636 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
7638 found
= ahd_search_qinfifo(ahd
, target
, channel
, lun
, SCB_LIST_NULL
,
7639 role
, CAM_REQUEUE_REQ
, SEARCH_COMPLETE
);
7642 * Clean out the busy target table for any untagged commands.
7646 if (target
!= CAM_TARGET_WILDCARD
) {
7653 if (lun
== CAM_LUN_WILDCARD
) {
7655 maxlun
= AHD_NUM_LUNS_NONPKT
;
7656 } else if (lun
>= AHD_NUM_LUNS_NONPKT
) {
7657 minlun
= maxlun
= 0;
7663 if (role
!= ROLE_TARGET
) {
7664 for (;i
< maxtarget
; i
++) {
7665 for (j
= minlun
;j
< maxlun
; j
++) {
7669 tcl
= BUILD_TCL_RAW(i
, 'A', j
);
7670 scbid
= ahd_find_busy_tcl(ahd
, tcl
);
7671 scbp
= ahd_lookup_scb(ahd
, scbid
);
7673 || ahd_match_scb(ahd
, scbp
, target
, channel
,
7674 lun
, tag
, role
) == 0)
7676 ahd_unbusy_tcl(ahd
, BUILD_TCL_RAW(i
, 'A', j
));
7682 * Don't abort commands that have already completed,
7683 * but haven't quite made it up to the host yet.
7685 ahd_flush_qoutfifo(ahd
);
7688 * Go through the pending CCB list and look for
7689 * commands for this target that are still active.
7690 * These are other tagged commands that were
7691 * disconnected when the reset occurred.
7693 scbp_next
= LIST_FIRST(&ahd
->pending_scbs
);
7694 while (scbp_next
!= NULL
) {
7696 scbp_next
= LIST_NEXT(scbp
, pending_links
);
7697 if (ahd_match_scb(ahd
, scbp
, target
, channel
, lun
, tag
, role
)) {
7700 ostat
= ahd_get_transaction_status(scbp
);
7701 if (ostat
== CAM_REQ_INPROG
)
7702 ahd_set_transaction_status(scbp
, status
);
7703 if (ahd_get_transaction_status(scbp
) != CAM_REQ_CMP
)
7704 ahd_freeze_scb(scbp
);
7705 if ((scbp
->flags
& SCB_ACTIVE
) == 0)
7706 printf("Inactive SCB on pending list\n");
7707 ahd_done(ahd
, scbp
);
7711 ahd_restore_modes(ahd
, saved_modes
);
7712 ahd_platform_abort_scbs(ahd
, target
, channel
, lun
, tag
, role
, status
);
7713 ahd
->flags
|= AHD_UPDATE_PEND_CMDS
;
7718 ahd_reset_current_bus(struct ahd_softc
*ahd
)
7722 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
7723 ahd_outb(ahd
, SIMODE1
, ahd_inb(ahd
, SIMODE1
) & ~ENSCSIRST
);
7724 scsiseq
= ahd_inb(ahd
, SCSISEQ0
) & ~(ENSELO
|ENARBO
|SCSIRSTO
);
7725 ahd_outb(ahd
, SCSISEQ0
, scsiseq
| SCSIRSTO
);
7726 ahd_flush_device_writes(ahd
);
7727 ahd_delay(AHD_BUSRESET_DELAY
);
7728 /* Turn off the bus reset */
7729 ahd_outb(ahd
, SCSISEQ0
, scsiseq
);
7730 ahd_flush_device_writes(ahd
);
7731 ahd_delay(AHD_BUSRESET_DELAY
);
7732 if ((ahd
->bugs
& AHD_SCSIRST_BUG
) != 0) {
7735 * Certain chip state is not cleared for
7736 * SCSI bus resets that we initiate, so
7737 * we must reset the chip.
7739 ahd_reset(ahd
, /*reinit*/TRUE
);
7740 ahd_intr_enable(ahd
, /*enable*/TRUE
);
7741 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
7744 ahd_clear_intstat(ahd
);
7748 ahd_reset_channel(struct ahd_softc
*ahd
, char channel
, int initiate_reset
)
7750 struct ahd_devinfo devinfo
;
7758 ahd
->pending_device
= NULL
;
7760 ahd_compile_devinfo(&devinfo
,
7761 CAM_TARGET_WILDCARD
,
7762 CAM_TARGET_WILDCARD
,
7764 channel
, ROLE_UNKNOWN
);
7767 /* Make sure the sequencer is in a safe location. */
7768 ahd_clear_critical_section(ahd
);
7770 #ifdef AHD_TARGET_MODE
7771 if ((ahd
->flags
& AHD_TARGETROLE
) != 0) {
7772 ahd_run_tqinfifo(ahd
, /*paused*/TRUE
);
7775 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
7778 * Disable selections so no automatic hardware
7779 * functions will modify chip state.
7781 ahd_outb(ahd
, SCSISEQ0
, 0);
7782 ahd_outb(ahd
, SCSISEQ1
, 0);
7785 * Safely shut down our DMA engines. Always start with
7786 * the FIFO that is not currently active (if any are
7787 * actively connected).
7789 next_fifo
= fifo
= ahd_inb(ahd
, DFFSTAT
) & CURRFIFO
;
7790 if (next_fifo
> CURRFIFO_1
)
7791 /* If disconneced, arbitrarily start with FIFO1. */
7792 next_fifo
= fifo
= 0;
7794 next_fifo
^= CURRFIFO_1
;
7795 ahd_set_modes(ahd
, next_fifo
, next_fifo
);
7796 ahd_outb(ahd
, DFCNTRL
,
7797 ahd_inb(ahd
, DFCNTRL
) & ~(SCSIEN
|HDMAEN
));
7798 while ((ahd_inb(ahd
, DFCNTRL
) & HDMAENACK
) != 0)
7801 * Set CURRFIFO to the now inactive channel.
7803 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
7804 ahd_outb(ahd
, DFFSTAT
, next_fifo
);
7805 } while (next_fifo
!= fifo
);
7808 * Reset the bus if we are initiating this reset
7810 ahd_clear_msg_state(ahd
);
7811 ahd_outb(ahd
, SIMODE1
,
7812 ahd_inb(ahd
, SIMODE1
) & ~(ENBUSFREE
|ENSCSIRST
|ENBUSFREE
));
7815 ahd_reset_current_bus(ahd
);
7817 ahd_clear_intstat(ahd
);
7820 * Clean up all the state information for the
7821 * pending transactions on this bus.
7823 found
= ahd_abort_scbs(ahd
, CAM_TARGET_WILDCARD
, channel
,
7824 CAM_LUN_WILDCARD
, SCB_LIST_NULL
,
7825 ROLE_UNKNOWN
, CAM_SCSI_BUS_RESET
);
7828 * Cleanup anything left in the FIFOs.
7830 ahd_clear_fifo(ahd
, 0);
7831 ahd_clear_fifo(ahd
, 1);
7834 * Revert to async/narrow transfers until we renegotiate.
7836 max_scsiid
= (ahd
->features
& AHD_WIDE
) ? 15 : 7;
7837 for (target
= 0; target
<= max_scsiid
; target
++) {
7839 if (ahd
->enabled_targets
[target
] == NULL
)
7841 for (initiator
= 0; initiator
<= max_scsiid
; initiator
++) {
7842 struct ahd_devinfo devinfo
;
7844 ahd_compile_devinfo(&devinfo
, target
, initiator
,
7847 ahd_set_width(ahd
, &devinfo
, MSG_EXT_WDTR_BUS_8_BIT
,
7848 AHD_TRANS_CUR
, /*paused*/TRUE
);
7849 ahd_set_syncrate(ahd
, &devinfo
, /*period*/0,
7850 /*offset*/0, /*ppr_options*/0,
7851 AHD_TRANS_CUR
, /*paused*/TRUE
);
7855 #ifdef AHD_TARGET_MODE
7856 max_scsiid
= (ahd
->features
& AHD_WIDE
) ? 15 : 7;
7859 * Send an immediate notify ccb to all target more peripheral
7860 * drivers affected by this action.
7862 for (target
= 0; target
<= max_scsiid
; target
++) {
7863 struct ahd_tmode_tstate
* tstate
;
7866 tstate
= ahd
->enabled_targets
[target
];
7869 for (lun
= 0; lun
< AHD_NUM_LUNS
; lun
++) {
7870 struct ahd_tmode_lstate
* lstate
;
7872 lstate
= tstate
->enabled_luns
[lun
];
7876 ahd_queue_lstate_event(ahd
, lstate
, CAM_TARGET_WILDCARD
,
7877 EVENT_TYPE_BUS_RESET
, /*arg*/0);
7878 ahd_send_lstate_events(ahd
, lstate
);
7882 /* Notify the XPT that a bus reset occurred */
7883 ahd_send_async(ahd
, devinfo
.channel
, CAM_TARGET_WILDCARD
,
7884 CAM_LUN_WILDCARD
, AC_BUS_RESET
, NULL
);
7887 * Freeze the SIMQ until our poller can determine that
7888 * the bus reset has really gone away. We set the initial
7889 * timer to 0 to have the check performed as soon as possible
7890 * from the timer context.
7892 if ((ahd
->flags
& AHD_RESET_POLL_ACTIVE
) == 0) {
7893 ahd
->flags
|= AHD_RESET_POLL_ACTIVE
;
7894 ahd_freeze_simq(ahd
);
7895 ahd_timer_reset(&ahd
->reset_timer
, 0, ahd_reset_poll
, ahd
);
7901 #define AHD_RESET_POLL_US 1000
7903 ahd_reset_poll(void *arg
)
7905 struct ahd_softc
*ahd
;
7911 ahd
= ahd_find_softc((struct ahd_softc
*)arg
);
7913 printf("ahd_reset_poll: Instance %p no longer exists\n", arg
);
7914 ahd_list_unlock(&l
);
7919 ahd_update_modes(ahd
);
7920 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
7921 ahd_outb(ahd
, CLRSINT1
, CLRSCSIRSTI
);
7922 if ((ahd_inb(ahd
, SSTAT1
) & SCSIRSTI
) != 0) {
7923 ahd_timer_reset(&ahd
->reset_timer
, AHD_RESET_POLL_US
,
7924 ahd_reset_poll
, ahd
);
7926 ahd_unlock(ahd
, &s
);
7927 ahd_list_unlock(&l
);
7931 /* Reset is now low. Complete chip reinitialization. */
7932 ahd_outb(ahd
, SIMODE1
, ahd_inb(ahd
, SIMODE1
) | ENSCSIRST
);
7933 scsiseq1
= ahd_inb(ahd
, SCSISEQ_TEMPLATE
);
7934 ahd_outb(ahd
, SCSISEQ1
, scsiseq1
& (ENSELI
|ENRSELI
|ENAUTOATNP
));
7936 ahd
->flags
&= ~AHD_RESET_POLL_ACTIVE
;
7937 ahd_unlock(ahd
, &s
);
7938 ahd_release_simq(ahd
);
7939 ahd_list_unlock(&l
);
7942 /**************************** Statistics Processing ***************************/
7944 ahd_stat_timer(void *arg
)
7946 struct ahd_softc
*ahd
;
7952 ahd
= ahd_find_softc((struct ahd_softc
*)arg
);
7954 printf("ahd_stat_timer: Instance %p no longer exists\n", arg
);
7955 ahd_list_unlock(&l
);
7960 enint_coal
= ahd
->hs_mailbox
& ENINT_COALESCE
;
7961 if (ahd
->cmdcmplt_total
> ahd
->int_coalescing_threshold
)
7962 enint_coal
|= ENINT_COALESCE
;
7963 else if (ahd
->cmdcmplt_total
< ahd
->int_coalescing_stop_threshold
)
7964 enint_coal
&= ~ENINT_COALESCE
;
7966 if (enint_coal
!= (ahd
->hs_mailbox
& ENINT_COALESCE
)) {
7967 ahd_enable_coalescing(ahd
, enint_coal
);
7969 if ((ahd_debug
& AHD_SHOW_INT_COALESCING
) != 0)
7970 printf("%s: Interrupt coalescing "
7971 "now %sabled. Cmds %d\n",
7973 (enint_coal
& ENINT_COALESCE
) ? "en" : "dis",
7974 ahd
->cmdcmplt_total
);
7978 ahd
->cmdcmplt_bucket
= (ahd
->cmdcmplt_bucket
+1) & (AHD_STAT_BUCKETS
-1);
7979 ahd
->cmdcmplt_total
-= ahd
->cmdcmplt_counts
[ahd
->cmdcmplt_bucket
];
7980 ahd
->cmdcmplt_counts
[ahd
->cmdcmplt_bucket
] = 0;
7981 ahd_timer_reset(&ahd
->stat_timer
, AHD_STAT_UPDATE_US
,
7982 ahd_stat_timer
, ahd
);
7983 ahd_unlock(ahd
, &s
);
7984 ahd_list_unlock(&l
);
7987 /****************************** Status Processing *****************************/
7989 ahd_handle_scb_status(struct ahd_softc
*ahd
, struct scb
*scb
)
7991 if (scb
->hscb
->shared_data
.istatus
.scsi_status
!= 0) {
7992 ahd_handle_scsi_status(ahd
, scb
);
7994 ahd_calc_residual(ahd
, scb
);
8000 ahd_handle_scsi_status(struct ahd_softc
*ahd
, struct scb
*scb
)
8002 struct hardware_scb
*hscb
;
8006 * The sequencer freezes its select-out queue
8007 * anytime a SCSI status error occurs. We must
8008 * handle the error and decrement the QFREEZE count
8009 * to allow the sequencer to continue.
8013 /* Freeze the queue until the client sees the error. */
8014 ahd_freeze_devq(ahd
, scb
);
8015 ahd_freeze_scb(scb
);
8016 qfreeze_cnt
= ahd_inw(ahd
, QFREEZE_COUNT
);
8017 if (qfreeze_cnt
== 0) {
8018 printf("%s: Bad status with 0 qfreeze count!\n", ahd_name(ahd
));
8021 ahd_outw(ahd
, QFREEZE_COUNT
, qfreeze_cnt
);
8023 if (qfreeze_cnt
== 0)
8024 ahd_outb(ahd
, SEQ_FLAGS2
,
8025 ahd_inb(ahd
, SEQ_FLAGS2
) & ~SELECTOUT_QFROZEN
);
8027 /* Don't want to clobber the original sense code */
8028 if ((scb
->flags
& SCB_SENSE
) != 0) {
8030 * Clear the SCB_SENSE Flag and perform
8031 * a normal command completion.
8033 scb
->flags
&= ~SCB_SENSE
;
8034 ahd_set_transaction_status(scb
, CAM_AUTOSENSE_FAIL
);
8038 ahd_set_transaction_status(scb
, CAM_SCSI_STATUS_ERROR
);
8039 ahd_set_scsi_status(scb
, hscb
->shared_data
.istatus
.scsi_status
);
8040 switch (hscb
->shared_data
.istatus
.scsi_status
) {
8041 case STATUS_PKT_SENSE
:
8043 struct scsi_status_iu_header
*siu
;
8045 ahd_sync_sense(ahd
, scb
, BUS_DMASYNC_POSTREAD
);
8046 siu
= (struct scsi_status_iu_header
*)scb
->sense_data
;
8047 ahd_set_scsi_status(scb
, siu
->status
);
8049 if ((ahd_debug
& AHD_SHOW_SENSE
) != 0) {
8050 ahd_print_path(ahd
, scb
);
8051 printf("SCB 0x%x Received PKT Status of 0x%x\n",
8052 SCB_GET_TAG(scb
), siu
->status
);
8053 printf("\tflags = 0x%x, sense len = 0x%x, "
8055 siu
->flags
, scsi_4btoul(siu
->sense_length
),
8056 scsi_4btoul(siu
->pkt_failures_length
));
8059 if ((siu
->flags
& SIU_RSPVALID
) != 0) {
8060 ahd_print_path(ahd
, scb
);
8061 if (scsi_4btoul(siu
->pkt_failures_length
) < 4) {
8062 printf("Unable to parse pkt_failures\n");
8065 switch (SIU_PKTFAIL_CODE(siu
)) {
8067 printf("No packet failure found\n");
8069 case SIU_PFC_CIU_FIELDS_INVALID
:
8070 printf("Invalid Command IU Field\n");
8072 case SIU_PFC_TMF_NOT_SUPPORTED
:
8073 printf("TMF not supportd\n");
8075 case SIU_PFC_TMF_FAILED
:
8076 printf("TMF failed\n");
8078 case SIU_PFC_INVALID_TYPE_CODE
:
8079 printf("Invalid L_Q Type code\n");
8081 case SIU_PFC_ILLEGAL_REQUEST
:
8082 printf("Illegal request\n");
8087 if (siu
->status
== SCSI_STATUS_OK
)
8088 ahd_set_transaction_status(scb
,
8091 if ((siu
->flags
& SIU_SNSVALID
) != 0) {
8092 scb
->flags
|= SCB_PKT_SENSE
;
8094 if ((ahd_debug
& AHD_SHOW_SENSE
) != 0)
8095 printf("Sense data available\n");
8101 case SCSI_STATUS_CMD_TERMINATED
:
8102 case SCSI_STATUS_CHECK_COND
:
8104 struct ahd_devinfo devinfo
;
8105 struct ahd_dma_seg
*sg
;
8106 struct scsi_sense
*sc
;
8107 struct ahd_initiator_tinfo
*targ_info
;
8108 struct ahd_tmode_tstate
*tstate
;
8109 struct ahd_transinfo
*tinfo
;
8111 if (ahd_debug
& AHD_SHOW_SENSE
) {
8112 ahd_print_path(ahd
, scb
);
8113 printf("SCB %d: requests Check Status\n",
8118 if (ahd_perform_autosense(scb
) == 0)
8121 ahd_compile_devinfo(&devinfo
, SCB_GET_OUR_ID(scb
),
8122 SCB_GET_TARGET(ahd
, scb
),
8124 SCB_GET_CHANNEL(ahd
, scb
),
8126 targ_info
= ahd_fetch_transinfo(ahd
,
8131 tinfo
= &targ_info
->curr
;
8133 sc
= (struct scsi_sense
*)hscb
->shared_data
.idata
.cdb
;
8135 * Save off the residual if there is one.
8137 ahd_update_residual(ahd
, scb
);
8139 if (ahd_debug
& AHD_SHOW_SENSE
) {
8140 ahd_print_path(ahd
, scb
);
8141 printf("Sending Sense\n");
8145 sg
= ahd_sg_setup(ahd
, scb
, sg
, ahd_get_sense_bufaddr(ahd
, scb
),
8146 ahd_get_sense_bufsize(ahd
, scb
),
8148 sc
->opcode
= REQUEST_SENSE
;
8150 if (tinfo
->protocol_version
<= SCSI_REV_2
8151 && SCB_GET_LUN(scb
) < 8)
8152 sc
->byte2
= SCB_GET_LUN(scb
) << 5;
8155 sc
->length
= ahd_get_sense_bufsize(ahd
, scb
);
8159 * We can't allow the target to disconnect.
8160 * This will be an untagged transaction and
8161 * having the target disconnect will make this
8162 * transaction indestinguishable from outstanding
8163 * tagged transactions.
8168 * This request sense could be because the
8169 * the device lost power or in some other
8170 * way has lost our transfer negotiations.
8171 * Renegotiate if appropriate. Unit attention
8172 * errors will be reported before any data
8175 if (ahd_get_residual(scb
) == ahd_get_transfer_length(scb
)) {
8176 ahd_update_neg_request(ahd
, &devinfo
,
8178 AHD_NEG_IF_NON_ASYNC
);
8180 if (tstate
->auto_negotiate
& devinfo
.target_mask
) {
8181 hscb
->control
|= MK_MESSAGE
;
8183 ~(SCB_NEGOTIATE
|SCB_ABORT
|SCB_DEVICE_RESET
);
8184 scb
->flags
|= SCB_AUTO_NEGOTIATE
;
8186 hscb
->cdb_len
= sizeof(*sc
);
8187 ahd_setup_data_scb(ahd
, scb
);
8188 scb
->flags
|= SCB_SENSE
;
8189 ahd_queue_scb(ahd
, scb
);
8191 * Ensure we have enough time to actually
8192 * retrieve the sense.
8194 ahd_scb_timer_reset(scb
, 5 * 1000000);
8197 case SCSI_STATUS_OK
:
8198 printf("%s: Interrupted for staus of 0???\n",
8208 * Calculate the residual for a just completed SCB.
8211 ahd_calc_residual(struct ahd_softc
*ahd
, struct scb
*scb
)
8213 struct hardware_scb
*hscb
;
8214 struct initiator_status
*spkt
;
8216 uint32_t resid_sgptr
;
8222 * SG_STATUS_VALID clear in sgptr.
8223 * 2) Transferless command
8224 * 3) Never performed any transfers.
8225 * sgptr has SG_FULL_RESID set.
8226 * 4) No residual but target did not
8227 * save data pointers after the
8228 * last transfer, so sgptr was
8230 * 5) We have a partial residual.
8231 * Use residual_sgptr to determine
8236 sgptr
= ahd_le32toh(hscb
->sgptr
);
8237 if ((sgptr
& SG_STATUS_VALID
) == 0)
8240 sgptr
&= ~SG_STATUS_VALID
;
8242 if ((sgptr
& SG_LIST_NULL
) != 0)
8247 * Residual fields are the same in both
8248 * target and initiator status packets,
8249 * so we can always use the initiator fields
8250 * regardless of the role for this SCB.
8252 spkt
= &hscb
->shared_data
.istatus
;
8253 resid_sgptr
= ahd_le32toh(spkt
->residual_sgptr
);
8254 if ((sgptr
& SG_FULL_RESID
) != 0) {
8256 resid
= ahd_get_transfer_length(scb
);
8257 } else if ((resid_sgptr
& SG_LIST_NULL
) != 0) {
8260 } else if ((resid_sgptr
& SG_OVERRUN_RESID
) != 0) {
8261 ahd_print_path(ahd
, scb
);
8262 printf("data overrun detected Tag == 0x%x.\n",
8264 ahd_freeze_devq(ahd
, scb
);
8265 ahd_set_transaction_status(scb
, CAM_DATA_RUN_ERR
);
8266 ahd_freeze_scb(scb
);
8268 } else if ((resid_sgptr
& ~SG_PTR_MASK
) != 0) {
8269 panic("Bogus resid sgptr value 0x%x\n", resid_sgptr
);
8272 struct ahd_dma_seg
*sg
;
8275 * Remainder of the SG where the transfer
8278 resid
= ahd_le32toh(spkt
->residual_datacnt
) & AHD_SG_LEN_MASK
;
8279 sg
= ahd_sg_bus_to_virt(ahd
, scb
, resid_sgptr
& SG_PTR_MASK
);
8281 /* The residual sg_ptr always points to the next sg */
8285 * Add up the contents of all residual
8286 * SG segments that are after the SG where
8287 * the transfer stopped.
8289 while ((ahd_le32toh(sg
->len
) & AHD_DMA_LAST_SEG
) == 0) {
8291 resid
+= ahd_le32toh(sg
->len
) & AHD_SG_LEN_MASK
;
8294 if ((scb
->flags
& SCB_SENSE
) == 0)
8295 ahd_set_residual(scb
, resid
);
8297 ahd_set_sense_residual(scb
, resid
);
8300 if ((ahd_debug
& AHD_SHOW_MISC
) != 0) {
8301 ahd_print_path(ahd
, scb
);
8302 printf("Handled %sResidual of %d bytes\n",
8303 (scb
->flags
& SCB_SENSE
) ? "Sense " : "", resid
);
8308 /******************************* Target Mode **********************************/
8309 #ifdef AHD_TARGET_MODE
8311 * Add a target mode event to this lun's queue
8314 ahd_queue_lstate_event(struct ahd_softc
*ahd
, struct ahd_tmode_lstate
*lstate
,
8315 u_int initiator_id
, u_int event_type
, u_int event_arg
)
8317 struct ahd_tmode_event
*event
;
8320 xpt_freeze_devq(lstate
->path
, /*count*/1);
8321 if (lstate
->event_w_idx
>= lstate
->event_r_idx
)
8322 pending
= lstate
->event_w_idx
- lstate
->event_r_idx
;
8324 pending
= AHD_TMODE_EVENT_BUFFER_SIZE
+ 1
8325 - (lstate
->event_r_idx
- lstate
->event_w_idx
);
8327 if (event_type
== EVENT_TYPE_BUS_RESET
8328 || event_type
== MSG_BUS_DEV_RESET
) {
8330 * Any earlier events are irrelevant, so reset our buffer.
8331 * This has the effect of allowing us to deal with reset
8332 * floods (an external device holding down the reset line)
8333 * without losing the event that is really interesting.
8335 lstate
->event_r_idx
= 0;
8336 lstate
->event_w_idx
= 0;
8337 xpt_release_devq(lstate
->path
, pending
, /*runqueue*/FALSE
);
8340 if (pending
== AHD_TMODE_EVENT_BUFFER_SIZE
) {
8341 xpt_print_path(lstate
->path
);
8342 printf("immediate event %x:%x lost\n",
8343 lstate
->event_buffer
[lstate
->event_r_idx
].event_type
,
8344 lstate
->event_buffer
[lstate
->event_r_idx
].event_arg
);
8345 lstate
->event_r_idx
++;
8346 if (lstate
->event_r_idx
== AHD_TMODE_EVENT_BUFFER_SIZE
)
8347 lstate
->event_r_idx
= 0;
8348 xpt_release_devq(lstate
->path
, /*count*/1, /*runqueue*/FALSE
);
8351 event
= &lstate
->event_buffer
[lstate
->event_w_idx
];
8352 event
->initiator_id
= initiator_id
;
8353 event
->event_type
= event_type
;
8354 event
->event_arg
= event_arg
;
8355 lstate
->event_w_idx
++;
8356 if (lstate
->event_w_idx
== AHD_TMODE_EVENT_BUFFER_SIZE
)
8357 lstate
->event_w_idx
= 0;
8361 * Send any target mode events queued up waiting
8362 * for immediate notify resources.
8365 ahd_send_lstate_events(struct ahd_softc
*ahd
, struct ahd_tmode_lstate
*lstate
)
8367 struct ccb_hdr
*ccbh
;
8368 struct ccb_immed_notify
*inot
;
8370 while (lstate
->event_r_idx
!= lstate
->event_w_idx
8371 && (ccbh
= SLIST_FIRST(&lstate
->immed_notifies
)) != NULL
) {
8372 struct ahd_tmode_event
*event
;
8374 event
= &lstate
->event_buffer
[lstate
->event_r_idx
];
8375 SLIST_REMOVE_HEAD(&lstate
->immed_notifies
, sim_links
.sle
);
8376 inot
= (struct ccb_immed_notify
*)ccbh
;
8377 switch (event
->event_type
) {
8378 case EVENT_TYPE_BUS_RESET
:
8379 ccbh
->status
= CAM_SCSI_BUS_RESET
|CAM_DEV_QFRZN
;
8382 ccbh
->status
= CAM_MESSAGE_RECV
|CAM_DEV_QFRZN
;
8383 inot
->message_args
[0] = event
->event_type
;
8384 inot
->message_args
[1] = event
->event_arg
;
8387 inot
->initiator_id
= event
->initiator_id
;
8388 inot
->sense_len
= 0;
8389 xpt_done((union ccb
*)inot
);
8390 lstate
->event_r_idx
++;
8391 if (lstate
->event_r_idx
== AHD_TMODE_EVENT_BUFFER_SIZE
)
8392 lstate
->event_r_idx
= 0;
8397 /******************** Sequencer Program Patching/Download *********************/
8401 ahd_dumpseq(struct ahd_softc
* ahd
)
8408 ahd_outb(ahd
, SEQCTL0
, PERRORDIS
|FAILDIS
|FASTMODE
|LOADRAM
);
8409 ahd_outb(ahd
, PRGMCNT
, 0);
8410 ahd_outb(ahd
, PRGMCNT
+1, 0);
8411 for (i
= 0; i
< max_prog
; i
++) {
8412 uint8_t ins_bytes
[4];
8414 ahd_insb(ahd
, SEQRAM
, ins_bytes
, 4);
8415 printf("0x%08x\n", ins_bytes
[0] << 24
8416 | ins_bytes
[1] << 16
8424 ahd_loadseq(struct ahd_softc
*ahd
)
8426 struct cs cs_table
[num_critical_sections
];
8427 u_int begin_set
[num_critical_sections
];
8428 u_int end_set
[num_critical_sections
];
8429 struct patch
*cur_patch
;
8435 u_int sg_prefetch_cnt
;
8436 u_int sg_prefetch_cnt_limit
;
8437 u_int sg_prefetch_align
;
8439 uint8_t download_consts
[DOWNLOAD_CONST_COUNT
];
8442 printf("%s: Downloading Sequencer Program...",
8445 #if DOWNLOAD_CONST_COUNT != 7
8446 #error "Download Const Mismatch"
8449 * Start out with 0 critical sections
8450 * that apply to this firmware load.
8454 memset(begin_set
, 0, sizeof(begin_set
));
8455 memset(end_set
, 0, sizeof(end_set
));
8458 * Setup downloadable constant table.
8460 * The computation for the S/G prefetch variables is
8461 * a bit complicated. We would like to always fetch
8462 * in terms of cachelined sized increments. However,
8463 * if the cacheline is not an even multiple of the
8464 * SG element size or is larger than our SG RAM, using
8465 * just the cache size might leave us with only a portion
8466 * of an SG element at the tail of a prefetch. If the
8467 * cacheline is larger than our S/G prefetch buffer less
8468 * the size of an SG element, we may round down to a cacheline
8469 * that doesn't contain any or all of the S/G of interest
8470 * within the bounds of our S/G ram. Provide variables to
8471 * the sequencer that will allow it to handle these edge
8474 /* Start by aligning to the nearest cacheline. */
8475 sg_prefetch_align
= ahd
->pci_cachesize
;
8476 if (sg_prefetch_align
== 0)
8477 sg_prefetch_align
= 8;
8478 /* Round down to the nearest power of 2. */
8479 while (powerof2(sg_prefetch_align
) == 0)
8480 sg_prefetch_align
--;
8482 * If the cacheline boundary is greater than half our prefetch RAM
8483 * we risk not being able to fetch even a single complete S/G
8484 * segment if we align to that boundary.
8486 if (sg_prefetch_align
> CCSGADDR_MAX
/2)
8487 sg_prefetch_align
= CCSGADDR_MAX
/2;
8488 /* Start by fetching a single cacheline. */
8489 sg_prefetch_cnt
= sg_prefetch_align
;
8491 * Increment the prefetch count by cachelines until
8492 * at least one S/G element will fit.
8494 sg_size
= sizeof(struct ahd_dma_seg
);
8495 if ((ahd
->flags
& AHD_64BIT_ADDRESSING
) != 0)
8496 sg_size
= sizeof(struct ahd_dma64_seg
);
8497 while (sg_prefetch_cnt
< sg_size
)
8498 sg_prefetch_cnt
+= sg_prefetch_align
;
8500 * If the cacheline is not an even multiple of
8501 * the S/G size, we may only get a partial S/G when
8502 * we align. Add a cacheline if this is the case.
8504 if ((sg_prefetch_align
% sg_size
) != 0
8505 && (sg_prefetch_cnt
< CCSGADDR_MAX
))
8506 sg_prefetch_cnt
+= sg_prefetch_align
;
8508 * Lastly, compute a value that the sequencer can use
8509 * to determine if the remainder of the CCSGRAM buffer
8510 * has a full S/G element in it.
8512 sg_prefetch_cnt_limit
= -(sg_prefetch_cnt
- sg_size
+ 1);
8513 download_consts
[SG_PREFETCH_CNT
] = sg_prefetch_cnt
;
8514 download_consts
[SG_PREFETCH_CNT_LIMIT
] = sg_prefetch_cnt_limit
;
8515 download_consts
[SG_PREFETCH_ALIGN_MASK
] = ~(sg_prefetch_align
- 1);
8516 download_consts
[SG_PREFETCH_ADDR_MASK
] = (sg_prefetch_align
- 1);
8517 download_consts
[SG_SIZEOF
] = sg_size
;
8518 download_consts
[PKT_OVERRUN_BUFOFFSET
] =
8519 (ahd
->overrun_buf
- (uint8_t *)ahd
->qoutfifo
) / 256;
8520 download_consts
[SCB_TRANSFER_SIZE
] = SCB_TRANSFER_SIZE_1BYTE_LUN
;
8521 cur_patch
= patches
;
8524 ahd_outb(ahd
, SEQCTL0
, PERRORDIS
|FAILDIS
|FASTMODE
|LOADRAM
);
8525 ahd_outb(ahd
, PRGMCNT
, 0);
8526 ahd_outb(ahd
, PRGMCNT
+1, 0);
8528 for (i
= 0; i
< sizeof(seqprog
)/4; i
++) {
8529 if (ahd_check_patch(ahd
, &cur_patch
, i
, &skip_addr
) == 0) {
8531 * Don't download this instruction as it
8532 * is in a patch that was removed.
8537 * Move through the CS table until we find a CS
8538 * that might apply to this instruction.
8540 for (; cur_cs
< num_critical_sections
; cur_cs
++) {
8541 if (critical_sections
[cur_cs
].end
<= i
) {
8542 if (begin_set
[cs_count
] == TRUE
8543 && end_set
[cs_count
] == FALSE
) {
8544 cs_table
[cs_count
].end
= downloaded
;
8545 end_set
[cs_count
] = TRUE
;
8550 if (critical_sections
[cur_cs
].begin
<= i
8551 && begin_set
[cs_count
] == FALSE
) {
8552 cs_table
[cs_count
].begin
= downloaded
;
8553 begin_set
[cs_count
] = TRUE
;
8557 ahd_download_instr(ahd
, i
, download_consts
);
8561 ahd
->num_critical_sections
= cs_count
;
8562 if (cs_count
!= 0) {
8564 cs_count
*= sizeof(struct cs
);
8565 ahd
->critical_sections
= malloc(cs_count
, M_DEVBUF
, M_NOWAIT
);
8566 if (ahd
->critical_sections
== NULL
)
8567 panic("ahd_loadseq: Could not malloc");
8568 memcpy(ahd
->critical_sections
, cs_table
, cs_count
);
8570 ahd_outb(ahd
, SEQCTL0
, PERRORDIS
|FAILDIS
|FASTMODE
);
8573 printf(" %d instructions downloaded\n", downloaded
);
8574 printf("%s: Features 0x%x, Bugs 0x%x, Flags 0x%x\n",
8575 ahd_name(ahd
), ahd
->features
, ahd
->bugs
, ahd
->flags
);
8580 ahd_check_patch(struct ahd_softc
*ahd
, struct patch
**start_patch
,
8581 u_int start_instr
, u_int
*skip_addr
)
8583 struct patch
*cur_patch
;
8584 struct patch
*last_patch
;
8587 num_patches
= sizeof(patches
)/sizeof(struct patch
);
8588 last_patch
= &patches
[num_patches
];
8589 cur_patch
= *start_patch
;
8591 while (cur_patch
< last_patch
&& start_instr
== cur_patch
->begin
) {
8593 if (cur_patch
->patch_func(ahd
) == 0) {
8595 /* Start rejecting code */
8596 *skip_addr
= start_instr
+ cur_patch
->skip_instr
;
8597 cur_patch
+= cur_patch
->skip_patch
;
8599 /* Accepted this patch. Advance to the next
8600 * one and wait for our intruction pointer to
8607 *start_patch
= cur_patch
;
8608 if (start_instr
< *skip_addr
)
8609 /* Still skipping */
8616 ahd_resolve_seqaddr(struct ahd_softc
*ahd
, u_int address
)
8618 struct patch
*cur_patch
;
8624 cur_patch
= patches
;
8627 for (i
= 0; i
< address
;) {
8629 ahd_check_patch(ahd
, &cur_patch
, i
, &skip_addr
);
8631 if (skip_addr
> i
) {
8634 end_addr
= MIN(address
, skip_addr
);
8635 address_offset
+= end_addr
- i
;
8641 return (address
- address_offset
);
8645 ahd_download_instr(struct ahd_softc
*ahd
, u_int instrptr
, uint8_t *dconsts
)
8647 union ins_formats instr
;
8648 struct ins_format1
*fmt1_ins
;
8649 struct ins_format3
*fmt3_ins
;
8653 * The firmware is always compiled into a little endian format.
8655 instr
.integer
= ahd_le32toh(*(uint32_t*)&seqprog
[instrptr
* 4]);
8657 fmt1_ins
= &instr
.format1
;
8660 /* Pull the opcode */
8661 opcode
= instr
.format1
.opcode
;
8672 fmt3_ins
= &instr
.format3
;
8673 fmt3_ins
->address
= ahd_resolve_seqaddr(ahd
, fmt3_ins
->address
);
8682 if (fmt1_ins
->parity
!= 0) {
8683 fmt1_ins
->immediate
= dconsts
[fmt1_ins
->immediate
];
8685 fmt1_ins
->parity
= 0;
8691 /* Calculate odd parity for the instruction */
8692 for (i
= 0, count
= 0; i
< 31; i
++) {
8696 if ((instr
.integer
& mask
) != 0)
8699 if ((count
& 0x01) == 0)
8700 instr
.format1
.parity
= 1;
8702 /* The sequencer is a little endian cpu */
8703 instr
.integer
= ahd_htole32(instr
.integer
);
8704 ahd_outsb(ahd
, SEQRAM
, instr
.bytes
, 4);
8708 panic("Unknown opcode encountered in seq program");
8714 ahd_probe_stack_size(struct ahd_softc
*ahd
)
8723 * We avoid using 0 as a pattern to avoid
8724 * confusion if the stack implementation
8725 * "back-fills" with zeros when "poping'
8728 for (i
= 1; i
<= last_probe
+1; i
++) {
8729 ahd_outb(ahd
, STACK
, i
& 0xFF);
8730 ahd_outb(ahd
, STACK
, (i
>> 8) & 0xFF);
8734 for (i
= last_probe
+1; i
> 0; i
--) {
8737 stack_entry
= ahd_inb(ahd
, STACK
)
8738 |(ahd_inb(ahd
, STACK
) << 8);
8739 if (stack_entry
!= i
)
8745 return (last_probe
);
8749 ahd_dump_all_cards_state(void)
8751 struct ahd_softc
*list_ahd
;
8753 TAILQ_FOREACH(list_ahd
, &ahd_tailq
, links
) {
8754 ahd_dump_card_state(list_ahd
);
8759 ahd_print_register(ahd_reg_parse_entry_t
*table
, u_int num_entries
,
8760 const char *name
, u_int address
, u_int value
,
8761 u_int
*cur_column
, u_int wrap_point
)
8766 if (cur_column
!= NULL
&& *cur_column
>= wrap_point
) {
8770 printed
= printf("%s[0x%x]", name
, value
);
8771 if (table
== NULL
) {
8772 printed
+= printf(" ");
8773 *cur_column
+= printed
;
8777 while (printed_mask
!= 0xFF) {
8780 for (entry
= 0; entry
< num_entries
; entry
++) {
8781 if (((value
& table
[entry
].mask
)
8782 != table
[entry
].value
)
8783 || ((printed_mask
& table
[entry
].mask
)
8784 == table
[entry
].mask
))
8787 printed
+= printf("%s%s",
8788 printed_mask
== 0 ? ":(" : "|",
8790 printed_mask
|= table
[entry
].mask
;
8794 if (entry
>= num_entries
)
8797 if (printed_mask
!= 0)
8798 printed
+= printf(") ");
8800 printed
+= printf(" ");
8801 if (cur_column
!= NULL
)
8802 *cur_column
+= printed
;
8807 ahd_dump_card_state(struct ahd_softc
*ahd
)
8810 ahd_mode_state saved_modes
;
8814 u_int saved_scb_index
;
8818 if (ahd_is_paused(ahd
)) {
8824 saved_modes
= ahd_save_modes(ahd
);
8825 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
8826 printf(">>>>>>>>>>>>>>>>>> Dump Card State Begins <<<<<<<<<<<<<<<<<\n"
8827 "%s: Dumping Card State at program address 0x%x Mode 0x%x\n",
8829 ahd_inb(ahd
, CURADDR
) | (ahd_inb(ahd
, CURADDR
+1) << 8),
8830 ahd_build_mode_state(ahd
, ahd
->saved_src_mode
,
8831 ahd
->saved_dst_mode
));
8833 printf("Card was paused\n");
8835 if (ahd_check_cmdcmpltqueues(ahd
))
8836 printf("Completions are pending\n");
8839 * Mode independent registers.
8842 ahd_hs_mailbox_print(ahd_inb(ahd
, LOCAL_HS_MAILBOX
), &cur_col
, 50);
8843 ahd_intctl_print(ahd_inb(ahd
, INTCTL
), &cur_col
, 50);
8844 ahd_seqintstat_print(ahd_inb(ahd
, SEQINTSTAT
), &cur_col
, 50);
8845 ahd_saved_mode_print(ahd_inb(ahd
, SAVED_MODE
), &cur_col
, 50);
8846 ahd_dffstat_print(ahd_inb(ahd
, DFFSTAT
), &cur_col
, 50);
8847 ahd_scsisigi_print(ahd_inb(ahd
, SCSISIGI
), &cur_col
, 50);
8848 ahd_scsiphase_print(ahd_inb(ahd
, SCSIPHASE
), &cur_col
, 50);
8849 ahd_scsibus_print(ahd_inb(ahd
, SCSIBUS
), &cur_col
, 50);
8850 ahd_lastphase_print(ahd_inb(ahd
, LASTPHASE
), &cur_col
, 50);
8851 ahd_scsiseq0_print(ahd_inb(ahd
, SCSISEQ0
), &cur_col
, 50);
8852 ahd_scsiseq1_print(ahd_inb(ahd
, SCSISEQ1
), &cur_col
, 50);
8853 ahd_seqctl0_print(ahd_inb(ahd
, SEQCTL0
), &cur_col
, 50);
8854 ahd_seqintctl_print(ahd_inb(ahd
, SEQINTCTL
), &cur_col
, 50);
8855 ahd_seq_flags_print(ahd_inb(ahd
, SEQ_FLAGS
), &cur_col
, 50);
8856 ahd_seq_flags2_print(ahd_inb(ahd
, SEQ_FLAGS2
), &cur_col
, 50);
8857 ahd_sstat0_print(ahd_inb(ahd
, SSTAT0
), &cur_col
, 50);
8858 ahd_sstat1_print(ahd_inb(ahd
, SSTAT1
), &cur_col
, 50);
8859 ahd_sstat2_print(ahd_inb(ahd
, SSTAT2
), &cur_col
, 50);
8860 ahd_sstat3_print(ahd_inb(ahd
, SSTAT3
), &cur_col
, 50);
8861 ahd_perrdiag_print(ahd_inb(ahd
, PERRDIAG
), &cur_col
, 50);
8862 ahd_simode1_print(ahd_inb(ahd
, SIMODE1
), &cur_col
, 50);
8863 ahd_lqistat0_print(ahd_inb(ahd
, LQISTAT0
), &cur_col
, 50);
8864 ahd_lqistat1_print(ahd_inb(ahd
, LQISTAT1
), &cur_col
, 50);
8865 ahd_lqistat2_print(ahd_inb(ahd
, LQISTAT2
), &cur_col
, 50);
8866 ahd_lqostat0_print(ahd_inb(ahd
, LQOSTAT0
), &cur_col
, 50);
8867 ahd_lqostat1_print(ahd_inb(ahd
, LQOSTAT1
), &cur_col
, 50);
8868 ahd_lqostat2_print(ahd_inb(ahd
, LQOSTAT2
), &cur_col
, 50);
8870 printf("\nSCB Count = %d CMDS_PENDING = %d LASTSCB 0x%x "
8871 "CURRSCB 0x%x NEXTSCB 0x%x\n",
8872 ahd
->scb_data
.numscbs
, ahd_inw(ahd
, CMDS_PENDING
),
8873 ahd_inw(ahd
, LASTSCB
), ahd_inw(ahd
, CURRSCB
),
8874 ahd_inw(ahd
, NEXTSCB
));
8877 ahd_search_qinfifo(ahd
, CAM_TARGET_WILDCARD
, ALL_CHANNELS
,
8878 CAM_LUN_WILDCARD
, SCB_LIST_NULL
,
8879 ROLE_UNKNOWN
, /*status*/0, SEARCH_PRINT
);
8880 saved_scb_index
= ahd_get_scbptr(ahd
);
8881 printf("Pending list:");
8883 LIST_FOREACH(scb
, &ahd
->pending_scbs
, pending_links
) {
8884 if (i
++ > AHD_SCB_MAX
)
8886 cur_col
= printf("\n%3d FIFO_USE[0x%x] ", SCB_GET_TAG(scb
),
8887 ahd_inb_scbram(ahd
, SCB_FIFO_USE_COUNT
));
8888 ahd_set_scbptr(ahd
, SCB_GET_TAG(scb
));
8889 ahd_scb_control_print(ahd_inb_scbram(ahd
, SCB_CONTROL
),
8891 ahd_scb_scsiid_print(ahd_inb_scbram(ahd
, SCB_SCSIID
),
8894 printf("\nTotal %d\n", i
);
8896 printf("Kernel Free SCB list: ");
8898 TAILQ_FOREACH(scb
, &ahd
->scb_data
.free_scbs
, links
.tqe
) {
8899 struct scb
*list_scb
;
8903 printf("%d ", SCB_GET_TAG(list_scb
));
8904 list_scb
= LIST_NEXT(list_scb
, collision_links
);
8905 } while (list_scb
&& i
++ < AHD_SCB_MAX
);
8908 LIST_FOREACH(scb
, &ahd
->scb_data
.any_dev_free_scb_list
, links
.le
) {
8909 if (i
++ > AHD_SCB_MAX
)
8911 printf("%d ", SCB_GET_TAG(scb
));
8915 printf("Sequencer Complete DMA-inprog list: ");
8916 scb_index
= ahd_inw(ahd
, COMPLETE_SCB_DMAINPROG_HEAD
);
8918 while (!SCBID_IS_NULL(scb_index
) && i
++ < AHD_SCB_MAX
) {
8919 ahd_set_scbptr(ahd
, scb_index
);
8920 printf("%d ", scb_index
);
8921 scb_index
= ahd_inw_scbram(ahd
, SCB_NEXT_COMPLETE
);
8925 printf("Sequencer Complete list: ");
8926 scb_index
= ahd_inw(ahd
, COMPLETE_SCB_HEAD
);
8928 while (!SCBID_IS_NULL(scb_index
) && i
++ < AHD_SCB_MAX
) {
8929 ahd_set_scbptr(ahd
, scb_index
);
8930 printf("%d ", scb_index
);
8931 scb_index
= ahd_inw_scbram(ahd
, SCB_NEXT_COMPLETE
);
8936 printf("Sequencer DMA-Up and Complete list: ");
8937 scb_index
= ahd_inw(ahd
, COMPLETE_DMA_SCB_HEAD
);
8939 while (!SCBID_IS_NULL(scb_index
) && i
++ < AHD_SCB_MAX
) {
8940 ahd_set_scbptr(ahd
, scb_index
);
8941 printf("%d ", scb_index
);
8942 scb_index
= ahd_inw_scbram(ahd
, SCB_NEXT_COMPLETE
);
8945 ahd_set_scbptr(ahd
, saved_scb_index
);
8946 dffstat
= ahd_inb(ahd
, DFFSTAT
);
8947 for (i
= 0; i
< 2; i
++) {
8949 struct scb
*fifo_scb
;
8953 ahd_set_modes(ahd
, AHD_MODE_DFF0
+ i
, AHD_MODE_DFF0
+ i
);
8954 fifo_scbptr
= ahd_get_scbptr(ahd
);
8955 printf("\n%s: FIFO%d %s, LONGJMP == 0x%x, SCB 0x%x\n",
8957 (dffstat
& (FIFO0FREE
<< i
)) ? "Free" : "Active",
8958 ahd_inw(ahd
, LONGJMP_ADDR
), fifo_scbptr
);
8960 ahd_seqimode_print(ahd_inb(ahd
, SEQIMODE
), &cur_col
, 50);
8961 ahd_seqintsrc_print(ahd_inb(ahd
, SEQINTSRC
), &cur_col
, 50);
8962 ahd_dfcntrl_print(ahd_inb(ahd
, DFCNTRL
), &cur_col
, 50);
8963 ahd_dfstatus_print(ahd_inb(ahd
, DFSTATUS
), &cur_col
, 50);
8964 ahd_sg_cache_shadow_print(ahd_inb(ahd
, SG_CACHE_SHADOW
),
8966 ahd_sg_state_print(ahd_inb(ahd
, SG_STATE
), &cur_col
, 50);
8967 ahd_dffsxfrctl_print(ahd_inb(ahd
, DFFSXFRCTL
), &cur_col
, 50);
8968 ahd_soffcnt_print(ahd_inb(ahd
, SOFFCNT
), &cur_col
, 50);
8969 ahd_mdffstat_print(ahd_inb(ahd
, MDFFSTAT
), &cur_col
, 50);
8974 cur_col
+= printf("SHADDR = 0x%x%x, SHCNT = 0x%x ",
8975 ahd_inl(ahd
, SHADDR
+4),
8976 ahd_inl(ahd
, SHADDR
),
8977 (ahd_inb(ahd
, SHCNT
)
8978 | (ahd_inb(ahd
, SHCNT
+ 1) << 8)
8979 | (ahd_inb(ahd
, SHCNT
+ 2) << 16)));
8984 cur_col
+= printf("HADDR = 0x%x%x, HCNT = 0x%x ",
8985 ahd_inl(ahd
, HADDR
+4),
8986 ahd_inl(ahd
, HADDR
),
8988 | (ahd_inb(ahd
, HCNT
+ 1) << 8)
8989 | (ahd_inb(ahd
, HCNT
+ 2) << 16)));
8990 ahd_ccsgctl_print(ahd_inb(ahd
, CCSGCTL
), &cur_col
, 50);
8992 if ((ahd_debug
& AHD_SHOW_SG
) != 0) {
8993 fifo_scb
= ahd_lookup_scb(ahd
, fifo_scbptr
);
8994 if (fifo_scb
!= NULL
)
8995 ahd_dump_sglist(fifo_scb
);
9000 for (i
= 0; i
< 20; i
++)
9001 printf("0x%x ", ahd_inb(ahd
, LQIN
+ i
));
9003 ahd_set_modes(ahd
, AHD_MODE_CFG
, AHD_MODE_CFG
);
9004 printf("%s: LQISTATE = 0x%x, LQOSTATE = 0x%x, OPTIONMODE = 0x%x\n",
9005 ahd_name(ahd
), ahd_inb(ahd
, LQISTATE
), ahd_inb(ahd
, LQOSTATE
),
9006 ahd_inb(ahd
, OPTIONMODE
));
9007 printf("%s: OS_SPACE_CNT = 0x%x MAXCMDCNT = 0x%x\n",
9008 ahd_name(ahd
), ahd_inb(ahd
, OS_SPACE_CNT
),
9009 ahd_inb(ahd
, MAXCMDCNT
));
9010 ahd_simode0_print(ahd_inb(ahd
, SIMODE0
), &cur_col
, 50);
9012 ahd_set_modes(ahd
, AHD_MODE_CCHAN
, AHD_MODE_CCHAN
);
9014 ahd_ccscbctl_print(ahd_inb(ahd
, CCSCBCTL
), &cur_col
, 50);
9016 ahd_set_modes(ahd
, ahd
->saved_src_mode
, ahd
->saved_dst_mode
);
9017 printf("%s: REG0 == 0x%x, SINDEX = 0x%x, DINDEX = 0x%x\n",
9018 ahd_name(ahd
), ahd_inw(ahd
, REG0
), ahd_inw(ahd
, SINDEX
),
9019 ahd_inw(ahd
, DINDEX
));
9020 printf("%s: SCBPTR == 0x%x, SCB_NEXT == 0x%x, SCB_NEXT2 == 0x%x\n",
9021 ahd_name(ahd
), ahd_get_scbptr(ahd
),
9022 ahd_inw_scbram(ahd
, SCB_NEXT
),
9023 ahd_inw_scbram(ahd
, SCB_NEXT2
));
9024 printf("CDB %x %x %x %x %x %x\n",
9025 ahd_inb_scbram(ahd
, SCB_CDB_STORE
),
9026 ahd_inb_scbram(ahd
, SCB_CDB_STORE
+1),
9027 ahd_inb_scbram(ahd
, SCB_CDB_STORE
+2),
9028 ahd_inb_scbram(ahd
, SCB_CDB_STORE
+3),
9029 ahd_inb_scbram(ahd
, SCB_CDB_STORE
+4),
9030 ahd_inb_scbram(ahd
, SCB_CDB_STORE
+5));
9032 for (i
= 0; i
< ahd
->stack_size
; i
++) {
9033 ahd
->saved_stack
[i
] =
9034 ahd_inb(ahd
, STACK
)|(ahd_inb(ahd
, STACK
) << 8);
9035 printf(" 0x%x", ahd
->saved_stack
[i
]);
9037 for (i
= ahd
->stack_size
-1; i
>= 0; i
--) {
9038 ahd_outb(ahd
, STACK
, ahd
->saved_stack
[i
] & 0xFF);
9039 ahd_outb(ahd
, STACK
, (ahd
->saved_stack
[i
] >> 8) & 0xFF);
9041 printf("\n<<<<<<<<<<<<<<<<< Dump Card State Ends >>>>>>>>>>>>>>>>>>\n");
9042 ahd_platform_dump_card_state(ahd
);
9043 ahd_restore_modes(ahd
, saved_modes
);
9049 ahd_dump_scbs(struct ahd_softc
*ahd
)
9051 ahd_mode_state saved_modes
;
9052 u_int saved_scb_index
;
9055 saved_modes
= ahd_save_modes(ahd
);
9056 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
9057 saved_scb_index
= ahd_get_scbptr(ahd
);
9058 for (i
= 0; i
< AHD_SCB_MAX
; i
++) {
9059 ahd_set_scbptr(ahd
, i
);
9061 printf("(CTRL 0x%x ID 0x%x N 0x%x N2 0x%x SG 0x%x, RSG 0x%x)\n",
9062 ahd_inb_scbram(ahd
, SCB_CONTROL
),
9063 ahd_inb_scbram(ahd
, SCB_SCSIID
),
9064 ahd_inw_scbram(ahd
, SCB_NEXT
),
9065 ahd_inw_scbram(ahd
, SCB_NEXT2
),
9066 ahd_inl_scbram(ahd
, SCB_SGPTR
),
9067 ahd_inl_scbram(ahd
, SCB_RESIDUAL_SGPTR
));
9070 ahd_set_scbptr(ahd
, saved_scb_index
);
9071 ahd_restore_modes(ahd
, saved_modes
);
9074 /**************************** Flexport Logic **********************************/
9076 * Read count 16bit words from 16bit word address start_addr from the
9077 * SEEPROM attached to the controller, into buf, using the controller's
9078 * SEEPROM reading state machine. Optionally treat the data as a byte
9079 * stream in terms of byte order.
9082 ahd_read_seeprom(struct ahd_softc
*ahd
, uint16_t *buf
,
9083 u_int start_addr
, u_int count
, int bytestream
)
9090 * If we never make it through the loop even once,
9091 * we were passed invalid arguments.
9094 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
9095 end_addr
= start_addr
+ count
;
9096 for (cur_addr
= start_addr
; cur_addr
< end_addr
; cur_addr
++) {
9098 ahd_outb(ahd
, SEEADR
, cur_addr
);
9099 ahd_outb(ahd
, SEECTL
, SEEOP_READ
| SEESTART
);
9101 error
= ahd_wait_seeprom(ahd
);
9104 if (bytestream
!= 0) {
9105 uint8_t *bytestream_ptr
;
9107 bytestream_ptr
= (uint8_t *)buf
;
9108 *bytestream_ptr
++ = ahd_inb(ahd
, SEEDAT
);
9109 *bytestream_ptr
= ahd_inb(ahd
, SEEDAT
+1);
9112 * ahd_inw() already handles machine byte order.
9114 *buf
= ahd_inw(ahd
, SEEDAT
);
9122 * Write count 16bit words from buf, into SEEPROM attache to the
9123 * controller starting at 16bit word address start_addr, using the
9124 * controller's SEEPROM writing state machine.
9127 ahd_write_seeprom(struct ahd_softc
*ahd
, uint16_t *buf
,
9128 u_int start_addr
, u_int count
)
9135 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
9138 /* Place the chip into write-enable mode */
9139 ahd_outb(ahd
, SEEADR
, SEEOP_EWEN_ADDR
);
9140 ahd_outb(ahd
, SEECTL
, SEEOP_EWEN
| SEESTART
);
9141 error
= ahd_wait_seeprom(ahd
);
9146 * Write the data. If we don't get throught the loop at
9147 * least once, the arguments were invalid.
9150 end_addr
= start_addr
+ count
;
9151 for (cur_addr
= start_addr
; cur_addr
< end_addr
; cur_addr
++) {
9152 ahd_outw(ahd
, SEEDAT
, *buf
++);
9153 ahd_outb(ahd
, SEEADR
, cur_addr
);
9154 ahd_outb(ahd
, SEECTL
, SEEOP_WRITE
| SEESTART
);
9156 retval
= ahd_wait_seeprom(ahd
);
9164 ahd_outb(ahd
, SEEADR
, SEEOP_EWDS_ADDR
);
9165 ahd_outb(ahd
, SEECTL
, SEEOP_EWDS
| SEESTART
);
9166 error
= ahd_wait_seeprom(ahd
);
9173 * Wait ~100us for the serial eeprom to satisfy our request.
9176 ahd_wait_seeprom(struct ahd_softc
*ahd
)
9181 while ((ahd_inb(ahd
, SEESTAT
) & (SEEARBACK
|SEEBUSY
)) != 0 && --cnt
)
9190 * Validate the two checksums in the per_channel
9191 * vital product data struct.
9194 ahd_verify_vpd_cksum(struct vpd_config
*vpd
)
9201 vpdarray
= (uint8_t *)vpd
;
9202 maxaddr
= offsetof(struct vpd_config
, vpd_checksum
);
9204 for (i
= offsetof(struct vpd_config
, resource_type
); i
< maxaddr
; i
++)
9205 checksum
= checksum
+ vpdarray
[i
];
9207 || (-checksum
& 0xFF) != vpd
->vpd_checksum
)
9211 maxaddr
= offsetof(struct vpd_config
, checksum
);
9212 for (i
= offsetof(struct vpd_config
, default_target_flags
);
9214 checksum
= checksum
+ vpdarray
[i
];
9216 || (-checksum
& 0xFF) != vpd
->checksum
)
9222 ahd_verify_cksum(struct seeprom_config
*sc
)
9229 maxaddr
= (sizeof(*sc
)/2) - 1;
9231 scarray
= (uint16_t *)sc
;
9233 for (i
= 0; i
< maxaddr
; i
++)
9234 checksum
= checksum
+ scarray
[i
];
9236 || (checksum
& 0xFFFF) != sc
->checksum
) {
9244 ahd_acquire_seeprom(struct ahd_softc
*ahd
)
9247 * We should be able to determine the SEEPROM type
9248 * from the flexport logic, but unfortunately not
9249 * all implementations have this logic and there is
9250 * no programatic method for determining if the logic
9258 error
= ahd_read_flexport(ahd
, FLXADDR_ROMSTAT_CURSENSECTL
, &seetype
);
9260 || ((seetype
& FLX_ROMSTAT_SEECFG
) == FLX_ROMSTAT_SEE_NONE
))
9267 ahd_release_seeprom(struct ahd_softc
*ahd
)
9269 /* Currently a no-op */
9273 ahd_write_flexport(struct ahd_softc
*ahd
, u_int addr
, u_int value
)
9277 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
9279 panic("ahd_write_flexport: address out of range");
9280 ahd_outb(ahd
, BRDCTL
, BRDEN
|(addr
<< 3));
9281 error
= ahd_wait_flexport(ahd
);
9284 ahd_outb(ahd
, BRDDAT
, value
);
9285 ahd_flush_device_writes(ahd
);
9286 ahd_outb(ahd
, BRDCTL
, BRDSTB
|BRDEN
|(addr
<< 3));
9287 ahd_flush_device_writes(ahd
);
9288 ahd_outb(ahd
, BRDCTL
, BRDEN
|(addr
<< 3));
9289 ahd_flush_device_writes(ahd
);
9290 ahd_outb(ahd
, BRDCTL
, 0);
9291 ahd_flush_device_writes(ahd
);
9296 ahd_read_flexport(struct ahd_softc
*ahd
, u_int addr
, uint8_t *value
)
9300 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
9302 panic("ahd_read_flexport: address out of range");
9303 ahd_outb(ahd
, BRDCTL
, BRDRW
|BRDEN
|(addr
<< 3));
9304 error
= ahd_wait_flexport(ahd
);
9307 *value
= ahd_inb(ahd
, BRDDAT
);
9308 ahd_outb(ahd
, BRDCTL
, 0);
9309 ahd_flush_device_writes(ahd
);
9314 * Wait at most 2 seconds for flexport arbitration to succeed.
9317 ahd_wait_flexport(struct ahd_softc
*ahd
)
9321 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
9322 cnt
= 1000000 * 2 / 5;
9323 while ((ahd_inb(ahd
, BRDCTL
) & FLXARBACK
) == 0 && --cnt
)
9331 /************************* Target Mode ****************************************/
9332 #ifdef AHD_TARGET_MODE
9334 ahd_find_tmode_devs(struct ahd_softc
*ahd
, struct cam_sim
*sim
, union ccb
*ccb
,
9335 struct ahd_tmode_tstate
**tstate
,
9336 struct ahd_tmode_lstate
**lstate
,
9337 int notfound_failure
)
9340 if ((ahd
->features
& AHD_TARGETMODE
) == 0)
9341 return (CAM_REQ_INVALID
);
9344 * Handle the 'black hole' device that sucks up
9345 * requests to unattached luns on enabled targets.
9347 if (ccb
->ccb_h
.target_id
== CAM_TARGET_WILDCARD
9348 && ccb
->ccb_h
.target_lun
== CAM_LUN_WILDCARD
) {
9350 *lstate
= ahd
->black_hole
;
9354 max_id
= (ahd
->features
& AHD_WIDE
) ? 15 : 7;
9355 if (ccb
->ccb_h
.target_id
> max_id
)
9356 return (CAM_TID_INVALID
);
9358 if (ccb
->ccb_h
.target_lun
>= AHD_NUM_LUNS
)
9359 return (CAM_LUN_INVALID
);
9361 *tstate
= ahd
->enabled_targets
[ccb
->ccb_h
.target_id
];
9363 if (*tstate
!= NULL
)
9365 (*tstate
)->enabled_luns
[ccb
->ccb_h
.target_lun
];
9368 if (notfound_failure
!= 0 && *lstate
== NULL
)
9369 return (CAM_PATH_INVALID
);
9371 return (CAM_REQ_CMP
);
9375 ahd_handle_en_lun(struct ahd_softc
*ahd
, struct cam_sim
*sim
, union ccb
*ccb
)
9378 struct ahd_tmode_tstate
*tstate
;
9379 struct ahd_tmode_lstate
*lstate
;
9380 struct ccb_en_lun
*cel
;
9388 status
= ahd_find_tmode_devs(ahd
, sim
, ccb
, &tstate
, &lstate
,
9389 /*notfound_failure*/FALSE
);
9391 if (status
!= CAM_REQ_CMP
) {
9392 ccb
->ccb_h
.status
= status
;
9396 if ((ahd
->features
& AHD_MULTIROLE
) != 0) {
9399 our_id
= ahd
->our_id
;
9400 if (ccb
->ccb_h
.target_id
!= our_id
) {
9401 if ((ahd
->features
& AHD_MULTI_TID
) != 0
9402 && (ahd
->flags
& AHD_INITIATORROLE
) != 0) {
9404 * Only allow additional targets if
9405 * the initiator role is disabled.
9406 * The hardware cannot handle a re-select-in
9407 * on the initiator id during a re-select-out
9408 * on a different target id.
9410 status
= CAM_TID_INVALID
;
9411 } else if ((ahd
->flags
& AHD_INITIATORROLE
) != 0
9412 || ahd
->enabled_luns
> 0) {
9414 * Only allow our target id to change
9415 * if the initiator role is not configured
9416 * and there are no enabled luns which
9417 * are attached to the currently registered
9420 status
= CAM_TID_INVALID
;
9425 if (status
!= CAM_REQ_CMP
) {
9426 ccb
->ccb_h
.status
= status
;
9431 * We now have an id that is valid.
9432 * If we aren't in target mode, switch modes.
9434 if ((ahd
->flags
& AHD_TARGETROLE
) == 0
9435 && ccb
->ccb_h
.target_id
!= CAM_TARGET_WILDCARD
) {
9438 printf("Configuring Target Mode\n");
9440 if (LIST_FIRST(&ahd
->pending_scbs
) != NULL
) {
9441 ccb
->ccb_h
.status
= CAM_BUSY
;
9442 ahd_unlock(ahd
, &s
);
9445 ahd
->flags
|= AHD_TARGETROLE
;
9446 if ((ahd
->features
& AHD_MULTIROLE
) == 0)
9447 ahd
->flags
&= ~AHD_INITIATORROLE
;
9451 ahd_unlock(ahd
, &s
);
9454 target
= ccb
->ccb_h
.target_id
;
9455 lun
= ccb
->ccb_h
.target_lun
;
9456 channel
= SIM_CHANNEL(ahd
, sim
);
9457 target_mask
= 0x01 << target
;
9461 if (cel
->enable
!= 0) {
9464 /* Are we already enabled?? */
9465 if (lstate
!= NULL
) {
9466 xpt_print_path(ccb
->ccb_h
.path
);
9467 printf("Lun already enabled\n");
9468 ccb
->ccb_h
.status
= CAM_LUN_ALRDY_ENA
;
9472 if (cel
->grp6_len
!= 0
9473 || cel
->grp7_len
!= 0) {
9475 * Don't (yet?) support vendor
9476 * specific commands.
9478 ccb
->ccb_h
.status
= CAM_REQ_INVALID
;
9479 printf("Non-zero Group Codes\n");
9485 * Setup our data structures.
9487 if (target
!= CAM_TARGET_WILDCARD
&& tstate
== NULL
) {
9488 tstate
= ahd_alloc_tstate(ahd
, target
, channel
);
9489 if (tstate
== NULL
) {
9490 xpt_print_path(ccb
->ccb_h
.path
);
9491 printf("Couldn't allocate tstate\n");
9492 ccb
->ccb_h
.status
= CAM_RESRC_UNAVAIL
;
9496 lstate
= malloc(sizeof(*lstate
), M_DEVBUF
, M_NOWAIT
);
9497 if (lstate
== NULL
) {
9498 xpt_print_path(ccb
->ccb_h
.path
);
9499 printf("Couldn't allocate lstate\n");
9500 ccb
->ccb_h
.status
= CAM_RESRC_UNAVAIL
;
9503 memset(lstate
, 0, sizeof(*lstate
));
9504 status
= xpt_create_path(&lstate
->path
, /*periph*/NULL
,
9505 xpt_path_path_id(ccb
->ccb_h
.path
),
9506 xpt_path_target_id(ccb
->ccb_h
.path
),
9507 xpt_path_lun_id(ccb
->ccb_h
.path
));
9508 if (status
!= CAM_REQ_CMP
) {
9509 free(lstate
, M_DEVBUF
);
9510 xpt_print_path(ccb
->ccb_h
.path
);
9511 printf("Couldn't allocate path\n");
9512 ccb
->ccb_h
.status
= CAM_RESRC_UNAVAIL
;
9515 SLIST_INIT(&lstate
->accept_tios
);
9516 SLIST_INIT(&lstate
->immed_notifies
);
9519 if (target
!= CAM_TARGET_WILDCARD
) {
9520 tstate
->enabled_luns
[lun
] = lstate
;
9521 ahd
->enabled_luns
++;
9523 if ((ahd
->features
& AHD_MULTI_TID
) != 0) {
9526 targid_mask
= ahd_inb(ahd
, TARGID
)
9527 | (ahd_inb(ahd
, TARGID
+ 1) << 8);
9529 targid_mask
|= target_mask
;
9530 ahd_outb(ahd
, TARGID
, targid_mask
);
9531 ahd_outb(ahd
, TARGID
+1, (targid_mask
>> 8));
9533 ahd_update_scsiid(ahd
, targid_mask
);
9538 channel
= SIM_CHANNEL(ahd
, sim
);
9539 our_id
= SIM_SCSI_ID(ahd
, sim
);
9542 * This can only happen if selections
9545 if (target
!= our_id
) {
9550 sblkctl
= ahd_inb(ahd
, SBLKCTL
);
9551 cur_channel
= (sblkctl
& SELBUSB
)
9553 if ((ahd
->features
& AHD_TWIN
) == 0)
9555 swap
= cur_channel
!= channel
;
9556 ahd
->our_id
= target
;
9559 ahd_outb(ahd
, SBLKCTL
,
9562 ahd_outb(ahd
, SCSIID
, target
);
9565 ahd_outb(ahd
, SBLKCTL
, sblkctl
);
9569 ahd
->black_hole
= lstate
;
9570 /* Allow select-in operations */
9571 if (ahd
->black_hole
!= NULL
&& ahd
->enabled_luns
> 0) {
9572 scsiseq1
= ahd_inb(ahd
, SCSISEQ_TEMPLATE
);
9574 ahd_outb(ahd
, SCSISEQ_TEMPLATE
, scsiseq1
);
9575 scsiseq1
= ahd_inb(ahd
, SCSISEQ1
);
9577 ahd_outb(ahd
, SCSISEQ1
, scsiseq1
);
9580 ahd_unlock(ahd
, &s
);
9581 ccb
->ccb_h
.status
= CAM_REQ_CMP
;
9582 xpt_print_path(ccb
->ccb_h
.path
);
9583 printf("Lun now enabled for target mode\n");
9588 if (lstate
== NULL
) {
9589 ccb
->ccb_h
.status
= CAM_LUN_INVALID
;
9595 ccb
->ccb_h
.status
= CAM_REQ_CMP
;
9596 LIST_FOREACH(scb
, &ahd
->pending_scbs
, pending_links
) {
9597 struct ccb_hdr
*ccbh
;
9599 ccbh
= &scb
->io_ctx
->ccb_h
;
9600 if (ccbh
->func_code
== XPT_CONT_TARGET_IO
9601 && !xpt_path_comp(ccbh
->path
, ccb
->ccb_h
.path
)){
9602 printf("CTIO pending\n");
9603 ccb
->ccb_h
.status
= CAM_REQ_INVALID
;
9604 ahd_unlock(ahd
, &s
);
9609 if (SLIST_FIRST(&lstate
->accept_tios
) != NULL
) {
9610 printf("ATIOs pending\n");
9611 ccb
->ccb_h
.status
= CAM_REQ_INVALID
;
9614 if (SLIST_FIRST(&lstate
->immed_notifies
) != NULL
) {
9615 printf("INOTs pending\n");
9616 ccb
->ccb_h
.status
= CAM_REQ_INVALID
;
9619 if (ccb
->ccb_h
.status
!= CAM_REQ_CMP
) {
9620 ahd_unlock(ahd
, &s
);
9624 xpt_print_path(ccb
->ccb_h
.path
);
9625 printf("Target mode disabled\n");
9626 xpt_free_path(lstate
->path
);
9627 free(lstate
, M_DEVBUF
);
9630 /* Can we clean up the target too? */
9631 if (target
!= CAM_TARGET_WILDCARD
) {
9632 tstate
->enabled_luns
[lun
] = NULL
;
9633 ahd
->enabled_luns
--;
9634 for (empty
= 1, i
= 0; i
< 8; i
++)
9635 if (tstate
->enabled_luns
[i
] != NULL
) {
9641 ahd_free_tstate(ahd
, target
, channel
,
9643 if (ahd
->features
& AHD_MULTI_TID
) {
9646 targid_mask
= ahd_inb(ahd
, TARGID
)
9647 | (ahd_inb(ahd
, TARGID
+ 1)
9650 targid_mask
&= ~target_mask
;
9651 ahd_outb(ahd
, TARGID
, targid_mask
);
9652 ahd_outb(ahd
, TARGID
+1,
9653 (targid_mask
>> 8));
9654 ahd_update_scsiid(ahd
, targid_mask
);
9659 ahd
->black_hole
= NULL
;
9662 * We can't allow selections without
9663 * our black hole device.
9667 if (ahd
->enabled_luns
== 0) {
9668 /* Disallow select-in */
9671 scsiseq1
= ahd_inb(ahd
, SCSISEQ_TEMPLATE
);
9672 scsiseq1
&= ~ENSELI
;
9673 ahd_outb(ahd
, SCSISEQ_TEMPLATE
, scsiseq1
);
9674 scsiseq1
= ahd_inb(ahd
, SCSISEQ1
);
9675 scsiseq1
&= ~ENSELI
;
9676 ahd_outb(ahd
, SCSISEQ1
, scsiseq1
);
9678 if ((ahd
->features
& AHD_MULTIROLE
) == 0) {
9679 printf("Configuring Initiator Mode\n");
9680 ahd
->flags
&= ~AHD_TARGETROLE
;
9681 ahd
->flags
|= AHD_INITIATORROLE
;
9686 * Unpaused. The extra unpause
9687 * that follows is harmless.
9692 ahd_unlock(ahd
, &s
);
9698 ahd_update_scsiid(struct ahd_softc
*ahd
, u_int targid_mask
)
9704 if ((ahd
->features
& AHD_MULTI_TID
) == 0)
9705 panic("ahd_update_scsiid called on non-multitid unit\n");
9708 * Since we will rely on the TARGID mask
9709 * for selection enables, ensure that OID
9710 * in SCSIID is not set to some other ID
9711 * that we don't want to allow selections on.
9713 if ((ahd
->features
& AHD_ULTRA2
) != 0)
9714 scsiid
= ahd_inb(ahd
, SCSIID_ULTRA2
);
9716 scsiid
= ahd_inb(ahd
, SCSIID
);
9717 scsiid_mask
= 0x1 << (scsiid
& OID
);
9718 if ((targid_mask
& scsiid_mask
) == 0) {
9721 /* ffs counts from 1 */
9722 our_id
= ffs(targid_mask
);
9724 our_id
= ahd
->our_id
;
9730 if ((ahd
->features
& AHD_ULTRA2
) != 0)
9731 ahd_outb(ahd
, SCSIID_ULTRA2
, scsiid
);
9733 ahd_outb(ahd
, SCSIID
, scsiid
);
9738 ahd_run_tqinfifo(struct ahd_softc
*ahd
, int paused
)
9740 struct target_cmd
*cmd
;
9742 ahd_sync_tqinfifo(ahd
, BUS_DMASYNC_POSTREAD
);
9743 while ((cmd
= &ahd
->targetcmds
[ahd
->tqinfifonext
])->cmd_valid
!= 0) {
9746 * Only advance through the queue if we
9747 * have the resources to process the command.
9749 if (ahd_handle_target_cmd(ahd
, cmd
) != 0)
9753 ahd_dmamap_sync(ahd
, ahd
->shared_data_dmat
,
9754 ahd
->shared_data_dmamap
,
9755 ahd_targetcmd_offset(ahd
, ahd
->tqinfifonext
),
9756 sizeof(struct target_cmd
),
9757 BUS_DMASYNC_PREREAD
);
9758 ahd
->tqinfifonext
++;
9761 * Lazily update our position in the target mode incoming
9762 * command queue as seen by the sequencer.
9764 if ((ahd
->tqinfifonext
& (HOST_TQINPOS
- 1)) == 1) {
9767 hs_mailbox
= ahd_inb(ahd
, HS_MAILBOX
);
9768 hs_mailbox
&= ~HOST_TQINPOS
;
9769 hs_mailbox
|= ahd
->tqinfifonext
& HOST_TQINPOS
;
9770 ahd_outb(ahd
, HS_MAILBOX
, hs_mailbox
);
9776 ahd_handle_target_cmd(struct ahd_softc
*ahd
, struct target_cmd
*cmd
)
9778 struct ahd_tmode_tstate
*tstate
;
9779 struct ahd_tmode_lstate
*lstate
;
9780 struct ccb_accept_tio
*atio
;
9786 initiator
= SCSIID_TARGET(ahd
, cmd
->scsiid
);
9787 target
= SCSIID_OUR_ID(cmd
->scsiid
);
9788 lun
= (cmd
->identify
& MSG_IDENTIFY_LUNMASK
);
9791 tstate
= ahd
->enabled_targets
[target
];
9794 lstate
= tstate
->enabled_luns
[lun
];
9797 * Commands for disabled luns go to the black hole driver.
9800 lstate
= ahd
->black_hole
;
9802 atio
= (struct ccb_accept_tio
*)SLIST_FIRST(&lstate
->accept_tios
);
9804 ahd
->flags
|= AHD_TQINFIFO_BLOCKED
;
9806 * Wait for more ATIOs from the peripheral driver for this lun.
9810 ahd
->flags
&= ~AHD_TQINFIFO_BLOCKED
;
9812 if ((ahd_debug
& AHD_SHOW_TQIN
) != 0)
9813 printf("Incoming command from %d for %d:%d%s\n",
9814 initiator
, target
, lun
,
9815 lstate
== ahd
->black_hole
? "(Black Holed)" : "");
9817 SLIST_REMOVE_HEAD(&lstate
->accept_tios
, sim_links
.sle
);
9819 if (lstate
== ahd
->black_hole
) {
9820 /* Fill in the wildcards */
9821 atio
->ccb_h
.target_id
= target
;
9822 atio
->ccb_h
.target_lun
= lun
;
9826 * Package it up and send it off to
9827 * whomever has this lun enabled.
9829 atio
->sense_len
= 0;
9830 atio
->init_id
= initiator
;
9831 if (byte
[0] != 0xFF) {
9832 /* Tag was included */
9833 atio
->tag_action
= *byte
++;
9834 atio
->tag_id
= *byte
++;
9835 atio
->ccb_h
.flags
= CAM_TAG_ACTION_VALID
;
9837 atio
->ccb_h
.flags
= 0;
9841 /* Okay. Now determine the cdb size based on the command code */
9842 switch (*byte
>> CMD_GROUP_CODE_SHIFT
) {
9858 /* Only copy the opcode. */
9860 printf("Reserved or VU command code type encountered\n");
9864 memcpy(atio
->cdb_io
.cdb_bytes
, byte
, atio
->cdb_len
);
9866 atio
->ccb_h
.status
|= CAM_CDB_RECVD
;
9868 if ((cmd
->identify
& MSG_IDENTIFY_DISCFLAG
) == 0) {
9870 * We weren't allowed to disconnect.
9871 * We're hanging on the bus until a
9872 * continue target I/O comes in response
9873 * to this accept tio.
9876 if ((ahd_debug
& AHD_SHOW_TQIN
) != 0)
9877 printf("Received Immediate Command %d:%d:%d - %p\n",
9878 initiator
, target
, lun
, ahd
->pending_device
);
9880 ahd
->pending_device
= lstate
;
9881 ahd_freeze_ccb((union ccb
*)atio
);
9882 atio
->ccb_h
.flags
|= CAM_DIS_DISCONNECT
;
9884 xpt_done((union ccb
*)atio
);