xref: /openbsd/sys/dev/ic/aic79xx_openbsd.h (revision 4431c8f9)
1*4431c8f9Smiod /*	$OpenBSD: aic79xx_openbsd.h,v 1.16 2005/12/10 11:45:43 miod Exp $	*/
26dab29ddSmarco 
36dab29ddSmarco /*
46dab29ddSmarco  * Copyright (c) 2004 Milos Urbanek, Kenneth R. Westerback & Marco Peereboom
56dab29ddSmarco  * All rights reserved.
66dab29ddSmarco  *
76dab29ddSmarco  * Redistribution and use in source and binary forms, with or without
86dab29ddSmarco  * modification, are permitted provided that the following conditions
96dab29ddSmarco  * are met:
106dab29ddSmarco  * 1. Redistributions of source code must retain the above copyright
116dab29ddSmarco  *    notice, this list of conditions and the following disclaimer.
126dab29ddSmarco  * 2. Redistributions in binary form must reproduce the above copyright
136dab29ddSmarco  *    notice, this list of conditions and the following disclaimer in the
146dab29ddSmarco  *    documentation and/or other materials provided with the distribution.
156dab29ddSmarco  *
166dab29ddSmarco  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
176dab29ddSmarco  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
186dab29ddSmarco  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
196dab29ddSmarco  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
206dab29ddSmarco  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
216dab29ddSmarco  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
226dab29ddSmarco  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
236dab29ddSmarco  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
246dab29ddSmarco  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
256dab29ddSmarco  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
266dab29ddSmarco  * SUCH DAMAGE.
276dab29ddSmarco  *
286dab29ddSmarco  */
296dab29ddSmarco 
3056007914Smarco /*
3156007914Smarco  * FreeBSD platform specific driver option settings, data structures,
3256007914Smarco  * function declarations and includes.
3356007914Smarco  *
3456007914Smarco  * Copyright (c) 1994-2001 Justin T. Gibbs.
3556007914Smarco  * Copyright (c) 2001-2002 Adaptec Inc.
3656007914Smarco  * All rights reserved.
3756007914Smarco  *
3856007914Smarco  * Redistribution and use in source and binary forms, with or without
3956007914Smarco  * modification, are permitted provided that the following conditions
4056007914Smarco  * are met:
4156007914Smarco  * 1. Redistributions of source code must retain the above copyright
4256007914Smarco  *    notice, this list of conditions, and the following disclaimer,
4356007914Smarco  *    without modification.
4456007914Smarco  * 2. The name of the author may not be used to endorse or promote products
4556007914Smarco  *    derived from this software without specific prior written permission.
4656007914Smarco  *
4756007914Smarco  * Alternatively, this software may be distributed under the terms of the
4856007914Smarco  * GNU Public License ("GPL").
4956007914Smarco  *
5056007914Smarco  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
5156007914Smarco  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5256007914Smarco  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
5356007914Smarco  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
5456007914Smarco  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
5556007914Smarco  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
5656007914Smarco  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
5756007914Smarco  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
5856007914Smarco  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
5956007914Smarco  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
6056007914Smarco  * SUCH DAMAGE.
6156007914Smarco  *
6256007914Smarco  * $FreeBSD: src/sys/dev/aic7xxx/aic79xx_osm.h,v 1.13 2003/12/17 00:02:09 gibbs Exp $
6356007914Smarco  *
6456007914Smarco  */
6556007914Smarco 
6656007914Smarco #ifndef _AIC79XX_OPENBSD_H_
6756007914Smarco #define _AIC79XX_OPENBSD_H_
6856007914Smarco 
6956007914Smarco #include "pci.h"		/* for config options */
7056007914Smarco 
7156007914Smarco #include <sys/param.h>
7256007914Smarco #include <sys/kernel.h>
7356007914Smarco #include <sys/systm.h>
7456007914Smarco #include <sys/device.h>
7556007914Smarco #include <sys/malloc.h>
7656007914Smarco #include <sys/buf.h>
7756007914Smarco #include <sys/proc.h>
7856007914Smarco #include <sys/queue.h>
7956007914Smarco 
8056007914Smarco #define AIC_PCI_CONFIG 1
8156007914Smarco #include <dev/pci/pcireg.h>
8256007914Smarco #include <dev/pci/pcivar.h>
8356007914Smarco 
8456007914Smarco #include <machine/bus.h>
8556007914Smarco #include <machine/intr.h>
8656007914Smarco 
8756007914Smarco #include <scsi/scsi_all.h>
8856007914Smarco #include <scsi/scsi_message.h>
8956007914Smarco #include <scsi/scsi_debug.h>
9056007914Smarco #include <scsi/scsiconf.h>
9156007914Smarco 
9256007914Smarco #include <uvm/uvm_extern.h>
9356007914Smarco 
9456007914Smarco #ifdef DEBUG
9556007914Smarco #define bootverbose     1
9656007914Smarco #else
9756007914Smarco #define bootverbose     0
9856007914Smarco #endif
9956007914Smarco /****************************** Platform Macros *******************************/
10056007914Smarco #define	SCSI_IS_SCSIBUS_B(ahd, sc_link)	\
10156007914Smarco 	(0)
10256007914Smarco #define	SCSI_CHANNEL(ahd, sc_link)	\
10356007914Smarco 	('A')
10456007914Smarco #define	SCSI_SCSI_ID(ahd, sc_link)	\
10556007914Smarco 	(ahd->our_id)
10656007914Smarco #define BUILD_SCSIID(ahd, sc_link, target_id, our_id) \
10756007914Smarco 	((((target_id) << TID_SHIFT) & TID) | (our_id))
10856007914Smarco 
10956007914Smarco #ifndef offsetof
11056007914Smarco #define offsetof(type, member)  ((size_t)(&((type *)0)->member))
11156007914Smarco #endif
11256007914Smarco 
113cfe61e4dSmarco /************************* Forward Declarations *******************************/
114cfe61e4dSmarco typedef struct pci_attach_args * ahd_dev_softc_t;
11556007914Smarco 
11656007914Smarco /***************************** Bus Space/DMA **********************************/
11756007914Smarco 
11856007914Smarco /* XXX Need to update Bus DMA for partial map syncs */
11956007914Smarco #define ahd_dmamap_sync(ahc, dma_tag, dmamap, offset, len, op)		\
12056007914Smarco 	bus_dmamap_sync(dma_tag, dmamap, offset, len, op)
12156007914Smarco 
12256007914Smarco /************************ Tunable Driver Parameters  **************************/
12356007914Smarco /*
12456007914Smarco  * The number of dma segments supported.  The sequencer can handle any number
125*4431c8f9Smiod  * of physically contiguous S/G entries.  To reduce the driver's memory
12656007914Smarco  * consumption, we limit the number supported to be sufficient to handle
12756007914Smarco  * the largest mapping supported by the kernel, MAXPHYS.  Assuming the
12856007914Smarco  * transfer is as fragmented as possible and unaligned, this turns out to
12956007914Smarco  * be the number of paged sized transfers in MAXPHYS plus an extra element
13056007914Smarco  * to handle any unaligned residual.  The sequencer fetches SG elements
13156007914Smarco  * in cacheline sized chucks, so make the number per-transaction an even
13256007914Smarco  * multiple of 16 which should align us on even the largest of cacheline
13356007914Smarco  * boundaries.
13456007914Smarco  */
13556007914Smarco #define AHD_NSEG (roundup(btoc(MAXPHYS) + 1, 16))
13656007914Smarco 
13756007914Smarco /* This driver supports target mode */
13856007914Smarco // #define AHD_TARGET_MODE 1
13956007914Smarco 
14056007914Smarco /************************** Softc/SCB Platform Data ***************************/
14156007914Smarco struct ahd_platform_data {
14256007914Smarco };
14356007914Smarco 
14456007914Smarco struct scb_platform_data {
14556007914Smarco };
14656007914Smarco 
14756007914Smarco /************************** Timer DataStructures ******************************/
148f8f66019Skrw typedef struct timeout aic_timer_t;
14956007914Smarco 
15056007914Smarco /***************************** Core Includes **********************************/
15156007914Smarco 
15256007914Smarco #if AHD_REG_PRETTY_PRINT
15356007914Smarco #define AIC_DEBUG_REGISTERS 1
15456007914Smarco #else
15556007914Smarco #define AIC_DEBUG_REGISTERS 0
15656007914Smarco #endif
15756007914Smarco #include <dev/ic/aic79xx.h>
15856007914Smarco 
15956007914Smarco /***************************** Timer Facilities *******************************/
16056007914Smarco void ahd_timeout(void*);
1610a7a9938Skrw void aic_timer_reset(aic_timer_t *, u_int, ahd_callback_t *, void *);
162f8f66019Skrw void aic_scb_timer_reset(struct scb *, u_int);
16356007914Smarco 
164f8f66019Skrw #define aic_timer_stop timeout_del
1652a53356eSkrw #define aic_get_timeout(scb) ((scb)->xs->timeout)
16656007914Smarco /*************************** Device Access ************************************/
16756007914Smarco #define ahd_inb(ahd, port)					\
16856007914Smarco 	bus_space_read_1((ahd)->tags[(port) >> 8],		\
16956007914Smarco 			 (ahd)->bshs[(port) >> 8], (port) & 0xFF)
17056007914Smarco 
17156007914Smarco #define ahd_outb(ahd, port, value)				\
17256007914Smarco 	bus_space_write_1((ahd)->tags[(port) >> 8],		\
17356007914Smarco 			  (ahd)->bshs[(port) >> 8], (port) & 0xFF, value)
17456007914Smarco 
17556007914Smarco #define ahd_inw_atomic(ahd, port)				\
176b1b2b63cSkrw 	aic_le16toh(bus_space_read_2((ahd)->tags[(port) >> 8],	\
17756007914Smarco 				     (ahd)->bshs[(port) >> 8], (port) & 0xFF))
17856007914Smarco 
17956007914Smarco #define ahd_outw_atomic(ahd, port, value)			\
18056007914Smarco 	bus_space_write_2((ahd)->tags[(port) >> 8],		\
18156007914Smarco 			  (ahd)->bshs[(port) >> 8],		\
182b1b2b63cSkrw 			  (port & 0xFF), aic_htole16(value))
18356007914Smarco 
18456007914Smarco #define ahd_outsb(ahd, port, valp, count)			\
18556007914Smarco 	bus_space_write_multi_1((ahd)->tags[(port) >> 8],	\
18656007914Smarco 				(ahd)->bshs[(port) >> 8],	\
18756007914Smarco 				(port & 0xFF), valp, count)
18856007914Smarco 
18956007914Smarco #define ahd_insb(ahd, port, valp, count)			\
19056007914Smarco 	bus_space_read_multi_1((ahd)->tags[(port) >> 8],	\
19156007914Smarco 			       (ahd)->bshs[(port) >> 8],	\
19256007914Smarco 			       (port & 0xFF), valp, count)
19356007914Smarco 
194e5238fd1Smarco void ahd_flush_device_writes(struct ahd_softc *);
19556007914Smarco 
19656007914Smarco /**************************** Locking Primitives ******************************/
19756007914Smarco /* Lock protecting internal data structures */
198f8f66019Skrw #define ahd_lockinit(ahd)
199f8f66019Skrw #define ahd_lock(ahd, flags) *(flags) = splbio()
200f8f66019Skrw #define ahd_unlock(ahd, flags) splx(*(flags))
20156007914Smarco 
202f8f66019Skrw /* Lock held during command completion to the upper layer */
203f8f66019Skrw #define ahd_done_lockinit(ahd)
204f8f66019Skrw #define ahd_done_lock(ahd, flags)
205f8f66019Skrw #define ahd_done_unlock(ahd, flags)
20656007914Smarco 
20756007914Smarco /* Lock held during ahd_list manipulation and ahd softc frees */
208f8f66019Skrw #define ahd_list_lockinit(x)
209f8f66019Skrw #define ahd_list_lock(flags) *(flags) = splbio()
210f8f66019Skrw #define ahd_list_unlock(flags) splx(*(flags))
21156007914Smarco 
21256007914Smarco /****************************** OS Primitives *********************************/
213c4ff7968Skrw #define scsi_4btoul(b)	(_4btol(b))
21456007914Smarco 
21556007914Smarco /************************** Transaction Operations ****************************/
216f8f66019Skrw #define aic_set_transaction_status(scb, status) (scb)->xs->error = (status)
217f8f66019Skrw #define aic_set_scsi_status(scb, status) (scb)->xs->xs_status = (status)
218f8f66019Skrw #define aic_set_transaction_tag(scb, enabled, type)
219f8f66019Skrw #define aic_set_residual(scb, residual) (scb)->xs->resid = (residual)
220f8f66019Skrw #define aic_set_sense_residual(scb, residual) (scb)->xs->resid = (residual)
221f8f66019Skrw 
222f8f66019Skrw #define aic_get_transaction_status(scb) \
223f8f66019Skrw 	(((scb)->xs->flags & ITSDONE) ? CAM_REQ_CMP : (scb)->xs->error)
224f8f66019Skrw #define aic_get_scsi_status(scb) ((scb)->xs->status)
225f8f66019Skrw #define aic_get_transfer_length(scb) ((scb)->xs->datalen)
226f8f66019Skrw #define aic_get_transfer_dir(scb) \
227f8f66019Skrw 	((scb)->xs->flags & (SCSI_DATA_IN | SCSI_DATA_OUT))
228f8f66019Skrw #define aic_get_residual(scb) ((scb)->xs->resid)
229f8f66019Skrw #define aic_get_sense_bufsize(ahd, scb) (sizeof(struct scsi_sense_data))
230f8f66019Skrw 
231f8f66019Skrw #define aic_perform_autosense(scb) (1)
232f8f66019Skrw 
233f8f66019Skrw #define aic_freeze_simq(ahd)
234f8f66019Skrw #define aic_release_simq(ahd)
235f8f66019Skrw #define aic_freeze_scb(scb)
236f8f66019Skrw #define ahd_platform_freeze_devq(ahd, scb)
237f8f66019Skrw #define ahd_platform_abort_scbs(ahd, target, channel, lun, tag, role, status)
238f8f66019Skrw 
239f8f66019Skrw void aic_platform_scb_free(struct ahd_softc *, struct scb *);
24056007914Smarco 
24156007914Smarco /********************************** PCI ***************************************/
242e5238fd1Smarco /*#if AHD_PCI_CONFIG > 0*/
243f8f66019Skrw #define aic_get_pci_function(pci) ((pci)->pa_function)
244f8f66019Skrw #define aic_get_pci_slot(pci) ((pci)->pa_device)
245f8f66019Skrw #define aic_get_pci_bus(pci) ((pci)->pa_bus)
24656007914Smarco 
24756007914Smarco int			ahd_pci_map_registers(struct ahd_softc *);
24856007914Smarco int			ahd_pci_map_int(struct ahd_softc *);
249e5238fd1Smarco /*#endif*/
25056007914Smarco 
25156007914Smarco typedef enum
25256007914Smarco {
25356007914Smarco 	AHD_POWER_STATE_D0,
25456007914Smarco 	AHD_POWER_STATE_D1,
25556007914Smarco 	AHD_POWER_STATE_D2,
25656007914Smarco 	AHD_POWER_STATE_D3
25756007914Smarco } ahd_power_state;
25856007914Smarco 
25956007914Smarco void ahd_power_state_change(struct ahd_softc *, ahd_power_state);
26056007914Smarco 
26156007914Smarco /********************************* Debug **************************************/
262e5238fd1Smarco void	ahd_print_path(struct ahd_softc *, struct scb *);
263e5238fd1Smarco void	ahd_platform_dump_card_state(struct ahd_softc *ahd);
26456007914Smarco 
26556007914Smarco /**************************** Transfer Settings *******************************/
26656007914Smarco void	  ahd_notify_xfer_settings_change(struct ahd_softc *,
26756007914Smarco 					  struct ahd_devinfo *);
26856007914Smarco void	  ahd_platform_set_tags(struct ahd_softc *, struct ahd_devinfo *,
26956007914Smarco 				ahd_queue_alg);
27056007914Smarco 
27156007914Smarco /************************* Initialization/Teardown ****************************/
27256007914Smarco int	  ahd_platform_alloc(struct ahd_softc *, void *);
27356007914Smarco void	  ahd_platform_free(struct ahd_softc *);
27456007914Smarco int	  ahd_attach(struct ahd_softc *);
27556007914Smarco int	  ahd_softc_comp(struct ahd_softc *lahd, struct ahd_softc *rahd);
27656007914Smarco int	  ahd_detach(struct device *, int);
277f8f66019Skrw 
278f8f66019Skrw #define	ahd_platform_init(ahd)
27956007914Smarco 
28056007914Smarco /****************************** Interrupts ************************************/
28156007914Smarco int			ahd_platform_intr(void *);
282e5238fd1Smarco void	ahd_platform_flushwork(struct ahd_softc *ahd);
28356007914Smarco /************************ Misc Function Declarations **************************/
28456007914Smarco void	  ahd_done(struct ahd_softc *, struct scb *);
28556007914Smarco void	  ahd_send_async(struct ahd_softc *, char /*channel*/,
28656007914Smarco 			 u_int /*target*/, u_int /*lun*/, ac_code, void *arg);
28756007914Smarco #endif  /* _AIC79XX_OPENBSD_H_ */
288