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