Home | History | Annotate | Download | only in ic

Lines Matching defs:ahd

116 static void		ahd_handle_transmission_error(struct ahd_softc *ahd);
117 static void ahd_handle_lqiphase_error(struct ahd_softc *ahd,
119 static int ahd_handle_pkt_busfree(struct ahd_softc *ahd,
121 static int ahd_handle_nonpkt_busfree(struct ahd_softc *ahd);
122 static void ahd_handle_proto_violation(struct ahd_softc *ahd);
123 static void ahd_force_renegotiation(struct ahd_softc *ahd,
127 ahd_alloc_tstate(struct ahd_softc *ahd,
130 static void ahd_free_tstate(struct ahd_softc *ahd,
133 static void ahd_devlimited_syncrate(struct ahd_softc *ahd,
138 static void ahd_update_neg_table(struct ahd_softc *ahd,
141 static void ahd_update_pending_scbs(struct ahd_softc *ahd);
142 static void ahd_fetch_devinfo(struct ahd_softc *ahd,
144 static void ahd_scb_devinfo(struct ahd_softc *ahd,
147 static void ahd_setup_initiator_msgout(struct ahd_softc *ahd,
150 static void ahd_build_transfer_msg(struct ahd_softc *ahd,
152 static void ahd_construct_sdtr(struct ahd_softc *ahd,
155 static void ahd_construct_wdtr(struct ahd_softc *ahd,
158 static void ahd_construct_ppr(struct ahd_softc *ahd,
162 static void ahd_clear_msg_state(struct ahd_softc *ahd);
163 static void ahd_handle_message_phase(struct ahd_softc *ahd);
169 static int ahd_sent_msg(struct ahd_softc *ahd, ahd_msgtype type,
171 static int ahd_parse_msg(struct ahd_softc *ahd,
173 static int ahd_handle_msg_reject(struct ahd_softc *ahd,
175 static void ahd_handle_ign_wide_residue(struct ahd_softc *ahd,
177 static void ahd_reinitialize_dataptrs(struct ahd_softc *ahd);
178 static void ahd_handle_devreset(struct ahd_softc *ahd,
184 static void ahd_setup_target_msgin(struct ahd_softc *ahd,
189 static u_int ahd_sglist_size(struct ahd_softc *ahd);
190 static u_int ahd_sglist_allocsize(struct ahd_softc *ahd);
191 static void ahd_initialize_hscbs(struct ahd_softc *ahd);
192 static int ahd_init_scbdata(struct ahd_softc *ahd);
193 static void ahd_fini_scbdata(struct ahd_softc *ahd);
194 static void ahd_setup_iocell_workaround(struct ahd_softc *ahd);
195 static void ahd_iocell_first_selection(struct ahd_softc *ahd);
196 static void ahd_add_col_list(struct ahd_softc *ahd,
198 static void ahd_rem_col_list(struct ahd_softc *ahd,
200 static void ahd_chip_init(struct ahd_softc *ahd);
201 static void ahd_qinfifo_requeue(struct ahd_softc *ahd,
204 static int ahd_qinfifo_count(struct ahd_softc *ahd);
205 static int ahd_search_scb_list(struct ahd_softc *ahd, int target,
210 static void ahd_stitch_tid_list(struct ahd_softc *ahd,
213 static void ahd_add_scb_to_free_list(struct ahd_softc *ahd,
215 static u_int ahd_rem_wscb(struct ahd_softc *ahd, u_int scbid,
217 static void ahd_reset_current_bus(struct ahd_softc *ahd);
221 static void ahd_dumpseq(struct ahd_softc *ahd);
223 static void ahd_loadseq(struct ahd_softc *ahd);
224 static int ahd_check_patch(struct ahd_softc *ahd,
227 static u_int ahd_resolve_seqaddr(struct ahd_softc *ahd,
229 static void ahd_download_instr(struct ahd_softc *ahd,
231 static int ahd_probe_stack_size(struct ahd_softc *ahd);
232 static int ahd_scb_active_in_fifo(struct ahd_softc *ahd,
234 static void ahd_run_data_fifo(struct ahd_softc *ahd,
238 static void ahd_queue_lstate_event(struct ahd_softc *ahd,
243 static void ahd_update_scsiid(struct ahd_softc *ahd,
245 static int ahd_handle_target_cmd(struct ahd_softc *ahd,
268 static inline void ahd_assert_atn(struct ahd_softc *ahd);
269 static inline int ahd_currently_packetized(struct ahd_softc *ahd);
270 static inline int ahd_set_active_fifo(struct ahd_softc *ahd);
273 ahd_assert_atn(struct ahd_softc *ahd)
275 ahd_outb(ahd, SCSISIGO, ATNO);
285 ahd_currently_packetized(struct ahd_softc *ahd)
290 saved_modes = ahd_save_modes(ahd);
291 if ((ahd->bugs & AHD_PKTIZED_STATUS_BUG) != 0) {
297 ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
298 packetized = ahd_inb(ahd, LQISTATE) != 0;
300 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
301 packetized = ahd_inb(ahd, LQISTAT2) & PACKETIZED;
303 ahd_restore_modes(ahd, saved_modes);
308 ahd_set_active_fifo(struct ahd_softc *ahd)
312 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
313 active_fifo = ahd_inb(ahd, DFFSTAT) & CURRFIFO;
317 ahd_set_modes(ahd, active_fifo, active_fifo);
329 ahd_restart(struct ahd_softc *ahd)
332 ahd_pause(ahd);
334 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
337 ahd_clear_msg_state(ahd);
338 ahd_outb(ahd, SCSISIGO, 0); /* De-assert BSY */
339 ahd_outb(ahd, MSG_OUT, MSG_NOOP); /* No message to send */
340 ahd_outb(ahd, SXFRCTL1, ahd_inb(ahd, SXFRCTL1) & ~BITBUCKET);
341 ahd_outb(ahd, SEQINTCTL, 0);
342 ahd_outb(ahd, LASTPHASE, P_BUSFREE);
343 ahd_outb(ahd, SEQ_FLAGS, 0);
344 ahd_outb(ahd, SAVED_SCSIID, 0xFF);
345 ahd_outb(ahd, SAVED_LUN, 0xFF);
354 ahd_outb(ahd, TQINPOS, ahd->tqinfifonext);
357 ahd_outb(ahd, SCSISEQ1,
358 ahd_inb(ahd, SCSISEQ_TEMPLATE) & (ENSELI|ENRSELI|ENAUTOATNP));
359 ahd_set_modes(ahd, AHD_MODE_CCHAN, AHD_MODE_CCHAN);
360 ahd_outb(ahd, SEQCTL0, FASTMODE|SEQRESET);
361 ahd_unpause(ahd);
365 ahd_clear_fifo(struct ahd_softc *ahd, u_int fifo)
371 printf("%s: Clearing FIFO %d\n", ahd_name(ahd), fifo);
373 saved_modes = ahd_save_modes(ahd);
374 ahd_set_modes(ahd, fifo, fifo);
375 ahd_outb(ahd, DFFSXFRCTL, RSTCHN|CLRSHCNT);
376 if ((ahd_inb(ahd, SG_STATE) & FETCH_INPROG) != 0)
377 ahd_outb(ahd, CCSGCTL, CCSGRESET);
378 ahd_outb(ahd, LONGJMP_ADDR + 1, INVALID_ADDR);
379 ahd_outb(ahd, SG_STATE, 0);
380 ahd_restore_modes(ahd, saved_modes);
389 ahd_flush_qoutfifo(struct ahd_softc *ahd)
398 saved_modes = ahd_save_modes(ahd);
404 ahd_run_qoutfifo(ahd);
409 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
410 saved_scbptr = ahd_get_scbptr(ahd);
411 while ((ahd_inb(ahd, LQISTAT2) & LQIGSAVAIL) != 0) {
415 scbid = (ahd_inb(ahd, GSFIFO+1) << 8)
416 | ahd_inb(ahd, GSFIFO);
417 scb = ahd_lookup_scb(ahd, scbid);
420 ahd_name(ahd), scbid);
432 ahd_set_modes(ahd, fifo_mode, fifo_mode);
433 if (ahd_scb_active_in_fifo(ahd, scb) == 0)
436 ahd_run_data_fifo(ahd, scb);
446 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
447 ahd_set_scbptr(ahd, scbid);
448 if ((ahd_inb_scbram(ahd, SCB_SGPTR) & SG_LIST_NULL) == 0
449 && ((ahd_inb_scbram(ahd, SCB_SGPTR) & SG_FULL_RESID) != 0
450 || (ahd_inb_scbram(ahd, SCB_RESIDUAL_SGPTR)
460 ahd_outb(ahd, SCB_SCSI_STATUS, 0);
461 ahd_outb(ahd, SCB_SGPTR,
462 ahd_inb_scbram(ahd, SCB_SGPTR)
464 ahd_outw(ahd, SCB_TAG, SCB_GET_TAG(scb));
465 comp_head = ahd_inw(ahd, COMPLETE_DMA_SCB_HEAD);
466 ahd_outw(ahd, SCB_NEXT_COMPLETE, comp_head);
468 ahd_outw(ahd, COMPLETE_DMA_SCB_HEAD,
471 ahd_complete_scb(ahd, scb);
473 ahd_set_scbptr(ahd, saved_scbptr);
478 ahd_set_modes(ahd, AHD_MODE_CCHAN, AHD_MODE_CCHAN);
484 while (((ccscbctl = ahd_inb(ahd
494 ahd_outb(ahd, CCSCBCTL, ccscbctl & ~(CCARREN|CCSCBEN));
496 saved_scbptr = ahd_get_scbptr(ahd);
501 scbid = ahd_inw(ahd, COMPLETE_DMA_SCB_HEAD);
506 ahd_set_scbptr(ahd, scbid);
507 next_scbid = ahd_inw_scbram(ahd, SCB_NEXT_COMPLETE);
508 scb = ahd_lookup_scb(ahd, scbid);
511 "SCB %d invalid\n", ahd_name(ahd), scbid);
516 *hscb_ptr++ = ahd_inb_scbram(ahd, SCB_BASE + i);
518 ahd_complete_scb(ahd, scb);
521 ahd_outw(ahd, COMPLETE_DMA_SCB_HEAD, SCB_LIST_NULL);
523 scbid = ahd_inw(ahd, COMPLETE_SCB_HEAD);
526 ahd_set_scbptr(ahd, scbid);
527 next_scbid = ahd_inw_scbram(ahd, SCB_NEXT_COMPLETE);
528 scb = ahd_lookup_scb(ahd, scbid);
531 ahd_name(ahd), scbid);
535 ahd_complete_scb(ahd, scb);
538 ahd_outw(ahd, COMPLETE_SCB_HEAD, SCB_LIST_NULL);
543 ahd_set_scbptr(ahd, saved_scbptr);
544 ahd_restore_modes(ahd, saved_modes);
545 ahd->flags |= AHD_UPDATE_PEND_CMDS;
553 ahd_scb_active_in_fifo(struct ahd_softc *ahd, struct scb *scb)
562 if (ahd_get_scbptr(ahd) != SCB_GET_TAG(scb)
563 || ((ahd_inb(ahd, LONGJMP_ADDR+1) & INVALID_ADDR) != 0
564 && (ahd_inb(ahd, SEQINTSRC) & (CFG4DATA|SAVEPTRS)) == 0))
582 ahd_run_data_fifo(struct ahd_softc *ahd, struct scb *scb)
587 seqintsrc = ahd_inb(ahd, SEQINTSRC);
595 sgptr = ahd_inl_scbram(ahd, SCB_SGPTR) & ~SG_FULL_RESID;
596 ahd_outb(ahd, SCB_SGPTR, sgptr);
601 datacnt = ahd_inl_scbram(ahd, SCB_DATACNT);
604 ahd_outb(ahd, SG_STATE, 0);
606 ahd_outb(ahd, SG_STATE, LOADING_NEEDED);
607 ahd_outq(ahd, HADDR, ahd_inq_scbram(ahd, SCB_DATAPTR));
608 ahd_outl(ahd, HCNT, datacnt & AHD_SG_LEN_MASK);
609 ahd_outb(ahd, SG_CACHE_PRE, sgptr);
610 ahd_outb(ahd, DFCNTRL, PRELOADEN|SCSIEN|HDMAEN);
615 ahd_outb(ahd, SCB_RESIDUAL_DATACNT+3, datacnt >> 24);
616 ahd_outl(ahd, SCB_RESIDUAL_SGPTR, sgptr & SG_PTR_MASK);
621 ahd_outb(ahd, SCB_FIFO_USE_COUNT,
622 ahd_inb_scbram(ahd, SCB_FIFO_USE_COUNT) + 1);
627 ahd_outw(ahd, LONGJMP_ADDR, 0);
633 ahd_outb(ahd, CLRSEQINTSRC, CLRCFG4DATA);
638 if ((ahd_inb(ahd, LONGJMP_ADDR+1)&INVALID_ADDR) != 0) {
643 ahd_outb(ahd, DFFSXFRCTL, CLRCHN);
651 if ((ahd_inb(ahd, SG_STATE) & FETCH_INPROG) != 0)
652 ahd_outb(ahd, CCSGCTL, 0);
653 ahd_outb(ahd, SG_STATE, 0);
659 ahd_outb(ahd, DFCNTRL,
660 ahd_inb(ahd, DFCNTRL) | FIFOFLUSH);
665 sgptr = ahd_inl_scbram(ahd, SCB_RESIDUAL_SGPTR);
666 resid = ahd_inl(ahd, SHCNT);
668 ahd_inb_scbram(ahd, SCB_RESIDUAL_DATACNT+3) << 24;
669 ahd_outl(ahd, SCB_RESIDUAL_DATACNT, resid);
670 if ((ahd_inb(ahd, SG_CACHE_SHADOW) & LAST_SEG) == 0) {
678 if ((ahd_inb(ahd, SG_CACHE_SHADOW) & 0x80) != 0
682 sgptr |= ahd_inb(ahd, SG_CACHE_SHADOW)
684 ahd_outl(ahd, SCB_RESIDUAL_SGPTR, sgptr);
685 ahd_outb(ahd, SCB_RESIDUAL_DATACNT + 3, 0);
687 ahd_outb(ahd, SCB_RESIDUAL_SGPTR,
693 ahd_outq(ahd, SCB_DATAPTR, ahd_inq(ahd, SHADDR));
694 ahd_outl(ahd, SCB_DATACNT, resid);
695 ahd_outl(ahd, SCB_SGPTR, sgptr);
696 ahd_outb(ahd, CLRSEQINTSRC, CLRSAVEPTRS);
697 ahd_outb(ahd, SEQIMODE,
698 ahd_inb(ahd, SEQIMODE) | ENSAVEPTRS);
703 if ((ahd_inb(ahd, DFCNTRL) & DIRECTION) != 0)
705 } else if ((ahd_inb(ahd, SG_STATE) & LOADING_NEEDED) != 0) {
715 if ((ahd_inb(ahd, SG_STATE) & FETCH_INPROG) != 0) {
716 ahd_outb(ahd, CCSGCTL, 0);
717 ahd_outb(ahd, SG_STATE, LOADING_NEEDED);
726 if ((ahd_inb(ahd, DFSTATUS) & PRELOAD_AVAIL) == 0)
728 if ((ahd_inb(ahd, DFCNTRL) & HDMAENACK) == 0)
735 sgptr = ahd_inl_scbram(ahd, SCB_RESIDUAL_SGPTR);
737 if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0) {
740 sg = ahd_sg_bus_to_virt(ahd, scb, sgptr);
747 sg = ahd_sg_bus_to_virt(ahd, scb, sgptr);
758 ahd_outb(ahd, SCB_RESIDUAL_DATACNT+3, data_len >> 24);
759 ahd_outl(ahd, SCB_RESIDUAL_SGPTR, sgptr);
766 ahd_outb(ahd, SG_STATE, 0);
768 ahd_outq(ahd, HADDR, data_addr);
769 ahd_outl(ahd, HCNT, data_len & AHD_SG_LEN_MASK);
770 ahd_outb(ahd, SG_CACHE_PRE, sgptr & 0xFF);
775 dfcntrl = ahd_inb(ahd, DFCNTRL)|PRELOADEN|HDMAEN;
776 if ((ahd->features & AHD_NEW_DFCNTRL_OPTS)!=0) {
784 ahd_outb(ahd, DFCNTRL, dfcntrl);
785 } else if ((ahd_inb(ahd, SG_CACHE_SHADOW)
792 ahd_outb(ahd, SCB_SGPTR,
793 ahd_inb_scbram(ahd, SCB_SGPTR) | SG_LIST_NULL);
795 } else if ((ahd_inb(ahd, DFSTATUS) & FIFOEMP) != 0) {
805 ahd_outb(ahd, LONGJMP_ADDR + 1, INVALID_ADDR);
806 ahd_outb(ahd, SCB_FIFO_USE_COUNT,
807 ahd_inb_scbram(ahd, SCB_FIFO_USE_COUNT) - 1);
808 ahd_outb(ahd, DFFSXFRCTL, CLRCHN);
812 ahd_run_qoutfifo(struct ahd_softc *ahd)
817 if ((ahd->flags & AHD_RUNNING_QOUTFIFO) != 0)
819 ahd->flags |= AHD_RUNNING_QOUTFIFO;
820 ahd_sync_qoutfifo(ahd, BUS_DMASYNC_POSTREAD);
821 while ((ahd->qoutfifo[ahd->qoutfifonext]
822 & QOUTFIFO_ENTRY_VALID_LE) == ahd->qoutfifonext_valid_tag) {
824 scb_index = ahd_le16toh(ahd->qoutfifo[ahd->qoutfifonext]
826 scb = ahd_lookup_scb(ahd, scb_index);
830 ahd_name(ahd), scb_index,
831 ahd->qoutfifonext);
832 ahd_dump_card_state(ahd);
834 ahd_complete_scb(ahd, scb);
836 ahd->qoutfifonext = (ahd->qoutfifonext+1) & (AHD_QOUT_SIZE-1);
837 if (ahd->qoutfifonext == 0)
838 ahd->qoutfifonext_valid_tag ^= QOUTFIFO_ENTRY_VALID_LE;
840 ahd->flags &= ~AHD_RUNNING_QOUTFIFO;
845 ahd_handle_hwerrint(struct ahd_softc *ahd)
854 error = ahd_inb(ahd, ERROR);
858 ahd_name(ahd), ahd_hard_errors[i].errmesg);
861 ahd_dump_card_state(ahd);
865 ahd_abort_scbs(ahd, CAM_TARGET_WILDCARD, ALL_CHANNELS,
870 ahd_free(ahd);
874 ahd_handle_seqint(struct ahd_softc *ahd, u_int intstat)
883 seqintcode = ahd_inb(ahd, SEQINTCODE);
884 ahd_outb(ahd, CLRINT, CLRSEQINT);
885 if ((ahd->bugs & AHD_INTCOLLISION_BUG) != 0) {
892 ahd_unpause(ahd);
893 while (!ahd_is_paused(ahd))
895 ahd_outb(ahd, CLRINT, CLRSEQINT);
897 ahd_update_modes(ahd);
901 ahd_name(ahd), seqintcode);
910 scbid = ahd_get_scbptr(ahd);
911 scb = ahd_lookup_scb(ahd, scbid);
913 ahd_complete_scb(ahd, scb);
916 "(bad status)\n", ahd_name(ahd), scbid);
917 ahd_dump_card_state(ahd);
919 cmds_pending = ahd_inw(ahd, CMDS_PENDING);
921 ahd_outw(ahd, CMDS_PENDING, cmds_pending - 1);
929 AHD_ASSERT_MODES(ahd, ~(AHD_MODE_UNKNOWN_MSK|AHD_MODE_CFG_MSK),
931 scbid = ahd_get_scbptr(ahd);
932 scb = ahd_lookup_scb(ahd, scbid);
941 ahd_outb(ahd, SAVED_SCSIID, scb->hscb->scsiid);
942 ahd_outb(ahd, SAVED_LUN, scb->hscb->lun);
943 ahd_outb(ahd, SEQ_FLAGS, 0x0);
945 if ((ahd_inb(ahd, LQISTAT2) & LQIPHASE_OUTPKT) != 0
946 && (ahd_inb(ahd, SCSISIGO) & ATNO) != 0) {
955 "P0 assertion\n", ahd_name(ahd));
960 printf("%s: Entering NONPACK\n", ahd_name(ahd));
966 ahd_name(ahd));
967 ahd_dump_card_state(ahd);
968 ahd_reset_channel(ahd, 'A', /*Initiate Reset*/TRUE);
975 scbid = ahd_get_scbptr(ahd);
976 scb = ahd_lookup_scb(ahd, scbid);
978 ahd_print_path(ahd, scb);
980 printf("%s: ", ahd_name(ahd));
982 ahd_dump_card_state(ahd);
983 ahd_reset_channel(ahd, 'A', /*Initiate Reset*/TRUE);
991 scbid = ahd_get_scbptr(ahd);
992 scb = ahd_lookup_scb(ahd, scbid);
994 ahd_dump_card_state(ahd);
998 ahd_outq(ahd, HADDR, scb->sense_busaddr);
999 ahd_outw(ahd, HCNT, AHD_SENSE_BUFSIZE);
1000 ahd_outb(ahd, HCNT + 2, 0);
1001 ahd_outb(ahd, SG_CACHE_PRE, SG_LAST_SEG);
1002 ahd_outb(ahd, DFCNTRL, PRELOADEN|SCSIEN|HDMAEN);
1009 bus_phase = ahd_inb(ahd, SCSISIGI) & PHASE_MASK;
1011 ahd_name(ahd), bus_phase);
1021 ahd_reset_channel(ahd, 'A', /*Initiate Reset*/TRUE);
1022 printf("%s: Issued Bus Reset.\n", ahd_name(ahd));
1045 scbid = ahd_get_scbptr(ahd);
1046 scb = ahd_lookup_scb(ahd, scbid);
1050 ahd_reset_channel(ahd, 'A',
1055 SCB_GET_TARGET(ahd, scb),
1057 SCB_GET_CHANNEL(ahd, scb),
1060 targ_info = ahd_fetch_transinfo(ahd,
1066 ahd_set_width(ahd, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
1068 ahd_set_syncrate(ahd, &devinfo, /*period*/0,
1071 ahd_outb(ahd, SCB_CDB_STORE, 0);
1072 ahd_outb(ahd, SCB_CDB_STORE+1, 0);
1073 ahd_outb(ahd, SCB_CDB_STORE+2, 0);
1074 ahd_outb(ahd, SCB_CDB_STORE+3, 0);
1075 ahd_outb(ahd, SCB_CDB_STORE+4, 0);
1076 ahd_outb(ahd, SCB_CDB_STORE+5, 0);
1077 ahd_outb(ahd, SCB_CDB_LEN, 6);
1080 ahd_outb(ahd, SCB_CONTROL, scb->hscb->control);
1081 ahd_outb(ahd, MSG_OUT, HOST_MSG);
1082 ahd_outb(ahd, SAVED_SCSIID, scb->hscb->scsiid);
1087 ahd_outb(ahd, SAVED_LUN, 0);
1088 ahd_outb(ahd, SEQ_FLAGS, 0);
1089 ahd_assert_atn(ahd);
1092 ahd_freeze_devq(ahd, scb);
1100 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
1101 ahd_outb(ahd, CLRLQOINT1, CLRLQOPHACHGINPKT);
1102 if ((ahd->bugs & AHD_CLRLQO_AUTOCLR_BUG) != 0) {
1103 ahd_outb(ahd, CLRLQOINT1, 0);
1107 ahd_print_path(ahd, scb);
1124 printf("%s: CFG4OVERRUN mode = %x\n", ahd_name(ahd),
1125 ahd_inb(ahd, MODE_PTR));
1128 scb_index = ahd_get_scbptr(ahd);
1129 scb = ahd_lookup_scb(ahd, scb_index);
1135 ahd_assert_atn(ahd);
1136 ahd_outb(ahd, MSG_OUT, HOST_MSG);
1137 ahd->msgout_buf[0] = MSG_ABORT_TASK;
1138 ahd->msgout_len = 1;
1139 ahd->msgout_index = 0;
1140 ahd->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
1145 ahd_outb(ahd, SCB_CONTROL,
1146 ahd_inb_scbram(ahd, SCB_CONTROL)
1153 ahd_dump_card_state(ahd);
1162 ahd_name(ahd), ahd_inb(ahd, DFCNTRL),
1163 ahd_inb(ahd, SG_CACHE_SHADOW));
1166 ahd_reinitialize_dataptrs(ahd);
1184 ahd_fetch_devinfo(ahd, &devinfo);
1185 if (ahd->msg_type == MSG_TYPE_NONE) {
1190 bus_phase = ahd_inb(ahd, SCSISIGI) & PHASE_MASK;
1199 ahd_dump_card_state(ahd);
1200 ahd_clear_intstat(ahd);
1201 ahd_restart(ahd);
1205 scb_index = ahd_get_scbptr(ahd);
1206 scb = ahd_lookup_scb(ahd, scb_index);
1209 ahd_setup_initiator_msgout(ahd,
1213 ahd->msg_type =
1215 ahd->msgin_index = 0;
1221 ahd->msg_type =
1223 ahd->msgin_index = 0;
1226 ahd_setup_target_msgin(ahd,
1233 ahd_handle_message_phase(ahd);
1239 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
1240 ahd_outb(ahd, SCSISEQ0, ahd_inb(ahd, SCSISEQ0) & ~ENSELO);
1244 ahd_name(ahd), 'A', ahd_inb(ahd, SELID) >> 4);
1247 ahd_inb(ahd, SAVED_SCSIID), ahd_inb(ahd, SAVED_LUN),
1248 ahd_inw(ahd, REG0), ahd_inb(ahd, ACCUM));
1251 ahd_inb(ahd, SEQ_FLAGS), ahd_get_scbptr(ahd),
1252 ahd_find_busy_tcl(ahd,
1253 BUILD_TCL(ahd_inb(ahd, SAVED_SCSIID),
1254 ahd_inb(ahd, SAVED_LUN))),
1255 ahd_inw(ahd, SINDEX));
1258 ahd_inb(ahd, SELID), ahd_inb_scbram(ahd, SCB_SCSIID),
1259 ahd_inb_scbram(ahd, SCB_LUN),
1260 ahd_inb_scbram(ahd, SCB_CONTROL));
1262 ahd_inb(ahd, SCSIBUS), ahd_inb(ahd, SCSISIGI));
1263 printf("SXFRCTL0 == 0x%x\n", ahd_inb(ahd, SXFRCTL0));
1264 printf("SEQCTL0 == 0x%x\n", ahd_inb(ahd, SEQCTL0));
1265 ahd_dump_card_state(ahd);
1266 ahd->msgout_buf[0] = MSG_BUS_DEV_RESET;
1267 ahd->msgout_len = 1;
1268 ahd->msgout_index = 0;
1269 ahd->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
1270 ahd_outb(ahd, MSG_OUT, HOST_MSG);
1271 ahd_assert_atn(ahd);
1276 ahd_handle_proto_violation(ahd);
1283 ahd_fetch_devinfo(ahd, &devinfo);
1284 ahd_handle_ign_wide_residue(ahd, &devinfo);
1291 lastphase = ahd_inb(ahd, LASTPHASE);
1294 ahd_name(ahd), 'A',
1295 SCSIID_TARGET(ahd, ahd_inb(ahd, SAVED_SCSIID)),
1296 lastphase, ahd_inb(ahd, SCSISIGI));
1303 lastphase = ahd_inb(ahd, LASTPHASE);
1306 ahd_name(ahd), 'A',
1307 SCSIID_TARGET(ahd, ahd_inb(ahd, SAVED_SCSIID)),
1308 lastphase, ahd_inb(ahd, SCSISIGI));
1309 ahd_restart(ahd);
1328 scbindex = ahd_get_scbptr(ahd);
1329 scb = ahd_lookup_scb(ahd, scbindex);
1331 lastphase = ahd_inb(ahd, LASTPHASE);
1333 ahd_print_path(ahd, scb);
1337 ahd_print_path(ahd, scb);
1340 ahd_inb(ahd, SEQ_FLAGS) & DPHASE
1351 ahd_freeze_devq(ahd, scb);
1362 ahd_fetch_devinfo(ahd, &devinfo);
1364 ahd_name(ahd), devinfo.channel, devinfo.target,
1366 scbid = ahd_get_scbptr(ahd);
1367 scb = ahd_lookup_scb(ahd, scbid);
1374 ahd_search_qinfifo(ahd, SCB_GET_TARGET(ahd, scb),
1375 SCB_GET_CHANNEL(ahd, scb),
1379 ahd_outb(ahd, SCB_CONTROL,
1380 ahd_inb_scbram(ahd, SCB_CONTROL) & ~MK_MESSAGE);
1388 scbid = ahd_get_scbptr(ahd);
1389 scb = ahd_lookup_scb(ahd, scbid);
1395 ahd_print_path(ahd, scb);
1409 ahd_abort_scbs(ahd, SCB_GET_TARGET(ahd, scb),
1420 ahd_scb_devinfo(ahd, &devinfo, scb);
1422 ahd_handle_devreset(ahd, &devinfo, lun,
1446 scbid = ahd_get_scbptr(ahd);
1447 scb = ahd_lookup_scb(ahd, scbid);
1453 ahd_print_path(ahd, scb);
1462 while ((ahd_inb(ahd, SCSISEQ0) & ENSELO) != 0
1463 && (ahd_inb(ahd, SSTAT0) & SELDO) == 0
1464 && (ahd_inb(ahd, SSTAT1) & SELTO) == 0)
1466 ahd_outb(ahd, SCB_TASK_MANAGEMENT, 0);
1467 ahd_search_qinfifo(ahd, SCB_GET_TARGET(ahd, scb),
1468 SCB_GET_CHANNEL(ahd, scb),
1479 printf("%s: Tracepoint %d\n", ahd_name(ahd),
1485 ahd_handle_hwerrint(ahd);
1488 printf("%s: Unexpected SEQINTCODE %d\n", ahd_name(ahd),
1497 ahd_unpause(ahd);
1501 ahd_handle_scsiint(struct ahd_softc *ahd, u_int intstat)
1512 ahd_update_modes(ahd);
1513 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
1515 status3 = ahd_inb(ahd, SSTAT3) & (NTRAMPERR|OSRAMPERR);
1516 status0 = ahd_inb(ahd, SSTAT0) & (IOERR|OVERRUN|SELDI|SELDO);
1517 status = ahd_inb(ahd, SSTAT1) & (SELTO|SCSIRSTI|BUSFREE|SCSIPERR);
1518 lqistat1 = ahd_inb(ahd, LQISTAT1);
1519 lqostat0 = ahd_inb(ahd, LQOSTAT0);
1520 busfreetime = ahd_inb(ahd, SSTAT2) & BUSFREETIME;
1524 ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
1525 simode0 = ahd_inb(ahd, SIMODE0);
1527 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
1529 scbid = ahd_get_scbptr(ahd);
1530 scb = ahd_lookup_scb(ahd, scbid);
1532 && (ahd_inb(ahd, SEQ_FLAGS) & NOT_IDENTIFIED) != 0)
1536 ahd_clear_critical_section(ahd);
1541 now_lvd = ahd_inb(ahd, SBLKCTL) & ENAB40;
1543 ahd_name(ahd), now_lvd ? "LVD" : "SE");
1544 ahd_outb(ahd, CLRSINT0, CLRIOERR);
1548 ahd_reset_channel(ahd, 'A', /*Initiate Reset*/TRUE);
1549 ahd_pause(ahd);
1550 ahd_setup_iocell_workaround(ahd);
1551 ahd_unpause(ahd);
1554 ahd_name(ahd));
1555 ahd_reset_channel(ahd, 'A', /*Initiate Reset*/TRUE);
1557 printf("%s: Someone reset channel A\n", ahd_name(ahd));
1558 ahd_reset_channel(ahd, 'A', /*Initiate Reset*/FALSE);
1560 ahd_handle_transmission_error(ahd);
1562 printf("%s: lqostat0 == 0x%x!\n", ahd_name(ahd), lqostat0);
1563 ahd_outb(ahd, CLRLQOINT0, lqostat0);
1564 if ((ahd->bugs & AHD_CLRLQO_AUTOCLR_BUG) != 0) {
1565 ahd_outb(ahd, CLRLQOINT1, 0);
1571 ahd_outb(ahd, SCSISEQ0, 0);
1574 ahd_clear_msg_state(ahd);
1577 ahd_outb(ahd, CLRSINT1, CLRSELTIMEO|CLRBUSFREE|CLRSCSIPERR);
1587 ahd_outb(ahd, CLRSINT0, CLRSELINGO);
1589 scbid1 = ahd_inw(ahd, WAITING_TID_HEAD);
1590 scb = ahd_lookup_scb(ahd, scbid1);
1594 ahd_name(ahd), scbid1);
1595 ahd_dump_card_state(ahd);
1600 ahd_print_path(ahd, scb);
1614 ahd_scb_devinfo(ahd, &devinfo, scb);
1615 ahd_force_renegotiation(ahd, &devinfo);
1617 ahd_freeze_devq(ahd, scb);
1619 ahd_outb(ahd, CLRINT, CLRSCSIINT);
1620 ahd_iocell_first_selection(ahd);
1621 ahd_unpause(ahd);
1623 ahd_iocell_first_selection(ahd);
1624 ahd_unpause(ahd);
1627 ahd_name(ahd), status3);
1628 ahd_outb(ahd, CLRSINT3, status3);
1630 ahd_handle_lqiphase_error(ahd, lqistat1);
1638 ahd_outb(ahd, CLRLQIINT1, CLRLQICRCI_NLQ);
1652 ahd_outb(ahd, SCSISEQ0, 0);
1659 busfreetime = ahd_inb(ahd, SSTAT2) & BUSFREETIME;
1660 lqostat1 = ahd_inb(ahd, LQOSTAT1);
1670 ahd_set_modes(ahd, mode, mode);
1671 scbid1 = ahd_get_scbptr(ahd);
1672 scb1 = ahd_lookup_scb(ahd, scbid1);
1676 ahd_name(ahd), scbid1, mode);
1692 && ahd_inb(ahd, LASTPHASE) == P_BUSFREE)
1706 if (packetized && ahd_inb(ahd, LASTPHASE) == P_BUSFREE) {
1707 restart = ahd_handle_pkt_busfree(ahd, busfreetime);
1710 restart = ahd_handle_nonpkt_busfree(ahd);
1723 ahd_outb(ahd, CLRSINT1, CLRBUSFREE);
1725 && (ahd->bugs & AHD_BUSFREEREV_BUG) != 0)
1726 ahd_outb(ahd, SIMODE1,
1727 ahd_inb(ahd, SIMODE1) & ~ENBUSFREE);
1730 ahd_clear_fifo(ahd, mode);
1732 ahd_clear_msg_state(ahd);
1733 ahd_outb(ahd, CLRINT, CLRSCSIINT);
1735 ahd_restart(ahd);
1737 ahd_unpause(ahd);
1741 ahd_name(ahd), status);
1742 ahd_dump_card_state(ahd);
1743 ahd_clear_intstat(ahd);
1744 ahd_unpause(ahd);
1749 ahd_handle_transmission_error(struct ahd_softc *ahd)
1762 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
1763 lqistat1 = ahd_inb(ahd, LQISTAT1) & ~(LQIPHASE_LQ|LQIPHASE_NLQ);
1764 (void)ahd_inb(ahd, LQISTAT2);
1766 && (ahd->bugs & AHD_NLQICRC_DELAYED_BUG) != 0) {
1769 ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
1770 lqistate = ahd_inb(ahd, LQISTATE);
1776 ahd_name(ahd));
1781 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
1784 ahd_outb(ahd, CLRLQIINT1, lqistat1);
1785 lastphase = ahd_inb(ahd, LASTPHASE);
1786 curphase = ahd_inb(ahd, SCSISIGI) & PHASE_MASK;
1787 perrdiag = ahd_inb(ahd, PERRDIAG);
1789 ahd_outb(ahd, CLRSINT1, CLRSCSIPERR);
1798 ahd_set_active_fifo(ahd);
1799 scbid = ahd_get_scbptr(ahd);
1800 scb = ahd_lookup_scb(ahd, scbid);
1807 printf("%s: Transmission error detected\n", ahd_name(ahd));
1813 ahd_dump_card_state(ahd);
1820 ahd_name(ahd), lqistat1);
1822 ahd_reset_channel(ahd, 'A', /*Initiate Reset*/TRUE);
1846 ahd_outb(ahd, LQCTL2, LQIRETRY);
1898 "Resetting bus\n", ahd_name(ahd));
1899 ahd_reset_channel(ahd, 'A', /*Initiate Reset*/TRUE);
1904 ahd_reset_channel(ahd, 'A', /*Initiate Reset*/TRUE);
1912 ahd_inb(ahd, SCSIDAT);
1926 ahd->send_msg_perror = msg_out;
1929 ahd_outb(ahd, MSG_OUT, HOST_MSG);
1930 ahd_outb(ahd, CLRINT, CLRSCSIINT);
1931 ahd_unpause(ahd);
1935 ahd_handle_lqiphase_error(struct ahd_softc *ahd, u_int lqistat1)
1940 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
1941 ahd_outb(ahd, CLRLQIINT1, lqistat1);
1951 ahd_set_active_fifo(ahd);
1952 if ((ahd_inb(ahd, SCSISIGO) & ATNO) != 0
1953 && (ahd_inb(ahd, MDFFSTAT) & DLZERO) != 0) {
1956 ahd_outb(ahd, LQCTL2, LQIRETRY);
1959 ahd_outb(ahd, LQCTL2, LQIRETRY);
1962 ahd_dump_card_state(ahd);
1963 ahd_outb(ahd, CLRINT, CLRSCSIINT);
1964 ahd_unpause(ahd);
1967 ahd_dump_card_state(ahd);
1968 ahd_reset_channel(ahd, 'A', /*Initiate Reset*/TRUE);
1977 ahd_handle_pkt_busfree(struct ahd_softc *ahd, u_int busfreetime)
1981 AHD_ASSERT_MODES(ahd, ~(AHD_MODE_UNKNOWN_MSK|AHD_MODE_CFG_MSK),
1983 lqostat1 = ahd_inb(ahd, LQOSTAT1);
1995 ahd_name(ahd), busfreetime);
2011 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
2012 scbid = ahd_inw(ahd, CURRSCB);
2013 scb = ahd_lookup_scb(ahd, scbid);
2019 ahd_outb(ahd, CLRLQOINT1, CLRLQOBUSFREE);
2020 if ((ahd->bugs & AHD_CLRLQO_AUTOCLR_BUG) != 0)
2021 ahd_outb(ahd, CLRLQOINT1, 0);
2022 ahd_outb(ahd, SCSISEQ0, ahd_inb(ahd, SCSISEQ0) & ~ENSELO);
2023 ahd_flush_device_writes(ahd);
2024 ahd_outb(ahd, CLRSINT0, CLRSELDO);
2032 ahd_outb(ahd, LQCTL2, ahd_inb(ahd, LQCTL2) | LQOTOIDLE);
2038 waiting_h = ahd_inw(ahd, WAITING_TID_HEAD);
2039 saved_scbptr = ahd_get_scbptr(ahd);
2042 ahd_outw(ahd, WAITING_TID_HEAD, scbid);
2043 waiting_t = ahd_inw(ahd, WAITING_TID_TAIL);
2045 ahd_outw(ahd, WAITING_TID_TAIL, scbid);
2048 ahd_set_scbptr(ahd, waiting_h);
2049 next = ahd_inw_scbram(ahd, SCB_NEXT2);
2051 ahd_set_scbptr(ahd, scbid);
2052 ahd_outw(ahd, SCB_NEXT2, next);
2054 ahd_set_scbptr(ahd, saved_scbptr);
2057 ahd_print_path(ahd, scb);
2065 ahd_freeze_devq(ahd, scb);
2069 } else if ((ahd_inb(ahd, PERRDIAG) & PARITYERR) != 0) {
2077 ahd_outb(ahd, CLRSINT1, CLRSCSIPERR|CLRBUSFREE);
2082 ahd_name(ahd));
2087 if (ahd->src_mode != AHD_MODE_SCSI) {
2091 scbid = ahd_get_scbptr(ahd);
2092 scb = ahd_lookup_scb(ahd, scbid);
2093 ahd_print_path(ahd, scb);
2095 ahd_dump_card_state(ahd);
2096 ahd_abort_scbs(ahd, SCB_GET_TARGET(ahd, scb), 'A',
2103 printf("%s: Unexpected PKT busfree condition\n", ahd_name(ahd));
2104 ahd_dump_card_state(ahd);
2113 ahd_handle_nonpkt_busfree(struct ahd_softc *ahd)
2131 lastphase = ahd_inb(ahd, LASTPHASE);
2132 saved_scsiid = ahd_inb(ahd, SAVED_SCSIID);
2133 saved_lun = ahd_inb(ahd, SAVED_LUN);
2134 target = SCSIID_TARGET(ahd, saved_scsiid);
2140 scbid = ahd_get_scbptr(ahd);
2141 scb = ahd_lookup_scb(ahd, scbid);
2143 && (ahd_inb(ahd, SEQ_FLAGS) & NOT_IDENTIFIED) != 0)
2146 ppr_busfree = (ahd->msg_flags & MSG_FLAG_EXPECT_PPR_BUSFREE) != 0;
2151 if (ahd_sent_msg(ahd, AHDMSG_1B, MSG_ABORT_TAG, TRUE)
2152 || ahd_sent_msg(ahd, AHDMSG_1B, MSG_ABORT, TRUE)) {
2157 ahd_print_devinfo(ahd, &devinfo);
2163 sent_msg = ahd->msgout_buf[ahd->msgout_index - 1];
2164 ahd_print_path(ahd, scb);
2188 found = ahd_abort_scbs(ahd, target, 'A', saved_lun,
2193 } else if (ahd_sent_msg(ahd, AHDMSG_1B,
2203 ahd, scb, target, 'A',
2208 ahd_handle_devreset(ahd, &devinfo, CAM_LUN_WILDCARD,
2212 } else if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_PPR, FALSE)
2225 tinfo = ahd_fetch_transinfo(ahd, devinfo.channel,
2231 ahd_qinfifo_requeue_tail(ahd, scb);
2233 } else if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_WDTR, FALSE)
2243 ahd_set_width(ahd, &devinfo,
2247 ahd_qinfifo_requeue_tail(ahd, scb);
2249 } else if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_SDTR, FALSE)
2259 ahd_set_syncrate(ahd, &devinfo,
2264 ahd_qinfifo_requeue_tail(ahd, scb);
2266 } else if ((ahd->msg_flags & MSG_FLAG_EXPECT_IDE_BUSFREE) != 0
2267 && ahd_sent_msg(ahd, AHDMSG_1B,
2275 } else if ((ahd->msg_flags & MSG_FLAG_EXPECT_QASREJ_BUSFREE)
2276 && ahd_sent_msg(ahd, AHDMSG_1B,
2294 && ((ahd->msg_flags & MSG_FLAG_EXPECT_PPR_BUSFREE) != 0)) {
2296 ahd_freeze_devq(ahd, scb);
2299 if ((ahd->msg_flags & MSG_FLAG_IU_REQ_CHANGED) != 0) {
2300 ahd_abort_scbs(ahd, SCB_GET_TARGET(ahd, scb),
2301 SCB_GET_CHANNEL(ahd, scb),
2309 ahd_done(ahd, scb);
2324 ahd_print_path(ahd, scb);
2325 aborted = ahd_abort_scbs(ahd, target, 'A',
2334 printf("%s: ", ahd_name(ahd));
2337 ahd_force_renegotiation(ahd, &devinfo);
2342 ahd_inb(ahd, PRGMCNT)
2343 | (ahd_inb(ahd, PRGMCNT+1) << 8));
2344 ahd_dump_card_state(ahd);
2351 ahd_handle_proto_violation(struct ahd_softc *ahd)
2361 ahd_fetch_devinfo(ahd, &devinfo);
2362 scbid = ahd_get_scbptr(ahd);
2363 scb = ahd_lookup_scb(ahd, scbid);
2364 seq_flags = ahd_inb(ahd, SEQ_FLAGS);
2365 curphase = ahd_inb(ahd, SCSISIGI) & PHASE_MASK;
2366 lastphase = ahd_inb(ahd, LASTPHASE);
2374 ahd_print_devinfo(ahd, &devinfo);
2383 ahd_print_devinfo(ahd, &devinfo);
2389 ahd_print_path(ahd, scb);
2391 } else if ((ahd_inb_scbram(ahd, SCB_CONTROL)
2400 ahd_print_path(ahd, scb);
2403 ahd_print_path(ahd, scb);
2405 ahd_dump_card_state(ahd);
2417 found = ahd_reset_channel(ahd, 'A', TRUE);
2419 "%d SCBs aborted\n", ahd_name(ahd), 'A', found);
2426 ahd_outb(ahd, SCSISEQ0,
2427 ahd_inb(ahd, SCSISEQ0) & ~ENSELO);
2428 ahd_assert_atn(ahd);
2429 ahd_outb(ahd, MSG_OUT, HOST_MSG);
2431 ahd_print_devinfo(ahd, &devinfo);
2432 ahd->msgout_buf[0] = MSG_ABORT_TASK;
2433 ahd->msgout_len = 1;
2434 ahd->msgout_index = 0;
2435 ahd->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
2437 ahd_print_path(ahd, scb);
2450 ahd_force_renegotiation(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
2457 ahd_print_devinfo(ahd, devinfo);
2461 targ_info = ahd_fetch_transinfo(ahd,
2466 ahd_update_neg_request(ahd, devinfo, tstate,
2472 ahd_clear_critical_section(struct ahd_softc *ahd)
2486 if (ahd->num_critical_sections == 0)
2499 saved_modes = ahd_save_modes(ahd);
2505 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
2506 seqaddr = ahd_inb(ahd, CURADDR)
2507 | (ahd_inb(ahd, CURADDR+1) << 8);
2509 cs = ahd->critical_sections;
2510 for (i = 0; i < ahd->num_critical_sections; i++, cs++) {
2516 if (i == ahd->num_critical_sections)
2522 ahd_name(ahd), ahd_name(ahd), first_instr,
2524 ahd_dump_card_state(ahd);
2531 printf("%s: Single stepping at 0x%x\n", ahd_name(ahd),
2537 ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
2538 simode0 = ahd_inb(ahd, SIMODE0);
2539 simode3 = ahd_inb(ahd, SIMODE3);
2540 lqimode0 = ahd_inb(ahd, LQIMODE0);
2541 lqimode1 = ahd_inb(ahd, LQIMODE1);
2542 lqomode0 = ahd_inb(ahd, LQOMODE0);
2543 lqomode1 = ahd_inb(ahd, LQOMODE1);
2544 ahd_outb(ahd, SIMODE0, 0);
2545 ahd_outb(ahd, SIMODE3, 0);
2546 ahd_outb(ahd, LQIMODE0, 0);
2547 ahd_outb(ahd, LQIMODE1, 0);
2548 ahd_outb(ahd, LQOMODE0, 0);
2549 ahd_outb(ahd, LQOMODE1, 0);
2550 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
2551 simode1 = ahd_inb(ahd, SIMODE1);
2558 ahd_outb(ahd, SIMODE1, simode1 & ENBUSFREE);
2559 ahd_outb(ahd, SEQCTL0, ahd_inb(ahd, SEQCTL0) | STEP);
2562 ahd_outb(ahd, CLRSINT1, CLRBUSFREE);
2563 ahd_outb(ahd, CLRINT, CLRSCSIINT);
2564 ahd_set_modes(ahd, ahd->saved_src_mode, ahd->saved_dst_mode);
2565 ahd_outb(ahd, HCNTRL, ahd->unpause);
2566 while (!ahd_is_paused(ahd))
2568 ahd_update_modes(ahd);
2571 ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
2572 ahd_outb(ahd, SIMODE0, simode0);
2573 ahd_outb(ahd, SIMODE3, simode3);
2574 ahd_outb(ahd, LQIMODE0, lqimode0);
2575 ahd_outb(ahd, LQIMODE1, lqimode1);
2576 ahd_outb(ahd, LQOMODE0, lqomode0);
2577 ahd_outb(ahd, LQOMODE1, lqomode1);
2578 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
2579 ahd_outb(ahd, SEQCTL0, ahd_inb(ahd, SEQCTL0) & ~STEP);
2580 ahd_outb(ahd, SIMODE1, simode1);
2587 ahd_outb(ahd, CLRINT, CLRSCSIINT);
2589 ahd_restore_modes(ahd, saved_modes);
2596 ahd_clear_intstat(struct ahd_softc *ahd)
2598 AHD_ASSERT_MODES(ahd, ~(AHD_MODE_UNKNOWN_MSK|AHD_MODE_CFG_MSK),
2601 ahd_outb(ahd, CLRLQIINT0, CLRLQIATNQAS|CLRLQICRCT1|CLRLQICRCT2
2603 ahd_outb(ahd, CLRLQIINT1, CLRLQIPHASE_LQ|CLRLQIPHASE_NLQ|CLRLIQABORT
2606 ahd_outb(ahd, CLRLQOINT0, CLRLQOTARGSCBPERR|CLRLQOSTOPT2|CLRLQOATNLQ
2608 ahd_outb(ahd, CLRLQOINT1, CLRLQOINITSCBPERR|CLRLQOSTOPI2|CLRLQOBADQAS
2610 if ((ahd->bugs & AHD_CLRLQO_AUTOCLR_BUG) != 0) {
2611 ahd_outb(ahd, CLRLQOINT0, 0);
2612 ahd_outb(ahd, CLRLQOINT1, 0);
2614 ahd_outb(ahd, CLRSINT3, CLRNTRAMPERR|CLROSRAMPERR);
2615 ahd_outb(ahd, CLRSINT1, CLRSELTIMEO|CLRATNO|CLRSCSIRSTI
2617 ahd_outb(ahd, CLRSINT0, CLRSELDO|CLRSELDI|CLRSELINGO
2619 ahd_outb(ahd, CLRINT, CLRSCSIINT);
2698 ahd_alloc_tstate(struct ahd_softc *ahd, u_int scsi_id, char channel)
2704 master_tstate = ahd->enabled_targets[ahd->our_id];
2705 if (ahd->enabled_targets[scsi_id] != NULL
2706 && ahd->enabled_targets[scsi_id] != master_tstate)
2708 ahd_name(ahd));
2728 ahd->enabled_targets[scsi_id] = tstate;
2738 ahd_free_tstate(struct ahd_softc *ahd, u_int scsi_id, char channel, int force)
2746 if (scsi_id == ahd->our_id
2750 tstate = ahd->enabled_targets[scsi_id];
2753 ahd->enabled_targets[scsi_id] = NULL;
2764 ahd_devlimited_syncrate(struct ahd_softc *ahd,
2771 if ((ahd_inb(ahd, SBLKCTL) & ENAB40) != 0
2772 && (ahd_inb(ahd, SSTAT2) & EXP_ACTIVE) == 0) {
2803 ahd_find_syncrate(ahd, period, ppr_options, maxsync);
2813 ahd_find_syncrate(struct ahd_softc *ahd, u_int *period,
2852 ahd_validate_offset(struct ahd_softc *ahd,
2863 if ((ahd->bugs & AHD_PACED_NEGTABLE_BUG) != 0)
2883 ahd_validate_width(struct ahd_softc *ahd, struct ahd_initiator_tinfo *tinfo,
2888 if (ahd->features & AHD_WIDE) {
2913 ahd_update_neg_request(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
2927 if ((ahd->features & AHD_WIDE) != 0)
2956 ahd_set_syncrate(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
2976 tinfo = ahd_fetch_transinfo(ahd, devinfo->channel, devinfo->our_scsiid,
3006 ahd_send_async(ahd, devinfo->channel, devinfo->target,
3015 ahd_name(ahd), devinfo->target,
3045 ahd_name(ahd), devinfo->target,
3061 ahd_pause(ahd);
3062 ahd_update_neg_table(ahd, devinfo, &tinfo->curr);
3064 ahd_unpause(ahd);
3065 if (ahd->msg_type != MSG_TYPE_NONE) {
3070 ahd_print_devinfo(ahd, devinfo);
3074 ahd->msg_flags |= MSG_FLAG_EXPECT_PPR_BUSFREE
3082 ahd->msg_flags |= MSG_FLAG_EXPECT_PPR_BUSFREE;
3087 update_needed += ahd_update_neg_request(ahd, devinfo, tstate,
3091 ahd_update_pending_scbs(ahd);
3103 ahd_set_width(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
3114 tinfo = ahd_fetch_transinfo(ahd, devinfo->channel, devinfo->our_scsiid,
3129 ahd_send_async(ahd, devinfo->channel, devinfo->target,
3134 ahd_name(ahd), devinfo->target,
3141 ahd_pause(ahd);
3142 ahd_update_neg_table(ahd, devinfo, &tinfo->curr);
3144 ahd_unpause(ahd);
3147 update_needed += ahd_update_neg_request(ahd, devinfo, tstate,
3150 ahd_update_pending_scbs(ahd);
3158 ahd_set_tags(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
3161 ahd_platform_set_tags(ahd, devinfo, alg);
3162 ahd_send_async(ahd, devinfo->channel, devinfo->target,
3167 ahd_update_neg_table(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
3176 uint8_t iocell_opts[sizeof(ahd->iocell_opts)];
3178 saved_modes = ahd_save_modes(ahd);
3179 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
3181 saved_negoaddr = ahd_inb(ahd, NEGOADDR);
3182 ahd_outb(ahd, NEGOADDR, devinfo->target);
3185 memcpy(iocell_opts, ahd->iocell_opts, sizeof(ahd->iocell_opts));
3193 if ((ahd->bugs & AHD_PACED_NEGTABLE_BUG) != 0) {
3225 if ((ahd->features & AHD_NEW_IOCELL_OPTS) != 0
3236 ahd_outb(ahd, ANNEXCOL, AHD_ANNEXCOL_PRECOMP_SLEW);
3237 ahd_outb(ahd, ANNEXDAT, iocell_opts[AHD_PRECOMP_SLEW_INDEX]);
3238 ahd_outb(ahd, ANNEXCOL, AHD_ANNEXCOL_AMPLITUDE);
3239 ahd_outb(ahd, ANNEXDAT, iocell_opts[AHD_AMPLITUDE_INDEX]);
3241 ahd_outb(ahd, NEGPERIOD, period);
3242 ahd_outb(ahd, NEGPPROPTS, ppr_opts);
3243 ahd_outb(ahd, NEGOFFSET, offset);
3255 ahd_outb(ahd, NEGCONOPTS, con_opts);
3256 ahd_outb(ahd, NEGOADDR, saved_negoaddr);
3257 ahd_restore_modes(ahd, saved_modes);
3267 ahd_update_pending_scbs(struct ahd_softc *ahd)
3287 LIST_FOREACH(pending_scb, &ahd->pending_scbs, pending_links) {
3292 ahd_scb_devinfo(ahd, &devinfo, pending_scb);
3293 (void)ahd_fetch_transinfo(ahd, devinfo.channel,
3302 ahd_sync_scb(ahd, pending_scb,
3310 if (ahd_is_paused(ahd)) {
3314 ahd_pause(ahd);
3323 saved_modes = ahd_save_modes(ahd);
3324 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
3325 ahd_outb(ahd, SCSISEQ0, ahd_inb(ahd, SCSISEQ0) & ~ENSELO);
3326 saved_scbptr = ahd_get_scbptr(ahd);
3328 for (scb_tag = 0; scb_tag < ahd->scb_data.maxhscbs; scb_tag++) {
3332 pending_scb = ahd_lookup_scb(ahd, scb_tag);
3335 ahd_set_scbptr(ahd, scb_tag);
3337 control = ahd_inb_scbram(ahd, SCB_CONTROL);
3340 ahd_outb(ahd, SCB_CONTROL, control);
3342 ahd_set_scbptr(ahd
3343 ahd_restore_modes(ahd, saved_modes);
3346 ahd_unpause(ahd);
3351 ahd_fetch_devinfo(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
3358 saved_modes = ahd_save_modes(ahd);
3359 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
3361 if (ahd_inb(ahd, SSTAT0) & TARGET)
3367 && (ahd_inb(ahd, SEQ_FLAGS) & CMDPHASE_PENDING) != 0) {
3369 our_id = ahd_inb(ahd, TARGIDIN) & OID;
3371 our_id = ahd_inb(ahd, TOWNID);
3373 our_id = ahd_inb(ahd, IOWNID);
3375 saved_scsiid = ahd_inb(ahd, SAVED_SCSIID);
3378 SCSIID_TARGET(ahd, saved_scsiid),
3379 ahd_inb(ahd, SAVED_LUN),
3380 SCSIID_CHANNEL(ahd, saved_scsiid),
3382 ahd_restore_modes(ahd, saved_modes);
3386 ahd_print_devinfo(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
3388 printf("%s:%c:%d:%d: (0x%x) ", ahd_name(ahd), 'A',
3389 devinfo->target, devinfo->lun, ahd_get_scbptr(ahd));
3426 ahd_scb_devinfo(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
3436 ahd_compile_devinfo(devinfo, our_id, SCB_GET_TARGET(ahd, scb),
3437 SCB_GET_LUN(scb), SCB_GET_CHANNEL(ahd, scb), role);
3449 ahd_setup_initiator_msgout(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
3457 ahd->msgout_index = 0;
3458 ahd->msgout_len = 0;
3460 if (ahd_currently_packetized(ahd))
3461 ahd->msg_flags |= MSG_FLAG_PACKETIZED;
3463 if (ahd->send_msg_perror
3464 && ahd_inb(ahd, MSG_OUT) == HOST_MSG) {
3465 ahd->msgout_buf[ahd->msgout_index++] = ahd->send_msg_perror;
3466 ahd->msgout_len++;
3467 ahd->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
3475 "I_T msgin. Issuing NO-OP\n", ahd_name(ahd));
3476 ahd->msgout_buf[ahd->msgout_index++] = MSG_NOOP;
3477 ahd->msgout_len++;
3478 ahd->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
3484 && ahd_inb(ahd, MSG_OUT) == MSG_IDENTIFYFLAG) {
3490 ahd->msgout_buf[ahd->msgout_index++] = identify_msg;
3491 ahd->msgout_len++;
3494 ahd->msgout_buf[ahd->msgout_index++] =
3496 ahd->msgout_buf[ahd->msgout_index++] = SCB_GET_TAG(scb);
3497 ahd->msgout_len += 2;
3502 ahd->msgout_buf[ahd->msgout_index++] = MSG_BUS_DEV_RESET;
3503 ahd->msgout_len++;
3504 ahd_print_path(ahd, scb);
3513 ahd_outb(ahd, SCSISEQ0, 0);
3517 ahd->msgout_buf[ahd->msgout_index++] = MSG_ABORT_TAG;
3519 ahd->msgout_buf[ahd->msgout_index++] = MSG_ABORT;
3521 ahd->msgout_len++;
3522 ahd_print_path(ahd, scb);
3532 ahd_outb(ahd, SCSISEQ0, 0);
3534 ahd_build_transfer_msg(ahd, devinfo);
3542 ahd_outb(ahd, SCSISEQ0, 0);
3550 ahd_inb_scbram(ahd, SCB_CONTROL), ahd_inb(ahd, MSG_OUT),
3558 ahd_outb(ahd, SCB_CONTROL,
3559 ahd_inb_scbram(ahd, SCB_CONTROL) & ~MK_MESSAGE);
3561 ahd->msgout_index = 0;
3562 ahd->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
3570 ahd_build_transfer_msg(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
3586 tinfo = ahd_fetch_transinfo(ahd, devinfo->channel, devinfo->our_scsiid,
3600 ahd_devlimited_syncrate(ahd, tinfo, &period,
3621 if ((ahd->features & AHD_WIDE) != 0)
3627 ahd_print_devinfo(ahd, devinfo);
3646 ahd_validate_offset(ahd, tinfo, period, &offset,
3651 ahd_construct_ppr(ahd, devinfo, period, offset,
3654 ahd_construct_sdtr(ahd, devinfo, period, offset);
3657 ahd_construct_wdtr(ahd, devinfo, tinfo->goal.width);
3666 ahd_construct_sdtr(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
3671 ahd->msgout_buf[ahd->msgout_index++] = MSG_EXTENDED;
3672 ahd->msgout_buf[ahd->msgout_index++] = MSG_EXT_SDTR_LEN;
3673 ahd->msgout_buf[ahd->msgout_index++] = MSG_EXT_SDTR;
3674 ahd->msgout_buf[ahd->msgout_index++] = period;
3675 ahd->msgout_buf[ahd->msgout_index++] = offset;
3676 ahd->msgout_len += 5;
3679 ahd_name(ahd), devinfo->channel, devinfo->target,
3689 ahd_construct_wdtr(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
3692 ahd->msgout_buf[ahd->msgout_index++] = MSG_EXTENDED;
3693 ahd->msgout_buf[ahd->msgout_index++] = MSG_EXT_WDTR_LEN;
3694 ahd->msgout_buf[ahd->msgout_index++] = MSG_EXT_WDTR;
3695 ahd->msgout_buf[ahd->msgout_index++] = bus_width;
3696 ahd->msgout_len += 4;
3699 ahd_name(ahd), devinfo->channel, devinfo->target,
3709 ahd_construct_ppr(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
3722 ahd->msgout_buf[ahd->msgout_index++] = MSG_EXTENDED;
3723 ahd->msgout_buf[ahd->msgout_index++] = MSG_EXT_PPR_LEN;
3724 ahd->msgout_buf[ahd->msgout_index++] = MSG_EXT_PPR;
3725 ahd->msgout_buf[ahd->msgout_index++] = period;
3726 ahd->msgout_buf[ahd->msgout_index++] = 0;
3727 ahd->msgout_buf[ahd->msgout_index++] = offset;
3728 ahd->msgout_buf[ahd->msgout_index++] = bus_width;
3729 ahd->msgout_buf[ahd->msgout_index++] = ppr_options;
3730 ahd->msgout_len += 8;
3733 "offset 0x%x, ppr_options 0x%x\n", ahd_name(ahd),
3743 ahd_clear_msg_state(struct ahd_softc *ahd)
3747 saved_modes = ahd_save_modes(ahd);
3748 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
3749 ahd->send_msg_perror = 0;
3750 ahd->msg_flags = MSG_FLAG_NONE;
3751 ahd->msgout_len = 0;
3752 ahd->msgin_index = 0;
3753 ahd->msg_type = MSG_TYPE_NONE;
3754 if ((ahd_inb(ahd, SCSISIGO) & ATNO) != 0) {
3759 ahd_outb(ahd, CLRSINT1, CLRATNO);
3761 ahd_outb(ahd, MSG_OUT, MSG_NOOP);
3762 ahd_outb(ahd, SEQ_FLAGS2,
3763 ahd_inb(ahd, SEQ_FLAGS2) & ~TARGET_MSG_PENDING);
3764 ahd_restore_modes(ahd, saved_modes);
3771 ahd_handle_message_phase(struct ahd_softc *ahd)
3777 ahd_fetch_devinfo(ahd, &devinfo);
3779 bus_phase = ahd_inb(ahd, LASTPHASE);
3781 if ((ahd_inb(ahd, LQISTAT2) & LQIPHASE_OUTPKT) != 0) {
3783 ahd_outb(ahd, LQCTL2, LQIRETRY);
3786 switch (ahd->msg_type) {
3793 if (ahd->msgout_len == 0 && ahd->send_msg_perror == 0)
3798 ahd_print_devinfo(ahd, &devinfo);
3818 ahd_outb(ahd, CLRSINT1, CLRATNO);
3819 ahd->send_msg_perror = 0;
3820 ahd->msg_type = MSG_TYPE_INITIATOR_MSGIN;
3821 ahd->msgin_index = 0;
3828 if (ahd->send_msg_perror) {
3829 ahd_outb(ahd, CLRSINT1, CLRATNO);
3830 ahd_outb(ahd, CLRSINT1, CLRREQINIT);
3833 printf(" byte 0x%x\n", ahd->send_msg_perror);
3841 if ((ahd->msg_flags & MSG_FLAG_PACKETIZED) != 0
3842 && ahd->send_msg_perror == MSG_INITIATOR_DET_ERR)
3843 ahd->msg_flags |= MSG_FLAG_EXPECT_IDE_BUSFREE;
3845 ahd_outb(ahd, RETURN_2, ahd->send_msg_perror);
3846 ahd_outb(ahd, RETURN_1, CONT_MSG_LOOP_WRITE);
3850 msgdone = ahd->msgout_index == ahd->msgout_len;
3857 ahd->msgout_index = 0;
3858 ahd_assert_atn(ahd);
3861 lastbyte = ahd->msgout_index == (ahd->msgout_len - 1);
3864 ahd_outb(ahd, CLRSINT1, CLRATNO);
3871 ahd_outb(ahd, CLRSINT1, CLRREQINIT);
3875 ahd->msgout_buf[ahd->msgout_index]);
3877 ahd_outb(ahd, RETURN_2, ahd->msgout_buf[ahd->msgout_index++]);
3878 ahd_outb(ahd, RETURN_1, CONT_MSG_LOOP_WRITE);
3888 ahd_print_devinfo(ahd, &devinfo);
3901 ahd->msgin_index = 0;
3903 && (ahd->send_msg_perror != 0
3904 || (ahd->msgout_len != 0
3905 && ahd->msgout_index == 0))) {
3906 ahd->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
3914 ahd->msgin_buf[ahd->msgin_index] = ahd_inb(ahd, SCSIBUS);
3918 ahd->msgin_buf[ahd->msgin_index]);
3921 message_done = ahd_parse_msg(ahd, &devinfo);
3928 ahd->msgin_index = 0;
3935 if (ahd->msgout_len != 0) {
3938 ahd_print_devinfo(ahd, &devinfo);
3942 ahd_assert_atn(ahd);
3945 ahd->msgin_index++;
3951 ahd_outb(ahd, CLRSINT1, CLRREQINIT);
3952 ahd_outb(ahd, RETURN_1, CONT_MSG_LOOP_READ);
3964 ahd_outb(ahd, RETURN_1, CONT_MSG_LOOP_TARG);
3966 if (ahd->msgout_len == 0)
3975 if ((ahd_inb(ahd, SCSISIGI) & ATNI) != 0
3976 && ahd->msgout_index > 0)
3989 ahd->msg_type = MSG_TYPE_TARGET_MSGOUT;
3990 ahd_outb(ahd, SCSISIGO, P_MESGOUT | BSYO);
3991 ahd->msgin_index = 0;
3993 ahd_inb(ahd, SCSIDAT);
3994 ahd_outb(ahd, SXFRCTL0,
3995 ahd_inb(ahd, SXFRCTL0) | SPIOEN);
3999 msgdone = ahd->msgout_index == ahd->msgout_len;
4001 ahd_outb(ahd, SXFRCTL0,
4002 ahd_inb(ahd, SXFRCTL0) & ~SPIOEN);
4010 ahd_outb(ahd, SXFRCTL0, ahd_inb(ahd, SXFRCTL0) | SPIOEN);
4011 ahd_outb(ahd, SCSIDAT, ahd->msgout_buf[ahd->msgout_index++]);
4022 ahd_outb(ahd, RETURN_1, CONT_MSG_LOOP_TARG);
4028 lastbyte = (ahd_inb(ahd, SCSISIGI) & ATNI) == 0;
4035 ahd_outb(ahd, SXFRCTL0, ahd_inb(ahd, SXFRCTL0) & ~SPIOEN);
4036 ahd->msgin_buf[ahd->msgin_index] = ahd_inb(ahd, SCSIDAT);
4037 msgdone = ahd_parse_msg(ahd, &devinfo);
4048 ahd->msgin_index++;
4055 ahd->msgin_index = 0;
4061 if (ahd->msgout_len != 0) {
4062 ahd_outb(ahd, SCSISIGO, P_MESGIN | BSYO);
4063 ahd_outb(ahd, SXFRCTL0,
4064 ahd_inb(ahd, SXFRCTL0) | SPIOEN);
4065 ahd->msg_type = MSG_TYPE_TARGET_MSGIN;
4066 ahd->msgin_index = 0;
4075 ahd_outb(ahd, SXFRCTL0,
4076 ahd_inb(ahd, SXFRCTL0) | SPIOEN);
4086 if ((ahd->msg_flags & MSG_FLAG_PACKETIZED) != 0) {
4088 ahd_name(ahd));
4089 ahd_clear_msg_state(ahd);
4094 ahd_outb(ahd, LASTPHASE, P_BUSFREE);
4095 ahd_outb(ahd, SEQ_FLAGS, NOT_IDENTIFIED|NO_CDB_SENT);
4096 ahd_outb(ahd, SEQCTL0, FASTMODE|SEQRESET);
4098 ahd_clear_msg_state(ahd);
4099 ahd_outb(ahd, RETURN_1, EXIT_MSG_LOOP);
4111 ahd_sent_msg(struct ahd_softc *ahd, ahd_msgtype type, u_int msgval, int full)
4119 while (index < ahd->msgout_len) {
4120 if (ahd->msgout_buf[index] == MSG_EXTENDED) {
4123 end_index = index + 1 + ahd->msgout_buf[index + 1];
4124 if (ahd->msgout_buf[index+2] == msgval
4128 if (ahd->msgout_index > end_index)
4130 } else if (ahd->msgout_index > index)
4134 } else if (ahd->msgout_buf[index] >= MSG_SIMPLE_TASK
4135 && ahd->msgout_buf[index] <= MSG_IGN_WIDE_RESIDUE) {
4142 && ahd->msgout_index > index
4143 && (ahd->msgout_buf[index] == msgval
4144 || ((ahd->msgout_buf[index] & MSG_IDENTIFYFLAG) != 0
4160 ahd_parse_msg(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
4171 tinfo = ahd_fetch_transinfo(ahd, devinfo->channel, devinfo->our_scsiid,
4185 switch (ahd->msgin_buf[0]) {
4198 response = ahd_handle_msg_reject(ahd, devinfo);
4206 if (ahd->msgin_index < 2)
4208 switch (ahd->msgin_buf[2]) {
4216 if (ahd->msgin_buf[1] != MSG_EXT_SDTR_LEN) {
4228 if (ahd->msgin_index < (MSG_EXT_SDTR_LEN + 1))
4231 period = ahd->msgin_buf[3];
4233 saved_offset = offset = ahd->msgin_buf[4];
4234 ahd_devlimited_syncrate(ahd, tinfo, &period,
4236 ahd_validate_offset(ahd, tinfo, period, &offset,
4242 ahd_name(ahd), devinfo->channel,
4244 ahd->msgin_buf[3], saved_offset,
4247 ahd_set_syncrate(ahd, devinfo, period,
4257 if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_SDTR, TRUE)) {
4271 ahd_name(ahd), devinfo->channel,
4274 ahd->msgout_index = 0;
4275 ahd->msgout_len = 0;
4276 ahd_construct_sdtr(ahd, devinfo,
4278 ahd->msgout_index = 0;
4291 if (ahd->msgin_buf[1] != MSG_EXT_WDTR_LEN) {
4303 if (ahd->msgin_index < (MSG_EXT_WDTR_LEN + 1))
4306 bus_width = ahd->msgin_buf[3];
4308 ahd_validate_width(ahd, tinfo, &bus_width,
4313 ahd_name(ahd), devinfo->channel,
4318 if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_WDTR, TRUE)) {
4329 ahd_name(ahd), devinfo->channel,
4342 ahd_name(ahd), devinfo->channel,
4345 ahd->msgout_index = 0;
4346 ahd->msgout_len = 0;
4347 ahd_construct_wdtr(ahd, devinfo, bus_width);
4348 ahd->msgout_index = 0;
4361 ahd_update_neg_request(ahd, devinfo, tstate,
4363 ahd_set_width(ahd, devinfo, bus_width,
4371 ahd->msgout_index = 0;
4372 ahd->msgout_len = 0;
4373 ahd_build_transfer_msg(ahd, devinfo);
4374 ahd->msgout_index = 0;
4390 if (ahd->msgin_buf[1] != MSG_EXT_PPR_LEN) {
4402 if (ahd->msgin_index < (MSG_EXT_PPR_LEN + 1))
4405 period = ahd->msgin_buf[3];
4406 offset = ahd->msgin_buf[5];
4407 bus_width = ahd->msgin_buf[6];
4409 ppr_options = ahd->msgin_buf[7];
4428 ahd_validate_width(ahd, tinfo, &bus_width,
4430 ahd_devlimited_syncrate(ahd, tinfo, &period,
4432 ahd_validate_offset(ahd, tinfo, period, &offset,
4435 if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_PPR, TRUE)) {
4454 ahd_name(ahd), devinfo->channel,
4459 ahd_name(ahd), devinfo->channel,
4461 ahd->msgout_index = 0;
4462 ahd->msgout_len = 0;
4463 ahd_construct_ppr(ahd, devinfo, period, offset,
4465 ahd->msgout_index = 0;
4473 ahd_name(ahd), devinfo->channel,
4475 saved_width, ahd->msgin_buf[3],
4479 ahd_set_width(ahd, devinfo, bus_width,
4482 ahd_set_syncrate(ahd, devinfo, period,
4499 ahd_handle_devreset(ahd, devinfo, CAM_LUN_WILDCARD,
4503 ahd_restart(ahd);
4518 if (ahd->msgin_buf[0] == MSG_ABORT_TAG)
4519 tag = ahd_inb(ahd, INITIATOR_TAG);
4520 ahd_abort_scbs(ahd, devinfo->target, devinfo->channel,
4524 tstate = ahd->enabled_targets[devinfo->our_scsiid];
4530 ahd_queue_lstate_event(ahd, lstate,
4532 ahd->msgin_buf[0],
4534 ahd_send_lstate_events(ahd, lstate);
4537 ahd_restart(ahd);
4546 ahd_name(ahd), ahd_inb(ahd, SCSISIGI));
4548 ahd->msg_flags |= MSG_FLAG_EXPECT_QASREJ_BUSFREE;
4560 ahd->msgout_index = 0;
4561 ahd->msgout_len = 1;
4562 ahd->msgout_buf[0] = MSG_MESSAGE_REJECT;
4569 ahd->msgout_len = 0;
4578 ahd_handle_msg_reject(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
4593 scb_index = ahd_get_scbptr(ahd);
4594 scb = ahd_lookup_scb(ahd, scb_index);
4595 tinfo = ahd_fetch_transinfo(ahd, devinfo->channel,
4599 last_msg = ahd_inb(ahd, LAST_MSG);
4601 if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_PPR, /*full*/FALSE)) {
4602 if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_PPR, /*full*/TRUE)
4612 ahd_name(ahd), devinfo->channel,
4627 ahd_name(ahd), devinfo->channel,
4634 ahd->msgout_index = 0;
4635 ahd->msgout_len = 0;
4636 ahd_build_transfer_msg(ahd, devinfo);
4637 ahd->msgout_index = 0;
4639 } else if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_WDTR, /*full*/FALSE)) {
4643 "8bit transfers\n", ahd_name(ahd),
4645 ahd_set_width(ahd, devinfo, MSG_EXT_WDTR_BUS_8_BIT,
4658 ahd->msgout_index = 0;
4659 ahd->msgout_len = 0;
4660 ahd_build_transfer_msg(ahd, devinfo);
4661 ahd->msgout_index = 0;
4664 } else if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_SDTR, /*full*/FALSE)) {
4666 ahd_set_syncrate(ahd, devinfo, /*period*/0,
4672 ahd_name(ahd), devinfo->channel,
4682 "Performing non-tagged I/O\n", ahd_name(ahd),
4684 ahd_set_tags(ahd, devinfo, AHD_QUEUE_NONE);
4689 ahd_name(ahd), devinfo->channel, devinfo->target,
4692 ahd_set_tags(ahd, devinfo, AHD_QUEUE_BASIC);
4700 ahd_outb(ahd, SCB_CONTROL,
4701 ahd_inb_scbram(ahd, SCB_CONTROL) & mask);
4705 ahd_outb(ahd, MSG_OUT, MSG_IDENTIFYFLAG);
4706 ahd_assert_atn(ahd);
4707 ahd_busy_tcl(ahd, BUILD_TCL(scb->hscb->scsiid, devinfo->lun),
4715 ahd_search_qinfifo(ahd, SCB_GET_TARGET(ahd, scb),
4716 SCB_GET_CHANNEL(ahd, scb),
4720 } else if (ahd_sent_msg(ahd, AHDMSG_1B, MSG_IDENTIFYFLAG, TRUE)) {
4725 ahd->msg_flags |= MSG_FLAG_EXPECT_PPR_BUSFREE
4728 ahd_force_renegotiation(ahd, devinfo);
4729 ahd->msgout_index = 0;
4730 ahd->msgout_len = 0;
4731 ahd_build_transfer_msg(ahd, devinfo);
4732 ahd->msgout_index = 0;
4739 ahd_name(ahd), devinfo->channel, devinfo->target,
4749 ahd_handle_ign_wide_residue(struct ahd_softc *ahd,
4755 printf("%s: ahd_handle_ign_wide_residue\n", ahd_name(ahd));
4757 scb_index = ahd_get_scbptr(ahd);
4758 scb = ahd_lookup_scb(ahd, scb_index);
4763 if ((ahd_inb(ahd, SEQ_FLAGS) & DPHASE) == 0
4779 sgptr = ahd_inb_scbram(ahd, SCB_RESIDUAL_SGPTR);
4781 && (ahd_inb_scbram(ahd, SCB_TASK_ATTRIBUTE)
4795 sgptr = ahd_inl_scbram(ahd, SCB_RESIDUAL_SGPTR);
4796 data_cnt = ahd_inl_scbram(ahd, SCB_RESIDUAL_DATACNT);
4805 data_addr = ahd_inq(ahd, SHADDR);
4809 if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0) {
4812 sg = ahd_sg_bus_to_virt(ahd, scb, sgptr);
4839 sgptr = ahd_sg_virt_to_bus(ahd, scb,
4845 sg = ahd_sg_bus_to_virt(ahd, scb, sgptr);
4872 sgptr = ahd_sg_virt_to_bus(ahd, scb,
4882 ahd_outb(ahd, SCB_TASK_ATTRIBUTE,
4883 ahd_inb_scbram(ahd, SCB_TASK_ATTRIBUTE)
4886 ahd_outl(ahd, SCB_RESIDUAL_SGPTR, sgptr);
4887 ahd_outl(ahd, SCB_RESIDUAL_DATACNT, data_cnt);
4902 ahd_reinitialize_dataptrs(struct ahd_softc *ahd)
4912 AHD_ASSERT_MODES(ahd, AHD_MODE_DFF0_MSK|AHD_MODE_DFF1_MSK,
4915 scb_index = ahd_get_scbptr(ahd);
4916 scb = ahd_lookup_scb(ahd, scb_index);
4922 ahd_outb(ahd, DFFSXFRCTL, CLRCHN);
4924 while (--wait && !(ahd_inb(ahd, MDFFSTAT) & FIFOFREE))
4927 ahd_print_path(ahd, scb);
4929 ahd_outb(ahd, DFFSXFRCTL, RSTCHN|CLRSHCNT);
4931 saved_modes = ahd_save_modes(ahd);
4932 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
4933 ahd_outb(ahd, DFFSTAT,
4934 ahd_inb(ahd, DFFSTAT)
4941 sgptr = (ahd_inb_scbram(ahd, SCB_RESIDUAL_SGPTR + 3) << 24)
4942 | (ahd_inb_scbram(ahd, SCB_RESIDUAL_SGPTR + 2) << 16)
4943 | (ahd_inb_scbram(ahd, SCB_RESIDUAL_SGPTR + 1) << 8)
4944 | ahd_inb_scbram(ahd, SCB_RESIDUAL_SGPTR);
4947 resid = (ahd_inb_scbram(ahd, SCB_RESIDUAL_DATACNT + 2) << 16)
4948 | (ahd_inb_scbram(ahd, SCB_RESIDUAL_DATACNT + 1) << 8)
4949 | ahd_inb_scbram(ahd, SCB_RESIDUAL_DATACNT);
4951 if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0) {
4954 sg = ahd_sg_bus_to_virt(ahd, scb, sgptr);
4962 ahd_outb(ahd, HADDR + 7, dataptr >> 56);
4963 ahd_outb(ahd, HADDR + 6, dataptr >> 48);
4964 ahd_outb(ahd, HADDR + 5, dataptr >> 40);
4965 ahd_outb(ahd, HADDR + 4, dataptr >> 32);
4969 sg = ahd_sg_bus_to_virt(ahd, scb, sgptr);
4977 ahd_outb(ahd, HADDR + 4,
4980 ahd_outb(ahd, HADDR + 3, dataptr >> 24);
4981 ahd_outb(ahd, HADDR + 2, dataptr >> 16);
4982 ahd_outb(ahd, HADDR + 1, dataptr >> 8);
4983 ahd_outb(ahd, HADDR, dataptr);
4984 ahd_outb(ahd, HCNT + 2, resid >> 16);
4985 ahd_outb(ahd, HCNT + 1, resid >> 8);
4986 ahd_outb(ahd, HCNT, resid);
4993 ahd_handle_devreset(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
5002 found = ahd_abort_scbs(ahd, devinfo->target, devinfo->channel,
5011 tstate = ahd->enabled_targets[devinfo->our_scsiid];
5030 ahd_queue_lstate_event(ahd, lstate, devinfo->our_scsiid,
5032 ahd_send_lstate_events(ahd, lstate);
5040 ahd_set_width(ahd, devinfo, MSG_EXT_WDTR_BUS_8_BIT,
5042 ahd_set_syncrate(ahd, devinfo, /*period*/0, /*offset*/0,
5045 ahd_send_async(ahd, devinfo->channel, devinfo->target,
5050 printf("%s: %s on %c:%d. %d SCBs aborted\n", ahd_name(ahd),
5056 ahd_setup_target_msgin(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
5065 ahd->msgout_index = 0;
5066 ahd->msgout_len = 0;
5069 ahd_build_transfer_msg(ahd, devinfo);
5073 ahd->msgout_index = 0;
5074 ahd->msg_type = MSG_TYPE_TARGET_MSGIN;
5079 ahd_sglist_size(struct ahd_softc *ahd)
5084 if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0)
5096 ahd_sglist_allocsize(struct ahd_softc *ahd)
5104 sg_list_increment = ahd_sglist_size(ahd);
5137 ahd_softc_init(struct ahd_softc *ahd)
5140 ahd->unpause = 0;
5141 ahd->pause = PAUSE;
5146 ahd_set_unit(struct ahd_softc *ahd, int unit)
5148 ahd->unit = unit;
5152 ahd_set_name(struct ahd_softc *ahd, const char *name)
5154 ahd->name = name;
5158 ahd_free(struct ahd_softc *ahd)
5162 switch (ahd
5165 ahd_shutdown(ahd);
5166 TAILQ_REMOVE(&ahd_tailq, ahd, links);
5169 bus_dmamap_unload(ahd->parent_dmat,
5170 ahd->shared_data_map.dmamap);
5171 bus_dmamap_destroy(ahd->parent_dmat,
5172 ahd->shared_data_map.dmamap);
5173 bus_dmamem_unmap(ahd->parent_dmat, (void *)ahd->qoutfifo,
5174 ahd->shared_data_size);
5175 bus_dmamem_free(ahd->parent_dmat,
5176 &ahd->shared_data_map.dmasegs, ahd->shared_data_map.nseg);
5182 ahd_platform_free(ahd);
5183 ahd_fini_scbdata(ahd);
5187 tstate = ahd->enabled_targets[i];
5206 if (ahd->black_hole != NULL) {
5207 xpt_free_path(ahd->black_hole->path);
5208 free(ahd->black_hole, M_DEVBUF);
5211 if (ahd->seep_config != NULL)
5212 free(ahd->seep_config, M_DEVBUF);
5213 if (ahd->saved_stack != NULL)
5214 free(ahd->saved_stack, M_DEVBUF);
5216 free(ahd, M_DEVBUF);
5224 struct ahd_softc *ahd;
5226 ahd = arg;
5229 printf("%s: ahd_shutdown\n", ahd_name(ahd));
5234 ahd_timer_stop(&ahd->reset_timer);
5235 ahd_timer_stop(&ahd->stat_timer);
5238 ahd_reset(ahd, /*reinit*/FALSE);
5251 ahd_reset(struct ahd_softc *ahd, int reinit)
5256 struct ahd_pci_busdata *bd = ahd->bus_data;
5263 ahd_pause(ahd);
5264 ahd_update_modes(ahd);
5265 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
5266 sxfrctl1 = ahd_inb(ahd, SXFRCTL1);
5270 if ((ahd->bugs & AHD_PCIX_CHIPRST_BUG) != 0) {
5287 ahd_outb(ahd, HCNTRL, CHIPRST | ahd->pause);
5298 } while (--wait && !(ahd_inb(ahd, HCNTRL) & CHIPRSTACK));
5302 "Trying to initialize anyway.\n", ahd_name(ahd));
5304 ahd_outb(ahd, HCNTRL, ahd->pause);
5306 if ((ahd->bugs & AHD_PCIX_CHIPRST_BUG) != 0) {
5323 ahd_known_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
5324 ahd_outb(ahd, MODE_PTR,
5325 ahd_build_mode_state(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI));
5335 ahd_outb(ahd, SXFRCTL1, sxfrctl1|STPWEN);
5336 ahd_outb(ahd, SXFRCTL1, sxfrctl1);
5339 ahd->features &= ~AHD_WIDE;
5340 if ((ahd_inb(ahd, SBLKCTL) & SELWIDE) != 0)
5341 ahd->features |= AHD_WIDE;
5348 ahd_chip_init(ahd);
5357 ahd_probe_scbs(struct ahd_softc *ahd) {
5360 AHD_ASSERT_MODES(ahd, ~(AHD_MODE_UNKNOWN_MSK|AHD_MODE_CFG_MSK),
5366 ahd_set_scbptr(ahd, i);
5367 ahd_outw(ahd, SCB_BASE, i);
5369 ahd_outb(ahd, SCB_BASE+j, 0);
5371 ahd_outb(ahd, SCB_CONTROL, MK_MESSAGE);
5372 ret = ahd_inw_scbram(ahd, SCB_BASE);
5375 ahd_name(ahd), i, ret);
5378 ahd_set_scbptr(ahd, 0);
5379 ret = ahd_inw_scbram(ahd, SCB_BASE);
5390 ahd_initialize_hscbs(struct ahd_softc *ahd)
5394 for (i = 0; i < ahd->scb_data.maxhscbs; i++) {
5395 ahd_set_scbptr(ahd, i);
5398 ahd_outb(ahd, SCB_CONTROL, 0);
5401 ahd_outw(ahd, SCB_NEXT, SCB_LIST_NULL);
5406 ahd_init_scbdata(struct ahd_softc *ahd)
5411 scb_data = &ahd->scb_data;
5421 scb_data->maxhscbs = ahd_probe_scbs(ahd);
5423 printf("%s: No SCB space found\n", ahd_name(ahd));
5426 ahd_initialize_hscbs(ahd);
5439 ahd_alloc_scbs(ahd);
5444 ahd_name(ahd));
5459 ahd_find_scb_by_tag(struct ahd_softc *ahd, u_int tag)
5466 LIST_FOREACH(scb, &ahd->pending_scbs, pending_links) {
5474 TAILQ_FOREACH(scb, &ahd->scb_data.free_scbs, links.tqe) {
5488 LIST_FOREACH(scb, &ahd->scb_data.any_dev_free_scb_list, links.le) {
5497 ahd_fini_scbdata(struct ahd_softc *ahd)
5501 scb_data = &ahd->scb_data;
5513 ahd_freedmamem(ahd->parent_dmat, PAGE_SIZE,
5526 ahd_freedmamem(ahd->parent_dmat,
5527 ahd_sglist_allocsize(ahd),
5540 ahd_freedmamem(ahd->parent_dmat, PAGE_SIZE,
5558 ahd_setup_iocell_workaround(struct ahd_softc *ahd)
5562 saved_modes = ahd_save_modes(ahd);
5563 ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
5564 ahd_outb(ahd, DSPDATACTL, ahd_inb(ahd, DSPDATACTL)
5566 ahd_outb(ahd, SIMODE0, ahd_inb(ahd, SIMODE0) | (ENSELDO|ENSELDI));
5569 printf("%s: Setting up iocell workaround\n", ahd_name(ahd));
5571 ahd_restore_modes(ahd, saved_modes);
5572 ahd->flags &= ~AHD_HAD_FIRST_SEL;
5576 ahd_iocell_first_selection(struct ahd_softc *ahd)
5581 if ((ahd->flags & AHD_HAD_FIRST_SEL) != 0)
5583 saved_modes = ahd_save_modes(ahd);
5584 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
5585 sblkctl = ahd_inb(ahd, SBLKCTL);
5586 ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
5589 printf("%s: iocell first selection\n", ahd_name(ahd));
5592 ahd_outb(ahd, DSPDATACTL,
5593 ahd_inb(ahd, DSPDATACTL) & ~BYPASSENAB);
5596 printf("%s: BYPASS now disabled\n", ahd_name(ahd));
5599 ahd_outb(ahd, SIMODE0, ahd_inb(ahd, SIMODE0) & ~(ENSELDO|ENSELDI));
5600 ahd_outb(ahd, CLRINT, CLRSCSIINT);
5601 ahd_restore_modes(ahd, saved_modes);
5602 ahd->flags |= AHD_HAD_FIRST_SEL;
5607 ahd_add_col_list(struct ahd_softc *ahd, struct scb *scb, u_int col_idx)
5615 free_list = &ahd->scb_data.free_scb_lists[col_idx];
5616 free_tailq = &ahd->scb_data.free_scbs;
5627 ahd_rem_col_list(struct ahd_softc *ahd, struct scb *scb)
5635 col_idx = AHD_GET_SCB_COL_IDX(ahd, scb);
5636 free_list = &ahd->scb_data.free_scb_lists[col_idx];
5637 free_tailq = &ahd->scb_data.free_scbs;
5661 ahd_get_scb(struct ahd_softc *ahd, u_int col_idx)
5664 TAILQ_FOREACH(scb, &ahd->scb_data.free_scbs, links.tqe) {
5665 if (AHD_GET_SCB_COL_IDX(ahd, scb) != col_idx) {
5666 ahd_rem_col_list(ahd, scb);
5670 if ((scb = LIST_FIRST(&ahd->scb_data.any_dev_free_scb_list)) == NULL)
5677 ahd_add_col_list(ahd, scb->col_scb, col_idx);
5688 ahd_free_scb(struct ahd_softc *ahd, struct scb *scb)
5694 ahd->scb_data.scbindex[SCB_GET_TAG(scb)] = NULL;
5701 LIST_INSERT_HEAD(&ahd->scb_data.any_dev_free_scb_list,
5710 ahd_rem_col_list(ahd, scb->col_scb);
5711 LIST_INSERT_HEAD(&ahd->scb_data.any_dev_free_scb_list,
5713 LIST_INSERT_HEAD(&ahd->scb_data.any_dev_free_scb_list,
5724 ahd_add_col_list(ahd, scb,
5725 AHD_GET_SCB_COL_IDX(ahd, scb->col_scb));
5733 LIST_INSERT_HEAD(&ahd->scb_data.any_dev_free_scb_list,
5737 ahd_platform_scb_free(ahd, scb);
5741 ahd_alloc_scbs(struct ahd_softc *ahd)
5757 scb_data = &ahd->scb_data;
5779 if (ahd_createdmamem(ahd->parent_dmat, PAGE_SIZE,
5780 ahd->sc_dmaflags,
5784 &hscb_map->nseg, ahd_name(ahd),
5802 offset = ((ahd_sglist_allocsize(ahd) / ahd_sglist_size(ahd))
5803 - scb_data->sgs_left) * ahd_sglist_size(ahd);
5816 if (ahd_createdmamem(ahd->parent_dmat,
5817 ahd_sglist_allocsize(ahd),
5818 ahd->sc_dmaflags,
5821 &sg_map->nseg, ahd_name(ahd),
5832 ahd_sglist_allocsize(ahd) / ahd_sglist_size(ahd);
5836 ahd_name(ahd));
5859 if (ahd_createdmamem(ahd->parent_dmat, PAGE_SIZE,
5860 ahd->sc_dmaflags,
5864 &sense_map->nseg, ahd_name(ahd),
5878 ahd_name(ahd));
5925 if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0)
5930 next_scb->ahd_softc = ahd;
5933 error = bus_dmamap_create(ahd->parent_dmat,
5937 ahd->sc_dmaflags,
5946 next_scb->col_scb = ahd_find_scb_by_tag(ahd, col_tag);
5949 ahd_free_scb(ahd, next_scb);
5952 segs += ahd_sglist_size(ahd);
5953 sg_busaddr += ahd_sglist_size(ahd);
5962 ahd_controller_info(struct ahd_softc *ahd, char *tbuf, size_t l)
5969 ahd_chip_names[ahd->chip & AHD_CHIPID_MASK]);
5973 if ((ahd->features & AHD_WIDE) != 0) {
5979 speed, type, ahd->channel, ahd->our_id);
5982 snprintf(tbuf + len, l - len, "%s, %d SCBs", ahd->bus_description,
5983 ahd->scb_data.maxhscbs);
6004 ahd_init(struct ahd_softc *ahd)
6015 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
6017 ahd->stack_size = ahd_probe_stack_size(ahd);
6018 ahd->saved_stack = malloc(ahd->stack_size * sizeof(uint16_t),
6030 ahd->flags |= AHD_SEQUENCER_DEBUG;
6036 ahd->flags |= AHD_INITIATORROLE;
6041 if ((AHD_TMODE_ENABLE & (0x1 << ahd->unit)) == 0)
6042 ahd->features &= ~AHD_TARGETMODE;
6053 if ((ahd->features & AHD_TARGETMODE) != 0)
6055 if ((ahd->bugs & AHD_PKT_BITBUCKET_BUG) != 0)
6057 ahd->shared_data_size = driver_data_size;
6059 memset(&ahd->shared_data_map, 0, sizeof(ahd->shared_data_map));
6060 ahd->sc_dmaflags = BUS_DMA_NOWAIT;
6062 if (ahd_createdmamem(ahd->parent_dmat, ahd->shared_data_size,
6063 ahd->sc_dmaflags,
6064 &ahd->shared_data_map.dmamap,
6065 (void **)&ahd->shared_data_map.vaddr,
6066 &ahd->shared_data_map.physaddr,
6067 &ahd->shared_data_map.dmasegs,
6068 &ahd->shared_data_map.nseg, ahd_name(ahd),
6071 ahd->qoutfifo = (void *) ahd->shared_data_map.vaddr;
6073 ahd->init_level++;
6075 next_vaddr = (uint8_t *)&ahd->qoutfifo[AHD_QOUT_SIZE];
6076 next_baddr = ahd->shared_data_map.physaddr +
6078 if ((ahd->features & AHD_TARGETMODE) != 0) {
6079 ahd->targetcmds = (struct target_cmd *)next_vaddr;
6084 if ((ahd->bugs & AHD_PKT_BITBUCKET_BUG) != 0) {
6085 ahd->overrun_buf = next_vaddr;
6097 ahd->next_queued_hscb = (struct hardware_scb *)next_vaddr;
6098 ahd->next_queued_hscb_map = &ahd->shared_data_map;
6099 ahd->next_queued_hscb->hscb_busaddr = ahd_htole32(next_baddr);
6101 memset(&ahd->scb_data, 0, sizeof(struct scb_data));
6104 if (ahd_init_scbdata(ahd) != 0)
6107 if ((ahd->flags & AHD_INITIATORROLE) == 0)
6108 ahd->flags &= ~AHD_RESET_BUS_A;
6114 ahd_platform_init(ahd);
6117 ahd_chip_init(ahd);
6119 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
6121 if ((ahd->flags & AHD_CURRENT_SENSING) == 0)
6128 error = ahd_write_flexport(ahd, FLXADDR_ROMSTAT_CURSENSECTL,
6131 printf("%s: current sensing timeout 1\n", ahd_name(ahd));
6136 error = ahd_read_flexport(ahd, FLXADDR_FLEXSTAT, &fstat);
6139 ahd_name(ahd));
6145 ahd_name(ahd));
6150 error = ahd_read_flexport(ahd, FLXADDR_CURRENT_STAT, &current_sensing);
6152 printf("%s: current sensing timeout 3\n", ahd_name(ahd));
6157 ahd_write_flexport(ahd, FLXADDR_ROMSTAT_CURSENSECTL, 0);
6162 ahd_name(ahd), current_sensing);
6179 printf("%s: %s Channel %s\n", ahd_name(ahd),
6187 ahd_name(ahd), ahd_name(ahd));
6190 ahd_reset_current_bus(ahd);
6191 ahd_restart(ahd);
6192 ahd_timer_reset(&ahd->stat_timer, AHD_STAT_UPDATE_US,
6193 ahd_stat_timer, ahd);
6202 ahd_chip_init(struct ahd_softc *ahd)
6211 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
6215 ahd_outb(ahd, SBLKCTL, ahd_inb(ahd, SBLKCTL) & ~(DIAGLEDEN|DIAGLEDON));
6220 ahd->hs_mailbox = 0;
6221 ahd_outb(ahd, HS_MAILBOX, 0);
6224 ahd_outb(ahd, IOWNID, ahd->our_id);
6225 ahd_outb(ahd, TOWNID, ahd->our_id);
6226 sxfrctl1 = (ahd->flags & AHD_TERM_ENB_A) != 0 ? STPWEN : 0;
6227 sxfrctl1 |= (ahd->flags & AHD_SPCHK_ENB_A) != 0 ? ENSPCHK : 0;
6228 if ((ahd->bugs & AHD_LONG_SETIMO_BUG)
6229 && (ahd->seltime != STIMESEL_MIN)) {
6235 sxfrctl1 |= ahd->seltime + STIMESEL_BUG_ADJ;
6237 sxfrctl1 |= ahd->seltime;
6240 ahd_outb(ahd, SXFRCTL0, DFON);
6241 ahd_outb(ahd, SXFRCTL1, sxfrctl1|ahd->seltime|ENSTIMER|ACTNEGEN);
6242 ahd_outb(ahd, SIMODE1, ENSELTIMO|ENSCSIRST|ENSCSIPERR);
6252 (ahd_inb(ahd, SBLKCTL) & (ENAB40|ENAB20)) == 0 && wait;
6257 ahd_outb(ahd, CLRSINT1, CLRSCSIRSTI);
6258 ahd_outb(ahd, CLRINT, CLRSCSIINT);
6262 ahd_set_modes(ahd, AHD_MODE_DFF0 + i, AHD_MODE_DFF0 + i);
6263 ahd_outb(ahd, LONGJMP_ADDR + 1, INVALID_ADDR);
6264 ahd_outb(ahd, SG_STATE, 0);
6265 ahd_outb(ahd, CLRSEQINTSRC, 0xFF);
6266 ahd_outb(ahd, SEQIMODE,
6271 ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
6272 ahd_outb(ahd, DSCOMMAND0, ahd_inb(ahd, DSCOMMAND0)|MPARCKEN|CACHETHEN);
6273 ahd_outb(ahd, DFF_THRSH, RD_DFTHRSH_75|WR_DFTHRSH_75);
6274 ahd_outb(ahd, SIMODE0, ENIOERR|ENOVERRUN);
6275 ahd_outb(ahd, SIMODE3, ENNTRAMPERR|ENOSRAMPERR);
6276 if ((ahd->bugs & AHD_BUSFREEREV_BUG) != 0) {
6277 ahd_outb(ahd, OPTIONMODE, AUTOACKEN|AUTO_MSGOUT_DE);
6279 ahd_outb(ahd, OPTIONMODE, AUTOACKEN|BUSFREEREV|AUTO_MSGOUT_DE);
6281 ahd_outb(ahd, SCSCHKN, CURRFIFODEF|WIDERESEN|SHVALIDSTDIS);
6282 if ((ahd->chip & AHD_BUS_MASK) == AHD_PCIX)
6288 ahd_outb(ahd, PCIXCTL, ahd_inb(ahd, PCIXCTL) | SPLTSTADIS);
6290 if ((ahd->bugs & AHD_LQOOVERRUN_BUG) != 0)
6291 ahd_outb(ahd, LQOSCSCTL, LQONOCHKOVER);
6296 if ((ahd->flags & AHD_HP_BOARD) != 0) {
6298 ahd_outb(ahd, DSPSELECT, i);
6299 ahd_outb(ahd, WRTBIASCTL, WRTBIASCTL_HP_DEFAULT);
6303 printf("%s: WRTBIASCTL now 0x%x\n", ahd_name(ahd),
6307 ahd_setup_iocell_workaround(ahd);
6312 ahd_outb(ahd, LQIMODE1, ENLQIPHASE_LQ|ENLQIPHASE_NLQ|ENLIQABORT
6315 ahd_outb(ahd, LQOMODE0, ENLQOATNLQ|ENLQOATNPKT|ENLQOTCRC);
6321 ahd_outb(ahd, LQOMODE1, ENLQOBUSFREE|ENLQOPHACHGINPKT);
6323 ahd_outb(ahd, LQOMODE1, 0);
6328 ahd_outw(ahd, INTVEC1_ADDR, ahd_resolve_seqaddr(ahd, LABEL_seq_isr));
6329 ahd_outw(ahd, INTVEC2_ADDR, ahd_resolve_seqaddr(ahd, LABEL_timer_isr));
6334 if ((ahd->bugs & AHD_PKT_LUN_BUG) != 0) {
6335 ahd_outb(ahd, LUNPTR, offsetof(struct hardware_scb,
6338 ahd_outb(ahd, LUNPTR, offsetof(struct hardware_scb, lun));
6340 ahd_outb(ahd, CMDLENPTR, offsetof(struct hardware_scb, cdb_len));
6341 ahd_outb(ahd, ATTRPTR, offsetof(struct hardware_scb, task_attribute));
6342 ahd_outb(ahd, FLAGPTR, offsetof(struct hardware_scb, task_management));
6343 ahd_outb(ahd, CMDPTR, offsetof(struct hardware_scb,
6345 ahd_outb(ahd, QNEXTPTR,
6347 ahd_outb(ahd, ABRTBITPTR, MK_MESSAGE_BIT_OFFSET);
6348 ahd_outb(ahd, ABRTBYTEPTR, offsetof(struct hardware_scb, control));
6349 if ((ahd->bugs & AHD_PKT_LUN_BUG) != 0) {
6350 ahd_outb(ahd, LUNLEN,
6351 sizeof(ahd->next_queued_hscb->pkt_long_lun) - 1);
6353 ahd_outb(ahd, LUNLEN, LUNLEN_SINGLE_LEVEL_LUN);
6355 ahd_outb(ahd, CDBLIMIT, SCB_CDB_LEN_PTR - 1);
6356 ahd_outb(ahd, MAXCMD, 0xFF);
6357 ahd_outb(ahd, SCBAUTOPTR,
6361 ahd_outb(ahd, MULTARGID, 0);
6362 ahd_outb(ahd, MULTARGID + 1, 0);
6364 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
6366 if ((ahd->features & AHD_NEW_IOCELL_OPTS) == 0) {
6372 ahd_outb(ahd, NEGOADDR, target);
6373 ahd_outb(ahd, ANNEXCOL, AHD_ANNEXCOL_PER_DEV0);
6375 ahd_outb(ahd, ANNEXDAT, 0);
6384 tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
6386 ahd_compile_devinfo(&devinfo, ahd->our_id,
6389 ahd_update_neg_table(ahd, &devinfo, &tinfo->curr);
6392 ahd_outb(ahd, CLRSINT3, NTRAMPERR|OSRAMPERR);
6393 ahd_outb(ahd, CLRINT, CLRSCSIINT);
6400 if ((ahd->bugs & AHD_ABORT_LQI_BUG) == 0)
6401 ahd_outb(ahd, LQCTL1, ABORTPENDING);
6404 ahd_outb(ahd, LQCTL1, 0);
6407 ahd->qoutfifonext = 0;
6408 ahd->qoutfifonext_valid_tag = QOUTFIFO_ENTRY_VALID_LE;
6409 ahd_outb(ahd, QOUTFIFO_ENTRY_VALID_TAG, QOUTFIFO_ENTRY_VALID >> 8);
6411 ahd->qoutfifo[i] = 0;
6412 ahd_sync_qoutfifo(ahd, BUS_DMASYNC_PREREAD);
6414 ahd->qinfifonext = 0;
6416 ahd->qinfifo[i] = SCB_LIST_NULL;
6418 if ((ahd->features & AHD_TARGETMODE) != 0) {
6421 ahd->targetcmds[i].cmd_valid = 0;
6422 ahd_sync_tqinfifo(ahd, BUS_DMASYNC_PREREAD);
6423 ahd->tqinfifonext = 1;
6424 ahd_outb(ahd, KERNEL_TQINPOS, ahd->tqinfifonext - 1);
6425 ahd_outb(ahd, TQINPOS, ahd->tqinfifonext);
6429 ahd_outb(ahd, SEQ_FLAGS, 0);
6430 ahd_outb(ahd, SEQ_FLAGS2, 0);
6433 ahd_outw(ahd, WAITING_TID_HEAD, SCB_LIST_NULL);
6434 ahd_outw(ahd, WAITING_TID_TAIL, SCB_LIST_NULL);
6436 ahd_outw(ahd, WAITING_SCB_TAILS + (2 * i), SCB_LIST_NULL);
6442 ahd_outw(ahd, COMPLETE_SCB_HEAD, SCB_LIST_NULL);
6443 ahd_outw(ahd, COMPLETE_SCB_DMAINPROG_HEAD, SCB_LIST_NULL);
6444 ahd_outw(ahd, COMPLETE_DMA_SCB_HEAD, SCB_LIST_NULL);
6449 ahd_outw(ahd, QFREEZE_COUNT, 0);
6454 busaddr = ahd->shared_data_map.physaddr;
6455 ahd_outb(ahd, SHARED_DATA_ADDR, busaddr & 0xFF);
6456 ahd_outb(ahd, SHARED_DATA_ADDR + 1, (busaddr >> 8) & 0xFF);
6457 ahd_outb(ahd, SHARED_DATA_ADDR + 2, (busaddr >> 16) & 0xFF);
6458 ahd_outb(ahd, SHARED_DATA_ADDR + 3, (busaddr >> 24) & 0xFF);
6459 ahd_outb(ahd, QOUTFIFO_NEXT_ADDR, busaddr & 0xFF);
6460 ahd_outb(ahd, QOUTFIFO_NEXT_ADDR + 1, (busaddr >> 8) & 0xFF);
6461 ahd_outb(ahd, QOUTFIFO_NEXT_ADDR + 2, (busaddr >> 16) & 0xFF);
6462 ahd_outb(ahd, QOUTFIFO_NEXT_ADDR + 3, (busaddr >> 24) & 0xFF);
6469 if ((ahd->flags & AHD_INITIATORROLE) != 0)
6471 ahd_outb(ahd, SCSISEQ_TEMPLATE, scsiseq_template);
6478 ahd_unbusy_tcl(ahd, BUILD_TCL_RAW(target, 'A', lun));
6487 ahd_outb(ahd, CMDSIZE_TABLE, 5);
6488 ahd_outb(ahd, CMDSIZE_TABLE + 1, 9);
6489 ahd_outb(ahd, CMDSIZE_TABLE + 2, 9);
6490 ahd_outb(ahd, CMDSIZE_TABLE + 3, 0);
6491 ahd_outb(ahd, CMDSIZE_TABLE + 4, 15);
6492 ahd_outb(ahd, CMDSIZE_TABLE + 5, 11);
6493 ahd_outb(ahd, CMDSIZE_TABLE + 6, 0);
6494 ahd_outb(ahd, CMDSIZE_TABLE + 7, 0);
6497 ahd_set_modes(ahd, AHD_MODE_CCHAN, AHD_MODE_CCHAN);
6498 ahd_outb(ahd, QOFF_CTLSTA, SCB_QSIZE_512);
6499 ahd->qinfifonext = 0;
6500 ahd_set_hnscb_qoff(ahd, ahd->qinfifonext);
6501 ahd_set_hescb_qoff(ahd, 0);
6502 ahd_set_snscb_qoff(ahd, 0);
6503 ahd_set_sescb_qoff(ahd, 0);
6504 ahd_set_sdscb_qoff(ahd, 0);
6509 busaddr = ahd_le32toh(ahd->next_queued_hscb->hscb_busaddr);
6510 ahd_outb(ahd, NEXT_QUEUED_SCB_ADDR + 0, busaddr & 0xFF);
6511 ahd_outb(ahd, NEXT_QUEUED_SCB_ADDR + 1, (busaddr >> 8) & 0xFF);
6512 ahd_outb(ahd, NEXT_QUEUED_SCB_ADDR + 2, (busaddr >> 16) & 0xFF);
6513 ahd_outb(ahd, NEXT_QUEUED_SCB_ADDR + 3, (busaddr >> 24) & 0xFF);
6518 ahd_outw(ahd, INT_COALESCING_CMDCOUNT, 0);
6519 ahd_outw(ahd, CMDS_PENDING, 0);
6520 ahd_update_coalescing_values(ahd, ahd->int_coalescing_timer,
6521 ahd->int_coalescing_maxcmds,
6522 ahd->int_coalescing_mincmds);
6523 ahd_enable_coalescing(ahd, FALSE);
6525 ahd_loadseq(ahd);
6526 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
6535 ahd_default_config(struct ahd_softc *ahd)
6539 ahd->our_id = 7;
6546 if (ahd_alloc_tstate(ahd, ahd->our_id, 'A') == NULL) {
6548 "Failing attach\n", ahd_name(ahd));
6558 tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
6567 ahd->user_discenable |= target_mask;
6569 ahd->user_tagenable |= target_mask;
6582 if ((ahd->features & AHD_RTI) != 0)
6595 ahd_compile_devinfo(&devinfo, ahd->our_id,
6599 ahd_set_width(ahd, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
6601 ahd_set_syncrate(ahd, &devinfo, /*period*/0, /*offset*/0,
6612 ahd_parse_cfgdata(struct ahd_softc *ahd, struct seeprom_config *sc)
6618 ahd->our_id = sc->brtime_id & CFSCSIID;
6625 if (ahd_alloc_tstate(ahd, ahd->our_id, 'A') == NULL) {
6627 "Failing attach\n", ahd_name(ahd));
6638 tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
6649 ahd->user_discenable &= ~target_mask;
6651 ahd->user_tagenable &= ~target_mask;
6654 ahd->user_discenable |= target_mask;
6655 ahd->user_tagenable |= target_mask;
6683 if ((ahd->features & AHD_RTI) != 0)
6709 ahd_compile_devinfo(&devinfo, ahd->our_id,
6712 ahd_set_width(ahd, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
6714 ahd_set_syncrate(ahd, &devinfo, /*period*/0, /*offset*/0,
6719 ahd->flags &= ~AHD_SPCHK_ENB_A;
6721 ahd->flags |= AHD_SPCHK_ENB_A;
6723 ahd->flags &= ~AHD_RESET_BUS_A;
6725 ahd->flags |= AHD_RESET_BUS_A;
6727 ahd->flags &= ~AHD_EXTENDED_TRANS_A;
6729 ahd->flags |= AHD_EXTENDED_TRANS_A;
6731 ahd->flags &= ~AHD_BIOS_ENABLED;
6733 ahd->flags |= AHD_BIOS_ENABLED;
6735 ahd->flags &= ~AHD_STPWLEVEL_A;
6737 ahd->flags |= AHD_STPWLEVEL_A;
6746 ahd_parse_vpddata(struct ahd_softc *ahd, struct vpd_config *vpd)
6754 ahd->flags |= AHD_BOOT_CHANNEL;
6759 ahd_intr_enable(struct ahd_softc *ahd, int enable)
6763 hcntrl = ahd_inb(ahd, HCNTRL);
6765 ahd->pause &= ~INTEN;
6766 ahd->unpause &= ~INTEN;
6769 ahd->pause |= INTEN;
6770 ahd->unpause |= INTEN;
6772 ahd_outb(ahd, HCNTRL, hcntrl);
6776 ahd_update_coalescing_values(struct ahd_softc *ahd, u_int timer, u_int maxcmds,
6781 ahd->int_coalescing_timer = timer;
6787 ahd->int_coalescing_maxcmds = maxcmds;
6788 ahd_outw(ahd, INT_COALESCING_TIMER, timer / AHD_TIMER_US_PER_TICK);
6789 ahd_outb(ahd, INT_COALESCING_MAXCMDS, -maxcmds);
6790 ahd_outb(ahd, INT_COALESCING_MINCMDS, -mincmds);
6794 ahd_enable_coalescing(struct ahd_softc *ahd, int enable)
6797 ahd->hs_mailbox &= ~ENINT_COALESCE;
6799 ahd->hs_mailbox |= ENINT_COALESCE;
6800 ahd_outb(ahd, HS_MAILBOX, ahd->hs_mailbox);
6801 ahd_flush_device_writes(ahd);
6802 ahd_run_qoutfifo(ahd);
6813 ahd_pause_and_flushwork(struct ahd_softc *ahd)
6820 ahd->flags |= AHD_ALL_INTERRUPTS;
6821 ahd_pause(ahd);
6828 ahd_outw(ahd, QFREEZE_COUNT, ahd_inw(ahd, QFREEZE_COUNT) + 1);
6829 ahd_outb(ahd, SEQ_FLAGS2, ahd_inb(ahd, SEQ_FLAGS2) | SELECTOUT_QFROZEN);
6833 ahd_unpause(ahd);
6834 ahd_intr(ahd);
6835 ahd_pause(ahd);
6836 ahd_clear_critical_section(ahd);
6837 intstat = ahd_inb(ahd, INTSTAT);
6838 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
6839 if ((ahd_inb(ahd, SSTAT0) & (SELDO|SELINGO)) == 0)
6840 ahd_outb(ahd, SCSISEQ0,
6841 ahd_inb(ahd, SCSISEQ0) & ~ENSELO);
6847 waiting_scb = ahd_lookup_scb(ahd,
6848 ahd_inw(ahd, WAITING_TID_HEAD));
6851 && (ahd_inb(ahd, SSTAT0) & (SELDO|SELINGO)) != 0)
6852 ahd_outb(ahd, SCSISEQ0,
6853 ahd_inb(ahd, SCSISEQ0) | ENSELO);
6855 && (intstat != 0xFF || (ahd->features & AHD_REMOVABLE) == 0)
6857 || (ahd_inb(ahd, SCSISEQ0) & ENSELO) != 0
6858 || (ahd_inb(ahd, SSTAT0) & (SELDO|SELINGO)) != 0));
6861 ahd_inb(ahd, INTSTAT));
6863 qfreeze_cnt = ahd_inw(ahd, QFREEZE_COUNT);
6866 ahd_name(ahd));
6870 ahd_outw(ahd, QFREEZE_COUNT, qfreeze_cnt);
6872 ahd_outb(ahd, SEQ_FLAGS2,
6873 ahd_inb(ahd, SEQ_FLAGS2) & ~SELECTOUT_QFROZEN);
6875 ahd_flush_qoutfifo(ahd);
6877 ahd_platform_flushwork(ahd);
6878 ahd->flags &= ~AHD_ALL_INTERRUPTS;
6882 ahd_suspend(struct ahd_softc *ahd)
6885 ahd_pause_and_flushwork(ahd);
6887 if (LIST_FIRST(&ahd->pending_scbs) != NULL) {
6888 ahd_unpause(ahd);
6891 ahd_shutdown(ahd);
6896 ahd_resume(struct ahd_softc *ahd)
6899 ahd_reset(ahd, /*reinit*/TRUE);
6900 ahd_intr_enable(ahd, TRUE);
6901 ahd_restart(ahd);
6915 ahd_index_busy_tcl(struct ahd_softc *ahd, u_int *saved_scbid, u_int tcl)
6920 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
6921 *saved_scbid = ahd_get_scbptr(ahd);
6922 ahd_set_scbptr(ahd, TCL_LUN(tcl)
6937 ahd_find_busy_tcl(struct ahd_softc *ahd, u_int tcl)
6943 ahd, &saved_scbptr, tcl);
6944 scbid = ahd_inw_scbram(ahd, scb_offset);
6945 ahd_set_scbptr(ahd, saved_scbptr);
6950 ahd_busy_tcl(struct ahd_softc *ahd, u_int tcl, u_int scbid)
6955 scb_offset = ahd_index_busy_tcl(ahd, &saved_scbptr, tcl);
6956 ahd_outw(ahd, scb_offset, scbid);
6957 ahd_set_scbptr(ahd, saved_scbptr);
6962 ahd_match_scb(struct ahd_softc *ahd, struct scb *scb, int target,
6965 int targ = SCB_GET_TARGET(ahd, scb);
6966 char chan = SCB_GET_CHANNEL(ahd, scb);
6998 ahd_freeze_devq(struct ahd_softc *ahd, struct scb *scb)
7004 target = SCB_GET_TARGET(ahd, scb);
7006 channel = SCB_GET_CHANNEL(ahd, scb);
7008 ahd_search_qinfifo(ahd, target, channel, lun,
7012 ahd_platform_freeze_devq(ahd, scb);
7016 ahd_qinfifo_requeue_tail(struct ahd_softc *ahd, struct scb *scb)
7021 saved_modes = ahd_save_modes(ahd);
7022 ahd_set_modes(ahd, AHD_MODE_CCHAN, AHD_MODE_CCHAN);
7024 if (ahd_qinfifo_count(ahd) != 0) {
7028 prev_pos = AHD_QIN_WRAP(ahd->qinfifonext - 1);
7029 prev_tag = ahd->qinfifo[prev_pos];
7030 prev_scb = ahd_lookup_scb(ahd, prev_tag);
7032 ahd_qinfifo_requeue(ahd, prev_scb, scb);
7033 ahd_set_hnscb_qoff(ahd, ahd->qinfifonext);
7034 ahd_restore_modes(ahd, saved_modes);
7038 ahd_qinfifo_requeue(struct ahd_softc *ahd, struct scb *prev_scb,
7045 ahd_outb(ahd, NEXT_QUEUED_SCB_ADDR + 0, busaddr & 0xFF);
7046 ahd_outb(ahd, NEXT_QUEUED_SCB_ADDR + 1, (busaddr >> 8) & 0xFF);
7047 ahd_outb(ahd, NEXT_QUEUED_SCB_ADDR + 2, (busaddr >> 16) & 0xFF);
7048 ahd_outb(ahd, NEXT_QUEUED_SCB_ADDR + 3, (busaddr >> 24) & 0xFF);
7051 ahd_sync_scb(ahd, prev_scb,
7054 ahd->qinfifo[AHD_QIN_WRAP(ahd->qinfifonext)] = SCB_GET_TAG(scb);
7055 ahd->qinfifonext++;
7056 scb->hscb->next_hscb_busaddr = ahd->next_queued_hscb->hscb_busaddr;
7057 ahd_sync_scb(ahd, scb, BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
7061 ahd_qinfifo_count(struct ahd_softc *ahd)
7067 AHD_ASSERT_MODES(ahd, AHD_MODE_CCHAN_MSK, AHD_MODE_CCHAN_MSK);
7068 qinpos = ahd_get_snscb_qoff(ahd);
7070 wrap_qinfifonext = AHD_QIN_WRAP(ahd->qinfifonext);
7075 + NUM_ELEMENTS(ahd->qinfifo) - wrap_qinpos);
7079 ahd_reset_cmds_pending(struct ahd_softc *ahd)
7085 saved_modes = ahd_save_modes(ahd);
7086 ahd_set_modes(ahd, AHD_MODE_CCHAN, AHD_MODE_CCHAN);
7092 ahd_flush_qoutfifo(ahd);
7095 LIST_FOREACH(scb, &ahd->pending_scbs, pending_links) {
7098 ahd_outw(ahd, CMDS_PENDING, pending_cmds - ahd_qinfifo_count(ahd));
7099 ahd_restore_modes(ahd, saved_modes);
7100 ahd->flags &= ~AHD_UPDATE_PEND_CMDS;
7104 ahd_search_qinfifo(struct ahd_softc *ahd, int target, char channel,
7124 saved_modes = ahd_save_modes(ahd);
7125 ahd_set_modes(ahd, AHD_MODE_CCHAN, AHD_MODE_CCHAN);
7131 if ((ahd_inb(ahd, CCSCBCTL) & (CCARREN|CCSCBEN|CCSCBDIR))
7133 ahd_outb(ahd, CCSCBCTL,
7134 ahd_inb(ahd, CCSCBCTL) & ~(CCARREN|CCSCBEN));
7135 while ((ahd_inb(ahd, CCSCBCTL) & (CCARREN|CCSCBEN)) != 0)
7139 qintail = AHD_QIN_WRAP(ahd->qinfifonext);
7140 qinstart = ahd_get_snscb_qoff(ahd);
7146 LIST_FOREACH(scb, &ahd->pending_scbs, pending_links) {
7149 (void)ahd_qinfifo_count(ahd);
7153 qinstart, ahd->qinfifonext);
7160 ahd->qinfifonext = qinstart;
7161 busaddr = ahd_le32toh(ahd->next_queued_hscb->hscb_busaddr);
7162 ahd_outb(ahd, NEXT_QUEUED_SCB_ADDR + 0, busaddr & 0xFF);
7163 ahd_outb(ahd, NEXT_QUEUED_SCB_ADDR + 1, (busaddr >> 8) & 0xFF);
7164 ahd_outb(ahd, NEXT_QUEUED_SCB_ADDR + 2, (busaddr >> 16) & 0xFF);
7165 ahd_outb(ahd, NEXT_QUEUED_SCB_ADDR + 3, (busaddr >> 24) & 0xFF);
7168 scb = ahd_lookup_scb(ahd, ahd->qinfifo[qinpos]);
7173 if (ahd_match_scb(ahd, scb, target, channel, lun, tag, role)) {
7198 ahd_done(ahd, scb);
7205 printf(" 0x%x", ahd->qinfifo[qinpos]);
7208 ahd_qinfifo_requeue(ahd, prev_scb, scb);
7213 ahd_qinfifo_requeue(ahd, prev_scb, scb);
7219 ahd_set_hnscb_qoff(ahd, ahd->qinfifonext);
7230 savedscbptr = ahd_get_scbptr(ahd);
7231 tid_next = ahd_inw(ahd, WAITING_TID_HEAD);
7245 if (scbid >= ahd->scb_data.numscbs) {
7248 ahd_name(ahd), scbid, ahd->scb_data.numscbs);
7249 ahd_dump_card_state(ahd);
7252 scb = ahd_lookup_scb(ahd, scbid);
7255 ahd_name(ahd), scbid);
7259 ahd_set_scbptr(ahd, scbid);
7260 tid_next = ahd_inw_scbram(ahd, SCB_NEXT2);
7261 if (ahd_match_scb(ahd, scb, target, channel, CAM_LUN_WILDCARD,
7271 printf(" %d ( ", SCB_GET_TARGET(ahd, scb));
7273 found += ahd_search_scb_list(ahd, target, channel,
7276 SCB_GET_TARGET(ahd, scb));
7278 ahd_stitch_tid_list(ahd, tid_prev, tid_head, tid_next);
7284 ahd_set_scbptr(ahd, savedscbptr);
7285 ahd_restore_modes(ahd, saved_modes);
7290 ahd_search_scb_list(struct ahd_softc *ahd, int target, char channel,
7300 AHD_ASSERT_MODES(ahd, AHD_MODE_CCHAN_MSK, AHD_MODE_CCHAN_MSK);
7305 if (scbid >= ahd->scb_data.numscbs) {
7308 ahd_name(ahd), scbid, ahd->scb_data.numscbs);
7309 ahd_dump_card_state(ahd);
7312 scb = ahd_lookup_scb(ahd, scbid);
7315 ahd_name(ahd), scbid);
7318 ahd_set_scbptr(ahd, scbid);
7319 next = ahd_inw_scbram(ahd, SCB_NEXT);
7320 if (ahd_match_scb(ahd, scb, target, channel,
7340 ahd_done(ahd, scb);
7344 ahd_rem_wscb(ahd, scbid, prev, next, tid);
7360 ahd_outw(ahd, CMDS_PENDING, ahd_inw(ahd, CMDS_PENDING) - found);
7365 ahd_stitch_tid_list(struct ahd_softc *ahd, u_int tid_prev,
7368 AHD_ASSERT_MODES(ahd, AHD_MODE_CCHAN_MSK, AHD_MODE_CCHAN_MSK);
7374 ahd_outw(ahd, WAITING_TID_HEAD, tid_next);
7376 ahd_set_scbptr(ahd, tid_prev);
7377 ahd_outw(ahd, SCB_NEXT2, tid_next);
7380 ahd_outw(ahd, WAITING_TID_TAIL, tid_prev);
7385 ahd_outw(ahd, WAITING_TID_HEAD, tid_cur);
7387 ahd_set_scbptr(ahd, tid_prev);
7388 ahd_outw(ahd, SCB_NEXT2, tid_cur);
7390 ahd_set_scbptr(ahd, tid_cur);
7391 ahd_outw(ahd, SCB_NEXT2, tid_next);
7394 ahd_outw(ahd, WAITING_TID_TAIL, tid_cur);
7403 ahd_rem_wscb(struct ahd_softc *ahd, u_int scbid,
7408 AHD_ASSERT_MODES(ahd, AHD_MODE_CCHAN_MSK, AHD_MODE_CCHAN_MSK);
7410 ahd_set_scbptr(ahd, prev);
7411 ahd_outw(ahd, SCB_NEXT, next);
7421 && ahd_inw(ahd, tail_offset) == scbid)
7422 ahd_outw(ahd, tail_offset, prev);
7423 ahd_add_scb_to_free_list(ahd, scbid);
7433 ahd_add_scb_to_free_list(struct ahd_softc *ahd, u_int scbid)
7441 ahd_outb(ahd, SCB_TAG, SCB_LIST_NULL);
7453 ahd_abort_scbs(struct ahd_softc *ahd, int target, char channel,
7466 saved_modes = ahd_save_modes(ahd);
7467 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
7469 found = ahd_search_qinfifo(ahd, target, channel, lun, SCB_LIST_NULL,
7501 scbid = ahd_find_busy_tcl(ahd, tcl);
7502 scbp = ahd_lookup_scb(ahd, scbid);
7504 || ahd_match_scb(ahd, scbp, target, channel,
7507 ahd_unbusy_tcl(ahd, BUILD_TCL_RAW(i, 'A', j));
7516 ahd_flush_qoutfifo(ahd);
7524 scbp_next = LIST_FIRST(&ahd->pending_scbs);
7528 if (ahd_match_scb(ahd, scbp, target, channel, lun, tag, role)) {
7538 ahd_done(ahd, scbp);
7542 ahd_restore_modes(ahd, saved_modes);
7543 ahd_platform_abort_scbs(ahd, target, channel, lun, tag, role, status);
7544 ahd->flags |= AHD_UPDATE_PEND_CMDS;
7549 ahd_reset_current_bus(struct ahd_softc *ahd)
7553 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
7554 ahd_outb(ahd, SIMODE1, ahd_inb(ahd, SIMODE1) & ~ENSCSIRST);
7555 ahd, SCSISEQ0) & ~(ENSELO|ENARBO|SCSIRSTO);
7556 ahd_outb(ahd, SCSISEQ0, scsiseq | SCSIRSTO);
7557 ahd_flush_device_writes(ahd);
7560 ahd_outb(ahd, SCSISEQ0, scsiseq);
7561 ahd_flush_device_writes(ahd);
7563 if ((ahd->bugs & AHD_SCSIRST_BUG) != 0) {
7570 ahd_reset(ahd, /*reinit*/TRUE);
7571 ahd_intr_enable(ahd, /*enable*/TRUE);
7572 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
7575 ahd_clear_intstat(ahd);
7579 ahd_reset_channel(struct ahd_softc *ahd, char channel, int initiate_reset)
7590 ahd->pending_device = NULL;
7597 ahd_pause(ahd);
7600 ahd_clear_critical_section(ahd);
7603 if ((ahd->flags & AHD_TARGETROLE) != 0) {
7604 ahd_run_tqinfifo(ahd, /*paused*/TRUE);
7607 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
7613 ahd_outb(ahd, SCSISEQ0, 0);
7614 ahd_outb(ahd, SCSISEQ1, 0);
7621 next_fifo = fifo = ahd_inb(ahd, DFFSTAT) & CURRFIFO;
7627 ahd_set_modes(ahd, next_fifo, next_fifo);
7628 ahd_outb(ahd, DFCNTRL,
7629 ahd_inb(ahd, DFCNTRL) & ~(SCSIEN|HDMAEN));
7630 while ((ahd_inb(ahd, DFCNTRL) & HDMAENACK) != 0)
7635 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
7636 ahd_outb(ahd, DFFSTAT, next_fifo);
7642 ahd_clear_msg_state(ahd);
7643 ahd_outb(ahd, SIMODE1,
7644 ahd_inb(ahd, SIMODE1) & ~(ENBUSFREE|ENSCSIRST|ENBUSFREE));
7647 ahd_reset_current_bus(ahd);
7649 ahd_clear_intstat(ahd);
7655 found = ahd_abort_scbs(ahd, CAM_TARGET_WILDCARD, channel,
7662 ahd_clear_fifo(ahd, 0);
7663 ahd_clear_fifo(ahd, 1);
7668 max_scsiid = (ahd->features & AHD_WIDE) ? 15 : 7;
7671 if (ahd->enabled_targets[target] == NULL)
7679 ahd_set_width(ahd, &dinfo, MSG_EXT_WDTR_BUS_8_BIT,
7681 ahd_set_syncrate(ahd, &dinfo, /*period*/0,
7688 max_scsiid = (ahd->features & AHD_WIDE) ? 15 : 7;
7698 tstate = ahd->enabled_targets[target];
7708 ahd_queue_lstate_event(ahd, lstate, CAM_TARGET_WILDCARD,
7710 ahd_send_lstate_events(ahd, lstate);
7716 ahd_send_async(ahd, devinfo.channel, CAM_TARGET_WILDCARD,
7718 ahd_restart(ahd);
7726 if ((ahd->flags & AHD_RESET_POLL_ACTIVE) == 0) {
7727 ahd->flags |= AHD_RESET_POLL_ACTIVE;
7728 ahd_freeze_simq(ahd);
7729 ahd_timer_reset(&ahd->reset_timer, 0, ahd_reset_poll, ahd);
7739 struct ahd_softc *ahd;
7745 ahd = arg;
7746 if (ahd == NULL) {
7751 ahd_lock(ahd, &s);
7752 ahd_pause(ahd);
7753 ahd_update_modes(ahd);
7754 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
7755 ahd_outb(ahd, CLRSINT1, CLRSCSIRSTI);
7756 if ((ahd_inb(ahd, SSTAT1) & SCSIRSTI) != 0) {
7757 ahd_timer_reset(&ahd->reset_timer, AHD_RESET_POLL_US,
7758 ahd_reset_poll, ahd);
7759 ahd_unpause(ahd);
7760 ahd_unlock(ahd, &s);
7766 ahd_outb(ahd, SIMODE1, ahd_inb(ahd, SIMODE1) | ENSCSIRST);
7767 scsiseq1 = ahd_inb(ahd, SCSISEQ_TEMPLATE);
7768 ahd_outb(ahd, SCSISEQ1, scsiseq1 & (ENSELI|ENRSELI|ENAUTOATNP));
7769 ahd_unpause(ahd);
7770 ahd->flags &= ~AHD_RESET_POLL_ACTIVE;
7771 ahd_unlock(ahd, &s);
7772 ahd_release_simq(ahd);
7780 struct ahd_softc *ahd;
7786 ahd = arg;
7787 if (ahd == NULL) {
7792 ahd_lock(ahd, &s);
7794 enint_coal = ahd->hs_mailbox & ENINT_COALESCE;
7795 if (ahd->cmdcmplt_total > ahd->int_coalescing_threshold)
7797 else if (ahd->cmdcmplt_total < ahd->int_coalescing_stop_threshold)
7800 if (enint_coal != (ahd->hs_mailbox & ENINT_COALESCE)) {
7801 ahd_enable_coalescing(ahd, enint_coal);
7806 ahd_name(ahd),
7808 ahd->cmdcmplt_total);
7812 ahd->cmdcmplt_bucket = (ahd->cmdcmplt_bucket+1) & (AHD_STAT_BUCKETS-1);
7813 ahd->cmdcmplt_total -= ahd->cmdcmplt_counts[ahd->cmdcmplt_bucket];
7814 ahd->cmdcmplt_counts[ahd->cmdcmplt_bucket] = 0;
7815 ahd_timer_reset(&ahd->stat_timer, AHD_STAT_UPDATE_US,
7816 ahd_stat_timer, ahd);
7817 ahd_unlock(ahd, &s);
7823 ahd_handle_scb_status(struct ahd_softc *ahd, struct scb *scb)
7826 ahd_handle_scsi_status(ahd, scb);
7828 ahd_calc_residual(ahd, scb);
7829 ahd_done(ahd, scb);
7834 ahd_handle_scsi_status(struct ahd_softc *ahd, struct scb *scb)
7848 ahd_freeze_devq(ahd, scb);
7850 qfreeze_cnt = ahd_inw(ahd, QFREEZE_COUNT);
7852 printf("%s: Bad status with 0 qfreeze count!\n", ahd_name(ahd));
7855 ahd_outw(ahd, QFREEZE_COUNT, qfreeze_cnt);
7858 ahd_outb(ahd, SEQ_FLAGS2,
7859 ahd_inb(ahd, SEQ_FLAGS2) & ~SELECTOUT_QFROZEN);
7869 ahd_done(ahd, scb);
7879 ahd_sync_sense(ahd, scb, BUS_DMASYNC_POSTREAD);
7884 ahd_print_path(ahd, scb);
7937 ahd_done(ahd, scb);
7950 ahd_print_path(ahd, scb);
7960 SCB_GET_TARGET(ahd, scb),
7962 SCB_GET_CHANNEL(ahd, scb),
7964 targ_info = ahd_fetch_transinfo(ahd,
7974 ahd_update_residual(ahd, scb);
7977 ahd_print_path(ahd, scb);
7982 sg = ahd_sg_setup(ahd, scb, sg, ahd_get_sense_bufaddr(ahd, scb),
7983 ahd_get_sense_bufsize(ahd, scb),
7987 sc->length = ahd_get_sense_bufsize(ahd, scb);
8007 ahd_update_neg_request(ahd, &devinfo,
8018 ahd_setup_data_scb(ahd, scb);
8020 ahd_queue_scb(ahd, scb);
8030 ahd_name(ahd), SCB_GET_TAG(scb));
8033 ahd_done(ahd, scb);
8042 ahd_calc_residual(struct ahd_softc *ahd, struct scb *scb)
8092 ahd_print_path(ahd, scb);
8095 ahd_freeze_devq(ahd, scb);
8110 sg = ahd_sg_bus_to_virt(ahd, scb, resid_sgptr & SG_PTR_MASK);
8133 ahd_print_path(ahd, scb);
8146 ahd_queue_lstate_event(struct ahd_softc *ahd, struct ahd_tmode_lstate *lstate,
8197 ahd_send_lstate_events(struct ahd_softc *ahd, struct ahd_tmode_lstate *lstate)
8233 ahd_dumpseq(struct ahd_softc* ahd)
8240 ahd_outb(ahd, SEQCTL0, PERRORDIS|FAILDIS|FASTMODE|LOADRAM);
8241 ahd_outb(ahd, PRGMCNT, 0);
8242 ahd_outb(ahd, PRGMCNT+1, 0);
8246 ahd_insb(ahd, SEQRAM, ins_bytes, 4);
8256 ahd_loadseq(struct ahd_softc *ahd)
8275 ahd_name(ahd));
8307 sg_prefetch_align = ahd->pci_cachesize;
8327 if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0)
8351 (ahd->overrun_buf - (uint8_t *)ahd->qoutfifo) / 256;
8356 ahd_outb(ahd, SEQCTL0, PERRORDIS|FAILDIS|FASTMODE|LOADRAM);
8357 ahd_outb(ahd, PRGMCNT, 0);
8358 ahd_outb(ahd, PRGMCNT+1, 0);
8361 if (ahd_check_patch(ahd, &cur_patch, i, &skip_addr) == 0) {
8389 ahd_download_instr(ahd, i, download_consts);
8393 ahd->num_critical_sections = cs_count;
8397 ahd->critical_sections = malloc(cs_count, M_DEVBUF, M_NOWAIT);
8398 if (ahd->critical_sections == NULL)
8400 memcpy(ahd->critical_sections, cs_table, cs_count);
8402 ahd_outb(ahd, SEQCTL0, PERRORDIS|FAILDIS|FASTMODE);
8407 ahd_name(ahd), ahd->features, ahd->bugs, ahd->flags);
8412 ahd_check_patch(struct ahd_softc *ahd, const struct patch **start_patch,
8425 if (cur_patch->patch_func(ahd) == 0) {
8448 ahd_resolve_seqaddr(struct ahd_softc *ahd, u_int address)
8461 ahd_check_patch(ahd, &cur_patch, i, &skip_addr);
8477 ahd_download_instr(struct ahd_softc *ahd, u_int instrptr, uint8_t *dconsts)
8505 fmt3_ins->address = ahd_resolve_seqaddr(ahd, fmt3_ins->address);
8536 ahd_outsb(ahd, SEQRAM, instr.bytes, 4);
8546 ahd_probe_stack_size(struct ahd_softc *ahd)
8561 ahd_outb(ahd, STACK, i & 0xFF);
8562 ahd_outb(ahd, STACK, (i >> 8) & 0xFF);
8569 stack_entry = ahd_inb(ahd, STACK)
8570 |(ahd_inb(ahd, STACK) << 8);
8654 ahd_dump_card_state(struct ahd_softc *ahd)
8665 if (ahd_is_paused(ahd)) {
8669 ahd_pause(ahd);
8671 saved_modes = ahd_save_modes(ahd);
8672 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
8675 ahd_name(ahd),
8676 ahd_inb(ahd, CURADDR) | (ahd_inb(ahd, CURADDR+1) << 8),
8677 ahd_build_mode_state(ahd, ahd->saved_src_mode,
8678 ahd->saved_dst_mode));
8682 if (ahd_check_cmdcmpltqueues(ahd))
8688 ahd_hs_mailbox_print(ahd_inb(ahd, LOCAL_HS_MAILBOX), &cur_col, 50);
8689 ahd_intctl_print(ahd_inb(ahd, INTCTL), &cur_col, 50);
8690 ahd_seqintstat_print(ahd_inb(ahd, SEQINTSTAT), &cur_col, 50);
8691 ahd_saved_mode_print(ahd_inb(ahd, SAVED_MODE), &cur_col, 50);
8692 ahd_dffstat_print(ahd_inb(ahd, DFFSTAT), &cur_col, 50);
8693 ahd_scsisigi_print(ahd_inb(ahd, SCSISIGI), &cur_col, 50);
8694 ahd_scsiphase_print(ahd_inb(ahd, SCSIPHASE), &cur_col, 50);
8695 ahd_scsibus_print(ahd_inb(ahd, SCSIBUS), &cur_col, 50);
8696 ahd_lastphase_print(ahd_inb(ahd, LASTPHASE), &cur_col, 50);
8697 ahd_scsiseq0_print(ahd_inb(ahd, SCSISEQ0), &cur_col, 50);
8698 ahd_scsiseq1_print(ahd_inb(ahd, SCSISEQ1), &cur_col, 50);
8699 ahd_seqctl0_print(ahd_inb(ahd, SEQCTL0), &cur_col, 50);
8700 ahd_seqintctl_print(ahd_inb(ahd, SEQINTCTL), &cur_col, 50);
8701 ahd_seq_flags_print(ahd_inb(ahd, SEQ_FLAGS), &cur_col, 50);
8702 ahd_seq_flags2_print(ahd_inb(ahd, SEQ_FLAGS2), &cur_col, 50);
8703 ahd_sstat0_print(ahd_inb(ahd, SSTAT0), &cur_col, 50);
8704 ahd_sstat1_print(ahd_inb(ahd, SSTAT1), &cur_col, 50);
8705 ahd_sstat2_print(ahd_inb(ahd, SSTAT2), &cur_col, 50);
8706 ahd_sstat3_print(ahd_inb(ahd, SSTAT3), &cur_col, 50);
8707 ahd_perrdiag_print(ahd_inb(ahd, PERRDIAG), &cur_col, 50);
8708 ahd_simode1_print(ahd_inb(ahd, SIMODE1), &cur_col, 50);
8709 ahd_lqistat0_print(ahd_inb(ahd, LQISTAT0), &cur_col, 50);
8710 ahd_lqistat1_print(ahd_inb(ahd, LQISTAT1), &cur_col, 50);
8711 ahd_lqistat2_print(ahd_inb(ahd, LQISTAT2), &cur_col, 50);
8712 ahd_lqostat0_print(ahd_inb(ahd, LQOSTAT0), &cur_col, 50);
8713 ahd_lqostat1_print(ahd_inb(ahd, LQOSTAT1), &cur_col, 50);
8714 ahd_lqostat2_print(ahd_inb(ahd, LQOSTAT2), &cur_col, 50);
8718 ahd->scb_data.numscbs, ahd_inw(ahd, CMDS_PENDING),
8719 ahd_inw(ahd, LASTSCB), ahd_inw(ahd, CURRSCB),
8720 ahd_inw(ahd, NEXTSCB));
8723 ahd_search_qinfifo(ahd, CAM_TARGET_WILDCARD, ALL_CHANNELS,
8726 saved_scb_index = ahd_get_scbptr(ahd);
8729 LIST_FOREACH(scb, &ahd->pending_scbs, pending_links) {
8733 ahd_inb_scbram(ahd, SCB_FIFO_USE_COUNT));
8734 ahd_set_scbptr(ahd, SCB_GET_TAG(scb));
8735 ahd_scb_control_print(ahd_inb_scbram(ahd, SCB_CONTROL),
8737 ahd_scb_scsiid_print(ahd_inb_scbram(ahd, SCB_SCSIID),
8744 TAILQ_FOREACH(scb, &ahd->scb_data.free_scbs, links.tqe) {
8754 LIST_FOREACH(scb, &ahd->scb_data.any_dev_free_scb_list, links.le) {
8762 scb_index = ahd_inw(ahd, COMPLETE_SCB_DMAINPROG_HEAD);
8765 ahd_set_scbptr(ahd, scb_index);
8767 scb_index = ahd_inw_scbram(ahd, SCB_NEXT_COMPLETE);
8772 scb_index = ahd_inw(ahd, COMPLETE_SCB_HEAD);
8775 ahd_set_scbptr(ahd, scb_index);
8777 scb_index = ahd_inw_scbram(ahd, SCB_NEXT_COMPLETE);
8783 scb_index = ahd_inw(ahd, COMPLETE_DMA_SCB_HEAD);
8786 ahd_set_scbptr(ahd, scb_index);
8788 scb_index = ahd_inw_scbram(ahd, SCB_NEXT_COMPLETE);
8791 ahd_set_scbptr(ahd, saved_scb_index);
8792 dffstat = ahd_inb(ahd, DFFSTAT);
8799 ahd_set_modes(ahd, AHD_MODE_DFF0 + i, AHD_MODE_DFF0 + i);
8800 fifo_scbptr = ahd_get_scbptr(ahd);
8802 ahd_name(ahd), i,
8804 ahd_inw(ahd, LONGJMP_ADDR), fifo_scbptr);
8806 ahd_seqimode_print(ahd_inb(ahd, SEQIMODE), &cur_col, 50);
8807 ahd_seqintsrc_print(ahd_inb(ahd, SEQINTSRC), &cur_col, 50);
8808 ahd_dfcntrl_print(ahd_inb(ahd, DFCNTRL), &cur_col, 50);
8809 ahd_dfstatus_print(ahd_inb(ahd, DFSTATUS), &cur_col, 50);
8810 ahd_sg_cache_shadow_print(ahd_inb(ahd, SG_CACHE_SHADOW),
8812 ahd_sg_state_print(ahd_inb(ahd, SG_STATE), &cur_col, 50);
8813 ahd_dffsxfrctl_print(ahd_inb(ahd, DFFSXFRCTL), &cur_col, 50);
8814 ahd_soffcnt_print(ahd_inb(ahd, SOFFCNT), &cur_col, 50);
8815 ahd_mdffstat_print(ahd_inb(ahd, MDFFSTAT), &cur_col, 50);
8821 ahd_inl(ahd, SHADDR+4),
8822 ahd_inl(ahd, SHADDR),
8823 (ahd_inb(ahd, SHCNT)
8824 | (ahd_inb(ahd, SHCNT + 1) << 8)
8825 | (ahd_inb(ahd, SHCNT + 2) << 16)));
8827 ahd_inl(ahd, HADDR+4),
8828 ahd_inl(ahd, HADDR),
8829 (ahd_inb(ahd, HCNT)
8830 | (ahd_inb(ahd, HCNT + 1) << 8)
8831 | (ahd_inb(ahd, HCNT + 2) << 16)));
8832 ahd_ccsgctl_print(ahd_inb(ahd, CCSGCTL), &cur_col, 50);
8835 fifo_scb = ahd_lookup_scb(ahd, fifo_scbptr);
8843 printf("0x%x ", ahd_inb(ahd, LQIN + i));
8845 ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
8847 ahd_name(ahd), ahd_inb(ahd, LQISTATE), ahd_inb(ahd, LQOSTATE),
8848 ahd_inb(ahd, OPTIONMODE));
8850 ahd_name(ahd), ahd_inb(ahd, OS_SPACE_CNT),
8851 ahd_inb(ahd, MAXCMDCNT));
8852 ahd_simode0_print(ahd_inb(ahd, SIMODE0), &cur_col, 50);
8854 ahd_set_modes(ahd, AHD_MODE_CCHAN, AHD_MODE_CCHAN);
8856 ahd_set_modes(ahd, ahd->saved_src_mode, ahd->saved_dst_mode);
8858 ahd_name(ahd), ahd_inw(ahd, REG0), ahd_inw(ahd, SINDEX),
8859 ahd_inw(ahd, DINDEX));
8861 ahd_name(ahd), ahd_get_scbptr(ahd),
8862 ahd_inw_scbram(ahd, SCB_NEXT),
8863 ahd_inw_scbram(ahd, SCB_NEXT2));
8865 ahd_inb_scbram(ahd, SCB_CDB_STORE),
8866 ahd_inb_scbram(ahd, SCB_CDB_STORE+1),
8867 ahd_inb_scbram(ahd, SCB_CDB_STORE+2),
8868 ahd_inb_scbram(ahd, SCB_CDB_STORE+3),
8869 ahd_inb_scbram(ahd, SCB_CDB_STORE+4),
8870 ahd_inb_scbram(ahd, SCB_CDB_STORE+5));
8872 for (i = 0; i < ahd->stack_size; i++) {
8873 ahd->saved_stack[i] =
8874 ahd_inb(ahd, STACK)|(ahd_inb(ahd, STACK) << 8);
8875 printf(" 0x%x", ahd->saved_stack[i]);
8877 for (i = ahd->stack_size-1; i >= 0; i--) {
8878 ahd_outb(ahd, STACK, ahd->saved_stack[i] & 0xFF);
8879 ahd_outb(ahd, STACK, (ahd->saved_stack[i] >> 8) & 0xFF);
8882 ahd_platform_dump_card_state(ahd);
8883 ahd_restore_modes(ahd, saved_modes);
8885 ahd_unpause(ahd);
8889 ahd_dump_scbs(struct ahd_softc *ahd)
8895 saved_modes = ahd_save_modes(ahd);
8896 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
8897 saved_scb_index = ahd_get_scbptr(ahd);
8899 ahd_set_scbptr(ahd, i);
8902 ahd_inb_scbram(ahd, SCB_CONTROL),
8903 ahd_inb_scbram(ahd, SCB_SCSIID),
8904 ahd_inw_scbram(ahd, SCB_NEXT),
8905 ahd_inw_scbram(ahd, SCB_NEXT2),
8906 ahd_inl_scbram(ahd, SCB_SGPTR),
8907 ahd_inl_scbram(ahd, SCB_RESIDUAL_SGPTR));
8910 ahd_set_scbptr(ahd, saved_scb_index);
8911 ahd_restore_modes(ahd, saved_modes);
8922 ahd_read_seeprom(struct ahd_softc *ahd, uint16_t *tbuf,
8934 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
8938 ahd_outb(ahd, SEEADR, cur_addr);
8939 ahd_outb(ahd, SEECTL, SEEOP_READ | SEESTART);
8941 error = ahd_wait_seeprom(ahd);
8944 ahd_name(ahd));
8951 *bytestream_ptr++ = ahd_inb(ahd, SEEDAT);
8952 *bytestream_ptr = ahd_inb(ahd, SEEDAT+1);
8957 *tbuf = ahd_inw(ahd, SEEDAT);
8970 ahd_write_seeprom(struct ahd_softc *ahd, uint16_t *tbuf,
8978 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
8982 ahd_outb(ahd, SEEADR, SEEOP_EWEN_ADDR);
8983 ahd_outb(ahd, SEECTL, SEEOP_EWEN | SEESTART);
8984 error = ahd_wait_seeprom(ahd);
8995 ahd_outw(ahd, SEEDAT, *tbuf++);
8996 ahd_outb(ahd, SEEADR, cur_addr);
8997 ahd_outb(ahd, SEECTL, SEEOP_WRITE | SEESTART);
8999 retval = ahd_wait_seeprom(ahd);
9007 ahd_outb(ahd, SEEADR, SEEOP_EWDS_ADDR);
9008 ahd_outb(ahd, SEECTL, SEEOP_EWDS | SEESTART);
9009 error = ahd_wait_seeprom(ahd);
9019 ahd_wait_seeprom(struct ahd_softc *ahd)
9024 while ((ahd_inb(ahd, SEESTAT) & (SEEARBACK|SEEBUSY)) != 0 && --cnt)
9087 ahd_acquire_seeprom(struct ahd_softc *ahd)
9102 error = ahd_read_flexport(ahd, FLXADDR_ROMSTAT_CURSENSECTL, &seetype);
9111 ahd_release_seeprom(struct ahd_softc *ahd)
9117 ahd_write_flexport(struct ahd_softc *ahd, u_int addr, u_int value)
9121 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
9124 ahd_outb(ahd, BRDCTL, BRDEN|(addr << 3));
9125 error = ahd_wait_flexport(ahd);
9128 ahd_outb(ahd, BRDDAT, value);
9129 ahd_flush_device_writes(ahd);
9130 ahd_outb(ahd, BRDCTL, BRDSTB|BRDEN|(addr << 3));
9131 ahd_flush_device_writes(ahd);
9132 ahd_outb(ahd, BRDCTL, BRDEN|(addr << 3));
9133 ahd_flush_device_writes(ahd);
9134 ahd_outb(ahd, BRDCTL, 0);
9135 ahd_flush_device_writes(ahd);
9140 ahd_read_flexport(struct ahd_softc *ahd, u_int addr, uint8_t *value)
9144 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
9147 ahd_outb(ahd, BRDCTL, BRDRW|BRDEN|(addr << 3));
9148 error = ahd_wait_flexport(ahd);
9151 *value = ahd_inb(ahd, BRDDAT);
9152 ahd_outb(ahd, BRDCTL, 0);
9153 ahd_flush_device_writes(ahd);
9161 ahd_wait_flexport(struct ahd_softc *ahd)
9165 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
9167 while ((ahd_inb(ahd, BRDCTL) & FLXARBACK) == 0 && --cnt)
9178 ahd_find_tmode_devs(struct ahd_softc *ahd, struct cam_sim *sim, union ccb *ccb,
9184 if ((ahd->features & AHD_TARGETMODE) == 0)
9194 *lstate = ahd->black_hole;
9198 max_id = (ahd->features & AHD_WIDE) ? 15 : 7;
9205 *tstate = ahd->enabled_targets[ccb->ccb_h.target_id];
9219 ahd_handle_en_lun(struct ahd_softc *ahd, struct cam_sim *sim, union ccb *ccb)
9232 status = ahd_find_tmode_devs(ahd, sim, ccb, &tstate, &lstate,
9240 if ((ahd->features & AHD_MULTIROLE) != 0) {
9243 our_id = ahd->our_id;
9245 if ((ahd->features & AHD_MULTI_TID) != 0
9246 && (ahd->flags & AHD_INITIATORROLE) != 0) {
9255 } else if ((ahd->flags & AHD_INITIATORROLE) != 0
9256 || ahd->enabled_luns > 0) {
9278 if ((ahd->flags & AHD_TARGETROLE) == 0
9283 ahd_lock(ahd, &s);
9284 if (LIST_FIRST(&ahd->pending_scbs) != NULL) {
9286 ahd_unlock(ahd, &s);
9289 ahd->flags |= AHD_TARGETROLE;
9290 if ((ahd->features & AHD_MULTIROLE) == 0)
9291 ahd->flags &= ~AHD_INITIATORROLE;
9292 ahd_pause(ahd);
9293 ahd_loadseq(ahd);
9294 ahd_restart(ahd);
9295 ahd_unlock(ahd, &s);
9300 channel = SIM_CHANNEL(ahd, sim);
9332 tstate = ahd_alloc_tstate(ahd, target, channel);
9361 ahd_lock(ahd, &s);
9362 ahd_pause(ahd);
9365 ahd->enabled_luns++;
9367 if ((ahd->features & AHD_MULTI_TID) != 0) {
9370 targid_mask = ahd_inb(ahd, TARGID)
9371 | (ahd_inb(ahd, TARGID + 1) << 8);
9374 ahd_outb(ahd, TARGID, targid_mask);
9375 ahd_outb(ahd, TARGID+1, (targid_mask >> 8));
9377 ahd, targid_mask);
9382 channel = SIM_CHANNEL(ahd, sim);
9383 our_id = SIM_SCSI_ID(ahd, sim);
9394 sblkctl = ahd_inb(ahd, SBLKCTL);
9397 if ((ahd->features & AHD_TWIN) == 0)
9400 ahd->our_id = target;
9403 ahd_outb(ahd, SBLKCTL,
9406 ahd_outb(ahd, SCSIID, target);
9409 ahd_outb(ahd, SBLKCTL, sblkctl);
9413 ahd->black_hole = lstate;
9415 if (ahd->black_hole != NULL && ahd->enabled_luns > 0) {
9416 scsiseq1 = ahd_inb(ahd, SCSISEQ_TEMPLATE);
9418 ahd_outb(ahd, SCSISEQ_TEMPLATE, scsiseq1);
9419 scsiseq1 = ahd_inb(ahd, SCSISEQ1);
9421 ahd_outb(ahd, SCSISEQ1, scsiseq1);
9423 ahd_unpause(ahd);
9424 ahd_unlock(ahd, &s);
9437 ahd_lock(ahd, &s);
9440 LIST_FOREACH(scb, &ahd->pending_scbs, pending_links) {
9448 ahd_unlock(ahd, &s);
9464 ahd_unlock(ahd, &s);
9473 ahd_pause(ahd);
9477 ahd->enabled_luns--;
9485 ahd_free_tstate(ahd, target, channel,
9487 if (ahd->features & AHD_MULTI_TID) {
9490 targid_mask = ahd_inb(ahd, TARGID)
9491 | (ahd_inb(ahd, TARGID + 1)
9495 ahd_outb(ahd, TARGID, targid_mask);
9496 ahd_outb(ahd, TARGID+1,
9498 ahd_update_scsiid(ahd, targid_mask);
9503 ahd->black_hole = NULL;
9511 if (ahd->enabled_luns == 0) {
9515 scsiseq1 = ahd_inb(ahd, SCSISEQ_TEMPLATE);
9517 ahd_outb(ahd, SCSISEQ_TEMPLATE, scsiseq1);
9518 scsiseq1 = ahd_inb(ahd, SCSISEQ1);
9520 ahd_outb(ahd, SCSISEQ1, scsiseq1);
9522 if ((ahd->features & AHD_MULTIROLE) == 0) {
9524 ahd->flags &= ~AHD_TARGETROLE;
9525 ahd->flags |= AHD_INITIATORROLE;
9526 ahd_pause(ahd);
9527 ahd_loadseq(ahd);
9528 ahd_restart(ahd);
9535 ahd_unpause(ahd);
9536 ahd_unlock(ahd, &s);
9542 ahd_update_scsiid(struct ahd_softc *ahd, u_int targid_mask)
9548 if ((ahd->features & AHD_MULTI_TID) == 0)
9557 if ((ahd->features & AHD_ULTRA2) != 0)
9558 scsiid = ahd_inb(ahd, SCSIID_ULTRA2);
9560 scsiid = ahd_inb(ahd, SCSIID);
9568 our_id = ahd->our_id;
9574 if ((ahd->features & AHD_ULTRA2) != 0)
9575 ahd_outb(ahd, SCSIID_ULTRA2, scsiid);
9577 ahd_outb(ahd, SCSIID, scsiid);
9583 ahd_run_tqinfifo(struct ahd_softc *ahd, int paused)
9587 ahd_sync_tqinfifo(ahd, BUS_DMASYNC_POSTREAD);
9588 while ((cmd = &ahd->targetcmds[ahd->tqinfifonext])->cmd_valid != 0) {
9594 if (ahd_handle_target_cmd(ahd, cmd) != 0)
9598 ahd_dmamap_sync(ahd, ahd->parent_dmat /*shared_data_dmat*/,
9599 ahd->shared_data_map.dmamap,
9600 ahd_targetcmd_offset(ahd, ahd->tqinfifonext),
9603 ahd->tqinfifonext++;
9609 if ((ahd->tqinfifonext & (HOST_TQINPOS - 1)) == 1) {
9612 hs_mailbox = ahd_inb(ahd, HS_MAILBOX);
9614 hs_mailbox |= ahd->tqinfifonext & HOST_TQINPOS;
9615 ahd_outb(ahd, HS_MAILBOX, hs_mailbox);
9622 ahd_handle_target_cmd(struct ahd_softc *ahd, struct target_cmd *cmd)
9632 initiator = SCSIID_TARGET(ahd, cmd->scsiid);
9637 tstate = ahd->enabled_targets[target];
9646 lstate = ahd->black_hole;
9650 ahd->flags |= AHD_TQINFIFO_BLOCKED;
9656 ahd->flags &= ~AHD_TQINFIFO_BLOCKED;
9660 ahd_name(ahd),
9662 lstate == ahd->black_hole ? "(Black Holed)" : "");
9666 if (lstate == ahd->black_hole) {
9725 initiator, target, lun, ahd->pending_device);
9727 ahd->pending_device = lstate;