ahc_loadseq(struct ahc_softc *ahc) { struct	cs cs_table[num_critical_sections]; u_int	begin_set[num_critical_sections]; u_int	end_set[num_critical_sections]; struct	patch *cur_patch; u_int	cs_count; u_int	cur_cs; u_int	i; int	downloaded; u_int	skip_addr; u_int	sg_prefetch_cnt; uint8_t	download_consts[7];
STATIC void	ahc_loadseq __P((struct ahc_softc *ahc)); STATIC int	ahc_check_patch __P((struct ahc_softc *ahc, struct patch **start_patch, int start_instr, int *skip_addr)); STATIC void	ahc_download_instr __P((struct ahc_softc *ahc, int instrptr, u_int8_t *dconsts)); STATIC int	ahc_match_scb __P((struct scb *scb, int target, char channel, int lun, u_int tag, role_t role)); #ifdef AHC_DEBUG STATIC void	ahc_print_scb __P((struct scb *scb)); #endif STATIC int	ahc_search_qinfifo __P((struct ahc_softc *ahc, int target, char channel, int lun, u_int tag, role_t role, u_int32_t status, ahc_search_action action)); STATIC int	ahc_reset_channel __P((struct ahc_softc *ahc, char channel, int initiate_reset)); STATIC int	ahc_abort_scbs __P((struct ahc_softc *ahc, int target, char channel, int lun, u_int tag, role_t role, u_int32_t status)); STATIC int	ahc_search_disc_list __P((struct ahc_softc *ahc, int target, char channel, int lun, u_int tag, int stop_on_first, int remove, int save_state)); STATIC u_int	ahc_rem_scb_from_disc_list __P((struct ahc_softc *ahc, u_int prev, u_int scbptr)); STATIC void	ahc_add_curscb_to_free_list __P((struct ahc_softc *ahc)); STATIC void	ahc_clear_intstat __P((struct ahc_softc *ahc)); STATIC void	ahc_reset_current_bus __P((struct ahc_softc *ahc)); STATIC struct ahc_syncrate * ahc_devlimited_syncrate __P((struct ahc_softc *ahc, u_int *period)); STATIC struct ahc_syncrate * ahc_find_syncrate __P((struct ahc_softc *ahc, u_int *period, u_int maxsync)); STATIC u_int ahc_find_period __P((struct ahc_softc *ahc, u_int scsirate, u_int maxsync)); STATIC void	ahc_validate_offset __P((struct ahc_softc *ahc, struct ahc_syncrate *syncrate, u_int *offset, int wide)); STATIC void	ahc_update_target_msg_request __P((struct ahc_softc *ahc, struct ahc_devinfo *devinfo, struct ahc_initiator_tinfo *tinfo, int force, int paused)); STATIC void	ahc_set_syncrate __P((struct ahc_softc *ahc, struct ahc_devinfo *devinfo, struct ahc_syncrate *syncrate, u_int period, u_int offset, u_int type, int paused, int done)); STATIC void	ahc_set_width __P((struct ahc_softc *ahc, struct ahc_devinfo *devinfo, u_int width, u_int type, int paused, int done)); STATIC void	ahc_set_tags __P((struct ahc_softc *ahc, struct ahc_devinfo *devinfo,int enable)); STATIC int      ahc_istagged_device __P((struct ahc_softc *ahc, struct scsi_xfer *xs, int nocmdcheck)); STATIC void     ahc_check_tags __P((struct ahc_softc *ahc, struct scsi_xfer *xs)); STATIC void	ahc_construct_sdtr __P((struct ahc_softc *ahc, u_int period, u_int offset)); STATIC void	ahc_construct_wdtr __P((struct ahc_softc *ahc, u_int bus_width));  STATIC void	ahc_calc_residual __P((struct scb *scb));  STATIC void	ahc_update_pending_syncrates __P((struct ahc_softc *ahc));  STATIC void	ahc_set_recoveryscb __P((struct ahc_softc *ahc, struct scb *scb)); STATIC void ahc_timeout __P((void *));  static __inline int  sequencer_paused __P((struct ahc_softc *ahc)); static __inline void pause_sequencer __P((struct ahc_softc *ahc)); static __inline void unpause_sequencer __P((struct ahc_softc *ahc)); STATIC void restart_sequencer __P((struct ahc_softc *ahc)); static __inline u_int ahc_index_busy_tcl __P((struct ahc_softc *ahc, u_int tcl, int unbusy));  static __inline void	ahc_busy_tcl __P((struct ahc_softc *ahc, struct scb *scb)); static __inline int	ahc_isbusy_tcl __P((struct ahc_softc *ahc, struct scb *scb)); static __inline void ahc_freeze_ccb __P((struct scb* scb)); 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, };   static struct scsi_device ahc_dev = { NULL,  NULL,  NULL,  NULL,  };  static __inline void ahc_swap_hscb(struct hardware_scb *hscb) { hscb->SG_pointer = htole32(hscb->SG_pointer); hscb->data = htole32(hscb->data); hscb->datalen = htole32(hscb->datalen);
ahc_loadseq(struct ahc_softc *ahc){	struct	cs cs_table[num_critical_sections];	u_int	begin_set[num_critical_sections];	u_int	end_set[num_critical_sections];	struct	patch *cur_patch;	u_int	cs_count;	u_int	cur_cs;	u_int	i;	int	downloaded;	u_int	skip_addr;	u_int	sg_prefetch_cnt;	uint8_t	download_consts[7];	/*	 * Start out with 0 critical sections	 * that apply to this firmware load.	 */	cs_count = 0;	cur_cs = 0;	memset(begin_set, 0, sizeof(begin_set));	memset(end_set, 0, sizeof(end_set));	/* Setup downloadable constant table */	download_consts[QOUTFIFO_OFFSET] = 0;	if (ahc->targetcmds != NULL)		download_consts[QOUTFIFO_OFFSET] += 32;	download_consts[QINFIFO_OFFSET] = download_consts[QOUTFIFO_OFFSET] + 1;	download_consts[CACHESIZE_MASK] = ahc->pci_cachesize - 1;	download_consts[INVERTED_CACHESIZE_MASK] = ~(ahc->pci_cachesize - 1);	sg_prefetch_cnt = ahc->pci_cachesize;	if (sg_prefetch_cnt < (2 * sizeof(struct ahc_dma_seg)))		sg_prefetch_cnt = 2 * sizeof(struct ahc_dma_seg);	download_consts[SG_PREFETCH_CNT] = sg_prefetch_cnt;	download_consts[SG_PREFETCH_ALIGN_MASK] = ~(sg_prefetch_cnt - 1);	download_consts[SG_PREFETCH_ADDR_MASK] = (sg_prefetch_cnt - 1);	cur_patch = patches;	downloaded = 0;	skip_addr = 0;	ahc_outb(ahc, SEQCTL, PERRORDIS|FAILDIS|FASTMODE|LOADRAM);	ahc_outb(ahc, SEQADDR0, 0);	ahc_outb(ahc, SEQADDR1, 0);	for (i = 0; i < sizeof(seqprog)/4; i++) {		if (ahc_check_patch(ahc, &cur_patch, i, &skip_addr) == 0) {			/*			 * Don't download this instruction as it			 * is in a patch that was removed.			 */			continue;		}		/*		 * Move through the CS table until we find a CS		 * that might apply to this instruction.		 */		for (; cur_cs < num_critical_sections; cur_cs++) {			if (critical_sections[cur_cs].end <= i) {				if (begin_set[cs_count] == TRUE				 && end_set[cs_count] == FALSE) {					cs_table[cs_count].end = downloaded;				 	end_set[cs_count] = TRUE;					cs_count++;				}				continue;			}			if (critical_sections[cur_cs].begin <= i			 && begin_set[cs_count] == FALSE) {				cs_table[cs_count].begin = downloaded;				begin_set[cs_count] = TRUE;			}			break;		}		ahc_download_instr(ahc, i, download_consts);		downloaded++;	}	ahc->num_critical_sections = cs_count;	if (cs_count != 0) {		cs_count *= sizeof(struct cs);		ahc->critical_sections = malloc(cs_count, M_DEVBUF, M_NOWAIT);		if (ahc->critical_sections == NULL)			panic("ahc_loadseq: Could not malloc");		memcpy(ahc->critical_sections, cs_table, cs_count);	}	ahc_outb(ahc, SEQCTL, PERRORDIS|FAILDIS|FASTMODE);	ahc_restart(ahc);	if (bootverbose)		printf(" %d instructions downloaded\n", downloaded);}