• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /freebsd-12-stable/sys/dev/aic7xxx/

Lines Matching defs:ahd

112 static void		ahd_handle_transmission_error(struct ahd_softc *ahd);
113 static void ahd_handle_lqiphase_error(struct ahd_softc *ahd,
115 static int ahd_handle_pkt_busfree(struct ahd_softc *ahd,
117 static int ahd_handle_nonpkt_busfree(struct ahd_softc *ahd);
118 static void ahd_handle_proto_violation(struct ahd_softc *ahd);
119 static void ahd_force_renegotiation(struct ahd_softc *ahd,
123 ahd_alloc_tstate(struct ahd_softc *ahd,
126 static void ahd_free_tstate(struct ahd_softc *ahd,
129 static void ahd_devlimited_syncrate(struct ahd_softc *ahd,
134 static void ahd_update_neg_table(struct ahd_softc *ahd,
137 static void ahd_update_pending_scbs(struct ahd_softc *ahd);
138 static void ahd_fetch_devinfo(struct ahd_softc *ahd,
140 static void ahd_scb_devinfo(struct ahd_softc *ahd,
143 static void ahd_setup_initiator_msgout(struct ahd_softc *ahd,
146 static void ahd_build_transfer_msg(struct ahd_softc *ahd,
148 static void ahd_construct_sdtr(struct ahd_softc *ahd,
151 static void ahd_construct_wdtr(struct ahd_softc *ahd,
154 static void ahd_construct_ppr(struct ahd_softc *ahd,
158 static void ahd_clear_msg_state(struct ahd_softc *ahd);
159 static void ahd_handle_message_phase(struct ahd_softc *ahd);
165 static int ahd_sent_msg(struct ahd_softc *ahd, ahd_msgtype type,
167 static int ahd_parse_msg(struct ahd_softc *ahd,
169 static int ahd_handle_msg_reject(struct ahd_softc *ahd,
171 static void ahd_handle_ign_wide_residue(struct ahd_softc *ahd,
173 static void ahd_reinitialize_dataptrs(struct ahd_softc *ahd);
174 static void ahd_handle_devreset(struct ahd_softc *ahd,
179 static void ahd_setup_target_msgin(struct ahd_softc *ahd,
184 static u_int ahd_sglist_size(struct ahd_softc *ahd);
185 static u_int ahd_sglist_allocsize(struct ahd_softc *ahd);
188 static void ahd_initialize_hscbs(struct ahd_softc *ahd);
189 static int ahd_init_scbdata(struct ahd_softc *ahd);
190 static void ahd_fini_scbdata(struct ahd_softc *ahd);
191 static void ahd_setup_iocell_workaround(struct ahd_softc *ahd);
192 static void ahd_iocell_first_selection(struct ahd_softc *ahd);
193 static void ahd_add_col_list(struct ahd_softc *ahd,
195 static void ahd_rem_col_list(struct ahd_softc *ahd,
197 static void ahd_chip_init(struct ahd_softc *ahd);
198 static void ahd_qinfifo_requeue(struct ahd_softc *ahd,
201 static int ahd_qinfifo_count(struct ahd_softc *ahd);
202 static int ahd_search_scb_list(struct ahd_softc *ahd, int target,
208 static void ahd_stitch_tid_list(struct ahd_softc *ahd,
211 static void ahd_add_scb_to_free_list(struct ahd_softc *ahd,
213 static u_int ahd_rem_wscb(struct ahd_softc *ahd, u_int scbid,
215 static void ahd_reset_current_bus(struct ahd_softc *ahd);
219 static void ahd_dumpseq(struct ahd_softc *ahd);
221 static void ahd_loadseq(struct ahd_softc *ahd);
222 static int ahd_check_patch(struct ahd_softc *ahd,
225 static u_int ahd_resolve_seqaddr(struct ahd_softc *ahd,
227 static void ahd_download_instr(struct ahd_softc *ahd,
229 static int ahd_probe_stack_size(struct ahd_softc *ahd);
230 static int ahd_other_scb_timeout(struct ahd_softc *ahd,
233 static int ahd_scb_active_in_fifo(struct ahd_softc *ahd,
235 static void ahd_run_data_fifo(struct ahd_softc *ahd,
239 static void ahd_queue_lstate_event(struct ahd_softc *ahd,
244 static void ahd_update_scsiid(struct ahd_softc *ahd,
246 static int ahd_handle_target_cmd(struct ahd_softc *ahd,
251 static __inline void ahd_assert_atn(struct ahd_softc *ahd);
252 static __inline int ahd_currently_packetized(struct ahd_softc *ahd);
253 static __inline int ahd_set_active_fifo(struct ahd_softc *ahd);
256 ahd_assert_atn(struct ahd_softc *ahd)
258 ahd_outb(ahd, SCSISIGO, ATNO);
268 ahd_currently_packetized(struct ahd_softc *ahd)
273 saved_modes = ahd_save_modes(ahd);
274 if ((ahd->bugs & AHD_PKTIZED_STATUS_BUG) != 0) {
280 ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
281 packetized = ahd_inb(ahd, LQISTATE) != 0;
283 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
284 packetized = ahd_inb(ahd, LQISTAT2) & PACKETIZED;
286 ahd_restore_modes(ahd, saved_modes);
291 ahd_set_active_fifo(struct ahd_softc *ahd)
295 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
296 active_fifo = ahd_inb(ahd, DFFSTAT) & CURRFIFO;
300 ahd_set_modes(ahd, active_fifo, active_fifo);
312 ahd_restart(struct ahd_softc *ahd)
315 ahd_pause(ahd);
317 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
320 ahd_clear_msg_state(ahd);
321 ahd_outb(ahd, SCSISIGO, 0); /* De-assert BSY */
322 ahd_outb(ahd, MSG_OUT, MSG_NOOP); /* No message to send */
323 ahd_outb(ahd, SXFRCTL1, ahd_inb(ahd, SXFRCTL1) & ~BITBUCKET);
324 ahd_outb(ahd, SEQINTCTL, 0);
325 ahd_outb(ahd, LASTPHASE, P_BUSFREE);
326 ahd_outb(ahd, SEQ_FLAGS, 0);
327 ahd_outb(ahd, SAVED_SCSIID, 0xFF);
328 ahd_outb(ahd, SAVED_LUN, 0xFF);
337 ahd_outb(ahd, TQINPOS, ahd->tqinfifonext);
340 ahd_outb(ahd, SCSISEQ1,
341 ahd_inb(ahd, SCSISEQ_TEMPLATE) & (ENSELI|ENRSELI|ENAUTOATNP));
342 ahd_set_modes(ahd, AHD_MODE_CCHAN, AHD_MODE_CCHAN);
349 ahd_outb(ahd, CLRINT, CLRSEQINT);
351 ahd_outb(ahd, SEQCTL0, FASTMODE|SEQRESET);
352 ahd_unpause(ahd);
356 ahd_clear_fifo(struct ahd_softc *ahd, u_int fifo)
362 printf("%s: Clearing FIFO %d\n", ahd_name(ahd), fifo);
364 saved_modes = ahd_save_modes(ahd);
365 ahd_set_modes(ahd, fifo, fifo);
366 ahd_outb(ahd, DFFSXFRCTL, RSTCHN|CLRSHCNT);
367 if ((ahd_inb(ahd, SG_STATE) & FETCH_INPROG) != 0)
368 ahd_outb(ahd, CCSGCTL, CCSGRESET);
369 ahd_outb(ahd, LONGJMP_ADDR + 1, INVALID_ADDR);
370 ahd_outb(ahd, SG_STATE, 0);
371 ahd_restore_modes(ahd, saved_modes);
380 ahd_flush_qoutfifo(struct ahd_softc *ahd)
389 saved_modes = ahd_save_modes(ahd);
394 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
395 saved_scbptr = ahd_get_scbptr(ahd);
396 while ((ahd_inb(ahd, LQISTAT2) & LQIGSAVAIL) != 0) {
400 scbid = ahd_inw(ahd, GSFIFO);
401 scb = ahd_lookup_scb(ahd, scbid);
404 ahd_name(ahd), scbid);
405 AHD_CORRECTABLE_ERROR(ahd);
418 ahd_set_modes(ahd, fifo_mode, fifo_mode);
420 if (ahd_scb_active_in_fifo(ahd, scb) == 0)
423 ahd_run_data_fifo(ahd, scb);
442 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
443 ahd_set_scbptr(ahd, scbid);
444 if ((ahd_inb_scbram(ahd, SCB_SGPTR) & SG_LIST_NULL) == 0
445 && ((ahd_inb_scbram(ahd, SCB_SGPTR) & SG_FULL_RESID) != 0
446 || (ahd_inb_scbram(ahd, SCB_RESIDUAL_SGPTR)
456 ahd_outb(ahd, SCB_SCSI_STATUS, 0);
457 ahd_outb(ahd, SCB_SGPTR,
458 ahd_inb_scbram(ahd, SCB_SGPTR)
460 ahd_outw(ahd, SCB_TAG, scbid);
461 ahd_outw(ahd, SCB_NEXT_COMPLETE, SCB_LIST_NULL);
462 comp_head = ahd_inw(ahd, COMPLETE_DMA_SCB_HEAD);
464 ahd_outw(ahd, COMPLETE_DMA_SCB_HEAD, scbid);
465 ahd_outw(ahd, COMPLETE_DMA_SCB_TAIL, scbid);
469 tail = ahd_inw(ahd, COMPLETE_DMA_SCB_TAIL);
470 ahd_set_scbptr(ahd, tail);
471 ahd_outw(ahd, SCB_NEXT_COMPLETE, scbid);
472 ahd_outw(ahd, COMPLETE_DMA_SCB_TAIL, scbid);
473 ahd_set_scbptr(ahd, scbid);
476 ahd_complete_scb(ahd, scb);
478 ahd_set_scbptr(ahd, saved_scbptr);
483 ahd_set_modes(ahd, AHD_MODE_CCHAN, AHD_MODE_CCHAN);
489 while (((ccscbctl = ahd_inb(ahd, CCSCBCTL)) & (CCARREN|CCSCBEN)) != 0) {
506 ahd_outb(ahd, CCSCBCTL, ccscbctl & ~(CCARREN|CCSCBEN));
512 ahd_run_qoutfifo(ahd);
514 saved_scbptr = ahd_get_scbptr(ahd);
519 scbid = ahd_inw(ahd, COMPLETE_DMA_SCB_HEAD);
524 ahd_set_scbptr(ahd, scbid);
525 next_scbid = ahd_inw_scbram(ahd, SCB_NEXT_COMPLETE);
526 scb = ahd_lookup_scb(ahd, scbid);
529 "SCB %d invalid\n", ahd_name(ahd), scbid);
530 AHD_CORRECTABLE_ERROR(ahd);
535 *hscb_ptr++ = ahd_inb_scbram(ahd, SCB_BASE + i);
537 ahd_complete_scb(ahd, scb);
540 ahd_outw(ahd, COMPLETE_DMA_SCB_HEAD, SCB_LIST_NULL);
541 ahd_outw(ahd, COMPLETE_DMA_SCB_TAIL, SCB_LIST_NULL);
543 scbid = ahd_inw(ahd, COMPLETE_ON_QFREEZE_HEAD);
546 ahd_set_scbptr(ahd, scbid);
547 next_scbid = ahd_inw_scbram(ahd, SCB_NEXT_COMPLETE);
548 scb = ahd_lookup_scb(ahd, scbid);
551 ahd_name(ahd), scbid);
552 AHD_CORRECTABLE_ERROR(ahd);
556 ahd_complete_scb(ahd, scb);
559 ahd_outw(ahd, COMPLETE_ON_QFREEZE_HEAD, SCB_LIST_NULL);
561 scbid = ahd_inw(ahd, COMPLETE_SCB_HEAD);
564 ahd_set_scbptr(ahd, scbid);
565 next_scbid = ahd_inw_scbram(ahd, SCB_NEXT_COMPLETE);
566 scb = ahd_lookup_scb(ahd, scbid);
569 ahd_name(ahd), scbid);
570 AHD_CORRECTABLE_ERROR(ahd);
574 ahd_complete_scb(ahd, scb);
577 ahd_outw(ahd, COMPLETE_SCB_HEAD, SCB_LIST_NULL);
582 ahd_set_scbptr(ahd, saved_scbptr);
583 ahd_restore_modes(ahd, saved_modes);
584 ahd->flags |= AHD_UPDATE_PEND_CMDS;
592 ahd_scb_active_in_fifo(struct ahd_softc *ahd, struct scb *scb)
601 if (ahd_get_scbptr(ahd) != SCB_GET_TAG(scb)
602 || ((ahd_inb(ahd, LONGJMP_ADDR+1) & INVALID_ADDR) != 0
603 && (ahd_inb(ahd, SEQINTSRC) & (CFG4DATA|SAVEPTRS)) == 0))
621 ahd_run_data_fifo(struct ahd_softc *ahd, struct scb *scb)
625 seqintsrc = ahd_inb(ahd, SEQINTSRC);
633 sgptr = ahd_inl_scbram(ahd, SCB_SGPTR) & ~SG_FULL_RESID;
634 ahd_outb(ahd, SCB_SGPTR, sgptr);
639 datacnt = ahd_inl_scbram(ahd, SCB_DATACNT);
642 ahd_outb(ahd, SG_STATE, 0);
644 ahd_outb(ahd, SG_STATE, LOADING_NEEDED);
645 ahd_outq(ahd, HADDR, ahd_inq_scbram(ahd, SCB_DATAPTR));
646 ahd_outl(ahd, HCNT, datacnt & AHD_SG_LEN_MASK);
647 ahd_outb(ahd, SG_CACHE_PRE, sgptr);
648 ahd_outb(ahd, DFCNTRL, PRELOADEN|SCSIEN|HDMAEN);
653 ahd_outb(ahd, SCB_RESIDUAL_DATACNT+3, datacnt >> 24);
654 ahd_outl(ahd, SCB_RESIDUAL_SGPTR, sgptr & SG_PTR_MASK);
659 ahd_outb(ahd, SCB_FIFO_USE_COUNT,
660 ahd_inb_scbram(ahd, SCB_FIFO_USE_COUNT) + 1);
665 ahd_outw(ahd, LONGJMP_ADDR, 0);
671 ahd_outb(ahd, CLRSEQINTSRC, CLRCFG4DATA);
676 if ((ahd_inb(ahd, LONGJMP_ADDR+1)&INVALID_ADDR) != 0) {
689 if ((ahd_inb(ahd, SG_STATE) & FETCH_INPROG) != 0)
690 ahd_outb(ahd, CCSGCTL, 0);
691 ahd_outb(ahd, SG_STATE, 0);
697 ahd_outb(ahd, DFCNTRL, ahd_inb(ahd, DFCNTRL) | FIFOFLUSH);
702 sgptr = ahd_inl_scbram(ahd, SCB_RESIDUAL_SGPTR);
703 resid = ahd_inl(ahd, SHCNT);
704 resid |= ahd_inb_scbram(ahd, SCB_RESIDUAL_DATACNT+3) << 24;
705 ahd_outl(ahd, SCB_RESIDUAL_DATACNT, resid);
706 if ((ahd_inb(ahd, SG_CACHE_SHADOW) & LAST_SEG) == 0) {
714 if ((ahd_inb(ahd, SG_CACHE_SHADOW) & 0x80) != 0
718 sgptr |= ahd_inb(ahd, SG_CACHE_SHADOW)
720 ahd_outl(ahd, SCB_RESIDUAL_SGPTR, sgptr);
721 ahd_outb(ahd, SCB_RESIDUAL_DATACNT + 3, 0);
723 ahd_outb(ahd, SCB_RESIDUAL_SGPTR,
729 ahd_outq(ahd, SCB_DATAPTR, ahd_inq(ahd, SHADDR));
730 ahd_outl(ahd, SCB_DATACNT, resid);
731 ahd_outl(ahd, SCB_SGPTR, sgptr);
732 ahd_outb(ahd, CLRSEQINTSRC, CLRSAVEPTRS);
733 ahd_outb(ahd, SEQIMODE,
734 ahd_inb(ahd, SEQIMODE) | ENSAVEPTRS);
739 if ((ahd_inb(ahd, DFCNTRL) & DIRECTION) != 0)
741 } else if ((ahd_inb(ahd, SG_STATE) & LOADING_NEEDED) != 0) {
752 if ((ahd_inb(ahd, SG_STATE) & FETCH_INPROG) != 0) {
753 ahd_outb(ahd, CCSGCTL, 0);
754 ahd_outb(ahd, SG_STATE, LOADING_NEEDED);
763 if ((ahd_inb(ahd, DFSTATUS) & PRELOAD_AVAIL) != 0
764 && (ahd_inb(ahd, DFCNTRL) & HDMAENACK) != 0) {
770 sgptr = ahd_inl_scbram(ahd, SCB_RESIDUAL_SGPTR);
772 if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0) {
775 sg = ahd_sg_bus_to_virt(ahd, scb, sgptr);
782 sg = ahd_sg_bus_to_virt(ahd, scb, sgptr);
793 ahd_outb(ahd, SCB_RESIDUAL_DATACNT+3, data_len >> 24);
794 ahd_outl(ahd, SCB_RESIDUAL_SGPTR, sgptr);
801 ahd_outb(ahd, SG_STATE, 0);
803 ahd_outq(ahd, HADDR, data_addr);
804 ahd_outl(ahd, HCNT, data_len & AHD_SG_LEN_MASK);
805 ahd_outb(ahd, SG_CACHE_PRE, sgptr & 0xFF);
810 dfcntrl = ahd_inb(ahd, DFCNTRL)|PRELOADEN|HDMAEN;
811 if ((ahd->features & AHD_NEW_DFCNTRL_OPTS) != 0) {
819 ahd_outb(ahd, DFCNTRL, dfcntrl);
821 } else if ((ahd_inb(ahd, SG_CACHE_SHADOW) & LAST_SEG_DONE) != 0) {
827 ahd_outb(ahd, SCB_SGPTR,
828 ahd_inb_scbram(ahd, SCB_SGPTR) | SG_LIST_NULL);
830 } else if ((ahd_inb(ahd, DFSTATUS) & FIFOEMP) != 0) {
837 ahd_outb(ahd, LONGJMP_ADDR + 1, INVALID_ADDR);
838 ahd_outb(ahd, SCB_FIFO_USE_COUNT,
839 ahd_inb_scbram(ahd, SCB_FIFO_USE_COUNT) - 1);
840 ahd_outb(ahd, DFFSXFRCTL, CLRCHN);
855 ahd_run_qoutfifo(struct ahd_softc *ahd)
861 if ((ahd->flags & AHD_RUNNING_QOUTFIFO) != 0)
863 ahd->flags |= AHD_RUNNING_QOUTFIFO;
864 ahd_sync_qoutfifo(ahd, BUS_DMASYNC_POSTREAD);
866 completion = &ahd->qoutfifo[ahd->qoutfifonext];
868 if (completion->valid_tag != ahd->qoutfifonext_valid_tag)
872 scb = ahd_lookup_scb(ahd, scb_index);
876 ahd_name(ahd), scb_index,
877 ahd->qoutfifonext);
878 AHD_CORRECTABLE_ERROR(ahd);
879 ahd_dump_card_state(ahd);
881 ahd_handle_scb_status(ahd, scb);
883 ahd_done(ahd, scb);
886 ahd->qoutfifonext = (ahd->qoutfifonext+1) & (AHD_QOUT_SIZE-1);
887 if (ahd->qoutfifonext == 0)
888 ahd->qoutfifonext_valid_tag ^= QOUTFIFO_ENTRY_VALID;
890 ahd->flags &= ~AHD_RUNNING_QOUTFIFO;
895 ahd_handle_hwerrint(struct ahd_softc *ahd)
904 error = ahd_inb(ahd, ERROR);
908 ahd_name(ahd), ahd_hard_errors[i].errmesg);
909 AHD_UNCORRECTABLE_ERROR(ahd);
913 ahd_dump_card_state(ahd);
917 ahd_abort_scbs(ahd, CAM_TARGET_WILDCARD, ALL_CHANNELS,
922 ahd_free(ahd);
926 ahd_handle_seqint(struct ahd_softc *ahd, u_int intstat)
935 seqintcode = ahd_inb(ahd, SEQINTCODE);
936 ahd_outb(ahd, CLRINT, CLRSEQINT);
937 if ((ahd->bugs & AHD_INTCOLLISION_BUG) != 0) {
944 ahd_unpause(ahd);
945 while (!ahd_is_paused(ahd))
947 ahd_outb(ahd, CLRINT, CLRSEQINT);
949 ahd_update_modes(ahd);
953 ahd_name(ahd), seqintcode);
961 AHD_ASSERT_MODES(ahd, ~(AHD_MODE_UNKNOWN_MSK|AHD_MODE_CFG_MSK),
963 scbid = ahd_get_scbptr(ahd);
964 scb = ahd_lookup_scb(ahd, scbid);
973 ahd_outb(ahd, SAVED_SCSIID, scb->hscb->scsiid);
974 ahd_outb(ahd, SAVED_LUN, scb->hscb->lun);
975 ahd_outb(ahd, SEQ_FLAGS, 0x0);
977 if ((ahd_inb(ahd, LQISTAT2) & LQIPHASE_OUTPKT) != 0
978 && (ahd_inb(ahd, SCSISIGO) & ATNO) != 0) {
987 "P0 assertion\n", ahd_name(ahd));
992 printf("%s: Entering NONPACK\n", ahd_name(ahd));
998 ahd_name(ahd));
999 ahd_dump_card_state(ahd);
1000 ahd_reset_channel(ahd, 'A', /*Initiate Reset*/TRUE);
1001 AHD_UNCORRECTABLE_ERROR(ahd);
1008 scbid = ahd_get_scbptr(ahd);
1009 scb = ahd_lookup_scb(ahd, scbid);
1011 ahd_print_path(ahd, scb);
1013 printf("%s: ", ahd_name(ahd));
1015 ahd_dump_card_state(ahd);
1016 ahd_reset_channel(ahd, 'A', /*Initiate Reset*/TRUE);
1017 AHD_UNCORRECTABLE_ERROR(ahd);
1025 scbid = ahd_get_scbptr(ahd);
1026 scb = ahd_lookup_scb(ahd, scbid);
1028 ahd_dump_card_state(ahd);
1030 AHD_FATAL_ERROR(ahd);
1033 ahd_outq(ahd, HADDR, scb->sense_busaddr);
1034 ahd_outw(ahd, HCNT, AHD_SENSE_BUFSIZE);
1035 ahd_outb(ahd, HCNT + 2, 0);
1036 ahd_outb(ahd, SG_CACHE_PRE, SG_LAST_SEG);
1037 ahd_outb(ahd, DFCNTRL, PRELOADEN|SCSIEN|HDMAEN);
1044 bus_phase = ahd_inb(ahd, SCSISIGI) & PHASE_MASK;
1046 ahd_name(ahd), bus_phase);
1056 ahd_reset_channel(ahd, 'A', /*Initiate Reset*/TRUE);
1057 printf("%s: Issued Bus Reset.\n", ahd_name(ahd));
1058 AHD_UNCORRECTABLE_ERROR(ahd);
1078 scbid = ahd_get_scbptr(ahd);
1079 scb = ahd_lookup_scb(ahd, scbid);
1081 AHD_CORRECTABLE_ERROR(ahd);
1084 ahd_reset_channel(ahd, 'A',
1089 SCB_GET_TARGET(ahd, scb),
1091 SCB_GET_CHANNEL(ahd, scb),
1093 ahd_fetch_transinfo(ahd,
1098 ahd_set_width(ahd, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
1100 ahd_set_syncrate(ahd, &devinfo, /*period*/0,
1103 ahd_outb(ahd, SCB_CDB_STORE, 0);
1104 ahd_outb(ahd, SCB_CDB_STORE+1, 0);
1105 ahd_outb(ahd, SCB_CDB_STORE+2, 0);
1106 ahd_outb(ahd, SCB_CDB_STORE+3, 0);
1107 ahd_outb(ahd, SCB_CDB_STORE+4, 0);
1108 ahd_outb(ahd, SCB_CDB_STORE+5, 0);
1109 ahd_outb(ahd, SCB_CDB_LEN, 6);
1112 ahd_outb(ahd, SCB_CONTROL, scb->hscb->control);
1113 ahd_outb(ahd, MSG_OUT, HOST_MSG);
1114 ahd_outb(ahd, SAVED_SCSIID, scb->hscb->scsiid);
1119 ahd_outb(ahd, SAVED_LUN, 0);
1120 ahd_outb(ahd, SEQ_FLAGS, 0);
1121 ahd_assert_atn(ahd);
1124 ahd_freeze_devq(ahd, scb);
1132 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
1133 ahd_outb(ahd, CLRLQOINT1, CLRLQOPHACHGINPKT);
1134 if ((ahd->bugs & AHD_CLRLQO_AUTOCLR_BUG) != 0) {
1135 ahd_outb(ahd, CLRLQOINT1, 0);
1139 ahd_print_path(ahd, scb);
1140 AHD_CORRECTABLE_ERROR(ahd);
1157 printf("%s: CFG4OVERRUN mode = %x\n", ahd_name(ahd),
1158 ahd_inb(ahd, MODE_PTR));
1161 scb_index = ahd_get_scbptr(ahd);
1162 scb = ahd_lookup_scb(ahd, scb_index);
1168 ahd_assert_atn(ahd);
1169 ahd_outb(ahd, MSG_OUT, HOST_MSG);
1170 ahd->msgout_buf[0] = MSG_ABORT_TASK;
1171 ahd->msgout_len = 1;
1172 ahd->msgout_index = 0;
1173 ahd->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
1178 ahd_outb(ahd, SCB_CONTROL,
1179 ahd_inb_scbram(ahd, SCB_CONTROL)
1186 ahd_dump_card_state(ahd);
1195 ahd_name(ahd), ahd_inb(ahd, DFCNTRL),
1196 ahd_inb(ahd, SG_CACHE_SHADOW));
1199 ahd_reinitialize_dataptrs(ahd);
1217 ahd_fetch_devinfo(ahd, &devinfo);
1218 if (ahd->msg_type == MSG_TYPE_NONE) {
1223 bus_phase = ahd_inb(ahd, SCSISIGI) & PHASE_MASK;
1228 AHD_CORRECTABLE_ERROR(ahd);
1233 ahd_dump_card_state(ahd);
1234 ahd_clear_intstat(ahd);
1235 ahd_restart(ahd);
1239 scb_index = ahd_get_scbptr(ahd);
1240 scb = ahd_lookup_scb(ahd, scb_index);
1243 ahd_setup_initiator_msgout(ahd,
1247 ahd->msg_type =
1249 ahd->msgin_index = 0;
1255 ahd->msg_type =
1257 ahd->msgin_index = 0;
1260 ahd_setup_target_msgin(ahd,
1267 ahd_handle_message_phase(ahd);
1273 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
1274 ahd_outb(ahd, SCSISEQ0, ahd_inb(ahd, SCSISEQ0) & ~ENSELO);
1278 ahd_name(ahd), 'A', ahd_inb(ahd, SELID) >> 4);
1281 ahd_inb(ahd, SAVED_SCSIID), ahd_inb(ahd, SAVED_LUN),
1282 ahd_inw(ahd, REG0), ahd_inb(ahd, ACCUM));
1285 ahd_inb(ahd, SEQ_FLAGS), ahd_get_scbptr(ahd),
1286 ahd_find_busy_tcl(ahd,
1287 BUILD_TCL(ahd_inb(ahd, SAVED_SCSIID),
1288 ahd_inb(ahd, SAVED_LUN))),
1289 ahd_inw(ahd, SINDEX));
1292 ahd_inb(ahd, SELID), ahd_inb_scbram(ahd, SCB_SCSIID),
1293 ahd_inb_scbram(ahd, SCB_LUN),
1294 ahd_inb_scbram(ahd, SCB_CONTROL));
1296 ahd_inb(ahd, SCSIBUS), ahd_inb(ahd, SCSISIGI));
1297 printf("SXFRCTL0 == 0x%x\n", ahd_inb(ahd, SXFRCTL0));
1298 printf("SEQCTL0 == 0x%x\n", ahd_inb(ahd, SEQCTL0));
1299 ahd_dump_card_state(ahd);
1300 ahd->msgout_buf[0] = MSG_BUS_DEV_RESET;
1301 ahd->msgout_len = 1;
1302 ahd->msgout_index = 0;
1303 ahd->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
1304 ahd_outb(ahd, MSG_OUT, HOST_MSG);
1305 ahd_assert_atn(ahd);
1310 ahd_handle_proto_violation(ahd);
1317 ahd_fetch_devinfo(ahd, &devinfo);
1318 ahd_handle_ign_wide_residue(ahd, &devinfo);
1325 lastphase = ahd_inb(ahd, LASTPHASE);
1328 ahd_name(ahd), 'A',
1329 SCSIID_TARGET(ahd, ahd_inb(ahd, SAVED_SCSIID)),
1330 lastphase, ahd_inb(ahd, SCSISIGI));
1331 AHD_CORRECTABLE_ERROR(ahd);
1338 lastphase = ahd_inb(ahd, LASTPHASE);
1341 ahd_name(ahd), 'A',
1342 SCSIID_TARGET(ahd, ahd_inb(ahd, SAVED_SCSIID)),
1343 lastphase, ahd_inb(ahd, SCSISIGI));
1344 AHD_CORRECTABLE_ERROR(ahd);
1345 ahd_restart(ahd);
1364 scbindex = ahd_get_scbptr(ahd);
1365 scb = ahd_lookup_scb(ahd, scbindex);
1367 lastphase = ahd_inb(ahd, LASTPHASE);
1369 ahd_print_path(ahd, scb);
1373 ahd_print_path(ahd, scb);
1376 ahd_inb(ahd, SEQ_FLAGS) & DPHASE
1387 ahd_freeze_devq(ahd, scb);
1398 ahd_fetch_devinfo(ahd, &devinfo);
1400 ahd_name(ahd), devinfo.channel, devinfo.target,
1402 scbid = ahd_get_scbptr(ahd);
1403 scb = ahd_lookup_scb(ahd, scbid);
1404 AHD_CORRECTABLE_ERROR(ahd);
1411 ahd_search_qinfifo(ahd, SCB_GET_TARGET(ahd, scb),
1412 SCB_GET_CHANNEL(ahd, scb),
1416 ahd_outb(ahd, SCB_CONTROL,
1417 ahd_inb_scbram(ahd, SCB_CONTROL) & ~MK_MESSAGE);
1425 scbid = ahd_get_scbptr(ahd);
1426 scb = ahd_lookup_scb(ahd, scbid);
1432 ahd_print_path(ahd, scb);
1445 ahd_abort_scbs(ahd, SCB_GET_TARGET(ahd, scb),
1455 ahd_scb_devinfo(ahd, &devinfo, scb);
1457 ahd_handle_devreset(ahd, &devinfo, lun,
1481 scbid = ahd_get_scbptr(ahd);
1482 scb = ahd_lookup_scb(ahd, scbid);
1488 ahd_print_path(ahd, scb);
1497 while ((ahd_inb(ahd, SCSISEQ0) & ENSELO) != 0
1498 && (ahd_inb(ahd, SSTAT0) & SELDO) == 0
1499 && (ahd_inb(ahd, SSTAT1) & SELTO) == 0)
1501 ahd_outb(ahd, SCB_TASK_MANAGEMENT, 0);
1502 ahd_search_qinfifo(ahd, SCB_GET_TARGET(ahd, scb),
1503 SCB_GET_CHANNEL(ahd, scb),
1514 printf("%s: Tracepoint %d\n", ahd_name(ahd),
1520 ahd_handle_hwerrint(ahd);
1523 printf("%s: Unexpected SEQINTCODE %d\n", ahd_name(ahd),
1532 ahd_unpause(ahd);
1536 ahd_handle_scsiint(struct ahd_softc *ahd, u_int intstat)
1547 ahd_update_modes(ahd);
1548 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
1550 status3 = ahd_inb(ahd, SSTAT3) & (NTRAMPERR|OSRAMPERR);
1551 status0 = ahd_inb(ahd, SSTAT0) & (IOERR|OVERRUN|SELDI|SELDO);
1552 status = ahd_inb(ahd, SSTAT1) & (SELTO|SCSIRSTI|BUSFREE|SCSIPERR);
1553 lqistat1 = ahd_inb(ahd, LQISTAT1);
1554 lqostat0 = ahd_inb(ahd, LQOSTAT0);
1555 busfreetime = ahd_inb(ahd, SSTAT2) & BUSFREETIME;
1559 ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
1560 simode0 = ahd_inb(ahd, SIMODE0);
1562 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
1564 scbid = ahd_get_scbptr(ahd);
1565 scb = ahd_lookup_scb(ahd, scbid);
1567 && (ahd_inb(ahd, SEQ_FLAGS) & NOT_IDENTIFIED) != 0)
1573 now_lvd = ahd_inb(ahd, SBLKCTL) & ENAB40;
1575 ahd_name(ahd), now_lvd ? "LVD" : "SE");
1576 ahd_outb(ahd, CLRSINT0, CLRIOERR);
1580 ahd_reset_channel(ahd, 'A', /*Initiate Reset*/TRUE);
1581 ahd_pause(ahd);
1582 ahd_setup_iocell_workaround(ahd);
1583 ahd_unpause(ahd);
1587 ahd_name(ahd));
1588 AHD_CORRECTABLE_ERROR(ahd);
1589 ahd_reset_channel(ahd, 'A', /*Initiate Reset*/TRUE);
1592 printf("%s: Someone reset channel A\n", ahd_name(ahd));
1593 ahd_reset_channel(ahd, 'A', /*Initiate Reset*/FALSE);
1594 AHD_UNCORRECTABLE_ERROR(ahd);
1598 ahd_clear_critical_section(ahd);
1600 ahd_handle_transmission_error(ahd);
1603 printf("%s: lqostat0 == 0x%x!\n", ahd_name(ahd), lqostat0);
1604 ahd_outb(ahd, CLRLQOINT0, lqostat0);
1605 if ((ahd->bugs & AHD_CLRLQO_AUTOCLR_BUG) != 0)
1606 ahd_outb(ahd, CLRLQOINT1, 0);
1611 ahd_outb(ahd, SCSISEQ0, 0);
1614 ahd_clear_critical_section(ahd);
1617 ahd_clear_msg_state(ahd);
1620 ahd_outb(ahd, CLRSINT1, CLRSELTIMEO|CLRBUSFREE|CLRSCSIPERR);
1630 ahd_outb(ahd, CLRSINT0, CLRSELINGO);
1632 scbid = ahd_inw(ahd, WAITING_TID_HEAD);
1633 scb = ahd_lookup_scb(ahd, scbid);
1637 ahd_name(ahd), scbid);
1638 ahd_dump_card_state(ahd);
1639 AHD_UNCORRECTABLE_ERROR(ahd);
1644 ahd_print_path(ahd, scb);
1649 ahd_scb_devinfo(ahd, &devinfo, scb);
1651 ahd_freeze_devq(ahd, scb);
1659 ahd_handle_devreset(ahd, &devinfo,
1665 ahd_outb(ahd, CLRINT, CLRSCSIINT);
1666 ahd_iocell_first_selection(ahd);
1667 ahd_unpause(ahd);
1670 ahd_iocell_first_selection(ahd);
1671 ahd_unpause(ahd);
1674 ahd_name(ahd), status3);
1675 AHD_CORRECTABLE_ERROR(ahd);
1676 ahd_outb(ahd, CLRSINT3, status3);
1680 ahd_clear_critical_section(ahd);
1682 ahd_handle_lqiphase_error(ahd, lqistat1);
1690 ahd_outb(ahd, CLRLQIINT1, CLRLQICRCI_NLQ);
1705 ahd_outb(ahd, SCSISEQ0, 0);
1708 ahd_clear_critical_section(ahd);
1715 busfreetime = ahd_inb(ahd, SSTAT2) & BUSFREETIME;
1716 lqostat1 = ahd_inb(ahd, LQOSTAT1);
1726 ahd_set_modes(ahd, mode, mode);
1727 scbid = ahd_get_scbptr(ahd);
1728 scb = ahd_lookup_scb(ahd, scbid);
1732 ahd_name(ahd), scbid, mode);
1734 AHD_CORRECTABLE_ERROR(ahd);
1748 && ahd_inb(ahd, LASTPHASE) == P_BUSFREE
1749 && (ahd_inb(ahd, SSTAT0) & SELDI) == 0
1750 && ((ahd_inb(ahd, SSTAT0) & SELDO) == 0
1751 || (ahd_inb(ahd, SCSISEQ0) & ENSELO) == 0))
1771 if (packetized && ahd_inb(ahd, LASTPHASE) == P_BUSFREE) {
1772 restart = ahd_handle_pkt_busfree(ahd, busfreetime);
1775 restart = ahd_handle_nonpkt_busfree(ahd);
1788 ahd_outb(ahd, CLRSINT1, CLRBUSFREE);
1790 && (ahd->bugs & AHD_BUSFREEREV_BUG) != 0)
1791 ahd_outb(ahd, SIMODE1,
1792 ahd_inb(ahd, SIMODE1) & ~ENBUSFREE);
1795 ahd_clear_fifo(ahd, mode);
1797 ahd_clear_msg_state(ahd);
1798 ahd_outb(ahd, CLRINT, CLRSCSIINT);
1800 ahd_restart(ahd);
1802 ahd_unpause(ahd);
1806 ahd_name(ahd), status);
1807 ahd_dump_card_state(ahd);
1808 ahd_clear_intstat(ahd);
1809 ahd_unpause(ahd);
1814 ahd_handle_transmission_error(struct ahd_softc *ahd)
1827 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
1828 lqistat1 = ahd_inb(ahd, LQISTAT1) & ~(LQIPHASE_LQ|LQIPHASE_NLQ);
1829 ahd_inb(ahd, LQISTAT2);
1831 && (ahd->bugs & AHD_NLQICRC_DELAYED_BUG) != 0) {
1834 ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
1835 lqistate = ahd_inb(ahd, LQISTATE);
1841 ahd_name(ahd));
1846 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
1849 ahd_outb(ahd, CLRLQIINT1, lqistat1);
1850 lastphase = ahd_inb(ahd, LASTPHASE);
1851 curphase = ahd_inb(ahd, SCSISIGI) & PHASE_MASK;
1852 perrdiag = ahd_inb(ahd, PERRDIAG);
1854 ahd_outb(ahd, CLRSINT1, CLRSCSIPERR);
1863 ahd_set_active_fifo(ahd);
1864 scbid = ahd_get_scbptr(ahd);
1865 scb = ahd_lookup_scb(ahd, scbid);
1872 printf("%s: Transmission error detected\n", ahd_name(ahd));
1878 AHD_CORRECTABLE_ERROR(ahd);
1879 ahd_dump_card_state(ahd);
1886 ahd_name(ahd), lqistat1);
1887 AHD_UNCORRECTABLE_ERROR(ahd);
1889 ahd_reset_channel(ahd, 'A', /*Initiate Reset*/TRUE);
1913 ahd_outb(ahd, LQCTL2, LQIRETRY);
1915 AHD_CORRECTABLE_ERROR(ahd);
1966 "Resetting bus\n", ahd_name(ahd));
1967 AHD_UNCORRECTABLE_ERROR(ahd);
1968 ahd_reset_channel(ahd, 'A', /*Initiate Reset*/TRUE);
1973 ahd_reset_channel(ahd, 'A', /*Initiate Reset*/TRUE);
1981 ahd_inb(ahd, SCSIDAT);
1995 ahd->send_msg_perror = msg_out;
1998 ahd_outb(ahd, MSG_OUT, HOST_MSG);
1999 ahd_outb(ahd, CLRINT, CLRSCSIINT);
2000 ahd_unpause(ahd);
2004 ahd_handle_lqiphase_error(struct ahd_softc *ahd, u_int lqistat1)
2009 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
2010 ahd_outb(ahd, CLRLQIINT1, lqistat1);
2020 ahd_set_active_fifo(ahd);
2021 if ((ahd_inb(ahd, SCSISIGO) & ATNO) != 0
2022 && (ahd_inb(ahd, MDFFSTAT) & DLZERO) != 0) {
2025 AHD_CORRECTABLE_ERROR(ahd);
2026 ahd_outb(ahd, LQCTL2, LQIRETRY);
2029 AHD_CORRECTABLE_ERROR(ahd);
2030 ahd_outb(ahd, LQCTL2, LQIRETRY);
2033 ahd_dump_card_state(ahd);
2034 ahd_outb(ahd, CLRINT, CLRSCSIINT);
2035 ahd_unpause(ahd);
2038 AHD_CORRECTABLE_ERROR(ahd);
2039 ahd_dump_card_state(ahd);
2040 ahd_reset_channel(ahd, 'A', /*Initiate Reset*/TRUE);
2049 ahd_handle_pkt_busfree(struct ahd_softc *ahd, u_int busfreetime)
2053 AHD_ASSERT_MODES(ahd, ~(AHD_MODE_UNKNOWN_MSK|AHD_MODE_CFG_MSK),
2055 lqostat1 = ahd_inb(ahd, LQOSTAT1);
2079 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
2080 scbid = ahd_inw(ahd, CURRSCB);
2081 scb = ahd_lookup_scb(ahd, scbid);
2087 ahd_outb(ahd, CLRLQOINT1, CLRLQOBUSFREE);
2088 if ((ahd->bugs & AHD_CLRLQO_AUTOCLR_BUG) != 0)
2089 ahd_outb(ahd, CLRLQOINT1, 0);
2090 ahd_outb(ahd, SCSISEQ0, ahd_inb(ahd, SCSISEQ0) & ~ENSELO);
2091 ahd_flush_device_writes(ahd);
2092 ahd_outb(ahd, CLRSINT0, CLRSELDO);
2100 ahd_outb(ahd, LQCTL2, ahd_inb(ahd, LQCTL2) | LQOTOIDLE);
2106 waiting_h = ahd_inw(ahd, WAITING_TID_HEAD);
2107 saved_scbptr = ahd_get_scbptr(ahd);
2110 ahd_outw(ahd, WAITING_TID_HEAD, scbid);
2111 waiting_t = ahd_inw(ahd, WAITING_TID_TAIL);
2113 ahd_outw(ahd, WAITING_TID_TAIL, scbid);
2116 ahd_set_scbptr(ahd, waiting_h);
2117 next = ahd_inw_scbram(ahd, SCB_NEXT2);
2119 ahd_set_scbptr(ahd, scbid);
2120 ahd_outw(ahd, SCB_NEXT2, next);
2122 ahd_set_scbptr(ahd, saved_scbptr);
2125 ahd_print_path(ahd, scb);
2128 AHD_CORRECTABLE_ERROR(ahd);
2134 ahd_freeze_devq(ahd, scb);
2138 } else if ((ahd_inb(ahd, PERRDIAG) & PARITYERR) != 0) {
2146 ahd_outb(ahd, CLRSINT1, CLRSCSIPERR|CLRBUSFREE);
2151 ahd_name(ahd));
2156 if (ahd->src_mode != AHD_MODE_SCSI) {
2160 scbid = ahd_get_scbptr(ahd);
2161 scb = ahd_lookup_scb(ahd, scbid);
2162 ahd_print_path(ahd, scb);
2164 AHD_UNCORRECTABLE_ERROR(ahd);
2165 ahd_dump_card_state(ahd);
2166 ahd_abort_scbs(ahd, SCB_GET_TARGET(ahd, scb), 'A',
2173 printf("%s: Unexpected PKT busfree condition\n", ahd_name(ahd));
2174 AHD_UNCORRECTABLE_ERROR(ahd);
2175 ahd_dump_card_state(ahd);
2184 ahd_handle_nonpkt_busfree(struct ahd_softc *ahd)
2202 lastphase = ahd_inb(ahd, LASTPHASE);
2203 saved_scsiid = ahd_inb(ahd, SAVED_SCSIID);
2204 saved_lun = ahd_inb(ahd, SAVED_LUN);
2205 target = SCSIID_TARGET(ahd, saved_scsiid);
2211 scbid = ahd_get_scbptr(ahd);
2212 scb = ahd_lookup_scb(ahd, scbid);
2214 && (ahd_inb(ahd, SEQ_FLAGS) & NOT_IDENTIFIED) != 0)
2217 ppr_busfree = (ahd->msg_flags & MSG_FLAG_EXPECT_PPR_BUSFREE) != 0;
2222 if (ahd_sent_msg(ahd, AHDMSG_1B, MSG_ABORT_TAG, TRUE)
2223 || ahd_sent_msg(ahd, AHDMSG_1B, MSG_ABORT, TRUE)) {
2228 ahd_print_devinfo(ahd, &devinfo);
2234 sent_msg = ahd->msgout_buf[ahd->msgout_index - 1];
2235 ahd_print_path(ahd, scb);
2259 found = ahd_abort_scbs(ahd, target, 'A', saved_lun,
2264 } else if (ahd_sent_msg(ahd, AHDMSG_1B,
2274 && ahd_match_scb(ahd, scb, target, 'A',
2279 ahd_handle_devreset(ahd, &devinfo, CAM_LUN_WILDCARD,
2283 } else if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_PPR, FALSE)
2302 tinfo = ahd_fetch_transinfo(ahd, devinfo.channel,
2306 ahd_set_width(ahd, &devinfo,
2310 ahd_set_syncrate(ahd, &devinfo,
2329 ahd_freeze_devq(ahd, scb);
2330 ahd_qinfifo_requeue_tail(ahd, scb);
2333 } else if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_WDTR, FALSE)
2343 ahd_set_width(ahd, &devinfo,
2352 ahd_freeze_devq(ahd, scb);
2353 ahd_qinfifo_requeue_tail(ahd, scb);
2355 } else if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_SDTR, FALSE)
2365 ahd_set_syncrate(ahd, &devinfo,
2375 ahd_freeze_devq(ahd, scb);
2376 ahd_qinfifo_requeue_tail(ahd, scb);
2378 } else if ((ahd->msg_flags & MSG_FLAG_EXPECT_IDE_BUSFREE) != 0
2379 && ahd_sent_msg(ahd, AHDMSG_1B,
2387 } else if ((ahd->msg_flags & MSG_FLAG_EXPECT_QASREJ_BUSFREE)
2388 && ahd_sent_msg(ahd, AHDMSG_1B,
2406 && ((ahd->msg_flags & MSG_FLAG_EXPECT_PPR_BUSFREE) != 0)) {
2408 ahd_freeze_devq(ahd, scb);
2411 if ((ahd->msg_flags & MSG_FLAG_IU_REQ_CHANGED) != 0) {
2412 ahd_abort_scbs(ahd, SCB_GET_TARGET(ahd, scb),
2413 SCB_GET_CHANNEL(ahd, scb),
2421 ahd_done(ahd, scb);
2436 ahd_print_path(ahd, scb);
2437 aborted = ahd_abort_scbs(ahd, target, 'A',
2446 printf("%s: ", ahd_name(ahd));
2452 ahd_inw(ahd, PRGMCNT));
2453 AHD_UNCORRECTABLE_ERROR(ahd);
2454 ahd_dump_card_state(ahd);
2456 ahd_force_renegotiation(ahd, &devinfo);
2463 ahd_handle_proto_violation(struct ahd_softc *ahd)
2473 ahd_fetch_devinfo(ahd, &devinfo);
2474 scbid = ahd_get_scbptr(ahd);
2475 scb = ahd_lookup_scb(ahd, scbid);
2476 seq_flags = ahd_inb(ahd, SEQ_FLAGS);
2477 curphase = ahd_inb(ahd, SCSISIGI) & PHASE_MASK;
2478 lastphase = ahd_inb(ahd, LASTPHASE);
2486 ahd_print_devinfo(ahd, &devinfo);
2489 AHD_UNCORRECTABLE_ERROR(ahd);
2496 ahd_print_devinfo(ahd, &devinfo);
2498 AHD_UNCORRECTABLE_ERROR(ahd);
2503 ahd_print_path(ahd, scb);
2505 AHD_UNCORRECTABLE_ERROR(ahd);
2506 } else if ((ahd_inb_scbram(ahd, SCB_CONTROL)
2515 ahd_print_path(ahd, scb);
2518 ahd_print_path(ahd, scb);
2520 AHD_UNCORRECTABLE_ERROR(ahd);
2521 ahd_dump_card_state(ahd);
2533 found = ahd_reset_channel(ahd, 'A', TRUE);
2535 "%d SCBs aborted\n", ahd_name(ahd), 'A', found);
2536 AHD_UNCORRECTABLE_ERROR(ahd);
2543 ahd_outb(ahd, SCSISEQ0,
2544 ahd_inb(ahd, SCSISEQ0) & ~ENSELO);
2545 ahd_assert_atn(ahd);
2546 ahd_outb(ahd, MSG_OUT, HOST_MSG);
2548 ahd_print_devinfo(ahd, &devinfo);
2549 ahd->msgout_buf[0] = MSG_ABORT_TASK;
2550 ahd->msgout_len = 1;
2551 ahd->msgout_index = 0;
2552 ahd->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
2554 ahd_print_path(ahd, scb);
2559 AHD_UNCORRECTABLE_ERROR(ahd);
2568 ahd_force_renegotiation(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
2575 ahd_print_devinfo(ahd, devinfo);
2579 targ_info = ahd_fetch_transinfo(ahd,
2584 ahd_update_neg_request(ahd, devinfo, tstate,
2590 ahd_clear_critical_section(struct ahd_softc *ahd)
2604 if (ahd->num_critical_sections == 0)
2617 saved_modes = ahd_save_modes(ahd);
2623 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
2624 seqaddr = ahd_inw(ahd, CURADDR);
2626 cs = ahd->critical_sections;
2627 for (i = 0; i < ahd->num_critical_sections; i++, cs++) {
2633 if (i == ahd->num_critical_sections)
2639 ahd_name(ahd), ahd_name(ahd), first_instr,
2641 AHD_FATAL_ERROR(ahd);
2642 ahd_dump_card_state(ahd);
2649 printf("%s: Single stepping at 0x%x\n", ahd_name(ahd),
2655 ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
2656 simode0 = ahd_inb(ahd, SIMODE0);
2657 simode3 = ahd_inb(ahd, SIMODE3);
2658 lqimode0 = ahd_inb(ahd, LQIMODE0);
2659 lqimode1 = ahd_inb(ahd, LQIMODE1);
2660 lqomode0 = ahd_inb(ahd, LQOMODE0);
2661 lqomode1 = ahd_inb(ahd, LQOMODE1);
2662 ahd_outb(ahd, SIMODE0, 0);
2663 ahd_outb(ahd, SIMODE3, 0);
2664 ahd_outb(ahd, LQIMODE0, 0);
2665 ahd_outb(ahd, LQIMODE1, 0);
2666 ahd_outb(ahd, LQOMODE0, 0);
2667 ahd_outb(ahd, LQOMODE1, 0);
2668 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
2669 simode1 = ahd_inb(ahd, SIMODE1);
2676 ahd_outb(ahd, SIMODE1, simode1 & ENBUSFREE);
2677 ahd_outb(ahd, SEQCTL0, ahd_inb(ahd, SEQCTL0) | STEP);
2680 ahd_outb(ahd, CLRSINT1, CLRBUSFREE);
2681 ahd_outb(ahd, CLRINT, CLRSCSIINT);
2682 ahd_set_modes(ahd, ahd->saved_src_mode, ahd->saved_dst_mode);
2683 ahd_outb(ahd, HCNTRL, ahd->unpause);
2684 while (!ahd_is_paused(ahd))
2686 ahd_update_modes(ahd);
2689 ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
2690 ahd_outb(ahd, SIMODE0, simode0);
2691 ahd_outb(ahd, SIMODE3, simode3);
2692 ahd_outb(ahd, LQIMODE0, lqimode0);
2693 ahd_outb(ahd, LQIMODE1, lqimode1);
2694 ahd_outb(ahd, LQOMODE0, lqomode0);
2695 ahd_outb(ahd, LQOMODE1, lqomode1);
2696 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
2697 ahd_outb(ahd, SEQCTL0, ahd_inb(ahd, SEQCTL0) & ~STEP);
2698 ahd_outb(ahd, SIMODE1, simode1);
2705 ahd_outb(ahd, CLRINT, CLRSCSIINT);
2707 ahd_restore_modes(ahd, saved_modes);
2714 ahd_clear_intstat(struct ahd_softc *ahd)
2716 AHD_ASSERT_MODES(ahd, ~(AHD_MODE_UNKNOWN_MSK|AHD_MODE_CFG_MSK),
2719 ahd_outb(ahd, CLRLQIINT0, CLRLQIATNQAS|CLRLQICRCT1|CLRLQICRCT2
2721 ahd_outb(ahd, CLRLQIINT1, CLRLQIPHASE_LQ|CLRLQIPHASE_NLQ|CLRLIQABORT
2724 ahd_outb(ahd, CLRLQOINT0, CLRLQOTARGSCBPERR|CLRLQOSTOPT2|CLRLQOATNLQ
2726 ahd_outb(ahd, CLRLQOINT1, CLRLQOINITSCBPERR|CLRLQOSTOPI2|CLRLQOBADQAS
2728 if ((ahd->bugs & AHD_CLRLQO_AUTOCLR_BUG) != 0) {
2729 ahd_outb(ahd, CLRLQOINT0, 0);
2730 ahd_outb(ahd, CLRLQOINT1, 0);
2732 ahd_outb(ahd, CLRSINT3, CLRNTRAMPERR|CLROSRAMPERR);
2733 ahd_outb(ahd, CLRSINT1, CLRSELTIMEO|CLRATNO|CLRSCSIRSTI
2735 ahd_outb(ahd, CLRSINT0, CLRSELDO|CLRSELDI|CLRSELINGO
2737 ahd_outb(ahd, CLRINT, CLRSCSIINT);
2816 ahd_alloc_tstate(struct ahd_softc *ahd, u_int scsi_id, char channel)
2822 master_tstate = ahd->enabled_targets[ahd->our_id];
2823 if (ahd->enabled_targets[scsi_id] != NULL
2824 && ahd->enabled_targets[scsi_id] != master_tstate)
2826 ahd_name(ahd));
2848 ahd->enabled_targets[scsi_id] = tstate;
2858 ahd_free_tstate(struct ahd_softc *ahd, u_int scsi_id, char channel, int force)
2866 if (scsi_id == ahd->our_id
2870 tstate = ahd->enabled_targets[scsi_id];
2873 ahd->enabled_targets[scsi_id] = NULL;
2884 ahd_devlimited_syncrate(struct ahd_softc *ahd,
2891 if ((ahd_inb(ahd, SBLKCTL) & ENAB40) != 0
2892 && (ahd_inb(ahd, SSTAT2) & EXP_ACTIVE) == 0) {
2923 ahd_find_syncrate(ahd, period, ppr_options, maxsync);
2933 ahd_find_syncrate(struct ahd_softc *ahd, u_int *period,
2972 ahd_validate_offset(struct ahd_softc *ahd,
2983 if ((ahd->bugs & AHD_PACED_NEGTABLE_BUG) != 0)
3003 ahd_validate_width(struct ahd_softc *ahd, struct ahd_initiator_tinfo *tinfo,
3008 if (ahd->features & AHD_WIDE) {
3033 ahd_update_neg_request(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
3047 if ((ahd->features & AHD_WIDE) != 0)
3076 ahd_set_syncrate(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
3096 tinfo = ahd_fetch_transinfo(ahd, devinfo->channel, devinfo->our_scsiid,
3126 ahd_send_async(ahd, devinfo->channel, devinfo->target,
3134 ahd_name(ahd), devinfo->target,
3164 ahd_name(ahd), devinfo->target,
3180 ahd_pause(ahd);
3181 ahd_update_neg_table(ahd, devinfo, &tinfo->curr);
3183 ahd_unpause(ahd);
3184 if (ahd->msg_type != MSG_TYPE_NONE) {
3189 ahd_print_devinfo(ahd, devinfo);
3193 ahd->msg_flags |= MSG_FLAG_EXPECT_PPR_BUSFREE
3201 ahd->msg_flags |= MSG_FLAG_EXPECT_PPR_BUSFREE;
3206 update_needed += ahd_update_neg_request(ahd, devinfo, tstate,
3210 ahd_update_pending_scbs(ahd);
3222 ahd_set_width(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
3233 tinfo = ahd_fetch_transinfo(ahd, devinfo->channel, devinfo->our_scsiid,
3248 ahd_send_async(ahd, devinfo->channel, devinfo->target,
3252 ahd_name(ahd), devinfo->target,
3259 ahd_pause(ahd);
3260 ahd_update_neg_table(ahd, devinfo, &tinfo->curr);
3262 ahd_unpause(ahd);
3265 update_needed += ahd_update_neg_request(ahd, devinfo, tstate,
3268 ahd_update_pending_scbs(ahd);
3276 ahd_set_tags(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
3279 ahd_platform_set_tags(ahd, devinfo, alg);
3280 ahd_send_async(ahd, devinfo->channel, devinfo->target,
3285 ahd_update_neg_table(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
3294 uint8_t iocell_opts[sizeof(ahd->iocell_opts)];
3296 saved_modes = ahd_save_modes(ahd);
3297 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
3299 saved_negoaddr = ahd_inb(ahd, NEGOADDR);
3300 ahd_outb(ahd, NEGOADDR, devinfo->target);
3303 memcpy(iocell_opts, ahd->iocell_opts, sizeof(ahd->iocell_opts));
3311 if ((ahd->bugs & AHD_PACED_NEGTABLE_BUG) != 0) {
3343 if ((ahd->features & AHD_NEW_IOCELL_OPTS) != 0
3355 if ((ahd->bugs & AHD_PACED_NEGTABLE_BUG) != 0) {
3365 ahd_outb(ahd, ANNEXCOL, AHD_ANNEXCOL_PRECOMP_SLEW);
3366 ahd_outb(ahd, ANNEXDAT, iocell_opts[AHD_PRECOMP_SLEW_INDEX]);
3367 ahd_outb(ahd, ANNEXCOL, AHD_ANNEXCOL_AMPLITUDE);
3368 ahd_outb(ahd, ANNEXDAT, iocell_opts[AHD_AMPLITUDE_INDEX]);
3370 ahd_outb(ahd, NEGPERIOD, period);
3371 ahd_outb(ahd, NEGPPROPTS, ppr_opts);
3372 ahd_outb(ahd, NEGOFFSET, offset);
3384 ahd_outb(ahd, NEGCONOPTS, con_opts);
3385 ahd_outb(ahd, NEGOADDR, saved_negoaddr);
3386 ahd_restore_modes(ahd, saved_modes);
3396 ahd_update_pending_scbs(struct ahd_softc *ahd)
3415 LIST_FOREACH(pending_scb, &ahd->pending_scbs, pending_links) {
3419 ahd_scb_devinfo(ahd, &devinfo, pending_scb);
3420 ahd_fetch_transinfo(ahd, devinfo.channel,
3428 ahd_sync_scb(ahd, pending_scb,
3436 if (ahd_is_paused(ahd)) {
3440 ahd_pause(ahd);
3451 saved_modes = ahd_save_modes(ahd);
3452 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
3453 if ((ahd_inb(ahd, SCSISIGI) & BSYI) != 0
3454 && (ahd_inb(ahd, SSTAT0) & (SELDO|SELINGO)) == 0)
3455 ahd_outb(ahd, SCSISEQ0, ahd_inb(ahd, SCSISEQ0) & ~ENSELO);
3456 saved_scbptr = ahd_get_scbptr(ahd);
3458 LIST_FOREACH(pending_scb, &ahd->pending_scbs, pending_links) {
3463 ahd_set_scbptr(ahd, scb_tag);
3464 control = ahd_inb_scbram(ahd, SCB_CONTROL);
3467 ahd_outb(ahd, SCB_CONTROL, control);
3469 ahd_set_scbptr(ahd, saved_scbptr);
3470 ahd_restore_modes(ahd, saved_modes);
3473 ahd_unpause(ahd);
3478 ahd_fetch_devinfo(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
3485 saved_modes = ahd_save_modes(ahd);
3486 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
3488 if (ahd_inb(ahd, SSTAT0) & TARGET)
3494 && (ahd_inb(ahd, SEQ_FLAGS) & CMDPHASE_PENDING) != 0) {
3496 our_id = ahd_inb(ahd, TARGIDIN) & OID;
3498 our_id = ahd_inb(ahd, TOWNID);
3500 our_id = ahd_inb(ahd, IOWNID);
3502 saved_scsiid = ahd_inb(ahd, SAVED_SCSIID);
3505 SCSIID_TARGET(ahd, saved_scsiid),
3506 ahd_inb(ahd, SAVED_LUN),
3507 SCSIID_CHANNEL(ahd, saved_scsiid),
3509 ahd_restore_modes(ahd, saved_modes);
3513 ahd_print_devinfo(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
3515 printf("%s:%c:%d:%d: ", ahd_name(ahd), 'A',
3553 ahd_scb_devinfo(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
3563 ahd_compile_devinfo(devinfo, our_id, SCB_GET_TARGET(ahd, scb),
3564 SCB_GET_LUN(scb), SCB_GET_CHANNEL(ahd, scb), role);
3576 ahd_setup_initiator_msgout(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
3584 ahd->msgout_index = 0;
3585 ahd->msgout_len = 0;
3587 if (ahd_currently_packetized(ahd))
3588 ahd->msg_flags |= MSG_FLAG_PACKETIZED;
3590 if (ahd->send_msg_perror
3591 && ahd_inb(ahd, MSG_OUT) == HOST_MSG) {
3592 ahd->msgout_buf[ahd->msgout_index++] = ahd->send_msg_perror;
3593 ahd->msgout_len++;
3594 ahd->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
3602 "I_T msgin. Issuing NO-OP\n", ahd_name(ahd));
3603 AHD_CORRECTABLE_ERROR(ahd);
3604 ahd->msgout_buf[ahd->msgout_index++] = MSG_NOOP;
3605 ahd->msgout_len++;
3606 ahd->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
3612 && ahd_inb(ahd, MSG_OUT) == MSG_IDENTIFYFLAG) {
3618 ahd->msgout_buf[ahd->msgout_index++] = identify_msg;
3619 ahd->msgout_len++;
3622 ahd->msgout_buf[ahd->msgout_index++] =
3624 ahd->msgout_buf[ahd->msgout_index++] = SCB_GET_TAG(scb);
3625 ahd->msgout_len += 2;
3630 ahd->msgout_buf[ahd->msgout_index++] = MSG_BUS_DEV_RESET;
3631 ahd->msgout_len++;
3632 ahd_print_path(ahd, scb);
3634 AHD_CORRECTABLE_ERROR(ahd);
3642 ahd_outb(ahd, SCSISEQ0, 0);
3646 ahd->msgout_buf[ahd->msgout_index++] = MSG_ABORT_TAG;
3648 ahd->msgout_buf[ahd->msgout_index++] = MSG_ABORT;
3650 ahd->msgout_len++;
3651 ahd_print_path(ahd, scb);
3654 AHD_CORRECTABLE_ERROR(ahd);
3662 ahd_outb(ahd, SCSISEQ0, 0);
3664 ahd_build_transfer_msg(ahd, devinfo);
3672 ahd_outb(ahd, SCSISEQ0, 0);
3678 AHD_FATAL_ERROR(ahd);
3681 ahd_inb_scbram(ahd, SCB_CONTROL), ahd_inb(ahd, MSG_OUT),
3689 ahd_outb(ahd, SCB_CONTROL,
3690 ahd_inb_scbram(ahd, SCB_CONTROL) & ~MK_MESSAGE);
3692 ahd->msgout_index = 0;
3693 ahd->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
3701 ahd_build_transfer_msg(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
3717 tinfo = ahd_fetch_transinfo(ahd, devinfo->channel, devinfo->our_scsiid,
3731 ahd_devlimited_syncrate(ahd, tinfo, &period,
3752 if ((ahd->features & AHD_WIDE) != 0)
3758 ahd_print_devinfo(ahd, devinfo);
3777 ahd_validate_offset(ahd, tinfo, period, &offset,
3782 ahd_construct_ppr(ahd, devinfo, period, offset,
3785 ahd_construct_sdtr(ahd, devinfo, period, offset);
3788 ahd_construct_wdtr(ahd, devinfo, tinfo->goal.width);
3797 ahd_construct_sdtr(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
3802 ahd->msgout_buf[ahd->msgout_index++] = MSG_EXTENDED;
3803 ahd->msgout_buf[ahd->msgout_index++] = MSG_EXT_SDTR_LEN;
3804 ahd->msgout_buf[ahd->msgout_index++] = MSG_EXT_SDTR;
3805 ahd->msgout_buf[ahd->msgout_index++] = period;
3806 ahd->msgout_buf[ahd->msgout_index++] = offset;
3807 ahd->msgout_len += 5;
3810 ahd_name(ahd), devinfo->channel, devinfo->target,
3820 ahd_construct_wdtr(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
3823 ahd->msgout_buf[ahd->msgout_index++] = MSG_EXTENDED;
3824 ahd->msgout_buf[ahd->msgout_index++] = MSG_EXT_WDTR_LEN;
3825 ahd->msgout_buf[ahd->msgout_index++] = MSG_EXT_WDTR;
3826 ahd->msgout_buf[ahd->msgout_index++] = bus_width;
3827 ahd->msgout_len += 4;
3830 ahd_name(ahd), devinfo->channel, devinfo->target,
3840 ahd_construct_ppr(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
3853 ahd->msgout_buf[ahd->msgout_index++] = MSG_EXTENDED;
3854 ahd->msgout_buf[ahd->msgout_index++] = MSG_EXT_PPR_LEN;
3855 ahd->msgout_buf[ahd->msgout_index++] = MSG_EXT_PPR;
3856 ahd->msgout_buf[ahd->msgout_index++] = period;
3857 ahd->msgout_buf[ahd->msgout_index++] = 0;
3858 ahd->msgout_buf[ahd->msgout_index++] = offset;
3859 ahd->msgout_buf[ahd->msgout_index++] = bus_width;
3860 ahd->msgout_buf[ahd->msgout_index++] = ppr_options;
3861 ahd->msgout_len += 8;
3864 "offset %x, ppr_options %x\n", ahd_name(ahd),
3874 ahd_clear_msg_state(struct ahd_softc *ahd)
3878 saved_modes = ahd_save_modes(ahd);
3879 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
3880 ahd->send_msg_perror = 0;
3881 ahd->msg_flags = MSG_FLAG_NONE;
3882 ahd->msgout_len = 0;
3883 ahd->msgin_index = 0;
3884 ahd->msg_type = MSG_TYPE_NONE;
3885 if ((ahd_inb(ahd, SCSISIGO) & ATNO) != 0) {
3890 ahd_outb(ahd, CLRSINT1, CLRATNO);
3892 ahd_outb(ahd, MSG_OUT, MSG_NOOP);
3893 ahd_outb(ahd, SEQ_FLAGS2,
3894 ahd_inb(ahd, SEQ_FLAGS2) & ~TARGET_MSG_PENDING);
3895 ahd_restore_modes(ahd, saved_modes);
3902 ahd_handle_message_phase(struct ahd_softc *ahd)
3908 ahd_fetch_devinfo(ahd, &devinfo);
3910 bus_phase = ahd_inb(ahd, LASTPHASE);
3912 if ((ahd_inb(ahd, LQISTAT2) & LQIPHASE_OUTPKT) != 0) {
3914 ahd_outb(ahd, LQCTL2, LQIRETRY);
3917 switch (ahd->msg_type) {
3924 if (ahd->msgout_len == 0 && ahd->send_msg_perror == 0)
3929 ahd_print_devinfo(ahd, &devinfo);
3949 ahd_outb(ahd, CLRSINT1, CLRATNO);
3950 ahd->send_msg_perror = 0;
3951 ahd->msg_type = MSG_TYPE_INITIATOR_MSGIN;
3952 ahd->msgin_index = 0;
3959 if (ahd->send_msg_perror) {
3960 ahd_outb(ahd, CLRSINT1, CLRATNO);
3961 ahd_outb(ahd, CLRSINT1, CLRREQINIT);
3964 printf(" byte 0x%x\n", ahd->send_msg_perror);
3972 if ((ahd->msg_flags & MSG_FLAG_PACKETIZED) != 0
3973 && ahd->send_msg_perror == MSG_INITIATOR_DET_ERR)
3974 ahd->msg_flags |= MSG_FLAG_EXPECT_IDE_BUSFREE;
3976 ahd_outb(ahd, RETURN_2, ahd->send_msg_perror);
3977 ahd_outb(ahd, RETURN_1, CONT_MSG_LOOP_WRITE);
3981 msgdone = ahd->msgout_index == ahd->msgout_len;
3988 ahd->msgout_index = 0;
3989 ahd_assert_atn(ahd);
3992 lastbyte = ahd->msgout_index == (ahd->msgout_len - 1);
3995 ahd_outb(ahd, CLRSINT1, CLRATNO);
4002 ahd_outb(ahd, CLRSINT1, CLRREQINIT);
4006 ahd->msgout_buf[ahd->msgout_index]);
4008 ahd_outb(ahd, RETURN_2, ahd->msgout_buf[ahd->msgout_index++]);
4009 ahd_outb(ahd, RETURN_1, CONT_MSG_LOOP_WRITE);
4019 ahd_print_devinfo(ahd, &devinfo);
4032 ahd->msgin_index = 0;
4034 && (ahd->send_msg_perror != 0
4035 || (ahd->msgout_len != 0
4036 && ahd->msgout_index == 0))) {
4037 ahd->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
4045 ahd->msgin_buf[ahd->msgin_index] = ahd_inb(ahd, SCSIBUS);
4049 ahd->msgin_buf[ahd->msgin_index]);
4052 message_done = ahd_parse_msg(ahd, &devinfo);
4059 ahd->msgin_index = 0;
4066 if (ahd->msgout_len != 0) {
4069 ahd_print_devinfo(ahd, &devinfo);
4073 ahd_assert_atn(ahd);
4076 ahd->msgin_index++;
4082 ahd_outb(ahd, CLRSINT1, CLRREQINIT);
4083 ahd_outb(ahd, RETURN_1, CONT_MSG_LOOP_READ);
4095 ahd_outb(ahd, RETURN_1, CONT_MSG_LOOP_TARG);
4097 if (ahd->msgout_len == 0)
4106 if ((ahd_inb(ahd, SCSISIGI) & ATNI) != 0
4107 && ahd->msgout_index > 0)
4120 ahd->msg_type = MSG_TYPE_TARGET_MSGOUT;
4121 ahd_outb(ahd, SCSISIGO, P_MESGOUT | BSYO);
4122 ahd->msgin_index = 0;
4124 ahd_inb(ahd, SCSIDAT);
4125 ahd_outb(ahd, SXFRCTL0,
4126 ahd_inb(ahd, SXFRCTL0) | SPIOEN);
4130 msgdone = ahd->msgout_index == ahd->msgout_len;
4132 ahd_outb(ahd, SXFRCTL0,
4133 ahd_inb(ahd, SXFRCTL0) & ~SPIOEN);
4141 ahd_outb(ahd, SXFRCTL0, ahd_inb(ahd, SXFRCTL0) | SPIOEN);
4142 ahd_outb(ahd, SCSIDAT, ahd->msgout_buf[ahd->msgout_index++]);
4153 ahd_outb(ahd, RETURN_1, CONT_MSG_LOOP_TARG);
4159 lastbyte = (ahd_inb(ahd, SCSISIGI) & ATNI) == 0;
4166 ahd_outb(ahd, SXFRCTL0, ahd_inb(ahd, SXFRCTL0) & ~SPIOEN);
4167 ahd->msgin_buf[ahd->msgin_index] = ahd_inb(ahd, SCSIDAT);
4168 msgdone = ahd_parse_msg(ahd, &devinfo);
4179 ahd->msgin_index++;
4186 ahd->msgin_index = 0;
4192 if (ahd->msgout_len != 0) {
4193 ahd_outb(ahd, SCSISIGO, P_MESGIN | BSYO);
4194 ahd_outb(ahd, SXFRCTL0,
4195 ahd_inb(ahd, SXFRCTL0) | SPIOEN);
4196 ahd->msg_type = MSG_TYPE_TARGET_MSGIN;
4197 ahd->msgin_index = 0;
4206 ahd_outb(ahd, SXFRCTL0,
4207 ahd_inb(ahd, SXFRCTL0) | SPIOEN);
4217 if ((ahd->msg_flags & MSG_FLAG_PACKETIZED) != 0) {
4219 ahd_name(ahd));
4220 ahd_clear_msg_state(ahd);
4225 ahd_outb(ahd, LASTPHASE, P_BUSFREE);
4226 ahd_outb(ahd, SEQ_FLAGS, NOT_IDENTIFIED|NO_CDB_SENT);
4227 ahd_outb(ahd, SEQCTL0, FASTMODE|SEQRESET);
4229 ahd_clear_msg_state(ahd);
4230 ahd_outb(ahd, RETURN_1, EXIT_MSG_LOOP);
4242 ahd_sent_msg(struct ahd_softc *ahd, ahd_msgtype type, u_int msgval, int full)
4250 while (index < ahd->msgout_len) {
4251 if (ahd->msgout_buf[index] == MSG_EXTENDED) {
4254 end_index = index + 1 + ahd->msgout_buf[index + 1];
4255 if (ahd->msgout_buf[index+2] == msgval
4259 if (ahd->msgout_index > end_index)
4261 } else if (ahd->msgout_index > index)
4265 } else if (ahd->msgout_buf[index] >= MSG_SIMPLE_TASK
4266 && ahd->msgout_buf[index] <= MSG_IGN_WIDE_RESIDUE) {
4273 && ahd->msgout_index > index
4274 && (ahd->msgout_buf[index] == msgval
4275 || ((ahd->msgout_buf[index] & MSG_IDENTIFYFLAG) != 0
4291 ahd_parse_msg(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
4302 tinfo = ahd_fetch_transinfo(ahd, devinfo->channel, devinfo->our_scsiid,
4316 switch (ahd->msgin_buf[0]) {
4329 response = ahd_handle_msg_reject(ahd, devinfo);
4337 if (ahd->msgin_index < 2)
4339 switch (ahd->msgin_buf[2]) {
4347 if (ahd->msgin_buf[1] != MSG_EXT_SDTR_LEN) {
4359 if (ahd->msgin_index < (MSG_EXT_SDTR_LEN + 1))
4362 period = ahd->msgin_buf[3];
4364 saved_offset = offset = ahd->msgin_buf[4];
4365 ahd_devlimited_syncrate(ahd, tinfo, &period,
4367 ahd_validate_offset(ahd, tinfo, period, &offset,
4373 ahd_name(ahd), devinfo->channel,
4375 ahd->msgin_buf[3], saved_offset,
4378 ahd_set_syncrate(ahd, devinfo, period,
4388 if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_SDTR, TRUE)) {
4402 ahd_name(ahd), devinfo->channel,
4405 ahd->msgout_index = 0;
4406 ahd->msgout_len = 0;
4407 ahd_construct_sdtr(ahd, devinfo,
4409 ahd->msgout_index = 0;
4422 if (ahd->msgin_buf[1] != MSG_EXT_WDTR_LEN) {
4434 if (ahd->msgin_index < (MSG_EXT_WDTR_LEN + 1))
4437 bus_width = ahd->msgin_buf[3];
4439 ahd_validate_width(ahd, tinfo, &bus_width,
4444 ahd_name(ahd), devinfo->channel,
4449 if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_WDTR, TRUE)) {
4460 ahd_name(ahd), devinfo->channel,
4473 ahd_name(ahd), devinfo->channel,
4476 ahd->msgout_index = 0;
4477 ahd->msgout_len = 0;
4478 ahd_construct_wdtr(ahd, devinfo, bus_width);
4479 ahd->msgout_index = 0;
4492 ahd_update_neg_request(ahd, devinfo, tstate,
4494 ahd_set_width(ahd, devinfo, bus_width,
4502 ahd->msgout_index = 0;
4503 ahd->msgout_len = 0;
4504 ahd_build_transfer_msg(ahd, devinfo);
4505 ahd->msgout_index = 0;
4521 if (ahd->msgin_buf[1] != MSG_EXT_PPR_LEN) {
4533 if (ahd->msgin_index < (MSG_EXT_PPR_LEN + 1))
4536 period = ahd->msgin_buf[3];
4537 offset = ahd->msgin_buf[5];
4538 bus_width = ahd->msgin_buf[6];
4540 ppr_options = ahd->msgin_buf[7];
4559 ahd_validate_width(ahd, tinfo, &bus_width,
4561 ahd_devlimited_syncrate(ahd, tinfo, &period,
4563 ahd_validate_offset(ahd, tinfo, period, &offset,
4566 if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_PPR, TRUE)) {
4585 ahd_name(ahd), devinfo->channel,
4590 ahd_name(ahd), devinfo->channel,
4592 ahd->msgout_index = 0;
4593 ahd->msgout_len = 0;
4594 ahd_construct_ppr(ahd, devinfo, period, offset,
4596 ahd->msgout_index = 0;
4604 ahd_name(ahd), devinfo->channel,
4606 saved_width, ahd->msgin_buf[3],
4610 ahd_set_width(ahd, devinfo, bus_width,
4613 ahd_set_syncrate(ahd, devinfo, period,
4630 ahd_handle_devreset(ahd, devinfo, CAM_LUN_WILDCARD,
4634 ahd_restart(ahd);
4649 if (ahd->msgin_buf[0] == MSG_ABORT_TAG)
4650 tag = ahd_inb(ahd, INITIATOR_TAG);
4651 ahd_abort_scbs(ahd, devinfo->target, devinfo->channel,
4655 tstate = ahd->enabled_targets[devinfo->our_scsiid];
4661 ahd_queue_lstate_event(ahd, lstate,
4663 ahd->msgin_buf[0],
4665 ahd_send_lstate_events(ahd, lstate);
4668 ahd_restart(ahd);
4677 ahd_name(ahd), ahd_inb(ahd, SCSISIGI));
4679 ahd->msg_flags |= MSG_FLAG_EXPECT_QASREJ_BUSFREE;
4691 ahd->msgout_index = 0;
4692 ahd->msgout_len = 1;
4693 ahd->msgout_buf[0] = MSG_MESSAGE_REJECT;
4700 ahd->msgout_len = 0;
4709 ahd_handle_msg_reject(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
4724 scb_index = ahd_get_scbptr(ahd);
4725 scb = ahd_lookup_scb(ahd, scb_index);
4726 tinfo = ahd_fetch_transinfo(ahd, devinfo->channel,
4730 last_msg = ahd_inb(ahd, LAST_MSG);
4732 if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_PPR, /*full*/FALSE)) {
4733 if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_PPR, /*full*/TRUE)
4743 ahd_name(ahd), devinfo->channel,
4758 ahd_name(ahd), devinfo->channel,
4765 ahd->msgout_index = 0;
4766 ahd->msgout_len = 0;
4767 ahd_build_transfer_msg(ahd, devinfo);
4768 ahd->msgout_index = 0;
4770 } else if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_WDTR, /*full*/FALSE)) {
4774 "8bit transfers\n", ahd_name(ahd),
4776 ahd_set_width(ahd, devinfo, MSG_EXT_WDTR_BUS_8_BIT,
4789 ahd->msgout_index = 0;
4790 ahd->msgout_len = 0;
4791 ahd_build_transfer_msg(ahd, devinfo);
4792 ahd->msgout_index = 0;
4795 } else if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_SDTR, /*full*/FALSE)) {
4797 ahd_set_syncrate(ahd, devinfo, /*period*/0,
4803 ahd_name(ahd), devinfo->channel,
4813 "Performing non-tagged I/O\n", ahd_name(ahd),
4815 ahd_set_tags(ahd, devinfo, AHD_QUEUE_NONE);
4820 ahd_name(ahd), devinfo->channel, devinfo->target,
4823 ahd_set_tags(ahd, devinfo, AHD_QUEUE_BASIC);
4831 ahd_outb(ahd, SCB_CONTROL,
4832 ahd_inb_scbram(ahd, SCB_CONTROL) & mask);
4836 ahd_outb(ahd, MSG_OUT, MSG_IDENTIFYFLAG);
4837 ahd_assert_atn(ahd);
4838 ahd_busy_tcl(ahd, BUILD_TCL(scb->hscb->scsiid, devinfo->lun),
4846 ahd_search_qinfifo(ahd, SCB_GET_TARGET(ahd, scb),
4847 SCB_GET_CHANNEL(ahd, scb),
4851 } else if (ahd_sent_msg(ahd, AHDMSG_1B, MSG_IDENTIFYFLAG, TRUE)) {
4856 ahd->msg_flags |= MSG_FLAG_EXPECT_PPR_BUSFREE
4859 ahd_force_renegotiation(ahd, devinfo);
4860 ahd->msgout_index = 0;
4861 ahd->msgout_len = 0;
4862 ahd_build_transfer_msg(ahd, devinfo);
4863 ahd->msgout_index = 0;
4870 ahd_name(ahd), devinfo->channel, devinfo->target,
4880 ahd_handle_ign_wide_residue(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
4885 scb_index = ahd_get_scbptr(ahd);
4886 scb = ahd_lookup_scb(ahd, scb_index);
4891 if ((ahd_inb(ahd, SEQ_FLAGS) & DPHASE) == 0
4907 sgptr = ahd_inb_scbram(ahd, SCB_RESIDUAL_SGPTR);
4909 && (ahd_inb_scbram(ahd, SCB_TASK_ATTRIBUTE)
4923 sgptr = ahd_inl_scbram(ahd, SCB_RESIDUAL_SGPTR);
4924 data_cnt = ahd_inl_scbram(ahd, SCB_RESIDUAL_DATACNT);
4933 data_addr = ahd_inq(ahd, SHADDR);
4937 if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0) {
4940 sg = ahd_sg_bus_to_virt(ahd, scb, sgptr);
4967 sgptr = ahd_sg_virt_to_bus(ahd, scb,
4973 sg = ahd_sg_bus_to_virt(ahd, scb, sgptr);
5000 sgptr = ahd_sg_virt_to_bus(ahd, scb,
5010 ahd_outb(ahd, SCB_TASK_ATTRIBUTE,
5011 ahd_inb_scbram(ahd, SCB_TASK_ATTRIBUTE)
5014 ahd_outl(ahd, SCB_RESIDUAL_SGPTR, sgptr);
5015 ahd_outl(ahd, SCB_RESIDUAL_DATACNT, data_cnt);
5030 ahd_reinitialize_dataptrs(struct ahd_softc *ahd)
5040 AHD_ASSERT_MODES(ahd, AHD_MODE_DFF0_MSK|AHD_MODE_DFF1_MSK,
5043 scb_index = ahd_get_scbptr(ahd);
5044 scb = ahd_lookup_scb(ahd, scb_index);
5050 ahd_outb(ahd, DFFSXFRCTL, CLRCHN);
5052 while (--wait && !(ahd_inb(ahd, MDFFSTAT) & FIFOFREE))
5055 ahd_print_path(ahd, scb);
5057 ahd_outb(ahd, DFFSXFRCTL, RSTCHN|CLRSHCNT);
5059 saved_modes = ahd_save_modes(ahd);
5060 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
5061 ahd_outb(ahd, DFFSTAT,
5062 ahd_inb(ahd, DFFSTAT)
5069 sgptr = ahd_inl_scbram(ahd, SCB_RESIDUAL_SGPTR);
5072 resid = (ahd_inb_scbram(ahd, SCB_RESIDUAL_DATACNT + 2) << 16)
5073 | (ahd_inb_scbram(ahd, SCB_RESIDUAL_DATACNT + 1) << 8)
5074 | ahd_inb_scbram(ahd, SCB_RESIDUAL_DATACNT);
5076 if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0) {
5079 sg = ahd_sg_bus_to_virt(ahd, scb, sgptr);
5087 ahd_outl(ahd, HADDR + 4, dataptr >> 32);
5091 sg = ahd_sg_bus_to_virt(ahd, scb, sgptr);
5099 ahd_outb(ahd, HADDR + 4,
5102 ahd_outl(ahd, HADDR, dataptr);
5103 ahd_outb(ahd, HCNT + 2, resid >> 16);
5104 ahd_outb(ahd, HCNT + 1, resid >> 8);
5105 ahd_outb(ahd, HCNT, resid);
5112 ahd_handle_devreset(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
5121 found = ahd_abort_scbs(ahd, devinfo->target, devinfo->channel,
5130 tstate = ahd->enabled_targets[devinfo->our_scsiid];
5149 ahd_queue_lstate_event(ahd, lstate, devinfo->our_scsiid,
5151 ahd_send_lstate_events(ahd, lstate);
5159 ahd_set_width(ahd, devinfo, MSG_EXT_WDTR_BUS_8_BIT,
5161 ahd_set_syncrate(ahd, devinfo, /*period*/0, /*offset*/0,
5166 ahd_send_async(ahd, devinfo->channel, devinfo->target,
5171 AHD_CORRECTABLE_ERROR(ahd);
5172 printf("%s: %s on %c:%d. %d SCBs aborted\n", ahd_name(ahd),
5179 ahd_setup_target_msgin(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
5188 ahd->msgout_index = 0;
5189 ahd->msgout_len = 0;
5192 ahd_build_transfer_msg(ahd, devinfo);
5196 ahd->msgout_index = 0;
5197 ahd->msg_type = MSG_TYPE_TARGET_MSGIN;
5202 ahd_sglist_size(struct ahd_softc *ahd)
5207 if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0)
5219 ahd_sglist_allocsize(struct ahd_softc *ahd)
5227 sg_list_increment = ahd_sglist_size(ahd);
5266 struct ahd_softc *ahd;
5269 ahd = malloc(sizeof(*ahd), M_DEVBUF, M_NOWAIT);
5270 if (!ahd) {
5276 ahd = device_get_softc((device_t)platform_arg);
5278 memset(ahd, 0, sizeof(*ahd));
5279 ahd->seep_config = malloc(sizeof(*ahd->seep_config),
5281 if (ahd->seep_config == NULL) {
5283 free(ahd, M_DEVBUF);
5288 LIST_INIT(&ahd->pending_scbs);
5289 LIST_INIT(&ahd->timedout_scbs);
5291 ahd->name = name;
5292 ahd->unit = -1;
5293 ahd->description = NULL;
5294 ahd->bus_description = NULL;
5295 ahd->channel = 'A';
5296 ahd->chip = AHD_NONE;
5297 ahd->features = AHD_FENONE;
5298 ahd->bugs = AHD_BUGNONE;
5299 ahd->flags = AHD_SPCHK_ENB_A|AHD_RESET_BUS_A|AHD_TERM_ENB_A
5301 aic_timer_init(&ahd->reset_timer);
5302 aic_timer_init(&ahd->stat_timer);
5303 ahd->int_coalescing_timer = AHD_INT_COALESCING_TIMER_DEFAULT;
5304 ahd->int_coalescing_maxcmds = AHD_INT_COALESCING_MAXCMDS_DEFAULT;
5305 ahd->int_coalescing_mincmds = AHD_INT_COALESCING_MINCMDS_DEFAULT;
5306 ahd->int_coalescing_threshold = AHD_INT_COALESCING_THRESHOLD_DEFAULT;
5307 ahd->int_coalescing_stop_threshold =
5310 if (ahd_platform_alloc(ahd, platform_arg) != 0) {
5311 ahd_free(ahd);
5312 ahd = NULL;
5314 ahd_lockinit(ahd);
5318 ahd_name(ahd), (u_int)sizeof(struct scb),
5322 return (ahd);
5326 ahd_softc_init(struct ahd_softc *ahd)
5329 ahd->unpause = 0;
5330 ahd->pause = PAUSE;
5335 ahd_softc_insert(struct ahd_softc *ahd)
5344 if ((ahd->features & AHD_MULTI_FUNC) != 0) {
5350 pci = ahd->dev_softc;
5358 slave = ahd;
5360 master = ahd;
5377 && ahd_softc_comp(ahd, list_ahd) <= 0)
5380 TAILQ_INSERT_BEFORE(list_ahd, ahd, links);
5382 TAILQ_INSERT_TAIL(&ahd_tailq, ahd, links);
5383 ahd->init_level++;
5387 ahd_set_unit(struct ahd_softc *ahd, int unit)
5389 ahd->unit = unit;
5393 ahd_set_name(struct ahd_softc *ahd, char *name)
5395 if (ahd->name != NULL)
5396 free(ahd->name, M_DEVBUF);
5397 ahd->name = name;
5401 ahd_free(struct ahd_softc *ahd)
5405 ahd_terminate_recovery_thread(ahd);
5406 switch (ahd->init_level) {
5409 ahd_shutdown(ahd);
5412 aic_dmamap_unload(ahd, ahd->shared_data_dmat,
5413 ahd->shared_data_map.dmamap);
5416 aic_dmamem_free(ahd, ahd->shared_data_dmat, ahd->qoutfifo,
5417 ahd->shared_data_map.dmamap);
5420 aic_dma_tag_destroy(ahd, ahd->shared_data_dmat);
5423 aic_dma_tag_destroy(ahd, ahd->buffer_dmat);
5431 aic_dma_tag_destroy(ahd, ahd->parent_dmat);
5433 ahd_platform_free(ahd);
5434 ahd_fini_scbdata(ahd);
5438 tstate = ahd->enabled_targets[i];
5457 if (ahd->black_hole != NULL) {
5458 xpt_free_path(ahd->black_hole->path);
5459 free(ahd->black_hole, M_DEVBUF);
5462 if (ahd->name != NULL)
5463 free(ahd->name, M_DEVBUF);
5464 if (ahd->seep_config != NULL)
5465 free(ahd->seep_config, M_DEVBUF);
5466 if (ahd->saved_stack != NULL)
5467 free(ahd->saved_stack, M_DEVBUF);
5469 free(ahd, M_DEVBUF);
5477 struct ahd_softc *ahd;
5479 ahd = (struct ahd_softc *)arg;
5484 aic_timer_stop(&ahd->reset_timer);
5485 aic_timer_stop(&ahd->stat_timer);
5488 ahd_reset(ahd, /*reinit*/FALSE);
5501 ahd_reset(struct ahd_softc *ahd, int reinit)
5512 ahd_pause(ahd);
5513 ahd_update_modes(ahd);
5514 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
5515 sxfrctl1 = ahd_inb(ahd, SXFRCTL1);
5517 cmd = aic_pci_read_config(ahd->dev_softc, PCIR_COMMAND, /*bytes*/2);
5518 if ((ahd->bugs & AHD_PCIX_CHIPRST_BUG) != 0) {
5531 aic_pci_write_config(ahd->dev_softc, PCIR_COMMAND,
5534 ahd_outb(ahd, HCNTRL, CHIPRST | ahd->pause);
5545 } while (--wait && !(ahd_inb(ahd, HCNTRL) & CHIPRSTACK));
5549 "Trying to initialize anyway.\n", ahd_name(ahd));
5550 AHD_FATAL_ERROR(ahd);
5552 ahd_outb(ahd, HCNTRL, ahd->pause);
5554 if ((ahd->bugs & AHD_PCIX_CHIPRST_BUG) != 0) {
5559 aic_pci_write_config(ahd->dev_softc, PCIR_STATUS + 1,
5561 aic_pci_write_config(ahd->dev_softc, PCIR_COMMAND,
5571 ahd_known_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
5572 ahd_outb(ahd, MODE_PTR,
5573 ahd_build_mode_state(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI));
5583 ahd_outb(ahd, SXFRCTL1, sxfrctl1|STPWEN);
5584 ahd_outb(ahd, SXFRCTL1, sxfrctl1);
5587 ahd->features &= ~AHD_WIDE;
5588 if ((ahd_inb(ahd, SBLKCTL) & SELWIDE) != 0)
5589 ahd->features |= AHD_WIDE;
5596 ahd_chip_init(ahd);
5605 ahd_probe_scbs(struct ahd_softc *ahd) {
5608 AHD_ASSERT_MODES(ahd, ~(AHD_MODE_UNKNOWN_MSK|AHD_MODE_CFG_MSK),
5613 ahd_set_scbptr(ahd, i);
5614 ahd_outw(ahd, SCB_BASE, i);
5616 ahd_outb(ahd, SCB_BASE+j, 0);
5618 ahd_outb(ahd, SCB_CONTROL, MK_MESSAGE);
5619 if (ahd_inw_scbram(ahd, SCB_BASE) != i)
5621 ahd_set_scbptr(ahd, 0);
5622 if (ahd_inw_scbram(ahd, SCB_BASE) != 0)
5638 ahd_initialize_hscbs(struct ahd_softc *ahd)
5642 for (i = 0; i < ahd->scb_data.maxhscbs; i++) {
5643 ahd_set_scbptr(ahd, i);
5646 ahd_outb(ahd, SCB_CONTROL, 0);
5649 ahd_outw(ahd, SCB_NEXT, SCB_LIST_NULL);
5654 ahd_init_scbdata(struct ahd_softc *ahd)
5659 scb_data = &ahd->scb_data;
5669 scb_data->maxhscbs = ahd_probe_scbs(ahd);
5671 printf("%s: No SCB space found\n", ahd_name(ahd));
5672 AHD_FATAL_ERROR(ahd);
5676 ahd_initialize_hscbs(ahd);
5689 if (aic_dma_tag_create(ahd, ahd->parent_dmat, /*alignment*/1,
5703 if (aic_dma_tag_create(ahd, ahd->parent_dmat, /*alignment*/8,
5708 ahd_sglist_allocsize(ahd), /*nsegments*/1,
5715 printf("%s: ahd_sglist_allocsize = 0x%x\n", ahd_name(ahd),
5716 ahd_sglist_allocsize(ahd));
5722 if (aic_dma_tag_create(ahd, ahd->parent_dmat, /*alignment*/1,
5736 while (ahd_alloc_scbs(ahd) != 0)
5742 ahd_name(ahd));
5757 ahd_find_scb_by_tag(struct ahd_softc *ahd, u_int tag)
5764 LIST_FOREACH(scb, &ahd->pending_scbs, pending_links) {
5772 TAILQ_FOREACH(scb, &ahd->scb_data.free_scbs, links.tqe) {
5786 LIST_FOREACH(scb, &ahd->scb_data.any_dev_free_scb_list, links.le) {
5795 ahd_fini_scbdata(struct ahd_softc *ahd)
5799 scb_data = &ahd->scb_data;
5811 aic_dmamap_unload(ahd, scb_data->sense_dmat,
5813 aic_dmamem_free(ahd, scb_data->sense_dmat,
5817 aic_dma_tag_destroy(ahd, scb_data->sense_dmat);
5826 aic_dmamap_unload(ahd, scb_data->sg_dmat,
5828 aic_dmamem_free(ahd, scb_data->sg_dmat,
5832 aic_dma_tag_destroy(ahd, scb_data->sg_dmat);
5841 aic_dmamap_unload(ahd, scb_data->hscb_dmat,
5843 aic_dmamem_free(ahd, scb_data->hscb_dmat,
5847 aic_dma_tag_destroy(ahd, scb_data->hscb_dmat);
5864 ahd_setup_iocell_workaround(struct ahd_softc *ahd)
5868 saved_modes = ahd_save_modes(ahd);
5869 ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
5870 ahd_outb(ahd, DSPDATACTL, ahd_inb(ahd, DSPDATACTL)
5872 ahd_outb(ahd, SIMODE0, ahd_inb(ahd, SIMODE0) | (ENSELDO|ENSELDI));
5875 printf("%s: Setting up iocell workaround\n", ahd_name(ahd));
5877 ahd_restore_modes(ahd, saved_modes);
5878 ahd->flags &= ~AHD_HAD_FIRST_SEL;
5882 ahd_iocell_first_selection(struct ahd_softc *ahd)
5887 if ((ahd->flags & AHD_HAD_FIRST_SEL) != 0)
5889 saved_modes = ahd_save_modes(ahd);
5890 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
5891 sblkctl = ahd_inb(ahd, SBLKCTL);
5892 ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
5895 printf("%s: iocell first selection\n", ahd_name(ahd));
5898 ahd_outb(ahd, DSPDATACTL,
5899 ahd_inb(ahd, DSPDATACTL) & ~BYPASSENAB);
5902 printf("%s: BYPASS now disabled\n", ahd_name(ahd));
5905 ahd_outb(ahd, SIMODE0, ahd_inb(ahd, SIMODE0) & ~(ENSELDO|ENSELDI));
5906 ahd_outb(ahd, CLRINT, CLRSCSIINT);
5907 ahd_restore_modes(ahd, saved_modes);
5908 ahd->flags |= AHD_HAD_FIRST_SEL;
5913 ahd_add_col_list(struct ahd_softc *ahd, struct scb *scb, u_int col_idx)
5921 free_list = &ahd->scb_data.free_scb_lists[col_idx];
5922 free_tailq = &ahd->scb_data.free_scbs;
5933 ahd_rem_col_list(struct ahd_softc *ahd, struct scb *scb)
5941 col_idx = AHD_GET_SCB_COL_IDX(ahd, scb);
5942 free_list = &ahd->scb_data.free_scb_lists[col_idx];
5943 free_tailq = &ahd->scb_data.free_scbs;
5967 ahd_get_scb(struct ahd_softc *ahd, u_int col_idx)
5974 TAILQ_FOREACH(scb, &ahd->scb_data.free_scbs, links.tqe) {
5975 if (AHD_GET_SCB_COL_IDX(ahd, scb) != col_idx) {
5976 ahd_rem_col_list(ahd, scb);
5980 if ((scb = LIST_FIRST(&ahd->scb_data.any_dev_free_scb_list)) == NULL) {
5984 if (ahd_alloc_scbs(ahd) == 0)
5993 ahd_add_col_list(ahd, scb->col_scb, col_idx);
6004 ahd_free_scb(struct ahd_softc *ahd, struct scb *scb)
6010 ahd->scb_data.scbindex[SCB_GET_TAG(scb)] = NULL;
6017 LIST_INSERT_HEAD(&ahd->scb_data.any_dev_free_scb_list,
6026 ahd_rem_col_list(ahd, scb->col_scb);
6027 LIST_INSERT_HEAD(&ahd->scb_data.any_dev_free_scb_list,
6029 LIST_INSERT_HEAD(&ahd->scb_data.any_dev_free_scb_list,
6040 ahd_add_col_list(ahd, scb,
6041 AHD_GET_SCB_COL_IDX(ahd, scb->col_scb));
6049 LIST_INSERT_HEAD(&ahd->scb_data.any_dev_free_scb_list,
6053 aic_platform_scb_free(ahd, scb);
6057 ahd_alloc_scbs(struct ahd_softc *ahd)
6073 scb_data = &ahd->scb_data;
6092 if (aic_dmamem_alloc(ahd, scb_data->hscb_dmat,
6102 aic_dmamap_load(ahd, scb_data->hscb_dmat, hscb_map->dmamap,
6114 offset = ((ahd_sglist_allocsize(ahd) / ahd_sglist_size(ahd))
6115 - scb_data->sgs_left) * ahd_sglist_size(ahd);
6126 if (aic_dmamem_alloc(ahd, scb_data->sg_dmat,
6136 aic_dmamap_load(ahd, scb_data->sg_dmat, sg_map->dmamap,
6137 sg_map->vaddr, ahd_sglist_allocsize(ahd),
6143 ahd_sglist_allocsize(ahd) / ahd_sglist_size(ahd);
6164 if (aic_dmamem_alloc(ahd, scb_data->sense_dmat,
6173 aic_dmamap_load(ahd, scb_data->sense_dmat, sense_map->dmamap,
6226 if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0)
6231 next_scb->ahd_softc = ahd;
6234 error = aic_dmamap_create(ahd, ahd->buffer_dmat, /*flags*/0,
6244 next_scb->col_scb = ahd_find_scb_by_tag(ahd, col_tag);
6248 ahd_free_scb(ahd, next_scb);
6251 segs += ahd_sglist_size(ahd);
6252 sg_busaddr += ahd_sglist_size(ahd);
6261 ahd_controller_info(struct ahd_softc *ahd, char *buf)
6267 len = sprintf(buf, "%s: ", ahd_chip_names[ahd->chip & AHD_CHIPID_MASK]);
6271 if ((ahd->features & AHD_WIDE) != 0) {
6277 speed, type, ahd->channel, ahd->our_id);
6280 sprintf(buf, "%s, %d SCBs", ahd->bus_description,
6281 ahd->scb_data.maxhscbs);
6302 ahd_init(struct ahd_softc *ahd)
6313 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
6315 ahd->stack_size = ahd_probe_stack_size(ahd);
6316 ahd->saved_stack = malloc(ahd->stack_size * sizeof(uint16_t),
6318 if (ahd->saved_stack == NULL)
6330 ahd->flags |= AHD_SEQUENCER_DEBUG;
6336 ahd->flags |= AHD_INITIATORROLE;
6341 if ((AHD_TMODE_ENABLE & (0x1 << ahd->unit)) == 0)
6342 ahd->features &= ~AHD_TARGETMODE;
6346 if (aic_dma_tag_create(ahd, ahd->parent_dmat, /*alignment*/1,
6348 /*lowaddr*/ahd->flags & AHD_39BIT_ADDRESSING
6357 &ahd->buffer_dmat) != 0) {
6362 ahd->init_level++;
6371 driver_data_size = AHD_SCB_MAX * sizeof(*ahd->qoutfifo)
6373 if ((ahd->features & AHD_TARGETMODE) != 0)
6375 if ((ahd->bugs & AHD_PKT_BITBUCKET_BUG) != 0)
6377 if (aic_dma_tag_create(ahd, ahd->parent_dmat, /*alignment*/1,
6385 /*flags*/0, &ahd->shared_data_dmat) != 0) {
6389 ahd->init_level++;
6392 if (aic_dmamem_alloc(ahd, ahd->shared_data_dmat,
6393 (void **)&ahd->shared_data_map.vaddr,
6395 &ahd->shared_data_map.dmamap) != 0) {
6399 ahd->init_level++;
6402 aic_dmamap_load(ahd, ahd->shared_data_dmat, ahd->shared_data_map.dmamap,
6403 ahd->shared_data_map.vaddr, driver_data_size,
6404 ahd_dmamap_cb, &ahd->shared_data_map.busaddr,
6406 ahd->qoutfifo = (struct ahd_completion *)ahd->shared_data_map.vaddr;
6407 next_vaddr = (uint8_t *)&ahd->qoutfifo[AHD_QOUT_SIZE];
6408 next_baddr = ahd->shared_data_map.busaddr
6410 if ((ahd->features & AHD_TARGETMODE) != 0) {
6411 ahd->targetcmds = (struct target_cmd *)next_vaddr;
6416 if ((ahd->bugs & AHD_PKT_BITBUCKET_BUG) != 0) {
6417 ahd->overrun_buf = next_vaddr;
6429 ahd->next_queued_hscb = (struct hardware_scb *)next_vaddr;
6430 ahd->next_queued_hscb_map = &ahd->shared_data_map;
6431 ahd->next_queued_hscb->hscb_busaddr = aic_htole32(next_baddr);
6433 ahd->init_level++;
6436 if (ahd_init_scbdata(ahd) != 0)
6439 if ((ahd->flags & AHD_INITIATORROLE) == 0)
6440 ahd->flags &= ~AHD_RESET_BUS_A;
6446 ahd_platform_init(ahd);
6449 ahd_chip_init(ahd);
6451 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
6453 if ((ahd->flags & AHD_CURRENT_SENSING) == 0)
6460 error = ahd_write_flexport(ahd, FLXADDR_ROMSTAT_CURSENSECTL,
6463 printf("%s: current sensing timeout 1\n", ahd_name(ahd));
6468 error = ahd_read_flexport(ahd, FLXADDR_FLEXSTAT, &fstat);
6471 ahd_name(ahd));
6477 ahd_name(ahd));
6482 error = ahd_read_flexport(ahd, FLXADDR_CURRENT_STAT, &current_sensing);
6484 printf("%s: current sensing timeout 3\n", ahd_name(ahd));
6489 ahd_write_flexport(ahd, FLXADDR_ROMSTAT_CURSENSECTL, 0);
6494 ahd_name(ahd), current_sensing);
6510 printf("%s: %s Channel %s\n", ahd_name(ahd),
6518 ahd_name(ahd), ahd_name(ahd));
6519 AHD_CORRECTABLE_ERROR(ahd);
6522 ahd_restart(ahd);
6523 aic_timer_reset(&ahd->stat_timer, AHD_STAT_UPDATE_MS,
6524 ahd_stat_timer, ahd);
6532 ahd_chip_init(struct ahd_softc *ahd)
6541 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
6545 ahd_outb(ahd, SBLKCTL, ahd_inb(ahd, SBLKCTL) & ~(DIAGLEDEN|DIAGLEDON));
6550 ahd->hs_mailbox = 0;
6551 ahd_outb(ahd, HS_MAILBOX, 0);
6554 ahd_outb(ahd, IOWNID, ahd->our_id);
6555 ahd_outb(ahd, TOWNID, ahd->our_id);
6556 sxfrctl1 = (ahd->flags & AHD_TERM_ENB_A) != 0 ? STPWEN : 0;
6557 sxfrctl1 |= (ahd->flags & AHD_SPCHK_ENB_A) != 0 ? ENSPCHK : 0;
6558 if ((ahd->bugs & AHD_LONG_SETIMO_BUG)
6559 && (ahd->seltime != STIMESEL_MIN)) {
6565 sxfrctl1 |= ahd->seltime + STIMESEL_BUG_ADJ;
6567 sxfrctl1 |= ahd->seltime;
6570 ahd_outb(ahd, SXFRCTL0, DFON);
6571 ahd_outb(ahd, SXFRCTL1, sxfrctl1|ahd->seltime|ENSTIMER|ACTNEGEN);
6572 ahd_outb(ahd, SIMODE1, ENSELTIMO|ENSCSIRST|ENSCSIPERR);
6582 (ahd_inb(ahd, SBLKCTL) & (ENAB40|ENAB20)) == 0 && wait;
6587 ahd_outb(ahd, CLRSINT1, CLRSCSIRSTI);
6588 ahd_outb(ahd, CLRINT, CLRSCSIINT);
6592 ahd_set_modes(ahd, AHD_MODE_DFF0 + i, AHD_MODE_DFF0 + i);
6593 ahd_outb(ahd, LONGJMP_ADDR + 1, INVALID_ADDR);
6594 ahd_outb(ahd, SG_STATE, 0);
6595 ahd_outb(ahd, CLRSEQINTSRC, 0xFF);
6596 ahd_outb(ahd, SEQIMODE,
6601 ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
6602 ahd_outb(ahd, DSCOMMAND0, ahd_inb(ahd, DSCOMMAND0)|MPARCKEN|CACHETHEN);
6603 ahd_outb(ahd, DFF_THRSH, RD_DFTHRSH_75|WR_DFTHRSH_75);
6604 ahd_outb(ahd, SIMODE0, ENIOERR|ENOVERRUN);
6605 ahd_outb(ahd, SIMODE3, ENNTRAMPERR|ENOSRAMPERR);
6606 if ((ahd->bugs & AHD_BUSFREEREV_BUG) != 0) {
6607 ahd_outb(ahd, OPTIONMODE, AUTOACKEN|AUTO_MSGOUT_DE);
6609 ahd_outb(ahd, OPTIONMODE, AUTOACKEN|BUSFREEREV|AUTO_MSGOUT_DE);
6611 ahd_outb(ahd, SCSCHKN, CURRFIFODEF|WIDERESEN|SHVALIDSTDIS);
6612 if ((ahd->chip & AHD_BUS_MASK) == AHD_PCIX)
6618 ahd_outb(ahd, PCIXCTL, ahd_inb(ahd, PCIXCTL) | SPLTSTADIS);
6620 if ((ahd->bugs & AHD_LQOOVERRUN_BUG) != 0)
6621 ahd_outb(ahd, LQOSCSCTL, LQONOCHKOVER);
6626 if ((ahd->flags & AHD_HP_BOARD) != 0) {
6628 ahd_outb(ahd, DSPSELECT, i);
6629 ahd_outb(ahd, WRTBIASCTL, WRTBIASCTL_HP_DEFAULT);
6633 printf("%s: WRTBIASCTL now 0x%x\n", ahd_name(ahd),
6637 ahd_setup_iocell_workaround(ahd);
6642 ahd_outb(ahd, LQIMODE1, ENLQIPHASE_LQ|ENLQIPHASE_NLQ|ENLIQABORT
6645 ahd_outb(ahd, LQOMODE0, ENLQOATNLQ|ENLQOATNPKT|ENLQOTCRC);
6654 ahd_outb(ahd, LQOMODE1, ENLQOBUSFREE);
6659 ahd_outw(ahd, INTVEC1_ADDR, ahd_resolve_seqaddr(ahd, LABEL_seq_isr));
6660 ahd_outw(ahd, INTVEC2_ADDR, ahd_resolve_seqaddr(ahd, LABEL_timer_isr));
6665 if ((ahd->bugs & AHD_PKT_LUN_BUG) != 0) {
6666 ahd_outb(ahd, LUNPTR, offsetof(struct hardware_scb,
6669 ahd_outb(ahd, LUNPTR, offsetof(struct hardware_scb, lun));
6671 ahd_outb(ahd, CMDLENPTR, offsetof(struct hardware_scb, cdb_len));
6672 ahd_outb(ahd, ATTRPTR, offsetof(struct hardware_scb, task_attribute));
6673 ahd_outb(ahd, FLAGPTR, offsetof(struct hardware_scb, task_management));
6674 ahd_outb(ahd, CMDPTR, offsetof(struct hardware_scb,
6676 ahd_outb(ahd, QNEXTPTR,
6678 ahd_outb(ahd, ABRTBITPTR, MK_MESSAGE_BIT_OFFSET);
6679 ahd_outb(ahd, ABRTBYTEPTR, offsetof(struct hardware_scb, control));
6680 if ((ahd->bugs & AHD_PKT_LUN_BUG) != 0) {
6681 ahd_outb(ahd, LUNLEN,
6682 sizeof(ahd->next_queued_hscb->pkt_long_lun) - 1);
6684 ahd_outb(ahd, LUNLEN, LUNLEN_SINGLE_LEVEL_LUN);
6686 ahd_outb(ahd, CDBLIMIT, SCB_CDB_LEN_PTR - 1);
6687 ahd_outb(ahd, MAXCMD, 0xFF);
6688 ahd_outb(ahd, SCBAUTOPTR,
6692 ahd_outb(ahd, MULTARGID, 0);
6693 ahd_outb(ahd, MULTARGID + 1, 0);
6695 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
6697 if ((ahd->features & AHD_NEW_IOCELL_OPTS) == 0) {
6703 ahd_outb(ahd, NEGOADDR, target);
6704 ahd_outb(ahd, ANNEXCOL, AHD_ANNEXCOL_PER_DEV0);
6706 ahd_outb(ahd, ANNEXDAT, 0);
6714 tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
6716 ahd_compile_devinfo(&devinfo, ahd->our_id,
6719 ahd_update_neg_table(ahd, &devinfo, &tinfo->curr);
6722 ahd_outb(ahd, CLRSINT3, NTRAMPERR|OSRAMPERR);
6723 ahd_outb(ahd, CLRINT, CLRSCSIINT);
6730 if ((ahd->bugs & AHD_ABORT_LQI_BUG) == 0)
6731 ahd_outb(ahd, LQCTL1, ABORTPENDING);
6734 ahd_outb(ahd, LQCTL1, 0);
6737 ahd->qoutfifonext = 0;
6738 ahd->qoutfifonext_valid_tag = QOUTFIFO_ENTRY_VALID;
6739 ahd_outb(ahd, QOUTFIFO_ENTRY_VALID_TAG, QOUTFIFO_ENTRY_VALID);
6741 ahd->qoutfifo[i].valid_tag = 0;
6742 ahd_sync_qoutfifo(ahd, BUS_DMASYNC_PREREAD);
6744 ahd->qinfifonext = 0;
6746 ahd->qinfifo[i] = SCB_LIST_NULL;
6748 if ((ahd->features & AHD_TARGETMODE) != 0) {
6751 ahd->targetcmds[i].cmd_valid = 0;
6752 ahd_sync_tqinfifo(ahd, BUS_DMASYNC_PREREAD);
6753 ahd->tqinfifonext = 1;
6754 ahd_outb(ahd, KERNEL_TQINPOS, ahd->tqinfifonext - 1);
6755 ahd_outb(ahd, TQINPOS, ahd->tqinfifonext);
6759 ahd_outb(ahd, SEQ_FLAGS, 0);
6760 ahd_outb(ahd, SEQ_FLAGS2, 0);
6763 ahd_outw(ahd, WAITING_TID_HEAD, SCB_LIST_NULL);
6764 ahd_outw(ahd, WAITING_TID_TAIL, SCB_LIST_NULL);
6765 ahd_outw(ahd, MK_MESSAGE_SCB, SCB_LIST_NULL);
6766 ahd_outw(ahd, MK_MESSAGE_SCSIID, 0xFF);
6768 ahd_outw(ahd, WAITING_SCB_TAILS + (2 * i), SCB_LIST_NULL);
6773 ahd_outw(ahd, COMPLETE_SCB_HEAD, SCB_LIST_NULL);
6774 ahd_outw(ahd, COMPLETE_SCB_DMAINPROG_HEAD, SCB_LIST_NULL);
6775 ahd_outw(ahd, COMPLETE_DMA_SCB_HEAD, SCB_LIST_NULL);
6776 ahd_outw(ahd, COMPLETE_DMA_SCB_TAIL, SCB_LIST_NULL);
6777 ahd_outw(ahd, COMPLETE_ON_QFREEZE_HEAD, SCB_LIST_NULL);
6782 ahd->qfreeze_cnt = 0;
6783 ahd_outw(ahd, QFREEZE_COUNT, 0);
6784 ahd_outw(ahd, KERNEL_QFREEZE_COUNT, 0);
6789 busaddr = ahd->shared_data_map.busaddr;
6790 ahd_outl(ahd, SHARED_DATA_ADDR, busaddr);
6791 ahd_outl(ahd, QOUTFIFO_NEXT_ADDR, busaddr);
6799 if ((ahd->flags & AHD_INITIATORROLE) != 0)
6801 ahd_outb(ahd, SCSISEQ_TEMPLATE, scsiseq_template);
6808 ahd_unbusy_tcl(ahd, BUILD_TCL_RAW(target, 'A', lun));
6817 ahd_outb(ahd, CMDSIZE_TABLE, 5);
6818 ahd_outb(ahd, CMDSIZE_TABLE + 1, 9);
6819 ahd_outb(ahd, CMDSIZE_TABLE + 2, 9);
6820 ahd_outb(ahd, CMDSIZE_TABLE + 3, 0);
6821 ahd_outb(ahd, CMDSIZE_TABLE + 4, 15);
6822 ahd_outb(ahd, CMDSIZE_TABLE + 5, 11);
6823 ahd_outb(ahd, CMDSIZE_TABLE + 6, 0);
6824 ahd_outb(ahd, CMDSIZE_TABLE + 7, 0);
6827 ahd_set_modes(ahd, AHD_MODE_CCHAN, AHD_MODE_CCHAN);
6828 ahd_outb(ahd, QOFF_CTLSTA, SCB_QSIZE_512);
6829 ahd->qinfifonext = 0;
6830 ahd_set_hnscb_qoff(ahd, ahd->qinfifonext);
6831 ahd_set_hescb_qoff(ahd, 0);
6832 ahd_set_snscb_qoff(ahd, 0);
6833 ahd_set_sescb_qoff(ahd, 0);
6834 ahd_set_sdscb_qoff(ahd, 0);
6839 busaddr = aic_le32toh(ahd->next_queued_hscb->hscb_busaddr);
6840 ahd_outl(ahd, NEXT_QUEUED_SCB_ADDR, busaddr);
6845 ahd_outw(ahd, INT_COALESCING_CMDCOUNT, 0);
6846 ahd_outw(ahd, CMDS_PENDING, 0);
6847 ahd_update_coalescing_values(ahd, ahd->int_coalescing_timer,
6848 ahd->int_coalescing_maxcmds,
6849 ahd->int_coalescing_mincmds);
6850 ahd_enable_coalescing(ahd, FALSE);
6852 ahd_loadseq(ahd);
6853 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
6862 ahd_default_config(struct ahd_softc *ahd)
6866 ahd->our_id = 7;
6873 if (ahd_alloc_tstate(ahd, ahd->our_id, 'A') == NULL) {
6875 "Failing attach\n", ahd_name(ahd));
6876 AHD_FATAL_ERROR(ahd);
6886 tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
6895 ahd->user_discenable |= target_mask;
6897 ahd->user_tagenable |= target_mask;
6910 if ((ahd->features & AHD_RTI) != 0)
6923 ahd_compile_devinfo(&devinfo, ahd->our_id,
6927 ahd_set_width(ahd, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
6929 ahd_set_syncrate(ahd, &devinfo, /*period*/0, /*offset*/0,
6940 ahd_parse_cfgdata(struct ahd_softc *ahd, struct seeprom_config *sc)
6946 ahd->our_id = sc->brtime_id & CFSCSIID;
6953 if (ahd_alloc_tstate(ahd, ahd->our_id, 'A') == NULL) {
6955 "Failing attach\n", ahd_name(ahd));
6956 AHD_FATAL_ERROR(ahd);
6967 tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
6978 ahd->user_discenable &= ~target_mask;
6980 ahd->user_tagenable &= ~target_mask;
6983 ahd->user_discenable |= target_mask;
6984 ahd->user_tagenable |= target_mask;
7012 if ((ahd->features & AHD_RTI) != 0)
7038 ahd_compile_devinfo(&devinfo, ahd->our_id,
7041 ahd_set_width(ahd, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
7043 ahd_set_syncrate(ahd, &devinfo, /*period*/0, /*offset*/0,
7048 ahd->flags &= ~AHD_SPCHK_ENB_A;
7050 ahd->flags |= AHD_SPCHK_ENB_A;
7052 ahd->flags &= ~AHD_RESET_BUS_A;
7054 ahd->flags |= AHD_RESET_BUS_A;
7056 ahd->flags &= ~AHD_EXTENDED_TRANS_A;
7058 ahd->flags |= AHD_EXTENDED_TRANS_A;
7060 ahd->flags &= ~AHD_BIOS_ENABLED;
7062 ahd->flags |= AHD_BIOS_ENABLED;
7064 ahd->flags &= ~AHD_STPWLEVEL_A;
7066 ahd->flags |= AHD_STPWLEVEL_A;
7075 ahd_parse_vpddata(struct ahd_softc *ahd, struct vpd_config *vpd)
7083 ahd->flags |= AHD_BOOT_CHANNEL;
7088 ahd_intr_enable(struct ahd_softc *ahd, int enable)
7092 hcntrl = ahd_inb(ahd, HCNTRL);
7094 ahd->pause &= ~INTEN;
7095 ahd->unpause &= ~INTEN;
7098 ahd->pause |= INTEN;
7099 ahd->unpause |= INTEN;
7101 ahd_outb(ahd, HCNTRL, hcntrl);
7105 ahd_update_coalescing_values(struct ahd_softc *ahd, u_int timer, u_int maxcmds,
7110 ahd->int_coalescing_timer = timer;
7116 ahd->int_coalescing_maxcmds = maxcmds;
7117 ahd_outw(ahd, INT_COALESCING_TIMER, timer / AHD_TIMER_US_PER_TICK);
7118 ahd_outb(ahd, INT_COALESCING_MAXCMDS, -maxcmds);
7119 ahd_outb(ahd, INT_COALESCING_MINCMDS, -mincmds);
7123 ahd_enable_coalescing(struct ahd_softc *ahd, int enable)
7126 ahd->hs_mailbox &= ~ENINT_COALESCE;
7128 ahd->hs_mailbox |= ENINT_COALESCE;
7129 ahd_outb(ahd, HS_MAILBOX, ahd->hs_mailbox);
7130 ahd_flush_device_writes(ahd);
7131 ahd_run_qoutfifo(ahd);
7142 ahd_pause_and_flushwork(struct ahd_softc *ahd)
7148 ahd->flags |= AHD_ALL_INTERRUPTS;
7149 ahd_pause(ahd);
7155 ahd->qfreeze_cnt--;
7156 ahd_outw(ahd, KERNEL_QFREEZE_COUNT, ahd->qfreeze_cnt);
7157 ahd_outb(ahd, SEQ_FLAGS2, ahd_inb(ahd, SEQ_FLAGS2) | SELECTOUT_QFROZEN);
7160 ahd_unpause(ahd);
7167 ahd_intr(ahd);
7168 ahd_pause(ahd);
7169 intstat = ahd_inb(ahd, INTSTAT);
7171 ahd_clear_critical_section(ahd);
7172 intstat = ahd_inb(ahd, INTSTAT);
7175 && (intstat != 0xFF || (ahd->features & AHD_REMOVABLE) == 0)
7177 || (ahd_inb(ahd, SCSISEQ0) & ENSELO) != 0
7178 || (ahd_inb(ahd, SSTAT0) & (SELDO|SELINGO)) != 0));
7182 ahd_inb(ahd, INTSTAT));
7183 AHD_FATAL_ERROR(ahd);
7185 ahd->qfreeze_cnt++;
7186 ahd_outw(ahd, KERNEL_QFREEZE_COUNT, ahd->qfreeze_cnt);
7188 ahd_flush_qoutfifo(ahd);
7190 ahd_platform_flushwork(ahd);
7191 ahd->flags &= ~AHD_ALL_INTERRUPTS;
7195 ahd_suspend(struct ahd_softc *ahd)
7198 ahd_pause_and_flushwork(ahd);
7200 if (LIST_FIRST(&ahd->pending_scbs) != NULL) {
7201 ahd_unpause(ahd);
7204 ahd_shutdown(ahd);
7209 ahd_resume(struct ahd_softc *ahd)
7212 ahd_reset(ahd, /*reinit*/TRUE);
7213 ahd_intr_enable(ahd, TRUE);
7214 ahd_restart(ahd);
7228 ahd_index_busy_tcl(struct ahd_softc *ahd, u_int *saved_scbid, u_int tcl)
7233 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
7234 *saved_scbid = ahd_get_scbptr(ahd);
7235 ahd_set_scbptr(ahd, TCL_LUN(tcl)
7250 ahd_find_busy_tcl(struct ahd_softc *ahd, u_int tcl)
7256 scb_offset = ahd_index_busy_tcl(ahd, &saved_scbptr, tcl);
7257 scbid = ahd_inw_scbram(ahd, scb_offset);
7258 ahd_set_scbptr(ahd, saved_scbptr);
7263 ahd_busy_tcl(struct ahd_softc *ahd, u_int tcl, u_int scbid)
7268 scb_offset = ahd_index_busy_tcl(ahd, &saved_scbptr, tcl);
7269 ahd_outw(ahd, scb_offset, scbid);
7270 ahd_set_scbptr(ahd, saved_scbptr);
7275 ahd_match_scb(struct ahd_softc *ahd, struct scb *scb, int target,
7278 int targ = SCB_GET_TARGET(ahd, scb);
7279 char chan = SCB_GET_CHANNEL(ahd, scb);
7311 ahd_freeze_devq(struct ahd_softc *ahd, struct scb *scb)
7317 target = SCB_GET_TARGET(ahd, scb);
7319 channel = SCB_GET_CHANNEL(ahd, scb);
7321 ahd_search_qinfifo(ahd, target, channel, lun,
7325 ahd_platform_freeze_devq(ahd, scb);
7329 ahd_qinfifo_requeue_tail(struct ahd_softc *ahd, struct scb *scb)
7334 saved_modes = ahd_save_modes(ahd);
7335 ahd_set_modes(ahd, AHD_MODE_CCHAN, AHD_MODE_CCHAN);
7337 if (ahd_qinfifo_count(ahd) != 0) {
7341 prev_pos = AHD_QIN_WRAP(ahd->qinfifonext - 1);
7342 prev_tag = ahd->qinfifo[prev_pos];
7343 prev_scb = ahd_lookup_scb(ahd, prev_tag);
7345 ahd_qinfifo_requeue(ahd, prev_scb, scb);
7346 ahd_set_hnscb_qoff(ahd, ahd->qinfifonext);
7347 ahd_restore_modes(ahd, saved_modes);
7351 ahd_qinfifo_requeue(struct ahd_softc *ahd, struct scb *prev_scb,
7358 ahd_outl(ahd, NEXT_QUEUED_SCB_ADDR, busaddr);
7361 ahd_sync_scb(ahd, prev_scb,
7364 ahd->qinfifo[AHD_QIN_WRAP(ahd->qinfifonext)] = SCB_GET_TAG(scb);
7365 ahd->qinfifonext++;
7366 scb->hscb->next_hscb_busaddr = ahd->next_queued_hscb->hscb_busaddr;
7367 ahd_sync_scb(ahd, scb, BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
7371 ahd_qinfifo_count(struct ahd_softc *ahd)
7377 AHD_ASSERT_MODES(ahd, AHD_MODE_CCHAN_MSK, AHD_MODE_CCHAN_MSK);
7378 qinpos = ahd_get_snscb_qoff(ahd);
7380 wrap_qinfifonext = AHD_QIN_WRAP(ahd->qinfifonext);
7385 + NUM_ELEMENTS(ahd->qinfifo) - wrap_qinpos);
7389 ahd_reset_cmds_pending(struct ahd_softc *ahd)
7395 saved_modes = ahd_save_modes(ahd);
7396 ahd_set_modes(ahd, AHD_MODE_CCHAN, AHD_MODE_CCHAN);
7402 ahd_flush_qoutfifo(ahd);
7405 LIST_FOREACH(scb, &ahd->pending_scbs, pending_links) {
7408 ahd_outw(ahd, CMDS_PENDING, pending_cmds - ahd_qinfifo_count(ahd));
7409 ahd_restore_modes(ahd, saved_modes);
7410 ahd->flags &= ~AHD_UPDATE_PEND_CMDS;
7414 ahd_done_with_status(struct ahd_softc *ahd, struct scb *scb, uint32_t status)
7425 ahd_done(ahd, scb);
7429 ahd_search_qinfifo(struct ahd_softc *ahd, int target, char channel,
7450 saved_modes = ahd_save_modes(ahd);
7451 ahd_set_modes(ahd, AHD_MODE_CCHAN, AHD_MODE_CCHAN);
7457 if ((ahd_inb(ahd, CCSCBCTL) & (CCARREN|CCSCBEN|CCSCBDIR))
7459 ahd_outb(ahd, CCSCBCTL,
7460 ahd_inb(ahd, CCSCBCTL) & ~(CCARREN|CCSCBEN));
7461 while ((ahd_inb(ahd, CCSCBCTL) & (CCARREN|CCSCBEN)) != 0)
7465 qintail = AHD_QIN_WRAP(ahd->qinfifonext);
7466 qinstart = ahd_get_snscb_qoff(ahd);
7473 qinstart, ahd->qinfifonext);
7480 ahd->qinfifonext = qinstart;
7481 busaddr = aic_le32toh(ahd->next_queued_hscb->hscb_busaddr);
7482 ahd_outl(ahd, NEXT_QUEUED_SCB_ADDR, busaddr);
7485 scb = ahd_lookup_scb(ahd, ahd->qinfifo[qinpos]);
7488 qinpos, ahd->qinfifo[qinpos]);
7489 AHD_FATAL_ERROR(ahd);
7493 if (ahd_match_scb(ahd, scb, target, channel, lun, tag, role)) {
7502 ahd_done_with_status(ahd, scb, status);
7507 printf(" 0x%x", ahd->qinfifo[qinpos]);
7510 ahd_qinfifo_requeue(ahd, prev_scb, scb);
7515 ahd_qinfifo_requeue(ahd, prev_scb, scb);
7521 ahd_set_hnscb_qoff(ahd, ahd->qinfifonext);
7532 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
7533 seq_flags2 = ahd_inb(ahd, SEQ_FLAGS2);
7535 scbid = ahd_inw(ahd, MK_MESSAGE_SCB);
7536 mk_msg_scb = ahd_lookup_scb(ahd, scbid);
7539 savedscbptr = ahd_get_scbptr(ahd);
7540 tid_next = ahd_inw(ahd, WAITING_TID_HEAD);
7551 if (scbid >= ahd->scb_data.numscbs) {
7554 ahd_name(ahd), scbid, ahd->scb_data.numscbs);
7555 ahd_dump_card_state(ahd);
7558 scb = ahd_lookup_scb(ahd, scbid);
7561 ahd_name(ahd), scbid);
7564 ahd_set_scbptr(ahd, scbid);
7565 tid_next = ahd_inw_scbram(ahd, SCB_NEXT2);
7566 if (ahd_match_scb(ahd, scb, target, channel, CAM_LUN_WILDCARD,
7576 printf(" %d ( ", SCB_GET_TARGET(ahd, scb));
7578 found += ahd_search_scb_list(ahd, target, channel,
7581 SCB_GET_TARGET(ahd, scb));
7587 && ahd_match_scb(ahd, mk_msg_scb, target, channel,
7598 ahd_done_with_status(ahd, mk_msg_scb, status);
7611 + (2 * SCB_GET_TARGET(ahd, mk_msg_scb));
7612 ahd_outw(ahd, tail_offset, tid_tail);
7615 ahd_outb(ahd, SEQ_FLAGS2, seq_flags2);
7616 ahd_outw(ahd, CMDS_PENDING,
7617 ahd_inw(ahd, CMDS_PENDING)-1);
7631 && ahd_match_scb(ahd, scb, target, channel, CAM_LUN_WILDCARD,
7640 tid_head = ahd_inw(ahd, MK_MESSAGE_SCB);
7642 ahd_outb(ahd, SEQ_FLAGS2, seq_flags2);
7646 ahd_stitch_tid_list(ahd, tid_prev, tid_head, tid_next);
7654 ahd_set_scbptr(ahd, savedscbptr);
7655 ahd_restore_modes(ahd, saved_modes);
7660 ahd_search_scb_list(struct ahd_softc *ahd, int target, char channel,
7671 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
7677 if (scbid >= ahd->scb_data.numscbs) {
7680 ahd_name(ahd), scbid, ahd->scb_data.numscbs);
7681 ahd_dump_card_state(ahd);
7684 scb = ahd_lookup_scb(ahd, scbid);
7687 ahd_name(ahd), scbid);
7690 ahd_set_scbptr(ahd, scbid);
7692 next = ahd_inw_scbram(ahd, SCB_NEXT);
7693 if (ahd_match_scb(ahd, scb, target, channel,
7703 ahd_done_with_status(ahd, scb, status);
7706 ahd_rem_wscb(ahd, scbid, prev, next, tid);
7722 ahd_outw(ahd, CMDS_PENDING, ahd_inw(ahd, CMDS_PENDING) - found);
7727 ahd_stitch_tid_list(struct ahd_softc *ahd, u_int tid_prev,
7730 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
7736 ahd_outw(ahd, WAITING_TID_HEAD, tid_next);
7738 ahd_set_scbptr(ahd, tid_prev);
7739 ahd_outw(ahd, SCB_NEXT2, tid_next);
7742 ahd_outw(ahd, WAITING_TID_TAIL, tid_prev);
7747 ahd_outw(ahd, WAITING_TID_HEAD, tid_cur);
7749 ahd_set_scbptr(ahd, tid_prev);
7750 ahd_outw(ahd, SCB_NEXT2, tid_cur);
7752 ahd_set_scbptr(ahd, tid_cur);
7753 ahd_outw(ahd, SCB_NEXT2, tid_next);
7756 ahd_outw(ahd, WAITING_TID_TAIL, tid_cur);
7765 ahd_rem_wscb(struct ahd_softc *ahd, u_int scbid,
7770 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
7772 ahd_set_scbptr(ahd, prev);
7773 ahd_outw(ahd, SCB_NEXT, next);
7785 && ahd_inw(ahd, tail_offset) == scbid)
7786 ahd_outw(ahd, tail_offset, prev);
7788 ahd_add_scb_to_free_list(ahd, scbid);
7798 ahd_add_scb_to_free_list(struct ahd_softc *ahd, u_int scbid)
7804 ahd_outb(ahd, SCB_TAG, SCB_LIST_NULL);
7816 ahd_abort_scbs(struct ahd_softc *ahd, int target, char channel,
7829 saved_modes = ahd_save_modes(ahd);
7830 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
7832 found = ahd_search_qinfifo(ahd, target, channel, lun, SCB_LIST_NULL,
7864 scbid = ahd_find_busy_tcl(ahd, tcl);
7865 scbp = ahd_lookup_scb(ahd, scbid);
7867 || ahd_match_scb(ahd, scbp, target, channel,
7870 ahd_unbusy_tcl(ahd, BUILD_TCL_RAW(i, 'A', j));
7879 ahd_flush_qoutfifo(ahd);
7887 scbp_next = LIST_FIRST(&ahd->pending_scbs);
7891 if (ahd_match_scb(ahd, scbp, target, channel, lun, tag, role)) {
7901 ahd_done(ahd, scbp);
7905 ahd_restore_modes(ahd, saved_modes);
7906 ahd_platform_abort_scbs(ahd, target, channel, lun, tag, role, status);
7907 ahd->flags |= AHD_UPDATE_PEND_CMDS;
7912 ahd_reset_current_bus(struct ahd_softc *ahd)
7916 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
7917 ahd_outb(ahd, SIMODE1, ahd_inb(ahd, SIMODE1) & ~ENSCSIRST);
7918 scsiseq = ahd_inb(ahd, SCSISEQ0) & ~(ENSELO|ENARBO|SCSIRSTO);
7919 ahd_outb(ahd, SCSISEQ0, scsiseq | SCSIRSTO);
7920 ahd_flush_device_writes(ahd);
7923 ahd_outb(ahd, SCSISEQ0, scsiseq);
7924 ahd_flush_device_writes(ahd);
7926 if ((ahd->bugs & AHD_SCSIRST_BUG) != 0) {
7933 ahd_reset(ahd, /*reinit*/TRUE);
7934 ahd_intr_enable(ahd, /*enable*/TRUE);
7935 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
7938 ahd_clear_intstat(ahd);
7942 ahd_reset_channel(struct ahd_softc *ahd, char channel, int initiate_reset)
7952 ahd->pending_device = NULL;
7959 ahd_pause(ahd);
7962 ahd_clear_critical_section(ahd);
7965 if ((ahd->flags & AHD_TARGETROLE) != 0) {
7966 ahd_run_tqinfifo(ahd, /*paused*/TRUE);
7969 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
7975 ahd_outb(ahd, SCSISEQ0, 0);
7976 ahd_outb(ahd, SCSISEQ1, 0);
7983 next_fifo = fifo = ahd_inb(ahd, DFFSTAT) & CURRFIFO;
7989 ahd_set_modes(ahd, next_fifo, next_fifo);
7990 ahd_outb(ahd, DFCNTRL,
7991 ahd_inb(ahd, DFCNTRL) & ~(SCSIEN|HDMAEN));
7992 while ((ahd_inb(ahd, DFCNTRL) & HDMAENACK) != 0)
7997 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
7998 ahd_outb(ahd, DFFSTAT, next_fifo);
8004 ahd_clear_msg_state(ahd);
8005 ahd_outb(ahd, SIMODE1,
8006 ahd_inb(ahd, SIMODE1) & ~(ENBUSFREE|ENSCSIRST));
8009 ahd_reset_current_bus(ahd);
8011 ahd_clear_intstat(ahd);
8017 found = ahd_abort_scbs(ahd, CAM_TARGET_WILDCARD, channel,
8024 ahd_clear_fifo(ahd, 0);
8025 ahd_clear_fifo(ahd, 1);
8030 max_scsiid = (ahd->features & AHD_WIDE) ? 15 : 7;
8033 if (ahd->enabled_targets[target] == NULL)
8041 ahd_set_width(ahd, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
8043 ahd_set_syncrate(ahd, &devinfo, /*period*/0,
8050 max_scsiid = (ahd->features & AHD_WIDE) ? 15 : 7;
8060 tstate = ahd->enabled_targets[target];
8070 ahd_queue_lstate_event(ahd, lstate, CAM_TARGET_WILDCARD,
8072 ahd_send_lstate_events(ahd, lstate);
8077 ahd_send_async(ahd, devinfo.channel, CAM_TARGET_WILDCARD,
8079 ahd_restart(ahd);
8086 if ((ahd->flags & AHD_RESET_POLL_ACTIVE) == 0) {
8087 ahd->flags |= AHD_RESET_POLL_ACTIVE;
8088 aic_freeze_simq(ahd);
8089 aic_timer_reset(&ahd->reset_timer, 0, ahd_reset_poll, ahd);
8099 struct ahd_softc *ahd = (struct ahd_softc *)arg;
8102 ahd_lock(ahd);
8103 ahd_pause(ahd);
8104 ahd_update_modes(ahd);
8105 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
8106 ahd_outb(ahd, CLRSINT1, CLRSCSIRSTI);
8107 if ((ahd_inb(ahd, SSTAT1) & SCSIRSTI) != 0) {
8108 aic_timer_reset(&ahd->reset_timer, AHD_RESET_POLL_MS,
8109 ahd_reset_poll, ahd);
8110 ahd_unpause(ahd);
8111 ahd_unlock(ahd);
8116 ahd_outb(ahd, SIMODE1, ahd_inb(ahd, SIMODE1) | ENSCSIRST);
8117 scsiseq1 = ahd_inb(ahd, SCSISEQ_TEMPLATE);
8118 ahd_outb(ahd, SCSISEQ1, scsiseq1 & (ENSELI|ENRSELI|ENAUTOATNP));
8119 ahd_unpause(ahd);
8120 ahd->flags &= ~AHD_RESET_POLL_ACTIVE;
8121 aic_release_simq(ahd);
8122 ahd_unlock(ahd);
8129 struct ahd_softc *ahd = (struct ahd_softc *)arg;
8132 ahd_lock(ahd);
8133 enint_coal = ahd->hs_mailbox & ENINT_COALESCE;
8134 if (ahd->cmdcmplt_total > ahd->int_coalescing_threshold)
8136 else if (ahd->cmdcmplt_total < ahd->int_coalescing_stop_threshold)
8139 if (enint_coal != (ahd->hs_mailbox & ENINT_COALESCE)) {
8140 ahd_enable_coalescing(ahd, enint_coal);
8145 ahd_name(ahd),
8147 ahd->cmdcmplt_total);
8151 ahd->cmdcmplt_bucket = (ahd->cmdcmplt_bucket+1) & (AHD_STAT_BUCKETS-1);
8152 ahd->cmdcmplt_total -= ahd->cmdcmplt_counts[ahd->cmdcmplt_bucket];
8153 ahd->cmdcmplt_counts[ahd->cmdcmplt_bucket] = 0;
8154 aic_timer_reset(&ahd->stat_timer, AHD_STAT_UPDATE_MS,
8155 ahd_stat_timer, ahd);
8156 ahd_unlock(ahd);
8161 ahd_handle_scb_status(struct ahd_softc *ahd, struct scb *scb)
8164 ahd_handle_scsi_status(ahd, scb);
8166 ahd_calc_residual(ahd, scb);
8167 ahd_done(ahd, scb);
8172 ahd_handle_scsi_status(struct ahd_softc *ahd, struct scb *scb)
8188 if (ahd_is_paused(ahd)) {
8192 ahd_pause(ahd);
8196 ahd_freeze_devq(ahd, scb);
8198 ahd->qfreeze_cnt++;
8199 ahd_outw(ahd, KERNEL_QFREEZE_COUNT, ahd->qfreeze_cnt);
8202 ahd_unpause(ahd);
8212 ahd_done(ahd, scb);
8222 ahd_sync_sense(ahd, scb, BUS_DMASYNC_POSTREAD);
8227 ahd_print_path(ahd, scb);
8237 ahd_print_path(ahd, scb);
8245 AHD_UNCORRECTABLE_ERROR(ahd);
8249 AHD_UNCORRECTABLE_ERROR(ahd);
8253 AHD_UNCORRECTABLE_ERROR(ahd);
8257 AHD_UNCORRECTABLE_ERROR(ahd);
8261 AHD_UNCORRECTABLE_ERROR(ahd);
8264 AHD_UNCORRECTABLE_ERROR(ahd);
8281 ahd_done(ahd, scb);
8295 ahd_print_path(ahd, scb);
8305 SCB_GET_TARGET(ahd, scb),
8307 SCB_GET_CHANNEL(ahd, scb),
8309 targ_info = ahd_fetch_transinfo(ahd,
8320 ahd_update_residual(ahd, scb);
8323 ahd_print_path(ahd, scb);
8328 sg = ahd_sg_setup(ahd, scb, sg, ahd_get_sense_bufaddr(ahd, scb),
8329 aic_get_sense_bufsize(ahd, scb),
8338 sc->length = aic_get_sense_bufsize(ahd, scb);
8359 ahd_update_neg_request(ahd, &devinfo,
8370 ahd_setup_data_scb(ahd, scb);
8372 ahd_queue_scb(ahd, scb);
8380 if (ahd->scb_data.recovery_scbs == 0
8387 ahd_name(ahd));
8390 ahd_done(ahd, scb);
8399 ahd_calc_residual(struct ahd_softc *ahd, struct scb *scb)
8449 ahd_print_path(ahd, scb);
8452 ahd_freeze_devq(ahd, scb);
8467 sg = ahd_sg_bus_to_virt(ahd, scb, resid_sgptr & SG_PTR_MASK);
8489 ahd_print_path(ahd, scb);
8502 ahd_queue_lstate_event(struct ahd_softc *ahd, struct ahd_tmode_lstate *lstate,
8553 ahd_send_lstate_events(struct ahd_softc *ahd, struct ahd_tmode_lstate *lstate)
8588 ahd_dumpseq(struct ahd_softc* ahd)
8595 ahd_outb(ahd, SEQCTL0, PERRORDIS|FAILDIS|FASTMODE|LOADRAM);
8596 ahd_outw(ahd, PRGMCNT, 0);
8600 ahd_insb(ahd, SEQRAM, ins_bytes, 4);
8610 ahd_loadseq(struct ahd_softc *ahd)
8630 ahd_name(ahd));
8662 sg_prefetch_align = ahd->pci_cachesize;
8685 if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0)
8709 (ahd->overrun_buf - (uint8_t *)ahd->qoutfifo) / 256;
8715 ahd_outb(ahd, SEQCTL0, PERRORDIS|FAILDIS|FASTMODE|LOADRAM);
8716 ahd_outw(ahd, PRGMCNT, 0);
8719 if (ahd_check_patch(ahd, &cur_patch, i, &skip_addr) == 0) {
8747 ahd_download_instr(ahd, i, download_consts);
8751 ahd->num_critical_sections = cs_count;
8755 ahd->critical_sections = malloc(cs_count, M_DEVBUF, M_NOWAIT);
8756 if (ahd->critical_sections == NULL)
8758 memcpy(ahd->critical_sections, cs_table, cs_count);
8760 ahd_outb(ahd, SEQCTL0, PERRORDIS|FAILDIS|FASTMODE);
8765 ahd_name(ahd), ahd->features, ahd->bugs, ahd->flags);
8770 ahd_check_patch(struct ahd_softc *ahd, struct patch **start_patch,
8783 if (cur_patch->patch_func(ahd) == 0) {
8806 ahd_resolve_seqaddr(struct ahd_softc *ahd, u_int address)
8819 ahd_check_patch(ahd, &cur_patch, i, &skip_addr);
8835 ahd_download_instr(struct ahd_softc *ahd, u_int instrptr, uint8_t *dconsts)
8863 fmt3_ins->address = ahd_resolve_seqaddr(ahd, fmt3_ins->address);
8894 ahd_outsb(ahd, SEQRAM, instr.bytes, 4);
8904 ahd_probe_stack_size(struct ahd_softc *ahd)
8919 ahd_outb(ahd, STACK, i & 0xFF);
8920 ahd_outb(ahd, STACK, (i >> 8) & 0xFF);
8927 stack_entry = ahd_inb(ahd, STACK)
8928 |(ahd_inb(ahd, STACK) << 8);
9002 ahd_dump_card_state(struct ahd_softc *ahd)
9013 if (ahd_is_paused(ahd)) {
9017 ahd_pause(ahd);
9019 saved_modes = ahd_save_modes(ahd);
9020 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
9023 ahd_name(ahd),
9024 ahd_inw(ahd, CURADDR),
9025 ahd_build_mode_state(ahd, ahd->saved_src_mode,
9026 ahd->saved_dst_mode));
9030 if (ahd_check_cmdcmpltqueues(ahd))
9037 ahd_intstat_print(ahd_inb(ahd, INTSTAT), &cur_col, 50);
9038 ahd_seloid_print(ahd_inb(ahd, SELOID), &cur_col, 50);
9039 ahd_selid_print(ahd_inb(ahd, SELID), &cur_col, 50);
9040 ahd_hs_mailbox_print(ahd_inb(ahd, LOCAL_HS_MAILBOX), &cur_col, 50);
9041 ahd_intctl_print(ahd_inb(ahd, INTCTL), &cur_col, 50);
9042 ahd_seqintstat_print(ahd_inb(ahd, SEQINTSTAT), &cur_col, 50);
9043 ahd_saved_mode_print(ahd_inb(ahd, SAVED_MODE), &cur_col, 50);
9044 ahd_dffstat_print(ahd_inb(ahd, DFFSTAT), &cur_col, 50);
9045 ahd_scsisigi_print(ahd_inb(ahd, SCSISIGI), &cur_col, 50);
9046 ahd_scsiphase_print(ahd_inb(ahd, SCSIPHASE), &cur_col, 50);
9047 ahd_scsibus_print(ahd_inb(ahd, SCSIBUS), &cur_col, 50);
9048 ahd_lastphase_print(ahd_inb(ahd, LASTPHASE), &cur_col, 50);
9049 ahd_scsiseq0_print(ahd_inb(ahd, SCSISEQ0), &cur_col, 50);
9050 ahd_scsiseq1_print(ahd_inb(ahd, SCSISEQ1), &cur_col, 50);
9051 ahd_seqctl0_print(ahd_inb(ahd, SEQCTL0), &cur_col, 50);
9052 ahd_seqintctl_print(ahd_inb(ahd, SEQINTCTL), &cur_col, 50);
9053 ahd_seq_flags_print(ahd_inb(ahd, SEQ_FLAGS), &cur_col, 50);
9054 ahd_seq_flags2_print(ahd_inb(ahd, SEQ_FLAGS2), &cur_col, 50);
9055 ahd_qfreeze_count_print(ahd_inw(ahd, QFREEZE_COUNT), &cur_col, 50);
9056 ahd_kernel_qfreeze_count_print(ahd_inw(ahd, KERNEL_QFREEZE_COUNT),
9058 ahd_mk_message_scb_print(ahd_inw(ahd, MK_MESSAGE_SCB), &cur_col, 50);
9059 ahd_mk_message_scsiid_print(ahd_inb(ahd, MK_MESSAGE_SCSIID),
9061 ahd_sstat0_print(ahd_inb(ahd, SSTAT0), &cur_col, 50);
9062 ahd_sstat1_print(ahd_inb(ahd, SSTAT1), &cur_col, 50);
9063 ahd_sstat2_print(ahd_inb(ahd, SSTAT2), &cur_col, 50);
9064 ahd_sstat3_print(ahd_inb(ahd, SSTAT3), &cur_col, 50);
9065 ahd_perrdiag_print(ahd_inb(ahd, PERRDIAG), &cur_col, 50);
9066 ahd_simode1_print(ahd_inb(ahd, SIMODE1), &cur_col, 50);
9067 ahd_lqistat0_print(ahd_inb(ahd, LQISTAT0), &cur_col, 50);
9068 ahd_lqistat1_print(ahd_inb(ahd, LQISTAT1), &cur_col, 50);
9069 ahd_lqistat2_print(ahd_inb(ahd, LQISTAT2), &cur_col, 50);
9070 ahd_lqostat0_print(ahd_inb(ahd, LQOSTAT0), &cur_col, 50);
9071 ahd_lqostat1_print(ahd_inb(ahd, LQOSTAT1), &cur_col, 50);
9072 ahd_lqostat2_print(ahd_inb(ahd, LQOSTAT2), &cur_col, 50);
9076 ahd->scb_data.numscbs, ahd_inw(ahd, CMDS_PENDING),
9077 ahd_inw(ahd, LASTSCB), ahd_inw(ahd, CURRSCB),
9078 ahd_inw(ahd, NEXTSCB));
9081 ahd_search_qinfifo(ahd, CAM_TARGET_WILDCARD, ALL_CHANNELS,
9084 saved_scb_index = ahd_get_scbptr(ahd);
9087 LIST_FOREACH(scb, &ahd->pending_scbs, pending_links) {
9091 ahd_inb_scbram(ahd, SCB_FIFO_USE_COUNT));
9092 ahd_set_scbptr(ahd, SCB_GET_TAG(scb));
9093 ahd_scb_control_print(ahd_inb_scbram(ahd, SCB_CONTROL),
9095 ahd_scb_scsiid_print(ahd_inb_scbram(ahd, SCB_SCSIID),
9102 TAILQ_FOREACH(scb, &ahd->scb_data.free_scbs, links.tqe) {
9105 printf("\n COLIDX[%d]: ", AHD_GET_SCB_COL_IDX(ahd, scb));
9114 LIST_FOREACH(scb, &ahd->scb_data.any_dev_free_scb_list, links.le) {
9122 scb_index = ahd_inw(ahd, COMPLETE_SCB_DMAINPROG_HEAD);
9125 ahd_set_scbptr(ahd, scb_index);
9127 scb_index = ahd_inw_scbram(ahd, SCB_NEXT_COMPLETE);
9132 scb_index = ahd_inw(ahd, COMPLETE_SCB_HEAD);
9135 ahd_set_scbptr(ahd, scb_index);
9137 scb_index = ahd_inw_scbram(ahd, SCB_NEXT_COMPLETE);
9143 scb_index = ahd_inw(ahd, COMPLETE_DMA_SCB_HEAD);
9146 ahd_set_scbptr(ahd, scb_index);
9148 scb_index = ahd_inw_scbram(ahd, SCB_NEXT_COMPLETE);
9152 scb_index = ahd_inw(ahd, COMPLETE_ON_QFREEZE_HEAD);
9155 ahd_set_scbptr(ahd, scb_index);
9157 scb_index = ahd_inw_scbram(ahd, SCB_NEXT_COMPLETE);
9160 ahd_set_scbptr(ahd, saved_scb_index);
9161 dffstat = ahd_inb(ahd, DFFSTAT);
9168 ahd_set_modes(ahd, AHD_MODE_DFF0 + i, AHD_MODE_DFF0 + i);
9169 fifo_scbptr = ahd_get_scbptr(ahd);
9171 ahd_name(ahd), i,
9173 ahd_inw(ahd, LONGJMP_ADDR), fifo_scbptr);
9175 ahd_seqimode_print(ahd_inb(ahd, SEQIMODE), &cur_col, 50);
9176 ahd_seqintsrc_print(ahd_inb(ahd, SEQINTSRC), &cur_col, 50);
9177 ahd_dfcntrl_print(ahd_inb(ahd, DFCNTRL), &cur_col, 50);
9178 ahd_dfstatus_print(ahd_inb(ahd, DFSTATUS), &cur_col, 50);
9179 ahd_sg_cache_shadow_print(ahd_inb(ahd, SG_CACHE_SHADOW),
9181 ahd_sg_state_print(ahd_inb(ahd, SG_STATE), &cur_col, 50);
9182 ahd_dffsxfrctl_print(ahd_inb(ahd, DFFSXFRCTL), &cur_col, 50);
9183 ahd_soffcnt_print(ahd_inb(ahd, SOFFCNT), &cur_col, 50);
9184 ahd_mdffstat_print(ahd_inb(ahd, MDFFSTAT), &cur_col, 50);
9190 ahd_inl(ahd, SHADDR+4),
9191 ahd_inl(ahd, SHADDR),
9192 (ahd_inb(ahd, SHCNT)
9193 | (ahd_inb(ahd, SHCNT + 1) << 8)
9194 | (ahd_inb(ahd, SHCNT + 2) << 16)));
9200 ahd_inl(ahd, HADDR+4),
9201 ahd_inl(ahd, HADDR),
9202 (ahd_inb(ahd, HCNT)
9203 | (ahd_inb(ahd, HCNT + 1) << 8)
9204 | (ahd_inb(ahd, HCNT + 2) << 16)));
9205 ahd_ccsgctl_print(ahd_inb(ahd, CCSGCTL), &cur_col, 50);
9208 fifo_scb = ahd_lookup_scb(ahd, fifo_scbptr);
9216 printf("0x%x ", ahd_inb(ahd, LQIN + i));
9218 ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
9220 ahd_name(ahd), ahd_inb(ahd, LQISTATE), ahd_inb(ahd, LQOSTATE),
9221 ahd_inb(ahd, OPTIONMODE));
9223 ahd_name(ahd), ahd_inb(ahd, OS_SPACE_CNT),
9224 ahd_inb(ahd, MAXCMDCNT));
9226 ahd_name(ahd), ahd_inb(ahd, SAVED_SCSIID),
9227 ahd_inb(ahd, SAVED_LUN));
9228 ahd_simode0_print(ahd_inb(ahd, SIMODE0), &cur_col, 50);
9230 ahd_set_modes(ahd, AHD_MODE_CCHAN, AHD_MODE_CCHAN);
9232 ahd_ccscbctl_print(ahd_inb(ahd, CCSCBCTL), &cur_col, 50);
9234 ahd_set_modes(ahd, ahd->saved_src_mode, ahd->saved_dst_mode);
9236 ahd_name(ahd), ahd_inw(ahd, REG0), ahd_inw(ahd, SINDEX),
9237 ahd_inw(ahd, DINDEX));
9239 ahd_name(ahd), ahd_get_scbptr(ahd),
9240 ahd_inw_scbram(ahd, SCB_NEXT),
9241 ahd_inw_scbram(ahd, SCB_NEXT2));
9243 ahd_inb_scbram(ahd, SCB_CDB_STORE),
9244 ahd_inb_scbram(ahd, SCB_CDB_STORE+1),
9245 ahd_inb_scbram(ahd, SCB_CDB_STORE+2),
9246 ahd_inb_scbram(ahd, SCB_CDB_STORE+3),
9247 ahd_inb_scbram(ahd, SCB_CDB_STORE+4),
9248 ahd_inb_scbram(ahd, SCB_CDB_STORE+5));
9250 for (i = 0; i < ahd->stack_size; i++) {
9251 ahd->saved_stack[i] =
9252 ahd_inb(ahd, STACK)|(ahd_inb(ahd, STACK) << 8);
9253 printf(" 0x%x", ahd->saved_stack[i]);
9255 for (i = ahd->stack_size-1; i >= 0; i--) {
9256 ahd_outb(ahd, STACK, ahd->saved_stack[i] & 0xFF);
9257 ahd_outb(ahd, STACK, (ahd->saved_stack[i] >> 8) & 0xFF);
9260 ahd_platform_dump_card_state(ahd);
9261 ahd_restore_modes(ahd, saved_modes);
9263 ahd_unpause(ahd);
9267 ahd_dump_scbs(struct ahd_softc *ahd)
9273 saved_modes = ahd_save_modes(ahd);
9274 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
9275 saved_scb_index = ahd_get_scbptr(ahd);
9277 ahd_set_scbptr(ahd, i);
9280 ahd_inb_scbram(ahd, SCB_CONTROL),
9281 ahd_inb_scbram(ahd, SCB_SCSIID),
9282 ahd_inw_scbram(ahd, SCB_NEXT),
9283 ahd_inw_scbram(ahd, SCB_NEXT2),
9284 ahd_inl_scbram(ahd, SCB_SGPTR),
9285 ahd_inl_scbram(ahd, SCB_RESIDUAL_SGPTR));
9288 ahd_set_scbptr(ahd, saved_scb_index);
9289 ahd_restore_modes(ahd, saved_modes);
9297 struct ahd_softc *ahd;
9299 ahd = scb->ahd_softc;
9302 LIST_INSERT_HEAD(&ahd->timedout_scbs, scb,
9306 ahd_wakeup_recovery_thread(ahd);
9318 ahd_recover_commands(struct ahd_softc *ahd)
9332 was_paused = ahd_is_paused(ahd);
9334 printf("%s: Recovery Initiated - Card was %spaused\n", ahd_name(ahd),
9336 AHD_CORRECTABLE_ERROR(ahd);
9337 ahd_dump_card_state(ahd);
9339 ahd_pause_and_flushwork(ahd);
9341 if (LIST_EMPTY(&ahd->timedout_scbs) != 0) {
9351 "Interrupts may not be functioning.\n", ahd_name(ahd));
9352 ahd_unpause(ahd);
9363 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
9364 last_phase = ahd_inb(ahd, LASTPHASE);
9365 active_scbptr = ahd_get_scbptr(ahd);
9368 || (ahd_inb(ahd, SEQ_FLAGS) & NOT_IDENTIFIED) == 0)
9369 active_scb = ahd_lookup_scb(ahd, active_scbptr);
9371 while ((scb = LIST_FIRST(&ahd->timedout_scbs)) != NULL) {
9376 target = SCB_GET_TARGET(ahd, scb);
9377 channel = SCB_GET_CHANNEL(ahd, scb);
9380 ahd_print_path(ahd, scb);
9390 found = ahd_reset_channel(ahd, channel,
9393 "%d SCBs aborted\n", ahd_name(ahd), channel,
9417 if (ahd_other_scb_timeout(ahd, scb,
9427 ahd_set_recoveryscb(ahd, active_scb);
9429 ahd_outb(ahd, MSG_OUT, HOST_MSG);
9430 ahd_outb(ahd, SCSISIGO, last_phase|ATNO);
9431 ahd_print_path(ahd, active_scb);
9436 && ahd_inb(ahd, SCSIPHASE) == 0) {
9445 "Identify Msg.\n", ahd_name(ahd));
9447 } else if (ahd_search_qinfifo(ahd, target, channel, lun,
9458 if (ahd_other_scb_timeout(ahd, scb, NULL) == 0)
9466 ahd_set_recoveryscb(ahd, scb);
9480 ahd_set_scbptr(ahd, SCB_GET_TAG(scb));
9489 ahd_outb(ahd, SCB_TASK_MANAGEMENT,
9510 ahd_outb(ahd, SCB_CONTROL,
9511 ahd_inb(ahd, SCB_CONTROL)|MK_MESSAGE);
9519 ahd_search_qinfifo(ahd, target, channel, lun,
9522 ahd_qinfifo_requeue_tail(ahd, scb);
9523 ahd_set_scbptr(ahd, active_scbptr);
9524 ahd_print_path(ahd, scb);
9536 while ((scb = LIST_FIRST(&ahd->timedout_scbs)) != NULL) {
9542 ahd_unpause(ahd);
9552 ahd_other_scb_timeout(struct ahd_softc *ahd, struct scb *scb,
9558 ahd_print_path(ahd, scb);
9563 AHD_UNCORRECTABLE_ERROR(ahd);
9576 LIST_FOREACH(other_scb, &ahd->pending_scbs, pending_links) {
9590 ahd_print_path(ahd, scb);
9605 ahd_read_seeprom(struct ahd_softc *ahd, uint16_t *buf,
9617 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
9621 ahd_outb(ahd, SEEADR, cur_addr);
9622 ahd_outb(ahd, SEECTL, SEEOP_READ | SEESTART);
9624 error = ahd_wait_seeprom(ahd);
9631 *bytestream_ptr++ = ahd_inb(ahd, SEEDAT);
9632 *bytestream_ptr = ahd_inb(ahd, SEEDAT+1);
9637 *buf = ahd_inw(ahd, SEEDAT);
9650 ahd_write_seeprom(struct ahd_softc *ahd, uint16_t *buf,
9658 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
9662 ahd_outb(ahd, SEEADR, SEEOP_EWEN_ADDR);
9663 ahd_outb(ahd, SEECTL, SEEOP_EWEN | SEESTART);
9664 error = ahd_wait_seeprom(ahd);
9675 ahd_outw(ahd, SEEDAT, *buf++);
9676 ahd_outb(ahd, SEEADR, cur_addr);
9677 ahd_outb(ahd, SEECTL, SEEOP_WRITE | SEESTART);
9679 retval = ahd_wait_seeprom(ahd);
9687 ahd_outb(ahd, SEEADR, SEEOP_EWDS_ADDR);
9688 ahd_outb(ahd, SEECTL, SEEOP_EWDS | SEESTART);
9689 error = ahd_wait_seeprom(ahd);
9699 ahd_wait_seeprom(struct ahd_softc *ahd)
9704 while ((ahd_inb(ahd, SEESTAT) & (SEEARBACK|SEEBUSY)) != 0 && --cnt)
9767 ahd_acquire_seeprom(struct ahd_softc *ahd)
9781 error = ahd_read_flexport(ahd, FLXADDR_ROMSTAT_CURSENSECTL, &seetype);
9790 ahd_release_seeprom(struct ahd_softc *ahd)
9796 ahd_write_flexport(struct ahd_softc *ahd, u_int addr, u_int value)
9800 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
9803 ahd_outb(ahd, BRDCTL, BRDEN|(addr << 3));
9804 error = ahd_wait_flexport(ahd);
9807 ahd_outb(ahd, BRDDAT, value);
9808 ahd_flush_device_writes(ahd);
9809 ahd_outb(ahd, BRDCTL, BRDSTB|BRDEN|(addr << 3));
9810 ahd_flush_device_writes(ahd);
9811 ahd_outb(ahd, BRDCTL, BRDEN|(addr << 3));
9812 ahd_flush_device_writes(ahd);
9813 ahd_outb(ahd, BRDCTL, 0);
9814 ahd_flush_device_writes(ahd);
9819 ahd_read_flexport(struct ahd_softc *ahd, u_int addr, uint8_t *value)
9823 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
9826 ahd_outb(ahd, BRDCTL, BRDRW|BRDEN|(addr << 3));
9827 error = ahd_wait_flexport(ahd);
9830 *value = ahd_inb(ahd, BRDDAT);
9831 ahd_outb(ahd, BRDCTL, 0);
9832 ahd_flush_device_writes(ahd);
9840 ahd_wait_flexport(struct ahd_softc *ahd)
9844 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
9846 while ((ahd_inb(ahd, BRDCTL) & FLXARBACK) == 0 && --cnt)
9857 ahd_find_tmode_devs(struct ahd_softc *ahd, struct cam_sim *sim, union ccb *ccb,
9863 if ((ahd->features & AHD_TARGETMODE) == 0)
9873 *lstate = ahd->black_hole;
9877 max_id = (ahd->features & AHD_WIDE) ? 15 : 7;
9884 *tstate = ahd->enabled_targets[ccb->ccb_h.target_id];
9898 ahd_handle_en_lun(struct ahd_softc *ahd, struct cam_sim *sim, union ccb *ccb)
9911 status = ahd_find_tmode_devs(ahd, sim, ccb, &tstate, &lstate,
9919 if ((ahd->features & AHD_MULTIROLE) != 0) {
9922 our_id = ahd->our_id;
9925 if ((ahd->features & AHD_MULTI_TID) != 0
9926 && (ahd->flags & AHD_INITIATORROLE) != 0) {
9935 } else if ((ahd->flags & AHD_INITIATORROLE) != 0
9936 || ahd->enabled_luns > 0) {
9958 if ((ahd->flags & AHD_TARGETROLE) == 0
9961 if (LIST_FIRST(&ahd->pending_scbs) != NULL) {
9965 ahd->flags |= AHD_TARGETROLE;
9966 if ((ahd->features & AHD_MULTIROLE) == 0)
9967 ahd->flags &= ~AHD_INITIATORROLE;
9968 ahd_pause(ahd);
9969 ahd_loadseq(ahd);
9970 ahd_restart(ahd);
9975 channel = SIM_CHANNEL(ahd, sim);
9987 AHD_CORRECTABLE_ERROR(ahd);
10008 tstate = ahd_alloc_tstate(ahd, target, channel);
10037 ahd_pause(ahd);
10040 ahd->enabled_luns++;
10042 if ((ahd->features & AHD_MULTI_TID) != 0) {
10045 targid_mask = ahd_inw(ahd, TARGID);
10047 ahd_outw(ahd, TARGID, targid_mask);
10048 ahd_update_scsiid(ahd, targid_mask);
10053 channel = SIM_CHANNEL(ahd, sim);
10054 our_id = SIM_SCSI_ID(ahd, sim);
10065 sblkctl = ahd_inb(ahd, SBLKCTL);
10068 if ((ahd->features & AHD_TWIN) == 0)
10071 ahd->our_id = target;
10074 ahd_outb(ahd, SBLKCTL,
10077 ahd_outb(ahd, SCSIID, target);
10080 ahd_outb(ahd, SBLKCTL, sblkctl);
10084 ahd->black_hole = lstate;
10086 if (ahd->black_hole != NULL && ahd->enabled_luns > 0) {
10087 scsiseq1 = ahd_inb(ahd, SCSISEQ_TEMPLATE);
10089 ahd_outb(ahd, SCSISEQ_TEMPLATE, scsiseq1);
10090 scsiseq1 = ahd_inb(ahd, SCSISEQ1);
10092 ahd_outb(ahd, SCSISEQ1, scsiseq1);
10094 ahd_unpause(ahd);
10108 LIST_FOREACH(scb, &ahd->pending_scbs, pending_links) {
10139 ahd_pause(ahd);
10143 ahd->enabled_luns--;
10151 ahd_free_tstate(ahd, target, channel,
10153 if (ahd->features & AHD_MULTI_TID) {
10156 targid_mask = ahd_inw(ahd, TARGID);
10158 ahd_outw(ahd, TARGID, targid_mask);
10159 ahd_update_scsiid(ahd, targid_mask);
10164 ahd->black_hole = NULL;
10172 if (ahd->enabled_luns == 0) {
10176 scsiseq1 = ahd_inb(ahd, SCSISEQ_TEMPLATE);
10178 ahd_outb(ahd, SCSISEQ_TEMPLATE, scsiseq1);
10179 scsiseq1 = ahd_inb(ahd, SCSISEQ1);
10181 ahd_outb(ahd, SCSISEQ1, scsiseq1);
10183 if ((ahd->features & AHD_MULTIROLE) == 0) {
10185 ahd->flags &= ~AHD_TARGETROLE;
10186 ahd->flags |= AHD_INITIATORROLE;
10187 ahd_pause(ahd);
10188 ahd_loadseq(ahd);
10189 ahd_restart(ahd);
10196 ahd_unpause(ahd);
10202 ahd_update_scsiid(struct ahd_softc *ahd, u_int targid_mask)
10208 if ((ahd->features & AHD_MULTI_TID) == 0)
10217 if ((ahd->features & AHD_ULTRA2) != 0)
10218 scsiid = ahd_inb(ahd, SCSIID_ULTRA2);
10220 scsiid = ahd_inb(ahd, SCSIID);
10228 our_id = ahd->our_id;
10234 if ((ahd->features & AHD_ULTRA2) != 0)
10235 ahd_outb(ahd, SCSIID_ULTRA2, scsiid);
10237 ahd_outb(ahd, SCSIID, scsiid);
10242 ahd_run_tqinfifo(struct ahd_softc *ahd, int paused)
10246 ahd_sync_tqinfifo(ahd, BUS_DMASYNC_POSTREAD);
10247 while ((cmd = &ahd->targetcmds[ahd->tqinfifonext])->cmd_valid != 0) {
10253 if (ahd_handle_target_cmd(ahd, cmd) != 0)
10257 ahd_dmamap_sync(ahd, ahd->shared_data_dmat,
10258 ahd->shared_data_dmamap,
10259 ahd_targetcmd_offset(ahd, ahd->tqinfifonext),
10262 ahd->tqinfifonext++;
10268 if ((ahd->tqinfifonext & (HOST_TQINPOS - 1)) == 1) {
10271 hs_mailbox = ahd_inb(ahd, HS_MAILBOX);
10273 hs_mailbox |= ahd->tqinfifonext & HOST_TQINPOS;
10274 ahd_outb(ahd, HS_MAILBOX, hs_mailbox);
10280 ahd_handle_target_cmd(struct ahd_softc *ahd, struct target_cmd *cmd)
10290 initiator = SCSIID_TARGET(ahd, cmd->scsiid);
10295 tstate = ahd->enabled_targets[target];
10304 lstate = ahd->black_hole;
10308 ahd->flags |= AHD_TQINFIFO_BLOCKED;
10314 ahd->flags &= ~AHD_TQINFIFO_BLOCKED;
10319 lstate == ahd->black_hole ? "(Black Holed)" : "");
10323 if (lstate == ahd->black_hole) {
10382 initiator, target, lun, ahd->pending_device);
10384 ahd->pending_device = lstate;