ahc_bus_dmamap_sync(ahc->sc_dmat, ahc->shared_data_dmamap,
bus_dmamap_sync(ahc->sc_dmat, ahc->shared_data_dmamap,
static __inline void ahcsetccbstatus __P((struct scsi_xfer *xs, int status));STATIC void ahc_run_qoutfifo __P((struct ahc_softc *ahc));static __inline struct ahc_initiator_tinfo *	ahc_fetch_transinfo __P((struct ahc_softc *ahc, char channel,				 u_int our_id, u_int target,				 struct tmode_tstate **tstate));STATIC void ahcfreescb __P((struct ahc_softc *ahc, struct scb *scb));static __inline struct scb *ahcgetscb __P((struct ahc_softc *ahc));int    ahc_createdmamem __P((struct ahc_softc *ahc, int size,			     bus_dmamap_t *mapp, caddr_t *vaddr,			     bus_addr_t *baddr, bus_dma_segment_t *segs,			     int *nseg, const char *what));STATIC void ahc_freedmamem __P((bus_dma_tag_t tag, int size,				bus_dmamap_t map, caddr_t vaddr,				bus_dma_segment_t *seg, int nseg));STATIC void ahcminphys __P((struct buf *bp));STATIC INLINE	struct scsi_xfer *ahc_first_xs __P((struct ahc_softc *));STATIC INLINE	void   ahc_list_insert_before __P((struct ahc_softc *ahc,						   struct scsi_xfer *xs,						   struct scsi_xfer *next_xs));STATIC INLINE	void   ahc_list_insert_head __P((struct ahc_softc *ahc,						 struct scsi_xfer *xs));STATIC INLINE	void   ahc_list_insert_tail __P((struct ahc_softc *ahc,						 struct scsi_xfer *xs));STATIC INLINE	void   ahc_list_remove __P((struct ahc_softc *ahc,					    struct scsi_xfer *xs));STATIC INLINE	struct scsi_xfer *ahc_list_next __P((struct ahc_softc *ahc,						     struct scsi_xfer *xs));STATIC int32_t ahc_scsi_cmd __P((struct scsi_xfer *xs));static __inline void ahc_swap_hscb __P((struct hardware_scb *));static __inline void ahc_swap_sg __P((struct ahc_dma_seg *));struct cfdriver ahc_cd = {	NULL, "ahc", DV_DULL};static struct scsi_adapter ahc_switch ={	ahc_scsi_cmd,	ahcminphys,	0,	0,};/* the below structure is so we have a default dev struct for our link struct */static struct scsi_device ahc_dev ={	NULL, /* Use default error handler */	NULL, /* have a queue, served by this */	NULL, /* have no async handler */	NULL, /* Use default 'done' routine */};static __inline voidahc_swap_hscb(struct hardware_scb *hscb){	hscb->SG_pointer = htole32(hscb->SG_pointer);	hscb->data = htole32(hscb->data);	hscb->datalen = htole32(hscb->datalen);	/*	 * No need to swap cmdpointer; it's either 0 or set to	 * cmdstore_busaddr, which is already swapped.	 */}static __inline voidahc_swap_sg(struct ahc_dma_seg *sg){	sg->addr = htole32(sg->addr);	sg->len = htole32(sg->len);}STATIC voidahcminphys(bp)	struct buf *bp;{/* * Even though the card can transfer up to 16megs per command * we are limited by the number of segments in the dma segment * list that we can hold.  The worst case is that all pages are * discontinuous physically, hense the "page per segment" limit * enforced here. */	if (bp->b_bcount > ((AHC_NSEG - 1) * PAGE_SIZE)) {		bp->b_bcount = ((AHC_NSEG - 1) * PAGE_SIZE);	}	minphys(bp);}static __inline u_int32_tahc_hscb_busaddr(struct ahc_softc *ahc, u_int index){	return (ahc->scb_data->hscb_busaddr		+ (sizeof(struct hardware_scb) * index));}#define AHC_BUSRESET_DELAY	25	/* Reset delay in us */static __inline intsequencer_paused(ahc)	struct ahc_softc *ahc;{	return ((ahc_inb(ahc, HCNTRL) & PAUSE) != 0);}static __inline voidpause_sequencer(ahc)	struct ahc_softc *ahc;{	ahc_outb(ahc, HCNTRL, ahc->pause);	/*	 * Since the sequencer can disable pausing in a critical section, we	 * must loop until it actually stops.	 */	while (sequencer_paused(ahc) == 0)		;}static __inline voidunpause_sequencer(ahc)	struct ahc_softc *ahc;{	if ((ahc_inb(ahc, INTSTAT) & (SCSIINT | SEQINT | BRKADRINT)) == 0)		ahc_outb(ahc, HCNTRL, ahc->unpause);}/* * Restart the sequencer program from address zero */STATIC voidrestart_sequencer(ahc)	struct ahc_softc *ahc;{	u_int i;	pause_sequencer(ahc);	/*	 * Everytime we restart the sequencer, there	 * is the possiblitity that we have restarted	 * within a three instruction window where an	 * SCB has been marked free but has not made it	 * onto the free list.  Since SCSI events(bus reset,	 * unexpected bus free) will always freeze the	 * sequencer, we cannot close this window.  To	 * avoid losing an SCB, we reconsitute the free	 * list every time we restart the sequencer.	 */	ahc_outb(ahc, FREE_SCBH, SCB_LIST_NULL);	for (i = 0; i < ahc->scb_data->maxhscbs; i++) {				ahc_outb(ahc, SCBPTR, i);		if (ahc_inb(ahc, SCB_TAG) == SCB_LIST_NULL)			ahc_add_curscb_to_free_list(ahc);	}	ahc_outb(ahc, SEQCTL, FASTMODE|SEQRESET);	unpause_sequencer(ahc);}static __inline u_intahc_index_busy_tcl(ahc, tcl, unbusy)	struct ahc_softc *ahc;	u_int tcl;	int unbusy;{	u_int scbid;	scbid = ahc->untagged_scbs[tcl];	if (unbusy) {		ahc->untagged_scbs[tcl] = SCB_LIST_NULL;		ahc_bus_dmamap_sync(ahc->sc_dmat, ahc->shared_data_dmamap,		    UNTAGGEDSCB_OFFSET * 256, 256, BUS_DMASYNC_PREWRITE);	}	return (scbid);}static __inline voidahc_busy_tcl(ahc, scb)	struct ahc_softc *ahc;	struct scb *scb;{	ahc->untagged_scbs[scb->hscb->tcl] = scb->hscb->tag;	ahc_bus_dmamap_sync(ahc->sc_dmat, ahc->shared_data_dmamap, 	    UNTAGGEDSCB_OFFSET * 256, 256, BUS_DMASYNC_PREWRITE);}static __inline intahc_isbusy_tcl(ahc, scb)	struct ahc_softc *ahc;	struct scb *scb;{	return ahc->untagged_scbs[scb->hscb->tcl] != SCB_LIST_NULL;}static __inline voidahc_freeze_ccb(scb)	struct scb *scb;{	struct scsi_xfer *xs = scb->xs;	struct ahc_softc *ahc = (struct ahc_softc *)xs->sc_link->adapter_softc;	int target;	target = xs->sc_link->target;	if (!(scb->flags & SCB_FREEZE_QUEUE)) {		ahc->devqueue_blocked[target]++;		scb->flags |= SCB_FREEZE_QUEUE;	}}static __inline voidahcsetccbstatus(xs, status)	struct scsi_xfer *xs;	int status;{	xs->error = status;}