• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /netgear-R7000-V1.0.7.12_1.2.5/components/opensource/linux/linux-2.6.36/drivers/scsi/aic7xxx/

Lines Matching refs: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,
269 static void ahd_reset_cmds_pending(struct ahd_softc *ahd);
272 static void ahd_run_qoutfifo(struct ahd_softc *ahd);
274 static void ahd_run_tqinfifo(struct ahd_softc *ahd, int paused);
276 static void ahd_handle_hwerrint(struct ahd_softc *ahd);
277 static void ahd_handle_seqint(struct ahd_softc *ahd, u_int intstat);
278 static void ahd_handle_scsiint(struct ahd_softc *ahd,
283 ahd_set_modes(struct ahd_softc *ahd, ahd_mode src, ahd_mode dst)
285 if (ahd->src_mode == src && ahd->dst_mode == dst)
288 if (ahd->src_mode == AHD_MODE_UNKNOWN
289 || ahd->dst_mode == AHD_MODE_UNKNOWN)
292 printk("%s: Setting mode 0x%x\n", ahd_name(ahd),
293 ahd_build_mode_state(ahd, src, dst));
295 ahd_outb(ahd, MODE_PTR, ahd_build_mode_state(ahd, src, dst));
296 ahd->src_mode = src;
297 ahd->dst_mode = dst;
301 ahd_update_modes(struct ahd_softc *ahd)
307 mode_ptr = ahd_inb(ahd, MODE_PTR);
312 ahd_extract_mode_state(ahd, mode_ptr, &src, &dst);
313 ahd_known_modes(ahd, src, dst);
317 ahd_assert_modes(struct ahd_softc *ahd, ahd_mode srcmode,
321 if ((srcmode & AHD_MK_MSK(ahd->src_mode)) == 0
322 || (dstmode & AHD_MK_MSK(ahd->dst_mode)) == 0) {
324 ahd_name(ahd), file, line);
329 #define AHD_ASSERT_MODES(ahd, source, dest) \
330 ahd_assert_modes(ahd, source, dest, __FILE__, __LINE__);
333 ahd_save_modes(struct ahd_softc *ahd)
335 if (ahd->src_mode == AHD_MODE_UNKNOWN
336 || ahd->dst_mode == AHD_MODE_UNKNOWN)
337 ahd_update_modes(ahd);
339 return (ahd_build_mode_state(ahd, ahd->src_mode, ahd->dst_mode));
343 ahd_restore_modes(struct ahd_softc *ahd, ahd_mode_state state)
348 ahd_extract_mode_state(ahd, state, &src, &dst);
349 ahd_set_modes(ahd, src, dst);
357 ahd_is_paused(struct ahd_softc *ahd)
359 return ((ahd_inb(ahd, HCNTRL) & PAUSE) != 0);
370 ahd_pause(struct ahd_softc *ahd)
372 ahd_outb(ahd, HCNTRL, ahd->pause);
378 while (ahd_is_paused(ahd) == 0)
393 ahd_unpause(struct ahd_softc *ahd)
399 if (ahd->saved_src_mode != AHD_MODE_UNKNOWN
400 && ahd->saved_dst_mode != AHD_MODE_UNKNOWN) {
401 if ((ahd->flags & AHD_UPDATE_PEND_CMDS) != 0)
402 ahd_reset_cmds_pending(ahd);
403 ahd_set_modes(ahd, ahd->saved_src_mode, ahd->saved_dst_mode);
406 if ((ahd_inb(ahd, INTSTAT) & ~CMDCMPLT) == 0)
407 ahd_outb(ahd, HCNTRL, ahd->unpause);
409 ahd_known_modes(ahd, AHD_MODE_UNKNOWN, AHD_MODE_UNKNOWN);
414 ahd_sg_setup(struct ahd_softc *ahd, struct scb *scb,
419 && (ahd->flags & AHD_64BIT_ADDRESSING) != 0) {
438 ahd_setup_scb_common(struct ahd_softc *ahd, struct scb *scb)
457 ahd_setup_data_scb(struct ahd_softc *ahd, struct scb *scb)
462 if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0) {
476 if ((ahd->flags & AHD_39BIT_ADDRESSING) != 0) {
494 ahd_setup_noxfer_scb(struct ahd_softc *ahd, struct scb *scb)
503 ahd_sg_bus_to_virt(struct ahd_softc *ahd, struct scb *scb, uint32_t sg_busaddr)
508 sg_offset = sg_busaddr - (scb->sg_list_busaddr - ahd_sg_size(ahd));
513 ahd_sg_virt_to_bus(struct ahd_softc *ahd, struct scb *scb, void *sg)
519 - ahd_sg_size(ahd);
525 ahd_sync_scb(struct ahd_softc *ahd, struct scb *scb, int op)
527 ahd_dmamap_sync(ahd, ahd->scb_data.hscb_dmat,
534 ahd_sync_sglist(struct ahd_softc *ahd, struct scb *scb, int op)
539 ahd_dmamap_sync(ahd, ahd->scb_data.sg_dmat,
541 /*offset*/scb->sg_list_busaddr - ahd_sg_size(ahd),
542 /*len*/ahd_sg_size(ahd) * scb->sg_count, op);
546 ahd_sync_sense(struct ahd_softc *ahd, struct scb *scb, int op)
548 ahd_dmamap_sync(ahd, ahd->scb_data.sense_dmat,
556 ahd_targetcmd_offset(struct ahd_softc *ahd, u_int index)
558 return (((uint8_t *)&ahd->targetcmds[index])
559 - (uint8_t *)ahd->qoutfifo);
569 ahd_fetch_transinfo(struct ahd_softc *ahd, char channel, u_int our_id,
580 *tstate = ahd->enabled_targets[our_id];
585 ahd_inw(struct ahd_softc *ahd, u_int port)
592 uint16_t r = ahd_inb(ahd, port+1) << 8;
593 return r | ahd_inb(ahd, port);
597 ahd_outw(struct ahd_softc *ahd, u_int port, u_int value)
603 ahd_outb(ahd, port, value & 0xFF);
604 ahd_outb(ahd, port+1, (value >> 8) & 0xFF);
608 ahd_inl(struct ahd_softc *ahd, u_int port)
610 return ((ahd_inb(ahd, port))
611 | (ahd_inb(ahd, port+1) << 8)
612 | (ahd_inb(ahd, port+2) << 16)
613 | (ahd_inb(ahd, port+3) << 24));
617 ahd_outl(struct ahd_softc *ahd, u_int port, uint32_t value)
619 ahd_outb(ahd, port, (value) & 0xFF);
620 ahd_outb(ahd, port+1, ((value) >> 8) & 0xFF);
621 ahd_outb(ahd, port+2, ((value) >> 16) & 0xFF);
622 ahd_outb(ahd, port+3, ((value) >> 24) & 0xFF);
626 ahd_inq(struct ahd_softc *ahd, u_int port)
628 return ((ahd_inb(ahd, port))
629 | (ahd_inb(ahd, port+1) << 8)
630 | (ahd_inb(ahd, port+2) << 16)
631 | (ahd_inb(ahd, port+3) << 24)
632 | (((uint64_t)ahd_inb(ahd, port+4)) << 32)
633 | (((uint64_t)ahd_inb(ahd, port+5)) << 40)
634 | (((uint64_t)ahd_inb(ahd, port+6)) << 48)
635 | (((uint64_t)ahd_inb(ahd, port+7)) << 56));
639 ahd_outq(struct ahd_softc *ahd, u_int port, uint64_t value)
641 ahd_outb(ahd, port, value & 0xFF);
642 ahd_outb(ahd, port+1, (value >> 8) & 0xFF);
643 ahd_outb(ahd, port+2, (value >> 16) & 0xFF);
644 ahd_outb(ahd, port+3, (value >> 24) & 0xFF);
645 ahd_outb(ahd, port+4, (value >> 32) & 0xFF);
646 ahd_outb(ahd, port+5, (value >> 40) & 0xFF);
647 ahd_outb(ahd, port+6, (value >> 48) & 0xFF);
648 ahd_outb(ahd, port+7, (value >> 56) & 0xFF);
652 ahd_get_scbptr(struct ahd_softc *ahd)
654 AHD_ASSERT_MODES(ahd, ~(AHD_MODE_UNKNOWN_MSK|AHD_MODE_CFG_MSK),
656 return (ahd_inb(ahd, SCBPTR) | (ahd_inb(ahd, SCBPTR + 1) << 8));
660 ahd_set_scbptr(struct ahd_softc *ahd, u_int scbptr)
662 AHD_ASSERT_MODES(ahd, ~(AHD_MODE_UNKNOWN_MSK|AHD_MODE_CFG_MSK),
664 ahd_outb(ahd, SCBPTR, scbptr & 0xFF);
665 ahd_outb(ahd, SCBPTR+1, (scbptr >> 8) & 0xFF);
670 ahd_set_hnscb_qoff(struct ahd_softc *ahd, u_int value)
672 ahd_outw_atomic(ahd, HNSCB_QOFF, value);
677 ahd_set_hescb_qoff(struct ahd_softc *ahd, u_int value)
679 ahd_outb(ahd, HESCB_QOFF, value);
683 ahd_get_snscb_qoff(struct ahd_softc *ahd)
687 AHD_ASSERT_MODES(ahd, AHD_MODE_CCHAN_MSK, AHD_MODE_CCHAN_MSK);
688 oldvalue = ahd_inw(ahd, SNSCB_QOFF);
689 ahd_outw(ahd, SNSCB_QOFF, oldvalue);
694 ahd_set_snscb_qoff(struct ahd_softc *ahd, u_int value)
696 AHD_ASSERT_MODES(ahd, AHD_MODE_CCHAN_MSK, AHD_MODE_CCHAN_MSK);
697 ahd_outw(ahd, SNSCB_QOFF, value);
702 ahd_set_sescb_qoff(struct ahd_softc *ahd, u_int value)
704 AHD_ASSERT_MODES(ahd, AHD_MODE_CCHAN_MSK, AHD_MODE_CCHAN_MSK);
705 ahd_outb(ahd, SESCB_QOFF, value);
710 ahd_set_sdscb_qoff(struct ahd_softc *ahd, u_int value)
712 AHD_ASSERT_MODES(ahd, AHD_MODE_CCHAN_MSK, AHD_MODE_CCHAN_MSK);
713 ahd_outb(ahd, SDSCB_QOFF, value & 0xFF);
714 ahd_outb(ahd, SDSCB_QOFF+1, (value >> 8) & 0xFF);
718 ahd_inb_scbram(struct ahd_softc *ahd, u_int offset)
722 value = ahd_inb(ahd, offset);
723 if ((ahd->bugs & AHD_PCIX_SCBRAM_RD_BUG) != 0)
724 ahd_inb(ahd, MODE_PTR);
729 ahd_inw_scbram(struct ahd_softc *ahd, u_int offset)
731 return (ahd_inb_scbram(ahd, offset)
732 | (ahd_inb_scbram(ahd, offset+1) << 8));
736 ahd_inl_scbram(struct ahd_softc *ahd, u_int offset)
738 return (ahd_inw_scbram(ahd, offset)
739 | (ahd_inw_scbram(ahd, offset+2) << 16));
743 ahd_inq_scbram(struct ahd_softc *ahd, u_int offset)
745 return (ahd_inl_scbram(ahd, offset)
746 | ((uint64_t)ahd_inl_scbram(ahd, offset+4)) << 32);
750 ahd_lookup_scb(struct ahd_softc *ahd, u_int tag)
756 scb = ahd->scb_data.scbindex[tag];
758 ahd_sync_scb(ahd, scb,
764 ahd_swap_with_next_hscb(struct ahd_softc *ahd, struct scb *scb)
774 * HSCB to download is saved off in ahd->next_queued_hscb.
782 q_hscb = ahd->next_queued_hscb;
783 q_hscb_map = ahd->next_queued_hscb_map;
790 ahd->next_queued_hscb = scb->hscb;
791 ahd->next_queued_hscb_map = scb->hscb_map;
796 ahd->scb_data.scbindex[SCB_GET_TAG(scb)] = scb;
803 ahd_queue_scb(struct ahd_softc *ahd, struct scb *scb)
805 ahd_swap_with_next_hscb(ahd, scb);
814 ahd->qinfifo[AHD_QIN_WRAP(ahd->qinfifonext)] = SCB_GET_TAG(scb);
815 ahd->qinfifonext++;
818 ahd_setup_data_scb(ahd, scb);
820 ahd_setup_noxfer_scb(ahd, scb);
821 ahd_setup_scb_common(ahd, scb);
827 ahd_sync_scb(ahd, scb, BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
835 ahd_name(ahd),
844 ahd_set_hnscb_qoff(ahd, ahd->qinfifonext);
849 ahd_sync_qoutfifo(struct ahd_softc *ahd, int op)
851 ahd_dmamap_sync(ahd, ahd->shared_data_dmat, ahd->shared_data_map.dmamap,
857 ahd_sync_tqinfifo(struct ahd_softc *ahd, int op)
860 if ((ahd->flags & AHD_TARGETROLE) != 0) {
861 ahd_dmamap_sync(ahd, ahd->shared_data_dmat,
862 ahd->shared_data_map.dmamap,
863 ahd_targetcmd_offset(ahd, 0),
877 ahd_check_cmdcmpltqueues(struct ahd_softc *ahd)
882 ahd_dmamap_sync(ahd, ahd->shared_data_dmat, ahd->shared_data_map.dmamap,
883 /*offset*/ahd->qoutfifonext * sizeof(*ahd->qoutfifo),
884 /*len*/sizeof(*ahd->qoutfifo), BUS_DMASYNC_POSTREAD);
885 if (ahd->qoutfifo[ahd->qoutfifonext].valid_tag
886 == ahd->qoutfifonext_valid_tag)
889 if ((ahd->flags & AHD_TARGETROLE) != 0
890 && (ahd->flags & AHD_TQINFIFO_BLOCKED) == 0) {
891 ahd_dmamap_sync(ahd, ahd->shared_data_dmat,
892 ahd->shared_data_map.dmamap,
893 ahd_targetcmd_offset(ahd, ahd->tqinfifofnext),
896 if (ahd->targetcmds[ahd->tqinfifonext].cmd_valid != 0)
907 ahd_intr(struct ahd_softc *ahd)
911 if ((ahd->pause & INTEN) == 0) {
927 if ((ahd->flags & AHD_ALL_INTERRUPTS) == 0
928 && (ahd_check_cmdcmpltqueues(ahd) != 0))
931 intstat = ahd_inb(ahd, INTSTAT);
937 ahd_outb(ahd, CLRINT, CLRCMDINT);
947 if ((ahd->bugs & AHD_INTCOLLISION_BUG) != 0) {
948 if (ahd_is_paused(ahd)) {
954 if (ahd_inb(ahd, SEQINTCODE) != NO_SEQINT)
958 ahd_flush_device_writes(ahd);
960 ahd_run_qoutfifo(ahd);
961 ahd->cmdcmplt_counts[ahd->cmdcmplt_bucket]++;
962 ahd->cmdcmplt_total++;
964 if ((ahd->flags & AHD_TARGETROLE) != 0)
965 ahd_run_tqinfifo(ahd, /*paused*/FALSE);
973 if (intstat == 0xFF && (ahd->features & AHD_REMOVABLE) != 0) {
976 ahd_handle_hwerrint(ahd);
978 ahd->bus_intr(ahd);
982 ahd_handle_seqint(ahd, intstat);
985 ahd_handle_scsiint(ahd, intstat);
992 ahd_assert_atn(struct ahd_softc *ahd)
994 ahd_outb(ahd, SCSISIGO, ATNO);
1004 ahd_currently_packetized(struct ahd_softc *ahd)
1009 saved_modes = ahd_save_modes(ahd);
1010 if ((ahd->bugs & AHD_PKTIZED_STATUS_BUG) != 0) {
1016 ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
1017 packetized = ahd_inb(ahd, LQISTATE) != 0;
1019 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
1020 packetized = ahd_inb(ahd, LQISTAT2) & PACKETIZED;
1022 ahd_restore_modes(ahd, saved_modes);
1027 ahd_set_active_fifo(struct ahd_softc *ahd)
1031 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
1032 active_fifo = ahd_inb(ahd, DFFSTAT) & CURRFIFO;
1036 ahd_set_modes(ahd, active_fifo, active_fifo);
1044 ahd_unbusy_tcl(struct ahd_softc *ahd, u_int tcl)
1046 ahd_busy_tcl(ahd, tcl, SCB_LIST_NULL);
1054 ahd_update_residual(struct ahd_softc *ahd, struct scb *scb)
1060 ahd_calc_residual(ahd, scb);
1064 ahd_complete_scb(struct ahd_softc *ahd, struct scb *scb)
1070 ahd_handle_scb_status(ahd, scb);
1072 ahd_done(ahd, scb);
1081 ahd_restart(struct ahd_softc *ahd)
1084 ahd_pause(ahd);
1086 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
1089 ahd_clear_msg_state(ahd);
1090 ahd_outb(ahd, SCSISIGO, 0); /* De-assert BSY */
1091 ahd_outb(ahd, MSG_OUT, MSG_NOOP); /* No message to send */
1092 ahd_outb(ahd, SXFRCTL1, ahd_inb(ahd, SXFRCTL1) & ~BITBUCKET);
1093 ahd_outb(ahd, SEQINTCTL, 0);
1094 ahd_outb(ahd, LASTPHASE, P_BUSFREE);
1095 ahd_outb(ahd, SEQ_FLAGS, 0);
1096 ahd_outb(ahd, SAVED_SCSIID, 0xFF);
1097 ahd_outb(ahd, SAVED_LUN, 0xFF);
1106 ahd_outb(ahd, TQINPOS, ahd->tqinfifonext);
1109 ahd_outb(ahd, SCSISEQ1,
1110 ahd_inb(ahd, SCSISEQ_TEMPLATE) & (ENSELI|ENRSELI|ENAUTOATNP));
1111 ahd_set_modes(ahd, AHD_MODE_CCHAN, AHD_MODE_CCHAN);
1118 ahd_outb(ahd, CLRINT, CLRSEQINT);
1120 ahd_outb(ahd, SEQCTL0, FASTMODE|SEQRESET);
1121 ahd_unpause(ahd);
1125 ahd_clear_fifo(struct ahd_softc *ahd, u_int fifo)
1131 printk("%s: Clearing FIFO %d\n", ahd_name(ahd), fifo);
1133 saved_modes = ahd_save_modes(ahd);
1134 ahd_set_modes(ahd, fifo, fifo);
1135 ahd_outb(ahd, DFFSXFRCTL, RSTCHN|CLRSHCNT);
1136 if ((ahd_inb(ahd, SG_STATE) & FETCH_INPROG) != 0)
1137 ahd_outb(ahd, CCSGCTL, CCSGRESET);
1138 ahd_outb(ahd, LONGJMP_ADDR + 1, INVALID_ADDR);
1139 ahd_outb(ahd, SG_STATE, 0);
1140 ahd_restore_modes(ahd, saved_modes);
1149 ahd_flush_qoutfifo(struct ahd_softc *ahd)
1158 saved_modes = ahd_save_modes(ahd);
1163 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
1164 saved_scbptr = ahd_get_scbptr(ahd);
1165 while ((ahd_inb(ahd, LQISTAT2) & LQIGSAVAIL) != 0) {
1169 scbid = ahd_inw(ahd, GSFIFO);
1170 scb = ahd_lookup_scb(ahd, scbid);
1173 ahd_name(ahd), scbid);
1186 ahd_set_modes(ahd, fifo_mode, fifo_mode);
1188 if (ahd_scb_active_in_fifo(ahd, scb) == 0)
1191 ahd_run_data_fifo(ahd, scb);
1210 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
1211 ahd_set_scbptr(ahd, scbid);
1212 if ((ahd_inb_scbram(ahd, SCB_SGPTR) & SG_LIST_NULL) == 0
1213 && ((ahd_inb_scbram(ahd, SCB_SGPTR) & SG_FULL_RESID) != 0
1214 || (ahd_inb_scbram(ahd, SCB_RESIDUAL_SGPTR)
1224 ahd_outb(ahd, SCB_SCSI_STATUS, 0);
1225 ahd_outb(ahd, SCB_SGPTR,
1226 ahd_inb_scbram(ahd, SCB_SGPTR)
1228 ahd_outw(ahd, SCB_TAG, scbid);
1229 ahd_outw(ahd, SCB_NEXT_COMPLETE, SCB_LIST_NULL);
1230 comp_head = ahd_inw(ahd, COMPLETE_DMA_SCB_HEAD);
1232 ahd_outw(ahd, COMPLETE_DMA_SCB_HEAD, scbid);
1233 ahd_outw(ahd, COMPLETE_DMA_SCB_TAIL, scbid);
1237 tail = ahd_inw(ahd, COMPLETE_DMA_SCB_TAIL);
1238 ahd_set_scbptr(ahd, tail);
1239 ahd_outw(ahd, SCB_NEXT_COMPLETE, scbid);
1240 ahd_outw(ahd, COMPLETE_DMA_SCB_TAIL, scbid);
1241 ahd_set_scbptr(ahd, scbid);
1244 ahd_complete_scb(ahd, scb);
1246 ahd_set_scbptr(ahd, saved_scbptr);
1251 ahd_set_modes(ahd, AHD_MODE_CCHAN, AHD_MODE_CCHAN);
1257 while (((ccscbctl = ahd_inb(ahd, CCSCBCTL)) & (CCARREN|CCSCBEN)) != 0) {
1274 ahd_outb(ahd, CCSCBCTL, ccscbctl & ~(CCARREN|CCSCBEN));
1280 ahd_run_qoutfifo(ahd);
1282 saved_scbptr = ahd_get_scbptr(ahd);
1287 scbid = ahd_inw(ahd, COMPLETE_DMA_SCB_HEAD);
1292 ahd_set_scbptr(ahd, scbid);
1293 next_scbid = ahd_inw_scbram(ahd, SCB_NEXT_COMPLETE);
1294 scb = ahd_lookup_scb(ahd, scbid);
1297 "SCB %d invalid\n", ahd_name(ahd), scbid);
1302 *hscb_ptr++ = ahd_inb_scbram(ahd, SCB_BASE + i);
1304 ahd_complete_scb(ahd, scb);
1307 ahd_outw(ahd, COMPLETE_DMA_SCB_HEAD, SCB_LIST_NULL);
1308 ahd_outw(ahd, COMPLETE_DMA_SCB_TAIL, SCB_LIST_NULL);
1310 scbid = ahd_inw(ahd, COMPLETE_ON_QFREEZE_HEAD);
1313 ahd_set_scbptr(ahd, scbid);
1314 next_scbid = ahd_inw_scbram(ahd, SCB_NEXT_COMPLETE);
1315 scb = ahd_lookup_scb(ahd, scbid);
1318 ahd_name(ahd), scbid);
1322 ahd_complete_scb(ahd, scb);
1325 ahd_outw(ahd, COMPLETE_ON_QFREEZE_HEAD, SCB_LIST_NULL);
1327 scbid = ahd_inw(ahd, COMPLETE_SCB_HEAD);
1330 ahd_set_scbptr(ahd, scbid);
1331 next_scbid = ahd_inw_scbram(ahd, SCB_NEXT_COMPLETE);
1332 scb = ahd_lookup_scb(ahd, scbid);
1335 ahd_name(ahd), scbid);
1339 ahd_complete_scb(ahd, scb);
1342 ahd_outw(ahd, COMPLETE_SCB_HEAD, SCB_LIST_NULL);
1347 ahd_set_scbptr(ahd, saved_scbptr);
1348 ahd_restore_modes(ahd, saved_modes);
1349 ahd->flags |= AHD_UPDATE_PEND_CMDS;
1357 ahd_scb_active_in_fifo(struct ahd_softc *ahd, struct scb *scb)
1366 if (ahd_get_scbptr(ahd) != SCB_GET_TAG(scb)
1367 || ((ahd_inb(ahd, LONGJMP_ADDR+1) & INVALID_ADDR) != 0
1368 && (ahd_inb(ahd, SEQINTSRC) & (CFG4DATA|SAVEPTRS)) == 0))
1386 ahd_run_data_fifo(struct ahd_softc *ahd, struct scb *scb)
1390 seqintsrc = ahd_inb(ahd, SEQINTSRC);
1398 sgptr = ahd_inl_scbram(ahd, SCB_SGPTR) & ~SG_FULL_RESID;
1399 ahd_outb(ahd, SCB_SGPTR, sgptr);
1404 datacnt = ahd_inl_scbram(ahd, SCB_DATACNT);
1407 ahd_outb(ahd, SG_STATE, 0);
1409 ahd_outb(ahd, SG_STATE, LOADING_NEEDED);
1410 ahd_outq(ahd, HADDR, ahd_inq_scbram(ahd, SCB_DATAPTR));
1411 ahd_outl(ahd, HCNT, datacnt & AHD_SG_LEN_MASK);
1412 ahd_outb(ahd, SG_CACHE_PRE, sgptr);
1413 ahd_outb(ahd, DFCNTRL, PRELOADEN|SCSIEN|HDMAEN);
1418 ahd_outb(ahd, SCB_RESIDUAL_DATACNT+3, datacnt >> 24);
1419 ahd_outl(ahd, SCB_RESIDUAL_SGPTR, sgptr & SG_PTR_MASK);
1424 ahd_outb(ahd, SCB_FIFO_USE_COUNT,
1425 ahd_inb_scbram(ahd, SCB_FIFO_USE_COUNT) + 1);
1430 ahd_outw(ahd, LONGJMP_ADDR, 0);
1436 ahd_outb(ahd, CLRSEQINTSRC, CLRCFG4DATA);
1441 if ((ahd_inb(ahd, LONGJMP_ADDR+1)&INVALID_ADDR) != 0) {
1454 if ((ahd_inb(ahd, SG_STATE) & FETCH_INPROG) != 0)
1455 ahd_outb(ahd, CCSGCTL, 0);
1456 ahd_outb(ahd, SG_STATE, 0);
1462 ahd_outb(ahd, DFCNTRL, ahd_inb(ahd, DFCNTRL) | FIFOFLUSH);
1467 sgptr = ahd_inl_scbram(ahd, SCB_RESIDUAL_SGPTR);
1468 resid = ahd_inl(ahd, SHCNT);
1469 resid |= ahd_inb_scbram(ahd, SCB_RESIDUAL_DATACNT+3) << 24;
1470 ahd_outl(ahd, SCB_RESIDUAL_DATACNT, resid);
1471 if ((ahd_inb(ahd, SG_CACHE_SHADOW) & LAST_SEG) == 0) {
1479 if ((ahd_inb(ahd, SG_CACHE_SHADOW) & 0x80) != 0
1483 sgptr |= ahd_inb(ahd, SG_CACHE_SHADOW)
1485 ahd_outl(ahd, SCB_RESIDUAL_SGPTR, sgptr);
1486 ahd_outb(ahd, SCB_RESIDUAL_DATACNT + 3, 0);
1488 ahd_outb(ahd, SCB_RESIDUAL_SGPTR,
1494 ahd_outq(ahd, SCB_DATAPTR, ahd_inq(ahd, SHADDR));
1495 ahd_outl(ahd, SCB_DATACNT, resid);
1496 ahd_outl(ahd, SCB_SGPTR, sgptr);
1497 ahd_outb(ahd, CLRSEQINTSRC, CLRSAVEPTRS);
1498 ahd_outb(ahd, SEQIMODE,
1499 ahd_inb(ahd, SEQIMODE) | ENSAVEPTRS);
1504 if ((ahd_inb(ahd, DFCNTRL) & DIRECTION) != 0)
1506 } else if ((ahd_inb(ahd, SG_STATE) & LOADING_NEEDED) != 0) {
1517 if ((ahd_inb(ahd, SG_STATE) & FETCH_INPROG) != 0) {
1518 ahd_outb(ahd, CCSGCTL, 0);
1519 ahd_outb(ahd, SG_STATE, LOADING_NEEDED);
1528 if ((ahd_inb(ahd, DFSTATUS) & PRELOAD_AVAIL) != 0
1529 && (ahd_inb(ahd, DFCNTRL) & HDMAENACK) != 0) {
1535 sgptr = ahd_inl_scbram(ahd, SCB_RESIDUAL_SGPTR);
1537 if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0) {
1540 sg = ahd_sg_bus_to_virt(ahd, scb, sgptr);
1547 sg = ahd_sg_bus_to_virt(ahd, scb, sgptr);
1558 ahd_outb(ahd, SCB_RESIDUAL_DATACNT+3, data_len >> 24);
1559 ahd_outl(ahd, SCB_RESIDUAL_SGPTR, sgptr);
1566 ahd_outb(ahd, SG_STATE, 0);
1568 ahd_outq(ahd, HADDR, data_addr);
1569 ahd_outl(ahd, HCNT, data_len & AHD_SG_LEN_MASK);
1570 ahd_outb(ahd, SG_CACHE_PRE, sgptr & 0xFF);
1575 dfcntrl = ahd_inb(ahd, DFCNTRL)|PRELOADEN|HDMAEN;
1576 if ((ahd->features & AHD_NEW_DFCNTRL_OPTS) != 0) {
1584 ahd_outb(ahd, DFCNTRL, dfcntrl);
1586 } else if ((ahd_inb(ahd, SG_CACHE_SHADOW) & LAST_SEG_DONE) != 0) {
1592 ahd_outb(ahd, SCB_SGPTR,
1593 ahd_inb_scbram(ahd, SCB_SGPTR) | SG_LIST_NULL);
1595 } else if ((ahd_inb(ahd, DFSTATUS) & FIFOEMP) != 0) {
1602 ahd_outb(ahd, LONGJMP_ADDR + 1, INVALID_ADDR);
1603 ahd_outb(ahd, SCB_FIFO_USE_COUNT,
1604 ahd_inb_scbram(ahd, SCB_FIFO_USE_COUNT) - 1);
1605 ahd_outb(ahd, DFFSXFRCTL, CLRCHN);
1620 ahd_run_qoutfifo(struct ahd_softc *ahd)
1626 if ((ahd->flags & AHD_RUNNING_QOUTFIFO) != 0)
1628 ahd->flags |= AHD_RUNNING_QOUTFIFO;
1629 ahd_sync_qoutfifo(ahd, BUS_DMASYNC_POSTREAD);
1631 completion = &ahd->qoutfifo[ahd->qoutfifonext];
1633 if (completion->valid_tag != ahd->qoutfifonext_valid_tag)
1637 scb = ahd_lookup_scb(ahd, scb_index);
1641 ahd_name(ahd), scb_index,
1642 ahd->qoutfifonext);
1643 ahd_dump_card_state(ahd);
1645 ahd_handle_scb_status(ahd, scb);
1647 ahd_done(ahd, scb);
1650 ahd->qoutfifonext = (ahd->qoutfifonext+1) & (AHD_QOUT_SIZE-1);
1651 if (ahd->qoutfifonext == 0)
1652 ahd->qoutfifonext_valid_tag ^= QOUTFIFO_ENTRY_VALID;
1654 ahd->flags &= ~AHD_RUNNING_QOUTFIFO;
1659 ahd_handle_hwerrint(struct ahd_softc *ahd)
1668 error = ahd_inb(ahd, ERROR);
1672 ahd_name(ahd), ahd_hard_errors[i].errmesg);
1675 ahd_dump_card_state(ahd);
1679 ahd_abort_scbs(ahd, CAM_TARGET_WILDCARD, ALL_CHANNELS,
1684 ahd_free(ahd);
1733 ahd_handle_seqint(struct ahd_softc *ahd, u_int intstat)
1742 seqintcode = ahd_inb(ahd, SEQINTCODE);
1743 ahd_outb(ahd, CLRINT, CLRSEQINT);
1744 if ((ahd->bugs & AHD_INTCOLLISION_BUG) != 0) {
1751 ahd_unpause(ahd);
1752 while (!ahd_is_paused(ahd))
1754 ahd_outb(ahd, CLRINT, CLRSEQINT);
1756 ahd_update_modes(ahd);
1760 ahd_name(ahd), seqintcode);
1768 AHD_ASSERT_MODES(ahd, ~(AHD_MODE_UNKNOWN_MSK|AHD_MODE_CFG_MSK),
1770 scbid = ahd_get_scbptr(ahd);
1771 scb = ahd_lookup_scb(ahd, scbid);
1780 ahd_outb(ahd, SAVED_SCSIID, scb->hscb->scsiid);
1781 ahd_outb(ahd, SAVED_LUN, scb->hscb->lun);
1782 ahd_outb(ahd, SEQ_FLAGS, 0x0);
1784 if ((ahd_inb(ahd, LQISTAT2) & LQIPHASE_OUTPKT) != 0
1785 && (ahd_inb(ahd, SCSISIGO) & ATNO) != 0) {
1794 "P0 assertion\n", ahd_name(ahd));
1799 printk("%s: Entering NONPACK\n", ahd_name(ahd));
1806 ahd_name(ahd));
1809 ahd_dump_card_state(ahd);
1811 ahd_reset_channel(ahd, 'A', /*Initiate Reset*/TRUE);
1818 scbid = ahd_get_scbptr(ahd);
1819 scb = ahd_lookup_scb(ahd, scbid);
1821 ahd_print_path(ahd, scb);
1823 printk("%s: ", ahd_name(ahd));
1825 ahd_dump_card_state(ahd);
1826 ahd_reset_channel(ahd, 'A', /*Initiate Reset*/TRUE);
1834 scbid = ahd_get_scbptr(ahd);
1835 scb = ahd_lookup_scb(ahd, scbid);
1837 ahd_dump_card_state(ahd);
1841 ahd_outq(ahd, HADDR, scb->sense_busaddr);
1842 ahd_outw(ahd, HCNT, AHD_SENSE_BUFSIZE);
1843 ahd_outb(ahd, HCNT + 2, 0);
1844 ahd_outb(ahd, SG_CACHE_PRE, SG_LAST_SEG);
1845 ahd_outb(ahd, DFCNTRL, PRELOADEN|SCSIEN|HDMAEN);
1852 bus_phase = ahd_inb(ahd, SCSISIGI) & PHASE_MASK;
1854 ahd_name(ahd), bus_phase);
1864 ahd_reset_channel(ahd, 'A', /*Initiate Reset*/TRUE);
1865 printk("%s: Issued Bus Reset.\n", ahd_name(ahd));
1887 scbid = ahd_get_scbptr(ahd);
1888 scb = ahd_lookup_scb(ahd, scbid);
1892 ahd_reset_channel(ahd, 'A',
1897 SCB_GET_TARGET(ahd, scb),
1899 SCB_GET_CHANNEL(ahd, scb),
1901 targ_info = ahd_fetch_transinfo(ahd,
1907 ahd_set_width(ahd, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
1909 ahd_set_syncrate(ahd, &devinfo, /*period*/0,
1913 ahd_outb(ahd, SCB_CDB_STORE, 0);
1914 ahd_outb(ahd, SCB_CDB_STORE+1, 0);
1915 ahd_outb(ahd, SCB_CDB_STORE+2, 0);
1916 ahd_outb(ahd, SCB_CDB_STORE+3, 0);
1917 ahd_outb(ahd, SCB_CDB_STORE+4, 0);
1918 ahd_outb(ahd, SCB_CDB_STORE+5, 0);
1919 ahd_outb(ahd, SCB_CDB_LEN, 6);
1922 ahd_outb(ahd, SCB_CONTROL, scb->hscb->control);
1923 ahd_outb(ahd, MSG_OUT, HOST_MSG);
1924 ahd_outb(ahd, SAVED_SCSIID, scb->hscb->scsiid);
1929 ahd_outb(ahd, SAVED_LUN, 0);
1930 ahd_outb(ahd, SEQ_FLAGS, 0);
1931 ahd_assert_atn(ahd);
1934 ahd_freeze_devq(ahd, scb);
1939 ahd_send_async(ahd, devinfo.channel, devinfo.target,
1946 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
1947 ahd_outb(ahd, CLRLQOINT1, CLRLQOPHACHGINPKT);
1948 if ((ahd->bugs & AHD_CLRLQO_AUTOCLR_BUG) != 0) {
1949 ahd_outb(ahd, CLRLQOINT1, 0);
1953 ahd_print_path(ahd, scb);
1970 printk("%s: CFG4OVERRUN mode = %x\n", ahd_name(ahd),
1971 ahd_inb(ahd, MODE_PTR));
1974 scb_index = ahd_get_scbptr(ahd);
1975 scb = ahd_lookup_scb(ahd, scb_index);
1981 ahd_assert_atn(ahd);
1982 ahd_outb(ahd, MSG_OUT, HOST_MSG);
1983 ahd->msgout_buf[0] = MSG_ABORT_TASK;
1984 ahd->msgout_len = 1;
1985 ahd->msgout_index = 0;
1986 ahd->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
1991 ahd_outb(ahd, SCB_CONTROL,
1992 ahd_inb_scbram(ahd, SCB_CONTROL)
1999 ahd_dump_card_state(ahd);
2008 ahd_name(ahd), ahd_inb(ahd, DFCNTRL),
2009 ahd_inb(ahd, SG_CACHE_SHADOW));
2012 ahd_reinitialize_dataptrs(ahd);
2030 ahd_fetch_devinfo(ahd, &devinfo);
2031 if (ahd->msg_type == MSG_TYPE_NONE) {
2036 bus_phase = ahd_inb(ahd, SCSISIGI) & PHASE_MASK;
2045 ahd_dump_card_state(ahd);
2046 ahd_clear_intstat(ahd);
2047 ahd_restart(ahd);
2051 scb_index = ahd_get_scbptr(ahd);
2052 scb = ahd_lookup_scb(ahd, scb_index);
2055 ahd_setup_initiator_msgout(ahd,
2059 ahd->msg_type =
2061 ahd->msgin_index = 0;
2067 ahd->msg_type =
2069 ahd->msgin_index = 0;
2072 ahd_setup_target_msgin(ahd,
2079 ahd_handle_message_phase(ahd);
2085 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
2086 ahd_outb(ahd, SCSISEQ0, ahd_inb(ahd, SCSISEQ0) & ~ENSELO);
2090 ahd_name(ahd), 'A', ahd_inb(ahd, SELID) >> 4);
2093 ahd_inb(ahd, SAVED_SCSIID), ahd_inb(ahd, SAVED_LUN),
2094 ahd_inw(ahd, REG0), ahd_inb(ahd, ACCUM));
2097 ahd_inb(ahd, SEQ_FLAGS), ahd_get_scbptr(ahd),
2098 ahd_find_busy_tcl(ahd,
2099 BUILD_TCL(ahd_inb(ahd, SAVED_SCSIID),
2100 ahd_inb(ahd, SAVED_LUN))),
2101 ahd_inw(ahd, SINDEX));
2104 ahd_inb(ahd, SELID), ahd_inb_scbram(ahd, SCB_SCSIID),
2105 ahd_inb_scbram(ahd, SCB_LUN),
2106 ahd_inb_scbram(ahd, SCB_CONTROL));
2108 ahd_inb(ahd, SCSIBUS), ahd_inb(ahd, SCSISIGI));
2109 printk("SXFRCTL0 == 0x%x\n", ahd_inb(ahd, SXFRCTL0));
2110 printk("SEQCTL0 == 0x%x\n", ahd_inb(ahd, SEQCTL0));
2111 ahd_dump_card_state(ahd);
2112 ahd->msgout_buf[0] = MSG_BUS_DEV_RESET;
2113 ahd->msgout_len = 1;
2114 ahd->msgout_index = 0;
2115 ahd->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
2116 ahd_outb(ahd, MSG_OUT, HOST_MSG);
2117 ahd_assert_atn(ahd);
2122 ahd_handle_proto_violation(ahd);
2129 ahd_fetch_devinfo(ahd, &devinfo);
2130 ahd_handle_ign_wide_residue(ahd, &devinfo);
2137 lastphase = ahd_inb(ahd, LASTPHASE);
2140 ahd_name(ahd), 'A',
2141 SCSIID_TARGET(ahd, ahd_inb(ahd, SAVED_SCSIID)),
2142 lastphase, ahd_inb(ahd, SCSISIGI));
2149 lastphase = ahd_inb(ahd, LASTPHASE);
2152 ahd_name(ahd), 'A',
2153 SCSIID_TARGET(ahd, ahd_inb(ahd, SAVED_SCSIID)),
2154 lastphase, ahd_inb(ahd, SCSISIGI));
2155 ahd_restart(ahd);
2174 scbindex = ahd_get_scbptr(ahd);
2175 scb = ahd_lookup_scb(ahd, scbindex);
2177 lastphase = ahd_inb(ahd, LASTPHASE);
2179 ahd_print_path(ahd, scb);
2183 ahd_print_path(ahd, scb);
2186 ahd_inb(ahd, SEQ_FLAGS) & DPHASE
2197 ahd_freeze_devq(ahd, scb);
2208 ahd_fetch_devinfo(ahd, &devinfo);
2210 ahd_name(ahd), devinfo.channel, devinfo.target,
2212 scbid = ahd_get_scbptr(ahd);
2213 scb = ahd_lookup_scb(ahd, scbid);
2220 ahd_search_qinfifo(ahd, SCB_GET_TARGET(ahd, scb),
2221 SCB_GET_CHANNEL(ahd, scb),
2225 ahd_outb(ahd, SCB_CONTROL,
2226 ahd_inb_scbram(ahd, SCB_CONTROL) & ~MK_MESSAGE);
2234 scbid = ahd_get_scbptr(ahd);
2235 scb = ahd_lookup_scb(ahd, scbid);
2241 ahd_print_path(ahd, scb);
2254 ahd_abort_scbs(ahd, SCB_GET_TARGET(ahd, scb),
2264 ahd_scb_devinfo(ahd, &devinfo, scb);
2266 ahd_handle_devreset(ahd, &devinfo, lun,
2290 scbid = ahd_get_scbptr(ahd);
2291 scb = ahd_lookup_scb(ahd, scbid);
2297 ahd_print_path(ahd, scb);
2306 while ((ahd_inb(ahd, SCSISEQ0) & ENSELO) != 0
2307 && (ahd_inb(ahd, SSTAT0) & SELDO) == 0
2308 && (ahd_inb(ahd, SSTAT1) & SELTO) == 0)
2310 ahd_outb(ahd, SCB_TASK_MANAGEMENT, 0);
2311 ahd_search_qinfifo(ahd, SCB_GET_TARGET(ahd, scb),
2312 SCB_GET_CHANNEL(ahd, scb),
2323 printk("%s: Tracepoint %d\n", ahd_name(ahd),
2329 ahd_handle_hwerrint(ahd);
2332 printk("%s: Unexpected SEQINTCODE %d\n", ahd_name(ahd),
2341 ahd_unpause(ahd);
2345 ahd_handle_scsiint(struct ahd_softc *ahd, u_int intstat)
2356 ahd_update_modes(ahd);
2357 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
2359 status3 = ahd_inb(ahd, SSTAT3) & (NTRAMPERR|OSRAMPERR);
2360 status0 = ahd_inb(ahd, SSTAT0) & (IOERR|OVERRUN|SELDI|SELDO);
2361 status = ahd_inb(ahd, SSTAT1) & (SELTO|SCSIRSTI|BUSFREE|SCSIPERR);
2362 lqistat1 = ahd_inb(ahd, LQISTAT1);
2363 lqostat0 = ahd_inb(ahd, LQOSTAT0);
2364 busfreetime = ahd_inb(ahd, SSTAT2) & BUSFREETIME;
2369 if (((status & SCSIRSTI) != 0) && (ahd->flags & AHD_BUS_RESET_ACTIVE)) {
2370 ahd_outb(ahd, CLRSINT1, CLRSCSIRSTI);
2377 ahd->flags &= ~AHD_BUS_RESET_ACTIVE;
2382 ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
2383 simode0 = ahd_inb(ahd, SIMODE0);
2385 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
2387 scbid = ahd_get_scbptr(ahd);
2388 scb = ahd_lookup_scb(ahd, scbid);
2390 && (ahd_inb(ahd, SEQ_FLAGS) & NOT_IDENTIFIED) != 0)
2396 now_lvd = ahd_inb(ahd, SBLKCTL) & ENAB40;
2398 ahd_name(ahd), now_lvd ? "LVD" : "SE");
2399 ahd_outb(ahd, CLRSINT0, CLRIOERR);
2403 ahd_reset_channel(ahd, 'A', /*Initiate Reset*/TRUE);
2404 ahd_pause(ahd);
2405 ahd_setup_iocell_workaround(ahd);
2406 ahd_unpause(ahd);
2410 ahd_name(ahd));
2411 ahd_reset_channel(ahd, 'A', /*Initiate Reset*/TRUE);
2414 printk("%s: Someone reset channel A\n", ahd_name(ahd));
2415 ahd_reset_channel(ahd, 'A', /*Initiate Reset*/FALSE);
2419 ahd_clear_critical_section(ahd);
2421 ahd_handle_transmission_error(ahd);
2424 printk("%s: lqostat0 == 0x%x!\n", ahd_name(ahd), lqostat0);
2425 ahd_outb(ahd, CLRLQOINT0, lqostat0);
2426 if ((ahd->bugs & AHD_CLRLQO_AUTOCLR_BUG) != 0)
2427 ahd_outb(ahd, CLRLQOINT1, 0);
2430 ahd_outb(ahd, SCSISEQ0, 0);
2433 ahd_clear_critical_section(ahd);
2436 ahd_clear_msg_state(ahd);
2439 ahd_outb(ahd, CLRSINT1, CLRSELTIMEO|CLRBUSFREE|CLRSCSIPERR);
2449 ahd_outb(ahd, CLRSINT0, CLRSELINGO);
2451 scbid = ahd_inw(ahd, WAITING_TID_HEAD);
2452 scb = ahd_lookup_scb(ahd, scbid);
2456 ahd_name(ahd), scbid);
2457 ahd_dump_card_state(ahd);
2462 ahd_print_path(ahd, scb);
2467 ahd_scb_devinfo(ahd, &devinfo, scb);
2469 ahd_freeze_devq(ahd, scb);
2477 ahd_handle_devreset(ahd, &devinfo,
2483 ahd_outb(ahd, CLRINT, CLRSCSIINT);
2484 ahd_iocell_first_selection(ahd);
2485 ahd_unpause(ahd);
2488 ahd_iocell_first_selection(ahd);
2489 ahd_unpause(ahd);
2492 ahd_name(ahd), status3);
2493 ahd_outb(ahd, CLRSINT3, status3);
2497 ahd_clear_critical_section(ahd);
2499 ahd_handle_lqiphase_error(ahd, lqistat1);
2507 ahd_outb(ahd, CLRLQIINT1, CLRLQICRCI_NLQ);
2522 ahd_outb(ahd, SCSISEQ0, 0);
2525 ahd_clear_critical_section(ahd);
2532 busfreetime = ahd_inb(ahd, SSTAT2) & BUSFREETIME;
2533 lqostat1 = ahd_inb(ahd, LQOSTAT1);
2540 ahd_set_modes(ahd, mode, mode);
2541 scbid = ahd_get_scbptr(ahd);
2542 scb = ahd_lookup_scb(ahd, scbid);
2546 ahd_name(ahd), scbid, mode);
2561 && ahd_inb(ahd, LASTPHASE) == P_BUSFREE
2562 && (ahd_inb(ahd, SSTAT0) & SELDI) == 0
2563 && ((ahd_inb(ahd, SSTAT0) & SELDO) == 0
2564 || (ahd_inb(ahd, SCSISEQ0) & ENSELO) == 0))
2584 if (packetized && ahd_inb(ahd, LASTPHASE) == P_BUSFREE) {
2585 restart = ahd_handle_pkt_busfree(ahd, busfreetime);
2588 restart = ahd_handle_nonpkt_busfree(ahd);
2601 ahd_outb(ahd, CLRSINT1, CLRBUSFREE);
2603 && (ahd->bugs & AHD_BUSFREEREV_BUG) != 0)
2604 ahd_outb(ahd, SIMODE1,
2605 ahd_inb(ahd, SIMODE1) & ~ENBUSFREE);
2608 ahd_clear_fifo(ahd, mode);
2610 ahd_clear_msg_state(ahd);
2611 ahd_outb(ahd, CLRINT, CLRSCSIINT);
2613 ahd_restart(ahd);
2615 ahd_unpause(ahd);
2619 ahd_name(ahd), status);
2620 ahd_dump_card_state(ahd);
2621 ahd_clear_intstat(ahd);
2622 ahd_unpause(ahd);
2627 ahd_handle_transmission_error(struct ahd_softc *ahd)
2641 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
2642 lqistat1 = ahd_inb(ahd, LQISTAT1) & ~(LQIPHASE_LQ|LQIPHASE_NLQ);
2643 lqistat2 = ahd_inb(ahd, LQISTAT2);
2645 && (ahd->bugs & AHD_NLQICRC_DELAYED_BUG) != 0) {
2648 ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
2649 lqistate = ahd_inb(ahd, LQISTATE);
2655 ahd_name(ahd));
2660 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
2663 ahd_outb(ahd, CLRLQIINT1, lqistat1);
2664 lastphase = ahd_inb(ahd, LASTPHASE);
2665 curphase = ahd_inb(ahd, SCSISIGI) & PHASE_MASK;
2666 perrdiag = ahd_inb(ahd, PERRDIAG);
2668 ahd_outb(ahd, CLRSINT1, CLRSCSIPERR);
2677 ahd_set_active_fifo(ahd);
2678 scbid = ahd_get_scbptr(ahd);
2679 scb = ahd_lookup_scb(ahd, scbid);
2686 printk("%s: Transmission error detected\n", ahd_name(ahd));
2692 ahd_dump_card_state(ahd);
2699 ahd_name(ahd), lqistat1);
2701 ahd_reset_channel(ahd, 'A', /*Initiate Reset*/TRUE);
2725 ahd_outb(ahd, LQCTL2, LQIRETRY);
2777 "Resetting bus\n", ahd_name(ahd));
2778 ahd_reset_channel(ahd, 'A', /*Initiate Reset*/TRUE);
2783 ahd_reset_channel(ahd, 'A', /*Initiate Reset*/TRUE);
2791 ahd_inb(ahd, SCSIDAT);
2805 ahd->send_msg_perror = msg_out;
2808 ahd_outb(ahd, MSG_OUT, HOST_MSG);
2809 ahd_outb(ahd, CLRINT, CLRSCSIINT);
2810 ahd_unpause(ahd);
2814 ahd_handle_lqiphase_error(struct ahd_softc *ahd, u_int lqistat1)
2819 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
2820 ahd_outb(ahd, CLRLQIINT1, lqistat1);
2830 ahd_set_active_fifo(ahd);
2831 if ((ahd_inb(ahd, SCSISIGO) & ATNO) != 0
2832 && (ahd_inb(ahd, MDFFSTAT) & DLZERO) != 0) {
2835 ahd_outb(ahd, LQCTL2, LQIRETRY);
2838 ahd_outb(ahd, LQCTL2, LQIRETRY);
2841 ahd_dump_card_state(ahd);
2842 ahd_outb(ahd, CLRINT, CLRSCSIINT);
2843 ahd_unpause(ahd);
2846 ahd_dump_card_state(ahd);
2847 ahd_reset_channel(ahd, 'A', /*Initiate Reset*/TRUE);
2856 ahd_handle_pkt_busfree(struct ahd_softc *ahd, u_int busfreetime)
2860 AHD_ASSERT_MODES(ahd, ~(AHD_MODE_UNKNOWN_MSK|AHD_MODE_CFG_MSK),
2862 lqostat1 = ahd_inb(ahd, LQOSTAT1);
2886 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
2887 scbid = ahd_inw(ahd, CURRSCB);
2888 scb = ahd_lookup_scb(ahd, scbid);
2894 ahd_outb(ahd, CLRLQOINT1, CLRLQOBUSFREE);
2895 if ((ahd->bugs & AHD_CLRLQO_AUTOCLR_BUG) != 0)
2896 ahd_outb(ahd, CLRLQOINT1, 0);
2897 ahd_outb(ahd, SCSISEQ0, ahd_inb(ahd, SCSISEQ0) & ~ENSELO);
2898 ahd_flush_device_writes(ahd);
2899 ahd_outb(ahd, CLRSINT0, CLRSELDO);
2907 ahd_outb(ahd, LQCTL2, ahd_inb(ahd, LQCTL2) | LQOTOIDLE);
2913 waiting_h = ahd_inw(ahd, WAITING_TID_HEAD);
2914 saved_scbptr = ahd_get_scbptr(ahd);
2917 ahd_outw(ahd, WAITING_TID_HEAD, scbid);
2918 waiting_t = ahd_inw(ahd, WAITING_TID_TAIL);
2920 ahd_outw(ahd, WAITING_TID_TAIL, scbid);
2923 ahd_set_scbptr(ahd, waiting_h);
2924 next = ahd_inw_scbram(ahd, SCB_NEXT2);
2926 ahd_set_scbptr(ahd, scbid);
2927 ahd_outw(ahd, SCB_NEXT2, next);
2929 ahd_set_scbptr(ahd, saved_scbptr);
2932 ahd_print_path(ahd, scb);
2940 ahd_freeze_devq(ahd, scb);
2944 } else if ((ahd_inb(ahd, PERRDIAG) & PARITYERR) != 0) {
2952 ahd_outb(ahd, CLRSINT1, CLRSCSIPERR|CLRBUSFREE);
2957 ahd_name(ahd));
2962 if (ahd->src_mode != AHD_MODE_SCSI) {
2966 scbid = ahd_get_scbptr(ahd);
2967 scb = ahd_lookup_scb(ahd, scbid);
2968 ahd_print_path(ahd, scb);
2970 ahd_dump_card_state(ahd);
2971 ahd_abort_scbs(ahd, SCB_GET_TARGET(ahd, scb), 'A',
2978 printk("%s: Unexpected PKT busfree condition\n", ahd_name(ahd));
2979 ahd_dump_card_state(ahd);
2988 ahd_handle_nonpkt_busfree(struct ahd_softc *ahd)
3006 lastphase = ahd_inb(ahd, LASTPHASE);
3007 saved_scsiid = ahd_inb(ahd, SAVED_SCSIID);
3008 saved_lun = ahd_inb(ahd, SAVED_LUN);
3009 target = SCSIID_TARGET(ahd, saved_scsiid);
3015 scbid = ahd_get_scbptr(ahd);
3016 scb = ahd_lookup_scb(ahd, scbid);
3018 && (ahd_inb(ahd, SEQ_FLAGS) & NOT_IDENTIFIED) != 0)
3021 ppr_busfree = (ahd->msg_flags & MSG_FLAG_EXPECT_PPR_BUSFREE) != 0;
3026 if (ahd_sent_msg(ahd, AHDMSG_1B, MSG_ABORT_TAG, TRUE)
3027 || ahd_sent_msg(ahd, AHDMSG_1B, MSG_ABORT, TRUE)) {
3032 ahd_print_devinfo(ahd, &devinfo);
3038 sent_msg = ahd->msgout_buf[ahd->msgout_index - 1];
3039 ahd_print_path(ahd, scb);
3063 found = ahd_abort_scbs(ahd, target, 'A', saved_lun,
3068 } else if (ahd_sent_msg(ahd, AHDMSG_1B,
3078 && ahd_match_scb(ahd, scb, target, 'A',
3083 ahd_handle_devreset(ahd, &devinfo, CAM_LUN_WILDCARD,
3087 } else if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_PPR, FALSE)
3106 tinfo = ahd_fetch_transinfo(ahd, devinfo.channel,
3110 ahd_set_width(ahd, &devinfo,
3114 ahd_set_syncrate(ahd, &devinfo,
3135 ahd_freeze_devq(ahd, scb);
3136 ahd_qinfifo_requeue_tail(ahd, scb);
3140 } else if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_WDTR, FALSE)
3150 ahd_set_width(ahd, &devinfo,
3161 ahd_freeze_devq(ahd, scb);
3162 ahd_qinfifo_requeue_tail(ahd, scb);
3165 } else if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_SDTR, FALSE)
3175 ahd_set_syncrate(ahd, &devinfo,
3187 ahd_freeze_devq(ahd, scb);
3188 ahd_qinfifo_requeue_tail(ahd, scb);
3191 } else if ((ahd->msg_flags & MSG_FLAG_EXPECT_IDE_BUSFREE) != 0
3192 && ahd_sent_msg(ahd, AHDMSG_1B,
3200 } else if ((ahd->msg_flags & MSG_FLAG_EXPECT_QASREJ_BUSFREE)
3201 && ahd_sent_msg(ahd, AHDMSG_1B,
3219 && ((ahd->msg_flags & MSG_FLAG_EXPECT_PPR_BUSFREE) != 0)) {
3221 ahd_freeze_devq(ahd, scb);
3224 if ((ahd->msg_flags & MSG_FLAG_IU_REQ_CHANGED) != 0) {
3225 ahd_abort_scbs(ahd, SCB_GET_TARGET(ahd, scb),
3226 SCB_GET_CHANNEL(ahd, scb),
3234 ahd_done(ahd, scb);
3249 ahd_print_path(ahd, scb);
3250 aborted = ahd_abort_scbs(ahd, target, 'A',
3259 printk("%s: ", ahd_name(ahd));
3265 ahd_inw(ahd, PRGMCNT));
3266 ahd_dump_card_state(ahd);
3268 ahd_force_renegotiation(ahd, &devinfo);
3275 ahd_handle_proto_violation(struct ahd_softc *ahd)
3285 ahd_fetch_devinfo(ahd, &devinfo);
3286 scbid = ahd_get_scbptr(ahd);
3287 scb = ahd_lookup_scb(ahd, scbid);
3288 seq_flags = ahd_inb(ahd, SEQ_FLAGS);
3289 curphase = ahd_inb(ahd, SCSISIGI) & PHASE_MASK;
3290 lastphase = ahd_inb(ahd, LASTPHASE);
3298 ahd_print_devinfo(ahd, &devinfo);
3307 ahd_print_devinfo(ahd, &devinfo);
3313 ahd_print_path(ahd, scb);
3315 } else if ((ahd_inb_scbram(ahd, SCB_CONTROL)
3324 ahd_print_path(ahd, scb);
3327 ahd_print_path(ahd, scb);
3329 ahd_dump_card_state(ahd);
3341 found = ahd_reset_channel(ahd, 'A', TRUE);
3343 "%d SCBs aborted\n", ahd_name(ahd), 'A', found);
3350 ahd_outb(ahd, SCSISEQ0,
3351 ahd_inb(ahd, SCSISEQ0) & ~ENSELO);
3352 ahd_assert_atn(ahd);
3353 ahd_outb(ahd, MSG_OUT, HOST_MSG);
3355 ahd_print_devinfo(ahd, &devinfo);
3356 ahd->msgout_buf[0] = MSG_ABORT_TASK;
3357 ahd->msgout_len = 1;
3358 ahd->msgout_index = 0;
3359 ahd->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
3361 ahd_print_path(ahd, scb);
3374 ahd_force_renegotiation(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
3381 ahd_print_devinfo(ahd, devinfo);
3385 targ_info = ahd_fetch_transinfo(ahd,
3390 ahd_update_neg_request(ahd, devinfo, tstate,
3396 ahd_clear_critical_section(struct ahd_softc *ahd)
3410 if (ahd->num_critical_sections == 0)
3423 saved_modes = ahd_save_modes(ahd);
3429 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
3430 seqaddr = ahd_inw(ahd, CURADDR);
3432 cs = ahd->critical_sections;
3433 for (i = 0; i < ahd->num_critical_sections; i++, cs++) {
3439 if (i == ahd->num_critical_sections)
3445 ahd_name(ahd), ahd_name(ahd), first_instr,
3447 ahd_dump_card_state(ahd);
3454 printk("%s: Single stepping at 0x%x\n", ahd_name(ahd),
3460 ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
3461 simode0 = ahd_inb(ahd, SIMODE0);
3462 simode3 = ahd_inb(ahd, SIMODE3);
3463 lqimode0 = ahd_inb(ahd, LQIMODE0);
3464 lqimode1 = ahd_inb(ahd, LQIMODE1);
3465 lqomode0 = ahd_inb(ahd, LQOMODE0);
3466 lqomode1 = ahd_inb(ahd, LQOMODE1);
3467 ahd_outb(ahd, SIMODE0, 0);
3468 ahd_outb(ahd, SIMODE3, 0);
3469 ahd_outb(ahd, LQIMODE0, 0);
3470 ahd_outb(ahd, LQIMODE1, 0);
3471 ahd_outb(ahd, LQOMODE0, 0);
3472 ahd_outb(ahd, LQOMODE1, 0);
3473 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
3474 simode1 = ahd_inb(ahd, SIMODE1);
3481 ahd_outb(ahd, SIMODE1, simode1 & ENBUSFREE);
3482 ahd_outb(ahd, SEQCTL0, ahd_inb(ahd, SEQCTL0) | STEP);
3485 ahd_outb(ahd, CLRSINT1, CLRBUSFREE);
3486 ahd_outb(ahd, CLRINT, CLRSCSIINT);
3487 ahd_set_modes(ahd, ahd->saved_src_mode, ahd->saved_dst_mode);
3488 ahd_outb(ahd, HCNTRL, ahd->unpause);
3489 while (!ahd_is_paused(ahd))
3491 ahd_update_modes(ahd);
3494 ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
3495 ahd_outb(ahd, SIMODE0, simode0);
3496 ahd_outb(ahd, SIMODE3, simode3);
3497 ahd_outb(ahd, LQIMODE0, lqimode0);
3498 ahd_outb(ahd, LQIMODE1, lqimode1);
3499 ahd_outb(ahd, LQOMODE0, lqomode0);
3500 ahd_outb(ahd, LQOMODE1, lqomode1);
3501 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
3502 ahd_outb(ahd, SEQCTL0, ahd_inb(ahd, SEQCTL0) & ~STEP);
3503 ahd_outb(ahd, SIMODE1, simode1);
3510 ahd_outb(ahd, CLRINT, CLRSCSIINT);
3512 ahd_restore_modes(ahd, saved_modes);
3519 ahd_clear_intstat(struct ahd_softc *ahd)
3521 AHD_ASSERT_MODES(ahd, ~(AHD_MODE_UNKNOWN_MSK|AHD_MODE_CFG_MSK),
3524 ahd_outb(ahd, CLRLQIINT0, CLRLQIATNQAS|CLRLQICRCT1|CLRLQICRCT2
3526 ahd_outb(ahd, CLRLQIINT1, CLRLQIPHASE_LQ|CLRLQIPHASE_NLQ|CLRLIQABORT
3529 ahd_outb(ahd, CLRLQOINT0, CLRLQOTARGSCBPERR|CLRLQOSTOPT2|CLRLQOATNLQ
3531 ahd_outb(ahd, CLRLQOINT1, CLRLQOINITSCBPERR|CLRLQOSTOPI2|CLRLQOBADQAS
3533 if ((ahd->bugs & AHD_CLRLQO_AUTOCLR_BUG) != 0) {
3534 ahd_outb(ahd, CLRLQOINT0, 0);
3535 ahd_outb(ahd, CLRLQOINT1, 0);
3537 ahd_outb(ahd, CLRSINT3, CLRNTRAMPERR|CLROSRAMPERR);
3538 ahd_outb(ahd, CLRSINT1, CLRSELTIMEO|CLRATNO|CLRSCSIRSTI
3540 ahd_outb(ahd, CLRSINT0, CLRSELDO|CLRSELDI|CLRSELINGO
3542 ahd_outb(ahd, CLRINT, CLRSCSIINT);
3557 ahd_alloc_tstate(struct ahd_softc *ahd, u_int scsi_id, char channel)
3563 master_tstate = ahd->enabled_targets[ahd->our_id];
3564 if (ahd->enabled_targets[scsi_id] != NULL
3565 && ahd->enabled_targets[scsi_id] != master_tstate)
3567 ahd_name(ahd));
3589 ahd->enabled_targets[scsi_id] = tstate;
3599 ahd_free_tstate(struct ahd_softc *ahd, u_int scsi_id, char channel, int force)
3607 if (scsi_id == ahd->our_id
3611 tstate = ahd->enabled_targets[scsi_id];
3614 ahd->enabled_targets[scsi_id] = NULL;
3625 ahd_devlimited_syncrate(struct ahd_softc *ahd,
3632 if ((ahd_inb(ahd, SBLKCTL) & ENAB40) != 0
3633 && (ahd_inb(ahd, SSTAT2) & EXP_ACTIVE) == 0) {
3664 ahd_find_syncrate(ahd, period, ppr_options, maxsync);
3674 ahd_find_syncrate(struct ahd_softc *ahd, u_int *period,
3713 ahd_validate_offset(struct ahd_softc *ahd,
3724 if ((ahd->bugs & AHD_PACED_NEGTABLE_BUG) != 0)
3744 ahd_validate_width(struct ahd_softc *ahd, struct ahd_initiator_tinfo *tinfo,
3749 if (ahd->features & AHD_WIDE) {
3774 ahd_update_neg_request(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
3788 if ((ahd->features & AHD_WIDE) != 0)
3817 ahd_set_syncrate(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
3837 tinfo = ahd_fetch_transinfo(ahd, devinfo->channel, devinfo->our_scsiid,
3867 ahd_send_async(ahd, devinfo->channel, devinfo->target,
3875 ahd_name(ahd), devinfo->target,
3905 ahd_name(ahd), devinfo->target,
3921 ahd_pause(ahd);
3922 ahd_update_neg_table(ahd, devinfo, &tinfo->curr);
3924 ahd_unpause(ahd);
3925 if (ahd->msg_type != MSG_TYPE_NONE) {
3930 ahd_print_devinfo(ahd, devinfo);
3934 ahd->msg_flags |= MSG_FLAG_EXPECT_PPR_BUSFREE
3942 ahd->msg_flags |= MSG_FLAG_EXPECT_PPR_BUSFREE;
3947 update_needed += ahd_update_neg_request(ahd, devinfo, tstate,
3951 ahd_update_pending_scbs(ahd);
3963 ahd_set_width(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
3974 tinfo = ahd_fetch_transinfo(ahd, devinfo->channel, devinfo->our_scsiid,
3989 ahd_send_async(ahd, devinfo->channel, devinfo->target,
3993 ahd_name(ahd), devinfo->target,
4000 ahd_pause(ahd);
4001 ahd_update_neg_table(ahd, devinfo, &tinfo->curr);
4003 ahd_unpause(ahd);
4006 update_needed += ahd_update_neg_request(ahd, devinfo, tstate,
4009 ahd_update_pending_scbs(ahd);
4017 ahd_set_tags(struct ahd_softc *ahd, struct scsi_cmnd *cmd,
4022 ahd_platform_set_tags(ahd, sdev, devinfo, alg);
4023 ahd_send_async(ahd, devinfo->channel, devinfo->target,
4028 ahd_update_neg_table(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
4037 uint8_t iocell_opts[sizeof(ahd->iocell_opts)];
4039 saved_modes = ahd_save_modes(ahd);
4040 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
4042 saved_negoaddr = ahd_inb(ahd, NEGOADDR);
4043 ahd_outb(ahd, NEGOADDR, devinfo->target);
4046 memcpy(iocell_opts, ahd->iocell_opts, sizeof(ahd->iocell_opts));
4054 if ((ahd->bugs & AHD_PACED_NEGTABLE_BUG) != 0) {
4086 if ((ahd->features & AHD_NEW_IOCELL_OPTS) != 0
4098 if ((ahd->bugs & AHD_PACED_NEGTABLE_BUG) != 0) {
4108 ahd_outb(ahd, ANNEXCOL, AHD_ANNEXCOL_PRECOMP_SLEW);
4109 ahd_outb(ahd, ANNEXDAT, iocell_opts[AHD_PRECOMP_SLEW_INDEX]);
4110 ahd_outb(ahd, ANNEXCOL, AHD_ANNEXCOL_AMPLITUDE);
4111 ahd_outb(ahd, ANNEXDAT, iocell_opts[AHD_AMPLITUDE_INDEX]);
4113 ahd_outb(ahd, NEGPERIOD, period);
4114 ahd_outb(ahd, NEGPPROPTS, ppr_opts);
4115 ahd_outb(ahd, NEGOFFSET, offset);
4125 if (ahd->features & AHD_AIC79XXB_SLOWCRC) {
4136 ahd_outb(ahd, NEGCONOPTS, con_opts);
4137 ahd_outb(ahd, NEGOADDR, saved_negoaddr);
4138 ahd_restore_modes(ahd, saved_modes);
4148 ahd_update_pending_scbs(struct ahd_softc *ahd)
4167 LIST_FOREACH(pending_scb, &ahd->pending_scbs, pending_links) {
4172 ahd_scb_devinfo(ahd, &devinfo, pending_scb);
4173 tinfo = ahd_fetch_transinfo(ahd, devinfo.channel,
4181 ahd_sync_scb(ahd, pending_scb,
4189 if (ahd_is_paused(ahd)) {
4193 ahd_pause(ahd);
4204 saved_modes = ahd_save_modes(ahd);
4205 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
4206 if ((ahd_inb(ahd, SCSISIGI) & BSYI) != 0
4207 && (ahd_inb(ahd, SSTAT0) & (SELDO|SELINGO)) == 0)
4208 ahd_outb(ahd, SCSISEQ0, ahd_inb(ahd, SCSISEQ0) & ~ENSELO);
4209 saved_scbptr = ahd_get_scbptr(ahd);
4211 LIST_FOREACH(pending_scb, &ahd->pending_scbs, pending_links) {
4216 ahd_set_scbptr(ahd, scb_tag);
4217 control = ahd_inb_scbram(ahd, SCB_CONTROL);
4220 ahd_outb(ahd, SCB_CONTROL, control);
4222 ahd_set_scbptr(ahd, saved_scbptr);
4223 ahd_restore_modes(ahd, saved_modes);
4226 ahd_unpause(ahd);
4231 ahd_fetch_devinfo(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
4238 saved_modes = ahd_save_modes(ahd);
4239 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
4241 if (ahd_inb(ahd, SSTAT0) & TARGET)
4247 && (ahd_inb(ahd, SEQ_FLAGS) & CMDPHASE_PENDING) != 0) {
4249 our_id = ahd_inb(ahd, TARGIDIN) & OID;
4251 our_id = ahd_inb(ahd, TOWNID);
4253 our_id = ahd_inb(ahd, IOWNID);
4255 saved_scsiid = ahd_inb(ahd, SAVED_SCSIID);
4258 SCSIID_TARGET(ahd, saved_scsiid),
4259 ahd_inb(ahd, SAVED_LUN),
4260 SCSIID_CHANNEL(ahd, saved_scsiid),
4262 ahd_restore_modes(ahd, saved_modes);
4266 ahd_print_devinfo(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
4268 printk("%s:%c:%d:%d: ", ahd_name(ahd), 'A',
4306 ahd_scb_devinfo(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
4316 ahd_compile_devinfo(devinfo, our_id, SCB_GET_TARGET(ahd, scb),
4317 SCB_GET_LUN(scb), SCB_GET_CHANNEL(ahd, scb), role);
4329 ahd_setup_initiator_msgout(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
4337 ahd->msgout_index = 0;
4338 ahd->msgout_len = 0;
4340 if (ahd_currently_packetized(ahd))
4341 ahd->msg_flags |= MSG_FLAG_PACKETIZED;
4343 if (ahd->send_msg_perror
4344 && ahd_inb(ahd, MSG_OUT) == HOST_MSG) {
4345 ahd->msgout_buf[ahd->msgout_index++] = ahd->send_msg_perror;
4346 ahd->msgout_len++;
4347 ahd->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
4355 "I_T msgin. Issuing NO-OP\n", ahd_name(ahd));
4356 ahd->msgout_buf[ahd->msgout_index++] = MSG_NOOP;
4357 ahd->msgout_len++;
4358 ahd->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
4364 && ahd_inb(ahd, MSG_OUT) == MSG_IDENTIFYFLAG) {
4370 ahd->msgout_buf[ahd->msgout_index++] = identify_msg;
4371 ahd->msgout_len++;
4374 ahd->msgout_buf[ahd->msgout_index++] =
4376 ahd->msgout_buf[ahd->msgout_index++] = SCB_GET_TAG(scb);
4377 ahd->msgout_len += 2;
4382 ahd->msgout_buf[ahd->msgout_index++] = MSG_BUS_DEV_RESET;
4383 ahd->msgout_len++;
4384 ahd_print_path(ahd, scb);
4393 ahd_outb(ahd, SCSISEQ0, 0);
4397 ahd->msgout_buf[ahd->msgout_index++] = MSG_ABORT_TAG;
4399 ahd->msgout_buf[ahd->msgout_index++] = MSG_ABORT;
4401 ahd->msgout_len++;
4402 ahd_print_path(ahd, scb);
4412 ahd_outb(ahd, SCSISEQ0, 0);
4414 ahd_build_transfer_msg(ahd, devinfo);
4422 ahd_outb(ahd, SCSISEQ0, 0);
4430 ahd_inb_scbram(ahd, SCB_CONTROL), ahd_inb(ahd, MSG_OUT),
4438 ahd_outb(ahd, SCB_CONTROL,
4439 ahd_inb_scbram(ahd, SCB_CONTROL) & ~MK_MESSAGE);
4441 ahd->msgout_index = 0;
4442 ahd->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
4450 ahd_build_transfer_msg(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
4466 tinfo = ahd_fetch_transinfo(ahd, devinfo->channel, devinfo->our_scsiid,
4480 ahd_devlimited_syncrate(ahd, tinfo, &period,
4501 if ((ahd->features & AHD_WIDE) != 0)
4507 ahd_print_devinfo(ahd, devinfo);
4526 ahd_validate_offset(ahd, tinfo, period, &offset,
4531 ahd_construct_ppr(ahd, devinfo, period, offset,
4534 ahd_construct_sdtr(ahd, devinfo, period, offset);
4537 ahd_construct_wdtr(ahd, devinfo, tinfo->goal.width);
4546 ahd_construct_sdtr(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
4551 ahd->msgout_index += spi_populate_sync_msg(
4552 ahd->msgout_buf + ahd->msgout_index, period, offset);
4553 ahd->msgout_len += 5;
4556 ahd_name(ahd), devinfo->channel, devinfo->target,
4566 ahd_construct_wdtr(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
4569 ahd->msgout_index += spi_populate_width_msg(
4570 ahd->msgout_buf + ahd->msgout_index, bus_width);
4571 ahd->msgout_len += 4;
4574 ahd_name(ahd), devinfo->channel, devinfo->target,
4584 ahd_construct_ppr(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
4597 ahd->msgout_index += spi_populate_ppr_msg(
4598 ahd->msgout_buf + ahd->msgout_index, period, offset,
4600 ahd->msgout_len += 8;
4603 "offset %x, ppr_options %x\n", ahd_name(ahd),
4613 ahd_clear_msg_state(struct ahd_softc *ahd)
4617 saved_modes = ahd_save_modes(ahd);
4618 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
4619 ahd->send_msg_perror = 0;
4620 ahd->msg_flags = MSG_FLAG_NONE;
4621 ahd->msgout_len = 0;
4622 ahd->msgin_index = 0;
4623 ahd->msg_type = MSG_TYPE_NONE;
4624 if ((ahd_inb(ahd, SCSISIGO) & ATNO) != 0) {
4629 ahd_outb(ahd, CLRSINT1, CLRATNO);
4631 ahd_outb(ahd, MSG_OUT, MSG_NOOP);
4632 ahd_outb(ahd, SEQ_FLAGS2,
4633 ahd_inb(ahd, SEQ_FLAGS2) & ~TARGET_MSG_PENDING);
4634 ahd_restore_modes(ahd, saved_modes);
4641 ahd_handle_message_phase(struct ahd_softc *ahd)
4647 ahd_fetch_devinfo(ahd, &devinfo);
4649 bus_phase = ahd_inb(ahd, LASTPHASE);
4651 if ((ahd_inb(ahd, LQISTAT2) & LQIPHASE_OUTPKT) != 0) {
4653 ahd_outb(ahd, LQCTL2, LQIRETRY);
4656 switch (ahd->msg_type) {
4663 if (ahd->msgout_len == 0 && ahd->send_msg_perror == 0)
4668 ahd_print_devinfo(ahd, &devinfo);
4688 ahd_outb(ahd, CLRSINT1, CLRATNO);
4689 ahd->send_msg_perror = 0;
4690 ahd->msg_type = MSG_TYPE_INITIATOR_MSGIN;
4691 ahd->msgin_index = 0;
4698 if (ahd->send_msg_perror) {
4699 ahd_outb(ahd, CLRSINT1, CLRATNO);
4700 ahd_outb(ahd, CLRSINT1, CLRREQINIT);
4703 printk(" byte 0x%x\n", ahd->send_msg_perror);
4711 if ((ahd->msg_flags & MSG_FLAG_PACKETIZED) != 0
4712 && ahd->send_msg_perror == MSG_INITIATOR_DET_ERR)
4713 ahd->msg_flags |= MSG_FLAG_EXPECT_IDE_BUSFREE;
4715 ahd_outb(ahd, RETURN_2, ahd->send_msg_perror);
4716 ahd_outb(ahd, RETURN_1, CONT_MSG_LOOP_WRITE);
4720 msgdone = ahd->msgout_index == ahd->msgout_len;
4727 ahd->msgout_index = 0;
4728 ahd_assert_atn(ahd);
4731 lastbyte = ahd->msgout_index == (ahd->msgout_len - 1);
4734 ahd_outb(ahd, CLRSINT1, CLRATNO);
4741 ahd_outb(ahd, CLRSINT1, CLRREQINIT);
4745 ahd->msgout_buf[ahd->msgout_index]);
4747 ahd_outb(ahd, RETURN_2, ahd->msgout_buf[ahd->msgout_index++]);
4748 ahd_outb(ahd, RETURN_1, CONT_MSG_LOOP_WRITE);
4758 ahd_print_devinfo(ahd, &devinfo);
4771 ahd->msgin_index = 0;
4773 && (ahd->send_msg_perror != 0
4774 || (ahd->msgout_len != 0
4775 && ahd->msgout_index == 0))) {
4776 ahd->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
4784 ahd->msgin_buf[ahd->msgin_index] = ahd_inb(ahd, SCSIBUS);
4788 ahd->msgin_buf[ahd->msgin_index]);
4791 message_done = ahd_parse_msg(ahd, &devinfo);
4798 ahd->msgin_index = 0;
4805 if (ahd->msgout_len != 0) {
4808 ahd_print_devinfo(ahd, &devinfo);
4812 ahd_assert_atn(ahd);
4815 ahd->msgin_index++;
4821 ahd_outb(ahd, CLRSINT1, CLRREQINIT);
4822 ahd_outb(ahd, RETURN_1, CONT_MSG_LOOP_READ);
4834 ahd_outb(ahd, RETURN_1, CONT_MSG_LOOP_TARG);
4836 if (ahd->msgout_len == 0)
4845 if ((ahd_inb(ahd, SCSISIGI) & ATNI) != 0
4846 && ahd->msgout_index > 0)
4859 ahd->msg_type = MSG_TYPE_TARGET_MSGOUT;
4860 ahd_outb(ahd, SCSISIGO, P_MESGOUT | BSYO);
4861 ahd->msgin_index = 0;
4863 ahd_inb(ahd, SCSIDAT);
4864 ahd_outb(ahd, SXFRCTL0,
4865 ahd_inb(ahd, SXFRCTL0) | SPIOEN);
4869 msgdone = ahd->msgout_index == ahd->msgout_len;
4871 ahd_outb(ahd, SXFRCTL0,
4872 ahd_inb(ahd, SXFRCTL0) & ~SPIOEN);
4880 ahd_outb(ahd, SXFRCTL0, ahd_inb(ahd, SXFRCTL0) | SPIOEN);
4881 ahd_outb(ahd, SCSIDAT, ahd->msgout_buf[ahd->msgout_index++]);
4892 ahd_outb(ahd, RETURN_1, CONT_MSG_LOOP_TARG);
4898 lastbyte = (ahd_inb(ahd, SCSISIGI) & ATNI) == 0;
4905 ahd_outb(ahd, SXFRCTL0, ahd_inb(ahd, SXFRCTL0) & ~SPIOEN);
4906 ahd->msgin_buf[ahd->msgin_index] = ahd_inb(ahd, SCSIDAT);
4907 msgdone = ahd_parse_msg(ahd, &devinfo);
4918 ahd->msgin_index++;
4921 ahd->msgin_index = 0;
4927 if (ahd->msgout_len != 0) {
4928 ahd_outb(ahd, SCSISIGO, P_MESGIN | BSYO);
4929 ahd_outb(ahd, SXFRCTL0,
4930 ahd_inb(ahd, SXFRCTL0) | SPIOEN);
4931 ahd->msg_type = MSG_TYPE_TARGET_MSGIN;
4932 ahd->msgin_index = 0;
4941 ahd_outb(ahd, SXFRCTL0,
4942 ahd_inb(ahd, SXFRCTL0) | SPIOEN);
4952 if ((ahd->msg_flags & MSG_FLAG_PACKETIZED) != 0) {
4954 ahd_name(ahd));
4955 ahd_clear_msg_state(ahd);
4960 ahd_outb(ahd, LASTPHASE, P_BUSFREE);
4961 ahd_outb(ahd, SEQ_FLAGS, NOT_IDENTIFIED|NO_CDB_SENT);
4962 ahd_outb(ahd, SEQCTL0, FASTMODE|SEQRESET);
4964 ahd_clear_msg_state(ahd);
4965 ahd_outb(ahd, RETURN_1, EXIT_MSG_LOOP);
4977 ahd_sent_msg(struct ahd_softc *ahd, ahd_msgtype type, u_int msgval, int full)
4985 while (index < ahd->msgout_len) {
4986 if (ahd->msgout_buf[index] == MSG_EXTENDED) {
4989 end_index = index + 1 + ahd->msgout_buf[index + 1];
4990 if (ahd->msgout_buf[index+2] == msgval
4994 if (ahd->msgout_index > end_index)
4996 } else if (ahd->msgout_index > index)
5000 } else if (ahd->msgout_buf[index] >= MSG_SIMPLE_TASK
5001 && ahd->msgout_buf[index] <= MSG_IGN_WIDE_RESIDUE) {
5008 && ahd->msgout_index > index
5009 && (ahd->msgout_buf[index] == msgval
5010 || ((ahd->msgout_buf[index] & MSG_IDENTIFYFLAG) != 0
5026 ahd_parse_msg(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
5037 tinfo = ahd_fetch_transinfo(ahd, devinfo->channel, devinfo->our_scsiid,
5051 switch (ahd->msgin_buf[0]) {
5064 response = ahd_handle_msg_reject(ahd, devinfo);
5072 if (ahd->msgin_index < 2)
5074 switch (ahd->msgin_buf[2]) {
5082 if (ahd->msgin_buf[1] != MSG_EXT_SDTR_LEN) {
5094 if (ahd->msgin_index < (MSG_EXT_SDTR_LEN + 1))
5097 period = ahd->msgin_buf[3];
5099 saved_offset = offset = ahd->msgin_buf[4];
5100 ahd_devlimited_syncrate(ahd, tinfo, &period,
5102 ahd_validate_offset(ahd, tinfo, period, &offset,
5108 ahd_name(ahd), devinfo->channel,
5110 ahd->msgin_buf[3], saved_offset,
5113 ahd_set_syncrate(ahd, devinfo, period,
5123 if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_SDTR, TRUE)) {
5137 ahd_name(ahd), devinfo->channel,
5140 ahd->msgout_index = 0;
5141 ahd->msgout_len = 0;
5142 ahd_construct_sdtr(ahd, devinfo,
5144 ahd->msgout_index = 0;
5157 if (ahd->msgin_buf[1] != MSG_EXT_WDTR_LEN) {
5169 if (ahd->msgin_index < (MSG_EXT_WDTR_LEN + 1))
5172 bus_width = ahd->msgin_buf[3];
5174 ahd_validate_width(ahd, tinfo, &bus_width,
5179 ahd_name(ahd), devinfo->channel,
5184 if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_WDTR, TRUE)) {
5195 ahd_name(ahd), devinfo->channel,
5208 ahd_name(ahd), devinfo->channel,
5211 ahd->msgout_index = 0;
5212 ahd->msgout_len = 0;
5213 ahd_construct_wdtr(ahd, devinfo, bus_width);
5214 ahd->msgout_index = 0;
5227 ahd_update_neg_request(ahd, devinfo, tstate,
5229 ahd_set_width(ahd, devinfo, bus_width,
5237 ahd->msgout_index = 0;
5238 ahd->msgout_len = 0;
5239 ahd_build_transfer_msg(ahd, devinfo);
5240 ahd->msgout_index = 0;
5256 if (ahd->msgin_buf[1] != MSG_EXT_PPR_LEN) {
5268 if (ahd->msgin_index < (MSG_EXT_PPR_LEN + 1))
5271 period = ahd->msgin_buf[3];
5272 offset = ahd->msgin_buf[5];
5273 bus_width = ahd->msgin_buf[6];
5275 ppr_options = ahd->msgin_buf[7];
5294 ahd_validate_width(ahd, tinfo, &bus_width,
5296 ahd_devlimited_syncrate(ahd, tinfo, &period,
5298 ahd_validate_offset(ahd, tinfo, period, &offset,
5301 if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_PPR, TRUE)) {
5320 ahd_name(ahd), devinfo->channel,
5325 ahd_name(ahd), devinfo->channel,
5327 ahd->msgout_index = 0;
5328 ahd->msgout_len = 0;
5329 ahd_construct_ppr(ahd, devinfo, period, offset,
5331 ahd->msgout_index = 0;
5339 ahd_name(ahd), devinfo->channel,
5341 saved_width, ahd->msgin_buf[3],
5345 ahd_set_width(ahd, devinfo, bus_width,
5348 ahd_set_syncrate(ahd, devinfo, period,
5365 ahd_handle_devreset(ahd, devinfo, CAM_LUN_WILDCARD,
5369 ahd_restart(ahd);
5384 if (ahd->msgin_buf[0] == MSG_ABORT_TAG)
5385 tag = ahd_inb(ahd, INITIATOR_TAG);
5386 ahd_abort_scbs(ahd, devinfo->target, devinfo->channel,
5390 tstate = ahd->enabled_targets[devinfo->our_scsiid];
5396 ahd_queue_lstate_event(ahd, lstate,
5398 ahd->msgin_buf[0],
5400 ahd_send_lstate_events(ahd, lstate);
5403 ahd_restart(ahd);
5412 ahd_name(ahd), ahd_inb(ahd, SCSISIGI));
5414 ahd->msg_flags |= MSG_FLAG_EXPECT_QASREJ_BUSFREE;
5426 ahd->msgout_index = 0;
5427 ahd->msgout_len = 1;
5428 ahd->msgout_buf[0] = MSG_MESSAGE_REJECT;
5435 ahd->msgout_len = 0;
5444 ahd_handle_msg_reject(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
5459 scb_index = ahd_get_scbptr(ahd);
5460 scb = ahd_lookup_scb(ahd, scb_index);
5461 tinfo = ahd_fetch_transinfo(ahd, devinfo->channel,
5465 last_msg = ahd_inb(ahd, LAST_MSG);
5467 if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_PPR, /*full*/FALSE)) {
5468 if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_PPR, /*full*/TRUE)
5478 ahd_name(ahd), devinfo->channel,
5493 ahd_name(ahd), devinfo->channel,
5500 ahd->msgout_index = 0;
5501 ahd->msgout_len = 0;
5502 ahd_build_transfer_msg(ahd, devinfo);
5503 ahd->msgout_index = 0;
5505 } else if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_WDTR, /*full*/FALSE)) {
5509 "8bit transfers\n", ahd_name(ahd),
5511 ahd_set_width(ahd, devinfo, MSG_EXT_WDTR_BUS_8_BIT,
5524 ahd->msgout_index = 0;
5525 ahd->msgout_len = 0;
5526 ahd_build_transfer_msg(ahd, devinfo);
5527 ahd->msgout_index = 0;
5530 } else if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_SDTR, /*full*/FALSE)) {
5532 ahd_set_syncrate(ahd, devinfo, /*period*/0,
5538 ahd_name(ahd), devinfo->channel,
5548 "Performing non-tagged I/O\n", ahd_name(ahd),
5550 ahd_set_tags(ahd, scb->io_ctx, devinfo, AHD_QUEUE_NONE);
5555 ahd_name(ahd), devinfo->channel, devinfo->target,
5558 ahd_set_tags(ahd, scb->io_ctx, devinfo, AHD_QUEUE_BASIC);
5566 ahd_outb(ahd, SCB_CONTROL,
5567 ahd_inb_scbram(ahd, SCB_CONTROL) & mask);
5571 ahd_outb(ahd, MSG_OUT, MSG_IDENTIFYFLAG);
5572 ahd_assert_atn(ahd);
5573 ahd_busy_tcl(ahd, BUILD_TCL(scb->hscb->scsiid, devinfo->lun),
5581 ahd_search_qinfifo(ahd, SCB_GET_TARGET(ahd, scb),
5582 SCB_GET_CHANNEL(ahd, scb),
5586 } else if (ahd_sent_msg(ahd, AHDMSG_1B, MSG_IDENTIFYFLAG, TRUE)) {
5591 ahd->msg_flags |= MSG_FLAG_EXPECT_PPR_BUSFREE
5594 ahd_force_renegotiation(ahd, devinfo);
5595 ahd->msgout_index = 0;
5596 ahd->msgout_len = 0;
5597 ahd_build_transfer_msg(ahd, devinfo);
5598 ahd->msgout_index = 0;
5605 ahd_name(ahd), devinfo->channel, devinfo->target,
5615 ahd_handle_ign_wide_residue(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
5620 scb_index = ahd_get_scbptr(ahd);
5621 scb = ahd_lookup_scb(ahd, scb_index);
5622 if ((ahd_inb(ahd, SEQ_FLAGS) & DPHASE) == 0
5638 sgptr = ahd_inb_scbram(ahd, SCB_RESIDUAL_SGPTR);
5640 && (ahd_inb_scbram(ahd, SCB_TASK_ATTRIBUTE)
5654 sgptr = ahd_inl_scbram(ahd, SCB_RESIDUAL_SGPTR);
5655 data_cnt = ahd_inl_scbram(ahd, SCB_RESIDUAL_DATACNT);
5664 data_addr = ahd_inq(ahd, SHADDR);
5668 if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0) {
5671 sg = ahd_sg_bus_to_virt(ahd, scb, sgptr);
5698 sgptr = ahd_sg_virt_to_bus(ahd, scb,
5704 sg = ahd_sg_bus_to_virt(ahd, scb, sgptr);
5731 sgptr = ahd_sg_virt_to_bus(ahd, scb,
5741 ahd_outb(ahd, SCB_TASK_ATTRIBUTE,
5742 ahd_inb_scbram(ahd, SCB_TASK_ATTRIBUTE)
5745 ahd_outl(ahd, SCB_RESIDUAL_SGPTR, sgptr);
5746 ahd_outl(ahd, SCB_RESIDUAL_DATACNT, data_cnt);
5761 ahd_reinitialize_dataptrs(struct ahd_softc *ahd)
5771 AHD_ASSERT_MODES(ahd, AHD_MODE_DFF0_MSK|AHD_MODE_DFF1_MSK,
5774 scb_index = ahd_get_scbptr(ahd);
5775 scb = ahd_lookup_scb(ahd, scb_index);
5781 ahd_outb(ahd, DFFSXFRCTL, CLRCHN);
5783 while (--wait && !(ahd_inb(ahd, MDFFSTAT) & FIFOFREE))
5786 ahd_print_path(ahd, scb);
5788 ahd_outb(ahd, DFFSXFRCTL, RSTCHN|CLRSHCNT);
5790 saved_modes = ahd_save_modes(ahd);
5791 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
5792 ahd_outb(ahd, DFFSTAT,
5793 ahd_inb(ahd, DFFSTAT)
5800 sgptr = ahd_inl_scbram(ahd, SCB_RESIDUAL_SGPTR);
5803 resid = (ahd_inb_scbram(ahd, SCB_RESIDUAL_DATACNT + 2) << 16)
5804 | (ahd_inb_scbram(ahd, SCB_RESIDUAL_DATACNT + 1) << 8)
5805 | ahd_inb_scbram(ahd, SCB_RESIDUAL_DATACNT);
5807 if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0) {
5810 sg = ahd_sg_bus_to_virt(ahd, scb, sgptr);
5818 ahd_outl(ahd, HADDR + 4, dataptr >> 32);
5822 sg = ahd_sg_bus_to_virt(ahd, scb, sgptr);
5830 ahd_outb(ahd, HADDR + 4,
5833 ahd_outl(ahd, HADDR, dataptr);
5834 ahd_outb(ahd, HCNT + 2, resid >> 16);
5835 ahd_outb(ahd, HCNT + 1, resid >> 8);
5836 ahd_outb(ahd, HCNT, resid);
5843 ahd_handle_devreset(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
5852 found = ahd_abort_scbs(ahd, devinfo->target, devinfo->channel,
5861 tstate = ahd->enabled_targets[devinfo->our_scsiid];
5880 ahd_queue_lstate_event(ahd, lstate, devinfo->our_scsiid,
5882 ahd_send_lstate_events(ahd, lstate);
5890 ahd_set_width(ahd, devinfo, MSG_EXT_WDTR_BUS_8_BIT,
5892 ahd_set_syncrate(ahd, devinfo, /*period*/0, /*offset*/0,
5897 ahd_send_async(ahd, devinfo->channel, devinfo->target,
5901 printk("%s: %s on %c:%d. %d SCBs aborted\n", ahd_name(ahd),
5907 ahd_setup_target_msgin(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
5916 ahd->msgout_index = 0;
5917 ahd->msgout_len = 0;
5920 ahd_build_transfer_msg(ahd, devinfo);
5924 ahd->msgout_index = 0;
5925 ahd->msg_type = MSG_TYPE_TARGET_MSGIN;
5930 ahd_sglist_size(struct ahd_softc *ahd)
5935 if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0)
5947 ahd_sglist_allocsize(struct ahd_softc *ahd)
5955 sg_list_increment = ahd_sglist_size(ahd);
5994 struct ahd_softc *ahd;
5997 ahd = kmalloc(sizeof(*ahd), GFP_ATOMIC);
5998 if (!ahd) {
6004 ahd = device_get_softc((device_t)platform_arg);
6006 memset(ahd, 0, sizeof(*ahd));
6007 ahd->seep_config = kmalloc(sizeof(*ahd->seep_config), GFP_ATOMIC);
6008 if (ahd->seep_config == NULL) {
6010 kfree(ahd);
6015 LIST_INIT(&ahd->pending_scbs);
6017 ahd->name = name;
6018 ahd->unit = -1;
6019 ahd->description = NULL;
6020 ahd->bus_description = NULL;
6021 ahd->channel = 'A';
6022 ahd->chip = AHD_NONE;
6023 ahd->features = AHD_FENONE;
6024 ahd->bugs = AHD_BUGNONE;
6025 ahd->flags = AHD_SPCHK_ENB_A|AHD_RESET_BUS_A|AHD_TERM_ENB_A
6027 ahd_timer_init(&ahd->reset_timer);
6028 ahd_timer_init(&ahd->stat_timer);
6029 ahd->int_coalescing_timer = AHD_INT_COALESCING_TIMER_DEFAULT;
6030 ahd->int_coalescing_maxcmds = AHD_INT_COALESCING_MAXCMDS_DEFAULT;
6031 ahd->int_coalescing_mincmds = AHD_INT_COALESCING_MINCMDS_DEFAULT;
6032 ahd->int_coalescing_threshold = AHD_INT_COALESCING_THRESHOLD_DEFAULT;
6033 ahd->int_coalescing_stop_threshold =
6036 if (ahd_platform_alloc(ahd, platform_arg) != 0) {
6037 ahd_free(ahd);
6038 ahd = NULL;
6043 ahd_name(ahd), (u_int)sizeof(struct scb),
6047 return (ahd);
6051 ahd_softc_init(struct ahd_softc *ahd)
6054 ahd->unpause = 0;
6055 ahd->pause = PAUSE;
6060 ahd_set_unit(struct ahd_softc *ahd, int unit)
6062 ahd->unit = unit;
6066 ahd_set_name(struct ahd_softc *ahd, char *name)
6068 if (ahd->name != NULL)
6069 kfree(ahd->name);
6070 ahd->name = name;
6074 ahd_free(struct ahd_softc *ahd)
6078 switch (ahd->init_level) {
6081 ahd_shutdown(ahd);
6084 ahd_dmamap_unload(ahd, ahd->shared_data_dmat,
6085 ahd->shared_data_map.dmamap);
6088 ahd_dmamem_free(ahd, ahd->shared_data_dmat, ahd->qoutfifo,
6089 ahd->shared_data_map.dmamap);
6090 ahd_dmamap_destroy(ahd, ahd->shared_data_dmat,
6091 ahd->shared_data_map.dmamap);
6094 ahd_dma_tag_destroy(ahd, ahd->shared_data_dmat);
6097 ahd_dma_tag_destroy(ahd, ahd->buffer_dmat);
6105 ahd_dma_tag_destroy(ahd, ahd->parent_dmat);
6107 ahd_platform_free(ahd);
6108 ahd_fini_scbdata(ahd);
6112 tstate = ahd->enabled_targets[i];
6131 if (ahd->black_hole != NULL) {
6132 xpt_free_path(ahd->black_hole->path);
6133 kfree(ahd->black_hole);
6136 if (ahd->name != NULL)
6137 kfree(ahd->name);
6138 if (ahd->seep_config != NULL)
6139 kfree(ahd->seep_config);
6140 if (ahd->saved_stack != NULL)
6141 kfree(ahd->saved_stack);
6143 kfree(ahd);
6151 struct ahd_softc *ahd;
6153 ahd = (struct ahd_softc *)arg;
6158 ahd_timer_stop(&ahd->reset_timer);
6159 ahd_timer_stop(&ahd->stat_timer);
6162 ahd_reset(ahd, /*reinit*/FALSE);
6175 ahd_reset(struct ahd_softc *ahd, int reinit)
6186 ahd_pause(ahd);
6187 ahd_update_modes(ahd);
6188 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
6189 sxfrctl1 = ahd_inb(ahd, SXFRCTL1);
6191 cmd = ahd_pci_read_config(ahd->dev_softc, PCIR_COMMAND, /*bytes*/2);
6192 if ((ahd->bugs & AHD_PCIX_CHIPRST_BUG) != 0) {
6205 ahd_pci_write_config(ahd->dev_softc, PCIR_COMMAND,
6208 ahd_outb(ahd, HCNTRL, CHIPRST | ahd->pause);
6219 } while (--wait && !(ahd_inb(ahd, HCNTRL) & CHIPRSTACK));
6223 "Trying to initialize anyway.\n", ahd_name(ahd));
6225 ahd_outb(ahd, HCNTRL, ahd->pause);
6227 if ((ahd->bugs & AHD_PCIX_CHIPRST_BUG) != 0) {
6232 ahd_pci_write_config(ahd->dev_softc, PCIR_STATUS + 1,
6234 ahd_pci_write_config(ahd->dev_softc, PCIR_COMMAND,
6244 ahd_known_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
6245 ahd_outb(ahd, MODE_PTR,
6246 ahd_build_mode_state(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI));
6256 ahd_outb(ahd, SXFRCTL1, sxfrctl1|STPWEN);
6257 ahd_outb(ahd, SXFRCTL1, sxfrctl1);
6260 ahd->features &= ~AHD_WIDE;
6261 if ((ahd_inb(ahd, SBLKCTL) & SELWIDE) != 0)
6262 ahd->features |= AHD_WIDE;
6269 ahd_chip_init(ahd);
6278 ahd_probe_scbs(struct ahd_softc *ahd) {
6281 AHD_ASSERT_MODES(ahd, ~(AHD_MODE_UNKNOWN_MSK|AHD_MODE_CFG_MSK),
6286 ahd_set_scbptr(ahd, i);
6287 ahd_outw(ahd, SCB_BASE, i);
6289 ahd_outb(ahd, SCB_BASE+j, 0);
6291 ahd_outb(ahd, SCB_CONTROL, MK_MESSAGE);
6292 if (ahd_inw_scbram(ahd, SCB_BASE) != i)
6294 ahd_set_scbptr(ahd, 0);
6295 if (ahd_inw_scbram(ahd, SCB_BASE) != 0)
6311 ahd_initialize_hscbs(struct ahd_softc *ahd)
6315 for (i = 0; i < ahd->scb_data.maxhscbs; i++) {
6316 ahd_set_scbptr(ahd, i);
6319 ahd_outb(ahd, SCB_CONTROL, 0);
6322 ahd_outw(ahd, SCB_NEXT, SCB_LIST_NULL);
6327 ahd_init_scbdata(struct ahd_softc *ahd)
6332 scb_data = &ahd->scb_data;
6342 scb_data->maxhscbs = ahd_probe_scbs(ahd);
6344 printk("%s: No SCB space found\n", ahd_name(ahd));
6348 ahd_initialize_hscbs(ahd);
6361 if (ahd_dma_tag_create(ahd, ahd->parent_dmat, /*alignment*/1,
6375 if (ahd_dma_tag_create(ahd, ahd->parent_dmat, /*alignment*/8,
6380 ahd_sglist_allocsize(ahd), /*nsegments*/1,
6387 printk("%s: ahd_sglist_allocsize = 0x%x\n", ahd_name(ahd),
6388 ahd_sglist_allocsize(ahd));
6394 if (ahd_dma_tag_create(ahd, ahd->parent_dmat, /*alignment*/1,
6408 ahd_alloc_scbs(ahd);
6413 ahd_name(ahd));
6428 ahd_find_scb_by_tag(struct ahd_softc *ahd, u_int tag)
6435 LIST_FOREACH(scb, &ahd->pending_scbs, pending_links) {
6443 TAILQ_FOREACH(scb, &ahd->scb_data.free_scbs, links.tqe) {
6457 LIST_FOREACH(scb, &ahd->scb_data.any_dev_free_scb_list, links.le) {
6466 ahd_fini_scbdata(struct ahd_softc *ahd)
6470 scb_data = &ahd->scb_data;
6482 ahd_dmamap_unload(ahd, scb_data->sense_dmat,
6484 ahd_dmamem_free(ahd, scb_data->sense_dmat,
6488 ahd_dma_tag_destroy(ahd, scb_data->sense_dmat);
6497 ahd_dmamap_unload(ahd, scb_data->sg_dmat,
6499 ahd_dmamem_free(ahd, scb_data->sg_dmat,
6503 ahd_dma_tag_destroy(ahd, scb_data->sg_dmat);
6512 ahd_dmamap_unload(ahd, scb_data->hscb_dmat,
6514 ahd_dmamem_free(ahd, scb_data->hscb_dmat,
6518 ahd_dma_tag_destroy(ahd, scb_data->hscb_dmat);
6535 ahd_setup_iocell_workaround(struct ahd_softc *ahd)
6539 saved_modes = ahd_save_modes(ahd);
6540 ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
6541 ahd_outb(ahd, DSPDATACTL, ahd_inb(ahd, DSPDATACTL)
6543 ahd_outb(ahd, SIMODE0, ahd_inb(ahd, SIMODE0) | (ENSELDO|ENSELDI));
6546 printk("%s: Setting up iocell workaround\n", ahd_name(ahd));
6548 ahd_restore_modes(ahd, saved_modes);
6549 ahd->flags &= ~AHD_HAD_FIRST_SEL;
6553 ahd_iocell_first_selection(struct ahd_softc *ahd)
6558 if ((ahd->flags & AHD_HAD_FIRST_SEL) != 0)
6560 saved_modes = ahd_save_modes(ahd);
6561 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
6562 sblkctl = ahd_inb(ahd, SBLKCTL);
6563 ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
6566 printk("%s: iocell first selection\n", ahd_name(ahd));
6569 ahd_outb(ahd, DSPDATACTL,
6570 ahd_inb(ahd, DSPDATACTL) & ~BYPASSENAB);
6573 printk("%s: BYPASS now disabled\n", ahd_name(ahd));
6576 ahd_outb(ahd, SIMODE0, ahd_inb(ahd, SIMODE0) & ~(ENSELDO|ENSELDI));
6577 ahd_outb(ahd, CLRINT, CLRSCSIINT);
6578 ahd_restore_modes(ahd, saved_modes);
6579 ahd->flags |= AHD_HAD_FIRST_SEL;
6584 ahd_add_col_list(struct ahd_softc *ahd, struct scb *scb, u_int col_idx)
6592 free_list = &ahd->scb_data.free_scb_lists[col_idx];
6593 free_tailq = &ahd->scb_data.free_scbs;
6604 ahd_rem_col_list(struct ahd_softc *ahd, struct scb *scb)
6612 col_idx = AHD_GET_SCB_COL_IDX(ahd, scb);
6613 free_list = &ahd->scb_data.free_scb_lists[col_idx];
6614 free_tailq = &ahd->scb_data.free_scbs;
6638 ahd_get_scb(struct ahd_softc *ahd, u_int col_idx)
6645 TAILQ_FOREACH(scb, &ahd->scb_data.free_scbs, links.tqe) {
6646 if (AHD_GET_SCB_COL_IDX(ahd, scb) != col_idx) {
6647 ahd_rem_col_list(ahd, scb);
6651 if ((scb = LIST_FIRST(&ahd->scb_data.any_dev_free_scb_list)) == NULL) {
6655 ahd_alloc_scbs(ahd);
6663 ahd_add_col_list(ahd, scb->col_scb, col_idx);
6674 ahd_free_scb(struct ahd_softc *ahd, struct scb *scb)
6679 ahd->scb_data.scbindex[SCB_GET_TAG(scb)] = NULL;
6686 LIST_INSERT_HEAD(&ahd->scb_data.any_dev_free_scb_list,
6695 ahd_rem_col_list(ahd, scb->col_scb);
6696 LIST_INSERT_HEAD(&ahd->scb_data.any_dev_free_scb_list,
6698 LIST_INSERT_HEAD(&ahd->scb_data.any_dev_free_scb_list,
6709 ahd_add_col_list(ahd, scb,
6710 AHD_GET_SCB_COL_IDX(ahd, scb->col_scb));
6718 LIST_INSERT_HEAD(&ahd->scb_data.any_dev_free_scb_list,
6722 ahd_platform_scb_free(ahd, scb);
6726 ahd_alloc_scbs(struct ahd_softc *ahd)
6742 scb_data = &ahd->scb_data;
6761 if (ahd_dmamem_alloc(ahd, scb_data->hscb_dmat,
6770 ahd_dmamap_load(ahd, scb_data->hscb_dmat, hscb_map->dmamap,
6782 offset = ((ahd_sglist_allocsize(ahd) / ahd_sglist_size(ahd))
6783 - scb_data->sgs_left) * ahd_sglist_size(ahd);
6794 if (ahd_dmamem_alloc(ahd, scb_data->sg_dmat,
6803 ahd_dmamap_load(ahd, scb_data->sg_dmat, sg_map->dmamap,
6804 sg_map->vaddr, ahd_sglist_allocsize(ahd),
6810 ahd_sglist_allocsize(ahd) / ahd_sglist_size(ahd);
6831 if (ahd_dmamem_alloc(ahd, scb_data->sense_dmat,
6840 ahd_dmamap_load(ahd, scb_data->sense_dmat, sense_map->dmamap,
6888 if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0)
6893 next_scb->ahd_softc = ahd;
6896 error = ahd_dmamap_create(ahd, ahd->buffer_dmat, /*flags*/0,
6906 next_scb->col_scb = ahd_find_scb_by_tag(ahd, col_tag);
6909 ahd_free_scb(ahd, next_scb);
6912 segs += ahd_sglist_size(ahd);
6913 sg_busaddr += ahd_sglist_size(ahd);
6924 ahd_controller_info(struct ahd_softc *ahd, char *buf)
6930 len = sprintf(buf, "%s: ", ahd_chip_names[ahd->chip & AHD_CHIPID_MASK]);
6934 if ((ahd->features & AHD_WIDE) != 0) {
6940 speed, type, ahd->channel, ahd->our_id);
6943 sprintf(buf, "%s, %d SCBs", ahd->bus_description,
6944 ahd->scb_data.maxhscbs);
6969 struct ahd_softc *ahd;
6971 ahd = (struct ahd_softc *)arg;
6983 ahd_init(struct ahd_softc *ahd)
6994 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
6996 ahd->stack_size = ahd_probe_stack_size(ahd);
6997 ahd->saved_stack = kmalloc(ahd->stack_size * sizeof(uint16_t), GFP_ATOMIC);
6998 if (ahd->saved_stack == NULL)
7010 ahd->flags |= AHD_SEQUENCER_DEBUG;
7016 ahd->flags |= AHD_INITIATORROLE;
7021 if ((AHD_TMODE_ENABLE & (0x1 << ahd->unit)) == 0)
7022 ahd->features &= ~AHD_TARGETMODE;
7026 if (ahd_dma_tag_create(ahd, ahd->parent_dmat, /*alignment*/1,
7028 /*lowaddr*/ahd->flags & AHD_39BIT_ADDRESSING
7037 &ahd->buffer_dmat) != 0) {
7042 ahd->init_level++;
7051 driver_data_size = AHD_SCB_MAX * sizeof(*ahd->qoutfifo)
7053 if ((ahd->features & AHD_TARGETMODE) != 0)
7055 if ((ahd->bugs & AHD_PKT_BITBUCKET_BUG) != 0)
7057 if (ahd_dma_tag_create(ahd, ahd->parent_dmat, /*alignment*/1,
7065 /*flags*/0, &ahd->shared_data_dmat) != 0) {
7069 ahd->init_level++;
7072 if (ahd_dmamem_alloc(ahd, ahd->shared_data_dmat,
7073 (void **)&ahd->shared_data_map.vaddr,
7075 &ahd->shared_data_map.dmamap) != 0) {
7079 ahd->init_level++;
7082 ahd_dmamap_load(ahd, ahd->shared_data_dmat, ahd->shared_data_map.dmamap,
7083 ahd->shared_data_map.vaddr, driver_data_size,
7084 ahd_dmamap_cb, &ahd->shared_data_map.physaddr,
7086 ahd->qoutfifo = (struct ahd_completion *)ahd->shared_data_map.vaddr;
7087 next_vaddr = (uint8_t *)&ahd->qoutfifo[AHD_QOUT_SIZE];
7088 next_baddr = ahd->shared_data_map.physaddr
7090 if ((ahd->features & AHD_TARGETMODE) != 0) {
7091 ahd->targetcmds = (struct target_cmd *)next_vaddr;
7096 if ((ahd->bugs & AHD_PKT_BITBUCKET_BUG) != 0) {
7097 ahd->overrun_buf = next_vaddr;
7109 ahd->next_queued_hscb = (struct hardware_scb *)next_vaddr;
7110 ahd->next_queued_hscb_map = &ahd->shared_data_map;
7111 ahd->next_queued_hscb->hscb_busaddr = ahd_htole32(next_baddr);
7113 ahd->init_level++;
7116 if (ahd_init_scbdata(ahd) != 0)
7119 if ((ahd->flags & AHD_INITIATORROLE) == 0)
7120 ahd->flags &= ~AHD_RESET_BUS_A;
7126 ahd_platform_init(ahd);
7129 ahd_chip_init(ahd);
7131 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
7133 if ((ahd->flags & AHD_CURRENT_SENSING) == 0)
7140 error = ahd_write_flexport(ahd, FLXADDR_ROMSTAT_CURSENSECTL,
7143 printk("%s: current sensing timeout 1\n", ahd_name(ahd));
7148 error = ahd_read_flexport(ahd, FLXADDR_FLEXSTAT, &fstat);
7151 ahd_name(ahd));
7157 ahd_name(ahd));
7162 error = ahd_read_flexport(ahd, FLXADDR_CURRENT_STAT, &current_sensing);
7164 printk("%s: current sensing timeout 3\n", ahd_name(ahd));
7169 ahd_write_flexport(ahd, FLXADDR_ROMSTAT_CURSENSECTL, 0);
7174 ahd_name(ahd), current_sensing);
7190 printk("%s: %s Channel %s\n", ahd_name(ahd),
7198 ahd_name(ahd), ahd_name(ahd));
7201 ahd_restart(ahd);
7202 ahd_timer_reset(&ahd->stat_timer, AHD_STAT_UPDATE_US,
7203 ahd_stat_timer, ahd);
7211 ahd_chip_init(struct ahd_softc *ahd)
7220 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
7224 ahd_outb(ahd, SBLKCTL, ahd_inb(ahd, SBLKCTL) & ~(DIAGLEDEN|DIAGLEDON));
7229 ahd->hs_mailbox = 0;
7230 ahd_outb(ahd, HS_MAILBOX, 0);
7233 ahd_outb(ahd, IOWNID, ahd->our_id);
7234 ahd_outb(ahd, TOWNID, ahd->our_id);
7235 sxfrctl1 = (ahd->flags & AHD_TERM_ENB_A) != 0 ? STPWEN : 0;
7236 sxfrctl1 |= (ahd->flags & AHD_SPCHK_ENB_A) != 0 ? ENSPCHK : 0;
7237 if ((ahd->bugs & AHD_LONG_SETIMO_BUG)
7238 && (ahd->seltime != STIMESEL_MIN)) {
7244 sxfrctl1 |= ahd->seltime + STIMESEL_BUG_ADJ;
7246 sxfrctl1 |= ahd->seltime;
7249 ahd_outb(ahd, SXFRCTL0, DFON);
7250 ahd_outb(ahd, SXFRCTL1, sxfrctl1|ahd->seltime|ENSTIMER|ACTNEGEN);
7251 ahd_outb(ahd, SIMODE1, ENSELTIMO|ENSCSIRST|ENSCSIPERR);
7261 (ahd_inb(ahd, SBLKCTL) & (ENAB40|ENAB20)) == 0 && wait;
7266 ahd_outb(ahd, CLRSINT1, CLRSCSIRSTI);
7267 ahd_outb(ahd, CLRINT, CLRSCSIINT);
7271 ahd_set_modes(ahd, AHD_MODE_DFF0 + i, AHD_MODE_DFF0 + i);
7272 ahd_outb(ahd, LONGJMP_ADDR + 1, INVALID_ADDR);
7273 ahd_outb(ahd, SG_STATE, 0);
7274 ahd_outb(ahd, CLRSEQINTSRC, 0xFF);
7275 ahd_outb(ahd, SEQIMODE,
7280 ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
7281 ahd_outb(ahd, DSCOMMAND0, ahd_inb(ahd, DSCOMMAND0)|MPARCKEN|CACHETHEN);
7282 ahd_outb(ahd, DFF_THRSH, RD_DFTHRSH_75|WR_DFTHRSH_75);
7283 ahd_outb(ahd, SIMODE0, ENIOERR|ENOVERRUN);
7284 ahd_outb(ahd, SIMODE3, ENNTRAMPERR|ENOSRAMPERR);
7285 if ((ahd->bugs & AHD_BUSFREEREV_BUG) != 0) {
7286 ahd_outb(ahd, OPTIONMODE, AUTOACKEN|AUTO_MSGOUT_DE);
7288 ahd_outb(ahd, OPTIONMODE, AUTOACKEN|BUSFREEREV|AUTO_MSGOUT_DE);
7290 ahd_outb(ahd, SCSCHKN, CURRFIFODEF|WIDERESEN|SHVALIDSTDIS);
7291 if ((ahd->chip & AHD_BUS_MASK) == AHD_PCIX)
7297 ahd_outb(ahd, PCIXCTL, ahd_inb(ahd, PCIXCTL) | SPLTSTADIS);
7299 if ((ahd->bugs & AHD_LQOOVERRUN_BUG) != 0)
7300 ahd_outb(ahd, LQOSCSCTL, LQONOCHKOVER);
7305 if ((ahd->flags & AHD_HP_BOARD) != 0) {
7307 ahd_outb(ahd, DSPSELECT, i);
7308 ahd_outb(ahd, WRTBIASCTL, WRTBIASCTL_HP_DEFAULT);
7312 printk("%s: WRTBIASCTL now 0x%x\n", ahd_name(ahd),
7316 ahd_setup_iocell_workaround(ahd);
7321 ahd_outb(ahd, LQIMODE1, ENLQIPHASE_LQ|ENLQIPHASE_NLQ|ENLIQABORT
7324 ahd_outb(ahd, LQOMODE0, ENLQOATNLQ|ENLQOATNPKT|ENLQOTCRC);
7333 ahd_outb(ahd, LQOMODE1, ENLQOBUSFREE);
7338 ahd_outw(ahd, INTVEC1_ADDR, ahd_resolve_seqaddr(ahd, LABEL_seq_isr));
7339 ahd_outw(ahd, INTVEC2_ADDR, ahd_resolve_seqaddr(ahd, LABEL_timer_isr));
7344 if ((ahd->bugs & AHD_PKT_LUN_BUG) != 0) {
7345 ahd_outb(ahd, LUNPTR, offsetof(struct hardware_scb,
7348 ahd_outb(ahd, LUNPTR, offsetof(struct hardware_scb, lun));
7350 ahd_outb(ahd, CMDLENPTR, offsetof(struct hardware_scb, cdb_len));
7351 ahd_outb(ahd, ATTRPTR, offsetof(struct hardware_scb, task_attribute));
7352 ahd_outb(ahd, FLAGPTR, offsetof(struct hardware_scb, task_management));
7353 ahd_outb(ahd, CMDPTR, offsetof(struct hardware_scb,
7355 ahd_outb(ahd, QNEXTPTR,
7357 ahd_outb(ahd, ABRTBITPTR, MK_MESSAGE_BIT_OFFSET);
7358 ahd_outb(ahd, ABRTBYTEPTR, offsetof(struct hardware_scb, control));
7359 if ((ahd->bugs & AHD_PKT_LUN_BUG) != 0) {
7360 ahd_outb(ahd, LUNLEN,
7361 sizeof(ahd->next_queued_hscb->pkt_long_lun) - 1);
7363 ahd_outb(ahd, LUNLEN, LUNLEN_SINGLE_LEVEL_LUN);
7365 ahd_outb(ahd, CDBLIMIT, SCB_CDB_LEN_PTR - 1);
7366 ahd_outb(ahd, MAXCMD, 0xFF);
7367 ahd_outb(ahd, SCBAUTOPTR,
7371 ahd_outb(ahd, MULTARGID, 0);
7372 ahd_outb(ahd, MULTARGID + 1, 0);
7374 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
7376 if ((ahd->features & AHD_NEW_IOCELL_OPTS) == 0) {
7382 ahd_outb(ahd, NEGOADDR, target);
7383 ahd_outb(ahd, ANNEXCOL, AHD_ANNEXCOL_PER_DEV0);
7385 ahd_outb(ahd, ANNEXDAT, 0);
7393 tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
7395 ahd_compile_devinfo(&devinfo, ahd->our_id,
7398 ahd_update_neg_table(ahd, &devinfo, &tinfo->curr);
7401 ahd_outb(ahd, CLRSINT3, NTRAMPERR|OSRAMPERR);
7402 ahd_outb(ahd, CLRINT, CLRSCSIINT);
7409 if ((ahd->bugs & AHD_ABORT_LQI_BUG) == 0)
7410 ahd_outb(ahd, LQCTL1, ABORTPENDING);
7413 ahd_outb(ahd, LQCTL1, 0);
7416 ahd->qoutfifonext = 0;
7417 ahd->qoutfifonext_valid_tag = QOUTFIFO_ENTRY_VALID;
7418 ahd_outb(ahd, QOUTFIFO_ENTRY_VALID_TAG, QOUTFIFO_ENTRY_VALID);
7420 ahd->qoutfifo[i].valid_tag = 0;
7421 ahd_sync_qoutfifo(ahd, BUS_DMASYNC_PREREAD);
7423 ahd->qinfifonext = 0;
7425 ahd->qinfifo[i] = SCB_LIST_NULL;
7427 if ((ahd->features & AHD_TARGETMODE) != 0) {
7430 ahd->targetcmds[i].cmd_valid = 0;
7431 ahd_sync_tqinfifo(ahd, BUS_DMASYNC_PREREAD);
7432 ahd->tqinfifonext = 1;
7433 ahd_outb(ahd, KERNEL_TQINPOS, ahd->tqinfifonext - 1);
7434 ahd_outb(ahd, TQINPOS, ahd->tqinfifonext);
7438 ahd_outb(ahd, SEQ_FLAGS, 0);
7439 ahd_outb(ahd, SEQ_FLAGS2, 0);
7442 ahd_outw(ahd, WAITING_TID_HEAD, SCB_LIST_NULL);
7443 ahd_outw(ahd, WAITING_TID_TAIL, SCB_LIST_NULL);
7444 ahd_outw(ahd, MK_MESSAGE_SCB, SCB_LIST_NULL);
7445 ahd_outw(ahd, MK_MESSAGE_SCSIID, 0xFF);
7447 ahd_outw(ahd, WAITING_SCB_TAILS + (2 * i), SCB_LIST_NULL);
7452 ahd_outw(ahd, COMPLETE_SCB_HEAD, SCB_LIST_NULL);
7453 ahd_outw(ahd, COMPLETE_SCB_DMAINPROG_HEAD, SCB_LIST_NULL);
7454 ahd_outw(ahd, COMPLETE_DMA_SCB_HEAD, SCB_LIST_NULL);
7455 ahd_outw(ahd, COMPLETE_DMA_SCB_TAIL, SCB_LIST_NULL);
7456 ahd_outw(ahd, COMPLETE_ON_QFREEZE_HEAD, SCB_LIST_NULL);
7461 ahd->qfreeze_cnt = 0;
7462 ahd_outw(ahd, QFREEZE_COUNT, 0);
7463 ahd_outw(ahd, KERNEL_QFREEZE_COUNT, 0);
7468 busaddr = ahd->shared_data_map.physaddr;
7469 ahd_outl(ahd, SHARED_DATA_ADDR, busaddr);
7470 ahd_outl(ahd, QOUTFIFO_NEXT_ADDR, busaddr);
7478 if ((ahd->flags & AHD_INITIATORROLE) != 0)
7480 ahd_outb(ahd, SCSISEQ_TEMPLATE, scsiseq_template);
7487 ahd_unbusy_tcl(ahd, BUILD_TCL_RAW(target, 'A', lun));
7496 ahd_outb(ahd, CMDSIZE_TABLE, 5);
7497 ahd_outb(ahd, CMDSIZE_TABLE + 1, 9);
7498 ahd_outb(ahd, CMDSIZE_TABLE + 2, 9);
7499 ahd_outb(ahd, CMDSIZE_TABLE + 3, 0);
7500 ahd_outb(ahd, CMDSIZE_TABLE + 4, 15);
7501 ahd_outb(ahd, CMDSIZE_TABLE + 5, 11);
7502 ahd_outb(ahd, CMDSIZE_TABLE + 6, 0);
7503 ahd_outb(ahd, CMDSIZE_TABLE + 7, 0);
7506 ahd_set_modes(ahd, AHD_MODE_CCHAN, AHD_MODE_CCHAN);
7507 ahd_outb(ahd, QOFF_CTLSTA, SCB_QSIZE_512);
7508 ahd->qinfifonext = 0;
7509 ahd_set_hnscb_qoff(ahd, ahd->qinfifonext);
7510 ahd_set_hescb_qoff(ahd, 0);
7511 ahd_set_snscb_qoff(ahd, 0);
7512 ahd_set_sescb_qoff(ahd, 0);
7513 ahd_set_sdscb_qoff(ahd, 0);
7518 busaddr = ahd_le32toh(ahd->next_queued_hscb->hscb_busaddr);
7519 ahd_outl(ahd, NEXT_QUEUED_SCB_ADDR, busaddr);
7524 ahd_outw(ahd, INT_COALESCING_CMDCOUNT, 0);
7525 ahd_outw(ahd, CMDS_PENDING, 0);
7526 ahd_update_coalescing_values(ahd, ahd->int_coalescing_timer,
7527 ahd->int_coalescing_maxcmds,
7528 ahd->int_coalescing_mincmds);
7529 ahd_enable_coalescing(ahd, FALSE);
7531 ahd_loadseq(ahd);
7532 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
7534 if (ahd->features & AHD_AIC79XXB_SLOWCRC) {
7535 u_int negodat3 = ahd_inb(ahd, NEGCONOPTS);
7538 ahd_outb(ahd, NEGCONOPTS, negodat3);
7539 negodat3 = ahd_inb(ahd, NEGCONOPTS);
7553 ahd_default_config(struct ahd_softc *ahd)
7557 ahd->our_id = 7;
7564 if (ahd_alloc_tstate(ahd, ahd->our_id, 'A') == NULL) {
7566 "Failing attach\n", ahd_name(ahd));
7576 tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
7585 ahd->user_discenable |= target_mask;
7587 ahd->user_tagenable |= target_mask;
7600 if ((ahd->features & AHD_RTI) != 0)
7613 ahd_compile_devinfo(&devinfo, ahd->our_id,
7617 ahd_set_width(ahd, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
7619 ahd_set_syncrate(ahd, &devinfo, /*period*/0, /*offset*/0,
7630 ahd_parse_cfgdata(struct ahd_softc *ahd, struct seeprom_config *sc)
7636 ahd->our_id = sc->brtime_id & CFSCSIID;
7643 if (ahd_alloc_tstate(ahd, ahd->our_id, 'A') == NULL) {
7645 "Failing attach\n", ahd_name(ahd));
7656 tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
7667 ahd->user_discenable &= ~target_mask;
7669 ahd->user_tagenable &= ~target_mask;
7672 ahd->user_discenable |= target_mask;
7673 ahd->user_tagenable |= target_mask;
7701 if ((ahd->features & AHD_RTI) != 0)
7727 ahd_compile_devinfo(&devinfo, ahd->our_id,
7730 ahd_set_width(ahd, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
7732 ahd_set_syncrate(ahd, &devinfo, /*period*/0, /*offset*/0,
7737 ahd->flags &= ~AHD_SPCHK_ENB_A;
7739 ahd->flags |= AHD_SPCHK_ENB_A;
7741 ahd->flags &= ~AHD_RESET_BUS_A;
7743 ahd->flags |= AHD_RESET_BUS_A;
7745 ahd->flags &= ~AHD_EXTENDED_TRANS_A;
7747 ahd->flags |= AHD_EXTENDED_TRANS_A;
7749 ahd->flags &= ~AHD_BIOS_ENABLED;
7751 ahd->flags |= AHD_BIOS_ENABLED;
7753 ahd->flags &= ~AHD_STPWLEVEL_A;
7755 ahd->flags |= AHD_STPWLEVEL_A;
7764 ahd_parse_vpddata(struct ahd_softc *ahd, struct vpd_config *vpd)
7772 ahd->flags |= AHD_BOOT_CHANNEL;
7777 ahd_intr_enable(struct ahd_softc *ahd, int enable)
7781 hcntrl = ahd_inb(ahd, HCNTRL);
7783 ahd->pause &= ~INTEN;
7784 ahd->unpause &= ~INTEN;
7787 ahd->pause |= INTEN;
7788 ahd->unpause |= INTEN;
7790 ahd_outb(ahd, HCNTRL, hcntrl);
7794 ahd_update_coalescing_values(struct ahd_softc *ahd, u_int timer, u_int maxcmds,
7799 ahd->int_coalescing_timer = timer;
7805 ahd->int_coalescing_maxcmds = maxcmds;
7806 ahd_outw(ahd, INT_COALESCING_TIMER, timer / AHD_TIMER_US_PER_TICK);
7807 ahd_outb(ahd, INT_COALESCING_MAXCMDS, -maxcmds);
7808 ahd_outb(ahd, INT_COALESCING_MINCMDS, -mincmds);
7812 ahd_enable_coalescing(struct ahd_softc *ahd, int enable)
7815 ahd->hs_mailbox &= ~ENINT_COALESCE;
7817 ahd->hs_mailbox |= ENINT_COALESCE;
7818 ahd_outb(ahd, HS_MAILBOX, ahd->hs_mailbox);
7819 ahd_flush_device_writes(ahd);
7820 ahd_run_qoutfifo(ahd);
7831 ahd_pause_and_flushwork(struct ahd_softc *ahd)
7837 ahd->flags |= AHD_ALL_INTERRUPTS;
7838 ahd_pause(ahd);
7844 ahd->qfreeze_cnt--;
7845 ahd_outw(ahd, KERNEL_QFREEZE_COUNT, ahd->qfreeze_cnt);
7846 ahd_outb(ahd, SEQ_FLAGS2, ahd_inb(ahd, SEQ_FLAGS2) | SELECTOUT_QFROZEN);
7849 ahd_unpause(ahd);
7856 ahd_intr(ahd);
7857 ahd_pause(ahd);
7858 intstat = ahd_inb(ahd, INTSTAT);
7860 ahd_clear_critical_section(ahd);
7861 intstat = ahd_inb(ahd, INTSTAT);
7864 && (intstat != 0xFF || (ahd->features & AHD_REMOVABLE) == 0)
7866 || (ahd_inb(ahd, SCSISEQ0) & ENSELO) != 0
7867 || (ahd_inb(ahd, SSTAT0) & (SELDO|SELINGO)) != 0));
7871 ahd_inb(ahd, INTSTAT));
7873 ahd->qfreeze_cnt++;
7874 ahd_outw(ahd, KERNEL_QFREEZE_COUNT, ahd->qfreeze_cnt);
7876 ahd_flush_qoutfifo(ahd);
7878 ahd->flags &= ~AHD_ALL_INTERRUPTS;
7883 ahd_suspend(struct ahd_softc *ahd)
7886 ahd_pause_and_flushwork(ahd);
7888 if (LIST_FIRST(&ahd->pending_scbs) != NULL) {
7889 ahd_unpause(ahd);
7892 ahd_shutdown(ahd);
7897 ahd_resume(struct ahd_softc *ahd)
7900 ahd_reset(ahd, /*reinit*/TRUE);
7901 ahd_intr_enable(ahd, TRUE);
7902 ahd_restart(ahd);
7916 ahd_index_busy_tcl(struct ahd_softc *ahd, u_int *saved_scbid, u_int tcl)
7921 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
7922 *saved_scbid = ahd_get_scbptr(ahd);
7923 ahd_set_scbptr(ahd, TCL_LUN(tcl)
7938 ahd_find_busy_tcl(struct ahd_softc *ahd, u_int tcl)
7944 scb_offset = ahd_index_busy_tcl(ahd, &saved_scbptr, tcl);
7945 scbid = ahd_inw_scbram(ahd, scb_offset);
7946 ahd_set_scbptr(ahd, saved_scbptr);
7951 ahd_busy_tcl(struct ahd_softc *ahd, u_int tcl, u_int scbid)
7956 scb_offset = ahd_index_busy_tcl(ahd, &saved_scbptr, tcl);
7957 ahd_outw(ahd, scb_offset, scbid);
7958 ahd_set_scbptr(ahd, saved_scbptr);
7963 ahd_match_scb(struct ahd_softc *ahd, struct scb *scb, int target,
7966 int targ = SCB_GET_TARGET(ahd, scb);
7967 char chan = SCB_GET_CHANNEL(ahd, scb);
7999 ahd_freeze_devq(struct ahd_softc *ahd, struct scb *scb)
8005 target = SCB_GET_TARGET(ahd, scb);
8007 channel = SCB_GET_CHANNEL(ahd, scb);
8009 ahd_search_qinfifo(ahd, target, channel, lun,
8013 ahd_platform_freeze_devq(ahd, scb);
8017 ahd_qinfifo_requeue_tail(struct ahd_softc *ahd, struct scb *scb)
8022 saved_modes = ahd_save_modes(ahd);
8023 ahd_set_modes(ahd, AHD_MODE_CCHAN, AHD_MODE_CCHAN);
8025 if (ahd_qinfifo_count(ahd) != 0) {
8029 prev_pos = AHD_QIN_WRAP(ahd->qinfifonext - 1);
8030 prev_tag = ahd->qinfifo[prev_pos];
8031 prev_scb = ahd_lookup_scb(ahd, prev_tag);
8033 ahd_qinfifo_requeue(ahd, prev_scb, scb);
8034 ahd_set_hnscb_qoff(ahd, ahd->qinfifonext);
8035 ahd_restore_modes(ahd, saved_modes);
8039 ahd_qinfifo_requeue(struct ahd_softc *ahd, struct scb *prev_scb,
8046 ahd_outl(ahd, NEXT_QUEUED_SCB_ADDR, busaddr);
8049 ahd_sync_scb(ahd, prev_scb,
8052 ahd->qinfifo[AHD_QIN_WRAP(ahd->qinfifonext)] = SCB_GET_TAG(scb);
8053 ahd->qinfifonext++;
8054 scb->hscb->next_hscb_busaddr = ahd->next_queued_hscb->hscb_busaddr;
8055 ahd_sync_scb(ahd, scb, BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
8059 ahd_qinfifo_count(struct ahd_softc *ahd)
8065 AHD_ASSERT_MODES(ahd, AHD_MODE_CCHAN_MSK, AHD_MODE_CCHAN_MSK);
8066 qinpos = ahd_get_snscb_qoff(ahd);
8068 wrap_qinfifonext = AHD_QIN_WRAP(ahd->qinfifonext);
8073 + ARRAY_SIZE(ahd->qinfifo) - wrap_qinpos);
8077 ahd_reset_cmds_pending(struct ahd_softc *ahd)
8083 saved_modes = ahd_save_modes(ahd);
8084 ahd_set_modes(ahd, AHD_MODE_CCHAN, AHD_MODE_CCHAN);
8090 ahd_flush_qoutfifo(ahd);
8093 LIST_FOREACH(scb, &ahd->pending_scbs, pending_links) {
8096 ahd_outw(ahd, CMDS_PENDING, pending_cmds - ahd_qinfifo_count(ahd));
8097 ahd_restore_modes(ahd, saved_modes);
8098 ahd->flags &= ~AHD_UPDATE_PEND_CMDS;
8102 ahd_done_with_status(struct ahd_softc *ahd, struct scb *scb, uint32_t status)
8113 ahd_done(ahd, scb);
8117 ahd_search_qinfifo(struct ahd_softc *ahd, int target, char channel,
8138 saved_modes = ahd_save_modes(ahd);
8139 ahd_set_modes(ahd, AHD_MODE_CCHAN, AHD_MODE_CCHAN);
8145 if ((ahd_inb(ahd, CCSCBCTL) & (CCARREN|CCSCBEN|CCSCBDIR))
8147 ahd_outb(ahd, CCSCBCTL,
8148 ahd_inb(ahd, CCSCBCTL) & ~(CCARREN|CCSCBEN));
8149 while ((ahd_inb(ahd, CCSCBCTL) & (CCARREN|CCSCBEN)) != 0)
8153 qintail = AHD_QIN_WRAP(ahd->qinfifonext);
8154 qinstart = ahd_get_snscb_qoff(ahd);
8161 qinstart, ahd->qinfifonext);
8168 ahd->qinfifonext = qinstart;
8169 busaddr = ahd_le32toh(ahd->next_queued_hscb->hscb_busaddr);
8170 ahd_outl(ahd, NEXT_QUEUED_SCB_ADDR, busaddr);
8173 scb = ahd_lookup_scb(ahd, ahd->qinfifo[qinpos]);
8176 qinpos, ahd->qinfifo[qinpos]);
8180 if (ahd_match_scb(ahd, scb, target, channel, lun, tag, role)) {
8189 ahd_done_with_status(ahd, scb, status);
8194 printk(" 0x%x", ahd->qinfifo[qinpos]);
8197 ahd_qinfifo_requeue(ahd, prev_scb, scb);
8202 ahd_qinfifo_requeue(ahd, prev_scb, scb);
8208 ahd_set_hnscb_qoff(ahd, ahd->qinfifonext);
8219 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
8220 seq_flags2 = ahd_inb(ahd, SEQ_FLAGS2);
8222 scbid = ahd_inw(ahd, MK_MESSAGE_SCB);
8223 mk_msg_scb = ahd_lookup_scb(ahd, scbid);
8226 savedscbptr = ahd_get_scbptr(ahd);
8227 tid_next = ahd_inw(ahd, WAITING_TID_HEAD);
8238 if (scbid >= ahd->scb_data.numscbs) {
8241 ahd_name(ahd), scbid, ahd->scb_data.numscbs);
8242 ahd_dump_card_state(ahd);
8245 scb = ahd_lookup_scb(ahd, scbid);
8248 ahd_name(ahd), scbid);
8251 ahd_set_scbptr(ahd, scbid);
8252 tid_next = ahd_inw_scbram(ahd, SCB_NEXT2);
8253 if (ahd_match_scb(ahd, scb, target, channel, CAM_LUN_WILDCARD,
8263 printk(" %d ( ", SCB_GET_TARGET(ahd, scb));
8265 found += ahd_search_scb_list(ahd, target, channel,
8268 SCB_GET_TARGET(ahd, scb));
8274 && ahd_match_scb(ahd, mk_msg_scb, target, channel,
8285 ahd_done_with_status(ahd, mk_msg_scb, status);
8298 + (2 * SCB_GET_TARGET(ahd, mk_msg_scb));
8299 ahd_outw(ahd, tail_offset, tid_tail);
8302 ahd_outb(ahd, SEQ_FLAGS2, seq_flags2);
8303 ahd_outw(ahd, CMDS_PENDING,
8304 ahd_inw(ahd, CMDS_PENDING)-1);
8318 && ahd_match_scb(ahd, scb, target, channel, CAM_LUN_WILDCARD,
8327 tid_head = ahd_inw(ahd, MK_MESSAGE_SCB);
8329 ahd_outb(ahd, SEQ_FLAGS2, seq_flags2);
8333 ahd_stitch_tid_list(ahd, tid_prev, tid_head, tid_next);
8341 ahd_set_scbptr(ahd, savedscbptr);
8342 ahd_restore_modes(ahd, saved_modes);
8347 ahd_search_scb_list(struct ahd_softc *ahd, int target, char channel,
8358 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
8364 if (scbid >= ahd->scb_data.numscbs) {
8367 ahd_name(ahd), scbid, ahd->scb_data.numscbs);
8368 ahd_dump_card_state(ahd);
8371 scb = ahd_lookup_scb(ahd, scbid);
8374 ahd_name(ahd), scbid);
8377 ahd_set_scbptr(ahd, scbid);
8379 next = ahd_inw_scbram(ahd, SCB_NEXT);
8380 if (ahd_match_scb(ahd, scb, target, channel,
8390 ahd_done_with_status(ahd, scb, status);
8393 ahd_rem_wscb(ahd, scbid, prev, next, tid);
8409 ahd_outw(ahd, CMDS_PENDING, ahd_inw(ahd, CMDS_PENDING) - found);
8414 ahd_stitch_tid_list(struct ahd_softc *ahd, u_int tid_prev,
8417 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
8423 ahd_outw(ahd, WAITING_TID_HEAD, tid_next);
8425 ahd_set_scbptr(ahd, tid_prev);
8426 ahd_outw(ahd, SCB_NEXT2, tid_next);
8429 ahd_outw(ahd, WAITING_TID_TAIL, tid_prev);
8434 ahd_outw(ahd, WAITING_TID_HEAD, tid_cur);
8436 ahd_set_scbptr(ahd, tid_prev);
8437 ahd_outw(ahd, SCB_NEXT2, tid_cur);
8439 ahd_set_scbptr(ahd, tid_cur);
8440 ahd_outw(ahd, SCB_NEXT2, tid_next);
8443 ahd_outw(ahd, WAITING_TID_TAIL, tid_cur);
8452 ahd_rem_wscb(struct ahd_softc *ahd, u_int scbid,
8457 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
8459 ahd_set_scbptr(ahd, prev);
8460 ahd_outw(ahd, SCB_NEXT, next);
8472 && ahd_inw(ahd, tail_offset) == scbid)
8473 ahd_outw(ahd, tail_offset, prev);
8475 ahd_add_scb_to_free_list(ahd, scbid);
8485 ahd_add_scb_to_free_list(struct ahd_softc *ahd, u_int scbid)
8490 ahd_outb(ahd, SCB_TAG, SCB_LIST_NULL);
8502 ahd_abort_scbs(struct ahd_softc *ahd, int target, char channel,
8515 saved_modes = ahd_save_modes(ahd);
8516 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
8518 found = ahd_search_qinfifo(ahd, target, channel, lun, SCB_LIST_NULL,
8550 scbid = ahd_find_busy_tcl(ahd, tcl);
8551 scbp = ahd_lookup_scb(ahd, scbid);
8553 || ahd_match_scb(ahd, scbp, target, channel,
8556 ahd_unbusy_tcl(ahd, BUILD_TCL_RAW(i, 'A', j));
8565 ahd_flush_qoutfifo(ahd);
8573 scbp_next = LIST_FIRST(&ahd->pending_scbs);
8577 if (ahd_match_scb(ahd, scbp, target, channel, lun, tag, role)) {
8587 ahd_done(ahd, scbp);
8591 ahd_restore_modes(ahd, saved_modes);
8592 ahd_platform_abort_scbs(ahd, target, channel, lun, tag, role, status);
8593 ahd->flags |= AHD_UPDATE_PEND_CMDS;
8598 ahd_reset_current_bus(struct ahd_softc *ahd)
8602 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
8603 ahd_outb(ahd, SIMODE1, ahd_inb(ahd, SIMODE1) & ~ENSCSIRST);
8604 scsiseq = ahd_inb(ahd, SCSISEQ0) & ~(ENSELO|ENARBO|SCSIRSTO);
8605 ahd_outb(ahd, SCSISEQ0, scsiseq | SCSIRSTO);
8606 ahd_flush_device_writes(ahd);
8609 ahd_outb(ahd, SCSISEQ0, scsiseq);
8610 ahd_flush_device_writes(ahd);
8612 if ((ahd->bugs & AHD_SCSIRST_BUG) != 0) {
8619 ahd_reset(ahd, /*reinit*/TRUE);
8620 ahd_intr_enable(ahd, /*enable*/TRUE);
8621 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
8624 ahd_clear_intstat(ahd);
8628 ahd_reset_channel(struct ahd_softc *ahd, char channel, int initiate_reset)
8642 if (ahd->flags & AHD_BUS_RESET_ACTIVE) {
8644 ahd_name(ahd));
8647 ahd->flags |= AHD_BUS_RESET_ACTIVE;
8649 ahd->pending_device = NULL;
8656 ahd_pause(ahd);
8659 ahd_clear_critical_section(ahd);
8666 ahd_run_qoutfifo(ahd);
8668 if ((ahd->flags & AHD_TARGETROLE) != 0) {
8669 ahd_run_tqinfifo(ahd, /*paused*/TRUE);
8672 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
8678 ahd_outb(ahd, SCSISEQ0, 0);
8679 ahd_outb(ahd, SCSISEQ1, 0);
8686 next_fifo = fifo = ahd_inb(ahd, DFFSTAT) & CURRFIFO;
8692 ahd_set_modes(ahd, next_fifo, next_fifo);
8693 ahd_outb(ahd, DFCNTRL,
8694 ahd_inb(ahd, DFCNTRL) & ~(SCSIEN|HDMAEN));
8695 while ((ahd_inb(ahd, DFCNTRL) & HDMAENACK) != 0)
8700 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
8701 ahd_outb(ahd, DFFSTAT, next_fifo);
8707 ahd_clear_msg_state(ahd);
8708 ahd_outb(ahd, SIMODE1,
8709 ahd_inb(ahd, SIMODE1) & ~(ENBUSFREE|ENSCSIRST));
8712 ahd_reset_current_bus(ahd);
8714 ahd_clear_intstat(ahd);
8720 found = ahd_abort_scbs(ahd, CAM_TARGET_WILDCARD, channel,
8727 ahd_clear_fifo(ahd, 0);
8728 ahd_clear_fifo(ahd, 1);
8733 ahd_outb(ahd, CLRSINT1, CLRSCSIRSTI);
8738 ahd_outb(ahd, SIMODE1, ahd_inb(ahd, SIMODE1) | ENSCSIRST);
8739 scsiseq = ahd_inb(ahd, SCSISEQ_TEMPLATE);
8740 ahd_outb(ahd, SCSISEQ1, scsiseq & (ENSELI|ENRSELI|ENAUTOATNP));
8742 max_scsiid = (ahd->features & AHD_WIDE) ? 15 : 7;
8752 tstate = ahd->enabled_targets[target];
8762 ahd_queue_lstate_event(ahd, lstate, CAM_TARGET_WILDCARD,
8764 ahd_send_lstate_events(ahd, lstate);
8773 if (ahd->enabled_targets[target] == NULL)
8781 ahd_set_width(ahd, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
8783 ahd_set_syncrate(ahd, &devinfo, /*period*/0,
8790 ahd_send_async(ahd, caminfo.channel, CAM_TARGET_WILDCARD,
8793 ahd_restart(ahd);
8802 struct ahd_softc *ahd = arg;
8806 ahd_lock(ahd, &s);
8808 enint_coal = ahd->hs_mailbox & ENINT_COALESCE;
8809 if (ahd->cmdcmplt_total > ahd->int_coalescing_threshold)
8811 else if (ahd->cmdcmplt_total < ahd->int_coalescing_stop_threshold)
8814 if (enint_coal != (ahd->hs_mailbox & ENINT_COALESCE)) {
8815 ahd_enable_coalescing(ahd, enint_coal);
8820 ahd_name(ahd),
8822 ahd->cmdcmplt_total);
8826 ahd->cmdcmplt_bucket = (ahd->cmdcmplt_bucket+1) & (AHD_STAT_BUCKETS-1);
8827 ahd->cmdcmplt_total -= ahd->cmdcmplt_counts[ahd->cmdcmplt_bucket];
8828 ahd->cmdcmplt_counts[ahd->cmdcmplt_bucket] = 0;
8829 ahd_timer_reset(&ahd->stat_timer, AHD_STAT_UPDATE_US,
8830 ahd_stat_timer, ahd);
8831 ahd_unlock(ahd, &s);
8837 ahd_handle_scsi_status(struct ahd_softc *ahd, struct scb *scb)
8853 if (ahd_is_paused(ahd)) {
8857 ahd_pause(ahd);
8861 ahd_freeze_devq(ahd, scb);
8863 ahd->qfreeze_cnt++;
8864 ahd_outw(ahd, KERNEL_QFREEZE_COUNT, ahd->qfreeze_cnt);
8867 ahd_unpause(ahd);
8877 ahd_done(ahd, scb);
8887 ahd_sync_sense(ahd, scb, BUS_DMASYNC_POSTREAD);
8892 ahd_print_path(ahd, scb);
8902 ahd_print_path(ahd, scb);
8940 ahd_done(ahd, scb);
8954 ahd_print_path(ahd, scb);
8964 SCB_GET_TARGET(ahd, scb),
8966 SCB_GET_CHANNEL(ahd, scb),
8968 targ_info = ahd_fetch_transinfo(ahd,
8979 ahd_update_residual(ahd, scb);
8982 ahd_print_path(ahd, scb);
8987 sg = ahd_sg_setup(ahd, scb, sg, ahd_get_sense_bufaddr(ahd, scb),
8988 ahd_get_sense_bufsize(ahd, scb),
8997 sc->length = ahd_get_sense_bufsize(ahd, scb);
9018 ahd_update_neg_request(ahd, &devinfo,
9029 ahd_setup_data_scb(ahd, scb);
9031 ahd_queue_scb(ahd, scb);
9036 ahd_name(ahd));
9039 ahd_done(ahd, scb);
9045 ahd_handle_scb_status(struct ahd_softc *ahd, struct scb *scb)
9048 ahd_handle_scsi_status(ahd, scb);
9050 ahd_calc_residual(ahd, scb);
9051 ahd_done(ahd, scb);
9059 ahd_calc_residual(struct ahd_softc *ahd, struct scb *scb)
9109 ahd_print_path(ahd, scb);
9112 ahd_freeze_devq(ahd, scb);
9127 sg = ahd_sg_bus_to_virt(ahd, scb, resid_sgptr & SG_PTR_MASK);
9149 ahd_print_path(ahd, scb);
9162 ahd_queue_lstate_event(struct ahd_softc *ahd, struct ahd_tmode_lstate *lstate,
9213 ahd_send_lstate_events(struct ahd_softc *ahd, struct ahd_tmode_lstate *lstate)
9249 ahd_dumpseq(struct ahd_softc* ahd)
9256 ahd_outb(ahd, SEQCTL0, PERRORDIS|FAILDIS|FASTMODE|LOADRAM);
9257 ahd_outw(ahd, PRGMCNT, 0);
9261 ahd_insb(ahd, SEQRAM, ins_bytes, 4);
9271 ahd_loadseq(struct ahd_softc *ahd)
9291 ahd_name(ahd));
9323 sg_prefetch_align = ahd->pci_cachesize;
9346 if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0)
9370 (ahd->overrun_buf - (uint8_t *)ahd->qoutfifo) / 256;
9376 ahd_outb(ahd, SEQCTL0, PERRORDIS|FAILDIS|FASTMODE|LOADRAM);
9377 ahd_outw(ahd, PRGMCNT, 0);
9380 if (ahd_check_patch(ahd, &cur_patch, i, &skip_addr) == 0) {
9408 ahd_download_instr(ahd, i, download_consts);
9412 ahd->num_critical_sections = cs_count;
9416 ahd->critical_sections = kmalloc(cs_count, GFP_ATOMIC);
9417 if (ahd->critical_sections == NULL)
9419 memcpy(ahd->critical_sections, cs_table, cs_count);
9421 ahd_outb(ahd, SEQCTL0, PERRORDIS|FAILDIS|FASTMODE);
9426 ahd_name(ahd), ahd->features, ahd->bugs, ahd->flags);
9431 ahd_check_patch(struct ahd_softc *ahd, const struct patch **start_patch,
9444 if (cur_patch->patch_func(ahd) == 0) {
9467 ahd_resolve_seqaddr(struct ahd_softc *ahd, u_int address)
9480 ahd_check_patch(ahd, &cur_patch, i, &skip_addr);
9496 ahd_download_instr(struct ahd_softc *ahd, u_int instrptr, uint8_t *dconsts)
9524 fmt3_ins->address = ahd_resolve_seqaddr(ahd, fmt3_ins->address);
9555 ahd_outsb(ahd, SEQRAM, instr.bytes, 4);
9565 ahd_probe_stack_size(struct ahd_softc *ahd)
9580 ahd_outb(ahd, STACK, i & 0xFF);
9581 ahd_outb(ahd, STACK, (i >> 8) & 0xFF);
9588 stack_entry = ahd_inb(ahd, STACK)
9589 |(ahd_inb(ahd, STACK) << 8);
9648 ahd_dump_card_state(struct ahd_softc *ahd)
9659 if (ahd_is_paused(ahd)) {
9663 ahd_pause(ahd);
9665 saved_modes = ahd_save_modes(ahd);
9666 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
9669 ahd_name(ahd),
9670 ahd_inw(ahd, CURADDR),
9671 ahd_build_mode_state(ahd, ahd->saved_src_mode,
9672 ahd->saved_dst_mode));
9676 if (ahd_check_cmdcmpltqueues(ahd))
9683 ahd_intstat_print(ahd_inb(ahd, INTSTAT), &cur_col, 50);
9684 ahd_seloid_print(ahd_inb(ahd, SELOID), &cur_col, 50);
9685 ahd_selid_print(ahd_inb(ahd, SELID), &cur_col, 50);
9686 ahd_hs_mailbox_print(ahd_inb(ahd, LOCAL_HS_MAILBOX), &cur_col, 50);
9687 ahd_intctl_print(ahd_inb(ahd, INTCTL), &cur_col, 50);
9688 ahd_seqintstat_print(ahd_inb(ahd, SEQINTSTAT), &cur_col, 50);
9689 ahd_saved_mode_print(ahd_inb(ahd, SAVED_MODE), &cur_col, 50);
9690 ahd_dffstat_print(ahd_inb(ahd, DFFSTAT), &cur_col, 50);
9691 ahd_scsisigi_print(ahd_inb(ahd, SCSISIGI), &cur_col, 50);
9692 ahd_scsiphase_print(ahd_inb(ahd, SCSIPHASE), &cur_col, 50);
9693 ahd_scsibus_print(ahd_inb(ahd, SCSIBUS), &cur_col, 50);
9694 ahd_lastphase_print(ahd_inb(ahd, LASTPHASE), &cur_col, 50);
9695 ahd_scsiseq0_print(ahd_inb(ahd, SCSISEQ0), &cur_col, 50);
9696 ahd_scsiseq1_print(ahd_inb(ahd, SCSISEQ1), &cur_col, 50);
9697 ahd_seqctl0_print(ahd_inb(ahd, SEQCTL0), &cur_col, 50);
9698 ahd_seqintctl_print(ahd_inb(ahd, SEQINTCTL), &cur_col, 50);
9699 ahd_seq_flags_print(ahd_inb(ahd, SEQ_FLAGS), &cur_col, 50);
9700 ahd_seq_flags2_print(ahd_inb(ahd, SEQ_FLAGS2), &cur_col, 50);
9701 ahd_qfreeze_count_print(ahd_inw(ahd, QFREEZE_COUNT), &cur_col, 50);
9702 ahd_kernel_qfreeze_count_print(ahd_inw(ahd, KERNEL_QFREEZE_COUNT),
9704 ahd_mk_message_scb_print(ahd_inw(ahd, MK_MESSAGE_SCB), &cur_col, 50);
9705 ahd_mk_message_scsiid_print(ahd_inb(ahd, MK_MESSAGE_SCSIID),
9707 ahd_sstat0_print(ahd_inb(ahd, SSTAT0), &cur_col, 50);
9708 ahd_sstat1_print(ahd_inb(ahd, SSTAT1), &cur_col, 50);
9709 ahd_sstat2_print(ahd_inb(ahd, SSTAT2), &cur_col, 50);
9710 ahd_sstat3_print(ahd_inb(ahd, SSTAT3), &cur_col, 50);
9711 ahd_perrdiag_print(ahd_inb(ahd, PERRDIAG), &cur_col, 50);
9712 ahd_simode1_print(ahd_inb(ahd, SIMODE1), &cur_col, 50);
9713 ahd_lqistat0_print(ahd_inb(ahd, LQISTAT0), &cur_col, 50);
9714 ahd_lqistat1_print(ahd_inb(ahd, LQISTAT1), &cur_col, 50);
9715 ahd_lqistat2_print(ahd_inb(ahd, LQISTAT2), &cur_col, 50);
9716 ahd_lqostat0_print(ahd_inb(ahd, LQOSTAT0), &cur_col, 50);
9717 ahd_lqostat1_print(ahd_inb(ahd, LQOSTAT1), &cur_col, 50);
9718 ahd_lqostat2_print(ahd_inb(ahd, LQOSTAT2), &cur_col, 50);
9722 ahd->scb_data.numscbs, ahd_inw(ahd, CMDS_PENDING),
9723 ahd_inw(ahd, LASTSCB), ahd_inw(ahd, CURRSCB),
9724 ahd_inw(ahd, NEXTSCB));
9727 ahd_search_qinfifo(ahd, CAM_TARGET_WILDCARD, ALL_CHANNELS,
9730 saved_scb_index = ahd_get_scbptr(ahd);
9733 LIST_FOREACH(scb, &ahd->pending_scbs, pending_links) {
9737 ahd_inb_scbram(ahd, SCB_FIFO_USE_COUNT));
9738 ahd_set_scbptr(ahd, SCB_GET_TAG(scb));
9739 ahd_scb_control_print(ahd_inb_scbram(ahd, SCB_CONTROL),
9741 ahd_scb_scsiid_print(ahd_inb_scbram(ahd, SCB_SCSIID),
9748 TAILQ_FOREACH(scb, &ahd->scb_data.free_scbs, links.tqe) {
9758 LIST_FOREACH(scb, &ahd->scb_data.any_dev_free_scb_list, links.le) {
9766 scb_index = ahd_inw(ahd, COMPLETE_SCB_DMAINPROG_HEAD);
9769 ahd_set_scbptr(ahd, scb_index);
9771 scb_index = ahd_inw_scbram(ahd, SCB_NEXT_COMPLETE);
9776 scb_index = ahd_inw(ahd, COMPLETE_SCB_HEAD);
9779 ahd_set_scbptr(ahd, scb_index);
9781 scb_index = ahd_inw_scbram(ahd, SCB_NEXT_COMPLETE);
9787 scb_index = ahd_inw(ahd, COMPLETE_DMA_SCB_HEAD);
9790 ahd_set_scbptr(ahd, scb_index);
9792 scb_index = ahd_inw_scbram(ahd, SCB_NEXT_COMPLETE);
9796 scb_index = ahd_inw(ahd, COMPLETE_ON_QFREEZE_HEAD);
9799 ahd_set_scbptr(ahd, scb_index);
9801 scb_index = ahd_inw_scbram(ahd, SCB_NEXT_COMPLETE);
9804 ahd_set_scbptr(ahd, saved_scb_index);
9805 dffstat = ahd_inb(ahd, DFFSTAT);
9812 ahd_set_modes(ahd, AHD_MODE_DFF0 + i, AHD_MODE_DFF0 + i);
9813 fifo_scbptr = ahd_get_scbptr(ahd);
9815 ahd_name(ahd), i,
9817 ahd_inw(ahd, LONGJMP_ADDR), fifo_scbptr);
9819 ahd_seqimode_print(ahd_inb(ahd, SEQIMODE), &cur_col, 50);
9820 ahd_seqintsrc_print(ahd_inb(ahd, SEQINTSRC), &cur_col, 50);
9821 ahd_dfcntrl_print(ahd_inb(ahd, DFCNTRL), &cur_col, 50);
9822 ahd_dfstatus_print(ahd_inb(ahd, DFSTATUS), &cur_col, 50);
9823 ahd_sg_cache_shadow_print(ahd_inb(ahd, SG_CACHE_SHADOW),
9825 ahd_sg_state_print(ahd_inb(ahd, SG_STATE), &cur_col, 50);
9826 ahd_dffsxfrctl_print(ahd_inb(ahd, DFFSXFRCTL), &cur_col, 50);
9827 ahd_soffcnt_print(ahd_inb(ahd, SOFFCNT), &cur_col, 50);
9828 ahd_mdffstat_print(ahd_inb(ahd, MDFFSTAT), &cur_col, 50);
9834 ahd_inl(ahd, SHADDR+4),
9835 ahd_inl(ahd, SHADDR),
9836 (ahd_inb(ahd, SHCNT)
9837 | (ahd_inb(ahd, SHCNT + 1) << 8)
9838 | (ahd_inb(ahd, SHCNT + 2) << 16)));
9844 ahd_inl(ahd, HADDR+4),
9845 ahd_inl(ahd, HADDR),
9846 (ahd_inb(ahd, HCNT)
9847 | (ahd_inb(ahd, HCNT + 1) << 8)
9848 | (ahd_inb(ahd, HCNT + 2) << 16)));
9849 ahd_ccsgctl_print(ahd_inb(ahd, CCSGCTL), &cur_col, 50);
9852 fifo_scb = ahd_lookup_scb(ahd, fifo_scbptr);
9860 printk("0x%x ", ahd_inb(ahd, LQIN + i));
9862 ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
9864 ahd_name(ahd), ahd_inb(ahd, LQISTATE), ahd_inb(ahd, LQOSTATE),
9865 ahd_inb(ahd, OPTIONMODE));
9867 ahd_name(ahd), ahd_inb(ahd, OS_SPACE_CNT),
9868 ahd_inb(ahd, MAXCMDCNT));
9870 ahd_name(ahd), ahd_inb(ahd, SAVED_SCSIID),
9871 ahd_inb(ahd, SAVED_LUN));
9872 ahd_simode0_print(ahd_inb(ahd, SIMODE0), &cur_col, 50);
9874 ahd_set_modes(ahd, AHD_MODE_CCHAN, AHD_MODE_CCHAN);
9876 ahd_ccscbctl_print(ahd_inb(ahd, CCSCBCTL), &cur_col, 50);
9878 ahd_set_modes(ahd, ahd->saved_src_mode, ahd->saved_dst_mode);
9880 ahd_name(ahd), ahd_inw(ahd, REG0), ahd_inw(ahd, SINDEX),
9881 ahd_inw(ahd, DINDEX));
9883 ahd_name(ahd), ahd_get_scbptr(ahd),
9884 ahd_inw_scbram(ahd, SCB_NEXT),
9885 ahd_inw_scbram(ahd, SCB_NEXT2));
9887 ahd_inb_scbram(ahd, SCB_CDB_STORE),
9888 ahd_inb_scbram(ahd, SCB_CDB_STORE+1),
9889 ahd_inb_scbram(ahd, SCB_CDB_STORE+2),
9890 ahd_inb_scbram(ahd, SCB_CDB_STORE+3),
9891 ahd_inb_scbram(ahd, SCB_CDB_STORE+4),
9892 ahd_inb_scbram(ahd, SCB_CDB_STORE+5));
9894 for (i = 0; i < ahd->stack_size; i++) {
9895 ahd->saved_stack[i] =
9896 ahd_inb(ahd, STACK)|(ahd_inb(ahd, STACK) << 8);
9897 printk(" 0x%x", ahd->saved_stack[i]);
9899 for (i = ahd->stack_size-1; i >= 0; i--) {
9900 ahd_outb(ahd, STACK, ahd->saved_stack[i] & 0xFF);
9901 ahd_outb(ahd, STACK, (ahd->saved_stack[i] >> 8) & 0xFF);
9904 ahd_restore_modes(ahd, saved_modes);
9906 ahd_unpause(ahd);
9918 ahd_read_seeprom(struct ahd_softc *ahd, uint16_t *buf,
9930 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
9934 ahd_outb(ahd, SEEADR, cur_addr);
9935 ahd_outb(ahd, SEECTL, SEEOP_READ | SEESTART);
9937 error = ahd_wait_seeprom(ahd);
9944 *bytestream_ptr++ = ahd_inb(ahd, SEEDAT);
9945 *bytestream_ptr = ahd_inb(ahd, SEEDAT+1);
9950 *buf = ahd_inw(ahd, SEEDAT);
9963 ahd_write_seeprom(struct ahd_softc *ahd, uint16_t *buf,
9971 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
9975 ahd_outb(ahd, SEEADR, SEEOP_EWEN_ADDR);
9976 ahd_outb(ahd, SEECTL, SEEOP_EWEN | SEESTART);
9977 error = ahd_wait_seeprom(ahd);
9988 ahd_outw(ahd, SEEDAT, *buf++);
9989 ahd_outb(ahd, SEEADR, cur_addr);
9990 ahd_outb(ahd, SEECTL, SEEOP_WRITE | SEESTART);
9992 retval = ahd_wait_seeprom(ahd);
10000 ahd_outb(ahd, SEEADR, SEEOP_EWDS_ADDR);
10001 ahd_outb(ahd, SEECTL, SEEOP_EWDS | SEESTART);
10002 error = ahd_wait_seeprom(ahd);
10012 ahd_wait_seeprom(struct ahd_softc *ahd)
10017 while ((ahd_inb(ahd, SEESTAT) & (SEEARBACK|SEEBUSY)) != 0 && --cnt)
10080 ahd_acquire_seeprom(struct ahd_softc *ahd)
10093 ahd_release_seeprom(struct ahd_softc *ahd)
10102 ahd_wait_flexport(struct ahd_softc *ahd)
10106 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
10108 while ((ahd_inb(ahd, BRDCTL) & FLXARBACK) == 0 && --cnt)
10117 ahd_write_flexport(struct ahd_softc *ahd, u_int addr, u_int value)
10121 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
10124 ahd_outb(ahd, BRDCTL, BRDEN|(addr << 3));
10125 error = ahd_wait_flexport(ahd);
10128 ahd_outb(ahd, BRDDAT, value);
10129 ahd_flush_device_writes(ahd);
10130 ahd_outb(ahd, BRDCTL, BRDSTB|BRDEN|(addr << 3));
10131 ahd_flush_device_writes(ahd);
10132 ahd_outb(ahd, BRDCTL, BRDEN|(addr << 3));
10133 ahd_flush_device_writes(ahd);
10134 ahd_outb(ahd, BRDCTL, 0);
10135 ahd_flush_device_writes(ahd);
10140 ahd_read_flexport(struct ahd_softc *ahd, u_int addr, uint8_t *value)
10144 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
10147 ahd_outb(ahd, BRDCTL, BRDRW|BRDEN|(addr << 3));
10148 error = ahd_wait_flexport(ahd);
10151 *value = ahd_inb(ahd, BRDDAT);
10152 ahd_outb(ahd, BRDCTL, 0);
10153 ahd_flush_device_writes(ahd);
10160 ahd_find_tmode_devs(struct ahd_softc *ahd, struct cam_sim *sim, union ccb *ccb,
10166 if ((ahd->features & AHD_TARGETMODE) == 0)
10176 *lstate = ahd->black_hole;
10180 max_id = (ahd->features & AHD_WIDE) ? 16 : 8;
10187 *tstate = ahd->enabled_targets[ccb->ccb_h.target_id];
10201 ahd_handle_en_lun(struct ahd_softc *ahd, struct cam_sim *sim, union ccb *ccb)
10214 status = ahd_find_tmode_devs(ahd, sim, ccb, &tstate, &lstate,
10222 if ((ahd->features & AHD_MULTIROLE) != 0) {
10225 our_id = ahd->our_id;
10227 if ((ahd->features & AHD_MULTI_TID) != 0
10228 && (ahd->flags & AHD_INITIATORROLE) != 0) {
10237 } else if ((ahd->flags & AHD_INITIATORROLE) != 0
10238 || ahd->enabled_luns > 0) {
10260 if ((ahd->flags & AHD_TARGETROLE) == 0
10265 ahd_lock(ahd, &s);
10266 if (LIST_FIRST(&ahd->pending_scbs) != NULL) {
10268 ahd_unlock(ahd, &s);
10271 ahd->flags |= AHD_TARGETROLE;
10272 if ((ahd->features & AHD_MULTIROLE) == 0)
10273 ahd->flags &= ~AHD_INITIATORROLE;
10274 ahd_pause(ahd);
10275 ahd_loadseq(ahd);
10276 ahd_restart(ahd);
10277 ahd_unlock(ahd, &s);
10282 channel = SIM_CHANNEL(ahd, sim);
10314 tstate = ahd_alloc_tstate(ahd, target, channel);
10343 ahd_lock(ahd, &s);
10344 ahd_pause(ahd);
10347 ahd->enabled_luns++;
10349 if ((ahd->features & AHD_MULTI_TID) != 0) {
10352 targid_mask = ahd_inw(ahd, TARGID);
10354 ahd_outw(ahd, TARGID, targid_mask);
10355 ahd_update_scsiid(ahd, targid_mask);
10360 channel = SIM_CHANNEL(ahd, sim);
10361 our_id = SIM_SCSI_ID(ahd, sim);
10372 sblkctl = ahd_inb(ahd, SBLKCTL);
10375 if ((ahd->features & AHD_TWIN) == 0)
10378 ahd->our_id = target;
10381 ahd_outb(ahd, SBLKCTL,
10384 ahd_outb(ahd, SCSIID, target);
10387 ahd_outb(ahd, SBLKCTL, sblkctl);
10391 ahd->black_hole = lstate;
10393 if (ahd->black_hole != NULL && ahd->enabled_luns > 0) {
10394 scsiseq1 = ahd_inb(ahd, SCSISEQ_TEMPLATE);
10396 ahd_outb(ahd, SCSISEQ_TEMPLATE, scsiseq1);
10397 scsiseq1 = ahd_inb(ahd, SCSISEQ1);
10399 ahd_outb(ahd, SCSISEQ1, scsiseq1);
10401 ahd_unpause(ahd);
10402 ahd_unlock(ahd, &s);
10415 ahd_lock(ahd, &s);
10418 LIST_FOREACH(scb, &ahd->pending_scbs, pending_links) {
10426 ahd_unlock(ahd, &s);
10442 ahd_unlock(ahd, &s);
10451 ahd_pause(ahd);
10455 ahd->enabled_luns--;
10463 ahd_free_tstate(ahd, target, channel,
10465 if (ahd->features & AHD_MULTI_TID) {
10468 targid_mask = ahd_inw(ahd, TARGID);
10470 ahd_outw(ahd, TARGID, targid_mask);
10471 ahd_update_scsiid(ahd, targid_mask);
10476 ahd->black_hole = NULL;
10484 if (ahd->enabled_luns == 0) {
10488 scsiseq1 = ahd_inb(ahd, SCSISEQ_TEMPLATE);
10490 ahd_outb(ahd, SCSISEQ_TEMPLATE, scsiseq1);
10491 scsiseq1 = ahd_inb(ahd, SCSISEQ1);
10493 ahd_outb(ahd, SCSISEQ1, scsiseq1);
10495 if ((ahd->features & AHD_MULTIROLE) == 0) {
10497 ahd->flags &= ~AHD_TARGETROLE;
10498 ahd->flags |= AHD_INITIATORROLE;
10499 ahd_pause(ahd);
10500 ahd_loadseq(ahd);
10501 ahd_restart(ahd);
10508 ahd_unpause(ahd);
10509 ahd_unlock(ahd, &s);
10515 ahd_update_scsiid(struct ahd_softc *ahd, u_int targid_mask)
10521 if ((ahd->features & AHD_MULTI_TID) == 0)
10530 if ((ahd->features & AHD_ULTRA2) != 0)
10531 scsiid = ahd_inb(ahd, SCSIID_ULTRA2);
10533 scsiid = ahd_inb(ahd, SCSIID);
10541 our_id = ahd->our_id;
10547 if ((ahd->features & AHD_ULTRA2) != 0)
10548 ahd_outb(ahd, SCSIID_ULTRA2, scsiid);
10550 ahd_outb(ahd, SCSIID, scsiid);
10555 ahd_run_tqinfifo(struct ahd_softc *ahd, int paused)
10559 ahd_sync_tqinfifo(ahd, BUS_DMASYNC_POSTREAD);
10560 while ((cmd = &ahd->targetcmds[ahd->tqinfifonext])->cmd_valid != 0) {
10566 if (ahd_handle_target_cmd(ahd, cmd) != 0)
10570 ahd_dmamap_sync(ahd, ahd->shared_data_dmat,
10571 ahd->shared_data_map.dmamap,
10572 ahd_targetcmd_offset(ahd, ahd->tqinfifonext),
10575 ahd->tqinfifonext++;
10581 if ((ahd->tqinfifonext & (HOST_TQINPOS - 1)) == 1) {
10584 hs_mailbox = ahd_inb(ahd, HS_MAILBOX);
10586 hs_mailbox |= ahd->tqinfifonext & HOST_TQINPOS;
10587 ahd_outb(ahd, HS_MAILBOX, hs_mailbox);
10593 ahd_handle_target_cmd(struct ahd_softc *ahd, struct target_cmd *cmd)
10603 initiator = SCSIID_TARGET(ahd, cmd->scsiid);
10608 tstate = ahd->enabled_targets[target];
10617 lstate = ahd->black_hole;
10621 ahd->flags |= AHD_TQINFIFO_BLOCKED;
10627 ahd->flags &= ~AHD_TQINFIFO_BLOCKED;
10632 lstate == ahd->black_hole ? "(Black Holed)" : "");
10636 if (lstate == ahd->black_hole) {
10695 initiator, target, lun, ahd->pending_device);
10697 ahd->pending_device = lstate;