xref: /freebsd/sys/dev/aic7xxx/aic7xxx_osm.h (revision f0adf7f5cdd241db2f2c817683191a6ef64a4e95)
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$
35  */
36 
37 #ifndef _AIC7XXX_FREEBSD_H_
38 #define _AIC7XXX_FREEBSD_H_
39 
40 #include <opt_aic7xxx.h>	/* for config options */
41 
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/bus.h>		/* For device_t */
45 #if __FreeBSD_version >= 500000
46 #include <sys/endian.h>
47 #endif
48 #include <sys/eventhandler.h>
49 #include <sys/kernel.h>
50 #include <sys/malloc.h>
51 #include <sys/module.h>
52 #include <sys/queue.h>
53 
54 #if __FreeBSD_version < 500000
55 #include <pci.h>
56 #else
57 #define NPCI 1
58 #endif
59 
60 #if NPCI > 0
61 #define AIC_PCI_CONFIG 1
62 #include <machine/bus_memio.h>
63 #endif
64 #include <machine/bus_pio.h>
65 #include <machine/bus.h>
66 #include <machine/endian.h>
67 #include <machine/clock.h>
68 #include <machine/resource.h>
69 
70 #include <sys/rman.h>
71 
72 #if NPCI > 0
73 #if __FreeBSD_version >= 500000
74 #include <dev/pci/pcireg.h>
75 #include <dev/pci/pcivar.h>
76 #else
77 #include <pci/pcireg.h>
78 #include <pci/pcivar.h>
79 #endif
80 #endif
81 
82 #include <cam/cam.h>
83 #include <cam/cam_ccb.h>
84 #include <cam/cam_debug.h>
85 #include <cam/cam_sim.h>
86 #include <cam/cam_xpt_sim.h>
87 
88 #include <cam/scsi/scsi_all.h>
89 #include <cam/scsi/scsi_message.h>
90 
91 #ifdef CAM_NEW_TRAN_CODE
92 #define AHC_NEW_TRAN_SETTINGS
93 #endif /* CAM_NEW_TRAN_CODE */
94 
95 /*************************** Attachment Bookkeeping ***************************/
96 extern devclass_t ahc_devclass;
97 
98 /****************************** Platform Macros *******************************/
99 #define	SIM_IS_SCSIBUS_B(ahc, sim)	\
100 	((sim) == ahc->platform_data->sim_b)
101 #define	SIM_CHANNEL(ahc, sim)	\
102 	(((sim) == ahc->platform_data->sim_b) ? 'B' : 'A')
103 #define	SIM_SCSI_ID(ahc, sim)	\
104 	(((sim) == ahc->platform_data->sim_b) ? ahc->our_id_b : ahc->our_id)
105 #define	SIM_PATH(ahc, sim)	\
106 	(((sim) == ahc->platform_data->sim_b) ? ahc->platform_data->path_b \
107 					      : ahc->platform_data->path)
108 #define BUILD_SCSIID(ahc, sim, target_id, our_id) \
109         ((((target_id) << TID_SHIFT) & TID) | (our_id) \
110         | (SIM_IS_SCSIBUS_B(ahc, sim) ? TWIN_CHNLB : 0))
111 
112 #define SCB_GET_SIM(ahc, scb) \
113 	(SCB_GET_CHANNEL(ahc, scb) == 'A' ? (ahc)->platform_data->sim \
114 					  : (ahc)->platform_data->sim_b)
115 
116 #ifndef offsetof
117 #define offsetof(type, member)  ((size_t)(&((type *)0)->member))
118 #endif
119 
120 /************************ Tunable Driver Parameters  **************************/
121 /*
122  * The number of dma segments supported.  The sequencer can handle any number
123  * of physically contiguous S/G entrys.  To reduce the driver's memory
124  * consumption, we limit the number supported to be sufficient to handle
125  * the largest mapping supported by the kernel, MAXPHYS.  Assuming the
126  * transfer is as fragmented as possible and unaligned, this turns out to
127  * be the number of paged sized transfers in MAXPHYS plus an extra element
128  * to handle any unaligned residual.  The sequencer fetches SG elements
129  * in cacheline sized chucks, so make the number per-transaction an even
130  * multiple of 16 which should align us on even the largest of cacheline
131  * boundaries.
132  */
133 #define AHC_NSEG (roundup(btoc(MAXPHYS) + 1, 16))
134 
135 /* This driver supports target mode */
136 #define AHC_TARGET_MODE 1
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 proc		*recovery_thread;
156 };
157 
158 struct scb_platform_data {
159 };
160 
161 /***************************** Core Includes **********************************/
162 #if AHC_REG_PRETTY_PRINT
163 #define AIC_DEBUG_REGISTERS 1
164 #else
165 #define AIC_DEBUG_REGISTERS 0
166 #endif
167 #define AIC_CORE_INCLUDE <dev/aic7xxx/aic7xxx.h>
168 #define	AIC_LIB_PREFIX ahc
169 #define	AIC_CONST_PREFIX AHC
170 #include <dev/aic7xxx/aic_osm_lib.h>
171 
172 /*************************** Device Access ************************************/
173 #define ahc_inb(ahc, port)				\
174 	bus_space_read_1((ahc)->tag, (ahc)->bsh, port)
175 
176 #define ahc_outb(ahc, port, value)			\
177 	bus_space_write_1((ahc)->tag, (ahc)->bsh, port, value)
178 
179 #define ahc_outsb(ahc, port, valp, count)		\
180 	bus_space_write_multi_1((ahc)->tag, (ahc)->bsh, port, valp, count)
181 
182 #define ahc_insb(ahc, port, valp, count)		\
183 	bus_space_read_multi_1((ahc)->tag, (ahc)->bsh, port, valp, count)
184 
185 static __inline void ahc_flush_device_writes(struct ahc_softc *);
186 
187 static __inline void
188 ahc_flush_device_writes(struct ahc_softc *ahc)
189 {
190 	/* XXX Is this sufficient for all architectures??? */
191 	ahc_inb(ahc, INTSTAT);
192 }
193 
194 /**************************** Locking Primitives ******************************/
195 /* Lock protecting internal data structures */
196 static __inline void ahc_lockinit(struct ahc_softc *);
197 static __inline void ahc_lock(struct ahc_softc *, unsigned long *flags);
198 static __inline void ahc_unlock(struct ahc_softc *, unsigned long *flags);
199 
200 /* Lock held during command compeletion to the upper layer */
201 static __inline void ahc_done_lockinit(struct ahc_softc *);
202 static __inline void ahc_done_lock(struct ahc_softc *, unsigned long *flags);
203 static __inline void ahc_done_unlock(struct ahc_softc *, unsigned long *flags);
204 
205 /* Lock held during ahc_list manipulation and ahc softc frees */
206 static __inline void ahc_list_lockinit(void);
207 static __inline void ahc_list_lock(unsigned long *flags);
208 static __inline void ahc_list_unlock(unsigned long *flags);
209 
210 static __inline void
211 ahc_lockinit(struct ahc_softc *ahc)
212 {
213 }
214 
215 static __inline void
216 ahc_lock(struct ahc_softc *ahc, unsigned long *flags)
217 {
218 	*flags = splcam();
219 }
220 
221 static __inline void
222 ahc_unlock(struct ahc_softc *ahc, unsigned long *flags)
223 {
224 	splx(*flags);
225 }
226 
227 /* Lock held during command compeletion to the upper layer */
228 static __inline void
229 ahc_done_lockinit(struct ahc_softc *ahc)
230 {
231 }
232 
233 static __inline void
234 ahc_done_lock(struct ahc_softc *ahc, unsigned long *flags)
235 {
236 }
237 
238 static __inline void
239 ahc_done_unlock(struct ahc_softc *ahc, unsigned long *flags)
240 {
241 }
242 
243 /* Lock held during ahc_list manipulation and ahc softc frees */
244 static __inline void
245 ahc_list_lockinit(void)
246 {
247 }
248 
249 static __inline void
250 ahc_list_lock(unsigned long *flags)
251 {
252 }
253 
254 static __inline void
255 ahc_list_unlock(unsigned long *flags)
256 {
257 }
258 
259 /********************************** PCI ***************************************/
260 #ifdef AIC_PCI_CONFIG
261 int ahc_pci_map_registers(struct ahc_softc *ahc);
262 int ahc_pci_map_int(struct ahc_softc *ahc);
263 #endif /*AIC_PCI_CONFIG*/
264 
265 /******************************** VL/EISA *************************************/
266 int aic7770_map_registers(struct ahc_softc *ahc, u_int port);
267 int aic7770_map_int(struct ahc_softc *ahc, int irq);
268 
269 /********************************* Debug **************************************/
270 static __inline void	ahc_print_path(struct ahc_softc *, struct scb *);
271 static __inline void	ahc_platform_dump_card_state(struct ahc_softc *ahc);
272 
273 static __inline void
274 ahc_print_path(struct ahc_softc *ahc, struct scb *scb)
275 {
276 	xpt_print_path(scb->io_ctx->ccb_h.path);
277 }
278 
279 static __inline void
280 ahc_platform_dump_card_state(struct ahc_softc *ahc)
281 {
282 	/* Nothing to do here for FreeBSD */
283 }
284 /**************************** Transfer Settings *******************************/
285 void	  ahc_notify_xfer_settings_change(struct ahc_softc *,
286 					  struct ahc_devinfo *);
287 void	  ahc_platform_set_tags(struct ahc_softc *, struct ahc_devinfo *,
288 				int /*enable*/);
289 
290 /************************* Initialization/Teardown ****************************/
291 int	  ahc_platform_alloc(struct ahc_softc *ahc, void *platform_arg);
292 void	  ahc_platform_free(struct ahc_softc *ahc);
293 int	  ahc_map_int(struct ahc_softc *ahc);
294 int	  ahc_attach(struct ahc_softc *);
295 int	  ahc_softc_comp(struct ahc_softc *lahc, struct ahc_softc *rahc);
296 int	  ahc_detach(device_t);
297 
298 /****************************** Interrupts ************************************/
299 void			ahc_platform_intr(void *);
300 static __inline void	ahc_platform_flushwork(struct ahc_softc *ahc);
301 static __inline void
302 ahc_platform_flushwork(struct ahc_softc *ahc)
303 {
304 }
305 
306 /************************ Misc Function Declarations **************************/
307 void	  ahc_done(struct ahc_softc *ahc, struct scb *scb);
308 void	  ahc_send_async(struct ahc_softc *, char /*channel*/,
309 			 u_int /*target*/, u_int /*lun*/, ac_code, void *arg);
310 #endif  /* _AIC7XXX_FREEBSD_H_ */
311