-Wundef fix.
[dragonfly.git] / sys / dev / disk / aic7xxx / aic7xxx_osm.h
CommitLineData
984263bc
MD
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 *
750f3593 32 * $Id: //depot/aic7xxx/freebsd/dev/aic7xxx/aic7xxx_osm.h#18 $
984263bc 33 *
96ca467d
PA
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.12 2007/07/07 01:09:42 pavalos Exp $
984263bc
MD
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 */
84754cd0 46#if defined(__FreeBSD__) && __FreeBSD_version >= 500000
984263bc
MD
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>
1f7ab7c9 53#include <sys/rman.h>
c1139c5e 54#include <sys/thread2.h>
984263bc 55
84754cd0 56#if defined(__DragonFly__) || __FreeBSD_version < 500000
1f2de5d4 57#include <use_pci.h>
984263bc
MD
58#else
59#define NPCI 1
60#endif
61
62#if NPCI > 0
750f3593 63#define AIC_PCI_CONFIG 1
984263bc 64#endif
984263bc
MD
65#include <machine/endian.h>
66#include <machine/clock.h>
984263bc
MD
67
68#if NPCI > 0
1f2de5d4
MD
69#include <bus/pci/pcireg.h>
70#include <bus/pci/pcivar.h>
984263bc
MD
71#endif
72
1f2de5d4
MD
73#include <bus/cam/cam.h>
74#include <bus/cam/cam_ccb.h>
75#include <bus/cam/cam_debug.h>
76#include <bus/cam/cam_sim.h>
77#include <bus/cam/cam_xpt_sim.h>
984263bc 78
1f2de5d4
MD
79#include <bus/cam/scsi/scsi_all.h>
80#include <bus/cam/scsi/scsi_message.h>
984263bc
MD
81
82#ifdef CAM_NEW_TRAN_CODE
83#define AHC_NEW_TRAN_SETTINGS
84#endif /* CAM_NEW_TRAN_CODE */
85
86/*************************** Attachment Bookkeeping ***************************/
87extern devclass_t ahc_devclass;
88
89/****************************** Platform Macros *******************************/
90#define SIM_IS_SCSIBUS_B(ahc, sim) \
91 ((sim) == ahc->platform_data->sim_b)
92#define SIM_CHANNEL(ahc, sim) \
93 (((sim) == ahc->platform_data->sim_b) ? 'B' : 'A')
94#define SIM_SCSI_ID(ahc, sim) \
95 (((sim) == ahc->platform_data->sim_b) ? ahc->our_id_b : ahc->our_id)
96#define SIM_PATH(ahc, sim) \
97 (((sim) == ahc->platform_data->sim_b) ? ahc->platform_data->path_b \
98 : ahc->platform_data->path)
99#define BUILD_SCSIID(ahc, sim, target_id, our_id) \
100 ((((target_id) << TID_SHIFT) & TID) | (our_id) \
101 | (SIM_IS_SCSIBUS_B(ahc, sim) ? TWIN_CHNLB : 0))
102
103#define SCB_GET_SIM(ahc, scb) \
104 (SCB_GET_CHANNEL(ahc, scb) == 'A' ? (ahc)->platform_data->sim \
105 : (ahc)->platform_data->sim_b)
106
107#ifndef offsetof
108#define offsetof(type, member) ((size_t)(&((type *)0)->member))
109#endif
984263bc
MD
110
111/************************ Tunable Driver Parameters **************************/
112/*
113 * The number of dma segments supported. The sequencer can handle any number
114 * of physically contiguous S/G entrys. To reduce the driver's memory
115 * consumption, we limit the number supported to be sufficient to handle
116 * the largest mapping supported by the kernel, MAXPHYS. Assuming the
117 * transfer is as fragmented as possible and unaligned, this turns out to
118 * be the number of paged sized transfers in MAXPHYS plus an extra element
119 * to handle any unaligned residual. The sequencer fetches SG elements
120 * in cacheline sized chucks, so make the number per-transaction an even
121 * multiple of 16 which should align us on even the largest of cacheline
122 * boundaries.
123 */
124#define AHC_NSEG (roundup(btoc(MAXPHYS) + 1, 16))
125
126/* This driver supports target mode */
127#define AHC_TARGET_MODE 1
128
129/************************** Softc/SCB Platform Data ***************************/
130struct ahc_platform_data {
131 /*
132 * Hooks into the XPT.
133 */
134 struct cam_sim *sim;
135 struct cam_sim *sim_b;
136 struct cam_path *path;
137 struct cam_path *path_b;
138
139 int regs_res_type;
140 int regs_res_id;
141 int irq_res_type;
142 struct resource *regs;
143 struct resource *irq;
144 void *ih;
145 eventhandler_tag eh;
750f3593 146 struct thread *recovery_thread;
984263bc
MD
147};
148
149struct scb_platform_data {
150};
151
984263bc 152/***************************** Core Includes **********************************/
96ca467d 153#ifdef AHC_REG_PRETTY_PRINT
984263bc
MD
154#define AIC_DEBUG_REGISTERS 1
155#else
156#define AIC_DEBUG_REGISTERS 0
157#endif
750f3593
PA
158#define AIC_CORE_INCLUDE "aic7xxx.h"
159#define AIC_LIB_PREFIX ahc
160#define AIC_CONST_PREFIX AHC
161#include "aic_osm_lib.h"
984263bc
MD
162
163/*************************** Device Access ************************************/
164#define ahc_inb(ahc, port) \
165 bus_space_read_1((ahc)->tag, (ahc)->bsh, port)
166
167#define ahc_outb(ahc, port, value) \
168 bus_space_write_1((ahc)->tag, (ahc)->bsh, port, value)
169
170#define ahc_outsb(ahc, port, valp, count) \
171 bus_space_write_multi_1((ahc)->tag, (ahc)->bsh, port, valp, count)
172
173#define ahc_insb(ahc, port, valp, count) \
174 bus_space_read_multi_1((ahc)->tag, (ahc)->bsh, port, valp, count)
175
176static __inline void ahc_flush_device_writes(struct ahc_softc *);
177
178static __inline void
179ahc_flush_device_writes(struct ahc_softc *ahc)
180{
181 /* XXX Is this sufficient for all architectures??? */
182 ahc_inb(ahc, INTSTAT);
183}
184
185/**************************** Locking Primitives ******************************/
186/* Lock protecting internal data structures */
1cd11320
SW
187static __inline void ahc_lock(void);
188static __inline void ahc_unlock(void);
984263bc
MD
189
190static __inline void
1cd11320 191ahc_lock(void)
984263bc 192{
cb3b8b44 193 crit_enter_id("ahc");
984263bc
MD
194}
195
196static __inline void
1cd11320 197ahc_unlock(void)
984263bc 198{
cb3b8b44 199 crit_exit_id("ahc");
984263bc
MD
200}
201
dff3fb2d
PA
202/************************* Initialization/Teardown ****************************/
203int ahc_platform_alloc(struct ahc_softc *ahc, void *platform_arg);
204void ahc_platform_free(struct ahc_softc *ahc);
205int ahc_map_int(struct ahc_softc *ahc);
206int ahc_attach(struct ahc_softc *);
207int ahc_softc_comp(struct ahc_softc *lahc, struct ahc_softc *rahc);
208int ahc_detach(device_t);
209
984263bc 210/********************************** PCI ***************************************/
750f3593
PA
211#ifdef AIC_PCI_CONFIG
212int ahc_pci_map_registers(struct ahc_softc *ahc);
dff3fb2d 213#define ahc_pci_map_int ahc_map_int
750f3593 214#endif /*AIC_PCI_CONFIG*/
984263bc 215
984263bc
MD
216/******************************** VL/EISA *************************************/
217int aic7770_map_registers(struct ahc_softc *ahc, u_int port);
dff3fb2d
PA
218static __inline int aic7770_map_int(struct ahc_softc *, int);
219
220static __inline int
221aic7770_map_int(struct ahc_softc *ahc, int irq)
222{
223 /*
224 * The IRQ is unused in the FreeBSD
225 * implementation since the EISA and
226 * ISA attachments register the IRQ
227 * with newbus before the core is called.
228 */
229 return ahc_map_int(ahc);
230}
984263bc
MD
231
232/********************************* Debug **************************************/
233static __inline void ahc_print_path(struct ahc_softc *, struct scb *);
234static __inline void ahc_platform_dump_card_state(struct ahc_softc *ahc);
235
236static __inline void
237ahc_print_path(struct ahc_softc *ahc, struct scb *scb)
238{
239 xpt_print_path(scb->io_ctx->ccb_h.path);
240}
241
242static __inline void
243ahc_platform_dump_card_state(struct ahc_softc *ahc)
244{
245 /* Nothing to do here for FreeBSD */
246}
247/**************************** Transfer Settings *******************************/
248void ahc_notify_xfer_settings_change(struct ahc_softc *,
249 struct ahc_devinfo *);
250void ahc_platform_set_tags(struct ahc_softc *, struct ahc_devinfo *,
251 int /*enable*/);
252
984263bc
MD
253/****************************** Interrupts ************************************/
254void ahc_platform_intr(void *);
255static __inline void ahc_platform_flushwork(struct ahc_softc *ahc);
256static __inline void
257ahc_platform_flushwork(struct ahc_softc *ahc)
258{
259}
260
261/************************ Misc Function Declarations **************************/
262void ahc_done(struct ahc_softc *ahc, struct scb *scb);
263void ahc_send_async(struct ahc_softc *, char /*channel*/,
264 u_int /*target*/, u_int /*lun*/, ac_code, void *arg);
265#endif /* _AIC7XXX_FREEBSD_H_ */