• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /netgear-WNDR4500-V1.0.1.40_1.0.68/src/linux/linux-2.6/drivers/scsi/aic7xxx/

Lines Matching defs:ahd

106 static void		ahd_handle_transmission_error(struct ahd_softc *ahd);
107 static void ahd_handle_lqiphase_error(struct ahd_softc *ahd,
109 static int ahd_handle_pkt_busfree(struct ahd_softc *ahd,
111 static int ahd_handle_nonpkt_busfree(struct ahd_softc *ahd);
112 static void ahd_handle_proto_violation(struct ahd_softc *ahd);
113 static void ahd_force_renegotiation(struct ahd_softc *ahd,
117 ahd_alloc_tstate(struct ahd_softc *ahd,
120 static void ahd_free_tstate(struct ahd_softc *ahd,
123 static void ahd_devlimited_syncrate(struct ahd_softc *ahd,
128 static void ahd_update_neg_table(struct ahd_softc *ahd,
131 static void ahd_update_pending_scbs(struct ahd_softc *ahd);
132 static void ahd_fetch_devinfo(struct ahd_softc *ahd,
134 static void ahd_scb_devinfo(struct ahd_softc *ahd,
137 static void ahd_setup_initiator_msgout(struct ahd_softc *ahd,
140 static void ahd_build_transfer_msg(struct ahd_softc *ahd,
142 static void ahd_construct_sdtr(struct ahd_softc *ahd,
145 static void ahd_construct_wdtr(struct ahd_softc *ahd,
148 static void ahd_construct_ppr(struct ahd_softc *ahd,
152 static void ahd_clear_msg_state(struct ahd_softc *ahd);
153 static void ahd_handle_message_phase(struct ahd_softc *ahd);
159 static int ahd_sent_msg(struct ahd_softc *ahd, ahd_msgtype type,
161 static int ahd_parse_msg(struct ahd_softc *ahd,
163 static int ahd_handle_msg_reject(struct ahd_softc *ahd,
165 static void ahd_handle_ign_wide_residue(struct ahd_softc *ahd,
167 static void ahd_reinitialize_dataptrs(struct ahd_softc *ahd);
168 static void ahd_handle_devreset(struct ahd_softc *ahd,
173 static void ahd_setup_target_msgin(struct ahd_softc *ahd,
178 static u_int ahd_sglist_size(struct ahd_softc *ahd);
179 static u_int ahd_sglist_allocsize(struct ahd_softc *ahd);
182 static void ahd_initialize_hscbs(struct ahd_softc *ahd);
183 static int ahd_init_scbdata(struct ahd_softc *ahd);
184 static void ahd_fini_scbdata(struct ahd_softc *ahd);
185 static void ahd_setup_iocell_workaround(struct ahd_softc *ahd);
186 static void ahd_iocell_first_selection(struct ahd_softc *ahd);
187 static void ahd_add_col_list(struct ahd_softc *ahd,
189 static void ahd_rem_col_list(struct ahd_softc *ahd,
191 static void ahd_chip_init(struct ahd_softc *ahd);
192 static void ahd_qinfifo_requeue(struct ahd_softc *ahd,
195 static int ahd_qinfifo_count(struct ahd_softc *ahd);
196 static int ahd_search_scb_list(struct ahd_softc *ahd, int target,
202 static void ahd_stitch_tid_list(struct ahd_softc *ahd,
205 static void ahd_add_scb_to_free_list(struct ahd_softc *ahd,
207 static u_int ahd_rem_wscb(struct ahd_softc *ahd, u_int scbid,
209 static void ahd_reset_current_bus(struct ahd_softc *ahd);
212 static void ahd_dumpseq(struct ahd_softc *ahd);
214 static void ahd_loadseq(struct ahd_softc *ahd);
215 static int ahd_check_patch(struct ahd_softc *ahd,
218 static u_int ahd_resolve_seqaddr(struct ahd_softc *ahd,
220 static void ahd_download_instr(struct ahd_softc *ahd,
222 static int ahd_probe_stack_size(struct ahd_softc *ahd);
223 static int ahd_scb_active_in_fifo(struct ahd_softc *ahd,
225 static void ahd_run_data_fifo(struct ahd_softc *ahd,
229 static void ahd_queue_lstate_event(struct ahd_softc *ahd,
234 static void ahd_update_scsiid(struct ahd_softc *ahd,
236 static int ahd_handle_target_cmd(struct ahd_softc *ahd,
240 static int ahd_abort_scbs(struct ahd_softc *ahd, int target,
243 static void ahd_alloc_scbs(struct ahd_softc *ahd);
244 static void ahd_busy_tcl(struct ahd_softc *ahd, u_int tcl,
246 static void ahd_calc_residual(struct ahd_softc *ahd,
248 static void ahd_clear_critical_section(struct ahd_softc *ahd);
249 static void ahd_clear_intstat(struct ahd_softc *ahd);
250 static void ahd_enable_coalescing(struct ahd_softc *ahd,
252 static u_int ahd_find_busy_tcl(struct ahd_softc *ahd, u_int tcl);
253 static void ahd_freeze_devq(struct ahd_softc *ahd,
255 static void ahd_handle_scb_status(struct ahd_softc *ahd,
259 static void ahd_update_coalescing_values(struct ahd_softc *ahd,
264 static int ahd_wait_seeprom(struct ahd_softc *ahd);
265 static int ahd_match_scb(struct ahd_softc *ahd, struct scb *scb,
272 ahd_assert_atn(struct ahd_softc *ahd)
274 ahd_outb(ahd, SCSISIGO, ATNO);
284 ahd_currently_packetized(struct ahd_softc *ahd)
289 saved_modes = ahd_save_modes(ahd);
290 if ((ahd->bugs & AHD_PKTIZED_STATUS_BUG) != 0) {
296 ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
297 packetized = ahd_inb(ahd, LQISTATE) != 0;
299 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
300 packetized = ahd_inb(ahd, LQISTAT2) & PACKETIZED;
302 ahd_restore_modes(ahd, saved_modes);
307 ahd_set_active_fifo(struct ahd_softc *ahd)
311 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
312 active_fifo = ahd_inb(ahd, DFFSTAT) & CURRFIFO;
316 ahd_set_modes(ahd, active_fifo, active_fifo);
324 ahd_unbusy_tcl(struct ahd_softc *ahd, u_int tcl)
326 ahd_busy_tcl(ahd, tcl, SCB_LIST_NULL);
334 ahd_update_residual(struct ahd_softc *ahd, struct scb *scb)
340 ahd_calc_residual(ahd, scb);
344 ahd_complete_scb(struct ahd_softc *ahd, struct scb *scb)
350 ahd_handle_scb_status(ahd, scb);
352 ahd_done(ahd, scb);
361 ahd_restart(struct ahd_softc *ahd)
364 ahd_pause(ahd);
366 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
369 ahd_clear_msg_state(ahd);
370 ahd_outb(ahd, SCSISIGO, 0); /* De-assert BSY */
371 ahd_outb(ahd, MSG_OUT, MSG_NOOP); /* No message to send */
372 ahd_outb(ahd, SXFRCTL1, ahd_inb(ahd, SXFRCTL1) & ~BITBUCKET);
373 ahd_outb(ahd, SEQINTCTL, 0);
374 ahd_outb(ahd, LASTPHASE, P_BUSFREE);
375 ahd_outb(ahd, SEQ_FLAGS, 0);
376 ahd_outb(ahd, SAVED_SCSIID, 0xFF);
377 ahd_outb(ahd, SAVED_LUN, 0xFF);
386 ahd_outb(ahd, TQINPOS, ahd->tqinfifonext);
389 ahd_outb(ahd, SCSISEQ1,
390 ahd_inb(ahd, SCSISEQ_TEMPLATE) & (ENSELI|ENRSELI|ENAUTOATNP));
391 ahd_set_modes(ahd, AHD_MODE_CCHAN, AHD_MODE_CCHAN);
398 ahd_outb(ahd, CLRINT, CLRSEQINT);
400 ahd_outb(ahd, SEQCTL0, FASTMODE|SEQRESET);
401 ahd_unpause(ahd);
405 ahd_clear_fifo(struct ahd_softc *ahd, u_int fifo)
411 printf("%s: Clearing FIFO %d\n", ahd_name(ahd), fifo);
413 saved_modes = ahd_save_modes(ahd);
414 ahd_set_modes(ahd, fifo, fifo);
415 ahd_outb(ahd, DFFSXFRCTL, RSTCHN|CLRSHCNT);
416 if ((ahd_inb(ahd, SG_STATE) & FETCH_INPROG) != 0)
417 ahd_outb(ahd, CCSGCTL, CCSGRESET);
418 ahd_outb(ahd, LONGJMP_ADDR + 1, INVALID_ADDR);
419 ahd_outb(ahd, SG_STATE, 0);
420 ahd_restore_modes(ahd, saved_modes);
429 ahd_flush_qoutfifo(struct ahd_softc *ahd)
438 saved_modes = ahd_save_modes(ahd);
443 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
444 saved_scbptr = ahd_get_scbptr(ahd);
445 while ((ahd_inb(ahd, LQISTAT2) & LQIGSAVAIL) != 0) {
449 scbid = ahd_inw(ahd, GSFIFO);
450 scb = ahd_lookup_scb(ahd, scbid);
453 ahd_name(ahd), scbid);
466 ahd_set_modes(ahd, fifo_mode, fifo_mode);
468 if (ahd_scb_active_in_fifo(ahd, scb) == 0)
471 ahd_run_data_fifo(ahd, scb);
490 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
491 ahd_set_scbptr(ahd, scbid);
492 if ((ahd_inb_scbram(ahd, SCB_SGPTR) & SG_LIST_NULL) == 0
493 && ((ahd_inb_scbram(ahd, SCB_SGPTR) & SG_FULL_RESID) != 0
494 || (ahd_inb_scbram(ahd, SCB_RESIDUAL_SGPTR)
504 ahd_outb(ahd, SCB_SCSI_STATUS, 0);
505 ahd_outb(ahd, SCB_SGPTR,
506 ahd_inb_scbram(ahd, SCB_SGPTR)
508 ahd_outw(ahd, SCB_TAG, scbid);
509 ahd_outw(ahd, SCB_NEXT_COMPLETE, SCB_LIST_NULL);
510 comp_head = ahd_inw(ahd, COMPLETE_DMA_SCB_HEAD);
512 ahd_outw(ahd, COMPLETE_DMA_SCB_HEAD, scbid);
513 ahd_outw(ahd, COMPLETE_DMA_SCB_TAIL, scbid);
517 tail = ahd_inw(ahd, COMPLETE_DMA_SCB_TAIL);
518 ahd_set_scbptr(ahd, tail);
519 ahd_outw(ahd, SCB_NEXT_COMPLETE, scbid);
520 ahd_outw(ahd, COMPLETE_DMA_SCB_TAIL, scbid);
521 ahd_set_scbptr(ahd, scbid);
524 ahd_complete_scb(ahd, scb);
526 ahd_set_scbptr(ahd, saved_scbptr);
531 ahd_set_modes(ahd, AHD_MODE_CCHAN, AHD_MODE_CCHAN);
537 while (((ccscbctl = ahd_inb(ahd, CCSCBCTL)) & (CCARREN|CCSCBEN)) != 0) {
554 ahd_outb(ahd, CCSCBCTL, ccscbctl & ~(CCARREN|CCSCBEN));
560 ahd_run_qoutfifo(ahd);
562 saved_scbptr = ahd_get_scbptr(ahd);
567 scbid = ahd_inw(ahd, COMPLETE_DMA_SCB_HEAD);
572 ahd_set_scbptr(ahd, scbid);
573 next_scbid = ahd_inw_scbram(ahd, SCB_NEXT_COMPLETE);
574 scb = ahd_lookup_scb(ahd, scbid);
577 "SCB %d invalid\n", ahd_name(ahd), scbid);
582 *hscb_ptr++ = ahd_inb_scbram(ahd, SCB_BASE + i);
584 ahd_complete_scb(ahd, scb);
587 ahd_outw(ahd, COMPLETE_DMA_SCB_HEAD, SCB_LIST_NULL);
588 ahd_outw(ahd, COMPLETE_DMA_SCB_TAIL, SCB_LIST_NULL);
590 scbid = ahd_inw(ahd, COMPLETE_ON_QFREEZE_HEAD);
593 ahd_set_scbptr(ahd, scbid);
594 next_scbid = ahd_inw_scbram(ahd, SCB_NEXT_COMPLETE);
595 scb = ahd_lookup_scb(ahd, scbid);
598 ahd_name(ahd), scbid);
602 ahd_complete_scb(ahd, scb);
605 ahd_outw(ahd, COMPLETE_ON_QFREEZE_HEAD, SCB_LIST_NULL);
607 scbid = ahd_inw(ahd, COMPLETE_SCB_HEAD);
610 ahd_set_scbptr(ahd, scbid);
611 next_scbid = ahd_inw_scbram(ahd, SCB_NEXT_COMPLETE);
612 scb = ahd_lookup_scb(ahd, scbid);
615 ahd_name(ahd), scbid);
619 ahd_complete_scb(ahd, scb);
622 ahd_outw(ahd, COMPLETE_SCB_HEAD, SCB_LIST_NULL);
627 ahd_set_scbptr(ahd, saved_scbptr);
628 ahd_restore_modes(ahd, saved_modes);
629 ahd->flags |= AHD_UPDATE_PEND_CMDS;
637 ahd_scb_active_in_fifo(struct ahd_softc *ahd, struct scb *scb)
646 if (ahd_get_scbptr(ahd) != SCB_GET_TAG(scb)
647 || ((ahd_inb(ahd, LONGJMP_ADDR+1) & INVALID_ADDR) != 0
648 && (ahd_inb(ahd, SEQINTSRC) & (CFG4DATA|SAVEPTRS)) == 0))
666 ahd_run_data_fifo(struct ahd_softc *ahd, struct scb *scb)
670 seqintsrc = ahd_inb(ahd, SEQINTSRC);
678 sgptr = ahd_inl_scbram(ahd, SCB_SGPTR) & ~SG_FULL_RESID;
679 ahd_outb(ahd, SCB_SGPTR, sgptr);
684 datacnt = ahd_inl_scbram(ahd, SCB_DATACNT);
687 ahd_outb(ahd, SG_STATE, 0);
689 ahd_outb(ahd, SG_STATE, LOADING_NEEDED);
690 ahd_outq(ahd, HADDR, ahd_inq_scbram(ahd, SCB_DATAPTR));
691 ahd_outl(ahd, HCNT, datacnt & AHD_SG_LEN_MASK);
692 ahd_outb(ahd, SG_CACHE_PRE, sgptr);
693 ahd_outb(ahd, DFCNTRL, PRELOADEN|SCSIEN|HDMAEN);
698 ahd_outb(ahd, SCB_RESIDUAL_DATACNT+3, datacnt >> 24);
699 ahd_outl(ahd, SCB_RESIDUAL_SGPTR, sgptr & SG_PTR_MASK);
704 ahd_outb(ahd, SCB_FIFO_USE_COUNT,
705 ahd_inb_scbram(ahd, SCB_FIFO_USE_COUNT) + 1);
710 ahd_outw(ahd, LONGJMP_ADDR, 0);
716 ahd_outb(ahd, CLRSEQINTSRC, CLRCFG4DATA);
721 if ((ahd_inb(ahd, LONGJMP_ADDR+1)&INVALID_ADDR) != 0) {
734 if ((ahd_inb(ahd, SG_STATE) & FETCH_INPROG) != 0)
735 ahd_outb(ahd, CCSGCTL, 0);
736 ahd_outb(ahd, SG_STATE, 0);
742 ahd_outb(ahd, DFCNTRL, ahd_inb(ahd, DFCNTRL) | FIFOFLUSH);
747 sgptr = ahd_inl_scbram(ahd, SCB_RESIDUAL_SGPTR);
748 resid = ahd_inl(ahd, SHCNT);
749 resid |= ahd_inb_scbram(ahd, SCB_RESIDUAL_DATACNT+3) << 24;
750 ahd_outl(ahd, SCB_RESIDUAL_DATACNT, resid);
751 if ((ahd_inb(ahd, SG_CACHE_SHADOW) & LAST_SEG) == 0) {
759 if ((ahd_inb(ahd, SG_CACHE_SHADOW) & 0x80) != 0
763 sgptr |= ahd_inb(ahd, SG_CACHE_SHADOW)
765 ahd_outl(ahd, SCB_RESIDUAL_SGPTR, sgptr);
766 ahd_outb(ahd, SCB_RESIDUAL_DATACNT + 3, 0);
768 ahd_outb(ahd, SCB_RESIDUAL_SGPTR,
774 ahd_outq(ahd, SCB_DATAPTR, ahd_inq(ahd, SHADDR));
775 ahd_outl(ahd, SCB_DATACNT, resid);
776 ahd_outl(ahd, SCB_SGPTR, sgptr);
777 ahd_outb(ahd, CLRSEQINTSRC, CLRSAVEPTRS);
778 ahd_outb(ahd, SEQIMODE,
779 ahd_inb(ahd, SEQIMODE) | ENSAVEPTRS);
784 if ((ahd_inb(ahd, DFCNTRL) & DIRECTION) != 0)
786 } else if ((ahd_inb(ahd, SG_STATE) & LOADING_NEEDED) != 0) {
797 if ((ahd_inb(ahd, SG_STATE) & FETCH_INPROG) != 0) {
798 ahd_outb(ahd, CCSGCTL, 0);
799 ahd_outb(ahd, SG_STATE, LOADING_NEEDED);
808 if ((ahd_inb(ahd, DFSTATUS) & PRELOAD_AVAIL) != 0
809 && (ahd_inb(ahd, DFCNTRL) & HDMAENACK) != 0) {
815 sgptr = ahd_inl_scbram(ahd, SCB_RESIDUAL_SGPTR);
817 if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0) {
820 sg = ahd_sg_bus_to_virt(ahd, scb, sgptr);
827 sg = ahd_sg_bus_to_virt(ahd, scb, sgptr);
838 ahd_outb(ahd, SCB_RESIDUAL_DATACNT+3, data_len >> 24);
839 ahd_outl(ahd, SCB_RESIDUAL_SGPTR, sgptr);
846 ahd_outb(ahd, SG_STATE, 0);
848 ahd_outq(ahd, HADDR, data_addr);
849 ahd_outl(ahd, HCNT, data_len & AHD_SG_LEN_MASK);
850 ahd_outb(ahd, SG_CACHE_PRE, sgptr & 0xFF);
855 dfcntrl = ahd_inb(ahd, DFCNTRL)|PRELOADEN|HDMAEN;
856 if ((ahd->features & AHD_NEW_DFCNTRL_OPTS) != 0) {
864 ahd_outb(ahd, DFCNTRL, dfcntrl);
866 } else if ((ahd_inb(ahd, SG_CACHE_SHADOW) & LAST_SEG_DONE) != 0) {
872 ahd_outb(ahd, SCB_SGPTR,
873 ahd_inb_scbram(ahd, SCB_SGPTR) | SG_LIST_NULL);
875 } else if ((ahd_inb(ahd, DFSTATUS) & FIFOEMP) != 0) {
882 ahd_outb(ahd, LONGJMP_ADDR + 1, INVALID_ADDR);
883 ahd_outb(ahd, SCB_FIFO_USE_COUNT,
884 ahd_inb_scbram(ahd, SCB_FIFO_USE_COUNT) - 1);
885 ahd_outb(ahd, DFFSXFRCTL, CLRCHN);
900 ahd_run_qoutfifo(struct ahd_softc *ahd)
906 if ((ahd->flags & AHD_RUNNING_QOUTFIFO) != 0)
908 ahd->flags |= AHD_RUNNING_QOUTFIFO;
909 ahd_sync_qoutfifo(ahd, BUS_DMASYNC_POSTREAD);
911 completion = &ahd->qoutfifo[ahd->qoutfifonext];
913 if (completion->valid_tag != ahd->qoutfifonext_valid_tag)
917 scb = ahd_lookup_scb(ahd, scb_index);
921 ahd_name(ahd), scb_index,
922 ahd->qoutfifonext);
923 ahd_dump_card_state(ahd);
925 ahd_handle_scb_status(ahd, scb);
927 ahd_done(ahd, scb);
930 ahd->qoutfifonext = (ahd->qoutfifonext+1) & (AHD_QOUT_SIZE-1);
931 if (ahd->qoutfifonext == 0)
932 ahd->qoutfifonext_valid_tag ^= QOUTFIFO_ENTRY_VALID;
934 ahd->flags &= ~AHD_RUNNING_QOUTFIFO;
939 ahd_handle_hwerrint(struct ahd_softc *ahd)
948 error = ahd_inb(ahd, ERROR);
952 ahd_name(ahd), ahd_hard_errors[i].errmesg);
955 ahd_dump_card_state(ahd);
959 ahd_abort_scbs(ahd, CAM_TARGET_WILDCARD, ALL_CHANNELS,
964 ahd_free(ahd);
1013 ahd_handle_seqint(struct ahd_softc *ahd, u_int intstat)
1022 seqintcode = ahd_inb(ahd, SEQINTCODE);
1023 ahd_outb(ahd, CLRINT, CLRSEQINT);
1024 if ((ahd->bugs & AHD_INTCOLLISION_BUG) != 0) {
1031 ahd_unpause(ahd);
1032 while (!ahd_is_paused(ahd))
1034 ahd_outb(ahd, CLRINT, CLRSEQINT);
1036 ahd_update_modes(ahd);
1040 ahd_name(ahd), seqintcode);
1048 AHD_ASSERT_MODES(ahd, ~(AHD_MODE_UNKNOWN_MSK|AHD_MODE_CFG_MSK),
1050 scbid = ahd_get_scbptr(ahd);
1051 scb = ahd_lookup_scb(ahd, scbid);
1060 ahd_outb(ahd, SAVED_SCSIID, scb->hscb->scsiid);
1061 ahd_outb(ahd, SAVED_LUN, scb->hscb->lun);
1062 ahd_outb(ahd, SEQ_FLAGS, 0x0);
1064 if ((ahd_inb(ahd, LQISTAT2) & LQIPHASE_OUTPKT) != 0
1065 && (ahd_inb(ahd, SCSISIGO) & ATNO) != 0) {
1074 "P0 assertion\n", ahd_name(ahd));
1079 printf("%s: Entering NONPACK\n", ahd_name(ahd));
1086 ahd_name(ahd));
1089 ahd_dump_card_state(ahd);
1091 ahd_reset_channel(ahd, 'A', /*Initiate Reset*/TRUE);
1098 scbid = ahd_get_scbptr(ahd);
1099 scb = ahd_lookup_scb(ahd, scbid);
1101 ahd_print_path(ahd, scb);
1103 printf("%s: ", ahd_name(ahd));
1105 ahd_dump_card_state(ahd);
1106 ahd_reset_channel(ahd, 'A', /*Initiate Reset*/TRUE);
1114 scbid = ahd_get_scbptr(ahd);
1115 scb = ahd_lookup_scb(ahd, scbid);
1117 ahd_dump_card_state(ahd);
1121 ahd_outq(ahd, HADDR, scb->sense_busaddr);
1122 ahd_outw(ahd, HCNT, AHD_SENSE_BUFSIZE);
1123 ahd_outb(ahd, HCNT + 2, 0);
1124 ahd_outb(ahd, SG_CACHE_PRE, SG_LAST_SEG);
1125 ahd_outb(ahd, DFCNTRL, PRELOADEN|SCSIEN|HDMAEN);
1132 bus_phase = ahd_inb(ahd, SCSISIGI) & PHASE_MASK;
1134 ahd_name(ahd), bus_phase);
1144 ahd_reset_channel(ahd, 'A', /*Initiate Reset*/TRUE);
1145 printf("%s: Issued Bus Reset.\n", ahd_name(ahd));
1167 scbid = ahd_get_scbptr(ahd);
1168 scb = ahd_lookup_scb(ahd, scbid);
1172 ahd_reset_channel(ahd, 'A',
1177 SCB_GET_TARGET(ahd, scb),
1179 SCB_GET_CHANNEL(ahd, scb),
1181 targ_info = ahd_fetch_transinfo(ahd,
1187 ahd_set_width(ahd, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
1189 ahd_set_syncrate(ahd, &devinfo, /*period*/0,
1193 ahd_outb(ahd, SCB_CDB_STORE, 0);
1194 ahd_outb(ahd, SCB_CDB_STORE+1, 0);
1195 ahd_outb(ahd, SCB_CDB_STORE+2, 0);
1196 ahd_outb(ahd, SCB_CDB_STORE+3, 0);
1197 ahd_outb(ahd, SCB_CDB_STORE+4, 0);
1198 ahd_outb(ahd, SCB_CDB_STORE+5, 0);
1199 ahd_outb(ahd, SCB_CDB_LEN, 6);
1202 ahd_outb(ahd, SCB_CONTROL, scb->hscb->control);
1203 ahd_outb(ahd, MSG_OUT, HOST_MSG);
1204 ahd_outb(ahd, SAVED_SCSIID, scb->hscb->scsiid);
1209 ahd_outb(ahd, SAVED_LUN, 0);
1210 ahd_outb(ahd, SEQ_FLAGS, 0);
1211 ahd_assert_atn(ahd);
1214 ahd_freeze_devq(ahd, scb);
1219 ahd_send_async(ahd, devinfo.channel, devinfo.target,
1226 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
1227 ahd_outb(ahd, CLRLQOINT1, CLRLQOPHACHGINPKT);
1228 if ((ahd->bugs & AHD_CLRLQO_AUTOCLR_BUG) != 0) {
1229 ahd_outb(ahd, CLRLQOINT1, 0);
1233 ahd_print_path(ahd, scb);
1250 printf("%s: CFG4OVERRUN mode = %x\n", ahd_name(ahd),
1251 ahd_inb(ahd, MODE_PTR));
1254 scb_index = ahd_get_scbptr(ahd);
1255 scb = ahd_lookup_scb(ahd, scb_index);
1261 ahd_assert_atn(ahd);
1262 ahd_outb(ahd, MSG_OUT, HOST_MSG);
1263 ahd->msgout_buf[0] = MSG_ABORT_TASK;
1264 ahd->msgout_len = 1;
1265 ahd->msgout_index = 0;
1266 ahd->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
1271 ahd_outb(ahd, SCB_CONTROL,
1272 ahd_inb_scbram(ahd, SCB_CONTROL)
1279 ahd_dump_card_state(ahd);
1288 ahd_name(ahd), ahd_inb(ahd, DFCNTRL),
1289 ahd_inb(ahd, SG_CACHE_SHADOW));
1292 ahd_reinitialize_dataptrs(ahd);
1310 ahd_fetch_devinfo(ahd, &devinfo);
1311 if (ahd->msg_type == MSG_TYPE_NONE) {
1316 bus_phase = ahd_inb(ahd, SCSISIGI) & PHASE_MASK;
1325 ahd_dump_card_state(ahd);
1326 ahd_clear_intstat(ahd);
1327 ahd_restart(ahd);
1331 scb_index = ahd_get_scbptr(ahd);
1332 scb = ahd_lookup_scb(ahd, scb_index);
1335 ahd_setup_initiator_msgout(ahd,
1339 ahd->msg_type =
1341 ahd->msgin_index = 0;
1347 ahd->msg_type =
1349 ahd->msgin_index = 0;
1352 ahd_setup_target_msgin(ahd,
1359 ahd_handle_message_phase(ahd);
1365 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
1366 ahd_outb(ahd, SCSISEQ0, ahd_inb(ahd, SCSISEQ0) & ~ENSELO);
1370 ahd_name(ahd), 'A', ahd_inb(ahd, SELID) >> 4);
1373 ahd_inb(ahd, SAVED_SCSIID), ahd_inb(ahd, SAVED_LUN),
1374 ahd_inw(ahd, REG0), ahd_inb(ahd, ACCUM));
1377 ahd_inb(ahd, SEQ_FLAGS), ahd_get_scbptr(ahd),
1378 ahd_find_busy_tcl(ahd,
1379 BUILD_TCL(ahd_inb(ahd, SAVED_SCSIID),
1380 ahd_inb(ahd, SAVED_LUN))),
1381 ahd_inw(ahd, SINDEX));
1384 ahd_inb(ahd, SELID), ahd_inb_scbram(ahd, SCB_SCSIID),
1385 ahd_inb_scbram(ahd, SCB_LUN),
1386 ahd_inb_scbram(ahd, SCB_CONTROL));
1388 ahd_inb(ahd, SCSIBUS), ahd_inb(ahd, SCSISIGI));
1389 printf("SXFRCTL0 == 0x%x\n", ahd_inb(ahd, SXFRCTL0));
1390 printf("SEQCTL0 == 0x%x\n", ahd_inb(ahd, SEQCTL0));
1391 ahd_dump_card_state(ahd);
1392 ahd->msgout_buf[0] = MSG_BUS_DEV_RESET;
1393 ahd->msgout_len = 1;
1394 ahd->msgout_index = 0;
1395 ahd->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
1396 ahd_outb(ahd, MSG_OUT, HOST_MSG);
1397 ahd_assert_atn(ahd);
1402 ahd_handle_proto_violation(ahd);
1409 ahd_fetch_devinfo(ahd, &devinfo);
1410 ahd_handle_ign_wide_residue(ahd, &devinfo);
1417 lastphase = ahd_inb(ahd, LASTPHASE);
1420 ahd_name(ahd), 'A',
1421 SCSIID_TARGET(ahd, ahd_inb(ahd, SAVED_SCSIID)),
1422 lastphase, ahd_inb(ahd, SCSISIGI));
1429 lastphase = ahd_inb(ahd, LASTPHASE);
1432 ahd_name(ahd), 'A',
1433 SCSIID_TARGET(ahd, ahd_inb(ahd, SAVED_SCSIID)),
1434 lastphase, ahd_inb(ahd, SCSISIGI));
1435 ahd_restart(ahd);
1454 scbindex = ahd_get_scbptr(ahd);
1455 scb = ahd_lookup_scb(ahd, scbindex);
1457 lastphase = ahd_inb(ahd, LASTPHASE);
1459 ahd_print_path(ahd, scb);
1463 ahd_print_path(ahd, scb);
1466 ahd_inb(ahd, SEQ_FLAGS) & DPHASE
1477 ahd_freeze_devq(ahd, scb);
1488 ahd_fetch_devinfo(ahd, &devinfo);
1490 ahd_name(ahd), devinfo.channel, devinfo.target,
1492 scbid = ahd_get_scbptr(ahd);
1493 scb = ahd_lookup_scb(ahd, scbid);
1500 ahd_search_qinfifo(ahd, SCB_GET_TARGET(ahd, scb),
1501 SCB_GET_CHANNEL(ahd, scb),
1505 ahd_outb(ahd, SCB_CONTROL,
1506 ahd_inb_scbram(ahd, SCB_CONTROL) & ~MK_MESSAGE);
1514 scbid = ahd_get_scbptr(ahd);
1515 scb = ahd_lookup_scb(ahd, scbid);
1521 ahd_print_path(ahd, scb);
1534 ahd_abort_scbs(ahd, SCB_GET_TARGET(ahd, scb),
1544 ahd_scb_devinfo(ahd, &devinfo, scb);
1546 ahd_handle_devreset(ahd, &devinfo, lun,
1570 scbid = ahd_get_scbptr(ahd);
1571 scb = ahd_lookup_scb(ahd, scbid);
1577 ahd_print_path(ahd, scb);
1586 while ((ahd_inb(ahd, SCSISEQ0) & ENSELO) != 0
1587 && (ahd_inb(ahd, SSTAT0) & SELDO) == 0
1588 && (ahd_inb(ahd, SSTAT1) & SELTO) == 0)
1590 ahd_outb(ahd, SCB_TASK_MANAGEMENT, 0);
1591 ahd_search_qinfifo(ahd, SCB_GET_TARGET(ahd, scb),
1592 SCB_GET_CHANNEL(ahd, scb),
1603 printf("%s: Tracepoint %d\n", ahd_name(ahd),
1609 ahd_handle_hwerrint(ahd);
1612 printf("%s: Unexpected SEQINTCODE %d\n", ahd_name(ahd),
1621 ahd_unpause(ahd);
1625 ahd_handle_scsiint(struct ahd_softc *ahd, u_int intstat)
1636 ahd_update_modes(ahd);
1637 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
1639 status3 = ahd_inb(ahd, SSTAT3) & (NTRAMPERR|OSRAMPERR);
1640 status0 = ahd_inb(ahd, SSTAT0) & (IOERR|OVERRUN|SELDI|SELDO);
1641 status = ahd_inb(ahd, SSTAT1) & (SELTO|SCSIRSTI|BUSFREE|SCSIPERR);
1642 lqistat1 = ahd_inb(ahd, LQISTAT1);
1643 lqostat0 = ahd_inb(ahd, LQOSTAT0);
1644 busfreetime = ahd_inb(ahd, SSTAT2) & BUSFREETIME;
1649 if (((status & SCSIRSTI) != 0) && (ahd->flags & AHD_BUS_RESET_ACTIVE)) {
1650 ahd_outb(ahd, CLRSINT1, CLRSCSIRSTI);
1657 ahd->flags &= ~AHD_BUS_RESET_ACTIVE;
1662 ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
1663 simode0 = ahd_inb(ahd, SIMODE0);
1665 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
1667 scbid = ahd_get_scbptr(ahd);
1668 scb = ahd_lookup_scb(ahd, scbid);
1670 && (ahd_inb(ahd, SEQ_FLAGS) & NOT_IDENTIFIED) != 0)
1676 now_lvd = ahd_inb(ahd, SBLKCTL) & ENAB40;
1678 ahd_name(ahd), now_lvd ? "LVD" : "SE");
1679 ahd_outb(ahd, CLRSINT0, CLRIOERR);
1683 ahd_reset_channel(ahd, 'A', /*Initiate Reset*/TRUE);
1684 ahd_pause(ahd);
1685 ahd_setup_iocell_workaround(ahd);
1686 ahd_unpause(ahd);
1690 ahd_name(ahd));
1691 ahd_reset_channel(ahd, 'A', /*Initiate Reset*/TRUE);
1694 printf("%s: Someone reset channel A\n", ahd_name(ahd));
1695 ahd_reset_channel(ahd, 'A', /*Initiate Reset*/FALSE);
1699 ahd_clear_critical_section(ahd);
1701 ahd_handle_transmission_error(ahd);
1704 printf("%s: lqostat0 == 0x%x!\n", ahd_name(ahd), lqostat0);
1705 ahd_outb(ahd, CLRLQOINT0, lqostat0);
1706 if ((ahd->bugs & AHD_CLRLQO_AUTOCLR_BUG) != 0)
1707 ahd_outb(ahd, CLRLQOINT1, 0);
1712 ahd_outb(ahd, SCSISEQ0, 0);
1715 ahd_clear_critical_section(ahd);
1718 ahd_clear_msg_state(ahd);
1721 ahd_outb(ahd, CLRSINT1, CLRSELTIMEO|CLRBUSFREE|CLRSCSIPERR);
1731 ahd_outb(ahd, CLRSINT0, CLRSELINGO);
1733 scbid = ahd_inw(ahd, WAITING_TID_HEAD);
1734 scb = ahd_lookup_scb(ahd, scbid);
1738 ahd_name(ahd), scbid);
1739 ahd_dump_card_state(ahd);
1744 ahd_print_path(ahd, scb);
1749 ahd_scb_devinfo(ahd, &devinfo, scb);
1751 ahd_freeze_devq(ahd, scb);
1759 ahd_handle_devreset(ahd, &devinfo,
1765 ahd_outb(ahd, CLRINT, CLRSCSIINT);
1766 ahd_iocell_first_selection(ahd);
1767 ahd_unpause(ahd);
1770 ahd_iocell_first_selection(ahd);
1771 ahd_unpause(ahd);
1774 ahd_name(ahd), status3);
1775 ahd_outb(ahd, CLRSINT3, status3);
1779 ahd_clear_critical_section(ahd);
1781 ahd_handle_lqiphase_error(ahd, lqistat1);
1789 ahd_outb(ahd, CLRLQIINT1, CLRLQICRCI_NLQ);
1804 ahd_outb(ahd, SCSISEQ0, 0);
1807 ahd_clear_critical_section(ahd);
1814 busfreetime = ahd_inb(ahd, SSTAT2) & BUSFREETIME;
1815 lqostat1 = ahd_inb(ahd, LQOSTAT1);
1825 ahd_set_modes(ahd, mode, mode);
1826 scbid = ahd_get_scbptr(ahd);
1827 scb = ahd_lookup_scb(ahd, scbid);
1831 ahd_name(ahd), scbid, mode);
1846 && ahd_inb(ahd, LASTPHASE) == P_BUSFREE
1847 && (ahd_inb(ahd, SSTAT0) & SELDI) == 0
1848 && ((ahd_inb(ahd, SSTAT0) & SELDO) == 0
1849 || (ahd_inb(ahd, SCSISEQ0) & ENSELO) == 0))
1869 if (packetized && ahd_inb(ahd, LASTPHASE) == P_BUSFREE) {
1870 restart = ahd_handle_pkt_busfree(ahd, busfreetime);
1873 restart = ahd_handle_nonpkt_busfree(ahd);
1886 ahd_outb(ahd, CLRSINT1, CLRBUSFREE);
1888 && (ahd->bugs & AHD_BUSFREEREV_BUG) != 0)
1889 ahd_outb(ahd, SIMODE1,
1890 ahd_inb(ahd, SIMODE1) & ~ENBUSFREE);
1893 ahd_clear_fifo(ahd, mode);
1895 ahd_clear_msg_state(ahd);
1896 ahd_outb(ahd, CLRINT, CLRSCSIINT);
1898 ahd_restart(ahd);
1900 ahd_unpause(ahd);
1904 ahd_name(ahd), status);
1905 ahd_dump_card_state(ahd);
1906 ahd_clear_intstat(ahd);
1907 ahd_unpause(ahd);
1912 ahd_handle_transmission_error(struct ahd_softc *ahd)
1926 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
1927 lqistat1 = ahd_inb(ahd, LQISTAT1) & ~(LQIPHASE_LQ|LQIPHASE_NLQ);
1928 lqistat2 = ahd_inb(ahd, LQISTAT2);
1930 && (ahd->bugs & AHD_NLQICRC_DELAYED_BUG) != 0) {
1933 ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
1934 lqistate = ahd_inb(ahd, LQISTATE);
1940 ahd_name(ahd));
1945 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
1948 ahd_outb(ahd, CLRLQIINT1, lqistat1);
1949 lastphase = ahd_inb(ahd, LASTPHASE);
1950 curphase = ahd_inb(ahd, SCSISIGI) & PHASE_MASK;
1951 perrdiag = ahd_inb(ahd, PERRDIAG);
1953 ahd_outb(ahd, CLRSINT1, CLRSCSIPERR);
1962 ahd_set_active_fifo(ahd);
1963 scbid = ahd_get_scbptr(ahd);
1964 scb = ahd_lookup_scb(ahd, scbid);
1971 printf("%s: Transmission error detected\n", ahd_name(ahd));
1977 ahd_dump_card_state(ahd);
1984 ahd_name(ahd), lqistat1);
1986 ahd_reset_channel(ahd, 'A', /*Initiate Reset*/TRUE);
2010 ahd_outb(ahd, LQCTL2, LQIRETRY);
2062 "Resetting bus\n", ahd_name(ahd));
2063 ahd_reset_channel(ahd, 'A', /*Initiate Reset*/TRUE);
2068 ahd_reset_channel(ahd, 'A', /*Initiate Reset*/TRUE);
2076 ahd_inb(ahd, SCSIDAT);
2090 ahd->send_msg_perror = msg_out;
2093 ahd_outb(ahd, MSG_OUT, HOST_MSG);
2094 ahd_outb(ahd, CLRINT, CLRSCSIINT);
2095 ahd_unpause(ahd);
2099 ahd_handle_lqiphase_error(struct ahd_softc *ahd, u_int lqistat1)
2104 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
2105 ahd_outb(ahd, CLRLQIINT1, lqistat1);
2115 ahd_set_active_fifo(ahd);
2116 if ((ahd_inb(ahd, SCSISIGO) & ATNO) != 0
2117 && (ahd_inb(ahd, MDFFSTAT) & DLZERO) != 0) {
2120 ahd_outb(ahd, LQCTL2, LQIRETRY);
2123 ahd_outb(ahd, LQCTL2, LQIRETRY);
2126 ahd_dump_card_state(ahd);
2127 ahd_outb(ahd, CLRINT, CLRSCSIINT);
2128 ahd_unpause(ahd);
2131 ahd_dump_card_state(ahd);
2132 ahd_reset_channel(ahd, 'A', /*Initiate Reset*/TRUE);
2141 ahd_handle_pkt_busfree(struct ahd_softc *ahd, u_int busfreetime)
2145 AHD_ASSERT_MODES(ahd, ~(AHD_MODE_UNKNOWN_MSK|AHD_MODE_CFG_MSK),
2147 lqostat1 = ahd_inb(ahd, LQOSTAT1);
2171 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
2172 scbid = ahd_inw(ahd, CURRSCB);
2173 scb = ahd_lookup_scb(ahd, scbid);
2179 ahd_outb(ahd, CLRLQOINT1, CLRLQOBUSFREE);
2180 if ((ahd->bugs & AHD_CLRLQO_AUTOCLR_BUG) != 0)
2181 ahd_outb(ahd, CLRLQOINT1, 0);
2182 ahd_outb(ahd, SCSISEQ0, ahd_inb(ahd, SCSISEQ0) & ~ENSELO);
2183 ahd_flush_device_writes(ahd);
2184 ahd_outb(ahd, CLRSINT0, CLRSELDO);
2192 ahd_outb(ahd, LQCTL2, ahd_inb(ahd, LQCTL2) | LQOTOIDLE);
2198 waiting_h = ahd_inw(ahd, WAITING_TID_HEAD);
2199 saved_scbptr = ahd_get_scbptr(ahd);
2202 ahd_outw(ahd, WAITING_TID_HEAD, scbid);
2203 waiting_t = ahd_inw(ahd, WAITING_TID_TAIL);
2205 ahd_outw(ahd, WAITING_TID_TAIL, scbid);
2208 ahd_set_scbptr(ahd, waiting_h);
2209 next = ahd_inw_scbram(ahd, SCB_NEXT2);
2211 ahd_set_scbptr(ahd, scbid);
2212 ahd_outw(ahd, SCB_NEXT2, next);
2214 ahd_set_scbptr(ahd, saved_scbptr);
2217 ahd_print_path(ahd, scb);
2225 ahd_freeze_devq(ahd, scb);
2229 } else if ((ahd_inb(ahd, PERRDIAG) & PARITYERR) != 0) {
2237 ahd_outb(ahd, CLRSINT1, CLRSCSIPERR|CLRBUSFREE);
2242 ahd_name(ahd));
2247 if (ahd->src_mode != AHD_MODE_SCSI) {
2251 scbid = ahd_get_scbptr(ahd);
2252 scb = ahd_lookup_scb(ahd, scbid);
2253 ahd_print_path(ahd, scb);
2255 ahd_dump_card_state(ahd);
2256 ahd_abort_scbs(ahd, SCB_GET_TARGET(ahd, scb), 'A',
2263 printf("%s: Unexpected PKT busfree condition\n", ahd_name(ahd));
2264 ahd_dump_card_state(ahd);
2273 ahd_handle_nonpkt_busfree(struct ahd_softc *ahd)
2291 lastphase = ahd_inb(ahd, LASTPHASE);
2292 saved_scsiid = ahd_inb(ahd, SAVED_SCSIID);
2293 saved_lun = ahd_inb(ahd, SAVED_LUN);
2294 target = SCSIID_TARGET(ahd, saved_scsiid);
2300 scbid = ahd_get_scbptr(ahd);
2301 scb = ahd_lookup_scb(ahd, scbid);
2303 && (ahd_inb(ahd, SEQ_FLAGS) & NOT_IDENTIFIED) != 0)
2306 ppr_busfree = (ahd->msg_flags & MSG_FLAG_EXPECT_PPR_BUSFREE) != 0;
2311 if (ahd_sent_msg(ahd, AHDMSG_1B, MSG_ABORT_TAG, TRUE)
2312 || ahd_sent_msg(ahd, AHDMSG_1B, MSG_ABORT, TRUE)) {
2317 ahd_print_devinfo(ahd, &devinfo);
2323 sent_msg = ahd->msgout_buf[ahd->msgout_index - 1];
2324 ahd_print_path(ahd, scb);
2348 found = ahd_abort_scbs(ahd, target, 'A', saved_lun,
2353 } else if (ahd_sent_msg(ahd, AHDMSG_1B,
2363 && ahd_match_scb(ahd, scb, target, 'A',
2368 ahd_handle_devreset(ahd, &devinfo, CAM_LUN_WILDCARD,
2372 } else if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_PPR, FALSE)
2391 tinfo = ahd_fetch_transinfo(ahd, devinfo.channel,
2395 ahd_set_width(ahd, &devinfo,
2399 ahd_set_syncrate(ahd, &devinfo,
2418 ahd_freeze_devq(ahd, scb);
2419 ahd_qinfifo_requeue_tail(ahd, scb);
2422 } else if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_WDTR, FALSE)
2432 ahd_set_width(ahd, &devinfo,
2441 ahd_freeze_devq(ahd, scb);
2442 ahd_qinfifo_requeue_tail(ahd, scb);
2444 } else if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_SDTR, FALSE)
2454 ahd_set_syncrate(ahd, &devinfo,
2464 ahd_freeze_devq(ahd, scb);
2465 ahd_qinfifo_requeue_tail(ahd, scb);
2467 } else if ((ahd->msg_flags & MSG_FLAG_EXPECT_IDE_BUSFREE) != 0
2468 && ahd_sent_msg(ahd, AHDMSG_1B,
2476 } else if ((ahd->msg_flags & MSG_FLAG_EXPECT_QASREJ_BUSFREE)
2477 && ahd_sent_msg(ahd, AHDMSG_1B,
2495 && ((ahd->msg_flags & MSG_FLAG_EXPECT_PPR_BUSFREE) != 0)) {
2497 ahd_freeze_devq(ahd, scb);
2500 if ((ahd->msg_flags & MSG_FLAG_IU_REQ_CHANGED) != 0) {
2501 ahd_abort_scbs(ahd, SCB_GET_TARGET(ahd, scb),
2502 SCB_GET_CHANNEL(ahd, scb),
2510 ahd_done(ahd, scb);
2525 ahd_print_path(ahd, scb);
2526 aborted = ahd_abort_scbs(ahd, target, 'A',
2535 printf("%s: ", ahd_name(ahd));
2541 ahd_inw(ahd, PRGMCNT));
2542 ahd_dump_card_state(ahd);
2544 ahd_force_renegotiation(ahd, &devinfo);
2551 ahd_handle_proto_violation(struct ahd_softc *ahd)
2561 ahd_fetch_devinfo(ahd, &devinfo);
2562 scbid = ahd_get_scbptr(ahd);
2563 scb = ahd_lookup_scb(ahd, scbid);
2564 seq_flags = ahd_inb(ahd, SEQ_FLAGS);
2565 curphase = ahd_inb(ahd, SCSISIGI) & PHASE_MASK;
2566 lastphase = ahd_inb(ahd, LASTPHASE);
2574 ahd_print_devinfo(ahd, &devinfo);
2583 ahd_print_devinfo(ahd, &devinfo);
2589 ahd_print_path(ahd, scb);
2591 } else if ((ahd_inb_scbram(ahd, SCB_CONTROL)
2600 ahd_print_path(ahd, scb);
2603 ahd_print_path(ahd, scb);
2605 ahd_dump_card_state(ahd);
2617 found = ahd_reset_channel(ahd, 'A', TRUE);
2619 "%d SCBs aborted\n", ahd_name(ahd), 'A', found);
2626 ahd_outb(ahd, SCSISEQ0,
2627 ahd_inb(ahd, SCSISEQ0) & ~ENSELO);
2628 ahd_assert_atn(ahd);
2629 ahd_outb(ahd, MSG_OUT, HOST_MSG);
2631 ahd_print_devinfo(ahd, &devinfo);
2632 ahd->msgout_buf[0] = MSG_ABORT_TASK;
2633 ahd->msgout_len = 1;
2634 ahd->msgout_index = 0;
2635 ahd->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
2637 ahd_print_path(ahd, scb);
2650 ahd_force_renegotiation(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
2657 ahd_print_devinfo(ahd, devinfo);
2661 targ_info = ahd_fetch_transinfo(ahd,
2666 ahd_update_neg_request(ahd, devinfo, tstate,
2672 ahd_clear_critical_section(struct ahd_softc *ahd)
2686 if (ahd->num_critical_sections == 0)
2699 saved_modes = ahd_save_modes(ahd);
2705 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
2706 seqaddr = ahd_inw(ahd, CURADDR);
2708 cs = ahd->critical_sections;
2709 for (i = 0; i < ahd->num_critical_sections; i++, cs++) {
2715 if (i == ahd->num_critical_sections)
2721 ahd_name(ahd), ahd_name(ahd), first_instr,
2723 ahd_dump_card_state(ahd);
2730 printf("%s: Single stepping at 0x%x\n", ahd_name(ahd),
2736 ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
2737 simode0 = ahd_inb(ahd, SIMODE0);
2738 simode3 = ahd_inb(ahd, SIMODE3);
2739 lqimode0 = ahd_inb(ahd, LQIMODE0);
2740 lqimode1 = ahd_inb(ahd, LQIMODE1);
2741 lqomode0 = ahd_inb(ahd, LQOMODE0);
2742 lqomode1 = ahd_inb(ahd, LQOMODE1);
2743 ahd_outb(ahd, SIMODE0, 0);
2744 ahd_outb(ahd, SIMODE3, 0);
2745 ahd_outb(ahd, LQIMODE0, 0);
2746 ahd_outb(ahd, LQIMODE1, 0);
2747 ahd_outb(ahd, LQOMODE0, 0);
2748 ahd_outb(ahd, LQOMODE1, 0);
2749 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
2750 simode1 = ahd_inb(ahd, SIMODE1);
2757 ahd_outb(ahd, SIMODE1, simode1 & ENBUSFREE);
2758 ahd_outb(ahd, SEQCTL0, ahd_inb(ahd, SEQCTL0) | STEP);
2761 ahd_outb(ahd, CLRSINT1, CLRBUSFREE);
2762 ahd_outb(ahd, CLRINT, CLRSCSIINT);
2763 ahd_set_modes(ahd, ahd->saved_src_mode, ahd->saved_dst_mode);
2764 ahd_outb(ahd, HCNTRL, ahd->unpause);
2765 while (!ahd_is_paused(ahd))
2767 ahd_update_modes(ahd);
2770 ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
2771 ahd_outb(ahd, SIMODE0, simode0);
2772 ahd_outb(ahd, SIMODE3, simode3);
2773 ahd_outb(ahd, LQIMODE0, lqimode0);
2774 ahd_outb(ahd, LQIMODE1, lqimode1);
2775 ahd_outb(ahd, LQOMODE0, lqomode0);
2776 ahd_outb(ahd, LQOMODE1, lqomode1);
2777 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
2778 ahd_outb(ahd, SEQCTL0, ahd_inb(ahd, SEQCTL0) & ~STEP);
2779 ahd_outb(ahd, SIMODE1, simode1);
2786 ahd_outb(ahd, CLRINT, CLRSCSIINT);
2788 ahd_restore_modes(ahd, saved_modes);
2795 ahd_clear_intstat(struct ahd_softc *ahd)
2797 AHD_ASSERT_MODES(ahd, ~(AHD_MODE_UNKNOWN_MSK|AHD_MODE_CFG_MSK),
2800 ahd_outb(ahd, CLRLQIINT0, CLRLQIATNQAS|CLRLQICRCT1|CLRLQICRCT2
2802 ahd_outb(ahd, CLRLQIINT1, CLRLQIPHASE_LQ|CLRLQIPHASE_NLQ|CLRLIQABORT
2805 ahd_outb(ahd, CLRLQOINT0, CLRLQOTARGSCBPERR|CLRLQOSTOPT2|CLRLQOATNLQ
2807 ahd_outb(ahd, CLRLQOINT1, CLRLQOINITSCBPERR|CLRLQOSTOPI2|CLRLQOBADQAS
2809 if ((ahd->bugs & AHD_CLRLQO_AUTOCLR_BUG) != 0) {
2810 ahd_outb(ahd, CLRLQOINT0, 0);
2811 ahd_outb(ahd, CLRLQOINT1, 0);
2813 ahd_outb(ahd, CLRSINT3, CLRNTRAMPERR|CLROSRAMPERR);
2814 ahd_outb(ahd, CLRSINT1, CLRSELTIMEO|CLRATNO|CLRSCSIRSTI
2816 ahd_outb(ahd, CLRSINT0, CLRSELDO|CLRSELDI|CLRSELINGO
2818 ahd_outb(ahd, CLRINT, CLRSCSIINT);
2833 ahd_alloc_tstate(struct ahd_softc *ahd, u_int scsi_id, char channel)
2839 master_tstate = ahd->enabled_targets[ahd->our_id];
2840 if (ahd->enabled_targets[scsi_id] != NULL
2841 && ahd->enabled_targets[scsi_id] != master_tstate)
2843 ahd_name(ahd));
2865 ahd->enabled_targets[scsi_id] = tstate;
2875 ahd_free_tstate(struct ahd_softc *ahd, u_int scsi_id, char channel, int force)
2883 if (scsi_id == ahd->our_id
2887 tstate = ahd->enabled_targets[scsi_id];
2890 ahd->enabled_targets[scsi_id] = NULL;
2901 ahd_devlimited_syncrate(struct ahd_softc *ahd,
2908 if ((ahd_inb(ahd, SBLKCTL) & ENAB40) != 0
2909 && (ahd_inb(ahd, SSTAT2) & EXP_ACTIVE) == 0) {
2940 ahd_find_syncrate(ahd, period, ppr_options, maxsync);
2950 ahd_find_syncrate(struct ahd_softc *ahd, u_int *period,
2989 ahd_validate_offset(struct ahd_softc *ahd,
3000 if ((ahd->bugs & AHD_PACED_NEGTABLE_BUG) != 0)
3020 ahd_validate_width(struct ahd_softc *ahd, struct ahd_initiator_tinfo *tinfo,
3025 if (ahd->features & AHD_WIDE) {
3050 ahd_update_neg_request(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
3064 if ((ahd->features & AHD_WIDE) != 0)
3093 ahd_set_syncrate(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
3113 tinfo = ahd_fetch_transinfo(ahd, devinfo->channel, devinfo->our_scsiid,
3143 ahd_send_async(ahd, devinfo->channel, devinfo->target,
3151 ahd_name(ahd), devinfo->target,
3181 ahd_name(ahd), devinfo->target,
3197 ahd_pause(ahd);
3198 ahd_update_neg_table(ahd, devinfo, &tinfo->curr);
3200 ahd_unpause(ahd);
3201 if (ahd->msg_type != MSG_TYPE_NONE) {
3206 ahd_print_devinfo(ahd, devinfo);
3210 ahd->msg_flags |= MSG_FLAG_EXPECT_PPR_BUSFREE
3218 ahd->msg_flags |= MSG_FLAG_EXPECT_PPR_BUSFREE;
3223 update_needed += ahd_update_neg_request(ahd, devinfo, tstate,
3227 ahd_update_pending_scbs(ahd);
3239 ahd_set_width(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
3250 tinfo = ahd_fetch_transinfo(ahd, devinfo->channel, devinfo->our_scsiid,
3265 ahd_send_async(ahd, devinfo->channel, devinfo->target,
3269 ahd_name(ahd), devinfo->target,
3276 ahd_pause(ahd);
3277 ahd_update_neg_table(ahd, devinfo, &tinfo->curr);
3279 ahd_unpause(ahd);
3282 update_needed += ahd_update_neg_request(ahd, devinfo, tstate,
3285 ahd_update_pending_scbs(ahd);
3293 ahd_set_tags(struct ahd_softc *ahd, struct scsi_cmnd *cmd,
3298 ahd_platform_set_tags(ahd, sdev, devinfo, alg);
3299 ahd_send_async(ahd, devinfo->channel, devinfo->target,
3304 ahd_update_neg_table(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
3313 uint8_t iocell_opts[sizeof(ahd->iocell_opts)];
3315 saved_modes = ahd_save_modes(ahd);
3316 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
3318 saved_negoaddr = ahd_inb(ahd, NEGOADDR);
3319 ahd_outb(ahd, NEGOADDR, devinfo->target);
3322 memcpy(iocell_opts, ahd->iocell_opts, sizeof(ahd->iocell_opts));
3330 if ((ahd->bugs & AHD_PACED_NEGTABLE_BUG) != 0) {
3362 if ((ahd->features & AHD_NEW_IOCELL_OPTS) != 0
3374 if ((ahd->bugs & AHD_PACED_NEGTABLE_BUG) != 0) {
3384 ahd_outb(ahd, ANNEXCOL, AHD_ANNEXCOL_PRECOMP_SLEW);
3385 ahd_outb(ahd, ANNEXDAT, iocell_opts[AHD_PRECOMP_SLEW_INDEX]);
3386 ahd_outb(ahd, ANNEXCOL, AHD_ANNEXCOL_AMPLITUDE);
3387 ahd_outb(ahd, ANNEXDAT, iocell_opts[AHD_AMPLITUDE_INDEX]);
3389 ahd_outb(ahd, NEGPERIOD, period);
3390 ahd_outb(ahd, NEGPPROPTS, ppr_opts);
3391 ahd_outb(ahd, NEGOFFSET, offset);
3401 if (ahd->features & AHD_AIC79XXB_SLOWCRC) {
3412 ahd_outb(ahd, NEGCONOPTS, con_opts);
3413 ahd_outb(ahd, NEGOADDR, saved_negoaddr);
3414 ahd_restore_modes(ahd, saved_modes);
3424 ahd_update_pending_scbs(struct ahd_softc *ahd)
3443 LIST_FOREACH(pending_scb, &ahd->pending_scbs, pending_links) {
3448 ahd_scb_devinfo(ahd, &devinfo, pending_scb);
3449 tinfo = ahd_fetch_transinfo(ahd, devinfo.channel,
3457 ahd_sync_scb(ahd, pending_scb,
3465 if (ahd_is_paused(ahd)) {
3469 ahd_pause(ahd);
3480 saved_modes = ahd_save_modes(ahd);
3481 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
3482 if ((ahd_inb(ahd, SCSISIGI) & BSYI) != 0
3483 && (ahd_inb(ahd, SSTAT0) & (SELDO|SELINGO)) == 0)
3484 ahd_outb(ahd, SCSISEQ0, ahd_inb(ahd, SCSISEQ0) & ~ENSELO);
3485 saved_scbptr = ahd_get_scbptr(ahd);
3487 LIST_FOREACH(pending_scb, &ahd->pending_scbs, pending_links) {
3492 ahd_set_scbptr(ahd, scb_tag);
3493 control = ahd_inb_scbram(ahd, SCB_CONTROL);
3496 ahd_outb(ahd, SCB_CONTROL, control);
3498 ahd_set_scbptr(ahd, saved_scbptr);
3499 ahd_restore_modes(ahd, saved_modes);
3502 ahd_unpause(ahd);
3507 ahd_fetch_devinfo(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
3514 saved_modes = ahd_save_modes(ahd);
3515 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
3517 if (ahd_inb(ahd, SSTAT0) & TARGET)
3523 && (ahd_inb(ahd, SEQ_FLAGS) & CMDPHASE_PENDING) != 0) {
3525 our_id = ahd_inb(ahd, TARGIDIN) & OID;
3527 our_id = ahd_inb(ahd, TOWNID);
3529 our_id = ahd_inb(ahd, IOWNID);
3531 saved_scsiid = ahd_inb(ahd, SAVED_SCSIID);
3534 SCSIID_TARGET(ahd, saved_scsiid),
3535 ahd_inb(ahd, SAVED_LUN),
3536 SCSIID_CHANNEL(ahd, saved_scsiid),
3538 ahd_restore_modes(ahd, saved_modes);
3542 ahd_print_devinfo(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
3544 printf("%s:%c:%d:%d: ", ahd_name(ahd), 'A',
3582 ahd_scb_devinfo(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
3592 ahd_compile_devinfo(devinfo, our_id, SCB_GET_TARGET(ahd, scb),
3593 SCB_GET_LUN(scb), SCB_GET_CHANNEL(ahd, scb), role);
3605 ahd_setup_initiator_msgout(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
3613 ahd->msgout_index = 0;
3614 ahd->msgout_len = 0;
3616 if (ahd_currently_packetized(ahd))
3617 ahd->msg_flags |= MSG_FLAG_PACKETIZED;
3619 if (ahd->send_msg_perror
3620 && ahd_inb(ahd, MSG_OUT) == HOST_MSG) {
3621 ahd->msgout_buf[ahd->msgout_index++] = ahd->send_msg_perror;
3622 ahd->msgout_len++;
3623 ahd->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
3631 "I_T msgin. Issuing NO-OP\n", ahd_name(ahd));
3632 ahd->msgout_buf[ahd->msgout_index++] = MSG_NOOP;
3633 ahd->msgout_len++;
3634 ahd->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
3640 && ahd_inb(ahd, MSG_OUT) == MSG_IDENTIFYFLAG) {
3646 ahd->msgout_buf[ahd->msgout_index++] = identify_msg;
3647 ahd->msgout_len++;
3650 ahd->msgout_buf[ahd->msgout_index++] =
3652 ahd->msgout_buf[ahd->msgout_index++] = SCB_GET_TAG(scb);
3653 ahd->msgout_len += 2;
3658 ahd->msgout_buf[ahd->msgout_index++] = MSG_BUS_DEV_RESET;
3659 ahd->msgout_len++;
3660 ahd_print_path(ahd, scb);
3669 ahd_outb(ahd, SCSISEQ0, 0);
3673 ahd->msgout_buf[ahd->msgout_index++] = MSG_ABORT_TAG;
3675 ahd->msgout_buf[ahd->msgout_index++] = MSG_ABORT;
3677 ahd->msgout_len++;
3678 ahd_print_path(ahd, scb);
3688 ahd_outb(ahd, SCSISEQ0, 0);
3690 ahd_build_transfer_msg(ahd, devinfo);
3698 ahd_outb(ahd, SCSISEQ0, 0);
3706 ahd_inb_scbram(ahd, SCB_CONTROL), ahd_inb(ahd, MSG_OUT),
3714 ahd_outb(ahd, SCB_CONTROL,
3715 ahd_inb_scbram(ahd, SCB_CONTROL) & ~MK_MESSAGE);
3717 ahd->msgout_index = 0;
3718 ahd->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
3726 ahd_build_transfer_msg(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
3742 tinfo = ahd_fetch_transinfo(ahd, devinfo->channel, devinfo->our_scsiid,
3756 ahd_devlimited_syncrate(ahd, tinfo, &period,
3777 if ((ahd->features & AHD_WIDE) != 0)
3783 ahd_print_devinfo(ahd, devinfo);
3802 ahd_validate_offset(ahd, tinfo, period, &offset,
3807 ahd_construct_ppr(ahd, devinfo, period, offset,
3810 ahd_construct_sdtr(ahd, devinfo, period, offset);
3813 ahd_construct_wdtr(ahd, devinfo, tinfo->goal.width);
3822 ahd_construct_sdtr(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
3827 ahd->msgout_index += spi_populate_sync_msg(
3828 ahd->msgout_buf + ahd->msgout_index, period, offset);
3829 ahd->msgout_len += 5;
3832 ahd_name(ahd), devinfo->channel, devinfo->target,
3842 ahd_construct_wdtr(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
3845 ahd->msgout_index += spi_populate_width_msg(
3846 ahd->msgout_buf + ahd->msgout_index, bus_width);
3847 ahd->msgout_len += 4;
3850 ahd_name(ahd), devinfo->channel, devinfo->target,
3860 ahd_construct_ppr(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
3873 ahd->msgout_index += spi_populate_ppr_msg(
3874 ahd->msgout_buf + ahd->msgout_index, period, offset,
3876 ahd->msgout_len += 8;
3879 "offset %x, ppr_options %x\n", ahd_name(ahd),
3889 ahd_clear_msg_state(struct ahd_softc *ahd)
3893 saved_modes = ahd_save_modes(ahd);
3894 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
3895 ahd->send_msg_perror = 0;
3896 ahd->msg_flags = MSG_FLAG_NONE;
3897 ahd->msgout_len = 0;
3898 ahd->msgin_index = 0;
3899 ahd->msg_type = MSG_TYPE_NONE;
3900 if ((ahd_inb(ahd, SCSISIGO) & ATNO) != 0) {
3905 ahd_outb(ahd, CLRSINT1, CLRATNO);
3907 ahd_outb(ahd, MSG_OUT, MSG_NOOP);
3908 ahd_outb(ahd, SEQ_FLAGS2,
3909 ahd_inb(ahd, SEQ_FLAGS2) & ~TARGET_MSG_PENDING);
3910 ahd_restore_modes(ahd, saved_modes);
3917 ahd_handle_message_phase(struct ahd_softc *ahd)
3923 ahd_fetch_devinfo(ahd, &devinfo);
3925 bus_phase = ahd_inb(ahd, LASTPHASE);
3927 if ((ahd_inb(ahd, LQISTAT2) & LQIPHASE_OUTPKT) != 0) {
3929 ahd_outb(ahd, LQCTL2, LQIRETRY);
3932 switch (ahd->msg_type) {
3939 if (ahd->msgout_len == 0 && ahd->send_msg_perror == 0)
3944 ahd_print_devinfo(ahd, &devinfo);
3964 ahd_outb(ahd, CLRSINT1, CLRATNO);
3965 ahd->send_msg_perror = 0;
3966 ahd->msg_type = MSG_TYPE_INITIATOR_MSGIN;
3967 ahd->msgin_index = 0;
3974 if (ahd->send_msg_perror) {
3975 ahd_outb(ahd, CLRSINT1, CLRATNO);
3976 ahd_outb(ahd, CLRSINT1, CLRREQINIT);
3979 printf(" byte 0x%x\n", ahd->send_msg_perror);
3987 if ((ahd->msg_flags & MSG_FLAG_PACKETIZED) != 0
3988 && ahd->send_msg_perror == MSG_INITIATOR_DET_ERR)
3989 ahd->msg_flags |= MSG_FLAG_EXPECT_IDE_BUSFREE;
3991 ahd_outb(ahd, RETURN_2, ahd->send_msg_perror);
3992 ahd_outb(ahd, RETURN_1, CONT_MSG_LOOP_WRITE);
3996 msgdone = ahd->msgout_index == ahd->msgout_len;
4003 ahd->msgout_index = 0;
4004 ahd_assert_atn(ahd);
4007 lastbyte = ahd->msgout_index == (ahd->msgout_len - 1);
4010 ahd_outb(ahd, CLRSINT1, CLRATNO);
4017 ahd_outb(ahd, CLRSINT1, CLRREQINIT);
4021 ahd->msgout_buf[ahd->msgout_index]);
4023 ahd_outb(ahd, RETURN_2, ahd->msgout_buf[ahd->msgout_index++]);
4024 ahd_outb(ahd, RETURN_1, CONT_MSG_LOOP_WRITE);
4034 ahd_print_devinfo(ahd, &devinfo);
4047 ahd->msgin_index = 0;
4049 && (ahd->send_msg_perror != 0
4050 || (ahd->msgout_len != 0
4051 && ahd->msgout_index == 0))) {
4052 ahd->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
4060 ahd->msgin_buf[ahd->msgin_index] = ahd_inb(ahd, SCSIBUS);
4064 ahd->msgin_buf[ahd->msgin_index]);
4067 message_done = ahd_parse_msg(ahd, &devinfo);
4074 ahd->msgin_index = 0;
4081 if (ahd->msgout_len != 0) {
4084 ahd_print_devinfo(ahd, &devinfo);
4088 ahd_assert_atn(ahd);
4091 ahd->msgin_index++;
4097 ahd_outb(ahd, CLRSINT1, CLRREQINIT);
4098 ahd_outb(ahd, RETURN_1, CONT_MSG_LOOP_READ);
4110 ahd_outb(ahd, RETURN_1, CONT_MSG_LOOP_TARG);
4112 if (ahd->msgout_len == 0)
4121 if ((ahd_inb(ahd, SCSISIGI) & ATNI) != 0
4122 && ahd->msgout_index > 0)
4135 ahd->msg_type = MSG_TYPE_TARGET_MSGOUT;
4136 ahd_outb(ahd, SCSISIGO, P_MESGOUT | BSYO);
4137 ahd->msgin_index = 0;
4139 ahd_inb(ahd, SCSIDAT);
4140 ahd_outb(ahd, SXFRCTL0,
4141 ahd_inb(ahd, SXFRCTL0) | SPIOEN);
4145 msgdone = ahd->msgout_index == ahd->msgout_len;
4147 ahd_outb(ahd, SXFRCTL0,
4148 ahd_inb(ahd, SXFRCTL0) & ~SPIOEN);
4156 ahd_outb(ahd, SXFRCTL0, ahd_inb(ahd, SXFRCTL0) | SPIOEN);
4157 ahd_outb(ahd, SCSIDAT, ahd->msgout_buf[ahd->msgout_index++]);
4168 ahd_outb(ahd, RETURN_1, CONT_MSG_LOOP_TARG);
4174 lastbyte = (ahd_inb(ahd, SCSISIGI) & ATNI) == 0;
4181 ahd_outb(ahd, SXFRCTL0, ahd_inb(ahd, SXFRCTL0) & ~SPIOEN);
4182 ahd->msgin_buf[ahd->msgin_index] = ahd_inb(ahd, SCSIDAT);
4183 msgdone = ahd_parse_msg(ahd, &devinfo);
4194 ahd->msgin_index++;
4197 ahd->msgin_index = 0;
4203 if (ahd->msgout_len != 0) {
4204 ahd_outb(ahd, SCSISIGO, P_MESGIN | BSYO);
4205 ahd_outb(ahd, SXFRCTL0,
4206 ahd_inb(ahd, SXFRCTL0) | SPIOEN);
4207 ahd->msg_type = MSG_TYPE_TARGET_MSGIN;
4208 ahd->msgin_index = 0;
4217 ahd_outb(ahd, SXFRCTL0,
4218 ahd_inb(ahd, SXFRCTL0) | SPIOEN);
4228 if ((ahd->msg_flags & MSG_FLAG_PACKETIZED) != 0) {
4230 ahd_name(ahd));
4231 ahd_clear_msg_state(ahd);
4236 ahd_outb(ahd, LASTPHASE, P_BUSFREE);
4237 ahd_outb(ahd, SEQ_FLAGS, NOT_IDENTIFIED|NO_CDB_SENT);
4238 ahd_outb(ahd, SEQCTL0, FASTMODE|SEQRESET);
4240 ahd_clear_msg_state(ahd);
4241 ahd_outb(ahd, RETURN_1, EXIT_MSG_LOOP);
4253 ahd_sent_msg(struct ahd_softc *ahd, ahd_msgtype type, u_int msgval, int full)
4261 while (index < ahd->msgout_len) {
4262 if (ahd->msgout_buf[index] == MSG_EXTENDED) {
4265 end_index = index + 1 + ahd->msgout_buf[index + 1];
4266 if (ahd->msgout_buf[index+2] == msgval
4270 if (ahd->msgout_index > end_index)
4272 } else if (ahd->msgout_index > index)
4276 } else if (ahd->msgout_buf[index] >= MSG_SIMPLE_TASK
4277 && ahd->msgout_buf[index] <= MSG_IGN_WIDE_RESIDUE) {
4284 && ahd->msgout_index > index
4285 && (ahd->msgout_buf[index] == msgval
4286 || ((ahd->msgout_buf[index] & MSG_IDENTIFYFLAG) != 0
4302 ahd_parse_msg(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
4313 tinfo = ahd_fetch_transinfo(ahd, devinfo->channel, devinfo->our_scsiid,
4327 switch (ahd->msgin_buf[0]) {
4340 response = ahd_handle_msg_reject(ahd, devinfo);
4348 if (ahd->msgin_index < 2)
4350 switch (ahd->msgin_buf[2]) {
4358 if (ahd->msgin_buf[1] != MSG_EXT_SDTR_LEN) {
4370 if (ahd->msgin_index < (MSG_EXT_SDTR_LEN + 1))
4373 period = ahd->msgin_buf[3];
4375 saved_offset = offset = ahd->msgin_buf[4];
4376 ahd_devlimited_syncrate(ahd, tinfo, &period,
4378 ahd_validate_offset(ahd, tinfo, period, &offset,
4384 ahd_name(ahd), devinfo->channel,
4386 ahd->msgin_buf[3], saved_offset,
4389 ahd_set_syncrate(ahd, devinfo, period,
4399 if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_SDTR, TRUE)) {
4413 ahd_name(ahd), devinfo->channel,
4416 ahd->msgout_index = 0;
4417 ahd->msgout_len = 0;
4418 ahd_construct_sdtr(ahd, devinfo,
4420 ahd->msgout_index = 0;
4433 if (ahd->msgin_buf[1] != MSG_EXT_WDTR_LEN) {
4445 if (ahd->msgin_index < (MSG_EXT_WDTR_LEN + 1))
4448 bus_width = ahd->msgin_buf[3];
4450 ahd_validate_width(ahd, tinfo, &bus_width,
4455 ahd_name(ahd), devinfo->channel,
4460 if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_WDTR, TRUE)) {
4471 ahd_name(ahd), devinfo->channel,
4484 ahd_name(ahd), devinfo->channel,
4487 ahd->msgout_index = 0;
4488 ahd->msgout_len = 0;
4489 ahd_construct_wdtr(ahd, devinfo, bus_width);
4490 ahd->msgout_index = 0;
4503 ahd_update_neg_request(ahd, devinfo, tstate,
4505 ahd_set_width(ahd, devinfo, bus_width,
4513 ahd->msgout_index = 0;
4514 ahd->msgout_len = 0;
4515 ahd_build_transfer_msg(ahd, devinfo);
4516 ahd->msgout_index = 0;
4532 if (ahd->msgin_buf[1] != MSG_EXT_PPR_LEN) {
4544 if (ahd->msgin_index < (MSG_EXT_PPR_LEN + 1))
4547 period = ahd->msgin_buf[3];
4548 offset = ahd->msgin_buf[5];
4549 bus_width = ahd->msgin_buf[6];
4551 ppr_options = ahd->msgin_buf[7];
4570 ahd_validate_width(ahd, tinfo, &bus_width,
4572 ahd_devlimited_syncrate(ahd, tinfo, &period,
4574 ahd_validate_offset(ahd, tinfo, period, &offset,
4577 if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_PPR, TRUE)) {
4596 ahd_name(ahd), devinfo->channel,
4601 ahd_name(ahd), devinfo->channel,
4603 ahd->msgout_index = 0;
4604 ahd->msgout_len = 0;
4605 ahd_construct_ppr(ahd, devinfo, period, offset,
4607 ahd->msgout_index = 0;
4615 ahd_name(ahd), devinfo->channel,
4617 saved_width, ahd->msgin_buf[3],
4621 ahd_set_width(ahd, devinfo, bus_width,
4624 ahd_set_syncrate(ahd, devinfo, period,
4641 ahd_handle_devreset(ahd, devinfo, CAM_LUN_WILDCARD,
4645 ahd_restart(ahd);
4660 if (ahd->msgin_buf[0] == MSG_ABORT_TAG)
4661 tag = ahd_inb(ahd, INITIATOR_TAG);
4662 ahd_abort_scbs(ahd, devinfo->target, devinfo->channel,
4666 tstate = ahd->enabled_targets[devinfo->our_scsiid];
4672 ahd_queue_lstate_event(ahd, lstate,
4674 ahd->msgin_buf[0],
4676 ahd_send_lstate_events(ahd, lstate);
4679 ahd_restart(ahd);
4688 ahd_name(ahd), ahd_inb(ahd, SCSISIGI));
4690 ahd->msg_flags |= MSG_FLAG_EXPECT_QASREJ_BUSFREE;
4702 ahd->msgout_index = 0;
4703 ahd->msgout_len = 1;
4704 ahd->msgout_buf[0] = MSG_MESSAGE_REJECT;
4711 ahd->msgout_len = 0;
4720 ahd_handle_msg_reject(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
4735 scb_index = ahd_get_scbptr(ahd);
4736 scb = ahd_lookup_scb(ahd, scb_index);
4737 tinfo = ahd_fetch_transinfo(ahd, devinfo->channel,
4741 last_msg = ahd_inb(ahd, LAST_MSG);
4743 if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_PPR, /*full*/FALSE)) {
4744 if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_PPR, /*full*/TRUE)
4754 ahd_name(ahd), devinfo->channel,
4769 ahd_name(ahd), devinfo->channel,
4776 ahd->msgout_index = 0;
4777 ahd->msgout_len = 0;
4778 ahd_build_transfer_msg(ahd, devinfo);
4779 ahd->msgout_index = 0;
4781 } else if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_WDTR, /*full*/FALSE)) {
4785 "8bit transfers\n", ahd_name(ahd),
4787 ahd_set_width(ahd, devinfo, MSG_EXT_WDTR_BUS_8_BIT,
4800 ahd->msgout_index = 0;
4801 ahd->msgout_len = 0;
4802 ahd_build_transfer_msg(ahd, devinfo);
4803 ahd->msgout_index = 0;
4806 } else if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_SDTR, /*full*/FALSE)) {
4808 ahd_set_syncrate(ahd, devinfo, /*period*/0,
4814 ahd_name(ahd), devinfo->channel,
4824 "Performing non-tagged I/O\n", ahd_name(ahd),
4826 ahd_set_tags(ahd, scb->io_ctx, devinfo, AHD_QUEUE_NONE);
4831 ahd_name(ahd), devinfo->channel, devinfo->target,
4834 ahd_set_tags(ahd, scb->io_ctx, devinfo, AHD_QUEUE_BASIC);
4842 ahd_outb(ahd, SCB_CONTROL,
4843 ahd_inb_scbram(ahd, SCB_CONTROL) & mask);
4847 ahd_outb(ahd, MSG_OUT, MSG_IDENTIFYFLAG);
4848 ahd_assert_atn(ahd);
4849 ahd_busy_tcl(ahd, BUILD_TCL(scb->hscb->scsiid, devinfo->lun),
4857 ahd_search_qinfifo(ahd, SCB_GET_TARGET(ahd, scb),
4858 SCB_GET_CHANNEL(ahd, scb),
4862 } else if (ahd_sent_msg(ahd, AHDMSG_1B, MSG_IDENTIFYFLAG, TRUE)) {
4867 ahd->msg_flags |= MSG_FLAG_EXPECT_PPR_BUSFREE
4870 ahd_force_renegotiation(ahd, devinfo);
4871 ahd->msgout_index = 0;
4872 ahd->msgout_len = 0;
4873 ahd_build_transfer_msg(ahd, devinfo);
4874 ahd->msgout_index = 0;
4881 ahd_name(ahd), devinfo->channel, devinfo->target,
4891 ahd_handle_ign_wide_residue(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
4896 scb_index = ahd_get_scbptr(ahd);
4897 scb = ahd_lookup_scb(ahd, scb_index);
4898 if ((ahd_inb(ahd, SEQ_FLAGS) & DPHASE) == 0
4914 sgptr = ahd_inb_scbram(ahd, SCB_RESIDUAL_SGPTR);
4916 && (ahd_inb_scbram(ahd, SCB_TASK_ATTRIBUTE)
4930 sgptr = ahd_inl_scbram(ahd, SCB_RESIDUAL_SGPTR);
4931 data_cnt = ahd_inl_scbram(ahd, SCB_RESIDUAL_DATACNT);
4940 data_addr = ahd_inq(ahd, SHADDR);
4944 if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0) {
4947 sg = ahd_sg_bus_to_virt(ahd, scb, sgptr);
4974 sgptr = ahd_sg_virt_to_bus(ahd, scb,
4980 sg = ahd_sg_bus_to_virt(ahd, scb, sgptr);
5007 sgptr = ahd_sg_virt_to_bus(ahd, scb,
5017 ahd_outb(ahd, SCB_TASK_ATTRIBUTE,
5018 ahd_inb_scbram(ahd, SCB_TASK_ATTRIBUTE)
5021 ahd_outl(ahd, SCB_RESIDUAL_SGPTR, sgptr);
5022 ahd_outl(ahd, SCB_RESIDUAL_DATACNT, data_cnt);
5037 ahd_reinitialize_dataptrs(struct ahd_softc *ahd)
5047 AHD_ASSERT_MODES(ahd, AHD_MODE_DFF0_MSK|AHD_MODE_DFF1_MSK,
5050 scb_index = ahd_get_scbptr(ahd);
5051 scb = ahd_lookup_scb(ahd, scb_index);
5057 ahd_outb(ahd, DFFSXFRCTL, CLRCHN);
5059 while (--wait && !(ahd_inb(ahd, MDFFSTAT) & FIFOFREE))
5062 ahd_print_path(ahd, scb);
5064 ahd_outb(ahd, DFFSXFRCTL, RSTCHN|CLRSHCNT);
5066 saved_modes = ahd_save_modes(ahd);
5067 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
5068 ahd_outb(ahd, DFFSTAT,
5069 ahd_inb(ahd, DFFSTAT)
5076 sgptr = ahd_inl_scbram(ahd, SCB_RESIDUAL_SGPTR);
5079 resid = (ahd_inb_scbram(ahd, SCB_RESIDUAL_DATACNT + 2) << 16)
5080 | (ahd_inb_scbram(ahd, SCB_RESIDUAL_DATACNT + 1) << 8)
5081 | ahd_inb_scbram(ahd, SCB_RESIDUAL_DATACNT);
5083 if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0) {
5086 sg = ahd_sg_bus_to_virt(ahd, scb, sgptr);
5094 ahd_outl(ahd, HADDR + 4, dataptr >> 32);
5098 sg = ahd_sg_bus_to_virt(ahd, scb, sgptr);
5106 ahd_outb(ahd, HADDR + 4,
5109 ahd_outl(ahd, HADDR, dataptr);
5110 ahd_outb(ahd, HCNT + 2, resid >> 16);
5111 ahd_outb(ahd, HCNT + 1, resid >> 8);
5112 ahd_outb(ahd, HCNT, resid);
5119 ahd_handle_devreset(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
5128 found = ahd_abort_scbs(ahd, devinfo->target, devinfo->channel,
5137 tstate = ahd->enabled_targets[devinfo->our_scsiid];
5156 ahd_queue_lstate_event(ahd, lstate, devinfo->our_scsiid,
5158 ahd_send_lstate_events(ahd, lstate);
5166 ahd_set_width(ahd, devinfo, MSG_EXT_WDTR_BUS_8_BIT,
5168 ahd_set_syncrate(ahd, devinfo, /*period*/0, /*offset*/0,
5173 ahd_send_async(ahd, devinfo->channel, devinfo->target,
5177 printf("%s: %s on %c:%d. %d SCBs aborted\n", ahd_name(ahd),
5183 ahd_setup_target_msgin(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
5192 ahd->msgout_index = 0;
5193 ahd->msgout_len = 0;
5196 ahd_build_transfer_msg(ahd, devinfo);
5200 ahd->msgout_index = 0;
5201 ahd->msg_type = MSG_TYPE_TARGET_MSGIN;
5206 ahd_sglist_size(struct ahd_softc *ahd)
5211 if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0)
5223 ahd_sglist_allocsize(struct ahd_softc *ahd)
5231 sg_list_increment = ahd_sglist_size(ahd);
5270 struct ahd_softc *ahd;
5273 ahd = malloc(sizeof(*ahd), M_DEVBUF, M_NOWAIT);
5274 if (!ahd) {
5280 ahd = device_get_softc((device_t)platform_arg);
5282 memset(ahd, 0, sizeof(*ahd));
5283 ahd->seep_config = malloc(sizeof(*ahd->seep_config),
5285 if (ahd->seep_config == NULL) {
5287 free(ahd, M_DEVBUF);
5292 LIST_INIT(&ahd->pending_scbs);
5294 ahd->name = name;
5295 ahd->unit = -1;
5296 ahd->description = NULL;
5297 ahd->bus_description = NULL;
5298 ahd->channel = 'A';
5299 ahd->chip = AHD_NONE;
5300 ahd->features = AHD_FENONE;
5301 ahd->bugs = AHD_BUGNONE;
5302 ahd->flags = AHD_SPCHK_ENB_A|AHD_RESET_BUS_A|AHD_TERM_ENB_A
5304 ahd_timer_init(&ahd->reset_timer);
5305 ahd_timer_init(&ahd->stat_timer);
5306 ahd->int_coalescing_timer = AHD_INT_COALESCING_TIMER_DEFAULT;
5307 ahd->int_coalescing_maxcmds = AHD_INT_COALESCING_MAXCMDS_DEFAULT;
5308 ahd->int_coalescing_mincmds = AHD_INT_COALESCING_MINCMDS_DEFAULT;
5309 ahd->int_coalescing_threshold = AHD_INT_COALESCING_THRESHOLD_DEFAULT;
5310 ahd->int_coalescing_stop_threshold =
5313 if (ahd_platform_alloc(ahd, platform_arg) != 0) {
5314 ahd_free(ahd);
5315 ahd = NULL;
5320 ahd_name(ahd), (u_int)sizeof(struct scb),
5324 return (ahd);
5328 ahd_softc_init(struct ahd_softc *ahd)
5331 ahd->unpause = 0;
5332 ahd->pause = PAUSE;
5337 ahd_set_unit(struct ahd_softc *ahd, int unit)
5339 ahd->unit = unit;
5343 ahd_set_name(struct ahd_softc *ahd, char *name)
5345 if (ahd->name != NULL)
5346 free(ahd->name, M_DEVBUF);
5347 ahd->name = name;
5351 ahd_free(struct ahd_softc *ahd)
5355 switch (ahd->init_level) {
5358 ahd_shutdown(ahd);
5361 ahd_dmamap_unload(ahd, ahd->shared_data_dmat,
5362 ahd->shared_data_map.dmamap);
5365 ahd_dmamem_free(ahd, ahd->shared_data_dmat, ahd->qoutfifo,
5366 ahd->shared_data_map.dmamap);
5367 ahd_dmamap_destroy(ahd, ahd->shared_data_dmat,
5368 ahd->shared_data_map.dmamap);
5371 ahd_dma_tag_destroy(ahd, ahd->shared_data_dmat);
5374 ahd_dma_tag_destroy(ahd, ahd->buffer_dmat);
5382 ahd_dma_tag_destroy(ahd, ahd->parent_dmat);
5384 ahd_platform_free(ahd);
5385 ahd_fini_scbdata(ahd);
5389 tstate = ahd->enabled_targets[i];
5408 if (ahd->black_hole != NULL) {
5409 xpt_free_path(ahd->black_hole->path);
5410 free(ahd->black_hole, M_DEVBUF);
5413 if (ahd->name != NULL)
5414 free(ahd->name, M_DEVBUF);
5415 if (ahd->seep_config != NULL)
5416 free(ahd->seep_config, M_DEVBUF);
5417 if (ahd->saved_stack != NULL)
5418 free(ahd->saved_stack, M_DEVBUF);
5420 free(ahd, M_DEVBUF);
5428 struct ahd_softc *ahd;
5430 ahd = (struct ahd_softc *)arg;
5435 ahd_timer_stop(&ahd->reset_timer);
5436 ahd_timer_stop(&ahd->stat_timer);
5439 ahd_reset(ahd, /*reinit*/FALSE);
5452 ahd_reset(struct ahd_softc *ahd, int reinit)
5463 ahd_pause(ahd);
5464 ahd_update_modes(ahd);
5465 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
5466 sxfrctl1 = ahd_inb(ahd, SXFRCTL1);
5468 cmd = ahd_pci_read_config(ahd->dev_softc, PCIR_COMMAND, /*bytes*/2);
5469 if ((ahd->bugs & AHD_PCIX_CHIPRST_BUG) != 0) {
5482 ahd_pci_write_config(ahd->dev_softc, PCIR_COMMAND,
5485 ahd_outb(ahd, HCNTRL, CHIPRST | ahd->pause);
5496 } while (--wait && !(ahd_inb(ahd, HCNTRL) & CHIPRSTACK));
5500 "Trying to initialize anyway.\n", ahd_name(ahd));
5502 ahd_outb(ahd, HCNTRL, ahd->pause);
5504 if ((ahd->bugs & AHD_PCIX_CHIPRST_BUG) != 0) {
5509 ahd_pci_write_config(ahd->dev_softc, PCIR_STATUS + 1,
5511 ahd_pci_write_config(ahd->dev_softc, PCIR_COMMAND,
5521 ahd_known_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
5522 ahd_outb(ahd, MODE_PTR,
5523 ahd_build_mode_state(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI));
5533 ahd_outb(ahd, SXFRCTL1, sxfrctl1|STPWEN);
5534 ahd_outb(ahd, SXFRCTL1, sxfrctl1);
5537 ahd->features &= ~AHD_WIDE;
5538 if ((ahd_inb(ahd, SBLKCTL) & SELWIDE) != 0)
5539 ahd->features |= AHD_WIDE;
5546 ahd_chip_init(ahd);
5555 ahd_probe_scbs(struct ahd_softc *ahd) {
5558 AHD_ASSERT_MODES(ahd, ~(AHD_MODE_UNKNOWN_MSK|AHD_MODE_CFG_MSK),
5563 ahd_set_scbptr(ahd, i);
5564 ahd_outw(ahd, SCB_BASE, i);
5566 ahd_outb(ahd, SCB_BASE+j, 0);
5568 ahd_outb(ahd, SCB_CONTROL, MK_MESSAGE);
5569 if (ahd_inw_scbram(ahd, SCB_BASE) != i)
5571 ahd_set_scbptr(ahd, 0);
5572 if (ahd_inw_scbram(ahd, SCB_BASE) != 0)
5588 ahd_initialize_hscbs(struct ahd_softc *ahd)
5592 for (i = 0; i < ahd->scb_data.maxhscbs; i++) {
5593 ahd_set_scbptr(ahd, i);
5596 ahd_outb(ahd, SCB_CONTROL, 0);
5599 ahd_outw(ahd, SCB_NEXT, SCB_LIST_NULL);
5604 ahd_init_scbdata(struct ahd_softc *ahd)
5609 scb_data = &ahd->scb_data;
5619 scb_data->maxhscbs = ahd_probe_scbs(ahd);
5621 printf("%s: No SCB space found\n", ahd_name(ahd));
5625 ahd_initialize_hscbs(ahd);
5638 if (ahd_dma_tag_create(ahd, ahd->parent_dmat, /*alignment*/1,
5652 if (ahd_dma_tag_create(ahd, ahd->parent_dmat, /*alignment*/8,
5657 ahd_sglist_allocsize(ahd), /*nsegments*/1,
5664 printf("%s: ahd_sglist_allocsize = 0x%x\n", ahd_name(ahd),
5665 ahd_sglist_allocsize(ahd));
5671 if (ahd_dma_tag_create(ahd, ahd->parent_dmat, /*alignment*/1,
5685 ahd_alloc_scbs(ahd);
5690 ahd_name(ahd));
5705 ahd_find_scb_by_tag(struct ahd_softc *ahd, u_int tag)
5712 LIST_FOREACH(scb, &ahd->pending_scbs, pending_links) {
5720 TAILQ_FOREACH(scb, &ahd->scb_data.free_scbs, links.tqe) {
5734 LIST_FOREACH(scb, &ahd->scb_data.any_dev_free_scb_list, links.le) {
5743 ahd_fini_scbdata(struct ahd_softc *ahd)
5747 scb_data = &ahd->scb_data;
5759 ahd_dmamap_unload(ahd, scb_data->sense_dmat,
5761 ahd_dmamem_free(ahd, scb_data->sense_dmat,
5765 ahd_dma_tag_destroy(ahd, scb_data->sense_dmat);
5774 ahd_dmamap_unload(ahd, scb_data->sg_dmat,
5776 ahd_dmamem_free(ahd, scb_data->sg_dmat,
5780 ahd_dma_tag_destroy(ahd, scb_data->sg_dmat);
5789 ahd_dmamap_unload(ahd, scb_data->hscb_dmat,
5791 ahd_dmamem_free(ahd, scb_data->hscb_dmat,
5795 ahd_dma_tag_destroy(ahd, scb_data->hscb_dmat);
5812 ahd_setup_iocell_workaround(struct ahd_softc *ahd)
5816 saved_modes = ahd_save_modes(ahd);
5817 ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
5818 ahd_outb(ahd, DSPDATACTL, ahd_inb(ahd, DSPDATACTL)
5820 ahd_outb(ahd, SIMODE0, ahd_inb(ahd, SIMODE0) | (ENSELDO|ENSELDI));
5823 printf("%s: Setting up iocell workaround\n", ahd_name(ahd));
5825 ahd_restore_modes(ahd, saved_modes);
5826 ahd->flags &= ~AHD_HAD_FIRST_SEL;
5830 ahd_iocell_first_selection(struct ahd_softc *ahd)
5835 if ((ahd->flags & AHD_HAD_FIRST_SEL) != 0)
5837 saved_modes = ahd_save_modes(ahd);
5838 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
5839 sblkctl = ahd_inb(ahd, SBLKCTL);
5840 ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
5843 printf("%s: iocell first selection\n", ahd_name(ahd));
5846 ahd_outb(ahd, DSPDATACTL,
5847 ahd_inb(ahd, DSPDATACTL) & ~BYPASSENAB);
5850 printf("%s: BYPASS now disabled\n", ahd_name(ahd));
5853 ahd_outb(ahd, SIMODE0, ahd_inb(ahd, SIMODE0) & ~(ENSELDO|ENSELDI));
5854 ahd_outb(ahd, CLRINT, CLRSCSIINT);
5855 ahd_restore_modes(ahd, saved_modes);
5856 ahd->flags |= AHD_HAD_FIRST_SEL;
5861 ahd_add_col_list(struct ahd_softc *ahd, struct scb *scb, u_int col_idx)
5869 free_list = &ahd->scb_data.free_scb_lists[col_idx];
5870 free_tailq = &ahd->scb_data.free_scbs;
5881 ahd_rem_col_list(struct ahd_softc *ahd, struct scb *scb)
5889 col_idx = AHD_GET_SCB_COL_IDX(ahd, scb);
5890 free_list = &ahd->scb_data.free_scb_lists[col_idx];
5891 free_tailq = &ahd->scb_data.free_scbs;
5915 ahd_get_scb(struct ahd_softc *ahd, u_int col_idx)
5922 TAILQ_FOREACH(scb, &ahd->scb_data.free_scbs, links.tqe) {
5923 if (AHD_GET_SCB_COL_IDX(ahd, scb) != col_idx) {
5924 ahd_rem_col_list(ahd, scb);
5928 if ((scb = LIST_FIRST(&ahd->scb_data.any_dev_free_scb_list)) == NULL) {
5932 ahd_alloc_scbs(ahd);
5940 ahd_add_col_list(ahd, scb->col_scb, col_idx);
5951 ahd_free_scb(struct ahd_softc *ahd, struct scb *scb)
5957 ahd->scb_data.scbindex[SCB_GET_TAG(scb)] = NULL;
5964 LIST_INSERT_HEAD(&ahd->scb_data.any_dev_free_scb_list,
5973 ahd_rem_col_list(ahd, scb->col_scb);
5974 LIST_INSERT_HEAD(&ahd->scb_data.any_dev_free_scb_list,
5976 LIST_INSERT_HEAD(&ahd->scb_data.any_dev_free_scb_list,
5987 ahd_add_col_list(ahd, scb,
5988 AHD_GET_SCB_COL_IDX(ahd, scb->col_scb));
5996 LIST_INSERT_HEAD(&ahd->scb_data.any_dev_free_scb_list,
6000 ahd_platform_scb_free(ahd, scb);
6004 ahd_alloc_scbs(struct ahd_softc *ahd)
6020 scb_data = &ahd->scb_data;
6039 if (ahd_dmamem_alloc(ahd, scb_data->hscb_dmat,
6048 ahd_dmamap_load(ahd, scb_data->hscb_dmat, hscb_map->dmamap,
6060 offset = ((ahd_sglist_allocsize(ahd) / ahd_sglist_size(ahd))
6061 - scb_data->sgs_left) * ahd_sglist_size(ahd);
6072 if (ahd_dmamem_alloc(ahd, scb_data->sg_dmat,
6081 ahd_dmamap_load(ahd, scb_data->sg_dmat, sg_map->dmamap,
6082 sg_map->vaddr, ahd_sglist_allocsize(ahd),
6088 ahd_sglist_allocsize(ahd) / ahd_sglist_size(ahd);
6109 if (ahd_dmamem_alloc(ahd, scb_data->sense_dmat,
6118 ahd_dmamap_load(ahd, scb_data->sense_dmat, sense_map->dmamap,
6168 if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0)
6173 next_scb->ahd_softc = ahd;
6176 error = ahd_dmamap_create(ahd, ahd->buffer_dmat, /*flags*/0,
6186 next_scb->col_scb = ahd_find_scb_by_tag(ahd, col_tag);
6189 ahd_free_scb(ahd, next_scb);
6192 segs += ahd_sglist_size(ahd);
6193 sg_busaddr += ahd_sglist_size(ahd);
6204 ahd_controller_info(struct ahd_softc *ahd, char *buf)
6210 len = sprintf(buf, "%s: ", ahd_chip_names[ahd->chip & AHD_CHIPID_MASK]);
6214 if ((ahd->features & AHD_WIDE) != 0) {
6220 speed, type, ahd->channel, ahd->our_id);
6223 sprintf(buf, "%s, %d SCBs", ahd->bus_description,
6224 ahd->scb_data.maxhscbs);
6245 ahd_init(struct ahd_softc *ahd)
6256 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
6258 ahd->stack_size = ahd_probe_stack_size(ahd);
6259 ahd->saved_stack = malloc(ahd->stack_size * sizeof(uint16_t),
6261 if (ahd->saved_stack == NULL)
6273 ahd->flags |= AHD_SEQUENCER_DEBUG;
6279 ahd->flags |= AHD_INITIATORROLE;
6284 if ((AHD_TMODE_ENABLE & (0x1 << ahd->unit)) == 0)
6285 ahd->features &= ~AHD_TARGETMODE;
6289 if (ahd_dma_tag_create(ahd, ahd->parent_dmat, /*alignment*/1,
6291 /*lowaddr*/ahd->flags & AHD_39BIT_ADDRESSING
6300 &ahd->buffer_dmat) != 0) {
6305 ahd->init_level++;
6314 driver_data_size = AHD_SCB_MAX * sizeof(*ahd->qoutfifo)
6316 if ((ahd->features & AHD_TARGETMODE) != 0)
6318 if ((ahd->bugs & AHD_PKT_BITBUCKET_BUG) != 0)
6320 if (ahd_dma_tag_create(ahd, ahd->parent_dmat, /*alignment*/1,
6328 /*flags*/0, &ahd->shared_data_dmat) != 0) {
6332 ahd->init_level++;
6335 if (ahd_dmamem_alloc(ahd, ahd->shared_data_dmat,
6336 (void **)&ahd->shared_data_map.vaddr,
6338 &ahd->shared_data_map.dmamap) != 0) {
6342 ahd->init_level++;
6345 ahd_dmamap_load(ahd, ahd->shared_data_dmat, ahd->shared_data_map.dmamap,
6346 ahd->shared_data_map.vaddr, driver_data_size,
6347 ahd_dmamap_cb, &ahd->shared_data_map.physaddr,
6349 ahd->qoutfifo = (struct ahd_completion *)ahd->shared_data_map.vaddr;
6350 next_vaddr = (uint8_t *)&ahd->qoutfifo[AHD_QOUT_SIZE];
6351 next_baddr = ahd->shared_data_map.physaddr
6353 if ((ahd->features & AHD_TARGETMODE) != 0) {
6354 ahd->targetcmds = (struct target_cmd *)next_vaddr;
6359 if ((ahd->bugs & AHD_PKT_BITBUCKET_BUG) != 0) {
6360 ahd->overrun_buf = next_vaddr;
6372 ahd->next_queued_hscb = (struct hardware_scb *)next_vaddr;
6373 ahd->next_queued_hscb_map = &ahd->shared_data_map;
6374 ahd->next_queued_hscb->hscb_busaddr = ahd_htole32(next_baddr);
6376 ahd->init_level++;
6379 if (ahd_init_scbdata(ahd) != 0)
6382 if ((ahd->flags & AHD_INITIATORROLE) == 0)
6383 ahd->flags &= ~AHD_RESET_BUS_A;
6389 ahd_platform_init(ahd);
6392 ahd_chip_init(ahd);
6394 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
6396 if ((ahd->flags & AHD_CURRENT_SENSING) == 0)
6403 error = ahd_write_flexport(ahd, FLXADDR_ROMSTAT_CURSENSECTL,
6406 printf("%s: current sensing timeout 1\n", ahd_name(ahd));
6411 error = ahd_read_flexport(ahd, FLXADDR_FLEXSTAT, &fstat);
6414 ahd_name(ahd));
6420 ahd_name(ahd));
6425 error = ahd_read_flexport(ahd, FLXADDR_CURRENT_STAT, &current_sensing);
6427 printf("%s: current sensing timeout 3\n", ahd_name(ahd));
6432 ahd_write_flexport(ahd, FLXADDR_ROMSTAT_CURSENSECTL, 0);
6437 ahd_name(ahd), current_sensing);
6453 printf("%s: %s Channel %s\n", ahd_name(ahd),
6461 ahd_name(ahd), ahd_name(ahd));
6464 ahd_restart(ahd);
6465 ahd_timer_reset(&ahd->stat_timer, AHD_STAT_UPDATE_US,
6466 ahd_stat_timer, ahd);
6474 ahd_chip_init(struct ahd_softc *ahd)
6483 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
6487 ahd_outb(ahd, SBLKCTL, ahd_inb(ahd, SBLKCTL) & ~(DIAGLEDEN|DIAGLEDON));
6492 ahd->hs_mailbox = 0;
6493 ahd_outb(ahd, HS_MAILBOX, 0);
6496 ahd_outb(ahd, IOWNID, ahd->our_id);
6497 ahd_outb(ahd, TOWNID, ahd->our_id);
6498 sxfrctl1 = (ahd->flags & AHD_TERM_ENB_A) != 0 ? STPWEN : 0;
6499 sxfrctl1 |= (ahd->flags & AHD_SPCHK_ENB_A) != 0 ? ENSPCHK : 0;
6500 if ((ahd->bugs & AHD_LONG_SETIMO_BUG)
6501 && (ahd->seltime != STIMESEL_MIN)) {
6507 sxfrctl1 |= ahd->seltime + STIMESEL_BUG_ADJ;
6509 sxfrctl1 |= ahd->seltime;
6512 ahd_outb(ahd, SXFRCTL0, DFON);
6513 ahd_outb(ahd, SXFRCTL1, sxfrctl1|ahd->seltime|ENSTIMER|ACTNEGEN);
6514 ahd_outb(ahd, SIMODE1, ENSELTIMO|ENSCSIRST|ENSCSIPERR);
6524 (ahd_inb(ahd, SBLKCTL) & (ENAB40|ENAB20)) == 0 && wait;
6529 ahd_outb(ahd, CLRSINT1, CLRSCSIRSTI);
6530 ahd_outb(ahd, CLRINT, CLRSCSIINT);
6534 ahd_set_modes(ahd, AHD_MODE_DFF0 + i, AHD_MODE_DFF0 + i);
6535 ahd_outb(ahd, LONGJMP_ADDR + 1, INVALID_ADDR);
6536 ahd_outb(ahd, SG_STATE, 0);
6537 ahd_outb(ahd, CLRSEQINTSRC, 0xFF);
6538 ahd_outb(ahd, SEQIMODE,
6543 ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
6544 ahd_outb(ahd, DSCOMMAND0, ahd_inb(ahd, DSCOMMAND0)|MPARCKEN|CACHETHEN);
6545 ahd_outb(ahd, DFF_THRSH, RD_DFTHRSH_75|WR_DFTHRSH_75);
6546 ahd_outb(ahd, SIMODE0, ENIOERR|ENOVERRUN);
6547 ahd_outb(ahd, SIMODE3, ENNTRAMPERR|ENOSRAMPERR);
6548 if ((ahd->bugs & AHD_BUSFREEREV_BUG) != 0) {
6549 ahd_outb(ahd, OPTIONMODE, AUTOACKEN|AUTO_MSGOUT_DE);
6551 ahd_outb(ahd, OPTIONMODE, AUTOACKEN|BUSFREEREV|AUTO_MSGOUT_DE);
6553 ahd_outb(ahd, SCSCHKN, CURRFIFODEF|WIDERESEN|SHVALIDSTDIS);
6554 if ((ahd->chip & AHD_BUS_MASK) == AHD_PCIX)
6560 ahd_outb(ahd, PCIXCTL, ahd_inb(ahd, PCIXCTL) | SPLTSTADIS);
6562 if ((ahd->bugs & AHD_LQOOVERRUN_BUG) != 0)
6563 ahd_outb(ahd, LQOSCSCTL, LQONOCHKOVER);
6568 if ((ahd->flags & AHD_HP_BOARD) != 0) {
6570 ahd_outb(ahd, DSPSELECT, i);
6571 ahd_outb(ahd, WRTBIASCTL, WRTBIASCTL_HP_DEFAULT);
6575 printf("%s: WRTBIASCTL now 0x%x\n", ahd_name(ahd),
6579 ahd_setup_iocell_workaround(ahd);
6584 ahd_outb(ahd, LQIMODE1, ENLQIPHASE_LQ|ENLQIPHASE_NLQ|ENLIQABORT
6587 ahd_outb(ahd, LQOMODE0, ENLQOATNLQ|ENLQOATNPKT|ENLQOTCRC);
6596 ahd_outb(ahd, LQOMODE1, ENLQOBUSFREE);
6601 ahd_outw(ahd, INTVEC1_ADDR, ahd_resolve_seqaddr(ahd, LABEL_seq_isr));
6602 ahd_outw(ahd, INTVEC2_ADDR, ahd_resolve_seqaddr(ahd, LABEL_timer_isr));
6607 if ((ahd->bugs & AHD_PKT_LUN_BUG) != 0) {
6608 ahd_outb(ahd, LUNPTR, offsetof(struct hardware_scb,
6611 ahd_outb(ahd, LUNPTR, offsetof(struct hardware_scb, lun));
6613 ahd_outb(ahd, CMDLENPTR, offsetof(struct hardware_scb, cdb_len));
6614 ahd_outb(ahd, ATTRPTR, offsetof(struct hardware_scb, task_attribute));
6615 ahd_outb(ahd, FLAGPTR, offsetof(struct hardware_scb, task_management));
6616 ahd_outb(ahd, CMDPTR, offsetof(struct hardware_scb,
6618 ahd_outb(ahd, QNEXTPTR,
6620 ahd_outb(ahd, ABRTBITPTR, MK_MESSAGE_BIT_OFFSET);
6621 ahd_outb(ahd, ABRTBYTEPTR, offsetof(struct hardware_scb, control));
6622 if ((ahd->bugs & AHD_PKT_LUN_BUG) != 0) {
6623 ahd_outb(ahd, LUNLEN,
6624 sizeof(ahd->next_queued_hscb->pkt_long_lun) - 1);
6626 ahd_outb(ahd, LUNLEN, LUNLEN_SINGLE_LEVEL_LUN);
6628 ahd_outb(ahd, CDBLIMIT, SCB_CDB_LEN_PTR - 1);
6629 ahd_outb(ahd, MAXCMD, 0xFF);
6630 ahd_outb(ahd, SCBAUTOPTR,
6634 ahd_outb(ahd, MULTARGID, 0);
6635 ahd_outb(ahd, MULTARGID + 1, 0);
6637 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
6639 if ((ahd->features & AHD_NEW_IOCELL_OPTS) == 0) {
6645 ahd_outb(ahd, NEGOADDR, target);
6646 ahd_outb(ahd, ANNEXCOL, AHD_ANNEXCOL_PER_DEV0);
6648 ahd_outb(ahd, ANNEXDAT, 0);
6656 tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
6658 ahd_compile_devinfo(&devinfo, ahd->our_id,
6661 ahd_update_neg_table(ahd, &devinfo, &tinfo->curr);
6664 ahd_outb(ahd, CLRSINT3, NTRAMPERR|OSRAMPERR);
6665 ahd_outb(ahd, CLRINT, CLRSCSIINT);
6672 if ((ahd->bugs & AHD_ABORT_LQI_BUG) == 0)
6673 ahd_outb(ahd, LQCTL1, ABORTPENDING);
6676 ahd_outb(ahd, LQCTL1, 0);
6679 ahd->qoutfifonext = 0;
6680 ahd->qoutfifonext_valid_tag = QOUTFIFO_ENTRY_VALID;
6681 ahd_outb(ahd, QOUTFIFO_ENTRY_VALID_TAG, QOUTFIFO_ENTRY_VALID);
6683 ahd->qoutfifo[i].valid_tag = 0;
6684 ahd_sync_qoutfifo(ahd, BUS_DMASYNC_PREREAD);
6686 ahd->qinfifonext = 0;
6688 ahd->qinfifo[i] = SCB_LIST_NULL;
6690 if ((ahd->features & AHD_TARGETMODE) != 0) {
6693 ahd->targetcmds[i].cmd_valid = 0;
6694 ahd_sync_tqinfifo(ahd, BUS_DMASYNC_PREREAD);
6695 ahd->tqinfifonext = 1;
6696 ahd_outb(ahd, KERNEL_TQINPOS, ahd->tqinfifonext - 1);
6697 ahd_outb(ahd, TQINPOS, ahd->tqinfifonext);
6701 ahd_outb(ahd, SEQ_FLAGS, 0);
6702 ahd_outb(ahd, SEQ_FLAGS2, 0);
6705 ahd_outw(ahd, WAITING_TID_HEAD, SCB_LIST_NULL);
6706 ahd_outw(ahd, WAITING_TID_TAIL, SCB_LIST_NULL);
6707 ahd_outw(ahd, MK_MESSAGE_SCB, SCB_LIST_NULL);
6708 ahd_outw(ahd, MK_MESSAGE_SCSIID, 0xFF);
6710 ahd_outw(ahd, WAITING_SCB_TAILS + (2 * i), SCB_LIST_NULL);
6715 ahd_outw(ahd, COMPLETE_SCB_HEAD, SCB_LIST_NULL);
6716 ahd_outw(ahd, COMPLETE_SCB_DMAINPROG_HEAD, SCB_LIST_NULL);
6717 ahd_outw(ahd, COMPLETE_DMA_SCB_HEAD, SCB_LIST_NULL);
6718 ahd_outw(ahd, COMPLETE_DMA_SCB_TAIL, SCB_LIST_NULL);
6719 ahd_outw(ahd, COMPLETE_ON_QFREEZE_HEAD, SCB_LIST_NULL);
6724 ahd->qfreeze_cnt = 0;
6725 ahd_outw(ahd, QFREEZE_COUNT, 0);
6726 ahd_outw(ahd, KERNEL_QFREEZE_COUNT, 0);
6731 busaddr = ahd->shared_data_map.physaddr;
6732 ahd_outl(ahd, SHARED_DATA_ADDR, busaddr);
6733 ahd_outl(ahd, QOUTFIFO_NEXT_ADDR, busaddr);
6741 if ((ahd->flags & AHD_INITIATORROLE) != 0)
6743 ahd_outb(ahd, SCSISEQ_TEMPLATE, scsiseq_template);
6750 ahd_unbusy_tcl(ahd, BUILD_TCL_RAW(target, 'A', lun));
6759 ahd_outb(ahd, CMDSIZE_TABLE, 5);
6760 ahd_outb(ahd, CMDSIZE_TABLE + 1, 9);
6761 ahd_outb(ahd, CMDSIZE_TABLE + 2, 9);
6762 ahd_outb(ahd, CMDSIZE_TABLE + 3, 0);
6763 ahd_outb(ahd, CMDSIZE_TABLE + 4, 15);
6764 ahd_outb(ahd, CMDSIZE_TABLE + 5, 11);
6765 ahd_outb(ahd, CMDSIZE_TABLE + 6, 0);
6766 ahd_outb(ahd, CMDSIZE_TABLE + 7, 0);
6769 ahd_set_modes(ahd, AHD_MODE_CCHAN, AHD_MODE_CCHAN);
6770 ahd_outb(ahd, QOFF_CTLSTA, SCB_QSIZE_512);
6771 ahd->qinfifonext = 0;
6772 ahd_set_hnscb_qoff(ahd, ahd->qinfifonext);
6773 ahd_set_hescb_qoff(ahd, 0);
6774 ahd_set_snscb_qoff(ahd, 0);
6775 ahd_set_sescb_qoff(ahd, 0);
6776 ahd_set_sdscb_qoff(ahd, 0);
6781 busaddr = ahd_le32toh(ahd->next_queued_hscb->hscb_busaddr);
6782 ahd_outl(ahd, NEXT_QUEUED_SCB_ADDR, busaddr);
6787 ahd_outw(ahd, INT_COALESCING_CMDCOUNT, 0);
6788 ahd_outw(ahd, CMDS_PENDING, 0);
6789 ahd_update_coalescing_values(ahd, ahd->int_coalescing_timer,
6790 ahd->int_coalescing_maxcmds,
6791 ahd->int_coalescing_mincmds);
6792 ahd_enable_coalescing(ahd, FALSE);
6794 ahd_loadseq(ahd);
6795 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
6797 if (ahd->features & AHD_AIC79XXB_SLOWCRC) {
6798 u_int negodat3 = ahd_inb(ahd, NEGCONOPTS);
6801 ahd_outb(ahd, NEGCONOPTS, negodat3);
6802 negodat3 = ahd_inb(ahd, NEGCONOPTS);
6816 ahd_default_config(struct ahd_softc *ahd)
6820 ahd->our_id = 7;
6827 if (ahd_alloc_tstate(ahd, ahd->our_id, 'A') == NULL) {
6829 "Failing attach\n", ahd_name(ahd));
6839 tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
6848 ahd->user_discenable |= target_mask;
6850 ahd->user_tagenable |= target_mask;
6863 if ((ahd->features & AHD_RTI) != 0)
6876 ahd_compile_devinfo(&devinfo, ahd->our_id,
6880 ahd_set_width(ahd, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
6882 ahd_set_syncrate(ahd, &devinfo, /*period*/0, /*offset*/0,
6893 ahd_parse_cfgdata(struct ahd_softc *ahd, struct seeprom_config *sc)
6899 ahd->our_id = sc->brtime_id & CFSCSIID;
6906 if (ahd_alloc_tstate(ahd, ahd->our_id, 'A') == NULL) {
6908 "Failing attach\n", ahd_name(ahd));
6919 tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
6930 ahd->user_discenable &= ~target_mask;
6932 ahd->user_tagenable &= ~target_mask;
6935 ahd->user_discenable |= target_mask;
6936 ahd->user_tagenable |= target_mask;
6964 if ((ahd->features & AHD_RTI) != 0)
6990 ahd_compile_devinfo(&devinfo, ahd->our_id,
6993 ahd_set_width(ahd, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
6995 ahd_set_syncrate(ahd, &devinfo, /*period*/0, /*offset*/0,
7000 ahd->flags &= ~AHD_SPCHK_ENB_A;
7002 ahd->flags |= AHD_SPCHK_ENB_A;
7004 ahd->flags &= ~AHD_RESET_BUS_A;
7006 ahd->flags |= AHD_RESET_BUS_A;
7008 ahd->flags &= ~AHD_EXTENDED_TRANS_A;
7010 ahd->flags |= AHD_EXTENDED_TRANS_A;
7012 ahd->flags &= ~AHD_BIOS_ENABLED;
7014 ahd->flags |= AHD_BIOS_ENABLED;
7016 ahd->flags &= ~AHD_STPWLEVEL_A;
7018 ahd->flags |= AHD_STPWLEVEL_A;
7027 ahd_parse_vpddata(struct ahd_softc *ahd, struct vpd_config *vpd)
7035 ahd->flags |= AHD_BOOT_CHANNEL;
7040 ahd_intr_enable(struct ahd_softc *ahd, int enable)
7044 hcntrl = ahd_inb(ahd, HCNTRL);
7046 ahd->pause &= ~INTEN;
7047 ahd->unpause &= ~INTEN;
7050 ahd->pause |= INTEN;
7051 ahd->unpause |= INTEN;
7053 ahd_outb(ahd, HCNTRL, hcntrl);
7057 ahd_update_coalescing_values(struct ahd_softc *ahd, u_int timer, u_int maxcmds,
7062 ahd->int_coalescing_timer = timer;
7068 ahd->int_coalescing_maxcmds = maxcmds;
7069 ahd_outw(ahd, INT_COALESCING_TIMER, timer / AHD_TIMER_US_PER_TICK);
7070 ahd_outb(ahd, INT_COALESCING_MAXCMDS, -maxcmds);
7071 ahd_outb(ahd, INT_COALESCING_MINCMDS, -mincmds);
7075 ahd_enable_coalescing(struct ahd_softc *ahd, int enable)
7078 ahd->hs_mailbox &= ~ENINT_COALESCE;
7080 ahd->hs_mailbox |= ENINT_COALESCE;
7081 ahd_outb(ahd, HS_MAILBOX, ahd->hs_mailbox);
7082 ahd_flush_device_writes(ahd);
7083 ahd_run_qoutfifo(ahd);
7094 ahd_pause_and_flushwork(struct ahd_softc *ahd)
7100 ahd->flags |= AHD_ALL_INTERRUPTS;
7101 ahd_pause(ahd);
7107 ahd->qfreeze_cnt--;
7108 ahd_outw(ahd, KERNEL_QFREEZE_COUNT, ahd->qfreeze_cnt);
7109 ahd_outb(ahd, SEQ_FLAGS2, ahd_inb(ahd, SEQ_FLAGS2) | SELECTOUT_QFROZEN);
7112 ahd_unpause(ahd);
7119 ahd_intr(ahd);
7120 ahd_pause(ahd);
7121 intstat = ahd_inb(ahd, INTSTAT);
7123 ahd_clear_critical_section(ahd);
7124 intstat = ahd_inb(ahd, INTSTAT);
7127 && (intstat != 0xFF || (ahd->features & AHD_REMOVABLE) == 0)
7129 || (ahd_inb(ahd, SCSISEQ0) & ENSELO) != 0
7130 || (ahd_inb(ahd, SSTAT0) & (SELDO|SELINGO)) != 0));
7134 ahd_inb(ahd, INTSTAT));
7136 ahd->qfreeze_cnt++;
7137 ahd_outw(ahd, KERNEL_QFREEZE_COUNT, ahd->qfreeze_cnt);
7139 ahd_flush_qoutfifo(ahd);
7141 ahd->flags &= ~AHD_ALL_INTERRUPTS;
7156 ahd_index_busy_tcl(struct ahd_softc *ahd, u_int *saved_scbid, u_int tcl)
7161 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
7162 *saved_scbid = ahd_get_scbptr(ahd);
7163 ahd_set_scbptr(ahd, TCL_LUN(tcl)
7178 ahd_find_busy_tcl(struct ahd_softc *ahd, u_int tcl)
7184 scb_offset = ahd_index_busy_tcl(ahd, &saved_scbptr, tcl);
7185 scbid = ahd_inw_scbram(ahd, scb_offset);
7186 ahd_set_scbptr(ahd, saved_scbptr);
7191 ahd_busy_tcl(struct ahd_softc *ahd, u_int tcl, u_int scbid)
7196 scb_offset = ahd_index_busy_tcl(ahd, &saved_scbptr, tcl);
7197 ahd_outw(ahd, scb_offset, scbid);
7198 ahd_set_scbptr(ahd, saved_scbptr);
7203 ahd_match_scb(struct ahd_softc *ahd, struct scb *scb, int target,
7206 int targ = SCB_GET_TARGET(ahd, scb);
7207 char chan = SCB_GET_CHANNEL(ahd, scb);
7239 ahd_freeze_devq(struct ahd_softc *ahd, struct scb *scb)
7245 target = SCB_GET_TARGET(ahd, scb);
7247 channel = SCB_GET_CHANNEL(ahd, scb);
7249 ahd_search_qinfifo(ahd, target, channel, lun,
7253 ahd_platform_freeze_devq(ahd, scb);
7257 ahd_qinfifo_requeue_tail(struct ahd_softc *ahd, struct scb *scb)
7262 saved_modes = ahd_save_modes(ahd);
7263 ahd_set_modes(ahd, AHD_MODE_CCHAN, AHD_MODE_CCHAN);
7265 if (ahd_qinfifo_count(ahd) != 0) {
7269 prev_pos = AHD_QIN_WRAP(ahd->qinfifonext - 1);
7270 prev_tag = ahd->qinfifo[prev_pos];
7271 prev_scb = ahd_lookup_scb(ahd, prev_tag);
7273 ahd_qinfifo_requeue(ahd, prev_scb, scb);
7274 ahd_set_hnscb_qoff(ahd, ahd->qinfifonext);
7275 ahd_restore_modes(ahd, saved_modes);
7279 ahd_qinfifo_requeue(struct ahd_softc *ahd, struct scb *prev_scb,
7286 ahd_outl(ahd, NEXT_QUEUED_SCB_ADDR, busaddr);
7289 ahd_sync_scb(ahd, prev_scb,
7292 ahd->qinfifo[AHD_QIN_WRAP(ahd->qinfifonext)] = SCB_GET_TAG(scb);
7293 ahd->qinfifonext++;
7294 scb->hscb->next_hscb_busaddr = ahd->next_queued_hscb->hscb_busaddr;
7295 ahd_sync_scb(ahd, scb, BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
7299 ahd_qinfifo_count(struct ahd_softc *ahd)
7305 AHD_ASSERT_MODES(ahd, AHD_MODE_CCHAN_MSK, AHD_MODE_CCHAN_MSK);
7306 qinpos = ahd_get_snscb_qoff(ahd);
7308 wrap_qinfifonext = AHD_QIN_WRAP(ahd->qinfifonext);
7313 + ARRAY_SIZE(ahd->qinfifo) - wrap_qinpos);
7317 ahd_reset_cmds_pending(struct ahd_softc *ahd)
7323 saved_modes = ahd_save_modes(ahd);
7324 ahd_set_modes(ahd, AHD_MODE_CCHAN, AHD_MODE_CCHAN);
7330 ahd_flush_qoutfifo(ahd);
7333 LIST_FOREACH(scb, &ahd->pending_scbs, pending_links) {
7336 ahd_outw(ahd, CMDS_PENDING, pending_cmds - ahd_qinfifo_count(ahd));
7337 ahd_restore_modes(ahd, saved_modes);
7338 ahd->flags &= ~AHD_UPDATE_PEND_CMDS;
7342 ahd_done_with_status(struct ahd_softc *ahd, struct scb *scb, uint32_t status)
7353 ahd_done(ahd, scb);
7357 ahd_search_qinfifo(struct ahd_softc *ahd, int target, char channel,
7378 saved_modes = ahd_save_modes(ahd);
7379 ahd_set_modes(ahd, AHD_MODE_CCHAN, AHD_MODE_CCHAN);
7385 if ((ahd_inb(ahd, CCSCBCTL) & (CCARREN|CCSCBEN|CCSCBDIR))
7387 ahd_outb(ahd, CCSCBCTL,
7388 ahd_inb(ahd, CCSCBCTL) & ~(CCARREN|CCSCBEN));
7389 while ((ahd_inb(ahd, CCSCBCTL) & (CCARREN|CCSCBEN)) != 0)
7393 qintail = AHD_QIN_WRAP(ahd->qinfifonext);
7394 qinstart = ahd_get_snscb_qoff(ahd);
7401 qinstart, ahd->qinfifonext);
7408 ahd->qinfifonext = qinstart;
7409 busaddr = ahd_le32toh(ahd->next_queued_hscb->hscb_busaddr);
7410 ahd_outl(ahd, NEXT_QUEUED_SCB_ADDR, busaddr);
7413 scb = ahd_lookup_scb(ahd, ahd->qinfifo[qinpos]);
7416 qinpos, ahd->qinfifo[qinpos]);
7420 if (ahd_match_scb(ahd, scb, target, channel, lun, tag, role)) {
7429 ahd_done_with_status(ahd, scb, status);
7434 printf(" 0x%x", ahd->qinfifo[qinpos]);
7437 ahd_qinfifo_requeue(ahd, prev_scb, scb);
7442 ahd_qinfifo_requeue(ahd, prev_scb, scb);
7448 ahd_set_hnscb_qoff(ahd, ahd->qinfifonext);
7459 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
7460 seq_flags2 = ahd_inb(ahd, SEQ_FLAGS2);
7462 scbid = ahd_inw(ahd, MK_MESSAGE_SCB);
7463 mk_msg_scb = ahd_lookup_scb(ahd, scbid);
7466 savedscbptr = ahd_get_scbptr(ahd);
7467 tid_next = ahd_inw(ahd, WAITING_TID_HEAD);
7478 if (scbid >= ahd->scb_data.numscbs) {
7481 ahd_name(ahd), scbid, ahd->scb_data.numscbs);
7482 ahd_dump_card_state(ahd);
7485 scb = ahd_lookup_scb(ahd, scbid);
7488 ahd_name(ahd), scbid);
7491 ahd_set_scbptr(ahd, scbid);
7492 tid_next = ahd_inw_scbram(ahd, SCB_NEXT2);
7493 if (ahd_match_scb(ahd, scb, target, channel, CAM_LUN_WILDCARD,
7503 printf(" %d ( ", SCB_GET_TARGET(ahd, scb));
7505 found += ahd_search_scb_list(ahd, target, channel,
7508 SCB_GET_TARGET(ahd, scb));
7514 && ahd_match_scb(ahd, mk_msg_scb, target, channel,
7525 ahd_done_with_status(ahd, mk_msg_scb, status);
7538 + (2 * SCB_GET_TARGET(ahd, mk_msg_scb));
7539 ahd_outw(ahd, tail_offset, tid_tail);
7542 ahd_outb(ahd, SEQ_FLAGS2, seq_flags2);
7543 ahd_outw(ahd, CMDS_PENDING,
7544 ahd_inw(ahd, CMDS_PENDING)-1);
7558 && ahd_match_scb(ahd, scb, target, channel, CAM_LUN_WILDCARD,
7567 tid_head = ahd_inw(ahd, MK_MESSAGE_SCB);
7569 ahd_outb(ahd, SEQ_FLAGS2, seq_flags2);
7573 ahd_stitch_tid_list(ahd, tid_prev, tid_head, tid_next);
7581 ahd_set_scbptr(ahd, savedscbptr);
7582 ahd_restore_modes(ahd, saved_modes);
7587 ahd_search_scb_list(struct ahd_softc *ahd, int target, char channel,
7598 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
7604 if (scbid >= ahd->scb_data.numscbs) {
7607 ahd_name(ahd), scbid, ahd->scb_data.numscbs);
7608 ahd_dump_card_state(ahd);
7611 scb = ahd_lookup_scb(ahd, scbid);
7614 ahd_name(ahd), scbid);
7617 ahd_set_scbptr(ahd, scbid);
7619 next = ahd_inw_scbram(ahd, SCB_NEXT);
7620 if (ahd_match_scb(ahd, scb, target, channel,
7630 ahd_done_with_status(ahd, scb, status);
7633 ahd_rem_wscb(ahd, scbid, prev, next, tid);
7649 ahd_outw(ahd, CMDS_PENDING, ahd_inw(ahd, CMDS_PENDING) - found);
7654 ahd_stitch_tid_list(struct ahd_softc *ahd, u_int tid_prev,
7657 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
7663 ahd_outw(ahd, WAITING_TID_HEAD, tid_next);
7665 ahd_set_scbptr(ahd, tid_prev);
7666 ahd_outw(ahd, SCB_NEXT2, tid_next);
7669 ahd_outw(ahd, WAITING_TID_TAIL, tid_prev);
7674 ahd_outw(ahd, WAITING_TID_HEAD, tid_cur);
7676 ahd_set_scbptr(ahd, tid_prev);
7677 ahd_outw(ahd, SCB_NEXT2, tid_cur);
7679 ahd_set_scbptr(ahd, tid_cur);
7680 ahd_outw(ahd, SCB_NEXT2, tid_next);
7683 ahd_outw(ahd, WAITING_TID_TAIL, tid_cur);
7692 ahd_rem_wscb(struct ahd_softc *ahd, u_int scbid,
7697 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
7699 ahd_set_scbptr(ahd, prev);
7700 ahd_outw(ahd, SCB_NEXT, next);
7712 && ahd_inw(ahd, tail_offset) == scbid)
7713 ahd_outw(ahd, tail_offset, prev);
7715 ahd_add_scb_to_free_list(ahd, scbid);
7725 ahd_add_scb_to_free_list(struct ahd_softc *ahd, u_int scbid)
7730 ahd_outb(ahd, SCB_TAG, SCB_LIST_NULL);
7742 ahd_abort_scbs(struct ahd_softc *ahd, int target, char channel,
7755 saved_modes = ahd_save_modes(ahd);
7756 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
7758 found = ahd_search_qinfifo(ahd, target, channel, lun, SCB_LIST_NULL,
7790 scbid = ahd_find_busy_tcl(ahd, tcl);
7791 scbp = ahd_lookup_scb(ahd, scbid);
7793 || ahd_match_scb(ahd, scbp, target, channel,
7796 ahd_unbusy_tcl(ahd, BUILD_TCL_RAW(i, 'A', j));
7805 ahd_flush_qoutfifo(ahd);
7813 scbp_next = LIST_FIRST(&ahd->pending_scbs);
7817 if (ahd_match_scb(ahd, scbp, target, channel, lun, tag, role)) {
7827 ahd_done(ahd, scbp);
7831 ahd_restore_modes(ahd, saved_modes);
7832 ahd_platform_abort_scbs(ahd, target, channel, lun, tag, role, status);
7833 ahd->flags |= AHD_UPDATE_PEND_CMDS;
7838 ahd_reset_current_bus(struct ahd_softc *ahd)
7842 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
7843 ahd_outb(ahd, SIMODE1, ahd_inb(ahd, SIMODE1) & ~ENSCSIRST);
7844 scsiseq = ahd_inb(ahd, SCSISEQ0) & ~(ENSELO|ENARBO|SCSIRSTO);
7845 ahd_outb(ahd, SCSISEQ0, scsiseq | SCSIRSTO);
7846 ahd_flush_device_writes(ahd);
7849 ahd_outb(ahd, SCSISEQ0, scsiseq);
7850 ahd_flush_device_writes(ahd);
7852 if ((ahd->bugs & AHD_SCSIRST_BUG) != 0) {
7859 ahd_reset(ahd, /*reinit*/TRUE);
7860 ahd_intr_enable(ahd, /*enable*/TRUE);
7861 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
7864 ahd_clear_intstat(ahd);
7868 ahd_reset_channel(struct ahd_softc *ahd, char channel, int initiate_reset)
7882 if (ahd->flags & AHD_BUS_RESET_ACTIVE) {
7884 ahd_name(ahd));
7887 ahd->flags |= AHD_BUS_RESET_ACTIVE;
7889 ahd->pending_device = NULL;
7896 ahd_pause(ahd);
7899 ahd_clear_critical_section(ahd);
7906 ahd_run_qoutfifo(ahd);
7908 if ((ahd->flags & AHD_TARGETROLE) != 0) {
7909 ahd_run_tqinfifo(ahd, /*paused*/TRUE);
7912 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
7918 ahd_outb(ahd, SCSISEQ0, 0);
7919 ahd_outb(ahd, SCSISEQ1, 0);
7926 next_fifo = fifo = ahd_inb(ahd, DFFSTAT) & CURRFIFO;
7932 ahd_set_modes(ahd, next_fifo, next_fifo);
7933 ahd_outb(ahd, DFCNTRL,
7934 ahd_inb(ahd, DFCNTRL) & ~(SCSIEN|HDMAEN));
7935 while ((ahd_inb(ahd, DFCNTRL) & HDMAENACK) != 0)
7940 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
7941 ahd_outb(ahd, DFFSTAT, next_fifo);
7947 ahd_clear_msg_state(ahd);
7948 ahd_outb(ahd, SIMODE1,
7949 ahd_inb(ahd, SIMODE1) & ~(ENBUSFREE|ENSCSIRST));
7952 ahd_reset_current_bus(ahd);
7954 ahd_clear_intstat(ahd);
7960 found = ahd_abort_scbs(ahd, CAM_TARGET_WILDCARD, channel,
7967 ahd_clear_fifo(ahd, 0);
7968 ahd_clear_fifo(ahd, 1);
7973 ahd_outb(ahd, CLRSINT1, CLRSCSIRSTI);
7978 ahd_outb(ahd, SIMODE1, ahd_inb(ahd, SIMODE1) | ENSCSIRST);
7979 scsiseq = ahd_inb(ahd, SCSISEQ_TEMPLATE);
7980 ahd_outb(ahd, SCSISEQ1, scsiseq & (ENSELI|ENRSELI|ENAUTOATNP));
7982 max_scsiid = (ahd->features & AHD_WIDE) ? 15 : 7;
7992 tstate = ahd->enabled_targets[target];
8002 ahd_queue_lstate_event(ahd, lstate, CAM_TARGET_WILDCARD,
8004 ahd_send_lstate_events(ahd, lstate);
8013 if (ahd->enabled_targets[target] == NULL)
8021 ahd_set_width(ahd, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
8023 ahd_set_syncrate(ahd, &devinfo, /*period*/0,
8030 ahd_send_async(ahd, devinfo.channel, CAM_TARGET_WILDCARD,
8033 ahd_restart(ahd);
8042 struct ahd_softc *ahd = arg;
8046 ahd_lock(ahd, &s);
8048 enint_coal = ahd->hs_mailbox & ENINT_COALESCE;
8049 if (ahd->cmdcmplt_total > ahd->int_coalescing_threshold)
8051 else if (ahd->cmdcmplt_total < ahd->int_coalescing_stop_threshold)
8054 if (enint_coal != (ahd->hs_mailbox & ENINT_COALESCE)) {
8055 ahd_enable_coalescing(ahd, enint_coal);
8060 ahd_name(ahd),
8062 ahd->cmdcmplt_total);
8066 ahd->cmdcmplt_bucket = (ahd->cmdcmplt_bucket+1) & (AHD_STAT_BUCKETS-1);
8067 ahd->cmdcmplt_total -= ahd->cmdcmplt_counts[ahd->cmdcmplt_bucket];
8068 ahd->cmdcmplt_counts[ahd->cmdcmplt_bucket] = 0;
8069 ahd_timer_reset(&ahd->stat_timer, AHD_STAT_UPDATE_US,
8070 ahd_stat_timer, ahd);
8071 ahd_unlock(ahd, &s);
8077 ahd_handle_scsi_status(struct ahd_softc *ahd, struct scb *scb)
8093 if (ahd_is_paused(ahd)) {
8097 ahd_pause(ahd);
8101 ahd_freeze_devq(ahd, scb);
8103 ahd->qfreeze_cnt++;
8104 ahd_outw(ahd, KERNEL_QFREEZE_COUNT, ahd->qfreeze_cnt);
8107 ahd_unpause(ahd);
8117 ahd_done(ahd, scb);
8127 ahd_sync_sense(ahd, scb, BUS_DMASYNC_POSTREAD);
8132 ahd_print_path(ahd, scb);
8142 ahd_print_path(ahd, scb);
8180 ahd_done(ahd, scb);
8194 ahd_print_path(ahd, scb);
8204 SCB_GET_TARGET(ahd, scb),
8206 SCB_GET_CHANNEL(ahd, scb),
8208 targ_info = ahd_fetch_transinfo(ahd,
8219 ahd_update_residual(ahd, scb);
8222 ahd_print_path(ahd, scb);
8227 sg = ahd_sg_setup(ahd, scb, sg, ahd_get_sense_bufaddr(ahd, scb),
8228 ahd_get_sense_bufsize(ahd, scb),
8237 sc->length = ahd_get_sense_bufsize(ahd, scb);
8258 ahd_update_neg_request(ahd, &devinfo,
8269 ahd_setup_data_scb(ahd, scb);
8271 ahd_queue_scb(ahd, scb);
8276 ahd_name(ahd));
8279 ahd_done(ahd, scb);
8285 ahd_handle_scb_status(struct ahd_softc *ahd, struct scb *scb)
8288 ahd_handle_scsi_status(ahd, scb);
8290 ahd_calc_residual(ahd, scb);
8291 ahd_done(ahd, scb);
8299 ahd_calc_residual(struct ahd_softc *ahd, struct scb *scb)
8349 ahd_print_path(ahd, scb);
8352 ahd_freeze_devq(ahd, scb);
8367 sg = ahd_sg_bus_to_virt(ahd, scb, resid_sgptr & SG_PTR_MASK);
8389 ahd_print_path(ahd, scb);
8402 ahd_queue_lstate_event(struct ahd_softc *ahd, struct ahd_tmode_lstate *lstate,
8453 ahd_send_lstate_events(struct ahd_softc *ahd, struct ahd_tmode_lstate *lstate)
8489 ahd_dumpseq(struct ahd_softc* ahd)
8496 ahd_outb(ahd, SEQCTL0, PERRORDIS|FAILDIS|FASTMODE|LOADRAM);
8497 ahd_outw(ahd, PRGMCNT, 0);
8501 ahd_insb(ahd, SEQRAM, ins_bytes, 4);
8511 ahd_loadseq(struct ahd_softc *ahd)
8531 ahd_name(ahd));
8563 sg_prefetch_align = ahd->pci_cachesize;
8586 if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0)
8610 (ahd->overrun_buf - (uint8_t *)ahd->qoutfifo) / 256;
8616 ahd_outb(ahd, SEQCTL0, PERRORDIS|FAILDIS|FASTMODE|LOADRAM);
8617 ahd_outw(ahd, PRGMCNT, 0);
8620 if (ahd_check_patch(ahd, &cur_patch, i, &skip_addr) == 0) {
8648 ahd_download_instr(ahd, i, download_consts);
8652 ahd->num_critical_sections = cs_count;
8656 ahd->critical_sections = malloc(cs_count, M_DEVBUF, M_NOWAIT);
8657 if (ahd->critical_sections == NULL)
8659 memcpy(ahd->critical_sections, cs_table, cs_count);
8661 ahd_outb(ahd, SEQCTL0, PERRORDIS|FAILDIS|FASTMODE);
8666 ahd_name(ahd), ahd->features, ahd->bugs, ahd->flags);
8671 ahd_check_patch(struct ahd_softc *ahd, struct patch **start_patch,
8684 if (cur_patch->patch_func(ahd) == 0) {
8707 ahd_resolve_seqaddr(struct ahd_softc *ahd, u_int address)
8720 ahd_check_patch(ahd, &cur_patch, i, &skip_addr);
8736 ahd_download_instr(struct ahd_softc *ahd, u_int instrptr, uint8_t *dconsts)
8764 fmt3_ins->address = ahd_resolve_seqaddr(ahd, fmt3_ins->address);
8795 ahd_outsb(ahd, SEQRAM, instr.bytes, 4);
8805 ahd_probe_stack_size(struct ahd_softc *ahd)
8820 ahd_outb(ahd, STACK, i & 0xFF);
8821 ahd_outb(ahd, STACK, (i >> 8) & 0xFF);
8828 stack_entry = ahd_inb(ahd, STACK)
8829 |(ahd_inb(ahd, STACK) << 8);
8888 ahd_dump_card_state(struct ahd_softc *ahd)
8899 if (ahd_is_paused(ahd)) {
8903 ahd_pause(ahd);
8905 saved_modes = ahd_save_modes(ahd);
8906 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
8909 ahd_name(ahd),
8910 ahd_inw(ahd, CURADDR),
8911 ahd_build_mode_state(ahd, ahd->saved_src_mode,
8912 ahd->saved_dst_mode));
8916 if (ahd_check_cmdcmpltqueues(ahd))
8923 ahd_intstat_print(ahd_inb(ahd, INTSTAT), &cur_col, 50);
8924 ahd_seloid_print(ahd_inb(ahd, SELOID), &cur_col, 50);
8925 ahd_selid_print(ahd_inb(ahd, SELID), &cur_col, 50);
8926 ahd_hs_mailbox_print(ahd_inb(ahd, LOCAL_HS_MAILBOX), &cur_col, 50);
8927 ahd_intctl_print(ahd_inb(ahd, INTCTL), &cur_col, 50);
8928 ahd_seqintstat_print(ahd_inb(ahd, SEQINTSTAT), &cur_col, 50);
8929 ahd_saved_mode_print(ahd_inb(ahd, SAVED_MODE), &cur_col, 50);
8930 ahd_dffstat_print(ahd_inb(ahd, DFFSTAT), &cur_col, 50);
8931 ahd_scsisigi_print(ahd_inb(ahd, SCSISIGI), &cur_col, 50);
8932 ahd_scsiphase_print(ahd_inb(ahd, SCSIPHASE), &cur_col, 50);
8933 ahd_scsibus_print(ahd_inb(ahd, SCSIBUS), &cur_col, 50);
8934 ahd_lastphase_print(ahd_inb(ahd, LASTPHASE), &cur_col, 50);
8935 ahd_scsiseq0_print(ahd_inb(ahd, SCSISEQ0), &cur_col, 50);
8936 ahd_scsiseq1_print(ahd_inb(ahd, SCSISEQ1), &cur_col, 50);
8937 ahd_seqctl0_print(ahd_inb(ahd, SEQCTL0), &cur_col, 50);
8938 ahd_seqintctl_print(ahd_inb(ahd, SEQINTCTL), &cur_col, 50);
8939 ahd_seq_flags_print(ahd_inb(ahd, SEQ_FLAGS), &cur_col, 50);
8940 ahd_seq_flags2_print(ahd_inb(ahd, SEQ_FLAGS2), &cur_col, 50);
8941 ahd_qfreeze_count_print(ahd_inw(ahd, QFREEZE_COUNT), &cur_col, 50);
8942 ahd_kernel_qfreeze_count_print(ahd_inw(ahd, KERNEL_QFREEZE_COUNT),
8944 ahd_mk_message_scb_print(ahd_inw(ahd, MK_MESSAGE_SCB), &cur_col, 50);
8945 ahd_mk_message_scsiid_print(ahd_inb(ahd, MK_MESSAGE_SCSIID),
8947 ahd_sstat0_print(ahd_inb(ahd, SSTAT0), &cur_col, 50);
8948 ahd_sstat1_print(ahd_inb(ahd, SSTAT1), &cur_col, 50);
8949 ahd_sstat2_print(ahd_inb(ahd, SSTAT2), &cur_col, 50);
8950 ahd_sstat3_print(ahd_inb(ahd, SSTAT3), &cur_col, 50);
8951 ahd_perrdiag_print(ahd_inb(ahd, PERRDIAG), &cur_col, 50);
8952 ahd_simode1_print(ahd_inb(ahd, SIMODE1), &cur_col, 50);
8953 ahd_lqistat0_print(ahd_inb(ahd, LQISTAT0), &cur_col, 50);
8954 ahd_lqistat1_print(ahd_inb(ahd, LQISTAT1), &cur_col, 50);
8955 ahd_lqistat2_print(ahd_inb(ahd, LQISTAT2), &cur_col, 50);
8956 ahd_lqostat0_print(ahd_inb(ahd, LQOSTAT0), &cur_col, 50);
8957 ahd_lqostat1_print(ahd_inb(ahd, LQOSTAT1), &cur_col, 50);
8958 ahd_lqostat2_print(ahd_inb(ahd, LQOSTAT2), &cur_col, 50);
8962 ahd->scb_data.numscbs, ahd_inw(ahd, CMDS_PENDING),
8963 ahd_inw(ahd, LASTSCB), ahd_inw(ahd, CURRSCB),
8964 ahd_inw(ahd, NEXTSCB));
8967 ahd_search_qinfifo(ahd, CAM_TARGET_WILDCARD, ALL_CHANNELS,
8970 saved_scb_index = ahd_get_scbptr(ahd);
8973 LIST_FOREACH(scb, &ahd->pending_scbs, pending_links) {
8977 ahd_inb_scbram(ahd, SCB_FIFO_USE_COUNT));
8978 ahd_set_scbptr(ahd, SCB_GET_TAG(scb));
8979 ahd_scb_control_print(ahd_inb_scbram(ahd, SCB_CONTROL),
8981 ahd_scb_scsiid_print(ahd_inb_scbram(ahd, SCB_SCSIID),
8988 TAILQ_FOREACH(scb, &ahd->scb_data.free_scbs, links.tqe) {
8998 LIST_FOREACH(scb, &ahd->scb_data.any_dev_free_scb_list, links.le) {
9006 scb_index = ahd_inw(ahd, COMPLETE_SCB_DMAINPROG_HEAD);
9009 ahd_set_scbptr(ahd, scb_index);
9011 scb_index = ahd_inw_scbram(ahd, SCB_NEXT_COMPLETE);
9016 scb_index = ahd_inw(ahd, COMPLETE_SCB_HEAD);
9019 ahd_set_scbptr(ahd, scb_index);
9021 scb_index = ahd_inw_scbram(ahd, SCB_NEXT_COMPLETE);
9027 scb_index = ahd_inw(ahd, COMPLETE_DMA_SCB_HEAD);
9030 ahd_set_scbptr(ahd, scb_index);
9032 scb_index = ahd_inw_scbram(ahd, SCB_NEXT_COMPLETE);
9036 scb_index = ahd_inw(ahd, COMPLETE_ON_QFREEZE_HEAD);
9039 ahd_set_scbptr(ahd, scb_index);
9041 scb_index = ahd_inw_scbram(ahd, SCB_NEXT_COMPLETE);
9044 ahd_set_scbptr(ahd, saved_scb_index);
9045 dffstat = ahd_inb(ahd, DFFSTAT);
9052 ahd_set_modes(ahd, AHD_MODE_DFF0 + i, AHD_MODE_DFF0 + i);
9053 fifo_scbptr = ahd_get_scbptr(ahd);
9055 ahd_name(ahd), i,
9057 ahd_inw(ahd, LONGJMP_ADDR), fifo_scbptr);
9059 ahd_seqimode_print(ahd_inb(ahd, SEQIMODE), &cur_col, 50);
9060 ahd_seqintsrc_print(ahd_inb(ahd, SEQINTSRC), &cur_col, 50);
9061 ahd_dfcntrl_print(ahd_inb(ahd, DFCNTRL), &cur_col, 50);
9062 ahd_dfstatus_print(ahd_inb(ahd, DFSTATUS), &cur_col, 50);
9063 ahd_sg_cache_shadow_print(ahd_inb(ahd, SG_CACHE_SHADOW),
9065 ahd_sg_state_print(ahd_inb(ahd, SG_STATE), &cur_col, 50);
9066 ahd_dffsxfrctl_print(ahd_inb(ahd, DFFSXFRCTL), &cur_col, 50);
9067 ahd_soffcnt_print(ahd_inb(ahd, SOFFCNT), &cur_col, 50);
9068 ahd_mdffstat_print(ahd_inb(ahd, MDFFSTAT), &cur_col, 50);
9074 ahd_inl(ahd, SHADDR+4),
9075 ahd_inl(ahd, SHADDR),
9076 (ahd_inb(ahd, SHCNT)
9077 | (ahd_inb(ahd, SHCNT + 1) << 8)
9078 | (ahd_inb(ahd, SHCNT + 2) << 16)));
9084 ahd_inl(ahd, HADDR+4),
9085 ahd_inl(ahd, HADDR),
9086 (ahd_inb(ahd, HCNT)
9087 | (ahd_inb(ahd, HCNT + 1) << 8)
9088 | (ahd_inb(ahd, HCNT + 2) << 16)));
9089 ahd_ccsgctl_print(ahd_inb(ahd, CCSGCTL), &cur_col, 50);
9092 fifo_scb = ahd_lookup_scb(ahd, fifo_scbptr);
9100 printf("0x%x ", ahd_inb(ahd, LQIN + i));
9102 ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
9104 ahd_name(ahd), ahd_inb(ahd, LQISTATE), ahd_inb(ahd, LQOSTATE),
9105 ahd_inb(ahd, OPTIONMODE));
9107 ahd_name(ahd), ahd_inb(ahd, OS_SPACE_CNT),
9108 ahd_inb(ahd, MAXCMDCNT));
9110 ahd_name(ahd), ahd_inb(ahd, SAVED_SCSIID),
9111 ahd_inb(ahd, SAVED_LUN));
9112 ahd_simode0_print(ahd_inb(ahd, SIMODE0), &cur_col, 50);
9114 ahd_set_modes(ahd, AHD_MODE_CCHAN, AHD_MODE_CCHAN);
9116 ahd_ccscbctl_print(ahd_inb(ahd, CCSCBCTL), &cur_col, 50);
9118 ahd_set_modes(ahd, ahd->saved_src_mode, ahd->saved_dst_mode);
9120 ahd_name(ahd), ahd_inw(ahd, REG0), ahd_inw(ahd, SINDEX),
9121 ahd_inw(ahd, DINDEX));
9123 ahd_name(ahd), ahd_get_scbptr(ahd),
9124 ahd_inw_scbram(ahd, SCB_NEXT),
9125 ahd_inw_scbram(ahd, SCB_NEXT2));
9127 ahd_inb_scbram(ahd, SCB_CDB_STORE),
9128 ahd_inb_scbram(ahd, SCB_CDB_STORE+1),
9129 ahd_inb_scbram(ahd, SCB_CDB_STORE+2),
9130 ahd_inb_scbram(ahd, SCB_CDB_STORE+3),
9131 ahd_inb_scbram(ahd, SCB_CDB_STORE+4),
9132 ahd_inb_scbram(ahd, SCB_CDB_STORE+5));
9134 for (i = 0; i < ahd->stack_size; i++) {
9135 ahd->saved_stack[i] =
9136 ahd_inb(ahd, STACK)|(ahd_inb(ahd, STACK) << 8);
9137 printf(" 0x%x", ahd->saved_stack[i]);
9139 for (i = ahd->stack_size-1; i >= 0; i--) {
9140 ahd_outb(ahd, STACK, ahd->saved_stack[i] & 0xFF);
9141 ahd_outb(ahd, STACK, (ahd->saved_stack[i] >> 8) & 0xFF);
9144 ahd_restore_modes(ahd, saved_modes);
9146 ahd_unpause(ahd);
9158 ahd_read_seeprom(struct ahd_softc *ahd, uint16_t *buf,
9170 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
9174 ahd_outb(ahd, SEEADR, cur_addr);
9175 ahd_outb(ahd, SEECTL, SEEOP_READ | SEESTART);
9177 error = ahd_wait_seeprom(ahd);
9184 *bytestream_ptr++ = ahd_inb(ahd, SEEDAT);
9185 *bytestream_ptr = ahd_inb(ahd, SEEDAT+1);
9190 *buf = ahd_inw(ahd, SEEDAT);
9203 ahd_write_seeprom(struct ahd_softc *ahd, uint16_t *buf,
9211 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
9215 ahd_outb(ahd, SEEADR, SEEOP_EWEN_ADDR);
9216 ahd_outb(ahd, SEECTL, SEEOP_EWEN | SEESTART);
9217 error = ahd_wait_seeprom(ahd);
9228 ahd_outw(ahd, SEEDAT, *buf++);
9229 ahd_outb(ahd, SEEADR, cur_addr);
9230 ahd_outb(ahd, SEECTL, SEEOP_WRITE | SEESTART);
9232 retval = ahd_wait_seeprom(ahd);
9240 ahd_outb(ahd, SEEADR, SEEOP_EWDS_ADDR);
9241 ahd_outb(ahd, SEECTL, SEEOP_EWDS | SEESTART);
9242 error = ahd_wait_seeprom(ahd);
9252 ahd_wait_seeprom(struct ahd_softc *ahd)
9257 while ((ahd_inb(ahd, SEESTAT) & (SEEARBACK|SEEBUSY)) != 0 && --cnt)
9320 ahd_acquire_seeprom(struct ahd_softc *ahd)
9333 ahd_release_seeprom(struct ahd_softc *ahd)
9342 ahd_wait_flexport(struct ahd_softc *ahd)
9346 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
9348 while ((ahd_inb(ahd, BRDCTL) & FLXARBACK) == 0 && --cnt)
9357 ahd_write_flexport(struct ahd_softc *ahd, u_int addr, u_int value)
9361 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
9364 ahd_outb(ahd, BRDCTL, BRDEN|(addr << 3));
9365 error = ahd_wait_flexport(ahd);
9368 ahd_outb(ahd, BRDDAT, value);
9369 ahd_flush_device_writes(ahd);
9370 ahd_outb(ahd, BRDCTL, BRDSTB|BRDEN|(addr << 3));
9371 ahd_flush_device_writes(ahd);
9372 ahd_outb(ahd, BRDCTL, BRDEN|(addr << 3));
9373 ahd_flush_device_writes(ahd);
9374 ahd_outb(ahd, BRDCTL, 0);
9375 ahd_flush_device_writes(ahd);
9380 ahd_read_flexport(struct ahd_softc *ahd, u_int addr, uint8_t *value)
9384 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
9387 ahd_outb(ahd, BRDCTL, BRDRW|BRDEN|(addr << 3));
9388 error = ahd_wait_flexport(ahd);
9391 *value = ahd_inb(ahd, BRDDAT);
9392 ahd_outb(ahd, BRDCTL, 0);
9393 ahd_flush_device_writes(ahd);
9400 ahd_find_tmode_devs(struct ahd_softc *ahd, struct cam_sim *sim, union ccb *ccb,
9406 if ((ahd->features & AHD_TARGETMODE) == 0)
9416 *lstate = ahd->black_hole;
9420 max_id = (ahd->features & AHD_WIDE) ? 16 : 8;
9427 *tstate = ahd->enabled_targets[ccb->ccb_h.target_id];
9441 ahd_handle_en_lun(struct ahd_softc *ahd, struct cam_sim *sim, union ccb *ccb)
9454 status = ahd_find_tmode_devs(ahd, sim, ccb, &tstate, &lstate,
9462 if ((ahd->features & AHD_MULTIROLE) != 0) {
9465 our_id = ahd->our_id;
9467 if ((ahd->features & AHD_MULTI_TID) != 0
9468 && (ahd->flags & AHD_INITIATORROLE) != 0) {
9477 } else if ((ahd->flags & AHD_INITIATORROLE) != 0
9478 || ahd->enabled_luns > 0) {
9500 if ((ahd->flags & AHD_TARGETROLE) == 0
9505 ahd_lock(ahd, &s);
9506 if (LIST_FIRST(&ahd->pending_scbs) != NULL) {
9508 ahd_unlock(ahd, &s);
9511 ahd->flags |= AHD_TARGETROLE;
9512 if ((ahd->features & AHD_MULTIROLE) == 0)
9513 ahd->flags &= ~AHD_INITIATORROLE;
9514 ahd_pause(ahd);
9515 ahd_loadseq(ahd);
9516 ahd_restart(ahd);
9517 ahd_unlock(ahd, &s);
9522 channel = SIM_CHANNEL(ahd, sim);
9554 tstate = ahd_alloc_tstate(ahd, target, channel);
9583 ahd_lock(ahd, &s);
9584 ahd_pause(ahd);
9587 ahd->enabled_luns++;
9589 if ((ahd->features & AHD_MULTI_TID) != 0) {
9592 targid_mask = ahd_inw(ahd, TARGID);
9594 ahd_outw(ahd, TARGID, targid_mask);
9595 ahd_update_scsiid(ahd, targid_mask);
9600 channel = SIM_CHANNEL(ahd, sim);
9601 our_id = SIM_SCSI_ID(ahd, sim);
9612 sblkctl = ahd_inb(ahd, SBLKCTL);
9615 if ((ahd->features & AHD_TWIN) == 0)
9618 ahd->our_id = target;
9621 ahd_outb(ahd, SBLKCTL,
9624 ahd_outb(ahd, SCSIID, target);
9627 ahd_outb(ahd, SBLKCTL, sblkctl);
9631 ahd->black_hole = lstate;
9633 if (ahd->black_hole != NULL && ahd->enabled_luns > 0) {
9634 scsiseq1 = ahd_inb(ahd, SCSISEQ_TEMPLATE);
9636 ahd_outb(ahd, SCSISEQ_TEMPLATE, scsiseq1);
9637 scsiseq1 = ahd_inb(ahd, SCSISEQ1);
9639 ahd_outb(ahd, SCSISEQ1, scsiseq1);
9641 ahd_unpause(ahd);
9642 ahd_unlock(ahd, &s);
9655 ahd_lock(ahd, &s);
9658 LIST_FOREACH(scb, &ahd->pending_scbs, pending_links) {
9666 ahd_unlock(ahd, &s);
9682 ahd_unlock(ahd, &s);
9691 ahd_pause(ahd);
9695 ahd->enabled_luns--;
9703 ahd_free_tstate(ahd, target, channel,
9705 if (ahd->features & AHD_MULTI_TID) {
9708 targid_mask = ahd_inw(ahd, TARGID);
9710 ahd_outw(ahd, TARGID, targid_mask);
9711 ahd_update_scsiid(ahd, targid_mask);
9716 ahd->black_hole = NULL;
9724 if (ahd->enabled_luns == 0) {
9728 scsiseq1 = ahd_inb(ahd, SCSISEQ_TEMPLATE);
9730 ahd_outb(ahd, SCSISEQ_TEMPLATE, scsiseq1);
9731 scsiseq1 = ahd_inb(ahd, SCSISEQ1);
9733 ahd_outb(ahd, SCSISEQ1, scsiseq1);
9735 if ((ahd->features & AHD_MULTIROLE) == 0) {
9737 ahd->flags &= ~AHD_TARGETROLE;
9738 ahd->flags |= AHD_INITIATORROLE;
9739 ahd_pause(ahd);
9740 ahd_loadseq(ahd);
9741 ahd_restart(ahd);
9748 ahd_unpause(ahd);
9749 ahd_unlock(ahd, &s);
9755 ahd_update_scsiid(struct ahd_softc *ahd, u_int targid_mask)
9761 if ((ahd->features & AHD_MULTI_TID) == 0)
9770 if ((ahd->features & AHD_ULTRA2) != 0)
9771 scsiid = ahd_inb(ahd, SCSIID_ULTRA2);
9773 scsiid = ahd_inb(ahd, SCSIID);
9781 our_id = ahd->our_id;
9787 if ((ahd->features & AHD_ULTRA2) != 0)
9788 ahd_outb(ahd, SCSIID_ULTRA2, scsiid);
9790 ahd_outb(ahd, SCSIID, scsiid);
9795 ahd_run_tqinfifo(struct ahd_softc *ahd, int paused)
9799 ahd_sync_tqinfifo(ahd, BUS_DMASYNC_POSTREAD);
9800 while ((cmd = &ahd->targetcmds[ahd->tqinfifonext])->cmd_valid != 0) {
9806 if (ahd_handle_target_cmd(ahd, cmd) != 0)
9810 ahd_dmamap_sync(ahd, ahd->shared_data_dmat,
9811 ahd->shared_data_map.dmamap,
9812 ahd_targetcmd_offset(ahd, ahd->tqinfifonext),
9815 ahd->tqinfifonext++;
9821 if ((ahd->tqinfifonext & (HOST_TQINPOS - 1)) == 1) {
9824 hs_mailbox = ahd_inb(ahd, HS_MAILBOX);
9826 hs_mailbox |= ahd->tqinfifonext & HOST_TQINPOS;
9827 ahd_outb(ahd, HS_MAILBOX, hs_mailbox);
9833 ahd_handle_target_cmd(struct ahd_softc *ahd, struct target_cmd *cmd)
9843 initiator = SCSIID_TARGET(ahd, cmd->scsiid);
9848 tstate = ahd->enabled_targets[target];
9857 lstate = ahd->black_hole;
9861 ahd->flags |= AHD_TQINFIFO_BLOCKED;
9867 ahd->flags &= ~AHD_TQINFIFO_BLOCKED;
9872 lstate == ahd->black_hole ? "(Black Holed)" : "");
9876 if (lstate == ahd->black_hole) {
9935 initiator, target, lun, ahd->pending_device);
9937 ahd->pending_device = lstate;