• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/linux/linux-2.6.36/drivers/scsi/aic7xxx/

Lines Matching refs:ahc

141 static void		ahc_force_renegotiation(struct ahc_softc *ahc,
144 ahc_alloc_tstate(struct ahc_softc *ahc,
147 static void ahc_free_tstate(struct ahc_softc *ahc,
151 ahc_devlimited_syncrate(struct ahc_softc *ahc,
156 static void ahc_update_pending_scbs(struct ahc_softc *ahc);
157 static void ahc_fetch_devinfo(struct ahc_softc *ahc,
159 static void ahc_scb_devinfo(struct ahc_softc *ahc,
162 static void ahc_assert_atn(struct ahc_softc *ahc);
163 static void ahc_setup_initiator_msgout(struct ahc_softc *ahc,
166 static void ahc_build_transfer_msg(struct ahc_softc *ahc,
168 static void ahc_construct_sdtr(struct ahc_softc *ahc,
171 static void ahc_construct_wdtr(struct ahc_softc *ahc,
174 static void ahc_construct_ppr(struct ahc_softc *ahc,
178 static void ahc_clear_msg_state(struct ahc_softc *ahc);
179 static void ahc_handle_proto_violation(struct ahc_softc *ahc);
180 static void ahc_handle_message_phase(struct ahc_softc *ahc);
186 static int ahc_sent_msg(struct ahc_softc *ahc, ahc_msgtype type,
188 static int ahc_parse_msg(struct ahc_softc *ahc,
190 static int ahc_handle_msg_reject(struct ahc_softc *ahc,
192 static void ahc_handle_ign_wide_residue(struct ahc_softc *ahc,
194 static void ahc_reinitialize_dataptrs(struct ahc_softc *ahc);
195 static void ahc_handle_devreset(struct ahc_softc *ahc,
200 static void ahc_setup_target_msgin(struct ahc_softc *ahc,
206 static void ahc_build_free_scb_list(struct ahc_softc *ahc);
207 static int ahc_init_scbdata(struct ahc_softc *ahc);
208 static void ahc_fini_scbdata(struct ahc_softc *ahc);
209 static void ahc_qinfifo_requeue(struct ahc_softc *ahc,
212 static int ahc_qinfifo_count(struct ahc_softc *ahc);
213 static u_int ahc_rem_scb_from_disc_list(struct ahc_softc *ahc,
215 static void ahc_add_curscb_to_free_list(struct ahc_softc *ahc);
216 static u_int ahc_rem_wscb(struct ahc_softc *ahc,
218 static void ahc_reset_current_bus(struct ahc_softc *ahc);
220 static void ahc_dumpseq(struct ahc_softc *ahc);
222 static int ahc_loadseq(struct ahc_softc *ahc);
223 static int ahc_check_patch(struct ahc_softc *ahc,
226 static void ahc_download_instr(struct ahc_softc *ahc,
229 static void ahc_queue_lstate_event(struct ahc_softc *ahc,
234 static void ahc_update_scsiid(struct ahc_softc *ahc,
236 static int ahc_handle_target_cmd(struct ahc_softc *ahc,
240 static u_int ahc_index_busy_tcl(struct ahc_softc *ahc, u_int tcl);
241 static void ahc_unbusy_tcl(struct ahc_softc *ahc, u_int tcl);
242 static void ahc_busy_tcl(struct ahc_softc *ahc,
246 static void ahc_run_untagged_queues(struct ahc_softc *ahc);
247 static void ahc_run_untagged_queue(struct ahc_softc *ahc,
251 static void ahc_alloc_scbs(struct ahc_softc *ahc);
255 static void ahc_clear_intstat(struct ahc_softc *ahc);
256 static void ahc_run_qoutfifo(struct ahc_softc *ahc);
258 static void ahc_run_tqinfifo(struct ahc_softc *ahc, int paused);
260 static void ahc_handle_brkadrint(struct ahc_softc *ahc);
261 static void ahc_handle_seqint(struct ahc_softc *ahc, u_int intstat);
262 static void ahc_handle_scsiint(struct ahc_softc *ahc,
264 static void ahc_clear_critical_section(struct ahc_softc *ahc);
267 static void ahc_freeze_devq(struct ahc_softc *ahc, struct scb *scb);
268 static int ahc_abort_scbs(struct ahc_softc *ahc, int target,
271 static void ahc_calc_residual(struct ahc_softc *ahc,
275 static inline void ahc_freeze_untagged_queues(struct ahc_softc *ahc);
276 static inline void ahc_release_untagged_queues(struct ahc_softc *ahc);
283 ahc_freeze_untagged_queues(struct ahc_softc *ahc)
285 if ((ahc->flags & AHC_SCB_BTT) == 0)
286 ahc->untagged_queue_lock++;
296 ahc_release_untagged_queues(struct ahc_softc *ahc)
298 if ((ahc->flags & AHC_SCB_BTT) == 0) {
299 ahc->untagged_queue_lock--;
300 if (ahc->untagged_queue_lock == 0)
301 ahc_run_untagged_queues(ahc);
307 ahc_pause_bug_fix(struct ahc_softc *ahc)
309 if ((ahc->features & AHC_ULTRA2) != 0)
310 (void)ahc_inb(ahc, CCSCBCTL);
318 ahc_is_paused(struct ahc_softc *ahc)
320 return ((ahc_inb(ahc, HCNTRL) & PAUSE) != 0);
331 ahc_pause(struct ahc_softc *ahc)
333 ahc_outb(ahc, HCNTRL, ahc->pause);
339 while (ahc_is_paused(ahc) == 0)
342 ahc_pause_bug_fix(ahc);
356 ahc_unpause(struct ahc_softc *ahc)
358 if ((ahc_inb(ahc, INTSTAT) & (SCSIINT | SEQINT | BRKADRINT)) == 0)
359 ahc_outb(ahc, HCNTRL, ahc->unpause);
387 ahc_hscb_busaddr(struct ahc_softc *ahc, u_int index)
389 return (ahc->scb_data->hscb_busaddr
394 ahc_sync_scb(struct ahc_softc *ahc, struct scb *scb, int op)
396 ahc_dmamap_sync(ahc, ahc->scb_data->hscb_dmat,
397 ahc->scb_data->hscb_dmamap,
398 /*offset*/(scb->hscb - ahc->hscbs) * sizeof(*scb->hscb),
403 ahc_sync_sglist(struct ahc_softc *ahc, struct scb *scb, int op)
408 ahc_dmamap_sync(ahc, ahc->scb_data->sg_dmat, scb->sg_map->sg_dmamap,
416 ahc_targetcmd_offset(struct ahc_softc *ahc, u_int index)
418 return (((uint8_t *)&ahc->targetcmds[index]) - ahc->qoutfifo);
428 ahc_update_residual(struct ahc_softc *ahc, struct scb *scb)
434 ahc_calc_residual(ahc, scb);
442 ahc_fetch_transinfo(struct ahc_softc *ahc, char channel, u_int our_id,
453 *tstate = ahc->enabled_targets[our_id];
458 ahc_inw(struct ahc_softc *ahc, u_int port)
460 uint16_t r = ahc_inb(ahc, port+1) << 8;
461 return r | ahc_inb(ahc, port);
465 ahc_outw(struct ahc_softc *ahc, u_int port, u_int value)
467 ahc_outb(ahc, port, value & 0xFF);
468 ahc_outb(ahc, port+1, (value >> 8) & 0xFF);
472 ahc_inl(struct ahc_softc *ahc, u_int port)
474 return ((ahc_inb(ahc, port))
475 | (ahc_inb(ahc, port+1) << 8)
476 | (ahc_inb(ahc, port+2) << 16)
477 | (ahc_inb(ahc, port+3) << 24));
481 ahc_outl(struct ahc_softc *ahc, u_int port, uint32_t value)
483 ahc_outb(ahc, port, (value) & 0xFF);
484 ahc_outb(ahc, port+1, ((value) >> 8) & 0xFF);
485 ahc_outb(ahc, port+2, ((value) >> 16) & 0xFF);
486 ahc_outb(ahc, port+3, ((value) >> 24) & 0xFF);
490 ahc_inq(struct ahc_softc *ahc, u_int port)
492 return ((ahc_inb(ahc, port))
493 | (ahc_inb(ahc, port+1) << 8)
494 | (ahc_inb(ahc, port+2) << 16)
495 | (ahc_inb(ahc, port+3) << 24)
496 | (((uint64_t)ahc_inb(ahc, port+4)) << 32)
497 | (((uint64_t)ahc_inb(ahc, port+5)) << 40)
498 | (((uint64_t)ahc_inb(ahc, port+6)) << 48)
499 | (((uint64_t)ahc_inb(ahc, port+7)) << 56));
503 ahc_outq(struct ahc_softc *ahc, u_int port, uint64_t value)
505 ahc_outb(ahc, port, value & 0xFF);
506 ahc_outb(ahc, port+1, (value >> 8) & 0xFF);
507 ahc_outb(ahc, port+2, (value >> 16) & 0xFF);
508 ahc_outb(ahc, port+3, (value >> 24) & 0xFF);
509 ahc_outb(ahc, port+4, (value >> 32) & 0xFF);
510 ahc_outb(ahc, port+5, (value >> 40) & 0xFF);
511 ahc_outb(ahc, port+6, (value >> 48) & 0xFF);
512 ahc_outb(ahc, port+7, (value >> 56) & 0xFF);
519 ahc_get_scb(struct ahc_softc *ahc)
523 if ((scb = SLIST_FIRST(&ahc->scb_data->free_scbs)) == NULL) {
524 ahc_alloc_scbs(ahc);
525 scb = SLIST_FIRST(&ahc->scb_data->free_scbs);
529 SLIST_REMOVE_HEAD(&ahc->scb_data->free_scbs, links.sle);
537 ahc_free_scb(struct ahc_softc *ahc, struct scb *scb)
543 ahc->scb_data->scbindex[hscb->tag] = NULL;
547 SLIST_INSERT_HEAD(&ahc->scb_data->free_scbs, scb, links.sle);
550 ahc_platform_scb_free(ahc, scb);
554 ahc_lookup_scb(struct ahc_softc *ahc, u_int tag)
558 scb = ahc->scb_data->scbindex[tag];
560 ahc_sync_scb(ahc, scb,
566 ahc_swap_with_next_hscb(struct ahc_softc *ahc, struct scb *scb)
575 * SCB to download is saved off in ahc->next_queued_scb.
583 q_hscb = ahc->next_queued_scb->hscb;
588 ahc_htole32(ahc_hscb_busaddr(ahc, q_hscb->tag)
595 ahc->next_queued_scb->hscb = scb->hscb;
599 ahc->scb_data->scbindex[scb->hscb->tag] = scb;
606 ahc_queue_scb(struct ahc_softc *ahc, struct scb *scb)
608 ahc_swap_with_next_hscb(ahc, scb);
625 ahc->qinfifo[ahc->qinfifonext++] = scb->hscb->tag;
631 ahc_sync_scb(ahc, scb, BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
634 if ((ahc->features & AHC_QUEUE_REGS) != 0) {
635 ahc_outb(ahc, HNSCB_QOFF, ahc->qinfifonext);
637 if ((ahc->features & AHC_AUTOPAUSE) == 0)
638 ahc_pause(ahc);
639 ahc_outb(ahc, KERNEL_QINPOS, ahc->qinfifonext);
640 if ((ahc->features & AHC_AUTOPAUSE) == 0)
641 ahc_unpause(ahc);
646 ahc_get_sense_buf(struct ahc_softc *ahc, struct scb *scb)
650 offset = scb - ahc->scb_data->scbarray;
651 return (&ahc->scb_data->sense[offset]);
655 ahc_get_sense_bufaddr(struct ahc_softc *ahc, struct scb *scb)
659 offset = scb - ahc->scb_data->scbarray;
660 return (ahc->scb_data->sense_busaddr
666 ahc_sync_qoutfifo(struct ahc_softc *ahc, int op)
668 ahc_dmamap_sync(ahc, ahc->shared_data_dmat, ahc->shared_data_dmamap,
673 ahc_sync_tqinfifo(struct ahc_softc *ahc, int op)
676 if ((ahc->flags & AHC_TARGETROLE) != 0) {
677 ahc_dmamap_sync(ahc, ahc->shared_data_dmat,
678 ahc->shared_data_dmamap,
679 ahc_targetcmd_offset(ahc, 0),
693 ahc_check_cmdcmpltqueues(struct ahc_softc *ahc)
698 ahc_dmamap_sync(ahc, ahc->shared_data_dmat, ahc->shared_data_dmamap,
699 /*offset*/ahc->qoutfifonext, /*len*/1,
701 if (ahc->qoutfifo[ahc->qoutfifonext] != SCB_LIST_NULL)
704 if ((ahc->flags & AHC_TARGETROLE) != 0
705 && (ahc->flags & AHC_TQINFIFO_BLOCKED) == 0) {
706 ahc_dmamap_sync(ahc, ahc->shared_data_dmat,
707 ahc->shared_data_dmamap,
708 ahc_targetcmd_offset(ahc, ahc->tqinfifofnext),
711 if (ahc->targetcmds[ahc->tqinfifonext].cmd_valid != 0)
722 ahc_intr(struct ahc_softc *ahc)
726 if ((ahc->pause & INTEN) == 0) {
741 if ((ahc->flags & (AHC_ALL_INTERRUPTS|AHC_EDGE_INTERRUPT)) == 0
742 && (ahc_check_cmdcmpltqueues(ahc) != 0))
745 intstat = ahc_inb(ahc, INTSTAT);
750 if (ahc->unsolicited_ints > 500) {
751 ahc->unsolicited_ints = 0;
752 if ((ahc->chip & AHC_PCI) != 0
753 && (ahc_inb(ahc, ERROR) & PCIERRSTAT) != 0)
754 ahc->bus_intr(ahc);
757 ahc->unsolicited_ints++;
760 ahc->unsolicited_ints = 0;
763 ahc_outb(ahc, CLRINT, CLRCMDINT);
773 ahc_flush_device_writes(ahc);
774 ahc_run_qoutfifo(ahc);
776 if ((ahc->flags & AHC_TARGETROLE) != 0)
777 ahc_run_tqinfifo(ahc, /*paused*/FALSE);
785 if (intstat == 0xFF && (ahc->features & AHC_REMOVABLE) != 0) {
788 ahc_handle_brkadrint(ahc);
791 ahc_pause_bug_fix(ahc);
794 ahc_handle_seqint(ahc, intstat);
797 ahc_handle_scsiint(ahc, intstat);
807 ahc_restart(struct ahc_softc *ahc)
811 ahc_pause(ahc);
814 ahc_clear_msg_state(ahc);
816 ahc_outb(ahc, SCSISIGO, 0); /* De-assert BSY */
817 ahc_outb(ahc, MSG_OUT, MSG_NOOP); /* No message to send */
818 ahc_outb(ahc, SXFRCTL1, ahc_inb(ahc, SXFRCTL1) & ~BITBUCKET);
819 ahc_outb(ahc, LASTPHASE, P_BUSFREE);
820 ahc_outb(ahc, SAVED_SCSIID, 0xFF);
821 ahc_outb(ahc, SAVED_LUN, 0xFF);
830 ahc_outb(ahc, TQINPOS, ahc->tqinfifonext);
833 ahc_outb(ahc, SCSISEQ,
834 ahc_inb(ahc, SCSISEQ_TEMPLATE) & (ENSELI|ENRSELI|ENAUTOATNP));
835 if ((ahc->features & AHC_CMD_CHAN) != 0) {
837 ahc_outb(ahc, CCSCBCNT, 0);
838 ahc_outb(ahc, CCSGCTL, 0);
839 ahc_outb(ahc, CCSCBCTL, 0);
846 if ((ahc_inb(ahc, SEQ_FLAGS2) & SCB_DMA) != 0) {
847 ahc_add_curscb_to_free_list(ahc);
848 ahc_outb(ahc, SEQ_FLAGS2,
849 ahc_inb(ahc, SEQ_FLAGS2) & ~SCB_DMA);
857 ahc_outb(ahc, CLRINT, CLRSEQINT);
859 ahc_outb(ahc, MWI_RESIDUAL, 0);
860 ahc_outb(ahc, SEQCTL, ahc->seqctl);
861 ahc_outb(ahc, SEQADDR0, 0);
862 ahc_outb(ahc, SEQADDR1, 0);
867 sblkctl = ahc_inb(ahc, SBLKCTL);
868 ahc_outb(ahc, SBLKCTL, (sblkctl & ~(DIAGLEDEN|DIAGLEDON)));
870 ahc_unpause(ahc);
875 ahc_run_qoutfifo(struct ahc_softc *ahc)
880 ahc_sync_qoutfifo(ahc, BUS_DMASYNC_POSTREAD);
881 while (ahc->qoutfifo[ahc->qoutfifonext] != SCB_LIST_NULL) {
883 scb_index = ahc->qoutfifo[ahc->qoutfifonext];
884 if ((ahc->qoutfifonext & 0x03) == 0x03) {
894 modnext = ahc->qoutfifonext & ~0x3;
895 *((uint32_t *)(&ahc->qoutfifo[modnext])) = 0xFFFFFFFFUL;
896 ahc_dmamap_sync(ahc, ahc->shared_data_dmat,
897 ahc->shared_data_dmamap,
901 ahc->qoutfifonext++;
903 scb = ahc_lookup_scb(ahc, scb_index);
907 ahc_name(ahc), scb_index,
908 (ahc->qoutfifonext - 1) & 0xFF);
916 ahc_update_residual(ahc, scb);
917 ahc_done(ahc, scb);
922 ahc_run_untagged_queues(struct ahc_softc *ahc)
927 ahc_run_untagged_queue(ahc, &ahc->untagged_queues[i]);
931 ahc_run_untagged_queue(struct ahc_softc *ahc, struct scb_tailq *queue)
935 if (ahc->untagged_queue_lock != 0)
941 ahc_queue_scb(ahc, scb);
947 ahc_handle_brkadrint(struct ahc_softc *ahc)
956 error = ahc_inb(ahc, ERROR);
960 ahc_name(ahc), ahc_hard_errors[i].errmesg,
961 ahc_inb(ahc, SEQADDR0) |
962 (ahc_inb(ahc, SEQADDR1) << 8));
964 ahc_dump_card_state(ahc);
967 ahc_abort_scbs(ahc, CAM_TARGET_WILDCARD, ALL_CHANNELS,
972 ahc_shutdown(ahc);
976 ahc_handle_seqint(struct ahc_softc *ahc, u_int intstat)
981 ahc_fetch_devinfo(ahc, &devinfo);
989 ahc_outb(ahc, CLRINT, CLRSEQINT);
1001 ahc_outb(ahc, RETURN_1, 0);
1012 scb_index = ahc_inb(ahc, SCB_TAG);
1013 scb = ahc_lookup_scb(ahc, scb_index);
1015 ahc_print_devinfo(ahc, &devinfo);
1019 ahc_dump_card_state(ahc);
1039 ahc_freeze_devq(ahc, scb);
1045 ahc_name(ahc));
1057 ahc_print_path(ahc, scb);
1066 targ_info = ahc_fetch_transinfo(ahc,
1077 ahc_update_residual(ahc, scb);
1080 ahc_print_path(ahc, scb);
1084 sg->addr = ahc_get_sense_bufaddr(ahc, scb);
1085 sg->len = ahc_get_sense_bufsize(ahc, scb);
1121 ahc_update_neg_request(ahc, &devinfo,
1137 ahc_qinfifo_requeue_tail(ahc, scb);
1138 ahc_outb(ahc, RETURN_1, SEND_SENSE);
1154 ahc_outb(ahc, SCSISEQ,
1155 ahc_inb(ahc, SCSISEQ) & (ENSELI|ENRSELI|ENAUTOATNP));
1159 ahc_name(ahc), devinfo.channel, devinfo.target);
1162 ahc_inb(ahc, SAVED_SCSIID), ahc_inb(ahc, SAVED_LUN),
1163 ahc_inb(ahc, ARG_1), ahc_inb(ahc, ACCUM));
1166 ahc_inb(ahc, SEQ_FLAGS), ahc_inb(ahc, SCBPTR),
1167 ahc_index_busy_tcl(ahc,
1168 BUILD_TCL(ahc_inb(ahc, SAVED_SCSIID),
1169 ahc_inb(ahc, SAVED_LUN))),
1170 ahc_inb(ahc, SINDEX));
1173 ahc_inb(ahc, SCSIID), ahc_inb(ahc, SCB_SCSIID),
1174 ahc_inb(ahc, SCB_LUN), ahc_inb(ahc, SCB_TAG),
1175 ahc_inb(ahc, SCB_CONTROL));
1177 ahc_inb(ahc, SCSIBUSL), ahc_inb(ahc, SCSISIGI));
1178 printk("SXFRCTL0 == 0x%x\n", ahc_inb(ahc, SXFRCTL0));
1179 printk("SEQCTL == 0x%x\n", ahc_inb(ahc, SEQCTL));
1180 ahc_dump_card_state(ahc);
1181 ahc->msgout_buf[0] = MSG_BUS_DEV_RESET;
1182 ahc->msgout_len = 1;
1183 ahc->msgout_index = 0;
1184 ahc->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
1185 ahc_outb(ahc, MSG_OUT, HOST_MSG);
1186 ahc_assert_atn(ahc);
1191 u_int rejbyte = ahc_inb(ahc, ACCUM);
1194 ahc_name(ahc), devinfo.channel, devinfo.target, rejbyte);
1199 ahc_handle_proto_violation(ahc);
1203 ahc_handle_ign_wide_residue(ahc, &devinfo);
1206 ahc_reinitialize_dataptrs(ahc);
1212 lastphase = ahc_inb(ahc, LASTPHASE);
1215 ahc_name(ahc), devinfo.channel, devinfo.target,
1216 lastphase, ahc_inb(ahc, SCSISIGI));
1223 lastphase = ahc_inb(ahc, LASTPHASE);
1226 ahc_name(ahc), devinfo.channel, devinfo.target,
1227 lastphase, ahc_inb(ahc, SCSISIGI));
1228 ahc_restart(ahc);
1244 if (ahc->msg_type == MSG_TYPE_NONE) {
1249 bus_phase = ahc_inb(ahc, SCSISIGI) & PHASE_MASK;
1259 ahc_clear_intstat(ahc);
1260 ahc_restart(ahc);
1264 scb_index = ahc_inb(ahc, SCB_TAG);
1265 scb = ahc_lookup_scb(ahc, scb_index);
1273 ahc_setup_initiator_msgout(ahc,
1277 ahc->msg_type =
1279 ahc->msgin_index = 0;
1285 ahc->msg_type =
1287 ahc->msgin_index = 0;
1290 ahc_setup_target_msgin(ahc,
1297 ahc_handle_message_phase(ahc);
1314 && (ahc_inb(ahc, SSTAT1) & SCSIPERR) != 0) {
1316 if ((ahc->features & AHC_DT) == 0) {
1325 curphase = ahc_inb(ahc, SCSISIGI) & PHASE_MASK;
1326 ahc_outb(ahc, LASTPHASE, curphase);
1327 ahc_outb(ahc, SCSISIGO, curphase);
1329 if ((ahc_inb(ahc, SCSISIGI) & (CDI|MSGI)) == 0) {
1338 ahc_outb(ahc, SXFRCTL1,
1339 ahc_inb(ahc, SXFRCTL1) | BITBUCKET);
1342 if ((ahc_inb(ahc, SCSISIGI)
1347 ahc_outb(ahc, SXFRCTL1,
1348 ahc_inb(ahc, SXFRCTL1) & ~BITBUCKET);
1353 ahc_print_devinfo(ahc, &devinfo);
1356 scb_index = ahc_inb(ahc, SCB_TAG);
1357 scb = ahc_lookup_scb(ahc, scb_index);
1361 ahc_reset_channel(ahc, devinfo.channel,
1365 ahc_inb(ahc, SCSIDATL);
1380 u_int scbindex = ahc_inb(ahc, SCB_TAG);
1381 u_int lastphase = ahc_inb(ahc, LASTPHASE);
1384 scb = ahc_lookup_scb(ahc, scbindex);
1389 ahc_print_path(ahc, scb);
1394 ahc_print_path(ahc, scb);
1396 ahc_inb(ahc, SEQ_FLAGS) & DPHASE ? "Have" : "Haven't",
1414 ahc_freeze_devq(ahc, scb);
1423 if ((ahc->features & AHC_ULTRA2) != 0) {
1428 ahc_outb(ahc, SXFRCTL0,
1429 ahc_inb(ahc, SXFRCTL0) | CLRSTCNT|CLRCHN);
1430 ahc_outb(ahc, SXFRCTL0,
1431 ahc_inb(ahc, SXFRCTL0) | CLRSTCNT|CLRCHN);
1433 if ((ahc->flags & AHC_39BIT_ADDRESSING) != 0) {
1437 dscommand1 = ahc_inb(ahc, DSCOMMAND1);
1438 ahc_outb(ahc, DSCOMMAND1, dscommand1 | HADDLDSEL0);
1439 ahc_outb(ahc, HADDR, 0);
1440 ahc_outb(ahc, DSCOMMAND1, dscommand1);
1449 ahc_name(ahc), devinfo.channel, devinfo.target,
1451 scbindex = ahc_inb(ahc, SCB_TAG);
1452 scb = ahc_lookup_scb(ahc, scbindex);
1459 ahc_search_qinfifo(ahc, SCB_GET_TARGET(ahc, scb),
1460 SCB_GET_CHANNEL(ahc, scb),
1468 printk("%s: No free or disconnected SCBs\n", ahc_name(ahc));
1469 ahc_dump_card_state(ahc);
1477 scbptr = ahc_inb(ahc, SCBPTR);
1479 scbptr, ahc_inb(ahc, ARG_1),
1480 ahc->scb_data->hscbs[scbptr].tag);
1481 ahc_dump_card_state(ahc);
1487 printk("%s: BTT calculation out of range\n", ahc_name(ahc));
1490 ahc_inb(ahc, SAVED_SCSIID), ahc_inb(ahc, SAVED_LUN),
1491 ahc_inb(ahc, ARG_1), ahc_inb(ahc, ACCUM));
1494 ahc_inb(ahc, SEQ_FLAGS), ahc_inb(ahc, SCBPTR),
1495 ahc_index_busy_tcl(ahc,
1496 BUILD_TCL(ahc_inb(ahc, SAVED_SCSIID),
1497 ahc_inb(ahc, SAVED_LUN))),
1498 ahc_inb(ahc, SINDEX),
1499 ahc_inb(ahc, ACCUM));
1502 ahc_inb(ahc, SCSIID), ahc_inb(ahc, SCB_SCSIID),
1503 ahc_inb(ahc, SCB_LUN), ahc_inb(ahc, SCB_TAG),
1504 ahc_inb(ahc, SCB_CONTROL));
1506 ahc_inb(ahc, SCSIBUSL), ahc_inb(ahc, SCSISIGI));
1507 ahc_dump_card_state(ahc);
1514 intstat, ahc_inb(ahc, SCSISIGI));
1523 ahc_unpause(ahc);
1527 ahc_handle_scsiint(struct ahc_softc *ahc, u_int intstat)
1536 if ((ahc->features & AHC_TWIN) != 0
1537 && ((ahc_inb(ahc, SBLKCTL) & SELBUSB) != 0))
1543 if ((ahc->features & AHC_ULTRA2) != 0)
1544 status0 = ahc_inb(ahc, SSTAT0) & IOERR;
1547 status = ahc_inb(ahc, SSTAT1) & (SELTO|SCSIRSTI|BUSFREE|SCSIPERR);
1549 if ((ahc->features & AHC_TWIN) != 0) {
1551 ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) ^ SELBUSB);
1552 status = ahc_inb(ahc, SSTAT1)
1557 printk("%s: Spurious SCSI interrupt\n", ahc_name(ahc));
1558 ahc_outb(ahc, CLRINT, CLRSCSIINT);
1559 ahc_unpause(ahc);
1565 ahc_clear_critical_section(ahc);
1567 scb_index = ahc_inb(ahc, SCB_TAG);
1568 scb = ahc_lookup_scb(ahc, scb_index);
1570 && (ahc_inb(ahc, SEQ_FLAGS) & NOT_IDENTIFIED) != 0)
1573 if ((ahc->features & AHC_ULTRA2) != 0
1577 now_lvd = ahc_inb(ahc, SBLKCTL) & ENAB40;
1579 ahc_name(ahc), now_lvd ? "LVD" : "SE");
1580 ahc_outb(ahc, CLRSINT0, CLRIOERR);
1591 ahc_reset_channel(ahc, intr_channel,
1595 ahc_name(ahc), intr_channel);
1597 ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) ^ SELBUSB);
1598 ahc_reset_channel(ahc, intr_channel, /*Initiate Reset*/FALSE);
1620 lastphase = ahc_inb(ahc, LASTPHASE);
1621 curphase = ahc_inb(ahc, SCSISIGI) & PHASE_MASK;
1622 sstat2 = ahc_inb(ahc, SSTAT2);
1623 ahc_outb(ahc, CLRSINT1, CLRSCSIPERR);
1635 if ((ahc_inb(ahc, SSTAT1) & SCSIPERR) != 0
1651 ahc_print_path(ahc, scb);
1654 printk("%s:%c:%d: ", ahc_name(ahc), intr_channel,
1655 SCSIID_TARGET(ahc, ahc_inb(ahc, SAVED_SCSIID)));
1656 scsirate = ahc_inb(ahc, SCSIRATE);
1661 ahc_inw(ahc, SEQADDR0),
1663 if ((ahc->features & AHC_DT) != 0) {
1679 if ((ahc->features & AHC_DT) != 0
1697 if (ahc->msg_type != MSG_TYPE_NONE)
1698 ahc->send_msg_perror = TRUE;
1700 ahc_outb(ahc, MSG_OUT, mesg_out);
1707 ahc_fetch_devinfo(ahc, &devinfo);
1708 ahc_force_renegotiation(ahc, &devinfo);
1710 ahc_outb(ahc, CLRINT, CLRSCSIINT);
1711 ahc_unpause(ahc);
1716 ahc_outb(ahc, SCSISEQ, 0);
1719 ahc_clear_msg_state(ahc);
1722 ahc_outb(ahc, SIMODE1, ahc_inb(ahc, SIMODE1) & ~ENBUSFREE);
1723 ahc_outb(ahc, CLRSINT1, CLRSELTIMEO|CLRBUSFREE|CLRSCSIPERR);
1733 ahc_outb(ahc, CLRSINT0, CLRSELINGO);
1735 scbptr = ahc_inb(ahc, WAITING_SCBH);
1736 ahc_outb(ahc, SCBPTR, scbptr);
1737 scb_index = ahc_inb(ahc, SCB_TAG);
1739 scb = ahc_lookup_scb(ahc, scb_index);
1743 ahc_name(ahc), scbptr, scb_index);
1744 ahc_dump_card_state(ahc);
1749 ahc_print_path(ahc, scb);
1754 ahc_scb_devinfo(ahc, &devinfo, scb);
1756 ahc_freeze_devq(ahc, scb);
1764 ahc_handle_devreset(ahc, &devinfo,
1769 ahc_outb(ahc, CLRINT, CLRSCSIINT);
1770 ahc_restart(ahc);
1772 && (ahc_inb(ahc, SIMODE1) & ENBUSFREE) != 0) {
1788 ahc_outb(ahc, SCSISEQ,
1789 ahc_inb(ahc, SCSISEQ) & (ENSELI|ENRSELI|ENAUTOATNP));
1797 ahc_outb(ahc, SIMODE1, ahc_inb(ahc, SIMODE1) & ~ENBUSFREE);
1798 ahc_outb(ahc, CLRSINT1, CLRBUSFREE|CLRSCSIPERR);
1806 lastphase = ahc_inb(ahc, LASTPHASE);
1807 saved_scsiid = ahc_inb(ahc, SAVED_SCSIID);
1808 saved_lun = ahc_inb(ahc, SAVED_LUN);
1809 target = SCSIID_TARGET(ahc, saved_scsiid);
1811 channel = SCSIID_CHANNEL(ahc, saved_scsiid);
1820 if (ahc_sent_msg(ahc, AHCMSG_1B, MSG_ABORT_TAG, TRUE)
1821 || ahc_sent_msg(ahc, AHCMSG_1B, MSG_ABORT, TRUE)) {
1822 if (ahc->msgout_buf[ahc->msgout_index - 1]
1825 ahc_print_path(ahc, scb);
1829 ahc_abort_scbs(ahc, target, channel,
1834 } else if (ahc_sent_msg(ahc, AHCMSG_1B,
1844 && ahc_match_scb(ahc, scb, target, channel,
1857 ahc_handle_devreset(ahc, &devinfo,
1862 } else if (ahc_sent_msg(ahc, AHCMSG_EXT,
1871 tinfo = ahc_fetch_transinfo(ahc,
1879 ahc_qinfifo_requeue_tail(ahc, scb);
1881 } else if (ahc_sent_msg(ahc, AHCMSG_EXT,
1887 ahc_set_width(ahc, &devinfo,
1891 ahc_qinfifo_requeue_tail(ahc, scb);
1893 } else if (ahc_sent_msg(ahc, AHCMSG_EXT,
1899 ahc_set_syncrate(ahc, &devinfo,
1905 ahc_qinfifo_requeue_tail(ahc, scb);
1919 ahc_print_path(ahc, scb);
1920 ahc_abort_scbs(ahc, target, channel,
1929 printk("%s: ", ahc_name(ahc));
1942 ahc_force_renegotiation(ahc, &devinfo);
1947 ahc_inb(ahc, SEQADDR0)
1948 | (ahc_inb(ahc, SEQADDR1) << 8));
1950 ahc_outb(ahc, CLRINT, CLRSCSIINT);
1951 ahc_restart(ahc);
1954 ahc_name(ahc), status);
1955 ahc_outb(ahc, CLRINT, CLRSCSIINT);
1964 ahc_force_renegotiation(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
1969 targ_info = ahc_fetch_transinfo(ahc,
1974 ahc_update_neg_request(ahc, devinfo, tstate,
1980 ahc_clear_critical_section(struct ahc_softc *ahc)
1987 if (ahc->num_critical_sections == 0)
1999 seqaddr = ahc_inb(ahc, SEQADDR0)
2000 | (ahc_inb(ahc, SEQADDR1) << 8);
2009 cs = ahc->critical_sections;
2010 for (i = 0; i < ahc->num_critical_sections; i++, cs++) {
2016 if (i == ahc->num_critical_sections)
2021 ahc_name(ahc));
2022 ahc_dump_card_state(ahc);
2035 simode0 = ahc_inb(ahc, SIMODE0);
2036 ahc_outb(ahc, SIMODE0, 0);
2037 simode1 = ahc_inb(ahc, SIMODE1);
2038 if ((ahc->features & AHC_DT) != 0)
2047 ahc_outb(ahc, SIMODE1, simode1 & ENBUSFREE);
2049 ahc_outb(ahc, SIMODE1, 0);
2050 ahc_outb(ahc, CLRINT, CLRSCSIINT);
2051 ahc_outb(ahc, SEQCTL, ahc->seqctl | STEP);
2054 if ((ahc->features & AHC_DT) != 0) {
2055 ahc_outb(ahc, CLRSINT1, CLRBUSFREE);
2056 ahc_outb(ahc, CLRINT, CLRSCSIINT);
2058 ahc_outb(ahc, HCNTRL, ahc->unpause);
2059 while (!ahc_is_paused(ahc))
2063 ahc_outb(ahc, SIMODE0, simode0);
2064 ahc_outb(ahc, SIMODE1, simode1);
2065 ahc_outb(ahc, SEQCTL, ahc->seqctl);
2073 ahc_clear_intstat(struct ahc_softc *ahc)
2076 ahc_outb(ahc, CLRSINT1, CLRSELTIMEO|CLRATNO|CLRSCSIRSTI
2079 ahc_flush_device_writes(ahc);
2080 ahc_outb(ahc, CLRSINT0, CLRSELDO|CLRSELDI|CLRSELINGO);
2081 ahc_flush_device_writes(ahc);
2082 ahc_outb(ahc, CLRINT, CLRSCSIINT);
2083 ahc_flush_device_writes(ahc);
2098 ahc_alloc_tstate(struct ahc_softc *ahc, u_int scsi_id, char channel)
2104 master_tstate = ahc->enabled_targets[ahc->our_id];
2107 master_tstate = ahc->enabled_targets[ahc->our_id_b + 8];
2109 if (ahc->enabled_targets[scsi_id] != NULL
2110 && ahc->enabled_targets[scsi_id] != master_tstate)
2112 ahc_name(ahc));
2135 ahc->enabled_targets[scsi_id] = tstate;
2145 ahc_free_tstate(struct ahc_softc *ahc, u_int scsi_id, char channel, int force)
2153 if (((channel == 'B' && scsi_id == ahc->our_id_b)
2154 || (channel == 'A' && scsi_id == ahc->our_id))
2160 tstate = ahc->enabled_targets[scsi_id];
2163 ahc->enabled_targets[scsi_id] = NULL;
2174 ahc_devlimited_syncrate(struct ahc_softc *ahc,
2181 if ((ahc->features & AHC_ULTRA2) != 0) {
2182 if ((ahc_inb(ahc, SBLKCTL) & ENAB40) != 0
2183 && (ahc_inb(ahc, SSTAT2) & EXP_ACTIVE) == 0) {
2190 } else if ((ahc->features & AHC_ULTRA) != 0) {
2220 return (ahc_find_syncrate(ahc, period, ppr_options, maxsync));
2229 ahc_find_syncrate(struct ahc_softc *ahc, u_int *period,
2234 if ((ahc->features & AHC_DT) == 0)
2244 if ((ahc->features & (AHC_DT | AHC_ULTRA2)) == 0
2247 if ((ahc->features & (AHC_DT | AHC_ULTRA2 | AHC_ULTRA)) == 0
2259 if ((ahc->features & AHC_ULTRA2) != 0
2290 || ((ahc->features & AHC_ULTRA2) != 0
2305 ahc_find_period(struct ahc_softc *ahc, u_int scsirate, u_int maxsync)
2309 if ((ahc->features & AHC_ULTRA2) != 0)
2315 if ((ahc->features & AHC_DT) == 0 && maxsync < AHC_SYNCRATE_ULTRA2)
2317 if ((ahc->features & (AHC_DT | AHC_ULTRA2)) == 0
2320 if ((ahc->features & (AHC_DT | AHC_ULTRA2 | AHC_ULTRA)) == 0
2328 if ((ahc->features & AHC_ULTRA2) != 0) {
2346 ahc_validate_offset(struct ahc_softc *ahc,
2356 } else if ((ahc->features & AHC_ULTRA2) != 0) {
2378 ahc_validate_width(struct ahc_softc *ahc, struct ahc_initiator_tinfo *tinfo,
2383 if (ahc->features & AHC_WIDE) {
2408 ahc_update_neg_request(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
2422 if ((ahc->features & AHC_WIDE) != 0)
2451 ahc_set_syncrate(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
2471 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, devinfo->our_scsiid,
2498 if ((ahc->features & AHC_ULTRA2) != 0) {
2527 sxfrctl0 = ahc_inb(ahc, SXFRCTL0);
2531 ahc_outb(ahc, SXFRCTL0, sxfrctl0);
2535 ahc_outb(ahc, SCSIRATE, scsirate);
2536 if ((ahc->features & AHC_ULTRA2) != 0)
2537 ahc_outb(ahc, SCSIOFFSET, offset);
2545 ahc_send_async(ahc, devinfo->channel, devinfo->target,
2550 "offset = 0x%x\n", ahc_name(ahc),
2557 ahc_name(ahc), devinfo->target);
2562 update_needed += ahc_update_neg_request(ahc, devinfo, tstate,
2566 ahc_update_pending_scbs(ahc);
2578 ahc_set_width(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
2589 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, devinfo->our_scsiid,
2611 ahc_outb(ahc, SCSIRATE, scsirate);
2615 ahc_send_async(ahc, devinfo->channel, devinfo->target,
2619 ahc_name(ahc), devinfo->target,
2624 update_needed += ahc_update_neg_request(ahc, devinfo, tstate,
2627 ahc_update_pending_scbs(ahc);
2634 ahc_set_tags(struct ahc_softc *ahc, struct scsi_cmnd *cmd,
2639 ahc_platform_set_tags(ahc, sdev, devinfo, alg);
2640 ahc_send_async(ahc, devinfo->channel, devinfo->target,
2650 ahc_update_pending_scbs(struct ahc_softc *ahc)
2663 LIST_FOREACH(pending_scb, &ahc->pending_scbs, pending_links) {
2669 ahc_scb_devinfo(ahc, &devinfo, pending_scb);
2670 tinfo = ahc_fetch_transinfo(ahc, devinfo.channel,
2684 ahc_sync_scb(ahc, pending_scb,
2692 if (ahc_is_paused(ahc)) {
2696 ahc_pause(ahc);
2699 saved_scbptr = ahc_inb(ahc, SCBPTR);
2701 for (i = 0; i < ahc->scb_data->maxhscbs; i++) {
2706 ahc_outb(ahc, SCBPTR, i);
2707 scb_tag = ahc_inb(ahc, SCB_TAG);
2708 pending_scb = ahc_lookup_scb(ahc, scb_tag);
2713 control = ahc_inb(ahc, SCB_CONTROL);
2716 ahc_outb(ahc, SCB_CONTROL, control);
2717 ahc_outb(ahc, SCB_SCSIRATE, pending_hscb->scsirate);
2718 ahc_outb(ahc, SCB_SCSIOFFSET, pending_hscb->scsioffset);
2720 ahc_outb(ahc, SCBPTR, saved_scbptr);
2723 ahc_unpause(ahc);
2728 ahc_fetch_devinfo(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
2734 if (ahc_inb(ahc, SSTAT0) & TARGET)
2740 && (ahc->features & AHC_MULTI_TID) != 0
2741 && (ahc_inb(ahc, SEQ_FLAGS)
2744 our_id = ahc_inb(ahc, TARGIDIN) & OID;
2745 } else if ((ahc->features & AHC_ULTRA2) != 0)
2746 our_id = ahc_inb(ahc, SCSIID_ULTRA2) & OID;
2748 our_id = ahc_inb(ahc, SCSIID) & OID;
2750 saved_scsiid = ahc_inb(ahc, SAVED_SCSIID);
2753 SCSIID_TARGET(ahc, saved_scsiid),
2754 ahc_inb(ahc, SAVED_LUN),
2755 SCSIID_CHANNEL(ahc, saved_scsiid),
2793 ahc_print_devinfo(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
2795 printk("%s:%c:%d:%d: ", ahc_name(ahc), devinfo->channel,
2800 ahc_scb_devinfo(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
2810 ahc_compile_devinfo(devinfo, our_id, SCB_GET_TARGET(ahc, scb),
2811 SCB_GET_LUN(scb), SCB_GET_CHANNEL(ahc, scb), role);
2817 ahc_assert_atn(struct ahc_softc *ahc)
2822 if ((ahc->features & AHC_DT) == 0)
2823 scsisigo |= ahc_inb(ahc, SCSISIGI);
2824 ahc_outb(ahc, SCSISIGO, scsisigo);
2834 ahc_setup_initiator_msgout(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
2842 ahc->msgout_index = 0;
2843 ahc->msgout_len = 0;
2846 && ahc_inb(ahc, MSG_OUT) == MSG_IDENTIFYFLAG) {
2852 ahc->msgout_buf[ahc->msgout_index++] = identify_msg;
2853 ahc->msgout_len++;
2856 ahc->msgout_buf[ahc->msgout_index++] =
2858 ahc->msgout_buf[ahc->msgout_index++] = scb->hscb->tag;
2859 ahc->msgout_len += 2;
2864 ahc->msgout_buf[ahc->msgout_index++] = MSG_BUS_DEV_RESET;
2865 ahc->msgout_len++;
2866 ahc_print_path(ahc, scb);
2875 ahc_outb(ahc, SCSISEQ, (ahc_inb(ahc, SCSISEQ) & ~ENSELO));
2878 ahc->msgout_buf[ahc->msgout_index++] = MSG_ABORT_TAG;
2880 ahc->msgout_buf[ahc->msgout_index++] = MSG_ABORT;
2881 ahc->msgout_len++;
2882 ahc_print_path(ahc, scb);
2892 ahc_outb(ahc, SCSISEQ, (ahc_inb(ahc, SCSISEQ) & ~ENSELO));
2894 ahc_build_transfer_msg(ahc, devinfo);
2902 ahc_inb(ahc, MSG_OUT), scb->flags);
2909 ahc_outb(ahc, SCB_CONTROL, ahc_inb(ahc, SCB_CONTROL) & ~MK_MESSAGE);
2911 ahc->msgout_index = 0;
2912 ahc->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
2920 ahc_build_transfer_msg(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
2937 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, devinfo->our_scsiid,
2951 rate = ahc_devlimited_syncrate(ahc, tinfo, &period,
2972 if ((ahc->features & AHC_WIDE) != 0)
2978 ahc_print_devinfo(ahc, devinfo);
2998 ahc_validate_offset(ahc, tinfo, rate, &offset,
3003 ahc_construct_ppr(ahc, devinfo, period, offset,
3006 ahc_construct_sdtr(ahc, devinfo, period, offset);
3009 ahc_construct_wdtr(ahc, devinfo, tinfo->goal.width);
3018 ahc_construct_sdtr(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
3023 ahc->msgout_index += spi_populate_sync_msg(
3024 ahc->msgout_buf + ahc->msgout_index, period, offset);
3025 ahc->msgout_len += 5;
3028 ahc_name(ahc), devinfo->channel, devinfo->target,
3038 ahc_construct_wdtr(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
3041 ahc->msgout_index += spi_populate_width_msg(
3042 ahc->msgout_buf + ahc->msgout_index, bus_width);
3043 ahc->msgout_len += 4;
3046 ahc_name(ahc), devinfo->channel, devinfo->target,
3056 ahc_construct_ppr(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
3062 ahc->msgout_index += spi_populate_ppr_msg(
3063 ahc->msgout_buf + ahc->msgout_index, period, offset,
3065 ahc->msgout_len += 8;
3068 "offset %x, ppr_options %x\n", ahc_name(ahc),
3078 ahc_clear_msg_state(struct ahc_softc *ahc)
3080 ahc->msgout_len = 0;
3081 ahc->msgin_index = 0;
3082 ahc->msg_type = MSG_TYPE_NONE;
3083 if ((ahc_inb(ahc, SCSISIGI) & ATNI) != 0) {
3088 ahc_outb(ahc, CLRSINT1, CLRATNO);
3090 ahc_outb(ahc, MSG_OUT, MSG_NOOP);
3091 ahc_outb(ahc, SEQ_FLAGS2,
3092 ahc_inb(ahc, SEQ_FLAGS2) & ~TARGET_MSG_PENDING);
3096 ahc_handle_proto_violation(struct ahc_softc *ahc)
3106 ahc_fetch_devinfo(ahc, &devinfo);
3107 scbid = ahc_inb(ahc, SCB_TAG);
3108 scb = ahc_lookup_scb(ahc, scbid);
3109 seq_flags = ahc_inb(ahc, SEQ_FLAGS);
3110 curphase = ahc_inb(ahc, SCSISIGI) & PHASE_MASK;
3111 lastphase = ahc_inb(ahc, LASTPHASE);
3119 ahc_print_devinfo(ahc, &devinfo);
3128 ahc_print_devinfo(ahc, &devinfo);
3134 ahc_print_path(ahc, scb);
3136 } else if ((ahc_inb(ahc, SCB_CONTROL) & STATUS_RCVD) == 0) {
3144 ahc_print_path(ahc, scb);
3147 ahc_print_path(ahc, scb);
3149 ahc_dump_card_state(ahc);
3161 found = ahc_reset_channel(ahc, 'A', TRUE);
3163 "%d SCBs aborted\n", ahc_name(ahc), 'A', found);
3170 ahc_outb(ahc, SCSISEQ,
3171 ahc_inb(ahc, SCSISEQ) & ~ENSELO);
3172 ahc_assert_atn(ahc);
3173 ahc_outb(ahc, MSG_OUT, HOST_MSG);
3175 ahc_print_devinfo(ahc, &devinfo);
3176 ahc->msgout_buf[0] = MSG_ABORT_TASK;
3177 ahc->msgout_len = 1;
3178 ahc->msgout_index = 0;
3179 ahc->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
3181 ahc_print_path(ahc, scb);
3193 ahc_handle_message_phase(struct ahc_softc *ahc)
3199 ahc_fetch_devinfo(ahc, &devinfo);
3201 bus_phase = ahc_inb(ahc, SCSISIGI) & PHASE_MASK;
3204 switch (ahc->msg_type) {
3211 if (ahc->msgout_len == 0)
3216 ahc_print_devinfo(ahc, &devinfo);
3236 ahc_outb(ahc, CLRSINT1, CLRATNO);
3237 ahc->send_msg_perror = FALSE;
3238 ahc->msg_type = MSG_TYPE_INITIATOR_MSGIN;
3239 ahc->msgin_index = 0;
3246 if (ahc->send_msg_perror) {
3247 ahc_outb(ahc, CLRSINT1, CLRATNO);
3248 ahc_outb(ahc, CLRSINT1, CLRREQINIT);
3251 printk(" byte 0x%x\n", ahc->send_msg_perror);
3253 ahc_outb(ahc, SCSIDATL, MSG_PARITY_ERROR);
3257 msgdone = ahc->msgout_index == ahc->msgout_len;
3264 ahc->msgout_index = 0;
3265 ahc_assert_atn(ahc);
3268 lastbyte = ahc->msgout_index == (ahc->msgout_len - 1);
3271 ahc_outb(ahc, CLRSINT1, CLRATNO);
3278 ahc_outb(ahc, CLRSINT1, CLRREQINIT);
3282 ahc->msgout_buf[ahc->msgout_index]);
3284 ahc_outb(ahc, SCSIDATL, ahc->msgout_buf[ahc->msgout_index++]);
3294 ahc_print_devinfo(ahc, &devinfo);
3307 ahc->msgin_index = 0;
3309 && (ahc->send_msg_perror == TRUE
3310 || (ahc->msgout_len != 0
3311 && ahc->msgout_index == 0))) {
3312 ahc->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
3320 ahc->msgin_buf[ahc->msgin_index] = ahc_inb(ahc, SCSIBUSL);
3324 ahc->msgin_buf[ahc->msgin_index]);
3327 message_done = ahc_parse_msg(ahc, &devinfo);
3334 ahc->msgin_index = 0;
3341 if (ahc->msgout_len != 0) {
3344 ahc_print_devinfo(ahc, &devinfo);
3348 ahc_assert_atn(ahc);
3351 ahc->msgin_index++;
3357 ahc_outb(ahc, CLRSINT1, CLRREQINIT);
3358 ahc_inb(ahc, SCSIDATL);
3367 if (ahc->msgout_len == 0)
3376 if ((ahc_inb(ahc, SCSISIGI) & ATNI) != 0
3377 && ahc->msgout_index > 0)
3390 ahc->msg_type = MSG_TYPE_TARGET_MSGOUT;
3391 ahc_outb(ahc, SCSISIGO, P_MESGOUT | BSYO);
3392 ahc->msgin_index = 0;
3394 ahc_inb(ahc, SCSIDATL);
3395 ahc_outb(ahc, SXFRCTL0,
3396 ahc_inb(ahc, SXFRCTL0) | SPIOEN);
3400 msgdone = ahc->msgout_index == ahc->msgout_len;
3402 ahc_outb(ahc, SXFRCTL0,
3403 ahc_inb(ahc, SXFRCTL0) & ~SPIOEN);
3411 ahc_outb(ahc, SXFRCTL0, ahc_inb(ahc, SXFRCTL0) | SPIOEN);
3412 ahc_outb(ahc, SCSIDATL, ahc->msgout_buf[ahc->msgout_index++]);
3424 lastbyte = (ahc_inb(ahc, SCSISIGI) & ATNI) == 0;
3431 ahc_outb(ahc, SXFRCTL0, ahc_inb(ahc, SXFRCTL0) & ~SPIOEN);
3432 ahc->msgin_buf[ahc->msgin_index] = ahc_inb(ahc, SCSIDATL);
3433 msgdone = ahc_parse_msg(ahc, &devinfo);
3444 ahc->msgin_index++;
3447 ahc->msgin_index = 0;
3453 if (ahc->msgout_len != 0) {
3454 ahc_outb(ahc, SCSISIGO, P_MESGIN | BSYO);
3455 ahc_outb(ahc, SXFRCTL0,
3456 ahc_inb(ahc, SXFRCTL0) | SPIOEN);
3457 ahc->msg_type = MSG_TYPE_TARGET_MSGIN;
3458 ahc->msgin_index = 0;
3467 ahc_outb(ahc, SXFRCTL0,
3468 ahc_inb(ahc, SXFRCTL0) | SPIOEN);
3478 ahc_clear_msg_state(ahc);
3479 ahc_outb(ahc, RETURN_1, EXIT_MSG_LOOP);
3481 ahc_outb(ahc, RETURN_1, CONT_MSG_LOOP);
3491 ahc_sent_msg(struct ahc_softc *ahc, ahc_msgtype type, u_int msgval, int full)
3499 while (index < ahc->msgout_len) {
3500 if (ahc->msgout_buf[index] == MSG_EXTENDED) {
3503 end_index = index + 1 + ahc->msgout_buf[index + 1];
3504 if (ahc->msgout_buf[index+2] == msgval
3508 if (ahc->msgout_index > end_index)
3510 } else if (ahc->msgout_index > index)
3514 } else if (ahc->msgout_buf[index] >= MSG_SIMPLE_TASK
3515 && ahc->msgout_buf[index] <= MSG_IGN_WIDE_RESIDUE) {
3522 && ahc->msgout_buf[index] == msgval
3523 && ahc->msgout_index > index)
3538 ahc_parse_msg(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
3550 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, devinfo->our_scsiid,
3565 switch (ahc->msgin_buf[0]) {
3578 response = ahc_handle_msg_reject(ahc, devinfo);
3586 if (ahc->msgin_index < 2)
3588 switch (ahc->msgin_buf[2]) {
3597 if (ahc->msgin_buf[1] != MSG_EXT_SDTR_LEN) {
3609 if (ahc->msgin_index < (MSG_EXT_SDTR_LEN + 1))
3612 period = ahc->msgin_buf[3];
3614 saved_offset = offset = ahc->msgin_buf[4];
3615 syncrate = ahc_devlimited_syncrate(ahc, tinfo, &period,
3618 ahc_validate_offset(ahc, tinfo, syncrate, &offset,
3625 ahc_name(ahc), devinfo->channel,
3627 ahc->msgin_buf[3], saved_offset,
3630 ahc_set_syncrate(ahc, devinfo,
3641 if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_SDTR, TRUE)) {
3655 ahc_name(ahc), devinfo->channel,
3658 ahc->msgout_index = 0;
3659 ahc->msgout_len = 0;
3660 ahc_construct_sdtr(ahc, devinfo,
3662 ahc->msgout_index = 0;
3675 if (ahc->msgin_buf[1] != MSG_EXT_WDTR_LEN) {
3687 if (ahc->msgin_index < (MSG_EXT_WDTR_LEN + 1))
3690 bus_width = ahc->msgin_buf[3];
3692 ahc_validate_width(ahc, tinfo, &bus_width,
3697 ahc_name(ahc), devinfo->channel,
3702 if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_WDTR, TRUE)) {
3713 ahc_name(ahc), devinfo->channel,
3726 ahc_name(ahc), devinfo->channel,
3729 ahc->msgout_index = 0;
3730 ahc->msgout_len = 0;
3731 ahc_construct_wdtr(ahc, devinfo, bus_width);
3732 ahc->msgout_index = 0;
3745 ahc_update_neg_request(ahc, devinfo, tstate,
3747 ahc_set_width(ahc, devinfo, bus_width,
3755 ahc->msgout_index = 0;
3756 ahc->msgout_len = 0;
3757 ahc_build_transfer_msg(ahc, devinfo);
3758 ahc->msgout_index = 0;
3775 if (ahc->msgin_buf[1] != MSG_EXT_PPR_LEN) {
3787 if (ahc->msgin_index < (MSG_EXT_PPR_LEN + 1))
3790 period = ahc->msgin_buf[3];
3791 offset = ahc->msgin_buf[5];
3792 bus_width = ahc->msgin_buf[6];
3794 ppr_options = ahc->msgin_buf[7];
3815 ahc_validate_width(ahc, tinfo, &bus_width,
3817 syncrate = ahc_devlimited_syncrate(ahc, tinfo, &period,
3820 ahc_validate_offset(ahc, tinfo, syncrate,
3824 if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_PPR, TRUE)) {
3844 ahc_name(ahc), devinfo->channel,
3849 ahc_name(ahc), devinfo->channel,
3851 ahc->msgout_index = 0;
3852 ahc->msgout_len = 0;
3853 ahc_construct_ppr(ahc, devinfo, period, offset,
3855 ahc->msgout_index = 0;
3863 ahc_name(ahc), devinfo->channel,
3865 saved_width, ahc->msgin_buf[3],
3869 ahc_set_width(ahc, devinfo, bus_width,
3872 ahc_set_syncrate(ahc, devinfo,
3889 ahc_handle_devreset(ahc, devinfo,
3893 ahc_restart(ahc);
3908 if (ahc->msgin_buf[0] == MSG_ABORT_TAG)
3909 tag = ahc_inb(ahc, INITIATOR_TAG);
3910 ahc_abort_scbs(ahc, devinfo->target, devinfo->channel,
3914 tstate = ahc->enabled_targets[devinfo->our_scsiid];
3920 ahc_queue_lstate_event(ahc, lstate,
3922 ahc->msgin_buf[0],
3924 ahc_send_lstate_events(ahc, lstate);
3927 ahc_restart(ahc);
3942 ahc->msgout_index = 0;
3943 ahc->msgout_len = 1;
3944 ahc->msgout_buf[0] = MSG_MESSAGE_REJECT;
3951 ahc->msgout_len = 0;
3960 ahc_handle_msg_reject(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
3975 scb_index = ahc_inb(ahc, SCB_TAG);
3976 scb = ahc_lookup_scb(ahc, scb_index);
3977 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel,
3981 last_msg = ahc_inb(ahc, LAST_MSG);
3983 if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_PPR, /*full*/FALSE)) {
3991 ahc_name(ahc), devinfo->channel,
3997 ahc->msgout_index = 0;
3998 ahc->msgout_len = 0;
3999 ahc_build_transfer_msg(ahc, devinfo);
4000 ahc->msgout_index = 0;
4002 } else if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_WDTR, /*full*/FALSE)) {
4006 "8bit transfers\n", ahc_name(ahc),
4008 ahc_set_width(ahc, devinfo, MSG_EXT_WDTR_BUS_8_BIT,
4021 ahc->msgout_index = 0;
4022 ahc->msgout_len = 0;
4023 ahc_build_transfer_msg(ahc, devinfo);
4024 ahc->msgout_index = 0;
4027 } else if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_SDTR, /*full*/FALSE)) {
4029 ahc_set_syncrate(ahc, devinfo, /*syncrate*/NULL, /*period*/0,
4035 ahc_name(ahc), devinfo->channel,
4045 "Performing non-tagged I/O\n", ahc_name(ahc),
4047 ahc_set_tags(ahc, scb->io_ctx, devinfo, AHC_QUEUE_NONE);
4052 ahc_name(ahc), devinfo->channel, devinfo->target,
4055 ahc_set_tags(ahc, scb->io_ctx, devinfo, AHC_QUEUE_BASIC);
4063 ahc_outb(ahc, SCB_CONTROL,
4064 ahc_inb(ahc, SCB_CONTROL) & mask);
4068 ahc_outb(ahc, MSG_OUT, MSG_IDENTIFYFLAG);
4069 ahc_assert_atn(ahc);
4075 if ((ahc->flags & AHC_SCB_BTT) == 0) {
4079 &(ahc->untagged_queues[devinfo->target_offset]);
4083 ahc_busy_tcl(ahc, BUILD_TCL(scb->hscb->scsiid, devinfo->lun),
4091 ahc_search_qinfifo(ahc, SCB_GET_TARGET(ahc, scb),
4092 SCB_GET_CHANNEL(ahc, scb),
4101 ahc_name(ahc), devinfo->channel, devinfo->target,
4111 ahc_handle_ign_wide_residue(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
4116 scb_index = ahc_inb(ahc, SCB_TAG);
4117 scb = ahc_lookup_scb(ahc, scb_index);
4118 if ((ahc_inb(ahc, SEQ_FLAGS) & DPHASE) == 0
4134 sgptr = ahc_inb(ahc, SCB_RESIDUAL_SGPTR);
4136 && (ahc_inb(ahc, SCB_LUN) & SCB_XFERLEN_ODD) != 0) {
4150 sgptr = ahc_inl(ahc, SCB_RESIDUAL_SGPTR);
4151 data_cnt = ahc_inl(ahc, SCB_RESIDUAL_DATACNT);
4162 data_addr = ahc_inl(ahc, SHADDR);
4196 ahc_outl(ahc, SCB_RESIDUAL_SGPTR, sgptr);
4197 ahc_outl(ahc, SCB_RESIDUAL_DATACNT, data_cnt);
4204 ahc_outb(ahc, SCB_LUN,
4205 ahc_inb(ahc, SCB_LUN) ^ SCB_XFERLEN_ODD);
4216 ahc_reinitialize_dataptrs(struct ahc_softc *ahc)
4225 scb_index = ahc_inb(ahc, SCB_TAG);
4226 scb = ahc_lookup_scb(ahc, scb_index);
4227 sgptr = (ahc_inb(ahc, SCB_RESIDUAL_SGPTR + 3) << 24)
4228 | (ahc_inb(ahc, SCB_RESIDUAL_SGPTR + 2) << 16)
4229 | (ahc_inb(ahc, SCB_RESIDUAL_SGPTR + 1) << 8)
4230 | ahc_inb(ahc, SCB_RESIDUAL_SGPTR);
4238 resid = (ahc_inb(ahc, SCB_RESIDUAL_DATACNT + 2) << 16)
4239 | (ahc_inb(ahc, SCB_RESIDUAL_DATACNT + 1) << 8)
4240 | ahc_inb(ahc, SCB_RESIDUAL_DATACNT);
4245 if ((ahc->flags & AHC_39BIT_ADDRESSING) != 0) {
4248 dscommand1 = ahc_inb(ahc, DSCOMMAND1);
4249 ahc_outb(ahc, DSCOMMAND1, dscommand1 | HADDLDSEL0);
4250 ahc_outb(ahc, HADDR,
4252 ahc_outb(ahc, DSCOMMAND1, dscommand1);
4254 ahc_outb(ahc, HADDR + 3, dataptr >> 24);
4255 ahc_outb(ahc, HADDR + 2, dataptr >> 16);
4256 ahc_outb(ahc, HADDR + 1, dataptr >> 8);
4257 ahc_outb(ahc, HADDR, dataptr);
4258 ahc_outb(ahc, HCNT + 2, resid >> 16);
4259 ahc_outb(ahc, HCNT + 1, resid >> 8);
4260 ahc_outb(ahc, HCNT, resid);
4261 if ((ahc->features & AHC_ULTRA2) == 0) {
4262 ahc_outb(ahc, STCNT + 2, resid >> 16);
4263 ahc_outb(ahc, STCNT + 1, resid >> 8);
4264 ahc_outb(ahc, STCNT, resid);
4272 ahc_handle_devreset(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
4281 found = ahc_abort_scbs(ahc, devinfo->target, devinfo->channel,
4290 tstate = ahc->enabled_targets[devinfo->our_scsiid];
4299 ahc_queue_lstate_event(ahc, lstate, devinfo->our_scsiid,
4301 ahc_send_lstate_events(ahc, lstate);
4309 ahc_set_width(ahc, devinfo, MSG_EXT_WDTR_BUS_8_BIT,
4311 ahc_set_syncrate(ahc, devinfo, /*syncrate*/NULL,
4316 ahc_send_async(ahc, devinfo->channel, devinfo->target,
4321 printk("%s: %s on %c:%d. %d SCBs aborted\n", ahc_name(ahc),
4327 ahc_setup_target_msgin(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
4336 ahc->msgout_index = 0;
4337 ahc->msgout_len = 0;
4340 ahc_build_transfer_msg(ahc, devinfo);
4344 ahc->msgout_index = 0;
4345 ahc->msg_type = MSG_TYPE_TARGET_MSGIN;
4356 struct ahc_softc *ahc;
4360 ahc = kmalloc(sizeof(*ahc), GFP_ATOMIC);
4361 if (!ahc) {
4367 ahc = device_get_softc((device_t)platform_arg);
4369 memset(ahc, 0, sizeof(*ahc));
4370 ahc->seep_config = kmalloc(sizeof(*ahc->seep_config), GFP_ATOMIC);
4371 if (ahc->seep_config == NULL) {
4373 kfree(ahc);
4378 LIST_INIT(&ahc->pending_scbs);
4380 ahc->name = name;
4381 ahc->unit = -1;
4382 ahc->description = NULL;
4383 ahc->channel = 'A';
4384 ahc->channel_b = 'B';
4385 ahc->chip = AHC_NONE;
4386 ahc->features = AHC_FENONE;
4387 ahc->bugs = AHC_BUGNONE;
4388 ahc->flags = AHC_FNONE;
4394 ahc->seqctl = FASTMODE;
4397 TAILQ_INIT(&ahc->untagged_queues[i]);
4398 if (ahc_platform_alloc(ahc, platform_arg) != 0) {
4399 ahc_free(ahc);
4400 ahc = NULL;
4402 return (ahc);
4406 ahc_softc_init(struct ahc_softc *ahc)
4410 if ((ahc->chip & AHC_PCI) == 0)
4411 ahc->unpause = ahc_inb(ahc, HCNTRL) & IRQMS;
4413 ahc->unpause = 0;
4414 ahc->pause = ahc->unpause | PAUSE;
4415 if (ahc->scb_data == NULL) {
4416 ahc->scb_data = kmalloc(sizeof(*ahc->scb_data), GFP_ATOMIC);
4417 if (ahc->scb_data == NULL)
4419 memset(ahc->scb_data, 0, sizeof(*ahc->scb_data));
4426 ahc_set_unit(struct ahc_softc *ahc, int unit)
4428 ahc->unit = unit;
4432 ahc_set_name(struct ahc_softc *ahc, char *name)
4434 if (ahc->name != NULL)
4435 kfree(ahc->name);
4436 ahc->name = name;
4440 ahc_free(struct ahc_softc *ahc)
4444 switch (ahc->init_level) {
4447 ahc_shutdown(ahc);
4450 ahc_dmamap_unload(ahc, ahc->shared_data_dmat,
4451 ahc->shared_data_dmamap);
4454 ahc_dmamem_free(ahc, ahc->shared_data_dmat, ahc->qoutfifo,
4455 ahc->shared_data_dmamap);
4456 ahc_dmamap_destroy(ahc, ahc->shared_data_dmat,
4457 ahc->shared_data_dmamap);
4460 ahc_dma_tag_destroy(ahc, ahc->shared_data_dmat);
4463 ahc_dma_tag_destroy(ahc, ahc->buffer_dmat);
4471 ahc_dma_tag_destroy(ahc, ahc->parent_dmat);
4473 ahc_platform_free(ahc);
4474 ahc_fini_scbdata(ahc);
4478 tstate = ahc->enabled_targets[i];
4497 if (ahc->black_hole != NULL) {
4498 xpt_free_path(ahc->black_hole->path);
4499 kfree(ahc->black_hole);
4502 if (ahc->name != NULL)
4503 kfree(ahc->name);
4504 if (ahc->seep_config != NULL)
4505 kfree(ahc->seep_config);
4507 kfree(ahc);
4515 struct ahc_softc *ahc;
4518 ahc = (struct ahc_softc *)arg;
4521 ahc_reset(ahc, /*reinit*/FALSE);
4522 ahc_outb(ahc, SCSISEQ, 0);
4523 ahc_outb(ahc, SXFRCTL0, 0);
4524 ahc_outb(ahc, DSPCISTATUS, 0);
4527 ahc_outb(ahc, i, 0);
4540 ahc_reset(struct ahc_softc *ahc, int reinit)
4552 ahc_pause(ahc);
4554 if ((ahc->chip & AHC_CHIPID_MASK) == AHC_AIC7770) {
4561 sblkctl = ahc_inb(ahc, SBLKCTL);
4562 ahc_outb(ahc, SBLKCTL, sblkctl | SELBUSB);
4563 sxfrctl1_b = ahc_inb(ahc, SXFRCTL1);
4564 ahc_outb(ahc, SBLKCTL, sblkctl & ~SELBUSB);
4566 sxfrctl1_a = ahc_inb(ahc, SXFRCTL1);
4568 ahc_outb(ahc, HCNTRL, CHIPRST | ahc->pause);
4579 } while (--wait && !(ahc_inb(ahc, HCNTRL) & CHIPRSTACK));
4583 "Trying to initialize anyway.\n", ahc_name(ahc));
4585 ahc_outb(ahc, HCNTRL, ahc->pause);
4588 sblkctl = ahc_inb(ahc, SBLKCTL) & (SELBUSB|SELWIDE);
4590 if ((ahc->chip & AHC_PCI) != 0)
4598 ahc->features |= AHC_WIDE;
4602 ahc->features |= AHC_TWIN;
4617 if ((ahc->features & AHC_TWIN) != 0) {
4620 sblkctl = ahc_inb(ahc, SBLKCTL);
4621 ahc_outb(ahc, SBLKCTL, sblkctl | SELBUSB);
4622 ahc_outb(ahc, SXFRCTL1, sxfrctl1_b);
4623 ahc_outb(ahc, SBLKCTL, sblkctl & ~SELBUSB);
4625 ahc_outb(ahc, SXFRCTL1, sxfrctl1_a);
4633 error = ahc->bus_chip_init(ahc);
4636 ahc_dumpseq(ahc);
4646 ahc_probe_scbs(struct ahc_softc *ahc) {
4651 ahc_outb(ahc, SCBPTR, i);
4652 ahc_outb(ahc, SCB_BASE, i);
4653 if (ahc_inb(ahc, SCB_BASE) != i)
4655 ahc_outb(ahc, SCBPTR, 0);
4656 if (ahc_inb(ahc, SCB_BASE) != 0)
4672 ahc_build_free_scb_list(struct ahc_softc *ahc)
4678 if ((ahc->flags & AHC_LSCBS_ENABLED) != 0)
4681 for (i = 0; i < ahc->scb_data->maxhscbs; i++) {
4684 ahc_outb(ahc, SCBPTR, i);
4692 ahc_outb(ahc, SCB_BASE+j, 0xFF);
4695 ahc_outb(ahc, SCB_CONTROL, 0);
4698 if ((ahc->flags & AHC_PAGESCBS) != 0)
4699 ahc_outb(ahc, SCB_NEXT, i+1);
4701 ahc_outb(ahc, SCB_NEXT, SCB_LIST_NULL);
4704 ahc_outb(ahc, SCB_TAG, SCB_LIST_NULL);
4705 ahc_outb(ahc, SCB_SCSIID, 0xFF);
4706 ahc_outb(ahc, SCB_LUN, 0xFF);
4709 if ((ahc->flags & AHC_PAGESCBS) != 0) {
4711 ahc_outb(ahc, FREE_SCBH, 0);
4714 ahc_outb(ahc, FREE_SCBH, SCB_LIST_NULL);
4718 ahc_outb(ahc, SCBPTR, i-1);
4719 ahc_outb(ahc, SCB_NEXT, SCB_LIST_NULL);
4723 ahc_init_scbdata(struct ahc_softc *ahc)
4727 scb_data = ahc->scb_data;
4739 scb_data->maxhscbs = ahc_probe_scbs(ahc);
4740 if (ahc->scb_data->maxhscbs == 0) {
4741 printk("%s: No SCB space found\n", ahc_name(ahc));
4756 if (ahc_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/1,
4771 if (ahc_dmamem_alloc(ahc, scb_data->hscb_dmat,
4780 ahc_dmamap_load(ahc, scb_data->hscb_dmat, scb_data->hscb_dmamap,
4788 if (ahc_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/1,
4803 if (ahc_dmamem_alloc(ahc, scb_data->sense_dmat,
4812 ahc_dmamap_load(ahc, scb_data->sense_dmat, scb_data->sense_dmamap,
4820 if (ahc_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/8,
4836 ahc_alloc_scbs(ahc);
4841 ahc_name(ahc));
4848 ahc->next_queued_scb = ahc_get_scb(ahc);
4861 ahc_fini_scbdata(struct ahc_softc *ahc)
4865 scb_data = ahc->scb_data;
4877 ahc_dmamap_unload(ahc, scb_data->sg_dmat,
4879 ahc_dmamem_free(ahc, scb_data->sg_dmat,
4884 ahc_dma_tag_destroy(ahc, scb_data->sg_dmat);
4887 ahc_dmamap_unload(ahc, scb_data->sense_dmat,
4890 ahc_dmamem_free(ahc, scb_data->sense_dmat, scb_data->sense,
4892 ahc_dmamap_destroy(ahc, scb_data->sense_dmat,
4895 ahc_dma_tag_destroy(ahc, scb_data->sense_dmat);
4897 ahc_dmamap_unload(ahc, scb_data->hscb_dmat,
4900 ahc_dmamem_free(ahc, scb_data->hscb_dmat, scb_data->hscbs,
4902 ahc_dmamap_destroy(ahc, scb_data->hscb_dmat,
4905 ahc_dma_tag_destroy(ahc, scb_data->hscb_dmat);
4915 ahc_alloc_scbs(struct ahc_softc *ahc)
4925 scb_data = ahc->scb_data;
4938 if (ahc_dmamem_alloc(ahc, scb_data->sg_dmat,
4947 ahc_dmamap_load(ahc, scb_data->sg_dmat, sg_map->sg_dmamap,
4972 next_scb->ahc_softc = ahc;
4975 error = ahc_dmamap_create(ahc, ahc->buffer_dmat, /*flags*/0,
4981 next_scb->hscb->tag = ahc->scb_data->numscbs;
4982 SLIST_INSERT_HEAD(&ahc->scb_data->free_scbs,
4987 ahc->scb_data->numscbs++;
4992 ahc_controller_info(struct ahc_softc *ahc, char *buf)
4996 len = sprintf(buf, "%s: ", ahc_chip_names[ahc->chip & AHC_CHIPID_MASK]);
4998 if ((ahc->features & AHC_TWIN) != 0)
5001 ahc->our_id, ahc->our_id_b,
5002 (ahc->flags & AHC_PRIMARY_CHANNEL) + 'A');
5008 if ((ahc->features & AHC_ULTRA) != 0) {
5010 } else if ((ahc->features & AHC_DT) != 0) {
5012 } else if ((ahc->features & AHC_ULTRA2) != 0) {
5015 if ((ahc->features & AHC_WIDE) != 0) {
5021 speed, type, ahc->channel, ahc->our_id);
5025 if ((ahc->flags & AHC_PAGESCBS) != 0)
5027 ahc->scb_data->maxhscbs, AHC_MAX_QUEUE);
5029 sprintf(buf, "%d SCBs", ahc->scb_data->maxhscbs);
5033 ahc_chip_init(struct ahc_softc *ahc)
5042 ahc_outb(ahc, SEQ_FLAGS, 0);
5043 ahc_outb(ahc, SEQ_FLAGS2, 0);
5046 if (ahc->features & AHC_TWIN) {
5051 ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) | SELBUSB);
5052 term = (ahc->flags & AHC_TERM_ENB_B) != 0 ? STPWEN : 0;
5053 ahc_outb(ahc, SCSIID, ahc->our_id_b);
5054 scsi_conf = ahc_inb(ahc, SCSICONF + 1);
5055 ahc_outb(ahc, SXFRCTL1, (scsi_conf & (ENSPCHK|STIMESEL))
5056 |term|ahc->seltime_b|ENSTIMER|ACTNEGEN);
5057 if ((ahc->features & AHC_ULTRA2) != 0)
5058 ahc_outb(ahc, SIMODE0, ahc_inb(ahc, SIMODE0)|ENIOERR);
5059 ahc_outb(ahc, SIMODE1, ENSELTIMO|ENSCSIRST|ENSCSIPERR);
5060 ahc_outb(ahc, SXFRCTL0, DFON|SPIOEN);
5063 ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) & ~SELBUSB);
5065 term = (ahc->flags & AHC_TERM_ENB_A) != 0 ? STPWEN : 0;
5066 if ((ahc->features & AHC_ULTRA2) != 0)
5067 ahc_outb(ahc, SCSIID_ULTRA2, ahc->our_id);
5069 ahc_outb(ahc, SCSIID, ahc->our_id);
5070 scsi_conf = ahc_inb(ahc, SCSICONF);
5071 ahc_outb(ahc, SXFRCTL1, (scsi_conf & (ENSPCHK|STIMESEL))
5072 |term|ahc->seltime
5074 if ((ahc->features & AHC_ULTRA2) != 0)
5075 ahc_outb(ahc, SIMODE0, ahc_inb(ahc, SIMODE0)|ENIOERR);
5076 ahc_outb(ahc, SIMODE1, ENSELTIMO|ENSCSIRST|ENSCSIPERR);
5077 ahc_outb(ahc, SXFRCTL0, DFON|SPIOEN);
5081 ahc_unbusy_tcl(ahc, BUILD_TCL(i << 4, 0));
5082 if ((ahc->flags & AHC_SCB_BTT) != 0) {
5090 ahc_unbusy_tcl(ahc, BUILD_TCL(i << 4, lun));
5096 ahc->qoutfifo[i] = SCB_LIST_NULL;
5097 ahc_sync_qoutfifo(ahc, BUS_DMASYNC_PREREAD);
5100 ahc->qinfifo[i] = SCB_LIST_NULL;
5102 if ((ahc->features & AHC_MULTI_TID) != 0) {
5103 ahc_outb(ahc, TARGID, 0);
5104 ahc_outb(ahc, TARGID + 1, 0);
5110 physaddr = ahc->scb_data->hscb_busaddr;
5111 ahc_outb(ahc, HSCB_ADDR, physaddr & 0xFF);
5112 ahc_outb(ahc, HSCB_ADDR + 1, (physaddr >> 8) & 0xFF);
5113 ahc_outb(ahc, HSCB_ADDR + 2, (physaddr >> 16) & 0xFF);
5114 ahc_outb(ahc, HSCB_ADDR + 3, (physaddr >> 24) & 0xFF);
5116 physaddr = ahc->shared_data_busaddr;
5117 ahc_outb(ahc, SHARED_DATA_ADDR, physaddr & 0xFF);
5118 ahc_outb(ahc, SHARED_DATA_ADDR + 1, (physaddr >> 8) & 0xFF);
5119 ahc_outb(ahc, SHARED_DATA_ADDR + 2, (physaddr >> 16) & 0xFF);
5120 ahc_outb(ahc, SHARED_DATA_ADDR + 3, (physaddr >> 24) & 0xFF);
5127 ahc_outb(ahc, CMDSIZE_TABLE, 5);
5128 ahc_outb(ahc, CMDSIZE_TABLE + 1, 9);
5129 ahc_outb(ahc, CMDSIZE_TABLE + 2, 9);
5130 ahc_outb(ahc, CMDSIZE_TABLE + 3, 0);
5131 ahc_outb(ahc, CMDSIZE_TABLE + 4, 15);
5132 ahc_outb(ahc, CMDSIZE_TABLE + 5, 11);
5133 ahc_outb(ahc, CMDSIZE_TABLE + 6, 0);
5134 ahc_outb(ahc, CMDSIZE_TABLE + 7, 0);
5136 if ((ahc->features & AHC_HS_MAILBOX) != 0)
5137 ahc_outb(ahc, HS_MAILBOX, 0);
5140 if ((ahc->features & AHC_TARGETMODE) != 0) {
5141 ahc->tqinfifonext = 1;
5142 ahc_outb(ahc, KERNEL_TQINPOS, ahc->tqinfifonext - 1);
5143 ahc_outb(ahc, TQINPOS, ahc->tqinfifonext);
5145 ahc->qinfifonext = 0;
5146 ahc->qoutfifonext = 0;
5147 if ((ahc->features & AHC_QUEUE_REGS) != 0) {
5148 ahc_outb(ahc, QOFF_CTLSTA, SCB_QSIZE_256);
5149 ahc_outb(ahc, HNSCB_QOFF, ahc->qinfifonext);
5150 ahc_outb(ahc, SNSCB_QOFF, ahc->qinfifonext);
5151 ahc_outb(ahc, SDSCB_QOFF, 0);
5153 ahc_outb(ahc, KERNEL_QINPOS, ahc->qinfifonext);
5154 ahc_outb(ahc, QINPOS, ahc->qinfifonext);
5155 ahc_outb(ahc, QOUTPOS, ahc->qoutfifonext);
5159 ahc_outb(ahc, WAITING_SCBH, SCB_LIST_NULL);
5162 ahc_outb(ahc, DISCONNECTED_SCBH, SCB_LIST_NULL);
5165 ahc_outb(ahc, MSG_OUT, MSG_NOOP);
5173 if ((ahc->flags & AHC_INITIATORROLE) != 0)
5175 ahc_outb(ahc, SCSISEQ_TEMPLATE, scsiseq_template);
5178 ahc_build_free_scb_list(ahc);
5183 ahc_outb(ahc, NEXT_QUEUED_SCB, ahc->next_queued_scb->hscb->tag);
5191 ahc_name(ahc));
5193 error = ahc_loadseq(ahc);
5197 if ((ahc->features & AHC_ULTRA2) != 0) {
5208 (ahc_inb(ahc, SBLKCTL) & (ENAB40|ENAB20)) == 0 && wait;
5212 ahc_restart(ahc);
5220 ahc_init(struct ahc_softc *ahc)
5232 ahc->flags |= AHC_SEQUENCER_DEBUG;
5241 printk (" 0x%x", ahc_inb(ahc, i));
5243 if ((ahc->features & AHC_MORE_SRAM) != 0) {
5248 printk (" 0x%x", ahc_inb(ahc, i));
5256 ahc_outb(ahc, CLRINT, CLRPARERR);
5257 ahc_outb(ahc, CLRINT, CLRBRKADRINT);
5264 if ((ahc->flags & AHC_USEDEFAULTS) != 0)
5265 ahc->our_id = ahc->our_id_b = 7;
5270 ahc->flags |= AHC_INITIATORROLE;
5275 if ((AHC_TMODE_ENABLE & (0x1 << ahc->unit)) == 0)
5276 ahc->features &= ~AHC_TARGETMODE;
5280 if (ahc_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/1,
5282 /*lowaddr*/ahc->flags & AHC_39BIT_ADDRESSING
5291 &ahc->buffer_dmat) != 0) {
5296 ahc->init_level++;
5308 if ((ahc->features & AHC_TARGETMODE) != 0)
5311 if (ahc_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/1,
5319 /*flags*/0, &ahc->shared_data_dmat) != 0) {
5323 ahc->init_level++;
5326 if (ahc_dmamem_alloc(ahc, ahc->shared_data_dmat,
5327 (void **)&ahc->qoutfifo,
5328 BUS_DMA_NOWAIT, &ahc->shared_data_dmamap) != 0) {
5332 ahc->init_level++;
5335 ahc_dmamap_load(ahc, ahc->shared_data_dmat, ahc->shared_data_dmamap,
5336 ahc->qoutfifo, driver_data_size, ahc_dmamap_cb,
5337 &ahc->shared_data_busaddr, /*flags*/0);
5339 if ((ahc->features & AHC_TARGETMODE) != 0) {
5340 ahc->targetcmds = (struct target_cmd *)ahc->qoutfifo;
5341 ahc->qoutfifo = (uint8_t *)&ahc->targetcmds[AHC_TMODE_CMDS];
5342 ahc->dma_bug_buf = ahc->shared_data_busaddr
5346 ahc->targetcmds[i].cmd_valid = 0;
5347 ahc_sync_tqinfifo(ahc, BUS_DMASYNC_PREREAD);
5348 ahc->qoutfifo = (uint8_t *)&ahc->targetcmds[256];
5350 ahc->qinfifo = &ahc->qoutfifo[256];
5352 ahc->init_level++;
5355 if (ahc->scb_data->maxhscbs == 0)
5356 if (ahc_init_scbdata(ahc) != 0)
5364 if (ahc_alloc_tstate(ahc, ahc->our_id, 'A') == NULL) {
5366 "Failing attach\n", ahc_name(ahc));
5370 if ((ahc->features & AHC_TWIN) != 0) {
5371 if (ahc_alloc_tstate(ahc, ahc->our_id_b, 'B') == NULL) {
5373 "Failing attach\n", ahc_name(ahc));
5378 if (ahc->scb_data->maxhscbs < AHC_SCB_MAX_ALLOC) {
5379 ahc->flags |= AHC_PAGESCBS;
5381 ahc->flags &= ~AHC_PAGESCBS;
5388 ahc_name(ahc),
5399 if (ahc->features & AHC_TWIN) {
5400 scsi_conf = ahc_inb(ahc, SCSICONF + 1);
5402 && (ahc->flags & AHC_INITIATORROLE) != 0)
5403 ahc->flags |= AHC_RESET_BUS_B;
5406 scsi_conf = ahc_inb(ahc, SCSICONF);
5408 && (ahc->flags & AHC_INITIATORROLE) != 0)
5409 ahc->flags |= AHC_RESET_BUS_A;
5415 if ((ahc->flags & AHC_USEDEFAULTS) != 0) {
5417 "device parameters\n", ahc_name(ahc));
5418 ahc->flags |= AHC_EXTENDED_TRANS_A|AHC_EXTENDED_TRANS_B|
5421 if ((ahc->features & AHC_ULTRA) != 0)
5424 discenable = ~((ahc_inb(ahc, DISC_DSB + 1) << 8)
5425 | ahc_inb(ahc, DISC_DSB));
5426 if ((ahc->features & (AHC_ULTRA|AHC_ULTRA2)) != 0)
5427 ultraenb = (ahc_inb(ahc, ULTRA_ENB + 1) << 8)
5428 | ahc_inb(ahc, ULTRA_ENB);
5431 if ((ahc->features & (AHC_WIDE|AHC_TWIN)) == 0)
5442 our_id = ahc->our_id;
5444 if (i > 7 && (ahc->features & AHC_TWIN) != 0) {
5446 our_id = ahc->our_id_b;
5449 tinfo = ahc_fetch_transinfo(ahc, channel, our_id,
5453 if (ahc->flags & AHC_USEDEFAULTS) {
5454 if ((ahc->features & AHC_WIDE) != 0)
5468 scsirate = ahc_inb(ahc, TARG_SCSIRATE + i);
5470 if ((ahc->features & AHC_ULTRA2) != 0) {
5485 offset = ahc_inb(ahc, TARG_OFFSET + i);
5490 if ((ahc->features & AHC_DT) != 0)
5493 ahc_find_period(ahc, scsirate, maxsync);
5499 && (ahc->features & AHC_DT) != 0)
5510 ahc_find_period(ahc, scsirate,
5520 && (ahc->features & AHC_WIDE) != 0)
5523 if ((ahc->features & AHC_DT) != 0)
5534 ahc->user_discenable = discenable;
5535 ahc->user_tagenable = tagenable;
5537 return (ahc->bus_chip_init(ahc));
5541 ahc_intr_enable(struct ahc_softc *ahc, int enable)
5545 hcntrl = ahc_inb(ahc, HCNTRL);
5547 ahc->pause &= ~INTEN;
5548 ahc->unpause &= ~INTEN;
5551 ahc->pause |= INTEN;
5552 ahc->unpause |= INTEN;
5554 ahc_outb(ahc, HCNTRL, hcntrl);
5565 ahc_pause_and_flushwork(struct ahc_softc *ahc)
5572 ahc->flags |= AHC_ALL_INTERRUPTS;
5576 ahc_unpause(ahc);
5583 ahc_intr(ahc);
5584 ahc_pause(ahc);
5586 ahc_outb(ahc, SCSISEQ, ahc_inb(ahc, SCSISEQ) & ~ENSELO);
5587 intstat = ahc_inb(ahc, INTSTAT);
5589 ahc_clear_critical_section(ahc);
5590 intstat = ahc_inb(ahc, INTSTAT);
5593 && (intstat != 0xFF || (ahc->features & AHC_REMOVABLE) == 0)
5595 || (ahc_inb(ahc, SSTAT0) & (SELDO|SELINGO)) != 0));
5598 ahc_inb(ahc, INTSTAT));
5600 ahc_platform_flushwork(ahc);
5601 ahc->flags &= ~AHC_ALL_INTERRUPTS;
5606 ahc_suspend(struct ahc_softc *ahc)
5609 ahc_pause_and_flushwork(ahc);
5611 if (LIST_FIRST(&ahc->pending_scbs) != NULL) {
5612 ahc_unpause(ahc);
5617 if (ahc->pending_device != NULL) {
5618 ahc_unpause(ahc);
5622 ahc_shutdown(ahc);
5627 ahc_resume(struct ahc_softc *ahc)
5630 ahc_reset(ahc, /*reinit*/TRUE);
5631 ahc_intr_enable(ahc, TRUE);
5632 ahc_restart(ahc);
5642 ahc_index_busy_tcl(struct ahc_softc *ahc, u_int tcl)
5647 if ((ahc->flags & AHC_SCB_BTT) != 0) {
5650 saved_scbptr = ahc_inb(ahc, SCBPTR);
5651 ahc_outb(ahc, SCBPTR, TCL_LUN(tcl));
5652 scbid = ahc_inb(ahc, SCB_64_BTT + TCL_TARGET_OFFSET(tcl));
5653 ahc_outb(ahc, SCBPTR, saved_scbptr);
5656 scbid = ahc_inb(ahc, BUSY_TARGETS + target_offset);
5663 ahc_unbusy_tcl(struct ahc_softc *ahc, u_int tcl)
5667 if ((ahc->flags & AHC_SCB_BTT) != 0) {
5670 saved_scbptr = ahc_inb(ahc, SCBPTR);
5671 ahc_outb(ahc, SCBPTR, TCL_LUN(tcl));
5672 ahc_outb(ahc, SCB_64_BTT+TCL_TARGET_OFFSET(tcl), SCB_LIST_NULL);
5673 ahc_outb(ahc, SCBPTR, saved_scbptr);
5676 ahc_outb(ahc, BUSY_TARGETS + target_offset, SCB_LIST_NULL);
5681 ahc_busy_tcl(struct ahc_softc *ahc, u_int tcl, u_int scbid)
5685 if ((ahc->flags & AHC_SCB_BTT) != 0) {
5688 saved_scbptr = ahc_inb(ahc, SCBPTR);
5689 ahc_outb(ahc, SCBPTR, TCL_LUN(tcl));
5690 ahc_outb(ahc, SCB_64_BTT + TCL_TARGET_OFFSET(tcl), scbid);
5691 ahc_outb(ahc, SCBPTR, saved_scbptr);
5694 ahc_outb(ahc, BUSY_TARGETS + target_offset, scbid);
5700 ahc_match_scb(struct ahc_softc *ahc, struct scb *scb, int target,
5703 int targ = SCB_GET_TARGET(ahc, scb);
5704 char chan = SCB_GET_CHANNEL(ahc, scb);
5736 ahc_freeze_devq(struct ahc_softc *ahc, struct scb *scb)
5742 target = SCB_GET_TARGET(ahc, scb);
5744 channel = SCB_GET_CHANNEL(ahc, scb);
5746 ahc_search_qinfifo(ahc, target, channel, lun,
5750 ahc_platform_freeze_devq(ahc, scb);
5754 ahc_qinfifo_requeue_tail(struct ahc_softc *ahc, struct scb *scb)
5759 if (ahc_qinfifo_count(ahc) != 0) {
5763 prev_pos = ahc->qinfifonext - 1;
5764 prev_tag = ahc->qinfifo[prev_pos];
5765 prev_scb = ahc_lookup_scb(ahc, prev_tag);
5767 ahc_qinfifo_requeue(ahc, prev_scb, scb);
5768 if ((ahc->features & AHC_QUEUE_REGS) != 0) {
5769 ahc_outb(ahc, HNSCB_QOFF, ahc->qinfifonext);
5771 ahc_outb(ahc, KERNEL_QINPOS, ahc->qinfifonext);
5776 ahc_qinfifo_requeue(struct ahc_softc *ahc, struct scb *prev_scb,
5780 ahc_outb(ahc, NEXT_QUEUED_SCB, scb->hscb->tag);
5783 ahc_sync_scb(ahc, prev_scb,
5786 ahc->qinfifo[ahc->qinfifonext++] = scb->hscb->tag;
5787 scb->hscb->next = ahc->next_queued_scb->hscb->tag;
5788 ahc_sync_scb(ahc, scb, BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
5792 ahc_qinfifo_count(struct ahc_softc *ahc)
5797 if ((ahc->features & AHC_QUEUE_REGS) != 0) {
5798 qinpos = ahc_inb(ahc, SNSCB_QOFF);
5799 ahc_outb(ahc, SNSCB_QOFF, qinpos);
5801 qinpos = ahc_inb(ahc, QINPOS);
5802 diff = ahc->qinfifonext - qinpos;
5807 ahc_search_qinfifo(struct ahc_softc *ahc, int target, char channel,
5822 qintail = ahc->qinfifonext;
5823 have_qregs = (ahc->features & AHC_QUEUE_REGS) != 0;
5825 qinstart = ahc_inb(ahc, SNSCB_QOFF);
5826 ahc_outb(ahc, SNSCB_QOFF, qinstart);
5828 qinstart = ahc_inb(ahc, QINPOS);
5838 ahc_freeze_untagged_queues(ahc);
5845 ahc->qinfifonext = qinpos;
5846 ahc_outb(ahc, NEXT_QUEUED_SCB, ahc->next_queued_scb->hscb->tag);
5849 scb = ahc_lookup_scb(ahc, ahc->qinfifo[qinpos]);
5852 qinpos, ahc->qinfifo[qinpos]);
5856 if (ahc_match_scb(ahc, scb, target, channel, lun, tag, role)) {
5875 ahc_done(ahc, scb);
5882 ahc_qinfifo_requeue(ahc, prev_scb, scb);
5887 ahc_qinfifo_requeue(ahc, prev_scb, scb);
5893 if ((ahc->features & AHC_QUEUE_REGS) != 0) {
5894 ahc_outb(ahc, HNSCB_QOFF, ahc->qinfifonext);
5896 ahc_outb(ahc, KERNEL_QINPOS, ahc->qinfifonext);
5901 && (qinstart != ahc->qinfifonext)) {
5914 scb = ahc_lookup_scb(ahc, ahc->qinfifo[qinstart]);
5918 found, qinstart, ahc->qinfifonext);
5928 ahc->scb_data->scbindex[scb->hscb->tag] = NULL;
5929 ahc_swap_with_next_hscb(ahc, scb);
5931 ahc->qinfifo[qinstart] = scb->hscb->tag;
5934 ahc_outb(ahc, NEXT_QUEUED_SCB, scb->hscb->tag);
5937 qintail = ahc->qinfifonext - 1;
5938 scb = ahc_lookup_scb(ahc, ahc->qinfifo[qintail]);
5939 scb->hscb->next = ahc->next_queued_scb->hscb->tag;
5945 curscbptr = ahc_inb(ahc, SCBPTR);
5946 next = ahc_inb(ahc, WAITING_SCBH); /* Start at head of list. */
5952 ahc_outb(ahc, SCBPTR, next);
5953 scb_index = ahc_inb(ahc, SCB_TAG);
5954 if (scb_index >= ahc->scb_data->numscbs) {
5957 scb_index, ahc->scb_data->numscbs);
5958 ahc_dump_card_state(ahc);
5961 scb = ahc_lookup_scb(ahc, scb_index);
5967 if (ahc_match_scb(ahc, scb, target, channel,
5988 ahc_done(ahc, scb);
5992 next = ahc_rem_wscb(ahc, next, prev);
5996 next = ahc_inb(ahc, SCB_NEXT);
6002 next = ahc_inb(ahc, SCB_NEXT);
6005 ahc_outb(ahc, SCBPTR, curscbptr);
6007 found += ahc_search_untagged_queues(ahc, /*ahc_io_ctx_t*/NULL, target,
6011 ahc_release_untagged_queues(ahc);
6016 ahc_search_untagged_queues(struct ahc_softc *ahc, ahc_io_ctx_t ctx,
6030 ahc_freeze_untagged_queues(ahc);
6035 if ((ahc->flags & AHC_SCB_BTT) == 0) {
6053 untagged_q = &(ahc->untagged_queues[i]);
6072 if (ahc_match_scb(ahc, scb, target, channel, lun,
6095 ahc_done(ahc, scb);
6109 ahc_release_untagged_queues(ahc);
6114 ahc_search_disc_list(struct ahc_softc *ahc, int target, char channel,
6125 next = ahc_inb(ahc, DISCONNECTED_SCBH);
6130 active_scb = ahc_inb(ahc, SCBPTR);
6138 ahc_outb(ahc, SCBPTR, next);
6139 scb_index = ahc_inb(ahc, SCB_TAG);
6140 if (scb_index >= ahc->scb_data->numscbs) {
6143 scb_index, ahc->scb_data->numscbs);
6144 ahc_dump_card_state(ahc);
6153 scbp = ahc_lookup_scb(ahc, scb_index);
6154 if (ahc_match_scb(ahc, scbp, target, channel, lun,
6159 ahc_rem_scb_from_disc_list(ahc, prev, next);
6162 next = ahc_inb(ahc, SCB_NEXT);
6168 next = ahc_inb(ahc, SCB_NEXT);
6172 ahc_outb(ahc, SCBPTR, active_scb);
6181 ahc_rem_scb_from_disc_list(struct ahc_softc *ahc, u_int prev, u_int scbptr)
6185 ahc_outb(ahc, SCBPTR, scbptr);
6186 next = ahc_inb(ahc, SCB_NEXT);
6188 ahc_outb(ahc, SCB_CONTROL, 0);
6190 ahc_add_curscb_to_free_list(ahc);
6193 ahc_outb(ahc, SCBPTR, prev);
6194 ahc_outb(ahc, SCB_NEXT, next);
6196 ahc_outb(ahc, DISCONNECTED_SCBH, next);
6207 ahc_add_curscb_to_free_list(struct ahc_softc *ahc)
6213 ahc_outb(ahc, SCB_TAG, SCB_LIST_NULL);
6215 if ((ahc->flags & AHC_PAGESCBS) != 0) {
6216 ahc_outb(ahc, SCB_NEXT, ahc_inb(ahc, FREE_SCBH));
6217 ahc_outb(ahc, FREE_SCBH, ahc_inb(ahc, SCBPTR));
6226 ahc_rem_wscb(struct ahc_softc *ahc, u_int scbpos, u_int prev)
6234 curscb = ahc_inb(ahc, SCBPTR);
6235 ahc_outb(ahc, SCBPTR, scbpos);
6236 next = ahc_inb(ahc, SCB_NEXT);
6239 ahc_outb(ahc, SCB_CONTROL, 0);
6241 ahc_add_curscb_to_free_list(ahc);
6246 ahc_outb(ahc, WAITING_SCBH, next);
6252 ahc_outb(ahc, SCSISEQ, (ahc_inb(ahc, SCSISEQ) & ~ENSELO));
6258 ahc_outb(ahc, SCBPTR, prev);
6259 ahc_outb(ahc, SCB_NEXT, next);
6265 ahc_outb(ahc, SCBPTR, curscb);
6277 ahc_abort_scbs(struct ahc_softc *ahc, int target, char channel,
6294 ahc_freeze_untagged_queues(ahc);
6297 active_scb = ahc_inb(ahc, SCBPTR);
6299 found = ahc_search_qinfifo(ahc, target, channel, lun, SCB_LIST_NULL,
6324 if ((ahc->flags & AHC_SCB_BTT) != 0)
6338 scbid = ahc_index_busy_tcl(ahc, tcl);
6339 scbp = ahc_lookup_scb(ahc, scbid);
6341 || ahc_match_scb(ahc, scbp, target, channel,
6344 ahc_unbusy_tcl(ahc, BUILD_TCL(i << 4, j));
6354 ahc_search_disc_list(ahc, target, channel, lun, tag,
6366 for (i = 0; i < ahc->scb_data->maxhscbs; i++) {
6369 ahc_outb(ahc, SCBPTR, i);
6370 scbid = ahc_inb(ahc, SCB_TAG);
6371 scbp = ahc_lookup_scb(ahc, scbid);
6374 && ahc_match_scb(ahc, scbp, target, channel, lun, tag, role)))
6375 ahc_add_curscb_to_free_list(ahc);
6384 scbp_next = LIST_FIRST(&ahc->pending_scbs);
6388 if (ahc_match_scb(ahc, scbp, target, channel, lun, tag, role)) {
6398 ahc_done(ahc, scbp);
6402 ahc_outb(ahc, SCBPTR, active_scb);
6403 ahc_platform_abort_scbs(ahc, target, channel, lun, tag, role, status);
6404 ahc_release_untagged_queues(ahc);
6409 ahc_reset_current_bus(struct ahc_softc *ahc)
6413 ahc_outb(ahc, SIMODE1, ahc_inb(ahc, SIMODE1) & ~ENSCSIRST);
6414 scsiseq = ahc_inb(ahc, SCSISEQ);
6415 ahc_outb(ahc, SCSISEQ, scsiseq | SCSIRSTO);
6416 ahc_flush_device_writes(ahc);
6419 ahc_outb(ahc, SCSISEQ, scsiseq & ~SCSIRSTO);
6421 ahc_clear_intstat(ahc);
6424 ahc_outb(ahc, SIMODE1, ahc_inb(ahc, SIMODE1) | ENSCSIRST);
6428 ahc_reset_channel(struct ahc_softc *ahc, char channel, int initiate_reset)
6439 ahc->pending_device = NULL;
6446 ahc_pause(ahc);
6449 ahc_clear_critical_section(ahc);
6456 ahc_run_qoutfifo(ahc);
6458 if ((ahc->flags & AHC_TARGETROLE) != 0) {
6459 ahc_run_tqinfifo(ahc, /*paused*/TRUE);
6466 sblkctl = ahc_inb(ahc, SBLKCTL);
6468 if ((ahc->features & AHC_TWIN) != 0
6471 scsiseq = ahc_inb(ahc, SCSISEQ_TEMPLATE);
6477 ahc_outb(ahc, SBLKCTL, sblkctl ^ SELBUSB);
6478 simode1 = ahc_inb(ahc, SIMODE1) & ~(ENBUSFREE|ENSCSIRST);
6485 if ((ahc->flags & AHC_TARGETROLE) != 0)
6488 ahc_outb(ahc, SIMODE1, simode1);
6490 ahc_reset_current_bus(ahc);
6491 ahc_clear_intstat(ahc);
6492 ahc_outb(ahc, SCSISEQ, scsiseq & (ENSELI|ENRSELI|ENAUTOATNP));
6493 ahc_outb(ahc, SBLKCTL, sblkctl);
6497 simode1 = ahc_inb(ahc, SIMODE1) & ~(ENBUSFREE|ENSCSIRST);
6504 if ((ahc->flags & AHC_TARGETROLE) != 0)
6507 ahc_outb(ahc, SIMODE1, simode1);
6509 ahc_reset_current_bus(ahc);
6510 ahc_clear_intstat(ahc);
6511 ahc_outb(ahc, SCSISEQ, scsiseq & (ENSELI|ENRSELI|ENAUTOATNP));
6519 found = ahc_abort_scbs(ahc, CAM_TARGET_WILDCARD, channel,
6523 max_scsiid = (ahc->features & AHC_WIDE) ? 15 : 7;
6534 tstate = ahc->enabled_targets[target];
6544 ahc_queue_lstate_event(ahc, lstate, CAM_TARGET_WILDCARD,
6546 ahc_send_lstate_events(ahc, lstate);
6551 ahc_send_async(ahc, devinfo.channel, CAM_TARGET_WILDCARD,
6559 if (ahc->enabled_targets[target] == NULL)
6567 ahc_set_width(ahc, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
6569 ahc_set_syncrate(ahc, &devinfo, /*syncrate*/NULL,
6577 ahc_restart(ahc);
6579 ahc_unpause(ahc);
6589 ahc_calc_residual(struct ahc_softc *ahc, struct scb *scb)
6664 ahc_print_path(ahc, scb);
6677 ahc_queue_lstate_event(struct ahc_softc *ahc, struct ahc_tmode_lstate *lstate,
6728 ahc_send_lstate_events(struct ahc_softc *ahc, struct ahc_tmode_lstate *lstate)
6764 ahc_dumpseq(struct ahc_softc* ahc)
6768 ahc_outb(ahc, SEQCTL, PERRORDIS|FAILDIS|FASTMODE|LOADRAM);
6769 ahc_outb(ahc, SEQADDR0, 0);
6770 ahc_outb(ahc, SEQADDR1, 0);
6771 for (i = 0; i < ahc->instruction_ram_size; i++) {
6774 ahc_insb(ahc, SEQRAM, ins_bytes, 4);
6784 ahc_loadseq(struct ahc_softc *ahc)
6809 if (ahc->targetcmds != NULL)
6812 download_consts[CACHESIZE_MASK] = ahc->pci_cachesize - 1;
6813 download_consts[INVERTED_CACHESIZE_MASK] = ~(ahc->pci_cachesize - 1);
6814 sg_prefetch_cnt = ahc->pci_cachesize;
6824 ahc_outb(ahc, SEQCTL, PERRORDIS|FAILDIS|FASTMODE|LOADRAM);
6825 ahc_outb(ahc, SEQADDR0, 0);
6826 ahc_outb(ahc, SEQADDR1, 0);
6829 if (ahc_check_patch(ahc, &cur_patch, i, &skip_addr) == 0) {
6837 if (downloaded == ahc->instruction_ram_size) {
6844 "size of %d!\n", ahc_name(ahc),
6845 ahc->instruction_ram_size);
6870 ahc_download_instr(ahc, i, download_consts);
6874 ahc->num_critical_sections = cs_count;
6878 ahc->critical_sections = kmalloc(cs_count, GFP_ATOMIC);
6879 if (ahc->critical_sections == NULL)
6881 memcpy(ahc->critical_sections, cs_table, cs_count);
6883 ahc_outb(ahc, SEQCTL, PERRORDIS|FAILDIS|FASTMODE);
6888 ahc_name(ahc), ahc->features, ahc->bugs, ahc->flags);
6894 ahc_check_patch(struct ahc_softc *ahc, const struct patch **start_patch,
6907 if (cur_patch->patch_func(ahc) == 0) {
6930 ahc_download_instr(struct ahc_softc *ahc, u_int instrptr, uint8_t *dconsts)
6971 ahc_check_patch(ahc, &cur_patch, i, &skip_addr);
6997 if ((ahc->features & AHC_CMD_CHAN) == 0
7008 ahc_name(ahc));
7014 if ((ahc->features & AHC_ULTRA2) != 0) {
7046 ahc_outsb(ahc, SEQRAM, instr.bytes, 4);
7103 ahc_dump_card_state(struct ahc_softc *ahc)
7119 if (ahc_is_paused(ahc)) {
7123 ahc_pause(ahc);
7126 saved_scbptr = ahc_inb(ahc, SCBPTR);
7127 last_phase = ahc_inb(ahc, LASTPHASE);
7130 ahc_name(ahc), ahc_lookup_phase_entry(last_phase)->phasemsg,
7131 ahc_inb(ahc, SEQADDR0) | (ahc_inb(ahc, SEQADDR1) << 8));
7135 ahc_inb(ahc, ACCUM), ahc_inb(ahc, SINDEX), ahc_inb(ahc, DINDEX),
7136 ahc_inb(ahc, ARG_2));
7137 printk("HCNT = 0x%x SCBPTR = 0x%x\n", ahc_inb(ahc, HCNT),
7138 ahc_inb(ahc, SCBPTR));
7140 if ((ahc->features & AHC_DT) != 0)
7141 ahc_scsiphase_print(ahc_inb(ahc, SCSIPHASE), &cur_col, 50);
7142 ahc_scsisigi_print(ahc_inb(ahc, SCSISIGI), &cur_col, 50);
7143 ahc_error_print(ahc_inb(ahc, ERROR), &cur_col, 50);
7144 ahc_scsibusl_print(ahc_inb(ahc, SCSIBUSL), &cur_col, 50);
7145 ahc_lastphase_print(ahc_inb(ahc, LASTPHASE), &cur_col, 50);
7146 ahc_scsiseq_print(ahc_inb(ahc, SCSISEQ), &cur_col, 50);
7147 ahc_sblkctl_print(ahc_inb(ahc, SBLKCTL), &cur_col, 50);
7148 ahc_scsirate_print(ahc_inb(ahc, SCSIRATE), &cur_col, 50);
7149 ahc_seqctl_print(ahc_inb(ahc, SEQCTL), &cur_col, 50);
7150 ahc_seq_flags_print(ahc_inb(ahc, SEQ_FLAGS), &cur_col, 50);
7151 ahc_sstat0_print(ahc_inb(ahc, SSTAT0), &cur_col, 50);
7152 ahc_sstat1_print(ahc_inb(ahc, SSTAT1), &cur_col, 50);
7153 ahc_sstat2_print(ahc_inb(ahc, SSTAT2), &cur_col, 50);
7154 ahc_sstat3_print(ahc_inb(ahc, SSTAT3), &cur_col, 50);
7155 ahc_simode0_print(ahc_inb(ahc, SIMODE0), &cur_col, 50);
7156 ahc_simode1_print(ahc_inb(ahc, SIMODE1), &cur_col, 50);
7157 ahc_sxfrctl0_print(ahc_inb(ahc, SXFRCTL0), &cur_col, 50);
7158 ahc_dfcntrl_print(ahc_inb(ahc, DFCNTRL), &cur_col, 50);
7159 ahc_dfstatus_print(ahc_inb(ahc, DFSTATUS), &cur_col, 50);
7164 printk(" 0x%x", ahc_inb(ahc, STACK)|(ahc_inb(ahc, STACK) << 8));
7165 printk("\nSCB count = %d\n", ahc->scb_data->numscbs);
7166 printk("Kernel NEXTQSCB = %d\n", ahc->next_queued_scb->hscb->tag);
7167 printk("Card NEXTQSCB = %d\n", ahc_inb(ahc, NEXT_QUEUED_SCB));
7170 if ((ahc->features & AHC_QUEUE_REGS) != 0) {
7171 qinpos = ahc_inb(ahc, SNSCB_QOFF);
7172 ahc_outb(ahc, SNSCB_QOFF, qinpos);
7174 qinpos = ahc_inb(ahc, QINPOS);
7175 qintail = ahc->qinfifonext;
7177 printk("%d ", ahc->qinfifo[qinpos]);
7183 scb_index = ahc_inb(ahc, WAITING_SCBH);
7186 ahc_outb(ahc, SCBPTR, scb_index);
7187 printk("%d:%d ", scb_index, ahc_inb(ahc, SCB_TAG));
7188 scb_index = ahc_inb(ahc, SCB_NEXT);
7193 scb_index = ahc_inb(ahc, DISCONNECTED_SCBH);
7196 ahc_outb(ahc, SCBPTR, scb_index);
7197 printk("%d:%d ", scb_index, ahc_inb(ahc, SCB_TAG));
7198 scb_index = ahc_inb(ahc, SCB_NEXT);
7202 ahc_sync_qoutfifo(ahc, BUS_DMASYNC_POSTREAD);
7204 qoutpos = ahc->qoutfifonext;
7206 while (ahc->qoutfifo[qoutpos] != SCB_LIST_NULL && i++ < 256) {
7207 printk("%d ", ahc->qoutfifo[qoutpos]);
7213 scb_index = ahc_inb(ahc, FREE_SCBH);
7216 ahc_outb(ahc, SCBPTR, scb_index);
7218 scb_index = ahc_inb(ahc, SCB_NEXT);
7223 for (i = 0; i < ahc->scb_data->maxhscbs; i++) {
7224 ahc_outb(ahc, SCBPTR, i);
7227 ahc_scb_control_print(ahc_inb(ahc, SCB_CONTROL), &cur_col, 60);
7228 ahc_scb_scsiid_print(ahc_inb(ahc, SCB_SCSIID), &cur_col, 60);
7229 ahc_scb_lun_print(ahc_inb(ahc, SCB_LUN), &cur_col, 60);
7230 ahc_scb_tag_print(ahc_inb(ahc, SCB_TAG), &cur_col, 60);
7236 LIST_FOREACH(scb, &ahc->pending_scbs, pending_links) {
7243 if ((ahc->flags & AHC_PAGESCBS) == 0) {
7244 ahc_outb(ahc, SCBPTR, scb->hscb->tag);
7246 ahc_scb_control_print(ahc_inb(ahc, SCB_CONTROL),
7248 ahc_scb_tag_print(ahc_inb(ahc, SCB_TAG), &cur_col, 60);
7256 SLIST_FOREACH(scb, &ahc->scb_data->free_scbs, links.sle) {
7263 maxtarget = (ahc->features & (AHC_WIDE|AHC_TWIN)) ? 15 : 7;
7265 untagged_q = &ahc->untagged_queues[target];
7278 ahc_platform_dump_card_state(ahc);
7280 ahc_outb(ahc, SCBPTR, saved_scbptr);
7282 ahc_unpause(ahc);
7288 ahc_find_tmode_devs(struct ahc_softc *ahc, struct cam_sim *sim, union ccb *ccb,
7294 if ((ahc->features & AHC_TARGETMODE) == 0)
7304 *lstate = ahc->black_hole;
7308 max_id = (ahc->features & AHC_WIDE) ? 16 : 8;
7315 *tstate = ahc->enabled_targets[ccb->ccb_h.target_id];
7329 ahc_handle_en_lun(struct ahc_softc *ahc, struct cam_sim *sim, union ccb *ccb)
7343 status = ahc_find_tmode_devs(ahc, sim, ccb, &tstate, &lstate,
7352 our_id = ahc->our_id;
7354 our_id = ahc->our_id_b;
7376 if ((ahc->features & AHC_MULTIROLE) != 0) {
7378 if ((ahc->features & AHC_MULTI_TID) != 0
7379 && (ahc->flags & AHC_INITIATORROLE) != 0) {
7388 } else if ((ahc->flags & AHC_INITIATORROLE) != 0
7389 || ahc->enabled_luns > 0) {
7399 } else if ((ahc->features & AHC_MULTI_TID) == 0
7400 && ahc->enabled_luns > 0) {
7415 if ((ahc->flags & AHC_TARGETROLE) == 0
7421 ahc_lock(ahc, &s);
7422 if (LIST_FIRST(&ahc->pending_scbs) != NULL) {
7424 ahc_unlock(ahc, &s);
7427 saved_flags = ahc->flags;
7428 ahc->flags |= AHC_TARGETROLE;
7429 if ((ahc->features & AHC_MULTIROLE) == 0)
7430 ahc->flags &= ~AHC_INITIATORROLE;
7431 ahc_pause(ahc);
7432 error = ahc_loadseq(ahc);
7442 ahc->flags = saved_flags;
7443 (void)ahc_loadseq(ahc);
7444 ahc_restart(ahc);
7445 ahc_unlock(ahc, &s);
7449 ahc_restart(ahc);
7450 ahc_unlock(ahc, &s);
7455 channel = SIM_CHANNEL(ahc, sim);
7487 tstate = ahc_alloc_tstate(ahc, target, channel);
7516 ahc_lock(ahc, &s);
7517 ahc_pause(ahc);
7520 ahc->enabled_luns++;
7522 if ((ahc->features & AHC_MULTI_TID) != 0) {
7525 targid_mask = ahc_inb(ahc, TARGID)
7526 | (ahc_inb(ahc, TARGID + 1) << 8);
7529 ahc_outb(ahc, TARGID, targid_mask);
7530 ahc_outb(ahc, TARGID+1, (targid_mask >> 8));
7532 ahc_update_scsiid(ahc, targid_mask);
7537 channel = SIM_CHANNEL(ahc, sim);
7538 our_id = SIM_SCSI_ID(ahc, sim);
7549 sblkctl = ahc_inb(ahc, SBLKCTL);
7552 if ((ahc->features & AHC_TWIN) == 0)
7556 ahc->our_id = target;
7558 ahc->our_id_b = target;
7561 ahc_outb(ahc, SBLKCTL,
7564 ahc_outb(ahc, SCSIID, target);
7567 ahc_outb(ahc, SBLKCTL, sblkctl);
7571 ahc->black_hole = lstate;
7573 if (ahc->black_hole != NULL && ahc->enabled_luns > 0) {
7574 scsiseq = ahc_inb(ahc, SCSISEQ_TEMPLATE);
7576 ahc_outb(ahc, SCSISEQ_TEMPLATE, scsiseq);
7577 scsiseq = ahc_inb(ahc, SCSISEQ);
7579 ahc_outb(ahc, SCSISEQ, scsiseq);
7581 ahc_unpause(ahc);
7582 ahc_unlock(ahc, &s);
7595 ahc_lock(ahc, &s);
7598 LIST_FOREACH(scb, &ahc->pending_scbs, pending_links) {
7606 ahc_unlock(ahc, &s);
7622 ahc_unlock(ahc, &s);
7631 ahc_pause(ahc);
7635 ahc->enabled_luns--;
7643 ahc_free_tstate(ahc, target, channel,
7645 if (ahc->features & AHC_MULTI_TID) {
7648 targid_mask = ahc_inb(ahc, TARGID)
7649 | (ahc_inb(ahc, TARGID + 1)
7653 ahc_outb(ahc, TARGID, targid_mask);
7654 ahc_outb(ahc, TARGID+1,
7656 ahc_update_scsiid(ahc, targid_mask);
7661 ahc->black_hole = NULL;
7669 if (ahc->enabled_luns == 0) {
7673 scsiseq = ahc_inb(ahc, SCSISEQ_TEMPLATE);
7675 ahc_outb(ahc, SCSISEQ_TEMPLATE, scsiseq);
7676 scsiseq = ahc_inb(ahc, SCSISEQ);
7678 ahc_outb(ahc, SCSISEQ, scsiseq);
7680 if ((ahc->features & AHC_MULTIROLE) == 0) {
7682 ahc->flags &= ~AHC_TARGETROLE;
7683 ahc->flags |= AHC_INITIATORROLE;
7688 (void)ahc_loadseq(ahc);
7689 ahc_restart(ahc);
7696 ahc_unpause(ahc);
7697 ahc_unlock(ahc, &s);
7702 ahc_update_scsiid(struct ahc_softc *ahc, u_int targid_mask)
7707 if ((ahc->features & AHC_MULTI_TID) == 0)
7716 if ((ahc->features & AHC_ULTRA2) != 0)
7717 scsiid = ahc_inb(ahc, SCSIID_ULTRA2);
7719 scsiid = ahc_inb(ahc, SCSIID);
7727 our_id = ahc->our_id;
7733 if ((ahc->features & AHC_ULTRA2) != 0)
7734 ahc_outb(ahc, SCSIID_ULTRA2, scsiid);
7736 ahc_outb(ahc, SCSIID, scsiid);
7740 ahc_run_tqinfifo(struct ahc_softc *ahc, int paused)
7749 if ((ahc->features & AHC_AUTOPAUSE) != 0)
7752 ahc_sync_tqinfifo(ahc, BUS_DMASYNC_POSTREAD);
7753 while ((cmd = &ahc->targetcmds[ahc->tqinfifonext])->cmd_valid != 0) {
7759 if (ahc_handle_target_cmd(ahc, cmd) != 0)
7763 ahc_dmamap_sync(ahc, ahc->shared_data_dmat,
7764 ahc->shared_data_dmamap,
7765 ahc_targetcmd_offset(ahc, ahc->tqinfifonext),
7768 ahc->tqinfifonext++;
7774 if ((ahc->tqinfifonext & (HOST_TQINPOS - 1)) == 1) {
7775 if ((ahc->features & AHC_HS_MAILBOX) != 0) {
7778 hs_mailbox = ahc_inb(ahc, HS_MAILBOX);
7780 hs_mailbox |= ahc->tqinfifonext & HOST_TQINPOS;
7781 ahc_outb(ahc, HS_MAILBOX, hs_mailbox);
7784 ahc_pause(ahc);
7785 ahc_outb(ahc, KERNEL_TQINPOS,
7786 ahc->tqinfifonext & HOST_TQINPOS);
7788 ahc_unpause(ahc);
7795 ahc_handle_target_cmd(struct ahc_softc *ahc, struct target_cmd *cmd)
7805 initiator = SCSIID_TARGET(ahc, cmd->scsiid);
7810 tstate = ahc->enabled_targets[target];
7819 lstate = ahc->black_hole;
7823 ahc->flags |= AHC_TQINFIFO_BLOCKED;
7828 printk("%s: ATIOs exhausted\n", ahc_name(ahc));
7831 ahc->flags &= ~AHC_TQINFIFO_BLOCKED;
7834 if (lstate == ahc->black_hole) {
7890 ahc->pending_device = lstate;