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
, NOP
, "in Data-out phase" },
77 { P_DATAIN
, INITIATOR_ERROR
, "in Data-in phase" },
78 { P_DATAOUT_DT
, NOP
, "in DT Data-out phase" },
79 { P_DATAIN_DT
, INITIATOR_ERROR
, "in DT Data-in phase" },
80 { P_COMMAND
, NOP
, "in Command phase" },
81 { P_MESGOUT
, NOP
, "in Message-out phase" },
82 { P_STATUS
, INITIATOR_ERROR
, "in Status phase" },
83 { P_MESGIN
, MSG_PARITY_ERROR
, "in Message-in phase" },
84 { P_BUSFREE
, NOP
, "while idle" },
85 { 0, NOP
, "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
, NOP
); /* 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
++) {
1739 addr
= ahd_le64toh(sg_list
[i
].addr
);
1740 printk("sg[%d] - Addr 0x%x%x : Length %d%s\n",
1742 (uint32_t)((addr
>> 32) & 0xFFFFFFFF),
1743 (uint32_t)(addr
& 0xFFFFFFFF),
1744 sg_list
[i
].len
& AHD_SG_LEN_MASK
,
1745 (sg_list
[i
].len
& AHD_DMA_LAST_SEG
)
1749 struct ahd_dma_seg
*sg_list
;
1751 sg_list
= (struct ahd_dma_seg
*)scb
->sg_list
;
1752 for (i
= 0; i
< scb
->sg_count
; i
++) {
1755 len
= ahd_le32toh(sg_list
[i
].len
);
1756 printk("sg[%d] - Addr 0x%x%x : Length %d%s\n",
1758 (len
& AHD_SG_HIGH_ADDR_MASK
) >> 24,
1759 ahd_le32toh(sg_list
[i
].addr
),
1760 len
& AHD_SG_LEN_MASK
,
1761 len
& AHD_DMA_LAST_SEG
? " Last" : "");
1766 #endif /* AHD_DEBUG */
1769 ahd_handle_seqint(struct ahd_softc
*ahd
, u_int intstat
)
1774 * Save the sequencer interrupt code and clear the SEQINT
1775 * bit. We will unpause the sequencer, if appropriate,
1776 * after servicing the request.
1778 seqintcode
= ahd_inb(ahd
, SEQINTCODE
);
1779 ahd_outb(ahd
, CLRINT
, CLRSEQINT
);
1780 if ((ahd
->bugs
& AHD_INTCOLLISION_BUG
) != 0) {
1782 * Unpause the sequencer and let it clear
1783 * SEQINT by writing NO_SEQINT to it. This
1784 * will cause the sequencer to be paused again,
1785 * which is the expected state of this routine.
1788 while (!ahd_is_paused(ahd
))
1790 ahd_outb(ahd
, CLRINT
, CLRSEQINT
);
1792 ahd_update_modes(ahd
);
1794 if ((ahd_debug
& AHD_SHOW_MISC
) != 0)
1795 printk("%s: Handle Seqint Called for code %d\n",
1796 ahd_name(ahd
), seqintcode
);
1798 switch (seqintcode
) {
1799 case ENTERING_NONPACK
:
1804 AHD_ASSERT_MODES(ahd
, ~(AHD_MODE_UNKNOWN_MSK
|AHD_MODE_CFG_MSK
),
1805 ~(AHD_MODE_UNKNOWN_MSK
|AHD_MODE_CFG_MSK
));
1806 scbid
= ahd_get_scbptr(ahd
);
1807 scb
= ahd_lookup_scb(ahd
, scbid
);
1810 * Somehow need to know if this
1811 * is from a selection or reselection.
1812 * From that, we can determine target
1813 * ID so we at least have an I_T nexus.
1816 ahd_outb(ahd
, SAVED_SCSIID
, scb
->hscb
->scsiid
);
1817 ahd_outb(ahd
, SAVED_LUN
, scb
->hscb
->lun
);
1818 ahd_outb(ahd
, SEQ_FLAGS
, 0x0);
1820 if ((ahd_inb(ahd
, LQISTAT2
) & LQIPHASE_OUTPKT
) != 0
1821 && (ahd_inb(ahd
, SCSISIGO
) & ATNO
) != 0) {
1823 * Phase change after read stream with
1824 * CRC error with P0 asserted on last
1828 if ((ahd_debug
& AHD_SHOW_RECOVERY
) != 0)
1829 printk("%s: Assuming LQIPHASE_NLQ with "
1830 "P0 assertion\n", ahd_name(ahd
));
1834 if ((ahd_debug
& AHD_SHOW_RECOVERY
) != 0)
1835 printk("%s: Entering NONPACK\n", ahd_name(ahd
));
1839 case INVALID_SEQINT
:
1840 printk("%s: Invalid Sequencer interrupt occurred, "
1841 "resetting channel.\n",
1844 if ((ahd_debug
& AHD_SHOW_RECOVERY
) != 0)
1845 ahd_dump_card_state(ahd
);
1847 ahd_reset_channel(ahd
, 'A', /*Initiate Reset*/TRUE
);
1849 case STATUS_OVERRUN
:
1854 scbid
= ahd_get_scbptr(ahd
);
1855 scb
= ahd_lookup_scb(ahd
, scbid
);
1857 ahd_print_path(ahd
, scb
);
1859 printk("%s: ", ahd_name(ahd
));
1860 printk("SCB %d Packetized Status Overrun", scbid
);
1861 ahd_dump_card_state(ahd
);
1862 ahd_reset_channel(ahd
, 'A', /*Initiate Reset*/TRUE
);
1865 case CFG4ISTAT_INTR
:
1870 scbid
= ahd_get_scbptr(ahd
);
1871 scb
= ahd_lookup_scb(ahd
, scbid
);
1873 ahd_dump_card_state(ahd
);
1874 printk("CFG4ISTAT: Free SCB %d referenced", scbid
);
1875 panic("For safety");
1877 ahd_outq(ahd
, HADDR
, scb
->sense_busaddr
);
1878 ahd_outw(ahd
, HCNT
, AHD_SENSE_BUFSIZE
);
1879 ahd_outb(ahd
, HCNT
+ 2, 0);
1880 ahd_outb(ahd
, SG_CACHE_PRE
, SG_LAST_SEG
);
1881 ahd_outb(ahd
, DFCNTRL
, PRELOADEN
|SCSIEN
|HDMAEN
);
1888 bus_phase
= ahd_inb(ahd
, SCSISIGI
) & PHASE_MASK
;
1889 printk("%s: ILLEGAL_PHASE 0x%x\n",
1890 ahd_name(ahd
), bus_phase
);
1892 switch (bus_phase
) {
1900 ahd_reset_channel(ahd
, 'A', /*Initiate Reset*/TRUE
);
1901 printk("%s: Issued Bus Reset.\n", ahd_name(ahd
));
1905 struct ahd_devinfo devinfo
;
1910 * If a target takes us into the command phase
1911 * assume that it has been externally reset and
1912 * has thus lost our previous packetized negotiation
1913 * agreement. Since we have not sent an identify
1914 * message and may not have fully qualified the
1915 * connection, we change our command to TUR, assert
1916 * ATN and ABORT the task when we go to message in
1917 * phase. The OSM will see the REQUEUE_REQUEST
1918 * status and retry the command.
1920 scbid
= ahd_get_scbptr(ahd
);
1921 scb
= ahd_lookup_scb(ahd
, scbid
);
1923 printk("Invalid phase with no valid SCB. "
1924 "Resetting bus.\n");
1925 ahd_reset_channel(ahd
, 'A',
1926 /*Initiate Reset*/TRUE
);
1929 ahd_compile_devinfo(&devinfo
, SCB_GET_OUR_ID(scb
),
1930 SCB_GET_TARGET(ahd
, scb
),
1932 SCB_GET_CHANNEL(ahd
, scb
),
1934 ahd_set_width(ahd
, &devinfo
, MSG_EXT_WDTR_BUS_8_BIT
,
1935 AHD_TRANS_ACTIVE
, /*paused*/TRUE
);
1936 ahd_set_syncrate(ahd
, &devinfo
, /*period*/0,
1937 /*offset*/0, /*ppr_options*/0,
1938 AHD_TRANS_ACTIVE
, /*paused*/TRUE
);
1939 /* Hand-craft TUR command */
1940 ahd_outb(ahd
, SCB_CDB_STORE
, 0);
1941 ahd_outb(ahd
, SCB_CDB_STORE
+1, 0);
1942 ahd_outb(ahd
, SCB_CDB_STORE
+2, 0);
1943 ahd_outb(ahd
, SCB_CDB_STORE
+3, 0);
1944 ahd_outb(ahd
, SCB_CDB_STORE
+4, 0);
1945 ahd_outb(ahd
, SCB_CDB_STORE
+5, 0);
1946 ahd_outb(ahd
, SCB_CDB_LEN
, 6);
1947 scb
->hscb
->control
&= ~(TAG_ENB
|SCB_TAG_TYPE
);
1948 scb
->hscb
->control
|= MK_MESSAGE
;
1949 ahd_outb(ahd
, SCB_CONTROL
, scb
->hscb
->control
);
1950 ahd_outb(ahd
, MSG_OUT
, HOST_MSG
);
1951 ahd_outb(ahd
, SAVED_SCSIID
, scb
->hscb
->scsiid
);
1953 * The lun is 0, regardless of the SCB's lun
1954 * as we have not sent an identify message.
1956 ahd_outb(ahd
, SAVED_LUN
, 0);
1957 ahd_outb(ahd
, SEQ_FLAGS
, 0);
1958 ahd_assert_atn(ahd
);
1959 scb
->flags
&= ~SCB_PACKETIZED
;
1960 scb
->flags
|= SCB_ABORT
|SCB_EXTERNAL_RESET
;
1961 ahd_freeze_devq(ahd
, scb
);
1962 ahd_set_transaction_status(scb
, CAM_REQUEUE_REQ
);
1963 ahd_freeze_scb(scb
);
1966 ahd_send_async(ahd
, devinfo
.channel
, devinfo
.target
,
1967 CAM_LUN_WILDCARD
, AC_SENT_BDR
);
1970 * Allow the sequencer to continue with
1971 * non-pack processing.
1973 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
1974 ahd_outb(ahd
, CLRLQOINT1
, CLRLQOPHACHGINPKT
);
1975 if ((ahd
->bugs
& AHD_CLRLQO_AUTOCLR_BUG
) != 0) {
1976 ahd_outb(ahd
, CLRLQOINT1
, 0);
1979 if ((ahd_debug
& AHD_SHOW_RECOVERY
) != 0) {
1980 ahd_print_path(ahd
, scb
);
1981 printk("Unexpected command phase from "
1982 "packetized target\n");
1996 if ((ahd_debug
& AHD_SHOW_RECOVERY
) != 0) {
1997 printk("%s: CFG4OVERRUN mode = %x\n", ahd_name(ahd
),
1998 ahd_inb(ahd
, MODE_PTR
));
2001 scb_index
= ahd_get_scbptr(ahd
);
2002 scb
= ahd_lookup_scb(ahd
, scb_index
);
2005 * Attempt to transfer to an SCB that is
2008 ahd_assert_atn(ahd
);
2009 ahd_outb(ahd
, MSG_OUT
, HOST_MSG
);
2010 ahd
->msgout_buf
[0] = ABORT_TASK
;
2011 ahd
->msgout_len
= 1;
2012 ahd
->msgout_index
= 0;
2013 ahd
->msg_type
= MSG_TYPE_INITIATOR_MSGOUT
;
2015 * Clear status received flag to prevent any
2016 * attempt to complete this bogus SCB.
2018 ahd_outb(ahd
, SCB_CONTROL
,
2019 ahd_inb_scbram(ahd
, SCB_CONTROL
)
2024 case DUMP_CARD_STATE
:
2026 ahd_dump_card_state(ahd
);
2032 if ((ahd_debug
& AHD_SHOW_RECOVERY
) != 0) {
2033 printk("%s: PDATA_REINIT - DFCNTRL = 0x%x "
2034 "SG_CACHE_SHADOW = 0x%x\n",
2035 ahd_name(ahd
), ahd_inb(ahd
, DFCNTRL
),
2036 ahd_inb(ahd
, SG_CACHE_SHADOW
));
2039 ahd_reinitialize_dataptrs(ahd
);
2044 struct ahd_devinfo devinfo
;
2047 * The sequencer has encountered a message phase
2048 * that requires host assistance for completion.
2049 * While handling the message phase(s), we will be
2050 * notified by the sequencer after each byte is
2051 * transferred so we can track bus phase changes.
2053 * If this is the first time we've seen a HOST_MSG_LOOP
2054 * interrupt, initialize the state of the host message
2057 ahd_fetch_devinfo(ahd
, &devinfo
);
2058 if (ahd
->msg_type
== MSG_TYPE_NONE
) {
2063 bus_phase
= ahd_inb(ahd
, SCSISIGI
) & PHASE_MASK
;
2064 if (bus_phase
!= P_MESGIN
2065 && bus_phase
!= P_MESGOUT
) {
2066 printk("ahd_intr: HOST_MSG_LOOP bad "
2067 "phase 0x%x\n", bus_phase
);
2069 * Probably transitioned to bus free before
2070 * we got here. Just punt the message.
2072 ahd_dump_card_state(ahd
);
2073 ahd_clear_intstat(ahd
);
2078 scb_index
= ahd_get_scbptr(ahd
);
2079 scb
= ahd_lookup_scb(ahd
, scb_index
);
2080 if (devinfo
.role
== ROLE_INITIATOR
) {
2081 if (bus_phase
== P_MESGOUT
)
2082 ahd_setup_initiator_msgout(ahd
,
2087 MSG_TYPE_INITIATOR_MSGIN
;
2088 ahd
->msgin_index
= 0;
2091 #ifdef AHD_TARGET_MODE
2093 if (bus_phase
== P_MESGOUT
) {
2095 MSG_TYPE_TARGET_MSGOUT
;
2096 ahd
->msgin_index
= 0;
2098 ahd_setup_target_msgin(ahd
,
2105 ahd_handle_message_phase(ahd
);
2110 /* Ensure we don't leave the selection hardware on */
2111 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
2112 ahd_outb(ahd
, SCSISEQ0
, ahd_inb(ahd
, SCSISEQ0
) & ~ENSELO
);
2114 printk("%s:%c:%d: no active SCB for reconnecting "
2115 "target - issuing BUS DEVICE RESET\n",
2116 ahd_name(ahd
), 'A', ahd_inb(ahd
, SELID
) >> 4);
2117 printk("SAVED_SCSIID == 0x%x, SAVED_LUN == 0x%x, "
2118 "REG0 == 0x%x ACCUM = 0x%x\n",
2119 ahd_inb(ahd
, SAVED_SCSIID
), ahd_inb(ahd
, SAVED_LUN
),
2120 ahd_inw(ahd
, REG0
), ahd_inb(ahd
, ACCUM
));
2121 printk("SEQ_FLAGS == 0x%x, SCBPTR == 0x%x, BTT == 0x%x, "
2123 ahd_inb(ahd
, SEQ_FLAGS
), ahd_get_scbptr(ahd
),
2124 ahd_find_busy_tcl(ahd
,
2125 BUILD_TCL(ahd_inb(ahd
, SAVED_SCSIID
),
2126 ahd_inb(ahd
, SAVED_LUN
))),
2127 ahd_inw(ahd
, SINDEX
));
2128 printk("SELID == 0x%x, SCB_SCSIID == 0x%x, SCB_LUN == 0x%x, "
2129 "SCB_CONTROL == 0x%x\n",
2130 ahd_inb(ahd
, SELID
), ahd_inb_scbram(ahd
, SCB_SCSIID
),
2131 ahd_inb_scbram(ahd
, SCB_LUN
),
2132 ahd_inb_scbram(ahd
, SCB_CONTROL
));
2133 printk("SCSIBUS[0] == 0x%x, SCSISIGI == 0x%x\n",
2134 ahd_inb(ahd
, SCSIBUS
), ahd_inb(ahd
, SCSISIGI
));
2135 printk("SXFRCTL0 == 0x%x\n", ahd_inb(ahd
, SXFRCTL0
));
2136 printk("SEQCTL0 == 0x%x\n", ahd_inb(ahd
, SEQCTL0
));
2137 ahd_dump_card_state(ahd
);
2138 ahd
->msgout_buf
[0] = TARGET_RESET
;
2139 ahd
->msgout_len
= 1;
2140 ahd
->msgout_index
= 0;
2141 ahd
->msg_type
= MSG_TYPE_INITIATOR_MSGOUT
;
2142 ahd_outb(ahd
, MSG_OUT
, HOST_MSG
);
2143 ahd_assert_atn(ahd
);
2146 case PROTO_VIOLATION
:
2148 ahd_handle_proto_violation(ahd
);
2153 struct ahd_devinfo devinfo
;
2155 ahd_fetch_devinfo(ahd
, &devinfo
);
2156 ahd_handle_ign_wide_residue(ahd
, &devinfo
);
2163 lastphase
= ahd_inb(ahd
, LASTPHASE
);
2164 printk("%s:%c:%d: unknown scsi bus phase %x, "
2165 "lastphase = 0x%x. Attempting to continue\n",
2167 SCSIID_TARGET(ahd
, ahd_inb(ahd
, SAVED_SCSIID
)),
2168 lastphase
, ahd_inb(ahd
, SCSISIGI
));
2171 case MISSED_BUSFREE
:
2175 lastphase
= ahd_inb(ahd
, LASTPHASE
);
2176 printk("%s:%c:%d: Missed busfree. "
2177 "Lastphase = 0x%x, Curphase = 0x%x\n",
2179 SCSIID_TARGET(ahd
, ahd_inb(ahd
, SAVED_SCSIID
)),
2180 lastphase
, ahd_inb(ahd
, SCSISIGI
));
2187 * When the sequencer detects an overrun, it
2188 * places the controller in "BITBUCKET" mode
2189 * and allows the target to complete its transfer.
2190 * Unfortunately, none of the counters get updated
2191 * when the controller is in this mode, so we have
2192 * no way of knowing how large the overrun was.
2200 scbindex
= ahd_get_scbptr(ahd
);
2201 scb
= ahd_lookup_scb(ahd
, scbindex
);
2203 lastphase
= ahd_inb(ahd
, LASTPHASE
);
2204 if ((ahd_debug
& AHD_SHOW_RECOVERY
) != 0) {
2205 ahd_print_path(ahd
, scb
);
2206 printk("data overrun detected %s. Tag == 0x%x.\n",
2207 ahd_lookup_phase_entry(lastphase
)->phasemsg
,
2209 ahd_print_path(ahd
, scb
);
2210 printk("%s seen Data Phase. Length = %ld. "
2212 ahd_inb(ahd
, SEQ_FLAGS
) & DPHASE
2213 ? "Have" : "Haven't",
2214 ahd_get_transfer_length(scb
), scb
->sg_count
);
2215 ahd_dump_sglist(scb
);
2220 * Set this and it will take effect when the
2221 * target does a command complete.
2223 ahd_freeze_devq(ahd
, scb
);
2224 ahd_set_transaction_status(scb
, CAM_DATA_RUN_ERR
);
2225 ahd_freeze_scb(scb
);
2230 struct ahd_devinfo devinfo
;
2234 ahd_fetch_devinfo(ahd
, &devinfo
);
2235 printk("%s:%c:%d:%d: Attempt to issue message failed\n",
2236 ahd_name(ahd
), devinfo
.channel
, devinfo
.target
,
2238 scbid
= ahd_get_scbptr(ahd
);
2239 scb
= ahd_lookup_scb(ahd
, scbid
);
2241 && (scb
->flags
& SCB_RECOVERY_SCB
) != 0)
2243 * Ensure that we didn't put a second instance of this
2244 * SCB into the QINFIFO.
2246 ahd_search_qinfifo(ahd
, SCB_GET_TARGET(ahd
, scb
),
2247 SCB_GET_CHANNEL(ahd
, scb
),
2248 SCB_GET_LUN(scb
), SCB_GET_TAG(scb
),
2249 ROLE_INITIATOR
, /*status*/0,
2251 ahd_outb(ahd
, SCB_CONTROL
,
2252 ahd_inb_scbram(ahd
, SCB_CONTROL
) & ~MK_MESSAGE
);
2255 case TASKMGMT_FUNC_COMPLETE
:
2260 scbid
= ahd_get_scbptr(ahd
);
2261 scb
= ahd_lookup_scb(ahd
, scbid
);
2267 ahd_print_path(ahd
, scb
);
2268 printk("Task Management Func 0x%x Complete\n",
2269 scb
->hscb
->task_management
);
2270 lun
= CAM_LUN_WILDCARD
;
2271 tag
= SCB_LIST_NULL
;
2273 switch (scb
->hscb
->task_management
) {
2274 case SIU_TASKMGMT_ABORT_TASK
:
2275 tag
= SCB_GET_TAG(scb
);
2277 case SIU_TASKMGMT_ABORT_TASK_SET
:
2278 case SIU_TASKMGMT_CLEAR_TASK_SET
:
2279 lun
= scb
->hscb
->lun
;
2280 error
= CAM_REQ_ABORTED
;
2281 ahd_abort_scbs(ahd
, SCB_GET_TARGET(ahd
, scb
),
2282 'A', lun
, tag
, ROLE_INITIATOR
,
2285 case SIU_TASKMGMT_LUN_RESET
:
2286 lun
= scb
->hscb
->lun
;
2288 case SIU_TASKMGMT_TARGET_RESET
:
2290 struct ahd_devinfo devinfo
;
2292 ahd_scb_devinfo(ahd
, &devinfo
, scb
);
2293 error
= CAM_BDR_SENT
;
2294 ahd_handle_devreset(ahd
, &devinfo
, lun
,
2296 lun
!= CAM_LUN_WILDCARD
2299 /*verbose_level*/0);
2303 panic("Unexpected TaskMgmt Func\n");
2309 case TASKMGMT_CMD_CMPLT_OKAY
:
2315 * An ABORT TASK TMF failed to be delivered before
2316 * the targeted command completed normally.
2318 scbid
= ahd_get_scbptr(ahd
);
2319 scb
= ahd_lookup_scb(ahd
, scbid
);
2322 * Remove the second instance of this SCB from
2323 * the QINFIFO if it is still there.
2325 ahd_print_path(ahd
, scb
);
2326 printk("SCB completes before TMF\n");
2328 * Handle losing the race. Wait until any
2329 * current selection completes. We will then
2330 * set the TMF back to zero in this SCB so that
2331 * the sequencer doesn't bother to issue another
2332 * sequencer interrupt for its completion.
2334 while ((ahd_inb(ahd
, SCSISEQ0
) & ENSELO
) != 0
2335 && (ahd_inb(ahd
, SSTAT0
) & SELDO
) == 0
2336 && (ahd_inb(ahd
, SSTAT1
) & SELTO
) == 0)
2338 ahd_outb(ahd
, SCB_TASK_MANAGEMENT
, 0);
2339 ahd_search_qinfifo(ahd
, SCB_GET_TARGET(ahd
, scb
),
2340 SCB_GET_CHANNEL(ahd
, scb
),
2341 SCB_GET_LUN(scb
), SCB_GET_TAG(scb
),
2342 ROLE_INITIATOR
, /*status*/0,
2351 printk("%s: Tracepoint %d\n", ahd_name(ahd
),
2352 seqintcode
- TRACEPOINT0
);
2357 ahd_handle_hwerrint(ahd
);
2360 printk("%s: Unexpected SEQINTCODE %d\n", ahd_name(ahd
),
2365 * The sequencer is paused immediately on
2366 * a SEQINT, so we should restart it when
2373 ahd_handle_scsiint(struct ahd_softc
*ahd
, u_int intstat
)
2384 ahd_update_modes(ahd
);
2385 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
2387 status3
= ahd_inb(ahd
, SSTAT3
) & (NTRAMPERR
|OSRAMPERR
);
2388 status0
= ahd_inb(ahd
, SSTAT0
) & (IOERR
|OVERRUN
|SELDI
|SELDO
);
2389 status
= ahd_inb(ahd
, SSTAT1
) & (SELTO
|SCSIRSTI
|BUSFREE
|SCSIPERR
);
2390 lqistat1
= ahd_inb(ahd
, LQISTAT1
);
2391 lqostat0
= ahd_inb(ahd
, LQOSTAT0
);
2392 busfreetime
= ahd_inb(ahd
, SSTAT2
) & BUSFREETIME
;
2395 * Ignore external resets after a bus reset.
2397 if (((status
& SCSIRSTI
) != 0) && (ahd
->flags
& AHD_BUS_RESET_ACTIVE
)) {
2398 ahd_outb(ahd
, CLRSINT1
, CLRSCSIRSTI
);
2403 * Clear bus reset flag
2405 ahd
->flags
&= ~AHD_BUS_RESET_ACTIVE
;
2407 if ((status0
& (SELDI
|SELDO
)) != 0) {
2410 ahd_set_modes(ahd
, AHD_MODE_CFG
, AHD_MODE_CFG
);
2411 simode0
= ahd_inb(ahd
, SIMODE0
);
2412 status0
&= simode0
& (IOERR
|OVERRUN
|SELDI
|SELDO
);
2413 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
2415 scbid
= ahd_get_scbptr(ahd
);
2416 scb
= ahd_lookup_scb(ahd
, scbid
);
2418 && (ahd_inb(ahd
, SEQ_FLAGS
) & NOT_IDENTIFIED
) != 0)
2421 if ((status0
& IOERR
) != 0) {
2424 now_lvd
= ahd_inb(ahd
, SBLKCTL
) & ENAB40
;
2425 printk("%s: Transceiver State Has Changed to %s mode\n",
2426 ahd_name(ahd
), now_lvd
? "LVD" : "SE");
2427 ahd_outb(ahd
, CLRSINT0
, CLRIOERR
);
2429 * A change in I/O mode is equivalent to a bus reset.
2431 ahd_reset_channel(ahd
, 'A', /*Initiate Reset*/TRUE
);
2433 ahd_setup_iocell_workaround(ahd
);
2435 } else if ((status0
& OVERRUN
) != 0) {
2437 printk("%s: SCSI offset overrun detected. Resetting bus.\n",
2439 ahd_reset_channel(ahd
, 'A', /*Initiate Reset*/TRUE
);
2440 } else if ((status
& SCSIRSTI
) != 0) {
2442 printk("%s: Someone reset channel A\n", ahd_name(ahd
));
2443 ahd_reset_channel(ahd
, 'A', /*Initiate Reset*/FALSE
);
2444 } else if ((status
& SCSIPERR
) != 0) {
2446 /* Make sure the sequencer is in a safe location. */
2447 ahd_clear_critical_section(ahd
);
2449 ahd_handle_transmission_error(ahd
);
2450 } else if (lqostat0
!= 0) {
2452 printk("%s: lqostat0 == 0x%x!\n", ahd_name(ahd
), lqostat0
);
2453 ahd_outb(ahd
, CLRLQOINT0
, lqostat0
);
2454 if ((ahd
->bugs
& AHD_CLRLQO_AUTOCLR_BUG
) != 0)
2455 ahd_outb(ahd
, CLRLQOINT1
, 0);
2456 } else if ((status
& SELTO
) != 0) {
2457 /* Stop the selection */
2458 ahd_outb(ahd
, SCSISEQ0
, 0);
2460 /* Make sure the sequencer is in a safe location. */
2461 ahd_clear_critical_section(ahd
);
2463 /* No more pending messages */
2464 ahd_clear_msg_state(ahd
);
2466 /* Clear interrupt state */
2467 ahd_outb(ahd
, CLRSINT1
, CLRSELTIMEO
|CLRBUSFREE
|CLRSCSIPERR
);
2470 * Although the driver does not care about the
2471 * 'Selection in Progress' status bit, the busy
2472 * LED does. SELINGO is only cleared by a successful
2473 * selection, so we must manually clear it to insure
2474 * the LED turns off just incase no future successful
2475 * selections occur (e.g. no devices on the bus).
2477 ahd_outb(ahd
, CLRSINT0
, CLRSELINGO
);
2479 scbid
= ahd_inw(ahd
, WAITING_TID_HEAD
);
2480 scb
= ahd_lookup_scb(ahd
, scbid
);
2482 printk("%s: ahd_intr - referenced scb not "
2483 "valid during SELTO scb(0x%x)\n",
2484 ahd_name(ahd
), scbid
);
2485 ahd_dump_card_state(ahd
);
2487 struct ahd_devinfo devinfo
;
2489 if ((ahd_debug
& AHD_SHOW_SELTO
) != 0) {
2490 ahd_print_path(ahd
, scb
);
2491 printk("Saw Selection Timeout for SCB 0x%x\n",
2495 ahd_scb_devinfo(ahd
, &devinfo
, scb
);
2496 ahd_set_transaction_status(scb
, CAM_SEL_TIMEOUT
);
2497 ahd_freeze_devq(ahd
, scb
);
2500 * Cancel any pending transactions on the device
2501 * now that it seems to be missing. This will
2502 * also revert us to async/narrow transfers until
2503 * we can renegotiate with the device.
2505 ahd_handle_devreset(ahd
, &devinfo
,
2508 "Selection Timeout",
2509 /*verbose_level*/1);
2511 ahd_outb(ahd
, CLRINT
, CLRSCSIINT
);
2512 ahd_iocell_first_selection(ahd
);
2514 } else if ((status0
& (SELDI
|SELDO
)) != 0) {
2516 ahd_iocell_first_selection(ahd
);
2518 } else if (status3
!= 0) {
2519 printk("%s: SCSI Cell parity error SSTAT3 == 0x%x\n",
2520 ahd_name(ahd
), status3
);
2521 ahd_outb(ahd
, CLRSINT3
, status3
);
2522 } else if ((lqistat1
& (LQIPHASE_LQ
|LQIPHASE_NLQ
)) != 0) {
2524 /* Make sure the sequencer is in a safe location. */
2525 ahd_clear_critical_section(ahd
);
2527 ahd_handle_lqiphase_error(ahd
, lqistat1
);
2528 } else if ((lqistat1
& LQICRCI_NLQ
) != 0) {
2530 * This status can be delayed during some
2531 * streaming operations. The SCSIPHASE
2532 * handler has already dealt with this case
2533 * so just clear the error.
2535 ahd_outb(ahd
, CLRLQIINT1
, CLRLQICRCI_NLQ
);
2536 } else if ((status
& BUSFREE
) != 0
2537 || (lqistat1
& LQOBUSFREE
) != 0) {
2545 * Clear our selection hardware as soon as possible.
2546 * We may have an entry in the waiting Q for this target,
2547 * that is affected by this busfree and we don't want to
2548 * go about selecting the target while we handle the event.
2550 ahd_outb(ahd
, SCSISEQ0
, 0);
2552 /* Make sure the sequencer is in a safe location. */
2553 ahd_clear_critical_section(ahd
);
2556 * Determine what we were up to at the time of
2559 mode
= AHD_MODE_SCSI
;
2560 busfreetime
= ahd_inb(ahd
, SSTAT2
) & BUSFREETIME
;
2561 lqostat1
= ahd_inb(ahd
, LQOSTAT1
);
2562 switch (busfreetime
) {
2566 mode
= busfreetime
== BUSFREE_DFF0
2567 ? AHD_MODE_DFF0
: AHD_MODE_DFF1
;
2568 ahd_set_modes(ahd
, mode
, mode
);
2569 scbid
= ahd_get_scbptr(ahd
);
2570 scb
= ahd_lookup_scb(ahd
, scbid
);
2572 printk("%s: Invalid SCB %d in DFF%d "
2573 "during unexpected busfree\n",
2574 ahd_name(ahd
), scbid
, mode
);
2577 packetized
= (scb
->flags
& SCB_PACKETIZED
) != 0;
2587 packetized
= (lqostat1
& LQOBUSFREE
) != 0;
2589 && ahd_inb(ahd
, LASTPHASE
) == P_BUSFREE
2590 && (ahd_inb(ahd
, SSTAT0
) & SELDI
) == 0
2591 && ((ahd_inb(ahd
, SSTAT0
) & SELDO
) == 0
2592 || (ahd_inb(ahd
, SCSISEQ0
) & ENSELO
) == 0))
2594 * Assume packetized if we are not
2595 * on the bus in a non-packetized
2596 * capacity and any pending selection
2597 * was a packetized selection.
2604 if ((ahd_debug
& AHD_SHOW_MISC
) != 0)
2605 printk("Saw Busfree. Busfreetime = 0x%x.\n",
2609 * Busfrees that occur in non-packetized phases are
2610 * handled by the nonpkt_busfree handler.
2612 if (packetized
&& ahd_inb(ahd
, LASTPHASE
) == P_BUSFREE
) {
2613 restart
= ahd_handle_pkt_busfree(ahd
, busfreetime
);
2616 restart
= ahd_handle_nonpkt_busfree(ahd
);
2619 * Clear the busfree interrupt status. The setting of
2620 * the interrupt is a pulse, so in a perfect world, we
2621 * would not need to muck with the ENBUSFREE logic. This
2622 * would ensure that if the bus moves on to another
2623 * connection, busfree protection is still in force. If
2624 * BUSFREEREV is broken, however, we must manually clear
2625 * the ENBUSFREE if the busfree occurred during a non-pack
2626 * connection so that we don't get false positives during
2627 * future, packetized, connections.
2629 ahd_outb(ahd
, CLRSINT1
, CLRBUSFREE
);
2631 && (ahd
->bugs
& AHD_BUSFREEREV_BUG
) != 0)
2632 ahd_outb(ahd
, SIMODE1
,
2633 ahd_inb(ahd
, SIMODE1
) & ~ENBUSFREE
);
2636 ahd_clear_fifo(ahd
, mode
);
2638 ahd_clear_msg_state(ahd
);
2639 ahd_outb(ahd
, CLRINT
, CLRSCSIINT
);
2646 printk("%s: Missing case in ahd_handle_scsiint. status = %x\n",
2647 ahd_name(ahd
), status
);
2648 ahd_dump_card_state(ahd
);
2649 ahd_clear_intstat(ahd
);
2655 ahd_handle_transmission_error(struct ahd_softc
*ahd
)
2668 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
2669 lqistat1
= ahd_inb(ahd
, LQISTAT1
) & ~(LQIPHASE_LQ
|LQIPHASE_NLQ
);
2670 ahd_inb(ahd
, LQISTAT2
);
2671 if ((lqistat1
& (LQICRCI_NLQ
|LQICRCI_LQ
)) == 0
2672 && (ahd
->bugs
& AHD_NLQICRC_DELAYED_BUG
) != 0) {
2675 ahd_set_modes(ahd
, AHD_MODE_CFG
, AHD_MODE_CFG
);
2676 lqistate
= ahd_inb(ahd
, LQISTATE
);
2677 if ((lqistate
>= 0x1E && lqistate
<= 0x24)
2678 || (lqistate
== 0x29)) {
2680 if ((ahd_debug
& AHD_SHOW_RECOVERY
) != 0) {
2681 printk("%s: NLQCRC found via LQISTATE\n",
2685 lqistat1
|= LQICRCI_NLQ
;
2687 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
2690 ahd_outb(ahd
, CLRLQIINT1
, lqistat1
);
2691 lastphase
= ahd_inb(ahd
, LASTPHASE
);
2692 curphase
= ahd_inb(ahd
, SCSISIGI
) & PHASE_MASK
;
2693 perrdiag
= ahd_inb(ahd
, PERRDIAG
);
2694 msg_out
= INITIATOR_ERROR
;
2695 ahd_outb(ahd
, CLRSINT1
, CLRSCSIPERR
);
2698 * Try to find the SCB associated with this error.
2702 || (lqistat1
& LQICRCI_NLQ
) != 0) {
2703 if ((lqistat1
& (LQICRCI_NLQ
|LQIOVERI_NLQ
)) != 0)
2704 ahd_set_active_fifo(ahd
);
2705 scbid
= ahd_get_scbptr(ahd
);
2706 scb
= ahd_lookup_scb(ahd
, scbid
);
2707 if (scb
!= NULL
&& SCB_IS_SILENT(scb
))
2712 if (silent
== FALSE
) {
2713 printk("%s: Transmission error detected\n", ahd_name(ahd
));
2714 ahd_lqistat1_print(lqistat1
, &cur_col
, 50);
2715 ahd_lastphase_print(lastphase
, &cur_col
, 50);
2716 ahd_scsisigi_print(curphase
, &cur_col
, 50);
2717 ahd_perrdiag_print(perrdiag
, &cur_col
, 50);
2719 ahd_dump_card_state(ahd
);
2722 if ((lqistat1
& (LQIOVERI_LQ
|LQIOVERI_NLQ
)) != 0) {
2723 if (silent
== FALSE
) {
2724 printk("%s: Gross protocol error during incoming "
2725 "packet. lqistat1 == 0x%x. Resetting bus.\n",
2726 ahd_name(ahd
), lqistat1
);
2728 ahd_reset_channel(ahd
, 'A', /*Initiate Reset*/TRUE
);
2730 } else if ((lqistat1
& LQICRCI_LQ
) != 0) {
2732 * A CRC error has been detected on an incoming LQ.
2733 * The bus is currently hung on the last ACK.
2734 * Hit LQIRETRY to release the last ack, and
2735 * wait for the sequencer to determine that ATNO
2736 * is asserted while in message out to take us
2737 * to our host message loop. No NONPACKREQ or
2738 * LQIPHASE type errors will occur in this
2739 * scenario. After this first LQIRETRY, the LQI
2740 * manager will be in ISELO where it will
2741 * happily sit until another packet phase begins.
2742 * Unexpected bus free detection is enabled
2743 * through any phases that occur after we release
2744 * this last ack until the LQI manager sees a
2745 * packet phase. This implies we may have to
2746 * ignore a perfectly valid "unexected busfree"
2747 * after our "initiator detected error" message is
2748 * sent. A busfree is the expected response after
2749 * we tell the target that it's L_Q was corrupted.
2750 * (SPI4R09 10.7.3.3.3)
2752 ahd_outb(ahd
, LQCTL2
, LQIRETRY
);
2753 printk("LQIRetry for LQICRCI_LQ to release ACK\n");
2754 } else if ((lqistat1
& LQICRCI_NLQ
) != 0) {
2756 * We detected a CRC error in a NON-LQ packet.
2757 * The hardware has varying behavior in this situation
2758 * depending on whether this packet was part of a
2762 * The hardware has already acked the complete packet.
2763 * If the target honors our outstanding ATN condition,
2764 * we should be (or soon will be) in MSGOUT phase.
2765 * This will trigger the LQIPHASE_LQ status bit as the
2766 * hardware was expecting another LQ. Unexpected
2767 * busfree detection is enabled. Once LQIPHASE_LQ is
2768 * true (first entry into host message loop is much
2769 * the same), we must clear LQIPHASE_LQ and hit
2770 * LQIRETRY so the hardware is ready to handle
2771 * a future LQ. NONPACKREQ will not be asserted again
2772 * once we hit LQIRETRY until another packet is
2773 * processed. The target may either go busfree
2774 * or start another packet in response to our message.
2776 * Read Streaming P0 asserted:
2777 * If we raise ATN and the target completes the entire
2778 * stream (P0 asserted during the last packet), the
2779 * hardware will ack all data and return to the ISTART
2780 * state. When the target reponds to our ATN condition,
2781 * LQIPHASE_LQ will be asserted. We should respond to
2782 * this with an LQIRETRY to prepare for any future
2783 * packets. NONPACKREQ will not be asserted again
2784 * once we hit LQIRETRY until another packet is
2785 * processed. The target may either go busfree or
2786 * start another packet in response to our message.
2787 * Busfree detection is enabled.
2789 * Read Streaming P0 not asserted:
2790 * If we raise ATN and the target transitions to
2791 * MSGOUT in or after a packet where P0 is not
2792 * asserted, the hardware will assert LQIPHASE_NLQ.
2793 * We should respond to the LQIPHASE_NLQ with an
2794 * LQIRETRY. Should the target stay in a non-pkt
2795 * phase after we send our message, the hardware
2796 * will assert LQIPHASE_LQ. Recovery is then just as
2797 * listed above for the read streaming with P0 asserted.
2798 * Busfree detection is enabled.
2800 if (silent
== FALSE
)
2801 printk("LQICRC_NLQ\n");
2803 printk("%s: No SCB valid for LQICRC_NLQ. "
2804 "Resetting bus\n", ahd_name(ahd
));
2805 ahd_reset_channel(ahd
, 'A', /*Initiate Reset*/TRUE
);
2808 } else if ((lqistat1
& LQIBADLQI
) != 0) {
2809 printk("Need to handle BADLQI!\n");
2810 ahd_reset_channel(ahd
, 'A', /*Initiate Reset*/TRUE
);
2812 } else if ((perrdiag
& (PARITYERR
|PREVPHASE
)) == PARITYERR
) {
2813 if ((curphase
& ~P_DATAIN_DT
) != 0) {
2814 /* Ack the byte. So we can continue. */
2815 if (silent
== FALSE
)
2816 printk("Acking %s to clear perror\n",
2817 ahd_lookup_phase_entry(curphase
)->phasemsg
);
2818 ahd_inb(ahd
, SCSIDAT
);
2821 if (curphase
== P_MESGIN
)
2822 msg_out
= MSG_PARITY_ERROR
;
2826 * We've set the hardware to assert ATN if we
2827 * get a parity error on "in" phases, so all we
2828 * need to do is stuff the message buffer with
2829 * the appropriate message. "In" phases have set
2830 * mesg_out to something other than NOP.
2832 ahd
->send_msg_perror
= msg_out
;
2833 if (scb
!= NULL
&& msg_out
== INITIATOR_ERROR
)
2834 scb
->flags
|= SCB_TRANSMISSION_ERROR
;
2835 ahd_outb(ahd
, MSG_OUT
, HOST_MSG
);
2836 ahd_outb(ahd
, CLRINT
, CLRSCSIINT
);
2841 ahd_handle_lqiphase_error(struct ahd_softc
*ahd
, u_int lqistat1
)
2844 * Clear the sources of the interrupts.
2846 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
2847 ahd_outb(ahd
, CLRLQIINT1
, lqistat1
);
2850 * If the "illegal" phase changes were in response
2851 * to our ATN to flag a CRC error, AND we ended up
2852 * on packet boundaries, clear the error, restart the
2853 * LQI manager as appropriate, and go on our merry
2854 * way toward sending the message. Otherwise, reset
2855 * the bus to clear the error.
2857 ahd_set_active_fifo(ahd
);
2858 if ((ahd_inb(ahd
, SCSISIGO
) & ATNO
) != 0
2859 && (ahd_inb(ahd
, MDFFSTAT
) & DLZERO
) != 0) {
2860 if ((lqistat1
& LQIPHASE_LQ
) != 0) {
2861 printk("LQIRETRY for LQIPHASE_LQ\n");
2862 ahd_outb(ahd
, LQCTL2
, LQIRETRY
);
2863 } else if ((lqistat1
& LQIPHASE_NLQ
) != 0) {
2864 printk("LQIRETRY for LQIPHASE_NLQ\n");
2865 ahd_outb(ahd
, LQCTL2
, LQIRETRY
);
2867 panic("ahd_handle_lqiphase_error: No phase errors\n");
2868 ahd_dump_card_state(ahd
);
2869 ahd_outb(ahd
, CLRINT
, CLRSCSIINT
);
2872 printk("Resetting Channel for LQI Phase error\n");
2873 ahd_dump_card_state(ahd
);
2874 ahd_reset_channel(ahd
, 'A', /*Initiate Reset*/TRUE
);
2879 * Packetized unexpected or expected busfree.
2880 * Entered in mode based on busfreetime.
2883 ahd_handle_pkt_busfree(struct ahd_softc
*ahd
, u_int busfreetime
)
2887 AHD_ASSERT_MODES(ahd
, ~(AHD_MODE_UNKNOWN_MSK
|AHD_MODE_CFG_MSK
),
2888 ~(AHD_MODE_UNKNOWN_MSK
|AHD_MODE_CFG_MSK
));
2889 lqostat1
= ahd_inb(ahd
, LQOSTAT1
);
2890 if ((lqostat1
& LQOBUSFREE
) != 0) {
2899 * The LQO manager detected an unexpected busfree
2902 * 1) During an outgoing LQ.
2903 * 2) After an outgoing LQ but before the first
2904 * REQ of the command packet.
2905 * 3) During an outgoing command packet.
2907 * In all cases, CURRSCB is pointing to the
2908 * SCB that encountered the failure. Clean
2909 * up the queue, clear SELDO and LQOBUSFREE,
2910 * and allow the sequencer to restart the select
2911 * out at its lesure.
2913 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
2914 scbid
= ahd_inw(ahd
, CURRSCB
);
2915 scb
= ahd_lookup_scb(ahd
, scbid
);
2917 panic("SCB not valid during LQOBUSFREE");
2921 ahd_outb(ahd
, CLRLQOINT1
, CLRLQOBUSFREE
);
2922 if ((ahd
->bugs
& AHD_CLRLQO_AUTOCLR_BUG
) != 0)
2923 ahd_outb(ahd
, CLRLQOINT1
, 0);
2924 ahd_outb(ahd
, SCSISEQ0
, ahd_inb(ahd
, SCSISEQ0
) & ~ENSELO
);
2925 ahd_flush_device_writes(ahd
);
2926 ahd_outb(ahd
, CLRSINT0
, CLRSELDO
);
2929 * Return the LQO manager to its idle loop. It will
2930 * not do this automatically if the busfree occurs
2931 * after the first REQ of either the LQ or command
2932 * packet or between the LQ and command packet.
2934 ahd_outb(ahd
, LQCTL2
, ahd_inb(ahd
, LQCTL2
) | LQOTOIDLE
);
2937 * Update the waiting for selection queue so
2938 * we restart on the correct SCB.
2940 waiting_h
= ahd_inw(ahd
, WAITING_TID_HEAD
);
2941 saved_scbptr
= ahd_get_scbptr(ahd
);
2942 if (waiting_h
!= scbid
) {
2944 ahd_outw(ahd
, WAITING_TID_HEAD
, scbid
);
2945 waiting_t
= ahd_inw(ahd
, WAITING_TID_TAIL
);
2946 if (waiting_t
== waiting_h
) {
2947 ahd_outw(ahd
, WAITING_TID_TAIL
, scbid
);
2948 next
= SCB_LIST_NULL
;
2950 ahd_set_scbptr(ahd
, waiting_h
);
2951 next
= ahd_inw_scbram(ahd
, SCB_NEXT2
);
2953 ahd_set_scbptr(ahd
, scbid
);
2954 ahd_outw(ahd
, SCB_NEXT2
, next
);
2956 ahd_set_scbptr(ahd
, saved_scbptr
);
2957 if (scb
->crc_retry_count
< AHD_MAX_LQ_CRC_ERRORS
) {
2958 if (SCB_IS_SILENT(scb
) == FALSE
) {
2959 ahd_print_path(ahd
, scb
);
2960 printk("Probable outgoing LQ CRC error. "
2961 "Retrying command\n");
2963 scb
->crc_retry_count
++;
2965 ahd_set_transaction_status(scb
, CAM_UNCOR_PARITY
);
2966 ahd_freeze_scb(scb
);
2967 ahd_freeze_devq(ahd
, scb
);
2969 /* Return unpausing the sequencer. */
2971 } else if ((ahd_inb(ahd
, PERRDIAG
) & PARITYERR
) != 0) {
2973 * Ignore what are really parity errors that
2974 * occur on the last REQ of a free running
2975 * clock prior to going busfree. Some drives
2976 * do not properly active negate just before
2977 * going busfree resulting in a parity glitch.
2979 ahd_outb(ahd
, CLRSINT1
, CLRSCSIPERR
|CLRBUSFREE
);
2981 if ((ahd_debug
& AHD_SHOW_MASKED_ERRORS
) != 0)
2982 printk("%s: Parity on last REQ detected "
2983 "during busfree phase.\n",
2986 /* Return unpausing the sequencer. */
2989 if (ahd
->src_mode
!= AHD_MODE_SCSI
) {
2993 scbid
= ahd_get_scbptr(ahd
);
2994 scb
= ahd_lookup_scb(ahd
, scbid
);
2995 ahd_print_path(ahd
, scb
);
2996 printk("Unexpected PKT busfree condition\n");
2997 ahd_dump_card_state(ahd
);
2998 ahd_abort_scbs(ahd
, SCB_GET_TARGET(ahd
, scb
), 'A',
2999 SCB_GET_LUN(scb
), SCB_GET_TAG(scb
),
3000 ROLE_INITIATOR
, CAM_UNEXP_BUSFREE
);
3002 /* Return restarting the sequencer. */
3005 printk("%s: Unexpected PKT busfree condition\n", ahd_name(ahd
));
3006 ahd_dump_card_state(ahd
);
3007 /* Restart the sequencer. */
3012 * Non-packetized unexpected or expected busfree.
3015 ahd_handle_nonpkt_busfree(struct ahd_softc
*ahd
)
3017 struct ahd_devinfo devinfo
;
3023 u_int initiator_role_id
;
3029 * Look at what phase we were last in. If its message out,
3030 * chances are pretty good that the busfree was in response
3031 * to one of our abort requests.
3033 lastphase
= ahd_inb(ahd
, LASTPHASE
);
3034 saved_scsiid
= ahd_inb(ahd
, SAVED_SCSIID
);
3035 saved_lun
= ahd_inb(ahd
, SAVED_LUN
);
3036 target
= SCSIID_TARGET(ahd
, saved_scsiid
);
3037 initiator_role_id
= SCSIID_OUR_ID(saved_scsiid
);
3038 ahd_compile_devinfo(&devinfo
, initiator_role_id
,
3039 target
, saved_lun
, 'A', ROLE_INITIATOR
);
3042 scbid
= ahd_get_scbptr(ahd
);
3043 scb
= ahd_lookup_scb(ahd
, scbid
);
3045 && (ahd_inb(ahd
, SEQ_FLAGS
) & NOT_IDENTIFIED
) != 0)
3048 ppr_busfree
= (ahd
->msg_flags
& MSG_FLAG_EXPECT_PPR_BUSFREE
) != 0;
3049 if (lastphase
== P_MESGOUT
) {
3052 tag
= SCB_LIST_NULL
;
3053 if (ahd_sent_msg(ahd
, AHDMSG_1B
, ABORT_TASK
, TRUE
)
3054 || ahd_sent_msg(ahd
, AHDMSG_1B
, ABORT_TASK_SET
, TRUE
)) {
3059 ahd_print_devinfo(ahd
, &devinfo
);
3060 printk("Abort for unidentified "
3061 "connection completed.\n");
3062 /* restart the sequencer. */
3065 sent_msg
= ahd
->msgout_buf
[ahd
->msgout_index
- 1];
3066 ahd_print_path(ahd
, scb
);
3067 printk("SCB %d - Abort%s Completed.\n",
3069 sent_msg
== ABORT_TASK
? "" : " Tag");
3071 if (sent_msg
== ABORT_TASK
)
3072 tag
= SCB_GET_TAG(scb
);
3074 if ((scb
->flags
& SCB_EXTERNAL_RESET
) != 0) {
3076 * This abort is in response to an
3077 * unexpected switch to command phase
3078 * for a packetized connection. Since
3079 * the identify message was never sent,
3080 * "saved lun" is 0. We really want to
3081 * abort only the SCB that encountered
3082 * this error, which could have a different
3083 * lun. The SCB will be retried so the OS
3084 * will see the UA after renegotiating to
3087 tag
= SCB_GET_TAG(scb
);
3088 saved_lun
= scb
->hscb
->lun
;
3090 found
= ahd_abort_scbs(ahd
, target
, 'A', saved_lun
,
3091 tag
, ROLE_INITIATOR
,
3093 printk("found == 0x%x\n", found
);
3095 } else if (ahd_sent_msg(ahd
, AHDMSG_1B
,
3096 TARGET_RESET
, TRUE
)) {
3097 ahd_handle_devreset(ahd
, &devinfo
, CAM_LUN_WILDCARD
,
3098 CAM_BDR_SENT
, "Bus Device Reset",
3099 /*verbose_level*/0);
3101 } else if (ahd_sent_msg(ahd
, AHDMSG_EXT
, EXTENDED_PPR
, FALSE
)
3102 && ppr_busfree
== 0) {
3103 struct ahd_initiator_tinfo
*tinfo
;
3104 struct ahd_tmode_tstate
*tstate
;
3109 * If the previous negotiation was packetized,
3110 * this could be because the device has been
3111 * reset without our knowledge. Force our
3112 * current negotiation to async and retry the
3113 * negotiation. Otherwise retry the command
3114 * with non-ppr negotiation.
3117 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
3118 printk("PPR negotiation rejected busfree.\n");
3120 tinfo
= ahd_fetch_transinfo(ahd
, devinfo
.channel
,
3122 devinfo
.target
, &tstate
);
3123 if ((tinfo
->curr
.ppr_options
& MSG_EXT_PPR_IU_REQ
)!=0) {
3124 ahd_set_width(ahd
, &devinfo
,
3125 MSG_EXT_WDTR_BUS_8_BIT
,
3128 ahd_set_syncrate(ahd
, &devinfo
,
3129 /*period*/0, /*offset*/0,
3134 * The expect PPR busfree handler below
3135 * will effect the retry and necessary
3139 tinfo
->curr
.transport_version
= 2;
3140 tinfo
->goal
.transport_version
= 2;
3141 tinfo
->goal
.ppr_options
= 0;
3144 * Remove any SCBs in the waiting
3145 * for selection queue that may
3146 * also be for this target so that
3147 * command ordering is preserved.
3149 ahd_freeze_devq(ahd
, scb
);
3150 ahd_qinfifo_requeue_tail(ahd
, scb
);
3154 } else if (ahd_sent_msg(ahd
, AHDMSG_EXT
, EXTENDED_WDTR
, FALSE
)
3155 && ppr_busfree
== 0) {
3157 * Negotiation Rejected. Go-narrow and
3161 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
3162 printk("WDTR negotiation rejected busfree.\n");
3164 ahd_set_width(ahd
, &devinfo
,
3165 MSG_EXT_WDTR_BUS_8_BIT
,
3166 AHD_TRANS_CUR
|AHD_TRANS_GOAL
,
3170 * Remove any SCBs in the waiting for
3171 * selection queue that may also be for
3172 * this target so that command ordering
3175 ahd_freeze_devq(ahd
, scb
);
3176 ahd_qinfifo_requeue_tail(ahd
, scb
);
3179 } else if (ahd_sent_msg(ahd
, AHDMSG_EXT
, EXTENDED_SDTR
, FALSE
)
3180 && ppr_busfree
== 0) {
3182 * Negotiation Rejected. Go-async and
3186 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
3187 printk("SDTR negotiation rejected busfree.\n");
3189 ahd_set_syncrate(ahd
, &devinfo
,
3190 /*period*/0, /*offset*/0,
3192 AHD_TRANS_CUR
|AHD_TRANS_GOAL
,
3196 * Remove any SCBs in the waiting for
3197 * selection queue that may also be for
3198 * this target so that command ordering
3201 ahd_freeze_devq(ahd
, scb
);
3202 ahd_qinfifo_requeue_tail(ahd
, scb
);
3205 } else if ((ahd
->msg_flags
& MSG_FLAG_EXPECT_IDE_BUSFREE
) != 0
3206 && ahd_sent_msg(ahd
, AHDMSG_1B
,
3207 INITIATOR_ERROR
, TRUE
)) {
3210 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
3211 printk("Expected IDE Busfree\n");
3214 } else if ((ahd
->msg_flags
& MSG_FLAG_EXPECT_QASREJ_BUSFREE
)
3215 && ahd_sent_msg(ahd
, AHDMSG_1B
,
3216 MESSAGE_REJECT
, TRUE
)) {
3219 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
3220 printk("Expected QAS Reject Busfree\n");
3227 * The busfree required flag is honored at the end of
3228 * the message phases. We check it last in case we
3229 * had to send some other message that caused a busfree.
3231 if (scb
!= NULL
&& printerror
!= 0
3232 && (lastphase
== P_MESGIN
|| lastphase
== P_MESGOUT
)
3233 && ((ahd
->msg_flags
& MSG_FLAG_EXPECT_PPR_BUSFREE
) != 0)) {
3235 ahd_freeze_devq(ahd
, scb
);
3236 ahd_set_transaction_status(scb
, CAM_REQUEUE_REQ
);
3237 ahd_freeze_scb(scb
);
3238 if ((ahd
->msg_flags
& MSG_FLAG_IU_REQ_CHANGED
) != 0) {
3239 ahd_abort_scbs(ahd
, SCB_GET_TARGET(ahd
, scb
),
3240 SCB_GET_CHANNEL(ahd
, scb
),
3241 SCB_GET_LUN(scb
), SCB_LIST_NULL
,
3242 ROLE_INITIATOR
, CAM_REQ_ABORTED
);
3245 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
3246 printk("PPR Negotiation Busfree.\n");
3252 if (printerror
!= 0) {
3259 if ((scb
->hscb
->control
& TAG_ENB
) != 0)
3260 tag
= SCB_GET_TAG(scb
);
3262 tag
= SCB_LIST_NULL
;
3263 ahd_print_path(ahd
, scb
);
3264 aborted
= ahd_abort_scbs(ahd
, target
, 'A',
3265 SCB_GET_LUN(scb
), tag
,
3270 * We had not fully identified this connection,
3271 * so we cannot abort anything.
3273 printk("%s: ", ahd_name(ahd
));
3275 printk("Unexpected busfree %s, %d SCBs aborted, "
3276 "PRGMCNT == 0x%x\n",
3277 ahd_lookup_phase_entry(lastphase
)->phasemsg
,
3279 ahd_inw(ahd
, PRGMCNT
));
3280 ahd_dump_card_state(ahd
);
3281 if (lastphase
!= P_BUSFREE
)
3282 ahd_force_renegotiation(ahd
, &devinfo
);
3284 /* Always restart the sequencer. */
3289 ahd_handle_proto_violation(struct ahd_softc
*ahd
)
3291 struct ahd_devinfo devinfo
;
3299 ahd_fetch_devinfo(ahd
, &devinfo
);
3300 scbid
= ahd_get_scbptr(ahd
);
3301 scb
= ahd_lookup_scb(ahd
, scbid
);
3302 seq_flags
= ahd_inb(ahd
, SEQ_FLAGS
);
3303 curphase
= ahd_inb(ahd
, SCSISIGI
) & PHASE_MASK
;
3304 lastphase
= ahd_inb(ahd
, LASTPHASE
);
3305 if ((seq_flags
& NOT_IDENTIFIED
) != 0) {
3308 * The reconnecting target either did not send an
3309 * identify message, or did, but we didn't find an SCB
3312 ahd_print_devinfo(ahd
, &devinfo
);
3313 printk("Target did not send an IDENTIFY message. "
3314 "LASTPHASE = 0x%x.\n", lastphase
);
3316 } else if (scb
== NULL
) {
3318 * We don't seem to have an SCB active for this
3319 * transaction. Print an error and reset the bus.
3321 ahd_print_devinfo(ahd
, &devinfo
);
3322 printk("No SCB found during protocol violation\n");
3323 goto proto_violation_reset
;
3325 ahd_set_transaction_status(scb
, CAM_SEQUENCE_FAIL
);
3326 if ((seq_flags
& NO_CDB_SENT
) != 0) {
3327 ahd_print_path(ahd
, scb
);
3328 printk("No or incomplete CDB sent to device.\n");
3329 } else if ((ahd_inb_scbram(ahd
, SCB_CONTROL
)
3330 & STATUS_RCVD
) == 0) {
3332 * The target never bothered to provide status to
3333 * us prior to completing the command. Since we don't
3334 * know the disposition of this command, we must attempt
3335 * to abort it. Assert ATN and prepare to send an abort
3338 ahd_print_path(ahd
, scb
);
3339 printk("Completed command without status.\n");
3341 ahd_print_path(ahd
, scb
);
3342 printk("Unknown protocol violation.\n");
3343 ahd_dump_card_state(ahd
);
3346 if ((lastphase
& ~P_DATAIN_DT
) == 0
3347 || lastphase
== P_COMMAND
) {
3348 proto_violation_reset
:
3350 * Target either went directly to data
3351 * phase or didn't respond to our ATN.
3352 * The only safe thing to do is to blow
3353 * it away with a bus reset.
3355 found
= ahd_reset_channel(ahd
, 'A', TRUE
);
3356 printk("%s: Issued Channel %c Bus Reset. "
3357 "%d SCBs aborted\n", ahd_name(ahd
), 'A', found
);
3360 * Leave the selection hardware off in case
3361 * this abort attempt will affect yet to
3364 ahd_outb(ahd
, SCSISEQ0
,
3365 ahd_inb(ahd
, SCSISEQ0
) & ~ENSELO
);
3366 ahd_assert_atn(ahd
);
3367 ahd_outb(ahd
, MSG_OUT
, HOST_MSG
);
3369 ahd_print_devinfo(ahd
, &devinfo
);
3370 ahd
->msgout_buf
[0] = ABORT_TASK
;
3371 ahd
->msgout_len
= 1;
3372 ahd
->msgout_index
= 0;
3373 ahd
->msg_type
= MSG_TYPE_INITIATOR_MSGOUT
;
3375 ahd_print_path(ahd
, scb
);
3376 scb
->flags
|= SCB_ABORT
;
3378 printk("Protocol violation %s. Attempting to abort.\n",
3379 ahd_lookup_phase_entry(curphase
)->phasemsg
);
3384 * Force renegotiation to occur the next time we initiate
3385 * a command to the current device.
3388 ahd_force_renegotiation(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
)
3390 struct ahd_initiator_tinfo
*targ_info
;
3391 struct ahd_tmode_tstate
*tstate
;
3394 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0) {
3395 ahd_print_devinfo(ahd
, devinfo
);
3396 printk("Forcing renegotiation\n");
3399 targ_info
= ahd_fetch_transinfo(ahd
,
3401 devinfo
->our_scsiid
,
3404 ahd_update_neg_request(ahd
, devinfo
, tstate
,
3405 targ_info
, AHD_NEG_IF_NON_ASYNC
);
3408 #define AHD_MAX_STEPS 2000
3410 ahd_clear_critical_section(struct ahd_softc
*ahd
)
3412 ahd_mode_state saved_modes
;
3424 if (ahd
->num_critical_sections
== 0)
3437 saved_modes
= ahd_save_modes(ahd
);
3443 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
3444 seqaddr
= ahd_inw(ahd
, CURADDR
);
3446 cs
= ahd
->critical_sections
;
3447 for (i
= 0; i
< ahd
->num_critical_sections
; i
++, cs
++) {
3448 if (cs
->begin
< seqaddr
&& cs
->end
>= seqaddr
)
3452 if (i
== ahd
->num_critical_sections
)
3455 if (steps
> AHD_MAX_STEPS
) {
3456 printk("%s: Infinite loop in critical section\n"
3457 "%s: First Instruction 0x%x now 0x%x\n",
3458 ahd_name(ahd
), ahd_name(ahd
), first_instr
,
3460 ahd_dump_card_state(ahd
);
3461 panic("critical section loop");
3466 if ((ahd_debug
& AHD_SHOW_MISC
) != 0)
3467 printk("%s: Single stepping at 0x%x\n", ahd_name(ahd
),
3470 if (stepping
== FALSE
) {
3472 first_instr
= seqaddr
;
3473 ahd_set_modes(ahd
, AHD_MODE_CFG
, AHD_MODE_CFG
);
3474 simode0
= ahd_inb(ahd
, SIMODE0
);
3475 simode3
= ahd_inb(ahd
, SIMODE3
);
3476 lqimode0
= ahd_inb(ahd
, LQIMODE0
);
3477 lqimode1
= ahd_inb(ahd
, LQIMODE1
);
3478 lqomode0
= ahd_inb(ahd
, LQOMODE0
);
3479 lqomode1
= ahd_inb(ahd
, LQOMODE1
);
3480 ahd_outb(ahd
, SIMODE0
, 0);
3481 ahd_outb(ahd
, SIMODE3
, 0);
3482 ahd_outb(ahd
, LQIMODE0
, 0);
3483 ahd_outb(ahd
, LQIMODE1
, 0);
3484 ahd_outb(ahd
, LQOMODE0
, 0);
3485 ahd_outb(ahd
, LQOMODE1
, 0);
3486 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
3487 simode1
= ahd_inb(ahd
, SIMODE1
);
3489 * We don't clear ENBUSFREE. Unfortunately
3490 * we cannot re-enable busfree detection within
3491 * the current connection, so we must leave it
3492 * on while single stepping.
3494 ahd_outb(ahd
, SIMODE1
, simode1
& ENBUSFREE
);
3495 ahd_outb(ahd
, SEQCTL0
, ahd_inb(ahd
, SEQCTL0
) | STEP
);
3498 ahd_outb(ahd
, CLRSINT1
, CLRBUSFREE
);
3499 ahd_outb(ahd
, CLRINT
, CLRSCSIINT
);
3500 ahd_set_modes(ahd
, ahd
->saved_src_mode
, ahd
->saved_dst_mode
);
3501 ahd_outb(ahd
, HCNTRL
, ahd
->unpause
);
3502 while (!ahd_is_paused(ahd
))
3504 ahd_update_modes(ahd
);
3507 ahd_set_modes(ahd
, AHD_MODE_CFG
, AHD_MODE_CFG
);
3508 ahd_outb(ahd
, SIMODE0
, simode0
);
3509 ahd_outb(ahd
, SIMODE3
, simode3
);
3510 ahd_outb(ahd
, LQIMODE0
, lqimode0
);
3511 ahd_outb(ahd
, LQIMODE1
, lqimode1
);
3512 ahd_outb(ahd
, LQOMODE0
, lqomode0
);
3513 ahd_outb(ahd
, LQOMODE1
, lqomode1
);
3514 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
3515 ahd_outb(ahd
, SEQCTL0
, ahd_inb(ahd
, SEQCTL0
) & ~STEP
);
3516 ahd_outb(ahd
, SIMODE1
, simode1
);
3518 * SCSIINT seems to glitch occasionally when
3519 * the interrupt masks are restored. Clear SCSIINT
3520 * one more time so that only persistent errors
3521 * are seen as a real interrupt.
3523 ahd_outb(ahd
, CLRINT
, CLRSCSIINT
);
3525 ahd_restore_modes(ahd
, saved_modes
);
3529 * Clear any pending interrupt status.
3532 ahd_clear_intstat(struct ahd_softc
*ahd
)
3534 AHD_ASSERT_MODES(ahd
, ~(AHD_MODE_UNKNOWN_MSK
|AHD_MODE_CFG_MSK
),
3535 ~(AHD_MODE_UNKNOWN_MSK
|AHD_MODE_CFG_MSK
));
3536 /* Clear any interrupt conditions this may have caused */
3537 ahd_outb(ahd
, CLRLQIINT0
, CLRLQIATNQAS
|CLRLQICRCT1
|CLRLQICRCT2
3538 |CLRLQIBADLQT
|CLRLQIATNLQ
|CLRLQIATNCMD
);
3539 ahd_outb(ahd
, CLRLQIINT1
, CLRLQIPHASE_LQ
|CLRLQIPHASE_NLQ
|CLRLIQABORT
3540 |CLRLQICRCI_LQ
|CLRLQICRCI_NLQ
|CLRLQIBADLQI
3541 |CLRLQIOVERI_LQ
|CLRLQIOVERI_NLQ
|CLRNONPACKREQ
);
3542 ahd_outb(ahd
, CLRLQOINT0
, CLRLQOTARGSCBPERR
|CLRLQOSTOPT2
|CLRLQOATNLQ
3543 |CLRLQOATNPKT
|CLRLQOTCRC
);
3544 ahd_outb(ahd
, CLRLQOINT1
, CLRLQOINITSCBPERR
|CLRLQOSTOPI2
|CLRLQOBADQAS
3545 |CLRLQOBUSFREE
|CLRLQOPHACHGINPKT
);
3546 if ((ahd
->bugs
& AHD_CLRLQO_AUTOCLR_BUG
) != 0) {
3547 ahd_outb(ahd
, CLRLQOINT0
, 0);
3548 ahd_outb(ahd
, CLRLQOINT1
, 0);
3550 ahd_outb(ahd
, CLRSINT3
, CLRNTRAMPERR
|CLROSRAMPERR
);
3551 ahd_outb(ahd
, CLRSINT1
, CLRSELTIMEO
|CLRATNO
|CLRSCSIRSTI
3552 |CLRBUSFREE
|CLRSCSIPERR
|CLRREQINIT
);
3553 ahd_outb(ahd
, CLRSINT0
, CLRSELDO
|CLRSELDI
|CLRSELINGO
3554 |CLRIOERR
|CLROVERRUN
);
3555 ahd_outb(ahd
, CLRINT
, CLRSCSIINT
);
3558 /**************************** Debugging Routines ******************************/
3560 uint32_t ahd_debug
= AHD_DEBUG_OPTS
;
3565 ahd_print_scb(struct scb
*scb
)
3567 struct hardware_scb
*hscb
;
3571 printk("scb:%p control:0x%x scsiid:0x%x lun:%d cdb_len:%d\n",
3577 printk("Shared Data: ");
3578 for (i
= 0; i
< sizeof(hscb
->shared_data
.idata
.cdb
); i
++)
3579 printk("%#02x", hscb
->shared_data
.idata
.cdb
[i
]);
3580 printk(" dataptr:%#x%x datacnt:%#x sgptr:%#x tag:%#x\n",
3581 (uint32_t)((ahd_le64toh(hscb
->dataptr
) >> 32) & 0xFFFFFFFF),
3582 (uint32_t)(ahd_le64toh(hscb
->dataptr
) & 0xFFFFFFFF),
3583 ahd_le32toh(hscb
->datacnt
),
3584 ahd_le32toh(hscb
->sgptr
),
3586 ahd_dump_sglist(scb
);
3590 /************************* Transfer Negotiation *******************************/
3592 * Allocate per target mode instance (ID we respond to as a target)
3593 * transfer negotiation data structures.
3595 static struct ahd_tmode_tstate
*
3596 ahd_alloc_tstate(struct ahd_softc
*ahd
, u_int scsi_id
, char channel
)
3598 struct ahd_tmode_tstate
*master_tstate
;
3599 struct ahd_tmode_tstate
*tstate
;
3602 master_tstate
= ahd
->enabled_targets
[ahd
->our_id
];
3603 if (ahd
->enabled_targets
[scsi_id
] != NULL
3604 && ahd
->enabled_targets
[scsi_id
] != master_tstate
)
3605 panic("%s: ahd_alloc_tstate - Target already allocated",
3607 tstate
= kmalloc(sizeof(*tstate
), GFP_ATOMIC
);
3612 * If we have allocated a master tstate, copy user settings from
3613 * the master tstate (taken from SRAM or the EEPROM) for this
3614 * channel, but reset our current and goal settings to async/narrow
3615 * until an initiator talks to us.
3617 if (master_tstate
!= NULL
) {
3618 memcpy(tstate
, master_tstate
, sizeof(*tstate
));
3619 memset(tstate
->enabled_luns
, 0, sizeof(tstate
->enabled_luns
));
3620 for (i
= 0; i
< 16; i
++) {
3621 memset(&tstate
->transinfo
[i
].curr
, 0,
3622 sizeof(tstate
->transinfo
[i
].curr
));
3623 memset(&tstate
->transinfo
[i
].goal
, 0,
3624 sizeof(tstate
->transinfo
[i
].goal
));
3627 memset(tstate
, 0, sizeof(*tstate
));
3628 ahd
->enabled_targets
[scsi_id
] = tstate
;
3632 #ifdef AHD_TARGET_MODE
3634 * Free per target mode instance (ID we respond to as a target)
3635 * transfer negotiation data structures.
3638 ahd_free_tstate(struct ahd_softc
*ahd
, u_int scsi_id
, char channel
, int force
)
3640 struct ahd_tmode_tstate
*tstate
;
3643 * Don't clean up our "master" tstate.
3644 * It has our default user settings.
3646 if (scsi_id
== ahd
->our_id
3650 tstate
= ahd
->enabled_targets
[scsi_id
];
3652 ahd
->enabled_targets
[scsi_id
] = NULL
;
3657 * Called when we have an active connection to a target on the bus,
3658 * this function finds the nearest period to the input period limited
3659 * by the capabilities of the bus connectivity of and sync settings for
3663 ahd_devlimited_syncrate(struct ahd_softc
*ahd
,
3664 struct ahd_initiator_tinfo
*tinfo
,
3665 u_int
*period
, u_int
*ppr_options
, role_t role
)
3667 struct ahd_transinfo
*transinfo
;
3670 if ((ahd_inb(ahd
, SBLKCTL
) & ENAB40
) != 0
3671 && (ahd_inb(ahd
, SSTAT2
) & EXP_ACTIVE
) == 0) {
3672 maxsync
= AHD_SYNCRATE_PACED
;
3674 maxsync
= AHD_SYNCRATE_ULTRA
;
3675 /* Can't do DT related options on an SE bus */
3676 *ppr_options
&= MSG_EXT_PPR_QAS_REQ
;
3679 * Never allow a value higher than our current goal
3680 * period otherwise we may allow a target initiated
3681 * negotiation to go above the limit as set by the
3682 * user. In the case of an initiator initiated
3683 * sync negotiation, we limit based on the user
3684 * setting. This allows the system to still accept
3685 * incoming negotiations even if target initiated
3686 * negotiation is not performed.
3688 if (role
== ROLE_TARGET
)
3689 transinfo
= &tinfo
->user
;
3691 transinfo
= &tinfo
->goal
;
3692 *ppr_options
&= (transinfo
->ppr_options
|MSG_EXT_PPR_PCOMP_EN
);
3693 if (transinfo
->width
== MSG_EXT_WDTR_BUS_8_BIT
) {
3694 maxsync
= max(maxsync
, (u_int
)AHD_SYNCRATE_ULTRA2
);
3695 *ppr_options
&= ~MSG_EXT_PPR_DT_REQ
;
3697 if (transinfo
->period
== 0) {
3701 *period
= max(*period
, (u_int
)transinfo
->period
);
3702 ahd_find_syncrate(ahd
, period
, ppr_options
, maxsync
);
3707 * Look up the valid period to SCSIRATE conversion in our table.
3708 * Return the period and offset that should be sent to the target
3709 * if this was the beginning of an SDTR.
3712 ahd_find_syncrate(struct ahd_softc
*ahd
, u_int
*period
,
3713 u_int
*ppr_options
, u_int maxsync
)
3715 if (*period
< maxsync
)
3718 if ((*ppr_options
& MSG_EXT_PPR_DT_REQ
) != 0
3719 && *period
> AHD_SYNCRATE_MIN_DT
)
3720 *ppr_options
&= ~MSG_EXT_PPR_DT_REQ
;
3722 if (*period
> AHD_SYNCRATE_MIN
)
3725 /* Honor PPR option conformance rules. */
3726 if (*period
> AHD_SYNCRATE_PACED
)
3727 *ppr_options
&= ~MSG_EXT_PPR_RTI
;
3729 if ((*ppr_options
& MSG_EXT_PPR_IU_REQ
) == 0)
3730 *ppr_options
&= (MSG_EXT_PPR_DT_REQ
|MSG_EXT_PPR_QAS_REQ
);
3732 if ((*ppr_options
& MSG_EXT_PPR_DT_REQ
) == 0)
3733 *ppr_options
&= MSG_EXT_PPR_QAS_REQ
;
3735 /* Skip all PACED only entries if IU is not available */
3736 if ((*ppr_options
& MSG_EXT_PPR_IU_REQ
) == 0
3737 && *period
< AHD_SYNCRATE_DT
)
3738 *period
= AHD_SYNCRATE_DT
;
3740 /* Skip all DT only entries if DT is not available */
3741 if ((*ppr_options
& MSG_EXT_PPR_DT_REQ
) == 0
3742 && *period
< AHD_SYNCRATE_ULTRA2
)
3743 *period
= AHD_SYNCRATE_ULTRA2
;
3747 * Truncate the given synchronous offset to a value the
3748 * current adapter type and syncrate are capable of.
3751 ahd_validate_offset(struct ahd_softc
*ahd
,
3752 struct ahd_initiator_tinfo
*tinfo
,
3753 u_int period
, u_int
*offset
, int wide
,
3758 /* Limit offset to what we can do */
3761 else if (period
<= AHD_SYNCRATE_PACED
) {
3762 if ((ahd
->bugs
& AHD_PACED_NEGTABLE_BUG
) != 0)
3763 maxoffset
= MAX_OFFSET_PACED_BUG
;
3765 maxoffset
= MAX_OFFSET_PACED
;
3767 maxoffset
= MAX_OFFSET_NON_PACED
;
3768 *offset
= min(*offset
, maxoffset
);
3769 if (tinfo
!= NULL
) {
3770 if (role
== ROLE_TARGET
)
3771 *offset
= min(*offset
, (u_int
)tinfo
->user
.offset
);
3773 *offset
= min(*offset
, (u_int
)tinfo
->goal
.offset
);
3778 * Truncate the given transfer width parameter to a value the
3779 * current adapter type is capable of.
3782 ahd_validate_width(struct ahd_softc
*ahd
, struct ahd_initiator_tinfo
*tinfo
,
3783 u_int
*bus_width
, role_t role
)
3785 switch (*bus_width
) {
3787 if (ahd
->features
& AHD_WIDE
) {
3789 *bus_width
= MSG_EXT_WDTR_BUS_16_BIT
;
3793 case MSG_EXT_WDTR_BUS_8_BIT
:
3794 *bus_width
= MSG_EXT_WDTR_BUS_8_BIT
;
3797 if (tinfo
!= NULL
) {
3798 if (role
== ROLE_TARGET
)
3799 *bus_width
= min((u_int
)tinfo
->user
.width
, *bus_width
);
3801 *bus_width
= min((u_int
)tinfo
->goal
.width
, *bus_width
);
3806 * Update the bitmask of targets for which the controller should
3807 * negotiate with at the next convenient opportunity. This currently
3808 * means the next time we send the initial identify messages for
3809 * a new transaction.
3812 ahd_update_neg_request(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
,
3813 struct ahd_tmode_tstate
*tstate
,
3814 struct ahd_initiator_tinfo
*tinfo
, ahd_neg_type neg_type
)
3816 u_int auto_negotiate_orig
;
3818 auto_negotiate_orig
= tstate
->auto_negotiate
;
3819 if (neg_type
== AHD_NEG_ALWAYS
) {
3821 * Force our "current" settings to be
3822 * unknown so that unless a bus reset
3823 * occurs the need to renegotiate is
3824 * recorded persistently.
3826 if ((ahd
->features
& AHD_WIDE
) != 0)
3827 tinfo
->curr
.width
= AHD_WIDTH_UNKNOWN
;
3828 tinfo
->curr
.period
= AHD_PERIOD_UNKNOWN
;
3829 tinfo
->curr
.offset
= AHD_OFFSET_UNKNOWN
;
3831 if (tinfo
->curr
.period
!= tinfo
->goal
.period
3832 || tinfo
->curr
.width
!= tinfo
->goal
.width
3833 || tinfo
->curr
.offset
!= tinfo
->goal
.offset
3834 || tinfo
->curr
.ppr_options
!= tinfo
->goal
.ppr_options
3835 || (neg_type
== AHD_NEG_IF_NON_ASYNC
3836 && (tinfo
->goal
.offset
!= 0
3837 || tinfo
->goal
.width
!= MSG_EXT_WDTR_BUS_8_BIT
3838 || tinfo
->goal
.ppr_options
!= 0)))
3839 tstate
->auto_negotiate
|= devinfo
->target_mask
;
3841 tstate
->auto_negotiate
&= ~devinfo
->target_mask
;
3843 return (auto_negotiate_orig
!= tstate
->auto_negotiate
);
3847 * Update the user/goal/curr tables of synchronous negotiation
3848 * parameters as well as, in the case of a current or active update,
3849 * any data structures on the host controller. In the case of an
3850 * active update, the specified target is currently talking to us on
3851 * the bus, so the transfer parameter update must take effect
3855 ahd_set_syncrate(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
,
3856 u_int period
, u_int offset
, u_int ppr_options
,
3857 u_int type
, int paused
)
3859 struct ahd_initiator_tinfo
*tinfo
;
3860 struct ahd_tmode_tstate
*tstate
;
3867 active
= (type
& AHD_TRANS_ACTIVE
) == AHD_TRANS_ACTIVE
;
3870 if (period
== 0 || offset
== 0) {
3875 tinfo
= ahd_fetch_transinfo(ahd
, devinfo
->channel
, devinfo
->our_scsiid
,
3876 devinfo
->target
, &tstate
);
3878 if ((type
& AHD_TRANS_USER
) != 0) {
3879 tinfo
->user
.period
= period
;
3880 tinfo
->user
.offset
= offset
;
3881 tinfo
->user
.ppr_options
= ppr_options
;
3884 if ((type
& AHD_TRANS_GOAL
) != 0) {
3885 tinfo
->goal
.period
= period
;
3886 tinfo
->goal
.offset
= offset
;
3887 tinfo
->goal
.ppr_options
= ppr_options
;
3890 old_period
= tinfo
->curr
.period
;
3891 old_offset
= tinfo
->curr
.offset
;
3892 old_ppr
= tinfo
->curr
.ppr_options
;
3894 if ((type
& AHD_TRANS_CUR
) != 0
3895 && (old_period
!= period
3896 || old_offset
!= offset
3897 || old_ppr
!= ppr_options
)) {
3901 tinfo
->curr
.period
= period
;
3902 tinfo
->curr
.offset
= offset
;
3903 tinfo
->curr
.ppr_options
= ppr_options
;
3905 ahd_send_async(ahd
, devinfo
->channel
, devinfo
->target
,
3906 CAM_LUN_WILDCARD
, AC_TRANSFER_NEG
);
3911 printk("%s: target %d synchronous with "
3912 "period = 0x%x, offset = 0x%x",
3913 ahd_name(ahd
), devinfo
->target
,
3916 if ((ppr_options
& MSG_EXT_PPR_RD_STRM
) != 0) {
3920 if ((ppr_options
& MSG_EXT_PPR_DT_REQ
) != 0) {
3921 printk("%s", options
? "|DT" : "(DT");
3924 if ((ppr_options
& MSG_EXT_PPR_IU_REQ
) != 0) {
3925 printk("%s", options
? "|IU" : "(IU");
3928 if ((ppr_options
& MSG_EXT_PPR_RTI
) != 0) {
3929 printk("%s", options
? "|RTI" : "(RTI");
3932 if ((ppr_options
& MSG_EXT_PPR_QAS_REQ
) != 0) {
3933 printk("%s", options
? "|QAS" : "(QAS");
3941 printk("%s: target %d using "
3942 "asynchronous transfers%s\n",
3943 ahd_name(ahd
), devinfo
->target
,
3944 (ppr_options
& MSG_EXT_PPR_QAS_REQ
) != 0
3950 * Always refresh the neg-table to handle the case of the
3951 * sequencer setting the ENATNO bit for a MK_MESSAGE request.
3952 * We will always renegotiate in that case if this is a
3953 * packetized request. Also manage the busfree expected flag
3954 * from this common routine so that we catch changes due to
3955 * WDTR or SDTR messages.
3957 if ((type
& AHD_TRANS_CUR
) != 0) {
3960 ahd_update_neg_table(ahd
, devinfo
, &tinfo
->curr
);
3963 if (ahd
->msg_type
!= MSG_TYPE_NONE
) {
3964 if ((old_ppr
& MSG_EXT_PPR_IU_REQ
)
3965 != (ppr_options
& MSG_EXT_PPR_IU_REQ
)) {
3967 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0) {
3968 ahd_print_devinfo(ahd
, devinfo
);
3969 printk("Expecting IU Change busfree\n");
3972 ahd
->msg_flags
|= MSG_FLAG_EXPECT_PPR_BUSFREE
3973 | MSG_FLAG_IU_REQ_CHANGED
;
3975 if ((old_ppr
& MSG_EXT_PPR_IU_REQ
) != 0) {
3977 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
3978 printk("PPR with IU_REQ outstanding\n");
3980 ahd
->msg_flags
|= MSG_FLAG_EXPECT_PPR_BUSFREE
;
3985 update_needed
+= ahd_update_neg_request(ahd
, devinfo
, tstate
,
3986 tinfo
, AHD_NEG_TO_GOAL
);
3988 if (update_needed
&& active
)
3989 ahd_update_pending_scbs(ahd
);
3993 * Update the user/goal/curr tables of wide negotiation
3994 * parameters as well as, in the case of a current or active update,
3995 * any data structures on the host controller. In the case of an
3996 * active update, the specified target is currently talking to us on
3997 * the bus, so the transfer parameter update must take effect
4001 ahd_set_width(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
,
4002 u_int width
, u_int type
, int paused
)
4004 struct ahd_initiator_tinfo
*tinfo
;
4005 struct ahd_tmode_tstate
*tstate
;
4010 active
= (type
& AHD_TRANS_ACTIVE
) == AHD_TRANS_ACTIVE
;
4012 tinfo
= ahd_fetch_transinfo(ahd
, devinfo
->channel
, devinfo
->our_scsiid
,
4013 devinfo
->target
, &tstate
);
4015 if ((type
& AHD_TRANS_USER
) != 0)
4016 tinfo
->user
.width
= width
;
4018 if ((type
& AHD_TRANS_GOAL
) != 0)
4019 tinfo
->goal
.width
= width
;
4021 oldwidth
= tinfo
->curr
.width
;
4022 if ((type
& AHD_TRANS_CUR
) != 0 && oldwidth
!= width
) {
4026 tinfo
->curr
.width
= width
;
4027 ahd_send_async(ahd
, devinfo
->channel
, devinfo
->target
,
4028 CAM_LUN_WILDCARD
, AC_TRANSFER_NEG
);
4030 printk("%s: target %d using %dbit transfers\n",
4031 ahd_name(ahd
), devinfo
->target
,
4032 8 * (0x01 << width
));
4036 if ((type
& AHD_TRANS_CUR
) != 0) {
4039 ahd_update_neg_table(ahd
, devinfo
, &tinfo
->curr
);
4044 update_needed
+= ahd_update_neg_request(ahd
, devinfo
, tstate
,
4045 tinfo
, AHD_NEG_TO_GOAL
);
4046 if (update_needed
&& active
)
4047 ahd_update_pending_scbs(ahd
);
4052 * Update the current state of tagged queuing for a given target.
4055 ahd_set_tags(struct ahd_softc
*ahd
, struct scsi_cmnd
*cmd
,
4056 struct ahd_devinfo
*devinfo
, ahd_queue_alg alg
)
4058 struct scsi_device
*sdev
= cmd
->device
;
4060 ahd_platform_set_tags(ahd
, sdev
, devinfo
, alg
);
4061 ahd_send_async(ahd
, devinfo
->channel
, devinfo
->target
,
4062 devinfo
->lun
, AC_TRANSFER_NEG
);
4066 ahd_update_neg_table(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
,
4067 struct ahd_transinfo
*tinfo
)
4069 ahd_mode_state saved_modes
;
4074 u_int saved_negoaddr
;
4075 uint8_t iocell_opts
[sizeof(ahd
->iocell_opts
)];
4077 saved_modes
= ahd_save_modes(ahd
);
4078 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
4080 saved_negoaddr
= ahd_inb(ahd
, NEGOADDR
);
4081 ahd_outb(ahd
, NEGOADDR
, devinfo
->target
);
4082 period
= tinfo
->period
;
4083 offset
= tinfo
->offset
;
4084 memcpy(iocell_opts
, ahd
->iocell_opts
, sizeof(ahd
->iocell_opts
));
4085 ppr_opts
= tinfo
->ppr_options
& (MSG_EXT_PPR_QAS_REQ
|MSG_EXT_PPR_DT_REQ
4086 |MSG_EXT_PPR_IU_REQ
|MSG_EXT_PPR_RTI
);
4089 period
= AHD_SYNCRATE_ASYNC
;
4090 if (period
== AHD_SYNCRATE_160
) {
4092 if ((ahd
->bugs
& AHD_PACED_NEGTABLE_BUG
) != 0) {
4094 * When the SPI4 spec was finalized, PACE transfers
4095 * was not made a configurable option in the PPR
4096 * message. Instead it is assumed to be enabled for
4097 * any syncrate faster than 80MHz. Nevertheless,
4098 * Harpoon2A4 allows this to be configurable.
4100 * Harpoon2A4 also assumes at most 2 data bytes per
4101 * negotiated REQ/ACK offset. Paced transfers take
4102 * 4, so we must adjust our offset.
4104 ppr_opts
|= PPROPT_PACE
;
4108 * Harpoon2A assumed that there would be a
4109 * fallback rate between 160MHz and 80MHz,
4110 * so 7 is used as the period factor rather
4111 * than 8 for 160MHz.
4113 period
= AHD_SYNCRATE_REVA_160
;
4115 if ((tinfo
->ppr_options
& MSG_EXT_PPR_PCOMP_EN
) == 0)
4116 iocell_opts
[AHD_PRECOMP_SLEW_INDEX
] &=
4120 * Precomp should be disabled for non-paced transfers.
4122 iocell_opts
[AHD_PRECOMP_SLEW_INDEX
] &= ~AHD_PRECOMP_MASK
;
4124 if ((ahd
->features
& AHD_NEW_IOCELL_OPTS
) != 0
4125 && (ppr_opts
& MSG_EXT_PPR_DT_REQ
) != 0
4126 && (ppr_opts
& MSG_EXT_PPR_IU_REQ
) == 0) {
4128 * Slow down our CRC interval to be
4129 * compatible with non-packetized
4130 * U160 devices that can't handle a
4131 * CRC at full speed.
4133 con_opts
|= ENSLOWCRC
;
4136 if ((ahd
->bugs
& AHD_PACED_NEGTABLE_BUG
) != 0) {
4138 * On H2A4, revert to a slower slewrate
4139 * on non-paced transfers.
4141 iocell_opts
[AHD_PRECOMP_SLEW_INDEX
] &=
4146 ahd_outb(ahd
, ANNEXCOL
, AHD_ANNEXCOL_PRECOMP_SLEW
);
4147 ahd_outb(ahd
, ANNEXDAT
, iocell_opts
[AHD_PRECOMP_SLEW_INDEX
]);
4148 ahd_outb(ahd
, ANNEXCOL
, AHD_ANNEXCOL_AMPLITUDE
);
4149 ahd_outb(ahd
, ANNEXDAT
, iocell_opts
[AHD_AMPLITUDE_INDEX
]);
4151 ahd_outb(ahd
, NEGPERIOD
, period
);
4152 ahd_outb(ahd
, NEGPPROPTS
, ppr_opts
);
4153 ahd_outb(ahd
, NEGOFFSET
, offset
);
4155 if (tinfo
->width
== MSG_EXT_WDTR_BUS_16_BIT
)
4156 con_opts
|= WIDEXFER
;
4159 * Slow down our CRC interval to be
4160 * compatible with packetized U320 devices
4161 * that can't handle a CRC at full speed
4163 if (ahd
->features
& AHD_AIC79XXB_SLOWCRC
) {
4164 con_opts
|= ENSLOWCRC
;
4168 * During packetized transfers, the target will
4169 * give us the opportunity to send command packets
4170 * without us asserting attention.
4172 if ((tinfo
->ppr_options
& MSG_EXT_PPR_IU_REQ
) == 0)
4173 con_opts
|= ENAUTOATNO
;
4174 ahd_outb(ahd
, NEGCONOPTS
, con_opts
);
4175 ahd_outb(ahd
, NEGOADDR
, saved_negoaddr
);
4176 ahd_restore_modes(ahd
, saved_modes
);
4180 * When the transfer settings for a connection change, setup for
4181 * negotiation in pending SCBs to effect the change as quickly as
4182 * possible. We also cancel any negotiations that are scheduled
4183 * for inflight SCBs that have not been started yet.
4186 ahd_update_pending_scbs(struct ahd_softc
*ahd
)
4188 struct scb
*pending_scb
;
4189 int pending_scb_count
;
4192 ahd_mode_state saved_modes
;
4195 * Traverse the pending SCB list and ensure that all of the
4196 * SCBs there have the proper settings. We can only safely
4197 * clear the negotiation required flag (setting requires the
4198 * execution queue to be modified) and this is only possible
4199 * if we are not already attempting to select out for this
4200 * SCB. For this reason, all callers only call this routine
4201 * if we are changing the negotiation settings for the currently
4202 * active transaction on the bus.
4204 pending_scb_count
= 0;
4205 LIST_FOREACH(pending_scb
, &ahd
->pending_scbs
, pending_links
) {
4206 struct ahd_devinfo devinfo
;
4207 struct ahd_tmode_tstate
*tstate
;
4209 ahd_scb_devinfo(ahd
, &devinfo
, pending_scb
);
4210 ahd_fetch_transinfo(ahd
, devinfo
.channel
, devinfo
.our_scsiid
,
4211 devinfo
.target
, &tstate
);
4212 if ((tstate
->auto_negotiate
& devinfo
.target_mask
) == 0
4213 && (pending_scb
->flags
& SCB_AUTO_NEGOTIATE
) != 0) {
4214 pending_scb
->flags
&= ~SCB_AUTO_NEGOTIATE
;
4215 pending_scb
->hscb
->control
&= ~MK_MESSAGE
;
4217 ahd_sync_scb(ahd
, pending_scb
,
4218 BUS_DMASYNC_PREREAD
|BUS_DMASYNC_PREWRITE
);
4219 pending_scb_count
++;
4222 if (pending_scb_count
== 0)
4225 if (ahd_is_paused(ahd
)) {
4233 * Force the sequencer to reinitialize the selection for
4234 * the command at the head of the execution queue if it
4235 * has already been setup. The negotiation changes may
4236 * effect whether we select-out with ATN. It is only
4237 * safe to clear ENSELO when the bus is not free and no
4238 * selection is in progres or completed.
4240 saved_modes
= ahd_save_modes(ahd
);
4241 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
4242 if ((ahd_inb(ahd
, SCSISIGI
) & BSYI
) != 0
4243 && (ahd_inb(ahd
, SSTAT0
) & (SELDO
|SELINGO
)) == 0)
4244 ahd_outb(ahd
, SCSISEQ0
, ahd_inb(ahd
, SCSISEQ0
) & ~ENSELO
);
4245 saved_scbptr
= ahd_get_scbptr(ahd
);
4246 /* Ensure that the hscbs down on the card match the new information */
4247 LIST_FOREACH(pending_scb
, &ahd
->pending_scbs
, pending_links
) {
4251 scb_tag
= SCB_GET_TAG(pending_scb
);
4252 ahd_set_scbptr(ahd
, scb_tag
);
4253 control
= ahd_inb_scbram(ahd
, SCB_CONTROL
);
4254 control
&= ~MK_MESSAGE
;
4255 control
|= pending_scb
->hscb
->control
& MK_MESSAGE
;
4256 ahd_outb(ahd
, SCB_CONTROL
, control
);
4258 ahd_set_scbptr(ahd
, saved_scbptr
);
4259 ahd_restore_modes(ahd
, saved_modes
);
4265 /**************************** Pathing Information *****************************/
4267 ahd_fetch_devinfo(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
)
4269 ahd_mode_state saved_modes
;
4274 saved_modes
= ahd_save_modes(ahd
);
4275 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
4277 if (ahd_inb(ahd
, SSTAT0
) & TARGET
)
4280 role
= ROLE_INITIATOR
;
4282 if (role
== ROLE_TARGET
4283 && (ahd_inb(ahd
, SEQ_FLAGS
) & CMDPHASE_PENDING
) != 0) {
4284 /* We were selected, so pull our id from TARGIDIN */
4285 our_id
= ahd_inb(ahd
, TARGIDIN
) & OID
;
4286 } else if (role
== ROLE_TARGET
)
4287 our_id
= ahd_inb(ahd
, TOWNID
);
4289 our_id
= ahd_inb(ahd
, IOWNID
);
4291 saved_scsiid
= ahd_inb(ahd
, SAVED_SCSIID
);
4292 ahd_compile_devinfo(devinfo
,
4294 SCSIID_TARGET(ahd
, saved_scsiid
),
4295 ahd_inb(ahd
, SAVED_LUN
),
4296 SCSIID_CHANNEL(ahd
, saved_scsiid
),
4298 ahd_restore_modes(ahd
, saved_modes
);
4302 ahd_print_devinfo(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
)
4304 printk("%s:%c:%d:%d: ", ahd_name(ahd
), 'A',
4305 devinfo
->target
, devinfo
->lun
);
4308 static const struct ahd_phase_table_entry
*
4309 ahd_lookup_phase_entry(int phase
)
4311 const struct ahd_phase_table_entry
*entry
;
4312 const struct ahd_phase_table_entry
*last_entry
;
4315 * num_phases doesn't include the default entry which
4316 * will be returned if the phase doesn't match.
4318 last_entry
= &ahd_phase_table
[num_phases
];
4319 for (entry
= ahd_phase_table
; entry
< last_entry
; entry
++) {
4320 if (phase
== entry
->phase
)
4327 ahd_compile_devinfo(struct ahd_devinfo
*devinfo
, u_int our_id
, u_int target
,
4328 u_int lun
, char channel
, role_t role
)
4330 devinfo
->our_scsiid
= our_id
;
4331 devinfo
->target
= target
;
4333 devinfo
->target_offset
= target
;
4334 devinfo
->channel
= channel
;
4335 devinfo
->role
= role
;
4337 devinfo
->target_offset
+= 8;
4338 devinfo
->target_mask
= (0x01 << devinfo
->target_offset
);
4342 ahd_scb_devinfo(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
,
4348 our_id
= SCSIID_OUR_ID(scb
->hscb
->scsiid
);
4349 role
= ROLE_INITIATOR
;
4350 if ((scb
->hscb
->control
& TARGET_SCB
) != 0)
4352 ahd_compile_devinfo(devinfo
, our_id
, SCB_GET_TARGET(ahd
, scb
),
4353 SCB_GET_LUN(scb
), SCB_GET_CHANNEL(ahd
, scb
), role
);
4357 /************************ Message Phase Processing ****************************/
4359 * When an initiator transaction with the MK_MESSAGE flag either reconnects
4360 * or enters the initial message out phase, we are interrupted. Fill our
4361 * outgoing message buffer with the appropriate message and beging handing
4362 * the message phase(s) manually.
4365 ahd_setup_initiator_msgout(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
,
4369 * To facilitate adding multiple messages together,
4370 * each routine should increment the index and len
4371 * variables instead of setting them explicitly.
4373 ahd
->msgout_index
= 0;
4374 ahd
->msgout_len
= 0;
4376 if (ahd_currently_packetized(ahd
))
4377 ahd
->msg_flags
|= MSG_FLAG_PACKETIZED
;
4379 if (ahd
->send_msg_perror
4380 && ahd_inb(ahd
, MSG_OUT
) == HOST_MSG
) {
4381 ahd
->msgout_buf
[ahd
->msgout_index
++] = ahd
->send_msg_perror
;
4383 ahd
->msg_type
= MSG_TYPE_INITIATOR_MSGOUT
;
4385 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
4386 printk("Setting up for Parity Error delivery\n");
4389 } else if (scb
== NULL
) {
4390 printk("%s: WARNING. No pending message for "
4391 "I_T msgin. Issuing NO-OP\n", ahd_name(ahd
));
4392 ahd
->msgout_buf
[ahd
->msgout_index
++] = NOP
;
4394 ahd
->msg_type
= MSG_TYPE_INITIATOR_MSGOUT
;
4398 if ((scb
->flags
& SCB_DEVICE_RESET
) == 0
4399 && (scb
->flags
& SCB_PACKETIZED
) == 0
4400 && ahd_inb(ahd
, MSG_OUT
) == MSG_IDENTIFYFLAG
) {
4403 identify_msg
= MSG_IDENTIFYFLAG
| SCB_GET_LUN(scb
);
4404 if ((scb
->hscb
->control
& DISCENB
) != 0)
4405 identify_msg
|= MSG_IDENTIFY_DISCFLAG
;
4406 ahd
->msgout_buf
[ahd
->msgout_index
++] = identify_msg
;
4409 if ((scb
->hscb
->control
& TAG_ENB
) != 0) {
4410 ahd
->msgout_buf
[ahd
->msgout_index
++] =
4411 scb
->hscb
->control
& (TAG_ENB
|SCB_TAG_TYPE
);
4412 ahd
->msgout_buf
[ahd
->msgout_index
++] = SCB_GET_TAG(scb
);
4413 ahd
->msgout_len
+= 2;
4417 if (scb
->flags
& SCB_DEVICE_RESET
) {
4418 ahd
->msgout_buf
[ahd
->msgout_index
++] = TARGET_RESET
;
4420 ahd_print_path(ahd
, scb
);
4421 printk("Bus Device Reset Message Sent\n");
4423 * Clear our selection hardware in advance of
4424 * the busfree. We may have an entry in the waiting
4425 * Q for this target, and we don't want to go about
4426 * selecting while we handle the busfree and blow it
4429 ahd_outb(ahd
, SCSISEQ0
, 0);
4430 } else if ((scb
->flags
& SCB_ABORT
) != 0) {
4432 if ((scb
->hscb
->control
& TAG_ENB
) != 0) {
4433 ahd
->msgout_buf
[ahd
->msgout_index
++] = ABORT_TASK
;
4435 ahd
->msgout_buf
[ahd
->msgout_index
++] = ABORT_TASK_SET
;
4438 ahd_print_path(ahd
, scb
);
4439 printk("Abort%s Message Sent\n",
4440 (scb
->hscb
->control
& TAG_ENB
) != 0 ? " Tag" : "");
4442 * Clear our selection hardware in advance of
4443 * the busfree. We may have an entry in the waiting
4444 * Q for this target, and we don't want to go about
4445 * selecting while we handle the busfree and blow it
4448 ahd_outb(ahd
, SCSISEQ0
, 0);
4449 } else if ((scb
->flags
& (SCB_AUTO_NEGOTIATE
|SCB_NEGOTIATE
)) != 0) {
4450 ahd_build_transfer_msg(ahd
, devinfo
);
4452 * Clear our selection hardware in advance of potential
4453 * PPR IU status change busfree. We may have an entry in
4454 * the waiting Q for this target, and we don't want to go
4455 * about selecting while we handle the busfree and blow
4458 ahd_outb(ahd
, SCSISEQ0
, 0);
4460 printk("ahd_intr: AWAITING_MSG for an SCB that "
4461 "does not have a waiting message\n");
4462 printk("SCSIID = %x, target_mask = %x\n", scb
->hscb
->scsiid
,
4463 devinfo
->target_mask
);
4464 panic("SCB = %d, SCB Control = %x:%x, MSG_OUT = %x "
4465 "SCB flags = %x", SCB_GET_TAG(scb
), scb
->hscb
->control
,
4466 ahd_inb_scbram(ahd
, SCB_CONTROL
), ahd_inb(ahd
, MSG_OUT
),
4471 * Clear the MK_MESSAGE flag from the SCB so we aren't
4472 * asked to send this message again.
4474 ahd_outb(ahd
, SCB_CONTROL
,
4475 ahd_inb_scbram(ahd
, SCB_CONTROL
) & ~MK_MESSAGE
);
4476 scb
->hscb
->control
&= ~MK_MESSAGE
;
4477 ahd
->msgout_index
= 0;
4478 ahd
->msg_type
= MSG_TYPE_INITIATOR_MSGOUT
;
4482 * Build an appropriate transfer negotiation message for the
4483 * currently active target.
4486 ahd_build_transfer_msg(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
)
4489 * We need to initiate transfer negotiations.
4490 * If our current and goal settings are identical,
4491 * we want to renegotiate due to a check condition.
4493 struct ahd_initiator_tinfo
*tinfo
;
4494 struct ahd_tmode_tstate
*tstate
;
4502 tinfo
= ahd_fetch_transinfo(ahd
, devinfo
->channel
, devinfo
->our_scsiid
,
4503 devinfo
->target
, &tstate
);
4505 * Filter our period based on the current connection.
4506 * If we can't perform DT transfers on this segment (not in LVD
4507 * mode for instance), then our decision to issue a PPR message
4510 period
= tinfo
->goal
.period
;
4511 offset
= tinfo
->goal
.offset
;
4512 ppr_options
= tinfo
->goal
.ppr_options
;
4513 /* Target initiated PPR is not allowed in the SCSI spec */
4514 if (devinfo
->role
== ROLE_TARGET
)
4516 ahd_devlimited_syncrate(ahd
, tinfo
, &period
,
4517 &ppr_options
, devinfo
->role
);
4518 dowide
= tinfo
->curr
.width
!= tinfo
->goal
.width
;
4519 dosync
= tinfo
->curr
.offset
!= offset
|| tinfo
->curr
.period
!= period
;
4521 * Only use PPR if we have options that need it, even if the device
4522 * claims to support it. There might be an expander in the way
4525 doppr
= ppr_options
!= 0;
4527 if (!dowide
&& !dosync
&& !doppr
) {
4528 dowide
= tinfo
->goal
.width
!= MSG_EXT_WDTR_BUS_8_BIT
;
4529 dosync
= tinfo
->goal
.offset
!= 0;
4532 if (!dowide
&& !dosync
&& !doppr
) {
4534 * Force async with a WDTR message if we have a wide bus,
4535 * or just issue an SDTR with a 0 offset.
4537 if ((ahd
->features
& AHD_WIDE
) != 0)
4543 ahd_print_devinfo(ahd
, devinfo
);
4544 printk("Ensuring async\n");
4547 /* Target initiated PPR is not allowed in the SCSI spec */
4548 if (devinfo
->role
== ROLE_TARGET
)
4552 * Both the PPR message and SDTR message require the
4553 * goal syncrate to be limited to what the target device
4554 * is capable of handling (based on whether an LVD->SE
4555 * expander is on the bus), so combine these two cases.
4556 * Regardless, guarantee that if we are using WDTR and SDTR
4557 * messages that WDTR comes first.
4559 if (doppr
|| (dosync
&& !dowide
)) {
4561 offset
= tinfo
->goal
.offset
;
4562 ahd_validate_offset(ahd
, tinfo
, period
, &offset
,
4563 doppr
? tinfo
->goal
.width
4564 : tinfo
->curr
.width
,
4567 ahd_construct_ppr(ahd
, devinfo
, period
, offset
,
4568 tinfo
->goal
.width
, ppr_options
);
4570 ahd_construct_sdtr(ahd
, devinfo
, period
, offset
);
4573 ahd_construct_wdtr(ahd
, devinfo
, tinfo
->goal
.width
);
4578 * Build a synchronous negotiation message in our message
4579 * buffer based on the input parameters.
4582 ahd_construct_sdtr(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
,
4583 u_int period
, u_int offset
)
4586 period
= AHD_ASYNC_XFER_PERIOD
;
4587 ahd
->msgout_index
+= spi_populate_sync_msg(
4588 ahd
->msgout_buf
+ ahd
->msgout_index
, period
, offset
);
4589 ahd
->msgout_len
+= 5;
4591 printk("(%s:%c:%d:%d): Sending SDTR period %x, offset %x\n",
4592 ahd_name(ahd
), devinfo
->channel
, devinfo
->target
,
4593 devinfo
->lun
, period
, offset
);
4598 * Build a wide negotiateion message in our message
4599 * buffer based on the input parameters.
4602 ahd_construct_wdtr(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
,
4605 ahd
->msgout_index
+= spi_populate_width_msg(
4606 ahd
->msgout_buf
+ ahd
->msgout_index
, bus_width
);
4607 ahd
->msgout_len
+= 4;
4609 printk("(%s:%c:%d:%d): Sending WDTR %x\n",
4610 ahd_name(ahd
), devinfo
->channel
, devinfo
->target
,
4611 devinfo
->lun
, bus_width
);
4616 * Build a parallel protocol request message in our message
4617 * buffer based on the input parameters.
4620 ahd_construct_ppr(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
,
4621 u_int period
, u_int offset
, u_int bus_width
,
4625 * Always request precompensation from
4626 * the other target if we are running
4627 * at paced syncrates.
4629 if (period
<= AHD_SYNCRATE_PACED
)
4630 ppr_options
|= MSG_EXT_PPR_PCOMP_EN
;
4632 period
= AHD_ASYNC_XFER_PERIOD
;
4633 ahd
->msgout_index
+= spi_populate_ppr_msg(
4634 ahd
->msgout_buf
+ ahd
->msgout_index
, period
, offset
,
4635 bus_width
, ppr_options
);
4636 ahd
->msgout_len
+= 8;
4638 printk("(%s:%c:%d:%d): Sending PPR bus_width %x, period %x, "
4639 "offset %x, ppr_options %x\n", ahd_name(ahd
),
4640 devinfo
->channel
, devinfo
->target
, devinfo
->lun
,
4641 bus_width
, period
, offset
, ppr_options
);
4646 * Clear any active message state.
4649 ahd_clear_msg_state(struct ahd_softc
*ahd
)
4651 ahd_mode_state saved_modes
;
4653 saved_modes
= ahd_save_modes(ahd
);
4654 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
4655 ahd
->send_msg_perror
= 0;
4656 ahd
->msg_flags
= MSG_FLAG_NONE
;
4657 ahd
->msgout_len
= 0;
4658 ahd
->msgin_index
= 0;
4659 ahd
->msg_type
= MSG_TYPE_NONE
;
4660 if ((ahd_inb(ahd
, SCSISIGO
) & ATNO
) != 0) {
4662 * The target didn't care to respond to our
4663 * message request, so clear ATN.
4665 ahd_outb(ahd
, CLRSINT1
, CLRATNO
);
4667 ahd_outb(ahd
, MSG_OUT
, NOP
);
4668 ahd_outb(ahd
, SEQ_FLAGS2
,
4669 ahd_inb(ahd
, SEQ_FLAGS2
) & ~TARGET_MSG_PENDING
);
4670 ahd_restore_modes(ahd
, saved_modes
);
4674 * Manual message loop handler.
4677 ahd_handle_message_phase(struct ahd_softc
*ahd
)
4679 struct ahd_devinfo devinfo
;
4683 ahd_fetch_devinfo(ahd
, &devinfo
);
4684 end_session
= FALSE
;
4685 bus_phase
= ahd_inb(ahd
, LASTPHASE
);
4687 if ((ahd_inb(ahd
, LQISTAT2
) & LQIPHASE_OUTPKT
) != 0) {
4688 printk("LQIRETRY for LQIPHASE_OUTPKT\n");
4689 ahd_outb(ahd
, LQCTL2
, LQIRETRY
);
4692 switch (ahd
->msg_type
) {
4693 case MSG_TYPE_INITIATOR_MSGOUT
:
4699 if (ahd
->msgout_len
== 0 && ahd
->send_msg_perror
== 0)
4700 panic("HOST_MSG_LOOP interrupt with no active message");
4703 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0) {
4704 ahd_print_devinfo(ahd
, &devinfo
);
4705 printk("INITIATOR_MSG_OUT");
4708 phasemis
= bus_phase
!= P_MESGOUT
;
4711 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0) {
4712 printk(" PHASEMIS %s\n",
4713 ahd_lookup_phase_entry(bus_phase
)
4717 if (bus_phase
== P_MESGIN
) {
4719 * Change gears and see if
4720 * this messages is of interest to
4721 * us or should be passed back to
4724 ahd_outb(ahd
, CLRSINT1
, CLRATNO
);
4725 ahd
->send_msg_perror
= 0;
4726 ahd
->msg_type
= MSG_TYPE_INITIATOR_MSGIN
;
4727 ahd
->msgin_index
= 0;
4734 if (ahd
->send_msg_perror
) {
4735 ahd_outb(ahd
, CLRSINT1
, CLRATNO
);
4736 ahd_outb(ahd
, CLRSINT1
, CLRREQINIT
);
4738 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
4739 printk(" byte 0x%x\n", ahd
->send_msg_perror
);
4742 * If we are notifying the target of a CRC error
4743 * during packetized operations, the target is
4744 * within its rights to acknowledge our message
4747 if ((ahd
->msg_flags
& MSG_FLAG_PACKETIZED
) != 0
4748 && ahd
->send_msg_perror
== INITIATOR_ERROR
)
4749 ahd
->msg_flags
|= MSG_FLAG_EXPECT_IDE_BUSFREE
;
4751 ahd_outb(ahd
, RETURN_2
, ahd
->send_msg_perror
);
4752 ahd_outb(ahd
, RETURN_1
, CONT_MSG_LOOP_WRITE
);
4756 msgdone
= ahd
->msgout_index
== ahd
->msgout_len
;
4759 * The target has requested a retry.
4760 * Re-assert ATN, reset our message index to
4763 ahd
->msgout_index
= 0;
4764 ahd_assert_atn(ahd
);
4767 lastbyte
= ahd
->msgout_index
== (ahd
->msgout_len
- 1);
4769 /* Last byte is signified by dropping ATN */
4770 ahd_outb(ahd
, CLRSINT1
, CLRATNO
);
4774 * Clear our interrupt status and present
4775 * the next byte on the bus.
4777 ahd_outb(ahd
, CLRSINT1
, CLRREQINIT
);
4779 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
4780 printk(" byte 0x%x\n",
4781 ahd
->msgout_buf
[ahd
->msgout_index
]);
4783 ahd_outb(ahd
, RETURN_2
, ahd
->msgout_buf
[ahd
->msgout_index
++]);
4784 ahd_outb(ahd
, RETURN_1
, CONT_MSG_LOOP_WRITE
);
4787 case MSG_TYPE_INITIATOR_MSGIN
:
4793 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0) {
4794 ahd_print_devinfo(ahd
, &devinfo
);
4795 printk("INITIATOR_MSG_IN");
4798 phasemis
= bus_phase
!= P_MESGIN
;
4801 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0) {
4802 printk(" PHASEMIS %s\n",
4803 ahd_lookup_phase_entry(bus_phase
)
4807 ahd
->msgin_index
= 0;
4808 if (bus_phase
== P_MESGOUT
4809 && (ahd
->send_msg_perror
!= 0
4810 || (ahd
->msgout_len
!= 0
4811 && ahd
->msgout_index
== 0))) {
4812 ahd
->msg_type
= MSG_TYPE_INITIATOR_MSGOUT
;
4819 /* Pull the byte in without acking it */
4820 ahd
->msgin_buf
[ahd
->msgin_index
] = ahd_inb(ahd
, SCSIBUS
);
4822 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
4823 printk(" byte 0x%x\n",
4824 ahd
->msgin_buf
[ahd
->msgin_index
]);
4827 message_done
= ahd_parse_msg(ahd
, &devinfo
);
4831 * Clear our incoming message buffer in case there
4832 * is another message following this one.
4834 ahd
->msgin_index
= 0;
4837 * If this message illicited a response,
4838 * assert ATN so the target takes us to the
4839 * message out phase.
4841 if (ahd
->msgout_len
!= 0) {
4843 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0) {
4844 ahd_print_devinfo(ahd
, &devinfo
);
4845 printk("Asserting ATN for response\n");
4848 ahd_assert_atn(ahd
);
4853 if (message_done
== MSGLOOP_TERMINATED
) {
4857 ahd_outb(ahd
, CLRSINT1
, CLRREQINIT
);
4858 ahd_outb(ahd
, RETURN_1
, CONT_MSG_LOOP_READ
);
4862 case MSG_TYPE_TARGET_MSGIN
:
4868 * By default, the message loop will continue.
4870 ahd_outb(ahd
, RETURN_1
, CONT_MSG_LOOP_TARG
);
4872 if (ahd
->msgout_len
== 0)
4873 panic("Target MSGIN with no active message");
4876 * If we interrupted a mesgout session, the initiator
4877 * will not know this until our first REQ. So, we
4878 * only honor mesgout requests after we've sent our
4881 if ((ahd_inb(ahd
, SCSISIGI
) & ATNI
) != 0
4882 && ahd
->msgout_index
> 0)
4883 msgout_request
= TRUE
;
4885 msgout_request
= FALSE
;
4887 if (msgout_request
) {
4890 * Change gears and see if
4891 * this messages is of interest to
4892 * us or should be passed back to
4895 ahd
->msg_type
= MSG_TYPE_TARGET_MSGOUT
;
4896 ahd_outb(ahd
, SCSISIGO
, P_MESGOUT
| BSYO
);
4897 ahd
->msgin_index
= 0;
4898 /* Dummy read to REQ for first byte */
4899 ahd_inb(ahd
, SCSIDAT
);
4900 ahd_outb(ahd
, SXFRCTL0
,
4901 ahd_inb(ahd
, SXFRCTL0
) | SPIOEN
);
4905 msgdone
= ahd
->msgout_index
== ahd
->msgout_len
;
4907 ahd_outb(ahd
, SXFRCTL0
,
4908 ahd_inb(ahd
, SXFRCTL0
) & ~SPIOEN
);
4914 * Present the next byte on the bus.
4916 ahd_outb(ahd
, SXFRCTL0
, ahd_inb(ahd
, SXFRCTL0
) | SPIOEN
);
4917 ahd_outb(ahd
, SCSIDAT
, ahd
->msgout_buf
[ahd
->msgout_index
++]);
4920 case MSG_TYPE_TARGET_MSGOUT
:
4926 * By default, the message loop will continue.
4928 ahd_outb(ahd
, RETURN_1
, CONT_MSG_LOOP_TARG
);
4931 * The initiator signals that this is
4932 * the last byte by dropping ATN.
4934 lastbyte
= (ahd_inb(ahd
, SCSISIGI
) & ATNI
) == 0;
4937 * Read the latched byte, but turn off SPIOEN first
4938 * so that we don't inadvertently cause a REQ for the
4941 ahd_outb(ahd
, SXFRCTL0
, ahd_inb(ahd
, SXFRCTL0
) & ~SPIOEN
);
4942 ahd
->msgin_buf
[ahd
->msgin_index
] = ahd_inb(ahd
, SCSIDAT
);
4943 msgdone
= ahd_parse_msg(ahd
, &devinfo
);
4944 if (msgdone
== MSGLOOP_TERMINATED
) {
4946 * The message is *really* done in that it caused
4947 * us to go to bus free. The sequencer has already
4948 * been reset at this point, so pull the ejection
4957 * XXX Read spec about initiator dropping ATN too soon
4958 * and use msgdone to detect it.
4960 if (msgdone
== MSGLOOP_MSGCOMPLETE
) {
4961 ahd
->msgin_index
= 0;
4964 * If this message illicited a response, transition
4965 * to the Message in phase and send it.
4967 if (ahd
->msgout_len
!= 0) {
4968 ahd_outb(ahd
, SCSISIGO
, P_MESGIN
| BSYO
);
4969 ahd_outb(ahd
, SXFRCTL0
,
4970 ahd_inb(ahd
, SXFRCTL0
) | SPIOEN
);
4971 ahd
->msg_type
= MSG_TYPE_TARGET_MSGIN
;
4972 ahd
->msgin_index
= 0;
4980 /* Ask for the next byte. */
4981 ahd_outb(ahd
, SXFRCTL0
,
4982 ahd_inb(ahd
, SXFRCTL0
) | SPIOEN
);
4988 panic("Unknown REQINIT message type");
4992 if ((ahd
->msg_flags
& MSG_FLAG_PACKETIZED
) != 0) {
4993 printk("%s: Returning to Idle Loop\n",
4995 ahd_clear_msg_state(ahd
);
4998 * Perform the equivalent of a clear_target_state.
5000 ahd_outb(ahd
, LASTPHASE
, P_BUSFREE
);
5001 ahd_outb(ahd
, SEQ_FLAGS
, NOT_IDENTIFIED
|NO_CDB_SENT
);
5002 ahd_outb(ahd
, SEQCTL0
, FASTMODE
|SEQRESET
);
5004 ahd_clear_msg_state(ahd
);
5005 ahd_outb(ahd
, RETURN_1
, EXIT_MSG_LOOP
);
5011 * See if we sent a particular extended message to the target.
5012 * If "full" is true, return true only if the target saw the full
5013 * message. If "full" is false, return true if the target saw at
5014 * least the first byte of the message.
5017 ahd_sent_msg(struct ahd_softc
*ahd
, ahd_msgtype type
, u_int msgval
, int full
)
5025 while (index
< ahd
->msgout_len
) {
5026 if (ahd
->msgout_buf
[index
] == EXTENDED_MESSAGE
) {
5029 end_index
= index
+ 1 + ahd
->msgout_buf
[index
+ 1];
5030 if (ahd
->msgout_buf
[index
+2] == msgval
5031 && type
== AHDMSG_EXT
) {
5034 if (ahd
->msgout_index
> end_index
)
5036 } else if (ahd
->msgout_index
> index
)
5040 } else if (ahd
->msgout_buf
[index
] >= SIMPLE_QUEUE_TAG
5041 && ahd
->msgout_buf
[index
] <= IGNORE_WIDE_RESIDUE
) {
5043 /* Skip tag type and tag id or residue param*/
5046 /* Single byte message */
5047 if (type
== AHDMSG_1B
5048 && ahd
->msgout_index
> index
5049 && (ahd
->msgout_buf
[index
] == msgval
5050 || ((ahd
->msgout_buf
[index
] & MSG_IDENTIFYFLAG
) != 0
5051 && msgval
== MSG_IDENTIFYFLAG
)))
5063 * Wait for a complete incoming message, parse it, and respond accordingly.
5066 ahd_parse_msg(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
)
5068 struct ahd_initiator_tinfo
*tinfo
;
5069 struct ahd_tmode_tstate
*tstate
;
5074 done
= MSGLOOP_IN_PROG
;
5077 tinfo
= ahd_fetch_transinfo(ahd
, devinfo
->channel
, devinfo
->our_scsiid
,
5078 devinfo
->target
, &tstate
);
5081 * Parse as much of the message as is available,
5082 * rejecting it if we don't support it. When
5083 * the entire message is available and has been
5084 * handled, return MSGLOOP_MSGCOMPLETE, indicating
5085 * that we have parsed an entire message.
5087 * In the case of extended messages, we accept the length
5088 * byte outright and perform more checking once we know the
5089 * extended message type.
5091 switch (ahd
->msgin_buf
[0]) {
5094 case COMMAND_COMPLETE
:
5095 case RESTORE_POINTERS
:
5096 case IGNORE_WIDE_RESIDUE
:
5098 * End our message loop as these are messages
5099 * the sequencer handles on its own.
5101 done
= MSGLOOP_TERMINATED
;
5103 case MESSAGE_REJECT
:
5104 response
= ahd_handle_msg_reject(ahd
, devinfo
);
5107 done
= MSGLOOP_MSGCOMPLETE
;
5109 case EXTENDED_MESSAGE
:
5111 /* Wait for enough of the message to begin validation */
5112 if (ahd
->msgin_index
< 2)
5114 switch (ahd
->msgin_buf
[2]) {
5122 if (ahd
->msgin_buf
[1] != MSG_EXT_SDTR_LEN
) {
5128 * Wait until we have both args before validating
5129 * and acting on this message.
5131 * Add one to MSG_EXT_SDTR_LEN to account for
5132 * the extended message preamble.
5134 if (ahd
->msgin_index
< (MSG_EXT_SDTR_LEN
+ 1))
5137 period
= ahd
->msgin_buf
[3];
5139 saved_offset
= offset
= ahd
->msgin_buf
[4];
5140 ahd_devlimited_syncrate(ahd
, tinfo
, &period
,
5141 &ppr_options
, devinfo
->role
);
5142 ahd_validate_offset(ahd
, tinfo
, period
, &offset
,
5143 tinfo
->curr
.width
, devinfo
->role
);
5145 printk("(%s:%c:%d:%d): Received "
5146 "SDTR period %x, offset %x\n\t"
5147 "Filtered to period %x, offset %x\n",
5148 ahd_name(ahd
), devinfo
->channel
,
5149 devinfo
->target
, devinfo
->lun
,
5150 ahd
->msgin_buf
[3], saved_offset
,
5153 ahd_set_syncrate(ahd
, devinfo
, period
,
5154 offset
, ppr_options
,
5155 AHD_TRANS_ACTIVE
|AHD_TRANS_GOAL
,
5159 * See if we initiated Sync Negotiation
5160 * and didn't have to fall down to async
5163 if (ahd_sent_msg(ahd
, AHDMSG_EXT
, EXTENDED_SDTR
, TRUE
)) {
5165 if (saved_offset
!= offset
) {
5166 /* Went too low - force async */
5171 * Send our own SDTR in reply
5174 && devinfo
->role
== ROLE_INITIATOR
) {
5175 printk("(%s:%c:%d:%d): Target "
5177 ahd_name(ahd
), devinfo
->channel
,
5178 devinfo
->target
, devinfo
->lun
);
5180 ahd
->msgout_index
= 0;
5181 ahd
->msgout_len
= 0;
5182 ahd_construct_sdtr(ahd
, devinfo
,
5184 ahd
->msgout_index
= 0;
5187 done
= MSGLOOP_MSGCOMPLETE
;
5194 u_int sending_reply
;
5196 sending_reply
= FALSE
;
5197 if (ahd
->msgin_buf
[1] != MSG_EXT_WDTR_LEN
) {
5203 * Wait until we have our arg before validating
5204 * and acting on this message.
5206 * Add one to MSG_EXT_WDTR_LEN to account for
5207 * the extended message preamble.
5209 if (ahd
->msgin_index
< (MSG_EXT_WDTR_LEN
+ 1))
5212 bus_width
= ahd
->msgin_buf
[3];
5213 saved_width
= bus_width
;
5214 ahd_validate_width(ahd
, tinfo
, &bus_width
,
5217 printk("(%s:%c:%d:%d): Received WDTR "
5218 "%x filtered to %x\n",
5219 ahd_name(ahd
), devinfo
->channel
,
5220 devinfo
->target
, devinfo
->lun
,
5221 saved_width
, bus_width
);
5224 if (ahd_sent_msg(ahd
, AHDMSG_EXT
, EXTENDED_WDTR
, TRUE
)) {
5226 * Don't send a WDTR back to the
5227 * target, since we asked first.
5228 * If the width went higher than our
5229 * request, reject it.
5231 if (saved_width
> bus_width
) {
5233 printk("(%s:%c:%d:%d): requested %dBit "
5234 "transfers. Rejecting...\n",
5235 ahd_name(ahd
), devinfo
->channel
,
5236 devinfo
->target
, devinfo
->lun
,
5237 8 * (0x01 << bus_width
));
5242 * Send our own WDTR in reply
5245 && devinfo
->role
== ROLE_INITIATOR
) {
5246 printk("(%s:%c:%d:%d): Target "
5248 ahd_name(ahd
), devinfo
->channel
,
5249 devinfo
->target
, devinfo
->lun
);
5251 ahd
->msgout_index
= 0;
5252 ahd
->msgout_len
= 0;
5253 ahd_construct_wdtr(ahd
, devinfo
, bus_width
);
5254 ahd
->msgout_index
= 0;
5256 sending_reply
= TRUE
;
5259 * After a wide message, we are async, but
5260 * some devices don't seem to honor this portion
5261 * of the spec. Force a renegotiation of the
5262 * sync component of our transfer agreement even
5263 * if our goal is async. By updating our width
5264 * after forcing the negotiation, we avoid
5265 * renegotiating for width.
5267 ahd_update_neg_request(ahd
, devinfo
, tstate
,
5268 tinfo
, AHD_NEG_ALWAYS
);
5269 ahd_set_width(ahd
, devinfo
, bus_width
,
5270 AHD_TRANS_ACTIVE
|AHD_TRANS_GOAL
,
5272 if (sending_reply
== FALSE
&& reject
== FALSE
) {
5275 * We will always have an SDTR to send.
5277 ahd
->msgout_index
= 0;
5278 ahd
->msgout_len
= 0;
5279 ahd_build_transfer_msg(ahd
, devinfo
);
5280 ahd
->msgout_index
= 0;
5283 done
= MSGLOOP_MSGCOMPLETE
;
5294 u_int saved_ppr_options
;
5296 if (ahd
->msgin_buf
[1] != MSG_EXT_PPR_LEN
) {
5302 * Wait until we have all args before validating
5303 * and acting on this message.
5305 * Add one to MSG_EXT_PPR_LEN to account for
5306 * the extended message preamble.
5308 if (ahd
->msgin_index
< (MSG_EXT_PPR_LEN
+ 1))
5311 period
= ahd
->msgin_buf
[3];
5312 offset
= ahd
->msgin_buf
[5];
5313 bus_width
= ahd
->msgin_buf
[6];
5314 saved_width
= bus_width
;
5315 ppr_options
= ahd
->msgin_buf
[7];
5317 * According to the spec, a DT only
5318 * period factor with no DT option
5319 * set implies async.
5321 if ((ppr_options
& MSG_EXT_PPR_DT_REQ
) == 0
5324 saved_ppr_options
= ppr_options
;
5325 saved_offset
= offset
;
5328 * Transfer options are only available if we
5329 * are negotiating wide.
5332 ppr_options
&= MSG_EXT_PPR_QAS_REQ
;
5334 ahd_validate_width(ahd
, tinfo
, &bus_width
,
5336 ahd_devlimited_syncrate(ahd
, tinfo
, &period
,
5337 &ppr_options
, devinfo
->role
);
5338 ahd_validate_offset(ahd
, tinfo
, period
, &offset
,
5339 bus_width
, devinfo
->role
);
5341 if (ahd_sent_msg(ahd
, AHDMSG_EXT
, EXTENDED_PPR
, TRUE
)) {
5343 * If we are unable to do any of the
5344 * requested options (we went too low),
5345 * then we'll have to reject the message.
5347 if (saved_width
> bus_width
5348 || saved_offset
!= offset
5349 || saved_ppr_options
!= ppr_options
) {
5357 if (devinfo
->role
!= ROLE_TARGET
)
5358 printk("(%s:%c:%d:%d): Target "
5360 ahd_name(ahd
), devinfo
->channel
,
5361 devinfo
->target
, devinfo
->lun
);
5363 printk("(%s:%c:%d:%d): Initiator "
5365 ahd_name(ahd
), devinfo
->channel
,
5366 devinfo
->target
, devinfo
->lun
);
5367 ahd
->msgout_index
= 0;
5368 ahd
->msgout_len
= 0;
5369 ahd_construct_ppr(ahd
, devinfo
, period
, offset
,
5370 bus_width
, ppr_options
);
5371 ahd
->msgout_index
= 0;
5375 printk("(%s:%c:%d:%d): Received PPR width %x, "
5376 "period %x, offset %x,options %x\n"
5377 "\tFiltered to width %x, period %x, "
5378 "offset %x, options %x\n",
5379 ahd_name(ahd
), devinfo
->channel
,
5380 devinfo
->target
, devinfo
->lun
,
5381 saved_width
, ahd
->msgin_buf
[3],
5382 saved_offset
, saved_ppr_options
,
5383 bus_width
, period
, offset
, ppr_options
);
5385 ahd_set_width(ahd
, devinfo
, bus_width
,
5386 AHD_TRANS_ACTIVE
|AHD_TRANS_GOAL
,
5388 ahd_set_syncrate(ahd
, devinfo
, period
,
5389 offset
, ppr_options
,
5390 AHD_TRANS_ACTIVE
|AHD_TRANS_GOAL
,
5393 done
= MSGLOOP_MSGCOMPLETE
;
5397 /* Unknown extended message. Reject it. */
5403 #ifdef AHD_TARGET_MODE
5405 ahd_handle_devreset(ahd
, devinfo
, CAM_LUN_WILDCARD
,
5407 "Bus Device Reset Received",
5408 /*verbose_level*/0);
5410 done
= MSGLOOP_TERMINATED
;
5413 case ABORT_TASK_SET
:
5414 case CLEAR_TASK_SET
:
5418 /* Target mode messages */
5419 if (devinfo
->role
!= ROLE_TARGET
) {
5423 tag
= SCB_LIST_NULL
;
5424 if (ahd
->msgin_buf
[0] == ABORT_TASK
)
5425 tag
= ahd_inb(ahd
, INITIATOR_TAG
);
5426 ahd_abort_scbs(ahd
, devinfo
->target
, devinfo
->channel
,
5427 devinfo
->lun
, tag
, ROLE_TARGET
,
5430 tstate
= ahd
->enabled_targets
[devinfo
->our_scsiid
];
5431 if (tstate
!= NULL
) {
5432 struct ahd_tmode_lstate
* lstate
;
5434 lstate
= tstate
->enabled_luns
[devinfo
->lun
];
5435 if (lstate
!= NULL
) {
5436 ahd_queue_lstate_event(ahd
, lstate
,
5437 devinfo
->our_scsiid
,
5440 ahd_send_lstate_events(ahd
, lstate
);
5444 done
= MSGLOOP_TERMINATED
;
5450 if ((ahd_debug
& AHD_SHOW_MESSAGES
) != 0)
5451 printk("%s: QAS request. SCSISIGI == 0x%x\n",
5452 ahd_name(ahd
), ahd_inb(ahd
, SCSISIGI
));
5454 ahd
->msg_flags
|= MSG_FLAG_EXPECT_QASREJ_BUSFREE
;
5456 case TERMINATE_IO_PROC
:
5464 * Setup to reject the message.
5466 ahd
->msgout_index
= 0;
5467 ahd
->msgout_len
= 1;
5468 ahd
->msgout_buf
[0] = MESSAGE_REJECT
;
5469 done
= MSGLOOP_MSGCOMPLETE
;
5473 if (done
!= MSGLOOP_IN_PROG
&& !response
)
5474 /* Clear the outgoing message buffer */
5475 ahd
->msgout_len
= 0;
5481 * Process a message reject message.
5484 ahd_handle_msg_reject(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
)
5487 * What we care about here is if we had an
5488 * outstanding SDTR or WDTR message for this
5489 * target. If we did, this is a signal that
5490 * the target is refusing negotiation.
5493 struct ahd_initiator_tinfo
*tinfo
;
5494 struct ahd_tmode_tstate
*tstate
;
5499 scb_index
= ahd_get_scbptr(ahd
);
5500 scb
= ahd_lookup_scb(ahd
, scb_index
);
5501 tinfo
= ahd_fetch_transinfo(ahd
, devinfo
->channel
,
5502 devinfo
->our_scsiid
,
5503 devinfo
->target
, &tstate
);
5504 /* Might be necessary */
5505 last_msg
= ahd_inb(ahd
, LAST_MSG
);
5507 if (ahd_sent_msg(ahd
, AHDMSG_EXT
, EXTENDED_PPR
, /*full*/FALSE
)) {
5508 if (ahd_sent_msg(ahd
, AHDMSG_EXT
, EXTENDED_PPR
, /*full*/TRUE
)
5509 && tinfo
->goal
.period
<= AHD_SYNCRATE_PACED
) {
5511 * Target may not like our SPI-4 PPR Options.
5512 * Attempt to negotiate 80MHz which will turn
5513 * off these options.
5516 printk("(%s:%c:%d:%d): PPR Rejected. "
5517 "Trying simple U160 PPR\n",
5518 ahd_name(ahd
), devinfo
->channel
,
5519 devinfo
->target
, devinfo
->lun
);
5521 tinfo
->goal
.period
= AHD_SYNCRATE_DT
;
5522 tinfo
->goal
.ppr_options
&= MSG_EXT_PPR_IU_REQ
5523 | MSG_EXT_PPR_QAS_REQ
5524 | MSG_EXT_PPR_DT_REQ
;
5527 * Target does not support the PPR message.
5528 * Attempt to negotiate SPI-2 style.
5531 printk("(%s:%c:%d:%d): PPR Rejected. "
5532 "Trying WDTR/SDTR\n",
5533 ahd_name(ahd
), devinfo
->channel
,
5534 devinfo
->target
, devinfo
->lun
);
5536 tinfo
->goal
.ppr_options
= 0;
5537 tinfo
->curr
.transport_version
= 2;
5538 tinfo
->goal
.transport_version
= 2;
5540 ahd
->msgout_index
= 0;
5541 ahd
->msgout_len
= 0;
5542 ahd_build_transfer_msg(ahd
, devinfo
);
5543 ahd
->msgout_index
= 0;
5545 } else if (ahd_sent_msg(ahd
, AHDMSG_EXT
, EXTENDED_WDTR
, /*full*/FALSE
)) {
5547 /* note 8bit xfers */
5548 printk("(%s:%c:%d:%d): refuses WIDE negotiation. Using "
5549 "8bit transfers\n", ahd_name(ahd
),
5550 devinfo
->channel
, devinfo
->target
, devinfo
->lun
);
5551 ahd_set_width(ahd
, devinfo
, MSG_EXT_WDTR_BUS_8_BIT
,
5552 AHD_TRANS_ACTIVE
|AHD_TRANS_GOAL
,
5555 * No need to clear the sync rate. If the target
5556 * did not accept the command, our syncrate is
5557 * unaffected. If the target started the negotiation,
5558 * but rejected our response, we already cleared the
5559 * sync rate before sending our WDTR.
5561 if (tinfo
->goal
.offset
!= tinfo
->curr
.offset
) {
5563 /* Start the sync negotiation */
5564 ahd
->msgout_index
= 0;
5565 ahd
->msgout_len
= 0;
5566 ahd_build_transfer_msg(ahd
, devinfo
);
5567 ahd
->msgout_index
= 0;
5570 } else if (ahd_sent_msg(ahd
, AHDMSG_EXT
, EXTENDED_SDTR
, /*full*/FALSE
)) {
5571 /* note asynch xfers and clear flag */
5572 ahd_set_syncrate(ahd
, devinfo
, /*period*/0,
5573 /*offset*/0, /*ppr_options*/0,
5574 AHD_TRANS_ACTIVE
|AHD_TRANS_GOAL
,
5576 printk("(%s:%c:%d:%d): refuses synchronous negotiation. "
5577 "Using asynchronous transfers\n",
5578 ahd_name(ahd
), devinfo
->channel
,
5579 devinfo
->target
, devinfo
->lun
);
5580 } else if ((scb
->hscb
->control
& SIMPLE_QUEUE_TAG
) != 0) {
5584 tag_type
= (scb
->hscb
->control
& SIMPLE_QUEUE_TAG
);
5586 if (tag_type
== SIMPLE_QUEUE_TAG
) {
5587 printk("(%s:%c:%d:%d): refuses tagged commands. "
5588 "Performing non-tagged I/O\n", ahd_name(ahd
),
5589 devinfo
->channel
, devinfo
->target
, devinfo
->lun
);
5590 ahd_set_tags(ahd
, scb
->io_ctx
, devinfo
, AHD_QUEUE_NONE
);
5593 printk("(%s:%c:%d:%d): refuses %s tagged commands. "
5594 "Performing simple queue tagged I/O only\n",
5595 ahd_name(ahd
), devinfo
->channel
, devinfo
->target
,
5596 devinfo
->lun
, tag_type
== ORDERED_QUEUE_TAG
5597 ? "ordered" : "head of queue");
5598 ahd_set_tags(ahd
, scb
->io_ctx
, devinfo
, AHD_QUEUE_BASIC
);
5603 * Resend the identify for this CCB as the target
5604 * may believe that the selection is invalid otherwise.
5606 ahd_outb(ahd
, SCB_CONTROL
,
5607 ahd_inb_scbram(ahd
, SCB_CONTROL
) & mask
);
5608 scb
->hscb
->control
&= mask
;
5609 ahd_set_transaction_tag(scb
, /*enabled*/FALSE
,
5610 /*type*/SIMPLE_QUEUE_TAG
);
5611 ahd_outb(ahd
, MSG_OUT
, MSG_IDENTIFYFLAG
);
5612 ahd_assert_atn(ahd
);
5613 ahd_busy_tcl(ahd
, BUILD_TCL(scb
->hscb
->scsiid
, devinfo
->lun
),
5617 * Requeue all tagged commands for this target
5618 * currently in our possession so they can be
5619 * converted to untagged commands.
5621 ahd_search_qinfifo(ahd
, SCB_GET_TARGET(ahd
, scb
),
5622 SCB_GET_CHANNEL(ahd
, scb
),
5623 SCB_GET_LUN(scb
), /*tag*/SCB_LIST_NULL
,
5624 ROLE_INITIATOR
, CAM_REQUEUE_REQ
,
5626 } else if (ahd_sent_msg(ahd
, AHDMSG_1B
, MSG_IDENTIFYFLAG
, TRUE
)) {
5628 * Most likely the device believes that we had
5629 * previously negotiated packetized.
5631 ahd
->msg_flags
|= MSG_FLAG_EXPECT_PPR_BUSFREE
5632 | MSG_FLAG_IU_REQ_CHANGED
;
5634 ahd_force_renegotiation(ahd
, devinfo
);
5635 ahd
->msgout_index
= 0;
5636 ahd
->msgout_len
= 0;
5637 ahd_build_transfer_msg(ahd
, devinfo
);
5638 ahd
->msgout_index
= 0;
5642 * Otherwise, we ignore it.
5644 printk("%s:%c:%d: Message reject for %x -- ignored\n",
5645 ahd_name(ahd
), devinfo
->channel
, devinfo
->target
,
5652 * Process an ingnore wide residue message.
5655 ahd_handle_ign_wide_residue(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
)
5660 scb_index
= ahd_get_scbptr(ahd
);
5661 scb
= ahd_lookup_scb(ahd
, scb_index
);
5663 * XXX Actually check data direction in the sequencer?
5664 * Perhaps add datadir to some spare bits in the hscb?
5666 if ((ahd_inb(ahd
, SEQ_FLAGS
) & DPHASE
) == 0
5667 || ahd_get_transfer_dir(scb
) != CAM_DIR_IN
) {
5669 * Ignore the message if we haven't
5670 * seen an appropriate data phase yet.
5674 * If the residual occurred on the last
5675 * transfer and the transfer request was
5676 * expected to end on an odd count, do
5677 * nothing. Otherwise, subtract a byte
5678 * and update the residual count accordingly.
5682 sgptr
= ahd_inb_scbram(ahd
, SCB_RESIDUAL_SGPTR
);
5683 if ((sgptr
& SG_LIST_NULL
) != 0
5684 && (ahd_inb_scbram(ahd
, SCB_TASK_ATTRIBUTE
)
5685 & SCB_XFERLEN_ODD
) != 0) {
5687 * If the residual occurred on the last
5688 * transfer and the transfer request was
5689 * expected to end on an odd count, do
5697 /* Pull in the rest of the sgptr */
5698 sgptr
= ahd_inl_scbram(ahd
, SCB_RESIDUAL_SGPTR
);
5699 data_cnt
= ahd_inl_scbram(ahd
, SCB_RESIDUAL_DATACNT
);
5700 if ((sgptr
& SG_LIST_NULL
) != 0) {
5702 * The residual data count is not updated
5703 * for the command run to completion case.
5704 * Explicitly zero the count.
5706 data_cnt
&= ~AHD_SG_LEN_MASK
;
5708 data_addr
= ahd_inq(ahd
, SHADDR
);
5711 sgptr
&= SG_PTR_MASK
;
5712 if ((ahd
->flags
& AHD_64BIT_ADDRESSING
) != 0) {
5713 struct ahd_dma64_seg
*sg
;
5715 sg
= ahd_sg_bus_to_virt(ahd
, scb
, sgptr
);
5718 * The residual sg ptr points to the next S/G
5719 * to load so we must go back one.
5722 sglen
= ahd_le32toh(sg
->len
) & AHD_SG_LEN_MASK
;
5723 if (sg
!= scb
->sg_list
5724 && sglen
< (data_cnt
& AHD_SG_LEN_MASK
)) {
5727 sglen
= ahd_le32toh(sg
->len
);
5729 * Preserve High Address and SG_LIST
5730 * bits while setting the count to 1.
5732 data_cnt
= 1|(sglen
&(~AHD_SG_LEN_MASK
));
5733 data_addr
= ahd_le64toh(sg
->addr
)
5734 + (sglen
& AHD_SG_LEN_MASK
)
5738 * Increment sg so it points to the
5742 sgptr
= ahd_sg_virt_to_bus(ahd
, scb
,
5746 struct ahd_dma_seg
*sg
;
5748 sg
= ahd_sg_bus_to_virt(ahd
, scb
, sgptr
);
5751 * The residual sg ptr points to the next S/G
5752 * to load so we must go back one.
5755 sglen
= ahd_le32toh(sg
->len
) & AHD_SG_LEN_MASK
;
5756 if (sg
!= scb
->sg_list
5757 && sglen
< (data_cnt
& AHD_SG_LEN_MASK
)) {
5760 sglen
= ahd_le32toh(sg
->len
);
5762 * Preserve High Address and SG_LIST
5763 * bits while setting the count to 1.
5765 data_cnt
= 1|(sglen
&(~AHD_SG_LEN_MASK
));
5766 data_addr
= ahd_le32toh(sg
->addr
)
5767 + (sglen
& AHD_SG_LEN_MASK
)
5771 * Increment sg so it points to the
5775 sgptr
= ahd_sg_virt_to_bus(ahd
, scb
,
5780 * Toggle the "oddness" of the transfer length
5781 * to handle this mid-transfer ignore wide
5782 * residue. This ensures that the oddness is
5783 * correct for subsequent data transfers.
5785 ahd_outb(ahd
, SCB_TASK_ATTRIBUTE
,
5786 ahd_inb_scbram(ahd
, SCB_TASK_ATTRIBUTE
)
5789 ahd_outl(ahd
, SCB_RESIDUAL_SGPTR
, sgptr
);
5790 ahd_outl(ahd
, SCB_RESIDUAL_DATACNT
, data_cnt
);
5792 * The FIFO's pointers will be updated if/when the
5793 * sequencer re-enters a data phase.
5801 * Reinitialize the data pointers for the active transfer
5802 * based on its current residual.
5805 ahd_reinitialize_dataptrs(struct ahd_softc
*ahd
)
5808 ahd_mode_state saved_modes
;
5815 AHD_ASSERT_MODES(ahd
, AHD_MODE_DFF0_MSK
|AHD_MODE_DFF1_MSK
,
5816 AHD_MODE_DFF0_MSK
|AHD_MODE_DFF1_MSK
);
5818 scb_index
= ahd_get_scbptr(ahd
);
5819 scb
= ahd_lookup_scb(ahd
, scb_index
);
5822 * Release and reacquire the FIFO so we
5823 * have a clean slate.
5825 ahd_outb(ahd
, DFFSXFRCTL
, CLRCHN
);
5827 while (--wait
&& !(ahd_inb(ahd
, MDFFSTAT
) & FIFOFREE
))
5830 ahd_print_path(ahd
, scb
);
5831 printk("ahd_reinitialize_dataptrs: Forcing FIFO free.\n");
5832 ahd_outb(ahd
, DFFSXFRCTL
, RSTCHN
|CLRSHCNT
);
5834 saved_modes
= ahd_save_modes(ahd
);
5835 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
5836 ahd_outb(ahd
, DFFSTAT
,
5837 ahd_inb(ahd
, DFFSTAT
)
5838 | (saved_modes
== 0x11 ? CURRFIFO_1
: CURRFIFO_0
));
5841 * Determine initial values for data_addr and data_cnt
5842 * for resuming the data phase.
5844 sgptr
= ahd_inl_scbram(ahd
, SCB_RESIDUAL_SGPTR
);
5845 sgptr
&= SG_PTR_MASK
;
5847 resid
= (ahd_inb_scbram(ahd
, SCB_RESIDUAL_DATACNT
+ 2) << 16)
5848 | (ahd_inb_scbram(ahd
, SCB_RESIDUAL_DATACNT
+ 1) << 8)
5849 | ahd_inb_scbram(ahd
, SCB_RESIDUAL_DATACNT
);
5851 if ((ahd
->flags
& AHD_64BIT_ADDRESSING
) != 0) {
5852 struct ahd_dma64_seg
*sg
;
5854 sg
= ahd_sg_bus_to_virt(ahd
, scb
, sgptr
);
5856 /* The residual sg_ptr always points to the next sg */
5859 dataptr
= ahd_le64toh(sg
->addr
)
5860 + (ahd_le32toh(sg
->len
) & AHD_SG_LEN_MASK
)
5862 ahd_outl(ahd
, HADDR
+ 4, dataptr
>> 32);
5864 struct ahd_dma_seg
*sg
;
5866 sg
= ahd_sg_bus_to_virt(ahd
, scb
, sgptr
);
5868 /* The residual sg_ptr always points to the next sg */
5871 dataptr
= ahd_le32toh(sg
->addr
)
5872 + (ahd_le32toh(sg
->len
) & AHD_SG_LEN_MASK
)
5874 ahd_outb(ahd
, HADDR
+ 4,
5875 (ahd_le32toh(sg
->len
) & ~AHD_SG_LEN_MASK
) >> 24);
5877 ahd_outl(ahd
, HADDR
, dataptr
);
5878 ahd_outb(ahd
, HCNT
+ 2, resid
>> 16);
5879 ahd_outb(ahd
, HCNT
+ 1, resid
>> 8);
5880 ahd_outb(ahd
, HCNT
, resid
);
5884 * Handle the effects of issuing a bus device reset message.
5887 ahd_handle_devreset(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
,
5888 u_int lun
, cam_status status
, char *message
,
5891 #ifdef AHD_TARGET_MODE
5892 struct ahd_tmode_tstate
* tstate
;
5896 found
= ahd_abort_scbs(ahd
, devinfo
->target
, devinfo
->channel
,
5897 lun
, SCB_LIST_NULL
, devinfo
->role
,
5900 #ifdef AHD_TARGET_MODE
5902 * Send an immediate notify ccb to all target mord peripheral
5903 * drivers affected by this action.
5905 tstate
= ahd
->enabled_targets
[devinfo
->our_scsiid
];
5906 if (tstate
!= NULL
) {
5910 if (lun
!= CAM_LUN_WILDCARD
) {
5912 max_lun
= AHD_NUM_LUNS
- 1;
5917 for (;cur_lun
<= max_lun
; cur_lun
++) {
5918 struct ahd_tmode_lstate
* lstate
;
5920 lstate
= tstate
->enabled_luns
[cur_lun
];
5924 ahd_queue_lstate_event(ahd
, lstate
, devinfo
->our_scsiid
,
5925 TARGET_RESET
, /*arg*/0);
5926 ahd_send_lstate_events(ahd
, lstate
);
5932 * Go back to async/narrow transfers and renegotiate.
5934 ahd_set_width(ahd
, devinfo
, MSG_EXT_WDTR_BUS_8_BIT
,
5935 AHD_TRANS_CUR
, /*paused*/TRUE
);
5936 ahd_set_syncrate(ahd
, devinfo
, /*period*/0, /*offset*/0,
5937 /*ppr_options*/0, AHD_TRANS_CUR
,
5940 if (status
!= CAM_SEL_TIMEOUT
)
5941 ahd_send_async(ahd
, devinfo
->channel
, devinfo
->target
,
5942 CAM_LUN_WILDCARD
, AC_SENT_BDR
);
5944 if (message
!= NULL
&& bootverbose
)
5945 printk("%s: %s on %c:%d. %d SCBs aborted\n", ahd_name(ahd
),
5946 message
, devinfo
->channel
, devinfo
->target
, found
);
5949 #ifdef AHD_TARGET_MODE
5951 ahd_setup_target_msgin(struct ahd_softc
*ahd
, struct ahd_devinfo
*devinfo
,
5956 * To facilitate adding multiple messages together,
5957 * each routine should increment the index and len
5958 * variables instead of setting them explicitly.
5960 ahd
->msgout_index
= 0;
5961 ahd
->msgout_len
= 0;
5963 if (scb
!= NULL
&& (scb
->flags
& SCB_AUTO_NEGOTIATE
) != 0)
5964 ahd_build_transfer_msg(ahd
, devinfo
);
5966 panic("ahd_intr: AWAITING target message with no message");
5968 ahd
->msgout_index
= 0;
5969 ahd
->msg_type
= MSG_TYPE_TARGET_MSGIN
;
5972 /**************************** Initialization **********************************/
5974 ahd_sglist_size(struct ahd_softc
*ahd
)
5976 bus_size_t list_size
;
5978 list_size
= sizeof(struct ahd_dma_seg
) * AHD_NSEG
;
5979 if ((ahd
->flags
& AHD_64BIT_ADDRESSING
) != 0)
5980 list_size
= sizeof(struct ahd_dma64_seg
) * AHD_NSEG
;
5985 * Calculate the optimum S/G List allocation size. S/G elements used
5986 * for a given transaction must be physically contiguous. Assume the
5987 * OS will allocate full pages to us, so it doesn't make sense to request
5991 ahd_sglist_allocsize(struct ahd_softc
*ahd
)
5993 bus_size_t sg_list_increment
;
5994 bus_size_t sg_list_size
;
5995 bus_size_t max_list_size
;
5996 bus_size_t best_list_size
;
5998 /* Start out with the minimum required for AHD_NSEG. */
5999 sg_list_increment
= ahd_sglist_size(ahd
);
6000 sg_list_size
= sg_list_increment
;
6002 /* Get us as close as possible to a page in size. */
6003 while ((sg_list_size
+ sg_list_increment
) <= PAGE_SIZE
)
6004 sg_list_size
+= sg_list_increment
;
6007 * Try to reduce the amount of wastage by allocating
6010 best_list_size
= sg_list_size
;
6011 max_list_size
= roundup(sg_list_increment
, PAGE_SIZE
);
6012 if (max_list_size
< 4 * PAGE_SIZE
)
6013 max_list_size
= 4 * PAGE_SIZE
;
6014 if (max_list_size
> (AHD_SCB_MAX_ALLOC
* sg_list_increment
))
6015 max_list_size
= (AHD_SCB_MAX_ALLOC
* sg_list_increment
);
6016 while ((sg_list_size
+ sg_list_increment
) <= max_list_size
6017 && (sg_list_size
% PAGE_SIZE
) != 0) {
6019 bus_size_t best_mod
;
6021 sg_list_size
+= sg_list_increment
;
6022 new_mod
= sg_list_size
% PAGE_SIZE
;
6023 best_mod
= best_list_size
% PAGE_SIZE
;
6024 if (new_mod
> best_mod
|| new_mod
== 0) {
6025 best_list_size
= sg_list_size
;
6028 return (best_list_size
);
6032 * Allocate a controller structure for a new device
6033 * and perform initial initializion.
6036 ahd_alloc(void *platform_arg
, char *name
)
6038 struct ahd_softc
*ahd
;
6040 ahd
= kzalloc(sizeof(*ahd
), GFP_ATOMIC
);
6042 printk("aic7xxx: cannot malloc softc!\n");
6047 ahd
->seep_config
= kmalloc(sizeof(*ahd
->seep_config
), GFP_ATOMIC
);
6048 if (ahd
->seep_config
== NULL
) {
6053 LIST_INIT(&ahd
->pending_scbs
);
6054 /* We don't know our unit number until the OSM sets it */
6057 ahd
->description
= NULL
;
6058 ahd
->bus_description
= NULL
;
6060 ahd
->chip
= AHD_NONE
;
6061 ahd
->features
= AHD_FENONE
;
6062 ahd
->bugs
= AHD_BUGNONE
;
6063 ahd
->flags
= AHD_SPCHK_ENB_A
|AHD_RESET_BUS_A
|AHD_TERM_ENB_A
6064 | AHD_EXTENDED_TRANS_A
|AHD_STPWLEVEL_A
;
6065 timer_setup(&ahd
->stat_timer
, ahd_stat_timer
, 0);
6066 ahd
->int_coalescing_timer
= AHD_INT_COALESCING_TIMER_DEFAULT
;
6067 ahd
->int_coalescing_maxcmds
= AHD_INT_COALESCING_MAXCMDS_DEFAULT
;
6068 ahd
->int_coalescing_mincmds
= AHD_INT_COALESCING_MINCMDS_DEFAULT
;
6069 ahd
->int_coalescing_threshold
= AHD_INT_COALESCING_THRESHOLD_DEFAULT
;
6070 ahd
->int_coalescing_stop_threshold
=
6071 AHD_INT_COALESCING_STOP_THRESHOLD_DEFAULT
;
6074 if ((ahd_debug
& AHD_SHOW_MEMORY
) != 0) {
6075 printk("%s: scb size = 0x%x, hscb size = 0x%x\n",
6076 ahd_name(ahd
), (u_int
)sizeof(struct scb
),
6077 (u_int
)sizeof(struct hardware_scb
));
6080 if (ahd_platform_alloc(ahd
, platform_arg
) != 0) {
6088 ahd_softc_init(struct ahd_softc
*ahd
)
6097 ahd_set_unit(struct ahd_softc
*ahd
, int unit
)
6103 ahd_set_name(struct ahd_softc
*ahd
, char *name
)
6110 ahd_free(struct ahd_softc
*ahd
)
6114 switch (ahd
->init_level
) {
6120 ahd_dmamap_unload(ahd
, ahd
->shared_data_dmat
,
6121 ahd
->shared_data_map
.dmamap
);
6124 ahd_dmamem_free(ahd
, ahd
->shared_data_dmat
, ahd
->qoutfifo
,
6125 ahd
->shared_data_map
.dmamap
);
6126 ahd_dmamap_destroy(ahd
, ahd
->shared_data_dmat
,
6127 ahd
->shared_data_map
.dmamap
);
6130 ahd_dma_tag_destroy(ahd
, ahd
->shared_data_dmat
);
6138 ahd_platform_free(ahd
);
6139 ahd_fini_scbdata(ahd
);
6140 for (i
= 0; i
< AHD_NUM_TARGETS
; i
++) {
6141 struct ahd_tmode_tstate
*tstate
;
6143 tstate
= ahd
->enabled_targets
[i
];
6144 if (tstate
!= NULL
) {
6145 #ifdef AHD_TARGET_MODE
6148 for (j
= 0; j
< AHD_NUM_LUNS
; j
++) {
6149 struct ahd_tmode_lstate
*lstate
;
6151 lstate
= tstate
->enabled_luns
[j
];
6152 if (lstate
!= NULL
) {
6153 xpt_free_path(lstate
->path
);
6161 #ifdef AHD_TARGET_MODE
6162 if (ahd
->black_hole
!= NULL
) {
6163 xpt_free_path(ahd
->black_hole
->path
);
6164 kfree(ahd
->black_hole
);
6168 kfree(ahd
->seep_config
);
6169 kfree(ahd
->saved_stack
);
6175 ahd_shutdown(void *arg
)
6177 struct ahd_softc
*ahd
;
6179 ahd
= (struct ahd_softc
*)arg
;
6182 * Stop periodic timer callbacks.
6184 del_timer_sync(&ahd
->stat_timer
);
6186 /* This will reset most registers to 0, but not all */
6187 ahd_reset(ahd
, /*reinit*/FALSE
);
6191 * Reset the controller and record some information about it
6192 * that is only available just after a reset. If "reinit" is
6193 * non-zero, this reset occurred after initial configuration
6194 * and the caller requests that the chip be fully reinitialized
6195 * to a runable state. Chip interrupts are *not* enabled after
6196 * a reinitialization. The caller must enable interrupts via
6197 * ahd_intr_enable().
6200 ahd_reset(struct ahd_softc
*ahd
, int reinit
)
6207 * Preserve the value of the SXFRCTL1 register for all channels.
6208 * It contains settings that affect termination and we don't want
6209 * to disturb the integrity of the bus.
6212 ahd_update_modes(ahd
);
6213 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
6214 sxfrctl1
= ahd_inb(ahd
, SXFRCTL1
);
6216 cmd
= ahd_pci_read_config(ahd
->dev_softc
, PCIR_COMMAND
, /*bytes*/2);
6217 if ((ahd
->bugs
& AHD_PCIX_CHIPRST_BUG
) != 0) {
6222 * During the assertion of CHIPRST, the chip
6223 * does not disable its parity logic prior to
6224 * the start of the reset. This may cause a
6225 * parity error to be detected and thus a
6226 * spurious SERR or PERR assertion. Disable
6227 * PERR and SERR responses during the CHIPRST.
6229 mod_cmd
= cmd
& ~(PCIM_CMD_PERRESPEN
|PCIM_CMD_SERRESPEN
);
6230 ahd_pci_write_config(ahd
->dev_softc
, PCIR_COMMAND
,
6231 mod_cmd
, /*bytes*/2);
6233 ahd_outb(ahd
, HCNTRL
, CHIPRST
| ahd
->pause
);
6236 * Ensure that the reset has finished. We delay 1000us
6237 * prior to reading the register to make sure the chip
6238 * has sufficiently completed its reset to handle register
6244 } while (--wait
&& !(ahd_inb(ahd
, HCNTRL
) & CHIPRSTACK
));
6247 printk("%s: WARNING - Failed chip reset! "
6248 "Trying to initialize anyway.\n", ahd_name(ahd
));
6250 ahd_outb(ahd
, HCNTRL
, ahd
->pause
);
6252 if ((ahd
->bugs
& AHD_PCIX_CHIPRST_BUG
) != 0) {
6254 * Clear any latched PCI error status and restore
6255 * previous SERR and PERR response enables.
6257 ahd_pci_write_config(ahd
->dev_softc
, PCIR_STATUS
+ 1,
6259 ahd_pci_write_config(ahd
->dev_softc
, PCIR_COMMAND
,
6264 * Mode should be SCSI after a chip reset, but lets
6265 * set it just to be safe. We touch the MODE_PTR
6266 * register directly so as to bypass the lazy update
6267 * code in ahd_set_modes().
6269 ahd_known_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
6270 ahd_outb(ahd
, MODE_PTR
,
6271 ahd_build_mode_state(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
));
6276 * We must always initialize STPWEN to 1 before we
6277 * restore the saved values. STPWEN is initialized
6278 * to a tri-state condition which can only be cleared
6281 ahd_outb(ahd
, SXFRCTL1
, sxfrctl1
|STPWEN
);
6282 ahd_outb(ahd
, SXFRCTL1
, sxfrctl1
);
6284 /* Determine chip configuration */
6285 ahd
->features
&= ~AHD_WIDE
;
6286 if ((ahd_inb(ahd
, SBLKCTL
) & SELWIDE
) != 0)
6287 ahd
->features
|= AHD_WIDE
;
6290 * If a recovery action has forced a chip reset,
6291 * re-initialize the chip to our liking.
6300 * Determine the number of SCBs available on the controller
6303 ahd_probe_scbs(struct ahd_softc
*ahd
) {
6306 AHD_ASSERT_MODES(ahd
, ~(AHD_MODE_UNKNOWN_MSK
|AHD_MODE_CFG_MSK
),
6307 ~(AHD_MODE_UNKNOWN_MSK
|AHD_MODE_CFG_MSK
));
6308 for (i
= 0; i
< AHD_SCB_MAX
; i
++) {
6311 ahd_set_scbptr(ahd
, i
);
6312 ahd_outw(ahd
, SCB_BASE
, i
);
6313 for (j
= 2; j
< 64; j
++)
6314 ahd_outb(ahd
, SCB_BASE
+j
, 0);
6315 /* Start out life as unallocated (needing an abort) */
6316 ahd_outb(ahd
, SCB_CONTROL
, MK_MESSAGE
);
6317 if (ahd_inw_scbram(ahd
, SCB_BASE
) != i
)
6319 ahd_set_scbptr(ahd
, 0);
6320 if (ahd_inw_scbram(ahd
, SCB_BASE
) != 0)
6327 ahd_dmamap_cb(void *arg
, bus_dma_segment_t
*segs
, int nseg
, int error
)
6331 baddr
= (dma_addr_t
*)arg
;
6332 *baddr
= segs
->ds_addr
;
6336 ahd_initialize_hscbs(struct ahd_softc
*ahd
)
6340 for (i
= 0; i
< ahd
->scb_data
.maxhscbs
; i
++) {
6341 ahd_set_scbptr(ahd
, i
);
6343 /* Clear the control byte. */
6344 ahd_outb(ahd
, SCB_CONTROL
, 0);
6346 /* Set the next pointer */
6347 ahd_outw(ahd
, SCB_NEXT
, SCB_LIST_NULL
);
6352 ahd_init_scbdata(struct ahd_softc
*ahd
)
6354 struct scb_data
*scb_data
;
6357 scb_data
= &ahd
->scb_data
;
6358 TAILQ_INIT(&scb_data
->free_scbs
);
6359 for (i
= 0; i
< AHD_NUM_TARGETS
* AHD_NUM_LUNS_NONPKT
; i
++)
6360 LIST_INIT(&scb_data
->free_scb_lists
[i
]);
6361 LIST_INIT(&scb_data
->any_dev_free_scb_list
);
6362 SLIST_INIT(&scb_data
->hscb_maps
);
6363 SLIST_INIT(&scb_data
->sg_maps
);
6364 SLIST_INIT(&scb_data
->sense_maps
);
6366 /* Determine the number of hardware SCBs and initialize them */
6367 scb_data
->maxhscbs
= ahd_probe_scbs(ahd
);
6368 if (scb_data
->maxhscbs
== 0) {
6369 printk("%s: No SCB space found\n", ahd_name(ahd
));
6373 ahd_initialize_hscbs(ahd
);
6376 * Create our DMA tags. These tags define the kinds of device
6377 * accessible memory allocations and memory mappings we will
6378 * need to perform during normal operation.
6380 * Unless we need to further restrict the allocation, we rely
6381 * on the restrictions of the parent dmat, hence the common
6382 * use of MAXADDR and MAXSIZE.
6385 /* DMA tag for our hardware scb structures */
6386 if (ahd_dma_tag_create(ahd
, ahd
->parent_dmat
, /*alignment*/1,
6387 /*boundary*/BUS_SPACE_MAXADDR_32BIT
+ 1,
6388 /*lowaddr*/BUS_SPACE_MAXADDR_32BIT
,
6389 /*highaddr*/BUS_SPACE_MAXADDR
,
6390 /*filter*/NULL
, /*filterarg*/NULL
,
6391 PAGE_SIZE
, /*nsegments*/1,
6392 /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT
,
6393 /*flags*/0, &scb_data
->hscb_dmat
) != 0) {
6397 scb_data
->init_level
++;
6399 /* DMA tag for our S/G structures. */
6400 if (ahd_dma_tag_create(ahd
, ahd
->parent_dmat
, /*alignment*/8,
6401 /*boundary*/BUS_SPACE_MAXADDR_32BIT
+ 1,
6402 /*lowaddr*/BUS_SPACE_MAXADDR_32BIT
,
6403 /*highaddr*/BUS_SPACE_MAXADDR
,
6404 /*filter*/NULL
, /*filterarg*/NULL
,
6405 ahd_sglist_allocsize(ahd
), /*nsegments*/1,
6406 /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT
,
6407 /*flags*/0, &scb_data
->sg_dmat
) != 0) {
6411 if ((ahd_debug
& AHD_SHOW_MEMORY
) != 0)
6412 printk("%s: ahd_sglist_allocsize = 0x%x\n", ahd_name(ahd
),
6413 ahd_sglist_allocsize(ahd
));
6416 scb_data
->init_level
++;
6418 /* DMA tag for our sense buffers. We allocate in page sized chunks */
6419 if (ahd_dma_tag_create(ahd
, ahd
->parent_dmat
, /*alignment*/1,
6420 /*boundary*/BUS_SPACE_MAXADDR_32BIT
+ 1,
6421 /*lowaddr*/BUS_SPACE_MAXADDR_32BIT
,
6422 /*highaddr*/BUS_SPACE_MAXADDR
,
6423 /*filter*/NULL
, /*filterarg*/NULL
,
6424 PAGE_SIZE
, /*nsegments*/1,
6425 /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT
,
6426 /*flags*/0, &scb_data
->sense_dmat
) != 0) {
6430 scb_data
->init_level
++;
6432 /* Perform initial CCB allocation */
6433 ahd_alloc_scbs(ahd
);
6435 if (scb_data
->numscbs
== 0) {
6436 printk("%s: ahd_init_scbdata - "
6437 "Unable to allocate initial scbs\n",
6443 * Note that we were successful
6453 ahd_find_scb_by_tag(struct ahd_softc
*ahd
, u_int tag
)
6458 * Look on the pending list.
6460 LIST_FOREACH(scb
, &ahd
->pending_scbs
, pending_links
) {
6461 if (SCB_GET_TAG(scb
) == tag
)
6466 * Then on all of the collision free lists.
6468 TAILQ_FOREACH(scb
, &ahd
->scb_data
.free_scbs
, links
.tqe
) {
6469 struct scb
*list_scb
;
6473 if (SCB_GET_TAG(list_scb
) == tag
)
6475 list_scb
= LIST_NEXT(list_scb
, collision_links
);
6480 * And finally on the generic free list.
6482 LIST_FOREACH(scb
, &ahd
->scb_data
.any_dev_free_scb_list
, links
.le
) {
6483 if (SCB_GET_TAG(scb
) == tag
)
6491 ahd_fini_scbdata(struct ahd_softc
*ahd
)
6493 struct scb_data
*scb_data
;
6495 scb_data
= &ahd
->scb_data
;
6496 if (scb_data
== NULL
)
6499 switch (scb_data
->init_level
) {
6503 struct map_node
*sns_map
;
6505 while ((sns_map
= SLIST_FIRST(&scb_data
->sense_maps
)) != NULL
) {
6506 SLIST_REMOVE_HEAD(&scb_data
->sense_maps
, links
);
6507 ahd_dmamap_unload(ahd
, scb_data
->sense_dmat
,
6509 ahd_dmamem_free(ahd
, scb_data
->sense_dmat
,
6510 sns_map
->vaddr
, sns_map
->dmamap
);
6513 ahd_dma_tag_destroy(ahd
, scb_data
->sense_dmat
);
6518 struct map_node
*sg_map
;
6520 while ((sg_map
= SLIST_FIRST(&scb_data
->sg_maps
)) != NULL
) {
6521 SLIST_REMOVE_HEAD(&scb_data
->sg_maps
, links
);
6522 ahd_dmamap_unload(ahd
, scb_data
->sg_dmat
,
6524 ahd_dmamem_free(ahd
, scb_data
->sg_dmat
,
6525 sg_map
->vaddr
, sg_map
->dmamap
);
6528 ahd_dma_tag_destroy(ahd
, scb_data
->sg_dmat
);
6533 struct map_node
*hscb_map
;
6535 while ((hscb_map
= SLIST_FIRST(&scb_data
->hscb_maps
)) != NULL
) {
6536 SLIST_REMOVE_HEAD(&scb_data
->hscb_maps
, links
);
6537 ahd_dmamap_unload(ahd
, scb_data
->hscb_dmat
,
6539 ahd_dmamem_free(ahd
, scb_data
->hscb_dmat
,
6540 hscb_map
->vaddr
, hscb_map
->dmamap
);
6543 ahd_dma_tag_destroy(ahd
, scb_data
->hscb_dmat
);
6556 * DSP filter Bypass must be enabled until the first selection
6557 * after a change in bus mode (Razor #491 and #493).
6560 ahd_setup_iocell_workaround(struct ahd_softc
*ahd
)
6562 ahd_mode_state saved_modes
;
6564 saved_modes
= ahd_save_modes(ahd
);
6565 ahd_set_modes(ahd
, AHD_MODE_CFG
, AHD_MODE_CFG
);
6566 ahd_outb(ahd
, DSPDATACTL
, ahd_inb(ahd
, DSPDATACTL
)
6567 | BYPASSENAB
| RCVROFFSTDIS
| XMITOFFSTDIS
);
6568 ahd_outb(ahd
, SIMODE0
, ahd_inb(ahd
, SIMODE0
) | (ENSELDO
|ENSELDI
));
6570 if ((ahd_debug
& AHD_SHOW_MISC
) != 0)
6571 printk("%s: Setting up iocell workaround\n", ahd_name(ahd
));
6573 ahd_restore_modes(ahd
, saved_modes
);
6574 ahd
->flags
&= ~AHD_HAD_FIRST_SEL
;
6578 ahd_iocell_first_selection(struct ahd_softc
*ahd
)
6580 ahd_mode_state saved_modes
;
6583 if ((ahd
->flags
& AHD_HAD_FIRST_SEL
) != 0)
6585 saved_modes
= ahd_save_modes(ahd
);
6586 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
6587 sblkctl
= ahd_inb(ahd
, SBLKCTL
);
6588 ahd_set_modes(ahd
, AHD_MODE_CFG
, AHD_MODE_CFG
);
6590 if ((ahd_debug
& AHD_SHOW_MISC
) != 0)
6591 printk("%s: iocell first selection\n", ahd_name(ahd
));
6593 if ((sblkctl
& ENAB40
) != 0) {
6594 ahd_outb(ahd
, DSPDATACTL
,
6595 ahd_inb(ahd
, DSPDATACTL
) & ~BYPASSENAB
);
6597 if ((ahd_debug
& AHD_SHOW_MISC
) != 0)
6598 printk("%s: BYPASS now disabled\n", ahd_name(ahd
));
6601 ahd_outb(ahd
, SIMODE0
, ahd_inb(ahd
, SIMODE0
) & ~(ENSELDO
|ENSELDI
));
6602 ahd_outb(ahd
, CLRINT
, CLRSCSIINT
);
6603 ahd_restore_modes(ahd
, saved_modes
);
6604 ahd
->flags
|= AHD_HAD_FIRST_SEL
;
6607 /*************************** SCB Management ***********************************/
6609 ahd_add_col_list(struct ahd_softc
*ahd
, struct scb
*scb
, u_int col_idx
)
6611 struct scb_list
*free_list
;
6612 struct scb_tailq
*free_tailq
;
6613 struct scb
*first_scb
;
6615 scb
->flags
|= SCB_ON_COL_LIST
;
6616 AHD_SET_SCB_COL_IDX(scb
, col_idx
);
6617 free_list
= &ahd
->scb_data
.free_scb_lists
[col_idx
];
6618 free_tailq
= &ahd
->scb_data
.free_scbs
;
6619 first_scb
= LIST_FIRST(free_list
);
6620 if (first_scb
!= NULL
) {
6621 LIST_INSERT_AFTER(first_scb
, scb
, collision_links
);
6623 LIST_INSERT_HEAD(free_list
, scb
, collision_links
);
6624 TAILQ_INSERT_TAIL(free_tailq
, scb
, links
.tqe
);
6629 ahd_rem_col_list(struct ahd_softc
*ahd
, struct scb
*scb
)
6631 struct scb_list
*free_list
;
6632 struct scb_tailq
*free_tailq
;
6633 struct scb
*first_scb
;
6636 scb
->flags
&= ~SCB_ON_COL_LIST
;
6637 col_idx
= AHD_GET_SCB_COL_IDX(ahd
, scb
);
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
== scb
) {
6642 struct scb
*next_scb
;
6645 * Maintain order in the collision free
6646 * lists for fairness if this device has
6647 * other colliding tags active.
6649 next_scb
= LIST_NEXT(scb
, collision_links
);
6650 if (next_scb
!= NULL
) {
6651 TAILQ_INSERT_AFTER(free_tailq
, scb
,
6652 next_scb
, links
.tqe
);
6654 TAILQ_REMOVE(free_tailq
, scb
, links
.tqe
);
6656 LIST_REMOVE(scb
, collision_links
);
6660 * Get a free scb. If there are none, see if we can allocate a new SCB.
6663 ahd_get_scb(struct ahd_softc
*ahd
, u_int col_idx
)
6670 TAILQ_FOREACH(scb
, &ahd
->scb_data
.free_scbs
, links
.tqe
) {
6671 if (AHD_GET_SCB_COL_IDX(ahd
, scb
) != col_idx
) {
6672 ahd_rem_col_list(ahd
, scb
);
6676 if ((scb
= LIST_FIRST(&ahd
->scb_data
.any_dev_free_scb_list
)) == NULL
) {
6680 ahd_alloc_scbs(ahd
);
6683 LIST_REMOVE(scb
, links
.le
);
6684 if (col_idx
!= AHD_NEVER_COL_IDX
6685 && (scb
->col_scb
!= NULL
)
6686 && (scb
->col_scb
->flags
& SCB_ACTIVE
) == 0) {
6687 LIST_REMOVE(scb
->col_scb
, links
.le
);
6688 ahd_add_col_list(ahd
, scb
->col_scb
, col_idx
);
6691 scb
->flags
|= SCB_ACTIVE
;
6696 * Return an SCB resource to the free list.
6699 ahd_free_scb(struct ahd_softc
*ahd
, struct scb
*scb
)
6701 /* Clean up for the next user */
6702 scb
->flags
= SCB_FLAG_NONE
;
6703 scb
->hscb
->control
= 0;
6704 ahd
->scb_data
.scbindex
[SCB_GET_TAG(scb
)] = NULL
;
6706 if (scb
->col_scb
== NULL
) {
6709 * No collision possible. Just free normally.
6711 LIST_INSERT_HEAD(&ahd
->scb_data
.any_dev_free_scb_list
,
6713 } else if ((scb
->col_scb
->flags
& SCB_ON_COL_LIST
) != 0) {
6716 * The SCB we might have collided with is on
6717 * a free collision list. Put both SCBs on
6720 ahd_rem_col_list(ahd
, scb
->col_scb
);
6721 LIST_INSERT_HEAD(&ahd
->scb_data
.any_dev_free_scb_list
,
6723 LIST_INSERT_HEAD(&ahd
->scb_data
.any_dev_free_scb_list
,
6724 scb
->col_scb
, links
.le
);
6725 } else if ((scb
->col_scb
->flags
6726 & (SCB_PACKETIZED
|SCB_ACTIVE
)) == SCB_ACTIVE
6727 && (scb
->col_scb
->hscb
->control
& TAG_ENB
) != 0) {
6730 * The SCB we might collide with on the next allocation
6731 * is still active in a non-packetized, tagged, context.
6732 * Put us on the SCB collision list.
6734 ahd_add_col_list(ahd
, scb
,
6735 AHD_GET_SCB_COL_IDX(ahd
, scb
->col_scb
));
6738 * The SCB we might collide with on the next allocation
6739 * is either active in a packetized context, or free.
6740 * Since we can't collide, put this SCB on the generic
6743 LIST_INSERT_HEAD(&ahd
->scb_data
.any_dev_free_scb_list
,
6747 ahd_platform_scb_free(ahd
, scb
);
6751 ahd_alloc_scbs(struct ahd_softc
*ahd
)
6753 struct scb_data
*scb_data
;
6754 struct scb
*next_scb
;
6755 struct hardware_scb
*hscb
;
6756 struct map_node
*hscb_map
;
6757 struct map_node
*sg_map
;
6758 struct map_node
*sense_map
;
6760 uint8_t *sense_data
;
6761 dma_addr_t hscb_busaddr
;
6762 dma_addr_t sg_busaddr
;
6763 dma_addr_t sense_busaddr
;
6767 scb_data
= &ahd
->scb_data
;
6768 if (scb_data
->numscbs
>= AHD_SCB_MAX_ALLOC
)
6769 /* Can't allocate any more */
6772 if (scb_data
->scbs_left
!= 0) {
6775 offset
= (PAGE_SIZE
/ sizeof(*hscb
)) - scb_data
->scbs_left
;
6776 hscb_map
= SLIST_FIRST(&scb_data
->hscb_maps
);
6777 hscb
= &((struct hardware_scb
*)hscb_map
->vaddr
)[offset
];
6778 hscb_busaddr
= hscb_map
->physaddr
+ (offset
* sizeof(*hscb
));
6780 hscb_map
= kmalloc(sizeof(*hscb_map
), GFP_ATOMIC
);
6782 if (hscb_map
== NULL
)
6785 /* Allocate the next batch of hardware SCBs */
6786 if (ahd_dmamem_alloc(ahd
, scb_data
->hscb_dmat
,
6787 (void **)&hscb_map
->vaddr
,
6788 BUS_DMA_NOWAIT
, &hscb_map
->dmamap
) != 0) {
6793 SLIST_INSERT_HEAD(&scb_data
->hscb_maps
, hscb_map
, links
);
6795 ahd_dmamap_load(ahd
, scb_data
->hscb_dmat
, hscb_map
->dmamap
,
6796 hscb_map
->vaddr
, PAGE_SIZE
, ahd_dmamap_cb
,
6797 &hscb_map
->physaddr
, /*flags*/0);
6799 hscb
= (struct hardware_scb
*)hscb_map
->vaddr
;
6800 hscb_busaddr
= hscb_map
->physaddr
;
6801 scb_data
->scbs_left
= PAGE_SIZE
/ sizeof(*hscb
);
6804 if (scb_data
->sgs_left
!= 0) {
6807 offset
= ((ahd_sglist_allocsize(ahd
) / ahd_sglist_size(ahd
))
6808 - scb_data
->sgs_left
) * ahd_sglist_size(ahd
);
6809 sg_map
= SLIST_FIRST(&scb_data
->sg_maps
);
6810 segs
= sg_map
->vaddr
+ offset
;
6811 sg_busaddr
= sg_map
->physaddr
+ offset
;
6813 sg_map
= kmalloc(sizeof(*sg_map
), GFP_ATOMIC
);
6818 /* Allocate the next batch of S/G lists */
6819 if (ahd_dmamem_alloc(ahd
, scb_data
->sg_dmat
,
6820 (void **)&sg_map
->vaddr
,
6821 BUS_DMA_NOWAIT
, &sg_map
->dmamap
) != 0) {
6826 SLIST_INSERT_HEAD(&scb_data
->sg_maps
, sg_map
, links
);
6828 ahd_dmamap_load(ahd
, scb_data
->sg_dmat
, sg_map
->dmamap
,
6829 sg_map
->vaddr
, ahd_sglist_allocsize(ahd
),
6830 ahd_dmamap_cb
, &sg_map
->physaddr
, /*flags*/0);
6832 segs
= sg_map
->vaddr
;
6833 sg_busaddr
= sg_map
->physaddr
;
6834 scb_data
->sgs_left
=
6835 ahd_sglist_allocsize(ahd
) / ahd_sglist_size(ahd
);
6837 if (ahd_debug
& AHD_SHOW_MEMORY
)
6838 printk("Mapped SG data\n");
6842 if (scb_data
->sense_left
!= 0) {
6845 offset
= PAGE_SIZE
- (AHD_SENSE_BUFSIZE
* scb_data
->sense_left
);
6846 sense_map
= SLIST_FIRST(&scb_data
->sense_maps
);
6847 sense_data
= sense_map
->vaddr
+ offset
;
6848 sense_busaddr
= sense_map
->physaddr
+ offset
;
6850 sense_map
= kmalloc(sizeof(*sense_map
), GFP_ATOMIC
);
6852 if (sense_map
== NULL
)
6855 /* Allocate the next batch of sense buffers */
6856 if (ahd_dmamem_alloc(ahd
, scb_data
->sense_dmat
,
6857 (void **)&sense_map
->vaddr
,
6858 BUS_DMA_NOWAIT
, &sense_map
->dmamap
) != 0) {
6863 SLIST_INSERT_HEAD(&scb_data
->sense_maps
, sense_map
, links
);
6865 ahd_dmamap_load(ahd
, scb_data
->sense_dmat
, sense_map
->dmamap
,
6866 sense_map
->vaddr
, PAGE_SIZE
, ahd_dmamap_cb
,
6867 &sense_map
->physaddr
, /*flags*/0);
6869 sense_data
= sense_map
->vaddr
;
6870 sense_busaddr
= sense_map
->physaddr
;
6871 scb_data
->sense_left
= PAGE_SIZE
/ AHD_SENSE_BUFSIZE
;
6873 if (ahd_debug
& AHD_SHOW_MEMORY
)
6874 printk("Mapped sense data\n");
6878 newcount
= min(scb_data
->sense_left
, scb_data
->scbs_left
);
6879 newcount
= min(newcount
, scb_data
->sgs_left
);
6880 newcount
= min(newcount
, (AHD_SCB_MAX_ALLOC
- scb_data
->numscbs
));
6881 for (i
= 0; i
< newcount
; i
++) {
6882 struct scb_platform_data
*pdata
;
6885 next_scb
= kmalloc(sizeof(*next_scb
), GFP_ATOMIC
);
6886 if (next_scb
== NULL
)
6889 pdata
= kmalloc(sizeof(*pdata
), GFP_ATOMIC
);
6890 if (pdata
== NULL
) {
6894 next_scb
->platform_data
= pdata
;
6895 next_scb
->hscb_map
= hscb_map
;
6896 next_scb
->sg_map
= sg_map
;
6897 next_scb
->sense_map
= sense_map
;
6898 next_scb
->sg_list
= segs
;
6899 next_scb
->sense_data
= sense_data
;
6900 next_scb
->sense_busaddr
= sense_busaddr
;
6901 memset(hscb
, 0, sizeof(*hscb
));
6902 next_scb
->hscb
= hscb
;
6903 hscb
->hscb_busaddr
= ahd_htole32(hscb_busaddr
);
6906 * The sequencer always starts with the second entry.
6907 * The first entry is embedded in the scb.
6909 next_scb
->sg_list_busaddr
= sg_busaddr
;
6910 if ((ahd
->flags
& AHD_64BIT_ADDRESSING
) != 0)
6911 next_scb
->sg_list_busaddr
6912 += sizeof(struct ahd_dma64_seg
);
6914 next_scb
->sg_list_busaddr
+= sizeof(struct ahd_dma_seg
);
6915 next_scb
->ahd_softc
= ahd
;
6916 next_scb
->flags
= SCB_FLAG_NONE
;
6917 next_scb
->hscb
->tag
= ahd_htole16(scb_data
->numscbs
);
6918 col_tag
= scb_data
->numscbs
^ 0x100;
6919 next_scb
->col_scb
= ahd_find_scb_by_tag(ahd
, col_tag
);
6920 if (next_scb
->col_scb
!= NULL
)
6921 next_scb
->col_scb
->col_scb
= next_scb
;
6922 ahd_free_scb(ahd
, next_scb
);
6924 hscb_busaddr
+= sizeof(*hscb
);
6925 segs
+= ahd_sglist_size(ahd
);
6926 sg_busaddr
+= ahd_sglist_size(ahd
);
6927 sense_data
+= AHD_SENSE_BUFSIZE
;
6928 sense_busaddr
+= AHD_SENSE_BUFSIZE
;
6929 scb_data
->numscbs
++;
6930 scb_data
->sense_left
--;
6931 scb_data
->scbs_left
--;
6932 scb_data
->sgs_left
--;
6937 ahd_controller_info(struct ahd_softc
*ahd
, char *buf
)
6943 len
= sprintf(buf
, "%s: ", ahd_chip_names
[ahd
->chip
& AHD_CHIPID_MASK
]);
6946 speed
= "Ultra320 ";
6947 if ((ahd
->features
& AHD_WIDE
) != 0) {
6952 len
= sprintf(buf
, "%s%sChannel %c, SCSI Id=%d, ",
6953 speed
, type
, ahd
->channel
, ahd
->our_id
);
6956 sprintf(buf
, "%s, %d SCBs", ahd
->bus_description
,
6957 ahd
->scb_data
.maxhscbs
);
6960 static const char *channel_strings
[] = {
6967 static const char *termstat_strings
[] = {
6968 "Terminated Correctly",
6974 /***************************** Timer Facilities *******************************/
6976 ahd_timer_reset(struct timer_list
*timer
, int usec
)
6979 timer
->expires
= jiffies
+ (usec
* HZ
)/1000000;
6984 * Start the board, ready for normal operation
6987 ahd_init(struct ahd_softc
*ahd
)
6989 uint8_t *next_vaddr
;
6990 dma_addr_t next_baddr
;
6991 size_t driver_data_size
;
6995 uint8_t current_sensing
;
6998 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
7000 ahd
->stack_size
= ahd_probe_stack_size(ahd
);
7001 ahd
->saved_stack
= kmalloc_array(ahd
->stack_size
, sizeof(uint16_t),
7003 if (ahd
->saved_stack
== NULL
)
7007 * Verify that the compiler hasn't over-aggressively
7008 * padded important structures.
7010 if (sizeof(struct hardware_scb
) != 64)
7011 panic("Hardware SCB size is incorrect");
7014 if ((ahd_debug
& AHD_DEBUG_SEQUENCER
) != 0)
7015 ahd
->flags
|= AHD_SEQUENCER_DEBUG
;
7019 * Default to allowing initiator operations.
7021 ahd
->flags
|= AHD_INITIATORROLE
;
7024 * Only allow target mode features if this unit has them enabled.
7026 if ((AHD_TMODE_ENABLE
& (0x1 << ahd
->unit
)) == 0)
7027 ahd
->features
&= ~AHD_TARGETMODE
;
7032 * DMA tag for our command fifos and other data in system memory
7033 * the card's sequencer must be able to access. For initiator
7034 * roles, we need to allocate space for the qoutfifo. When providing
7035 * for the target mode role, we must additionally provide space for
7036 * the incoming target command fifo.
7038 driver_data_size
= AHD_SCB_MAX
* sizeof(*ahd
->qoutfifo
)
7039 + sizeof(struct hardware_scb
);
7040 if ((ahd
->features
& AHD_TARGETMODE
) != 0)
7041 driver_data_size
+= AHD_TMODE_CMDS
* sizeof(struct target_cmd
);
7042 if ((ahd
->bugs
& AHD_PKT_BITBUCKET_BUG
) != 0)
7043 driver_data_size
+= PKT_OVERRUN_BUFSIZE
;
7044 if (ahd_dma_tag_create(ahd
, ahd
->parent_dmat
, /*alignment*/1,
7045 /*boundary*/BUS_SPACE_MAXADDR_32BIT
+ 1,
7046 /*lowaddr*/BUS_SPACE_MAXADDR_32BIT
,
7047 /*highaddr*/BUS_SPACE_MAXADDR
,
7048 /*filter*/NULL
, /*filterarg*/NULL
,
7051 /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT
,
7052 /*flags*/0, &ahd
->shared_data_dmat
) != 0) {
7058 /* Allocation of driver data */
7059 if (ahd_dmamem_alloc(ahd
, ahd
->shared_data_dmat
,
7060 (void **)&ahd
->shared_data_map
.vaddr
,
7062 &ahd
->shared_data_map
.dmamap
) != 0) {
7068 /* And permanently map it in */
7069 ahd_dmamap_load(ahd
, ahd
->shared_data_dmat
, ahd
->shared_data_map
.dmamap
,
7070 ahd
->shared_data_map
.vaddr
, driver_data_size
,
7071 ahd_dmamap_cb
, &ahd
->shared_data_map
.physaddr
,
7073 ahd
->qoutfifo
= (struct ahd_completion
*)ahd
->shared_data_map
.vaddr
;
7074 next_vaddr
= (uint8_t *)&ahd
->qoutfifo
[AHD_QOUT_SIZE
];
7075 next_baddr
= ahd
->shared_data_map
.physaddr
7076 + AHD_QOUT_SIZE
*sizeof(struct ahd_completion
);
7077 if ((ahd
->features
& AHD_TARGETMODE
) != 0) {
7078 ahd
->targetcmds
= (struct target_cmd
*)next_vaddr
;
7079 next_vaddr
+= AHD_TMODE_CMDS
* sizeof(struct target_cmd
);
7080 next_baddr
+= AHD_TMODE_CMDS
* sizeof(struct target_cmd
);
7083 if ((ahd
->bugs
& AHD_PKT_BITBUCKET_BUG
) != 0) {
7084 ahd
->overrun_buf
= next_vaddr
;
7085 next_vaddr
+= PKT_OVERRUN_BUFSIZE
;
7086 next_baddr
+= PKT_OVERRUN_BUFSIZE
;
7090 * We need one SCB to serve as the "next SCB". Since the
7091 * tag identifier in this SCB will never be used, there is
7092 * no point in using a valid HSCB tag from an SCB pulled from
7093 * the standard free pool. So, we allocate this "sentinel"
7094 * specially from the DMA safe memory chunk used for the QOUTFIFO.
7096 ahd
->next_queued_hscb
= (struct hardware_scb
*)next_vaddr
;
7097 ahd
->next_queued_hscb_map
= &ahd
->shared_data_map
;
7098 ahd
->next_queued_hscb
->hscb_busaddr
= ahd_htole32(next_baddr
);
7102 /* Allocate SCB data now that buffer_dmat is initialized */
7103 if (ahd_init_scbdata(ahd
) != 0)
7106 if ((ahd
->flags
& AHD_INITIATORROLE
) == 0)
7107 ahd
->flags
&= ~AHD_RESET_BUS_A
;
7110 * Before committing these settings to the chip, give
7111 * the OSM one last chance to modify our configuration.
7113 ahd_platform_init(ahd
);
7115 /* Bring up the chip. */
7118 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
7120 if ((ahd
->flags
& AHD_CURRENT_SENSING
) == 0)
7124 * Verify termination based on current draw and
7125 * warn user if the bus is over/under terminated.
7127 error
= ahd_write_flexport(ahd
, FLXADDR_ROMSTAT_CURSENSECTL
,
7130 printk("%s: current sensing timeout 1\n", ahd_name(ahd
));
7133 for (i
= 20, fstat
= FLX_FSTAT_BUSY
;
7134 (fstat
& FLX_FSTAT_BUSY
) != 0 && i
; i
--) {
7135 error
= ahd_read_flexport(ahd
, FLXADDR_FLEXSTAT
, &fstat
);
7137 printk("%s: current sensing timeout 2\n",
7143 printk("%s: Timedout during current-sensing test\n",
7148 /* Latch Current Sensing status. */
7149 error
= ahd_read_flexport(ahd
, FLXADDR_CURRENT_STAT
, ¤t_sensing
);
7151 printk("%s: current sensing timeout 3\n", ahd_name(ahd
));
7155 /* Diable current sensing. */
7156 ahd_write_flexport(ahd
, FLXADDR_ROMSTAT_CURSENSECTL
, 0);
7159 if ((ahd_debug
& AHD_SHOW_TERMCTL
) != 0) {
7160 printk("%s: current_sensing == 0x%x\n",
7161 ahd_name(ahd
), current_sensing
);
7165 for (i
= 0; i
< 4; i
++, current_sensing
>>= FLX_CSTAT_SHIFT
) {
7168 term_stat
= (current_sensing
& FLX_CSTAT_MASK
);
7169 switch (term_stat
) {
7170 case FLX_CSTAT_OVER
:
7171 case FLX_CSTAT_UNDER
:
7174 case FLX_CSTAT_INVALID
:
7175 case FLX_CSTAT_OKAY
:
7176 if (warn_user
== 0 && bootverbose
== 0)
7178 printk("%s: %s Channel %s\n", ahd_name(ahd
),
7179 channel_strings
[i
], termstat_strings
[term_stat
]);
7184 printk("%s: WARNING. Termination is not configured correctly.\n"
7185 "%s: WARNING. SCSI bus operations may FAIL.\n",
7186 ahd_name(ahd
), ahd_name(ahd
));
7190 ahd_timer_reset(&ahd
->stat_timer
, AHD_STAT_UPDATE_US
);
7195 * (Re)initialize chip state after a chip reset.
7198 ahd_chip_init(struct ahd_softc
*ahd
)
7202 u_int scsiseq_template
;
7207 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
7209 * Take the LED out of diagnostic mode
7211 ahd_outb(ahd
, SBLKCTL
, ahd_inb(ahd
, SBLKCTL
) & ~(DIAGLEDEN
|DIAGLEDON
));
7214 * Return HS_MAILBOX to its default value.
7216 ahd
->hs_mailbox
= 0;
7217 ahd_outb(ahd
, HS_MAILBOX
, 0);
7219 /* Set the SCSI Id, SXFRCTL0, SXFRCTL1, and SIMODE1. */
7220 ahd_outb(ahd
, IOWNID
, ahd
->our_id
);
7221 ahd_outb(ahd
, TOWNID
, ahd
->our_id
);
7222 sxfrctl1
= (ahd
->flags
& AHD_TERM_ENB_A
) != 0 ? STPWEN
: 0;
7223 sxfrctl1
|= (ahd
->flags
& AHD_SPCHK_ENB_A
) != 0 ? ENSPCHK
: 0;
7224 if ((ahd
->bugs
& AHD_LONG_SETIMO_BUG
)
7225 && (ahd
->seltime
!= STIMESEL_MIN
)) {
7227 * The selection timer duration is twice as long
7228 * as it should be. Halve it by adding "1" to
7229 * the user specified setting.
7231 sxfrctl1
|= ahd
->seltime
+ STIMESEL_BUG_ADJ
;
7233 sxfrctl1
|= ahd
->seltime
;
7236 ahd_outb(ahd
, SXFRCTL0
, DFON
);
7237 ahd_outb(ahd
, SXFRCTL1
, sxfrctl1
|ahd
->seltime
|ENSTIMER
|ACTNEGEN
);
7238 ahd_outb(ahd
, SIMODE1
, ENSELTIMO
|ENSCSIRST
|ENSCSIPERR
);
7241 * Now that termination is set, wait for up
7242 * to 500ms for our transceivers to settle. If
7243 * the adapter does not have a cable attached,
7244 * the transceivers may never settle, so don't
7245 * complain if we fail here.
7248 (ahd_inb(ahd
, SBLKCTL
) & (ENAB40
|ENAB20
)) == 0 && wait
;
7252 /* Clear any false bus resets due to the transceivers settling */
7253 ahd_outb(ahd
, CLRSINT1
, CLRSCSIRSTI
);
7254 ahd_outb(ahd
, CLRINT
, CLRSCSIINT
);
7256 /* Initialize mode specific S/G state. */
7257 for (i
= 0; i
< 2; i
++) {
7258 ahd_set_modes(ahd
, AHD_MODE_DFF0
+ i
, AHD_MODE_DFF0
+ i
);
7259 ahd_outb(ahd
, LONGJMP_ADDR
+ 1, INVALID_ADDR
);
7260 ahd_outb(ahd
, SG_STATE
, 0);
7261 ahd_outb(ahd
, CLRSEQINTSRC
, 0xFF);
7262 ahd_outb(ahd
, SEQIMODE
,
7263 ENSAVEPTRS
|ENCFG4DATA
|ENCFG4ISTAT
7264 |ENCFG4TSTAT
|ENCFG4ICMD
|ENCFG4TCMD
);
7267 ahd_set_modes(ahd
, AHD_MODE_CFG
, AHD_MODE_CFG
);
7268 ahd_outb(ahd
, DSCOMMAND0
, ahd_inb(ahd
, DSCOMMAND0
)|MPARCKEN
|CACHETHEN
);
7269 ahd_outb(ahd
, DFF_THRSH
, RD_DFTHRSH_75
|WR_DFTHRSH_75
);
7270 ahd_outb(ahd
, SIMODE0
, ENIOERR
|ENOVERRUN
);
7271 ahd_outb(ahd
, SIMODE3
, ENNTRAMPERR
|ENOSRAMPERR
);
7272 if ((ahd
->bugs
& AHD_BUSFREEREV_BUG
) != 0) {
7273 ahd_outb(ahd
, OPTIONMODE
, AUTOACKEN
|AUTO_MSGOUT_DE
);
7275 ahd_outb(ahd
, OPTIONMODE
, AUTOACKEN
|BUSFREEREV
|AUTO_MSGOUT_DE
);
7277 ahd_outb(ahd
, SCSCHKN
, CURRFIFODEF
|WIDERESEN
|SHVALIDSTDIS
);
7278 if ((ahd
->chip
& AHD_BUS_MASK
) == AHD_PCIX
)
7280 * Do not issue a target abort when a split completion
7281 * error occurs. Let our PCIX interrupt handler deal
7282 * with it instead. H2A4 Razor #625
7284 ahd_outb(ahd
, PCIXCTL
, ahd_inb(ahd
, PCIXCTL
) | SPLTSTADIS
);
7286 if ((ahd
->bugs
& AHD_LQOOVERRUN_BUG
) != 0)
7287 ahd_outb(ahd
, LQOSCSCTL
, LQONOCHKOVER
);
7290 * Tweak IOCELL settings.
7292 if ((ahd
->flags
& AHD_HP_BOARD
) != 0) {
7293 for (i
= 0; i
< NUMDSPS
; i
++) {
7294 ahd_outb(ahd
, DSPSELECT
, i
);
7295 ahd_outb(ahd
, WRTBIASCTL
, WRTBIASCTL_HP_DEFAULT
);
7298 if ((ahd_debug
& AHD_SHOW_MISC
) != 0)
7299 printk("%s: WRTBIASCTL now 0x%x\n", ahd_name(ahd
),
7300 WRTBIASCTL_HP_DEFAULT
);
7303 ahd_setup_iocell_workaround(ahd
);
7306 * Enable LQI Manager interrupts.
7308 ahd_outb(ahd
, LQIMODE1
, ENLQIPHASE_LQ
|ENLQIPHASE_NLQ
|ENLIQABORT
7309 | ENLQICRCI_LQ
|ENLQICRCI_NLQ
|ENLQIBADLQI
7310 | ENLQIOVERI_LQ
|ENLQIOVERI_NLQ
);
7311 ahd_outb(ahd
, LQOMODE0
, ENLQOATNLQ
|ENLQOATNPKT
|ENLQOTCRC
);
7313 * We choose to have the sequencer catch LQOPHCHGINPKT errors
7314 * manually for the command phase at the start of a packetized
7315 * selection case. ENLQOBUSFREE should be made redundant by
7316 * the BUSFREE interrupt, but it seems that some LQOBUSFREE
7317 * events fail to assert the BUSFREE interrupt so we must
7318 * also enable LQOBUSFREE interrupts.
7320 ahd_outb(ahd
, LQOMODE1
, ENLQOBUSFREE
);
7323 * Setup sequencer interrupt handlers.
7325 ahd_outw(ahd
, INTVEC1_ADDR
, ahd_resolve_seqaddr(ahd
, LABEL_seq_isr
));
7326 ahd_outw(ahd
, INTVEC2_ADDR
, ahd_resolve_seqaddr(ahd
, LABEL_timer_isr
));
7329 * Setup SCB Offset registers.
7331 if ((ahd
->bugs
& AHD_PKT_LUN_BUG
) != 0) {
7332 ahd_outb(ahd
, LUNPTR
, offsetof(struct hardware_scb
,
7335 ahd_outb(ahd
, LUNPTR
, offsetof(struct hardware_scb
, lun
));
7337 ahd_outb(ahd
, CMDLENPTR
, offsetof(struct hardware_scb
, cdb_len
));
7338 ahd_outb(ahd
, ATTRPTR
, offsetof(struct hardware_scb
, task_attribute
));
7339 ahd_outb(ahd
, FLAGPTR
, offsetof(struct hardware_scb
, task_management
));
7340 ahd_outb(ahd
, CMDPTR
, offsetof(struct hardware_scb
,
7341 shared_data
.idata
.cdb
));
7342 ahd_outb(ahd
, QNEXTPTR
,
7343 offsetof(struct hardware_scb
, next_hscb_busaddr
));
7344 ahd_outb(ahd
, ABRTBITPTR
, MK_MESSAGE_BIT_OFFSET
);
7345 ahd_outb(ahd
, ABRTBYTEPTR
, offsetof(struct hardware_scb
, control
));
7346 if ((ahd
->bugs
& AHD_PKT_LUN_BUG
) != 0) {
7347 ahd_outb(ahd
, LUNLEN
,
7348 sizeof(ahd
->next_queued_hscb
->pkt_long_lun
) - 1);
7350 ahd_outb(ahd
, LUNLEN
, LUNLEN_SINGLE_LEVEL_LUN
);
7352 ahd_outb(ahd
, CDBLIMIT
, SCB_CDB_LEN_PTR
- 1);
7353 ahd_outb(ahd
, MAXCMD
, 0xFF);
7354 ahd_outb(ahd
, SCBAUTOPTR
,
7355 AUSCBPTR_EN
| offsetof(struct hardware_scb
, tag
));
7357 /* We haven't been enabled for target mode yet. */
7358 ahd_outb(ahd
, MULTARGID
, 0);
7359 ahd_outb(ahd
, MULTARGID
+ 1, 0);
7361 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
7362 /* Initialize the negotiation table. */
7363 if ((ahd
->features
& AHD_NEW_IOCELL_OPTS
) == 0) {
7365 * Clear the spare bytes in the neg table to avoid
7366 * spurious parity errors.
7368 for (target
= 0; target
< AHD_NUM_TARGETS
; target
++) {
7369 ahd_outb(ahd
, NEGOADDR
, target
);
7370 ahd_outb(ahd
, ANNEXCOL
, AHD_ANNEXCOL_PER_DEV0
);
7371 for (i
= 0; i
< AHD_NUM_PER_DEV_ANNEXCOLS
; i
++)
7372 ahd_outb(ahd
, ANNEXDAT
, 0);
7375 for (target
= 0; target
< AHD_NUM_TARGETS
; target
++) {
7376 struct ahd_devinfo devinfo
;
7377 struct ahd_initiator_tinfo
*tinfo
;
7378 struct ahd_tmode_tstate
*tstate
;
7380 tinfo
= ahd_fetch_transinfo(ahd
, 'A', ahd
->our_id
,
7382 ahd_compile_devinfo(&devinfo
, ahd
->our_id
,
7383 target
, CAM_LUN_WILDCARD
,
7384 'A', ROLE_INITIATOR
);
7385 ahd_update_neg_table(ahd
, &devinfo
, &tinfo
->curr
);
7388 ahd_outb(ahd
, CLRSINT3
, NTRAMPERR
|OSRAMPERR
);
7389 ahd_outb(ahd
, CLRINT
, CLRSCSIINT
);
7391 #ifdef NEEDS_MORE_TESTING
7393 * Always enable abort on incoming L_Qs if this feature is
7394 * supported. We use this to catch invalid SCB references.
7396 if ((ahd
->bugs
& AHD_ABORT_LQI_BUG
) == 0)
7397 ahd_outb(ahd
, LQCTL1
, ABORTPENDING
);
7400 ahd_outb(ahd
, LQCTL1
, 0);
7402 /* All of our queues are empty */
7403 ahd
->qoutfifonext
= 0;
7404 ahd
->qoutfifonext_valid_tag
= QOUTFIFO_ENTRY_VALID
;
7405 ahd_outb(ahd
, QOUTFIFO_ENTRY_VALID_TAG
, QOUTFIFO_ENTRY_VALID
);
7406 for (i
= 0; i
< AHD_QOUT_SIZE
; i
++)
7407 ahd
->qoutfifo
[i
].valid_tag
= 0;
7408 ahd_sync_qoutfifo(ahd
, BUS_DMASYNC_PREREAD
);
7410 ahd
->qinfifonext
= 0;
7411 for (i
= 0; i
< AHD_QIN_SIZE
; i
++)
7412 ahd
->qinfifo
[i
] = SCB_LIST_NULL
;
7414 if ((ahd
->features
& AHD_TARGETMODE
) != 0) {
7415 /* All target command blocks start out invalid. */
7416 for (i
= 0; i
< AHD_TMODE_CMDS
; i
++)
7417 ahd
->targetcmds
[i
].cmd_valid
= 0;
7418 ahd_sync_tqinfifo(ahd
, BUS_DMASYNC_PREREAD
);
7419 ahd
->tqinfifonext
= 1;
7420 ahd_outb(ahd
, KERNEL_TQINPOS
, ahd
->tqinfifonext
- 1);
7421 ahd_outb(ahd
, TQINPOS
, ahd
->tqinfifonext
);
7424 /* Initialize Scratch Ram. */
7425 ahd_outb(ahd
, SEQ_FLAGS
, 0);
7426 ahd_outb(ahd
, SEQ_FLAGS2
, 0);
7428 /* We don't have any waiting selections */
7429 ahd_outw(ahd
, WAITING_TID_HEAD
, SCB_LIST_NULL
);
7430 ahd_outw(ahd
, WAITING_TID_TAIL
, SCB_LIST_NULL
);
7431 ahd_outw(ahd
, MK_MESSAGE_SCB
, SCB_LIST_NULL
);
7432 ahd_outw(ahd
, MK_MESSAGE_SCSIID
, 0xFF);
7433 for (i
= 0; i
< AHD_NUM_TARGETS
; i
++)
7434 ahd_outw(ahd
, WAITING_SCB_TAILS
+ (2 * i
), SCB_LIST_NULL
);
7437 * Nobody is waiting to be DMAed into the QOUTFIFO.
7439 ahd_outw(ahd
, COMPLETE_SCB_HEAD
, SCB_LIST_NULL
);
7440 ahd_outw(ahd
, COMPLETE_SCB_DMAINPROG_HEAD
, SCB_LIST_NULL
);
7441 ahd_outw(ahd
, COMPLETE_DMA_SCB_HEAD
, SCB_LIST_NULL
);
7442 ahd_outw(ahd
, COMPLETE_DMA_SCB_TAIL
, SCB_LIST_NULL
);
7443 ahd_outw(ahd
, COMPLETE_ON_QFREEZE_HEAD
, SCB_LIST_NULL
);
7446 * The Freeze Count is 0.
7448 ahd
->qfreeze_cnt
= 0;
7449 ahd_outw(ahd
, QFREEZE_COUNT
, 0);
7450 ahd_outw(ahd
, KERNEL_QFREEZE_COUNT
, 0);
7453 * Tell the sequencer where it can find our arrays in memory.
7455 busaddr
= ahd
->shared_data_map
.physaddr
;
7456 ahd_outl(ahd
, SHARED_DATA_ADDR
, busaddr
);
7457 ahd_outl(ahd
, QOUTFIFO_NEXT_ADDR
, busaddr
);
7460 * Setup the allowed SCSI Sequences based on operational mode.
7461 * If we are a target, we'll enable select in operations once
7462 * we've had a lun enabled.
7464 scsiseq_template
= ENAUTOATNP
;
7465 if ((ahd
->flags
& AHD_INITIATORROLE
) != 0)
7466 scsiseq_template
|= ENRSELI
;
7467 ahd_outb(ahd
, SCSISEQ_TEMPLATE
, scsiseq_template
);
7469 /* There are no busy SCBs yet. */
7470 for (target
= 0; target
< AHD_NUM_TARGETS
; target
++) {
7473 for (lun
= 0; lun
< AHD_NUM_LUNS_NONPKT
; lun
++)
7474 ahd_unbusy_tcl(ahd
, BUILD_TCL_RAW(target
, 'A', lun
));
7478 * Initialize the group code to command length table.
7479 * Vendor Unique codes are set to 0 so we only capture
7480 * the first byte of the cdb. These can be overridden
7481 * when target mode is enabled.
7483 ahd_outb(ahd
, CMDSIZE_TABLE
, 5);
7484 ahd_outb(ahd
, CMDSIZE_TABLE
+ 1, 9);
7485 ahd_outb(ahd
, CMDSIZE_TABLE
+ 2, 9);
7486 ahd_outb(ahd
, CMDSIZE_TABLE
+ 3, 0);
7487 ahd_outb(ahd
, CMDSIZE_TABLE
+ 4, 15);
7488 ahd_outb(ahd
, CMDSIZE_TABLE
+ 5, 11);
7489 ahd_outb(ahd
, CMDSIZE_TABLE
+ 6, 0);
7490 ahd_outb(ahd
, CMDSIZE_TABLE
+ 7, 0);
7492 /* Tell the sequencer of our initial queue positions */
7493 ahd_set_modes(ahd
, AHD_MODE_CCHAN
, AHD_MODE_CCHAN
);
7494 ahd_outb(ahd
, QOFF_CTLSTA
, SCB_QSIZE_512
);
7495 ahd
->qinfifonext
= 0;
7496 ahd_set_hnscb_qoff(ahd
, ahd
->qinfifonext
);
7497 ahd_set_hescb_qoff(ahd
, 0);
7498 ahd_set_snscb_qoff(ahd
, 0);
7499 ahd_set_sescb_qoff(ahd
, 0);
7500 ahd_set_sdscb_qoff(ahd
, 0);
7503 * Tell the sequencer which SCB will be the next one it receives.
7505 busaddr
= ahd_le32toh(ahd
->next_queued_hscb
->hscb_busaddr
);
7506 ahd_outl(ahd
, NEXT_QUEUED_SCB_ADDR
, busaddr
);
7509 * Default to coalescing disabled.
7511 ahd_outw(ahd
, INT_COALESCING_CMDCOUNT
, 0);
7512 ahd_outw(ahd
, CMDS_PENDING
, 0);
7513 ahd_update_coalescing_values(ahd
, ahd
->int_coalescing_timer
,
7514 ahd
->int_coalescing_maxcmds
,
7515 ahd
->int_coalescing_mincmds
);
7516 ahd_enable_coalescing(ahd
, FALSE
);
7519 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
7521 if (ahd
->features
& AHD_AIC79XXB_SLOWCRC
) {
7522 u_int negodat3
= ahd_inb(ahd
, NEGCONOPTS
);
7524 negodat3
|= ENSLOWCRC
;
7525 ahd_outb(ahd
, NEGCONOPTS
, negodat3
);
7526 negodat3
= ahd_inb(ahd
, NEGCONOPTS
);
7527 if (!(negodat3
& ENSLOWCRC
))
7528 printk("aic79xx: failed to set the SLOWCRC bit\n");
7530 printk("aic79xx: SLOWCRC bit set\n");
7535 * Setup default device and controller settings.
7536 * This should only be called if our probe has
7537 * determined that no configuration data is available.
7540 ahd_default_config(struct ahd_softc
*ahd
)
7547 * Allocate a tstate to house information for our
7548 * initiator presence on the bus as well as the user
7549 * data for any target mode initiator.
7551 if (ahd_alloc_tstate(ahd
, ahd
->our_id
, 'A') == NULL
) {
7552 printk("%s: unable to allocate ahd_tmode_tstate. "
7553 "Failing attach\n", ahd_name(ahd
));
7557 for (targ
= 0; targ
< AHD_NUM_TARGETS
; targ
++) {
7558 struct ahd_devinfo devinfo
;
7559 struct ahd_initiator_tinfo
*tinfo
;
7560 struct ahd_tmode_tstate
*tstate
;
7561 uint16_t target_mask
;
7563 tinfo
= ahd_fetch_transinfo(ahd
, 'A', ahd
->our_id
,
7566 * We support SPC2 and SPI4.
7568 tinfo
->user
.protocol_version
= 4;
7569 tinfo
->user
.transport_version
= 4;
7571 target_mask
= 0x01 << targ
;
7572 ahd
->user_discenable
|= target_mask
;
7573 tstate
->discenable
|= target_mask
;
7574 ahd
->user_tagenable
|= target_mask
;
7575 #ifdef AHD_FORCE_160
7576 tinfo
->user
.period
= AHD_SYNCRATE_DT
;
7578 tinfo
->user
.period
= AHD_SYNCRATE_160
;
7580 tinfo
->user
.offset
= MAX_OFFSET
;
7581 tinfo
->user
.ppr_options
= MSG_EXT_PPR_RD_STRM
7582 | MSG_EXT_PPR_WR_FLOW
7583 | MSG_EXT_PPR_HOLD_MCS
7584 | MSG_EXT_PPR_IU_REQ
7585 | MSG_EXT_PPR_QAS_REQ
7586 | MSG_EXT_PPR_DT_REQ
;
7587 if ((ahd
->features
& AHD_RTI
) != 0)
7588 tinfo
->user
.ppr_options
|= MSG_EXT_PPR_RTI
;
7590 tinfo
->user
.width
= MSG_EXT_WDTR_BUS_16_BIT
;
7593 * Start out Async/Narrow/Untagged and with
7594 * conservative protocol support.
7596 tinfo
->goal
.protocol_version
= 2;
7597 tinfo
->goal
.transport_version
= 2;
7598 tinfo
->curr
.protocol_version
= 2;
7599 tinfo
->curr
.transport_version
= 2;
7600 ahd_compile_devinfo(&devinfo
, ahd
->our_id
,
7601 targ
, CAM_LUN_WILDCARD
,
7602 'A', ROLE_INITIATOR
);
7603 tstate
->tagenable
&= ~target_mask
;
7604 ahd_set_width(ahd
, &devinfo
, MSG_EXT_WDTR_BUS_8_BIT
,
7605 AHD_TRANS_CUR
|AHD_TRANS_GOAL
, /*paused*/TRUE
);
7606 ahd_set_syncrate(ahd
, &devinfo
, /*period*/0, /*offset*/0,
7607 /*ppr_options*/0, AHD_TRANS_CUR
|AHD_TRANS_GOAL
,
7614 * Parse device configuration information.
7617 ahd_parse_cfgdata(struct ahd_softc
*ahd
, struct seeprom_config
*sc
)
7622 max_targ
= sc
->max_targets
& CFMAXTARG
;
7623 ahd
->our_id
= sc
->brtime_id
& CFSCSIID
;
7626 * Allocate a tstate to house information for our
7627 * initiator presence on the bus as well as the user
7628 * data for any target mode initiator.
7630 if (ahd_alloc_tstate(ahd
, ahd
->our_id
, 'A') == NULL
) {
7631 printk("%s: unable to allocate ahd_tmode_tstate. "
7632 "Failing attach\n", ahd_name(ahd
));
7636 for (targ
= 0; targ
< max_targ
; targ
++) {
7637 struct ahd_devinfo devinfo
;
7638 struct ahd_initiator_tinfo
*tinfo
;
7639 struct ahd_transinfo
*user_tinfo
;
7640 struct ahd_tmode_tstate
*tstate
;
7641 uint16_t target_mask
;
7643 tinfo
= ahd_fetch_transinfo(ahd
, 'A', ahd
->our_id
,
7645 user_tinfo
= &tinfo
->user
;
7648 * We support SPC2 and SPI4.
7650 tinfo
->user
.protocol_version
= 4;
7651 tinfo
->user
.transport_version
= 4;
7653 target_mask
= 0x01 << targ
;
7654 ahd
->user_discenable
&= ~target_mask
;
7655 tstate
->discenable
&= ~target_mask
;
7656 ahd
->user_tagenable
&= ~target_mask
;
7657 if (sc
->device_flags
[targ
] & CFDISC
) {
7658 tstate
->discenable
|= target_mask
;
7659 ahd
->user_discenable
|= target_mask
;
7660 ahd
->user_tagenable
|= target_mask
;
7663 * Cannot be packetized without disconnection.
7665 sc
->device_flags
[targ
] &= ~CFPACKETIZED
;
7668 user_tinfo
->ppr_options
= 0;
7669 user_tinfo
->period
= (sc
->device_flags
[targ
] & CFXFER
);
7670 if (user_tinfo
->period
< CFXFER_ASYNC
) {
7671 if (user_tinfo
->period
<= AHD_PERIOD_10MHz
)
7672 user_tinfo
->ppr_options
|= MSG_EXT_PPR_DT_REQ
;
7673 user_tinfo
->offset
= MAX_OFFSET
;
7675 user_tinfo
->offset
= 0;
7676 user_tinfo
->period
= AHD_ASYNC_XFER_PERIOD
;
7678 #ifdef AHD_FORCE_160
7679 if (user_tinfo
->period
<= AHD_SYNCRATE_160
)
7680 user_tinfo
->period
= AHD_SYNCRATE_DT
;
7683 if ((sc
->device_flags
[targ
] & CFPACKETIZED
) != 0) {
7684 user_tinfo
->ppr_options
|= MSG_EXT_PPR_RD_STRM
7685 | MSG_EXT_PPR_WR_FLOW
7686 | MSG_EXT_PPR_HOLD_MCS
7687 | MSG_EXT_PPR_IU_REQ
;
7688 if ((ahd
->features
& AHD_RTI
) != 0)
7689 user_tinfo
->ppr_options
|= MSG_EXT_PPR_RTI
;
7692 if ((sc
->device_flags
[targ
] & CFQAS
) != 0)
7693 user_tinfo
->ppr_options
|= MSG_EXT_PPR_QAS_REQ
;
7695 if ((sc
->device_flags
[targ
] & CFWIDEB
) != 0)
7696 user_tinfo
->width
= MSG_EXT_WDTR_BUS_16_BIT
;
7698 user_tinfo
->width
= MSG_EXT_WDTR_BUS_8_BIT
;
7700 if ((ahd_debug
& AHD_SHOW_MISC
) != 0)
7701 printk("(%d): %x:%x:%x:%x\n", targ
, user_tinfo
->width
,
7702 user_tinfo
->period
, user_tinfo
->offset
,
7703 user_tinfo
->ppr_options
);
7706 * Start out Async/Narrow/Untagged and with
7707 * conservative protocol support.
7709 tstate
->tagenable
&= ~target_mask
;
7710 tinfo
->goal
.protocol_version
= 2;
7711 tinfo
->goal
.transport_version
= 2;
7712 tinfo
->curr
.protocol_version
= 2;
7713 tinfo
->curr
.transport_version
= 2;
7714 ahd_compile_devinfo(&devinfo
, ahd
->our_id
,
7715 targ
, CAM_LUN_WILDCARD
,
7716 'A', ROLE_INITIATOR
);
7717 ahd_set_width(ahd
, &devinfo
, MSG_EXT_WDTR_BUS_8_BIT
,
7718 AHD_TRANS_CUR
|AHD_TRANS_GOAL
, /*paused*/TRUE
);
7719 ahd_set_syncrate(ahd
, &devinfo
, /*period*/0, /*offset*/0,
7720 /*ppr_options*/0, AHD_TRANS_CUR
|AHD_TRANS_GOAL
,
7724 ahd
->flags
&= ~AHD_SPCHK_ENB_A
;
7725 if (sc
->bios_control
& CFSPARITY
)
7726 ahd
->flags
|= AHD_SPCHK_ENB_A
;
7728 ahd
->flags
&= ~AHD_RESET_BUS_A
;
7729 if (sc
->bios_control
& CFRESETB
)
7730 ahd
->flags
|= AHD_RESET_BUS_A
;
7732 ahd
->flags
&= ~AHD_EXTENDED_TRANS_A
;
7733 if (sc
->bios_control
& CFEXTEND
)
7734 ahd
->flags
|= AHD_EXTENDED_TRANS_A
;
7736 ahd
->flags
&= ~AHD_BIOS_ENABLED
;
7737 if ((sc
->bios_control
& CFBIOSSTATE
) == CFBS_ENABLED
)
7738 ahd
->flags
|= AHD_BIOS_ENABLED
;
7740 ahd
->flags
&= ~AHD_STPWLEVEL_A
;
7741 if ((sc
->adapter_control
& CFSTPWLEVEL
) != 0)
7742 ahd
->flags
|= AHD_STPWLEVEL_A
;
7748 * Parse device configuration information.
7751 ahd_parse_vpddata(struct ahd_softc
*ahd
, struct vpd_config
*vpd
)
7755 error
= ahd_verify_vpd_cksum(vpd
);
7758 if ((vpd
->bios_flags
& VPDBOOTHOST
) != 0)
7759 ahd
->flags
|= AHD_BOOT_CHANNEL
;
7764 ahd_intr_enable(struct ahd_softc
*ahd
, int enable
)
7768 hcntrl
= ahd_inb(ahd
, HCNTRL
);
7770 ahd
->pause
&= ~INTEN
;
7771 ahd
->unpause
&= ~INTEN
;
7774 ahd
->pause
|= INTEN
;
7775 ahd
->unpause
|= INTEN
;
7777 ahd_outb(ahd
, HCNTRL
, hcntrl
);
7781 ahd_update_coalescing_values(struct ahd_softc
*ahd
, u_int timer
, u_int maxcmds
,
7784 if (timer
> AHD_TIMER_MAX_US
)
7785 timer
= AHD_TIMER_MAX_US
;
7786 ahd
->int_coalescing_timer
= timer
;
7788 if (maxcmds
> AHD_INT_COALESCING_MAXCMDS_MAX
)
7789 maxcmds
= AHD_INT_COALESCING_MAXCMDS_MAX
;
7790 if (mincmds
> AHD_INT_COALESCING_MINCMDS_MAX
)
7791 mincmds
= AHD_INT_COALESCING_MINCMDS_MAX
;
7792 ahd
->int_coalescing_maxcmds
= maxcmds
;
7793 ahd_outw(ahd
, INT_COALESCING_TIMER
, timer
/ AHD_TIMER_US_PER_TICK
);
7794 ahd_outb(ahd
, INT_COALESCING_MAXCMDS
, -maxcmds
);
7795 ahd_outb(ahd
, INT_COALESCING_MINCMDS
, -mincmds
);
7799 ahd_enable_coalescing(struct ahd_softc
*ahd
, int enable
)
7802 ahd
->hs_mailbox
&= ~ENINT_COALESCE
;
7804 ahd
->hs_mailbox
|= ENINT_COALESCE
;
7805 ahd_outb(ahd
, HS_MAILBOX
, ahd
->hs_mailbox
);
7806 ahd_flush_device_writes(ahd
);
7807 ahd_run_qoutfifo(ahd
);
7811 * Ensure that the card is paused in a location
7812 * outside of all critical sections and that all
7813 * pending work is completed prior to returning.
7814 * This routine should only be called from outside
7815 * an interrupt context.
7818 ahd_pause_and_flushwork(struct ahd_softc
*ahd
)
7824 ahd
->flags
|= AHD_ALL_INTERRUPTS
;
7827 * Freeze the outgoing selections. We do this only
7828 * until we are safely paused without further selections
7832 ahd_outw(ahd
, KERNEL_QFREEZE_COUNT
, ahd
->qfreeze_cnt
);
7833 ahd_outb(ahd
, SEQ_FLAGS2
, ahd_inb(ahd
, SEQ_FLAGS2
) | SELECTOUT_QFROZEN
);
7838 * Give the sequencer some time to service
7839 * any active selections.
7845 intstat
= ahd_inb(ahd
, INTSTAT
);
7846 if ((intstat
& INT_PEND
) == 0) {
7847 ahd_clear_critical_section(ahd
);
7848 intstat
= ahd_inb(ahd
, INTSTAT
);
7851 && (intstat
!= 0xFF || (ahd
->features
& AHD_REMOVABLE
) == 0)
7852 && ((intstat
& INT_PEND
) != 0
7853 || (ahd_inb(ahd
, SCSISEQ0
) & ENSELO
) != 0
7854 || (ahd_inb(ahd
, SSTAT0
) & (SELDO
|SELINGO
)) != 0));
7856 if (maxloops
== 0) {
7857 printk("Infinite interrupt loop, INTSTAT = %x",
7858 ahd_inb(ahd
, INTSTAT
));
7861 ahd_outw(ahd
, KERNEL_QFREEZE_COUNT
, ahd
->qfreeze_cnt
);
7863 ahd_flush_qoutfifo(ahd
);
7865 ahd
->flags
&= ~AHD_ALL_INTERRUPTS
;
7869 ahd_suspend(struct ahd_softc
*ahd
)
7871 ahd_pause_and_flushwork(ahd
);
7873 if (LIST_FIRST(&ahd
->pending_scbs
) != NULL
) {
7882 ahd_resume(struct ahd_softc
*ahd
)
7884 ahd_reset(ahd
, /*reinit*/TRUE
);
7885 ahd_intr_enable(ahd
, TRUE
);
7889 /************************** Busy Target Table *********************************/
7891 * Set SCBPTR to the SCB that contains the busy
7892 * table entry for TCL. Return the offset into
7893 * the SCB that contains the entry for TCL.
7894 * saved_scbid is dereferenced and set to the
7895 * scbid that should be restored once manipualtion
7896 * of the TCL entry is complete.
7899 ahd_index_busy_tcl(struct ahd_softc
*ahd
, u_int
*saved_scbid
, u_int tcl
)
7902 * Index to the SCB that contains the busy entry.
7904 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
7905 *saved_scbid
= ahd_get_scbptr(ahd
);
7906 ahd_set_scbptr(ahd
, TCL_LUN(tcl
)
7907 | ((TCL_TARGET_OFFSET(tcl
) & 0xC) << 4));
7910 * And now calculate the SCB offset to the entry.
7911 * Each entry is 2 bytes wide, hence the
7912 * multiplication by 2.
7914 return (((TCL_TARGET_OFFSET(tcl
) & 0x3) << 1) + SCB_DISCONNECTED_LISTS
);
7918 * Return the untagged transaction id for a given target/channel lun.
7921 ahd_find_busy_tcl(struct ahd_softc
*ahd
, u_int tcl
)
7927 scb_offset
= ahd_index_busy_tcl(ahd
, &saved_scbptr
, tcl
);
7928 scbid
= ahd_inw_scbram(ahd
, scb_offset
);
7929 ahd_set_scbptr(ahd
, saved_scbptr
);
7934 ahd_busy_tcl(struct ahd_softc
*ahd
, u_int tcl
, u_int scbid
)
7939 scb_offset
= ahd_index_busy_tcl(ahd
, &saved_scbptr
, tcl
);
7940 ahd_outw(ahd
, scb_offset
, scbid
);
7941 ahd_set_scbptr(ahd
, saved_scbptr
);
7944 /************************** SCB and SCB queue management **********************/
7946 ahd_match_scb(struct ahd_softc
*ahd
, struct scb
*scb
, int target
,
7947 char channel
, int lun
, u_int tag
, role_t role
)
7949 int targ
= SCB_GET_TARGET(ahd
, scb
);
7950 char chan
= SCB_GET_CHANNEL(ahd
, scb
);
7951 int slun
= SCB_GET_LUN(scb
);
7954 match
= ((chan
== channel
) || (channel
== ALL_CHANNELS
));
7956 match
= ((targ
== target
) || (target
== CAM_TARGET_WILDCARD
));
7958 match
= ((lun
== slun
) || (lun
== CAM_LUN_WILDCARD
));
7960 #ifdef AHD_TARGET_MODE
7963 group
= XPT_FC_GROUP(scb
->io_ctx
->ccb_h
.func_code
);
7964 if (role
== ROLE_INITIATOR
) {
7965 match
= (group
!= XPT_FC_GROUP_TMODE
)
7966 && ((tag
== SCB_GET_TAG(scb
))
7967 || (tag
== SCB_LIST_NULL
));
7968 } else if (role
== ROLE_TARGET
) {
7969 match
= (group
== XPT_FC_GROUP_TMODE
)
7970 && ((tag
== scb
->io_ctx
->csio
.tag_id
)
7971 || (tag
== SCB_LIST_NULL
));
7973 #else /* !AHD_TARGET_MODE */
7974 match
= ((tag
== SCB_GET_TAG(scb
)) || (tag
== SCB_LIST_NULL
));
7975 #endif /* AHD_TARGET_MODE */
7982 ahd_freeze_devq(struct ahd_softc
*ahd
, struct scb
*scb
)
7988 target
= SCB_GET_TARGET(ahd
, scb
);
7989 lun
= SCB_GET_LUN(scb
);
7990 channel
= SCB_GET_CHANNEL(ahd
, scb
);
7992 ahd_search_qinfifo(ahd
, target
, channel
, lun
,
7993 /*tag*/SCB_LIST_NULL
, ROLE_UNKNOWN
,
7994 CAM_REQUEUE_REQ
, SEARCH_COMPLETE
);
7996 ahd_platform_freeze_devq(ahd
, scb
);
8000 ahd_qinfifo_requeue_tail(struct ahd_softc
*ahd
, struct scb
*scb
)
8002 struct scb
*prev_scb
;
8003 ahd_mode_state saved_modes
;
8005 saved_modes
= ahd_save_modes(ahd
);
8006 ahd_set_modes(ahd
, AHD_MODE_CCHAN
, AHD_MODE_CCHAN
);
8008 if (ahd_qinfifo_count(ahd
) != 0) {
8012 prev_pos
= AHD_QIN_WRAP(ahd
->qinfifonext
- 1);
8013 prev_tag
= ahd
->qinfifo
[prev_pos
];
8014 prev_scb
= ahd_lookup_scb(ahd
, prev_tag
);
8016 ahd_qinfifo_requeue(ahd
, prev_scb
, scb
);
8017 ahd_set_hnscb_qoff(ahd
, ahd
->qinfifonext
);
8018 ahd_restore_modes(ahd
, saved_modes
);
8022 ahd_qinfifo_requeue(struct ahd_softc
*ahd
, struct scb
*prev_scb
,
8025 if (prev_scb
== NULL
) {
8028 busaddr
= ahd_le32toh(scb
->hscb
->hscb_busaddr
);
8029 ahd_outl(ahd
, NEXT_QUEUED_SCB_ADDR
, busaddr
);
8031 prev_scb
->hscb
->next_hscb_busaddr
= scb
->hscb
->hscb_busaddr
;
8032 ahd_sync_scb(ahd
, prev_scb
,
8033 BUS_DMASYNC_PREREAD
|BUS_DMASYNC_PREWRITE
);
8035 ahd
->qinfifo
[AHD_QIN_WRAP(ahd
->qinfifonext
)] = SCB_GET_TAG(scb
);
8037 scb
->hscb
->next_hscb_busaddr
= ahd
->next_queued_hscb
->hscb_busaddr
;
8038 ahd_sync_scb(ahd
, scb
, BUS_DMASYNC_PREREAD
|BUS_DMASYNC_PREWRITE
);
8042 ahd_qinfifo_count(struct ahd_softc
*ahd
)
8046 u_int wrap_qinfifonext
;
8048 AHD_ASSERT_MODES(ahd
, AHD_MODE_CCHAN_MSK
, AHD_MODE_CCHAN_MSK
);
8049 qinpos
= ahd_get_snscb_qoff(ahd
);
8050 wrap_qinpos
= AHD_QIN_WRAP(qinpos
);
8051 wrap_qinfifonext
= AHD_QIN_WRAP(ahd
->qinfifonext
);
8052 if (wrap_qinfifonext
>= wrap_qinpos
)
8053 return (wrap_qinfifonext
- wrap_qinpos
);
8055 return (wrap_qinfifonext
8056 + ARRAY_SIZE(ahd
->qinfifo
) - wrap_qinpos
);
8060 ahd_reset_cmds_pending(struct ahd_softc
*ahd
)
8063 ahd_mode_state saved_modes
;
8066 saved_modes
= ahd_save_modes(ahd
);
8067 ahd_set_modes(ahd
, AHD_MODE_CCHAN
, AHD_MODE_CCHAN
);
8070 * Don't count any commands as outstanding that the
8071 * sequencer has already marked for completion.
8073 ahd_flush_qoutfifo(ahd
);
8076 LIST_FOREACH(scb
, &ahd
->pending_scbs
, pending_links
) {
8079 ahd_outw(ahd
, CMDS_PENDING
, pending_cmds
- ahd_qinfifo_count(ahd
));
8080 ahd_restore_modes(ahd
, saved_modes
);
8081 ahd
->flags
&= ~AHD_UPDATE_PEND_CMDS
;
8085 ahd_done_with_status(struct ahd_softc
*ahd
, struct scb
*scb
, uint32_t status
)
8090 ostat
= ahd_get_transaction_status(scb
);
8091 if (ostat
== CAM_REQ_INPROG
)
8092 ahd_set_transaction_status(scb
, status
);
8093 cstat
= ahd_get_transaction_status(scb
);
8094 if (cstat
!= CAM_REQ_CMP
)
8095 ahd_freeze_scb(scb
);
8100 ahd_search_qinfifo(struct ahd_softc
*ahd
, int target
, char channel
,
8101 int lun
, u_int tag
, role_t role
, uint32_t status
,
8102 ahd_search_action action
)
8105 struct scb
*mk_msg_scb
;
8106 struct scb
*prev_scb
;
8107 ahd_mode_state saved_modes
;
8120 /* Must be in CCHAN mode */
8121 saved_modes
= ahd_save_modes(ahd
);
8122 ahd_set_modes(ahd
, AHD_MODE_CCHAN
, AHD_MODE_CCHAN
);
8125 * Halt any pending SCB DMA. The sequencer will reinitiate
8126 * this dma if the qinfifo is not empty once we unpause.
8128 if ((ahd_inb(ahd
, CCSCBCTL
) & (CCARREN
|CCSCBEN
|CCSCBDIR
))
8129 == (CCARREN
|CCSCBEN
|CCSCBDIR
)) {
8130 ahd_outb(ahd
, CCSCBCTL
,
8131 ahd_inb(ahd
, CCSCBCTL
) & ~(CCARREN
|CCSCBEN
));
8132 while ((ahd_inb(ahd
, CCSCBCTL
) & (CCARREN
|CCSCBEN
)) != 0)
8135 /* Determine sequencer's position in the qinfifo. */
8136 qintail
= AHD_QIN_WRAP(ahd
->qinfifonext
);
8137 qinstart
= ahd_get_snscb_qoff(ahd
);
8138 qinpos
= AHD_QIN_WRAP(qinstart
);
8142 if (action
== SEARCH_PRINT
) {
8143 printk("qinstart = %d qinfifonext = %d\nQINFIFO:",
8144 qinstart
, ahd
->qinfifonext
);
8148 * Start with an empty queue. Entries that are not chosen
8149 * for removal will be re-added to the queue as we go.
8151 ahd
->qinfifonext
= qinstart
;
8152 busaddr
= ahd_le32toh(ahd
->next_queued_hscb
->hscb_busaddr
);
8153 ahd_outl(ahd
, NEXT_QUEUED_SCB_ADDR
, busaddr
);
8155 while (qinpos
!= qintail
) {
8156 scb
= ahd_lookup_scb(ahd
, ahd
->qinfifo
[qinpos
]);
8158 printk("qinpos = %d, SCB index = %d\n",
8159 qinpos
, ahd
->qinfifo
[qinpos
]);
8163 if (ahd_match_scb(ahd
, scb
, target
, channel
, lun
, tag
, role
)) {
8165 * We found an scb that needs to be acted on.
8169 case SEARCH_COMPLETE
:
8170 if ((scb
->flags
& SCB_ACTIVE
) == 0)
8171 printk("Inactive SCB in qinfifo\n");
8172 ahd_done_with_status(ahd
, scb
, status
);
8177 printk(" 0x%x", ahd
->qinfifo
[qinpos
]);
8180 ahd_qinfifo_requeue(ahd
, prev_scb
, scb
);
8185 ahd_qinfifo_requeue(ahd
, prev_scb
, scb
);
8188 qinpos
= AHD_QIN_WRAP(qinpos
+1);
8191 ahd_set_hnscb_qoff(ahd
, ahd
->qinfifonext
);
8193 if (action
== SEARCH_PRINT
)
8194 printk("\nWAITING_TID_QUEUES:\n");
8197 * Search waiting for selection lists. We traverse the
8198 * list of "their ids" waiting for selection and, if
8199 * appropriate, traverse the SCBs of each "their id"
8200 * looking for matches.
8202 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
8203 seq_flags2
= ahd_inb(ahd
, SEQ_FLAGS2
);
8204 if ((seq_flags2
& PENDING_MK_MESSAGE
) != 0) {
8205 scbid
= ahd_inw(ahd
, MK_MESSAGE_SCB
);
8206 mk_msg_scb
= ahd_lookup_scb(ahd
, scbid
);
8209 savedscbptr
= ahd_get_scbptr(ahd
);
8210 tid_next
= ahd_inw(ahd
, WAITING_TID_HEAD
);
8211 tid_prev
= SCB_LIST_NULL
;
8213 for (scbid
= tid_next
; !SCBID_IS_NULL(scbid
); scbid
= tid_next
) {
8218 if (targets
> AHD_NUM_TARGETS
)
8219 panic("TID LIST LOOP");
8221 if (scbid
>= ahd
->scb_data
.numscbs
) {
8222 printk("%s: Waiting TID List inconsistency. "
8223 "SCB index == 0x%x, yet numscbs == 0x%x.",
8224 ahd_name(ahd
), scbid
, ahd
->scb_data
.numscbs
);
8225 ahd_dump_card_state(ahd
);
8226 panic("for safety");
8228 scb
= ahd_lookup_scb(ahd
, scbid
);
8230 printk("%s: SCB = 0x%x Not Active!\n",
8231 ahd_name(ahd
), scbid
);
8232 panic("Waiting TID List traversal\n");
8234 ahd_set_scbptr(ahd
, scbid
);
8235 tid_next
= ahd_inw_scbram(ahd
, SCB_NEXT2
);
8236 if (ahd_match_scb(ahd
, scb
, target
, channel
, CAM_LUN_WILDCARD
,
8237 SCB_LIST_NULL
, ROLE_UNKNOWN
) == 0) {
8243 * We found a list of scbs that needs to be searched.
8245 if (action
== SEARCH_PRINT
)
8246 printk(" %d ( ", SCB_GET_TARGET(ahd
, scb
));
8248 found
+= ahd_search_scb_list(ahd
, target
, channel
,
8249 lun
, tag
, role
, status
,
8250 action
, &tid_head
, &tid_tail
,
8251 SCB_GET_TARGET(ahd
, scb
));
8253 * Check any MK_MESSAGE SCB that is still waiting to
8254 * enter this target's waiting for selection queue.
8256 if (mk_msg_scb
!= NULL
8257 && ahd_match_scb(ahd
, mk_msg_scb
, target
, channel
,
8261 * We found an scb that needs to be acted on.
8265 case SEARCH_COMPLETE
:
8266 if ((mk_msg_scb
->flags
& SCB_ACTIVE
) == 0)
8267 printk("Inactive SCB pending MK_MSG\n");
8268 ahd_done_with_status(ahd
, mk_msg_scb
, status
);
8274 printk("Removing MK_MSG scb\n");
8277 * Reset our tail to the tail of the
8278 * main per-target list.
8280 tail_offset
= WAITING_SCB_TAILS
8281 + (2 * SCB_GET_TARGET(ahd
, mk_msg_scb
));
8282 ahd_outw(ahd
, tail_offset
, tid_tail
);
8284 seq_flags2
&= ~PENDING_MK_MESSAGE
;
8285 ahd_outb(ahd
, SEQ_FLAGS2
, seq_flags2
);
8286 ahd_outw(ahd
, CMDS_PENDING
,
8287 ahd_inw(ahd
, CMDS_PENDING
)-1);
8292 printk(" 0x%x", SCB_GET_TAG(scb
));
8299 if (mk_msg_scb
!= NULL
8300 && SCBID_IS_NULL(tid_head
)
8301 && ahd_match_scb(ahd
, scb
, target
, channel
, CAM_LUN_WILDCARD
,
8302 SCB_LIST_NULL
, ROLE_UNKNOWN
)) {
8305 * When removing the last SCB for a target
8306 * queue with a pending MK_MESSAGE scb, we
8307 * must queue the MK_MESSAGE scb.
8309 printk("Queueing mk_msg_scb\n");
8310 tid_head
= ahd_inw(ahd
, MK_MESSAGE_SCB
);
8311 seq_flags2
&= ~PENDING_MK_MESSAGE
;
8312 ahd_outb(ahd
, SEQ_FLAGS2
, seq_flags2
);
8315 if (tid_head
!= scbid
)
8316 ahd_stitch_tid_list(ahd
, tid_prev
, tid_head
, tid_next
);
8317 if (!SCBID_IS_NULL(tid_head
))
8318 tid_prev
= tid_head
;
8319 if (action
== SEARCH_PRINT
)
8323 /* Restore saved state. */
8324 ahd_set_scbptr(ahd
, savedscbptr
);
8325 ahd_restore_modes(ahd
, saved_modes
);
8330 ahd_search_scb_list(struct ahd_softc
*ahd
, int target
, char channel
,
8331 int lun
, u_int tag
, role_t role
, uint32_t status
,
8332 ahd_search_action action
, u_int
*list_head
,
8333 u_int
*list_tail
, u_int tid
)
8341 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
8343 prev
= SCB_LIST_NULL
;
8345 *list_tail
= SCB_LIST_NULL
;
8346 for (scbid
= next
; !SCBID_IS_NULL(scbid
); scbid
= next
) {
8347 if (scbid
>= ahd
->scb_data
.numscbs
) {
8348 printk("%s:SCB List inconsistency. "
8349 "SCB == 0x%x, yet numscbs == 0x%x.",
8350 ahd_name(ahd
), scbid
, ahd
->scb_data
.numscbs
);
8351 ahd_dump_card_state(ahd
);
8352 panic("for safety");
8354 scb
= ahd_lookup_scb(ahd
, scbid
);
8356 printk("%s: SCB = %d Not Active!\n",
8357 ahd_name(ahd
), scbid
);
8358 panic("Waiting List traversal\n");
8360 ahd_set_scbptr(ahd
, scbid
);
8362 next
= ahd_inw_scbram(ahd
, SCB_NEXT
);
8363 if (ahd_match_scb(ahd
, scb
, target
, channel
,
8364 lun
, SCB_LIST_NULL
, role
) == 0) {
8370 case SEARCH_COMPLETE
:
8371 if ((scb
->flags
& SCB_ACTIVE
) == 0)
8372 printk("Inactive SCB in Waiting List\n");
8373 ahd_done_with_status(ahd
, scb
, status
);
8376 ahd_rem_wscb(ahd
, scbid
, prev
, next
, tid
);
8378 if (SCBID_IS_NULL(prev
))
8382 printk("0x%x ", scbid
);
8388 if (found
> AHD_SCB_MAX
)
8389 panic("SCB LIST LOOP");
8391 if (action
== SEARCH_COMPLETE
8392 || action
== SEARCH_REMOVE
)
8393 ahd_outw(ahd
, CMDS_PENDING
, ahd_inw(ahd
, CMDS_PENDING
) - found
);
8398 ahd_stitch_tid_list(struct ahd_softc
*ahd
, u_int tid_prev
,
8399 u_int tid_cur
, u_int tid_next
)
8401 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
8403 if (SCBID_IS_NULL(tid_cur
)) {
8405 /* Bypass current TID list */
8406 if (SCBID_IS_NULL(tid_prev
)) {
8407 ahd_outw(ahd
, WAITING_TID_HEAD
, tid_next
);
8409 ahd_set_scbptr(ahd
, tid_prev
);
8410 ahd_outw(ahd
, SCB_NEXT2
, tid_next
);
8412 if (SCBID_IS_NULL(tid_next
))
8413 ahd_outw(ahd
, WAITING_TID_TAIL
, tid_prev
);
8416 /* Stitch through tid_cur */
8417 if (SCBID_IS_NULL(tid_prev
)) {
8418 ahd_outw(ahd
, WAITING_TID_HEAD
, tid_cur
);
8420 ahd_set_scbptr(ahd
, tid_prev
);
8421 ahd_outw(ahd
, SCB_NEXT2
, tid_cur
);
8423 ahd_set_scbptr(ahd
, tid_cur
);
8424 ahd_outw(ahd
, SCB_NEXT2
, tid_next
);
8426 if (SCBID_IS_NULL(tid_next
))
8427 ahd_outw(ahd
, WAITING_TID_TAIL
, tid_cur
);
8432 * Manipulate the waiting for selection list and return the
8433 * scb that follows the one that we remove.
8436 ahd_rem_wscb(struct ahd_softc
*ahd
, u_int scbid
,
8437 u_int prev
, u_int next
, u_int tid
)
8441 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
8442 if (!SCBID_IS_NULL(prev
)) {
8443 ahd_set_scbptr(ahd
, prev
);
8444 ahd_outw(ahd
, SCB_NEXT
, next
);
8448 * SCBs that have MK_MESSAGE set in them may
8449 * cause the tail pointer to be updated without
8450 * setting the next pointer of the previous tail.
8451 * Only clear the tail if the removed SCB was
8454 tail_offset
= WAITING_SCB_TAILS
+ (2 * tid
);
8455 if (SCBID_IS_NULL(next
)
8456 && ahd_inw(ahd
, tail_offset
) == scbid
)
8457 ahd_outw(ahd
, tail_offset
, prev
);
8459 ahd_add_scb_to_free_list(ahd
, scbid
);
8464 * Add the SCB as selected by SCBPTR onto the on chip list of
8465 * free hardware SCBs. This list is empty/unused if we are not
8466 * performing SCB paging.
8469 ahd_add_scb_to_free_list(struct ahd_softc
*ahd
, u_int scbid
)
8471 /* XXX Need some other mechanism to designate "free". */
8473 * Invalidate the tag so that our abort
8474 * routines don't think it's active.
8475 ahd_outb(ahd, SCB_TAG, SCB_LIST_NULL);
8479 /******************************** Error Handling ******************************/
8481 * Abort all SCBs that match the given description (target/channel/lun/tag),
8482 * setting their status to the passed in status if the status has not already
8483 * been modified from CAM_REQ_INPROG. This routine assumes that the sequencer
8484 * is paused before it is called.
8487 ahd_abort_scbs(struct ahd_softc
*ahd
, int target
, char channel
,
8488 int lun
, u_int tag
, role_t role
, uint32_t status
)
8491 struct scb
*scbp_next
;
8497 ahd_mode_state saved_modes
;
8499 /* restore this when we're done */
8500 saved_modes
= ahd_save_modes(ahd
);
8501 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
8503 found
= ahd_search_qinfifo(ahd
, target
, channel
, lun
, SCB_LIST_NULL
,
8504 role
, CAM_REQUEUE_REQ
, SEARCH_COMPLETE
);
8507 * Clean out the busy target table for any untagged commands.
8511 if (target
!= CAM_TARGET_WILDCARD
) {
8518 if (lun
== CAM_LUN_WILDCARD
) {
8520 maxlun
= AHD_NUM_LUNS_NONPKT
;
8521 } else if (lun
>= AHD_NUM_LUNS_NONPKT
) {
8522 minlun
= maxlun
= 0;
8528 if (role
!= ROLE_TARGET
) {
8529 for (;i
< maxtarget
; i
++) {
8530 for (j
= minlun
;j
< maxlun
; j
++) {
8534 tcl
= BUILD_TCL_RAW(i
, 'A', j
);
8535 scbid
= ahd_find_busy_tcl(ahd
, tcl
);
8536 scbp
= ahd_lookup_scb(ahd
, scbid
);
8538 || ahd_match_scb(ahd
, scbp
, target
, channel
,
8539 lun
, tag
, role
) == 0)
8541 ahd_unbusy_tcl(ahd
, BUILD_TCL_RAW(i
, 'A', j
));
8547 * Don't abort commands that have already completed,
8548 * but haven't quite made it up to the host yet.
8550 ahd_flush_qoutfifo(ahd
);
8553 * Go through the pending CCB list and look for
8554 * commands for this target that are still active.
8555 * These are other tagged commands that were
8556 * disconnected when the reset occurred.
8558 scbp_next
= LIST_FIRST(&ahd
->pending_scbs
);
8559 while (scbp_next
!= NULL
) {
8561 scbp_next
= LIST_NEXT(scbp
, pending_links
);
8562 if (ahd_match_scb(ahd
, scbp
, target
, channel
, lun
, tag
, role
)) {
8565 ostat
= ahd_get_transaction_status(scbp
);
8566 if (ostat
== CAM_REQ_INPROG
)
8567 ahd_set_transaction_status(scbp
, status
);
8568 if (ahd_get_transaction_status(scbp
) != CAM_REQ_CMP
)
8569 ahd_freeze_scb(scbp
);
8570 if ((scbp
->flags
& SCB_ACTIVE
) == 0)
8571 printk("Inactive SCB on pending list\n");
8572 ahd_done(ahd
, scbp
);
8576 ahd_restore_modes(ahd
, saved_modes
);
8577 ahd_platform_abort_scbs(ahd
, target
, channel
, lun
, tag
, role
, status
);
8578 ahd
->flags
|= AHD_UPDATE_PEND_CMDS
;
8583 ahd_reset_current_bus(struct ahd_softc
*ahd
)
8587 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
8588 ahd_outb(ahd
, SIMODE1
, ahd_inb(ahd
, SIMODE1
) & ~ENSCSIRST
);
8589 scsiseq
= ahd_inb(ahd
, SCSISEQ0
) & ~(ENSELO
|ENARBO
|SCSIRSTO
);
8590 ahd_outb(ahd
, SCSISEQ0
, scsiseq
| SCSIRSTO
);
8591 ahd_flush_device_writes(ahd
);
8592 ahd_delay(AHD_BUSRESET_DELAY
);
8593 /* Turn off the bus reset */
8594 ahd_outb(ahd
, SCSISEQ0
, scsiseq
);
8595 ahd_flush_device_writes(ahd
);
8596 ahd_delay(AHD_BUSRESET_DELAY
);
8597 if ((ahd
->bugs
& AHD_SCSIRST_BUG
) != 0) {
8600 * Certain chip state is not cleared for
8601 * SCSI bus resets that we initiate, so
8602 * we must reset the chip.
8604 ahd_reset(ahd
, /*reinit*/TRUE
);
8605 ahd_intr_enable(ahd
, /*enable*/TRUE
);
8606 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
8609 ahd_clear_intstat(ahd
);
8613 ahd_reset_channel(struct ahd_softc
*ahd
, char channel
, int initiate_reset
)
8615 struct ahd_devinfo caminfo
;
8625 * Check if the last bus reset is cleared
8627 if (ahd
->flags
& AHD_BUS_RESET_ACTIVE
) {
8628 printk("%s: bus reset still active\n",
8632 ahd
->flags
|= AHD_BUS_RESET_ACTIVE
;
8634 ahd
->pending_device
= NULL
;
8636 ahd_compile_devinfo(&caminfo
,
8637 CAM_TARGET_WILDCARD
,
8638 CAM_TARGET_WILDCARD
,
8640 channel
, ROLE_UNKNOWN
);
8643 /* Make sure the sequencer is in a safe location. */
8644 ahd_clear_critical_section(ahd
);
8647 * Run our command complete fifos to ensure that we perform
8648 * completion processing on any commands that 'completed'
8649 * before the reset occurred.
8651 ahd_run_qoutfifo(ahd
);
8652 #ifdef AHD_TARGET_MODE
8653 if ((ahd
->flags
& AHD_TARGETROLE
) != 0) {
8654 ahd_run_tqinfifo(ahd
, /*paused*/TRUE
);
8657 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
8660 * Disable selections so no automatic hardware
8661 * functions will modify chip state.
8663 ahd_outb(ahd
, SCSISEQ0
, 0);
8664 ahd_outb(ahd
, SCSISEQ1
, 0);
8667 * Safely shut down our DMA engines. Always start with
8668 * the FIFO that is not currently active (if any are
8669 * actively connected).
8671 next_fifo
= fifo
= ahd_inb(ahd
, DFFSTAT
) & CURRFIFO
;
8672 if (next_fifo
> CURRFIFO_1
)
8673 /* If disconneced, arbitrarily start with FIFO1. */
8674 next_fifo
= fifo
= 0;
8676 next_fifo
^= CURRFIFO_1
;
8677 ahd_set_modes(ahd
, next_fifo
, next_fifo
);
8678 ahd_outb(ahd
, DFCNTRL
,
8679 ahd_inb(ahd
, DFCNTRL
) & ~(SCSIEN
|HDMAEN
));
8680 while ((ahd_inb(ahd
, DFCNTRL
) & HDMAENACK
) != 0)
8683 * Set CURRFIFO to the now inactive channel.
8685 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
8686 ahd_outb(ahd
, DFFSTAT
, next_fifo
);
8687 } while (next_fifo
!= fifo
);
8690 * Reset the bus if we are initiating this reset
8692 ahd_clear_msg_state(ahd
);
8693 ahd_outb(ahd
, SIMODE1
,
8694 ahd_inb(ahd
, SIMODE1
) & ~(ENBUSFREE
|ENSCSIRST
));
8697 ahd_reset_current_bus(ahd
);
8699 ahd_clear_intstat(ahd
);
8702 * Clean up all the state information for the
8703 * pending transactions on this bus.
8705 found
= ahd_abort_scbs(ahd
, CAM_TARGET_WILDCARD
, channel
,
8706 CAM_LUN_WILDCARD
, SCB_LIST_NULL
,
8707 ROLE_UNKNOWN
, CAM_SCSI_BUS_RESET
);
8710 * Cleanup anything left in the FIFOs.
8712 ahd_clear_fifo(ahd
, 0);
8713 ahd_clear_fifo(ahd
, 1);
8716 * Clear SCSI interrupt status
8718 ahd_outb(ahd
, CLRSINT1
, CLRSCSIRSTI
);
8721 * Reenable selections
8723 ahd_outb(ahd
, SIMODE1
, ahd_inb(ahd
, SIMODE1
) | ENSCSIRST
);
8724 scsiseq
= ahd_inb(ahd
, SCSISEQ_TEMPLATE
);
8725 ahd_outb(ahd
, SCSISEQ1
, scsiseq
& (ENSELI
|ENRSELI
|ENAUTOATNP
));
8727 max_scsiid
= (ahd
->features
& AHD_WIDE
) ? 15 : 7;
8728 #ifdef AHD_TARGET_MODE
8730 * Send an immediate notify ccb to all target more peripheral
8731 * drivers affected by this action.
8733 for (target
= 0; target
<= max_scsiid
; target
++) {
8734 struct ahd_tmode_tstate
* tstate
;
8737 tstate
= ahd
->enabled_targets
[target
];
8740 for (lun
= 0; lun
< AHD_NUM_LUNS
; lun
++) {
8741 struct ahd_tmode_lstate
* lstate
;
8743 lstate
= tstate
->enabled_luns
[lun
];
8747 ahd_queue_lstate_event(ahd
, lstate
, CAM_TARGET_WILDCARD
,
8748 EVENT_TYPE_BUS_RESET
, /*arg*/0);
8749 ahd_send_lstate_events(ahd
, lstate
);
8754 * Revert to async/narrow transfers until we renegotiate.
8756 for (target
= 0; target
<= max_scsiid
; target
++) {
8758 if (ahd
->enabled_targets
[target
] == NULL
)
8760 for (initiator
= 0; initiator
<= max_scsiid
; initiator
++) {
8761 struct ahd_devinfo devinfo
;
8763 ahd_compile_devinfo(&devinfo
, target
, initiator
,
8766 ahd_set_width(ahd
, &devinfo
, MSG_EXT_WDTR_BUS_8_BIT
,
8767 AHD_TRANS_CUR
, /*paused*/TRUE
);
8768 ahd_set_syncrate(ahd
, &devinfo
, /*period*/0,
8769 /*offset*/0, /*ppr_options*/0,
8770 AHD_TRANS_CUR
, /*paused*/TRUE
);
8774 /* Notify the XPT that a bus reset occurred */
8775 ahd_send_async(ahd
, caminfo
.channel
, CAM_TARGET_WILDCARD
,
8776 CAM_LUN_WILDCARD
, AC_BUS_RESET
);
8783 /**************************** Statistics Processing ***************************/
8785 ahd_stat_timer(struct timer_list
*t
)
8787 struct ahd_softc
*ahd
= from_timer(ahd
, t
, stat_timer
);
8793 enint_coal
= ahd
->hs_mailbox
& ENINT_COALESCE
;
8794 if (ahd
->cmdcmplt_total
> ahd
->int_coalescing_threshold
)
8795 enint_coal
|= ENINT_COALESCE
;
8796 else if (ahd
->cmdcmplt_total
< ahd
->int_coalescing_stop_threshold
)
8797 enint_coal
&= ~ENINT_COALESCE
;
8799 if (enint_coal
!= (ahd
->hs_mailbox
& ENINT_COALESCE
)) {
8800 ahd_enable_coalescing(ahd
, enint_coal
);
8802 if ((ahd_debug
& AHD_SHOW_INT_COALESCING
) != 0)
8803 printk("%s: Interrupt coalescing "
8804 "now %sabled. Cmds %d\n",
8806 (enint_coal
& ENINT_COALESCE
) ? "en" : "dis",
8807 ahd
->cmdcmplt_total
);
8811 ahd
->cmdcmplt_bucket
= (ahd
->cmdcmplt_bucket
+1) & (AHD_STAT_BUCKETS
-1);
8812 ahd
->cmdcmplt_total
-= ahd
->cmdcmplt_counts
[ahd
->cmdcmplt_bucket
];
8813 ahd
->cmdcmplt_counts
[ahd
->cmdcmplt_bucket
] = 0;
8814 ahd_timer_reset(&ahd
->stat_timer
, AHD_STAT_UPDATE_US
);
8815 ahd_unlock(ahd
, &s
);
8818 /****************************** Status Processing *****************************/
8821 ahd_handle_scsi_status(struct ahd_softc
*ahd
, struct scb
*scb
)
8823 struct hardware_scb
*hscb
;
8827 * The sequencer freezes its select-out queue
8828 * anytime a SCSI status error occurs. We must
8829 * handle the error and increment our qfreeze count
8830 * to allow the sequencer to continue. We don't
8831 * bother clearing critical sections here since all
8832 * operations are on data structures that the sequencer
8833 * is not touching once the queue is frozen.
8837 if (ahd_is_paused(ahd
)) {
8844 /* Freeze the queue until the client sees the error. */
8845 ahd_freeze_devq(ahd
, scb
);
8846 ahd_freeze_scb(scb
);
8848 ahd_outw(ahd
, KERNEL_QFREEZE_COUNT
, ahd
->qfreeze_cnt
);
8853 /* Don't want to clobber the original sense code */
8854 if ((scb
->flags
& SCB_SENSE
) != 0) {
8856 * Clear the SCB_SENSE Flag and perform
8857 * a normal command completion.
8859 scb
->flags
&= ~SCB_SENSE
;
8860 ahd_set_transaction_status(scb
, CAM_AUTOSENSE_FAIL
);
8864 ahd_set_transaction_status(scb
, CAM_SCSI_STATUS_ERROR
);
8865 ahd_set_scsi_status(scb
, hscb
->shared_data
.istatus
.scsi_status
);
8866 switch (hscb
->shared_data
.istatus
.scsi_status
) {
8867 case STATUS_PKT_SENSE
:
8869 struct scsi_status_iu_header
*siu
;
8871 ahd_sync_sense(ahd
, scb
, BUS_DMASYNC_POSTREAD
);
8872 siu
= (struct scsi_status_iu_header
*)scb
->sense_data
;
8873 ahd_set_scsi_status(scb
, siu
->status
);
8875 if ((ahd_debug
& AHD_SHOW_SENSE
) != 0) {
8876 ahd_print_path(ahd
, scb
);
8877 printk("SCB 0x%x Received PKT Status of 0x%x\n",
8878 SCB_GET_TAG(scb
), siu
->status
);
8879 printk("\tflags = 0x%x, sense len = 0x%x, "
8881 siu
->flags
, scsi_4btoul(siu
->sense_length
),
8882 scsi_4btoul(siu
->pkt_failures_length
));
8885 if ((siu
->flags
& SIU_RSPVALID
) != 0) {
8886 ahd_print_path(ahd
, scb
);
8887 if (scsi_4btoul(siu
->pkt_failures_length
) < 4) {
8888 printk("Unable to parse pkt_failures\n");
8891 switch (SIU_PKTFAIL_CODE(siu
)) {
8893 printk("No packet failure found\n");
8895 case SIU_PFC_CIU_FIELDS_INVALID
:
8896 printk("Invalid Command IU Field\n");
8898 case SIU_PFC_TMF_NOT_SUPPORTED
:
8899 printk("TMF not supported\n");
8901 case SIU_PFC_TMF_FAILED
:
8902 printk("TMF failed\n");
8904 case SIU_PFC_INVALID_TYPE_CODE
:
8905 printk("Invalid L_Q Type code\n");
8907 case SIU_PFC_ILLEGAL_REQUEST
:
8908 printk("Illegal request\n");
8914 if (siu
->status
== SAM_STAT_GOOD
)
8915 ahd_set_transaction_status(scb
,
8918 if ((siu
->flags
& SIU_SNSVALID
) != 0) {
8919 scb
->flags
|= SCB_PKT_SENSE
;
8921 if ((ahd_debug
& AHD_SHOW_SENSE
) != 0)
8922 printk("Sense data available\n");
8928 case SAM_STAT_COMMAND_TERMINATED
:
8929 case SAM_STAT_CHECK_CONDITION
:
8931 struct ahd_devinfo devinfo
;
8932 struct ahd_dma_seg
*sg
;
8933 struct scsi_sense
*sc
;
8934 struct ahd_initiator_tinfo
*targ_info
;
8935 struct ahd_tmode_tstate
*tstate
;
8936 struct ahd_transinfo
*tinfo
;
8938 if (ahd_debug
& AHD_SHOW_SENSE
) {
8939 ahd_print_path(ahd
, scb
);
8940 printk("SCB %d: requests Check Status\n",
8945 if (ahd_perform_autosense(scb
) == 0)
8948 ahd_compile_devinfo(&devinfo
, SCB_GET_OUR_ID(scb
),
8949 SCB_GET_TARGET(ahd
, scb
),
8951 SCB_GET_CHANNEL(ahd
, scb
),
8953 targ_info
= ahd_fetch_transinfo(ahd
,
8958 tinfo
= &targ_info
->curr
;
8960 sc
= (struct scsi_sense
*)hscb
->shared_data
.idata
.cdb
;
8962 * Save off the residual if there is one.
8964 ahd_update_residual(ahd
, scb
);
8966 if (ahd_debug
& AHD_SHOW_SENSE
) {
8967 ahd_print_path(ahd
, scb
);
8968 printk("Sending Sense\n");
8972 sg
= ahd_sg_setup(ahd
, scb
, sg
, ahd_get_sense_bufaddr(ahd
, scb
),
8973 ahd_get_sense_bufsize(ahd
, scb
),
8975 sc
->opcode
= REQUEST_SENSE
;
8977 if (tinfo
->protocol_version
<= SCSI_REV_2
8978 && SCB_GET_LUN(scb
) < 8)
8979 sc
->byte2
= SCB_GET_LUN(scb
) << 5;
8982 sc
->length
= ahd_get_sense_bufsize(ahd
, scb
);
8986 * We can't allow the target to disconnect.
8987 * This will be an untagged transaction and
8988 * having the target disconnect will make this
8989 * transaction indestinguishable from outstanding
8990 * tagged transactions.
8995 * This request sense could be because the
8996 * the device lost power or in some other
8997 * way has lost our transfer negotiations.
8998 * Renegotiate if appropriate. Unit attention
8999 * errors will be reported before any data
9002 if (ahd_get_residual(scb
) == ahd_get_transfer_length(scb
)) {
9003 ahd_update_neg_request(ahd
, &devinfo
,
9005 AHD_NEG_IF_NON_ASYNC
);
9007 if (tstate
->auto_negotiate
& devinfo
.target_mask
) {
9008 hscb
->control
|= MK_MESSAGE
;
9010 ~(SCB_NEGOTIATE
|SCB_ABORT
|SCB_DEVICE_RESET
);
9011 scb
->flags
|= SCB_AUTO_NEGOTIATE
;
9013 hscb
->cdb_len
= sizeof(*sc
);
9014 ahd_setup_data_scb(ahd
, scb
);
9015 scb
->flags
|= SCB_SENSE
;
9016 ahd_queue_scb(ahd
, scb
);
9020 printk("%s: Interrupted for status of 0???\n",
9030 ahd_handle_scb_status(struct ahd_softc
*ahd
, struct scb
*scb
)
9032 if (scb
->hscb
->shared_data
.istatus
.scsi_status
!= 0) {
9033 ahd_handle_scsi_status(ahd
, scb
);
9035 ahd_calc_residual(ahd
, scb
);
9041 * Calculate the residual for a just completed SCB.
9044 ahd_calc_residual(struct ahd_softc
*ahd
, struct scb
*scb
)
9046 struct hardware_scb
*hscb
;
9047 struct initiator_status
*spkt
;
9049 uint32_t resid_sgptr
;
9055 * SG_STATUS_VALID clear in sgptr.
9056 * 2) Transferless command
9057 * 3) Never performed any transfers.
9058 * sgptr has SG_FULL_RESID set.
9059 * 4) No residual but target did not
9060 * save data pointers after the
9061 * last transfer, so sgptr was
9063 * 5) We have a partial residual.
9064 * Use residual_sgptr to determine
9069 sgptr
= ahd_le32toh(hscb
->sgptr
);
9070 if ((sgptr
& SG_STATUS_VALID
) == 0)
9073 sgptr
&= ~SG_STATUS_VALID
;
9075 if ((sgptr
& SG_LIST_NULL
) != 0)
9080 * Residual fields are the same in both
9081 * target and initiator status packets,
9082 * so we can always use the initiator fields
9083 * regardless of the role for this SCB.
9085 spkt
= &hscb
->shared_data
.istatus
;
9086 resid_sgptr
= ahd_le32toh(spkt
->residual_sgptr
);
9087 if ((sgptr
& SG_FULL_RESID
) != 0) {
9089 resid
= ahd_get_transfer_length(scb
);
9090 } else if ((resid_sgptr
& SG_LIST_NULL
) != 0) {
9093 } else if ((resid_sgptr
& SG_OVERRUN_RESID
) != 0) {
9094 ahd_print_path(ahd
, scb
);
9095 printk("data overrun detected Tag == 0x%x.\n",
9097 ahd_freeze_devq(ahd
, scb
);
9098 ahd_set_transaction_status(scb
, CAM_DATA_RUN_ERR
);
9099 ahd_freeze_scb(scb
);
9101 } else if ((resid_sgptr
& ~SG_PTR_MASK
) != 0) {
9102 panic("Bogus resid sgptr value 0x%x\n", resid_sgptr
);
9105 struct ahd_dma_seg
*sg
;
9108 * Remainder of the SG where the transfer
9111 resid
= ahd_le32toh(spkt
->residual_datacnt
) & AHD_SG_LEN_MASK
;
9112 sg
= ahd_sg_bus_to_virt(ahd
, scb
, resid_sgptr
& SG_PTR_MASK
);
9114 /* The residual sg_ptr always points to the next sg */
9118 * Add up the contents of all residual
9119 * SG segments that are after the SG where
9120 * the transfer stopped.
9122 while ((ahd_le32toh(sg
->len
) & AHD_DMA_LAST_SEG
) == 0) {
9124 resid
+= ahd_le32toh(sg
->len
) & AHD_SG_LEN_MASK
;
9127 if ((scb
->flags
& SCB_SENSE
) == 0)
9128 ahd_set_residual(scb
, resid
);
9130 ahd_set_sense_residual(scb
, resid
);
9133 if ((ahd_debug
& AHD_SHOW_MISC
) != 0) {
9134 ahd_print_path(ahd
, scb
);
9135 printk("Handled %sResidual of %d bytes\n",
9136 (scb
->flags
& SCB_SENSE
) ? "Sense " : "", resid
);
9141 /******************************* Target Mode **********************************/
9142 #ifdef AHD_TARGET_MODE
9144 * Add a target mode event to this lun's queue
9147 ahd_queue_lstate_event(struct ahd_softc
*ahd
, struct ahd_tmode_lstate
*lstate
,
9148 u_int initiator_id
, u_int event_type
, u_int event_arg
)
9150 struct ahd_tmode_event
*event
;
9153 xpt_freeze_devq(lstate
->path
, /*count*/1);
9154 if (lstate
->event_w_idx
>= lstate
->event_r_idx
)
9155 pending
= lstate
->event_w_idx
- lstate
->event_r_idx
;
9157 pending
= AHD_TMODE_EVENT_BUFFER_SIZE
+ 1
9158 - (lstate
->event_r_idx
- lstate
->event_w_idx
);
9160 if (event_type
== EVENT_TYPE_BUS_RESET
9161 || event_type
== TARGET_RESET
) {
9163 * Any earlier events are irrelevant, so reset our buffer.
9164 * This has the effect of allowing us to deal with reset
9165 * floods (an external device holding down the reset line)
9166 * without losing the event that is really interesting.
9168 lstate
->event_r_idx
= 0;
9169 lstate
->event_w_idx
= 0;
9170 xpt_release_devq(lstate
->path
, pending
, /*runqueue*/FALSE
);
9173 if (pending
== AHD_TMODE_EVENT_BUFFER_SIZE
) {
9174 xpt_print_path(lstate
->path
);
9175 printk("immediate event %x:%x lost\n",
9176 lstate
->event_buffer
[lstate
->event_r_idx
].event_type
,
9177 lstate
->event_buffer
[lstate
->event_r_idx
].event_arg
);
9178 lstate
->event_r_idx
++;
9179 if (lstate
->event_r_idx
== AHD_TMODE_EVENT_BUFFER_SIZE
)
9180 lstate
->event_r_idx
= 0;
9181 xpt_release_devq(lstate
->path
, /*count*/1, /*runqueue*/FALSE
);
9184 event
= &lstate
->event_buffer
[lstate
->event_w_idx
];
9185 event
->initiator_id
= initiator_id
;
9186 event
->event_type
= event_type
;
9187 event
->event_arg
= event_arg
;
9188 lstate
->event_w_idx
++;
9189 if (lstate
->event_w_idx
== AHD_TMODE_EVENT_BUFFER_SIZE
)
9190 lstate
->event_w_idx
= 0;
9194 * Send any target mode events queued up waiting
9195 * for immediate notify resources.
9198 ahd_send_lstate_events(struct ahd_softc
*ahd
, struct ahd_tmode_lstate
*lstate
)
9200 struct ccb_hdr
*ccbh
;
9201 struct ccb_immed_notify
*inot
;
9203 while (lstate
->event_r_idx
!= lstate
->event_w_idx
9204 && (ccbh
= SLIST_FIRST(&lstate
->immed_notifies
)) != NULL
) {
9205 struct ahd_tmode_event
*event
;
9207 event
= &lstate
->event_buffer
[lstate
->event_r_idx
];
9208 SLIST_REMOVE_HEAD(&lstate
->immed_notifies
, sim_links
.sle
);
9209 inot
= (struct ccb_immed_notify
*)ccbh
;
9210 switch (event
->event_type
) {
9211 case EVENT_TYPE_BUS_RESET
:
9212 ccbh
->status
= CAM_SCSI_BUS_RESET
|CAM_DEV_QFRZN
;
9215 ccbh
->status
= CAM_MESSAGE_RECV
|CAM_DEV_QFRZN
;
9216 inot
->message_args
[0] = event
->event_type
;
9217 inot
->message_args
[1] = event
->event_arg
;
9220 inot
->initiator_id
= event
->initiator_id
;
9221 inot
->sense_len
= 0;
9222 xpt_done((union ccb
*)inot
);
9223 lstate
->event_r_idx
++;
9224 if (lstate
->event_r_idx
== AHD_TMODE_EVENT_BUFFER_SIZE
)
9225 lstate
->event_r_idx
= 0;
9230 /******************** Sequencer Program Patching/Download *********************/
9234 ahd_dumpseq(struct ahd_softc
* ahd
)
9241 ahd_outb(ahd
, SEQCTL0
, PERRORDIS
|FAILDIS
|FASTMODE
|LOADRAM
);
9242 ahd_outw(ahd
, PRGMCNT
, 0);
9243 for (i
= 0; i
< max_prog
; i
++) {
9244 uint8_t ins_bytes
[4];
9246 ahd_insb(ahd
, SEQRAM
, ins_bytes
, 4);
9247 printk("0x%08x\n", ins_bytes
[0] << 24
9248 | ins_bytes
[1] << 16
9256 ahd_loadseq(struct ahd_softc
*ahd
)
9258 struct cs cs_table
[NUM_CRITICAL_SECTIONS
];
9259 u_int begin_set
[NUM_CRITICAL_SECTIONS
];
9260 u_int end_set
[NUM_CRITICAL_SECTIONS
];
9261 const struct patch
*cur_patch
;
9267 u_int sg_prefetch_cnt
;
9268 u_int sg_prefetch_cnt_limit
;
9269 u_int sg_prefetch_align
;
9271 u_int cacheline_mask
;
9272 uint8_t download_consts
[DOWNLOAD_CONST_COUNT
];
9275 printk("%s: Downloading Sequencer Program...",
9278 #if DOWNLOAD_CONST_COUNT != 8
9279 #error "Download Const Mismatch"
9282 * Start out with 0 critical sections
9283 * that apply to this firmware load.
9287 memset(begin_set
, 0, sizeof(begin_set
));
9288 memset(end_set
, 0, sizeof(end_set
));
9291 * Setup downloadable constant table.
9293 * The computation for the S/G prefetch variables is
9294 * a bit complicated. We would like to always fetch
9295 * in terms of cachelined sized increments. However,
9296 * if the cacheline is not an even multiple of the
9297 * SG element size or is larger than our SG RAM, using
9298 * just the cache size might leave us with only a portion
9299 * of an SG element at the tail of a prefetch. If the
9300 * cacheline is larger than our S/G prefetch buffer less
9301 * the size of an SG element, we may round down to a cacheline
9302 * that doesn't contain any or all of the S/G of interest
9303 * within the bounds of our S/G ram. Provide variables to
9304 * the sequencer that will allow it to handle these edge
9307 /* Start by aligning to the nearest cacheline. */
9308 sg_prefetch_align
= ahd
->pci_cachesize
;
9309 if (sg_prefetch_align
== 0)
9310 sg_prefetch_align
= 8;
9311 /* Round down to the nearest power of 2. */
9312 while (powerof2(sg_prefetch_align
) == 0)
9313 sg_prefetch_align
--;
9315 cacheline_mask
= sg_prefetch_align
- 1;
9318 * If the cacheline boundary is greater than half our prefetch RAM
9319 * we risk not being able to fetch even a single complete S/G
9320 * segment if we align to that boundary.
9322 if (sg_prefetch_align
> CCSGADDR_MAX
/2)
9323 sg_prefetch_align
= CCSGADDR_MAX
/2;
9324 /* Start by fetching a single cacheline. */
9325 sg_prefetch_cnt
= sg_prefetch_align
;
9327 * Increment the prefetch count by cachelines until
9328 * at least one S/G element will fit.
9330 sg_size
= sizeof(struct ahd_dma_seg
);
9331 if ((ahd
->flags
& AHD_64BIT_ADDRESSING
) != 0)
9332 sg_size
= sizeof(struct ahd_dma64_seg
);
9333 while (sg_prefetch_cnt
< sg_size
)
9334 sg_prefetch_cnt
+= sg_prefetch_align
;
9336 * If the cacheline is not an even multiple of
9337 * the S/G size, we may only get a partial S/G when
9338 * we align. Add a cacheline if this is the case.
9340 if ((sg_prefetch_align
% sg_size
) != 0
9341 && (sg_prefetch_cnt
< CCSGADDR_MAX
))
9342 sg_prefetch_cnt
+= sg_prefetch_align
;
9344 * Lastly, compute a value that the sequencer can use
9345 * to determine if the remainder of the CCSGRAM buffer
9346 * has a full S/G element in it.
9348 sg_prefetch_cnt_limit
= -(sg_prefetch_cnt
- sg_size
+ 1);
9349 download_consts
[SG_PREFETCH_CNT
] = sg_prefetch_cnt
;
9350 download_consts
[SG_PREFETCH_CNT_LIMIT
] = sg_prefetch_cnt_limit
;
9351 download_consts
[SG_PREFETCH_ALIGN_MASK
] = ~(sg_prefetch_align
- 1);
9352 download_consts
[SG_PREFETCH_ADDR_MASK
] = (sg_prefetch_align
- 1);
9353 download_consts
[SG_SIZEOF
] = sg_size
;
9354 download_consts
[PKT_OVERRUN_BUFOFFSET
] =
9355 (ahd
->overrun_buf
- (uint8_t *)ahd
->qoutfifo
) / 256;
9356 download_consts
[SCB_TRANSFER_SIZE
] = SCB_TRANSFER_SIZE_1BYTE_LUN
;
9357 download_consts
[CACHELINE_MASK
] = cacheline_mask
;
9358 cur_patch
= patches
;
9361 ahd_outb(ahd
, SEQCTL0
, PERRORDIS
|FAILDIS
|FASTMODE
|LOADRAM
);
9362 ahd_outw(ahd
, PRGMCNT
, 0);
9364 for (i
= 0; i
< sizeof(seqprog
)/4; i
++) {
9365 if (ahd_check_patch(ahd
, &cur_patch
, i
, &skip_addr
) == 0) {
9367 * Don't download this instruction as it
9368 * is in a patch that was removed.
9373 * Move through the CS table until we find a CS
9374 * that might apply to this instruction.
9376 for (; cur_cs
< NUM_CRITICAL_SECTIONS
; cur_cs
++) {
9377 if (critical_sections
[cur_cs
].end
<= i
) {
9378 if (begin_set
[cs_count
] == TRUE
9379 && end_set
[cs_count
] == FALSE
) {
9380 cs_table
[cs_count
].end
= downloaded
;
9381 end_set
[cs_count
] = TRUE
;
9386 if (critical_sections
[cur_cs
].begin
<= i
9387 && begin_set
[cs_count
] == FALSE
) {
9388 cs_table
[cs_count
].begin
= downloaded
;
9389 begin_set
[cs_count
] = TRUE
;
9393 ahd_download_instr(ahd
, i
, download_consts
);
9397 ahd
->num_critical_sections
= cs_count
;
9398 if (cs_count
!= 0) {
9400 cs_count
*= sizeof(struct cs
);
9401 ahd
->critical_sections
= kmemdup(cs_table
, cs_count
, GFP_ATOMIC
);
9402 if (ahd
->critical_sections
== NULL
)
9403 panic("ahd_loadseq: Could not malloc");
9405 ahd_outb(ahd
, SEQCTL0
, PERRORDIS
|FAILDIS
|FASTMODE
);
9408 printk(" %d instructions downloaded\n", downloaded
);
9409 printk("%s: Features 0x%x, Bugs 0x%x, Flags 0x%x\n",
9410 ahd_name(ahd
), ahd
->features
, ahd
->bugs
, ahd
->flags
);
9415 ahd_check_patch(struct ahd_softc
*ahd
, const struct patch
**start_patch
,
9416 u_int start_instr
, u_int
*skip_addr
)
9418 const struct patch
*cur_patch
;
9419 const struct patch
*last_patch
;
9422 num_patches
= ARRAY_SIZE(patches
);
9423 last_patch
= &patches
[num_patches
];
9424 cur_patch
= *start_patch
;
9426 while (cur_patch
< last_patch
&& start_instr
== cur_patch
->begin
) {
9428 if (cur_patch
->patch_func(ahd
) == 0) {
9430 /* Start rejecting code */
9431 *skip_addr
= start_instr
+ cur_patch
->skip_instr
;
9432 cur_patch
+= cur_patch
->skip_patch
;
9434 /* Accepted this patch. Advance to the next
9435 * one and wait for our intruction pointer to
9442 *start_patch
= cur_patch
;
9443 if (start_instr
< *skip_addr
)
9444 /* Still skipping */
9451 ahd_resolve_seqaddr(struct ahd_softc
*ahd
, u_int address
)
9453 const struct patch
*cur_patch
;
9459 cur_patch
= patches
;
9462 for (i
= 0; i
< address
;) {
9464 ahd_check_patch(ahd
, &cur_patch
, i
, &skip_addr
);
9466 if (skip_addr
> i
) {
9469 end_addr
= min(address
, skip_addr
);
9470 address_offset
+= end_addr
- i
;
9476 return (address
- address_offset
);
9480 ahd_download_instr(struct ahd_softc
*ahd
, u_int instrptr
, uint8_t *dconsts
)
9482 union ins_formats instr
;
9483 struct ins_format1
*fmt1_ins
;
9484 struct ins_format3
*fmt3_ins
;
9488 * The firmware is always compiled into a little endian format.
9490 instr
.integer
= ahd_le32toh(*(uint32_t*)&seqprog
[instrptr
* 4]);
9492 fmt1_ins
= &instr
.format1
;
9495 /* Pull the opcode */
9496 opcode
= instr
.format1
.opcode
;
9507 fmt3_ins
= &instr
.format3
;
9508 fmt3_ins
->address
= ahd_resolve_seqaddr(ahd
, fmt3_ins
->address
);
9517 if (fmt1_ins
->parity
!= 0) {
9518 fmt1_ins
->immediate
= dconsts
[fmt1_ins
->immediate
];
9520 fmt1_ins
->parity
= 0;
9526 /* Calculate odd parity for the instruction */
9527 for (i
= 0, count
= 0; i
< 31; i
++) {
9531 if ((instr
.integer
& mask
) != 0)
9534 if ((count
& 0x01) == 0)
9535 instr
.format1
.parity
= 1;
9537 /* The sequencer is a little endian cpu */
9538 instr
.integer
= ahd_htole32(instr
.integer
);
9539 ahd_outsb(ahd
, SEQRAM
, instr
.bytes
, 4);
9543 panic("Unknown opcode encountered in seq program");
9549 ahd_probe_stack_size(struct ahd_softc
*ahd
)
9558 * We avoid using 0 as a pattern to avoid
9559 * confusion if the stack implementation
9560 * "back-fills" with zeros when "poping'
9563 for (i
= 1; i
<= last_probe
+1; i
++) {
9564 ahd_outb(ahd
, STACK
, i
& 0xFF);
9565 ahd_outb(ahd
, STACK
, (i
>> 8) & 0xFF);
9569 for (i
= last_probe
+1; i
> 0; i
--) {
9572 stack_entry
= ahd_inb(ahd
, STACK
)
9573 |(ahd_inb(ahd
, STACK
) << 8);
9574 if (stack_entry
!= i
)
9580 return (last_probe
);
9584 ahd_print_register(const ahd_reg_parse_entry_t
*table
, u_int num_entries
,
9585 const char *name
, u_int address
, u_int value
,
9586 u_int
*cur_column
, u_int wrap_point
)
9591 if (cur_column
!= NULL
&& *cur_column
>= wrap_point
) {
9595 printed
= printk("%s[0x%x]", name
, value
);
9596 if (table
== NULL
) {
9597 printed
+= printk(" ");
9598 *cur_column
+= printed
;
9602 while (printed_mask
!= 0xFF) {
9605 for (entry
= 0; entry
< num_entries
; entry
++) {
9606 if (((value
& table
[entry
].mask
)
9607 != table
[entry
].value
)
9608 || ((printed_mask
& table
[entry
].mask
)
9609 == table
[entry
].mask
))
9612 printed
+= printk("%s%s",
9613 printed_mask
== 0 ? ":(" : "|",
9615 printed_mask
|= table
[entry
].mask
;
9619 if (entry
>= num_entries
)
9622 if (printed_mask
!= 0)
9623 printed
+= printk(") ");
9625 printed
+= printk(" ");
9626 if (cur_column
!= NULL
)
9627 *cur_column
+= printed
;
9632 ahd_dump_card_state(struct ahd_softc
*ahd
)
9635 ahd_mode_state saved_modes
;
9639 u_int saved_scb_index
;
9643 if (ahd_is_paused(ahd
)) {
9649 saved_modes
= ahd_save_modes(ahd
);
9650 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
9651 printk(">>>>>>>>>>>>>>>>>> Dump Card State Begins <<<<<<<<<<<<<<<<<\n"
9652 "%s: Dumping Card State at program address 0x%x Mode 0x%x\n",
9654 ahd_inw(ahd
, CURADDR
),
9655 ahd_build_mode_state(ahd
, ahd
->saved_src_mode
,
9656 ahd
->saved_dst_mode
));
9658 printk("Card was paused\n");
9660 if (ahd_check_cmdcmpltqueues(ahd
))
9661 printk("Completions are pending\n");
9664 * Mode independent registers.
9667 ahd_intstat_print(ahd_inb(ahd
, INTSTAT
), &cur_col
, 50);
9668 ahd_seloid_print(ahd_inb(ahd
, SELOID
), &cur_col
, 50);
9669 ahd_selid_print(ahd_inb(ahd
, SELID
), &cur_col
, 50);
9670 ahd_hs_mailbox_print(ahd_inb(ahd
, LOCAL_HS_MAILBOX
), &cur_col
, 50);
9671 ahd_intctl_print(ahd_inb(ahd
, INTCTL
), &cur_col
, 50);
9672 ahd_seqintstat_print(ahd_inb(ahd
, SEQINTSTAT
), &cur_col
, 50);
9673 ahd_saved_mode_print(ahd_inb(ahd
, SAVED_MODE
), &cur_col
, 50);
9674 ahd_dffstat_print(ahd_inb(ahd
, DFFSTAT
), &cur_col
, 50);
9675 ahd_scsisigi_print(ahd_inb(ahd
, SCSISIGI
), &cur_col
, 50);
9676 ahd_scsiphase_print(ahd_inb(ahd
, SCSIPHASE
), &cur_col
, 50);
9677 ahd_scsibus_print(ahd_inb(ahd
, SCSIBUS
), &cur_col
, 50);
9678 ahd_lastphase_print(ahd_inb(ahd
, LASTPHASE
), &cur_col
, 50);
9679 ahd_scsiseq0_print(ahd_inb(ahd
, SCSISEQ0
), &cur_col
, 50);
9680 ahd_scsiseq1_print(ahd_inb(ahd
, SCSISEQ1
), &cur_col
, 50);
9681 ahd_seqctl0_print(ahd_inb(ahd
, SEQCTL0
), &cur_col
, 50);
9682 ahd_seqintctl_print(ahd_inb(ahd
, SEQINTCTL
), &cur_col
, 50);
9683 ahd_seq_flags_print(ahd_inb(ahd
, SEQ_FLAGS
), &cur_col
, 50);
9684 ahd_seq_flags2_print(ahd_inb(ahd
, SEQ_FLAGS2
), &cur_col
, 50);
9685 ahd_qfreeze_count_print(ahd_inw(ahd
, QFREEZE_COUNT
), &cur_col
, 50);
9686 ahd_kernel_qfreeze_count_print(ahd_inw(ahd
, KERNEL_QFREEZE_COUNT
),
9688 ahd_mk_message_scb_print(ahd_inw(ahd
, MK_MESSAGE_SCB
), &cur_col
, 50);
9689 ahd_mk_message_scsiid_print(ahd_inb(ahd
, MK_MESSAGE_SCSIID
),
9691 ahd_sstat0_print(ahd_inb(ahd
, SSTAT0
), &cur_col
, 50);
9692 ahd_sstat1_print(ahd_inb(ahd
, SSTAT1
), &cur_col
, 50);
9693 ahd_sstat2_print(ahd_inb(ahd
, SSTAT2
), &cur_col
, 50);
9694 ahd_sstat3_print(ahd_inb(ahd
, SSTAT3
), &cur_col
, 50);
9695 ahd_perrdiag_print(ahd_inb(ahd
, PERRDIAG
), &cur_col
, 50);
9696 ahd_simode1_print(ahd_inb(ahd
, SIMODE1
), &cur_col
, 50);
9697 ahd_lqistat0_print(ahd_inb(ahd
, LQISTAT0
), &cur_col
, 50);
9698 ahd_lqistat1_print(ahd_inb(ahd
, LQISTAT1
), &cur_col
, 50);
9699 ahd_lqistat2_print(ahd_inb(ahd
, LQISTAT2
), &cur_col
, 50);
9700 ahd_lqostat0_print(ahd_inb(ahd
, LQOSTAT0
), &cur_col
, 50);
9701 ahd_lqostat1_print(ahd_inb(ahd
, LQOSTAT1
), &cur_col
, 50);
9702 ahd_lqostat2_print(ahd_inb(ahd
, LQOSTAT2
), &cur_col
, 50);
9704 printk("\nSCB Count = %d CMDS_PENDING = %d LASTSCB 0x%x "
9705 "CURRSCB 0x%x NEXTSCB 0x%x\n",
9706 ahd
->scb_data
.numscbs
, ahd_inw(ahd
, CMDS_PENDING
),
9707 ahd_inw(ahd
, LASTSCB
), ahd_inw(ahd
, CURRSCB
),
9708 ahd_inw(ahd
, NEXTSCB
));
9711 ahd_search_qinfifo(ahd
, CAM_TARGET_WILDCARD
, ALL_CHANNELS
,
9712 CAM_LUN_WILDCARD
, SCB_LIST_NULL
,
9713 ROLE_UNKNOWN
, /*status*/0, SEARCH_PRINT
);
9714 saved_scb_index
= ahd_get_scbptr(ahd
);
9715 printk("Pending list:");
9717 LIST_FOREACH(scb
, &ahd
->pending_scbs
, pending_links
) {
9718 if (i
++ > AHD_SCB_MAX
)
9720 cur_col
= printk("\n%3d FIFO_USE[0x%x] ", SCB_GET_TAG(scb
),
9721 ahd_inb_scbram(ahd
, SCB_FIFO_USE_COUNT
));
9722 ahd_set_scbptr(ahd
, SCB_GET_TAG(scb
));
9723 ahd_scb_control_print(ahd_inb_scbram(ahd
, SCB_CONTROL
),
9725 ahd_scb_scsiid_print(ahd_inb_scbram(ahd
, SCB_SCSIID
),
9728 printk("\nTotal %d\n", i
);
9730 printk("Kernel Free SCB list: ");
9732 TAILQ_FOREACH(scb
, &ahd
->scb_data
.free_scbs
, links
.tqe
) {
9733 struct scb
*list_scb
;
9737 printk("%d ", SCB_GET_TAG(list_scb
));
9738 list_scb
= LIST_NEXT(list_scb
, collision_links
);
9739 } while (list_scb
&& i
++ < AHD_SCB_MAX
);
9742 LIST_FOREACH(scb
, &ahd
->scb_data
.any_dev_free_scb_list
, links
.le
) {
9743 if (i
++ > AHD_SCB_MAX
)
9745 printk("%d ", SCB_GET_TAG(scb
));
9749 printk("Sequencer Complete DMA-inprog list: ");
9750 scb_index
= ahd_inw(ahd
, COMPLETE_SCB_DMAINPROG_HEAD
);
9752 while (!SCBID_IS_NULL(scb_index
) && i
++ < AHD_SCB_MAX
) {
9753 ahd_set_scbptr(ahd
, scb_index
);
9754 printk("%d ", scb_index
);
9755 scb_index
= ahd_inw_scbram(ahd
, SCB_NEXT_COMPLETE
);
9759 printk("Sequencer Complete list: ");
9760 scb_index
= ahd_inw(ahd
, COMPLETE_SCB_HEAD
);
9762 while (!SCBID_IS_NULL(scb_index
) && i
++ < AHD_SCB_MAX
) {
9763 ahd_set_scbptr(ahd
, scb_index
);
9764 printk("%d ", scb_index
);
9765 scb_index
= ahd_inw_scbram(ahd
, SCB_NEXT_COMPLETE
);
9769 printk("Sequencer DMA-Up and Complete list: ");
9770 scb_index
= ahd_inw(ahd
, COMPLETE_DMA_SCB_HEAD
);
9772 while (!SCBID_IS_NULL(scb_index
) && i
++ < AHD_SCB_MAX
) {
9773 ahd_set_scbptr(ahd
, scb_index
);
9774 printk("%d ", scb_index
);
9775 scb_index
= ahd_inw_scbram(ahd
, SCB_NEXT_COMPLETE
);
9778 printk("Sequencer On QFreeze and Complete list: ");
9779 scb_index
= ahd_inw(ahd
, COMPLETE_ON_QFREEZE_HEAD
);
9781 while (!SCBID_IS_NULL(scb_index
) && i
++ < AHD_SCB_MAX
) {
9782 ahd_set_scbptr(ahd
, scb_index
);
9783 printk("%d ", scb_index
);
9784 scb_index
= ahd_inw_scbram(ahd
, SCB_NEXT_COMPLETE
);
9787 ahd_set_scbptr(ahd
, saved_scb_index
);
9788 dffstat
= ahd_inb(ahd
, DFFSTAT
);
9789 for (i
= 0; i
< 2; i
++) {
9791 struct scb
*fifo_scb
;
9795 ahd_set_modes(ahd
, AHD_MODE_DFF0
+ i
, AHD_MODE_DFF0
+ i
);
9796 fifo_scbptr
= ahd_get_scbptr(ahd
);
9797 printk("\n\n%s: FIFO%d %s, LONGJMP == 0x%x, SCB 0x%x\n",
9799 (dffstat
& (FIFO0FREE
<< i
)) ? "Free" : "Active",
9800 ahd_inw(ahd
, LONGJMP_ADDR
), fifo_scbptr
);
9802 ahd_seqimode_print(ahd_inb(ahd
, SEQIMODE
), &cur_col
, 50);
9803 ahd_seqintsrc_print(ahd_inb(ahd
, SEQINTSRC
), &cur_col
, 50);
9804 ahd_dfcntrl_print(ahd_inb(ahd
, DFCNTRL
), &cur_col
, 50);
9805 ahd_dfstatus_print(ahd_inb(ahd
, DFSTATUS
), &cur_col
, 50);
9806 ahd_sg_cache_shadow_print(ahd_inb(ahd
, SG_CACHE_SHADOW
),
9808 ahd_sg_state_print(ahd_inb(ahd
, SG_STATE
), &cur_col
, 50);
9809 ahd_dffsxfrctl_print(ahd_inb(ahd
, DFFSXFRCTL
), &cur_col
, 50);
9810 ahd_soffcnt_print(ahd_inb(ahd
, SOFFCNT
), &cur_col
, 50);
9811 ahd_mdffstat_print(ahd_inb(ahd
, MDFFSTAT
), &cur_col
, 50);
9816 cur_col
+= printk("SHADDR = 0x%x%x, SHCNT = 0x%x ",
9817 ahd_inl(ahd
, SHADDR
+4),
9818 ahd_inl(ahd
, SHADDR
),
9819 (ahd_inb(ahd
, SHCNT
)
9820 | (ahd_inb(ahd
, SHCNT
+ 1) << 8)
9821 | (ahd_inb(ahd
, SHCNT
+ 2) << 16)));
9826 cur_col
+= printk("HADDR = 0x%x%x, HCNT = 0x%x ",
9827 ahd_inl(ahd
, HADDR
+4),
9828 ahd_inl(ahd
, HADDR
),
9830 | (ahd_inb(ahd
, HCNT
+ 1) << 8)
9831 | (ahd_inb(ahd
, HCNT
+ 2) << 16)));
9832 ahd_ccsgctl_print(ahd_inb(ahd
, CCSGCTL
), &cur_col
, 50);
9834 if ((ahd_debug
& AHD_SHOW_SG
) != 0) {
9835 fifo_scb
= ahd_lookup_scb(ahd
, fifo_scbptr
);
9836 if (fifo_scb
!= NULL
)
9837 ahd_dump_sglist(fifo_scb
);
9842 for (i
= 0; i
< 20; i
++)
9843 printk("0x%x ", ahd_inb(ahd
, LQIN
+ i
));
9845 ahd_set_modes(ahd
, AHD_MODE_CFG
, AHD_MODE_CFG
);
9846 printk("%s: LQISTATE = 0x%x, LQOSTATE = 0x%x, OPTIONMODE = 0x%x\n",
9847 ahd_name(ahd
), ahd_inb(ahd
, LQISTATE
), ahd_inb(ahd
, LQOSTATE
),
9848 ahd_inb(ahd
, OPTIONMODE
));
9849 printk("%s: OS_SPACE_CNT = 0x%x MAXCMDCNT = 0x%x\n",
9850 ahd_name(ahd
), ahd_inb(ahd
, OS_SPACE_CNT
),
9851 ahd_inb(ahd
, MAXCMDCNT
));
9852 printk("%s: SAVED_SCSIID = 0x%x SAVED_LUN = 0x%x\n",
9853 ahd_name(ahd
), ahd_inb(ahd
, SAVED_SCSIID
),
9854 ahd_inb(ahd
, SAVED_LUN
));
9855 ahd_simode0_print(ahd_inb(ahd
, SIMODE0
), &cur_col
, 50);
9857 ahd_set_modes(ahd
, AHD_MODE_CCHAN
, AHD_MODE_CCHAN
);
9859 ahd_ccscbctl_print(ahd_inb(ahd
, CCSCBCTL
), &cur_col
, 50);
9861 ahd_set_modes(ahd
, ahd
->saved_src_mode
, ahd
->saved_dst_mode
);
9862 printk("%s: REG0 == 0x%x, SINDEX = 0x%x, DINDEX = 0x%x\n",
9863 ahd_name(ahd
), ahd_inw(ahd
, REG0
), ahd_inw(ahd
, SINDEX
),
9864 ahd_inw(ahd
, DINDEX
));
9865 printk("%s: SCBPTR == 0x%x, SCB_NEXT == 0x%x, SCB_NEXT2 == 0x%x\n",
9866 ahd_name(ahd
), ahd_get_scbptr(ahd
),
9867 ahd_inw_scbram(ahd
, SCB_NEXT
),
9868 ahd_inw_scbram(ahd
, SCB_NEXT2
));
9869 printk("CDB %x %x %x %x %x %x\n",
9870 ahd_inb_scbram(ahd
, SCB_CDB_STORE
),
9871 ahd_inb_scbram(ahd
, SCB_CDB_STORE
+1),
9872 ahd_inb_scbram(ahd
, SCB_CDB_STORE
+2),
9873 ahd_inb_scbram(ahd
, SCB_CDB_STORE
+3),
9874 ahd_inb_scbram(ahd
, SCB_CDB_STORE
+4),
9875 ahd_inb_scbram(ahd
, SCB_CDB_STORE
+5));
9877 for (i
= 0; i
< ahd
->stack_size
; i
++) {
9878 ahd
->saved_stack
[i
] =
9879 ahd_inb(ahd
, STACK
)|(ahd_inb(ahd
, STACK
) << 8);
9880 printk(" 0x%x", ahd
->saved_stack
[i
]);
9882 for (i
= ahd
->stack_size
-1; i
>= 0; i
--) {
9883 ahd_outb(ahd
, STACK
, ahd
->saved_stack
[i
] & 0xFF);
9884 ahd_outb(ahd
, STACK
, (ahd
->saved_stack
[i
] >> 8) & 0xFF);
9886 printk("\n<<<<<<<<<<<<<<<<< Dump Card State Ends >>>>>>>>>>>>>>>>>>\n");
9887 ahd_restore_modes(ahd
, saved_modes
);
9894 ahd_dump_scbs(struct ahd_softc
*ahd
)
9896 ahd_mode_state saved_modes
;
9897 u_int saved_scb_index
;
9900 saved_modes
= ahd_save_modes(ahd
);
9901 ahd_set_modes(ahd
, AHD_MODE_SCSI
, AHD_MODE_SCSI
);
9902 saved_scb_index
= ahd_get_scbptr(ahd
);
9903 for (i
= 0; i
< AHD_SCB_MAX
; i
++) {
9904 ahd_set_scbptr(ahd
, i
);
9906 printk("(CTRL 0x%x ID 0x%x N 0x%x N2 0x%x SG 0x%x, RSG 0x%x)\n",
9907 ahd_inb_scbram(ahd
, SCB_CONTROL
),
9908 ahd_inb_scbram(ahd
, SCB_SCSIID
),
9909 ahd_inw_scbram(ahd
, SCB_NEXT
),
9910 ahd_inw_scbram(ahd
, SCB_NEXT2
),
9911 ahd_inl_scbram(ahd
, SCB_SGPTR
),
9912 ahd_inl_scbram(ahd
, SCB_RESIDUAL_SGPTR
));
9915 ahd_set_scbptr(ahd
, saved_scb_index
);
9916 ahd_restore_modes(ahd
, saved_modes
);
9920 /**************************** Flexport Logic **********************************/
9922 * Read count 16bit words from 16bit word address start_addr from the
9923 * SEEPROM attached to the controller, into buf, using the controller's
9924 * SEEPROM reading state machine. Optionally treat the data as a byte
9925 * stream in terms of byte order.
9928 ahd_read_seeprom(struct ahd_softc
*ahd
, uint16_t *buf
,
9929 u_int start_addr
, u_int count
, int bytestream
)
9936 * If we never make it through the loop even once,
9937 * we were passed invalid arguments.
9940 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
9941 end_addr
= start_addr
+ count
;
9942 for (cur_addr
= start_addr
; cur_addr
< end_addr
; cur_addr
++) {
9944 ahd_outb(ahd
, SEEADR
, cur_addr
);
9945 ahd_outb(ahd
, SEECTL
, SEEOP_READ
| SEESTART
);
9947 error
= ahd_wait_seeprom(ahd
);
9950 if (bytestream
!= 0) {
9951 uint8_t *bytestream_ptr
;
9953 bytestream_ptr
= (uint8_t *)buf
;
9954 *bytestream_ptr
++ = ahd_inb(ahd
, SEEDAT
);
9955 *bytestream_ptr
= ahd_inb(ahd
, SEEDAT
+1);
9958 * ahd_inw() already handles machine byte order.
9960 *buf
= ahd_inw(ahd
, SEEDAT
);
9968 * Write count 16bit words from buf, into SEEPROM attache to the
9969 * controller starting at 16bit word address start_addr, using the
9970 * controller's SEEPROM writing state machine.
9973 ahd_write_seeprom(struct ahd_softc
*ahd
, uint16_t *buf
,
9974 u_int start_addr
, u_int count
)
9981 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
9984 /* Place the chip into write-enable mode */
9985 ahd_outb(ahd
, SEEADR
, SEEOP_EWEN_ADDR
);
9986 ahd_outb(ahd
, SEECTL
, SEEOP_EWEN
| SEESTART
);
9987 error
= ahd_wait_seeprom(ahd
);
9992 * Write the data. If we don't get through the loop at
9993 * least once, the arguments were invalid.
9996 end_addr
= start_addr
+ count
;
9997 for (cur_addr
= start_addr
; cur_addr
< end_addr
; cur_addr
++) {
9998 ahd_outw(ahd
, SEEDAT
, *buf
++);
9999 ahd_outb(ahd
, SEEADR
, cur_addr
);
10000 ahd_outb(ahd
, SEECTL
, SEEOP_WRITE
| SEESTART
);
10002 retval
= ahd_wait_seeprom(ahd
);
10010 ahd_outb(ahd
, SEEADR
, SEEOP_EWDS_ADDR
);
10011 ahd_outb(ahd
, SEECTL
, SEEOP_EWDS
| SEESTART
);
10012 error
= ahd_wait_seeprom(ahd
);
10019 * Wait ~100us for the serial eeprom to satisfy our request.
10022 ahd_wait_seeprom(struct ahd_softc
*ahd
)
10027 while ((ahd_inb(ahd
, SEESTAT
) & (SEEARBACK
|SEEBUSY
)) != 0 && --cnt
)
10031 return (ETIMEDOUT
);
10036 * Validate the two checksums in the per_channel
10037 * vital product data struct.
10040 ahd_verify_vpd_cksum(struct vpd_config
*vpd
)
10047 vpdarray
= (uint8_t *)vpd
;
10048 maxaddr
= offsetof(struct vpd_config
, vpd_checksum
);
10050 for (i
= offsetof(struct vpd_config
, resource_type
); i
< maxaddr
; i
++)
10051 checksum
= checksum
+ vpdarray
[i
];
10053 || (-checksum
& 0xFF) != vpd
->vpd_checksum
)
10057 maxaddr
= offsetof(struct vpd_config
, checksum
);
10058 for (i
= offsetof(struct vpd_config
, default_target_flags
);
10060 checksum
= checksum
+ vpdarray
[i
];
10062 || (-checksum
& 0xFF) != vpd
->checksum
)
10068 ahd_verify_cksum(struct seeprom_config
*sc
)
10075 maxaddr
= (sizeof(*sc
)/2) - 1;
10077 scarray
= (uint16_t *)sc
;
10079 for (i
= 0; i
< maxaddr
; i
++)
10080 checksum
= checksum
+ scarray
[i
];
10082 || (checksum
& 0xFFFF) != sc
->checksum
) {
10090 ahd_acquire_seeprom(struct ahd_softc
*ahd
)
10093 * We should be able to determine the SEEPROM type
10094 * from the flexport logic, but unfortunately not
10095 * all implementations have this logic and there is
10096 * no programatic method for determining if the logic
10104 error
= ahd_read_flexport(ahd
, FLXADDR_ROMSTAT_CURSENSECTL
, &seetype
);
10106 || ((seetype
& FLX_ROMSTAT_SEECFG
) == FLX_ROMSTAT_SEE_NONE
))
10113 ahd_release_seeprom(struct ahd_softc
*ahd
)
10115 /* Currently a no-op */
10119 * Wait at most 2 seconds for flexport arbitration to succeed.
10122 ahd_wait_flexport(struct ahd_softc
*ahd
)
10126 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
10127 cnt
= 1000000 * 2 / 5;
10128 while ((ahd_inb(ahd
, BRDCTL
) & FLXARBACK
) == 0 && --cnt
)
10132 return (ETIMEDOUT
);
10137 ahd_write_flexport(struct ahd_softc
*ahd
, u_int addr
, u_int value
)
10141 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
10143 panic("ahd_write_flexport: address out of range");
10144 ahd_outb(ahd
, BRDCTL
, BRDEN
|(addr
<< 3));
10145 error
= ahd_wait_flexport(ahd
);
10148 ahd_outb(ahd
, BRDDAT
, value
);
10149 ahd_flush_device_writes(ahd
);
10150 ahd_outb(ahd
, BRDCTL
, BRDSTB
|BRDEN
|(addr
<< 3));
10151 ahd_flush_device_writes(ahd
);
10152 ahd_outb(ahd
, BRDCTL
, BRDEN
|(addr
<< 3));
10153 ahd_flush_device_writes(ahd
);
10154 ahd_outb(ahd
, BRDCTL
, 0);
10155 ahd_flush_device_writes(ahd
);
10160 ahd_read_flexport(struct ahd_softc
*ahd
, u_int addr
, uint8_t *value
)
10164 AHD_ASSERT_MODES(ahd
, AHD_MODE_SCSI_MSK
, AHD_MODE_SCSI_MSK
);
10166 panic("ahd_read_flexport: address out of range");
10167 ahd_outb(ahd
, BRDCTL
, BRDRW
|BRDEN
|(addr
<< 3));
10168 error
= ahd_wait_flexport(ahd
);
10171 *value
= ahd_inb(ahd
, BRDDAT
);
10172 ahd_outb(ahd
, BRDCTL
, 0);
10173 ahd_flush_device_writes(ahd
);
10177 /************************* Target Mode ****************************************/
10178 #ifdef AHD_TARGET_MODE
10180 ahd_find_tmode_devs(struct ahd_softc
*ahd
, struct cam_sim
*sim
, union ccb
*ccb
,
10181 struct ahd_tmode_tstate
**tstate
,
10182 struct ahd_tmode_lstate
**lstate
,
10183 int notfound_failure
)
10186 if ((ahd
->features
& AHD_TARGETMODE
) == 0)
10187 return (CAM_REQ_INVALID
);
10190 * Handle the 'black hole' device that sucks up
10191 * requests to unattached luns on enabled targets.
10193 if (ccb
->ccb_h
.target_id
== CAM_TARGET_WILDCARD
10194 && ccb
->ccb_h
.target_lun
== CAM_LUN_WILDCARD
) {
10196 *lstate
= ahd
->black_hole
;
10200 max_id
= (ahd
->features
& AHD_WIDE
) ? 16 : 8;
10201 if (ccb
->ccb_h
.target_id
>= max_id
)
10202 return (CAM_TID_INVALID
);
10204 if (ccb
->ccb_h
.target_lun
>= AHD_NUM_LUNS
)
10205 return (CAM_LUN_INVALID
);
10207 *tstate
= ahd
->enabled_targets
[ccb
->ccb_h
.target_id
];
10209 if (*tstate
!= NULL
)
10211 (*tstate
)->enabled_luns
[ccb
->ccb_h
.target_lun
];
10214 if (notfound_failure
!= 0 && *lstate
== NULL
)
10215 return (CAM_PATH_INVALID
);
10217 return (CAM_REQ_CMP
);
10221 ahd_handle_en_lun(struct ahd_softc
*ahd
, struct cam_sim
*sim
, union ccb
*ccb
)
10224 struct ahd_tmode_tstate
*tstate
;
10225 struct ahd_tmode_lstate
*lstate
;
10226 struct ccb_en_lun
*cel
;
10234 status
= ahd_find_tmode_devs(ahd
, sim
, ccb
, &tstate
, &lstate
,
10235 /*notfound_failure*/FALSE
);
10237 if (status
!= CAM_REQ_CMP
) {
10238 ccb
->ccb_h
.status
= status
;
10242 if ((ahd
->features
& AHD_MULTIROLE
) != 0) {
10245 our_id
= ahd
->our_id
;
10246 if (ccb
->ccb_h
.target_id
!= our_id
) {
10247 if ((ahd
->features
& AHD_MULTI_TID
) != 0
10248 && (ahd
->flags
& AHD_INITIATORROLE
) != 0) {
10250 * Only allow additional targets if
10251 * the initiator role is disabled.
10252 * The hardware cannot handle a re-select-in
10253 * on the initiator id during a re-select-out
10254 * on a different target id.
10256 status
= CAM_TID_INVALID
;
10257 } else if ((ahd
->flags
& AHD_INITIATORROLE
) != 0
10258 || ahd
->enabled_luns
> 0) {
10260 * Only allow our target id to change
10261 * if the initiator role is not configured
10262 * and there are no enabled luns which
10263 * are attached to the currently registered
10266 status
= CAM_TID_INVALID
;
10271 if (status
!= CAM_REQ_CMP
) {
10272 ccb
->ccb_h
.status
= status
;
10277 * We now have an id that is valid.
10278 * If we aren't in target mode, switch modes.
10280 if ((ahd
->flags
& AHD_TARGETROLE
) == 0
10281 && ccb
->ccb_h
.target_id
!= CAM_TARGET_WILDCARD
) {
10284 printk("Configuring Target Mode\n");
10286 if (LIST_FIRST(&ahd
->pending_scbs
) != NULL
) {
10287 ccb
->ccb_h
.status
= CAM_BUSY
;
10288 ahd_unlock(ahd
, &s
);
10291 ahd
->flags
|= AHD_TARGETROLE
;
10292 if ((ahd
->features
& AHD_MULTIROLE
) == 0)
10293 ahd
->flags
&= ~AHD_INITIATORROLE
;
10297 ahd_unlock(ahd
, &s
);
10300 target
= ccb
->ccb_h
.target_id
;
10301 lun
= ccb
->ccb_h
.target_lun
;
10302 channel
= SIM_CHANNEL(ahd
, sim
);
10303 target_mask
= 0x01 << target
;
10304 if (channel
== 'B')
10307 if (cel
->enable
!= 0) {
10310 /* Are we already enabled?? */
10311 if (lstate
!= NULL
) {
10312 xpt_print_path(ccb
->ccb_h
.path
);
10313 printk("Lun already enabled\n");
10314 ccb
->ccb_h
.status
= CAM_LUN_ALRDY_ENA
;
10318 if (cel
->grp6_len
!= 0
10319 || cel
->grp7_len
!= 0) {
10321 * Don't (yet?) support vendor
10322 * specific commands.
10324 ccb
->ccb_h
.status
= CAM_REQ_INVALID
;
10325 printk("Non-zero Group Codes\n");
10330 * Seems to be okay.
10331 * Setup our data structures.
10333 if (target
!= CAM_TARGET_WILDCARD
&& tstate
== NULL
) {
10334 tstate
= ahd_alloc_tstate(ahd
, target
, channel
);
10335 if (tstate
== NULL
) {
10336 xpt_print_path(ccb
->ccb_h
.path
);
10337 printk("Couldn't allocate tstate\n");
10338 ccb
->ccb_h
.status
= CAM_RESRC_UNAVAIL
;
10342 lstate
= kzalloc(sizeof(*lstate
), GFP_ATOMIC
);
10343 if (lstate
== NULL
) {
10344 xpt_print_path(ccb
->ccb_h
.path
);
10345 printk("Couldn't allocate lstate\n");
10346 ccb
->ccb_h
.status
= CAM_RESRC_UNAVAIL
;
10349 status
= xpt_create_path(&lstate
->path
, /*periph*/NULL
,
10350 xpt_path_path_id(ccb
->ccb_h
.path
),
10351 xpt_path_target_id(ccb
->ccb_h
.path
),
10352 xpt_path_lun_id(ccb
->ccb_h
.path
));
10353 if (status
!= CAM_REQ_CMP
) {
10355 xpt_print_path(ccb
->ccb_h
.path
);
10356 printk("Couldn't allocate path\n");
10357 ccb
->ccb_h
.status
= CAM_RESRC_UNAVAIL
;
10360 SLIST_INIT(&lstate
->accept_tios
);
10361 SLIST_INIT(&lstate
->immed_notifies
);
10364 if (target
!= CAM_TARGET_WILDCARD
) {
10365 tstate
->enabled_luns
[lun
] = lstate
;
10366 ahd
->enabled_luns
++;
10368 if ((ahd
->features
& AHD_MULTI_TID
) != 0) {
10371 targid_mask
= ahd_inw(ahd
, TARGID
);
10372 targid_mask
|= target_mask
;
10373 ahd_outw(ahd
, TARGID
, targid_mask
);
10374 ahd_update_scsiid(ahd
, targid_mask
);
10379 channel
= SIM_CHANNEL(ahd
, sim
);
10380 our_id
= SIM_SCSI_ID(ahd
, sim
);
10383 * This can only happen if selections
10386 if (target
!= our_id
) {
10391 sblkctl
= ahd_inb(ahd
, SBLKCTL
);
10392 cur_channel
= (sblkctl
& SELBUSB
)
10394 if ((ahd
->features
& AHD_TWIN
) == 0)
10396 swap
= cur_channel
!= channel
;
10397 ahd
->our_id
= target
;
10400 ahd_outb(ahd
, SBLKCTL
,
10401 sblkctl
^ SELBUSB
);
10403 ahd_outb(ahd
, SCSIID
, target
);
10406 ahd_outb(ahd
, SBLKCTL
, sblkctl
);
10410 ahd
->black_hole
= lstate
;
10411 /* Allow select-in operations */
10412 if (ahd
->black_hole
!= NULL
&& ahd
->enabled_luns
> 0) {
10413 scsiseq1
= ahd_inb(ahd
, SCSISEQ_TEMPLATE
);
10414 scsiseq1
|= ENSELI
;
10415 ahd_outb(ahd
, SCSISEQ_TEMPLATE
, scsiseq1
);
10416 scsiseq1
= ahd_inb(ahd
, SCSISEQ1
);
10417 scsiseq1
|= ENSELI
;
10418 ahd_outb(ahd
, SCSISEQ1
, scsiseq1
);
10421 ahd_unlock(ahd
, &s
);
10422 ccb
->ccb_h
.status
= CAM_REQ_CMP
;
10423 xpt_print_path(ccb
->ccb_h
.path
);
10424 printk("Lun now enabled for target mode\n");
10429 if (lstate
== NULL
) {
10430 ccb
->ccb_h
.status
= CAM_LUN_INVALID
;
10436 ccb
->ccb_h
.status
= CAM_REQ_CMP
;
10437 LIST_FOREACH(scb
, &ahd
->pending_scbs
, pending_links
) {
10438 struct ccb_hdr
*ccbh
;
10440 ccbh
= &scb
->io_ctx
->ccb_h
;
10441 if (ccbh
->func_code
== XPT_CONT_TARGET_IO
10442 && !xpt_path_comp(ccbh
->path
, ccb
->ccb_h
.path
)){
10443 printk("CTIO pending\n");
10444 ccb
->ccb_h
.status
= CAM_REQ_INVALID
;
10445 ahd_unlock(ahd
, &s
);
10450 if (SLIST_FIRST(&lstate
->accept_tios
) != NULL
) {
10451 printk("ATIOs pending\n");
10452 ccb
->ccb_h
.status
= CAM_REQ_INVALID
;
10455 if (SLIST_FIRST(&lstate
->immed_notifies
) != NULL
) {
10456 printk("INOTs pending\n");
10457 ccb
->ccb_h
.status
= CAM_REQ_INVALID
;
10460 if (ccb
->ccb_h
.status
!= CAM_REQ_CMP
) {
10461 ahd_unlock(ahd
, &s
);
10465 xpt_print_path(ccb
->ccb_h
.path
);
10466 printk("Target mode disabled\n");
10467 xpt_free_path(lstate
->path
);
10471 /* Can we clean up the target too? */
10472 if (target
!= CAM_TARGET_WILDCARD
) {
10473 tstate
->enabled_luns
[lun
] = NULL
;
10474 ahd
->enabled_luns
--;
10475 for (empty
= 1, i
= 0; i
< 8; i
++)
10476 if (tstate
->enabled_luns
[i
] != NULL
) {
10482 ahd_free_tstate(ahd
, target
, channel
,
10484 if (ahd
->features
& AHD_MULTI_TID
) {
10487 targid_mask
= ahd_inw(ahd
, TARGID
);
10488 targid_mask
&= ~target_mask
;
10489 ahd_outw(ahd
, TARGID
, targid_mask
);
10490 ahd_update_scsiid(ahd
, targid_mask
);
10495 ahd
->black_hole
= NULL
;
10498 * We can't allow selections without
10499 * our black hole device.
10503 if (ahd
->enabled_luns
== 0) {
10504 /* Disallow select-in */
10507 scsiseq1
= ahd_inb(ahd
, SCSISEQ_TEMPLATE
);
10508 scsiseq1
&= ~ENSELI
;
10509 ahd_outb(ahd
, SCSISEQ_TEMPLATE
, scsiseq1
);
10510 scsiseq1
= ahd_inb(ahd
, SCSISEQ1
);
10511 scsiseq1
&= ~ENSELI
;
10512 ahd_outb(ahd
, SCSISEQ1
, scsiseq1
);
10514 if ((ahd
->features
& AHD_MULTIROLE
) == 0) {
10515 printk("Configuring Initiator Mode\n");
10516 ahd
->flags
&= ~AHD_TARGETROLE
;
10517 ahd
->flags
|= AHD_INITIATORROLE
;
10522 * Unpaused. The extra unpause
10523 * that follows is harmless.
10528 ahd_unlock(ahd
, &s
);
10534 ahd_update_scsiid(struct ahd_softc
*ahd
, u_int targid_mask
)
10540 if ((ahd
->features
& AHD_MULTI_TID
) == 0)
10541 panic("ahd_update_scsiid called on non-multitid unit\n");
10544 * Since we will rely on the TARGID mask
10545 * for selection enables, ensure that OID
10546 * in SCSIID is not set to some other ID
10547 * that we don't want to allow selections on.
10549 if ((ahd
->features
& AHD_ULTRA2
) != 0)
10550 scsiid
= ahd_inb(ahd
, SCSIID_ULTRA2
);
10552 scsiid
= ahd_inb(ahd
, SCSIID
);
10553 scsiid_mask
= 0x1 << (scsiid
& OID
);
10554 if ((targid_mask
& scsiid_mask
) == 0) {
10557 /* ffs counts from 1 */
10558 our_id
= ffs(targid_mask
);
10560 our_id
= ahd
->our_id
;
10566 if ((ahd
->features
& AHD_ULTRA2
) != 0)
10567 ahd_outb(ahd
, SCSIID_ULTRA2
, scsiid
);
10569 ahd_outb(ahd
, SCSIID
, scsiid
);
10574 ahd_run_tqinfifo(struct ahd_softc
*ahd
, int paused
)
10576 struct target_cmd
*cmd
;
10578 ahd_sync_tqinfifo(ahd
, BUS_DMASYNC_POSTREAD
);
10579 while ((cmd
= &ahd
->targetcmds
[ahd
->tqinfifonext
])->cmd_valid
!= 0) {
10582 * Only advance through the queue if we
10583 * have the resources to process the command.
10585 if (ahd_handle_target_cmd(ahd
, cmd
) != 0)
10588 cmd
->cmd_valid
= 0;
10589 ahd_dmamap_sync(ahd
, ahd
->shared_data_dmat
,
10590 ahd
->shared_data_map
.dmamap
,
10591 ahd_targetcmd_offset(ahd
, ahd
->tqinfifonext
),
10592 sizeof(struct target_cmd
),
10593 BUS_DMASYNC_PREREAD
);
10594 ahd
->tqinfifonext
++;
10597 * Lazily update our position in the target mode incoming
10598 * command queue as seen by the sequencer.
10600 if ((ahd
->tqinfifonext
& (HOST_TQINPOS
- 1)) == 1) {
10603 hs_mailbox
= ahd_inb(ahd
, HS_MAILBOX
);
10604 hs_mailbox
&= ~HOST_TQINPOS
;
10605 hs_mailbox
|= ahd
->tqinfifonext
& HOST_TQINPOS
;
10606 ahd_outb(ahd
, HS_MAILBOX
, hs_mailbox
);
10612 ahd_handle_target_cmd(struct ahd_softc
*ahd
, struct target_cmd
*cmd
)
10614 struct ahd_tmode_tstate
*tstate
;
10615 struct ahd_tmode_lstate
*lstate
;
10616 struct ccb_accept_tio
*atio
;
10622 initiator
= SCSIID_TARGET(ahd
, cmd
->scsiid
);
10623 target
= SCSIID_OUR_ID(cmd
->scsiid
);
10624 lun
= (cmd
->identify
& MSG_IDENTIFY_LUNMASK
);
10627 tstate
= ahd
->enabled_targets
[target
];
10629 if (tstate
!= NULL
)
10630 lstate
= tstate
->enabled_luns
[lun
];
10633 * Commands for disabled luns go to the black hole driver.
10635 if (lstate
== NULL
)
10636 lstate
= ahd
->black_hole
;
10638 atio
= (struct ccb_accept_tio
*)SLIST_FIRST(&lstate
->accept_tios
);
10639 if (atio
== NULL
) {
10640 ahd
->flags
|= AHD_TQINFIFO_BLOCKED
;
10642 * Wait for more ATIOs from the peripheral driver for this lun.
10646 ahd
->flags
&= ~AHD_TQINFIFO_BLOCKED
;
10648 if ((ahd_debug
& AHD_SHOW_TQIN
) != 0)
10649 printk("Incoming command from %d for %d:%d%s\n",
10650 initiator
, target
, lun
,
10651 lstate
== ahd
->black_hole
? "(Black Holed)" : "");
10653 SLIST_REMOVE_HEAD(&lstate
->accept_tios
, sim_links
.sle
);
10655 if (lstate
== ahd
->black_hole
) {
10656 /* Fill in the wildcards */
10657 atio
->ccb_h
.target_id
= target
;
10658 atio
->ccb_h
.target_lun
= lun
;
10662 * Package it up and send it off to
10663 * whomever has this lun enabled.
10665 atio
->sense_len
= 0;
10666 atio
->init_id
= initiator
;
10667 if (byte
[0] != 0xFF) {
10668 /* Tag was included */
10669 atio
->tag_action
= *byte
++;
10670 atio
->tag_id
= *byte
++;
10671 atio
->ccb_h
.flags
= CAM_TAG_ACTION_VALID
;
10673 atio
->ccb_h
.flags
= 0;
10677 /* Okay. Now determine the cdb size based on the command code */
10678 switch (*byte
>> CMD_GROUP_CODE_SHIFT
) {
10684 atio
->cdb_len
= 10;
10687 atio
->cdb_len
= 16;
10690 atio
->cdb_len
= 12;
10694 /* Only copy the opcode. */
10696 printk("Reserved or VU command code type encountered\n");
10700 memcpy(atio
->cdb_io
.cdb_bytes
, byte
, atio
->cdb_len
);
10702 atio
->ccb_h
.status
|= CAM_CDB_RECVD
;
10704 if ((cmd
->identify
& MSG_IDENTIFY_DISCFLAG
) == 0) {
10706 * We weren't allowed to disconnect.
10707 * We're hanging on the bus until a
10708 * continue target I/O comes in response
10709 * to this accept tio.
10712 if ((ahd_debug
& AHD_SHOW_TQIN
) != 0)
10713 printk("Received Immediate Command %d:%d:%d - %p\n",
10714 initiator
, target
, lun
, ahd
->pending_device
);
10716 ahd
->pending_device
= lstate
;
10717 ahd_freeze_ccb((union ccb
*)atio
);
10718 atio
->ccb_h
.flags
|= CAM_DIS_DISCONNECT
;
10720 xpt_done((union ccb
*)atio
);