Lines Matching defs:ahc

149 static void		ahc_force_renegotiation(struct ahc_softc *ahc,
152 ahc_alloc_tstate(struct ahc_softc *ahc,
155 static void ahc_free_tstate(struct ahc_softc *ahc,
159 ahc_devlimited_syncrate(struct ahc_softc *ahc,
164 static void ahc_update_pending_scbs(struct ahc_softc *ahc);
165 static void ahc_fetch_devinfo(struct ahc_softc *ahc,
167 static void ahc_assert_atn(struct ahc_softc *ahc);
168 static void ahc_setup_initiator_msgout(struct ahc_softc *ahc,
171 static void ahc_build_transfer_msg(struct ahc_softc *ahc,
173 static void ahc_construct_sdtr(struct ahc_softc *ahc,
176 static void ahc_construct_wdtr(struct ahc_softc *ahc,
179 static void ahc_construct_ppr(struct ahc_softc *ahc,
183 static void ahc_clear_msg_state(struct ahc_softc *ahc);
184 static void ahc_handle_proto_violation(struct ahc_softc *ahc);
185 static void ahc_handle_message_phase(struct ahc_softc *ahc);
191 static int ahc_sent_msg(struct ahc_softc *ahc, ahc_msgtype type,
193 static int ahc_parse_msg(struct ahc_softc *ahc,
195 static int ahc_handle_msg_reject(struct ahc_softc *ahc,
197 static void ahc_handle_ign_wide_residue(struct ahc_softc *ahc,
199 static void ahc_reinitialize_dataptrs(struct ahc_softc *ahc);
200 static void ahc_handle_devreset(struct ahc_softc *ahc,
205 static void ahc_setup_target_msgin(struct ahc_softc *ahc,
211 static void ahc_build_free_scb_list(struct ahc_softc *ahc);
212 static int ahc_init_scbdata(struct ahc_softc *ahc);
213 static void ahc_fini_scbdata(struct ahc_softc *ahc);
214 static void ahc_qinfifo_requeue(struct ahc_softc *ahc,
217 static int ahc_qinfifo_count(struct ahc_softc *ahc);
218 static u_int ahc_rem_scb_from_disc_list(struct ahc_softc *ahc,
220 static void ahc_add_curscb_to_free_list(struct ahc_softc *ahc);
221 static u_int ahc_rem_wscb(struct ahc_softc *ahc,
223 static void ahc_reset_current_bus(struct ahc_softc *ahc);
225 static void ahc_dumpseq(struct ahc_softc *ahc);
227 static int ahc_loadseq(struct ahc_softc *ahc);
228 static int ahc_check_patch(struct ahc_softc *ahc,
231 static void ahc_download_instr(struct ahc_softc *ahc,
234 static void ahc_queue_lstate_event(struct ahc_softc *ahc,
239 static void ahc_update_scsiid(struct ahc_softc *ahc,
241 static int ahc_handle_target_cmd(struct ahc_softc *ahc,
267 ahc_restart(struct ahc_softc *ahc)
270 ahc_pause(ahc);
273 ahc_clear_msg_state(ahc);
275 ahc_outb(ahc, SCSISIGO, 0); /* De-assert BSY */
276 ahc_outb(ahc, MSG_OUT, MSG_NOOP); /* No message to send */
277 ahc_outb(ahc, SXFRCTL1, ahc_inb(ahc, SXFRCTL1) & ~BITBUCKET);
278 ahc_outb(ahc, LASTPHASE, P_BUSFREE);
279 ahc_outb(ahc, SAVED_SCSIID, 0xFF);
280 ahc_outb(ahc, SAVED_LUN, 0xFF);
289 ahc_outb(ahc, TQINPOS, ahc->tqinfifonext);
292 ahc_outb(ahc, SCSISEQ,
293 ahc_inb(ahc, SCSISEQ_TEMPLATE) & (ENSELI|ENRSELI|ENAUTOATNP));
294 if ((ahc->features & AHC_CMD_CHAN) != 0) {
296 ahc_outb(ahc, CCSCBCNT, 0);
297 ahc_outb(ahc, CCSGCTL, 0);
298 ahc_outb(ahc, CCSCBCTL, 0);
305 if ((ahc_inb(ahc, SEQ_FLAGS2) & SCB_DMA) != 0) {
306 ahc_add_curscb_to_free_list(ahc);
307 ahc_outb(ahc, SEQ_FLAGS2,
308 ahc_inb(ahc, SEQ_FLAGS2) & ~SCB_DMA);
316 ahc_outb(ahc, CLRINT, CLRSEQINT);
318 ahc_outb(ahc, MWI_RESIDUAL, 0);
319 ahc_outb(ahc, SEQCTL, ahc->seqctl);
320 ahc_outb(ahc, SEQADDR0, 0);
321 ahc_outb(ahc, SEQADDR1, 0);
323 ahc_unpause(ahc);
328 ahc_run_qoutfifo(struct ahc_softc *ahc)
333 ahc_sync_qoutfifo(ahc, BUS_DMASYNC_POSTREAD);
334 while (ahc->qoutfifo[ahc->qoutfifonext] != SCB_LIST_NULL) {
336 scb_index = ahc->qoutfifo[ahc->qoutfifonext];
337 if ((ahc->qoutfifonext & 0x03) == 0x03) {
347 modnext = ahc->qoutfifonext & ~0x3;
348 *((uint32_t *)(&ahc->qoutfifo[modnext])) = 0xFFFFFFFFUL;
349 ahc_dmamap_sync(ahc, ahc->parent_dmat /*shared_data_dmat*/,
350 ahc->shared_data_dmamap,
354 ahc->qoutfifonext++;
356 scb = ahc_lookup_scb(ahc, scb_index);
360 ahc_name(ahc), scb_index,
361 (ahc->qoutfifonext - 1) & 0xFF);
369 ahc_update_residual(ahc, scb);
370 ahc_done(ahc, scb);
375 ahc_run_untagged_queues(struct ahc_softc *ahc)
380 ahc_run_untagged_queue(ahc, &ahc->untagged_queues[i]);
384 ahc_run_untagged_queue(struct ahc_softc *ahc, struct scb_tailq *queue)
388 if (ahc->untagged_queue_lock != 0)
394 ahc_queue_scb(ahc, scb);
400 ahc_handle_brkadrint(struct ahc_softc *ahc)
410 error = ahc_inb(ahc, ERROR);
416 ahc_name(ahc), ahc_hard_errors[i].errmesg,
417 ahc_inb(ahc, SEQADDR0) |
418 (ahc_inb(ahc, SEQADDR1) << 8));
420 ahc_dump_card_state(ahc);
424 ahc_abort_scbs(ahc, CAM_TARGET_WILDCARD, ALL_CHANNELS,
429 ahc_shutdown(ahc);
433 ahc_handle_seqint(struct ahc_softc *ahc, u_int intstat)
439 ahc_fetch_devinfo(ahc, &devinfo);
447 ahc_outb(ahc, CLRINT, CLRSEQINT);
458 ahc_outb(ahc, RETURN_1, 0);
469 scb_index = ahc_inb(ahc, SCB_TAG);
470 scb = ahc_lookup_scb(ahc, scb_index);
472 ahc_print_devinfo(ahc, &devinfo);
476 ahc_dump_card_state(ahc);
496 ahc_freeze_devq(ahc, scb);
502 ahc_name(ahc));
514 ahc_print_path(ahc, scb);
523 targ_info = ahc_fetch_transinfo(ahc,
534 ahc_update_residual(ahc, scb);
537 ahc_print_path(ahc, scb);
541 sg->addr = ahc_get_sense_bufaddr(ahc, scb);
542 sg->len = ahc_get_sense_bufsize(ahc, scb);
578 ahc_update_neg_request(ahc, &devinfo,
593 bus_dmamap_sync(ahc->parent_dmat,
594 ahc->scb_data->sense_dmamap,
595 (scb - ahc->scb_data->scbarray) *
599 bus_dmamap_sync(ahc->parent_dmat,
603 bus_dmamap_sync(ahc->parent_dmat,
604 ahc->scb_data->hscb_dmamap,
605 0, ahc->scb_data->hscb_dmamap->dm_mapsize,
610 ahc_qinfifo_requeue_tail(ahc, scb);
611 ahc_outb(ahc, RETURN_1, SEND_SENSE);
627 ahc_outb(ahc, SCSISEQ,
628 ahc_inb(ahc, SCSISEQ) & (ENSELI|ENRSELI|ENAUTOATNP));
632 ahc_name(ahc), devinfo.channel, devinfo.target);
635 ahc_inb(ahc, SAVED_SCSIID), ahc_inb(ahc, SAVED_LUN),
636 ahc_inb(ahc, ARG_1), ahc_inb(ahc, ACCUM));
639 ahc_inb(ahc, SEQ_FLAGS), ahc_inb(ahc, SCBPTR),
640 ahc_index_busy_tcl(ahc,
641 BUILD_TCL(ahc_inb(ahc, SAVED_SCSIID),
642 ahc_inb(ahc, SAVED_LUN))),
643 ahc_inb(ahc, SINDEX));
646 ahc_inb(ahc, SCSIID), ahc_inb(ahc, SCB_SCSIID),
647 ahc_inb(ahc, SCB_LUN), ahc_inb(ahc, SCB_TAG),
648 ahc_inb(ahc, SCB_CONTROL));
650 ahc_inb(ahc, SCSIBUSL), ahc_inb(ahc, SCSISIGI));
651 printf("SXFRCTL0 == 0x%x\n", ahc_inb(ahc, SXFRCTL0));
652 printf("SEQCTL == 0x%x\n", ahc_inb(ahc, SEQCTL));
653 ahc_dump_card_state(ahc);
654 ahc->msgout_buf[0] = MSG_BUS_DEV_RESET;
655 ahc->msgout_len = 1;
656 ahc->msgout_index = 0;
657 ahc->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
658 ahc_outb(ahc, MSG_OUT, HOST_MSG);
659 ahc_assert_atn(ahc);
664 u_int rejbyte = ahc_inb(ahc, ACCUM);
667 ahc_name(ahc), devinfo.channel, devinfo.target, rejbyte);
672 ahc_handle_proto_violation(ahc);
676 ahc_handle_ign_wide_residue(ahc, &devinfo);
679 ahc_reinitialize_dataptrs(ahc);
685 lastphase = ahc_inb(ahc, LASTPHASE);
688 ahc_name(ahc), devinfo.channel, devinfo.target,
689 lastphase, ahc_inb(ahc, SCSISIGI));
696 lastphase = ahc_inb(ahc, LASTPHASE);
699 ahc_name(ahc), devinfo.channel, devinfo.target,
700 lastphase, ahc_inb(ahc, SCSISIGI));
701 ahc_restart(ahc);
717 if (ahc->msg_type == MSG_TYPE_NONE) {
720 bus_phase = ahc_inb(ahc, SCSISIGI) & PHASE_MASK;
730 ahc_clear_intstat(ahc);
731 ahc_restart(ahc);
735 scb_index = ahc_inb(ahc, SCB_TAG);
736 scb = ahc_lookup_scb(ahc, scb_index);
743 ahc_setup_initiator_msgout(ahc,
747 ahc->msg_type =
749 ahc->msgin_index = 0;
755 ahc->msg_type =
757 ahc->msgin_index = 0;
760 ahc_setup_target_msgin(ahc,
767 ahc_handle_message_phase(ahc);
784 && (ahc_inb(ahc, SSTAT1) & SCSIPERR) != 0) {
786 if ((ahc->features & AHC_DT) == 0) {
795 curphase = ahc_inb(ahc, SCSISIGI) & PHASE_MASK;
796 ahc_outb(ahc, LASTPHASE, curphase);
797 ahc_outb(ahc, SCSISIGO, curphase);
799 if ((ahc_inb(ahc, SCSISIGI) & (CDI|MSGI)) == 0) {
808 ahc_outb(ahc, SXFRCTL1,
809 ahc_inb(ahc, SXFRCTL1) | BITBUCKET);
812 if ((ahc_inb(ahc, SCSISIGI)
817 ahc_outb(ahc, SXFRCTL1,
818 ahc_inb(ahc, SXFRCTL1) & ~BITBUCKET);
820 ahc_print_devinfo(ahc, &devinfo);
823 scb_index = ahc_inb(ahc, SCB_TAG);
824 scb = ahc_lookup_scb(ahc, scb_index);
828 ahc_reset_channel(ahc, devinfo.channel,
832 ahc_inb(ahc, SCSIDATL);
847 u_int scbindex = ahc_inb(ahc, SCB_TAG);
848 u_int lastphase = ahc_inb(ahc, LASTPHASE);
851 scb = ahc_lookup_scb(ahc, scbindex);
858 ahc_print_path(ahc, scb);
863 ahc_print_path(ahc, scb);
865 ahc_inb(ahc, SEQ_FLAGS) & DPHASE ? "Have" : "Haven't",
885 ahc_freeze_devq(ahc, scb);
894 if ((ahc->features & AHC_ULTRA2) != 0) {
899 ahc_outb(ahc, SXFRCTL0,
900 ahc_inb(ahc, SXFRCTL0) | CLRSTCNT|CLRCHN);
901 ahc_outb(ahc, SXFRCTL0,
902 ahc_inb(ahc, SXFRCTL0) | CLRSTCNT|CLRCHN);
904 if ((ahc->flags & AHC_39BIT_ADDRESSING) != 0) {
908 dscommand1 = ahc_inb(ahc, DSCOMMAND1);
909 ahc_outb(ahc, DSCOMMAND1, dscommand1 | HADDLDSEL0);
910 ahc_outb(ahc, HADDR, 0);
911 ahc_outb(ahc, DSCOMMAND1, dscommand1);
920 ahc_name(ahc), devinfo.channel, devinfo.target,
922 scbindex = ahc_inb(ahc, SCB_TAG);
923 scb = ahc_lookup_scb(ahc, scbindex);
929 ahc_search_qinfifo(ahc, SCB_GET_TARGET(ahc, scb),
930 SCB_GET_CHANNEL(ahc, scb),
938 printf("%s: No free or disconnected SCBs\n", ahc_name(ahc));
939 ahc_dump_card_state(ahc);
947 scbptr = ahc_inb(ahc, SCBPTR);
949 scbptr, ahc_inb(ahc, ARG_1),
950 ahc->scb_data->hscbs[scbptr].tag);
951 ahc_dump_card_state(ahc);
958 printf("%s: BTT calculation out of range\n", ahc_name(ahc));
961 ahc_inb(ahc, SAVED_SCSIID), ahc_inb(ahc, SAVED_LUN),
962 ahc_inb(ahc, ARG_1), ahc_inb(ahc, ACCUM));
965 ahc_inb(ahc, SEQ_FLAGS), ahc_inb(ahc, SCBPTR),
966 ahc_index_busy_tcl(ahc,
967 BUILD_TCL(ahc_inb(ahc, SAVED_SCSIID),
968 ahc_inb(ahc, SAVED_LUN))),
969 ahc_inb(ahc, SINDEX),
970 ahc_inb(ahc, ACCUM));
973 ahc_inb(ahc, SCSIID), ahc_inb(ahc, SCB_SCSIID),
974 ahc_inb(ahc, SCB_LUN), ahc_inb(ahc, SCB_TAG),
975 ahc_inb(ahc, SCB_CONTROL));
977 ahc_inb(ahc, SCSIBUSL), ahc_inb(ahc, SCSISIGI));
979 ahc_dump_card_state(ahc);
986 intstat, ahc_inb(ahc, SCSISIGI));
995 ahc_unpause(ahc);
999 ahc_handle_scsiint(struct ahc_softc *ahc, u_int intstat)
1008 if ((ahc->features & AHC_TWIN) != 0
1009 && ((ahc_inb(ahc, SBLKCTL) & SELBUSB) != 0))
1015 if ((ahc->features & AHC_ULTRA2) != 0)
1016 status0 = ahc_inb(ahc, SSTAT0) & IOERR;
1019 status = ahc_inb(ahc, SSTAT1) & (SELTO|SCSIRSTI|BUSFREE|SCSIPERR);
1021 if ((ahc->features & AHC_TWIN) != 0) {
1023 ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) ^ SELBUSB);
1024 status = ahc_inb(ahc, SSTAT1)
1029 printf("%s: Spurious SCSI interrupt\n", ahc_name(ahc));
1030 ahc_outb(ahc, CLRINT, CLRSCSIINT);
1031 ahc_unpause(ahc);
1037 ahc_clear_critical_section(ahc);
1039 scb_index = ahc_inb(ahc, SCB_TAG);
1040 scb = ahc_lookup_scb(ahc, scb_index);
1042 && (ahc_inb(ahc, SEQ_FLAGS) & NOT_IDENTIFIED) != 0)
1045 if ((ahc->features & AHC_ULTRA2) != 0
1049 now_lvd = ahc_inb(ahc, SBLKCTL) & ENAB40;
1051 ahc_name(ahc), now_lvd ? "LVD" : "SE");
1052 ahc_outb(ahc, CLRSINT0, CLRIOERR);
1063 ahc_reset_channel(ahc, intr_channel,
1067 ahc_name(ahc), intr_channel);
1069 ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) ^ SELBUSB);
1070 ahc_reset_channel(ahc, intr_channel, /*Initiate Reset*/FALSE);
1092 lastphase = ahc_inb(ahc, LASTPHASE);
1093 curphase = ahc_inb(ahc, SCSISIGI) & PHASE_MASK;
1094 sstat2 = ahc_inb(ahc, SSTAT2);
1095 ahc_outb(ahc, CLRSINT1, CLRSCSIPERR);
1107 if ((ahc_inb(ahc, SSTAT1) & SCSIPERR) != 0
1123 ahc_print_path(ahc, scb);
1126 printf("%s:%c:%d: ", ahc_name(ahc), intr_channel,
1127 SCSIID_TARGET(ahc, ahc_inb(ahc, SAVED_SCSIID)));
1128 scsirate = ahc_inb(ahc, SCSIRATE);
1133 ahc_inw(ahc, SEQADDR0),
1135 if ((ahc->features & AHC_DT) != 0) {
1151 if ((ahc->features & AHC_DT) != 0
1169 if (ahc->msg_type != MSG_TYPE_NONE)
1170 ahc->send_msg_perror = TRUE;
1172 ahc_outb(ahc, MSG_OUT, mesg_out);
1179 ahc_fetch_devinfo(ahc, &devinfo);
1180 ahc_force_renegotiation(ahc, &devinfo);
1182 ahc_outb(ahc, CLRINT, CLRSCSIINT);
1183 ahc_unpause(ahc);
1188 ahc_outb(ahc, SCSISEQ, 0);
1191 ahc_clear_msg_state(ahc);
1194 ahc_outb(ahc, SIMODE1, ahc_inb(ahc, SIMODE1) & ~ENBUSFREE);
1195 ahc_outb(ahc, CLRSINT1, CLRSELTIMEO|CLRBUSFREE|CLRSCSIPERR);
1205 ahc_outb(ahc, CLRSINT0, CLRSELINGO);
1207 scbptr = ahc_inb(ahc, WAITING_SCBH);
1208 ahc_outb(ahc, SCBPTR, scbptr);
1209 scb_index = ahc_inb(ahc, SCB_TAG);
1211 scb = ahc_lookup_scb(ahc, scb_index);
1215 ahc_name(ahc), scbptr, scb_index);
1216 ahc_dump_card_state(ahc);
1221 ahc_print_path(ahc, scb);
1226 ahc_scb_devinfo(ahc, &devinfo, scb);
1228 ahc_freeze_devq(ahc, scb);
1236 ahc_handle_devreset(ahc, &devinfo,
1241 ahc_outb(ahc, CLRINT, CLRSCSIINT);
1242 ahc_restart(ahc);
1244 && (ahc_inb(ahc, SIMODE1) & ENBUSFREE) != 0) {
1260 ahc_outb(ahc, SCSISEQ,
1261 ahc_inb(ahc, SCSISEQ) & (ENSELI|ENRSELI|ENAUTOATNP));
1269 ahc_outb(ahc, SIMODE1, ahc_inb(ahc, SIMODE1) & ~ENBUSFREE);
1270 ahc_outb(ahc, CLRSINT1, CLRBUSFREE|CLRSCSIPERR);
1278 lastphase = ahc_inb(ahc, LASTPHASE);
1279 saved_scsiid = ahc_inb(ahc, SAVED_SCSIID);
1280 saved_lun = ahc_inb(ahc, SAVED_LUN);
1281 target = SCSIID_TARGET(ahc, saved_scsiid);
1283 channel = SCSIID_CHANNEL(ahc, saved_scsiid);
1292 if (ahc_sent_msg(ahc, AHCMSG_1B, MSG_ABORT_TAG, TRUE)
1293 || ahc_sent_msg(ahc, AHCMSG_1B, MSG_ABORT, TRUE)) {
1294 if (ahc->msgout_buf[ahc->msgout_index - 1]
1297 ahc_print_path(ahc, scb);
1301 ahc_abort_scbs(ahc, target, channel,
1306 } else if (ahc_sent_msg(ahc, AHCMSG_1B,
1316 && ahc_match_scb(ahc, scb, target, channel,
1329 ahc_handle_devreset(ahc, &devinfo,
1334 } else if (ahc_sent_msg(ahc, AHCMSG_EXT,
1343 tinfo = ahc_fetch_transinfo(ahc,
1351 ahc_qinfifo_requeue_tail(ahc, scb);
1353 } else if (ahc_sent_msg(ahc, AHCMSG_EXT,
1359 ahc_set_width(ahc, &devinfo,
1363 ahc_qinfifo_requeue_tail(ahc, scb);
1365 } else if (ahc_sent_msg(ahc, AHCMSG_EXT,
1371 ahc_set_syncrate(ahc, &devinfo,
1377 ahc_qinfifo_requeue_tail(ahc, scb);
1391 ahc_print_path(ahc, scb);
1392 ahc_abort_scbs(ahc, target, channel,
1401 printf("%s: ", ahc_name(ahc));
1414 ahc_force_renegotiation(ahc, &devinfo);
1419 ahc_inb(ahc, SEQADDR0)
1420 | (ahc_inb(ahc, SEQADDR1) << 8));
1422 ahc_outb(ahc, CLRINT, CLRSCSIINT);
1423 ahc_restart(ahc);
1426 ahc_name(ahc), status);
1427 ahc_outb(ahc, CLRINT, CLRSCSIINT);
1436 ahc_force_renegotiation(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
1441 targ_info = ahc_fetch_transinfo(ahc,
1446 ahc_update_neg_request(ahc, devinfo, tstate,
1452 ahc_clear_critical_section(struct ahc_softc *ahc)
1459 if (ahc->num_critical_sections == 0)
1471 seqaddr = ahc_inb(ahc, SEQADDR0)
1472 | (ahc_inb(ahc, SEQADDR1) << 8);
1479 cs = ahc->critical_sections;
1480 for (i = 0; i < ahc->num_critical_sections; i++, cs++) {
1486 if (i == ahc->num_critical_sections)
1491 ahc_name(ahc));
1492 ahc_dump_card_state(ahc);
1505 simode0 = ahc_inb(ahc, SIMODE0);
1506 ahc_outb(ahc, SIMODE0, 0);
1507 simode1 = ahc_inb(ahc, SIMODE1);
1508 if ((ahc->features & AHC_DT) != 0)
1517 ahc_outb(ahc, SIMODE1, simode1 & ENBUSFREE);
1519 ahc_outb(ahc, SIMODE1, 0);
1520 ahc_outb(ahc, CLRINT, CLRSCSIINT);
1521 ahc_outb(ahc, SEQCTL, ahc->seqctl | STEP);
1524 if ((ahc->features & AHC_DT) != 0) {
1525 ahc_outb(ahc, CLRSINT1, CLRBUSFREE);
1526 ahc_outb(ahc, CLRINT, CLRSCSIINT);
1528 ahc_outb(ahc, HCNTRL, ahc->unpause);
1529 while (!ahc_is_paused(ahc))
1533 ahc_outb(ahc, SIMODE0, simode0);
1534 ahc_outb(ahc, SIMODE1, simode1);
1535 ahc_outb(ahc, SEQCTL, ahc->seqctl);
1543 ahc_clear_intstat(struct ahc_softc *ahc)
1546 ahc_outb(ahc, CLRSINT1, CLRSELTIMEO|CLRATNO|CLRSCSIRSTI
1549 ahc_flush_device_writes(ahc);
1550 ahc_outb(ahc, CLRSINT0, CLRSELDO|CLRSELDI|CLRSELINGO);
1551 ahc_flush_device_writes(ahc);
1552 ahc_outb(ahc, CLRINT, CLRSCSIINT);
1553 ahc_flush_device_writes(ahc);
1600 ahc_alloc_tstate(struct ahc_softc *ahc, u_int scsi_id, char channel)
1606 master_tstate = ahc->enabled_targets[ahc->our_id];
1609 master_tstate = ahc->enabled_targets[ahc->our_id_b + 8];
1611 if (ahc->enabled_targets[scsi_id] != NULL
1612 && ahc->enabled_targets[scsi_id] != master_tstate)
1614 ahc_name(ahc));
1636 ahc->enabled_targets[scsi_id] = tstate;
1646 ahc_free_tstate(struct ahc_softc *ahc, u_int scsi_id, char channel, int force)
1654 if (((channel == 'B' && scsi_id == ahc->our_id_b)
1655 || (channel == 'A' && scsi_id == ahc->our_id))
1661 tstate = ahc->enabled_targets[scsi_id];
1664 ahc->enabled_targets[scsi_id] = NULL;
1675 ahc_devlimited_syncrate(struct ahc_softc *ahc,
1682 if ((ahc->features & AHC_ULTRA2) != 0) {
1683 if ((ahc_inb(ahc, SBLKCTL) & ENAB40) != 0
1684 && (ahc_inb(ahc, SSTAT2) & EXP_ACTIVE) == 0) {
1691 } else if ((ahc->features & AHC_ULTRA) != 0) {
1721 return (ahc_find_syncrate(ahc, period, ppr_options, maxsync));
1730 ahc_find_syncrate(struct ahc_softc *ahc, u_int *period,
1735 if ((ahc->features & AHC_DT) == 0)
1751 if ((ahc->features & AHC_ULTRA2) != 0
1782 || ((ahc->features & AHC_ULTRA2) != 0
1797 ahc_find_period(struct ahc_softc *ahc, u_int scsirate, u_int maxsync)
1801 if ((ahc->features & AHC_ULTRA2) != 0)
1809 if ((ahc->features & AHC_ULTRA2) != 0) {
1827 ahc_validate_offset(struct ahc_softc *ahc,
1837 } else if ((ahc->features & AHC_ULTRA2) != 0) {
1859 ahc_validate_width(struct ahc_softc *ahc, struct ahc_initiator_tinfo *tinfo,
1864 if (ahc->features & AHC_WIDE) {
1889 ahc_update_neg_request(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
1903 if ((ahc->features & AHC_WIDE) != 0)
1932 ahc_set_syncrate(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
1952 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, devinfo->our_scsiid,
1979 if ((ahc->features & AHC_ULTRA2) != 0) {
2008 sxfrctl0 = ahc_inb(ahc, SXFRCTL0);
2012 ahc_outb(ahc, SXFRCTL0, sxfrctl0);
2016 ahc_outb(ahc, SCSIRATE, scsirate);
2017 if ((ahc->features & AHC_ULTRA2) != 0)
2018 ahc_outb(ahc, SCSIOFFSET, offset);
2026 ahc_send_async(ahc, devinfo->channel, devinfo->target,
2031 "offset = 0x%x\n", ahc_name(ahc),
2038 ahc_name(ahc), devinfo->target);
2043 update_needed += ahc_update_neg_request(ahc, devinfo, tstate,
2047 ahc_update_pending_scbs(ahc);
2059 ahc_set_width(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
2070 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, devinfo->our_scsiid,
2092 ahc_outb(ahc, SCSIRATE, scsirate);
2096 ahc_send_async(ahc, devinfo->channel, devinfo->target,
2100 ahc_name(ahc), devinfo->target,
2105 update_needed += ahc_update_neg_request(ahc, devinfo, tstate,
2108 ahc_update_pending_scbs(ahc);
2115 ahc_set_tags(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
2118 ahc_platform_set_tags(ahc, devinfo, alg);
2119 ahc_send_async(ahc, devinfo->channel, devinfo->target,
2129 ahc_update_pending_scbs(struct ahc_softc *ahc)
2142 LIST_FOREACH(pending_scb, &ahc->pending_scbs, pending_links) {
2148 ahc_scb_devinfo(ahc, &devinfo, pending_scb);
2149 tinfo = ahc_fetch_transinfo(ahc, devinfo.channel,
2163 ahc_sync_scb(ahc, pending_scb,
2171 if (ahc_is_paused(ahc)) {
2175 ahc_pause(ahc);
2178 saved_scbptr = ahc_inb(ahc, SCBPTR);
2180 for (i = 0; i < ahc->scb_data->maxhscbs; i++) {
2185 ahc_outb(ahc, SCBPTR, i);
2186 scb_tag = ahc_inb(ahc, SCB_TAG);
2187 pending_scb = ahc_lookup_scb(ahc, scb_tag);
2192 control = ahc_inb(ahc, SCB_CONTROL);
2195 ahc_outb(ahc, SCB_CONTROL, control);
2196 ahc_outb(ahc, SCB_SCSIRATE, pending_hscb->scsirate);
2197 ahc_outb(ahc, SCB_SCSIOFFSET, pending_hscb->scsioffset);
2199 ahc_outb(ahc, SCBPTR, saved_scbptr);
2202 ahc_unpause(ahc);
2207 ahc_fetch_devinfo(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
2213 if (ahc_inb(ahc, SSTAT0) & TARGET)
2219 && (ahc->features & AHC_MULTI_TID) != 0
2220 && (ahc_inb(ahc, SEQ_FLAGS)
2223 our_id = ahc_inb(ahc, TARGIDIN) & OID;
2224 } else if ((ahc->features & AHC_ULTRA2) != 0)
2225 our_id = ahc_inb(ahc, SCSIID_ULTRA2) & OID;
2227 our_id = ahc_inb(ahc, SCSIID) & OID;
2229 saved_scsiid = ahc_inb(ahc, SAVED_SCSIID);
2232 SCSIID_TARGET(ahc, saved_scsiid),
2233 ahc_inb(ahc, SAVED_LUN),
2234 SCSIID_CHANNEL(ahc, saved_scsiid),
2272 ahc_print_devinfo(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
2274 printf("%s:%c:%d:%d: ", ahc_name(ahc), devinfo->channel,
2279 ahc_scb_devinfo(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
2289 ahc_compile_devinfo(devinfo, our_id, SCB_GET_TARGET(ahc, scb),
2290 SCB_GET_LUN(scb), SCB_GET_CHANNEL(ahc, scb), role);
2296 ahc_assert_atn(struct ahc_softc *ahc)
2301 if ((ahc->features & AHC_DT) == 0)
2302 scsisigo |= ahc_inb(ahc, SCSISIGI);
2303 ahc_outb(ahc, SCSISIGO, scsisigo);
2313 ahc_setup_initiator_msgout(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
2321 ahc->msgout_index = 0;
2322 ahc->msgout_len = 0;
2325 && ahc_inb(ahc, MSG_OUT) == MSG_IDENTIFYFLAG) {
2331 ahc->msgout_buf[ahc->msgout_index++] = identify_msg;
2332 ahc->msgout_len++;
2335 ahc->msgout_buf[ahc->msgout_index++] =
2337 ahc->msgout_buf[ahc->msgout_index++] = scb->hscb->tag;
2338 ahc->msgout_len += 2;
2343 ahc->msgout_buf[ahc->msgout_index++] = MSG_BUS_DEV_RESET;
2344 ahc->msgout_len++;
2345 ahc_print_path(ahc, scb);
2354 ahc_outb(ahc, SCSISEQ, (ahc_inb(ahc, SCSISEQ) & ~ENSELO));
2357 ahc->msgout_buf[ahc->msgout_index++] = MSG_ABORT_TAG;
2359 ahc->msgout_buf[ahc->msgout_index++] = MSG_ABORT;
2360 ahc->msgout_len++;
2361 ahc_print_path(ahc, scb);
2371 ahc_outb(ahc, SCSISEQ, (ahc_inb(ahc, SCSISEQ) & ~ENSELO));
2373 ahc_build_transfer_msg(ahc, devinfo);
2381 ahc_inb(ahc, MSG_OUT), scb->flags);
2388 ahc_outb(ahc, SCB_CONTROL, ahc_inb(ahc, SCB_CONTROL) & ~MK_MESSAGE);
2390 ahc->msgout_index = 0;
2391 ahc->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
2399 ahc_build_transfer_msg(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
2416 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, devinfo->our_scsiid,
2430 rate = ahc_devlimited_syncrate(ahc, tinfo, &period,
2451 if ((ahc->features & AHC_WIDE) != 0)
2457 ahc_print_devinfo(ahc, devinfo);
2477 ahc_validate_offset(ahc, tinfo, rate, &offset,
2482 ahc_construct_ppr(ahc, devinfo, period, offset,
2485 ahc_construct_sdtr(ahc, devinfo, period, offset);
2488 ahc_construct_wdtr(ahc, devinfo, tinfo->goal.width);
2497 ahc_construct_sdtr(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
2502 ahc->msgout_buf[ahc->msgout_index++] = MSG_EXTENDED;
2503 ahc->msgout_buf[ahc->msgout_index++] = MSG_EXT_SDTR_LEN;
2504 ahc->msgout_buf[ahc->msgout_index++] = MSG_EXT_SDTR;
2505 ahc->msgout_buf[ahc->msgout_index++] = period;
2506 ahc->msgout_buf[ahc->msgout_index++] = offset;
2507 ahc->msgout_len += 5;
2510 ahc_name(ahc), devinfo->channel, devinfo->target,
2520 ahc_construct_wdtr(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
2523 ahc->msgout_buf[ahc->msgout_index++] = MSG_EXTENDED;
2524 ahc->msgout_buf[ahc->msgout_index++] = MSG_EXT_WDTR_LEN;
2525 ahc->msgout_buf[ahc->msgout_index++] = MSG_EXT_WDTR;
2526 ahc->msgout_buf[ahc->msgout_index++] = bus_width;
2527 ahc->msgout_len += 4;
2530 ahc_name(ahc), devinfo->channel, devinfo->target,
2540 ahc_construct_ppr(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
2546 ahc->msgout_buf[ahc->msgout_index++] = MSG_EXTENDED;
2547 ahc->msgout_buf[ahc->msgout_index++] = MSG_EXT_PPR_LEN;
2548 ahc->msgout_buf[ahc->msgout_index++] = MSG_EXT_PPR;
2549 ahc->msgout_buf[ahc->msgout_index++] = period;
2550 ahc->msgout_buf[ahc->msgout_index++] = 0;
2551 ahc->msgout_buf[ahc->msgout_index++] = offset;
2552 ahc->msgout_buf[ahc->msgout_index++] = bus_width;
2553 ahc->msgout_buf[ahc->msgout_index++] = ppr_options;
2554 ahc->msgout_len += 8;
2557 "offset %x, ppr_options %x\n", ahc_name(ahc),
2567 ahc_clear_msg_state(struct ahc_softc *ahc)
2569 ahc->msgout_len = 0;
2570 ahc->msgin_index = 0;
2571 ahc->msg_type = MSG_TYPE_NONE;
2572 if ((ahc_inb(ahc, SCSISIGI) & ATNI) != 0) {
2577 ahc_outb(ahc, CLRSINT1, CLRATNO);
2579 ahc_outb(ahc, MSG_OUT, MSG_NOOP);
2580 ahc_outb(ahc, SEQ_FLAGS2,
2581 ahc_inb(ahc, SEQ_FLAGS2) & ~TARGET_MSG_PENDING);
2585 ahc_handle_proto_violation(struct ahc_softc *ahc)
2595 ahc_fetch_devinfo(ahc, &devinfo);
2596 scbid = ahc_inb(ahc, SCB_TAG);
2597 scb = ahc_lookup_scb(ahc, scbid);
2598 seq_flags = ahc_inb(ahc, SEQ_FLAGS);
2599 curphase = ahc_inb(ahc, SCSISIGI) & PHASE_MASK;
2600 lastphase = ahc_inb(ahc, LASTPHASE);
2608 ahc_print_devinfo(ahc, &devinfo);
2617 ahc_print_devinfo(ahc, &devinfo);
2623 ahc_print_path(ahc, scb);
2625 } else if ((ahc_inb(ahc, SCB_CONTROL) & STATUS_RCVD) == 0) {
2633 ahc_print_path(ahc, scb);
2636 ahc_print_path(ahc, scb);
2638 ahc_dump_card_state(ahc);
2650 found = ahc_reset_channel(ahc, 'A', TRUE);
2652 "%d SCBs aborted\n", ahc_name(ahc), 'A', found);
2659 ahc_outb(ahc, SCSISEQ,
2660 ahc_inb(ahc, SCSISEQ) & ~ENSELO);
2661 ahc_assert_atn(ahc);
2662 ahc_outb(ahc, MSG_OUT, HOST_MSG);
2664 ahc_print_devinfo(ahc, &devinfo);
2665 ahc->msgout_buf[0] = MSG_ABORT_TASK;
2666 ahc->msgout_len = 1;
2667 ahc->msgout_index = 0;
2668 ahc->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
2670 ahc_print_path(ahc, scb);
2682 ahc_handle_message_phase(struct ahc_softc *ahc)
2688 ahc_fetch_devinfo(ahc, &devinfo);
2690 bus_phase = ahc_inb(ahc, SCSISIGI) & PHASE_MASK;
2693 switch (ahc->msg_type) {
2700 if (ahc->msgout_len == 0)
2705 ahc_print_devinfo(ahc, &devinfo);
2725 ahc_outb(ahc, CLRSINT1, CLRATNO);
2726 ahc->send_msg_perror = FALSE;
2727 ahc->msg_type = MSG_TYPE_INITIATOR_MSGIN;
2728 ahc->msgin_index = 0;
2735 if (ahc->send_msg_perror) {
2736 ahc_outb(ahc, CLRSINT1, CLRATNO);
2737 ahc_outb(ahc, CLRSINT1, CLRREQINIT);
2740 printf(" byte 0x%x\n", ahc->send_msg_perror);
2742 ahc_outb(ahc, SCSIDATL, MSG_PARITY_ERROR);
2746 msgdone = ahc->msgout_index == ahc->msgout_len;
2753 ahc->msgout_index = 0;
2754 ahc_assert_atn(ahc);
2757 lastbyte = ahc->msgout_index == (ahc->msgout_len - 1);
2760 ahc_outb(ahc, CLRSINT1, CLRATNO);
2767 ahc_outb(ahc, CLRSINT1, CLRREQINIT);
2771 ahc->msgout_buf[ahc->msgout_index]);
2773 ahc_outb(ahc, SCSIDATL, ahc->msgout_buf[ahc->msgout_index++]);
2783 ahc_print_devinfo(ahc, &devinfo);
2796 ahc->msgin_index = 0;
2798 && (ahc->send_msg_perror == TRUE
2799 || (ahc->msgout_len != 0
2800 && ahc->msgout_index == 0))) {
2801 ahc->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
2809 ahc->msgin_buf[ahc->msgin_index] = ahc_inb(ahc, SCSIBUSL);
2813 ahc->msgin_buf[ahc->msgin_index]);
2816 message_done = ahc_parse_msg(ahc, &devinfo);
2823 ahc->msgin_index = 0;
2830 if (ahc->msgout_len != 0) {
2833 ahc_print_devinfo(ahc, &devinfo);
2837 ahc_assert_atn(ahc);
2840 ahc->msgin_index++;
2846 ahc_outb(ahc, CLRSINT1, CLRREQINIT);
2847 ahc_inb(ahc, SCSIDATL);
2856 if (ahc->msgout_len == 0)
2865 if ((ahc_inb(ahc, SCSISIGI) & ATNI) != 0
2866 && ahc->msgout_index > 0)
2879 ahc->msg_type = MSG_TYPE_TARGET_MSGOUT;
2880 ahc_outb(ahc, SCSISIGO, P_MESGOUT | BSYO);
2881 ahc->msgin_index = 0;
2883 ahc_inb(ahc, SCSIDATL);
2884 ahc_outb(ahc, SXFRCTL0,
2885 ahc_inb(ahc, SXFRCTL0) | SPIOEN);
2889 msgdone = ahc->msgout_index == ahc->msgout_len;
2891 ahc_outb(ahc, SXFRCTL0,
2892 ahc_inb(ahc, SXFRCTL0) & ~SPIOEN);
2900 ahc_outb(ahc, SXFRCTL0, ahc_inb(ahc, SXFRCTL0) | SPIOEN);
2901 ahc_outb(ahc, SCSIDATL, ahc->msgout_buf[ahc->msgout_index++]);
2913 lastbyte = (ahc_inb(ahc, SCSISIGI) & ATNI) == 0;
2920 ahc_outb(ahc, SXFRCTL0, ahc_inb(ahc, SXFRCTL0) & ~SPIOEN);
2921 ahc->msgin_buf[ahc->msgin_index] = ahc_inb(ahc, SCSIDATL);
2922 msgdone = ahc_parse_msg(ahc, &devinfo);
2933 ahc->msgin_index++;
2940 ahc->msgin_index = 0;
2946 if (ahc->msgout_len != 0) {
2947 ahc_outb(ahc, SCSISIGO, P_MESGIN | BSYO);
2948 ahc_outb(ahc, SXFRCTL0,
2949 ahc_inb(ahc, SXFRCTL0) | SPIOEN);
2950 ahc->msg_type = MSG_TYPE_TARGET_MSGIN;
2951 ahc->msgin_index = 0;
2960 ahc_outb(ahc, SXFRCTL0,
2961 ahc_inb(ahc, SXFRCTL0) | SPIOEN);
2971 ahc_clear_msg_state(ahc);
2972 ahc_outb(ahc, RETURN_1, EXIT_MSG_LOOP);
2974 ahc_outb(ahc, RETURN_1, CONT_MSG_LOOP);
2984 ahc_sent_msg(struct ahc_softc *ahc, ahc_msgtype type, u_int msgval, int full)
2992 while (index < ahc->msgout_len) {
2993 if (ahc->msgout_buf[index] == MSG_EXTENDED) {
2996 end_index = index + 1 + ahc->msgout_buf[index + 1];
2997 if (ahc->msgout_buf[index+2] == msgval
3001 if (ahc->msgout_index > end_index)
3003 } else if (ahc->msgout_index > index)
3007 } else if (ahc->msgout_buf[index] >= MSG_SIMPLE_TASK
3008 && ahc->msgout_buf[index] <= MSG_IGN_WIDE_RESIDUE) {
3015 && ahc->msgout_buf[index] == msgval
3016 && ahc->msgout_index > index)
3031 ahc_parse_msg(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
3043 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, devinfo->our_scsiid,
3058 switch (ahc->msgin_buf[0]) {
3071 response = ahc_handle_msg_reject(ahc, devinfo);
3079 if (ahc->msgin_index < 2)
3081 switch (ahc->msgin_buf[2]) {
3090 if (ahc->msgin_buf[1] != MSG_EXT_SDTR_LEN) {
3102 if (ahc->msgin_index < (MSG_EXT_SDTR_LEN + 1))
3105 period = ahc->msgin_buf[3];
3107 saved_offset = offset = ahc->msgin_buf[4];
3108 syncrate = ahc_devlimited_syncrate(ahc, tinfo, &period,
3111 ahc_validate_offset(ahc, tinfo, syncrate, &offset,
3118 ahc_name(ahc), devinfo->channel,
3120 ahc->msgin_buf[3], saved_offset,
3123 ahc_set_syncrate(ahc, devinfo,
3134 if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_SDTR, TRUE)) {
3148 ahc_name(ahc), devinfo->channel,
3151 ahc->msgout_index = 0;
3152 ahc->msgout_len = 0;
3153 ahc_construct_sdtr(ahc, devinfo,
3155 ahc->msgout_index = 0;
3168 if (ahc->msgin_buf[1] != MSG_EXT_WDTR_LEN) {
3180 if (ahc->msgin_index < (MSG_EXT_WDTR_LEN + 1))
3183 bus_width = ahc->msgin_buf[3];
3185 ahc_validate_width(ahc, tinfo, &bus_width,
3190 ahc_name(ahc), devinfo->channel,
3195 if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_WDTR, TRUE)) {
3206 ahc_name(ahc), devinfo->channel,
3219 ahc_name(ahc), devinfo->channel,
3222 ahc->msgout_index = 0;
3223 ahc->msgout_len = 0;
3224 ahc_construct_wdtr(ahc, devinfo, bus_width);
3225 ahc->msgout_index = 0;
3238 ahc_update_neg_request(ahc, devinfo, tstate,
3240 ahc_set_width(ahc, devinfo, bus_width,
3248 ahc->msgout_index = 0;
3249 ahc->msgout_len = 0;
3250 ahc_build_transfer_msg(ahc, devinfo);
3251 ahc->msgout_index = 0;
3268 if (ahc->msgin_buf[1] != MSG_EXT_PPR_LEN) {
3280 if (ahc->msgin_index < (MSG_EXT_PPR_LEN + 1))
3283 period = ahc->msgin_buf[3];
3284 offset = ahc->msgin_buf[5];
3285 bus_width = ahc->msgin_buf[6];
3287 ppr_options = ahc->msgin_buf[7];
3308 ahc_validate_width(ahc, tinfo, &bus_width,
3310 syncrate = ahc_devlimited_syncrate(ahc, tinfo, &period,
3313 ahc_validate_offset(ahc, tinfo, syncrate,
3317 if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_PPR, TRUE)) {
3337 ahc_name(ahc), devinfo->channel,
3342 ahc_name(ahc), devinfo->channel,
3344 ahc->msgout_index = 0;
3345 ahc->msgout_len = 0;
3346 ahc_construct_ppr(ahc, devinfo, period, offset,
3348 ahc->msgout_index = 0;
3356 ahc_name(ahc), devinfo->channel,
3358 saved_width, ahc->msgin_buf[3],
3362 ahc_set_width(ahc, devinfo, bus_width,
3365 ahc_set_syncrate(ahc, devinfo,
3382 ahc_handle_devreset(ahc, devinfo,
3386 ahc_restart(ahc);
3401 if (ahc->msgin_buf[0] == MSG_ABORT_TAG)
3402 tag = ahc_inb(ahc, INITIATOR_TAG);
3403 ahc_abort_scbs(ahc, devinfo->target, devinfo->channel,
3407 tstate = ahc->enabled_targets[devinfo->our_scsiid];
3413 ahc_queue_lstate_event(ahc, lstate,
3415 ahc->msgin_buf[0],
3417 ahc_send_lstate_events(ahc, lstate);
3420 ahc_restart(ahc);
3435 ahc->msgout_index = 0;
3436 ahc->msgout_len = 1;
3437 ahc->msgout_buf[0] = MSG_MESSAGE_REJECT;
3444 ahc->msgout_len = 0;
3453 ahc_handle_msg_reject(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
3468 scb_index = ahc_inb(ahc, SCB_TAG);
3469 scb = ahc_lookup_scb(ahc, scb_index);
3470 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel,
3474 last_msg = ahc_inb(ahc, LAST_MSG);
3476 if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_PPR, /*full*/FALSE)) {
3484 ahc_name(ahc), devinfo->channel,
3490 ahc->msgout_index = 0;
3491 ahc->msgout_len = 0;
3492 ahc_build_transfer_msg(ahc, devinfo);
3493 ahc->msgout_index = 0;
3495 } else if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_WDTR, /*full*/FALSE)) {
3499 "8bit transfers\n", ahc_name(ahc),
3501 ahc_set_width(ahc, devinfo, MSG_EXT_WDTR_BUS_8_BIT,
3514 ahc->msgout_index = 0;
3515 ahc->msgout_len = 0;
3516 ahc_build_transfer_msg(ahc, devinfo);
3517 ahc->msgout_index = 0;
3520 } else if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_SDTR, /*full*/FALSE)) {
3522 ahc_set_syncrate(ahc, devinfo, /*syncrate*/NULL, /*period*/0,
3528 ahc_name(ahc), devinfo->channel,
3538 "Performing non-tagged I/O\n", ahc_name(ahc),
3540 ahc_set_tags(ahc, devinfo, AHC_QUEUE_NONE);
3545 ahc_name(ahc), devinfo->channel, devinfo->target,
3548 ahc_set_tags(ahc, devinfo, AHC_QUEUE_BASIC);
3556 ahc_outb(ahc, SCB_CONTROL,
3557 ahc_inb(ahc, SCB_CONTROL) & mask);
3561 ahc_outb(ahc, MSG_OUT, MSG_IDENTIFYFLAG);
3562 ahc_assert_atn(ahc);
3568 if ((ahc->flags & AHC_SCB_BTT) == 0) {
3572 &(ahc->untagged_queues[devinfo->target_offset]);
3576 ahc_busy_tcl(ahc, BUILD_TCL(scb->hscb->scsiid, devinfo->lun),
3584 ahc_search_qinfifo(ahc, SCB_GET_TARGET(ahc, scb),
3585 SCB_GET_CHANNEL(ahc, scb),
3594 ahc_name(ahc), devinfo->channel, devinfo->target,
3604 ahc_handle_ign_wide_residue(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
3609 scb_index = ahc_inb(ahc, SCB_TAG);
3610 scb = ahc_lookup_scb(ahc, scb_index);
3615 if ((ahc_inb(ahc, SEQ_FLAGS) & DPHASE) == 0
3631 sgptr = ahc_inb(ahc, SCB_RESIDUAL_SGPTR);
3633 && (ahc_inb(ahc, SCB_LUN) & SCB_XFERLEN_ODD) != 0) {
3647 sgptr = ahc_inl(ahc, SCB_RESIDUAL_SGPTR);
3648 data_cnt = ahc_inl(ahc, SCB_RESIDUAL_DATACNT);
3659 data_addr = ahc_inl(ahc, SHADDR);
3693 ahc_outl(ahc, SCB_RESIDUAL_SGPTR, sgptr);
3694 ahc_outl(ahc, SCB_RESIDUAL_DATACNT, data_cnt);
3701 ahc_outb(ahc, SCB_LUN,
3702 ahc_inb(ahc, SCB_LUN) ^ SCB_XFERLEN_ODD);
3713 ahc_reinitialize_dataptrs(struct ahc_softc *ahc)
3722 scb_index = ahc_inb(ahc, SCB_TAG);
3723 scb = ahc_lookup_scb(ahc, scb_index);
3724 sgptr = (ahc_inb(ahc, SCB_RESIDUAL_SGPTR + 3) << 24)
3725 | (ahc_inb(ahc, SCB_RESIDUAL_SGPTR + 2) << 16)
3726 | (ahc_inb(ahc, SCB_RESIDUAL_SGPTR + 1) << 8)
3727 | ahc_inb(ahc, SCB_RESIDUAL_SGPTR);
3735 resid = (ahc_inb(ahc, SCB_RESIDUAL_DATACNT + 2) << 16)
3736 | (ahc_inb(ahc, SCB_RESIDUAL_DATACNT + 1) << 8)
3737 | ahc_inb(ahc, SCB_RESIDUAL_DATACNT);
3742 if ((ahc->flags & AHC_39BIT_ADDRESSING) != 0) {
3745 dscommand1 = ahc_inb(ahc, DSCOMMAND1);
3746 ahc_outb(ahc, DSCOMMAND1, dscommand1 | HADDLDSEL0);
3747 ahc_outb(ahc, HADDR,
3749 ahc_outb(ahc, DSCOMMAND1, dscommand1);
3751 ahc_outb(ahc, HADDR + 3, dataptr >> 24);
3752 ahc_outb(ahc, HADDR + 2, dataptr >> 16);
3753 ahc_outb(ahc, HADDR + 1, dataptr >> 8);
3754 ahc_outb(ahc, HADDR, dataptr);
3755 ahc_outb(ahc, HCNT + 2, resid >> 16);
3756 ahc_outb(ahc, HCNT + 1, resid >> 8);
3757 ahc_outb(ahc, HCNT, resid);
3758 if ((ahc->features & AHC_ULTRA2) == 0) {
3759 ahc_outb(ahc, STCNT + 2, resid >> 16);
3760 ahc_outb(ahc, STCNT + 1, resid >> 8);
3761 ahc_outb(ahc, STCNT, resid);
3769 ahc_handle_devreset(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
3778 found = ahc_abort_scbs(ahc, devinfo->target, devinfo->channel,
3787 tstate = ahc->enabled_targets[devinfo->our_scsiid];
3796 ahc_queue_lstate_event(ahc, lstate, devinfo->our_scsiid,
3798 ahc_send_lstate_events(ahc, lstate);
3806 ahc_set_width(ahc, devinfo, MSG_EXT_WDTR_BUS_8_BIT,
3808 ahc_set_syncrate(ahc, devinfo, /*syncrate*/NULL,
3813 ahc_send_async(ahc, devinfo->channel, devinfo->target,
3818 printf("%s: %s on %c:%d. %d SCBs aborted\n", ahc_name(ahc),
3824 ahc_setup_target_msgin(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
3833 ahc->msgout_index = 0;
3834 ahc->msgout_len = 0;
3837 ahc_build_transfer_msg(ahc, devinfo);
3841 ahc->msgout_index = 0;
3842 ahc->msg_type = MSG_TYPE_TARGET_MSGIN;
3847 ahc_softc_init(struct ahc_softc *ahc)
3851 if ((ahc->chip & AHC_PCI) == 0)
3852 ahc->unpause = ahc_inb(ahc, HCNTRL) & IRQMS;
3854 ahc->unpause = 0;
3855 ahc->pause = ahc->unpause | PAUSE;
3857 if (ahc->scb_data == NULL) {
3858 ahc->scb_data = malloc(sizeof(*ahc->scb_data), M_DEVBUF,
3860 if (ahc->scb_data == NULL)
3868 ahc_softc_insert(struct ahc_softc *ahc)
3877 if ((ahc->chip & AHC_BUS_MASK) == AHC_PCI
3878 && (ahc->features & AHC_MULTI_FUNC) != 0) {
3884 pci = ahc->dev_softc;
3892 slave = ahc;
3894 master = ahc;
3914 && ahc_softc_comp(ahc, list_ahc) <= 0)
3917 TAILQ_INSERT_BEFORE(list_ahc, ahc, links);
3919 TAILQ_INSERT_TAIL(&ahc_tailq, ahc, links);
3920 ahc->init_level++;
3924 ahc_set_unit(struct ahc_softc *ahc, int unit)
3926 ahc->unit = unit;
3930 ahc_set_name(struct ahc_softc *ahc, char *name)
3932 ahc->name = name;
3936 ahc_free(struct ahc_softc *ahc)
3940 switch (ahc->init_level) {
3943 ahc_shutdown(ahc);
3946 bus_dmamap_unload(ahc->parent_dmat, ahc->shared_data_dmamap);
3947 bus_dmamap_destroy(ahc->parent_dmat, ahc->shared_data_dmamap);
3948 bus_dmamem_unmap(ahc->parent_dmat, (caddr_t)ahc->qoutfifo, ahc->shared_data_size);
3949 bus_dmamem_free(ahc->parent_dmat, &ahc->shared_data_seg, ahc->shared_data_nseg);
3955 ahc_fini_scbdata(ahc);
3959 tstate = ahc->enabled_targets[i];
3978 if (ahc->black_hole != NULL) {
3979 /*xpt_free_path(ahc->black_hole->path);*/
3980 free(ahc->black_hole, M_DEVBUF, sizeof(*ahc->black_hole));
3983 if (ahc->seep_config != NULL)
3984 free(ahc->seep_config, M_DEVBUF, sizeof(*ahc->seep_config));
3991 struct ahc_softc *ahc;
3994 ahc = (struct ahc_softc *)arg;
3997 ahc_reset(ahc, /*reinit*/FALSE);
3998 ahc_outb(ahc, SCSISEQ, 0);
3999 ahc_outb(ahc, SXFRCTL0, 0);
4000 ahc_outb(ahc, DSPCISTATUS, 0);
4003 ahc_outb(ahc, i, 0);
4016 ahc_reset(struct ahc_softc *ahc, int reinit)
4028 ahc_pause(ahc);
4030 if ((ahc->chip & AHC_CHIPID_MASK) == AHC_AIC7770) {
4035 sblkctl = ahc_inb(ahc, SBLKCTL);
4036 ahc_outb(ahc, SBLKCTL, sblkctl | SELBUSB);
4037 sxfrctl1_b = ahc_inb(ahc, SXFRCTL1);
4038 ahc_outb(ahc, SBLKCTL, sblkctl & ~SELBUSB);
4040 sxfrctl1_a = ahc_inb(ahc, SXFRCTL1);
4042 ahc_outb(ahc, HCNTRL, CHIPRST | ahc->pause);
4053 } while (--wait && !(ahc_inb(ahc, HCNTRL) & CHIPRSTACK));
4057 "Trying to initialize anyway.\n", ahc_name(ahc));
4059 ahc_outb(ahc, HCNTRL, ahc->pause);
4062 sblkctl = ahc_inb(ahc, SBLKCTL) & (SELBUSB|SELWIDE);
4064 if ((ahc->chip & AHC_PCI) != 0)
4072 ahc->features |= AHC_WIDE;
4076 ahc->features |= AHC_TWIN;
4091 if ((ahc->features & AHC_TWIN) != 0) {
4092 sblkctl = ahc_inb(ahc, SBLKCTL);
4093 ahc_outb(ahc, SBLKCTL, sblkctl | SELBUSB);
4094 ahc_outb(ahc, SXFRCTL1, sxfrctl1_b);
4095 ahc_outb(ahc, SBLKCTL, sblkctl & ~SELBUSB);
4097 ahc_outb(ahc, SXFRCTL1, sxfrctl1_a);
4105 error = ahc->bus_chip_init(ahc);
4108 ahc_dumpseq(ahc);
4118 ahc_probe_scbs(struct ahc_softc *ahc) {
4123 ahc_outb(ahc, SCBPTR, i);
4124 ahc_outb(ahc, SCB_BASE, i);
4125 if (ahc_inb(ahc, SCB_BASE) != i)
4127 ahc_outb(ahc, SCBPTR, 0);
4128 if (ahc_inb(ahc, SCB_BASE) != 0)
4146 ahc_build_free_scb_list(struct ahc_softc *ahc)
4152 if ((ahc->flags & AHC_LSCBS_ENABLED) != 0)
4155 for (i = 0; i < ahc->scb_data->maxhscbs; i++) {
4158 ahc_outb(ahc, SCBPTR, i);
4166 ahc_outb(ahc, SCB_BASE+j, 0xFF);
4169 ahc_outb(ahc, SCB_CONTROL, 0);
4172 if ((ahc->flags & AHC_PAGESCBS) != 0)
4173 ahc_outb(ahc, SCB_NEXT, i+1);
4175 ahc_outb(ahc, SCB_NEXT, SCB_LIST_NULL);
4178 ahc_outb(ahc, SCB_TAG, SCB_LIST_NULL);
4179 ahc_outb(ahc, SCB_SCSIID, 0xFF);
4180 ahc_outb(ahc, SCB_LUN, 0xFF);
4183 if ((ahc->flags & AHC_PAGESCBS) != 0) {
4185 ahc_outb(ahc, FREE_SCBH, 0);
4188 ahc_outb(ahc, FREE_SCBH, SCB_LIST_NULL);
4192 ahc_outb(ahc, SCBPTR, i-1);
4193 ahc_outb(ahc, SCB_NEXT, SCB_LIST_NULL);
4197 ahc_init_scbdata(struct ahc_softc *ahc)
4202 scb_data = ahc->scb_data;
4206 mtx_init(&ahc->sc_scb_mtx, IPL_BIO);
4207 scsi_iopool_init(&ahc->sc_iopool, ahc, ahc_scb_alloc, ahc_scb_free);
4217 scb_data->maxhscbs = ahc_probe_scbs(ahc);
4218 if (ahc->scb_data->maxhscbs == 0) {
4219 printf("%s: No SCB space found\n", ahc_name(ahc));
4233 if (ahc_createdmamem(ahc->parent_dmat,
4234 AHC_SCB_MAX * sizeof(struct hardware_scb), ahc->sc_dmaflags,
4237 &scb_data->hscb_seg, &scb_data->hscb_nseg, ahc_name(ahc),
4243 if (ahc_createdmamem(ahc->parent_dmat,
4244 AHC_SCB_MAX * sizeof(struct scsi_sense_data), ahc->sc_dmaflags,
4247 &scb_data->sense_nseg, ahc_name(ahc), "sense buffers") < 0)
4257 ahc_alloc_scbs(ahc);
4264 ahc_name(ahc));
4271 ahc->next_queued_scb = scsi_io_get(&ahc->sc_iopool,
4273 if (ahc->next_queued_scb != NULL)
4283 ahc_fini_scbdata(struct ahc_softc *ahc)
4287 scb_data = ahc->scb_data;
4299 ahc_freedmamem(ahc->parent_dmat, PAGE_SIZE,
4307 ahc_freedmamem(ahc->parent_dmat,
4313 ahc_freedmamem(ahc->parent_dmat,
4330 ahc_alloc_scbs(struct ahc_softc *ahc)
4340 scb_data = ahc->scb_data;
4353 if (ahc_createdmamem(ahc->parent_dmat, PAGE_SIZE, ahc->sc_dmaflags,
4356 &sg_map->sg_dmasegs, &sg_map->sg_nseg, ahc_name(ahc),
4379 next_scb->ahc_softc = ahc;
4382 error = bus_dmamap_create(ahc->parent_dmat,
4384 BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW|ahc->sc_dmaflags,
4390 next_scb->hscb->tag = ahc->scb_data->numscbs;
4391 mtx_enter(&ahc->sc_scb_mtx);
4392 SLIST_INSERT_HEAD(&ahc->scb_data->free_scbs,
4394 mtx_leave(&ahc->sc_scb_mtx);
4398 ahc->scb_data->numscbs++;
4404 ahc_controller_info(struct ahc_softc *ahc, char *buf, size_t buf_len)
4409 ahc_chip_names[ahc->chip & AHC_CHIPID_MASK]);
4411 if ((ahc->features & AHC_TWIN) != 0)
4414 (ahc->flags & AHC_PRIMARY_CHANNEL) + 'A');
4420 if ((ahc->features & AHC_ULTRA) != 0) {
4422 } else if ((ahc->features & AHC_DT) != 0) {
4424 } else if ((ahc->features & AHC_ULTRA2) != 0) {
4427 if ((ahc->features & AHC_WIDE) != 0) {
4434 speed, type, ahc->channel);
4438 if ((ahc->flags & AHC_PAGESCBS) != 0)
4440 ahc->scb_data->maxhscbs, AHC_MAX_QUEUE);
4443 ahc->scb_data->maxhscbs);
4448 ahc_chip_init(struct ahc_softc *ahc)
4457 ahc_outb(ahc, SEQ_FLAGS, 0);
4458 ahc_outb(ahc, SEQ_FLAGS2, 0);
4461 if (ahc->features & AHC_TWIN) {
4466 ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) | SELBUSB);
4467 term = (ahc->flags & AHC_TERM_ENB_B) != 0 ? STPWEN : 0;
4468 ahc_outb(ahc, SCSIID, ahc->our_id_b);
4469 scsi_conf = ahc_inb(ahc, SCSICONF + 1);
4470 ahc_outb(ahc, SXFRCTL1, (scsi_conf & (ENSPCHK|STIMESEL))
4471 |term|ahc->seltime_b|ENSTIMER|ACTNEGEN);
4472 if ((ahc->features & AHC_ULTRA2) != 0)
4473 ahc_outb(ahc, SIMODE0, ahc_inb(ahc, SIMODE0)|ENIOERR);
4474 ahc_outb(ahc, SIMODE1, ENSELTIMO|ENSCSIRST|ENSCSIPERR);
4475 ahc_outb(ahc, SXFRCTL0, DFON|SPIOEN);
4478 ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) & ~SELBUSB);
4480 term = (ahc->flags & AHC_TERM_ENB_A) != 0 ? STPWEN : 0;
4481 if ((ahc->features & AHC_ULTRA2) != 0)
4482 ahc_outb(ahc, SCSIID_ULTRA2, ahc->our_id);
4484 ahc_outb(ahc, SCSIID, ahc->our_id);
4485 scsi_conf = ahc_inb(ahc, SCSICONF);
4486 ahc_outb(ahc, SXFRCTL1, (scsi_conf & (ENSPCHK|STIMESEL))
4487 |term|ahc->seltime
4489 if ((ahc->features & AHC_ULTRA2) != 0)
4490 ahc_outb(ahc, SIMODE0, ahc_inb(ahc, SIMODE0)|ENIOERR);
4491 ahc_outb(ahc, SIMODE1, ENSELTIMO|ENSCSIRST|ENSCSIPERR);
4492 ahc_outb(ahc, SXFRCTL0, DFON|SPIOEN);
4496 ahc_unbusy_tcl(ahc, BUILD_TCL(i << 4, 0));
4497 if ((ahc->flags & AHC_SCB_BTT) != 0) {
4505 ahc_unbusy_tcl(ahc, BUILD_TCL(i << 4, lun));
4511 ahc->qoutfifo[i] = SCB_LIST_NULL;
4512 ahc_sync_qoutfifo(ahc, BUS_DMASYNC_PREREAD);
4514 ahc->qinfifo[i] = SCB_LIST_NULL;
4516 if ((ahc->features & AHC_MULTI_TID) != 0) {
4517 ahc_outb(ahc, TARGID, 0);
4518 ahc_outb(ahc, TARGID + 1, 0);
4524 physaddr = ahc->scb_data->hscb_busaddr;
4525 ahc_outb(ahc, HSCB_ADDR, physaddr & 0xFF);
4526 ahc_outb(ahc, HSCB_ADDR + 1, (physaddr >> 8) & 0xFF);
4527 ahc_outb(ahc, HSCB_ADDR + 2, (physaddr >> 16) & 0xFF);
4528 ahc_outb(ahc, HSCB_ADDR + 3, (physaddr >> 24) & 0xFF);
4530 physaddr = ahc->shared_data_busaddr;
4531 ahc_outb(ahc, SHARED_DATA_ADDR, physaddr & 0xFF);
4532 ahc_outb(ahc, SHARED_DATA_ADDR + 1, (physaddr >> 8) & 0xFF);
4533 ahc_outb(ahc, SHARED_DATA_ADDR + 2, (physaddr >> 16) & 0xFF);
4534 ahc_outb(ahc, SHARED_DATA_ADDR + 3, (physaddr >> 24) & 0xFF);
4541 ahc_outb(ahc, CMDSIZE_TABLE, 5);
4542 ahc_outb(ahc, CMDSIZE_TABLE + 1, 9);
4543 ahc_outb(ahc, CMDSIZE_TABLE + 2, 9);
4544 ahc_outb(ahc, CMDSIZE_TABLE + 3, 0);
4545 ahc_outb(ahc, CMDSIZE_TABLE + 4, 15);
4546 ahc_outb(ahc, CMDSIZE_TABLE + 5, 11);
4547 ahc_outb(ahc, CMDSIZE_TABLE + 6, 0);
4548 ahc_outb(ahc, CMDSIZE_TABLE + 7, 0);
4550 if ((ahc->features & AHC_HS_MAILBOX) != 0)
4551 ahc_outb(ahc, HS_MAILBOX, 0);
4554 if ((ahc->features & AHC_TARGETMODE) != 0) {
4555 ahc->tqinfifonext = 1;
4556 ahc_outb(ahc, KERNEL_TQINPOS, ahc->tqinfifonext - 1);
4557 ahc_outb(ahc, TQINPOS, ahc->tqinfifonext);
4559 ahc->qinfifonext = 0;
4560 ahc->qoutfifonext = 0;
4561 if ((ahc->features & AHC_QUEUE_REGS) != 0) {
4562 ahc_outb(ahc, QOFF_CTLSTA, SCB_QSIZE_256);
4563 ahc_outb(ahc, HNSCB_QOFF, ahc->qinfifonext);
4564 ahc_outb(ahc, SNSCB_QOFF, ahc->qinfifonext);
4565 ahc_outb(ahc, SDSCB_QOFF, 0);
4567 ahc_outb(ahc, KERNEL_QINPOS, ahc->qinfifonext);
4568 ahc_outb(ahc, QINPOS, ahc->qinfifonext);
4569 ahc_outb(ahc, QOUTPOS, ahc->qoutfifonext);
4573 ahc_outb(ahc, WAITING_SCBH, SCB_LIST_NULL);
4576 ahc_outb(ahc, DISCONNECTED_SCBH, SCB_LIST_NULL);
4579 ahc_outb(ahc, MSG_OUT, MSG_NOOP);
4587 if ((ahc->flags & AHC_INITIATORROLE) != 0)
4589 ahc_outb(ahc, SCSISEQ_TEMPLATE, scsiseq_template);
4592 ahc_build_free_scb_list(ahc);
4597 ahc_outb(ahc, NEXT_QUEUED_SCB, ahc->next_queued_scb->hscb->tag);
4605 ahc_name(ahc));
4607 error = ahc_loadseq(ahc);
4611 if ((ahc->features & AHC_ULTRA2) != 0) {
4622 (ahc_inb(ahc, SBLKCTL) & (ENAB40|ENAB20)) == 0 && wait;
4626 ahc_restart(ahc);
4634 ahc_init(struct ahc_softc *ahc)
4646 ahc->flags |= AHC_SEQUENCER_DEBUG;
4655 printf (" 0x%x", ahc_inb(ahc, i));
4657 if ((ahc->features & AHC_MORE_SRAM) != 0) {
4662 printf (" 0x%x", ahc_inb(ahc, i));
4670 ahc_outb(ahc, CLRINT, CLRPARERR);
4671 ahc_outb(ahc, CLRINT, CLRBRKADRINT);
4678 if ((ahc->flags & AHC_USEDEFAULTS) != 0)
4679 ahc->our_id = ahc->our_id_b = 7;
4684 ahc->flags |= AHC_INITIATORROLE;
4689 //if ((AHC_TMODE_ENABLE & (0x1 << ahc->unit)) == 0)
4690 ahc->features &= ~AHC_TARGETMODE;
4702 if ((ahc->features & AHC_TARGETMODE) != 0)
4706 ahc->init_level++;
4708 if (ahc_createdmamem(ahc->parent_dmat, driver_data_size,
4709 ahc->sc_dmaflags,
4710 &ahc->shared_data_dmamap, (caddr_t *)&ahc->qoutfifo,
4711 &ahc->shared_data_busaddr, &ahc->shared_data_seg,
4712 &ahc->shared_data_nseg, ahc_name(ahc), "shared data") < 0)
4715 ahc->init_level++;
4717 if ((ahc->features & AHC_TARGETMODE) != 0) {
4718 ahc->targetcmds = (struct target_cmd *)ahc->qoutfifo;
4719 ahc->qoutfifo = (uint8_t *)&ahc->targetcmds[AHC_TMODE_CMDS];
4720 ahc->dma_bug_buf = ahc->shared_data_busaddr
4724 ahc->targetcmds[i].cmd_valid = 0;
4725 ahc_sync_tqinfifo(ahc, BUS_DMASYNC_PREREAD);
4726 ahc->qoutfifo = (uint8_t *)&ahc->targetcmds[256];
4728 ahc->qinfifo = &ahc->qoutfifo[256];
4730 ahc->init_level++;
4733 if (ahc->scb_data->maxhscbs == 0)
4734 if (ahc_init_scbdata(ahc) != 0)
4742 if (ahc_alloc_tstate(ahc, ahc->our_id, 'A') == NULL) {
4744 "Failing attach\n", ahc_name(ahc));
4748 if ((ahc->features & AHC_TWIN) != 0) {
4749 if (ahc_alloc_tstate(ahc, ahc->our_id_b, 'B') == NULL) {
4751 "Failing attach\n", ahc_name(ahc));
4756 ahc_outb(ahc, SEQ_FLAGS, 0);
4757 ahc_outb(ahc, SEQ_FLAGS2, 0);
4759 if (ahc->scb_data->maxhscbs < AHC_SCB_MAX_ALLOC) {
4760 ahc->flags |= AHC_PAGESCBS;
4762 ahc->flags &= ~AHC_PAGESCBS;
4769 ahc_name(ahc),
4780 if (ahc->features & AHC_TWIN) {
4781 scsi_conf = ahc_inb(ahc, SCSICONF + 1);
4783 && (ahc->flags & AHC_INITIATORROLE) != 0)
4784 ahc->flags |= AHC_RESET_BUS_B;
4787 scsi_conf = ahc_inb(ahc, SCSICONF);
4789 && (ahc->flags & AHC_INITIATORROLE) != 0)
4790 ahc->flags |= AHC_RESET_BUS_A;
4796 if ((ahc->flags & AHC_USEDEFAULTS) != 0) {
4798 "device parameters\n", ahc_name(ahc));
4799 ahc->flags |= AHC_EXTENDED_TRANS_A|AHC_EXTENDED_TRANS_B|
4802 if ((ahc->features & AHC_ULTRA) != 0)
4805 discenable = ~((ahc_inb(ahc, DISC_DSB + 1) << 8)
4806 | ahc_inb(ahc, DISC_DSB));
4807 if ((ahc->features & (AHC_ULTRA|AHC_ULTRA2)) != 0)
4808 ultraenb = (ahc_inb(ahc, ULTRA_ENB + 1) << 8)
4809 | ahc_inb(ahc, ULTRA_ENB);
4812 if ((ahc->features & (AHC_WIDE|AHC_TWIN)) == 0)
4823 our_id = ahc->our_id;
4825 if (i > 7 && (ahc->features & AHC_TWIN) != 0) {
4827 our_id = ahc->our_id_b;
4830 tinfo = ahc_fetch_transinfo(ahc, channel, our_id,
4834 if (ahc->flags & AHC_USEDEFAULTS) {
4835 if ((ahc->features & AHC_WIDE) != 0)
4849 scsirate = ahc_inb(ahc, TARG_SCSIRATE + i);
4851 if ((ahc->features & AHC_ULTRA2) != 0) {
4866 offset = ahc_inb(ahc, TARG_OFFSET + i);
4871 if ((ahc->features & AHC_DT) != 0)
4874 ahc_find_period(ahc, scsirate, maxsync);
4880 && (ahc->features & AHC_DT) != 0)
4891 ahc_find_period(ahc, scsirate,
4901 && (ahc->features & AHC_WIDE) != 0)
4904 if ((ahc->features & AHC_DT) != 0)
4916 ahc->user_discenable = discenable;
4917 ahc->user_tagenable = tagenable;
4919 return (ahc->bus_chip_init(ahc));
4923 ahc_intr_enable(struct ahc_softc *ahc, int enable)
4927 hcntrl = ahc_inb(ahc, HCNTRL);
4929 ahc->pause &= ~INTEN;
4930 ahc->unpause &= ~INTEN;
4933 ahc->pause |= INTEN;
4934 ahc->unpause |= INTEN;
4936 ahc_outb(ahc, HCNTRL, hcntrl);
4945 ahc_index_busy_tcl(struct ahc_softc *ahc, u_int tcl)
4950 if ((ahc->flags & AHC_SCB_BTT) != 0) {
4953 saved_scbptr = ahc_inb(ahc, SCBPTR);
4954 ahc_outb(ahc, SCBPTR, TCL_LUN(tcl));
4955 scbid = ahc_inb(ahc, SCB_64_BTT + TCL_TARGET_OFFSET(tcl));
4956 ahc_outb(ahc, SCBPTR, saved_scbptr);
4959 scbid = ahc_inb(ahc, BUSY_TARGETS + target_offset);
4966 ahc_unbusy_tcl(struct ahc_softc *ahc, u_int tcl)
4970 if ((ahc->flags & AHC_SCB_BTT) != 0) {
4973 saved_scbptr = ahc_inb(ahc, SCBPTR);
4974 ahc_outb(ahc, SCBPTR, TCL_LUN(tcl));
4975 ahc_outb(ahc, SCB_64_BTT+TCL_TARGET_OFFSET(tcl), SCB_LIST_NULL);
4976 ahc_outb(ahc, SCBPTR, saved_scbptr);
4979 ahc_outb(ahc, BUSY_TARGETS + target_offset, SCB_LIST_NULL);
4984 ahc_busy_tcl(struct ahc_softc *ahc, u_int tcl, u_int scbid)
4988 if ((ahc->flags & AHC_SCB_BTT) != 0) {
4991 saved_scbptr = ahc_inb(ahc, SCBPTR);
4992 ahc_outb(ahc, SCBPTR, TCL_LUN(tcl));
4993 ahc_outb(ahc, SCB_64_BTT + TCL_TARGET_OFFSET(tcl), scbid);
4994 ahc_outb(ahc, SCBPTR, saved_scbptr);
4997 ahc_outb(ahc, BUSY_TARGETS + target_offset, scbid);
5003 ahc_match_scb(struct ahc_softc *ahc, struct scb *scb, int target,
5012 targ = SCB_GET_TARGET(ahc, scb);
5013 chan = SCB_GET_CHANNEL(ahc, scb);
5044 ahc_freeze_devq(struct ahc_softc *ahc, struct scb *scb)
5050 target = SCB_GET_TARGET(ahc, scb);
5052 channel = SCB_GET_CHANNEL(ahc, scb);
5054 ahc_search_qinfifo(ahc, target, channel, lun,
5060 ahc_qinfifo_requeue_tail(struct ahc_softc *ahc, struct scb *scb)
5065 if (ahc_qinfifo_count(ahc) != 0) {
5069 prev_pos = ahc->qinfifonext - 1;
5070 prev_tag = ahc->qinfifo[prev_pos];
5071 prev_scb = ahc_lookup_scb(ahc, prev_tag);
5073 ahc_qinfifo_requeue(ahc, prev_scb, scb);
5074 if ((ahc->features & AHC_QUEUE_REGS) != 0) {
5075 ahc_outb(ahc, HNSCB_QOFF, ahc->qinfifonext);
5077 ahc_outb(ahc, KERNEL_QINPOS, ahc->qinfifonext);
5082 ahc_qinfifo_requeue(struct ahc_softc *ahc, struct scb *prev_scb,
5086 ahc_outb(ahc, NEXT_QUEUED_SCB, scb->hscb->tag);
5089 ahc_sync_scb(ahc, prev_scb,
5092 ahc->qinfifo[ahc->qinfifonext] = scb->hscb->tag;
5093 ahc_dmamap_sync(ahc, ahc->parent_dmat, ahc->shared_data_dmamap,
5094 /*offset*/ahc->qinfifonext+256, /*len*/1,
5096 ahc->qinfifonext++;
5097 scb->hscb->next = ahc->next_queued_scb->hscb->tag;
5098 ahc_sync_scb(ahc, scb, BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
5102 ahc_qinfifo_count(struct ahc_softc *ahc)
5107 if ((ahc->features & AHC_QUEUE_REGS) != 0) {
5108 qinpos = ahc_inb(ahc, SNSCB_QOFF);
5109 ahc_outb(ahc, SNSCB_QOFF, qinpos);
5111 qinpos = ahc_inb(ahc, QINPOS);
5112 diff = ahc->qinfifonext - qinpos;
5117 ahc_search_qinfifo(struct ahc_softc *ahc, int target, char channel,
5132 qintail = ahc->qinfifonext;
5133 have_qregs = (ahc->features & AHC_QUEUE_REGS) != 0;
5135 qinstart = ahc_inb(ahc, SNSCB_QOFF);
5136 ahc_outb(ahc, SNSCB_QOFF, qinstart);
5138 qinstart = ahc_inb(ahc, QINPOS);
5148 ahc_freeze_untagged_queues(ahc);
5155 ahc->qinfifonext = qinpos;
5156 ahc_outb(ahc, NEXT_QUEUED_SCB, ahc->next_queued_scb->hscb->tag);
5159 scb = ahc_lookup_scb(ahc, ahc->qinfifo[qinpos]);
5162 qinpos, ahc->qinfifo[qinpos]);
5166 if (ahc_match_scb(ahc, scb, target, channel, lun, tag, role)) {
5185 ahc_done(ahc, scb);
5192 ahc_qinfifo_requeue(ahc, prev_scb, scb);
5197 ahc_qinfifo_requeue(ahc, prev_scb, scb);
5203 if ((ahc->features & AHC_QUEUE_REGS) != 0) {
5204 ahc_outb(ahc, HNSCB_QOFF, ahc->qinfifonext);
5206 ahc_outb(ahc, KERNEL_QINPOS, ahc->qinfifonext);
5211 && (qinstart != ahc->qinfifonext)) {
5224 scb = ahc_lookup_scb(ahc, ahc->qinfifo[qinstart]);
5228 found, qinstart, ahc->qinfifonext);
5238 ahc->scb_data->scbindex[scb->hscb->tag] = NULL;
5239 ahc_swap_with_next_hscb(ahc, scb);
5241 ahc->qinfifo[qinstart] = scb->hscb->tag;
5244 ahc_outb(ahc, NEXT_QUEUED_SCB, scb->hscb->tag);
5247 qintail = ahc->qinfifonext - 1;
5248 scb = ahc_lookup_scb(ahc, ahc->qinfifo[qintail]);
5249 scb->hscb->next = ahc->next_queued_scb->hscb->tag;
5255 curscbptr = ahc_inb(ahc, SCBPTR);
5256 next = ahc_inb(ahc, WAITING_SCBH); /* Start at head of list. */
5262 ahc_outb(ahc, SCBPTR, next);
5263 scb_index = ahc_inb(ahc, SCB_TAG);
5264 if (scb_index >= ahc->scb_data->numscbs) {
5267 scb_index, ahc->scb_data->numscbs);
5268 ahc_dump_card_state(ahc);
5271 scb = ahc_lookup_scb(ahc, scb_index);
5277 if (ahc_match_scb(ahc, scb, target, channel,
5297 ahc_done(ahc, scb);
5301 next = ahc_rem_wscb(ahc, next, prev);
5305 next = ahc_inb(ahc, SCB_NEXT);
5311 next = ahc_inb(ahc, SCB_NEXT);
5314 ahc_outb(ahc, SCBPTR, curscbptr);
5316 found += ahc_search_untagged_queues(ahc, /*scsi_xfer*/NULL, target,
5320 ahc_release_untagged_queues(ahc);
5325 ahc_search_untagged_queues(struct ahc_softc *ahc, struct scsi_xfer *xs,
5339 ahc_freeze_untagged_queues(ahc);
5344 if ((ahc->flags & AHC_SCB_BTT) == 0) {
5362 untagged_q = &(ahc->untagged_queues[i]);
5381 if (ahc_match_scb(ahc, scb, target, channel, lun,
5402 ahc_done(ahc, scb);
5416 ahc_release_untagged_queues(ahc);
5421 ahc_search_disc_list(struct ahc_softc *ahc, int target, char channel,
5432 next = ahc_inb(ahc, DISCONNECTED_SCBH);
5437 active_scb = ahc_inb(ahc, SCBPTR);
5445 ahc_outb(ahc, SCBPTR, next);
5446 scb_index = ahc_inb(ahc, SCB_TAG);
5447 if (scb_index >= ahc->scb_data->numscbs) {
5450 scb_index, ahc->scb_data->numscbs);
5451 ahc_dump_card_state(ahc);
5460 scbp = ahc_lookup_scb(ahc, scb_index);
5461 if (ahc_match_scb(ahc, scbp, target, channel, lun,
5466 ahc_rem_scb_from_disc_list(ahc, prev, next);
5469 next = ahc_inb(ahc, SCB_NEXT);
5475 next = ahc_inb(ahc, SCB_NEXT);
5479 ahc_outb(ahc, SCBPTR, active_scb);
5488 ahc_rem_scb_from_disc_list(struct ahc_softc *ahc, u_int prev, u_int scbptr)
5492 ahc_outb(ahc, SCBPTR, scbptr);
5493 next = ahc_inb(ahc, SCB_NEXT);
5495 ahc_outb(ahc, SCB_CONTROL, 0);
5497 ahc_add_curscb_to_free_list(ahc);
5500 ahc_outb(ahc, SCBPTR, prev);
5501 ahc_outb(ahc, SCB_NEXT, next);
5503 ahc_outb(ahc, DISCONNECTED_SCBH, next);
5514 ahc_add_curscb_to_free_list(struct ahc_softc *ahc)
5520 ahc_outb(ahc, SCB_TAG, SCB_LIST_NULL);
5522 if ((ahc->flags & AHC_PAGESCBS) != 0) {
5523 ahc_outb(ahc, SCB_NEXT, ahc_inb(ahc, FREE_SCBH));
5524 ahc_outb(ahc, FREE_SCBH, ahc_inb(ahc, SCBPTR));
5533 ahc_rem_wscb(struct ahc_softc *ahc, u_int scbpos, u_int prev)
5541 curscb = ahc_inb(ahc, SCBPTR);
5542 ahc_outb(ahc, SCBPTR, scbpos);
5543 next = ahc_inb(ahc, SCB_NEXT);
5546 ahc_outb(ahc, SCB_CONTROL, 0);
5548 ahc_add_curscb_to_free_list(ahc);
5553 ahc_outb(ahc, WAITING_SCBH, next);
5559 ahc_outb(ahc, SCSISEQ, (ahc_inb(ahc, SCSISEQ) & ~ENSELO));
5565 ahc_outb(ahc, SCBPTR, prev);
5566 ahc_outb(ahc, SCB_NEXT, next);
5572 ahc_outb(ahc, SCBPTR, curscb);
5584 ahc_abort_scbs(struct ahc_softc *ahc, int target, char channel,
5601 ahc_freeze_untagged_queues(ahc);
5604 active_scb = ahc_inb(ahc, SCBPTR);
5606 found = ahc_search_qinfifo(ahc, target, channel, lun, SCB_LIST_NULL,
5631 if ((ahc->flags & AHC_SCB_BTT) != 0)
5645 scbid = ahc_index_busy_tcl(ahc, tcl);
5646 scbp = ahc_lookup_scb(ahc, scbid);
5648 || ahc_match_scb(ahc, scbp, target, channel,
5651 ahc_unbusy_tcl(ahc, BUILD_TCL(i << 4, j));
5661 ahc_search_disc_list(ahc, target, channel, lun, tag,
5673 for (i = 0; i < ahc->scb_data->maxhscbs; i++) {
5676 ahc_outb(ahc, SCBPTR, i);
5677 scbid = ahc_inb(ahc, SCB_TAG);
5678 scbp = ahc_lookup_scb(ahc, scbid);
5681 && ahc_match_scb(ahc, scbp, target, channel, lun, tag, role)))
5682 ahc_add_curscb_to_free_list(ahc);
5691 scbp_next = LIST_FIRST(&ahc->pending_scbs);
5695 if (ahc_match_scb(ahc, scbp, target, channel, lun, tag, role)) {
5705 ahc_done(ahc, scbp);
5709 ahc_outb(ahc, SCBPTR, active_scb);
5710 ahc_release_untagged_queues(ahc);
5715 ahc_reset_current_bus(struct ahc_softc *ahc)
5719 ahc_outb(ahc, SIMODE1, ahc_inb(ahc, SIMODE1) & ~ENSCSIRST);
5720 scsiseq = ahc_inb(ahc, SCSISEQ);
5721 ahc_outb(ahc, SCSISEQ, scsiseq | SCSIRSTO);
5722 ahc_flush_device_writes(ahc);
5725 ahc_outb(ahc, SCSISEQ, scsiseq & ~SCSIRSTO);
5727 ahc_clear_intstat(ahc);
5730 ahc_outb(ahc, SIMODE1, ahc_inb(ahc, SIMODE1) | ENSCSIRST);
5734 ahc_reset_channel(struct ahc_softc *ahc, char channel, int initiate_reset)
5745 ahc->pending_device = NULL;
5752 ahc_pause(ahc);
5755 ahc_clear_critical_section(ahc);
5762 ahc_run_qoutfifo(ahc);
5774 if ((ahc->flags & AHC_TARGETROLE) != 0) {
5775 ahc_run_tqinfifo(ahc, /*paused*/TRUE);
5782 sblkctl = ahc_inb(ahc, SBLKCTL);
5784 if ((ahc->features & AHC_TWIN) != 0
5787 scsiseq = ahc_inb(ahc, SCSISEQ_TEMPLATE);
5793 ahc_outb(ahc, SBLKCTL, sblkctl ^ SELBUSB);
5794 simode1 = ahc_inb(ahc, SIMODE1) & ~(ENBUSFREE|ENSCSIRST);
5801 if ((ahc->flags & AHC_TARGETROLE) != 0)
5804 ahc_outb(ahc, SIMODE1, simode1);
5806 ahc_reset_current_bus(ahc);
5807 ahc_clear_intstat(ahc);
5808 ahc_outb(ahc, SCSISEQ, scsiseq & (ENSELI|ENRSELI|ENAUTOATNP));
5809 ahc_outb(ahc, SBLKCTL, sblkctl);
5813 simode1 = ahc_inb(ahc, SIMODE1) & ~(ENBUSFREE|ENSCSIRST);
5820 if ((ahc->flags & AHC_TARGETROLE) != 0)
5823 ahc_outb(ahc, SIMODE1, simode1);
5825 ahc_reset_current_bus(ahc);
5826 ahc_clear_intstat(ahc);
5827 ahc_outb(ahc, SCSISEQ, scsiseq & (ENSELI|ENRSELI|ENAUTOATNP));
5835 found = ahc_abort_scbs(ahc, CAM_TARGET_WILDCARD, channel,
5839 max_scsiid = (ahc->features & AHC_WIDE) ? 15 : 7;
5850 tstate = ahc->enabled_targets[target];
5860 ahc_queue_lstate_event(ahc, lstate, CAM_TARGET_WILDCARD,
5862 ahc_send_lstate_events(ahc, lstate);
5867 ahc_send_async(ahc, devinfo.channel, CAM_TARGET_WILDCARD,
5875 if (ahc->enabled_targets[target] == NULL)
5881 ahc_set_width(ahc, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
5883 ahc_set_syncrate(ahc, &devinfo, /*syncrate*/NULL,
5891 ahc_restart(ahc);
5893 ahc_unpause(ahc);
5903 ahc_calc_residual(struct ahc_softc *ahc, struct scb *scb)
5978 ahc_print_path(ahc, scb);
5991 ahc_queue_lstate_event(struct ahc_softc *ahc, struct ahc_tmode_lstate *lstate,
6042 ahc_send_lstate_events(struct ahc_softc *ahc, struct ahc_tmode_lstate *lstate)
6078 ahc_dumpseq(struct ahc_softc* ahc)
6082 ahc_outb(ahc, SEQCTL, PERRORDIS|FAILDIS|FASTMODE|LOADRAM);
6083 ahc_outb(ahc, SEQADDR0, 0);
6084 ahc_outb(ahc, SEQADDR1, 0);
6085 for (i = 0; i < ahc->instruction_ram_size; i++) {
6088 ahc_insb(ahc, SEQRAM, ins_bytes, 4);
6098 ahc_loadseq(struct ahc_softc *ahc)
6123 if (ahc->targetcmds != NULL)
6126 download_consts[CACHESIZE_MASK] = ahc->pci_cachesize - 1;
6127 download_consts[INVERTED_CACHESIZE_MASK] = ~(ahc->pci_cachesize - 1);
6128 sg_prefetch_cnt = ahc->pci_cachesize;
6138 ahc_outb(ahc, SEQCTL, PERRORDIS|FAILDIS|FASTMODE|LOADRAM);
6139 ahc_outb(ahc, SEQADDR0, 0);
6140 ahc_outb(ahc, SEQADDR1, 0);
6143 if (ahc_check_patch(ahc, &cur_patch, i, &skip_addr) == 0) {
6151 if (downloaded == ahc->instruction_ram_size) {
6158 "size of %d!\n", ahc_name(ahc),
6159 ahc->instruction_ram_size);
6184 ahc_download_instr(ahc, i, download_consts);
6188 ahc->num_critical_sections = cs_count;
6190 ahc->critical_sections = mallocarray(cs_count,
6192 if (ahc->critical_sections == NULL)
6196 memcpy(ahc->critical_sections, cs_table, cs_count);
6198 ahc_outb(ahc, SEQCTL, PERRORDIS|FAILDIS|FASTMODE);
6203 ahc_name(ahc), ahc->features, ahc->bugs, ahc->flags);
6209 ahc_check_patch(struct ahc_softc *ahc, const struct patch **start_patch,
6222 if (cur_patch->patch_func(ahc) == 0) {
6245 ahc_download_instr(struct ahc_softc *ahc, u_int instrptr, uint8_t *dconsts)
6286 ahc_check_patch(ahc, &cur_patch, i, &skip_addr);
6312 if ((ahc->features & AHC_CMD_CHAN) == 0
6323 ahc_name(ahc));
6329 if ((ahc->features & AHC_ULTRA2) != 0) {
6361 ahc_outsb(ahc, SEQRAM, instr.bytes, 4);
6418 ahc_dump_card_state(struct ahc_softc *ahc)
6435 if (ahc_is_paused(ahc)) {
6439 ahc_pause(ahc);
6442 saved_scbptr = ahc_inb(ahc, SCBPTR);
6443 last_phase = ahc_inb(ahc, LASTPHASE);
6446 ahc_name(ahc), ahc_lookup_phase_entry(last_phase)->phasemsg,
6447 ahc_inb(ahc, SEQADDR0) | (ahc_inb(ahc, SEQADDR1) << 8));
6451 ahc_inb(ahc, ACCUM), ahc_inb(ahc, SINDEX), ahc_inb(ahc, DINDEX),
6452 ahc_inb(ahc, ARG_2));
6453 printf("HCNT = 0x%x SCBPTR = 0x%x\n", ahc_inb(ahc, HCNT),
6454 ahc_inb(ahc, SCBPTR));
6456 if ((ahc->features & AHC_DT) != 0)
6457 ahc_scsiphase_print(ahc_inb(ahc, SCSIPHASE), &cur_col, 50);
6458 ahc_scsisigi_print(ahc_inb(ahc, SCSISIGI), &cur_col, 50);
6459 ahc_error_print(ahc_inb(ahc, ERROR), &cur_col, 50);
6460 ahc_scsibusl_print(ahc_inb(ahc, SCSIBUSL), &cur_col, 50);
6461 ahc_lastphase_print(ahc_inb(ahc, LASTPHASE), &cur_col, 50);
6462 ahc_scsiseq_print(ahc_inb(ahc, SCSISEQ), &cur_col, 50);
6463 ahc_sblkctl_print(ahc_inb(ahc, SBLKCTL), &cur_col, 50);
6464 ahc_scsirate_print(ahc_inb(ahc, SCSIRATE), &cur_col, 50);
6465 ahc_seqctl_print(ahc_inb(ahc, SEQCTL), &cur_col, 50);
6466 ahc_seq_flags_print(ahc_inb(ahc, SEQ_FLAGS), &cur_col, 50);
6467 ahc_sstat0_print(ahc_inb(ahc, SSTAT0), &cur_col, 50);
6468 ahc_sstat1_print(ahc_inb(ahc, SSTAT1), &cur_col, 50);
6469 ahc_sstat2_print(ahc_inb(ahc, SSTAT2), &cur_col, 50);
6470 ahc_sstat3_print(ahc_inb(ahc, SSTAT3), &cur_col, 50);
6471 ahc_simode0_print(ahc_inb(ahc, SIMODE0), &cur_col, 50);
6472 ahc_simode1_print(ahc_inb(ahc, SIMODE1), &cur_col, 50);
6473 ahc_sxfrctl0_print(ahc_inb(ahc, SXFRCTL0), &cur_col, 50);
6474 ahc_dfcntrl_print(ahc_inb(ahc, DFCNTRL), &cur_col, 50);
6475 ahc_dfstatus_print(ahc_inb(ahc, DFSTATUS), &cur_col, 50);
6480 printf(" 0x%x", ahc_inb(ahc, STACK)|(ahc_inb(ahc, STACK) << 8));
6481 printf("\nSCB count = %d\n", ahc->scb_data->numscbs);
6482 printf("Kernel NEXTQSCB = %d\n", ahc->next_queued_scb->hscb->tag);
6483 printf("Card NEXTQSCB = %d\n", ahc_inb(ahc, NEXT_QUEUED_SCB));
6486 if ((ahc->features & AHC_QUEUE_REGS) != 0) {
6487 qinpos = ahc_inb(ahc, SNSCB_QOFF);
6488 ahc_outb(ahc, SNSCB_QOFF, qinpos);
6490 qinpos = ahc_inb(ahc, QINPOS);
6491 qintail = ahc->qinfifonext;
6493 printf("%d ", ahc->qinfifo[qinpos]);
6499 scb_index = ahc_inb(ahc, WAITING_SCBH);
6502 ahc_outb(ahc, SCBPTR, scb_index);
6503 printf("%d:%d ", scb_index, ahc_inb(ahc, SCB_TAG));
6504 scb_index = ahc_inb(ahc, SCB_NEXT);
6509 scb_index = ahc_inb(ahc, DISCONNECTED_SCBH);
6512 ahc_outb(ahc, SCBPTR, scb_index);
6513 printf("%d:%d ", scb_index, ahc_inb(ahc, SCB_TAG));
6514 scb_index = ahc_inb(ahc, SCB_NEXT);
6518 ahc_sync_qoutfifo(ahc, BUS_DMASYNC_POSTREAD);
6520 qoutpos = ahc->qoutfifonext;
6522 while (ahc->qoutfifo[qoutpos] != SCB_LIST_NULL && i++ < 256) {
6523 printf("%d ", ahc->qoutfifo[qoutpos]);
6529 scb_index = ahc_inb(ahc, FREE_SCBH);
6532 ahc_outb(ahc, SCBPTR, scb_index);
6534 scb_index = ahc_inb(ahc, SCB_NEXT);
6539 for (i = 0; i < ahc->scb_data->maxhscbs; i++) {
6540 ahc_outb(ahc, SCBPTR, i);
6543 ahc_scb_control_print(ahc_inb(ahc, SCB_CONTROL), &cur_col, 60);
6544 ahc_scb_scsiid_print(ahc_inb(ahc, SCB_SCSIID), &cur_col, 60);
6545 ahc_scb_lun_print(ahc_inb(ahc, SCB_LUN), &cur_col, 60);
6546 ahc_scb_tag_print(ahc_inb(ahc, SCB_TAG), &cur_col, 60);
6552 LIST_FOREACH(scb, &ahc->pending_scbs, pending_links) {
6559 if ((ahc->flags & AHC_PAGESCBS) == 0) {
6560 ahc_outb(ahc, SCBPTR, scb->hscb->tag);
6562 ahc_scb_control_print(ahc_inb(ahc, SCB_CONTROL),
6564 ahc_scb_tag_print(ahc_inb(ahc, SCB_TAG), &cur_col, 60);
6572 mtx_enter(&ahc->sc_scb_mtx);
6573 SLIST_FOREACH(scb, &ahc->scb_data->free_scbs, links.sle) {
6579 mtx_leave(&ahc->sc_scb_mtx);
6581 maxtarget = (ahc->features & (AHC_WIDE|AHC_TWIN)) ? 15 : 7;
6583 untagged_q = &ahc->untagged_queues[target];
6596 ahc_platform_dump_card_state(ahc);
6598 ahc_outb(ahc, SCBPTR, saved_scbptr);
6600 ahc_unpause(ahc);
6607 ahc_find_tmode_devs(struct ahc_softc *ahc, struct cam_sim *sim, union ccb *ccb,
6613 if ((ahc->features & AHC_TARGETMODE) == 0)
6623 *lstate = ahc->black_hole;
6627 max_id = (ahc->features & AHC_WIDE) ? 15 : 7;
6634 *tstate = ahc->enabled_targets[ccb->ccb_h.target_id];
6648 ahc_handle_en_lun(struct ahc_softc *ahc, struct cam_sim *sim, union ccb *ccb)
6662 status = ahc_find_tmode_devs(ahc, sim, ccb, &tstate, &lstate,
6671 our_id = ahc->our_id;
6673 our_id = ahc->our_id_b;
6695 if ((ahc->features & AHC_MULTIROLE) != 0) {
6697 if ((ahc->features & AHC_MULTI_TID) != 0
6698 && (ahc->flags & AHC_INITIATORROLE) != 0) {
6707 } else if ((ahc->flags & AHC_INITIATORROLE) != 0
6708 || ahc->enabled_luns > 0) {
6718 } else if ((ahc->features & AHC_MULTI_TID) == 0
6719 && ahc->enabled_luns > 0) {
6734 if ((ahc->flags & AHC_TARGETROLE) == 0
6741 if (LIST_FIRST(&ahc->pending_scbs) != NULL) {
6746 saved_flags = ahc->flags;
6747 ahc->flags |= AHC_TARGETROLE;
6748 if ((ahc->features & AHC_MULTIROLE) == 0)
6749 ahc->flags &= ~AHC_INITIATORROLE;
6750 ahc_pause(ahc);
6751 error = ahc_loadseq(ahc);
6761 ahc->flags = saved_flags;
6762 (void)ahc_loadseq(ahc);
6763 ahc_restart(ahc);
6768 ahc_restart(ahc);
6774 channel = SIM_CHANNEL(ahc, sim);
6806 tstate = ahc_alloc_tstate(ahc, target, channel);
6835 ahc_pause(ahc);
6838 ahc->enabled_luns++;
6840 if ((ahc->features & AHC_MULTI_TID) != 0) {
6843 targid_mask = ahc_inb(ahc, TARGID)
6844 | (ahc_inb(ahc, TARGID + 1) << 8);
6847 ahc_outb(ahc, TARGID, targid_mask);
6848 ahc_outb(ahc, TARGID+1, (targid_mask >> 8));
6850 ahc_update_scsiid(ahc, targid_mask);
6855 channel = SIM_CHANNEL(ahc, sim);
6856 our_id = SIM_SCSI_ID(ahc, sim);
6867 sblkctl = ahc_inb(ahc, SBLKCTL);
6870 if ((ahc->features & AHC_TWIN) == 0)
6874 ahc->our_id = target;
6876 ahc->our_id_b = target;
6879 ahc_outb(ahc, SBLKCTL,
6882 ahc_outb(ahc, SCSIID, target);
6885 ahc_outb(ahc, SBLKCTL, sblkctl);
6889 ahc->black_hole = lstate;
6891 if (ahc->black_hole != NULL && ahc->enabled_luns > 0) {
6892 scsiseq = ahc_inb(ahc, SCSISEQ_TEMPLATE);
6894 ahc_outb(ahc, SCSISEQ_TEMPLATE, scsiseq);
6895 scsiseq = ahc_inb(ahc, SCSISEQ);
6897 ahc_outb(ahc, SCSISEQ, scsiseq);
6899 ahc_unpause(ahc);
6916 LIST_FOREACH(scb, &ahc->pending_scbs, pending_links) {
6949 ahc_pause(ahc);
6953 ahc->enabled_luns--;
6961 ahc_free_tstate(ahc, target, channel,
6963 if (ahc->features & AHC_MULTI_TID) {
6966 targid_mask = ahc_inb(ahc, TARGID)
6967 | (ahc_inb(ahc, TARGID + 1)
6971 ahc_outb(ahc, TARGID, targid_mask);
6972 ahc_outb(ahc, TARGID+1,
6974 ahc_update_scsiid(ahc, targid_mask);
6979 ahc->black_hole = NULL;
6987 if (ahc->enabled_luns == 0) {
6991 scsiseq = ahc_inb(ahc, SCSISEQ_TEMPLATE);
6993 ahc_outb(ahc, SCSISEQ_TEMPLATE, scsiseq);
6994 scsiseq = ahc_inb(ahc, SCSISEQ);
6996 ahc_outb(ahc, SCSISEQ, scsiseq);
6998 if ((ahc->features & AHC_MULTIROLE) == 0) {
7000 ahc->flags &= ~AHC_TARGETROLE;
7001 ahc->flags |= AHC_INITIATORROLE;
7006 (void)ahc_loadseq(ahc);
7007 ahc_restart(ahc);
7014 ahc_unpause(ahc);
7020 ahc_update_scsiid(struct ahc_softc *ahc, u_int targid_mask)
7025 if ((ahc->features & AHC_MULTI_TID) == 0)
7034 if ((ahc->features & AHC_ULTRA2) != 0)
7035 scsiid = ahc_inb(ahc, SCSIID_ULTRA2);
7037 scsiid = ahc_inb(ahc, SCSIID);
7045 our_id = ahc->our_id;
7051 if ((ahc->features & AHC_ULTRA2) != 0)
7052 ahc_outb(ahc, SCSIID_ULTRA2, scsiid);
7054 ahc_outb(ahc, SCSIID, scsiid);
7059 ahc_run_tqinfifo(struct ahc_softc *ahc, int paused)
7068 if ((ahc->features & AHC_AUTOPAUSE) != 0)
7071 ahc_sync_tqinfifo(ahc, BUS_DMASYNC_POSTREAD);
7072 while ((cmd = &ahc->targetcmds[ahc->tqinfifonext])->cmd_valid != 0) {
7078 if (ahc_handle_target_cmd(ahc, cmd) != 0)
7082 ahc_dmamap_sync(ahc, ahc->parent_dmat/*shared_data_dmat*/,
7083 ahc->shared_data_dmamap,
7084 ahc_targetcmd_offset(ahc, ahc->tqinfifonext),
7087 ahc->tqinfifonext++;
7093 if ((ahc->tqinfifonext & (HOST_TQINPOS - 1)) == 1) {
7094 if ((ahc->features & AHC_HS_MAILBOX) != 0) {
7097 hs_mailbox = ahc_inb(ahc, HS_MAILBOX);
7099 hs_mailbox |= ahc->tqinfifonext & HOST_TQINPOS;
7100 ahc_outb(ahc, HS_MAILBOX, hs_mailbox);
7103 ahc_pause(ahc);
7104 ahc_outb(ahc, KERNEL_TQINPOS,
7105 ahc->tqinfifonext & HOST_TQINPOS);
7107 ahc_unpause(ahc);
7115 ahc_handle_target_cmd(struct ahc_softc *ahc, struct target_cmd *cmd)
7125 initiator = SCSIID_TARGET(ahc, cmd->scsiid);
7130 tstate = ahc->enabled_targets[target];
7139 lstate = ahc->black_hole;
7143 ahc->flags |= AHC_TQINFIFO_BLOCKED;
7148 printf("%s: ATIOs exhausted\n", ahc_name(ahc));
7151 ahc->flags &= ~AHC_TQINFIFO_BLOCKED;
7155 lstate == ahc->black_hole ? "(Black Holed)" : "");
7159 if (lstate == ahc->black_hole) {
7217 initiator, target, lun, ahc->pending_device);
7219 ahc->pending_device = lstate;