aic79xx_openbsd.h revision 1.5
1/*	$OpenBSD: aic79xx_openbsd.h,v 1.5 2004/08/23 20:16:01 marco 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/proc.h>
78#include <sys/queue.h>
79
80#define AIC_PCI_CONFIG 1
81#include <dev/pci/pcireg.h>
82#include <dev/pci/pcivar.h>
83
84#include <machine/bus.h>
85#include <machine/intr.h>
86
87#include <scsi/scsi_all.h>
88#include <scsi/scsi_message.h>
89#include <scsi/scsi_debug.h>
90#include <scsi/scsiconf.h>
91
92#include <uvm/uvm_extern.h>
93
94#ifdef DEBUG
95#define bootverbose     1
96#else
97#define bootverbose     0
98#endif
99/****************************** Platform Macros *******************************/
100#define	SCSI_IS_SCSIBUS_B(ahd, sc_link)	\
101	(0)
102#define	SCSI_CHANNEL(ahd, sc_link)	\
103	('A')
104#define	SCSI_SCSI_ID(ahd, sc_link)	\
105	(ahd->our_id)
106#define BUILD_SCSIID(ahd, sc_link, target_id, our_id) \
107        ((((target_id) << TID_SHIFT) & TID) | (our_id))
108
109#ifndef offsetof
110#define offsetof(type, member)  ((size_t)(&((type *)0)->member))
111#endif
112
113/************************* Forward Declarations *******************************/
114typedef struct pci_attach_args * ahd_dev_softc_t;
115
116/***************************** Bus Space/DMA **********************************/
117
118/* XXX Need to update Bus DMA for partial map syncs */
119#define ahd_dmamap_sync(ahc, dma_tag, dmamap, offset, len, op)		\
120	bus_dmamap_sync(dma_tag, dmamap, offset, len, op)
121
122/************************ Tunable Driver Parameters  **************************/
123/*
124 * The number of dma segments supported.  The sequencer can handle any number
125 * of physically contiguous S/G entrys.  To reduce the driver's memory
126 * consumption, we limit the number supported to be sufficient to handle
127 * the largest mapping supported by the kernel, MAXPHYS.  Assuming the
128 * transfer is as fragmented as possible and unaligned, this turns out to
129 * be the number of paged sized transfers in MAXPHYS plus an extra element
130 * to handle any unaligned residual.  The sequencer fetches SG elements
131 * in cacheline sized chucks, so make the number per-transaction an even
132 * multiple of 16 which should align us on even the largest of cacheline
133 * boundaries.
134 */
135#define AHD_NSEG (roundup(btoc(MAXPHYS) + 1, 16))
136
137/* This driver supports target mode */
138// #define AHD_TARGET_MODE 1
139
140/************************** Softc/SCB Platform Data ***************************/
141struct ahd_platform_data {
142};
143
144struct scb_platform_data {
145};
146
147/********************************* Byte Order *********************************/
148#define ahd_htobe16(x) htobe16(x)
149#define ahd_htobe32(x) htobe32(x)
150#define ahd_htobe64(x) htobe64(x)
151#define ahd_htole16(x) htole16(x)
152#define ahd_htole32(x) htole32(x)
153#define ahd_htole64(x) htole64(x)
154
155#define ahd_be16toh(x) be16toh(x)
156#define ahd_be32toh(x) be32toh(x)
157#define ahd_be64toh(x) be64toh(x)
158#define ahd_le16toh(x) letoh16(x)
159#define ahd_le32toh(x) letoh32(x)
160#define ahd_le64toh(x) letoh64(x)
161
162/************************** Timer DataStructures ******************************/
163typedef struct timeout ahd_timer_t;
164
165/***************************** Core Includes **********************************/
166
167#if AHD_REG_PRETTY_PRINT
168#define AIC_DEBUG_REGISTERS 1
169#else
170#define AIC_DEBUG_REGISTERS 0
171#endif
172#include <dev/ic/aic79xx.h>
173
174/***************************** Timer Facilities *******************************/
175void ahd_timeout(void*);
176void ahd_timer_reset(ahd_timer_t *, u_int, ahd_callback_t *, void *);
177void ahd_scb_timer_reset(struct scb *, u_int);
178
179ahd_callback_t  ahd_reset_poll;
180ahd_callback_t  ahd_stat_timer;
181
182#define ahd_timer_init callout_init
183#define ahd_timer_stop callout_stop
184
185/*************************** Device Access ************************************/
186#define ahd_inb(ahd, port)					\
187	bus_space_read_1((ahd)->tags[(port) >> 8],		\
188			 (ahd)->bshs[(port) >> 8], (port) & 0xFF)
189
190#define ahd_outb(ahd, port, value)				\
191	bus_space_write_1((ahd)->tags[(port) >> 8],		\
192			  (ahd)->bshs[(port) >> 8], (port) & 0xFF, value)
193
194#define ahd_inw_atomic(ahd, port)				\
195	ahd_le16toh(bus_space_read_2((ahd)->tags[(port) >> 8],	\
196				     (ahd)->bshs[(port) >> 8], (port) & 0xFF))
197
198#define ahd_outw_atomic(ahd, port, value)			\
199	bus_space_write_2((ahd)->tags[(port) >> 8],		\
200			  (ahd)->bshs[(port) >> 8],		\
201			  (port & 0xFF), ahd_htole16(value))
202
203#define ahd_outsb(ahd, port, valp, count)			\
204	bus_space_write_multi_1((ahd)->tags[(port) >> 8],	\
205				(ahd)->bshs[(port) >> 8],	\
206				(port & 0xFF), valp, count)
207
208#define ahd_insb(ahd, port, valp, count)			\
209	bus_space_read_multi_1((ahd)->tags[(port) >> 8],	\
210			       (ahd)->bshs[(port) >> 8],	\
211			       (port & 0xFF), valp, count)
212
213void ahd_flush_device_writes(struct ahd_softc *);
214
215/**************************** Locking Primitives ******************************/
216/* Lock protecting internal data structures */
217void ahd_lockinit(struct ahd_softc *);
218void ahd_lock(struct ahd_softc *, int *flags);
219void ahd_unlock(struct ahd_softc *, int *flags);
220
221/* Lock held during command compeletion to the upper layer */
222void ahd_done_lockinit(struct ahd_softc *);
223void ahd_done_lock(struct ahd_softc *, int *flags);
224void ahd_done_unlock(struct ahd_softc *, int *flags);
225
226/* Lock held during ahd_list manipulation and ahd softc frees */
227void ahd_list_lockinit(void);
228void ahd_list_lock(int *flags);
229void ahd_list_unlock(int *flags);
230
231/****************************** OS Primitives *********************************/
232#define ahd_delay DELAY
233
234/************************** Transaction Operations ****************************/
235void ahd_set_transaction_status(struct scb *, uint32_t);
236void ahd_set_scsi_status(struct scb *, uint32_t);
237uint32_t ahd_get_transaction_status(struct scb *);
238uint32_t ahd_get_scsi_status(struct scb *);
239void ahd_set_transaction_tag(struct scb *, int, u_int);
240u_long ahd_get_transfer_length(struct scb *);
241int ahd_get_transfer_dir(struct scb *);
242void ahd_set_residual(struct scb *, u_long);
243void ahd_set_sense_residual(struct scb *, u_long);
244u_long ahd_get_residual(struct scb *);
245int ahd_perform_autosense(struct scb *);
246uint32_t ahd_get_sense_bufsize(struct ahd_softc*, struct scb*);
247void ahd_freeze_simq(struct ahd_softc *);
248void ahd_release_simq(struct ahd_softc *);
249void ahd_freeze_scb(struct scb *);
250void ahd_platform_freeze_devq(struct ahd_softc *, struct scb *);
251int  ahd_platform_abort_scbs(struct ahd_softc *, int,
252		    char, int, u_int, role_t, uint32_t);
253void ahd_platform_scb_free(struct ahd_softc *, struct scb *);
254
255/********************************** PCI ***************************************/
256/*#if AHD_PCI_CONFIG > 0*/
257uint32_t ahd_pci_read_config(ahd_dev_softc_t, int, int);
258void	ahd_pci_write_config(ahd_dev_softc_t, int,
259		uint32_t, int);
260int	ahd_get_pci_function(ahd_dev_softc_t);
261int	ahd_get_pci_slot(ahd_dev_softc_t);
262int	ahd_get_pci_bus(ahd_dev_softc_t);
263
264int			ahd_pci_map_registers(struct ahd_softc *);
265int			ahd_pci_map_int(struct ahd_softc *);
266/*#endif*/
267
268typedef enum
269{
270	AHD_POWER_STATE_D0,
271	AHD_POWER_STATE_D1,
272	AHD_POWER_STATE_D2,
273	AHD_POWER_STATE_D3
274} ahd_power_state;
275
276void ahd_power_state_change(struct ahd_softc *, ahd_power_state);
277
278/******************************** VL/EISA *************************************/
279int aic7770_map_registers(struct ahd_softc *);
280int aic7770_map_int(struct ahd_softc *, int);
281
282/********************************* Debug **************************************/
283void	ahd_print_path(struct ahd_softc *, struct scb *);
284void	ahd_platform_dump_card_state(struct ahd_softc *ahd);
285
286/**************************** Transfer Settings *******************************/
287void	  ahd_notify_xfer_settings_change(struct ahd_softc *,
288					  struct ahd_devinfo *);
289void	  ahd_platform_set_tags(struct ahd_softc *, struct ahd_devinfo *,
290				ahd_queue_alg);
291
292/************************* Initialization/Teardown ****************************/
293int	  ahd_platform_alloc(struct ahd_softc *, void *);
294void	  ahd_platform_free(struct ahd_softc *);
295int	  ahd_attach(struct ahd_softc *);
296int	  ahd_softc_comp(struct ahd_softc *lahd, struct ahd_softc *rahd);
297int	  ahd_detach(struct device *, int);
298#define	ahd_platform_init
299
300/****************************** Interrupts ************************************/
301int			ahd_platform_intr(void *);
302void	ahd_platform_flushwork(struct ahd_softc *ahd);
303/************************ Misc Function Declarations **************************/
304void	  ahd_done(struct ahd_softc *, struct scb *);
305void	  ahd_send_async(struct ahd_softc *, char /*channel*/,
306			 u_int /*target*/, u_int /*lun*/, ac_code, void *arg);
307/************************ SCSI task management **************************/
308#define SIU_TASKMGMT_NONE               0x00
309#define SIU_TASKMGMT_ABORT_TASK         0x01
310#define SIU_TASKMGMT_ABORT_TASK_SET     0x02
311#define SIU_TASKMGMT_CLEAR_TASK_SET     0x04
312#define SIU_TASKMGMT_LUN_RESET          0x08
313#define SIU_TASKMGMT_TARGET_RESET       0x20
314#define SIU_TASKMGMT_CLEAR_ACA          0x40
315#endif  /* _AIC79XX_OPENBSD_H_ */
316