]> CyberLeo.Net >> Repos - FreeBSD/releng/8.0.git/blob - sys/dev/aic7xxx/aic79xx_osm.h
Adjust to reflect 8.0-RELEASE.
[FreeBSD/releng/8.0.git] / sys / dev / aic7xxx / aic79xx_osm.h
1 /*-
2  * FreeBSD platform specific driver option settings, data structures,
3  * function declarations and includes.
4  *
5  * Copyright (c) 1994-2001 Justin T. Gibbs.
6  * Copyright (c) 2001-2002 Adaptec Inc.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions, and the following disclaimer,
14  *    without modification.
15  * 2. The name of the author may not be used to endorse or promote products
16  *    derived from this software without specific prior written permission.
17  *
18  * Alternatively, this software may be distributed under the terms of the
19  * GNU Public License ("GPL").
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
25  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  * $Id: //depot/aic7xxx/freebsd/dev/aic7xxx/aic79xx_osm.h#23 $
34  *
35  * $FreeBSD$
36  */
37
38 #ifndef _AIC79XX_FREEBSD_H_
39 #define _AIC79XX_FREEBSD_H_
40
41 #include <opt_aic79xx.h>        /* for config options */
42
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/bus.h>            /* For device_t */
46 #if __FreeBSD_version >= 500000
47 #include <sys/endian.h>
48 #endif
49 #include <sys/eventhandler.h>
50 #include <sys/kernel.h>
51 #include <sys/malloc.h>
52 #include <sys/module.h>
53 #include <sys/queue.h>
54
55 #define AIC_PCI_CONFIG 1
56 #include <machine/bus.h>
57 #include <machine/endian.h>
58 #include <machine/resource.h>
59
60 #include <sys/rman.h>
61
62 #if __FreeBSD_version >= 500000
63 #include <dev/pci/pcireg.h>
64 #include <dev/pci/pcivar.h>
65 #else
66 #include <pci/pcireg.h>
67 #include <pci/pcivar.h>
68 #endif
69
70 #include <cam/cam.h>
71 #include <cam/cam_ccb.h>
72 #include <cam/cam_debug.h>
73 #include <cam/cam_sim.h>
74 #include <cam/cam_xpt_sim.h>
75
76 #include <cam/scsi/scsi_all.h>
77 #include <cam/scsi/scsi_message.h>
78 #include <cam/scsi/scsi_iu.h>
79
80 /****************************** Platform Macros *******************************/
81 #define SIM_IS_SCSIBUS_B(ahd, sim)      \
82         (0)
83 #define SIM_CHANNEL(ahd, sim)   \
84         ('A')
85 #define SIM_SCSI_ID(ahd, sim)   \
86         (ahd->our_id)
87 #define SIM_PATH(ahd, sim)      \
88         (ahd->platform_data->path)
89 #define BUILD_SCSIID(ahd, sim, target_id, our_id) \
90         ((((target_id) << TID_SHIFT) & TID) | (our_id))
91         
92
93 #define SCB_GET_SIM(ahd, scb) \
94         ((ahd)->platform_data->sim)
95
96 #ifndef offsetof
97 #define offsetof(type, member)  ((size_t)(&((type *)0)->member))
98 #endif
99
100 /************************ Tunable Driver Parameters  **************************/
101 /*
102  * The number of dma segments supported.  The sequencer can handle any number
103  * of physically contiguous S/G entrys.  To reduce the driver's memory
104  * consumption, we limit the number supported to be sufficient to handle
105  * the largest mapping supported by the the legacy kernel MAXPHYS setting of
106  * 128K.  This can be increased once some testing is done.  Assuming the
107  * transfer is as fragmented as possible and unaligned, this turns out to
108  * be the number of paged sized transfers in MAXPHYS plus an extra element
109  * to handle any unaligned residual.  The sequencer fetches SG elements
110  * in cacheline sized chucks, so make the number per-transaction an even
111  * multiple of 16 which should align us on even the largest of cacheline
112  * boundaries. 
113  */
114 #define AHD_MAXPHYS (128 * 1024)
115 #define AHD_NSEG (roundup(btoc(AHD_MAXPHYS) + 1, 16))
116
117 /* This driver supports target mode */
118 #ifdef NOT_YET
119 #define AHD_TARGET_MODE 1
120 #endif
121
122 /************************** Softc/SCB Platform Data ***************************/
123 struct ahd_platform_data {
124         /*
125          * Hooks into the XPT.
126          */
127         struct  cam_sim         *sim;
128         struct  cam_path        *path;
129
130         int                      regs_res_type[2];
131         int                      regs_res_id[2];
132         int                      irq_res_type;
133         struct resource         *regs[2];
134         struct resource         *irq;
135         void                    *ih;
136         eventhandler_tag         eh;
137         struct proc             *recovery_thread;
138         struct mtx              mtx;
139 };
140
141 struct scb_platform_data {
142 };
143
144 /***************************** Core Includes **********************************/
145 #ifdef AHD_REG_PRETTY_PRINT
146 #define AIC_DEBUG_REGISTERS 1
147 #else
148 #define AIC_DEBUG_REGISTERS 0
149 #endif
150 #define AIC_CORE_INCLUDE <dev/aic7xxx/aic79xx.h>
151 #define AIC_LIB_PREFIX ahd
152 #define AIC_CONST_PREFIX AHD
153 #include <dev/aic7xxx/aic_osm_lib.h>
154
155 /*************************** Device Access ************************************/
156 #define ahd_inb(ahd, port)                                      \
157         bus_space_read_1((ahd)->tags[(port) >> 8],              \
158                          (ahd)->bshs[(port) >> 8], (port) & 0xFF)
159
160 #define ahd_outb(ahd, port, value)                              \
161         bus_space_write_1((ahd)->tags[(port) >> 8],             \
162                           (ahd)->bshs[(port) >> 8], (port) & 0xFF, value)
163
164 #define ahd_inw_atomic(ahd, port)                               \
165         aic_le16toh(bus_space_read_2((ahd)->tags[(port) >> 8],  \
166                                      (ahd)->bshs[(port) >> 8], (port) & 0xFF))
167
168 #define ahd_outw_atomic(ahd, port, value)                       \
169         bus_space_write_2((ahd)->tags[(port) >> 8],             \
170                           (ahd)->bshs[(port) >> 8],             \
171                           (port & 0xFF), aic_htole16(value))
172
173 #define ahd_outsb(ahd, port, valp, count)                       \
174         bus_space_write_multi_1((ahd)->tags[(port) >> 8],       \
175                                 (ahd)->bshs[(port) >> 8],       \
176                                 (port & 0xFF), valp, count)
177
178 #define ahd_insb(ahd, port, valp, count)                        \
179         bus_space_read_multi_1((ahd)->tags[(port) >> 8],        \
180                                (ahd)->bshs[(port) >> 8],        \
181                                (port & 0xFF), valp, count)
182
183 static __inline void ahd_flush_device_writes(struct ahd_softc *);
184
185 static __inline void
186 ahd_flush_device_writes(struct ahd_softc *ahd)
187 {
188         /* XXX Is this sufficient for all architectures??? */
189         ahd_inb(ahd, INTSTAT);
190 }
191
192 /**************************** Locking Primitives ******************************/
193 /* Lock protecting internal data structures */
194 static __inline void ahd_lockinit(struct ahd_softc *);
195 static __inline void ahd_lock(struct ahd_softc *);
196 static __inline void ahd_unlock(struct ahd_softc *);
197
198 static __inline void
199 ahd_lockinit(struct ahd_softc *ahd)
200 {
201         mtx_init(&ahd->platform_data->mtx, "ahd_lock", NULL, MTX_DEF);
202 }
203
204 static __inline void
205 ahd_lock(struct ahd_softc *ahd)
206 {
207         mtx_lock(&ahd->platform_data->mtx);
208 }
209
210 static __inline void
211 ahd_unlock(struct ahd_softc *ahd)
212 {
213         mtx_unlock(&ahd->platform_data->mtx);
214 }
215
216 /********************************** PCI ***************************************/
217 int ahd_pci_map_registers(struct ahd_softc *ahd);
218 int ahd_pci_map_int(struct ahd_softc *ahd);
219
220 /************************** Transaction Operations ****************************/
221 static __inline void aic_freeze_simq(struct aic_softc*);
222 static __inline void aic_release_simq(struct aic_softc*);
223
224 static __inline void
225 aic_freeze_simq(struct aic_softc *aic)
226 {
227         xpt_freeze_simq(aic->platform_data->sim, /*count*/1);
228 }
229
230 static __inline void
231 aic_release_simq(struct aic_softc *aic)
232 {
233         xpt_release_simq(aic->platform_data->sim, /*run queue*/TRUE);
234 }
235 /********************************* Debug **************************************/
236 static __inline void    ahd_print_path(struct ahd_softc *, struct scb *);
237 static __inline void    ahd_platform_dump_card_state(struct ahd_softc *ahd);
238
239 static __inline void
240 ahd_print_path(struct ahd_softc *ahd, struct scb *scb)
241 {
242         xpt_print_path(scb->io_ctx->ccb_h.path);
243 }
244
245 static __inline void
246 ahd_platform_dump_card_state(struct ahd_softc *ahd)
247 {
248         /* Nothing to do here for FreeBSD */
249 }
250 /**************************** Transfer Settings *******************************/
251 void      ahd_notify_xfer_settings_change(struct ahd_softc *,
252                                           struct ahd_devinfo *);
253 void      ahd_platform_set_tags(struct ahd_softc *, struct ahd_devinfo *,
254                                 int /*enable*/);
255
256 /************************* Initialization/Teardown ****************************/
257 int       ahd_platform_alloc(struct ahd_softc *ahd, void *platform_arg);
258 void      ahd_platform_free(struct ahd_softc *ahd);
259 int       ahd_map_int(struct ahd_softc *ahd);
260 int       ahd_attach(struct ahd_softc *);
261 int       ahd_softc_comp(struct ahd_softc *lahd, struct ahd_softc *rahd);
262 int       ahd_detach(device_t);
263 #define ahd_platform_init(arg)
264
265
266 /****************************** Interrupts ************************************/
267 void                    ahd_platform_intr(void *);
268 static __inline void    ahd_platform_flushwork(struct ahd_softc *ahd);
269 static __inline void
270 ahd_platform_flushwork(struct ahd_softc *ahd)
271 {
272 }
273
274 /************************ Misc Function Declarations **************************/
275 void      ahd_done(struct ahd_softc *ahd, struct scb *scb);
276 void      ahd_send_async(struct ahd_softc *, char /*channel*/,
277                          u_int /*target*/, u_int /*lun*/, ac_code, void *arg);
278 #endif  /* _AIC79XX_FREEBSD_H_ */