xref: /freebsd/sys/dev/mfi/mfivar.h (revision 685dc743dc3b5645e34836464128e1c0558b404b)
12e21a3efSScott Long /*-
2*eebd9d53SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni  *
42e21a3efSScott Long  * Copyright (c) 2006 IronPort Systems
52e21a3efSScott Long  * All rights reserved.
62e21a3efSScott Long  *
72e21a3efSScott Long  * Redistribution and use in source and binary forms, with or without
82e21a3efSScott Long  * modification, are permitted provided that the following conditions
92e21a3efSScott Long  * are met:
102e21a3efSScott Long  * 1. Redistributions of source code must retain the above copyright
112e21a3efSScott Long  *    notice, this list of conditions and the following disclaimer.
122e21a3efSScott Long  * 2. Redistributions in binary form must reproduce the above copyright
132e21a3efSScott Long  *    notice, this list of conditions and the following disclaimer in the
142e21a3efSScott Long  *    documentation and/or other materials provided with the distribution.
152e21a3efSScott Long  *
162e21a3efSScott Long  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
172e21a3efSScott Long  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
182e21a3efSScott Long  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
192e21a3efSScott Long  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
202e21a3efSScott Long  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
212e21a3efSScott Long  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
222e21a3efSScott Long  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
232e21a3efSScott Long  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
242e21a3efSScott Long  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
252e21a3efSScott Long  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
262e21a3efSScott Long  * SUCH DAMAGE.
272e21a3efSScott Long  */
28610f2ef3SScott Long /*-
29610f2ef3SScott Long  * Copyright (c) 2007 LSI Corp.
30610f2ef3SScott Long  * Copyright (c) 2007 Rajesh Prabhakaran.
31610f2ef3SScott Long  * All rights reserved.
32610f2ef3SScott Long  *
33610f2ef3SScott Long  * Redistribution and use in source and binary forms, with or without
34610f2ef3SScott Long  * modification, are permitted provided that the following conditions
35610f2ef3SScott Long  * are met:
36610f2ef3SScott Long  * 1. Redistributions of source code must retain the above copyright
37610f2ef3SScott Long  *    notice, this list of conditions and the following disclaimer.
38610f2ef3SScott Long  * 2. Redistributions in binary form must reproduce the above copyright
39610f2ef3SScott Long  *    notice, this list of conditions and the following disclaimer in the
40610f2ef3SScott Long  *    documentation and/or other materials provided with the distribution.
41610f2ef3SScott Long  *
42610f2ef3SScott Long  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
43610f2ef3SScott Long  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44610f2ef3SScott Long  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45610f2ef3SScott Long  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
46610f2ef3SScott Long  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
47610f2ef3SScott Long  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
48610f2ef3SScott Long  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49610f2ef3SScott Long  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
50610f2ef3SScott Long  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
51610f2ef3SScott Long  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
52610f2ef3SScott Long  * SUCH DAMAGE.
53610f2ef3SScott Long  */
542e21a3efSScott Long 
552e21a3efSScott Long #ifndef _MFIVAR_H
562e21a3efSScott Long #define _MFIVAR_H
572e21a3efSScott Long 
582e21a3efSScott Long #include <sys/cdefs.h>
598ec5c98bSJohn Baldwin #include <sys/lock.h>
608ec5c98bSJohn Baldwin #include <sys/sx.h>
618ec5c98bSJohn Baldwin 
620d9a4ef3SDoug Ambrisko #include <sys/types.h>
63a6ba0fd6SDoug Ambrisko #include <sys/taskqueue.h>
64cf72e893SSean Bruno #include "opt_mfi.h"
650d9a4ef3SDoug Ambrisko 
662e21a3efSScott Long /*
672e21a3efSScott Long  * SCSI structures and definitions are used from here, but no linking
682e21a3efSScott Long  * requirements are made to CAM.
692e21a3efSScott Long  */
702e21a3efSScott Long #include <cam/scsi/scsi_all.h>
712e21a3efSScott Long 
722e21a3efSScott Long struct mfi_hwcomms {
732e21a3efSScott Long 	uint32_t		hw_pi;
742e21a3efSScott Long 	uint32_t		hw_ci;
752e21a3efSScott Long 	uint32_t		hw_reply_q[1];
762e21a3efSScott Long };
770d9a4ef3SDoug Ambrisko #define	MEGASAS_MAX_NAME	32
780d9a4ef3SDoug Ambrisko #define	MEGASAS_VERSION		"4.23"
792e21a3efSScott Long 
802e21a3efSScott Long struct mfi_softc;
81ddfae47bSScott Long struct disk;
8235ef86f2SScott Long struct ccb_hdr;
832e21a3efSScott Long 
842e21a3efSScott Long struct mfi_command {
852e21a3efSScott Long 	TAILQ_ENTRY(mfi_command) cm_link;
865ba21ff1SScott Long 	time_t			cm_timestamp;
872e21a3efSScott Long 	struct mfi_softc	*cm_sc;
882e21a3efSScott Long 	union mfi_frame		*cm_frame;
890d9a4ef3SDoug Ambrisko 	bus_addr_t		cm_frame_busaddr;
902e21a3efSScott Long 	struct mfi_sense	*cm_sense;
910d9a4ef3SDoug Ambrisko 	bus_addr_t		cm_sense_busaddr;
922e21a3efSScott Long 	bus_dmamap_t		cm_dmamap;
932e21a3efSScott Long 	union mfi_sgl		*cm_sg;
942e21a3efSScott Long 	void			*cm_data;
952e21a3efSScott Long 	int			cm_len;
965f8ad41cSAlexander Motin 	int			cm_stp_len;
972e21a3efSScott Long 	int			cm_total_frame_size;
982e21a3efSScott Long 	int			cm_extra_frames;
992e21a3efSScott Long 	int			cm_flags;
1002e21a3efSScott Long #define MFI_CMD_MAPPED		(1<<0)
1012e21a3efSScott Long #define MFI_CMD_DATAIN		(1<<1)
1022e21a3efSScott Long #define MFI_CMD_DATAOUT		(1<<2)
1032e21a3efSScott Long #define MFI_CMD_COMPLETED	(1<<3)
1042e21a3efSScott Long #define MFI_CMD_POLLED		(1<<4)
10508c89430SSteven Hartland #define MFI_CMD_SCSI		(1<<5)
10608c89430SSteven Hartland #define MFI_CMD_CCB		(1<<6)
107c33ce503SKonstantin Belousov #define	MFI_CMD_BIO		(1<<7)
108c33ce503SKonstantin Belousov #define MFI_CMD_TBOLT		(1<<8)
109c33ce503SKonstantin Belousov #define MFI_ON_MFIQ_FREE	(1<<9)
110c33ce503SKonstantin Belousov #define MFI_ON_MFIQ_READY	(1<<10)
111c33ce503SKonstantin Belousov #define MFI_ON_MFIQ_BUSY	(1<<11)
11208c89430SSteven Hartland #define MFI_ON_MFIQ_MASK	(MFI_ON_MFIQ_FREE | MFI_ON_MFIQ_READY| \
11308c89430SSteven Hartland     MFI_ON_MFIQ_BUSY)
11408c89430SSteven Hartland #define MFI_CMD_FLAGS_FMT	"\20" \
11508c89430SSteven Hartland     "\1MAPPED" \
11608c89430SSteven Hartland     "\2DATAIN" \
11708c89430SSteven Hartland     "\3DATAOUT" \
11808c89430SSteven Hartland     "\4COMPLETED" \
11908c89430SSteven Hartland     "\5POLLED" \
12008c89430SSteven Hartland     "\6SCSI" \
121c33ce503SKonstantin Belousov     "\7BIO" \
122c33ce503SKonstantin Belousov     "\10TBOLT" \
123c33ce503SKonstantin Belousov     "\11Q_FREE" \
124c33ce503SKonstantin Belousov     "\12Q_READY" \
125c33ce503SKonstantin Belousov     "\13Q_BUSY"
1260d9a4ef3SDoug Ambrisko 	uint8_t			retry_for_fw_reset;
1272e21a3efSScott Long 	void			(* cm_complete)(struct mfi_command *cm);
1282e21a3efSScott Long 	void			*cm_private;
1295ba21ff1SScott Long 	int			cm_index;
1305be25877SDoug Ambrisko 	int			cm_error;
1312e21a3efSScott Long };
1322e21a3efSScott Long 
133ddfae47bSScott Long struct mfi_disk {
134ddfae47bSScott Long 	TAILQ_ENTRY(mfi_disk)	ld_link;
135ddfae47bSScott Long 	device_t	ld_dev;
1362e21a3efSScott Long 	int		ld_id;
137ddfae47bSScott Long 	int		ld_unit;
138ddfae47bSScott Long 	struct mfi_softc *ld_controller;
139ddfae47bSScott Long 	struct mfi_ld_info	*ld_info;
140ddfae47bSScott Long 	struct disk	*ld_disk;
141ddfae47bSScott Long 	int		ld_flags;
142ddfae47bSScott Long #define MFI_DISK_FLAGS_OPEN	0x01
1438ec5c98bSJohn Baldwin #define	MFI_DISK_FLAGS_DISABLED	0x02
1442e21a3efSScott Long };
1452e21a3efSScott Long 
14658ef3154SDoug Ambrisko struct mfi_disk_pending {
14758ef3154SDoug Ambrisko 	TAILQ_ENTRY(mfi_disk_pending)	ld_link;
14858ef3154SDoug Ambrisko 	int		ld_id;
14958ef3154SDoug Ambrisko };
15058ef3154SDoug Ambrisko 
1510d9a4ef3SDoug Ambrisko struct mfi_system_pd {
1520d9a4ef3SDoug Ambrisko 	TAILQ_ENTRY(mfi_system_pd) pd_link;
1530d9a4ef3SDoug Ambrisko 	device_t	pd_dev;
1540d9a4ef3SDoug Ambrisko 	int		pd_id;
1550d9a4ef3SDoug Ambrisko 	int		pd_unit;
1560d9a4ef3SDoug Ambrisko 	struct mfi_softc *pd_controller;
1570d9a4ef3SDoug Ambrisko 	struct mfi_pd_info *pd_info;
1580d9a4ef3SDoug Ambrisko 	struct disk	*pd_disk;
1590d9a4ef3SDoug Ambrisko 	int		pd_flags;
1600d9a4ef3SDoug Ambrisko };
161a6ba0fd6SDoug Ambrisko 
16258ef3154SDoug Ambrisko struct mfi_system_pending {
16358ef3154SDoug Ambrisko 	TAILQ_ENTRY(mfi_system_pending) pd_link;
16458ef3154SDoug Ambrisko 	int		pd_id;
16558ef3154SDoug Ambrisko };
16658ef3154SDoug Ambrisko 
167a6ba0fd6SDoug Ambrisko struct mfi_evt_queue_elm {
168a6ba0fd6SDoug Ambrisko 	TAILQ_ENTRY(mfi_evt_queue_elm)	link;
169a6ba0fd6SDoug Ambrisko 	struct mfi_evt_detail		detail;
170a6ba0fd6SDoug Ambrisko };
171a6ba0fd6SDoug Ambrisko 
172741367d5SDoug Ambrisko struct mfi_aen {
173741367d5SDoug Ambrisko 	TAILQ_ENTRY(mfi_aen) aen_link;
174741367d5SDoug Ambrisko 	struct proc			*p;
175741367d5SDoug Ambrisko };
176741367d5SDoug Ambrisko 
1770d9a4ef3SDoug Ambrisko struct mfi_skinny_dma_info {
1780d9a4ef3SDoug Ambrisko 	bus_dma_tag_t			dmat[514];
1790d9a4ef3SDoug Ambrisko 	bus_dmamap_t			dmamap[514];
1800d9a4ef3SDoug Ambrisko 	uint32_t			mem[514];
1810d9a4ef3SDoug Ambrisko 	int				noofmaps;
1820d9a4ef3SDoug Ambrisko };
1830d9a4ef3SDoug Ambrisko 
1847e4dd9e1SDoug Ambrisko struct megasas_sge
1857e4dd9e1SDoug Ambrisko {
1867e4dd9e1SDoug Ambrisko 	bus_addr_t			phys_addr;
1877e4dd9e1SDoug Ambrisko 	uint32_t			length;
1887e4dd9e1SDoug Ambrisko };
1897e4dd9e1SDoug Ambrisko 
1900d9a4ef3SDoug Ambrisko struct mfi_cmd_tbolt;
1910d9a4ef3SDoug Ambrisko 
1922e21a3efSScott Long struct mfi_softc {
1932e21a3efSScott Long 	device_t			mfi_dev;
1942e21a3efSScott Long 	int				mfi_flags;
1952e21a3efSScott Long #define MFI_FLAGS_SG64		(1<<0)
1962e21a3efSScott Long #define MFI_FLAGS_QFRZN		(1<<1)
1972e21a3efSScott Long #define MFI_FLAGS_OPEN		(1<<2)
198441f6d5dSScott Long #define MFI_FLAGS_STOP		(1<<3)
199610f2ef3SScott Long #define MFI_FLAGS_1064R		(1<<4)
200610f2ef3SScott Long #define MFI_FLAGS_1078		(1<<5)
201fa1e6ef4SDoug Ambrisko #define MFI_FLAGS_GEN2		(1<<6)
2020d9a4ef3SDoug Ambrisko #define MFI_FLAGS_SKINNY	(1<<7)
2030d9a4ef3SDoug Ambrisko #define MFI_FLAGS_TBOLT		(1<<8)
20496f9425fSDoug Ambrisko #define MFI_FLAGS_MRSAS		(1<<9)
2053b8ad66eSMark Johnston #define MFI_FLAGS_INVADER	(1<<10)
2063b8ad66eSMark Johnston #define MFI_FLAGS_FURY		(1<<11)
2070d9a4ef3SDoug Ambrisko 	// Start: LSIP200113393
2080d9a4ef3SDoug Ambrisko 	bus_dma_tag_t			verbuf_h_dmat;
2090d9a4ef3SDoug Ambrisko 	bus_dmamap_t			verbuf_h_dmamap;
2109a4e738aSSean Bruno 	bus_addr_t			verbuf_h_busaddr;
2110d9a4ef3SDoug Ambrisko 	uint32_t			*verbuf;
2120d9a4ef3SDoug Ambrisko 	void				*kbuff_arr[MAX_IOCTL_SGE];
2130d9a4ef3SDoug Ambrisko 	bus_dma_tag_t			mfi_kbuff_arr_dmat[2];
2140d9a4ef3SDoug Ambrisko 	bus_dmamap_t			mfi_kbuff_arr_dmamap[2];
215a6ba0fd6SDoug Ambrisko 	bus_addr_t			mfi_kbuff_arr_busaddr[2];
2162e21a3efSScott Long 
2172e21a3efSScott Long 	struct mfi_hwcomms		*mfi_comms;
2182e21a3efSScott Long 	TAILQ_HEAD(,mfi_command)	mfi_free;
2192e21a3efSScott Long 	TAILQ_HEAD(,mfi_command)	mfi_ready;
2200d9a4ef3SDoug Ambrisko 	TAILQ_HEAD(BUSYQ,mfi_command)	mfi_busy;
2212e21a3efSScott Long 	struct bio_queue_head		mfi_bioq;
2222e21a3efSScott Long 	struct mfi_qstat		mfi_qstat[MFIQ_COUNT];
2232e21a3efSScott Long 
2242e21a3efSScott Long 	struct resource			*mfi_regs_resource;
2252e21a3efSScott Long 	bus_space_handle_t		mfi_bhandle;
2262e21a3efSScott Long 	bus_space_tag_t			mfi_btag;
2272e21a3efSScott Long 	int				mfi_regs_rid;
2282e21a3efSScott Long 
2292e21a3efSScott Long 	bus_dma_tag_t			mfi_parent_dmat;
2302e21a3efSScott Long 	bus_dma_tag_t			mfi_buffer_dmat;
2312e21a3efSScott Long 
2322e21a3efSScott Long 	bus_dma_tag_t			mfi_comms_dmat;
2332e21a3efSScott Long 	bus_dmamap_t			mfi_comms_dmamap;
234a6ba0fd6SDoug Ambrisko 	bus_addr_t			mfi_comms_busaddr;
2352e21a3efSScott Long 
2362e21a3efSScott Long 	bus_dma_tag_t			mfi_frames_dmat;
2372e21a3efSScott Long 	bus_dmamap_t			mfi_frames_dmamap;
238a6ba0fd6SDoug Ambrisko 	bus_addr_t			mfi_frames_busaddr;
2392e21a3efSScott Long 	union mfi_frame			*mfi_frames;
2402e21a3efSScott Long 
2410d9a4ef3SDoug Ambrisko 	bus_dma_tag_t			mfi_tb_init_dmat;
2420d9a4ef3SDoug Ambrisko 	bus_dmamap_t			mfi_tb_init_dmamap;
243a6ba0fd6SDoug Ambrisko 	bus_addr_t			mfi_tb_init_busaddr;
244a6ba0fd6SDoug Ambrisko 	bus_addr_t			mfi_tb_ioc_init_busaddr;
2450d9a4ef3SDoug Ambrisko 	union mfi_frame			*mfi_tb_init;
2460d9a4ef3SDoug Ambrisko 
247a6ba0fd6SDoug Ambrisko 	TAILQ_HEAD(,mfi_evt_queue_elm)	mfi_evt_queue;
248a6ba0fd6SDoug Ambrisko 	struct task			mfi_evt_task;
249ddbffe7fSDoug Ambrisko 	struct task			mfi_map_sync_task;
250741367d5SDoug Ambrisko 	TAILQ_HEAD(,mfi_aen)		mfi_aen_pids;
251741367d5SDoug Ambrisko 	struct mfi_command		*mfi_aen_cm;
2520d9a4ef3SDoug Ambrisko 	struct mfi_command		*mfi_skinny_cm;
253ddbffe7fSDoug Ambrisko 	struct mfi_command		*mfi_map_sync_cm;
254ddbffe7fSDoug Ambrisko 	int				cm_aen_abort;
255ddbffe7fSDoug Ambrisko 	int				cm_map_abort;
256741367d5SDoug Ambrisko 	uint32_t			mfi_aen_triggered;
257741367d5SDoug Ambrisko 	uint32_t			mfi_poll_waiting;
258a6ba0fd6SDoug Ambrisko 	uint32_t			mfi_boot_seq_num;
259741367d5SDoug Ambrisko 	struct selinfo			mfi_select;
2608ec5c98bSJohn Baldwin 	int				mfi_delete_busy_volumes;
2618ec5c98bSJohn Baldwin 	int				mfi_keep_deleted_volumes;
2628ec5c98bSJohn Baldwin 	int				mfi_detaching;
263741367d5SDoug Ambrisko 
2642e21a3efSScott Long 	bus_dma_tag_t			mfi_sense_dmat;
2652e21a3efSScott Long 	bus_dmamap_t			mfi_sense_dmamap;
2669a4e738aSSean Bruno 	bus_addr_t			mfi_sense_busaddr;
2672e21a3efSScott Long 	struct mfi_sense		*mfi_sense;
2682e21a3efSScott Long 
2692e21a3efSScott Long 	struct resource			*mfi_irq;
2702e21a3efSScott Long 	void				*mfi_intr;
2712e21a3efSScott Long 	int				mfi_irq_rid;
2722e21a3efSScott Long 
2732e21a3efSScott Long 	struct intr_config_hook		mfi_ich;
2742e21a3efSScott Long 	eventhandler_tag		eh;
2750d9a4ef3SDoug Ambrisko 	/* OCR flags */
2760d9a4ef3SDoug Ambrisko 	uint8_t adpreset;
2770d9a4ef3SDoug Ambrisko 	uint8_t issuepend_done;
2780d9a4ef3SDoug Ambrisko 	uint8_t disableOnlineCtrlReset;
2790d9a4ef3SDoug Ambrisko 	uint32_t mfiStatus;
2800d9a4ef3SDoug Ambrisko 	uint32_t last_seq_num;
2810d9a4ef3SDoug Ambrisko 	uint32_t volatile hw_crit_error;
2822e21a3efSScott Long 
2832e21a3efSScott Long 	/*
2842e21a3efSScott Long 	 * Allocation for the command array.  Used as an indexable array to
2852e21a3efSScott Long 	 * recover completed commands.
2862e21a3efSScott Long 	 */
2872e21a3efSScott Long 	struct mfi_command		*mfi_commands;
2882e21a3efSScott Long 	/*
2892e21a3efSScott Long 	 * How many commands the firmware can handle.  Also how big the reply
2902e21a3efSScott Long 	 * queue is, minus 1.
2912e21a3efSScott Long 	 */
2922e21a3efSScott Long 	int				mfi_max_fw_cmds;
2932e21a3efSScott Long 	/*
2942e21a3efSScott Long 	 * How many S/G elements we'll ever actually use
2952e21a3efSScott Long 	 */
29678e36c27SScott Long 	int				mfi_max_sge;
2972e21a3efSScott Long 	/*
2982e21a3efSScott Long 	 * How many bytes a compound frame is, including all of the extra frames
2992e21a3efSScott Long 	 * that are used for S/G elements.
3002e21a3efSScott Long 	 */
30178e36c27SScott Long 	int				mfi_cmd_size;
3022e21a3efSScott Long 	/*
3032e21a3efSScott Long 	 * How large an S/G element is.  Used to calculate the number of single
3042e21a3efSScott Long 	 * frames in a command.
3052e21a3efSScott Long 	 */
30678e36c27SScott Long 	int				mfi_sge_size;
3072e21a3efSScott Long 	/*
3082e21a3efSScott Long 	 * Max number of sectors that the firmware allows
3092e21a3efSScott Long 	 */
3102e21a3efSScott Long 	uint32_t			mfi_max_io;
3112e21a3efSScott Long 
312ddfae47bSScott Long 	TAILQ_HEAD(,mfi_disk)		mfi_ld_tqh;
3130d9a4ef3SDoug Ambrisko 	TAILQ_HEAD(,mfi_system_pd)	mfi_syspd_tqh;
31458ef3154SDoug Ambrisko 	TAILQ_HEAD(,mfi_disk_pending)	mfi_ld_pend_tqh;
31558ef3154SDoug Ambrisko 	TAILQ_HEAD(,mfi_system_pending)	mfi_syspd_pend_tqh;
3162e21a3efSScott Long 	eventhandler_tag		mfi_eh;
3172e21a3efSScott Long 	struct cdev			*mfi_cdev;
3182e21a3efSScott Long 
31935ef86f2SScott Long 	TAILQ_HEAD(, ccb_hdr)		mfi_cam_ccbq;
32035ef86f2SScott Long 	struct mfi_command *		(* mfi_cam_start)(void *);
32159ddd3e9SDoug Ambrisko 	void				(*mfi_cam_rescan_cb)(struct mfi_softc *,
32259ddd3e9SDoug Ambrisko 					    uint32_t);
3235ba21ff1SScott Long 	struct callout			mfi_watchdog_callout;
3242e21a3efSScott Long 	struct mtx			mfi_io_lock;
3258ec5c98bSJohn Baldwin 	struct sx			mfi_config_lock;
326610f2ef3SScott Long 
327610f2ef3SScott Long 	/* Controller type specific interfaces */
328610f2ef3SScott Long 	void	(*mfi_enable_intr)(struct mfi_softc *sc);
3290d9a4ef3SDoug Ambrisko 	void	(*mfi_disable_intr)(struct mfi_softc *sc);
330610f2ef3SScott Long 	int32_t	(*mfi_read_fw_status)(struct mfi_softc *sc);
331610f2ef3SScott Long 	int	(*mfi_check_clear_intr)(struct mfi_softc *sc);
332a6ba0fd6SDoug Ambrisko 	void	(*mfi_issue_cmd)(struct mfi_softc *sc, bus_addr_t bus_add,
333a6ba0fd6SDoug Ambrisko 		    uint32_t frame_cnt);
3340d9a4ef3SDoug Ambrisko 	int	(*mfi_adp_reset)(struct mfi_softc *sc);
3350d9a4ef3SDoug Ambrisko 	int	(*mfi_adp_check_reset)(struct mfi_softc *sc);
33658ef3154SDoug Ambrisko 	void				(*mfi_intr_ptr)(void *sc);
3370d9a4ef3SDoug Ambrisko 
3380d9a4ef3SDoug Ambrisko 	/* ThunderBolt */
3390d9a4ef3SDoug Ambrisko 	uint32_t			mfi_tbolt;
3400d9a4ef3SDoug Ambrisko 	uint32_t			MFA_enabled;
341a6ba0fd6SDoug Ambrisko 	/* Single Reply structure size */
342a6ba0fd6SDoug Ambrisko 	uint16_t			reply_size;
343a6ba0fd6SDoug Ambrisko 	/* Singler message size. */
344a6ba0fd6SDoug Ambrisko 	uint16_t			raid_io_msg_size;
3450d9a4ef3SDoug Ambrisko 	TAILQ_HEAD(TB, mfi_cmd_tbolt)	mfi_cmd_tbolt_tqh;
346a6ba0fd6SDoug Ambrisko 	/* ThunderBolt base contiguous memory mapping. */
347a6ba0fd6SDoug Ambrisko 	bus_dma_tag_t			mfi_tb_dmat;
3480d9a4ef3SDoug Ambrisko 	bus_dmamap_t			mfi_tb_dmamap;
349a6ba0fd6SDoug Ambrisko 	bus_addr_t			mfi_tb_busaddr;
350a6ba0fd6SDoug Ambrisko 	/* ThunderBolt Contiguous DMA memory Mapping */
351a6ba0fd6SDoug Ambrisko 	uint8_t	*			request_message_pool;
3520d9a4ef3SDoug Ambrisko 	uint8_t *			request_message_pool_align;
3530d9a4ef3SDoug Ambrisko 	uint8_t *			request_desc_pool;
354a6ba0fd6SDoug Ambrisko 	bus_addr_t			request_msg_busaddr;
355a6ba0fd6SDoug Ambrisko 	bus_addr_t			reply_frame_busaddr;
356a6ba0fd6SDoug Ambrisko 	bus_addr_t			sg_frame_busaddr;
357a6ba0fd6SDoug Ambrisko 	/* ThunderBolt IOC Init Descriptor */
358a6ba0fd6SDoug Ambrisko 	bus_dma_tag_t			mfi_tb_ioc_init_dmat;
3590d9a4ef3SDoug Ambrisko 	bus_dmamap_t			mfi_tb_ioc_init_dmamap;
3600d9a4ef3SDoug Ambrisko 	uint8_t *			mfi_tb_ioc_init_desc;
3610d9a4ef3SDoug Ambrisko 	struct mfi_cmd_tbolt		**mfi_cmd_pool_tbolt;
362a6ba0fd6SDoug Ambrisko 	/* Virtual address of reply Frame Pool */
363a6ba0fd6SDoug Ambrisko 	struct mfi_mpi2_reply_header*	reply_frame_pool;
3640d9a4ef3SDoug Ambrisko 	struct mfi_mpi2_reply_header*	reply_frame_pool_align;
3650d9a4ef3SDoug Ambrisko 
366a6ba0fd6SDoug Ambrisko 	/* Last reply frame address */
367a6ba0fd6SDoug Ambrisko 	uint8_t *			reply_pool_limit;
3680d9a4ef3SDoug Ambrisko 	uint16_t			last_reply_idx;
3690d9a4ef3SDoug Ambrisko 	uint8_t				max_SGEs_in_chain_message;
3700d9a4ef3SDoug Ambrisko 	uint8_t				max_SGEs_in_main_message;
3710d9a4ef3SDoug Ambrisko 	uint8_t				chain_offset_value_for_main_message;
3720d9a4ef3SDoug Ambrisko 	uint8_t				chain_offset_value_for_mpt_ptmsg;
3730d9a4ef3SDoug Ambrisko };
3740d9a4ef3SDoug Ambrisko 
3750d9a4ef3SDoug Ambrisko union desc_value {
3760d9a4ef3SDoug Ambrisko 	uint64_t	word;
3770d9a4ef3SDoug Ambrisko 	struct {
3780d9a4ef3SDoug Ambrisko 		uint32_t	low;
3790d9a4ef3SDoug Ambrisko 		uint32_t	high;
3800d9a4ef3SDoug Ambrisko 	}u;
3810d9a4ef3SDoug Ambrisko };
3820d9a4ef3SDoug Ambrisko 
3830d9a4ef3SDoug Ambrisko // TODO find the right definition
3840d9a4ef3SDoug Ambrisko #define XXX_MFI_CMD_OP_INIT2                    0x9
3850d9a4ef3SDoug Ambrisko /*
3860d9a4ef3SDoug Ambrisko  * Request descriptor types
3870d9a4ef3SDoug Ambrisko  */
3880d9a4ef3SDoug Ambrisko #define MFI_REQ_DESCRIPT_FLAGS_LD_IO           0x7
3890d9a4ef3SDoug Ambrisko #define MFI_REQ_DESCRIPT_FLAGS_MFA             0x1
3900d9a4ef3SDoug Ambrisko #define MFI_REQ_DESCRIPT_FLAGS_TYPE_SHIFT	0x1
3910d9a4ef3SDoug Ambrisko #define MFI_FUSION_FP_DEFAULT_TIMEOUT		0x14
3920d9a4ef3SDoug Ambrisko #define MFI_LOAD_BALANCE_FLAG			0x1
3930d9a4ef3SDoug Ambrisko #define MFI_DCMD_MBOX_PEND_FLAG			0x1
3940d9a4ef3SDoug Ambrisko 
3950d9a4ef3SDoug Ambrisko //#define MR_PROT_INFO_TYPE_CONTROLLER	0x08
3960d9a4ef3SDoug Ambrisko #define	MEGASAS_SCSI_VARIABLE_LENGTH_CMD	0x7f
3970d9a4ef3SDoug Ambrisko #define MEGASAS_SCSI_SERVICE_ACTION_READ32	0x9
3980d9a4ef3SDoug Ambrisko #define MEGASAS_SCSI_SERVICE_ACTION_WRITE32	0xB
3990d9a4ef3SDoug Ambrisko #define	MEGASAS_SCSI_ADDL_CDB_LEN   		0x18
4000d9a4ef3SDoug Ambrisko #define MEGASAS_RD_WR_PROTECT_CHECK_ALL		0x20
4010d9a4ef3SDoug Ambrisko #define MEGASAS_RD_WR_PROTECT_CHECK_NONE	0x60
4020d9a4ef3SDoug Ambrisko #define MEGASAS_EEDPBLOCKSIZE			512
4030d9a4ef3SDoug Ambrisko struct mfi_cmd_tbolt {
4040d9a4ef3SDoug Ambrisko 	union mfi_mpi2_request_descriptor *request_desc;
4050d9a4ef3SDoug Ambrisko 	struct mfi_mpi2_request_raid_scsi_io *io_request;
406a6ba0fd6SDoug Ambrisko 	bus_addr_t		io_request_phys_addr;
407a6ba0fd6SDoug Ambrisko 	bus_addr_t		sg_frame_phys_addr;
408a6ba0fd6SDoug Ambrisko 	bus_addr_t 		sense_phys_addr;
4090d9a4ef3SDoug Ambrisko 	MPI2_SGE_IO_UNION	*sg_frame;
4100d9a4ef3SDoug Ambrisko 	uint8_t			*sense;
4110d9a4ef3SDoug Ambrisko 	TAILQ_ENTRY(mfi_cmd_tbolt) next;
4120d9a4ef3SDoug Ambrisko 	/*
4130d9a4ef3SDoug Ambrisko 	 * Context for a MFI frame.
4140d9a4ef3SDoug Ambrisko 	 * Used to get the mfi cmd from list when a MFI cmd is completed
4150d9a4ef3SDoug Ambrisko 	 */
4160d9a4ef3SDoug Ambrisko 	uint32_t		sync_cmd_idx;
4170d9a4ef3SDoug Ambrisko 	uint16_t		index;
4180d9a4ef3SDoug Ambrisko 	uint8_t			status;
4192e21a3efSScott Long };
4202e21a3efSScott Long 
4212e21a3efSScott Long extern int mfi_attach(struct mfi_softc *);
4222e21a3efSScott Long extern void mfi_free(struct mfi_softc *);
4232e21a3efSScott Long extern int mfi_shutdown(struct mfi_softc *);
4242e21a3efSScott Long extern void mfi_startio(struct mfi_softc *);
4252e21a3efSScott Long extern void mfi_disk_complete(struct bio *);
4268ec5c98bSJohn Baldwin extern int mfi_disk_disable(struct mfi_disk *);
4278ec5c98bSJohn Baldwin extern void mfi_disk_enable(struct mfi_disk *);
4282e21a3efSScott Long extern int mfi_dump_blocks(struct mfi_softc *, int id, uint64_t, void *, int);
4290d9a4ef3SDoug Ambrisko extern int mfi_syspd_disable(struct mfi_system_pd *);
4300d9a4ef3SDoug Ambrisko extern void mfi_syspd_enable(struct mfi_system_pd *);
4310d9a4ef3SDoug Ambrisko extern int mfi_dump_syspd_blocks(struct mfi_softc *, int id, uint64_t, void *,
4320d9a4ef3SDoug Ambrisko     int);
4330d9a4ef3SDoug Ambrisko extern int mfi_transition_firmware(struct mfi_softc *sc);
4340d9a4ef3SDoug Ambrisko extern int mfi_aen_setup(struct mfi_softc *sc, uint32_t seq_start);
4350d9a4ef3SDoug Ambrisko extern void mfi_complete(struct mfi_softc *sc, struct mfi_command *cm);
4360d9a4ef3SDoug Ambrisko extern int mfi_mapcmd(struct mfi_softc *sc,struct mfi_command *cm);
4370d9a4ef3SDoug Ambrisko extern int mfi_wait_command(struct mfi_softc *sc, struct mfi_command *cm);
4380d9a4ef3SDoug Ambrisko extern void mfi_tbolt_enable_intr_ppc(struct mfi_softc *);
4390d9a4ef3SDoug Ambrisko extern void mfi_tbolt_disable_intr_ppc(struct mfi_softc *);
4400d9a4ef3SDoug Ambrisko extern int32_t mfi_tbolt_read_fw_status_ppc(struct mfi_softc *);
4410d9a4ef3SDoug Ambrisko extern int32_t mfi_tbolt_check_clear_intr_ppc(struct mfi_softc *);
4420d9a4ef3SDoug Ambrisko extern void mfi_tbolt_issue_cmd_ppc(struct mfi_softc *, bus_addr_t, uint32_t);
4430d9a4ef3SDoug Ambrisko extern void mfi_tbolt_init_globals(struct mfi_softc*);
4440d9a4ef3SDoug Ambrisko extern uint32_t mfi_tbolt_get_memory_requirement(struct mfi_softc *);
4450d9a4ef3SDoug Ambrisko extern int mfi_tbolt_init_desc_pool(struct mfi_softc *, uint8_t *, uint32_t);
4460d9a4ef3SDoug Ambrisko extern int mfi_tbolt_init_MFI_queue(struct mfi_softc *);
4470d9a4ef3SDoug Ambrisko extern void mfi_intr_tbolt(void *arg);
4480d9a4ef3SDoug Ambrisko extern int mfi_tbolt_alloc_cmd(struct mfi_softc *sc);
4490d9a4ef3SDoug Ambrisko extern int mfi_tbolt_send_frame(struct mfi_softc *sc, struct mfi_command *cm);
4500d9a4ef3SDoug Ambrisko extern int mfi_tbolt_adp_reset(struct mfi_softc *sc);
4510d9a4ef3SDoug Ambrisko extern int mfi_tbolt_reset(struct mfi_softc *sc);
452ddbffe7fSDoug Ambrisko extern void mfi_tbolt_sync_map_info(struct mfi_softc *sc);
453ddbffe7fSDoug Ambrisko extern void mfi_handle_map_sync(void *context, int pending);
454ddbffe7fSDoug Ambrisko extern int mfi_dcmd_command(struct mfi_softc *, struct mfi_command **,
455ddbffe7fSDoug Ambrisko      uint32_t, void **, size_t);
45658ef3154SDoug Ambrisko extern int mfi_build_cdb(int, uint8_t, u_int64_t, u_int32_t, uint8_t *);
4572e21a3efSScott Long 
4582e21a3efSScott Long #define MFIQ_ADD(sc, qname)					\
4592e21a3efSScott Long 	do {							\
4602e21a3efSScott Long 		struct mfi_qstat *qs;				\
4612e21a3efSScott Long 								\
4622e21a3efSScott Long 		qs = &(sc)->mfi_qstat[qname];			\
4632e21a3efSScott Long 		qs->q_length++;					\
4642e21a3efSScott Long 		if (qs->q_length > qs->q_max)			\
4652e21a3efSScott Long 			qs->q_max = qs->q_length;		\
4662e21a3efSScott Long 	} while (0)
4672e21a3efSScott Long 
4682e21a3efSScott Long #define MFIQ_REMOVE(sc, qname)	(sc)->mfi_qstat[qname].q_length--
4692e21a3efSScott Long 
4702e21a3efSScott Long #define MFIQ_INIT(sc, qname)					\
4712e21a3efSScott Long 	do {							\
4722e21a3efSScott Long 		sc->mfi_qstat[qname].q_length = 0;		\
4732e21a3efSScott Long 		sc->mfi_qstat[qname].q_max = 0;			\
4742e21a3efSScott Long 	} while (0)
4752e21a3efSScott Long 
4762e21a3efSScott Long #define MFIQ_COMMAND_QUEUE(name, index)					\
4772e21a3efSScott Long 	static __inline void						\
4782e21a3efSScott Long 	mfi_initq_ ## name (struct mfi_softc *sc)			\
4792e21a3efSScott Long 	{								\
4802e21a3efSScott Long 		TAILQ_INIT(&sc->mfi_ ## name);				\
4812e21a3efSScott Long 		MFIQ_INIT(sc, index);					\
4822e21a3efSScott Long 	}								\
4832e21a3efSScott Long 	static __inline void						\
4842e21a3efSScott Long 	mfi_enqueue_ ## name (struct mfi_command *cm)			\
4852e21a3efSScott Long 	{								\
4862e21a3efSScott Long 		if ((cm->cm_flags & MFI_ON_MFIQ_MASK) != 0) {		\
48708c89430SSteven Hartland 			panic("command %p is on another queue, "	\
4882e21a3efSScott Long 			    "flags = %#x\n", cm, cm->cm_flags);		\
4892e21a3efSScott Long 		}							\
4902e21a3efSScott Long 		TAILQ_INSERT_TAIL(&cm->cm_sc->mfi_ ## name, cm, cm_link); \
4912e21a3efSScott Long 		cm->cm_flags |= MFI_ON_ ## index;			\
4922e21a3efSScott Long 		MFIQ_ADD(cm->cm_sc, index);				\
4932e21a3efSScott Long 	}								\
4942e21a3efSScott Long 	static __inline void						\
4952e21a3efSScott Long 	mfi_requeue_ ## name (struct mfi_command *cm)			\
4962e21a3efSScott Long 	{								\
4972e21a3efSScott Long 		if ((cm->cm_flags & MFI_ON_MFIQ_MASK) != 0) {		\
49808c89430SSteven Hartland 			panic("command %p is on another queue, "	\
4992e21a3efSScott Long 			    "flags = %#x\n", cm, cm->cm_flags);		\
5002e21a3efSScott Long 		}							\
5012e21a3efSScott Long 		TAILQ_INSERT_HEAD(&cm->cm_sc->mfi_ ## name, cm, cm_link); \
5022e21a3efSScott Long 		cm->cm_flags |= MFI_ON_ ## index;			\
5032e21a3efSScott Long 		MFIQ_ADD(cm->cm_sc, index);				\
5042e21a3efSScott Long 	}								\
5052e21a3efSScott Long 	static __inline struct mfi_command *				\
5062e21a3efSScott Long 	mfi_dequeue_ ## name (struct mfi_softc *sc)			\
5072e21a3efSScott Long 	{								\
5082e21a3efSScott Long 		struct mfi_command *cm;					\
5092e21a3efSScott Long 									\
5102e21a3efSScott Long 		if ((cm = TAILQ_FIRST(&sc->mfi_ ## name)) != NULL) {	\
5112e21a3efSScott Long 			if ((cm->cm_flags & MFI_ON_ ## index) == 0) {	\
51208c89430SSteven Hartland 				panic("command %p not in queue, "	\
5132e21a3efSScott Long 				    "flags = %#x, bit = %#x\n", cm,	\
5142e21a3efSScott Long 				    cm->cm_flags, MFI_ON_ ## index);	\
5152e21a3efSScott Long 			}						\
5162e21a3efSScott Long 			TAILQ_REMOVE(&sc->mfi_ ## name, cm, cm_link);	\
5172e21a3efSScott Long 			cm->cm_flags &= ~MFI_ON_ ## index;		\
5182e21a3efSScott Long 			MFIQ_REMOVE(sc, index);				\
5192e21a3efSScott Long 		}							\
5202e21a3efSScott Long 		return (cm);						\
5212e21a3efSScott Long 	}								\
5222e21a3efSScott Long 	static __inline void						\
5232e21a3efSScott Long 	mfi_remove_ ## name (struct mfi_command *cm)			\
5242e21a3efSScott Long 	{								\
5252e21a3efSScott Long 		if ((cm->cm_flags & MFI_ON_ ## index) == 0) {		\
52608c89430SSteven Hartland 			panic("command %p not in queue, flags = %#x, " \
5272e21a3efSScott Long 			    "bit = %#x\n", cm, cm->cm_flags,		\
5282e21a3efSScott Long 			    MFI_ON_ ## index);				\
5292e21a3efSScott Long 		}							\
5302e21a3efSScott Long 		TAILQ_REMOVE(&cm->cm_sc->mfi_ ## name, cm, cm_link);	\
5312e21a3efSScott Long 		cm->cm_flags &= ~MFI_ON_ ## index;			\
5322e21a3efSScott Long 		MFIQ_REMOVE(cm->cm_sc, index);				\
5332e21a3efSScott Long 	}								\
5342e21a3efSScott Long struct hack
5352e21a3efSScott Long 
5362e21a3efSScott Long MFIQ_COMMAND_QUEUE(free, MFIQ_FREE);
5372e21a3efSScott Long MFIQ_COMMAND_QUEUE(ready, MFIQ_READY);
5382e21a3efSScott Long MFIQ_COMMAND_QUEUE(busy, MFIQ_BUSY);
5392e21a3efSScott Long 
5402e21a3efSScott Long static __inline void
mfi_initq_bio(struct mfi_softc * sc)5412e21a3efSScott Long mfi_initq_bio(struct mfi_softc *sc)
5422e21a3efSScott Long {
5432e21a3efSScott Long 	bioq_init(&sc->mfi_bioq);
5442e21a3efSScott Long 	MFIQ_INIT(sc, MFIQ_BIO);
5452e21a3efSScott Long }
5462e21a3efSScott Long 
5472e21a3efSScott Long static __inline void
mfi_enqueue_bio(struct mfi_softc * sc,struct bio * bp)5482e21a3efSScott Long mfi_enqueue_bio(struct mfi_softc *sc, struct bio *bp)
5492e21a3efSScott Long {
5502e21a3efSScott Long 	bioq_insert_tail(&sc->mfi_bioq, bp);
5512e21a3efSScott Long 	MFIQ_ADD(sc, MFIQ_BIO);
5522e21a3efSScott Long }
5532e21a3efSScott Long 
5542e21a3efSScott Long static __inline struct bio *
mfi_dequeue_bio(struct mfi_softc * sc)5552e21a3efSScott Long mfi_dequeue_bio(struct mfi_softc *sc)
5562e21a3efSScott Long {
5572e21a3efSScott Long 	struct bio *bp;
5582e21a3efSScott Long 
5592e21a3efSScott Long 	if ((bp = bioq_first(&sc->mfi_bioq)) != NULL) {
5602e21a3efSScott Long 		bioq_remove(&sc->mfi_bioq, bp);
5612e21a3efSScott Long 		MFIQ_REMOVE(sc, MFIQ_BIO);
5622e21a3efSScott Long 	}
5632e21a3efSScott Long 	return (bp);
5642e21a3efSScott Long }
5652e21a3efSScott Long 
56651550f82SScott Long /*
56751550f82SScott Long  * This is from the original scsi_extract_sense() in CAM.  It's copied
56851550f82SScott Long  * here because CAM now uses a non-inline version that follows more complex
56951550f82SScott Long  * additions to the SPC spec, and we don't want to force a dependency on
57051550f82SScott Long  * the CAM module for such a trivial action.
57151550f82SScott Long  */
57251550f82SScott Long static __inline void
mfi_extract_sense(struct scsi_sense_data_fixed * sense,int * error_code,int * sense_key,int * asc,int * ascq)57351550f82SScott Long mfi_extract_sense(struct scsi_sense_data_fixed *sense,
57451550f82SScott Long     int *error_code, int *sense_key, int *asc, int *ascq)
57551550f82SScott Long {
57651550f82SScott Long 
57751550f82SScott Long 	*error_code = sense->error_code & SSD_ERRCODE;
57851550f82SScott Long 	*sense_key = sense->flags & SSD_KEY;
57951550f82SScott Long 	*asc = (sense->extra_len >= 5) ? sense->add_sense_code : 0;
58051550f82SScott Long 	*ascq = (sense->extra_len >= 6) ? sense->add_sense_code_qual : 0;
58151550f82SScott Long }
58251550f82SScott Long 
5832e21a3efSScott Long static __inline void
mfi_print_sense(struct mfi_softc * sc,void * sense)5842e21a3efSScott Long mfi_print_sense(struct mfi_softc *sc, void *sense)
5852e21a3efSScott Long {
5862e21a3efSScott Long 	int error, key, asc, ascq;
5872e21a3efSScott Long 
58851550f82SScott Long 	mfi_extract_sense((struct scsi_sense_data_fixed *)sense,
5892e21a3efSScott Long 	    &error, &key, &asc, &ascq);
5902e21a3efSScott Long 	device_printf(sc->mfi_dev, "sense error %d, sense_key %d, "
5912e21a3efSScott Long 	    "asc %d, ascq %d\n", error, key, asc, ascq);
5922e21a3efSScott Long }
5932e21a3efSScott Long 
5942e21a3efSScott Long #define MFI_WRITE4(sc, reg, val)	bus_space_write_4((sc)->mfi_btag, \
5952e21a3efSScott Long 	sc->mfi_bhandle, (reg), (val))
5962e21a3efSScott Long #define MFI_READ4(sc, reg)		bus_space_read_4((sc)->mfi_btag, \
5972e21a3efSScott Long 	(sc)->mfi_bhandle, (reg))
5982e21a3efSScott Long #define MFI_WRITE2(sc, reg, val)	bus_space_write_2((sc)->mfi_btag, \
5992e21a3efSScott Long 	sc->mfi_bhandle, (reg), (val))
6002e21a3efSScott Long #define MFI_READ2(sc, reg)		bus_space_read_2((sc)->mfi_btag, \
6012e21a3efSScott Long 	(sc)->mfi_bhandle, (reg))
6022e21a3efSScott Long #define MFI_WRITE1(sc, reg, val)	bus_space_write_1((sc)->mfi_btag, \
6032e21a3efSScott Long 	sc->mfi_bhandle, (reg), (val))
6042e21a3efSScott Long #define MFI_READ1(sc, reg)		bus_space_read_1((sc)->mfi_btag, \
6052e21a3efSScott Long 	(sc)->mfi_bhandle, (reg))
6062e21a3efSScott Long 
6072e21a3efSScott Long MALLOC_DECLARE(M_MFIBUF);
608d1c5fc76SJohn Baldwin SYSCTL_DECL(_hw_mfi);
6092e21a3efSScott Long 
6100d9a4ef3SDoug Ambrisko #define MFI_RESET_WAIT_TIME 180
6115ba21ff1SScott Long #define MFI_CMD_TIMEOUT 30
6120d9a4ef3SDoug Ambrisko #define MFI_SYS_PD_IO	0
6130d9a4ef3SDoug Ambrisko #define MFI_LD_IO	1
6147e4dd9e1SDoug Ambrisko #define MFI_SKINNY_MEMORY 0x02000000
61552c9ce25SScott Long #define MFI_MAXPHYS (128 * 1024)
6165ba21ff1SScott Long 
6175ba21ff1SScott Long #ifdef MFI_DEBUG
6185ba21ff1SScott Long extern void mfi_print_cmd(struct mfi_command *cm);
6195ba21ff1SScott Long extern void mfi_dump_cmds(struct mfi_softc *sc);
62008c89430SSteven Hartland extern void mfi_validate_sg(struct mfi_softc *, struct mfi_command *,
62108c89430SSteven Hartland     const char *, int);
6225ba21ff1SScott Long #define MFI_PRINT_CMD(cm)	mfi_print_cmd(cm)
623441f6d5dSScott Long #define MFI_DUMP_CMDS(sc)	mfi_dump_cmds(sc)
624441f6d5dSScott Long #define MFI_VALIDATE_CMD(sc, cm) mfi_validate_sg(sc, cm, __FUNCTION__, __LINE__)
6255ba21ff1SScott Long #else
6265ba21ff1SScott Long #define MFI_PRINT_CMD(cm)
6275ba21ff1SScott Long #define MFI_DUMP_CMDS(sc)
628441f6d5dSScott Long #define MFI_VALIDATE_CMD(sc, cm)
6295ba21ff1SScott Long #endif
6305ba21ff1SScott Long 
63108c89430SSteven Hartland extern void mfi_release_command(struct mfi_command *);
63208c89430SSteven Hartland extern void mfi_tbolt_return_cmd(struct mfi_softc *,
63308c89430SSteven Hartland     struct mfi_cmd_tbolt *, struct mfi_command *);
63435ef86f2SScott Long 
6352e21a3efSScott Long #endif /* _MFIVAR_H */
636