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) in ahc_freeze_untagged_queues() argument
285 if ((ahc->flags & AHC_SCB_BTT) == 0) in ahc_freeze_untagged_queues()
286 ahc->untagged_queue_lock++; in ahc_freeze_untagged_queues()
296 ahc_release_untagged_queues(struct ahc_softc *ahc) in ahc_release_untagged_queues() argument
298 if ((ahc->flags & AHC_SCB_BTT) == 0) { in ahc_release_untagged_queues()
299 ahc->untagged_queue_lock--; in ahc_release_untagged_queues()
300 if (ahc->untagged_queue_lock == 0) in ahc_release_untagged_queues()
301 ahc_run_untagged_queues(ahc); in ahc_release_untagged_queues()
315 ahc_pause_bug_fix(struct ahc_softc *ahc) in ahc_pause_bug_fix() argument
317 if ((ahc->features & AHC_ULTRA2) != 0) in ahc_pause_bug_fix()
318 (void)ahc_inb(ahc, CCSCBCTL); in ahc_pause_bug_fix()
326 ahc_is_paused(struct ahc_softc *ahc) in ahc_is_paused() argument
328 return ((ahc_inb(ahc, HCNTRL) & PAUSE) != 0); in ahc_is_paused()
339 ahc_pause(struct ahc_softc *ahc) in ahc_pause() argument
341 ahc_outb(ahc, HCNTRL, ahc->pause); in ahc_pause()
347 while (ahc_is_paused(ahc) == 0) in ahc_pause()
350 ahc_pause_bug_fix(ahc); in ahc_pause()
364 ahc_unpause(struct ahc_softc *ahc) in ahc_unpause() argument
366 if ((ahc_inb(ahc, INTSTAT) & (SCSIINT | SEQINT | BRKADRINT)) == 0) in ahc_unpause()
367 ahc_outb(ahc, HCNTRL, ahc->unpause); in ahc_unpause()
395 ahc_hscb_busaddr(struct ahc_softc *ahc, u_int index) in ahc_hscb_busaddr() argument
397 return (ahc->scb_data->hscb_busaddr in ahc_hscb_busaddr()
402 ahc_sync_scb(struct ahc_softc *ahc, struct scb *scb, int op) in ahc_sync_scb() argument
404 ahc_dmamap_sync(ahc, ahc->scb_data->hscb_dmat, in ahc_sync_scb()
405 ahc->scb_data->hscb_dmamap, in ahc_sync_scb()
406 /*offset*/(scb->hscb - ahc->hscbs) * sizeof(*scb->hscb), in ahc_sync_scb()
411 ahc_sync_sglist(struct ahc_softc *ahc, struct scb *scb, int op) in ahc_sync_sglist() argument
416 ahc_dmamap_sync(ahc, ahc->scb_data->sg_dmat, scb->sg_map->sg_dmamap, in ahc_sync_sglist()
424 ahc_targetcmd_offset(struct ahc_softc *ahc, u_int index) in ahc_targetcmd_offset() argument
426 return (((uint8_t *)&ahc->targetcmds[index]) - ahc->qoutfifo); in ahc_targetcmd_offset()
436 ahc_update_residual(struct ahc_softc *ahc, struct scb *scb) in ahc_update_residual() argument
442 ahc_calc_residual(ahc, scb); in ahc_update_residual()
450 ahc_fetch_transinfo(struct ahc_softc *ahc, char channel, u_int our_id, in ahc_fetch_transinfo() argument
461 *tstate = ahc->enabled_targets[our_id]; in ahc_fetch_transinfo()
466 ahc_inw(struct ahc_softc *ahc, u_int port) in ahc_inw() argument
468 uint16_t r = ahc_inb(ahc, port+1) << 8; in ahc_inw()
469 return r | ahc_inb(ahc, port); in ahc_inw()
473 ahc_outw(struct ahc_softc *ahc, u_int port, u_int value) in ahc_outw() argument
475 ahc_outb(ahc, port, value & 0xFF); in ahc_outw()
476 ahc_outb(ahc, port+1, (value >> 8) & 0xFF); in ahc_outw()
480 ahc_inl(struct ahc_softc *ahc, u_int port) in ahc_inl() argument
482 return ((ahc_inb(ahc, port)) in ahc_inl()
483 | (ahc_inb(ahc, port+1) << 8) in ahc_inl()
484 | (ahc_inb(ahc, port+2) << 16) in ahc_inl()
485 | (ahc_inb(ahc, port+3) << 24)); in ahc_inl()
489 ahc_outl(struct ahc_softc *ahc, u_int port, uint32_t value) in ahc_outl() argument
491 ahc_outb(ahc, port, (value) & 0xFF); in ahc_outl()
492 ahc_outb(ahc, port+1, ((value) >> 8) & 0xFF); in ahc_outl()
493 ahc_outb(ahc, port+2, ((value) >> 16) & 0xFF); in ahc_outl()
494 ahc_outb(ahc, port+3, ((value) >> 24) & 0xFF); in ahc_outl()
498 ahc_inq(struct ahc_softc *ahc, u_int port) in ahc_inq() argument
500 return ((ahc_inb(ahc, port)) in ahc_inq()
501 | (ahc_inb(ahc, port+1) << 8) in ahc_inq()
502 | (ahc_inb(ahc, port+2) << 16) in ahc_inq()
503 | (ahc_inb(ahc, port+3) << 24) in ahc_inq()
504 | (((uint64_t)ahc_inb(ahc, port+4)) << 32) in ahc_inq()
505 | (((uint64_t)ahc_inb(ahc, port+5)) << 40) in ahc_inq()
506 | (((uint64_t)ahc_inb(ahc, port+6)) << 48) in ahc_inq()
507 | (((uint64_t)ahc_inb(ahc, port+7)) << 56)); in ahc_inq()
511 ahc_outq(struct ahc_softc *ahc, u_int port, uint64_t value) in ahc_outq() argument
513 ahc_outb(ahc, port, value & 0xFF); in ahc_outq()
514 ahc_outb(ahc, port+1, (value >> 8) & 0xFF); in ahc_outq()
515 ahc_outb(ahc, port+2, (value >> 16) & 0xFF); in ahc_outq()
516 ahc_outb(ahc, port+3, (value >> 24) & 0xFF); in ahc_outq()
517 ahc_outb(ahc, port+4, (value >> 32) & 0xFF); in ahc_outq()
518 ahc_outb(ahc, port+5, (value >> 40) & 0xFF); in ahc_outq()
519 ahc_outb(ahc, port+6, (value >> 48) & 0xFF); in ahc_outq()
520 ahc_outb(ahc, port+7, (value >> 56) & 0xFF); in ahc_outq()
527 ahc_get_scb(struct ahc_softc *ahc) in ahc_get_scb() argument
531 if ((scb = SLIST_FIRST(&ahc->scb_data->free_scbs)) == NULL) { in ahc_get_scb()
532 ahc_alloc_scbs(ahc); in ahc_get_scb()
533 scb = SLIST_FIRST(&ahc->scb_data->free_scbs); in ahc_get_scb()
537 SLIST_REMOVE_HEAD(&ahc->scb_data->free_scbs, links.sle); in ahc_get_scb()
545 ahc_free_scb(struct ahc_softc *ahc, struct scb *scb) in ahc_free_scb() argument
551 ahc->scb_data->scbindex[hscb->tag] = NULL; in ahc_free_scb()
555 SLIST_INSERT_HEAD(&ahc->scb_data->free_scbs, scb, links.sle); in ahc_free_scb()
558 ahc_platform_scb_free(ahc, scb); in ahc_free_scb()
562 ahc_lookup_scb(struct ahc_softc *ahc, u_int tag) in ahc_lookup_scb() argument
566 scb = ahc->scb_data->scbindex[tag]; in ahc_lookup_scb()
568 ahc_sync_scb(ahc, scb, in ahc_lookup_scb()
574 ahc_swap_with_next_hscb(struct ahc_softc *ahc, struct scb *scb) in ahc_swap_with_next_hscb() argument
591 q_hscb = ahc->next_queued_scb->hscb; in ahc_swap_with_next_hscb()
596 ahc_htole32(ahc_hscb_busaddr(ahc, q_hscb->tag) in ahc_swap_with_next_hscb()
603 ahc->next_queued_scb->hscb = scb->hscb; in ahc_swap_with_next_hscb()
607 ahc->scb_data->scbindex[scb->hscb->tag] = scb; in ahc_swap_with_next_hscb()
614 ahc_queue_scb(struct ahc_softc *ahc, struct scb *scb) in ahc_queue_scb() argument
616 ahc_swap_with_next_hscb(ahc, scb); in ahc_queue_scb()
633 ahc->qinfifo[ahc->qinfifonext++] = scb->hscb->tag; in ahc_queue_scb()
639 ahc_sync_scb(ahc, scb, BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE); in ahc_queue_scb()
642 if ((ahc->features & AHC_QUEUE_REGS) != 0) { in ahc_queue_scb()
643 ahc_outb(ahc, HNSCB_QOFF, ahc->qinfifonext); in ahc_queue_scb()
645 if ((ahc->features & AHC_AUTOPAUSE) == 0) in ahc_queue_scb()
646 ahc_pause(ahc); in ahc_queue_scb()
647 ahc_outb(ahc, KERNEL_QINPOS, ahc->qinfifonext); in ahc_queue_scb()
648 if ((ahc->features & AHC_AUTOPAUSE) == 0) in ahc_queue_scb()
649 ahc_unpause(ahc); in ahc_queue_scb()
654 ahc_get_sense_buf(struct ahc_softc *ahc, struct scb *scb) in ahc_get_sense_buf() argument
658 offset = scb - ahc->scb_data->scbarray; in ahc_get_sense_buf()
659 return (&ahc->scb_data->sense[offset]); in ahc_get_sense_buf()
663 ahc_get_sense_bufaddr(struct ahc_softc *ahc, struct scb *scb) in ahc_get_sense_bufaddr() argument
667 offset = scb - ahc->scb_data->scbarray; in ahc_get_sense_bufaddr()
668 return (ahc->scb_data->sense_busaddr in ahc_get_sense_bufaddr()
674 ahc_sync_qoutfifo(struct ahc_softc *ahc, int op) in ahc_sync_qoutfifo() argument
676 ahc_dmamap_sync(ahc, ahc->shared_data_dmat, ahc->shared_data_dmamap, in ahc_sync_qoutfifo()
681 ahc_sync_tqinfifo(struct ahc_softc *ahc, int op) in ahc_sync_tqinfifo() argument
684 if ((ahc->flags & AHC_TARGETROLE) != 0) { in ahc_sync_tqinfifo()
685 ahc_dmamap_sync(ahc, ahc->shared_data_dmat, in ahc_sync_tqinfifo()
686 ahc->shared_data_dmamap, in ahc_sync_tqinfifo()
687 ahc_targetcmd_offset(ahc, 0), in ahc_sync_tqinfifo()
701 ahc_check_cmdcmpltqueues(struct ahc_softc *ahc) in ahc_check_cmdcmpltqueues() argument
706 ahc_dmamap_sync(ahc, ahc->shared_data_dmat, ahc->shared_data_dmamap, in ahc_check_cmdcmpltqueues()
707 /*offset*/ahc->qoutfifonext, /*len*/1, in ahc_check_cmdcmpltqueues()
709 if (ahc->qoutfifo[ahc->qoutfifonext] != SCB_LIST_NULL) in ahc_check_cmdcmpltqueues()
712 if ((ahc->flags & AHC_TARGETROLE) != 0 in ahc_check_cmdcmpltqueues()
713 && (ahc->flags & AHC_TQINFIFO_BLOCKED) == 0) { in ahc_check_cmdcmpltqueues()
714 ahc_dmamap_sync(ahc, ahc->shared_data_dmat, in ahc_check_cmdcmpltqueues()
715 ahc->shared_data_dmamap, in ahc_check_cmdcmpltqueues()
716 ahc_targetcmd_offset(ahc, ahc->tqinfifofnext), in ahc_check_cmdcmpltqueues()
719 if (ahc->targetcmds[ahc->tqinfifonext].cmd_valid != 0) in ahc_check_cmdcmpltqueues()
730 ahc_intr(struct ahc_softc *ahc) in ahc_intr() argument
734 if ((ahc->pause & INTEN) == 0) { in ahc_intr()
749 if ((ahc->flags & (AHC_ALL_INTERRUPTS|AHC_EDGE_INTERRUPT)) == 0 in ahc_intr()
750 && (ahc_check_cmdcmpltqueues(ahc) != 0)) in ahc_intr()
753 intstat = ahc_inb(ahc, INTSTAT); in ahc_intr()
758 if (ahc->unsolicited_ints > 500) { in ahc_intr()
759 ahc->unsolicited_ints = 0; in ahc_intr()
760 if ((ahc->chip & AHC_PCI) != 0 in ahc_intr()
761 && (ahc_inb(ahc, ERROR) & PCIERRSTAT) != 0) in ahc_intr()
762 ahc->bus_intr(ahc); in ahc_intr()
765 ahc->unsolicited_ints++; in ahc_intr()
768 ahc->unsolicited_ints = 0; in ahc_intr()
771 ahc_outb(ahc, CLRINT, CLRCMDINT); in ahc_intr()
781 ahc_flush_device_writes(ahc); in ahc_intr()
782 ahc_run_qoutfifo(ahc); in ahc_intr()
784 if ((ahc->flags & AHC_TARGETROLE) != 0) in ahc_intr()
785 ahc_run_tqinfifo(ahc, /*paused*/FALSE); in ahc_intr()
793 if (intstat == 0xFF && (ahc->features & AHC_REMOVABLE) != 0) { in ahc_intr()
796 ahc_handle_brkadrint(ahc); in ahc_intr()
799 ahc_pause_bug_fix(ahc); in ahc_intr()
802 ahc_handle_seqint(ahc, intstat); in ahc_intr()
805 ahc_handle_scsiint(ahc, intstat); in ahc_intr()
815 ahc_restart(struct ahc_softc *ahc) in ahc_restart() argument
819 ahc_pause(ahc); in ahc_restart()
822 ahc_clear_msg_state(ahc); in ahc_restart()
824 ahc_outb(ahc, SCSISIGO, 0); /* De-assert BSY */ in ahc_restart()
825 ahc_outb(ahc, MSG_OUT, MSG_NOOP); /* No message to send */ in ahc_restart()
826 ahc_outb(ahc, SXFRCTL1, ahc_inb(ahc, SXFRCTL1) & ~BITBUCKET); in ahc_restart()
827 ahc_outb(ahc, LASTPHASE, P_BUSFREE); in ahc_restart()
828 ahc_outb(ahc, SAVED_SCSIID, 0xFF); in ahc_restart()
829 ahc_outb(ahc, SAVED_LUN, 0xFF); in ahc_restart()
838 ahc_outb(ahc, TQINPOS, ahc->tqinfifonext); in ahc_restart()
841 ahc_outb(ahc, SCSISEQ, in ahc_restart()
842 ahc_inb(ahc, SCSISEQ_TEMPLATE) & (ENSELI|ENRSELI|ENAUTOATNP)); in ahc_restart()
843 if ((ahc->features & AHC_CMD_CHAN) != 0) { in ahc_restart()
845 ahc_outb(ahc, CCSCBCNT, 0); in ahc_restart()
846 ahc_outb(ahc, CCSGCTL, 0); in ahc_restart()
847 ahc_outb(ahc, CCSCBCTL, 0); in ahc_restart()
854 if ((ahc_inb(ahc, SEQ_FLAGS2) & SCB_DMA) != 0) { in ahc_restart()
855 ahc_add_curscb_to_free_list(ahc); in ahc_restart()
856 ahc_outb(ahc, SEQ_FLAGS2, in ahc_restart()
857 ahc_inb(ahc, SEQ_FLAGS2) & ~SCB_DMA); in ahc_restart()
865 ahc_outb(ahc, CLRINT, CLRSEQINT); in ahc_restart()
867 ahc_outb(ahc, MWI_RESIDUAL, 0); in ahc_restart()
868 ahc_outb(ahc, SEQCTL, ahc->seqctl); in ahc_restart()
869 ahc_outb(ahc, SEQADDR0, 0); in ahc_restart()
870 ahc_outb(ahc, SEQADDR1, 0); in ahc_restart()
875 sblkctl = ahc_inb(ahc, SBLKCTL); in ahc_restart()
876 ahc_outb(ahc, SBLKCTL, (sblkctl & ~(DIAGLEDEN|DIAGLEDON))); in ahc_restart()
878 ahc_unpause(ahc); in ahc_restart()
883 ahc_run_qoutfifo(struct ahc_softc *ahc) in ahc_run_qoutfifo() argument
888 ahc_sync_qoutfifo(ahc, BUS_DMASYNC_POSTREAD); in ahc_run_qoutfifo()
889 while (ahc->qoutfifo[ahc->qoutfifonext] != SCB_LIST_NULL) { in ahc_run_qoutfifo()
891 scb_index = ahc->qoutfifo[ahc->qoutfifonext]; in ahc_run_qoutfifo()
892 if ((ahc->qoutfifonext & 0x03) == 0x03) { in ahc_run_qoutfifo()
902 modnext = ahc->qoutfifonext & ~0x3; in ahc_run_qoutfifo()
903 *((uint32_t *)(&ahc->qoutfifo[modnext])) = 0xFFFFFFFFUL; in ahc_run_qoutfifo()
904 ahc_dmamap_sync(ahc, ahc->shared_data_dmat, in ahc_run_qoutfifo()
905 ahc->shared_data_dmamap, in ahc_run_qoutfifo()
909 ahc->qoutfifonext++; in ahc_run_qoutfifo()
911 scb = ahc_lookup_scb(ahc, scb_index); in ahc_run_qoutfifo()
915 ahc_name(ahc), scb_index, in ahc_run_qoutfifo()
916 (ahc->qoutfifonext - 1) & 0xFF); in ahc_run_qoutfifo()
924 ahc_update_residual(ahc, scb); in ahc_run_qoutfifo()
925 ahc_done(ahc, scb); in ahc_run_qoutfifo()
930 ahc_run_untagged_queues(struct ahc_softc *ahc) in ahc_run_untagged_queues() argument
935 ahc_run_untagged_queue(ahc, &ahc->untagged_queues[i]); in ahc_run_untagged_queues()
939 ahc_run_untagged_queue(struct ahc_softc *ahc, struct scb_tailq *queue) in ahc_run_untagged_queue() argument
943 if (ahc->untagged_queue_lock != 0) in ahc_run_untagged_queue()
949 ahc_queue_scb(ahc, scb); in ahc_run_untagged_queue()
955 ahc_handle_brkadrint(struct ahc_softc *ahc) in ahc_handle_brkadrint() argument
964 error = ahc_inb(ahc, ERROR); in ahc_handle_brkadrint()
968 ahc_name(ahc), ahc_hard_errors[i].errmesg, in ahc_handle_brkadrint()
969 ahc_inb(ahc, SEQADDR0) | in ahc_handle_brkadrint()
970 (ahc_inb(ahc, SEQADDR1) << 8)); in ahc_handle_brkadrint()
972 ahc_dump_card_state(ahc); in ahc_handle_brkadrint()
975 ahc_abort_scbs(ahc, CAM_TARGET_WILDCARD, ALL_CHANNELS, in ahc_handle_brkadrint()
980 ahc_shutdown(ahc); in ahc_handle_brkadrint()
984 ahc_handle_seqint(struct ahc_softc *ahc, u_int intstat) in ahc_handle_seqint() argument
989 ahc_fetch_devinfo(ahc, &devinfo); in ahc_handle_seqint()
997 ahc_outb(ahc, CLRINT, CLRSEQINT); in ahc_handle_seqint()
1009 ahc_outb(ahc, RETURN_1, 0); in ahc_handle_seqint()
1020 scb_index = ahc_inb(ahc, SCB_TAG); in ahc_handle_seqint()
1021 scb = ahc_lookup_scb(ahc, scb_index); in ahc_handle_seqint()
1023 ahc_print_devinfo(ahc, &devinfo); in ahc_handle_seqint()
1027 ahc_dump_card_state(ahc); in ahc_handle_seqint()
1047 ahc_freeze_devq(ahc, scb); in ahc_handle_seqint()
1053 ahc_name(ahc)); in ahc_handle_seqint()
1065 ahc_print_path(ahc, scb); in ahc_handle_seqint()
1074 targ_info = ahc_fetch_transinfo(ahc, in ahc_handle_seqint()
1085 ahc_update_residual(ahc, scb); in ahc_handle_seqint()
1088 ahc_print_path(ahc, scb); in ahc_handle_seqint()
1092 sg->addr = ahc_get_sense_bufaddr(ahc, scb); in ahc_handle_seqint()
1093 sg->len = ahc_get_sense_bufsize(ahc, scb); in ahc_handle_seqint()
1129 ahc_update_neg_request(ahc, &devinfo, in ahc_handle_seqint()
1145 ahc_qinfifo_requeue_tail(ahc, scb); in ahc_handle_seqint()
1146 ahc_outb(ahc, RETURN_1, SEND_SENSE); in ahc_handle_seqint()
1162 ahc_outb(ahc, SCSISEQ, in ahc_handle_seqint()
1163 ahc_inb(ahc, SCSISEQ) & (ENSELI|ENRSELI|ENAUTOATNP)); in ahc_handle_seqint()
1167 ahc_name(ahc), devinfo.channel, devinfo.target); in ahc_handle_seqint()
1170 ahc_inb(ahc, SAVED_SCSIID), ahc_inb(ahc, SAVED_LUN), in ahc_handle_seqint()
1171 ahc_inb(ahc, ARG_1), ahc_inb(ahc, ACCUM)); in ahc_handle_seqint()
1174 ahc_inb(ahc, SEQ_FLAGS), ahc_inb(ahc, SCBPTR), in ahc_handle_seqint()
1175 ahc_index_busy_tcl(ahc, in ahc_handle_seqint()
1176 BUILD_TCL(ahc_inb(ahc, SAVED_SCSIID), in ahc_handle_seqint()
1177 ahc_inb(ahc, SAVED_LUN))), in ahc_handle_seqint()
1178 ahc_inb(ahc, SINDEX)); in ahc_handle_seqint()
1181 ahc_inb(ahc, SCSIID), ahc_inb(ahc, SCB_SCSIID), in ahc_handle_seqint()
1182 ahc_inb(ahc, SCB_LUN), ahc_inb(ahc, SCB_TAG), in ahc_handle_seqint()
1183 ahc_inb(ahc, SCB_CONTROL)); in ahc_handle_seqint()
1185 ahc_inb(ahc, SCSIBUSL), ahc_inb(ahc, SCSISIGI)); in ahc_handle_seqint()
1186 printk("SXFRCTL0 == 0x%x\n", ahc_inb(ahc, SXFRCTL0)); in ahc_handle_seqint()
1187 printk("SEQCTL == 0x%x\n", ahc_inb(ahc, SEQCTL)); in ahc_handle_seqint()
1188 ahc_dump_card_state(ahc); in ahc_handle_seqint()
1189 ahc->msgout_buf[0] = MSG_BUS_DEV_RESET; in ahc_handle_seqint()
1190 ahc->msgout_len = 1; in ahc_handle_seqint()
1191 ahc->msgout_index = 0; in ahc_handle_seqint()
1192 ahc->msg_type = MSG_TYPE_INITIATOR_MSGOUT; in ahc_handle_seqint()
1193 ahc_outb(ahc, MSG_OUT, HOST_MSG); in ahc_handle_seqint()
1194 ahc_assert_atn(ahc); in ahc_handle_seqint()
1199 u_int rejbyte = ahc_inb(ahc, ACCUM); in ahc_handle_seqint()
1202 ahc_name(ahc), devinfo.channel, devinfo.target, rejbyte); in ahc_handle_seqint()
1207 ahc_handle_proto_violation(ahc); in ahc_handle_seqint()
1211 ahc_handle_ign_wide_residue(ahc, &devinfo); in ahc_handle_seqint()
1214 ahc_reinitialize_dataptrs(ahc); in ahc_handle_seqint()
1220 lastphase = ahc_inb(ahc, LASTPHASE); in ahc_handle_seqint()
1223 ahc_name(ahc), devinfo.channel, devinfo.target, in ahc_handle_seqint()
1224 lastphase, ahc_inb(ahc, SCSISIGI)); in ahc_handle_seqint()
1231 lastphase = ahc_inb(ahc, LASTPHASE); in ahc_handle_seqint()
1234 ahc_name(ahc), devinfo.channel, devinfo.target, in ahc_handle_seqint()
1235 lastphase, ahc_inb(ahc, SCSISIGI)); in ahc_handle_seqint()
1236 ahc_restart(ahc); in ahc_handle_seqint()
1252 if (ahc->msg_type == MSG_TYPE_NONE) { in ahc_handle_seqint()
1257 bus_phase = ahc_inb(ahc, SCSISIGI) & PHASE_MASK; in ahc_handle_seqint()
1267 ahc_clear_intstat(ahc); in ahc_handle_seqint()
1268 ahc_restart(ahc); in ahc_handle_seqint()
1272 scb_index = ahc_inb(ahc, SCB_TAG); in ahc_handle_seqint()
1273 scb = ahc_lookup_scb(ahc, scb_index); in ahc_handle_seqint()
1281 ahc_setup_initiator_msgout(ahc, in ahc_handle_seqint()
1285 ahc->msg_type = in ahc_handle_seqint()
1287 ahc->msgin_index = 0; in ahc_handle_seqint()
1293 ahc->msg_type = in ahc_handle_seqint()
1295 ahc->msgin_index = 0; in ahc_handle_seqint()
1298 ahc_setup_target_msgin(ahc, in ahc_handle_seqint()
1305 ahc_handle_message_phase(ahc); in ahc_handle_seqint()
1322 && (ahc_inb(ahc, SSTAT1) & SCSIPERR) != 0) { in ahc_handle_seqint()
1324 if ((ahc->features & AHC_DT) == 0) { in ahc_handle_seqint()
1333 curphase = ahc_inb(ahc, SCSISIGI) & PHASE_MASK; in ahc_handle_seqint()
1334 ahc_outb(ahc, LASTPHASE, curphase); in ahc_handle_seqint()
1335 ahc_outb(ahc, SCSISIGO, curphase); in ahc_handle_seqint()
1337 if ((ahc_inb(ahc, SCSISIGI) & (CDI|MSGI)) == 0) { in ahc_handle_seqint()
1346 ahc_outb(ahc, SXFRCTL1, in ahc_handle_seqint()
1347 ahc_inb(ahc, SXFRCTL1) | BITBUCKET); in ahc_handle_seqint()
1350 if ((ahc_inb(ahc, SCSISIGI) in ahc_handle_seqint()
1355 ahc_outb(ahc, SXFRCTL1, in ahc_handle_seqint()
1356 ahc_inb(ahc, SXFRCTL1) & ~BITBUCKET); in ahc_handle_seqint()
1361 ahc_print_devinfo(ahc, &devinfo); in ahc_handle_seqint()
1364 scb_index = ahc_inb(ahc, SCB_TAG); in ahc_handle_seqint()
1365 scb = ahc_lookup_scb(ahc, scb_index); in ahc_handle_seqint()
1369 ahc_reset_channel(ahc, devinfo.channel, in ahc_handle_seqint()
1373 ahc_inb(ahc, SCSIDATL); in ahc_handle_seqint()
1388 u_int scbindex = ahc_inb(ahc, SCB_TAG); in ahc_handle_seqint()
1389 u_int lastphase = ahc_inb(ahc, LASTPHASE); in ahc_handle_seqint()
1392 scb = ahc_lookup_scb(ahc, scbindex); in ahc_handle_seqint()
1397 ahc_print_path(ahc, scb); in ahc_handle_seqint()
1402 ahc_print_path(ahc, scb); in ahc_handle_seqint()
1404 ahc_inb(ahc, SEQ_FLAGS) & DPHASE ? "Have" : "Haven't", in ahc_handle_seqint()
1422 ahc_freeze_devq(ahc, scb); in ahc_handle_seqint()
1431 if ((ahc->features & AHC_ULTRA2) != 0) { in ahc_handle_seqint()
1436 ahc_outb(ahc, SXFRCTL0, in ahc_handle_seqint()
1437 ahc_inb(ahc, SXFRCTL0) | CLRSTCNT|CLRCHN); in ahc_handle_seqint()
1438 ahc_outb(ahc, SXFRCTL0, in ahc_handle_seqint()
1439 ahc_inb(ahc, SXFRCTL0) | CLRSTCNT|CLRCHN); in ahc_handle_seqint()
1441 if ((ahc->flags & AHC_39BIT_ADDRESSING) != 0) { in ahc_handle_seqint()
1445 dscommand1 = ahc_inb(ahc, DSCOMMAND1); in ahc_handle_seqint()
1446 ahc_outb(ahc, DSCOMMAND1, dscommand1 | HADDLDSEL0); in ahc_handle_seqint()
1447 ahc_outb(ahc, HADDR, 0); in ahc_handle_seqint()
1448 ahc_outb(ahc, DSCOMMAND1, dscommand1); in ahc_handle_seqint()
1457 ahc_name(ahc), devinfo.channel, devinfo.target, in ahc_handle_seqint()
1459 scbindex = ahc_inb(ahc, SCB_TAG); in ahc_handle_seqint()
1460 scb = ahc_lookup_scb(ahc, scbindex); in ahc_handle_seqint()
1467 ahc_search_qinfifo(ahc, SCB_GET_TARGET(ahc, scb), in ahc_handle_seqint()
1468 SCB_GET_CHANNEL(ahc, scb), in ahc_handle_seqint()
1476 printk("%s: No free or disconnected SCBs\n", ahc_name(ahc)); in ahc_handle_seqint()
1477 ahc_dump_card_state(ahc); in ahc_handle_seqint()
1485 scbptr = ahc_inb(ahc, SCBPTR); in ahc_handle_seqint()
1487 scbptr, ahc_inb(ahc, ARG_1), in ahc_handle_seqint()
1488 ahc->scb_data->hscbs[scbptr].tag); in ahc_handle_seqint()
1489 ahc_dump_card_state(ahc); in ahc_handle_seqint()
1495 printk("%s: BTT calculation out of range\n", ahc_name(ahc)); in ahc_handle_seqint()
1498 ahc_inb(ahc, SAVED_SCSIID), ahc_inb(ahc, SAVED_LUN), in ahc_handle_seqint()
1499 ahc_inb(ahc, ARG_1), ahc_inb(ahc, ACCUM)); in ahc_handle_seqint()
1502 ahc_inb(ahc, SEQ_FLAGS), ahc_inb(ahc, SCBPTR), in ahc_handle_seqint()
1503 ahc_index_busy_tcl(ahc, in ahc_handle_seqint()
1504 BUILD_TCL(ahc_inb(ahc, SAVED_SCSIID), in ahc_handle_seqint()
1505 ahc_inb(ahc, SAVED_LUN))), in ahc_handle_seqint()
1506 ahc_inb(ahc, SINDEX), in ahc_handle_seqint()
1507 ahc_inb(ahc, ACCUM)); in ahc_handle_seqint()
1510 ahc_inb(ahc, SCSIID), ahc_inb(ahc, SCB_SCSIID), in ahc_handle_seqint()
1511 ahc_inb(ahc, SCB_LUN), ahc_inb(ahc, SCB_TAG), in ahc_handle_seqint()
1512 ahc_inb(ahc, SCB_CONTROL)); in ahc_handle_seqint()
1514 ahc_inb(ahc, SCSIBUSL), ahc_inb(ahc, SCSISIGI)); in ahc_handle_seqint()
1515 ahc_dump_card_state(ahc); in ahc_handle_seqint()
1522 intstat, ahc_inb(ahc, SCSISIGI)); in ahc_handle_seqint()
1531 ahc_unpause(ahc); in ahc_handle_seqint()
1535 ahc_handle_scsiint(struct ahc_softc *ahc, u_int intstat) in ahc_handle_scsiint() argument
1544 if ((ahc->features & AHC_TWIN) != 0 in ahc_handle_scsiint()
1545 && ((ahc_inb(ahc, SBLKCTL) & SELBUSB) != 0)) in ahc_handle_scsiint()
1551 if ((ahc->features & AHC_ULTRA2) != 0) in ahc_handle_scsiint()
1552 status0 = ahc_inb(ahc, SSTAT0) & IOERR; in ahc_handle_scsiint()
1555 status = ahc_inb(ahc, SSTAT1) & (SELTO|SCSIRSTI|BUSFREE|SCSIPERR); in ahc_handle_scsiint()
1557 if ((ahc->features & AHC_TWIN) != 0) { in ahc_handle_scsiint()
1559 ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) ^ SELBUSB); in ahc_handle_scsiint()
1560 status = ahc_inb(ahc, SSTAT1) in ahc_handle_scsiint()
1565 printk("%s: Spurious SCSI interrupt\n", ahc_name(ahc)); in ahc_handle_scsiint()
1566 ahc_outb(ahc, CLRINT, CLRSCSIINT); in ahc_handle_scsiint()
1567 ahc_unpause(ahc); in ahc_handle_scsiint()
1573 ahc_clear_critical_section(ahc); in ahc_handle_scsiint()
1575 scb_index = ahc_inb(ahc, SCB_TAG); in ahc_handle_scsiint()
1576 scb = ahc_lookup_scb(ahc, scb_index); in ahc_handle_scsiint()
1578 && (ahc_inb(ahc, SEQ_FLAGS) & NOT_IDENTIFIED) != 0) in ahc_handle_scsiint()
1581 if ((ahc->features & AHC_ULTRA2) != 0 in ahc_handle_scsiint()
1585 now_lvd = ahc_inb(ahc, SBLKCTL) & ENAB40; in ahc_handle_scsiint()
1587 ahc_name(ahc), now_lvd ? "LVD" : "SE"); in ahc_handle_scsiint()
1588 ahc_outb(ahc, CLRSINT0, CLRIOERR); in ahc_handle_scsiint()
1599 ahc_reset_channel(ahc, intr_channel, in ahc_handle_scsiint()
1603 ahc_name(ahc), intr_channel); in ahc_handle_scsiint()
1605 ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) ^ SELBUSB); in ahc_handle_scsiint()
1606 ahc_reset_channel(ahc, intr_channel, /*Initiate Reset*/FALSE); in ahc_handle_scsiint()
1628 lastphase = ahc_inb(ahc, LASTPHASE); in ahc_handle_scsiint()
1629 curphase = ahc_inb(ahc, SCSISIGI) & PHASE_MASK; in ahc_handle_scsiint()
1630 sstat2 = ahc_inb(ahc, SSTAT2); in ahc_handle_scsiint()
1631 ahc_outb(ahc, CLRSINT1, CLRSCSIPERR); in ahc_handle_scsiint()
1643 if ((ahc_inb(ahc, SSTAT1) & SCSIPERR) != 0 in ahc_handle_scsiint()
1659 ahc_print_path(ahc, scb); in ahc_handle_scsiint()
1662 printk("%s:%c:%d: ", ahc_name(ahc), intr_channel, in ahc_handle_scsiint()
1663 SCSIID_TARGET(ahc, ahc_inb(ahc, SAVED_SCSIID))); in ahc_handle_scsiint()
1664 scsirate = ahc_inb(ahc, SCSIRATE); in ahc_handle_scsiint()
1669 ahc_inw(ahc, SEQADDR0), in ahc_handle_scsiint()
1671 if ((ahc->features & AHC_DT) != 0) { in ahc_handle_scsiint()
1687 if ((ahc->features & AHC_DT) != 0 in ahc_handle_scsiint()
1705 if (ahc->msg_type != MSG_TYPE_NONE) in ahc_handle_scsiint()
1706 ahc->send_msg_perror = TRUE; in ahc_handle_scsiint()
1708 ahc_outb(ahc, MSG_OUT, mesg_out); in ahc_handle_scsiint()
1715 ahc_fetch_devinfo(ahc, &devinfo); in ahc_handle_scsiint()
1716 ahc_force_renegotiation(ahc, &devinfo); in ahc_handle_scsiint()
1718 ahc_outb(ahc, CLRINT, CLRSCSIINT); in ahc_handle_scsiint()
1719 ahc_unpause(ahc); in ahc_handle_scsiint()
1724 ahc_outb(ahc, SCSISEQ, 0); in ahc_handle_scsiint()
1727 ahc_clear_msg_state(ahc); in ahc_handle_scsiint()
1730 ahc_outb(ahc, SIMODE1, ahc_inb(ahc, SIMODE1) & ~ENBUSFREE); in ahc_handle_scsiint()
1731 ahc_outb(ahc, CLRSINT1, CLRSELTIMEO|CLRBUSFREE|CLRSCSIPERR); in ahc_handle_scsiint()
1741 ahc_outb(ahc, CLRSINT0, CLRSELINGO); in ahc_handle_scsiint()
1743 scbptr = ahc_inb(ahc, WAITING_SCBH); in ahc_handle_scsiint()
1744 ahc_outb(ahc, SCBPTR, scbptr); in ahc_handle_scsiint()
1745 scb_index = ahc_inb(ahc, SCB_TAG); in ahc_handle_scsiint()
1747 scb = ahc_lookup_scb(ahc, scb_index); in ahc_handle_scsiint()
1751 ahc_name(ahc), scbptr, scb_index); in ahc_handle_scsiint()
1752 ahc_dump_card_state(ahc); in ahc_handle_scsiint()
1757 ahc_print_path(ahc, scb); in ahc_handle_scsiint()
1762 ahc_scb_devinfo(ahc, &devinfo, scb); in ahc_handle_scsiint()
1764 ahc_freeze_devq(ahc, scb); in ahc_handle_scsiint()
1772 ahc_handle_devreset(ahc, &devinfo, in ahc_handle_scsiint()
1777 ahc_outb(ahc, CLRINT, CLRSCSIINT); in ahc_handle_scsiint()
1778 ahc_restart(ahc); in ahc_handle_scsiint()
1780 && (ahc_inb(ahc, SIMODE1) & ENBUSFREE) != 0) { in ahc_handle_scsiint()
1796 ahc_outb(ahc, SCSISEQ, in ahc_handle_scsiint()
1797 ahc_inb(ahc, SCSISEQ) & (ENSELI|ENRSELI|ENAUTOATNP)); in ahc_handle_scsiint()
1805 ahc_outb(ahc, SIMODE1, ahc_inb(ahc, SIMODE1) & ~ENBUSFREE); in ahc_handle_scsiint()
1806 ahc_outb(ahc, CLRSINT1, CLRBUSFREE|CLRSCSIPERR); in ahc_handle_scsiint()
1814 lastphase = ahc_inb(ahc, LASTPHASE); in ahc_handle_scsiint()
1815 saved_scsiid = ahc_inb(ahc, SAVED_SCSIID); in ahc_handle_scsiint()
1816 saved_lun = ahc_inb(ahc, SAVED_LUN); in ahc_handle_scsiint()
1817 target = SCSIID_TARGET(ahc, saved_scsiid); in ahc_handle_scsiint()
1819 channel = SCSIID_CHANNEL(ahc, saved_scsiid); in ahc_handle_scsiint()
1828 if (ahc_sent_msg(ahc, AHCMSG_1B, MSG_ABORT_TAG, TRUE) in ahc_handle_scsiint()
1829 || ahc_sent_msg(ahc, AHCMSG_1B, MSG_ABORT, TRUE)) { in ahc_handle_scsiint()
1830 if (ahc->msgout_buf[ahc->msgout_index - 1] in ahc_handle_scsiint()
1833 ahc_print_path(ahc, scb); in ahc_handle_scsiint()
1837 ahc_abort_scbs(ahc, target, channel, in ahc_handle_scsiint()
1842 } else if (ahc_sent_msg(ahc, AHCMSG_1B, in ahc_handle_scsiint()
1852 && ahc_match_scb(ahc, scb, target, channel, in ahc_handle_scsiint()
1865 ahc_handle_devreset(ahc, &devinfo, in ahc_handle_scsiint()
1870 } else if (ahc_sent_msg(ahc, AHCMSG_EXT, in ahc_handle_scsiint()
1879 tinfo = ahc_fetch_transinfo(ahc, in ahc_handle_scsiint()
1887 ahc_qinfifo_requeue_tail(ahc, scb); in ahc_handle_scsiint()
1889 } else if (ahc_sent_msg(ahc, AHCMSG_EXT, in ahc_handle_scsiint()
1895 ahc_set_width(ahc, &devinfo, in ahc_handle_scsiint()
1899 ahc_qinfifo_requeue_tail(ahc, scb); in ahc_handle_scsiint()
1901 } else if (ahc_sent_msg(ahc, AHCMSG_EXT, in ahc_handle_scsiint()
1907 ahc_set_syncrate(ahc, &devinfo, in ahc_handle_scsiint()
1913 ahc_qinfifo_requeue_tail(ahc, scb); in ahc_handle_scsiint()
1927 ahc_print_path(ahc, scb); in ahc_handle_scsiint()
1928 ahc_abort_scbs(ahc, target, channel, in ahc_handle_scsiint()
1937 printk("%s: ", ahc_name(ahc)); in ahc_handle_scsiint()
1950 ahc_force_renegotiation(ahc, &devinfo); in ahc_handle_scsiint()
1955 ahc_inb(ahc, SEQADDR0) in ahc_handle_scsiint()
1956 | (ahc_inb(ahc, SEQADDR1) << 8)); in ahc_handle_scsiint()
1958 ahc_outb(ahc, CLRINT, CLRSCSIINT); in ahc_handle_scsiint()
1959 ahc_restart(ahc); in ahc_handle_scsiint()
1962 ahc_name(ahc), status); in ahc_handle_scsiint()
1963 ahc_outb(ahc, CLRINT, CLRSCSIINT); in ahc_handle_scsiint()
1972 ahc_force_renegotiation(struct ahc_softc *ahc, struct ahc_devinfo *devinfo) in ahc_force_renegotiation() argument
1977 targ_info = ahc_fetch_transinfo(ahc, in ahc_force_renegotiation()
1982 ahc_update_neg_request(ahc, devinfo, tstate, in ahc_force_renegotiation()
1988 ahc_clear_critical_section(struct ahc_softc *ahc) in ahc_clear_critical_section() argument
1995 if (ahc->num_critical_sections == 0) in ahc_clear_critical_section()
2007 seqaddr = ahc_inb(ahc, SEQADDR0) in ahc_clear_critical_section()
2008 | (ahc_inb(ahc, SEQADDR1) << 8); in ahc_clear_critical_section()
2017 cs = ahc->critical_sections; in ahc_clear_critical_section()
2018 for (i = 0; i < ahc->num_critical_sections; i++, cs++) { in ahc_clear_critical_section()
2024 if (i == ahc->num_critical_sections) in ahc_clear_critical_section()
2029 ahc_name(ahc)); in ahc_clear_critical_section()
2030 ahc_dump_card_state(ahc); in ahc_clear_critical_section()
2043 simode0 = ahc_inb(ahc, SIMODE0); in ahc_clear_critical_section()
2044 ahc_outb(ahc, SIMODE0, 0); in ahc_clear_critical_section()
2045 simode1 = ahc_inb(ahc, SIMODE1); in ahc_clear_critical_section()
2046 if ((ahc->features & AHC_DT) != 0) in ahc_clear_critical_section()
2055 ahc_outb(ahc, SIMODE1, simode1 & ENBUSFREE); in ahc_clear_critical_section()
2057 ahc_outb(ahc, SIMODE1, 0); in ahc_clear_critical_section()
2058 ahc_outb(ahc, CLRINT, CLRSCSIINT); in ahc_clear_critical_section()
2059 ahc_outb(ahc, SEQCTL, ahc->seqctl | STEP); in ahc_clear_critical_section()
2062 if ((ahc->features & AHC_DT) != 0) { in ahc_clear_critical_section()
2063 ahc_outb(ahc, CLRSINT1, CLRBUSFREE); in ahc_clear_critical_section()
2064 ahc_outb(ahc, CLRINT, CLRSCSIINT); in ahc_clear_critical_section()
2066 ahc_outb(ahc, HCNTRL, ahc->unpause); in ahc_clear_critical_section()
2067 while (!ahc_is_paused(ahc)) in ahc_clear_critical_section()
2071 ahc_outb(ahc, SIMODE0, simode0); in ahc_clear_critical_section()
2072 ahc_outb(ahc, SIMODE1, simode1); in ahc_clear_critical_section()
2073 ahc_outb(ahc, SEQCTL, ahc->seqctl); in ahc_clear_critical_section()
2081 ahc_clear_intstat(struct ahc_softc *ahc) in ahc_clear_intstat() argument
2084 ahc_outb(ahc, CLRSINT1, CLRSELTIMEO|CLRATNO|CLRSCSIRSTI in ahc_clear_intstat()
2087 ahc_flush_device_writes(ahc); in ahc_clear_intstat()
2088 ahc_outb(ahc, CLRSINT0, CLRSELDO|CLRSELDI|CLRSELINGO); in ahc_clear_intstat()
2089 ahc_flush_device_writes(ahc); in ahc_clear_intstat()
2090 ahc_outb(ahc, CLRINT, CLRSCSIINT); in ahc_clear_intstat()
2091 ahc_flush_device_writes(ahc); in ahc_clear_intstat()
2140 ahc_alloc_tstate(struct ahc_softc *ahc, u_int scsi_id, char channel) in ahc_alloc_tstate() argument
2146 master_tstate = ahc->enabled_targets[ahc->our_id]; in ahc_alloc_tstate()
2149 master_tstate = ahc->enabled_targets[ahc->our_id_b + 8]; in ahc_alloc_tstate()
2151 if (ahc->enabled_targets[scsi_id] != NULL in ahc_alloc_tstate()
2152 && ahc->enabled_targets[scsi_id] != master_tstate) in ahc_alloc_tstate()
2154 ahc_name(ahc)); in ahc_alloc_tstate()
2177 ahc->enabled_targets[scsi_id] = tstate; in ahc_alloc_tstate()
2187 ahc_free_tstate(struct ahc_softc *ahc, u_int scsi_id, char channel, int force) in ahc_free_tstate() argument
2195 if (((channel == 'B' && scsi_id == ahc->our_id_b) in ahc_free_tstate()
2196 || (channel == 'A' && scsi_id == ahc->our_id)) in ahc_free_tstate()
2202 tstate = ahc->enabled_targets[scsi_id]; in ahc_free_tstate()
2205 ahc->enabled_targets[scsi_id] = NULL; in ahc_free_tstate()
2216 ahc_devlimited_syncrate(struct ahc_softc *ahc, in ahc_devlimited_syncrate() argument
2223 if ((ahc->features & AHC_ULTRA2) != 0) { in ahc_devlimited_syncrate()
2224 if ((ahc_inb(ahc, SBLKCTL) & ENAB40) != 0 in ahc_devlimited_syncrate()
2225 && (ahc_inb(ahc, SSTAT2) & EXP_ACTIVE) == 0) { in ahc_devlimited_syncrate()
2232 } else if ((ahc->features & AHC_ULTRA) != 0) { in ahc_devlimited_syncrate()
2262 return (ahc_find_syncrate(ahc, period, ppr_options, maxsync)); in ahc_devlimited_syncrate()
2271 ahc_find_syncrate(struct ahc_softc *ahc, u_int *period, in ahc_find_syncrate() argument
2276 if ((ahc->features & AHC_DT) == 0) in ahc_find_syncrate()
2286 if ((ahc->features & (AHC_DT | AHC_ULTRA2)) == 0 in ahc_find_syncrate()
2289 if ((ahc->features & (AHC_DT | AHC_ULTRA2 | AHC_ULTRA)) == 0 in ahc_find_syncrate()
2301 if ((ahc->features & AHC_ULTRA2) != 0 in ahc_find_syncrate()
2332 || ((ahc->features & AHC_ULTRA2) != 0 in ahc_find_syncrate()
2347 ahc_find_period(struct ahc_softc *ahc, u_int scsirate, u_int maxsync) in ahc_find_period() argument
2351 if ((ahc->features & AHC_ULTRA2) != 0) in ahc_find_period()
2357 if ((ahc->features & AHC_DT) == 0 && maxsync < AHC_SYNCRATE_ULTRA2) in ahc_find_period()
2359 if ((ahc->features & (AHC_DT | AHC_ULTRA2)) == 0 in ahc_find_period()
2362 if ((ahc->features & (AHC_DT | AHC_ULTRA2 | AHC_ULTRA)) == 0 in ahc_find_period()
2370 if ((ahc->features & AHC_ULTRA2) != 0) { in ahc_find_period()
2388 ahc_validate_offset(struct ahc_softc *ahc, in ahc_validate_offset() argument
2398 } else if ((ahc->features & AHC_ULTRA2) != 0) { in ahc_validate_offset()
2420 ahc_validate_width(struct ahc_softc *ahc, struct ahc_initiator_tinfo *tinfo, in ahc_validate_width() argument
2425 if (ahc->features & AHC_WIDE) { in ahc_validate_width()
2450 ahc_update_neg_request(struct ahc_softc *ahc, struct ahc_devinfo *devinfo, in ahc_update_neg_request() argument
2464 if ((ahc->features & AHC_WIDE) != 0) in ahc_update_neg_request()
2493 ahc_set_syncrate(struct ahc_softc *ahc, struct ahc_devinfo *devinfo, in ahc_set_syncrate() argument
2513 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, devinfo->our_scsiid, in ahc_set_syncrate()
2540 if ((ahc->features & AHC_ULTRA2) != 0) { in ahc_set_syncrate()
2569 sxfrctl0 = ahc_inb(ahc, SXFRCTL0); in ahc_set_syncrate()
2573 ahc_outb(ahc, SXFRCTL0, sxfrctl0); in ahc_set_syncrate()
2577 ahc_outb(ahc, SCSIRATE, scsirate); in ahc_set_syncrate()
2578 if ((ahc->features & AHC_ULTRA2) != 0) in ahc_set_syncrate()
2579 ahc_outb(ahc, SCSIOFFSET, offset); in ahc_set_syncrate()
2587 ahc_send_async(ahc, devinfo->channel, devinfo->target, in ahc_set_syncrate()
2592 "offset = 0x%x\n", ahc_name(ahc), in ahc_set_syncrate()
2599 ahc_name(ahc), devinfo->target); in ahc_set_syncrate()
2604 update_needed += ahc_update_neg_request(ahc, devinfo, tstate, in ahc_set_syncrate()
2608 ahc_update_pending_scbs(ahc); in ahc_set_syncrate()
2620 ahc_set_width(struct ahc_softc *ahc, struct ahc_devinfo *devinfo, in ahc_set_width() argument
2631 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, devinfo->our_scsiid, in ahc_set_width()
2653 ahc_outb(ahc, SCSIRATE, scsirate); in ahc_set_width()
2657 ahc_send_async(ahc, devinfo->channel, devinfo->target, in ahc_set_width()
2661 ahc_name(ahc), devinfo->target, in ahc_set_width()
2666 update_needed += ahc_update_neg_request(ahc, devinfo, tstate, in ahc_set_width()
2669 ahc_update_pending_scbs(ahc); in ahc_set_width()
2676 ahc_set_tags(struct ahc_softc *ahc, struct scsi_cmnd *cmd, in ahc_set_tags() argument
2681 ahc_platform_set_tags(ahc, sdev, devinfo, alg); in ahc_set_tags()
2682 ahc_send_async(ahc, devinfo->channel, devinfo->target, in ahc_set_tags()
2692 ahc_update_pending_scbs(struct ahc_softc *ahc) in ahc_update_pending_scbs() argument
2705 LIST_FOREACH(pending_scb, &ahc->pending_scbs, pending_links) { in ahc_update_pending_scbs()
2711 ahc_scb_devinfo(ahc, &devinfo, pending_scb); in ahc_update_pending_scbs()
2712 tinfo = ahc_fetch_transinfo(ahc, devinfo.channel, in ahc_update_pending_scbs()
2726 ahc_sync_scb(ahc, pending_scb, in ahc_update_pending_scbs()
2734 if (ahc_is_paused(ahc)) { in ahc_update_pending_scbs()
2738 ahc_pause(ahc); in ahc_update_pending_scbs()
2741 saved_scbptr = ahc_inb(ahc, SCBPTR); in ahc_update_pending_scbs()
2743 for (i = 0; i < ahc->scb_data->maxhscbs; i++) { in ahc_update_pending_scbs()
2748 ahc_outb(ahc, SCBPTR, i); in ahc_update_pending_scbs()
2749 scb_tag = ahc_inb(ahc, SCB_TAG); in ahc_update_pending_scbs()
2750 pending_scb = ahc_lookup_scb(ahc, scb_tag); in ahc_update_pending_scbs()
2755 control = ahc_inb(ahc, SCB_CONTROL); in ahc_update_pending_scbs()
2758 ahc_outb(ahc, SCB_CONTROL, control); in ahc_update_pending_scbs()
2759 ahc_outb(ahc, SCB_SCSIRATE, pending_hscb->scsirate); in ahc_update_pending_scbs()
2760 ahc_outb(ahc, SCB_SCSIOFFSET, pending_hscb->scsioffset); in ahc_update_pending_scbs()
2762 ahc_outb(ahc, SCBPTR, saved_scbptr); in ahc_update_pending_scbs()
2765 ahc_unpause(ahc); in ahc_update_pending_scbs()
2770 ahc_fetch_devinfo(struct ahc_softc *ahc, struct ahc_devinfo *devinfo) in ahc_fetch_devinfo() argument
2776 if (ahc_inb(ahc, SSTAT0) & TARGET) in ahc_fetch_devinfo()
2782 && (ahc->features & AHC_MULTI_TID) != 0 in ahc_fetch_devinfo()
2783 && (ahc_inb(ahc, SEQ_FLAGS) in ahc_fetch_devinfo()
2786 our_id = ahc_inb(ahc, TARGIDIN) & OID; in ahc_fetch_devinfo()
2787 } else if ((ahc->features & AHC_ULTRA2) != 0) in ahc_fetch_devinfo()
2788 our_id = ahc_inb(ahc, SCSIID_ULTRA2) & OID; in ahc_fetch_devinfo()
2790 our_id = ahc_inb(ahc, SCSIID) & OID; in ahc_fetch_devinfo()
2792 saved_scsiid = ahc_inb(ahc, SAVED_SCSIID); in ahc_fetch_devinfo()
2795 SCSIID_TARGET(ahc, saved_scsiid), in ahc_fetch_devinfo()
2796 ahc_inb(ahc, SAVED_LUN), in ahc_fetch_devinfo()
2797 SCSIID_CHANNEL(ahc, saved_scsiid), in ahc_fetch_devinfo()
2835 ahc_print_devinfo(struct ahc_softc *ahc, struct ahc_devinfo *devinfo) in ahc_print_devinfo() argument
2837 printk("%s:%c:%d:%d: ", ahc_name(ahc), devinfo->channel, in ahc_print_devinfo()
2842 ahc_scb_devinfo(struct ahc_softc *ahc, struct ahc_devinfo *devinfo, in ahc_scb_devinfo() argument
2852 ahc_compile_devinfo(devinfo, our_id, SCB_GET_TARGET(ahc, scb), in ahc_scb_devinfo()
2853 SCB_GET_LUN(scb), SCB_GET_CHANNEL(ahc, scb), role); in ahc_scb_devinfo()
2859 ahc_assert_atn(struct ahc_softc *ahc) in ahc_assert_atn() argument
2864 if ((ahc->features & AHC_DT) == 0) in ahc_assert_atn()
2865 scsisigo |= ahc_inb(ahc, SCSISIGI); in ahc_assert_atn()
2866 ahc_outb(ahc, SCSISIGO, scsisigo); in ahc_assert_atn()
2876 ahc_setup_initiator_msgout(struct ahc_softc *ahc, struct ahc_devinfo *devinfo, in ahc_setup_initiator_msgout() argument
2884 ahc->msgout_index = 0; in ahc_setup_initiator_msgout()
2885 ahc->msgout_len = 0; in ahc_setup_initiator_msgout()
2888 && ahc_inb(ahc, MSG_OUT) == MSG_IDENTIFYFLAG) { in ahc_setup_initiator_msgout()
2894 ahc->msgout_buf[ahc->msgout_index++] = identify_msg; in ahc_setup_initiator_msgout()
2895 ahc->msgout_len++; in ahc_setup_initiator_msgout()
2898 ahc->msgout_buf[ahc->msgout_index++] = in ahc_setup_initiator_msgout()
2900 ahc->msgout_buf[ahc->msgout_index++] = scb->hscb->tag; in ahc_setup_initiator_msgout()
2901 ahc->msgout_len += 2; in ahc_setup_initiator_msgout()
2906 ahc->msgout_buf[ahc->msgout_index++] = MSG_BUS_DEV_RESET; in ahc_setup_initiator_msgout()
2907 ahc->msgout_len++; in ahc_setup_initiator_msgout()
2908 ahc_print_path(ahc, scb); in ahc_setup_initiator_msgout()
2917 ahc_outb(ahc, SCSISEQ, (ahc_inb(ahc, SCSISEQ) & ~ENSELO)); in ahc_setup_initiator_msgout()
2920 ahc->msgout_buf[ahc->msgout_index++] = MSG_ABORT_TAG; in ahc_setup_initiator_msgout()
2922 ahc->msgout_buf[ahc->msgout_index++] = MSG_ABORT; in ahc_setup_initiator_msgout()
2923 ahc->msgout_len++; in ahc_setup_initiator_msgout()
2924 ahc_print_path(ahc, scb); in ahc_setup_initiator_msgout()
2934 ahc_outb(ahc, SCSISEQ, (ahc_inb(ahc, SCSISEQ) & ~ENSELO)); in ahc_setup_initiator_msgout()
2936 ahc_build_transfer_msg(ahc, devinfo); in ahc_setup_initiator_msgout()
2944 ahc_inb(ahc, MSG_OUT), scb->flags); in ahc_setup_initiator_msgout()
2951 ahc_outb(ahc, SCB_CONTROL, ahc_inb(ahc, SCB_CONTROL) & ~MK_MESSAGE); in ahc_setup_initiator_msgout()
2953 ahc->msgout_index = 0; in ahc_setup_initiator_msgout()
2954 ahc->msg_type = MSG_TYPE_INITIATOR_MSGOUT; in ahc_setup_initiator_msgout()
2962 ahc_build_transfer_msg(struct ahc_softc *ahc, struct ahc_devinfo *devinfo) in ahc_build_transfer_msg() argument
2979 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, devinfo->our_scsiid, in ahc_build_transfer_msg()
2993 rate = ahc_devlimited_syncrate(ahc, tinfo, &period, in ahc_build_transfer_msg()
3014 if ((ahc->features & AHC_WIDE) != 0) in ahc_build_transfer_msg()
3020 ahc_print_devinfo(ahc, devinfo); in ahc_build_transfer_msg()
3040 ahc_validate_offset(ahc, tinfo, rate, &offset, in ahc_build_transfer_msg()
3045 ahc_construct_ppr(ahc, devinfo, period, offset, in ahc_build_transfer_msg()
3048 ahc_construct_sdtr(ahc, devinfo, period, offset); in ahc_build_transfer_msg()
3051 ahc_construct_wdtr(ahc, devinfo, tinfo->goal.width); in ahc_build_transfer_msg()
3060 ahc_construct_sdtr(struct ahc_softc *ahc, struct ahc_devinfo *devinfo, in ahc_construct_sdtr() argument
3065 ahc->msgout_index += spi_populate_sync_msg( in ahc_construct_sdtr()
3066 ahc->msgout_buf + ahc->msgout_index, period, offset); in ahc_construct_sdtr()
3067 ahc->msgout_len += 5; in ahc_construct_sdtr()
3070 ahc_name(ahc), devinfo->channel, devinfo->target, in ahc_construct_sdtr()
3080 ahc_construct_wdtr(struct ahc_softc *ahc, struct ahc_devinfo *devinfo, in ahc_construct_wdtr() argument
3083 ahc->msgout_index += spi_populate_width_msg( in ahc_construct_wdtr()
3084 ahc->msgout_buf + ahc->msgout_index, bus_width); in ahc_construct_wdtr()
3085 ahc->msgout_len += 4; in ahc_construct_wdtr()
3088 ahc_name(ahc), devinfo->channel, devinfo->target, in ahc_construct_wdtr()
3098 ahc_construct_ppr(struct ahc_softc *ahc, struct ahc_devinfo *devinfo, in ahc_construct_ppr() argument
3104 ahc->msgout_index += spi_populate_ppr_msg( in ahc_construct_ppr()
3105 ahc->msgout_buf + ahc->msgout_index, period, offset, in ahc_construct_ppr()
3107 ahc->msgout_len += 8; in ahc_construct_ppr()
3110 "offset %x, ppr_options %x\n", ahc_name(ahc), in ahc_construct_ppr()
3120 ahc_clear_msg_state(struct ahc_softc *ahc) in ahc_clear_msg_state() argument
3122 ahc->msgout_len = 0; in ahc_clear_msg_state()
3123 ahc->msgin_index = 0; in ahc_clear_msg_state()
3124 ahc->msg_type = MSG_TYPE_NONE; in ahc_clear_msg_state()
3125 if ((ahc_inb(ahc, SCSISIGI) & ATNI) != 0) { in ahc_clear_msg_state()
3130 ahc_outb(ahc, CLRSINT1, CLRATNO); in ahc_clear_msg_state()
3132 ahc_outb(ahc, MSG_OUT, MSG_NOOP); in ahc_clear_msg_state()
3133 ahc_outb(ahc, SEQ_FLAGS2, in ahc_clear_msg_state()
3134 ahc_inb(ahc, SEQ_FLAGS2) & ~TARGET_MSG_PENDING); in ahc_clear_msg_state()
3138 ahc_handle_proto_violation(struct ahc_softc *ahc) in ahc_handle_proto_violation() argument
3148 ahc_fetch_devinfo(ahc, &devinfo); in ahc_handle_proto_violation()
3149 scbid = ahc_inb(ahc, SCB_TAG); in ahc_handle_proto_violation()
3150 scb = ahc_lookup_scb(ahc, scbid); in ahc_handle_proto_violation()
3151 seq_flags = ahc_inb(ahc, SEQ_FLAGS); in ahc_handle_proto_violation()
3152 curphase = ahc_inb(ahc, SCSISIGI) & PHASE_MASK; in ahc_handle_proto_violation()
3153 lastphase = ahc_inb(ahc, LASTPHASE); in ahc_handle_proto_violation()
3161 ahc_print_devinfo(ahc, &devinfo); in ahc_handle_proto_violation()
3170 ahc_print_devinfo(ahc, &devinfo); in ahc_handle_proto_violation()
3176 ahc_print_path(ahc, scb); in ahc_handle_proto_violation()
3178 } else if ((ahc_inb(ahc, SCB_CONTROL) & STATUS_RCVD) == 0) { in ahc_handle_proto_violation()
3186 ahc_print_path(ahc, scb); in ahc_handle_proto_violation()
3189 ahc_print_path(ahc, scb); in ahc_handle_proto_violation()
3191 ahc_dump_card_state(ahc); in ahc_handle_proto_violation()
3203 found = ahc_reset_channel(ahc, 'A', TRUE); in ahc_handle_proto_violation()
3205 "%d SCBs aborted\n", ahc_name(ahc), 'A', found); in ahc_handle_proto_violation()
3212 ahc_outb(ahc, SCSISEQ, in ahc_handle_proto_violation()
3213 ahc_inb(ahc, SCSISEQ) & ~ENSELO); in ahc_handle_proto_violation()
3214 ahc_assert_atn(ahc); in ahc_handle_proto_violation()
3215 ahc_outb(ahc, MSG_OUT, HOST_MSG); in ahc_handle_proto_violation()
3217 ahc_print_devinfo(ahc, &devinfo); in ahc_handle_proto_violation()
3218 ahc->msgout_buf[0] = MSG_ABORT_TASK; in ahc_handle_proto_violation()
3219 ahc->msgout_len = 1; in ahc_handle_proto_violation()
3220 ahc->msgout_index = 0; in ahc_handle_proto_violation()
3221 ahc->msg_type = MSG_TYPE_INITIATOR_MSGOUT; in ahc_handle_proto_violation()
3223 ahc_print_path(ahc, scb); in ahc_handle_proto_violation()
3235 ahc_handle_message_phase(struct ahc_softc *ahc) in ahc_handle_message_phase() argument
3241 ahc_fetch_devinfo(ahc, &devinfo); in ahc_handle_message_phase()
3243 bus_phase = ahc_inb(ahc, SCSISIGI) & PHASE_MASK; in ahc_handle_message_phase()
3246 switch (ahc->msg_type) { in ahc_handle_message_phase()
3253 if (ahc->msgout_len == 0) in ahc_handle_message_phase()
3258 ahc_print_devinfo(ahc, &devinfo); in ahc_handle_message_phase()
3278 ahc_outb(ahc, CLRSINT1, CLRATNO); in ahc_handle_message_phase()
3279 ahc->send_msg_perror = FALSE; in ahc_handle_message_phase()
3280 ahc->msg_type = MSG_TYPE_INITIATOR_MSGIN; in ahc_handle_message_phase()
3281 ahc->msgin_index = 0; in ahc_handle_message_phase()
3288 if (ahc->send_msg_perror) { in ahc_handle_message_phase()
3289 ahc_outb(ahc, CLRSINT1, CLRATNO); in ahc_handle_message_phase()
3290 ahc_outb(ahc, CLRSINT1, CLRREQINIT); in ahc_handle_message_phase()
3293 printk(" byte 0x%x\n", ahc->send_msg_perror); in ahc_handle_message_phase()
3295 ahc_outb(ahc, SCSIDATL, MSG_PARITY_ERROR); in ahc_handle_message_phase()
3299 msgdone = ahc->msgout_index == ahc->msgout_len; in ahc_handle_message_phase()
3306 ahc->msgout_index = 0; in ahc_handle_message_phase()
3307 ahc_assert_atn(ahc); in ahc_handle_message_phase()
3310 lastbyte = ahc->msgout_index == (ahc->msgout_len - 1); in ahc_handle_message_phase()
3313 ahc_outb(ahc, CLRSINT1, CLRATNO); in ahc_handle_message_phase()
3320 ahc_outb(ahc, CLRSINT1, CLRREQINIT); in ahc_handle_message_phase()
3324 ahc->msgout_buf[ahc->msgout_index]); in ahc_handle_message_phase()
3326 ahc_outb(ahc, SCSIDATL, ahc->msgout_buf[ahc->msgout_index++]); in ahc_handle_message_phase()
3336 ahc_print_devinfo(ahc, &devinfo); in ahc_handle_message_phase()
3349 ahc->msgin_index = 0; in ahc_handle_message_phase()
3351 && (ahc->send_msg_perror == TRUE in ahc_handle_message_phase()
3352 || (ahc->msgout_len != 0 in ahc_handle_message_phase()
3353 && ahc->msgout_index == 0))) { in ahc_handle_message_phase()
3354 ahc->msg_type = MSG_TYPE_INITIATOR_MSGOUT; in ahc_handle_message_phase()
3362 ahc->msgin_buf[ahc->msgin_index] = ahc_inb(ahc, SCSIBUSL); in ahc_handle_message_phase()
3366 ahc->msgin_buf[ahc->msgin_index]); in ahc_handle_message_phase()
3369 message_done = ahc_parse_msg(ahc, &devinfo); in ahc_handle_message_phase()
3376 ahc->msgin_index = 0; in ahc_handle_message_phase()
3383 if (ahc->msgout_len != 0) { in ahc_handle_message_phase()
3386 ahc_print_devinfo(ahc, &devinfo); in ahc_handle_message_phase()
3390 ahc_assert_atn(ahc); in ahc_handle_message_phase()
3393 ahc->msgin_index++; in ahc_handle_message_phase()
3399 ahc_outb(ahc, CLRSINT1, CLRREQINIT); in ahc_handle_message_phase()
3400 ahc_inb(ahc, SCSIDATL); in ahc_handle_message_phase()
3409 if (ahc->msgout_len == 0) in ahc_handle_message_phase()
3418 if ((ahc_inb(ahc, SCSISIGI) & ATNI) != 0 in ahc_handle_message_phase()
3419 && ahc->msgout_index > 0) in ahc_handle_message_phase()
3432 ahc->msg_type = MSG_TYPE_TARGET_MSGOUT; in ahc_handle_message_phase()
3433 ahc_outb(ahc, SCSISIGO, P_MESGOUT | BSYO); in ahc_handle_message_phase()
3434 ahc->msgin_index = 0; in ahc_handle_message_phase()
3436 ahc_inb(ahc, SCSIDATL); in ahc_handle_message_phase()
3437 ahc_outb(ahc, SXFRCTL0, in ahc_handle_message_phase()
3438 ahc_inb(ahc, SXFRCTL0) | SPIOEN); in ahc_handle_message_phase()
3442 msgdone = ahc->msgout_index == ahc->msgout_len; in ahc_handle_message_phase()
3444 ahc_outb(ahc, SXFRCTL0, in ahc_handle_message_phase()
3445 ahc_inb(ahc, SXFRCTL0) & ~SPIOEN); in ahc_handle_message_phase()
3453 ahc_outb(ahc, SXFRCTL0, ahc_inb(ahc, SXFRCTL0) | SPIOEN); in ahc_handle_message_phase()
3454 ahc_outb(ahc, SCSIDATL, ahc->msgout_buf[ahc->msgout_index++]); in ahc_handle_message_phase()
3466 lastbyte = (ahc_inb(ahc, SCSISIGI) & ATNI) == 0; in ahc_handle_message_phase()
3473 ahc_outb(ahc, SXFRCTL0, ahc_inb(ahc, SXFRCTL0) & ~SPIOEN); in ahc_handle_message_phase()
3474 ahc->msgin_buf[ahc->msgin_index] = ahc_inb(ahc, SCSIDATL); in ahc_handle_message_phase()
3475 msgdone = ahc_parse_msg(ahc, &devinfo); in ahc_handle_message_phase()
3486 ahc->msgin_index++; in ahc_handle_message_phase()
3493 ahc->msgin_index = 0; in ahc_handle_message_phase()
3499 if (ahc->msgout_len != 0) { in ahc_handle_message_phase()
3500 ahc_outb(ahc, SCSISIGO, P_MESGIN | BSYO); in ahc_handle_message_phase()
3501 ahc_outb(ahc, SXFRCTL0, in ahc_handle_message_phase()
3502 ahc_inb(ahc, SXFRCTL0) | SPIOEN); in ahc_handle_message_phase()
3503 ahc->msg_type = MSG_TYPE_TARGET_MSGIN; in ahc_handle_message_phase()
3504 ahc->msgin_index = 0; in ahc_handle_message_phase()
3513 ahc_outb(ahc, SXFRCTL0, in ahc_handle_message_phase()
3514 ahc_inb(ahc, SXFRCTL0) | SPIOEN); in ahc_handle_message_phase()
3524 ahc_clear_msg_state(ahc); in ahc_handle_message_phase()
3525 ahc_outb(ahc, RETURN_1, EXIT_MSG_LOOP); in ahc_handle_message_phase()
3527 ahc_outb(ahc, RETURN_1, CONT_MSG_LOOP); in ahc_handle_message_phase()
3537 ahc_sent_msg(struct ahc_softc *ahc, ahc_msgtype type, u_int msgval, int full) in ahc_sent_msg() argument
3545 while (index < ahc->msgout_len) { in ahc_sent_msg()
3546 if (ahc->msgout_buf[index] == MSG_EXTENDED) { in ahc_sent_msg()
3549 end_index = index + 1 + ahc->msgout_buf[index + 1]; in ahc_sent_msg()
3550 if (ahc->msgout_buf[index+2] == msgval in ahc_sent_msg()
3554 if (ahc->msgout_index > end_index) in ahc_sent_msg()
3556 } else if (ahc->msgout_index > index) in ahc_sent_msg()
3560 } else if (ahc->msgout_buf[index] >= MSG_SIMPLE_TASK in ahc_sent_msg()
3561 && ahc->msgout_buf[index] <= MSG_IGN_WIDE_RESIDUE) { in ahc_sent_msg()
3568 && ahc->msgout_buf[index] == msgval in ahc_sent_msg()
3569 && ahc->msgout_index > index) in ahc_sent_msg()
3584 ahc_parse_msg(struct ahc_softc *ahc, struct ahc_devinfo *devinfo) in ahc_parse_msg() argument
3596 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, devinfo->our_scsiid, in ahc_parse_msg()
3611 switch (ahc->msgin_buf[0]) { in ahc_parse_msg()
3624 response = ahc_handle_msg_reject(ahc, devinfo); in ahc_parse_msg()
3632 if (ahc->msgin_index < 2) in ahc_parse_msg()
3634 switch (ahc->msgin_buf[2]) { in ahc_parse_msg()
3643 if (ahc->msgin_buf[1] != MSG_EXT_SDTR_LEN) { in ahc_parse_msg()
3655 if (ahc->msgin_index < (MSG_EXT_SDTR_LEN + 1)) in ahc_parse_msg()
3658 period = ahc->msgin_buf[3]; in ahc_parse_msg()
3660 saved_offset = offset = ahc->msgin_buf[4]; in ahc_parse_msg()
3661 syncrate = ahc_devlimited_syncrate(ahc, tinfo, &period, in ahc_parse_msg()
3664 ahc_validate_offset(ahc, tinfo, syncrate, &offset, in ahc_parse_msg()
3671 ahc_name(ahc), devinfo->channel, in ahc_parse_msg()
3673 ahc->msgin_buf[3], saved_offset, in ahc_parse_msg()
3676 ahc_set_syncrate(ahc, devinfo, in ahc_parse_msg()
3687 if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_SDTR, TRUE)) { in ahc_parse_msg()
3701 ahc_name(ahc), devinfo->channel, in ahc_parse_msg()
3704 ahc->msgout_index = 0; in ahc_parse_msg()
3705 ahc->msgout_len = 0; in ahc_parse_msg()
3706 ahc_construct_sdtr(ahc, devinfo, in ahc_parse_msg()
3708 ahc->msgout_index = 0; in ahc_parse_msg()
3721 if (ahc->msgin_buf[1] != MSG_EXT_WDTR_LEN) { in ahc_parse_msg()
3733 if (ahc->msgin_index < (MSG_EXT_WDTR_LEN + 1)) in ahc_parse_msg()
3736 bus_width = ahc->msgin_buf[3]; in ahc_parse_msg()
3738 ahc_validate_width(ahc, tinfo, &bus_width, in ahc_parse_msg()
3743 ahc_name(ahc), devinfo->channel, in ahc_parse_msg()
3748 if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_WDTR, TRUE)) { in ahc_parse_msg()
3759 ahc_name(ahc), devinfo->channel, in ahc_parse_msg()
3772 ahc_name(ahc), devinfo->channel, in ahc_parse_msg()
3775 ahc->msgout_index = 0; in ahc_parse_msg()
3776 ahc->msgout_len = 0; in ahc_parse_msg()
3777 ahc_construct_wdtr(ahc, devinfo, bus_width); in ahc_parse_msg()
3778 ahc->msgout_index = 0; in ahc_parse_msg()
3791 ahc_update_neg_request(ahc, devinfo, tstate, in ahc_parse_msg()
3793 ahc_set_width(ahc, devinfo, bus_width, in ahc_parse_msg()
3801 ahc->msgout_index = 0; in ahc_parse_msg()
3802 ahc->msgout_len = 0; in ahc_parse_msg()
3803 ahc_build_transfer_msg(ahc, devinfo); in ahc_parse_msg()
3804 ahc->msgout_index = 0; in ahc_parse_msg()
3821 if (ahc->msgin_buf[1] != MSG_EXT_PPR_LEN) { in ahc_parse_msg()
3833 if (ahc->msgin_index < (MSG_EXT_PPR_LEN + 1)) in ahc_parse_msg()
3836 period = ahc->msgin_buf[3]; in ahc_parse_msg()
3837 offset = ahc->msgin_buf[5]; in ahc_parse_msg()
3838 bus_width = ahc->msgin_buf[6]; in ahc_parse_msg()
3840 ppr_options = ahc->msgin_buf[7]; in ahc_parse_msg()
3861 ahc_validate_width(ahc, tinfo, &bus_width, in ahc_parse_msg()
3863 syncrate = ahc_devlimited_syncrate(ahc, tinfo, &period, in ahc_parse_msg()
3866 ahc_validate_offset(ahc, tinfo, syncrate, in ahc_parse_msg()
3870 if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_PPR, TRUE)) { in ahc_parse_msg()
3890 ahc_name(ahc), devinfo->channel, in ahc_parse_msg()
3895 ahc_name(ahc), devinfo->channel, in ahc_parse_msg()
3897 ahc->msgout_index = 0; in ahc_parse_msg()
3898 ahc->msgout_len = 0; in ahc_parse_msg()
3899 ahc_construct_ppr(ahc, devinfo, period, offset, in ahc_parse_msg()
3901 ahc->msgout_index = 0; in ahc_parse_msg()
3909 ahc_name(ahc), devinfo->channel, in ahc_parse_msg()
3911 saved_width, ahc->msgin_buf[3], in ahc_parse_msg()
3915 ahc_set_width(ahc, devinfo, bus_width, in ahc_parse_msg()
3918 ahc_set_syncrate(ahc, devinfo, in ahc_parse_msg()
3935 ahc_handle_devreset(ahc, devinfo, in ahc_parse_msg()
3939 ahc_restart(ahc); in ahc_parse_msg()
3954 if (ahc->msgin_buf[0] == MSG_ABORT_TAG) in ahc_parse_msg()
3955 tag = ahc_inb(ahc, INITIATOR_TAG); in ahc_parse_msg()
3956 ahc_abort_scbs(ahc, devinfo->target, devinfo->channel, in ahc_parse_msg()
3960 tstate = ahc->enabled_targets[devinfo->our_scsiid]; in ahc_parse_msg()
3966 ahc_queue_lstate_event(ahc, lstate, in ahc_parse_msg()
3968 ahc->msgin_buf[0], in ahc_parse_msg()
3970 ahc_send_lstate_events(ahc, lstate); in ahc_parse_msg()
3973 ahc_restart(ahc); in ahc_parse_msg()
3988 ahc->msgout_index = 0; in ahc_parse_msg()
3989 ahc->msgout_len = 1; in ahc_parse_msg()
3990 ahc->msgout_buf[0] = MSG_MESSAGE_REJECT; in ahc_parse_msg()
3997 ahc->msgout_len = 0; in ahc_parse_msg()
4006 ahc_handle_msg_reject(struct ahc_softc *ahc, struct ahc_devinfo *devinfo) in ahc_handle_msg_reject() argument
4021 scb_index = ahc_inb(ahc, SCB_TAG); in ahc_handle_msg_reject()
4022 scb = ahc_lookup_scb(ahc, scb_index); in ahc_handle_msg_reject()
4023 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, in ahc_handle_msg_reject()
4027 last_msg = ahc_inb(ahc, LAST_MSG); in ahc_handle_msg_reject()
4029 if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_PPR, /*full*/FALSE)) { in ahc_handle_msg_reject()
4037 ahc_name(ahc), devinfo->channel, in ahc_handle_msg_reject()
4043 ahc->msgout_index = 0; in ahc_handle_msg_reject()
4044 ahc->msgout_len = 0; in ahc_handle_msg_reject()
4045 ahc_build_transfer_msg(ahc, devinfo); in ahc_handle_msg_reject()
4046 ahc->msgout_index = 0; in ahc_handle_msg_reject()
4048 } else if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_WDTR, /*full*/FALSE)) { in ahc_handle_msg_reject()
4052 "8bit transfers\n", ahc_name(ahc), in ahc_handle_msg_reject()
4054 ahc_set_width(ahc, devinfo, MSG_EXT_WDTR_BUS_8_BIT, in ahc_handle_msg_reject()
4067 ahc->msgout_index = 0; in ahc_handle_msg_reject()
4068 ahc->msgout_len = 0; in ahc_handle_msg_reject()
4069 ahc_build_transfer_msg(ahc, devinfo); in ahc_handle_msg_reject()
4070 ahc->msgout_index = 0; in ahc_handle_msg_reject()
4073 } else if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_SDTR, /*full*/FALSE)) { in ahc_handle_msg_reject()
4075 ahc_set_syncrate(ahc, devinfo, /*syncrate*/NULL, /*period*/0, in ahc_handle_msg_reject()
4081 ahc_name(ahc), devinfo->channel, in ahc_handle_msg_reject()
4091 "Performing non-tagged I/O\n", ahc_name(ahc), in ahc_handle_msg_reject()
4093 ahc_set_tags(ahc, scb->io_ctx, devinfo, AHC_QUEUE_NONE); in ahc_handle_msg_reject()
4098 ahc_name(ahc), devinfo->channel, devinfo->target, in ahc_handle_msg_reject()
4101 ahc_set_tags(ahc, scb->io_ctx, devinfo, AHC_QUEUE_BASIC); in ahc_handle_msg_reject()
4109 ahc_outb(ahc, SCB_CONTROL, in ahc_handle_msg_reject()
4110 ahc_inb(ahc, SCB_CONTROL) & mask); in ahc_handle_msg_reject()
4114 ahc_outb(ahc, MSG_OUT, MSG_IDENTIFYFLAG); in ahc_handle_msg_reject()
4115 ahc_assert_atn(ahc); in ahc_handle_msg_reject()
4121 if ((ahc->flags & AHC_SCB_BTT) == 0) { in ahc_handle_msg_reject()
4125 &(ahc->untagged_queues[devinfo->target_offset]); in ahc_handle_msg_reject()
4129 ahc_busy_tcl(ahc, BUILD_TCL(scb->hscb->scsiid, devinfo->lun), in ahc_handle_msg_reject()
4137 ahc_search_qinfifo(ahc, SCB_GET_TARGET(ahc, scb), in ahc_handle_msg_reject()
4138 SCB_GET_CHANNEL(ahc, scb), in ahc_handle_msg_reject()
4147 ahc_name(ahc), devinfo->channel, devinfo->target, in ahc_handle_msg_reject()
4157 ahc_handle_ign_wide_residue(struct ahc_softc *ahc, struct ahc_devinfo *devinfo) in ahc_handle_ign_wide_residue() argument
4162 scb_index = ahc_inb(ahc, SCB_TAG); in ahc_handle_ign_wide_residue()
4163 scb = ahc_lookup_scb(ahc, scb_index); in ahc_handle_ign_wide_residue()
4168 if ((ahc_inb(ahc, SEQ_FLAGS) & DPHASE) == 0 in ahc_handle_ign_wide_residue()
4184 sgptr = ahc_inb(ahc, SCB_RESIDUAL_SGPTR); in ahc_handle_ign_wide_residue()
4186 && (ahc_inb(ahc, SCB_LUN) & SCB_XFERLEN_ODD) != 0) { in ahc_handle_ign_wide_residue()
4200 sgptr = ahc_inl(ahc, SCB_RESIDUAL_SGPTR); in ahc_handle_ign_wide_residue()
4201 data_cnt = ahc_inl(ahc, SCB_RESIDUAL_DATACNT); in ahc_handle_ign_wide_residue()
4212 data_addr = ahc_inl(ahc, SHADDR); in ahc_handle_ign_wide_residue()
4246 ahc_outl(ahc, SCB_RESIDUAL_SGPTR, sgptr); in ahc_handle_ign_wide_residue()
4247 ahc_outl(ahc, SCB_RESIDUAL_DATACNT, data_cnt); in ahc_handle_ign_wide_residue()
4254 ahc_outb(ahc, SCB_LUN, in ahc_handle_ign_wide_residue()
4255 ahc_inb(ahc, SCB_LUN) ^ SCB_XFERLEN_ODD); in ahc_handle_ign_wide_residue()
4266 ahc_reinitialize_dataptrs(struct ahc_softc *ahc) in ahc_reinitialize_dataptrs() argument
4275 scb_index = ahc_inb(ahc, SCB_TAG); in ahc_reinitialize_dataptrs()
4276 scb = ahc_lookup_scb(ahc, scb_index); in ahc_reinitialize_dataptrs()
4277 sgptr = (ahc_inb(ahc, SCB_RESIDUAL_SGPTR + 3) << 24) in ahc_reinitialize_dataptrs()
4278 | (ahc_inb(ahc, SCB_RESIDUAL_SGPTR + 2) << 16) in ahc_reinitialize_dataptrs()
4279 | (ahc_inb(ahc, SCB_RESIDUAL_SGPTR + 1) << 8) in ahc_reinitialize_dataptrs()
4280 | ahc_inb(ahc, SCB_RESIDUAL_SGPTR); in ahc_reinitialize_dataptrs()
4288 resid = (ahc_inb(ahc, SCB_RESIDUAL_DATACNT + 2) << 16) in ahc_reinitialize_dataptrs()
4289 | (ahc_inb(ahc, SCB_RESIDUAL_DATACNT + 1) << 8) in ahc_reinitialize_dataptrs()
4290 | ahc_inb(ahc, SCB_RESIDUAL_DATACNT); in ahc_reinitialize_dataptrs()
4295 if ((ahc->flags & AHC_39BIT_ADDRESSING) != 0) { in ahc_reinitialize_dataptrs()
4298 dscommand1 = ahc_inb(ahc, DSCOMMAND1); in ahc_reinitialize_dataptrs()
4299 ahc_outb(ahc, DSCOMMAND1, dscommand1 | HADDLDSEL0); in ahc_reinitialize_dataptrs()
4300 ahc_outb(ahc, HADDR, in ahc_reinitialize_dataptrs()
4302 ahc_outb(ahc, DSCOMMAND1, dscommand1); in ahc_reinitialize_dataptrs()
4304 ahc_outb(ahc, HADDR + 3, dataptr >> 24); in ahc_reinitialize_dataptrs()
4305 ahc_outb(ahc, HADDR + 2, dataptr >> 16); in ahc_reinitialize_dataptrs()
4306 ahc_outb(ahc, HADDR + 1, dataptr >> 8); in ahc_reinitialize_dataptrs()
4307 ahc_outb(ahc, HADDR, dataptr); in ahc_reinitialize_dataptrs()
4308 ahc_outb(ahc, HCNT + 2, resid >> 16); in ahc_reinitialize_dataptrs()
4309 ahc_outb(ahc, HCNT + 1, resid >> 8); in ahc_reinitialize_dataptrs()
4310 ahc_outb(ahc, HCNT, resid); in ahc_reinitialize_dataptrs()
4311 if ((ahc->features & AHC_ULTRA2) == 0) { in ahc_reinitialize_dataptrs()
4312 ahc_outb(ahc, STCNT + 2, resid >> 16); in ahc_reinitialize_dataptrs()
4313 ahc_outb(ahc, STCNT + 1, resid >> 8); in ahc_reinitialize_dataptrs()
4314 ahc_outb(ahc, STCNT, resid); in ahc_reinitialize_dataptrs()
4322 ahc_handle_devreset(struct ahc_softc *ahc, struct ahc_devinfo *devinfo, in ahc_handle_devreset() argument
4331 found = ahc_abort_scbs(ahc, devinfo->target, devinfo->channel, in ahc_handle_devreset()
4340 tstate = ahc->enabled_targets[devinfo->our_scsiid]; in ahc_handle_devreset()
4349 ahc_queue_lstate_event(ahc, lstate, devinfo->our_scsiid, in ahc_handle_devreset()
4351 ahc_send_lstate_events(ahc, lstate); in ahc_handle_devreset()
4359 ahc_set_width(ahc, devinfo, MSG_EXT_WDTR_BUS_8_BIT, in ahc_handle_devreset()
4361 ahc_set_syncrate(ahc, devinfo, /*syncrate*/NULL, in ahc_handle_devreset()
4366 ahc_send_async(ahc, devinfo->channel, devinfo->target, in ahc_handle_devreset()
4371 printk("%s: %s on %c:%d. %d SCBs aborted\n", ahc_name(ahc), in ahc_handle_devreset()
4377 ahc_setup_target_msgin(struct ahc_softc *ahc, struct ahc_devinfo *devinfo, in ahc_setup_target_msgin() argument
4386 ahc->msgout_index = 0; in ahc_setup_target_msgin()
4387 ahc->msgout_len = 0; in ahc_setup_target_msgin()
4390 ahc_build_transfer_msg(ahc, devinfo); in ahc_setup_target_msgin()
4394 ahc->msgout_index = 0; in ahc_setup_target_msgin()
4395 ahc->msg_type = MSG_TYPE_TARGET_MSGIN; in ahc_setup_target_msgin()
4406 struct ahc_softc *ahc; in ahc_alloc() local
4410 ahc = kmalloc(sizeof(*ahc), GFP_ATOMIC); in ahc_alloc()
4411 if (!ahc) { in ahc_alloc()
4417 ahc = device_get_softc((device_t)platform_arg); in ahc_alloc()
4419 memset(ahc, 0, sizeof(*ahc)); in ahc_alloc()
4420 ahc->seep_config = kmalloc(sizeof(*ahc->seep_config), GFP_ATOMIC); in ahc_alloc()
4421 if (ahc->seep_config == NULL) { in ahc_alloc()
4423 kfree(ahc); in ahc_alloc()
4428 LIST_INIT(&ahc->pending_scbs); in ahc_alloc()
4430 ahc->name = name; in ahc_alloc()
4431 ahc->unit = -1; in ahc_alloc()
4432 ahc->description = NULL; in ahc_alloc()
4433 ahc->channel = 'A'; in ahc_alloc()
4434 ahc->channel_b = 'B'; in ahc_alloc()
4435 ahc->chip = AHC_NONE; in ahc_alloc()
4436 ahc->features = AHC_FENONE; in ahc_alloc()
4437 ahc->bugs = AHC_BUGNONE; in ahc_alloc()
4438 ahc->flags = AHC_FNONE; in ahc_alloc()
4444 ahc->seqctl = FASTMODE; in ahc_alloc()
4447 TAILQ_INIT(&ahc->untagged_queues[i]); in ahc_alloc()
4448 if (ahc_platform_alloc(ahc, platform_arg) != 0) { in ahc_alloc()
4449 ahc_free(ahc); in ahc_alloc()
4450 ahc = NULL; in ahc_alloc()
4452 return (ahc); in ahc_alloc()
4456 ahc_softc_init(struct ahc_softc *ahc) in ahc_softc_init() argument
4460 if ((ahc->chip & AHC_PCI) == 0) in ahc_softc_init()
4461 ahc->unpause = ahc_inb(ahc, HCNTRL) & IRQMS; in ahc_softc_init()
4463 ahc->unpause = 0; in ahc_softc_init()
4464 ahc->pause = ahc->unpause | PAUSE; in ahc_softc_init()
4466 if (ahc->scb_data == NULL) { in ahc_softc_init()
4467 ahc->scb_data = kzalloc(sizeof(*ahc->scb_data), GFP_ATOMIC); in ahc_softc_init()
4468 if (ahc->scb_data == NULL) in ahc_softc_init()
4476 ahc_set_unit(struct ahc_softc *ahc, int unit) in ahc_set_unit() argument
4478 ahc->unit = unit; in ahc_set_unit()
4482 ahc_set_name(struct ahc_softc *ahc, char *name) in ahc_set_name() argument
4484 if (ahc->name != NULL) in ahc_set_name()
4485 kfree(ahc->name); in ahc_set_name()
4486 ahc->name = name; in ahc_set_name()
4490 ahc_free(struct ahc_softc *ahc) in ahc_free() argument
4494 switch (ahc->init_level) { in ahc_free()
4497 ahc_shutdown(ahc); in ahc_free()
4500 ahc_dmamap_unload(ahc, ahc->shared_data_dmat, in ahc_free()
4501 ahc->shared_data_dmamap); in ahc_free()
4504 ahc_dmamem_free(ahc, ahc->shared_data_dmat, ahc->qoutfifo, in ahc_free()
4505 ahc->shared_data_dmamap); in ahc_free()
4506 ahc_dmamap_destroy(ahc, ahc->shared_data_dmat, in ahc_free()
4507 ahc->shared_data_dmamap); in ahc_free()
4510 ahc_dma_tag_destroy(ahc, ahc->shared_data_dmat); in ahc_free()
4513 ahc_dma_tag_destroy(ahc, ahc->buffer_dmat); in ahc_free()
4521 ahc_dma_tag_destroy(ahc, ahc->parent_dmat); in ahc_free()
4523 ahc_platform_free(ahc); in ahc_free()
4524 ahc_fini_scbdata(ahc); in ahc_free()
4528 tstate = ahc->enabled_targets[i]; in ahc_free()
4547 if (ahc->black_hole != NULL) { in ahc_free()
4548 xpt_free_path(ahc->black_hole->path); in ahc_free()
4549 kfree(ahc->black_hole); in ahc_free()
4552 if (ahc->name != NULL) in ahc_free()
4553 kfree(ahc->name); in ahc_free()
4554 if (ahc->seep_config != NULL) in ahc_free()
4555 kfree(ahc->seep_config); in ahc_free()
4557 kfree(ahc); in ahc_free()
4565 struct ahc_softc *ahc; in ahc_shutdown() local
4568 ahc = (struct ahc_softc *)arg; in ahc_shutdown()
4571 ahc_reset(ahc, /*reinit*/FALSE); in ahc_shutdown()
4572 ahc_outb(ahc, SCSISEQ, 0); in ahc_shutdown()
4573 ahc_outb(ahc, SXFRCTL0, 0); in ahc_shutdown()
4574 ahc_outb(ahc, DSPCISTATUS, 0); in ahc_shutdown()
4577 ahc_outb(ahc, i, 0); in ahc_shutdown()
4590 ahc_reset(struct ahc_softc *ahc, int reinit) in ahc_reset() argument
4602 ahc_pause(ahc); in ahc_reset()
4604 if ((ahc->chip & AHC_CHIPID_MASK) == AHC_AIC7770) { in ahc_reset()
4611 sblkctl = ahc_inb(ahc, SBLKCTL); in ahc_reset()
4612 ahc_outb(ahc, SBLKCTL, sblkctl | SELBUSB); in ahc_reset()
4613 sxfrctl1_b = ahc_inb(ahc, SXFRCTL1); in ahc_reset()
4614 ahc_outb(ahc, SBLKCTL, sblkctl & ~SELBUSB); in ahc_reset()
4616 sxfrctl1_a = ahc_inb(ahc, SXFRCTL1); in ahc_reset()
4618 ahc_outb(ahc, HCNTRL, CHIPRST | ahc->pause); in ahc_reset()
4629 } while (--wait && !(ahc_inb(ahc, HCNTRL) & CHIPRSTACK)); in ahc_reset()
4633 "Trying to initialize anyway.\n", ahc_name(ahc)); in ahc_reset()
4635 ahc_outb(ahc, HCNTRL, ahc->pause); in ahc_reset()
4638 sblkctl = ahc_inb(ahc, SBLKCTL) & (SELBUSB|SELWIDE); in ahc_reset()
4640 if ((ahc->chip & AHC_PCI) != 0) in ahc_reset()
4648 ahc->features |= AHC_WIDE; in ahc_reset()
4652 ahc->features |= AHC_TWIN; in ahc_reset()
4667 if ((ahc->features & AHC_TWIN) != 0) { in ahc_reset()
4670 sblkctl = ahc_inb(ahc, SBLKCTL); in ahc_reset()
4671 ahc_outb(ahc, SBLKCTL, sblkctl | SELBUSB); in ahc_reset()
4672 ahc_outb(ahc, SXFRCTL1, sxfrctl1_b); in ahc_reset()
4673 ahc_outb(ahc, SBLKCTL, sblkctl & ~SELBUSB); in ahc_reset()
4675 ahc_outb(ahc, SXFRCTL1, sxfrctl1_a); in ahc_reset()
4683 error = ahc->bus_chip_init(ahc); in ahc_reset()
4686 ahc_dumpseq(ahc); in ahc_reset()
4696 ahc_probe_scbs(struct ahc_softc *ahc) { in ahc_probe_scbs() argument
4701 ahc_outb(ahc, SCBPTR, i); in ahc_probe_scbs()
4702 ahc_outb(ahc, SCB_BASE, i); in ahc_probe_scbs()
4703 if (ahc_inb(ahc, SCB_BASE) != i) in ahc_probe_scbs()
4705 ahc_outb(ahc, SCBPTR, 0); in ahc_probe_scbs()
4706 if (ahc_inb(ahc, SCB_BASE) != 0) in ahc_probe_scbs()
4722 ahc_build_free_scb_list(struct ahc_softc *ahc) in ahc_build_free_scb_list() argument
4728 if ((ahc->flags & AHC_LSCBS_ENABLED) != 0) in ahc_build_free_scb_list()
4731 for (i = 0; i < ahc->scb_data->maxhscbs; i++) { in ahc_build_free_scb_list()
4734 ahc_outb(ahc, SCBPTR, i); in ahc_build_free_scb_list()
4742 ahc_outb(ahc, SCB_BASE+j, 0xFF); in ahc_build_free_scb_list()
4745 ahc_outb(ahc, SCB_CONTROL, 0); in ahc_build_free_scb_list()
4748 if ((ahc->flags & AHC_PAGESCBS) != 0) in ahc_build_free_scb_list()
4749 ahc_outb(ahc, SCB_NEXT, i+1); in ahc_build_free_scb_list()
4751 ahc_outb(ahc, SCB_NEXT, SCB_LIST_NULL); in ahc_build_free_scb_list()
4754 ahc_outb(ahc, SCB_TAG, SCB_LIST_NULL); in ahc_build_free_scb_list()
4755 ahc_outb(ahc, SCB_SCSIID, 0xFF); in ahc_build_free_scb_list()
4756 ahc_outb(ahc, SCB_LUN, 0xFF); in ahc_build_free_scb_list()
4759 if ((ahc->flags & AHC_PAGESCBS) != 0) { in ahc_build_free_scb_list()
4761 ahc_outb(ahc, FREE_SCBH, 0); in ahc_build_free_scb_list()
4764 ahc_outb(ahc, FREE_SCBH, SCB_LIST_NULL); in ahc_build_free_scb_list()
4768 ahc_outb(ahc, SCBPTR, i-1); in ahc_build_free_scb_list()
4769 ahc_outb(ahc, SCB_NEXT, SCB_LIST_NULL); in ahc_build_free_scb_list()
4773 ahc_init_scbdata(struct ahc_softc *ahc) in ahc_init_scbdata() argument
4777 scb_data = ahc->scb_data; in ahc_init_scbdata()
4789 scb_data->maxhscbs = ahc_probe_scbs(ahc); in ahc_init_scbdata()
4790 if (ahc->scb_data->maxhscbs == 0) { in ahc_init_scbdata()
4791 printk("%s: No SCB space found\n", ahc_name(ahc)); in ahc_init_scbdata()
4806 if (ahc_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/1, in ahc_init_scbdata()
4821 if (ahc_dmamem_alloc(ahc, scb_data->hscb_dmat, in ahc_init_scbdata()
4830 ahc_dmamap_load(ahc, scb_data->hscb_dmat, scb_data->hscb_dmamap, in ahc_init_scbdata()
4838 if (ahc_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/1, in ahc_init_scbdata()
4853 if (ahc_dmamem_alloc(ahc, scb_data->sense_dmat, in ahc_init_scbdata()
4862 ahc_dmamap_load(ahc, scb_data->sense_dmat, scb_data->sense_dmamap, in ahc_init_scbdata()
4870 if (ahc_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/8, in ahc_init_scbdata()
4886 ahc_alloc_scbs(ahc); in ahc_init_scbdata()
4891 ahc_name(ahc)); in ahc_init_scbdata()
4898 ahc->next_queued_scb = ahc_get_scb(ahc); in ahc_init_scbdata()
4911 ahc_fini_scbdata(struct ahc_softc *ahc) in ahc_fini_scbdata() argument
4915 scb_data = ahc->scb_data; in ahc_fini_scbdata()
4927 ahc_dmamap_unload(ahc, scb_data->sg_dmat, in ahc_fini_scbdata()
4929 ahc_dmamem_free(ahc, scb_data->sg_dmat, in ahc_fini_scbdata()
4934 ahc_dma_tag_destroy(ahc, scb_data->sg_dmat); in ahc_fini_scbdata()
4937 ahc_dmamap_unload(ahc, scb_data->sense_dmat, in ahc_fini_scbdata()
4940 ahc_dmamem_free(ahc, scb_data->sense_dmat, scb_data->sense, in ahc_fini_scbdata()
4942 ahc_dmamap_destroy(ahc, scb_data->sense_dmat, in ahc_fini_scbdata()
4945 ahc_dma_tag_destroy(ahc, scb_data->sense_dmat); in ahc_fini_scbdata()
4947 ahc_dmamap_unload(ahc, scb_data->hscb_dmat, in ahc_fini_scbdata()
4950 ahc_dmamem_free(ahc, scb_data->hscb_dmat, scb_data->hscbs, in ahc_fini_scbdata()
4952 ahc_dmamap_destroy(ahc, scb_data->hscb_dmat, in ahc_fini_scbdata()
4955 ahc_dma_tag_destroy(ahc, scb_data->hscb_dmat); in ahc_fini_scbdata()
4965 ahc_alloc_scbs(struct ahc_softc *ahc) in ahc_alloc_scbs() argument
4975 scb_data = ahc->scb_data; in ahc_alloc_scbs()
4988 if (ahc_dmamem_alloc(ahc, scb_data->sg_dmat, in ahc_alloc_scbs()
4997 ahc_dmamap_load(ahc, scb_data->sg_dmat, sg_map->sg_dmamap, in ahc_alloc_scbs()
5022 next_scb->ahc_softc = ahc; in ahc_alloc_scbs()
5025 error = ahc_dmamap_create(ahc, ahc->buffer_dmat, /*flags*/0, in ahc_alloc_scbs()
5031 next_scb->hscb->tag = ahc->scb_data->numscbs; in ahc_alloc_scbs()
5032 SLIST_INSERT_HEAD(&ahc->scb_data->free_scbs, in ahc_alloc_scbs()
5037 ahc->scb_data->numscbs++; in ahc_alloc_scbs()
5042 ahc_controller_info(struct ahc_softc *ahc, char *buf) in ahc_controller_info() argument
5046 len = sprintf(buf, "%s: ", ahc_chip_names[ahc->chip & AHC_CHIPID_MASK]); in ahc_controller_info()
5048 if ((ahc->features & AHC_TWIN) != 0) in ahc_controller_info()
5051 ahc->our_id, ahc->our_id_b, in ahc_controller_info()
5052 (ahc->flags & AHC_PRIMARY_CHANNEL) + 'A'); in ahc_controller_info()
5058 if ((ahc->features & AHC_ULTRA) != 0) { in ahc_controller_info()
5060 } else if ((ahc->features & AHC_DT) != 0) { in ahc_controller_info()
5062 } else if ((ahc->features & AHC_ULTRA2) != 0) { in ahc_controller_info()
5065 if ((ahc->features & AHC_WIDE) != 0) { in ahc_controller_info()
5071 speed, type, ahc->channel, ahc->our_id); in ahc_controller_info()
5075 if ((ahc->flags & AHC_PAGESCBS) != 0) in ahc_controller_info()
5077 ahc->scb_data->maxhscbs, AHC_MAX_QUEUE); in ahc_controller_info()
5079 sprintf(buf, "%d SCBs", ahc->scb_data->maxhscbs); in ahc_controller_info()
5083 ahc_chip_init(struct ahc_softc *ahc) in ahc_chip_init() argument
5092 ahc_outb(ahc, SEQ_FLAGS, 0); in ahc_chip_init()
5093 ahc_outb(ahc, SEQ_FLAGS2, 0); in ahc_chip_init()
5096 if (ahc->features & AHC_TWIN) { in ahc_chip_init()
5101 ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) | SELBUSB); in ahc_chip_init()
5102 term = (ahc->flags & AHC_TERM_ENB_B) != 0 ? STPWEN : 0; in ahc_chip_init()
5103 ahc_outb(ahc, SCSIID, ahc->our_id_b); in ahc_chip_init()
5104 scsi_conf = ahc_inb(ahc, SCSICONF + 1); in ahc_chip_init()
5105 ahc_outb(ahc, SXFRCTL1, (scsi_conf & (ENSPCHK|STIMESEL)) in ahc_chip_init()
5106 |term|ahc->seltime_b|ENSTIMER|ACTNEGEN); in ahc_chip_init()
5107 if ((ahc->features & AHC_ULTRA2) != 0) in ahc_chip_init()
5108 ahc_outb(ahc, SIMODE0, ahc_inb(ahc, SIMODE0)|ENIOERR); in ahc_chip_init()
5109 ahc_outb(ahc, SIMODE1, ENSELTIMO|ENSCSIRST|ENSCSIPERR); in ahc_chip_init()
5110 ahc_outb(ahc, SXFRCTL0, DFON|SPIOEN); in ahc_chip_init()
5113 ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) & ~SELBUSB); in ahc_chip_init()
5115 term = (ahc->flags & AHC_TERM_ENB_A) != 0 ? STPWEN : 0; in ahc_chip_init()
5116 if ((ahc->features & AHC_ULTRA2) != 0) in ahc_chip_init()
5117 ahc_outb(ahc, SCSIID_ULTRA2, ahc->our_id); in ahc_chip_init()
5119 ahc_outb(ahc, SCSIID, ahc->our_id); in ahc_chip_init()
5120 scsi_conf = ahc_inb(ahc, SCSICONF); in ahc_chip_init()
5121 ahc_outb(ahc, SXFRCTL1, (scsi_conf & (ENSPCHK|STIMESEL)) in ahc_chip_init()
5122 |term|ahc->seltime in ahc_chip_init()
5124 if ((ahc->features & AHC_ULTRA2) != 0) in ahc_chip_init()
5125 ahc_outb(ahc, SIMODE0, ahc_inb(ahc, SIMODE0)|ENIOERR); in ahc_chip_init()
5126 ahc_outb(ahc, SIMODE1, ENSELTIMO|ENSCSIRST|ENSCSIPERR); in ahc_chip_init()
5127 ahc_outb(ahc, SXFRCTL0, DFON|SPIOEN); in ahc_chip_init()
5131 ahc_unbusy_tcl(ahc, BUILD_TCL(i << 4, 0)); in ahc_chip_init()
5132 if ((ahc->flags & AHC_SCB_BTT) != 0) { in ahc_chip_init()
5140 ahc_unbusy_tcl(ahc, BUILD_TCL(i << 4, lun)); in ahc_chip_init()
5146 ahc->qoutfifo[i] = SCB_LIST_NULL; in ahc_chip_init()
5147 ahc_sync_qoutfifo(ahc, BUS_DMASYNC_PREREAD); in ahc_chip_init()
5150 ahc->qinfifo[i] = SCB_LIST_NULL; in ahc_chip_init()
5152 if ((ahc->features & AHC_MULTI_TID) != 0) { in ahc_chip_init()
5153 ahc_outb(ahc, TARGID, 0); in ahc_chip_init()
5154 ahc_outb(ahc, TARGID + 1, 0); in ahc_chip_init()
5160 physaddr = ahc->scb_data->hscb_busaddr; in ahc_chip_init()
5161 ahc_outb(ahc, HSCB_ADDR, physaddr & 0xFF); in ahc_chip_init()
5162 ahc_outb(ahc, HSCB_ADDR + 1, (physaddr >> 8) & 0xFF); in ahc_chip_init()
5163 ahc_outb(ahc, HSCB_ADDR + 2, (physaddr >> 16) & 0xFF); in ahc_chip_init()
5164 ahc_outb(ahc, HSCB_ADDR + 3, (physaddr >> 24) & 0xFF); in ahc_chip_init()
5166 physaddr = ahc->shared_data_busaddr; in ahc_chip_init()
5167 ahc_outb(ahc, SHARED_DATA_ADDR, physaddr & 0xFF); in ahc_chip_init()
5168 ahc_outb(ahc, SHARED_DATA_ADDR + 1, (physaddr >> 8) & 0xFF); in ahc_chip_init()
5169 ahc_outb(ahc, SHARED_DATA_ADDR + 2, (physaddr >> 16) & 0xFF); in ahc_chip_init()
5170 ahc_outb(ahc, SHARED_DATA_ADDR + 3, (physaddr >> 24) & 0xFF); in ahc_chip_init()
5177 ahc_outb(ahc, CMDSIZE_TABLE, 5); in ahc_chip_init()
5178 ahc_outb(ahc, CMDSIZE_TABLE + 1, 9); in ahc_chip_init()
5179 ahc_outb(ahc, CMDSIZE_TABLE + 2, 9); in ahc_chip_init()
5180 ahc_outb(ahc, CMDSIZE_TABLE + 3, 0); in ahc_chip_init()
5181 ahc_outb(ahc, CMDSIZE_TABLE + 4, 15); in ahc_chip_init()
5182 ahc_outb(ahc, CMDSIZE_TABLE + 5, 11); in ahc_chip_init()
5183 ahc_outb(ahc, CMDSIZE_TABLE + 6, 0); in ahc_chip_init()
5184 ahc_outb(ahc, CMDSIZE_TABLE + 7, 0); in ahc_chip_init()
5186 if ((ahc->features & AHC_HS_MAILBOX) != 0) in ahc_chip_init()
5187 ahc_outb(ahc, HS_MAILBOX, 0); in ahc_chip_init()
5190 if ((ahc->features & AHC_TARGETMODE) != 0) { in ahc_chip_init()
5191 ahc->tqinfifonext = 1; in ahc_chip_init()
5192 ahc_outb(ahc, KERNEL_TQINPOS, ahc->tqinfifonext - 1); in ahc_chip_init()
5193 ahc_outb(ahc, TQINPOS, ahc->tqinfifonext); in ahc_chip_init()
5195 ahc->qinfifonext = 0; in ahc_chip_init()
5196 ahc->qoutfifonext = 0; in ahc_chip_init()
5197 if ((ahc->features & AHC_QUEUE_REGS) != 0) { in ahc_chip_init()
5198 ahc_outb(ahc, QOFF_CTLSTA, SCB_QSIZE_256); in ahc_chip_init()
5199 ahc_outb(ahc, HNSCB_QOFF, ahc->qinfifonext); in ahc_chip_init()
5200 ahc_outb(ahc, SNSCB_QOFF, ahc->qinfifonext); in ahc_chip_init()
5201 ahc_outb(ahc, SDSCB_QOFF, 0); in ahc_chip_init()
5203 ahc_outb(ahc, KERNEL_QINPOS, ahc->qinfifonext); in ahc_chip_init()
5204 ahc_outb(ahc, QINPOS, ahc->qinfifonext); in ahc_chip_init()
5205 ahc_outb(ahc, QOUTPOS, ahc->qoutfifonext); in ahc_chip_init()
5209 ahc_outb(ahc, WAITING_SCBH, SCB_LIST_NULL); in ahc_chip_init()
5212 ahc_outb(ahc, DISCONNECTED_SCBH, SCB_LIST_NULL); in ahc_chip_init()
5215 ahc_outb(ahc, MSG_OUT, MSG_NOOP); in ahc_chip_init()
5223 if ((ahc->flags & AHC_INITIATORROLE) != 0) in ahc_chip_init()
5225 ahc_outb(ahc, SCSISEQ_TEMPLATE, scsiseq_template); in ahc_chip_init()
5228 ahc_build_free_scb_list(ahc); in ahc_chip_init()
5233 ahc_outb(ahc, NEXT_QUEUED_SCB, ahc->next_queued_scb->hscb->tag); in ahc_chip_init()
5241 ahc_name(ahc)); in ahc_chip_init()
5243 error = ahc_loadseq(ahc); in ahc_chip_init()
5247 if ((ahc->features & AHC_ULTRA2) != 0) { in ahc_chip_init()
5258 (ahc_inb(ahc, SBLKCTL) & (ENAB40|ENAB20)) == 0 && wait; in ahc_chip_init()
5262 ahc_restart(ahc); in ahc_chip_init()
5270 ahc_init(struct ahc_softc *ahc) in ahc_init() argument
5282 ahc->flags |= AHC_SEQUENCER_DEBUG; in ahc_init()
5291 printk (" 0x%x", ahc_inb(ahc, i)); in ahc_init()
5293 if ((ahc->features & AHC_MORE_SRAM) != 0) { in ahc_init()
5298 printk (" 0x%x", ahc_inb(ahc, i)); in ahc_init()
5306 ahc_outb(ahc, CLRINT, CLRPARERR); in ahc_init()
5307 ahc_outb(ahc, CLRINT, CLRBRKADRINT); in ahc_init()
5314 if ((ahc->flags & AHC_USEDEFAULTS) != 0) in ahc_init()
5315 ahc->our_id = ahc->our_id_b = 7; in ahc_init()
5320 ahc->flags |= AHC_INITIATORROLE; in ahc_init()
5325 if ((AHC_TMODE_ENABLE & (0x1 << ahc->unit)) == 0) in ahc_init()
5326 ahc->features &= ~AHC_TARGETMODE; in ahc_init()
5330 if (ahc_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/1, in ahc_init()
5332 /*lowaddr*/ahc->flags & AHC_39BIT_ADDRESSING in ahc_init()
5341 &ahc->buffer_dmat) != 0) { in ahc_init()
5346 ahc->init_level++; in ahc_init()
5358 if ((ahc->features & AHC_TARGETMODE) != 0) in ahc_init()
5361 if (ahc_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/1, in ahc_init()
5369 /*flags*/0, &ahc->shared_data_dmat) != 0) { in ahc_init()
5373 ahc->init_level++; in ahc_init()
5376 if (ahc_dmamem_alloc(ahc, ahc->shared_data_dmat, in ahc_init()
5377 (void **)&ahc->qoutfifo, in ahc_init()
5378 BUS_DMA_NOWAIT, &ahc->shared_data_dmamap) != 0) { in ahc_init()
5382 ahc->init_level++; in ahc_init()
5385 ahc_dmamap_load(ahc, ahc->shared_data_dmat, ahc->shared_data_dmamap, in ahc_init()
5386 ahc->qoutfifo, driver_data_size, ahc_dmamap_cb, in ahc_init()
5387 &ahc->shared_data_busaddr, /*flags*/0); in ahc_init()
5389 if ((ahc->features & AHC_TARGETMODE) != 0) { in ahc_init()
5390 ahc->targetcmds = (struct target_cmd *)ahc->qoutfifo; in ahc_init()
5391 ahc->qoutfifo = (uint8_t *)&ahc->targetcmds[AHC_TMODE_CMDS]; in ahc_init()
5392 ahc->dma_bug_buf = ahc->shared_data_busaddr in ahc_init()
5396 ahc->targetcmds[i].cmd_valid = 0; in ahc_init()
5397 ahc_sync_tqinfifo(ahc, BUS_DMASYNC_PREREAD); in ahc_init()
5398 ahc->qoutfifo = (uint8_t *)&ahc->targetcmds[256]; in ahc_init()
5400 ahc->qinfifo = &ahc->qoutfifo[256]; in ahc_init()
5402 ahc->init_level++; in ahc_init()
5405 if (ahc->scb_data->maxhscbs == 0) in ahc_init()
5406 if (ahc_init_scbdata(ahc) != 0) in ahc_init()
5414 if (ahc_alloc_tstate(ahc, ahc->our_id, 'A') == NULL) { in ahc_init()
5416 "Failing attach\n", ahc_name(ahc)); in ahc_init()
5420 if ((ahc->features & AHC_TWIN) != 0) { in ahc_init()
5421 if (ahc_alloc_tstate(ahc, ahc->our_id_b, 'B') == NULL) { in ahc_init()
5423 "Failing attach\n", ahc_name(ahc)); in ahc_init()
5428 if (ahc->scb_data->maxhscbs < AHC_SCB_MAX_ALLOC) { in ahc_init()
5429 ahc->flags |= AHC_PAGESCBS; in ahc_init()
5431 ahc->flags &= ~AHC_PAGESCBS; in ahc_init()
5438 ahc_name(ahc), in ahc_init()
5449 if (ahc->features & AHC_TWIN) { in ahc_init()
5450 scsi_conf = ahc_inb(ahc, SCSICONF + 1); in ahc_init()
5452 && (ahc->flags & AHC_INITIATORROLE) != 0) in ahc_init()
5453 ahc->flags |= AHC_RESET_BUS_B; in ahc_init()
5456 scsi_conf = ahc_inb(ahc, SCSICONF); in ahc_init()
5458 && (ahc->flags & AHC_INITIATORROLE) != 0) in ahc_init()
5459 ahc->flags |= AHC_RESET_BUS_A; in ahc_init()
5465 if ((ahc->flags & AHC_USEDEFAULTS) != 0) { in ahc_init()
5467 "device parameters\n", ahc_name(ahc)); in ahc_init()
5468 ahc->flags |= AHC_EXTENDED_TRANS_A|AHC_EXTENDED_TRANS_B| in ahc_init()
5471 if ((ahc->features & AHC_ULTRA) != 0) in ahc_init()
5474 discenable = ~((ahc_inb(ahc, DISC_DSB + 1) << 8) in ahc_init()
5475 | ahc_inb(ahc, DISC_DSB)); in ahc_init()
5476 if ((ahc->features & (AHC_ULTRA|AHC_ULTRA2)) != 0) in ahc_init()
5477 ultraenb = (ahc_inb(ahc, ULTRA_ENB + 1) << 8) in ahc_init()
5478 | ahc_inb(ahc, ULTRA_ENB); in ahc_init()
5481 if ((ahc->features & (AHC_WIDE|AHC_TWIN)) == 0) in ahc_init()
5492 our_id = ahc->our_id; in ahc_init()
5494 if (i > 7 && (ahc->features & AHC_TWIN) != 0) { in ahc_init()
5496 our_id = ahc->our_id_b; in ahc_init()
5499 tinfo = ahc_fetch_transinfo(ahc, channel, our_id, in ahc_init()
5503 if (ahc->flags & AHC_USEDEFAULTS) { in ahc_init()
5504 if ((ahc->features & AHC_WIDE) != 0) in ahc_init()
5518 scsirate = ahc_inb(ahc, TARG_SCSIRATE + i); in ahc_init()
5520 if ((ahc->features & AHC_ULTRA2) != 0) { in ahc_init()
5535 offset = ahc_inb(ahc, TARG_OFFSET + i); in ahc_init()
5540 if ((ahc->features & AHC_DT) != 0) in ahc_init()
5543 ahc_find_period(ahc, scsirate, maxsync); in ahc_init()
5549 && (ahc->features & AHC_DT) != 0) in ahc_init()
5560 ahc_find_period(ahc, scsirate, in ahc_init()
5570 && (ahc->features & AHC_WIDE) != 0) in ahc_init()
5573 if ((ahc->features & AHC_DT) != 0) in ahc_init()
5584 ahc->user_discenable = discenable; in ahc_init()
5585 ahc->user_tagenable = tagenable; in ahc_init()
5587 return (ahc->bus_chip_init(ahc)); in ahc_init()
5591 ahc_intr_enable(struct ahc_softc *ahc, int enable) in ahc_intr_enable() argument
5595 hcntrl = ahc_inb(ahc, HCNTRL); in ahc_intr_enable()
5597 ahc->pause &= ~INTEN; in ahc_intr_enable()
5598 ahc->unpause &= ~INTEN; in ahc_intr_enable()
5601 ahc->pause |= INTEN; in ahc_intr_enable()
5602 ahc->unpause |= INTEN; in ahc_intr_enable()
5604 ahc_outb(ahc, HCNTRL, hcntrl); in ahc_intr_enable()
5615 ahc_pause_and_flushwork(struct ahc_softc *ahc) in ahc_pause_and_flushwork() argument
5622 ahc->flags |= AHC_ALL_INTERRUPTS; in ahc_pause_and_flushwork()
5626 ahc_unpause(ahc); in ahc_pause_and_flushwork()
5633 ahc_intr(ahc); in ahc_pause_and_flushwork()
5634 ahc_pause(ahc); in ahc_pause_and_flushwork()
5636 ahc_outb(ahc, SCSISEQ, ahc_inb(ahc, SCSISEQ) & ~ENSELO); in ahc_pause_and_flushwork()
5637 intstat = ahc_inb(ahc, INTSTAT); in ahc_pause_and_flushwork()
5639 ahc_clear_critical_section(ahc); in ahc_pause_and_flushwork()
5640 intstat = ahc_inb(ahc, INTSTAT); in ahc_pause_and_flushwork()
5643 && (intstat != 0xFF || (ahc->features & AHC_REMOVABLE) == 0) in ahc_pause_and_flushwork()
5645 || (ahc_inb(ahc, SSTAT0) & (SELDO|SELINGO)) != 0)); in ahc_pause_and_flushwork()
5648 ahc_inb(ahc, INTSTAT)); in ahc_pause_and_flushwork()
5650 ahc_platform_flushwork(ahc); in ahc_pause_and_flushwork()
5651 ahc->flags &= ~AHC_ALL_INTERRUPTS; in ahc_pause_and_flushwork()
5656 ahc_suspend(struct ahc_softc *ahc) in ahc_suspend() argument
5659 ahc_pause_and_flushwork(ahc); in ahc_suspend()
5661 if (LIST_FIRST(&ahc->pending_scbs) != NULL) { in ahc_suspend()
5662 ahc_unpause(ahc); in ahc_suspend()
5672 if (ahc->pending_device != NULL) { in ahc_suspend()
5673 ahc_unpause(ahc); in ahc_suspend()
5677 ahc_shutdown(ahc); in ahc_suspend()
5682 ahc_resume(struct ahc_softc *ahc) in ahc_resume() argument
5685 ahc_reset(ahc, /*reinit*/TRUE); in ahc_resume()
5686 ahc_intr_enable(ahc, TRUE); in ahc_resume()
5687 ahc_restart(ahc); in ahc_resume()
5697 ahc_index_busy_tcl(struct ahc_softc *ahc, u_int tcl) in ahc_index_busy_tcl() argument
5702 if ((ahc->flags & AHC_SCB_BTT) != 0) { in ahc_index_busy_tcl()
5705 saved_scbptr = ahc_inb(ahc, SCBPTR); in ahc_index_busy_tcl()
5706 ahc_outb(ahc, SCBPTR, TCL_LUN(tcl)); in ahc_index_busy_tcl()
5707 scbid = ahc_inb(ahc, SCB_64_BTT + TCL_TARGET_OFFSET(tcl)); in ahc_index_busy_tcl()
5708 ahc_outb(ahc, SCBPTR, saved_scbptr); in ahc_index_busy_tcl()
5711 scbid = ahc_inb(ahc, BUSY_TARGETS + target_offset); in ahc_index_busy_tcl()
5718 ahc_unbusy_tcl(struct ahc_softc *ahc, u_int tcl) in ahc_unbusy_tcl() argument
5722 if ((ahc->flags & AHC_SCB_BTT) != 0) { in ahc_unbusy_tcl()
5725 saved_scbptr = ahc_inb(ahc, SCBPTR); in ahc_unbusy_tcl()
5726 ahc_outb(ahc, SCBPTR, TCL_LUN(tcl)); in ahc_unbusy_tcl()
5727 ahc_outb(ahc, SCB_64_BTT+TCL_TARGET_OFFSET(tcl), SCB_LIST_NULL); in ahc_unbusy_tcl()
5728 ahc_outb(ahc, SCBPTR, saved_scbptr); in ahc_unbusy_tcl()
5731 ahc_outb(ahc, BUSY_TARGETS + target_offset, SCB_LIST_NULL); in ahc_unbusy_tcl()
5736 ahc_busy_tcl(struct ahc_softc *ahc, u_int tcl, u_int scbid) in ahc_busy_tcl() argument
5740 if ((ahc->flags & AHC_SCB_BTT) != 0) { in ahc_busy_tcl()
5743 saved_scbptr = ahc_inb(ahc, SCBPTR); in ahc_busy_tcl()
5744 ahc_outb(ahc, SCBPTR, TCL_LUN(tcl)); in ahc_busy_tcl()
5745 ahc_outb(ahc, SCB_64_BTT + TCL_TARGET_OFFSET(tcl), scbid); in ahc_busy_tcl()
5746 ahc_outb(ahc, SCBPTR, saved_scbptr); in ahc_busy_tcl()
5749 ahc_outb(ahc, BUSY_TARGETS + target_offset, scbid); in ahc_busy_tcl()
5755 ahc_match_scb(struct ahc_softc *ahc, struct scb *scb, int target, in ahc_match_scb() argument
5758 int targ = SCB_GET_TARGET(ahc, scb); in ahc_match_scb()
5759 char chan = SCB_GET_CHANNEL(ahc, scb); in ahc_match_scb()
5791 ahc_freeze_devq(struct ahc_softc *ahc, struct scb *scb) in ahc_freeze_devq() argument
5797 target = SCB_GET_TARGET(ahc, scb); in ahc_freeze_devq()
5799 channel = SCB_GET_CHANNEL(ahc, scb); in ahc_freeze_devq()
5801 ahc_search_qinfifo(ahc, target, channel, lun, in ahc_freeze_devq()
5805 ahc_platform_freeze_devq(ahc, scb); in ahc_freeze_devq()
5809 ahc_qinfifo_requeue_tail(struct ahc_softc *ahc, struct scb *scb) in ahc_qinfifo_requeue_tail() argument
5814 if (ahc_qinfifo_count(ahc) != 0) { in ahc_qinfifo_requeue_tail()
5818 prev_pos = ahc->qinfifonext - 1; in ahc_qinfifo_requeue_tail()
5819 prev_tag = ahc->qinfifo[prev_pos]; in ahc_qinfifo_requeue_tail()
5820 prev_scb = ahc_lookup_scb(ahc, prev_tag); in ahc_qinfifo_requeue_tail()
5822 ahc_qinfifo_requeue(ahc, prev_scb, scb); in ahc_qinfifo_requeue_tail()
5823 if ((ahc->features & AHC_QUEUE_REGS) != 0) { in ahc_qinfifo_requeue_tail()
5824 ahc_outb(ahc, HNSCB_QOFF, ahc->qinfifonext); in ahc_qinfifo_requeue_tail()
5826 ahc_outb(ahc, KERNEL_QINPOS, ahc->qinfifonext); in ahc_qinfifo_requeue_tail()
5831 ahc_qinfifo_requeue(struct ahc_softc *ahc, struct scb *prev_scb, in ahc_qinfifo_requeue() argument
5835 ahc_outb(ahc, NEXT_QUEUED_SCB, scb->hscb->tag); in ahc_qinfifo_requeue()
5838 ahc_sync_scb(ahc, prev_scb, in ahc_qinfifo_requeue()
5841 ahc->qinfifo[ahc->qinfifonext++] = scb->hscb->tag; in ahc_qinfifo_requeue()
5842 scb->hscb->next = ahc->next_queued_scb->hscb->tag; in ahc_qinfifo_requeue()
5843 ahc_sync_scb(ahc, scb, BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE); in ahc_qinfifo_requeue()
5847 ahc_qinfifo_count(struct ahc_softc *ahc) in ahc_qinfifo_count() argument
5852 if ((ahc->features & AHC_QUEUE_REGS) != 0) { in ahc_qinfifo_count()
5853 qinpos = ahc_inb(ahc, SNSCB_QOFF); in ahc_qinfifo_count()
5854 ahc_outb(ahc, SNSCB_QOFF, qinpos); in ahc_qinfifo_count()
5856 qinpos = ahc_inb(ahc, QINPOS); in ahc_qinfifo_count()
5857 diff = ahc->qinfifonext - qinpos; in ahc_qinfifo_count()
5862 ahc_search_qinfifo(struct ahc_softc *ahc, int target, char channel, in ahc_search_qinfifo() argument
5877 qintail = ahc->qinfifonext; in ahc_search_qinfifo()
5878 have_qregs = (ahc->features & AHC_QUEUE_REGS) != 0; in ahc_search_qinfifo()
5880 qinstart = ahc_inb(ahc, SNSCB_QOFF); in ahc_search_qinfifo()
5881 ahc_outb(ahc, SNSCB_QOFF, qinstart); in ahc_search_qinfifo()
5883 qinstart = ahc_inb(ahc, QINPOS); in ahc_search_qinfifo()
5893 ahc_freeze_untagged_queues(ahc); in ahc_search_qinfifo()
5900 ahc->qinfifonext = qinpos; in ahc_search_qinfifo()
5901 ahc_outb(ahc, NEXT_QUEUED_SCB, ahc->next_queued_scb->hscb->tag); in ahc_search_qinfifo()
5904 scb = ahc_lookup_scb(ahc, ahc->qinfifo[qinpos]); in ahc_search_qinfifo()
5907 qinpos, ahc->qinfifo[qinpos]); in ahc_search_qinfifo()
5911 if (ahc_match_scb(ahc, scb, target, channel, lun, tag, role)) { in ahc_search_qinfifo()
5930 ahc_done(ahc, scb); in ahc_search_qinfifo()
5937 ahc_qinfifo_requeue(ahc, prev_scb, scb); in ahc_search_qinfifo()
5942 ahc_qinfifo_requeue(ahc, prev_scb, scb); in ahc_search_qinfifo()
5948 if ((ahc->features & AHC_QUEUE_REGS) != 0) { in ahc_search_qinfifo()
5949 ahc_outb(ahc, HNSCB_QOFF, ahc->qinfifonext); in ahc_search_qinfifo()
5951 ahc_outb(ahc, KERNEL_QINPOS, ahc->qinfifonext); in ahc_search_qinfifo()
5956 && (qinstart != ahc->qinfifonext)) { in ahc_search_qinfifo()
5969 scb = ahc_lookup_scb(ahc, ahc->qinfifo[qinstart]); in ahc_search_qinfifo()
5973 found, qinstart, ahc->qinfifonext); in ahc_search_qinfifo()
5983 ahc->scb_data->scbindex[scb->hscb->tag] = NULL; in ahc_search_qinfifo()
5984 ahc_swap_with_next_hscb(ahc, scb); in ahc_search_qinfifo()
5986 ahc->qinfifo[qinstart] = scb->hscb->tag; in ahc_search_qinfifo()
5989 ahc_outb(ahc, NEXT_QUEUED_SCB, scb->hscb->tag); in ahc_search_qinfifo()
5992 qintail = ahc->qinfifonext - 1; in ahc_search_qinfifo()
5993 scb = ahc_lookup_scb(ahc, ahc->qinfifo[qintail]); in ahc_search_qinfifo()
5994 scb->hscb->next = ahc->next_queued_scb->hscb->tag; in ahc_search_qinfifo()
6000 curscbptr = ahc_inb(ahc, SCBPTR); in ahc_search_qinfifo()
6001 next = ahc_inb(ahc, WAITING_SCBH); /* Start at head of list. */ in ahc_search_qinfifo()
6007 ahc_outb(ahc, SCBPTR, next); in ahc_search_qinfifo()
6008 scb_index = ahc_inb(ahc, SCB_TAG); in ahc_search_qinfifo()
6009 if (scb_index >= ahc->scb_data->numscbs) { in ahc_search_qinfifo()
6012 scb_index, ahc->scb_data->numscbs); in ahc_search_qinfifo()
6013 ahc_dump_card_state(ahc); in ahc_search_qinfifo()
6016 scb = ahc_lookup_scb(ahc, scb_index); in ahc_search_qinfifo()
6022 if (ahc_match_scb(ahc, scb, target, channel, in ahc_search_qinfifo()
6043 ahc_done(ahc, scb); in ahc_search_qinfifo()
6047 next = ahc_rem_wscb(ahc, next, prev); in ahc_search_qinfifo()
6051 next = ahc_inb(ahc, SCB_NEXT); in ahc_search_qinfifo()
6057 next = ahc_inb(ahc, SCB_NEXT); in ahc_search_qinfifo()
6060 ahc_outb(ahc, SCBPTR, curscbptr); in ahc_search_qinfifo()
6062 found += ahc_search_untagged_queues(ahc, /*ahc_io_ctx_t*/NULL, target, in ahc_search_qinfifo()
6066 ahc_release_untagged_queues(ahc); in ahc_search_qinfifo()
6071 ahc_search_untagged_queues(struct ahc_softc *ahc, ahc_io_ctx_t ctx, in ahc_search_untagged_queues() argument
6085 ahc_freeze_untagged_queues(ahc); in ahc_search_untagged_queues()
6090 if ((ahc->flags & AHC_SCB_BTT) == 0) { in ahc_search_untagged_queues()
6108 untagged_q = &(ahc->untagged_queues[i]); in ahc_search_untagged_queues()
6127 if (ahc_match_scb(ahc, scb, target, channel, lun, in ahc_search_untagged_queues()
6150 ahc_done(ahc, scb); in ahc_search_untagged_queues()
6164 ahc_release_untagged_queues(ahc); in ahc_search_untagged_queues()
6169 ahc_search_disc_list(struct ahc_softc *ahc, int target, char channel, in ahc_search_disc_list() argument
6180 next = ahc_inb(ahc, DISCONNECTED_SCBH); in ahc_search_disc_list()
6185 active_scb = ahc_inb(ahc, SCBPTR); in ahc_search_disc_list()
6193 ahc_outb(ahc, SCBPTR, next); in ahc_search_disc_list()
6194 scb_index = ahc_inb(ahc, SCB_TAG); in ahc_search_disc_list()
6195 if (scb_index >= ahc->scb_data->numscbs) { in ahc_search_disc_list()
6198 scb_index, ahc->scb_data->numscbs); in ahc_search_disc_list()
6199 ahc_dump_card_state(ahc); in ahc_search_disc_list()
6208 scbp = ahc_lookup_scb(ahc, scb_index); in ahc_search_disc_list()
6209 if (ahc_match_scb(ahc, scbp, target, channel, lun, in ahc_search_disc_list()
6214 ahc_rem_scb_from_disc_list(ahc, prev, next); in ahc_search_disc_list()
6217 next = ahc_inb(ahc, SCB_NEXT); in ahc_search_disc_list()
6223 next = ahc_inb(ahc, SCB_NEXT); in ahc_search_disc_list()
6227 ahc_outb(ahc, SCBPTR, active_scb); in ahc_search_disc_list()
6236 ahc_rem_scb_from_disc_list(struct ahc_softc *ahc, u_int prev, u_int scbptr) in ahc_rem_scb_from_disc_list() argument
6240 ahc_outb(ahc, SCBPTR, scbptr); in ahc_rem_scb_from_disc_list()
6241 next = ahc_inb(ahc, SCB_NEXT); in ahc_rem_scb_from_disc_list()
6243 ahc_outb(ahc, SCB_CONTROL, 0); in ahc_rem_scb_from_disc_list()
6245 ahc_add_curscb_to_free_list(ahc); in ahc_rem_scb_from_disc_list()
6248 ahc_outb(ahc, SCBPTR, prev); in ahc_rem_scb_from_disc_list()
6249 ahc_outb(ahc, SCB_NEXT, next); in ahc_rem_scb_from_disc_list()
6251 ahc_outb(ahc, DISCONNECTED_SCBH, next); in ahc_rem_scb_from_disc_list()
6262 ahc_add_curscb_to_free_list(struct ahc_softc *ahc) in ahc_add_curscb_to_free_list() argument
6268 ahc_outb(ahc, SCB_TAG, SCB_LIST_NULL); in ahc_add_curscb_to_free_list()
6270 if ((ahc->flags & AHC_PAGESCBS) != 0) { in ahc_add_curscb_to_free_list()
6271 ahc_outb(ahc, SCB_NEXT, ahc_inb(ahc, FREE_SCBH)); in ahc_add_curscb_to_free_list()
6272 ahc_outb(ahc, FREE_SCBH, ahc_inb(ahc, SCBPTR)); in ahc_add_curscb_to_free_list()
6281 ahc_rem_wscb(struct ahc_softc *ahc, u_int scbpos, u_int prev) in ahc_rem_wscb() argument
6289 curscb = ahc_inb(ahc, SCBPTR); in ahc_rem_wscb()
6290 ahc_outb(ahc, SCBPTR, scbpos); in ahc_rem_wscb()
6291 next = ahc_inb(ahc, SCB_NEXT); in ahc_rem_wscb()
6294 ahc_outb(ahc, SCB_CONTROL, 0); in ahc_rem_wscb()
6296 ahc_add_curscb_to_free_list(ahc); in ahc_rem_wscb()
6301 ahc_outb(ahc, WAITING_SCBH, next); in ahc_rem_wscb()
6307 ahc_outb(ahc, SCSISEQ, (ahc_inb(ahc, SCSISEQ) & ~ENSELO)); in ahc_rem_wscb()
6313 ahc_outb(ahc, SCBPTR, prev); in ahc_rem_wscb()
6314 ahc_outb(ahc, SCB_NEXT, next); in ahc_rem_wscb()
6320 ahc_outb(ahc, SCBPTR, curscb); in ahc_rem_wscb()
6332 ahc_abort_scbs(struct ahc_softc *ahc, int target, char channel, in ahc_abort_scbs() argument
6349 ahc_freeze_untagged_queues(ahc); in ahc_abort_scbs()
6352 active_scb = ahc_inb(ahc, SCBPTR); in ahc_abort_scbs()
6354 found = ahc_search_qinfifo(ahc, target, channel, lun, SCB_LIST_NULL, in ahc_abort_scbs()
6379 if ((ahc->flags & AHC_SCB_BTT) != 0) in ahc_abort_scbs()
6393 scbid = ahc_index_busy_tcl(ahc, tcl); in ahc_abort_scbs()
6394 scbp = ahc_lookup_scb(ahc, scbid); in ahc_abort_scbs()
6396 || ahc_match_scb(ahc, scbp, target, channel, in ahc_abort_scbs()
6399 ahc_unbusy_tcl(ahc, BUILD_TCL(i << 4, j)); in ahc_abort_scbs()
6409 ahc_search_disc_list(ahc, target, channel, lun, tag, in ahc_abort_scbs()
6421 for (i = 0; i < ahc->scb_data->maxhscbs; i++) { in ahc_abort_scbs()
6424 ahc_outb(ahc, SCBPTR, i); in ahc_abort_scbs()
6425 scbid = ahc_inb(ahc, SCB_TAG); in ahc_abort_scbs()
6426 scbp = ahc_lookup_scb(ahc, scbid); in ahc_abort_scbs()
6429 && ahc_match_scb(ahc, scbp, target, channel, lun, tag, role))) in ahc_abort_scbs()
6430 ahc_add_curscb_to_free_list(ahc); in ahc_abort_scbs()
6439 scbp_next = LIST_FIRST(&ahc->pending_scbs); in ahc_abort_scbs()
6443 if (ahc_match_scb(ahc, scbp, target, channel, lun, tag, role)) { in ahc_abort_scbs()
6453 ahc_done(ahc, scbp); in ahc_abort_scbs()
6457 ahc_outb(ahc, SCBPTR, active_scb); in ahc_abort_scbs()
6458 ahc_platform_abort_scbs(ahc, target, channel, lun, tag, role, status); in ahc_abort_scbs()
6459 ahc_release_untagged_queues(ahc); in ahc_abort_scbs()
6464 ahc_reset_current_bus(struct ahc_softc *ahc) in ahc_reset_current_bus() argument
6468 ahc_outb(ahc, SIMODE1, ahc_inb(ahc, SIMODE1) & ~ENSCSIRST); in ahc_reset_current_bus()
6469 scsiseq = ahc_inb(ahc, SCSISEQ); in ahc_reset_current_bus()
6470 ahc_outb(ahc, SCSISEQ, scsiseq | SCSIRSTO); in ahc_reset_current_bus()
6471 ahc_flush_device_writes(ahc); in ahc_reset_current_bus()
6474 ahc_outb(ahc, SCSISEQ, scsiseq & ~SCSIRSTO); in ahc_reset_current_bus()
6476 ahc_clear_intstat(ahc); in ahc_reset_current_bus()
6479 ahc_outb(ahc, SIMODE1, ahc_inb(ahc, SIMODE1) | ENSCSIRST); in ahc_reset_current_bus()
6483 ahc_reset_channel(struct ahc_softc *ahc, char channel, int initiate_reset) in ahc_reset_channel() argument
6494 ahc->pending_device = NULL; in ahc_reset_channel()
6501 ahc_pause(ahc); in ahc_reset_channel()
6504 ahc_clear_critical_section(ahc); in ahc_reset_channel()
6511 ahc_run_qoutfifo(ahc); in ahc_reset_channel()
6523 if ((ahc->flags & AHC_TARGETROLE) != 0) { in ahc_reset_channel()
6524 ahc_run_tqinfifo(ahc, /*paused*/TRUE); in ahc_reset_channel()
6531 sblkctl = ahc_inb(ahc, SBLKCTL); in ahc_reset_channel()
6533 if ((ahc->features & AHC_TWIN) != 0 in ahc_reset_channel()
6536 scsiseq = ahc_inb(ahc, SCSISEQ_TEMPLATE); in ahc_reset_channel()
6542 ahc_outb(ahc, SBLKCTL, sblkctl ^ SELBUSB); in ahc_reset_channel()
6543 simode1 = ahc_inb(ahc, SIMODE1) & ~(ENBUSFREE|ENSCSIRST); in ahc_reset_channel()
6550 if ((ahc->flags & AHC_TARGETROLE) != 0) in ahc_reset_channel()
6553 ahc_outb(ahc, SIMODE1, simode1); in ahc_reset_channel()
6555 ahc_reset_current_bus(ahc); in ahc_reset_channel()
6556 ahc_clear_intstat(ahc); in ahc_reset_channel()
6557 ahc_outb(ahc, SCSISEQ, scsiseq & (ENSELI|ENRSELI|ENAUTOATNP)); in ahc_reset_channel()
6558 ahc_outb(ahc, SBLKCTL, sblkctl); in ahc_reset_channel()
6562 simode1 = ahc_inb(ahc, SIMODE1) & ~(ENBUSFREE|ENSCSIRST); in ahc_reset_channel()
6569 if ((ahc->flags & AHC_TARGETROLE) != 0) in ahc_reset_channel()
6572 ahc_outb(ahc, SIMODE1, simode1); in ahc_reset_channel()
6574 ahc_reset_current_bus(ahc); in ahc_reset_channel()
6575 ahc_clear_intstat(ahc); in ahc_reset_channel()
6576 ahc_outb(ahc, SCSISEQ, scsiseq & (ENSELI|ENRSELI|ENAUTOATNP)); in ahc_reset_channel()
6584 found = ahc_abort_scbs(ahc, CAM_TARGET_WILDCARD, channel, in ahc_reset_channel()
6588 max_scsiid = (ahc->features & AHC_WIDE) ? 15 : 7; in ahc_reset_channel()
6599 tstate = ahc->enabled_targets[target]; in ahc_reset_channel()
6609 ahc_queue_lstate_event(ahc, lstate, CAM_TARGET_WILDCARD, in ahc_reset_channel()
6611 ahc_send_lstate_events(ahc, lstate); in ahc_reset_channel()
6616 ahc_send_async(ahc, devinfo.channel, CAM_TARGET_WILDCARD, in ahc_reset_channel()
6624 if (ahc->enabled_targets[target] == NULL) in ahc_reset_channel()
6632 ahc_set_width(ahc, &devinfo, MSG_EXT_WDTR_BUS_8_BIT, in ahc_reset_channel()
6634 ahc_set_syncrate(ahc, &devinfo, /*syncrate*/NULL, in ahc_reset_channel()
6642 ahc_restart(ahc); in ahc_reset_channel()
6644 ahc_unpause(ahc); in ahc_reset_channel()
6654 ahc_calc_residual(struct ahc_softc *ahc, struct scb *scb) in ahc_calc_residual() argument
6729 ahc_print_path(ahc, scb); in ahc_calc_residual()
6742 ahc_queue_lstate_event(struct ahc_softc *ahc, struct ahc_tmode_lstate *lstate, in ahc_queue_lstate_event() argument
6793 ahc_send_lstate_events(struct ahc_softc *ahc, struct ahc_tmode_lstate *lstate) in ahc_send_lstate_events() argument
6829 ahc_dumpseq(struct ahc_softc* ahc) in ahc_dumpseq() argument
6833 ahc_outb(ahc, SEQCTL, PERRORDIS|FAILDIS|FASTMODE|LOADRAM); in ahc_dumpseq()
6834 ahc_outb(ahc, SEQADDR0, 0); in ahc_dumpseq()
6835 ahc_outb(ahc, SEQADDR1, 0); in ahc_dumpseq()
6836 for (i = 0; i < ahc->instruction_ram_size; i++) { in ahc_dumpseq()
6839 ahc_insb(ahc, SEQRAM, ins_bytes, 4); in ahc_dumpseq()
6849 ahc_loadseq(struct ahc_softc *ahc) in ahc_loadseq() argument
6874 if (ahc->targetcmds != NULL) in ahc_loadseq()
6877 download_consts[CACHESIZE_MASK] = ahc->pci_cachesize - 1; in ahc_loadseq()
6878 download_consts[INVERTED_CACHESIZE_MASK] = ~(ahc->pci_cachesize - 1); in ahc_loadseq()
6879 sg_prefetch_cnt = ahc->pci_cachesize; in ahc_loadseq()
6889 ahc_outb(ahc, SEQCTL, PERRORDIS|FAILDIS|FASTMODE|LOADRAM); in ahc_loadseq()
6890 ahc_outb(ahc, SEQADDR0, 0); in ahc_loadseq()
6891 ahc_outb(ahc, SEQADDR1, 0); in ahc_loadseq()
6894 if (ahc_check_patch(ahc, &cur_patch, i, &skip_addr) == 0) { in ahc_loadseq()
6902 if (downloaded == ahc->instruction_ram_size) { in ahc_loadseq()
6909 "size of %d!\n", ahc_name(ahc), in ahc_loadseq()
6910 ahc->instruction_ram_size); in ahc_loadseq()
6935 ahc_download_instr(ahc, i, download_consts); in ahc_loadseq()
6939 ahc->num_critical_sections = cs_count; in ahc_loadseq()
6943 ahc->critical_sections = kmalloc(cs_count, GFP_ATOMIC); in ahc_loadseq()
6944 if (ahc->critical_sections == NULL) in ahc_loadseq()
6946 memcpy(ahc->critical_sections, cs_table, cs_count); in ahc_loadseq()
6948 ahc_outb(ahc, SEQCTL, PERRORDIS|FAILDIS|FASTMODE); in ahc_loadseq()
6953 ahc_name(ahc), ahc->features, ahc->bugs, ahc->flags); in ahc_loadseq()
6959 ahc_check_patch(struct ahc_softc *ahc, const struct patch **start_patch, in ahc_check_patch() argument
6972 if (cur_patch->patch_func(ahc) == 0) { in ahc_check_patch()
6995 ahc_download_instr(struct ahc_softc *ahc, u_int instrptr, uint8_t *dconsts) in ahc_download_instr() argument
7036 ahc_check_patch(ahc, &cur_patch, i, &skip_addr); in ahc_download_instr()
7062 if ((ahc->features & AHC_CMD_CHAN) == 0 in ahc_download_instr()
7073 ahc_name(ahc)); in ahc_download_instr()
7079 if ((ahc->features & AHC_ULTRA2) != 0) { in ahc_download_instr()
7111 ahc_outsb(ahc, SEQRAM, instr.bytes, 4); in ahc_download_instr()
7168 ahc_dump_card_state(struct ahc_softc *ahc) in ahc_dump_card_state() argument
7184 if (ahc_is_paused(ahc)) { in ahc_dump_card_state()
7188 ahc_pause(ahc); in ahc_dump_card_state()
7191 saved_scbptr = ahc_inb(ahc, SCBPTR); in ahc_dump_card_state()
7192 last_phase = ahc_inb(ahc, LASTPHASE); in ahc_dump_card_state()
7195 ahc_name(ahc), ahc_lookup_phase_entry(last_phase)->phasemsg, in ahc_dump_card_state()
7196 ahc_inb(ahc, SEQADDR0) | (ahc_inb(ahc, SEQADDR1) << 8)); in ahc_dump_card_state()
7200 ahc_inb(ahc, ACCUM), ahc_inb(ahc, SINDEX), ahc_inb(ahc, DINDEX), in ahc_dump_card_state()
7201 ahc_inb(ahc, ARG_2)); in ahc_dump_card_state()
7202 printk("HCNT = 0x%x SCBPTR = 0x%x\n", ahc_inb(ahc, HCNT), in ahc_dump_card_state()
7203 ahc_inb(ahc, SCBPTR)); in ahc_dump_card_state()
7205 if ((ahc->features & AHC_DT) != 0) in ahc_dump_card_state()
7206 ahc_scsiphase_print(ahc_inb(ahc, SCSIPHASE), &cur_col, 50); in ahc_dump_card_state()
7207 ahc_scsisigi_print(ahc_inb(ahc, SCSISIGI), &cur_col, 50); in ahc_dump_card_state()
7208 ahc_error_print(ahc_inb(ahc, ERROR), &cur_col, 50); in ahc_dump_card_state()
7209 ahc_scsibusl_print(ahc_inb(ahc, SCSIBUSL), &cur_col, 50); in ahc_dump_card_state()
7210 ahc_lastphase_print(ahc_inb(ahc, LASTPHASE), &cur_col, 50); in ahc_dump_card_state()
7211 ahc_scsiseq_print(ahc_inb(ahc, SCSISEQ), &cur_col, 50); in ahc_dump_card_state()
7212 ahc_sblkctl_print(ahc_inb(ahc, SBLKCTL), &cur_col, 50); in ahc_dump_card_state()
7213 ahc_scsirate_print(ahc_inb(ahc, SCSIRATE), &cur_col, 50); in ahc_dump_card_state()
7214 ahc_seqctl_print(ahc_inb(ahc, SEQCTL), &cur_col, 50); in ahc_dump_card_state()
7215 ahc_seq_flags_print(ahc_inb(ahc, SEQ_FLAGS), &cur_col, 50); in ahc_dump_card_state()
7216 ahc_sstat0_print(ahc_inb(ahc, SSTAT0), &cur_col, 50); in ahc_dump_card_state()
7217 ahc_sstat1_print(ahc_inb(ahc, SSTAT1), &cur_col, 50); in ahc_dump_card_state()
7218 ahc_sstat2_print(ahc_inb(ahc, SSTAT2), &cur_col, 50); in ahc_dump_card_state()
7219 ahc_sstat3_print(ahc_inb(ahc, SSTAT3), &cur_col, 50); in ahc_dump_card_state()
7220 ahc_simode0_print(ahc_inb(ahc, SIMODE0), &cur_col, 50); in ahc_dump_card_state()
7221 ahc_simode1_print(ahc_inb(ahc, SIMODE1), &cur_col, 50); in ahc_dump_card_state()
7222 ahc_sxfrctl0_print(ahc_inb(ahc, SXFRCTL0), &cur_col, 50); in ahc_dump_card_state()
7223 ahc_dfcntrl_print(ahc_inb(ahc, DFCNTRL), &cur_col, 50); in ahc_dump_card_state()
7224 ahc_dfstatus_print(ahc_inb(ahc, DFSTATUS), &cur_col, 50); in ahc_dump_card_state()
7229 printk(" 0x%x", ahc_inb(ahc, STACK)|(ahc_inb(ahc, STACK) << 8)); in ahc_dump_card_state()
7230 printk("\nSCB count = %d\n", ahc->scb_data->numscbs); in ahc_dump_card_state()
7231 printk("Kernel NEXTQSCB = %d\n", ahc->next_queued_scb->hscb->tag); in ahc_dump_card_state()
7232 printk("Card NEXTQSCB = %d\n", ahc_inb(ahc, NEXT_QUEUED_SCB)); in ahc_dump_card_state()
7235 if ((ahc->features & AHC_QUEUE_REGS) != 0) { in ahc_dump_card_state()
7236 qinpos = ahc_inb(ahc, SNSCB_QOFF); in ahc_dump_card_state()
7237 ahc_outb(ahc, SNSCB_QOFF, qinpos); in ahc_dump_card_state()
7239 qinpos = ahc_inb(ahc, QINPOS); in ahc_dump_card_state()
7240 qintail = ahc->qinfifonext; in ahc_dump_card_state()
7242 printk("%d ", ahc->qinfifo[qinpos]); in ahc_dump_card_state()
7248 scb_index = ahc_inb(ahc, WAITING_SCBH); in ahc_dump_card_state()
7251 ahc_outb(ahc, SCBPTR, scb_index); in ahc_dump_card_state()
7252 printk("%d:%d ", scb_index, ahc_inb(ahc, SCB_TAG)); in ahc_dump_card_state()
7253 scb_index = ahc_inb(ahc, SCB_NEXT); in ahc_dump_card_state()
7258 scb_index = ahc_inb(ahc, DISCONNECTED_SCBH); in ahc_dump_card_state()
7261 ahc_outb(ahc, SCBPTR, scb_index); in ahc_dump_card_state()
7262 printk("%d:%d ", scb_index, ahc_inb(ahc, SCB_TAG)); in ahc_dump_card_state()
7263 scb_index = ahc_inb(ahc, SCB_NEXT); in ahc_dump_card_state()
7267 ahc_sync_qoutfifo(ahc, BUS_DMASYNC_POSTREAD); in ahc_dump_card_state()
7269 qoutpos = ahc->qoutfifonext; in ahc_dump_card_state()
7271 while (ahc->qoutfifo[qoutpos] != SCB_LIST_NULL && i++ < 256) { in ahc_dump_card_state()
7272 printk("%d ", ahc->qoutfifo[qoutpos]); in ahc_dump_card_state()
7278 scb_index = ahc_inb(ahc, FREE_SCBH); in ahc_dump_card_state()
7281 ahc_outb(ahc, SCBPTR, scb_index); in ahc_dump_card_state()
7283 scb_index = ahc_inb(ahc, SCB_NEXT); in ahc_dump_card_state()
7288 for (i = 0; i < ahc->scb_data->maxhscbs; i++) { in ahc_dump_card_state()
7289 ahc_outb(ahc, SCBPTR, i); in ahc_dump_card_state()
7292 ahc_scb_control_print(ahc_inb(ahc, SCB_CONTROL), &cur_col, 60); in ahc_dump_card_state()
7293 ahc_scb_scsiid_print(ahc_inb(ahc, SCB_SCSIID), &cur_col, 60); in ahc_dump_card_state()
7294 ahc_scb_lun_print(ahc_inb(ahc, SCB_LUN), &cur_col, 60); in ahc_dump_card_state()
7295 ahc_scb_tag_print(ahc_inb(ahc, SCB_TAG), &cur_col, 60); in ahc_dump_card_state()
7301 LIST_FOREACH(scb, &ahc->pending_scbs, pending_links) { in ahc_dump_card_state()
7308 if ((ahc->flags & AHC_PAGESCBS) == 0) { in ahc_dump_card_state()
7309 ahc_outb(ahc, SCBPTR, scb->hscb->tag); in ahc_dump_card_state()
7311 ahc_scb_control_print(ahc_inb(ahc, SCB_CONTROL), in ahc_dump_card_state()
7313 ahc_scb_tag_print(ahc_inb(ahc, SCB_TAG), &cur_col, 60); in ahc_dump_card_state()
7321 SLIST_FOREACH(scb, &ahc->scb_data->free_scbs, links.sle) { in ahc_dump_card_state()
7328 maxtarget = (ahc->features & (AHC_WIDE|AHC_TWIN)) ? 15 : 7; in ahc_dump_card_state()
7330 untagged_q = &ahc->untagged_queues[target]; in ahc_dump_card_state()
7343 ahc_platform_dump_card_state(ahc); in ahc_dump_card_state()
7345 ahc_outb(ahc, SCBPTR, saved_scbptr); in ahc_dump_card_state()
7347 ahc_unpause(ahc); in ahc_dump_card_state()
7353 ahc_find_tmode_devs(struct ahc_softc *ahc, struct cam_sim *sim, union ccb *ccb, in ahc_find_tmode_devs() argument
7359 if ((ahc->features & AHC_TARGETMODE) == 0) in ahc_find_tmode_devs()
7369 *lstate = ahc->black_hole; in ahc_find_tmode_devs()
7373 max_id = (ahc->features & AHC_WIDE) ? 16 : 8; in ahc_find_tmode_devs()
7380 *tstate = ahc->enabled_targets[ccb->ccb_h.target_id]; in ahc_find_tmode_devs()
7394 ahc_handle_en_lun(struct ahc_softc *ahc, struct cam_sim *sim, union ccb *ccb) in ahc_handle_en_lun() argument
7408 status = ahc_find_tmode_devs(ahc, sim, ccb, &tstate, &lstate, in ahc_handle_en_lun()
7417 our_id = ahc->our_id; in ahc_handle_en_lun()
7419 our_id = ahc->our_id_b; in ahc_handle_en_lun()
7441 if ((ahc->features & AHC_MULTIROLE) != 0) { in ahc_handle_en_lun()
7443 if ((ahc->features & AHC_MULTI_TID) != 0 in ahc_handle_en_lun()
7444 && (ahc->flags & AHC_INITIATORROLE) != 0) { in ahc_handle_en_lun()
7453 } else if ((ahc->flags & AHC_INITIATORROLE) != 0 in ahc_handle_en_lun()
7454 || ahc->enabled_luns > 0) { in ahc_handle_en_lun()
7464 } else if ((ahc->features & AHC_MULTI_TID) == 0 in ahc_handle_en_lun()
7465 && ahc->enabled_luns > 0) { in ahc_handle_en_lun()
7480 if ((ahc->flags & AHC_TARGETROLE) == 0 in ahc_handle_en_lun()
7486 ahc_lock(ahc, &s); in ahc_handle_en_lun()
7487 if (LIST_FIRST(&ahc->pending_scbs) != NULL) { in ahc_handle_en_lun()
7489 ahc_unlock(ahc, &s); in ahc_handle_en_lun()
7492 saved_flags = ahc->flags; in ahc_handle_en_lun()
7493 ahc->flags |= AHC_TARGETROLE; in ahc_handle_en_lun()
7494 if ((ahc->features & AHC_MULTIROLE) == 0) in ahc_handle_en_lun()
7495 ahc->flags &= ~AHC_INITIATORROLE; in ahc_handle_en_lun()
7496 ahc_pause(ahc); in ahc_handle_en_lun()
7497 error = ahc_loadseq(ahc); in ahc_handle_en_lun()
7507 ahc->flags = saved_flags; in ahc_handle_en_lun()
7508 (void)ahc_loadseq(ahc); in ahc_handle_en_lun()
7509 ahc_restart(ahc); in ahc_handle_en_lun()
7510 ahc_unlock(ahc, &s); in ahc_handle_en_lun()
7514 ahc_restart(ahc); in ahc_handle_en_lun()
7515 ahc_unlock(ahc, &s); in ahc_handle_en_lun()
7520 channel = SIM_CHANNEL(ahc, sim); in ahc_handle_en_lun()
7552 tstate = ahc_alloc_tstate(ahc, target, channel); in ahc_handle_en_lun()
7580 ahc_lock(ahc, &s); in ahc_handle_en_lun()
7581 ahc_pause(ahc); in ahc_handle_en_lun()
7584 ahc->enabled_luns++; in ahc_handle_en_lun()
7586 if ((ahc->features & AHC_MULTI_TID) != 0) { in ahc_handle_en_lun()
7589 targid_mask = ahc_inb(ahc, TARGID) in ahc_handle_en_lun()
7590 | (ahc_inb(ahc, TARGID + 1) << 8); in ahc_handle_en_lun()
7593 ahc_outb(ahc, TARGID, targid_mask); in ahc_handle_en_lun()
7594 ahc_outb(ahc, TARGID+1, (targid_mask >> 8)); in ahc_handle_en_lun()
7596 ahc_update_scsiid(ahc, targid_mask); in ahc_handle_en_lun()
7601 channel = SIM_CHANNEL(ahc, sim); in ahc_handle_en_lun()
7602 our_id = SIM_SCSI_ID(ahc, sim); in ahc_handle_en_lun()
7613 sblkctl = ahc_inb(ahc, SBLKCTL); in ahc_handle_en_lun()
7616 if ((ahc->features & AHC_TWIN) == 0) in ahc_handle_en_lun()
7620 ahc->our_id = target; in ahc_handle_en_lun()
7622 ahc->our_id_b = target; in ahc_handle_en_lun()
7625 ahc_outb(ahc, SBLKCTL, in ahc_handle_en_lun()
7628 ahc_outb(ahc, SCSIID, target); in ahc_handle_en_lun()
7631 ahc_outb(ahc, SBLKCTL, sblkctl); in ahc_handle_en_lun()
7635 ahc->black_hole = lstate; in ahc_handle_en_lun()
7637 if (ahc->black_hole != NULL && ahc->enabled_luns > 0) { in ahc_handle_en_lun()
7638 scsiseq = ahc_inb(ahc, SCSISEQ_TEMPLATE); in ahc_handle_en_lun()
7640 ahc_outb(ahc, SCSISEQ_TEMPLATE, scsiseq); in ahc_handle_en_lun()
7641 scsiseq = ahc_inb(ahc, SCSISEQ); in ahc_handle_en_lun()
7643 ahc_outb(ahc, SCSISEQ, scsiseq); in ahc_handle_en_lun()
7645 ahc_unpause(ahc); in ahc_handle_en_lun()
7646 ahc_unlock(ahc, &s); in ahc_handle_en_lun()
7659 ahc_lock(ahc, &s); in ahc_handle_en_lun()
7662 LIST_FOREACH(scb, &ahc->pending_scbs, pending_links) { in ahc_handle_en_lun()
7670 ahc_unlock(ahc, &s); in ahc_handle_en_lun()
7686 ahc_unlock(ahc, &s); in ahc_handle_en_lun()
7695 ahc_pause(ahc); in ahc_handle_en_lun()
7699 ahc->enabled_luns--; in ahc_handle_en_lun()
7707 ahc_free_tstate(ahc, target, channel, in ahc_handle_en_lun()
7709 if (ahc->features & AHC_MULTI_TID) { in ahc_handle_en_lun()
7712 targid_mask = ahc_inb(ahc, TARGID) in ahc_handle_en_lun()
7713 | (ahc_inb(ahc, TARGID + 1) in ahc_handle_en_lun()
7717 ahc_outb(ahc, TARGID, targid_mask); in ahc_handle_en_lun()
7718 ahc_outb(ahc, TARGID+1, in ahc_handle_en_lun()
7720 ahc_update_scsiid(ahc, targid_mask); in ahc_handle_en_lun()
7725 ahc->black_hole = NULL; in ahc_handle_en_lun()
7733 if (ahc->enabled_luns == 0) { in ahc_handle_en_lun()
7737 scsiseq = ahc_inb(ahc, SCSISEQ_TEMPLATE); in ahc_handle_en_lun()
7739 ahc_outb(ahc, SCSISEQ_TEMPLATE, scsiseq); in ahc_handle_en_lun()
7740 scsiseq = ahc_inb(ahc, SCSISEQ); in ahc_handle_en_lun()
7742 ahc_outb(ahc, SCSISEQ, scsiseq); in ahc_handle_en_lun()
7744 if ((ahc->features & AHC_MULTIROLE) == 0) { in ahc_handle_en_lun()
7746 ahc->flags &= ~AHC_TARGETROLE; in ahc_handle_en_lun()
7747 ahc->flags |= AHC_INITIATORROLE; in ahc_handle_en_lun()
7752 (void)ahc_loadseq(ahc); in ahc_handle_en_lun()
7753 ahc_restart(ahc); in ahc_handle_en_lun()
7760 ahc_unpause(ahc); in ahc_handle_en_lun()
7761 ahc_unlock(ahc, &s); in ahc_handle_en_lun()
7766 ahc_update_scsiid(struct ahc_softc *ahc, u_int targid_mask) in ahc_update_scsiid() argument
7771 if ((ahc->features & AHC_MULTI_TID) == 0) in ahc_update_scsiid()
7780 if ((ahc->features & AHC_ULTRA2) != 0) in ahc_update_scsiid()
7781 scsiid = ahc_inb(ahc, SCSIID_ULTRA2); in ahc_update_scsiid()
7783 scsiid = ahc_inb(ahc, SCSIID); in ahc_update_scsiid()
7791 our_id = ahc->our_id; in ahc_update_scsiid()
7797 if ((ahc->features & AHC_ULTRA2) != 0) in ahc_update_scsiid()
7798 ahc_outb(ahc, SCSIID_ULTRA2, scsiid); in ahc_update_scsiid()
7800 ahc_outb(ahc, SCSIID, scsiid); in ahc_update_scsiid()
7804 ahc_run_tqinfifo(struct ahc_softc *ahc, int paused) in ahc_run_tqinfifo() argument
7813 if ((ahc->features & AHC_AUTOPAUSE) != 0) in ahc_run_tqinfifo()
7816 ahc_sync_tqinfifo(ahc, BUS_DMASYNC_POSTREAD); in ahc_run_tqinfifo()
7817 while ((cmd = &ahc->targetcmds[ahc->tqinfifonext])->cmd_valid != 0) { in ahc_run_tqinfifo()
7823 if (ahc_handle_target_cmd(ahc, cmd) != 0) in ahc_run_tqinfifo()
7827 ahc_dmamap_sync(ahc, ahc->shared_data_dmat, in ahc_run_tqinfifo()
7828 ahc->shared_data_dmamap, in ahc_run_tqinfifo()
7829 ahc_targetcmd_offset(ahc, ahc->tqinfifonext), in ahc_run_tqinfifo()
7832 ahc->tqinfifonext++; in ahc_run_tqinfifo()
7838 if ((ahc->tqinfifonext & (HOST_TQINPOS - 1)) == 1) { in ahc_run_tqinfifo()
7839 if ((ahc->features & AHC_HS_MAILBOX) != 0) { in ahc_run_tqinfifo()
7842 hs_mailbox = ahc_inb(ahc, HS_MAILBOX); in ahc_run_tqinfifo()
7844 hs_mailbox |= ahc->tqinfifonext & HOST_TQINPOS; in ahc_run_tqinfifo()
7845 ahc_outb(ahc, HS_MAILBOX, hs_mailbox); in ahc_run_tqinfifo()
7848 ahc_pause(ahc); in ahc_run_tqinfifo()
7849 ahc_outb(ahc, KERNEL_TQINPOS, in ahc_run_tqinfifo()
7850 ahc->tqinfifonext & HOST_TQINPOS); in ahc_run_tqinfifo()
7852 ahc_unpause(ahc); in ahc_run_tqinfifo()
7859 ahc_handle_target_cmd(struct ahc_softc *ahc, struct target_cmd *cmd) in ahc_handle_target_cmd() argument
7869 initiator = SCSIID_TARGET(ahc, cmd->scsiid); in ahc_handle_target_cmd()
7874 tstate = ahc->enabled_targets[target]; in ahc_handle_target_cmd()
7883 lstate = ahc->black_hole; in ahc_handle_target_cmd()
7887 ahc->flags |= AHC_TQINFIFO_BLOCKED; in ahc_handle_target_cmd()
7892 printk("%s: ATIOs exhausted\n", ahc_name(ahc)); in ahc_handle_target_cmd()
7895 ahc->flags &= ~AHC_TQINFIFO_BLOCKED; in ahc_handle_target_cmd()
7899 lstate == ahc->black_hole ? "(Black Holed)" : ""); in ahc_handle_target_cmd()
7903 if (lstate == ahc->black_hole) { in ahc_handle_target_cmd()
7961 initiator, target, lun, ahc->pending_device); in ahc_handle_target_cmd()
7963 ahc->pending_device = lstate; in ahc_handle_target_cmd()