mfireg.h revision 234429
1157114Sscottl/*-
2157114Sscottl * Copyright (c) 2006 IronPort Systems
3157114Sscottl * All rights reserved.
4157114Sscottl *
5157114Sscottl * Redistribution and use in source and binary forms, with or without
6157114Sscottl * modification, are permitted provided that the following conditions
7157114Sscottl * are met:
8157114Sscottl * 1. Redistributions of source code must retain the above copyright
9157114Sscottl *    notice, this list of conditions and the following disclaimer.
10157114Sscottl * 2. Redistributions in binary form must reproduce the above copyright
11157114Sscottl *    notice, this list of conditions and the following disclaimer in the
12157114Sscottl *    documentation and/or other materials provided with the distribution.
13157114Sscottl *
14157114Sscottl * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15157114Sscottl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16157114Sscottl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17157114Sscottl * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18157114Sscottl * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19157114Sscottl * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20157114Sscottl * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21157114Sscottl * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22157114Sscottl * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23157114Sscottl * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24157114Sscottl * SUCH DAMAGE.
25157114Sscottl */
26171980Sscottl/*-
27171980Sscottl * Copyright (c) 2007 LSI Corp.
28171980Sscottl * Copyright (c) 2007 Rajesh Prabhakaran.
29171980Sscottl * All rights reserved.
30171980Sscottl *
31171980Sscottl * Redistribution and use in source and binary forms, with or without
32171980Sscottl * modification, are permitted provided that the following conditions
33171980Sscottl * are met:
34171980Sscottl * 1. Redistributions of source code must retain the above copyright
35171980Sscottl *    notice, this list of conditions and the following disclaimer.
36171980Sscottl * 2. Redistributions in binary form must reproduce the above copyright
37171980Sscottl *    notice, this list of conditions and the following disclaimer in the
38171980Sscottl *    documentation and/or other materials provided with the distribution.
39171980Sscottl *
40171980Sscottl * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
41171980Sscottl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42171980Sscottl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43171980Sscottl * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
44171980Sscottl * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45171980Sscottl * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46171980Sscottl * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47171980Sscottl * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48171980Sscottl * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49171980Sscottl * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50171980Sscottl * SUCH DAMAGE.
51171980Sscottl */
52157114Sscottl
53157114Sscottl#ifndef _MFIREG_H
54157114Sscottl#define _MFIREG_H
55157114Sscottl
56157114Sscottl#include <sys/cdefs.h>
57157114Sscottl__FBSDID("$FreeBSD: stable/9/sys/dev/mfi/mfireg.h 234429 2012-04-18 18:31:11Z ambrisko $");
58157114Sscottl
59157114Sscottl/*
60157114Sscottl * MegaRAID SAS MFI firmware definitions
61157114Sscottl *
62157114Sscottl * Calling this driver 'MegaRAID SAS' is a bit misleading.  It's a completely
63157114Sscottl * new firmware interface from the old AMI MegaRAID one, and there is no
64157114Sscottl * reason why this interface should be limited to just SAS.  In any case, LSI
65157114Sscottl * seems to also call this interface 'MFI', so that will be used here.
66157114Sscottl */
67234429Sambrisko#define MEGAMFI_FRAME_SIZE              64
68157114Sscottl/*
69157114Sscottl * Start with the register set.  All registers are 32 bits wide.
70157114Sscottl * The usual Intel IOP style setup.
71157114Sscottl */
72157114Sscottl#define MFI_IMSG0	0x10	/* Inbound message 0 */
73157114Sscottl#define MFI_IMSG1	0x14	/* Inbound message 1 */
74157114Sscottl#define MFI_OMSG0	0x18	/* Outbound message 0 */
75157114Sscottl#define MFI_OMSG1	0x1c	/* Outbound message 1 */
76157114Sscottl#define MFI_IDB		0x20	/* Inbound doorbell */
77157114Sscottl#define MFI_ISTS	0x24	/* Inbound interrupt status */
78157114Sscottl#define MFI_IMSK	0x28	/* Inbound interrupt mask */
79157114Sscottl#define MFI_ODB		0x2c	/* Outbound doorbell */
80157114Sscottl#define MFI_OSTS	0x30	/* Outbound interrupt status */
81157114Sscottl#define MFI_OMSK	0x34	/* Outbound interrupt mask */
82157114Sscottl#define MFI_IQP		0x40	/* Inbound queue port */
83157114Sscottl#define MFI_OQP		0x44	/* Outbound queue port */
84157114Sscottl
85171980Sscottl/*
86234429Sambrisko*  ThunderBolt specific Register
87234429Sambrisko*/
88234429Sambrisko
89234429Sambrisko#define MFI_RPI		0x6c 		/* reply_post_host_index */
90234429Sambrisko#define MFI_ILQP 	0xc0		/* inbound_low_queue_port */
91234429Sambrisko#define MFI_IHQP 	0xc4		/* inbound_high_queue_port */
92234429Sambrisko
93234429Sambrisko/*
94171980Sscottl * 1078 specific related register
95171980Sscottl */
96171980Sscottl#define MFI_ODR0	0x9c 		/* outbound doorbell register0 */
97171980Sscottl#define MFI_ODCR0	0xa0 		/* outbound doorbell clear register0  */
98171980Sscottl#define MFI_OSP0	0xb0 		/* outbound scratch pad0  */
99171980Sscottl#define MFI_1078_EIM	0x80000004 	/* 1078 enable intrrupt mask  */
100234429Sambrisko#define MFI_RMI		0x2 		/* reply message interrupt  */
101171980Sscottl#define MFI_1078_RM	0x80000000 	/* reply 1078 message interrupt  */
102171980Sscottl#define MFI_ODC		0x4 		/* outbound doorbell change interrupt */
103171980Sscottl
104234429Sambrisko/* OCR registers */
105234429Sambrisko#define MFI_WSR		0x004		/* write sequence register */
106234429Sambrisko#define MFI_HDR		0x008		/* host diagnostic register */
107234429Sambrisko#define MFI_RSR		0x3c3		/* Reset Status Register */
108234429Sambrisko
109184897Sambrisko/*
110184897Sambrisko * GEN2 specific changes
111184897Sambrisko */
112184897Sambrisko#define MFI_GEN2_EIM	0x00000005	/* GEN2 enable interrupt mask */
113184897Sambrisko#define MFI_GEN2_RM	0x00000001	/* reply GEN2 message interrupt */
114184897Sambrisko
115234429Sambrisko/*
116234429Sambrisko * skinny specific changes
117234429Sambrisko */
118234429Sambrisko#define MFI_SKINNY_IDB	0x00	/* Inbound doorbell is at 0x00 for skinny */
119234429Sambrisko#define MFI_IQPL	0x000000c0
120234429Sambrisko#define MFI_IQPH	0x000000c4
121234429Sambrisko#define MFI_SKINNY_RM	0x00000001	/* reply skinny message interrupt */
122234429Sambrisko
123157114Sscottl/* Bits for MFI_OSTS */
124157114Sscottl#define MFI_OSTS_INTR_VALID	0x00000002
125157114Sscottl
126234429Sambrisko/* OCR specific flags */
127234429Sambrisko#define MFI_FIRMWARE_STATE_CHANGE	0x00000002
128234429Sambrisko#define MFI_STATE_CHANGE_INTERRUPT	0x00000004  /* MFI state change interrrupt */
129234429Sambrisko
130157114Sscottl/*
131157114Sscottl * Firmware state values.  Found in OMSG0 during initialization.
132157114Sscottl */
133157114Sscottl#define MFI_FWSTATE_MASK		0xf0000000
134157114Sscottl#define MFI_FWSTATE_UNDEFINED		0x00000000
135157114Sscottl#define MFI_FWSTATE_BB_INIT		0x10000000
136157114Sscottl#define MFI_FWSTATE_FW_INIT		0x40000000
137157114Sscottl#define MFI_FWSTATE_WAIT_HANDSHAKE	0x60000000
138157114Sscottl#define MFI_FWSTATE_FW_INIT_2		0x70000000
139157114Sscottl#define MFI_FWSTATE_DEVICE_SCAN		0x80000000
140224041Sjhb#define MFI_FWSTATE_BOOT_MESSAGE_PENDING	0x90000000
141157114Sscottl#define MFI_FWSTATE_FLUSH_CACHE		0xa0000000
142157114Sscottl#define MFI_FWSTATE_READY		0xb0000000
143157114Sscottl#define MFI_FWSTATE_OPERATIONAL		0xc0000000
144157114Sscottl#define MFI_FWSTATE_FAULT		0xf0000000
145157114Sscottl#define MFI_FWSTATE_MAXSGL_MASK		0x00ff0000
146157114Sscottl#define MFI_FWSTATE_MAXCMD_MASK		0x0000ffff
147234429Sambrisko#define MFI_FWSTATE_HOSTMEMREQD_MASK	0x08000000
148234429Sambrisko#define MFI_FWSTATE_BOOT_MESSAGE_PENDING	0x90000000
149234429Sambrisko#define MFI_RESET_REQUIRED		0x00000001
150157114Sscottl
151234429Sambrisko/* ThunderBolt Support */
152234429Sambrisko#define MFI_FWSTATE_TB_MASK		0xf0000000
153234429Sambrisko#define MFI_FWSTATE_TB_RESET		0x00000000
154234429Sambrisko#define MFI_FWSTATE_TB_READY		0x10000000
155234429Sambrisko#define MFI_FWSTATE_TB_OPERATIONAL	0x20000000
156234429Sambrisko#define MFI_FWSTATE_TB_FAULT		0x40000000
157234429Sambrisko
158157114Sscottl/*
159157114Sscottl * Control bits to drive the card to ready state.  These go into the IDB
160157114Sscottl * register.
161157114Sscottl */
162157114Sscottl#define MFI_FWINIT_ABORT	0x00000000 /* Abort all pending commands */
163157114Sscottl#define MFI_FWINIT_READY	0x00000002 /* Move from operational to ready */
164157114Sscottl#define MFI_FWINIT_MFIMODE	0x00000004 /* unknown */
165157114Sscottl#define MFI_FWINIT_CLEAR_HANDSHAKE 0x00000008 /* Respond to WAIT_HANDSHAKE */
166224041Sjhb#define MFI_FWINIT_HOTPLUG	0x00000010
167157114Sscottl
168234429Sambrisko/* ADP reset flags */
169234429Sambrisko#define MFI_STOP_ADP		0x00000020
170234429Sambrisko#define MFI_ADP_RESET		0x00000040
171234429Sambrisko#define DIAG_WRITE_ENABLE	0x00000080
172234429Sambrisko#define DIAG_RESET_ADAPTER	0x00000004
173234429Sambrisko
174157114Sscottl/* MFI Commands */
175157114Sscottltypedef enum {
176157114Sscottl	MFI_CMD_INIT =		0x00,
177157114Sscottl	MFI_CMD_LD_READ,
178157114Sscottl	MFI_CMD_LD_WRITE,
179157114Sscottl	MFI_CMD_LD_SCSI_IO,
180157114Sscottl	MFI_CMD_PD_SCSI_IO,
181157114Sscottl	MFI_CMD_DCMD,
182157114Sscottl	MFI_CMD_ABORT,
183157114Sscottl	MFI_CMD_SMP,
184157114Sscottl	MFI_CMD_STP
185157114Sscottl} mfi_cmd_t;
186157114Sscottl
187157114Sscottl/* Direct commands */
188157114Sscottltypedef enum {
189157114Sscottl	MFI_DCMD_CTRL_GETINFO =		0x01010000,
190234429Sambrisko	MFI_DCMD_CTRL_MFI_HOST_MEM_ALLOC =0x0100e100,
191163398Sscottl	MFI_DCMD_CTRL_MFC_DEFAULTS_GET =0x010e0201,
192163398Sscottl	MFI_DCMD_CTRL_MFC_DEFAULTS_SET =0x010e0202,
193157114Sscottl	MFI_DCMD_CTRL_FLUSHCACHE =	0x01101000,
194157114Sscottl	MFI_DCMD_CTRL_SHUTDOWN =	0x01050000,
195157114Sscottl	MFI_DCMD_CTRL_EVENT_GETINFO =	0x01040100,
196157114Sscottl	MFI_DCMD_CTRL_EVENT_GET =	0x01040300,
197157114Sscottl	MFI_DCMD_CTRL_EVENT_WAIT =	0x01040500,
198196200Sscottl	MFI_DCMD_PR_GET_STATUS =	0x01070100,
199196200Sscottl	MFI_DCMD_PR_GET_PROPERTIES =	0x01070200,
200196200Sscottl	MFI_DCMD_PR_SET_PROPERTIES =	0x01070300,
201196200Sscottl	MFI_DCMD_PR_START =		0x01070400,
202196200Sscottl	MFI_DCMD_PR_STOP =		0x01070500,
203196200Sscottl	MFI_DCMD_TIME_SECS_GET =	0x01080201,
204196200Sscottl	MFI_DCMD_FLASH_FW_OPEN =	0x010f0100,
205196200Sscottl	MFI_DCMD_FLASH_FW_DOWNLOAD =	0x010f0200,
206196200Sscottl	MFI_DCMD_FLASH_FW_FLASH =	0x010f0300,
207196200Sscottl	MFI_DCMD_FLASH_FW_CLOSE =	0x010f0400,
208196200Sscottl	MFI_DCMD_PD_GET_LIST =		0x02010000,
209234429Sambrisko	MFI_DCMD_PD_LIST_QUERY =	0x02010100,
210196200Sscottl	MFI_DCMD_PD_GET_INFO = 		0x02020000,
211196200Sscottl	MFI_DCMD_PD_STATE_SET =		0x02030100,
212196200Sscottl	MFI_DCMD_PD_REBUILD_START =	0x02040100,
213196200Sscottl	MFI_DCMD_PD_REBUILD_ABORT =	0x02040200,
214196200Sscottl	MFI_DCMD_PD_CLEAR_START =	0x02050100,
215196200Sscottl	MFI_DCMD_PD_CLEAR_ABORT =	0x02050200,
216196200Sscottl	MFI_DCMD_PD_GET_PROGRESS =	0x02060000,
217196200Sscottl	MFI_DCMD_PD_LOCATE_START =	0x02070100,
218196200Sscottl	MFI_DCMD_PD_LOCATE_STOP =	0x02070200,
219234429Sambrisko	MFI_DCMD_LD_MAP_GET_INFO =	0x0300e101,
220234429Sambrisko	MFI_DCMD_LD_SYNC =		0x0300e102,
221159811Sps	MFI_DCMD_LD_GET_LIST =		0x03010000,
222159811Sps	MFI_DCMD_LD_GET_INFO =		0x03020000,
223157114Sscottl	MFI_DCMD_LD_GET_PROP =		0x03030000,
224159811Sps	MFI_DCMD_LD_SET_PROP =		0x03040000,
225196200Sscottl	MFI_DCMD_LD_INIT_START =	0x03060100,
226171821Sjhb	MFI_DCMD_LD_DELETE =		0x03090000,
227163398Sscottl	MFI_DCMD_CFG_READ =		0x04010000,
228163398Sscottl	MFI_DCMD_CFG_ADD =		0x04020000,
229163398Sscottl	MFI_DCMD_CFG_CLEAR =		0x04030000,
230196200Sscottl	MFI_DCMD_CFG_MAKE_SPARE =	0x04040000,
231234429Sambrisko	MFI_DCMD_CFG_REMOVE_SPARE =	0x04050000,
232184897Sambrisko	MFI_DCMD_CFG_FOREIGN_IMPORT =	0x04060400,
233196200Sscottl	MFI_DCMD_BBU_GET_STATUS =	0x05010000,
234196200Sscottl	MFI_DCMD_BBU_GET_CAPACITY_INFO =0x05020000,
235196200Sscottl	MFI_DCMD_BBU_GET_DESIGN_INFO =	0x05030000,
236157114Sscottl	MFI_DCMD_CLUSTER =		0x08000000,
237157114Sscottl	MFI_DCMD_CLUSTER_RESET_ALL =	0x08010100,
238157114Sscottl	MFI_DCMD_CLUSTER_RESET_LD =	0x08010200
239157114Sscottl} mfi_dcmd_t;
240157114Sscottl
241157114Sscottl/* Modifiers for MFI_DCMD_CTRL_FLUSHCACHE */
242157114Sscottl#define MFI_FLUSHCACHE_CTRL	0x01
243157114Sscottl#define MFI_FLUSHCACHE_DISK	0x02
244157114Sscottl
245157114Sscottl/* Modifiers for MFI_DCMD_CTRL_SHUTDOWN */
246157114Sscottl#define MFI_SHUTDOWN_SPINDOWN	0x01
247157114Sscottl
248157114Sscottl/*
249158737Sambrisko * MFI Frame flags
250157114Sscottl */
251157114Sscottl#define MFI_FRAME_POST_IN_REPLY_QUEUE		0x0000
252157114Sscottl#define MFI_FRAME_DONT_POST_IN_REPLY_QUEUE	0x0001
253157114Sscottl#define MFI_FRAME_SGL32				0x0000
254157114Sscottl#define MFI_FRAME_SGL64				0x0002
255157114Sscottl#define MFI_FRAME_SENSE32			0x0000
256157114Sscottl#define MFI_FRAME_SENSE64			0x0004
257157114Sscottl#define MFI_FRAME_DIR_NONE			0x0000
258157114Sscottl#define MFI_FRAME_DIR_WRITE			0x0008
259157114Sscottl#define MFI_FRAME_DIR_READ			0x0010
260157114Sscottl#define MFI_FRAME_DIR_BOTH			0x0018
261234429Sambrisko#define MFI_FRAME_IEEE_SGL			0x0020
262157114Sscottl
263234429Sambrisko/* ThunderBolt Specific */
264234429Sambrisko
265234429Sambrisko/*
266234429Sambrisko * Pre-TB command size and TB command size.
267234429Sambrisko * We will be checking it at the load time for the time being
268234429Sambrisko */
269234429Sambrisko#define MR_COMMAND_SIZE (MFI_FRAME_SIZE*20) /* 1280 bytes */
270234429Sambrisko
271234429Sambrisko#define MEGASAS_THUNDERBOLT_MSG_ALLIGNMENT  256
272234429Sambrisko/*
273234429Sambrisko * We are defining only 128 byte message to reduce memory move over head
274234429Sambrisko * and also it will reduce the SRB extension size by 128byte compared with
275234429Sambrisko * 256 message size
276234429Sambrisko */
277234429Sambrisko#define MEGASAS_THUNDERBOLT_NEW_MSG_SIZE	256
278234429Sambrisko#define MEGASAS_THUNDERBOLT_MAX_COMMANDS	1024
279234429Sambrisko#define MEGASAS_THUNDERBOLT_MAX_REPLY_COUNT	1024
280234429Sambrisko#define MEGASAS_THUNDERBOLT_REPLY_SIZE		8
281234429Sambrisko#define MEGASAS_THUNDERBOLT_MAX_CHAIN_COUNT	1
282234429Sambrisko#define MEGASAS_MAX_SZ_CHAIN_FRAME		1024
283234429Sambrisko
284234429Sambrisko#define MPI2_FUNCTION_PASSTHRU_IO_REQUEST       0xF0
285234429Sambrisko#define MPI2_FUNCTION_LD_IO_REQUEST             0xF1
286234429Sambrisko
287234429Sambrisko#define MR_INTERNAL_MFI_FRAMES_SMID             1
288234429Sambrisko#define MR_CTRL_EVENT_WAIT_SMID                 2
289234429Sambrisko#define MR_INTERNAL_DRIVER_RESET_SMID           3
290234429Sambrisko
291234429Sambrisko
292157114Sscottl/* MFI Status codes */
293157114Sscottltypedef enum {
294157114Sscottl	MFI_STAT_OK =			0x00,
295157114Sscottl	MFI_STAT_INVALID_CMD,
296157114Sscottl	MFI_STAT_INVALID_DCMD,
297157114Sscottl	MFI_STAT_INVALID_PARAMETER,
298157114Sscottl	MFI_STAT_INVALID_SEQUENCE_NUMBER,
299157114Sscottl	MFI_STAT_ABORT_NOT_POSSIBLE,
300157114Sscottl	MFI_STAT_APP_HOST_CODE_NOT_FOUND,
301157114Sscottl	MFI_STAT_APP_IN_USE,
302157114Sscottl	MFI_STAT_APP_NOT_INITIALIZED,
303157114Sscottl	MFI_STAT_ARRAY_INDEX_INVALID,
304157114Sscottl	MFI_STAT_ARRAY_ROW_NOT_EMPTY,
305157114Sscottl	MFI_STAT_CONFIG_RESOURCE_CONFLICT,
306157114Sscottl	MFI_STAT_DEVICE_NOT_FOUND,
307157114Sscottl	MFI_STAT_DRIVE_TOO_SMALL,
308157114Sscottl	MFI_STAT_FLASH_ALLOC_FAIL,
309157114Sscottl	MFI_STAT_FLASH_BUSY,
310157114Sscottl	MFI_STAT_FLASH_ERROR =		0x10,
311157114Sscottl	MFI_STAT_FLASH_IMAGE_BAD,
312157114Sscottl	MFI_STAT_FLASH_IMAGE_INCOMPLETE,
313157114Sscottl	MFI_STAT_FLASH_NOT_OPEN,
314157114Sscottl	MFI_STAT_FLASH_NOT_STARTED,
315157114Sscottl	MFI_STAT_FLUSH_FAILED,
316157114Sscottl	MFI_STAT_HOST_CODE_NOT_FOUNT,
317157114Sscottl	MFI_STAT_LD_CC_IN_PROGRESS,
318157114Sscottl	MFI_STAT_LD_INIT_IN_PROGRESS,
319157114Sscottl	MFI_STAT_LD_LBA_OUT_OF_RANGE,
320157114Sscottl	MFI_STAT_LD_MAX_CONFIGURED,
321157114Sscottl	MFI_STAT_LD_NOT_OPTIMAL,
322157114Sscottl	MFI_STAT_LD_RBLD_IN_PROGRESS,
323157114Sscottl	MFI_STAT_LD_RECON_IN_PROGRESS,
324157114Sscottl	MFI_STAT_LD_WRONG_RAID_LEVEL,
325157114Sscottl	MFI_STAT_MAX_SPARES_EXCEEDED,
326157114Sscottl	MFI_STAT_MEMORY_NOT_AVAILABLE =	0x20,
327157114Sscottl	MFI_STAT_MFC_HW_ERROR,
328157114Sscottl	MFI_STAT_NO_HW_PRESENT,
329157114Sscottl	MFI_STAT_NOT_FOUND,
330157114Sscottl	MFI_STAT_NOT_IN_ENCL,
331157114Sscottl	MFI_STAT_PD_CLEAR_IN_PROGRESS,
332157114Sscottl	MFI_STAT_PD_TYPE_WRONG,
333157114Sscottl	MFI_STAT_PR_DISABLED,
334157114Sscottl	MFI_STAT_ROW_INDEX_INVALID,
335157114Sscottl	MFI_STAT_SAS_CONFIG_INVALID_ACTION,
336157114Sscottl	MFI_STAT_SAS_CONFIG_INVALID_DATA,
337157114Sscottl	MFI_STAT_SAS_CONFIG_INVALID_PAGE,
338157114Sscottl	MFI_STAT_SAS_CONFIG_INVALID_TYPE,
339157114Sscottl	MFI_STAT_SCSI_DONE_WITH_ERROR,
340157114Sscottl	MFI_STAT_SCSI_IO_FAILED,
341157114Sscottl	MFI_STAT_SCSI_RESERVATION_CONFLICT,
342157114Sscottl	MFI_STAT_SHUTDOWN_FAILED =	0x30,
343157114Sscottl	MFI_STAT_TIME_NOT_SET,
344157114Sscottl	MFI_STAT_WRONG_STATE,
345157114Sscottl	MFI_STAT_LD_OFFLINE,
346157114Sscottl	MFI_STAT_PEER_NOTIFICATION_REJECTED,
347157114Sscottl	MFI_STAT_PEER_NOTIFICATION_FAILED,
348157114Sscottl	MFI_STAT_RESERVATION_IN_PROGRESS,
349157114Sscottl	MFI_STAT_I2C_ERRORS_DETECTED,
350157114Sscottl	MFI_STAT_PCI_ERRORS_DETECTED,
351196200Sscottl	MFI_STAT_DIAG_FAILED,
352196200Sscottl	MFI_STAT_BOOT_MSG_PENDING,
353196200Sscottl	MFI_STAT_FOREIGN_CONFIG_INCOMPLETE,
354157114Sscottl	MFI_STAT_INVALID_STATUS =	0xFF
355157114Sscottl} mfi_status_t;
356157114Sscottl
357157114Sscottltypedef enum {
358157114Sscottl	MFI_EVT_CLASS_DEBUG =		-2,
359157114Sscottl	MFI_EVT_CLASS_PROGRESS =	-1,
360157114Sscottl	MFI_EVT_CLASS_INFO =		0,
361157114Sscottl	MFI_EVT_CLASS_WARNING =		1,
362157114Sscottl	MFI_EVT_CLASS_CRITICAL =	2,
363157114Sscottl	MFI_EVT_CLASS_FATAL =		3,
364157114Sscottl	MFI_EVT_CLASS_DEAD =		4
365157114Sscottl} mfi_evt_class_t;
366157114Sscottl
367157114Sscottltypedef enum {
368157114Sscottl	MFI_EVT_LOCALE_LD =		0x0001,
369157114Sscottl	MFI_EVT_LOCALE_PD =		0x0002,
370157114Sscottl	MFI_EVT_LOCALE_ENCL =		0x0004,
371157114Sscottl	MFI_EVT_LOCALE_BBU =		0x0008,
372157114Sscottl	MFI_EVT_LOCALE_SAS =		0x0010,
373157114Sscottl	MFI_EVT_LOCALE_CTRL =		0x0020,
374157114Sscottl	MFI_EVT_LOCALE_CONFIG =		0x0040,
375157114Sscottl	MFI_EVT_LOCALE_CLUSTER =	0x0080,
376157114Sscottl	MFI_EVT_LOCALE_ALL =		0xffff
377157114Sscottl} mfi_evt_locale_t;
378157114Sscottl
379157114Sscottltypedef enum {
380158737Sambrisko	MR_EVT_ARGS_NONE =		0x00,
381158737Sambrisko	MR_EVT_ARGS_CDB_SENSE,
382158737Sambrisko	MR_EVT_ARGS_LD,
383158737Sambrisko	MR_EVT_ARGS_LD_COUNT,
384158737Sambrisko	MR_EVT_ARGS_LD_LBA,
385158737Sambrisko	MR_EVT_ARGS_LD_OWNER,
386158737Sambrisko	MR_EVT_ARGS_LD_LBA_PD_LBA,
387158737Sambrisko	MR_EVT_ARGS_LD_PROG,
388158737Sambrisko	MR_EVT_ARGS_LD_STATE,
389158737Sambrisko	MR_EVT_ARGS_LD_STRIP,
390158737Sambrisko	MR_EVT_ARGS_PD,
391158737Sambrisko	MR_EVT_ARGS_PD_ERR,
392158737Sambrisko	MR_EVT_ARGS_PD_LBA,
393158737Sambrisko	MR_EVT_ARGS_PD_LBA_LD,
394158737Sambrisko	MR_EVT_ARGS_PD_PROG,
395158737Sambrisko	MR_EVT_ARGS_PD_STATE,
396158737Sambrisko	MR_EVT_ARGS_PCI,
397158737Sambrisko	MR_EVT_ARGS_RATE,
398158737Sambrisko	MR_EVT_ARGS_STR,
399158737Sambrisko	MR_EVT_ARGS_TIME,
400158737Sambrisko	MR_EVT_ARGS_ECC
401157114Sscottl} mfi_evt_args;
402157114Sscottl
403234429Sambrisko#define MR_EVT_CTRL_HOST_BUS_SCAN_REQUESTED	0x0152
404234429Sambrisko#define MR_EVT_PD_REMOVED			0x0070
405234429Sambrisko#define MR_EVT_PD_INSERTED			0x005b
406234429Sambrisko
407163398Sscottltypedef enum {
408163398Sscottl	MR_LD_CACHE_WRITE_BACK =	0x01,
409163398Sscottl	MR_LD_CACHE_WRITE_ADAPTIVE =	0x02,
410163398Sscottl	MR_LD_CACHE_READ_AHEAD =	0x04,
411163398Sscottl	MR_LD_CACHE_READ_ADAPTIVE =	0x08,
412163398Sscottl	MR_LD_CACHE_WRITE_CACHE_BAD_BBU=0x10,
413163398Sscottl	MR_LD_CACHE_ALLOW_WRITE_CACHE =	0x20,
414163398Sscottl	MR_LD_CACHE_ALLOW_READ_CACHE =	0x40
415163398Sscottl} mfi_ld_cache;
416196200Sscottl#define	MR_LD_CACHE_MASK	0x7f
417163398Sscottl
418196200Sscottl#define	MR_LD_CACHE_POLICY_READ_AHEAD_NONE		0
419196200Sscottl#define	MR_LD_CACHE_POLICY_READ_AHEAD_ALWAYS		MR_LD_CACHE_READ_AHEAD
420196200Sscottl#define	MR_LD_CACHE_POLICY_READ_AHEAD_ADAPTIVE		\
421196200Sscottl	(MR_LD_CACHE_READ_AHEAD | MR_LD_CACHE_READ_ADAPTIVE)
422196200Sscottl#define	MR_LD_CACHE_POLICY_WRITE_THROUGH		0
423196200Sscottl#define	MR_LD_CACHE_POLICY_WRITE_BACK			MR_LD_CACHE_WRITE_BACK
424196200Sscottl#define	MR_LD_CACHE_POLICY_IO_CACHED			\
425196200Sscottl	(MR_LD_CACHE_ALLOW_WRITE_CACHE | MR_LD_CACHE_ALLOW_READ_CACHE)
426196200Sscottl#define	MR_LD_CACHE_POLICY_IO_DIRECT			0
427196200Sscottl
428163398Sscottltypedef enum {
429163398Sscottl	MR_PD_CACHE_UNCHANGED  =	0,
430163398Sscottl	MR_PD_CACHE_ENABLE =		1,
431163398Sscottl	MR_PD_CACHE_DISABLE =		2
432163398Sscottl} mfi_pd_cache;
433163398Sscottl
434234429Sambriskotypedef enum {
435234429Sambrisko	MR_PD_QUERY_TYPE_ALL =		0,
436234429Sambrisko	MR_PD_QUERY_TYPE_STATE =	1,
437234429Sambrisko	MR_PD_QUERY_TYPE_POWER_STATE =	2,
438234429Sambrisko	MR_PD_QUERY_TYPE_MEDIA_TYPE =	3,
439234429Sambrisko	MR_PD_QUERY_TYPE_SPEED =	4,
440234429Sambrisko	MR_PD_QUERY_TYPE_EXPOSED_TO_HOST = 5 /*query for system drives */
441234429Sambrisko} mfi_pd_query_type;
442234429Sambrisko
443157114Sscottl/*
444157114Sscottl * Other propertities and definitions
445157114Sscottl */
446157114Sscottl#define MFI_MAX_PD_CHANNELS	2
447157114Sscottl#define MFI_MAX_LD_CHANNELS	2
448157114Sscottl#define MFI_MAX_CHANNELS	(MFI_MAX_PD_CHANNELS + MFI_MAX_LD_CHANNELS)
449157114Sscottl#define MFI_MAX_CHANNEL_DEVS	128
450157114Sscottl#define MFI_DEFAULT_ID		-1
451157114Sscottl#define MFI_MAX_LUN		8
452157114Sscottl#define MFI_MAX_LD		64
453196200Sscottl#define	MFI_MAX_PD		256
454157114Sscottl
455157114Sscottl#define MFI_FRAME_SIZE		64
456157114Sscottl#define MFI_MBOX_SIZE		12
457157114Sscottl
458165225Sambrisko/* Firmware flashing can take 40s */
459165225Sambrisko#define MFI_POLL_TIMEOUT_SECS	50
460157114Sscottl
461157114Sscottl/* Allow for speedier math calculations */
462157114Sscottl#define MFI_SECTOR_LEN		512
463157114Sscottl
464157114Sscottl/* Scatter Gather elements */
465157114Sscottlstruct mfi_sg32 {
466157114Sscottl	uint32_t	addr;
467157114Sscottl	uint32_t	len;
468157114Sscottl} __packed;
469157114Sscottl
470157114Sscottlstruct mfi_sg64 {
471157114Sscottl	uint64_t	addr;
472157114Sscottl	uint32_t	len;
473157114Sscottl} __packed;
474157114Sscottl
475234429Sambriskostruct mfi_sg_skinny {
476234429Sambrisko	uint64_t	addr;
477234429Sambrisko	uint32_t	len;
478234429Sambrisko	uint32_t	flag;
479234429Sambrisko} __packed;
480234429Sambrisko
481157114Sscottlunion mfi_sgl {
482234429Sambrisko	struct mfi_sg32		sg32[1];
483234429Sambrisko	struct mfi_sg64		sg64[1];
484234429Sambrisko	struct mfi_sg_skinny	sg_skinny[1];
485157114Sscottl} __packed;
486157114Sscottl
487157114Sscottl/* Message frames.  All messages have a common header */
488157114Sscottlstruct mfi_frame_header {
489157114Sscottl	uint8_t		cmd;
490157114Sscottl	uint8_t		sense_len;
491157114Sscottl	uint8_t		cmd_status;
492157114Sscottl	uint8_t		scsi_status;
493157114Sscottl	uint8_t		target_id;
494157114Sscottl	uint8_t		lun_id;
495157114Sscottl	uint8_t		cdb_len;
496157114Sscottl	uint8_t		sg_count;
497157114Sscottl	uint32_t	context;
498234429Sambrisko	/*
499234429Sambrisko	 * pad0 is MSI Specific. Not used by Driver. Zero the value before
500234429Sambrisko	 * sending the command to f/w.
501234429Sambrisko	 */
502157114Sscottl	uint32_t	pad0;
503157114Sscottl	uint16_t	flags;
504175897Sambrisko#define MFI_FRAME_DATAOUT	0x08
505175897Sambrisko#define MFI_FRAME_DATAIN	0x10
506157114Sscottl	uint16_t	timeout;
507157114Sscottl	uint32_t	data_len;
508157114Sscottl} __packed;
509157114Sscottl
510157114Sscottlstruct mfi_init_frame {
511157114Sscottl	struct mfi_frame_header	header;
512157114Sscottl	uint32_t	qinfo_new_addr_lo;
513157114Sscottl	uint32_t	qinfo_new_addr_hi;
514157114Sscottl	uint32_t	qinfo_old_addr_lo;
515157114Sscottl	uint32_t	qinfo_old_addr_hi;
516234429Sambrisko	// Start LSIP200113393
517234429Sambrisko	uint32_t	driver_ver_lo;      /*28h */
518234429Sambrisko	uint32_t	driver_ver_hi;      /*2Ch */
519234429Sambrisko
520234429Sambrisko	uint32_t	reserved[4];
521234429Sambrisko	// End LSIP200113393
522157114Sscottl} __packed;
523157114Sscottl
524234429Sambrisko/*
525234429Sambrisko * Define MFI Address Context union.
526234429Sambrisko */
527234429Sambrisko#ifdef MFI_ADDRESS_IS_uint64_t
528234429Sambrisko    typedef uint64_t     MFI_ADDRESS;
529234429Sambrisko#else
530234429Sambrisko    typedef union _MFI_ADDRESS {
531234429Sambrisko        struct {
532234429Sambrisko            uint32_t     addressLow;
533234429Sambrisko            uint32_t     addressHigh;
534234429Sambrisko        } u;
535234429Sambrisko        uint64_t     address;
536234429Sambrisko    } MFI_ADDRESS, *PMFI_ADDRESS;
537234429Sambrisko#endif
538234429Sambrisko
539157114Sscottl#define MFI_IO_FRAME_SIZE 40
540157114Sscottlstruct mfi_io_frame {
541157114Sscottl	struct mfi_frame_header	header;
542157114Sscottl	uint32_t	sense_addr_lo;
543157114Sscottl	uint32_t	sense_addr_hi;
544157114Sscottl	uint32_t	lba_lo;
545157114Sscottl	uint32_t	lba_hi;
546157114Sscottl	union mfi_sgl	sgl;
547157114Sscottl} __packed;
548157114Sscottl
549157114Sscottl#define MFI_PASS_FRAME_SIZE 48
550157114Sscottlstruct mfi_pass_frame {
551157114Sscottl	struct mfi_frame_header header;
552157114Sscottl	uint32_t	sense_addr_lo;
553157114Sscottl	uint32_t	sense_addr_hi;
554157114Sscottl	uint8_t		cdb[16];
555157114Sscottl	union mfi_sgl	sgl;
556157114Sscottl} __packed;
557157114Sscottl
558157114Sscottl#define MFI_DCMD_FRAME_SIZE 40
559157114Sscottlstruct mfi_dcmd_frame {
560157114Sscottl	struct mfi_frame_header header;
561157114Sscottl	uint32_t	opcode;
562157114Sscottl	uint8_t		mbox[MFI_MBOX_SIZE];
563157114Sscottl	union mfi_sgl	sgl;
564157114Sscottl} __packed;
565157114Sscottl
566157114Sscottlstruct mfi_abort_frame {
567157114Sscottl	struct mfi_frame_header header;
568157114Sscottl	uint32_t	abort_context;
569234429Sambrisko	/* pad is changed to reserved.*/
570234429Sambrisko	uint32_t	reserved0;
571157114Sscottl	uint32_t	abort_mfi_addr_lo;
572157114Sscottl	uint32_t	abort_mfi_addr_hi;
573234429Sambrisko	uint32_t	reserved1[6];
574157114Sscottl} __packed;
575157114Sscottl
576157114Sscottlstruct mfi_smp_frame {
577157114Sscottl	struct mfi_frame_header header;
578157114Sscottl	uint64_t	sas_addr;
579157114Sscottl	union {
580157114Sscottl		struct mfi_sg32 sg32[2];
581157114Sscottl		struct mfi_sg64 sg64[2];
582157114Sscottl	} sgl;
583157114Sscottl} __packed;
584157114Sscottl
585157114Sscottlstruct mfi_stp_frame {
586157114Sscottl	struct mfi_frame_header header;
587157114Sscottl	uint16_t	fis[10];
588157114Sscottl	uint32_t	stp_flags;
589157114Sscottl	union {
590157114Sscottl		struct mfi_sg32 sg32[2];
591157114Sscottl		struct mfi_sg64 sg64[2];
592157114Sscottl	} sgl;
593157114Sscottl} __packed;
594157114Sscottl
595157114Sscottlunion mfi_frame {
596157114Sscottl	struct mfi_frame_header header;
597157114Sscottl	struct mfi_init_frame	init;
598234429Sambrisko	/* ThunderBolt Initialization */
599157114Sscottl	struct mfi_io_frame	io;
600157114Sscottl	struct mfi_pass_frame	pass;
601157114Sscottl	struct mfi_dcmd_frame	dcmd;
602157114Sscottl	struct mfi_abort_frame	abort;
603157114Sscottl	struct mfi_smp_frame	smp;
604157114Sscottl	struct mfi_stp_frame	stp;
605157114Sscottl	uint8_t			bytes[MFI_FRAME_SIZE];
606157114Sscottl};
607157114Sscottl
608157114Sscottl#define MFI_SENSE_LEN 128
609157114Sscottlstruct mfi_sense {
610157114Sscottl	uint8_t		data[MFI_SENSE_LEN];
611157114Sscottl};
612157114Sscottl
613157114Sscottl/* The queue init structure that is passed with the init message */
614157114Sscottlstruct mfi_init_qinfo {
615157114Sscottl	uint32_t	flags;
616157114Sscottl	uint32_t	rq_entries;
617157114Sscottl	uint32_t	rq_addr_lo;
618157114Sscottl	uint32_t	rq_addr_hi;
619157114Sscottl	uint32_t	pi_addr_lo;
620157114Sscottl	uint32_t	pi_addr_hi;
621157114Sscottl	uint32_t	ci_addr_lo;
622157114Sscottl	uint32_t	ci_addr_hi;
623157114Sscottl} __packed;
624157114Sscottl
625157114Sscottl/* SAS (?) controller properties, part of mfi_ctrl_info */
626157114Sscottlstruct mfi_ctrl_props {
627157114Sscottl	uint16_t	seq_num;
628157114Sscottl	uint16_t	pred_fail_poll_interval;
629157114Sscottl	uint16_t	intr_throttle_cnt;
630157114Sscottl	uint16_t	intr_throttle_timeout;
631157114Sscottl	uint8_t		rebuild_rate;
632157114Sscottl	uint8_t		patrol_read_rate;
633157114Sscottl	uint8_t		bgi_rate;
634157114Sscottl	uint8_t		cc_rate;
635157114Sscottl	uint8_t		recon_rate;
636157114Sscottl	uint8_t		cache_flush_interval;
637157114Sscottl	uint8_t		spinup_drv_cnt;
638157114Sscottl	uint8_t		spinup_delay;
639157114Sscottl	uint8_t		cluster_enable;
640157114Sscottl	uint8_t		coercion_mode;
641157114Sscottl	uint8_t		alarm_enable;
642157114Sscottl	uint8_t		disable_auto_rebuild;
643157114Sscottl	uint8_t		disable_battery_warn;
644157114Sscottl	uint8_t		ecc_bucket_size;
645157114Sscottl	uint16_t	ecc_bucket_leak_rate;
646157114Sscottl	uint8_t		restore_hotspare_on_insertion;
647157114Sscottl	uint8_t		expose_encl_devices;
648234429Sambrisko	uint8_t		maintainPdFailHistory;
649234429Sambrisko	uint8_t		disallowHostRequestReordering;
650234429Sambrisko	/* set TRUE to abort CC on detecting an inconsistency */
651234429Sambrisko	uint8_t		abortCCOnError;
652234429Sambrisko	/* load balance mode (MR_LOAD_BALANCE_MODE) */
653234429Sambrisko	uint8_t		loadBalanceMode;
654234429Sambrisko	/*
655234429Sambrisko	 * 0 - use auto detect logic of backplanes like SGPIO, i2c SEP using
656234429Sambrisko	 *     h/w mechansim like GPIO pins
657234429Sambrisko	 * 1 - disable auto detect SGPIO,
658234429Sambrisko	 * 2 - disable i2c SEP auto detect
659234429Sambrisko	 * 3 - disable both auto detect
660234429Sambrisko	 */
661234429Sambrisko	uint8_t		disableAutoDetectBackplane;
662234429Sambrisko	/*
663234429Sambrisko	 * % of source LD to be reserved for a VDs snapshot in snapshot
664234429Sambrisko	 * repository, for metadata and user data: 1=5%, 2=10%, 3=15% and so on
665234429Sambrisko	 */
666234429Sambrisko	uint8_t		snapVDSpace;
667234429Sambrisko
668234429Sambrisko	/*
669234429Sambrisko	 * Add properties that can be controlled by a bit in the following
670234429Sambrisko	 * structure.
671234429Sambrisko	 */
672234429Sambrisko	struct {
673234429Sambrisko		/* set TRUE to disable copyBack (0=copback enabled) */
674234429Sambrisko		uint32_t	copyBackDisabled		:1;
675234429Sambrisko		uint32_t	SMARTerEnabled			:1;
676234429Sambrisko		uint32_t	prCorrectUnconfiguredAreas	:1;
677234429Sambrisko		uint32_t	useFdeOnly			:1;
678234429Sambrisko		uint32_t	disableNCQ			:1;
679234429Sambrisko		uint32_t	SSDSMARTerEnabled		:1;
680234429Sambrisko		uint32_t	SSDPatrolReadEnabled		:1;
681234429Sambrisko		uint32_t	enableSpinDownUnconfigured	:1;
682234429Sambrisko		uint32_t	autoEnhancedImport		:1;
683234429Sambrisko		uint32_t	enableSecretKeyControl		:1;
684234429Sambrisko		uint32_t	disableOnlineCtrlReset		:1;
685234429Sambrisko		uint32_t	allowBootWithPinnedCache	:1;
686234429Sambrisko		uint32_t	disableSpinDownHS		:1;
687234429Sambrisko		uint32_t	enableJBOD			:1;
688234429Sambrisko		uint32_t	reserved			:18;
689234429Sambrisko	} OnOffProperties;
690234429Sambrisko	/*
691234429Sambrisko	 * % of source LD to be reserved for auto snapshot in snapshot
692234429Sambrisko	 * repository, for metadata and user data: 1=5%, 2=10%, 3=15% and so on.
693234429Sambrisko	 */
694234429Sambrisko	uint8_t		autoSnapVDSpace;
695234429Sambrisko	/*
696234429Sambrisko	 * Snapshot writeable VIEWs capacity as a % of source LD capacity:
697234429Sambrisko	 * 0=READ only, 1=5%, 2=10%, 3=15% and so on.
698234429Sambrisko	 */
699234429Sambrisko	uint8_t		viewSpace;
700234429Sambrisko	/* # of idle minutes before device is spun down (0=use FW defaults) */
701234429Sambrisko	uint16_t	spinDownTime;
702234429Sambrisko	uint8_t		reserved[24];
703157114Sscottl} __packed;
704157114Sscottl
705157114Sscottl/* PCI information about the card. */
706157114Sscottlstruct mfi_info_pci {
707157114Sscottl	uint16_t	vendor;
708157114Sscottl	uint16_t	device;
709157114Sscottl	uint16_t	subvendor;
710157114Sscottl	uint16_t	subdevice;
711157114Sscottl	uint8_t		reserved[24];
712157114Sscottl} __packed;
713157114Sscottl
714157114Sscottl/* Host (front end) interface information */
715157114Sscottlstruct mfi_info_host {
716157114Sscottl	uint8_t		type;
717157114Sscottl#define MFI_INFO_HOST_PCIX	0x01
718157114Sscottl#define MFI_INFO_HOST_PCIE	0x02
719157114Sscottl#define MFI_INFO_HOST_ISCSI	0x04
720157114Sscottl#define MFI_INFO_HOST_SAS3G	0x08
721157114Sscottl	uint8_t		reserved[6];
722157114Sscottl	uint8_t		port_count;
723157114Sscottl	uint64_t	port_addr[8];
724157114Sscottl} __packed;
725157114Sscottl
726157114Sscottl/* Device (back end) interface information */
727157114Sscottlstruct mfi_info_device {
728157114Sscottl	uint8_t		type;
729157114Sscottl#define MFI_INFO_DEV_SPI	0x01
730157114Sscottl#define MFI_INFO_DEV_SAS3G	0x02
731157114Sscottl#define MFI_INFO_DEV_SATA1	0x04
732157114Sscottl#define MFI_INFO_DEV_SATA3G	0x08
733157114Sscottl	uint8_t		reserved[6];
734157114Sscottl	uint8_t		port_count;
735157114Sscottl	uint64_t	port_addr[8];
736157114Sscottl} __packed;
737157114Sscottl
738157114Sscottl/* Firmware component information */
739157114Sscottlstruct mfi_info_component {
740157114Sscottl	char		 name[8];
741157114Sscottl	char		 version[32];
742157114Sscottl	char		 build_date[16];
743157114Sscottl	char		 build_time[16];
744157114Sscottl} __packed;
745157114Sscottl
746163398Sscottl/* Controller default settings */
747163398Sscottlstruct mfi_defaults {
748163398Sscottl	uint64_t	sas_addr;
749163398Sscottl	uint8_t		phy_polarity;
750163398Sscottl	uint8_t		background_rate;
751163398Sscottl	uint8_t		stripe_size;
752163398Sscottl	uint8_t		flush_time;
753163398Sscottl	uint8_t		write_back;
754163398Sscottl	uint8_t		read_ahead;
755163398Sscottl	uint8_t		cache_when_bbu_bad;
756163398Sscottl	uint8_t		cached_io;
757163398Sscottl	uint8_t		smart_mode;
758163398Sscottl	uint8_t		alarm_disable;
759163398Sscottl	uint8_t		coercion;
760163398Sscottl	uint8_t		zrc_config;
761163398Sscottl	uint8_t		dirty_led_shows_drive_activity;
762163398Sscottl	uint8_t		bios_continue_on_error;
763163398Sscottl	uint8_t		spindown_mode;
764163398Sscottl	uint8_t		allowed_device_types;
765163398Sscottl	uint8_t		allow_mix_in_enclosure;
766163398Sscottl	uint8_t		allow_mix_in_ld;
767163398Sscottl	uint8_t		allow_sata_in_cluster;
768163398Sscottl	uint8_t		max_chained_enclosures;
769163398Sscottl	uint8_t		disable_ctrl_r;
770163398Sscottl	uint8_t		enabel_web_bios;
771163398Sscottl	uint8_t		phy_polarity_split;
772163398Sscottl	uint8_t		direct_pd_mapping;
773163398Sscottl	uint8_t		bios_enumerate_lds;
774163398Sscottl	uint8_t		restored_hot_spare_on_insertion;
775163398Sscottl	uint8_t		expose_enclosure_devices;
776163398Sscottl	uint8_t		maintain_pd_fail_history;
777163398Sscottl	uint8_t		resv[28];
778163398Sscottl} __packed;
779157114Sscottl
780163398Sscottl/* Controller default settings */
781163398Sscottlstruct mfi_bios_data {
782163398Sscottl	uint16_t	boot_target_id;
783163398Sscottl	uint8_t		do_not_int_13;
784163398Sscottl	uint8_t		continue_on_error;
785163398Sscottl	uint8_t		verbose;
786163398Sscottl	uint8_t		geometry;
787163398Sscottl	uint8_t		expose_all_drives;
788163398Sscottl	uint8_t		reserved[56];
789163398Sscottl	uint8_t		check_sum;
790163398Sscottl} __packed;
791163398Sscottl
792157114Sscottl/* SAS (?) controller info, returned from MFI_DCMD_CTRL_GETINFO. */
793157114Sscottlstruct mfi_ctrl_info {
794157114Sscottl	struct mfi_info_pci	pci;
795157114Sscottl	struct mfi_info_host	host;
796157114Sscottl	struct mfi_info_device	device;
797157114Sscottl
798157114Sscottl	/* Firmware components that are present and active. */
799157114Sscottl	uint32_t		image_check_word;
800157114Sscottl	uint32_t		image_component_count;
801157114Sscottl	struct mfi_info_component image_component[8];
802157114Sscottl
803157114Sscottl	/* Firmware components that have been flashed but are inactive */
804157114Sscottl	uint32_t		pending_image_component_count;
805157114Sscottl	struct mfi_info_component pending_image_component[8];
806157114Sscottl
807157114Sscottl	uint8_t			max_arms;
808157114Sscottl	uint8_t			max_spans;
809157114Sscottl	uint8_t			max_arrays;
810157114Sscottl	uint8_t			max_lds;
811157114Sscottl	char			product_name[80];
812157114Sscottl	char			serial_number[32];
813157114Sscottl	uint32_t		hw_present;
814157114Sscottl#define MFI_INFO_HW_BBU		0x01
815157114Sscottl#define MFI_INFO_HW_ALARM	0x02
816157114Sscottl#define MFI_INFO_HW_NVRAM	0x04
817157114Sscottl#define MFI_INFO_HW_UART	0x08
818157114Sscottl	uint32_t		current_fw_time;
819157114Sscottl	uint16_t		max_cmds;
820157114Sscottl	uint16_t		max_sg_elements;
821157114Sscottl	uint32_t		max_request_size;
822157114Sscottl	uint16_t		lds_present;
823157114Sscottl	uint16_t		lds_degraded;
824157114Sscottl	uint16_t		lds_offline;
825157114Sscottl	uint16_t		pd_present;
826157114Sscottl	uint16_t		pd_disks_present;
827157114Sscottl	uint16_t		pd_disks_pred_failure;
828157114Sscottl	uint16_t		pd_disks_failed;
829157114Sscottl	uint16_t		nvram_size;
830157114Sscottl	uint16_t		memory_size;
831157114Sscottl	uint16_t		flash_size;
832157114Sscottl	uint16_t		ram_correctable_errors;
833157114Sscottl	uint16_t		ram_uncorrectable_errors;
834157114Sscottl	uint8_t			cluster_allowed;
835157114Sscottl	uint8_t			cluster_active;
836157114Sscottl	uint16_t		max_strips_per_io;
837157114Sscottl
838157114Sscottl	uint32_t		raid_levels;
839157114Sscottl#define MFI_INFO_RAID_0		0x01
840157114Sscottl#define MFI_INFO_RAID_1		0x02
841157114Sscottl#define MFI_INFO_RAID_5		0x04
842157114Sscottl#define MFI_INFO_RAID_1E	0x08
843157114Sscottl#define MFI_INFO_RAID_6		0x10
844157114Sscottl
845157114Sscottl	uint32_t		adapter_ops;
846158737Sambrisko#define MFI_INFO_AOPS_RBLD_RATE		0x0001
847157114Sscottl#define MFI_INFO_AOPS_CC_RATE		0x0002
848157114Sscottl#define MFI_INFO_AOPS_BGI_RATE		0x0004
849157114Sscottl#define MFI_INFO_AOPS_RECON_RATE	0x0008
850157114Sscottl#define MFI_INFO_AOPS_PATROL_RATE	0x0010
851157114Sscottl#define MFI_INFO_AOPS_ALARM_CONTROL	0x0020
852157114Sscottl#define MFI_INFO_AOPS_CLUSTER_SUPPORTED	0x0040
853157114Sscottl#define MFI_INFO_AOPS_BBU		0x0080
854157114Sscottl#define MFI_INFO_AOPS_SPANNING_ALLOWED	0x0100
855157114Sscottl#define MFI_INFO_AOPS_DEDICATED_SPARES	0x0200
856157114Sscottl#define MFI_INFO_AOPS_REVERTIBLE_SPARES	0x0400
857157114Sscottl#define MFI_INFO_AOPS_FOREIGN_IMPORT	0x0800
858157114Sscottl#define MFI_INFO_AOPS_SELF_DIAGNOSTIC	0x1000
859157114Sscottl#define MFI_INFO_AOPS_MIXED_ARRAY	0x2000
860157114Sscottl#define MFI_INFO_AOPS_GLOBAL_SPARES	0x4000
861157114Sscottl
862157114Sscottl	uint32_t		ld_ops;
863157114Sscottl#define MFI_INFO_LDOPS_READ_POLICY	0x01
864157114Sscottl#define MFI_INFO_LDOPS_WRITE_POLICY	0x02
865157114Sscottl#define MFI_INFO_LDOPS_IO_POLICY	0x04
866157114Sscottl#define MFI_INFO_LDOPS_ACCESS_POLICY	0x08
867157114Sscottl#define MFI_INFO_LDOPS_DISK_CACHE_POLICY 0x10
868157114Sscottl
869157114Sscottl	struct {
870157114Sscottl		uint8_t		min;
871157114Sscottl		uint8_t		max;
872157114Sscottl		uint8_t		reserved[2];
873157114Sscottl	} __packed stripe_sz_ops;
874157114Sscottl
875157114Sscottl	uint32_t		pd_ops;
876157114Sscottl#define MFI_INFO_PDOPS_FORCE_ONLINE	0x01
877157114Sscottl#define MFI_INFO_PDOPS_FORCE_OFFLINE	0x02
878157114Sscottl#define MFI_INFO_PDOPS_FORCE_REBUILD	0x04
879157114Sscottl
880157114Sscottl	uint32_t		pd_mix_support;
881157114Sscottl#define MFI_INFO_PDMIX_SAS		0x01
882157114Sscottl#define MFI_INFO_PDMIX_SATA		0x02
883157114Sscottl#define MFI_INFO_PDMIX_ENCL		0x04
884157114Sscottl#define MFI_INFO_PDMIX_LD		0x08
885157114Sscottl#define MFI_INFO_PDMIX_SATA_CLUSTER	0x10
886157114Sscottl
887157114Sscottl	uint8_t			ecc_bucket_count;
888157114Sscottl	uint8_t			reserved2[11];
889157114Sscottl	struct mfi_ctrl_props	properties;
890157114Sscottl	char			package_version[0x60];
891157114Sscottl	uint8_t			pad[0x800 - 0x6a0];
892157114Sscottl} __packed;
893157114Sscottl
894158737Sambrisko/* keep track of an event. */
895158737Sambriskounion mfi_evt {
896158737Sambrisko	struct {
897158737Sambrisko		uint16_t	locale;
898158737Sambrisko		uint8_t		reserved;
899222589Semaste		int8_t		evt_class;
900158737Sambrisko	} members;
901158737Sambrisko	uint32_t		word;
902158737Sambrisko} __packed;
903158737Sambrisko
904158737Sambrisko/* event log state. */
905158737Sambriskostruct mfi_evt_log_state {
906158737Sambrisko	uint32_t		newest_seq_num;
907158737Sambrisko	uint32_t		oldest_seq_num;
908158737Sambrisko	uint32_t		clear_seq_num;
909158737Sambrisko	uint32_t		shutdown_seq_num;
910158737Sambrisko	uint32_t		boot_seq_num;
911158737Sambrisko} __packed;
912158737Sambrisko
913158737Sambriskostruct mfi_progress {
914158737Sambrisko	uint16_t		progress;
915158737Sambrisko	uint16_t		elapsed_seconds;
916158737Sambrisko} __packed;
917158737Sambrisko
918158737Sambriskostruct mfi_evt_ld {
919158737Sambrisko	uint16_t		target_id;
920158737Sambrisko	uint8_t			ld_index;
921158737Sambrisko	uint8_t			reserved;
922158737Sambrisko} __packed;
923158737Sambrisko
924158737Sambriskostruct mfi_evt_pd {
925158737Sambrisko	uint16_t		device_id;
926158737Sambrisko	uint8_t			enclosure_index;
927158737Sambrisko	uint8_t			slot_number;
928158737Sambrisko} __packed;
929158737Sambrisko
930158737Sambrisko/* SAS (?) event detail, returned from MFI_DCMD_CTRL_EVENT_WAIT. */
931158737Sambriskostruct mfi_evt_detail {
932158737Sambrisko	uint32_t		seq;
933158737Sambrisko	uint32_t		time;
934158737Sambrisko	uint32_t		code;
935222589Semaste	union mfi_evt		evt_class;
936158737Sambrisko	uint8_t			arg_type;
937158737Sambrisko	uint8_t			reserved1[15];
938158737Sambrisko
939158737Sambrisko	union {
940158737Sambrisko		struct {
941158737Sambrisko			struct mfi_evt_pd	pd;
942158737Sambrisko			uint8_t			cdb_len;
943158737Sambrisko			uint8_t			sense_len;
944158737Sambrisko			uint8_t			reserved[2];
945158737Sambrisko			uint8_t			cdb[16];
946158737Sambrisko			uint8_t			sense[64];
947158737Sambrisko		} cdb_sense;
948158737Sambrisko
949158737Sambrisko		struct mfi_evt_ld		ld;
950158737Sambrisko
951158737Sambrisko		struct {
952158737Sambrisko			struct mfi_evt_ld	ld;
953158737Sambrisko			uint64_t		count;
954158737Sambrisko		} ld_count;
955158737Sambrisko
956158737Sambrisko		struct {
957158737Sambrisko			uint64_t		lba;
958158737Sambrisko			struct mfi_evt_ld	ld;
959158737Sambrisko		} ld_lba;
960158737Sambrisko
961158737Sambrisko		struct {
962158737Sambrisko			struct mfi_evt_ld	ld;
963158737Sambrisko			uint32_t		pre_owner;
964158737Sambrisko			uint32_t		new_owner;
965158737Sambrisko		} ld_owner;
966158737Sambrisko
967158737Sambrisko		struct {
968158737Sambrisko			uint64_t		ld_lba;
969158737Sambrisko			uint64_t		pd_lba;
970158737Sambrisko			struct mfi_evt_ld	ld;
971158737Sambrisko			struct mfi_evt_pd	pd;
972158737Sambrisko		} ld_lba_pd_lba;
973158737Sambrisko
974158737Sambrisko		struct {
975158737Sambrisko			struct mfi_evt_ld	ld;
976158737Sambrisko			struct mfi_progress	prog;
977158737Sambrisko		} ld_prog;
978158737Sambrisko
979158737Sambrisko		struct {
980158737Sambrisko			struct mfi_evt_ld	ld;
981158737Sambrisko			uint32_t		prev_state;
982158737Sambrisko			uint32_t		new_state;
983158737Sambrisko		} ld_state;
984158737Sambrisko
985158737Sambrisko		struct {
986158737Sambrisko			uint64_t		strip;
987158737Sambrisko			struct mfi_evt_ld	ld;
988158737Sambrisko		} ld_strip;
989158737Sambrisko
990158737Sambrisko		struct mfi_evt_pd		pd;
991158737Sambrisko
992158737Sambrisko		struct {
993158737Sambrisko			struct mfi_evt_pd	pd;
994158737Sambrisko			uint32_t		err;
995158737Sambrisko		} pd_err;
996158737Sambrisko
997158737Sambrisko		struct {
998158737Sambrisko			uint64_t		lba;
999158737Sambrisko			struct mfi_evt_pd	pd;
1000158737Sambrisko		} pd_lba;
1001158737Sambrisko
1002158737Sambrisko		struct {
1003158737Sambrisko			uint64_t		lba;
1004158737Sambrisko			struct mfi_evt_pd	pd;
1005158737Sambrisko			struct mfi_evt_ld	ld;
1006158737Sambrisko		} pd_lba_ld;
1007158737Sambrisko
1008158737Sambrisko		struct {
1009158737Sambrisko			struct mfi_evt_pd	pd;
1010158737Sambrisko			struct mfi_progress	prog;
1011158737Sambrisko		} pd_prog;
1012158737Sambrisko
1013158737Sambrisko		struct {
1014158737Sambrisko			struct mfi_evt_pd	ld;
1015158737Sambrisko			uint32_t		prev_state;
1016158737Sambrisko			uint32_t		new_state;
1017158737Sambrisko		} pd_state;
1018158737Sambrisko
1019158737Sambrisko		struct {
1020158737Sambrisko			uint16_t		venderId;
1021158737Sambrisko			uint16_t		deviceId;
1022158737Sambrisko			uint16_t		subVenderId;
1023158737Sambrisko			uint16_t		subDeviceId;
1024158737Sambrisko		} pci;
1025158737Sambrisko
1026158737Sambrisko		uint32_t			rate;
1027158737Sambrisko
1028158737Sambrisko		char				str[96];
1029158737Sambrisko
1030158737Sambrisko		struct {
1031158737Sambrisko			uint32_t		rtc;
1032158737Sambrisko			uint16_t		elapsedSeconds;
1033158737Sambrisko		} time;
1034158737Sambrisko
1035158737Sambrisko		struct {
1036158737Sambrisko			uint32_t		ecar;
1037158737Sambrisko			uint32_t		elog;
1038158737Sambrisko			char			str[64];
1039158737Sambrisko		} ecc;
1040158737Sambrisko
1041158737Sambrisko		uint8_t		b[96];
1042158737Sambrisko		uint16_t	s[48];
1043158737Sambrisko		uint32_t	w[24];
1044158737Sambrisko		uint64_t	d[12];
1045158737Sambrisko	} args;
1046158737Sambrisko
1047158737Sambrisko	char description[128];
1048158737Sambrisko} __packed;
1049158737Sambrisko
1050162118Sambriskostruct mfi_evt_list {
1051162118Sambrisko	uint32_t		count;
1052162118Sambrisko	uint32_t		reserved;
1053162118Sambrisko	struct mfi_evt_detail	event[1];
1054158737Sambrisko} __packed;
1055158737Sambrisko
1056163398Sscottlunion mfi_pd_ref {
1057163398Sscottl	struct {
1058163398Sscottl		uint16_t	device_id;
1059163398Sscottl		uint16_t	seq_num;
1060163398Sscottl	} v;
1061163398Sscottl	uint32_t	ref;
1062159811Sps} __packed;
1063159811Sps
1064163398Sscottlunion mfi_pd_ddf_type {
1065163398Sscottl	struct {
1066163398Sscottl		union {
1067163398Sscottl			struct {
1068163398Sscottl				uint16_t	forced_pd_guid	: 1;
1069163398Sscottl				uint16_t	in_vd		: 1;
1070163398Sscottl				uint16_t	is_global_spare	: 1;
1071163398Sscottl				uint16_t	is_spare	: 1;
1072163398Sscottl				uint16_t	is_foreign	: 1;
1073163398Sscottl				uint16_t	reserved	: 7;
1074163398Sscottl				uint16_t	intf		: 4;
1075163398Sscottl			} pd_type;
1076163398Sscottl			uint16_t	type;
1077163398Sscottl		} v;
1078163398Sscottl		uint16_t		reserved;
1079163398Sscottl	} ddf;
1080163398Sscottl	struct {
1081163398Sscottl		uint32_t		reserved;
1082163398Sscottl	} non_disk;
1083163398Sscottl	uint32_t			type;
1084163398Sscottl} __packed;
1085163398Sscottl
1086163398Sscottlstruct mfi_pd_progress {
1087196200Sscottl	uint32_t			active;
1088196200Sscottl#define	MFI_PD_PROGRESS_REBUILD	(1<<0)
1089196200Sscottl#define	MFI_PD_PROGRESS_PATROL	(1<<1)
1090196200Sscottl#define	MFI_PD_PROGRESS_CLEAR	(1<<2)
1091163398Sscottl	struct mfi_progress		rbld;
1092163398Sscottl	struct mfi_progress		patrol;
1093163398Sscottl	struct mfi_progress		clear;
1094163398Sscottl	struct mfi_progress		reserved[4];
1095163398Sscottl} __packed;
1096163398Sscottl
1097163398Sscottlstruct mfi_pd_info {
1098163398Sscottl	union mfi_pd_ref		ref;
1099163398Sscottl	uint8_t				inquiry_data[96];
1100163398Sscottl	uint8_t				vpd_page83[64];
1101163398Sscottl	uint8_t				not_supported;
1102163398Sscottl	uint8_t				scsi_dev_type;
1103163398Sscottl	uint8_t				connected_port_bitmap;
1104163398Sscottl	uint8_t				device_speed;
1105163398Sscottl	uint32_t			media_err_count;
1106163398Sscottl	uint32_t			other_err_count;
1107163398Sscottl	uint32_t			pred_fail_count;
1108163398Sscottl	uint32_t			last_pred_fail_event_seq_num;
1109196200Sscottl	uint16_t			fw_state;	/* MFI_PD_STATE_* */
1110196200Sscottl	uint8_t				disabled_for_removal;
1111163398Sscottl	uint8_t				link_speed;
1112163398Sscottl	union mfi_pd_ddf_type		state;
1113163398Sscottl	struct {
1114163398Sscottl		uint8_t			count;
1115163398Sscottl		uint8_t			is_path_broken;
1116163398Sscottl		uint8_t			reserved[6];
1117163398Sscottl		uint64_t		sas_addr[4];
1118163398Sscottl	} path_info;
1119163398Sscottl	uint64_t			raw_size;
1120163398Sscottl	uint64_t			non_coerced_size;
1121163398Sscottl	uint64_t			coerced_size;
1122163398Sscottl	uint16_t			encl_device_id;
1123163398Sscottl	uint8_t				encl_index;
1124163398Sscottl	uint8_t				slot_number;
1125163398Sscottl	struct mfi_pd_progress		prog_info;
1126163398Sscottl	uint8_t				bad_block_table_full;
1127163398Sscottl	uint8_t				unusable_in_current_config;
1128163398Sscottl	uint8_t				vpd_page83_ext[64];
1129163398Sscottl	uint8_t				reserved[512-358];
1130163398Sscottl} __packed;
1131163398Sscottl
1132163398Sscottlstruct mfi_pd_address {
1133163398Sscottl	uint16_t		device_id;
1134163398Sscottl	uint16_t		encl_device_id;
1135163398Sscottl	uint8_t			encl_index;
1136163398Sscottl	uint8_t			slot_number;
1137196200Sscottl	uint8_t			scsi_dev_type;	/* 0 = disk */
1138163398Sscottl	uint8_t			connect_port_bitmap;
1139163398Sscottl	uint64_t		sas_addr[2];
1140163398Sscottl} __packed;
1141163398Sscottl
1142234429Sambrisko#define MAX_SYS_PDS 240
1143163398Sscottlstruct mfi_pd_list {
1144163398Sscottl	uint32_t		size;
1145163398Sscottl	uint32_t		count;
1146234429Sambrisko	struct mfi_pd_address	addr[MAX_SYS_PDS];
1147163398Sscottl} __packed;
1148163398Sscottl
1149196200Sscottlenum mfi_pd_state {
1150196200Sscottl	MFI_PD_STATE_UNCONFIGURED_GOOD = 0x00,
1151196200Sscottl	MFI_PD_STATE_UNCONFIGURED_BAD = 0x01,
1152196200Sscottl	MFI_PD_STATE_HOT_SPARE = 0x02,
1153196200Sscottl	MFI_PD_STATE_OFFLINE = 0x10,
1154196200Sscottl	MFI_PD_STATE_FAILED = 0x11,
1155196200Sscottl	MFI_PD_STATE_REBUILD = 0x14,
1156214130Spluknet	MFI_PD_STATE_ONLINE = 0x18,
1157214130Spluknet	MFI_PD_STATE_COPYBACK = 0x20,
1158214130Spluknet	MFI_PD_STATE_SYSTEM = 0x40
1159196200Sscottl};
1160196200Sscottl
1161234429Sambrisko/*
1162234429Sambrisko * "SYSTEM" disk appears to be "JBOD" support from the RAID controller.
1163234429Sambrisko * Adding a #define to denote this.
1164234429Sambrisko */
1165234429Sambrisko#define MFI_PD_STATE_JBOD MFI_PD_STATE_SYSTEM
1166234429Sambrisko
1167163398Sscottlunion mfi_ld_ref {
1168163398Sscottl	struct {
1169163398Sscottl		uint8_t		target_id;
1170163398Sscottl		uint8_t		reserved;
1171163398Sscottl		uint16_t	seq;
1172163398Sscottl	} v;
1173163398Sscottl	uint32_t		ref;
1174163398Sscottl} __packed;
1175163398Sscottl
1176159811Spsstruct mfi_ld_list {
1177159811Sps	uint32_t		ld_count;
1178159811Sps	uint32_t		reserved1;
1179159811Sps	struct {
1180163398Sscottl		union mfi_ld_ref	ld;
1181159811Sps		uint8_t		state;
1182159811Sps		uint8_t		reserved2[3];
1183159811Sps		uint64_t	size;
1184159811Sps	} ld_list[MFI_MAX_LD];
1185159811Sps} __packed;
1186159811Sps
1187159811Spsenum mfi_ld_access {
1188159811Sps	MFI_LD_ACCESS_RW =	0,
1189159811Sps	MFI_LD_ACCSSS_RO = 	2,
1190159811Sps	MFI_LD_ACCESS_BLOCKED =	3,
1191159811Sps};
1192159811Sps#define MFI_LD_ACCESS_MASK	3
1193159811Sps
1194159811Spsenum mfi_ld_state {
1195159811Sps	MFI_LD_STATE_OFFLINE =			0,
1196159811Sps	MFI_LD_STATE_PARTIALLY_DEGRADED =	1,
1197159811Sps	MFI_LD_STATE_DEGRADED =			2,
1198159811Sps	MFI_LD_STATE_OPTIMAL =			3
1199159811Sps};
1200159811Sps
1201159811Spsstruct mfi_ld_props {
1202163398Sscottl	union mfi_ld_ref	ld;
1203159811Sps	char			name[16];
1204159811Sps	uint8_t			default_cache_policy;
1205159811Sps	uint8_t			access_policy;
1206159811Sps	uint8_t			disk_cache_policy;
1207159811Sps	uint8_t			current_cache_policy;
1208159811Sps	uint8_t			no_bgi;
1209159811Sps	uint8_t			reserved[7];
1210159811Sps} __packed;
1211159811Sps
1212159811Spsstruct mfi_ld_params {
1213159811Sps	uint8_t			primary_raid_level;
1214159811Sps	uint8_t			raid_level_qualifier;
1215159811Sps	uint8_t			secondary_raid_level;
1216159811Sps	uint8_t			stripe_size;
1217159811Sps	uint8_t			num_drives;
1218159811Sps	uint8_t			span_depth;
1219159811Sps	uint8_t			state;
1220159811Sps	uint8_t			init_state;
1221196200Sscottl#define	MFI_LD_PARAMS_INIT_NO		0
1222196200Sscottl#define	MFI_LD_PARAMS_INIT_QUICK	1
1223196200Sscottl#define	MFI_LD_PARAMS_INIT_FULL		2
1224159811Sps	uint8_t			is_consistent;
1225234429Sambrisko	uint8_t			reserved1[6];
1226234429Sambrisko	uint8_t			isSSCD;
1227234429Sambrisko	uint8_t			reserved2[16];
1228159811Sps} __packed;
1229159811Sps
1230159811Spsstruct mfi_ld_progress {
1231159811Sps	uint32_t		active;
1232159811Sps#define	MFI_LD_PROGRESS_CC	(1<<0)
1233159811Sps#define	MFI_LD_PROGRESS_BGI	(1<<1)
1234159811Sps#define	MFI_LD_PROGRESS_FGI	(1<<2)
1235196200Sscottl#define	MFI_LD_PROGRESS_RECON	(1<<3)
1236159811Sps	struct mfi_progress	cc;
1237159811Sps	struct mfi_progress	bgi;
1238159811Sps	struct mfi_progress	fgi;
1239159811Sps	struct mfi_progress	recon;
1240159811Sps	struct mfi_progress	reserved[4];
1241159811Sps} __packed;
1242159811Sps
1243159811Spsstruct mfi_span {
1244159811Sps	uint64_t		start_block;
1245159811Sps	uint64_t		num_blocks;
1246159811Sps	uint16_t		array_ref;
1247159811Sps	uint8_t			reserved[6];
1248159811Sps} __packed;
1249159811Sps
1250159811Sps#define	MFI_MAX_SPAN_DEPTH	8
1251159811Spsstruct mfi_ld_config {
1252159811Sps	struct mfi_ld_props	properties;
1253159811Sps	struct mfi_ld_params	params;
1254159811Sps	struct mfi_span		span[MFI_MAX_SPAN_DEPTH];
1255159811Sps} __packed;
1256159811Sps
1257159811Spsstruct mfi_ld_info {
1258159811Sps	struct mfi_ld_config	ld_config;
1259159811Sps	uint64_t		size;
1260159811Sps	struct mfi_ld_progress	progress;
1261159811Sps	uint16_t		cluster_owner;
1262159811Sps	uint8_t			reconstruct_active;
1263159811Sps	uint8_t			reserved1[1];
1264159811Sps	uint8_t			vpd_page83[64];
1265159811Sps	uint8_t			reserved2[16];
1266159811Sps} __packed;
1267159811Sps
1268234429Sambrisko#define MFI_MAX_ARRAYS 16
1269163398Sscottlstruct mfi_spare {
1270163398Sscottl	union mfi_pd_ref	ref;
1271196200Sscottl	uint8_t			spare_type;
1272196200Sscottl#define	MFI_SPARE_DEDICATED	(1 << 0)
1273196200Sscottl#define	MFI_SPARE_REVERTIBLE	(1 << 1)
1274196200Sscottl#define	MFI_SPARE_ENCL_AFFINITY	(1 << 2)
1275163398Sscottl	uint8_t			reserved[2];
1276163398Sscottl	uint8_t			array_count;
1277234429Sambrisko	uint16_t		array_ref[MFI_MAX_ARRAYS];
1278163398Sscottl} __packed;
1279163398Sscottl
1280234429Sambrisko#define MFI_MAX_ROW_SIZE 32
1281163398Sscottlstruct mfi_array {
1282163398Sscottl	uint64_t			size;
1283163398Sscottl	uint8_t				num_drives;
1284163398Sscottl	uint8_t				reserved;
1285163398Sscottl	uint16_t			array_ref;
1286163398Sscottl	uint8_t				pad[20];
1287163398Sscottl	struct {
1288196200Sscottl		union mfi_pd_ref	ref;	/* 0xffff == missing drive */
1289196200Sscottl		uint16_t		fw_state;	/* MFI_PD_STATE_* */
1290163398Sscottl		struct {
1291163398Sscottl			uint8_t		pd;
1292163398Sscottl			uint8_t		slot;
1293163398Sscottl		} encl;
1294234429Sambrisko	} pd[MFI_MAX_ROW_SIZE];
1295163398Sscottl} __packed;
1296163398Sscottl
1297163398Sscottlstruct mfi_config_data {
1298163398Sscottl	uint32_t		size;
1299163398Sscottl	uint16_t		array_count;
1300163398Sscottl	uint16_t		array_size;
1301163398Sscottl	uint16_t		log_drv_count;
1302163398Sscottl	uint16_t		log_drv_size;
1303163398Sscottl	uint16_t		spares_count;
1304163398Sscottl	uint16_t		spares_size;
1305163398Sscottl	uint8_t			reserved[16];
1306196200Sscottl	struct mfi_array	array[0];
1307196200Sscottl	struct mfi_ld_config	ld[0];
1308196200Sscottl	struct mfi_spare	spare[0];
1309163398Sscottl} __packed;
1310163398Sscottl
1311196200Sscottlstruct mfi_bbu_capacity_info {
1312196200Sscottl	uint16_t		relative_charge;
1313196200Sscottl	uint16_t		absolute_charge;
1314196200Sscottl	uint16_t		remaining_capacity;
1315196200Sscottl	uint16_t		full_charge_capacity;
1316196200Sscottl	uint16_t		run_time_to_empty;
1317196200Sscottl	uint16_t		average_time_to_empty;
1318196200Sscottl	uint16_t		average_time_to_full;
1319196200Sscottl	uint16_t		cycle_count;
1320196200Sscottl	uint16_t		max_error;
1321196200Sscottl	uint16_t		remaining_capacity_alarm;
1322196200Sscottl	uint16_t		remaining_time_alarm;
1323196200Sscottl	uint8_t			reserved[26];
1324196200Sscottl} __packed;
1325196200Sscottl
1326196200Sscottlstruct mfi_bbu_design_info {
1327196200Sscottl	uint32_t		mfg_date;
1328196200Sscottl	uint16_t		design_capacity;
1329196200Sscottl	uint16_t		design_voltage;
1330196200Sscottl	uint16_t		spec_info;
1331196200Sscottl	uint16_t		serial_number;
1332196200Sscottl	uint16_t		pack_stat_config;
1333196200Sscottl	uint8_t			mfg_name[12];
1334196200Sscottl	uint8_t			device_name[8];
1335196200Sscottl	uint8_t			device_chemistry[8];
1336196200Sscottl	uint8_t			mfg_data[8];
1337196200Sscottl	uint8_t			reserved[17];
1338196200Sscottl} __packed;
1339196200Sscottl
1340196200Sscottlstruct mfi_ibbu_state {
1341196200Sscottl	uint16_t		gas_guage_status;
1342196200Sscottl	uint16_t		relative_charge;
1343196200Sscottl	uint16_t		charger_system_state;
1344196200Sscottl	uint16_t		charger_system_ctrl;
1345196200Sscottl	uint16_t		charging_current;
1346196200Sscottl	uint16_t		absolute_charge;
1347196200Sscottl	uint16_t		max_error;
1348196200Sscottl	uint8_t			reserved[18];
1349196200Sscottl} __packed;
1350196200Sscottl
1351196200Sscottlstruct mfi_bbu_state {
1352196200Sscottl	uint16_t		gas_guage_status;
1353196200Sscottl	uint16_t		relative_charge;
1354196200Sscottl	uint16_t		charger_status;
1355196200Sscottl	uint16_t		remaining_capacity;
1356196200Sscottl	uint16_t		full_charge_capacity;
1357196200Sscottl	uint8_t			is_SOH_good;
1358196200Sscottl	uint8_t			reserved[21];
1359196200Sscottl} __packed;
1360196200Sscottl
1361196200Sscottlunion mfi_bbu_status_detail {
1362196200Sscottl	struct mfi_ibbu_state	ibbu;
1363196200Sscottl	struct mfi_bbu_state	bbu;
1364196200Sscottl};
1365196200Sscottl
1366196200Sscottlstruct mfi_bbu_status {
1367196200Sscottl	uint8_t			battery_type;
1368196200Sscottl#define	MFI_BBU_TYPE_NONE	0
1369196200Sscottl#define	MFI_BBU_TYPE_IBBU	1
1370234429Sambrisko#define	MFI_BBU_TYPE_BBU	2
1371196200Sscottl	uint8_t			reserved;
1372196200Sscottl	uint16_t		voltage;
1373196200Sscottl	int16_t			current;
1374196200Sscottl	uint16_t		temperature;
1375196200Sscottl	uint32_t		fw_status;
1376196200Sscottl#define	MFI_BBU_STATE_PACK_MISSING	(1 << 0)
1377196200Sscottl#define	MFI_BBU_STATE_VOLTAGE_LOW	(1 << 1)
1378196200Sscottl#define	MFI_BBU_STATE_TEMPERATURE_HIGH	(1 << 2)
1379196200Sscottl#define	MFI_BBU_STATE_CHARGE_ACTIVE	(1 << 0)
1380196200Sscottl#define	MFI_BBU_STATE_DISCHARGE_ACTIVE	(1 << 0)
1381196200Sscottl	uint8_t			pad[20];
1382196200Sscottl	union mfi_bbu_status_detail detail;
1383196200Sscottl} __packed;
1384196200Sscottl
1385196200Sscottlenum mfi_pr_state {
1386196200Sscottl	MFI_PR_STATE_STOPPED = 0,
1387196200Sscottl	MFI_PR_STATE_READY = 1,
1388196200Sscottl	MFI_PR_STATE_ACTIVE = 2,
1389196200Sscottl	MFI_PR_STATE_ABORTED = 0xff
1390196200Sscottl};
1391196200Sscottl
1392196200Sscottlstruct mfi_pr_status {
1393196200Sscottl	uint32_t		num_iteration;
1394196200Sscottl	uint8_t			state;
1395196200Sscottl	uint8_t			num_pd_done;
1396196200Sscottl	uint8_t			reserved[10];
1397196200Sscottl};
1398196200Sscottl
1399196200Sscottlenum mfi_pr_opmode {
1400196200Sscottl	MFI_PR_OPMODE_AUTO = 0,
1401196200Sscottl	MFI_PR_OPMODE_MANUAL = 1,
1402196200Sscottl	MFI_PR_OPMODE_DISABLED = 2
1403196200Sscottl};
1404196200Sscottl
1405196200Sscottlstruct mfi_pr_properties {
1406196200Sscottl	uint8_t			op_mode;
1407196200Sscottl	uint8_t			max_pd;
1408196200Sscottl	uint8_t			reserved;
1409196200Sscottl	uint8_t			exclude_ld_count;
1410196200Sscottl	uint16_t		excluded_ld[MFI_MAX_LD];
1411196200Sscottl	uint8_t			cur_pd_map[MFI_MAX_PD / 8];
1412196200Sscottl	uint8_t			last_pd_map[MFI_MAX_PD / 8];
1413196200Sscottl	uint32_t		next_exec;
1414196200Sscottl	uint32_t		exec_freq;
1415196200Sscottl	uint32_t		clear_freq;
1416196200Sscottl};
1417196200Sscottl
1418234429Sambrisko/* ThunderBolt support */
1419234429Sambrisko
1420234429Sambrisko/*
1421234429Sambrisko * Raid Context structure which describes MegaRAID specific IO Paramenters
1422234429Sambrisko * This resides at offset 0x60 where the SGL normally starts in MPT IO Frames
1423234429Sambrisko */
1424234429Sambriskotypedef struct _MPI2_SCSI_IO_VENDOR_UNIQUE {
1425234429Sambrisko	uint16_t	resvd0;		/* 0x00 - 0x01 */
1426234429Sambrisko	uint16_t	timeoutValue;	/* 0x02 - 0x03 */
1427234429Sambrisko	uint8_t		regLockFlags;
1428234429Sambrisko	uint8_t		armId;
1429234429Sambrisko	uint16_t	TargetID;	/* 0x06 - 0x07 */
1430234429Sambrisko
1431234429Sambrisko	uint64_t	RegLockLBA;	/* 0x08 - 0x0F */
1432234429Sambrisko
1433234429Sambrisko	uint32_t	RegLockLength;	/* 0x10 - 0x13 */
1434234429Sambrisko
1435234429Sambrisko	uint16_t	SMID;		/* 0x14 - 0x15 nextLMId */
1436234429Sambrisko	uint8_t		exStatus;	/* 0x16 */
1437234429Sambrisko	uint8_t		Status;		/* 0x17 status */
1438234429Sambrisko
1439234429Sambrisko	uint8_t		RAIDFlags;	/* 0x18 */
1440234429Sambrisko	uint8_t		numSGE;		/* 0x19 numSge */
1441234429Sambrisko	uint16_t	configSeqNum;	/* 0x1A - 0x1B */
1442234429Sambrisko	uint8_t		spanArm;	/* 0x1C */
1443234429Sambrisko	uint8_t		resvd2[3];	/* 0x1D - 0x1F */
1444234429Sambrisko} MPI2_SCSI_IO_VENDOR_UNIQUE, MPI25_SCSI_IO_VENDOR_UNIQUE;
1445234429Sambrisko
1446234429Sambrisko/*****************************************************************************
1447234429Sambrisko*
1448234429Sambrisko*        Message Functions
1449234429Sambrisko*
1450234429Sambrisko*****************************************************************************/
1451234429Sambrisko
1452234429Sambrisko#define NA_MPI2_FUNCTION_SCSI_IO_REQUEST            (0x00) /* SCSI IO */
1453234429Sambrisko#define MPI2_FUNCTION_SCSI_TASK_MGMT                (0x01) /* SCSI Task Management */
1454234429Sambrisko#define MPI2_FUNCTION_IOC_INIT                      (0x02) /* IOC Init */
1455234429Sambrisko#define MPI2_FUNCTION_IOC_FACTS                     (0x03) /* IOC Facts */
1456234429Sambrisko#define MPI2_FUNCTION_CONFIG                        (0x04) /* Configuration */
1457234429Sambrisko#define MPI2_FUNCTION_PORT_FACTS                    (0x05) /* Port Facts */
1458234429Sambrisko#define MPI2_FUNCTION_PORT_ENABLE                   (0x06) /* Port Enable */
1459234429Sambrisko#define MPI2_FUNCTION_EVENT_NOTIFICATION            (0x07) /* Event Notification */
1460234429Sambrisko#define MPI2_FUNCTION_EVENT_ACK                     (0x08) /* Event Acknowledge */
1461234429Sambrisko#define MPI2_FUNCTION_FW_DOWNLOAD                   (0x09) /* FW Download */
1462234429Sambrisko#define MPI2_FUNCTION_TARGET_ASSIST                 (0x0B) /* Target Assist */
1463234429Sambrisko#define MPI2_FUNCTION_TARGET_STATUS_SEND            (0x0C) /* Target Status Send */
1464234429Sambrisko#define MPI2_FUNCTION_TARGET_MODE_ABORT             (0x0D) /* Target Mode Abort */
1465234429Sambrisko#define MPI2_FUNCTION_FW_UPLOAD                     (0x12) /* FW Upload */
1466234429Sambrisko#define MPI2_FUNCTION_RAID_ACTION                   (0x15) /* RAID Action */
1467234429Sambrisko#define MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH      (0x16) /* SCSI IO RAID Passthrough */
1468234429Sambrisko#define MPI2_FUNCTION_TOOLBOX                       (0x17) /* Toolbox */
1469234429Sambrisko#define MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR      (0x18) /* SCSI Enclosure Processor */
1470234429Sambrisko#define MPI2_FUNCTION_SMP_PASSTHROUGH               (0x1A) /* SMP Passthrough */
1471234429Sambrisko#define MPI2_FUNCTION_SAS_IO_UNIT_CONTROL           (0x1B) /* SAS IO Unit Control */
1472234429Sambrisko#define MPI2_FUNCTION_SATA_PASSTHROUGH              (0x1C) /* SATA Passthrough */
1473234429Sambrisko#define MPI2_FUNCTION_DIAG_BUFFER_POST              (0x1D) /* Diagnostic Buffer Post */
1474234429Sambrisko#define MPI2_FUNCTION_DIAG_RELEASE                  (0x1E) /* Diagnostic Release */
1475234429Sambrisko#define MPI2_FUNCTION_TARGET_CMD_BUF_BASE_POST      (0x24) /* Target Command Buffer Post Base */
1476234429Sambrisko#define MPI2_FUNCTION_TARGET_CMD_BUF_LIST_POST      (0x25) /* Target Command Buffer Post List */
1477234429Sambrisko#define MPI2_FUNCTION_RAID_ACCELERATOR              (0x2C) /* RAID Accelerator */
1478234429Sambrisko#define MPI2_FUNCTION_HOST_BASED_DISCOVERY_ACTION   (0x2F) /* Host Based Discovery Action */
1479234429Sambrisko#define MPI2_FUNCTION_PWR_MGMT_CONTROL              (0x30) /* Power Management Control */
1480234429Sambrisko#define MPI2_FUNCTION_MIN_PRODUCT_SPECIFIC          (0xF0) /* beginning of product-specific range */
1481234429Sambrisko#define MPI2_FUNCTION_MAX_PRODUCT_SPECIFIC          (0xFF) /* end of product-specific range */
1482234429Sambrisko
1483234429Sambrisko/* Doorbell functions */
1484234429Sambrisko#define MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET        (0x40)
1485234429Sambrisko#define MPI2_FUNCTION_HANDSHAKE                     (0x42)
1486234429Sambrisko
1487234429Sambrisko/*****************************************************************************
1488234429Sambrisko*
1489234429Sambrisko*        MPI Version Definitions
1490234429Sambrisko*
1491234429Sambrisko*****************************************************************************/
1492234429Sambrisko
1493234429Sambrisko#define MPI2_VERSION_MAJOR                  (0x02)
1494234429Sambrisko#define MPI2_VERSION_MINOR                  (0x00)
1495234429Sambrisko#define MPI2_VERSION_MAJOR_MASK             (0xFF00)
1496234429Sambrisko#define MPI2_VERSION_MAJOR_SHIFT            (8)
1497234429Sambrisko#define MPI2_VERSION_MINOR_MASK             (0x00FF)
1498234429Sambrisko#define MPI2_VERSION_MINOR_SHIFT            (0)
1499234429Sambrisko#define MPI2_VERSION ((MPI2_VERSION_MAJOR << MPI2_VERSION_MAJOR_SHIFT) |   \
1500234429Sambrisko                                      MPI2_VERSION_MINOR)
1501234429Sambrisko
1502234429Sambrisko#define MPI2_VERSION_02_00                  (0x0200)
1503234429Sambrisko
1504234429Sambrisko/* versioning for this MPI header set */
1505234429Sambrisko#define MPI2_HEADER_VERSION_UNIT            (0x10)
1506234429Sambrisko#define MPI2_HEADER_VERSION_DEV             (0x00)
1507234429Sambrisko#define MPI2_HEADER_VERSION_UNIT_MASK       (0xFF00)
1508234429Sambrisko#define MPI2_HEADER_VERSION_UNIT_SHIFT      (8)
1509234429Sambrisko#define MPI2_HEADER_VERSION_DEV_MASK        (0x00FF)
1510234429Sambrisko#define MPI2_HEADER_VERSION_DEV_SHIFT       (0)
1511234429Sambrisko#define MPI2_HEADER_VERSION ((MPI2_HEADER_VERSION_UNIT << 8) |		\
1512234429Sambrisko					MPI2_HEADER_VERSION_DEV)
1513234429Sambrisko
1514234429Sambrisko
1515234429Sambrisko/* IOCInit Request message */
1516234429Sambriskostruct MPI2_IOC_INIT_REQUEST {
1517234429Sambrisko	uint8_t		WhoInit;                        /* 0x00 */
1518234429Sambrisko	uint8_t		Reserved1;                      /* 0x01 */
1519234429Sambrisko	uint8_t		ChainOffset;                    /* 0x02 */
1520234429Sambrisko	uint8_t		Function;                       /* 0x03 */
1521234429Sambrisko	uint16_t	Reserved2;                      /* 0x04 */
1522234429Sambrisko	uint8_t		Reserved3;                      /* 0x06 */
1523234429Sambrisko	uint8_t		MsgFlags;                       /* 0x07 */
1524234429Sambrisko	uint8_t		VP_ID;                          /* 0x08 */
1525234429Sambrisko	uint8_t		VF_ID;                          /* 0x09 */
1526234429Sambrisko	uint16_t	Reserved4;                      /* 0x0A */
1527234429Sambrisko	uint16_t	MsgVersion;                     /* 0x0C */
1528234429Sambrisko	uint16_t	HeaderVersion;                  /* 0x0E */
1529234429Sambrisko	uint32_t	Reserved5;                      /* 0x10 */
1530234429Sambrisko	uint16_t	Reserved6;                      /* 0x14 */
1531234429Sambrisko	uint8_t		Reserved7;                      /* 0x16 */
1532234429Sambrisko	uint8_t		HostMSIxVectors;                /* 0x17 */
1533234429Sambrisko	uint16_t	Reserved8;                      /* 0x18 */
1534234429Sambrisko	uint16_t	SystemRequestFrameSize;         /* 0x1A */
1535234429Sambrisko	uint16_t	ReplyDescriptorPostQueueDepth;  /* 0x1C */
1536234429Sambrisko	uint16_t	ReplyFreeQueueDepth;            /* 0x1E */
1537234429Sambrisko	uint32_t	SenseBufferAddressHigh;         /* 0x20 */
1538234429Sambrisko	uint32_t	SystemReplyAddressHigh;         /* 0x24 */
1539234429Sambrisko	uint64_t	SystemRequestFrameBaseAddress;  /* 0x28 */
1540234429Sambrisko	uint64_t	ReplyDescriptorPostQueueAddress;/* 0x30 */
1541234429Sambrisko	uint64_t	ReplyFreeQueueAddress;          /* 0x38 */
1542234429Sambrisko	uint64_t	TimeStamp;                      /* 0x40 */
1543234429Sambrisko};
1544234429Sambrisko
1545234429Sambrisko/* WhoInit values */
1546234429Sambrisko#define MPI2_WHOINIT_NOT_INITIALIZED            (0x00)
1547234429Sambrisko#define MPI2_WHOINIT_SYSTEM_BIOS                (0x01)
1548234429Sambrisko#define MPI2_WHOINIT_ROM_BIOS                   (0x02)
1549234429Sambrisko#define MPI2_WHOINIT_PCI_PEER                   (0x03)
1550234429Sambrisko#define MPI2_WHOINIT_HOST_DRIVER                (0x04)
1551234429Sambrisko#define MPI2_WHOINIT_MANUFACTURER               (0x05)
1552234429Sambrisko
1553234429Sambriskostruct MPI2_SGE_CHAIN_UNION {
1554234429Sambrisko	uint16_t	Length;
1555234429Sambrisko	uint8_t		NextChainOffset;
1556234429Sambrisko	uint8_t		Flags;
1557234429Sambrisko	union {
1558234429Sambrisko		uint32_t	Address32;
1559234429Sambrisko		uint64_t	Address64;
1560234429Sambrisko	} u;
1561234429Sambrisko};
1562234429Sambrisko
1563234429Sambriskostruct MPI2_IEEE_SGE_SIMPLE32 {
1564234429Sambrisko	uint32_t	Address;
1565234429Sambrisko	uint32_t	FlagsLength;
1566234429Sambrisko};
1567234429Sambrisko
1568234429Sambriskostruct MPI2_IEEE_SGE_SIMPLE64 {
1569234429Sambrisko	uint64_t	Address;
1570234429Sambrisko	uint32_t	Length;
1571234429Sambrisko	uint16_t	Reserved1;
1572234429Sambrisko	uint8_t		Reserved2;
1573234429Sambrisko	uint8_t		Flags;
1574234429Sambrisko};
1575234429Sambrisko
1576234429Sambriskotypedef union _MPI2_IEEE_SGE_SIMPLE_UNION {
1577234429Sambrisko	struct MPI2_IEEE_SGE_SIMPLE32	Simple32;
1578234429Sambrisko	struct MPI2_IEEE_SGE_SIMPLE64	Simple64;
1579234429Sambrisko} MPI2_IEEE_SGE_SIMPLE_UNION;
1580234429Sambrisko
1581234429Sambriskotypedef struct _MPI2_SGE_SIMPLE_UNION {
1582234429Sambrisko	uint32_t	FlagsLength;
1583234429Sambrisko	union {
1584234429Sambrisko		uint32_t	Address32;
1585234429Sambrisko		uint64_t	Address64;
1586234429Sambrisko	} u;
1587234429Sambrisko} MPI2_SGE_SIMPLE_UNION;
1588234429Sambrisko
1589234429Sambrisko/****************************************************************************
1590234429Sambrisko*  IEEE SGE field definitions and masks
1591234429Sambrisko****************************************************************************/
1592234429Sambrisko
1593234429Sambrisko/* Flags field bit definitions */
1594234429Sambrisko
1595234429Sambrisko#define MPI2_IEEE_SGE_FLAGS_ELEMENT_TYPE_MASK   (0x80)
1596234429Sambrisko
1597234429Sambrisko#define MPI2_IEEE32_SGE_FLAGS_SHIFT             (24)
1598234429Sambrisko
1599234429Sambrisko#define MPI2_IEEE32_SGE_LENGTH_MASK             (0x00FFFFFF)
1600234429Sambrisko
1601234429Sambrisko/* Element Type */
1602234429Sambrisko
1603234429Sambrisko#define MPI2_IEEE_SGE_FLAGS_SIMPLE_ELEMENT      (0x00)
1604234429Sambrisko#define MPI2_IEEE_SGE_FLAGS_CHAIN_ELEMENT       (0x80)
1605234429Sambrisko
1606234429Sambrisko/* Data Location Address Space */
1607234429Sambrisko
1608234429Sambrisko#define MPI2_IEEE_SGE_FLAGS_ADDR_MASK           (0x03)
1609234429Sambrisko#define MPI2_IEEE_SGE_FLAGS_SYSTEM_ADDR         (0x00)
1610234429Sambrisko#define MPI2_IEEE_SGE_FLAGS_IOCDDR_ADDR         (0x01)
1611234429Sambrisko#define MPI2_IEEE_SGE_FLAGS_IOCPLB_ADDR         (0x02)
1612234429Sambrisko#define MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR      (0x03)
1613234429Sambrisko
1614234429Sambrisko/* Address Size */
1615234429Sambrisko
1616234429Sambrisko#define MPI2_SGE_FLAGS_32_BIT_ADDRESSING        (0x00)
1617234429Sambrisko#define MPI2_SGE_FLAGS_64_BIT_ADDRESSING        (0x02)
1618234429Sambrisko
1619234429Sambrisko/*******************/
1620234429Sambrisko/* SCSI IO Control bits */
1621234429Sambrisko#define MPI2_SCSIIO_CONTROL_ADDCDBLEN_MASK      (0xFC000000)
1622234429Sambrisko#define MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT     (26)
1623234429Sambrisko
1624234429Sambrisko#define MPI2_SCSIIO_CONTROL_DATADIRECTION_MASK  (0x03000000)
1625234429Sambrisko#define MPI2_SCSIIO_CONTROL_NODATATRANSFER      (0x00000000)
1626234429Sambrisko#define MPI2_SCSIIO_CONTROL_WRITE               (0x01000000)
1627234429Sambrisko#define MPI2_SCSIIO_CONTROL_READ                (0x02000000)
1628234429Sambrisko#define MPI2_SCSIIO_CONTROL_BIDIRECTIONAL       (0x03000000)
1629234429Sambrisko
1630234429Sambrisko#define MPI2_SCSIIO_CONTROL_TASKPRI_MASK        (0x00007800)
1631234429Sambrisko#define MPI2_SCSIIO_CONTROL_TASKPRI_SHIFT       (11)
1632234429Sambrisko
1633234429Sambrisko#define MPI2_SCSIIO_CONTROL_TASKATTRIBUTE_MASK  (0x00000700)
1634234429Sambrisko#define MPI2_SCSIIO_CONTROL_SIMPLEQ             (0x00000000)
1635234429Sambrisko#define MPI2_SCSIIO_CONTROL_HEADOFQ             (0x00000100)
1636234429Sambrisko#define MPI2_SCSIIO_CONTROL_ORDEREDQ            (0x00000200)
1637234429Sambrisko#define MPI2_SCSIIO_CONTROL_ACAQ                (0x00000400)
1638234429Sambrisko
1639234429Sambrisko#define MPI2_SCSIIO_CONTROL_TLR_MASK            (0x000000C0)
1640234429Sambrisko#define MPI2_SCSIIO_CONTROL_NO_TLR              (0x00000000)
1641234429Sambrisko#define MPI2_SCSIIO_CONTROL_TLR_ON              (0x00000040)
1642234429Sambrisko#define MPI2_SCSIIO_CONTROL_TLR_OFF             (0x00000080)
1643234429Sambrisko
1644234429Sambrisko/*******************/
1645234429Sambrisko
1646234429Sambriskotypedef struct {
1647234429Sambrisko	uint8_t		CDB[20];                    /* 0x00 */
1648234429Sambrisko	uint32_t	PrimaryReferenceTag;        /* 0x14 */
1649234429Sambrisko	uint16_t	PrimaryApplicationTag;      /* 0x18 */
1650234429Sambrisko	uint16_t	PrimaryApplicationTagMask;  /* 0x1A */
1651234429Sambrisko	uint32_t	TransferLength;             /* 0x1C */
1652234429Sambrisko} MPI2_SCSI_IO_CDB_EEDP32;
1653234429Sambrisko
1654234429Sambrisko
1655234429Sambriskotypedef union _MPI2_IEEE_SGE_CHAIN_UNION {
1656234429Sambrisko	struct MPI2_IEEE_SGE_SIMPLE32	Chain32;
1657234429Sambrisko	struct MPI2_IEEE_SGE_SIMPLE64	Chain64;
1658234429Sambrisko} MPI2_IEEE_SGE_CHAIN_UNION;
1659234429Sambrisko
1660234429Sambriskotypedef union _MPI2_SIMPLE_SGE_UNION {
1661234429Sambrisko	MPI2_SGE_SIMPLE_UNION		MpiSimple;
1662234429Sambrisko	MPI2_IEEE_SGE_SIMPLE_UNION	IeeeSimple;
1663234429Sambrisko} MPI2_SIMPLE_SGE_UNION;
1664234429Sambrisko
1665234429Sambriskotypedef union _MPI2_SGE_IO_UNION {
1666234429Sambrisko	MPI2_SGE_SIMPLE_UNION		MpiSimple;
1667234429Sambrisko	struct MPI2_SGE_CHAIN_UNION	MpiChain;
1668234429Sambrisko	MPI2_IEEE_SGE_SIMPLE_UNION	IeeeSimple;
1669234429Sambrisko	MPI2_IEEE_SGE_CHAIN_UNION	IeeeChain;
1670234429Sambrisko} MPI2_SGE_IO_UNION;
1671234429Sambrisko
1672234429Sambriskotypedef union {
1673234429Sambrisko	uint8_t			CDB32[32];
1674234429Sambrisko	MPI2_SCSI_IO_CDB_EEDP32	EEDP32;
1675234429Sambrisko	MPI2_SGE_SIMPLE_UNION	SGE;
1676234429Sambrisko} MPI2_SCSI_IO_CDB_UNION;
1677234429Sambrisko
1678234429Sambrisko
1679234429Sambrisko/* MPI 2.5 SGLs */
1680234429Sambrisko
1681234429Sambrisko#define MPI25_IEEE_SGE_FLAGS_END_OF_LIST        (0x40)
1682234429Sambrisko
1683234429Sambriskotypedef struct _MPI25_IEEE_SGE_CHAIN64 {
1684234429Sambrisko	uint64_t	Address;
1685234429Sambrisko	uint32_t	Length;
1686234429Sambrisko	uint16_t	Reserved1;
1687234429Sambrisko	uint8_t		NextChainOffset;
1688234429Sambrisko	uint8_t		Flags;
1689234429Sambrisko} MPI25_IEEE_SGE_CHAIN64, *pMpi25IeeeSgeChain64_t;
1690234429Sambrisko
1691234429Sambrisko/* use MPI2_IEEE_SGE_FLAGS_ defines for the Flags field */
1692234429Sambrisko
1693234429Sambrisko
1694234429Sambrisko/********/
1695234429Sambrisko
1696234429Sambrisko/*
1697234429Sambrisko * RAID SCSI IO Request Message
1698234429Sambrisko * Total SGE count will be one less than  _MPI2_SCSI_IO_REQUEST
1699234429Sambrisko */
1700234429Sambriskostruct mfi_mpi2_request_raid_scsi_io {
1701234429Sambrisko	uint16_t		DevHandle;                      /* 0x00 */
1702234429Sambrisko	uint8_t			ChainOffset;                    /* 0x02 */
1703234429Sambrisko	uint8_t			Function;                       /* 0x03 */
1704234429Sambrisko	uint16_t		Reserved1;                      /* 0x04 */
1705234429Sambrisko	uint8_t			Reserved2;                      /* 0x06 */
1706234429Sambrisko	uint8_t			MsgFlags;                       /* 0x07 */
1707234429Sambrisko	uint8_t			VP_ID;                          /* 0x08 */
1708234429Sambrisko	uint8_t			VF_ID;                          /* 0x09 */
1709234429Sambrisko	uint16_t		Reserved3;                      /* 0x0A */
1710234429Sambrisko	uint32_t		SenseBufferLowAddress;          /* 0x0C */
1711234429Sambrisko	uint16_t		SGLFlags;                       /* 0x10 */
1712234429Sambrisko	uint8_t			SenseBufferLength;              /* 0x12 */
1713234429Sambrisko	uint8_t			Reserved4;                      /* 0x13 */
1714234429Sambrisko	uint8_t			SGLOffset0;                     /* 0x14 */
1715234429Sambrisko	uint8_t			SGLOffset1;                     /* 0x15 */
1716234429Sambrisko	uint8_t			SGLOffset2;                     /* 0x16 */
1717234429Sambrisko	uint8_t			SGLOffset3;                     /* 0x17 */
1718234429Sambrisko	uint32_t		SkipCount;                      /* 0x18 */
1719234429Sambrisko	uint32_t		DataLength;                     /* 0x1C */
1720234429Sambrisko	uint32_t		BidirectionalDataLength;        /* 0x20 */
1721234429Sambrisko	uint16_t		IoFlags;                        /* 0x24 */
1722234429Sambrisko	uint16_t		EEDPFlags;                      /* 0x26 */
1723234429Sambrisko	uint32_t		EEDPBlockSize;                  /* 0x28 */
1724234429Sambrisko	uint32_t		SecondaryReferenceTag;          /* 0x2C */
1725234429Sambrisko	uint16_t		SecondaryApplicationTag;        /* 0x30 */
1726234429Sambrisko	uint16_t		ApplicationTagTranslationMask;  /* 0x32 */
1727234429Sambrisko	uint8_t			LUN[8];                         /* 0x34 */
1728234429Sambrisko	uint32_t		Control;                        /* 0x3C */
1729234429Sambrisko	MPI2_SCSI_IO_CDB_UNION	CDB;                            /* 0x40 */
1730234429Sambrisko	MPI2_SCSI_IO_VENDOR_UNIQUE	RaidContext;              /* 0x60 */
1731234429Sambrisko	MPI2_SGE_IO_UNION	SGL;                            /* 0x80 */
1732234429Sambrisko} __packed;
1733234429Sambrisko
1734234429Sambrisko/*
1735234429Sambrisko * MPT RAID MFA IO Descriptor.
1736234429Sambrisko */
1737234429Sambriskotypedef struct _MFI_RAID_MFA_IO_DESCRIPTOR {
1738234429Sambrisko	uint32_t	RequestFlags : 8;
1739234429Sambrisko	uint32_t	MessageAddress1 : 24; /* bits 31:8*/
1740234429Sambrisko	uint32_t	MessageAddress2;      /* bits 61:32 */
1741234429Sambrisko} MFI_RAID_MFA_IO_REQUEST_DESCRIPTOR,*PMFI_RAID_MFA_IO_REQUEST_DESCRIPTOR;
1742234429Sambrisko
1743234429Sambriskostruct mfi_mpi2_request_header {
1744234429Sambrisko	uint8_t		RequestFlags;       /* 0x00 */
1745234429Sambrisko	uint8_t		MSIxIndex;          /* 0x01 */
1746234429Sambrisko	uint16_t	SMID;               /* 0x02 */
1747234429Sambrisko	uint16_t	LMID;               /* 0x04 */
1748234429Sambrisko};
1749234429Sambrisko
1750234429Sambrisko/* defines for the RequestFlags field */
1751234429Sambrisko#define MPI2_REQ_DESCRIPT_FLAGS_TYPE_MASK               (0x0E)
1752234429Sambrisko#define MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO                 (0x00)
1753234429Sambrisko#define MPI2_REQ_DESCRIPT_FLAGS_SCSI_TARGET             (0x02)
1754234429Sambrisko#define MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY           (0x06)
1755234429Sambrisko#define MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE            (0x08)
1756234429Sambrisko#define MPI2_REQ_DESCRIPT_FLAGS_RAID_ACCELERATOR        (0x0A)
1757234429Sambrisko
1758234429Sambrisko#define MPI2_REQ_DESCRIPT_FLAGS_IOC_FIFO_MARKER (0x01)
1759234429Sambrisko
1760234429Sambriskostruct mfi_mpi2_request_high_priority {
1761234429Sambrisko	struct mfi_mpi2_request_header	header;
1762234429Sambrisko	uint16_t			reserved;
1763234429Sambrisko};
1764234429Sambrisko
1765234429Sambriskostruct mfi_mpi2_request_scsi_io {
1766234429Sambrisko	struct mfi_mpi2_request_header	header;
1767234429Sambrisko	uint16_t			scsi_io_dev_handle;
1768234429Sambrisko};
1769234429Sambrisko
1770234429Sambriskostruct mfi_mpi2_request_scsi_target {
1771234429Sambrisko	struct mfi_mpi2_request_header	header;
1772234429Sambrisko	uint16_t			scsi_target_io_index;
1773234429Sambrisko};
1774234429Sambrisko
1775234429Sambrisko/* Request Descriptors */
1776234429Sambriskounion mfi_mpi2_request_descriptor {
1777234429Sambrisko	struct mfi_mpi2_request_header		header;
1778234429Sambrisko	struct mfi_mpi2_request_high_priority	high_priority;
1779234429Sambrisko	struct mfi_mpi2_request_scsi_io		scsi_io;
1780234429Sambrisko	struct mfi_mpi2_request_scsi_target	scsi_target;
1781234429Sambrisko	uint64_t				words;
1782234429Sambrisko};
1783234429Sambrisko
1784234429Sambrisko
1785234429Sambriskostruct mfi_mpi2_reply_header {
1786234429Sambrisko	uint8_t		ReplyFlags;                 /* 0x00 */
1787234429Sambrisko	uint8_t		MSIxIndex;                  /* 0x01 */
1788234429Sambrisko	uint16_t	SMID;                       /* 0x02 */
1789234429Sambrisko};
1790234429Sambrisko
1791234429Sambrisko/* defines for the ReplyFlags field */
1792234429Sambrisko#define MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK                   (0x0F)
1793234429Sambrisko#define MPI2_RPY_DESCRIPT_FLAGS_SCSI_IO_SUCCESS             (0x00)
1794234429Sambrisko#define MPI2_RPY_DESCRIPT_FLAGS_ADDRESS_REPLY               (0x01)
1795234429Sambrisko#define MPI2_RPY_DESCRIPT_FLAGS_TARGETASSIST_SUCCESS        (0x02)
1796234429Sambrisko#define MPI2_RPY_DESCRIPT_FLAGS_TARGET_COMMAND_BUFFER       (0x03)
1797234429Sambrisko#define MPI2_RPY_DESCRIPT_FLAGS_RAID_ACCELERATOR_SUCCESS    (0x05)
1798234429Sambrisko#define MPI2_RPY_DESCRIPT_FLAGS_UNUSED                      (0x0F)
1799234429Sambrisko
1800234429Sambrisko/* values for marking a reply descriptor as unused */
1801234429Sambrisko#define MPI2_RPY_DESCRIPT_UNUSED_WORD0_MARK             (0xFFFFFFFF)
1802234429Sambrisko#define MPI2_RPY_DESCRIPT_UNUSED_WORD1_MARK             (0xFFFFFFFF)
1803234429Sambrisko
1804234429Sambriskostruct mfi_mpi2_reply_default {
1805234429Sambrisko	struct mfi_mpi2_reply_header	header;
1806234429Sambrisko	uint32_t			DescriptorTypeDependent2;
1807234429Sambrisko};
1808234429Sambrisko
1809234429Sambriskostruct mfi_mpi2_reply_address {
1810234429Sambrisko	struct mfi_mpi2_reply_header	header;
1811234429Sambrisko	uint32_t			ReplyFrameAddress;
1812234429Sambrisko};
1813234429Sambrisko
1814234429Sambriskostruct mfi_mpi2_reply_scsi_io {
1815234429Sambrisko	struct mfi_mpi2_reply_header	header;
1816234429Sambrisko	uint16_t			TaskTag;		/* 0x04 */
1817234429Sambrisko	uint16_t			Reserved1;		/* 0x06 */
1818234429Sambrisko};
1819234429Sambrisko
1820234429Sambriskostruct mfi_mpi2_reply_target_assist {
1821234429Sambrisko	struct mfi_mpi2_reply_header	header;
1822234429Sambrisko	uint8_t				SequenceNumber;		/* 0x04 */
1823234429Sambrisko	uint8_t				Reserved1;		/* 0x04 */
1824234429Sambrisko	uint16_t			IoIndex;		/* 0x06 */
1825234429Sambrisko};
1826234429Sambrisko
1827234429Sambriskostruct mfi_mpi2_reply_target_cmd_buffer {
1828234429Sambrisko	struct mfi_mpi2_reply_header	header;
1829234429Sambrisko	uint8_t				SequenceNumber;		/* 0x04 */
1830234429Sambrisko	uint8_t				Flags;			/* 0x04 */
1831234429Sambrisko	uint16_t			InitiatorDevHandle;	/* 0x06 */
1832234429Sambrisko	uint16_t			IoIndex;		/* 0x06 */
1833234429Sambrisko};
1834234429Sambrisko
1835234429Sambriskostruct mfi_mpi2_reply_raid_accel {
1836234429Sambrisko	struct mfi_mpi2_reply_header	header;
1837234429Sambrisko	uint8_t				SequenceNumber;		/* 0x04 */
1838234429Sambrisko	uint32_t			Reserved;		/* 0x04 */
1839234429Sambrisko};
1840234429Sambrisko
1841234429Sambrisko/* union of Reply Descriptors */
1842234429Sambriskounion mfi_mpi2_reply_descriptor {
1843234429Sambrisko	struct mfi_mpi2_reply_header		header;
1844234429Sambrisko	struct mfi_mpi2_reply_scsi_io		scsi_io;
1845234429Sambrisko	struct mfi_mpi2_reply_target_assist	target_assist;
1846234429Sambrisko	struct mfi_mpi2_reply_target_cmd_buffer	target_cmd;
1847234429Sambrisko	struct mfi_mpi2_reply_raid_accel	raid_accel;
1848234429Sambrisko	struct mfi_mpi2_reply_default		reply_default;
1849234429Sambrisko	uint64_t				words;
1850234429Sambrisko};
1851234429Sambrisko
1852234429Sambriskostruct IO_REQUEST_INFO {
1853234429Sambrisko	uint64_t	ldStartBlock;
1854234429Sambrisko	uint32_t	numBlocks;
1855234429Sambrisko	uint16_t	ldTgtId;
1856234429Sambrisko	uint8_t		isRead;
1857234429Sambrisko	uint16_t	devHandle;
1858234429Sambrisko	uint64_t	pdBlock;
1859234429Sambrisko	uint8_t		fpOkForIo;
1860234429Sambrisko};
1861234429Sambrisko
1862169611Sscottl#define MFI_SCSI_MAX_TARGETS	128
1863169611Sscottl#define MFI_SCSI_MAX_LUNS	8
1864169611Sscottl#define MFI_SCSI_INITIATOR_ID	255
1865169611Sscottl#define MFI_SCSI_MAX_CMDS	8
1866169611Sscottl#define MFI_SCSI_MAX_CDB_LEN	16
1867169611Sscottl
1868157114Sscottl#endif /* _MFIREG_H */
1869