USB: Add Vendor/Product ID for new CDMA U727 to option driver
[safe/jmp/linux-2.6] / drivers / scsi / aic7xxx / aic79xx_inline.h
1 /*
2  * Inline routines shareable across OS platforms.
3  *
4  * Copyright (c) 1994-2001 Justin T. Gibbs.
5  * Copyright (c) 2000-2003 Adaptec Inc.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions, and the following disclaimer,
13  *    without modification.
14  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
15  *    substantially similar to the "NO WARRANTY" disclaimer below
16  *    ("Disclaimer") and any redistribution must be conditioned upon
17  *    including a substantially similar Disclaimer requirement for further
18  *    binary redistribution.
19  * 3. Neither the names of the above-listed copyright holders nor the names
20  *    of any contributors may be used to endorse or promote products derived
21  *    from this software without specific prior written permission.
22  *
23  * Alternatively, this software may be distributed under the terms of the
24  * GNU General Public License ("GPL") version 2 as published by the Free
25  * Software Foundation.
26  *
27  * NO WARRANTY
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
31  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
36  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
37  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38  * POSSIBILITY OF SUCH DAMAGES.
39  *
40  * $Id: //depot/aic7xxx/aic7xxx/aic79xx_inline.h#59 $
41  *
42  * $FreeBSD$
43  */
44
45 #ifndef _AIC79XX_INLINE_H_
46 #define _AIC79XX_INLINE_H_
47
48 /******************************** Debugging ***********************************/
49 static __inline char *ahd_name(struct ahd_softc *ahd);
50
51 static __inline char *
52 ahd_name(struct ahd_softc *ahd)
53 {
54         return (ahd->name);
55 }
56
57 /************************ Sequencer Execution Control *************************/
58 static __inline void ahd_known_modes(struct ahd_softc *ahd,
59                                      ahd_mode src, ahd_mode dst);
60 static __inline ahd_mode_state ahd_build_mode_state(struct ahd_softc *ahd,
61                                                     ahd_mode src,
62                                                     ahd_mode dst);
63 static __inline void ahd_extract_mode_state(struct ahd_softc *ahd,
64                                             ahd_mode_state state,
65                                             ahd_mode *src, ahd_mode *dst);
66
67 void ahd_set_modes(struct ahd_softc *ahd, ahd_mode src,
68                    ahd_mode dst);
69 ahd_mode_state ahd_save_modes(struct ahd_softc *ahd);
70 void ahd_restore_modes(struct ahd_softc *ahd,
71                        ahd_mode_state state);
72 int  ahd_is_paused(struct ahd_softc *ahd);
73 void ahd_pause(struct ahd_softc *ahd);
74 void ahd_unpause(struct ahd_softc *ahd);
75
76 static __inline void
77 ahd_known_modes(struct ahd_softc *ahd, ahd_mode src, ahd_mode dst)
78 {
79         ahd->src_mode = src;
80         ahd->dst_mode = dst;
81         ahd->saved_src_mode = src;
82         ahd->saved_dst_mode = dst;
83 }
84
85 static __inline ahd_mode_state
86 ahd_build_mode_state(struct ahd_softc *ahd, ahd_mode src, ahd_mode dst)
87 {
88         return ((src << SRC_MODE_SHIFT) | (dst << DST_MODE_SHIFT));
89 }
90
91 static __inline void
92 ahd_extract_mode_state(struct ahd_softc *ahd, ahd_mode_state state,
93                        ahd_mode *src, ahd_mode *dst)
94 {
95         *src = (state & SRC_MODE) >> SRC_MODE_SHIFT;
96         *dst = (state & DST_MODE) >> DST_MODE_SHIFT;
97 }
98
99 /*********************** Scatter Gather List Handling *************************/
100 void    *ahd_sg_setup(struct ahd_softc *ahd, struct scb *scb,
101                       void *sgptr, dma_addr_t addr,
102                       bus_size_t len, int last);
103
104 /************************** Memory mapping routines ***************************/
105 static __inline size_t  ahd_sg_size(struct ahd_softc *ahd);
106
107 void    ahd_sync_sglist(struct ahd_softc *ahd,
108                         struct scb *scb, int op);
109
110 static __inline size_t
111 ahd_sg_size(struct ahd_softc *ahd)
112 {
113         if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0)
114                 return (sizeof(struct ahd_dma64_seg));
115         return (sizeof(struct ahd_dma_seg));
116 }
117
118 /*********************** Miscellaneous Support Functions ***********************/
119 struct ahd_initiator_tinfo *
120         ahd_fetch_transinfo(struct ahd_softc *ahd,
121                             char channel, u_int our_id,
122                             u_int remote_id,
123                             struct ahd_tmode_tstate **tstate);
124 uint16_t
125         ahd_inw(struct ahd_softc *ahd, u_int port);
126 void    ahd_outw(struct ahd_softc *ahd, u_int port,
127                  u_int value);
128 uint32_t
129         ahd_inl(struct ahd_softc *ahd, u_int port);
130 void    ahd_outl(struct ahd_softc *ahd, u_int port,
131                  uint32_t value);
132 uint64_t
133         ahd_inq(struct ahd_softc *ahd, u_int port);
134 void    ahd_outq(struct ahd_softc *ahd, u_int port,
135                  uint64_t value);
136 u_int   ahd_get_scbptr(struct ahd_softc *ahd);
137 void    ahd_set_scbptr(struct ahd_softc *ahd, u_int scbptr);
138 u_int   ahd_inb_scbram(struct ahd_softc *ahd, u_int offset);
139 u_int   ahd_inw_scbram(struct ahd_softc *ahd, u_int offset);
140 struct scb *
141         ahd_lookup_scb(struct ahd_softc *ahd, u_int tag);
142 void    ahd_queue_scb(struct ahd_softc *ahd, struct scb *scb);
143
144 static __inline uint8_t *
145                         ahd_get_sense_buf(struct ahd_softc *ahd,
146                                           struct scb *scb);
147 static __inline uint32_t
148                         ahd_get_sense_bufaddr(struct ahd_softc *ahd,
149                                               struct scb *scb);
150
151 #if 0 /* unused */
152
153 #define AHD_COPY_COL_IDX(dst, src)                              \
154 do {                                                            \
155         dst->hscb->scsiid = src->hscb->scsiid;                  \
156         dst->hscb->lun = src->hscb->lun;                        \
157 } while (0)
158
159 #endif
160
161 static __inline uint8_t *
162 ahd_get_sense_buf(struct ahd_softc *ahd, struct scb *scb)
163 {
164         return (scb->sense_data);
165 }
166
167 static __inline uint32_t
168 ahd_get_sense_bufaddr(struct ahd_softc *ahd, struct scb *scb)
169 {
170         return (scb->sense_busaddr);
171 }
172
173 /************************** Interrupt Processing ******************************/
174 int     ahd_intr(struct ahd_softc *ahd);
175
176 #endif  /* _AIC79XX_INLINE_H_ */