Lines Matching refs:ahc
150 static void ahc_force_renegotiation(struct ahc_softc *ahc);
152 ahc_alloc_tstate(struct ahc_softc *ahc,
155 static void ahc_free_tstate(struct ahc_softc *ahc,
159 ahc_devlimited_syncrate(struct ahc_softc *ahc,
164 static void ahc_update_pending_scbs(struct ahc_softc *ahc);
165 static void ahc_fetch_devinfo(struct ahc_softc *ahc,
167 static void ahc_scb_devinfo(struct ahc_softc *ahc,
170 static void ahc_assert_atn(struct ahc_softc *ahc);
171 static void ahc_setup_initiator_msgout(struct ahc_softc *ahc,
174 static void ahc_build_transfer_msg(struct ahc_softc *ahc,
176 static void ahc_construct_sdtr(struct ahc_softc *ahc,
179 static void ahc_construct_wdtr(struct ahc_softc *ahc,
182 static void ahc_construct_ppr(struct ahc_softc *ahc,
186 static void ahc_clear_msg_state(struct ahc_softc *ahc);
187 static void ahc_handle_proto_violation(struct ahc_softc *ahc);
188 static void ahc_handle_message_phase(struct ahc_softc *ahc);
194 static int ahc_sent_msg(struct ahc_softc *ahc, ahc_msgtype type,
196 static int ahc_parse_msg(struct ahc_softc *ahc,
198 static int ahc_handle_msg_reject(struct ahc_softc *ahc,
200 static void ahc_handle_ign_wide_residue(struct ahc_softc *ahc,
202 static void ahc_reinitialize_dataptrs(struct ahc_softc *ahc);
203 static void ahc_handle_devreset(struct ahc_softc *ahc,
209 static void ahc_setup_target_msgin(struct ahc_softc *ahc,
217 static void ahc_build_free_scb_list(struct ahc_softc *ahc);
218 static int ahc_init_scbdata(struct ahc_softc *ahc);
219 static void ahc_fini_scbdata(struct ahc_softc *ahc);
220 static void ahc_qinfifo_requeue(struct ahc_softc *ahc,
223 static int ahc_qinfifo_count(struct ahc_softc *ahc);
224 static u_int ahc_rem_scb_from_disc_list(struct ahc_softc *ahc,
226 static void ahc_add_curscb_to_free_list(struct ahc_softc *ahc);
227 static u_int ahc_rem_wscb(struct ahc_softc *ahc,
229 static void ahc_reset_current_bus(struct ahc_softc *ahc);
231 static void ahc_dumpseq(struct ahc_softc *ahc);
233 static void ahc_loadseq(struct ahc_softc *ahc);
234 static int ahc_check_patch(struct ahc_softc *ahc,
237 static void ahc_download_instr(struct ahc_softc *ahc,
240 static void ahc_queue_lstate_event(struct ahc_softc *ahc,
245 static void ahc_update_scsiid(struct ahc_softc *ahc,
247 static int ahc_handle_target_cmd(struct ahc_softc *ahc,
273 ahc_restart(struct ahc_softc *ahc)
276 ahc_pause(ahc);
279 ahc_clear_msg_state(ahc);
281 ahc_outb(ahc, SCSISIGO, 0); /* De-assert BSY */
282 ahc_outb(ahc, MSG_OUT, MSG_NOOP); /* No message to send */
283 ahc_outb(ahc, SXFRCTL1, ahc_inb(ahc, SXFRCTL1) & ~BITBUCKET);
284 ahc_outb(ahc, LASTPHASE, P_BUSFREE);
285 ahc_outb(ahc, SAVED_SCSIID, 0xFF);
286 ahc_outb(ahc, SAVED_LUN, 0xFF);
295 ahc_outb(ahc, TQINPOS, ahc->tqinfifonext);
298 ahc_outb(ahc, SCSISEQ,
299 ahc_inb(ahc, SCSISEQ_TEMPLATE) & (ENSELI|ENRSELI|ENAUTOATNP));
300 if ((ahc->features & AHC_CMD_CHAN) != 0) {
302 ahc_outb(ahc, CCSCBCNT, 0);
303 ahc_outb(ahc, CCSGCTL, 0);
304 ahc_outb(ahc, CCSCBCTL, 0);
311 if ((ahc_inb(ahc, SEQ_FLAGS2) & SCB_DMA) != 0) {
312 ahc_add_curscb_to_free_list(ahc);
313 ahc_outb(ahc, SEQ_FLAGS2,
314 ahc_inb(ahc, SEQ_FLAGS2) & ~SCB_DMA);
316 ahc_outb(ahc, MWI_RESIDUAL, 0);
317 ahc_outb(ahc, SEQCTL, FASTMODE);
318 ahc_outb(ahc, SEQADDR0, 0);
319 ahc_outb(ahc, SEQADDR1, 0);
320 ahc_unpause(ahc);
325 ahc_run_qoutfifo(struct ahc_softc *ahc)
330 ahc_sync_qoutfifo(ahc, BUS_DMASYNC_POSTREAD);
331 while (ahc->qoutfifo[ahc->qoutfifonext] != SCB_LIST_NULL) {
333 scb_index = ahc->qoutfifo[ahc->qoutfifonext];
334 if ((ahc->qoutfifonext & 0x03) == 0x03) {
344 modnext = ahc->qoutfifonext & ~0x3;
345 *((uint32_t *)(&ahc->qoutfifo[modnext])) = 0xFFFFFFFFUL;
346 ahc_dmamap_sync(ahc,
347 ahc->parent_dmat /*shared_data_dmat*/,
348 ahc->shared_data_dmamap,
352 ahc->qoutfifonext++;
354 scb = ahc_lookup_scb(ahc, scb_index);
358 ahc_name(ahc), scb_index,
359 (ahc->qoutfifonext - 1) & 0xFF);
367 ahc_update_residual(ahc, scb);
368 ahc_done(ahc, scb);
373 ahc_run_untagged_queues(struct ahc_softc *ahc)
378 ahc_run_untagged_queue(ahc, &ahc->untagged_queues[i]);
382 ahc_run_untagged_queue(struct ahc_softc *ahc, struct scb_tailq *queue)
386 if (ahc->untagged_queue_lock != 0)
392 ahc_queue_scb(ahc, scb);
398 ahc_handle_brkadrint(struct ahc_softc *ahc)
407 error = ahc_inb(ahc, ERROR);
411 ahc_name(ahc), ahc_hard_errors[i].errmesg,
412 ahc_inb(ahc, SEQADDR0) |
413 (ahc_inb(ahc, SEQADDR1) << 8));
415 ahc_dump_card_state(ahc);
418 ahc_abort_scbs(ahc, CAM_TARGET_WILDCARD, ALL_CHANNELS,
423 ahc_shutdown(ahc);
427 ahc_handle_seqint(struct ahc_softc *ahc, u_int intstat)
432 ahc_fetch_devinfo(ahc, &devinfo);
440 ahc_outb(ahc, CLRINT, CLRSEQINT);
452 ahc_outb(ahc, RETURN_1, 0);
463 scb_index = ahc_inb(ahc, SCB_TAG);
464 scb = ahc_lookup_scb(ahc, scb_index);
466 ahc_print_devinfo(ahc, &devinfo);
470 ahc_dump_card_state(ahc);
488 ahc_freeze_devq(ahc, scb);
494 ahc_name(ahc));
507 ahc_print_path(ahc, scb);
516 targ_info = ahc_fetch_transinfo(ahc
528 ahc_update_residual(ahc, scb);
531 ahc_print_path(ahc, scb);
535 sg->addr = ahc_htole32(ahc_get_sense_bufaddr(ahc, scb));
536 len = ahc_get_sense_bufsize(ahc, scb);
565 ahc_update_neg_request(ahc, &devinfo,
581 ahc_qinfifo_requeue_tail(ahc, scb);
582 ahc_outb(ahc, RETURN_1, SEND_SENSE);
598 ahc_outb(ahc, SCSISEQ,
599 ahc_inb(ahc, SCSISEQ) & (ENSELI|ENRSELI|ENAUTOATNP));
603 ahc_name(ahc), devinfo.channel, devinfo.target);
606 ahc_inb(ahc, SAVED_SCSIID), ahc_inb(ahc, SAVED_LUN),
607 ahc_inb(ahc, ARG_1), ahc_inb(ahc, ACCUM));
610 ahc_inb(ahc, SEQ_FLAGS), ahc_inb(ahc, SCBPTR),
611 ahc_index_busy_tcl(ahc,
612 BUILD_TCL(ahc_inb(ahc, SAVED_SCSIID),
613 ahc_inb(ahc, SAVED_LUN))),
614 ahc_inb(ahc, SINDEX));
617 ahc_inb(ahc, SCSIID), ahc_inb(ahc, SCB_SCSIID),
618 ahc_inb(ahc, SCB_LUN), ahc_inb(ahc, SCB_TAG),
619 ahc_inb(ahc, SCB_CONTROL));
621 ahc_inb(ahc, SCSIBUSL), ahc_inb(ahc, SCSISIGI));
622 printf("SXFRCTL0 == 0x%x\n", ahc_inb(ahc, SXFRCTL0));
623 printf("SEQCTL == 0x%x\n", ahc_inb(ahc, SEQCTL));
624 ahc_dump_card_state(ahc);
625 ahc->msgout_buf[0] = MSG_BUS_DEV_RESET;
626 ahc->msgout_len = 1;
627 ahc->msgout_index = 0;
628 ahc->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
629 ahc_outb(ahc, MSG_OUT, HOST_MSG);
630 ahc_assert_atn(ahc);
635 u_int rejbyte = ahc_inb(ahc, ACCUM);
638 ahc_name(ahc), devinfo.channel, devinfo.target, rejbyte);
643 ahc_handle_proto_violation(ahc);
647 ahc_handle_ign_wide_residue(ahc, &devinfo);
650 ahc_reinitialize_dataptrs(ahc);
656 lastphase = ahc_inb(ahc, LASTPHASE);
659 ahc_name(ahc), devinfo.channel, devinfo.target,
660 lastphase, ahc_inb(ahc, SCSISIGI));
667 lastphase = ahc_inb(ahc, LASTPHASE);
670 ahc_name(ahc), devinfo.channel, devinfo.target,
671 lastphase, ahc_inb(ahc, SCSISIGI));
672 ahc_restart(ahc);
688 if (ahc->msg_type == MSG_TYPE_NONE) {
693 bus_phase = ahc_inb(ahc, SCSISIGI) & PHASE_MASK;
703 ahc_clear_intstat(ahc);
704 ahc_restart(ahc);
708 scb_index = ahc_inb(ahc, SCB_TAG);
709 scb1 = ahc_lookup_scb(ahc, scb_index);
716 ahc_setup_initiator_msgout(ahc,
720 ahc->msg_type =
722 ahc->msgin_index = 0;
728 ahc->msg_type =
730 ahc->msgin_index = 0;
733 ahc_setup_target_msgin(ahc,
740 ahc_handle_message_phase(ahc);
757 && (ahc_inb(ahc, SSTAT1) & SCSIPERR) != 0) {
759 if ((ahc->features & AHC_DT) == 0) {
768 curphase = ahc_inb(ahc, SCSISIGI) & PHASE_MASK;
769 ahc_outb(ahc, LASTPHASE, curphase);
770 ahc_outb(ahc, SCSISIGO, curphase);
772 if ((ahc_inb(ahc, SCSISIGI) & (CDI|MSGI)) == 0) {
781 ahc_outb(ahc, SXFRCTL1,
782 ahc_inb(ahc, SXFRCTL1) | BITBUCKET);
785 if ((ahc_inb(ahc, SCSISIGI)
790 ahc_outb(ahc, SXFRCTL1,
791 ahc_inb(ahc, SXFRCTL1) & ~BITBUCKET);
796 ahc_print_devinfo(ahc, &devinfo);
799 scb_index = ahc_inb(ahc, SCB_TAG);
800 scb1 = ahc_lookup_scb(ahc, scb_index);
804 ahc_reset_channel(ahc, devinfo.channel,
808 (void)ahc_inb(ahc, SCSIDATL);
823 u_int scbindex = ahc_inb(ahc, SCB_TAG);
824 u_int lastphase = ahc_inb(ahc, LASTPHASE);
827 scb = ahc_lookup_scb(ahc, scbindex);
832 ahc_print_path(ahc, scb);
837 ahc_print_path(ahc, scb);
839 ahc_inb(ahc, SEQ_FLAGS) & DPHASE ? "Have" : "Haven't",
857 ahc_freeze_devq(ahc, scb);
866 if ((ahc->features & AHC_ULTRA2) != 0) {
871 ahc_outb(ahc, SXFRCTL0,
872 ahc_inb(ahc, SXFRCTL0) | CLRSTCNT|CLRCHN);
873 ahc_outb(ahc, SXFRCTL0,
874 ahc_inb(ahc, SXFRCTL0) | CLRSTCNT|CLRCHN);
876 if ((ahc->flags & AHC_39BIT_ADDRESSING) != 0) {
880 dscommand1 = ahc_inb(ahc, DSCOMMAND1);
881 ahc_outb(ahc, DSCOMMAND1, dscommand1 | HADDLDSEL0);
882 ahc_outb(ahc, HADDR, 0);
883 ahc_outb(ahc, DSCOMMAND1, dscommand1);
892 ahc_name(ahc), devinfo.channel, devinfo.target,
894 scbindex = ahc_inb(ahc, SCB_TAG);
895 scb = ahc_lookup_scb(ahc, scbindex);
902 ahc_search_qinfifo(ahc, SCB_GET_TARGET(ahc, scb),
903 SCB_GET_CHANNEL(ahc, scb),
911 printf("%s: No free or disconnected SCBs\n", ahc_name(ahc));
912 ahc_dump_card_state(ahc);
920 scbptr = ahc_inb(ahc, SCBPTR);
922 scbptr, ahc_inb(ahc, ARG_1),
923 ahc->scb_data->hscbs[scbptr].tag);
924 ahc_dump_card_state(ahc);
930 printf("%s: BTT calculation out of range\n", ahc_name(ahc));
933 ahc_inb(ahc, SAVED_SCSIID), ahc_inb(ahc, SAVED_LUN),
934 ahc_inb(ahc, ARG_1), ahc_inb(ahc, ACCUM));
937 ahc_inb(ahc, SEQ_FLAGS), ahc_inb(ahc, SCBPTR),
938 ahc_index_busy_tcl(ahc,
939 BUILD_TCL(ahc_inb(ahc, SAVED_SCSIID),
940 ahc_inb(ahc, SAVED_LUN))),
941 ahc_inb(ahc, SINDEX),
942 ahc_inb(ahc, ACCUM));
945 ahc_inb(ahc, SCSIID), ahc_inb(ahc, SCB_SCSIID),
946 ahc_inb(ahc, SCB_LUN), ahc_inb(ahc, SCB_TAG),
947 ahc_inb(ahc, SCB_CONTROL));
949 ahc_inb(ahc, SCSIBUSL), ahc_inb(ahc, SCSISIGI));
950 ahc_dump_card_state(ahc);
957 intstat, ahc_inb(ahc, SCSISIGI));
966 ahc_unpause(ahc);
970 ahc_handle_scsiint(struct ahc_softc *ahc, u_int intstat)
979 if ((ahc->features & AHC_TWIN) != 0
980 && ((ahc_inb(ahc, SBLKCTL) & SELBUSB) != 0))
986 if ((ahc->features & AHC_ULTRA2) != 0)
987 status0 = ahc_inb(ahc, SSTAT0) & IOERR;
990 status = ahc_inb(ahc, SSTAT1) & (SELTO|SCSIRSTI|BUSFREE|SCSIPERR);
992 if ((ahc->features & AHC_TWIN) != 0) {
994 ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) ^ SELBUSB);
995 status = ahc_inb(ahc, SSTAT1)
1000 printf("%s: Spurious SCSI interrupt\n", ahc_name(ahc));
1001 ahc_outb(ahc, CLRINT, CLRSCSIINT);
1002 ahc_unpause(ahc);
1008 ahc_clear_critical_section(ahc);
1010 scb_index = ahc_inb(ahc, SCB_TAG);
1011 scb = ahc_lookup_scb(ahc, scb_index);
1013 && (ahc_inb(ahc, SEQ_FLAGS) & NOT_IDENTIFIED) != 0)
1016 if ((ahc->features & AHC_ULTRA2) != 0
1020 now_lvd = ahc_inb(ahc, SBLKCTL) & ENAB40;
1022 ahc_name(ahc), now_lvd ? "LVD" : "SE");
1023 ahc_outb(ahc, CLRSINT0, CLRIOERR);
1034 ahc_reset_channel(ahc, intr_channel,
1038 ahc_name(ahc), intr_channel);
1040 ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) ^ SELBUSB);
1041 ahc_reset_channel(ahc, intr_channel, /*Initiate Reset*/FALSE);
1062 lastphase = ahc_inb(ahc, LASTPHASE);
1063 curphase = ahc_inb(ahc, SCSISIGI) & PHASE_MASK;
1064 sstat2 = ahc_inb(ahc, SSTAT2);
1065 ahc_outb(ahc, CLRSINT1, CLRSCSIPERR);
1077 if ((ahc_inb(ahc, SSTAT1) & SCSIPERR) != 0
1093 ahc_print_path(ahc, scb);
1096 printf("%s:%c:%d: ", ahc_name(ahc), intr_channel,
1097 SCSIID_TARGET(ahc, ahc_inb(ahc, SAVED_SCSIID)));
1098 scsirate = ahc_inb(ahc, SCSIRATE);
1103 ahc_inw(ahc, SEQADDR0),
1105 if ((ahc->features & AHC_DT) != 0) {
1121 if ((ahc->features & AHC_DT) != 0
1139 if (ahc->msg_type != MSG_TYPE_NONE)
1140 ahc->send_msg_perror = TRUE;
1142 ahc_outb(ahc, MSG_OUT, mesg_out);
1149 ahc_force_renegotiation(ahc);
1150 ahc_outb(ahc, CLRINT, CLRSCSIINT);
1151 ahc_unpause(ahc);
1156 ahc_outb(ahc, SCSISEQ, 0);
1159 ahc_clear_msg_state(ahc);
1162 ahc_outb(ahc, SIMODE1, ahc_inb(ahc, SIMODE1) & ~ENBUSFREE);
1163 ahc_outb(ahc, CLRSINT1, CLRSELTIMEO|CLRBUSFREE|CLRSCSIPERR);
1173 ahc_outb(ahc, CLRSINT0, CLRSELINGO);
1175 scbptr = ahc_inb(ahc, WAITING_SCBH);
1176 ahc_outb(ahc, SCBPTR, scbptr);
1177 scb_index = ahc_inb(ahc, SCB_TAG);
1179 scb = ahc_lookup_scb(ahc, scb_index);
1183 ahc_name(ahc), scbptr, scb_index);
1184 ahc_dump_card_state(ahc);
1188 ahc_print_path(ahc, scb);
1202 ahc_force_renegotiation(ahc);
1204 ahc_freeze_devq(ahc, scb);
1206 ahc_outb(ahc, CLRINT, CLRSCSIINT);
1207 ahc_restart(ahc);
1209 && (ahc_inb(ahc, SIMODE1) & ENBUSFREE) != 0) {
1224 ahc_outb(ahc, SCSISEQ,
1225 ahc_inb(ahc, SCSISEQ) & (ENSELI|ENRSELI|ENAUTOATNP));
1233 ahc_outb(ahc, SIMODE1, ahc_inb(ahc, SIMODE1) & ~ENBUSFREE);
1234 ahc_outb(ahc, CLRSINT1, CLRBUSFREE|CLRSCSIPERR);
1242 lastphase = ahc_inb(ahc, LASTPHASE);
1243 saved_scsiid = ahc_inb(ahc, SAVED_SCSIID);
1244 saved_lun = ahc_inb(ahc, SAVED_LUN);
1245 target = SCSIID_TARGET(ahc, saved_scsiid);
1247 channel = SCSIID_CHANNEL(ahc, saved_scsiid);
1254 ahc_fetch_devinfo(ahc, &devinfo);
1256 if (ahc_sent_msg(ahc, AHCMSG_1B, MSG_ABORT_TAG, TRUE)
1257 || ahc_sent_msg(ahc, AHCMSG_1B, MSG_ABORT, TRUE)) {
1258 if (ahc->msgout_buf[ahc->msgout_index - 1]
1261 ahc_print_path(ahc, scb);
1265 ahc_abort_scbs(ahc, target, channel,
1270 } else if (ahc_sent_msg(ahc, AHCMSG_1B,
1280 && ahc_match_scb(ahc, scb, target, channel,
1294 ahc_handle_devreset(ahc, &devinfo,
1299 } else if (ahc_sent_msg(ahc, AHCMSG_EXT,
1308 tinfo = ahc_fetch_transinfo(ahc,
1316 ahc_qinfifo_requeue_tail(ahc, scb);
1318 } else if (ahc_sent_msg(ahc, AHCMSG_EXT,
1320 || ahc_sent_msg(ahc, AHCMSG_EXT,
1326 ahc_set_width(ahc, &devinfo,
1330 ahc_set_syncrate(ahc, &devinfo,
1336 ahc_qinfifo_requeue_tail(ahc, scb);
1350 ahc_print_path(ahc, scb);
1351 ahc_abort_scbs(ahc, target, channel,
1360 printf("%s: ", ahc_name(ahc));
1372 ahc_force_renegotiation(ahc);
1376 ahc_inb(ahc, SEQADDR0)
1377 | (ahc_inb(ahc, SEQADDR1) << 8));
1379 ahc_outb(ahc, CLRINT, CLRSCSIINT);
1380 ahc_restart(ahc);
1383 ahc_name(ahc), status);
1384 ahc_outb(ahc, CLRINT, CLRSCSIINT);
1393 ahc_force_renegotiation(struct ahc_softc *ahc)
1399 ahc_fetch_devinfo(ahc, &devinfo);
1400 targ_info = ahc_fetch_transinfo(ahc,
1405 ahc_update_neg_request(ahc, &devinfo, tstate,
1411 ahc_clear_critical_section(struct ahc_softc *ahc)
1418 if (ahc->num_critical_sections == 0)
1430 seqaddr = ahc_inb(ahc, SEQADDR0)
1431 | (ahc_inb(ahc, SEQADDR1) << 8);
1440 cs = ahc->critical_sections;
1441 for (i = 0; i < ahc->num_critical_sections; i++, cs++) {
1447 if (i == ahc->num_critical_sections)
1452 ahc_name(ahc));
1453 ahc_dump_card_state(ahc);
1466 simode0 = ahc_inb(ahc, SIMODE0);
1467 ahc_outb(ahc, SIMODE0, 0);
1468 simode1 = ahc_inb(ahc, SIMODE1);
1469 if ((ahc->features & AHC_DT) != 0)
1478 ahc_outb(ahc, SIMODE1, ENBUSFREE);
1480 ahc_outb(ahc, SIMODE1, 0);
1481 ahc_outb(ahc, CLRINT, CLRSCSIINT);
1482 ahc_outb(ahc, SEQCTL, ahc_inb(ahc, SEQCTL) | STEP);
1485 if ((ahc->features & AHC_DT) != 0) {
1486 ahc_outb(ahc, CLRSINT1, CLRBUSFREE);
1487 ahc_outb(ahc, CLRINT, CLRSCSIINT);
1489 ahc_outb(ahc, HCNTRL, ahc->unpause);
1490 while (!ahc_is_paused(ahc))
1494 ahc_outb(ahc, SIMODE0, simode0);
1495 ahc_outb(ahc, SIMODE1, simode1);
1496 ahc_outb(ahc, SEQCTL, ahc_inb(ahc, SEQCTL) & ~STEP);
1504 ahc_clear_intstat(struct ahc_softc *ahc)
1507 ahc_outb(ahc, CLRSINT1, CLRSELTIMEO|CLRATNO|CLRSCSIRSTI
1510 ahc_flush_device_writes(ahc);
1511 ahc_outb(ahc, CLRSINT0, CLRSELDO|CLRSELDI|CLRSELINGO);
1512 ahc_flush_device_writes(ahc);
1513 ahc_outb(ahc, CLRINT, CLRSCSIINT);
1514 ahc_flush_device_writes(ahc);
1561 ahc_alloc_tstate(struct ahc_softc *ahc, u_int scsi_id, char channel)
1567 master_tstate = ahc->enabled_targets[ahc->our_id];
1570 master_tstate = ahc->enabled_targets[ahc->our_id_b + 8];
1572 if (ahc->enabled_targets[scsi_id] != NULL
1573 && ahc->enabled_targets[scsi_id] != master_tstate)
1575 ahc_name(ahc));
1596 ahc->enabled_targets[scsi_id] = tstate;
1606 ahc_free_tstate(struct ahc_softc *ahc, u_int scsi_id, char channel, int force)
1614 if (((channel == 'B' && scsi_id == ahc->our_id_b)
1615 || (channel == 'A' && scsi_id == ahc->our_id))
1621 tstate = ahc->enabled_targets[scsi_id];
1624 ahc->enabled_targets[scsi_id] = NULL;
1635 ahc_devlimited_syncrate(struct ahc_softc *ahc,
1642 if ((ahc->features & AHC_ULTRA2) != 0) {
1643 if ((ahc_inb(ahc, SBLKCTL) & ENAB40) != 0
1644 && (ahc_inb(ahc, SSTAT2) & EXP_ACTIVE) == 0) {
1651 } else if ((ahc->features & AHC_ULTRA) != 0) {
1681 return (ahc_find_syncrate(ahc, period, ppr_options, maxsync));
1690 ahc_find_syncrate(struct ahc_softc *ahc, u_int *period,
1695 if ((ahc->features & AHC_DT) == 0)
1711 if ((ahc->features & AHC_ULTRA2) != 0
1742 || ((ahc->features & AHC_ULTRA2) != 0
1757 ahc_find_period(struct ahc_softc *ahc, u_int scsirate, u_int maxsync)
1761 if ((ahc->features & AHC_ULTRA2) != 0)
1769 if ((ahc->features & AHC_ULTRA2) != 0) {
1787 ahc_validate_offset(struct ahc_softc *ahc,
1797 } else if ((ahc->features & AHC_ULTRA2) != 0) {
1819 ahc_validate_width(struct ahc_softc *ahc, struct ahc_initiator_tinfo *tinfo,
1824 if (ahc->features & AHC_WIDE) {
1849 ahc_update_neg_request(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
1863 if ((ahc->features & AHC_WIDE) != 0)
1892 ahc_set_syncrate(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
1912 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, devinfo->our_scsiid,
1939 if ((ahc->features & AHC_ULTRA2) != 0) {
1968 sxfrctl0 = ahc_inb(ahc, SXFRCTL0);
1972 ahc_outb(ahc, SXFRCTL0, sxfrctl0);
1976 ahc_outb(ahc, SCSIRATE, scsirate);
1977 if ((ahc->features & AHC_ULTRA2) != 0)
1978 ahc_outb(ahc, SCSIOFFSET, offset);
1986 ahc_send_async(ahc, devinfo->channel, devinfo->target,
1991 "offset = 0x%x\n", ahc_name(ahc),
1998 ahc_name(ahc), devinfo->target);
2003 update_needed += ahc_update_neg_request(ahc, devinfo, tstate,
2007 ahc_update_pending_scbs(ahc);
2019 ahc_set_width(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
2030 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, devinfo->our_scsiid,
2052 ahc_outb(ahc, SCSIRATE, scsirate);
2056 ahc_send_async(ahc, devinfo->channel, devinfo->target,
2060 ahc_name(ahc), devinfo->target,
2065 update_needed += ahc_update_neg_request(ahc, devinfo, tstate,
2068 ahc_update_pending_scbs(ahc);
2075 ahc_set_tags(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
2078 ahc_platform_set_tags(ahc, devinfo, alg);
2087 ahc_update_pending_scbs(struct ahc_softc *ahc)
2100 LIST_FOREACH(pending_scb, &ahc->pending_scbs, pending_links) {
2106 ahc_scb_devinfo(ahc, &devinfo, pending_scb);
2107 tinfo = ahc_fetch_transinfo(ahc, devinfo.channel,
2121 ahc_sync_scb(ahc, pending_scb,
2129 if (ahc_is_paused(ahc)) {
2133 ahc_pause(ahc);
2136 saved_scbptr = ahc_inb(ahc, SCBPTR);
2138 for (i = 0; i < ahc->scb_data->maxhscbs; i++) {
2143 ahc_outb(ahc, SCBPTR, i);
2144 scb_tag = ahc_inb(ahc, SCB_TAG);
2145 pending_scb = ahc_lookup_scb(ahc, scb_tag);
2150 control = ahc_inb(ahc, SCB_CONTROL);
2153 ahc_outb(ahc, SCB_CONTROL, control);
2154 ahc_outb(ahc, SCB_SCSIRATE, pending_hscb->scsirate);
2155 ahc_outb(ahc, SCB_SCSIOFFSET, pending_hscb->scsioffset);
2157 ahc_outb(ahc, SCBPTR, saved_scbptr);
2160 ahc_unpause(ahc);
2165 ahc_fetch_devinfo(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
2171 if (ahc_inb(ahc, SSTAT0) & TARGET)
2177 && (ahc->features & AHC_MULTI_TID) != 0
2178 && (ahc_inb(ahc, SEQ_FLAGS)
2181 our_id = ahc_inb(ahc, TARGIDIN) & OID;
2182 } else if ((ahc->features & AHC_ULTRA2) != 0)
2183 our_id = ahc_inb(ahc, SCSIID_ULTRA2) & OID;
2185 our_id = ahc_inb(ahc, SCSIID) & OID;
2187 saved_scsiid = ahc_inb(ahc, SAVED_SCSIID);
2190 SCSIID_TARGET(ahc, saved_scsiid),
2191 ahc_inb(ahc, SAVED_LUN),
2192 SCSIID_CHANNEL(ahc, saved_scsiid),
2230 ahc_print_devinfo(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
2232 printf("%s:%c:%d:%d: ", ahc_name(ahc), devinfo->channel,
2237 ahc_scb_devinfo(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
2247 ahc_compile_devinfo(devinfo, our_id, SCB_GET_TARGET(ahc, scb),
2248 SCB_GET_LUN(scb), SCB_GET_CHANNEL(ahc, scb), role);
2254 ahc_assert_atn(struct ahc_softc *ahc)
2259 if ((ahc->features & AHC_DT) == 0)
2260 scsisigo |= ahc_inb(ahc, SCSISIGI);
2261 ahc_outb(ahc, SCSISIGO, scsisigo);
2271 ahc_setup_initiator_msgout(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
2279 ahc->msgout_index = 0;
2280 ahc->msgout_len = 0;
2283 && ahc_inb(ahc, MSG_OUT) == MSG_IDENTIFYFLAG) {
2289 ahc->msgout_buf[ahc->msgout_index++] = identify_msg;
2290 ahc->msgout_len++;
2293 ahc->msgout_buf[ahc->msgout_index++] =
2295 ahc->msgout_buf[ahc->msgout_index++] = scb->hscb->tag;
2296 ahc->msgout_len += 2;
2301 ahc->msgout_buf[ahc->msgout_index++] = MSG_BUS_DEV_RESET;
2302 ahc->msgout_len++;
2303 ahc_print_path(ahc, scb);
2312 ahc_outb(ahc, SCSISEQ, (ahc_inb(ahc, SCSISEQ) & ~ENSELO));
2315 ahc->msgout_buf[ahc->msgout_index++] = MSG_ABORT_TAG;
2317 ahc->msgout_buf[ahc->msgout_index++] = MSG_ABORT;
2318 ahc->msgout_len++;
2319 ahc_print_path(ahc, scb);
2329 ahc_outb(ahc, SCSISEQ, (ahc_inb(ahc, SCSISEQ) & ~ENSELO));
2331 ahc_build_transfer_msg(ahc, devinfo);
2339 ahc_inb(ahc, MSG_OUT), scb->flags);
2346 ahc_outb(ahc, SCB_CONTROL, ahc_inb(ahc, SCB_CONTROL) & ~MK_MESSAGE);
2348 ahc->msgout_index = 0;
2349 ahc->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
2357 ahc_build_transfer_msg(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
2374 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, devinfo->our_scsiid,
2387 rate = ahc_devlimited_syncrate(ahc, tinfo, &period,
2408 if ((ahc->features & AHC_WIDE) != 0)
2414 ahc_print_devinfo(ahc, devinfo);
2434 ahc_validate_offset(ahc, tinfo, rate, &offset,
2439 ahc_construct_ppr(ahc, devinfo, period, offset,
2442 ahc_construct_sdtr(ahc, devinfo, period, offset);
2445 ahc_construct_wdtr(ahc, devinfo, tinfo->goal.width);
2454 ahc_construct_sdtr(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
2459 ahc->msgout_buf[ahc->msgout_index++] = MSG_EXTENDED;
2460 ahc->msgout_buf[ahc->msgout_index++] = MSG_EXT_SDTR_LEN;
2461 ahc->msgout_buf[ahc->msgout_index++] = MSG_EXT_SDTR;
2462 ahc->msgout_buf[ahc->msgout_index++] = period;
2463 ahc->msgout_buf[ahc->msgout_index++] = offset;
2464 ahc->msgout_len += 5;
2467 ahc_name(ahc), devinfo->channel, devinfo->target,
2477 ahc_construct_wdtr(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
2480 ahc->msgout_buf[ahc->msgout_index++] = MSG_EXTENDED;
2481 ahc->msgout_buf[ahc->msgout_index++] = MSG_EXT_WDTR_LEN;
2482 ahc->msgout_buf[ahc->msgout_index++] = MSG_EXT_WDTR;
2483 ahc->msgout_buf[ahc->msgout_index++] = bus_width;
2484 ahc->msgout_len += 4;
2487 ahc_name(ahc), devinfo->channel, devinfo->target,
2497 ahc_construct_ppr(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
2503 ahc->msgout_buf[ahc->msgout_index++] = MSG_EXTENDED;
2504 ahc->msgout_buf[ahc->msgout_index++] = MSG_EXT_PPR_LEN;
2505 ahc->msgout_buf[ahc->msgout_index++] = MSG_EXT_PPR;
2506 ahc->msgout_buf[ahc->msgout_index++] = period;
2507 ahc->msgout_buf[ahc->msgout_index++] = 0;
2508 ahc->msgout_buf[ahc->msgout_index++] = offset;
2509 ahc->msgout_buf[ahc->msgout_index++] = bus_width;
2510 ahc->msgout_buf[ahc->msgout_index++] = ppr_options;
2511 ahc->msgout_len += 8;
2514 "offset %x, ppr_options %x\n", ahc_name(ahc),
2524 ahc_clear_msg_state(struct ahc_softc *ahc)
2526 ahc->msgout_len = 0;
2527 ahc->msgin_index = 0;
2528 ahc->msg_type = MSG_TYPE_NONE;
2529 if ((ahc_inb(ahc, SCSISIGI) & ATNI) != 0) {
2534 ahc_outb(ahc, CLRSINT1, CLRATNO);
2536 ahc_outb(ahc, MSG_OUT, MSG_NOOP);
2537 ahc_outb(ahc, SEQ_FLAGS2,
2538 ahc_inb(ahc, SEQ_FLAGS2) & ~TARGET_MSG_PENDING);
2542 ahc_handle_proto_violation(struct ahc_softc *ahc)
2552 ahc_fetch_devinfo(ahc, &devinfo);
2553 scbid = ahc_inb(ahc, SCB_TAG);
2554 scb = ahc_lookup_scb(ahc, scbid);
2555 seq_flags = ahc_inb(ahc, SEQ_FLAGS);
2556 curphase = ahc_inb(ahc, SCSISIGI) & PHASE_MASK;
2557 lastphase = ahc_inb(ahc, LASTPHASE);
2565 ahc_print_devinfo(ahc, &devinfo);
2574 ahc_print_devinfo(ahc, &devinfo);
2580 ahc_print_path(ahc, scb);
2582 } else if ((ahc_inb(ahc, SCB_CONTROL) & STATUS_RCVD) == 0) {
2590 ahc_print_path(ahc, scb);
2593 ahc_print_path(ahc, scb);
2595 ahc_dump_card_state(ahc);
2607 found = ahc_reset_channel(ahc, 'A', TRUE);
2609 "%d SCBs aborted\n", ahc_name(ahc), 'A', found);
2616 ahc_outb(ahc, SCSISEQ,
2617 ahc_inb(ahc, SCSISEQ) & ~ENSELO);
2618 ahc_assert_atn(ahc);
2619 ahc_outb(ahc, MSG_OUT, HOST_MSG);
2621 ahc_print_devinfo(ahc, &devinfo);
2622 ahc->msgout_buf[0] = MSG_ABORT_TASK;
2623 ahc->msgout_len = 1;
2624 ahc->msgout_index = 0;
2625 ahc->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
2627 ahc_print_path(ahc, scb);
2639 ahc_handle_message_phase(struct ahc_softc *ahc)
2645 ahc_fetch_devinfo(ahc, &devinfo);
2647 bus_phase = ahc_inb(ahc, SCSISIGI) & PHASE_MASK;
2650 switch (ahc->msg_type) {
2657 if (ahc->msgout_len == 0)
2662 ahc_print_devinfo(ahc, &devinfo);
2682 ahc_outb(ahc, CLRSINT1, CLRATNO);
2683 ahc->send_msg_perror = FALSE;
2684 ahc->msg_type = MSG_TYPE_INITIATOR_MSGIN;
2685 ahc->msgin_index = 0;
2692 if (ahc->send_msg_perror) {
2693 ahc_outb(ahc, CLRSINT1, CLRATNO);
2694 ahc_outb(ahc, CLRSINT1, CLRREQINIT);
2697 printf(" byte 0x%x\n", ahc->send_msg_perror);
2699 ahc_outb(ahc, SCSIDATL, MSG_PARITY_ERROR);
2703 msgdone = ahc->msgout_index == ahc->msgout_len;
2710 ahc->msgout_index = 0;
2711 ahc_assert_atn(ahc);
2714 lastbyte = ahc->msgout_index == (ahc->msgout_len - 1);
2717 ahc_outb(ahc, CLRSINT1, CLRATNO);
2724 ahc_outb(ahc, CLRSINT1, CLRREQINIT);
2728 ahc->msgout_buf[ahc->msgout_index]);
2730 ahc_outb(ahc, SCSIDATL, ahc->msgout_buf[ahc->msgout_index++]);
2740 ahc_print_devinfo(ahc, &devinfo);
2753 ahc->msgin_index = 0;
2755 && (ahc->send_msg_perror == TRUE
2756 || (ahc->msgout_len != 0
2757 && ahc->msgout_index == 0))) {
2758 ahc->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
2766 ahc->msgin_buf[ahc->msgin_index] = ahc_inb(ahc, SCSIBUSL);
2770 ahc->msgin_buf[ahc->msgin_index]);
2773 message_done = ahc_parse_msg(ahc, &devinfo);
2780 ahc->msgin_index = 0;
2787 if (ahc->msgout_len != 0) {
2790 ahc_print_devinfo(ahc, &devinfo);
2794 ahc_assert_atn(ahc);
2797 ahc->msgin_index++;
2803 ahc_outb(ahc, CLRSINT1, CLRREQINIT);
2804 (void)ahc_inb(ahc, SCSIDATL);
2813 if (ahc->msgout_len == 0)
2822 if ((ahc_inb(ahc, SCSISIGI) & ATNI) != 0
2823 && ahc->msgout_index > 0)
2836 ahc->msg_type = MSG_TYPE_TARGET_MSGOUT;
2837 ahc_outb(ahc, SCSISIGO, P_MESGOUT | BSYO);
2838 ahc->msgin_index = 0;
2840 (void)ahc_inb(ahc, SCSIDATL);
2841 ahc_outb(ahc, SXFRCTL0,
2842 ahc_inb(ahc, SXFRCTL0) | SPIOEN);
2846 msgdone = ahc->msgout_index == ahc->msgout_len;
2848 ahc_outb(ahc, SXFRCTL0,
2849 ahc_inb(ahc, SXFRCTL0) & ~SPIOEN);
2857 ahc_outb(ahc, SXFRCTL0, ahc_inb(ahc, SXFRCTL0) | SPIOEN);
2858 ahc_outb(ahc, SCSIDATL, ahc->msgout_buf[ahc->msgout_index++]);
2870 lastbyte = (ahc_inb(ahc, SCSISIGI) & ATNI) == 0;
2877 ahc_outb(ahc, SXFRCTL0, ahc_inb(ahc, SXFRCTL0) & ~SPIOEN);
2878 ahc->msgin_buf[ahc->msgin_index] = ahc_inb(ahc, SCSIDATL);
2879 msgdone = ahc_parse_msg(ahc, &devinfo);
2890 ahc->msgin_index++;
2897 ahc->msgin_index = 0;
2903 if (ahc->msgout_len != 0) {
2904 ahc_outb(ahc, SCSISIGO, P_MESGIN | BSYO);
2905 ahc_outb(ahc, SXFRCTL0,
2906 ahc_inb(ahc, SXFRCTL0) | SPIOEN);
2907 ahc->msg_type = MSG_TYPE_TARGET_MSGIN;
2908 ahc->msgin_index = 0;
2917 ahc_outb(ahc, SXFRCTL0,
2918 ahc_inb(ahc, SXFRCTL0) | SPIOEN);
2928 ahc_clear_msg_state(ahc);
2929 ahc_outb(ahc, RETURN_1, EXIT_MSG_LOOP);
2931 ahc_outb(ahc, RETURN_1, CONT_MSG_LOOP);
2941 ahc_sent_msg(struct ahc_softc *ahc, ahc_msgtype type, u_int msgval, int full)
2949 while (index < ahc->msgout_len) {
2950 if (ahc->msgout_buf[index] == MSG_EXTENDED) {
2953 end_index = index + 1 + ahc->msgout_buf[index + 1];
2954 if (ahc->msgout_buf[index+2] == msgval
2958 if (ahc->msgout_index > end_index)
2960 } else if (ahc->msgout_index > index)
2964 } else if (ahc->msgout_buf[index] >= MSG_SIMPLE_TASK
2965 && ahc->msgout_buf[index] <= MSG_IGN_WIDE_RESIDUE) {
2972 && ahc->msgout_buf[index] == msgval
2973 && ahc->msgout_index > index)
2988 ahc_parse_msg(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
3000 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, devinfo->our_scsiid,
3015 switch (ahc->msgin_buf[0]) {
3028 response = ahc_handle_msg_reject(ahc, devinfo);
3036 if (ahc->msgin_index < 2)
3038 switch (ahc->msgin_buf[2]) {
3047 if (ahc->msgin_buf[1] != MSG_EXT_SDTR_LEN) {
3059 if (ahc->msgin_index < (MSG_EXT_SDTR_LEN + 1))
3062 period = ahc->msgin_buf[3];
3064 saved_offset = offset = ahc->msgin_buf[4];
3065 syncrate = ahc_devlimited_syncrate(ahc, tinfo, &period,
3068 ahc_validate_offset(ahc, tinfo, syncrate, &offset,
3075 ahc_name(ahc), devinfo->channel,
3077 ahc->msgin_buf[3], saved_offset,
3080 ahc_set_syncrate(ahc, devinfo,
3091 if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_SDTR, TRUE)) {
3105 ahc_name(ahc), devinfo->channel,
3108 ahc->msgout_index = 0;
3109 ahc->msgout_len = 0;
3110 ahc_construct_sdtr(ahc, devinfo,
3112 ahc->msgout_index = 0;
3125 if (ahc->msgin_buf[1] != MSG_EXT_WDTR_LEN) {
3137 if (ahc->msgin_index < (MSG_EXT_WDTR_LEN + 1))
3140 bus_width = ahc->msgin_buf[3];
3142 ahc_validate_width(ahc, tinfo, &bus_width,
3147 ahc_name(ahc), devinfo->channel,
3152 if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_WDTR, TRUE)) {
3163 ahc_name(ahc), devinfo->channel,
3176 ahc_name(ahc), devinfo->channel,
3179 ahc->msgout_index = 0;
3180 ahc->msgout_len = 0;
3181 ahc_construct_wdtr(ahc, devinfo, bus_width);
3182 ahc->msgout_index = 0;
3186 ahc_set_width(ahc, devinfo, bus_width,
3190 ahc_set_syncrate(ahc, devinfo,
3197 ahc->msgout_index = 0;
3198 ahc->msgout_len = 0;
3199 ahc_build_transfer_msg(ahc, devinfo);
3200 ahc->msgout_index = 0;
3218 if (ahc->msgin_buf[1] != MSG_EXT_PPR_LEN) {
3230 if (ahc->msgin_index < (MSG_EXT_PPR_LEN + 1))
3233 period = ahc->msgin_buf[3];
3234 offset = ahc->msgin_buf[5];
3235 bus_width = ahc->msgin_buf[6];
3237 ppr_options = ahc->msgin_buf[7];
3258 ahc_validate_width(ahc, tinfo, &bus_width,
3260 syncrate = ahc_devlimited_syncrate(ahc, tinfo, &period,
3263 ahc_validate_offset(ahc, tinfo, syncrate,
3267 if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_PPR, TRUE)) {
3287 ahc_name(ahc), devinfo->channel,
3292 ahc_name(ahc), devinfo->channel,
3294 ahc->msgout_index = 0;
3295 ahc->msgout_len = 0;
3296 ahc_construct_ppr(ahc, devinfo, period, offset,
3298 ahc->msgout_index = 0;
3306 ahc_name(ahc), devinfo->channel,
3308 saved_width, ahc->msgin_buf[3],
3312 ahc_set_width(ahc, devinfo, bus_width,
3315 ahc_set_syncrate(ahc, devinfo,
3332 ahc_handle_devreset(ahc, devinfo,
3336 ahc_restart(ahc);
3351 if (ahc->msgin_buf[0] == MSG_ABORT_TAG)
3352 tag = ahc_inb(ahc, INITIATOR_TAG);
3353 ahc_abort_scbs(ahc, devinfo->target, devinfo->channel,
3357 tstate = ahc->enabled_targets[devinfo->our_scsiid];
3363 ahc_queue_lstate_event(ahc, lstate,
3365 ahc->msgin_buf[0],
3367 ahc_send_lstate_events(ahc, lstate);
3370 ahc_restart(ahc);
3385 ahc->msgout_index = 0;
3386 ahc->msgout_len = 1;
3387 ahc->msgout_buf[0] = MSG_MESSAGE_REJECT;
3394 ahc->msgout_len = 0;
3403 ahc_handle_msg_reject(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
3418 scb_index = ahc_inb(ahc, SCB_TAG);
3419 scb = ahc_lookup_scb(ahc, scb_index);
3420 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel,
3424 last_msg = ahc_inb(ahc, LAST_MSG);
3426 if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_PPR, /*full*/FALSE)) {
3434 ahc_name(ahc), devinfo->channel,
3440 ahc->msgout_index = 0;
3441 ahc->msgout_len = 0;
3442 ahc_build_transfer_msg(ahc, devinfo);
3443 ahc->msgout_index = 0;
3445 } else if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_WDTR, /*full*/FALSE)) {
3450 "8bit transfers\n", ahc_name(ahc),
3452 ahc_set_width(ahc, devinfo, MSG_EXT_WDTR_BUS_8_BIT,
3465 ahc->msgout_index = 0;
3466 ahc->msgout_len = 0;
3467 ahc_build_transfer_msg(ahc, devinfo);
3468 ahc->msgout_index = 0;
3471 } else if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_SDTR, /*full*/FALSE)) {
3473 ahc_set_syncrate(ahc, devinfo, /*syncrate*/NULL, /*period*/0,
3480 ahc_name(ahc), devinfo->channel,
3492 ahc_name(ahc), devinfo->channel,
3494 ahc_set_tags(ahc, devinfo, AHC_QUEUE_NONE);
3501 ahc_name(ahc), devinfo->channel,
3505 ahc_set_tags(ahc, devinfo, AHC_QUEUE_BASIC);
3513 ahc_outb(ahc, SCB_CONTROL,
3514 ahc_inb(ahc, SCB_CONTROL) & mask);
3518 ahc_outb(ahc, MSG_OUT, MSG_IDENTIFYFLAG);
3519 ahc_assert_atn(ahc);
3525 if ((ahc->flags & AHC_SCB_BTT) == 0) {
3529 &(ahc->untagged_queues[devinfo->target_offset]);
3533 ahc_busy_tcl(ahc, BUILD_TCL(scb->hscb->scsiid, devinfo->lun),
3541 ahc_search_qinfifo(ahc, SCB_GET_TARGET(ahc, scb),
3542 SCB_GET_CHANNEL(ahc, scb),
3552 ahc_name(ahc), devinfo->channel, devinfo->target,
3562 ahc_handle_ign_wide_residue(struct ahc_softc *ahc,
3568 scb_index = ahc_inb(ahc, SCB_TAG);
3569 scb = ahc_lookup_scb(ahc, scb_index);
3574 if ((ahc_inb(ahc, SEQ_FLAGS) & DPHASE) == 0
3590 sgptr = ahc_inb(ahc, SCB_RESIDUAL_SGPTR);
3592 && ahc_inb(ahc, DATA_COUNT_ODD) == 1) {
3606 sgptr |= (ahc_inb(ahc, SCB_RESIDUAL_SGPTR + 3) << 24)
3607 | (ahc_inb(ahc, SCB_RESIDUAL_SGPTR + 2) << 16)
3608 | (ahc_inb(ahc, SCB_RESIDUAL_SGPTR + 1) << 8);
3610 data_cnt = (ahc_inb(ahc, SCB_RESIDUAL_DATACNT+3) << 24)
3611 | (ahc_inb(ahc, SCB_RESIDUAL_DATACNT+2) << 16)
3612 | (ahc_inb(ahc, SCB_RESIDUAL_DATACNT+1) << 8)
3613 | (ahc_inb(ahc, SCB_RESIDUAL_DATACNT));
3615 data_addr = (ahc_inb(ahc, SHADDR + 3) << 24)
3616 | (ahc_inb(ahc, SHADDR + 2) << 16)
3617 | (ahc_inb(ahc, SHADDR + 1) << 8)
3618 | (ahc_inb(ahc, SHADDR));
3649 ahc_outb(ahc, SCB_RESIDUAL_SGPTR + 3,
3651 ahc_outb(ahc, SCB_RESIDUAL_SGPTR + 2,
3653 ahc_outb(ahc, SCB_RESIDUAL_SGPTR + 1,
3655 ahc_outb(ahc, SCB_RESIDUAL_SGPTR, sgptr);
3658 ahc_outb(ahc, SCB_RESIDUAL_DATACNT + 3, data_cnt >> 24);
3659 ahc_outb(ahc, SCB_RESIDUAL_DATACNT + 2, data_cnt >> 16);
3660 ahc_outb(ahc, SCB_RESIDUAL_DATACNT + 1, data_cnt >> 8);
3661 ahc_outb(ahc, SCB_RESIDUAL_DATACNT, data_cnt);
3672 ahc_reinitialize_dataptrs(struct ahc_softc *ahc)
3681 scb_index = ahc_inb(ahc, SCB_TAG);
3682 scb = ahc_lookup_scb(ahc, scb_index);
3683 sgptr = (ahc_inb(ahc, SCB_RESIDUAL_SGPTR + 3) << 24)
3684 | (ahc_inb(ahc, SCB_RESIDUAL_SGPTR + 2) << 16)
3685 | (ahc_inb(ahc, SCB_RESIDUAL_SGPTR + 1) << 8)
3686 | ahc_inb(ahc, SCB_RESIDUAL_SGPTR);
3694 resid = (ahc_inb(ahc, SCB_RESIDUAL_DATACNT + 2) << 16)
3695 | (ahc_inb(ahc, SCB_RESIDUAL_DATACNT + 1) << 8)
3696 | ahc_inb(ahc, SCB_RESIDUAL_DATACNT);
3701 if ((ahc->flags & AHC_39BIT_ADDRESSING) != 0) {
3704 dscommand1 = ahc_inb(ahc, DSCOMMAND1);
3705 ahc_outb(ahc, DSCOMMAND1, dscommand1 | HADDLDSEL0);
3706 ahc_outb(ahc, HADDR,
3708 ahc_outb(ahc, DSCOMMAND1, dscommand1);
3710 ahc_outb(ahc, HADDR + 3, dataptr >> 24);
3711 ahc_outb(ahc, HADDR + 2, dataptr >> 16);
3712 ahc_outb(ahc, HADDR + 1, dataptr >> 8);
3713 ahc_outb(ahc, HADDR, dataptr);
3714 ahc_outb(ahc, HCNT + 2, resid >> 16);
3715 ahc_outb(ahc, HCNT + 1, resid >> 8);
3716 ahc_outb(ahc, HCNT, resid);
3717 if ((ahc->features & AHC_ULTRA2) == 0) {
3718 ahc_outb(ahc, STCNT + 2, resid >> 16);
3719 ahc_outb(ahc, STCNT + 1, resid >> 8);
3720 ahc_outb(ahc, STCNT, resid);
3728 ahc_handle_devreset(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
3737 found = ahc_abort_scbs(ahc, devinfo->target, devinfo->channel,
3746 tstate = ahc->enabled_targets[devinfo->our_scsiid];
3755 ahc_queue_lstate_event(ahc, lstate, devinfo->our_scsiid,
3757 ahc_send_lstate_events(ahc, lstate);
3765 ahc_set_width(ahc, devinfo, MSG_EXT_WDTR_BUS_8_BIT,
3767 ahc_set_syncrate(ahc, devinfo, /*syncrate*/NULL,
3771 ahc_send_async(ahc, devinfo->channel, devinfo->target,
3776 printf("%s: %s on %c:%d. %d SCBs aborted\n", ahc_name(ahc),
3782 ahc_setup_target_msgin(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
3791 ahc->msgout_index = 0;
3792 ahc->msgout_len = 0;
3795 ahc_build_transfer_msg(ahc, devinfo);
3799 ahc->msgout_index = 0;
3800 ahc->msg_type = MSG_TYPE_TARGET_MSGIN;
3805 ahc_softc_init(struct ahc_softc *ahc)
3809 if ((ahc->chip & AHC_PCI) == 0)
3810 ahc->unpause = ahc_inb(ahc, HCNTRL) & IRQMS;
3812 ahc->unpause = 0;
3813 ahc->pause = ahc->unpause | PAUSE;
3815 if (ahc->scb_data == NULL) {
3816 ahc->scb_data = malloc(sizeof(*ahc->scb_data),
3824 ahc_softc_insert(struct ahc_softc *ahc)
3833 if ((ahc->chip & AHC_BUS_MASK) == AHC_PCI
3834 && (ahc->features & AHC_MULTI_FUNC) != 0) {
3840 pci = ahc->dev_softc;
3848 slave = ahc;
3850 master = ahc;
3870 && ahc_softc_comp(list_ahc, ahc) <= 0)
3873 TAILQ_INSERT_BEFORE(list_ahc, ahc, links);
3875 TAILQ_INSERT_TAIL(&ahc_tailq, ahc, links);
3876 ahc->init_level++;
3884 ahc_find_softc(struct ahc_softc *ahc)
3889 if (list_ahc == ahc)
3890 return (ahc);
3896 ahc_set_unit(struct ahc_softc *ahc, int unit)
3898 ahc->unit = unit;
3902 ahc_set_name(struct ahc_softc *ahc, const char *name)
3904 ahc->name = name;
3908 ahc_free(struct ahc_softc *ahc)
3912 ahc_fini_scbdata(ahc);
3913 switch (ahc->init_level) {
3916 ahc_shutdown(ahc);
3917 /* TAILQ_REMOVE(&ahc_tailq, ahc, links); XXX */
3920 ahc_freedmamem(ahc->parent_dmat, ahc->shared_data_size,
3921 ahc->shared_data_dmamap, (void *)ahc->qoutfifo,
3922 &ahc->shared_data_seg, ahc->shared_data_nseg);
3928 ahc_platform_free(ahc);
3932 tstate = ahc->enabled_targets[i];
3951 if (ahc->black_hole != NULL) {
3952 /*xpt_free_path(ahc->black_hole->path);*/
3953 free(ahc->black_hole, M_DEVBUF);
3957 if (ahc->name != NULL)
3958 free(ahc->name, M_DEVBUF);
3960 if (ahc->seep_config != NULL)
3961 free(ahc->seep_config, M_DEVBUF);
3963 free(ahc, M_DEVBUF);
3971 struct ahc_softc *ahc;
3974 ahc = arg;
3977 ahc_reset(ahc);
3978 ahc_outb(ahc, SCSISEQ, 0);
3979 ahc_outb(ahc, SXFRCTL0, 0);
3980 ahc_outb(ahc, DSPCISTATUS, 0);
3983 ahc_outb(ahc, i, 0);
3991 ahc_reset(struct ahc_softc *ahc)
4002 ahc_pause(ahc);
4003 if ((ahc_inb(ahc, HCNTRL) & CHIPRST) != 0) {
4009 ahc->flags |= AHC_NO_BIOS_INIT;
4012 if ((ahc->chip & AHC_CHIPID_MASK) == AHC_AIC7770) {
4019 sblkctl1 = ahc_inb(ahc, SBLKCTL);
4020 ahc_outb(ahc, SBLKCTL, sblkctl1 | SELBUSB);
4021 sxfrctl1_b = ahc_inb(ahc, SXFRCTL1);
4022 ahc_outb(ahc, SBLKCTL, sblkctl1 & ~SELBUSB);
4024 sxfrctl1_a = ahc_inb(ahc, SXFRCTL1);
4026 ahc_outb(ahc, HCNTRL, CHIPRST | ahc->pause);
4037 } while (--wait && !(ahc_inb(ahc, HCNTRL) & CHIPRSTACK));
4041 "Trying to initialize anyway.\n", ahc_name(ahc));
4043 ahc_outb(ahc, HCNTRL, ahc->pause);
4046 sblkctl = ahc_inb(ahc, SBLKCTL) & (SELBUSB|SELWIDE);
4048 if ((ahc->chip & AHC_PCI) != 0)
4056 ahc->features |= AHC_WIDE;
4060 ahc->features |= AHC_TWIN;
4076 if ((ahc->features & AHC_TWIN) != 0) {
4079 sblkctl1 = ahc_inb(ahc, SBLKCTL);
4080 ahc_outb(ahc, SBLKCTL, sblkctl1 | SELBUSB);
4081 ahc_outb(ahc, SXFRCTL1, sxfrctl1_b);
4082 ahc_outb(ahc, SBLKCTL, sblkctl1 & ~SELBUSB);
4084 ahc_outb(ahc, SXFRCTL1, sxfrctl1_a);
4087 if (ahc->init_level == 0)
4088 ahc_dumpseq(ahc);
4098 ahc_probe_scbs(struct ahc_softc *ahc) {
4103 ahc_outb(ahc, SCBPTR, i);
4104 ahc_outb(ahc, SCB_BASE, i);
4105 if (ahc_inb(ahc, SCB_BASE) != i)
4107 ahc_outb(ahc, SCBPTR, 0);
4108 if (ahc_inb(ahc, SCB_BASE) != 0)
4126 ahc_build_free_scb_list(struct ahc_softc *ahc)
4132 if ((ahc->flags & AHC_LSCBS_ENABLED) != 0)
4135 for (i = 0; i < ahc->scb_data->maxhscbs; i++) {
4138 ahc_outb(ahc, SCBPTR, i);
4146 ahc_outb(ahc, SCB_BASE+j, 0xFF);
4149 ahc_outb(ahc, SCB_CONTROL, 0);
4152 if ((ahc->flags & AHC_PAGESCBS) != 0)
4153 ahc_outb(ahc, SCB_NEXT, i+1);
4155 ahc_outb(ahc, SCB_NEXT, SCB_LIST_NULL);
4158 ahc_outb(ahc, SCB_TAG, SCB_LIST_NULL);
4159 ahc_outb(ahc, SCB_SCSIID, 0xFF);
4160 ahc_outb(ahc, SCB_LUN, 0xFF);
4164 ahc_outb(ahc, SCBPTR, i-1);
4165 ahc_outb(ahc, SCB_NEXT, SCB_LIST_NULL);
4169 ahc_init_scbdata(struct ahc_softc *ahc)
4173 scb_data = ahc->scb_data;
4183 scb_data->maxhscbs = ahc_probe_scbs(ahc);
4184 if ((ahc->flags & AHC_PAGESCBS) != 0) {
4186 ahc_outb(ahc, FREE_SCBH, 0);
4188 ahc_outb(ahc, FREE_SCBH, SCB_LIST_NULL);
4191 if (ahc->scb_data->maxhscbs == 0) {
4192 printf("%s: No SCB space found\n", ahc_name(ahc));
4196 ahc_build_free_scb_list(ahc);
4208 if (ahc_createdmamem(ahc->parent_dmat,
4209 AHC_SCB_MAX * sizeof(struct hardware_scb), ahc->sc_dmaflags,
4212 &scb_data->hscb_seg, &scb_data->hscb_nseg, ahc_name(ahc),
4218 if (ahc_createdmamem(ahc->parent_dmat,
4219 AHC_SCB_MAX * sizeof(struct scsi_sense_data), ahc->sc_dmaflags,
4222 &scb_data->sense_nseg, ahc_name(ahc), "sense buffers") < 0)
4230 ahc_alloc_scbs(ahc);
4236 ahc_name(ahc));
4243 ahc->next_queued_scb = ahc_get_scb(ahc);
4244 ahc_outb(ahc, NEXT_QUEUED_SCB, ahc->next_queued_scb->hscb->tag);
4257 ahc_fini_scbdata(struct ahc_softc *ahc)
4261 scb_data = ahc->scb_data;
4273 ahc_freedmamem(ahc->parent_dmat, PAGE_SIZE,
4281 ahc_freedmamem(ahc->parent_dmat,
4287 ahc_freedmamem(ahc->parent_dmat,
4302 ahc_alloc_scbs(struct ahc_softc *ahc)
4312 scb_data = ahc->scb_data;
4325 if (ahc_createdmamem(ahc->parent_dmat, PAGE_SIZE, ahc->sc_dmaflags,
4329 ahc_name(ahc),
4357 next_scb->ahc_softc = ahc;
4360 error = bus_dmamap_create(ahc->parent_dmat,
4362 BUS_DMA_WAITOK|BUS_DMA_ALLOCNOW|ahc->sc_dmaflags,
4370 next_scb->hscb->tag = ahc->scb_data->numscbs;
4371 SLIST_INSERT_HEAD(&ahc->scb_data->free_scbs,
4376 ahc->scb_data->numscbs++;
4382 ahc_controller_info(struct ahc_softc *ahc, char *tbuf, size_t l)
4387 ahc_chip_names[ahc->chip & AHC_CHIPID_MASK]);
4390 if ((ahc->features & AHC_TWIN) != 0)
4393 ahc->our_id, ahc->our_id_b,
4394 (ahc->flags & AHC_PRIMARY_CHANNEL) + 'A');
4400 if ((ahc->features & AHC_ULTRA) != 0) {
4402 } else if ((ahc->features & AHC_DT) != 0) {
4404 } else if ((ahc->features & AHC_ULTRA2) != 0) {
4407 if ((ahc->features & AHC_WIDE) != 0) {
4413 speed, type, ahc->channel, ahc->our_id);
4418 if ((ahc->flags & AHC_PAGESCBS) != 0)
4420 ahc->scb_data->maxhscbs, AHC_MAX_QUEUE);
4422 snprintf(tbuf + len, l - len, "%d SCBs", ahc->scb_data->maxhscbs);
4429 ahc_init(struct ahc_softc *ahc)
4444 ahc->flags |= AHC_SEQUENCER_DEBUG;
4453 printf (" 0x%x", ahc_inb(ahc, i));
4455 if ((ahc->features & AHC_MORE_SRAM) != 0) {
4460 printf (" 0x%x", ahc_inb(ahc, i));
4468 ahc_outb(ahc, CLRINT, CLRPARERR);
4469 ahc_outb(ahc, CLRINT, CLRBRKADRINT);
4476 if ((ahc->flags & AHC_USEDEFAULTS) != 0)
4477 ahc->our_id = ahc->our_id_b = 7;
4482 ahc->flags |= AHC_INITIATORROLE;
4487 //if ((AHC_TMODE_ENABLE & (0x1 << ahc->unit)) == 0)
4488 ahc->features &= ~AHC_TARGETMODE;
4500 if ((ahc->features & AHC_TARGETMODE) != 0)
4503 ahc->shared_data_size = driver_data_size;
4505 if (ahc_createdmamem(ahc->parent_dmat, ahc->shared_data_size,
4506 ahc->sc_dmaflags,
4507 &ahc->shared_data_dmamap, (void **)&ahc->qoutfifo,
4508 &ahc->shared_data_busaddr, &ahc->shared_data_seg,
4509 &ahc->shared_data_nseg, ahc_name(ahc),
4513 ahc->init_level++;
4515 if ((ahc->features & AHC_TARGETMODE) != 0) {
4516 ahc->targetcmds = (struct target_cmd *)ahc->qoutfifo;
4517 ahc->qoutfifo = (uint8_t *)&ahc->targetcmds[AHC_TMODE_CMDS];
4518 ahc->dma_bug_buf = ahc->shared_data_busaddr
4519 + ahc->shared_data_size - 1;
4522 ahc->targetcmds[i].cmd_valid = 0;
4523 ahc_sync_tqinfifo(ahc, BUS_DMASYNC_PREREAD);
4524 ahc->tqinfifonext = 1;
4525 ahc_outb(ahc, KERNEL_TQINPOS, ahc->tqinfifonext - 1);
4526 ahc_outb(ahc, TQINPOS, ahc->tqinfifonext);
4527 ahc->qoutfifo = (uint8_t *)&ahc->targetcmds[256];
4529 ahc->qinfifo = &ahc->qoutfifo[256];
4531 ahc->init_level++;
4534 if (ahc->scb_data->maxhscbs == 0)
4535 if (ahc_init_scbdata(ahc) != 0)
4539 printf("%s: found %d SCBs\n", ahc_name(ahc),
4540 ahc->scb_data->maxhscbs);
4547 if (ahc_alloc_tstate(ahc, ahc->our_id, 'A') == NULL) {
4549 "Failing attach\n", ahc_name(ahc));
4553 if ((ahc->features & AHC_TWIN) != 0) {
4554 if (ahc_alloc_tstate(ahc, ahc->our_id_b, 'B') == NULL) {
4556 "Failing attach\n", ahc_name(ahc));
4561 ahc_outb(ahc, SEQ_FLAGS, 0);
4562 ahc_outb(ahc, SEQ_FLAGS2, 0);
4564 if (ahc->scb_data->maxhscbs < AHC_SCB_MAX_ALLOC) {
4565 ahc->flags |= AHC_PAGESCBS;
4567 ahc->flags &= ~AHC_PAGESCBS;
4574 ahc_name(ahc),
4584 if (ahc->features & AHC_TWIN) {
4590 ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) | SELBUSB);
4591 term = (ahc->flags & AHC_TERM_ENB_B) != 0 ? STPWEN : 0;
4592 ahc_outb(ahc, SCSIID, ahc->our_id_b);
4593 scsi_conf = ahc_inb(ahc, SCSICONF + 1);
4594 ahc_outb(ahc, SXFRCTL1, (scsi_conf & (ENSPCHK|STIMESEL))
4595 |term|ahc->seltime_b|ENSTIMER|ACTNEGEN);
4596 if ((ahc->features & AHC_ULTRA2) != 0)
4597 ahc_outb(ahc, SIMODE0, ahc_inb(ahc, SIMODE0)|ENIOERR);
4598 ahc_outb(ahc, SIMODE1, ENSELTIMO|ENSCSIRST|ENSCSIPERR);
4599 ahc_outb(ahc, SXFRCTL0, DFON|SPIOEN);
4602 && (ahc->flags & AHC_INITIATORROLE) != 0)
4603 ahc->flags |= AHC_RESET_BUS_B;
4606 ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) & ~SELBUSB);
4609 term = (ahc->flags & AHC_TERM_ENB_A) != 0 ? STPWEN : 0;
4610 if ((ahc->features & AHC_ULTRA2) != 0)
4611 ahc_outb(ahc, SCSIID_ULTRA2, ahc->our_id);
4613 ahc_outb(ahc, SCSIID, ahc->our_id);
4614 scsi_conf = ahc_inb(ahc, SCSICONF);
4615 ahc_outb(ahc, SXFRCTL1, (scsi_conf & (ENSPCHK|STIMESEL))
4616 |term|ahc->seltime
4618 if ((ahc->features & AHC_ULTRA2) != 0)
4619 ahc_outb(ahc, SIMODE0, ahc_inb(ahc, SIMODE0)|ENIOERR);
4620 ahc_outb(ahc, SIMODE1, ENSELTIMO|ENSCSIRST|ENSCSIPERR);
4621 ahc_outb(ahc, SXFRCTL0, DFON|SPIOEN);
4624 && (ahc->flags & AHC_INITIATORROLE) != 0)
4625 ahc->flags |= AHC_RESET_BUS_A;
4635 if ((ahc->flags & AHC_USEDEFAULTS) != 0) {
4637 "host and target device parameters\n", ahc_name(ahc));
4638 ahc->flags |= AHC_EXTENDED_TRANS_A|AHC_EXTENDED_TRANS_B|
4641 if ((ahc->features & AHC_ULTRA) != 0)
4643 } else if ((ahc->flags & AHC_USETARGETDEFAULTS) != 0) {
4645 " target parameters\n", ahc_name(ahc));
4646 ahc->flags |= AHC_EXTENDED_TRANS_A|AHC_EXTENDED_TRANS_B;
4648 if ((ahc->features & AHC_ULTRA) != 0)
4651 discenable = ~((ahc_inb(ahc, DISC_DSB + 1) << 8)
4652 | ahc_inb(ahc, DISC_DSB));
4653 if ((ahc->features & (AHC_ULTRA|AHC_ULTRA2)) != 0)
4654 ultraenb = (ahc_inb(ahc, ULTRA_ENB + 1) << 8)
4655 | ahc_inb(ahc, ULTRA_ENB);
4658 if ((ahc->features & (AHC_WIDE|AHC_TWIN)) == 0)
4669 our_id = ahc->our_id;
4671 if (i > 7 && (ahc->features & AHC_TWIN) != 0) {
4673 our_id = ahc->our_id_b;
4676 tinfo = ahc_fetch_transinfo(ahc, channel, our_id,
4680 if (ahc->flags & (AHC_USEDEFAULTS | AHC_USETARGETDEFAULTS)) {
4681 if ((ahc->features & AHC_WIDE) != 0)
4695 scsirate = ahc_inb(ahc, TARG_SCSIRATE + i);
4697 if ((ahc->features & AHC_ULTRA2) != 0) {
4712 offset = ahc_inb(ahc, TARG_OFFSET + i);
4717 if ((ahc->features & AHC_DT) != 0)
4720 ahc_find_period(ahc, scsirate, maxsync);
4726 && (ahc->features & AHC_DT) != 0)
4737 ahc_find_period(ahc, scsirate,
4747 && (ahc->features & AHC_WIDE) != 0)
4750 if ((ahc->features & AHC_DT) != 0)
4762 ahc->user_discenable = discenable;
4763 ahc->user_tagenable = tagenable;
4767 ahc_unbusy_tcl(ahc, BUILD_TCL(i << 4, 0));
4768 if ((ahc->flags & AHC_SCB_BTT) != 0) {
4776 ahc_unbusy_tcl(ahc, BUILD_TCL(i << 4, lun));
4782 ahc->qoutfifo[i] = SCB_LIST_NULL;
4784 ahc_sync_qoutfifo(ahc, BUS_DMASYNC_PREREAD);
4787 ahc->qinfifo[i] = SCB_LIST_NULL;
4789 if ((ahc->features & AHC_MULTI_TID) != 0) {
4790 ahc_outb(ahc, TARGID, 0);
4791 ahc_outb(ahc, TARGID + 1, 0);
4797 physaddr = ahc->scb_data->hscb_busaddr;
4798 ahc_outb(ahc, HSCB_ADDR, physaddr & 0xFF);
4799 ahc_outb(ahc, HSCB_ADDR + 1, (physaddr >> 8) & 0xFF);
4800 ahc_outb(ahc, HSCB_ADDR + 2, (physaddr >> 16) & 0xFF);
4801 ahc_outb(ahc, HSCB_ADDR + 3, (physaddr >> 24) & 0xFF);
4803 physaddr = ahc->shared_data_busaddr;
4804 ahc_outb(ahc, SHARED_DATA_ADDR, physaddr & 0xFF);
4805 ahc_outb(ahc, SHARED_DATA_ADDR + 1, (physaddr >> 8) & 0xFF);
4806 ahc_outb(ahc, SHARED_DATA_ADDR + 2, (physaddr >> 16) & 0xFF);
4807 ahc_outb(ahc, SHARED_DATA_ADDR + 3, (physaddr >> 24) & 0xFF);
4814 ahc_outb(ahc, CMDSIZE_TABLE, 5);
4815 ahc_outb(ahc, CMDSIZE_TABLE + 1, 9);
4816 ahc_outb(ahc, CMDSIZE_TABLE + 2, 9);
4817 ahc_outb(ahc, CMDSIZE_TABLE + 3, 0);
4818 ahc_outb(ahc, CMDSIZE_TABLE + 4, 15);
4819 ahc_outb(ahc, CMDSIZE_TABLE + 5, 11);
4820 ahc_outb(ahc, CMDSIZE_TABLE + 6, 0);
4821 ahc_outb(ahc, CMDSIZE_TABLE + 7, 0);
4824 ahc_outb(ahc, KERNEL_QINPOS, 0);
4825 ahc_outb(ahc, QINPOS, 0);
4826 ahc_outb(ahc, QOUTPOS, 0);
4832 if ((ahc->features & AHC_QUEUE_REGS) != 0) {
4833 ahc_outb(ahc, QOFF_CTLSTA, SCB_QSIZE_256);
4834 ahc_outb(ahc, SDSCB_QOFF, 0);
4835 ahc_outb(ahc, SNSCB_QOFF, 0);
4836 ahc_outb(ahc, HNSCB_QOFF, 0);
4841 ahc_outb(ahc, WAITING_SCBH, SCB_LIST_NULL);
4844 ahc_outb(ahc, DISCONNECTED_SCBH, SCB_LIST_NULL);
4847 ahc_outb(ahc, MSG_OUT, MSG_NOOP);
4855 if ((ahc->flags & AHC_INITIATORROLE) != 0)
4857 ahc_outb(ahc, SCSISEQ_TEMPLATE, scsiseq_template);
4865 ahc_name(ahc));
4867 ahc_loadseq(ahc);
4869 if ((ahc->features & AHC_ULTRA2) != 0) {
4879 ahc_pause(ahc);
4881 (ahc_inb(ahc, SBLKCTL) & (ENAB40|ENAB20)) == 0 && wait;
4884 ahc_unpause(ahc);
4891 ahc_intr_enable(struct ahc_softc *ahc, int enable)
4895 hcntrl = ahc_inb(ahc, HCNTRL);
4897 ahc->pause &= ~INTEN;
4898 ahc->unpause &= ~INTEN;
4901 ahc->pause |= INTEN;
4902 ahc->unpause |= INTEN;
4904 ahc_outb(ahc, HCNTRL, hcntrl);
4915 ahc_pause_and_flushwork(struct ahc_softc *ahc)
4922 ahc->flags |= AHC_ALL_INTERRUPTS;
4927 ahc_unpause(ahc);
4928 ahc_intr(ahc);
4929 ahc_pause(ahc);
4931 ahc_outb(ahc, SCSISEQ, ahc_inb(ahc, SCSISEQ) & ~ENSELO);
4932 ahc_clear_critical_section(ahc);
4933 if (intstat == 0xFF && (ahc->features & AHC_REMOVABLE) != 0)
4936 && (((intstat = ahc_inb(ahc, INTSTAT)) & INT_PEND) != 0
4937 || (ahc_inb(ahc, SSTAT0) & (SELDO|SELINGO))));
4940 ahc_inb(ahc, INTSTAT));
4942 ahc_platform_flushwork(ahc);
4943 ahc->flags &= ~AHC_ALL_INTERRUPTS;
4947 ahc_suspend(struct ahc_softc *ahc)
4952 ahc_pause_and_flushwork(ahc);
4954 if (LIST_FIRST(&ahc->pending_scbs) != NULL)
4963 if (ahc->pending_device != NULL)
4968 if ((ahc->features & AHC_TWIN) != 0) {
4969 ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) | SELBUSB);
4970 ahc->suspend_state.channel[1].scsiseq = ahc_inb(ahc, SCSISEQ);
4971 ahc->suspend_state.channel[1].sxfrctl0 = ahc_inb(ahc, SXFRCTL0);
4972 ahc->suspend_state.channel[1].sxfrctl1 = ahc_inb(ahc, SXFRCTL1);
4973 ahc->suspend_state.channel[1].simode0 = ahc_inb(ahc, SIMODE0);
4974 ahc->suspend_state.channel[1].simode1 = ahc_inb(ahc, SIMODE1);
4975 ahc->suspend_state.channel[1].seltimer = ahc_inb(ahc, SELTIMER);
4976 ahc->suspend_state.channel[1].seqctl = ahc_inb(ahc, SEQCTL);
4977 ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) & ~SELBUSB);
4979 ahc->suspend_state.channel[0].scsiseq = ahc_inb(ahc, SCSISEQ);
4980 ahc->suspend_state.channel[0].sxfrctl0 = ahc_inb(ahc, SXFRCTL0);
4981 ahc->suspend_state.channel[0].sxfrctl1 = ahc_inb(ahc, SXFRCTL1);
4982 ahc->suspend_state.channel[0].simode0 = ahc_inb(ahc, SIMODE0);
4983 ahc->suspend_state.channel[0].simode1 = ahc_inb(ahc, SIMODE1);
4984 ahc->suspend_state.channel[0].seltimer = ahc_inb(ahc, SELTIMER);
4985 ahc->suspend_state.channel[0].seqctl = ahc_inb(ahc, SEQCTL);
4987 if ((ahc->chip & AHC_PCI) != 0) {
4988 ahc->suspend_state.dscommand0 = ahc_inb(ahc, DSCOMMAND0);
4989 ahc->suspend_state.dspcistatus = ahc_inb(ahc, DSPCISTATUS);
4992 if ((ahc->features & AHC_DT) != 0) {
4995 sfunct = ahc_inb(ahc, SFUNCT) & ~ALT_MODE;
4996 ahc_outb(ahc, SFUNCT, sfunct | ALT_MODE);
4997 ahc->suspend_state.optionmode = ahc_inb(ahc, OPTIONMODE);
4998 ahc_outb(ahc, SFUNCT, sfunct);
4999 ahc->suspend_state.crccontrol1 = ahc_inb(ahc, CRCCONTROL1);
5002 if ((ahc->features & AHC_MULTI_FUNC) != 0)
5003 ahc->suspend_state.scbbaddr = ahc_inb(ahc, SCBBADDR);
5005 if ((ahc->features & AHC_ULTRA2) != 0)
5006 ahc->suspend_state.dff_thrsh = ahc_inb(ahc, DFF_THRSH);
5008 ptr = ahc->suspend_state.scratch_ram;
5010 *ptr++ = ahc_inb(ahc, SRAM_BASE + i);
5012 if ((ahc->features & AHC_MORE_SRAM) != 0) {
5014 *ptr++ = ahc_inb(ahc, TARG_OFFSET + i);
5017 ptr = ahc->suspend_state.btt;
5018 if ((ahc->flags & AHC_SCB_BTT) != 0) {
5026 *ptr = ahc_index_busy_tcl(ahc, tcl);
5030 ahc_shutdown(ahc);
5035 ahc_resume(struct ahc_softc *ahc)
5040 ahc_reset(ahc);
5042 ahc_build_free_scb_list(ahc);
5045 if ((ahc->features & AHC_TWIN) != 0) {
5046 ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) | SELBUSB);
5047 ahc_outb(ahc, SCSIID, ahc->our_id);
5048 ahc_outb(ahc, SCSISEQ, ahc->suspend_state.channel[1].scsiseq);
5049 ahc_outb(ahc, SXFRCTL0, ahc->suspend_state.channel[1].sxfrctl0);
5050 ahc_outb(ahc, SXFRCTL1, ahc->suspend_state.channel[1].sxfrctl1);
5051 ahc_outb(ahc, SIMODE0, ahc->suspend_state.channel[1].simode0);
5052 ahc_outb(ahc, SIMODE1, ahc->suspend_state.channel[1].simode1);
5053 ahc_outb(ahc, SELTIMER, ahc->suspend_state.channel[1].seltimer);
5054 ahc_outb(ahc, SEQCTL, ahc->suspend_state.channel[1].seqctl);
5055 ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) & ~SELBUSB);
5057 ahc_outb(ahc, SCSISEQ, ahc->suspend_state.channel[0].scsiseq);
5058 ahc_outb(ahc, SXFRCTL0, ahc->suspend_state.channel[0].sxfrctl0);
5059 ahc_outb(ahc, SXFRCTL1, ahc->suspend_state.channel[0].sxfrctl1);
5060 ahc_outb(ahc, SIMODE0, ahc->suspend_state.channel[0].simode0);
5061 ahc_outb(ahc, SIMODE1, ahc->suspend_state.channel[0].simode1);
5062 ahc_outb(ahc, SELTIMER, ahc->suspend_state.channel[0].seltimer);
5063 ahc_outb(ahc, SEQCTL, ahc->suspend_state.channel[0].seqctl);
5064 if ((ahc->features & AHC_ULTRA2) != 0)
5065 ahc_outb(ahc, SCSIID_ULTRA2, ahc->our_id);
5067 ahc_outb(ahc, SCSIID, ahc->our_id);
5069 if ((ahc->chip & AHC_PCI) != 0) {
5070 ahc_outb(ahc, DSCOMMAND0, ahc->suspend_state.dscommand0);
5071 ahc_outb(ahc, DSPCISTATUS, ahc->suspend_state.dspcistatus);
5074 if ((ahc->features & AHC_DT) != 0) {
5077 sfunct = ahc_inb(ahc, SFUNCT) & ~ALT_MODE;
5078 ahc_outb(ahc, SFUNCT, sfunct | ALT_MODE);
5079 ahc_outb(ahc, OPTIONMODE, ahc->suspend_state.optionmode);
5080 ahc_outb(ahc, SFUNCT, sfunct);
5081 ahc_outb(ahc, CRCCONTROL1, ahc->suspend_state.crccontrol1);
5084 if ((ahc->features & AHC_MULTI_FUNC) != 0)
5085 ahc_outb(ahc, SCBBADDR, ahc->suspend_state.scbbaddr);
5087 if ((ahc->features & AHC_ULTRA2) != 0)
5088 ahc_outb(ahc, DFF_THRSH, ahc->suspend_state.dff_thrsh);
5090 ptr = ahc->suspend_state.scratch_ram;
5092 ahc_outb(ahc, SRAM_BASE + i, *ptr++);
5094 if ((ahc->features & AHC_MORE_SRAM) != 0) {
5096 ahc_outb(ahc, TARG_OFFSET + i, *ptr++);
5099 ptr = ahc->suspend_state.btt;
5100 if ((ahc->flags & AHC_SCB_BTT) != 0) {
5108 ahc_busy_tcl(ahc, tcl, *ptr);
5121 ahc_index_busy_tcl(struct ahc_softc *ahc, u_int tcl)
5126 if ((ahc->flags & AHC_SCB_BTT) != 0) {
5129 saved_scbptr = ahc_inb(ahc, SCBPTR);
5130 ahc_outb(ahc, SCBPTR, TCL_LUN(tcl));
5131 scbid = ahc_inb(ahc, SCB_64_BTT + TCL_TARGET_OFFSET(tcl));
5132 ahc_outb(ahc, SCBPTR, saved_scbptr);
5135 scbid = ahc_inb(ahc, BUSY_TARGETS + target_offset);
5142 ahc_unbusy_tcl(struct ahc_softc *ahc, u_int tcl)
5146 if ((ahc->flags & AHC_SCB_BTT) != 0) {
5149 saved_scbptr = ahc_inb(ahc, SCBPTR);
5150 ahc_outb(ahc, SCBPTR, TCL_LUN(tcl));
5151 ahc_outb(ahc, SCB_64_BTT+TCL_TARGET_OFFSET(tcl), SCB_LIST_NULL);
5152 ahc_outb(ahc, SCBPTR, saved_scbptr);
5155 ahc_outb(ahc, BUSY_TARGETS + target_offset, SCB_LIST_NULL);
5160 ahc_busy_tcl(struct ahc_softc *ahc, u_int tcl, u_int scbid)
5164 if ((ahc->flags & AHC_SCB_BTT) != 0) {
5167 saved_scbptr = ahc_inb(ahc, SCBPTR);
5168 ahc_outb(ahc, SCBPTR, TCL_LUN(tcl));
5169 ahc_outb(ahc, SCB_64_BTT + TCL_TARGET_OFFSET(tcl), scbid);
5170 ahc_outb(ahc, SCBPTR, saved_scbptr);
5173 ahc_outb(ahc, BUSY_TARGETS + target_offset, scbid);
5179 ahc_match_scb(struct ahc_softc *ahc, struct scb *scb, int target,
5182 int targ = SCB_GET_TARGET(ahc, scb);
5183 char chan = SCB_GET_CHANNEL(ahc, scb);
5217 ahc_freeze_devq(struct ahc_softc *ahc, struct scb *scb)
5223 target = SCB_GET_TARGET(ahc, scb);
5225 channel = SCB_GET_CHANNEL(ahc, scb);
5227 ahc_search_qinfifo(ahc, target, channel, lun,
5231 ahc_platform_freeze_devq(ahc, scb);
5235 ahc_qinfifo_requeue_tail(struct ahc_softc *ahc, struct scb *scb)
5240 if (ahc_qinfifo_count(ahc) != 0) {
5244 prev_pos = ahc->qinfifonext - 1;
5245 prev_tag = ahc->qinfifo[prev_pos];
5246 prev_scb = ahc_lookup_scb(ahc, prev_tag);
5248 ahc_qinfifo_requeue(ahc, prev_scb, scb);
5249 if ((ahc->features & AHC_QUEUE_REGS) != 0) {
5250 ahc_outb(ahc, HNSCB_QOFF, ahc->qinfifonext);
5252 ahc_outb(ahc, KERNEL_QINPOS, ahc->qinfifonext);
5257 ahc_qinfifo_requeue(struct ahc_softc *ahc, struct scb *prev_scb,
5261 ahc_outb(ahc, NEXT_QUEUED_SCB, scb->hscb->tag);
5264 ahc_sync_scb(ahc, prev_scb,
5267 ahc->qinfifo[ahc->qinfifonext++] = scb->hscb->tag;
5268 scb->hscb->next = ahc->next_queued_scb->hscb->tag;
5269 ahc_sync_scb(ahc, scb, BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
5273 ahc_qinfifo_count(struct ahc_softc *ahc)
5278 if ((ahc->features & AHC_QUEUE_REGS) != 0) {
5279 qinpos = ahc_inb(ahc, SNSCB_QOFF);
5280 ahc_outb(ahc, SNSCB_QOFF, qinpos);
5282 qinpos = ahc_inb(ahc, QINPOS);
5283 diff = ahc->qinfifonext - qinpos;
5288 ahc_search_qinfifo(struct ahc_softc *ahc, int target, char channel,
5303 qintail = ahc->qinfifonext;
5304 have_qregs = (ahc->features & AHC_QUEUE_REGS) != 0;
5306 qinstart = ahc_inb(ahc, SNSCB_QOFF);
5307 ahc_outb(ahc, SNSCB_QOFF, qinstart);
5309 qinstart = ahc_inb(ahc, QINPOS);
5319 ahc_freeze_untagged_queues(ahc);
5326 ahc->qinfifonext = qinpos;
5327 ahc_outb(ahc, NEXT_QUEUED_SCB, ahc->next_queued_scb->hscb->tag);
5330 scb = ahc_lookup_scb(ahc, ahc->qinfifo[qinpos]);
5333 qinpos, ahc->qinfifo[qinpos]);
5337 if (ahc_match_scb(ahc, scb, target, channel, lun, tag, role)) {
5356 ahc_done(ahc, scb);
5363 ahc_qinfifo_requeue(ahc, prev_scb, scb);
5368 ahc_qinfifo_requeue(ahc, prev_scb, scb);
5374 if ((ahc->features & AHC_QUEUE_REGS) != 0) {
5375 ahc_outb(ahc, HNSCB_QOFF, ahc->qinfifonext);
5377 ahc_outb(ahc, KERNEL_QINPOS, ahc->qinfifonext);
5382 && (qinstart != ahc->qinfifonext)) {
5395 scb = ahc_lookup_scb(ahc, ahc->qinfifo[qinstart]);
5399 found, qinstart, ahc->qinfifonext);
5409 ahc->scb_data->scbindex[scb->hscb->tag] = NULL;
5410 ahc_swap_with_next_hscb(ahc, scb);
5412 ahc->qinfifo[qinstart] = scb->hscb->tag;
5415 ahc_outb(ahc, NEXT_QUEUED_SCB, scb->hscb->tag);
5418 qintail = ahc->qinfifonext - 1;
5419 scb = ahc_lookup_scb(ahc, ahc->qinfifo[qintail]);
5420 scb->hscb->next = ahc->next_queued_scb->hscb->tag;
5426 curscbptr = ahc_inb(ahc, SCBPTR);
5427 next = ahc_inb(ahc, WAITING_SCBH); /* Start at head of list. */
5433 ahc_outb(ahc, SCBPTR, next);
5434 scb_index = ahc_inb(ahc, SCB_TAG);
5435 if (scb_index >= ahc->scb_data->numscbs) {
5438 scb_index, ahc->scb_data->numscbs);
5439 ahc_dump_card_state(ahc);
5442 scb = ahc_lookup_scb(ahc, scb_index);
5448 if (ahc_match_scb(ahc, scb, target, channel,
5469 ahc_done(ahc, scb);
5473 next = ahc_rem_wscb(ahc, next, prev);
5477 next = ahc_inb(ahc, SCB_NEXT);
5483 next = ahc_inb(ahc, SCB_NEXT);
5486 ahc_outb(ahc, SCBPTR, curscbptr);
5488 found += ahc_search_untagged_queues(ahc, /*ahc_io_ctx_t*/NULL, target,
5492 ahc_release_untagged_queues(ahc);
5497 ahc_search_untagged_queues(struct ahc_softc *ahc,
5511 ahc_freeze_untagged_queues(ahc);
5516 if ((ahc->flags & AHC_SCB_BTT) == 0) {
5534 untagged_q = &(ahc->untagged_queues[i]);
5553 if (ahc_match_scb(ahc, scb, target, channel, lun,
5576 ahc_done(ahc, scb);
5590 ahc_release_untagged_queues(ahc);
5595 ahc_search_disc_list(struct ahc_softc *ahc, int target, char channel,
5606 next = ahc_inb(ahc, DISCONNECTED_SCBH);
5611 active_scb = ahc_inb(ahc, SCBPTR);
5619 ahc_outb(ahc, SCBPTR, next);
5620 scb_index = ahc_inb(ahc, SCB_TAG);
5621 if (scb_index >= ahc->scb_data->numscbs) {
5624 scb_index, ahc->scb_data->numscbs);
5625 ahc_dump_card_state(ahc);
5634 scbp = ahc_lookup_scb(ahc, scb_index);
5635 if (ahc_match_scb(ahc, scbp, target, channel, lun,
5640 ahc_rem_scb_from_disc_list(ahc, prev, next);
5643 next = ahc_inb(ahc, SCB_NEXT);
5649 next = ahc_inb(ahc, SCB_NEXT);
5653 ahc_outb(ahc, SCBPTR, active_scb);
5662 ahc_rem_scb_from_disc_list(struct ahc_softc *ahc, u_int prev, u_int scbptr)
5666 ahc_outb(ahc, SCBPTR, scbptr);
5667 next = ahc_inb(ahc, SCB_NEXT);
5669 ahc_outb(ahc, SCB_CONTROL, 0);
5671 ahc_add_curscb_to_free_list(ahc);
5674 ahc_outb(ahc, SCBPTR, prev);
5675 ahc_outb(ahc, SCB_NEXT, next);
5677 ahc_outb(ahc, DISCONNECTED_SCBH, next);
5688 ahc_add_curscb_to_free_list(struct ahc_softc *ahc)
5694 ahc_outb(ahc, SCB_TAG, SCB_LIST_NULL);
5696 if ((ahc->flags & AHC_PAGESCBS) != 0) {
5697 ahc_outb(ahc, SCB_NEXT, ahc_inb(ahc, FREE_SCBH));
5698 ahc_outb(ahc, FREE_SCBH, ahc_inb(ahc, SCBPTR));
5707 ahc_rem_wscb(struct ahc_softc *ahc, u_int scbpos, u_int prev)
5715 curscb = ahc_inb(ahc, SCBPTR);
5716 ahc_outb(ahc, SCBPTR, scbpos);
5717 next = ahc_inb(ahc, SCB_NEXT);
5720 ahc_outb(ahc, SCB_CONTROL, 0);
5722 ahc_add_curscb_to_free_list(ahc);
5727 ahc_outb(ahc, WAITING_SCBH, next);
5733 ahc_outb(ahc, SCSISEQ, (ahc_inb(ahc, SCSISEQ) & ~ENSELO));
5739 ahc_outb(ahc, SCBPTR, prev);
5740 ahc_outb(ahc, SCB_NEXT, next);
5746 ahc_outb(ahc, SCBPTR, curscb);
5758 ahc_abort_scbs(struct ahc_softc *ahc, int target, char channel,
5775 ahc_freeze_untagged_queues(ahc);
5778 active_scb = ahc_inb(ahc, SCBPTR);
5780 found = ahc_search_qinfifo(ahc, target, channel, lun, SCB_LIST_NULL,
5805 if ((ahc->flags & AHC_SCB_BTT) != 0)
5819 scbid = ahc_index_busy_tcl(ahc, tcl);
5820 scbp = ahc_lookup_scb(ahc, scbid);
5822 || ahc_match_scb(ahc, scbp, target, channel,
5825 ahc_unbusy_tcl(ahc, BUILD_TCL(i << 4, j));
5835 ahc_search_disc_list(ahc, target, channel, lun, tag,
5847 for (i = 0; i < ahc->scb_data->maxhscbs; i++) {
5850 ahc_outb(ahc, SCBPTR, i);
5851 scbid = ahc_inb(ahc, SCB_TAG);
5852 scbp = ahc_lookup_scb(ahc, scbid);
5855 && ahc_match_scb(ahc, scbp, target, channel, lun, tag, role)))
5856 ahc_add_curscb_to_free_list(ahc);
5865 scbp_next = LIST_FIRST(&ahc->pending_scbs);
5869 if (ahc_match_scb(ahc, scbp, target, channel, lun, tag, role)) {
5879 ahc_done(ahc, scbp);
5883 ahc_outb(ahc, SCBPTR, active_scb);
5884 ahc_platform_abort_scbs(ahc, target, channel, lun, tag, role, status);
5885 ahc_release_untagged_queues(ahc);
5890 ahc_reset_current_bus(struct ahc_softc *ahc)
5894 ahc_outb(ahc, SIMODE1, ahc_inb(ahc, SIMODE1) & ~ENSCSIRST);
5895 scsiseq = ahc_inb(ahc, SCSISEQ);
5896 ahc_outb(ahc, SCSISEQ, scsiseq | SCSIRSTO);
5897 ahc_flush_device_writes(ahc);
5900 ahc_outb(ahc, SCSISEQ, scsiseq & ~SCSIRSTO);
5902 ahc_clear_intstat(ahc);
5905 ahc_outb(ahc, SIMODE1, ahc_inb(ahc, SIMODE1) | ENSCSIRST);
5909 ahc_reset_channel(struct ahc_softc *ahc, char channel, int initiate_reset)
5920 ahc->pending_device = NULL;
5927 ahc_pause(ahc);
5930 ahc_clear_critical_section(ahc);
5937 ahc_run_qoutfifo(ahc);
5949 if ((ahc->flags & AHC_TARGETROLE) != 0) {
5950 ahc_run_tqinfifo(ahc, /*paused*/TRUE);
5957 sblkctl = ahc_inb(ahc, SBLKCTL);
5959 if ((ahc->features & AHC_TWIN) != 0
5962 scsiseq = ahc_inb(ahc, SCSISEQ_TEMPLATE);
5968 ahc_outb(ahc, SBLKCTL, sblkctl ^ SELBUSB);
5969 simode1 = ahc_inb(ahc, SIMODE1) & ~(ENBUSFREE|ENSCSIRST);
5976 if ((ahc->flags & AHC_TARGETROLE) != 0)
5979 ahc, SIMODE1, simode1);
5981 ahc_reset_current_bus(ahc);
5982 ahc_clear_intstat(ahc);
5983 ahc_outb(ahc, SCSISEQ, scsiseq & (ENSELI|ENRSELI|ENAUTOATNP));
5984 ahc_outb(ahc, SBLKCTL, sblkctl);
5988 simode1 = ahc_inb(ahc, SIMODE1) & ~(ENBUSFREE|ENSCSIRST);
5995 if ((ahc->flags & AHC_TARGETROLE) != 0)
5998 ahc_outb(ahc, SIMODE1, simode1);
6000 ahc_reset_current_bus(ahc);
6001 ahc_clear_intstat(ahc);
6002 ahc_outb(ahc, SCSISEQ, scsiseq & (ENSELI|ENRSELI|ENAUTOATNP));
6010 found = ahc_abort_scbs(ahc, CAM_TARGET_WILDCARD, channel,
6014 max_scsiid = (ahc->features & AHC_WIDE) ? 15 : 7;
6025 tstate = ahc->enabled_targets[target];
6035 ahc_queue_lstate_event(ahc, lstate, CAM_TARGET_WILDCARD,
6037 ahc_send_lstate_events(ahc, lstate);
6046 if (ahc->enabled_targets[target] == NULL)
6054 ahc_set_width(ahc, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
6056 ahc_set_syncrate(ahc, &devinfo, /*syncrate*/NULL,
6064 ahc_restart(ahc);
6066 ahc_unpause(ahc);
6076 ahc_calc_residual(struct ahc_softc *ahc, struct scb *scb)
6151 ahc_print_path(ahc, scb);
6164 ahc_queue_lstate_event(struct ahc_softc *ahc, struct ahc_tmode_lstate *lstate,
6215 ahc_send_lstate_events(struct ahc_softc *ahc, struct ahc_tmode_lstate *lstate)
6251 ahc_dumpseq(struct ahc_softc* ahc)
6256 if ((ahc->chip & AHC_BUS_MASK) < AHC_PCI)
6258 else if ((ahc->features & AHC_ULTRA2) != 0)
6263 ahc_outb(ahc, SEQCTL, PERRORDIS|FAILDIS|FASTMODE|LOADRAM);
6264 ahc_outb(ahc, SEQADDR0, 0);
6265 ahc_outb(ahc, SEQADDR1, 0);
6269 ahc_insb(ahc, SEQRAM, ins_bytes, 4);
6279 ahc_loadseq(struct ahc_softc *ahc)
6304 if (ahc->targetcmds != NULL)
6307 download_consts[CACHESIZE_MASK] = ahc->pci_cachesize - 1;
6308 download_consts[INVERTED_CACHESIZE_MASK] = ~(ahc->pci_cachesize - 1);
6309 sg_prefetch_cnt = ahc->pci_cachesize;
6319 ahc_outb(ahc, SEQCTL, PERRORDIS|FAILDIS|FASTMODE|LOADRAM);
6320 ahc_outb(ahc, SEQADDR0, 0);
6321 ahc_outb(ahc, SEQADDR1, 0);
6324 if (ahc_check_patch(ahc, &cur_patch, i, &skip_addr) == 0) {
6352 ahc_download_instr(ahc, i, download_consts);
6356 ahc->num_critical_sections = cs_count;
6360 ahc->critical_sections = malloc(cs_count, M_DEVBUF, M_WAITOK);
6361 memcpy(ahc->critical_sections, cs_table, cs_count);
6363 ahc_outb(ahc, SEQCTL, PERRORDIS|FAILDIS|FASTMODE);
6364 ahc_restart(ahc);
6369 ahc_name(ahc), ahc->features, ahc->bugs, ahc->flags);
6374 ahc_check_patch(struct ahc_softc *ahc, const struct patch **start_patch,
6387 if (cur_patch->patch_func(ahc) == 0) {
6410 ahc_download_instr(struct ahc_softc *ahc, u_int instrptr, uint8_t *dconsts)
6449 ahc_check_patch(ahc, &cur_patch, i, &skip_addr);
6475 if ((ahc->features & AHC_CMD_CHAN) == 0
6486 ahc_name(ahc));
6492 if ((ahc->features & AHC_ULTRA2) != 0) {
6524 ahc_outsb(ahc, SEQRAM, instr.bytes, 4);
6599 ahc_dump_card_state(struct ahc_softc *ahc)
6615 if (ahc_is_paused(ahc)) {
6619 ahc_pause(ahc);
6622 saved_scbptr = ahc_inb(ahc, SCBPTR);
6623 last_phase = ahc_inb(ahc, LASTPHASE);
6626 ahc_name(ahc), ahc_lookup_phase_entry(last_phase)->phasemsg,
6627 ahc_inb(ahc, SEQADDR0) | (ahc_inb(ahc, SEQADDR1) << 8));
6631 ahc_inb(ahc, ACCUM), ahc_inb(ahc, SINDEX), ahc_inb(ahc, DINDEX),
6632 ahc_inb(ahc, ARG_2));
6633 printf("HCNT = 0x%x SCBPTR = 0x%x\n", ahc_inb(ahc, HCNT),
6634 ahc_inb(ahc, SCBPTR));
6636 if ((ahc->features & AHC_DT) != 0)
6637 ahc_scsiphase_print(ahc_inb(ahc, SCSIPHASE), &cur_col, 50);
6638 ahc_scsisigi_print(ahc_inb(ahc, SCSISIGI), &cur_col, 50);
6639 ahc_error_print(ahc_inb(ahc, ERROR), &cur_col, 50);
6640 ahc_scsibusl_print(ahc_inb(ahc, SCSIBUSL), &cur_col, 50);
6641 ahc_lastphase_print(ahc_inb(ahc, LASTPHASE), &cur_col, 50);
6642 ahc_scsiseq_print(ahc_inb(ahc, SCSISEQ), &cur_col, 50);
6643 ahc_sblkctl_print(ahc_inb(ahc, SBLKCTL), &cur_col, 50);
6644 ahc_scsirate_print(ahc_inb(ahc, SCSIRATE), &cur_col, 50);
6645 ahc_seqctl_print(ahc_inb(ahc, SEQCTL), &cur_col, 50);
6646 ahc_seq_flags_print(ahc_inb(ahc, SEQ_FLAGS), &cur_col, 50);
6647 ahc_sstat0_print(ahc_inb(ahc, SSTAT0), &cur_col, 50);
6648 ahc_sstat1_print(ahc_inb(ahc, SSTAT1), &cur_col, 50);
6649 ahc_sstat2_print(ahc_inb(ahc, SSTAT2), &cur_col, 50);
6650 ahc_sstat3_print(ahc_inb(ahc, SSTAT3), &cur_col, 50);
6651 ahc_simode0_print(ahc_inb(ahc, SIMODE0), &cur_col, 50);
6652 ahc_simode1_print(ahc_inb(ahc, SIMODE1), &cur_col, 50);
6653 ahc_sxfrctl0_print(ahc_inb(ahc, SXFRCTL0), &cur_col, 50);
6654 ahc_dfcntrl_print(ahc_inb(ahc, DFCNTRL), &cur_col, 50);
6655 ahc_dfstatus_print(ahc_inb(ahc, DFSTATUS), &cur_col, 50);
6660 printf(" 0x%x", ahc_inb(ahc, STACK)|(ahc_inb(ahc, STACK) << 8));
6661 printf("\nSCB count = %d\n", ahc->scb_data->numscbs);
6662 printf("Kernel NEXTQSCB = %d\n", ahc->next_queued_scb->hscb->tag);
6663 printf("Card NEXTQSCB = %d\n", ahc_inb(ahc, NEXT_QUEUED_SCB));
6666 if ((ahc->features & AHC_QUEUE_REGS) != 0) {
6667 qinpos = ahc_inb(ahc, SNSCB_QOFF);
6668 ahc_outb(ahc, SNSCB_QOFF, qinpos);
6670 qinpos = ahc_inb(ahc, QINPOS);
6671 qintail = ahc->qinfifonext;
6673 printf("%d ", ahc->qinfifo[qinpos]);
6679 scb_index = ahc_inb(ahc, WAITING_SCBH);
6682 ahc_outb(ahc, SCBPTR, scb_index);
6683 printf("%d:%d ", scb_index, ahc_inb(ahc, SCB_TAG));
6684 scb_index = ahc_inb(ahc, SCB_NEXT);
6689 scb_index = ahc_inb(ahc, DISCONNECTED_SCBH);
6692 ahc_outb(ahc, SCBPTR, scb_index);
6693 printf("%d:%d ", scb_index, ahc_inb(ahc, SCB_TAG));
6694 scb_index = ahc_inb(ahc, SCB_NEXT);
6698 ahc_sync_qoutfifo(ahc, BUS_DMASYNC_POSTREAD);
6700 qoutpos = ahc->qoutfifonext;
6702 while (ahc->qoutfifo[qoutpos] != SCB_LIST_NULL && i++ < 256) {
6703 printf("%d ", ahc->qoutfifo[qoutpos]);
6709 scb_index = ahc_inb(ahc, FREE_SCBH);
6712 ahc_outb(ahc, SCBPTR, scb_index);
6714 scb_index = ahc_inb(ahc, SCB_NEXT);
6719 for (i = 0; i < ahc->scb_data->maxhscbs; i++) {
6720 ahc_outb(ahc, SCBPTR, i);
6723 ahc_scb_control_print(ahc_inb(ahc, SCB_CONTROL), &cur_col, 60);
6724 ahc_scb_scsiid_print(ahc_inb(ahc, SCB_SCSIID), &cur_col, 60);
6725 ahc_scb_lun_print(ahc_inb(ahc, SCB_LUN), &cur_col, 60);
6726 ahc_scb_tag_print(ahc_inb(ahc, SCB_TAG), &cur_col, 60);
6732 LIST_FOREACH(scb, &ahc->pending_scbs, pending_links) {
6739 if ((ahc->flags & AHC_PAGESCBS) == 0) {
6740 ahc_outb(ahc, SCBPTR, scb->hscb->tag);
6742 ahc_scb_control_print(ahc_inb(ahc, SCB_CONTROL),
6744 ahc_scb_tag_print(ahc_inb(ahc, SCB_TAG), &cur_col, 60);
6752 SLIST_FOREACH(scb, &ahc->scb_data->free_scbs, links.sle) {
6759 maxtarget = (ahc->features & (AHC_WIDE|AHC_TWIN)) ? 15 : 7;
6761 untagged_q = &ahc->untagged_queues[target];
6774 ahc_platform_dump_card_state(ahc);
6776 ahc_outb(ahc, SCBPTR, saved_scbptr);
6778 ahc_unpause(ahc);
6784 ahc_find_tmode_devs(struct ahc_softc *ahc, struct cam_sim *sim, union ccb *ccb,
6790 if ((ahc->features & AHC_TARGETMODE) == 0)
6800 *lstate = ahc->black_hole;
6804 max_id = (ahc->features & AHC_WIDE) ? 15 : 7;
6811 *tstate = ahc->enabled_targets[ccb->ccb_h.target_id];
6825 ahc_handle_en_lun(struct ahc_softc *ahc, struct cam_sim *sim, union ccb *ccb)
6838 status = ahc_find_tmode_devs(ahc, sim, ccb, &tstate, &lstate,
6847 our_id = ahc->our_id;
6849 our_id = ahc->our_id_b;
6871 if ((ahc->features & AHC_MULTIROLE) != 0) {
6873 if ((ahc->features & AHC_MULTI_TID) != 0
6874 && (ahc->flags & AHC_INITIATORROLE) != 0) {
6883 } else if ((ahc->flags & AHC_INITIATORROLE) != 0
6884 || ahc->enabled_luns > 0) {
6894 } else if ((ahc->features & AHC_MULTI_TID) == 0
6895 && ahc->enabled_luns > 0) {
6910 if ((ahc->flags & AHC_TARGETROLE) == 0
6915 ahc_lock(ahc, &s);
6916 if (LIST_FIRST(&ahc->pending_scbs) != NULL) {
6918 ahc_unlock(ahc, &s);
6921 ahc->flags |= AHC_TARGETROLE;
6922 if ((ahc->features & AHC_MULTIROLE) == 0)
6923 ahc->flags &= ~AHC_INITIATORROLE;
6924 ahc_pause(ahc);
6925 ahc_loadseq(ahc);
6926 ahc_unlock(ahc, &s);
6931 channel = SIM_CHANNEL(ahc, sim);
6963 tstate = ahc_alloc_tstate(ahc, target, channel);
6992 ahc_lock(ahc, &s);
6993 ahc_pause(ahc);
6996 ahc->enabled_luns++;
6998 if ((ahc->features & AHC_MULTI_TID) != 0) {
7001 targid_mask = ahc_inb(ahc, TARGID)
7002 | (ahc_inb(ahc, TARGID + 1) << 8);
7005 ahc_outb(ahc, TARGID, targid_mask);
7006 ahc_outb(ahc, TARGID+1, (targid_mask >> 8));
7008 ahc_update_scsiid(ahc, targid_mask);
7013 channel = SIM_CHANNEL(ahc, sim);
7014 our_id = SIM_SCSI_ID(ahc, sim);
7025 sblkctl = ahc_inb(ahc, SBLKCTL);
7028 if ((ahc->features & AHC_TWIN) == 0)
7032 ahc->our_id = target;
7034 ahc->our_id_b = target;
7037 ahc_outb(ahc, SBLKCTL,
7040 ahc_outb(ahc, SCSIID, target);
7043 ahc_outb(ahc, SBLKCTL, sblkctl);
7047 ahc->black_hole = lstate;
7049 if (ahc->black_hole != NULL && ahc->enabled_luns > 0) {
7050 scsiseq = ahc_inb(ahc, SCSISEQ_TEMPLATE);
7052 ahc_outb(ahc, SCSISEQ_TEMPLATE, scsiseq);
7053 scsiseq = ahc_inb(ahc, SCSISEQ);
7055 ahc_outb(ahc, SCSISEQ, scsiseq);
7057 ahc_unpause(ahc);
7058 ahc_unlock(ahc, &s);
7071 ahc_lock(ahc, &s);
7074 LIST_FOREACH(scb, &ahc->pending_scbs, pending_links) {
7082 ahc_unlock(ahc, &s);
7098 ahc_unlock(ahc, &s);
7107 ahc_pause(ahc);
7111 ahc->enabled_luns--;
7119 ahc_free_tstate(ahc, target, channel,
7121 if (ahc->features & AHC_MULTI_TID) {
7124 targid_mask = ahc_inb(ahc, TARGID)
7125 | (ahc_inb(ahc, TARGID + 1)
7129 ahc_outb(ahc, TARGID, targid_mask);
7130 ahc_outb(ahc, TARGID+1,
7132 ahc_update_scsiid(ahc, targid_mask);
7137 ahc->black_hole = NULL;
7145 if (ahc->enabled_luns == 0) {
7149 scsiseq = ahc_inb(ahc, SCSISEQ_TEMPLATE);
7151 ahc_outb(ahc, SCSISEQ_TEMPLATE, scsiseq);
7152 scsiseq = ahc_inb(ahc, SCSISEQ);
7154 ahc_outb(ahc, SCSISEQ, scsiseq);
7156 if ((ahc->features & AHC_MULTIROLE) == 0) {
7158 ahc->flags &= ~AHC_TARGETROLE;
7159 ahc->flags |= AHC_INITIATORROLE;
7160 ahc_pause(ahc);
7161 ahc_loadseq(ahc);
7164 ahc_unpause(ahc);
7165 ahc_unlock(ahc, &s);
7170 ahc_update_scsiid(struct ahc_softc *ahc, u_int targid_mask)
7175 if ((ahc->features & AHC_MULTI_TID) == 0)
7184 if ((ahc->features & AHC_ULTRA2) != 0)
7185 scsiid = ahc_inb(ahc, SCSIID_ULTRA2);
7187 scsiid = ahc_inb(ahc, SCSIID);
7195 our_id = ahc->our_id;
7201 if ((ahc->features & AHC_ULTRA2) != 0)
7202 ahc_outb(ahc, SCSIID_ULTRA2, scsiid);
7204 ahc_outb(ahc, SCSIID, scsiid);
7208 ahc_run_tqinfifo(struct ahc_softc *ahc, int paused)
7217 if ((ahc->features & AHC_AUTOPAUSE) != 0)
7220 ahc_sync_tqinfifo(ahc, BUS_DMASYNC_POSTREAD);
7221 ahc->targetcmds[ahc->tqinfifonext])->cmd_valid != 0) {
7227 if (ahc_handle_target_cmd(ahc, cmd) != 0)
7231 ahc_dmamap_sync(ahc, ahc->parent_dmat/*shared_data_dmat*/,
7232 ahc->shared_data_dmamap,
7233 ahc_targetcmd_offset(ahc, ahc->tqinfifonext),
7236 ahc->tqinfifonext++;
7242 if ((ahc->tqinfifonext & (HOST_TQINPOS - 1)) == 1) {
7243 if ((ahc->features & AHC_HS_MAILBOX) != 0) {
7246 hs_mailbox = ahc_inb(ahc, HS_MAILBOX);
7248 hs_mailbox |= ahc->tqinfifonext & HOST_TQINPOS;
7249 ahc_outb(ahc, HS_MAILBOX, hs_mailbox);
7252 ahc_pause(ahc);
7253 ahc_outb(ahc, KERNEL_TQINPOS,
7254 ahc->tqinfifonext & HOST_TQINPOS);
7256 ahc_unpause(ahc);
7263 ahc_handle_target_cmd(struct ahc_softc *ahc, struct target_cmd *cmd)
7273 initiator = SCSIID_TARGET(ahc, cmd->scsiid);
7278 tstate = ahc->enabled_targets[target];
7287 lstate = ahc->black_hole;
7291 ahc->flags |= AHC_TQINFIFO_BLOCKED;
7296 printf("%s: ATIOs exhausted\n", ahc_name(ahc));
7299 ahc->flags &= ~AHC_TQINFIFO_BLOCKED;
7303 lstate == ahc->black_hole ? "(Black Holed)" : "");
7307 if (lstate == ahc->black_hole) {
7365 initiator, target, lun, ahc->pending_device);
7367 ahc->pending_device = lstate;