2 * FreeBSD platform specific driver option settings, data structures,
3 * function declarations and includes.
5 * Copyright (c) 1994-2001 Justin T. Gibbs.
6 * Copyright (c) 2001-2002 Adaptec Inc.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
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.
18 * Alternatively, this software may be distributed under the terms of the
19 * GNU Public License ("GPL").
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
33 * $Id: //depot/aic7xxx/freebsd/dev/aic7xxx/aic79xx_osm.h#23 $
35 * $FreeBSD: src/sys/dev/aic7xxx/aic79xx_osm.h,v 1.18 2005/12/06 11:19:36 ru Exp $
36 * $DragonFly: src/sys/dev/disk/aic7xxx/aic79xx_osm.h,v 1.11 2007/07/07 01:12:01 pavalos Exp $
39 #ifndef _AIC79XX_FREEBSD_H_
40 #define _AIC79XX_FREEBSD_H_
42 #include <opt_aic79xx.h> /* for config options */
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/bus.h> /* For device_t */
47 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
48 #include <sys/endian.h>
50 #include <sys/eventhandler.h>
51 #include <sys/kernel.h>
52 #include <sys/malloc.h>
53 #include <sys/queue.h>
54 #include <sys/thread2.h>
56 #define AIC_PCI_CONFIG 1
57 #include <machine/endian.h>
58 #include <machine/clock.h>
62 #include <bus/pci/pcireg.h>
63 #include <bus/pci/pcivar.h>
65 #include <bus/cam/cam.h>
66 #include <bus/cam/cam_ccb.h>
67 #include <bus/cam/cam_debug.h>
68 #include <bus/cam/cam_sim.h>
69 #include <bus/cam/cam_xpt_sim.h>
71 #include <bus/cam/scsi/scsi_all.h>
72 #include <bus/cam/scsi/scsi_message.h>
73 #include <bus/cam/scsi/scsi_iu.h>
75 #ifdef CAM_NEW_TRAN_CODE
76 #define AHD_NEW_TRAN_SETTINGS
77 #endif /* CAM_NEW_TRAN_CODE */
79 /****************************** Platform Macros *******************************/
80 #define SIM_IS_SCSIBUS_B(ahd, sim) \
82 #define SIM_CHANNEL(ahd, sim) \
84 #define SIM_SCSI_ID(ahd, sim) \
86 #define SIM_PATH(ahd, sim) \
87 (ahd->platform_data->path)
88 #define BUILD_SCSIID(ahd, sim, target_id, our_id) \
89 ((((target_id) << TID_SHIFT) & TID) | (our_id))
92 #define SCB_GET_SIM(ahd, scb) \
93 ((ahd)->platform_data->sim)
96 #define offsetof(type, member) ((size_t)(&((type *)0)->member))
99 /************************ Tunable Driver Parameters **************************/
101 * The number of dma segments supported. The sequencer can handle any number
102 * of physically contiguous S/G entrys. To reduce the driver's memory
103 * consumption, we limit the number supported to be sufficient to handle
104 * the largest mapping supported by the kernel, MAXPHYS. Assuming the
105 * transfer is as fragmented as possible and unaligned, this turns out to
106 * be the number of paged sized transfers in MAXPHYS plus an extra element
107 * to handle any unaligned residual. The sequencer fetches SG elements
108 * in cacheline sized chucks, so make the number per-transaction an even
109 * multiple of 16 which should align us on even the largest of cacheline
112 #define AHD_NSEG (roundup(btoc(MAXPHYS) + 1, 16))
114 /* This driver supports target mode */
116 #define AHD_TARGET_MODE 1
119 /************************** Softc/SCB Platform Data ***************************/
120 struct ahd_platform_data {
122 * Hooks into the XPT.
125 struct cam_path *path;
127 int regs_res_type[2];
130 struct resource *regs[2];
131 struct resource *irq;
134 struct thread *recovery_thread;
137 struct scb_platform_data {
140 /***************************** Core Includes **********************************/
141 #ifdef AHD_REG_PRETTY_PRINT
142 #define AIC_DEBUG_REGISTERS 1
144 #define AIC_DEBUG_REGISTERS 0
146 #define AIC_CORE_INCLUDE "aic79xx.h"
147 #define AIC_LIB_PREFIX ahd
148 #define AIC_CONST_PREFIX AHD
149 #include "aic_osm_lib.h"
151 /*************************** Device Access ************************************/
152 #define ahd_inb(ahd, port) \
153 bus_space_read_1((ahd)->tags[(port) >> 8], \
154 (ahd)->bshs[(port) >> 8], (port) & 0xFF)
156 #define ahd_outb(ahd, port, value) \
157 bus_space_write_1((ahd)->tags[(port) >> 8], \
158 (ahd)->bshs[(port) >> 8], (port) & 0xFF, value)
160 #define ahd_inw_atomic(ahd, port) \
161 aic_le16toh(bus_space_read_2((ahd)->tags[(port) >> 8], \
162 (ahd)->bshs[(port) >> 8], (port) & 0xFF))
164 #define ahd_outw_atomic(ahd, port, value) \
165 bus_space_write_2((ahd)->tags[(port) >> 8], \
166 (ahd)->bshs[(port) >> 8], \
167 (port & 0xFF), aic_htole16(value))
169 #define ahd_outsb(ahd, port, valp, count) \
170 bus_space_write_multi_1((ahd)->tags[(port) >> 8], \
171 (ahd)->bshs[(port) >> 8], \
172 (port & 0xFF), valp, count)
174 #define ahd_insb(ahd, port, valp, count) \
175 bus_space_read_multi_1((ahd)->tags[(port) >> 8], \
176 (ahd)->bshs[(port) >> 8], \
177 (port & 0xFF), valp, count)
179 static __inline void ahd_flush_device_writes(struct ahd_softc *);
182 ahd_flush_device_writes(struct ahd_softc *ahd)
184 /* XXX Is this sufficient for all architectures??? */
185 ahd_inb(ahd, INTSTAT);
188 /**************************** Locking Primitives ******************************/
189 /* Lock protecting internal data structures */
190 static __inline void ahd_lock(void);
191 static __inline void ahd_unlock(void);
205 /********************************** PCI ***************************************/
206 int ahd_pci_map_registers(struct ahd_softc *ahd);
207 int ahd_pci_map_int(struct ahd_softc *ahd);
209 /************************** Transaction Operations ****************************/
210 static __inline void aic_freeze_simq(struct aic_softc*);
211 static __inline void aic_release_simq(struct aic_softc*);
214 aic_freeze_simq(struct aic_softc *aic)
216 xpt_freeze_simq(aic->platform_data->sim, /*count*/1);
220 aic_release_simq(struct aic_softc *aic)
222 xpt_release_simq(aic->platform_data->sim, /*run queue*/TRUE);
225 /********************************* Debug **************************************/
226 static __inline void ahd_print_path(struct ahd_softc *, struct scb *);
227 static __inline void ahd_platform_dump_card_state(struct ahd_softc *ahd);
230 ahd_print_path(struct ahd_softc *ahd, struct scb *scb)
232 xpt_print_path(scb->io_ctx->ccb_h.path);
236 ahd_platform_dump_card_state(struct ahd_softc *ahd)
238 /* Nothing to do here for FreeBSD */
240 /**************************** Transfer Settings *******************************/
241 void ahd_notify_xfer_settings_change(struct ahd_softc *,
242 struct ahd_devinfo *);
243 void ahd_platform_set_tags(struct ahd_softc *, struct ahd_devinfo *,
246 /************************* Initialization/Teardown ****************************/
247 int ahd_platform_alloc(struct ahd_softc *ahd, void *platform_arg);
248 void ahd_platform_free(struct ahd_softc *ahd);
249 int ahd_map_int(struct ahd_softc *ahd);
250 int ahd_attach(struct ahd_softc *);
251 int ahd_softc_comp(struct ahd_softc *lahd, struct ahd_softc *rahd);
252 int ahd_detach(device_t);
253 #define ahd_platform_init(arg)
256 /****************************** Interrupts ************************************/
257 void ahd_platform_intr(void *);
258 static __inline void ahd_platform_flushwork(struct ahd_softc *ahd);
260 ahd_platform_flushwork(struct ahd_softc *ahd)
264 /************************ Misc Function Declarations **************************/
265 void ahd_done(struct ahd_softc *ahd, struct scb *scb);
266 void ahd_send_async(struct ahd_softc *, char /*channel*/,
267 u_int /*target*/, u_int /*lun*/, ac_code, void *arg);
268 #endif /* _AIC79XX_FREEBSD_H_ */