Merge branch 'vendor/BINUTILS220'
[dragonfly.git] / sys / dev / disk / 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: src/sys/dev/aic7xxx/aic79xx_osm.h,v 1.18 2005/12/06 11:19:36 ru Exp $
36  * $DragonFly: src/sys/dev/disk/aic7xxx/aic79xx_osm.h,v 1.14 2008/04/06 19:03:18 pavalos Exp $
37  */
38
39 #ifndef _AIC79XX_FREEBSD_H_
40 #define _AIC79XX_FREEBSD_H_
41
42 #include <opt_aic79xx.h>        /* for config options */
43
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/bus.h>            /* For device_t */
47 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
48 #include <sys/endian.h>
49 #endif
50 #include <sys/eventhandler.h>
51 #include <sys/kernel.h>
52 #include <sys/malloc.h>
53 #include <sys/queue.h>
54
55 #include <sys/thread2.h>
56 #include <sys/mplock2.h>
57
58 #define AIC_PCI_CONFIG 1
59 #include <machine/endian.h>
60 #include <machine/clock.h>
61
62 #include <sys/rman.h>
63
64 #include <bus/pci/pcireg.h>
65 #include <bus/pci/pcivar.h>
66
67 #include <bus/cam/cam.h>
68 #include <bus/cam/cam_ccb.h>
69 #include <bus/cam/cam_debug.h>
70 #include <bus/cam/cam_sim.h>
71 #include <bus/cam/cam_xpt_sim.h>
72
73 #include <bus/cam/scsi/scsi_all.h>
74 #include <bus/cam/scsi/scsi_message.h>
75 #include <bus/cam/scsi/scsi_iu.h>
76
77 /****************************** Platform Macros *******************************/
78 #define SIM_IS_SCSIBUS_B(ahd, sim)      \
79         (0)
80 #define SIM_CHANNEL(ahd, sim)   \
81         ('A')
82 #define SIM_SCSI_ID(ahd, sim)   \
83         (ahd->our_id)
84 #define SIM_PATH(ahd, sim)      \
85         (ahd->platform_data->path)
86 #define BUILD_SCSIID(ahd, sim, target_id, our_id) \
87         ((((target_id) << TID_SHIFT) & TID) | (our_id))
88         
89
90 #define SCB_GET_SIM(ahd, scb) \
91         ((ahd)->platform_data->sim)
92
93 #ifndef offsetof
94 #define offsetof(type, member)  ((size_t)(&((type *)0)->member))
95 #endif
96
97 /************************ Tunable Driver Parameters  **************************/
98 /*
99  * The number of dma segments supported.  The sequencer can handle any number
100  * of physically contiguous S/G entrys.  To reduce the driver's memory
101  * consumption, we limit the number supported to be sufficient to handle
102  * the largest mapping supported by the kernel, MAXPHYS.  Assuming the
103  * transfer is as fragmented as possible and unaligned, this turns out to
104  * be the number of paged sized transfers in MAXPHYS plus an extra element
105  * to handle any unaligned residual.  The sequencer fetches SG elements
106  * in cacheline sized chucks, so make the number per-transaction an even
107  * multiple of 16 which should align us on even the largest of cacheline
108  * boundaries. 
109  */
110 #define AHD_NSEG (roundup(btoc(MAXPHYS) + 1, 16))
111
112 /* This driver supports target mode */
113 #ifdef NOT_YET
114 #define AHD_TARGET_MODE 1
115 #endif
116
117 /***************************** Core Includes **********************************/
118 #ifdef AHD_REG_PRETTY_PRINT
119 #define AIC_DEBUG_REGISTERS 1
120 #else
121 #define AIC_DEBUG_REGISTERS 0
122 #endif
123 #define AIC_CORE_INCLUDE "aic79xx.h"
124 #define AIC_LIB_PREFIX ahd
125 #define AIC_CONST_PREFIX AHD
126 #include "aic_osm_lib.h"
127
128 /************************** Softc/SCB Platform Data ***************************/
129 struct ahd_platform_data {
130         /*
131          * Hooks into the XPT.
132          */
133         struct  cam_sim         *sim;
134         struct  cam_path        *path;
135
136         int                      regs_res_type[2];
137         int                      regs_res_id[2];
138         int                      irq_res_type;
139         struct resource         *regs[2];
140         struct resource         *irq;
141         void                    *ih;
142         eventhandler_tag         eh;
143         struct thread           *recovery_thread;
144         struct lock              lock;
145 };
146
147 struct scb_platform_data {
148 };
149
150 /*************************** Device Access ************************************/
151 #define ahd_inb(ahd, port)                                      \
152         bus_space_read_1((ahd)->tags[(port) >> 8],              \
153                          (ahd)->bshs[(port) >> 8], (port) & 0xFF)
154
155 #define ahd_outb(ahd, port, value)                              \
156         bus_space_write_1((ahd)->tags[(port) >> 8],             \
157                           (ahd)->bshs[(port) >> 8], (port) & 0xFF, value)
158
159 #define ahd_inw_atomic(ahd, port)                               \
160         aic_le16toh(bus_space_read_2((ahd)->tags[(port) >> 8],  \
161                                      (ahd)->bshs[(port) >> 8], (port) & 0xFF))
162
163 #define ahd_outw_atomic(ahd, port, value)                       \
164         bus_space_write_2((ahd)->tags[(port) >> 8],             \
165                           (ahd)->bshs[(port) >> 8],             \
166                           (port & 0xFF), aic_htole16(value))
167
168 #define ahd_outsb(ahd, port, valp, count)                       \
169         bus_space_write_multi_1((ahd)->tags[(port) >> 8],       \
170                                 (ahd)->bshs[(port) >> 8],       \
171                                 (port & 0xFF), valp, count)
172
173 #define ahd_insb(ahd, port, valp, count)                        \
174         bus_space_read_multi_1((ahd)->tags[(port) >> 8],        \
175                                (ahd)->bshs[(port) >> 8],        \
176                                (port & 0xFF), valp, count)
177
178 static __inline void ahd_flush_device_writes(struct ahd_softc *);
179
180 static __inline void
181 ahd_flush_device_writes(struct ahd_softc *ahd)
182 {
183         /* XXX Is this sufficient for all architectures??? */
184         ahd_inb(ahd, INTSTAT);
185 }
186
187 /**************************** Locking Primitives ******************************/
188 /* Lock protecting internal data structures */
189 static __inline void ahd_lockinit(struct ahd_softc *);
190 static __inline void ahd_lock(struct ahd_softc *);
191 static __inline void ahd_unlock(struct ahd_softc *);
192
193 static __inline void
194 ahd_lockinit(struct ahd_softc *ahd)
195 {
196         lockinit(&ahd->platform_data->lock, "ahd_lock", 0, LK_CANRECURSE);
197 }
198
199 static __inline void
200 ahd_lock(struct ahd_softc *ahd)
201 {
202         lockmgr(&ahd->platform_data->lock, LK_EXCLUSIVE);
203 }
204
205 static __inline void
206 ahd_unlock(struct ahd_softc *ahd)
207 {
208         lockmgr(&ahd->platform_data->lock, LK_RELEASE);
209 }
210
211 /********************************** PCI ***************************************/
212 int ahd_pci_map_registers(struct ahd_softc *ahd);
213 int ahd_pci_map_int(struct ahd_softc *ahd);
214
215 /************************** Transaction Operations ****************************/
216 static __inline void aic_freeze_simq(struct aic_softc*);
217 static __inline void aic_release_simq(struct aic_softc*);
218
219 static __inline void
220 aic_freeze_simq(struct aic_softc *aic)
221 {
222         xpt_freeze_simq(aic->platform_data->sim, /*count*/1);
223 }
224
225 static __inline void
226 aic_release_simq(struct aic_softc *aic)
227 {
228         xpt_release_simq(aic->platform_data->sim, /*run queue*/TRUE);
229 }
230
231 /********************************* Debug **************************************/
232 static __inline void    ahd_print_path(struct ahd_softc *, struct scb *);
233 static __inline void    ahd_platform_dump_card_state(struct ahd_softc *ahd);
234
235 static __inline void
236 ahd_print_path(struct ahd_softc *ahd, struct scb *scb)
237 {
238         xpt_print_path(scb->io_ctx->ccb_h.path);
239 }
240
241 static __inline void
242 ahd_platform_dump_card_state(struct ahd_softc *ahd)
243 {
244         /* Nothing to do here for FreeBSD */
245 }
246 /**************************** Transfer Settings *******************************/
247 void      ahd_notify_xfer_settings_change(struct ahd_softc *,
248                                           struct ahd_devinfo *);
249 void      ahd_platform_set_tags(struct ahd_softc *, struct ahd_devinfo *,
250                                 int /*enable*/);
251
252 /************************* Initialization/Teardown ****************************/
253 int       ahd_platform_alloc(struct ahd_softc *ahd, void *platform_arg);
254 void      ahd_platform_free(struct ahd_softc *ahd);
255 int       ahd_map_int(struct ahd_softc *ahd);
256 int       ahd_attach(struct ahd_softc *);
257 int       ahd_softc_comp(struct ahd_softc *lahd, struct ahd_softc *rahd);
258 int       ahd_detach(device_t);
259 #define ahd_platform_init(arg)
260
261
262 /****************************** Interrupts ************************************/
263 void                    ahd_platform_intr(void *);
264 static __inline void    ahd_platform_flushwork(struct ahd_softc *ahd);
265 static __inline void
266 ahd_platform_flushwork(struct ahd_softc *ahd)
267 {
268 }
269
270 /************************ Misc Function Declarations **************************/
271 void      ahd_done(struct ahd_softc *ahd, struct scb *scb);
272 void      ahd_send_async(struct ahd_softc *, char /*channel*/,
273                          u_int /*target*/, u_int /*lun*/, ac_code, void *arg);
274 #endif  /* _AIC79XX_FREEBSD_H_ */