Lines Matching defs:ahc

146 static void		ahc_force_renegotiation(struct ahc_softc *ahc,
149 ahc_alloc_tstate(struct ahc_softc *ahc,
152 static void ahc_free_tstate(struct ahc_softc *ahc,
156 ahc_devlimited_syncrate(struct ahc_softc *ahc,
161 static void ahc_update_pending_scbs(struct ahc_softc *ahc);
162 static void ahc_fetch_devinfo(struct ahc_softc *ahc,
164 static void ahc_scb_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,
233 static int ahc_other_scb_timeout(struct ahc_softc *ahc,
237 static void ahc_queue_lstate_event(struct ahc_softc *ahc,
242 static void ahc_update_scsiid(struct ahc_softc *ahc,
244 static int ahc_handle_target_cmd(struct ahc_softc *ahc,
252 ahc_restart(struct ahc_softc *ahc)
255 ahc_pause(ahc);
258 ahc_clear_msg_state(ahc);
260 ahc_outb(ahc, SCSISIGO, 0); /* De-assert BSY */
261 ahc_outb(ahc, MSG_OUT, MSG_NOOP); /* No message to send */
262 ahc_outb(ahc, SXFRCTL1, ahc_inb(ahc, SXFRCTL1) & ~BITBUCKET);
263 ahc_outb(ahc, LASTPHASE, P_BUSFREE);
264 ahc_outb(ahc, SAVED_SCSIID, 0xFF);
265 ahc_outb(ahc, SAVED_LUN, 0xFF);
274 ahc_outb(ahc, TQINPOS, ahc->tqinfifonext);
277 ahc_outb(ahc, SCSISEQ,
278 ahc_inb(ahc, SCSISEQ_TEMPLATE) & (ENSELI|ENRSELI|ENAUTOATNP));
279 if ((ahc->features & AHC_CMD_CHAN) != 0) {
281 ahc_outb(ahc, CCSCBCNT, 0);
282 ahc_outb(ahc, CCSGCTL, 0);
283 ahc_outb(ahc, CCSCBCTL, 0);
290 if ((ahc_inb(ahc, SEQ_FLAGS2) & SCB_DMA) != 0) {
291 ahc_add_curscb_to_free_list(ahc);
292 ahc_outb(ahc, SEQ_FLAGS2,
293 ahc_inb(ahc, SEQ_FLAGS2) & ~SCB_DMA);
301 ahc_outb(ahc, CLRINT, CLRSEQINT);
303 ahc_outb(ahc, MWI_RESIDUAL, 0);
304 ahc_outb(ahc, SEQCTL, ahc->seqctl);
305 ahc_outb(ahc, SEQADDR0, 0);
306 ahc_outb(ahc, SEQADDR1, 0);
308 ahc_unpause(ahc);
313 ahc_run_qoutfifo(struct ahc_softc *ahc)
318 ahc_sync_qoutfifo(ahc, BUS_DMASYNC_POSTREAD);
319 while (ahc->qoutfifo[ahc->qoutfifonext] != SCB_LIST_NULL) {
321 scb_index = ahc->qoutfifo[ahc->qoutfifonext];
322 if ((ahc->qoutfifonext & 0x03) == 0x03) {
332 modnext = ahc->qoutfifonext & ~0x3;
333 *((uint32_t *)(&ahc->qoutfifo[modnext])) = 0xFFFFFFFFUL;
334 aic_dmamap_sync(ahc, ahc->shared_data_dmat,
335 ahc->shared_data_dmamap,
339 ahc->qoutfifonext++;
341 scb = ahc_lookup_scb(ahc, scb_index);
345 ahc_name(ahc), scb_index,
346 (ahc->qoutfifonext - 1) & 0xFF);
354 ahc_update_residual(ahc, scb);
355 ahc_done(ahc, scb);
360 ahc_run_untagged_queues(struct ahc_softc *ahc)
365 ahc_run_untagged_queue(ahc, &ahc->untagged_queues[i]);
369 ahc_run_untagged_queue(struct ahc_softc *ahc, struct scb_tailq *queue)
373 if (ahc->untagged_queue_lock != 0)
383 ahc_queue_scb(ahc, scb);
389 ahc_handle_brkadrint(struct ahc_softc *ahc)
398 error = ahc_inb(ahc, ERROR);
402 ahc_name(ahc), ahc_hard_errors[i].errmesg,
403 ahc_inb(ahc, SEQADDR0) |
404 (ahc_inb(ahc, SEQADDR1) << 8));
406 ahc_dump_card_state(ahc);
409 ahc_abort_scbs(ahc, CAM_TARGET_WILDCARD, ALL_CHANNELS,
414 ahc_shutdown(ahc);
418 ahc_handle_seqint(struct ahc_softc *ahc, u_int intstat)
423 ahc_fetch_devinfo(ahc, &devinfo);
431 ahc_outb(ahc, CLRINT, CLRSEQINT);
443 ahc_outb(ahc, RETURN_1, 0);
454 scb_index = ahc_inb(ahc, SCB_TAG);
455 scb = ahc_lookup_scb(ahc, scb_index);
457 ahc_print_devinfo(ahc, &devinfo);
461 ahc_dump_card_state(ahc);
481 ahc_freeze_devq(ahc, scb);
487 ahc_name(ahc));
499 ahc_print_path(ahc, scb);
508 targ_info = ahc_fetch_transinfo(ahc,
519 ahc_update_residual(ahc, scb);
522 ahc_print_path(ahc, scb);
526 sg->addr = ahc_get_sense_bufaddr(ahc, scb);
527 sg->len = aic_get_sense_bufsize(ahc, scb);
563 ahc_update_neg_request(ahc, &devinfo,
579 ahc_qinfifo_requeue_tail(ahc, scb);
580 ahc_outb(ahc, RETURN_1, SEND_SENSE);
588 if (ahc->scb_data->recovery_scbs == 0
601 ahc_outb(ahc, SCSISEQ,
602 ahc_inb(ahc, SCSISEQ) & (ENSELI|ENRSELI|ENAUTOATNP));
606 ahc_name(ahc), devinfo.channel, devinfo.target);
609 ahc_inb(ahc, SAVED_SCSIID), ahc_inb(ahc, SAVED_LUN),
610 ahc_inb(ahc, ARG_1), ahc_inb(ahc, ACCUM));
613 ahc_inb(ahc, SEQ_FLAGS), ahc_inb(ahc, SCBPTR),
614 ahc_index_busy_tcl(ahc,
615 BUILD_TCL(ahc_inb(ahc, SAVED_SCSIID),
616 ahc_inb(ahc, SAVED_LUN))),
617 ahc_inb(ahc, SINDEX));
620 ahc_inb(ahc, SCSIID), ahc_inb(ahc, SCB_SCSIID),
621 ahc_inb(ahc, SCB_LUN), ahc_inb(ahc, SCB_TAG),
622 ahc_inb(ahc, SCB_CONTROL));
624 ahc_inb(ahc, SCSIBUSL), ahc_inb(ahc, SCSISIGI));
625 printf("SXFRCTL0 == 0x%x\n", ahc_inb(ahc, SXFRCTL0));
626 printf("SEQCTL == 0x%x\n", ahc_inb(ahc, SEQCTL));
627 ahc_dump_card_state(ahc);
628 ahc->msgout_buf[0] = MSG_BUS_DEV_RESET;
629 ahc->msgout_len = 1;
630 ahc->msgout_index = 0;
631 ahc->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
632 ahc_outb(ahc, MSG_OUT, HOST_MSG);
633 ahc_assert_atn(ahc);
638 u_int rejbyte = ahc_inb(ahc, ACCUM);
641 ahc_name(ahc), devinfo.channel, devinfo.target, rejbyte);
646 ahc_handle_proto_violation(ahc);
650 ahc_handle_ign_wide_residue(ahc, &devinfo);
653 ahc_reinitialize_dataptrs(ahc);
659 lastphase = ahc_inb(ahc, LASTPHASE);
662 ahc_name(ahc), devinfo.channel, devinfo.target,
663 lastphase, ahc_inb(ahc, SCSISIGI));
670 lastphase = ahc_inb(ahc, LASTPHASE);
673 ahc_name(ahc), devinfo.channel, devinfo.target,
674 lastphase, ahc_inb(ahc, SCSISIGI));
675 ahc_restart(ahc);
691 if (ahc->msg_type == MSG_TYPE_NONE) {
696 bus_phase = ahc_inb(ahc, SCSISIGI) & PHASE_MASK;
706 ahc_clear_intstat(ahc);
707 ahc_restart(ahc);
711 scb_index = ahc_inb(ahc, SCB_TAG);
712 scb = ahc_lookup_scb(ahc, scb_index);
719 ahc_setup_initiator_msgout(ahc,
723 ahc->msg_type =
725 ahc->msgin_index = 0;
731 ahc->msg_type =
733 ahc->msgin_index = 0;
736 ahc_setup_target_msgin(ahc,
743 ahc_handle_message_phase(ahc);
760 && (ahc_inb(ahc, SSTAT1) & SCSIPERR) != 0) {
762 if ((ahc->features & AHC_DT) == 0) {
771 curphase = ahc_inb(ahc, SCSISIGI) & PHASE_MASK;
772 ahc_outb(ahc, LASTPHASE, curphase);
773 ahc_outb(ahc, SCSISIGO, curphase);
775 if ((ahc_inb(ahc, SCSISIGI) & (CDI|MSGI)) == 0) {
784 ahc_outb(ahc, SXFRCTL1,
785 ahc_inb(ahc, SXFRCTL1) | BITBUCKET);
788 if ((ahc_inb(ahc, SCSISIGI)
793 ahc_outb(ahc, SXFRCTL1,
794 ahc_inb(ahc, SXFRCTL1) & ~BITBUCKET);
799 ahc_print_devinfo(ahc, &devinfo);
802 scb_index = ahc_inb(ahc, SCB_TAG);
803 scb = ahc_lookup_scb(ahc, scb_index);
807 ahc_reset_channel(ahc, devinfo.channel,
811 ahc_inb(ahc, SCSIDATL);
826 u_int scbindex = ahc_inb(ahc, SCB_TAG);
827 u_int lastphase = ahc_inb(ahc, LASTPHASE);
830 scb = ahc_lookup_scb(ahc, scbindex);
835 ahc_print_path(ahc, scb);
840 ahc_print_path(ahc, scb);
842 ahc_inb(ahc, SEQ_FLAGS) & DPHASE ? "Have" : "Haven't",
860 ahc_freeze_devq(ahc, scb);
869 if ((ahc->features & AHC_ULTRA2) != 0) {
874 ahc_outb(ahc, SXFRCTL0,
875 ahc_inb(ahc, SXFRCTL0) | CLRSTCNT|CLRCHN);
876 ahc_outb(ahc, SXFRCTL0,
877 ahc_inb(ahc, SXFRCTL0) | CLRSTCNT|CLRCHN);
879 if ((ahc->flags & AHC_39BIT_ADDRESSING) != 0) {
883 dscommand1 = ahc_inb(ahc, DSCOMMAND1);
884 ahc_outb(ahc, DSCOMMAND1, dscommand1 | HADDLDSEL0);
885 ahc_outb(ahc, HADDR, 0);
886 ahc_outb(ahc, DSCOMMAND1, dscommand1);
895 ahc_name(ahc), devinfo.channel, devinfo.target,
897 scbindex = ahc_inb(ahc, SCB_TAG);
898 scb = ahc_lookup_scb(ahc, scbindex);
905 ahc_search_qinfifo(ahc, SCB_GET_TARGET(ahc, scb),
906 SCB_GET_CHANNEL(ahc, scb),
914 printf("%s: No free or disconnected SCBs\n", ahc_name(ahc));
915 ahc_dump_card_state(ahc);
923 scbptr = ahc_inb(ahc, SCBPTR);
925 scbptr, ahc_inb(ahc, ARG_1),
926 ahc->scb_data->hscbs[scbptr].tag);
927 ahc_dump_card_state(ahc);
933 printf("%s: BTT calculation out of range\n", ahc_name(ahc));
936 ahc_inb(ahc, SAVED_SCSIID), ahc_inb(ahc, SAVED_LUN),
937 ahc_inb(ahc, ARG_1), ahc_inb(ahc, ACCUM));
940 ahc_inb(ahc, SEQ_FLAGS), ahc_inb(ahc, SCBPTR),
941 ahc_index_busy_tcl(ahc,
942 BUILD_TCL(ahc_inb(ahc, SAVED_SCSIID),
943 ahc_inb(ahc, SAVED_LUN))),
944 ahc_inb(ahc, SINDEX),
945 ahc_inb(ahc, ACCUM));
948 ahc_inb(ahc, SCSIID), ahc_inb(ahc, SCB_SCSIID),
949 ahc_inb(ahc, SCB_LUN), ahc_inb(ahc, SCB_TAG),
950 ahc_inb(ahc, SCB_CONTROL));
952 ahc_inb(ahc, SCSIBUSL), ahc_inb(ahc, SCSISIGI));
953 ahc_dump_card_state(ahc);
960 intstat, ahc_inb(ahc, SCSISIGI));
969 ahc_unpause(ahc);
973 ahc_handle_scsiint(struct ahc_softc *ahc, u_int intstat)
982 if ((ahc->features & AHC_TWIN) != 0
983 && ((ahc_inb(ahc, SBLKCTL) & SELBUSB) != 0))
989 if ((ahc->features & AHC_ULTRA2) != 0)
990 status0 = ahc_inb(ahc, SSTAT0) & IOERR;
993 status = ahc_inb(ahc, SSTAT1) & (SELTO|SCSIRSTI|BUSFREE|SCSIPERR);
995 if ((ahc->features & AHC_TWIN) != 0) {
997 ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) ^ SELBUSB);
998 status = ahc_inb(ahc, SSTAT1)
1003 printf("%s: Spurious SCSI interrupt\n", ahc_name(ahc));
1004 ahc_outb(ahc, CLRINT, CLRSCSIINT);
1005 ahc_unpause(ahc);
1011 ahc_clear_critical_section(ahc);
1013 scb_index = ahc_inb(ahc, SCB_TAG);
1014 scb = ahc_lookup_scb(ahc, scb_index);
1016 && (ahc_inb(ahc, SEQ_FLAGS) & NOT_IDENTIFIED) != 0)
1019 if ((ahc->features & AHC_ULTRA2) != 0
1023 now_lvd = ahc_inb(ahc, SBLKCTL) & ENAB40;
1025 ahc_name(ahc), now_lvd ? "LVD" : "SE");
1026 ahc_outb(ahc, CLRSINT0, CLRIOERR);
1037 ahc_reset_channel(ahc, intr_channel,
1041 ahc_name(ahc), intr_channel);
1043 ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) ^ SELBUSB);
1044 ahc_reset_channel(ahc, intr_channel, /*Initiate Reset*/FALSE);
1066 lastphase = ahc_inb(ahc, LASTPHASE);
1067 curphase = ahc_inb(ahc, SCSISIGI) & PHASE_MASK;
1068 sstat2 = ahc_inb(ahc, SSTAT2);
1069 ahc_outb(ahc, CLRSINT1, CLRSCSIPERR);
1081 if ((ahc_inb(ahc, SSTAT1) & SCSIPERR) != 0
1097 ahc_print_path(ahc, scb);
1100 printf("%s:%c:%d: ", ahc_name(ahc), intr_channel,
1101 SCSIID_TARGET(ahc, ahc_inb(ahc, SAVED_SCSIID)));
1102 scsirate = ahc_inb(ahc, SCSIRATE);
1107 ahc_inw(ahc, SEQADDR0),
1109 if ((ahc->features & AHC_DT) != 0) {
1125 if ((ahc->features & AHC_DT) != 0
1143 if (ahc->msg_type != MSG_TYPE_NONE)
1144 ahc->send_msg_perror = TRUE;
1146 ahc_outb(ahc, MSG_OUT, mesg_out);
1153 ahc_fetch_devinfo(ahc, &devinfo);
1154 ahc_force_renegotiation(ahc, &devinfo);
1156 ahc_outb(ahc, CLRINT, CLRSCSIINT);
1157 ahc_unpause(ahc);
1162 ahc_outb(ahc, SCSISEQ, 0);
1165 ahc_clear_msg_state(ahc);
1168 ahc_outb(ahc, SIMODE1, ahc_inb(ahc, SIMODE1) & ~ENBUSFREE);
1169 ahc_outb(ahc, CLRSINT1, CLRSELTIMEO|CLRBUSFREE|CLRSCSIPERR);
1179 ahc_outb(ahc, CLRSINT0, CLRSELINGO);
1181 scbptr = ahc_inb(ahc, WAITING_SCBH);
1182 ahc_outb(ahc, SCBPTR, scbptr);
1183 scb_index = ahc_inb(ahc, SCB_TAG);
1185 scb = ahc_lookup_scb(ahc, scb_index);
1189 ahc_name(ahc), scbptr, scb_index);
1190 ahc_dump_card_state(ahc);
1195 ahc_print_path(ahc, scb);
1200 ahc_scb_devinfo(ahc, &devinfo, scb);
1202 ahc_freeze_devq(ahc, scb);
1210 ahc_handle_devreset(ahc, &devinfo,
1215 ahc_outb(ahc, CLRINT, CLRSCSIINT);
1216 ahc_restart(ahc);
1218 && (ahc_inb(ahc, SIMODE1) & ENBUSFREE) != 0) {
1234 ahc_outb(ahc, SCSISEQ,
1235 ahc_inb(ahc, SCSISEQ) & (ENSELI|ENRSELI|ENAUTOATNP));
1243 ahc_outb(ahc, SIMODE1, ahc_inb(ahc, SIMODE1) & ~ENBUSFREE);
1244 ahc_outb(ahc, CLRSINT1, CLRBUSFREE|CLRSCSIPERR);
1252 lastphase = ahc_inb(ahc, LASTPHASE);
1253 saved_scsiid = ahc_inb(ahc, SAVED_SCSIID);
1254 saved_lun = ahc_inb(ahc, SAVED_LUN);
1255 target = SCSIID_TARGET(ahc, saved_scsiid);
1257 channel = SCSIID_CHANNEL(ahc, saved_scsiid);
1266 if (ahc_sent_msg(ahc, AHCMSG_1B, MSG_ABORT_TAG, TRUE)
1267 || ahc_sent_msg(ahc, AHCMSG_1B, MSG_ABORT, TRUE)) {
1268 if (ahc->msgout_buf[ahc->msgout_index - 1]
1271 ahc_print_path(ahc, scb);
1275 ahc_abort_scbs(ahc, target, channel,
1280 } else if (ahc_sent_msg(ahc, AHCMSG_1B,
1290 && ahc_match_scb(ahc, scb, target, channel,
1303 ahc_handle_devreset(ahc, &devinfo,
1308 } else if (ahc_sent_msg(ahc, AHCMSG_EXT,
1317 tinfo = ahc_fetch_transinfo(ahc,
1325 ahc_qinfifo_requeue_tail(ahc, scb);
1327 } else if (ahc_sent_msg(ahc, AHCMSG_EXT,
1333 ahc_set_width(ahc, &devinfo,
1337 ahc_qinfifo_requeue_tail(ahc, scb);
1339 } else if (ahc_sent_msg(ahc, AHCMSG_EXT,
1345 ahc_set_syncrate(ahc, &devinfo,
1351 ahc_qinfifo_requeue_tail(ahc, scb);
1365 ahc_print_path(ahc, scb);
1366 ahc_abort_scbs(ahc, target, channel,
1375 printf("%s: ", ahc_name(ahc));
1388 ahc_force_renegotiation(ahc, &devinfo);
1393 ahc_inb(ahc, SEQADDR0)
1394 | (ahc_inb(ahc, SEQADDR1) << 8));
1396 ahc_outb(ahc, CLRINT, CLRSCSIINT);
1397 ahc_restart(ahc);
1400 ahc_name(ahc), status);
1401 ahc_outb(ahc, CLRINT, CLRSCSIINT);
1410 ahc_force_renegotiation(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
1415 targ_info = ahc_fetch_transinfo(ahc,
1420 ahc_update_neg_request(ahc, devinfo, tstate,
1426 ahc_clear_critical_section(struct ahc_softc *ahc)
1433 if (ahc->num_critical_sections == 0)
1445 seqaddr = ahc_inb(ahc, SEQADDR0)
1446 | (ahc_inb(ahc, SEQADDR1) << 8);
1453 cs = ahc->critical_sections;
1454 for (i = 0; i < ahc->num_critical_sections; i++, cs++) {
1460 if (i == ahc->num_critical_sections)
1465 ahc_name(ahc));
1466 ahc_dump_card_state(ahc);
1479 simode0 = ahc_inb(ahc, SIMODE0);
1480 ahc_outb(ahc, SIMODE0, 0);
1481 simode1 = ahc_inb(ahc, SIMODE1);
1482 if ((ahc->features & AHC_DT) != 0)
1491 ahc_outb(ahc, SIMODE1, simode1 & ENBUSFREE);
1493 ahc_outb(ahc, SIMODE1, 0);
1494 ahc_outb(ahc, CLRINT, CLRSCSIINT);
1495 ahc_outb(ahc, SEQCTL, ahc->seqctl | STEP);
1498 if ((ahc->features & AHC_DT) != 0) {
1499 ahc_outb(ahc, CLRSINT1, CLRBUSFREE);
1500 ahc_outb(ahc, CLRINT, CLRSCSIINT);
1502 ahc_outb(ahc, HCNTRL, ahc->unpause);
1503 while (!ahc_is_paused(ahc))
1507 ahc_outb(ahc, SIMODE0, simode0);
1508 ahc_outb(ahc, SIMODE1, simode1);
1509 ahc_outb(ahc, SEQCTL, ahc->seqctl);
1517 ahc_clear_intstat(struct ahc_softc *ahc)
1520 ahc_outb(ahc, CLRSINT1, CLRSELTIMEO|CLRATNO|CLRSCSIRSTI
1523 ahc_flush_device_writes(ahc);
1524 ahc_outb(ahc, CLRSINT0, CLRSELDO|CLRSELDI|CLRSELINGO);
1525 ahc_flush_device_writes(ahc);
1526 ahc_outb(ahc, CLRINT, CLRSCSIINT);
1527 ahc_flush_device_writes(ahc);
1574 ahc_alloc_tstate(struct ahc_softc *ahc, u_int scsi_id, char channel)
1580 master_tstate = ahc->enabled_targets[ahc->our_id];
1583 master_tstate = ahc->enabled_targets[ahc->our_id_b + 8];
1585 if (ahc->enabled_targets[scsi_id] != NULL
1586 && ahc->enabled_targets[scsi_id] != master_tstate)
1588 ahc_name(ahc));
1612 ahc->enabled_targets[scsi_id] = tstate;
1622 ahc_free_tstate(struct ahc_softc *ahc, u_int scsi_id, char channel, int force)
1630 if (((channel == 'B' && scsi_id == ahc->our_id_b)
1631 || (channel == 'A' && scsi_id == ahc->our_id))
1637 tstate = ahc->enabled_targets[scsi_id];
1640 ahc->enabled_targets[scsi_id] = NULL;
1651 ahc_devlimited_syncrate(struct ahc_softc *ahc,
1658 if ((ahc->features & AHC_ULTRA2) != 0) {
1659 if ((ahc_inb(ahc, SBLKCTL) & ENAB40) != 0
1660 && (ahc_inb(ahc, SSTAT2) & EXP_ACTIVE) == 0) {
1667 } else if ((ahc->features & AHC_ULTRA) != 0) {
1697 return (ahc_find_syncrate(ahc, period, ppr_options, maxsync));
1706 ahc_find_syncrate(struct ahc_softc *ahc, u_int *period,
1711 if ((ahc->features & AHC_DT) == 0)
1727 if ((ahc->features & AHC_ULTRA2) != 0
1758 || ((ahc->features & AHC_ULTRA2) != 0
1773 ahc_find_period(struct ahc_softc *ahc, u_int scsirate, u_int maxsync)
1777 if ((ahc->features & AHC_ULTRA2) != 0)
1785 if ((ahc->features & AHC_ULTRA2) != 0) {
1803 ahc_validate_offset(struct ahc_softc *ahc,
1813 } else if ((ahc->features & AHC_ULTRA2) != 0) {
1835 ahc_validate_width(struct ahc_softc *ahc, struct ahc_initiator_tinfo *tinfo,
1840 if (ahc->features & AHC_WIDE) {
1865 ahc_update_neg_request(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
1879 if ((ahc->features & AHC_WIDE) != 0)
1908 ahc_set_syncrate(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
1928 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, devinfo->our_scsiid,
1955 if ((ahc->features & AHC_ULTRA2) != 0) {
1984 sxfrctl0 = ahc_inb(ahc, SXFRCTL0);
1988 ahc_outb(ahc, SXFRCTL0, sxfrctl0);
1992 ahc_outb(ahc, SCSIRATE, scsirate);
1993 if ((ahc->features & AHC_ULTRA2) != 0)
1994 ahc_outb(ahc, SCSIOFFSET, offset);
2002 ahc_send_async(ahc, devinfo->channel, devinfo->target,
2007 "offset = 0x%x\n", ahc_name(ahc),
2014 ahc_name(ahc), devinfo->target);
2019 update_needed += ahc_update_neg_request(ahc, devinfo, tstate,
2023 ahc_update_pending_scbs(ahc);
2035 ahc_set_width(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
2046 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, devinfo->our_scsiid,
2068 ahc_outb(ahc, SCSIRATE, scsirate);
2072 ahc_send_async(ahc, devinfo->channel, devinfo->target,
2076 ahc_name(ahc), devinfo->target,
2081 update_needed += ahc_update_neg_request(ahc, devinfo, tstate,
2084 ahc_update_pending_scbs(ahc);
2091 ahc_set_tags(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
2094 ahc_platform_set_tags(ahc, devinfo, alg);
2095 ahc_send_async(ahc, devinfo->channel, devinfo->target,
2105 ahc_update_pending_scbs(struct ahc_softc *ahc)
2118 LIST_FOREACH(pending_scb, &ahc->pending_scbs, pending_links) {
2124 ahc_scb_devinfo(ahc, &devinfo, pending_scb);
2125 tinfo = ahc_fetch_transinfo(ahc, devinfo.channel,
2139 ahc_sync_scb(ahc, pending_scb,
2147 if (ahc_is_paused(ahc)) {
2151 ahc_pause(ahc);
2154 saved_scbptr = ahc_inb(ahc, SCBPTR);
2156 for (i = 0; i < ahc->scb_data->maxhscbs; i++) {
2161 ahc_outb(ahc, SCBPTR, i);
2162 scb_tag = ahc_inb(ahc, SCB_TAG);
2163 pending_scb = ahc_lookup_scb(ahc, scb_tag);
2168 control = ahc_inb(ahc, SCB_CONTROL);
2171 ahc_outb(ahc, SCB_CONTROL, control);
2172 ahc_outb(ahc, SCB_SCSIRATE, pending_hscb->scsirate);
2173 ahc_outb(ahc, SCB_SCSIOFFSET, pending_hscb->scsioffset);
2175 ahc_outb(ahc, SCBPTR, saved_scbptr);
2178 ahc_unpause(ahc);
2183 ahc_fetch_devinfo(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
2189 if (ahc_inb(ahc, SSTAT0) & TARGET)
2195 && (ahc->features & AHC_MULTI_TID) != 0
2196 && (ahc_inb(ahc, SEQ_FLAGS)
2199 our_id = ahc_inb(ahc, TARGIDIN) & OID;
2200 } else if ((ahc->features & AHC_ULTRA2) != 0)
2201 our_id = ahc_inb(ahc, SCSIID_ULTRA2) & OID;
2203 our_id = ahc_inb(ahc, SCSIID) & OID;
2205 saved_scsiid = ahc_inb(ahc, SAVED_SCSIID);
2208 SCSIID_TARGET(ahc, saved_scsiid),
2209 ahc_inb(ahc, SAVED_LUN),
2210 SCSIID_CHANNEL(ahc, saved_scsiid),
2248 ahc_print_devinfo(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
2250 printf("%s:%c:%d:%d: ", ahc_name(ahc), devinfo->channel,
2255 ahc_scb_devinfo(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
2265 ahc_compile_devinfo(devinfo, our_id, SCB_GET_TARGET(ahc, scb),
2266 SCB_GET_LUN(scb), SCB_GET_CHANNEL(ahc, scb), role);
2272 ahc_assert_atn(struct ahc_softc *ahc)
2277 if ((ahc->features & AHC_DT) == 0)
2278 scsisigo |= ahc_inb(ahc, SCSISIGI);
2279 ahc_outb(ahc, SCSISIGO, scsisigo);
2289 ahc_setup_initiator_msgout(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
2297 ahc->msgout_index = 0;
2298 ahc->msgout_len = 0;
2301 && ahc_inb(ahc, MSG_OUT) == MSG_IDENTIFYFLAG) {
2307 ahc->msgout_buf[ahc->msgout_index++] = identify_msg;
2308 ahc->msgout_len++;
2311 ahc->msgout_buf[ahc->msgout_index++] =
2313 ahc->msgout_buf[ahc->msgout_index++] = scb->hscb->tag;
2314 ahc->msgout_len += 2;
2319 ahc->msgout_buf[ahc->msgout_index++] = MSG_BUS_DEV_RESET;
2320 ahc->msgout_len++;
2321 ahc_print_path(ahc, scb);
2330 ahc_outb(ahc, SCSISEQ, (ahc_inb(ahc, SCSISEQ) & ~ENSELO));
2333 ahc->msgout_buf[ahc->msgout_index++] = MSG_ABORT_TAG;
2335 ahc->msgout_buf[ahc->msgout_index++] = MSG_ABORT;
2336 ahc->msgout_len++;
2337 ahc_print_path(ahc, scb);
2347 ahc_outb(ahc, SCSISEQ, (ahc_inb(ahc, SCSISEQ) & ~ENSELO));
2349 ahc_build_transfer_msg(ahc, devinfo);
2357 ahc_inb(ahc, MSG_OUT), scb->flags);
2364 ahc_outb(ahc, SCB_CONTROL, ahc_inb(ahc, SCB_CONTROL) & ~MK_MESSAGE);
2366 ahc->msgout_index = 0;
2367 ahc->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
2375 ahc_build_transfer_msg(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
2392 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, devinfo->our_scsiid,
2406 rate = ahc_devlimited_syncrate(ahc, tinfo, &period,
2427 if ((ahc->features & AHC_WIDE) != 0)
2433 ahc_print_devinfo(ahc, devinfo);
2453 ahc_validate_offset(ahc, tinfo, rate, &offset,
2458 ahc_construct_ppr(ahc, devinfo, period, offset,
2461 ahc_construct_sdtr(ahc, devinfo, period, offset);
2464 ahc_construct_wdtr(ahc, devinfo, tinfo->goal.width);
2473 ahc_construct_sdtr(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
2478 ahc->msgout_buf[ahc->msgout_index++] = MSG_EXTENDED;
2479 ahc->msgout_buf[ahc->msgout_index++] = MSG_EXT_SDTR_LEN;
2480 ahc->msgout_buf[ahc->msgout_index++] = MSG_EXT_SDTR;
2481 ahc->msgout_buf[ahc->msgout_index++] = period;
2482 ahc->msgout_buf[ahc->msgout_index++] = offset;
2483 ahc->msgout_len += 5;
2486 ahc_name(ahc), devinfo->channel, devinfo->target,
2496 ahc_construct_wdtr(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
2499 ahc->msgout_buf[ahc->msgout_index++] = MSG_EXTENDED;
2500 ahc->msgout_buf[ahc->msgout_index++] = MSG_EXT_WDTR_LEN;
2501 ahc->msgout_buf[ahc->msgout_index++] = MSG_EXT_WDTR;
2502 ahc->msgout_buf[ahc->msgout_index++] = bus_width;
2503 ahc->msgout_len += 4;
2506 ahc_name(ahc), devinfo->channel, devinfo->target,
2516 ahc_construct_ppr(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
2522 ahc->msgout_buf[ahc->msgout_index++] = MSG_EXTENDED;
2523 ahc->msgout_buf[ahc->msgout_index++] = MSG_EXT_PPR_LEN;
2524 ahc->msgout_buf[ahc->msgout_index++] = MSG_EXT_PPR;
2525 ahc->msgout_buf[ahc->msgout_index++] = period;
2526 ahc->msgout_buf[ahc->msgout_index++] = 0;
2527 ahc->msgout_buf[ahc->msgout_index++] = offset;
2528 ahc->msgout_buf[ahc->msgout_index++] = bus_width;
2529 ahc->msgout_buf[ahc->msgout_index++] = ppr_options;
2530 ahc->msgout_len += 8;
2533 "offset %x, ppr_options %x\n", ahc_name(ahc),
2543 ahc_clear_msg_state(struct ahc_softc *ahc)
2545 ahc->msgout_len = 0;
2546 ahc->msgin_index = 0;
2547 ahc->msg_type = MSG_TYPE_NONE;
2548 if ((ahc_inb(ahc, SCSISIGI) & ATNI) != 0) {
2553 ahc_outb(ahc, CLRSINT1, CLRATNO);
2555 ahc_outb(ahc, MSG_OUT, MSG_NOOP);
2556 ahc_outb(ahc, SEQ_FLAGS2,
2557 ahc_inb(ahc, SEQ_FLAGS2) & ~TARGET_MSG_PENDING);
2561 ahc_handle_proto_violation(struct ahc_softc *ahc)
2571 ahc_fetch_devinfo(ahc, &devinfo);
2572 scbid = ahc_inb(ahc, SCB_TAG);
2573 scb = ahc_lookup_scb(ahc, scbid);
2574 seq_flags = ahc_inb(ahc, SEQ_FLAGS);
2575 curphase = ahc_inb(ahc, SCSISIGI) & PHASE_MASK;
2576 lastphase = ahc_inb(ahc, LASTPHASE);
2584 ahc_print_devinfo(ahc, &devinfo);
2593 ahc_print_devinfo(ahc, &devinfo);
2599 ahc_print_path(ahc, scb);
2601 } else if ((ahc_inb(ahc, SCB_CONTROL) & STATUS_RCVD) == 0) {
2609 ahc_print_path(ahc, scb);
2612 ahc_print_path(ahc, scb);
2614 ahc_dump_card_state(ahc);
2626 found = ahc_reset_channel(ahc, 'A', TRUE);
2628 "%d SCBs aborted\n", ahc_name(ahc), 'A', found);
2635 ahc_outb(ahc, SCSISEQ,
2636 ahc_inb(ahc, SCSISEQ) & ~ENSELO);
2637 ahc_assert_atn(ahc);
2638 ahc_outb(ahc, MSG_OUT, HOST_MSG);
2640 ahc_print_devinfo(ahc, &devinfo);
2641 ahc->msgout_buf[0] = MSG_ABORT_TASK;
2642 ahc->msgout_len = 1;
2643 ahc->msgout_index = 0;
2644 ahc->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
2646 ahc_print_path(ahc, scb);
2658 ahc_handle_message_phase(struct ahc_softc *ahc)
2664 ahc_fetch_devinfo(ahc, &devinfo);
2666 bus_phase = ahc_inb(ahc, SCSISIGI) & PHASE_MASK;
2669 switch (ahc->msg_type) {
2676 if (ahc->msgout_len == 0)
2681 ahc_print_devinfo(ahc, &devinfo);
2701 ahc_outb(ahc, CLRSINT1, CLRATNO);
2702 ahc->send_msg_perror = FALSE;
2703 ahc->msg_type = MSG_TYPE_INITIATOR_MSGIN;
2704 ahc->msgin_index = 0;
2711 if (ahc->send_msg_perror) {
2712 ahc_outb(ahc, CLRSINT1, CLRATNO);
2713 ahc_outb(ahc, CLRSINT1, CLRREQINIT);
2716 printf(" byte 0x%x\n", ahc->send_msg_perror);
2718 ahc_outb(ahc, SCSIDATL, MSG_PARITY_ERROR);
2722 msgdone = ahc->msgout_index == ahc->msgout_len;
2729 ahc->msgout_index = 0;
2730 ahc_assert_atn(ahc);
2733 lastbyte = ahc->msgout_index == (ahc->msgout_len - 1);
2736 ahc_outb(ahc, CLRSINT1, CLRATNO);
2743 ahc_outb(ahc, CLRSINT1, CLRREQINIT);
2747 ahc->msgout_buf[ahc->msgout_index]);
2749 ahc_outb(ahc, SCSIDATL, ahc->msgout_buf[ahc->msgout_index++]);
2759 ahc_print_devinfo(ahc, &devinfo);
2772 ahc->msgin_index = 0;
2774 && (ahc->send_msg_perror == TRUE
2775 || (ahc->msgout_len != 0
2776 && ahc->msgout_index == 0))) {
2777 ahc->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
2785 ahc->msgin_buf[ahc->msgin_index] = ahc_inb(ahc, SCSIBUSL);
2789 ahc->msgin_buf[ahc->msgin_index]);
2792 message_done = ahc_parse_msg(ahc, &devinfo);
2799 ahc->msgin_index = 0;
2806 if (ahc->msgout_len != 0) {
2809 ahc_print_devinfo(ahc, &devinfo);
2813 ahc_assert_atn(ahc);
2816 ahc->msgin_index++;
2822 ahc_outb(ahc, CLRSINT1, CLRREQINIT);
2823 ahc_inb(ahc, SCSIDATL);
2831 if (ahc->msgout_len == 0)
2836 ahc_print_devinfo(ahc, &devinfo);
2847 if ((ahc_inb(ahc, SCSISIGI) & ATNI) != 0
2848 && ahc->msgout_index > 0) {
2859 ahc->msg_type = MSG_TYPE_TARGET_MSGOUT;
2865 ahc_outb(ahc, SXFRCTL0,
2866 ahc_inb(ahc, SXFRCTL0) & ~SPIOEN);
2874 while ((ahc_inb(ahc, SCSISIGI) & ACKI) != 0)
2877 ahc_outb(ahc, SCSISIGO, P_MESGOUT | BSYO);
2884 ahc_flush_device_writes(ahc);
2887 ahc->msgin_index = 0;
2889 ahc_outb(ahc, SXFRCTL0,
2890 ahc_inb(ahc, SXFRCTL0) | SPIOEN);
2894 msgdone = ahc->msgout_index == ahc->msgout_len;
2896 ahc_outb(ahc, SXFRCTL0,
2897 ahc_inb(ahc, SXFRCTL0) & ~SPIOEN);
2908 ahc->msgout_buf[ahc->msgout_index]);
2910 ahc_outb(ahc, SXFRCTL0, ahc_inb(ahc, SXFRCTL0) | SPIOEN);
2911 ahc_outb(ahc, SCSIDATL, ahc->msgout_buf[ahc->msgout_index++]);
2921 ahc_print_devinfo(ahc, &devinfo);
2929 lastbyte = (ahc_inb(ahc, SCSISIGI) & ATNI) == 0;
2936 ahc_outb(ahc, SXFRCTL0, ahc_inb(ahc, SXFRCTL0) & ~SPIOEN);
2937 ahc->msgin_buf[ahc->msgin_index] = ahc_inb(ahc, SCSIDATL);
2942 ahc->msgin_buf[ahc->msgin_index]);
2945 msgdone = ahc_parse_msg(ahc, &devinfo);
2956 ahc->msgin_index++;
2963 ahc->msgin_index = 0;
2969 if (ahc->msgout_len != 0) {
2972 ahc_print_devinfo(ahc, &devinfo);
2976 ahc_outb(ahc, SCSISIGO, P_MESGIN | BSYO);
2987 ahc_flush_device_writes(ahc);
2997 ahc_outb(ahc, SXFRCTL0,
2998 ahc_inb(ahc, SXFRCTL0) | SPIOEN);
2999 ahc->msg_type = MSG_TYPE_TARGET_MSGIN;
3000 ahc->msgin_index = 0;
3009 ahc_outb(ahc, SXFRCTL0,
3010 ahc_inb(ahc, SXFRCTL0) | SPIOEN);
3020 ahc_clear_msg_state(ahc);
3021 ahc_outb(ahc, RETURN_1, EXIT_MSG_LOOP);
3023 ahc_outb(ahc, RETURN_1, CONT_MSG_LOOP);
3033 ahc_sent_msg(struct ahc_softc *ahc, ahc_msgtype type, u_int msgval, int full)
3041 while (index < ahc->msgout_len) {
3042 if (ahc->msgout_buf[index] == MSG_EXTENDED) {
3045 end_index = index + 1 + ahc->msgout_buf[index + 1];
3046 if (ahc->msgout_buf[index+2] == msgval
3050 if (ahc->msgout_index > end_index)
3052 } else if (ahc->msgout_index > index)
3056 } else if (ahc->msgout_buf[index] >= MSG_SIMPLE_TASK
3057 && ahc->msgout_buf[index] <= MSG_IGN_WIDE_RESIDUE) {
3064 && ahc->msgout_buf[index] == msgval
3065 && ahc->msgout_index > index)
3080 ahc_parse_msg(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
3092 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, devinfo->our_scsiid,
3107 switch (ahc->msgin_buf[0]) {
3120 response = ahc_handle_msg_reject(ahc, devinfo);
3128 if (ahc->msgin_index < 2)
3130 switch (ahc->msgin_buf[2]) {
3139 if (ahc->msgin_buf[1] != MSG_EXT_SDTR_LEN) {
3151 if (ahc->msgin_index < (MSG_EXT_SDTR_LEN + 1))
3154 period = ahc->msgin_buf[3];
3156 saved_offset = offset = ahc->msgin_buf[4];
3157 syncrate = ahc_devlimited_syncrate(ahc, tinfo, &period,
3160 ahc_validate_offset(ahc, tinfo, syncrate, &offset,
3167 ahc_name(ahc), devinfo->channel,
3169 ahc->msgin_buf[3], saved_offset,
3172 ahc_set_syncrate(ahc, devinfo,
3183 if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_SDTR, TRUE)) {
3197 ahc_name(ahc), devinfo->channel,
3200 ahc->msgout_index = 0;
3201 ahc->msgout_len = 0;
3202 ahc_construct_sdtr(ahc, devinfo,
3204 ahc->msgout_index = 0;
3217 if (ahc->msgin_buf[1] != MSG_EXT_WDTR_LEN) {
3229 if (ahc->msgin_index < (MSG_EXT_WDTR_LEN + 1))
3232 bus_width = ahc->msgin_buf[3];
3234 ahc_validate_width(ahc, tinfo, &bus_width,
3239 ahc_name(ahc), devinfo->channel,
3244 if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_WDTR, TRUE)) {
3255 ahc_name(ahc), devinfo->channel,
3268 ahc_name(ahc), devinfo->channel,
3271 ahc->msgout_index = 0;
3272 ahc->msgout_len = 0;
3273 ahc_construct_wdtr(ahc, devinfo, bus_width);
3274 ahc->msgout_index = 0;
3287 ahc_update_neg_request(ahc, devinfo, tstate,
3289 ahc_set_width(ahc, devinfo, bus_width,
3297 ahc->msgout_index = 0;
3298 ahc->msgout_len = 0;
3299 ahc_build_transfer_msg(ahc, devinfo);
3300 ahc->msgout_index = 0;
3317 if (ahc->msgin_buf[1] != MSG_EXT_PPR_LEN) {
3329 if (ahc->msgin_index < (MSG_EXT_PPR_LEN + 1))
3332 period = ahc->msgin_buf[3];
3333 offset = ahc->msgin_buf[5];
3334 bus_width = ahc->msgin_buf[6];
3336 ppr_options = ahc->msgin_buf[7];
3357 ahc_validate_width(ahc, tinfo, &bus_width,
3359 syncrate = ahc_devlimited_syncrate(ahc, tinfo, &period,
3362 ahc_validate_offset(ahc, tinfo, syncrate,
3366 if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_PPR, TRUE)) {
3386 ahc_name(ahc), devinfo->channel,
3391 ahc_name(ahc), devinfo->channel,
3393 ahc->msgout_index = 0;
3394 ahc->msgout_len = 0;
3395 ahc_construct_ppr(ahc, devinfo, period, offset,
3397 ahc->msgout_index = 0;
3405 ahc_name(ahc), devinfo->channel,
3407 saved_width, ahc->msgin_buf[3],
3411 ahc_set_width(ahc, devinfo, bus_width,
3414 ahc_set_syncrate(ahc, devinfo,
3431 ahc_handle_devreset(ahc, devinfo,
3435 ahc_restart(ahc);
3450 if (ahc->msgin_buf[0] == MSG_ABORT_TAG)
3451 tag = ahc_inb(ahc, INITIATOR_TAG);
3452 ahc_abort_scbs(ahc, devinfo->target, devinfo->channel,
3456 tstate = ahc->enabled_targets[devinfo->our_scsiid];
3462 ahc_queue_lstate_event(ahc, lstate,
3464 ahc->msgin_buf[0],
3466 ahc_send_lstate_events(ahc, lstate);
3469 ahc_restart(ahc);
3484 ahc->msgout_index = 0;
3485 ahc->msgout_len = 1;
3486 ahc->msgout_buf[0] = MSG_MESSAGE_REJECT;
3493 ahc->msgout_len = 0;
3502 ahc_handle_msg_reject(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
3517 scb_index = ahc_inb(ahc, SCB_TAG);
3518 scb = ahc_lookup_scb(ahc, scb_index);
3519 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel,
3523 last_msg = ahc_inb(ahc, LAST_MSG);
3525 if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_PPR, /*full*/FALSE)) {
3533 ahc_name(ahc), devinfo->channel,
3539 ahc->msgout_index = 0;
3540 ahc->msgout_len = 0;
3541 ahc_build_transfer_msg(ahc, devinfo);
3542 ahc->msgout_index = 0;
3544 } else if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_WDTR, /*full*/FALSE)) {
3548 "8bit transfers\n", ahc_name(ahc),
3550 ahc_set_width(ahc, devinfo, MSG_EXT_WDTR_BUS_8_BIT,
3563 ahc->msgout_index = 0;
3564 ahc->msgout_len = 0;
3565 ahc_build_transfer_msg(ahc, devinfo);
3566 ahc->msgout_index = 0;
3569 } else if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_SDTR, /*full*/FALSE)) {
3571 ahc_set_syncrate(ahc, devinfo, /*syncrate*/NULL, /*period*/0,
3577 ahc_name(ahc), devinfo->channel,
3587 "Performing non-tagged I/O\n", ahc_name(ahc),
3589 ahc_set_tags(ahc, devinfo, AHC_QUEUE_NONE);
3594 ahc_name(ahc), devinfo->channel, devinfo->target,
3597 ahc_set_tags(ahc, devinfo, AHC_QUEUE_BASIC);
3605 ahc_outb(ahc, SCB_CONTROL,
3606 ahc_inb(ahc, SCB_CONTROL) & mask);
3610 ahc_outb(ahc, MSG_OUT, MSG_IDENTIFYFLAG);
3611 ahc_assert_atn(ahc);
3617 if ((ahc->flags & AHC_SCB_BTT) == 0) {
3621 &(ahc->untagged_queues[devinfo->target_offset]);
3625 ahc_busy_tcl(ahc, BUILD_TCL(scb->hscb->scsiid, devinfo->lun),
3633 ahc_search_qinfifo(ahc, SCB_GET_TARGET(ahc, scb),
3634 SCB_GET_CHANNEL(ahc, scb),
3643 ahc_name(ahc), devinfo->channel, devinfo->target,
3653 ahc_handle_ign_wide_residue(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
3658 scb_index = ahc_inb(ahc, SCB_TAG);
3659 scb = ahc_lookup_scb(ahc, scb_index);
3664 if ((ahc_inb(ahc, SEQ_FLAGS) & DPHASE) == 0
3680 sgptr = ahc_inb(ahc, SCB_RESIDUAL_SGPTR);
3682 && (ahc_inb(ahc, SCB_LUN) & SCB_XFERLEN_ODD) != 0) {
3696 sgptr = ahc_inl(ahc, SCB_RESIDUAL_SGPTR);
3697 data_cnt = ahc_inl(ahc, SCB_RESIDUAL_DATACNT);
3708 data_addr = ahc_inl(ahc, SHADDR);
3742 ahc_outl(ahc, SCB_RESIDUAL_SGPTR, sgptr);
3743 ahc_outl(ahc, SCB_RESIDUAL_DATACNT, data_cnt);
3750 ahc_outb(ahc, SCB_LUN,
3751 ahc_inb(ahc, SCB_LUN) ^ SCB_XFERLEN_ODD);
3762 ahc_reinitialize_dataptrs(struct ahc_softc *ahc)
3771 scb_index = ahc_inb(ahc, SCB_TAG);
3772 scb = ahc_lookup_scb(ahc, scb_index);
3773 sgptr = (ahc_inb(ahc, SCB_RESIDUAL_SGPTR + 3) << 24)
3774 | (ahc_inb(ahc, SCB_RESIDUAL_SGPTR + 2) << 16)
3775 | (ahc_inb(ahc, SCB_RESIDUAL_SGPTR + 1) << 8)
3776 | ahc_inb(ahc, SCB_RESIDUAL_SGPTR);
3784 resid = (ahc_inb(ahc, SCB_RESIDUAL_DATACNT + 2) << 16)
3785 | (ahc_inb(ahc, SCB_RESIDUAL_DATACNT + 1) << 8)
3786 | ahc_inb(ahc, SCB_RESIDUAL_DATACNT);
3791 if ((ahc->flags & AHC_39BIT_ADDRESSING) != 0) {
3794 dscommand1 = ahc_inb(ahc, DSCOMMAND1);
3795 ahc_outb(ahc, DSCOMMAND1, dscommand1 | HADDLDSEL0);
3796 ahc_outb(ahc, HADDR,
3798 ahc_outb(ahc, DSCOMMAND1, dscommand1);
3800 ahc_outb(ahc, HADDR + 3, dataptr >> 24);
3801 ahc_outb(ahc, HADDR + 2, dataptr >> 16);
3802 ahc_outb(ahc, HADDR + 1, dataptr >> 8);
3803 ahc_outb(ahc, HADDR, dataptr);
3804 ahc_outb(ahc, HCNT + 2, resid >> 16);
3805 ahc_outb(ahc, HCNT + 1, resid >> 8);
3806 ahc_outb(ahc, HCNT, resid);
3807 if ((ahc->features & AHC_ULTRA2) == 0) {
3808 ahc_outb(ahc, STCNT + 2, resid >> 16);
3809 ahc_outb(ahc, STCNT + 1, resid >> 8);
3810 ahc_outb(ahc, STCNT, resid);
3818 ahc_handle_devreset(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
3827 found = ahc_abort_scbs(ahc, devinfo->target, devinfo->channel,
3836 tstate = ahc->enabled_targets[devinfo->our_scsiid];
3845 ahc_queue_lstate_event(ahc, lstate, devinfo->our_scsiid,
3847 ahc_send_lstate_events(ahc, lstate);
3855 ahc_set_width(ahc, devinfo, MSG_EXT_WDTR_BUS_8_BIT,
3857 ahc_set_syncrate(ahc, devinfo, /*syncrate*/NULL,
3862 ahc_send_async(ahc, devinfo->channel, devinfo->target,
3867 printf("%s: %s on %c:%d. %d SCBs aborted\n", ahc_name(ahc),
3873 ahc_setup_target_msgin(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
3882 ahc->msgout_index = 0;
3883 ahc->msgout_len = 0;
3886 ahc_build_transfer_msg(ahc, devinfo);
3890 ahc->msgout_index = 0;
3891 ahc->msg_type = MSG_TYPE_TARGET_MSGIN;
3902 struct ahc_softc *ahc;
3906 ahc = malloc(sizeof(*ahc), M_DEVBUF, M_NOWAIT);
3907 if (!ahc) {
3913 ahc = device_get_softc((device_t)platform_arg);
3915 memset(ahc, 0, sizeof(*ahc));
3916 ahc->seep_config = malloc(sizeof(*ahc->seep_config),
3918 if (ahc->seep_config == NULL) {
3920 free(ahc, M_DEVBUF);
3925 LIST_INIT(&ahc->pending_scbs);
3926 LIST_INIT(&ahc->timedout_scbs);
3928 ahc->name = name;
3929 ahc->unit = -1;
3930 ahc->description = NULL;
3931 ahc->channel = 'A';
3932 ahc->channel_b = 'B';
3933 ahc->chip = AHC_NONE;
3934 ahc->features = AHC_FENONE;
3935 ahc->bugs = AHC_BUGNONE;
3936 ahc->flags = AHC_FNONE;
3942 ahc->seqctl = FASTMODE;
3945 TAILQ_INIT(&ahc->untagged_queues[i]);
3946 if (ahc_platform_alloc(ahc, platform_arg) != 0) {
3947 ahc_free(ahc);
3948 ahc = NULL;
3950 ahc_lockinit(ahc);
3951 return (ahc);
3955 ahc_softc_init(struct ahc_softc *ahc)
3959 if ((ahc->chip & AHC_PCI) == 0)
3960 ahc->unpause = ahc_inb(ahc, HCNTRL) & IRQMS;
3962 ahc->unpause = 0;
3963 ahc->pause = ahc->unpause | PAUSE;
3965 if (ahc->scb_data == NULL) {
3966 ahc->scb_data = malloc(sizeof(*ahc->scb_data),
3968 if (ahc->scb_data == NULL)
3970 memset(ahc->scb_data, 0, sizeof(*ahc->scb_data));
3977 ahc_softc_insert(struct ahc_softc *ahc)
3986 if ((ahc->chip & AHC_BUS_MASK) == AHC_PCI
3987 && (ahc->features & AHC_MULTI_FUNC) != 0) {
3993 pci = ahc->dev_softc;
4001 slave = ahc;
4003 master = ahc;
4023 && ahc_softc_comp(ahc, list_ahc) <= 0)
4026 TAILQ_INSERT_BEFORE(list_ahc, ahc, links);
4028 TAILQ_INSERT_TAIL(&ahc_tailq, ahc, links);
4029 ahc->init_level++;
4033 ahc_set_unit(struct ahc_softc *ahc, int unit)
4035 ahc->unit = unit;
4039 ahc_set_name(struct ahc_softc *ahc, char *name)
4041 if (ahc->name != NULL)
4042 free(ahc->name, M_DEVBUF);
4043 ahc->name = name;
4047 ahc_free(struct ahc_softc *ahc)
4051 ahc_terminate_recovery_thread(ahc);
4052 switch (ahc->init_level) {
4055 ahc_shutdown(ahc);
4058 aic_dmamap_unload(ahc, ahc->shared_data_dmat,
4059 ahc->shared_data_dmamap);
4062 aic_dmamem_free(ahc, ahc->shared_data_dmat, ahc->qoutfifo,
4063 ahc->shared_data_dmamap);
4066 aic_dma_tag_destroy(ahc, ahc->shared_data_dmat);
4069 aic_dma_tag_destroy(ahc, ahc->buffer_dmat);
4077 aic_dma_tag_destroy(ahc, ahc->parent_dmat);
4079 ahc_platform_free(ahc);
4080 ahc_fini_scbdata(ahc);
4084 tstate = ahc->enabled_targets[i];
4103 if (ahc->black_hole != NULL) {
4104 xpt_free_path(ahc->black_hole->path);
4105 free(ahc->black_hole, M_DEVBUF);
4108 if (ahc->name != NULL)
4109 free(ahc->name, M_DEVBUF);
4110 if (ahc->seep_config != NULL)
4111 free(ahc->seep_config, M_DEVBUF);
4113 free(ahc, M_DEVBUF);
4121 struct ahc_softc *ahc;
4124 ahc = (struct ahc_softc *)arg;
4127 ahc_reset(ahc, /*reinit*/FALSE);
4128 ahc_outb(ahc, SCSISEQ, 0);
4129 ahc_outb(ahc, SXFRCTL0, 0);
4130 ahc_outb(ahc, DSPCISTATUS, 0);
4133 ahc_outb(ahc, i, 0);
4146 ahc_reset(struct ahc_softc *ahc, int reinit)
4158 ahc_pause(ahc);
4160 if ((ahc->chip & AHC_CHIPID_MASK) == AHC_AIC7770) {
4167 sblkctl = ahc_inb(ahc, SBLKCTL);
4168 ahc_outb(ahc, SBLKCTL, sblkctl | SELBUSB);
4169 sxfrctl1_b = ahc_inb(ahc, SXFRCTL1);
4170 ahc_outb(ahc, SBLKCTL, sblkctl & ~SELBUSB);
4172 sxfrctl1_a = ahc_inb(ahc, SXFRCTL1);
4174 ahc_outb(ahc, HCNTRL, CHIPRST | ahc->pause);
4185 } while (--wait && !(ahc_inb(ahc, HCNTRL) & CHIPRSTACK));
4189 "Trying to initialize anyway.\n", ahc_name(ahc));
4191 ahc_outb(ahc, HCNTRL, ahc->pause);
4194 sblkctl = ahc_inb(ahc, SBLKCTL) & (SELBUSB|SELWIDE);
4196 if ((ahc->chip & AHC_PCI) != 0)
4204 ahc->features |= AHC_WIDE;
4208 ahc->features |= AHC_TWIN;
4223 if ((ahc->features & AHC_TWIN) != 0) {
4226 sblkctl = ahc_inb(ahc, SBLKCTL);
4227 ahc_outb(ahc, SBLKCTL, sblkctl | SELBUSB);
4228 ahc_outb(ahc, SXFRCTL1, sxfrctl1_b);
4229 ahc_outb(ahc, SBLKCTL, sblkctl & ~SELBUSB);
4231 ahc_outb(ahc, SXFRCTL1, sxfrctl1_a);
4239 error = ahc->bus_chip_init(ahc);
4242 ahc_dumpseq(ahc);
4252 ahc_probe_scbs(struct ahc_softc *ahc) {
4257 ahc_outb(ahc, SCBPTR, i);
4258 ahc_outb(ahc, SCB_BASE, i);
4259 if (ahc_inb(ahc, SCB_BASE) != i)
4261 ahc_outb(ahc, SCBPTR, 0);
4262 if (ahc_inb(ahc, SCB_BASE) != 0)
4278 ahc_build_free_scb_list(struct ahc_softc *ahc)
4284 if ((ahc->flags & AHC_LSCBS_ENABLED) != 0)
4287 for (i = 0; i < ahc->scb_data->maxhscbs; i++) {
4290 ahc_outb(ahc, SCBPTR, i);
4298 ahc_outb(ahc, SCB_BASE+j, 0xFF);
4301 ahc_outb(ahc, SCB_CONTROL, 0);
4304 if ((ahc->flags & AHC_PAGESCBS) != 0)
4305 ahc_outb(ahc, SCB_NEXT, i+1);
4307 ahc_outb(ahc, SCB_NEXT, SCB_LIST_NULL);
4310 ahc_outb(ahc, SCB_TAG, SCB_LIST_NULL);
4311 ahc_outb(ahc, SCB_SCSIID, 0xFF);
4312 ahc_outb(ahc, SCB_LUN, 0xFF);
4315 if ((ahc->flags & AHC_PAGESCBS) != 0) {
4317 ahc_outb(ahc, FREE_SCBH, 0);
4320 ahc_outb(ahc, FREE_SCBH, SCB_LIST_NULL);
4324 ahc_outb(ahc, SCBPTR, i-1);
4325 ahc_outb(ahc, SCB_NEXT, SCB_LIST_NULL);
4329 ahc_init_scbdata(struct ahc_softc *ahc)
4333 scb_data = ahc->scb_data;
4347 scb_data->maxhscbs = ahc_probe_scbs(ahc);
4348 if (ahc->scb_data->maxhscbs == 0) {
4349 printf("%s: No SCB space found\n", ahc_name(ahc));
4364 if (aic_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/1,
4379 if (aic_dmamem_alloc(ahc, scb_data->hscb_dmat,
4389 aic_dmamap_load(ahc, scb_data->hscb_dmat, scb_data->hscb_dmamap,
4397 if (aic_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/1,
4412 if (aic_dmamem_alloc(ahc, scb_data->sense_dmat,
4421 aic_dmamap_load(ahc, scb_data->sense_dmat, scb_data->sense_dmamap,
4429 if (aic_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/8,
4445 while (ahc_alloc_scbs(ahc) != 0)
4451 ahc_name(ahc));
4458 ahc->next_queued_scb = ahc_get_scb(ahc);
4471 ahc_fini_scbdata(struct ahc_softc *ahc)
4475 scb_data = ahc->scb_data;
4487 aic_dmamap_unload(ahc, scb_data->sg_dmat,
4489 aic_dmamem_free(ahc, scb_data->sg_dmat,
4494 aic_dma_tag_destroy(ahc, scb_data->sg_dmat);
4497 aic_dmamap_unload(ahc, scb_data->sense_dmat,
4500 aic_dmamem_free(ahc, scb_data->sense_dmat, scb_data->sense,
4503 aic_dma_tag_destroy(ahc, scb_data->sense_dmat);
4505 aic_dmamap_unload(ahc, scb_data->hscb_dmat,
4508 aic_dmamem_free(ahc, scb_data->hscb_dmat, scb_data->hscbs,
4511 aic_dma_tag_destroy(ahc, scb_data->hscb_dmat);
4521 ahc_alloc_scbs(struct ahc_softc *ahc)
4531 scb_data = ahc->scb_data;
4544 if (aic_dmamem_alloc(ahc, scb_data->sg_dmat,
4554 aic_dmamap_load(ahc, scb_data->sg_dmat, sg_map->sg_dmamap,
4580 next_scb->ahc_softc = ahc;
4583 error = aic_dmamap_create(ahc, ahc->buffer_dmat, /*flags*/0,
4589 next_scb->hscb->tag = ahc->scb_data->numscbs;
4591 SLIST_INSERT_HEAD(&ahc->scb_data->free_scbs,
4596 ahc->scb_data->numscbs++;
4602 ahc_controller_info(struct ahc_softc *ahc, char *buf)
4606 len = sprintf(buf, "%s: ", ahc_chip_names[ahc->chip & AHC_CHIPID_MASK]);
4608 if ((ahc->features & AHC_TWIN) != 0)
4611 ahc->our_id, ahc->our_id_b,
4612 (ahc->flags & AHC_PRIMARY_CHANNEL) + 'A');
4618 if ((ahc->features & AHC_ULTRA) != 0) {
4620 } else if ((ahc->features & AHC_DT) != 0) {
4622 } else if ((ahc->features & AHC_ULTRA2) != 0) {
4625 if ((ahc->features & AHC_WIDE) != 0) {
4631 speed, type, ahc->channel, ahc->our_id);
4635 if ((ahc->flags & AHC_PAGESCBS) != 0)
4637 ahc->scb_data->maxhscbs, AHC_MAX_QUEUE);
4639 sprintf(buf, "%d SCBs", ahc->scb_data->maxhscbs);
4643 ahc_chip_init(struct ahc_softc *ahc)
4652 ahc_outb(ahc, SEQ_FLAGS, 0);
4653 ahc_outb(ahc, SEQ_FLAGS2, 0);
4656 if (ahc->features & AHC_TWIN) {
4661 ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) | SELBUSB);
4662 term = (ahc->flags & AHC_TERM_ENB_B) != 0 ? STPWEN : 0;
4663 ahc_outb(ahc, SCSIID, ahc->our_id_b);
4664 scsi_conf = ahc_inb(ahc, SCSICONF + 1);
4665 ahc_outb(ahc, SXFRCTL1, (scsi_conf & (ENSPCHK|STIMESEL))
4666 |term|ahc->seltime_b|ENSTIMER|ACTNEGEN);
4667 if ((ahc->features & AHC_ULTRA2) != 0)
4668 ahc_outb(ahc, SIMODE0, ahc_inb(ahc, SIMODE0)|ENIOERR);
4669 ahc_outb(ahc, SIMODE1, ENSELTIMO|ENSCSIRST|ENSCSIPERR);
4670 ahc_outb(ahc, SXFRCTL0, DFON|SPIOEN);
4673 ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) & ~SELBUSB);
4675 term = (ahc->flags & AHC_TERM_ENB_A) != 0 ? STPWEN : 0;
4676 if ((ahc->features & AHC_ULTRA2) != 0)
4677 ahc_outb(ahc, SCSIID_ULTRA2, ahc->our_id);
4679 ahc_outb(ahc, SCSIID, ahc->our_id);
4680 scsi_conf = ahc_inb(ahc, SCSICONF);
4681 ahc_outb(ahc, SXFRCTL1, (scsi_conf & (ENSPCHK|STIMESEL))
4682 |term|ahc->seltime
4684 if ((ahc->features & AHC_ULTRA2) != 0)
4685 ahc_outb(ahc, SIMODE0, ahc_inb(ahc, SIMODE0)|ENIOERR);
4686 ahc_outb(ahc, SIMODE1, ENSELTIMO|ENSCSIRST|ENSCSIPERR);
4687 ahc_outb(ahc, SXFRCTL0, DFON|SPIOEN);
4691 ahc_unbusy_tcl(ahc, BUILD_TCL(i << 4, 0));
4692 if ((ahc->flags & AHC_SCB_BTT) != 0) {
4700 ahc_unbusy_tcl(ahc, BUILD_TCL(i << 4, lun));
4706 ahc->qoutfifo[i] = SCB_LIST_NULL;
4707 ahc_sync_qoutfifo(ahc, BUS_DMASYNC_PREREAD);
4710 ahc->qinfifo[i] = SCB_LIST_NULL;
4712 if ((ahc->features & AHC_MULTI_TID) != 0) {
4713 ahc_outb(ahc, TARGID, 0);
4714 ahc_outb(ahc, TARGID + 1, 0);
4720 physaddr = ahc->scb_data->hscb_busaddr;
4721 ahc_outb(ahc, HSCB_ADDR, physaddr & 0xFF);
4722 ahc_outb(ahc, HSCB_ADDR + 1, (physaddr >> 8) & 0xFF);
4723 ahc_outb(ahc, HSCB_ADDR + 2, (physaddr >> 16) & 0xFF);
4724 ahc_outb(ahc, HSCB_ADDR + 3, (physaddr >> 24) & 0xFF);
4726 physaddr = ahc->shared_data_busaddr;
4727 ahc_outb(ahc, SHARED_DATA_ADDR, physaddr & 0xFF);
4728 ahc_outb(ahc, SHARED_DATA_ADDR + 1, (physaddr >> 8) & 0xFF);
4729 ahc_outb(ahc, SHARED_DATA_ADDR + 2, (physaddr >> 16) & 0xFF);
4730 ahc_outb(ahc, SHARED_DATA_ADDR + 3, (physaddr >> 24) & 0xFF);
4737 ahc_outb(ahc, CMDSIZE_TABLE, 5);
4738 ahc_outb(ahc, CMDSIZE_TABLE + 1, 9);
4739 ahc_outb(ahc, CMDSIZE_TABLE + 2, 9);
4740 ahc_outb(ahc, CMDSIZE_TABLE + 3, 0);
4741 ahc_outb(ahc, CMDSIZE_TABLE + 4, 15);
4742 ahc_outb(ahc, CMDSIZE_TABLE + 5, 11);
4743 ahc_outb(ahc, CMDSIZE_TABLE + 6, 0);
4744 ahc_outb(ahc, CMDSIZE_TABLE + 7, 0);
4746 if ((ahc->features & AHC_HS_MAILBOX) != 0)
4747 ahc_outb(ahc, HS_MAILBOX, 0);
4750 if ((ahc->features & AHC_TARGETMODE) != 0) {
4751 ahc->tqinfifonext = 1;
4752 ahc_outb(ahc, KERNEL_TQINPOS, ahc->tqinfifonext - 1);
4753 ahc_outb(ahc, TQINPOS, ahc->tqinfifonext);
4755 ahc->qinfifonext = 0;
4756 ahc->qoutfifonext = 0;
4757 if ((ahc->features & AHC_QUEUE_REGS) != 0) {
4758 ahc_outb(ahc, QOFF_CTLSTA, SCB_QSIZE_256);
4759 ahc_outb(ahc, HNSCB_QOFF, ahc->qinfifonext);
4760 ahc_outb(ahc, SNSCB_QOFF, ahc->qinfifonext);
4761 ahc_outb(ahc, SDSCB_QOFF, 0);
4763 ahc_outb(ahc, KERNEL_QINPOS, ahc->qinfifonext);
4764 ahc_outb(ahc, QINPOS, ahc->qinfifonext);
4765 ahc_outb(ahc, QOUTPOS, ahc->qoutfifonext);
4769 ahc_outb(ahc, WAITING_SCBH, SCB_LIST_NULL);
4772 ahc_outb(ahc, DISCONNECTED_SCBH, SCB_LIST_NULL);
4775 ahc_outb(ahc, MSG_OUT, MSG_NOOP);
4783 if ((ahc->flags & AHC_INITIATORROLE) != 0)
4785 ahc_outb(ahc, SCSISEQ_TEMPLATE, scsiseq_template);
4788 ahc_build_free_scb_list(ahc);
4793 ahc_outb(ahc, NEXT_QUEUED_SCB, ahc->next_queued_scb->hscb->tag);
4801 ahc_name(ahc));
4803 error = ahc_loadseq(ahc);
4807 if ((ahc->features & AHC_ULTRA2) != 0) {
4818 (ahc_inb(ahc, SBLKCTL) & (ENAB40|ENAB20)) == 0 && wait;
4822 ahc_restart(ahc);
4830 ahc_init(struct ahc_softc *ahc)
4843 ahc->flags |= AHC_SEQUENCER_DEBUG;
4852 printf (" 0x%x", ahc_inb(ahc, i));
4854 if ((ahc->features & AHC_MORE_SRAM) != 0) {
4859 printf (" 0x%x", ahc_inb(ahc, i));
4867 ahc_outb(ahc, CLRINT, CLRPARERR);
4868 ahc_outb(ahc, CLRINT, CLRBRKADRINT);
4875 if ((ahc->flags & AHC_USEDEFAULTS) != 0)
4876 ahc->our_id = ahc->our_id_b = 7;
4881 ahc->flags |= AHC_INITIATORROLE;
4886 if ((AHC_TMODE_ENABLE & (0x1 << ahc->unit)) == 0)
4887 ahc->features &= ~AHC_TARGETMODE;
4891 if (aic_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/1,
4893 /*lowaddr*/ahc->flags & AHC_39BIT_ADDRESSING
4902 &ahc->buffer_dmat) != 0) {
4907 ahc->init_level++;
4919 if ((ahc->features & AHC_TARGETMODE) != 0)
4922 if (aic_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/1,
4930 /*flags*/0, &ahc->shared_data_dmat) != 0) {
4934 ahc->init_level++;
4937 if (aic_dmamem_alloc(ahc, ahc->shared_data_dmat,
4938 (void **)&ahc->qoutfifo,
4940 &ahc->shared_data_dmamap) != 0) {
4944 ahc->init_level++;
4947 aic_dmamap_load(ahc, ahc->shared_data_dmat, ahc->shared_data_dmamap,
4948 ahc->qoutfifo, driver_data_size, ahc_dmamap_cb,
4949 &ahc->shared_data_busaddr, /*flags*/0);
4951 if ((ahc->features & AHC_TARGETMODE) != 0) {
4952 ahc->targetcmds = (struct target_cmd *)ahc->qoutfifo;
4953 ahc->qoutfifo = (uint8_t *)&ahc->targetcmds[AHC_TMODE_CMDS];
4954 ahc->dma_bug_buf = ahc->shared_data_busaddr
4958 ahc->targetcmds[i].cmd_valid = 0;
4959 ahc_sync_tqinfifo(ahc, BUS_DMASYNC_PREREAD);
4960 ahc->qoutfifo = (uint8_t *)&ahc->targetcmds[256];
4962 ahc->qinfifo = &ahc->qoutfifo[256];
4964 ahc->init_level++;
4967 if (ahc->scb_data->maxhscbs == 0)
4968 if (ahc_init_scbdata(ahc) != 0)
4976 if (ahc_alloc_tstate(ahc, ahc->our_id, 'A') == NULL) {
4978 "Failing attach\n", ahc_name(ahc));
4982 if ((ahc->features & AHC_TWIN) != 0) {
4983 if (ahc_alloc_tstate(ahc, ahc->our_id_b, 'B') == NULL) {
4985 "Failing attach\n", ahc_name(ahc));
4993 error = ahc_spawn_recovery_thread(ahc);
4997 if (ahc->scb_data->maxhscbs < AHC_SCB_MAX_ALLOC) {
4998 ahc->flags |= AHC_PAGESCBS;
5000 ahc->flags &= ~AHC_PAGESCBS;
5007 ahc_name(ahc),
5018 if (ahc->features & AHC_TWIN) {
5019 scsi_conf = ahc_inb(ahc, SCSICONF + 1);
5021 && (ahc->flags & AHC_INITIATORROLE) != 0)
5022 ahc->flags |= AHC_RESET_BUS_B;
5025 scsi_conf = ahc_inb(ahc, SCSICONF);
5027 && (ahc->flags & AHC_INITIATORROLE) != 0)
5028 ahc->flags |= AHC_RESET_BUS_A;
5034 if ((ahc->flags & AHC_USEDEFAULTS) != 0) {
5036 "device parameters\n", ahc_name(ahc));
5037 ahc->flags |= AHC_EXTENDED_TRANS_A|AHC_EXTENDED_TRANS_B|
5040 if ((ahc->features & AHC_ULTRA) != 0)
5043 discenable = ~((ahc_inb(ahc, DISC_DSB + 1) << 8)
5044 | ahc_inb(ahc, DISC_DSB));
5045 if ((ahc->features & (AHC_ULTRA|AHC_ULTRA2)) != 0)
5046 ultraenb = (ahc_inb(ahc, ULTRA_ENB + 1) << 8)
5047 | ahc_inb(ahc, ULTRA_ENB);
5050 if ((ahc->features & (AHC_WIDE|AHC_TWIN)) == 0)
5061 our_id = ahc->our_id;
5063 if (i > 7 && (ahc->features & AHC_TWIN) != 0) {
5065 our_id = ahc->our_id_b;
5068 tinfo = ahc_fetch_transinfo(ahc, channel, our_id,
5072 if (ahc->flags & AHC_USEDEFAULTS) {
5073 if ((ahc->features & AHC_WIDE) != 0)
5087 scsirate = ahc_inb(ahc, TARG_SCSIRATE + i);
5089 if ((ahc->features & AHC_ULTRA2) != 0) {
5104 offset = ahc_inb(ahc, TARG_OFFSET + i);
5109 if ((ahc->features & AHC_DT) != 0)
5112 ahc_find_period(ahc, scsirate, maxsync);
5118 && (ahc->features & AHC_DT) != 0)
5129 ahc_find_period(ahc, scsirate,
5139 && (ahc->features & AHC_WIDE) != 0)
5142 if ((ahc->features & AHC_DT) != 0)
5153 ahc->user_discenable = discenable;
5154 ahc->user_tagenable = tagenable;
5156 return (ahc->bus_chip_init(ahc));
5160 ahc_intr_enable(struct ahc_softc *ahc, int enable)
5164 hcntrl = ahc_inb(ahc, HCNTRL);
5166 ahc->pause &= ~INTEN;
5167 ahc->unpause &= ~INTEN;
5170 ahc->pause |= INTEN;
5171 ahc->unpause |= INTEN;
5173 ahc_outb(ahc, HCNTRL, hcntrl);
5184 ahc_pause_and_flushwork(struct ahc_softc *ahc)
5191 ahc->flags |= AHC_ALL_INTERRUPTS;
5195 ahc_unpause(ahc);
5202 ahc_intr(ahc);
5203 ahc_pause(ahc);
5205 ahc_outb(ahc, SCSISEQ, ahc_inb(ahc, SCSISEQ) & ~ENSELO);
5206 intstat = ahc_inb(ahc, INTSTAT);
5208 ahc_clear_critical_section(ahc);
5209 intstat = ahc_inb(ahc, INTSTAT);
5212 && (intstat != 0xFF || (ahc->features & AHC_REMOVABLE) == 0)
5214 || (ahc_inb(ahc, SSTAT0) & (SELDO|SELINGO)) != 0));
5217 ahc_inb(ahc, INTSTAT));
5219 ahc_platform_flushwork(ahc);
5220 ahc->flags &= ~AHC_ALL_INTERRUPTS;
5224 ahc_suspend(struct ahc_softc *ahc)
5227 ahc_pause_and_flushwork(ahc);
5229 if (LIST_FIRST(&ahc->pending_scbs) != NULL) {
5230 ahc_unpause(ahc);
5240 if (ahc->pending_device != NULL) {
5241 ahc_unpause(ahc);
5245 ahc_shutdown(ahc);
5250 ahc_resume(struct ahc_softc *ahc)
5253 ahc_reset(ahc, /*reinit*/TRUE);
5254 ahc_intr_enable(ahc, TRUE);
5255 ahc_restart(ahc);
5265 ahc_index_busy_tcl(struct ahc_softc *ahc, u_int tcl)
5270 if ((ahc->flags & AHC_SCB_BTT) != 0) {
5273 saved_scbptr = ahc_inb(ahc, SCBPTR);
5274 ahc_outb(ahc, SCBPTR, TCL_LUN(tcl));
5275 scbid = ahc_inb(ahc, SCB_64_BTT + TCL_TARGET_OFFSET(tcl));
5276 ahc_outb(ahc, SCBPTR, saved_scbptr);
5279 scbid = ahc_inb(ahc, BUSY_TARGETS + target_offset);
5286 ahc_unbusy_tcl(struct ahc_softc *ahc, u_int tcl)
5290 if ((ahc->flags & AHC_SCB_BTT) != 0) {
5293 saved_scbptr = ahc_inb(ahc, SCBPTR);
5294 ahc_outb(ahc, SCBPTR, TCL_LUN(tcl));
5295 ahc_outb(ahc, SCB_64_BTT+TCL_TARGET_OFFSET(tcl), SCB_LIST_NULL);
5296 ahc_outb(ahc, SCBPTR, saved_scbptr);
5299 ahc_outb(ahc, BUSY_TARGETS + target_offset, SCB_LIST_NULL);
5304 ahc_busy_tcl(struct ahc_softc *ahc, u_int tcl, u_int scbid)
5308 if ((ahc->flags & AHC_SCB_BTT) != 0) {
5311 saved_scbptr = ahc_inb(ahc, SCBPTR);
5312 ahc_outb(ahc, SCBPTR, TCL_LUN(tcl));
5313 ahc_outb(ahc, SCB_64_BTT + TCL_TARGET_OFFSET(tcl), scbid);
5314 ahc_outb(ahc, SCBPTR, saved_scbptr);
5317 ahc_outb(ahc, BUSY_TARGETS + target_offset, scbid);
5323 ahc_match_scb(struct ahc_softc *ahc, struct scb *scb, int target,
5326 int targ = SCB_GET_TARGET(ahc, scb);
5327 char chan = SCB_GET_CHANNEL(ahc, scb);
5359 ahc_freeze_devq(struct ahc_softc *ahc, struct scb *scb)
5365 target = SCB_GET_TARGET(ahc, scb);
5367 channel = SCB_GET_CHANNEL(ahc, scb);
5369 ahc_search_qinfifo(ahc, target, channel, lun,
5373 ahc_platform_freeze_devq(ahc, scb);
5377 ahc_qinfifo_requeue_tail(struct ahc_softc *ahc, struct scb *scb)
5382 if (ahc_qinfifo_count(ahc) != 0) {
5386 prev_pos = ahc->qinfifonext - 1;
5387 prev_tag = ahc->qinfifo[prev_pos];
5388 prev_scb = ahc_lookup_scb(ahc, prev_tag);
5390 ahc_qinfifo_requeue(ahc, prev_scb, scb);
5391 if ((ahc->features & AHC_QUEUE_REGS) != 0) {
5392 ahc_outb(ahc, HNSCB_QOFF, ahc->qinfifonext);
5394 ahc_outb(ahc, KERNEL_QINPOS, ahc->qinfifonext);
5399 ahc_qinfifo_requeue(struct ahc_softc *ahc, struct scb *prev_scb,
5403 ahc_outb(ahc, NEXT_QUEUED_SCB, scb->hscb->tag);
5406 ahc_sync_scb(ahc, prev_scb,
5409 ahc->qinfifo[ahc->qinfifonext++] = scb->hscb->tag;
5410 scb->hscb->next = ahc->next_queued_scb->hscb->tag;
5411 ahc_sync_scb(ahc, scb, BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
5415 ahc_qinfifo_count(struct ahc_softc *ahc)
5420 if ((ahc->features & AHC_QUEUE_REGS) != 0) {
5421 qinpos = ahc_inb(ahc, SNSCB_QOFF);
5422 ahc_outb(ahc, SNSCB_QOFF, qinpos);
5424 qinpos = ahc_inb(ahc, QINPOS);
5425 diff = ahc->qinfifonext - qinpos;
5430 ahc_search_qinfifo(struct ahc_softc *ahc, int target, char channel,
5445 qintail = ahc->qinfifonext;
5446 have_qregs = (ahc->features & AHC_QUEUE_REGS) != 0;
5448 qinstart = ahc_inb(ahc, SNSCB_QOFF);
5449 ahc_outb(ahc, SNSCB_QOFF, qinstart);
5451 qinstart = ahc_inb(ahc, QINPOS);
5461 ahc_freeze_untagged_queues(ahc);
5468 ahc->qinfifonext = qinpos;
5469 ahc_outb(ahc, NEXT_QUEUED_SCB, ahc->next_queued_scb->hscb->tag);
5472 scb = ahc_lookup_scb(ahc, ahc->qinfifo[qinpos]);
5475 qinpos, ahc->qinfifo[qinpos]);
5479 if (ahc_match_scb(ahc, scb, target, channel, lun, tag, role)) {
5498 ahc_done(ahc, scb);
5505 ahc_qinfifo_requeue(ahc, prev_scb, scb);
5510 ahc_qinfifo_requeue(ahc, prev_scb, scb);
5516 if ((ahc->features & AHC_QUEUE_REGS) != 0) {
5517 ahc_outb(ahc, HNSCB_QOFF, ahc->qinfifonext);
5519 ahc_outb(ahc, KERNEL_QINPOS, ahc->qinfifonext);
5524 && (qinstart != ahc->qinfifonext)) {
5537 scb = ahc_lookup_scb(ahc, ahc->qinfifo[qinstart]);
5541 found, qinstart, ahc->qinfifonext);
5551 ahc->scb_data->scbindex[scb->hscb->tag] = NULL;
5552 ahc_swap_with_next_hscb(ahc, scb);
5554 ahc->qinfifo[qinstart] = scb->hscb->tag;
5557 ahc_outb(ahc, NEXT_QUEUED_SCB, scb->hscb->tag);
5560 qintail = ahc->qinfifonext - 1;
5561 scb = ahc_lookup_scb(ahc, ahc->qinfifo[qintail]);
5562 scb->hscb->next = ahc->next_queued_scb->hscb->tag;
5568 curscbptr = ahc_inb(ahc, SCBPTR);
5569 next = ahc_inb(ahc, WAITING_SCBH); /* Start at head of list. */
5575 ahc_outb(ahc, SCBPTR, next);
5576 scb_index = ahc_inb(ahc, SCB_TAG);
5577 if (scb_index >= ahc->scb_data->numscbs) {
5580 scb_index, ahc->scb_data->numscbs);
5581 ahc_dump_card_state(ahc);
5584 scb = ahc_lookup_scb(ahc, scb_index);
5590 if (ahc_match_scb(ahc, scb, target, channel,
5611 ahc_done(ahc, scb);
5615 next = ahc_rem_wscb(ahc, next, prev);
5619 next = ahc_inb(ahc, SCB_NEXT);
5625 next = ahc_inb(ahc, SCB_NEXT);
5628 ahc_outb(ahc, SCBPTR, curscbptr);
5630 found += ahc_search_untagged_queues(ahc, /*aic_io_ctx_t*/NULL, target,
5634 ahc_release_untagged_queues(ahc);
5639 ahc_search_untagged_queues(struct ahc_softc *ahc, aic_io_ctx_t ctx,
5653 ahc_freeze_untagged_queues(ahc);
5658 if ((ahc->flags & AHC_SCB_BTT) == 0) {
5676 untagged_q = &(ahc->untagged_queues[i]);
5695 if (ahc_match_scb(ahc, scb, target, channel, lun,
5716 ahc_done(ahc, scb);
5730 ahc_release_untagged_queues(ahc);
5735 ahc_search_disc_list(struct ahc_softc *ahc, int target, char channel,
5746 next = ahc_inb(ahc, DISCONNECTED_SCBH);
5751 active_scb = ahc_inb(ahc, SCBPTR);
5759 ahc_outb(ahc, SCBPTR, next);
5760 scb_index = ahc_inb(ahc, SCB_TAG);
5761 if (scb_index >= ahc->scb_data->numscbs) {
5764 scb_index, ahc->scb_data->numscbs);
5765 ahc_dump_card_state(ahc);
5774 scbp = ahc_lookup_scb(ahc, scb_index);
5775 if (ahc_match_scb(ahc, scbp, target, channel, lun,
5780 ahc_rem_scb_from_disc_list(ahc, prev, next);
5783 next = ahc_inb(ahc, SCB_NEXT);
5789 next = ahc_inb(ahc, SCB_NEXT);
5793 ahc_outb(ahc, SCBPTR, active_scb);
5802 ahc_rem_scb_from_disc_list(struct ahc_softc *ahc, u_int prev, u_int scbptr)
5806 ahc_outb(ahc, SCBPTR, scbptr);
5807 next = ahc_inb(ahc, SCB_NEXT);
5809 ahc_outb(ahc, SCB_CONTROL, 0);
5811 ahc_add_curscb_to_free_list(ahc);
5814 ahc_outb(ahc, SCBPTR, prev);
5815 ahc_outb(ahc, SCB_NEXT, next);
5817 ahc_outb(ahc, DISCONNECTED_SCBH, next);
5828 ahc_add_curscb_to_free_list(struct ahc_softc *ahc)
5834 ahc_outb(ahc, SCB_TAG, SCB_LIST_NULL);
5836 if ((ahc->flags & AHC_PAGESCBS) != 0) {
5837 ahc_outb(ahc, SCB_NEXT, ahc_inb(ahc, FREE_SCBH));
5838 ahc_outb(ahc, FREE_SCBH, ahc_inb(ahc, SCBPTR));
5847 ahc_rem_wscb(struct ahc_softc *ahc, u_int scbpos, u_int prev)
5855 curscb = ahc_inb(ahc, SCBPTR);
5856 ahc_outb(ahc, SCBPTR, scbpos);
5857 next = ahc_inb(ahc, SCB_NEXT);
5860 ahc_outb(ahc, SCB_CONTROL, 0);
5862 ahc_add_curscb_to_free_list(ahc);
5867 ahc_outb(ahc, WAITING_SCBH, next);
5873 ahc_outb(ahc, SCSISEQ, (ahc_inb(ahc, SCSISEQ) & ~ENSELO));
5879 ahc_outb(ahc, SCBPTR, prev);
5880 ahc_outb(ahc, SCB_NEXT, next);
5886 ahc_outb(ahc, SCBPTR, curscb);
5898 ahc_abort_scbs(struct ahc_softc *ahc, int target, char channel,
5915 ahc_freeze_untagged_queues(ahc);
5918 active_scb = ahc_inb(ahc, SCBPTR);
5920 found = ahc_search_qinfifo(ahc, target, channel, lun, SCB_LIST_NULL,
5945 if ((ahc->flags & AHC_SCB_BTT) != 0)
5959 scbid = ahc_index_busy_tcl(ahc, tcl);
5960 scbp = ahc_lookup_scb(ahc, scbid);
5962 || ahc_match_scb(ahc, scbp, target, channel,
5965 ahc_unbusy_tcl(ahc, BUILD_TCL(i << 4, j));
5975 ahc_search_disc_list(ahc, target, channel, lun, tag,
5987 for (i = 0; i < ahc->scb_data->maxhscbs; i++) {
5990 ahc_outb(ahc, SCBPTR, i);
5991 scbid = ahc_inb(ahc, SCB_TAG);
5992 scbp = ahc_lookup_scb(ahc, scbid);
5995 && ahc_match_scb(ahc, scbp, target, channel, lun, tag, role)))
5996 ahc_add_curscb_to_free_list(ahc);
6005 scbp_next = LIST_FIRST(&ahc->pending_scbs);
6009 if (ahc_match_scb(ahc, scbp, target, channel, lun, tag, role)) {
6019 ahc_done(ahc, scbp);
6023 ahc_outb(ahc, SCBPTR, active_scb);
6024 ahc_platform_abort_scbs(ahc, target, channel, lun, tag, role, status);
6025 ahc_release_untagged_queues(ahc);
6030 ahc_reset_current_bus(struct ahc_softc *ahc)
6034 ahc_outb(ahc, SIMODE1, ahc_inb(ahc, SIMODE1) & ~ENSCSIRST);
6035 scsiseq = ahc_inb(ahc, SCSISEQ);
6036 ahc_outb(ahc, SCSISEQ, scsiseq | SCSIRSTO);
6037 ahc_flush_device_writes(ahc);
6040 ahc_outb(ahc, SCSISEQ, scsiseq & ~SCSIRSTO);
6042 ahc_clear_intstat(ahc);
6045 ahc_outb(ahc, SIMODE1, ahc_inb(ahc, SIMODE1) | ENSCSIRST);
6049 ahc_reset_channel(struct ahc_softc *ahc, char channel, int initiate_reset)
6060 ahc->pending_device = NULL;
6067 ahc_pause(ahc);
6070 ahc_clear_critical_section(ahc);
6077 ahc_run_qoutfifo(ahc);
6089 if ((ahc->flags & AHC_TARGETROLE) != 0) {
6090 ahc_run_tqinfifo(ahc, /*paused*/TRUE);
6097 sblkctl = ahc_inb(ahc, SBLKCTL);
6099 if ((ahc->features & AHC_TWIN) != 0
6102 scsiseq = ahc_inb(ahc, SCSISEQ_TEMPLATE);
6108 ahc_outb(ahc, SBLKCTL, sblkctl ^ SELBUSB);
6109 simode1 = ahc_inb(ahc, SIMODE1) & ~(ENBUSFREE|ENSCSIRST);
6116 if ((ahc->flags & AHC_TARGETROLE) != 0)
6119 ahc_outb(ahc, SIMODE1, simode1);
6121 ahc_reset_current_bus(ahc);
6122 ahc_clear_intstat(ahc);
6123 ahc_outb(ahc, SCSISEQ, scsiseq & (ENSELI|ENRSELI|ENAUTOATNP));
6124 ahc_outb(ahc, SBLKCTL, sblkctl);
6128 simode1 = ahc_inb(ahc, SIMODE1) & ~(ENBUSFREE|ENSCSIRST);
6135 if ((ahc->flags & AHC_TARGETROLE) != 0)
6138 ahc_outb(ahc, SIMODE1, simode1);
6140 ahc_reset_current_bus(ahc);
6141 ahc_clear_intstat(ahc);
6142 ahc_outb(ahc, SCSISEQ, scsiseq & (ENSELI|ENRSELI|ENAUTOATNP));
6150 found = ahc_abort_scbs(ahc, CAM_TARGET_WILDCARD, channel,
6154 max_scsiid = (ahc->features & AHC_WIDE) ? 15 : 7;
6165 tstate = ahc->enabled_targets[target];
6175 ahc_queue_lstate_event(ahc, lstate, CAM_TARGET_WILDCARD,
6177 ahc_send_lstate_events(ahc, lstate);
6182 ahc_send_async(ahc, devinfo.channel, CAM_TARGET_WILDCARD,
6190 if (ahc->enabled_targets[target] == NULL)
6198 ahc_set_width(ahc, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
6200 ahc_set_syncrate(ahc, &devinfo, /*syncrate*/NULL,
6208 ahc_restart(ahc);
6210 ahc_unpause(ahc);
6220 ahc_calc_residual(struct ahc_softc *ahc, struct scb *scb)
6297 ahc_print_path(ahc, scb);
6310 ahc_queue_lstate_event(struct ahc_softc *ahc, struct ahc_tmode_lstate *lstate,
6361 ahc_send_lstate_events(struct ahc_softc *ahc, struct ahc_tmode_lstate *lstate)
6396 ahc_dumpseq(struct ahc_softc* ahc)
6400 ahc_outb(ahc, SEQCTL, PERRORDIS|FAILDIS|FASTMODE|LOADRAM);
6401 ahc_outb(ahc, SEQADDR0, 0);
6402 ahc_outb(ahc, SEQADDR1, 0);
6403 for (i = 0; i < ahc->instruction_ram_size; i++) {
6406 ahc_insb(ahc, SEQRAM, ins_bytes, 4);
6416 ahc_loadseq(struct ahc_softc *ahc)
6441 if (ahc->targetcmds != NULL)
6444 download_consts[CACHESIZE_MASK] = ahc->pci_cachesize - 1;
6445 download_consts[INVERTED_CACHESIZE_MASK] = ~(ahc->pci_cachesize - 1);
6446 sg_prefetch_cnt = ahc->pci_cachesize;
6456 ahc_outb(ahc, SEQCTL, PERRORDIS|FAILDIS|FASTMODE|LOADRAM);
6457 ahc_outb(ahc, SEQADDR0, 0);
6458 ahc_outb(ahc, SEQADDR1, 0);
6461 if (ahc_check_patch(ahc, &cur_patch, i, &skip_addr) == 0) {
6469 if (downloaded == ahc->instruction_ram_size) {
6476 "size of %d!\n", ahc_name(ahc),
6477 ahc->instruction_ram_size);
6502 ahc_download_instr(ahc, i, download_consts);
6506 ahc->num_critical_sections = cs_count;
6510 ahc->critical_sections = malloc(cs_count, M_DEVBUF, M_NOWAIT);
6511 if (ahc->critical_sections == NULL)
6513 memcpy(ahc->critical_sections, cs_table, cs_count);
6515 ahc_outb(ahc, SEQCTL, PERRORDIS|FAILDIS|FASTMODE);
6520 ahc_name(ahc), ahc->features, ahc->bugs, ahc->flags);
6526 ahc_check_patch(struct ahc_softc *ahc, struct patch **start_patch,
6539 if (cur_patch->patch_func(ahc) == 0) {
6562 ahc_download_instr(struct ahc_softc *ahc, u_int instrptr, uint8_t *dconsts)
6603 ahc_check_patch(ahc, &cur_patch, i, &skip_addr);
6629 if ((ahc->features & AHC_CMD_CHAN) == 0
6640 ahc_name(ahc));
6646 if ((ahc->features & AHC_ULTRA2) != 0) {
6678 ahc_outsb(ahc, SEQRAM, instr.bytes, 4);
6741 ahc_dump_card_state(struct ahc_softc *ahc)
6757 if (ahc_is_paused(ahc)) {
6761 ahc_pause(ahc);
6764 saved_scbptr = ahc_inb(ahc, SCBPTR);
6765 last_phase = ahc_inb(ahc, LASTPHASE);
6768 ahc_name(ahc), ahc_lookup_phase_entry(last_phase)->phasemsg,
6769 ahc_inb(ahc, SEQADDR0) | (ahc_inb(ahc, SEQADDR1) << 8));
6773 ahc_inb(ahc, ACCUM), ahc_inb(ahc, SINDEX), ahc_inb(ahc, DINDEX),
6774 ahc_inb(ahc, ARG_2));
6775 printf("HCNT = 0x%x SCBPTR = 0x%x\n", ahc_inb(ahc, HCNT),
6776 ahc_inb(ahc, SCBPTR));
6778 if ((ahc->features & AHC_DT) != 0)
6779 ahc_scsiphase_print(ahc_inb(ahc, SCSIPHASE), &cur_col, 50);
6780 ahc_scsisigi_print(ahc_inb(ahc, SCSISIGI), &cur_col, 50);
6781 ahc_error_print(ahc_inb(ahc, ERROR), &cur_col, 50);
6782 ahc_scsibusl_print(ahc_inb(ahc, SCSIBUSL), &cur_col, 50);
6783 ahc_lastphase_print(ahc_inb(ahc, LASTPHASE), &cur_col, 50);
6784 ahc_scsiseq_print(ahc_inb(ahc, SCSISEQ), &cur_col, 50);
6785 ahc_sblkctl_print(ahc_inb(ahc, SBLKCTL), &cur_col, 50);
6786 ahc_scsirate_print(ahc_inb(ahc, SCSIRATE), &cur_col, 50);
6787 ahc_seqctl_print(ahc_inb(ahc, SEQCTL), &cur_col, 50);
6788 ahc_seq_flags_print(ahc_inb(ahc, SEQ_FLAGS), &cur_col, 50);
6789 ahc_sstat0_print(ahc_inb(ahc, SSTAT0), &cur_col, 50);
6790 ahc_sstat1_print(ahc_inb(ahc, SSTAT1), &cur_col, 50);
6791 ahc_sstat2_print(ahc_inb(ahc, SSTAT2), &cur_col, 50);
6792 ahc_sstat3_print(ahc_inb(ahc, SSTAT3), &cur_col, 50);
6793 ahc_simode0_print(ahc_inb(ahc, SIMODE0), &cur_col, 50);
6794 ahc_simode1_print(ahc_inb(ahc, SIMODE1), &cur_col, 50);
6795 ahc_sxfrctl0_print(ahc_inb(ahc, SXFRCTL0), &cur_col, 50);
6796 ahc_dfcntrl_print(ahc_inb(ahc, DFCNTRL), &cur_col, 50);
6797 ahc_dfstatus_print(ahc_inb(ahc, DFSTATUS), &cur_col, 50);
6802 printf(" 0x%x", ahc_inb(ahc, STACK)|(ahc_inb(ahc, STACK) << 8));
6803 printf("\nSCB count = %d\n", ahc->scb_data->numscbs);
6804 printf("Kernel NEXTQSCB = %d\n", ahc->next_queued_scb->hscb->tag);
6805 printf("Card NEXTQSCB = %d\n", ahc_inb(ahc, NEXT_QUEUED_SCB));
6808 if ((ahc->features & AHC_QUEUE_REGS) != 0) {
6809 qinpos = ahc_inb(ahc, SNSCB_QOFF);
6810 ahc_outb(ahc, SNSCB_QOFF, qinpos);
6812 qinpos = ahc_inb(ahc, QINPOS);
6813 qintail = ahc->qinfifonext;
6815 printf("%d ", ahc->qinfifo[qinpos]);
6821 scb_index = ahc_inb(ahc, WAITING_SCBH);
6824 ahc_outb(ahc, SCBPTR, scb_index);
6825 printf("%d:%d ", scb_index, ahc_inb(ahc, SCB_TAG));
6826 scb_index = ahc_inb(ahc, SCB_NEXT);
6831 scb_index = ahc_inb(ahc, DISCONNECTED_SCBH);
6834 ahc_outb(ahc, SCBPTR, scb_index);
6835 printf("%d:%d ", scb_index, ahc_inb(ahc, SCB_TAG));
6836 scb_index = ahc_inb(ahc, SCB_NEXT);
6840 ahc_sync_qoutfifo(ahc, BUS_DMASYNC_POSTREAD);
6842 qoutpos = ahc->qoutfifonext;
6844 while (ahc->qoutfifo[qoutpos] != SCB_LIST_NULL && i++ < 256) {
6845 printf("%d ", ahc->qoutfifo[qoutpos]);
6851 scb_index = ahc_inb(ahc, FREE_SCBH);
6854 ahc_outb(ahc, SCBPTR, scb_index);
6856 scb_index = ahc_inb(ahc, SCB_NEXT);
6861 for (i = 0; i < ahc->scb_data->maxhscbs; i++) {
6862 ahc_outb(ahc, SCBPTR, i);
6865 ahc_scb_control_print(ahc_inb(ahc, SCB_CONTROL), &cur_col, 60);
6866 ahc_scb_scsiid_print(ahc_inb(ahc, SCB_SCSIID), &cur_col, 60);
6867 ahc_scb_lun_print(ahc_inb(ahc, SCB_LUN), &cur_col, 60);
6868 ahc_scb_tag_print(ahc_inb(ahc, SCB_TAG), &cur_col, 60);
6874 LIST_FOREACH(scb, &ahc->pending_scbs, pending_links) {
6881 if ((ahc->flags & AHC_PAGESCBS) == 0) {
6882 ahc_outb(ahc, SCBPTR, scb->hscb->tag);
6884 ahc_scb_control_print(ahc_inb(ahc, SCB_CONTROL),
6886 ahc_scb_tag_print(ahc_inb(ahc, SCB_TAG), &cur_col, 60);
6894 SLIST_FOREACH(scb, &ahc->scb_data->free_scbs, links.sle) {
6901 maxtarget = (ahc->features & (AHC_WIDE|AHC_TWIN)) ? 15 : 7;
6903 untagged_q = &ahc->untagged_queues[target];
6916 ahc_platform_dump_card_state(ahc);
6918 ahc_outb(ahc, SCBPTR, saved_scbptr);
6920 ahc_unpause(ahc);
6927 struct ahc_softc *ahc;
6929 ahc = scb->ahc_softc;
6932 LIST_INSERT_HEAD(&ahc->timedout_scbs, scb,
6936 ahc_wakeup_recovery_thread(ahc);
6947 ahc_other_scb_timeout(struct ahc_softc *ahc, struct scb *scb,
6953 ahc_print_path(ahc, scb);
6970 LIST_FOREACH(other_scb, &ahc->pending_scbs, pending_links) {
6985 ahc_print_path(ahc, scb);
7000 ahc_recover_commands(struct ahc_softc *ahc)
7012 ahc_pause_and_flushwork(ahc);
7014 if (LIST_EMPTY(&ahc->timedout_scbs) != 0) {
7024 "Interrupts may not be functioning.\n", ahc_name(ahc));
7025 ahc_unpause(ahc);
7030 printf("%s: Recovery Initiated\n", ahc_name(ahc));
7031 ahc_dump_card_state(ahc);
7033 last_phase = ahc_inb(ahc, LASTPHASE);
7034 while ((scb = LIST_FIRST(&ahc->timedout_scbs)) != NULL) {
7042 target = SCB_GET_TARGET(ahc, scb);
7043 channel = SCB_GET_CHANNEL(ahc, scb);
7046 ahc_print_path(ahc, scb);
7063 found = ahc_reset_channel(ahc, channel,
7066 "%d SCBs aborted\n", ahc_name(ahc), channel,
7100 saved_scbptr = ahc_inb(ahc, SCBPTR);
7101 active_scb_index = ahc_inb(ahc, SCB_TAG);
7103 if ((ahc_inb(ahc, SEQ_FLAGS) & NOT_IDENTIFIED) == 0
7104 && (active_scb_index < ahc->scb_data->numscbs)) {
7113 active_scb = ahc_lookup_scb(ahc, active_scb_index);
7115 if (ahc_other_scb_timeout(ahc, scb,
7128 ahc_abort_scbs(ahc, SCB_GET_TARGET(ahc, scb),
7129 SCB_GET_CHANNEL(ahc, scb),
7140 ahc_set_recoveryscb(ahc, active_scb);
7141 ahc_outb(ahc, MSG_OUT, HOST_MSG);
7142 ahc_outb(ahc, SCSISIGO, last_phase|ATNO);
7143 ahc_print_path(ahc, active_scb);
7148 && (ahc_inb(ahc, SSTAT1) & REQINIT) == 0) {
7157 "Identify Msg.\n", ahc_name(ahc));
7163 && (ahc_inb(ahc, SSTAT0) & TARGET) != 0) {
7166 ahc_name(ahc));
7175 if (ahc_search_qinfifo(ahc, target, channel, lun,
7185 ahc_set_recoveryscb(ahc, scb);
7212 ahc_search_disc_list(ahc, target, channel,
7225 if ((ahc->flags & AHC_PAGESCBS) == 0) {
7226 ahc_outb(ahc, SCBPTR, scb->hscb->tag);
7227 ahc_outb(ahc, SCB_CONTROL,
7228 ahc_inb(ahc, SCB_CONTROL)
7237 ahc_search_qinfifo(ahc,
7238 SCB_GET_TARGET(ahc, scb),
7244 ahc_print_path(ahc, scb);
7246 ahc_qinfifo_requeue_tail(ahc, scb);
7247 ahc_outb(ahc, SCBPTR, saved_scbptr);
7252 ahc_set_recoveryscb(ahc, scb);
7253 ahc_print_path(ahc, scb);
7268 while ((scb = LIST_FIRST(&ahc->timedout_scbs)) != NULL) {
7275 ahc_restart(ahc);
7277 ahc_unpause(ahc);
7283 ahc_find_tmode_devs(struct ahc_softc *ahc, struct cam_sim *sim, union ccb *ccb,
7289 if ((ahc->features & AHC_TARGETMODE) == 0)
7299 *lstate = ahc->black_hole;
7303 max_id = (ahc->features & AHC_WIDE) ? 15 : 7;
7310 *tstate = ahc->enabled_targets[ccb->ccb_h.target_id];
7324 ahc_handle_en_lun(struct ahc_softc *ahc, struct cam_sim *sim, union ccb *ccb)
7337 status = ahc_find_tmode_devs(ahc, sim, ccb, &tstate, &lstate,
7346 our_id = ahc->our_id;
7348 our_id = ahc->our_id_b;
7370 if ((ahc->features & AHC_MULTIROLE) != 0) {
7372 if ((ahc->features & AHC_MULTI_TID) != 0
7373 && (ahc->flags & AHC_INITIATORROLE) != 0) {
7382 } else if ((ahc->flags & AHC_INITIATORROLE) != 0
7383 || ahc->enabled_luns > 0) {
7393 } else if ((ahc->features & AHC_MULTI_TID) == 0
7394 && ahc->enabled_luns > 0) {
7409 if ((ahc->flags & AHC_TARGETROLE) == 0
7414 if (LIST_FIRST(&ahc->pending_scbs) != NULL) {
7418 saved_flags = ahc->flags;
7419 ahc->flags |= AHC_TARGETROLE;
7420 if ((ahc->features & AHC_MULTIROLE) == 0)
7421 ahc->flags &= ~AHC_INITIATORROLE;
7422 ahc_pause(ahc);
7423 error = ahc_loadseq(ahc);
7433 ahc->flags = saved_flags;
7434 (void)ahc_loadseq(ahc);
7435 ahc_restart(ahc);
7439 ahc_restart(ahc);
7444 channel = SIM_CHANNEL(ahc, sim);
7476 tstate = ahc_alloc_tstate(ahc, target, channel);
7505 ahc_pause(ahc);
7508 ahc->enabled_luns++;
7510 if ((ahc->features & AHC_MULTI_TID) != 0) {
7513 targid_mask = ahc_inb(ahc, TARGID)
7514 | (ahc_inb(ahc, TARGID + 1) << 8);
7517 ahc_outb(ahc, TARGID, targid_mask);
7518 ahc_outb(ahc, TARGID+1, (targid_mask >> 8));
7520 ahc_update_scsiid(ahc, targid_mask);
7525 channel = SIM_CHANNEL(ahc, sim);
7526 our_id = SIM_SCSI_ID(ahc, sim);
7537 sblkctl = ahc_inb(ahc, SBLKCTL);
7540 if ((ahc->features & AHC_TWIN) == 0)
7544 ahc->our_id = target;
7546 ahc->our_id_b = target;
7549 ahc_outb(ahc, SBLKCTL,
7552 ahc_outb(ahc, SCSIID, target);
7555 ahc_outb(ahc, SBLKCTL, sblkctl);
7559 ahc->black_hole = lstate;
7561 if (ahc->black_hole != NULL && ahc->enabled_luns > 0) {
7562 scsiseq = ahc_inb(ahc, SCSISEQ_TEMPLATE);
7564 ahc_outb(ahc, SCSISEQ_TEMPLATE, scsiseq);
7565 scsiseq = ahc_inb(ahc, SCSISEQ);
7567 ahc_outb(ahc, SCSISEQ, scsiseq);
7569 ahc_unpause(ahc);
7583 LIST_FOREACH(scb, &ahc->pending_scbs, pending_links) {
7614 ahc_pause(ahc);
7618 ahc->enabled_luns--;
7626 ahc_free_tstate(ahc, target, channel,
7628 if (ahc->features & AHC_MULTI_TID) {
7631 targid_mask = ahc_inb(ahc, TARGID)
7632 | (ahc_inb(ahc, TARGID + 1)
7636 ahc_outb(ahc, TARGID, targid_mask);
7637 ahc_outb(ahc, TARGID+1,
7639 ahc_update_scsiid(ahc, targid_mask);
7644 ahc->black_hole = NULL;
7652 if (ahc->enabled_luns == 0) {
7656 scsiseq = ahc_inb(ahc, SCSISEQ_TEMPLATE);
7658 ahc_outb(ahc, SCSISEQ_TEMPLATE, scsiseq);
7659 scsiseq = ahc_inb(ahc, SCSISEQ);
7661 ahc_outb(ahc, SCSISEQ, scsiseq);
7663 if ((ahc->features & AHC_MULTIROLE) == 0) {
7665 ahc->flags &= ~AHC_TARGETROLE;
7666 ahc->flags |= AHC_INITIATORROLE;
7671 (void)ahc_loadseq(ahc);
7672 ahc_restart(ahc);
7679 ahc_unpause(ahc);
7684 ahc_update_scsiid(struct ahc_softc *ahc, u_int targid_mask)
7689 if ((ahc->features & AHC_MULTI_TID) == 0)
7698 if ((ahc->features & AHC_ULTRA2) != 0)
7699 scsiid = ahc_inb(ahc, SCSIID_ULTRA2);
7701 scsiid = ahc_inb(ahc, SCSIID);
7709 our_id = ahc->our_id;
7715 if ((ahc->features & AHC_ULTRA2) != 0)
7716 ahc_outb(ahc, SCSIID_ULTRA2, scsiid);
7718 ahc_outb(ahc, SCSIID, scsiid);
7722 ahc_run_tqinfifo(struct ahc_softc *ahc, int paused)
7731 if ((ahc->features & AHC_AUTOPAUSE) != 0)
7734 ahc_sync_tqinfifo(ahc, BUS_DMASYNC_POSTREAD);
7735 while ((cmd = &ahc->targetcmds[ahc->tqinfifonext])->cmd_valid != 0) {
7741 if (ahc_handle_target_cmd(ahc, cmd) != 0)
7745 aic_dmamap_sync(ahc, ahc->shared_data_dmat,
7746 ahc->shared_data_dmamap,
7747 ahc_targetcmd_offset(ahc, ahc->tqinfifonext),
7750 ahc->tqinfifonext++;
7756 if ((ahc->tqinfifonext & (HOST_TQINPOS - 1)) == 1) {
7757 if ((ahc->features & AHC_HS_MAILBOX) != 0) {
7760 hs_mailbox = ahc_inb(ahc, HS_MAILBOX);
7762 hs_mailbox |= ahc->tqinfifonext & HOST_TQINPOS;
7763 ahc_outb(ahc, HS_MAILBOX, hs_mailbox);
7766 ahc_pause(ahc);
7767 ahc_outb(ahc, KERNEL_TQINPOS,
7768 ahc->tqinfifonext & HOST_TQINPOS);
7770 ahc_unpause(ahc);
7777 ahc_handle_target_cmd(struct ahc_softc *ahc, struct target_cmd *cmd)
7787 initiator = SCSIID_TARGET(ahc, cmd->scsiid);
7792 tstate = ahc->enabled_targets[target];
7801 lstate = ahc->black_hole;
7805 ahc->flags |= AHC_TQINFIFO_BLOCKED;
7810 printf("%s: ATIOs exhausted\n", ahc_name(ahc));
7813 ahc->flags &= ~AHC_TQINFIFO_BLOCKED;
7818 lstate == ahc->black_hole ? "(Black Holed)" : "");
7823 if (lstate == ahc->black_hole) {
7882 initiator, target, lun, ahc->pending_device);
7885 ahc->pending_device = lstate;