11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds * Inline routines shareable across OS platforms.
31da177e4SLinus Torvalds *
41da177e4SLinus Torvalds * Copyright (c) 1994-2001 Justin T. Gibbs.
51da177e4SLinus Torvalds * Copyright (c) 2000-2003 Adaptec Inc.
61da177e4SLinus Torvalds * All rights reserved.
71da177e4SLinus Torvalds *
81da177e4SLinus Torvalds * Redistribution and use in source and binary forms, with or without
91da177e4SLinus Torvalds * modification, are permitted provided that the following conditions
101da177e4SLinus Torvalds * are met:
111da177e4SLinus Torvalds * 1. Redistributions of source code must retain the above copyright
121da177e4SLinus Torvalds * notice, this list of conditions, and the following disclaimer,
131da177e4SLinus Torvalds * without modification.
141da177e4SLinus Torvalds * 2. Redistributions in binary form must reproduce at minimum a disclaimer
151da177e4SLinus Torvalds * substantially similar to the "NO WARRANTY" disclaimer below
161da177e4SLinus Torvalds * ("Disclaimer") and any redistribution must be conditioned upon
171da177e4SLinus Torvalds * including a substantially similar Disclaimer requirement for further
181da177e4SLinus Torvalds * binary redistribution.
191da177e4SLinus Torvalds * 3. Neither the names of the above-listed copyright holders nor the names
201da177e4SLinus Torvalds * of any contributors may be used to endorse or promote products derived
211da177e4SLinus Torvalds * from this software without specific prior written permission.
221da177e4SLinus Torvalds *
231da177e4SLinus Torvalds * Alternatively, this software may be distributed under the terms of the
241da177e4SLinus Torvalds * GNU General Public License ("GPL") version 2 as published by the Free
251da177e4SLinus Torvalds * Software Foundation.
261da177e4SLinus Torvalds *
271da177e4SLinus Torvalds * NO WARRANTY
281da177e4SLinus Torvalds * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
291da177e4SLinus Torvalds * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
301da177e4SLinus Torvalds * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
311da177e4SLinus Torvalds * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
321da177e4SLinus Torvalds * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
331da177e4SLinus Torvalds * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
341da177e4SLinus Torvalds * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
351da177e4SLinus Torvalds * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
361da177e4SLinus Torvalds * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
371da177e4SLinus Torvalds * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
381da177e4SLinus Torvalds * POSSIBILITY OF SUCH DAMAGES.
391da177e4SLinus Torvalds *
4053467e63SHannes Reinecke * $Id: //depot/aic7xxx/aic7xxx/aic79xx_inline.h#59 $
411da177e4SLinus Torvalds *
421da177e4SLinus Torvalds * $FreeBSD$
431da177e4SLinus Torvalds */
441da177e4SLinus Torvalds
451da177e4SLinus Torvalds #ifndef _AIC79XX_INLINE_H_
461da177e4SLinus Torvalds #define _AIC79XX_INLINE_H_
471da177e4SLinus Torvalds
481da177e4SLinus Torvalds /******************************** Debugging ***********************************/
49*1beb6fa8SHarvey Harrison static inline char *ahd_name(struct ahd_softc *ahd);
501da177e4SLinus Torvalds
ahd_name(struct ahd_softc * ahd)51*1beb6fa8SHarvey Harrison static inline char *ahd_name(struct ahd_softc *ahd)
521da177e4SLinus Torvalds {
531da177e4SLinus Torvalds return (ahd->name);
541da177e4SLinus Torvalds }
551da177e4SLinus Torvalds
561da177e4SLinus Torvalds /************************ Sequencer Execution Control *************************/
57*1beb6fa8SHarvey Harrison static inline void ahd_known_modes(struct ahd_softc *ahd,
581da177e4SLinus Torvalds ahd_mode src, ahd_mode dst);
59*1beb6fa8SHarvey Harrison static inline ahd_mode_state ahd_build_mode_state(struct ahd_softc *ahd,
601da177e4SLinus Torvalds ahd_mode src,
611da177e4SLinus Torvalds ahd_mode dst);
62*1beb6fa8SHarvey Harrison static inline void ahd_extract_mode_state(struct ahd_softc *ahd,
631da177e4SLinus Torvalds ahd_mode_state state,
641da177e4SLinus Torvalds ahd_mode *src, ahd_mode *dst);
65be0d6768SDenys Vlasenko
66be0d6768SDenys Vlasenko void ahd_set_modes(struct ahd_softc *ahd, ahd_mode src,
671da177e4SLinus Torvalds ahd_mode dst);
68be0d6768SDenys Vlasenko ahd_mode_state ahd_save_modes(struct ahd_softc *ahd);
69be0d6768SDenys Vlasenko void ahd_restore_modes(struct ahd_softc *ahd,
701da177e4SLinus Torvalds ahd_mode_state state);
71be0d6768SDenys Vlasenko int ahd_is_paused(struct ahd_softc *ahd);
72be0d6768SDenys Vlasenko void ahd_pause(struct ahd_softc *ahd);
73be0d6768SDenys Vlasenko void ahd_unpause(struct ahd_softc *ahd);
741da177e4SLinus Torvalds
75*1beb6fa8SHarvey Harrison static inline void
ahd_known_modes(struct ahd_softc * ahd,ahd_mode src,ahd_mode dst)761da177e4SLinus Torvalds ahd_known_modes(struct ahd_softc *ahd, ahd_mode src, ahd_mode dst)
771da177e4SLinus Torvalds {
781da177e4SLinus Torvalds ahd->src_mode = src;
791da177e4SLinus Torvalds ahd->dst_mode = dst;
801da177e4SLinus Torvalds ahd->saved_src_mode = src;
811da177e4SLinus Torvalds ahd->saved_dst_mode = dst;
821da177e4SLinus Torvalds }
831da177e4SLinus Torvalds
84*1beb6fa8SHarvey Harrison static inline ahd_mode_state
ahd_build_mode_state(struct ahd_softc * ahd,ahd_mode src,ahd_mode dst)851da177e4SLinus Torvalds ahd_build_mode_state(struct ahd_softc *ahd, ahd_mode src, ahd_mode dst)
861da177e4SLinus Torvalds {
871da177e4SLinus Torvalds return ((src << SRC_MODE_SHIFT) | (dst << DST_MODE_SHIFT));
881da177e4SLinus Torvalds }
891da177e4SLinus Torvalds
90*1beb6fa8SHarvey Harrison static inline void
ahd_extract_mode_state(struct ahd_softc * ahd,ahd_mode_state state,ahd_mode * src,ahd_mode * dst)911da177e4SLinus Torvalds ahd_extract_mode_state(struct ahd_softc *ahd, ahd_mode_state state,
921da177e4SLinus Torvalds ahd_mode *src, ahd_mode *dst)
931da177e4SLinus Torvalds {
941da177e4SLinus Torvalds *src = (state & SRC_MODE) >> SRC_MODE_SHIFT;
951da177e4SLinus Torvalds *dst = (state & DST_MODE) >> DST_MODE_SHIFT;
961da177e4SLinus Torvalds }
971da177e4SLinus Torvalds
981da177e4SLinus Torvalds /*********************** Scatter Gather List Handling *************************/
99be0d6768SDenys Vlasenko void *ahd_sg_setup(struct ahd_softc *ahd, struct scb *scb,
1001da177e4SLinus Torvalds void *sgptr, dma_addr_t addr,
1011da177e4SLinus Torvalds bus_size_t len, int last);
1021da177e4SLinus Torvalds
1031da177e4SLinus Torvalds /************************** Memory mapping routines ***************************/
104*1beb6fa8SHarvey Harrison static inline size_t ahd_sg_size(struct ahd_softc *ahd);
105be0d6768SDenys Vlasenko
106be0d6768SDenys Vlasenko void ahd_sync_sglist(struct ahd_softc *ahd,
1071da177e4SLinus Torvalds struct scb *scb, int op);
1081da177e4SLinus Torvalds
ahd_sg_size(struct ahd_softc * ahd)109*1beb6fa8SHarvey Harrison static inline size_t ahd_sg_size(struct ahd_softc *ahd)
1101da177e4SLinus Torvalds {
1111da177e4SLinus Torvalds if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0)
1121da177e4SLinus Torvalds return (sizeof(struct ahd_dma64_seg));
1131da177e4SLinus Torvalds return (sizeof(struct ahd_dma_seg));
1141da177e4SLinus Torvalds }
1151da177e4SLinus Torvalds
116b1c11812SJoe Perches /*********************** Miscellaneous Support Functions ***********************/
117be0d6768SDenys Vlasenko struct ahd_initiator_tinfo *
1181da177e4SLinus Torvalds ahd_fetch_transinfo(struct ahd_softc *ahd,
1191da177e4SLinus Torvalds char channel, u_int our_id,
1201da177e4SLinus Torvalds u_int remote_id,
1211da177e4SLinus Torvalds struct ahd_tmode_tstate **tstate);
122be0d6768SDenys Vlasenko uint16_t
1231da177e4SLinus Torvalds ahd_inw(struct ahd_softc *ahd, u_int port);
124be0d6768SDenys Vlasenko void ahd_outw(struct ahd_softc *ahd, u_int port,
1251da177e4SLinus Torvalds u_int value);
126be0d6768SDenys Vlasenko uint32_t
1271da177e4SLinus Torvalds ahd_inl(struct ahd_softc *ahd, u_int port);
128be0d6768SDenys Vlasenko void ahd_outl(struct ahd_softc *ahd, u_int port,
1291da177e4SLinus Torvalds uint32_t value);
130be0d6768SDenys Vlasenko uint64_t
1311da177e4SLinus Torvalds ahd_inq(struct ahd_softc *ahd, u_int port);
132be0d6768SDenys Vlasenko void ahd_outq(struct ahd_softc *ahd, u_int port,
1331da177e4SLinus Torvalds uint64_t value);
134be0d6768SDenys Vlasenko u_int ahd_get_scbptr(struct ahd_softc *ahd);
135be0d6768SDenys Vlasenko void ahd_set_scbptr(struct ahd_softc *ahd, u_int scbptr);
136be0d6768SDenys Vlasenko u_int ahd_inb_scbram(struct ahd_softc *ahd, u_int offset);
137be0d6768SDenys Vlasenko u_int ahd_inw_scbram(struct ahd_softc *ahd, u_int offset);
138be0d6768SDenys Vlasenko struct scb *
139be0d6768SDenys Vlasenko ahd_lookup_scb(struct ahd_softc *ahd, u_int tag);
140be0d6768SDenys Vlasenko void ahd_queue_scb(struct ahd_softc *ahd, struct scb *scb);
141be0d6768SDenys Vlasenko
142*1beb6fa8SHarvey Harrison static inline uint8_t *ahd_get_sense_buf(struct ahd_softc *ahd,
1431da177e4SLinus Torvalds struct scb *scb);
144*1beb6fa8SHarvey Harrison static inline uint32_t ahd_get_sense_bufaddr(struct ahd_softc *ahd,
1451da177e4SLinus Torvalds struct scb *scb);
1461da177e4SLinus Torvalds
147be0d6768SDenys Vlasenko #if 0 /* unused */
1481da177e4SLinus Torvalds
1491da177e4SLinus Torvalds #define AHD_COPY_COL_IDX(dst, src) \
1501da177e4SLinus Torvalds do { \
1511da177e4SLinus Torvalds dst->hscb->scsiid = src->hscb->scsiid; \
1521da177e4SLinus Torvalds dst->hscb->lun = src->hscb->lun; \
1531da177e4SLinus Torvalds } while (0)
1541da177e4SLinus Torvalds
1551da177e4SLinus Torvalds #endif
1561da177e4SLinus Torvalds
157*1beb6fa8SHarvey Harrison static inline uint8_t *
ahd_get_sense_buf(struct ahd_softc * ahd,struct scb * scb)1581da177e4SLinus Torvalds ahd_get_sense_buf(struct ahd_softc *ahd, struct scb *scb)
1591da177e4SLinus Torvalds {
1601da177e4SLinus Torvalds return (scb->sense_data);
1611da177e4SLinus Torvalds }
1621da177e4SLinus Torvalds
163*1beb6fa8SHarvey Harrison static inline uint32_t
ahd_get_sense_bufaddr(struct ahd_softc * ahd,struct scb * scb)1641da177e4SLinus Torvalds ahd_get_sense_bufaddr(struct ahd_softc *ahd, struct scb *scb)
1651da177e4SLinus Torvalds {
1661da177e4SLinus Torvalds return (scb->sense_busaddr);
1671da177e4SLinus Torvalds }
1681da177e4SLinus Torvalds
1691da177e4SLinus Torvalds /************************** Interrupt Processing ******************************/
170be0d6768SDenys Vlasenko int ahd_intr(struct ahd_softc *ahd);
1711da177e4SLinus Torvalds
1721da177e4SLinus Torvalds #endif /* _AIC79XX_INLINE_H_ */
173