48 #include <dev/aic7xxx/aic79xx_osm.h>
49 #include <dev/aic7xxx/aic79xx_inline.h>
50 #include <dev/aic7xxx/aicasm/aicasm_insformat.h>
55 static const char *
const ahd_chip_names[] =
73 {
DSCTMOUT,
"Discard Timer has timed out" },
74 {
ILLOPCODE,
"Illegal Opcode in sequencer program" },
75 {
SQPARERR,
"Sequencer Parity Error" },
76 {
DPARERR,
"Data-path Parity Error" },
77 {
MPARERR,
"Scratch or SCB Memory Parity Error" },
86 { P_DATAOUT_DT,
MSG_NOOP,
"in DT Data-out phase" },
103 #include "aic79xx_seq.h"
106 static void ahd_handle_transmission_error(
struct ahd_softc *ahd);
107 static void ahd_handle_lqiphase_error(
struct ahd_softc *ahd,
109 static int ahd_handle_pkt_busfree(
struct ahd_softc *ahd,
111 static int ahd_handle_nonpkt_busfree(
struct ahd_softc *ahd);
112 static void ahd_handle_proto_violation(
struct ahd_softc *ahd);
113 static void ahd_force_renegotiation(
struct ahd_softc *ahd,
119 #ifdef AHD_TARGET_MODE
120 static void ahd_free_tstate(
struct ahd_softc *ahd,
123 static void ahd_devlimited_syncrate(
struct ahd_softc *ahd,
128 static void ahd_update_neg_table(
struct ahd_softc *ahd,
131 static void ahd_update_pending_scbs(
struct ahd_softc *ahd);
132 static void ahd_fetch_devinfo(
struct ahd_softc *ahd,
134 static void ahd_scb_devinfo(
struct ahd_softc *ahd,
137 static void ahd_setup_initiator_msgout(
struct ahd_softc *ahd,
140 static void ahd_build_transfer_msg(
struct ahd_softc *ahd,
142 static void ahd_construct_sdtr(
struct ahd_softc *ahd,
145 static void ahd_construct_wdtr(
struct ahd_softc *ahd,
148 static void ahd_construct_ppr(
struct ahd_softc *ahd,
152 static void ahd_clear_msg_state(
struct ahd_softc *ahd);
153 static void ahd_handle_message_phase(
struct ahd_softc *ahd);
161 static int ahd_parse_msg(
struct ahd_softc *ahd,
163 static int ahd_handle_msg_reject(
struct ahd_softc *ahd,
165 static void ahd_handle_ign_wide_residue(
struct ahd_softc *ahd,
167 static void ahd_reinitialize_dataptrs(
struct ahd_softc *ahd);
168 static void ahd_handle_devreset(
struct ahd_softc *ahd,
171 char *
message,
int verbose_level);
172 #ifdef AHD_TARGET_MODE
173 static void ahd_setup_target_msgin(
struct ahd_softc *ahd,
182 static void ahd_initialize_hscbs(
struct ahd_softc *ahd);
183 static int ahd_init_scbdata(
struct ahd_softc *ahd);
184 static void ahd_fini_scbdata(
struct ahd_softc *ahd);
185 static void ahd_setup_iocell_workaround(
struct ahd_softc *ahd);
186 static void ahd_iocell_first_selection(
struct ahd_softc *ahd);
187 static void ahd_add_col_list(
struct ahd_softc *ahd,
189 static void ahd_rem_col_list(
struct ahd_softc *ahd,
191 static void ahd_chip_init(
struct ahd_softc *ahd);
192 static void ahd_qinfifo_requeue(
struct ahd_softc *ahd,
193 struct scb *prev_scb,
195 static int ahd_qinfifo_count(
struct ahd_softc *ahd);
202 static void ahd_stitch_tid_list(
struct ahd_softc *ahd,
205 static void ahd_add_scb_to_free_list(
struct ahd_softc *ahd,
209 static void ahd_reset_current_bus(
struct ahd_softc *ahd);
212 static void ahd_dumpseq(
struct ahd_softc *ahd);
214 static void ahd_loadseq(
struct ahd_softc *ahd);
215 static int ahd_check_patch(
struct ahd_softc *ahd,
216 const struct patch **start_patch,
220 static void ahd_download_instr(
struct ahd_softc *ahd,
222 static int ahd_probe_stack_size(
struct ahd_softc *ahd);
223 static int ahd_scb_active_in_fifo(
struct ahd_softc *ahd,
225 static void ahd_run_data_fifo(
struct ahd_softc *ahd,
228 #ifdef AHD_TARGET_MODE
229 static void ahd_queue_lstate_event(
struct ahd_softc *ahd,
230 struct ahd_tmode_lstate *lstate,
234 static void ahd_update_scsiid(
struct ahd_softc *ahd,
236 static int ahd_handle_target_cmd(
struct ahd_softc *ahd,
243 static void ahd_alloc_scbs(
struct ahd_softc *ahd);
246 static void ahd_calc_residual(
struct ahd_softc *ahd,
248 static void ahd_clear_critical_section(
struct ahd_softc *ahd);
249 static void ahd_clear_intstat(
struct ahd_softc *ahd);
250 static void ahd_enable_coalescing(
struct ahd_softc *ahd,
253 static void ahd_freeze_devq(
struct ahd_softc *ahd,
255 static void ahd_handle_scb_status(
struct ahd_softc *ahd,
258 static void ahd_shutdown(
void *
arg);
259 static void ahd_update_coalescing_values(
struct ahd_softc *ahd,
264 static int ahd_wait_seeprom(
struct ahd_softc *ahd);
269 static void ahd_reset_cmds_pending(
struct ahd_softc *ahd);
272 static void ahd_run_qoutfifo(
struct ahd_softc *ahd);
273 #ifdef AHD_TARGET_MODE
274 static void ahd_run_tqinfifo(
struct ahd_softc *ahd,
int paused);
276 static void ahd_handle_hwerrint(
struct ahd_softc *ahd);
277 static void ahd_handle_seqint(
struct ahd_softc *ahd,
u_int intstat);
278 static void ahd_handle_scsiint(
struct ahd_softc *ahd,
290 panic(
"Setting mode prior to saving it.\n");
291 if ((ahd_debug & AHD_SHOW_MODEPTR) != 0)
292 printk(
"%s: Setting mode 0x%x\n", ahd_name(ahd),
293 ahd_build_mode_state(ahd, src, dst));
295 ahd_outb(ahd, MODE_PTR, ahd_build_mode_state(ahd, src, dst));
307 mode_ptr =
ahd_inb(ahd, MODE_PTR);
309 if ((ahd_debug & AHD_SHOW_MODEPTR) != 0)
310 printk(
"Reading mode 0x%x\n", mode_ptr);
312 ahd_extract_mode_state(ahd, mode_ptr, &src, &dst);
313 ahd_known_modes(ahd, src, dst);
323 panic(
"%s:%s:%d: Mode assertion failed.\n",
324 ahd_name(ahd), file, line);
329 #define AHD_ASSERT_MODES(ahd, source, dest) \
330 ahd_assert_modes(ahd, source, dest, __FILE__, __LINE__);
337 ahd_update_modes(ahd);
348 ahd_extract_mode_state(ahd, state, &src, &dst);
402 ahd_reset_cmds_pending(ahd);
446 if (ahd_get_transfer_length(scb) & 0x01)
447 scb->
hscb->task_attribute = SCB_XFERLEN_ODD;
449 scb->
hscb->task_attribute = 0;
453 || (scb->
hscb->cdb_len & SCB_CDB_LEN_PTR) != 0)
454 scb->
hscb->shared_data.idata.cdb_plus_saddr.sense_addr =
459 ahd_setup_data_scb(
struct ahd_softc *ahd,
struct scb *scb)
476 dataptr_words[0] = sg->
addr;
477 dataptr_words[1] = 0;
496 ahd_setup_noxfer_scb(
struct ahd_softc *ahd,
struct scb *scb)
499 scb->
hscb->dataptr = 0;
500 scb->
hscb->datacnt = 0;
515 ahd_sg_virt_to_bus(
struct ahd_softc *ahd,
struct scb *scb,
void *sg)
527 ahd_sync_scb(
struct ahd_softc *ahd,
struct scb *scb,
int op)
532 sizeof(*scb->
hscb), op);
544 ahd_sg_size(ahd) * scb->
sg_count, op);
548 ahd_sync_sense(
struct ahd_softc *ahd,
struct scb *scb,
int op)
553 AHD_SENSE_BUFSIZE, op);
556 #ifdef AHD_TARGET_MODE
583 return (&(*tstate)->transinfo[remote_id]);
606 ahd_outb(ahd, port+1, (value >> 8) & 0xFF);
615 | (
ahd_inb(ahd, port+3) << 24));
621 ahd_outb(ahd, port, (value) & 0xFF);
622 ahd_outb(ahd, port+1, ((value) >> 8) & 0xFF);
623 ahd_outb(ahd, port+2, ((value) >> 16) & 0xFF);
624 ahd_outb(ahd, port+3, ((value) >> 24) & 0xFF);
644 ahd_outb(ahd, port+1, (value >> 8) & 0xFF);
645 ahd_outb(ahd, port+2, (value >> 16) & 0xFF);
646 ahd_outb(ahd, port+3, (value >> 24) & 0xFF);
647 ahd_outb(ahd, port+4, (value >> 32) & 0xFF);
648 ahd_outb(ahd, port+5, (value >> 40) & 0xFF);
649 ahd_outb(ahd, port+6, (value >> 48) & 0xFF);
650 ahd_outb(ahd, port+7, (value >> 56) & 0xFF);
672 ahd_get_hnscb_qoff(
struct ahd_softc *ahd)
686 ahd_get_hescb_qoff(
struct ahd_softc *ahd)
699 ahd_get_snscb_qoff(
struct ahd_softc *ahd)
718 ahd_get_sescb_qoff(
struct ahd_softc *ahd)
734 ahd_get_sdscb_qoff(
struct ahd_softc *ahd)
791 return (ahd_inl_scbram(ahd, offset)
792 | ((
uint64_t)ahd_inl_scbram(ahd, offset+4)) << 32);
804 ahd_sync_scb(ahd, scb,
810 ahd_swap_with_next_hscb(
struct ahd_softc *ahd,
struct scb *scb)
851 ahd_swap_with_next_hscb(ahd, scb);
854 panic(
"Attempt to queue invalid SCB tag %x\n",
864 ahd_setup_data_scb(ahd, scb);
866 ahd_setup_noxfer_scb(ahd, scb);
867 ahd_setup_scb_common(ahd, scb);
876 if ((ahd_debug & AHD_SHOW_QUEUE) != 0) {
880 printk(
"%s: Queueing SCB %d:0x%x bus addr 0x%x - 0x%x%x/0x%x\n",
884 (
u_int)((host_dataptr >> 32) & 0xFFFFFFFF),
885 (
u_int)(host_dataptr & 0xFFFFFFFF),
905 #ifdef AHD_TARGET_MODE
909 ahd_targetcmd_offset(ahd, 0),
920 #define AHD_RUN_QOUTFIFO 0x1
921 #define AHD_RUN_TQINFIFO 0x2
923 ahd_check_cmdcmpltqueues(
struct ahd_softc *ahd)
934 #ifdef AHD_TARGET_MODE
939 ahd_targetcmd_offset(ahd, ahd->tqinfifofnext),
974 && (ahd_check_cmdcmpltqueues(ahd) != 0))
1000 if (
ahd_inb(ahd, SEQINTCODE) != NO_SEQINT)
1004 ahd_flush_device_writes(ahd);
1006 ahd_run_qoutfifo(ahd);
1009 #ifdef AHD_TARGET_MODE
1011 ahd_run_tqinfifo(ahd,
FALSE);
1021 }
else if (intstat & HWERRINT) {
1022 ahd_handle_hwerrint(ahd);
1023 }
else if ((intstat & (PCIINT|SPLTINT)) != 0) {
1027 if ((intstat &
SEQINT) != 0)
1028 ahd_handle_seqint(ahd, intstat);
1031 ahd_handle_scsiint(ahd, intstat);
1050 ahd_currently_packetized(
struct ahd_softc *ahd)
1063 packetized =
ahd_inb(ahd, LQISTATE) != 0;
1066 packetized =
ahd_inb(ahd, LQISTAT2) & PACKETIZED;
1069 return (packetized);
1073 ahd_set_active_fifo(
struct ahd_softc *ahd)
1078 active_fifo =
ahd_inb(ahd, DFFSTAT) & CURRFIFO;
1079 switch (active_fifo) {
1100 ahd_update_residual(
struct ahd_softc *ahd,
struct scb *scb)
1105 if ((sgptr & SG_STATUS_VALID) != 0)
1106 ahd_calc_residual(ahd, scb);
1110 ahd_complete_scb(
struct ahd_softc *ahd,
struct scb *scb)
1115 if ((sgptr & SG_STATUS_VALID) != 0)
1116 ahd_handle_scb_status(ahd, scb);
1135 ahd_clear_msg_state(ahd);
1176 if ((ahd_debug & AHD_SHOW_FIFOS) != 0)
1177 printk(
"%s: Clearing FIFO %d\n", ahd_name(ahd), fifo);
1181 ahd_outb(ahd, DFFSXFRCTL, RSTCHN|CLRSHCNT);
1182 if ((
ahd_inb(ahd, SG_STATE) & FETCH_INPROG) != 0)
1195 ahd_flush_qoutfifo(
struct ahd_softc *ahd)
1211 while ((
ahd_inb(ahd, LQISTAT2) & LQIGSAVAIL) != 0) {
1218 printk(
"%s: Warning - GSFIFO SCB %d invalid\n",
1219 ahd_name(ahd), scbid);
1229 for (i = 0; i < 2; i++) {
1234 if (ahd_scb_active_in_fifo(ahd, scb) == 0)
1237 ahd_run_data_fifo(ahd, scb);
1261 & SG_LIST_NULL) != 0)) {
1276 comp_head =
ahd_inw(ahd, COMPLETE_DMA_SCB_HEAD);
1278 ahd_outw(ahd, COMPLETE_DMA_SCB_HEAD, scbid);
1279 ahd_outw(ahd, COMPLETE_DMA_SCB_TAIL, scbid);
1283 tail =
ahd_inw(ahd, COMPLETE_DMA_SCB_TAIL);
1285 ahd_outw(ahd, SCB_NEXT_COMPLETE, scbid);
1286 ahd_outw(ahd, COMPLETE_DMA_SCB_TAIL, scbid);
1290 ahd_complete_scb(ahd, scb);
1306 if ((ccscbctl &
ARRDONE) != 0)
1326 ahd_run_qoutfifo(ahd);
1333 scbid =
ahd_inw(ahd, COMPLETE_DMA_SCB_HEAD);
1342 printk(
"%s: Warning - DMA-up and complete "
1343 "SCB %d invalid\n", ahd_name(ahd), scbid);
1350 ahd_complete_scb(ahd, scb);
1356 scbid =
ahd_inw(ahd, COMPLETE_ON_QFREEZE_HEAD);
1363 printk(
"%s: Warning - Complete Qfrz SCB %d invalid\n",
1364 ahd_name(ahd), scbid);
1368 ahd_complete_scb(ahd, scb);
1373 scbid =
ahd_inw(ahd, COMPLETE_SCB_HEAD);
1380 printk(
"%s: Warning - Complete SCB %d invalid\n",
1381 ahd_name(ahd), scbid);
1385 ahd_complete_scb(ahd, scb);
1403 ahd_scb_active_in_fifo(
struct ahd_softc *ahd,
struct scb *scb)
1414 && (
ahd_inb(ahd, SEQINTSRC) & (CFG4DATA|SAVEPTRS)) == 0))
1432 ahd_run_data_fifo(
struct ahd_softc *ahd,
struct scb *scb)
1436 seqintsrc =
ahd_inb(ahd, SEQINTSRC);
1437 if ((seqintsrc & CFG4DATA) != 0) {
1444 sgptr = ahd_inl_scbram(ahd,
SCB_SGPTR) & ~SG_FULL_RESID;
1455 ahd_outb(ahd, SG_STATE, LOADING_NEEDED);
1458 ahd_outb(ahd, SG_CACHE_PRE, sgptr);
1464 ahd_outb(ahd, SCB_RESIDUAL_DATACNT+3, datacnt >> 24);
1482 ahd_outb(ahd, CLRSEQINTSRC, CLRCFG4DATA);
1483 }
else if ((seqintsrc & SAVEPTRS) != 0) {
1500 if ((
ahd_inb(ahd, SG_STATE) & FETCH_INPROG) != 0)
1513 sgptr = ahd_inl_scbram(ahd, SCB_RESIDUAL_SGPTR);
1516 ahd_outl(ahd, SCB_RESIDUAL_DATACNT, resid);
1525 if ((
ahd_inb(ahd, SG_CACHE_SHADOW) & 0x80) != 0
1526 && (sgptr & 0x80) == 0)
1529 sgptr |=
ahd_inb(ahd, SG_CACHE_SHADOW)
1531 ahd_outl(ahd, SCB_RESIDUAL_SGPTR, sgptr);
1532 ahd_outb(ahd, SCB_RESIDUAL_DATACNT + 3, 0);
1535 sgptr | SG_LIST_NULL);
1543 ahd_outb(ahd, CLRSEQINTSRC, CLRSAVEPTRS);
1545 ahd_inb(ahd, SEQIMODE) | ENSAVEPTRS);
1552 }
else if ((
ahd_inb(ahd, SG_STATE) & LOADING_NEEDED) != 0) {
1563 if ((
ahd_inb(ahd, SG_STATE) & FETCH_INPROG) != 0) {
1565 ahd_outb(ahd, SG_STATE, LOADING_NEEDED);
1581 sgptr = ahd_inl_scbram(ahd, SCB_RESIDUAL_SGPTR);
1586 sg = ahd_sg_bus_to_virt(ahd, scb, sgptr);
1587 data_addr = sg->
addr;
1589 sgptr +=
sizeof(*sg);
1593 sg = ahd_sg_bus_to_virt(ahd, scb, sgptr);
1596 data_addr |= sg->
addr;
1598 sgptr +=
sizeof(*sg);
1604 ahd_outb(ahd, SCB_RESIDUAL_DATACNT+3, data_len >> 24);
1605 ahd_outl(ahd, SCB_RESIDUAL_SGPTR, sgptr);
1610 if (data_len & AHD_DMA_LAST_SEG) {
1616 ahd_outb(ahd, SG_CACHE_PRE, sgptr & 0xFF);
1628 dfcntrl |= SCSIENWRDIS;
1673 panic(
"ahd_run_qoutfifo recursion");
1685 printk(
"%s: WARNING no command for scb %d "
1686 "(cmdcmplt)\nQOUTPOS = %d\n",
1687 ahd_name(ahd), scb_index,
1690 }
else if ((completion->
sg_status & SG_STATUS_VALID) != 0) {
1691 ahd_handle_scb_status(ahd, scb);
1705 ahd_handle_hwerrint(
struct ahd_softc *ahd)
1716 if ((error & ahd_hard_errors[i].errno) != 0)
1717 printk(
"%s: hwerrint, %s\n",
1718 ahd_name(ahd), ahd_hard_errors[i].
errmesg);
1735 ahd_dump_sglist(
struct scb *scb)
1750 printk(
"sg[%d] - Addr 0x%x%x : Length %d%s\n",
1752 (
uint32_t)((addr >> 32) & 0xFFFFFFFF),
1754 sg_list[i].len & AHD_SG_LEN_MASK,
1755 (sg_list[i].len & AHD_DMA_LAST_SEG)
1766 printk(
"sg[%d] - Addr 0x%x%x : Length %d%s\n",
1770 len & AHD_SG_LEN_MASK,
1771 len & AHD_DMA_LAST_SEG ?
" Last" :
"");
1788 seqintcode =
ahd_inb(ahd, SEQINTCODE);
1802 ahd_update_modes(ahd);
1804 if ((ahd_debug & AHD_SHOW_MISC) != 0)
1805 printk(
"%s: Handle Seqint Called for code %d\n",
1806 ahd_name(ahd), seqintcode);
1808 switch (seqintcode) {
1809 case ENTERING_NONPACK:
1830 if ((
ahd_inb(ahd, LQISTAT2) & LQIPHASE_OUTPKT) != 0
1838 if ((ahd_debug & AHD_SHOW_RECOVERY) != 0)
1839 printk(
"%s: Assuming LQIPHASE_NLQ with "
1840 "P0 assertion\n", ahd_name(ahd));
1844 if ((ahd_debug & AHD_SHOW_RECOVERY) != 0)
1845 printk(
"%s: Entering NONPACK\n", ahd_name(ahd));
1849 case INVALID_SEQINT:
1850 printk(
"%s: Invalid Sequencer interrupt occurred, "
1851 "resetting channel.\n",
1854 if ((ahd_debug & AHD_SHOW_RECOVERY) != 0)
1859 case STATUS_OVERRUN:
1869 printk(
"%s: ", ahd_name(ahd));
1870 printk(
"SCB %d Packetized Status Overrun", scbid);
1875 case CFG4ISTAT_INTR:
1884 printk(
"CFG4ISTAT: Free SCB %d referenced", scbid);
1885 panic(
"For safety");
1890 ahd_outb(ahd, SG_CACHE_PRE, SG_LAST_SEG);
1899 printk(
"%s: ILLEGAL_PHASE 0x%x\n",
1900 ahd_name(ahd), bus_phase);
1902 switch (bus_phase) {
1911 printk(
"%s: Issued Bus Reset.\n", ahd_name(ahd));
1936 printk(
"Invalid phase with no valid SCB. "
1937 "Resetting bus.\n");
1952 tinfo = &targ_info->
curr;
1977 ahd_assert_atn(ahd);
1980 ahd_freeze_devq(ahd, scb);
1982 ahd_freeze_scb(scb);
1993 ahd_outb(ahd, CLRLQOINT1, CLRLQOPHACHGINPKT);
1998 if ((ahd_debug & AHD_SHOW_RECOVERY) != 0) {
2000 printk(
"Unexpected command phase from "
2001 "packetized target\n");
2015 if ((ahd_debug & AHD_SHOW_RECOVERY) != 0) {
2016 printk(
"%s: CFG4OVERRUN mode = %x\n", ahd_name(ahd),
2027 ahd_assert_atn(ahd);
2043 case DUMP_CARD_STATE:
2051 if ((ahd_debug & AHD_SHOW_RECOVERY) != 0) {
2052 printk(
"%s: PDATA_REINIT - DFCNTRL = 0x%x "
2053 "SG_CACHE_SHADOW = 0x%x\n",
2055 ahd_inb(ahd, SG_CACHE_SHADOW));
2058 ahd_reinitialize_dataptrs(ahd);
2076 ahd_fetch_devinfo(ahd, &devinfo);
2085 printk(
"ahd_intr: HOST_MSG_LOOP bad "
2086 "phase 0x%x\n", bus_phase);
2092 ahd_clear_intstat(ahd);
2101 ahd_setup_initiator_msgout(ahd,
2110 #ifdef AHD_TARGET_MODE
2118 ahd_setup_target_msgin(ahd,
2125 ahd_handle_message_phase(ahd);
2134 printk(
"%s:%c:%d: no active SCB for reconnecting "
2135 "target - issuing BUS DEVICE RESET\n",
2137 printk(
"SAVED_SCSIID == 0x%x, SAVED_LUN == 0x%x, "
2138 "REG0 == 0x%x ACCUM = 0x%x\n",
2141 printk(
"SEQ_FLAGS == 0x%x, SCBPTR == 0x%x, BTT == 0x%x, "
2144 ahd_find_busy_tcl(ahd,
2148 printk(
"SELID == 0x%x, SCB_SCSIID == 0x%x, SCB_LUN == 0x%x, "
2149 "SCB_CONTROL == 0x%x\n",
2153 printk(
"SCSIBUS[0] == 0x%x, SCSISIGI == 0x%x\n",
2163 ahd_assert_atn(ahd);
2166 case PROTO_VIOLATION:
2168 ahd_handle_proto_violation(ahd);
2175 ahd_fetch_devinfo(ahd, &devinfo);
2176 ahd_handle_ign_wide_residue(ahd, &devinfo);
2184 printk(
"%s:%c:%d: unknown scsi bus phase %x, "
2185 "lastphase = 0x%x. Attempting to continue\n",
2191 case MISSED_BUSFREE:
2196 printk(
"%s:%c:%d: Missed busfree. "
2197 "Lastphase = 0x%x, Curphase = 0x%x\n",
2224 if ((ahd_debug & AHD_SHOW_RECOVERY) != 0) {
2226 printk(
"data overrun detected %s. Tag == 0x%x.\n",
2227 ahd_lookup_phase_entry(lastphase)->phasemsg,
2230 printk(
"%s seen Data Phase. Length = %ld. "
2233 ?
"Have" :
"Haven't",
2234 ahd_get_transfer_length(scb), scb->
sg_count);
2235 ahd_dump_sglist(scb);
2243 ahd_freeze_devq(ahd, scb);
2245 ahd_freeze_scb(scb);
2254 ahd_fetch_devinfo(ahd, &devinfo);
2255 printk(
"%s:%c:%d:%d: Attempt to issue message failed\n",
2256 ahd_name(ahd), devinfo.channel, devinfo.target,
2275 case TASKMGMT_FUNC_COMPLETE:
2288 printk(
"Task Management Func 0x%x Complete\n",
2289 scb->
hscb->task_management);
2293 switch (scb->
hscb->task_management) {
2298 lun = scb->
hscb->lun;
2305 lun = scb->
hscb->lun;
2310 ahd_scb_devinfo(ahd, &devinfo, scb);
2312 ahd_handle_devreset(ahd, &devinfo, lun,
2321 panic(
"Unexpected TaskMgmt Func\n");
2327 case TASKMGMT_CMD_CMPLT_OKAY:
2344 printk(
"SCB completes before TMF\n");
2356 ahd_outb(ahd, SCB_TASK_MANAGEMENT, 0);
2369 printk(
"%s: Tracepoint %d\n", ahd_name(ahd),
2370 seqintcode - TRACEPOINT0);
2375 ahd_handle_hwerrint(ahd);
2378 printk(
"%s: Unexpected SEQINTCODE %d\n", ahd_name(ahd),
2402 ahd_update_modes(ahd);
2408 lqistat1 =
ahd_inb(ahd, LQISTAT1);
2409 lqostat0 =
ahd_inb(ahd, LQOSTAT0);
2425 if ((status0 & (
SELDI|SELDO)) != 0) {
2439 if ((status0 &
IOERR) != 0) {
2443 printk(
"%s: Transceiver State Has Changed to %s mode\n",
2444 ahd_name(ahd), now_lvd ?
"LVD" :
"SE");
2451 ahd_setup_iocell_workaround(ahd);
2453 }
else if ((status0 &
OVERRUN) != 0) {
2455 printk(
"%s: SCSI offset overrun detected. Resetting bus.\n",
2458 }
else if ((status & SCSIRSTI) != 0) {
2460 printk(
"%s: Someone reset channel A\n", ahd_name(ahd));
2462 }
else if ((status &
SCSIPERR) != 0) {
2465 ahd_clear_critical_section(ahd);
2467 ahd_handle_transmission_error(ahd);
2468 }
else if (lqostat0 != 0) {
2470 printk(
"%s: lqostat0 == 0x%x!\n", ahd_name(ahd), lqostat0);
2471 ahd_outb(ahd, CLRLQOINT0, lqostat0);
2474 }
else if ((status & SELTO) != 0) {
2479 ahd_clear_critical_section(ahd);
2482 ahd_clear_msg_state(ahd);
2497 scbid =
ahd_inw(ahd, WAITING_TID_HEAD);
2500 printk(
"%s: ahd_intr - referenced scb not "
2501 "valid during SELTO scb(0x%x)\n",
2502 ahd_name(ahd), scbid);
2507 if ((ahd_debug & AHD_SHOW_SELTO) != 0) {
2509 printk(
"Saw Selection Timeout for SCB 0x%x\n",
2513 ahd_scb_devinfo(ahd, &devinfo, scb);
2515 ahd_freeze_devq(ahd, scb);
2523 ahd_handle_devreset(ahd, &devinfo,
2526 "Selection Timeout",
2530 ahd_iocell_first_selection(ahd);
2532 }
else if ((status0 & (
SELDI|SELDO)) != 0) {
2534 ahd_iocell_first_selection(ahd);
2536 }
else if (status3 != 0) {
2537 printk(
"%s: SCSI Cell parity error SSTAT3 == 0x%x\n",
2538 ahd_name(ahd), status3);
2540 }
else if ((lqistat1 & (LQIPHASE_LQ|LQIPHASE_NLQ)) != 0) {
2543 ahd_clear_critical_section(ahd);
2545 ahd_handle_lqiphase_error(ahd, lqistat1);
2546 }
else if ((lqistat1 & LQICRCI_NLQ) != 0) {
2553 ahd_outb(ahd, CLRLQIINT1, CLRLQICRCI_NLQ);
2554 }
else if ((status &
BUSFREE) != 0
2555 || (lqistat1 & LQOBUSFREE) != 0) {
2571 ahd_clear_critical_section(ahd);
2579 lqostat1 =
ahd_inb(ahd, LQOSTAT1);
2580 switch (busfreetime) {
2584 mode = busfreetime == BUSFREE_DFF0
2590 printk(
"%s: Invalid SCB %d in DFF%d "
2591 "during unexpected busfree\n",
2592 ahd_name(ahd), scbid, mode);
2605 packetized = (lqostat1 & LQOBUSFREE) != 0;
2622 if ((ahd_debug & AHD_SHOW_MISC) != 0)
2623 printk(
"Saw Busfree. Busfreetime = 0x%x.\n",
2631 restart = ahd_handle_pkt_busfree(ahd, busfreetime);
2634 restart = ahd_handle_nonpkt_busfree(ahd);
2654 ahd_clear_fifo(ahd, mode);
2656 ahd_clear_msg_state(ahd);
2664 printk(
"%s: Missing case in ahd_handle_scsiint. status = %x\n",
2665 ahd_name(ahd), status);
2667 ahd_clear_intstat(ahd);
2673 ahd_handle_transmission_error(
struct ahd_softc *ahd)
2688 lqistat1 =
ahd_inb(ahd, LQISTAT1) & ~(LQIPHASE_LQ|LQIPHASE_NLQ);
2689 lqistat2 =
ahd_inb(ahd, LQISTAT2);
2690 if ((lqistat1 & (LQICRCI_NLQ|LQICRCI_LQ)) == 0
2695 lqistate =
ahd_inb(ahd, LQISTATE);
2696 if ((lqistate >= 0x1E && lqistate <= 0x24)
2697 || (lqistate == 0x29)) {
2699 if ((ahd_debug & AHD_SHOW_RECOVERY) != 0) {
2700 printk(
"%s: NLQCRC found via LQISTATE\n",
2704 lqistat1 |= LQICRCI_NLQ;
2709 ahd_outb(ahd, CLRLQIINT1, lqistat1);
2712 perrdiag =
ahd_inb(ahd, PERRDIAG);
2721 || (lqistat1 & LQICRCI_NLQ) != 0) {
2722 if ((lqistat1 & (LQICRCI_NLQ|LQIOVERI_NLQ)) != 0)
2723 ahd_set_active_fifo(ahd);
2731 if (silent ==
FALSE) {
2732 printk(
"%s: Transmission error detected\n", ahd_name(ahd));
2733 ahd_lqistat1_print(lqistat1, &cur_col, 50);
2734 ahd_lastphase_print(lastphase, &cur_col, 50);
2735 ahd_scsisigi_print(curphase, &cur_col, 50);
2736 ahd_perrdiag_print(perrdiag, &cur_col, 50);
2741 if ((lqistat1 & (LQIOVERI_LQ|LQIOVERI_NLQ)) != 0) {
2742 if (silent ==
FALSE) {
2743 printk(
"%s: Gross protocol error during incoming "
2744 "packet. lqistat1 == 0x%x. Resetting bus.\n",
2745 ahd_name(ahd), lqistat1);
2749 }
else if ((lqistat1 & LQICRCI_LQ) != 0) {
2772 printk(
"LQIRetry for LQICRCI_LQ to release ACK\n");
2773 }
else if ((lqistat1 & LQICRCI_NLQ) != 0) {
2819 if (silent ==
FALSE)
2822 printk(
"%s: No SCB valid for LQICRC_NLQ. "
2823 "Resetting bus\n", ahd_name(ahd));
2827 }
else if ((lqistat1 & LQIBADLQI) != 0) {
2828 printk(
"Need to handle BADLQI!\n");
2832 if ((curphase & ~P_DATAIN_DT) != 0) {
2834 if (silent ==
FALSE)
2835 printk(
"Acking %s to clear perror\n",
2836 ahd_lookup_phase_entry(curphase)->phasemsg);
2866 ahd_outb(ahd, CLRLQIINT1, lqistat1);
2876 ahd_set_active_fifo(ahd);
2878 && (
ahd_inb(ahd, MDFFSTAT) & DLZERO) != 0) {
2879 if ((lqistat1 & LQIPHASE_LQ) != 0) {
2880 printk(
"LQIRETRY for LQIPHASE_LQ\n");
2882 }
else if ((lqistat1 & LQIPHASE_NLQ) != 0) {
2883 printk(
"LQIRETRY for LQIPHASE_NLQ\n");
2886 panic(
"ahd_handle_lqiphase_error: No phase errors\n");
2891 printk(
"Resetting Channel for LQI Phase error\n");
2908 lqostat1 =
ahd_inb(ahd, LQOSTAT1);
2909 if ((lqostat1 & LQOBUSFREE) != 0) {
2933 scbid =
ahd_inw(ahd, CURRSCB);
2936 panic(
"SCB not valid during LQOBUSFREE");
2940 ahd_outb(ahd, CLRLQOINT1, CLRLQOBUSFREE);
2944 ahd_flush_device_writes(ahd);
2959 waiting_h =
ahd_inw(ahd, WAITING_TID_HEAD);
2961 if (waiting_h != scbid) {
2963 ahd_outw(ahd, WAITING_TID_HEAD, scbid);
2964 waiting_t =
ahd_inw(ahd, WAITING_TID_TAIL);
2965 if (waiting_t == waiting_h) {
2966 ahd_outw(ahd, WAITING_TID_TAIL, scbid);
2979 printk(
"Probable outgoing LQ CRC error. "
2980 "Retrying command\n");
2985 ahd_freeze_scb(scb);
2986 ahd_freeze_devq(ahd, scb);
3000 if ((ahd_debug & AHD_SHOW_MASKED_ERRORS) != 0)
3001 printk(
"%s: Parity on last REQ detected "
3002 "during busfree phase.\n",
3015 printk(
"Unexpected PKT busfree condition\n");
3024 printk(
"%s: Unexpected PKT busfree condition\n", ahd_name(ahd));
3034 ahd_handle_nonpkt_busfree(
struct ahd_softc *ahd)
3042 u_int initiator_role_id;
3053 saved_scsiid =
ahd_inb(ahd, SAVED_SCSIID);
3054 saved_lun =
ahd_inb(ahd, SAVED_LUN);
3079 printk(
"Abort for unidentified "
3080 "connection completed.\n");
3086 printk(
"SCB %d - Abort%s Completed.\n",
3107 saved_lun = scb->
hscb->lun;
3109 found = ahd_abort_scbs(ahd, target,
'A', saved_lun,
3112 printk(
"found == 0x%x\n", found);
3123 && scb->
io_ctx->ccb_h.func_code== XPT_RESET_DEV
3124 && ahd_match_scb(ahd, scb, target,
'A',
3134 && ppr_busfree == 0) {
3149 if ((ahd_debug & AHD_SHOW_MESSAGES) != 0)
3150 printk(
"PPR negotiation rejected busfree.\n");
3154 devinfo.target, &tstate);
3171 tinfo->
curr.transport_version = 2;
3172 tinfo->
goal.transport_version = 2;
3173 tinfo->
goal.ppr_options = 0;
3181 ahd_freeze_devq(ahd, scb);
3187 && ppr_busfree == 0) {
3193 if ((ahd_debug & AHD_SHOW_MESSAGES) != 0)
3194 printk(
"WDTR negotiation rejected busfree.\n");
3207 ahd_freeze_devq(ahd, scb);
3212 && ppr_busfree == 0) {
3218 if ((ahd_debug & AHD_SHOW_MESSAGES) != 0)
3219 printk(
"SDTR negotiation rejected busfree.\n");
3233 ahd_freeze_devq(ahd, scb);
3242 if ((ahd_debug & AHD_SHOW_MESSAGES) != 0)
3243 printk(
"Expected IDE Busfree\n");
3251 if ((ahd_debug & AHD_SHOW_MESSAGES) != 0)
3252 printk(
"Expected QAS Reject Busfree\n");
3263 if (scb !=
NULL && printerror != 0
3267 ahd_freeze_devq(ahd, scb);
3269 ahd_freeze_scb(scb);
3277 if ((ahd_debug & AHD_SHOW_MESSAGES) != 0)
3278 printk(
"PPR Negotiation Busfree.\n");
3284 if (printerror != 0) {
3296 aborted = ahd_abort_scbs(ahd, target,
'A',
3305 printk(
"%s: ", ahd_name(ahd));
3307 printk(
"Unexpected busfree %s, %d SCBs aborted, "
3308 "PRGMCNT == 0x%x\n",
3309 ahd_lookup_phase_entry(lastphase)->phasemsg,
3314 ahd_force_renegotiation(ahd, &devinfo);
3321 ahd_handle_proto_violation(
struct ahd_softc *ahd)
3331 ahd_fetch_devinfo(ahd, &devinfo);
3337 if ((seq_flags & NOT_IDENTIFIED) != 0) {
3345 printk(
"Target did not send an IDENTIFY message. "
3346 "LASTPHASE = 0x%x.\n", lastphase);
3348 }
else if (scb ==
NULL) {
3354 printk(
"No SCB found during protocol violation\n");
3355 goto proto_violation_reset;
3358 if ((seq_flags & NO_CDB_SENT) != 0) {
3360 printk(
"No or incomplete CDB sent to device.\n");
3362 & STATUS_RCVD) == 0) {
3371 printk(
"Completed command without status.\n");
3374 printk(
"Unknown protocol violation.\n");
3378 if ((lastphase & ~P_DATAIN_DT) == 0
3380 proto_violation_reset:
3388 printk(
"%s: Issued Channel %c Bus Reset. "
3389 "%d SCBs aborted\n", ahd_name(ahd),
'A', found);
3397 ahd_inb(ahd, SCSISEQ0) & ~ENSELO);
3398 ahd_assert_atn(ahd);
3410 printk(
"Protocol violation %s. Attempting to abort.\n",
3411 ahd_lookup_phase_entry(curphase)->phasemsg);
3426 if ((ahd_debug & AHD_SHOW_MESSAGES) != 0) {
3428 printk(
"Forcing renegotiation\n");
3440 #define AHD_MAX_STEPS 2000
3442 ahd_clear_critical_section(
struct ahd_softc *ahd)
3476 seqaddr =
ahd_inw(ahd, CURADDR);
3481 if (cs->begin < seqaddr && cs->end >= seqaddr)
3489 printk(
"%s: Infinite loop in critical section\n"
3490 "%s: First Instruction 0x%x now 0x%x\n",
3491 ahd_name(ahd), ahd_name(ahd), first_instr,
3494 panic(
"critical section loop");
3499 if ((ahd_debug & AHD_SHOW_MISC) != 0)
3500 printk(
"%s: Single stepping at 0x%x\n", ahd_name(ahd),
3503 if (stepping ==
FALSE) {
3505 first_instr = seqaddr;
3508 simode3 =
ahd_inb(ahd, SIMODE3);
3509 lqimode0 =
ahd_inb(ahd, LQIMODE0);
3510 lqimode1 =
ahd_inb(ahd, LQIMODE1);
3511 lqomode0 =
ahd_inb(ahd, LQOMODE0);
3512 lqomode1 =
ahd_inb(ahd, LQOMODE1);
3537 ahd_update_modes(ahd);
3565 ahd_clear_intstat(
struct ahd_softc *ahd)
3570 ahd_outb(ahd, CLRLQIINT0, CLRLQIATNQAS|CLRLQICRCT1|CLRLQICRCT2
3571 |CLRLQIBADLQT|CLRLQIATNLQ|CLRLQIATNCMD);
3572 ahd_outb(ahd, CLRLQIINT1, CLRLQIPHASE_LQ|CLRLQIPHASE_NLQ|CLRLIQABORT
3573 |CLRLQICRCI_LQ|CLRLQICRCI_NLQ|CLRLQIBADLQI
3574 |CLRLQIOVERI_LQ|CLRLQIOVERI_NLQ|CLRNONPACKREQ);
3575 ahd_outb(ahd, CLRLQOINT0, CLRLQOTARGSCBPERR|CLRLQOSTOPT2|CLRLQOATNLQ
3576 |CLRLQOATNPKT|CLRLQOTCRC);
3577 ahd_outb(ahd, CLRLQOINT1, CLRLQOINITSCBPERR|CLRLQOSTOPI2|CLRLQOBADQAS
3578 |CLRLQOBUSFREE|CLRLQOPHACHGINPKT);
3583 ahd_outb(ahd, CLRSINT3, CLRNTRAMPERR|CLROSRAMPERR);
3587 |CLRIOERR|CLROVERRUN);
3593 uint32_t ahd_debug = AHD_DEBUG_OPTS;
3598 ahd_print_scb(
struct scb *scb)
3604 printk(
"scb:%p control:0x%x scsiid:0x%x lun:%d cdb_len:%d\n",
3613 printk(
" dataptr:%#x%x datacnt:%#x sgptr:%#x tag:%#x\n",
3619 ahd_dump_sglist(scb);
3638 panic(
"%s: ahd_alloc_tstate - Target already allocated",
3650 if (master_tstate !=
NULL) {
3651 memcpy(tstate, master_tstate,
sizeof(*tstate));
3653 for (i = 0; i < 16; i++) {
3660 memset(tstate, 0,
sizeof(*tstate));
3665 #ifdef AHD_TARGET_MODE
3679 if (scsi_id == ahd->
our_id
3697 ahd_devlimited_syncrate(
struct ahd_softc *ahd,
3723 transinfo = &tinfo->
user;
3725 transinfo = &tinfo->
goal;
3731 if (transinfo->
period == 0) {
3749 if (*period < maxsync)
3754 *ppr_options &= ~MSG_EXT_PPR_DT_REQ;
3766 if ((*ppr_options & MSG_EXT_PPR_DT_REQ) == 0)
3770 if ((*ppr_options & MSG_EXT_PPR_IU_REQ) == 0
3775 if ((*ppr_options & MSG_EXT_PPR_DT_REQ) == 0
3785 ahd_validate_offset(
struct ahd_softc *ahd,
3797 maxoffset = MAX_OFFSET_PACED_BUG;
3799 maxoffset = MAX_OFFSET_PACED;
3801 maxoffset = MAX_OFFSET_NON_PACED;
3802 *offset =
min(*offset, maxoffset);
3803 if (tinfo !=
NULL) {
3819 switch (*bus_width) {
3831 if (tinfo !=
NULL) {
3833 *bus_width =
min((
u_int)tinfo->
user.width, *bus_width);
3835 *bus_width =
min((
u_int)tinfo->
goal.width, *bus_width);
3850 u_int auto_negotiate_orig;
3865 if (tinfo->
curr.period != tinfo->
goal.period
3866 || tinfo->
curr.width != tinfo->
goal.width
3867 || tinfo->
curr.offset != tinfo->
goal.offset
3868 || tinfo->
curr.ppr_options != tinfo->
goal.ppr_options
3870 && (tinfo->
goal.offset != 0
3872 || tinfo->
goal.ppr_options != 0)))
3904 if (period == 0 || offset == 0) {
3910 devinfo->
target, &tstate);
3915 tinfo->
user.ppr_options = ppr_options;
3921 tinfo->
goal.ppr_options = ppr_options;
3924 old_period = tinfo->
curr.period;
3925 old_offset = tinfo->
curr.offset;
3926 old_ppr = tinfo->
curr.ppr_options;
3929 && (old_period != period
3930 || old_offset != offset
3931 || old_ppr != ppr_options)) {
3937 tinfo->
curr.ppr_options = ppr_options;
3945 printk(
"%s: target %d synchronous with "
3946 "period = 0x%x, offset = 0x%x",
3947 ahd_name(ahd), devinfo->
target,
3955 printk(
"%s", options ?
"|DT" :
"(DT");
3959 printk(
"%s", options ?
"|IU" :
"(IU");
3963 printk(
"%s", options ?
"|RTI" :
"(RTI");
3967 printk(
"%s", options ?
"|QAS" :
"(QAS");
3975 printk(
"%s: target %d using "
3976 "asynchronous transfers%s\n",
3977 ahd_name(ahd), devinfo->
target,
3991 if ((type & AHD_TRANS_CUR) != 0) {
3994 ahd_update_neg_table(ahd, devinfo, &tinfo->
curr);
3999 != (ppr_options & MSG_EXT_PPR_IU_REQ)) {
4001 if ((ahd_debug & AHD_SHOW_MESSAGES) != 0) {
4003 printk(
"Expecting IU Change busfree\n");
4009 if ((old_ppr & MSG_EXT_PPR_IU_REQ) != 0) {
4011 if ((ahd_debug & AHD_SHOW_MESSAGES) != 0)
4012 printk(
"PPR with IU_REQ outstanding\n");
4022 if (update_needed && active)
4023 ahd_update_pending_scbs(ahd);
4047 devinfo->
target, &tstate);
4055 oldwidth = tinfo->
curr.width;
4064 printk(
"%s: target %d using %dbit transfers\n",
4065 ahd_name(ahd), devinfo->
target,
4066 8 * (0x01 << width));
4070 if ((type & AHD_TRANS_CUR) != 0) {
4073 ahd_update_neg_table(ahd, devinfo, &tinfo->
curr);
4080 if (update_needed && active)
4081 ahd_update_pending_scbs(ahd);
4108 u_int saved_negoaddr;
4114 saved_negoaddr =
ahd_inb(ahd, NEGOADDR);
4138 ppr_opts |= PPROPT_PACE;
4167 con_opts |= ENSLOWCRC;
4180 ahd_outb(ahd, ANNEXCOL, AHD_ANNEXCOL_PRECOMP_SLEW);
4182 ahd_outb(ahd, ANNEXCOL, AHD_ANNEXCOL_AMPLITUDE);
4186 ahd_outb(ahd, NEGPPROPTS, ppr_opts);
4198 con_opts |= ENSLOWCRC;
4206 if ((tinfo->
ppr_options & MSG_EXT_PPR_IU_REQ) == 0)
4208 ahd_outb(ahd, NEGCONOPTS, con_opts);
4209 ahd_outb(ahd, NEGOADDR, saved_negoaddr);
4220 ahd_update_pending_scbs(
struct ahd_softc *ahd)
4222 struct scb *pending_scb;
4223 int pending_scb_count;
4238 pending_scb_count = 0;
4244 ahd_scb_devinfo(ahd, &devinfo, pending_scb);
4247 devinfo.
target, &tstate);
4253 ahd_sync_scb(ahd, pending_scb,
4255 pending_scb_count++;
4258 if (pending_scb_count == 0)
4323 our_id =
ahd_inb(ahd, TOWNID);
4325 our_id =
ahd_inb(ahd, IOWNID);
4327 saved_scsiid =
ahd_inb(ahd, SAVED_SCSIID);
4340 printk(
"%s:%c:%d:%d: ", ahd_name(ahd),
'A',
4345 ahd_lookup_phase_entry(
int phase)
4354 last_entry = &ahd_phase_table[num_phases];
4355 for (entry = ahd_phase_table; entry < last_entry; entry++) {
4356 if (phase == entry->
phase)
4386 if ((scb->
hscb->control & TARGET_SCB) != 0)
4412 if (ahd_currently_packetized(ahd))
4421 if ((ahd_debug & AHD_SHOW_MESSAGES) != 0)
4422 printk(
"Setting up for Parity Error delivery\n");
4425 }
else if (scb ==
NULL) {
4426 printk(
"%s: WARNING. No pending message for "
4427 "I_T msgin. Issuing NO-OP\n", ahd_name(ahd));
4457 printk(
"Bus Device Reset Message Sent\n");
4475 printk(
"Abort%s Message Sent\n",
4476 (scb->
hscb->control &
TAG_ENB) != 0 ?
" Tag" :
"");
4486 ahd_build_transfer_msg(ahd, devinfo);
4496 printk(
"ahd_intr: AWAITING_MSG for an SCB that "
4497 "does not have a waiting message\n");
4498 printk(
"SCSIID = %x, target_mask = %x\n", scb->
hscb->scsiid,
4500 panic(
"SCB = %d, SCB Control = %x:%x, MSG_OUT = %x "
4539 devinfo->
target, &tstate);
4546 period = tinfo->
goal.period;
4547 offset = tinfo->
goal.offset;
4548 ppr_options = tinfo->
goal.ppr_options;
4552 ahd_devlimited_syncrate(ahd, tinfo, &period,
4553 &ppr_options, devinfo->
role);
4554 dowide = tinfo->
curr.width != tinfo->
goal.width;
4555 dosync = tinfo->
curr.offset != offset || tinfo->
curr.period !=
period;
4561 doppr = ppr_options != 0;
4563 if (!dowide && !dosync && !doppr) {
4565 dosync = tinfo->
goal.offset != 0;
4568 if (!dowide && !dosync && !doppr) {
4580 printk(
"Ensuring async\n");
4595 if (doppr || (dosync && !dowide)) {
4597 offset = tinfo->
goal.offset;
4598 ahd_validate_offset(ahd, tinfo, period, &offset,
4599 doppr ? tinfo->
goal.width
4600 : tinfo->
curr.width,
4603 ahd_construct_ppr(ahd, devinfo, period, offset,
4604 tinfo->
goal.width, ppr_options);
4606 ahd_construct_sdtr(ahd, devinfo, period, offset);
4609 ahd_construct_wdtr(ahd, devinfo, tinfo->
goal.width);
4627 printk(
"(%s:%c:%d:%d): Sending SDTR period %x, offset %x\n",
4629 devinfo->
lun, period, offset);
4645 printk(
"(%s:%c:%d:%d): Sending WDTR %x\n",
4647 devinfo->
lun, bus_width);
4671 bus_width, ppr_options);
4674 printk(
"(%s:%c:%d:%d): Sending PPR bus_width %x, period %x, "
4675 "offset %x, ppr_options %x\n", ahd_name(ahd),
4677 bus_width, period, offset, ppr_options);
4685 ahd_clear_msg_state(
struct ahd_softc *ahd)
4705 ahd_inb(ahd, SEQ_FLAGS2) & ~TARGET_MSG_PENDING);
4713 ahd_handle_message_phase(
struct ahd_softc *ahd)
4719 ahd_fetch_devinfo(ahd, &devinfo);
4720 end_session =
FALSE;
4723 if ((
ahd_inb(ahd, LQISTAT2) & LQIPHASE_OUTPKT) != 0) {
4724 printk(
"LQIRETRY for LQIPHASE_OUTPKT\n");
4736 panic(
"HOST_MSG_LOOP interrupt with no active message");
4739 if ((ahd_debug & AHD_SHOW_MESSAGES) != 0) {
4741 printk(
"INITIATOR_MSG_OUT");
4747 if ((ahd_debug & AHD_SHOW_MESSAGES) != 0) {
4749 ahd_lookup_phase_entry(bus_phase)
4774 if ((ahd_debug & AHD_SHOW_MESSAGES) != 0)
4800 ahd_assert_atn(ahd);
4815 if ((ahd_debug & AHD_SHOW_MESSAGES) != 0)
4829 if ((ahd_debug & AHD_SHOW_MESSAGES) != 0) {
4831 printk(
"INITIATOR_MSG_IN");
4837 if ((ahd_debug & AHD_SHOW_MESSAGES) != 0) {
4839 ahd_lookup_phase_entry(bus_phase)
4858 if ((ahd_debug & AHD_SHOW_MESSAGES) != 0)
4863 message_done = ahd_parse_msg(ahd, &devinfo);
4879 if ((ahd_debug & AHD_SHOW_MESSAGES) != 0) {
4881 printk(
"Asserting ATN for response\n");
4884 ahd_assert_atn(ahd);
4909 panic(
"Target MSGIN with no active message");
4919 msgout_request =
TRUE;
4921 msgout_request =
FALSE;
4923 if (msgout_request) {
4979 msgdone = ahd_parse_msg(ahd, &devinfo);
5024 panic(
"Unknown REQINIT message type");
5029 printk(
"%s: Returning to Idle Loop\n",
5031 ahd_clear_msg_state(ahd);
5040 ahd_clear_msg_state(ahd);
5061 while (index < ahd->msgout_len) {
5065 end_index = index + 1 + ahd->
msgout_buf[index + 1];
5087 && msgval == MSG_IDENTIFYFLAG)))
5114 devinfo->
target, &tstate);
5140 response = ahd_handle_msg_reject(ahd, devinfo);
5175 saved_offset = offset = ahd->
msgin_buf[4];
5176 ahd_devlimited_syncrate(ahd, tinfo, &period,
5177 &ppr_options, devinfo->
role);
5178 ahd_validate_offset(ahd, tinfo, period, &offset,
5181 printk(
"(%s:%c:%d:%d): Received "
5182 "SDTR period %x, offset %x\n\t"
5183 "Filtered to period %x, offset %x\n",
5184 ahd_name(ahd), devinfo->
channel,
5190 offset, ppr_options,
5201 if (saved_offset != offset) {
5211 printk(
"(%s:%c:%d:%d): Target "
5213 ahd_name(ahd), devinfo->
channel,
5218 ahd_construct_sdtr(ahd, devinfo,
5230 u_int sending_reply;
5232 sending_reply =
FALSE;
5250 ahd_validate_width(ahd, tinfo, &bus_width,
5253 printk(
"(%s:%c:%d:%d): Received WDTR "
5254 "%x filtered to %x\n",
5255 ahd_name(ahd), devinfo->
channel,
5257 saved_width, bus_width);
5267 if (saved_width > bus_width) {
5269 printk(
"(%s:%c:%d:%d): requested %dBit "
5270 "transfers. Rejecting...\n",
5271 ahd_name(ahd), devinfo->
channel,
5273 8 * (0x01 << bus_width));
5282 printk(
"(%s:%c:%d:%d): Target "
5284 ahd_name(ahd), devinfo->
channel,
5289 ahd_construct_wdtr(ahd, devinfo, bus_width);
5292 sending_reply =
TRUE;
5308 if (sending_reply ==
FALSE && reject ==
FALSE) {
5315 ahd_build_transfer_msg(ahd, devinfo);
5330 u_int saved_ppr_options;
5360 saved_ppr_options = ppr_options;
5370 ahd_validate_width(ahd, tinfo, &bus_width,
5372 ahd_devlimited_syncrate(ahd, tinfo, &period,
5373 &ppr_options, devinfo->
role);
5374 ahd_validate_offset(ahd, tinfo, period, &offset,
5375 bus_width, devinfo->
role);
5383 if (saved_width > bus_width
5384 || saved_offset != offset
5385 || saved_ppr_options != ppr_options) {
5394 printk(
"(%s:%c:%d:%d): Target "
5396 ahd_name(ahd), devinfo->
channel,
5399 printk(
"(%s:%c:%d:%d): Initiator "
5401 ahd_name(ahd), devinfo->
channel,
5405 ahd_construct_ppr(ahd, devinfo, period, offset,
5406 bus_width, ppr_options);
5411 printk(
"(%s:%c:%d:%d): Received PPR width %x, "
5412 "period %x, offset %x,options %x\n"
5413 "\tFiltered to width %x, period %x, "
5414 "offset %x, options %x\n",
5415 ahd_name(ahd), devinfo->
channel,
5418 saved_offset, saved_ppr_options,
5419 bus_width, period, offset, ppr_options);
5425 offset, ppr_options,
5439 #ifdef AHD_TARGET_MODE
5443 "Bus Device Reset Received",
5461 tag =
ahd_inb(ahd, INITIATOR_TAG);
5467 if (tstate !=
NULL) {
5468 struct ahd_tmode_lstate* lstate;
5471 if (lstate !=
NULL) {
5472 ahd_queue_lstate_event(ahd, lstate,
5476 ahd_send_lstate_events(ahd, lstate);
5486 if ((ahd_debug & AHD_SHOW_MESSAGES) != 0)
5487 printk(
"%s: QAS request. SCSISIGI == 0x%x\n",
5539 devinfo->
target, &tstate);
5552 printk(
"(%s:%c:%d:%d): PPR Rejected. "
5553 "Trying simple U160 PPR\n",
5554 ahd_name(ahd), devinfo->
channel,
5558 tinfo->
goal.ppr_options &= MSG_EXT_PPR_IU_REQ
5567 printk(
"(%s:%c:%d:%d): PPR Rejected. "
5568 "Trying WDTR/SDTR\n",
5569 ahd_name(ahd), devinfo->
channel,
5572 tinfo->
goal.ppr_options = 0;
5573 tinfo->
curr.transport_version = 2;
5574 tinfo->
goal.transport_version = 2;
5578 ahd_build_transfer_msg(ahd, devinfo);
5584 printk(
"(%s:%c:%d:%d): refuses WIDE negotiation. Using "
5585 "8bit transfers\n", ahd_name(ahd),
5597 if (tinfo->
goal.offset != tinfo->
curr.offset) {
5602 ahd_build_transfer_msg(ahd, devinfo);
5612 printk(
"(%s:%c:%d:%d): refuses synchronous negotiation. "
5613 "Using asynchronous transfers\n",
5614 ahd_name(ahd), devinfo->
channel,
5623 printk(
"(%s:%c:%d:%d): refuses tagged commands. "
5624 "Performing non-tagged I/O\n", ahd_name(ahd),
5629 printk(
"(%s:%c:%d:%d): refuses %s tagged commands. "
5630 "Performing simple queue tagged I/O only\n",
5633 ?
"ordered" :
"head of queue");
5645 ahd_set_transaction_tag(scb,
FALSE,
5648 ahd_assert_atn(ahd);
5670 ahd_force_renegotiation(ahd, devinfo);
5673 ahd_build_transfer_msg(ahd, devinfo);
5680 printk(
"%s:%c:%d: Message reject for %x -- ignored\n",
5703 || ahd_get_transfer_dir(scb) !=
CAM_DIR_IN) {
5719 if ((sgptr & SG_LIST_NULL) != 0
5721 & SCB_XFERLEN_ODD) != 0) {
5734 sgptr = ahd_inl_scbram(ahd, SCB_RESIDUAL_SGPTR);
5735 data_cnt = ahd_inl_scbram(ahd, SCB_RESIDUAL_DATACNT);
5736 if ((sgptr & SG_LIST_NULL) != 0) {
5742 data_cnt &= ~AHD_SG_LEN_MASK;
5751 sg = ahd_sg_bus_to_virt(ahd, scb, sgptr);
5760 && sglen < (data_cnt & AHD_SG_LEN_MASK)) {
5768 data_cnt = 1|(sglen&(~AHD_SG_LEN_MASK));
5778 sgptr = ahd_sg_virt_to_bus(ahd, scb,
5784 sg = ahd_sg_bus_to_virt(ahd, scb, sgptr);
5793 && sglen < (data_cnt & AHD_SG_LEN_MASK)) {
5801 data_cnt = 1|(sglen&(~AHD_SG_LEN_MASK));
5811 sgptr = ahd_sg_virt_to_bus(ahd, scb,
5825 ahd_outl(ahd, SCB_RESIDUAL_SGPTR, sgptr);
5826 ahd_outl(ahd, SCB_RESIDUAL_DATACNT, data_cnt);
5841 ahd_reinitialize_dataptrs(
struct ahd_softc *ahd)
5863 while (--wait && !(
ahd_inb(ahd, MDFFSTAT) & FIFOFREE))
5867 printk(
"ahd_reinitialize_dataptrs: Forcing FIFO free.\n");
5868 ahd_outb(ahd, DFFSXFRCTL, RSTCHN|CLRSHCNT);
5874 | (saved_modes == 0x11 ? CURRFIFO_1 : CURRFIFO_0));
5880 sgptr = ahd_inl_scbram(ahd, SCB_RESIDUAL_SGPTR);
5890 sg = ahd_sg_bus_to_virt(ahd, scb, sgptr);
5902 sg = ahd_sg_bus_to_virt(ahd, scb, sgptr);
5927 #ifdef AHD_TARGET_MODE
5932 found = ahd_abort_scbs(ahd, devinfo->
target, devinfo->
channel,
5936 #ifdef AHD_TARGET_MODE
5942 if (tstate !=
NULL) {
5953 for (;cur_lun <= max_lun; cur_lun++) {
5954 struct ahd_tmode_lstate* lstate;
5960 ahd_queue_lstate_event(ahd, lstate, devinfo->
our_scsiid,
5962 ahd_send_lstate_events(ahd, lstate);
5981 printk(
"%s: %s on %c:%d. %d SCBs aborted\n", ahd_name(ahd),
5985 #ifdef AHD_TARGET_MODE
6000 ahd_build_transfer_msg(ahd, devinfo);
6002 panic(
"ahd_intr: AWAITING target message with no message");
6027 ahd_sglist_allocsize(
struct ahd_softc *ahd)
6035 sg_list_increment = ahd_sglist_size(ahd);
6036 sg_list_size = sg_list_increment;
6039 while ((sg_list_size + sg_list_increment) <=
PAGE_SIZE)
6040 sg_list_size += sg_list_increment;
6046 best_list_size = sg_list_size;
6052 while ((sg_list_size + sg_list_increment) <= max_list_size
6057 sg_list_size += sg_list_increment;
6060 if (new_mod > best_mod || new_mod == 0) {
6061 best_list_size = sg_list_size;
6064 return (best_list_size);
6079 printk(
"aic7xxx: cannot malloc softc!\n");
6084 ahd = device_get_softc((
device_t)platform_arg);
6086 memset(ahd, 0,
sizeof(*ahd));
6121 if ((ahd_debug & AHD_SHOW_MEMORY) != 0) {
6122 printk(
"%s: scb size = 0x%x, hscb size = 0x%x\n",
6123 ahd_name(ahd), (
u_int)
sizeof(
struct scb),
6188 ahd_fini_scbdata(ahd);
6193 if (tstate !=
NULL) {
6194 #ifdef AHD_TARGET_MODE
6198 struct ahd_tmode_lstate *lstate;
6201 if (lstate !=
NULL) {
6202 xpt_free_path(lstate->path);
6210 #ifdef AHD_TARGET_MODE
6229 ahd_shutdown(
void *
arg)
6267 ahd_update_modes(ahd);
6302 printk(
"%s: WARNING - Failed chip reset! "
6303 "Trying to initialize anyway.\n", ahd_name(ahd));
6368 for (j = 2; j < 64; j++)
6391 ahd_initialize_hscbs(
struct ahd_softc *ahd)
6395 for (i = 0; i < ahd->
scb_data.maxhscbs; i++) {
6422 scb_data->
maxhscbs = ahd_probe_scbs(ahd);
6424 printk(
"%s: No SCB space found\n", ahd_name(ahd));
6428 ahd_initialize_hscbs(ahd);
6460 ahd_sglist_allocsize(ahd), 1,
6462 0, &scb_data->
sg_dmat) != 0) {
6466 if ((ahd_debug & AHD_SHOW_MEMORY) != 0)
6467 printk(
"%s: ahd_sglist_allocsize = 0x%x\n", ahd_name(ahd),
6468 ahd_sglist_allocsize(ahd));
6488 ahd_alloc_scbs(ahd);
6491 printk(
"%s: ahd_init_scbdata - "
6492 "Unable to allocate initial scbs\n",
6524 struct scb *list_scb;
6548 struct scb_data *scb_data;
6551 if (scb_data ==
NULL)
6615 ahd_setup_iocell_workaround(
struct ahd_softc *ahd)
6622 | BYPASSENAB | RCVROFFSTDIS | XMITOFFSTDIS);
6625 if ((ahd_debug & AHD_SHOW_MISC) != 0)
6626 printk(
"%s: Setting up iocell workaround\n", ahd_name(ahd));
6633 ahd_iocell_first_selection(
struct ahd_softc *ahd)
6645 if ((ahd_debug & AHD_SHOW_MISC) != 0)
6646 printk(
"%s: iocell first selection\n", ahd_name(ahd));
6648 if ((sblkctl & ENAB40) != 0) {
6650 ahd_inb(ahd, DSPDATACTL) & ~BYPASSENAB);
6652 if ((ahd_debug & AHD_SHOW_MISC) != 0)
6653 printk(
"%s: BYPASS now disabled\n", ahd_name(ahd));
6664 ahd_add_col_list(
struct ahd_softc *ahd,
struct scb *scb,
u_int col_idx)
6667 struct scb_tailq *free_tailq;
6668 struct scb *first_scb;
6672 free_list = &ahd->
scb_data.free_scb_lists[col_idx];
6673 free_tailq = &ahd->
scb_data.free_scbs;
6675 if (first_scb !=
NULL) {
6684 ahd_rem_col_list(
struct ahd_softc *ahd,
struct scb *scb)
6686 struct scb_list *free_list;
6687 struct scb_tailq *free_tailq;
6688 struct scb *first_scb;
6693 free_list = &ahd->
scb_data.free_scb_lists[col_idx];
6694 free_tailq = &ahd->
scb_data.free_scbs;
6696 if (first_scb == scb) {
6705 if (next_scb !=
NULL) {
6707 next_scb,
links.tqe);
6727 ahd_rem_col_list(ahd, scb);
6735 ahd_alloc_scbs(ahd);
6743 ahd_add_col_list(ahd, scb->
col_scb, col_idx);
6758 scb->
hscb->control = 0;
6775 ahd_rem_col_list(ahd, scb->
col_scb);
6780 }
else if ((scb->
col_scb->flags
6789 ahd_add_col_list(ahd, scb,
6802 ahd_platform_scb_free(ahd, scb);
6808 struct scb_data *scb_data;
6833 hscb_busaddr = hscb_map->
physaddr + (offset *
sizeof(*hscb));
6837 if (hscb_map ==
NULL)
6842 (
void **)&hscb_map->
vaddr,
6862 offset = ((ahd_sglist_allocsize(ahd) / ahd_sglist_size(ahd))
6863 - scb_data->
sgs_left) * ahd_sglist_size(ahd);
6875 (
void **)&sg_map->
vaddr,
6884 sg_map->
vaddr, ahd_sglist_allocsize(ahd),
6885 ahd_dmamap_cb, &sg_map->
physaddr, 0);
6887 segs = sg_map->
vaddr;
6890 ahd_sglist_allocsize(ahd) / ahd_sglist_size(ahd);
6892 if (ahd_debug & AHD_SHOW_MEMORY)
6893 printk(
"Mapped SG data\n");
6902 sense_data = sense_map->vaddr +
offset;
6903 sense_busaddr = sense_map->physaddr +
offset;
6907 if (sense_map ==
NULL)
6912 (
void **)&sense_map->
vaddr,
6924 sense_data = sense_map->
vaddr;
6925 sense_busaddr = sense_map->
physaddr;
6928 if (ahd_debug & AHD_SHOW_MEMORY)
6929 printk(
"Mapped sense data\n");
6936 for (i = 0; i < newcount; i++) {
6944 if (next_scb ==
NULL)
6948 if (pdata ==
NULL) {
6954 next_scb->
sg_map = sg_map;
6959 memset(hscb, 0,
sizeof(*hscb));
6960 next_scb->
hscb = hscb;
6976 error = ahd_dmamap_create(ahd, ahd->
buffer_dmat, 0,
6985 col_tag = scb_data->
numscbs ^ 0x100;
6986 next_scb->
col_scb = ahd_find_scb_by_tag(ahd, col_tag);
6991 hscb_busaddr +=
sizeof(*hscb);
6992 segs += ahd_sglist_size(ahd);
6993 sg_busaddr += ahd_sglist_size(ahd);
6994 sense_data += AHD_SENSE_BUFSIZE;
6995 sense_busaddr += AHD_SENSE_BUFSIZE;
7013 speed =
"Ultra320 ";
7019 len =
sprintf(buf,
"%s%sChannel %c, SCSI Id=%d, ",
7027 static const char *channel_strings[] = {
7034 static const char *termstat_strings[] = {
7035 "Terminated Correctly",
7042 #define ahd_timer_init init_timer
7043 #define ahd_timer_stop del_timer_sync
7067 size_t driver_data_size;
7086 panic(
"Hardware SCB size is incorrect");
7089 if ((ahd_debug & AHD_DEBUG_SEQUENCER) != 0)
7131 driver_data_size = AHD_SCB_MAX *
sizeof(*ahd->
qoutfifo)
7136 driver_data_size += PKT_OVERRUN_BUFSIZE;
7138 BUS_SPACE_MAXADDR_32BIT + 1,
7139 BUS_SPACE_MAXADDR_32BIT,
7178 next_vaddr += PKT_OVERRUN_BUFSIZE;
7179 next_baddr += PKT_OVERRUN_BUFSIZE;
7196 if (ahd_init_scbdata(ahd) != 0)
7223 printk(
"%s: current sensing timeout 1\n", ahd_name(ahd));
7230 printk(
"%s: current sensing timeout 2\n",
7236 printk(
"%s: Timedout during current-sensing test\n",
7244 printk(
"%s: current sensing timeout 3\n", ahd_name(ahd));
7252 if ((ahd_debug & AHD_SHOW_TERMCTL) != 0) {
7253 printk(
"%s: current_sensing == 0x%x\n",
7254 ahd_name(ahd), current_sensing);
7262 switch (term_stat) {
7270 printk(
"%s: %s Channel %s\n", ahd_name(ahd),
7271 channel_strings[i], termstat_strings[term_stat]);
7276 printk(
"%s: WARNING. Termination is not configured correctly.\n"
7277 "%s: WARNING. SCSI bus operations may FAIL.\n",
7278 ahd_name(ahd), ahd_name(ahd));
7283 ahd_stat_timer, ahd);
7295 u_int scsiseq_template;
7318 && (ahd->
seltime != STIMESEL_MIN)) {
7324 sxfrctl1 |= ahd->
seltime + STIMESEL_BUG_ADJ;
7350 for (i = 0; i < 2; i++) {
7356 ENSAVEPTRS|ENCFG4DATA|ENCFG4ISTAT
7357 |ENCFG4TSTAT|ENCFG4ICMD|ENCFG4TCMD);
7364 ahd_outb(ahd, SIMODE3, ENNTRAMPERR|ENOSRAMPERR);
7370 ahd_outb(ahd, SCSCHKN, CURRFIFODEF|WIDERESEN|SHVALIDSTDIS);
7380 ahd_outb(ahd, LQOSCSCTL, LQONOCHKOVER);
7386 for (i = 0; i < NUMDSPS; i++) {
7388 ahd_outb(ahd, WRTBIASCTL, WRTBIASCTL_HP_DEFAULT);
7391 if ((ahd_debug & AHD_SHOW_MISC) != 0)
7392 printk(
"%s: WRTBIASCTL now 0x%x\n", ahd_name(ahd),
7393 WRTBIASCTL_HP_DEFAULT);
7396 ahd_setup_iocell_workaround(ahd);
7401 ahd_outb(ahd, LQIMODE1, ENLQIPHASE_LQ|ENLQIPHASE_NLQ|ENLIQABORT
7402 | ENLQICRCI_LQ|ENLQICRCI_NLQ|ENLQIBADLQI
7403 | ENLQIOVERI_LQ|ENLQIOVERI_NLQ);
7404 ahd_outb(ahd, LQOMODE0, ENLQOATNLQ|ENLQOATNPKT|ENLQOTCRC);
7413 ahd_outb(ahd, LQOMODE1, ENLQOBUSFREE);
7418 ahd_outw(ahd, INTVEC1_ADDR, ahd_resolve_seqaddr(ahd, LABEL_seq_isr));
7419 ahd_outw(ahd, INTVEC2_ADDR, ahd_resolve_seqaddr(ahd, LABEL_timer_isr));
7437 ahd_outb(ahd, ABRTBITPTR, MK_MESSAGE_BIT_OFFSET);
7443 ahd_outb(ahd, LUNLEN, LUNLEN_SINGLE_LEVEL_LUN);
7445 ahd_outb(ahd, CDBLIMIT, SCB_CDB_LEN_PTR - 1);
7463 ahd_outb(ahd, ANNEXCOL, AHD_ANNEXCOL_PER_DEV0);
7464 for (i = 0; i < AHD_NUM_PER_DEV_ANNEXCOLS; i++)
7478 ahd_update_neg_table(ahd, &devinfo, &tinfo->
curr);
7481 ahd_outb(ahd, CLRSINT3, NTRAMPERR|OSRAMPERR);
7484 #ifdef NEEDS_MORE_TESTING
7490 ahd_outb(ahd, LQCTL1, ABORTPENDING);
7525 ahd_outw(ahd, MK_MESSAGE_SCSIID, 0xFF);
7543 ahd_outw(ahd, KERNEL_QFREEZE_COUNT, 0);
7549 ahd_outl(ahd, SHARED_DATA_ADDR, busaddr);
7550 ahd_outl(ahd, QOUTFIFO_NEXT_ADDR, busaddr);
7560 ahd_outb(ahd, SCSISEQ_TEMPLATE, scsiseq_template);
7577 ahd_outb(ahd, CMDSIZE_TABLE + 1, 9);
7578 ahd_outb(ahd, CMDSIZE_TABLE + 2, 9);
7579 ahd_outb(ahd, CMDSIZE_TABLE + 3, 0);
7580 ahd_outb(ahd, CMDSIZE_TABLE + 4, 15);
7581 ahd_outb(ahd, CMDSIZE_TABLE + 5, 11);
7582 ahd_outb(ahd, CMDSIZE_TABLE + 6, 0);
7583 ahd_outb(ahd, CMDSIZE_TABLE + 7, 0);
7590 ahd_set_hescb_qoff(ahd, 0);
7591 ahd_set_snscb_qoff(ahd, 0);
7592 ahd_set_sescb_qoff(ahd, 0);
7593 ahd_set_sdscb_qoff(ahd, 0);
7599 ahd_outl(ahd, NEXT_QUEUED_SCB_ADDR, busaddr);
7604 ahd_outw(ahd, INT_COALESCING_CMDCOUNT, 0);
7609 ahd_enable_coalescing(ahd,
FALSE);
7617 negodat3 |= ENSLOWCRC;
7618 ahd_outb(ahd, NEGCONOPTS, negodat3);
7619 negodat3 =
ahd_inb(ahd, NEGCONOPTS);
7620 if (!(negodat3 & ENSLOWCRC))
7621 printk(
"aic79xx: failed to set the SLOWCRC bit\n");
7623 printk(
"aic79xx: SLOWCRC bit set\n");
7644 if (ahd_alloc_tstate(ahd, ahd->
our_id,
'A') ==
NULL) {
7645 printk(
"%s: unable to allocate ahd_tmode_tstate. "
7646 "Failing attach\n", ahd_name(ahd));
7661 tinfo->
user.protocol_version = 4;
7662 tinfo->
user.transport_version = 4;
7664 target_mask = 0x01 << targ;
7668 #ifdef AHD_FORCE_160
7677 | MSG_EXT_PPR_IU_REQ
7689 tinfo->
goal.protocol_version = 2;
7690 tinfo->
goal.transport_version = 2;
7691 tinfo->
curr.protocol_version = 2;
7692 tinfo->
curr.transport_version = 2;
7723 if (ahd_alloc_tstate(ahd, ahd->
our_id,
'A') ==
NULL) {
7724 printk(
"%s: unable to allocate ahd_tmode_tstate. "
7725 "Failing attach\n", ahd_name(ahd));
7729 for (targ = 0; targ < max_targ; targ++) {
7738 user_tinfo = &tinfo->
user;
7743 tinfo->
user.protocol_version = 4;
7744 tinfo->
user.transport_version = 4;
7746 target_mask = 0x01 << targ;
7771 #ifdef AHD_FORCE_160
7793 if ((ahd_debug & AHD_SHOW_MISC) != 0)
7794 printk(
"(%d): %x:%x:%x:%x\n", targ, user_tinfo->
width,
7803 tinfo->
goal.protocol_version = 2;
7804 tinfo->
goal.transport_version = 2;
7805 tinfo->
curr.protocol_version = 2;
7806 tinfo->
curr.transport_version = 2;
7848 error = ahd_verify_vpd_cksum(vpd);
7877 if (timer > AHD_TIMER_MAX_US)
7878 timer = AHD_TIMER_MAX_US;
7886 ahd_outw(ahd, INT_COALESCING_TIMER, timer / AHD_TIMER_US_PER_TICK);
7887 ahd_outb(ahd, INT_COALESCING_MAXCMDS, -maxcmds);
7888 ahd_outb(ahd, INT_COALESCING_MINCMDS, -mincmds);
7899 ahd_flush_device_writes(ahd);
7900 ahd_run_qoutfifo(ahd);
7926 ahd_outb(ahd, SEQ_FLAGS2,
ahd_inb(ahd, SEQ_FLAGS2) | SELECTOUT_QFROZEN);
7940 ahd_clear_critical_section(ahd);
7946 || (
ahd_inb(ahd, SCSISEQ0) & ENSELO) != 0
7949 if (maxloops == 0) {
7950 printk(
"Infinite interrupt loop, INTSTAT = %x",
7956 ahd_flush_qoutfifo(ahd);
8024 scb_offset = ahd_index_busy_tcl(ahd, &saved_scbptr, tcl);
8036 scb_offset = ahd_index_busy_tcl(ahd, &saved_scbptr, tcl);
8043 ahd_match_scb(
struct ahd_softc *ahd,
struct scb *scb,
int target,
8057 #ifdef AHD_TARGET_MODE
8060 group = XPT_FC_GROUP(scb->
io_ctx->ccb_h.func_code);
8062 match = (group != XPT_FC_GROUP_TMODE)
8066 match = (group == XPT_FC_GROUP_TMODE)
8067 && ((tag == scb->
io_ctx->csio.tag_id)
8079 ahd_freeze_devq(
struct ahd_softc *ahd,
struct scb *scb)
8099 struct scb *prev_scb;
8105 if (ahd_qinfifo_count(ahd) != 0) {
8110 prev_tag = ahd->
qinfifo[prev_pos];
8113 ahd_qinfifo_requeue(ahd, prev_scb, scb);
8119 ahd_qinfifo_requeue(
struct ahd_softc *ahd,
struct scb *prev_scb,
8122 if (prev_scb ==
NULL) {
8126 ahd_outl(ahd, NEXT_QUEUED_SCB_ADDR, busaddr);
8128 prev_scb->
hscb->next_hscb_busaddr = scb->
hscb->hscb_busaddr;
8129 ahd_sync_scb(ahd, prev_scb,
8139 ahd_qinfifo_count(
struct ahd_softc *ahd)
8143 u_int wrap_qinfifonext;
8146 qinpos = ahd_get_snscb_qoff(ahd);
8149 if (wrap_qinfifonext >= wrap_qinpos)
8150 return (wrap_qinfifonext - wrap_qinpos);
8152 return (wrap_qinfifonext
8157 ahd_reset_cmds_pending(
struct ahd_softc *ahd)
8170 ahd_flush_qoutfifo(ahd);
8176 ahd_outw(ahd, CMDS_PENDING, pending_cmds - ahd_qinfifo_count(ahd));
8187 ostat = ahd_get_transaction_status(scb);
8189 ahd_set_transaction_status(scb, status);
8190 cstat = ahd_get_transaction_status(scb);
8192 ahd_freeze_scb(scb);
8202 struct scb *mk_msg_scb;
8203 struct scb *prev_scb;
8234 qinstart = ahd_get_snscb_qoff(ahd);
8240 printk(
"qinstart = %d qinfifonext = %d\nQINFIFO:",
8250 ahd_outl(ahd, NEXT_QUEUED_SCB_ADDR, busaddr);
8252 while (qinpos != qintail) {
8255 printk(
"qinpos = %d, SCB index = %d\n",
8256 qinpos, ahd->
qinfifo[qinpos]);
8260 if (ahd_match_scb(ahd, scb, target, channel, lun, tag, role)) {
8268 printk(
"Inactive SCB in qinfifo\n");
8269 ahd_done_with_status(ahd, scb, status);
8277 ahd_qinfifo_requeue(ahd, prev_scb, scb);
8282 ahd_qinfifo_requeue(ahd, prev_scb, scb);
8291 printk(
"\nWAITING_TID_QUEUES:\n");
8300 seq_flags2 =
ahd_inb(ahd, SEQ_FLAGS2);
8301 if ((seq_flags2 & PENDING_MK_MESSAGE) != 0) {
8302 scbid =
ahd_inw(ahd, MK_MESSAGE_SCB);
8307 tid_next =
ahd_inw(ahd, WAITING_TID_HEAD);
8310 for (scbid = tid_next; !
SCBID_IS_NULL(scbid); scbid = tid_next) {
8315 if (targets > AHD_NUM_TARGETS)
8316 panic(
"TID LIST LOOP");
8318 if (scbid >= ahd->
scb_data.numscbs) {
8319 printk(
"%s: Waiting TID List inconsistency. "
8320 "SCB index == 0x%x, yet numscbs == 0x%x.",
8321 ahd_name(ahd), scbid, ahd->
scb_data.numscbs);
8323 panic(
"for safety");
8327 printk(
"%s: SCB = 0x%x Not Active!\n",
8328 ahd_name(ahd), scbid);
8329 panic(
"Waiting TID List traversal\n");
8345 found += ahd_search_scb_list(ahd, target, channel,
8346 lun, tag, role, status,
8347 action, &tid_head, &tid_tail,
8353 if (mk_msg_scb !=
NULL
8354 && ahd_match_scb(ahd, mk_msg_scb, target, channel,
8364 printk(
"Inactive SCB pending MK_MSG\n");
8365 ahd_done_with_status(ahd, mk_msg_scb, status);
8371 printk(
"Removing MK_MSG scb\n");
8377 tail_offset = WAITING_SCB_TAILS
8379 ahd_outw(ahd, tail_offset, tid_tail);
8381 seq_flags2 &= ~PENDING_MK_MESSAGE;
8382 ahd_outb(ahd, SEQ_FLAGS2, seq_flags2);
8384 ahd_inw(ahd, CMDS_PENDING)-1);
8396 if (mk_msg_scb !=
NULL
8406 printk(
"Queueing mk_msg_scb\n");
8407 tid_head =
ahd_inw(ahd, MK_MESSAGE_SCB);
8408 seq_flags2 &= ~PENDING_MK_MESSAGE;
8409 ahd_outb(ahd, SEQ_FLAGS2, seq_flags2);
8412 if (tid_head != scbid)
8413 ahd_stitch_tid_list(ahd, tid_prev, tid_head, tid_next);
8415 tid_prev = tid_head;
8427 ahd_search_scb_list(
struct ahd_softc *ahd,
int target,
char channel,
8444 if (scbid >= ahd->
scb_data.numscbs) {
8445 printk(
"%s:SCB List inconsistency. "
8446 "SCB == 0x%x, yet numscbs == 0x%x.",
8447 ahd_name(ahd), scbid, ahd->
scb_data.numscbs);
8449 panic(
"for safety");
8453 printk(
"%s: SCB = %d Not Active!\n",
8454 ahd_name(ahd), scbid);
8455 panic(
"Waiting List traversal\n");
8460 if (ahd_match_scb(ahd, scb, target, channel,
8469 printk(
"Inactive SCB in Waiting List\n");
8470 ahd_done_with_status(ahd, scb, status);
8473 ahd_rem_wscb(ahd, scbid, prev, next, tid);
8484 if (found > AHD_SCB_MAX)
8485 panic(
"SCB LIST LOOP");
8503 ahd_outw(ahd, WAITING_TID_HEAD, tid_next);
8506 ahd_outw(ahd, SCB_NEXT2, tid_next);
8509 ahd_outw(ahd, WAITING_TID_TAIL, tid_prev);
8514 ahd_outw(ahd, WAITING_TID_HEAD, tid_cur);
8520 ahd_outw(ahd, SCB_NEXT2, tid_next);
8523 ahd_outw(ahd, WAITING_TID_TAIL, tid_cur);
8550 tail_offset = WAITING_SCB_TAILS + (2 * tid);
8552 &&
ahd_inw(ahd, tail_offset) == scbid)
8555 ahd_add_scb_to_free_list(ahd, scbid);
8583 ahd_abort_scbs(
struct ahd_softc *ahd,
int target,
char channel,
8587 struct scb *scbp_next;
8617 }
else if (lun >= AHD_NUM_LUNS_NONPKT) {
8618 minlun = maxlun = 0;
8625 for (;i < maxtarget; i++) {
8626 for (j = minlun;j < maxlun; j++) {
8631 scbid = ahd_find_busy_tcl(ahd, tcl);
8634 || ahd_match_scb(ahd, scbp, target, channel,
8635 lun, tag, role) == 0)
8646 ahd_flush_qoutfifo(ahd);
8655 while (scbp_next !=
NULL) {
8658 if (ahd_match_scb(ahd, scbp, target, channel, lun, tag, role)) {
8661 ostat = ahd_get_transaction_status(scbp);
8663 ahd_set_transaction_status(scbp, status);
8664 if (ahd_get_transaction_status(scbp) !=
CAM_REQ_CMP)
8665 ahd_freeze_scb(scbp);
8667 printk(
"Inactive SCB on pending list\n");
8679 ahd_reset_current_bus(
struct ahd_softc *ahd)
8687 ahd_flush_device_writes(ahd);
8691 ahd_flush_device_writes(ahd);
8705 ahd_clear_intstat(ahd);
8724 printk(
"%s: bus reset still active\n",
8740 ahd_clear_critical_section(ahd);
8747 ahd_run_qoutfifo(ahd);
8748 #ifdef AHD_TARGET_MODE
8750 ahd_run_tqinfifo(ahd,
TRUE);
8767 next_fifo = fifo =
ahd_inb(ahd, DFFSTAT) & CURRFIFO;
8768 if (next_fifo > CURRFIFO_1)
8770 next_fifo = fifo = 0;
8772 next_fifo ^= CURRFIFO_1;
8783 }
while (next_fifo != fifo);
8788 ahd_clear_msg_state(ahd);
8793 ahd_reset_current_bus(ahd);
8795 ahd_clear_intstat(ahd);
8808 ahd_clear_fifo(ahd, 0);
8809 ahd_clear_fifo(ahd, 1);
8820 scsiseq =
ahd_inb(ahd, SCSISEQ_TEMPLATE);
8824 #ifdef AHD_TARGET_MODE
8829 for (target = 0; target <= max_scsiid; target++) {
8837 struct ahd_tmode_lstate* lstate;
8845 ahd_send_lstate_events(ahd, lstate);
8852 for (target = 0; target <= max_scsiid; target++) {
8856 for (initiator = 0; initiator <= max_scsiid; initiator++) {
8881 ahd_stat_timer(
void *
arg)
8889 enint_coal = ahd->
hs_mailbox & ENINT_COALESCE;
8891 enint_coal |= ENINT_COALESCE;
8893 enint_coal &= ~ENINT_COALESCE;
8895 if (enint_coal != (ahd->
hs_mailbox & ENINT_COALESCE)) {
8896 ahd_enable_coalescing(ahd, enint_coal);
8898 if ((ahd_debug & AHD_SHOW_INT_COALESCING) != 0)
8899 printk(
"%s: Interrupt coalescing "
8900 "now %sabled. Cmds %d\n",
8902 (enint_coal & ENINT_COALESCE) ?
"en" :
"dis",
8911 ahd_stat_timer, ahd);
8912 ahd_unlock(ahd, &s);
8918 ahd_handle_scsi_status(
struct ahd_softc *ahd,
struct scb *scb)
8942 ahd_freeze_devq(ahd, scb);
8943 ahd_freeze_scb(scb);
8964 case STATUS_PKT_SENSE:
8970 ahd_set_scsi_status(scb, siu->
status);
8972 if ((ahd_debug & AHD_SHOW_SENSE) != 0) {
8974 printk(
"SCB 0x%x Received PKT Status of 0x%x\n",
8976 printk(
"\tflags = 0x%x, sense len = 0x%x, "
8985 printk(
"Unable to parse pkt_failures\n");
8990 printk(
"No packet failure found\n");
8993 printk(
"Invalid Command IU Field\n");
8996 printk(
"TMF not supported\n");
9002 printk(
"Invalid L_Q Type code\n");
9005 printk(
"Illegal request\n");
9011 ahd_set_transaction_status(scb,
9017 if ((ahd_debug & AHD_SHOW_SENSE) != 0)
9018 printk(
"Sense data available\n");
9034 if (ahd_debug & AHD_SHOW_SENSE) {
9036 printk(
"SCB %d: requests Check Status\n",
9041 if (ahd_perform_autosense(scb) == 0)
9054 tinfo = &targ_info->
curr;
9060 ahd_update_residual(ahd, scb);
9062 if (ahd_debug & AHD_SHOW_SENSE) {
9064 printk(
"Sending Sense\n");
9068 sg =
ahd_sg_setup(ahd, scb, sg, ahd_get_sense_bufaddr(ahd, scb),
9069 ahd_get_sense_bufsize(ahd, scb),
9078 sc->
length = ahd_get_sense_bufsize(ahd, scb);
9098 if (ahd_get_residual(scb) == ahd_get_transfer_length(scb)) {
9110 ahd_setup_data_scb(ahd, scb);
9116 printk(
"%s: Interrupted for status of 0???\n",
9126 ahd_handle_scb_status(
struct ahd_softc *ahd,
struct scb *scb)
9128 if (scb->
hscb->shared_data.istatus.scsi_status != 0) {
9129 ahd_handle_scsi_status(ahd, scb);
9131 ahd_calc_residual(ahd, scb);
9140 ahd_calc_residual(
struct ahd_softc *ahd,
struct scb *scb)
9166 if ((sgptr & SG_STATUS_VALID) == 0)
9169 sgptr &= ~SG_STATUS_VALID;
9171 if ((sgptr & SG_LIST_NULL) != 0)
9183 if ((sgptr & SG_FULL_RESID) != 0) {
9185 resid = ahd_get_transfer_length(scb);
9186 }
else if ((resid_sgptr & SG_LIST_NULL) != 0) {
9189 }
else if ((resid_sgptr & SG_OVERRUN_RESID) != 0) {
9191 printk(
"data overrun detected Tag == 0x%x.\n",
9193 ahd_freeze_devq(ahd, scb);
9195 ahd_freeze_scb(scb);
9198 panic(
"Bogus resid sgptr value 0x%x\n", resid_sgptr);
9208 sg = ahd_sg_bus_to_virt(ahd, scb, resid_sgptr &
SG_PTR_MASK);
9224 ahd_set_residual(scb, resid);
9226 ahd_set_sense_residual(scb, resid);
9229 if ((ahd_debug & AHD_SHOW_MISC) != 0) {
9231 printk(
"Handled %sResidual of %d bytes\n",
9238 #ifdef AHD_TARGET_MODE
9243 ahd_queue_lstate_event(
struct ahd_softc *ahd,
struct ahd_tmode_lstate *lstate,
9249 xpt_freeze_devq(lstate->path, 1);
9250 if (lstate->event_w_idx >= lstate->event_r_idx)
9251 pending = lstate->event_w_idx - lstate->event_r_idx;
9254 - (lstate->event_r_idx - lstate->event_w_idx);
9264 lstate->event_r_idx = 0;
9265 lstate->event_w_idx = 0;
9266 xpt_release_devq(lstate->path, pending,
FALSE);
9270 xpt_print_path(lstate->path);
9271 printk(
"immediate event %x:%x lost\n",
9272 lstate->event_buffer[lstate->event_r_idx].event_type,
9273 lstate->event_buffer[lstate->event_r_idx].event_arg);
9274 lstate->event_r_idx++;
9276 lstate->event_r_idx = 0;
9277 xpt_release_devq(lstate->path, 1,
FALSE);
9280 event = &lstate->event_buffer[lstate->event_w_idx];
9284 lstate->event_w_idx++;
9286 lstate->event_w_idx = 0;
9294 ahd_send_lstate_events(
struct ahd_softc *ahd,
struct ahd_tmode_lstate *lstate)
9296 struct ccb_hdr *ccbh;
9297 struct ccb_immed_notify *inot;
9299 while (lstate->event_r_idx != lstate->event_w_idx
9303 event = &lstate->event_buffer[lstate->event_r_idx];
9305 inot = (
struct ccb_immed_notify *)ccbh;
9312 inot->message_args[0] =
event->event_type;
9313 inot->message_args[1] =
event->event_arg;
9316 inot->initiator_id =
event->initiator_id;
9317 inot->sense_len = 0;
9318 xpt_done((
union ccb *)inot);
9319 lstate->event_r_idx++;
9321 lstate->event_r_idx = 0;
9339 for (i = 0; i < max_prog; i++) {
9343 printk(
"0x%08x\n", ins_bytes[0] << 24
9344 | ins_bytes[1] << 16
9354 struct cs cs_table[num_critical_sections];
9355 u_int begin_set[num_critical_sections];
9356 u_int end_set[num_critical_sections];
9357 const struct patch *cur_patch;
9363 u_int sg_prefetch_cnt;
9364 u_int sg_prefetch_cnt_limit;
9365 u_int sg_prefetch_align;
9367 u_int cacheline_mask;
9368 uint8_t download_consts[DOWNLOAD_CONST_COUNT];
9371 printk(
"%s: Downloading Sequencer Program...",
9374 #if DOWNLOAD_CONST_COUNT != 8
9375 #error "Download Const Mismatch"
9383 memset(begin_set, 0,
sizeof(begin_set));
9384 memset(end_set, 0,
sizeof(end_set));
9405 if (sg_prefetch_align == 0)
9406 sg_prefetch_align = 8;
9408 while (
powerof2(sg_prefetch_align) == 0)
9409 sg_prefetch_align--;
9411 cacheline_mask = sg_prefetch_align - 1;
9421 sg_prefetch_cnt = sg_prefetch_align;
9429 while (sg_prefetch_cnt < sg_size)
9430 sg_prefetch_cnt += sg_prefetch_align;
9436 if ((sg_prefetch_align % sg_size) != 0
9438 sg_prefetch_cnt += sg_prefetch_align;
9444 sg_prefetch_cnt_limit = -(sg_prefetch_cnt - sg_size + 1);
9445 download_consts[SG_PREFETCH_CNT] = sg_prefetch_cnt;
9446 download_consts[SG_PREFETCH_CNT_LIMIT] = sg_prefetch_cnt_limit;
9447 download_consts[SG_PREFETCH_ALIGN_MASK] = ~(sg_prefetch_align - 1);
9448 download_consts[SG_PREFETCH_ADDR_MASK] = (sg_prefetch_align - 1);
9450 download_consts[PKT_OVERRUN_BUFOFFSET] =
9452 download_consts[SCB_TRANSFER_SIZE] = SCB_TRANSFER_SIZE_1BYTE_LUN;
9453 download_consts[CACHELINE_MASK] = cacheline_mask;
9454 cur_patch = patches;
9460 for (i = 0; i <
sizeof(seqprog)/4; i++) {
9461 if (ahd_check_patch(ahd, &cur_patch, i, &skip_addr) == 0) {
9472 for (; cur_cs < num_critical_sections; cur_cs++) {
9473 if (critical_sections[cur_cs].
end <= i) {
9474 if (begin_set[cs_count] ==
TRUE
9475 && end_set[cs_count] ==
FALSE) {
9476 cs_table[cs_count].end = downloaded;
9477 end_set[cs_count] =
TRUE;
9482 if (critical_sections[cur_cs].begin <= i
9483 && begin_set[cs_count] ==
FALSE) {
9484 cs_table[cs_count].begin = downloaded;
9485 begin_set[cs_count] =
TRUE;
9489 ahd_download_instr(ahd, i, download_consts);
9494 if (cs_count != 0) {
9496 cs_count *=
sizeof(
struct cs);
9499 panic(
"ahd_loadseq: Could not malloc");
9505 printk(
" %d instructions downloaded\n", downloaded);
9506 printk(
"%s: Features 0x%x, Bugs 0x%x, Flags 0x%x\n",
9512 ahd_check_patch(
struct ahd_softc *ahd,
const struct patch **start_patch,
9515 const struct patch *cur_patch;
9516 const struct patch *last_patch;
9520 last_patch = &patches[num_patches];
9521 cur_patch = *start_patch;
9523 while (cur_patch < last_patch && start_instr == cur_patch->begin) {
9525 if (cur_patch->patch_func(ahd) == 0) {
9528 *skip_addr = start_instr + cur_patch->skip_instr;
9529 cur_patch += cur_patch->skip_patch;
9539 *start_patch = cur_patch;
9540 if (start_instr < *skip_addr)
9550 const struct patch *cur_patch;
9556 cur_patch = patches;
9561 ahd_check_patch(ahd, &cur_patch, i, &skip_addr);
9563 if (skip_addr > i) {
9566 end_addr =
min(address, skip_addr);
9567 address_offset += end_addr -
i;
9573 return (address - address_offset);
9589 fmt1_ins = &
instr.format1;
9593 opcode =
instr.format1.opcode;
9604 fmt3_ins = &
instr.format3;
9614 if (fmt1_ins->
parity != 0) {
9624 for (i = 0, count = 0; i < 31; i++) {
9628 if ((
instr.integer & mask) != 0)
9631 if ((count & 0x01) == 0)
9632 instr.format1.parity = 1;
9640 panic(
"Unknown opcode encountered in seq program");
9646 ahd_probe_stack_size(
struct ahd_softc *ahd)
9660 for (i = 1; i <= last_probe+1; i++) {
9666 for (i = last_probe+1; i > 0; i--) {
9671 if (stack_entry != i)
9677 return (last_probe);
9688 if (cur_column !=
NULL && *cur_column >= wrap_point) {
9692 printed =
printk(
"%s[0x%x]", name, value);
9693 if (table ==
NULL) {
9695 *cur_column += printed;
9699 while (printed_mask != 0xFF) {
9703 if (((value & table[entry].mask)
9704 != table[entry].value)
9705 || ((printed_mask & table[entry].mask)
9706 == table[entry].mask))
9709 printed +=
printk(
"%s%s",
9710 printed_mask == 0 ?
":(" :
"|",
9712 printed_mask |= table[
entry].mask;
9716 if (entry >= num_entries)
9719 if (printed_mask != 0)
9723 if (cur_column !=
NULL)
9724 *cur_column += printed;
9736 u_int saved_scb_index;
9748 printk(
">>>>>>>>>>>>>>>>>> Dump Card State Begins <<<<<<<<<<<<<<<<<\n"
9749 "%s: Dumping Card State at program address 0x%x Mode 0x%x\n",
9755 printk(
"Card was paused\n");
9757 if (ahd_check_cmdcmpltqueues(ahd))
9758 printk(
"Completions are pending\n");
9765 ahd_seloid_print(
ahd_inb(ahd, SELOID), &cur_col, 50);
9767 ahd_hs_mailbox_print(
ahd_inb(ahd, LOCAL_HS_MAILBOX), &cur_col, 50);
9768 ahd_intctl_print(
ahd_inb(ahd, INTCTL), &cur_col, 50);
9769 ahd_seqintstat_print(
ahd_inb(ahd, SEQINTSTAT), &cur_col, 50);
9770 ahd_saved_mode_print(
ahd_inb(ahd, SAVED_MODE), &cur_col, 50);
9771 ahd_dffstat_print(
ahd_inb(ahd, DFFSTAT), &cur_col, 50);
9776 ahd_scsiseq0_print(
ahd_inb(ahd, SCSISEQ0), &cur_col, 50);
9777 ahd_scsiseq1_print(
ahd_inb(ahd, SCSISEQ1), &cur_col, 50);
9778 ahd_seqctl0_print(
ahd_inb(ahd, SEQCTL0), &cur_col, 50);
9779 ahd_seqintctl_print(
ahd_inb(ahd, SEQINTCTL), &cur_col, 50);
9781 ahd_seq_flags2_print(
ahd_inb(ahd, SEQ_FLAGS2), &cur_col, 50);
9782 ahd_qfreeze_count_print(
ahd_inw(ahd, QFREEZE_COUNT), &cur_col, 50);
9783 ahd_kernel_qfreeze_count_print(
ahd_inw(ahd, KERNEL_QFREEZE_COUNT),
9785 ahd_mk_message_scb_print(
ahd_inw(ahd, MK_MESSAGE_SCB), &cur_col, 50);
9786 ahd_mk_message_scsiid_print(
ahd_inb(ahd, MK_MESSAGE_SCSIID),
9792 ahd_perrdiag_print(
ahd_inb(ahd, PERRDIAG), &cur_col, 50);
9794 ahd_lqistat0_print(
ahd_inb(ahd, LQISTAT0), &cur_col, 50);
9795 ahd_lqistat1_print(
ahd_inb(ahd, LQISTAT1), &cur_col, 50);
9796 ahd_lqistat2_print(
ahd_inb(ahd, LQISTAT2), &cur_col, 50);
9797 ahd_lqostat0_print(
ahd_inb(ahd, LQOSTAT0), &cur_col, 50);
9798 ahd_lqostat1_print(
ahd_inb(ahd, LQOSTAT1), &cur_col, 50);
9799 ahd_lqostat2_print(
ahd_inb(ahd, LQOSTAT2), &cur_col, 50);
9801 printk(
"\nSCB Count = %d CMDS_PENDING = %d LASTSCB 0x%x "
9802 "CURRSCB 0x%x NEXTSCB 0x%x\n",
9815 if (i++ > AHD_SCB_MAX)
9825 printk(
"\nTotal %d\n", i);
9827 printk(
"Kernel Free SCB list: ");
9830 struct scb *list_scb;
9836 }
while (list_scb && i++ < AHD_SCB_MAX);
9840 if (i++ > AHD_SCB_MAX)
9846 printk(
"Sequencer Complete DMA-inprog list: ");
9847 scb_index =
ahd_inw(ahd, COMPLETE_SCB_DMAINPROG_HEAD);
9851 printk(
"%d ", scb_index);
9856 printk(
"Sequencer Complete list: ");
9857 scb_index =
ahd_inw(ahd, COMPLETE_SCB_HEAD);
9861 printk(
"%d ", scb_index);
9867 printk(
"Sequencer DMA-Up and Complete list: ");
9868 scb_index =
ahd_inw(ahd, COMPLETE_DMA_SCB_HEAD);
9872 printk(
"%d ", scb_index);
9876 printk(
"Sequencer On QFreeze and Complete list: ");
9877 scb_index =
ahd_inw(ahd, COMPLETE_ON_QFREEZE_HEAD);
9881 printk(
"%d ", scb_index);
9886 dffstat =
ahd_inb(ahd, DFFSTAT);
9887 for (i = 0; i < 2; i++) {
9889 struct scb *fifo_scb;
9895 printk(
"\n\n%s: FIFO%d %s, LONGJMP == 0x%x, SCB 0x%x\n",
9897 (dffstat & (FIFO0FREE << i)) ?
"Free" :
"Active",
9898 ahd_inw(ahd, LONGJMP_ADDR), fifo_scbptr);
9900 ahd_seqimode_print(
ahd_inb(ahd, SEQIMODE), &cur_col, 50);
9901 ahd_seqintsrc_print(
ahd_inb(ahd, SEQINTSRC), &cur_col, 50);
9904 ahd_sg_cache_shadow_print(
ahd_inb(ahd, SG_CACHE_SHADOW),
9906 ahd_sg_state_print(
ahd_inb(ahd, SG_STATE), &cur_col, 50);
9907 ahd_dffsxfrctl_print(
ahd_inb(ahd, DFFSXFRCTL), &cur_col, 50);
9908 ahd_soffcnt_print(
ahd_inb(ahd, SOFFCNT), &cur_col, 50);
9909 ahd_mdffstat_print(
ahd_inb(ahd, MDFFSTAT), &cur_col, 50);
9914 cur_col +=
printk(
"SHADDR = 0x%x%x, SHCNT = 0x%x ",
9918 | (
ahd_inb(ahd, SHCNT + 1) << 8)
9919 | (
ahd_inb(ahd, SHCNT + 2) << 16)));
9924 cur_col +=
printk(
"HADDR = 0x%x%x, HCNT = 0x%x ",
9932 if ((ahd_debug & AHD_SHOW_SG) != 0) {
9934 if (fifo_scb !=
NULL)
9935 ahd_dump_sglist(fifo_scb);
9940 for (i = 0; i < 20; i++)
9944 printk(
"%s: LQISTATE = 0x%x, LQOSTATE = 0x%x, OPTIONMODE = 0x%x\n",
9947 printk(
"%s: OS_SPACE_CNT = 0x%x MAXCMDCNT = 0x%x\n",
9948 ahd_name(ahd),
ahd_inb(ahd, OS_SPACE_CNT),
9950 printk(
"%s: SAVED_SCSIID = 0x%x SAVED_LUN = 0x%x\n",
9951 ahd_name(ahd),
ahd_inb(ahd, SAVED_SCSIID),
9960 printk(
"%s: REG0 == 0x%x, SINDEX = 0x%x, DINDEX = 0x%x\n",
9963 printk(
"%s: SCBPTR == 0x%x, SCB_NEXT == 0x%x, SCB_NEXT2 == 0x%x\n",
9967 printk(
"CDB %x %x %x %x %x %x\n",
9984 printk(
"\n<<<<<<<<<<<<<<<<< Dump Card State Ends >>>>>>>>>>>>>>>>>>\n");
9995 u_int saved_scb_index;
10004 printk(
"(CTRL 0x%x ID 0x%x N 0x%x N2 0x%x SG 0x%x, RSG 0x%x)\n",
10010 ahd_inl_scbram(ahd, SCB_RESIDUAL_SGPTR));
10039 end_addr = start_addr +
count;
10040 for (cur_addr = start_addr; cur_addr < end_addr; cur_addr++) {
10045 error = ahd_wait_seeprom(ahd);
10048 if (bytestream != 0) {
10051 bytestream_ptr = (
uint8_t *)buf;
10052 *bytestream_ptr++ =
ahd_inb(ahd, SEEDAT);
10053 *bytestream_ptr =
ahd_inb(ahd, SEEDAT+1);
10083 ahd_outb(ahd, SEEADR, SEEOP_EWEN_ADDR);
10085 error = ahd_wait_seeprom(ahd);
10094 end_addr = start_addr +
count;
10095 for (cur_addr = start_addr; cur_addr < end_addr; cur_addr++) {
10100 retval = ahd_wait_seeprom(ahd);
10108 ahd_outb(ahd, SEEADR, SEEOP_EWDS_ADDR);
10110 error = ahd_wait_seeprom(ahd);
10120 ahd_wait_seeprom(
struct ahd_softc *ahd)
10125 while ((
ahd_inb(ahd, SEESTAT) & (SEEARBACK|SEEBUSY)) != 0 && --cnt)
10149 checksum = checksum + vpdarray[i];
10158 checksum = checksum + vpdarray[i];
10160 || (-checksum & 0xFF) != vpd->
checksum)
10173 maxaddr = (
sizeof(*sc)/2) - 1;
10177 for (i = 0; i < maxaddr; i++)
10178 checksum = checksum + scarray[i];
10180 || (checksum & 0xFFFF) != sc->
checksum) {
10220 ahd_wait_flexport(
struct ahd_softc *ahd)
10225 cnt = 1000000 * 2 / 5;
10241 panic(
"ahd_write_flexport: address out of range");
10243 error = ahd_wait_flexport(ahd);
10247 ahd_flush_device_writes(ahd);
10249 ahd_flush_device_writes(ahd);
10251 ahd_flush_device_writes(ahd);
10253 ahd_flush_device_writes(ahd);
10264 panic(
"ahd_read_flexport: address out of range");
10266 error = ahd_wait_flexport(ahd);
10269 *value =
ahd_inb(ahd, BRDDAT);
10271 ahd_flush_device_writes(ahd);
10276 #ifdef AHD_TARGET_MODE
10278 ahd_find_tmode_devs(
struct ahd_softc *ahd,
struct cam_sim *sim,
union ccb *
ccb,
10280 struct ahd_tmode_lstate **lstate,
10281 int notfound_failure)
10299 if (ccb->ccb_h.target_id >= max_id)
10300 return (CAM_TID_INVALID);
10303 return (CAM_LUN_INVALID);
10307 if (*tstate !=
NULL)
10309 (*tstate)->enabled_luns[ccb->ccb_h.target_lun];
10312 if (notfound_failure != 0 && *lstate ==
NULL)
10319 ahd_handle_en_lun(
struct ahd_softc *ahd,
struct cam_sim *sim,
union ccb *ccb)
10323 struct ahd_tmode_lstate *lstate;
10324 struct ccb_en_lun *cel;
10332 status = ahd_find_tmode_devs(ahd, sim, ccb, &tstate, &lstate,
10336 ccb->ccb_h.status =
status;
10344 if (ccb->ccb_h.target_id != our_id) {
10345 if ((ahd->
features & AHD_MULTI_TID) != 0
10354 status = CAM_TID_INVALID;
10364 status = CAM_TID_INVALID;
10370 ccb->ccb_h.status =
status;
10382 printk(
"Configuring Target Mode\n");
10386 ahd_unlock(ahd, &s);
10395 ahd_unlock(ahd, &s);
10398 target = ccb->ccb_h.target_id;
10399 lun = ccb->ccb_h.target_lun;
10400 channel = SIM_CHANNEL(ahd, sim);
10401 target_mask = 0x01 <<
target;
10402 if (channel ==
'B')
10405 if (cel->enable != 0) {
10409 if (lstate !=
NULL) {
10410 xpt_print_path(ccb->ccb_h.path);
10411 printk(
"Lun already enabled\n");
10412 ccb->ccb_h.status = CAM_LUN_ALRDY_ENA;
10416 if (cel->grp6_len != 0
10417 || cel->grp7_len != 0) {
10423 printk(
"Non-zero Group Codes\n");
10432 tstate = ahd_alloc_tstate(ahd, target, channel);
10433 if (tstate ==
NULL) {
10434 xpt_print_path(ccb->ccb_h.path);
10435 printk(
"Couldn't allocate tstate\n");
10441 if (lstate ==
NULL) {
10442 xpt_print_path(ccb->ccb_h.path);
10443 printk(
"Couldn't allocate lstate\n");
10447 memset(lstate, 0,
sizeof(*lstate));
10448 status = xpt_create_path(&lstate->path,
NULL,
10449 xpt_path_path_id(ccb->ccb_h.path),
10450 xpt_path_target_id(ccb->ccb_h.path),
10451 xpt_path_lun_id(ccb->ccb_h.path));
10454 xpt_print_path(ccb->ccb_h.path);
10455 printk(
"Couldn't allocate path\n");
10467 if ((ahd->
features & AHD_MULTI_TID) != 0) {
10470 targid_mask =
ahd_inw(ahd, TARGID);
10471 targid_mask |= target_mask;
10472 ahd_outw(ahd, TARGID, targid_mask);
10473 ahd_update_scsiid(ahd, targid_mask);
10478 channel = SIM_CHANNEL(ahd, sim);
10479 our_id = SIM_SCSI_ID(ahd, sim);
10485 if (target != our_id) {
10491 cur_channel = (sblkctl &
SELBUSB)
10493 if ((ahd->
features & AHD_TWIN) == 0)
10495 swap = cur_channel !=
channel;
10512 scsiseq1 =
ahd_inb(ahd, SCSISEQ_TEMPLATE);
10514 ahd_outb(ahd, SCSISEQ_TEMPLATE, scsiseq1);
10515 scsiseq1 =
ahd_inb(ahd, SCSISEQ1);
10517 ahd_outb(ahd, SCSISEQ1, scsiseq1);
10520 ahd_unlock(ahd, &s);
10522 xpt_print_path(ccb->ccb_h.path);
10523 printk(
"Lun now enabled for target mode\n");
10528 if (lstate ==
NULL) {
10529 ccb->ccb_h.status = CAM_LUN_INVALID;
10537 struct ccb_hdr *ccbh;
10539 ccbh = &scb->
io_ctx->ccb_h;
10540 if (ccbh->func_code == XPT_CONT_TARGET_IO
10541 && !xpt_path_comp(ccbh->path, ccb->ccb_h.path)){
10542 printk(
"CTIO pending\n");
10544 ahd_unlock(ahd, &s);
10550 printk(
"ATIOs pending\n");
10555 printk(
"INOTs pending\n");
10560 ahd_unlock(ahd, &s);
10564 xpt_print_path(ccb->ccb_h.path);
10565 printk(
"Target mode disabled\n");
10566 xpt_free_path(lstate->path);
10574 for (empty = 1, i = 0; i < 8; i++)
10581 ahd_free_tstate(ahd, target, channel,
10583 if (ahd->
features & AHD_MULTI_TID) {
10586 targid_mask =
ahd_inw(ahd, TARGID);
10587 targid_mask &= ~target_mask;
10588 ahd_outw(ahd, TARGID, targid_mask);
10589 ahd_update_scsiid(ahd, targid_mask);
10606 scsiseq1 =
ahd_inb(ahd, SCSISEQ_TEMPLATE);
10608 ahd_outb(ahd, SCSISEQ_TEMPLATE, scsiseq1);
10609 scsiseq1 =
ahd_inb(ahd, SCSISEQ1);
10611 ahd_outb(ahd, SCSISEQ1, scsiseq1);
10614 printk(
"Configuring Initiator Mode\n");
10627 ahd_unlock(ahd, &s);
10639 if ((ahd->
features & AHD_MULTI_TID) == 0)
10640 panic(
"ahd_update_scsiid called on non-multitid unit\n");
10648 if ((ahd->
features & AHD_ULTRA2) != 0)
10652 scsiid_mask = 0x1 << (scsiid &
OID);
10653 if ((targid_mask & scsiid_mask) == 0) {
10657 our_id =
ffs(targid_mask);
10665 if ((ahd->
features & AHD_ULTRA2) != 0)
10673 ahd_run_tqinfifo(
struct ahd_softc *ahd,
int paused)
10684 if (ahd_handle_target_cmd(ahd, cmd) != 0)
10702 hs_mailbox =
ahd_inb(ahd, HS_MAILBOX);
10703 hs_mailbox &= ~HOST_TQINPOS;
10705 ahd_outb(ahd, HS_MAILBOX, hs_mailbox);
10714 struct ahd_tmode_lstate *lstate;
10715 struct ccb_accept_tio *
atio;
10728 if (tstate !=
NULL)
10734 if (lstate ==
NULL)
10737 atio = (
struct ccb_accept_tio*)
SLIST_FIRST(&lstate->accept_tios);
10738 if (atio ==
NULL) {
10747 if ((ahd_debug & AHD_SHOW_TQIN) != 0)
10748 printk(
"Incoming command from %d for %d:%d%s\n",
10749 initiator, target, lun,
10750 lstate == ahd->
black_hole ?
"(Black Holed)" :
"");
10756 atio->ccb_h.target_id =
target;
10757 atio->ccb_h.target_lun =
lun;
10764 atio->sense_len = 0;
10766 if (byte[0] != 0xFF) {
10768 atio->tag_action = *byte++;
10769 atio->tag_id = *byte++;
10770 atio->ccb_h.flags = CAM_TAG_ACTION_VALID;
10772 atio->ccb_h.flags = 0;
10783 atio->cdb_len = 10;
10786 atio->cdb_len = 16;
10789 atio->cdb_len = 12;
10795 printk(
"Reserved or VU command code type encountered\n");
10799 memcpy(atio->cdb_io.cdb_bytes, byte, atio->cdb_len);
10801 atio->ccb_h.status |= CAM_CDB_RECVD;
10811 if ((ahd_debug & AHD_SHOW_TQIN) != 0)
10812 printk(
"Received Immediate Command %d:%d:%d - %p\n",
10816 ahd_freeze_ccb((
union ccb *)atio);
10817 atio->ccb_h.flags |= CAM_DIS_DISCONNECT;
10819 xpt_done((
union ccb*)atio);