MPSAFE locking for the ahc/ahd drivers using lockmgr locks.
[dragonfly.git] / sys / dev / disk / aic7xxx / aic79xx_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 * 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 *
750f3593 33 * $Id: //depot/aic7xxx/freebsd/dev/aic7xxx/aic79xx_osm.h#23 $
984263bc 34 *
fc5262d5 35 * $FreeBSD: src/sys/dev/aic7xxx/aic79xx_osm.h,v 1.18 2005/12/06 11:19:36 ru Exp $
ef8ef949 36 * $DragonFly: src/sys/dev/disk/aic7xxx/aic79xx_osm.h,v 1.12 2008/02/09 18:13:13 pavalos Exp $
984263bc
MD
37 */
38
39#ifndef _AIC79XX_FREEBSD_H_
40#define _AIC79XX_FREEBSD_H_
41
42#include <opt_aic79xx.h> /* for config options */
43
44#include <sys/param.h>
45#include <sys/systm.h>
46#include <sys/bus.h> /* For device_t */
84754cd0 47#if defined(__FreeBSD__) && __FreeBSD_version >= 500000
984263bc
MD
48#include <sys/endian.h>
49#endif
50#include <sys/eventhandler.h>
51#include <sys/kernel.h>
52#include <sys/malloc.h>
53#include <sys/queue.h>
c1139c5e 54#include <sys/thread2.h>
984263bc 55
750f3593 56#define AIC_PCI_CONFIG 1
984263bc
MD
57#include <machine/endian.h>
58#include <machine/clock.h>
984263bc
MD
59
60#include <sys/rman.h>
61
1f2de5d4
MD
62#include <bus/pci/pcireg.h>
63#include <bus/pci/pcivar.h>
984263bc 64
1f2de5d4
MD
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>
984263bc 70
1f2de5d4
MD
71#include <bus/cam/scsi/scsi_all.h>
72#include <bus/cam/scsi/scsi_message.h>
73#include <bus/cam/scsi/scsi_iu.h>
984263bc
MD
74
75#ifdef CAM_NEW_TRAN_CODE
76#define AHD_NEW_TRAN_SETTINGS
77#endif /* CAM_NEW_TRAN_CODE */
78
79/****************************** Platform Macros *******************************/
80#define SIM_IS_SCSIBUS_B(ahd, sim) \
81 (0)
82#define SIM_CHANNEL(ahd, sim) \
83 ('A')
84#define SIM_SCSI_ID(ahd, sim) \
85 (ahd->our_id)
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))
90
91
92#define SCB_GET_SIM(ahd, scb) \
93 ((ahd)->platform_data->sim)
94
95#ifndef offsetof
96#define offsetof(type, member) ((size_t)(&((type *)0)->member))
97#endif
984263bc
MD
98
99/************************ Tunable Driver Parameters **************************/
100/*
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
110 * boundaries.
111 */
112#define AHD_NSEG (roundup(btoc(MAXPHYS) + 1, 16))
113
114/* This driver supports target mode */
9f00895f 115#ifdef NOT_YET
984263bc
MD
116#define AHD_TARGET_MODE 1
117#endif
118
ef8ef949
PA
119/***************************** Core Includes **********************************/
120#ifdef AHD_REG_PRETTY_PRINT
121#define AIC_DEBUG_REGISTERS 1
122#else
123#define AIC_DEBUG_REGISTERS 0
124#endif
125#define AIC_CORE_INCLUDE "aic79xx.h"
126#define AIC_LIB_PREFIX ahd
127#define AIC_CONST_PREFIX AHD
128#include "aic_osm_lib.h"
129
984263bc
MD
130/************************** Softc/SCB Platform Data ***************************/
131struct ahd_platform_data {
132 /*
133 * Hooks into the XPT.
134 */
135 struct cam_sim *sim;
984263bc 136 struct cam_path *path;
984263bc
MD
137
138 int regs_res_type[2];
139 int regs_res_id[2];
140 int irq_res_type;
141 struct resource *regs[2];
142 struct resource *irq;
143 void *ih;
144 eventhandler_tag eh;
750f3593 145 struct thread *recovery_thread;
ef8ef949 146 struct lock lock;
984263bc
MD
147};
148
149struct scb_platform_data {
150};
151
984263bc
MD
152/*************************** Device Access ************************************/
153#define ahd_inb(ahd, port) \
154 bus_space_read_1((ahd)->tags[(port) >> 8], \
155 (ahd)->bshs[(port) >> 8], (port) & 0xFF)
156
157#define ahd_outb(ahd, port, value) \
158 bus_space_write_1((ahd)->tags[(port) >> 8], \
159 (ahd)->bshs[(port) >> 8], (port) & 0xFF, value)
160
161#define ahd_inw_atomic(ahd, port) \
750f3593 162 aic_le16toh(bus_space_read_2((ahd)->tags[(port) >> 8], \
984263bc
MD
163 (ahd)->bshs[(port) >> 8], (port) & 0xFF))
164
165#define ahd_outw_atomic(ahd, port, value) \
166 bus_space_write_2((ahd)->tags[(port) >> 8], \
167 (ahd)->bshs[(port) >> 8], \
750f3593 168 (port & 0xFF), aic_htole16(value))
984263bc
MD
169
170#define ahd_outsb(ahd, port, valp, count) \
171 bus_space_write_multi_1((ahd)->tags[(port) >> 8], \
172 (ahd)->bshs[(port) >> 8], \
173 (port & 0xFF), valp, count)
174
175#define ahd_insb(ahd, port, valp, count) \
176 bus_space_read_multi_1((ahd)->tags[(port) >> 8], \
177 (ahd)->bshs[(port) >> 8], \
178 (port & 0xFF), valp, count)
179
180static __inline void ahd_flush_device_writes(struct ahd_softc *);
181
182static __inline void
183ahd_flush_device_writes(struct ahd_softc *ahd)
184{
185 /* XXX Is this sufficient for all architectures??? */
186 ahd_inb(ahd, INTSTAT);
187}
188
189/**************************** Locking Primitives ******************************/
190/* Lock protecting internal data structures */
ef8ef949
PA
191static __inline void ahd_lockinit(struct ahd_softc *);
192static __inline void ahd_lock(struct ahd_softc *);
193static __inline void ahd_unlock(struct ahd_softc *);
194
195static __inline void
196ahd_lockinit(struct ahd_softc *ahd)
197{
198 lockinit(&ahd->platform_data->lock, "ahd_lock", 0, LK_EXCLUSIVE|LK_CANRECURSE);
199}
984263bc
MD
200
201static __inline void
ef8ef949 202ahd_lock(struct ahd_softc *ahd)
984263bc 203{
ef8ef949 204 lockmgr(&ahd->platform_data->lock, LK_EXCLUSIVE);
984263bc
MD
205}
206
207static __inline void
ef8ef949 208ahd_unlock(struct ahd_softc *ahd)
984263bc 209{
ef8ef949 210 lockmgr(&ahd->platform_data->lock, LK_RELEASE);
984263bc
MD
211}
212
750f3593
PA
213/********************************** PCI ***************************************/
214int ahd_pci_map_registers(struct ahd_softc *ahd);
215int ahd_pci_map_int(struct ahd_softc *ahd);
984263bc
MD
216
217/************************** Transaction Operations ****************************/
750f3593
PA
218static __inline void aic_freeze_simq(struct aic_softc*);
219static __inline void aic_release_simq(struct aic_softc*);
984263bc
MD
220
221static __inline void
750f3593 222aic_freeze_simq(struct aic_softc *aic)
984263bc 223{
750f3593 224 xpt_freeze_simq(aic->platform_data->sim, /*count*/1);
984263bc
MD
225}
226
227static __inline void
750f3593 228aic_release_simq(struct aic_softc *aic)
984263bc 229{
750f3593 230 xpt_release_simq(aic->platform_data->sim, /*run queue*/TRUE);
984263bc
MD
231}
232
984263bc
MD
233/********************************* Debug **************************************/
234static __inline void ahd_print_path(struct ahd_softc *, struct scb *);
235static __inline void ahd_platform_dump_card_state(struct ahd_softc *ahd);
236
237static __inline void
238ahd_print_path(struct ahd_softc *ahd, struct scb *scb)
239{
240 xpt_print_path(scb->io_ctx->ccb_h.path);
241}
242
243static __inline void
244ahd_platform_dump_card_state(struct ahd_softc *ahd)
245{
246 /* Nothing to do here for FreeBSD */
247}
248/**************************** Transfer Settings *******************************/
249void ahd_notify_xfer_settings_change(struct ahd_softc *,
250 struct ahd_devinfo *);
251void ahd_platform_set_tags(struct ahd_softc *, struct ahd_devinfo *,
252 int /*enable*/);
253
254/************************* Initialization/Teardown ****************************/
255int ahd_platform_alloc(struct ahd_softc *ahd, void *platform_arg);
256void ahd_platform_free(struct ahd_softc *ahd);
257int ahd_map_int(struct ahd_softc *ahd);
258int ahd_attach(struct ahd_softc *);
259int ahd_softc_comp(struct ahd_softc *lahd, struct ahd_softc *rahd);
260int ahd_detach(device_t);
261#define ahd_platform_init(arg)
262
263
264/****************************** Interrupts ************************************/
265void ahd_platform_intr(void *);
266static __inline void ahd_platform_flushwork(struct ahd_softc *ahd);
267static __inline void
268ahd_platform_flushwork(struct ahd_softc *ahd)
269{
270}
271
272/************************ Misc Function Declarations **************************/
273void ahd_done(struct ahd_softc *ahd, struct scb *scb);
274void ahd_send_async(struct ahd_softc *, char /*channel*/,
275 u_int /*target*/, u_int /*lun*/, ac_code, void *arg);
276#endif /* _AIC79XX_FREEBSD_H_ */