ahc_setup_initiator_msgout(struct ahc_softc *ahc, struct ahc_devinfo *devinfo, struct scb *scb) {
STATIC void	ahc_setup_initiator_msgout __P((struct ahc_softc *ahc, struct ahc_devinfo *devinfo, struct scb *scb)); STATIC void	ahc_setup_target_msgin __P((struct ahc_softc *ahc, struct ahc_devinfo *devinfo)); STATIC int	ahc_handle_msg_reject __P((struct ahc_softc *ahc, struct ahc_devinfo *devinfo)); STATIC void	ahc_clear_msg_state __P((struct ahc_softc *ahc)); STATIC void	ahc_handle_message_phase __P((struct ahc_softc *ahc, struct scsi_link *sc_link)); STATIC int	ahc_sent_msg __P((struct ahc_softc *ahc, u_int msgtype, int full));  typedef enum { MSGLOOP_IN_PROG, MSGLOOP_MSGCOMPLETE, MSGLOOP_TERMINATED } msg_loop_stat;  STATIC int	ahc_parse_msg __P((struct ahc_softc *ahc, struct scsi_link *sc_link, struct ahc_devinfo *devinfo)); STATIC void	ahc_handle_ign_wide_residue __P((struct ahc_softc *ahc, struct ahc_devinfo *devinfo)); STATIC void	ahc_handle_devreset __P((struct ahc_softc *ahc, struct ahc_devinfo *devinfo, int status, char *message, int verbose_level)); #ifdef AHC_DUMP_SEQ STATIC void	ahc_dumpseq __P((struct ahc_softc *ahc)); #endif 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_setup_initiator_msgout(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,			   struct scb *scb){	/*	 * To facilitate adding multiple messages together,	 * each routine should increment the index and len	 * variables instead of setting them explicitly.	 */	ahc->msgout_index = 0;	ahc->msgout_len = 0;	if ((scb->flags & SCB_DEVICE_RESET) == 0	 && ahc_inb(ahc, MSG_OUT) == MSG_IDENTIFYFLAG) {		u_int identify_msg;		identify_msg = MSG_IDENTIFYFLAG | SCB_GET_LUN(scb);		if ((scb->hscb->control & DISCENB) != 0)			identify_msg |= MSG_IDENTIFY_DISCFLAG;		ahc->msgout_buf[ahc->msgout_index++] = identify_msg;		ahc->msgout_len++;		if ((scb->hscb->control & TAG_ENB) != 0) {			ahc->msgout_buf[ahc->msgout_index++] =			    scb->hscb->control & (TAG_ENB|SCB_TAG_TYPE);			ahc->msgout_buf[ahc->msgout_index++] = scb->hscb->tag;			ahc->msgout_len += 2;		}	}	if (scb->flags & SCB_DEVICE_RESET) {		ahc->msgout_buf[ahc->msgout_index++] = MSG_BUS_DEV_RESET;		ahc->msgout_len++;		ahc_print_path(ahc, scb);		printf("Bus Device Reset Message Sent\n");		/*		 * Clear our selection hardware in advance of		 * the busfree.  We may have an entry in the waiting		 * Q for this target, and we don't want to go about		 * selecting while we handle the busfree and blow it		 * away.		 */		ahc_outb(ahc, SCSISEQ, (ahc_inb(ahc, SCSISEQ) & ~ENSELO));	} else if ((scb->flags & SCB_ABORT) != 0) {		if ((scb->hscb->control & TAG_ENB) != 0)			ahc->msgout_buf[ahc->msgout_index++] = MSG_ABORT_TAG;		else			ahc->msgout_buf[ahc->msgout_index++] = MSG_ABORT;		ahc->msgout_len++;		ahc_print_path(ahc, scb);		printf("Abort%s Message Sent\n",		       (scb->hscb->control & TAG_ENB) != 0 ? " Tag" : "");		/*		 * Clear our selection hardware in advance of		 * the busfree.  We may have an entry in the waiting		 * Q for this target, and we don't want to go about		 * selecting while we handle the busfree and blow it		 * away.		 */		ahc_outb(ahc, SCSISEQ, (ahc_inb(ahc, SCSISEQ) & ~ENSELO));	} else if ((scb->flags & (SCB_AUTO_NEGOTIATE|SCB_NEGOTIATE)) != 0) {		ahc_build_transfer_msg(ahc, devinfo);	} else {		printf("ahc_intr: AWAITING_MSG for an SCB that "		       "does not have a waiting message\n");		printf("SCSIID = %x, target_mask = %x\n", scb->hscb->scsiid,		       devinfo->target_mask);		panic("SCB = %d, SCB Control = %x, MSG_OUT = %x "		      "SCB flags = %x", scb->hscb->tag, scb->hscb->control,		      ahc_inb(ahc, MSG_OUT), scb->flags);	}	/*	 * Clear the MK_MESSAGE flag from the SCB so we aren't	 * asked to send this message again.	 */	ahc_outb(ahc, SCB_CONTROL, ahc_inb(ahc, SCB_CONTROL) & ~MK_MESSAGE);	scb->hscb->control &= ~MK_MESSAGE;	ahc->msgout_index = 0;	ahc->msg_type = MSG_TYPE_INITIATOR_MSGOUT;}