2 * FreeBSD platform specific driver option settings, data structures,
3 * function declarations and includes.
5 * Copyright (c) 1994-2001 Justin T. Gibbs.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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.
17 * Alternatively, this software may be distributed under the terms of the
18 * GNU Public License ("GPL").
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
32 * $Id: //depot/aic7xxx/freebsd/dev/aic7xxx/aic7xxx_osm.h#18 $
34 * $FreeBSD: src/sys/dev/aic7xxx/aic7xxx_osm.h,v 1.30 2005/12/05 11:58:32 ru Exp $
37 #ifndef _AIC7XXX_FREEBSD_H_
38 #define _AIC7XXX_FREEBSD_H_
40 #include <opt_aic7xxx.h> /* for config options */
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>
53 #include <sys/thread2.h>
54 #include <sys/mplock2.h>
57 #define AIC_PCI_CONFIG 1
59 #include <machine/endian.h>
60 #include <machine/clock.h>
63 #include <bus/pci/pcireg.h>
64 #include <bus/pci/pcivar.h>
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>
73 #include <bus/cam/scsi/scsi_all.h>
74 #include <bus/cam/scsi/scsi_message.h>
76 /*************************** Attachment Bookkeeping ***************************/
77 extern devclass_t ahc_devclass;
79 /****************************** Platform Macros *******************************/
80 #define SIM_IS_SCSIBUS_B(ahc, sim) \
81 ((sim) == ahc->platform_data->sim_b)
82 #define SIM_CHANNEL(ahc, sim) \
83 (((sim) == ahc->platform_data->sim_b) ? 'B' : 'A')
84 #define SIM_SCSI_ID(ahc, sim) \
85 (((sim) == ahc->platform_data->sim_b) ? ahc->our_id_b : ahc->our_id)
86 #define SIM_PATH(ahc, sim) \
87 (((sim) == ahc->platform_data->sim_b) ? ahc->platform_data->path_b \
88 : ahc->platform_data->path)
89 #define BUILD_SCSIID(ahc, sim, target_id, our_id) \
90 ((((target_id) << TID_SHIFT) & TID) | (our_id) \
91 | (SIM_IS_SCSIBUS_B(ahc, sim) ? TWIN_CHNLB : 0))
93 #define SCB_GET_SIM(ahc, scb) \
94 (SCB_GET_CHANNEL(ahc, scb) == 'A' ? (ahc)->platform_data->sim \
95 : (ahc)->platform_data->sim_b)
98 #define offsetof(type, member) ((size_t)(&((type *)0)->member))
101 /************************ Tunable Driver Parameters **************************/
103 * The number of dma segments supported. The sequencer can handle any number
104 * of physically contiguous S/G entrys. To reduce the driver's memory
105 * consumption, we limit the number supported to be sufficient to handle
106 * the largest mapping supported by the kernel, MAXPHYS. Assuming the
107 * transfer is as fragmented as possible and unaligned, this turns out to
108 * be the number of paged sized transfers in MAXPHYS plus an extra element
109 * to handle any unaligned residual. The sequencer fetches SG elements
110 * in cacheline sized chucks, so make the number per-transaction an even
111 * multiple of 16 which should align us on even the largest of cacheline
114 #define AHC_NSEG (roundup(btoc(MAXPHYS) + 1, 16))
116 /* This driver supports target mode */
117 #define AHC_TARGET_MODE 1
119 /***************************** Core Includes **********************************/
120 #ifdef AHC_REG_PRETTY_PRINT
121 #define AIC_DEBUG_REGISTERS 1
123 #define AIC_DEBUG_REGISTERS 0
125 #define AIC_CORE_INCLUDE "aic7xxx.h"
126 #define AIC_LIB_PREFIX ahc
127 #define AIC_CONST_PREFIX AHC
128 #include "aic_osm_lib.h"
130 /************************** Softc/SCB Platform Data ***************************/
131 struct ahc_platform_data {
133 * Hooks into the XPT.
136 struct cam_sim *sim_b;
137 struct cam_path *path;
138 struct cam_path *path_b;
143 struct resource *regs;
144 struct resource *irq;
147 struct thread *recovery_thread;
151 struct scb_platform_data {
154 /*************************** Device Access ************************************/
155 #define ahc_inb(ahc, port) \
156 bus_space_read_1((ahc)->tag, (ahc)->bsh, port)
158 #define ahc_outb(ahc, port, value) \
159 bus_space_write_1((ahc)->tag, (ahc)->bsh, port, value)
161 #define ahc_outsb(ahc, port, valp, count) \
162 bus_space_write_multi_1((ahc)->tag, (ahc)->bsh, port, valp, count)
164 #define ahc_insb(ahc, port, valp, count) \
165 bus_space_read_multi_1((ahc)->tag, (ahc)->bsh, port, valp, count)
167 static __inline void ahc_flush_device_writes(struct ahc_softc *);
170 ahc_flush_device_writes(struct ahc_softc *ahc)
172 /* XXX Is this sufficient for all architectures??? */
173 ahc_inb(ahc, INTSTAT);
176 /**************************** Locking Primitives ******************************/
177 /* Lock protecting internal data structures */
178 static __inline void ahc_lockinit(struct ahc_softc *);
179 static __inline void ahc_lock(struct ahc_softc *);
180 static __inline void ahc_unlock(struct ahc_softc *);
183 ahc_lockinit(struct ahc_softc *ahc)
185 lockinit(&ahc->platform_data->lock, "ahc_lock", 0, LK_CANRECURSE);
189 ahc_lock(struct ahc_softc *ahc)
191 lockmgr(&ahc->platform_data->lock, LK_EXCLUSIVE);
195 ahc_unlock(struct ahc_softc *ahc)
197 lockmgr(&ahc->platform_data->lock, LK_RELEASE);
200 /************************* Initialization/Teardown ****************************/
201 int ahc_platform_alloc(struct ahc_softc *ahc, void *platform_arg);
202 void ahc_platform_free(struct ahc_softc *ahc);
203 int ahc_map_int(struct ahc_softc *ahc);
204 int ahc_attach(struct ahc_softc *);
205 int ahc_softc_comp(struct ahc_softc *lahc, struct ahc_softc *rahc);
206 int ahc_detach(device_t);
208 /********************************** PCI ***************************************/
209 #ifdef AIC_PCI_CONFIG
210 int ahc_pci_map_registers(struct ahc_softc *ahc);
211 #define ahc_pci_map_int ahc_map_int
212 #endif /*AIC_PCI_CONFIG*/
214 /********************************* Debug **************************************/
215 static __inline void ahc_print_path(struct ahc_softc *, struct scb *);
216 static __inline void ahc_platform_dump_card_state(struct ahc_softc *ahc);
219 ahc_print_path(struct ahc_softc *ahc, struct scb *scb)
221 xpt_print_path(scb->io_ctx->ccb_h.path);
225 ahc_platform_dump_card_state(struct ahc_softc *ahc)
227 /* Nothing to do here for FreeBSD */
229 /**************************** Transfer Settings *******************************/
230 void ahc_notify_xfer_settings_change(struct ahc_softc *,
231 struct ahc_devinfo *);
232 void ahc_platform_set_tags(struct ahc_softc *, struct ahc_devinfo *,
235 /****************************** Interrupts ************************************/
236 void ahc_platform_intr(void *);
237 static __inline void ahc_platform_flushwork(struct ahc_softc *ahc);
239 ahc_platform_flushwork(struct ahc_softc *ahc)
243 /************************ Misc Function Declarations **************************/
244 void ahc_done(struct ahc_softc *ahc, struct scb *scb);
245 void ahc_send_async(struct ahc_softc *, char /*channel*/,
246 u_int /*target*/, u_int /*lun*/, ac_code, void *arg);
247 #endif /* _AIC7XXX_FREEBSD_H_ */