Lines Matching refs:ahc
134 static void ahc_force_renegotiation(struct ahc_softc *ahc,
137 ahc_alloc_tstate(struct ahc_softc *ahc,
140 static void ahc_free_tstate(struct ahc_softc *ahc,
144 ahc_devlimited_syncrate(struct ahc_softc *ahc,
149 static void ahc_update_pending_scbs(struct ahc_softc *ahc);
150 static void ahc_fetch_devinfo(struct ahc_softc *ahc,
152 static void ahc_scb_devinfo(struct ahc_softc *ahc,
155 static void ahc_assert_atn(struct ahc_softc *ahc);
156 static void ahc_setup_initiator_msgout(struct ahc_softc *ahc,
159 static void ahc_build_transfer_msg(struct ahc_softc *ahc,
161 static void ahc_construct_sdtr(struct ahc_softc *ahc,
164 static void ahc_construct_wdtr(struct ahc_softc *ahc,
167 static void ahc_construct_ppr(struct ahc_softc *ahc,
171 static void ahc_clear_msg_state(struct ahc_softc *ahc);
172 static void ahc_handle_proto_violation(struct ahc_softc *ahc);
173 static void ahc_handle_message_phase(struct ahc_softc *ahc);
179 static int ahc_sent_msg(struct ahc_softc *ahc, ahc_msgtype type,
181 static int ahc_parse_msg(struct ahc_softc *ahc,
183 static int ahc_handle_msg_reject(struct ahc_softc *ahc,
185 static void ahc_handle_ign_wide_residue(struct ahc_softc *ahc,
187 static void ahc_reinitialize_dataptrs(struct ahc_softc *ahc);
188 static void ahc_handle_devreset(struct ahc_softc *ahc,
193 static void ahc_setup_target_msgin(struct ahc_softc *ahc,
199 static void ahc_build_free_scb_list(struct ahc_softc *ahc);
200 static int ahc_init_scbdata(struct ahc_softc *ahc);
201 static void ahc_fini_scbdata(struct ahc_softc *ahc);
202 static void ahc_qinfifo_requeue(struct ahc_softc *ahc,
205 static int ahc_qinfifo_count(struct ahc_softc *ahc);
206 static u_int ahc_rem_scb_from_disc_list(struct ahc_softc *ahc,
208 static void ahc_add_curscb_to_free_list(struct ahc_softc *ahc);
209 static u_int ahc_rem_wscb(struct ahc_softc *ahc,
211 static void ahc_reset_current_bus(struct ahc_softc *ahc);
213 static void ahc_dumpseq(struct ahc_softc *ahc);
215 static int ahc_loadseq(struct ahc_softc *ahc);
216 static int ahc_check_patch(struct ahc_softc *ahc,
219 static void ahc_download_instr(struct ahc_softc *ahc,
222 static void ahc_queue_lstate_event(struct ahc_softc *ahc,
227 static void ahc_update_scsiid(struct ahc_softc *ahc,
229 static int ahc_handle_target_cmd(struct ahc_softc *ahc,
233 static u_int ahc_index_busy_tcl(struct ahc_softc *ahc, u_int tcl);
234 static void ahc_unbusy_tcl(struct ahc_softc *ahc, u_int tcl);
235 static void ahc_busy_tcl(struct ahc_softc *ahc,
239 static void ahc_run_untagged_queues(struct ahc_softc *ahc);
240 static void ahc_run_untagged_queue(struct ahc_softc *ahc,
244 static void ahc_alloc_scbs(struct ahc_softc *ahc);
248 static void ahc_clear_intstat(struct ahc_softc *ahc);
249 static void ahc_run_qoutfifo(struct ahc_softc *ahc);
251 static void ahc_run_tqinfifo(struct ahc_softc *ahc, int paused);
253 static void ahc_handle_brkadrint(struct ahc_softc *ahc);
254 static void ahc_handle_seqint(struct ahc_softc *ahc, u_int intstat);
255 static void ahc_handle_scsiint(struct ahc_softc *ahc,
257 static void ahc_clear_critical_section(struct ahc_softc *ahc);
260 static void ahc_freeze_devq(struct ahc_softc *ahc, struct scb *scb);
261 static int ahc_abort_scbs(struct ahc_softc *ahc, int target,
264 static void ahc_calc_residual(struct ahc_softc *ahc,
268 static inline void ahc_freeze_untagged_queues(struct ahc_softc *ahc);
269 static inline void ahc_release_untagged_queues(struct ahc_softc *ahc);
276 ahc_freeze_untagged_queues(struct ahc_softc *ahc) in ahc_freeze_untagged_queues() argument
278 if ((ahc->flags & AHC_SCB_BTT) == 0) in ahc_freeze_untagged_queues()
279 ahc->untagged_queue_lock++; in ahc_freeze_untagged_queues()
289 ahc_release_untagged_queues(struct ahc_softc *ahc) in ahc_release_untagged_queues() argument
291 if ((ahc->flags & AHC_SCB_BTT) == 0) { in ahc_release_untagged_queues()
292 ahc->untagged_queue_lock--; in ahc_release_untagged_queues()
293 if (ahc->untagged_queue_lock == 0) in ahc_release_untagged_queues()
294 ahc_run_untagged_queues(ahc); in ahc_release_untagged_queues()
308 ahc_pause_bug_fix(struct ahc_softc *ahc) in ahc_pause_bug_fix() argument
310 if ((ahc->features & AHC_ULTRA2) != 0) in ahc_pause_bug_fix()
311 (void)ahc_inb(ahc, CCSCBCTL); in ahc_pause_bug_fix()
319 ahc_is_paused(struct ahc_softc *ahc) in ahc_is_paused() argument
321 return ((ahc_inb(ahc, HCNTRL) & PAUSE) != 0); in ahc_is_paused()
332 ahc_pause(struct ahc_softc *ahc) in ahc_pause() argument
334 ahc_outb(ahc, HCNTRL, ahc->pause); in ahc_pause()
340 while (ahc_is_paused(ahc) == 0) in ahc_pause()
343 ahc_pause_bug_fix(ahc); in ahc_pause()
357 ahc_unpause(struct ahc_softc *ahc) in ahc_unpause() argument
359 if ((ahc_inb(ahc, INTSTAT) & (SCSIINT | SEQINT | BRKADRINT)) == 0) in ahc_unpause()
360 ahc_outb(ahc, HCNTRL, ahc->unpause); in ahc_unpause()
388 ahc_hscb_busaddr(struct ahc_softc *ahc, u_int index) in ahc_hscb_busaddr() argument
390 return (ahc->scb_data->hscb_busaddr in ahc_hscb_busaddr()
395 ahc_sync_scb(struct ahc_softc *ahc, struct scb *scb, int op) in ahc_sync_scb() argument
397 ahc_dmamap_sync(ahc, ahc->scb_data->hscb_dmat, in ahc_sync_scb()
398 ahc->scb_data->hscb_dmamap, in ahc_sync_scb()
399 /*offset*/(scb->hscb - ahc->hscbs) * sizeof(*scb->hscb), in ahc_sync_scb()
404 ahc_sync_sglist(struct ahc_softc *ahc, struct scb *scb, int op) in ahc_sync_sglist() argument
409 ahc_dmamap_sync(ahc, ahc->scb_data->sg_dmat, scb->sg_map->sg_dmamap, in ahc_sync_sglist()
417 ahc_targetcmd_offset(struct ahc_softc *ahc, u_int index) in ahc_targetcmd_offset() argument
419 return (((uint8_t *)&ahc->targetcmds[index]) - ahc->qoutfifo); in ahc_targetcmd_offset()
429 ahc_update_residual(struct ahc_softc *ahc, struct scb *scb) in ahc_update_residual() argument
435 ahc_calc_residual(ahc, scb); in ahc_update_residual()
443 ahc_fetch_transinfo(struct ahc_softc *ahc, char channel, u_int our_id, in ahc_fetch_transinfo() argument
454 *tstate = ahc->enabled_targets[our_id]; in ahc_fetch_transinfo()
459 ahc_inw(struct ahc_softc *ahc, u_int port) in ahc_inw() argument
461 uint16_t r = ahc_inb(ahc, port+1) << 8; in ahc_inw()
462 return r | ahc_inb(ahc, port); in ahc_inw()
466 ahc_outw(struct ahc_softc *ahc, u_int port, u_int value) in ahc_outw() argument
468 ahc_outb(ahc, port, value & 0xFF); in ahc_outw()
469 ahc_outb(ahc, port+1, (value >> 8) & 0xFF); in ahc_outw()
473 ahc_inl(struct ahc_softc *ahc, u_int port) in ahc_inl() argument
475 return ((ahc_inb(ahc, port)) in ahc_inl()
476 | (ahc_inb(ahc, port+1) << 8) in ahc_inl()
477 | (ahc_inb(ahc, port+2) << 16) in ahc_inl()
478 | (ahc_inb(ahc, port+3) << 24)); in ahc_inl()
482 ahc_outl(struct ahc_softc *ahc, u_int port, uint32_t value) in ahc_outl() argument
484 ahc_outb(ahc, port, (value) & 0xFF); in ahc_outl()
485 ahc_outb(ahc, port+1, ((value) >> 8) & 0xFF); in ahc_outl()
486 ahc_outb(ahc, port+2, ((value) >> 16) & 0xFF); in ahc_outl()
487 ahc_outb(ahc, port+3, ((value) >> 24) & 0xFF); in ahc_outl()
491 ahc_inq(struct ahc_softc *ahc, u_int port) in ahc_inq() argument
493 return ((ahc_inb(ahc, port)) in ahc_inq()
494 | (ahc_inb(ahc, port+1) << 8) in ahc_inq()
495 | (ahc_inb(ahc, port+2) << 16) in ahc_inq()
496 | (ahc_inb(ahc, port+3) << 24) in ahc_inq()
497 | (((uint64_t)ahc_inb(ahc, port+4)) << 32) in ahc_inq()
498 | (((uint64_t)ahc_inb(ahc, port+5)) << 40) in ahc_inq()
499 | (((uint64_t)ahc_inb(ahc, port+6)) << 48) in ahc_inq()
500 | (((uint64_t)ahc_inb(ahc, port+7)) << 56)); in ahc_inq()
504 ahc_outq(struct ahc_softc *ahc, u_int port, uint64_t value) in ahc_outq() argument
506 ahc_outb(ahc, port, value & 0xFF); in ahc_outq()
507 ahc_outb(ahc, port+1, (value >> 8) & 0xFF); in ahc_outq()
508 ahc_outb(ahc, port+2, (value >> 16) & 0xFF); in ahc_outq()
509 ahc_outb(ahc, port+3, (value >> 24) & 0xFF); in ahc_outq()
510 ahc_outb(ahc, port+4, (value >> 32) & 0xFF); in ahc_outq()
511 ahc_outb(ahc, port+5, (value >> 40) & 0xFF); in ahc_outq()
512 ahc_outb(ahc, port+6, (value >> 48) & 0xFF); in ahc_outq()
513 ahc_outb(ahc, port+7, (value >> 56) & 0xFF); in ahc_outq()
520 ahc_get_scb(struct ahc_softc *ahc) in ahc_get_scb() argument
524 if ((scb = SLIST_FIRST(&ahc->scb_data->free_scbs)) == NULL) { in ahc_get_scb()
525 ahc_alloc_scbs(ahc); in ahc_get_scb()
526 scb = SLIST_FIRST(&ahc->scb_data->free_scbs); in ahc_get_scb()
530 SLIST_REMOVE_HEAD(&ahc->scb_data->free_scbs, links.sle); in ahc_get_scb()
538 ahc_free_scb(struct ahc_softc *ahc, struct scb *scb) in ahc_free_scb() argument
544 ahc->scb_data->scbindex[hscb->tag] = NULL; in ahc_free_scb()
548 SLIST_INSERT_HEAD(&ahc->scb_data->free_scbs, scb, links.sle); in ahc_free_scb()
551 ahc_platform_scb_free(ahc, scb); in ahc_free_scb()
555 ahc_lookup_scb(struct ahc_softc *ahc, u_int tag) in ahc_lookup_scb() argument
559 scb = ahc->scb_data->scbindex[tag]; in ahc_lookup_scb()
561 ahc_sync_scb(ahc, scb, in ahc_lookup_scb()
567 ahc_swap_with_next_hscb(struct ahc_softc *ahc, struct scb *scb) in ahc_swap_with_next_hscb() argument
584 q_hscb = ahc->next_queued_scb->hscb; in ahc_swap_with_next_hscb()
589 ahc_htole32(ahc_hscb_busaddr(ahc, q_hscb->tag) in ahc_swap_with_next_hscb()
596 ahc->next_queued_scb->hscb = scb->hscb; in ahc_swap_with_next_hscb()
600 ahc->scb_data->scbindex[scb->hscb->tag] = scb; in ahc_swap_with_next_hscb()
607 ahc_queue_scb(struct ahc_softc *ahc, struct scb *scb) in ahc_queue_scb() argument
609 ahc_swap_with_next_hscb(ahc, scb); in ahc_queue_scb()
626 ahc->qinfifo[ahc->qinfifonext++] = scb->hscb->tag; in ahc_queue_scb()
632 ahc_sync_scb(ahc, scb, BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE); in ahc_queue_scb()
635 if ((ahc->features & AHC_QUEUE_REGS) != 0) { in ahc_queue_scb()
636 ahc_outb(ahc, HNSCB_QOFF, ahc->qinfifonext); in ahc_queue_scb()
638 if ((ahc->features & AHC_AUTOPAUSE) == 0) in ahc_queue_scb()
639 ahc_pause(ahc); in ahc_queue_scb()
640 ahc_outb(ahc, KERNEL_QINPOS, ahc->qinfifonext); in ahc_queue_scb()
641 if ((ahc->features & AHC_AUTOPAUSE) == 0) in ahc_queue_scb()
642 ahc_unpause(ahc); in ahc_queue_scb()
647 ahc_get_sense_buf(struct ahc_softc *ahc, struct scb *scb) in ahc_get_sense_buf() argument
651 offset = scb - ahc->scb_data->scbarray; in ahc_get_sense_buf()
652 return (&ahc->scb_data->sense[offset]); in ahc_get_sense_buf()
656 ahc_get_sense_bufaddr(struct ahc_softc *ahc, struct scb *scb) in ahc_get_sense_bufaddr() argument
660 offset = scb - ahc->scb_data->scbarray; in ahc_get_sense_bufaddr()
661 return (ahc->scb_data->sense_busaddr in ahc_get_sense_bufaddr()
667 ahc_sync_qoutfifo(struct ahc_softc *ahc, int op) in ahc_sync_qoutfifo() argument
669 ahc_dmamap_sync(ahc, ahc->shared_data_dmat, ahc->shared_data_dmamap, in ahc_sync_qoutfifo()
674 ahc_sync_tqinfifo(struct ahc_softc *ahc, int op) in ahc_sync_tqinfifo() argument
677 if ((ahc->flags & AHC_TARGETROLE) != 0) { in ahc_sync_tqinfifo()
678 ahc_dmamap_sync(ahc, ahc->shared_data_dmat, in ahc_sync_tqinfifo()
679 ahc->shared_data_dmamap, in ahc_sync_tqinfifo()
680 ahc_targetcmd_offset(ahc, 0), in ahc_sync_tqinfifo()
694 ahc_check_cmdcmpltqueues(struct ahc_softc *ahc) in ahc_check_cmdcmpltqueues() argument
699 ahc_dmamap_sync(ahc, ahc->shared_data_dmat, ahc->shared_data_dmamap, in ahc_check_cmdcmpltqueues()
700 /*offset*/ahc->qoutfifonext, /*len*/1, in ahc_check_cmdcmpltqueues()
702 if (ahc->qoutfifo[ahc->qoutfifonext] != SCB_LIST_NULL) in ahc_check_cmdcmpltqueues()
705 if ((ahc->flags & AHC_TARGETROLE) != 0 in ahc_check_cmdcmpltqueues()
706 && (ahc->flags & AHC_TQINFIFO_BLOCKED) == 0) { in ahc_check_cmdcmpltqueues()
707 ahc_dmamap_sync(ahc, ahc->shared_data_dmat, in ahc_check_cmdcmpltqueues()
708 ahc->shared_data_dmamap, in ahc_check_cmdcmpltqueues()
709 ahc_targetcmd_offset(ahc, ahc->tqinfifofnext), in ahc_check_cmdcmpltqueues()
712 if (ahc->targetcmds[ahc->tqinfifonext].cmd_valid != 0) in ahc_check_cmdcmpltqueues()
723 ahc_intr(struct ahc_softc *ahc) in ahc_intr() argument
727 if ((ahc->pause & INTEN) == 0) { in ahc_intr()
742 if ((ahc->flags & (AHC_ALL_INTERRUPTS|AHC_EDGE_INTERRUPT)) == 0 in ahc_intr()
743 && (ahc_check_cmdcmpltqueues(ahc) != 0)) in ahc_intr()
746 intstat = ahc_inb(ahc, INTSTAT); in ahc_intr()
751 if (ahc->unsolicited_ints > 500) { in ahc_intr()
752 ahc->unsolicited_ints = 0; in ahc_intr()
753 if ((ahc->chip & AHC_PCI) != 0 in ahc_intr()
754 && (ahc_inb(ahc, ERROR) & PCIERRSTAT) != 0) in ahc_intr()
755 ahc->bus_intr(ahc); in ahc_intr()
758 ahc->unsolicited_ints++; in ahc_intr()
761 ahc->unsolicited_ints = 0; in ahc_intr()
764 ahc_outb(ahc, CLRINT, CLRCMDINT); in ahc_intr()
774 ahc_flush_device_writes(ahc); in ahc_intr()
775 ahc_run_qoutfifo(ahc); in ahc_intr()
777 if ((ahc->flags & AHC_TARGETROLE) != 0) in ahc_intr()
778 ahc_run_tqinfifo(ahc, /*paused*/FALSE); in ahc_intr()
786 if (intstat == 0xFF && (ahc->features & AHC_REMOVABLE) != 0) { in ahc_intr()
789 ahc_handle_brkadrint(ahc); in ahc_intr()
792 ahc_pause_bug_fix(ahc); in ahc_intr()
795 ahc_handle_seqint(ahc, intstat); in ahc_intr()
798 ahc_handle_scsiint(ahc, intstat); in ahc_intr()
808 ahc_restart(struct ahc_softc *ahc) in ahc_restart() argument
812 ahc_pause(ahc); in ahc_restart()
815 ahc_clear_msg_state(ahc); in ahc_restart()
817 ahc_outb(ahc, SCSISIGO, 0); /* De-assert BSY */ in ahc_restart()
818 ahc_outb(ahc, MSG_OUT, MSG_NOOP); /* No message to send */ in ahc_restart()
819 ahc_outb(ahc, SXFRCTL1, ahc_inb(ahc, SXFRCTL1) & ~BITBUCKET); in ahc_restart()
820 ahc_outb(ahc, LASTPHASE, P_BUSFREE); in ahc_restart()
821 ahc_outb(ahc, SAVED_SCSIID, 0xFF); in ahc_restart()
822 ahc_outb(ahc, SAVED_LUN, 0xFF); in ahc_restart()
831 ahc_outb(ahc, TQINPOS, ahc->tqinfifonext); in ahc_restart()
834 ahc_outb(ahc, SCSISEQ, in ahc_restart()
835 ahc_inb(ahc, SCSISEQ_TEMPLATE) & (ENSELI|ENRSELI|ENAUTOATNP)); in ahc_restart()
836 if ((ahc->features & AHC_CMD_CHAN) != 0) { in ahc_restart()
838 ahc_outb(ahc, CCSCBCNT, 0); in ahc_restart()
839 ahc_outb(ahc, CCSGCTL, 0); in ahc_restart()
840 ahc_outb(ahc, CCSCBCTL, 0); in ahc_restart()
847 if ((ahc_inb(ahc, SEQ_FLAGS2) & SCB_DMA) != 0) { in ahc_restart()
848 ahc_add_curscb_to_free_list(ahc); in ahc_restart()
849 ahc_outb(ahc, SEQ_FLAGS2, in ahc_restart()
850 ahc_inb(ahc, SEQ_FLAGS2) & ~SCB_DMA); in ahc_restart()
858 ahc_outb(ahc, CLRINT, CLRSEQINT); in ahc_restart()
860 ahc_outb(ahc, MWI_RESIDUAL, 0); in ahc_restart()
861 ahc_outb(ahc, SEQCTL, ahc->seqctl); in ahc_restart()
862 ahc_outb(ahc, SEQADDR0, 0); in ahc_restart()
863 ahc_outb(ahc, SEQADDR1, 0); in ahc_restart()
868 sblkctl = ahc_inb(ahc, SBLKCTL); in ahc_restart()
869 ahc_outb(ahc, SBLKCTL, (sblkctl & ~(DIAGLEDEN|DIAGLEDON))); in ahc_restart()
871 ahc_unpause(ahc); in ahc_restart()
876 ahc_run_qoutfifo(struct ahc_softc *ahc) in ahc_run_qoutfifo() argument
881 ahc_sync_qoutfifo(ahc, BUS_DMASYNC_POSTREAD); in ahc_run_qoutfifo()
882 while (ahc->qoutfifo[ahc->qoutfifonext] != SCB_LIST_NULL) { in ahc_run_qoutfifo()
884 scb_index = ahc->qoutfifo[ahc->qoutfifonext]; in ahc_run_qoutfifo()
885 if ((ahc->qoutfifonext & 0x03) == 0x03) { in ahc_run_qoutfifo()
895 modnext = ahc->qoutfifonext & ~0x3; in ahc_run_qoutfifo()
896 *((uint32_t *)(&ahc->qoutfifo[modnext])) = 0xFFFFFFFFUL; in ahc_run_qoutfifo()
897 ahc_dmamap_sync(ahc, ahc->shared_data_dmat, in ahc_run_qoutfifo()
898 ahc->shared_data_dmamap, in ahc_run_qoutfifo()
902 ahc->qoutfifonext++; in ahc_run_qoutfifo()
904 scb = ahc_lookup_scb(ahc, scb_index); in ahc_run_qoutfifo()
908 ahc_name(ahc), scb_index, in ahc_run_qoutfifo()
909 (ahc->qoutfifonext - 1) & 0xFF); in ahc_run_qoutfifo()
917 ahc_update_residual(ahc, scb); in ahc_run_qoutfifo()
918 ahc_done(ahc, scb); in ahc_run_qoutfifo()
923 ahc_run_untagged_queues(struct ahc_softc *ahc) in ahc_run_untagged_queues() argument
928 ahc_run_untagged_queue(ahc, &ahc->untagged_queues[i]); in ahc_run_untagged_queues()
932 ahc_run_untagged_queue(struct ahc_softc *ahc, struct scb_tailq *queue) in ahc_run_untagged_queue() argument
936 if (ahc->untagged_queue_lock != 0) in ahc_run_untagged_queue()
942 ahc_queue_scb(ahc, scb); in ahc_run_untagged_queue()
948 ahc_handle_brkadrint(struct ahc_softc *ahc) in ahc_handle_brkadrint() argument
957 error = ahc_inb(ahc, ERROR); in ahc_handle_brkadrint()
961 ahc_name(ahc), ahc_hard_errors[i].errmesg, in ahc_handle_brkadrint()
962 ahc_inb(ahc, SEQADDR0) | in ahc_handle_brkadrint()
963 (ahc_inb(ahc, SEQADDR1) << 8)); in ahc_handle_brkadrint()
965 ahc_dump_card_state(ahc); in ahc_handle_brkadrint()
968 ahc_abort_scbs(ahc, CAM_TARGET_WILDCARD, ALL_CHANNELS, in ahc_handle_brkadrint()
973 ahc_shutdown(ahc); in ahc_handle_brkadrint()
977 ahc_handle_seqint(struct ahc_softc *ahc, u_int intstat) in ahc_handle_seqint() argument
982 ahc_fetch_devinfo(ahc, &devinfo); in ahc_handle_seqint()
990 ahc_outb(ahc, CLRINT, CLRSEQINT); in ahc_handle_seqint()
1002 ahc_outb(ahc, RETURN_1, 0); in ahc_handle_seqint()
1013 scb_index = ahc_inb(ahc, SCB_TAG); in ahc_handle_seqint()
1014 scb = ahc_lookup_scb(ahc, scb_index); in ahc_handle_seqint()
1016 ahc_print_devinfo(ahc, &devinfo); in ahc_handle_seqint()
1020 ahc_dump_card_state(ahc); in ahc_handle_seqint()
1040 ahc_freeze_devq(ahc, scb); in ahc_handle_seqint()
1046 ahc_name(ahc)); in ahc_handle_seqint()
1058 ahc_print_path(ahc, scb); in ahc_handle_seqint()
1067 targ_info = ahc_fetch_transinfo(ahc, in ahc_handle_seqint()
1078 ahc_update_residual(ahc, scb); in ahc_handle_seqint()
1081 ahc_print_path(ahc, scb); in ahc_handle_seqint()
1085 sg->addr = ahc_get_sense_bufaddr(ahc, scb); in ahc_handle_seqint()
1086 sg->len = ahc_get_sense_bufsize(ahc, scb); in ahc_handle_seqint()
1122 ahc_update_neg_request(ahc, &devinfo, in ahc_handle_seqint()
1138 ahc_qinfifo_requeue_tail(ahc, scb); in ahc_handle_seqint()
1139 ahc_outb(ahc, RETURN_1, SEND_SENSE); in ahc_handle_seqint()
1155 ahc_outb(ahc, SCSISEQ, in ahc_handle_seqint()
1156 ahc_inb(ahc, SCSISEQ) & (ENSELI|ENRSELI|ENAUTOATNP)); in ahc_handle_seqint()
1160 ahc_name(ahc), devinfo.channel, devinfo.target); in ahc_handle_seqint()
1163 ahc_inb(ahc, SAVED_SCSIID), ahc_inb(ahc, SAVED_LUN), in ahc_handle_seqint()
1164 ahc_inb(ahc, ARG_1), ahc_inb(ahc, ACCUM)); in ahc_handle_seqint()
1167 ahc_inb(ahc, SEQ_FLAGS), ahc_inb(ahc, SCBPTR), in ahc_handle_seqint()
1168 ahc_index_busy_tcl(ahc, in ahc_handle_seqint()
1169 BUILD_TCL(ahc_inb(ahc, SAVED_SCSIID), in ahc_handle_seqint()
1170 ahc_inb(ahc, SAVED_LUN))), in ahc_handle_seqint()
1171 ahc_inb(ahc, SINDEX)); in ahc_handle_seqint()
1174 ahc_inb(ahc, SCSIID), ahc_inb(ahc, SCB_SCSIID), in ahc_handle_seqint()
1175 ahc_inb(ahc, SCB_LUN), ahc_inb(ahc, SCB_TAG), in ahc_handle_seqint()
1176 ahc_inb(ahc, SCB_CONTROL)); in ahc_handle_seqint()
1178 ahc_inb(ahc, SCSIBUSL), ahc_inb(ahc, SCSISIGI)); in ahc_handle_seqint()
1179 printk("SXFRCTL0 == 0x%x\n", ahc_inb(ahc, SXFRCTL0)); in ahc_handle_seqint()
1180 printk("SEQCTL == 0x%x\n", ahc_inb(ahc, SEQCTL)); in ahc_handle_seqint()
1181 ahc_dump_card_state(ahc); in ahc_handle_seqint()
1182 ahc->msgout_buf[0] = MSG_BUS_DEV_RESET; in ahc_handle_seqint()
1183 ahc->msgout_len = 1; in ahc_handle_seqint()
1184 ahc->msgout_index = 0; in ahc_handle_seqint()
1185 ahc->msg_type = MSG_TYPE_INITIATOR_MSGOUT; in ahc_handle_seqint()
1186 ahc_outb(ahc, MSG_OUT, HOST_MSG); in ahc_handle_seqint()
1187 ahc_assert_atn(ahc); in ahc_handle_seqint()
1192 u_int rejbyte = ahc_inb(ahc, ACCUM); in ahc_handle_seqint()
1195 ahc_name(ahc), devinfo.channel, devinfo.target, rejbyte); in ahc_handle_seqint()
1200 ahc_handle_proto_violation(ahc); in ahc_handle_seqint()
1204 ahc_handle_ign_wide_residue(ahc, &devinfo); in ahc_handle_seqint()
1207 ahc_reinitialize_dataptrs(ahc); in ahc_handle_seqint()
1213 lastphase = ahc_inb(ahc, LASTPHASE); in ahc_handle_seqint()
1216 ahc_name(ahc), devinfo.channel, devinfo.target, in ahc_handle_seqint()
1217 lastphase, ahc_inb(ahc, SCSISIGI)); in ahc_handle_seqint()
1224 lastphase = ahc_inb(ahc, LASTPHASE); in ahc_handle_seqint()
1227 ahc_name(ahc), devinfo.channel, devinfo.target, in ahc_handle_seqint()
1228 lastphase, ahc_inb(ahc, SCSISIGI)); in ahc_handle_seqint()
1229 ahc_restart(ahc); in ahc_handle_seqint()
1245 if (ahc->msg_type == MSG_TYPE_NONE) { in ahc_handle_seqint()
1250 bus_phase = ahc_inb(ahc, SCSISIGI) & PHASE_MASK; in ahc_handle_seqint()
1260 ahc_clear_intstat(ahc); in ahc_handle_seqint()
1261 ahc_restart(ahc); in ahc_handle_seqint()
1265 scb_index = ahc_inb(ahc, SCB_TAG); in ahc_handle_seqint()
1266 scb = ahc_lookup_scb(ahc, scb_index); in ahc_handle_seqint()
1274 ahc_setup_initiator_msgout(ahc, in ahc_handle_seqint()
1278 ahc->msg_type = in ahc_handle_seqint()
1280 ahc->msgin_index = 0; in ahc_handle_seqint()
1286 ahc->msg_type = in ahc_handle_seqint()
1288 ahc->msgin_index = 0; in ahc_handle_seqint()
1291 ahc_setup_target_msgin(ahc, in ahc_handle_seqint()
1298 ahc_handle_message_phase(ahc); in ahc_handle_seqint()
1315 && (ahc_inb(ahc, SSTAT1) & SCSIPERR) != 0) { in ahc_handle_seqint()
1317 if ((ahc->features & AHC_DT) == 0) { in ahc_handle_seqint()
1326 curphase = ahc_inb(ahc, SCSISIGI) & PHASE_MASK; in ahc_handle_seqint()
1327 ahc_outb(ahc, LASTPHASE, curphase); in ahc_handle_seqint()
1328 ahc_outb(ahc, SCSISIGO, curphase); in ahc_handle_seqint()
1330 if ((ahc_inb(ahc, SCSISIGI) & (CDI|MSGI)) == 0) { in ahc_handle_seqint()
1339 ahc_outb(ahc, SXFRCTL1, in ahc_handle_seqint()
1340 ahc_inb(ahc, SXFRCTL1) | BITBUCKET); in ahc_handle_seqint()
1343 if ((ahc_inb(ahc, SCSISIGI) in ahc_handle_seqint()
1348 ahc_outb(ahc, SXFRCTL1, in ahc_handle_seqint()
1349 ahc_inb(ahc, SXFRCTL1) & ~BITBUCKET); in ahc_handle_seqint()
1354 ahc_print_devinfo(ahc, &devinfo); in ahc_handle_seqint()
1357 scb_index = ahc_inb(ahc, SCB_TAG); in ahc_handle_seqint()
1358 scb = ahc_lookup_scb(ahc, scb_index); in ahc_handle_seqint()
1362 ahc_reset_channel(ahc, devinfo.channel, in ahc_handle_seqint()
1366 ahc_inb(ahc, SCSIDATL); in ahc_handle_seqint()
1381 u_int scbindex = ahc_inb(ahc, SCB_TAG); in ahc_handle_seqint()
1382 u_int lastphase = ahc_inb(ahc, LASTPHASE); in ahc_handle_seqint()
1385 scb = ahc_lookup_scb(ahc, scbindex); in ahc_handle_seqint()
1390 ahc_print_path(ahc, scb); in ahc_handle_seqint()
1395 ahc_print_path(ahc, scb); in ahc_handle_seqint()
1397 ahc_inb(ahc, SEQ_FLAGS) & DPHASE ? "Have" : "Haven't", in ahc_handle_seqint()
1415 ahc_freeze_devq(ahc, scb); in ahc_handle_seqint()
1424 if ((ahc->features & AHC_ULTRA2) != 0) { in ahc_handle_seqint()
1429 ahc_outb(ahc, SXFRCTL0, in ahc_handle_seqint()
1430 ahc_inb(ahc, SXFRCTL0) | CLRSTCNT|CLRCHN); in ahc_handle_seqint()
1431 ahc_outb(ahc, SXFRCTL0, in ahc_handle_seqint()
1432 ahc_inb(ahc, SXFRCTL0) | CLRSTCNT|CLRCHN); in ahc_handle_seqint()
1434 if ((ahc->flags & AHC_39BIT_ADDRESSING) != 0) { in ahc_handle_seqint()
1438 dscommand1 = ahc_inb(ahc, DSCOMMAND1); in ahc_handle_seqint()
1439 ahc_outb(ahc, DSCOMMAND1, dscommand1 | HADDLDSEL0); in ahc_handle_seqint()
1440 ahc_outb(ahc, HADDR, 0); in ahc_handle_seqint()
1441 ahc_outb(ahc, DSCOMMAND1, dscommand1); in ahc_handle_seqint()
1450 ahc_name(ahc), devinfo.channel, devinfo.target, in ahc_handle_seqint()
1452 scbindex = ahc_inb(ahc, SCB_TAG); in ahc_handle_seqint()
1453 scb = ahc_lookup_scb(ahc, scbindex); in ahc_handle_seqint()
1460 ahc_search_qinfifo(ahc, SCB_GET_TARGET(ahc, scb), in ahc_handle_seqint()
1461 SCB_GET_CHANNEL(ahc, scb), in ahc_handle_seqint()
1469 printk("%s: No free or disconnected SCBs\n", ahc_name(ahc)); in ahc_handle_seqint()
1470 ahc_dump_card_state(ahc); in ahc_handle_seqint()
1478 scbptr = ahc_inb(ahc, SCBPTR); in ahc_handle_seqint()
1480 scbptr, ahc_inb(ahc, ARG_1), in ahc_handle_seqint()
1481 ahc->scb_data->hscbs[scbptr].tag); in ahc_handle_seqint()
1482 ahc_dump_card_state(ahc); in ahc_handle_seqint()
1488 printk("%s: BTT calculation out of range\n", ahc_name(ahc)); in ahc_handle_seqint()
1491 ahc_inb(ahc, SAVED_SCSIID), ahc_inb(ahc, SAVED_LUN), in ahc_handle_seqint()
1492 ahc_inb(ahc, ARG_1), ahc_inb(ahc, ACCUM)); in ahc_handle_seqint()
1495 ahc_inb(ahc, SEQ_FLAGS), ahc_inb(ahc, SCBPTR), in ahc_handle_seqint()
1496 ahc_index_busy_tcl(ahc, in ahc_handle_seqint()
1497 BUILD_TCL(ahc_inb(ahc, SAVED_SCSIID), in ahc_handle_seqint()
1498 ahc_inb(ahc, SAVED_LUN))), in ahc_handle_seqint()
1499 ahc_inb(ahc, SINDEX), in ahc_handle_seqint()
1500 ahc_inb(ahc, ACCUM)); in ahc_handle_seqint()
1503 ahc_inb(ahc, SCSIID), ahc_inb(ahc, SCB_SCSIID), in ahc_handle_seqint()
1504 ahc_inb(ahc, SCB_LUN), ahc_inb(ahc, SCB_TAG), in ahc_handle_seqint()
1505 ahc_inb(ahc, SCB_CONTROL)); in ahc_handle_seqint()
1507 ahc_inb(ahc, SCSIBUSL), ahc_inb(ahc, SCSISIGI)); in ahc_handle_seqint()
1508 ahc_dump_card_state(ahc); in ahc_handle_seqint()
1515 intstat, ahc_inb(ahc, SCSISIGI)); in ahc_handle_seqint()
1524 ahc_unpause(ahc); in ahc_handle_seqint()
1528 ahc_handle_scsiint(struct ahc_softc *ahc, u_int intstat) in ahc_handle_scsiint() argument
1537 if ((ahc->features & AHC_TWIN) != 0 in ahc_handle_scsiint()
1538 && ((ahc_inb(ahc, SBLKCTL) & SELBUSB) != 0)) in ahc_handle_scsiint()
1544 if ((ahc->features & AHC_ULTRA2) != 0) in ahc_handle_scsiint()
1545 status0 = ahc_inb(ahc, SSTAT0) & IOERR; in ahc_handle_scsiint()
1548 status = ahc_inb(ahc, SSTAT1) & (SELTO|SCSIRSTI|BUSFREE|SCSIPERR); in ahc_handle_scsiint()
1550 if ((ahc->features & AHC_TWIN) != 0) { in ahc_handle_scsiint()
1552 ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) ^ SELBUSB); in ahc_handle_scsiint()
1553 status = ahc_inb(ahc, SSTAT1) in ahc_handle_scsiint()
1558 printk("%s: Spurious SCSI interrupt\n", ahc_name(ahc)); in ahc_handle_scsiint()
1559 ahc_outb(ahc, CLRINT, CLRSCSIINT); in ahc_handle_scsiint()
1560 ahc_unpause(ahc); in ahc_handle_scsiint()
1566 ahc_clear_critical_section(ahc); in ahc_handle_scsiint()
1568 scb_index = ahc_inb(ahc, SCB_TAG); in ahc_handle_scsiint()
1569 scb = ahc_lookup_scb(ahc, scb_index); in ahc_handle_scsiint()
1571 && (ahc_inb(ahc, SEQ_FLAGS) & NOT_IDENTIFIED) != 0) in ahc_handle_scsiint()
1574 if ((ahc->features & AHC_ULTRA2) != 0 in ahc_handle_scsiint()
1578 now_lvd = ahc_inb(ahc, SBLKCTL) & ENAB40; in ahc_handle_scsiint()
1580 ahc_name(ahc), now_lvd ? "LVD" : "SE"); in ahc_handle_scsiint()
1581 ahc_outb(ahc, CLRSINT0, CLRIOERR); in ahc_handle_scsiint()
1592 ahc_reset_channel(ahc, intr_channel, in ahc_handle_scsiint()
1596 ahc_name(ahc), intr_channel); in ahc_handle_scsiint()
1598 ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) ^ SELBUSB); in ahc_handle_scsiint()
1599 ahc_reset_channel(ahc, intr_channel, /*Initiate Reset*/FALSE); in ahc_handle_scsiint()
1621 lastphase = ahc_inb(ahc, LASTPHASE); in ahc_handle_scsiint()
1622 curphase = ahc_inb(ahc, SCSISIGI) & PHASE_MASK; in ahc_handle_scsiint()
1623 sstat2 = ahc_inb(ahc, SSTAT2); in ahc_handle_scsiint()
1624 ahc_outb(ahc, CLRSINT1, CLRSCSIPERR); in ahc_handle_scsiint()
1636 if ((ahc_inb(ahc, SSTAT1) & SCSIPERR) != 0 in ahc_handle_scsiint()
1652 ahc_print_path(ahc, scb); in ahc_handle_scsiint()
1655 printk("%s:%c:%d: ", ahc_name(ahc), intr_channel, in ahc_handle_scsiint()
1656 SCSIID_TARGET(ahc, ahc_inb(ahc, SAVED_SCSIID))); in ahc_handle_scsiint()
1657 scsirate = ahc_inb(ahc, SCSIRATE); in ahc_handle_scsiint()
1662 ahc_inw(ahc, SEQADDR0), in ahc_handle_scsiint()
1664 if ((ahc->features & AHC_DT) != 0) { in ahc_handle_scsiint()
1680 if ((ahc->features & AHC_DT) != 0 in ahc_handle_scsiint()
1698 if (ahc->msg_type != MSG_TYPE_NONE) in ahc_handle_scsiint()
1699 ahc->send_msg_perror = TRUE; in ahc_handle_scsiint()
1701 ahc_outb(ahc, MSG_OUT, mesg_out); in ahc_handle_scsiint()
1708 ahc_fetch_devinfo(ahc, &devinfo); in ahc_handle_scsiint()
1709 ahc_force_renegotiation(ahc, &devinfo); in ahc_handle_scsiint()
1711 ahc_outb(ahc, CLRINT, CLRSCSIINT); in ahc_handle_scsiint()
1712 ahc_unpause(ahc); in ahc_handle_scsiint()
1717 ahc_outb(ahc, SCSISEQ, 0); in ahc_handle_scsiint()
1720 ahc_clear_msg_state(ahc); in ahc_handle_scsiint()
1723 ahc_outb(ahc, SIMODE1, ahc_inb(ahc, SIMODE1) & ~ENBUSFREE); in ahc_handle_scsiint()
1724 ahc_outb(ahc, CLRSINT1, CLRSELTIMEO|CLRBUSFREE|CLRSCSIPERR); in ahc_handle_scsiint()
1734 ahc_outb(ahc, CLRSINT0, CLRSELINGO); in ahc_handle_scsiint()
1736 scbptr = ahc_inb(ahc, WAITING_SCBH); in ahc_handle_scsiint()
1737 ahc_outb(ahc, SCBPTR, scbptr); in ahc_handle_scsiint()
1738 scb_index = ahc_inb(ahc, SCB_TAG); in ahc_handle_scsiint()
1740 scb = ahc_lookup_scb(ahc, scb_index); in ahc_handle_scsiint()
1744 ahc_name(ahc), scbptr, scb_index); in ahc_handle_scsiint()
1745 ahc_dump_card_state(ahc); in ahc_handle_scsiint()
1750 ahc_print_path(ahc, scb); in ahc_handle_scsiint()
1755 ahc_scb_devinfo(ahc, &devinfo, scb); in ahc_handle_scsiint()
1757 ahc_freeze_devq(ahc, scb); in ahc_handle_scsiint()
1765 ahc_handle_devreset(ahc, &devinfo, in ahc_handle_scsiint()
1770 ahc_outb(ahc, CLRINT, CLRSCSIINT); in ahc_handle_scsiint()
1771 ahc_restart(ahc); in ahc_handle_scsiint()
1773 && (ahc_inb(ahc, SIMODE1) & ENBUSFREE) != 0) { in ahc_handle_scsiint()
1789 ahc_outb(ahc, SCSISEQ, in ahc_handle_scsiint()
1790 ahc_inb(ahc, SCSISEQ) & (ENSELI|ENRSELI|ENAUTOATNP)); in ahc_handle_scsiint()
1798 ahc_outb(ahc, SIMODE1, ahc_inb(ahc, SIMODE1) & ~ENBUSFREE); in ahc_handle_scsiint()
1799 ahc_outb(ahc, CLRSINT1, CLRBUSFREE|CLRSCSIPERR); in ahc_handle_scsiint()
1807 lastphase = ahc_inb(ahc, LASTPHASE); in ahc_handle_scsiint()
1808 saved_scsiid = ahc_inb(ahc, SAVED_SCSIID); in ahc_handle_scsiint()
1809 saved_lun = ahc_inb(ahc, SAVED_LUN); in ahc_handle_scsiint()
1810 target = SCSIID_TARGET(ahc, saved_scsiid); in ahc_handle_scsiint()
1812 channel = SCSIID_CHANNEL(ahc, saved_scsiid); in ahc_handle_scsiint()
1821 if (ahc_sent_msg(ahc, AHCMSG_1B, MSG_ABORT_TAG, TRUE) in ahc_handle_scsiint()
1822 || ahc_sent_msg(ahc, AHCMSG_1B, MSG_ABORT, TRUE)) { in ahc_handle_scsiint()
1823 if (ahc->msgout_buf[ahc->msgout_index - 1] in ahc_handle_scsiint()
1826 ahc_print_path(ahc, scb); in ahc_handle_scsiint()
1830 ahc_abort_scbs(ahc, target, channel, in ahc_handle_scsiint()
1835 } else if (ahc_sent_msg(ahc, AHCMSG_1B, in ahc_handle_scsiint()
1845 && ahc_match_scb(ahc, scb, target, channel, in ahc_handle_scsiint()
1858 ahc_handle_devreset(ahc, &devinfo, in ahc_handle_scsiint()
1863 } else if (ahc_sent_msg(ahc, AHCMSG_EXT, in ahc_handle_scsiint()
1872 tinfo = ahc_fetch_transinfo(ahc, in ahc_handle_scsiint()
1880 ahc_qinfifo_requeue_tail(ahc, scb); in ahc_handle_scsiint()
1882 } else if (ahc_sent_msg(ahc, AHCMSG_EXT, in ahc_handle_scsiint()
1888 ahc_set_width(ahc, &devinfo, in ahc_handle_scsiint()
1892 ahc_qinfifo_requeue_tail(ahc, scb); in ahc_handle_scsiint()
1894 } else if (ahc_sent_msg(ahc, AHCMSG_EXT, in ahc_handle_scsiint()
1900 ahc_set_syncrate(ahc, &devinfo, in ahc_handle_scsiint()
1906 ahc_qinfifo_requeue_tail(ahc, scb); in ahc_handle_scsiint()
1920 ahc_print_path(ahc, scb); in ahc_handle_scsiint()
1921 ahc_abort_scbs(ahc, target, channel, in ahc_handle_scsiint()
1930 printk("%s: ", ahc_name(ahc)); in ahc_handle_scsiint()
1943 ahc_force_renegotiation(ahc, &devinfo); in ahc_handle_scsiint()
1948 ahc_inb(ahc, SEQADDR0) in ahc_handle_scsiint()
1949 | (ahc_inb(ahc, SEQADDR1) << 8)); in ahc_handle_scsiint()
1951 ahc_outb(ahc, CLRINT, CLRSCSIINT); in ahc_handle_scsiint()
1952 ahc_restart(ahc); in ahc_handle_scsiint()
1955 ahc_name(ahc), status); in ahc_handle_scsiint()
1956 ahc_outb(ahc, CLRINT, CLRSCSIINT); in ahc_handle_scsiint()
1965 ahc_force_renegotiation(struct ahc_softc *ahc, struct ahc_devinfo *devinfo) in ahc_force_renegotiation() argument
1970 targ_info = ahc_fetch_transinfo(ahc, in ahc_force_renegotiation()
1975 ahc_update_neg_request(ahc, devinfo, tstate, in ahc_force_renegotiation()
1981 ahc_clear_critical_section(struct ahc_softc *ahc) in ahc_clear_critical_section() argument
1988 if (ahc->num_critical_sections == 0) in ahc_clear_critical_section()
2000 seqaddr = ahc_inb(ahc, SEQADDR0) in ahc_clear_critical_section()
2001 | (ahc_inb(ahc, SEQADDR1) << 8); in ahc_clear_critical_section()
2010 cs = ahc->critical_sections; in ahc_clear_critical_section()
2011 for (i = 0; i < ahc->num_critical_sections; i++, cs++) { in ahc_clear_critical_section()
2017 if (i == ahc->num_critical_sections) in ahc_clear_critical_section()
2022 ahc_name(ahc)); in ahc_clear_critical_section()
2023 ahc_dump_card_state(ahc); in ahc_clear_critical_section()
2036 simode0 = ahc_inb(ahc, SIMODE0); in ahc_clear_critical_section()
2037 ahc_outb(ahc, SIMODE0, 0); in ahc_clear_critical_section()
2038 simode1 = ahc_inb(ahc, SIMODE1); in ahc_clear_critical_section()
2039 if ((ahc->features & AHC_DT) != 0) in ahc_clear_critical_section()
2048 ahc_outb(ahc, SIMODE1, simode1 & ENBUSFREE); in ahc_clear_critical_section()
2050 ahc_outb(ahc, SIMODE1, 0); in ahc_clear_critical_section()
2051 ahc_outb(ahc, CLRINT, CLRSCSIINT); in ahc_clear_critical_section()
2052 ahc_outb(ahc, SEQCTL, ahc->seqctl | STEP); in ahc_clear_critical_section()
2055 if ((ahc->features & AHC_DT) != 0) { in ahc_clear_critical_section()
2056 ahc_outb(ahc, CLRSINT1, CLRBUSFREE); in ahc_clear_critical_section()
2057 ahc_outb(ahc, CLRINT, CLRSCSIINT); in ahc_clear_critical_section()
2059 ahc_outb(ahc, HCNTRL, ahc->unpause); in ahc_clear_critical_section()
2060 while (!ahc_is_paused(ahc)) in ahc_clear_critical_section()
2064 ahc_outb(ahc, SIMODE0, simode0); in ahc_clear_critical_section()
2065 ahc_outb(ahc, SIMODE1, simode1); in ahc_clear_critical_section()
2066 ahc_outb(ahc, SEQCTL, ahc->seqctl); in ahc_clear_critical_section()
2074 ahc_clear_intstat(struct ahc_softc *ahc) in ahc_clear_intstat() argument
2077 ahc_outb(ahc, CLRSINT1, CLRSELTIMEO|CLRATNO|CLRSCSIRSTI in ahc_clear_intstat()
2080 ahc_flush_device_writes(ahc); in ahc_clear_intstat()
2081 ahc_outb(ahc, CLRSINT0, CLRSELDO|CLRSELDI|CLRSELINGO); in ahc_clear_intstat()
2082 ahc_flush_device_writes(ahc); in ahc_clear_intstat()
2083 ahc_outb(ahc, CLRINT, CLRSCSIINT); in ahc_clear_intstat()
2084 ahc_flush_device_writes(ahc); in ahc_clear_intstat()
2133 ahc_alloc_tstate(struct ahc_softc *ahc, u_int scsi_id, char channel) in ahc_alloc_tstate() argument
2139 master_tstate = ahc->enabled_targets[ahc->our_id]; in ahc_alloc_tstate()
2142 master_tstate = ahc->enabled_targets[ahc->our_id_b + 8]; in ahc_alloc_tstate()
2144 if (ahc->enabled_targets[scsi_id] != NULL in ahc_alloc_tstate()
2145 && ahc->enabled_targets[scsi_id] != master_tstate) in ahc_alloc_tstate()
2147 ahc_name(ahc)); in ahc_alloc_tstate()
2170 ahc->enabled_targets[scsi_id] = tstate; in ahc_alloc_tstate()
2180 ahc_free_tstate(struct ahc_softc *ahc, u_int scsi_id, char channel, int force) in ahc_free_tstate() argument
2188 if (((channel == 'B' && scsi_id == ahc->our_id_b) in ahc_free_tstate()
2189 || (channel == 'A' && scsi_id == ahc->our_id)) in ahc_free_tstate()
2195 tstate = ahc->enabled_targets[scsi_id]; in ahc_free_tstate()
2198 ahc->enabled_targets[scsi_id] = NULL; in ahc_free_tstate()
2209 ahc_devlimited_syncrate(struct ahc_softc *ahc, in ahc_devlimited_syncrate() argument
2216 if ((ahc->features & AHC_ULTRA2) != 0) { in ahc_devlimited_syncrate()
2217 if ((ahc_inb(ahc, SBLKCTL) & ENAB40) != 0 in ahc_devlimited_syncrate()
2218 && (ahc_inb(ahc, SSTAT2) & EXP_ACTIVE) == 0) { in ahc_devlimited_syncrate()
2225 } else if ((ahc->features & AHC_ULTRA) != 0) { in ahc_devlimited_syncrate()
2255 return (ahc_find_syncrate(ahc, period, ppr_options, maxsync)); in ahc_devlimited_syncrate()
2264 ahc_find_syncrate(struct ahc_softc *ahc, u_int *period, in ahc_find_syncrate() argument
2269 if ((ahc->features & AHC_DT) == 0) in ahc_find_syncrate()
2279 if ((ahc->features & (AHC_DT | AHC_ULTRA2)) == 0 in ahc_find_syncrate()
2282 if ((ahc->features & (AHC_DT | AHC_ULTRA2 | AHC_ULTRA)) == 0 in ahc_find_syncrate()
2294 if ((ahc->features & AHC_ULTRA2) != 0 in ahc_find_syncrate()
2325 || ((ahc->features & AHC_ULTRA2) != 0 in ahc_find_syncrate()
2340 ahc_find_period(struct ahc_softc *ahc, u_int scsirate, u_int maxsync) in ahc_find_period() argument
2344 if ((ahc->features & AHC_ULTRA2) != 0) in ahc_find_period()
2350 if ((ahc->features & AHC_DT) == 0 && maxsync < AHC_SYNCRATE_ULTRA2) in ahc_find_period()
2352 if ((ahc->features & (AHC_DT | AHC_ULTRA2)) == 0 in ahc_find_period()
2355 if ((ahc->features & (AHC_DT | AHC_ULTRA2 | AHC_ULTRA)) == 0 in ahc_find_period()
2363 if ((ahc->features & AHC_ULTRA2) != 0) { in ahc_find_period()
2381 ahc_validate_offset(struct ahc_softc *ahc, in ahc_validate_offset() argument
2391 } else if ((ahc->features & AHC_ULTRA2) != 0) { in ahc_validate_offset()
2413 ahc_validate_width(struct ahc_softc *ahc, struct ahc_initiator_tinfo *tinfo, in ahc_validate_width() argument
2418 if (ahc->features & AHC_WIDE) { in ahc_validate_width()
2443 ahc_update_neg_request(struct ahc_softc *ahc, struct ahc_devinfo *devinfo, in ahc_update_neg_request() argument
2457 if ((ahc->features & AHC_WIDE) != 0) in ahc_update_neg_request()
2486 ahc_set_syncrate(struct ahc_softc *ahc, struct ahc_devinfo *devinfo, in ahc_set_syncrate() argument
2506 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, devinfo->our_scsiid, in ahc_set_syncrate()
2533 if ((ahc->features & AHC_ULTRA2) != 0) { in ahc_set_syncrate()
2562 sxfrctl0 = ahc_inb(ahc, SXFRCTL0); in ahc_set_syncrate()
2566 ahc_outb(ahc, SXFRCTL0, sxfrctl0); in ahc_set_syncrate()
2570 ahc_outb(ahc, SCSIRATE, scsirate); in ahc_set_syncrate()
2571 if ((ahc->features & AHC_ULTRA2) != 0) in ahc_set_syncrate()
2572 ahc_outb(ahc, SCSIOFFSET, offset); in ahc_set_syncrate()
2580 ahc_send_async(ahc, devinfo->channel, devinfo->target, in ahc_set_syncrate()
2585 "offset = 0x%x\n", ahc_name(ahc), in ahc_set_syncrate()
2592 ahc_name(ahc), devinfo->target); in ahc_set_syncrate()
2597 update_needed += ahc_update_neg_request(ahc, devinfo, tstate, in ahc_set_syncrate()
2601 ahc_update_pending_scbs(ahc); in ahc_set_syncrate()
2613 ahc_set_width(struct ahc_softc *ahc, struct ahc_devinfo *devinfo, in ahc_set_width() argument
2624 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, devinfo->our_scsiid, in ahc_set_width()
2646 ahc_outb(ahc, SCSIRATE, scsirate); in ahc_set_width()
2650 ahc_send_async(ahc, devinfo->channel, devinfo->target, in ahc_set_width()
2654 ahc_name(ahc), devinfo->target, in ahc_set_width()
2659 update_needed += ahc_update_neg_request(ahc, devinfo, tstate, in ahc_set_width()
2662 ahc_update_pending_scbs(ahc); in ahc_set_width()
2669 ahc_set_tags(struct ahc_softc *ahc, struct scsi_cmnd *cmd, in ahc_set_tags() argument
2674 ahc_platform_set_tags(ahc, sdev, devinfo, alg); in ahc_set_tags()
2675 ahc_send_async(ahc, devinfo->channel, devinfo->target, in ahc_set_tags()
2685 ahc_update_pending_scbs(struct ahc_softc *ahc) in ahc_update_pending_scbs() argument
2698 LIST_FOREACH(pending_scb, &ahc->pending_scbs, pending_links) { in ahc_update_pending_scbs()
2704 ahc_scb_devinfo(ahc, &devinfo, pending_scb); in ahc_update_pending_scbs()
2705 tinfo = ahc_fetch_transinfo(ahc, devinfo.channel, in ahc_update_pending_scbs()
2719 ahc_sync_scb(ahc, pending_scb, in ahc_update_pending_scbs()
2727 if (ahc_is_paused(ahc)) { in ahc_update_pending_scbs()
2731 ahc_pause(ahc); in ahc_update_pending_scbs()
2734 saved_scbptr = ahc_inb(ahc, SCBPTR); in ahc_update_pending_scbs()
2736 for (i = 0; i < ahc->scb_data->maxhscbs; i++) { in ahc_update_pending_scbs()
2741 ahc_outb(ahc, SCBPTR, i); in ahc_update_pending_scbs()
2742 scb_tag = ahc_inb(ahc, SCB_TAG); in ahc_update_pending_scbs()
2743 pending_scb = ahc_lookup_scb(ahc, scb_tag); in ahc_update_pending_scbs()
2748 control = ahc_inb(ahc, SCB_CONTROL); in ahc_update_pending_scbs()
2751 ahc_outb(ahc, SCB_CONTROL, control); in ahc_update_pending_scbs()
2752 ahc_outb(ahc, SCB_SCSIRATE, pending_hscb->scsirate); in ahc_update_pending_scbs()
2753 ahc_outb(ahc, SCB_SCSIOFFSET, pending_hscb->scsioffset); in ahc_update_pending_scbs()
2755 ahc_outb(ahc, SCBPTR, saved_scbptr); in ahc_update_pending_scbs()
2758 ahc_unpause(ahc); in ahc_update_pending_scbs()
2763 ahc_fetch_devinfo(struct ahc_softc *ahc, struct ahc_devinfo *devinfo) in ahc_fetch_devinfo() argument
2769 if (ahc_inb(ahc, SSTAT0) & TARGET) in ahc_fetch_devinfo()
2775 && (ahc->features & AHC_MULTI_TID) != 0 in ahc_fetch_devinfo()
2776 && (ahc_inb(ahc, SEQ_FLAGS) in ahc_fetch_devinfo()
2779 our_id = ahc_inb(ahc, TARGIDIN) & OID; in ahc_fetch_devinfo()
2780 } else if ((ahc->features & AHC_ULTRA2) != 0) in ahc_fetch_devinfo()
2781 our_id = ahc_inb(ahc, SCSIID_ULTRA2) & OID; in ahc_fetch_devinfo()
2783 our_id = ahc_inb(ahc, SCSIID) & OID; in ahc_fetch_devinfo()
2785 saved_scsiid = ahc_inb(ahc, SAVED_SCSIID); in ahc_fetch_devinfo()
2788 SCSIID_TARGET(ahc, saved_scsiid), in ahc_fetch_devinfo()
2789 ahc_inb(ahc, SAVED_LUN), in ahc_fetch_devinfo()
2790 SCSIID_CHANNEL(ahc, saved_scsiid), in ahc_fetch_devinfo()
2828 ahc_print_devinfo(struct ahc_softc *ahc, struct ahc_devinfo *devinfo) in ahc_print_devinfo() argument
2830 printk("%s:%c:%d:%d: ", ahc_name(ahc), devinfo->channel, in ahc_print_devinfo()
2835 ahc_scb_devinfo(struct ahc_softc *ahc, struct ahc_devinfo *devinfo, in ahc_scb_devinfo() argument
2845 ahc_compile_devinfo(devinfo, our_id, SCB_GET_TARGET(ahc, scb), in ahc_scb_devinfo()
2846 SCB_GET_LUN(scb), SCB_GET_CHANNEL(ahc, scb), role); in ahc_scb_devinfo()
2852 ahc_assert_atn(struct ahc_softc *ahc) in ahc_assert_atn() argument
2857 if ((ahc->features & AHC_DT) == 0) in ahc_assert_atn()
2858 scsisigo |= ahc_inb(ahc, SCSISIGI); in ahc_assert_atn()
2859 ahc_outb(ahc, SCSISIGO, scsisigo); in ahc_assert_atn()
2869 ahc_setup_initiator_msgout(struct ahc_softc *ahc, struct ahc_devinfo *devinfo, in ahc_setup_initiator_msgout() argument
2877 ahc->msgout_index = 0; in ahc_setup_initiator_msgout()
2878 ahc->msgout_len = 0; in ahc_setup_initiator_msgout()
2881 && ahc_inb(ahc, MSG_OUT) == MSG_IDENTIFYFLAG) { in ahc_setup_initiator_msgout()
2887 ahc->msgout_buf[ahc->msgout_index++] = identify_msg; in ahc_setup_initiator_msgout()
2888 ahc->msgout_len++; in ahc_setup_initiator_msgout()
2891 ahc->msgout_buf[ahc->msgout_index++] = in ahc_setup_initiator_msgout()
2893 ahc->msgout_buf[ahc->msgout_index++] = scb->hscb->tag; in ahc_setup_initiator_msgout()
2894 ahc->msgout_len += 2; in ahc_setup_initiator_msgout()
2899 ahc->msgout_buf[ahc->msgout_index++] = MSG_BUS_DEV_RESET; in ahc_setup_initiator_msgout()
2900 ahc->msgout_len++; in ahc_setup_initiator_msgout()
2901 ahc_print_path(ahc, scb); in ahc_setup_initiator_msgout()
2910 ahc_outb(ahc, SCSISEQ, (ahc_inb(ahc, SCSISEQ) & ~ENSELO)); in ahc_setup_initiator_msgout()
2913 ahc->msgout_buf[ahc->msgout_index++] = MSG_ABORT_TAG; in ahc_setup_initiator_msgout()
2915 ahc->msgout_buf[ahc->msgout_index++] = MSG_ABORT; in ahc_setup_initiator_msgout()
2916 ahc->msgout_len++; in ahc_setup_initiator_msgout()
2917 ahc_print_path(ahc, scb); in ahc_setup_initiator_msgout()
2927 ahc_outb(ahc, SCSISEQ, (ahc_inb(ahc, SCSISEQ) & ~ENSELO)); in ahc_setup_initiator_msgout()
2929 ahc_build_transfer_msg(ahc, devinfo); in ahc_setup_initiator_msgout()
2937 ahc_inb(ahc, MSG_OUT), scb->flags); in ahc_setup_initiator_msgout()
2944 ahc_outb(ahc, SCB_CONTROL, ahc_inb(ahc, SCB_CONTROL) & ~MK_MESSAGE); in ahc_setup_initiator_msgout()
2946 ahc->msgout_index = 0; in ahc_setup_initiator_msgout()
2947 ahc->msg_type = MSG_TYPE_INITIATOR_MSGOUT; in ahc_setup_initiator_msgout()
2955 ahc_build_transfer_msg(struct ahc_softc *ahc, struct ahc_devinfo *devinfo) in ahc_build_transfer_msg() argument
2972 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, devinfo->our_scsiid, in ahc_build_transfer_msg()
2986 rate = ahc_devlimited_syncrate(ahc, tinfo, &period, in ahc_build_transfer_msg()
3007 if ((ahc->features & AHC_WIDE) != 0) in ahc_build_transfer_msg()
3013 ahc_print_devinfo(ahc, devinfo); in ahc_build_transfer_msg()
3033 ahc_validate_offset(ahc, tinfo, rate, &offset, in ahc_build_transfer_msg()
3038 ahc_construct_ppr(ahc, devinfo, period, offset, in ahc_build_transfer_msg()
3041 ahc_construct_sdtr(ahc, devinfo, period, offset); in ahc_build_transfer_msg()
3044 ahc_construct_wdtr(ahc, devinfo, tinfo->goal.width); in ahc_build_transfer_msg()
3053 ahc_construct_sdtr(struct ahc_softc *ahc, struct ahc_devinfo *devinfo, in ahc_construct_sdtr() argument
3058 ahc->msgout_index += spi_populate_sync_msg( in ahc_construct_sdtr()
3059 ahc->msgout_buf + ahc->msgout_index, period, offset); in ahc_construct_sdtr()
3060 ahc->msgout_len += 5; in ahc_construct_sdtr()
3063 ahc_name(ahc), devinfo->channel, devinfo->target, in ahc_construct_sdtr()
3073 ahc_construct_wdtr(struct ahc_softc *ahc, struct ahc_devinfo *devinfo, in ahc_construct_wdtr() argument
3076 ahc->msgout_index += spi_populate_width_msg( in ahc_construct_wdtr()
3077 ahc->msgout_buf + ahc->msgout_index, bus_width); in ahc_construct_wdtr()
3078 ahc->msgout_len += 4; in ahc_construct_wdtr()
3081 ahc_name(ahc), devinfo->channel, devinfo->target, in ahc_construct_wdtr()
3091 ahc_construct_ppr(struct ahc_softc *ahc, struct ahc_devinfo *devinfo, in ahc_construct_ppr() argument
3097 ahc->msgout_index += spi_populate_ppr_msg( in ahc_construct_ppr()
3098 ahc->msgout_buf + ahc->msgout_index, period, offset, in ahc_construct_ppr()
3100 ahc->msgout_len += 8; in ahc_construct_ppr()
3103 "offset %x, ppr_options %x\n", ahc_name(ahc), in ahc_construct_ppr()
3113 ahc_clear_msg_state(struct ahc_softc *ahc) in ahc_clear_msg_state() argument
3115 ahc->msgout_len = 0; in ahc_clear_msg_state()
3116 ahc->msgin_index = 0; in ahc_clear_msg_state()
3117 ahc->msg_type = MSG_TYPE_NONE; in ahc_clear_msg_state()
3118 if ((ahc_inb(ahc, SCSISIGI) & ATNI) != 0) { in ahc_clear_msg_state()
3123 ahc_outb(ahc, CLRSINT1, CLRATNO); in ahc_clear_msg_state()
3125 ahc_outb(ahc, MSG_OUT, MSG_NOOP); in ahc_clear_msg_state()
3126 ahc_outb(ahc, SEQ_FLAGS2, in ahc_clear_msg_state()
3127 ahc_inb(ahc, SEQ_FLAGS2) & ~TARGET_MSG_PENDING); in ahc_clear_msg_state()
3131 ahc_handle_proto_violation(struct ahc_softc *ahc) in ahc_handle_proto_violation() argument
3141 ahc_fetch_devinfo(ahc, &devinfo); in ahc_handle_proto_violation()
3142 scbid = ahc_inb(ahc, SCB_TAG); in ahc_handle_proto_violation()
3143 scb = ahc_lookup_scb(ahc, scbid); in ahc_handle_proto_violation()
3144 seq_flags = ahc_inb(ahc, SEQ_FLAGS); in ahc_handle_proto_violation()
3145 curphase = ahc_inb(ahc, SCSISIGI) & PHASE_MASK; in ahc_handle_proto_violation()
3146 lastphase = ahc_inb(ahc, LASTPHASE); in ahc_handle_proto_violation()
3154 ahc_print_devinfo(ahc, &devinfo); in ahc_handle_proto_violation()
3163 ahc_print_devinfo(ahc, &devinfo); in ahc_handle_proto_violation()
3169 ahc_print_path(ahc, scb); in ahc_handle_proto_violation()
3171 } else if ((ahc_inb(ahc, SCB_CONTROL) & STATUS_RCVD) == 0) { in ahc_handle_proto_violation()
3179 ahc_print_path(ahc, scb); in ahc_handle_proto_violation()
3182 ahc_print_path(ahc, scb); in ahc_handle_proto_violation()
3184 ahc_dump_card_state(ahc); in ahc_handle_proto_violation()
3196 found = ahc_reset_channel(ahc, 'A', TRUE); in ahc_handle_proto_violation()
3198 "%d SCBs aborted\n", ahc_name(ahc), 'A', found); in ahc_handle_proto_violation()
3205 ahc_outb(ahc, SCSISEQ, in ahc_handle_proto_violation()
3206 ahc_inb(ahc, SCSISEQ) & ~ENSELO); in ahc_handle_proto_violation()
3207 ahc_assert_atn(ahc); in ahc_handle_proto_violation()
3208 ahc_outb(ahc, MSG_OUT, HOST_MSG); in ahc_handle_proto_violation()
3210 ahc_print_devinfo(ahc, &devinfo); in ahc_handle_proto_violation()
3211 ahc->msgout_buf[0] = MSG_ABORT_TASK; in ahc_handle_proto_violation()
3212 ahc->msgout_len = 1; in ahc_handle_proto_violation()
3213 ahc->msgout_index = 0; in ahc_handle_proto_violation()
3214 ahc->msg_type = MSG_TYPE_INITIATOR_MSGOUT; in ahc_handle_proto_violation()
3216 ahc_print_path(ahc, scb); in ahc_handle_proto_violation()
3228 ahc_handle_message_phase(struct ahc_softc *ahc) in ahc_handle_message_phase() argument
3234 ahc_fetch_devinfo(ahc, &devinfo); in ahc_handle_message_phase()
3236 bus_phase = ahc_inb(ahc, SCSISIGI) & PHASE_MASK; in ahc_handle_message_phase()
3239 switch (ahc->msg_type) { in ahc_handle_message_phase()
3246 if (ahc->msgout_len == 0) in ahc_handle_message_phase()
3251 ahc_print_devinfo(ahc, &devinfo); in ahc_handle_message_phase()
3271 ahc_outb(ahc, CLRSINT1, CLRATNO); in ahc_handle_message_phase()
3272 ahc->send_msg_perror = FALSE; in ahc_handle_message_phase()
3273 ahc->msg_type = MSG_TYPE_INITIATOR_MSGIN; in ahc_handle_message_phase()
3274 ahc->msgin_index = 0; in ahc_handle_message_phase()
3281 if (ahc->send_msg_perror) { in ahc_handle_message_phase()
3282 ahc_outb(ahc, CLRSINT1, CLRATNO); in ahc_handle_message_phase()
3283 ahc_outb(ahc, CLRSINT1, CLRREQINIT); in ahc_handle_message_phase()
3286 printk(" byte 0x%x\n", ahc->send_msg_perror); in ahc_handle_message_phase()
3288 ahc_outb(ahc, SCSIDATL, MSG_PARITY_ERROR); in ahc_handle_message_phase()
3292 msgdone = ahc->msgout_index == ahc->msgout_len; in ahc_handle_message_phase()
3299 ahc->msgout_index = 0; in ahc_handle_message_phase()
3300 ahc_assert_atn(ahc); in ahc_handle_message_phase()
3303 lastbyte = ahc->msgout_index == (ahc->msgout_len - 1); in ahc_handle_message_phase()
3306 ahc_outb(ahc, CLRSINT1, CLRATNO); in ahc_handle_message_phase()
3313 ahc_outb(ahc, CLRSINT1, CLRREQINIT); in ahc_handle_message_phase()
3317 ahc->msgout_buf[ahc->msgout_index]); in ahc_handle_message_phase()
3319 ahc_outb(ahc, SCSIDATL, ahc->msgout_buf[ahc->msgout_index++]); in ahc_handle_message_phase()
3329 ahc_print_devinfo(ahc, &devinfo); in ahc_handle_message_phase()
3342 ahc->msgin_index = 0; in ahc_handle_message_phase()
3344 && (ahc->send_msg_perror == TRUE in ahc_handle_message_phase()
3345 || (ahc->msgout_len != 0 in ahc_handle_message_phase()
3346 && ahc->msgout_index == 0))) { in ahc_handle_message_phase()
3347 ahc->msg_type = MSG_TYPE_INITIATOR_MSGOUT; in ahc_handle_message_phase()
3355 ahc->msgin_buf[ahc->msgin_index] = ahc_inb(ahc, SCSIBUSL); in ahc_handle_message_phase()
3359 ahc->msgin_buf[ahc->msgin_index]); in ahc_handle_message_phase()
3362 message_done = ahc_parse_msg(ahc, &devinfo); in ahc_handle_message_phase()
3369 ahc->msgin_index = 0; in ahc_handle_message_phase()
3376 if (ahc->msgout_len != 0) { in ahc_handle_message_phase()
3379 ahc_print_devinfo(ahc, &devinfo); in ahc_handle_message_phase()
3383 ahc_assert_atn(ahc); in ahc_handle_message_phase()
3386 ahc->msgin_index++; in ahc_handle_message_phase()
3392 ahc_outb(ahc, CLRSINT1, CLRREQINIT); in ahc_handle_message_phase()
3393 ahc_inb(ahc, SCSIDATL); in ahc_handle_message_phase()
3402 if (ahc->msgout_len == 0) in ahc_handle_message_phase()
3411 if ((ahc_inb(ahc, SCSISIGI) & ATNI) != 0 in ahc_handle_message_phase()
3412 && ahc->msgout_index > 0) in ahc_handle_message_phase()
3425 ahc->msg_type = MSG_TYPE_TARGET_MSGOUT; in ahc_handle_message_phase()
3426 ahc_outb(ahc, SCSISIGO, P_MESGOUT | BSYO); in ahc_handle_message_phase()
3427 ahc->msgin_index = 0; in ahc_handle_message_phase()
3429 ahc_inb(ahc, SCSIDATL); in ahc_handle_message_phase()
3430 ahc_outb(ahc, SXFRCTL0, in ahc_handle_message_phase()
3431 ahc_inb(ahc, SXFRCTL0) | SPIOEN); in ahc_handle_message_phase()
3435 msgdone = ahc->msgout_index == ahc->msgout_len; 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()
3446 ahc_outb(ahc, SXFRCTL0, ahc_inb(ahc, SXFRCTL0) | SPIOEN); in ahc_handle_message_phase()
3447 ahc_outb(ahc, SCSIDATL, ahc->msgout_buf[ahc->msgout_index++]); in ahc_handle_message_phase()
3459 lastbyte = (ahc_inb(ahc, SCSISIGI) & ATNI) == 0; in ahc_handle_message_phase()
3466 ahc_outb(ahc, SXFRCTL0, ahc_inb(ahc, SXFRCTL0) & ~SPIOEN); in ahc_handle_message_phase()
3467 ahc->msgin_buf[ahc->msgin_index] = ahc_inb(ahc, SCSIDATL); in ahc_handle_message_phase()
3468 msgdone = ahc_parse_msg(ahc, &devinfo); in ahc_handle_message_phase()
3479 ahc->msgin_index++; in ahc_handle_message_phase()
3486 ahc->msgin_index = 0; in ahc_handle_message_phase()
3492 if (ahc->msgout_len != 0) { in ahc_handle_message_phase()
3493 ahc_outb(ahc, SCSISIGO, P_MESGIN | BSYO); in ahc_handle_message_phase()
3494 ahc_outb(ahc, SXFRCTL0, in ahc_handle_message_phase()
3495 ahc_inb(ahc, SXFRCTL0) | SPIOEN); in ahc_handle_message_phase()
3496 ahc->msg_type = MSG_TYPE_TARGET_MSGIN; in ahc_handle_message_phase()
3497 ahc->msgin_index = 0; in ahc_handle_message_phase()
3506 ahc_outb(ahc, SXFRCTL0, in ahc_handle_message_phase()
3507 ahc_inb(ahc, SXFRCTL0) | SPIOEN); in ahc_handle_message_phase()
3517 ahc_clear_msg_state(ahc); in ahc_handle_message_phase()
3518 ahc_outb(ahc, RETURN_1, EXIT_MSG_LOOP); in ahc_handle_message_phase()
3520 ahc_outb(ahc, RETURN_1, CONT_MSG_LOOP); in ahc_handle_message_phase()
3530 ahc_sent_msg(struct ahc_softc *ahc, ahc_msgtype type, u_int msgval, int full) in ahc_sent_msg() argument
3538 while (index < ahc->msgout_len) { in ahc_sent_msg()
3539 if (ahc->msgout_buf[index] == MSG_EXTENDED) { in ahc_sent_msg()
3542 end_index = index + 1 + ahc->msgout_buf[index + 1]; in ahc_sent_msg()
3543 if (ahc->msgout_buf[index+2] == msgval in ahc_sent_msg()
3547 if (ahc->msgout_index > end_index) in ahc_sent_msg()
3549 } else if (ahc->msgout_index > index) in ahc_sent_msg()
3553 } else if (ahc->msgout_buf[index] >= MSG_SIMPLE_TASK in ahc_sent_msg()
3554 && ahc->msgout_buf[index] <= MSG_IGN_WIDE_RESIDUE) { in ahc_sent_msg()
3561 && ahc->msgout_buf[index] == msgval in ahc_sent_msg()
3562 && ahc->msgout_index > index) in ahc_sent_msg()
3577 ahc_parse_msg(struct ahc_softc *ahc, struct ahc_devinfo *devinfo) in ahc_parse_msg() argument
3589 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, devinfo->our_scsiid, in ahc_parse_msg()
3604 switch (ahc->msgin_buf[0]) { in ahc_parse_msg()
3617 response = ahc_handle_msg_reject(ahc, devinfo); in ahc_parse_msg()
3625 if (ahc->msgin_index < 2) in ahc_parse_msg()
3627 switch (ahc->msgin_buf[2]) { in ahc_parse_msg()
3636 if (ahc->msgin_buf[1] != MSG_EXT_SDTR_LEN) { in ahc_parse_msg()
3648 if (ahc->msgin_index < (MSG_EXT_SDTR_LEN + 1)) in ahc_parse_msg()
3651 period = ahc->msgin_buf[3]; in ahc_parse_msg()
3653 saved_offset = offset = ahc->msgin_buf[4]; in ahc_parse_msg()
3654 syncrate = ahc_devlimited_syncrate(ahc, tinfo, &period, in ahc_parse_msg()
3657 ahc_validate_offset(ahc, tinfo, syncrate, &offset, in ahc_parse_msg()
3664 ahc_name(ahc), devinfo->channel, in ahc_parse_msg()
3666 ahc->msgin_buf[3], saved_offset, in ahc_parse_msg()
3669 ahc_set_syncrate(ahc, devinfo, in ahc_parse_msg()
3680 if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_SDTR, TRUE)) { in ahc_parse_msg()
3694 ahc_name(ahc), devinfo->channel, in ahc_parse_msg()
3697 ahc->msgout_index = 0; in ahc_parse_msg()
3698 ahc->msgout_len = 0; in ahc_parse_msg()
3699 ahc_construct_sdtr(ahc, devinfo, in ahc_parse_msg()
3701 ahc->msgout_index = 0; in ahc_parse_msg()
3714 if (ahc->msgin_buf[1] != MSG_EXT_WDTR_LEN) { in ahc_parse_msg()
3726 if (ahc->msgin_index < (MSG_EXT_WDTR_LEN + 1)) in ahc_parse_msg()
3729 bus_width = ahc->msgin_buf[3]; in ahc_parse_msg()
3731 ahc_validate_width(ahc, tinfo, &bus_width, in ahc_parse_msg()
3736 ahc_name(ahc), devinfo->channel, in ahc_parse_msg()
3741 if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_WDTR, TRUE)) { in ahc_parse_msg()
3752 ahc_name(ahc), devinfo->channel, in ahc_parse_msg()
3765 ahc_name(ahc), devinfo->channel, in ahc_parse_msg()
3768 ahc->msgout_index = 0; in ahc_parse_msg()
3769 ahc->msgout_len = 0; in ahc_parse_msg()
3770 ahc_construct_wdtr(ahc, devinfo, bus_width); in ahc_parse_msg()
3771 ahc->msgout_index = 0; in ahc_parse_msg()
3784 ahc_update_neg_request(ahc, devinfo, tstate, in ahc_parse_msg()
3786 ahc_set_width(ahc, devinfo, bus_width, in ahc_parse_msg()
3794 ahc->msgout_index = 0; in ahc_parse_msg()
3795 ahc->msgout_len = 0; in ahc_parse_msg()
3796 ahc_build_transfer_msg(ahc, devinfo); in ahc_parse_msg()
3797 ahc->msgout_index = 0; in ahc_parse_msg()
3814 if (ahc->msgin_buf[1] != MSG_EXT_PPR_LEN) { in ahc_parse_msg()
3826 if (ahc->msgin_index < (MSG_EXT_PPR_LEN + 1)) in ahc_parse_msg()
3829 period = ahc->msgin_buf[3]; in ahc_parse_msg()
3830 offset = ahc->msgin_buf[5]; in ahc_parse_msg()
3831 bus_width = ahc->msgin_buf[6]; in ahc_parse_msg()
3833 ppr_options = ahc->msgin_buf[7]; in ahc_parse_msg()
3854 ahc_validate_width(ahc, tinfo, &bus_width, in ahc_parse_msg()
3856 syncrate = ahc_devlimited_syncrate(ahc, tinfo, &period, in ahc_parse_msg()
3859 ahc_validate_offset(ahc, tinfo, syncrate, in ahc_parse_msg()
3863 if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_PPR, TRUE)) { in ahc_parse_msg()
3883 ahc_name(ahc), devinfo->channel, in ahc_parse_msg()
3888 ahc_name(ahc), devinfo->channel, in ahc_parse_msg()
3890 ahc->msgout_index = 0; in ahc_parse_msg()
3891 ahc->msgout_len = 0; in ahc_parse_msg()
3892 ahc_construct_ppr(ahc, devinfo, period, offset, in ahc_parse_msg()
3894 ahc->msgout_index = 0; in ahc_parse_msg()
3902 ahc_name(ahc), devinfo->channel, in ahc_parse_msg()
3904 saved_width, ahc->msgin_buf[3], in ahc_parse_msg()
3908 ahc_set_width(ahc, devinfo, bus_width, in ahc_parse_msg()
3911 ahc_set_syncrate(ahc, devinfo, in ahc_parse_msg()
3928 ahc_handle_devreset(ahc, devinfo, in ahc_parse_msg()
3932 ahc_restart(ahc); in ahc_parse_msg()
3947 if (ahc->msgin_buf[0] == MSG_ABORT_TAG) in ahc_parse_msg()
3948 tag = ahc_inb(ahc, INITIATOR_TAG); in ahc_parse_msg()
3949 ahc_abort_scbs(ahc, devinfo->target, devinfo->channel, in ahc_parse_msg()
3953 tstate = ahc->enabled_targets[devinfo->our_scsiid]; in ahc_parse_msg()
3959 ahc_queue_lstate_event(ahc, lstate, in ahc_parse_msg()
3961 ahc->msgin_buf[0], in ahc_parse_msg()
3963 ahc_send_lstate_events(ahc, lstate); in ahc_parse_msg()
3966 ahc_restart(ahc); in ahc_parse_msg()
3981 ahc->msgout_index = 0; in ahc_parse_msg()
3982 ahc->msgout_len = 1; in ahc_parse_msg()
3983 ahc->msgout_buf[0] = MSG_MESSAGE_REJECT; in ahc_parse_msg()
3990 ahc->msgout_len = 0; in ahc_parse_msg()
3999 ahc_handle_msg_reject(struct ahc_softc *ahc, struct ahc_devinfo *devinfo) in ahc_handle_msg_reject() argument
4014 scb_index = ahc_inb(ahc, SCB_TAG); in ahc_handle_msg_reject()
4015 scb = ahc_lookup_scb(ahc, scb_index); in ahc_handle_msg_reject()
4016 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, in ahc_handle_msg_reject()
4020 last_msg = ahc_inb(ahc, LAST_MSG); in ahc_handle_msg_reject()
4022 if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_PPR, /*full*/FALSE)) { in ahc_handle_msg_reject()
4030 ahc_name(ahc), devinfo->channel, in ahc_handle_msg_reject()
4036 ahc->msgout_index = 0; in ahc_handle_msg_reject()
4037 ahc->msgout_len = 0; in ahc_handle_msg_reject()
4038 ahc_build_transfer_msg(ahc, devinfo); in ahc_handle_msg_reject()
4039 ahc->msgout_index = 0; in ahc_handle_msg_reject()
4041 } else if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_WDTR, /*full*/FALSE)) { in ahc_handle_msg_reject()
4045 "8bit transfers\n", ahc_name(ahc), in ahc_handle_msg_reject()
4047 ahc_set_width(ahc, devinfo, MSG_EXT_WDTR_BUS_8_BIT, in ahc_handle_msg_reject()
4060 ahc->msgout_index = 0; in ahc_handle_msg_reject()
4061 ahc->msgout_len = 0; in ahc_handle_msg_reject()
4062 ahc_build_transfer_msg(ahc, devinfo); in ahc_handle_msg_reject()
4063 ahc->msgout_index = 0; in ahc_handle_msg_reject()
4066 } else if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_SDTR, /*full*/FALSE)) { in ahc_handle_msg_reject()
4068 ahc_set_syncrate(ahc, devinfo, /*syncrate*/NULL, /*period*/0, in ahc_handle_msg_reject()
4074 ahc_name(ahc), devinfo->channel, in ahc_handle_msg_reject()
4084 "Performing non-tagged I/O\n", ahc_name(ahc), in ahc_handle_msg_reject()
4086 ahc_set_tags(ahc, scb->io_ctx, devinfo, AHC_QUEUE_NONE); in ahc_handle_msg_reject()
4091 ahc_name(ahc), devinfo->channel, devinfo->target, in ahc_handle_msg_reject()
4094 ahc_set_tags(ahc, scb->io_ctx, devinfo, AHC_QUEUE_BASIC); in ahc_handle_msg_reject()
4102 ahc_outb(ahc, SCB_CONTROL, in ahc_handle_msg_reject()
4103 ahc_inb(ahc, SCB_CONTROL) & mask); in ahc_handle_msg_reject()
4107 ahc_outb(ahc, MSG_OUT, MSG_IDENTIFYFLAG); in ahc_handle_msg_reject()
4108 ahc_assert_atn(ahc); in ahc_handle_msg_reject()
4114 if ((ahc->flags & AHC_SCB_BTT) == 0) { in ahc_handle_msg_reject()
4118 &(ahc->untagged_queues[devinfo->target_offset]); in ahc_handle_msg_reject()
4122 ahc_busy_tcl(ahc, BUILD_TCL(scb->hscb->scsiid, devinfo->lun), in ahc_handle_msg_reject()
4130 ahc_search_qinfifo(ahc, SCB_GET_TARGET(ahc, scb), in ahc_handle_msg_reject()
4131 SCB_GET_CHANNEL(ahc, scb), in ahc_handle_msg_reject()
4140 ahc_name(ahc), devinfo->channel, devinfo->target, in ahc_handle_msg_reject()
4150 ahc_handle_ign_wide_residue(struct ahc_softc *ahc, struct ahc_devinfo *devinfo) in ahc_handle_ign_wide_residue() argument
4155 scb_index = ahc_inb(ahc, SCB_TAG); in ahc_handle_ign_wide_residue()
4156 scb = ahc_lookup_scb(ahc, scb_index); in ahc_handle_ign_wide_residue()
4161 if ((ahc_inb(ahc, SEQ_FLAGS) & DPHASE) == 0 in ahc_handle_ign_wide_residue()
4177 sgptr = ahc_inb(ahc, SCB_RESIDUAL_SGPTR); in ahc_handle_ign_wide_residue()
4179 && (ahc_inb(ahc, SCB_LUN) & SCB_XFERLEN_ODD) != 0) { in ahc_handle_ign_wide_residue()
4193 sgptr = ahc_inl(ahc, SCB_RESIDUAL_SGPTR); in ahc_handle_ign_wide_residue()
4194 data_cnt = ahc_inl(ahc, SCB_RESIDUAL_DATACNT); in ahc_handle_ign_wide_residue()
4205 data_addr = ahc_inl(ahc, SHADDR); in ahc_handle_ign_wide_residue()
4239 ahc_outl(ahc, SCB_RESIDUAL_SGPTR, sgptr); in ahc_handle_ign_wide_residue()
4240 ahc_outl(ahc, SCB_RESIDUAL_DATACNT, data_cnt); in ahc_handle_ign_wide_residue()
4247 ahc_outb(ahc, SCB_LUN, in ahc_handle_ign_wide_residue()
4248 ahc_inb(ahc, SCB_LUN) ^ SCB_XFERLEN_ODD); in ahc_handle_ign_wide_residue()
4259 ahc_reinitialize_dataptrs(struct ahc_softc *ahc) in ahc_reinitialize_dataptrs() argument
4268 scb_index = ahc_inb(ahc, SCB_TAG); in ahc_reinitialize_dataptrs()
4269 scb = ahc_lookup_scb(ahc, scb_index); in ahc_reinitialize_dataptrs()
4270 sgptr = (ahc_inb(ahc, SCB_RESIDUAL_SGPTR + 3) << 24) in ahc_reinitialize_dataptrs()
4271 | (ahc_inb(ahc, SCB_RESIDUAL_SGPTR + 2) << 16) in ahc_reinitialize_dataptrs()
4272 | (ahc_inb(ahc, SCB_RESIDUAL_SGPTR + 1) << 8) in ahc_reinitialize_dataptrs()
4273 | ahc_inb(ahc, SCB_RESIDUAL_SGPTR); in ahc_reinitialize_dataptrs()
4281 resid = (ahc_inb(ahc, SCB_RESIDUAL_DATACNT + 2) << 16) in ahc_reinitialize_dataptrs()
4282 | (ahc_inb(ahc, SCB_RESIDUAL_DATACNT + 1) << 8) in ahc_reinitialize_dataptrs()
4283 | ahc_inb(ahc, SCB_RESIDUAL_DATACNT); in ahc_reinitialize_dataptrs()
4288 if ((ahc->flags & AHC_39BIT_ADDRESSING) != 0) { in ahc_reinitialize_dataptrs()
4291 dscommand1 = ahc_inb(ahc, DSCOMMAND1); in ahc_reinitialize_dataptrs()
4292 ahc_outb(ahc, DSCOMMAND1, dscommand1 | HADDLDSEL0); in ahc_reinitialize_dataptrs()
4293 ahc_outb(ahc, HADDR, in ahc_reinitialize_dataptrs()
4295 ahc_outb(ahc, DSCOMMAND1, dscommand1); in ahc_reinitialize_dataptrs()
4297 ahc_outb(ahc, HADDR + 3, dataptr >> 24); in ahc_reinitialize_dataptrs()
4298 ahc_outb(ahc, HADDR + 2, dataptr >> 16); in ahc_reinitialize_dataptrs()
4299 ahc_outb(ahc, HADDR + 1, dataptr >> 8); in ahc_reinitialize_dataptrs()
4300 ahc_outb(ahc, HADDR, dataptr); in ahc_reinitialize_dataptrs()
4301 ahc_outb(ahc, HCNT + 2, resid >> 16); in ahc_reinitialize_dataptrs()
4302 ahc_outb(ahc, HCNT + 1, resid >> 8); in ahc_reinitialize_dataptrs()
4303 ahc_outb(ahc, HCNT, resid); in ahc_reinitialize_dataptrs()
4304 if ((ahc->features & AHC_ULTRA2) == 0) { in ahc_reinitialize_dataptrs()
4305 ahc_outb(ahc, STCNT + 2, resid >> 16); in ahc_reinitialize_dataptrs()
4306 ahc_outb(ahc, STCNT + 1, resid >> 8); in ahc_reinitialize_dataptrs()
4307 ahc_outb(ahc, STCNT, resid); in ahc_reinitialize_dataptrs()
4315 ahc_handle_devreset(struct ahc_softc *ahc, struct ahc_devinfo *devinfo, in ahc_handle_devreset() argument
4324 found = ahc_abort_scbs(ahc, devinfo->target, devinfo->channel, in ahc_handle_devreset()
4333 tstate = ahc->enabled_targets[devinfo->our_scsiid]; in ahc_handle_devreset()
4342 ahc_queue_lstate_event(ahc, lstate, devinfo->our_scsiid, in ahc_handle_devreset()
4344 ahc_send_lstate_events(ahc, lstate); in ahc_handle_devreset()
4352 ahc_set_width(ahc, devinfo, MSG_EXT_WDTR_BUS_8_BIT, in ahc_handle_devreset()
4354 ahc_set_syncrate(ahc, devinfo, /*syncrate*/NULL, in ahc_handle_devreset()
4359 ahc_send_async(ahc, devinfo->channel, devinfo->target, in ahc_handle_devreset()
4364 printk("%s: %s on %c:%d. %d SCBs aborted\n", ahc_name(ahc), in ahc_handle_devreset()
4370 ahc_setup_target_msgin(struct ahc_softc *ahc, struct ahc_devinfo *devinfo, in ahc_setup_target_msgin() argument
4379 ahc->msgout_index = 0; in ahc_setup_target_msgin()
4380 ahc->msgout_len = 0; in ahc_setup_target_msgin()
4383 ahc_build_transfer_msg(ahc, devinfo); in ahc_setup_target_msgin()
4387 ahc->msgout_index = 0; in ahc_setup_target_msgin()
4388 ahc->msg_type = MSG_TYPE_TARGET_MSGIN; in ahc_setup_target_msgin()
4399 struct ahc_softc *ahc; in ahc_alloc() local
4403 ahc = kmalloc(sizeof(*ahc), GFP_ATOMIC); in ahc_alloc()
4404 if (!ahc) { in ahc_alloc()
4410 ahc = device_get_softc((device_t)platform_arg); in ahc_alloc()
4412 memset(ahc, 0, sizeof(*ahc)); in ahc_alloc()
4413 ahc->seep_config = kmalloc(sizeof(*ahc->seep_config), GFP_ATOMIC); in ahc_alloc()
4414 if (ahc->seep_config == NULL) { in ahc_alloc()
4416 kfree(ahc); in ahc_alloc()
4421 LIST_INIT(&ahc->pending_scbs); in ahc_alloc()
4423 ahc->name = name; in ahc_alloc()
4424 ahc->unit = -1; in ahc_alloc()
4425 ahc->description = NULL; in ahc_alloc()
4426 ahc->channel = 'A'; in ahc_alloc()
4427 ahc->channel_b = 'B'; in ahc_alloc()
4428 ahc->chip = AHC_NONE; in ahc_alloc()
4429 ahc->features = AHC_FENONE; in ahc_alloc()
4430 ahc->bugs = AHC_BUGNONE; in ahc_alloc()
4431 ahc->flags = AHC_FNONE; in ahc_alloc()
4437 ahc->seqctl = FASTMODE; in ahc_alloc()
4440 TAILQ_INIT(&ahc->untagged_queues[i]); in ahc_alloc()
4441 if (ahc_platform_alloc(ahc, platform_arg) != 0) { in ahc_alloc()
4442 ahc_free(ahc); in ahc_alloc()
4443 ahc = NULL; in ahc_alloc()
4445 return (ahc); in ahc_alloc()
4449 ahc_softc_init(struct ahc_softc *ahc) in ahc_softc_init() argument
4453 if ((ahc->chip & AHC_PCI) == 0) in ahc_softc_init()
4454 ahc->unpause = ahc_inb(ahc, HCNTRL) & IRQMS; in ahc_softc_init()
4456 ahc->unpause = 0; in ahc_softc_init()
4457 ahc->pause = ahc->unpause | PAUSE; in ahc_softc_init()
4459 if (ahc->scb_data == NULL) { in ahc_softc_init()
4460 ahc->scb_data = kzalloc(sizeof(*ahc->scb_data), GFP_ATOMIC); in ahc_softc_init()
4461 if (ahc->scb_data == NULL) in ahc_softc_init()
4469 ahc_set_unit(struct ahc_softc *ahc, int unit) in ahc_set_unit() argument
4471 ahc->unit = unit; in ahc_set_unit()
4475 ahc_set_name(struct ahc_softc *ahc, char *name) in ahc_set_name() argument
4477 if (ahc->name != NULL) in ahc_set_name()
4478 kfree(ahc->name); in ahc_set_name()
4479 ahc->name = name; in ahc_set_name()
4483 ahc_free(struct ahc_softc *ahc) in ahc_free() argument
4487 switch (ahc->init_level) { in ahc_free()
4490 ahc_shutdown(ahc); in ahc_free()
4493 ahc_dmamap_unload(ahc, ahc->shared_data_dmat, in ahc_free()
4494 ahc->shared_data_dmamap); in ahc_free()
4497 ahc_dmamem_free(ahc, ahc->shared_data_dmat, ahc->qoutfifo, in ahc_free()
4498 ahc->shared_data_dmamap); in ahc_free()
4499 ahc_dmamap_destroy(ahc, ahc->shared_data_dmat, in ahc_free()
4500 ahc->shared_data_dmamap); in ahc_free()
4503 ahc_dma_tag_destroy(ahc, ahc->shared_data_dmat); in ahc_free()
4510 ahc_platform_free(ahc); in ahc_free()
4511 ahc_fini_scbdata(ahc); in ahc_free()
4515 tstate = ahc->enabled_targets[i]; in ahc_free()
4534 if (ahc->black_hole != NULL) { in ahc_free()
4535 xpt_free_path(ahc->black_hole->path); in ahc_free()
4536 kfree(ahc->black_hole); in ahc_free()
4539 if (ahc->name != NULL) in ahc_free()
4540 kfree(ahc->name); in ahc_free()
4541 if (ahc->seep_config != NULL) in ahc_free()
4542 kfree(ahc->seep_config); in ahc_free()
4544 kfree(ahc); in ahc_free()
4552 struct ahc_softc *ahc; in ahc_shutdown() local
4555 ahc = (struct ahc_softc *)arg; in ahc_shutdown()
4558 ahc_reset(ahc, /*reinit*/FALSE); in ahc_shutdown()
4559 ahc_outb(ahc, SCSISEQ, 0); in ahc_shutdown()
4560 ahc_outb(ahc, SXFRCTL0, 0); in ahc_shutdown()
4561 ahc_outb(ahc, DSPCISTATUS, 0); in ahc_shutdown()
4564 ahc_outb(ahc, i, 0); in ahc_shutdown()
4577 ahc_reset(struct ahc_softc *ahc, int reinit) in ahc_reset() argument
4589 ahc_pause(ahc); in ahc_reset()
4591 if ((ahc->chip & AHC_CHIPID_MASK) == AHC_AIC7770) { in ahc_reset()
4598 sblkctl = ahc_inb(ahc, SBLKCTL); in ahc_reset()
4599 ahc_outb(ahc, SBLKCTL, sblkctl | SELBUSB); in ahc_reset()
4600 sxfrctl1_b = ahc_inb(ahc, SXFRCTL1); in ahc_reset()
4601 ahc_outb(ahc, SBLKCTL, sblkctl & ~SELBUSB); in ahc_reset()
4603 sxfrctl1_a = ahc_inb(ahc, SXFRCTL1); in ahc_reset()
4605 ahc_outb(ahc, HCNTRL, CHIPRST | ahc->pause); in ahc_reset()
4616 } while (--wait && !(ahc_inb(ahc, HCNTRL) & CHIPRSTACK)); in ahc_reset()
4620 "Trying to initialize anyway.\n", ahc_name(ahc)); in ahc_reset()
4622 ahc_outb(ahc, HCNTRL, ahc->pause); in ahc_reset()
4625 sblkctl = ahc_inb(ahc, SBLKCTL) & (SELBUSB|SELWIDE); in ahc_reset()
4627 if ((ahc->chip & AHC_PCI) != 0) in ahc_reset()
4635 ahc->features |= AHC_WIDE; in ahc_reset()
4639 ahc->features |= AHC_TWIN; in ahc_reset()
4654 if ((ahc->features & AHC_TWIN) != 0) { in ahc_reset()
4657 sblkctl = ahc_inb(ahc, SBLKCTL); in ahc_reset()
4658 ahc_outb(ahc, SBLKCTL, sblkctl | SELBUSB); in ahc_reset()
4659 ahc_outb(ahc, SXFRCTL1, sxfrctl1_b); in ahc_reset()
4660 ahc_outb(ahc, SBLKCTL, sblkctl & ~SELBUSB); in ahc_reset()
4662 ahc_outb(ahc, SXFRCTL1, sxfrctl1_a); in ahc_reset()
4670 error = ahc->bus_chip_init(ahc); in ahc_reset()
4673 ahc_dumpseq(ahc); in ahc_reset()
4683 ahc_probe_scbs(struct ahc_softc *ahc) { in ahc_probe_scbs() argument
4688 ahc_outb(ahc, SCBPTR, i); in ahc_probe_scbs()
4689 ahc_outb(ahc, SCB_BASE, i); in ahc_probe_scbs()
4690 if (ahc_inb(ahc, SCB_BASE) != i) in ahc_probe_scbs()
4692 ahc_outb(ahc, SCBPTR, 0); in ahc_probe_scbs()
4693 if (ahc_inb(ahc, SCB_BASE) != 0) in ahc_probe_scbs()
4709 ahc_build_free_scb_list(struct ahc_softc *ahc) in ahc_build_free_scb_list() argument
4715 if ((ahc->flags & AHC_LSCBS_ENABLED) != 0) in ahc_build_free_scb_list()
4718 for (i = 0; i < ahc->scb_data->maxhscbs; i++) { in ahc_build_free_scb_list()
4721 ahc_outb(ahc, SCBPTR, i); in ahc_build_free_scb_list()
4729 ahc_outb(ahc, SCB_BASE+j, 0xFF); in ahc_build_free_scb_list()
4732 ahc_outb(ahc, SCB_CONTROL, 0); in ahc_build_free_scb_list()
4735 if ((ahc->flags & AHC_PAGESCBS) != 0) in ahc_build_free_scb_list()
4736 ahc_outb(ahc, SCB_NEXT, i+1); in ahc_build_free_scb_list()
4738 ahc_outb(ahc, SCB_NEXT, SCB_LIST_NULL); in ahc_build_free_scb_list()
4741 ahc_outb(ahc, SCB_TAG, SCB_LIST_NULL); in ahc_build_free_scb_list()
4742 ahc_outb(ahc, SCB_SCSIID, 0xFF); in ahc_build_free_scb_list()
4743 ahc_outb(ahc, SCB_LUN, 0xFF); in ahc_build_free_scb_list()
4746 if ((ahc->flags & AHC_PAGESCBS) != 0) { in ahc_build_free_scb_list()
4748 ahc_outb(ahc, FREE_SCBH, 0); in ahc_build_free_scb_list()
4751 ahc_outb(ahc, FREE_SCBH, SCB_LIST_NULL); in ahc_build_free_scb_list()
4755 ahc_outb(ahc, SCBPTR, i-1); in ahc_build_free_scb_list()
4756 ahc_outb(ahc, SCB_NEXT, SCB_LIST_NULL); in ahc_build_free_scb_list()
4760 ahc_init_scbdata(struct ahc_softc *ahc) in ahc_init_scbdata() argument
4764 scb_data = ahc->scb_data; in ahc_init_scbdata()
4776 scb_data->maxhscbs = ahc_probe_scbs(ahc); in ahc_init_scbdata()
4777 if (ahc->scb_data->maxhscbs == 0) { in ahc_init_scbdata()
4778 printk("%s: No SCB space found\n", ahc_name(ahc)); in ahc_init_scbdata()
4793 if (ahc_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/1, in ahc_init_scbdata()
4808 if (ahc_dmamem_alloc(ahc, scb_data->hscb_dmat, in ahc_init_scbdata()
4817 ahc_dmamap_load(ahc, scb_data->hscb_dmat, scb_data->hscb_dmamap, in ahc_init_scbdata()
4825 if (ahc_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/1, in ahc_init_scbdata()
4840 if (ahc_dmamem_alloc(ahc, scb_data->sense_dmat, in ahc_init_scbdata()
4849 ahc_dmamap_load(ahc, scb_data->sense_dmat, scb_data->sense_dmamap, in ahc_init_scbdata()
4857 if (ahc_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/8, in ahc_init_scbdata()
4873 ahc_alloc_scbs(ahc); in ahc_init_scbdata()
4878 ahc_name(ahc)); in ahc_init_scbdata()
4885 ahc->next_queued_scb = ahc_get_scb(ahc); in ahc_init_scbdata()
4898 ahc_fini_scbdata(struct ahc_softc *ahc) in ahc_fini_scbdata() argument
4902 scb_data = ahc->scb_data; in ahc_fini_scbdata()
4914 ahc_dmamap_unload(ahc, scb_data->sg_dmat, in ahc_fini_scbdata()
4916 ahc_dmamem_free(ahc, scb_data->sg_dmat, in ahc_fini_scbdata()
4921 ahc_dma_tag_destroy(ahc, scb_data->sg_dmat); in ahc_fini_scbdata()
4925 ahc_dmamap_unload(ahc, scb_data->sense_dmat, in ahc_fini_scbdata()
4929 ahc_dmamem_free(ahc, scb_data->sense_dmat, scb_data->sense, in ahc_fini_scbdata()
4931 ahc_dmamap_destroy(ahc, scb_data->sense_dmat, in ahc_fini_scbdata()
4935 ahc_dma_tag_destroy(ahc, scb_data->sense_dmat); in ahc_fini_scbdata()
4938 ahc_dmamap_unload(ahc, scb_data->hscb_dmat, in ahc_fini_scbdata()
4942 ahc_dmamem_free(ahc, scb_data->hscb_dmat, scb_data->hscbs, in ahc_fini_scbdata()
4944 ahc_dmamap_destroy(ahc, scb_data->hscb_dmat, in ahc_fini_scbdata()
4948 ahc_dma_tag_destroy(ahc, scb_data->hscb_dmat); in ahc_fini_scbdata()
4958 ahc_alloc_scbs(struct ahc_softc *ahc) in ahc_alloc_scbs() argument
4968 scb_data = ahc->scb_data; in ahc_alloc_scbs()
4981 if (ahc_dmamem_alloc(ahc, scb_data->sg_dmat, in ahc_alloc_scbs()
4990 ahc_dmamap_load(ahc, scb_data->sg_dmat, sg_map->sg_dmamap, in ahc_alloc_scbs()
5013 next_scb->ahc_softc = ahc; in ahc_alloc_scbs()
5016 next_scb->hscb->tag = ahc->scb_data->numscbs; in ahc_alloc_scbs()
5017 SLIST_INSERT_HEAD(&ahc->scb_data->free_scbs, in ahc_alloc_scbs()
5022 ahc->scb_data->numscbs++; in ahc_alloc_scbs()
5027 ahc_controller_info(struct ahc_softc *ahc, char *buf) in ahc_controller_info() argument
5031 len = sprintf(buf, "%s: ", ahc_chip_names[ahc->chip & AHC_CHIPID_MASK]); in ahc_controller_info()
5033 if ((ahc->features & AHC_TWIN) != 0) in ahc_controller_info()
5036 ahc->our_id, ahc->our_id_b, in ahc_controller_info()
5037 (ahc->flags & AHC_PRIMARY_CHANNEL) + 'A'); in ahc_controller_info()
5043 if ((ahc->features & AHC_ULTRA) != 0) { in ahc_controller_info()
5045 } else if ((ahc->features & AHC_DT) != 0) { in ahc_controller_info()
5047 } else if ((ahc->features & AHC_ULTRA2) != 0) { in ahc_controller_info()
5050 if ((ahc->features & AHC_WIDE) != 0) { in ahc_controller_info()
5056 speed, type, ahc->channel, ahc->our_id); in ahc_controller_info()
5060 if ((ahc->flags & AHC_PAGESCBS) != 0) in ahc_controller_info()
5062 ahc->scb_data->maxhscbs, AHC_MAX_QUEUE); in ahc_controller_info()
5064 sprintf(buf, "%d SCBs", ahc->scb_data->maxhscbs); in ahc_controller_info()
5068 ahc_chip_init(struct ahc_softc *ahc) in ahc_chip_init() argument
5077 ahc_outb(ahc, SEQ_FLAGS, 0); in ahc_chip_init()
5078 ahc_outb(ahc, SEQ_FLAGS2, 0); in ahc_chip_init()
5081 if (ahc->features & AHC_TWIN) { in ahc_chip_init()
5086 ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) | SELBUSB); in ahc_chip_init()
5087 term = (ahc->flags & AHC_TERM_ENB_B) != 0 ? STPWEN : 0; in ahc_chip_init()
5088 ahc_outb(ahc, SCSIID, ahc->our_id_b); in ahc_chip_init()
5089 scsi_conf = ahc_inb(ahc, SCSICONF + 1); in ahc_chip_init()
5090 ahc_outb(ahc, SXFRCTL1, (scsi_conf & (ENSPCHK|STIMESEL)) in ahc_chip_init()
5091 |term|ahc->seltime_b|ENSTIMER|ACTNEGEN); in ahc_chip_init()
5092 if ((ahc->features & AHC_ULTRA2) != 0) in ahc_chip_init()
5093 ahc_outb(ahc, SIMODE0, ahc_inb(ahc, SIMODE0)|ENIOERR); in ahc_chip_init()
5094 ahc_outb(ahc, SIMODE1, ENSELTIMO|ENSCSIRST|ENSCSIPERR); in ahc_chip_init()
5095 ahc_outb(ahc, SXFRCTL0, DFON|SPIOEN); in ahc_chip_init()
5098 ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) & ~SELBUSB); in ahc_chip_init()
5100 term = (ahc->flags & AHC_TERM_ENB_A) != 0 ? STPWEN : 0; in ahc_chip_init()
5101 if ((ahc->features & AHC_ULTRA2) != 0) in ahc_chip_init()
5102 ahc_outb(ahc, SCSIID_ULTRA2, ahc->our_id); in ahc_chip_init()
5104 ahc_outb(ahc, SCSIID, ahc->our_id); in ahc_chip_init()
5105 scsi_conf = ahc_inb(ahc, SCSICONF); in ahc_chip_init()
5106 ahc_outb(ahc, SXFRCTL1, (scsi_conf & (ENSPCHK|STIMESEL)) in ahc_chip_init()
5107 |term|ahc->seltime in ahc_chip_init()
5109 if ((ahc->features & AHC_ULTRA2) != 0) in ahc_chip_init()
5110 ahc_outb(ahc, SIMODE0, ahc_inb(ahc, SIMODE0)|ENIOERR); in ahc_chip_init()
5111 ahc_outb(ahc, SIMODE1, ENSELTIMO|ENSCSIRST|ENSCSIPERR); in ahc_chip_init()
5112 ahc_outb(ahc, SXFRCTL0, DFON|SPIOEN); in ahc_chip_init()
5116 ahc_unbusy_tcl(ahc, BUILD_TCL(i << 4, 0)); in ahc_chip_init()
5117 if ((ahc->flags & AHC_SCB_BTT) != 0) { in ahc_chip_init()
5125 ahc_unbusy_tcl(ahc, BUILD_TCL(i << 4, lun)); in ahc_chip_init()
5131 ahc->qoutfifo[i] = SCB_LIST_NULL; in ahc_chip_init()
5132 ahc_sync_qoutfifo(ahc, BUS_DMASYNC_PREREAD); in ahc_chip_init()
5135 ahc->qinfifo[i] = SCB_LIST_NULL; in ahc_chip_init()
5137 if ((ahc->features & AHC_MULTI_TID) != 0) { in ahc_chip_init()
5138 ahc_outb(ahc, TARGID, 0); in ahc_chip_init()
5139 ahc_outb(ahc, TARGID + 1, 0); in ahc_chip_init()
5145 physaddr = ahc->scb_data->hscb_busaddr; in ahc_chip_init()
5146 ahc_outb(ahc, HSCB_ADDR, physaddr & 0xFF); in ahc_chip_init()
5147 ahc_outb(ahc, HSCB_ADDR + 1, (physaddr >> 8) & 0xFF); in ahc_chip_init()
5148 ahc_outb(ahc, HSCB_ADDR + 2, (physaddr >> 16) & 0xFF); in ahc_chip_init()
5149 ahc_outb(ahc, HSCB_ADDR + 3, (physaddr >> 24) & 0xFF); in ahc_chip_init()
5151 physaddr = ahc->shared_data_busaddr; in ahc_chip_init()
5152 ahc_outb(ahc, SHARED_DATA_ADDR, physaddr & 0xFF); in ahc_chip_init()
5153 ahc_outb(ahc, SHARED_DATA_ADDR + 1, (physaddr >> 8) & 0xFF); in ahc_chip_init()
5154 ahc_outb(ahc, SHARED_DATA_ADDR + 2, (physaddr >> 16) & 0xFF); in ahc_chip_init()
5155 ahc_outb(ahc, SHARED_DATA_ADDR + 3, (physaddr >> 24) & 0xFF); in ahc_chip_init()
5162 ahc_outb(ahc, CMDSIZE_TABLE, 5); in ahc_chip_init()
5163 ahc_outb(ahc, CMDSIZE_TABLE + 1, 9); in ahc_chip_init()
5164 ahc_outb(ahc, CMDSIZE_TABLE + 2, 9); in ahc_chip_init()
5165 ahc_outb(ahc, CMDSIZE_TABLE + 3, 0); in ahc_chip_init()
5166 ahc_outb(ahc, CMDSIZE_TABLE + 4, 15); in ahc_chip_init()
5167 ahc_outb(ahc, CMDSIZE_TABLE + 5, 11); in ahc_chip_init()
5168 ahc_outb(ahc, CMDSIZE_TABLE + 6, 0); in ahc_chip_init()
5169 ahc_outb(ahc, CMDSIZE_TABLE + 7, 0); in ahc_chip_init()
5171 if ((ahc->features & AHC_HS_MAILBOX) != 0) in ahc_chip_init()
5172 ahc_outb(ahc, HS_MAILBOX, 0); in ahc_chip_init()
5175 if ((ahc->features & AHC_TARGETMODE) != 0) { in ahc_chip_init()
5176 ahc->tqinfifonext = 1; in ahc_chip_init()
5177 ahc_outb(ahc, KERNEL_TQINPOS, ahc->tqinfifonext - 1); in ahc_chip_init()
5178 ahc_outb(ahc, TQINPOS, ahc->tqinfifonext); in ahc_chip_init()
5180 ahc->qinfifonext = 0; in ahc_chip_init()
5181 ahc->qoutfifonext = 0; in ahc_chip_init()
5182 if ((ahc->features & AHC_QUEUE_REGS) != 0) { in ahc_chip_init()
5183 ahc_outb(ahc, QOFF_CTLSTA, SCB_QSIZE_256); in ahc_chip_init()
5184 ahc_outb(ahc, HNSCB_QOFF, ahc->qinfifonext); in ahc_chip_init()
5185 ahc_outb(ahc, SNSCB_QOFF, ahc->qinfifonext); in ahc_chip_init()
5186 ahc_outb(ahc, SDSCB_QOFF, 0); in ahc_chip_init()
5188 ahc_outb(ahc, KERNEL_QINPOS, ahc->qinfifonext); in ahc_chip_init()
5189 ahc_outb(ahc, QINPOS, ahc->qinfifonext); in ahc_chip_init()
5190 ahc_outb(ahc, QOUTPOS, ahc->qoutfifonext); in ahc_chip_init()
5194 ahc_outb(ahc, WAITING_SCBH, SCB_LIST_NULL); in ahc_chip_init()
5197 ahc_outb(ahc, DISCONNECTED_SCBH, SCB_LIST_NULL); in ahc_chip_init()
5200 ahc_outb(ahc, MSG_OUT, MSG_NOOP); in ahc_chip_init()
5208 if ((ahc->flags & AHC_INITIATORROLE) != 0) in ahc_chip_init()
5210 ahc_outb(ahc, SCSISEQ_TEMPLATE, scsiseq_template); in ahc_chip_init()
5213 ahc_build_free_scb_list(ahc); in ahc_chip_init()
5218 ahc_outb(ahc, NEXT_QUEUED_SCB, ahc->next_queued_scb->hscb->tag); in ahc_chip_init()
5226 ahc_name(ahc)); in ahc_chip_init()
5228 error = ahc_loadseq(ahc); in ahc_chip_init()
5232 if ((ahc->features & AHC_ULTRA2) != 0) { in ahc_chip_init()
5243 (ahc_inb(ahc, SBLKCTL) & (ENAB40|ENAB20)) == 0 && wait; in ahc_chip_init()
5247 ahc_restart(ahc); in ahc_chip_init()
5255 ahc_init(struct ahc_softc *ahc) in ahc_init() argument
5267 ahc->flags |= AHC_SEQUENCER_DEBUG; in ahc_init()
5276 printk (" 0x%x", ahc_inb(ahc, i)); in ahc_init()
5278 if ((ahc->features & AHC_MORE_SRAM) != 0) { in ahc_init()
5283 printk (" 0x%x", ahc_inb(ahc, i)); in ahc_init()
5291 ahc_outb(ahc, CLRINT, CLRPARERR); in ahc_init()
5292 ahc_outb(ahc, CLRINT, CLRBRKADRINT); in ahc_init()
5299 if ((ahc->flags & AHC_USEDEFAULTS) != 0) in ahc_init()
5300 ahc->our_id = ahc->our_id_b = 7; in ahc_init()
5305 ahc->flags |= AHC_INITIATORROLE; in ahc_init()
5310 if ((AHC_TMODE_ENABLE & (0x1 << ahc->unit)) == 0) in ahc_init()
5311 ahc->features &= ~AHC_TARGETMODE; in ahc_init()
5313 ahc->init_level++; in ahc_init()
5325 if ((ahc->features & AHC_TARGETMODE) != 0) in ahc_init()
5328 if (ahc_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/1, in ahc_init()
5336 /*flags*/0, &ahc->shared_data_dmat) != 0) { in ahc_init()
5340 ahc->init_level++; in ahc_init()
5343 if (ahc_dmamem_alloc(ahc, ahc->shared_data_dmat, in ahc_init()
5344 (void **)&ahc->qoutfifo, in ahc_init()
5345 BUS_DMA_NOWAIT, &ahc->shared_data_dmamap) != 0) { in ahc_init()
5349 ahc->init_level++; in ahc_init()
5352 ahc_dmamap_load(ahc, ahc->shared_data_dmat, ahc->shared_data_dmamap, in ahc_init()
5353 ahc->qoutfifo, driver_data_size, ahc_dmamap_cb, in ahc_init()
5354 &ahc->shared_data_busaddr, /*flags*/0); in ahc_init()
5356 if ((ahc->features & AHC_TARGETMODE) != 0) { in ahc_init()
5357 ahc->targetcmds = (struct target_cmd *)ahc->qoutfifo; in ahc_init()
5358 ahc->qoutfifo = (uint8_t *)&ahc->targetcmds[AHC_TMODE_CMDS]; in ahc_init()
5359 ahc->dma_bug_buf = ahc->shared_data_busaddr in ahc_init()
5363 ahc->targetcmds[i].cmd_valid = 0; in ahc_init()
5364 ahc_sync_tqinfifo(ahc, BUS_DMASYNC_PREREAD); in ahc_init()
5365 ahc->qoutfifo = (uint8_t *)&ahc->targetcmds[256]; in ahc_init()
5367 ahc->qinfifo = &ahc->qoutfifo[256]; in ahc_init()
5369 ahc->init_level++; in ahc_init()
5372 if (ahc->scb_data->maxhscbs == 0) in ahc_init()
5373 if (ahc_init_scbdata(ahc) != 0) in ahc_init()
5381 if (ahc_alloc_tstate(ahc, ahc->our_id, 'A') == NULL) { in ahc_init()
5383 "Failing attach\n", ahc_name(ahc)); in ahc_init()
5387 if ((ahc->features & AHC_TWIN) != 0) { in ahc_init()
5388 if (ahc_alloc_tstate(ahc, ahc->our_id_b, 'B') == NULL) { in ahc_init()
5390 "Failing attach\n", ahc_name(ahc)); in ahc_init()
5395 if (ahc->scb_data->maxhscbs < AHC_SCB_MAX_ALLOC) { in ahc_init()
5396 ahc->flags |= AHC_PAGESCBS; in ahc_init()
5398 ahc->flags &= ~AHC_PAGESCBS; in ahc_init()
5405 ahc_name(ahc), in ahc_init()
5416 if (ahc->features & AHC_TWIN) { in ahc_init()
5417 scsi_conf = ahc_inb(ahc, SCSICONF + 1); in ahc_init()
5419 && (ahc->flags & AHC_INITIATORROLE) != 0) in ahc_init()
5420 ahc->flags |= AHC_RESET_BUS_B; in ahc_init()
5423 scsi_conf = ahc_inb(ahc, SCSICONF); in ahc_init()
5425 && (ahc->flags & AHC_INITIATORROLE) != 0) in ahc_init()
5426 ahc->flags |= AHC_RESET_BUS_A; in ahc_init()
5432 if ((ahc->flags & AHC_USEDEFAULTS) != 0) { in ahc_init()
5434 "device parameters\n", ahc_name(ahc)); in ahc_init()
5435 ahc->flags |= AHC_EXTENDED_TRANS_A|AHC_EXTENDED_TRANS_B| in ahc_init()
5438 if ((ahc->features & AHC_ULTRA) != 0) in ahc_init()
5441 discenable = ~((ahc_inb(ahc, DISC_DSB + 1) << 8) in ahc_init()
5442 | ahc_inb(ahc, DISC_DSB)); in ahc_init()
5443 if ((ahc->features & (AHC_ULTRA|AHC_ULTRA2)) != 0) in ahc_init()
5444 ultraenb = (ahc_inb(ahc, ULTRA_ENB + 1) << 8) in ahc_init()
5445 | ahc_inb(ahc, ULTRA_ENB); in ahc_init()
5448 if ((ahc->features & (AHC_WIDE|AHC_TWIN)) == 0) in ahc_init()
5459 our_id = ahc->our_id; in ahc_init()
5461 if (i > 7 && (ahc->features & AHC_TWIN) != 0) { in ahc_init()
5463 our_id = ahc->our_id_b; in ahc_init()
5466 tinfo = ahc_fetch_transinfo(ahc, channel, our_id, in ahc_init()
5470 if (ahc->flags & AHC_USEDEFAULTS) { in ahc_init()
5471 if ((ahc->features & AHC_WIDE) != 0) in ahc_init()
5485 scsirate = ahc_inb(ahc, TARG_SCSIRATE + i); in ahc_init()
5487 if ((ahc->features & AHC_ULTRA2) != 0) { in ahc_init()
5502 offset = ahc_inb(ahc, TARG_OFFSET + i); in ahc_init()
5507 if ((ahc->features & AHC_DT) != 0) in ahc_init()
5510 ahc_find_period(ahc, scsirate, maxsync); in ahc_init()
5516 && (ahc->features & AHC_DT) != 0) in ahc_init()
5527 ahc_find_period(ahc, scsirate, in ahc_init()
5537 && (ahc->features & AHC_WIDE) != 0) in ahc_init()
5540 if ((ahc->features & AHC_DT) != 0) in ahc_init()
5551 ahc->user_discenable = discenable; in ahc_init()
5552 ahc->user_tagenable = tagenable; in ahc_init()
5554 return (ahc->bus_chip_init(ahc)); in ahc_init()
5558 ahc_intr_enable(struct ahc_softc *ahc, int enable) in ahc_intr_enable() argument
5562 hcntrl = ahc_inb(ahc, HCNTRL); in ahc_intr_enable()
5564 ahc->pause &= ~INTEN; in ahc_intr_enable()
5565 ahc->unpause &= ~INTEN; in ahc_intr_enable()
5568 ahc->pause |= INTEN; in ahc_intr_enable()
5569 ahc->unpause |= INTEN; in ahc_intr_enable()
5571 ahc_outb(ahc, HCNTRL, hcntrl); in ahc_intr_enable()
5582 ahc_pause_and_flushwork(struct ahc_softc *ahc) in ahc_pause_and_flushwork() argument
5589 ahc->flags |= AHC_ALL_INTERRUPTS; in ahc_pause_and_flushwork()
5593 ahc_unpause(ahc); in ahc_pause_and_flushwork()
5600 ahc_intr(ahc); in ahc_pause_and_flushwork()
5601 ahc_pause(ahc); in ahc_pause_and_flushwork()
5603 ahc_outb(ahc, SCSISEQ, ahc_inb(ahc, SCSISEQ) & ~ENSELO); in ahc_pause_and_flushwork()
5604 intstat = ahc_inb(ahc, INTSTAT); in ahc_pause_and_flushwork()
5606 ahc_clear_critical_section(ahc); in ahc_pause_and_flushwork()
5607 intstat = ahc_inb(ahc, INTSTAT); in ahc_pause_and_flushwork()
5610 && (intstat != 0xFF || (ahc->features & AHC_REMOVABLE) == 0) in ahc_pause_and_flushwork()
5612 || (ahc_inb(ahc, SSTAT0) & (SELDO|SELINGO)) != 0)); in ahc_pause_and_flushwork()
5615 ahc_inb(ahc, INTSTAT)); in ahc_pause_and_flushwork()
5617 ahc_platform_flushwork(ahc); in ahc_pause_and_flushwork()
5618 ahc->flags &= ~AHC_ALL_INTERRUPTS; in ahc_pause_and_flushwork()
5623 ahc_suspend(struct ahc_softc *ahc) in ahc_suspend() argument
5626 ahc_pause_and_flushwork(ahc); in ahc_suspend()
5628 if (LIST_FIRST(&ahc->pending_scbs) != NULL) { in ahc_suspend()
5629 ahc_unpause(ahc); in ahc_suspend()
5639 if (ahc->pending_device != NULL) { in ahc_suspend()
5640 ahc_unpause(ahc); in ahc_suspend()
5644 ahc_shutdown(ahc); in ahc_suspend()
5649 ahc_resume(struct ahc_softc *ahc) in ahc_resume() argument
5652 ahc_reset(ahc, /*reinit*/TRUE); in ahc_resume()
5653 ahc_intr_enable(ahc, TRUE); in ahc_resume()
5654 ahc_restart(ahc); in ahc_resume()
5664 ahc_index_busy_tcl(struct ahc_softc *ahc, u_int tcl) in ahc_index_busy_tcl() argument
5669 if ((ahc->flags & AHC_SCB_BTT) != 0) { in ahc_index_busy_tcl()
5672 saved_scbptr = ahc_inb(ahc, SCBPTR); in ahc_index_busy_tcl()
5673 ahc_outb(ahc, SCBPTR, TCL_LUN(tcl)); in ahc_index_busy_tcl()
5674 scbid = ahc_inb(ahc, SCB_64_BTT + TCL_TARGET_OFFSET(tcl)); in ahc_index_busy_tcl()
5675 ahc_outb(ahc, SCBPTR, saved_scbptr); in ahc_index_busy_tcl()
5678 scbid = ahc_inb(ahc, BUSY_TARGETS + target_offset); in ahc_index_busy_tcl()
5685 ahc_unbusy_tcl(struct ahc_softc *ahc, u_int tcl) in ahc_unbusy_tcl() argument
5689 if ((ahc->flags & AHC_SCB_BTT) != 0) { in ahc_unbusy_tcl()
5692 saved_scbptr = ahc_inb(ahc, SCBPTR); in ahc_unbusy_tcl()
5693 ahc_outb(ahc, SCBPTR, TCL_LUN(tcl)); in ahc_unbusy_tcl()
5694 ahc_outb(ahc, SCB_64_BTT+TCL_TARGET_OFFSET(tcl), SCB_LIST_NULL); in ahc_unbusy_tcl()
5695 ahc_outb(ahc, SCBPTR, saved_scbptr); in ahc_unbusy_tcl()
5698 ahc_outb(ahc, BUSY_TARGETS + target_offset, SCB_LIST_NULL); in ahc_unbusy_tcl()
5703 ahc_busy_tcl(struct ahc_softc *ahc, u_int tcl, u_int scbid) in ahc_busy_tcl() argument
5707 if ((ahc->flags & AHC_SCB_BTT) != 0) { in ahc_busy_tcl()
5710 saved_scbptr = ahc_inb(ahc, SCBPTR); in ahc_busy_tcl()
5711 ahc_outb(ahc, SCBPTR, TCL_LUN(tcl)); in ahc_busy_tcl()
5712 ahc_outb(ahc, SCB_64_BTT + TCL_TARGET_OFFSET(tcl), scbid); in ahc_busy_tcl()
5713 ahc_outb(ahc, SCBPTR, saved_scbptr); in ahc_busy_tcl()
5716 ahc_outb(ahc, BUSY_TARGETS + target_offset, scbid); in ahc_busy_tcl()
5722 ahc_match_scb(struct ahc_softc *ahc, struct scb *scb, int target, in ahc_match_scb() argument
5725 int targ = SCB_GET_TARGET(ahc, scb); in ahc_match_scb()
5726 char chan = SCB_GET_CHANNEL(ahc, scb); in ahc_match_scb()
5758 ahc_freeze_devq(struct ahc_softc *ahc, struct scb *scb) in ahc_freeze_devq() argument
5764 target = SCB_GET_TARGET(ahc, scb); in ahc_freeze_devq()
5766 channel = SCB_GET_CHANNEL(ahc, scb); in ahc_freeze_devq()
5768 ahc_search_qinfifo(ahc, target, channel, lun, in ahc_freeze_devq()
5772 ahc_platform_freeze_devq(ahc, scb); in ahc_freeze_devq()
5776 ahc_qinfifo_requeue_tail(struct ahc_softc *ahc, struct scb *scb) in ahc_qinfifo_requeue_tail() argument
5781 if (ahc_qinfifo_count(ahc) != 0) { in ahc_qinfifo_requeue_tail()
5785 prev_pos = ahc->qinfifonext - 1; in ahc_qinfifo_requeue_tail()
5786 prev_tag = ahc->qinfifo[prev_pos]; in ahc_qinfifo_requeue_tail()
5787 prev_scb = ahc_lookup_scb(ahc, prev_tag); in ahc_qinfifo_requeue_tail()
5789 ahc_qinfifo_requeue(ahc, prev_scb, scb); in ahc_qinfifo_requeue_tail()
5790 if ((ahc->features & AHC_QUEUE_REGS) != 0) { in ahc_qinfifo_requeue_tail()
5791 ahc_outb(ahc, HNSCB_QOFF, ahc->qinfifonext); in ahc_qinfifo_requeue_tail()
5793 ahc_outb(ahc, KERNEL_QINPOS, ahc->qinfifonext); in ahc_qinfifo_requeue_tail()
5798 ahc_qinfifo_requeue(struct ahc_softc *ahc, struct scb *prev_scb, in ahc_qinfifo_requeue() argument
5802 ahc_outb(ahc, NEXT_QUEUED_SCB, scb->hscb->tag); in ahc_qinfifo_requeue()
5805 ahc_sync_scb(ahc, prev_scb, in ahc_qinfifo_requeue()
5808 ahc->qinfifo[ahc->qinfifonext++] = scb->hscb->tag; in ahc_qinfifo_requeue()
5809 scb->hscb->next = ahc->next_queued_scb->hscb->tag; in ahc_qinfifo_requeue()
5810 ahc_sync_scb(ahc, scb, BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE); in ahc_qinfifo_requeue()
5814 ahc_qinfifo_count(struct ahc_softc *ahc) in ahc_qinfifo_count() argument
5819 if ((ahc->features & AHC_QUEUE_REGS) != 0) { in ahc_qinfifo_count()
5820 qinpos = ahc_inb(ahc, SNSCB_QOFF); in ahc_qinfifo_count()
5821 ahc_outb(ahc, SNSCB_QOFF, qinpos); in ahc_qinfifo_count()
5823 qinpos = ahc_inb(ahc, QINPOS); in ahc_qinfifo_count()
5824 diff = ahc->qinfifonext - qinpos; in ahc_qinfifo_count()
5829 ahc_search_qinfifo(struct ahc_softc *ahc, int target, char channel, in ahc_search_qinfifo() argument
5844 qintail = ahc->qinfifonext; in ahc_search_qinfifo()
5845 have_qregs = (ahc->features & AHC_QUEUE_REGS) != 0; in ahc_search_qinfifo()
5847 qinstart = ahc_inb(ahc, SNSCB_QOFF); in ahc_search_qinfifo()
5848 ahc_outb(ahc, SNSCB_QOFF, qinstart); in ahc_search_qinfifo()
5850 qinstart = ahc_inb(ahc, QINPOS); in ahc_search_qinfifo()
5860 ahc_freeze_untagged_queues(ahc); in ahc_search_qinfifo()
5867 ahc->qinfifonext = qinpos; in ahc_search_qinfifo()
5868 ahc_outb(ahc, NEXT_QUEUED_SCB, ahc->next_queued_scb->hscb->tag); in ahc_search_qinfifo()
5871 scb = ahc_lookup_scb(ahc, ahc->qinfifo[qinpos]); in ahc_search_qinfifo()
5874 qinpos, ahc->qinfifo[qinpos]); in ahc_search_qinfifo()
5878 if (ahc_match_scb(ahc, scb, target, channel, lun, tag, role)) { in ahc_search_qinfifo()
5897 ahc_done(ahc, scb); in ahc_search_qinfifo()
5904 ahc_qinfifo_requeue(ahc, prev_scb, scb); in ahc_search_qinfifo()
5909 ahc_qinfifo_requeue(ahc, prev_scb, scb); in ahc_search_qinfifo()
5915 if ((ahc->features & AHC_QUEUE_REGS) != 0) { in ahc_search_qinfifo()
5916 ahc_outb(ahc, HNSCB_QOFF, ahc->qinfifonext); in ahc_search_qinfifo()
5918 ahc_outb(ahc, KERNEL_QINPOS, ahc->qinfifonext); in ahc_search_qinfifo()
5923 && (qinstart != ahc->qinfifonext)) { in ahc_search_qinfifo()
5936 scb = ahc_lookup_scb(ahc, ahc->qinfifo[qinstart]); in ahc_search_qinfifo()
5940 found, qinstart, ahc->qinfifonext); in ahc_search_qinfifo()
5950 ahc->scb_data->scbindex[scb->hscb->tag] = NULL; in ahc_search_qinfifo()
5951 ahc_swap_with_next_hscb(ahc, scb); in ahc_search_qinfifo()
5953 ahc->qinfifo[qinstart] = scb->hscb->tag; in ahc_search_qinfifo()
5956 ahc_outb(ahc, NEXT_QUEUED_SCB, scb->hscb->tag); in ahc_search_qinfifo()
5959 qintail = ahc->qinfifonext - 1; in ahc_search_qinfifo()
5960 scb = ahc_lookup_scb(ahc, ahc->qinfifo[qintail]); in ahc_search_qinfifo()
5961 scb->hscb->next = ahc->next_queued_scb->hscb->tag; in ahc_search_qinfifo()
5967 curscbptr = ahc_inb(ahc, SCBPTR); in ahc_search_qinfifo()
5968 next = ahc_inb(ahc, WAITING_SCBH); /* Start at head of list. */ in ahc_search_qinfifo()
5974 ahc_outb(ahc, SCBPTR, next); in ahc_search_qinfifo()
5975 scb_index = ahc_inb(ahc, SCB_TAG); in ahc_search_qinfifo()
5976 if (scb_index >= ahc->scb_data->numscbs) { in ahc_search_qinfifo()
5979 scb_index, ahc->scb_data->numscbs); in ahc_search_qinfifo()
5980 ahc_dump_card_state(ahc); in ahc_search_qinfifo()
5983 scb = ahc_lookup_scb(ahc, scb_index); in ahc_search_qinfifo()
5989 if (ahc_match_scb(ahc, scb, target, channel, in ahc_search_qinfifo()
6010 ahc_done(ahc, scb); in ahc_search_qinfifo()
6014 next = ahc_rem_wscb(ahc, next, prev); in ahc_search_qinfifo()
6018 next = ahc_inb(ahc, SCB_NEXT); in ahc_search_qinfifo()
6024 next = ahc_inb(ahc, SCB_NEXT); in ahc_search_qinfifo()
6027 ahc_outb(ahc, SCBPTR, curscbptr); in ahc_search_qinfifo()
6029 found += ahc_search_untagged_queues(ahc, /*ahc_io_ctx_t*/NULL, target, in ahc_search_qinfifo()
6033 ahc_release_untagged_queues(ahc); in ahc_search_qinfifo()
6038 ahc_search_untagged_queues(struct ahc_softc *ahc, ahc_io_ctx_t ctx, in ahc_search_untagged_queues() argument
6052 ahc_freeze_untagged_queues(ahc); in ahc_search_untagged_queues()
6057 if ((ahc->flags & AHC_SCB_BTT) == 0) { in ahc_search_untagged_queues()
6075 untagged_q = &(ahc->untagged_queues[i]); in ahc_search_untagged_queues()
6094 if (ahc_match_scb(ahc, scb, target, channel, lun, in ahc_search_untagged_queues()
6117 ahc_done(ahc, scb); in ahc_search_untagged_queues()
6131 ahc_release_untagged_queues(ahc); in ahc_search_untagged_queues()
6136 ahc_search_disc_list(struct ahc_softc *ahc, int target, char channel, in ahc_search_disc_list() argument
6147 next = ahc_inb(ahc, DISCONNECTED_SCBH); in ahc_search_disc_list()
6152 active_scb = ahc_inb(ahc, SCBPTR); in ahc_search_disc_list()
6160 ahc_outb(ahc, SCBPTR, next); in ahc_search_disc_list()
6161 scb_index = ahc_inb(ahc, SCB_TAG); in ahc_search_disc_list()
6162 if (scb_index >= ahc->scb_data->numscbs) { in ahc_search_disc_list()
6165 scb_index, ahc->scb_data->numscbs); in ahc_search_disc_list()
6166 ahc_dump_card_state(ahc); in ahc_search_disc_list()
6175 scbp = ahc_lookup_scb(ahc, scb_index); in ahc_search_disc_list()
6176 if (ahc_match_scb(ahc, scbp, target, channel, lun, in ahc_search_disc_list()
6181 ahc_rem_scb_from_disc_list(ahc, prev, next); in ahc_search_disc_list()
6184 next = ahc_inb(ahc, SCB_NEXT); in ahc_search_disc_list()
6190 next = ahc_inb(ahc, SCB_NEXT); in ahc_search_disc_list()
6194 ahc_outb(ahc, SCBPTR, active_scb); in ahc_search_disc_list()
6203 ahc_rem_scb_from_disc_list(struct ahc_softc *ahc, u_int prev, u_int scbptr) in ahc_rem_scb_from_disc_list() argument
6207 ahc_outb(ahc, SCBPTR, scbptr); in ahc_rem_scb_from_disc_list()
6208 next = ahc_inb(ahc, SCB_NEXT); in ahc_rem_scb_from_disc_list()
6210 ahc_outb(ahc, SCB_CONTROL, 0); in ahc_rem_scb_from_disc_list()
6212 ahc_add_curscb_to_free_list(ahc); in ahc_rem_scb_from_disc_list()
6215 ahc_outb(ahc, SCBPTR, prev); in ahc_rem_scb_from_disc_list()
6216 ahc_outb(ahc, SCB_NEXT, next); in ahc_rem_scb_from_disc_list()
6218 ahc_outb(ahc, DISCONNECTED_SCBH, next); in ahc_rem_scb_from_disc_list()
6229 ahc_add_curscb_to_free_list(struct ahc_softc *ahc) in ahc_add_curscb_to_free_list() argument
6235 ahc_outb(ahc, SCB_TAG, SCB_LIST_NULL); in ahc_add_curscb_to_free_list()
6237 if ((ahc->flags & AHC_PAGESCBS) != 0) { in ahc_add_curscb_to_free_list()
6238 ahc_outb(ahc, SCB_NEXT, ahc_inb(ahc, FREE_SCBH)); in ahc_add_curscb_to_free_list()
6239 ahc_outb(ahc, FREE_SCBH, ahc_inb(ahc, SCBPTR)); in ahc_add_curscb_to_free_list()
6248 ahc_rem_wscb(struct ahc_softc *ahc, u_int scbpos, u_int prev) in ahc_rem_wscb() argument
6256 curscb = ahc_inb(ahc, SCBPTR); in ahc_rem_wscb()
6257 ahc_outb(ahc, SCBPTR, scbpos); in ahc_rem_wscb()
6258 next = ahc_inb(ahc, SCB_NEXT); in ahc_rem_wscb()
6261 ahc_outb(ahc, SCB_CONTROL, 0); in ahc_rem_wscb()
6263 ahc_add_curscb_to_free_list(ahc); in ahc_rem_wscb()
6268 ahc_outb(ahc, WAITING_SCBH, next); in ahc_rem_wscb()
6274 ahc_outb(ahc, SCSISEQ, (ahc_inb(ahc, SCSISEQ) & ~ENSELO)); in ahc_rem_wscb()
6280 ahc_outb(ahc, SCBPTR, prev); in ahc_rem_wscb()
6281 ahc_outb(ahc, SCB_NEXT, next); in ahc_rem_wscb()
6287 ahc_outb(ahc, SCBPTR, curscb); in ahc_rem_wscb()
6299 ahc_abort_scbs(struct ahc_softc *ahc, int target, char channel, in ahc_abort_scbs() argument
6316 ahc_freeze_untagged_queues(ahc); in ahc_abort_scbs()
6319 active_scb = ahc_inb(ahc, SCBPTR); in ahc_abort_scbs()
6321 found = ahc_search_qinfifo(ahc, target, channel, lun, SCB_LIST_NULL, in ahc_abort_scbs()
6346 if ((ahc->flags & AHC_SCB_BTT) != 0) in ahc_abort_scbs()
6360 scbid = ahc_index_busy_tcl(ahc, tcl); in ahc_abort_scbs()
6361 scbp = ahc_lookup_scb(ahc, scbid); in ahc_abort_scbs()
6363 || ahc_match_scb(ahc, scbp, target, channel, in ahc_abort_scbs()
6366 ahc_unbusy_tcl(ahc, BUILD_TCL(i << 4, j)); in ahc_abort_scbs()
6376 ahc_search_disc_list(ahc, target, channel, lun, tag, in ahc_abort_scbs()
6388 for (i = 0; i < ahc->scb_data->maxhscbs; i++) { in ahc_abort_scbs()
6391 ahc_outb(ahc, SCBPTR, i); in ahc_abort_scbs()
6392 scbid = ahc_inb(ahc, SCB_TAG); in ahc_abort_scbs()
6393 scbp = ahc_lookup_scb(ahc, scbid); in ahc_abort_scbs()
6396 && ahc_match_scb(ahc, scbp, target, channel, lun, tag, role))) in ahc_abort_scbs()
6397 ahc_add_curscb_to_free_list(ahc); in ahc_abort_scbs()
6406 scbp_next = LIST_FIRST(&ahc->pending_scbs); in ahc_abort_scbs()
6410 if (ahc_match_scb(ahc, scbp, target, channel, lun, tag, role)) { in ahc_abort_scbs()
6420 ahc_done(ahc, scbp); in ahc_abort_scbs()
6424 ahc_outb(ahc, SCBPTR, active_scb); in ahc_abort_scbs()
6425 ahc_platform_abort_scbs(ahc, target, channel, lun, tag, role, status); in ahc_abort_scbs()
6426 ahc_release_untagged_queues(ahc); in ahc_abort_scbs()
6431 ahc_reset_current_bus(struct ahc_softc *ahc) in ahc_reset_current_bus() argument
6435 ahc_outb(ahc, SIMODE1, ahc_inb(ahc, SIMODE1) & ~ENSCSIRST); in ahc_reset_current_bus()
6436 scsiseq = ahc_inb(ahc, SCSISEQ); in ahc_reset_current_bus()
6437 ahc_outb(ahc, SCSISEQ, scsiseq | SCSIRSTO); in ahc_reset_current_bus()
6438 ahc_flush_device_writes(ahc); in ahc_reset_current_bus()
6441 ahc_outb(ahc, SCSISEQ, scsiseq & ~SCSIRSTO); in ahc_reset_current_bus()
6443 ahc_clear_intstat(ahc); in ahc_reset_current_bus()
6446 ahc_outb(ahc, SIMODE1, ahc_inb(ahc, SIMODE1) | ENSCSIRST); in ahc_reset_current_bus()
6450 ahc_reset_channel(struct ahc_softc *ahc, char channel, int initiate_reset) in ahc_reset_channel() argument
6461 ahc->pending_device = NULL; in ahc_reset_channel()
6468 ahc_pause(ahc); in ahc_reset_channel()
6471 ahc_clear_critical_section(ahc); in ahc_reset_channel()
6478 ahc_run_qoutfifo(ahc); in ahc_reset_channel()
6490 if ((ahc->flags & AHC_TARGETROLE) != 0) { in ahc_reset_channel()
6491 ahc_run_tqinfifo(ahc, /*paused*/TRUE); in ahc_reset_channel()
6498 sblkctl = ahc_inb(ahc, SBLKCTL); in ahc_reset_channel()
6500 if ((ahc->features & AHC_TWIN) != 0 in ahc_reset_channel()
6503 scsiseq = ahc_inb(ahc, SCSISEQ_TEMPLATE); in ahc_reset_channel()
6509 ahc_outb(ahc, SBLKCTL, sblkctl ^ SELBUSB); in ahc_reset_channel()
6510 simode1 = ahc_inb(ahc, SIMODE1) & ~(ENBUSFREE|ENSCSIRST); in ahc_reset_channel()
6517 if ((ahc->flags & AHC_TARGETROLE) != 0) in ahc_reset_channel()
6520 ahc_outb(ahc, SIMODE1, simode1); in ahc_reset_channel()
6522 ahc_reset_current_bus(ahc); in ahc_reset_channel()
6523 ahc_clear_intstat(ahc); in ahc_reset_channel()
6524 ahc_outb(ahc, SCSISEQ, scsiseq & (ENSELI|ENRSELI|ENAUTOATNP)); in ahc_reset_channel()
6525 ahc_outb(ahc, SBLKCTL, sblkctl); in ahc_reset_channel()
6529 simode1 = ahc_inb(ahc, SIMODE1) & ~(ENBUSFREE|ENSCSIRST); in ahc_reset_channel()
6536 if ((ahc->flags & AHC_TARGETROLE) != 0) in ahc_reset_channel()
6539 ahc_outb(ahc, SIMODE1, simode1); in ahc_reset_channel()
6541 ahc_reset_current_bus(ahc); in ahc_reset_channel()
6542 ahc_clear_intstat(ahc); in ahc_reset_channel()
6543 ahc_outb(ahc, SCSISEQ, scsiseq & (ENSELI|ENRSELI|ENAUTOATNP)); in ahc_reset_channel()
6551 found = ahc_abort_scbs(ahc, CAM_TARGET_WILDCARD, channel, in ahc_reset_channel()
6555 max_scsiid = (ahc->features & AHC_WIDE) ? 15 : 7; in ahc_reset_channel()
6566 tstate = ahc->enabled_targets[target]; in ahc_reset_channel()
6576 ahc_queue_lstate_event(ahc, lstate, CAM_TARGET_WILDCARD, in ahc_reset_channel()
6578 ahc_send_lstate_events(ahc, lstate); in ahc_reset_channel()
6583 ahc_send_async(ahc, devinfo.channel, CAM_TARGET_WILDCARD, in ahc_reset_channel()
6591 if (ahc->enabled_targets[target] == NULL) in ahc_reset_channel()
6599 ahc_set_width(ahc, &devinfo, MSG_EXT_WDTR_BUS_8_BIT, in ahc_reset_channel()
6601 ahc_set_syncrate(ahc, &devinfo, /*syncrate*/NULL, in ahc_reset_channel()
6609 ahc_restart(ahc); in ahc_reset_channel()
6611 ahc_unpause(ahc); in ahc_reset_channel()
6621 ahc_calc_residual(struct ahc_softc *ahc, struct scb *scb) in ahc_calc_residual() argument
6696 ahc_print_path(ahc, scb); in ahc_calc_residual()
6709 ahc_queue_lstate_event(struct ahc_softc *ahc, struct ahc_tmode_lstate *lstate, in ahc_queue_lstate_event() argument
6760 ahc_send_lstate_events(struct ahc_softc *ahc, struct ahc_tmode_lstate *lstate) in ahc_send_lstate_events() argument
6796 ahc_dumpseq(struct ahc_softc* ahc) in ahc_dumpseq() argument
6800 ahc_outb(ahc, SEQCTL, PERRORDIS|FAILDIS|FASTMODE|LOADRAM); in ahc_dumpseq()
6801 ahc_outb(ahc, SEQADDR0, 0); in ahc_dumpseq()
6802 ahc_outb(ahc, SEQADDR1, 0); in ahc_dumpseq()
6803 for (i = 0; i < ahc->instruction_ram_size; i++) { in ahc_dumpseq()
6806 ahc_insb(ahc, SEQRAM, ins_bytes, 4); in ahc_dumpseq()
6816 ahc_loadseq(struct ahc_softc *ahc) in ahc_loadseq() argument
6841 if (ahc->targetcmds != NULL) in ahc_loadseq()
6844 download_consts[CACHESIZE_MASK] = ahc->pci_cachesize - 1; in ahc_loadseq()
6845 download_consts[INVERTED_CACHESIZE_MASK] = ~(ahc->pci_cachesize - 1); in ahc_loadseq()
6846 sg_prefetch_cnt = ahc->pci_cachesize; in ahc_loadseq()
6856 ahc_outb(ahc, SEQCTL, PERRORDIS|FAILDIS|FASTMODE|LOADRAM); in ahc_loadseq()
6857 ahc_outb(ahc, SEQADDR0, 0); in ahc_loadseq()
6858 ahc_outb(ahc, SEQADDR1, 0); in ahc_loadseq()
6861 if (ahc_check_patch(ahc, &cur_patch, i, &skip_addr) == 0) { in ahc_loadseq()
6869 if (downloaded == ahc->instruction_ram_size) { in ahc_loadseq()
6876 "size of %d!\n", ahc_name(ahc), in ahc_loadseq()
6877 ahc->instruction_ram_size); in ahc_loadseq()
6902 ahc_download_instr(ahc, i, download_consts); in ahc_loadseq()
6906 ahc->num_critical_sections = cs_count; in ahc_loadseq()
6910 ahc->critical_sections = kmalloc(cs_count, GFP_ATOMIC); in ahc_loadseq()
6911 if (ahc->critical_sections == NULL) in ahc_loadseq()
6913 memcpy(ahc->critical_sections, cs_table, cs_count); in ahc_loadseq()
6915 ahc_outb(ahc, SEQCTL, PERRORDIS|FAILDIS|FASTMODE); in ahc_loadseq()
6920 ahc_name(ahc), ahc->features, ahc->bugs, ahc->flags); in ahc_loadseq()
6926 ahc_check_patch(struct ahc_softc *ahc, const struct patch **start_patch, in ahc_check_patch() argument
6939 if (cur_patch->patch_func(ahc) == 0) { in ahc_check_patch()
6962 ahc_download_instr(struct ahc_softc *ahc, u_int instrptr, uint8_t *dconsts) in ahc_download_instr() argument
7003 ahc_check_patch(ahc, &cur_patch, i, &skip_addr); in ahc_download_instr()
7029 if ((ahc->features & AHC_CMD_CHAN) == 0 in ahc_download_instr()
7040 ahc_name(ahc)); in ahc_download_instr()
7046 if ((ahc->features & AHC_ULTRA2) != 0) { in ahc_download_instr()
7078 ahc_outsb(ahc, SEQRAM, instr.bytes, 4); in ahc_download_instr()
7135 ahc_dump_card_state(struct ahc_softc *ahc) in ahc_dump_card_state() argument
7151 if (ahc_is_paused(ahc)) { in ahc_dump_card_state()
7155 ahc_pause(ahc); in ahc_dump_card_state()
7158 saved_scbptr = ahc_inb(ahc, SCBPTR); in ahc_dump_card_state()
7159 last_phase = ahc_inb(ahc, LASTPHASE); in ahc_dump_card_state()
7162 ahc_name(ahc), ahc_lookup_phase_entry(last_phase)->phasemsg, in ahc_dump_card_state()
7163 ahc_inb(ahc, SEQADDR0) | (ahc_inb(ahc, SEQADDR1) << 8)); in ahc_dump_card_state()
7167 ahc_inb(ahc, ACCUM), ahc_inb(ahc, SINDEX), ahc_inb(ahc, DINDEX), in ahc_dump_card_state()
7168 ahc_inb(ahc, ARG_2)); in ahc_dump_card_state()
7169 printk("HCNT = 0x%x SCBPTR = 0x%x\n", ahc_inb(ahc, HCNT), in ahc_dump_card_state()
7170 ahc_inb(ahc, SCBPTR)); in ahc_dump_card_state()
7172 if ((ahc->features & AHC_DT) != 0) in ahc_dump_card_state()
7173 ahc_scsiphase_print(ahc_inb(ahc, SCSIPHASE), &cur_col, 50); in ahc_dump_card_state()
7174 ahc_scsisigi_print(ahc_inb(ahc, SCSISIGI), &cur_col, 50); in ahc_dump_card_state()
7175 ahc_error_print(ahc_inb(ahc, ERROR), &cur_col, 50); in ahc_dump_card_state()
7176 ahc_scsibusl_print(ahc_inb(ahc, SCSIBUSL), &cur_col, 50); in ahc_dump_card_state()
7177 ahc_lastphase_print(ahc_inb(ahc, LASTPHASE), &cur_col, 50); in ahc_dump_card_state()
7178 ahc_scsiseq_print(ahc_inb(ahc, SCSISEQ), &cur_col, 50); in ahc_dump_card_state()
7179 ahc_sblkctl_print(ahc_inb(ahc, SBLKCTL), &cur_col, 50); in ahc_dump_card_state()
7180 ahc_scsirate_print(ahc_inb(ahc, SCSIRATE), &cur_col, 50); in ahc_dump_card_state()
7181 ahc_seqctl_print(ahc_inb(ahc, SEQCTL), &cur_col, 50); in ahc_dump_card_state()
7182 ahc_seq_flags_print(ahc_inb(ahc, SEQ_FLAGS), &cur_col, 50); in ahc_dump_card_state()
7183 ahc_sstat0_print(ahc_inb(ahc, SSTAT0), &cur_col, 50); in ahc_dump_card_state()
7184 ahc_sstat1_print(ahc_inb(ahc, SSTAT1), &cur_col, 50); in ahc_dump_card_state()
7185 ahc_sstat2_print(ahc_inb(ahc, SSTAT2), &cur_col, 50); in ahc_dump_card_state()
7186 ahc_sstat3_print(ahc_inb(ahc, SSTAT3), &cur_col, 50); in ahc_dump_card_state()
7187 ahc_simode0_print(ahc_inb(ahc, SIMODE0), &cur_col, 50); in ahc_dump_card_state()
7188 ahc_simode1_print(ahc_inb(ahc, SIMODE1), &cur_col, 50); in ahc_dump_card_state()
7189 ahc_sxfrctl0_print(ahc_inb(ahc, SXFRCTL0), &cur_col, 50); in ahc_dump_card_state()
7190 ahc_dfcntrl_print(ahc_inb(ahc, DFCNTRL), &cur_col, 50); in ahc_dump_card_state()
7191 ahc_dfstatus_print(ahc_inb(ahc, DFSTATUS), &cur_col, 50); in ahc_dump_card_state()
7196 printk(" 0x%x", ahc_inb(ahc, STACK)|(ahc_inb(ahc, STACK) << 8)); in ahc_dump_card_state()
7197 printk("\nSCB count = %d\n", ahc->scb_data->numscbs); in ahc_dump_card_state()
7198 printk("Kernel NEXTQSCB = %d\n", ahc->next_queued_scb->hscb->tag); in ahc_dump_card_state()
7199 printk("Card NEXTQSCB = %d\n", ahc_inb(ahc, NEXT_QUEUED_SCB)); in ahc_dump_card_state()
7202 if ((ahc->features & AHC_QUEUE_REGS) != 0) { in ahc_dump_card_state()
7203 qinpos = ahc_inb(ahc, SNSCB_QOFF); in ahc_dump_card_state()
7204 ahc_outb(ahc, SNSCB_QOFF, qinpos); in ahc_dump_card_state()
7206 qinpos = ahc_inb(ahc, QINPOS); in ahc_dump_card_state()
7207 qintail = ahc->qinfifonext; in ahc_dump_card_state()
7209 printk("%d ", ahc->qinfifo[qinpos]); in ahc_dump_card_state()
7215 scb_index = ahc_inb(ahc, WAITING_SCBH); in ahc_dump_card_state()
7218 ahc_outb(ahc, SCBPTR, scb_index); in ahc_dump_card_state()
7219 printk("%d:%d ", scb_index, ahc_inb(ahc, SCB_TAG)); in ahc_dump_card_state()
7220 scb_index = ahc_inb(ahc, SCB_NEXT); in ahc_dump_card_state()
7225 scb_index = ahc_inb(ahc, DISCONNECTED_SCBH); in ahc_dump_card_state()
7228 ahc_outb(ahc, SCBPTR, scb_index); in ahc_dump_card_state()
7229 printk("%d:%d ", scb_index, ahc_inb(ahc, SCB_TAG)); in ahc_dump_card_state()
7230 scb_index = ahc_inb(ahc, SCB_NEXT); in ahc_dump_card_state()
7234 ahc_sync_qoutfifo(ahc, BUS_DMASYNC_POSTREAD); in ahc_dump_card_state()
7236 qoutpos = ahc->qoutfifonext; in ahc_dump_card_state()
7238 while (ahc->qoutfifo[qoutpos] != SCB_LIST_NULL && i++ < 256) { in ahc_dump_card_state()
7239 printk("%d ", ahc->qoutfifo[qoutpos]); in ahc_dump_card_state()
7245 scb_index = ahc_inb(ahc, FREE_SCBH); in ahc_dump_card_state()
7248 ahc_outb(ahc, SCBPTR, scb_index); in ahc_dump_card_state()
7250 scb_index = ahc_inb(ahc, SCB_NEXT); in ahc_dump_card_state()
7255 for (i = 0; i < ahc->scb_data->maxhscbs; i++) { in ahc_dump_card_state()
7256 ahc_outb(ahc, SCBPTR, i); in ahc_dump_card_state()
7259 ahc_scb_control_print(ahc_inb(ahc, SCB_CONTROL), &cur_col, 60); in ahc_dump_card_state()
7260 ahc_scb_scsiid_print(ahc_inb(ahc, SCB_SCSIID), &cur_col, 60); in ahc_dump_card_state()
7261 ahc_scb_lun_print(ahc_inb(ahc, SCB_LUN), &cur_col, 60); in ahc_dump_card_state()
7262 ahc_scb_tag_print(ahc_inb(ahc, SCB_TAG), &cur_col, 60); in ahc_dump_card_state()
7268 LIST_FOREACH(scb, &ahc->pending_scbs, pending_links) { in ahc_dump_card_state()
7275 if ((ahc->flags & AHC_PAGESCBS) == 0) { in ahc_dump_card_state()
7276 ahc_outb(ahc, SCBPTR, scb->hscb->tag); in ahc_dump_card_state()
7278 ahc_scb_control_print(ahc_inb(ahc, SCB_CONTROL), in ahc_dump_card_state()
7280 ahc_scb_tag_print(ahc_inb(ahc, SCB_TAG), &cur_col, 60); in ahc_dump_card_state()
7288 SLIST_FOREACH(scb, &ahc->scb_data->free_scbs, links.sle) { in ahc_dump_card_state()
7295 maxtarget = (ahc->features & (AHC_WIDE|AHC_TWIN)) ? 15 : 7; in ahc_dump_card_state()
7297 untagged_q = &ahc->untagged_queues[target]; in ahc_dump_card_state()
7311 ahc_outb(ahc, SCBPTR, saved_scbptr); in ahc_dump_card_state()
7313 ahc_unpause(ahc); in ahc_dump_card_state()
7319 ahc_find_tmode_devs(struct ahc_softc *ahc, struct cam_sim *sim, union ccb *ccb, in ahc_find_tmode_devs() argument
7325 if ((ahc->features & AHC_TARGETMODE) == 0) in ahc_find_tmode_devs()
7335 *lstate = ahc->black_hole; in ahc_find_tmode_devs()
7339 max_id = (ahc->features & AHC_WIDE) ? 16 : 8; in ahc_find_tmode_devs()
7346 *tstate = ahc->enabled_targets[ccb->ccb_h.target_id]; in ahc_find_tmode_devs()
7360 ahc_handle_en_lun(struct ahc_softc *ahc, struct cam_sim *sim, union ccb *ccb) in ahc_handle_en_lun() argument
7374 status = ahc_find_tmode_devs(ahc, sim, ccb, &tstate, &lstate, in ahc_handle_en_lun()
7383 our_id = ahc->our_id; in ahc_handle_en_lun()
7385 our_id = ahc->our_id_b; in ahc_handle_en_lun()
7407 if ((ahc->features & AHC_MULTIROLE) != 0) { in ahc_handle_en_lun()
7409 if ((ahc->features & AHC_MULTI_TID) != 0 in ahc_handle_en_lun()
7410 && (ahc->flags & AHC_INITIATORROLE) != 0) { in ahc_handle_en_lun()
7419 } else if ((ahc->flags & AHC_INITIATORROLE) != 0 in ahc_handle_en_lun()
7420 || ahc->enabled_luns > 0) { in ahc_handle_en_lun()
7430 } else if ((ahc->features & AHC_MULTI_TID) == 0 in ahc_handle_en_lun()
7431 && ahc->enabled_luns > 0) { in ahc_handle_en_lun()
7446 if ((ahc->flags & AHC_TARGETROLE) == 0 in ahc_handle_en_lun()
7452 ahc_lock(ahc, &s); in ahc_handle_en_lun()
7453 if (LIST_FIRST(&ahc->pending_scbs) != NULL) { in ahc_handle_en_lun()
7455 ahc_unlock(ahc, &s); in ahc_handle_en_lun()
7458 saved_flags = ahc->flags; in ahc_handle_en_lun()
7459 ahc->flags |= AHC_TARGETROLE; in ahc_handle_en_lun()
7460 if ((ahc->features & AHC_MULTIROLE) == 0) in ahc_handle_en_lun()
7461 ahc->flags &= ~AHC_INITIATORROLE; in ahc_handle_en_lun()
7462 ahc_pause(ahc); in ahc_handle_en_lun()
7463 error = ahc_loadseq(ahc); in ahc_handle_en_lun()
7473 ahc->flags = saved_flags; in ahc_handle_en_lun()
7474 (void)ahc_loadseq(ahc); in ahc_handle_en_lun()
7475 ahc_restart(ahc); in ahc_handle_en_lun()
7476 ahc_unlock(ahc, &s); in ahc_handle_en_lun()
7480 ahc_restart(ahc); in ahc_handle_en_lun()
7481 ahc_unlock(ahc, &s); in ahc_handle_en_lun()
7486 channel = SIM_CHANNEL(ahc, sim); in ahc_handle_en_lun()
7518 tstate = ahc_alloc_tstate(ahc, target, channel); in ahc_handle_en_lun()
7546 ahc_lock(ahc, &s); in ahc_handle_en_lun()
7547 ahc_pause(ahc); in ahc_handle_en_lun()
7550 ahc->enabled_luns++; in ahc_handle_en_lun()
7552 if ((ahc->features & AHC_MULTI_TID) != 0) { in ahc_handle_en_lun()
7555 targid_mask = ahc_inb(ahc, TARGID) in ahc_handle_en_lun()
7556 | (ahc_inb(ahc, TARGID + 1) << 8); in ahc_handle_en_lun()
7559 ahc_outb(ahc, TARGID, targid_mask); in ahc_handle_en_lun()
7560 ahc_outb(ahc, TARGID+1, (targid_mask >> 8)); in ahc_handle_en_lun()
7562 ahc_update_scsiid(ahc, targid_mask); in ahc_handle_en_lun()
7567 channel = SIM_CHANNEL(ahc, sim); in ahc_handle_en_lun()
7568 our_id = SIM_SCSI_ID(ahc, sim); in ahc_handle_en_lun()
7579 sblkctl = ahc_inb(ahc, SBLKCTL); in ahc_handle_en_lun()
7582 if ((ahc->features & AHC_TWIN) == 0) in ahc_handle_en_lun()
7586 ahc->our_id = target; in ahc_handle_en_lun()
7588 ahc->our_id_b = target; in ahc_handle_en_lun()
7591 ahc_outb(ahc, SBLKCTL, in ahc_handle_en_lun()
7594 ahc_outb(ahc, SCSIID, target); in ahc_handle_en_lun()
7597 ahc_outb(ahc, SBLKCTL, sblkctl); in ahc_handle_en_lun()
7601 ahc->black_hole = lstate; in ahc_handle_en_lun()
7603 if (ahc->black_hole != NULL && ahc->enabled_luns > 0) { in ahc_handle_en_lun()
7604 scsiseq = ahc_inb(ahc, SCSISEQ_TEMPLATE); in ahc_handle_en_lun()
7606 ahc_outb(ahc, SCSISEQ_TEMPLATE, scsiseq); in ahc_handle_en_lun()
7607 scsiseq = ahc_inb(ahc, SCSISEQ); in ahc_handle_en_lun()
7609 ahc_outb(ahc, SCSISEQ, scsiseq); in ahc_handle_en_lun()
7611 ahc_unpause(ahc); in ahc_handle_en_lun()
7612 ahc_unlock(ahc, &s); in ahc_handle_en_lun()
7625 ahc_lock(ahc, &s); in ahc_handle_en_lun()
7628 LIST_FOREACH(scb, &ahc->pending_scbs, pending_links) { in ahc_handle_en_lun()
7636 ahc_unlock(ahc, &s); in ahc_handle_en_lun()
7652 ahc_unlock(ahc, &s); in ahc_handle_en_lun()
7661 ahc_pause(ahc); in ahc_handle_en_lun()
7665 ahc->enabled_luns--; in ahc_handle_en_lun()
7673 ahc_free_tstate(ahc, target, channel, in ahc_handle_en_lun()
7675 if (ahc->features & AHC_MULTI_TID) { in ahc_handle_en_lun()
7678 targid_mask = ahc_inb(ahc, TARGID) in ahc_handle_en_lun()
7679 | (ahc_inb(ahc, TARGID + 1) in ahc_handle_en_lun()
7683 ahc_outb(ahc, TARGID, targid_mask); in ahc_handle_en_lun()
7684 ahc_outb(ahc, TARGID+1, in ahc_handle_en_lun()
7686 ahc_update_scsiid(ahc, targid_mask); in ahc_handle_en_lun()
7691 ahc->black_hole = NULL; in ahc_handle_en_lun()
7699 if (ahc->enabled_luns == 0) { in ahc_handle_en_lun()
7703 scsiseq = ahc_inb(ahc, SCSISEQ_TEMPLATE); in ahc_handle_en_lun()
7705 ahc_outb(ahc, SCSISEQ_TEMPLATE, scsiseq); in ahc_handle_en_lun()
7706 scsiseq = ahc_inb(ahc, SCSISEQ); in ahc_handle_en_lun()
7708 ahc_outb(ahc, SCSISEQ, scsiseq); in ahc_handle_en_lun()
7710 if ((ahc->features & AHC_MULTIROLE) == 0) { in ahc_handle_en_lun()
7712 ahc->flags &= ~AHC_TARGETROLE; in ahc_handle_en_lun()
7713 ahc->flags |= AHC_INITIATORROLE; in ahc_handle_en_lun()
7718 (void)ahc_loadseq(ahc); in ahc_handle_en_lun()
7719 ahc_restart(ahc); in ahc_handle_en_lun()
7726 ahc_unpause(ahc); in ahc_handle_en_lun()
7727 ahc_unlock(ahc, &s); in ahc_handle_en_lun()
7732 ahc_update_scsiid(struct ahc_softc *ahc, u_int targid_mask) in ahc_update_scsiid() argument
7737 if ((ahc->features & AHC_MULTI_TID) == 0) in ahc_update_scsiid()
7746 if ((ahc->features & AHC_ULTRA2) != 0) in ahc_update_scsiid()
7747 scsiid = ahc_inb(ahc, SCSIID_ULTRA2); in ahc_update_scsiid()
7749 scsiid = ahc_inb(ahc, SCSIID); in ahc_update_scsiid()
7757 our_id = ahc->our_id; in ahc_update_scsiid()
7763 if ((ahc->features & AHC_ULTRA2) != 0) in ahc_update_scsiid()
7764 ahc_outb(ahc, SCSIID_ULTRA2, scsiid); in ahc_update_scsiid()
7766 ahc_outb(ahc, SCSIID, scsiid); in ahc_update_scsiid()
7770 ahc_run_tqinfifo(struct ahc_softc *ahc, int paused) in ahc_run_tqinfifo() argument
7779 if ((ahc->features & AHC_AUTOPAUSE) != 0) in ahc_run_tqinfifo()
7782 ahc_sync_tqinfifo(ahc, BUS_DMASYNC_POSTREAD); in ahc_run_tqinfifo()
7783 while ((cmd = &ahc->targetcmds[ahc->tqinfifonext])->cmd_valid != 0) { in ahc_run_tqinfifo()
7789 if (ahc_handle_target_cmd(ahc, cmd) != 0) in ahc_run_tqinfifo()
7793 ahc_dmamap_sync(ahc, ahc->shared_data_dmat, in ahc_run_tqinfifo()
7794 ahc->shared_data_dmamap, in ahc_run_tqinfifo()
7795 ahc_targetcmd_offset(ahc, ahc->tqinfifonext), in ahc_run_tqinfifo()
7798 ahc->tqinfifonext++; in ahc_run_tqinfifo()
7804 if ((ahc->tqinfifonext & (HOST_TQINPOS - 1)) == 1) { in ahc_run_tqinfifo()
7805 if ((ahc->features & AHC_HS_MAILBOX) != 0) { in ahc_run_tqinfifo()
7808 hs_mailbox = ahc_inb(ahc, HS_MAILBOX); in ahc_run_tqinfifo()
7810 hs_mailbox |= ahc->tqinfifonext & HOST_TQINPOS; in ahc_run_tqinfifo()
7811 ahc_outb(ahc, HS_MAILBOX, hs_mailbox); in ahc_run_tqinfifo()
7814 ahc_pause(ahc); in ahc_run_tqinfifo()
7815 ahc_outb(ahc, KERNEL_TQINPOS, in ahc_run_tqinfifo()
7816 ahc->tqinfifonext & HOST_TQINPOS); in ahc_run_tqinfifo()
7818 ahc_unpause(ahc); in ahc_run_tqinfifo()
7825 ahc_handle_target_cmd(struct ahc_softc *ahc, struct target_cmd *cmd) in ahc_handle_target_cmd() argument
7835 initiator = SCSIID_TARGET(ahc, cmd->scsiid); in ahc_handle_target_cmd()
7840 tstate = ahc->enabled_targets[target]; in ahc_handle_target_cmd()
7849 lstate = ahc->black_hole; in ahc_handle_target_cmd()
7853 ahc->flags |= AHC_TQINFIFO_BLOCKED; in ahc_handle_target_cmd()
7858 printk("%s: ATIOs exhausted\n", ahc_name(ahc)); in ahc_handle_target_cmd()
7861 ahc->flags &= ~AHC_TQINFIFO_BLOCKED; in ahc_handle_target_cmd()
7865 lstate == ahc->black_hole ? "(Black Holed)" : ""); in ahc_handle_target_cmd()
7869 if (lstate == ahc->black_hole) { in ahc_handle_target_cmd()
7927 initiator, target, lun, ahc->pending_device); in ahc_handle_target_cmd()
7929 ahc->pending_device = lstate; in ahc_handle_target_cmd()