48 #include <dev/aic7xxx/aic7xxx_osm.h>
49 #include <dev/aic7xxx/aic7xxx_inline.h>
50 #include <dev/aic7xxx/aicasm/aicasm_insformat.h>
54 static const char *
const ahc_chip_names[] = {
82 {
ILLSADDR,
"Illegal Sequencer Address referrenced" },
83 {
ILLOPCODE,
"Illegal Opcode in sequencer program" },
84 {
SQPARERR,
"Sequencer Parity Error" },
85 {
DPARERR,
"Data-path Parity Error" },
86 {
MPARERR,
"Scratch or SCB Memory Parity Error" },
96 { P_DATAOUT_DT,
MSG_NOOP,
"in DT Data-out phase" },
120 { 0x42, 0x000, 9,
"80.0" },
121 { 0x03, 0x000, 10,
"40.0" },
122 { 0x04, 0x000, 11,
"33.0" },
123 { 0x05, 0x100, 12,
"20.0" },
124 { 0x06, 0x110, 15,
"16.0" },
125 { 0x07, 0x120, 18,
"13.4" },
126 { 0x08, 0x000, 25,
"10.0" },
127 { 0x19, 0x010, 31,
"8.0" },
128 { 0x1a, 0x020, 37,
"6.67" },
129 { 0x1b, 0x030, 43,
"5.7" },
130 { 0x1c, 0x040, 50,
"5.0" },
131 { 0x00, 0x050, 56,
"4.4" },
132 { 0x00, 0x060, 62,
"4.0" },
133 { 0x00, 0x070, 68,
"3.6" },
134 { 0x00, 0x000, 0,
NULL }
138 #include "aic7xxx_seq.h"
141 static void ahc_force_renegotiation(
struct ahc_softc *ahc,
146 #ifdef AHC_TARGET_MODE
147 static void ahc_free_tstate(
struct ahc_softc *ahc,
151 ahc_devlimited_syncrate(
struct ahc_softc *ahc,
156 static void ahc_update_pending_scbs(
struct ahc_softc *ahc);
157 static void ahc_fetch_devinfo(
struct ahc_softc *ahc,
159 static void ahc_scb_devinfo(
struct ahc_softc *ahc,
162 static void ahc_assert_atn(
struct ahc_softc *ahc);
163 static void ahc_setup_initiator_msgout(
struct ahc_softc *ahc,
166 static void ahc_build_transfer_msg(
struct ahc_softc *ahc,
168 static void ahc_construct_sdtr(
struct ahc_softc *ahc,
171 static void ahc_construct_wdtr(
struct ahc_softc *ahc,
174 static void ahc_construct_ppr(
struct ahc_softc *ahc,
178 static void ahc_clear_msg_state(
struct ahc_softc *ahc);
179 static void ahc_handle_proto_violation(
struct ahc_softc *ahc);
180 static void ahc_handle_message_phase(
struct ahc_softc *ahc);
188 static int ahc_parse_msg(
struct ahc_softc *ahc,
190 static int ahc_handle_msg_reject(
struct ahc_softc *ahc,
192 static void ahc_handle_ign_wide_residue(
struct ahc_softc *ahc,
194 static void ahc_reinitialize_dataptrs(
struct ahc_softc *ahc);
195 static void ahc_handle_devreset(
struct ahc_softc *ahc,
199 #ifdef AHC_TARGET_MODE
200 static void ahc_setup_target_msgin(
struct ahc_softc *ahc,
206 static void ahc_build_free_scb_list(
struct ahc_softc *ahc);
207 static int ahc_init_scbdata(
struct ahc_softc *ahc);
208 static void ahc_fini_scbdata(
struct ahc_softc *ahc);
209 static void ahc_qinfifo_requeue(
struct ahc_softc *ahc,
210 struct scb *prev_scb,
212 static int ahc_qinfifo_count(
struct ahc_softc *ahc);
215 static void ahc_add_curscb_to_free_list(
struct ahc_softc *ahc);
218 static void ahc_reset_current_bus(
struct ahc_softc *ahc);
220 static void ahc_dumpseq(
struct ahc_softc *ahc);
222 static int ahc_loadseq(
struct ahc_softc *ahc);
223 static int ahc_check_patch(
struct ahc_softc *ahc,
224 const struct patch **start_patch,
226 static void ahc_download_instr(
struct ahc_softc *ahc,
228 #ifdef AHC_TARGET_MODE
229 static void ahc_queue_lstate_event(
struct ahc_softc *ahc,
230 struct ahc_tmode_lstate *lstate,
234 static void ahc_update_scsiid(
struct ahc_softc *ahc,
236 static int ahc_handle_target_cmd(
struct ahc_softc *ahc,
242 static void ahc_busy_tcl(
struct ahc_softc *ahc,
246 static void ahc_run_untagged_queues(
struct ahc_softc *ahc);
247 static void ahc_run_untagged_queue(
struct ahc_softc *ahc,
248 struct scb_tailq *
queue);
251 static void ahc_alloc_scbs(
struct ahc_softc *ahc);
252 static void ahc_shutdown(
void *
arg);
255 static void ahc_clear_intstat(
struct ahc_softc *ahc);
256 static void ahc_run_qoutfifo(
struct ahc_softc *ahc);
257 #ifdef AHC_TARGET_MODE
258 static void ahc_run_tqinfifo(
struct ahc_softc *ahc,
int paused);
260 static void ahc_handle_brkadrint(
struct ahc_softc *ahc);
261 static void ahc_handle_seqint(
struct ahc_softc *ahc,
u_int intstat);
262 static void ahc_handle_scsiint(
struct ahc_softc *ahc,
264 static void ahc_clear_critical_section(
struct ahc_softc *ahc);
271 static void ahc_calc_residual(
struct ahc_softc *ahc,
275 static inline void ahc_freeze_untagged_queues(
struct ahc_softc *ahc);
276 static inline void ahc_release_untagged_queues(
struct ahc_softc *ahc);
283 ahc_freeze_untagged_queues(
struct ahc_softc *ahc)
296 ahc_release_untagged_queues(
struct ahc_softc *ahc)
301 ahc_run_untagged_queues(ahc);
350 ahc_pause_bug_fix(ahc);
380 return (&scb->
sg_list[sg_index]);
389 sg_index = sg - &scb->
sg_list[1];
402 ahc_sync_scb(
struct ahc_softc *ahc,
struct scb *scb,
int op)
406 (scb->
hscb - ahc->hscbs) *
sizeof(*scb->
hscb),
407 sizeof(*scb->
hscb), op);
422 #ifdef AHC_TARGET_MODE
436 ahc_update_residual(
struct ahc_softc *ahc,
struct scb *scb)
441 if ((sgptr & SG_RESID_VALID) != 0)
442 ahc_calc_residual(ahc, scb);
462 return (&(*tstate)->transinfo[remote_id]);
476 ahc_outb(ahc, port+1, (value >> 8) & 0xFF);
485 | (
ahc_inb(ahc, port+3) << 24));
491 ahc_outb(ahc, port, (value) & 0xFF);
492 ahc_outb(ahc, port+1, ((value) >> 8) & 0xFF);
493 ahc_outb(ahc, port+2, ((value) >> 16) & 0xFF);
494 ahc_outb(ahc, port+3, ((value) >> 24) & 0xFF);
514 ahc_outb(ahc, port+1, (value >> 8) & 0xFF);
515 ahc_outb(ahc, port+2, (value >> 16) & 0xFF);
516 ahc_outb(ahc, port+3, (value >> 24) & 0xFF);
517 ahc_outb(ahc, port+4, (value >> 32) & 0xFF);
518 ahc_outb(ahc, port+5, (value >> 40) & 0xFF);
519 ahc_outb(ahc, port+6, (value >> 48) & 0xFF);
520 ahc_outb(ahc, port+7, (value >> 56) & 0xFF);
558 ahc_platform_scb_free(ahc, scb);
568 ahc_sync_scb(ahc, scb,
574 ahc_swap_with_next_hscb(
struct ahc_softc *ahc,
struct scb *scb)
592 saved_tag = q_hscb->
tag;
599 q_hscb->
tag = saved_tag;
616 ahc_swap_with_next_hscb(ahc, scb);
620 panic(
"Attempt to queue invalid SCB tag %x:%x\n",
627 if (ahc_get_transfer_length(scb) & 0x1)
628 scb->
hscb->lun |= SCB_XFERLEN_ODD;
658 offset = scb - ahc->
scb_data->scbarray;
659 return (&ahc->
scb_data->sense[offset]);
663 ahc_get_sense_bufaddr(
struct ahc_softc *ahc,
struct scb *scb)
667 offset = scb - ahc->
scb_data->scbarray;
668 return (ahc->
scb_data->sense_busaddr
683 #ifdef AHC_TARGET_MODE
687 ahc_targetcmd_offset(ahc, 0),
698 #define AHC_RUN_QOUTFIFO 0x1
699 #define AHC_RUN_TQINFIFO 0x2
701 ahc_check_cmdcmpltqueues(
struct ahc_softc *ahc)
711 #ifdef AHC_TARGET_MODE
716 ahc_targetcmd_offset(ahc, ahc->tqinfifofnext),
750 && (ahc_check_cmdcmpltqueues(ahc) != 0))
757 #if AHC_PCI_CONFIG > 0
781 ahc_flush_device_writes(ahc);
782 ahc_run_qoutfifo(ahc);
783 #ifdef AHC_TARGET_MODE
785 ahc_run_tqinfifo(ahc,
FALSE);
796 ahc_handle_brkadrint(ahc);
799 ahc_pause_bug_fix(ahc);
801 if ((intstat &
SEQINT) != 0)
802 ahc_handle_seqint(ahc, intstat);
805 ahc_handle_scsiint(ahc, intstat);
822 ahc_clear_msg_state(ahc);
854 if ((
ahc_inb(ahc, SEQ_FLAGS2) & SCB_DMA) != 0) {
855 ahc_add_curscb_to_free_list(ahc);
857 ahc_inb(ahc, SEQ_FLAGS2) & ~SCB_DMA);
913 printk(
"%s: WARNING no command for scb %d "
914 "(cmdcmplt)\nQOUTPOS = %d\n",
915 ahc_name(ahc), scb_index,
924 ahc_update_residual(ahc, scb);
930 ahc_run_untagged_queues(
struct ahc_softc *ahc)
934 for (i = 0; i < 16; i++)
939 ahc_run_untagged_queue(
struct ahc_softc *ahc,
struct scb_tailq *
queue)
955 ahc_handle_brkadrint(
struct ahc_softc *ahc)
965 for (i = 0; error != 1 && i <
num_errors; i++)
967 printk(
"%s: brkadrint, %s at seqaddr = 0x%x\n",
968 ahc_name(ahc), ahc_hard_errors[i].
errmesg,
989 ahc_fetch_devinfo(ahc, &devinfo);
1024 printk(
"ahc_intr - referenced scb "
1025 "not valid during seqint 0x%x scb(%d)\n",
1026 intstat, scb_index);
1028 panic(
"for safety");
1047 ahc_freeze_devq(ahc, scb);
1048 ahc_freeze_scb(scb);
1052 printk(
"%s: Interrupted for status of 0???\n",
1064 if (ahc_debug & AHC_SHOW_SENSE) {
1066 printk(
"SCB %d: requests Check Status\n",
1071 if (ahc_perform_autosense(scb) == 0)
1079 tinfo = &targ_info->
curr;
1085 ahc_update_residual(ahc, scb);
1087 if (ahc_debug & AHC_SHOW_SENSE) {
1089 printk(
"Sending Sense\n");
1092 sg->
addr = ahc_get_sense_bufaddr(ahc, scb);
1093 sg->
len = ahc_get_sense_bufsize(ahc, scb);
1127 if (ahc_get_residual(scb)
1128 == ahc_get_transfer_length(scb)) {
1151 ahc_scb_timer_reset(scb, 5 * 1000000);
1165 printk(
"%s:%c:%d: no active SCB for reconnecting "
1166 "target - issuing BUS DEVICE RESET\n",
1167 ahc_name(ahc), devinfo.channel, devinfo.target);
1168 printk(
"SAVED_SCSIID == 0x%x, SAVED_LUN == 0x%x, "
1169 "ARG_1 == 0x%x ACCUM = 0x%x\n",
1172 printk(
"SEQ_FLAGS == 0x%x, SCBPTR == 0x%x, BTT == 0x%x, "
1175 ahc_index_busy_tcl(ahc,
1179 printk(
"SCSIID == 0x%x, SCB_SCSIID == 0x%x, SCB_LUN == 0x%x, "
1180 "SCB_TAG == 0x%x, SCB_CONTROL == 0x%x\n",
1184 printk(
"SCSIBUSL == 0x%x, SCSISIGI == 0x%x\n",
1194 ahc_assert_atn(ahc);
1200 printk(
"%s:%c:%d: Warning - unknown message received from "
1201 "target (0x%x). Rejecting\n",
1202 ahc_name(ahc), devinfo.channel, devinfo.target, rejbyte);
1205 case PROTO_VIOLATION:
1207 ahc_handle_proto_violation(ahc);
1211 ahc_handle_ign_wide_residue(ahc, &devinfo);
1214 ahc_reinitialize_dataptrs(ahc);
1221 printk(
"%s:%c:%d: unknown scsi bus phase %x, "
1222 "lastphase = 0x%x. Attempting to continue\n",
1223 ahc_name(ahc), devinfo.channel, devinfo.target,
1227 case MISSED_BUSFREE:
1232 printk(
"%s:%c:%d: Missed busfree. "
1233 "Lastphase = 0x%x, Curphase = 0x%x\n",
1234 ahc_name(ahc), devinfo.channel, devinfo.target,
1260 printk(
"ahc_intr: HOST_MSG_LOOP bad "
1267 ahc_clear_intstat(ahc);
1277 panic(
"HOST_MSG_LOOP with "
1281 ahc_setup_initiator_msgout(ahc,
1290 #ifdef AHC_TARGET_MODE
1298 ahc_setup_target_msgin(ahc,
1305 ahc_handle_message_phase(ahc);
1349 while (--wait != 0) {
1362 printk(
"Unable to clear parity error. "
1363 "Resetting bus.\n");
1367 ahc_set_transaction_status(scb,
1393 for (i = 0; i < num_phases; i++) {
1394 if (lastphase == ahc_phase_table[i].
phase)
1398 printk(
"data overrun detected %s."
1400 ahc_phase_table[i].phasemsg,
1403 printk(
"%s seen Data Phase. Length = %ld. NumSGs = %d.\n",
1405 ahc_get_transfer_length(scb), scb->
sg_count);
1407 for (i = 0; i < scb->
sg_count; i++) {
1409 printk(
"sg[%d] - Addr 0x%x%x : Length %d\n",
1412 & SG_HIGH_ADDR_BITS),
1422 ahc_freeze_devq(ahc, scb);
1429 ahc_freeze_scb(scb);
1445 dscommand1 =
ahc_inb(ahc, DSCOMMAND1);
1446 ahc_outb(ahc, DSCOMMAND1, dscommand1 | HADDLDSEL0);
1448 ahc_outb(ahc, DSCOMMAND1, dscommand1);
1456 printk(
"%s:%c:%d:%d: Attempt to issue message failed\n",
1457 ahc_name(ahc), devinfo.channel, devinfo.target,
1476 printk(
"%s: No free or disconnected SCBs\n", ahc_name(ahc));
1478 panic(
"for safety");
1486 printk(
"Bogus TAG after DMA. SCBPTR %d, tag %d, our tag %d\n",
1490 panic(
"for safety");
1495 printk(
"%s: BTT calculation out of range\n", ahc_name(ahc));
1496 printk(
"SAVED_SCSIID == 0x%x, SAVED_LUN == 0x%x, "
1497 "ARG_1 == 0x%x ACCUM = 0x%x\n",
1500 printk(
"SEQ_FLAGS == 0x%x, SCBPTR == 0x%x, BTT == 0x%x, "
1501 "SINDEX == 0x%x\n, A == 0x%x\n",
1503 ahc_index_busy_tcl(ahc,
1508 printk(
"SCSIID == 0x%x, SCB_SCSIID == 0x%x, SCB_LUN == 0x%x, "
1509 "SCB_TAG == 0x%x, SCB_CONTROL == 0x%x\n",
1513 printk(
"SCSIBUSL == 0x%x, SCSISIGI == 0x%x\n",
1516 panic(
"for safety");
1520 printk(
"ahc_intr: seqint, "
1521 "intstat == 0x%x, scsisigi = 0x%x\n",
1549 intr_channel = cur_channel;
1556 if (status == 0 && status0 == 0) {
1562 intr_channel = (cur_channel ==
'A') ?
'B' :
'A';
1565 printk(
"%s: Spurious SCSI interrupt\n", ahc_name(ahc));
1573 ahc_clear_critical_section(ahc);
1582 && (status0 &
IOERR) != 0) {
1586 printk(
"%s: Transceiver State Has Changed to %s mode\n",
1587 ahc_name(ahc), now_lvd ?
"LVD" :
"SE");
1601 }
else if ((status &
SCSIRSTI) != 0) {
1602 printk(
"%s: Someone reset channel %c\n",
1603 ahc_name(ahc), intr_channel);
1604 if (intr_channel != cur_channel)
1607 }
else if ((status & SCSIPERR) != 0) {
1644 || curphase ==
P_DATAIN || curphase == P_DATAIN_DT)
1645 errorphase = curphase;
1647 errorphase = lastphase;
1649 for (i = 0; i < num_phases; i++) {
1650 if (errorphase == ahc_phase_table[i].
phase)
1662 printk(
"%s:%c:%d: ", ahc_name(ahc), intr_channel,
1665 if (silent ==
FALSE) {
1666 printk(
"parity error detected %s. "
1667 "SEQADDR(0x%x) SCSIRATE(0x%x)\n",
1668 ahc_phase_table[i].phasemsg,
1673 printk(
"\tCRC Value Mismatch\n");
1675 printk(
"\tNo terminal CRC packet "
1678 printk(
"\tIllegal CRC packet "
1680 if ((sstat2 & DUAL_EDGE_ERR) != 0)
1681 printk(
"\tUnexpected %sDT Data Phase\n",
1682 (scsirate & SINGLE_EDGE)
1688 && (sstat2 & DUAL_EDGE_ERR) != 0) {
1715 ahc_fetch_devinfo(ahc, &devinfo);
1716 ahc_force_renegotiation(ahc, &devinfo);
1720 }
else if ((status &
SELTO) != 0) {
1727 ahc_clear_msg_state(ahc);
1749 printk(
"%s: ahc_intr - referenced scb not "
1750 "valid during SELTO scb(%d, %d)\n",
1751 ahc_name(ahc), scbptr, scb_index);
1756 if ((ahc_debug & AHC_SHOW_SELTO) != 0) {
1758 printk(
"Saw Selection Timeout for SCB 0x%x\n",
1762 ahc_scb_devinfo(ahc, &devinfo, scb);
1764 ahc_freeze_devq(ahc, scb);
1772 ahc_handle_devreset(ahc, &devinfo,
1774 "Selection Timeout",
1779 }
else if ((status &
BUSFREE) != 0
1786 u_int initiator_role_id;
1815 saved_scsiid =
ahc_inb(ahc, SAVED_SCSIID);
1816 saved_lun =
ahc_inb(ahc, SAVED_LUN);
1832 tag = scb->
hscb->tag;
1834 printk(
"SCB %d - Abort%s Completed.\n",
1837 ahc_abort_scbs(ahc, target, channel,
1851 && scb->
io_ctx->ccb_h.func_code== XPT_RESET_DEV
1865 ahc_handle_devreset(ahc, &devinfo,
1884 tinfo->
curr.transport_version = 2;
1885 tinfo->
goal.transport_version = 2;
1886 tinfo->
goal.ppr_options = 0;
1917 if (printerror != 0) {
1924 tag = scb->
hscb->tag;
1928 ahc_abort_scbs(ahc, target, channel,
1937 printk(
"%s: ", ahc_name(ahc));
1939 for (i = 0; i < num_phases; i++) {
1940 if (lastphase == ahc_phase_table[i].
phase)
1950 ahc_force_renegotiation(ahc, &devinfo);
1952 printk(
"Unexpected busfree %s\n"
1953 "SEQADDR == 0x%x\n",
1954 ahc_phase_table[i].phasemsg,
1961 printk(
"%s: Missing case in ahc_handle_scsiint. status = %x\n",
1962 ahc_name(ahc), status);
1986 #define AHC_MAX_STEPS 2000
1988 ahc_clear_critical_section(
struct ahc_softc *ahc)
2020 if (cs->begin < seqaddr && cs->end >= seqaddr)
2028 printk(
"%s: Infinite loop in critical section\n",
2031 panic(
"critical section loop");
2035 if (stepping ==
FALSE) {
2081 ahc_clear_intstat(
struct ahc_softc *ahc)
2087 ahc_flush_device_writes(ahc);
2089 ahc_flush_device_writes(ahc);
2091 ahc_flush_device_writes(ahc);
2096 uint32_t ahc_debug = AHC_DEBUG_OPTS;
2101 ahc_print_scb(
struct scb *scb)
2107 printk(
"scb:%p control:0x%x scsiid:0x%x lun:%d cdb_len:%d\n",
2116 printk(
" dataptr:%#x datacnt:%#x sgptr:%#x tag:%#x\n",
2122 for (i = 0; i < scb->
sg_count; i++) {
2123 printk(
"sg[%d] - Addr 0x%x%x : Length %d\n",
2126 & SG_HIGH_ADDR_BITS),
2147 if (channel ==
'B') {
2153 panic(
"%s: ahc_alloc_tstate - Target already allocated",
2165 if (master_tstate !=
NULL) {
2166 memcpy(tstate, master_tstate,
sizeof(*tstate));
2176 memset(tstate, 0,
sizeof(*tstate));
2181 #ifdef AHC_TARGET_MODE
2195 if (((channel ==
'B' && scsi_id == ahc->
our_id_b)
2196 || (channel ==
'A' && scsi_id == ahc->
our_id))
2216 ahc_devlimited_syncrate(
struct ahc_softc *ahc,
2248 transinfo = &tinfo->
user;
2250 transinfo = &tinfo->
goal;
2256 if (transinfo->
period == 0) {
2293 for (syncrate = &ahc_syncrates[maxsync];
2305 if (*period <= syncrate->period) {
2317 if (syncrate == &ahc_syncrates[maxsync])
2318 *period = syncrate->
period;
2325 *ppr_options &= ~MSG_EXT_PPR_DT_REQ;
2333 && (syncrate->
sxfr_u2 == 0))) {
2337 *ppr_options &= ~MSG_EXT_PPR_DT_REQ;
2367 syncrate = &ahc_syncrates[maxsync];
2374 return (syncrate->
period);
2375 }
else if (scsirate == (syncrate->
sxfr &
SXFR)) {
2376 return (syncrate->
period);
2388 ahc_validate_offset(
struct ahc_softc *ahc,
2396 if (syncrate ==
NULL) {
2406 *offset =
min(*offset, maxoffset);
2407 if (tinfo !=
NULL) {
2423 switch (*bus_width) {
2435 if (tinfo !=
NULL) {
2437 *bus_width =
min((
u_int)tinfo->
user.width, *bus_width);
2439 *bus_width =
min((
u_int)tinfo->
goal.width, *bus_width);
2454 u_int auto_negotiate_orig;
2469 if (tinfo->
curr.period != tinfo->
goal.period
2470 || tinfo->
curr.width != tinfo->
goal.width
2471 || tinfo->
curr.offset != tinfo->
goal.offset
2472 || tinfo->
curr.ppr_options != tinfo->
goal.ppr_options
2474 && (tinfo->
goal.offset != 0
2476 || tinfo->
goal.ppr_options != 0)))
2508 if (syncrate ==
NULL) {
2514 devinfo->
target, &tstate);
2519 tinfo->
user.ppr_options = ppr_options;
2525 tinfo->
goal.ppr_options = ppr_options;
2528 old_period = tinfo->
curr.period;
2529 old_offset = tinfo->
curr.offset;
2530 old_ppr = tinfo->
curr.ppr_options;
2533 && (old_period != period
2534 || old_offset != offset
2535 || old_ppr != ppr_options)) {
2542 scsirate &= ~(
SXFR_ULTRA2|SINGLE_EDGE|ENABLE_CRC);
2543 if (syncrate !=
NULL) {
2544 scsirate |= syncrate->
sxfr_u2;
2546 scsirate |= ENABLE_CRC;
2548 scsirate |= SINGLE_EDGE;
2558 if (syncrate !=
NULL) {
2564 scsirate |= offset &
SOFS;
2585 tinfo->
curr.ppr_options = ppr_options;
2591 printk(
"%s: target %d synchronous at %sMHz%s, "
2592 "offset = 0x%x\n", ahc_name(ahc),
2595 ?
" DT" :
"", offset);
2597 printk(
"%s: target %d using "
2598 "asynchronous transfers\n",
2599 ahc_name(ahc), devinfo->
target);
2608 ahc_update_pending_scbs(ahc);
2632 devinfo->
target, &tstate);
2640 oldwidth = tinfo->
curr.width;
2660 printk(
"%s: target %d using %dbit transfers\n",
2661 ahc_name(ahc), devinfo->
target,
2662 8 * (0x01 << width));
2669 ahc_update_pending_scbs(ahc);
2692 ahc_update_pending_scbs(
struct ahc_softc *ahc)
2694 struct scb *pending_scb;
2695 int pending_scb_count;
2704 pending_scb_count = 0;
2711 ahc_scb_devinfo(ahc, &devinfo, pending_scb);
2714 devinfo.target, &tstate);
2715 pending_hscb = pending_scb->
hscb;
2716 pending_hscb->
control &= ~ULTRAENB;
2717 if ((tstate->
ultraenb & devinfo.target_mask) != 0)
2718 pending_hscb->
control |= ULTRAENB;
2726 ahc_sync_scb(ahc, pending_scb,
2728 pending_scb_count++;
2731 if (pending_scb_count == 0)
2743 for (i = 0; i < ahc->
scb_data->maxhscbs; i++) {
2751 if (pending_scb ==
NULL)
2754 pending_hscb = pending_scb->
hscb;
2784 & (CMDPHASE_PENDING|TARG_CMD_PENDING|NO_DISCONNECT)) != 0) {
2792 saved_scsiid =
ahc_inb(ahc, SAVED_SCSIID);
2802 ahc_lookup_phase_entry(
int phase)
2811 last_entry = &ahc_phase_table[num_phases];
2812 for (entry = ahc_phase_table; entry < last_entry; entry++) {
2813 if (phase == entry->
phase)
2909 printk(
"Bus Device Reset Message Sent\n");
2925 printk(
"Abort%s Message Sent\n",
2926 (scb->
hscb->control &
TAG_ENB) != 0 ?
" Tag" :
"");
2936 ahc_build_transfer_msg(ahc, devinfo);
2938 printk(
"ahc_intr: AWAITING_MSG for an SCB that "
2939 "does not have a waiting message\n");
2940 printk(
"SCSIID = %x, target_mask = %x\n", scb->
hscb->scsiid,
2942 panic(
"SCB = %d, SCB Control = %x, MSG_OUT = %x "
2943 "SCB flags = %x", scb->
hscb->tag, scb->
hscb->control,
2980 devinfo->
target, &tstate);
2987 period = tinfo->
goal.period;
2988 offset = tinfo->
goal.offset;
2989 ppr_options = tinfo->
goal.ppr_options;
2993 rate = ahc_devlimited_syncrate(ahc, tinfo, &period,
2994 &ppr_options, devinfo->
role);
2995 dowide = tinfo->
curr.width != tinfo->
goal.width;
2996 dosync = tinfo->
curr.offset != offset || tinfo->
curr.period !=
period;
3002 doppr = ppr_options != 0;
3004 if (!dowide && !dosync && !doppr) {
3006 dosync = tinfo->
goal.offset != 0;
3009 if (!dowide && !dosync && !doppr) {
3021 printk(
"Ensuring async\n");
3037 if (doppr || (dosync && !dowide)) {
3039 offset = tinfo->
goal.offset;
3040 ahc_validate_offset(ahc, tinfo, rate, &offset,
3041 doppr ? tinfo->
goal.width
3042 : tinfo->
curr.width,
3045 ahc_construct_ppr(ahc, devinfo, period, offset,
3046 tinfo->
goal.width, ppr_options);
3048 ahc_construct_sdtr(ahc, devinfo, period, offset);
3051 ahc_construct_wdtr(ahc, devinfo, tinfo->
goal.width);
3069 printk(
"(%s:%c:%d:%d): Sending SDTR period %x, offset %x\n",
3071 devinfo->
lun, period, offset);
3087 printk(
"(%s:%c:%d:%d): Sending WDTR %x\n",
3089 devinfo->
lun, bus_width);
3106 bus_width, ppr_options);
3109 printk(
"(%s:%c:%d:%d): Sending PPR bus_width %x, period %x, "
3110 "offset %x, ppr_options %x\n", ahc_name(ahc),
3112 bus_width, period, offset, ppr_options);
3120 ahc_clear_msg_state(
struct ahc_softc *ahc)
3134 ahc_inb(ahc, SEQ_FLAGS2) & ~TARGET_MSG_PENDING);
3138 ahc_handle_proto_violation(
struct ahc_softc *ahc)
3148 ahc_fetch_devinfo(ahc, &devinfo);
3154 if ((seq_flags & NOT_IDENTIFIED) != 0) {
3162 printk(
"Target did not send an IDENTIFY message. "
3163 "LASTPHASE = 0x%x.\n", lastphase);
3165 }
else if (scb ==
NULL) {
3171 printk(
"No SCB found during protocol violation\n");
3172 goto proto_violation_reset;
3175 if ((seq_flags & NO_CDB_SENT) != 0) {
3177 printk(
"No or incomplete CDB sent to device.\n");
3187 printk(
"Completed command without status.\n");
3190 printk(
"Unknown protocol violation.\n");
3194 if ((lastphase & ~P_DATAIN_DT) == 0
3196 proto_violation_reset:
3204 printk(
"%s: Issued Channel %c Bus Reset. "
3205 "%d SCBs aborted\n", ahc_name(ahc),
'A', found);
3214 ahc_assert_atn(ahc);
3226 printk(
"Protocol violation %s. Attempting to abort.\n",
3227 ahc_lookup_phase_entry(curphase)->phasemsg);
3235 ahc_handle_message_phase(
struct ahc_softc *ahc)
3241 ahc_fetch_devinfo(ahc, &devinfo);
3242 end_session =
FALSE;
3254 panic(
"HOST_MSG_LOOP interrupt with no active message");
3257 if ((ahc_debug & AHC_SHOW_MESSAGES) != 0) {
3259 printk(
"INITIATOR_MSG_OUT");
3265 if ((ahc_debug & AHC_SHOW_MESSAGES) != 0) {
3267 ahc_lookup_phase_entry(bus_phase)
3292 if ((ahc_debug & AHC_SHOW_MESSAGES) != 0)
3307 ahc_assert_atn(ahc);
3322 if ((ahc_debug & AHC_SHOW_MESSAGES) != 0)
3335 if ((ahc_debug & AHC_SHOW_MESSAGES) != 0) {
3337 printk(
"INITIATOR_MSG_IN");
3343 if ((ahc_debug & AHC_SHOW_MESSAGES) != 0) {
3345 ahc_lookup_phase_entry(bus_phase)
3364 if ((ahc_debug & AHC_SHOW_MESSAGES) != 0)
3369 message_done = ahc_parse_msg(ahc, &devinfo);
3385 if ((ahc_debug & AHC_SHOW_MESSAGES) != 0) {
3387 printk(
"Asserting ATN for response\n");
3390 ahc_assert_atn(ahc);
3410 panic(
"Target MSGIN with no active message");
3420 msgout_request =
TRUE;
3422 msgout_request =
FALSE;
3424 if (msgout_request) {
3475 msgdone = ahc_parse_msg(ahc, &devinfo);
3520 panic(
"Unknown REQINIT message type");
3524 ahc_clear_msg_state(ahc);
3545 while (index < ahc->msgout_len) {
3549 end_index = index + 1 + ahc->
msgout_buf[index + 1];
3591 u_int targ_scsirate;
3597 devinfo->
target, &tstate);
3624 response = ahc_handle_msg_reject(ahc, devinfo);
3660 saved_offset = offset = ahc->
msgin_buf[4];
3661 syncrate = ahc_devlimited_syncrate(ahc, tinfo, &period,
3664 ahc_validate_offset(ahc, tinfo, syncrate, &offset,
3668 printk(
"(%s:%c:%d:%d): Received "
3669 "SDTR period %x, offset %x\n\t"
3670 "Filtered to period %x, offset %x\n",
3671 ahc_name(ahc), devinfo->
channel,
3678 offset, ppr_options,
3689 if (saved_offset != offset) {
3699 printk(
"(%s:%c:%d:%d): Target "
3701 ahc_name(ahc), devinfo->
channel,
3706 ahc_construct_sdtr(ahc, devinfo,
3718 u_int sending_reply;
3720 sending_reply =
FALSE;
3738 ahc_validate_width(ahc, tinfo, &bus_width,
3741 printk(
"(%s:%c:%d:%d): Received WDTR "
3742 "%x filtered to %x\n",
3743 ahc_name(ahc), devinfo->
channel,
3745 saved_width, bus_width);
3755 if (saved_width > bus_width) {
3757 printk(
"(%s:%c:%d:%d): requested %dBit "
3758 "transfers. Rejecting...\n",
3759 ahc_name(ahc), devinfo->
channel,
3761 8 * (0x01 << bus_width));
3770 printk(
"(%s:%c:%d:%d): Target "
3772 ahc_name(ahc), devinfo->
channel,
3777 ahc_construct_wdtr(ahc, devinfo, bus_width);
3780 sending_reply =
TRUE;
3796 if (sending_reply ==
FALSE && reject ==
FALSE) {
3803 ahc_build_transfer_msg(ahc, devinfo);
3819 u_int saved_ppr_options;
3849 saved_ppr_options = ppr_options;
3861 ahc_validate_width(ahc, tinfo, &bus_width,
3863 syncrate = ahc_devlimited_syncrate(ahc, tinfo, &period,
3866 ahc_validate_offset(ahc, tinfo, syncrate,
3876 if (saved_width > bus_width
3877 || saved_offset != offset
3878 || saved_ppr_options != ppr_options) {
3888 printk(
"(%s:%c:%d:%d): Target "
3890 ahc_name(ahc), devinfo->
channel,
3893 printk(
"(%s:%c:%d:%d): Initiator "
3895 ahc_name(ahc), devinfo->
channel,
3899 ahc_construct_ppr(ahc, devinfo, period, offset,
3900 bus_width, ppr_options);
3905 printk(
"(%s:%c:%d:%d): Received PPR width %x, "
3906 "period %x, offset %x,options %x\n"
3907 "\tFiltered to width %x, period %x, "
3908 "offset %x, options %x\n",
3909 ahc_name(ahc), devinfo->
channel,
3912 saved_offset, saved_ppr_options,
3913 bus_width, period, offset, ppr_options);
3920 offset, ppr_options,
3933 #ifdef AHC_TARGET_MODE
3935 ahc_handle_devreset(ahc, devinfo,
3937 "Bus Device Reset Received",
3955 tag =
ahc_inb(ahc, INITIATOR_TAG);
3961 if (tstate !=
NULL) {
3962 struct ahc_tmode_lstate* lstate;
3965 if (lstate !=
NULL) {
3966 ahc_queue_lstate_event(ahc, lstate,
3970 ahc_send_lstate_events(ahc, lstate);
4025 devinfo->
target, &tstate);
4035 printk(
"(%s:%c:%d:%d): PPR Rejected. "
4036 "Trying WDTR/SDTR\n",
4037 ahc_name(ahc), devinfo->
channel,
4040 tinfo->
goal.ppr_options = 0;
4041 tinfo->
curr.transport_version = 2;
4042 tinfo->
goal.transport_version = 2;
4045 ahc_build_transfer_msg(ahc, devinfo);
4051 printk(
"(%s:%c:%d:%d): refuses WIDE negotiation. Using "
4052 "8bit transfers\n", ahc_name(ahc),
4064 if (tinfo->
goal.offset != tinfo->
curr.offset) {
4069 ahc_build_transfer_msg(ahc, devinfo);
4079 printk(
"(%s:%c:%d:%d): refuses synchronous negotiation. "
4080 "Using asynchronous transfers\n",
4081 ahc_name(ahc), devinfo->
channel,
4090 printk(
"(%s:%c:%d:%d): refuses tagged commands. "
4091 "Performing non-tagged I/O\n", ahc_name(ahc),
4096 printk(
"(%s:%c:%d:%d): refuses %s tagged commands. "
4097 "Performing simple queue tagged I/O only\n",
4100 ?
"ordered" :
"head of queue");
4112 ahc_set_transaction_tag(scb,
FALSE,
4115 ahc_assert_atn(ahc);
4122 struct scb_tailq *untagged_q;
4146 printk(
"%s:%c:%d: Message reject for %x -- ignored\n",
4169 || ahc_get_transfer_dir(scb) !=
CAM_DIR_IN) {
4184 sgptr =
ahc_inb(ahc, SCB_RESIDUAL_SGPTR);
4185 if ((sgptr & SG_LIST_NULL) != 0
4200 sgptr =
ahc_inl(ahc, SCB_RESIDUAL_SGPTR);
4201 data_cnt =
ahc_inl(ahc, SCB_RESIDUAL_DATACNT);
4203 if ((sgptr & SG_LIST_NULL) != 0) {
4218 sg = ahc_sg_bus_to_virt(scb, sgptr);
4235 data_cnt = 1 | (sglen & (~AHC_SG_LEN_MASK));
4244 sgptr = ahc_sg_virt_to_bus(scb, sg);
4246 ahc_outl(ahc, SCB_RESIDUAL_SGPTR, sgptr);
4247 ahc_outl(ahc, SCB_RESIDUAL_DATACNT, data_cnt);
4266 ahc_reinitialize_dataptrs(
struct ahc_softc *ahc)
4277 sgptr = (
ahc_inb(ahc, SCB_RESIDUAL_SGPTR + 3) << 24)
4278 | (
ahc_inb(ahc, SCB_RESIDUAL_SGPTR + 2) << 16)
4279 | (
ahc_inb(ahc, SCB_RESIDUAL_SGPTR + 1) << 8)
4280 |
ahc_inb(ahc, SCB_RESIDUAL_SGPTR);
4283 sg = ahc_sg_bus_to_virt(scb, sgptr);
4288 resid = (
ahc_inb(ahc, SCB_RESIDUAL_DATACNT + 2) << 16)
4289 | (
ahc_inb(ahc, SCB_RESIDUAL_DATACNT + 1) << 8)
4290 |
ahc_inb(ahc, SCB_RESIDUAL_DATACNT);
4298 dscommand1 =
ahc_inb(ahc, DSCOMMAND1);
4299 ahc_outb(ahc, DSCOMMAND1, dscommand1 | HADDLDSEL0);
4302 ahc_outb(ahc, DSCOMMAND1, dscommand1);
4325 #ifdef AHC_TARGET_MODE
4331 found = ahc_abort_scbs(ahc, devinfo->
target, devinfo->
channel,
4335 #ifdef AHC_TARGET_MODE
4341 if (tstate !=
NULL) {
4343 struct ahc_tmode_lstate* lstate;
4349 ahc_queue_lstate_event(ahc, lstate, devinfo->
our_scsiid,
4351 ahc_send_lstate_events(ahc, lstate);
4371 printk(
"%s: %s on %c:%d. %d SCBs aborted\n", ahc_name(ahc),
4375 #ifdef AHC_TARGET_MODE
4390 ahc_build_transfer_msg(ahc, devinfo);
4392 panic(
"ahc_intr: AWAITING target message with no message");
4412 printk(
"aic7xxx: cannot malloc softc!\n");
4417 ahc = device_get_softc((
device_t)platform_arg);
4419 memset(ahc, 0,
sizeof(*ahc));
4525 ahc_fini_scbdata(ahc);
4530 if (tstate !=
NULL) {
4531 #ifdef AHC_TARGET_MODE
4535 struct ahc_tmode_lstate *lstate;
4538 if (lstate !=
NULL) {
4539 xpt_free_path(lstate->path);
4547 #ifdef AHC_TARGET_MODE
4564 ahc_shutdown(
void *
arg)
4594 u_int sxfrctl1_a, sxfrctl1_b;
4633 printk(
"%s: WARNING - Failed chip reset! "
4634 "Trying to initialize anyway.\n", ahc_name(ahc));
4642 sblkctl &= ~SELBUSB;
4656 printk(
" Unsupported adapter type. Ignoring\n");
4723 ahc_build_free_scb_list(
struct ahc_softc *ahc)
4732 for (i = 0; i < ahc->
scb_data->maxhscbs; i++) {
4742 for (j = 0; j < scbsize; j++)
4791 if (ahc->
scb_data->maxhscbs == 0) {
4792 printk(
"%s: No SCB space found\n", ahc_name(ahc));
4823 (
void **)&scb_data->
hscbs,
4855 (
void **)&scb_data->
sense,
4878 0, &scb_data->
sg_dmat) != 0) {
4887 ahc_alloc_scbs(ahc);
4890 printk(
"%s: ahc_init_scbdata - "
4891 "Unable to allocate initial scbs\n",
4914 struct scb_data *scb_data;
4917 if (scb_data ==
NULL)
4968 struct scb_data *scb_data;
5007 for (i = 0; i < newcount; i++) {
5016 next_scb->
sg_map = sg_map;
5026 error = ahc_dmamap_create(ahc, ahc->
buffer_dmat, 0,
5034 next_scb, links.sle);
5050 len =
sprintf(buf,
"Twin Channel, A SCSI Id=%d, "
5051 "B SCSI Id=%d, primary %c, ",
5062 speed =
"Ultra160 ";
5071 len =
sprintf(buf,
"%s%s Channel %c, SCSI Id=%d, ",
5090 u_int scsiseq_template;
5105 scsi_conf =
ahc_inb(ahc, SCSICONF + 1);
5121 scsi_conf =
ahc_inb(ahc, SCSICONF);
5131 for (i = 0; i < 16; i++) {
5132 ahc_unbusy_tcl(ahc,
BUILD_TCL(i << 4, 0));
5141 ahc_unbusy_tcl(ahc,
BUILD_TCL(i << 4, lun));
5146 for (i = 0; i < 256; i++)
5150 for (i = 0; i < 256; i++)
5161 physaddr = ahc->
scb_data->hscb_busaddr;
5168 ahc_outb(ahc, SHARED_DATA_ADDR, physaddr & 0xFF);
5169 ahc_outb(ahc, SHARED_DATA_ADDR + 1, (physaddr >> 8) & 0xFF);
5170 ahc_outb(ahc, SHARED_DATA_ADDR + 2, (physaddr >> 16) & 0xFF);
5171 ahc_outb(ahc, SHARED_DATA_ADDR + 3, (physaddr >> 24) & 0xFF);
5179 ahc_outb(ahc, CMDSIZE_TABLE + 1, 9);
5180 ahc_outb(ahc, CMDSIZE_TABLE + 2, 9);
5181 ahc_outb(ahc, CMDSIZE_TABLE + 3, 0);
5182 ahc_outb(ahc, CMDSIZE_TABLE + 4, 15);
5183 ahc_outb(ahc, CMDSIZE_TABLE + 5, 11);
5184 ahc_outb(ahc, CMDSIZE_TABLE + 6, 0);
5185 ahc_outb(ahc, CMDSIZE_TABLE + 7, 0);
5226 ahc_outb(ahc, SCSISEQ_TEMPLATE, scsiseq_template);
5229 ahc_build_free_scb_list(ahc);
5241 printk(
"%s: Downloading Sequencer Program...",
5244 error = ahc_loadseq(ahc);
5279 size_t driver_data_size;
5282 if ((ahc_debug & AHC_DEBUG_SEQUENCER) != 0)
5286 #ifdef AHC_PRINT_SRAM
5288 for (i = 0x20; i < 0x5f; i++) {
5289 if (((i % 8) == 0) && (i != 0)) {
5295 for (i = 0x70; i < 0x7f; i++) {
5296 if (((i % 8) == 0) && (i != 0)) {
5358 driver_data_size = 2 * 256 *
sizeof(
uint8_t);
5363 BUS_SPACE_MAXADDR_32BIT + 1,
5364 BUS_SPACE_MAXADDR_32BIT,
5387 ahc->
qoutfifo, driver_data_size, ahc_dmamap_cb,
5394 + driver_data_size - 1;
5407 if (ahc_init_scbdata(ahc) != 0)
5415 if (ahc_alloc_tstate(ahc, ahc->
our_id,
'A') ==
NULL) {
5416 printk(
"%s: unable to allocate ahc_tmode_tstate. "
5417 "Failing attach\n", ahc_name(ahc));
5422 if (ahc_alloc_tstate(ahc, ahc->
our_id_b,
'B') ==
NULL) {
5423 printk(
"%s: unable to allocate ahc_tmode_tstate. "
5424 "Failing attach\n", ahc_name(ahc));
5436 if (ahc_debug & AHC_SHOW_MISC) {
5437 printk(
"%s: hardware scb %u bytes; kernel scb %u bytes; "
5438 "ahc_dma %u bytes\n",
5441 (
u_int)
sizeof(
struct scb),
5451 scsi_conf =
ahc_inb(ahc, SCSICONF + 1);
5457 scsi_conf =
ahc_inb(ahc, SCSICONF);
5467 printk(
"%s: Host Adapter Bios disabled. Using default SCSI "
5468 "device parameters\n", ahc_name(ahc));
5485 for (i = 0; i <= max_targ; i++) {
5501 target_id, &tstate);
5503 memset(tinfo, 0,
sizeof(*tinfo));
5525 if ((scsirate &
SOFS) == 0x0F) {
5530 scsirate = (scsirate &
SXFR) >> 4
5537 if ((scsirate & ~
WIDEXFER) == 0 && offset != 0)
5543 tinfo->
user.period =
5546 tinfo->
user.period = 0;
5551 tinfo->
user.ppr_options =
5553 }
else if ((scsirate &
SOFS) != 0) {
5554 if ((scsirate &
SXFR) == 0x40
5555 && (ultraenb & mask) != 0) {
5560 tinfo->
user.period =
5565 if (tinfo->
user.period != 0)
5568 if (tinfo->
user.period == 0)
5569 tinfo->
user.offset = 0;
5573 tinfo->
user.protocol_version = 4;
5575 tinfo->
user.transport_version = 3;
5577 tinfo->
user.transport_version = 2;
5578 tinfo->
goal.protocol_version = 2;
5579 tinfo->
goal.transport_version = 2;
5580 tinfo->
curr.protocol_version = 2;
5581 tinfo->
curr.transport_version = 2;
5640 ahc_clear_critical_section(ahc);
5647 if (maxloops == 0) {
5648 printk(
"Infinite interrupt loop, INTSTAT = %x",
5667 #ifdef AHC_TARGET_MODE
5701 u_int target_offset;
5712 scbid =
ahc_inb(ahc, BUSY_TARGETS + target_offset);
5721 u_int target_offset;
5739 u_int target_offset;
5750 ahc_outb(ahc, BUSY_TARGETS + target_offset, scbid);
5770 #ifdef AHC_TARGET_MODE
5773 group = XPT_FC_GROUP(scb->
io_ctx->ccb_h.func_code);
5775 match = (group != XPT_FC_GROUP_TMODE)
5776 && ((tag == scb->
hscb->tag)
5779 match = (group == XPT_FC_GROUP_TMODE)
5780 && ((tag == scb->
io_ctx->csio.tag_id)
5792 ahc_freeze_devq(
struct ahc_softc *ahc,
struct scb *scb)
5812 struct scb *prev_scb;
5815 if (ahc_qinfifo_count(ahc) != 0) {
5820 prev_tag = ahc->
qinfifo[prev_pos];
5823 ahc_qinfifo_requeue(ahc, prev_scb, scb);
5832 ahc_qinfifo_requeue(
struct ahc_softc *ahc,
struct scb *prev_scb,
5835 if (prev_scb ==
NULL) {
5838 prev_scb->
hscb->next = scb->
hscb->tag;
5839 ahc_sync_scb(ahc, prev_scb,
5848 ahc_qinfifo_count(
struct ahc_softc *ahc)
5868 struct scb *prev_scb;
5894 ahc_freeze_untagged_queues(ahc);
5904 while (qinpos != qintail) {
5907 printk(
"qinpos = %d, SCB index = %d\n",
5908 qinpos, ahc->
qinfifo[qinpos]);
5912 if (
ahc_match_scb(ahc, scb, target, channel, lun, tag, role)) {
5923 ostat = ahc_get_transaction_status(scb);
5925 ahc_set_transaction_status(scb, status);
5926 cstat = ahc_get_transaction_status(scb);
5928 ahc_freeze_scb(scb);
5930 printk(
"Inactive SCB in qinfifo\n");
5938 ahc_qinfifo_requeue(ahc, prev_scb, scb);
5943 ahc_qinfifo_requeue(ahc, prev_scb, scb);
5973 printk(
"found = %d, qinstart = %d, qinfifionext = %d\n",
5975 panic(
"First/Second Qinfifo fixup\n");
5983 next = scb->
hscb->next;
5985 ahc_swap_with_next_hscb(ahc, scb);
6010 if (scb_index >= ahc->
scb_data->numscbs) {
6011 printk(
"Waiting List inconsistency. "
6012 "SCB index == %d, yet numscbs == %d.",
6013 scb_index, ahc->
scb_data->numscbs);
6015 panic(
"for safety");
6019 printk(
"scb_index = %d, next = %d\n",
6021 panic(
"Waiting List traversal\n");
6035 ostat = ahc_get_transaction_status(scb);
6037 ahc_set_transaction_status(scb,
6039 cstat = ahc_get_transaction_status(scb);
6041 ahc_freeze_scb(scb);
6043 printk(
"Inactive SCB in Waiting List\n");
6048 next = ahc_rem_wscb(ahc, next, prev);
6064 channel, lun, status, action);
6067 ahc_release_untagged_queues(ahc);
6073 int target,
char channel,
int lun,
uint32_t status,
6086 ahc_freeze_untagged_queues(ahc);
6105 for (; i < maxtarget; i++) {
6106 struct scb_tailq *untagged_q;
6111 while (next_scb !=
NULL) {
6143 ostat = ahc_get_transaction_status(scb);
6145 ahc_set_transaction_status(scb, status);
6146 cstat = ahc_get_transaction_status(scb);
6148 ahc_freeze_scb(scb);
6150 printk(
"Inactive SCB in untaggedQ\n");
6165 ahc_release_untagged_queues(ahc);
6171 int lun,
u_int tag,
int stop_on_first,
int remove,
6196 if (scb_index >= ahc->
scb_data->numscbs) {
6197 printk(
"Disconnected List inconsistency. "
6198 "SCB index == %d, yet numscbs == %d.",
6199 scb_index, ahc->
scb_data->numscbs);
6201 panic(
"for safety");
6205 panic(
"Disconnected List Loop. "
6206 "cur SCBPTR == %x, prev SCBPTR == %x.",
6215 ahc_rem_scb_from_disc_list(ahc, prev, next);
6246 ahc_add_curscb_to_free_list(ahc);
6263 ahc_add_curscb_to_free_list(
struct ahc_softc *ahc)
6297 ahc_add_curscb_to_free_list(ahc);
6333 ahc_abort_scbs(
struct ahc_softc *ahc,
int target,
char channel,
6337 struct scb *scbp_next;
6350 ahc_freeze_untagged_queues(ahc);
6388 for (;i < maxtarget; i++) {
6389 for (j = minlun;j < maxlun; j++) {
6394 scbid = ahc_index_busy_tcl(ahc, tcl);
6398 lun, tag, role) == 0)
6400 ahc_unbusy_tcl(ahc,
BUILD_TCL(i << 4, j));
6422 for (i = 0; i < ahc->
scb_data->maxhscbs; i++) {
6430 &&
ahc_match_scb(ahc, scbp, target, channel, lun, tag, role)))
6431 ahc_add_curscb_to_free_list(ahc);
6441 while (scbp_next !=
NULL) {
6444 if (
ahc_match_scb(ahc, scbp, target, channel, lun, tag, role)) {
6447 ostat = ahc_get_transaction_status(scbp);
6449 ahc_set_transaction_status(scbp, status);
6450 if (ahc_get_transaction_status(scbp) !=
CAM_REQ_CMP)
6451 ahc_freeze_scb(scbp);
6453 printk(
"Inactive SCB on pending list\n");
6460 ahc_release_untagged_queues(ahc);
6465 ahc_reset_current_bus(
struct ahc_softc *ahc)
6472 ahc_flush_device_writes(ahc);
6477 ahc_clear_intstat(ahc);
6505 ahc_clear_critical_section(ahc);
6512 ahc_run_qoutfifo(ahc);
6513 #ifdef AHC_TARGET_MODE
6525 ahc_run_tqinfifo(ahc,
TRUE);
6535 && ((sblkctl & SELBUSB) != 0))
6537 scsiseq =
ahc_inb(ahc, SCSISEQ_TEMPLATE);
6538 if (cur_channel != channel) {
6545 #ifdef AHC_TARGET_MODE
6556 ahc_reset_current_bus(ahc);
6557 ahc_clear_intstat(ahc);
6560 restart_needed =
FALSE;
6564 #ifdef AHC_TARGET_MODE
6575 ahc_reset_current_bus(ahc);
6576 ahc_clear_intstat(ahc);
6578 restart_needed =
TRUE;
6591 #ifdef AHC_TARGET_MODE
6596 for (target = 0; target <= max_scsiid; target++) {
6604 struct ahc_tmode_lstate* lstate;
6612 ahc_send_lstate_events(ahc, lstate);
6623 for (target = 0; target <= max_scsiid; target++) {
6627 for (initiator = 0; initiator <= max_scsiid; initiator++) {
6655 ahc_calc_residual(
struct ahc_softc *ahc,
struct scb *scb)
6681 if ((sgptr & SG_RESID_VALID) == 0)
6684 sgptr &= ~SG_RESID_VALID;
6686 if ((sgptr & SG_LIST_NULL) != 0)
6692 if ((sgptr & SG_FULL_RESID) != 0) {
6694 resid = ahc_get_transfer_length(scb);
6695 }
else if ((resid_sgptr & SG_LIST_NULL) != 0) {
6699 panic(
"Bogus resid sgptr value 0x%x\n", resid_sgptr);
6708 sg = ahc_sg_bus_to_virt(scb, resid_sgptr &
SG_PTR_MASK);
6724 ahc_set_residual(scb, resid);
6726 ahc_set_sense_residual(scb, resid);
6729 if ((ahc_debug & AHC_SHOW_MISC) != 0) {
6731 printk(
"Handled %sResidual of %d bytes\n",
6738 #ifdef AHC_TARGET_MODE
6743 ahc_queue_lstate_event(
struct ahc_softc *ahc,
struct ahc_tmode_lstate *lstate,
6749 xpt_freeze_devq(lstate->path, 1);
6750 if (lstate->event_w_idx >= lstate->event_r_idx)
6751 pending = lstate->event_w_idx - lstate->event_r_idx;
6754 - (lstate->event_r_idx - lstate->event_w_idx);
6764 lstate->event_r_idx = 0;
6765 lstate->event_w_idx = 0;
6766 xpt_release_devq(lstate->path, pending,
FALSE);
6770 xpt_print_path(lstate->path);
6771 printk(
"immediate event %x:%x lost\n",
6772 lstate->event_buffer[lstate->event_r_idx].event_type,
6773 lstate->event_buffer[lstate->event_r_idx].event_arg);
6774 lstate->event_r_idx++;
6776 lstate->event_r_idx = 0;
6777 xpt_release_devq(lstate->path, 1,
FALSE);
6780 event = &lstate->event_buffer[lstate->event_w_idx];
6784 lstate->event_w_idx++;
6786 lstate->event_w_idx = 0;
6794 ahc_send_lstate_events(
struct ahc_softc *ahc,
struct ahc_tmode_lstate *lstate)
6796 struct ccb_hdr *ccbh;
6797 struct ccb_immed_notify *inot;
6799 while (lstate->event_r_idx != lstate->event_w_idx
6803 event = &lstate->event_buffer[lstate->event_r_idx];
6805 inot = (
struct ccb_immed_notify *)ccbh;
6812 inot->message_args[0] =
event->event_type;
6813 inot->message_args[1] =
event->event_arg;
6816 inot->initiator_id =
event->initiator_id;
6817 inot->sense_len = 0;
6818 xpt_done((
union ccb *)inot);
6819 lstate->event_r_idx++;
6821 lstate->event_r_idx = 0;
6841 printk(
"0x%08x\n", ins_bytes[0] << 24
6842 | ins_bytes[1] << 16
6852 struct cs cs_table[num_critical_sections];
6853 u_int begin_set[num_critical_sections];
6854 u_int end_set[num_critical_sections];
6855 const struct patch *cur_patch;
6860 u_int sg_prefetch_cnt;
6870 memset(begin_set, 0,
sizeof(begin_set));
6871 memset(end_set, 0,
sizeof(end_set));
6879 download_consts[INVERTED_CACHESIZE_MASK] = ~(ahc->
pci_cachesize - 1);
6881 if (sg_prefetch_cnt < (2 *
sizeof(
struct ahc_dma_seg)))
6883 download_consts[SG_PREFETCH_CNT] = sg_prefetch_cnt;
6884 download_consts[SG_PREFETCH_ALIGN_MASK] = ~(sg_prefetch_cnt - 1);
6885 download_consts[SG_PREFETCH_ADDR_MASK] = (sg_prefetch_cnt - 1);
6887 cur_patch = patches;
6894 for (i = 0; i <
sizeof(seqprog)/4; i++) {
6895 if (ahc_check_patch(ahc, &cur_patch, i, &skip_addr) == 0) {
6909 printk(
"\n%s: Program too large for instruction memory "
6910 "size of %d!\n", ahc_name(ahc),
6919 for (; cur_cs < num_critical_sections; cur_cs++) {
6920 if (critical_sections[cur_cs].
end <= i) {
6921 if (begin_set[cs_count] ==
TRUE
6922 && end_set[cs_count] ==
FALSE) {
6923 cs_table[cs_count].end = downloaded;
6924 end_set[cs_count] =
TRUE;
6929 if (critical_sections[cur_cs].begin <= i
6930 && begin_set[cs_count] ==
FALSE) {
6931 cs_table[cs_count].begin = downloaded;
6932 begin_set[cs_count] =
TRUE;
6936 ahc_download_instr(ahc, i, download_consts);
6941 if (cs_count != 0) {
6943 cs_count *=
sizeof(
struct cs);
6946 panic(
"ahc_loadseq: Could not malloc");
6952 printk(
" %d instructions downloaded\n", downloaded);
6953 printk(
"%s: Features 0x%x, Bugs 0x%x, Flags 0x%x\n",
6960 ahc_check_patch(
struct ahc_softc *ahc,
const struct patch **start_patch,
6963 const struct patch *cur_patch;
6964 const struct patch *last_patch;
6968 last_patch = &patches[num_patches];
6969 cur_patch = *start_patch;
6971 while (cur_patch < last_patch && start_instr == cur_patch->begin) {
6973 if (cur_patch->patch_func(ahc) == 0) {
6976 *skip_addr = start_instr + cur_patch->skip_instr;
6977 cur_patch += cur_patch->skip_patch;
6987 *start_patch = cur_patch;
6988 if (start_instr < *skip_addr)
7008 fmt1_ins = &
instr.format1;
7012 opcode =
instr.format1.opcode;
7023 const struct patch *cur_patch;
7029 fmt3_ins = &
instr.format3;
7032 cur_patch = patches;
7037 ahc_check_patch(ahc, &cur_patch, i, &skip_addr);
7039 if (skip_addr > i) {
7042 end_addr =
min(address, skip_addr);
7043 address_offset += end_addr -
i;
7049 address -= address_offset;
7059 if (fmt1_ins->
parity != 0) {
7073 panic(
"%s: BMOV not supported\n",
7084 for (i = 0, count = 0; i < 31; i++) {
7088 if ((
instr.integer & mask) != 0)
7091 if ((count & 0x01) == 0)
7092 instr.format1.parity = 1;
7095 if (fmt3_ins !=
NULL) {
7098 | (fmt3_ins->
source << 8)
7100 | (fmt3_ins->
opcode << 25);
7104 | (fmt1_ins->
source << 8)
7106 | (fmt1_ins->
ret << 24)
7107 | (fmt1_ins->
opcode << 25);
7115 panic(
"Unknown opcode encountered in seq program");
7128 if (cur_column !=
NULL && *cur_column >= wrap_point) {
7132 printed =
printk(
"%s[0x%x]", name, value);
7133 if (table ==
NULL) {
7135 *cur_column += printed;
7139 while (printed_mask != 0xFF) {
7143 if (((value & table[entry].mask)
7144 != table[entry].value)
7145 || ((printed_mask & table[entry].mask)
7146 == table[entry].mask))
7149 printed +=
printk(
"%s%s",
7150 printed_mask == 0 ?
":(" :
"|",
7152 printed_mask |= table[
entry].mask;
7156 if (entry >= num_entries)
7159 if (printed_mask != 0)
7163 if (cur_column !=
NULL)
7164 *cur_column += printed;
7172 struct scb_tailq *untagged_q;
7194 printk(
">>>>>>>>>>>>>>>>>> Dump Card State Begins <<<<<<<<<<<<<<<<<\n"
7195 "%s: Dumping Card State %s, at SEQADDR 0x%x\n",
7196 ahc_name(ahc), ahc_lookup_phase_entry(last_phase)->phasemsg,
7199 printk(
"Card was paused\n");
7200 printk(
"ACCUM = 0x%x, SINDEX = 0x%x, DINDEX = 0x%x, ARG_2 = 0x%x\n",
7233 printk(
"Card NEXTQSCB = %d\n",
ahc_inb(ahc, NEXT_QUEUED_SCB));
7235 printk(
"QINFIFO entries: ");
7242 while (qinpos != qintail) {
7248 printk(
"Waiting Queue entries: ");
7258 printk(
"Disconnected Queue entries: ");
7269 printk(
"QOUTFIFO entries: ");
7278 printk(
"Sequencer Free SCB List: ");
7283 printk(
"%d ", scb_index);
7288 printk(
"Sequencer SCB Info: ");
7289 for (i = 0; i < ahc->
scb_data->maxhscbs; i++) {
7291 cur_col =
printk(
"\n%3d ", i);
7294 ahc_scb_scsiid_print(
ahc_inb(ahc, SCB_SCSIID), &cur_col, 60);
7300 printk(
"Pending list: ");
7306 ahc_scb_control_print(scb->
hscb->control, &cur_col, 60);
7307 ahc_scb_scsiid_print(scb->
hscb->scsiid, &cur_col, 60);
7308 ahc_scb_lun_print(scb->
hscb->lun, &cur_col, 60);
7320 printk(
"Kernel Free SCB list: ");
7330 for (target = 0; target <= maxtarget; target++) {
7334 printk(
"Untagged Q(%d): ", target);
7345 printk(
"\n<<<<<<<<<<<<<<<<< Dump Card State Ends >>>>>>>>>>>>>>>>>>\n");
7352 #ifdef AHC_TARGET_MODE
7354 ahc_find_tmode_devs(
struct ahc_softc *ahc,
struct cam_sim *sim,
union ccb *
ccb,
7356 struct ahc_tmode_lstate **lstate,
7357 int notfound_failure)
7375 if (ccb->ccb_h.target_id >= max_id)
7376 return (CAM_TID_INVALID);
7378 if (ccb->ccb_h.target_lun >= AHC_NUM_LUNS)
7379 return (CAM_LUN_INVALID);
7383 if (*tstate !=
NULL)
7385 (*tstate)->enabled_luns[ccb->ccb_h.target_lun];
7388 if (notfound_failure != 0 && *lstate ==
NULL)
7395 ahc_handle_en_lun(
struct ahc_softc *ahc,
struct cam_sim *sim,
union ccb *ccb)
7398 struct ahc_tmode_lstate *lstate;
7399 struct ccb_en_lun *cel;
7409 status = ahc_find_tmode_devs(ahc, sim, ccb, &tstate, &lstate,
7413 ccb->ccb_h.status =
status;
7417 if (cam_sim_bus(sim) == 0)
7422 if (ccb->ccb_h.target_id != our_id) {
7453 status = CAM_TID_INVALID;
7463 status = CAM_TID_INVALID;
7468 status = CAM_TID_INVALID;
7473 ccb->ccb_h.status =
status;
7486 printk(
"Configuring Target Mode\n");
7490 ahc_unlock(ahc, &s);
7493 saved_flags = ahc->
flags;
7498 error = ahc_loadseq(ahc);
7508 ahc->
flags = saved_flags;
7509 (
void)ahc_loadseq(ahc);
7511 ahc_unlock(ahc, &s);
7512 ccb->ccb_h.status = CAM_FUNC_NOTAVAIL;
7516 ahc_unlock(ahc, &s);
7519 target = ccb->ccb_h.target_id;
7520 lun = ccb->ccb_h.target_lun;
7521 channel = SIM_CHANNEL(ahc, sim);
7522 target_mask = 0x01 <<
target;
7526 if (cel->enable != 0) {
7530 if (lstate !=
NULL) {
7531 xpt_print_path(ccb->ccb_h.path);
7532 printk(
"Lun already enabled\n");
7533 ccb->ccb_h.status = CAM_LUN_ALRDY_ENA;
7537 if (cel->grp6_len != 0
7538 || cel->grp7_len != 0) {
7544 printk(
"Non-zero Group Codes\n");
7553 tstate = ahc_alloc_tstate(ahc, target, channel);
7554 if (tstate ==
NULL) {
7555 xpt_print_path(ccb->ccb_h.path);
7556 printk(
"Couldn't allocate tstate\n");
7562 if (lstate ==
NULL) {
7563 xpt_print_path(ccb->ccb_h.path);
7564 printk(
"Couldn't allocate lstate\n");
7568 memset(lstate, 0,
sizeof(*lstate));
7569 status = xpt_create_path(&lstate->path,
NULL,
7570 xpt_path_path_id(ccb->ccb_h.path),
7571 xpt_path_target_id(ccb->ccb_h.path),
7572 xpt_path_lun_id(ccb->ccb_h.path));
7575 xpt_print_path(ccb->ccb_h.path);
7576 printk(
"Couldn't allocate path\n");
7591 targid_mask =
ahc_inb(ahc, TARGID)
7592 | (
ahc_inb(ahc, TARGID + 1) << 8);
7594 targid_mask |= target_mask;
7595 ahc_outb(ahc, TARGID, targid_mask);
7596 ahc_outb(ahc, TARGID+1, (targid_mask >> 8));
7598 ahc_update_scsiid(ahc, targid_mask);
7603 channel = SIM_CHANNEL(ahc, sim);
7604 our_id = SIM_SCSI_ID(ahc, sim);
7610 if (target != our_id) {
7616 cur_channel = (sblkctl &
SELBUSB)
7620 swap = cur_channel !=
channel;
7640 scsiseq =
ahc_inb(ahc, SCSISEQ_TEMPLATE);
7642 ahc_outb(ahc, SCSISEQ_TEMPLATE, scsiseq);
7648 ahc_unlock(ahc, &s);
7650 xpt_print_path(ccb->ccb_h.path);
7651 printk(
"Lun now enabled for target mode\n");
7656 if (lstate ==
NULL) {
7657 ccb->ccb_h.status = CAM_LUN_INVALID;
7665 struct ccb_hdr *ccbh;
7667 ccbh = &scb->
io_ctx->ccb_h;
7668 if (ccbh->func_code == XPT_CONT_TARGET_IO
7669 && !xpt_path_comp(ccbh->path, ccb->ccb_h.path)){
7670 printk(
"CTIO pending\n");
7672 ahc_unlock(ahc, &s);
7678 printk(
"ATIOs pending\n");
7683 printk(
"INOTs pending\n");
7688 ahc_unlock(ahc, &s);
7692 xpt_print_path(ccb->ccb_h.path);
7693 printk(
"Target mode disabled\n");
7694 xpt_free_path(lstate->path);
7702 for (empty = 1, i = 0; i < 8; i++)
7709 ahc_free_tstate(ahc, target, channel,
7714 targid_mask =
ahc_inb(ahc, TARGID)
7718 targid_mask &= ~target_mask;
7719 ahc_outb(ahc, TARGID, targid_mask);
7721 (targid_mask >> 8));
7722 ahc_update_scsiid(ahc, targid_mask);
7739 scsiseq =
ahc_inb(ahc, SCSISEQ_TEMPLATE);
7741 ahc_outb(ahc, SCSISEQ_TEMPLATE, scsiseq);
7747 printk(
"Configuring Initiator Mode\n");
7754 (
void)ahc_loadseq(ahc);
7763 ahc_unlock(ahc, &s);
7774 panic(
"ahc_update_scsiid called on non-multitid unit\n");
7786 scsiid_mask = 0x1 << (scsiid &
OID);
7787 if ((targid_mask & scsiid_mask) == 0) {
7791 our_id =
ffs(targid_mask);
7806 ahc_run_tqinfifo(
struct ahc_softc *ahc,
int paused)
7825 if (ahc_handle_target_cmd(ahc, cmd) != 0)
7844 hs_mailbox =
ahc_inb(ahc, HS_MAILBOX);
7845 hs_mailbox &= ~HOST_TQINPOS;
7847 ahc_outb(ahc, HS_MAILBOX, hs_mailbox);
7864 struct ahc_tmode_lstate *lstate;
7865 struct ccb_accept_tio *
atio;
7887 atio = (
struct ccb_accept_tio*)
SLIST_FIRST(&lstate->accept_tios);
7894 printk(
"%s: ATIOs exhausted\n", ahc_name(ahc));
7899 printk(
"Incoming command from %d for %d:%d%s\n",
7900 initiator, target, lun,
7901 lstate == ahc->
black_hole ?
"(Black Holed)" :
"");
7907 atio->ccb_h.target_id =
target;
7908 atio->ccb_h.target_lun =
lun;
7915 atio->sense_len = 0;
7917 if (byte[0] != 0xFF) {
7919 atio->tag_action = *byte++;
7920 atio->tag_id = *byte++;
7921 atio->ccb_h.flags = CAM_TAG_ACTION_VALID;
7923 atio->ccb_h.flags = 0;
7946 printk(
"Reserved or VU command code type encountered\n");
7950 memcpy(atio->cdb_io.cdb_bytes, byte, atio->cdb_len);
7952 atio->ccb_h.status |= CAM_CDB_RECVD;
7962 printk(
"Received Immediate Command %d:%d:%d - %p\n",
7966 ahc_freeze_ccb((
union ccb *)atio);
7967 atio->ccb_h.flags |= CAM_DIS_DISCONNECT;
7969 xpt_done((
union ccb*)atio);