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