2 * Core routines and tables shareable across OS platforms.
4 * Copyright (c) 1994-2002 Justin T. Gibbs.
5 * Copyright (c) 2000-2003 Adaptec Inc.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions, and the following disclaimer,
13 * without modification.
14 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
15 * substantially similar to the "NO WARRANTY" disclaimer below
16 * ("Disclaimer") and any redistribution must be conditioned upon
17 * including a substantially similar Disclaimer requirement for further
18 * binary redistribution.
19 * 3. Neither the names of the above-listed copyright holders nor the names
20 * of any contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
23 * Alternatively, this software may be distributed under the terms of the
24 * GNU General Public License ("GPL") version 2 as published by the Free
25 * Software Foundation.
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
36 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
37 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGES.
40 * $Id: //depot/aic7xxx/aic7xxx/aic79xx.c#250 $
43 #include "aic79xx_osm.h"
44 #include "aic79xx_inline.h"
45 #include "aicasm/aicasm_insformat.h"
47 /***************************** Lookup Tables **********************************/
48 static const char *const ahd_chip_names
[] =
57 * Hardware error codes.
59 struct ahd_hard_error_entry
{
64 static const struct ahd_hard_error_entry ahd_hard_errors
[] = {
65 { DSCTMOUT
, "Discard Timer has timed out" },
66 { ILLOPCODE
, "Illegal Opcode in sequencer program" },
67 { SQPARERR
, "Sequencer Parity Error" },
68 { DPARERR
, "Data-path Parity Error" },
69 { MPARERR
, "Scratch or SCB Memory Parity Error" },
70 { CIOPARERR
, "CIOBUS Parity Error" },
72 static const u_int num_errors
= ARRAY_SIZE(ahd_hard_errors
);
74 static const struct ahd_phase_table_entry ahd_phase_table
[] =
76 { P_DATAOUT
, MSG_NOOP
, "in Data-out phase" },
77 { P_DATAIN
, MSG_INITIATOR_DET_ERR
, "in Data-in phase" },
78 { P_DATAOUT_DT
, MSG_NOOP
, "in DT Data-out phase" },
79 { P_DATAIN_DT
, MSG_INITIATOR_DET_ERR
, "in DT Data-in phase" },
80 { P_COMMAND
, MSG_NOOP
, "in Command phase" },
81 { P_MESGOUT
, MSG_NOOP
, "in Message-out phase" },
82 { P_STATUS
, MSG_INITIATOR_DET_ERR
, "in Status phase" },
83 { P_MESGIN
, MSG_PARITY_ERROR
, "in Message-in phase" },
84 { P_BUSFREE
, MSG_NOOP
, "while idle" },
85 { 0, MSG_NOOP
, "in unknown phase" }
89 * In most cases we only wish to itterate over real phases, so
90 * exclude the last element from the count.
92 static const u_int num_phases
= ARRAY_SIZE(ahd_phase_table
) - 1;
94 /* Our Sequencer Program */
95 #include "aic79xx_seq.h"
97 /**************************** Function Declarations ***************************/
98 static void ahd_handle_transmission_error(struct ahd_softc
*ahd
);
99 static void ahd_handle_lqiphase_error(struct ahd_softc
*ahd
,
101 static int ahd_handle_pkt_busfree(struct ahd_softc
*ahd
,
103 static int ahd_handle_nonpkt_busfree(struct ahd_softc
*ahd
);
104 static void ahd_handle_proto_violation(struct ahd_softc
*ahd
);
105 static void ahd_force_renegotiation(struct ahd_softc
*ahd
,
106 struct ahd_devinfo
*devinfo
);
108 static struct ahd_tmode_tstate
*
109 ahd_alloc_tstate(struct ahd_softc
*ahd
,
110 u_int scsi_id
, char channel
);
111 #ifdef AHD_TARGET_MODE
112 static void ahd_free_tstate(struct ahd_softc
*ahd
,
113 u_int scsi_id
, char channel
, int force
);
115 static void ahd_devlimited_syncrate(struct ahd_softc
*ahd
,
116 struct ahd_initiator_tinfo
*,
120 static void ahd_update_neg_table(struct ahd_softc
*ahd
,
121 struct ahd_devinfo
*devinfo
,
122 struct ahd_transinfo
*tinfo
);
123 static void ahd_update_pending_scbs(struct ahd_softc
*ahd
);
124 static void ahd_fetch_devinfo(struct ahd_softc
*ahd
,
125 struct ahd_devinfo
*devinfo
);
126 static void ahd_scb_devinfo(struct ahd_softc
*ahd
,
127 struct ahd_devinfo
*devinfo
,
129 static void ahd_setup_initiator_msgout(struct ahd_softc
*ahd
,
130 struct ahd_devinfo
*devinfo
,
132 static void ahd_build_transfer_msg(struct ahd_softc
*ahd
,
133 struct ahd_devinfo
*devinfo
);
134 static void ahd_construct_sdtr(struct ahd_softc
*ahd
,
135 struct ahd_devinfo
*devinfo
,
136 u_int period
, u_int offset
);
137 static void ahd_construct_wdtr(struct ahd_softc
*ahd
,
138 struct ahd_devinfo
*devinfo
,
140 static void ahd_construct_ppr(struct ahd_softc
*ahd
,
141 struct ahd_devinfo
*devinfo
,
142 u_int period
, u_int offset
,
143 u_int bus_width
, u_int ppr_options
);
144 static void ahd_clear_msg_state(struct ahd_softc
*ahd
);
145 static void ahd_handle_message_phase(struct ahd_softc
*ahd
);
151 static int ahd_sent_msg(struct ahd_softc
*ahd
, ahd_msgtype type
,
152 u_int msgval
, int full
);
153 static int ahd_parse_msg(struct ahd_softc
*ahd
,
154 struct ahd_devinfo
*devinfo
);
155 static int ahd_handle_msg_reject(struct ahd_softc
*ahd
,
156 struct ahd_devinfo
*devinfo
);
157 static void ahd_handle_ign_wide_residue(struct ahd_softc
*ahd
,
158 struct ahd_devinfo
*devinfo
);
159 static void ahd_reinitialize_dataptrs(struct ahd_softc
*ahd
);
160 static void ahd_handle_devreset(struct ahd_softc
*ahd
,
161 struct ahd_devinfo
*devinfo
,
162 u_int lun
, cam_status status
,
163 char *message
, int verbose_level
);
164 #ifdef AHD_TARGET_MODE
165 static void ahd_setup_target_msgin(struct ahd_softc
*ahd
,
166 struct ahd_devinfo
*devinfo
,
170 static u_int
ahd_sglist_size(struct ahd_softc
*ahd
);
171 static u_int
ahd_sglist_allocsize(struct ahd_softc
*ahd
);
172 static bus_dmamap_callback_t
174 static void ahd_initialize_hscbs(struct ahd_softc
*ahd
);
175 static int ahd_init_scbdata(struct ahd_softc
*ahd
);
176 static void ahd_fini_scbdata(struct ahd_softc
*ahd
);
177 static void ahd_setup_iocell_workaround(struct ahd_softc
*ahd
);
178 static void ahd_iocell_first_selection(struct ahd_softc
*ahd
);
179 static void ahd_add_col_list(struct ahd_softc
*ahd
,
180 struct scb
*scb
, u_int col_idx
);
181 static void ahd_rem_col_list(struct ahd_softc
*ahd
,
183 static void ahd_chip_init(struct ahd_softc
*ahd
);
184 static void ahd_qinfifo_requeue(struct ahd_softc
*ahd
,
185 struct scb
*prev_scb
,
187 static int ahd_qinfifo_count(struct ahd_softc
*ahd
);
188 static int ahd_search_scb_list(struct ahd_softc
*ahd
, int target
,
189 char channel
, int lun
, u_int tag
,
190 role_t role
, uint32_t status
,
191 ahd_search_action action
,
192 u_int
*list_head
, u_int
*list_tail
,
194 static void ahd_stitch_tid_list(struct ahd_softc
*ahd
,
195 u_int tid_prev
, u_int tid_cur
,
197 static void ahd_add_scb_to_free_list(struct ahd_softc
*ahd
,
199 static u_int
ahd_rem_wscb(struct ahd_softc
*ahd
, u_int scbid
,
200 u_int prev
, u_int next
, u_int tid
);
201 static void ahd_reset_current_bus(struct ahd_softc
*ahd
);
202 static void ahd_stat_timer(struct timer_list
*t
);
204 static void ahd_dumpseq(struct ahd_softc
*ahd
);
206 static void ahd_loadseq(struct ahd_softc
*ahd
);
207 static int ahd_check_patch(struct ahd_softc
*ahd
,
208 const struct patch
**start_patch
,
209 u_int start_instr
, u_int
*skip_addr
);
210 static u_int
ahd_resolve_seqaddr(struct ahd_softc
*ahd
,
212 static void ahd_download_instr(struct ahd_softc
*ahd
,
213 u_int instrptr
, uint8_t *dconsts
);
214 static int ahd_probe_stack_size(struct ahd_softc
*ahd
);
215 static int ahd_scb_active_in_fifo(struct ahd_softc
*ahd
,
217 static void ahd_run_data_fifo(struct ahd_softc
*ahd
,
220 #ifdef AHD_TARGET_MODE
221 static void ahd_queue_lstate_event(struct ahd_softc
*ahd
,
222 struct ahd_tmode_lstate
*lstate
,
226 static void ahd_update_scsiid(struct ahd_softc
*ahd
,
228 static int ahd_handle_target_cmd(struct ahd_softc
*ahd
,
229 struct target_cmd
*cmd
);
232 static int ahd_abort_scbs(struct ahd_softc
*ahd
, int target
,
233 char channel
, int lun
, u_int tag
,
234 role_t role
, uint32_t status
);
235 static void ahd_alloc_scbs(struct ahd_softc
*ahd
);
236 static void ahd_busy_tcl(struct ahd_softc
*ahd
, u_int tcl
,
238 static void ahd_calc_residual(struct ahd_softc
*ahd
,
240 static void ahd_clear_critical_section(struct ahd_softc
*ahd
);
241 static void ahd_clear_intstat(struct ahd_softc
*ahd
);
242 static void ahd_enable_coalescing(struct ahd_softc
*ahd
,
244 static u_int
ahd_find_busy_tcl(struct ahd_softc
*ahd
, u_int tcl
);
245 static void ahd_freeze_devq(struct ahd_softc
*ahd
,
247 static void ahd_handle_scb_status(struct ahd_softc
*ahd
,
249 static const struct ahd_phase_table_entry
* ahd_lookup_phase_entry(int phase
);
250 static void ahd_shutdown(void *arg
);
251 static void ahd_update_coalescing_values(struct ahd_softc
*ahd
,
255 static int ahd_verify_vpd_cksum(struct vpd_config
*vpd
);
256 static int ahd_wait_seeprom(struct ahd_softc
*ahd
);
257 static int ahd_match_scb(struct ahd_softc
*ahd
, struct scb
*scb
,
258 int target
, char channel
, int lun
,
259 u_int tag
, role_t role
);
261 static void ahd_reset_cmds_pending(struct ahd_softc
*ahd
);
263 /*************************** Interrupt Services *******************************/
264 static void ahd_run_qoutfifo(struct ahd_softc
*ahd
);
265 #ifdef AHD_TARGET_MODE
266 static void ahd_run_tqinfifo(struct ahd_softc
*ahd
, int paused
);
268 static void ahd_handle_hwerrint(struct ahd_softc
*ahd
);
269 static void ahd_handle_seqint(struct ahd_softc
*ahd
, u_int intstat
);
270 static void ahd_handle_scsiint(struct ahd_softc
*ahd
,
273 /************************ Sequencer Execution Control *************************/
275 ahd_set_modes(struct ahd_softc
*ahd
, ahd_mode src
, ahd_mode dst
)
277 if (ahd
->src_mode
== src
&& ahd
->dst_mode
== dst
)
280 if (ahd
->src_mode
== AHD_MODE_UNKNOWN
281 || ahd
->dst_mode
== AHD_MODE_UNKNOWN
)
282 panic("Setting mode prior to saving it.\n");
283 if ((ahd_debug
& AHD_SHOW_MODEPTR
) != 0)
284 printk("%s: Setting mode 0x%x\n", ahd_name(ahd
),
285 ahd_build_mode_state(ahd
, src
, dst
));
287 ahd_outb(ahd
, MODE_PTR
, ahd_build_mode_state(ahd
, src
, dst
));
293 ahd_update_modes(struct ahd_softc
*ahd
)
295 ahd_mode_state mode_ptr
;
299 mode_ptr
= ahd_inb(ahd
, MODE_PTR
);
301 if ((ahd_debug
& AHD_SHOW_MODEPTR
) != 0)
302 printk("Reading mode 0x%x\n", mode_ptr
);
304 ahd_extract_mode_state(ahd
, mode_ptr
, &src
, &dst
);
305 ahd_known_modes(ahd
, src
, dst
);
309 ahd_assert_modes(struct ahd_softc
*ahd
, ahd_mode srcmode
,
310 ahd_mode dstmode
, const char *file
, int line
)
313 if ((srcmode
& AHD_MK_MSK(ahd
->src_mode
)) == 0
314 || (dstmode
& AHD_MK_MSK(ahd
->dst_mode
)) == 0) {
315 panic("%s:%s:%d: Mode assertion failed.\n",
316 ahd_name(ahd
), file
, line
);
321 #define AHD_ASSERT_MODES(ahd, source, dest) \
322 ahd_assert_modes(ahd, source, dest, __FILE__, __LINE__);
325 ahd_save_modes(struct ahd_softc
*ahd
)
327 if (ahd
->src_mode
== AHD_MODE_UNKNOWN
328 || ahd
->dst_mode
== AHD_MODE_UNKNOWN
)
329 ahd_update_modes(ahd
);
331 return (ahd_build_mode_state(ahd
, ahd
->src_mode
, ahd
->dst_mode
));
335 ahd_restore_modes(struct ahd_softc
*ahd
, ahd_mode_state state
)
340 ahd_extract_mode_state(ahd
, state
, &src
, &dst
);
341 ahd_set_modes(ahd
, src
, dst
);
345 * Determine whether the sequencer has halted code execution.
346 * Returns non-zero status if the sequencer is stopped.
349 ahd_is_paused(struct ahd_softc
*ahd
)
351 return ((ahd_inb(ahd
, HCNTRL
) & PAUSE
) != 0);
355 * Request that the sequencer stop and wait, indefinitely, for it
356 * to stop. The sequencer will only acknowledge that it is paused
357 * once it has reached an instruction boundary and PAUSEDIS is
358 * cleared in the SEQCTL register. The sequencer may use PAUSEDIS
359 * for critical sections.
362 ahd_pause(struct ahd_softc
*ahd
)
364 ahd_outb(ahd
, HCNTRL
, ahd
->pause
);
367 * Since the sequencer can disable pausing in a critical section, we
368 * must loop until it actually stops.
370 while (ahd_is_paused(ahd
) == 0)
375 * Allow the sequencer to continue program execution.
376 * We check here to ensure that no additional interrupt
377 * sources that would cause the sequencer to halt have been
378 * asserted. If, for example, a SCSI bus reset is detected
379 * while we are fielding a different, pausing, interrupt type,
380 * we don't want to release the sequencer before going back
381 * into our interrupt handler and dealing with this new
385 ahd_unpause(struct ahd_softc
*ahd
)
388 * Automatically restore our modes to those saved
389 * prior to the first change of the mode.
391 if (ahd
->saved_src_mode
!= AHD_MODE_UNKNOWN
392 && ahd
->saved_dst_mode
!= AHD_MODE_UNKNOWN
) {
393 if ((ahd
->flags
& AHD_UPDATE_PEND_CMDS
) != 0)
394 ahd_reset_cmds_pending(ahd
);
395 ahd_set_modes(ahd
, ahd
->saved_src_mode
, ahd
->saved_dst_mode
);
398 if ((ahd_inb(ahd
, INTSTAT
) & ~CMDCMPLT
) == 0)
399 ahd_outb(ahd
, HCNTRL
, ahd
->unpause
);
401 ahd_known_modes(ahd
, AHD_MODE_UNKNOWN
, AHD_MODE_UNKNOWN
);
404 /*********************** Scatter Gather List Handling *************************/
406 ahd_sg_setup(struct ahd_softc
*ahd
, struct scb
*scb
,
407 void *sgptr
, dma_addr_t addr
, bus_size_t len
, int last
)
410 if (sizeof(dma_addr_t
) > 4
411 && (ahd
->flags
& AHD_64BIT_ADDRESSING
) != 0) {
412 struct ahd_dma64_seg
*sg
;
414 sg
= (struct ahd_dma64_seg
*)sgptr
;
415 sg
->addr
= ahd_htole64(addr
);
416 sg
->len
= ahd_htole32(len
| (last
? AHD_DMA_LAST_SEG
: 0));
419 struct ahd_dma_seg
*sg
;
421 sg
= (struct ahd_dma_seg
*)sgptr
;
422 sg
->addr
= ahd_htole32(addr
& 0xFFFFFFFF);
423 sg
->len
= ahd_htole32(len
| ((addr
>> 8) & 0x7F000000)
424 | (last
? AHD_DMA_LAST_SEG
: 0));
430 ahd_setup_scb_common(struct ahd_softc
*ahd
, struct scb
*scb
)
432 /* XXX Handle target mode SCBs. */
433 scb
->crc_retry_count
= 0;
434 if ((scb
->flags
& SCB_PACKETIZED
) != 0) {
435 /* XXX what about ACA?? It is type 4, but TAG_TYPE == 0x3. */
436 scb
->hscb
->task_attribute
= scb
->hscb
->control
& SCB_TAG_TYPE
;
438 if (ahd_get_transfer_length(scb
) & 0x01)
439 scb
->hscb
->task_attribute
= SCB_XFERLEN_ODD
;
441 scb
->hscb
->task_attribute
= 0;
444 if (scb
->hscb
->cdb_len
<= MAX_CDB_LEN_WITH_SENSE_ADDR
445 || (scb
->hscb
->cdb_len
& SCB_CDB_LEN_PTR
) != 0)
446 scb
->hscb
->shared_data
.idata
.cdb_plus_saddr
.sense_addr
=
447 ahd_htole32(scb
->sense_busaddr
);
451 ahd_setup_data_scb(struct ahd_softc
*ahd
, struct scb
*scb
)
454 * Copy the first SG into the "current" data ponter area.
456 if ((ahd
->flags
& AHD_64BIT_ADDRESSING
) != 0) {
457 struct ahd_dma64_seg
*sg
;
459 sg
= (struct ahd_dma64_seg
*)scb
->sg_list
;
460 scb
->hscb
->dataptr
= sg
->addr
;
461 scb
->hscb
->datacnt
= sg
->len
;
463 struct ahd_dma_seg
*sg
;
464 uint32_t *dataptr_words
;
466 sg
= (struct ahd_dma_seg
*)scb
->sg_list
;
467 dataptr_words
= (uint32_t*)&scb
->hscb
->dataptr
;
468 dataptr_words
[0] = sg
->addr
;
469 dataptr_words
[1] = 0;
470 if ((ahd
->flags
& AHD_39BIT_ADDRESSING
) != 0) {
473 high_addr
= ahd_le32toh(sg
->len
) & 0x7F000000;
474 scb
->hscb
->dataptr
|= ahd_htole64(high_addr
<< 8);
476 scb
->hscb
->datacnt
= sg
->len
;
479 * Note where to find the SG entries in bus space.
480 * We also set the full residual flag which the
481 * sequencer will clear as soon as a data transfer
484 scb
->hscb
->sgptr
= ahd_htole32(scb
->sg_list_busaddr
|SG_FULL_RESID
);
488 ahd_setup_noxfer_scb(struct ahd_softc
*ahd
, struct scb
*scb
)
490 scb
->hscb
->sgptr
= ahd_htole32(SG_LIST_NULL
);
491 scb
->hscb
->dataptr
= 0;
492 scb
->hscb
->datacnt
= 0;
495 /************************** Memory mapping routines ***************************/
497 ahd_sg_bus_to_virt(struct ahd_softc
*ahd
, struct scb
*scb
, uint32_t sg_busaddr
)
499 dma_addr_t sg_offset
;
501 /* sg_list_phys points to entry 1, not 0 */
502 sg_offset
= sg_busaddr
- (scb
->sg_list_busaddr
- ahd_sg_size(ahd
));
503 return ((uint8_t *)scb
->sg_list
+ sg_offset
);
507 ahd_sg_virt_to_bus(struct ahd_softc
*ahd
, struct scb
*scb
, void *sg
)
509 dma_addr_t sg_offset
;
511 /* sg_list_phys points to entry 1, not 0 */
512 sg_offset
= ((uint8_t *)sg
- (uint8_t *)scb
->sg_list
)
515 return (scb
->sg_list_busaddr
+ sg_offset
);
519 ahd_sync_scb(struct ahd_softc
*ahd
, struct scb
*scb
, int op
)
521 ahd_dmamap_sync(ahd
, ahd
->scb_data
.hscb_dmat
,
522 scb
->hscb_map
->dmamap
,
523 /*offset*/(uint8_t*)scb
->hscb
- scb
->hscb_map
->vaddr
,
524 /*len*/sizeof(*scb
->hscb
), op
);
528 ahd_sync_sglist(struct ahd_softc
*ahd
, struct scb
*scb
, int op
)
530 if (scb
->sg_count
== 0)
533 ahd_dmamap_sync(ahd
, ahd
->scb_data
.sg_dmat
,
535 /*offset*/scb
->sg_list_busaddr
- ahd_sg_size(ahd
),
536 /*len*/ahd_sg_size(ahd
) * scb
->sg_count
, op
);
540 ahd_sync_sense(struct ahd_softc
*ahd
, struct scb
*scb
, int op
)
542 ahd_dmamap_sync(ahd
, ahd
->scb_data
.sense_dmat
,
543 scb
->sense_map
->dmamap
,
544 /*offset*/scb
->sense_busaddr
,
545 /*len*/AHD_SENSE_BUFSIZE
, op
);
548 #ifdef AHD_TARGET_MODE
550 ahd_targetcmd_offset(struct ahd_softc
*ahd
, u_int index
)
552 return (((uint8_t *)&ahd
->targetcmds
[index
])
553 - (uint8_t *)ahd
->qoutfifo
);
557 /*********************** Miscellaneous Support Functions ***********************/
559 * Return pointers to the transfer negotiation information
560 * for the specified our_id/remote_id pair.
562 struct ahd_initiator_tinfo
*
563 ahd_fetch_transinfo(struct ahd_softc
*ahd
, char channel
, u_int our_id
,
564 u_int remote_id
, struct ahd_tmode_tstate
**tstate
)
567 * Transfer data structures are stored from the perspective
568 * of the target role. Since the parameters for a connection
569 * in the initiator role to a given target are the same as
570 * when the roles are reversed, we pretend we are the target.
574 *tstate
= ahd
->enabled_targets
[our_id
];
575 return (&(*tstate
)->transinfo
[remote_id
]);
579 ahd_inw(struct ahd_softc
*ahd
, u_int port
)
582 * Read high byte first as some registers increment
583 * or have other side effects when the low byte is
586 uint16_t r
= ahd_inb(ahd
, port
+1) << 8;
587 return r
| ahd_inb(ahd
, port
);
591 ahd_outw(struct ahd_softc
*ahd
, u_int port
, u_int value
)
594 * Write low byte first to accommodate registers
595 * such as PRGMCNT where the order maters.
597 ahd_outb(ahd
, port
, value
& 0xFF);
598 ahd_outb(ahd
, port
+1, (value
>> 8) & 0xFF);
602 ahd_inl(struct ahd_softc
*ahd
, u_int port
)
604 return ((ahd_inb(ahd
, port
))
605 | (ahd_inb(ahd
, port
+1) << 8)
606 | (ahd_inb(ahd
, port
+2) << 16)
607 | (ahd_inb(ahd
, port
+3) << 24));
611 ahd_outl(struct ahd_softc
*ahd
, u_int port
, uint32_t value
)
613 ahd_outb(ahd
, port
, (value
) & 0xFF);
614 ahd_outb(ahd
, port
+1, ((value
) >> 8) & 0xFF);
615 ahd_outb(ahd
, port
+2, ((value
) >> 16) & 0xFF);
616 ahd_outb(ahd
, port
+3, ((value
) >> 24) & 0xFF);
620 ahd_inq(struct ahd_softc
*ahd
, u_int port
)
622 return ((ahd_inb(ahd
, port
))
623 | (ahd_inb(ahd
, port
+1) << 8)
624 | (ahd_inb(ahd
, port
+2) << 16)
625 | (ahd_inb(ahd
, port
+3) << 24)
626 | (((uint64_t)ahd_inb(ahd
, port
+4)) << 32)
627 | (((uint64_t)ahd_inb(ahd
, port
+5)) << 40)
628 | (((uint64_t)ahd_inb(ahd
, port
+6)) << 48)
629 | (((uint64_t)ahd_inb(ahd
, port
+7)) << 56));
633 ahd_outq(struct ahd_softc
*ahd
, u_int port
, uint64_t value
)
635 ahd_outb(ahd
, port
, value
& 0xFF);
636 ahd_outb(ahd
, port
+1, (value
>> 8) & 0xFF);
637 ahd_outb(ahd
, port
+2, (value
>> 16) & 0xFF);
638 ahd_outb(ahd
, port
+3, (value
>> 24) & 0xFF);
639 ahd_outb(ahd
, port
+4, (value
>> 32) & 0xFF);
640 ahd_outb(ahd
, port
+5, (value
>> 40) & 0xFF);
641 ahd_outb(ahd
, port
+6, (value
>> 48) & 0xFF);
642 ahd_outb(ahd
, port
+7, (value
>> 56) & 0xFF);
646 ahd_get_scbptr(struct ahd_softc
*ahd
)
648 AHD_ASSERT_MODES(ahd
, ~(AHD_MODE_UNKNOWN_MSK
|AHD_MODE_CFG_MSK
),
649 ~(AHD_MODE_UNKNOWN_MSK
|AHD_MODE_CFG_MSK
));
650 return (ahd_inb(ahd
, SCBPTR
) | (ahd_inb(ahd
, SCBPTR
+ 1) << 8));
654 ahd_set_scbptr(struct ahd_softc
*ahd
, u_int scbptr
)
656 AHD_ASSERT_MODES(ahd
, ~(AHD_MODE_UNKNOWN_MSK
|AHD_MODE_CFG_MSK
),
657 ~(AHD_MODE_UNKNOWN_MSK
|AHD_MODE_CFG_MSK
));
658 ahd_outb(ahd
, SCBPTR
, scbptr
& 0xFF);
659 ahd_outb(ahd
, SCBPTR
+1, (scbptr
>> 8) & 0xFF);
664 ahd_get_hnscb_qoff(struct ahd_softc
*ahd
)
666 return (ahd_inw_atomic(ahd
, HNSCB_QOFF
));
671 ahd_set_hnscb_qoff(struct ahd_softc
*ahd
, u_int value
)
673 ahd_outw_atomic(ahd
, HNSCB_QOFF
, value
);
678 ahd_get_hescb_qoff(struct ahd_softc
*ahd
)
680 return (ahd_inb(ahd
, HESCB_QOFF
));
685 ahd_set_hescb_qoff(struct ahd_softc
*ahd
, u_int value
)
687 ahd_outb(ahd
, HESCB_QOFF
, value
);
691 ahd_get_snscb_qoff(struct ahd_softc
*ahd
)
695 AHD_ASSERT_MODES(ahd
, AHD_MODE_CCHAN_MSK
, AHD_MODE_CCHAN_MSK
);
696 oldvalue
= ahd_inw(ahd
, SNSCB_QOFF
);
697 ahd_outw(ahd
, SNSCB_QOFF
, oldvalue
);
702 ahd_set_snscb_qoff(struct ahd_softc
*ahd
, u_int value
)
704 AHD_ASSERT_MODES(ahd
, AHD_MODE_CCHAN_MSK
, AHD_MODE_CCHAN_MSK
);
705 ahd_outw(ahd
, SNSCB_QOFF
, value
);
710 ahd_get_sescb_qoff(struct ahd_softc
*ahd
)
712 AHD_ASSERT_MODES(ahd
, AHD_MODE_CCHAN_MSK
, AHD_MODE_CCHAN_MSK
);
713 return (ahd_inb(ahd
, SESCB_QOFF
));
718 ahd_set_sescb_qoff(struct ahd_softc
*ahd
, u_int value
)
720 AHD_ASSERT_MODES(ahd
, AHD_MODE_CCHAN_MSK
, AHD_MODE_CCHAN_MSK
);
721 ahd_outb(ahd
, SESCB_QOFF
, value
);
726 ahd_get_sdscb_qoff(struct ahd_softc
*ahd
)
728 AHD_ASSERT_MODES(ahd
, AHD_MODE_CCHAN_MSK
, AHD_MODE_CCHAN_MSK
);
729 return (ahd_inb(ahd
, SDSCB_QOFF
) | (ahd_inb(ahd
, SDSCB_QOFF
+ 1) << 8));
734 ahd_set_sdscb_qoff(struct ahd_softc
*ahd
, u_int value
)
736 AHD_ASSERT_MODES(ahd
, AHD_MODE_CCHAN_MSK
, AHD_MODE_CCHAN_MSK
);
737 ahd_outb(ahd
, SDSCB_QOFF
, value
& 0xFF);
738 ahd_outb(ahd
, SDSCB_QOFF
+1, (value
>> 8) & 0xFF);
742 ahd_inb_scbram(struct ahd_softc
*ahd
, u_int offset
)
747 * Workaround PCI-X Rev A. hardware bug.
748 * After a host read of SCB memory, the chip
749 * may become confused into thinking prefetch
750 * was required. This starts the discard timer
751 * running and can cause an unexpected discard
752 * timer interrupt. The work around is to read
753 * a normal register prior to the exhaustion of
754 * the discard timer. The mode pointer register
755 * has no side effects and so serves well for
760 value
= ahd_inb(ahd
, offset
);
761 if ((ahd
->bugs
& AHD_PCIX_SCBRAM_RD_BUG
) != 0)
762 ahd_inb(ahd
, MODE_PTR
);
767 ahd_inw_scbram(struct ahd_softc
*ahd
, u_int offset
)
769 return (ahd_inb_scbram(ahd
, offset
)
770 | (ahd_inb_scbram(ahd
, offset
+1) << 8));
774 ahd_inl_scbram(struct ahd_softc
*ahd
, u_int offset
)
776 return (ahd_inw_scbram(ahd
, offset
)
777 | (ahd_inw_scbram(ahd
, offset
+2) << 16));
781 ahd_inq_scbram(struct ahd_softc
*ahd
, u_int offset
)
783 return (ahd_inl_scbram(ahd
, offset
)
784 | ((uint64_t)ahd_inl_scbram(ahd
, offset
+4)) << 32);
788 ahd_lookup_scb(struct ahd_softc
*ahd
, u_int tag
)
792 if (tag
>= AHD_SCB_MAX
)
794 scb
= ahd
->scb_data
.scbindex
[tag
];
796 ahd_sync_scb(ahd
, scb
,
797 BUS_DMASYNC_POSTREAD
|BUS_DMASYNC_POSTWRITE
);
802 ahd_swap_with_next_hscb(struct ahd_softc
*ahd
, struct scb
*scb
)
804 struct hardware_scb
*q_hscb
;
805 struct map_node
*q_hscb_map
;
806 uint32_t saved_hscb_busaddr
;
809 * Our queuing method is a bit tricky. The card
810 * knows in advance which HSCB (by address) to download,
811 * and we can't disappoint it. To achieve this, the next
812 * HSCB to download is saved off in ahd->next_queued_hscb.
813 * When we are called to queue "an arbitrary scb",
814 * we copy the contents of the incoming HSCB to the one
815 * the sequencer knows about, swap HSCB pointers and
816 * finally assign the SCB to the tag indexed location
817 * in the scb_array. This makes sure that we can still
818 * locate the correct SCB by SCB_TAG.
820 q_hscb
= ahd
->next_queued_hscb
;
821 q_hscb_map
= ahd
->next_queued_hscb_map
;
822 saved_hscb_busaddr
= q_hscb
->hscb_busaddr
;
823 memcpy(q_hscb
, scb
->hscb
, sizeof(*scb
->hscb
));
824 q_hscb
->hscb_busaddr
= saved_hscb_busaddr
;
825 q_hscb
->next_hscb_busaddr
= scb
->hscb
->hscb_busaddr
;
827 /* Now swap HSCB pointers. */
828 ahd
->next_queued_hscb
= scb
->hscb
;
829 ahd
->next_queued_hscb_map
= scb
->hscb_map
;
831 scb
->hscb_map
= q_hscb_map
;
833 /* Now define the mapping from tag to SCB in the scbindex */
834 ahd
->scb_data
.scbindex
[SCB_GET_TAG(scb
)] = scb
;
838 * Tell the sequencer about a new transaction to execute.
841 ahd_queue_scb(struct ahd_softc
*ahd
, struct scb
*scb
)
843 ahd_swap_with_next_hscb(ahd
, scb
);
845 if (SCBID_IS_NULL(SCB_GET_TAG(scb
)))
846 panic("Attempt to queue invalid SCB tag %x\n",
850 * Keep a history of SCBs we've downloaded in the qinfifo.
852 ahd
->qinfifo
[AHD_QIN_WRAP(ahd
->qinfifonext
)] = SCB_GET_TAG(scb
);
855 if (scb
->sg_count
!= 0)
856 ahd_setup_data_scb(ahd
, scb
);
858 ahd_setup_noxfer_scb(ahd
, scb
);
859 ahd_setup_scb_common(ahd
, scb
);
862 * Make sure our data is consistent from the
863 * perspective of the adapter.
865 ahd_sync_scb(ahd
, scb
, BUS_DMASYNC_PREREAD
|BUS_DMASYNC_PREWRITE
);
868 if ((ahd_debug
& AHD_SHOW_QUEUE
) != 0) {
869 uint64_t host_dataptr
;
871 host_dataptr
= ahd_le64toh(scb
->hscb
->dataptr
);
872 printk("%s: Queueing SCB %d:0x%x bus addr 0x%x - 0x%x%x/0x%x\n",
874 SCB_GET_TAG(scb
), scb
->hscb
->scsiid
,
875 ahd_le32toh(scb
->hscb
->hscb_busaddr
),
876 (u_int
)((host_dataptr
>> 32) & 0xFFFFFFFF),
877 (u_int
)(host_dataptr
& 0xFFFFFFFF),
878 ahd_le32toh(scb
->hscb
->datacnt
));
881 /* Tell the adapter about the newly queued SCB */
882 ahd_set_hnscb_qoff(ahd
, ahd
->qinfifonext
);
885 /************************** Interrupt Processing ******************************/
887 ahd_sync_qoutfifo(struct ahd_softc
*ahd
, int op
)
889 ahd_dmamap_sync(ahd
, ahd
->shared_data_dmat
, ahd
->shared_data_map
.dmamap
,
891 /*len*/AHD_SCB_MAX
* sizeof(struct ahd_completion
), op
);
895 ahd_sync_tqinfifo(struct ahd_softc
*ahd
, int op
)
897 #ifdef AHD_TARGET_MODE
898 if ((ahd
->flags
& AHD_TARGETROLE
) != 0) {
899 ahd_dmamap_sync(ahd
, ahd
->shared_data_dmat
,
900 ahd
->shared_data_map
.dmamap
,
901 ahd_targetcmd_offset(ahd
, 0),
902 sizeof(struct target_cmd
) * AHD_TMODE_CMDS
,
909 * See if the firmware has posted any completed commands
910 * into our in-core command complete fifos.
912 #define AHD_RUN_QOUTFIFO 0x1
913 #define AHD_RUN_TQINFIFO 0x2
915 ahd_check_cmdcmpltqueues(struct ahd_softc
*ahd
)
920 ahd_dmamap_sync(ahd
, ahd
->shared_data_dmat
, ahd
->shared_data_map
.dmamap
,
921 /*offset*/ahd
->qoutfifonext
* sizeof(*ahd
->qoutfifo
),
922 /*len*/sizeof(*ahd
->qoutfifo
), BUS_DMASYNC_POSTREAD
);
923 if (ahd
->qoutfifo
[ahd
->qoutfifonext
].valid_tag
924 == ahd
->qoutfifonext_valid_tag
)
925 retval
|= AHD_RUN_QOUTFIFO
;
926 #ifdef AHD_TARGET_MODE
927 if ((ahd
->flags
& AHD_TARGETROLE
) != 0
928 && (ahd
->flags
& AHD_TQINFIFO_BLOCKED
) == 0) {
929 ahd_dmamap_sync(ahd
, ahd
->shared_data_dmat
,
930 ahd
->shared_data_map
.dmamap
,
931 ahd_targetcmd_offset(ahd
, ahd
->tqinfifofnext
),
932 /*len*/sizeof(struct target_cmd
),
933 BUS_DMASYNC_POSTREAD
);
934 if (ahd
->targetcmds
[ahd
->tqinfifonext
].cmd_valid
!= 0)
935 retval
|= AHD_RUN_TQINFIFO
;
942 * Catch an interrupt from the adapter
945 ahd_intr(struct ahd_softc
*ahd
)
949 if ((ahd
->pause
& INTEN
) == 0) {
951 * Our interrupt is not enabled on the chip
952 * and may be disabled for re-entrancy reasons,
953 * so just return. This is likely just a shared
960 * Instead of directly reading the interrupt status register,
961 * infer the cause of the interrupt by checking our in-core
962 * completion queues. This avoids a costly PCI bus read in
965 if ((ahd
->flags
& AHD_ALL_INTERRUPTS
) == 0
966 && (ahd_check_cmdcmpltqueues(ahd
) != 0))
969 intstat
= ahd_inb(ahd
, INTSTAT
);
971 if ((intstat
& INT_PEND
) == 0)
974 if (intstat
& CMDCMPLT
) {
975 ahd_outb(ahd
, CLRINT
, CLRCMDINT
);
978 * Ensure that the chip sees that we've cleared
979 * this interrupt before we walk the output fifo.
980 * Otherwise, we may, due to posted bus writes,
981 * clear the interrupt after we finish the scan,
982 * and after the sequencer has added new entries
983 * and asserted the interrupt again.
985 if ((ahd
->bugs
& AHD_INTCOLLISION_BUG
) != 0) {
986 if (ahd_is_paused(ahd
)) {
988 * Potentially lost SEQINT.
989 * If SEQINTCODE is non-zero,
990 * simulate the SEQINT.
992 if (ahd_inb(ahd
, SEQINTCODE
) != NO_SEQINT
)
996 ahd_flush_device_writes(ahd
);
998 ahd_run_qoutfifo(ahd
);
999 ahd
->cmdcmplt_counts
[ahd
->cmdcmplt_bucket
]++;
1000 ahd
->cmdcmplt_total
++;
1001 #ifdef AHD_TARGET_MODE
1002 if ((ahd
->flags
& AHD_TARGETROLE
) != 0)
1003 ahd_run_tqinfifo(ahd
, /*paused*/FALSE
);
1008 * Handle statuses that may invalidate our cached
1009 * copy of INTSTAT separately.
1011 if (intstat
== 0xFF && (ahd
->features
& AHD_REMOVABLE
) != 0) {
1012 /* Hot eject. Do nothing */
1013 } else if (intstat
& HWERRINT
) {
1014 ahd_handle_hwerrint(ahd
);
1015 } else if ((intstat
& (PCIINT
|SPLTINT
)) != 0) {
1019 if ((intstat
& SEQINT
) != 0)
1020 ahd_handle_seqint(ahd
, intstat
);
1022 if ((intstat
& SCSIINT
) != 0)
1023 ahd_handle_scsiint(ahd
, intstat
);
1028 /******************************** Private Inlines *****************************/
1030 ahd_assert_atn(struct ahd_softc
*ahd
)
1032 ahd_outb(ahd
, SCSISIGO
, ATNO
);
1036 * Determine if the current connection has a packetized
1037 * agreement. This does not necessarily mean that we
1038 * are currently in a packetized transfer. We could
1039 * just as easily be sending or receiving a message.
1042 ahd_currently_packetized(struct ahd_softc
*ahd
)
1044 ahd_mode_state saved_modes
;
1047 saved_modes
= ahd_save_modes(ahd
);
1048 if ((ahd
->bugs
& AHD_PKTIZED_STATUS_BUG
) != 0) {
1050 * The packetized bit refers to the last
1051 * connection, not the current one. Check
1052 * for non-zero LQISTATE instead.
1054 ahd_set_modes(ahd
, AHD_MODE_CFG
, AHD_MODE_CFG
);
1055 packetized
= ahd_inb(ahd
, LQISTATE
) != 0;
1057 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
1058 packetized
= ahd_inb(ahd
, LQISTAT2
) & PACKETIZED
;
1060 ahd_restore_modes(ahd
, saved_modes
);
1061 return (packetized
);
1065 ahd_set_active_fifo(struct ahd_softc
*ahd
)
1069 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
1070 active_fifo
= ahd_inb(ahd
, DFFSTAT
) & CURRFIFO
;
1071 switch (active_fifo
) {
1074 ahd_set_modes(ahd
, active_fifo
, active_fifo
);
1082 ahd_unbusy_tcl(struct ahd_softc
*ahd
, u_int tcl
)
1084 ahd_busy_tcl(ahd
, tcl
, SCB_LIST_NULL
);
1088 * Determine whether the sequencer reported a residual
1089 * for this SCB/transaction.
1092 ahd_update_residual(struct ahd_softc
*ahd
, struct scb
*scb
)
1096 sgptr
= ahd_le32toh(scb
->hscb
->sgptr
);
1097 if ((sgptr
& SG_STATUS_VALID
) != 0)
1098 ahd_calc_residual(ahd
, scb
);
1102 ahd_complete_scb(struct ahd_softc
*ahd
, struct scb
*scb
)
1106 sgptr
= ahd_le32toh(scb
->hscb
->sgptr
);
1107 if ((sgptr
& SG_STATUS_VALID
) != 0)
1108 ahd_handle_scb_status(ahd
, scb
);
1114 /************************* Sequencer Execution Control ************************/
1116 * Restart the sequencer program from address zero
1119 ahd_restart(struct ahd_softc
*ahd
)
1124 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
1126 /* No more pending messages */
1127 ahd_clear_msg_state(ahd
);
1128 ahd_outb(ahd
, SCSISIGO
, 0); /* De-assert BSY */
1129 ahd_outb(ahd
, MSG_OUT
, MSG_NOOP
); /* No message to send */
1130 ahd_outb(ahd
, SXFRCTL1
, ahd_inb(ahd
, SXFRCTL1
) & ~BITBUCKET
);
1131 ahd_outb(ahd
, SEQINTCTL
, 0);
1132 ahd_outb(ahd
, LASTPHASE
, P_BUSFREE
);
1133 ahd_outb(ahd
, SEQ_FLAGS
, 0);
1134 ahd_outb(ahd
, SAVED_SCSIID
, 0xFF);
1135 ahd_outb(ahd
, SAVED_LUN
, 0xFF);
1138 * Ensure that the sequencer's idea of TQINPOS
1139 * matches our own. The sequencer increments TQINPOS
1140 * only after it sees a DMA complete and a reset could
1141 * occur before the increment leaving the kernel to believe
1142 * the command arrived but the sequencer to not.
1144 ahd_outb(ahd
, TQINPOS
, ahd
->tqinfifonext
);
1146 /* Always allow reselection */
1147 ahd_outb(ahd
, SCSISEQ1
,
1148 ahd_inb(ahd
, SCSISEQ_TEMPLATE
) & (ENSELI
|ENRSELI
|ENAUTOATNP
));
1149 ahd_set_modes(ahd
, AHD_MODE_CCHAN
, AHD_MODE_CCHAN
);
1152 * Clear any pending sequencer interrupt. It is no
1153 * longer relevant since we're resetting the Program
1156 ahd_outb(ahd
, CLRINT
, CLRSEQINT
);
1158 ahd_outb(ahd
, SEQCTL0
, FASTMODE
|SEQRESET
);
1163 ahd_clear_fifo(struct ahd_softc
*ahd
, u_int fifo
)
1165 ahd_mode_state saved_modes
;
1168 if ((ahd_debug
& AHD_SHOW_FIFOS
) != 0)
1169 printk("%s: Clearing FIFO %d\n", ahd_name(ahd
), fifo
);
1171 saved_modes
= ahd_save_modes(ahd
);
1172 ahd_set_modes(ahd
, fifo
, fifo
);
1173 ahd_outb(ahd
, DFFSXFRCTL
, RSTCHN
|CLRSHCNT
);
1174 if ((ahd_inb(ahd
, SG_STATE
) & FETCH_INPROG
) != 0)
1175 ahd_outb(ahd
, CCSGCTL
, CCSGRESET
);
1176 ahd_outb(ahd
, LONGJMP_ADDR
+ 1, INVALID_ADDR
);
1177 ahd_outb(ahd
, SG_STATE
, 0);
1178 ahd_restore_modes(ahd
, saved_modes
);
1181 /************************* Input/Output Queues ********************************/
1183 * Flush and completed commands that are sitting in the command
1184 * complete queues down on the chip but have yet to be dma'ed back up.
1187 ahd_flush_qoutfifo(struct ahd_softc
*ahd
)
1190 ahd_mode_state saved_modes
;
1196 saved_modes
= ahd_save_modes(ahd
);
1199 * Flush the good status FIFO for completed packetized commands.
1201 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
1202 saved_scbptr
= ahd_get_scbptr(ahd
);
1203 while ((ahd_inb(ahd
, LQISTAT2
) & LQIGSAVAIL
) != 0) {
1207 scbid
= ahd_inw(ahd
, GSFIFO
);
1208 scb
= ahd_lookup_scb(ahd
, scbid
);
1210 printk("%s: Warning - GSFIFO SCB %d invalid\n",
1211 ahd_name(ahd
), scbid
);
1215 * Determine if this transaction is still active in
1216 * any FIFO. If it is, we must flush that FIFO to
1217 * the host before completing the command.
1221 for (i
= 0; i
< 2; i
++) {
1222 /* Toggle to the other mode. */
1224 ahd_set_modes(ahd
, fifo_mode
, fifo_mode
);
1226 if (ahd_scb_active_in_fifo(ahd
, scb
) == 0)
1229 ahd_run_data_fifo(ahd
, scb
);
1232 * Running this FIFO may cause a CFG4DATA for
1233 * this same transaction to assert in the other
1234 * FIFO or a new snapshot SAVEPTRS interrupt
1235 * in this FIFO. Even running a FIFO may not
1236 * clear the transaction if we are still waiting
1237 * for data to drain to the host. We must loop
1238 * until the transaction is not active in either
1239 * FIFO just to be sure. Reset our loop counter
1240 * so we will visit both FIFOs again before
1241 * declaring this transaction finished. We
1242 * also delay a bit so that status has a chance
1243 * to change before we look at this FIFO again.
1248 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
1249 ahd_set_scbptr(ahd
, scbid
);
1250 if ((ahd_inb_scbram(ahd
, SCB_SGPTR
) & SG_LIST_NULL
) == 0
1251 && ((ahd_inb_scbram(ahd
, SCB_SGPTR
) & SG_FULL_RESID
) != 0
1252 || (ahd_inb_scbram(ahd
, SCB_RESIDUAL_SGPTR
)
1253 & SG_LIST_NULL
) != 0)) {
1257 * The transfer completed with a residual.
1258 * Place this SCB on the complete DMA list
1259 * so that we update our in-core copy of the
1260 * SCB before completing the command.
1262 ahd_outb(ahd
, SCB_SCSI_STATUS
, 0);
1263 ahd_outb(ahd
, SCB_SGPTR
,
1264 ahd_inb_scbram(ahd
, SCB_SGPTR
)
1266 ahd_outw(ahd
, SCB_TAG
, scbid
);
1267 ahd_outw(ahd
, SCB_NEXT_COMPLETE
, SCB_LIST_NULL
);
1268 comp_head
= ahd_inw(ahd
, COMPLETE_DMA_SCB_HEAD
);
1269 if (SCBID_IS_NULL(comp_head
)) {
1270 ahd_outw(ahd
, COMPLETE_DMA_SCB_HEAD
, scbid
);
1271 ahd_outw(ahd
, COMPLETE_DMA_SCB_TAIL
, scbid
);
1275 tail
= ahd_inw(ahd
, COMPLETE_DMA_SCB_TAIL
);
1276 ahd_set_scbptr(ahd
, tail
);
1277 ahd_outw(ahd
, SCB_NEXT_COMPLETE
, scbid
);
1278 ahd_outw(ahd
, COMPLETE_DMA_SCB_TAIL
, scbid
);
1279 ahd_set_scbptr(ahd
, scbid
);
1282 ahd_complete_scb(ahd
, scb
);
1284 ahd_set_scbptr(ahd
, saved_scbptr
);
1287 * Setup for command channel portion of flush.
1289 ahd_set_modes(ahd
, AHD_MODE_CCHAN
, AHD_MODE_CCHAN
);
1292 * Wait for any inprogress DMA to complete and clear DMA state
1293 * if this is for an SCB in the qinfifo.
1295 while (((ccscbctl
= ahd_inb(ahd
, CCSCBCTL
)) & (CCARREN
|CCSCBEN
)) != 0) {
1297 if ((ccscbctl
& (CCSCBDIR
|CCARREN
)) == (CCSCBDIR
|CCARREN
)) {
1298 if ((ccscbctl
& ARRDONE
) != 0)
1300 } else if ((ccscbctl
& CCSCBDONE
) != 0)
1305 * We leave the sequencer to cleanup in the case of DMA's to
1306 * update the qoutfifo. In all other cases (DMA's to the
1307 * chip or a push of an SCB from the COMPLETE_DMA_SCB list),
1308 * we disable the DMA engine so that the sequencer will not
1309 * attempt to handle the DMA completion.
1311 if ((ccscbctl
& CCSCBDIR
) != 0 || (ccscbctl
& ARRDONE
) != 0)
1312 ahd_outb(ahd
, CCSCBCTL
, ccscbctl
& ~(CCARREN
|CCSCBEN
));
1315 * Complete any SCBs that just finished
1316 * being DMA'ed into the qoutfifo.
1318 ahd_run_qoutfifo(ahd
);
1320 saved_scbptr
= ahd_get_scbptr(ahd
);
1322 * Manually update/complete any completed SCBs that are waiting to be
1323 * DMA'ed back up to the host.
1325 scbid
= ahd_inw(ahd
, COMPLETE_DMA_SCB_HEAD
);
1326 while (!SCBID_IS_NULL(scbid
)) {
1330 ahd_set_scbptr(ahd
, scbid
);
1331 next_scbid
= ahd_inw_scbram(ahd
, SCB_NEXT_COMPLETE
);
1332 scb
= ahd_lookup_scb(ahd
, scbid
);
1334 printk("%s: Warning - DMA-up and complete "
1335 "SCB %d invalid\n", ahd_name(ahd
), scbid
);
1338 hscb_ptr
= (uint8_t *)scb
->hscb
;
1339 for (i
= 0; i
< sizeof(struct hardware_scb
); i
++)
1340 *hscb_ptr
++ = ahd_inb_scbram(ahd
, SCB_BASE
+ i
);
1342 ahd_complete_scb(ahd
, scb
);
1345 ahd_outw(ahd
, COMPLETE_DMA_SCB_HEAD
, SCB_LIST_NULL
);
1346 ahd_outw(ahd
, COMPLETE_DMA_SCB_TAIL
, SCB_LIST_NULL
);
1348 scbid
= ahd_inw(ahd
, COMPLETE_ON_QFREEZE_HEAD
);
1349 while (!SCBID_IS_NULL(scbid
)) {
1351 ahd_set_scbptr(ahd
, scbid
);
1352 next_scbid
= ahd_inw_scbram(ahd
, SCB_NEXT_COMPLETE
);
1353 scb
= ahd_lookup_scb(ahd
, scbid
);
1355 printk("%s: Warning - Complete Qfrz SCB %d invalid\n",
1356 ahd_name(ahd
), scbid
);
1360 ahd_complete_scb(ahd
, scb
);
1363 ahd_outw(ahd
, COMPLETE_ON_QFREEZE_HEAD
, SCB_LIST_NULL
);
1365 scbid
= ahd_inw(ahd
, COMPLETE_SCB_HEAD
);
1366 while (!SCBID_IS_NULL(scbid
)) {
1368 ahd_set_scbptr(ahd
, scbid
);
1369 next_scbid
= ahd_inw_scbram(ahd
, SCB_NEXT_COMPLETE
);
1370 scb
= ahd_lookup_scb(ahd
, scbid
);
1372 printk("%s: Warning - Complete SCB %d invalid\n",
1373 ahd_name(ahd
), scbid
);
1377 ahd_complete_scb(ahd
, scb
);
1380 ahd_outw(ahd
, COMPLETE_SCB_HEAD
, SCB_LIST_NULL
);
1385 ahd_set_scbptr(ahd
, saved_scbptr
);
1386 ahd_restore_modes(ahd
, saved_modes
);
1387 ahd
->flags
|= AHD_UPDATE_PEND_CMDS
;
1391 * Determine if an SCB for a packetized transaction
1392 * is active in a FIFO.
1395 ahd_scb_active_in_fifo(struct ahd_softc
*ahd
, struct scb
*scb
)
1399 * The FIFO is only active for our transaction if
1400 * the SCBPTR matches the SCB's ID and the firmware
1401 * has installed a handler for the FIFO or we have
1402 * a pending SAVEPTRS or CFG4DATA interrupt.
1404 if (ahd_get_scbptr(ahd
) != SCB_GET_TAG(scb
)
1405 || ((ahd_inb(ahd
, LONGJMP_ADDR
+1) & INVALID_ADDR
) != 0
1406 && (ahd_inb(ahd
, SEQINTSRC
) & (CFG4DATA
|SAVEPTRS
)) == 0))
1413 * Run a data fifo to completion for a transaction we know
1414 * has completed across the SCSI bus (good status has been
1415 * received). We are already set to the correct FIFO mode
1416 * on entry to this routine.
1418 * This function attempts to operate exactly as the firmware
1419 * would when running this FIFO. Care must be taken to update
1420 * this routine any time the firmware's FIFO algorithm is
1424 ahd_run_data_fifo(struct ahd_softc
*ahd
, struct scb
*scb
)
1428 seqintsrc
= ahd_inb(ahd
, SEQINTSRC
);
1429 if ((seqintsrc
& CFG4DATA
) != 0) {
1434 * Clear full residual flag.
1436 sgptr
= ahd_inl_scbram(ahd
, SCB_SGPTR
) & ~SG_FULL_RESID
;
1437 ahd_outb(ahd
, SCB_SGPTR
, sgptr
);
1440 * Load datacnt and address.
1442 datacnt
= ahd_inl_scbram(ahd
, SCB_DATACNT
);
1443 if ((datacnt
& AHD_DMA_LAST_SEG
) != 0) {
1445 ahd_outb(ahd
, SG_STATE
, 0);
1447 ahd_outb(ahd
, SG_STATE
, LOADING_NEEDED
);
1448 ahd_outq(ahd
, HADDR
, ahd_inq_scbram(ahd
, SCB_DATAPTR
));
1449 ahd_outl(ahd
, HCNT
, datacnt
& AHD_SG_LEN_MASK
);
1450 ahd_outb(ahd
, SG_CACHE_PRE
, sgptr
);
1451 ahd_outb(ahd
, DFCNTRL
, PRELOADEN
|SCSIEN
|HDMAEN
);
1454 * Initialize Residual Fields.
1456 ahd_outb(ahd
, SCB_RESIDUAL_DATACNT
+3, datacnt
>> 24);
1457 ahd_outl(ahd
, SCB_RESIDUAL_SGPTR
, sgptr
& SG_PTR_MASK
);
1460 * Mark the SCB as having a FIFO in use.
1462 ahd_outb(ahd
, SCB_FIFO_USE_COUNT
,
1463 ahd_inb_scbram(ahd
, SCB_FIFO_USE_COUNT
) + 1);
1466 * Install a "fake" handler for this FIFO.
1468 ahd_outw(ahd
, LONGJMP_ADDR
, 0);
1471 * Notify the hardware that we have satisfied
1472 * this sequencer interrupt.
1474 ahd_outb(ahd
, CLRSEQINTSRC
, CLRCFG4DATA
);
1475 } else if ((seqintsrc
& SAVEPTRS
) != 0) {
1479 if ((ahd_inb(ahd
, LONGJMP_ADDR
+1)&INVALID_ADDR
) != 0) {
1481 * Snapshot Save Pointers. All that
1482 * is necessary to clear the snapshot
1489 * Disable S/G fetch so the DMA engine
1490 * is available to future users.
1492 if ((ahd_inb(ahd
, SG_STATE
) & FETCH_INPROG
) != 0)
1493 ahd_outb(ahd
, CCSGCTL
, 0);
1494 ahd_outb(ahd
, SG_STATE
, 0);
1497 * Flush the data FIFO. Strickly only
1498 * necessary for Rev A parts.
1500 ahd_outb(ahd
, DFCNTRL
, ahd_inb(ahd
, DFCNTRL
) | FIFOFLUSH
);
1503 * Calculate residual.
1505 sgptr
= ahd_inl_scbram(ahd
, SCB_RESIDUAL_SGPTR
);
1506 resid
= ahd_inl(ahd
, SHCNT
);
1507 resid
|= ahd_inb_scbram(ahd
, SCB_RESIDUAL_DATACNT
+3) << 24;
1508 ahd_outl(ahd
, SCB_RESIDUAL_DATACNT
, resid
);
1509 if ((ahd_inb(ahd
, SG_CACHE_SHADOW
) & LAST_SEG
) == 0) {
1511 * Must back up to the correct S/G element.
1512 * Typically this just means resetting our
1513 * low byte to the offset in the SG_CACHE,
1514 * but if we wrapped, we have to correct
1515 * the other bytes of the sgptr too.
1517 if ((ahd_inb(ahd
, SG_CACHE_SHADOW
) & 0x80) != 0
1518 && (sgptr
& 0x80) == 0)
1521 sgptr
|= ahd_inb(ahd
, SG_CACHE_SHADOW
)
1523 ahd_outl(ahd
, SCB_RESIDUAL_SGPTR
, sgptr
);
1524 ahd_outb(ahd
, SCB_RESIDUAL_DATACNT
+ 3, 0);
1525 } else if ((resid
& AHD_SG_LEN_MASK
) == 0) {
1526 ahd_outb(ahd
, SCB_RESIDUAL_SGPTR
,
1527 sgptr
| SG_LIST_NULL
);
1532 ahd_outq(ahd
, SCB_DATAPTR
, ahd_inq(ahd
, SHADDR
));
1533 ahd_outl(ahd
, SCB_DATACNT
, resid
);
1534 ahd_outl(ahd
, SCB_SGPTR
, sgptr
);
1535 ahd_outb(ahd
, CLRSEQINTSRC
, CLRSAVEPTRS
);
1536 ahd_outb(ahd
, SEQIMODE
,
1537 ahd_inb(ahd
, SEQIMODE
) | ENSAVEPTRS
);
1539 * If the data is to the SCSI bus, we are
1540 * done, otherwise wait for FIFOEMP.
1542 if ((ahd_inb(ahd
, DFCNTRL
) & DIRECTION
) != 0)
1544 } else if ((ahd_inb(ahd
, SG_STATE
) & LOADING_NEEDED
) != 0) {
1551 * Disable S/G fetch so the DMA engine
1552 * is available to future users. We won't
1553 * be using the DMA engine to load segments.
1555 if ((ahd_inb(ahd
, SG_STATE
) & FETCH_INPROG
) != 0) {
1556 ahd_outb(ahd
, CCSGCTL
, 0);
1557 ahd_outb(ahd
, SG_STATE
, LOADING_NEEDED
);
1561 * Wait for the DMA engine to notice that the
1562 * host transfer is enabled and that there is
1563 * space in the S/G FIFO for new segments before
1564 * loading more segments.
1566 if ((ahd_inb(ahd
, DFSTATUS
) & PRELOAD_AVAIL
) != 0
1567 && (ahd_inb(ahd
, DFCNTRL
) & HDMAENACK
) != 0) {
1570 * Determine the offset of the next S/G
1573 sgptr
= ahd_inl_scbram(ahd
, SCB_RESIDUAL_SGPTR
);
1574 sgptr
&= SG_PTR_MASK
;
1575 if ((ahd
->flags
& AHD_64BIT_ADDRESSING
) != 0) {
1576 struct ahd_dma64_seg
*sg
;
1578 sg
= ahd_sg_bus_to_virt(ahd
, scb
, sgptr
);
1579 data_addr
= sg
->addr
;
1581 sgptr
+= sizeof(*sg
);
1583 struct ahd_dma_seg
*sg
;
1585 sg
= ahd_sg_bus_to_virt(ahd
, scb
, sgptr
);
1586 data_addr
= sg
->len
& AHD_SG_HIGH_ADDR_MASK
;
1588 data_addr
|= sg
->addr
;
1590 sgptr
+= sizeof(*sg
);
1594 * Update residual information.
1596 ahd_outb(ahd
, SCB_RESIDUAL_DATACNT
+3, data_len
>> 24);
1597 ahd_outl(ahd
, SCB_RESIDUAL_SGPTR
, sgptr
);
1602 if (data_len
& AHD_DMA_LAST_SEG
) {
1604 ahd_outb(ahd
, SG_STATE
, 0);
1606 ahd_outq(ahd
, HADDR
, data_addr
);
1607 ahd_outl(ahd
, HCNT
, data_len
& AHD_SG_LEN_MASK
);
1608 ahd_outb(ahd
, SG_CACHE_PRE
, sgptr
& 0xFF);
1611 * Advertise the segment to the hardware.
1613 dfcntrl
= ahd_inb(ahd
, DFCNTRL
)|PRELOADEN
|HDMAEN
;
1614 if ((ahd
->features
& AHD_NEW_DFCNTRL_OPTS
) != 0) {
1616 * Use SCSIENWRDIS so that SCSIEN
1617 * is never modified by this
1620 dfcntrl
|= SCSIENWRDIS
;
1622 ahd_outb(ahd
, DFCNTRL
, dfcntrl
);
1624 } else if ((ahd_inb(ahd
, SG_CACHE_SHADOW
) & LAST_SEG_DONE
) != 0) {
1627 * Transfer completed to the end of SG list
1628 * and has flushed to the host.
1630 ahd_outb(ahd
, SCB_SGPTR
,
1631 ahd_inb_scbram(ahd
, SCB_SGPTR
) | SG_LIST_NULL
);
1633 } else if ((ahd_inb(ahd
, DFSTATUS
) & FIFOEMP
) != 0) {
1636 * Clear any handler for this FIFO, decrement
1637 * the FIFO use count for the SCB, and release
1640 ahd_outb(ahd
, LONGJMP_ADDR
+ 1, INVALID_ADDR
);
1641 ahd_outb(ahd
, SCB_FIFO_USE_COUNT
,
1642 ahd_inb_scbram(ahd
, SCB_FIFO_USE_COUNT
) - 1);
1643 ahd_outb(ahd
, DFFSXFRCTL
, CLRCHN
);
1648 * Look for entries in the QoutFIFO that have completed.
1649 * The valid_tag completion field indicates the validity
1650 * of the entry - the valid value toggles each time through
1651 * the queue. We use the sg_status field in the completion
1652 * entry to avoid referencing the hscb if the completion
1653 * occurred with no errors and no residual. sg_status is
1654 * a copy of the first byte (little endian) of the sgptr
1658 ahd_run_qoutfifo(struct ahd_softc
*ahd
)
1660 struct ahd_completion
*completion
;
1664 if ((ahd
->flags
& AHD_RUNNING_QOUTFIFO
) != 0)
1665 panic("ahd_run_qoutfifo recursion");
1666 ahd
->flags
|= AHD_RUNNING_QOUTFIFO
;
1667 ahd_sync_qoutfifo(ahd
, BUS_DMASYNC_POSTREAD
);
1669 completion
= &ahd
->qoutfifo
[ahd
->qoutfifonext
];
1671 if (completion
->valid_tag
!= ahd
->qoutfifonext_valid_tag
)
1674 scb_index
= ahd_le16toh(completion
->tag
);
1675 scb
= ahd_lookup_scb(ahd
, scb_index
);
1677 printk("%s: WARNING no command for scb %d "
1678 "(cmdcmplt)\nQOUTPOS = %d\n",
1679 ahd_name(ahd
), scb_index
,
1681 ahd_dump_card_state(ahd
);
1682 } else if ((completion
->sg_status
& SG_STATUS_VALID
) != 0) {
1683 ahd_handle_scb_status(ahd
, scb
);
1688 ahd
->qoutfifonext
= (ahd
->qoutfifonext
+1) & (AHD_QOUT_SIZE
-1);
1689 if (ahd
->qoutfifonext
== 0)
1690 ahd
->qoutfifonext_valid_tag
^= QOUTFIFO_ENTRY_VALID
;
1692 ahd
->flags
&= ~AHD_RUNNING_QOUTFIFO
;
1695 /************************* Interrupt Handling *********************************/
1697 ahd_handle_hwerrint(struct ahd_softc
*ahd
)
1700 * Some catastrophic hardware error has occurred.
1701 * Print it for the user and disable the controller.
1706 error
= ahd_inb(ahd
, ERROR
);
1707 for (i
= 0; i
< num_errors
; i
++) {
1708 if ((error
& ahd_hard_errors
[i
].errno
) != 0)
1709 printk("%s: hwerrint, %s\n",
1710 ahd_name(ahd
), ahd_hard_errors
[i
].errmesg
);
1713 ahd_dump_card_state(ahd
);
1716 /* Tell everyone that this HBA is no longer available */
1717 ahd_abort_scbs(ahd
, CAM_TARGET_WILDCARD
, ALL_CHANNELS
,
1718 CAM_LUN_WILDCARD
, SCB_LIST_NULL
, ROLE_UNKNOWN
,
1721 /* Tell the system that this controller has gone away. */
1727 ahd_dump_sglist(struct scb
*scb
)
1731 if (scb
->sg_count
> 0) {
1732 if ((scb
->ahd_softc
->flags
& AHD_64BIT_ADDRESSING
) != 0) {
1733 struct ahd_dma64_seg
*sg_list
;
1735 sg_list
= (struct ahd_dma64_seg
*)scb
->sg_list
;
1736 for (i
= 0; i
< scb
->sg_count
; i
++) {
1740 addr
= ahd_le64toh(sg_list
[i
].addr
);
1741 len
= ahd_le32toh(sg_list
[i
].len
);
1742 printk("sg[%d] - Addr 0x%x%x : Length %d%s\n",
1744 (uint32_t)((addr
>> 32) & 0xFFFFFFFF),
1745 (uint32_t)(addr
& 0xFFFFFFFF),
1746 sg_list
[i
].len
& AHD_SG_LEN_MASK
,
1747 (sg_list
[i
].len
& AHD_DMA_LAST_SEG
)
1751 struct ahd_dma_seg
*sg_list
;
1753 sg_list
= (struct ahd_dma_seg
*)scb
->sg_list
;
1754 for (i
= 0; i
< scb
->sg_count
; i
++) {
1757 len
= ahd_le32toh(sg_list
[i
].len
);
1758 printk("sg[%d] - Addr 0x%x%x : Length %d%s\n",
1760 (len
& AHD_SG_HIGH_ADDR_MASK
) >> 24,
1761 ahd_le32toh(sg_list
[i
].addr
),
1762 len
& AHD_SG_LEN_MASK
,
1763 len
& AHD_DMA_LAST_SEG
? " Last" : "");
1768 #endif /* AHD_DEBUG */
1771 ahd_handle_seqint(struct ahd_softc
*ahd
, u_int intstat
)
1776 * Save the sequencer interrupt code and clear the SEQINT
1777 * bit. We will unpause the sequencer, if appropriate,
1778 * after servicing the request.
1780 seqintcode
= ahd_inb(ahd
, SEQINTCODE
);
1781 ahd_outb(ahd
, CLRINT
, CLRSEQINT
);
1782 if ((ahd
->bugs
& AHD_INTCOLLISION_BUG
) != 0) {
1784 * Unpause the sequencer and let it clear
1785 * SEQINT by writing NO_SEQINT to it. This
1786 * will cause the sequencer to be paused again,
1787 * which is the expected state of this routine.
1790 while (!ahd_is_paused(ahd
))
1792 ahd_outb(ahd
, CLRINT
, CLRSEQINT
);
1794 ahd_update_modes(ahd
);
1796 if ((ahd_debug
& AHD_SHOW_MISC
) != 0)
1797 printk("%s: Handle Seqint Called for code %d\n",
1798 ahd_name(ahd
), seqintcode
);
1800 switch (seqintcode
) {
1801 case ENTERING_NONPACK
:
1806 AHD_ASSERT_MODES(ahd
, ~(AHD_MODE_UNKNOWN_MSK
|AHD_MODE_CFG_MSK
),
1807 ~(AHD_MODE_UNKNOWN_MSK
|AHD_MODE_CFG_MSK
));
1808 scbid
= ahd_get_scbptr(ahd
);
1809 scb
= ahd_lookup_scb(ahd
, scbid
);
1812 * Somehow need to know if this
1813 * is from a selection or reselection.
1814 * From that, we can determine target
1815 * ID so we at least have an I_T nexus.
1818 ahd_outb(ahd
, SAVED_SCSIID
, scb
->hscb
->scsiid
);
1819 ahd_outb(ahd
, SAVED_LUN
, scb
->hscb
->lun
);
1820 ahd_outb(ahd
, SEQ_FLAGS
, 0x0);
1822 if ((ahd_inb(ahd
, LQISTAT2
) & LQIPHASE_OUTPKT
) != 0
1823 && (ahd_inb(ahd
, SCSISIGO
) & ATNO
) != 0) {
1825 * Phase change after read stream with
1826 * CRC error with P0 asserted on last
1830 if ((ahd_debug
& AHD_SHOW_RECOVERY
) != 0)
1831 printk("%s: Assuming LQIPHASE_NLQ with "
1832 "P0 assertion\n", ahd_name(ahd
));
1836 if ((ahd_debug
& AHD_SHOW_RECOVERY
) != 0)
1837 printk("%s: Entering NONPACK\n", ahd_name(ahd
));
1841 case INVALID_SEQINT
:
1842 printk("%s: Invalid Sequencer interrupt occurred, "
1843 "resetting channel.\n",
1846 if ((ahd_debug
& AHD_SHOW_RECOVERY
) != 0)
1847 ahd_dump_card_state(ahd
);
1849 ahd_reset_channel(ahd
, 'A', /*Initiate Reset*/TRUE
);
1851 case STATUS_OVERRUN
:
1856 scbid
= ahd_get_scbptr(ahd
);
1857 scb
= ahd_lookup_scb(ahd
, scbid
);
1859 ahd_print_path(ahd
, scb
);
1861 printk("%s: ", ahd_name(ahd
));
1862 printk("SCB %d Packetized Status Overrun", scbid
);
1863 ahd_dump_card_state(ahd
);
1864 ahd_reset_channel(ahd
, 'A', /*Initiate Reset*/TRUE
);
1867 case CFG4ISTAT_INTR
:
1872 scbid
= ahd_get_scbptr(ahd
);
1873 scb
= ahd_lookup_scb(ahd
, scbid
);
1875 ahd_dump_card_state(ahd
);
1876 printk("CFG4ISTAT: Free SCB %d referenced", scbid
);
1877 panic("For safety");
1879 ahd_outq(ahd
, HADDR
, scb
->sense_busaddr
);
1880 ahd_outw(ahd
, HCNT
, AHD_SENSE_BUFSIZE
);
1881 ahd_outb(ahd
, HCNT
+ 2, 0);
1882 ahd_outb(ahd
, SG_CACHE_PRE
, SG_LAST_SEG
);
1883 ahd_outb(ahd
, DFCNTRL
, PRELOADEN
|SCSIEN
|HDMAEN
);
1890 bus_phase
= ahd_inb(ahd
, SCSISIGI
) & PHASE_MASK
;
1891 printk("%s: ILLEGAL_PHASE 0x%x\n",
1892 ahd_name(ahd
), bus_phase
);
1894 switch (bus_phase
) {
1902 ahd_reset_channel(ahd
, 'A', /*Initiate Reset*/TRUE
);
1903 printk("%s: Issued Bus Reset.\n", ahd_name(ahd
));
1907 struct ahd_devinfo devinfo
;
1909 struct ahd_initiator_tinfo
*targ_info
;
1910 struct ahd_tmode_tstate
*tstate
;
1911 struct ahd_transinfo
*tinfo
;
1915 * If a target takes us into the command phase
1916 * assume that it has been externally reset and
1917 * has thus lost our previous packetized negotiation
1918 * agreement. Since we have not sent an identify
1919 * message and may not have fully qualified the
1920 * connection, we change our command to TUR, assert
1921 * ATN and ABORT the task when we go to message in
1922 * phase. The OSM will see the REQUEUE_REQUEST
1923 * status and retry the command.
1925 scbid
= ahd_get_scbptr(ahd
);
1926 scb
= ahd_lookup_scb(ahd
, scbid
);
1928 printk("Invalid phase with no valid SCB. "
1929 "Resetting bus.\n");
1930 ahd_reset_channel(ahd
, 'A',
1931 /*Initiate Reset*/TRUE
);
1934 ahd_compile_devinfo(&devinfo
, SCB_GET_OUR_ID(scb
),
1935 SCB_GET_TARGET(ahd
, scb
),
1937 SCB_GET_CHANNEL(ahd
, scb
),
1939 targ_info
= ahd_fetch_transinfo(ahd
,
1944 tinfo
= &targ_info
->curr
;
1945 ahd_set_width(ahd
, &devinfo
, MSG_EXT_WDTR_BUS_8_BIT
,
1946 AHD_TRANS_ACTIVE
, /*paused*/TRUE
);
1947 ahd_set_syncrate(ahd
, &devinfo
, /*period*/0,
1948 /*offset*/0, /*ppr_options*/0,
1949 AHD_TRANS_ACTIVE
, /*paused*/TRUE
);
1950 /* Hand-craft TUR command */
1951 ahd_outb(ahd
, SCB_CDB_STORE
, 0);
1952 ahd_outb(ahd
, SCB_CDB_STORE
+1, 0);
1953 ahd_outb(ahd
, SCB_CDB_STORE
+2, 0);
1954 ahd_outb(ahd
, SCB_CDB_STORE
+3, 0);
1955 ahd_outb(ahd
, SCB_CDB_STORE
+4, 0);
1956 ahd_outb(ahd
, SCB_CDB_STORE
+5, 0);
1957 ahd_outb(ahd
, SCB_CDB_LEN
, 6);
1958 scb
->hscb
->control
&= ~(TAG_ENB
|SCB_TAG_TYPE
);
1959 scb
->hscb
->control
|= MK_MESSAGE
;
1960 ahd_outb(ahd
, SCB_CONTROL
, scb
->hscb
->control
);
1961 ahd_outb(ahd
, MSG_OUT
, HOST_MSG
);
1962 ahd_outb(ahd
, SAVED_SCSIID
, scb
->hscb
->scsiid
);
1964 * The lun is 0, regardless of the SCB's lun
1965 * as we have not sent an identify message.
1967 ahd_outb(ahd
, SAVED_LUN
, 0);
1968 ahd_outb(ahd
, SEQ_FLAGS
, 0);
1969 ahd_assert_atn(ahd
);
1970 scb
->flags
&= ~SCB_PACKETIZED
;
1971 scb
->flags
|= SCB_ABORT
|SCB_EXTERNAL_RESET
;
1972 ahd_freeze_devq(ahd
, scb
);
1973 ahd_set_transaction_status(scb
, CAM_REQUEUE_REQ
);
1974 ahd_freeze_scb(scb
);
1977 ahd_send_async(ahd
, devinfo
.channel
, devinfo
.target
,
1978 CAM_LUN_WILDCARD
, AC_SENT_BDR
);
1981 * Allow the sequencer to continue with
1982 * non-pack processing.
1984 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
1985 ahd_outb(ahd
, CLRLQOINT1
, CLRLQOPHACHGINPKT
);
1986 if ((ahd
->bugs
& AHD_CLRLQO_AUTOCLR_BUG
) != 0) {
1987 ahd_outb(ahd
, CLRLQOINT1
, 0);
1990 if ((ahd_debug
& AHD_SHOW_RECOVERY
) != 0) {
1991 ahd_print_path(ahd
, scb
);
1992 printk("Unexpected command phase from "
1993 "packetized target\n");
2007 if ((ahd_debug
& AHD_SHOW_RECOVERY
) != 0) {
2008 printk("%s: CFG4OVERRUN mode = %x\n", ahd_name(ahd
),
2009 ahd_inb(ahd
, MODE_PTR
));
2012 scb_index
= ahd_get_scbptr(ahd
);
2013 scb
= ahd_lookup_scb(ahd
, scb_index
);
2016 * Attempt to transfer to an SCB that is
2019 ahd_assert_atn(ahd
);
2020 ahd_outb(ahd
, MSG_OUT
, HOST_MSG
);
2021 ahd
->msgout_buf
[0] = MSG_ABORT_TASK
;
2022 ahd
->msgout_len
= 1;
2023 ahd
->msgout_index
= 0;
2024 ahd
->msg_type
= MSG_TYPE_INITIATOR_MSGOUT
;
2026 * Clear status received flag to prevent any
2027 * attempt to complete this bogus SCB.
2029 ahd_outb(ahd
, SCB_CONTROL
,
2030 ahd_inb_scbram(ahd
, SCB_CONTROL
)
2035 case DUMP_CARD_STATE
:
2037 ahd_dump_card_state(ahd
);
2043 if ((ahd_debug
& AHD_SHOW_RECOVERY
) != 0) {
2044 printk("%s: PDATA_REINIT - DFCNTRL = 0x%x "
2045 "SG_CACHE_SHADOW = 0x%x\n",
2046 ahd_name(ahd
), ahd_inb(ahd
, DFCNTRL
),
2047 ahd_inb(ahd
, SG_CACHE_SHADOW
));
2050 ahd_reinitialize_dataptrs(ahd
);
2055 struct ahd_devinfo devinfo
;
2058 * The sequencer has encountered a message phase
2059 * that requires host assistance for completion.
2060 * While handling the message phase(s), we will be
2061 * notified by the sequencer after each byte is
2062 * transferred so we can track bus phase changes.
2064 * If this is the first time we've seen a HOST_MSG_LOOP
2065 * interrupt, initialize the state of the host message
2068 ahd_fetch_devinfo(ahd
, &devinfo
);
2069 if (ahd
->msg_type
== MSG_TYPE_NONE
) {
2074 bus_phase
= ahd_inb(ahd
, SCSISIGI
) & PHASE_MASK
;
2075 if (bus_phase
!= P_MESGIN
2076 && bus_phase
!= P_MESGOUT
) {
2077 printk("ahd_intr: HOST_MSG_LOOP bad "
2078 "phase 0x%x\n", bus_phase
);
2080 * Probably transitioned to bus free before
2081 * we got here. Just punt the message.
2083 ahd_dump_card_state(ahd
);
2084 ahd_clear_intstat(ahd
);
2089 scb_index
= ahd_get_scbptr(ahd
);
2090 scb
= ahd_lookup_scb(ahd
, scb_index
);
2091 if (devinfo
.role
== ROLE_INITIATOR
) {
2092 if (bus_phase
== P_MESGOUT
)
2093 ahd_setup_initiator_msgout(ahd
,
2098 MSG_TYPE_INITIATOR_MSGIN
;
2099 ahd
->msgin_index
= 0;
2102 #ifdef AHD_TARGET_MODE
2104 if (bus_phase
== P_MESGOUT
) {
2106 MSG_TYPE_TARGET_MSGOUT
;
2107 ahd
->msgin_index
= 0;
2110 ahd_setup_target_msgin(ahd
,
2117 ahd_handle_message_phase(ahd
);
2122 /* Ensure we don't leave the selection hardware on */
2123 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
2124 ahd_outb(ahd
, SCSISEQ0
, ahd_inb(ahd
, SCSISEQ0
) & ~ENSELO
);
2126 printk("%s:%c:%d: no active SCB for reconnecting "
2127 "target - issuing BUS DEVICE RESET\n",
2128 ahd_name(ahd
), 'A', ahd_inb(ahd
, SELID
) >> 4);
2129 printk("SAVED_SCSIID == 0x%x, SAVED_LUN == 0x%x, "
2130 "REG0 == 0x%x ACCUM = 0x%x\n",
2131 ahd_inb(ahd
, SAVED_SCSIID
), ahd_inb(ahd
, SAVED_LUN
),
2132 ahd_inw(ahd
, REG0
), ahd_inb(ahd
, ACCUM
));
2133 printk("SEQ_FLAGS == 0x%x, SCBPTR == 0x%x, BTT == 0x%x, "
2135 ahd_inb(ahd
, SEQ_FLAGS
), ahd_get_scbptr(ahd
),
2136 ahd_find_busy_tcl(ahd
,
2137 BUILD_TCL(ahd_inb(ahd
, SAVED_SCSIID
),
2138 ahd_inb(ahd
, SAVED_LUN
))),
2139 ahd_inw(ahd
, SINDEX
));
2140 printk("SELID == 0x%x, SCB_SCSIID == 0x%x, SCB_LUN == 0x%x, "
2141 "SCB_CONTROL == 0x%x\n",
2142 ahd_inb(ahd
, SELID
), ahd_inb_scbram(ahd
, SCB_SCSIID
),
2143 ahd_inb_scbram(ahd
, SCB_LUN
),
2144 ahd_inb_scbram(ahd
, SCB_CONTROL
));
2145 printk("SCSIBUS[0] == 0x%x, SCSISIGI == 0x%x\n",
2146 ahd_inb(ahd
, SCSIBUS
), ahd_inb(ahd
, SCSISIGI
));
2147 printk("SXFRCTL0 == 0x%x\n", ahd_inb(ahd
, SXFRCTL0
));
2148 printk("SEQCTL0 == 0x%x\n", ahd_inb(ahd
, SEQCTL0
));
2149 ahd_dump_card_state(ahd
);
2150 ahd
->msgout_buf
[0] = MSG_BUS_DEV_RESET
;
2151 ahd
->msgout_len
= 1;
2152 ahd
->msgout_index
= 0;
2153 ahd
->msg_type
= MSG_TYPE_INITIATOR_MSGOUT
;
2154 ahd_outb(ahd
, MSG_OUT
, HOST_MSG
);
2155 ahd_assert_atn(ahd
);
2158 case PROTO_VIOLATION
:
2160 ahd_handle_proto_violation(ahd
);
2165 struct ahd_devinfo devinfo
;
2167 ahd_fetch_devinfo(ahd
, &devinfo
);
2168 ahd_handle_ign_wide_residue(ahd
, &devinfo
);
2175 lastphase
= ahd_inb(ahd
, LASTPHASE
);
2176 printk("%s:%c:%d: unknown scsi bus phase %x, "
2177 "lastphase = 0x%x. Attempting to continue\n",
2179 SCSIID_TARGET(ahd
, ahd_inb(ahd
, SAVED_SCSIID
)),
2180 lastphase
, ahd_inb(ahd
, SCSISIGI
));
2183 case MISSED_BUSFREE
:
2187 lastphase
= ahd_inb(ahd
, LASTPHASE
);
2188 printk("%s:%c:%d: Missed busfree. "
2189 "Lastphase = 0x%x, Curphase = 0x%x\n",
2191 SCSIID_TARGET(ahd
, ahd_inb(ahd
, SAVED_SCSIID
)),
2192 lastphase
, ahd_inb(ahd
, SCSISIGI
));
2199 * When the sequencer detects an overrun, it
2200 * places the controller in "BITBUCKET" mode
2201 * and allows the target to complete its transfer.
2202 * Unfortunately, none of the counters get updated
2203 * when the controller is in this mode, so we have
2204 * no way of knowing how large the overrun was.
2212 scbindex
= ahd_get_scbptr(ahd
);
2213 scb
= ahd_lookup_scb(ahd
, scbindex
);
2215 lastphase
= ahd_inb(ahd
, LASTPHASE
);
2216 if ((ahd_debug
& AHD_SHOW_RECOVERY
) != 0) {
2217 ahd_print_path(ahd
, scb
);
2218 printk("data overrun detected %s. Tag == 0x%x.\n",
2219 ahd_lookup_phase_entry(lastphase
)->phasemsg
,
2221 ahd_print_path(ahd
, scb
);
2222 printk("%s seen Data Phase. Length = %ld. "
2224 ahd_inb(ahd
, SEQ_FLAGS
) & DPHASE
2225 ? "Have" : "Haven't",
2226 ahd_get_transfer_length(scb
), scb
->sg_count
);
2227 ahd_dump_sglist(scb
);
2232 * Set this and it will take effect when the
2233 * target does a command complete.
2235 ahd_freeze_devq(ahd
, scb
);
2236 ahd_set_transaction_status(scb
, CAM_DATA_RUN_ERR
);
2237 ahd_freeze_scb(scb
);
2242 struct ahd_devinfo devinfo
;
2246 ahd_fetch_devinfo(ahd
, &devinfo
);
2247 printk("%s:%c:%d:%d: Attempt to issue message failed\n",
2248 ahd_name(ahd
), devinfo
.channel
, devinfo
.target
,
2250 scbid
= ahd_get_scbptr(ahd
);
2251 scb
= ahd_lookup_scb(ahd
, scbid
);
2253 && (scb
->flags
& SCB_RECOVERY_SCB
) != 0)
2255 * Ensure that we didn't put a second instance of this
2256 * SCB into the QINFIFO.
2258 ahd_search_qinfifo(ahd
, SCB_GET_TARGET(ahd
, scb
),
2259 SCB_GET_CHANNEL(ahd
, scb
),
2260 SCB_GET_LUN(scb
), SCB_GET_TAG(scb
),
2261 ROLE_INITIATOR
, /*status*/0,
2263 ahd_outb(ahd
, SCB_CONTROL
,
2264 ahd_inb_scbram(ahd
, SCB_CONTROL
) & ~MK_MESSAGE
);
2267 case TASKMGMT_FUNC_COMPLETE
:
2272 scbid
= ahd_get_scbptr(ahd
);
2273 scb
= ahd_lookup_scb(ahd
, scbid
);
2279 ahd_print_path(ahd
, scb
);
2280 printk("Task Management Func 0x%x Complete\n",
2281 scb
->hscb
->task_management
);
2282 lun
= CAM_LUN_WILDCARD
;
2283 tag
= SCB_LIST_NULL
;
2285 switch (scb
->hscb
->task_management
) {
2286 case SIU_TASKMGMT_ABORT_TASK
:
2287 tag
= SCB_GET_TAG(scb
);
2289 case SIU_TASKMGMT_ABORT_TASK_SET
:
2290 case SIU_TASKMGMT_CLEAR_TASK_SET
:
2291 lun
= scb
->hscb
->lun
;
2292 error
= CAM_REQ_ABORTED
;
2293 ahd_abort_scbs(ahd
, SCB_GET_TARGET(ahd
, scb
),
2294 'A', lun
, tag
, ROLE_INITIATOR
,
2297 case SIU_TASKMGMT_LUN_RESET
:
2298 lun
= scb
->hscb
->lun
;
2300 case SIU_TASKMGMT_TARGET_RESET
:
2302 struct ahd_devinfo devinfo
;
2304 ahd_scb_devinfo(ahd
, &devinfo
, scb
);
2305 error
= CAM_BDR_SENT
;
2306 ahd_handle_devreset(ahd
, &devinfo
, lun
,
2308 lun
!= CAM_LUN_WILDCARD
2311 /*verbose_level*/0);
2315 panic("Unexpected TaskMgmt Func\n");
2321 case TASKMGMT_CMD_CMPLT_OKAY
:
2327 * An ABORT TASK TMF failed to be delivered before
2328 * the targeted command completed normally.
2330 scbid
= ahd_get_scbptr(ahd
);
2331 scb
= ahd_lookup_scb(ahd
, scbid
);
2334 * Remove the second instance of this SCB from
2335 * the QINFIFO if it is still there.
2337 ahd_print_path(ahd
, scb
);
2338 printk("SCB completes before TMF\n");
2340 * Handle losing the race. Wait until any
2341 * current selection completes. We will then
2342 * set the TMF back to zero in this SCB so that
2343 * the sequencer doesn't bother to issue another
2344 * sequencer interrupt for its completion.
2346 while ((ahd_inb(ahd
, SCSISEQ0
) & ENSELO
) != 0
2347 && (ahd_inb(ahd
, SSTAT0
) & SELDO
) == 0
2348 && (ahd_inb(ahd
, SSTAT1
) & SELTO
) == 0)
2350 ahd_outb(ahd
, SCB_TASK_MANAGEMENT
, 0);
2351 ahd_search_qinfifo(ahd
, SCB_GET_TARGET(ahd
, scb
),
2352 SCB_GET_CHANNEL(ahd
, scb
),
2353 SCB_GET_LUN(scb
), SCB_GET_TAG(scb
),
2354 ROLE_INITIATOR
, /*status*/0,
2363 printk("%s: Tracepoint %d\n", ahd_name(ahd
),
2364 seqintcode
- TRACEPOINT0
);
2369 ahd_handle_hwerrint(ahd
);
2372 printk("%s: Unexpected SEQINTCODE %d\n", ahd_name(ahd
),
2377 * The sequencer is paused immediately on
2378 * a SEQINT, so we should restart it when
2385 ahd_handle_scsiint(struct ahd_softc
*ahd
, u_int intstat
)
2396 ahd_update_modes(ahd
);
2397 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
2399 status3
= ahd_inb(ahd
, SSTAT3
) & (NTRAMPERR
|OSRAMPERR
);
2400 status0
= ahd_inb(ahd
, SSTAT0
) & (IOERR
|OVERRUN
|SELDI
|SELDO
);
2401 status
= ahd_inb(ahd
, SSTAT1
) & (SELTO
|SCSIRSTI
|BUSFREE
|SCSIPERR
);
2402 lqistat1
= ahd_inb(ahd
, LQISTAT1
);
2403 lqostat0
= ahd_inb(ahd
, LQOSTAT0
);
2404 busfreetime
= ahd_inb(ahd
, SSTAT2
) & BUSFREETIME
;
2407 * Ignore external resets after a bus reset.
2409 if (((status
& SCSIRSTI
) != 0) && (ahd
->flags
& AHD_BUS_RESET_ACTIVE
)) {
2410 ahd_outb(ahd
, CLRSINT1
, CLRSCSIRSTI
);
2415 * Clear bus reset flag
2417 ahd
->flags
&= ~AHD_BUS_RESET_ACTIVE
;
2419 if ((status0
& (SELDI
|SELDO
)) != 0) {
2422 ahd_set_modes(ahd
, AHD_MODE_CFG
, AHD_MODE_CFG
);
2423 simode0
= ahd_inb(ahd
, SIMODE0
);
2424 status0
&= simode0
& (IOERR
|OVERRUN
|SELDI
|SELDO
);
2425 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
2427 scbid
= ahd_get_scbptr(ahd
);
2428 scb
= ahd_lookup_scb(ahd
, scbid
);
2430 && (ahd_inb(ahd
, SEQ_FLAGS
) & NOT_IDENTIFIED
) != 0)
2433 if ((status0
& IOERR
) != 0) {
2436 now_lvd
= ahd_inb(ahd
, SBLKCTL
) & ENAB40
;
2437 printk("%s: Transceiver State Has Changed to %s mode\n",
2438 ahd_name(ahd
), now_lvd
? "LVD" : "SE");
2439 ahd_outb(ahd
, CLRSINT0
, CLRIOERR
);
2441 * A change in I/O mode is equivalent to a bus reset.
2443 ahd_reset_channel(ahd
, 'A', /*Initiate Reset*/TRUE
);
2445 ahd_setup_iocell_workaround(ahd
);
2447 } else if ((status0
& OVERRUN
) != 0) {
2449 printk("%s: SCSI offset overrun detected. Resetting bus.\n",
2451 ahd_reset_channel(ahd
, 'A', /*Initiate Reset*/TRUE
);
2452 } else if ((status
& SCSIRSTI
) != 0) {
2454 printk("%s: Someone reset channel A\n", ahd_name(ahd
));
2455 ahd_reset_channel(ahd
, 'A', /*Initiate Reset*/FALSE
);
2456 } else if ((status
& SCSIPERR
) != 0) {
2458 /* Make sure the sequencer is in a safe location. */
2459 ahd_clear_critical_section(ahd
);
2461 ahd_handle_transmission_error(ahd
);
2462 } else if (lqostat0
!= 0) {
2464 printk("%s: lqostat0 == 0x%x!\n", ahd_name(ahd
), lqostat0
);
2465 ahd_outb(ahd
, CLRLQOINT0
, lqostat0
);
2466 if ((ahd
->bugs
& AHD_CLRLQO_AUTOCLR_BUG
) != 0)
2467 ahd_outb(ahd
, CLRLQOINT1
, 0);
2468 } else if ((status
& SELTO
) != 0) {
2469 /* Stop the selection */
2470 ahd_outb(ahd
, SCSISEQ0
, 0);
2472 /* Make sure the sequencer is in a safe location. */
2473 ahd_clear_critical_section(ahd
);
2475 /* No more pending messages */
2476 ahd_clear_msg_state(ahd
);
2478 /* Clear interrupt state */
2479 ahd_outb(ahd
, CLRSINT1
, CLRSELTIMEO
|CLRBUSFREE
|CLRSCSIPERR
);
2482 * Although the driver does not care about the
2483 * 'Selection in Progress' status bit, the busy
2484 * LED does. SELINGO is only cleared by a successful
2485 * selection, so we must manually clear it to insure
2486 * the LED turns off just incase no future successful
2487 * selections occur (e.g. no devices on the bus).
2489 ahd_outb(ahd
, CLRSINT0
, CLRSELINGO
);
2491 scbid
= ahd_inw(ahd
, WAITING_TID_HEAD
);
2492 scb
= ahd_lookup_scb(ahd
, scbid
);
2494 printk("%s: ahd_intr - referenced scb not "
2495 "valid during SELTO scb(0x%x)\n",
2496 ahd_name(ahd
), scbid
);
2497 ahd_dump_card_state(ahd
);
2499 struct ahd_devinfo devinfo
;
2501 if ((ahd_debug
& AHD_SHOW_SELTO
) != 0) {
2502 ahd_print_path(ahd
, scb
);
2503 printk("Saw Selection Timeout for SCB 0x%x\n",
2507 ahd_scb_devinfo(ahd
, &devinfo
, scb
);
2508 ahd_set_transaction_status(scb
, CAM_SEL_TIMEOUT
);
2509 ahd_freeze_devq(ahd
, scb
);
2512 * Cancel any pending transactions on the device
2513 * now that it seems to be missing. This will
2514 * also revert us to async/narrow transfers until
2515 * we can renegotiate with the device.
2517 ahd_handle_devreset(ahd
, &devinfo
,
2520 "Selection Timeout",
2521 /*verbose_level*/1);
2523 ahd_outb(ahd
, CLRINT
, CLRSCSIINT
);
2524 ahd_iocell_first_selection(ahd
);
2526 } else if ((status0
& (SELDI
|SELDO
)) != 0) {
2528 ahd_iocell_first_selection(ahd
);
2530 } else if (status3
!= 0) {
2531 printk("%s: SCSI Cell parity error SSTAT3 == 0x%x\n",
2532 ahd_name(ahd
), status3
);
2533 ahd_outb(ahd
, CLRSINT3
, status3
);
2534 } else if ((lqistat1
& (LQIPHASE_LQ
|LQIPHASE_NLQ
)) != 0) {
2536 /* Make sure the sequencer is in a safe location. */
2537 ahd_clear_critical_section(ahd
);
2539 ahd_handle_lqiphase_error(ahd
, lqistat1
);
2540 } else if ((lqistat1
& LQICRCI_NLQ
) != 0) {
2542 * This status can be delayed during some
2543 * streaming operations. The SCSIPHASE
2544 * handler has already dealt with this case
2545 * so just clear the error.
2547 ahd_outb(ahd
, CLRLQIINT1
, CLRLQICRCI_NLQ
);
2548 } else if ((status
& BUSFREE
) != 0
2549 || (lqistat1
& LQOBUSFREE
) != 0) {
2557 * Clear our selection hardware as soon as possible.
2558 * We may have an entry in the waiting Q for this target,
2559 * that is affected by this busfree and we don't want to
2560 * go about selecting the target while we handle the event.
2562 ahd_outb(ahd
, SCSISEQ0
, 0);
2564 /* Make sure the sequencer is in a safe location. */
2565 ahd_clear_critical_section(ahd
);
2568 * Determine what we were up to at the time of
2571 mode
= AHD_MODE_SCSI
;
2572 busfreetime
= ahd_inb(ahd
, SSTAT2
) & BUSFREETIME
;
2573 lqostat1
= ahd_inb(ahd
, LQOSTAT1
);
2574 switch (busfreetime
) {
2578 mode
= busfreetime
== BUSFREE_DFF0
2579 ? AHD_MODE_DFF0
: AHD_MODE_DFF1
;
2580 ahd_set_modes(ahd
, mode
, mode
);
2581 scbid
= ahd_get_scbptr(ahd
);
2582 scb
= ahd_lookup_scb(ahd
, scbid
);
2584 printk("%s: Invalid SCB %d in DFF%d "
2585 "during unexpected busfree\n",
2586 ahd_name(ahd
), scbid
, mode
);
2589 packetized
= (scb
->flags
& SCB_PACKETIZED
) != 0;
2599 packetized
= (lqostat1
& LQOBUSFREE
) != 0;
2601 && ahd_inb(ahd
, LASTPHASE
) == P_BUSFREE
2602 && (ahd_inb(ahd
, SSTAT0
) & SELDI
) == 0
2603 && ((ahd_inb(ahd
, SSTAT0
) & SELDO
) == 0
2604 || (ahd_inb(ahd
, SCSISEQ0
) & ENSELO
) == 0))
2606 * Assume packetized if we are not
2607 * on the bus in a non-packetized
2608 * capacity and any pending selection
2609 * was a packetized selection.
2616 if ((ahd_debug
& AHD_SHOW_MISC
) != 0)
2617 printk("Saw Busfree. Busfreetime = 0x%x.\n",
2621 * Busfrees that occur in non-packetized phases are
2622 * handled by the nonpkt_busfree handler.
2624 if (packetized
&& ahd_inb(ahd
, LASTPHASE
) == P_BUSFREE
) {
2625 restart
= ahd_handle_pkt_busfree(ahd
, busfreetime
);
2628 restart
= ahd_handle_nonpkt_busfree(ahd
);
2631 * Clear the busfree interrupt status. The setting of
2632 * the interrupt is a pulse, so in a perfect world, we
2633 * would not need to muck with the ENBUSFREE logic. This
2634 * would ensure that if the bus moves on to another
2635 * connection, busfree protection is still in force. If
2636 * BUSFREEREV is broken, however, we must manually clear
2637 * the ENBUSFREE if the busfree occurred during a non-pack
2638 * connection so that we don't get false positives during
2639 * future, packetized, connections.
2641 ahd_outb(ahd
, CLRSINT1
, CLRBUSFREE
);
2643 && (ahd
->bugs
& AHD_BUSFREEREV_BUG
) != 0)
2644 ahd_outb(ahd
, SIMODE1
,
2645 ahd_inb(ahd
, SIMODE1
) & ~ENBUSFREE
);
2648 ahd_clear_fifo(ahd
, mode
);
2650 ahd_clear_msg_state(ahd
);
2651 ahd_outb(ahd
, CLRINT
, CLRSCSIINT
);
2658 printk("%s: Missing case in ahd_handle_scsiint. status = %x\n",
2659 ahd_name(ahd
), status
);
2660 ahd_dump_card_state(ahd
);
2661 ahd_clear_intstat(ahd
);
2667 ahd_handle_transmission_error(struct ahd_softc
*ahd
)
2681 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
2682 lqistat1
= ahd_inb(ahd
, LQISTAT1
) & ~(LQIPHASE_LQ
|LQIPHASE_NLQ
);
2683 lqistat2
= ahd_inb(ahd
, LQISTAT2
);
2684 if ((lqistat1
& (LQICRCI_NLQ
|LQICRCI_LQ
)) == 0
2685 && (ahd
->bugs
& AHD_NLQICRC_DELAYED_BUG
) != 0) {
2688 ahd_set_modes(ahd
, AHD_MODE_CFG
, AHD_MODE_CFG
);
2689 lqistate
= ahd_inb(ahd
, LQISTATE
);
2690 if ((lqistate
>= 0x1E && lqistate
<= 0x24)
2691 || (lqistate
== 0x29)) {
2693 if ((ahd_debug
& AHD_SHOW_RECOVERY
) != 0) {
2694 printk("%s: NLQCRC found via LQISTATE\n",
2698 lqistat1
|= LQICRCI_NLQ
;
2700 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
2703 ahd_outb(ahd
, CLRLQIINT1
, lqistat1
);
2704 lastphase
= ahd_inb(ahd
, LASTPHASE
);
2705 curphase
= ahd_inb(ahd
, SCSISIGI
) & PHASE_MASK
;
2706 perrdiag
= ahd_inb(ahd
, PERRDIAG
);
2707 msg_out
= MSG_INITIATOR_DET_ERR
;
2708 ahd_outb(ahd
, CLRSINT1
, CLRSCSIPERR
);
2711 * Try to find the SCB associated with this error.
2715 || (lqistat1
& LQICRCI_NLQ
) != 0) {
2716 if ((lqistat1
& (LQICRCI_NLQ
|LQIOVERI_NLQ
)) != 0)
2717 ahd_set_active_fifo(ahd
);
2718 scbid
= ahd_get_scbptr(ahd
);
2719 scb
= ahd_lookup_scb(ahd
, scbid
);
2720 if (scb
!= NULL
&& SCB_IS_SILENT(scb
))
2725 if (silent
== FALSE
) {
2726 printk("%s: Transmission error detected\n", ahd_name(ahd
));
2727 ahd_lqistat1_print(lqistat1
, &cur_col
, 50);
2728 ahd_lastphase_print(lastphase
, &cur_col
, 50);
2729 ahd_scsisigi_print(curphase
, &cur_col
, 50);
2730 ahd_perrdiag_print(perrdiag
, &cur_col
, 50);
2732 ahd_dump_card_state(ahd
);
2735 if ((lqistat1
& (LQIOVERI_LQ
|LQIOVERI_NLQ
)) != 0) {
2736 if (silent
== FALSE
) {
2737 printk("%s: Gross protocol error during incoming "
2738 "packet. lqistat1 == 0x%x. Resetting bus.\n",
2739 ahd_name(ahd
), lqistat1
);
2741 ahd_reset_channel(ahd
, 'A', /*Initiate Reset*/TRUE
);
2743 } else if ((lqistat1
& LQICRCI_LQ
) != 0) {
2745 * A CRC error has been detected on an incoming LQ.
2746 * The bus is currently hung on the last ACK.
2747 * Hit LQIRETRY to release the last ack, and
2748 * wait for the sequencer to determine that ATNO
2749 * is asserted while in message out to take us
2750 * to our host message loop. No NONPACKREQ or
2751 * LQIPHASE type errors will occur in this
2752 * scenario. After this first LQIRETRY, the LQI
2753 * manager will be in ISELO where it will
2754 * happily sit until another packet phase begins.
2755 * Unexpected bus free detection is enabled
2756 * through any phases that occur after we release
2757 * this last ack until the LQI manager sees a
2758 * packet phase. This implies we may have to
2759 * ignore a perfectly valid "unexected busfree"
2760 * after our "initiator detected error" message is
2761 * sent. A busfree is the expected response after
2762 * we tell the target that it's L_Q was corrupted.
2763 * (SPI4R09 10.7.3.3.3)
2765 ahd_outb(ahd
, LQCTL2
, LQIRETRY
);
2766 printk("LQIRetry for LQICRCI_LQ to release ACK\n");
2767 } else if ((lqistat1
& LQICRCI_NLQ
) != 0) {
2769 * We detected a CRC error in a NON-LQ packet.
2770 * The hardware has varying behavior in this situation
2771 * depending on whether this packet was part of a
2775 * The hardware has already acked the complete packet.
2776 * If the target honors our outstanding ATN condition,
2777 * we should be (or soon will be) in MSGOUT phase.
2778 * This will trigger the LQIPHASE_LQ status bit as the
2779 * hardware was expecting another LQ. Unexpected
2780 * busfree detection is enabled. Once LQIPHASE_LQ is
2781 * true (first entry into host message loop is much
2782 * the same), we must clear LQIPHASE_LQ and hit
2783 * LQIRETRY so the hardware is ready to handle
2784 * a future LQ. NONPACKREQ will not be asserted again
2785 * once we hit LQIRETRY until another packet is
2786 * processed. The target may either go busfree
2787 * or start another packet in response to our message.
2789 * Read Streaming P0 asserted:
2790 * If we raise ATN and the target completes the entire
2791 * stream (P0 asserted during the last packet), the
2792 * hardware will ack all data and return to the ISTART
2793 * state. When the target reponds to our ATN condition,
2794 * LQIPHASE_LQ will be asserted. We should respond to
2795 * this with an LQIRETRY to prepare for any future
2796 * packets. NONPACKREQ will not be asserted again
2797 * once we hit LQIRETRY until another packet is
2798 * processed. The target may either go busfree or
2799 * start another packet in response to our message.
2800 * Busfree detection is enabled.
2802 * Read Streaming P0 not asserted:
2803 * If we raise ATN and the target transitions to
2804 * MSGOUT in or after a packet where P0 is not
2805 * asserted, the hardware will assert LQIPHASE_NLQ.
2806 * We should respond to the LQIPHASE_NLQ with an
2807 * LQIRETRY. Should the target stay in a non-pkt
2808 * phase after we send our message, the hardware
2809 * will assert LQIPHASE_LQ. Recovery is then just as
2810 * listed above for the read streaming with P0 asserted.
2811 * Busfree detection is enabled.
2813 if (silent
== FALSE
)
2814 printk("LQICRC_NLQ\n");
2816 printk("%s: No SCB valid for LQICRC_NLQ. "
2817 "Resetting bus\n", ahd_name(ahd
));
2818 ahd_reset_channel(ahd
, 'A', /*Initiate Reset*/TRUE
);
2821 } else if ((lqistat1
& LQIBADLQI
) != 0) {
2822 printk("Need to handle BADLQI!\n");
2823 ahd_reset_channel(ahd
, 'A', /*Initiate Reset*/TRUE
);
2825 } else if ((perrdiag
& (PARITYERR
|PREVPHASE
)) == PARITYERR
) {
2826 if ((curphase
& ~P_DATAIN_DT
) != 0) {
2827 /* Ack the byte. So we can continue. */
2828 if (silent
== FALSE
)
2829 printk("Acking %s to clear perror\n",
2830 ahd_lookup_phase_entry(curphase
)->phasemsg
);
2831 ahd_inb(ahd
, SCSIDAT
);
2834 if (curphase
== P_MESGIN
)
2835 msg_out
= MSG_PARITY_ERROR
;
2839 * We've set the hardware to assert ATN if we
2840 * get a parity error on "in" phases, so all we
2841 * need to do is stuff the message buffer with
2842 * the appropriate message. "In" phases have set
2843 * mesg_out to something other than MSG_NOP.
2845 ahd
->send_msg_perror
= msg_out
;
2846 if (scb
!= NULL
&& msg_out
== MSG_INITIATOR_DET_ERR
)
2847 scb
->flags
|= SCB_TRANSMISSION_ERROR
;
2848 ahd_outb(ahd
, MSG_OUT
, HOST_MSG
);
2849 ahd_outb(ahd
, CLRINT
, CLRSCSIINT
);
2854 ahd_handle_lqiphase_error(struct ahd_softc
*ahd
, u_int lqistat1
)
2857 * Clear the sources of the interrupts.
2859 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
2860 ahd_outb(ahd
, CLRLQIINT1
, lqistat1
);
2863 * If the "illegal" phase changes were in response
2864 * to our ATN to flag a CRC error, AND we ended up
2865 * on packet boundaries, clear the error, restart the
2866 * LQI manager as appropriate, and go on our merry
2867 * way toward sending the message. Otherwise, reset
2868 * the bus to clear the error.
2870 ahd_set_active_fifo(ahd
);
2871 if ((ahd_inb(ahd
, SCSISIGO
) & ATNO
) != 0
2872 && (ahd_inb(ahd
, MDFFSTAT
) & DLZERO
) != 0) {
2873 if ((lqistat1
& LQIPHASE_LQ
) != 0) {
2874 printk("LQIRETRY for LQIPHASE_LQ\n");
2875 ahd_outb(ahd
, LQCTL2
, LQIRETRY
);
2876 } else if ((lqistat1
& LQIPHASE_NLQ
) != 0) {
2877 printk("LQIRETRY for LQIPHASE_NLQ\n");
2878 ahd_outb(ahd
, LQCTL2
, LQIRETRY
);
2880 panic("ahd_handle_lqiphase_error: No phase errors\n");
2881 ahd_dump_card_state(ahd
);
2882 ahd_outb(ahd
, CLRINT
, CLRSCSIINT
);
2885 printk("Resetting Channel for LQI Phase error\n");
2886 ahd_dump_card_state(ahd
);
2887 ahd_reset_channel(ahd
, 'A', /*Initiate Reset*/TRUE
);
2892 * Packetized unexpected or expected busfree.
2893 * Entered in mode based on busfreetime.
2896 ahd_handle_pkt_busfree(struct ahd_softc
*ahd
, u_int busfreetime
)
2900 AHD_ASSERT_MODES(ahd
, ~(AHD_MODE_UNKNOWN_MSK
|AHD_MODE_CFG_MSK
),
2901 ~(AHD_MODE_UNKNOWN_MSK
|AHD_MODE_CFG_MSK
));
2902 lqostat1
= ahd_inb(ahd
, LQOSTAT1
);
2903 if ((lqostat1
& LQOBUSFREE
) != 0) {
2912 * The LQO manager detected an unexpected busfree
2915 * 1) During an outgoing LQ.
2916 * 2) After an outgoing LQ but before the first
2917 * REQ of the command packet.
2918 * 3) During an outgoing command packet.
2920 * In all cases, CURRSCB is pointing to the
2921 * SCB that encountered the failure. Clean
2922 * up the queue, clear SELDO and LQOBUSFREE,
2923 * and allow the sequencer to restart the select
2924 * out at its lesure.
2926 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
2927 scbid
= ahd_inw(ahd
, CURRSCB
);
2928 scb
= ahd_lookup_scb(ahd
, scbid
);
2930 panic("SCB not valid during LQOBUSFREE");
2934 ahd_outb(ahd
, CLRLQOINT1
, CLRLQOBUSFREE
);
2935 if ((ahd
->bugs
& AHD_CLRLQO_AUTOCLR_BUG
) != 0)
2936 ahd_outb(ahd
, CLRLQOINT1
, 0);
2937 ahd_outb(ahd
, SCSISEQ0
, ahd_inb(ahd
, SCSISEQ0
) & ~ENSELO
);
2938 ahd_flush_device_writes(ahd
);
2939 ahd_outb(ahd
, CLRSINT0
, CLRSELDO
);
2942 * Return the LQO manager to its idle loop. It will
2943 * not do this automatically if the busfree occurs
2944 * after the first REQ of either the LQ or command
2945 * packet or between the LQ and command packet.
2947 ahd_outb(ahd
, LQCTL2
, ahd_inb(ahd
, LQCTL2
) | LQOTOIDLE
);
2950 * Update the waiting for selection queue so
2951 * we restart on the correct SCB.
2953 waiting_h
= ahd_inw(ahd
, WAITING_TID_HEAD
);
2954 saved_scbptr
= ahd_get_scbptr(ahd
);
2955 if (waiting_h
!= scbid
) {
2957 ahd_outw(ahd
, WAITING_TID_HEAD
, scbid
);
2958 waiting_t
= ahd_inw(ahd
, WAITING_TID_TAIL
);
2959 if (waiting_t
== waiting_h
) {
2960 ahd_outw(ahd
, WAITING_TID_TAIL
, scbid
);
2961 next
= SCB_LIST_NULL
;
2963 ahd_set_scbptr(ahd
, waiting_h
);
2964 next
= ahd_inw_scbram(ahd
, SCB_NEXT2
);
2966 ahd_set_scbptr(ahd
, scbid
);
2967 ahd_outw(ahd
, SCB_NEXT2
, next
);
2969 ahd_set_scbptr(ahd
, saved_scbptr
);
2970 if (scb
->crc_retry_count
< AHD_MAX_LQ_CRC_ERRORS
) {
2971 if (SCB_IS_SILENT(scb
) == FALSE
) {
2972 ahd_print_path(ahd
, scb
);
2973 printk("Probable outgoing LQ CRC error. "
2974 "Retrying command\n");
2976 scb
->crc_retry_count
++;
2978 ahd_set_transaction_status(scb
, CAM_UNCOR_PARITY
);
2979 ahd_freeze_scb(scb
);
2980 ahd_freeze_devq(ahd
, scb
);
2982 /* Return unpausing the sequencer. */
2984 } else if ((ahd_inb(ahd
, PERRDIAG
) & PARITYERR
) != 0) {
2986 * Ignore what are really parity errors that
2987 * occur on the last REQ of a free running
2988 * clock prior to going busfree. Some drives
2989 * do not properly active negate just before
2990 * going busfree resulting in a parity glitch.
2992 ahd_outb(ahd
, CLRSINT1
, CLRSCSIPERR
|CLRBUSFREE
);
2994 if ((ahd_debug
& AHD_SHOW_MASKED_ERRORS
) != 0)
2995 printk("%s: Parity on last REQ detected "
2996 "during busfree phase.\n",
2999 /* Return unpausing the sequencer. */
3002 if (ahd
->src_mode
!= AHD_MODE_SCSI
) {
3006 scbid
= ahd_get_scbptr(ahd
);
3007 scb
= ahd_lookup_scb(ahd
, scbid
);
3008 ahd_print_path(ahd
, scb
);
3009 printk("Unexpected PKT busfree condition\n");
3010 ahd_dump_card_state(ahd
);
3011 ahd_abort_scbs(ahd
, SCB_GET_TARGET(ahd
, scb
), 'A',
3012 SCB_GET_LUN(scb
), SCB_GET_TAG(scb
),
3013 ROLE_INITIATOR
, CAM_UNEXP_BUSFREE
);
3015 /* Return restarting the sequencer. */
3018 printk("%s: Unexpected PKT busfree condition\n", ahd_name(ahd
));
3019 ahd_dump_card_state(ahd
);
3020 /* Restart the sequencer. */
3025 * Non-packetized unexpected or expected busfree.
3028 ahd_handle_nonpkt_busfree(struct ahd_softc
*ahd
)
3030 struct ahd_devinfo devinfo
;
3036 u_int initiator_role_id
;
3042 * Look at what phase we were last in. If its message out,
3043 * chances are pretty good that the busfree was in response
3044 * to one of our abort requests.
3046 lastphase
= ahd_inb(ahd
, LASTPHASE
);
3047 saved_scsiid
= ahd_inb(ahd
, SAVED_SCSIID
);
3048 saved_lun
= ahd_inb(ahd
, SAVED_LUN
);
3049 target
= SCSIID_TARGET(ahd
, saved_scsiid
);
3050 initiator_role_id
= SCSIID_OUR_ID(saved_scsiid
);
3051 ahd_compile_devinfo(&devinfo
, initiator_role_id
,
3052 target
, saved_lun
, 'A', ROLE_INITIATOR
);
3055 scbid
= ahd_get_scbptr(ahd
);
3056 scb
= ahd_lookup_scb(ahd
, scbid
);
3058 && (ahd_inb(ahd
, SEQ_FLAGS
) & NOT_IDENTIFIED
) != 0)
3061 ppr_busfree
= (ahd
->msg_flags
& MSG_FLAG_EXPECT_PPR_BUSFREE
) != 0;
3062 if (lastphase
== P_MESGOUT
) {
3065 tag
= SCB_LIST_NULL
;
3066 if (ahd_sent_msg(ahd
, AHDMSG_1B
, MSG_ABORT_TAG
, TRUE
)
3067 || ahd_sent_msg(ahd
, AHDMSG_1B
, MSG_ABORT
, TRUE
)) {
3072 ahd_print_devinfo(ahd
, &devinfo
);
3073 printk("Abort for unidentified "
3074 "connection completed.\n");
3075 /* restart the sequencer. */
3078 sent_msg
= ahd
->msgout_buf
[ahd
->msgout_index
- 1];
3079 ahd_print_path(ahd
, scb
);
3080 printk("SCB %d - Abort%s Completed.\n",
3082 sent_msg
== MSG_ABORT_TAG
? "" : " Tag");
3084 if (sent_msg
== MSG_ABORT_TAG
)
3085 tag
= SCB_GET_TAG(scb
);
3087 if ((scb
->flags
& SCB_EXTERNAL_RESET
) != 0) {
3089 * This abort is in response to an
3090 * unexpected switch to command phase
3091 * for a packetized connection. Since
3092 * the identify message was never sent,
3093 * "saved lun" is 0. We really want to
3094 * abort only the SCB that encountered
3095 * this error, which could have a different
3096 * lun. The SCB will be retried so the OS
3097 * will see the UA after renegotiating to
3100 tag
= SCB_GET_TAG(scb
);
3101 saved_lun
= scb
->hscb
->lun
;
3103 found
= ahd_abort_scbs(ahd
, target
, 'A', saved_lun
,
3104 tag
, ROLE_INITIATOR
,
3106 printk("found == 0x%x\n", found
);
3108 } else if (ahd_sent_msg(ahd
, AHDMSG_1B
,
3109 MSG_BUS_DEV_RESET
, TRUE
)) {
3110 ahd_handle_devreset(ahd
, &devinfo
, CAM_LUN_WILDCARD
,
3111 CAM_BDR_SENT
, "Bus Device Reset",
3112 /*verbose_level*/0);
3114 } else if (ahd_sent_msg(ahd
, AHDMSG_EXT
, MSG_EXT_PPR
, FALSE
)
3115 && ppr_busfree
== 0) {
3116 struct ahd_initiator_tinfo
*tinfo
;
3117 struct ahd_tmode_tstate
*tstate
;
3122 * If the previous negotiation was packetized,
3123 * this could be because the device has been
3124 * reset without our knowledge. Force our
3125 * current negotiation to async and retry the
3126 * negotiation. Otherwise retry the command
3127 * with non-ppr negotiation.
3130 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
3131 printk("PPR negotiation rejected busfree.\n");
3133 tinfo
= ahd_fetch_transinfo(ahd
, devinfo
.channel
,
3135 devinfo
.target
, &tstate
);
3136 if ((tinfo
->curr
.ppr_options
& MSG_EXT_PPR_IU_REQ
)!=0) {
3137 ahd_set_width(ahd
, &devinfo
,
3138 MSG_EXT_WDTR_BUS_8_BIT
,
3141 ahd_set_syncrate(ahd
, &devinfo
,
3142 /*period*/0, /*offset*/0,
3147 * The expect PPR busfree handler below
3148 * will effect the retry and necessary
3152 tinfo
->curr
.transport_version
= 2;
3153 tinfo
->goal
.transport_version
= 2;
3154 tinfo
->goal
.ppr_options
= 0;
3157 * Remove any SCBs in the waiting
3158 * for selection queue that may
3159 * also be for this target so that
3160 * command ordering is preserved.
3162 ahd_freeze_devq(ahd
, scb
);
3163 ahd_qinfifo_requeue_tail(ahd
, scb
);
3167 } else if (ahd_sent_msg(ahd
, AHDMSG_EXT
, MSG_EXT_WDTR
, FALSE
)
3168 && ppr_busfree
== 0) {
3170 * Negotiation Rejected. Go-narrow and
3174 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
3175 printk("WDTR negotiation rejected busfree.\n");
3177 ahd_set_width(ahd
, &devinfo
,
3178 MSG_EXT_WDTR_BUS_8_BIT
,
3179 AHD_TRANS_CUR
|AHD_TRANS_GOAL
,
3183 * Remove any SCBs in the waiting for
3184 * selection queue that may also be for
3185 * this target so that command ordering
3188 ahd_freeze_devq(ahd
, scb
);
3189 ahd_qinfifo_requeue_tail(ahd
, scb
);
3192 } else if (ahd_sent_msg(ahd
, AHDMSG_EXT
, MSG_EXT_SDTR
, FALSE
)
3193 && ppr_busfree
== 0) {
3195 * Negotiation Rejected. Go-async and
3199 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
3200 printk("SDTR negotiation rejected busfree.\n");
3202 ahd_set_syncrate(ahd
, &devinfo
,
3203 /*period*/0, /*offset*/0,
3205 AHD_TRANS_CUR
|AHD_TRANS_GOAL
,
3209 * Remove any SCBs in the waiting for
3210 * selection queue that may also be for
3211 * this target so that command ordering
3214 ahd_freeze_devq(ahd
, scb
);
3215 ahd_qinfifo_requeue_tail(ahd
, scb
);
3218 } else if ((ahd
->msg_flags
& MSG_FLAG_EXPECT_IDE_BUSFREE
) != 0
3219 && ahd_sent_msg(ahd
, AHDMSG_1B
,
3220 MSG_INITIATOR_DET_ERR
, TRUE
)) {
3223 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
3224 printk("Expected IDE Busfree\n");
3227 } else if ((ahd
->msg_flags
& MSG_FLAG_EXPECT_QASREJ_BUSFREE
)
3228 && ahd_sent_msg(ahd
, AHDMSG_1B
,
3229 MSG_MESSAGE_REJECT
, TRUE
)) {
3232 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
3233 printk("Expected QAS Reject Busfree\n");
3240 * The busfree required flag is honored at the end of
3241 * the message phases. We check it last in case we
3242 * had to send some other message that caused a busfree.
3244 if (scb
!= NULL
&& printerror
!= 0
3245 && (lastphase
== P_MESGIN
|| lastphase
== P_MESGOUT
)
3246 && ((ahd
->msg_flags
& MSG_FLAG_EXPECT_PPR_BUSFREE
) != 0)) {
3248 ahd_freeze_devq(ahd
, scb
);
3249 ahd_set_transaction_status(scb
, CAM_REQUEUE_REQ
);
3250 ahd_freeze_scb(scb
);
3251 if ((ahd
->msg_flags
& MSG_FLAG_IU_REQ_CHANGED
) != 0) {
3252 ahd_abort_scbs(ahd
, SCB_GET_TARGET(ahd
, scb
),
3253 SCB_GET_CHANNEL(ahd
, scb
),
3254 SCB_GET_LUN(scb
), SCB_LIST_NULL
,
3255 ROLE_INITIATOR
, CAM_REQ_ABORTED
);
3258 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
3259 printk("PPR Negotiation Busfree.\n");
3265 if (printerror
!= 0) {
3272 if ((scb
->hscb
->control
& TAG_ENB
) != 0)
3273 tag
= SCB_GET_TAG(scb
);
3275 tag
= SCB_LIST_NULL
;
3276 ahd_print_path(ahd
, scb
);
3277 aborted
= ahd_abort_scbs(ahd
, target
, 'A',
3278 SCB_GET_LUN(scb
), tag
,
3283 * We had not fully identified this connection,
3284 * so we cannot abort anything.
3286 printk("%s: ", ahd_name(ahd
));
3288 printk("Unexpected busfree %s, %d SCBs aborted, "
3289 "PRGMCNT == 0x%x\n",
3290 ahd_lookup_phase_entry(lastphase
)->phasemsg
,
3292 ahd_inw(ahd
, PRGMCNT
));
3293 ahd_dump_card_state(ahd
);
3294 if (lastphase
!= P_BUSFREE
)
3295 ahd_force_renegotiation(ahd
, &devinfo
);
3297 /* Always restart the sequencer. */
3302 ahd_handle_proto_violation(struct ahd_softc
*ahd
)
3304 struct ahd_devinfo devinfo
;
3312 ahd_fetch_devinfo(ahd
, &devinfo
);
3313 scbid
= ahd_get_scbptr(ahd
);
3314 scb
= ahd_lookup_scb(ahd
, scbid
);
3315 seq_flags
= ahd_inb(ahd
, SEQ_FLAGS
);
3316 curphase
= ahd_inb(ahd
, SCSISIGI
) & PHASE_MASK
;
3317 lastphase
= ahd_inb(ahd
, LASTPHASE
);
3318 if ((seq_flags
& NOT_IDENTIFIED
) != 0) {
3321 * The reconnecting target either did not send an
3322 * identify message, or did, but we didn't find an SCB
3325 ahd_print_devinfo(ahd
, &devinfo
);
3326 printk("Target did not send an IDENTIFY message. "
3327 "LASTPHASE = 0x%x.\n", lastphase
);
3329 } else if (scb
== NULL
) {
3331 * We don't seem to have an SCB active for this
3332 * transaction. Print an error and reset the bus.
3334 ahd_print_devinfo(ahd
, &devinfo
);
3335 printk("No SCB found during protocol violation\n");
3336 goto proto_violation_reset
;
3338 ahd_set_transaction_status(scb
, CAM_SEQUENCE_FAIL
);
3339 if ((seq_flags
& NO_CDB_SENT
) != 0) {
3340 ahd_print_path(ahd
, scb
);
3341 printk("No or incomplete CDB sent to device.\n");
3342 } else if ((ahd_inb_scbram(ahd
, SCB_CONTROL
)
3343 & STATUS_RCVD
) == 0) {
3345 * The target never bothered to provide status to
3346 * us prior to completing the command. Since we don't
3347 * know the disposition of this command, we must attempt
3348 * to abort it. Assert ATN and prepare to send an abort
3351 ahd_print_path(ahd
, scb
);
3352 printk("Completed command without status.\n");
3354 ahd_print_path(ahd
, scb
);
3355 printk("Unknown protocol violation.\n");
3356 ahd_dump_card_state(ahd
);
3359 if ((lastphase
& ~P_DATAIN_DT
) == 0
3360 || lastphase
== P_COMMAND
) {
3361 proto_violation_reset
:
3363 * Target either went directly to data
3364 * phase or didn't respond to our ATN.
3365 * The only safe thing to do is to blow
3366 * it away with a bus reset.
3368 found
= ahd_reset_channel(ahd
, 'A', TRUE
);
3369 printk("%s: Issued Channel %c Bus Reset. "
3370 "%d SCBs aborted\n", ahd_name(ahd
), 'A', found
);
3373 * Leave the selection hardware off in case
3374 * this abort attempt will affect yet to
3377 ahd_outb(ahd
, SCSISEQ0
,
3378 ahd_inb(ahd
, SCSISEQ0
) & ~ENSELO
);
3379 ahd_assert_atn(ahd
);
3380 ahd_outb(ahd
, MSG_OUT
, HOST_MSG
);
3382 ahd_print_devinfo(ahd
, &devinfo
);
3383 ahd
->msgout_buf
[0] = MSG_ABORT_TASK
;
3384 ahd
->msgout_len
= 1;
3385 ahd
->msgout_index
= 0;
3386 ahd
->msg_type
= MSG_TYPE_INITIATOR_MSGOUT
;
3388 ahd_print_path(ahd
, scb
);
3389 scb
->flags
|= SCB_ABORT
;
3391 printk("Protocol violation %s. Attempting to abort.\n",
3392 ahd_lookup_phase_entry(curphase
)->phasemsg
);
3397 * Force renegotiation to occur the next time we initiate
3398 * a command to the current device.
3401 ahd_force_renegotiation(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
)
3403 struct ahd_initiator_tinfo
*targ_info
;
3404 struct ahd_tmode_tstate
*tstate
;
3407 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0) {
3408 ahd_print_devinfo(ahd
, devinfo
);
3409 printk("Forcing renegotiation\n");
3412 targ_info
= ahd_fetch_transinfo(ahd
,
3414 devinfo
->our_scsiid
,
3417 ahd_update_neg_request(ahd
, devinfo
, tstate
,
3418 targ_info
, AHD_NEG_IF_NON_ASYNC
);
3421 #define AHD_MAX_STEPS 2000
3423 ahd_clear_critical_section(struct ahd_softc
*ahd
)
3425 ahd_mode_state saved_modes
;
3437 if (ahd
->num_critical_sections
== 0)
3450 saved_modes
= ahd_save_modes(ahd
);
3456 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
3457 seqaddr
= ahd_inw(ahd
, CURADDR
);
3459 cs
= ahd
->critical_sections
;
3460 for (i
= 0; i
< ahd
->num_critical_sections
; i
++, cs
++) {
3462 if (cs
->begin
< seqaddr
&& cs
->end
>= seqaddr
)
3466 if (i
== ahd
->num_critical_sections
)
3469 if (steps
> AHD_MAX_STEPS
) {
3470 printk("%s: Infinite loop in critical section\n"
3471 "%s: First Instruction 0x%x now 0x%x\n",
3472 ahd_name(ahd
), ahd_name(ahd
), first_instr
,
3474 ahd_dump_card_state(ahd
);
3475 panic("critical section loop");
3480 if ((ahd_debug
& AHD_SHOW_MISC
) != 0)
3481 printk("%s: Single stepping at 0x%x\n", ahd_name(ahd
),
3484 if (stepping
== FALSE
) {
3486 first_instr
= seqaddr
;
3487 ahd_set_modes(ahd
, AHD_MODE_CFG
, AHD_MODE_CFG
);
3488 simode0
= ahd_inb(ahd
, SIMODE0
);
3489 simode3
= ahd_inb(ahd
, SIMODE3
);
3490 lqimode0
= ahd_inb(ahd
, LQIMODE0
);
3491 lqimode1
= ahd_inb(ahd
, LQIMODE1
);
3492 lqomode0
= ahd_inb(ahd
, LQOMODE0
);
3493 lqomode1
= ahd_inb(ahd
, LQOMODE1
);
3494 ahd_outb(ahd
, SIMODE0
, 0);
3495 ahd_outb(ahd
, SIMODE3
, 0);
3496 ahd_outb(ahd
, LQIMODE0
, 0);
3497 ahd_outb(ahd
, LQIMODE1
, 0);
3498 ahd_outb(ahd
, LQOMODE0
, 0);
3499 ahd_outb(ahd
, LQOMODE1
, 0);
3500 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
3501 simode1
= ahd_inb(ahd
, SIMODE1
);
3503 * We don't clear ENBUSFREE. Unfortunately
3504 * we cannot re-enable busfree detection within
3505 * the current connection, so we must leave it
3506 * on while single stepping.
3508 ahd_outb(ahd
, SIMODE1
, simode1
& ENBUSFREE
);
3509 ahd_outb(ahd
, SEQCTL0
, ahd_inb(ahd
, SEQCTL0
) | STEP
);
3512 ahd_outb(ahd
, CLRSINT1
, CLRBUSFREE
);
3513 ahd_outb(ahd
, CLRINT
, CLRSCSIINT
);
3514 ahd_set_modes(ahd
, ahd
->saved_src_mode
, ahd
->saved_dst_mode
);
3515 ahd_outb(ahd
, HCNTRL
, ahd
->unpause
);
3516 while (!ahd_is_paused(ahd
))
3518 ahd_update_modes(ahd
);
3521 ahd_set_modes(ahd
, AHD_MODE_CFG
, AHD_MODE_CFG
);
3522 ahd_outb(ahd
, SIMODE0
, simode0
);
3523 ahd_outb(ahd
, SIMODE3
, simode3
);
3524 ahd_outb(ahd
, LQIMODE0
, lqimode0
);
3525 ahd_outb(ahd
, LQIMODE1
, lqimode1
);
3526 ahd_outb(ahd
, LQOMODE0
, lqomode0
);
3527 ahd_outb(ahd
, LQOMODE1
, lqomode1
);
3528 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
3529 ahd_outb(ahd
, SEQCTL0
, ahd_inb(ahd
, SEQCTL0
) & ~STEP
);
3530 ahd_outb(ahd
, SIMODE1
, simode1
);
3532 * SCSIINT seems to glitch occasionally when
3533 * the interrupt masks are restored. Clear SCSIINT
3534 * one more time so that only persistent errors
3535 * are seen as a real interrupt.
3537 ahd_outb(ahd
, CLRINT
, CLRSCSIINT
);
3539 ahd_restore_modes(ahd
, saved_modes
);
3543 * Clear any pending interrupt status.
3546 ahd_clear_intstat(struct ahd_softc
*ahd
)
3548 AHD_ASSERT_MODES(ahd
, ~(AHD_MODE_UNKNOWN_MSK
|AHD_MODE_CFG_MSK
),
3549 ~(AHD_MODE_UNKNOWN_MSK
|AHD_MODE_CFG_MSK
));
3550 /* Clear any interrupt conditions this may have caused */
3551 ahd_outb(ahd
, CLRLQIINT0
, CLRLQIATNQAS
|CLRLQICRCT1
|CLRLQICRCT2
3552 |CLRLQIBADLQT
|CLRLQIATNLQ
|CLRLQIATNCMD
);
3553 ahd_outb(ahd
, CLRLQIINT1
, CLRLQIPHASE_LQ
|CLRLQIPHASE_NLQ
|CLRLIQABORT
3554 |CLRLQICRCI_LQ
|CLRLQICRCI_NLQ
|CLRLQIBADLQI
3555 |CLRLQIOVERI_LQ
|CLRLQIOVERI_NLQ
|CLRNONPACKREQ
);
3556 ahd_outb(ahd
, CLRLQOINT0
, CLRLQOTARGSCBPERR
|CLRLQOSTOPT2
|CLRLQOATNLQ
3557 |CLRLQOATNPKT
|CLRLQOTCRC
);
3558 ahd_outb(ahd
, CLRLQOINT1
, CLRLQOINITSCBPERR
|CLRLQOSTOPI2
|CLRLQOBADQAS
3559 |CLRLQOBUSFREE
|CLRLQOPHACHGINPKT
);
3560 if ((ahd
->bugs
& AHD_CLRLQO_AUTOCLR_BUG
) != 0) {
3561 ahd_outb(ahd
, CLRLQOINT0
, 0);
3562 ahd_outb(ahd
, CLRLQOINT1
, 0);
3564 ahd_outb(ahd
, CLRSINT3
, CLRNTRAMPERR
|CLROSRAMPERR
);
3565 ahd_outb(ahd
, CLRSINT1
, CLRSELTIMEO
|CLRATNO
|CLRSCSIRSTI
3566 |CLRBUSFREE
|CLRSCSIPERR
|CLRREQINIT
);
3567 ahd_outb(ahd
, CLRSINT0
, CLRSELDO
|CLRSELDI
|CLRSELINGO
3568 |CLRIOERR
|CLROVERRUN
);
3569 ahd_outb(ahd
, CLRINT
, CLRSCSIINT
);
3572 /**************************** Debugging Routines ******************************/
3574 uint32_t ahd_debug
= AHD_DEBUG_OPTS
;
3579 ahd_print_scb(struct scb
*scb
)
3581 struct hardware_scb
*hscb
;
3585 printk("scb:%p control:0x%x scsiid:0x%x lun:%d cdb_len:%d\n",
3591 printk("Shared Data: ");
3592 for (i
= 0; i
< sizeof(hscb
->shared_data
.idata
.cdb
); i
++)
3593 printk("%#02x", hscb
->shared_data
.idata
.cdb
[i
]);
3594 printk(" dataptr:%#x%x datacnt:%#x sgptr:%#x tag:%#x\n",
3595 (uint32_t)((ahd_le64toh(hscb
->dataptr
) >> 32) & 0xFFFFFFFF),
3596 (uint32_t)(ahd_le64toh(hscb
->dataptr
) & 0xFFFFFFFF),
3597 ahd_le32toh(hscb
->datacnt
),
3598 ahd_le32toh(hscb
->sgptr
),
3600 ahd_dump_sglist(scb
);
3604 /************************* Transfer Negotiation *******************************/
3606 * Allocate per target mode instance (ID we respond to as a target)
3607 * transfer negotiation data structures.
3609 static struct ahd_tmode_tstate
*
3610 ahd_alloc_tstate(struct ahd_softc
*ahd
, u_int scsi_id
, char channel
)
3612 struct ahd_tmode_tstate
*master_tstate
;
3613 struct ahd_tmode_tstate
*tstate
;
3616 master_tstate
= ahd
->enabled_targets
[ahd
->our_id
];
3617 if (ahd
->enabled_targets
[scsi_id
] != NULL
3618 && ahd
->enabled_targets
[scsi_id
] != master_tstate
)
3619 panic("%s: ahd_alloc_tstate - Target already allocated",
3621 tstate
= kmalloc(sizeof(*tstate
), GFP_ATOMIC
);
3626 * If we have allocated a master tstate, copy user settings from
3627 * the master tstate (taken from SRAM or the EEPROM) for this
3628 * channel, but reset our current and goal settings to async/narrow
3629 * until an initiator talks to us.
3631 if (master_tstate
!= NULL
) {
3632 memcpy(tstate
, master_tstate
, sizeof(*tstate
));
3633 memset(tstate
->enabled_luns
, 0, sizeof(tstate
->enabled_luns
));
3634 for (i
= 0; i
< 16; i
++) {
3635 memset(&tstate
->transinfo
[i
].curr
, 0,
3636 sizeof(tstate
->transinfo
[i
].curr
));
3637 memset(&tstate
->transinfo
[i
].goal
, 0,
3638 sizeof(tstate
->transinfo
[i
].goal
));
3641 memset(tstate
, 0, sizeof(*tstate
));
3642 ahd
->enabled_targets
[scsi_id
] = tstate
;
3646 #ifdef AHD_TARGET_MODE
3648 * Free per target mode instance (ID we respond to as a target)
3649 * transfer negotiation data structures.
3652 ahd_free_tstate(struct ahd_softc
*ahd
, u_int scsi_id
, char channel
, int force
)
3654 struct ahd_tmode_tstate
*tstate
;
3657 * Don't clean up our "master" tstate.
3658 * It has our default user settings.
3660 if (scsi_id
== ahd
->our_id
3664 tstate
= ahd
->enabled_targets
[scsi_id
];
3667 ahd
->enabled_targets
[scsi_id
] = NULL
;
3672 * Called when we have an active connection to a target on the bus,
3673 * this function finds the nearest period to the input period limited
3674 * by the capabilities of the bus connectivity of and sync settings for
3678 ahd_devlimited_syncrate(struct ahd_softc
*ahd
,
3679 struct ahd_initiator_tinfo
*tinfo
,
3680 u_int
*period
, u_int
*ppr_options
, role_t role
)
3682 struct ahd_transinfo
*transinfo
;
3685 if ((ahd_inb(ahd
, SBLKCTL
) & ENAB40
) != 0
3686 && (ahd_inb(ahd
, SSTAT2
) & EXP_ACTIVE
) == 0) {
3687 maxsync
= AHD_SYNCRATE_PACED
;
3689 maxsync
= AHD_SYNCRATE_ULTRA
;
3690 /* Can't do DT related options on an SE bus */
3691 *ppr_options
&= MSG_EXT_PPR_QAS_REQ
;
3694 * Never allow a value higher than our current goal
3695 * period otherwise we may allow a target initiated
3696 * negotiation to go above the limit as set by the
3697 * user. In the case of an initiator initiated
3698 * sync negotiation, we limit based on the user
3699 * setting. This allows the system to still accept
3700 * incoming negotiations even if target initiated
3701 * negotiation is not performed.
3703 if (role
== ROLE_TARGET
)
3704 transinfo
= &tinfo
->user
;
3706 transinfo
= &tinfo
->goal
;
3707 *ppr_options
&= (transinfo
->ppr_options
|MSG_EXT_PPR_PCOMP_EN
);
3708 if (transinfo
->width
== MSG_EXT_WDTR_BUS_8_BIT
) {
3709 maxsync
= max(maxsync
, (u_int
)AHD_SYNCRATE_ULTRA2
);
3710 *ppr_options
&= ~MSG_EXT_PPR_DT_REQ
;
3712 if (transinfo
->period
== 0) {
3716 *period
= max(*period
, (u_int
)transinfo
->period
);
3717 ahd_find_syncrate(ahd
, period
, ppr_options
, maxsync
);
3722 * Look up the valid period to SCSIRATE conversion in our table.
3723 * Return the period and offset that should be sent to the target
3724 * if this was the beginning of an SDTR.
3727 ahd_find_syncrate(struct ahd_softc
*ahd
, u_int
*period
,
3728 u_int
*ppr_options
, u_int maxsync
)
3730 if (*period
< maxsync
)
3733 if ((*ppr_options
& MSG_EXT_PPR_DT_REQ
) != 0
3734 && *period
> AHD_SYNCRATE_MIN_DT
)
3735 *ppr_options
&= ~MSG_EXT_PPR_DT_REQ
;
3737 if (*period
> AHD_SYNCRATE_MIN
)
3740 /* Honor PPR option conformance rules. */
3741 if (*period
> AHD_SYNCRATE_PACED
)
3742 *ppr_options
&= ~MSG_EXT_PPR_RTI
;
3744 if ((*ppr_options
& MSG_EXT_PPR_IU_REQ
) == 0)
3745 *ppr_options
&= (MSG_EXT_PPR_DT_REQ
|MSG_EXT_PPR_QAS_REQ
);
3747 if ((*ppr_options
& MSG_EXT_PPR_DT_REQ
) == 0)
3748 *ppr_options
&= MSG_EXT_PPR_QAS_REQ
;
3750 /* Skip all PACED only entries if IU is not available */
3751 if ((*ppr_options
& MSG_EXT_PPR_IU_REQ
) == 0
3752 && *period
< AHD_SYNCRATE_DT
)
3753 *period
= AHD_SYNCRATE_DT
;
3755 /* Skip all DT only entries if DT is not available */
3756 if ((*ppr_options
& MSG_EXT_PPR_DT_REQ
) == 0
3757 && *period
< AHD_SYNCRATE_ULTRA2
)
3758 *period
= AHD_SYNCRATE_ULTRA2
;
3762 * Truncate the given synchronous offset to a value the
3763 * current adapter type and syncrate are capable of.
3766 ahd_validate_offset(struct ahd_softc
*ahd
,
3767 struct ahd_initiator_tinfo
*tinfo
,
3768 u_int period
, u_int
*offset
, int wide
,
3773 /* Limit offset to what we can do */
3776 else if (period
<= AHD_SYNCRATE_PACED
) {
3777 if ((ahd
->bugs
& AHD_PACED_NEGTABLE_BUG
) != 0)
3778 maxoffset
= MAX_OFFSET_PACED_BUG
;
3780 maxoffset
= MAX_OFFSET_PACED
;
3782 maxoffset
= MAX_OFFSET_NON_PACED
;
3783 *offset
= min(*offset
, maxoffset
);
3784 if (tinfo
!= NULL
) {
3785 if (role
== ROLE_TARGET
)
3786 *offset
= min(*offset
, (u_int
)tinfo
->user
.offset
);
3788 *offset
= min(*offset
, (u_int
)tinfo
->goal
.offset
);
3793 * Truncate the given transfer width parameter to a value the
3794 * current adapter type is capable of.
3797 ahd_validate_width(struct ahd_softc
*ahd
, struct ahd_initiator_tinfo
*tinfo
,
3798 u_int
*bus_width
, role_t role
)
3800 switch (*bus_width
) {
3802 if (ahd
->features
& AHD_WIDE
) {
3804 *bus_width
= MSG_EXT_WDTR_BUS_16_BIT
;
3808 case MSG_EXT_WDTR_BUS_8_BIT
:
3809 *bus_width
= MSG_EXT_WDTR_BUS_8_BIT
;
3812 if (tinfo
!= NULL
) {
3813 if (role
== ROLE_TARGET
)
3814 *bus_width
= min((u_int
)tinfo
->user
.width
, *bus_width
);
3816 *bus_width
= min((u_int
)tinfo
->goal
.width
, *bus_width
);
3821 * Update the bitmask of targets for which the controller should
3822 * negotiate with at the next convenient opportunity. This currently
3823 * means the next time we send the initial identify messages for
3824 * a new transaction.
3827 ahd_update_neg_request(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
,
3828 struct ahd_tmode_tstate
*tstate
,
3829 struct ahd_initiator_tinfo
*tinfo
, ahd_neg_type neg_type
)
3831 u_int auto_negotiate_orig
;
3833 auto_negotiate_orig
= tstate
->auto_negotiate
;
3834 if (neg_type
== AHD_NEG_ALWAYS
) {
3836 * Force our "current" settings to be
3837 * unknown so that unless a bus reset
3838 * occurs the need to renegotiate is
3839 * recorded persistently.
3841 if ((ahd
->features
& AHD_WIDE
) != 0)
3842 tinfo
->curr
.width
= AHD_WIDTH_UNKNOWN
;
3843 tinfo
->curr
.period
= AHD_PERIOD_UNKNOWN
;
3844 tinfo
->curr
.offset
= AHD_OFFSET_UNKNOWN
;
3846 if (tinfo
->curr
.period
!= tinfo
->goal
.period
3847 || tinfo
->curr
.width
!= tinfo
->goal
.width
3848 || tinfo
->curr
.offset
!= tinfo
->goal
.offset
3849 || tinfo
->curr
.ppr_options
!= tinfo
->goal
.ppr_options
3850 || (neg_type
== AHD_NEG_IF_NON_ASYNC
3851 && (tinfo
->goal
.offset
!= 0
3852 || tinfo
->goal
.width
!= MSG_EXT_WDTR_BUS_8_BIT
3853 || tinfo
->goal
.ppr_options
!= 0)))
3854 tstate
->auto_negotiate
|= devinfo
->target_mask
;
3856 tstate
->auto_negotiate
&= ~devinfo
->target_mask
;
3858 return (auto_negotiate_orig
!= tstate
->auto_negotiate
);
3862 * Update the user/goal/curr tables of synchronous negotiation
3863 * parameters as well as, in the case of a current or active update,
3864 * any data structures on the host controller. In the case of an
3865 * active update, the specified target is currently talking to us on
3866 * the bus, so the transfer parameter update must take effect
3870 ahd_set_syncrate(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
,
3871 u_int period
, u_int offset
, u_int ppr_options
,
3872 u_int type
, int paused
)
3874 struct ahd_initiator_tinfo
*tinfo
;
3875 struct ahd_tmode_tstate
*tstate
;
3882 active
= (type
& AHD_TRANS_ACTIVE
) == AHD_TRANS_ACTIVE
;
3885 if (period
== 0 || offset
== 0) {
3890 tinfo
= ahd_fetch_transinfo(ahd
, devinfo
->channel
, devinfo
->our_scsiid
,
3891 devinfo
->target
, &tstate
);
3893 if ((type
& AHD_TRANS_USER
) != 0) {
3894 tinfo
->user
.period
= period
;
3895 tinfo
->user
.offset
= offset
;
3896 tinfo
->user
.ppr_options
= ppr_options
;
3899 if ((type
& AHD_TRANS_GOAL
) != 0) {
3900 tinfo
->goal
.period
= period
;
3901 tinfo
->goal
.offset
= offset
;
3902 tinfo
->goal
.ppr_options
= ppr_options
;
3905 old_period
= tinfo
->curr
.period
;
3906 old_offset
= tinfo
->curr
.offset
;
3907 old_ppr
= tinfo
->curr
.ppr_options
;
3909 if ((type
& AHD_TRANS_CUR
) != 0
3910 && (old_period
!= period
3911 || old_offset
!= offset
3912 || old_ppr
!= ppr_options
)) {
3916 tinfo
->curr
.period
= period
;
3917 tinfo
->curr
.offset
= offset
;
3918 tinfo
->curr
.ppr_options
= ppr_options
;
3920 ahd_send_async(ahd
, devinfo
->channel
, devinfo
->target
,
3921 CAM_LUN_WILDCARD
, AC_TRANSFER_NEG
);
3926 printk("%s: target %d synchronous with "
3927 "period = 0x%x, offset = 0x%x",
3928 ahd_name(ahd
), devinfo
->target
,
3931 if ((ppr_options
& MSG_EXT_PPR_RD_STRM
) != 0) {
3935 if ((ppr_options
& MSG_EXT_PPR_DT_REQ
) != 0) {
3936 printk("%s", options
? "|DT" : "(DT");
3939 if ((ppr_options
& MSG_EXT_PPR_IU_REQ
) != 0) {
3940 printk("%s", options
? "|IU" : "(IU");
3943 if ((ppr_options
& MSG_EXT_PPR_RTI
) != 0) {
3944 printk("%s", options
? "|RTI" : "(RTI");
3947 if ((ppr_options
& MSG_EXT_PPR_QAS_REQ
) != 0) {
3948 printk("%s", options
? "|QAS" : "(QAS");
3956 printk("%s: target %d using "
3957 "asynchronous transfers%s\n",
3958 ahd_name(ahd
), devinfo
->target
,
3959 (ppr_options
& MSG_EXT_PPR_QAS_REQ
) != 0
3965 * Always refresh the neg-table to handle the case of the
3966 * sequencer setting the ENATNO bit for a MK_MESSAGE request.
3967 * We will always renegotiate in that case if this is a
3968 * packetized request. Also manage the busfree expected flag
3969 * from this common routine so that we catch changes due to
3970 * WDTR or SDTR messages.
3972 if ((type
& AHD_TRANS_CUR
) != 0) {
3975 ahd_update_neg_table(ahd
, devinfo
, &tinfo
->curr
);
3978 if (ahd
->msg_type
!= MSG_TYPE_NONE
) {
3979 if ((old_ppr
& MSG_EXT_PPR_IU_REQ
)
3980 != (ppr_options
& MSG_EXT_PPR_IU_REQ
)) {
3982 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0) {
3983 ahd_print_devinfo(ahd
, devinfo
);
3984 printk("Expecting IU Change busfree\n");
3987 ahd
->msg_flags
|= MSG_FLAG_EXPECT_PPR_BUSFREE
3988 | MSG_FLAG_IU_REQ_CHANGED
;
3990 if ((old_ppr
& MSG_EXT_PPR_IU_REQ
) != 0) {
3992 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
3993 printk("PPR with IU_REQ outstanding\n");
3995 ahd
->msg_flags
|= MSG_FLAG_EXPECT_PPR_BUSFREE
;
4000 update_needed
+= ahd_update_neg_request(ahd
, devinfo
, tstate
,
4001 tinfo
, AHD_NEG_TO_GOAL
);
4003 if (update_needed
&& active
)
4004 ahd_update_pending_scbs(ahd
);
4008 * Update the user/goal/curr tables of wide negotiation
4009 * parameters as well as, in the case of a current or active update,
4010 * any data structures on the host controller. In the case of an
4011 * active update, the specified target is currently talking to us on
4012 * the bus, so the transfer parameter update must take effect
4016 ahd_set_width(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
,
4017 u_int width
, u_int type
, int paused
)
4019 struct ahd_initiator_tinfo
*tinfo
;
4020 struct ahd_tmode_tstate
*tstate
;
4025 active
= (type
& AHD_TRANS_ACTIVE
) == AHD_TRANS_ACTIVE
;
4027 tinfo
= ahd_fetch_transinfo(ahd
, devinfo
->channel
, devinfo
->our_scsiid
,
4028 devinfo
->target
, &tstate
);
4030 if ((type
& AHD_TRANS_USER
) != 0)
4031 tinfo
->user
.width
= width
;
4033 if ((type
& AHD_TRANS_GOAL
) != 0)
4034 tinfo
->goal
.width
= width
;
4036 oldwidth
= tinfo
->curr
.width
;
4037 if ((type
& AHD_TRANS_CUR
) != 0 && oldwidth
!= width
) {
4041 tinfo
->curr
.width
= width
;
4042 ahd_send_async(ahd
, devinfo
->channel
, devinfo
->target
,
4043 CAM_LUN_WILDCARD
, AC_TRANSFER_NEG
);
4045 printk("%s: target %d using %dbit transfers\n",
4046 ahd_name(ahd
), devinfo
->target
,
4047 8 * (0x01 << width
));
4051 if ((type
& AHD_TRANS_CUR
) != 0) {
4054 ahd_update_neg_table(ahd
, devinfo
, &tinfo
->curr
);
4059 update_needed
+= ahd_update_neg_request(ahd
, devinfo
, tstate
,
4060 tinfo
, AHD_NEG_TO_GOAL
);
4061 if (update_needed
&& active
)
4062 ahd_update_pending_scbs(ahd
);
4067 * Update the current state of tagged queuing for a given target.
4070 ahd_set_tags(struct ahd_softc
*ahd
, struct scsi_cmnd
*cmd
,
4071 struct ahd_devinfo
*devinfo
, ahd_queue_alg alg
)
4073 struct scsi_device
*sdev
= cmd
->device
;
4075 ahd_platform_set_tags(ahd
, sdev
, devinfo
, alg
);
4076 ahd_send_async(ahd
, devinfo
->channel
, devinfo
->target
,
4077 devinfo
->lun
, AC_TRANSFER_NEG
);
4081 ahd_update_neg_table(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
,
4082 struct ahd_transinfo
*tinfo
)
4084 ahd_mode_state saved_modes
;
4089 u_int saved_negoaddr
;
4090 uint8_t iocell_opts
[sizeof(ahd
->iocell_opts
)];
4092 saved_modes
= ahd_save_modes(ahd
);
4093 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
4095 saved_negoaddr
= ahd_inb(ahd
, NEGOADDR
);
4096 ahd_outb(ahd
, NEGOADDR
, devinfo
->target
);
4097 period
= tinfo
->period
;
4098 offset
= tinfo
->offset
;
4099 memcpy(iocell_opts
, ahd
->iocell_opts
, sizeof(ahd
->iocell_opts
));
4100 ppr_opts
= tinfo
->ppr_options
& (MSG_EXT_PPR_QAS_REQ
|MSG_EXT_PPR_DT_REQ
4101 |MSG_EXT_PPR_IU_REQ
|MSG_EXT_PPR_RTI
);
4104 period
= AHD_SYNCRATE_ASYNC
;
4105 if (period
== AHD_SYNCRATE_160
) {
4107 if ((ahd
->bugs
& AHD_PACED_NEGTABLE_BUG
) != 0) {
4109 * When the SPI4 spec was finalized, PACE transfers
4110 * was not made a configurable option in the PPR
4111 * message. Instead it is assumed to be enabled for
4112 * any syncrate faster than 80MHz. Nevertheless,
4113 * Harpoon2A4 allows this to be configurable.
4115 * Harpoon2A4 also assumes at most 2 data bytes per
4116 * negotiated REQ/ACK offset. Paced transfers take
4117 * 4, so we must adjust our offset.
4119 ppr_opts
|= PPROPT_PACE
;
4123 * Harpoon2A assumed that there would be a
4124 * fallback rate between 160MHz and 80MHz,
4125 * so 7 is used as the period factor rather
4126 * than 8 for 160MHz.
4128 period
= AHD_SYNCRATE_REVA_160
;
4130 if ((tinfo
->ppr_options
& MSG_EXT_PPR_PCOMP_EN
) == 0)
4131 iocell_opts
[AHD_PRECOMP_SLEW_INDEX
] &=
4135 * Precomp should be disabled for non-paced transfers.
4137 iocell_opts
[AHD_PRECOMP_SLEW_INDEX
] &= ~AHD_PRECOMP_MASK
;
4139 if ((ahd
->features
& AHD_NEW_IOCELL_OPTS
) != 0
4140 && (ppr_opts
& MSG_EXT_PPR_DT_REQ
) != 0
4141 && (ppr_opts
& MSG_EXT_PPR_IU_REQ
) == 0) {
4143 * Slow down our CRC interval to be
4144 * compatible with non-packetized
4145 * U160 devices that can't handle a
4146 * CRC at full speed.
4148 con_opts
|= ENSLOWCRC
;
4151 if ((ahd
->bugs
& AHD_PACED_NEGTABLE_BUG
) != 0) {
4153 * On H2A4, revert to a slower slewrate
4154 * on non-paced transfers.
4156 iocell_opts
[AHD_PRECOMP_SLEW_INDEX
] &=
4161 ahd_outb(ahd
, ANNEXCOL
, AHD_ANNEXCOL_PRECOMP_SLEW
);
4162 ahd_outb(ahd
, ANNEXDAT
, iocell_opts
[AHD_PRECOMP_SLEW_INDEX
]);
4163 ahd_outb(ahd
, ANNEXCOL
, AHD_ANNEXCOL_AMPLITUDE
);
4164 ahd_outb(ahd
, ANNEXDAT
, iocell_opts
[AHD_AMPLITUDE_INDEX
]);
4166 ahd_outb(ahd
, NEGPERIOD
, period
);
4167 ahd_outb(ahd
, NEGPPROPTS
, ppr_opts
);
4168 ahd_outb(ahd
, NEGOFFSET
, offset
);
4170 if (tinfo
->width
== MSG_EXT_WDTR_BUS_16_BIT
)
4171 con_opts
|= WIDEXFER
;
4174 * Slow down our CRC interval to be
4175 * compatible with packetized U320 devices
4176 * that can't handle a CRC at full speed
4178 if (ahd
->features
& AHD_AIC79XXB_SLOWCRC
) {
4179 con_opts
|= ENSLOWCRC
;
4183 * During packetized transfers, the target will
4184 * give us the opportunity to send command packets
4185 * without us asserting attention.
4187 if ((tinfo
->ppr_options
& MSG_EXT_PPR_IU_REQ
) == 0)
4188 con_opts
|= ENAUTOATNO
;
4189 ahd_outb(ahd
, NEGCONOPTS
, con_opts
);
4190 ahd_outb(ahd
, NEGOADDR
, saved_negoaddr
);
4191 ahd_restore_modes(ahd
, saved_modes
);
4195 * When the transfer settings for a connection change, setup for
4196 * negotiation in pending SCBs to effect the change as quickly as
4197 * possible. We also cancel any negotiations that are scheduled
4198 * for inflight SCBs that have not been started yet.
4201 ahd_update_pending_scbs(struct ahd_softc
*ahd
)
4203 struct scb
*pending_scb
;
4204 int pending_scb_count
;
4207 ahd_mode_state saved_modes
;
4210 * Traverse the pending SCB list and ensure that all of the
4211 * SCBs there have the proper settings. We can only safely
4212 * clear the negotiation required flag (setting requires the
4213 * execution queue to be modified) and this is only possible
4214 * if we are not already attempting to select out for this
4215 * SCB. For this reason, all callers only call this routine
4216 * if we are changing the negotiation settings for the currently
4217 * active transaction on the bus.
4219 pending_scb_count
= 0;
4220 LIST_FOREACH(pending_scb
, &ahd
->pending_scbs
, pending_links
) {
4221 struct ahd_devinfo devinfo
;
4222 struct ahd_initiator_tinfo
*tinfo
;
4223 struct ahd_tmode_tstate
*tstate
;
4225 ahd_scb_devinfo(ahd
, &devinfo
, pending_scb
);
4226 tinfo
= ahd_fetch_transinfo(ahd
, devinfo
.channel
,
4228 devinfo
.target
, &tstate
);
4229 if ((tstate
->auto_negotiate
& devinfo
.target_mask
) == 0
4230 && (pending_scb
->flags
& SCB_AUTO_NEGOTIATE
) != 0) {
4231 pending_scb
->flags
&= ~SCB_AUTO_NEGOTIATE
;
4232 pending_scb
->hscb
->control
&= ~MK_MESSAGE
;
4234 ahd_sync_scb(ahd
, pending_scb
,
4235 BUS_DMASYNC_PREREAD
|BUS_DMASYNC_PREWRITE
);
4236 pending_scb_count
++;
4239 if (pending_scb_count
== 0)
4242 if (ahd_is_paused(ahd
)) {
4250 * Force the sequencer to reinitialize the selection for
4251 * the command at the head of the execution queue if it
4252 * has already been setup. The negotiation changes may
4253 * effect whether we select-out with ATN. It is only
4254 * safe to clear ENSELO when the bus is not free and no
4255 * selection is in progres or completed.
4257 saved_modes
= ahd_save_modes(ahd
);
4258 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
4259 if ((ahd_inb(ahd
, SCSISIGI
) & BSYI
) != 0
4260 && (ahd_inb(ahd
, SSTAT0
) & (SELDO
|SELINGO
)) == 0)
4261 ahd_outb(ahd
, SCSISEQ0
, ahd_inb(ahd
, SCSISEQ0
) & ~ENSELO
);
4262 saved_scbptr
= ahd_get_scbptr(ahd
);
4263 /* Ensure that the hscbs down on the card match the new information */
4264 LIST_FOREACH(pending_scb
, &ahd
->pending_scbs
, pending_links
) {
4268 scb_tag
= SCB_GET_TAG(pending_scb
);
4269 ahd_set_scbptr(ahd
, scb_tag
);
4270 control
= ahd_inb_scbram(ahd
, SCB_CONTROL
);
4271 control
&= ~MK_MESSAGE
;
4272 control
|= pending_scb
->hscb
->control
& MK_MESSAGE
;
4273 ahd_outb(ahd
, SCB_CONTROL
, control
);
4275 ahd_set_scbptr(ahd
, saved_scbptr
);
4276 ahd_restore_modes(ahd
, saved_modes
);
4282 /**************************** Pathing Information *****************************/
4284 ahd_fetch_devinfo(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
)
4286 ahd_mode_state saved_modes
;
4291 saved_modes
= ahd_save_modes(ahd
);
4292 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
4294 if (ahd_inb(ahd
, SSTAT0
) & TARGET
)
4297 role
= ROLE_INITIATOR
;
4299 if (role
== ROLE_TARGET
4300 && (ahd_inb(ahd
, SEQ_FLAGS
) & CMDPHASE_PENDING
) != 0) {
4301 /* We were selected, so pull our id from TARGIDIN */
4302 our_id
= ahd_inb(ahd
, TARGIDIN
) & OID
;
4303 } else if (role
== ROLE_TARGET
)
4304 our_id
= ahd_inb(ahd
, TOWNID
);
4306 our_id
= ahd_inb(ahd
, IOWNID
);
4308 saved_scsiid
= ahd_inb(ahd
, SAVED_SCSIID
);
4309 ahd_compile_devinfo(devinfo
,
4311 SCSIID_TARGET(ahd
, saved_scsiid
),
4312 ahd_inb(ahd
, SAVED_LUN
),
4313 SCSIID_CHANNEL(ahd
, saved_scsiid
),
4315 ahd_restore_modes(ahd
, saved_modes
);
4319 ahd_print_devinfo(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
)
4321 printk("%s:%c:%d:%d: ", ahd_name(ahd
), 'A',
4322 devinfo
->target
, devinfo
->lun
);
4325 static const struct ahd_phase_table_entry
*
4326 ahd_lookup_phase_entry(int phase
)
4328 const struct ahd_phase_table_entry
*entry
;
4329 const struct ahd_phase_table_entry
*last_entry
;
4332 * num_phases doesn't include the default entry which
4333 * will be returned if the phase doesn't match.
4335 last_entry
= &ahd_phase_table
[num_phases
];
4336 for (entry
= ahd_phase_table
; entry
< last_entry
; entry
++) {
4337 if (phase
== entry
->phase
)
4344 ahd_compile_devinfo(struct ahd_devinfo
*devinfo
, u_int our_id
, u_int target
,
4345 u_int lun
, char channel
, role_t role
)
4347 devinfo
->our_scsiid
= our_id
;
4348 devinfo
->target
= target
;
4350 devinfo
->target_offset
= target
;
4351 devinfo
->channel
= channel
;
4352 devinfo
->role
= role
;
4354 devinfo
->target_offset
+= 8;
4355 devinfo
->target_mask
= (0x01 << devinfo
->target_offset
);
4359 ahd_scb_devinfo(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
,
4365 our_id
= SCSIID_OUR_ID(scb
->hscb
->scsiid
);
4366 role
= ROLE_INITIATOR
;
4367 if ((scb
->hscb
->control
& TARGET_SCB
) != 0)
4369 ahd_compile_devinfo(devinfo
, our_id
, SCB_GET_TARGET(ahd
, scb
),
4370 SCB_GET_LUN(scb
), SCB_GET_CHANNEL(ahd
, scb
), role
);
4374 /************************ Message Phase Processing ****************************/
4376 * When an initiator transaction with the MK_MESSAGE flag either reconnects
4377 * or enters the initial message out phase, we are interrupted. Fill our
4378 * outgoing message buffer with the appropriate message and beging handing
4379 * the message phase(s) manually.
4382 ahd_setup_initiator_msgout(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
,
4386 * To facilitate adding multiple messages together,
4387 * each routine should increment the index and len
4388 * variables instead of setting them explicitly.
4390 ahd
->msgout_index
= 0;
4391 ahd
->msgout_len
= 0;
4393 if (ahd_currently_packetized(ahd
))
4394 ahd
->msg_flags
|= MSG_FLAG_PACKETIZED
;
4396 if (ahd
->send_msg_perror
4397 && ahd_inb(ahd
, MSG_OUT
) == HOST_MSG
) {
4398 ahd
->msgout_buf
[ahd
->msgout_index
++] = ahd
->send_msg_perror
;
4400 ahd
->msg_type
= MSG_TYPE_INITIATOR_MSGOUT
;
4402 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
4403 printk("Setting up for Parity Error delivery\n");
4406 } else if (scb
== NULL
) {
4407 printk("%s: WARNING. No pending message for "
4408 "I_T msgin. Issuing NO-OP\n", ahd_name(ahd
));
4409 ahd
->msgout_buf
[ahd
->msgout_index
++] = MSG_NOOP
;
4411 ahd
->msg_type
= MSG_TYPE_INITIATOR_MSGOUT
;
4415 if ((scb
->flags
& SCB_DEVICE_RESET
) == 0
4416 && (scb
->flags
& SCB_PACKETIZED
) == 0
4417 && ahd_inb(ahd
, MSG_OUT
) == MSG_IDENTIFYFLAG
) {
4420 identify_msg
= MSG_IDENTIFYFLAG
| SCB_GET_LUN(scb
);
4421 if ((scb
->hscb
->control
& DISCENB
) != 0)
4422 identify_msg
|= MSG_IDENTIFY_DISCFLAG
;
4423 ahd
->msgout_buf
[ahd
->msgout_index
++] = identify_msg
;
4426 if ((scb
->hscb
->control
& TAG_ENB
) != 0) {
4427 ahd
->msgout_buf
[ahd
->msgout_index
++] =
4428 scb
->hscb
->control
& (TAG_ENB
|SCB_TAG_TYPE
);
4429 ahd
->msgout_buf
[ahd
->msgout_index
++] = SCB_GET_TAG(scb
);
4430 ahd
->msgout_len
+= 2;
4434 if (scb
->flags
& SCB_DEVICE_RESET
) {
4435 ahd
->msgout_buf
[ahd
->msgout_index
++] = MSG_BUS_DEV_RESET
;
4437 ahd_print_path(ahd
, scb
);
4438 printk("Bus Device Reset Message Sent\n");
4440 * Clear our selection hardware in advance of
4441 * the busfree. We may have an entry in the waiting
4442 * Q for this target, and we don't want to go about
4443 * selecting while we handle the busfree and blow it
4446 ahd_outb(ahd
, SCSISEQ0
, 0);
4447 } else if ((scb
->flags
& SCB_ABORT
) != 0) {
4449 if ((scb
->hscb
->control
& TAG_ENB
) != 0) {
4450 ahd
->msgout_buf
[ahd
->msgout_index
++] = MSG_ABORT_TAG
;
4452 ahd
->msgout_buf
[ahd
->msgout_index
++] = MSG_ABORT
;
4455 ahd_print_path(ahd
, scb
);
4456 printk("Abort%s Message Sent\n",
4457 (scb
->hscb
->control
& TAG_ENB
) != 0 ? " Tag" : "");
4459 * Clear our selection hardware in advance of
4460 * the busfree. We may have an entry in the waiting
4461 * Q for this target, and we don't want to go about
4462 * selecting while we handle the busfree and blow it
4465 ahd_outb(ahd
, SCSISEQ0
, 0);
4466 } else if ((scb
->flags
& (SCB_AUTO_NEGOTIATE
|SCB_NEGOTIATE
)) != 0) {
4467 ahd_build_transfer_msg(ahd
, devinfo
);
4469 * Clear our selection hardware in advance of potential
4470 * PPR IU status change busfree. We may have an entry in
4471 * the waiting Q for this target, and we don't want to go
4472 * about selecting while we handle the busfree and blow
4475 ahd_outb(ahd
, SCSISEQ0
, 0);
4477 printk("ahd_intr: AWAITING_MSG for an SCB that "
4478 "does not have a waiting message\n");
4479 printk("SCSIID = %x, target_mask = %x\n", scb
->hscb
->scsiid
,
4480 devinfo
->target_mask
);
4481 panic("SCB = %d, SCB Control = %x:%x, MSG_OUT = %x "
4482 "SCB flags = %x", SCB_GET_TAG(scb
), scb
->hscb
->control
,
4483 ahd_inb_scbram(ahd
, SCB_CONTROL
), ahd_inb(ahd
, MSG_OUT
),
4488 * Clear the MK_MESSAGE flag from the SCB so we aren't
4489 * asked to send this message again.
4491 ahd_outb(ahd
, SCB_CONTROL
,
4492 ahd_inb_scbram(ahd
, SCB_CONTROL
) & ~MK_MESSAGE
);
4493 scb
->hscb
->control
&= ~MK_MESSAGE
;
4494 ahd
->msgout_index
= 0;
4495 ahd
->msg_type
= MSG_TYPE_INITIATOR_MSGOUT
;
4499 * Build an appropriate transfer negotiation message for the
4500 * currently active target.
4503 ahd_build_transfer_msg(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
)
4506 * We need to initiate transfer negotiations.
4507 * If our current and goal settings are identical,
4508 * we want to renegotiate due to a check condition.
4510 struct ahd_initiator_tinfo
*tinfo
;
4511 struct ahd_tmode_tstate
*tstate
;
4519 tinfo
= ahd_fetch_transinfo(ahd
, devinfo
->channel
, devinfo
->our_scsiid
,
4520 devinfo
->target
, &tstate
);
4522 * Filter our period based on the current connection.
4523 * If we can't perform DT transfers on this segment (not in LVD
4524 * mode for instance), then our decision to issue a PPR message
4527 period
= tinfo
->goal
.period
;
4528 offset
= tinfo
->goal
.offset
;
4529 ppr_options
= tinfo
->goal
.ppr_options
;
4530 /* Target initiated PPR is not allowed in the SCSI spec */
4531 if (devinfo
->role
== ROLE_TARGET
)
4533 ahd_devlimited_syncrate(ahd
, tinfo
, &period
,
4534 &ppr_options
, devinfo
->role
);
4535 dowide
= tinfo
->curr
.width
!= tinfo
->goal
.width
;
4536 dosync
= tinfo
->curr
.offset
!= offset
|| tinfo
->curr
.period
!= period
;
4538 * Only use PPR if we have options that need it, even if the device
4539 * claims to support it. There might be an expander in the way
4542 doppr
= ppr_options
!= 0;
4544 if (!dowide
&& !dosync
&& !doppr
) {
4545 dowide
= tinfo
->goal
.width
!= MSG_EXT_WDTR_BUS_8_BIT
;
4546 dosync
= tinfo
->goal
.offset
!= 0;
4549 if (!dowide
&& !dosync
&& !doppr
) {
4551 * Force async with a WDTR message if we have a wide bus,
4552 * or just issue an SDTR with a 0 offset.
4554 if ((ahd
->features
& AHD_WIDE
) != 0)
4560 ahd_print_devinfo(ahd
, devinfo
);
4561 printk("Ensuring async\n");
4564 /* Target initiated PPR is not allowed in the SCSI spec */
4565 if (devinfo
->role
== ROLE_TARGET
)
4569 * Both the PPR message and SDTR message require the
4570 * goal syncrate to be limited to what the target device
4571 * is capable of handling (based on whether an LVD->SE
4572 * expander is on the bus), so combine these two cases.
4573 * Regardless, guarantee that if we are using WDTR and SDTR
4574 * messages that WDTR comes first.
4576 if (doppr
|| (dosync
&& !dowide
)) {
4578 offset
= tinfo
->goal
.offset
;
4579 ahd_validate_offset(ahd
, tinfo
, period
, &offset
,
4580 doppr
? tinfo
->goal
.width
4581 : tinfo
->curr
.width
,
4584 ahd_construct_ppr(ahd
, devinfo
, period
, offset
,
4585 tinfo
->goal
.width
, ppr_options
);
4587 ahd_construct_sdtr(ahd
, devinfo
, period
, offset
);
4590 ahd_construct_wdtr(ahd
, devinfo
, tinfo
->goal
.width
);
4595 * Build a synchronous negotiation message in our message
4596 * buffer based on the input parameters.
4599 ahd_construct_sdtr(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
,
4600 u_int period
, u_int offset
)
4603 period
= AHD_ASYNC_XFER_PERIOD
;
4604 ahd
->msgout_index
+= spi_populate_sync_msg(
4605 ahd
->msgout_buf
+ ahd
->msgout_index
, period
, offset
);
4606 ahd
->msgout_len
+= 5;
4608 printk("(%s:%c:%d:%d): Sending SDTR period %x, offset %x\n",
4609 ahd_name(ahd
), devinfo
->channel
, devinfo
->target
,
4610 devinfo
->lun
, period
, offset
);
4615 * Build a wide negotiateion message in our message
4616 * buffer based on the input parameters.
4619 ahd_construct_wdtr(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
,
4622 ahd
->msgout_index
+= spi_populate_width_msg(
4623 ahd
->msgout_buf
+ ahd
->msgout_index
, bus_width
);
4624 ahd
->msgout_len
+= 4;
4626 printk("(%s:%c:%d:%d): Sending WDTR %x\n",
4627 ahd_name(ahd
), devinfo
->channel
, devinfo
->target
,
4628 devinfo
->lun
, bus_width
);
4633 * Build a parallel protocol request message in our message
4634 * buffer based on the input parameters.
4637 ahd_construct_ppr(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
,
4638 u_int period
, u_int offset
, u_int bus_width
,
4642 * Always request precompensation from
4643 * the other target if we are running
4644 * at paced syncrates.
4646 if (period
<= AHD_SYNCRATE_PACED
)
4647 ppr_options
|= MSG_EXT_PPR_PCOMP_EN
;
4649 period
= AHD_ASYNC_XFER_PERIOD
;
4650 ahd
->msgout_index
+= spi_populate_ppr_msg(
4651 ahd
->msgout_buf
+ ahd
->msgout_index
, period
, offset
,
4652 bus_width
, ppr_options
);
4653 ahd
->msgout_len
+= 8;
4655 printk("(%s:%c:%d:%d): Sending PPR bus_width %x, period %x, "
4656 "offset %x, ppr_options %x\n", ahd_name(ahd
),
4657 devinfo
->channel
, devinfo
->target
, devinfo
->lun
,
4658 bus_width
, period
, offset
, ppr_options
);
4663 * Clear any active message state.
4666 ahd_clear_msg_state(struct ahd_softc
*ahd
)
4668 ahd_mode_state saved_modes
;
4670 saved_modes
= ahd_save_modes(ahd
);
4671 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
4672 ahd
->send_msg_perror
= 0;
4673 ahd
->msg_flags
= MSG_FLAG_NONE
;
4674 ahd
->msgout_len
= 0;
4675 ahd
->msgin_index
= 0;
4676 ahd
->msg_type
= MSG_TYPE_NONE
;
4677 if ((ahd_inb(ahd
, SCSISIGO
) & ATNO
) != 0) {
4679 * The target didn't care to respond to our
4680 * message request, so clear ATN.
4682 ahd_outb(ahd
, CLRSINT1
, CLRATNO
);
4684 ahd_outb(ahd
, MSG_OUT
, MSG_NOOP
);
4685 ahd_outb(ahd
, SEQ_FLAGS2
,
4686 ahd_inb(ahd
, SEQ_FLAGS2
) & ~TARGET_MSG_PENDING
);
4687 ahd_restore_modes(ahd
, saved_modes
);
4691 * Manual message loop handler.
4694 ahd_handle_message_phase(struct ahd_softc
*ahd
)
4696 struct ahd_devinfo devinfo
;
4700 ahd_fetch_devinfo(ahd
, &devinfo
);
4701 end_session
= FALSE
;
4702 bus_phase
= ahd_inb(ahd
, LASTPHASE
);
4704 if ((ahd_inb(ahd
, LQISTAT2
) & LQIPHASE_OUTPKT
) != 0) {
4705 printk("LQIRETRY for LQIPHASE_OUTPKT\n");
4706 ahd_outb(ahd
, LQCTL2
, LQIRETRY
);
4709 switch (ahd
->msg_type
) {
4710 case MSG_TYPE_INITIATOR_MSGOUT
:
4716 if (ahd
->msgout_len
== 0 && ahd
->send_msg_perror
== 0)
4717 panic("HOST_MSG_LOOP interrupt with no active message");
4720 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0) {
4721 ahd_print_devinfo(ahd
, &devinfo
);
4722 printk("INITIATOR_MSG_OUT");
4725 phasemis
= bus_phase
!= P_MESGOUT
;
4728 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0) {
4729 printk(" PHASEMIS %s\n",
4730 ahd_lookup_phase_entry(bus_phase
)
4734 if (bus_phase
== P_MESGIN
) {
4736 * Change gears and see if
4737 * this messages is of interest to
4738 * us or should be passed back to
4741 ahd_outb(ahd
, CLRSINT1
, CLRATNO
);
4742 ahd
->send_msg_perror
= 0;
4743 ahd
->msg_type
= MSG_TYPE_INITIATOR_MSGIN
;
4744 ahd
->msgin_index
= 0;
4751 if (ahd
->send_msg_perror
) {
4752 ahd_outb(ahd
, CLRSINT1
, CLRATNO
);
4753 ahd_outb(ahd
, CLRSINT1
, CLRREQINIT
);
4755 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
4756 printk(" byte 0x%x\n", ahd
->send_msg_perror
);
4759 * If we are notifying the target of a CRC error
4760 * during packetized operations, the target is
4761 * within its rights to acknowledge our message
4764 if ((ahd
->msg_flags
& MSG_FLAG_PACKETIZED
) != 0
4765 && ahd
->send_msg_perror
== MSG_INITIATOR_DET_ERR
)
4766 ahd
->msg_flags
|= MSG_FLAG_EXPECT_IDE_BUSFREE
;
4768 ahd_outb(ahd
, RETURN_2
, ahd
->send_msg_perror
);
4769 ahd_outb(ahd
, RETURN_1
, CONT_MSG_LOOP_WRITE
);
4773 msgdone
= ahd
->msgout_index
== ahd
->msgout_len
;
4776 * The target has requested a retry.
4777 * Re-assert ATN, reset our message index to
4780 ahd
->msgout_index
= 0;
4781 ahd_assert_atn(ahd
);
4784 lastbyte
= ahd
->msgout_index
== (ahd
->msgout_len
- 1);
4786 /* Last byte is signified by dropping ATN */
4787 ahd_outb(ahd
, CLRSINT1
, CLRATNO
);
4791 * Clear our interrupt status and present
4792 * the next byte on the bus.
4794 ahd_outb(ahd
, CLRSINT1
, CLRREQINIT
);
4796 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
4797 printk(" byte 0x%x\n",
4798 ahd
->msgout_buf
[ahd
->msgout_index
]);
4800 ahd_outb(ahd
, RETURN_2
, ahd
->msgout_buf
[ahd
->msgout_index
++]);
4801 ahd_outb(ahd
, RETURN_1
, CONT_MSG_LOOP_WRITE
);
4804 case MSG_TYPE_INITIATOR_MSGIN
:
4810 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0) {
4811 ahd_print_devinfo(ahd
, &devinfo
);
4812 printk("INITIATOR_MSG_IN");
4815 phasemis
= bus_phase
!= P_MESGIN
;
4818 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0) {
4819 printk(" PHASEMIS %s\n",
4820 ahd_lookup_phase_entry(bus_phase
)
4824 ahd
->msgin_index
= 0;
4825 if (bus_phase
== P_MESGOUT
4826 && (ahd
->send_msg_perror
!= 0
4827 || (ahd
->msgout_len
!= 0
4828 && ahd
->msgout_index
== 0))) {
4829 ahd
->msg_type
= MSG_TYPE_INITIATOR_MSGOUT
;
4836 /* Pull the byte in without acking it */
4837 ahd
->msgin_buf
[ahd
->msgin_index
] = ahd_inb(ahd
, SCSIBUS
);
4839 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
4840 printk(" byte 0x%x\n",
4841 ahd
->msgin_buf
[ahd
->msgin_index
]);
4844 message_done
= ahd_parse_msg(ahd
, &devinfo
);
4848 * Clear our incoming message buffer in case there
4849 * is another message following this one.
4851 ahd
->msgin_index
= 0;
4854 * If this message illicited a response,
4855 * assert ATN so the target takes us to the
4856 * message out phase.
4858 if (ahd
->msgout_len
!= 0) {
4860 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0) {
4861 ahd_print_devinfo(ahd
, &devinfo
);
4862 printk("Asserting ATN for response\n");
4865 ahd_assert_atn(ahd
);
4870 if (message_done
== MSGLOOP_TERMINATED
) {
4874 ahd_outb(ahd
, CLRSINT1
, CLRREQINIT
);
4875 ahd_outb(ahd
, RETURN_1
, CONT_MSG_LOOP_READ
);
4879 case MSG_TYPE_TARGET_MSGIN
:
4885 * By default, the message loop will continue.
4887 ahd_outb(ahd
, RETURN_1
, CONT_MSG_LOOP_TARG
);
4889 if (ahd
->msgout_len
== 0)
4890 panic("Target MSGIN with no active message");
4893 * If we interrupted a mesgout session, the initiator
4894 * will not know this until our first REQ. So, we
4895 * only honor mesgout requests after we've sent our
4898 if ((ahd_inb(ahd
, SCSISIGI
) & ATNI
) != 0
4899 && ahd
->msgout_index
> 0)
4900 msgout_request
= TRUE
;
4902 msgout_request
= FALSE
;
4904 if (msgout_request
) {
4907 * Change gears and see if
4908 * this messages is of interest to
4909 * us or should be passed back to
4912 ahd
->msg_type
= MSG_TYPE_TARGET_MSGOUT
;
4913 ahd_outb(ahd
, SCSISIGO
, P_MESGOUT
| BSYO
);
4914 ahd
->msgin_index
= 0;
4915 /* Dummy read to REQ for first byte */
4916 ahd_inb(ahd
, SCSIDAT
);
4917 ahd_outb(ahd
, SXFRCTL0
,
4918 ahd_inb(ahd
, SXFRCTL0
) | SPIOEN
);
4922 msgdone
= ahd
->msgout_index
== ahd
->msgout_len
;
4924 ahd_outb(ahd
, SXFRCTL0
,
4925 ahd_inb(ahd
, SXFRCTL0
) & ~SPIOEN
);
4931 * Present the next byte on the bus.
4933 ahd_outb(ahd
, SXFRCTL0
, ahd_inb(ahd
, SXFRCTL0
) | SPIOEN
);
4934 ahd_outb(ahd
, SCSIDAT
, ahd
->msgout_buf
[ahd
->msgout_index
++]);
4937 case MSG_TYPE_TARGET_MSGOUT
:
4943 * By default, the message loop will continue.
4945 ahd_outb(ahd
, RETURN_1
, CONT_MSG_LOOP_TARG
);
4948 * The initiator signals that this is
4949 * the last byte by dropping ATN.
4951 lastbyte
= (ahd_inb(ahd
, SCSISIGI
) & ATNI
) == 0;
4954 * Read the latched byte, but turn off SPIOEN first
4955 * so that we don't inadvertently cause a REQ for the
4958 ahd_outb(ahd
, SXFRCTL0
, ahd_inb(ahd
, SXFRCTL0
) & ~SPIOEN
);
4959 ahd
->msgin_buf
[ahd
->msgin_index
] = ahd_inb(ahd
, SCSIDAT
);
4960 msgdone
= ahd_parse_msg(ahd
, &devinfo
);
4961 if (msgdone
== MSGLOOP_TERMINATED
) {
4963 * The message is *really* done in that it caused
4964 * us to go to bus free. The sequencer has already
4965 * been reset at this point, so pull the ejection
4974 * XXX Read spec about initiator dropping ATN too soon
4975 * and use msgdone to detect it.
4977 if (msgdone
== MSGLOOP_MSGCOMPLETE
) {
4978 ahd
->msgin_index
= 0;
4981 * If this message illicited a response, transition
4982 * to the Message in phase and send it.
4984 if (ahd
->msgout_len
!= 0) {
4985 ahd_outb(ahd
, SCSISIGO
, P_MESGIN
| BSYO
);
4986 ahd_outb(ahd
, SXFRCTL0
,
4987 ahd_inb(ahd
, SXFRCTL0
) | SPIOEN
);
4988 ahd
->msg_type
= MSG_TYPE_TARGET_MSGIN
;
4989 ahd
->msgin_index
= 0;
4997 /* Ask for the next byte. */
4998 ahd_outb(ahd
, SXFRCTL0
,
4999 ahd_inb(ahd
, SXFRCTL0
) | SPIOEN
);
5005 panic("Unknown REQINIT message type");
5009 if ((ahd
->msg_flags
& MSG_FLAG_PACKETIZED
) != 0) {
5010 printk("%s: Returning to Idle Loop\n",
5012 ahd_clear_msg_state(ahd
);
5015 * Perform the equivalent of a clear_target_state.
5017 ahd_outb(ahd
, LASTPHASE
, P_BUSFREE
);
5018 ahd_outb(ahd
, SEQ_FLAGS
, NOT_IDENTIFIED
|NO_CDB_SENT
);
5019 ahd_outb(ahd
, SEQCTL0
, FASTMODE
|SEQRESET
);
5021 ahd_clear_msg_state(ahd
);
5022 ahd_outb(ahd
, RETURN_1
, EXIT_MSG_LOOP
);
5028 * See if we sent a particular extended message to the target.
5029 * If "full" is true, return true only if the target saw the full
5030 * message. If "full" is false, return true if the target saw at
5031 * least the first byte of the message.
5034 ahd_sent_msg(struct ahd_softc
*ahd
, ahd_msgtype type
, u_int msgval
, int full
)
5042 while (index
< ahd
->msgout_len
) {
5043 if (ahd
->msgout_buf
[index
] == MSG_EXTENDED
) {
5046 end_index
= index
+ 1 + ahd
->msgout_buf
[index
+ 1];
5047 if (ahd
->msgout_buf
[index
+2] == msgval
5048 && type
== AHDMSG_EXT
) {
5051 if (ahd
->msgout_index
> end_index
)
5053 } else if (ahd
->msgout_index
> index
)
5057 } else if (ahd
->msgout_buf
[index
] >= MSG_SIMPLE_TASK
5058 && ahd
->msgout_buf
[index
] <= MSG_IGN_WIDE_RESIDUE
) {
5060 /* Skip tag type and tag id or residue param*/
5063 /* Single byte message */
5064 if (type
== AHDMSG_1B
5065 && ahd
->msgout_index
> index
5066 && (ahd
->msgout_buf
[index
] == msgval
5067 || ((ahd
->msgout_buf
[index
] & MSG_IDENTIFYFLAG
) != 0
5068 && msgval
== MSG_IDENTIFYFLAG
)))
5080 * Wait for a complete incoming message, parse it, and respond accordingly.
5083 ahd_parse_msg(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
)
5085 struct ahd_initiator_tinfo
*tinfo
;
5086 struct ahd_tmode_tstate
*tstate
;
5091 done
= MSGLOOP_IN_PROG
;
5094 tinfo
= ahd_fetch_transinfo(ahd
, devinfo
->channel
, devinfo
->our_scsiid
,
5095 devinfo
->target
, &tstate
);
5098 * Parse as much of the message as is available,
5099 * rejecting it if we don't support it. When
5100 * the entire message is available and has been
5101 * handled, return MSGLOOP_MSGCOMPLETE, indicating
5102 * that we have parsed an entire message.
5104 * In the case of extended messages, we accept the length
5105 * byte outright and perform more checking once we know the
5106 * extended message type.
5108 switch (ahd
->msgin_buf
[0]) {
5109 case MSG_DISCONNECT
:
5110 case MSG_SAVEDATAPOINTER
:
5111 case MSG_CMDCOMPLETE
:
5112 case MSG_RESTOREPOINTERS
:
5113 case MSG_IGN_WIDE_RESIDUE
:
5115 * End our message loop as these are messages
5116 * the sequencer handles on its own.
5118 done
= MSGLOOP_TERMINATED
;
5120 case MSG_MESSAGE_REJECT
:
5121 response
= ahd_handle_msg_reject(ahd
, devinfo
);
5124 done
= MSGLOOP_MSGCOMPLETE
;
5128 /* Wait for enough of the message to begin validation */
5129 if (ahd
->msgin_index
< 2)
5131 switch (ahd
->msgin_buf
[2]) {
5139 if (ahd
->msgin_buf
[1] != MSG_EXT_SDTR_LEN
) {
5145 * Wait until we have both args before validating
5146 * and acting on this message.
5148 * Add one to MSG_EXT_SDTR_LEN to account for
5149 * the extended message preamble.
5151 if (ahd
->msgin_index
< (MSG_EXT_SDTR_LEN
+ 1))
5154 period
= ahd
->msgin_buf
[3];
5156 saved_offset
= offset
= ahd
->msgin_buf
[4];
5157 ahd_devlimited_syncrate(ahd
, tinfo
, &period
,
5158 &ppr_options
, devinfo
->role
);
5159 ahd_validate_offset(ahd
, tinfo
, period
, &offset
,
5160 tinfo
->curr
.width
, devinfo
->role
);
5162 printk("(%s:%c:%d:%d): Received "
5163 "SDTR period %x, offset %x\n\t"
5164 "Filtered to period %x, offset %x\n",
5165 ahd_name(ahd
), devinfo
->channel
,
5166 devinfo
->target
, devinfo
->lun
,
5167 ahd
->msgin_buf
[3], saved_offset
,
5170 ahd_set_syncrate(ahd
, devinfo
, period
,
5171 offset
, ppr_options
,
5172 AHD_TRANS_ACTIVE
|AHD_TRANS_GOAL
,
5176 * See if we initiated Sync Negotiation
5177 * and didn't have to fall down to async
5180 if (ahd_sent_msg(ahd
, AHDMSG_EXT
, MSG_EXT_SDTR
, TRUE
)) {
5182 if (saved_offset
!= offset
) {
5183 /* Went too low - force async */
5188 * Send our own SDTR in reply
5191 && devinfo
->role
== ROLE_INITIATOR
) {
5192 printk("(%s:%c:%d:%d): Target "
5194 ahd_name(ahd
), devinfo
->channel
,
5195 devinfo
->target
, devinfo
->lun
);
5197 ahd
->msgout_index
= 0;
5198 ahd
->msgout_len
= 0;
5199 ahd_construct_sdtr(ahd
, devinfo
,
5201 ahd
->msgout_index
= 0;
5204 done
= MSGLOOP_MSGCOMPLETE
;
5211 u_int sending_reply
;
5213 sending_reply
= FALSE
;
5214 if (ahd
->msgin_buf
[1] != MSG_EXT_WDTR_LEN
) {
5220 * Wait until we have our arg before validating
5221 * and acting on this message.
5223 * Add one to MSG_EXT_WDTR_LEN to account for
5224 * the extended message preamble.
5226 if (ahd
->msgin_index
< (MSG_EXT_WDTR_LEN
+ 1))
5229 bus_width
= ahd
->msgin_buf
[3];
5230 saved_width
= bus_width
;
5231 ahd_validate_width(ahd
, tinfo
, &bus_width
,
5234 printk("(%s:%c:%d:%d): Received WDTR "
5235 "%x filtered to %x\n",
5236 ahd_name(ahd
), devinfo
->channel
,
5237 devinfo
->target
, devinfo
->lun
,
5238 saved_width
, bus_width
);
5241 if (ahd_sent_msg(ahd
, AHDMSG_EXT
, MSG_EXT_WDTR
, TRUE
)) {
5243 * Don't send a WDTR back to the
5244 * target, since we asked first.
5245 * If the width went higher than our
5246 * request, reject it.
5248 if (saved_width
> bus_width
) {
5250 printk("(%s:%c:%d:%d): requested %dBit "
5251 "transfers. Rejecting...\n",
5252 ahd_name(ahd
), devinfo
->channel
,
5253 devinfo
->target
, devinfo
->lun
,
5254 8 * (0x01 << bus_width
));
5259 * Send our own WDTR in reply
5262 && devinfo
->role
== ROLE_INITIATOR
) {
5263 printk("(%s:%c:%d:%d): Target "
5265 ahd_name(ahd
), devinfo
->channel
,
5266 devinfo
->target
, devinfo
->lun
);
5268 ahd
->msgout_index
= 0;
5269 ahd
->msgout_len
= 0;
5270 ahd_construct_wdtr(ahd
, devinfo
, bus_width
);
5271 ahd
->msgout_index
= 0;
5273 sending_reply
= TRUE
;
5276 * After a wide message, we are async, but
5277 * some devices don't seem to honor this portion
5278 * of the spec. Force a renegotiation of the
5279 * sync component of our transfer agreement even
5280 * if our goal is async. By updating our width
5281 * after forcing the negotiation, we avoid
5282 * renegotiating for width.
5284 ahd_update_neg_request(ahd
, devinfo
, tstate
,
5285 tinfo
, AHD_NEG_ALWAYS
);
5286 ahd_set_width(ahd
, devinfo
, bus_width
,
5287 AHD_TRANS_ACTIVE
|AHD_TRANS_GOAL
,
5289 if (sending_reply
== FALSE
&& reject
== FALSE
) {
5292 * We will always have an SDTR to send.
5294 ahd
->msgout_index
= 0;
5295 ahd
->msgout_len
= 0;
5296 ahd_build_transfer_msg(ahd
, devinfo
);
5297 ahd
->msgout_index
= 0;
5300 done
= MSGLOOP_MSGCOMPLETE
;
5311 u_int saved_ppr_options
;
5313 if (ahd
->msgin_buf
[1] != MSG_EXT_PPR_LEN
) {
5319 * Wait until we have all args before validating
5320 * and acting on this message.
5322 * Add one to MSG_EXT_PPR_LEN to account for
5323 * the extended message preamble.
5325 if (ahd
->msgin_index
< (MSG_EXT_PPR_LEN
+ 1))
5328 period
= ahd
->msgin_buf
[3];
5329 offset
= ahd
->msgin_buf
[5];
5330 bus_width
= ahd
->msgin_buf
[6];
5331 saved_width
= bus_width
;
5332 ppr_options
= ahd
->msgin_buf
[7];
5334 * According to the spec, a DT only
5335 * period factor with no DT option
5336 * set implies async.
5338 if ((ppr_options
& MSG_EXT_PPR_DT_REQ
) == 0
5341 saved_ppr_options
= ppr_options
;
5342 saved_offset
= offset
;
5345 * Transfer options are only available if we
5346 * are negotiating wide.
5349 ppr_options
&= MSG_EXT_PPR_QAS_REQ
;
5351 ahd_validate_width(ahd
, tinfo
, &bus_width
,
5353 ahd_devlimited_syncrate(ahd
, tinfo
, &period
,
5354 &ppr_options
, devinfo
->role
);
5355 ahd_validate_offset(ahd
, tinfo
, period
, &offset
,
5356 bus_width
, devinfo
->role
);
5358 if (ahd_sent_msg(ahd
, AHDMSG_EXT
, MSG_EXT_PPR
, TRUE
)) {
5360 * If we are unable to do any of the
5361 * requested options (we went too low),
5362 * then we'll have to reject the message.
5364 if (saved_width
> bus_width
5365 || saved_offset
!= offset
5366 || saved_ppr_options
!= ppr_options
) {
5374 if (devinfo
->role
!= ROLE_TARGET
)
5375 printk("(%s:%c:%d:%d): Target "
5377 ahd_name(ahd
), devinfo
->channel
,
5378 devinfo
->target
, devinfo
->lun
);
5380 printk("(%s:%c:%d:%d): Initiator "
5382 ahd_name(ahd
), devinfo
->channel
,
5383 devinfo
->target
, devinfo
->lun
);
5384 ahd
->msgout_index
= 0;
5385 ahd
->msgout_len
= 0;
5386 ahd_construct_ppr(ahd
, devinfo
, period
, offset
,
5387 bus_width
, ppr_options
);
5388 ahd
->msgout_index
= 0;
5392 printk("(%s:%c:%d:%d): Received PPR width %x, "
5393 "period %x, offset %x,options %x\n"
5394 "\tFiltered to width %x, period %x, "
5395 "offset %x, options %x\n",
5396 ahd_name(ahd
), devinfo
->channel
,
5397 devinfo
->target
, devinfo
->lun
,
5398 saved_width
, ahd
->msgin_buf
[3],
5399 saved_offset
, saved_ppr_options
,
5400 bus_width
, period
, offset
, ppr_options
);
5402 ahd_set_width(ahd
, devinfo
, bus_width
,
5403 AHD_TRANS_ACTIVE
|AHD_TRANS_GOAL
,
5405 ahd_set_syncrate(ahd
, devinfo
, period
,
5406 offset
, ppr_options
,
5407 AHD_TRANS_ACTIVE
|AHD_TRANS_GOAL
,
5410 done
= MSGLOOP_MSGCOMPLETE
;
5414 /* Unknown extended message. Reject it. */
5420 #ifdef AHD_TARGET_MODE
5421 case MSG_BUS_DEV_RESET
:
5422 ahd_handle_devreset(ahd
, devinfo
, CAM_LUN_WILDCARD
,
5424 "Bus Device Reset Received",
5425 /*verbose_level*/0);
5427 done
= MSGLOOP_TERMINATED
;
5431 case MSG_CLEAR_QUEUE
:
5435 /* Target mode messages */
5436 if (devinfo
->role
!= ROLE_TARGET
) {
5440 tag
= SCB_LIST_NULL
;
5441 if (ahd
->msgin_buf
[0] == MSG_ABORT_TAG
)
5442 tag
= ahd_inb(ahd
, INITIATOR_TAG
);
5443 ahd_abort_scbs(ahd
, devinfo
->target
, devinfo
->channel
,
5444 devinfo
->lun
, tag
, ROLE_TARGET
,
5447 tstate
= ahd
->enabled_targets
[devinfo
->our_scsiid
];
5448 if (tstate
!= NULL
) {
5449 struct ahd_tmode_lstate
* lstate
;
5451 lstate
= tstate
->enabled_luns
[devinfo
->lun
];
5452 if (lstate
!= NULL
) {
5453 ahd_queue_lstate_event(ahd
, lstate
,
5454 devinfo
->our_scsiid
,
5457 ahd_send_lstate_events(ahd
, lstate
);
5461 done
= MSGLOOP_TERMINATED
;
5465 case MSG_QAS_REQUEST
:
5467 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
5468 printk("%s: QAS request. SCSISIGI == 0x%x\n",
5469 ahd_name(ahd
), ahd_inb(ahd
, SCSISIGI
));
5471 ahd
->msg_flags
|= MSG_FLAG_EXPECT_QASREJ_BUSFREE
;
5473 case MSG_TERM_IO_PROC
:
5481 * Setup to reject the message.
5483 ahd
->msgout_index
= 0;
5484 ahd
->msgout_len
= 1;
5485 ahd
->msgout_buf
[0] = MSG_MESSAGE_REJECT
;
5486 done
= MSGLOOP_MSGCOMPLETE
;
5490 if (done
!= MSGLOOP_IN_PROG
&& !response
)
5491 /* Clear the outgoing message buffer */
5492 ahd
->msgout_len
= 0;
5498 * Process a message reject message.
5501 ahd_handle_msg_reject(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
)
5504 * What we care about here is if we had an
5505 * outstanding SDTR or WDTR message for this
5506 * target. If we did, this is a signal that
5507 * the target is refusing negotiation.
5510 struct ahd_initiator_tinfo
*tinfo
;
5511 struct ahd_tmode_tstate
*tstate
;
5516 scb_index
= ahd_get_scbptr(ahd
);
5517 scb
= ahd_lookup_scb(ahd
, scb_index
);
5518 tinfo
= ahd_fetch_transinfo(ahd
, devinfo
->channel
,
5519 devinfo
->our_scsiid
,
5520 devinfo
->target
, &tstate
);
5521 /* Might be necessary */
5522 last_msg
= ahd_inb(ahd
, LAST_MSG
);
5524 if (ahd_sent_msg(ahd
, AHDMSG_EXT
, MSG_EXT_PPR
, /*full*/FALSE
)) {
5525 if (ahd_sent_msg(ahd
, AHDMSG_EXT
, MSG_EXT_PPR
, /*full*/TRUE
)
5526 && tinfo
->goal
.period
<= AHD_SYNCRATE_PACED
) {
5528 * Target may not like our SPI-4 PPR Options.
5529 * Attempt to negotiate 80MHz which will turn
5530 * off these options.
5533 printk("(%s:%c:%d:%d): PPR Rejected. "
5534 "Trying simple U160 PPR\n",
5535 ahd_name(ahd
), devinfo
->channel
,
5536 devinfo
->target
, devinfo
->lun
);
5538 tinfo
->goal
.period
= AHD_SYNCRATE_DT
;
5539 tinfo
->goal
.ppr_options
&= MSG_EXT_PPR_IU_REQ
5540 | MSG_EXT_PPR_QAS_REQ
5541 | MSG_EXT_PPR_DT_REQ
;
5544 * Target does not support the PPR message.
5545 * Attempt to negotiate SPI-2 style.
5548 printk("(%s:%c:%d:%d): PPR Rejected. "
5549 "Trying WDTR/SDTR\n",
5550 ahd_name(ahd
), devinfo
->channel
,
5551 devinfo
->target
, devinfo
->lun
);
5553 tinfo
->goal
.ppr_options
= 0;
5554 tinfo
->curr
.transport_version
= 2;
5555 tinfo
->goal
.transport_version
= 2;
5557 ahd
->msgout_index
= 0;
5558 ahd
->msgout_len
= 0;
5559 ahd_build_transfer_msg(ahd
, devinfo
);
5560 ahd
->msgout_index
= 0;
5562 } else if (ahd_sent_msg(ahd
, AHDMSG_EXT
, MSG_EXT_WDTR
, /*full*/FALSE
)) {
5564 /* note 8bit xfers */
5565 printk("(%s:%c:%d:%d): refuses WIDE negotiation. Using "
5566 "8bit transfers\n", ahd_name(ahd
),
5567 devinfo
->channel
, devinfo
->target
, devinfo
->lun
);
5568 ahd_set_width(ahd
, devinfo
, MSG_EXT_WDTR_BUS_8_BIT
,
5569 AHD_TRANS_ACTIVE
|AHD_TRANS_GOAL
,
5572 * No need to clear the sync rate. If the target
5573 * did not accept the command, our syncrate is
5574 * unaffected. If the target started the negotiation,
5575 * but rejected our response, we already cleared the
5576 * sync rate before sending our WDTR.
5578 if (tinfo
->goal
.offset
!= tinfo
->curr
.offset
) {
5580 /* Start the sync negotiation */
5581 ahd
->msgout_index
= 0;
5582 ahd
->msgout_len
= 0;
5583 ahd_build_transfer_msg(ahd
, devinfo
);
5584 ahd
->msgout_index
= 0;
5587 } else if (ahd_sent_msg(ahd
, AHDMSG_EXT
, MSG_EXT_SDTR
, /*full*/FALSE
)) {
5588 /* note asynch xfers and clear flag */
5589 ahd_set_syncrate(ahd
, devinfo
, /*period*/0,
5590 /*offset*/0, /*ppr_options*/0,
5591 AHD_TRANS_ACTIVE
|AHD_TRANS_GOAL
,
5593 printk("(%s:%c:%d:%d): refuses synchronous negotiation. "
5594 "Using asynchronous transfers\n",
5595 ahd_name(ahd
), devinfo
->channel
,
5596 devinfo
->target
, devinfo
->lun
);
5597 } else if ((scb
->hscb
->control
& MSG_SIMPLE_TASK
) != 0) {
5601 tag_type
= (scb
->hscb
->control
& MSG_SIMPLE_TASK
);
5603 if (tag_type
== MSG_SIMPLE_TASK
) {
5604 printk("(%s:%c:%d:%d): refuses tagged commands. "
5605 "Performing non-tagged I/O\n", ahd_name(ahd
),
5606 devinfo
->channel
, devinfo
->target
, devinfo
->lun
);
5607 ahd_set_tags(ahd
, scb
->io_ctx
, devinfo
, AHD_QUEUE_NONE
);
5610 printk("(%s:%c:%d:%d): refuses %s tagged commands. "
5611 "Performing simple queue tagged I/O only\n",
5612 ahd_name(ahd
), devinfo
->channel
, devinfo
->target
,
5613 devinfo
->lun
, tag_type
== MSG_ORDERED_TASK
5614 ? "ordered" : "head of queue");
5615 ahd_set_tags(ahd
, scb
->io_ctx
, devinfo
, AHD_QUEUE_BASIC
);
5620 * Resend the identify for this CCB as the target
5621 * may believe that the selection is invalid otherwise.
5623 ahd_outb(ahd
, SCB_CONTROL
,
5624 ahd_inb_scbram(ahd
, SCB_CONTROL
) & mask
);
5625 scb
->hscb
->control
&= mask
;
5626 ahd_set_transaction_tag(scb
, /*enabled*/FALSE
,
5627 /*type*/MSG_SIMPLE_TASK
);
5628 ahd_outb(ahd
, MSG_OUT
, MSG_IDENTIFYFLAG
);
5629 ahd_assert_atn(ahd
);
5630 ahd_busy_tcl(ahd
, BUILD_TCL(scb
->hscb
->scsiid
, devinfo
->lun
),
5634 * Requeue all tagged commands for this target
5635 * currently in our possession so they can be
5636 * converted to untagged commands.
5638 ahd_search_qinfifo(ahd
, SCB_GET_TARGET(ahd
, scb
),
5639 SCB_GET_CHANNEL(ahd
, scb
),
5640 SCB_GET_LUN(scb
), /*tag*/SCB_LIST_NULL
,
5641 ROLE_INITIATOR
, CAM_REQUEUE_REQ
,
5643 } else if (ahd_sent_msg(ahd
, AHDMSG_1B
, MSG_IDENTIFYFLAG
, TRUE
)) {
5645 * Most likely the device believes that we had
5646 * previously negotiated packetized.
5648 ahd
->msg_flags
|= MSG_FLAG_EXPECT_PPR_BUSFREE
5649 | MSG_FLAG_IU_REQ_CHANGED
;
5651 ahd_force_renegotiation(ahd
, devinfo
);
5652 ahd
->msgout_index
= 0;
5653 ahd
->msgout_len
= 0;
5654 ahd_build_transfer_msg(ahd
, devinfo
);
5655 ahd
->msgout_index
= 0;
5659 * Otherwise, we ignore it.
5661 printk("%s:%c:%d: Message reject for %x -- ignored\n",
5662 ahd_name(ahd
), devinfo
->channel
, devinfo
->target
,
5669 * Process an ingnore wide residue message.
5672 ahd_handle_ign_wide_residue(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
)
5677 scb_index
= ahd_get_scbptr(ahd
);
5678 scb
= ahd_lookup_scb(ahd
, scb_index
);
5680 * XXX Actually check data direction in the sequencer?
5681 * Perhaps add datadir to some spare bits in the hscb?
5683 if ((ahd_inb(ahd
, SEQ_FLAGS
) & DPHASE
) == 0
5684 || ahd_get_transfer_dir(scb
) != CAM_DIR_IN
) {
5686 * Ignore the message if we haven't
5687 * seen an appropriate data phase yet.
5691 * If the residual occurred on the last
5692 * transfer and the transfer request was
5693 * expected to end on an odd count, do
5694 * nothing. Otherwise, subtract a byte
5695 * and update the residual count accordingly.
5699 sgptr
= ahd_inb_scbram(ahd
, SCB_RESIDUAL_SGPTR
);
5700 if ((sgptr
& SG_LIST_NULL
) != 0
5701 && (ahd_inb_scbram(ahd
, SCB_TASK_ATTRIBUTE
)
5702 & SCB_XFERLEN_ODD
) != 0) {
5704 * If the residual occurred on the last
5705 * transfer and the transfer request was
5706 * expected to end on an odd count, do
5714 /* Pull in the rest of the sgptr */
5715 sgptr
= ahd_inl_scbram(ahd
, SCB_RESIDUAL_SGPTR
);
5716 data_cnt
= ahd_inl_scbram(ahd
, SCB_RESIDUAL_DATACNT
);
5717 if ((sgptr
& SG_LIST_NULL
) != 0) {
5719 * The residual data count is not updated
5720 * for the command run to completion case.
5721 * Explicitly zero the count.
5723 data_cnt
&= ~AHD_SG_LEN_MASK
;
5725 data_addr
= ahd_inq(ahd
, SHADDR
);
5728 sgptr
&= SG_PTR_MASK
;
5729 if ((ahd
->flags
& AHD_64BIT_ADDRESSING
) != 0) {
5730 struct ahd_dma64_seg
*sg
;
5732 sg
= ahd_sg_bus_to_virt(ahd
, scb
, sgptr
);
5735 * The residual sg ptr points to the next S/G
5736 * to load so we must go back one.
5739 sglen
= ahd_le32toh(sg
->len
) & AHD_SG_LEN_MASK
;
5740 if (sg
!= scb
->sg_list
5741 && sglen
< (data_cnt
& AHD_SG_LEN_MASK
)) {
5744 sglen
= ahd_le32toh(sg
->len
);
5746 * Preserve High Address and SG_LIST
5747 * bits while setting the count to 1.
5749 data_cnt
= 1|(sglen
&(~AHD_SG_LEN_MASK
));
5750 data_addr
= ahd_le64toh(sg
->addr
)
5751 + (sglen
& AHD_SG_LEN_MASK
)
5755 * Increment sg so it points to the
5759 sgptr
= ahd_sg_virt_to_bus(ahd
, scb
,
5763 struct ahd_dma_seg
*sg
;
5765 sg
= ahd_sg_bus_to_virt(ahd
, scb
, sgptr
);
5768 * The residual sg ptr points to the next S/G
5769 * to load so we must go back one.
5772 sglen
= ahd_le32toh(sg
->len
) & AHD_SG_LEN_MASK
;
5773 if (sg
!= scb
->sg_list
5774 && sglen
< (data_cnt
& AHD_SG_LEN_MASK
)) {
5777 sglen
= ahd_le32toh(sg
->len
);
5779 * Preserve High Address and SG_LIST
5780 * bits while setting the count to 1.
5782 data_cnt
= 1|(sglen
&(~AHD_SG_LEN_MASK
));
5783 data_addr
= ahd_le32toh(sg
->addr
)
5784 + (sglen
& AHD_SG_LEN_MASK
)
5788 * Increment sg so it points to the
5792 sgptr
= ahd_sg_virt_to_bus(ahd
, scb
,
5797 * Toggle the "oddness" of the transfer length
5798 * to handle this mid-transfer ignore wide
5799 * residue. This ensures that the oddness is
5800 * correct for subsequent data transfers.
5802 ahd_outb(ahd
, SCB_TASK_ATTRIBUTE
,
5803 ahd_inb_scbram(ahd
, SCB_TASK_ATTRIBUTE
)
5806 ahd_outl(ahd
, SCB_RESIDUAL_SGPTR
, sgptr
);
5807 ahd_outl(ahd
, SCB_RESIDUAL_DATACNT
, data_cnt
);
5809 * The FIFO's pointers will be updated if/when the
5810 * sequencer re-enters a data phase.
5818 * Reinitialize the data pointers for the active transfer
5819 * based on its current residual.
5822 ahd_reinitialize_dataptrs(struct ahd_softc
*ahd
)
5825 ahd_mode_state saved_modes
;
5832 AHD_ASSERT_MODES(ahd
, AHD_MODE_DFF0_MSK
|AHD_MODE_DFF1_MSK
,
5833 AHD_MODE_DFF0_MSK
|AHD_MODE_DFF1_MSK
);
5835 scb_index
= ahd_get_scbptr(ahd
);
5836 scb
= ahd_lookup_scb(ahd
, scb_index
);
5839 * Release and reacquire the FIFO so we
5840 * have a clean slate.
5842 ahd_outb(ahd
, DFFSXFRCTL
, CLRCHN
);
5844 while (--wait
&& !(ahd_inb(ahd
, MDFFSTAT
) & FIFOFREE
))
5847 ahd_print_path(ahd
, scb
);
5848 printk("ahd_reinitialize_dataptrs: Forcing FIFO free.\n");
5849 ahd_outb(ahd
, DFFSXFRCTL
, RSTCHN
|CLRSHCNT
);
5851 saved_modes
= ahd_save_modes(ahd
);
5852 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
5853 ahd_outb(ahd
, DFFSTAT
,
5854 ahd_inb(ahd
, DFFSTAT
)
5855 | (saved_modes
== 0x11 ? CURRFIFO_1
: CURRFIFO_0
));
5858 * Determine initial values for data_addr and data_cnt
5859 * for resuming the data phase.
5861 sgptr
= ahd_inl_scbram(ahd
, SCB_RESIDUAL_SGPTR
);
5862 sgptr
&= SG_PTR_MASK
;
5864 resid
= (ahd_inb_scbram(ahd
, SCB_RESIDUAL_DATACNT
+ 2) << 16)
5865 | (ahd_inb_scbram(ahd
, SCB_RESIDUAL_DATACNT
+ 1) << 8)
5866 | ahd_inb_scbram(ahd
, SCB_RESIDUAL_DATACNT
);
5868 if ((ahd
->flags
& AHD_64BIT_ADDRESSING
) != 0) {
5869 struct ahd_dma64_seg
*sg
;
5871 sg
= ahd_sg_bus_to_virt(ahd
, scb
, sgptr
);
5873 /* The residual sg_ptr always points to the next sg */
5876 dataptr
= ahd_le64toh(sg
->addr
)
5877 + (ahd_le32toh(sg
->len
) & AHD_SG_LEN_MASK
)
5879 ahd_outl(ahd
, HADDR
+ 4, dataptr
>> 32);
5881 struct ahd_dma_seg
*sg
;
5883 sg
= ahd_sg_bus_to_virt(ahd
, scb
, sgptr
);
5885 /* The residual sg_ptr always points to the next sg */
5888 dataptr
= ahd_le32toh(sg
->addr
)
5889 + (ahd_le32toh(sg
->len
) & AHD_SG_LEN_MASK
)
5891 ahd_outb(ahd
, HADDR
+ 4,
5892 (ahd_le32toh(sg
->len
) & ~AHD_SG_LEN_MASK
) >> 24);
5894 ahd_outl(ahd
, HADDR
, dataptr
);
5895 ahd_outb(ahd
, HCNT
+ 2, resid
>> 16);
5896 ahd_outb(ahd
, HCNT
+ 1, resid
>> 8);
5897 ahd_outb(ahd
, HCNT
, resid
);
5901 * Handle the effects of issuing a bus device reset message.
5904 ahd_handle_devreset(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
,
5905 u_int lun
, cam_status status
, char *message
,
5908 #ifdef AHD_TARGET_MODE
5909 struct ahd_tmode_tstate
* tstate
;
5913 found
= ahd_abort_scbs(ahd
, devinfo
->target
, devinfo
->channel
,
5914 lun
, SCB_LIST_NULL
, devinfo
->role
,
5917 #ifdef AHD_TARGET_MODE
5919 * Send an immediate notify ccb to all target mord peripheral
5920 * drivers affected by this action.
5922 tstate
= ahd
->enabled_targets
[devinfo
->our_scsiid
];
5923 if (tstate
!= NULL
) {
5927 if (lun
!= CAM_LUN_WILDCARD
) {
5929 max_lun
= AHD_NUM_LUNS
- 1;
5934 for (;cur_lun
<= max_lun
; cur_lun
++) {
5935 struct ahd_tmode_lstate
* lstate
;
5937 lstate
= tstate
->enabled_luns
[cur_lun
];
5941 ahd_queue_lstate_event(ahd
, lstate
, devinfo
->our_scsiid
,
5942 MSG_BUS_DEV_RESET
, /*arg*/0);
5943 ahd_send_lstate_events(ahd
, lstate
);
5949 * Go back to async/narrow transfers and renegotiate.
5951 ahd_set_width(ahd
, devinfo
, MSG_EXT_WDTR_BUS_8_BIT
,
5952 AHD_TRANS_CUR
, /*paused*/TRUE
);
5953 ahd_set_syncrate(ahd
, devinfo
, /*period*/0, /*offset*/0,
5954 /*ppr_options*/0, AHD_TRANS_CUR
,
5957 if (status
!= CAM_SEL_TIMEOUT
)
5958 ahd_send_async(ahd
, devinfo
->channel
, devinfo
->target
,
5959 CAM_LUN_WILDCARD
, AC_SENT_BDR
);
5961 if (message
!= NULL
&& bootverbose
)
5962 printk("%s: %s on %c:%d. %d SCBs aborted\n", ahd_name(ahd
),
5963 message
, devinfo
->channel
, devinfo
->target
, found
);
5966 #ifdef AHD_TARGET_MODE
5968 ahd_setup_target_msgin(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
,
5973 * To facilitate adding multiple messages together,
5974 * each routine should increment the index and len
5975 * variables instead of setting them explicitly.
5977 ahd
->msgout_index
= 0;
5978 ahd
->msgout_len
= 0;
5980 if (scb
!= NULL
&& (scb
->flags
& SCB_AUTO_NEGOTIATE
) != 0)
5981 ahd_build_transfer_msg(ahd
, devinfo
);
5983 panic("ahd_intr: AWAITING target message with no message");
5985 ahd
->msgout_index
= 0;
5986 ahd
->msg_type
= MSG_TYPE_TARGET_MSGIN
;
5989 /**************************** Initialization **********************************/
5991 ahd_sglist_size(struct ahd_softc
*ahd
)
5993 bus_size_t list_size
;
5995 list_size
= sizeof(struct ahd_dma_seg
) * AHD_NSEG
;
5996 if ((ahd
->flags
& AHD_64BIT_ADDRESSING
) != 0)
5997 list_size
= sizeof(struct ahd_dma64_seg
) * AHD_NSEG
;
6002 * Calculate the optimum S/G List allocation size. S/G elements used
6003 * for a given transaction must be physically contiguous. Assume the
6004 * OS will allocate full pages to us, so it doesn't make sense to request
6008 ahd_sglist_allocsize(struct ahd_softc
*ahd
)
6010 bus_size_t sg_list_increment
;
6011 bus_size_t sg_list_size
;
6012 bus_size_t max_list_size
;
6013 bus_size_t best_list_size
;
6015 /* Start out with the minimum required for AHD_NSEG. */
6016 sg_list_increment
= ahd_sglist_size(ahd
);
6017 sg_list_size
= sg_list_increment
;
6019 /* Get us as close as possible to a page in size. */
6020 while ((sg_list_size
+ sg_list_increment
) <= PAGE_SIZE
)
6021 sg_list_size
+= sg_list_increment
;
6024 * Try to reduce the amount of wastage by allocating
6027 best_list_size
= sg_list_size
;
6028 max_list_size
= roundup(sg_list_increment
, PAGE_SIZE
);
6029 if (max_list_size
< 4 * PAGE_SIZE
)
6030 max_list_size
= 4 * PAGE_SIZE
;
6031 if (max_list_size
> (AHD_SCB_MAX_ALLOC
* sg_list_increment
))
6032 max_list_size
= (AHD_SCB_MAX_ALLOC
* sg_list_increment
);
6033 while ((sg_list_size
+ sg_list_increment
) <= max_list_size
6034 && (sg_list_size
% PAGE_SIZE
) != 0) {
6036 bus_size_t best_mod
;
6038 sg_list_size
+= sg_list_increment
;
6039 new_mod
= sg_list_size
% PAGE_SIZE
;
6040 best_mod
= best_list_size
% PAGE_SIZE
;
6041 if (new_mod
> best_mod
|| new_mod
== 0) {
6042 best_list_size
= sg_list_size
;
6045 return (best_list_size
);
6049 * Allocate a controller structure for a new device
6050 * and perform initial initializion.
6053 ahd_alloc(void *platform_arg
, char *name
)
6055 struct ahd_softc
*ahd
;
6057 ahd
= kmalloc(sizeof(*ahd
), GFP_ATOMIC
);
6059 printk("aic7xxx: cannot malloc softc!\n");
6064 memset(ahd
, 0, sizeof(*ahd
));
6065 ahd
->seep_config
= kmalloc(sizeof(*ahd
->seep_config
), GFP_ATOMIC
);
6066 if (ahd
->seep_config
== NULL
) {
6071 LIST_INIT(&ahd
->pending_scbs
);
6072 /* We don't know our unit number until the OSM sets it */
6075 ahd
->description
= NULL
;
6076 ahd
->bus_description
= NULL
;
6078 ahd
->chip
= AHD_NONE
;
6079 ahd
->features
= AHD_FENONE
;
6080 ahd
->bugs
= AHD_BUGNONE
;
6081 ahd
->flags
= AHD_SPCHK_ENB_A
|AHD_RESET_BUS_A
|AHD_TERM_ENB_A
6082 | AHD_EXTENDED_TRANS_A
|AHD_STPWLEVEL_A
;
6083 timer_setup(&ahd
->stat_timer
, ahd_stat_timer
, 0);
6084 ahd
->int_coalescing_timer
= AHD_INT_COALESCING_TIMER_DEFAULT
;
6085 ahd
->int_coalescing_maxcmds
= AHD_INT_COALESCING_MAXCMDS_DEFAULT
;
6086 ahd
->int_coalescing_mincmds
= AHD_INT_COALESCING_MINCMDS_DEFAULT
;
6087 ahd
->int_coalescing_threshold
= AHD_INT_COALESCING_THRESHOLD_DEFAULT
;
6088 ahd
->int_coalescing_stop_threshold
=
6089 AHD_INT_COALESCING_STOP_THRESHOLD_DEFAULT
;
6092 if ((ahd_debug
& AHD_SHOW_MEMORY
) != 0) {
6093 printk("%s: scb size = 0x%x, hscb size = 0x%x\n",
6094 ahd_name(ahd
), (u_int
)sizeof(struct scb
),
6095 (u_int
)sizeof(struct hardware_scb
));
6098 if (ahd_platform_alloc(ahd
, platform_arg
) != 0) {
6106 ahd_softc_init(struct ahd_softc
*ahd
)
6115 ahd_set_unit(struct ahd_softc
*ahd
, int unit
)
6121 ahd_set_name(struct ahd_softc
*ahd
, char *name
)
6123 if (ahd
->name
!= NULL
)
6129 ahd_free(struct ahd_softc
*ahd
)
6133 switch (ahd
->init_level
) {
6139 ahd_dmamap_unload(ahd
, ahd
->shared_data_dmat
,
6140 ahd
->shared_data_map
.dmamap
);
6143 ahd_dmamem_free(ahd
, ahd
->shared_data_dmat
, ahd
->qoutfifo
,
6144 ahd
->shared_data_map
.dmamap
);
6145 ahd_dmamap_destroy(ahd
, ahd
->shared_data_dmat
,
6146 ahd
->shared_data_map
.dmamap
);
6149 ahd_dma_tag_destroy(ahd
, ahd
->shared_data_dmat
);
6156 ahd_platform_free(ahd
);
6157 ahd_fini_scbdata(ahd
);
6158 for (i
= 0; i
< AHD_NUM_TARGETS
; i
++) {
6159 struct ahd_tmode_tstate
*tstate
;
6161 tstate
= ahd
->enabled_targets
[i
];
6162 if (tstate
!= NULL
) {
6163 #ifdef AHD_TARGET_MODE
6166 for (j
= 0; j
< AHD_NUM_LUNS
; j
++) {
6167 struct ahd_tmode_lstate
*lstate
;
6169 lstate
= tstate
->enabled_luns
[j
];
6170 if (lstate
!= NULL
) {
6171 xpt_free_path(lstate
->path
);
6179 #ifdef AHD_TARGET_MODE
6180 if (ahd
->black_hole
!= NULL
) {
6181 xpt_free_path(ahd
->black_hole
->path
);
6182 kfree(ahd
->black_hole
);
6185 if (ahd
->name
!= NULL
)
6187 if (ahd
->seep_config
!= NULL
)
6188 kfree(ahd
->seep_config
);
6189 if (ahd
->saved_stack
!= NULL
)
6190 kfree(ahd
->saved_stack
);
6196 ahd_shutdown(void *arg
)
6198 struct ahd_softc
*ahd
;
6200 ahd
= (struct ahd_softc
*)arg
;
6203 * Stop periodic timer callbacks.
6205 del_timer_sync(&ahd
->stat_timer
);
6207 /* This will reset most registers to 0, but not all */
6208 ahd_reset(ahd
, /*reinit*/FALSE
);
6212 * Reset the controller and record some information about it
6213 * that is only available just after a reset. If "reinit" is
6214 * non-zero, this reset occurred after initial configuration
6215 * and the caller requests that the chip be fully reinitialized
6216 * to a runable state. Chip interrupts are *not* enabled after
6217 * a reinitialization. The caller must enable interrupts via
6218 * ahd_intr_enable().
6221 ahd_reset(struct ahd_softc
*ahd
, int reinit
)
6228 * Preserve the value of the SXFRCTL1 register for all channels.
6229 * It contains settings that affect termination and we don't want
6230 * to disturb the integrity of the bus.
6233 ahd_update_modes(ahd
);
6234 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
6235 sxfrctl1
= ahd_inb(ahd
, SXFRCTL1
);
6237 cmd
= ahd_pci_read_config(ahd
->dev_softc
, PCIR_COMMAND
, /*bytes*/2);
6238 if ((ahd
->bugs
& AHD_PCIX_CHIPRST_BUG
) != 0) {
6243 * During the assertion of CHIPRST, the chip
6244 * does not disable its parity logic prior to
6245 * the start of the reset. This may cause a
6246 * parity error to be detected and thus a
6247 * spurious SERR or PERR assertion. Disable
6248 * PERR and SERR responses during the CHIPRST.
6250 mod_cmd
= cmd
& ~(PCIM_CMD_PERRESPEN
|PCIM_CMD_SERRESPEN
);
6251 ahd_pci_write_config(ahd
->dev_softc
, PCIR_COMMAND
,
6252 mod_cmd
, /*bytes*/2);
6254 ahd_outb(ahd
, HCNTRL
, CHIPRST
| ahd
->pause
);
6257 * Ensure that the reset has finished. We delay 1000us
6258 * prior to reading the register to make sure the chip
6259 * has sufficiently completed its reset to handle register
6265 } while (--wait
&& !(ahd_inb(ahd
, HCNTRL
) & CHIPRSTACK
));
6268 printk("%s: WARNING - Failed chip reset! "
6269 "Trying to initialize anyway.\n", ahd_name(ahd
));
6271 ahd_outb(ahd
, HCNTRL
, ahd
->pause
);
6273 if ((ahd
->bugs
& AHD_PCIX_CHIPRST_BUG
) != 0) {
6275 * Clear any latched PCI error status and restore
6276 * previous SERR and PERR response enables.
6278 ahd_pci_write_config(ahd
->dev_softc
, PCIR_STATUS
+ 1,
6280 ahd_pci_write_config(ahd
->dev_softc
, PCIR_COMMAND
,
6285 * Mode should be SCSI after a chip reset, but lets
6286 * set it just to be safe. We touch the MODE_PTR
6287 * register directly so as to bypass the lazy update
6288 * code in ahd_set_modes().
6290 ahd_known_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
6291 ahd_outb(ahd
, MODE_PTR
,
6292 ahd_build_mode_state(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
));
6297 * We must always initialize STPWEN to 1 before we
6298 * restore the saved values. STPWEN is initialized
6299 * to a tri-state condition which can only be cleared
6302 ahd_outb(ahd
, SXFRCTL1
, sxfrctl1
|STPWEN
);
6303 ahd_outb(ahd
, SXFRCTL1
, sxfrctl1
);
6305 /* Determine chip configuration */
6306 ahd
->features
&= ~AHD_WIDE
;
6307 if ((ahd_inb(ahd
, SBLKCTL
) & SELWIDE
) != 0)
6308 ahd
->features
|= AHD_WIDE
;
6311 * If a recovery action has forced a chip reset,
6312 * re-initialize the chip to our liking.
6321 * Determine the number of SCBs available on the controller
6324 ahd_probe_scbs(struct ahd_softc
*ahd
) {
6327 AHD_ASSERT_MODES(ahd
, ~(AHD_MODE_UNKNOWN_MSK
|AHD_MODE_CFG_MSK
),
6328 ~(AHD_MODE_UNKNOWN_MSK
|AHD_MODE_CFG_MSK
));
6329 for (i
= 0; i
< AHD_SCB_MAX
; i
++) {
6332 ahd_set_scbptr(ahd
, i
);
6333 ahd_outw(ahd
, SCB_BASE
, i
);
6334 for (j
= 2; j
< 64; j
++)
6335 ahd_outb(ahd
, SCB_BASE
+j
, 0);
6336 /* Start out life as unallocated (needing an abort) */
6337 ahd_outb(ahd
, SCB_CONTROL
, MK_MESSAGE
);
6338 if (ahd_inw_scbram(ahd
, SCB_BASE
) != i
)
6340 ahd_set_scbptr(ahd
, 0);
6341 if (ahd_inw_scbram(ahd
, SCB_BASE
) != 0)
6348 ahd_dmamap_cb(void *arg
, bus_dma_segment_t
*segs
, int nseg
, int error
)
6352 baddr
= (dma_addr_t
*)arg
;
6353 *baddr
= segs
->ds_addr
;
6357 ahd_initialize_hscbs(struct ahd_softc
*ahd
)
6361 for (i
= 0; i
< ahd
->scb_data
.maxhscbs
; i
++) {
6362 ahd_set_scbptr(ahd
, i
);
6364 /* Clear the control byte. */
6365 ahd_outb(ahd
, SCB_CONTROL
, 0);
6367 /* Set the next pointer */
6368 ahd_outw(ahd
, SCB_NEXT
, SCB_LIST_NULL
);
6373 ahd_init_scbdata(struct ahd_softc
*ahd
)
6375 struct scb_data
*scb_data
;
6378 scb_data
= &ahd
->scb_data
;
6379 TAILQ_INIT(&scb_data
->free_scbs
);
6380 for (i
= 0; i
< AHD_NUM_TARGETS
* AHD_NUM_LUNS_NONPKT
; i
++)
6381 LIST_INIT(&scb_data
->free_scb_lists
[i
]);
6382 LIST_INIT(&scb_data
->any_dev_free_scb_list
);
6383 SLIST_INIT(&scb_data
->hscb_maps
);
6384 SLIST_INIT(&scb_data
->sg_maps
);
6385 SLIST_INIT(&scb_data
->sense_maps
);
6387 /* Determine the number of hardware SCBs and initialize them */
6388 scb_data
->maxhscbs
= ahd_probe_scbs(ahd
);
6389 if (scb_data
->maxhscbs
== 0) {
6390 printk("%s: No SCB space found\n", ahd_name(ahd
));
6394 ahd_initialize_hscbs(ahd
);
6397 * Create our DMA tags. These tags define the kinds of device
6398 * accessible memory allocations and memory mappings we will
6399 * need to perform during normal operation.
6401 * Unless we need to further restrict the allocation, we rely
6402 * on the restrictions of the parent dmat, hence the common
6403 * use of MAXADDR and MAXSIZE.
6406 /* DMA tag for our hardware scb structures */
6407 if (ahd_dma_tag_create(ahd
, ahd
->parent_dmat
, /*alignment*/1,
6408 /*boundary*/BUS_SPACE_MAXADDR_32BIT
+ 1,
6409 /*lowaddr*/BUS_SPACE_MAXADDR_32BIT
,
6410 /*highaddr*/BUS_SPACE_MAXADDR
,
6411 /*filter*/NULL
, /*filterarg*/NULL
,
6412 PAGE_SIZE
, /*nsegments*/1,
6413 /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT
,
6414 /*flags*/0, &scb_data
->hscb_dmat
) != 0) {
6418 scb_data
->init_level
++;
6420 /* DMA tag for our S/G structures. */
6421 if (ahd_dma_tag_create(ahd
, ahd
->parent_dmat
, /*alignment*/8,
6422 /*boundary*/BUS_SPACE_MAXADDR_32BIT
+ 1,
6423 /*lowaddr*/BUS_SPACE_MAXADDR_32BIT
,
6424 /*highaddr*/BUS_SPACE_MAXADDR
,
6425 /*filter*/NULL
, /*filterarg*/NULL
,
6426 ahd_sglist_allocsize(ahd
), /*nsegments*/1,
6427 /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT
,
6428 /*flags*/0, &scb_data
->sg_dmat
) != 0) {
6432 if ((ahd_debug
& AHD_SHOW_MEMORY
) != 0)
6433 printk("%s: ahd_sglist_allocsize = 0x%x\n", ahd_name(ahd
),
6434 ahd_sglist_allocsize(ahd
));
6437 scb_data
->init_level
++;
6439 /* DMA tag for our sense buffers. We allocate in page sized chunks */
6440 if (ahd_dma_tag_create(ahd
, ahd
->parent_dmat
, /*alignment*/1,
6441 /*boundary*/BUS_SPACE_MAXADDR_32BIT
+ 1,
6442 /*lowaddr*/BUS_SPACE_MAXADDR_32BIT
,
6443 /*highaddr*/BUS_SPACE_MAXADDR
,
6444 /*filter*/NULL
, /*filterarg*/NULL
,
6445 PAGE_SIZE
, /*nsegments*/1,
6446 /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT
,
6447 /*flags*/0, &scb_data
->sense_dmat
) != 0) {
6451 scb_data
->init_level
++;
6453 /* Perform initial CCB allocation */
6454 ahd_alloc_scbs(ahd
);
6456 if (scb_data
->numscbs
== 0) {
6457 printk("%s: ahd_init_scbdata - "
6458 "Unable to allocate initial scbs\n",
6464 * Note that we were successful
6474 ahd_find_scb_by_tag(struct ahd_softc
*ahd
, u_int tag
)
6479 * Look on the pending list.
6481 LIST_FOREACH(scb
, &ahd
->pending_scbs
, pending_links
) {
6482 if (SCB_GET_TAG(scb
) == tag
)
6487 * Then on all of the collision free lists.
6489 TAILQ_FOREACH(scb
, &ahd
->scb_data
.free_scbs
, links
.tqe
) {
6490 struct scb
*list_scb
;
6494 if (SCB_GET_TAG(list_scb
) == tag
)
6496 list_scb
= LIST_NEXT(list_scb
, collision_links
);
6501 * And finally on the generic free list.
6503 LIST_FOREACH(scb
, &ahd
->scb_data
.any_dev_free_scb_list
, links
.le
) {
6504 if (SCB_GET_TAG(scb
) == tag
)
6512 ahd_fini_scbdata(struct ahd_softc
*ahd
)
6514 struct scb_data
*scb_data
;
6516 scb_data
= &ahd
->scb_data
;
6517 if (scb_data
== NULL
)
6520 switch (scb_data
->init_level
) {
6524 struct map_node
*sns_map
;
6526 while ((sns_map
= SLIST_FIRST(&scb_data
->sense_maps
)) != NULL
) {
6527 SLIST_REMOVE_HEAD(&scb_data
->sense_maps
, links
);
6528 ahd_dmamap_unload(ahd
, scb_data
->sense_dmat
,
6530 ahd_dmamem_free(ahd
, scb_data
->sense_dmat
,
6531 sns_map
->vaddr
, sns_map
->dmamap
);
6534 ahd_dma_tag_destroy(ahd
, scb_data
->sense_dmat
);
6539 struct map_node
*sg_map
;
6541 while ((sg_map
= SLIST_FIRST(&scb_data
->sg_maps
)) != NULL
) {
6542 SLIST_REMOVE_HEAD(&scb_data
->sg_maps
, links
);
6543 ahd_dmamap_unload(ahd
, scb_data
->sg_dmat
,
6545 ahd_dmamem_free(ahd
, scb_data
->sg_dmat
,
6546 sg_map
->vaddr
, sg_map
->dmamap
);
6549 ahd_dma_tag_destroy(ahd
, scb_data
->sg_dmat
);
6554 struct map_node
*hscb_map
;
6556 while ((hscb_map
= SLIST_FIRST(&scb_data
->hscb_maps
)) != NULL
) {
6557 SLIST_REMOVE_HEAD(&scb_data
->hscb_maps
, links
);
6558 ahd_dmamap_unload(ahd
, scb_data
->hscb_dmat
,
6560 ahd_dmamem_free(ahd
, scb_data
->hscb_dmat
,
6561 hscb_map
->vaddr
, hscb_map
->dmamap
);
6564 ahd_dma_tag_destroy(ahd
, scb_data
->hscb_dmat
);
6577 * DSP filter Bypass must be enabled until the first selection
6578 * after a change in bus mode (Razor #491 and #493).
6581 ahd_setup_iocell_workaround(struct ahd_softc
*ahd
)
6583 ahd_mode_state saved_modes
;
6585 saved_modes
= ahd_save_modes(ahd
);
6586 ahd_set_modes(ahd
, AHD_MODE_CFG
, AHD_MODE_CFG
);
6587 ahd_outb(ahd
, DSPDATACTL
, ahd_inb(ahd
, DSPDATACTL
)
6588 | BYPASSENAB
| RCVROFFSTDIS
| XMITOFFSTDIS
);
6589 ahd_outb(ahd
, SIMODE0
, ahd_inb(ahd
, SIMODE0
) | (ENSELDO
|ENSELDI
));
6591 if ((ahd_debug
& AHD_SHOW_MISC
) != 0)
6592 printk("%s: Setting up iocell workaround\n", ahd_name(ahd
));
6594 ahd_restore_modes(ahd
, saved_modes
);
6595 ahd
->flags
&= ~AHD_HAD_FIRST_SEL
;
6599 ahd_iocell_first_selection(struct ahd_softc
*ahd
)
6601 ahd_mode_state saved_modes
;
6604 if ((ahd
->flags
& AHD_HAD_FIRST_SEL
) != 0)
6606 saved_modes
= ahd_save_modes(ahd
);
6607 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
6608 sblkctl
= ahd_inb(ahd
, SBLKCTL
);
6609 ahd_set_modes(ahd
, AHD_MODE_CFG
, AHD_MODE_CFG
);
6611 if ((ahd_debug
& AHD_SHOW_MISC
) != 0)
6612 printk("%s: iocell first selection\n", ahd_name(ahd
));
6614 if ((sblkctl
& ENAB40
) != 0) {
6615 ahd_outb(ahd
, DSPDATACTL
,
6616 ahd_inb(ahd
, DSPDATACTL
) & ~BYPASSENAB
);
6618 if ((ahd_debug
& AHD_SHOW_MISC
) != 0)
6619 printk("%s: BYPASS now disabled\n", ahd_name(ahd
));
6622 ahd_outb(ahd
, SIMODE0
, ahd_inb(ahd
, SIMODE0
) & ~(ENSELDO
|ENSELDI
));
6623 ahd_outb(ahd
, CLRINT
, CLRSCSIINT
);
6624 ahd_restore_modes(ahd
, saved_modes
);
6625 ahd
->flags
|= AHD_HAD_FIRST_SEL
;
6628 /*************************** SCB Management ***********************************/
6630 ahd_add_col_list(struct ahd_softc
*ahd
, struct scb
*scb
, u_int col_idx
)
6632 struct scb_list
*free_list
;
6633 struct scb_tailq
*free_tailq
;
6634 struct scb
*first_scb
;
6636 scb
->flags
|= SCB_ON_COL_LIST
;
6637 AHD_SET_SCB_COL_IDX(scb
, col_idx
);
6638 free_list
= &ahd
->scb_data
.free_scb_lists
[col_idx
];
6639 free_tailq
= &ahd
->scb_data
.free_scbs
;
6640 first_scb
= LIST_FIRST(free_list
);
6641 if (first_scb
!= NULL
) {
6642 LIST_INSERT_AFTER(first_scb
, scb
, collision_links
);
6644 LIST_INSERT_HEAD(free_list
, scb
, collision_links
);
6645 TAILQ_INSERT_TAIL(free_tailq
, scb
, links
.tqe
);
6650 ahd_rem_col_list(struct ahd_softc
*ahd
, struct scb
*scb
)
6652 struct scb_list
*free_list
;
6653 struct scb_tailq
*free_tailq
;
6654 struct scb
*first_scb
;
6657 scb
->flags
&= ~SCB_ON_COL_LIST
;
6658 col_idx
= AHD_GET_SCB_COL_IDX(ahd
, scb
);
6659 free_list
= &ahd
->scb_data
.free_scb_lists
[col_idx
];
6660 free_tailq
= &ahd
->scb_data
.free_scbs
;
6661 first_scb
= LIST_FIRST(free_list
);
6662 if (first_scb
== scb
) {
6663 struct scb
*next_scb
;
6666 * Maintain order in the collision free
6667 * lists for fairness if this device has
6668 * other colliding tags active.
6670 next_scb
= LIST_NEXT(scb
, collision_links
);
6671 if (next_scb
!= NULL
) {
6672 TAILQ_INSERT_AFTER(free_tailq
, scb
,
6673 next_scb
, links
.tqe
);
6675 TAILQ_REMOVE(free_tailq
, scb
, links
.tqe
);
6677 LIST_REMOVE(scb
, collision_links
);
6681 * Get a free scb. If there are none, see if we can allocate a new SCB.
6684 ahd_get_scb(struct ahd_softc
*ahd
, u_int col_idx
)
6691 TAILQ_FOREACH(scb
, &ahd
->scb_data
.free_scbs
, links
.tqe
) {
6692 if (AHD_GET_SCB_COL_IDX(ahd
, scb
) != col_idx
) {
6693 ahd_rem_col_list(ahd
, scb
);
6697 if ((scb
= LIST_FIRST(&ahd
->scb_data
.any_dev_free_scb_list
)) == NULL
) {
6701 ahd_alloc_scbs(ahd
);
6704 LIST_REMOVE(scb
, links
.le
);
6705 if (col_idx
!= AHD_NEVER_COL_IDX
6706 && (scb
->col_scb
!= NULL
)
6707 && (scb
->col_scb
->flags
& SCB_ACTIVE
) == 0) {
6708 LIST_REMOVE(scb
->col_scb
, links
.le
);
6709 ahd_add_col_list(ahd
, scb
->col_scb
, col_idx
);
6712 scb
->flags
|= SCB_ACTIVE
;
6717 * Return an SCB resource to the free list.
6720 ahd_free_scb(struct ahd_softc
*ahd
, struct scb
*scb
)
6722 /* Clean up for the next user */
6723 scb
->flags
= SCB_FLAG_NONE
;
6724 scb
->hscb
->control
= 0;
6725 ahd
->scb_data
.scbindex
[SCB_GET_TAG(scb
)] = NULL
;
6727 if (scb
->col_scb
== NULL
) {
6730 * No collision possible. Just free normally.
6732 LIST_INSERT_HEAD(&ahd
->scb_data
.any_dev_free_scb_list
,
6734 } else if ((scb
->col_scb
->flags
& SCB_ON_COL_LIST
) != 0) {
6737 * The SCB we might have collided with is on
6738 * a free collision list. Put both SCBs on
6741 ahd_rem_col_list(ahd
, scb
->col_scb
);
6742 LIST_INSERT_HEAD(&ahd
->scb_data
.any_dev_free_scb_list
,
6744 LIST_INSERT_HEAD(&ahd
->scb_data
.any_dev_free_scb_list
,
6745 scb
->col_scb
, links
.le
);
6746 } else if ((scb
->col_scb
->flags
6747 & (SCB_PACKETIZED
|SCB_ACTIVE
)) == SCB_ACTIVE
6748 && (scb
->col_scb
->hscb
->control
& TAG_ENB
) != 0) {
6751 * The SCB we might collide with on the next allocation
6752 * is still active in a non-packetized, tagged, context.
6753 * Put us on the SCB collision list.
6755 ahd_add_col_list(ahd
, scb
,
6756 AHD_GET_SCB_COL_IDX(ahd
, scb
->col_scb
));
6759 * The SCB we might collide with on the next allocation
6760 * is either active in a packetized context, or free.
6761 * Since we can't collide, put this SCB on the generic
6764 LIST_INSERT_HEAD(&ahd
->scb_data
.any_dev_free_scb_list
,
6768 ahd_platform_scb_free(ahd
, scb
);
6772 ahd_alloc_scbs(struct ahd_softc
*ahd
)
6774 struct scb_data
*scb_data
;
6775 struct scb
*next_scb
;
6776 struct hardware_scb
*hscb
;
6777 struct map_node
*hscb_map
;
6778 struct map_node
*sg_map
;
6779 struct map_node
*sense_map
;
6781 uint8_t *sense_data
;
6782 dma_addr_t hscb_busaddr
;
6783 dma_addr_t sg_busaddr
;
6784 dma_addr_t sense_busaddr
;
6788 scb_data
= &ahd
->scb_data
;
6789 if (scb_data
->numscbs
>= AHD_SCB_MAX_ALLOC
)
6790 /* Can't allocate any more */
6793 if (scb_data
->scbs_left
!= 0) {
6796 offset
= (PAGE_SIZE
/ sizeof(*hscb
)) - scb_data
->scbs_left
;
6797 hscb_map
= SLIST_FIRST(&scb_data
->hscb_maps
);
6798 hscb
= &((struct hardware_scb
*)hscb_map
->vaddr
)[offset
];
6799 hscb_busaddr
= hscb_map
->physaddr
+ (offset
* sizeof(*hscb
));
6801 hscb_map
= kmalloc(sizeof(*hscb_map
), GFP_ATOMIC
);
6803 if (hscb_map
== NULL
)
6806 /* Allocate the next batch of hardware SCBs */
6807 if (ahd_dmamem_alloc(ahd
, scb_data
->hscb_dmat
,
6808 (void **)&hscb_map
->vaddr
,
6809 BUS_DMA_NOWAIT
, &hscb_map
->dmamap
) != 0) {
6814 SLIST_INSERT_HEAD(&scb_data
->hscb_maps
, hscb_map
, links
);
6816 ahd_dmamap_load(ahd
, scb_data
->hscb_dmat
, hscb_map
->dmamap
,
6817 hscb_map
->vaddr
, PAGE_SIZE
, ahd_dmamap_cb
,
6818 &hscb_map
->physaddr
, /*flags*/0);
6820 hscb
= (struct hardware_scb
*)hscb_map
->vaddr
;
6821 hscb_busaddr
= hscb_map
->physaddr
;
6822 scb_data
->scbs_left
= PAGE_SIZE
/ sizeof(*hscb
);
6825 if (scb_data
->sgs_left
!= 0) {
6828 offset
= ((ahd_sglist_allocsize(ahd
) / ahd_sglist_size(ahd
))
6829 - scb_data
->sgs_left
) * ahd_sglist_size(ahd
);
6830 sg_map
= SLIST_FIRST(&scb_data
->sg_maps
);
6831 segs
= sg_map
->vaddr
+ offset
;
6832 sg_busaddr
= sg_map
->physaddr
+ offset
;
6834 sg_map
= kmalloc(sizeof(*sg_map
), GFP_ATOMIC
);
6839 /* Allocate the next batch of S/G lists */
6840 if (ahd_dmamem_alloc(ahd
, scb_data
->sg_dmat
,
6841 (void **)&sg_map
->vaddr
,
6842 BUS_DMA_NOWAIT
, &sg_map
->dmamap
) != 0) {
6847 SLIST_INSERT_HEAD(&scb_data
->sg_maps
, sg_map
, links
);
6849 ahd_dmamap_load(ahd
, scb_data
->sg_dmat
, sg_map
->dmamap
,
6850 sg_map
->vaddr
, ahd_sglist_allocsize(ahd
),
6851 ahd_dmamap_cb
, &sg_map
->physaddr
, /*flags*/0);
6853 segs
= sg_map
->vaddr
;
6854 sg_busaddr
= sg_map
->physaddr
;
6855 scb_data
->sgs_left
=
6856 ahd_sglist_allocsize(ahd
) / ahd_sglist_size(ahd
);
6858 if (ahd_debug
& AHD_SHOW_MEMORY
)
6859 printk("Mapped SG data\n");
6863 if (scb_data
->sense_left
!= 0) {
6866 offset
= PAGE_SIZE
- (AHD_SENSE_BUFSIZE
* scb_data
->sense_left
);
6867 sense_map
= SLIST_FIRST(&scb_data
->sense_maps
);
6868 sense_data
= sense_map
->vaddr
+ offset
;
6869 sense_busaddr
= sense_map
->physaddr
+ offset
;
6871 sense_map
= kmalloc(sizeof(*sense_map
), GFP_ATOMIC
);
6873 if (sense_map
== NULL
)
6876 /* Allocate the next batch of sense buffers */
6877 if (ahd_dmamem_alloc(ahd
, scb_data
->sense_dmat
,
6878 (void **)&sense_map
->vaddr
,
6879 BUS_DMA_NOWAIT
, &sense_map
->dmamap
) != 0) {
6884 SLIST_INSERT_HEAD(&scb_data
->sense_maps
, sense_map
, links
);
6886 ahd_dmamap_load(ahd
, scb_data
->sense_dmat
, sense_map
->dmamap
,
6887 sense_map
->vaddr
, PAGE_SIZE
, ahd_dmamap_cb
,
6888 &sense_map
->physaddr
, /*flags*/0);
6890 sense_data
= sense_map
->vaddr
;
6891 sense_busaddr
= sense_map
->physaddr
;
6892 scb_data
->sense_left
= PAGE_SIZE
/ AHD_SENSE_BUFSIZE
;
6894 if (ahd_debug
& AHD_SHOW_MEMORY
)
6895 printk("Mapped sense data\n");
6899 newcount
= min(scb_data
->sense_left
, scb_data
->scbs_left
);
6900 newcount
= min(newcount
, scb_data
->sgs_left
);
6901 newcount
= min(newcount
, (AHD_SCB_MAX_ALLOC
- scb_data
->numscbs
));
6902 for (i
= 0; i
< newcount
; i
++) {
6903 struct scb_platform_data
*pdata
;
6906 next_scb
= kmalloc(sizeof(*next_scb
), GFP_ATOMIC
);
6907 if (next_scb
== NULL
)
6910 pdata
= kmalloc(sizeof(*pdata
), GFP_ATOMIC
);
6911 if (pdata
== NULL
) {
6915 next_scb
->platform_data
= pdata
;
6916 next_scb
->hscb_map
= hscb_map
;
6917 next_scb
->sg_map
= sg_map
;
6918 next_scb
->sense_map
= sense_map
;
6919 next_scb
->sg_list
= segs
;
6920 next_scb
->sense_data
= sense_data
;
6921 next_scb
->sense_busaddr
= sense_busaddr
;
6922 memset(hscb
, 0, sizeof(*hscb
));
6923 next_scb
->hscb
= hscb
;
6924 hscb
->hscb_busaddr
= ahd_htole32(hscb_busaddr
);
6927 * The sequencer always starts with the second entry.
6928 * The first entry is embedded in the scb.
6930 next_scb
->sg_list_busaddr
= sg_busaddr
;
6931 if ((ahd
->flags
& AHD_64BIT_ADDRESSING
) != 0)
6932 next_scb
->sg_list_busaddr
6933 += sizeof(struct ahd_dma64_seg
);
6935 next_scb
->sg_list_busaddr
+= sizeof(struct ahd_dma_seg
);
6936 next_scb
->ahd_softc
= ahd
;
6937 next_scb
->flags
= SCB_FLAG_NONE
;
6938 next_scb
->hscb
->tag
= ahd_htole16(scb_data
->numscbs
);
6939 col_tag
= scb_data
->numscbs
^ 0x100;
6940 next_scb
->col_scb
= ahd_find_scb_by_tag(ahd
, col_tag
);
6941 if (next_scb
->col_scb
!= NULL
)
6942 next_scb
->col_scb
->col_scb
= next_scb
;
6943 ahd_free_scb(ahd
, next_scb
);
6945 hscb_busaddr
+= sizeof(*hscb
);
6946 segs
+= ahd_sglist_size(ahd
);
6947 sg_busaddr
+= ahd_sglist_size(ahd
);
6948 sense_data
+= AHD_SENSE_BUFSIZE
;
6949 sense_busaddr
+= AHD_SENSE_BUFSIZE
;
6950 scb_data
->numscbs
++;
6951 scb_data
->sense_left
--;
6952 scb_data
->scbs_left
--;
6953 scb_data
->sgs_left
--;
6958 ahd_controller_info(struct ahd_softc
*ahd
, char *buf
)
6964 len
= sprintf(buf
, "%s: ", ahd_chip_names
[ahd
->chip
& AHD_CHIPID_MASK
]);
6967 speed
= "Ultra320 ";
6968 if ((ahd
->features
& AHD_WIDE
) != 0) {
6973 len
= sprintf(buf
, "%s%sChannel %c, SCSI Id=%d, ",
6974 speed
, type
, ahd
->channel
, ahd
->our_id
);
6977 sprintf(buf
, "%s, %d SCBs", ahd
->bus_description
,
6978 ahd
->scb_data
.maxhscbs
);
6981 static const char *channel_strings
[] = {
6988 static const char *termstat_strings
[] = {
6989 "Terminated Correctly",
6995 /***************************** Timer Facilities *******************************/
6997 ahd_timer_reset(struct timer_list
*timer
, int usec
)
7000 timer
->expires
= jiffies
+ (usec
* HZ
)/1000000;
7005 * Start the board, ready for normal operation
7008 ahd_init(struct ahd_softc
*ahd
)
7010 uint8_t *next_vaddr
;
7011 dma_addr_t next_baddr
;
7012 size_t driver_data_size
;
7016 uint8_t current_sensing
;
7019 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
7021 ahd
->stack_size
= ahd_probe_stack_size(ahd
);
7022 ahd
->saved_stack
= kmalloc_array(ahd
->stack_size
, sizeof(uint16_t),
7024 if (ahd
->saved_stack
== NULL
)
7028 * Verify that the compiler hasn't over-aggressively
7029 * padded important structures.
7031 if (sizeof(struct hardware_scb
) != 64)
7032 panic("Hardware SCB size is incorrect");
7035 if ((ahd_debug
& AHD_DEBUG_SEQUENCER
) != 0)
7036 ahd
->flags
|= AHD_SEQUENCER_DEBUG
;
7040 * Default to allowing initiator operations.
7042 ahd
->flags
|= AHD_INITIATORROLE
;
7045 * Only allow target mode features if this unit has them enabled.
7047 if ((AHD_TMODE_ENABLE
& (0x1 << ahd
->unit
)) == 0)
7048 ahd
->features
&= ~AHD_TARGETMODE
;
7053 * DMA tag for our command fifos and other data in system memory
7054 * the card's sequencer must be able to access. For initiator
7055 * roles, we need to allocate space for the qoutfifo. When providing
7056 * for the target mode role, we must additionally provide space for
7057 * the incoming target command fifo.
7059 driver_data_size
= AHD_SCB_MAX
* sizeof(*ahd
->qoutfifo
)
7060 + sizeof(struct hardware_scb
);
7061 if ((ahd
->features
& AHD_TARGETMODE
) != 0)
7062 driver_data_size
+= AHD_TMODE_CMDS
* sizeof(struct target_cmd
);
7063 if ((ahd
->bugs
& AHD_PKT_BITBUCKET_BUG
) != 0)
7064 driver_data_size
+= PKT_OVERRUN_BUFSIZE
;
7065 if (ahd_dma_tag_create(ahd
, ahd
->parent_dmat
, /*alignment*/1,
7066 /*boundary*/BUS_SPACE_MAXADDR_32BIT
+ 1,
7067 /*lowaddr*/BUS_SPACE_MAXADDR_32BIT
,
7068 /*highaddr*/BUS_SPACE_MAXADDR
,
7069 /*filter*/NULL
, /*filterarg*/NULL
,
7072 /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT
,
7073 /*flags*/0, &ahd
->shared_data_dmat
) != 0) {
7079 /* Allocation of driver data */
7080 if (ahd_dmamem_alloc(ahd
, ahd
->shared_data_dmat
,
7081 (void **)&ahd
->shared_data_map
.vaddr
,
7083 &ahd
->shared_data_map
.dmamap
) != 0) {
7089 /* And permanently map it in */
7090 ahd_dmamap_load(ahd
, ahd
->shared_data_dmat
, ahd
->shared_data_map
.dmamap
,
7091 ahd
->shared_data_map
.vaddr
, driver_data_size
,
7092 ahd_dmamap_cb
, &ahd
->shared_data_map
.physaddr
,
7094 ahd
->qoutfifo
= (struct ahd_completion
*)ahd
->shared_data_map
.vaddr
;
7095 next_vaddr
= (uint8_t *)&ahd
->qoutfifo
[AHD_QOUT_SIZE
];
7096 next_baddr
= ahd
->shared_data_map
.physaddr
7097 + AHD_QOUT_SIZE
*sizeof(struct ahd_completion
);
7098 if ((ahd
->features
& AHD_TARGETMODE
) != 0) {
7099 ahd
->targetcmds
= (struct target_cmd
*)next_vaddr
;
7100 next_vaddr
+= AHD_TMODE_CMDS
* sizeof(struct target_cmd
);
7101 next_baddr
+= AHD_TMODE_CMDS
* sizeof(struct target_cmd
);
7104 if ((ahd
->bugs
& AHD_PKT_BITBUCKET_BUG
) != 0) {
7105 ahd
->overrun_buf
= next_vaddr
;
7106 next_vaddr
+= PKT_OVERRUN_BUFSIZE
;
7107 next_baddr
+= PKT_OVERRUN_BUFSIZE
;
7111 * We need one SCB to serve as the "next SCB". Since the
7112 * tag identifier in this SCB will never be used, there is
7113 * no point in using a valid HSCB tag from an SCB pulled from
7114 * the standard free pool. So, we allocate this "sentinel"
7115 * specially from the DMA safe memory chunk used for the QOUTFIFO.
7117 ahd
->next_queued_hscb
= (struct hardware_scb
*)next_vaddr
;
7118 ahd
->next_queued_hscb_map
= &ahd
->shared_data_map
;
7119 ahd
->next_queued_hscb
->hscb_busaddr
= ahd_htole32(next_baddr
);
7123 /* Allocate SCB data now that buffer_dmat is initialized */
7124 if (ahd_init_scbdata(ahd
) != 0)
7127 if ((ahd
->flags
& AHD_INITIATORROLE
) == 0)
7128 ahd
->flags
&= ~AHD_RESET_BUS_A
;
7131 * Before committing these settings to the chip, give
7132 * the OSM one last chance to modify our configuration.
7134 ahd_platform_init(ahd
);
7136 /* Bring up the chip. */
7139 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
7141 if ((ahd
->flags
& AHD_CURRENT_SENSING
) == 0)
7145 * Verify termination based on current draw and
7146 * warn user if the bus is over/under terminated.
7148 error
= ahd_write_flexport(ahd
, FLXADDR_ROMSTAT_CURSENSECTL
,
7151 printk("%s: current sensing timeout 1\n", ahd_name(ahd
));
7154 for (i
= 20, fstat
= FLX_FSTAT_BUSY
;
7155 (fstat
& FLX_FSTAT_BUSY
) != 0 && i
; i
--) {
7156 error
= ahd_read_flexport(ahd
, FLXADDR_FLEXSTAT
, &fstat
);
7158 printk("%s: current sensing timeout 2\n",
7164 printk("%s: Timedout during current-sensing test\n",
7169 /* Latch Current Sensing status. */
7170 error
= ahd_read_flexport(ahd
, FLXADDR_CURRENT_STAT
, ¤t_sensing
);
7172 printk("%s: current sensing timeout 3\n", ahd_name(ahd
));
7176 /* Diable current sensing. */
7177 ahd_write_flexport(ahd
, FLXADDR_ROMSTAT_CURSENSECTL
, 0);
7180 if ((ahd_debug
& AHD_SHOW_TERMCTL
) != 0) {
7181 printk("%s: current_sensing == 0x%x\n",
7182 ahd_name(ahd
), current_sensing
);
7186 for (i
= 0; i
< 4; i
++, current_sensing
>>= FLX_CSTAT_SHIFT
) {
7189 term_stat
= (current_sensing
& FLX_CSTAT_MASK
);
7190 switch (term_stat
) {
7191 case FLX_CSTAT_OVER
:
7192 case FLX_CSTAT_UNDER
:
7195 case FLX_CSTAT_INVALID
:
7196 case FLX_CSTAT_OKAY
:
7197 if (warn_user
== 0 && bootverbose
== 0)
7199 printk("%s: %s Channel %s\n", ahd_name(ahd
),
7200 channel_strings
[i
], termstat_strings
[term_stat
]);
7205 printk("%s: WARNING. Termination is not configured correctly.\n"
7206 "%s: WARNING. SCSI bus operations may FAIL.\n",
7207 ahd_name(ahd
), ahd_name(ahd
));
7211 ahd_timer_reset(&ahd
->stat_timer
, AHD_STAT_UPDATE_US
);
7216 * (Re)initialize chip state after a chip reset.
7219 ahd_chip_init(struct ahd_softc
*ahd
)
7223 u_int scsiseq_template
;
7228 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
7230 * Take the LED out of diagnostic mode
7232 ahd_outb(ahd
, SBLKCTL
, ahd_inb(ahd
, SBLKCTL
) & ~(DIAGLEDEN
|DIAGLEDON
));
7235 * Return HS_MAILBOX to its default value.
7237 ahd
->hs_mailbox
= 0;
7238 ahd_outb(ahd
, HS_MAILBOX
, 0);
7240 /* Set the SCSI Id, SXFRCTL0, SXFRCTL1, and SIMODE1. */
7241 ahd_outb(ahd
, IOWNID
, ahd
->our_id
);
7242 ahd_outb(ahd
, TOWNID
, ahd
->our_id
);
7243 sxfrctl1
= (ahd
->flags
& AHD_TERM_ENB_A
) != 0 ? STPWEN
: 0;
7244 sxfrctl1
|= (ahd
->flags
& AHD_SPCHK_ENB_A
) != 0 ? ENSPCHK
: 0;
7245 if ((ahd
->bugs
& AHD_LONG_SETIMO_BUG
)
7246 && (ahd
->seltime
!= STIMESEL_MIN
)) {
7248 * The selection timer duration is twice as long
7249 * as it should be. Halve it by adding "1" to
7250 * the user specified setting.
7252 sxfrctl1
|= ahd
->seltime
+ STIMESEL_BUG_ADJ
;
7254 sxfrctl1
|= ahd
->seltime
;
7257 ahd_outb(ahd
, SXFRCTL0
, DFON
);
7258 ahd_outb(ahd
, SXFRCTL1
, sxfrctl1
|ahd
->seltime
|ENSTIMER
|ACTNEGEN
);
7259 ahd_outb(ahd
, SIMODE1
, ENSELTIMO
|ENSCSIRST
|ENSCSIPERR
);
7262 * Now that termination is set, wait for up
7263 * to 500ms for our transceivers to settle. If
7264 * the adapter does not have a cable attached,
7265 * the transceivers may never settle, so don't
7266 * complain if we fail here.
7269 (ahd_inb(ahd
, SBLKCTL
) & (ENAB40
|ENAB20
)) == 0 && wait
;
7273 /* Clear any false bus resets due to the transceivers settling */
7274 ahd_outb(ahd
, CLRSINT1
, CLRSCSIRSTI
);
7275 ahd_outb(ahd
, CLRINT
, CLRSCSIINT
);
7277 /* Initialize mode specific S/G state. */
7278 for (i
= 0; i
< 2; i
++) {
7279 ahd_set_modes(ahd
, AHD_MODE_DFF0
+ i
, AHD_MODE_DFF0
+ i
);
7280 ahd_outb(ahd
, LONGJMP_ADDR
+ 1, INVALID_ADDR
);
7281 ahd_outb(ahd
, SG_STATE
, 0);
7282 ahd_outb(ahd
, CLRSEQINTSRC
, 0xFF);
7283 ahd_outb(ahd
, SEQIMODE
,
7284 ENSAVEPTRS
|ENCFG4DATA
|ENCFG4ISTAT
7285 |ENCFG4TSTAT
|ENCFG4ICMD
|ENCFG4TCMD
);
7288 ahd_set_modes(ahd
, AHD_MODE_CFG
, AHD_MODE_CFG
);
7289 ahd_outb(ahd
, DSCOMMAND0
, ahd_inb(ahd
, DSCOMMAND0
)|MPARCKEN
|CACHETHEN
);
7290 ahd_outb(ahd
, DFF_THRSH
, RD_DFTHRSH_75
|WR_DFTHRSH_75
);
7291 ahd_outb(ahd
, SIMODE0
, ENIOERR
|ENOVERRUN
);
7292 ahd_outb(ahd
, SIMODE3
, ENNTRAMPERR
|ENOSRAMPERR
);
7293 if ((ahd
->bugs
& AHD_BUSFREEREV_BUG
) != 0) {
7294 ahd_outb(ahd
, OPTIONMODE
, AUTOACKEN
|AUTO_MSGOUT_DE
);
7296 ahd_outb(ahd
, OPTIONMODE
, AUTOACKEN
|BUSFREEREV
|AUTO_MSGOUT_DE
);
7298 ahd_outb(ahd
, SCSCHKN
, CURRFIFODEF
|WIDERESEN
|SHVALIDSTDIS
);
7299 if ((ahd
->chip
& AHD_BUS_MASK
) == AHD_PCIX
)
7301 * Do not issue a target abort when a split completion
7302 * error occurs. Let our PCIX interrupt handler deal
7303 * with it instead. H2A4 Razor #625
7305 ahd_outb(ahd
, PCIXCTL
, ahd_inb(ahd
, PCIXCTL
) | SPLTSTADIS
);
7307 if ((ahd
->bugs
& AHD_LQOOVERRUN_BUG
) != 0)
7308 ahd_outb(ahd
, LQOSCSCTL
, LQONOCHKOVER
);
7311 * Tweak IOCELL settings.
7313 if ((ahd
->flags
& AHD_HP_BOARD
) != 0) {
7314 for (i
= 0; i
< NUMDSPS
; i
++) {
7315 ahd_outb(ahd
, DSPSELECT
, i
);
7316 ahd_outb(ahd
, WRTBIASCTL
, WRTBIASCTL_HP_DEFAULT
);
7319 if ((ahd_debug
& AHD_SHOW_MISC
) != 0)
7320 printk("%s: WRTBIASCTL now 0x%x\n", ahd_name(ahd
),
7321 WRTBIASCTL_HP_DEFAULT
);
7324 ahd_setup_iocell_workaround(ahd
);
7327 * Enable LQI Manager interrupts.
7329 ahd_outb(ahd
, LQIMODE1
, ENLQIPHASE_LQ
|ENLQIPHASE_NLQ
|ENLIQABORT
7330 | ENLQICRCI_LQ
|ENLQICRCI_NLQ
|ENLQIBADLQI
7331 | ENLQIOVERI_LQ
|ENLQIOVERI_NLQ
);
7332 ahd_outb(ahd
, LQOMODE0
, ENLQOATNLQ
|ENLQOATNPKT
|ENLQOTCRC
);
7334 * We choose to have the sequencer catch LQOPHCHGINPKT errors
7335 * manually for the command phase at the start of a packetized
7336 * selection case. ENLQOBUSFREE should be made redundant by
7337 * the BUSFREE interrupt, but it seems that some LQOBUSFREE
7338 * events fail to assert the BUSFREE interrupt so we must
7339 * also enable LQOBUSFREE interrupts.
7341 ahd_outb(ahd
, LQOMODE1
, ENLQOBUSFREE
);
7344 * Setup sequencer interrupt handlers.
7346 ahd_outw(ahd
, INTVEC1_ADDR
, ahd_resolve_seqaddr(ahd
, LABEL_seq_isr
));
7347 ahd_outw(ahd
, INTVEC2_ADDR
, ahd_resolve_seqaddr(ahd
, LABEL_timer_isr
));
7350 * Setup SCB Offset registers.
7352 if ((ahd
->bugs
& AHD_PKT_LUN_BUG
) != 0) {
7353 ahd_outb(ahd
, LUNPTR
, offsetof(struct hardware_scb
,
7356 ahd_outb(ahd
, LUNPTR
, offsetof(struct hardware_scb
, lun
));
7358 ahd_outb(ahd
, CMDLENPTR
, offsetof(struct hardware_scb
, cdb_len
));
7359 ahd_outb(ahd
, ATTRPTR
, offsetof(struct hardware_scb
, task_attribute
));
7360 ahd_outb(ahd
, FLAGPTR
, offsetof(struct hardware_scb
, task_management
));
7361 ahd_outb(ahd
, CMDPTR
, offsetof(struct hardware_scb
,
7362 shared_data
.idata
.cdb
));
7363 ahd_outb(ahd
, QNEXTPTR
,
7364 offsetof(struct hardware_scb
, next_hscb_busaddr
));
7365 ahd_outb(ahd
, ABRTBITPTR
, MK_MESSAGE_BIT_OFFSET
);
7366 ahd_outb(ahd
, ABRTBYTEPTR
, offsetof(struct hardware_scb
, control
));
7367 if ((ahd
->bugs
& AHD_PKT_LUN_BUG
) != 0) {
7368 ahd_outb(ahd
, LUNLEN
,
7369 sizeof(ahd
->next_queued_hscb
->pkt_long_lun
) - 1);
7371 ahd_outb(ahd
, LUNLEN
, LUNLEN_SINGLE_LEVEL_LUN
);
7373 ahd_outb(ahd
, CDBLIMIT
, SCB_CDB_LEN_PTR
- 1);
7374 ahd_outb(ahd
, MAXCMD
, 0xFF);
7375 ahd_outb(ahd
, SCBAUTOPTR
,
7376 AUSCBPTR_EN
| offsetof(struct hardware_scb
, tag
));
7378 /* We haven't been enabled for target mode yet. */
7379 ahd_outb(ahd
, MULTARGID
, 0);
7380 ahd_outb(ahd
, MULTARGID
+ 1, 0);
7382 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
7383 /* Initialize the negotiation table. */
7384 if ((ahd
->features
& AHD_NEW_IOCELL_OPTS
) == 0) {
7386 * Clear the spare bytes in the neg table to avoid
7387 * spurious parity errors.
7389 for (target
= 0; target
< AHD_NUM_TARGETS
; target
++) {
7390 ahd_outb(ahd
, NEGOADDR
, target
);
7391 ahd_outb(ahd
, ANNEXCOL
, AHD_ANNEXCOL_PER_DEV0
);
7392 for (i
= 0; i
< AHD_NUM_PER_DEV_ANNEXCOLS
; i
++)
7393 ahd_outb(ahd
, ANNEXDAT
, 0);
7396 for (target
= 0; target
< AHD_NUM_TARGETS
; target
++) {
7397 struct ahd_devinfo devinfo
;
7398 struct ahd_initiator_tinfo
*tinfo
;
7399 struct ahd_tmode_tstate
*tstate
;
7401 tinfo
= ahd_fetch_transinfo(ahd
, 'A', ahd
->our_id
,
7403 ahd_compile_devinfo(&devinfo
, ahd
->our_id
,
7404 target
, CAM_LUN_WILDCARD
,
7405 'A', ROLE_INITIATOR
);
7406 ahd_update_neg_table(ahd
, &devinfo
, &tinfo
->curr
);
7409 ahd_outb(ahd
, CLRSINT3
, NTRAMPERR
|OSRAMPERR
);
7410 ahd_outb(ahd
, CLRINT
, CLRSCSIINT
);
7412 #ifdef NEEDS_MORE_TESTING
7414 * Always enable abort on incoming L_Qs if this feature is
7415 * supported. We use this to catch invalid SCB references.
7417 if ((ahd
->bugs
& AHD_ABORT_LQI_BUG
) == 0)
7418 ahd_outb(ahd
, LQCTL1
, ABORTPENDING
);
7421 ahd_outb(ahd
, LQCTL1
, 0);
7423 /* All of our queues are empty */
7424 ahd
->qoutfifonext
= 0;
7425 ahd
->qoutfifonext_valid_tag
= QOUTFIFO_ENTRY_VALID
;
7426 ahd_outb(ahd
, QOUTFIFO_ENTRY_VALID_TAG
, QOUTFIFO_ENTRY_VALID
);
7427 for (i
= 0; i
< AHD_QOUT_SIZE
; i
++)
7428 ahd
->qoutfifo
[i
].valid_tag
= 0;
7429 ahd_sync_qoutfifo(ahd
, BUS_DMASYNC_PREREAD
);
7431 ahd
->qinfifonext
= 0;
7432 for (i
= 0; i
< AHD_QIN_SIZE
; i
++)
7433 ahd
->qinfifo
[i
] = SCB_LIST_NULL
;
7435 if ((ahd
->features
& AHD_TARGETMODE
) != 0) {
7436 /* All target command blocks start out invalid. */
7437 for (i
= 0; i
< AHD_TMODE_CMDS
; i
++)
7438 ahd
->targetcmds
[i
].cmd_valid
= 0;
7439 ahd_sync_tqinfifo(ahd
, BUS_DMASYNC_PREREAD
);
7440 ahd
->tqinfifonext
= 1;
7441 ahd_outb(ahd
, KERNEL_TQINPOS
, ahd
->tqinfifonext
- 1);
7442 ahd_outb(ahd
, TQINPOS
, ahd
->tqinfifonext
);
7445 /* Initialize Scratch Ram. */
7446 ahd_outb(ahd
, SEQ_FLAGS
, 0);
7447 ahd_outb(ahd
, SEQ_FLAGS2
, 0);
7449 /* We don't have any waiting selections */
7450 ahd_outw(ahd
, WAITING_TID_HEAD
, SCB_LIST_NULL
);
7451 ahd_outw(ahd
, WAITING_TID_TAIL
, SCB_LIST_NULL
);
7452 ahd_outw(ahd
, MK_MESSAGE_SCB
, SCB_LIST_NULL
);
7453 ahd_outw(ahd
, MK_MESSAGE_SCSIID
, 0xFF);
7454 for (i
= 0; i
< AHD_NUM_TARGETS
; i
++)
7455 ahd_outw(ahd
, WAITING_SCB_TAILS
+ (2 * i
), SCB_LIST_NULL
);
7458 * Nobody is waiting to be DMAed into the QOUTFIFO.
7460 ahd_outw(ahd
, COMPLETE_SCB_HEAD
, SCB_LIST_NULL
);
7461 ahd_outw(ahd
, COMPLETE_SCB_DMAINPROG_HEAD
, SCB_LIST_NULL
);
7462 ahd_outw(ahd
, COMPLETE_DMA_SCB_HEAD
, SCB_LIST_NULL
);
7463 ahd_outw(ahd
, COMPLETE_DMA_SCB_TAIL
, SCB_LIST_NULL
);
7464 ahd_outw(ahd
, COMPLETE_ON_QFREEZE_HEAD
, SCB_LIST_NULL
);
7467 * The Freeze Count is 0.
7469 ahd
->qfreeze_cnt
= 0;
7470 ahd_outw(ahd
, QFREEZE_COUNT
, 0);
7471 ahd_outw(ahd
, KERNEL_QFREEZE_COUNT
, 0);
7474 * Tell the sequencer where it can find our arrays in memory.
7476 busaddr
= ahd
->shared_data_map
.physaddr
;
7477 ahd_outl(ahd
, SHARED_DATA_ADDR
, busaddr
);
7478 ahd_outl(ahd
, QOUTFIFO_NEXT_ADDR
, busaddr
);
7481 * Setup the allowed SCSI Sequences based on operational mode.
7482 * If we are a target, we'll enable select in operations once
7483 * we've had a lun enabled.
7485 scsiseq_template
= ENAUTOATNP
;
7486 if ((ahd
->flags
& AHD_INITIATORROLE
) != 0)
7487 scsiseq_template
|= ENRSELI
;
7488 ahd_outb(ahd
, SCSISEQ_TEMPLATE
, scsiseq_template
);
7490 /* There are no busy SCBs yet. */
7491 for (target
= 0; target
< AHD_NUM_TARGETS
; target
++) {
7494 for (lun
= 0; lun
< AHD_NUM_LUNS_NONPKT
; lun
++)
7495 ahd_unbusy_tcl(ahd
, BUILD_TCL_RAW(target
, 'A', lun
));
7499 * Initialize the group code to command length table.
7500 * Vendor Unique codes are set to 0 so we only capture
7501 * the first byte of the cdb. These can be overridden
7502 * when target mode is enabled.
7504 ahd_outb(ahd
, CMDSIZE_TABLE
, 5);
7505 ahd_outb(ahd
, CMDSIZE_TABLE
+ 1, 9);
7506 ahd_outb(ahd
, CMDSIZE_TABLE
+ 2, 9);
7507 ahd_outb(ahd
, CMDSIZE_TABLE
+ 3, 0);
7508 ahd_outb(ahd
, CMDSIZE_TABLE
+ 4, 15);
7509 ahd_outb(ahd
, CMDSIZE_TABLE
+ 5, 11);
7510 ahd_outb(ahd
, CMDSIZE_TABLE
+ 6, 0);
7511 ahd_outb(ahd
, CMDSIZE_TABLE
+ 7, 0);
7513 /* Tell the sequencer of our initial queue positions */
7514 ahd_set_modes(ahd
, AHD_MODE_CCHAN
, AHD_MODE_CCHAN
);
7515 ahd_outb(ahd
, QOFF_CTLSTA
, SCB_QSIZE_512
);
7516 ahd
->qinfifonext
= 0;
7517 ahd_set_hnscb_qoff(ahd
, ahd
->qinfifonext
);
7518 ahd_set_hescb_qoff(ahd
, 0);
7519 ahd_set_snscb_qoff(ahd
, 0);
7520 ahd_set_sescb_qoff(ahd
, 0);
7521 ahd_set_sdscb_qoff(ahd
, 0);
7524 * Tell the sequencer which SCB will be the next one it receives.
7526 busaddr
= ahd_le32toh(ahd
->next_queued_hscb
->hscb_busaddr
);
7527 ahd_outl(ahd
, NEXT_QUEUED_SCB_ADDR
, busaddr
);
7530 * Default to coalescing disabled.
7532 ahd_outw(ahd
, INT_COALESCING_CMDCOUNT
, 0);
7533 ahd_outw(ahd
, CMDS_PENDING
, 0);
7534 ahd_update_coalescing_values(ahd
, ahd
->int_coalescing_timer
,
7535 ahd
->int_coalescing_maxcmds
,
7536 ahd
->int_coalescing_mincmds
);
7537 ahd_enable_coalescing(ahd
, FALSE
);
7540 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
7542 if (ahd
->features
& AHD_AIC79XXB_SLOWCRC
) {
7543 u_int negodat3
= ahd_inb(ahd
, NEGCONOPTS
);
7545 negodat3
|= ENSLOWCRC
;
7546 ahd_outb(ahd
, NEGCONOPTS
, negodat3
);
7547 negodat3
= ahd_inb(ahd
, NEGCONOPTS
);
7548 if (!(negodat3
& ENSLOWCRC
))
7549 printk("aic79xx: failed to set the SLOWCRC bit\n");
7551 printk("aic79xx: SLOWCRC bit set\n");
7556 * Setup default device and controller settings.
7557 * This should only be called if our probe has
7558 * determined that no configuration data is available.
7561 ahd_default_config(struct ahd_softc
*ahd
)
7568 * Allocate a tstate to house information for our
7569 * initiator presence on the bus as well as the user
7570 * data for any target mode initiator.
7572 if (ahd_alloc_tstate(ahd
, ahd
->our_id
, 'A') == NULL
) {
7573 printk("%s: unable to allocate ahd_tmode_tstate. "
7574 "Failing attach\n", ahd_name(ahd
));
7578 for (targ
= 0; targ
< AHD_NUM_TARGETS
; targ
++) {
7579 struct ahd_devinfo devinfo
;
7580 struct ahd_initiator_tinfo
*tinfo
;
7581 struct ahd_tmode_tstate
*tstate
;
7582 uint16_t target_mask
;
7584 tinfo
= ahd_fetch_transinfo(ahd
, 'A', ahd
->our_id
,
7587 * We support SPC2 and SPI4.
7589 tinfo
->user
.protocol_version
= 4;
7590 tinfo
->user
.transport_version
= 4;
7592 target_mask
= 0x01 << targ
;
7593 ahd
->user_discenable
|= target_mask
;
7594 tstate
->discenable
|= target_mask
;
7595 ahd
->user_tagenable
|= target_mask
;
7596 #ifdef AHD_FORCE_160
7597 tinfo
->user
.period
= AHD_SYNCRATE_DT
;
7599 tinfo
->user
.period
= AHD_SYNCRATE_160
;
7601 tinfo
->user
.offset
= MAX_OFFSET
;
7602 tinfo
->user
.ppr_options
= MSG_EXT_PPR_RD_STRM
7603 | MSG_EXT_PPR_WR_FLOW
7604 | MSG_EXT_PPR_HOLD_MCS
7605 | MSG_EXT_PPR_IU_REQ
7606 | MSG_EXT_PPR_QAS_REQ
7607 | MSG_EXT_PPR_DT_REQ
;
7608 if ((ahd
->features
& AHD_RTI
) != 0)
7609 tinfo
->user
.ppr_options
|= MSG_EXT_PPR_RTI
;
7611 tinfo
->user
.width
= MSG_EXT_WDTR_BUS_16_BIT
;
7614 * Start out Async/Narrow/Untagged and with
7615 * conservative protocol support.
7617 tinfo
->goal
.protocol_version
= 2;
7618 tinfo
->goal
.transport_version
= 2;
7619 tinfo
->curr
.protocol_version
= 2;
7620 tinfo
->curr
.transport_version
= 2;
7621 ahd_compile_devinfo(&devinfo
, ahd
->our_id
,
7622 targ
, CAM_LUN_WILDCARD
,
7623 'A', ROLE_INITIATOR
);
7624 tstate
->tagenable
&= ~target_mask
;
7625 ahd_set_width(ahd
, &devinfo
, MSG_EXT_WDTR_BUS_8_BIT
,
7626 AHD_TRANS_CUR
|AHD_TRANS_GOAL
, /*paused*/TRUE
);
7627 ahd_set_syncrate(ahd
, &devinfo
, /*period*/0, /*offset*/0,
7628 /*ppr_options*/0, AHD_TRANS_CUR
|AHD_TRANS_GOAL
,
7635 * Parse device configuration information.
7638 ahd_parse_cfgdata(struct ahd_softc
*ahd
, struct seeprom_config
*sc
)
7643 max_targ
= sc
->max_targets
& CFMAXTARG
;
7644 ahd
->our_id
= sc
->brtime_id
& CFSCSIID
;
7647 * Allocate a tstate to house information for our
7648 * initiator presence on the bus as well as the user
7649 * data for any target mode initiator.
7651 if (ahd_alloc_tstate(ahd
, ahd
->our_id
, 'A') == NULL
) {
7652 printk("%s: unable to allocate ahd_tmode_tstate. "
7653 "Failing attach\n", ahd_name(ahd
));
7657 for (targ
= 0; targ
< max_targ
; targ
++) {
7658 struct ahd_devinfo devinfo
;
7659 struct ahd_initiator_tinfo
*tinfo
;
7660 struct ahd_transinfo
*user_tinfo
;
7661 struct ahd_tmode_tstate
*tstate
;
7662 uint16_t target_mask
;
7664 tinfo
= ahd_fetch_transinfo(ahd
, 'A', ahd
->our_id
,
7666 user_tinfo
= &tinfo
->user
;
7669 * We support SPC2 and SPI4.
7671 tinfo
->user
.protocol_version
= 4;
7672 tinfo
->user
.transport_version
= 4;
7674 target_mask
= 0x01 << targ
;
7675 ahd
->user_discenable
&= ~target_mask
;
7676 tstate
->discenable
&= ~target_mask
;
7677 ahd
->user_tagenable
&= ~target_mask
;
7678 if (sc
->device_flags
[targ
] & CFDISC
) {
7679 tstate
->discenable
|= target_mask
;
7680 ahd
->user_discenable
|= target_mask
;
7681 ahd
->user_tagenable
|= target_mask
;
7684 * Cannot be packetized without disconnection.
7686 sc
->device_flags
[targ
] &= ~CFPACKETIZED
;
7689 user_tinfo
->ppr_options
= 0;
7690 user_tinfo
->period
= (sc
->device_flags
[targ
] & CFXFER
);
7691 if (user_tinfo
->period
< CFXFER_ASYNC
) {
7692 if (user_tinfo
->period
<= AHD_PERIOD_10MHz
)
7693 user_tinfo
->ppr_options
|= MSG_EXT_PPR_DT_REQ
;
7694 user_tinfo
->offset
= MAX_OFFSET
;
7696 user_tinfo
->offset
= 0;
7697 user_tinfo
->period
= AHD_ASYNC_XFER_PERIOD
;
7699 #ifdef AHD_FORCE_160
7700 if (user_tinfo
->period
<= AHD_SYNCRATE_160
)
7701 user_tinfo
->period
= AHD_SYNCRATE_DT
;
7704 if ((sc
->device_flags
[targ
] & CFPACKETIZED
) != 0) {
7705 user_tinfo
->ppr_options
|= MSG_EXT_PPR_RD_STRM
7706 | MSG_EXT_PPR_WR_FLOW
7707 | MSG_EXT_PPR_HOLD_MCS
7708 | MSG_EXT_PPR_IU_REQ
;
7709 if ((ahd
->features
& AHD_RTI
) != 0)
7710 user_tinfo
->ppr_options
|= MSG_EXT_PPR_RTI
;
7713 if ((sc
->device_flags
[targ
] & CFQAS
) != 0)
7714 user_tinfo
->ppr_options
|= MSG_EXT_PPR_QAS_REQ
;
7716 if ((sc
->device_flags
[targ
] & CFWIDEB
) != 0)
7717 user_tinfo
->width
= MSG_EXT_WDTR_BUS_16_BIT
;
7719 user_tinfo
->width
= MSG_EXT_WDTR_BUS_8_BIT
;
7721 if ((ahd_debug
& AHD_SHOW_MISC
) != 0)
7722 printk("(%d): %x:%x:%x:%x\n", targ
, user_tinfo
->width
,
7723 user_tinfo
->period
, user_tinfo
->offset
,
7724 user_tinfo
->ppr_options
);
7727 * Start out Async/Narrow/Untagged and with
7728 * conservative protocol support.
7730 tstate
->tagenable
&= ~target_mask
;
7731 tinfo
->goal
.protocol_version
= 2;
7732 tinfo
->goal
.transport_version
= 2;
7733 tinfo
->curr
.protocol_version
= 2;
7734 tinfo
->curr
.transport_version
= 2;
7735 ahd_compile_devinfo(&devinfo
, ahd
->our_id
,
7736 targ
, CAM_LUN_WILDCARD
,
7737 'A', ROLE_INITIATOR
);
7738 ahd_set_width(ahd
, &devinfo
, MSG_EXT_WDTR_BUS_8_BIT
,
7739 AHD_TRANS_CUR
|AHD_TRANS_GOAL
, /*paused*/TRUE
);
7740 ahd_set_syncrate(ahd
, &devinfo
, /*period*/0, /*offset*/0,
7741 /*ppr_options*/0, AHD_TRANS_CUR
|AHD_TRANS_GOAL
,
7745 ahd
->flags
&= ~AHD_SPCHK_ENB_A
;
7746 if (sc
->bios_control
& CFSPARITY
)
7747 ahd
->flags
|= AHD_SPCHK_ENB_A
;
7749 ahd
->flags
&= ~AHD_RESET_BUS_A
;
7750 if (sc
->bios_control
& CFRESETB
)
7751 ahd
->flags
|= AHD_RESET_BUS_A
;
7753 ahd
->flags
&= ~AHD_EXTENDED_TRANS_A
;
7754 if (sc
->bios_control
& CFEXTEND
)
7755 ahd
->flags
|= AHD_EXTENDED_TRANS_A
;
7757 ahd
->flags
&= ~AHD_BIOS_ENABLED
;
7758 if ((sc
->bios_control
& CFBIOSSTATE
) == CFBS_ENABLED
)
7759 ahd
->flags
|= AHD_BIOS_ENABLED
;
7761 ahd
->flags
&= ~AHD_STPWLEVEL_A
;
7762 if ((sc
->adapter_control
& CFSTPWLEVEL
) != 0)
7763 ahd
->flags
|= AHD_STPWLEVEL_A
;
7769 * Parse device configuration information.
7772 ahd_parse_vpddata(struct ahd_softc
*ahd
, struct vpd_config
*vpd
)
7776 error
= ahd_verify_vpd_cksum(vpd
);
7779 if ((vpd
->bios_flags
& VPDBOOTHOST
) != 0)
7780 ahd
->flags
|= AHD_BOOT_CHANNEL
;
7785 ahd_intr_enable(struct ahd_softc
*ahd
, int enable
)
7789 hcntrl
= ahd_inb(ahd
, HCNTRL
);
7791 ahd
->pause
&= ~INTEN
;
7792 ahd
->unpause
&= ~INTEN
;
7795 ahd
->pause
|= INTEN
;
7796 ahd
->unpause
|= INTEN
;
7798 ahd_outb(ahd
, HCNTRL
, hcntrl
);
7802 ahd_update_coalescing_values(struct ahd_softc
*ahd
, u_int timer
, u_int maxcmds
,
7805 if (timer
> AHD_TIMER_MAX_US
)
7806 timer
= AHD_TIMER_MAX_US
;
7807 ahd
->int_coalescing_timer
= timer
;
7809 if (maxcmds
> AHD_INT_COALESCING_MAXCMDS_MAX
)
7810 maxcmds
= AHD_INT_COALESCING_MAXCMDS_MAX
;
7811 if (mincmds
> AHD_INT_COALESCING_MINCMDS_MAX
)
7812 mincmds
= AHD_INT_COALESCING_MINCMDS_MAX
;
7813 ahd
->int_coalescing_maxcmds
= maxcmds
;
7814 ahd_outw(ahd
, INT_COALESCING_TIMER
, timer
/ AHD_TIMER_US_PER_TICK
);
7815 ahd_outb(ahd
, INT_COALESCING_MAXCMDS
, -maxcmds
);
7816 ahd_outb(ahd
, INT_COALESCING_MINCMDS
, -mincmds
);
7820 ahd_enable_coalescing(struct ahd_softc
*ahd
, int enable
)
7823 ahd
->hs_mailbox
&= ~ENINT_COALESCE
;
7825 ahd
->hs_mailbox
|= ENINT_COALESCE
;
7826 ahd_outb(ahd
, HS_MAILBOX
, ahd
->hs_mailbox
);
7827 ahd_flush_device_writes(ahd
);
7828 ahd_run_qoutfifo(ahd
);
7832 * Ensure that the card is paused in a location
7833 * outside of all critical sections and that all
7834 * pending work is completed prior to returning.
7835 * This routine should only be called from outside
7836 * an interrupt context.
7839 ahd_pause_and_flushwork(struct ahd_softc
*ahd
)
7845 ahd
->flags
|= AHD_ALL_INTERRUPTS
;
7848 * Freeze the outgoing selections. We do this only
7849 * until we are safely paused without further selections
7853 ahd_outw(ahd
, KERNEL_QFREEZE_COUNT
, ahd
->qfreeze_cnt
);
7854 ahd_outb(ahd
, SEQ_FLAGS2
, ahd_inb(ahd
, SEQ_FLAGS2
) | SELECTOUT_QFROZEN
);
7859 * Give the sequencer some time to service
7860 * any active selections.
7866 intstat
= ahd_inb(ahd
, INTSTAT
);
7867 if ((intstat
& INT_PEND
) == 0) {
7868 ahd_clear_critical_section(ahd
);
7869 intstat
= ahd_inb(ahd
, INTSTAT
);
7872 && (intstat
!= 0xFF || (ahd
->features
& AHD_REMOVABLE
) == 0)
7873 && ((intstat
& INT_PEND
) != 0
7874 || (ahd_inb(ahd
, SCSISEQ0
) & ENSELO
) != 0
7875 || (ahd_inb(ahd
, SSTAT0
) & (SELDO
|SELINGO
)) != 0));
7877 if (maxloops
== 0) {
7878 printk("Infinite interrupt loop, INTSTAT = %x",
7879 ahd_inb(ahd
, INTSTAT
));
7882 ahd_outw(ahd
, KERNEL_QFREEZE_COUNT
, ahd
->qfreeze_cnt
);
7884 ahd_flush_qoutfifo(ahd
);
7886 ahd
->flags
&= ~AHD_ALL_INTERRUPTS
;
7891 ahd_suspend(struct ahd_softc
*ahd
)
7894 ahd_pause_and_flushwork(ahd
);
7896 if (LIST_FIRST(&ahd
->pending_scbs
) != NULL
) {
7905 ahd_resume(struct ahd_softc
*ahd
)
7908 ahd_reset(ahd
, /*reinit*/TRUE
);
7909 ahd_intr_enable(ahd
, TRUE
);
7914 /************************** Busy Target Table *********************************/
7916 * Set SCBPTR to the SCB that contains the busy
7917 * table entry for TCL. Return the offset into
7918 * the SCB that contains the entry for TCL.
7919 * saved_scbid is dereferenced and set to the
7920 * scbid that should be restored once manipualtion
7921 * of the TCL entry is complete.
7924 ahd_index_busy_tcl(struct ahd_softc
*ahd
, u_int
*saved_scbid
, u_int tcl
)
7927 * Index to the SCB that contains the busy entry.
7929 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
7930 *saved_scbid
= ahd_get_scbptr(ahd
);
7931 ahd_set_scbptr(ahd
, TCL_LUN(tcl
)
7932 | ((TCL_TARGET_OFFSET(tcl
) & 0xC) << 4));
7935 * And now calculate the SCB offset to the entry.
7936 * Each entry is 2 bytes wide, hence the
7937 * multiplication by 2.
7939 return (((TCL_TARGET_OFFSET(tcl
) & 0x3) << 1) + SCB_DISCONNECTED_LISTS
);
7943 * Return the untagged transaction id for a given target/channel lun.
7946 ahd_find_busy_tcl(struct ahd_softc
*ahd
, u_int tcl
)
7952 scb_offset
= ahd_index_busy_tcl(ahd
, &saved_scbptr
, tcl
);
7953 scbid
= ahd_inw_scbram(ahd
, scb_offset
);
7954 ahd_set_scbptr(ahd
, saved_scbptr
);
7959 ahd_busy_tcl(struct ahd_softc
*ahd
, u_int tcl
, u_int scbid
)
7964 scb_offset
= ahd_index_busy_tcl(ahd
, &saved_scbptr
, tcl
);
7965 ahd_outw(ahd
, scb_offset
, scbid
);
7966 ahd_set_scbptr(ahd
, saved_scbptr
);
7969 /************************** SCB and SCB queue management **********************/
7971 ahd_match_scb(struct ahd_softc
*ahd
, struct scb
*scb
, int target
,
7972 char channel
, int lun
, u_int tag
, role_t role
)
7974 int targ
= SCB_GET_TARGET(ahd
, scb
);
7975 char chan
= SCB_GET_CHANNEL(ahd
, scb
);
7976 int slun
= SCB_GET_LUN(scb
);
7979 match
= ((chan
== channel
) || (channel
== ALL_CHANNELS
));
7981 match
= ((targ
== target
) || (target
== CAM_TARGET_WILDCARD
));
7983 match
= ((lun
== slun
) || (lun
== CAM_LUN_WILDCARD
));
7985 #ifdef AHD_TARGET_MODE
7988 group
= XPT_FC_GROUP(scb
->io_ctx
->ccb_h
.func_code
);
7989 if (role
== ROLE_INITIATOR
) {
7990 match
= (group
!= XPT_FC_GROUP_TMODE
)
7991 && ((tag
== SCB_GET_TAG(scb
))
7992 || (tag
== SCB_LIST_NULL
));
7993 } else if (role
== ROLE_TARGET
) {
7994 match
= (group
== XPT_FC_GROUP_TMODE
)
7995 && ((tag
== scb
->io_ctx
->csio
.tag_id
)
7996 || (tag
== SCB_LIST_NULL
));
7998 #else /* !AHD_TARGET_MODE */
7999 match
= ((tag
== SCB_GET_TAG(scb
)) || (tag
== SCB_LIST_NULL
));
8000 #endif /* AHD_TARGET_MODE */
8007 ahd_freeze_devq(struct ahd_softc
*ahd
, struct scb
*scb
)
8013 target
= SCB_GET_TARGET(ahd
, scb
);
8014 lun
= SCB_GET_LUN(scb
);
8015 channel
= SCB_GET_CHANNEL(ahd
, scb
);
8017 ahd_search_qinfifo(ahd
, target
, channel
, lun
,
8018 /*tag*/SCB_LIST_NULL
, ROLE_UNKNOWN
,
8019 CAM_REQUEUE_REQ
, SEARCH_COMPLETE
);
8021 ahd_platform_freeze_devq(ahd
, scb
);
8025 ahd_qinfifo_requeue_tail(struct ahd_softc
*ahd
, struct scb
*scb
)
8027 struct scb
*prev_scb
;
8028 ahd_mode_state saved_modes
;
8030 saved_modes
= ahd_save_modes(ahd
);
8031 ahd_set_modes(ahd
, AHD_MODE_CCHAN
, AHD_MODE_CCHAN
);
8033 if (ahd_qinfifo_count(ahd
) != 0) {
8037 prev_pos
= AHD_QIN_WRAP(ahd
->qinfifonext
- 1);
8038 prev_tag
= ahd
->qinfifo
[prev_pos
];
8039 prev_scb
= ahd_lookup_scb(ahd
, prev_tag
);
8041 ahd_qinfifo_requeue(ahd
, prev_scb
, scb
);
8042 ahd_set_hnscb_qoff(ahd
, ahd
->qinfifonext
);
8043 ahd_restore_modes(ahd
, saved_modes
);
8047 ahd_qinfifo_requeue(struct ahd_softc
*ahd
, struct scb
*prev_scb
,
8050 if (prev_scb
== NULL
) {
8053 busaddr
= ahd_le32toh(scb
->hscb
->hscb_busaddr
);
8054 ahd_outl(ahd
, NEXT_QUEUED_SCB_ADDR
, busaddr
);
8056 prev_scb
->hscb
->next_hscb_busaddr
= scb
->hscb
->hscb_busaddr
;
8057 ahd_sync_scb(ahd
, prev_scb
,
8058 BUS_DMASYNC_PREREAD
|BUS_DMASYNC_PREWRITE
);
8060 ahd
->qinfifo
[AHD_QIN_WRAP(ahd
->qinfifonext
)] = SCB_GET_TAG(scb
);
8062 scb
->hscb
->next_hscb_busaddr
= ahd
->next_queued_hscb
->hscb_busaddr
;
8063 ahd_sync_scb(ahd
, scb
, BUS_DMASYNC_PREREAD
|BUS_DMASYNC_PREWRITE
);
8067 ahd_qinfifo_count(struct ahd_softc
*ahd
)
8071 u_int wrap_qinfifonext
;
8073 AHD_ASSERT_MODES(ahd
, AHD_MODE_CCHAN_MSK
, AHD_MODE_CCHAN_MSK
);
8074 qinpos
= ahd_get_snscb_qoff(ahd
);
8075 wrap_qinpos
= AHD_QIN_WRAP(qinpos
);
8076 wrap_qinfifonext
= AHD_QIN_WRAP(ahd
->qinfifonext
);
8077 if (wrap_qinfifonext
>= wrap_qinpos
)
8078 return (wrap_qinfifonext
- wrap_qinpos
);
8080 return (wrap_qinfifonext
8081 + ARRAY_SIZE(ahd
->qinfifo
) - wrap_qinpos
);
8085 ahd_reset_cmds_pending(struct ahd_softc
*ahd
)
8088 ahd_mode_state saved_modes
;
8091 saved_modes
= ahd_save_modes(ahd
);
8092 ahd_set_modes(ahd
, AHD_MODE_CCHAN
, AHD_MODE_CCHAN
);
8095 * Don't count any commands as outstanding that the
8096 * sequencer has already marked for completion.
8098 ahd_flush_qoutfifo(ahd
);
8101 LIST_FOREACH(scb
, &ahd
->pending_scbs
, pending_links
) {
8104 ahd_outw(ahd
, CMDS_PENDING
, pending_cmds
- ahd_qinfifo_count(ahd
));
8105 ahd_restore_modes(ahd
, saved_modes
);
8106 ahd
->flags
&= ~AHD_UPDATE_PEND_CMDS
;
8110 ahd_done_with_status(struct ahd_softc
*ahd
, struct scb
*scb
, uint32_t status
)
8115 ostat
= ahd_get_transaction_status(scb
);
8116 if (ostat
== CAM_REQ_INPROG
)
8117 ahd_set_transaction_status(scb
, status
);
8118 cstat
= ahd_get_transaction_status(scb
);
8119 if (cstat
!= CAM_REQ_CMP
)
8120 ahd_freeze_scb(scb
);
8125 ahd_search_qinfifo(struct ahd_softc
*ahd
, int target
, char channel
,
8126 int lun
, u_int tag
, role_t role
, uint32_t status
,
8127 ahd_search_action action
)
8130 struct scb
*mk_msg_scb
;
8131 struct scb
*prev_scb
;
8132 ahd_mode_state saved_modes
;
8145 /* Must be in CCHAN mode */
8146 saved_modes
= ahd_save_modes(ahd
);
8147 ahd_set_modes(ahd
, AHD_MODE_CCHAN
, AHD_MODE_CCHAN
);
8150 * Halt any pending SCB DMA. The sequencer will reinitiate
8151 * this dma if the qinfifo is not empty once we unpause.
8153 if ((ahd_inb(ahd
, CCSCBCTL
) & (CCARREN
|CCSCBEN
|CCSCBDIR
))
8154 == (CCARREN
|CCSCBEN
|CCSCBDIR
)) {
8155 ahd_outb(ahd
, CCSCBCTL
,
8156 ahd_inb(ahd
, CCSCBCTL
) & ~(CCARREN
|CCSCBEN
));
8157 while ((ahd_inb(ahd
, CCSCBCTL
) & (CCARREN
|CCSCBEN
)) != 0)
8160 /* Determine sequencer's position in the qinfifo. */
8161 qintail
= AHD_QIN_WRAP(ahd
->qinfifonext
);
8162 qinstart
= ahd_get_snscb_qoff(ahd
);
8163 qinpos
= AHD_QIN_WRAP(qinstart
);
8167 if (action
== SEARCH_PRINT
) {
8168 printk("qinstart = %d qinfifonext = %d\nQINFIFO:",
8169 qinstart
, ahd
->qinfifonext
);
8173 * Start with an empty queue. Entries that are not chosen
8174 * for removal will be re-added to the queue as we go.
8176 ahd
->qinfifonext
= qinstart
;
8177 busaddr
= ahd_le32toh(ahd
->next_queued_hscb
->hscb_busaddr
);
8178 ahd_outl(ahd
, NEXT_QUEUED_SCB_ADDR
, busaddr
);
8180 while (qinpos
!= qintail
) {
8181 scb
= ahd_lookup_scb(ahd
, ahd
->qinfifo
[qinpos
]);
8183 printk("qinpos = %d, SCB index = %d\n",
8184 qinpos
, ahd
->qinfifo
[qinpos
]);
8188 if (ahd_match_scb(ahd
, scb
, target
, channel
, lun
, tag
, role
)) {
8190 * We found an scb that needs to be acted on.
8194 case SEARCH_COMPLETE
:
8195 if ((scb
->flags
& SCB_ACTIVE
) == 0)
8196 printk("Inactive SCB in qinfifo\n");
8197 ahd_done_with_status(ahd
, scb
, status
);
8202 printk(" 0x%x", ahd
->qinfifo
[qinpos
]);
8205 ahd_qinfifo_requeue(ahd
, prev_scb
, scb
);
8210 ahd_qinfifo_requeue(ahd
, prev_scb
, scb
);
8213 qinpos
= AHD_QIN_WRAP(qinpos
+1);
8216 ahd_set_hnscb_qoff(ahd
, ahd
->qinfifonext
);
8218 if (action
== SEARCH_PRINT
)
8219 printk("\nWAITING_TID_QUEUES:\n");
8222 * Search waiting for selection lists. We traverse the
8223 * list of "their ids" waiting for selection and, if
8224 * appropriate, traverse the SCBs of each "their id"
8225 * looking for matches.
8227 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
8228 seq_flags2
= ahd_inb(ahd
, SEQ_FLAGS2
);
8229 if ((seq_flags2
& PENDING_MK_MESSAGE
) != 0) {
8230 scbid
= ahd_inw(ahd
, MK_MESSAGE_SCB
);
8231 mk_msg_scb
= ahd_lookup_scb(ahd
, scbid
);
8234 savedscbptr
= ahd_get_scbptr(ahd
);
8235 tid_next
= ahd_inw(ahd
, WAITING_TID_HEAD
);
8236 tid_prev
= SCB_LIST_NULL
;
8238 for (scbid
= tid_next
; !SCBID_IS_NULL(scbid
); scbid
= tid_next
) {
8243 if (targets
> AHD_NUM_TARGETS
)
8244 panic("TID LIST LOOP");
8246 if (scbid
>= ahd
->scb_data
.numscbs
) {
8247 printk("%s: Waiting TID List inconsistency. "
8248 "SCB index == 0x%x, yet numscbs == 0x%x.",
8249 ahd_name(ahd
), scbid
, ahd
->scb_data
.numscbs
);
8250 ahd_dump_card_state(ahd
);
8251 panic("for safety");
8253 scb
= ahd_lookup_scb(ahd
, scbid
);
8255 printk("%s: SCB = 0x%x Not Active!\n",
8256 ahd_name(ahd
), scbid
);
8257 panic("Waiting TID List traversal\n");
8259 ahd_set_scbptr(ahd
, scbid
);
8260 tid_next
= ahd_inw_scbram(ahd
, SCB_NEXT2
);
8261 if (ahd_match_scb(ahd
, scb
, target
, channel
, CAM_LUN_WILDCARD
,
8262 SCB_LIST_NULL
, ROLE_UNKNOWN
) == 0) {
8268 * We found a list of scbs that needs to be searched.
8270 if (action
== SEARCH_PRINT
)
8271 printk(" %d ( ", SCB_GET_TARGET(ahd
, scb
));
8273 found
+= ahd_search_scb_list(ahd
, target
, channel
,
8274 lun
, tag
, role
, status
,
8275 action
, &tid_head
, &tid_tail
,
8276 SCB_GET_TARGET(ahd
, scb
));
8278 * Check any MK_MESSAGE SCB that is still waiting to
8279 * enter this target's waiting for selection queue.
8281 if (mk_msg_scb
!= NULL
8282 && ahd_match_scb(ahd
, mk_msg_scb
, target
, channel
,
8286 * We found an scb that needs to be acted on.
8290 case SEARCH_COMPLETE
:
8291 if ((mk_msg_scb
->flags
& SCB_ACTIVE
) == 0)
8292 printk("Inactive SCB pending MK_MSG\n");
8293 ahd_done_with_status(ahd
, mk_msg_scb
, status
);
8299 printk("Removing MK_MSG scb\n");
8302 * Reset our tail to the tail of the
8303 * main per-target list.
8305 tail_offset
= WAITING_SCB_TAILS
8306 + (2 * SCB_GET_TARGET(ahd
, mk_msg_scb
));
8307 ahd_outw(ahd
, tail_offset
, tid_tail
);
8309 seq_flags2
&= ~PENDING_MK_MESSAGE
;
8310 ahd_outb(ahd
, SEQ_FLAGS2
, seq_flags2
);
8311 ahd_outw(ahd
, CMDS_PENDING
,
8312 ahd_inw(ahd
, CMDS_PENDING
)-1);
8317 printk(" 0x%x", SCB_GET_TAG(scb
));
8324 if (mk_msg_scb
!= NULL
8325 && SCBID_IS_NULL(tid_head
)
8326 && ahd_match_scb(ahd
, scb
, target
, channel
, CAM_LUN_WILDCARD
,
8327 SCB_LIST_NULL
, ROLE_UNKNOWN
)) {
8330 * When removing the last SCB for a target
8331 * queue with a pending MK_MESSAGE scb, we
8332 * must queue the MK_MESSAGE scb.
8334 printk("Queueing mk_msg_scb\n");
8335 tid_head
= ahd_inw(ahd
, MK_MESSAGE_SCB
);
8336 seq_flags2
&= ~PENDING_MK_MESSAGE
;
8337 ahd_outb(ahd
, SEQ_FLAGS2
, seq_flags2
);
8340 if (tid_head
!= scbid
)
8341 ahd_stitch_tid_list(ahd
, tid_prev
, tid_head
, tid_next
);
8342 if (!SCBID_IS_NULL(tid_head
))
8343 tid_prev
= tid_head
;
8344 if (action
== SEARCH_PRINT
)
8348 /* Restore saved state. */
8349 ahd_set_scbptr(ahd
, savedscbptr
);
8350 ahd_restore_modes(ahd
, saved_modes
);
8355 ahd_search_scb_list(struct ahd_softc
*ahd
, int target
, char channel
,
8356 int lun
, u_int tag
, role_t role
, uint32_t status
,
8357 ahd_search_action action
, u_int
*list_head
,
8358 u_int
*list_tail
, u_int tid
)
8366 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
8368 prev
= SCB_LIST_NULL
;
8370 *list_tail
= SCB_LIST_NULL
;
8371 for (scbid
= next
; !SCBID_IS_NULL(scbid
); scbid
= next
) {
8372 if (scbid
>= ahd
->scb_data
.numscbs
) {
8373 printk("%s:SCB List inconsistency. "
8374 "SCB == 0x%x, yet numscbs == 0x%x.",
8375 ahd_name(ahd
), scbid
, ahd
->scb_data
.numscbs
);
8376 ahd_dump_card_state(ahd
);
8377 panic("for safety");
8379 scb
= ahd_lookup_scb(ahd
, scbid
);
8381 printk("%s: SCB = %d Not Active!\n",
8382 ahd_name(ahd
), scbid
);
8383 panic("Waiting List traversal\n");
8385 ahd_set_scbptr(ahd
, scbid
);
8387 next
= ahd_inw_scbram(ahd
, SCB_NEXT
);
8388 if (ahd_match_scb(ahd
, scb
, target
, channel
,
8389 lun
, SCB_LIST_NULL
, role
) == 0) {
8395 case SEARCH_COMPLETE
:
8396 if ((scb
->flags
& SCB_ACTIVE
) == 0)
8397 printk("Inactive SCB in Waiting List\n");
8398 ahd_done_with_status(ahd
, scb
, status
);
8401 ahd_rem_wscb(ahd
, scbid
, prev
, next
, tid
);
8403 if (SCBID_IS_NULL(prev
))
8407 printk("0x%x ", scbid
);
8413 if (found
> AHD_SCB_MAX
)
8414 panic("SCB LIST LOOP");
8416 if (action
== SEARCH_COMPLETE
8417 || action
== SEARCH_REMOVE
)
8418 ahd_outw(ahd
, CMDS_PENDING
, ahd_inw(ahd
, CMDS_PENDING
) - found
);
8423 ahd_stitch_tid_list(struct ahd_softc
*ahd
, u_int tid_prev
,
8424 u_int tid_cur
, u_int tid_next
)
8426 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
8428 if (SCBID_IS_NULL(tid_cur
)) {
8430 /* Bypass current TID list */
8431 if (SCBID_IS_NULL(tid_prev
)) {
8432 ahd_outw(ahd
, WAITING_TID_HEAD
, tid_next
);
8434 ahd_set_scbptr(ahd
, tid_prev
);
8435 ahd_outw(ahd
, SCB_NEXT2
, tid_next
);
8437 if (SCBID_IS_NULL(tid_next
))
8438 ahd_outw(ahd
, WAITING_TID_TAIL
, tid_prev
);
8441 /* Stitch through tid_cur */
8442 if (SCBID_IS_NULL(tid_prev
)) {
8443 ahd_outw(ahd
, WAITING_TID_HEAD
, tid_cur
);
8445 ahd_set_scbptr(ahd
, tid_prev
);
8446 ahd_outw(ahd
, SCB_NEXT2
, tid_cur
);
8448 ahd_set_scbptr(ahd
, tid_cur
);
8449 ahd_outw(ahd
, SCB_NEXT2
, tid_next
);
8451 if (SCBID_IS_NULL(tid_next
))
8452 ahd_outw(ahd
, WAITING_TID_TAIL
, tid_cur
);
8457 * Manipulate the waiting for selection list and return the
8458 * scb that follows the one that we remove.
8461 ahd_rem_wscb(struct ahd_softc
*ahd
, u_int scbid
,
8462 u_int prev
, u_int next
, u_int tid
)
8466 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
8467 if (!SCBID_IS_NULL(prev
)) {
8468 ahd_set_scbptr(ahd
, prev
);
8469 ahd_outw(ahd
, SCB_NEXT
, next
);
8473 * SCBs that have MK_MESSAGE set in them may
8474 * cause the tail pointer to be updated without
8475 * setting the next pointer of the previous tail.
8476 * Only clear the tail if the removed SCB was
8479 tail_offset
= WAITING_SCB_TAILS
+ (2 * tid
);
8480 if (SCBID_IS_NULL(next
)
8481 && ahd_inw(ahd
, tail_offset
) == scbid
)
8482 ahd_outw(ahd
, tail_offset
, prev
);
8484 ahd_add_scb_to_free_list(ahd
, scbid
);
8489 * Add the SCB as selected by SCBPTR onto the on chip list of
8490 * free hardware SCBs. This list is empty/unused if we are not
8491 * performing SCB paging.
8494 ahd_add_scb_to_free_list(struct ahd_softc
*ahd
, u_int scbid
)
8496 /* XXX Need some other mechanism to designate "free". */
8498 * Invalidate the tag so that our abort
8499 * routines don't think it's active.
8500 ahd_outb(ahd, SCB_TAG, SCB_LIST_NULL);
8504 /******************************** Error Handling ******************************/
8506 * Abort all SCBs that match the given description (target/channel/lun/tag),
8507 * setting their status to the passed in status if the status has not already
8508 * been modified from CAM_REQ_INPROG. This routine assumes that the sequencer
8509 * is paused before it is called.
8512 ahd_abort_scbs(struct ahd_softc
*ahd
, int target
, char channel
,
8513 int lun
, u_int tag
, role_t role
, uint32_t status
)
8516 struct scb
*scbp_next
;
8522 ahd_mode_state saved_modes
;
8524 /* restore this when we're done */
8525 saved_modes
= ahd_save_modes(ahd
);
8526 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
8528 found
= ahd_search_qinfifo(ahd
, target
, channel
, lun
, SCB_LIST_NULL
,
8529 role
, CAM_REQUEUE_REQ
, SEARCH_COMPLETE
);
8532 * Clean out the busy target table for any untagged commands.
8536 if (target
!= CAM_TARGET_WILDCARD
) {
8543 if (lun
== CAM_LUN_WILDCARD
) {
8545 maxlun
= AHD_NUM_LUNS_NONPKT
;
8546 } else if (lun
>= AHD_NUM_LUNS_NONPKT
) {
8547 minlun
= maxlun
= 0;
8553 if (role
!= ROLE_TARGET
) {
8554 for (;i
< maxtarget
; i
++) {
8555 for (j
= minlun
;j
< maxlun
; j
++) {
8559 tcl
= BUILD_TCL_RAW(i
, 'A', j
);
8560 scbid
= ahd_find_busy_tcl(ahd
, tcl
);
8561 scbp
= ahd_lookup_scb(ahd
, scbid
);
8563 || ahd_match_scb(ahd
, scbp
, target
, channel
,
8564 lun
, tag
, role
) == 0)
8566 ahd_unbusy_tcl(ahd
, BUILD_TCL_RAW(i
, 'A', j
));
8572 * Don't abort commands that have already completed,
8573 * but haven't quite made it up to the host yet.
8575 ahd_flush_qoutfifo(ahd
);
8578 * Go through the pending CCB list and look for
8579 * commands for this target that are still active.
8580 * These are other tagged commands that were
8581 * disconnected when the reset occurred.
8583 scbp_next
= LIST_FIRST(&ahd
->pending_scbs
);
8584 while (scbp_next
!= NULL
) {
8586 scbp_next
= LIST_NEXT(scbp
, pending_links
);
8587 if (ahd_match_scb(ahd
, scbp
, target
, channel
, lun
, tag
, role
)) {
8590 ostat
= ahd_get_transaction_status(scbp
);
8591 if (ostat
== CAM_REQ_INPROG
)
8592 ahd_set_transaction_status(scbp
, status
);
8593 if (ahd_get_transaction_status(scbp
) != CAM_REQ_CMP
)
8594 ahd_freeze_scb(scbp
);
8595 if ((scbp
->flags
& SCB_ACTIVE
) == 0)
8596 printk("Inactive SCB on pending list\n");
8597 ahd_done(ahd
, scbp
);
8601 ahd_restore_modes(ahd
, saved_modes
);
8602 ahd_platform_abort_scbs(ahd
, target
, channel
, lun
, tag
, role
, status
);
8603 ahd
->flags
|= AHD_UPDATE_PEND_CMDS
;
8608 ahd_reset_current_bus(struct ahd_softc
*ahd
)
8612 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
8613 ahd_outb(ahd
, SIMODE1
, ahd_inb(ahd
, SIMODE1
) & ~ENSCSIRST
);
8614 scsiseq
= ahd_inb(ahd
, SCSISEQ0
) & ~(ENSELO
|ENARBO
|SCSIRSTO
);
8615 ahd_outb(ahd
, SCSISEQ0
, scsiseq
| SCSIRSTO
);
8616 ahd_flush_device_writes(ahd
);
8617 ahd_delay(AHD_BUSRESET_DELAY
);
8618 /* Turn off the bus reset */
8619 ahd_outb(ahd
, SCSISEQ0
, scsiseq
);
8620 ahd_flush_device_writes(ahd
);
8621 ahd_delay(AHD_BUSRESET_DELAY
);
8622 if ((ahd
->bugs
& AHD_SCSIRST_BUG
) != 0) {
8625 * Certain chip state is not cleared for
8626 * SCSI bus resets that we initiate, so
8627 * we must reset the chip.
8629 ahd_reset(ahd
, /*reinit*/TRUE
);
8630 ahd_intr_enable(ahd
, /*enable*/TRUE
);
8631 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
8634 ahd_clear_intstat(ahd
);
8638 ahd_reset_channel(struct ahd_softc
*ahd
, char channel
, int initiate_reset
)
8640 struct ahd_devinfo caminfo
;
8650 * Check if the last bus reset is cleared
8652 if (ahd
->flags
& AHD_BUS_RESET_ACTIVE
) {
8653 printk("%s: bus reset still active\n",
8657 ahd
->flags
|= AHD_BUS_RESET_ACTIVE
;
8659 ahd
->pending_device
= NULL
;
8661 ahd_compile_devinfo(&caminfo
,
8662 CAM_TARGET_WILDCARD
,
8663 CAM_TARGET_WILDCARD
,
8665 channel
, ROLE_UNKNOWN
);
8668 /* Make sure the sequencer is in a safe location. */
8669 ahd_clear_critical_section(ahd
);
8672 * Run our command complete fifos to ensure that we perform
8673 * completion processing on any commands that 'completed'
8674 * before the reset occurred.
8676 ahd_run_qoutfifo(ahd
);
8677 #ifdef AHD_TARGET_MODE
8678 if ((ahd
->flags
& AHD_TARGETROLE
) != 0) {
8679 ahd_run_tqinfifo(ahd
, /*paused*/TRUE
);
8682 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
8685 * Disable selections so no automatic hardware
8686 * functions will modify chip state.
8688 ahd_outb(ahd
, SCSISEQ0
, 0);
8689 ahd_outb(ahd
, SCSISEQ1
, 0);
8692 * Safely shut down our DMA engines. Always start with
8693 * the FIFO that is not currently active (if any are
8694 * actively connected).
8696 next_fifo
= fifo
= ahd_inb(ahd
, DFFSTAT
) & CURRFIFO
;
8697 if (next_fifo
> CURRFIFO_1
)
8698 /* If disconneced, arbitrarily start with FIFO1. */
8699 next_fifo
= fifo
= 0;
8701 next_fifo
^= CURRFIFO_1
;
8702 ahd_set_modes(ahd
, next_fifo
, next_fifo
);
8703 ahd_outb(ahd
, DFCNTRL
,
8704 ahd_inb(ahd
, DFCNTRL
) & ~(SCSIEN
|HDMAEN
));
8705 while ((ahd_inb(ahd
, DFCNTRL
) & HDMAENACK
) != 0)
8708 * Set CURRFIFO to the now inactive channel.
8710 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
8711 ahd_outb(ahd
, DFFSTAT
, next_fifo
);
8712 } while (next_fifo
!= fifo
);
8715 * Reset the bus if we are initiating this reset
8717 ahd_clear_msg_state(ahd
);
8718 ahd_outb(ahd
, SIMODE1
,
8719 ahd_inb(ahd
, SIMODE1
) & ~(ENBUSFREE
|ENSCSIRST
));
8722 ahd_reset_current_bus(ahd
);
8724 ahd_clear_intstat(ahd
);
8727 * Clean up all the state information for the
8728 * pending transactions on this bus.
8730 found
= ahd_abort_scbs(ahd
, CAM_TARGET_WILDCARD
, channel
,
8731 CAM_LUN_WILDCARD
, SCB_LIST_NULL
,
8732 ROLE_UNKNOWN
, CAM_SCSI_BUS_RESET
);
8735 * Cleanup anything left in the FIFOs.
8737 ahd_clear_fifo(ahd
, 0);
8738 ahd_clear_fifo(ahd
, 1);
8741 * Clear SCSI interrupt status
8743 ahd_outb(ahd
, CLRSINT1
, CLRSCSIRSTI
);
8746 * Reenable selections
8748 ahd_outb(ahd
, SIMODE1
, ahd_inb(ahd
, SIMODE1
) | ENSCSIRST
);
8749 scsiseq
= ahd_inb(ahd
, SCSISEQ_TEMPLATE
);
8750 ahd_outb(ahd
, SCSISEQ1
, scsiseq
& (ENSELI
|ENRSELI
|ENAUTOATNP
));
8752 max_scsiid
= (ahd
->features
& AHD_WIDE
) ? 15 : 7;
8753 #ifdef AHD_TARGET_MODE
8755 * Send an immediate notify ccb to all target more peripheral
8756 * drivers affected by this action.
8758 for (target
= 0; target
<= max_scsiid
; target
++) {
8759 struct ahd_tmode_tstate
* tstate
;
8762 tstate
= ahd
->enabled_targets
[target
];
8765 for (lun
= 0; lun
< AHD_NUM_LUNS
; lun
++) {
8766 struct ahd_tmode_lstate
* lstate
;
8768 lstate
= tstate
->enabled_luns
[lun
];
8772 ahd_queue_lstate_event(ahd
, lstate
, CAM_TARGET_WILDCARD
,
8773 EVENT_TYPE_BUS_RESET
, /*arg*/0);
8774 ahd_send_lstate_events(ahd
, lstate
);
8779 * Revert to async/narrow transfers until we renegotiate.
8781 for (target
= 0; target
<= max_scsiid
; target
++) {
8783 if (ahd
->enabled_targets
[target
] == NULL
)
8785 for (initiator
= 0; initiator
<= max_scsiid
; initiator
++) {
8786 struct ahd_devinfo devinfo
;
8788 ahd_compile_devinfo(&devinfo
, target
, initiator
,
8791 ahd_set_width(ahd
, &devinfo
, MSG_EXT_WDTR_BUS_8_BIT
,
8792 AHD_TRANS_CUR
, /*paused*/TRUE
);
8793 ahd_set_syncrate(ahd
, &devinfo
, /*period*/0,
8794 /*offset*/0, /*ppr_options*/0,
8795 AHD_TRANS_CUR
, /*paused*/TRUE
);
8799 /* Notify the XPT that a bus reset occurred */
8800 ahd_send_async(ahd
, caminfo
.channel
, CAM_TARGET_WILDCARD
,
8801 CAM_LUN_WILDCARD
, AC_BUS_RESET
);
8808 /**************************** Statistics Processing ***************************/
8810 ahd_stat_timer(struct timer_list
*t
)
8812 struct ahd_softc
*ahd
= from_timer(ahd
, t
, stat_timer
);
8818 enint_coal
= ahd
->hs_mailbox
& ENINT_COALESCE
;
8819 if (ahd
->cmdcmplt_total
> ahd
->int_coalescing_threshold
)
8820 enint_coal
|= ENINT_COALESCE
;
8821 else if (ahd
->cmdcmplt_total
< ahd
->int_coalescing_stop_threshold
)
8822 enint_coal
&= ~ENINT_COALESCE
;
8824 if (enint_coal
!= (ahd
->hs_mailbox
& ENINT_COALESCE
)) {
8825 ahd_enable_coalescing(ahd
, enint_coal
);
8827 if ((ahd_debug
& AHD_SHOW_INT_COALESCING
) != 0)
8828 printk("%s: Interrupt coalescing "
8829 "now %sabled. Cmds %d\n",
8831 (enint_coal
& ENINT_COALESCE
) ? "en" : "dis",
8832 ahd
->cmdcmplt_total
);
8836 ahd
->cmdcmplt_bucket
= (ahd
->cmdcmplt_bucket
+1) & (AHD_STAT_BUCKETS
-1);
8837 ahd
->cmdcmplt_total
-= ahd
->cmdcmplt_counts
[ahd
->cmdcmplt_bucket
];
8838 ahd
->cmdcmplt_counts
[ahd
->cmdcmplt_bucket
] = 0;
8839 ahd_timer_reset(&ahd
->stat_timer
, AHD_STAT_UPDATE_US
);
8840 ahd_unlock(ahd
, &s
);
8843 /****************************** Status Processing *****************************/
8846 ahd_handle_scsi_status(struct ahd_softc
*ahd
, struct scb
*scb
)
8848 struct hardware_scb
*hscb
;
8852 * The sequencer freezes its select-out queue
8853 * anytime a SCSI status error occurs. We must
8854 * handle the error and increment our qfreeze count
8855 * to allow the sequencer to continue. We don't
8856 * bother clearing critical sections here since all
8857 * operations are on data structures that the sequencer
8858 * is not touching once the queue is frozen.
8862 if (ahd_is_paused(ahd
)) {
8869 /* Freeze the queue until the client sees the error. */
8870 ahd_freeze_devq(ahd
, scb
);
8871 ahd_freeze_scb(scb
);
8873 ahd_outw(ahd
, KERNEL_QFREEZE_COUNT
, ahd
->qfreeze_cnt
);
8878 /* Don't want to clobber the original sense code */
8879 if ((scb
->flags
& SCB_SENSE
) != 0) {
8881 * Clear the SCB_SENSE Flag and perform
8882 * a normal command completion.
8884 scb
->flags
&= ~SCB_SENSE
;
8885 ahd_set_transaction_status(scb
, CAM_AUTOSENSE_FAIL
);
8889 ahd_set_transaction_status(scb
, CAM_SCSI_STATUS_ERROR
);
8890 ahd_set_scsi_status(scb
, hscb
->shared_data
.istatus
.scsi_status
);
8891 switch (hscb
->shared_data
.istatus
.scsi_status
) {
8892 case STATUS_PKT_SENSE
:
8894 struct scsi_status_iu_header
*siu
;
8896 ahd_sync_sense(ahd
, scb
, BUS_DMASYNC_POSTREAD
);
8897 siu
= (struct scsi_status_iu_header
*)scb
->sense_data
;
8898 ahd_set_scsi_status(scb
, siu
->status
);
8900 if ((ahd_debug
& AHD_SHOW_SENSE
) != 0) {
8901 ahd_print_path(ahd
, scb
);
8902 printk("SCB 0x%x Received PKT Status of 0x%x\n",
8903 SCB_GET_TAG(scb
), siu
->status
);
8904 printk("\tflags = 0x%x, sense len = 0x%x, "
8906 siu
->flags
, scsi_4btoul(siu
->sense_length
),
8907 scsi_4btoul(siu
->pkt_failures_length
));
8910 if ((siu
->flags
& SIU_RSPVALID
) != 0) {
8911 ahd_print_path(ahd
, scb
);
8912 if (scsi_4btoul(siu
->pkt_failures_length
) < 4) {
8913 printk("Unable to parse pkt_failures\n");
8916 switch (SIU_PKTFAIL_CODE(siu
)) {
8918 printk("No packet failure found\n");
8920 case SIU_PFC_CIU_FIELDS_INVALID
:
8921 printk("Invalid Command IU Field\n");
8923 case SIU_PFC_TMF_NOT_SUPPORTED
:
8924 printk("TMF not supported\n");
8926 case SIU_PFC_TMF_FAILED
:
8927 printk("TMF failed\n");
8929 case SIU_PFC_INVALID_TYPE_CODE
:
8930 printk("Invalid L_Q Type code\n");
8932 case SIU_PFC_ILLEGAL_REQUEST
:
8933 printk("Illegal request\n");
8938 if (siu
->status
== SCSI_STATUS_OK
)
8939 ahd_set_transaction_status(scb
,
8942 if ((siu
->flags
& SIU_SNSVALID
) != 0) {
8943 scb
->flags
|= SCB_PKT_SENSE
;
8945 if ((ahd_debug
& AHD_SHOW_SENSE
) != 0)
8946 printk("Sense data available\n");
8952 case SCSI_STATUS_CMD_TERMINATED
:
8953 case SCSI_STATUS_CHECK_COND
:
8955 struct ahd_devinfo devinfo
;
8956 struct ahd_dma_seg
*sg
;
8957 struct scsi_sense
*sc
;
8958 struct ahd_initiator_tinfo
*targ_info
;
8959 struct ahd_tmode_tstate
*tstate
;
8960 struct ahd_transinfo
*tinfo
;
8962 if (ahd_debug
& AHD_SHOW_SENSE
) {
8963 ahd_print_path(ahd
, scb
);
8964 printk("SCB %d: requests Check Status\n",
8969 if (ahd_perform_autosense(scb
) == 0)
8972 ahd_compile_devinfo(&devinfo
, SCB_GET_OUR_ID(scb
),
8973 SCB_GET_TARGET(ahd
, scb
),
8975 SCB_GET_CHANNEL(ahd
, scb
),
8977 targ_info
= ahd_fetch_transinfo(ahd
,
8982 tinfo
= &targ_info
->curr
;
8984 sc
= (struct scsi_sense
*)hscb
->shared_data
.idata
.cdb
;
8986 * Save off the residual if there is one.
8988 ahd_update_residual(ahd
, scb
);
8990 if (ahd_debug
& AHD_SHOW_SENSE
) {
8991 ahd_print_path(ahd
, scb
);
8992 printk("Sending Sense\n");
8996 sg
= ahd_sg_setup(ahd
, scb
, sg
, ahd_get_sense_bufaddr(ahd
, scb
),
8997 ahd_get_sense_bufsize(ahd
, scb
),
8999 sc
->opcode
= REQUEST_SENSE
;
9001 if (tinfo
->protocol_version
<= SCSI_REV_2
9002 && SCB_GET_LUN(scb
) < 8)
9003 sc
->byte2
= SCB_GET_LUN(scb
) << 5;
9006 sc
->length
= ahd_get_sense_bufsize(ahd
, scb
);
9010 * We can't allow the target to disconnect.
9011 * This will be an untagged transaction and
9012 * having the target disconnect will make this
9013 * transaction indestinguishable from outstanding
9014 * tagged transactions.
9019 * This request sense could be because the
9020 * the device lost power or in some other
9021 * way has lost our transfer negotiations.
9022 * Renegotiate if appropriate. Unit attention
9023 * errors will be reported before any data
9026 if (ahd_get_residual(scb
) == ahd_get_transfer_length(scb
)) {
9027 ahd_update_neg_request(ahd
, &devinfo
,
9029 AHD_NEG_IF_NON_ASYNC
);
9031 if (tstate
->auto_negotiate
& devinfo
.target_mask
) {
9032 hscb
->control
|= MK_MESSAGE
;
9034 ~(SCB_NEGOTIATE
|SCB_ABORT
|SCB_DEVICE_RESET
);
9035 scb
->flags
|= SCB_AUTO_NEGOTIATE
;
9037 hscb
->cdb_len
= sizeof(*sc
);
9038 ahd_setup_data_scb(ahd
, scb
);
9039 scb
->flags
|= SCB_SENSE
;
9040 ahd_queue_scb(ahd
, scb
);
9043 case SCSI_STATUS_OK
:
9044 printk("%s: Interrupted for status of 0???\n",
9054 ahd_handle_scb_status(struct ahd_softc
*ahd
, struct scb
*scb
)
9056 if (scb
->hscb
->shared_data
.istatus
.scsi_status
!= 0) {
9057 ahd_handle_scsi_status(ahd
, scb
);
9059 ahd_calc_residual(ahd
, scb
);
9065 * Calculate the residual for a just completed SCB.
9068 ahd_calc_residual(struct ahd_softc
*ahd
, struct scb
*scb
)
9070 struct hardware_scb
*hscb
;
9071 struct initiator_status
*spkt
;
9073 uint32_t resid_sgptr
;
9079 * SG_STATUS_VALID clear in sgptr.
9080 * 2) Transferless command
9081 * 3) Never performed any transfers.
9082 * sgptr has SG_FULL_RESID set.
9083 * 4) No residual but target did not
9084 * save data pointers after the
9085 * last transfer, so sgptr was
9087 * 5) We have a partial residual.
9088 * Use residual_sgptr to determine
9093 sgptr
= ahd_le32toh(hscb
->sgptr
);
9094 if ((sgptr
& SG_STATUS_VALID
) == 0)
9097 sgptr
&= ~SG_STATUS_VALID
;
9099 if ((sgptr
& SG_LIST_NULL
) != 0)
9104 * Residual fields are the same in both
9105 * target and initiator status packets,
9106 * so we can always use the initiator fields
9107 * regardless of the role for this SCB.
9109 spkt
= &hscb
->shared_data
.istatus
;
9110 resid_sgptr
= ahd_le32toh(spkt
->residual_sgptr
);
9111 if ((sgptr
& SG_FULL_RESID
) != 0) {
9113 resid
= ahd_get_transfer_length(scb
);
9114 } else if ((resid_sgptr
& SG_LIST_NULL
) != 0) {
9117 } else if ((resid_sgptr
& SG_OVERRUN_RESID
) != 0) {
9118 ahd_print_path(ahd
, scb
);
9119 printk("data overrun detected Tag == 0x%x.\n",
9121 ahd_freeze_devq(ahd
, scb
);
9122 ahd_set_transaction_status(scb
, CAM_DATA_RUN_ERR
);
9123 ahd_freeze_scb(scb
);
9125 } else if ((resid_sgptr
& ~SG_PTR_MASK
) != 0) {
9126 panic("Bogus resid sgptr value 0x%x\n", resid_sgptr
);
9129 struct ahd_dma_seg
*sg
;
9132 * Remainder of the SG where the transfer
9135 resid
= ahd_le32toh(spkt
->residual_datacnt
) & AHD_SG_LEN_MASK
;
9136 sg
= ahd_sg_bus_to_virt(ahd
, scb
, resid_sgptr
& SG_PTR_MASK
);
9138 /* The residual sg_ptr always points to the next sg */
9142 * Add up the contents of all residual
9143 * SG segments that are after the SG where
9144 * the transfer stopped.
9146 while ((ahd_le32toh(sg
->len
) & AHD_DMA_LAST_SEG
) == 0) {
9148 resid
+= ahd_le32toh(sg
->len
) & AHD_SG_LEN_MASK
;
9151 if ((scb
->flags
& SCB_SENSE
) == 0)
9152 ahd_set_residual(scb
, resid
);
9154 ahd_set_sense_residual(scb
, resid
);
9157 if ((ahd_debug
& AHD_SHOW_MISC
) != 0) {
9158 ahd_print_path(ahd
, scb
);
9159 printk("Handled %sResidual of %d bytes\n",
9160 (scb
->flags
& SCB_SENSE
) ? "Sense " : "", resid
);
9165 /******************************* Target Mode **********************************/
9166 #ifdef AHD_TARGET_MODE
9168 * Add a target mode event to this lun's queue
9171 ahd_queue_lstate_event(struct ahd_softc
*ahd
, struct ahd_tmode_lstate
*lstate
,
9172 u_int initiator_id
, u_int event_type
, u_int event_arg
)
9174 struct ahd_tmode_event
*event
;
9177 xpt_freeze_devq(lstate
->path
, /*count*/1);
9178 if (lstate
->event_w_idx
>= lstate
->event_r_idx
)
9179 pending
= lstate
->event_w_idx
- lstate
->event_r_idx
;
9181 pending
= AHD_TMODE_EVENT_BUFFER_SIZE
+ 1
9182 - (lstate
->event_r_idx
- lstate
->event_w_idx
);
9184 if (event_type
== EVENT_TYPE_BUS_RESET
9185 || event_type
== MSG_BUS_DEV_RESET
) {
9187 * Any earlier events are irrelevant, so reset our buffer.
9188 * This has the effect of allowing us to deal with reset
9189 * floods (an external device holding down the reset line)
9190 * without losing the event that is really interesting.
9192 lstate
->event_r_idx
= 0;
9193 lstate
->event_w_idx
= 0;
9194 xpt_release_devq(lstate
->path
, pending
, /*runqueue*/FALSE
);
9197 if (pending
== AHD_TMODE_EVENT_BUFFER_SIZE
) {
9198 xpt_print_path(lstate
->path
);
9199 printk("immediate event %x:%x lost\n",
9200 lstate
->event_buffer
[lstate
->event_r_idx
].event_type
,
9201 lstate
->event_buffer
[lstate
->event_r_idx
].event_arg
);
9202 lstate
->event_r_idx
++;
9203 if (lstate
->event_r_idx
== AHD_TMODE_EVENT_BUFFER_SIZE
)
9204 lstate
->event_r_idx
= 0;
9205 xpt_release_devq(lstate
->path
, /*count*/1, /*runqueue*/FALSE
);
9208 event
= &lstate
->event_buffer
[lstate
->event_w_idx
];
9209 event
->initiator_id
= initiator_id
;
9210 event
->event_type
= event_type
;
9211 event
->event_arg
= event_arg
;
9212 lstate
->event_w_idx
++;
9213 if (lstate
->event_w_idx
== AHD_TMODE_EVENT_BUFFER_SIZE
)
9214 lstate
->event_w_idx
= 0;
9218 * Send any target mode events queued up waiting
9219 * for immediate notify resources.
9222 ahd_send_lstate_events(struct ahd_softc
*ahd
, struct ahd_tmode_lstate
*lstate
)
9224 struct ccb_hdr
*ccbh
;
9225 struct ccb_immed_notify
*inot
;
9227 while (lstate
->event_r_idx
!= lstate
->event_w_idx
9228 && (ccbh
= SLIST_FIRST(&lstate
->immed_notifies
)) != NULL
) {
9229 struct ahd_tmode_event
*event
;
9231 event
= &lstate
->event_buffer
[lstate
->event_r_idx
];
9232 SLIST_REMOVE_HEAD(&lstate
->immed_notifies
, sim_links
.sle
);
9233 inot
= (struct ccb_immed_notify
*)ccbh
;
9234 switch (event
->event_type
) {
9235 case EVENT_TYPE_BUS_RESET
:
9236 ccbh
->status
= CAM_SCSI_BUS_RESET
|CAM_DEV_QFRZN
;
9239 ccbh
->status
= CAM_MESSAGE_RECV
|CAM_DEV_QFRZN
;
9240 inot
->message_args
[0] = event
->event_type
;
9241 inot
->message_args
[1] = event
->event_arg
;
9244 inot
->initiator_id
= event
->initiator_id
;
9245 inot
->sense_len
= 0;
9246 xpt_done((union ccb
*)inot
);
9247 lstate
->event_r_idx
++;
9248 if (lstate
->event_r_idx
== AHD_TMODE_EVENT_BUFFER_SIZE
)
9249 lstate
->event_r_idx
= 0;
9254 /******************** Sequencer Program Patching/Download *********************/
9258 ahd_dumpseq(struct ahd_softc
* ahd
)
9265 ahd_outb(ahd
, SEQCTL0
, PERRORDIS
|FAILDIS
|FASTMODE
|LOADRAM
);
9266 ahd_outw(ahd
, PRGMCNT
, 0);
9267 for (i
= 0; i
< max_prog
; i
++) {
9268 uint8_t ins_bytes
[4];
9270 ahd_insb(ahd
, SEQRAM
, ins_bytes
, 4);
9271 printk("0x%08x\n", ins_bytes
[0] << 24
9272 | ins_bytes
[1] << 16
9280 ahd_loadseq(struct ahd_softc
*ahd
)
9282 struct cs cs_table
[NUM_CRITICAL_SECTIONS
];
9283 u_int begin_set
[NUM_CRITICAL_SECTIONS
];
9284 u_int end_set
[NUM_CRITICAL_SECTIONS
];
9285 const struct patch
*cur_patch
;
9291 u_int sg_prefetch_cnt
;
9292 u_int sg_prefetch_cnt_limit
;
9293 u_int sg_prefetch_align
;
9295 u_int cacheline_mask
;
9296 uint8_t download_consts
[DOWNLOAD_CONST_COUNT
];
9299 printk("%s: Downloading Sequencer Program...",
9302 #if DOWNLOAD_CONST_COUNT != 8
9303 #error "Download Const Mismatch"
9306 * Start out with 0 critical sections
9307 * that apply to this firmware load.
9311 memset(begin_set
, 0, sizeof(begin_set
));
9312 memset(end_set
, 0, sizeof(end_set
));
9315 * Setup downloadable constant table.
9317 * The computation for the S/G prefetch variables is
9318 * a bit complicated. We would like to always fetch
9319 * in terms of cachelined sized increments. However,
9320 * if the cacheline is not an even multiple of the
9321 * SG element size or is larger than our SG RAM, using
9322 * just the cache size might leave us with only a portion
9323 * of an SG element at the tail of a prefetch. If the
9324 * cacheline is larger than our S/G prefetch buffer less
9325 * the size of an SG element, we may round down to a cacheline
9326 * that doesn't contain any or all of the S/G of interest
9327 * within the bounds of our S/G ram. Provide variables to
9328 * the sequencer that will allow it to handle these edge
9331 /* Start by aligning to the nearest cacheline. */
9332 sg_prefetch_align
= ahd
->pci_cachesize
;
9333 if (sg_prefetch_align
== 0)
9334 sg_prefetch_align
= 8;
9335 /* Round down to the nearest power of 2. */
9336 while (powerof2(sg_prefetch_align
) == 0)
9337 sg_prefetch_align
--;
9339 cacheline_mask
= sg_prefetch_align
- 1;
9342 * If the cacheline boundary is greater than half our prefetch RAM
9343 * we risk not being able to fetch even a single complete S/G
9344 * segment if we align to that boundary.
9346 if (sg_prefetch_align
> CCSGADDR_MAX
/2)
9347 sg_prefetch_align
= CCSGADDR_MAX
/2;
9348 /* Start by fetching a single cacheline. */
9349 sg_prefetch_cnt
= sg_prefetch_align
;
9351 * Increment the prefetch count by cachelines until
9352 * at least one S/G element will fit.
9354 sg_size
= sizeof(struct ahd_dma_seg
);
9355 if ((ahd
->flags
& AHD_64BIT_ADDRESSING
) != 0)
9356 sg_size
= sizeof(struct ahd_dma64_seg
);
9357 while (sg_prefetch_cnt
< sg_size
)
9358 sg_prefetch_cnt
+= sg_prefetch_align
;
9360 * If the cacheline is not an even multiple of
9361 * the S/G size, we may only get a partial S/G when
9362 * we align. Add a cacheline if this is the case.
9364 if ((sg_prefetch_align
% sg_size
) != 0
9365 && (sg_prefetch_cnt
< CCSGADDR_MAX
))
9366 sg_prefetch_cnt
+= sg_prefetch_align
;
9368 * Lastly, compute a value that the sequencer can use
9369 * to determine if the remainder of the CCSGRAM buffer
9370 * has a full S/G element in it.
9372 sg_prefetch_cnt_limit
= -(sg_prefetch_cnt
- sg_size
+ 1);
9373 download_consts
[SG_PREFETCH_CNT
] = sg_prefetch_cnt
;
9374 download_consts
[SG_PREFETCH_CNT_LIMIT
] = sg_prefetch_cnt_limit
;
9375 download_consts
[SG_PREFETCH_ALIGN_MASK
] = ~(sg_prefetch_align
- 1);
9376 download_consts
[SG_PREFETCH_ADDR_MASK
] = (sg_prefetch_align
- 1);
9377 download_consts
[SG_SIZEOF
] = sg_size
;
9378 download_consts
[PKT_OVERRUN_BUFOFFSET
] =
9379 (ahd
->overrun_buf
- (uint8_t *)ahd
->qoutfifo
) / 256;
9380 download_consts
[SCB_TRANSFER_SIZE
] = SCB_TRANSFER_SIZE_1BYTE_LUN
;
9381 download_consts
[CACHELINE_MASK
] = cacheline_mask
;
9382 cur_patch
= patches
;
9385 ahd_outb(ahd
, SEQCTL0
, PERRORDIS
|FAILDIS
|FASTMODE
|LOADRAM
);
9386 ahd_outw(ahd
, PRGMCNT
, 0);
9388 for (i
= 0; i
< sizeof(seqprog
)/4; i
++) {
9389 if (ahd_check_patch(ahd
, &cur_patch
, i
, &skip_addr
) == 0) {
9391 * Don't download this instruction as it
9392 * is in a patch that was removed.
9397 * Move through the CS table until we find a CS
9398 * that might apply to this instruction.
9400 for (; cur_cs
< NUM_CRITICAL_SECTIONS
; cur_cs
++) {
9401 if (critical_sections
[cur_cs
].end
<= i
) {
9402 if (begin_set
[cs_count
] == TRUE
9403 && end_set
[cs_count
] == FALSE
) {
9404 cs_table
[cs_count
].end
= downloaded
;
9405 end_set
[cs_count
] = TRUE
;
9410 if (critical_sections
[cur_cs
].begin
<= i
9411 && begin_set
[cs_count
] == FALSE
) {
9412 cs_table
[cs_count
].begin
= downloaded
;
9413 begin_set
[cs_count
] = TRUE
;
9417 ahd_download_instr(ahd
, i
, download_consts
);
9421 ahd
->num_critical_sections
= cs_count
;
9422 if (cs_count
!= 0) {
9424 cs_count
*= sizeof(struct cs
);
9425 ahd
->critical_sections
= kmalloc(cs_count
, GFP_ATOMIC
);
9426 if (ahd
->critical_sections
== NULL
)
9427 panic("ahd_loadseq: Could not malloc");
9428 memcpy(ahd
->critical_sections
, cs_table
, cs_count
);
9430 ahd_outb(ahd
, SEQCTL0
, PERRORDIS
|FAILDIS
|FASTMODE
);
9433 printk(" %d instructions downloaded\n", downloaded
);
9434 printk("%s: Features 0x%x, Bugs 0x%x, Flags 0x%x\n",
9435 ahd_name(ahd
), ahd
->features
, ahd
->bugs
, ahd
->flags
);
9440 ahd_check_patch(struct ahd_softc
*ahd
, const struct patch
**start_patch
,
9441 u_int start_instr
, u_int
*skip_addr
)
9443 const struct patch
*cur_patch
;
9444 const struct patch
*last_patch
;
9447 num_patches
= ARRAY_SIZE(patches
);
9448 last_patch
= &patches
[num_patches
];
9449 cur_patch
= *start_patch
;
9451 while (cur_patch
< last_patch
&& start_instr
== cur_patch
->begin
) {
9453 if (cur_patch
->patch_func(ahd
) == 0) {
9455 /* Start rejecting code */
9456 *skip_addr
= start_instr
+ cur_patch
->skip_instr
;
9457 cur_patch
+= cur_patch
->skip_patch
;
9459 /* Accepted this patch. Advance to the next
9460 * one and wait for our intruction pointer to
9467 *start_patch
= cur_patch
;
9468 if (start_instr
< *skip_addr
)
9469 /* Still skipping */
9476 ahd_resolve_seqaddr(struct ahd_softc
*ahd
, u_int address
)
9478 const struct patch
*cur_patch
;
9484 cur_patch
= patches
;
9487 for (i
= 0; i
< address
;) {
9489 ahd_check_patch(ahd
, &cur_patch
, i
, &skip_addr
);
9491 if (skip_addr
> i
) {
9494 end_addr
= min(address
, skip_addr
);
9495 address_offset
+= end_addr
- i
;
9501 return (address
- address_offset
);
9505 ahd_download_instr(struct ahd_softc
*ahd
, u_int instrptr
, uint8_t *dconsts
)
9507 union ins_formats instr
;
9508 struct ins_format1
*fmt1_ins
;
9509 struct ins_format3
*fmt3_ins
;
9513 * The firmware is always compiled into a little endian format.
9515 instr
.integer
= ahd_le32toh(*(uint32_t*)&seqprog
[instrptr
* 4]);
9517 fmt1_ins
= &instr
.format1
;
9520 /* Pull the opcode */
9521 opcode
= instr
.format1
.opcode
;
9532 fmt3_ins
= &instr
.format3
;
9533 fmt3_ins
->address
= ahd_resolve_seqaddr(ahd
, fmt3_ins
->address
);
9542 if (fmt1_ins
->parity
!= 0) {
9543 fmt1_ins
->immediate
= dconsts
[fmt1_ins
->immediate
];
9545 fmt1_ins
->parity
= 0;
9551 /* Calculate odd parity for the instruction */
9552 for (i
= 0, count
= 0; i
< 31; i
++) {
9556 if ((instr
.integer
& mask
) != 0)
9559 if ((count
& 0x01) == 0)
9560 instr
.format1
.parity
= 1;
9562 /* The sequencer is a little endian cpu */
9563 instr
.integer
= ahd_htole32(instr
.integer
);
9564 ahd_outsb(ahd
, SEQRAM
, instr
.bytes
, 4);
9568 panic("Unknown opcode encountered in seq program");
9574 ahd_probe_stack_size(struct ahd_softc
*ahd
)
9583 * We avoid using 0 as a pattern to avoid
9584 * confusion if the stack implementation
9585 * "back-fills" with zeros when "poping'
9588 for (i
= 1; i
<= last_probe
+1; i
++) {
9589 ahd_outb(ahd
, STACK
, i
& 0xFF);
9590 ahd_outb(ahd
, STACK
, (i
>> 8) & 0xFF);
9594 for (i
= last_probe
+1; i
> 0; i
--) {
9597 stack_entry
= ahd_inb(ahd
, STACK
)
9598 |(ahd_inb(ahd
, STACK
) << 8);
9599 if (stack_entry
!= i
)
9605 return (last_probe
);
9609 ahd_print_register(const ahd_reg_parse_entry_t
*table
, u_int num_entries
,
9610 const char *name
, u_int address
, u_int value
,
9611 u_int
*cur_column
, u_int wrap_point
)
9616 if (cur_column
!= NULL
&& *cur_column
>= wrap_point
) {
9620 printed
= printk("%s[0x%x]", name
, value
);
9621 if (table
== NULL
) {
9622 printed
+= printk(" ");
9623 *cur_column
+= printed
;
9627 while (printed_mask
!= 0xFF) {
9630 for (entry
= 0; entry
< num_entries
; entry
++) {
9631 if (((value
& table
[entry
].mask
)
9632 != table
[entry
].value
)
9633 || ((printed_mask
& table
[entry
].mask
)
9634 == table
[entry
].mask
))
9637 printed
+= printk("%s%s",
9638 printed_mask
== 0 ? ":(" : "|",
9640 printed_mask
|= table
[entry
].mask
;
9644 if (entry
>= num_entries
)
9647 if (printed_mask
!= 0)
9648 printed
+= printk(") ");
9650 printed
+= printk(" ");
9651 if (cur_column
!= NULL
)
9652 *cur_column
+= printed
;
9657 ahd_dump_card_state(struct ahd_softc
*ahd
)
9660 ahd_mode_state saved_modes
;
9664 u_int saved_scb_index
;
9668 if (ahd_is_paused(ahd
)) {
9674 saved_modes
= ahd_save_modes(ahd
);
9675 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
9676 printk(">>>>>>>>>>>>>>>>>> Dump Card State Begins <<<<<<<<<<<<<<<<<\n"
9677 "%s: Dumping Card State at program address 0x%x Mode 0x%x\n",
9679 ahd_inw(ahd
, CURADDR
),
9680 ahd_build_mode_state(ahd
, ahd
->saved_src_mode
,
9681 ahd
->saved_dst_mode
));
9683 printk("Card was paused\n");
9685 if (ahd_check_cmdcmpltqueues(ahd
))
9686 printk("Completions are pending\n");
9689 * Mode independent registers.
9692 ahd_intstat_print(ahd_inb(ahd
, INTSTAT
), &cur_col
, 50);
9693 ahd_seloid_print(ahd_inb(ahd
, SELOID
), &cur_col
, 50);
9694 ahd_selid_print(ahd_inb(ahd
, SELID
), &cur_col
, 50);
9695 ahd_hs_mailbox_print(ahd_inb(ahd
, LOCAL_HS_MAILBOX
), &cur_col
, 50);
9696 ahd_intctl_print(ahd_inb(ahd
, INTCTL
), &cur_col
, 50);
9697 ahd_seqintstat_print(ahd_inb(ahd
, SEQINTSTAT
), &cur_col
, 50);
9698 ahd_saved_mode_print(ahd_inb(ahd
, SAVED_MODE
), &cur_col
, 50);
9699 ahd_dffstat_print(ahd_inb(ahd
, DFFSTAT
), &cur_col
, 50);
9700 ahd_scsisigi_print(ahd_inb(ahd
, SCSISIGI
), &cur_col
, 50);
9701 ahd_scsiphase_print(ahd_inb(ahd
, SCSIPHASE
), &cur_col
, 50);
9702 ahd_scsibus_print(ahd_inb(ahd
, SCSIBUS
), &cur_col
, 50);
9703 ahd_lastphase_print(ahd_inb(ahd
, LASTPHASE
), &cur_col
, 50);
9704 ahd_scsiseq0_print(ahd_inb(ahd
, SCSISEQ0
), &cur_col
, 50);
9705 ahd_scsiseq1_print(ahd_inb(ahd
, SCSISEQ1
), &cur_col
, 50);
9706 ahd_seqctl0_print(ahd_inb(ahd
, SEQCTL0
), &cur_col
, 50);
9707 ahd_seqintctl_print(ahd_inb(ahd
, SEQINTCTL
), &cur_col
, 50);
9708 ahd_seq_flags_print(ahd_inb(ahd
, SEQ_FLAGS
), &cur_col
, 50);
9709 ahd_seq_flags2_print(ahd_inb(ahd
, SEQ_FLAGS2
), &cur_col
, 50);
9710 ahd_qfreeze_count_print(ahd_inw(ahd
, QFREEZE_COUNT
), &cur_col
, 50);
9711 ahd_kernel_qfreeze_count_print(ahd_inw(ahd
, KERNEL_QFREEZE_COUNT
),
9713 ahd_mk_message_scb_print(ahd_inw(ahd
, MK_MESSAGE_SCB
), &cur_col
, 50);
9714 ahd_mk_message_scsiid_print(ahd_inb(ahd
, MK_MESSAGE_SCSIID
),
9716 ahd_sstat0_print(ahd_inb(ahd
, SSTAT0
), &cur_col
, 50);
9717 ahd_sstat1_print(ahd_inb(ahd
, SSTAT1
), &cur_col
, 50);
9718 ahd_sstat2_print(ahd_inb(ahd
, SSTAT2
), &cur_col
, 50);
9719 ahd_sstat3_print(ahd_inb(ahd
, SSTAT3
), &cur_col
, 50);
9720 ahd_perrdiag_print(ahd_inb(ahd
, PERRDIAG
), &cur_col
, 50);
9721 ahd_simode1_print(ahd_inb(ahd
, SIMODE1
), &cur_col
, 50);
9722 ahd_lqistat0_print(ahd_inb(ahd
, LQISTAT0
), &cur_col
, 50);
9723 ahd_lqistat1_print(ahd_inb(ahd
, LQISTAT1
), &cur_col
, 50);
9724 ahd_lqistat2_print(ahd_inb(ahd
, LQISTAT2
), &cur_col
, 50);
9725 ahd_lqostat0_print(ahd_inb(ahd
, LQOSTAT0
), &cur_col
, 50);
9726 ahd_lqostat1_print(ahd_inb(ahd
, LQOSTAT1
), &cur_col
, 50);
9727 ahd_lqostat2_print(ahd_inb(ahd
, LQOSTAT2
), &cur_col
, 50);
9729 printk("\nSCB Count = %d CMDS_PENDING = %d LASTSCB 0x%x "
9730 "CURRSCB 0x%x NEXTSCB 0x%x\n",
9731 ahd
->scb_data
.numscbs
, ahd_inw(ahd
, CMDS_PENDING
),
9732 ahd_inw(ahd
, LASTSCB
), ahd_inw(ahd
, CURRSCB
),
9733 ahd_inw(ahd
, NEXTSCB
));
9736 ahd_search_qinfifo(ahd
, CAM_TARGET_WILDCARD
, ALL_CHANNELS
,
9737 CAM_LUN_WILDCARD
, SCB_LIST_NULL
,
9738 ROLE_UNKNOWN
, /*status*/0, SEARCH_PRINT
);
9739 saved_scb_index
= ahd_get_scbptr(ahd
);
9740 printk("Pending list:");
9742 LIST_FOREACH(scb
, &ahd
->pending_scbs
, pending_links
) {
9743 if (i
++ > AHD_SCB_MAX
)
9745 cur_col
= printk("\n%3d FIFO_USE[0x%x] ", SCB_GET_TAG(scb
),
9746 ahd_inb_scbram(ahd
, SCB_FIFO_USE_COUNT
));
9747 ahd_set_scbptr(ahd
, SCB_GET_TAG(scb
));
9748 ahd_scb_control_print(ahd_inb_scbram(ahd
, SCB_CONTROL
),
9750 ahd_scb_scsiid_print(ahd_inb_scbram(ahd
, SCB_SCSIID
),
9753 printk("\nTotal %d\n", i
);
9755 printk("Kernel Free SCB list: ");
9757 TAILQ_FOREACH(scb
, &ahd
->scb_data
.free_scbs
, links
.tqe
) {
9758 struct scb
*list_scb
;
9762 printk("%d ", SCB_GET_TAG(list_scb
));
9763 list_scb
= LIST_NEXT(list_scb
, collision_links
);
9764 } while (list_scb
&& i
++ < AHD_SCB_MAX
);
9767 LIST_FOREACH(scb
, &ahd
->scb_data
.any_dev_free_scb_list
, links
.le
) {
9768 if (i
++ > AHD_SCB_MAX
)
9770 printk("%d ", SCB_GET_TAG(scb
));
9774 printk("Sequencer Complete DMA-inprog list: ");
9775 scb_index
= ahd_inw(ahd
, COMPLETE_SCB_DMAINPROG_HEAD
);
9777 while (!SCBID_IS_NULL(scb_index
) && i
++ < AHD_SCB_MAX
) {
9778 ahd_set_scbptr(ahd
, scb_index
);
9779 printk("%d ", scb_index
);
9780 scb_index
= ahd_inw_scbram(ahd
, SCB_NEXT_COMPLETE
);
9784 printk("Sequencer Complete list: ");
9785 scb_index
= ahd_inw(ahd
, COMPLETE_SCB_HEAD
);
9787 while (!SCBID_IS_NULL(scb_index
) && i
++ < AHD_SCB_MAX
) {
9788 ahd_set_scbptr(ahd
, scb_index
);
9789 printk("%d ", scb_index
);
9790 scb_index
= ahd_inw_scbram(ahd
, SCB_NEXT_COMPLETE
);
9795 printk("Sequencer DMA-Up and Complete list: ");
9796 scb_index
= ahd_inw(ahd
, COMPLETE_DMA_SCB_HEAD
);
9798 while (!SCBID_IS_NULL(scb_index
) && i
++ < AHD_SCB_MAX
) {
9799 ahd_set_scbptr(ahd
, scb_index
);
9800 printk("%d ", scb_index
);
9801 scb_index
= ahd_inw_scbram(ahd
, SCB_NEXT_COMPLETE
);
9804 printk("Sequencer On QFreeze and Complete list: ");
9805 scb_index
= ahd_inw(ahd
, COMPLETE_ON_QFREEZE_HEAD
);
9807 while (!SCBID_IS_NULL(scb_index
) && i
++ < AHD_SCB_MAX
) {
9808 ahd_set_scbptr(ahd
, scb_index
);
9809 printk("%d ", scb_index
);
9810 scb_index
= ahd_inw_scbram(ahd
, SCB_NEXT_COMPLETE
);
9813 ahd_set_scbptr(ahd
, saved_scb_index
);
9814 dffstat
= ahd_inb(ahd
, DFFSTAT
);
9815 for (i
= 0; i
< 2; i
++) {
9817 struct scb
*fifo_scb
;
9821 ahd_set_modes(ahd
, AHD_MODE_DFF0
+ i
, AHD_MODE_DFF0
+ i
);
9822 fifo_scbptr
= ahd_get_scbptr(ahd
);
9823 printk("\n\n%s: FIFO%d %s, LONGJMP == 0x%x, SCB 0x%x\n",
9825 (dffstat
& (FIFO0FREE
<< i
)) ? "Free" : "Active",
9826 ahd_inw(ahd
, LONGJMP_ADDR
), fifo_scbptr
);
9828 ahd_seqimode_print(ahd_inb(ahd
, SEQIMODE
), &cur_col
, 50);
9829 ahd_seqintsrc_print(ahd_inb(ahd
, SEQINTSRC
), &cur_col
, 50);
9830 ahd_dfcntrl_print(ahd_inb(ahd
, DFCNTRL
), &cur_col
, 50);
9831 ahd_dfstatus_print(ahd_inb(ahd
, DFSTATUS
), &cur_col
, 50);
9832 ahd_sg_cache_shadow_print(ahd_inb(ahd
, SG_CACHE_SHADOW
),
9834 ahd_sg_state_print(ahd_inb(ahd
, SG_STATE
), &cur_col
, 50);
9835 ahd_dffsxfrctl_print(ahd_inb(ahd
, DFFSXFRCTL
), &cur_col
, 50);
9836 ahd_soffcnt_print(ahd_inb(ahd
, SOFFCNT
), &cur_col
, 50);
9837 ahd_mdffstat_print(ahd_inb(ahd
, MDFFSTAT
), &cur_col
, 50);
9842 cur_col
+= printk("SHADDR = 0x%x%x, SHCNT = 0x%x ",
9843 ahd_inl(ahd
, SHADDR
+4),
9844 ahd_inl(ahd
, SHADDR
),
9845 (ahd_inb(ahd
, SHCNT
)
9846 | (ahd_inb(ahd
, SHCNT
+ 1) << 8)
9847 | (ahd_inb(ahd
, SHCNT
+ 2) << 16)));
9852 cur_col
+= printk("HADDR = 0x%x%x, HCNT = 0x%x ",
9853 ahd_inl(ahd
, HADDR
+4),
9854 ahd_inl(ahd
, HADDR
),
9856 | (ahd_inb(ahd
, HCNT
+ 1) << 8)
9857 | (ahd_inb(ahd
, HCNT
+ 2) << 16)));
9858 ahd_ccsgctl_print(ahd_inb(ahd
, CCSGCTL
), &cur_col
, 50);
9860 if ((ahd_debug
& AHD_SHOW_SG
) != 0) {
9861 fifo_scb
= ahd_lookup_scb(ahd
, fifo_scbptr
);
9862 if (fifo_scb
!= NULL
)
9863 ahd_dump_sglist(fifo_scb
);
9868 for (i
= 0; i
< 20; i
++)
9869 printk("0x%x ", ahd_inb(ahd
, LQIN
+ i
));
9871 ahd_set_modes(ahd
, AHD_MODE_CFG
, AHD_MODE_CFG
);
9872 printk("%s: LQISTATE = 0x%x, LQOSTATE = 0x%x, OPTIONMODE = 0x%x\n",
9873 ahd_name(ahd
), ahd_inb(ahd
, LQISTATE
), ahd_inb(ahd
, LQOSTATE
),
9874 ahd_inb(ahd
, OPTIONMODE
));
9875 printk("%s: OS_SPACE_CNT = 0x%x MAXCMDCNT = 0x%x\n",
9876 ahd_name(ahd
), ahd_inb(ahd
, OS_SPACE_CNT
),
9877 ahd_inb(ahd
, MAXCMDCNT
));
9878 printk("%s: SAVED_SCSIID = 0x%x SAVED_LUN = 0x%x\n",
9879 ahd_name(ahd
), ahd_inb(ahd
, SAVED_SCSIID
),
9880 ahd_inb(ahd
, SAVED_LUN
));
9881 ahd_simode0_print(ahd_inb(ahd
, SIMODE0
), &cur_col
, 50);
9883 ahd_set_modes(ahd
, AHD_MODE_CCHAN
, AHD_MODE_CCHAN
);
9885 ahd_ccscbctl_print(ahd_inb(ahd
, CCSCBCTL
), &cur_col
, 50);
9887 ahd_set_modes(ahd
, ahd
->saved_src_mode
, ahd
->saved_dst_mode
);
9888 printk("%s: REG0 == 0x%x, SINDEX = 0x%x, DINDEX = 0x%x\n",
9889 ahd_name(ahd
), ahd_inw(ahd
, REG0
), ahd_inw(ahd
, SINDEX
),
9890 ahd_inw(ahd
, DINDEX
));
9891 printk("%s: SCBPTR == 0x%x, SCB_NEXT == 0x%x, SCB_NEXT2 == 0x%x\n",
9892 ahd_name(ahd
), ahd_get_scbptr(ahd
),
9893 ahd_inw_scbram(ahd
, SCB_NEXT
),
9894 ahd_inw_scbram(ahd
, SCB_NEXT2
));
9895 printk("CDB %x %x %x %x %x %x\n",
9896 ahd_inb_scbram(ahd
, SCB_CDB_STORE
),
9897 ahd_inb_scbram(ahd
, SCB_CDB_STORE
+1),
9898 ahd_inb_scbram(ahd
, SCB_CDB_STORE
+2),
9899 ahd_inb_scbram(ahd
, SCB_CDB_STORE
+3),
9900 ahd_inb_scbram(ahd
, SCB_CDB_STORE
+4),
9901 ahd_inb_scbram(ahd
, SCB_CDB_STORE
+5));
9903 for (i
= 0; i
< ahd
->stack_size
; i
++) {
9904 ahd
->saved_stack
[i
] =
9905 ahd_inb(ahd
, STACK
)|(ahd_inb(ahd
, STACK
) << 8);
9906 printk(" 0x%x", ahd
->saved_stack
[i
]);
9908 for (i
= ahd
->stack_size
-1; i
>= 0; i
--) {
9909 ahd_outb(ahd
, STACK
, ahd
->saved_stack
[i
] & 0xFF);
9910 ahd_outb(ahd
, STACK
, (ahd
->saved_stack
[i
] >> 8) & 0xFF);
9912 printk("\n<<<<<<<<<<<<<<<<< Dump Card State Ends >>>>>>>>>>>>>>>>>>\n");
9913 ahd_restore_modes(ahd
, saved_modes
);
9920 ahd_dump_scbs(struct ahd_softc
*ahd
)
9922 ahd_mode_state saved_modes
;
9923 u_int saved_scb_index
;
9926 saved_modes
= ahd_save_modes(ahd
);
9927 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
9928 saved_scb_index
= ahd_get_scbptr(ahd
);
9929 for (i
= 0; i
< AHD_SCB_MAX
; i
++) {
9930 ahd_set_scbptr(ahd
, i
);
9932 printk("(CTRL 0x%x ID 0x%x N 0x%x N2 0x%x SG 0x%x, RSG 0x%x)\n",
9933 ahd_inb_scbram(ahd
, SCB_CONTROL
),
9934 ahd_inb_scbram(ahd
, SCB_SCSIID
),
9935 ahd_inw_scbram(ahd
, SCB_NEXT
),
9936 ahd_inw_scbram(ahd
, SCB_NEXT2
),
9937 ahd_inl_scbram(ahd
, SCB_SGPTR
),
9938 ahd_inl_scbram(ahd
, SCB_RESIDUAL_SGPTR
));
9941 ahd_set_scbptr(ahd
, saved_scb_index
);
9942 ahd_restore_modes(ahd
, saved_modes
);
9946 /**************************** Flexport Logic **********************************/
9948 * Read count 16bit words from 16bit word address start_addr from the
9949 * SEEPROM attached to the controller, into buf, using the controller's
9950 * SEEPROM reading state machine. Optionally treat the data as a byte
9951 * stream in terms of byte order.
9954 ahd_read_seeprom(struct ahd_softc
*ahd
, uint16_t *buf
,
9955 u_int start_addr
, u_int count
, int bytestream
)
9962 * If we never make it through the loop even once,
9963 * we were passed invalid arguments.
9966 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
9967 end_addr
= start_addr
+ count
;
9968 for (cur_addr
= start_addr
; cur_addr
< end_addr
; cur_addr
++) {
9970 ahd_outb(ahd
, SEEADR
, cur_addr
);
9971 ahd_outb(ahd
, SEECTL
, SEEOP_READ
| SEESTART
);
9973 error
= ahd_wait_seeprom(ahd
);
9976 if (bytestream
!= 0) {
9977 uint8_t *bytestream_ptr
;
9979 bytestream_ptr
= (uint8_t *)buf
;
9980 *bytestream_ptr
++ = ahd_inb(ahd
, SEEDAT
);
9981 *bytestream_ptr
= ahd_inb(ahd
, SEEDAT
+1);
9984 * ahd_inw() already handles machine byte order.
9986 *buf
= ahd_inw(ahd
, SEEDAT
);
9994 * Write count 16bit words from buf, into SEEPROM attache to the
9995 * controller starting at 16bit word address start_addr, using the
9996 * controller's SEEPROM writing state machine.
9999 ahd_write_seeprom(struct ahd_softc
*ahd
, uint16_t *buf
,
10000 u_int start_addr
, u_int count
)
10007 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
10010 /* Place the chip into write-enable mode */
10011 ahd_outb(ahd
, SEEADR
, SEEOP_EWEN_ADDR
);
10012 ahd_outb(ahd
, SEECTL
, SEEOP_EWEN
| SEESTART
);
10013 error
= ahd_wait_seeprom(ahd
);
10018 * Write the data. If we don't get through the loop at
10019 * least once, the arguments were invalid.
10022 end_addr
= start_addr
+ count
;
10023 for (cur_addr
= start_addr
; cur_addr
< end_addr
; cur_addr
++) {
10024 ahd_outw(ahd
, SEEDAT
, *buf
++);
10025 ahd_outb(ahd
, SEEADR
, cur_addr
);
10026 ahd_outb(ahd
, SEECTL
, SEEOP_WRITE
| SEESTART
);
10028 retval
= ahd_wait_seeprom(ahd
);
10036 ahd_outb(ahd
, SEEADR
, SEEOP_EWDS_ADDR
);
10037 ahd_outb(ahd
, SEECTL
, SEEOP_EWDS
| SEESTART
);
10038 error
= ahd_wait_seeprom(ahd
);
10045 * Wait ~100us for the serial eeprom to satisfy our request.
10048 ahd_wait_seeprom(struct ahd_softc
*ahd
)
10053 while ((ahd_inb(ahd
, SEESTAT
) & (SEEARBACK
|SEEBUSY
)) != 0 && --cnt
)
10057 return (ETIMEDOUT
);
10062 * Validate the two checksums in the per_channel
10063 * vital product data struct.
10066 ahd_verify_vpd_cksum(struct vpd_config
*vpd
)
10073 vpdarray
= (uint8_t *)vpd
;
10074 maxaddr
= offsetof(struct vpd_config
, vpd_checksum
);
10076 for (i
= offsetof(struct vpd_config
, resource_type
); i
< maxaddr
; i
++)
10077 checksum
= checksum
+ vpdarray
[i
];
10079 || (-checksum
& 0xFF) != vpd
->vpd_checksum
)
10083 maxaddr
= offsetof(struct vpd_config
, checksum
);
10084 for (i
= offsetof(struct vpd_config
, default_target_flags
);
10086 checksum
= checksum
+ vpdarray
[i
];
10088 || (-checksum
& 0xFF) != vpd
->checksum
)
10094 ahd_verify_cksum(struct seeprom_config
*sc
)
10101 maxaddr
= (sizeof(*sc
)/2) - 1;
10103 scarray
= (uint16_t *)sc
;
10105 for (i
= 0; i
< maxaddr
; i
++)
10106 checksum
= checksum
+ scarray
[i
];
10108 || (checksum
& 0xFFFF) != sc
->checksum
) {
10116 ahd_acquire_seeprom(struct ahd_softc
*ahd
)
10119 * We should be able to determine the SEEPROM type
10120 * from the flexport logic, but unfortunately not
10121 * all implementations have this logic and there is
10122 * no programatic method for determining if the logic
10130 error
= ahd_read_flexport(ahd
, FLXADDR_ROMSTAT_CURSENSECTL
, &seetype
);
10132 || ((seetype
& FLX_ROMSTAT_SEECFG
) == FLX_ROMSTAT_SEE_NONE
))
10139 ahd_release_seeprom(struct ahd_softc
*ahd
)
10141 /* Currently a no-op */
10145 * Wait at most 2 seconds for flexport arbitration to succeed.
10148 ahd_wait_flexport(struct ahd_softc
*ahd
)
10152 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
10153 cnt
= 1000000 * 2 / 5;
10154 while ((ahd_inb(ahd
, BRDCTL
) & FLXARBACK
) == 0 && --cnt
)
10158 return (ETIMEDOUT
);
10163 ahd_write_flexport(struct ahd_softc
*ahd
, u_int addr
, u_int value
)
10167 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
10169 panic("ahd_write_flexport: address out of range");
10170 ahd_outb(ahd
, BRDCTL
, BRDEN
|(addr
<< 3));
10171 error
= ahd_wait_flexport(ahd
);
10174 ahd_outb(ahd
, BRDDAT
, value
);
10175 ahd_flush_device_writes(ahd
);
10176 ahd_outb(ahd
, BRDCTL
, BRDSTB
|BRDEN
|(addr
<< 3));
10177 ahd_flush_device_writes(ahd
);
10178 ahd_outb(ahd
, BRDCTL
, BRDEN
|(addr
<< 3));
10179 ahd_flush_device_writes(ahd
);
10180 ahd_outb(ahd
, BRDCTL
, 0);
10181 ahd_flush_device_writes(ahd
);
10186 ahd_read_flexport(struct ahd_softc
*ahd
, u_int addr
, uint8_t *value
)
10190 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
10192 panic("ahd_read_flexport: address out of range");
10193 ahd_outb(ahd
, BRDCTL
, BRDRW
|BRDEN
|(addr
<< 3));
10194 error
= ahd_wait_flexport(ahd
);
10197 *value
= ahd_inb(ahd
, BRDDAT
);
10198 ahd_outb(ahd
, BRDCTL
, 0);
10199 ahd_flush_device_writes(ahd
);
10203 /************************* Target Mode ****************************************/
10204 #ifdef AHD_TARGET_MODE
10206 ahd_find_tmode_devs(struct ahd_softc
*ahd
, struct cam_sim
*sim
, union ccb
*ccb
,
10207 struct ahd_tmode_tstate
**tstate
,
10208 struct ahd_tmode_lstate
**lstate
,
10209 int notfound_failure
)
10212 if ((ahd
->features
& AHD_TARGETMODE
) == 0)
10213 return (CAM_REQ_INVALID
);
10216 * Handle the 'black hole' device that sucks up
10217 * requests to unattached luns on enabled targets.
10219 if (ccb
->ccb_h
.target_id
== CAM_TARGET_WILDCARD
10220 && ccb
->ccb_h
.target_lun
== CAM_LUN_WILDCARD
) {
10222 *lstate
= ahd
->black_hole
;
10226 max_id
= (ahd
->features
& AHD_WIDE
) ? 16 : 8;
10227 if (ccb
->ccb_h
.target_id
>= max_id
)
10228 return (CAM_TID_INVALID
);
10230 if (ccb
->ccb_h
.target_lun
>= AHD_NUM_LUNS
)
10231 return (CAM_LUN_INVALID
);
10233 *tstate
= ahd
->enabled_targets
[ccb
->ccb_h
.target_id
];
10235 if (*tstate
!= NULL
)
10237 (*tstate
)->enabled_luns
[ccb
->ccb_h
.target_lun
];
10240 if (notfound_failure
!= 0 && *lstate
== NULL
)
10241 return (CAM_PATH_INVALID
);
10243 return (CAM_REQ_CMP
);
10247 ahd_handle_en_lun(struct ahd_softc
*ahd
, struct cam_sim
*sim
, union ccb
*ccb
)
10250 struct ahd_tmode_tstate
*tstate
;
10251 struct ahd_tmode_lstate
*lstate
;
10252 struct ccb_en_lun
*cel
;
10260 status
= ahd_find_tmode_devs(ahd
, sim
, ccb
, &tstate
, &lstate
,
10261 /*notfound_failure*/FALSE
);
10263 if (status
!= CAM_REQ_CMP
) {
10264 ccb
->ccb_h
.status
= status
;
10268 if ((ahd
->features
& AHD_MULTIROLE
) != 0) {
10271 our_id
= ahd
->our_id
;
10272 if (ccb
->ccb_h
.target_id
!= our_id
) {
10273 if ((ahd
->features
& AHD_MULTI_TID
) != 0
10274 && (ahd
->flags
& AHD_INITIATORROLE
) != 0) {
10276 * Only allow additional targets if
10277 * the initiator role is disabled.
10278 * The hardware cannot handle a re-select-in
10279 * on the initiator id during a re-select-out
10280 * on a different target id.
10282 status
= CAM_TID_INVALID
;
10283 } else if ((ahd
->flags
& AHD_INITIATORROLE
) != 0
10284 || ahd
->enabled_luns
> 0) {
10286 * Only allow our target id to change
10287 * if the initiator role is not configured
10288 * and there are no enabled luns which
10289 * are attached to the currently registered
10292 status
= CAM_TID_INVALID
;
10297 if (status
!= CAM_REQ_CMP
) {
10298 ccb
->ccb_h
.status
= status
;
10303 * We now have an id that is valid.
10304 * If we aren't in target mode, switch modes.
10306 if ((ahd
->flags
& AHD_TARGETROLE
) == 0
10307 && ccb
->ccb_h
.target_id
!= CAM_TARGET_WILDCARD
) {
10310 printk("Configuring Target Mode\n");
10312 if (LIST_FIRST(&ahd
->pending_scbs
) != NULL
) {
10313 ccb
->ccb_h
.status
= CAM_BUSY
;
10314 ahd_unlock(ahd
, &s
);
10317 ahd
->flags
|= AHD_TARGETROLE
;
10318 if ((ahd
->features
& AHD_MULTIROLE
) == 0)
10319 ahd
->flags
&= ~AHD_INITIATORROLE
;
10323 ahd_unlock(ahd
, &s
);
10326 target
= ccb
->ccb_h
.target_id
;
10327 lun
= ccb
->ccb_h
.target_lun
;
10328 channel
= SIM_CHANNEL(ahd
, sim
);
10329 target_mask
= 0x01 << target
;
10330 if (channel
== 'B')
10333 if (cel
->enable
!= 0) {
10336 /* Are we already enabled?? */
10337 if (lstate
!= NULL
) {
10338 xpt_print_path(ccb
->ccb_h
.path
);
10339 printk("Lun already enabled\n");
10340 ccb
->ccb_h
.status
= CAM_LUN_ALRDY_ENA
;
10344 if (cel
->grp6_len
!= 0
10345 || cel
->grp7_len
!= 0) {
10347 * Don't (yet?) support vendor
10348 * specific commands.
10350 ccb
->ccb_h
.status
= CAM_REQ_INVALID
;
10351 printk("Non-zero Group Codes\n");
10356 * Seems to be okay.
10357 * Setup our data structures.
10359 if (target
!= CAM_TARGET_WILDCARD
&& tstate
== NULL
) {
10360 tstate
= ahd_alloc_tstate(ahd
, target
, channel
);
10361 if (tstate
== NULL
) {
10362 xpt_print_path(ccb
->ccb_h
.path
);
10363 printk("Couldn't allocate tstate\n");
10364 ccb
->ccb_h
.status
= CAM_RESRC_UNAVAIL
;
10368 lstate
= kzalloc(sizeof(*lstate
), GFP_ATOMIC
);
10369 if (lstate
== NULL
) {
10370 xpt_print_path(ccb
->ccb_h
.path
);
10371 printk("Couldn't allocate lstate\n");
10372 ccb
->ccb_h
.status
= CAM_RESRC_UNAVAIL
;
10375 status
= xpt_create_path(&lstate
->path
, /*periph*/NULL
,
10376 xpt_path_path_id(ccb
->ccb_h
.path
),
10377 xpt_path_target_id(ccb
->ccb_h
.path
),
10378 xpt_path_lun_id(ccb
->ccb_h
.path
));
10379 if (status
!= CAM_REQ_CMP
) {
10381 xpt_print_path(ccb
->ccb_h
.path
);
10382 printk("Couldn't allocate path\n");
10383 ccb
->ccb_h
.status
= CAM_RESRC_UNAVAIL
;
10386 SLIST_INIT(&lstate
->accept_tios
);
10387 SLIST_INIT(&lstate
->immed_notifies
);
10390 if (target
!= CAM_TARGET_WILDCARD
) {
10391 tstate
->enabled_luns
[lun
] = lstate
;
10392 ahd
->enabled_luns
++;
10394 if ((ahd
->features
& AHD_MULTI_TID
) != 0) {
10397 targid_mask
= ahd_inw(ahd
, TARGID
);
10398 targid_mask
|= target_mask
;
10399 ahd_outw(ahd
, TARGID
, targid_mask
);
10400 ahd_update_scsiid(ahd
, targid_mask
);
10405 channel
= SIM_CHANNEL(ahd
, sim
);
10406 our_id
= SIM_SCSI_ID(ahd
, sim
);
10409 * This can only happen if selections
10412 if (target
!= our_id
) {
10417 sblkctl
= ahd_inb(ahd
, SBLKCTL
);
10418 cur_channel
= (sblkctl
& SELBUSB
)
10420 if ((ahd
->features
& AHD_TWIN
) == 0)
10422 swap
= cur_channel
!= channel
;
10423 ahd
->our_id
= target
;
10426 ahd_outb(ahd
, SBLKCTL
,
10427 sblkctl
^ SELBUSB
);
10429 ahd_outb(ahd
, SCSIID
, target
);
10432 ahd_outb(ahd
, SBLKCTL
, sblkctl
);
10436 ahd
->black_hole
= lstate
;
10437 /* Allow select-in operations */
10438 if (ahd
->black_hole
!= NULL
&& ahd
->enabled_luns
> 0) {
10439 scsiseq1
= ahd_inb(ahd
, SCSISEQ_TEMPLATE
);
10440 scsiseq1
|= ENSELI
;
10441 ahd_outb(ahd
, SCSISEQ_TEMPLATE
, scsiseq1
);
10442 scsiseq1
= ahd_inb(ahd
, SCSISEQ1
);
10443 scsiseq1
|= ENSELI
;
10444 ahd_outb(ahd
, SCSISEQ1
, scsiseq1
);
10447 ahd_unlock(ahd
, &s
);
10448 ccb
->ccb_h
.status
= CAM_REQ_CMP
;
10449 xpt_print_path(ccb
->ccb_h
.path
);
10450 printk("Lun now enabled for target mode\n");
10455 if (lstate
== NULL
) {
10456 ccb
->ccb_h
.status
= CAM_LUN_INVALID
;
10462 ccb
->ccb_h
.status
= CAM_REQ_CMP
;
10463 LIST_FOREACH(scb
, &ahd
->pending_scbs
, pending_links
) {
10464 struct ccb_hdr
*ccbh
;
10466 ccbh
= &scb
->io_ctx
->ccb_h
;
10467 if (ccbh
->func_code
== XPT_CONT_TARGET_IO
10468 && !xpt_path_comp(ccbh
->path
, ccb
->ccb_h
.path
)){
10469 printk("CTIO pending\n");
10470 ccb
->ccb_h
.status
= CAM_REQ_INVALID
;
10471 ahd_unlock(ahd
, &s
);
10476 if (SLIST_FIRST(&lstate
->accept_tios
) != NULL
) {
10477 printk("ATIOs pending\n");
10478 ccb
->ccb_h
.status
= CAM_REQ_INVALID
;
10481 if (SLIST_FIRST(&lstate
->immed_notifies
) != NULL
) {
10482 printk("INOTs pending\n");
10483 ccb
->ccb_h
.status
= CAM_REQ_INVALID
;
10486 if (ccb
->ccb_h
.status
!= CAM_REQ_CMP
) {
10487 ahd_unlock(ahd
, &s
);
10491 xpt_print_path(ccb
->ccb_h
.path
);
10492 printk("Target mode disabled\n");
10493 xpt_free_path(lstate
->path
);
10497 /* Can we clean up the target too? */
10498 if (target
!= CAM_TARGET_WILDCARD
) {
10499 tstate
->enabled_luns
[lun
] = NULL
;
10500 ahd
->enabled_luns
--;
10501 for (empty
= 1, i
= 0; i
< 8; i
++)
10502 if (tstate
->enabled_luns
[i
] != NULL
) {
10508 ahd_free_tstate(ahd
, target
, channel
,
10510 if (ahd
->features
& AHD_MULTI_TID
) {
10513 targid_mask
= ahd_inw(ahd
, TARGID
);
10514 targid_mask
&= ~target_mask
;
10515 ahd_outw(ahd
, TARGID
, targid_mask
);
10516 ahd_update_scsiid(ahd
, targid_mask
);
10521 ahd
->black_hole
= NULL
;
10524 * We can't allow selections without
10525 * our black hole device.
10529 if (ahd
->enabled_luns
== 0) {
10530 /* Disallow select-in */
10533 scsiseq1
= ahd_inb(ahd
, SCSISEQ_TEMPLATE
);
10534 scsiseq1
&= ~ENSELI
;
10535 ahd_outb(ahd
, SCSISEQ_TEMPLATE
, scsiseq1
);
10536 scsiseq1
= ahd_inb(ahd
, SCSISEQ1
);
10537 scsiseq1
&= ~ENSELI
;
10538 ahd_outb(ahd
, SCSISEQ1
, scsiseq1
);
10540 if ((ahd
->features
& AHD_MULTIROLE
) == 0) {
10541 printk("Configuring Initiator Mode\n");
10542 ahd
->flags
&= ~AHD_TARGETROLE
;
10543 ahd
->flags
|= AHD_INITIATORROLE
;
10548 * Unpaused. The extra unpause
10549 * that follows is harmless.
10554 ahd_unlock(ahd
, &s
);
10560 ahd_update_scsiid(struct ahd_softc
*ahd
, u_int targid_mask
)
10566 if ((ahd
->features
& AHD_MULTI_TID
) == 0)
10567 panic("ahd_update_scsiid called on non-multitid unit\n");
10570 * Since we will rely on the TARGID mask
10571 * for selection enables, ensure that OID
10572 * in SCSIID is not set to some other ID
10573 * that we don't want to allow selections on.
10575 if ((ahd
->features
& AHD_ULTRA2
) != 0)
10576 scsiid
= ahd_inb(ahd
, SCSIID_ULTRA2
);
10578 scsiid
= ahd_inb(ahd
, SCSIID
);
10579 scsiid_mask
= 0x1 << (scsiid
& OID
);
10580 if ((targid_mask
& scsiid_mask
) == 0) {
10583 /* ffs counts from 1 */
10584 our_id
= ffs(targid_mask
);
10586 our_id
= ahd
->our_id
;
10592 if ((ahd
->features
& AHD_ULTRA2
) != 0)
10593 ahd_outb(ahd
, SCSIID_ULTRA2
, scsiid
);
10595 ahd_outb(ahd
, SCSIID
, scsiid
);
10600 ahd_run_tqinfifo(struct ahd_softc
*ahd
, int paused
)
10602 struct target_cmd
*cmd
;
10604 ahd_sync_tqinfifo(ahd
, BUS_DMASYNC_POSTREAD
);
10605 while ((cmd
= &ahd
->targetcmds
[ahd
->tqinfifonext
])->cmd_valid
!= 0) {
10608 * Only advance through the queue if we
10609 * have the resources to process the command.
10611 if (ahd_handle_target_cmd(ahd
, cmd
) != 0)
10614 cmd
->cmd_valid
= 0;
10615 ahd_dmamap_sync(ahd
, ahd
->shared_data_dmat
,
10616 ahd
->shared_data_map
.dmamap
,
10617 ahd_targetcmd_offset(ahd
, ahd
->tqinfifonext
),
10618 sizeof(struct target_cmd
),
10619 BUS_DMASYNC_PREREAD
);
10620 ahd
->tqinfifonext
++;
10623 * Lazily update our position in the target mode incoming
10624 * command queue as seen by the sequencer.
10626 if ((ahd
->tqinfifonext
& (HOST_TQINPOS
- 1)) == 1) {
10629 hs_mailbox
= ahd_inb(ahd
, HS_MAILBOX
);
10630 hs_mailbox
&= ~HOST_TQINPOS
;
10631 hs_mailbox
|= ahd
->tqinfifonext
& HOST_TQINPOS
;
10632 ahd_outb(ahd
, HS_MAILBOX
, hs_mailbox
);
10638 ahd_handle_target_cmd(struct ahd_softc
*ahd
, struct target_cmd
*cmd
)
10640 struct ahd_tmode_tstate
*tstate
;
10641 struct ahd_tmode_lstate
*lstate
;
10642 struct ccb_accept_tio
*atio
;
10648 initiator
= SCSIID_TARGET(ahd
, cmd
->scsiid
);
10649 target
= SCSIID_OUR_ID(cmd
->scsiid
);
10650 lun
= (cmd
->identify
& MSG_IDENTIFY_LUNMASK
);
10653 tstate
= ahd
->enabled_targets
[target
];
10655 if (tstate
!= NULL
)
10656 lstate
= tstate
->enabled_luns
[lun
];
10659 * Commands for disabled luns go to the black hole driver.
10661 if (lstate
== NULL
)
10662 lstate
= ahd
->black_hole
;
10664 atio
= (struct ccb_accept_tio
*)SLIST_FIRST(&lstate
->accept_tios
);
10665 if (atio
== NULL
) {
10666 ahd
->flags
|= AHD_TQINFIFO_BLOCKED
;
10668 * Wait for more ATIOs from the peripheral driver for this lun.
10672 ahd
->flags
&= ~AHD_TQINFIFO_BLOCKED
;
10674 if ((ahd_debug
& AHD_SHOW_TQIN
) != 0)
10675 printk("Incoming command from %d for %d:%d%s\n",
10676 initiator
, target
, lun
,
10677 lstate
== ahd
->black_hole
? "(Black Holed)" : "");
10679 SLIST_REMOVE_HEAD(&lstate
->accept_tios
, sim_links
.sle
);
10681 if (lstate
== ahd
->black_hole
) {
10682 /* Fill in the wildcards */
10683 atio
->ccb_h
.target_id
= target
;
10684 atio
->ccb_h
.target_lun
= lun
;
10688 * Package it up and send it off to
10689 * whomever has this lun enabled.
10691 atio
->sense_len
= 0;
10692 atio
->init_id
= initiator
;
10693 if (byte
[0] != 0xFF) {
10694 /* Tag was included */
10695 atio
->tag_action
= *byte
++;
10696 atio
->tag_id
= *byte
++;
10697 atio
->ccb_h
.flags
= CAM_TAG_ACTION_VALID
;
10699 atio
->ccb_h
.flags
= 0;
10703 /* Okay. Now determine the cdb size based on the command code */
10704 switch (*byte
>> CMD_GROUP_CODE_SHIFT
) {
10710 atio
->cdb_len
= 10;
10713 atio
->cdb_len
= 16;
10716 atio
->cdb_len
= 12;
10720 /* Only copy the opcode. */
10722 printk("Reserved or VU command code type encountered\n");
10726 memcpy(atio
->cdb_io
.cdb_bytes
, byte
, atio
->cdb_len
);
10728 atio
->ccb_h
.status
|= CAM_CDB_RECVD
;
10730 if ((cmd
->identify
& MSG_IDENTIFY_DISCFLAG
) == 0) {
10732 * We weren't allowed to disconnect.
10733 * We're hanging on the bus until a
10734 * continue target I/O comes in response
10735 * to this accept tio.
10738 if ((ahd_debug
& AHD_SHOW_TQIN
) != 0)
10739 printk("Received Immediate Command %d:%d:%d - %p\n",
10740 initiator
, target
, lun
, ahd
->pending_device
);
10742 ahd
->pending_device
= lstate
;
10743 ahd_freeze_ccb((union ccb
*)atio
);
10744 atio
->ccb_h
.flags
|= CAM_DIS_DISCONNECT
;
10746 xpt_done((union ccb
*)atio
);