xref: /openbsd-src/sys/dev/pci/mpiireg.h (revision ae3cb403620ab940fbaabb3055fac045a63d56b7)
1 /*	$OpenBSD: mpiireg.h,v 1.12 2017/01/16 18:09:35 mikeb Exp $	*/
2 /*
3  * Copyright (c) 2010 Mike Belopuhov
4  * Copyright (c) 2009 James Giannoules
5  * Copyright (c) 2005 - 2010 David Gwynne <dlg@openbsd.org>
6  * Copyright (c) 2005 - 2010 Marco Peereboom <marco@openbsd.org>
7  *
8  * Permission to use, copy, modify, and distribute this software for any
9  * purpose with or without fee is hereby granted, provided that the above
10  * copyright notice and this permission notice appear in all copies.
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19  */
20 
21 #define MPII_DOORBELL			(0x00)
22 /* doorbell read bits */
23 #define MPII_DOORBELL_STATE		(0xf<<28) /* ioc state */
24 #define  MPII_DOORBELL_STATE_RESET	(0x0<<28)
25 #define  MPII_DOORBELL_STATE_READY	(0x1<<28)
26 #define  MPII_DOORBELL_STATE_OPER	(0x2<<28)
27 #define  MPII_DOORBELL_STATE_FAULT	(0x4<<28)
28 #define  MPII_DOORBELL_INUSE		(0x1<<27) /* doorbell used */
29 #define MPII_DOORBELL_WHOINIT		(0x7<<24) /* last to reset ioc */
30 #define  MPII_DOORBELL_WHOINIT_NOONE	(0x0<<24) /* not initialized */
31 #define  MPII_DOORBELL_WHOINIT_SYSBIOS	(0x1<<24) /* system bios */
32 #define  MPII_DOORBELL_WHOINIT_ROMBIOS	(0x2<<24) /* rom bios */
33 #define  MPII_DOORBELL_WHOINIT_PCIPEER	(0x3<<24) /* pci peer */
34 #define  MPII_DOORBELL_WHOINIT_DRIVER	(0x4<<24) /* host driver */
35 #define  MPII_DOORBELL_WHOINIT_MANUFACT	(0x5<<24) /* manufacturing */
36 #define MPII_DOORBELL_FAULT		(0xffff<<0) /* fault code */
37 /* doorbell write bits */
38 #define MPII_DOORBELL_FUNCTION_SHIFT	(24)
39 #define MPII_DOORBELL_FUNCTION_MASK	(0xff << MPII_DOORBELL_FUNCTION_SHIFT)
40 #define MPII_DOORBELL_FUNCTION(x)	\
41     (((x) << MPII_DOORBELL_FUNCTION_SHIFT) & MPII_DOORBELL_FUNCTION_MASK)
42 #define MPII_DOORBELL_DWORDS_SHIFT	16
43 #define MPII_DOORBELL_DWORDS_MASK	(0xff << MPII_DOORBELL_DWORDS_SHIFT)
44 #define MPII_DOORBELL_DWORDS(x)		\
45     (((x) << MPII_DOORBELL_DWORDS_SHIFT) & MPII_DOORBELL_DWORDS_MASK)
46 #define MPII_DOORBELL_DATA_MASK		(0xffff)
47 
48 #define MPII_WRITESEQ			(0x04)
49 #define  MPII_WRITESEQ_KEY_VALUE_MASK	(0x0000000f) /* key value */
50 #define  MPII_WRITESEQ_FLUSH		(0x00)
51 #define  MPII_WRITESEQ_1		(0x0f)
52 #define  MPII_WRITESEQ_2		(0x04)
53 #define  MPII_WRITESEQ_3		(0x0b)
54 #define  MPII_WRITESEQ_4		(0x02)
55 #define  MPII_WRITESEQ_5		(0x07)
56 #define  MPII_WRITESEQ_6		(0x0d)
57 
58 #define MPII_HOSTDIAG			(0x08)
59 #define  MPII_HOSTDIAG_BDS_MASK		(0x00001800) /* boot device select */
60 #define   MPII_HOSTDIAG_BDS_DEFAULT	(0<<11)	/* default address map, flash */
61 #define   MPII_HOSTDIAG_BDS_HCDW	(1<<11)	/* host code and data window */
62 #define  MPII_HOSTDIAG_CLEARFBS		(1<<10) /* clear flash bad sig */
63 #define  MPII_HOSTDIAG_FORCE_HCB_ONBOOT (1<<9)	/* force host controlled boot */
64 #define  MPII_HOSTDIAG_HCB_MODE		(1<<8)	/* host controlled boot mode */
65 #define  MPII_HOSTDIAG_DWRE		(1<<7)	/* diag reg write enabled */
66 #define  MPII_HOSTDIAG_FBS		(1<<6)	/* flash bad sig */
67 #define  MPII_HOSTDIAG_RESET_HIST	(1<<5)	/* reset history */
68 #define  MPII_HOSTDIAG_DIAGWR_EN	(1<<4)	/* diagnostic write enabled */
69 #define  MPII_HOSTDIAG_RESET_ADAPTER	(1<<2)	/* reset adapter */
70 #define  MPII_HOSTDIAG_HOLD_IOC_RESET	(1<<1)	/* hold ioc in reset */
71 #define  MPII_HOSTDIAG_DIAGMEM_EN	(1<<0)	/* diag mem enable */
72 
73 #define MPII_DIAGRWDATA			(0x10)
74 
75 #define MPII_DIAGRWADDRLOW		(0x14)
76 
77 #define MPII_DIAGRWADDRHIGH		(0x18)
78 
79 #define MPII_INTR_STATUS		(0x30)
80 #define  MPII_INTR_STATUS_SYS2IOCDB	(1<<31) /* ioc written to by host */
81 #define  MPII_INTR_STATUS_RESET		(1<<30) /* physical ioc reset */
82 #define  MPII_INTR_STATUS_REPLY		(1<<3)	/* reply message interrupt */
83 #define  MPII_INTR_STATUS_IOC2SYSDB	(1<<0)	/* ioc write to doorbell */
84 
85 #define MPII_INTR_MASK			(0x34)
86 #define  MPII_INTR_MASK_RESET		(1<<30) /* ioc reset intr mask */
87 #define  MPII_INTR_MASK_REPLY		(1<<3)	/* reply message intr mask */
88 #define  MPII_INTR_MASK_DOORBELL	(1<<0)	/* doorbell interrupt mask */
89 
90 #define MPII_DCR_DATA			(0x38)
91 
92 #define MPII_DCR_ADDRESS		(0x3c)
93 
94 #define MPII_REPLY_FREE_HOST_INDEX	(0x48)
95 
96 #define MPII_REPLY_POST_HOST_INDEX	(0x6c)
97 
98 #define MPII_HCB_SIZE			(0x74)
99 
100 #define MPII_HCB_ADDRESS_LOW		(0x78)
101 #define MPII_HCB_ADDRESS_HIGH		(0x7c)
102 
103 #define MPII_REQ_DESCR_POST_LOW		(0xc0)
104 #define MPII_REQ_DESCR_POST_HIGH	(0xc4)
105 
106 /*
107  * Scatter Gather Lists
108  */
109 
110 #define MPII_SGE_FL_LAST		(0x1<<31) /* last element in segment */
111 #define MPII_SGE_FL_EOB			(0x1<<30) /* last element of buffer */
112 #define MPII_SGE_FL_TYPE		(0x3<<28) /* element type */
113  #define MPII_SGE_FL_TYPE_SIMPLE	(0x1<<28) /* simple element */
114  #define MPII_SGE_FL_TYPE_CHAIN		(0x3<<28) /* chain element */
115  #define MPII_SGE_FL_TYPE_XACTCTX	(0x0<<28) /* transaction context */
116 #define MPII_SGE_FL_LOCAL		(0x1<<27) /* local address */
117 #define MPII_SGE_FL_DIR			(0x1<<26) /* direction */
118  #define MPII_SGE_FL_DIR_OUT		(0x1<<26)
119  #define MPII_SGE_FL_DIR_IN		(0x0<<26)
120 #define MPII_SGE_FL_SIZE		(0x1<<25) /* address size */
121  #define MPII_SGE_FL_SIZE_32		(0x0<<25)
122  #define MPII_SGE_FL_SIZE_64		(0x1<<25)
123 #define MPII_SGE_FL_EOL			(0x1<<24) /* end of list */
124 
125 struct mpii_sge {
126 	u_int32_t		sg_hdr;
127 	u_int32_t		sg_addr_lo;
128 	u_int32_t		sg_addr_hi;
129 } __packed __aligned(4);
130 
131 /*
132  * SAS3 (IEEE) Scatter Gather Lists
133  */
134 
135 #define MPII_IEEE_SGE_ADDR_MASK		(0x03)
136 #define MPII_IEEE_SGE_ADDR_SYSTEM	(0x00)
137 #define MPII_IEEE_SGE_ADDR_IOCDDR	(0x01)
138 #define MPII_IEEE_SGE_ADDR_IOCPLB	(0x02)
139 #define MPII_IEEE_SGE_ADDR_IOCPLBNTA	(0x03)
140 #define MPII_IEEE_SGE_END_OF_LIST	(0x40)
141 #define MPII_IEEE_SGE_CHAIN_ELEMENT	(0x80)
142 
143 struct mpii_ieee_sge {
144 	u_int64_t		sg_addr;
145 	u_int32_t		sg_len;
146 	u_int16_t		_reserved;
147 	u_int8_t		sg_next_chain_offset;
148 	u_int8_t		sg_flags;
149 } __packed __aligned(8);
150 
151 struct mpii_fw_tce {
152 	u_int8_t		reserved1;
153 	u_int8_t		context_size;
154 	u_int8_t		details_length;
155 	u_int8_t		flags;
156 
157 	u_int32_t		reserved2;
158 
159 	u_int32_t		image_offset;
160 
161 	u_int32_t		image_size;
162 } __packed __aligned(4);
163 
164 /*
165  * Messages
166  */
167 
168 /* functions */
169 #define MPII_FUNCTION_SCSI_IO_REQUEST			(0x00)
170 #define MPII_FUNCTION_SCSI_TASK_MGMT			(0x01)
171 #define MPII_FUNCTION_IOC_INIT				(0x02)
172 #define MPII_FUNCTION_IOC_FACTS				(0x03)
173 #define MPII_FUNCTION_CONFIG				(0x04)
174 #define MPII_FUNCTION_PORT_FACTS			(0x05)
175 #define MPII_FUNCTION_PORT_ENABLE			(0x06)
176 #define MPII_FUNCTION_EVENT_NOTIFICATION		(0x07)
177 #define MPII_FUNCTION_EVENT_ACK				(0x08)
178 #define MPII_FUNCTION_FW_DOWNLOAD			(0x09)
179 #define MPII_FUNCTION_TARGET_CMD_BUFFER_POST		(0x0a)
180 #define MPII_FUNCTION_TARGET_ASSIST			(0x0b)
181 #define MPII_FUNCTION_TARGET_STATUS_SEND		(0x0c)
182 #define MPII_FUNCTION_TARGET_MODE_ABORT			(0x0d)
183 #define MPII_FUNCTION_FW_UPLOAD				(0x12)
184 
185 #define MPII_FUNCTION_RAID_ACTION			(0x15)
186 #define MPII_FUNCTION_RAID_SCSI_IO_PASSTHROUGH		(0x16)
187 
188 #define MPII_FUNCTION_TOOLBOX				(0x17)
189 
190 #define MPII_FUNCTION_SCSI_ENCLOSURE_PROCESSOR		(0x18)
191 
192 #define MPII_FUNCTION_SMP_PASSTHROUGH			(0x1a)
193 #define MPII_FUNCTION_SAS_IO_UNIT_CONTROL		(0x1b)
194 #define MPII_FUNCTION_SATA_PASSTHROUGH			(0x1c)
195 
196 #define MPII_FUNCTION_DIAG_BUFFER_POST			(0x1d)
197 #define MPII_FUNCTION_DIAG_RELEASE			(0x1e)
198 
199 #define MPII_FUNCTION_TARGET_CMD_BUF_BASE_POST		(0x24)
200 #define MPII_FUNCTION_TARGET_CMD_BUF_LIST_POST		(0x25)
201 
202 #define MPII_FUNCTION_IOC_MESSAGE_UNIT_RESET		(0x40)
203 #define MPII_FUNCTION_IO_UNIT_RESET			(0x41)
204 #define MPII_FUNCTION_HANDSHAKE				(0x42)
205 
206 /* Common IOCStatus values for all replies */
207 #define MPII_IOCSTATUS_MASK				(0x7fff)
208 #define  MPII_IOCSTATUS_SUCCESS				(0x0000)
209 #define  MPII_IOCSTATUS_INVALID_FUNCTION		(0x0001)
210 #define  MPII_IOCSTATUS_BUSY				(0x0002)
211 #define  MPII_IOCSTATUS_INVALID_SGL			(0x0003)
212 #define  MPII_IOCSTATUS_INTERNAL_ERROR			(0x0004)
213 #define  MPII_IOCSTATUS_INVALID_VPID			(0x0005)
214 #define  MPII_IOCSTATUS_INSUFFICIENT_RESOURCES		(0x0006)
215 #define  MPII_IOCSTATUS_INVALID_FIELD			(0x0007)
216 #define  MPII_IOCSTATUS_INVALID_STATE			(0x0008)
217 #define  MPII_IOCSTATUS_OP_STATE_NOT_SUPPORTED		(0x0009)
218 /* Config IOCStatus values */
219 #define  MPII_IOCSTATUS_CONFIG_INVALID_ACTION		(0x0020)
220 #define  MPII_IOCSTATUS_CONFIG_INVALID_TYPE		(0x0021)
221 #define  MPII_IOCSTATUS_CONFIG_INVALID_PAGE		(0x0022)
222 #define  MPII_IOCSTATUS_CONFIG_INVALID_DATA		(0x0023)
223 #define  MPII_IOCSTATUS_CONFIG_NO_DEFAULTS		(0x0024)
224 #define  MPII_IOCSTATUS_CONFIG_CANT_COMMIT		(0x0025)
225 /* SCSIIO Reply initiator values */
226 #define  MPII_IOCSTATUS_SCSI_RECOVERED_ERROR		(0x0040)
227 #define  MPII_IOCSTATUS_SCSI_INVALID_DEVHANDLE		(0x0042)
228 #define  MPII_IOCSTATUS_SCSI_DEVICE_NOT_THERE		(0x0043)
229 #define  MPII_IOCSTATUS_SCSI_DATA_OVERRUN		(0x0044)
230 #define  MPII_IOCSTATUS_SCSI_DATA_UNDERRUN		(0x0045)
231 #define  MPII_IOCSTATUS_SCSI_IO_DATA_ERROR		(0x0046)
232 #define  MPII_IOCSTATUS_SCSI_PROTOCOL_ERROR		(0x0047)
233 #define  MPII_IOCSTATUS_SCSI_TASK_TERMINATED		(0x0048)
234 #define  MPII_IOCSTATUS_SCSI_RESIDUAL_MISMATCH		(0x0049)
235 #define  MPII_IOCSTATUS_SCSI_TASK_MGMT_FAILED		(0x004a)
236 #define  MPII_IOCSTATUS_SCSI_IOC_TERMINATED		(0x004b)
237 #define  MPII_IOCSTATUS_SCSI_EXT_TERMINATED		(0x004c)
238 /* For use by SCSI Initiator and SCSI Target end-to-end data protection */
239 #define  MPII_IOCSTATUS_EEDP_GUARD_ERROR		(0x004d)
240 #define  MPII_IOCSTATUS_EEDP_REF_TAG_ERROR		(0x004e)
241 #define  MPII_IOCSTATUS_EEDP_APP_TAG_ERROR		(0x004f)
242 /* SCSI (SPI & FCP) target values */
243 #define  MPII_IOCSTATUS_TARGET_INVALID_IO_INDEX		(0x0062)
244 #define  MPII_IOCSTATUS_TARGET_ABORTED			(0x0063)
245 #define  MPII_IOCSTATUS_TARGET_NO_CONN_RETRYABLE	(0x0064)
246 #define  MPII_IOCSTATUS_TARGET_NO_CONNECTION		(0x0065)
247 #define  MPII_IOCSTATUS_TARGET_XFER_COUNT_MISMATCH	(0x006a)
248 #define  MPII_IOCSTATUS_TARGET_DATA_OFFSET_ERROR	(0x006d)
249 #define  MPII_IOCSTATUS_TARGET_TOO_MUCH_WRITE_DATA	(0x006e)
250 #define  MPII_IOCSTATUS_TARGET_IU_TOO_SHORT		(0x006f)
251 #define  MPII_IOCSTATUS_TARGET_ACK_NAK_TIMEOUT		(0x0070)
252 #define  MPII_IOCSTATUS_TARGET_NAK_RECEIVED		(0x0071)
253 /* Serial Attached SCSI values */
254 #define  MPII_IOCSTATUS_SAS_SMP_REQUEST_FAILED		(0x0090)
255 #define  MPII_IOCSTATUS_SAS_SMP_DATA_OVERRUN		(0x0091)
256 /* Diagnostic Tools values */
257 #define  MPII_IOCSTATUS_DIAGNOSTIC_RELEASED		(0x00a0)
258 
259 #define MPII_REP_IOCLOGINFO_TYPE			(0xf<<28)
260 #define MPII_REP_IOCLOGINFO_TYPE_NONE			(0x0<<28)
261 #define MPII_REP_IOCLOGINFO_TYPE_SCSI			(0x1<<28)
262 #define MPII_REP_IOCLOGINFO_TYPE_FC			(0x2<<28)
263 #define MPII_REP_IOCLOGINFO_TYPE_SAS			(0x3<<28)
264 #define MPII_REP_IOCLOGINFO_TYPE_ISCSI			(0x4<<28)
265 #define MPII_REP_IOCLOGINFO_DATA			(0x0fffffff)
266 
267 /* event notification types */
268 #define MPII_EVENT_NONE					(0x00)
269 #define MPII_EVENT_LOG_DATA				(0x01)
270 #define MPII_EVENT_STATE_CHANGE				(0x02)
271 #define MPII_EVENT_HARD_RESET_RECEIVED			(0x05)
272 #define MPII_EVENT_EVENT_CHANGE				(0x0a)
273 #define MPII_EVENT_TASK_SET_FULL			(0x0e)
274 #define MPII_EVENT_SAS_DEVICE_STATUS_CHANGE		(0x0f)
275 #define MPII_EVENT_IR_OPERATION_STATUS			(0x14)
276 #define MPII_EVENT_SAS_DISCOVERY			(0x16)
277 #define MPII_EVENT_SAS_BROADCAST_PRIMITIVE		(0x17)
278 #define MPII_EVENT_SAS_INIT_DEVICE_STATUS_CHANGE	(0x18)
279 #define MPII_EVENT_SAS_INIT_TABLE_OVERFLOW		(0x19)
280 #define MPII_EVENT_SAS_TOPOLOGY_CHANGE_LIST		(0x1c)
281 #define MPII_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE	(0x1d)
282 #define MPII_EVENT_IR_VOLUME				(0x1e)
283 #define MPII_EVENT_IR_PHYSICAL_DISK			(0x1f)
284 #define MPII_EVENT_IR_CONFIGURATION_CHANGE_LIST		(0x20)
285 #define MPII_EVENT_LOG_ENTRY_ADDED			(0x21)
286 
287 /* messages */
288 
289 #define MPII_WHOINIT_NOONE				(0x00)
290 #define MPII_WHOINIT_SYSTEM_BIOS			(0x01)
291 #define MPII_WHOINIT_ROM_BIOS				(0x02)
292 #define MPII_WHOINIT_PCI_PEER				(0x03)
293 #define MPII_WHOINIT_HOST_DRIVER			(0x04)
294 #define MPII_WHOINIT_MANUFACTURER			(0x05)
295 
296 /* default messages */
297 
298 struct mpii_msg_request {
299 	u_int8_t		reserved1;
300 	u_int8_t		reserved2;
301 	u_int8_t		chain_offset;
302 	u_int8_t		function;
303 
304 	u_int8_t		reserved3;
305 	u_int8_t		reserved4;
306 	u_int8_t		reserved5;
307 	u_int8_t		msg_flags;
308 
309 	u_int8_t		vp_id;
310 	u_int8_t		vf_id;
311 	u_int16_t		reserved6;
312 } __packed __aligned(4);
313 
314 struct mpii_msg_reply {
315 	u_int16_t		reserved1;
316 	u_int8_t		msg_length;
317 	u_int8_t		function;
318 
319 	u_int16_t		reserved2;
320 	u_int8_t		reserved3;
321 	u_int8_t		msg_flags;
322 
323 	u_int8_t		vp_id;
324 	u_int8_t		vf_if;
325 	u_int16_t		reserved4;
326 
327 	u_int16_t		reserved5;
328 	u_int16_t		ioc_status;
329 
330 	u_int32_t		ioc_loginfo;
331 } __packed __aligned(4);
332 
333 /* ioc init */
334 
335 struct mpii_msg_iocinit_request {
336 	u_int8_t		whoinit;
337 	u_int8_t		reserved1;
338 	u_int8_t		chain_offset;
339 	u_int8_t		function;
340 
341 	u_int16_t		reserved2;
342 	u_int8_t		reserved3;
343 	u_int8_t		msg_flags;
344 
345 	u_int8_t		vp_id;
346 	u_int8_t		vf_id;
347 	u_int16_t		reserved4;
348 
349 	u_int8_t		msg_version_min;
350 	u_int8_t		msg_version_maj;
351 	u_int8_t		hdr_version_unit;
352 	u_int8_t		hdr_version_dev;
353 
354 	u_int32_t		reserved5;
355 
356 	u_int32_t		reserved6;
357 
358 	u_int16_t		reserved7;
359 	u_int16_t		system_request_frame_size;
360 
361 	u_int16_t		reply_descriptor_post_queue_depth;
362 	u_int16_t		reply_free_queue_depth;
363 
364 	u_int32_t		sense_buffer_address_high;
365 
366 	u_int32_t		system_reply_address_high;
367 
368 	u_int32_t		system_request_frame_base_address_lo;
369 	u_int32_t		system_request_frame_base_address_hi;
370 
371 	u_int32_t		reply_descriptor_post_queue_address_lo;
372 	u_int32_t		reply_descriptor_post_queue_address_hi;
373 
374 	u_int32_t		reply_free_queue_address_lo;
375 	u_int32_t		reply_free_queue_address_hi;
376 
377 	u_int64_t		timestamp;
378 } __packed __aligned(4);
379 
380 struct mpii_msg_iocinit_reply {
381 	u_int8_t		whoinit;
382 	u_int8_t		reserved1;
383 	u_int8_t		msg_length;
384 	u_int8_t		function;
385 
386 	u_int16_t		reserved2;
387 	u_int8_t		reserved3;
388 	u_int8_t		msg_flags;
389 
390 	u_int8_t		vp_id;
391 	u_int8_t		vf_id;
392 	u_int16_t		reserved4;
393 
394 	u_int16_t		reserved5;
395 	u_int16_t		ioc_status;
396 
397 	u_int32_t		ioc_loginfo;
398 } __packed __aligned(4);
399 
400 struct mpii_msg_iocfacts_request {
401 	u_int16_t		reserved1;
402 	u_int8_t		chain_offset;
403 	u_int8_t		function;
404 
405 	u_int16_t		reserved2;
406 	u_int8_t		reserved3;
407 	u_int8_t		msg_flags;
408 
409 	u_int8_t		vp_id;
410 	u_int8_t		vf_id;
411 	u_int16_t		reserved4;
412 } __packed __aligned(4);
413 
414 struct mpii_msg_iocfacts_reply {
415 	u_int8_t		msg_version_min;
416 	u_int8_t		msg_version_maj;
417 	u_int8_t		msg_length;
418 	u_int8_t		function;
419 
420 	u_int8_t		header_version_dev;
421 	u_int8_t		header_version_unit;
422 	u_int8_t		ioc_number;
423 	u_int8_t		msg_flags;
424 
425 	u_int8_t		vp_id;
426 	u_int8_t		vf_id;
427 	u_int16_t		reserved1;
428 
429 	u_int16_t		ioc_exceptions;
430 #define MPII_IOCFACTS_EXCEPT_CONFIG_CHECKSUM_FAIL	(1<<0)
431 #define MPII_IOCFACTS_EXCEPT_RAID_CONFIG_INVALID	(1<<1)
432 #define MPII_IOCFACTS_EXCEPT_FW_CHECKSUM_FAIL		(1<<2)
433 #define MPII_IOCFACTS_EXCEPT_MANUFACT_CHECKSUM_FAIL	(1<<3)
434 #define MPII_IOCFACTS_EXCEPT_METADATA_UNSUPPORTED	(1<<4)
435 #define MPII_IOCFACTS_EXCEPT_IR_FOREIGN_CONFIG_MAC	(1<<8)
436 	/* XXX JPG BOOT_STATUS in bits[7:5] */
437 	/* XXX JPG all these #defines need to be fixed up */
438 	u_int16_t		ioc_status;
439 
440 	u_int32_t		ioc_loginfo;
441 
442 	u_int8_t		max_chain_depth;
443 	u_int8_t		whoinit;
444 	u_int8_t		number_of_ports;
445 	u_int8_t		reserved2;
446 
447 	u_int16_t		request_credit;
448 	u_int16_t		product_id;
449 
450 	u_int32_t		ioc_capabilities;
451 #define MPII_IOCFACTS_CAPABILITY_EVENT_REPLAY           (1<<13)
452 #define MPII_IOCFACTS_CAPABILITY_INTEGRATED_RAID        (1<<12)
453 #define MPII_IOCFACTS_CAPABILITY_TLR                    (1<<11)
454 #define MPII_IOCFACTS_CAPABILITY_MULTICAST              (1<<8)
455 #define MPII_IOCFACTS_CAPABILITY_BIDIRECTIONAL_TARGET   (1<<7)
456 #define MPII_IOCFACTS_CAPABILITY_EEDP                   (1<<6)
457 #define MPII_IOCFACTS_CAPABILITY_SNAPSHOT_BUFFER        (1<<4)
458 #define MPII_IOCFACTS_CAPABILITY_DIAG_TRACE_BUFFER      (1<<3)
459 #define MPII_IOCFACTS_CAPABILITY_TASK_SET_FULL_HANDLING (1<<2)
460 
461 	u_int8_t		fw_version_dev;
462 	u_int8_t		fw_version_unit;
463 	u_int8_t		fw_version_min;
464 	u_int8_t		fw_version_maj;
465 
466 	u_int16_t		ioc_request_frame_size;
467 	u_int16_t		reserved3;
468 
469 	u_int16_t		max_initiators;
470 	u_int16_t		max_targets;
471 
472 	u_int16_t		max_sas_expanders;
473 	u_int16_t		max_enclosures;
474 
475 	u_int16_t		protocol_flags;
476 	u_int16_t		high_priority_credit;
477 
478 	u_int16_t		max_reply_descriptor_post_queue_depth;
479 	u_int8_t		reply_frame_size;
480 	u_int8_t		max_volumes;
481 
482 	u_int16_t		max_dev_handle;
483 	u_int16_t		max_persistent_entries;
484 
485 	u_int32_t		reserved4;
486 } __packed __aligned(4);
487 
488 struct mpii_msg_portfacts_request {
489 	u_int16_t		reserved1;
490 	u_int8_t		chain_offset;
491 	u_int8_t		function;
492 
493 	u_int16_t		reserved2;
494 	u_int8_t		port_number;
495 	u_int8_t		msg_flags;
496 
497 	u_int8_t		vp_id;
498 	u_int8_t		vf_id;
499 	u_int16_t		reserved3;
500 } __packed __aligned(4);
501 
502 struct mpii_msg_portfacts_reply {
503 	u_int16_t		reserved1;
504 	u_int8_t		msg_length;
505 	u_int8_t		function;
506 
507 	u_int16_t		reserved2;
508 	u_int8_t		port_number;
509 	u_int8_t		msg_flags;
510 
511 	u_int8_t		vp_id;
512 	u_int8_t		vf_id;
513 	u_int16_t		reserved3;
514 
515 	u_int16_t		reserved4;
516 	u_int16_t		ioc_status;
517 
518 	u_int32_t		ioc_loginfo;
519 
520 	u_int8_t		reserved5;
521 	u_int8_t		port_type;
522 #define MPII_PORTFACTS_PORTTYPE_INACTIVE		(0x00)
523 #define MPII_PORTFACTS_PORTTYPE_FC			(0x10)
524 #define MPII_PORTFACTS_PORTTYPE_ISCSI			(0x20)
525 #define MPII_PORTFACTS_PORTTYPE_SAS_PHYSICAL		(0x30)
526 #define MPII_PORTFACTS_PORTTYPE_SAS_VIRTUAL		(0x31)
527 	u_int16_t		reserved6;
528 
529 	u_int16_t		max_posted_cmd_buffers;
530 	u_int16_t		reserved7;
531 } __packed __aligned(4);
532 
533 struct mpii_msg_portenable_request {
534 	u_int16_t		reserved1;
535 	u_int8_t		chain_offset;
536 	u_int8_t		function;
537 
538 	u_int8_t		reserved2;
539 	u_int8_t		port_flags;
540 	u_int8_t		reserved3;
541 	u_int8_t		msg_flags;
542 
543 	u_int8_t		vp_id;
544 	u_int8_t		vf_id;
545 	u_int16_t		reserved4;
546 } __packed __aligned(4);
547 
548 struct mpii_msg_portenable_reply {
549 	u_int16_t		reserved1;
550 	u_int8_t		msg_length;
551 	u_int8_t		function;
552 
553 	u_int8_t		reserved2;
554 	u_int8_t		port_flags;
555 	u_int8_t		reserved3;
556 	u_int8_t		msg_flags;
557 
558 	u_int8_t		vp_id;
559 	u_int8_t		vf_id;
560 	u_int16_t		reserved4;
561 
562 	u_int16_t		reserved5;
563 	u_int16_t		ioc_status;
564 
565 	u_int32_t		ioc_loginfo;
566 } __packed __aligned(4);
567 
568 struct mpii_msg_event_request {
569 	u_int16_t		reserved1;
570 	u_int8_t		chain_offset;
571 	u_int8_t		function;
572 
573 	u_int16_t		reserved2;
574 	u_int8_t		reserved3;
575 	u_int8_t		msg_flags;
576 
577 	u_int8_t		vp_id;
578 	u_int8_t		vf_id;
579 	u_int16_t		reserved4;
580 
581 	u_int32_t		reserved5;
582 
583 	u_int32_t		reserved6;
584 
585 	u_int32_t		event_masks[4];
586 
587 	u_int16_t		sas_broadcase_primitive_masks;
588 	u_int16_t		reserved7;
589 
590 	u_int32_t		reserved8;
591 } __packed __aligned(4);
592 
593 struct mpii_msg_event_reply {
594 	u_int16_t		event_data_length;
595 	u_int8_t		msg_length;
596 	u_int8_t		function;
597 
598 	u_int16_t		reserved1;
599 	u_int8_t		ack_required;
600 #define MPII_EVENT_ACK_REQUIRED				(0x01)
601 	u_int8_t		msg_flags;
602 #define MPII_EVENT_FLAGS_REPLY_KEPT			(1<<7)
603 
604 	u_int8_t		vp_id;
605 	u_int8_t		vf_id;
606 	u_int16_t		reserved2;
607 
608 	u_int16_t		reserved3;
609 	u_int16_t		ioc_status;
610 
611 	u_int32_t		ioc_loginfo;
612 
613 	u_int16_t		event;
614 	u_int16_t		reserved4;
615 
616 	u_int32_t		event_context;
617 
618 	/* event data follows */
619 } __packed __aligned(4);
620 
621 struct mpii_msg_eventack_request {
622 	u_int16_t		reserved1;
623 	u_int8_t		chain_offset;
624 	u_int8_t		function;
625 
626 	u_int8_t		reserved2[3];
627 	u_int8_t		msg_flags;
628 
629 	u_int8_t		vp_id;
630 	u_int8_t		vf_id;
631 	u_int16_t		reserved3;
632 
633 	u_int16_t		event;
634 	u_int16_t		reserved4;
635 
636 	u_int32_t		event_context;
637 } __packed __aligned(4);
638 
639 struct mpii_msg_eventack_reply {
640 	u_int16_t		reserved1;
641 	u_int8_t		msg_length;
642 	u_int8_t		function;
643 
644 	u_int8_t		reserved2[3];
645 	u_int8_t		msg_flags;
646 
647 	u_int8_t		vp_id;
648 	u_int8_t		vf_id;
649 	u_int16_t		reserved3;
650 
651 	u_int16_t		reserved4;
652 	u_int16_t		ioc_status;
653 
654 	u_int32_t		ioc_loginfo;
655 } __packed __aligned(4);
656 
657 struct mpii_msg_fwupload_request {
658 	u_int8_t		image_type;
659 #define MPII_FWUPLOAD_IMAGETYPE_IOC_FW			(0x00)
660 #define MPII_FWUPLOAD_IMAGETYPE_NV_FW			(0x01)
661 #define MPII_FWUPLOAD_IMAGETYPE_NV_BACKUP		(0x05)
662 #define MPII_FWUPLOAD_IMAGETYPE_NV_MANUFACTURING	(0x06)
663 #define MPII_FWUPLOAD_IMAGETYPE_NV_CONFIG_1		(0x07)
664 #define MPII_FWUPLOAD_IMAGETYPE_NV_CONFIG_2		(0x08)
665 #define MPII_FWUPLOAD_IMAGETYPE_NV_MEGARAID		(0x09)
666 #define MPII_FWUPLOAD_IMAGETYPE_NV_COMPLETE		(0x0a)
667 #define MPII_FWUPLOAD_IMAGETYPE_COMMON_BOOT_BLOCK	(0x0b)
668 	u_int8_t		reserved1;
669 	u_int8_t		chain_offset;
670 	u_int8_t		function;
671 
672 	u_int8_t		reserved2[3];
673 	u_int8_t		msg_flags;
674 
675 	u_int8_t		vp_id;
676 	u_int8_t		vf_id;
677 	u_int16_t		reserved3;
678 
679 	u_int32_t		reserved4;
680 
681 	u_int32_t		reserved5;
682 
683 	struct mpii_fw_tce	tce;
684 
685 	/* followed by an sgl */
686 } __packed __aligned(4);
687 
688 struct mpii_msg_fwupload_reply {
689 	u_int8_t		image_type;
690 	u_int8_t		reserved1;
691 	u_int8_t		msg_length;
692 	u_int8_t		function;
693 
694 	u_int8_t		reserved2[3];
695 	u_int8_t		msg_flags;
696 
697 	u_int8_t		vp_id;
698 	u_int8_t		vf_id;
699 	u_int16_t		reserved3;
700 
701 	u_int16_t		reserved4;
702 	u_int16_t		ioc_status;
703 
704 	u_int32_t		ioc_loginfo;
705 
706 	u_int32_t		actual_image_size;
707 } __packed __aligned(4);
708 
709 struct mpii_msg_scsi_io {
710 	u_int16_t		dev_handle;
711 	u_int8_t		chain_offset;
712 	u_int8_t		function;
713 
714 	u_int16_t		reserved1;
715 	u_int8_t		reserved2;
716 	u_int8_t		msg_flags;
717 
718 	u_int8_t		vp_id;
719 	u_int8_t		vf_id;
720 	u_int16_t		reserved3;
721 
722 	u_int32_t		sense_buffer_low_address;
723 
724 	u_int16_t		sgl_flags;
725 	u_int8_t		sense_buffer_length;
726 	u_int8_t		reserved4;
727 
728 	u_int8_t		sgl_offset0;
729 	u_int8_t		sgl_offset1;
730 	u_int8_t		sgl_offset2;
731 	u_int8_t		sgl_offset3;
732 
733 	u_int32_t		skip_count;
734 
735 	u_int32_t		data_length;
736 
737 	u_int32_t		bidirectional_data_length;
738 
739 	u_int16_t		io_flags;
740 	u_int16_t		eedp_flags;
741 
742 	u_int32_t		eedp_block_size;
743 
744 	u_int32_t		secondary_reference_tag;
745 
746 	u_int16_t		secondary_application_tag;
747 	u_int16_t		application_tag_translation_mask;
748 
749 	u_int16_t		lun[4];
750 
751 /* the following 16 bits are defined in MPI2 as the control field */
752 	u_int8_t		reserved5;
753 	u_int8_t		tagging;
754 #define MPII_SCSIIO_ATTR_SIMPLE_Q			(0x0)
755 #define MPII_SCSIIO_ATTR_HEAD_OF_Q			(0x1)
756 #define MPII_SCSIIO_ATTR_ORDERED_Q			(0x2)
757 #define MPII_SCSIIO_ATTR_ACA_Q				(0x4)
758 #define MPII_SCSIIO_ATTR_UNTAGGED			(0x5)
759 #define MPII_SCSIIO_ATTR_NO_DISCONNECT			(0x7)
760 	u_int8_t		reserved6;
761 	u_int8_t		direction;
762 #define MPII_SCSIIO_DIR_NONE				(0x0)
763 #define MPII_SCSIIO_DIR_WRITE				(0x1)
764 #define MPII_SCSIIO_DIR_READ				(0x2)
765 
766 #define	MPII_CDB_LEN					(32)
767 	u_int8_t		cdb[MPII_CDB_LEN];
768 
769 	/* followed by an sgl */
770 } __packed __aligned(4);
771 
772 struct mpii_msg_scsi_io_error {
773 	u_int16_t		dev_handle;
774 	u_int8_t		msg_length;
775 	u_int8_t		function;
776 
777 	u_int16_t		reserved1;
778 	u_int8_t		reserved2;
779 	u_int8_t		msg_flags;
780 
781 	u_int8_t		vp_id;
782 	u_int8_t		vf_id;
783 	u_int16_t		reserved3;
784 
785 	u_int8_t		scsi_status;
786 #define MPII_SCSIIO_STATUS_GOOD				(0x00)
787 #define MPII_SCSIIO_STATUS_CHECK_COND			(0x02)
788 #define MPII_SCSIIO_STATUS_COND_MET			(0x04)
789 #define MPII_SCSIIO_STATUS_BUSY				(0x08)
790 #define MPII_SCSIIO_STATUS_INTERMEDIATE			(0x10)
791 #define MPII_SCSIIO_STATUS_INTERMEDIATE_CONDMET		(0x14)
792 #define MPII_SCSIIO_STATUS_RESERVATION_CONFLICT		(0x18)
793 #define MPII_SCSIIO_STATUS_CMD_TERM			(0x22)
794 #define MPII_SCSIIO_STATUS_TASK_SET_FULL		(0x28)
795 #define MPII_SCSIIO_STATUS_ACA_ACTIVE			(0x30)
796 #define MPII_SCSIIO_STATUS_TASK_ABORTED			(0x40)
797 	u_int8_t		scsi_state;
798 #define MPII_SCSIIO_STATE_AUTOSENSE_VALID		(1<<0)
799 #define MPII_SCSIIO_STATE_AUTOSENSE_FAILED		(1<<1)
800 #define MPII_SCSIIO_STATE_NO_SCSI_STATUS		(1<<2)
801 #define MPII_SCSIIO_STATE_TERMINATED			(1<<3)
802 #define MPII_SCSIIO_STATE_RESPONSE_INFO_VALID		(1<<4)
803 	u_int16_t		ioc_status;
804 
805 	u_int32_t		ioc_loginfo;
806 
807 	u_int32_t		transfer_count;
808 
809 	u_int32_t		sense_count;
810 
811 	u_int32_t		response_info;
812 
813 	u_int16_t		task_tag;
814 	u_int16_t		reserved4;
815 
816 	u_int32_t		bidirectional_transfer_count;
817 
818 	u_int32_t		reserved5;
819 
820 	u_int32_t		reserved6;
821 } __packed __aligned(4);
822 
823 struct mpii_request_descr {
824 	u_int8_t		request_flags;
825 #define MPII_REQ_DESCR_TYPE_MASK			(0x0e)
826 #define MPII_REQ_DESCR_SCSI_IO				(0x00)
827 #define MPII_REQ_DESCR_SCSI_TARGET			(0x02)
828 #define MPII_REQ_DESCR_HIGH_PRIORITY			(0x06)
829 #define MPII_REQ_DESCR_DEFAULT				(0x08)
830 	u_int8_t		vf_id;
831 	u_int16_t		smid;
832 
833 	u_int16_t		lmid;
834 	u_int16_t		dev_handle;
835 } __packed __aligned(8);
836 
837 struct mpii_reply_descr {
838 	u_int8_t		reply_flags;
839 #define MPII_REPLY_DESCR_TYPE_MASK			(0x0f)
840 #define MPII_REPLY_DESCR_SCSI_IO_SUCCESS		(0x00)
841 #define MPII_REPLY_DESCR_ADDRESS_REPLY			(0x01)
842 #define MPII_REPLY_DESCR_TARGET_ASSIST_SUCCESS		(0x02)
843 #define MPII_REPLY_DESCR_TARGET_COMMAND_BUFFER		(0x03)
844 #define MPII_REPLY_DESCR_UNUSED				(0x0f)
845 	u_int8_t		vf_id;
846 	u_int16_t		smid;
847 
848 	union {
849 		u_int32_t	data;
850 		u_int32_t	frame_addr;	/* Address Reply */
851 	};
852 } __packed __aligned(8);
853 
854 struct mpii_request_header {
855 	u_int16_t		function_dependent1;
856 	u_int8_t		chain_offset;
857 	u_int8_t		function;
858 
859 	u_int16_t		function_dependent2;
860 	u_int8_t		function_dependent3;
861 	u_int8_t		message_flags;
862 
863 	u_int8_t		vp_id;
864 	u_int8_t		vf_id;
865 	u_int16_t		reserved;
866 } __packed __aligned(4);
867 
868 struct mpii_msg_scsi_task_request {
869 	u_int16_t		dev_handle;
870 	u_int8_t		chain_offset;
871 	u_int8_t		function;
872 
873 	u_int8_t		reserved1;
874 	u_int8_t		task_type;
875 #define MPII_SCSI_TASK_ABORT_TASK			(0x01)
876 #define MPII_SCSI_TASK_ABRT_TASK_SET			(0x02)
877 #define MPII_SCSI_TASK_TARGET_RESET			(0x03)
878 #define MPII_SCSI_TASK_RESET_BUS			(0x04)
879 #define MPII_SCSI_TASK_LOGICAL_UNIT_RESET		(0x05)
880 	u_int8_t		reserved2;
881 	u_int8_t		msg_flags;
882 
883 	u_int8_t		vp_id;
884 	u_int8_t		vf_id;
885 	u_int16_t		reserved3;
886 
887 	u_int16_t		lun[4];
888 
889 	u_int32_t		reserved4[7];
890 
891 	u_int16_t		task_mid;
892 	u_int16_t		reserved5;
893 } __packed __aligned(4);
894 
895 struct mpii_msg_scsi_task_reply {
896 	u_int16_t		dev_handle;
897 	u_int8_t		msg_length;
898 	u_int8_t		function;
899 
900 	u_int8_t		response_code;
901 	u_int8_t		task_type;
902 	u_int8_t		reserved1;
903 	u_int8_t		msg_flags;
904 
905 	u_int8_t		vp_id;
906 	u_int8_t		vf_id;
907 	u_int16_t		reserved2;
908 
909 	u_int16_t		reserved3;
910 	u_int16_t		ioc_status;
911 
912 	u_int32_t		ioc_loginfo;
913 
914 	u_int32_t		termination_count;
915 } __packed __aligned(4);
916 
917 struct mpii_msg_sas_oper_request {
918 	u_int8_t		operation;
919 #define MPII_SAS_OP_CLEAR_PERSISTENT		(0x02)
920 #define MPII_SAS_OP_PHY_LINK_RESET		(0x06)
921 #define MPII_SAS_OP_PHY_HARD_RESET		(0x07)
922 #define MPII_SAS_OP_PHY_CLEAR_ERROR_LOG		(0x08)
923 #define MPII_SAS_OP_SEND_PRIMITIVE		(0x0a)
924 #define MPII_SAS_OP_FORCE_FULL_DISCOVERY	(0x0b)
925 #define MPII_SAS_OP_TRANSMIT_PORT_SELECT	(0x0c)
926 #define MPII_SAS_OP_REMOVE_DEVICE		(0x0d)
927 #define MPII_SAS_OP_LOOKUP_MAPPING		(0x0e)
928 #define MPII_SAS_OP_SET_IOC_PARAM		(0x0f)
929 	u_int8_t		reserved1;
930 	u_int8_t		chain_offset;
931 	u_int8_t		function;
932 
933 	u_int16_t		dev_handle;
934 	u_int8_t		ioc_param;
935 	u_int8_t		msg_flags;
936 
937 	u_int8_t		vp_id;
938 	u_int8_t		vf_id;
939 	u_int16_t		reserved2;
940 
941 	u_int16_t		reserved3;
942 	u_int8_t		phy_num;
943 	u_int8_t		prim_flags;
944 
945 	u_int32_t		primitive;
946 
947 	u_int8_t		lookup_method;
948 #define MPII_SAS_LOOKUP_METHOD_SAS_ADDR		(0x01)
949 #define MPII_SAS_LOOKUP_METHOD_SAS_ENCL		(0x02)
950 #define MPII_SAS_LOOKUP_METHOD_SAS_DEVNAME	(0x03)
951 	u_int8_t		reserved4;
952 	u_int16_t		slot_num;
953 
954 	u_int64_t		lookup_addr;
955 
956 	u_int32_t		ioc_param_value;
957 
958 	u_int64_t		reserved5;
959 } __packed __aligned(4);
960 
961 struct mpii_msg_sas_oper_reply {
962 	u_int8_t		operation;
963 	u_int8_t		reserved1;
964 	u_int8_t		chain_offset;
965 	u_int8_t		function;
966 
967 	u_int16_t		dev_handle;
968 	u_int8_t		ioc_param;
969 	u_int8_t		msg_flags;
970 
971 	u_int8_t		vp_id;
972 	u_int8_t		vf_id;
973 	u_int16_t		reserved2;
974 
975 	u_int16_t		reserved3;
976 	u_int16_t		ioc_status;
977 
978 	u_int32_t		ioc_loginfo;
979 } __packed __aligned(4);
980 
981 struct mpii_msg_raid_action_request {
982 	u_int8_t	action;
983 #define MPII_RAID_ACTION_CHANGE_VOL_WRITE_CACHE	(0x17)
984 	u_int8_t	reserved1;
985 	u_int8_t	chain_offset;
986 	u_int8_t	function;
987 
988 	u_int16_t	vol_dev_handle;
989 	u_int8_t	phys_disk_num;
990 	u_int8_t	msg_flags;
991 
992 	u_int8_t	vp_id;
993 	u_int8_t	vf_if;
994 	u_int16_t	reserved2;
995 
996 	u_int32_t	reserved3;
997 
998 	u_int32_t	action_data;
999 #define MPII_RAID_VOL_WRITE_CACHE_MASK			(0x03)
1000 #define MPII_RAID_VOL_WRITE_CACHE_DISABLE		(0x01)
1001 #define MPII_RAID_VOL_WRITE_CACHE_ENABLE		(0x02)
1002 
1003 	struct mpii_sge	action_sge;
1004 } __packed __aligned(4);
1005 
1006 struct mpii_msg_raid_action_reply {
1007 	u_int8_t	action;
1008 	u_int8_t	reserved1;
1009 	u_int8_t	chain_offset;
1010 	u_int8_t	function;
1011 
1012 	u_int16_t	vol_dev_handle;
1013 	u_int8_t	phys_disk_num;
1014 	u_int8_t	msg_flags;
1015 
1016 	u_int8_t	vp_id;
1017 	u_int8_t	vf_if;
1018 	u_int16_t	reserved2;
1019 
1020 	u_int16_t	reserved3;
1021 	u_int16_t	ioc_status;
1022 
1023 	u_int32_t	action_data[5];
1024 } __packed __aligned(4);
1025 
1026 struct mpii_cfg_hdr {
1027 	u_int8_t		page_version;
1028 	u_int8_t		page_length;
1029 	u_int8_t		page_number;
1030 	u_int8_t		page_type;
1031 #define MPII_CONFIG_REQ_PAGE_TYPE_ATTRIBUTE		(0xf0)
1032 #define MPI2_CONFIG_PAGEATTR_READ_ONLY			(0x00)
1033 #define MPI2_CONFIG_PAGEATTR_CHANGEABLE			(0x10)
1034 #define MPI2_CONFIG_PAGEATTR_PERSISTENT			(0x20)
1035 
1036 #define MPII_CONFIG_REQ_PAGE_TYPE_MASK			(0x0f)
1037 #define MPII_CONFIG_REQ_PAGE_TYPE_IO_UNIT		(0x00)
1038 #define MPII_CONFIG_REQ_PAGE_TYPE_IOC			(0x01)
1039 #define MPII_CONFIG_REQ_PAGE_TYPE_BIOS			(0x02)
1040 #define MPII_CONFIG_REQ_PAGE_TYPE_RAID_VOL		(0x08)
1041 #define MPII_CONFIG_REQ_PAGE_TYPE_MANUFACTURING		(0x09)
1042 #define MPII_CONFIG_REQ_PAGE_TYPE_RAID_PD		(0x0a)
1043 #define MPII_CONFIG_REQ_PAGE_TYPE_EXTENDED		(0x0f)
1044 } __packed __aligned(4);
1045 
1046 struct mpii_ecfg_hdr {
1047 	u_int8_t		page_version;
1048 	u_int8_t		reserved1;
1049 	u_int8_t		page_number;
1050 	u_int8_t		page_type;
1051 
1052 	u_int16_t		ext_page_length;
1053 	u_int8_t		ext_page_type;
1054 #define MPII_CONFIG_REQ_PAGE_TYPE_SAS_DEVICE		(0x12)
1055 #define MPII_CONFIG_REQ_PAGE_TYPE_RAID_CONFIG		(0x16)
1056 #define MPII_CONFIG_REQ_PAGE_TYPE_DRIVER_MAPPING	(0x17)
1057 	u_int8_t		reserved2;
1058 } __packed __aligned(4);
1059 
1060 /* config page address formats */
1061 #define MPII_PGAD_SAS_DEVICE_FORM_MASK			(0xf0000000)
1062 #define MPII_PGAD_SAS_DEVICE_FORM_GET_NEXT_HANDLE	(0x00000000)
1063 #define MPII_PGAD_SAS_DEVICE_FORM_HANDLE		(0x20000000)
1064 
1065 #define MPII_PGAD_SAS_DEVICE_HANDLE_MASK		(0x0000ffff)
1066 
1067 struct mpii_msg_config_request {
1068 	u_int8_t		action;
1069 #define MPII_CONFIG_REQ_ACTION_PAGE_HEADER		(0x00)
1070 #define MPII_CONFIG_REQ_ACTION_PAGE_READ_CURRENT	(0x01)
1071 #define MPII_CONFIG_REQ_ACTION_PAGE_WRITE_CURRENT	(0x02)
1072 #define MPII_CONFIG_REQ_ACTION_PAGE_DEFAULT		(0x03)
1073 #define MPII_CONFIG_REQ_ACTION_PAGE_WRITE_NVRAM		(0x04)
1074 #define MPII_CONFIG_REQ_ACTION_PAGE_READ_DEFAULT	(0x05)
1075 #define MPII_CONFIG_REQ_ACTION_PAGE_READ_NVRAM		(0x06)
1076 	u_int8_t		sgl_flags;
1077 	u_int8_t		chain_offset;
1078 	u_int8_t		function;
1079 
1080 	u_int16_t		ext_page_len;
1081 	u_int8_t		ext_page_type;
1082 #define MPII_CONFIG_REQ_EXTPAGE_TYPE_SAS_IO_UNIT	(0x10)
1083 #define MPII_CONFIG_REQ_EXTPAGE_TYPE_SAS_EXPANDER	(0x11)
1084 #define MPII_CONFIG_REQ_EXTPAGE_TYPE_SAS_DEVICE		(0x12)
1085 #define MPII_CONFIG_REQ_EXTPAGE_TYPE_SAS_PHY		(0x13)
1086 #define MPII_CONFIG_REQ_EXTPAGE_TYPE_LOG		(0x14)
1087 #define MPI2_CONFIG_EXTPAGETYPE_ENCLOSURE		(0x15)
1088 #define MPI2_CONFIG_EXTPAGETYPE_RAID_CONFIG		(0x16)
1089 #define MPI2_CONFIG_EXTPAGETYPE_DRIVER_MAPPING		(0x17)
1090 #define MPI2_CONFIG_EXTPAGETYPE_SAS_PORT		(0x18)
1091 	u_int8_t		msg_flags;
1092 
1093 	u_int8_t		vp_id;
1094 	u_int8_t		vf_id;
1095 	u_int16_t		reserved1;
1096 
1097 	u_int32_t		reserved2[2];
1098 
1099 	struct mpii_cfg_hdr	config_header;
1100 
1101 	u_int32_t		page_address;
1102 /* XXX lots of defns here */
1103 
1104 	struct mpii_sge		page_buffer;
1105 } __packed __aligned(4);
1106 
1107 struct mpii_msg_config_reply {
1108 	u_int8_t		action;
1109 	u_int8_t		sgl_flags;
1110 	u_int8_t		msg_length;
1111 	u_int8_t		function;
1112 
1113 	u_int16_t		ext_page_length;
1114 	u_int8_t		ext_page_type;
1115 	u_int8_t		msg_flags;
1116 
1117 	u_int8_t		vp_id;
1118 	u_int8_t		vf_id;
1119 	u_int16_t		reserved1;
1120 
1121 	u_int16_t		reserved2;
1122 	u_int16_t		ioc_status;
1123 
1124 	u_int32_t		ioc_loginfo;
1125 
1126 	struct mpii_cfg_hdr	config_header;
1127 } __packed __aligned(4);
1128 
1129 struct mpii_cfg_manufacturing_pg0 {
1130 	struct mpii_cfg_hdr	config_header;
1131 
1132 	char			chip_name[16];
1133 	char			chip_revision[8];
1134 	char			board_name[16];
1135 	char			board_assembly[16];
1136 	char			board_tracer_number[16];
1137 } __packed __aligned(4);
1138 
1139 struct mpii_cfg_ioc_pg1 {
1140 	struct mpii_cfg_hdr     config_header;
1141 
1142 	u_int32_t       flags;
1143 
1144 	u_int32_t       coalescing_timeout;
1145 #define	MPII_CFG_IOC_1_REPLY_COALESCING			(1<<0)
1146 
1147 	u_int8_t        coalescing_depth;
1148 	u_int8_t        pci_slot_num;
1149 	u_int8_t        pci_bus_num;
1150 	u_int8_t        pci_domain_segment;
1151 
1152 	u_int32_t       reserved1;
1153 
1154 	u_int32_t       reserved2;
1155 } __packed __aligned(4);
1156 
1157 struct mpii_cfg_ioc_pg3 {
1158 	struct mpii_cfg_hdr	config_header;
1159 
1160 	u_int8_t		no_phys_disks;
1161 	u_int8_t		reserved[3];
1162 
1163 	/* followed by a list of mpii_cfg_raid_physdisk structs */
1164 } __packed __aligned(4);
1165 
1166 struct mpii_cfg_ioc_pg8 {
1167 	struct mpii_cfg_hdr	config_header;
1168 
1169 	u_int8_t		num_devs_per_enclosure;
1170 	u_int8_t		reserved1;
1171 	u_int16_t		reserved2;
1172 
1173 	u_int16_t		max_persistent_entries;
1174 	u_int16_t		max_num_physical_mapped_ids;
1175 
1176 	u_int16_t		flags;
1177 #define	MPII_IOC_PG8_FLAGS_DA_START_SLOT_1		(1<<5)
1178 #define MPII_IOC_PG8_FLAGS_RESERVED_TARGETID_0		(1<<4)
1179 #define MPII_IOC_PG8_FLAGS_MAPPING_MODE_MASK		(0x0000000e)
1180 #define MPII_IOC_PG8_FLAGS_DEVICE_PERSISTENCE_MAPPING	(0<<1)
1181 #define MPII_IOC_PG8_FLAGS_ENCLOSURE_SLOT_MAPPING	(1<<1)
1182 #define MPII_IOC_PG8_FLAGS_DISABLE_PERSISTENT_MAPPING	(1<<0)
1183 #define	MPII_IOC_PG8_FLAGS_ENABLE_PERSISTENT_MAPPING	(0<<0)
1184 	u_int16_t		reserved3;
1185 
1186 	u_int16_t		ir_volume_mapping_flags;
1187 #define	MPII_IOC_PG8_IRFLAGS_VOLUME_MAPPING_MODE_MASK	(0x00000003)
1188 #define	MPII_IOC_PG8_IRFLAGS_LOW_VOLUME_MAPPING		(0<<0)
1189 #define	MPII_IOC_PG8_IRFLAGS_HIGH_VOLUME_MAPPING	(1<<0)
1190 	u_int16_t		reserved4;
1191 
1192 	u_int32_t		reserved5;
1193 } __packed __aligned(4);
1194 
1195 struct mpii_cfg_raid_physdisk {
1196 	u_int8_t		phys_disk_id;
1197 	u_int8_t		phys_disk_bus;
1198 	u_int8_t		phys_disk_ioc;
1199 	u_int8_t		phys_disk_num;
1200 } __packed __aligned(4);
1201 
1202 struct mpii_cfg_fc_port_pg0 {
1203 	struct mpii_cfg_hdr	config_header;
1204 
1205 	u_int32_t		flags;
1206 
1207 	u_int8_t		mpii_port_nr;
1208 	u_int8_t		link_type;
1209 	u_int8_t		port_state;
1210 	u_int8_t		reserved1;
1211 
1212 	u_int32_t		port_id;
1213 
1214 	u_int64_t		wwnn;
1215 
1216 	u_int64_t		wwpn;
1217 
1218 	u_int32_t		supported_service_class;
1219 
1220 	u_int32_t		supported_speeds;
1221 
1222 	u_int32_t		current_speed;
1223 
1224 	u_int32_t		max_frame_size;
1225 
1226 	u_int64_t		fabric_wwnn;
1227 
1228 	u_int64_t		fabric_wwpn;
1229 
1230 	u_int32_t		discovered_port_count;
1231 
1232 	u_int32_t		max_initiators;
1233 
1234 	u_int8_t		max_aliases_supported;
1235 	u_int8_t		max_hard_aliases_supported;
1236 	u_int8_t		num_current_aliases;
1237 	u_int8_t		reserved2;
1238 } __packed __aligned(4);
1239 
1240 struct mpii_cfg_fc_port_pg1 {
1241 	struct mpii_cfg_hdr	config_header;
1242 
1243 	u_int32_t		flags;
1244 
1245 	u_int64_t		noseepromwwnn;
1246 
1247 	u_int64_t		noseepromwwpn;
1248 
1249 	u_int8_t		hard_alpa;
1250 	u_int8_t		link_config;
1251 	u_int8_t		topology_config;
1252 	u_int8_t		alt_connector;
1253 
1254 	u_int8_t		num_req_aliases;
1255 	u_int8_t		rr_tov;
1256 	u_int8_t		initiator_dev_to;
1257 	u_int8_t		initiator_lo_pend_to;
1258 } __packed __aligned(4);
1259 
1260 struct mpii_cfg_fc_device_pg0 {
1261 	struct mpii_cfg_hdr	config_header;
1262 
1263 	u_int64_t		wwnn;
1264 
1265 	u_int64_t		wwpn;
1266 
1267 	u_int32_t		port_id;
1268 
1269 	u_int8_t		protocol;
1270 	u_int8_t		flags;
1271 	u_int16_t		bb_credit;
1272 
1273 	u_int16_t		max_rx_frame_size;
1274 	u_int8_t		adisc_hard_alpa;
1275 	u_int8_t		port_nr;
1276 
1277 	u_int8_t		fc_ph_low_version;
1278 	u_int8_t		fc_ph_high_version;
1279 	u_int8_t		current_target_id;
1280 	u_int8_t		current_bus;
1281 } __packed __aligned(4);
1282 
1283 #define MPII_CFG_RAID_VOL_ADDR_HANDLE		(1<<28)
1284 
1285 struct mpii_cfg_raid_vol_pg0 {
1286 	struct mpii_cfg_hdr	config_header;
1287 
1288 	u_int16_t		volume_handle;
1289 	u_int8_t		volume_state;
1290 #define MPII_CFG_RAID_VOL_0_STATE_MISSING		(0x00)
1291 #define MPII_CFG_RAID_VOL_0_STATE_FAILED		(0x01)
1292 #define MPII_CFG_RAID_VOL_0_STATE_INITIALIZING		(0x02)
1293 #define MPII_CFG_RAID_VOL_0_STATE_ONLINE		(0x03)
1294 #define MPII_CFG_RAID_VOL_0_STATE_DEGRADED		(0x04)
1295 #define MPII_CFG_RAID_VOL_0_STATE_OPTIMAL		(0x05)
1296 	u_int8_t		volume_type;
1297 #define MPII_CFG_RAID_VOL_0_TYPE_RAID0			(0x00)
1298 #define MPII_CFG_RAID_VOL_0_TYPE_RAID1E			(0x01)
1299 #define MPII_CFG_RAID_VOL_0_TYPE_RAID1			(0x02)
1300 #define MPII_CFG_RAID_VOL_0_TYPE_RAID10			(0x05)
1301 #define MPII_CFG_RAID_VOL_0_TYPE_UNKNOWN		(0xff)
1302 
1303 	u_int32_t		volume_status;
1304 #define MPII_CFG_RAID_VOL_0_STATUS_SCRUB		(1<<20)
1305 #define MPII_CFG_RAID_VOL_0_STATUS_RESYNC		(1<<16)
1306 
1307 	u_int16_t		volume_settings;
1308 #define MPII_CFG_RAID_VOL_0_SETTINGS_CACHE_MASK		(0x3<<0)
1309 #define MPII_CFG_RAID_VOL_0_SETTINGS_CACHE_UNCHANGED	(0x0<<0)
1310 #define MPII_CFG_RAID_VOL_0_SETTINGS_CACHE_DISABLED	(0x1<<0)
1311 #define MPII_CFG_RAID_VOL_0_SETTINGS_CACHE_ENABLED	(0x2<<0)
1312 
1313 	u_int8_t		hot_spare_pool;
1314 	u_int8_t		reserved1;
1315 
1316 	u_int64_t		max_lba;
1317 
1318 	u_int32_t		stripe_size;
1319 
1320 	u_int16_t		block_size;
1321 	u_int16_t		reserved2;
1322 
1323 	u_int8_t		phys_disk_types;
1324 	u_int8_t		resync_rate;
1325 	u_int16_t		data_scrub_rate;
1326 
1327 	u_int8_t		num_phys_disks;
1328 	u_int16_t		reserved3;
1329 	u_int8_t		inactive_status;
1330 #define MPII_CFG_RAID_VOL_0_INACTIVE_UNKNOWN		(0x00)
1331 #define MPII_CFG_RAID_VOL_0_INACTIVE_STALE_META		(0x01)
1332 #define MPII_CFG_RAID_VOL_0_INACTIVE_FOREIGN_VOL	(0x02)
1333 #define MPII_CFG_RAID_VOL_0_INACTIVE_NO_RESOURCES	(0x03)
1334 #define MPII_CFG_RAID_VOL_0_INACTIVE_CLONED_VOL		(0x04)
1335 #define MPII_CFG_RAID_VOL_0_INACTIVE_INSUF_META		(0x05)
1336 
1337 	/* followed by a list of mpii_cfg_raid_vol_pg0_physdisk structs */
1338 } __packed __aligned(4);
1339 
1340 struct mpii_cfg_raid_vol_pg0_physdisk {
1341 	u_int8_t		raid_set_num;
1342 	u_int8_t		phys_disk_map;
1343 	u_int8_t		phys_disk_num;
1344 	u_int8_t		reserved;
1345 } __packed __aligned(4);
1346 
1347 struct mpii_cfg_raid_vol_pg1 {
1348 	struct mpii_cfg_hdr	config_header;
1349 
1350 	u_int8_t		volume_id;
1351 	u_int8_t		volume_bus;
1352 	u_int8_t		volume_ioc;
1353 	u_int8_t		reserved1;
1354 
1355 	u_int8_t		guid[24];
1356 
1357 	u_int8_t		name[32];
1358 
1359 	u_int64_t		wwid;
1360 
1361 	u_int32_t		reserved2;
1362 
1363 	u_int32_t		reserved3;
1364 } __packed __aligned(4);
1365 
1366 #define MPII_CFG_RAID_PHYS_DISK_ADDR_NUMBER		(1<<28)
1367 
1368 struct mpii_cfg_raid_physdisk_pg0 {
1369 	struct mpii_cfg_hdr	config_header;
1370 
1371 	u_int16_t		dev_handle;
1372 	u_int8_t		reserved1;
1373 	u_int8_t		phys_disk_num;
1374 
1375 	u_int8_t		enc_id;
1376 	u_int8_t		enc_bus;
1377 	u_int8_t		hot_spare_pool;
1378 	u_int8_t		enc_type;
1379 #define MPII_CFG_RAID_PHYDISK_0_ENCTYPE_NONE		(0x0)
1380 #define MPII_CFG_RAID_PHYDISK_0_ENCTYPE_SAFTE		(0x1)
1381 #define MPII_CFG_RAID_PHYDISK_0_ENCTYPE_SES		(0x2)
1382 
1383 	u_int32_t		reserved2;
1384 
1385 	u_int8_t		vendor_id[8];
1386 
1387 	u_int8_t		product_id[16];
1388 
1389 	u_int8_t		product_rev[4];
1390 
1391 	u_int8_t		serial[32];
1392 
1393 	u_int32_t		reserved3;
1394 
1395 	u_int8_t		phys_disk_state;
1396 #define MPII_CFG_RAID_PHYDISK_0_STATE_NOTCONFIGURED	(0x00)
1397 #define MPII_CFG_RAID_PHYDISK_0_STATE_NOTCOMPATIBLE	(0x01)
1398 #define MPII_CFG_RAID_PHYDISK_0_STATE_OFFLINE		(0x02)
1399 #define MPII_CFG_RAID_PHYDISK_0_STATE_ONLINE		(0x03)
1400 #define MPII_CFG_RAID_PHYDISK_0_STATE_HOTSPARE		(0x04)
1401 #define MPII_CFG_RAID_PHYDISK_0_STATE_DEGRADED		(0x05)
1402 #define MPII_CFG_RAID_PHYDISK_0_STATE_REBUILDING	(0x06)
1403 #define MPII_CFG_RAID_PHYDISK_0_STATE_OPTIMAL		(0x07)
1404 	u_int8_t		offline_reason;
1405 #define MPII_CFG_RAID_PHYDISK_0_OFFLINE_MISSING		(0x01)
1406 #define MPII_CFG_RAID_PHYDISK_0_OFFLINE_FAILED		(0x03)
1407 #define MPII_CFG_RAID_PHYDISK_0_OFFLINE_INITIALIZING	(0x04)
1408 #define MPII_CFG_RAID_PHYDISK_0_OFFLINE_REQUESTED	(0x05)
1409 #define MPII_CFG_RAID_PHYDISK_0_OFFLINE_FAILEDREQ	(0x06)
1410 #define MPII_CFG_RAID_PHYDISK_0_OFFLINE_OTHER		(0xff)
1411 
1412 	u_int8_t		incompat_reason;
1413 	u_int8_t		phys_disk_attrs;
1414 
1415 	u_int32_t		phys_disk_status;
1416 #define MPII_CFG_RAID_PHYDISK_0_STATUS_OUTOFSYNC	(1<<0)
1417 #define MPII_CFG_RAID_PHYDISK_0_STATUS_QUIESCED		(1<<1)
1418 
1419 	u_int64_t		dev_max_lba;
1420 
1421 	u_int64_t		host_max_lba;
1422 
1423 	u_int64_t		coerced_max_lba;
1424 
1425 	u_int16_t		block_size;
1426 	u_int16_t		reserved4;
1427 
1428 	u_int32_t		reserved5;
1429 } __packed __aligned(4);
1430 
1431 struct mpii_cfg_raid_physdisk_pg1 {
1432 	struct mpii_cfg_hdr	config_header;
1433 
1434 	u_int8_t		num_phys_disk_paths;
1435 	u_int8_t		phys_disk_num;
1436 	u_int16_t		reserved1;
1437 
1438 	u_int32_t		reserved2;
1439 
1440 	/* followed by mpii_cfg_raid_physdisk_path structs */
1441 } __packed __aligned(4);
1442 
1443 struct mpii_cfg_raid_physdisk_path {
1444 	u_int8_t		phys_disk_id;
1445 	u_int8_t		phys_disk_bus;
1446 	u_int16_t		reserved1;
1447 
1448 	u_int64_t		wwwid;
1449 
1450 	u_int64_t		owner_wwid;
1451 
1452 	u_int8_t		ownder_id;
1453 	u_int8_t		reserved2;
1454 	u_int16_t		flags;
1455 #define MPII_CFG_RAID_PHYDISK_PATH_INVALID	(1<<0)
1456 #define MPII_CFG_RAID_PHYDISK_PATH_BROKEN	(1<<1)
1457 } __packed __aligned(4);
1458 
1459 #define MPII_CFG_SAS_DEV_ADDR_NEXT		(0<<28)
1460 #define MPII_CFG_SAS_DEV_ADDR_BUS		(1<<28)
1461 #define MPII_CFG_SAS_DEV_ADDR_HANDLE		(2<<28)
1462 
1463 struct mpii_cfg_sas_dev_pg0 {
1464 	struct mpii_ecfg_hdr	config_header;
1465 
1466 	u_int16_t		slot;
1467 	u_int16_t		enc_handle;
1468 
1469 	u_int64_t		sas_addr;
1470 
1471 	u_int16_t		parent_dev_handle;
1472 	u_int8_t		phy_num;
1473 	u_int8_t		access_status;
1474 
1475 	u_int16_t		dev_handle;
1476 	u_int8_t		target;
1477 	u_int8_t		bus;
1478 
1479 	u_int32_t		device_info;
1480 #define MPII_CFG_SAS_DEV_0_DEVINFO_TYPE			(0x7)
1481 #define MPII_CFG_SAS_DEV_0_DEVINFO_TYPE_NONE		(0x0)
1482 #define MPII_CFG_SAS_DEV_0_DEVINFO_TYPE_END		(0x1)
1483 #define MPII_CFG_SAS_DEV_0_DEVINFO_TYPE_EDGE_EXPANDER	(0x2)
1484 #define MPII_CFG_SAS_DEV_0_DEVINFO_TYPE_FANOUT_EXPANDER	(0x3)
1485 #define MPII_CFG_SAS_DEV_0_DEVINFO_SATA_HOST		(1<<3)
1486 #define MPII_CFG_SAS_DEV_0_DEVINFO_SMP_INITIATOR	(1<<4)
1487 #define MPII_CFG_SAS_DEV_0_DEVINFO_STP_INITIATOR	(1<<5)
1488 #define MPII_CFG_SAS_DEV_0_DEVINFO_SSP_INITIATOR	(1<<6)
1489 #define MPII_CFG_SAS_DEV_0_DEVINFO_SATA_DEVICE		(1<<7)
1490 #define MPII_CFG_SAS_DEV_0_DEVINFO_SMP_TARGET		(1<<8)
1491 #define MPII_CFG_SAS_DEV_0_DEVINFO_STP_TARGET		(1<<9)
1492 #define MPII_CFG_SAS_DEV_0_DEVINFO_SSP_TARGET		(1<<10)
1493 #define MPII_CFG_SAS_DEV_0_DEVINFO_DIRECT_ATTACHED	(1<<11)
1494 #define MPII_CFG_SAS_DEV_0_DEVINFO_LSI_DEVICE		(1<<12)
1495 #define MPII_CFG_SAS_DEV_0_DEVINFO_ATAPI_DEVICE		(1<<13)
1496 #define MPII_CFG_SAS_DEV_0_DEVINFO_SEP_DEVICE		(1<<14)
1497 
1498 	u_int16_t		flags;
1499 #define MPII_CFG_SAS_DEV_0_FLAGS_DEV_PRESENT		(1<<0)
1500 #define MPII_CFG_SAS_DEV_0_FLAGS_DEV_MAPPED		(1<<1)
1501 #define MPII_CFG_SAS_DEV_0_FLAGS_DEV_MAPPED_PERSISTENT	(1<<2)
1502 #define MPII_CFG_SAS_DEV_0_FLAGS_SATA_PORT_SELECTOR	(1<<3)
1503 #define MPII_CFG_SAS_DEV_0_FLAGS_SATA_FUA		(1<<4)
1504 #define MPII_CFG_SAS_DEV_0_FLAGS_SATA_NCQ		(1<<5)
1505 #define MPII_CFG_SAS_DEV_0_FLAGS_SATA_SMART		(1<<6)
1506 #define MPII_CFG_SAS_DEV_0_FLAGS_SATA_LBA48		(1<<7)
1507 #define MPII_CFG_SAS_DEV_0_FLAGS_UNSUPPORTED		(1<<8)
1508 #define MPII_CFG_SAS_DEV_0_FLAGS_SATA_SETTINGS		(1<<9)
1509 	u_int8_t		physical_port;
1510 	u_int8_t		max_port_conn;
1511 
1512 	u_int64_t		device_name;
1513 
1514 	u_int8_t		port_groups;
1515 	u_int8_t		dma_group;
1516 	u_int8_t		ctrl_group;
1517 	u_int8_t		reserved1;
1518 
1519 	u_int64_t		reserved2;
1520 } __packed __aligned(4);
1521 
1522 #define MPII_CFG_RAID_CONFIG_ACTIVE_CONFIG		(2<<28)
1523 
1524 struct mpii_cfg_raid_config_pg0 {
1525 	struct	mpii_ecfg_hdr	config_header;
1526 
1527 	u_int8_t		num_hot_spares;
1528 	u_int8_t		num_phys_disks;
1529 	u_int8_t		num_volumes;
1530 	u_int8_t		config_num;
1531 
1532 	u_int32_t		flags;
1533 #define MPII_CFG_RAID_CONFIG_0_FLAGS_NATIVE		(0<<0)
1534 #define MPII_CFG_RAID_CONFIG_0_FLAGS_FOREIGN		(1<<0)
1535 
1536 	u_int32_t		config_guid[6];
1537 
1538 	u_int32_t		reserved1;
1539 
1540 	u_int8_t		num_elements;
1541 	u_int8_t		reserved2[3];
1542 
1543 	/* followed by struct mpii_raid_config_element structs */
1544 } __packed __aligned(4);
1545 
1546 struct mpii_raid_config_element {
1547 	u_int16_t		element_flags;
1548 #define MPII_RAID_CONFIG_ELEMENT_FLAG_VOLUME		(0x0)
1549 #define MPII_RAID_CONFIG_ELEMENT_FLAG_VOLUME_PHYS_DISK	(0x1)
1550 #define	MPII_RAID_CONFIG_ELEMENT_FLAG_HSP_PHYS_DISK	(0x2)
1551 #define MPII_RAID_CONFIG_ELEMENT_ONLINE_CE_PHYS_DISK	(0x3)
1552 	u_int16_t		vol_dev_handle;
1553 
1554 	u_int8_t		hot_spare_pool;
1555 	u_int8_t		phys_disk_num;
1556 	u_int16_t		phys_disk_dev_handle;
1557 } __packed __aligned(4);
1558 
1559 struct mpii_cfg_dpm_pg0 {
1560 	struct mpii_ecfg_hdr	config_header;
1561 #define MPII_DPM_ADDRESS_FORM_MASK			(0xf0000000)
1562 #define MPII_DPM_ADDRESS_FORM_ENTRY_RANGE		(0x00000000)
1563 #define MPII_DPM_ADDRESS_ENTRY_COUNT_MASK		(0x0fff0000)
1564 #define MPII_DPM_ADDRESS_ENTRY_COUNT_SHIFT		(16)
1565 #define MPII_DPM_ADDRESS_START_ENTRY_MASK		(0x0000ffff)
1566 
1567 	/* followed by struct mpii_dpm_entry structs */
1568 } __packed __aligned(4);
1569 
1570 struct mpii_dpm_entry {
1571 	u_int64_t		physical_identifier;
1572 
1573 	u_int16_t		mapping_information;
1574 	u_int16_t		device_index;
1575 
1576 	u_int32_t		physical_bits_mapping;
1577 
1578 	u_int32_t		reserved1;
1579 } __packed __aligned(4);
1580 
1581 struct mpii_evt_sas_discovery {
1582 	u_int8_t		flags;
1583 #define	MPII_EVENT_SAS_DISC_FLAGS_DEV_CHANGE_MASK	(1<<1)
1584 #define MPII_EVENT_SAS_DISC_FLAGS_DEV_CHANGE_NO_CHANGE	(0<<1)
1585 #define MPII_EVENT_SAS_DISC_FLAGS_DEV_CHANGE_CHANGE	(1<<1)
1586 #define MPII_EVENT_SAS_DISC_FLAGS_DISC_IN_PROG_MASK	(1<<0)
1587 #define MPII_EVENT_SAS_DISC_FLAGS_DISC_NOT_IN_PROGRESS	(1<<0)
1588 #define MPII_EVENT_SAS_DISC_FLAGS_DISC_IN_PROGRESS	(0<<0)
1589 	u_int8_t		reason_code;
1590 #define MPII_EVENT_SAS_DISC_REASON_CODE_STARTED		(0x01)
1591 #define	MPII_EVENT_SAS_DISC_REASON_CODE_COMPLETED	(0x02)
1592 	u_int8_t		physical_port;
1593 	u_int8_t		reserved1;
1594 
1595 	u_int32_t		discovery_status;
1596 } __packed __aligned(4);
1597 
1598 struct mpii_evt_ir_status {
1599 	u_int16_t		vol_dev_handle;
1600 	u_int16_t		reserved1;
1601 
1602 	u_int8_t		operation;
1603 #define MPII_EVENT_IR_RAIDOP_RESYNC			(0x00)
1604 #define MPII_EVENT_IR_RAIDOP_OCE			(0x01)
1605 #define MPII_EVENT_IR_RAIDOP_CONS_CHECK			(0x02)
1606 #define MPII_EVENT_IR_RAIDOP_BG_INIT			(0x03)
1607 #define MPII_EVENT_IR_RAIDOP_MAKE_CONS			(0x04)
1608 	u_int8_t		percent;
1609 	u_int16_t		reserved2;
1610 
1611 	u_int32_t		reserved3;
1612 };
1613 
1614 struct mpii_evt_ir_volume {
1615 	u_int16_t		vol_dev_handle;
1616 	u_int8_t		reason_code;
1617 #define MPII_EVENT_IR_VOL_RC_SETTINGS_CHANGED		(0x01)
1618 #define MPII_EVENT_IR_VOL_RC_STATUS_CHANGED		(0x02)
1619 #define MPII_EVENT_IR_VOL_RC_STATE_CHANGED		(0x03)
1620 	u_int8_t		reserved1;
1621 
1622 	u_int32_t		new_value;
1623 	u_int32_t		prev_value;
1624 } __packed __aligned(4);
1625 
1626 struct mpii_evt_ir_physical_disk {
1627 	u_int16_t		reserved1;
1628 	u_int8_t		reason_code;
1629 #define MPII_EVENT_IR_PD_RC_SETTINGS_CHANGED		(0x01)
1630 #define MPII_EVENT_IR_PD_RC_STATUS_FLAGS_CHANGED	(0x02)
1631 #define MPII_EVENT_IR_PD_RC_STATUS_CHANGED		(0x03)
1632 	u_int8_t		phys_disk_num;
1633 
1634 	u_int16_t		phys_disk_dev_handle;
1635 	u_int16_t		reserved2;
1636 
1637 	u_int16_t		slot;
1638 	u_int16_t		enclosure_handle;
1639 
1640 	u_int32_t		new_value;
1641 	u_int32_t		previous_value;
1642 } __packed __aligned(4);
1643 
1644 struct mpii_evt_sas_tcl {
1645 	u_int16_t		enclosure_handle;
1646 	u_int16_t		expander_handle;
1647 
1648 	u_int8_t		num_phys;
1649 	u_int8_t		reserved1[3];
1650 
1651 	u_int8_t		num_entries;
1652 	u_int8_t		start_phy_num;
1653 	u_int8_t		expn_status;
1654 #define	MPII_EVENT_SAS_TOPO_ES_ADDED			(0x01)
1655 #define MPII_EVENT_SAS_TOPO_ES_NOT_RESPONDING		(0x02)
1656 #define MPII_EVENT_SAS_TOPO_ES_RESPONDING		(0x03)
1657 #define MPII_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING	(0x04)
1658 	u_int8_t		physical_port;
1659 
1660 	/* followed by num_entries number of struct mpii_evt_phy_entry */
1661 } __packed __aligned(4);
1662 
1663 struct mpii_evt_phy_entry {
1664 	u_int16_t		dev_handle;
1665 	u_int8_t		link_rate;
1666 	u_int8_t		phy_status;
1667 #define MPII_EVENT_SAS_TOPO_PS_RC_MASK			(0x0f)
1668 #define MPII_EVENT_SAS_TOPO_PS_RC_ADDED			(0x01)
1669 #define MPII_EVENT_SAS_TOPO_PS_RC_MISSING		(0x02)
1670 } __packed __aligned(4);
1671 
1672 struct mpii_evt_ir_cfg_change_list {
1673 	u_int8_t		num_elements;
1674 	u_int16_t		reserved;
1675 	u_int8_t		config_num;
1676 
1677 	u_int32_t		flags;
1678 #define MPII_EVT_IR_CFG_CHANGE_LIST_FOREIGN		(0x1)
1679 
1680 	/* followed by num_elements struct mpii_evt_ir_cfg_elements */
1681 } __packed __aligned(4);
1682 
1683 struct mpii_evt_ir_cfg_element {
1684 	u_int16_t		element_flags;
1685 #define MPII_EVT_IR_CFG_ELEMENT_TYPE_MASK		(0xf)
1686 #define MPII_EVT_IR_CFG_ELEMENT_TYPE_VOLUME		(0x0)
1687 #define MPII_EVT_IR_CFG_ELEMENT_TYPE_VOLUME_DISK	(0x1)
1688 #define MPII_EVT_IR_CFG_ELEMENT_TYPE_HOT_SPARE		(0x2)
1689 	u_int16_t		vol_dev_handle;
1690 
1691 	u_int8_t		reason_code;
1692 #define MPII_EVT_IR_CFG_ELEMENT_RC_ADDED		(0x01)
1693 #define MPII_EVT_IR_CFG_ELEMENT_RC_REMOVED		(0x02)
1694 #define MPII_EVT_IR_CFG_ELEMENT_RC_NO_CHANGE		(0x03)
1695 #define MPII_EVT_IR_CFG_ELEMENT_RC_HIDE			(0x04)
1696 #define MPII_EVT_IR_CFG_ELEMENT_RC_UNHIDE		(0x05)
1697 #define MPII_EVT_IR_CFG_ELEMENT_RC_VOLUME_CREATED	(0x06)
1698 #define MPII_EVT_IR_CFG_ELEMENT_RC_VOLUME_DELETED	(0x07)
1699 #define MPII_EVT_IR_CFG_ELEMENT_RC_PD_CREATED		(0x08)
1700 #define MPII_EVT_IR_CFG_ELEMENT_RC_PD_DELETED		(0x09)
1701 	u_int8_t		phys_disk_num;
1702 	u_int16_t		phys_disk_dev_handle;
1703 } __packed __aligned(4);
1704