aic79xx_openbsd.h revision 1.20
1/*	$OpenBSD: aic79xx_openbsd.h,v 1.20 2017/12/12 12:33:36 krw Exp $	*/
2
3/*
4 * Copyright (c) 2004 Milos Urbanek, Kenneth R. Westerback & Marco Peereboom
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 *
28 */
29
30/*
31 * FreeBSD platform specific driver option settings, data structures,
32 * function declarations and includes.
33 *
34 * Copyright (c) 1994-2001 Justin T. Gibbs.
35 * Copyright (c) 2001-2002 Adaptec Inc.
36 * All rights reserved.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 * 1. Redistributions of source code must retain the above copyright
42 *    notice, this list of conditions, and the following disclaimer,
43 *    without modification.
44 * 2. The name of the author may not be used to endorse or promote products
45 *    derived from this software without specific prior written permission.
46 *
47 * Alternatively, this software may be distributed under the terms of the
48 * GNU Public License ("GPL").
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
51 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
54 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * SUCH DAMAGE.
61 *
62 * $FreeBSD: src/sys/dev/aic7xxx/aic79xx_osm.h,v 1.13 2003/12/17 00:02:09 gibbs Exp $
63 *
64 */
65
66#ifndef _AIC79XX_OPENBSD_H_
67#define _AIC79XX_OPENBSD_H_
68
69#include "pci.h"		/* for config options */
70
71#include <sys/param.h>
72#include <sys/kernel.h>
73#include <sys/systm.h>
74#include <sys/device.h>
75#include <sys/malloc.h>
76#include <sys/buf.h>
77#include <sys/queue.h>
78
79#define AIC_PCI_CONFIG 1
80#include <dev/pci/pcireg.h>
81#include <dev/pci/pcivar.h>
82
83#include <machine/bus.h>
84#include <machine/intr.h>
85
86#include <scsi/scsi_all.h>
87#include <scsi/scsi_message.h>
88#include <scsi/scsi_debug.h>
89#include <scsi/scsiconf.h>
90
91#include <uvm/uvm_extern.h>
92
93#ifdef DEBUG
94#define bootverbose     1
95#else
96#define bootverbose     0
97#endif
98/****************************** Platform Macros *******************************/
99#define	SCSI_IS_SCSIBUS_B(ahd, sc_link)	\
100	(0)
101#define	SCSI_CHANNEL(ahd, sc_link)	\
102	('A')
103#define	SCSI_SCSI_ID(ahd, sc_link)	\
104	(ahd->our_id)
105#define BUILD_SCSIID(ahd, sc_link, target_id, our_id) \
106	((((target_id) << TID_SHIFT) & TID) | (our_id))
107
108#ifndef offsetof
109#define offsetof(type, member)  ((size_t)(&((type *)0)->member))
110#endif
111
112/************************* Forward Declarations *******************************/
113typedef struct pci_attach_args * ahd_dev_softc_t;
114
115/***************************** Bus Space/DMA **********************************/
116
117/* XXX Need to update Bus DMA for partial map syncs */
118#define ahd_dmamap_sync(ahc, dma_tag, dmamap, offset, len, op)		\
119	bus_dmamap_sync(dma_tag, dmamap, offset, len, op)
120
121/************************ Tunable Driver Parameters  **************************/
122/*
123 * The number of dma segments supported.  The sequencer can handle any number
124 * of physically contiguous S/G entries.  To reduce the driver's memory
125 * consumption, we limit the number supported to be sufficient to handle
126 * the largest mapping supported by the kernel, MAXPHYS.  Assuming the
127 * transfer is as fragmented as possible and unaligned, this turns out to
128 * be the number of paged sized transfers in MAXPHYS plus an extra element
129 * to handle any unaligned residual.  The sequencer fetches SG elements
130 * in cacheline sized chucks, so make the number per-transaction an even
131 * multiple of 16 which should align us on even the largest of cacheline
132 * boundaries.
133 */
134#define AHD_NSEG (roundup(atop(MAXPHYS) + 1, 16))
135
136/* This driver supports target mode */
137// #define AHD_TARGET_MODE 1
138
139/************************** Timer DataStructures ******************************/
140typedef struct timeout aic_timer_t;
141
142/***************************** Core Includes **********************************/
143
144#if AHD_REG_PRETTY_PRINT
145#define AIC_DEBUG_REGISTERS 1
146#else
147#define AIC_DEBUG_REGISTERS 0
148#endif
149#include <dev/ic/aic79xx.h>
150
151/***************************** Timer Facilities *******************************/
152void ahd_timeout(void*);
153void aic_timer_reset(aic_timer_t *, u_int, ahd_callback_t *, void *);
154void aic_scb_timer_reset(struct scb *, u_int);
155
156#define aic_timer_stop timeout_del
157#define aic_get_timeout(scb) ((scb)->xs->timeout)
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
186void ahd_flush_device_writes(struct ahd_softc *);
187
188/**************************** Locking Primitives ******************************/
189/* Lock protecting internal data structures */
190#define ahd_lockinit(ahd)
191#define ahd_lock(ahd, flags) *(flags) = splbio()
192#define ahd_unlock(ahd, flags) splx(*(flags))
193
194/* Lock held during command completion to the upper layer */
195#define ahd_done_lockinit(ahd)
196#define ahd_done_lock(ahd, flags)
197#define ahd_done_unlock(ahd, flags)
198
199/* Lock held during ahd_list manipulation and ahd softc frees */
200#define ahd_list_lockinit(x)
201#define ahd_list_lock(flags) *(flags) = splbio()
202#define ahd_list_unlock(flags) splx(*(flags))
203
204/****************************** OS Primitives *********************************/
205#define scsi_4btoul(b)	(_4btol(b))
206
207/************************** Transaction Operations ****************************/
208#define aic_set_transaction_status(scb, status) (scb)->xs->error = (status)
209#define aic_set_scsi_status(scb, status) (scb)->xs->xs_status = (status)
210#define aic_set_transaction_tag(scb, enabled, type)
211#define aic_set_residual(scb, residual) (scb)->xs->resid = (residual)
212#define aic_set_sense_residual(scb, residual) (scb)->xs->resid = (residual)
213
214#define aic_get_transaction_status(scb) \
215	(((scb)->xs->flags & ITSDONE) ? CAM_REQ_CMP : (scb)->xs->error)
216#define aic_get_scsi_status(scb) ((scb)->xs->status)
217#define aic_get_transfer_length(scb) ((scb)->xs->datalen)
218#define aic_get_transfer_dir(scb) \
219	((scb)->xs->flags & (SCSI_DATA_IN | SCSI_DATA_OUT))
220#define aic_get_residual(scb) ((scb)->xs->resid)
221#define aic_get_sense_bufsize(ahd, scb) (sizeof(struct scsi_sense_data))
222
223#define aic_perform_autosense(scb) (1)
224
225#define aic_freeze_simq(ahd)
226#define aic_release_simq(ahd)
227#define aic_freeze_scb(scb)
228
229void aic_platform_scb_free(struct ahd_softc *, struct scb *);
230
231/********************************** PCI ***************************************/
232/*#if AHD_PCI_CONFIG > 0*/
233#define aic_get_pci_function(pci) ((pci)->pa_function)
234#define aic_get_pci_slot(pci) ((pci)->pa_device)
235#define aic_get_pci_bus(pci) ((pci)->pa_bus)
236
237int			ahd_pci_map_registers(struct ahd_softc *);
238int			ahd_pci_map_int(struct ahd_softc *);
239/*#endif*/
240
241typedef enum
242{
243	AHD_POWER_STATE_D0,
244	AHD_POWER_STATE_D1,
245	AHD_POWER_STATE_D2,
246	AHD_POWER_STATE_D3
247} ahd_power_state;
248
249void ahd_power_state_change(struct ahd_softc *, ahd_power_state);
250
251/********************************* Debug **************************************/
252void	ahd_print_path(struct ahd_softc *, struct scb *);
253void	ahd_platform_dump_card_state(struct ahd_softc *ahd);
254
255/**************************** Transfer Settings *******************************/
256void	  ahd_notify_xfer_settings_change(struct ahd_softc *,
257					  struct ahd_devinfo *);
258void	  ahd_platform_set_tags(struct ahd_softc *, struct ahd_devinfo *,
259				ahd_queue_alg);
260
261/************************* Initialization/Teardown ****************************/
262int	  ahd_attach(struct ahd_softc *);
263int	  ahd_softc_comp(struct ahd_softc *lahd, struct ahd_softc *rahd);
264int	  ahd_detach(struct device *, int);
265
266/****************************** Interrupts ************************************/
267int			ahd_platform_intr(void *);
268
269/************************ Misc Function Declarations **************************/
270void	  ahd_done(struct ahd_softc *, struct scb *);
271void	  ahd_send_async(struct ahd_softc *, char /*channel*/,
272			 u_int /*target*/, u_int /*lun*/, ac_code, void *arg);
273#endif  /* _AIC79XX_OPENBSD_H_ */
274