Lines Matching defs:ahc

147 static void		ahc_force_renegotiation(struct ahc_softc *ahc,
150 ahc_alloc_tstate(struct ahc_softc *ahc,
153 static void ahc_free_tstate(struct ahc_softc *ahc,
157 ahc_devlimited_syncrate(struct ahc_softc *ahc,
162 static void ahc_update_pending_scbs(struct ahc_softc *ahc);
163 static void ahc_fetch_devinfo(struct ahc_softc *ahc,
165 static void ahc_scb_devinfo(struct ahc_softc *ahc,
168 static void ahc_assert_atn(struct ahc_softc *ahc);
169 static void ahc_setup_initiator_msgout(struct ahc_softc *ahc,
172 static void ahc_build_transfer_msg(struct ahc_softc *ahc,
174 static void ahc_construct_sdtr(struct ahc_softc *ahc,
177 static void ahc_construct_wdtr(struct ahc_softc *ahc,
180 static void ahc_construct_ppr(struct ahc_softc *ahc,
184 static void ahc_clear_msg_state(struct ahc_softc *ahc);
185 static void ahc_handle_proto_violation(struct ahc_softc *ahc);
186 static void ahc_handle_message_phase(struct ahc_softc *ahc);
192 static int ahc_sent_msg(struct ahc_softc *ahc, ahc_msgtype type,
194 static int ahc_parse_msg(struct ahc_softc *ahc,
196 static int ahc_handle_msg_reject(struct ahc_softc *ahc,
198 static void ahc_handle_ign_wide_residue(struct ahc_softc *ahc,
200 static void ahc_reinitialize_dataptrs(struct ahc_softc *ahc);
201 static void ahc_handle_devreset(struct ahc_softc *ahc,
206 static void ahc_setup_target_msgin(struct ahc_softc *ahc,
212 static void ahc_build_free_scb_list(struct ahc_softc *ahc);
213 static int ahc_init_scbdata(struct ahc_softc *ahc);
214 static void ahc_fini_scbdata(struct ahc_softc *ahc);
215 static void ahc_qinfifo_requeue(struct ahc_softc *ahc,
218 static int ahc_qinfifo_count(struct ahc_softc *ahc);
219 static u_int ahc_rem_scb_from_disc_list(struct ahc_softc *ahc,
221 static void ahc_add_curscb_to_free_list(struct ahc_softc *ahc);
222 static u_int ahc_rem_wscb(struct ahc_softc *ahc,
224 static void ahc_reset_current_bus(struct ahc_softc *ahc);
226 static void ahc_dumpseq(struct ahc_softc *ahc);
228 static int ahc_loadseq(struct ahc_softc *ahc);
229 static int ahc_check_patch(struct ahc_softc *ahc,
232 static void ahc_download_instr(struct ahc_softc *ahc,
234 static int ahc_other_scb_timeout(struct ahc_softc *ahc,
238 static void ahc_queue_lstate_event(struct ahc_softc *ahc,
243 static void ahc_update_scsiid(struct ahc_softc *ahc,
245 static int ahc_handle_target_cmd(struct ahc_softc *ahc,
253 ahc_restart(struct ahc_softc *ahc)
256 ahc_pause(ahc);
259 ahc_clear_msg_state(ahc);
261 ahc_outb(ahc, SCSISIGO, 0); /* De-assert BSY */
262 ahc_outb(ahc, MSG_OUT, MSG_NOOP); /* No message to send */
263 ahc_outb(ahc, SXFRCTL1, ahc_inb(ahc, SXFRCTL1) & ~BITBUCKET);
264 ahc_outb(ahc, LASTPHASE, P_BUSFREE);
265 ahc_outb(ahc, SAVED_SCSIID, 0xFF);
266 ahc_outb(ahc, SAVED_LUN, 0xFF);
275 ahc_outb(ahc, TQINPOS, ahc->tqinfifonext);
278 ahc_outb(ahc, SCSISEQ,
279 ahc_inb(ahc, SCSISEQ_TEMPLATE) & (ENSELI|ENRSELI|ENAUTOATNP));
280 if ((ahc->features & AHC_CMD_CHAN) != 0) {
282 ahc_outb(ahc, CCSCBCNT, 0);
283 ahc_outb(ahc, CCSGCTL, 0);
284 ahc_outb(ahc, CCSCBCTL, 0);
291 if ((ahc_inb(ahc, SEQ_FLAGS2) & SCB_DMA) != 0) {
292 ahc_add_curscb_to_free_list(ahc);
293 ahc_outb(ahc, SEQ_FLAGS2,
294 ahc_inb(ahc, SEQ_FLAGS2) & ~SCB_DMA);
302 ahc_outb(ahc, CLRINT, CLRSEQINT);
304 ahc_outb(ahc, MWI_RESIDUAL, 0);
305 ahc_outb(ahc, SEQCTL, ahc->seqctl);
306 ahc_outb(ahc, SEQADDR0, 0);
307 ahc_outb(ahc, SEQADDR1, 0);
309 ahc_unpause(ahc);
314 ahc_run_qoutfifo(struct ahc_softc *ahc)
319 ahc_sync_qoutfifo(ahc, BUS_DMASYNC_POSTREAD);
320 while (ahc->qoutfifo[ahc->qoutfifonext] != SCB_LIST_NULL) {
322 scb_index = ahc->qoutfifo[ahc->qoutfifonext];
323 if ((ahc->qoutfifonext & 0x03) == 0x03) {
333 modnext = ahc->qoutfifonext & ~0x3;
334 *((uint32_t *)(&ahc->qoutfifo[modnext])) = 0xFFFFFFFFUL;
335 aic_dmamap_sync(ahc, ahc->shared_data_dmat,
336 ahc->shared_data_dmamap,
340 ahc->qoutfifonext++;
342 scb = ahc_lookup_scb(ahc, scb_index);
346 ahc_name(ahc), scb_index,
347 (ahc->qoutfifonext - 1) & 0xFF);
355 ahc_update_residual(ahc, scb);
356 ahc_done(ahc, scb);
361 ahc_run_untagged_queues(struct ahc_softc *ahc)
366 ahc_run_untagged_queue(ahc, &ahc->untagged_queues[i]);
370 ahc_run_untagged_queue(struct ahc_softc *ahc, struct scb_tailq *queue)
374 if (ahc->untagged_queue_lock != 0)
384 ahc_queue_scb(ahc, scb);
390 ahc_handle_brkadrint(struct ahc_softc *ahc)
399 error = ahc_inb(ahc, ERROR);
403 ahc_name(ahc), ahc_hard_errors[i].errmesg,
404 ahc_inb(ahc, SEQADDR0) |
405 (ahc_inb(ahc, SEQADDR1) << 8));
407 ahc_dump_card_state(ahc);
410 ahc_abort_scbs(ahc, CAM_TARGET_WILDCARD, ALL_CHANNELS,
415 ahc_shutdown(ahc);
419 ahc_handle_seqint(struct ahc_softc *ahc, u_int intstat)
424 ahc_fetch_devinfo(ahc, &devinfo);
432 ahc_outb(ahc, CLRINT, CLRSEQINT);
444 ahc_outb(ahc, RETURN_1, 0);
455 scb_index = ahc_inb(ahc, SCB_TAG);
456 scb = ahc_lookup_scb(ahc, scb_index);
458 ahc_print_devinfo(ahc, &devinfo);
462 ahc_dump_card_state(ahc);
482 ahc_freeze_devq(ahc, scb);
488 ahc_name(ahc));
500 ahc_print_path(ahc, scb);
509 targ_info = ahc_fetch_transinfo(ahc,
520 ahc_update_residual(ahc, scb);
523 ahc_print_path(ahc, scb);
527 sg->addr = ahc_get_sense_bufaddr(ahc, scb);
528 sg->len = aic_get_sense_bufsize(ahc, scb);
564 ahc_update_neg_request(ahc, &devinfo,
580 ahc_qinfifo_requeue_tail(ahc, scb);
581 ahc_outb(ahc, RETURN_1, SEND_SENSE);
589 if (ahc->scb_data->recovery_scbs == 0
602 ahc_outb(ahc, SCSISEQ,
603 ahc_inb(ahc, SCSISEQ) & (ENSELI|ENRSELI|ENAUTOATNP));
607 ahc_name(ahc), devinfo.channel, devinfo.target);
610 ahc_inb(ahc, SAVED_SCSIID), ahc_inb(ahc, SAVED_LUN),
611 ahc_inb(ahc, ARG_1), ahc_inb(ahc, ACCUM));
614 ahc_inb(ahc, SEQ_FLAGS), ahc_inb(ahc, SCBPTR),
615 ahc_index_busy_tcl(ahc,
616 BUILD_TCL(ahc_inb(ahc, SAVED_SCSIID),
617 ahc_inb(ahc, SAVED_LUN))),
618 ahc_inb(ahc, SINDEX));
621 ahc_inb(ahc, SCSIID), ahc_inb(ahc, SCB_SCSIID),
622 ahc_inb(ahc, SCB_LUN), ahc_inb(ahc, SCB_TAG),
623 ahc_inb(ahc, SCB_CONTROL));
625 ahc_inb(ahc, SCSIBUSL), ahc_inb(ahc, SCSISIGI));
626 printf("SXFRCTL0 == 0x%x\n", ahc_inb(ahc, SXFRCTL0));
627 printf("SEQCTL == 0x%x\n", ahc_inb(ahc, SEQCTL));
628 ahc_dump_card_state(ahc);
629 ahc->msgout_buf[0] = MSG_BUS_DEV_RESET;
630 ahc->msgout_len = 1;
631 ahc->msgout_index = 0;
632 ahc->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
633 ahc_outb(ahc, MSG_OUT, HOST_MSG);
634 ahc_assert_atn(ahc);
639 u_int rejbyte = ahc_inb(ahc, ACCUM);
642 ahc_name(ahc), devinfo.channel, devinfo.target, rejbyte);
647 ahc_handle_proto_violation(ahc);
651 ahc_handle_ign_wide_residue(ahc, &devinfo);
654 ahc_reinitialize_dataptrs(ahc);
660 lastphase = ahc_inb(ahc, LASTPHASE);
663 ahc_name(ahc), devinfo.channel, devinfo.target,
664 lastphase, ahc_inb(ahc, SCSISIGI));
671 lastphase = ahc_inb(ahc, LASTPHASE);
674 ahc_name(ahc), devinfo.channel, devinfo.target,
675 lastphase, ahc_inb(ahc, SCSISIGI));
676 ahc_restart(ahc);
692 if (ahc->msg_type == MSG_TYPE_NONE) {
697 bus_phase = ahc_inb(ahc, SCSISIGI) & PHASE_MASK;
707 ahc_clear_intstat(ahc);
708 ahc_restart(ahc);
712 scb_index = ahc_inb(ahc, SCB_TAG);
713 scb = ahc_lookup_scb(ahc, scb_index);
720 ahc_setup_initiator_msgout(ahc,
724 ahc->msg_type =
726 ahc->msgin_index = 0;
732 ahc->msg_type =
734 ahc->msgin_index = 0;
737 ahc_setup_target_msgin(ahc,
744 ahc_handle_message_phase(ahc);
761 && (ahc_inb(ahc, SSTAT1) & SCSIPERR) != 0) {
763 if ((ahc->features & AHC_DT) == 0) {
772 curphase = ahc_inb(ahc, SCSISIGI) & PHASE_MASK;
773 ahc_outb(ahc, LASTPHASE, curphase);
774 ahc_outb(ahc, SCSISIGO, curphase);
776 if ((ahc_inb(ahc, SCSISIGI) & (CDI|MSGI)) == 0) {
785 ahc_outb(ahc, SXFRCTL1,
786 ahc_inb(ahc, SXFRCTL1) | BITBUCKET);
789 if ((ahc_inb(ahc, SCSISIGI)
794 ahc_outb(ahc, SXFRCTL1,
795 ahc_inb(ahc, SXFRCTL1) & ~BITBUCKET);
800 ahc_print_devinfo(ahc, &devinfo);
803 scb_index = ahc_inb(ahc, SCB_TAG);
804 scb = ahc_lookup_scb(ahc, scb_index);
808 ahc_reset_channel(ahc, devinfo.channel,
812 ahc_inb(ahc, SCSIDATL);
827 u_int scbindex = ahc_inb(ahc, SCB_TAG);
828 u_int lastphase = ahc_inb(ahc, LASTPHASE);
831 scb = ahc_lookup_scb(ahc, scbindex);
836 ahc_print_path(ahc, scb);
841 ahc_print_path(ahc, scb);
843 ahc_inb(ahc, SEQ_FLAGS) & DPHASE ? "Have" : "Haven't",
861 ahc_freeze_devq(ahc, scb);
870 if ((ahc->features & AHC_ULTRA2) != 0) {
875 ahc_outb(ahc, SXFRCTL0,
876 ahc_inb(ahc, SXFRCTL0) | CLRSTCNT|CLRCHN);
877 ahc_outb(ahc, SXFRCTL0,
878 ahc_inb(ahc, SXFRCTL0) | CLRSTCNT|CLRCHN);
880 if ((ahc->flags & AHC_39BIT_ADDRESSING) != 0) {
884 dscommand1 = ahc_inb(ahc, DSCOMMAND1);
885 ahc_outb(ahc, DSCOMMAND1, dscommand1 | HADDLDSEL0);
886 ahc_outb(ahc, HADDR, 0);
887 ahc_outb(ahc, DSCOMMAND1, dscommand1);
896 ahc_name(ahc), devinfo.channel, devinfo.target,
898 scbindex = ahc_inb(ahc, SCB_TAG);
899 scb = ahc_lookup_scb(ahc, scbindex);
906 ahc_search_qinfifo(ahc, SCB_GET_TARGET(ahc, scb),
907 SCB_GET_CHANNEL(ahc, scb),
915 printf("%s: No free or disconnected SCBs\n", ahc_name(ahc));
916 ahc_dump_card_state(ahc);
924 scbptr = ahc_inb(ahc, SCBPTR);
926 scbptr, ahc_inb(ahc, ARG_1),
927 ahc->scb_data->hscbs[scbptr].tag);
928 ahc_dump_card_state(ahc);
934 printf("%s: BTT calculation out of range\n", ahc_name(ahc));
937 ahc_inb(ahc, SAVED_SCSIID), ahc_inb(ahc, SAVED_LUN),
938 ahc_inb(ahc, ARG_1), ahc_inb(ahc, ACCUM));
941 ahc_inb(ahc, SEQ_FLAGS), ahc_inb(ahc, SCBPTR),
942 ahc_index_busy_tcl(ahc,
943 BUILD_TCL(ahc_inb(ahc, SAVED_SCSIID),
944 ahc_inb(ahc, SAVED_LUN))),
945 ahc_inb(ahc, SINDEX),
946 ahc_inb(ahc, ACCUM));
949 ahc_inb(ahc, SCSIID), ahc_inb(ahc, SCB_SCSIID),
950 ahc_inb(ahc, SCB_LUN), ahc_inb(ahc, SCB_TAG),
951 ahc_inb(ahc, SCB_CONTROL));
953 ahc_inb(ahc, SCSIBUSL), ahc_inb(ahc, SCSISIGI));
954 ahc_dump_card_state(ahc);
961 intstat, ahc_inb(ahc, SCSISIGI));
970 ahc_unpause(ahc);
974 ahc_handle_scsiint(struct ahc_softc *ahc, u_int intstat)
983 if ((ahc->features & AHC_TWIN) != 0
984 && ((ahc_inb(ahc, SBLKCTL) & SELBUSB) != 0))
990 if ((ahc->features & AHC_ULTRA2) != 0)
991 status0 = ahc_inb(ahc, SSTAT0) & IOERR;
994 status = ahc_inb(ahc, SSTAT1) & (SELTO|SCSIRSTI|BUSFREE|SCSIPERR);
996 if ((ahc->features & AHC_TWIN) != 0) {
998 ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) ^ SELBUSB);
999 status = ahc_inb(ahc, SSTAT1)
1004 printf("%s: Spurious SCSI interrupt\n", ahc_name(ahc));
1005 ahc_outb(ahc, CLRINT, CLRSCSIINT);
1006 ahc_unpause(ahc);
1012 ahc_clear_critical_section(ahc);
1014 scb_index = ahc_inb(ahc, SCB_TAG);
1015 scb = ahc_lookup_scb(ahc, scb_index);
1017 && (ahc_inb(ahc, SEQ_FLAGS) & NOT_IDENTIFIED) != 0)
1020 if ((ahc->features & AHC_ULTRA2) != 0
1024 now_lvd = ahc_inb(ahc, SBLKCTL) & ENAB40;
1026 ahc_name(ahc), now_lvd ? "LVD" : "SE");
1027 ahc_outb(ahc, CLRSINT0, CLRIOERR);
1038 ahc_reset_channel(ahc, intr_channel,
1042 ahc_name(ahc), intr_channel);
1044 ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) ^ SELBUSB);
1045 ahc_reset_channel(ahc, intr_channel, /*Initiate Reset*/FALSE);
1067 lastphase = ahc_inb(ahc, LASTPHASE);
1068 curphase = ahc_inb(ahc, SCSISIGI) & PHASE_MASK;
1069 sstat2 = ahc_inb(ahc, SSTAT2);
1070 ahc_outb(ahc, CLRSINT1, CLRSCSIPERR);
1082 if ((ahc_inb(ahc, SSTAT1) & SCSIPERR) != 0
1098 ahc_print_path(ahc, scb);
1101 printf("%s:%c:%d: ", ahc_name(ahc), intr_channel,
1102 SCSIID_TARGET(ahc, ahc_inb(ahc, SAVED_SCSIID)));
1103 scsirate = ahc_inb(ahc, SCSIRATE);
1108 ahc_inw(ahc, SEQADDR0),
1110 if ((ahc->features & AHC_DT) != 0) {
1126 if ((ahc->features & AHC_DT) != 0
1144 if (ahc->msg_type != MSG_TYPE_NONE)
1145 ahc->send_msg_perror = TRUE;
1147 ahc_outb(ahc, MSG_OUT, mesg_out);
1154 ahc_fetch_devinfo(ahc, &devinfo);
1155 ahc_force_renegotiation(ahc, &devinfo);
1157 ahc_outb(ahc, CLRINT, CLRSCSIINT);
1158 ahc_unpause(ahc);
1163 ahc_outb(ahc, SCSISEQ, 0);
1166 ahc_clear_msg_state(ahc);
1169 ahc_outb(ahc, SIMODE1, ahc_inb(ahc, SIMODE1) & ~ENBUSFREE);
1170 ahc_outb(ahc, CLRSINT1, CLRSELTIMEO|CLRBUSFREE|CLRSCSIPERR);
1180 ahc_outb(ahc, CLRSINT0, CLRSELINGO);
1182 scbptr = ahc_inb(ahc, WAITING_SCBH);
1183 ahc_outb(ahc, SCBPTR, scbptr);
1184 scb_index = ahc_inb(ahc, SCB_TAG);
1186 scb = ahc_lookup_scb(ahc, scb_index);
1190 ahc_name(ahc), scbptr, scb_index);
1191 ahc_dump_card_state(ahc);
1196 ahc_print_path(ahc, scb);
1201 ahc_scb_devinfo(ahc, &devinfo, scb);
1203 ahc_freeze_devq(ahc, scb);
1211 ahc_handle_devreset(ahc, &devinfo,
1216 ahc_outb(ahc, CLRINT, CLRSCSIINT);
1217 ahc_restart(ahc);
1219 && (ahc_inb(ahc, SIMODE1) & ENBUSFREE) != 0) {
1235 ahc_outb(ahc, SCSISEQ,
1236 ahc_inb(ahc, SCSISEQ) & (ENSELI|ENRSELI|ENAUTOATNP));
1244 ahc_outb(ahc, SIMODE1, ahc_inb(ahc, SIMODE1) & ~ENBUSFREE);
1245 ahc_outb(ahc, CLRSINT1, CLRBUSFREE|CLRSCSIPERR);
1253 lastphase = ahc_inb(ahc, LASTPHASE);
1254 saved_scsiid = ahc_inb(ahc, SAVED_SCSIID);
1255 saved_lun = ahc_inb(ahc, SAVED_LUN);
1256 target = SCSIID_TARGET(ahc, saved_scsiid);
1258 channel = SCSIID_CHANNEL(ahc, saved_scsiid);
1267 if (ahc_sent_msg(ahc, AHCMSG_1B, MSG_ABORT_TAG, TRUE)
1268 || ahc_sent_msg(ahc, AHCMSG_1B, MSG_ABORT, TRUE)) {
1269 if (ahc->msgout_buf[ahc->msgout_index - 1]
1272 ahc_print_path(ahc, scb);
1276 ahc_abort_scbs(ahc, target, channel,
1281 } else if (ahc_sent_msg(ahc, AHCMSG_1B,
1291 && ahc_match_scb(ahc, scb, target, channel,
1304 ahc_handle_devreset(ahc, &devinfo,
1309 } else if (ahc_sent_msg(ahc, AHCMSG_EXT,
1318 tinfo = ahc_fetch_transinfo(ahc,
1326 ahc_qinfifo_requeue_tail(ahc, scb);
1328 } else if (ahc_sent_msg(ahc, AHCMSG_EXT,
1334 ahc_set_width(ahc, &devinfo,
1338 ahc_qinfifo_requeue_tail(ahc, scb);
1340 } else if (ahc_sent_msg(ahc, AHCMSG_EXT,
1346 ahc_set_syncrate(ahc, &devinfo,
1352 ahc_qinfifo_requeue_tail(ahc, scb);
1366 ahc_print_path(ahc, scb);
1367 ahc_abort_scbs(ahc, target, channel,
1376 printf("%s: ", ahc_name(ahc));
1389 ahc_force_renegotiation(ahc, &devinfo);
1394 ahc_inb(ahc, SEQADDR0)
1395 | (ahc_inb(ahc, SEQADDR1) << 8));
1397 ahc_outb(ahc, CLRINT, CLRSCSIINT);
1398 ahc_restart(ahc);
1401 ahc_name(ahc), status);
1402 ahc_outb(ahc, CLRINT, CLRSCSIINT);
1411 ahc_force_renegotiation(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
1416 targ_info = ahc_fetch_transinfo(ahc,
1421 ahc_update_neg_request(ahc, devinfo, tstate,
1427 ahc_clear_critical_section(struct ahc_softc *ahc)
1434 if (ahc->num_critical_sections == 0)
1446 seqaddr = ahc_inb(ahc, SEQADDR0)
1447 | (ahc_inb(ahc, SEQADDR1) << 8);
1454 cs = ahc->critical_sections;
1455 for (i = 0; i < ahc->num_critical_sections; i++, cs++) {
1461 if (i == ahc->num_critical_sections)
1466 ahc_name(ahc));
1467 ahc_dump_card_state(ahc);
1480 simode0 = ahc_inb(ahc, SIMODE0);
1481 ahc_outb(ahc, SIMODE0, 0);
1482 simode1 = ahc_inb(ahc, SIMODE1);
1483 if ((ahc->features & AHC_DT) != 0)
1492 ahc_outb(ahc, SIMODE1, simode1 & ENBUSFREE);
1494 ahc_outb(ahc, SIMODE1, 0);
1495 ahc_outb(ahc, CLRINT, CLRSCSIINT);
1496 ahc_outb(ahc, SEQCTL, ahc->seqctl | STEP);
1499 if ((ahc->features & AHC_DT) != 0) {
1500 ahc_outb(ahc, CLRSINT1, CLRBUSFREE);
1501 ahc_outb(ahc, CLRINT, CLRSCSIINT);
1503 ahc_outb(ahc, HCNTRL, ahc->unpause);
1504 while (!ahc_is_paused(ahc))
1508 ahc_outb(ahc, SIMODE0, simode0);
1509 ahc_outb(ahc, SIMODE1, simode1);
1510 ahc_outb(ahc, SEQCTL, ahc->seqctl);
1518 ahc_clear_intstat(struct ahc_softc *ahc)
1521 ahc_outb(ahc, CLRSINT1, CLRSELTIMEO|CLRATNO|CLRSCSIRSTI
1524 ahc_flush_device_writes(ahc);
1525 ahc_outb(ahc, CLRSINT0, CLRSELDO|CLRSELDI|CLRSELINGO);
1526 ahc_flush_device_writes(ahc);
1527 ahc_outb(ahc, CLRINT, CLRSCSIINT);
1528 ahc_flush_device_writes(ahc);
1575 ahc_alloc_tstate(struct ahc_softc *ahc, u_int scsi_id, char channel)
1581 master_tstate = ahc->enabled_targets[ahc->our_id];
1584 master_tstate = ahc->enabled_targets[ahc->our_id_b + 8];
1586 if (ahc->enabled_targets[scsi_id] != NULL
1587 && ahc->enabled_targets[scsi_id] != master_tstate)
1589 ahc_name(ahc));
1613 ahc->enabled_targets[scsi_id] = tstate;
1623 ahc_free_tstate(struct ahc_softc *ahc, u_int scsi_id, char channel, int force)
1631 if (((channel == 'B' && scsi_id == ahc->our_id_b)
1632 || (channel == 'A' && scsi_id == ahc->our_id))
1638 tstate = ahc->enabled_targets[scsi_id];
1641 ahc->enabled_targets[scsi_id] = NULL;
1652 ahc_devlimited_syncrate(struct ahc_softc *ahc,
1659 if ((ahc->features & AHC_ULTRA2) != 0) {
1660 if ((ahc_inb(ahc, SBLKCTL) & ENAB40) != 0
1661 && (ahc_inb(ahc, SSTAT2) & EXP_ACTIVE) == 0) {
1668 } else if ((ahc->features & AHC_ULTRA) != 0) {
1698 return (ahc_find_syncrate(ahc, period, ppr_options, maxsync));
1707 ahc_find_syncrate(struct ahc_softc *ahc, u_int *period,
1712 if ((ahc->features & AHC_DT) == 0)
1728 if ((ahc->features & AHC_ULTRA2) != 0
1759 || ((ahc->features & AHC_ULTRA2) != 0
1774 ahc_find_period(struct ahc_softc *ahc, u_int scsirate, u_int maxsync)
1778 if ((ahc->features & AHC_ULTRA2) != 0)
1786 if ((ahc->features & AHC_ULTRA2) != 0) {
1804 ahc_validate_offset(struct ahc_softc *ahc,
1814 } else if ((ahc->features & AHC_ULTRA2) != 0) {
1836 ahc_validate_width(struct ahc_softc *ahc, struct ahc_initiator_tinfo *tinfo,
1841 if (ahc->features & AHC_WIDE) {
1866 ahc_update_neg_request(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
1880 if ((ahc->features & AHC_WIDE) != 0)
1909 ahc_set_syncrate(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
1929 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, devinfo->our_scsiid,
1956 if ((ahc->features & AHC_ULTRA2) != 0) {
1985 sxfrctl0 = ahc_inb(ahc, SXFRCTL0);
1989 ahc_outb(ahc, SXFRCTL0, sxfrctl0);
1993 ahc_outb(ahc, SCSIRATE, scsirate);
1994 if ((ahc->features & AHC_ULTRA2) != 0)
1995 ahc_outb(ahc, SCSIOFFSET, offset);
2003 ahc_send_async(ahc, devinfo->channel, devinfo->target,
2008 "offset = 0x%x\n", ahc_name(ahc),
2015 ahc_name(ahc), devinfo->target);
2020 update_needed += ahc_update_neg_request(ahc, devinfo, tstate,
2024 ahc_update_pending_scbs(ahc);
2036 ahc_set_width(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
2047 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, devinfo->our_scsiid,
2069 ahc_outb(ahc, SCSIRATE, scsirate);
2073 ahc_send_async(ahc, devinfo->channel, devinfo->target,
2077 ahc_name(ahc), devinfo->target,
2082 update_needed += ahc_update_neg_request(ahc, devinfo, tstate,
2085 ahc_update_pending_scbs(ahc);
2092 ahc_set_tags(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
2095 ahc_platform_set_tags(ahc, devinfo, alg);
2096 ahc_send_async(ahc, devinfo->channel, devinfo->target,
2106 ahc_update_pending_scbs(struct ahc_softc *ahc)
2119 LIST_FOREACH(pending_scb, &ahc->pending_scbs, pending_links) {
2125 ahc_scb_devinfo(ahc, &devinfo, pending_scb);
2126 tinfo = ahc_fetch_transinfo(ahc, devinfo.channel,
2140 ahc_sync_scb(ahc, pending_scb,
2148 if (ahc_is_paused(ahc)) {
2152 ahc_pause(ahc);
2155 saved_scbptr = ahc_inb(ahc, SCBPTR);
2157 for (i = 0; i < ahc->scb_data->maxhscbs; i++) {
2162 ahc_outb(ahc, SCBPTR, i);
2163 scb_tag = ahc_inb(ahc, SCB_TAG);
2164 pending_scb = ahc_lookup_scb(ahc, scb_tag);
2169 control = ahc_inb(ahc, SCB_CONTROL);
2172 ahc_outb(ahc, SCB_CONTROL, control);
2173 ahc_outb(ahc, SCB_SCSIRATE, pending_hscb->scsirate);
2174 ahc_outb(ahc, SCB_SCSIOFFSET, pending_hscb->scsioffset);
2176 ahc_outb(ahc, SCBPTR, saved_scbptr);
2179 ahc_unpause(ahc);
2184 ahc_fetch_devinfo(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
2190 if (ahc_inb(ahc, SSTAT0) & TARGET)
2196 && (ahc->features & AHC_MULTI_TID) != 0
2197 && (ahc_inb(ahc, SEQ_FLAGS)
2200 our_id = ahc_inb(ahc, TARGIDIN) & OID;
2201 } else if ((ahc->features & AHC_ULTRA2) != 0)
2202 our_id = ahc_inb(ahc, SCSIID_ULTRA2) & OID;
2204 our_id = ahc_inb(ahc, SCSIID) & OID;
2206 saved_scsiid = ahc_inb(ahc, SAVED_SCSIID);
2209 SCSIID_TARGET(ahc, saved_scsiid),
2210 ahc_inb(ahc, SAVED_LUN),
2211 SCSIID_CHANNEL(ahc, saved_scsiid),
2249 ahc_print_devinfo(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
2251 printf("%s:%c:%d:%d: ", ahc_name(ahc), devinfo->channel,
2256 ahc_scb_devinfo(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
2266 ahc_compile_devinfo(devinfo, our_id, SCB_GET_TARGET(ahc, scb),
2267 SCB_GET_LUN(scb), SCB_GET_CHANNEL(ahc, scb), role);
2273 ahc_assert_atn(struct ahc_softc *ahc)
2278 if ((ahc->features & AHC_DT) == 0)
2279 scsisigo |= ahc_inb(ahc, SCSISIGI);
2280 ahc_outb(ahc, SCSISIGO, scsisigo);
2290 ahc_setup_initiator_msgout(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
2298 ahc->msgout_index = 0;
2299 ahc->msgout_len = 0;
2302 && ahc_inb(ahc, MSG_OUT) == MSG_IDENTIFYFLAG) {
2308 ahc->msgout_buf[ahc->msgout_index++] = identify_msg;
2309 ahc->msgout_len++;
2312 ahc->msgout_buf[ahc->msgout_index++] =
2314 ahc->msgout_buf[ahc->msgout_index++] = scb->hscb->tag;
2315 ahc->msgout_len += 2;
2320 ahc->msgout_buf[ahc->msgout_index++] = MSG_BUS_DEV_RESET;
2321 ahc->msgout_len++;
2322 ahc_print_path(ahc, scb);
2331 ahc_outb(ahc, SCSISEQ, (ahc_inb(ahc, SCSISEQ) & ~ENSELO));
2334 ahc->msgout_buf[ahc->msgout_index++] = MSG_ABORT_TAG;
2336 ahc->msgout_buf[ahc->msgout_index++] = MSG_ABORT;
2337 ahc->msgout_len++;
2338 ahc_print_path(ahc, scb);
2348 ahc_outb(ahc, SCSISEQ, (ahc_inb(ahc, SCSISEQ) & ~ENSELO));
2350 ahc_build_transfer_msg(ahc, devinfo);
2358 ahc_inb(ahc, MSG_OUT), scb->flags);
2365 ahc_outb(ahc, SCB_CONTROL, ahc_inb(ahc, SCB_CONTROL) & ~MK_MESSAGE);
2367 ahc->msgout_index = 0;
2368 ahc->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
2376 ahc_build_transfer_msg(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
2393 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, devinfo->our_scsiid,
2407 rate = ahc_devlimited_syncrate(ahc, tinfo, &period,
2428 if ((ahc->features & AHC_WIDE) != 0)
2434 ahc_print_devinfo(ahc, devinfo);
2454 ahc_validate_offset(ahc, tinfo, rate, &offset,
2459 ahc_construct_ppr(ahc, devinfo, period, offset,
2462 ahc_construct_sdtr(ahc, devinfo, period, offset);
2465 ahc_construct_wdtr(ahc, devinfo, tinfo->goal.width);
2474 ahc_construct_sdtr(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
2479 ahc->msgout_buf[ahc->msgout_index++] = MSG_EXTENDED;
2480 ahc->msgout_buf[ahc->msgout_index++] = MSG_EXT_SDTR_LEN;
2481 ahc->msgout_buf[ahc->msgout_index++] = MSG_EXT_SDTR;
2482 ahc->msgout_buf[ahc->msgout_index++] = period;
2483 ahc->msgout_buf[ahc->msgout_index++] = offset;
2484 ahc->msgout_len += 5;
2487 ahc_name(ahc), devinfo->channel, devinfo->target,
2497 ahc_construct_wdtr(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
2500 ahc->msgout_buf[ahc->msgout_index++] = MSG_EXTENDED;
2501 ahc->msgout_buf[ahc->msgout_index++] = MSG_EXT_WDTR_LEN;
2502 ahc->msgout_buf[ahc->msgout_index++] = MSG_EXT_WDTR;
2503 ahc->msgout_buf[ahc->msgout_index++] = bus_width;
2504 ahc->msgout_len += 4;
2507 ahc_name(ahc), devinfo->channel, devinfo->target,
2517 ahc_construct_ppr(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_PPR_LEN;
2525 ahc->msgout_buf[ahc->msgout_index++] = MSG_EXT_PPR;
2526 ahc->msgout_buf[ahc->msgout_index++] = period;
2527 ahc->msgout_buf[ahc->msgout_index++] = 0;
2528 ahc->msgout_buf[ahc->msgout_index++] = offset;
2529 ahc->msgout_buf[ahc->msgout_index++] = bus_width;
2530 ahc->msgout_buf[ahc->msgout_index++] = ppr_options;
2531 ahc->msgout_len += 8;
2534 "offset %x, ppr_options %x\n", ahc_name(ahc),
2544 ahc_clear_msg_state(struct ahc_softc *ahc)
2546 ahc->msgout_len = 0;
2547 ahc->msgin_index = 0;
2548 ahc->msg_type = MSG_TYPE_NONE;
2549 if ((ahc_inb(ahc, SCSISIGI) & ATNI) != 0) {
2554 ahc_outb(ahc, CLRSINT1, CLRATNO);
2556 ahc_outb(ahc, MSG_OUT, MSG_NOOP);
2557 ahc_outb(ahc, SEQ_FLAGS2,
2558 ahc_inb(ahc, SEQ_FLAGS2) & ~TARGET_MSG_PENDING);
2562 ahc_handle_proto_violation(struct ahc_softc *ahc)
2572 ahc_fetch_devinfo(ahc, &devinfo);
2573 scbid = ahc_inb(ahc, SCB_TAG);
2574 scb = ahc_lookup_scb(ahc, scbid);
2575 seq_flags = ahc_inb(ahc, SEQ_FLAGS);
2576 curphase = ahc_inb(ahc, SCSISIGI) & PHASE_MASK;
2577 lastphase = ahc_inb(ahc, LASTPHASE);
2585 ahc_print_devinfo(ahc, &devinfo);
2594 ahc_print_devinfo(ahc, &devinfo);
2600 ahc_print_path(ahc, scb);
2602 } else if ((ahc_inb(ahc, SCB_CONTROL) & STATUS_RCVD) == 0) {
2610 ahc_print_path(ahc, scb);
2613 ahc_print_path(ahc, scb);
2615 ahc_dump_card_state(ahc);
2627 found = ahc_reset_channel(ahc, 'A', TRUE);
2629 "%d SCBs aborted\n", ahc_name(ahc), 'A', found);
2636 ahc_outb(ahc, SCSISEQ,
2637 ahc_inb(ahc, SCSISEQ) & ~ENSELO);
2638 ahc_assert_atn(ahc);
2639 ahc_outb(ahc, MSG_OUT, HOST_MSG);
2641 ahc_print_devinfo(ahc, &devinfo);
2642 ahc->msgout_buf[0] = MSG_ABORT_TASK;
2643 ahc->msgout_len = 1;
2644 ahc->msgout_index = 0;
2645 ahc->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
2647 ahc_print_path(ahc, scb);
2659 ahc_handle_message_phase(struct ahc_softc *ahc)
2665 ahc_fetch_devinfo(ahc, &devinfo);
2667 bus_phase = ahc_inb(ahc, SCSISIGI) & PHASE_MASK;
2670 switch (ahc->msg_type) {
2677 if (ahc->msgout_len == 0)
2682 ahc_print_devinfo(ahc, &devinfo);
2702 ahc_outb(ahc, CLRSINT1, CLRATNO);
2703 ahc->send_msg_perror = FALSE;
2704 ahc->msg_type = MSG_TYPE_INITIATOR_MSGIN;
2705 ahc->msgin_index = 0;
2712 if (ahc->send_msg_perror) {
2713 ahc_outb(ahc, CLRSINT1, CLRATNO);
2714 ahc_outb(ahc, CLRSINT1, CLRREQINIT);
2717 printf(" byte 0x%x\n", ahc->send_msg_perror);
2719 ahc_outb(ahc, SCSIDATL, MSG_PARITY_ERROR);
2723 msgdone = ahc->msgout_index == ahc->msgout_len;
2730 ahc->msgout_index = 0;
2731 ahc_assert_atn(ahc);
2734 lastbyte = ahc->msgout_index == (ahc->msgout_len - 1);
2737 ahc_outb(ahc, CLRSINT1, CLRATNO);
2744 ahc_outb(ahc, CLRSINT1, CLRREQINIT);
2748 ahc->msgout_buf[ahc->msgout_index]);
2750 ahc_outb(ahc, SCSIDATL, ahc->msgout_buf[ahc->msgout_index++]);
2760 ahc_print_devinfo(ahc, &devinfo);
2773 ahc->msgin_index = 0;
2775 && (ahc->send_msg_perror == TRUE
2776 || (ahc->msgout_len != 0
2777 && ahc->msgout_index == 0))) {
2778 ahc->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
2786 ahc->msgin_buf[ahc->msgin_index] = ahc_inb(ahc, SCSIBUSL);
2790 ahc->msgin_buf[ahc->msgin_index]);
2793 message_done = ahc_parse_msg(ahc, &devinfo);
2800 ahc->msgin_index = 0;
2807 if (ahc->msgout_len != 0) {
2810 ahc_print_devinfo(ahc, &devinfo);
2814 ahc_assert_atn(ahc);
2817 ahc->msgin_index++;
2823 ahc_outb(ahc, CLRSINT1, CLRREQINIT);
2824 ahc_inb(ahc, SCSIDATL);
2832 if (ahc->msgout_len == 0)
2837 ahc_print_devinfo(ahc, &devinfo);
2848 if ((ahc_inb(ahc, SCSISIGI) & ATNI) != 0
2849 && ahc->msgout_index > 0) {
2860 ahc->msg_type = MSG_TYPE_TARGET_MSGOUT;
2866 ahc_outb(ahc, SXFRCTL0,
2867 ahc_inb(ahc, SXFRCTL0) & ~SPIOEN);
2875 while ((ahc_inb(ahc, SCSISIGI) & ACKI) != 0)
2878 ahc_outb(ahc, SCSISIGO, P_MESGOUT | BSYO);
2885 ahc_flush_device_writes(ahc);
2888 ahc->msgin_index = 0;
2890 ahc_outb(ahc, SXFRCTL0,
2891 ahc_inb(ahc, SXFRCTL0) | SPIOEN);
2895 msgdone = ahc->msgout_index == ahc->msgout_len;
2897 ahc_outb(ahc, SXFRCTL0,
2898 ahc_inb(ahc, SXFRCTL0) & ~SPIOEN);
2909 ahc->msgout_buf[ahc->msgout_index]);
2911 ahc_outb(ahc, SXFRCTL0, ahc_inb(ahc, SXFRCTL0) | SPIOEN);
2912 ahc_outb(ahc, SCSIDATL, ahc->msgout_buf[ahc->msgout_index++]);
2922 ahc_print_devinfo(ahc, &devinfo);
2930 lastbyte = (ahc_inb(ahc, SCSISIGI) & ATNI) == 0;
2937 ahc_outb(ahc, SXFRCTL0, ahc_inb(ahc, SXFRCTL0) & ~SPIOEN);
2938 ahc->msgin_buf[ahc->msgin_index] = ahc_inb(ahc, SCSIDATL);
2943 ahc->msgin_buf[ahc->msgin_index]);
2946 msgdone = ahc_parse_msg(ahc, &devinfo);
2957 ahc->msgin_index++;
2964 ahc->msgin_index = 0;
2970 if (ahc->msgout_len != 0) {
2973 ahc_print_devinfo(ahc, &devinfo);
2977 ahc_outb(ahc, SCSISIGO, P_MESGIN | BSYO);
2988 ahc_flush_device_writes(ahc);
2998 ahc_outb(ahc, SXFRCTL0,
2999 ahc_inb(ahc, SXFRCTL0) | SPIOEN);
3000 ahc->msg_type = MSG_TYPE_TARGET_MSGIN;
3001 ahc->msgin_index = 0;
3010 ahc_outb(ahc, SXFRCTL0,
3011 ahc_inb(ahc, SXFRCTL0) | SPIOEN);
3021 ahc_clear_msg_state(ahc);
3022 ahc_outb(ahc, RETURN_1, EXIT_MSG_LOOP);
3024 ahc_outb(ahc, RETURN_1, CONT_MSG_LOOP);
3034 ahc_sent_msg(struct ahc_softc *ahc, ahc_msgtype type, u_int msgval, int full)
3042 while (index < ahc->msgout_len) {
3043 if (ahc->msgout_buf[index] == MSG_EXTENDED) {
3046 end_index = index + 1 + ahc->msgout_buf[index + 1];
3047 if (ahc->msgout_buf[index+2] == msgval
3051 if (ahc->msgout_index > end_index)
3053 } else if (ahc->msgout_index > index)
3057 } else if (ahc->msgout_buf[index] >= MSG_SIMPLE_TASK
3058 && ahc->msgout_buf[index] <= MSG_IGN_WIDE_RESIDUE) {
3065 && ahc->msgout_buf[index] == msgval
3066 && ahc->msgout_index > index)
3081 ahc_parse_msg(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
3093 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, devinfo->our_scsiid,
3108 switch (ahc->msgin_buf[0]) {
3121 response = ahc_handle_msg_reject(ahc, devinfo);
3129 if (ahc->msgin_index < 2)
3131 switch (ahc->msgin_buf[2]) {
3140 if (ahc->msgin_buf[1] != MSG_EXT_SDTR_LEN) {
3152 if (ahc->msgin_index < (MSG_EXT_SDTR_LEN + 1))
3155 period = ahc->msgin_buf[3];
3157 saved_offset = offset = ahc->msgin_buf[4];
3158 syncrate = ahc_devlimited_syncrate(ahc, tinfo, &period,
3161 ahc_validate_offset(ahc, tinfo, syncrate, &offset,
3168 ahc_name(ahc), devinfo->channel,
3170 ahc->msgin_buf[3], saved_offset,
3173 ahc_set_syncrate(ahc, devinfo,
3184 if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_SDTR, TRUE)) {
3198 ahc_name(ahc), devinfo->channel,
3201 ahc->msgout_index = 0;
3202 ahc->msgout_len = 0;
3203 ahc_construct_sdtr(ahc, devinfo,
3205 ahc->msgout_index = 0;
3218 if (ahc->msgin_buf[1] != MSG_EXT_WDTR_LEN) {
3230 if (ahc->msgin_index < (MSG_EXT_WDTR_LEN + 1))
3233 bus_width = ahc->msgin_buf[3];
3235 ahc_validate_width(ahc, tinfo, &bus_width,
3240 ahc_name(ahc), devinfo->channel,
3245 if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_WDTR, TRUE)) {
3256 ahc_name(ahc), devinfo->channel,
3269 ahc_name(ahc), devinfo->channel,
3272 ahc->msgout_index = 0;
3273 ahc->msgout_len = 0;
3274 ahc_construct_wdtr(ahc, devinfo, bus_width);
3275 ahc->msgout_index = 0;
3288 ahc_update_neg_request(ahc, devinfo, tstate,
3290 ahc_set_width(ahc, devinfo, bus_width,
3298 ahc->msgout_index = 0;
3299 ahc->msgout_len = 0;
3300 ahc_build_transfer_msg(ahc, devinfo);
3301 ahc->msgout_index = 0;
3318 if (ahc->msgin_buf[1] != MSG_EXT_PPR_LEN) {
3330 if (ahc->msgin_index < (MSG_EXT_PPR_LEN + 1))
3333 period = ahc->msgin_buf[3];
3334 offset = ahc->msgin_buf[5];
3335 bus_width = ahc->msgin_buf[6];
3337 ppr_options = ahc->msgin_buf[7];
3358 ahc_validate_width(ahc, tinfo, &bus_width,
3360 syncrate = ahc_devlimited_syncrate(ahc, tinfo, &period,
3363 ahc_validate_offset(ahc, tinfo, syncrate,
3367 if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_PPR, TRUE)) {
3387 ahc_name(ahc), devinfo->channel,
3392 ahc_name(ahc), devinfo->channel,
3394 ahc->msgout_index = 0;
3395 ahc->msgout_len = 0;
3396 ahc_construct_ppr(ahc, devinfo, period, offset,
3398 ahc->msgout_index = 0;
3406 ahc_name(ahc), devinfo->channel,
3408 saved_width, ahc->msgin_buf[3],
3412 ahc_set_width(ahc, devinfo, bus_width,
3415 ahc_set_syncrate(ahc, devinfo,
3432 ahc_handle_devreset(ahc, devinfo,
3436 ahc_restart(ahc);
3451 if (ahc->msgin_buf[0] == MSG_ABORT_TAG)
3452 tag = ahc_inb(ahc, INITIATOR_TAG);
3453 ahc_abort_scbs(ahc, devinfo->target, devinfo->channel,
3457 tstate = ahc->enabled_targets[devinfo->our_scsiid];
3463 ahc_queue_lstate_event(ahc, lstate,
3465 ahc->msgin_buf[0],
3467 ahc_send_lstate_events(ahc, lstate);
3470 ahc_restart(ahc);
3485 ahc->msgout_index = 0;
3486 ahc->msgout_len = 1;
3487 ahc->msgout_buf[0] = MSG_MESSAGE_REJECT;
3494 ahc->msgout_len = 0;
3503 ahc_handle_msg_reject(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
3518 scb_index = ahc_inb(ahc, SCB_TAG);
3519 scb = ahc_lookup_scb(ahc, scb_index);
3520 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel,
3524 last_msg = ahc_inb(ahc, LAST_MSG);
3526 if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_PPR, /*full*/FALSE)) {
3534 ahc_name(ahc), devinfo->channel,
3540 ahc->msgout_index = 0;
3541 ahc->msgout_len = 0;
3542 ahc_build_transfer_msg(ahc, devinfo);
3543 ahc->msgout_index = 0;
3545 } else if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_WDTR, /*full*/FALSE)) {
3549 "8bit transfers\n", ahc_name(ahc),
3551 ahc_set_width(ahc, devinfo, MSG_EXT_WDTR_BUS_8_BIT,
3564 ahc->msgout_index = 0;
3565 ahc->msgout_len = 0;
3566 ahc_build_transfer_msg(ahc, devinfo);
3567 ahc->msgout_index = 0;
3570 } else if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_SDTR, /*full*/FALSE)) {
3572 ahc_set_syncrate(ahc, devinfo, /*syncrate*/NULL, /*period*/0,
3578 ahc_name(ahc), devinfo->channel,
3588 "Performing non-tagged I/O\n", ahc_name(ahc),
3590 ahc_set_tags(ahc, devinfo, AHC_QUEUE_NONE);
3595 ahc_name(ahc), devinfo->channel, devinfo->target,
3598 ahc_set_tags(ahc, devinfo, AHC_QUEUE_BASIC);
3606 ahc_outb(ahc, SCB_CONTROL,
3607 ahc_inb(ahc, SCB_CONTROL) & mask);
3611 ahc_outb(ahc, MSG_OUT, MSG_IDENTIFYFLAG);
3612 ahc_assert_atn(ahc);
3618 if ((ahc->flags & AHC_SCB_BTT) == 0) {
3622 &(ahc->untagged_queues[devinfo->target_offset]);
3626 ahc_busy_tcl(ahc, BUILD_TCL(scb->hscb->scsiid, devinfo->lun),
3634 ahc_search_qinfifo(ahc, SCB_GET_TARGET(ahc, scb),
3635 SCB_GET_CHANNEL(ahc, scb),
3644 ahc_name(ahc), devinfo->channel, devinfo->target,
3654 ahc_handle_ign_wide_residue(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
3659 scb_index = ahc_inb(ahc, SCB_TAG);
3660 scb = ahc_lookup_scb(ahc, scb_index);
3665 if ((ahc_inb(ahc, SEQ_FLAGS) & DPHASE) == 0
3681 sgptr = ahc_inb(ahc, SCB_RESIDUAL_SGPTR);
3683 && (ahc_inb(ahc, SCB_LUN) & SCB_XFERLEN_ODD) != 0) {
3697 sgptr = ahc_inl(ahc, SCB_RESIDUAL_SGPTR);
3698 data_cnt = ahc_inl(ahc, SCB_RESIDUAL_DATACNT);
3709 data_addr = ahc_inl(ahc, SHADDR);
3743 ahc_outl(ahc, SCB_RESIDUAL_SGPTR, sgptr);
3744 ahc_outl(ahc, SCB_RESIDUAL_DATACNT, data_cnt);
3751 ahc_outb(ahc, SCB_LUN,
3752 ahc_inb(ahc, SCB_LUN) ^ SCB_XFERLEN_ODD);
3763 ahc_reinitialize_dataptrs(struct ahc_softc *ahc)
3772 scb_index = ahc_inb(ahc, SCB_TAG);
3773 scb = ahc_lookup_scb(ahc, scb_index);
3774 sgptr = (ahc_inb(ahc, SCB_RESIDUAL_SGPTR + 3) << 24)
3775 | (ahc_inb(ahc, SCB_RESIDUAL_SGPTR + 2) << 16)
3776 | (ahc_inb(ahc, SCB_RESIDUAL_SGPTR + 1) << 8)
3777 | ahc_inb(ahc, SCB_RESIDUAL_SGPTR);
3785 resid = (ahc_inb(ahc, SCB_RESIDUAL_DATACNT + 2) << 16)
3786 | (ahc_inb(ahc, SCB_RESIDUAL_DATACNT + 1) << 8)
3787 | ahc_inb(ahc, SCB_RESIDUAL_DATACNT);
3792 if ((ahc->flags & AHC_39BIT_ADDRESSING) != 0) {
3795 dscommand1 = ahc_inb(ahc, DSCOMMAND1);
3796 ahc_outb(ahc, DSCOMMAND1, dscommand1 | HADDLDSEL0);
3797 ahc_outb(ahc, HADDR,
3799 ahc_outb(ahc, DSCOMMAND1, dscommand1);
3801 ahc_outb(ahc, HADDR + 3, dataptr >> 24);
3802 ahc_outb(ahc, HADDR + 2, dataptr >> 16);
3803 ahc_outb(ahc, HADDR + 1, dataptr >> 8);
3804 ahc_outb(ahc, HADDR, dataptr);
3805 ahc_outb(ahc, HCNT + 2, resid >> 16);
3806 ahc_outb(ahc, HCNT + 1, resid >> 8);
3807 ahc_outb(ahc, HCNT, resid);
3808 if ((ahc->features & AHC_ULTRA2) == 0) {
3809 ahc_outb(ahc, STCNT + 2, resid >> 16);
3810 ahc_outb(ahc, STCNT + 1, resid >> 8);
3811 ahc_outb(ahc, STCNT, resid);
3819 ahc_handle_devreset(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
3828 found = ahc_abort_scbs(ahc, devinfo->target, devinfo->channel,
3837 tstate = ahc->enabled_targets[devinfo->our_scsiid];
3846 ahc_queue_lstate_event(ahc, lstate, devinfo->our_scsiid,
3848 ahc_send_lstate_events(ahc, lstate);
3856 ahc_set_width(ahc, devinfo, MSG_EXT_WDTR_BUS_8_BIT,
3858 ahc_set_syncrate(ahc, devinfo, /*syncrate*/NULL,
3863 ahc_send_async(ahc, devinfo->channel, devinfo->target,
3868 printf("%s: %s on %c:%d. %d SCBs aborted\n", ahc_name(ahc),
3874 ahc_setup_target_msgin(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
3883 ahc->msgout_index = 0;
3884 ahc->msgout_len = 0;
3887 ahc_build_transfer_msg(ahc, devinfo);
3891 ahc->msgout_index = 0;
3892 ahc->msg_type = MSG_TYPE_TARGET_MSGIN;
3903 struct ahc_softc *ahc;
3907 ahc = malloc(sizeof(*ahc), M_DEVBUF, M_NOWAIT);
3908 if (!ahc) {
3914 ahc = device_get_softc((device_t)platform_arg);
3916 memset(ahc, 0, sizeof(*ahc));
3917 ahc->seep_config = malloc(sizeof(*ahc->seep_config),
3919 if (ahc->seep_config == NULL) {
3921 free(ahc, M_DEVBUF);
3926 LIST_INIT(&ahc->pending_scbs);
3927 LIST_INIT(&ahc->timedout_scbs);
3929 ahc->name = name;
3930 ahc->unit = -1;
3931 ahc->description = NULL;
3932 ahc->channel = 'A';
3933 ahc->channel_b = 'B';
3934 ahc->chip = AHC_NONE;
3935 ahc->features = AHC_FENONE;
3936 ahc->bugs = AHC_BUGNONE;
3937 ahc->flags = AHC_FNONE;
3943 ahc->seqctl = FASTMODE;
3946 TAILQ_INIT(&ahc->untagged_queues[i]);
3947 if (ahc_platform_alloc(ahc, platform_arg) != 0) {
3948 ahc_free(ahc);
3949 ahc = NULL;
3951 ahc_lockinit(ahc);
3952 return (ahc);
3956 ahc_softc_init(struct ahc_softc *ahc)
3960 if ((ahc->chip & AHC_PCI) == 0)
3961 ahc->unpause = ahc_inb(ahc, HCNTRL) & IRQMS;
3963 ahc->unpause = 0;
3964 ahc->pause = ahc->unpause | PAUSE;
3966 if (ahc->scb_data == NULL) {
3967 ahc->scb_data = malloc(sizeof(*ahc->scb_data),
3969 if (ahc->scb_data == NULL)
3971 memset(ahc->scb_data, 0, sizeof(*ahc->scb_data));
3978 ahc_softc_insert(struct ahc_softc *ahc)
3987 if ((ahc->chip & AHC_BUS_MASK) == AHC_PCI
3988 && (ahc->features & AHC_MULTI_FUNC) != 0) {
3994 pci = ahc->dev_softc;
4002 slave = ahc;
4004 master = ahc;
4024 && ahc_softc_comp(ahc, list_ahc) <= 0)
4027 TAILQ_INSERT_BEFORE(list_ahc, ahc, links);
4029 TAILQ_INSERT_TAIL(&ahc_tailq, ahc, links);
4030 ahc->init_level++;
4034 ahc_set_unit(struct ahc_softc *ahc, int unit)
4036 ahc->unit = unit;
4040 ahc_set_name(struct ahc_softc *ahc, char *name)
4042 if (ahc->name != NULL)
4043 free(ahc->name, M_DEVBUF);
4044 ahc->name = name;
4048 ahc_free(struct ahc_softc *ahc)
4052 ahc_terminate_recovery_thread(ahc);
4053 switch (ahc->init_level) {
4056 ahc_shutdown(ahc);
4059 aic_dmamap_unload(ahc, ahc->shared_data_dmat,
4060 ahc->shared_data_dmamap);
4063 aic_dmamem_free(ahc, ahc->shared_data_dmat, ahc->qoutfifo,
4064 ahc->shared_data_dmamap);
4065 aic_dmamap_destroy(ahc, ahc->shared_data_dmat,
4066 ahc->shared_data_dmamap);
4069 aic_dma_tag_destroy(ahc, ahc->shared_data_dmat);
4072 aic_dma_tag_destroy(ahc, ahc->buffer_dmat);
4080 aic_dma_tag_destroy(ahc, ahc->parent_dmat);
4082 ahc_platform_free(ahc);
4083 ahc_fini_scbdata(ahc);
4087 tstate = ahc->enabled_targets[i];
4106 if (ahc->black_hole != NULL) {
4107 xpt_free_path(ahc->black_hole->path);
4108 free(ahc->black_hole, M_DEVBUF);
4111 if (ahc->name != NULL)
4112 free(ahc->name, M_DEVBUF);
4113 if (ahc->seep_config != NULL)
4114 free(ahc->seep_config, M_DEVBUF);
4116 free(ahc, M_DEVBUF);
4124 struct ahc_softc *ahc;
4127 ahc = (struct ahc_softc *)arg;
4130 ahc_reset(ahc, /*reinit*/FALSE);
4131 ahc_outb(ahc, SCSISEQ, 0);
4132 ahc_outb(ahc, SXFRCTL0, 0);
4133 ahc_outb(ahc, DSPCISTATUS, 0);
4136 ahc_outb(ahc, i, 0);
4149 ahc_reset(struct ahc_softc *ahc, int reinit)
4161 ahc_pause(ahc);
4163 if ((ahc->chip & AHC_CHIPID_MASK) == AHC_AIC7770) {
4170 sblkctl = ahc_inb(ahc, SBLKCTL);
4171 ahc_outb(ahc, SBLKCTL, sblkctl | SELBUSB);
4172 sxfrctl1_b = ahc_inb(ahc, SXFRCTL1);
4173 ahc_outb(ahc, SBLKCTL, sblkctl & ~SELBUSB);
4175 sxfrctl1_a = ahc_inb(ahc, SXFRCTL1);
4177 ahc_outb(ahc, HCNTRL, CHIPRST | ahc->pause);
4188 } while (--wait && !(ahc_inb(ahc, HCNTRL) & CHIPRSTACK));
4192 "Trying to initialize anyway.\n", ahc_name(ahc));
4194 ahc_outb(ahc, HCNTRL, ahc->pause);
4197 sblkctl = ahc_inb(ahc, SBLKCTL) & (SELBUSB|SELWIDE);
4199 if ((ahc->chip & AHC_PCI) != 0)
4207 ahc->features |= AHC_WIDE;
4211 ahc->features |= AHC_TWIN;
4226 if ((ahc->features & AHC_TWIN) != 0) {
4229 sblkctl = ahc_inb(ahc, SBLKCTL);
4230 ahc_outb(ahc, SBLKCTL, sblkctl | SELBUSB);
4231 ahc_outb(ahc, SXFRCTL1, sxfrctl1_b);
4232 ahc_outb(ahc, SBLKCTL, sblkctl & ~SELBUSB);
4234 ahc_outb(ahc, SXFRCTL1, sxfrctl1_a);
4242 error = ahc->bus_chip_init(ahc);
4245 ahc_dumpseq(ahc);
4255 ahc_probe_scbs(struct ahc_softc *ahc) {
4260 ahc_outb(ahc, SCBPTR, i);
4261 ahc_outb(ahc, SCB_BASE, i);
4262 if (ahc_inb(ahc, SCB_BASE) != i)
4264 ahc_outb(ahc, SCBPTR, 0);
4265 if (ahc_inb(ahc, SCB_BASE) != 0)
4281 ahc_build_free_scb_list(struct ahc_softc *ahc)
4287 if ((ahc->flags & AHC_LSCBS_ENABLED) != 0)
4290 for (i = 0; i < ahc->scb_data->maxhscbs; i++) {
4293 ahc_outb(ahc, SCBPTR, i);
4301 ahc_outb(ahc, SCB_BASE+j, 0xFF);
4304 ahc_outb(ahc, SCB_CONTROL, 0);
4307 if ((ahc->flags & AHC_PAGESCBS) != 0)
4308 ahc_outb(ahc, SCB_NEXT, i+1);
4310 ahc_outb(ahc, SCB_NEXT, SCB_LIST_NULL);
4313 ahc_outb(ahc, SCB_TAG, SCB_LIST_NULL);
4314 ahc_outb(ahc, SCB_SCSIID, 0xFF);
4315 ahc_outb(ahc, SCB_LUN, 0xFF);
4318 if ((ahc->flags & AHC_PAGESCBS) != 0) {
4320 ahc_outb(ahc, FREE_SCBH, 0);
4323 ahc_outb(ahc, FREE_SCBH, SCB_LIST_NULL);
4327 ahc_outb(ahc, SCBPTR, i-1);
4328 ahc_outb(ahc, SCB_NEXT, SCB_LIST_NULL);
4332 ahc_init_scbdata(struct ahc_softc *ahc)
4336 scb_data = ahc->scb_data;
4350 scb_data->maxhscbs = ahc_probe_scbs(ahc);
4351 if (ahc->scb_data->maxhscbs == 0) {
4352 printf("%s: No SCB space found\n", ahc_name(ahc));
4367 if (aic_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/1,
4382 if (aic_dmamem_alloc(ahc, scb_data->hscb_dmat,
4392 aic_dmamap_load(ahc, scb_data->hscb_dmat, scb_data->hscb_dmamap,
4400 if (aic_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/1,
4415 if (aic_dmamem_alloc(ahc, scb_data->sense_dmat,
4424 aic_dmamap_load(ahc, scb_data->sense_dmat, scb_data->sense_dmamap,
4432 if (aic_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/8,
4448 while (ahc_alloc_scbs(ahc) != 0)
4454 ahc_name(ahc));
4461 ahc->next_queued_scb = ahc_get_scb(ahc);
4474 ahc_fini_scbdata(struct ahc_softc *ahc)
4478 scb_data = ahc->scb_data;
4490 aic_dmamap_unload(ahc, scb_data->sg_dmat,
4492 aic_dmamem_free(ahc, scb_data->sg_dmat,
4497 aic_dma_tag_destroy(ahc, scb_data->sg_dmat);
4500 aic_dmamap_unload(ahc, scb_data->sense_dmat,
4503 aic_dmamem_free(ahc, scb_data->sense_dmat, scb_data->sense,
4505 aic_dmamap_destroy(ahc, scb_data->sense_dmat,
4508 aic_dma_tag_destroy(ahc, scb_data->sense_dmat);
4510 aic_dmamap_unload(ahc, scb_data->hscb_dmat,
4513 aic_dmamem_free(ahc, scb_data->hscb_dmat, scb_data->hscbs,
4515 aic_dmamap_destroy(ahc, scb_data->hscb_dmat,
4518 aic_dma_tag_destroy(ahc, scb_data->hscb_dmat);
4528 ahc_alloc_scbs(struct ahc_softc *ahc)
4538 scb_data = ahc->scb_data;
4551 if (aic_dmamem_alloc(ahc, scb_data->sg_dmat,
4561 aic_dmamap_load(ahc, scb_data->sg_dmat, sg_map->sg_dmamap,
4587 next_scb->ahc_softc = ahc;
4590 error = aic_dmamap_create(ahc, ahc->buffer_dmat, /*flags*/0,
4596 next_scb->hscb->tag = ahc->scb_data->numscbs;
4598 SLIST_INSERT_HEAD(&ahc->scb_data->free_scbs,
4603 ahc->scb_data->numscbs++;
4609 ahc_controller_info(struct ahc_softc *ahc, char *buf)
4613 len = sprintf(buf, "%s: ", ahc_chip_names[ahc->chip & AHC_CHIPID_MASK]);
4615 if ((ahc->features & AHC_TWIN) != 0)
4618 ahc->our_id, ahc->our_id_b,
4619 (ahc->flags & AHC_PRIMARY_CHANNEL) + 'A');
4625 if ((ahc->features & AHC_ULTRA) != 0) {
4627 } else if ((ahc->features & AHC_DT) != 0) {
4629 } else if ((ahc->features & AHC_ULTRA2) != 0) {
4632 if ((ahc->features & AHC_WIDE) != 0) {
4638 speed, type, ahc->channel, ahc->our_id);
4642 if ((ahc->flags & AHC_PAGESCBS) != 0)
4644 ahc->scb_data->maxhscbs, AHC_MAX_QUEUE);
4646 sprintf(buf, "%d SCBs", ahc->scb_data->maxhscbs);
4650 ahc_chip_init(struct ahc_softc *ahc)
4659 ahc_outb(ahc, SEQ_FLAGS, 0);
4660 ahc_outb(ahc, SEQ_FLAGS2, 0);
4663 if (ahc->features & AHC_TWIN) {
4668 ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) | SELBUSB);
4669 term = (ahc->flags & AHC_TERM_ENB_B) != 0 ? STPWEN : 0;
4670 ahc_outb(ahc, SCSIID, ahc->our_id_b);
4671 scsi_conf = ahc_inb(ahc, SCSICONF + 1);
4672 ahc_outb(ahc, SXFRCTL1, (scsi_conf & (ENSPCHK|STIMESEL))
4673 |term|ahc->seltime_b|ENSTIMER|ACTNEGEN);
4674 if ((ahc->features & AHC_ULTRA2) != 0)
4675 ahc_outb(ahc, SIMODE0, ahc_inb(ahc, SIMODE0)|ENIOERR);
4676 ahc_outb(ahc, SIMODE1, ENSELTIMO|ENSCSIRST|ENSCSIPERR);
4677 ahc_outb(ahc, SXFRCTL0, DFON|SPIOEN);
4680 ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) & ~SELBUSB);
4682 term = (ahc->flags & AHC_TERM_ENB_A) != 0 ? STPWEN : 0;
4683 if ((ahc->features & AHC_ULTRA2) != 0)
4684 ahc_outb(ahc, SCSIID_ULTRA2, ahc->our_id);
4686 ahc_outb(ahc, SCSIID, ahc->our_id);
4687 scsi_conf = ahc_inb(ahc, SCSICONF);
4688 ahc_outb(ahc, SXFRCTL1, (scsi_conf & (ENSPCHK|STIMESEL))
4689 |term|ahc->seltime
4691 if ((ahc->features & AHC_ULTRA2) != 0)
4692 ahc_outb(ahc, SIMODE0, ahc_inb(ahc, SIMODE0)|ENIOERR);
4693 ahc_outb(ahc, SIMODE1, ENSELTIMO|ENSCSIRST|ENSCSIPERR);
4694 ahc_outb(ahc, SXFRCTL0, DFON|SPIOEN);
4698 ahc_unbusy_tcl(ahc, BUILD_TCL(i << 4, 0));
4699 if ((ahc->flags & AHC_SCB_BTT) != 0) {
4707 ahc_unbusy_tcl(ahc, BUILD_TCL(i << 4, lun));
4713 ahc->qoutfifo[i] = SCB_LIST_NULL;
4714 ahc_sync_qoutfifo(ahc, BUS_DMASYNC_PREREAD);
4717 ahc->qinfifo[i] = SCB_LIST_NULL;
4719 if ((ahc->features & AHC_MULTI_TID) != 0) {
4720 ahc_outb(ahc, TARGID, 0);
4721 ahc_outb(ahc, TARGID + 1, 0);
4727 physaddr = ahc->scb_data->hscb_busaddr;
4728 ahc_outb(ahc, HSCB_ADDR, physaddr & 0xFF);
4729 ahc_outb(ahc, HSCB_ADDR + 1, (physaddr >> 8) & 0xFF);
4730 ahc_outb(ahc, HSCB_ADDR + 2, (physaddr >> 16) & 0xFF);
4731 ahc_outb(ahc, HSCB_ADDR + 3, (physaddr >> 24) & 0xFF);
4733 physaddr = ahc->shared_data_busaddr;
4734 ahc_outb(ahc, SHARED_DATA_ADDR, physaddr & 0xFF);
4735 ahc_outb(ahc, SHARED_DATA_ADDR + 1, (physaddr >> 8) & 0xFF);
4736 ahc_outb(ahc, SHARED_DATA_ADDR + 2, (physaddr >> 16) & 0xFF);
4737 ahc_outb(ahc, SHARED_DATA_ADDR + 3, (physaddr >> 24) & 0xFF);
4744 ahc_outb(ahc, CMDSIZE_TABLE, 5);
4745 ahc_outb(ahc, CMDSIZE_TABLE + 1, 9);
4746 ahc_outb(ahc, CMDSIZE_TABLE + 2, 9);
4747 ahc_outb(ahc, CMDSIZE_TABLE + 3, 0);
4748 ahc_outb(ahc, CMDSIZE_TABLE + 4, 15);
4749 ahc_outb(ahc, CMDSIZE_TABLE + 5, 11);
4750 ahc_outb(ahc, CMDSIZE_TABLE + 6, 0);
4751 ahc_outb(ahc, CMDSIZE_TABLE + 7, 0);
4753 if ((ahc->features & AHC_HS_MAILBOX) != 0)
4754 ahc_outb(ahc, HS_MAILBOX, 0);
4757 if ((ahc->features & AHC_TARGETMODE) != 0) {
4758 ahc->tqinfifonext = 1;
4759 ahc_outb(ahc, KERNEL_TQINPOS, ahc->tqinfifonext - 1);
4760 ahc_outb(ahc, TQINPOS, ahc->tqinfifonext);
4762 ahc->qinfifonext = 0;
4763 ahc->qoutfifonext = 0;
4764 if ((ahc->features & AHC_QUEUE_REGS) != 0) {
4765 ahc_outb(ahc, QOFF_CTLSTA, SCB_QSIZE_256);
4766 ahc_outb(ahc, HNSCB_QOFF, ahc->qinfifonext);
4767 ahc_outb(ahc, SNSCB_QOFF, ahc->qinfifonext);
4768 ahc_outb(ahc, SDSCB_QOFF, 0);
4770 ahc_outb(ahc, KERNEL_QINPOS, ahc->qinfifonext);
4771 ahc_outb(ahc, QINPOS, ahc->qinfifonext);
4772 ahc_outb(ahc, QOUTPOS, ahc->qoutfifonext);
4776 ahc_outb(ahc, WAITING_SCBH, SCB_LIST_NULL);
4779 ahc_outb(ahc, DISCONNECTED_SCBH, SCB_LIST_NULL);
4782 ahc_outb(ahc, MSG_OUT, MSG_NOOP);
4790 if ((ahc->flags & AHC_INITIATORROLE) != 0)
4792 ahc_outb(ahc, SCSISEQ_TEMPLATE, scsiseq_template);
4795 ahc_build_free_scb_list(ahc);
4800 ahc_outb(ahc, NEXT_QUEUED_SCB, ahc->next_queued_scb->hscb->tag);
4808 ahc_name(ahc));
4810 error = ahc_loadseq(ahc);
4814 if ((ahc->features & AHC_ULTRA2) != 0) {
4825 (ahc_inb(ahc, SBLKCTL) & (ENAB40|ENAB20)) == 0 && wait;
4829 ahc_restart(ahc);
4837 ahc_init(struct ahc_softc *ahc)
4850 ahc->flags |= AHC_SEQUENCER_DEBUG;
4859 printf (" 0x%x", ahc_inb(ahc, i));
4861 if ((ahc->features & AHC_MORE_SRAM) != 0) {
4866 printf (" 0x%x", ahc_inb(ahc, i));
4874 ahc_outb(ahc, CLRINT, CLRPARERR);
4875 ahc_outb(ahc, CLRINT, CLRBRKADRINT);
4882 if ((ahc->flags & AHC_USEDEFAULTS) != 0)
4883 ahc->our_id = ahc->our_id_b = 7;
4888 ahc->flags |= AHC_INITIATORROLE;
4893 if ((AHC_TMODE_ENABLE & (0x1 << ahc->unit)) == 0)
4894 ahc->features &= ~AHC_TARGETMODE;
4898 if (aic_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/1,
4900 /*lowaddr*/ahc->flags & AHC_39BIT_ADDRESSING
4909 &ahc->buffer_dmat) != 0) {
4914 ahc->init_level++;
4926 if ((ahc->features & AHC_TARGETMODE) != 0)
4929 if (aic_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/1,
4937 /*flags*/0, &ahc->shared_data_dmat) != 0) {
4941 ahc->init_level++;
4944 if (aic_dmamem_alloc(ahc, ahc->shared_data_dmat,
4945 (void **)&ahc->qoutfifo,
4947 &ahc->shared_data_dmamap) != 0) {
4951 ahc->init_level++;
4954 aic_dmamap_load(ahc, ahc->shared_data_dmat, ahc->shared_data_dmamap,
4955 ahc->qoutfifo, driver_data_size, ahc_dmamap_cb,
4956 &ahc->shared_data_busaddr, /*flags*/0);
4958 if ((ahc->features & AHC_TARGETMODE) != 0) {
4959 ahc->targetcmds = (struct target_cmd *)ahc->qoutfifo;
4960 ahc->qoutfifo = (uint8_t *)&ahc->targetcmds[AHC_TMODE_CMDS];
4961 ahc->dma_bug_buf = ahc->shared_data_busaddr
4965 ahc->targetcmds[i].cmd_valid = 0;
4966 ahc_sync_tqinfifo(ahc, BUS_DMASYNC_PREREAD);
4967 ahc->qoutfifo = (uint8_t *)&ahc->targetcmds[256];
4969 ahc->qinfifo = &ahc->qoutfifo[256];
4971 ahc->init_level++;
4974 if (ahc->scb_data->maxhscbs == 0)
4975 if (ahc_init_scbdata(ahc) != 0)
4983 if (ahc_alloc_tstate(ahc, ahc->our_id, 'A') == NULL) {
4985 "Failing attach\n", ahc_name(ahc));
4989 if ((ahc->features & AHC_TWIN) != 0) {
4990 if (ahc_alloc_tstate(ahc, ahc->our_id_b, 'B') == NULL) {
4992 "Failing attach\n", ahc_name(ahc));
5000 error = ahc_spawn_recovery_thread(ahc);
5004 if (ahc->scb_data->maxhscbs < AHC_SCB_MAX_ALLOC) {
5005 ahc->flags |= AHC_PAGESCBS;
5007 ahc->flags &= ~AHC_PAGESCBS;
5014 ahc_name(ahc),
5025 if (ahc->features & AHC_TWIN) {
5026 scsi_conf = ahc_inb(ahc, SCSICONF + 1);
5028 && (ahc->flags & AHC_INITIATORROLE) != 0)
5029 ahc->flags |= AHC_RESET_BUS_B;
5032 scsi_conf = ahc_inb(ahc, SCSICONF);
5034 && (ahc->flags & AHC_INITIATORROLE) != 0)
5035 ahc->flags |= AHC_RESET_BUS_A;
5041 if ((ahc->flags & AHC_USEDEFAULTS) != 0) {
5043 "device parameters\n", ahc_name(ahc));
5044 ahc->flags |= AHC_EXTENDED_TRANS_A|AHC_EXTENDED_TRANS_B|
5047 if ((ahc->features & AHC_ULTRA) != 0)
5050 discenable = ~((ahc_inb(ahc, DISC_DSB + 1) << 8)
5051 | ahc_inb(ahc, DISC_DSB));
5052 if ((ahc->features & (AHC_ULTRA|AHC_ULTRA2)) != 0)
5053 ultraenb = (ahc_inb(ahc, ULTRA_ENB + 1) << 8)
5054 | ahc_inb(ahc, ULTRA_ENB);
5057 if ((ahc->features & (AHC_WIDE|AHC_TWIN)) == 0)
5068 our_id = ahc->our_id;
5070 if (i > 7 && (ahc->features & AHC_TWIN) != 0) {
5072 our_id = ahc->our_id_b;
5075 tinfo = ahc_fetch_transinfo(ahc, channel, our_id,
5079 if (ahc->flags & AHC_USEDEFAULTS) {
5080 if ((ahc->features & AHC_WIDE) != 0)
5094 scsirate = ahc_inb(ahc, TARG_SCSIRATE + i);
5096 if ((ahc->features & AHC_ULTRA2) != 0) {
5111 offset = ahc_inb(ahc, TARG_OFFSET + i);
5116 if ((ahc->features & AHC_DT) != 0)
5119 ahc_find_period(ahc, scsirate, maxsync);
5125 && (ahc->features & AHC_DT) != 0)
5136 ahc_find_period(ahc, scsirate,
5146 && (ahc->features & AHC_WIDE) != 0)
5149 if ((ahc->features & AHC_DT) != 0)
5160 ahc->user_discenable = discenable;
5161 ahc->user_tagenable = tagenable;
5163 return (ahc->bus_chip_init(ahc));
5167 ahc_intr_enable(struct ahc_softc *ahc, int enable)
5171 hcntrl = ahc_inb(ahc, HCNTRL);
5173 ahc->pause &= ~INTEN;
5174 ahc->unpause &= ~INTEN;
5177 ahc->pause |= INTEN;
5178 ahc->unpause |= INTEN;
5180 ahc_outb(ahc, HCNTRL, hcntrl);
5191 ahc_pause_and_flushwork(struct ahc_softc *ahc)
5198 ahc->flags |= AHC_ALL_INTERRUPTS;
5202 ahc_unpause(ahc);
5209 ahc_intr(ahc);
5210 ahc_pause(ahc);
5212 ahc_outb(ahc, SCSISEQ, ahc_inb(ahc, SCSISEQ) & ~ENSELO);
5213 intstat = ahc_inb(ahc, INTSTAT);
5215 ahc_clear_critical_section(ahc);
5216 intstat = ahc_inb(ahc, INTSTAT);
5219 && (intstat != 0xFF || (ahc->features & AHC_REMOVABLE) == 0)
5221 || (ahc_inb(ahc, SSTAT0) & (SELDO|SELINGO)) != 0));
5224 ahc_inb(ahc, INTSTAT));
5226 ahc_platform_flushwork(ahc);
5227 ahc->flags &= ~AHC_ALL_INTERRUPTS;
5231 ahc_suspend(struct ahc_softc *ahc)
5234 ahc_pause_and_flushwork(ahc);
5236 if (LIST_FIRST(&ahc->pending_scbs) != NULL) {
5237 ahc_unpause(ahc);
5247 if (ahc->pending_device != NULL) {
5248 ahc_unpause(ahc);
5252 ahc_shutdown(ahc);
5257 ahc_resume(struct ahc_softc *ahc)
5260 ahc_reset(ahc, /*reinit*/TRUE);
5261 ahc_intr_enable(ahc, TRUE);
5262 ahc_restart(ahc);
5272 ahc_index_busy_tcl(struct ahc_softc *ahc, u_int tcl)
5277 if ((ahc->flags & AHC_SCB_BTT) != 0) {
5280 saved_scbptr = ahc_inb(ahc, SCBPTR);
5281 ahc_outb(ahc, SCBPTR, TCL_LUN(tcl));
5282 scbid = ahc_inb(ahc, SCB_64_BTT + TCL_TARGET_OFFSET(tcl));
5283 ahc_outb(ahc, SCBPTR, saved_scbptr);
5286 scbid = ahc_inb(ahc, BUSY_TARGETS + target_offset);
5293 ahc_unbusy_tcl(struct ahc_softc *ahc, u_int tcl)
5297 if ((ahc->flags & AHC_SCB_BTT) != 0) {
5300 saved_scbptr = ahc_inb(ahc, SCBPTR);
5301 ahc_outb(ahc, SCBPTR, TCL_LUN(tcl));
5302 ahc_outb(ahc, SCB_64_BTT+TCL_TARGET_OFFSET(tcl), SCB_LIST_NULL);
5303 ahc_outb(ahc, SCBPTR, saved_scbptr);
5306 ahc_outb(ahc, BUSY_TARGETS + target_offset, SCB_LIST_NULL);
5311 ahc_busy_tcl(struct ahc_softc *ahc, u_int tcl, u_int scbid)
5315 if ((ahc->flags & AHC_SCB_BTT) != 0) {
5318 saved_scbptr = ahc_inb(ahc, SCBPTR);
5319 ahc_outb(ahc, SCBPTR, TCL_LUN(tcl));
5320 ahc_outb(ahc, SCB_64_BTT + TCL_TARGET_OFFSET(tcl), scbid);
5321 ahc_outb(ahc, SCBPTR, saved_scbptr);
5324 ahc_outb(ahc, BUSY_TARGETS + target_offset, scbid);
5330 ahc_match_scb(struct ahc_softc *ahc, struct scb *scb, int target,
5333 int targ = SCB_GET_TARGET(ahc, scb);
5334 char chan = SCB_GET_CHANNEL(ahc, scb);
5366 ahc_freeze_devq(struct ahc_softc *ahc, struct scb *scb)
5372 target = SCB_GET_TARGET(ahc, scb);
5374 channel = SCB_GET_CHANNEL(ahc, scb);
5376 ahc_search_qinfifo(ahc, target, channel, lun,
5380 ahc_platform_freeze_devq(ahc, scb);
5384 ahc_qinfifo_requeue_tail(struct ahc_softc *ahc, struct scb *scb)
5389 if (ahc_qinfifo_count(ahc) != 0) {
5393 prev_pos = ahc->qinfifonext - 1;
5394 prev_tag = ahc->qinfifo[prev_pos];
5395 prev_scb = ahc_lookup_scb(ahc, prev_tag);
5397 ahc_qinfifo_requeue(ahc, prev_scb, scb);
5398 if ((ahc->features & AHC_QUEUE_REGS) != 0) {
5399 ahc_outb(ahc, HNSCB_QOFF, ahc->qinfifonext);
5401 ahc_outb(ahc, KERNEL_QINPOS, ahc->qinfifonext);
5406 ahc_qinfifo_requeue(struct ahc_softc *ahc, struct scb *prev_scb,
5410 ahc_outb(ahc, NEXT_QUEUED_SCB, scb->hscb->tag);
5413 ahc_sync_scb(ahc, prev_scb,
5416 ahc->qinfifo[ahc->qinfifonext++] = scb->hscb->tag;
5417 scb->hscb->next = ahc->next_queued_scb->hscb->tag;
5418 ahc_sync_scb(ahc, scb, BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
5422 ahc_qinfifo_count(struct ahc_softc *ahc)
5427 if ((ahc->features & AHC_QUEUE_REGS) != 0) {
5428 qinpos = ahc_inb(ahc, SNSCB_QOFF);
5429 ahc_outb(ahc, SNSCB_QOFF, qinpos);
5431 qinpos = ahc_inb(ahc, QINPOS);
5432 diff = ahc->qinfifonext - qinpos;
5437 ahc_search_qinfifo(struct ahc_softc *ahc, int target, char channel,
5452 qintail = ahc->qinfifonext;
5453 have_qregs = (ahc->features & AHC_QUEUE_REGS) != 0;
5455 qinstart = ahc_inb(ahc, SNSCB_QOFF);
5456 ahc_outb(ahc, SNSCB_QOFF, qinstart);
5458 qinstart = ahc_inb(ahc, QINPOS);
5468 ahc_freeze_untagged_queues(ahc);
5475 ahc->qinfifonext = qinpos;
5476 ahc_outb(ahc, NEXT_QUEUED_SCB, ahc->next_queued_scb->hscb->tag);
5479 scb = ahc_lookup_scb(ahc, ahc->qinfifo[qinpos]);
5482 qinpos, ahc->qinfifo[qinpos]);
5486 if (ahc_match_scb(ahc, scb, target, channel, lun, tag, role)) {
5505 ahc_done(ahc, scb);
5512 ahc_qinfifo_requeue(ahc, prev_scb, scb);
5517 ahc_qinfifo_requeue(ahc, prev_scb, scb);
5523 if ((ahc->features & AHC_QUEUE_REGS) != 0) {
5524 ahc_outb(ahc, HNSCB_QOFF, ahc->qinfifonext);
5526 ahc_outb(ahc, KERNEL_QINPOS, ahc->qinfifonext);
5531 && (qinstart != ahc->qinfifonext)) {
5544 scb = ahc_lookup_scb(ahc, ahc->qinfifo[qinstart]);
5548 found, qinstart, ahc->qinfifonext);
5558 ahc->scb_data->scbindex[scb->hscb->tag] = NULL;
5559 ahc_swap_with_next_hscb(ahc, scb);
5561 ahc->qinfifo[qinstart] = scb->hscb->tag;
5564 ahc_outb(ahc, NEXT_QUEUED_SCB, scb->hscb->tag);
5567 qintail = ahc->qinfifonext - 1;
5568 scb = ahc_lookup_scb(ahc, ahc->qinfifo[qintail]);
5569 scb->hscb->next = ahc->next_queued_scb->hscb->tag;
5575 curscbptr = ahc_inb(ahc, SCBPTR);
5576 next = ahc_inb(ahc, WAITING_SCBH); /* Start at head of list. */
5582 ahc_outb(ahc, SCBPTR, next);
5583 scb_index = ahc_inb(ahc, SCB_TAG);
5584 if (scb_index >= ahc->scb_data->numscbs) {
5587 scb_index, ahc->scb_data->numscbs);
5588 ahc_dump_card_state(ahc);
5591 scb = ahc_lookup_scb(ahc, scb_index);
5597 if (ahc_match_scb(ahc, scb, target, channel,
5618 ahc_done(ahc, scb);
5622 next = ahc_rem_wscb(ahc, next, prev);
5626 next = ahc_inb(ahc, SCB_NEXT);
5632 next = ahc_inb(ahc, SCB_NEXT);
5635 ahc_outb(ahc, SCBPTR, curscbptr);
5637 found += ahc_search_untagged_queues(ahc, /*aic_io_ctx_t*/NULL, target,
5641 ahc_release_untagged_queues(ahc);
5646 ahc_search_untagged_queues(struct ahc_softc *ahc, aic_io_ctx_t ctx,
5660 ahc_freeze_untagged_queues(ahc);
5665 if ((ahc->flags & AHC_SCB_BTT) == 0) {
5683 untagged_q = &(ahc->untagged_queues[i]);
5702 if (ahc_match_scb(ahc, scb, target, channel, lun,
5723 ahc_done(ahc, scb);
5737 ahc_release_untagged_queues(ahc);
5742 ahc_search_disc_list(struct ahc_softc *ahc, int target, char channel,
5753 next = ahc_inb(ahc, DISCONNECTED_SCBH);
5758 active_scb = ahc_inb(ahc, SCBPTR);
5766 ahc_outb(ahc, SCBPTR, next);
5767 scb_index = ahc_inb(ahc, SCB_TAG);
5768 if (scb_index >= ahc->scb_data->numscbs) {
5771 scb_index, ahc->scb_data->numscbs);
5772 ahc_dump_card_state(ahc);
5781 scbp = ahc_lookup_scb(ahc, scb_index);
5782 if (ahc_match_scb(ahc, scbp, target, channel, lun,
5787 ahc_rem_scb_from_disc_list(ahc, prev, next);
5790 next = ahc_inb(ahc, SCB_NEXT);
5796 next = ahc_inb(ahc, SCB_NEXT);
5800 ahc_outb(ahc, SCBPTR, active_scb);
5809 ahc_rem_scb_from_disc_list(struct ahc_softc *ahc, u_int prev, u_int scbptr)
5813 ahc_outb(ahc, SCBPTR, scbptr);
5814 next = ahc_inb(ahc, SCB_NEXT);
5816 ahc_outb(ahc, SCB_CONTROL, 0);
5818 ahc_add_curscb_to_free_list(ahc);
5821 ahc_outb(ahc, SCBPTR, prev);
5822 ahc_outb(ahc, SCB_NEXT, next);
5824 ahc_outb(ahc, DISCONNECTED_SCBH, next);
5835 ahc_add_curscb_to_free_list(struct ahc_softc *ahc)
5841 ahc_outb(ahc, SCB_TAG, SCB_LIST_NULL);
5843 if ((ahc->flags & AHC_PAGESCBS) != 0) {
5844 ahc_outb(ahc, SCB_NEXT, ahc_inb(ahc, FREE_SCBH));
5845 ahc_outb(ahc, FREE_SCBH, ahc_inb(ahc, SCBPTR));
5854 ahc_rem_wscb(struct ahc_softc *ahc, u_int scbpos, u_int prev)
5862 curscb = ahc_inb(ahc, SCBPTR);
5863 ahc_outb(ahc, SCBPTR, scbpos);
5864 next = ahc_inb(ahc, SCB_NEXT);
5867 ahc_outb(ahc, SCB_CONTROL, 0);
5869 ahc_add_curscb_to_free_list(ahc);
5874 ahc_outb(ahc, WAITING_SCBH, next);
5880 ahc_outb(ahc, SCSISEQ, (ahc_inb(ahc, SCSISEQ) & ~ENSELO));
5886 ahc_outb(ahc, SCBPTR, prev);
5887 ahc_outb(ahc, SCB_NEXT, next);
5893 ahc_outb(ahc, SCBPTR, curscb);
5905 ahc_abort_scbs(struct ahc_softc *ahc, int target, char channel,
5922 ahc_freeze_untagged_queues(ahc);
5925 active_scb = ahc_inb(ahc, SCBPTR);
5927 found = ahc_search_qinfifo(ahc, target, channel, lun, SCB_LIST_NULL,
5952 if ((ahc->flags & AHC_SCB_BTT) != 0)
5966 scbid = ahc_index_busy_tcl(ahc, tcl);
5967 scbp = ahc_lookup_scb(ahc, scbid);
5969 || ahc_match_scb(ahc, scbp, target, channel,
5972 ahc_unbusy_tcl(ahc, BUILD_TCL(i << 4, j));
5982 ahc_search_disc_list(ahc, target, channel, lun, tag,
5994 for (i = 0; i < ahc->scb_data->maxhscbs; i++) {
5997 ahc_outb(ahc, SCBPTR, i);
5998 scbid = ahc_inb(ahc, SCB_TAG);
5999 scbp = ahc_lookup_scb(ahc, scbid);
6002 && ahc_match_scb(ahc, scbp, target, channel, lun, tag, role)))
6003 ahc_add_curscb_to_free_list(ahc);
6012 scbp_next = LIST_FIRST(&ahc->pending_scbs);
6016 if (ahc_match_scb(ahc, scbp, target, channel, lun, tag, role)) {
6026 ahc_done(ahc, scbp);
6030 ahc_outb(ahc, SCBPTR, active_scb);
6031 ahc_platform_abort_scbs(ahc, target, channel, lun, tag, role, status);
6032 ahc_release_untagged_queues(ahc);
6037 ahc_reset_current_bus(struct ahc_softc *ahc)
6041 ahc_outb(ahc, SIMODE1, ahc_inb(ahc, SIMODE1) & ~ENSCSIRST);
6042 scsiseq = ahc_inb(ahc, SCSISEQ);
6043 ahc_outb(ahc, SCSISEQ, scsiseq | SCSIRSTO);
6044 ahc_flush_device_writes(ahc);
6047 ahc_outb(ahc, SCSISEQ, scsiseq & ~SCSIRSTO);
6049 ahc_clear_intstat(ahc);
6052 ahc_outb(ahc, SIMODE1, ahc_inb(ahc, SIMODE1) | ENSCSIRST);
6056 ahc_reset_channel(struct ahc_softc *ahc, char channel, int initiate_reset)
6067 ahc->pending_device = NULL;
6074 ahc_pause(ahc);
6077 ahc_clear_critical_section(ahc);
6084 ahc_run_qoutfifo(ahc);
6096 if ((ahc->flags & AHC_TARGETROLE) != 0) {
6097 ahc_run_tqinfifo(ahc, /*paused*/TRUE);
6104 sblkctl = ahc_inb(ahc, SBLKCTL);
6106 if ((ahc->features & AHC_TWIN) != 0
6109 scsiseq = ahc_inb(ahc, SCSISEQ_TEMPLATE);
6115 ahc_outb(ahc, SBLKCTL, sblkctl ^ SELBUSB);
6116 simode1 = ahc_inb(ahc, SIMODE1) & ~(ENBUSFREE|ENSCSIRST);
6123 if ((ahc->flags & AHC_TARGETROLE) != 0)
6126 ahc_outb(ahc, SIMODE1, simode1);
6128 ahc_reset_current_bus(ahc);
6129 ahc_clear_intstat(ahc);
6130 ahc_outb(ahc, SCSISEQ, scsiseq & (ENSELI|ENRSELI|ENAUTOATNP));
6131 ahc_outb(ahc, SBLKCTL, sblkctl);
6135 simode1 = ahc_inb(ahc, SIMODE1) & ~(ENBUSFREE|ENSCSIRST);
6142 if ((ahc->flags & AHC_TARGETROLE) != 0)
6145 ahc_outb(ahc, SIMODE1, simode1);
6147 ahc_reset_current_bus(ahc);
6148 ahc_clear_intstat(ahc);
6149 ahc_outb(ahc, SCSISEQ, scsiseq & (ENSELI|ENRSELI|ENAUTOATNP));
6157 found = ahc_abort_scbs(ahc, CAM_TARGET_WILDCARD, channel,
6161 max_scsiid = (ahc->features & AHC_WIDE) ? 15 : 7;
6172 tstate = ahc->enabled_targets[target];
6182 ahc_queue_lstate_event(ahc, lstate, CAM_TARGET_WILDCARD,
6184 ahc_send_lstate_events(ahc, lstate);
6189 ahc_send_async(ahc, devinfo.channel, CAM_TARGET_WILDCARD,
6197 if (ahc->enabled_targets[target] == NULL)
6205 ahc_set_width(ahc, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
6207 ahc_set_syncrate(ahc, &devinfo, /*syncrate*/NULL,
6215 ahc_restart(ahc);
6217 ahc_unpause(ahc);
6227 ahc_calc_residual(struct ahc_softc *ahc, struct scb *scb)
6304 ahc_print_path(ahc, scb);
6317 ahc_queue_lstate_event(struct ahc_softc *ahc, struct ahc_tmode_lstate *lstate,
6368 ahc_send_lstate_events(struct ahc_softc *ahc, struct ahc_tmode_lstate *lstate)
6403 ahc_dumpseq(struct ahc_softc* ahc)
6407 ahc_outb(ahc, SEQCTL, PERRORDIS|FAILDIS|FASTMODE|LOADRAM);
6408 ahc_outb(ahc, SEQADDR0, 0);
6409 ahc_outb(ahc, SEQADDR1, 0);
6410 for (i = 0; i < ahc->instruction_ram_size; i++) {
6413 ahc_insb(ahc, SEQRAM, ins_bytes, 4);
6423 ahc_loadseq(struct ahc_softc *ahc)
6448 if (ahc->targetcmds != NULL)
6451 download_consts[CACHESIZE_MASK] = ahc->pci_cachesize - 1;
6452 download_consts[INVERTED_CACHESIZE_MASK] = ~(ahc->pci_cachesize - 1);
6453 sg_prefetch_cnt = ahc->pci_cachesize;
6463 ahc_outb(ahc, SEQCTL, PERRORDIS|FAILDIS|FASTMODE|LOADRAM);
6464 ahc_outb(ahc, SEQADDR0, 0);
6465 ahc_outb(ahc, SEQADDR1, 0);
6468 if (ahc_check_patch(ahc, &cur_patch, i, &skip_addr) == 0) {
6476 if (downloaded == ahc->instruction_ram_size) {
6483 "size of %d!\n", ahc_name(ahc),
6484 ahc->instruction_ram_size);
6509 ahc_download_instr(ahc, i, download_consts);
6513 ahc->num_critical_sections = cs_count;
6517 ahc->critical_sections = malloc(cs_count, M_DEVBUF, M_NOWAIT);
6518 if (ahc->critical_sections == NULL)
6520 memcpy(ahc->critical_sections, cs_table, cs_count);
6522 ahc_outb(ahc, SEQCTL, PERRORDIS|FAILDIS|FASTMODE);
6527 ahc_name(ahc), ahc->features, ahc->bugs, ahc->flags);
6533 ahc_check_patch(struct ahc_softc *ahc, struct patch **start_patch,
6546 if (cur_patch->patch_func(ahc) == 0) {
6569 ahc_download_instr(struct ahc_softc *ahc, u_int instrptr, uint8_t *dconsts)
6610 ahc_check_patch(ahc, &cur_patch, i, &skip_addr);
6636 if ((ahc->features & AHC_CMD_CHAN) == 0
6647 ahc_name(ahc));
6653 if ((ahc->features & AHC_ULTRA2) != 0) {
6685 ahc_outsb(ahc, SEQRAM, instr.bytes, 4);
6748 ahc_dump_card_state(struct ahc_softc *ahc)
6764 if (ahc_is_paused(ahc)) {
6768 ahc_pause(ahc);
6771 saved_scbptr = ahc_inb(ahc, SCBPTR);
6772 last_phase = ahc_inb(ahc, LASTPHASE);
6775 ahc_name(ahc), ahc_lookup_phase_entry(last_phase)->phasemsg,
6776 ahc_inb(ahc, SEQADDR0) | (ahc_inb(ahc, SEQADDR1) << 8));
6780 ahc_inb(ahc, ACCUM), ahc_inb(ahc, SINDEX), ahc_inb(ahc, DINDEX),
6781 ahc_inb(ahc, ARG_2));
6782 printf("HCNT = 0x%x SCBPTR = 0x%x\n", ahc_inb(ahc, HCNT),
6783 ahc_inb(ahc, SCBPTR));
6785 if ((ahc->features & AHC_DT) != 0)
6786 ahc_scsiphase_print(ahc_inb(ahc, SCSIPHASE), &cur_col, 50);
6787 ahc_scsisigi_print(ahc_inb(ahc, SCSISIGI), &cur_col, 50);
6788 ahc_error_print(ahc_inb(ahc, ERROR), &cur_col, 50);
6789 ahc_scsibusl_print(ahc_inb(ahc, SCSIBUSL), &cur_col, 50);
6790 ahc_lastphase_print(ahc_inb(ahc, LASTPHASE), &cur_col, 50);
6791 ahc_scsiseq_print(ahc_inb(ahc, SCSISEQ), &cur_col, 50);
6792 ahc_sblkctl_print(ahc_inb(ahc, SBLKCTL), &cur_col, 50);
6793 ahc_scsirate_print(ahc_inb(ahc, SCSIRATE), &cur_col, 50);
6794 ahc_seqctl_print(ahc_inb(ahc, SEQCTL), &cur_col, 50);
6795 ahc_seq_flags_print(ahc_inb(ahc, SEQ_FLAGS), &cur_col, 50);
6796 ahc_sstat0_print(ahc_inb(ahc, SSTAT0), &cur_col, 50);
6797 ahc_sstat1_print(ahc_inb(ahc, SSTAT1), &cur_col, 50);
6798 ahc_sstat2_print(ahc_inb(ahc, SSTAT2), &cur_col, 50);
6799 ahc_sstat3_print(ahc_inb(ahc, SSTAT3), &cur_col, 50);
6800 ahc_simode0_print(ahc_inb(ahc, SIMODE0), &cur_col, 50);
6801 ahc_simode1_print(ahc_inb(ahc, SIMODE1), &cur_col, 50);
6802 ahc_sxfrctl0_print(ahc_inb(ahc, SXFRCTL0), &cur_col, 50);
6803 ahc_dfcntrl_print(ahc_inb(ahc, DFCNTRL), &cur_col, 50);
6804 ahc_dfstatus_print(ahc_inb(ahc, DFSTATUS), &cur_col, 50);
6809 printf(" 0x%x", ahc_inb(ahc, STACK)|(ahc_inb(ahc, STACK) << 8));
6810 printf("\nSCB count = %d\n", ahc->scb_data->numscbs);
6811 printf("Kernel NEXTQSCB = %d\n", ahc->next_queued_scb->hscb->tag);
6812 printf("Card NEXTQSCB = %d\n", ahc_inb(ahc, NEXT_QUEUED_SCB));
6815 if ((ahc->features & AHC_QUEUE_REGS) != 0) {
6816 qinpos = ahc_inb(ahc, SNSCB_QOFF);
6817 ahc_outb(ahc, SNSCB_QOFF, qinpos);
6819 qinpos = ahc_inb(ahc, QINPOS);
6820 qintail = ahc->qinfifonext;
6822 printf("%d ", ahc->qinfifo[qinpos]);
6828 scb_index = ahc_inb(ahc, WAITING_SCBH);
6831 ahc_outb(ahc, SCBPTR, scb_index);
6832 printf("%d:%d ", scb_index, ahc_inb(ahc, SCB_TAG));
6833 scb_index = ahc_inb(ahc, SCB_NEXT);
6838 scb_index = ahc_inb(ahc, DISCONNECTED_SCBH);
6841 ahc_outb(ahc, SCBPTR, scb_index);
6842 printf("%d:%d ", scb_index, ahc_inb(ahc, SCB_TAG));
6843 scb_index = ahc_inb(ahc, SCB_NEXT);
6847 ahc_sync_qoutfifo(ahc, BUS_DMASYNC_POSTREAD);
6849 qoutpos = ahc->qoutfifonext;
6851 while (ahc->qoutfifo[qoutpos] != SCB_LIST_NULL && i++ < 256) {
6852 printf("%d ", ahc->qoutfifo[qoutpos]);
6858 scb_index = ahc_inb(ahc, FREE_SCBH);
6861 ahc_outb(ahc, SCBPTR, scb_index);
6863 scb_index = ahc_inb(ahc, SCB_NEXT);
6868 for (i = 0; i < ahc->scb_data->maxhscbs; i++) {
6869 ahc_outb(ahc, SCBPTR, i);
6872 ahc_scb_control_print(ahc_inb(ahc, SCB_CONTROL), &cur_col, 60);
6873 ahc_scb_scsiid_print(ahc_inb(ahc, SCB_SCSIID), &cur_col, 60);
6874 ahc_scb_lun_print(ahc_inb(ahc, SCB_LUN), &cur_col, 60);
6875 ahc_scb_tag_print(ahc_inb(ahc, SCB_TAG), &cur_col, 60);
6881 LIST_FOREACH(scb, &ahc->pending_scbs, pending_links) {
6888 if ((ahc->flags & AHC_PAGESCBS) == 0) {
6889 ahc_outb(ahc, SCBPTR, scb->hscb->tag);
6891 ahc_scb_control_print(ahc_inb(ahc, SCB_CONTROL),
6893 ahc_scb_tag_print(ahc_inb(ahc, SCB_TAG), &cur_col, 60);
6901 SLIST_FOREACH(scb, &ahc->scb_data->free_scbs, links.sle) {
6908 maxtarget = (ahc->features & (AHC_WIDE|AHC_TWIN)) ? 15 : 7;
6910 untagged_q = &ahc->untagged_queues[target];
6923 ahc_platform_dump_card_state(ahc);
6925 ahc_outb(ahc, SCBPTR, saved_scbptr);
6927 ahc_unpause(ahc);
6934 struct ahc_softc *ahc;
6936 ahc = scb->ahc_softc;
6939 LIST_INSERT_HEAD(&ahc->timedout_scbs, scb,
6943 ahc_wakeup_recovery_thread(ahc);
6954 ahc_other_scb_timeout(struct ahc_softc *ahc, struct scb *scb,
6960 ahc_print_path(ahc, scb);
6977 LIST_FOREACH(other_scb, &ahc->pending_scbs, pending_links) {
6992 ahc_print_path(ahc, scb);
7007 ahc_recover_commands(struct ahc_softc *ahc)
7019 ahc_pause_and_flushwork(ahc);
7021 if (LIST_EMPTY(&ahc->timedout_scbs) != 0) {
7031 "Interrupts may not be functioning.\n", ahc_name(ahc));
7032 ahc_unpause(ahc);
7037 printf("%s: Recovery Initiated\n", ahc_name(ahc));
7038 ahc_dump_card_state(ahc);
7040 last_phase = ahc_inb(ahc, LASTPHASE);
7041 while ((scb = LIST_FIRST(&ahc->timedout_scbs)) != NULL) {
7049 target = SCB_GET_TARGET(ahc, scb);
7050 channel = SCB_GET_CHANNEL(ahc, scb);
7053 ahc_print_path(ahc, scb);
7070 found = ahc_reset_channel(ahc, channel,
7073 "%d SCBs aborted\n", ahc_name(ahc), channel,
7107 saved_scbptr = ahc_inb(ahc, SCBPTR);
7108 active_scb_index = ahc_inb(ahc, SCB_TAG);
7110 if ((ahc_inb(ahc, SEQ_FLAGS) & NOT_IDENTIFIED) == 0
7111 && (active_scb_index < ahc->scb_data->numscbs)) {
7120 active_scb = ahc_lookup_scb(ahc, active_scb_index);
7122 if (ahc_other_scb_timeout(ahc, scb,
7135 ahc_abort_scbs(ahc, SCB_GET_TARGET(ahc, scb),
7136 SCB_GET_CHANNEL(ahc, scb),
7147 ahc_set_recoveryscb(ahc, active_scb);
7148 ahc_outb(ahc, MSG_OUT, HOST_MSG);
7149 ahc_outb(ahc, SCSISIGO, last_phase|ATNO);
7150 ahc_print_path(ahc, active_scb);
7155 && (ahc_inb(ahc, SSTAT1) & REQINIT) == 0) {
7164 "Identify Msg.\n", ahc_name(ahc));
7170 && (ahc_inb(ahc, SSTAT0) & TARGET) != 0) {
7173 ahc_name(ahc));
7182 if (ahc_search_qinfifo(ahc, target, channel, lun,
7192 ahc_set_recoveryscb(ahc, scb);
7219 ahc_search_disc_list(ahc, target, channel,
7232 if ((ahc->flags & AHC_PAGESCBS) == 0) {
7233 ahc_outb(ahc, SCBPTR, scb->hscb->tag);
7234 ahc_outb(ahc, SCB_CONTROL,
7235 ahc_inb(ahc, SCB_CONTROL)
7244 ahc_search_qinfifo(ahc,
7245 SCB_GET_TARGET(ahc, scb),
7251 ahc_print_path(ahc, scb);
7253 ahc_qinfifo_requeue_tail(ahc, scb);
7254 ahc_outb(ahc, SCBPTR, saved_scbptr);
7259 ahc_set_recoveryscb(ahc, scb);
7260 ahc_print_path(ahc, scb);
7275 while ((scb = LIST_FIRST(&ahc->timedout_scbs)) != NULL) {
7282 ahc_restart(ahc);
7284 ahc_unpause(ahc);
7290 ahc_find_tmode_devs(struct ahc_softc *ahc, struct cam_sim *sim, union ccb *ccb,
7296 if ((ahc->features & AHC_TARGETMODE) == 0)
7306 *lstate = ahc->black_hole;
7310 max_id = (ahc->features & AHC_WIDE) ? 15 : 7;
7317 *tstate = ahc->enabled_targets[ccb->ccb_h.target_id];
7331 ahc_handle_en_lun(struct ahc_softc *ahc, struct cam_sim *sim, union ccb *ccb)
7344 status = ahc_find_tmode_devs(ahc, sim, ccb, &tstate, &lstate,
7353 our_id = ahc->our_id;
7355 our_id = ahc->our_id_b;
7377 if ((ahc->features & AHC_MULTIROLE) != 0) {
7379 if ((ahc->features & AHC_MULTI_TID) != 0
7380 && (ahc->flags & AHC_INITIATORROLE) != 0) {
7389 } else if ((ahc->flags & AHC_INITIATORROLE) != 0
7390 || ahc->enabled_luns > 0) {
7400 } else if ((ahc->features & AHC_MULTI_TID) == 0
7401 && ahc->enabled_luns > 0) {
7416 if ((ahc->flags & AHC_TARGETROLE) == 0
7421 if (LIST_FIRST(&ahc->pending_scbs) != NULL) {
7425 saved_flags = ahc->flags;
7426 ahc->flags |= AHC_TARGETROLE;
7427 if ((ahc->features & AHC_MULTIROLE) == 0)
7428 ahc->flags &= ~AHC_INITIATORROLE;
7429 ahc_pause(ahc);
7430 error = ahc_loadseq(ahc);
7440 ahc->flags = saved_flags;
7441 (void)ahc_loadseq(ahc);
7442 ahc_restart(ahc);
7446 ahc_restart(ahc);
7451 channel = SIM_CHANNEL(ahc, sim);
7483 tstate = ahc_alloc_tstate(ahc, target, channel);
7512 ahc_pause(ahc);
7515 ahc->enabled_luns++;
7517 if ((ahc->features & AHC_MULTI_TID) != 0) {
7520 targid_mask = ahc_inb(ahc, TARGID)
7521 | (ahc_inb(ahc, TARGID + 1) << 8);
7524 ahc_outb(ahc, TARGID, targid_mask);
7525 ahc_outb(ahc, TARGID+1, (targid_mask >> 8));
7527 ahc_update_scsiid(ahc, targid_mask);
7532 channel = SIM_CHANNEL(ahc, sim);
7533 our_id = SIM_SCSI_ID(ahc, sim);
7544 sblkctl = ahc_inb(ahc, SBLKCTL);
7547 if ((ahc->features & AHC_TWIN) == 0)
7551 ahc->our_id = target;
7553 ahc->our_id_b = target;
7556 ahc_outb(ahc, SBLKCTL,
7559 ahc_outb(ahc, SCSIID, target);
7562 ahc_outb(ahc, SBLKCTL, sblkctl);
7566 ahc->black_hole = lstate;
7568 if (ahc->black_hole != NULL && ahc->enabled_luns > 0) {
7569 scsiseq = ahc_inb(ahc, SCSISEQ_TEMPLATE);
7571 ahc_outb(ahc, SCSISEQ_TEMPLATE, scsiseq);
7572 scsiseq = ahc_inb(ahc, SCSISEQ);
7574 ahc_outb(ahc, SCSISEQ, scsiseq);
7576 ahc_unpause(ahc);
7590 LIST_FOREACH(scb, &ahc->pending_scbs, pending_links) {
7621 ahc_pause(ahc);
7625 ahc->enabled_luns--;
7633 ahc_free_tstate(ahc, target, channel,
7635 if (ahc->features & AHC_MULTI_TID) {
7638 targid_mask = ahc_inb(ahc, TARGID)
7639 | (ahc_inb(ahc, TARGID + 1)
7643 ahc_outb(ahc, TARGID, targid_mask);
7644 ahc_outb(ahc, TARGID+1,
7646 ahc_update_scsiid(ahc, targid_mask);
7651 ahc->black_hole = NULL;
7659 if (ahc->enabled_luns == 0) {
7663 scsiseq = ahc_inb(ahc, SCSISEQ_TEMPLATE);
7665 ahc_outb(ahc, SCSISEQ_TEMPLATE, scsiseq);
7666 scsiseq = ahc_inb(ahc, SCSISEQ);
7668 ahc_outb(ahc, SCSISEQ, scsiseq);
7670 if ((ahc->features & AHC_MULTIROLE) == 0) {
7672 ahc->flags &= ~AHC_TARGETROLE;
7673 ahc->flags |= AHC_INITIATORROLE;
7678 (void)ahc_loadseq(ahc);
7679 ahc_restart(ahc);
7686 ahc_unpause(ahc);
7691 ahc_update_scsiid(struct ahc_softc *ahc, u_int targid_mask)
7696 if ((ahc->features & AHC_MULTI_TID) == 0)
7705 if ((ahc->features & AHC_ULTRA2) != 0)
7706 scsiid = ahc_inb(ahc, SCSIID_ULTRA2);
7708 scsiid = ahc_inb(ahc, SCSIID);
7716 our_id = ahc->our_id;
7722 if ((ahc->features & AHC_ULTRA2) != 0)
7723 ahc_outb(ahc, SCSIID_ULTRA2, scsiid);
7725 ahc_outb(ahc, SCSIID, scsiid);
7729 ahc_run_tqinfifo(struct ahc_softc *ahc, int paused)
7738 if ((ahc->features & AHC_AUTOPAUSE) != 0)
7741 ahc_sync_tqinfifo(ahc, BUS_DMASYNC_POSTREAD);
7742 while ((cmd = &ahc->targetcmds[ahc->tqinfifonext])->cmd_valid != 0) {
7748 if (ahc_handle_target_cmd(ahc, cmd) != 0)
7752 aic_dmamap_sync(ahc, ahc->shared_data_dmat,
7753 ahc->shared_data_dmamap,
7754 ahc_targetcmd_offset(ahc, ahc->tqinfifonext),
7757 ahc->tqinfifonext++;
7763 if ((ahc->tqinfifonext & (HOST_TQINPOS - 1)) == 1) {
7764 if ((ahc->features & AHC_HS_MAILBOX) != 0) {
7767 hs_mailbox = ahc_inb(ahc, HS_MAILBOX);
7769 hs_mailbox |= ahc->tqinfifonext & HOST_TQINPOS;
7770 ahc_outb(ahc, HS_MAILBOX, hs_mailbox);
7773 ahc_pause(ahc);
7774 ahc_outb(ahc, KERNEL_TQINPOS,
7775 ahc->tqinfifonext & HOST_TQINPOS);
7777 ahc_unpause(ahc);
7784 ahc_handle_target_cmd(struct ahc_softc *ahc, struct target_cmd *cmd)
7794 initiator = SCSIID_TARGET(ahc, cmd->scsiid);
7799 tstate = ahc->enabled_targets[target];
7808 lstate = ahc->black_hole;
7812 ahc->flags |= AHC_TQINFIFO_BLOCKED;
7817 printf("%s: ATIOs exhausted\n", ahc_name(ahc));
7820 ahc->flags &= ~AHC_TQINFIFO_BLOCKED;
7825 lstate == ahc->black_hole ? "(Black Holed)" : "");
7830 if (lstate == ahc->black_hole) {
7889 initiator, target, lun, ahc->pending_device);
7892 ahc->pending_device = lstate;