mfireg.h revision 169611
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 */
26157114Sscottl
27157114Sscottl#ifndef _MFIREG_H
28157114Sscottl#define _MFIREG_H
29157114Sscottl
30157114Sscottl#include <sys/cdefs.h>
31157114Sscottl__FBSDID("$FreeBSD: head/sys/dev/mfi/mfireg.h 169611 2007-05-16 17:23:36Z scottl $");
32157114Sscottl
33157114Sscottl/*
34157114Sscottl * MegaRAID SAS MFI firmware definitions
35157114Sscottl *
36157114Sscottl * Calling this driver 'MegaRAID SAS' is a bit misleading.  It's a completely
37157114Sscottl * new firmware interface from the old AMI MegaRAID one, and there is no
38157114Sscottl * reason why this interface should be limited to just SAS.  In any case, LSI
39157114Sscottl * seems to also call this interface 'MFI', so that will be used here.
40157114Sscottl */
41157114Sscottl
42157114Sscottl/*
43157114Sscottl * Start with the register set.  All registers are 32 bits wide.
44157114Sscottl * The usual Intel IOP style setup.
45157114Sscottl */
46157114Sscottl#define MFI_IMSG0	0x10	/* Inbound message 0 */
47157114Sscottl#define MFI_IMSG1	0x14	/* Inbound message 1 */
48157114Sscottl#define MFI_OMSG0	0x18	/* Outbound message 0 */
49157114Sscottl#define MFI_OMSG1	0x1c	/* Outbound message 1 */
50157114Sscottl#define MFI_IDB		0x20	/* Inbound doorbell */
51157114Sscottl#define MFI_ISTS	0x24	/* Inbound interrupt status */
52157114Sscottl#define MFI_IMSK	0x28	/* Inbound interrupt mask */
53157114Sscottl#define MFI_ODB		0x2c	/* Outbound doorbell */
54157114Sscottl#define MFI_OSTS	0x30	/* Outbound interrupt status */
55157114Sscottl#define MFI_OMSK	0x34	/* Outbound interrupt mask */
56157114Sscottl#define MFI_IQP		0x40	/* Inbound queue port */
57157114Sscottl#define MFI_OQP		0x44	/* Outbound queue port */
58157114Sscottl
59157114Sscottl/* Bits for MFI_OSTS */
60157114Sscottl#define MFI_OSTS_INTR_VALID	0x00000002
61157114Sscottl
62157114Sscottl/*
63157114Sscottl * Firmware state values.  Found in OMSG0 during initialization.
64157114Sscottl */
65157114Sscottl#define MFI_FWSTATE_MASK		0xf0000000
66157114Sscottl#define MFI_FWSTATE_UNDEFINED		0x00000000
67157114Sscottl#define MFI_FWSTATE_BB_INIT		0x10000000
68157114Sscottl#define MFI_FWSTATE_FW_INIT		0x40000000
69157114Sscottl#define MFI_FWSTATE_WAIT_HANDSHAKE	0x60000000
70157114Sscottl#define MFI_FWSTATE_FW_INIT_2		0x70000000
71157114Sscottl#define MFI_FWSTATE_DEVICE_SCAN		0x80000000
72157114Sscottl#define MFI_FWSTATE_FLUSH_CACHE		0xa0000000
73157114Sscottl#define MFI_FWSTATE_READY		0xb0000000
74157114Sscottl#define MFI_FWSTATE_OPERATIONAL		0xc0000000
75157114Sscottl#define MFI_FWSTATE_FAULT		0xf0000000
76157114Sscottl#define MFI_FWSTATE_MAXSGL_MASK		0x00ff0000
77157114Sscottl#define MFI_FWSTATE_MAXCMD_MASK		0x0000ffff
78157114Sscottl
79157114Sscottl/*
80157114Sscottl * Control bits to drive the card to ready state.  These go into the IDB
81157114Sscottl * register.
82157114Sscottl */
83157114Sscottl#define MFI_FWINIT_ABORT	0x00000000 /* Abort all pending commands */
84157114Sscottl#define MFI_FWINIT_READY	0x00000002 /* Move from operational to ready */
85157114Sscottl#define MFI_FWINIT_MFIMODE	0x00000004 /* unknown */
86157114Sscottl#define MFI_FWINIT_CLEAR_HANDSHAKE 0x00000008 /* Respond to WAIT_HANDSHAKE */
87157114Sscottl
88157114Sscottl/* MFI Commands */
89157114Sscottltypedef enum {
90157114Sscottl	MFI_CMD_INIT =		0x00,
91157114Sscottl	MFI_CMD_LD_READ,
92157114Sscottl	MFI_CMD_LD_WRITE,
93157114Sscottl	MFI_CMD_LD_SCSI_IO,
94157114Sscottl	MFI_CMD_PD_SCSI_IO,
95157114Sscottl	MFI_CMD_DCMD,
96157114Sscottl	MFI_CMD_ABORT,
97157114Sscottl	MFI_CMD_SMP,
98157114Sscottl	MFI_CMD_STP
99157114Sscottl} mfi_cmd_t;
100157114Sscottl
101157114Sscottl/* Direct commands */
102157114Sscottltypedef enum {
103157114Sscottl	MFI_DCMD_CTRL_GETINFO =		0x01010000,
104163398Sscottl	MFI_DCMD_CTRL_MFC_DEFAULTS_GET =0x010e0201,
105163398Sscottl	MFI_DCMD_CTRL_MFC_DEFAULTS_SET =0x010e0202,
106157114Sscottl	MFI_DCMD_CTRL_FLUSHCACHE =	0x01101000,
107157114Sscottl	MFI_DCMD_CTRL_SHUTDOWN =	0x01050000,
108157114Sscottl	MFI_DCMD_CTRL_EVENT_GETINFO =	0x01040100,
109157114Sscottl	MFI_DCMD_CTRL_EVENT_GET =	0x01040300,
110157114Sscottl	MFI_DCMD_CTRL_EVENT_WAIT =	0x01040500,
111159811Sps	MFI_DCMD_LD_GET_LIST =		0x03010000,
112159811Sps	MFI_DCMD_LD_GET_INFO =		0x03020000,
113157114Sscottl	MFI_DCMD_LD_GET_PROP =		0x03030000,
114159811Sps	MFI_DCMD_LD_SET_PROP =		0x03040000,
115163398Sscottl	MFI_DCMD_CFG_READ =		0x04010000,
116163398Sscottl	MFI_DCMD_CFG_ADD =		0x04020000,
117163398Sscottl	MFI_DCMD_CFG_CLEAR =		0x04030000,
118157114Sscottl	MFI_DCMD_CLUSTER =		0x08000000,
119157114Sscottl	MFI_DCMD_CLUSTER_RESET_ALL =	0x08010100,
120157114Sscottl	MFI_DCMD_CLUSTER_RESET_LD =	0x08010200
121157114Sscottl} mfi_dcmd_t;
122157114Sscottl
123157114Sscottl/* Modifiers for MFI_DCMD_CTRL_FLUSHCACHE */
124157114Sscottl#define MFI_FLUSHCACHE_CTRL	0x01
125157114Sscottl#define MFI_FLUSHCACHE_DISK	0x02
126157114Sscottl
127157114Sscottl/* Modifiers for MFI_DCMD_CTRL_SHUTDOWN */
128157114Sscottl#define MFI_SHUTDOWN_SPINDOWN	0x01
129157114Sscottl
130157114Sscottl/*
131158737Sambrisko * MFI Frame flags
132157114Sscottl */
133157114Sscottl#define MFI_FRAME_POST_IN_REPLY_QUEUE		0x0000
134157114Sscottl#define MFI_FRAME_DONT_POST_IN_REPLY_QUEUE	0x0001
135157114Sscottl#define MFI_FRAME_SGL32				0x0000
136157114Sscottl#define MFI_FRAME_SGL64				0x0002
137157114Sscottl#define MFI_FRAME_SENSE32			0x0000
138157114Sscottl#define MFI_FRAME_SENSE64			0x0004
139157114Sscottl#define MFI_FRAME_DIR_NONE			0x0000
140157114Sscottl#define MFI_FRAME_DIR_WRITE			0x0008
141157114Sscottl#define MFI_FRAME_DIR_READ			0x0010
142157114Sscottl#define MFI_FRAME_DIR_BOTH			0x0018
143157114Sscottl
144157114Sscottl/* MFI Status codes */
145157114Sscottltypedef enum {
146157114Sscottl	MFI_STAT_OK =			0x00,
147157114Sscottl	MFI_STAT_INVALID_CMD,
148157114Sscottl	MFI_STAT_INVALID_DCMD,
149157114Sscottl	MFI_STAT_INVALID_PARAMETER,
150157114Sscottl	MFI_STAT_INVALID_SEQUENCE_NUMBER,
151157114Sscottl	MFI_STAT_ABORT_NOT_POSSIBLE,
152157114Sscottl	MFI_STAT_APP_HOST_CODE_NOT_FOUND,
153157114Sscottl	MFI_STAT_APP_IN_USE,
154157114Sscottl	MFI_STAT_APP_NOT_INITIALIZED,
155157114Sscottl	MFI_STAT_ARRAY_INDEX_INVALID,
156157114Sscottl	MFI_STAT_ARRAY_ROW_NOT_EMPTY,
157157114Sscottl	MFI_STAT_CONFIG_RESOURCE_CONFLICT,
158157114Sscottl	MFI_STAT_DEVICE_NOT_FOUND,
159157114Sscottl	MFI_STAT_DRIVE_TOO_SMALL,
160157114Sscottl	MFI_STAT_FLASH_ALLOC_FAIL,
161157114Sscottl	MFI_STAT_FLASH_BUSY,
162157114Sscottl	MFI_STAT_FLASH_ERROR =		0x10,
163157114Sscottl	MFI_STAT_FLASH_IMAGE_BAD,
164157114Sscottl	MFI_STAT_FLASH_IMAGE_INCOMPLETE,
165157114Sscottl	MFI_STAT_FLASH_NOT_OPEN,
166157114Sscottl	MFI_STAT_FLASH_NOT_STARTED,
167157114Sscottl	MFI_STAT_FLUSH_FAILED,
168157114Sscottl	MFI_STAT_HOST_CODE_NOT_FOUNT,
169157114Sscottl	MFI_STAT_LD_CC_IN_PROGRESS,
170157114Sscottl	MFI_STAT_LD_INIT_IN_PROGRESS,
171157114Sscottl	MFI_STAT_LD_LBA_OUT_OF_RANGE,
172157114Sscottl	MFI_STAT_LD_MAX_CONFIGURED,
173157114Sscottl	MFI_STAT_LD_NOT_OPTIMAL,
174157114Sscottl	MFI_STAT_LD_RBLD_IN_PROGRESS,
175157114Sscottl	MFI_STAT_LD_RECON_IN_PROGRESS,
176157114Sscottl	MFI_STAT_LD_WRONG_RAID_LEVEL,
177157114Sscottl	MFI_STAT_MAX_SPARES_EXCEEDED,
178157114Sscottl	MFI_STAT_MEMORY_NOT_AVAILABLE =	0x20,
179157114Sscottl	MFI_STAT_MFC_HW_ERROR,
180157114Sscottl	MFI_STAT_NO_HW_PRESENT,
181157114Sscottl	MFI_STAT_NOT_FOUND,
182157114Sscottl	MFI_STAT_NOT_IN_ENCL,
183157114Sscottl	MFI_STAT_PD_CLEAR_IN_PROGRESS,
184157114Sscottl	MFI_STAT_PD_TYPE_WRONG,
185157114Sscottl	MFI_STAT_PR_DISABLED,
186157114Sscottl	MFI_STAT_ROW_INDEX_INVALID,
187157114Sscottl	MFI_STAT_SAS_CONFIG_INVALID_ACTION,
188157114Sscottl	MFI_STAT_SAS_CONFIG_INVALID_DATA,
189157114Sscottl	MFI_STAT_SAS_CONFIG_INVALID_PAGE,
190157114Sscottl	MFI_STAT_SAS_CONFIG_INVALID_TYPE,
191157114Sscottl	MFI_STAT_SCSI_DONE_WITH_ERROR,
192157114Sscottl	MFI_STAT_SCSI_IO_FAILED,
193157114Sscottl	MFI_STAT_SCSI_RESERVATION_CONFLICT,
194157114Sscottl	MFI_STAT_SHUTDOWN_FAILED =	0x30,
195157114Sscottl	MFI_STAT_TIME_NOT_SET,
196157114Sscottl	MFI_STAT_WRONG_STATE,
197157114Sscottl	MFI_STAT_LD_OFFLINE,
198157114Sscottl	MFI_STAT_PEER_NOTIFICATION_REJECTED,
199157114Sscottl	MFI_STAT_PEER_NOTIFICATION_FAILED,
200157114Sscottl	MFI_STAT_RESERVATION_IN_PROGRESS,
201157114Sscottl	MFI_STAT_I2C_ERRORS_DETECTED,
202157114Sscottl	MFI_STAT_PCI_ERRORS_DETECTED,
203157114Sscottl	MFI_STAT_INVALID_STATUS =	0xFF
204157114Sscottl} mfi_status_t;
205157114Sscottl
206157114Sscottltypedef enum {
207157114Sscottl	MFI_EVT_CLASS_DEBUG =		-2,
208157114Sscottl	MFI_EVT_CLASS_PROGRESS =	-1,
209157114Sscottl	MFI_EVT_CLASS_INFO =		0,
210157114Sscottl	MFI_EVT_CLASS_WARNING =		1,
211157114Sscottl	MFI_EVT_CLASS_CRITICAL =	2,
212157114Sscottl	MFI_EVT_CLASS_FATAL =		3,
213157114Sscottl	MFI_EVT_CLASS_DEAD =		4
214157114Sscottl} mfi_evt_class_t;
215157114Sscottl
216157114Sscottltypedef enum {
217157114Sscottl	MFI_EVT_LOCALE_LD =		0x0001,
218157114Sscottl	MFI_EVT_LOCALE_PD =		0x0002,
219157114Sscottl	MFI_EVT_LOCALE_ENCL =		0x0004,
220157114Sscottl	MFI_EVT_LOCALE_BBU =		0x0008,
221157114Sscottl	MFI_EVT_LOCALE_SAS =		0x0010,
222157114Sscottl	MFI_EVT_LOCALE_CTRL =		0x0020,
223157114Sscottl	MFI_EVT_LOCALE_CONFIG =		0x0040,
224157114Sscottl	MFI_EVT_LOCALE_CLUSTER =	0x0080,
225157114Sscottl	MFI_EVT_LOCALE_ALL =		0xffff
226157114Sscottl} mfi_evt_locale_t;
227157114Sscottl
228157114Sscottltypedef enum {
229158737Sambrisko	MR_EVT_ARGS_NONE =		0x00,
230158737Sambrisko	MR_EVT_ARGS_CDB_SENSE,
231158737Sambrisko	MR_EVT_ARGS_LD,
232158737Sambrisko	MR_EVT_ARGS_LD_COUNT,
233158737Sambrisko	MR_EVT_ARGS_LD_LBA,
234158737Sambrisko	MR_EVT_ARGS_LD_OWNER,
235158737Sambrisko	MR_EVT_ARGS_LD_LBA_PD_LBA,
236158737Sambrisko	MR_EVT_ARGS_LD_PROG,
237158737Sambrisko	MR_EVT_ARGS_LD_STATE,
238158737Sambrisko	MR_EVT_ARGS_LD_STRIP,
239158737Sambrisko	MR_EVT_ARGS_PD,
240158737Sambrisko	MR_EVT_ARGS_PD_ERR,
241158737Sambrisko	MR_EVT_ARGS_PD_LBA,
242158737Sambrisko	MR_EVT_ARGS_PD_LBA_LD,
243158737Sambrisko	MR_EVT_ARGS_PD_PROG,
244158737Sambrisko	MR_EVT_ARGS_PD_STATE,
245158737Sambrisko	MR_EVT_ARGS_PCI,
246158737Sambrisko	MR_EVT_ARGS_RATE,
247158737Sambrisko	MR_EVT_ARGS_STR,
248158737Sambrisko	MR_EVT_ARGS_TIME,
249158737Sambrisko	MR_EVT_ARGS_ECC
250157114Sscottl} mfi_evt_args;
251157114Sscottl
252163398Sscottltypedef enum {
253163398Sscottl	MR_LD_CACHE_WRITE_BACK =	0x01,
254163398Sscottl	MR_LD_CACHE_WRITE_ADAPTIVE =	0x02,
255163398Sscottl	MR_LD_CACHE_READ_AHEAD =	0x04,
256163398Sscottl	MR_LD_CACHE_READ_ADAPTIVE =	0x08,
257163398Sscottl	MR_LD_CACHE_WRITE_CACHE_BAD_BBU=0x10,
258163398Sscottl	MR_LD_CACHE_ALLOW_WRITE_CACHE =	0x20,
259163398Sscottl	MR_LD_CACHE_ALLOW_READ_CACHE =	0x40
260163398Sscottl} mfi_ld_cache;
261163398Sscottl
262163398Sscottltypedef enum {
263163398Sscottl	MR_PD_CACHE_UNCHANGED  =	0,
264163398Sscottl	MR_PD_CACHE_ENABLE =		1,
265163398Sscottl	MR_PD_CACHE_DISABLE =		2
266163398Sscottl} mfi_pd_cache;
267163398Sscottl
268157114Sscottl/*
269157114Sscottl * Other propertities and definitions
270157114Sscottl */
271157114Sscottl#define MFI_MAX_PD_CHANNELS	2
272157114Sscottl#define MFI_MAX_LD_CHANNELS	2
273157114Sscottl#define MFI_MAX_CHANNELS	(MFI_MAX_PD_CHANNELS + MFI_MAX_LD_CHANNELS)
274157114Sscottl#define MFI_MAX_CHANNEL_DEVS	128
275157114Sscottl#define MFI_DEFAULT_ID		-1
276157114Sscottl#define MFI_MAX_LUN		8
277157114Sscottl#define MFI_MAX_LD		64
278157114Sscottl
279157114Sscottl#define MFI_FRAME_SIZE		64
280157114Sscottl#define MFI_MBOX_SIZE		12
281157114Sscottl
282165225Sambrisko/* Firmware flashing can take 40s */
283165225Sambrisko#define MFI_POLL_TIMEOUT_SECS	50
284157114Sscottl
285157114Sscottl/* Allow for speedier math calculations */
286157114Sscottl#define MFI_SECTOR_LEN		512
287157114Sscottl
288157114Sscottl/* Scatter Gather elements */
289157114Sscottlstruct mfi_sg32 {
290157114Sscottl	uint32_t	addr;
291157114Sscottl	uint32_t	len;
292157114Sscottl} __packed;
293157114Sscottl
294157114Sscottlstruct mfi_sg64 {
295157114Sscottl	uint64_t	addr;
296157114Sscottl	uint32_t	len;
297157114Sscottl} __packed;
298157114Sscottl
299157114Sscottlunion mfi_sgl {
300157114Sscottl	struct mfi_sg32	sg32[1];
301157114Sscottl	struct mfi_sg64	sg64[1];
302157114Sscottl} __packed;
303157114Sscottl
304157114Sscottl/* Message frames.  All messages have a common header */
305157114Sscottlstruct mfi_frame_header {
306157114Sscottl	uint8_t		cmd;
307157114Sscottl	uint8_t		sense_len;
308157114Sscottl	uint8_t		cmd_status;
309157114Sscottl	uint8_t		scsi_status;
310157114Sscottl	uint8_t		target_id;
311157114Sscottl	uint8_t		lun_id;
312157114Sscottl	uint8_t		cdb_len;
313157114Sscottl	uint8_t		sg_count;
314157114Sscottl	uint32_t	context;
315157114Sscottl	uint32_t	pad0;
316157114Sscottl	uint16_t	flags;
317157114Sscottl	uint16_t	timeout;
318157114Sscottl	uint32_t	data_len;
319157114Sscottl} __packed;
320157114Sscottl
321157114Sscottlstruct mfi_init_frame {
322157114Sscottl	struct mfi_frame_header	header;
323157114Sscottl	uint32_t	qinfo_new_addr_lo;
324157114Sscottl	uint32_t	qinfo_new_addr_hi;
325157114Sscottl	uint32_t	qinfo_old_addr_lo;
326157114Sscottl	uint32_t	qinfo_old_addr_hi;
327157114Sscottl	uint32_t	reserved[6];
328157114Sscottl} __packed;
329157114Sscottl
330157114Sscottl#define MFI_IO_FRAME_SIZE 40
331157114Sscottlstruct mfi_io_frame {
332157114Sscottl	struct mfi_frame_header	header;
333157114Sscottl	uint32_t	sense_addr_lo;
334157114Sscottl	uint32_t	sense_addr_hi;
335157114Sscottl	uint32_t	lba_lo;
336157114Sscottl	uint32_t	lba_hi;
337157114Sscottl	union mfi_sgl	sgl;
338157114Sscottl} __packed;
339157114Sscottl
340157114Sscottl#define MFI_PASS_FRAME_SIZE 48
341157114Sscottlstruct mfi_pass_frame {
342157114Sscottl	struct mfi_frame_header header;
343157114Sscottl	uint32_t	sense_addr_lo;
344157114Sscottl	uint32_t	sense_addr_hi;
345157114Sscottl	uint8_t		cdb[16];
346157114Sscottl	union mfi_sgl	sgl;
347157114Sscottl} __packed;
348157114Sscottl
349157114Sscottl#define MFI_DCMD_FRAME_SIZE 40
350157114Sscottlstruct mfi_dcmd_frame {
351157114Sscottl	struct mfi_frame_header header;
352157114Sscottl	uint32_t	opcode;
353157114Sscottl	uint8_t		mbox[MFI_MBOX_SIZE];
354157114Sscottl	union mfi_sgl	sgl;
355157114Sscottl} __packed;
356157114Sscottl
357157114Sscottlstruct mfi_abort_frame {
358157114Sscottl	struct mfi_frame_header header;
359157114Sscottl	uint32_t	abort_context;
360157114Sscottl	uint32_t	pad;
361157114Sscottl	uint32_t	abort_mfi_addr_lo;
362157114Sscottl	uint32_t	abort_mfi_addr_hi;
363157114Sscottl	uint32_t	reserved[6];
364157114Sscottl} __packed;
365157114Sscottl
366157114Sscottlstruct mfi_smp_frame {
367157114Sscottl	struct mfi_frame_header header;
368157114Sscottl	uint64_t	sas_addr;
369157114Sscottl	union {
370157114Sscottl		struct mfi_sg32 sg32[2];
371157114Sscottl		struct mfi_sg64 sg64[2];
372157114Sscottl	} sgl;
373157114Sscottl} __packed;
374157114Sscottl
375157114Sscottlstruct mfi_stp_frame {
376157114Sscottl	struct mfi_frame_header header;
377157114Sscottl	uint16_t	fis[10];
378157114Sscottl	uint32_t	stp_flags;
379157114Sscottl	union {
380157114Sscottl		struct mfi_sg32 sg32[2];
381157114Sscottl		struct mfi_sg64 sg64[2];
382157114Sscottl	} sgl;
383157114Sscottl} __packed;
384157114Sscottl
385157114Sscottlunion mfi_frame {
386157114Sscottl	struct mfi_frame_header header;
387157114Sscottl	struct mfi_init_frame	init;
388157114Sscottl	struct mfi_io_frame	io;
389157114Sscottl	struct mfi_pass_frame	pass;
390157114Sscottl	struct mfi_dcmd_frame	dcmd;
391157114Sscottl	struct mfi_abort_frame	abort;
392157114Sscottl	struct mfi_smp_frame	smp;
393157114Sscottl	struct mfi_stp_frame	stp;
394157114Sscottl	uint8_t			bytes[MFI_FRAME_SIZE];
395157114Sscottl};
396157114Sscottl
397157114Sscottl#define MFI_SENSE_LEN 128
398157114Sscottlstruct mfi_sense {
399157114Sscottl	uint8_t		data[MFI_SENSE_LEN];
400157114Sscottl};
401157114Sscottl
402157114Sscottl/* The queue init structure that is passed with the init message */
403157114Sscottlstruct mfi_init_qinfo {
404157114Sscottl	uint32_t	flags;
405157114Sscottl	uint32_t	rq_entries;
406157114Sscottl	uint32_t	rq_addr_lo;
407157114Sscottl	uint32_t	rq_addr_hi;
408157114Sscottl	uint32_t	pi_addr_lo;
409157114Sscottl	uint32_t	pi_addr_hi;
410157114Sscottl	uint32_t	ci_addr_lo;
411157114Sscottl	uint32_t	ci_addr_hi;
412157114Sscottl} __packed;
413157114Sscottl
414157114Sscottl/* SAS (?) controller properties, part of mfi_ctrl_info */
415157114Sscottlstruct mfi_ctrl_props {
416157114Sscottl	uint16_t	seq_num;
417157114Sscottl	uint16_t	pred_fail_poll_interval;
418157114Sscottl	uint16_t	intr_throttle_cnt;
419157114Sscottl	uint16_t	intr_throttle_timeout;
420157114Sscottl	uint8_t		rebuild_rate;
421157114Sscottl	uint8_t		patrol_read_rate;
422157114Sscottl	uint8_t		bgi_rate;
423157114Sscottl	uint8_t		cc_rate;
424157114Sscottl	uint8_t		recon_rate;
425157114Sscottl	uint8_t		cache_flush_interval;
426157114Sscottl	uint8_t		spinup_drv_cnt;
427157114Sscottl	uint8_t		spinup_delay;
428157114Sscottl	uint8_t		cluster_enable;
429157114Sscottl	uint8_t		coercion_mode;
430157114Sscottl	uint8_t		alarm_enable;
431157114Sscottl	uint8_t		disable_auto_rebuild;
432157114Sscottl	uint8_t		disable_battery_warn;
433157114Sscottl	uint8_t		ecc_bucket_size;
434157114Sscottl	uint16_t	ecc_bucket_leak_rate;
435157114Sscottl	uint8_t		restore_hotspare_on_insertion;
436157114Sscottl	uint8_t		expose_encl_devices;
437157114Sscottl	uint8_t		reserved[38];
438157114Sscottl} __packed;
439157114Sscottl
440157114Sscottl/* PCI information about the card. */
441157114Sscottlstruct mfi_info_pci {
442157114Sscottl	uint16_t	vendor;
443157114Sscottl	uint16_t	device;
444157114Sscottl	uint16_t	subvendor;
445157114Sscottl	uint16_t	subdevice;
446157114Sscottl	uint8_t		reserved[24];
447157114Sscottl} __packed;
448157114Sscottl
449157114Sscottl/* Host (front end) interface information */
450157114Sscottlstruct mfi_info_host {
451157114Sscottl	uint8_t		type;
452157114Sscottl#define MFI_INFO_HOST_PCIX	0x01
453157114Sscottl#define MFI_INFO_HOST_PCIE	0x02
454157114Sscottl#define MFI_INFO_HOST_ISCSI	0x04
455157114Sscottl#define MFI_INFO_HOST_SAS3G	0x08
456157114Sscottl	uint8_t		reserved[6];
457157114Sscottl	uint8_t		port_count;
458157114Sscottl	uint64_t	port_addr[8];
459157114Sscottl} __packed;
460157114Sscottl
461157114Sscottl/* Device (back end) interface information */
462157114Sscottlstruct mfi_info_device {
463157114Sscottl	uint8_t		type;
464157114Sscottl#define MFI_INFO_DEV_SPI	0x01
465157114Sscottl#define MFI_INFO_DEV_SAS3G	0x02
466157114Sscottl#define MFI_INFO_DEV_SATA1	0x04
467157114Sscottl#define MFI_INFO_DEV_SATA3G	0x08
468157114Sscottl	uint8_t		reserved[6];
469157114Sscottl	uint8_t		port_count;
470157114Sscottl	uint64_t	port_addr[8];
471157114Sscottl} __packed;
472157114Sscottl
473157114Sscottl/* Firmware component information */
474157114Sscottlstruct mfi_info_component {
475157114Sscottl	char		 name[8];
476157114Sscottl	char		 version[32];
477157114Sscottl	char		 build_date[16];
478157114Sscottl	char		 build_time[16];
479157114Sscottl} __packed;
480157114Sscottl
481163398Sscottl/* Controller default settings */
482163398Sscottlstruct mfi_defaults {
483163398Sscottl	uint64_t	sas_addr;
484163398Sscottl	uint8_t		phy_polarity;
485163398Sscottl	uint8_t		background_rate;
486163398Sscottl	uint8_t		stripe_size;
487163398Sscottl	uint8_t		flush_time;
488163398Sscottl	uint8_t		write_back;
489163398Sscottl	uint8_t		read_ahead;
490163398Sscottl	uint8_t		cache_when_bbu_bad;
491163398Sscottl	uint8_t		cached_io;
492163398Sscottl	uint8_t		smart_mode;
493163398Sscottl	uint8_t		alarm_disable;
494163398Sscottl	uint8_t		coercion;
495163398Sscottl	uint8_t		zrc_config;
496163398Sscottl	uint8_t		dirty_led_shows_drive_activity;
497163398Sscottl	uint8_t		bios_continue_on_error;
498163398Sscottl	uint8_t		spindown_mode;
499163398Sscottl	uint8_t		allowed_device_types;
500163398Sscottl	uint8_t		allow_mix_in_enclosure;
501163398Sscottl	uint8_t		allow_mix_in_ld;
502163398Sscottl	uint8_t		allow_sata_in_cluster;
503163398Sscottl	uint8_t		max_chained_enclosures;
504163398Sscottl	uint8_t		disable_ctrl_r;
505163398Sscottl	uint8_t		enabel_web_bios;
506163398Sscottl	uint8_t		phy_polarity_split;
507163398Sscottl	uint8_t		direct_pd_mapping;
508163398Sscottl	uint8_t		bios_enumerate_lds;
509163398Sscottl	uint8_t		restored_hot_spare_on_insertion;
510163398Sscottl	uint8_t		expose_enclosure_devices;
511163398Sscottl	uint8_t		maintain_pd_fail_history;
512163398Sscottl	uint8_t		resv[28];
513163398Sscottl} __packed;
514157114Sscottl
515163398Sscottl/* Controller default settings */
516163398Sscottlstruct mfi_bios_data {
517163398Sscottl	uint16_t	boot_target_id;
518163398Sscottl	uint8_t		do_not_int_13;
519163398Sscottl	uint8_t		continue_on_error;
520163398Sscottl	uint8_t		verbose;
521163398Sscottl	uint8_t		geometry;
522163398Sscottl	uint8_t		expose_all_drives;
523163398Sscottl	uint8_t		reserved[56];
524163398Sscottl	uint8_t		check_sum;
525163398Sscottl} __packed;
526163398Sscottl
527157114Sscottl/* SAS (?) controller info, returned from MFI_DCMD_CTRL_GETINFO. */
528157114Sscottlstruct mfi_ctrl_info {
529157114Sscottl	struct mfi_info_pci	pci;
530157114Sscottl	struct mfi_info_host	host;
531157114Sscottl	struct mfi_info_device	device;
532157114Sscottl
533157114Sscottl	/* Firmware components that are present and active. */
534157114Sscottl	uint32_t		image_check_word;
535157114Sscottl	uint32_t		image_component_count;
536157114Sscottl	struct mfi_info_component image_component[8];
537157114Sscottl
538157114Sscottl	/* Firmware components that have been flashed but are inactive */
539157114Sscottl	uint32_t		pending_image_component_count;
540157114Sscottl	struct mfi_info_component pending_image_component[8];
541157114Sscottl
542157114Sscottl	uint8_t			max_arms;
543157114Sscottl	uint8_t			max_spans;
544157114Sscottl	uint8_t			max_arrays;
545157114Sscottl	uint8_t			max_lds;
546157114Sscottl	char			product_name[80];
547157114Sscottl	char			serial_number[32];
548157114Sscottl	uint32_t		hw_present;
549157114Sscottl#define MFI_INFO_HW_BBU		0x01
550157114Sscottl#define MFI_INFO_HW_ALARM	0x02
551157114Sscottl#define MFI_INFO_HW_NVRAM	0x04
552157114Sscottl#define MFI_INFO_HW_UART	0x08
553157114Sscottl	uint32_t		current_fw_time;
554157114Sscottl	uint16_t		max_cmds;
555157114Sscottl	uint16_t		max_sg_elements;
556157114Sscottl	uint32_t		max_request_size;
557157114Sscottl	uint16_t		lds_present;
558157114Sscottl	uint16_t		lds_degraded;
559157114Sscottl	uint16_t		lds_offline;
560157114Sscottl	uint16_t		pd_present;
561157114Sscottl	uint16_t		pd_disks_present;
562157114Sscottl	uint16_t		pd_disks_pred_failure;
563157114Sscottl	uint16_t		pd_disks_failed;
564157114Sscottl	uint16_t		nvram_size;
565157114Sscottl	uint16_t		memory_size;
566157114Sscottl	uint16_t		flash_size;
567157114Sscottl	uint16_t		ram_correctable_errors;
568157114Sscottl	uint16_t		ram_uncorrectable_errors;
569157114Sscottl	uint8_t			cluster_allowed;
570157114Sscottl	uint8_t			cluster_active;
571157114Sscottl	uint16_t		max_strips_per_io;
572157114Sscottl
573157114Sscottl	uint32_t		raid_levels;
574157114Sscottl#define MFI_INFO_RAID_0		0x01
575157114Sscottl#define MFI_INFO_RAID_1		0x02
576157114Sscottl#define MFI_INFO_RAID_5		0x04
577157114Sscottl#define MFI_INFO_RAID_1E	0x08
578157114Sscottl#define MFI_INFO_RAID_6		0x10
579157114Sscottl
580157114Sscottl	uint32_t		adapter_ops;
581158737Sambrisko#define MFI_INFO_AOPS_RBLD_RATE		0x0001
582157114Sscottl#define MFI_INFO_AOPS_CC_RATE		0x0002
583157114Sscottl#define MFI_INFO_AOPS_BGI_RATE		0x0004
584157114Sscottl#define MFI_INFO_AOPS_RECON_RATE	0x0008
585157114Sscottl#define MFI_INFO_AOPS_PATROL_RATE	0x0010
586157114Sscottl#define MFI_INFO_AOPS_ALARM_CONTROL	0x0020
587157114Sscottl#define MFI_INFO_AOPS_CLUSTER_SUPPORTED	0x0040
588157114Sscottl#define MFI_INFO_AOPS_BBU		0x0080
589157114Sscottl#define MFI_INFO_AOPS_SPANNING_ALLOWED	0x0100
590157114Sscottl#define MFI_INFO_AOPS_DEDICATED_SPARES	0x0200
591157114Sscottl#define MFI_INFO_AOPS_REVERTIBLE_SPARES	0x0400
592157114Sscottl#define MFI_INFO_AOPS_FOREIGN_IMPORT	0x0800
593157114Sscottl#define MFI_INFO_AOPS_SELF_DIAGNOSTIC	0x1000
594157114Sscottl#define MFI_INFO_AOPS_MIXED_ARRAY	0x2000
595157114Sscottl#define MFI_INFO_AOPS_GLOBAL_SPARES	0x4000
596157114Sscottl
597157114Sscottl	uint32_t		ld_ops;
598157114Sscottl#define MFI_INFO_LDOPS_READ_POLICY	0x01
599157114Sscottl#define MFI_INFO_LDOPS_WRITE_POLICY	0x02
600157114Sscottl#define MFI_INFO_LDOPS_IO_POLICY	0x04
601157114Sscottl#define MFI_INFO_LDOPS_ACCESS_POLICY	0x08
602157114Sscottl#define MFI_INFO_LDOPS_DISK_CACHE_POLICY 0x10
603157114Sscottl
604157114Sscottl	struct {
605157114Sscottl		uint8_t		min;
606157114Sscottl		uint8_t		max;
607157114Sscottl		uint8_t		reserved[2];
608157114Sscottl	} __packed stripe_sz_ops;
609157114Sscottl
610157114Sscottl	uint32_t		pd_ops;
611157114Sscottl#define MFI_INFO_PDOPS_FORCE_ONLINE	0x01
612157114Sscottl#define MFI_INFO_PDOPS_FORCE_OFFLINE	0x02
613157114Sscottl#define MFI_INFO_PDOPS_FORCE_REBUILD	0x04
614157114Sscottl
615157114Sscottl	uint32_t		pd_mix_support;
616157114Sscottl#define MFI_INFO_PDMIX_SAS		0x01
617157114Sscottl#define MFI_INFO_PDMIX_SATA		0x02
618157114Sscottl#define MFI_INFO_PDMIX_ENCL		0x04
619157114Sscottl#define MFI_INFO_PDMIX_LD		0x08
620157114Sscottl#define MFI_INFO_PDMIX_SATA_CLUSTER	0x10
621157114Sscottl
622157114Sscottl	uint8_t			ecc_bucket_count;
623157114Sscottl	uint8_t			reserved2[11];
624157114Sscottl	struct mfi_ctrl_props	properties;
625157114Sscottl	char			package_version[0x60];
626157114Sscottl	uint8_t			pad[0x800 - 0x6a0];
627157114Sscottl} __packed;
628157114Sscottl
629158737Sambrisko/* keep track of an event. */
630158737Sambriskounion mfi_evt {
631158737Sambrisko	struct {
632158737Sambrisko		uint16_t	locale;
633158737Sambrisko		uint8_t		reserved;
634162122Sambrisko		int8_t		class;
635158737Sambrisko	} members;
636158737Sambrisko	uint32_t		word;
637158737Sambrisko} __packed;
638158737Sambrisko
639158737Sambrisko/* event log state. */
640158737Sambriskostruct mfi_evt_log_state {
641158737Sambrisko	uint32_t		newest_seq_num;
642158737Sambrisko	uint32_t		oldest_seq_num;
643158737Sambrisko	uint32_t		clear_seq_num;
644158737Sambrisko	uint32_t		shutdown_seq_num;
645158737Sambrisko	uint32_t		boot_seq_num;
646158737Sambrisko} __packed;
647158737Sambrisko
648158737Sambriskostruct mfi_progress {
649158737Sambrisko	uint16_t		progress;
650158737Sambrisko	uint16_t		elapsed_seconds;
651158737Sambrisko} __packed;
652158737Sambrisko
653158737Sambriskostruct mfi_evt_ld {
654158737Sambrisko	uint16_t		target_id;
655158737Sambrisko	uint8_t			ld_index;
656158737Sambrisko	uint8_t			reserved;
657158737Sambrisko} __packed;
658158737Sambrisko
659158737Sambriskostruct mfi_evt_pd {
660158737Sambrisko	uint16_t		device_id;
661158737Sambrisko	uint8_t			enclosure_index;
662158737Sambrisko	uint8_t			slot_number;
663158737Sambrisko} __packed;
664158737Sambrisko
665158737Sambrisko/* SAS (?) event detail, returned from MFI_DCMD_CTRL_EVENT_WAIT. */
666158737Sambriskostruct mfi_evt_detail {
667158737Sambrisko	uint32_t		seq;
668158737Sambrisko	uint32_t		time;
669158737Sambrisko	uint32_t		code;
670158737Sambrisko	union mfi_evt		class;
671158737Sambrisko	uint8_t			arg_type;
672158737Sambrisko	uint8_t			reserved1[15];
673158737Sambrisko
674158737Sambrisko	union {
675158737Sambrisko		struct {
676158737Sambrisko			struct mfi_evt_pd	pd;
677158737Sambrisko			uint8_t			cdb_len;
678158737Sambrisko			uint8_t			sense_len;
679158737Sambrisko			uint8_t			reserved[2];
680158737Sambrisko			uint8_t			cdb[16];
681158737Sambrisko			uint8_t			sense[64];
682158737Sambrisko		} cdb_sense;
683158737Sambrisko
684158737Sambrisko		struct mfi_evt_ld		ld;
685158737Sambrisko
686158737Sambrisko		struct {
687158737Sambrisko			struct mfi_evt_ld	ld;
688158737Sambrisko			uint64_t		count;
689158737Sambrisko		} ld_count;
690158737Sambrisko
691158737Sambrisko		struct {
692158737Sambrisko			uint64_t		lba;
693158737Sambrisko			struct mfi_evt_ld	ld;
694158737Sambrisko		} ld_lba;
695158737Sambrisko
696158737Sambrisko		struct {
697158737Sambrisko			struct mfi_evt_ld	ld;
698158737Sambrisko			uint32_t		pre_owner;
699158737Sambrisko			uint32_t		new_owner;
700158737Sambrisko		} ld_owner;
701158737Sambrisko
702158737Sambrisko		struct {
703158737Sambrisko			uint64_t		ld_lba;
704158737Sambrisko			uint64_t		pd_lba;
705158737Sambrisko			struct mfi_evt_ld	ld;
706158737Sambrisko			struct mfi_evt_pd	pd;
707158737Sambrisko		} ld_lba_pd_lba;
708158737Sambrisko
709158737Sambrisko		struct {
710158737Sambrisko			struct mfi_evt_ld	ld;
711158737Sambrisko			struct mfi_progress	prog;
712158737Sambrisko		} ld_prog;
713158737Sambrisko
714158737Sambrisko		struct {
715158737Sambrisko			struct mfi_evt_ld	ld;
716158737Sambrisko			uint32_t		prev_state;
717158737Sambrisko			uint32_t		new_state;
718158737Sambrisko		} ld_state;
719158737Sambrisko
720158737Sambrisko		struct {
721158737Sambrisko			uint64_t		strip;
722158737Sambrisko			struct mfi_evt_ld	ld;
723158737Sambrisko		} ld_strip;
724158737Sambrisko
725158737Sambrisko		struct mfi_evt_pd		pd;
726158737Sambrisko
727158737Sambrisko		struct {
728158737Sambrisko			struct mfi_evt_pd	pd;
729158737Sambrisko			uint32_t		err;
730158737Sambrisko		} pd_err;
731158737Sambrisko
732158737Sambrisko		struct {
733158737Sambrisko			uint64_t		lba;
734158737Sambrisko			struct mfi_evt_pd	pd;
735158737Sambrisko		} pd_lba;
736158737Sambrisko
737158737Sambrisko		struct {
738158737Sambrisko			uint64_t		lba;
739158737Sambrisko			struct mfi_evt_pd	pd;
740158737Sambrisko			struct mfi_evt_ld	ld;
741158737Sambrisko		} pd_lba_ld;
742158737Sambrisko
743158737Sambrisko		struct {
744158737Sambrisko			struct mfi_evt_pd	pd;
745158737Sambrisko			struct mfi_progress	prog;
746158737Sambrisko		} pd_prog;
747158737Sambrisko
748158737Sambrisko		struct {
749158737Sambrisko			struct mfi_evt_pd	ld;
750158737Sambrisko			uint32_t		prev_state;
751158737Sambrisko			uint32_t		new_state;
752158737Sambrisko		} pd_state;
753158737Sambrisko
754158737Sambrisko		struct {
755158737Sambrisko			uint16_t		venderId;
756158737Sambrisko			uint16_t		deviceId;
757158737Sambrisko			uint16_t		subVenderId;
758158737Sambrisko			uint16_t		subDeviceId;
759158737Sambrisko		} pci;
760158737Sambrisko
761158737Sambrisko		uint32_t			rate;
762158737Sambrisko
763158737Sambrisko		char				str[96];
764158737Sambrisko
765158737Sambrisko		struct {
766158737Sambrisko			uint32_t		rtc;
767158737Sambrisko			uint16_t		elapsedSeconds;
768158737Sambrisko		} time;
769158737Sambrisko
770158737Sambrisko		struct {
771158737Sambrisko			uint32_t		ecar;
772158737Sambrisko			uint32_t		elog;
773158737Sambrisko			char			str[64];
774158737Sambrisko		} ecc;
775158737Sambrisko
776158737Sambrisko		uint8_t		b[96];
777158737Sambrisko		uint16_t	s[48];
778158737Sambrisko		uint32_t	w[24];
779158737Sambrisko		uint64_t	d[12];
780158737Sambrisko	} args;
781158737Sambrisko
782158737Sambrisko	char description[128];
783158737Sambrisko} __packed;
784158737Sambrisko
785162118Sambriskostruct mfi_evt_list {
786162118Sambrisko	uint32_t		count;
787162118Sambrisko	uint32_t		reserved;
788162118Sambrisko	struct mfi_evt_detail	event[1];
789158737Sambrisko} __packed;
790158737Sambrisko
791163398Sscottlunion mfi_pd_ref {
792163398Sscottl	struct {
793163398Sscottl		uint16_t	device_id;
794163398Sscottl		uint16_t	seq_num;
795163398Sscottl	} v;
796163398Sscottl	uint32_t	ref;
797159811Sps} __packed;
798159811Sps
799163398Sscottlunion mfi_pd_ddf_type {
800163398Sscottl	struct {
801163398Sscottl		union {
802163398Sscottl			struct {
803163398Sscottl				uint16_t	forced_pd_guid	: 1;
804163398Sscottl				uint16_t	in_vd		: 1;
805163398Sscottl				uint16_t	is_global_spare	: 1;
806163398Sscottl				uint16_t	is_spare	: 1;
807163398Sscottl				uint16_t	is_foreign	: 1;
808163398Sscottl				uint16_t	reserved	: 7;
809163398Sscottl				uint16_t	intf		: 4;
810163398Sscottl			} pd_type;
811163398Sscottl			uint16_t	type;
812163398Sscottl		} v;
813163398Sscottl		uint16_t		reserved;
814163398Sscottl	} ddf;
815163398Sscottl	struct {
816163398Sscottl		uint32_t		reserved;
817163398Sscottl	} non_disk;
818163398Sscottl	uint32_t			type;
819163398Sscottl} __packed;
820163398Sscottl
821163398Sscottlstruct mfi_pd_progress {
822163398Sscottl	struct {
823163398Sscottl		uint32_t		rbld	: 1;
824163398Sscottl		uint32_t		patrol	: 1;
825163398Sscottl		uint32_t		clear	: 1;
826163398Sscottl		uint32_t		reserved: 29;
827163398Sscottl	} active;
828163398Sscottl	struct mfi_progress		rbld;
829163398Sscottl	struct mfi_progress		patrol;
830163398Sscottl	struct mfi_progress		clear;
831163398Sscottl	struct mfi_progress		reserved[4];
832163398Sscottl} __packed;
833163398Sscottl
834163398Sscottlstruct mfi_pd_info {
835163398Sscottl	union mfi_pd_ref		ref;
836163398Sscottl	uint8_t				inquiry_data[96];
837163398Sscottl	uint8_t				vpd_page83[64];
838163398Sscottl	uint8_t				not_supported;
839163398Sscottl	uint8_t				scsi_dev_type;
840163398Sscottl	uint8_t				connected_port_bitmap;
841163398Sscottl	uint8_t				device_speed;
842163398Sscottl	uint32_t			media_err_count;
843163398Sscottl	uint32_t			other_err_count;
844163398Sscottl	uint32_t			pred_fail_count;
845163398Sscottl	uint32_t			last_pred_fail_event_seq_num;
846163398Sscottl	uint16_t			fw_state;
847163398Sscottl	uint8_t				disable_for_removal;
848163398Sscottl	uint8_t				link_speed;
849163398Sscottl	union mfi_pd_ddf_type		state;
850163398Sscottl	struct {
851163398Sscottl		uint8_t			count;
852163398Sscottl		uint8_t			is_path_broken;
853163398Sscottl		uint8_t			reserved[6];
854163398Sscottl		uint64_t		sas_addr[4];
855163398Sscottl	} path_info;
856163398Sscottl	uint64_t			raw_size;
857163398Sscottl	uint64_t			non_coerced_size;
858163398Sscottl	uint64_t			coerced_size;
859163398Sscottl	uint16_t			encl_device_id;
860163398Sscottl	uint8_t				encl_index;
861163398Sscottl	uint8_t				slot_number;
862163398Sscottl	struct mfi_pd_progress		prog_info;
863163398Sscottl	uint8_t				bad_block_table_full;
864163398Sscottl	uint8_t				unusable_in_current_config;
865163398Sscottl	uint8_t				vpd_page83_ext[64];
866163398Sscottl	uint8_t				reserved[512-358];
867163398Sscottl} __packed;
868163398Sscottl
869163398Sscottlstruct mfi_pd_address {
870163398Sscottl	uint16_t		device_id;
871163398Sscottl	uint16_t		encl_device_id;
872163398Sscottl	uint8_t			encl_index;
873163398Sscottl	uint8_t			slot_number;
874163398Sscottl	uint8_t			scsi_dev_type;
875163398Sscottl	uint8_t			connect_port_bitmap;
876163398Sscottl	uint64_t		sas_addr[2];
877163398Sscottl} __packed;
878163398Sscottl
879163398Sscottlstruct mfi_pd_list {
880163398Sscottl	uint32_t		size;
881163398Sscottl	uint32_t		count;
882163398Sscottl	uint8_t			data;
883163398Sscottl	/*
884163398Sscottl	struct mfi_pd_address	addr[];
885163398Sscottl	*/
886163398Sscottl} __packed;
887163398Sscottl
888163398Sscottlunion mfi_ld_ref {
889163398Sscottl	struct {
890163398Sscottl		uint8_t		target_id;
891163398Sscottl		uint8_t		reserved;
892163398Sscottl		uint16_t	seq;
893163398Sscottl	} v;
894163398Sscottl	uint32_t		ref;
895163398Sscottl} __packed;
896163398Sscottl
897159811Spsstruct mfi_ld_list {
898159811Sps	uint32_t		ld_count;
899159811Sps	uint32_t		reserved1;
900159811Sps	struct {
901163398Sscottl		union mfi_ld_ref	ld;
902159811Sps		uint8_t		state;
903159811Sps		uint8_t		reserved2[3];
904159811Sps		uint64_t	size;
905159811Sps	} ld_list[MFI_MAX_LD];
906159811Sps} __packed;
907159811Sps
908159811Spsenum mfi_ld_access {
909159811Sps	MFI_LD_ACCESS_RW =	0,
910159811Sps	MFI_LD_ACCSSS_RO = 	2,
911159811Sps	MFI_LD_ACCESS_BLOCKED =	3,
912159811Sps};
913159811Sps#define MFI_LD_ACCESS_MASK	3
914159811Sps
915159811Spsenum mfi_ld_state {
916159811Sps	MFI_LD_STATE_OFFLINE =			0,
917159811Sps	MFI_LD_STATE_PARTIALLY_DEGRADED =	1,
918159811Sps	MFI_LD_STATE_DEGRADED =			2,
919159811Sps	MFI_LD_STATE_OPTIMAL =			3
920159811Sps};
921159811Sps
922159811Spsstruct mfi_ld_props {
923163398Sscottl	union mfi_ld_ref	ld;
924159811Sps	char			name[16];
925159811Sps	uint8_t			default_cache_policy;
926159811Sps	uint8_t			access_policy;
927159811Sps	uint8_t			disk_cache_policy;
928159811Sps	uint8_t			current_cache_policy;
929159811Sps	uint8_t			no_bgi;
930159811Sps	uint8_t			reserved[7];
931159811Sps} __packed;
932159811Sps
933159811Spsstruct mfi_ld_params {
934159811Sps	uint8_t			primary_raid_level;
935159811Sps	uint8_t			raid_level_qualifier;
936159811Sps	uint8_t			secondary_raid_level;
937159811Sps	uint8_t			stripe_size;
938159811Sps	uint8_t			num_drives;
939159811Sps	uint8_t			span_depth;
940159811Sps	uint8_t			state;
941159811Sps	uint8_t			init_state;
942159811Sps	uint8_t			is_consistent;
943159811Sps	uint8_t			reserved[23];
944159811Sps} __packed;
945159811Sps
946159811Spsstruct mfi_ld_progress {
947159811Sps	uint32_t		active;
948159811Sps#define	MFI_LD_PROGRESS_CC	(1<<0)
949159811Sps#define	MFI_LD_PROGRESS_BGI	(1<<1)
950159811Sps#define	MFI_LD_PROGRESS_FGI	(1<<2)
951159811Sps#define	MFI_LD_PORGRESS_RECON	(1<<3)
952159811Sps	struct mfi_progress	cc;
953159811Sps	struct mfi_progress	bgi;
954159811Sps	struct mfi_progress	fgi;
955159811Sps	struct mfi_progress	recon;
956159811Sps	struct mfi_progress	reserved[4];
957159811Sps} __packed;
958159811Sps
959159811Spsstruct mfi_span {
960159811Sps	uint64_t		start_block;
961159811Sps	uint64_t		num_blocks;
962159811Sps	uint16_t		array_ref;
963159811Sps	uint8_t			reserved[6];
964159811Sps} __packed;
965159811Sps
966159811Sps#define	MFI_MAX_SPAN_DEPTH	8
967159811Spsstruct mfi_ld_config {
968159811Sps	struct mfi_ld_props	properties;
969159811Sps	struct mfi_ld_params	params;
970159811Sps	struct mfi_span		span[MFI_MAX_SPAN_DEPTH];
971159811Sps} __packed;
972159811Sps
973159811Spsstruct mfi_ld_info {
974159811Sps	struct mfi_ld_config	ld_config;
975159811Sps	uint64_t		size;
976159811Sps	struct mfi_ld_progress	progress;
977159811Sps	uint16_t		cluster_owner;
978159811Sps	uint8_t			reconstruct_active;
979159811Sps	uint8_t			reserved1[1];
980159811Sps	uint8_t			vpd_page83[64];
981159811Sps	uint8_t			reserved2[16];
982159811Sps} __packed;
983159811Sps
984163398Sscottlunion mfi_spare_type {
985163398Sscottl	struct {
986163398Sscottl		uint8_t		is_dedicate		:1;
987163398Sscottl		uint8_t		is_revertable		:1;
988163398Sscottl		uint8_t		is_encl_affinity	:1;
989163398Sscottl		uint8_t		reserved		:5;
990163398Sscottl	} v;
991163398Sscottl	uint8_t		type;
992163398Sscottl} __packed;
993163398Sscottl
994163398Sscottl#define MAX_ARRAYS 16
995163398Sscottlstruct mfi_spare {
996163398Sscottl	union mfi_pd_ref	ref;
997163398Sscottl	union mfi_spare_type	spare_type;
998163398Sscottl	uint8_t			reserved[2];
999163398Sscottl	uint8_t			array_count;
1000163398Sscottl	uint16_t		array_refd[MAX_ARRAYS];
1001163398Sscottl} __packed;
1002163398Sscottl
1003163398Sscottl#define MAX_ROW_SIZE 32
1004163398Sscottlstruct mfi_array {
1005163398Sscottl	uint64_t			size;
1006163398Sscottl	uint8_t				num_drives;
1007163398Sscottl	uint8_t				reserved;
1008163398Sscottl	uint16_t			array_ref;
1009163398Sscottl	uint8_t				pad[20];
1010163398Sscottl	struct {
1011163398Sscottl		union mfi_pd_ref	ref;
1012163398Sscottl		uint16_t		fw_state;
1013163398Sscottl		struct {
1014163398Sscottl			uint8_t		pd;
1015163398Sscottl			uint8_t		slot;
1016163398Sscottl		} encl;
1017163398Sscottl	} pd[MAX_ROW_SIZE];
1018163398Sscottl} __packed;
1019163398Sscottl
1020163398Sscottlstruct mfi_config_data {
1021163398Sscottl	uint32_t		size;
1022163398Sscottl	uint16_t		array_count;
1023163398Sscottl	uint16_t		array_size;
1024163398Sscottl	uint16_t		log_drv_count;
1025163398Sscottl	uint16_t		log_drv_size;
1026163398Sscottl	uint16_t		spares_count;
1027163398Sscottl	uint16_t		spares_size;
1028163398Sscottl	uint8_t			reserved[16];
1029163398Sscottl	uint8_t			data;
1030163398Sscottl	/*
1031163398Sscottl	struct mfi_array	array[];
1032163398Sscottl	struct mfi_ld_config	ld[];
1033163398Sscottl	struct mfi_spare	spare[];
1034163398Sscottl	*/
1035163398Sscottl} __packed;
1036163398Sscottl
1037169611Sscottl#define MFI_SCSI_MAX_TARGETS	128
1038169611Sscottl#define MFI_SCSI_MAX_LUNS	8
1039169611Sscottl#define MFI_SCSI_INITIATOR_ID	255
1040169611Sscottl#define MFI_SCSI_MAX_CMDS	8
1041169611Sscottl#define MFI_SCSI_MAX_CDB_LEN	16
1042169611Sscottl
1043157114Sscottl#endif /* _MFIREG_H */
1044