⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aic79xx_inline.h

📁 linux-2.6.15.6
💻 H
📖 第 1 页 / 共 2 页
字号:
/* * Inline routines shareable across OS platforms. * * Copyright (c) 1994-2001 Justin T. Gibbs. * Copyright (c) 2000-2003 Adaptec Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions, and the following disclaimer, *    without modification. * 2. Redistributions in binary form must reproduce at minimum a disclaimer *    substantially similar to the "NO WARRANTY" disclaimer below *    ("Disclaimer") and any redistribution must be conditioned upon *    including a substantially similar Disclaimer requirement for further *    binary redistribution. * 3. Neither the names of the above-listed copyright holders nor the names *    of any contributors may be used to endorse or promote products derived *    from this software without specific prior written permission. * * Alternatively, this software may be distributed under the terms of the * GNU General Public License ("GPL") version 2 as published by the Free * Software Foundation. * * NO WARRANTY * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGES. * * $Id: //depot/aic7xxx/aic7xxx/aic79xx_inline.h#51 $ * * $FreeBSD$ */#ifndef _AIC79XX_INLINE_H_#define _AIC79XX_INLINE_H_/******************************** Debugging ***********************************/static __inline char *ahd_name(struct ahd_softc *ahd);static __inline char *ahd_name(struct ahd_softc *ahd){	return (ahd->name);}/************************ Sequencer Execution Control *************************/static __inline void ahd_known_modes(struct ahd_softc *ahd,				     ahd_mode src, ahd_mode dst);static __inline ahd_mode_state ahd_build_mode_state(struct ahd_softc *ahd,						    ahd_mode src,						    ahd_mode dst);static __inline void ahd_extract_mode_state(struct ahd_softc *ahd,					    ahd_mode_state state,					    ahd_mode *src, ahd_mode *dst);static __inline void ahd_set_modes(struct ahd_softc *ahd, ahd_mode src,				   ahd_mode dst);static __inline void ahd_update_modes(struct ahd_softc *ahd);static __inline void ahd_assert_modes(struct ahd_softc *ahd, ahd_mode srcmode,				      ahd_mode dstmode, const char *file,				      int line);static __inline ahd_mode_state ahd_save_modes(struct ahd_softc *ahd);static __inline void ahd_restore_modes(struct ahd_softc *ahd,				       ahd_mode_state state);static __inline int  ahd_is_paused(struct ahd_softc *ahd);static __inline void ahd_pause(struct ahd_softc *ahd);static __inline void ahd_unpause(struct ahd_softc *ahd);static __inline voidahd_known_modes(struct ahd_softc *ahd, ahd_mode src, ahd_mode dst){	ahd->src_mode = src;	ahd->dst_mode = dst;	ahd->saved_src_mode = src;	ahd->saved_dst_mode = dst;}static __inline ahd_mode_stateahd_build_mode_state(struct ahd_softc *ahd, ahd_mode src, ahd_mode dst){	return ((src << SRC_MODE_SHIFT) | (dst << DST_MODE_SHIFT));}static __inline voidahd_extract_mode_state(struct ahd_softc *ahd, ahd_mode_state state,		       ahd_mode *src, ahd_mode *dst){	*src = (state & SRC_MODE) >> SRC_MODE_SHIFT;	*dst = (state & DST_MODE) >> DST_MODE_SHIFT;}static __inline voidahd_set_modes(struct ahd_softc *ahd, ahd_mode src, ahd_mode dst){	if (ahd->src_mode == src && ahd->dst_mode == dst)		return;#ifdef AHD_DEBUG	if (ahd->src_mode == AHD_MODE_UNKNOWN	 || ahd->dst_mode == AHD_MODE_UNKNOWN)		panic("Setting mode prior to saving it.\n");	if ((ahd_debug & AHD_SHOW_MODEPTR) != 0)		printf("%s: Setting mode 0x%x\n", ahd_name(ahd),		       ahd_build_mode_state(ahd, src, dst));#endif	ahd_outb(ahd, MODE_PTR, ahd_build_mode_state(ahd, src, dst));	ahd->src_mode = src;	ahd->dst_mode = dst;}static __inline voidahd_update_modes(struct ahd_softc *ahd){	ahd_mode_state mode_ptr;	ahd_mode src;	ahd_mode dst;	mode_ptr = ahd_inb(ahd, MODE_PTR);#ifdef AHD_DEBUG	if ((ahd_debug & AHD_SHOW_MODEPTR) != 0)		printf("Reading mode 0x%x\n", mode_ptr);#endif	ahd_extract_mode_state(ahd, mode_ptr, &src, &dst);	ahd_known_modes(ahd, src, dst);}static __inline voidahd_assert_modes(struct ahd_softc *ahd, ahd_mode srcmode,		 ahd_mode dstmode, const char *file, int line){#ifdef AHD_DEBUG	if ((srcmode & AHD_MK_MSK(ahd->src_mode)) == 0	 || (dstmode & AHD_MK_MSK(ahd->dst_mode)) == 0) {		panic("%s:%s:%d: Mode assertion failed.\n",		       ahd_name(ahd), file, line);	}#endif}static __inline ahd_mode_stateahd_save_modes(struct ahd_softc *ahd){	if (ahd->src_mode == AHD_MODE_UNKNOWN	 || ahd->dst_mode == AHD_MODE_UNKNOWN)		ahd_update_modes(ahd);	return (ahd_build_mode_state(ahd, ahd->src_mode, ahd->dst_mode));}static __inline voidahd_restore_modes(struct ahd_softc *ahd, ahd_mode_state state){	ahd_mode src;	ahd_mode dst;	ahd_extract_mode_state(ahd, state, &src, &dst);	ahd_set_modes(ahd, src, dst);}#define AHD_ASSERT_MODES(ahd, source, dest) \	ahd_assert_modes(ahd, source, dest, __FILE__, __LINE__);/* * Determine whether the sequencer has halted code execution. * Returns non-zero status if the sequencer is stopped. */static __inline intahd_is_paused(struct ahd_softc *ahd){	return ((ahd_inb(ahd, HCNTRL) & PAUSE) != 0);}/* * Request that the sequencer stop and wait, indefinitely, for it * to stop.  The sequencer will only acknowledge that it is paused * once it has reached an instruction boundary and PAUSEDIS is * cleared in the SEQCTL register.  The sequencer may use PAUSEDIS * for critical sections. */static __inline voidahd_pause(struct ahd_softc *ahd){	ahd_outb(ahd, HCNTRL, ahd->pause);	/*	 * Since the sequencer can disable pausing in a critical section, we	 * must loop until it actually stops.	 */	while (ahd_is_paused(ahd) == 0)		;}/* * Allow the sequencer to continue program execution. * We check here to ensure that no additional interrupt * sources that would cause the sequencer to halt have been * asserted.  If, for example, a SCSI bus reset is detected * while we are fielding a different, pausing, interrupt type, * we don't want to release the sequencer before going back * into our interrupt handler and dealing with this new * condition. */static __inline voidahd_unpause(struct ahd_softc *ahd){	/*	 * Automatically restore our modes to those saved	 * prior to the first change of the mode.	 */	if (ahd->saved_src_mode != AHD_MODE_UNKNOWN	 && ahd->saved_dst_mode != AHD_MODE_UNKNOWN) {		if ((ahd->flags & AHD_UPDATE_PEND_CMDS) != 0)			ahd_reset_cmds_pending(ahd);		ahd_set_modes(ahd, ahd->saved_src_mode, ahd->saved_dst_mode);	}	if ((ahd_inb(ahd, INTSTAT) & ~CMDCMPLT) == 0)		ahd_outb(ahd, HCNTRL, ahd->unpause);	ahd_known_modes(ahd, AHD_MODE_UNKNOWN, AHD_MODE_UNKNOWN);}/*********************** Scatter Gather List Handling *************************/static __inline void	*ahd_sg_setup(struct ahd_softc *ahd, struct scb *scb,				      void *sgptr, dma_addr_t addr,				      bus_size_t len, int last);static __inline void	 ahd_setup_scb_common(struct ahd_softc *ahd,					      struct scb *scb);static __inline void	 ahd_setup_data_scb(struct ahd_softc *ahd,					    struct scb *scb);static __inline void	 ahd_setup_noxfer_scb(struct ahd_softc *ahd,					      struct scb *scb);static __inline void *ahd_sg_setup(struct ahd_softc *ahd, struct scb *scb,	     void *sgptr, dma_addr_t addr, bus_size_t len, int last){	scb->sg_count++;	if (sizeof(dma_addr_t) > 4	 && (ahd->flags & AHD_64BIT_ADDRESSING) != 0) {		struct ahd_dma64_seg *sg;		sg = (struct ahd_dma64_seg *)sgptr;		sg->addr = ahd_htole64(addr);		sg->len = ahd_htole32(len | (last ? AHD_DMA_LAST_SEG : 0));		return (sg + 1);	} else {		struct ahd_dma_seg *sg;		sg = (struct ahd_dma_seg *)sgptr;		sg->addr = ahd_htole32(addr & 0xFFFFFFFF);		sg->len = ahd_htole32(len | ((addr >> 8) & 0x7F000000)				    | (last ? AHD_DMA_LAST_SEG : 0));		return (sg + 1);	}}static __inline voidahd_setup_scb_common(struct ahd_softc *ahd, struct scb *scb){	/* XXX Handle target mode SCBs. */	scb->crc_retry_count = 0;	if ((scb->flags & SCB_PACKETIZED) != 0) {		/* XXX what about ACA??  It is type 4, but TAG_TYPE == 0x3. */		scb->hscb->task_attribute = scb->hscb->control & SCB_TAG_TYPE;	} else {		if (ahd_get_transfer_length(scb) & 0x01)			scb->hscb->task_attribute = SCB_XFERLEN_ODD;		else			scb->hscb->task_attribute = 0;	}	if (scb->hscb->cdb_len <= MAX_CDB_LEN_WITH_SENSE_ADDR	 || (scb->hscb->cdb_len & SCB_CDB_LEN_PTR) != 0)		scb->hscb->shared_data.idata.cdb_plus_saddr.sense_addr =		    ahd_htole32(scb->sense_busaddr);}static __inline voidahd_setup_data_scb(struct ahd_softc *ahd, struct scb *scb){	/*	 * Copy the first SG into the "current" data ponter area.	 */	if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0) {		struct ahd_dma64_seg *sg;		sg = (struct ahd_dma64_seg *)scb->sg_list;		scb->hscb->dataptr = sg->addr;		scb->hscb->datacnt = sg->len;	} else {		struct ahd_dma_seg *sg;		uint32_t *dataptr_words;		sg = (struct ahd_dma_seg *)scb->sg_list;		dataptr_words = (uint32_t*)&scb->hscb->dataptr;		dataptr_words[0] = sg->addr;		dataptr_words[1] = 0;		if ((ahd->flags & AHD_39BIT_ADDRESSING) != 0) {			uint64_t high_addr;			high_addr = ahd_le32toh(sg->len) & 0x7F000000;			scb->hscb->dataptr |= ahd_htole64(high_addr << 8);		}		scb->hscb->datacnt = sg->len;	}	/*	 * Note where to find the SG entries in bus space.	 * We also set the full residual flag which the 	 * sequencer will clear as soon as a data transfer	 * occurs.	 */	scb->hscb->sgptr = ahd_htole32(scb->sg_list_busaddr|SG_FULL_RESID);}static __inline voidahd_setup_noxfer_scb(struct ahd_softc *ahd, struct scb *scb){	scb->hscb->sgptr = ahd_htole32(SG_LIST_NULL);	scb->hscb->dataptr = 0;	scb->hscb->datacnt = 0;}/************************** Memory mapping routines ***************************/static __inline size_t	ahd_sg_size(struct ahd_softc *ahd);static __inline void *			ahd_sg_bus_to_virt(struct ahd_softc *ahd,					   struct scb *scb,					   uint32_t sg_busaddr);static __inline uint32_t			ahd_sg_virt_to_bus(struct ahd_softc *ahd,					   struct scb *scb,					   void *sg);static __inline void	ahd_sync_scb(struct ahd_softc *ahd,				     struct scb *scb, int op);static __inline void	ahd_sync_sglist(struct ahd_softc *ahd,					struct scb *scb, int op);static __inline void	ahd_sync_sense(struct ahd_softc *ahd,				       struct scb *scb, int op);static __inline uint32_t			ahd_targetcmd_offset(struct ahd_softc *ahd,					     u_int index);static __inline size_tahd_sg_size(struct ahd_softc *ahd){	if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0)		return (sizeof(struct ahd_dma64_seg));	return (sizeof(struct ahd_dma_seg));}static __inline void *ahd_sg_bus_to_virt(struct ahd_softc *ahd, struct scb *scb, uint32_t sg_busaddr){	dma_addr_t sg_offset;	/* sg_list_phys points to entry 1, not 0 */	sg_offset = sg_busaddr - (scb->sg_list_busaddr - ahd_sg_size(ahd));	return ((uint8_t *)scb->sg_list + sg_offset);}static __inline uint32_tahd_sg_virt_to_bus(struct ahd_softc *ahd, struct scb *scb, void *sg){	dma_addr_t sg_offset;	/* sg_list_phys points to entry 1, not 0 */	sg_offset = ((uint8_t *)sg - (uint8_t *)scb->sg_list)		  - ahd_sg_size(ahd);	return (scb->sg_list_busaddr + sg_offset);}static __inline voidahd_sync_scb(struct ahd_softc *ahd, struct scb *scb, int op){	ahd_dmamap_sync(ahd, ahd->scb_data.hscb_dmat,			scb->hscb_map->dmamap,			/*offset*/(uint8_t*)scb->hscb - scb->hscb_map->vaddr,			/*len*/sizeof(*scb->hscb), op);}static __inline voidahd_sync_sglist(struct ahd_softc *ahd, struct scb *scb, int op){	if (scb->sg_count == 0)		return;	ahd_dmamap_sync(ahd, ahd->scb_data.sg_dmat,			scb->sg_map->dmamap,			/*offset*/scb->sg_list_busaddr - ahd_sg_size(ahd),			/*len*/ahd_sg_size(ahd) * scb->sg_count, op);}static __inline voidahd_sync_sense(struct ahd_softc *ahd, struct scb *scb, int op){	ahd_dmamap_sync(ahd, ahd->scb_data.sense_dmat,			scb->sense_map->dmamap,			/*offset*/scb->sense_busaddr,			/*len*/AHD_SENSE_BUFSIZE, op);}static __inline uint32_tahd_targetcmd_offset(struct ahd_softc *ahd, u_int index){	return (((uint8_t *)&ahd->targetcmds[index])	       - (uint8_t *)ahd->qoutfifo);}/*********************** Miscelaneous Support Functions ***********************/static __inline void	ahd_complete_scb(struct ahd_softc *ahd,					 struct scb *scb);static __inline void	ahd_update_residual(struct ahd_softc *ahd,					    struct scb *scb);static __inline struct ahd_initiator_tinfo *			ahd_fetch_transinfo(struct ahd_softc *ahd,					    char channel, u_int our_id,					    u_int remote_id,					    struct ahd_tmode_tstate **tstate);static __inline uint16_t			ahd_inw(struct ahd_softc *ahd, u_int port);static __inline void	ahd_outw(struct ahd_softc *ahd, u_int port,				 u_int value);static __inline uint32_t			ahd_inl(struct ahd_softc *ahd, u_int port);static __inline void	ahd_outl(struct ahd_softc *ahd, u_int port,				 uint32_t value);static __inline uint64_t			ahd_inq(struct ahd_softc *ahd, u_int port);static __inline void	ahd_outq(struct ahd_softc *ahd, u_int port,				 uint64_t value);static __inline u_int	ahd_get_scbptr(struct ahd_softc *ahd);static __inline void	ahd_set_scbptr(struct ahd_softc *ahd, u_int scbptr);static __inline u_int	ahd_get_hnscb_qoff(struct ahd_softc *ahd);static __inline void	ahd_set_hnscb_qoff(struct ahd_softc *ahd, u_int value);static __inline u_int	ahd_get_hescb_qoff(struct ahd_softc *ahd);static __inline void	ahd_set_hescb_qoff(struct ahd_softc *ahd, u_int value);static __inline u_int	ahd_get_snscb_qoff(struct ahd_softc *ahd);static __inline void	ahd_set_snscb_qoff(struct ahd_softc *ahd, u_int value);static __inline u_int	ahd_get_sescb_qoff(struct ahd_softc *ahd);static __inline void	ahd_set_sescb_qoff(struct ahd_softc *ahd, u_int value);static __inline u_int	ahd_get_sdscb_qoff(struct ahd_softc *ahd);static __inline void	ahd_set_sdscb_qoff(struct ahd_softc *ahd, u_int value);static __inline u_int	ahd_inb_scbram(struct ahd_softc *ahd, u_int offset);static __inline u_int	ahd_inw_scbram(struct ahd_softc *ahd, u_int offset);static __inline uint32_t			ahd_inl_scbram(struct ahd_softc *ahd, u_int offset);static __inline uint64_t			ahd_inq_scbram(struct ahd_softc *ahd, u_int offset);static __inline void	ahd_swap_with_next_hscb(struct ahd_softc *ahd,						struct scb *scb);static __inline void	ahd_queue_scb(struct ahd_softc *ahd, struct scb *scb);static __inline uint8_t *			ahd_get_sense_buf(struct ahd_softc *ahd,					  struct scb *scb);static __inline uint32_t			ahd_get_sense_bufaddr(struct ahd_softc *ahd,					      struct scb *scb);static __inline voidahd_complete_scb(struct ahd_softc *ahd, struct scb *scb){	uint32_t sgptr;	sgptr = ahd_le32toh(scb->hscb->sgptr);	if ((sgptr & SG_STATUS_VALID) != 0)		ahd_handle_scb_status(ahd, scb);	else		ahd_done(ahd, scb);}/* * Determine whether the sequencer reported a residual

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -