gold: Fix hardcoded library search path
[dragonfly.git] / sys / dev / disk / aic7xxx / aic7xxx_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  * 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. The name of the author may not be used to endorse or promote products
15  *    derived from this software without specific prior written permission.
16  *
17  * Alternatively, this software may be distributed under the terms of the
18  * GNU Public License ("GPL").
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
24  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  *
32  * $Id: //depot/aic7xxx/freebsd/dev/aic7xxx/aic7xxx_osm.h#18 $
33  *
34  * $FreeBSD: src/sys/dev/aic7xxx/aic7xxx_osm.h,v 1.30 2005/12/05 11:58:32 ru Exp $
35  * $DragonFly: src/sys/dev/disk/aic7xxx/aic7xxx_osm.h,v 1.15 2008/04/06 19:03:18 pavalos Exp $
36  */
37
38 #ifndef _AIC7XXX_FREEBSD_H_
39 #define _AIC7XXX_FREEBSD_H_
40
41 #include <opt_aic7xxx.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 defined(__FreeBSD__) && __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/queue.h>
53 #include <sys/rman.h>
54
55 #include <sys/thread2.h>
56 #include <sys/mplock2.h>
57
58 #if defined(__DragonFly__) || __FreeBSD_version < 500000
59 #include <use_pci.h>
60 #else
61 #define NPCI 1
62 #endif
63
64 #if NPCI > 0
65 #define AIC_PCI_CONFIG 1
66 #endif
67 #include <machine/endian.h>
68 #include <machine/clock.h>
69
70 #if NPCI > 0
71 #include <bus/pci/pcireg.h>
72 #include <bus/pci/pcivar.h>
73 #endif
74
75 #include <bus/cam/cam.h>
76 #include <bus/cam/cam_ccb.h>
77 #include <bus/cam/cam_debug.h>
78 #include <bus/cam/cam_sim.h>
79 #include <bus/cam/cam_xpt_sim.h>
80
81 #include <bus/cam/scsi/scsi_all.h>
82 #include <bus/cam/scsi/scsi_message.h>
83
84 /*************************** Attachment Bookkeeping ***************************/
85 extern devclass_t ahc_devclass;
86
87 /****************************** Platform Macros *******************************/
88 #define SIM_IS_SCSIBUS_B(ahc, sim)      \
89         ((sim) == ahc->platform_data->sim_b)
90 #define SIM_CHANNEL(ahc, sim)   \
91         (((sim) == ahc->platform_data->sim_b) ? 'B' : 'A')
92 #define SIM_SCSI_ID(ahc, sim)   \
93         (((sim) == ahc->platform_data->sim_b) ? ahc->our_id_b : ahc->our_id)
94 #define SIM_PATH(ahc, sim)      \
95         (((sim) == ahc->platform_data->sim_b) ? ahc->platform_data->path_b \
96                                               : ahc->platform_data->path)
97 #define BUILD_SCSIID(ahc, sim, target_id, our_id) \
98         ((((target_id) << TID_SHIFT) & TID) | (our_id) \
99         | (SIM_IS_SCSIBUS_B(ahc, sim) ? TWIN_CHNLB : 0))
100
101 #define SCB_GET_SIM(ahc, scb) \
102         (SCB_GET_CHANNEL(ahc, scb) == 'A' ? (ahc)->platform_data->sim \
103                                           : (ahc)->platform_data->sim_b)
104
105 #ifndef offsetof
106 #define offsetof(type, member)  ((size_t)(&((type *)0)->member))
107 #endif
108
109 /************************ Tunable Driver Parameters  **************************/
110 /*
111  * The number of dma segments supported.  The sequencer can handle any number
112  * of physically contiguous S/G entrys.  To reduce the driver's memory
113  * consumption, we limit the number supported to be sufficient to handle
114  * the largest mapping supported by the kernel, MAXPHYS.  Assuming the
115  * transfer is as fragmented as possible and unaligned, this turns out to
116  * be the number of paged sized transfers in MAXPHYS plus an extra element
117  * to handle any unaligned residual.  The sequencer fetches SG elements
118  * in cacheline sized chucks, so make the number per-transaction an even
119  * multiple of 16 which should align us on even the largest of cacheline
120  * boundaries. 
121  */
122 #define AHC_NSEG (roundup(btoc(MAXPHYS) + 1, 16))
123
124 /* This driver supports target mode */
125 #define AHC_TARGET_MODE 1
126
127 /***************************** Core Includes **********************************/
128 #ifdef AHC_REG_PRETTY_PRINT
129 #define AIC_DEBUG_REGISTERS 1
130 #else
131 #define AIC_DEBUG_REGISTERS 0
132 #endif
133 #define AIC_CORE_INCLUDE "aic7xxx.h"
134 #define AIC_LIB_PREFIX ahc
135 #define AIC_CONST_PREFIX AHC
136 #include "aic_osm_lib.h"
137
138 /************************** Softc/SCB Platform Data ***************************/
139 struct ahc_platform_data {
140         /*
141          * Hooks into the XPT.
142          */
143         struct  cam_sim         *sim;
144         struct  cam_sim         *sim_b;
145         struct  cam_path        *path;
146         struct  cam_path        *path_b;
147
148         int                      regs_res_type;
149         int                      regs_res_id;
150         int                      irq_res_type;
151         struct resource         *regs;
152         struct resource         *irq;
153         void                    *ih;
154         eventhandler_tag         eh;
155         struct thread           *recovery_thread;
156         struct lock              lock;
157 };
158
159 struct scb_platform_data {
160 };
161
162 /*************************** Device Access ************************************/
163 #define ahc_inb(ahc, port)                              \
164         bus_space_read_1((ahc)->tag, (ahc)->bsh, port)
165
166 #define ahc_outb(ahc, port, value)                      \
167         bus_space_write_1((ahc)->tag, (ahc)->bsh, port, value)
168
169 #define ahc_outsb(ahc, port, valp, count)               \
170         bus_space_write_multi_1((ahc)->tag, (ahc)->bsh, port, valp, count)
171
172 #define ahc_insb(ahc, port, valp, count)                \
173         bus_space_read_multi_1((ahc)->tag, (ahc)->bsh, port, valp, count)
174
175 static __inline void ahc_flush_device_writes(struct ahc_softc *);
176
177 static __inline void
178 ahc_flush_device_writes(struct ahc_softc *ahc)
179 {
180         /* XXX Is this sufficient for all architectures??? */
181         ahc_inb(ahc, INTSTAT);
182 }
183
184 /**************************** Locking Primitives ******************************/
185 /* Lock protecting internal data structures */
186 static __inline void ahc_lockinit(struct ahc_softc *);
187 static __inline void ahc_lock(struct ahc_softc *);
188 static __inline void ahc_unlock(struct ahc_softc *);
189
190 static __inline void
191 ahc_lockinit(struct ahc_softc *ahc)
192 {
193         lockinit(&ahc->platform_data->lock, "ahc_lock", 0, LK_CANRECURSE);
194 }
195
196 static __inline void
197 ahc_lock(struct ahc_softc *ahc)
198 {
199         lockmgr(&ahc->platform_data->lock, LK_EXCLUSIVE);
200 }
201
202 static __inline void
203 ahc_unlock(struct ahc_softc *ahc)
204 {
205         lockmgr(&ahc->platform_data->lock, LK_RELEASE);
206 }
207
208 /************************* Initialization/Teardown ****************************/
209 int       ahc_platform_alloc(struct ahc_softc *ahc, void *platform_arg);
210 void      ahc_platform_free(struct ahc_softc *ahc);
211 int       ahc_map_int(struct ahc_softc *ahc);
212 int       ahc_attach(struct ahc_softc *);
213 int       ahc_softc_comp(struct ahc_softc *lahc, struct ahc_softc *rahc);
214 int       ahc_detach(device_t);
215
216 /********************************** PCI ***************************************/
217 #ifdef AIC_PCI_CONFIG
218 int ahc_pci_map_registers(struct ahc_softc *ahc);
219 #define ahc_pci_map_int ahc_map_int
220 #endif /*AIC_PCI_CONFIG*/
221
222 /********************************* Debug **************************************/
223 static __inline void    ahc_print_path(struct ahc_softc *, struct scb *);
224 static __inline void    ahc_platform_dump_card_state(struct ahc_softc *ahc);
225
226 static __inline void
227 ahc_print_path(struct ahc_softc *ahc, struct scb *scb)
228 {
229         xpt_print_path(scb->io_ctx->ccb_h.path);
230 }
231
232 static __inline void
233 ahc_platform_dump_card_state(struct ahc_softc *ahc)
234 {
235         /* Nothing to do here for FreeBSD */
236 }
237 /**************************** Transfer Settings *******************************/
238 void      ahc_notify_xfer_settings_change(struct ahc_softc *,
239                                           struct ahc_devinfo *);
240 void      ahc_platform_set_tags(struct ahc_softc *, struct ahc_devinfo *,
241                                 int /*enable*/);
242
243 /****************************** Interrupts ************************************/
244 void                    ahc_platform_intr(void *);
245 static __inline void    ahc_platform_flushwork(struct ahc_softc *ahc);
246 static __inline void
247 ahc_platform_flushwork(struct ahc_softc *ahc)
248 {
249 }
250
251 /************************ Misc Function Declarations **************************/
252 void      ahc_done(struct ahc_softc *ahc, struct scb *scb);
253 void      ahc_send_async(struct ahc_softc *, char /*channel*/,
254                          u_int /*target*/, u_int /*lun*/, ac_code, void *arg);
255 #endif  /* _AIC7XXX_FREEBSD_H_ */