xref: /openbsd/sys/dev/ic/aic79xx_openbsd.h (revision 528abb89)
1*528abb89Sjsg /*	$OpenBSD: aic79xx_openbsd.h,v 1.22 2024/05/29 00:48:15 jsg 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/queue.h>
7856007914Smarco 
7956007914Smarco #define AIC_PCI_CONFIG 1
8056007914Smarco #include <dev/pci/pcireg.h>
8156007914Smarco #include <dev/pci/pcivar.h>
8256007914Smarco 
8356007914Smarco #include <machine/bus.h>
8456007914Smarco #include <machine/intr.h>
8556007914Smarco 
8656007914Smarco #include <scsi/scsi_all.h>
8756007914Smarco #include <scsi/scsi_message.h>
8856007914Smarco #include <scsi/scsiconf.h>
8956007914Smarco 
9056007914Smarco #include <uvm/uvm_extern.h>
9156007914Smarco 
9256007914Smarco #ifdef DEBUG
9356007914Smarco #define bootverbose     1
9456007914Smarco #else
9556007914Smarco #define bootverbose     0
9656007914Smarco #endif
9756007914Smarco /****************************** Platform Macros *******************************/
9856007914Smarco #define	SCSI_IS_SCSIBUS_B(ahd, sc_link)	\
9956007914Smarco 	(0)
10056007914Smarco #define	SCSI_CHANNEL(ahd, sc_link)	\
10156007914Smarco 	('A')
10256007914Smarco #define	SCSI_SCSI_ID(ahd, sc_link)	\
10356007914Smarco 	(ahd->our_id)
10456007914Smarco #define BUILD_SCSIID(ahd, sc_link, target_id, our_id) \
10556007914Smarco 	((((target_id) << TID_SHIFT) & TID) | (our_id))
10656007914Smarco 
10756007914Smarco #ifndef offsetof
10856007914Smarco #define offsetof(type, member)  ((size_t)(&((type *)0)->member))
10956007914Smarco #endif
11056007914Smarco 
111cfe61e4dSmarco /************************* Forward Declarations *******************************/
112cfe61e4dSmarco typedef struct pci_attach_args * ahd_dev_softc_t;
11356007914Smarco 
11456007914Smarco /***************************** Bus Space/DMA **********************************/
11556007914Smarco 
11656007914Smarco /* XXX Need to update Bus DMA for partial map syncs */
11756007914Smarco #define ahd_dmamap_sync(ahc, dma_tag, dmamap, offset, len, op)		\
11856007914Smarco 	bus_dmamap_sync(dma_tag, dmamap, offset, len, op)
11956007914Smarco 
12056007914Smarco /************************ Tunable Driver Parameters  **************************/
12156007914Smarco /*
12256007914Smarco  * The number of dma segments supported.  The sequencer can handle any number
1234431c8f9Smiod  * of physically contiguous S/G entries.  To reduce the driver's memory
12456007914Smarco  * consumption, we limit the number supported to be sufficient to handle
12556007914Smarco  * the largest mapping supported by the kernel, MAXPHYS.  Assuming the
12656007914Smarco  * transfer is as fragmented as possible and unaligned, this turns out to
12756007914Smarco  * be the number of paged sized transfers in MAXPHYS plus an extra element
12856007914Smarco  * to handle any unaligned residual.  The sequencer fetches SG elements
12956007914Smarco  * in cacheline sized chucks, so make the number per-transaction an even
13056007914Smarco  * multiple of 16 which should align us on even the largest of cacheline
13156007914Smarco  * boundaries.
13256007914Smarco  */
1333b126145Smartin #define AHD_NSEG (roundup(atop(MAXPHYS) + 1, 16))
13456007914Smarco 
13556007914Smarco /* This driver supports target mode */
13656007914Smarco // #define AHD_TARGET_MODE 1
13756007914Smarco 
13856007914Smarco /************************** Timer DataStructures ******************************/
139f8f66019Skrw typedef struct timeout aic_timer_t;
14056007914Smarco 
14156007914Smarco /***************************** Core Includes **********************************/
14256007914Smarco 
14356007914Smarco #if AHD_REG_PRETTY_PRINT
14456007914Smarco #define AIC_DEBUG_REGISTERS 1
14556007914Smarco #else
14656007914Smarco #define AIC_DEBUG_REGISTERS 0
14756007914Smarco #endif
14856007914Smarco #include <dev/ic/aic79xx.h>
14956007914Smarco 
15056007914Smarco /***************************** Timer Facilities *******************************/
15156007914Smarco void ahd_timeout(void*);
1520a7a9938Skrw void aic_timer_reset(aic_timer_t *, u_int, ahd_callback_t *, void *);
153f8f66019Skrw void aic_scb_timer_reset(struct scb *, u_int);
15456007914Smarco 
155f8f66019Skrw #define aic_timer_stop timeout_del
1562a53356eSkrw #define aic_get_timeout(scb) ((scb)->xs->timeout)
15756007914Smarco /*************************** Device Access ************************************/
15856007914Smarco #define ahd_inb(ahd, port)					\
15956007914Smarco 	bus_space_read_1((ahd)->tags[(port) >> 8],		\
16056007914Smarco 			 (ahd)->bshs[(port) >> 8], (port) & 0xFF)
16156007914Smarco 
16256007914Smarco #define ahd_outb(ahd, port, value)				\
16356007914Smarco 	bus_space_write_1((ahd)->tags[(port) >> 8],		\
16456007914Smarco 			  (ahd)->bshs[(port) >> 8], (port) & 0xFF, value)
16556007914Smarco 
16656007914Smarco #define ahd_inw_atomic(ahd, port)				\
167b1b2b63cSkrw 	aic_le16toh(bus_space_read_2((ahd)->tags[(port) >> 8],	\
16856007914Smarco 				     (ahd)->bshs[(port) >> 8], (port) & 0xFF))
16956007914Smarco 
17056007914Smarco #define ahd_outw_atomic(ahd, port, value)			\
17156007914Smarco 	bus_space_write_2((ahd)->tags[(port) >> 8],		\
17256007914Smarco 			  (ahd)->bshs[(port) >> 8],		\
173b1b2b63cSkrw 			  (port & 0xFF), aic_htole16(value))
17456007914Smarco 
17556007914Smarco #define ahd_outsb(ahd, port, valp, count)			\
17656007914Smarco 	bus_space_write_multi_1((ahd)->tags[(port) >> 8],	\
17756007914Smarco 				(ahd)->bshs[(port) >> 8],	\
17856007914Smarco 				(port & 0xFF), valp, count)
17956007914Smarco 
18056007914Smarco #define ahd_insb(ahd, port, valp, count)			\
18156007914Smarco 	bus_space_read_multi_1((ahd)->tags[(port) >> 8],	\
18256007914Smarco 			       (ahd)->bshs[(port) >> 8],	\
18356007914Smarco 			       (port & 0xFF), valp, count)
18456007914Smarco 
185e5238fd1Smarco void ahd_flush_device_writes(struct ahd_softc *);
18656007914Smarco 
18756007914Smarco /**************************** Locking Primitives ******************************/
18856007914Smarco /* Lock protecting internal data structures */
189f8f66019Skrw #define ahd_lockinit(ahd)
190f8f66019Skrw #define ahd_lock(ahd, flags) *(flags) = splbio()
191f8f66019Skrw #define ahd_unlock(ahd, flags) splx(*(flags))
19256007914Smarco 
193f8f66019Skrw /* Lock held during command completion to the upper layer */
194f8f66019Skrw #define ahd_done_lockinit(ahd)
195f8f66019Skrw #define ahd_done_lock(ahd, flags)
196f8f66019Skrw #define ahd_done_unlock(ahd, flags)
19756007914Smarco 
19856007914Smarco /* Lock held during ahd_list manipulation and ahd softc frees */
199f8f66019Skrw #define ahd_list_lockinit(x)
200f8f66019Skrw #define ahd_list_lock(flags) *(flags) = splbio()
201f8f66019Skrw #define ahd_list_unlock(flags) splx(*(flags))
20256007914Smarco 
20356007914Smarco /****************************** OS Primitives *********************************/
204c4ff7968Skrw #define scsi_4btoul(b)	(_4btol(b))
20556007914Smarco 
20656007914Smarco /************************** Transaction Operations ****************************/
207f8f66019Skrw #define aic_set_transaction_status(scb, status) (scb)->xs->error = (status)
208f8f66019Skrw #define aic_set_scsi_status(scb, status) (scb)->xs->xs_status = (status)
209f8f66019Skrw #define aic_set_transaction_tag(scb, enabled, type)
210f8f66019Skrw #define aic_set_residual(scb, residual) (scb)->xs->resid = (residual)
211f8f66019Skrw #define aic_set_sense_residual(scb, residual) (scb)->xs->resid = (residual)
212f8f66019Skrw 
213f8f66019Skrw #define aic_get_transaction_status(scb) \
214f8f66019Skrw 	(((scb)->xs->flags & ITSDONE) ? CAM_REQ_CMP : (scb)->xs->error)
215f8f66019Skrw #define aic_get_scsi_status(scb) ((scb)->xs->status)
216f8f66019Skrw #define aic_get_transfer_length(scb) ((scb)->xs->datalen)
217f8f66019Skrw #define aic_get_transfer_dir(scb) \
218f8f66019Skrw 	((scb)->xs->flags & (SCSI_DATA_IN | SCSI_DATA_OUT))
219f8f66019Skrw #define aic_get_residual(scb) ((scb)->xs->resid)
220f8f66019Skrw #define aic_get_sense_bufsize(ahd, scb) (sizeof(struct scsi_sense_data))
221f8f66019Skrw 
222f8f66019Skrw #define aic_perform_autosense(scb) (1)
223f8f66019Skrw 
224f8f66019Skrw #define aic_freeze_simq(ahd)
225f8f66019Skrw #define aic_release_simq(ahd)
226f8f66019Skrw #define aic_freeze_scb(scb)
227f8f66019Skrw 
228f8f66019Skrw void aic_platform_scb_free(struct ahd_softc *, struct scb *);
22956007914Smarco 
23056007914Smarco /********************************** PCI ***************************************/
231e5238fd1Smarco /*#if AHD_PCI_CONFIG > 0*/
232f8f66019Skrw #define aic_get_pci_function(pci) ((pci)->pa_function)
233f8f66019Skrw #define aic_get_pci_slot(pci) ((pci)->pa_device)
234f8f66019Skrw #define aic_get_pci_bus(pci) ((pci)->pa_bus)
235e5238fd1Smarco /*#endif*/
23656007914Smarco 
23756007914Smarco typedef enum
23856007914Smarco {
23956007914Smarco 	AHD_POWER_STATE_D0,
24056007914Smarco 	AHD_POWER_STATE_D1,
24156007914Smarco 	AHD_POWER_STATE_D2,
24256007914Smarco 	AHD_POWER_STATE_D3
24356007914Smarco } ahd_power_state;
24456007914Smarco 
24556007914Smarco /********************************* Debug **************************************/
246e5238fd1Smarco void	ahd_print_path(struct ahd_softc *, struct scb *);
247e5238fd1Smarco void	ahd_platform_dump_card_state(struct ahd_softc *ahd);
24856007914Smarco 
24956007914Smarco /**************************** Transfer Settings *******************************/
25056007914Smarco void	  ahd_platform_set_tags(struct ahd_softc *, struct ahd_devinfo *,
25156007914Smarco 				ahd_queue_alg);
25256007914Smarco 
25356007914Smarco /************************* Initialization/Teardown ****************************/
25456007914Smarco int	  ahd_attach(struct ahd_softc *);
25556007914Smarco int	  ahd_softc_comp(struct ahd_softc *lahd, struct ahd_softc *rahd);
25656007914Smarco int	  ahd_detach(struct device *, int);
257f8f66019Skrw 
25856007914Smarco /****************************** Interrupts ************************************/
25956007914Smarco int			ahd_platform_intr(void *);
26062c54088Skrw 
26156007914Smarco /************************ Misc Function Declarations **************************/
26256007914Smarco void	  ahd_done(struct ahd_softc *, struct scb *);
26356007914Smarco void	  ahd_send_async(struct ahd_softc *, char /*channel*/,
26456007914Smarco 			 u_int /*target*/, u_int /*lun*/, ac_code, void *arg);
26556007914Smarco #endif  /* _AIC79XX_OPENBSD_H_ */
266