xref: /freebsd/sys/dev/smartpqi/smartpqi_structures.h (revision 22cf89c938886d14f5796fc49f9f020c23ea8eaf)
1 /*-
2  * Copyright 2016-2023 Microchip Technology, Inc. and/or its subsidiaries.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23  * SUCH DAMAGE.
24  */
25 
26 
27 #ifndef _PQI_STRUCTURES_H
28 #define _PQI_STRUCTURES_H
29 
30 
31 #include "smartpqi_defines.h"
32 
33 struct bmic_host_wellness_driver_version {
34 	uint8_t		start_tag[4];
35 	uint8_t		driver_version_tag[2];
36 	uint16_t	driver_version_length;
37 	char		driver_version[32];
38 	uint8_t		end_tag[2];
39 
40 }OS_ATTRIBUTE_PACKED;
41 
42 
43 struct bmic_host_wellness_time {
44 	uint8_t		start_tag[4];
45 	uint8_t		time_tag[2];
46 	uint16_t	time_length;
47 	uint8_t		hour;
48 	uint8_t		min;
49 	uint8_t		sec;
50 	uint8_t		reserved;
51 	uint8_t		month;
52 	uint8_t		day;
53 	uint8_t		century;
54 	uint8_t		year;
55 	uint8_t		dont_write_tag[2];
56 	uint8_t		end_tag[2];
57 
58 }OS_ATTRIBUTE_PACKED;
59 
60 
61 /* As per PQI Spec pqi-2r00a , 6.2.2. */
62 
63 /* device capability register , for admin q table 24 */
64 struct pqi_dev_adminq_cap {
65 	uint8_t		max_admin_ibq_elem;
66 	uint8_t		max_admin_obq_elem;
67 	uint8_t		admin_ibq_elem_len;
68 	uint8_t		admin_obq_elem_len;
69 	uint16_t	max_pqi_dev_reset_tmo;
70 	uint8_t		res[2];
71 }OS_ATTRIBUTE_PACKED;
72 
73 /* admin q parameter reg , table 36 */
74 struct admin_q_param {
75 	uint8_t		num_iq_elements;
76 	uint8_t		num_oq_elements;
77 	uint8_t		intr_msg_num;
78 	uint8_t		msix_disable;
79 }OS_ATTRIBUTE_PACKED;
80 
81 struct pqi_registers {
82 	uint64_t		signature;
83 	uint64_t		admin_q_config;
84 	uint64_t	 	pqi_dev_adminq_cap;
85 	uint32_t		legacy_intr_status;
86 	uint32_t		legacy_intr_mask_set;
87 	uint32_t		legacy_intr_mask_clr;
88 	uint8_t			res1[28];
89 	uint32_t		pqi_dev_status;
90 	uint8_t			res2[4];
91 	uint64_t		admin_ibq_pi_offset;
92 	uint64_t		admin_obq_ci_offset;
93 	uint64_t		admin_ibq_elem_array_addr;
94 	uint64_t		admin_obq_elem_array_addr;
95 	uint64_t		admin_ibq_ci_addr;
96 	uint64_t		admin_obq_pi_addr;
97 	uint32_t	 	admin_q_param;
98 	uint8_t			res3[4];
99 	uint32_t		pqi_dev_err;
100 	uint8_t			res4[4];
101 	uint64_t		error_details;
102 	uint32_t		dev_reset;
103 	uint32_t		power_action;
104 	uint8_t			res5[104];
105 }OS_ATTRIBUTE_PACKED;
106 
107 /*
108  * IOA controller registers
109  * Mapped in PCIe BAR 0.
110  */
111 
112 struct ioa_registers {
113 	uint8_t		res1[0x18];
114 	uint32_t	host_to_ioa_db_mask_clr; 	/* 18h */
115 	uint8_t		res2[4];
116 	uint32_t	host_to_ioa_db;			/* 20h */
117 	uint8_t		res3[4];
118 	uint32_t	host_to_ioa_db_clr;		/* 28h */
119 	uint8_t		res4[8];
120 	uint32_t	ioa_to_host_glob_int_mask;	/* 34h */
121 	uint8_t		res5[0x64];
122 	uint32_t	ioa_to_host_db;			/* 9Ch */
123 	uint32_t	ioa_to_host_db_clr;		/* A0h */
124 	uint8_t		res6[4];
125 	uint32_t	ioa_to_host_db_mask;		/* A8h */
126 	uint32_t	ioa_to_host_db_mask_clr;	/* ACh */
127 	uint32_t	scratchpad0;			/* B0h */
128 	uint32_t	scratchpad1;			/* B4h */
129 	uint32_t	scratchpad2;			/* B8h */
130 	uint32_t	scratchpad3_fw_status;		/* BCh */
131 	uint8_t		res7[8];
132 	uint32_t	scratchpad4;			/* C8h */
133 	uint8_t		res8[0xf34];			/* 0xC8 + 4 + 0xf34 = 1000h */
134 	uint32_t	mb[8];				/* 1000h */
135 }OS_ATTRIBUTE_PACKED;
136 
137 
138 /* PQI Preferred settings */
139 struct pqi_pref_settings {
140 	uint16_t	max_cmd_size;
141 	uint16_t	max_fib_size;
142 }OS_ATTRIBUTE_PACKED;
143 
144 /* pqi capability by sis interface */
145 struct pqi_cap {
146 	uint32_t	max_sg_elem;
147 	uint32_t	max_transfer_size;
148 	uint32_t	max_outstanding_io;
149 	uint32_t	conf_tab_off;
150 	uint32_t	conf_tab_sz;
151 }OS_ATTRIBUTE_PACKED;
152 
153 struct pqi_conf_table {
154 	uint8_t		sign[8];		/* "CFGTABLE" */
155 	uint32_t	first_section_off;
156 };
157 
158 struct pqi_conf_table_section_header {
159 	uint16_t	section_id;
160 	uint16_t	next_section_off;
161 };
162 
163 struct pqi_conf_table_general_info {
164 	struct pqi_conf_table_section_header header;
165 	uint32_t	section_len;
166 	uint32_t	max_outstanding_req;
167 	uint32_t	max_sg_size;
168 	uint32_t	max_sg_per_req;
169 };
170 
171 struct pqi_conf_table_debug {
172 	struct pqi_conf_table_section_header header;
173 	uint32_t	scratchpad;
174 };
175 
176 struct pqi_conf_table_heartbeat {
177 	struct pqi_conf_table_section_header header;
178 	uint32_t	heartbeat_counter;
179 };
180 
181 typedef union pqi_reset_reg {
182 	struct {
183 		uint32_t reset_type : 3;
184 		uint32_t reserved : 2;
185 		uint32_t reset_action : 3;
186 		uint32_t hold_in_pd1 : 1;
187 		uint32_t reserved2 : 23;
188 	} bits;
189 	uint32_t all_bits;
190 }pqi_reset_reg_t;
191 
192 /* Memory descriptor for DMA memory allocation */
193 typedef struct dma_mem {
194 	void			*virt_addr;
195    dma_addr_t 		dma_addr;
196 	uint32_t 		size;
197 	uint32_t 		align;
198 	char 			tag[32];
199    bus_dma_tag_t dma_tag;
200    bus_dmamap_t dma_map;
201 }dma_mem_t;
202 
203 /* Lock should be 8 byte aligned
204    TODO : need to apply aligned for lock alone  ?
205 */
206 
207 #ifndef LOCKFREE_STACK
208 
209 typedef struct pqi_taglist {
210         uint32_t        max_elem;
211         uint32_t        num_elem;
212         uint32_t        head;
213         uint32_t        tail;
214         uint32_t       	*elem_array;
215 	boolean_t       lockcreated;
216 	char            lockname[LOCKNAME_SIZE];
217 	OS_LOCK_T       lock	OS_ATTRIBUTE_ALIGNED(8);
218 }pqi_taglist_t;
219 
220 #else	/* LOCKFREE_STACK */
221 
222 union head_list {
223         struct {
224                 uint32_t        seq_no; /* To avoid aba problem */
225                 uint32_t        index;  /* Index at the top of the stack */
226         }top;
227         uint64_t        data;
228 };
229 /* lock-free stack used to push and pop the tag used for IO request */
230 typedef struct  lockless_stack {
231 	uint32_t	*next_index_array;
232 	uint32_t	max_elem;/*No.of total elements*/
233 	uint32_t	num_elem;/*No.of present elements*/
234 	volatile union	head_list      head	OS_ATTRIBUTE_ALIGNED(8);
235 }lockless_stack_t;
236 
237 #endif /* LOCKFREE_STACK */
238 
239 /*
240  * PQI SGL descriptor layouts.
241  */
242 /*
243  * SGL (Scatter Gather List) descriptor Codes
244  */
245 
246 #define SGL_DESCRIPTOR_CODE_DATA_BLOCK                     0x0
247 #define SGL_DESCRIPTOR_CODE_BIT_BUCKET                     0x1
248 #define SGL_DESCRIPTOR_CODE_STANDARD_SEGMENT               0x2
249 #define SGL_DESCRIPTOR_CODE_LAST_STANDARD_SEGMENT          0x3
250 #define SGL_DESCRIPTOR_CODE_LAST_ALTERNATIVE_SGL_SEGMENT   0x4
251 #define SGL_DESCRIPTOR_CODE_VENDOR_SPECIFIC                0xF
252 
253 typedef struct sgl_descriptor
254 {
255 	uint64_t	addr;	/* !< Bytes 0-7.  The starting 64-bit memory byte address of the data block. */
256 	uint32_t	length;	/* !< Bytes 8-11.  The length in bytes of the data block.  Set to 0x00000000 specifies that no data be transferred. */
257 	uint8_t		res[3];	/* !< Bytes 12-14. */
258 	uint8_t     zero : 4; /* !< Byte 15, Bits 0-3. */
259 	uint8_t     type : 4; /* !< Byte 15, Bits 4-7. sgl descriptor type */
260 } sg_desc_t;
261 
262 /* PQI IUs */
263 typedef struct iu_header
264 {
265 	uint8_t		iu_type;
266 	uint8_t		comp_feature;
267 	uint16_t	iu_length;
268 }OS_ATTRIBUTE_PACKED iu_header_t;
269 
270 
271 typedef struct general_admin_request /* REPORT_PQI_DEVICE_CAPABILITY, REPORT_MANUFACTURER_INFO,  REPORT_OPERATIONAL_IQ,  REPORT_OPERATIONAL_OQ all same layout. */
272 {
273 	iu_header_t	header;		/* !< Bytes 0-3. */
274 	uint16_t	res1;
275 	uint16_t	work;
276 	uint16_t	req_id;		/* !< Bytes 8-9. request identifier */
277 	uint8_t		fn_code;	/* !< Byte 10. which administrator function */
278 	union {
279 		struct {
280 			uint8_t		res2[33];	/* !< Bytes 11-43. function specific */
281 			uint32_t	buf_size;	/* !< Bytes 44-47. size in bytes of the Data-In/Out Buffer */
282 			sg_desc_t	sg_desc;	/* !< Bytes 48-63. SGL */
283         } OS_ATTRIBUTE_PACKED general_func;
284 
285 		struct {
286 			uint8_t		res1;
287 			uint16_t	qid;
288 			uint8_t		res2[2];
289 			uint64_t	elem_arr_addr;
290 			uint64_t	iq_ci_addr;
291 			uint16_t	num_elem;
292 			uint16_t	elem_len;
293 			uint8_t		queue_proto;
294 			uint8_t		arb_prio;
295 			uint8_t		res3[22];
296 			uint32_t	vend_specific;
297         } OS_ATTRIBUTE_PACKED create_op_iq;
298 
299 		struct {
300 			uint8_t		res1;
301 			uint16_t	qid;
302 			uint8_t		res2[2];
303 			uint64_t	elem_arr_addr;
304 			uint64_t	ob_pi_addr;
305 			uint16_t	num_elem;
306 			uint16_t	elem_len;
307 			uint8_t		queue_proto;
308 			uint8_t		res3[3];
309 			uint16_t	intr_msg_num;
310 			uint16_t	coales_count;
311 			uint32_t	min_coales_time;
312 			uint32_t	max_coales_time;
313 			uint8_t		res4[8];
314 			uint32_t	vend_specific;
315         } OS_ATTRIBUTE_PACKED create_op_oq;
316 
317 		struct {
318 			uint8_t		res1;
319 			uint16_t	qid;
320 			uint8_t		res2[50];
321         } OS_ATTRIBUTE_PACKED delete_op_queue;
322 
323 		struct {
324 			uint8_t		res1;
325 			uint16_t	qid;
326 			uint8_t		res2[46];
327 			uint32_t	vend_specific;
328         } OS_ATTRIBUTE_PACKED change_op_iq_prop;
329 
330     } OS_ATTRIBUTE_PACKED req_type;
331 
332 }OS_ATTRIBUTE_PACKED gen_adm_req_iu_t;
333 
334 
335 typedef struct general_admin_response {
336 	iu_header_t 	header;
337 	uint16_t	res1;
338 	uint16_t	work;
339 	uint16_t	req_id;
340 	uint8_t		fn_code;
341 	uint8_t		status;
342 	union {
343 		struct {
344 			uint8_t		status_desc[4];
345 			uint64_t	pi_offset;
346 			uint8_t		res[40];
347         }  OS_ATTRIBUTE_PACKED  create_op_iq;
348 
349 		struct {
350 			uint8_t		status_desc[4];
351 			uint64_t	ci_offset;
352 			uint8_t		res[40];
353         }  OS_ATTRIBUTE_PACKED  create_op_oq;
354     }  OS_ATTRIBUTE_PACKED  resp_type;
355 } OS_ATTRIBUTE_PACKED gen_adm_resp_iu_t ;
356 
357 /*report and set Event config IU*/
358 
359 typedef struct pqi_event_config_request {
360 	iu_header_t   	header;
361 	uint16_t	 	response_queue_id;	/* specifies the OQ where the response
362 					                              IU is to be delivered */
363 	uint8_t	    	work_area[2];	/* reserved for driver use */
364 	uint16_t	    request_id;
365 	union {
366 		uint16_t  	reserved;           /* Report event config iu */
367 		uint16_t  	global_event_oq_id; /* Set event config iu */
368 	}iu_specific;
369 	uint32_t	    buffer_length;
370 	sg_desc_t     	sg_desc;
371 }pqi_event_config_request_t;
372 #if 0
373 typedef struct pqi_set_event_config_request {
374 	iu_header_t  header;
375 	uint16_t  	response_queue_id;  /* specifies the OQ where the response
376 													IU is to be delivered */
377 	uint8_t   	work_area[2];   /* reserved for driver use */
378 	uint16_t	request_id;
379 	uint16_t	global_event_oq_id;
380 	uint32_t	buffer_length;
381 	sg_desc_t 	sg_desc;
382 }pqi_set_event_config_request_t;
383 #endif
384 
385  /* Report/Set event config data-in/data-out buffer structure */
386 
387 #define PQI_MAX_EVENT_DESCRIPTORS 255
388 
389 struct pqi_event_descriptor {
390 	uint8_t  	event_type;
391 	uint8_t  	reserved;
392 	uint16_t	oq_id;
393 };
394 
395 typedef struct pqi_event_config {
396 	uint8_t  	reserved[2];
397 	uint8_t  	num_event_descriptors;
398 	uint8_t  	reserved1;
399 	struct		pqi_event_descriptor descriptors[PQI_MAX_EVENT_DESCRIPTORS];
400 }pqi_event_config_t;
401 
402 /*management response IUs */
403 typedef struct pqi_management_response{
404    	iu_header_t		header;
405 	uint16_t 		reserved1;
406 	uint8_t 		work_area[2];
407 	uint16_t		req_id;
408 	uint8_t 		result;
409 	uint8_t			reserved[5];
410 	uint64_t		result_data;
411 }pqi_management_response_t;
412   /*Event response IU*/
413 typedef struct pqi_event_response {
414 	iu_header_t 	header;
415 	uint16_t 		reserved1;
416 	uint8_t 		work_area[2];
417 	uint8_t 		event_type;
418 	uint8_t 		reserved2 : 7;
419 	uint8_t 		request_acknowledge : 1;
420 	uint16_t	  	event_id;
421 	uint32_t	  	additional_event_id;
422 	uint8_t 		data[16];
423 }pqi_event_response_t;
424 
425   /*event acknowledge IU*/
426 typedef struct pqi_event_acknowledge_request {
427 	iu_header_t 	header;
428 	uint16_t 		reserved1;
429 	uint8_t 		work_area[2];
430 	uint8_t 		event_type;
431 	uint8_t 		reserved2;
432 	uint16_t	  	event_id;
433 	uint32_t	  	additional_event_id;
434 }pqi_event_acknowledge_request_t;
435 
436 struct pqi_event {
437 	boolean_t	pending;
438 	uint8_t	  	event_type;
439 	uint16_t	event_id;
440 	uint32_t	additional_event_id;
441 };
442 
443 typedef struct pqi_vendor_general_response {
444 	iu_header_t	header;
445 	uint16_t	reserved1;
446 	uint8_t		work_area[2];
447 	uint16_t	request_id;
448 	uint16_t	function_code;
449 	uint16_t	status;
450 	uint8_t		reserved2[2];
451 } OS_ATTRIBUTE_PACKED pqi_vendor_general_response_t;
452 
453 typedef struct op_q_params
454 {
455 	uint8_t		fn_code;
456 	uint16_t        qid;
457 	uint16_t	num_elem;
458 	uint16_t	elem_len;
459 	uint16_t	int_msg_num;
460 
461 } OS_ATTRIBUTE_PACKED op_q_params;
462 
463 
464 /* "Fixed Format Sense Data" (0x70 or 0x71)  (Table 45 in SPC5) */
465 typedef struct sense_data_fixed {
466 	uint8_t  response_code : 7;      /* Byte 0, 0x70 or 0x71 */
467 	uint8_t  valid : 1;              /* Byte 0, bit 7 */
468 	uint8_t  byte_1;                 /* Byte 1 */
469 	uint8_t  sense_key : 4;          /* Byte 2, bit 0-3 (Key) */
470 	uint8_t  byte_2_other : 4;       /* Byte 2, bit 4-7 */
471 	uint32_t information;            /* Byte 3-6, big-endian like block # in CDB */
472 	uint8_t  addtnl_length;          /* Byte 7 */
473 	uint8_t  cmd_specific[4];        /* Byte 8-11 */
474 	uint8_t  sense_code;             /* Byte 12 (ASC) */
475 	uint8_t  sense_qual;             /* Byte 13 (ASCQ) */
476 	uint8_t  fru_code;               /* Byte 14 */
477 	uint8_t  sense_key_specific[3];  /* Byte 15-17 */
478 	uint8_t  addtnl_sense[1];        /* Byte 18+ */
479 } OS_ATTRIBUTE_PACKED sense_data_fixed_t;
480 
481 
482 /* Generic Sense Data Descriptor (Table 29 in SPC5) */
483 typedef struct descriptor_entry
484 {
485 	uint8_t  desc_type;              /* Byte 9/0 */
486 	uint8_t  desc_type_length;       /* Byte 10/1 */
487 	union
488 	{
489 		/* Sense data descriptor specific */
490 		uint8_t bytes[1];
491 
492 		/* Information (Type 0) (Table 31 is SPC5) */
493 		struct {
494 			uint8_t  byte_2_rsvd : 7;  /* Byte 11/2 */
495 			uint8_t  valid : 1;        /* Byte 11/2, bit 7 */
496 			uint8_t  byte_3;           /* Byte 12/3 */
497 			uint8_t  information[8];   /* Byte 13-20/4-11 */
498 		} OS_ATTRIBUTE_PACKED type_0;
499 
500 	}u;
501 } OS_ATTRIBUTE_PACKED descriptor_entry_t;
502 
503 /* "Descriptor Format Sense Data" (0x72 or 0x73) (Table 28 in SPC5) */
504 typedef struct sense_data_descriptor {
505 	uint8_t  response_code : 7;      /* Byte 0, 0x72 or 0x73 */
506 	uint8_t  byte_0_rsvd: 1;         /* Byte 0, bit 7 */
507 	uint8_t  sense_key : 4;          /* Byte 1, bit 0-3 (Key) */
508 	uint8_t  byte_1_other : 4;       /* Byte 1, bit 4-7 */
509 	uint8_t  sense_code;             /* Byte 2 (ASC) */
510 	uint8_t  sense_qual;             /* Byte 3 (ASCQ) */
511 	uint8_t  byte4_6[3];             /* Byte 4-6 */
512 	uint8_t  more_length;            /* Byte 7 */
513 	descriptor_entry_t descriptor_list; /* Bytes 8+ */
514 
515 } OS_ATTRIBUTE_PACKED sense_data_descriptor_t;
516 
517 typedef union sense_data_u
518 {
519 	sense_data_fixed_t      fixed_format;
520 	sense_data_descriptor_t descriptor_format;
521 	uint8_t                 data[256];
522 } sense_data_u_t;
523 
524 
525 /* Driver will use this structure to interpret the error
526    info element returned from a failed requests */
527 typedef struct raid_path_error_info_elem {
528 	uint8_t  data_in_result;      /* !< Byte 0.  See SOP spec Table 77. */
529 	uint8_t  data_out_result;     /* !< Byte 1.  See SOP spec Table 78. */
530 	uint8_t  reserved[3];         /* !< Bytes 2-4. */
531 	uint8_t  status;              /* !< Byte 5. See SAM-5 specification "Status" codes Table 40.*/
532 	uint16_t status_qual;         /* !< Bytes 6-7. See SAM-5 specification Table 43. */
533 	uint16_t sense_data_len;      /* !< Bytes 8-9. See SOP specification table 79. */
534 	uint16_t resp_data_len;       /* !< Bytes 10-11. See SOP specification table 79. */
535 	uint32_t data_in_transferred; /* !< Bytes 12-15. If "dada_in_result = 0x01 (DATA_IN BUFFER UNDERFLOW)", Indicates the number of contiguous bytes starting with offset zero in Data-In buffer else Ignored. */
536 	uint32_t data_out_transferred;/* !< Bytes 16-19. If "data_out_result = 0x01 (DATA_OUT BUFFER UNDERFLOW)", Indicates the number of contiguous bytes starting with offset zero in Data-Out buffer else Ignored. */
537 	union
538 	{
539 		sense_data_u_t sense_data;
540 		uint8_t        data[256];              /* !< Bytes 20-275. Response Data buffer or Sense Data buffer but not both. */
541 	};
542 }OS_ATTRIBUTE_PACKED raid_path_error_info_elem_t;
543 
544 #define PQI_ERROR_BUFFER_ELEMENT_LENGTH sizeof(raid_path_error_info_elem_t)
545 
546 typedef enum error_data_present
547 {
548 	DATA_PRESENT_NO_DATA       = 0,   /* !< No data present in Data buffer. */
549 	DATA_PRESENT_RESPONSE_DATA = 1,   /* !< Response data is present in Data buffer. */
550 	DATA_PRESENT_SENSE_DATA    = 2    /* !< Sense data is present in Data buffer. */
551 } error_data_present_t;
552 
553 typedef struct aio_path_error_info_elem
554 {
555 	uint8_t  status;        /* !< Byte 0.  See SAM-5 specification "SCSI Status" codes Table 40.*/
556 	uint8_t  service_resp;  /* !< Byte 1.  SCSI Service Response.  */
557 	uint8_t  data_pres;     /* !< Byte 2.  Bits [7:2] reserved. Bits [1:0] - 0=No data, 1=Response data, 2=Sense data. */
558 	uint8_t  reserved1;     /* !< Byte 3.  Reserved. */
559 	uint32_t resd_count;    /* !< Bytes 4-7.  The residual data length in bytes. Need the original transfer size and if Status is OverRun or UnderRun. */
560 	uint16_t data_len;      /* !< Bytes 8-9.  The amount of Sense data or Response data returned in Response/Sense Data buffer. */
561 	uint16_t reserved2;     /* !< Bytes 10-11.  Reserved. */
562 	union
563 	{
564 		sense_data_u_t sense_data; /* */
565 		uint8_t        data[256];  /* !< Bytes 12-267. Response data buffer or Sense data buffer but not both. */
566 	};
567 	uint8_t  padding[8];    /* !< Bytes 268-275.  Padding to make AIO_PATH_ERROR_INFO_ELEMENT = RAID_PATH_ERROR_INFO_ELEMENT */
568 }OS_ATTRIBUTE_PACKED aio_path_error_info_elem_t;
569 
570 struct init_base_struct {
571 	uint32_t	revision;		/* revision of init structure */
572 	uint32_t	flags;			/* reserved */
573 	uint32_t	err_buf_paddr_l;	/* lower 32 bits of physical address of error buffer */
574 	uint32_t	err_buf_paddr_h;	/* upper 32 bits of physical address of error buffer */
575 	uint32_t	err_buf_elem_len;	/* length of each element in error buffer (in bytes) */
576 	uint32_t	err_buf_num_elem;	/* number of elements in error buffer */
577 }OS_ATTRIBUTE_PACKED;
578 
579 /* Queue details */
580 typedef struct ib_queue {
581 	uint32_t	q_id;
582 	uint32_t	num_elem;
583 	uint32_t	elem_size;
584 	char 		*array_virt_addr;
585 	dma_addr_t	array_dma_addr;
586 	uint32_t	pi_local;
587 	uint32_t	pi_register_offset;
588 	uint32_t	*pi_register_abs;
589 	uint32_t	*ci_virt_addr;
590 	dma_addr_t	ci_dma_addr;
591 	boolean_t	created;
592 	boolean_t	lockcreated;
593 	char		lockname[LOCKNAME_SIZE];
594 	OS_PQILOCK_T	lock	OS_ATTRIBUTE_ALIGNED(8);
595 	struct dma_mem	 alloc_dma;
596 }ib_queue_t;
597 
598 typedef struct ob_queue {
599 	uint32_t	q_id;
600 	uint32_t	num_elem;
601 	uint32_t	elem_size;
602 	uint32_t	intr_msg_num;
603 	char		*array_virt_addr;
604 	dma_addr_t	array_dma_addr;
605 	uint32_t	ci_local;
606 	uint32_t	ci_register_offset;
607 	uint32_t	*ci_register_abs;
608 	uint32_t	*pi_virt_addr;
609 	dma_addr_t	pi_dma_addr;
610 	boolean_t	created;
611 	struct dma_mem	 alloc_dma;
612 }ob_queue_t;
613 
614 typedef struct pqisrc_sg_desc{
615 	uint64_t	addr;
616 	uint32_t	len;
617 	uint32_t	flags;
618 }sgt_t;
619 
620 
621 typedef struct pqi_iu_layer_desc {
622 	uint8_t		ib_spanning_supported : 1;
623 	uint8_t		res1 : 7;
624 	uint8_t		res2[5];
625 	uint16_t	max_ib_iu_len;
626 	uint8_t		ob_spanning_supported : 1;
627 	uint8_t		res3 : 7;
628 	uint8_t		res4[5];
629 	uint16_t	max_ob_iu_len;
630 }OS_ATTRIBUTE_PACKED pqi_iu_layer_desc_t;
631 
632 
633 /* Response IU data */
634 typedef struct pqi_device_capabilities {
635 	uint16_t	length;
636 	uint8_t		res1[6];
637 	uint8_t		ibq_arb_priority_support_bitmask;
638 	uint8_t		max_aw_a;
639 	uint8_t		max_aw_b;
640 	uint8_t		max_aw_c;
641 	uint8_t		max_arb_burst : 3;
642 	uint8_t		res2 : 4;
643 	uint8_t		iqa : 1;
644 	uint8_t		res3[2];
645 	uint8_t		iq_freeze : 1;
646 	uint8_t		res4 : 7;
647 	uint16_t	max_iqs;
648 	uint16_t	max_iq_elements;
649 	uint8_t		res5[4];
650 	uint16_t	max_iq_elem_len;
651 	uint16_t	min_iq_elem_len;
652 	uint8_t		res6[2];
653 	uint16_t	max_oqs;
654 	uint16_t	max_oq_elements;
655 	uint16_t	intr_coales_time_granularity;
656 	uint16_t	max_oq_elem_len;
657 	uint16_t	min_oq_elem_len;
658 	uint8_t		res7[24];
659 	pqi_iu_layer_desc_t iu_layer_desc[32];
660 }OS_ATTRIBUTE_PACKED pqi_dev_cap_t;
661 
662 /* IO path */
663 
664 typedef struct iu_cmd_flags
665 {
666 	uint8_t		data_dir : 2;
667 	uint8_t		partial : 1;
668 	uint8_t		mem_type : 1;
669 	uint8_t		fence : 1;
670 	uint8_t		encrypt_enable : 1;
671 	uint8_t		res2 : 2;
672 }OS_ATTRIBUTE_PACKED iu_cmd_flags_t;
673 
674 typedef struct iu_attr_prio
675 {
676 	uint8_t		task_attr : 3;
677 	uint8_t		cmd_prio : 4;
678 	uint8_t		res3 : 1;
679 }OS_ATTRIBUTE_PACKED iu_attr_prio_t;
680 
681 typedef struct pqi_aio_req {
682 	iu_header_t	header;
683 	uint16_t	response_queue_id;
684 	uint8_t		work_area[2];
685 	uint16_t	req_id;
686 	uint8_t		res1[2];
687 	uint32_t	nexus;
688 	uint32_t	buf_len;
689 	iu_cmd_flags_t	cmd_flags;
690 	iu_attr_prio_t	attr_prio;
691 	uint16_t	encrypt_key_index;
692 	uint32_t	encrypt_twk_low;
693 	uint32_t	encrypt_twk_high;
694 	uint8_t		cdb[16];
695 	uint16_t	err_idx;
696 	uint8_t		num_sg;
697 	uint8_t		cdb_len;
698 	uint8_t		lun[8];
699 	uint8_t		res4[4];
700 	sgt_t		sg_desc[4];
701 }OS_ATTRIBUTE_PACKED pqi_aio_req_t;
702 
703 typedef struct pqi_aio_raid1_write_req {
704 	iu_header_t	header;
705 	uint16_t	response_queue_id;
706 	uint8_t		work_area[2];
707 	uint16_t	req_id;
708 	uint16_t	volume_id;	/* ID of raid volume */
709 	uint32_t	nexus_1;	/* 1st drive in RAID 1 */
710 	uint32_t	nexus_2;	/* 2nd drive in RAID 1 */
711 	uint32_t	nexus_3;	/* 3rd drive in RAID 1 */
712 	uint32_t	buf_len;
713 	iu_cmd_flags_t	cmd_flags;
714 	iu_attr_prio_t	attr_prio;
715 	uint16_t	encrypt_key_index;
716 	uint8_t		cdb[16];
717 	uint16_t	err_idx;
718 	uint8_t		num_sg;
719 	uint8_t		cdb_len;
720 	uint8_t		num_drives;	/* drives in raid1 (2 or 3) */
721 	uint8_t		reserved_bytes[3];
722 	uint32_t	encrypt_twk_low;
723 	uint32_t	encrypt_twk_high;
724 	sgt_t		sg_desc[4];
725 }OS_ATTRIBUTE_PACKED pqi_aio_raid1_write_req_t;
726 
727 typedef struct pqi_aio_raid5or6_write_req {
728 	iu_header_t	header;
729 	uint16_t	response_queue_id;
730 	uint8_t		work_area[2];
731 	uint16_t	req_id;
732 	uint16_t	volume_id;	/* ID of raid volume */
733 	uint32_t	data_it_nexus;	/* IT nexus of data drive */
734 	uint32_t	p_parity_it_nexus;/* It nexus of p parity disk */
735 	uint32_t	q_parity_it_nexus;/* It nexus of q parity disk (R6) */
736 	uint32_t	buf_len;
737 	iu_cmd_flags_t	cmd_flags;
738 	iu_attr_prio_t	attr_prio;
739 	uint16_t	encrypt_key_index;
740 	uint8_t		cdb[16];
741 	uint16_t	err_idx;
742 	uint8_t		num_sg;
743 	uint8_t		cdb_len;
744 	uint8_t		xor_multiplier; /* for generating RAID 6 Q parity */
745 	uint8_t		reserved[3];
746 	uint32_t	encrypt_twk_low;
747 	uint32_t	encrypt_twk_high;
748 	uint64_t	row;		/* logical lba / blocks per row */
749 	uint8_t		reserved2[8];	/* changed to reserved, used to stripe_lba */
750 	sgt_t		sg_desc[3]; 	/* only 3 entries for R5/6 */
751 }OS_ATTRIBUTE_PACKED pqi_aio_raid5or6_write_req_t;
752 
753 typedef struct pqisrc_raid_request {
754 	iu_header_t header;
755 	uint16_t response_queue_id;	/* specifies the OQ where the response
756 					   IU is to be delivered */
757 	uint8_t	work_area[2];	/* reserved for driver use */
758 	uint16_t request_id;
759 	uint16_t nexus_id;
760 	uint32_t buffer_length;
761 	uint8_t	lun_number[8];
762 	uint16_t protocol_spec;
763 	uint8_t	data_direction : 2;
764 	uint8_t	partial : 1;
765 	uint8_t	reserved1 : 4;
766 	uint8_t	fence : 1;
767 	uint16_t error_index;
768 	uint8_t	reserved2;
769 	uint8_t	task_attribute : 3;
770 	uint8_t	command_priority : 4;
771 	uint8_t	reserved3 : 1;
772 	uint8_t	reserved4 : 2;
773 	uint8_t	additional_cdb_bytes_usage : 3;
774 	uint8_t	reserved5 : 3;
775 	union
776 	{
777 		uint8_t	cdb[16];
778 		struct
779 		{
780 			uint8_t	op_code;		/* Byte 0.  SCSI opcode (0x26 or 0x27) */
781 			uint8_t	lun_lower;	/* Byte 1 */
782 			uint32_t	detail;		/* Byte 2-5 */
783 			uint8_t	cmd;			/* Byte 6.  Vendor specific op code. */
784 			uint16_t	xfer_len;	/* Byte 7-8 */
785 			uint8_t	lun_upper;	/* Byte 9 */
786 			uint8_t	unused[6];	/* Bytes 10-15. */
787 		}OS_ATTRIBUTE_PACKED bmic_cdb;
788 	}OS_ATTRIBUTE_PACKED cmd;
789 	uint8_t	reserved[11];
790 	uint8_t	ml_device_lun_number;
791 	uint32_t timeout_in_sec;
792 	sgt_t	sg_descriptors[4];
793 }OS_ATTRIBUTE_PACKED pqisrc_raid_req_t;
794 
795 
796 typedef struct pqi_raid_tmf_req {
797 	iu_header_t	header;
798 	uint16_t	resp_qid;
799 	uint8_t		work_area[2];
800 	uint16_t	req_id;
801 	uint16_t	nexus;
802 	uint8_t		res1[1];
803 	uint8_t		ml_device_lun_number;
804 	uint16_t	timeout_in_sec;
805 	uint8_t		lun[8];
806 	uint16_t	protocol_spec;
807 	uint16_t	obq_id_to_manage;
808 	uint16_t	req_id_to_manage;
809 	uint8_t		tmf;
810 	uint8_t		res2 : 7;
811 	uint8_t		fence : 1;
812 } OS_ATTRIBUTE_PACKED pqi_raid_tmf_req_t;
813 
814 typedef struct pqi_aio_tmf_req {
815 	iu_header_t     header;
816 	uint16_t        resp_qid;
817 	uint8_t         work_area[2];
818 	uint16_t        req_id;
819 	uint16_t        res1;
820 	uint32_t        nexus;
821 	uint8_t         lun[8];
822 	uint32_t        req_id_to_manage;
823 	uint8_t         tmf;
824 	uint8_t         res2 : 7;
825 	uint8_t         fence : 1;
826 	uint16_t        error_idx;
827 }OS_ATTRIBUTE_PACKED pqi_aio_tmf_req_t;
828 
829 typedef struct pqi_tmf_resp {
830         iu_header_t     header;
831         uint16_t        resp_qid;
832         uint8_t         work_area[2];
833         uint16_t        req_id;
834         uint16_t        nexus;
835         uint8_t         add_resp_info[3];
836         uint8_t         resp_code;
837 }pqi_tmf_resp_t;
838 
839 
840 struct pqi_io_response {
841 	iu_header_t	header;
842 	uint16_t	queue_id;
843 	uint8_t		work_area[2];
844 	uint16_t	request_id;
845 	uint16_t	error_index;
846 	uint8_t		reserved[4];
847 }OS_ATTRIBUTE_PACKED;
848 
849 
850 struct pqi_enc_info {
851 	uint16_t	data_enc_key_index;
852 	uint32_t	encrypt_tweak_lower;
853 	uint32_t	encrypt_tweak_upper;
854 };
855 
856 typedef uint32_t os_ticks_t;
857 
858 struct pqi_stream_data {
859 	uint64_t	next_lba;
860 	os_ticks_t	last_accessed;
861 };
862 
863 typedef struct pqi_scsi_device {
864 	device_type_t	devtype;		/* as reported by INQUIRY command */
865 	uint8_t	device_type;		/* as reported by
866 					   BMIC_IDENTIFY_PHYSICAL_DEVICE - only
867 					   valid for devtype = TYPE_DISK */
868 	int	bus;
869 	int	target;
870 	int	lun;
871 	uint8_t flags;
872 	uint8_t	scsi3addr[8];
873 	uint64_t	wwid;
874 	uint8_t	is_physical_device : 1;
875 	uint8_t	is_external_raid_device : 1;
876 	uint8_t target_lun_valid : 1;
877 	uint8_t	expose_device : 1;
878 	uint8_t	no_uld_attach : 1;
879 	uint8_t	is_obdr_device : 1;
880 	uint8_t aio_enabled : 1;
881 	uint8_t	device_gone : 1;
882 	uint8_t	new_device : 1;
883 	uint8_t	volume_offline : 1;
884 	uint8_t	is_nvme : 1;
885 	uint8_t	scsi_rescan : 1;
886 	uint8_t	vendor[8];		/* bytes 8-15 of inquiry data */
887 	uint8_t	model[16];		/* bytes 16-31 of inquiry data */
888 	uint64_t	sas_address;
889 	uint8_t	raid_level;
890 	uint16_t	queue_depth;		/* max. queue_depth for this device */
891 	uint32_t	ioaccel_handle;
892 	uint8_t	volume_status;
893 	uint8_t	active_path_index;
894 	uint8_t	path_map;
895 	uint8_t	bay;
896 	uint8_t	box[8];
897 	uint16_t	phys_connector[8];
898 	int	offload_config;		/* I/O accel RAID offload configured */
899 	int	offload_enabled;	/* I/O accel RAID offload enabled */
900 	int	offload_enabled_pending;
901 	int	*offload_to_mirror;	/* Send next I/O accelerator RAID
902 					   offload request to mirror drive. */
903 	struct raid_map *raid_map;	/* I/O accelerator RAID map */
904 
905 	int 	reset_in_progress;
906 	int 	logical_unit_number;
907 	os_dev_info_t	*dip;			/*os specific scsi device information*/
908 	boolean_t	invalid;
909 	boolean_t	path_destroyed;
910 	boolean_t	firmware_queue_depth_set;
911 	OS_ATOMIC64_T   active_requests;
912 	struct pqisrc_softstate *softs;
913 	boolean_t schedule_rescan;
914 	boolean_t in_remove;
915 	struct pqi_stream_data stream_data[NUM_STREAMS_PER_LUN];
916 	boolean_t is_multi_lun;
917 
918 }pqi_scsi_dev_t;
919 
920 struct sense_header_scsi {		/* See SPC-3 section 4.5 */
921 	uint8_t response_code;		/* permit: 0x0, 0x70, 0x71, 0x72, 0x73 */
922 	uint8_t sense_key;
923 	uint8_t asc;
924 	uint8_t ascq;
925 	uint8_t byte4;
926 	uint8_t byte5;
927 	uint8_t byte6;
928 	uint8_t additional_length;	/* always 0 for fixed sense format */
929 }OS_ATTRIBUTE_PACKED;
930 
931 typedef struct report_lun_header {
932 	uint32_t list_length;
933 	uint8_t	extended_response;
934 	uint8_t	reserved[3];
935 }OS_ATTRIBUTE_PACKED reportlun_header_t;
936 
937 
938 typedef struct report_lun_ext_entry {
939 	uint8_t	lunid[8];
940 	uint64_t wwid;
941 	uint8_t	device_type;
942 	uint8_t	device_flags;
943 	uint8_t	lun_count;	/* number of LUNs in a multi-LUN device */
944 	uint8_t	redundant_paths;
945 	uint32_t ioaccel_handle;
946 }OS_ATTRIBUTE_PACKED reportlun_ext_entry_t;
947 
948 
949 typedef struct report_lun_data_ext {
950 	reportlun_header_t header;
951 	reportlun_ext_entry_t lun_entries[1];
952 }OS_ATTRIBUTE_PACKED reportlun_data_ext_t;
953 
954 typedef struct reportlun_queue_depth_entry {
955         uint8_t logical_unit_num;
956         uint8_t reserved_1:6;
957         uint8_t address:2;
958         uint8_t box_bus_num;
959         uint8_t reserved_2:6;
960         uint8_t mode:2;
961         uint8_t bus_ident;
962 
963         /* Byte 5 */
964         uint8_t queue_depth:7;
965         uint8_t multiplier:1;
966 
967         /* Byte 6 */
968         uint8_t drive_type_mix_flags;
969         uint8_t level_2_bus:6;
970         uint8_t level_2_mode:2;
971         uint8_t unused_bytes[16];
972 }OS_ATTRIBUTE_PACKED reportlun_queue_depth_entry_t;
973 
974 typedef struct reportlun_queue_depth_data {
975         reportlun_header_t header;
976     	reportlun_queue_depth_entry_t lun_entries[1]; /* lun list with Queue Depth values for each lun */
977 }OS_ATTRIBUTE_PACKED reportlun_queue_depth_data_t;
978 
979 typedef struct raidmap_data {
980 	uint32_t ioaccel_handle;
981 	uint8_t	xor_mult[2];
982 	uint8_t	reserved[2];
983 }OS_ATTRIBUTE_PACKED raidmap_data_t;
984 
985 typedef struct raid_map {
986 	uint32_t	structure_size;		/* size of entire structure in bytes */
987 	uint32_t	volume_blk_size;	/* bytes / block in the volume */
988 	uint64_t	volume_blk_cnt;		/* logical blocks on the volume */
989 	uint8_t	phys_blk_shift;		/* shift factor to convert between
990 					   units of logical blocks and physical
991 					   disk blocks */
992 	uint8_t	parity_rotation_shift;	/* shift factor to convert between units
993 					   of logical stripes and physical
994 					   stripes */
995 	uint16_t	strip_size;		/* blocks used on each disk / stripe */
996 	uint64_t	disk_starting_blk;	/* first disk block used in volume */
997 	uint64_t	disk_blk_cnt;		/* disk blocks used by volume / disk */
998 	uint16_t	data_disks_per_row;	/* data disk entries / row in the map */
999 	uint16_t	metadata_disks_per_row;	/* mirror/parity disk entries / row
1000 					   in the map */
1001 	uint16_t	row_cnt;		/* rows in each layout map */
1002 	uint16_t	layout_map_count;	/* layout maps (1 map per mirror/parity
1003 					   group) */
1004 	uint16_t	flags;
1005 	uint16_t	data_encryption_key_index;
1006 	uint8_t	reserved[16];
1007 	raidmap_data_t dev_data[RAID_MAP_MAX_ENTRIES];
1008 }OS_ATTRIBUTE_PACKED pqisrc_raid_map_t;
1009 
1010 typedef struct aio_row {
1011 	uint32_t blks_per_row;	/* blocks per row */
1012 	uint64_t first;		/* first row */
1013 	uint64_t last;		/* last row */
1014 	uint32_t offset_first;	/* offset in first row */
1015 	uint32_t offset_last;	/* offset in last row */
1016 	uint16_t data_disks;	/* number of data disks per row */
1017 	uint16_t total_disks;	/* data + parity disks per row. */
1018 }OS_ATTRIBUTE_PACKED pqisrc_aio_row_t;
1019 
1020 typedef struct aio_column {
1021 	uint32_t first;		/* 1st column of req */
1022 	uint32_t last;		/* last column of req */
1023 }OS_ATTRIBUTE_PACKED pqisrc_aio_column_t;
1024 
1025 typedef struct aio_block {
1026 	uint64_t first;		/* 1st block number of req */
1027 	uint64_t last;		/* last block number of req */
1028 	uint32_t cnt;		/* total blocks in req	*/
1029 	uint64_t disk_block;	/* block number of phys disk */
1030 }OS_ATTRIBUTE_PACKED pqisrc_aio_block_t;
1031 
1032 typedef struct aio_r5or6_loc {
1033 	struct aio_row row;	/* row information */
1034 	struct aio_column col;	/* column information */
1035 }OS_ATTRIBUTE_PACKED pqisrc_aio_r5or6_loc_t;
1036 
1037 typedef struct aio_map {
1038 	uint32_t row;
1039 	uint32_t idx;		/* index into array of handles */
1040 	uint16_t layout_map_count;
1041 }OS_ATTRIBUTE_PACKED pqisrc_aio_map_t;
1042 
1043 typedef struct aio_disk_group {
1044 	uint32_t first;		/* first group */
1045 	uint32_t last;		/* last group */
1046 	uint32_t cur;		/* current group */
1047 }OS_ATTRIBUTE_PACKED pqisrc_aio_disk_group_t;
1048 
1049 typedef struct aio_req_locator {
1050 	uint8_t	raid_level;
1051 	struct raid_map *raid_map;	/* relevant raid map */
1052 	struct aio_block block;	/* block range and count */
1053 	struct aio_row row;		/* row range and offset info */
1054 	struct aio_column col;		/* first/last column info */
1055 	struct aio_r5or6_loc r5or6;	/* Raid 5/6-specific bits */
1056 	struct aio_map map;		/* map row, count, and index */
1057 	struct aio_disk_group group;	/* first, last, and curr group */
1058 	boolean_t is_write;
1059 	uint32_t stripesz;
1060 	uint16_t strip_sz;
1061 	int offload_to_mirror;
1062 }OS_ATTRIBUTE_PACKED aio_req_locator_t;
1063 
1064 typedef struct bmic_ident_ctrl {
1065 	uint8_t		conf_ld_count;
1066 	uint32_t	conf_sign;
1067 	uint8_t		fw_version[4];
1068 	uint8_t		rom_fw_rev[4];
1069 	uint8_t		hw_rev;
1070 	uint8_t		reserved[140];
1071 	uint16_t	extended_lun_count;
1072 	uint8_t		reserved1[34];
1073 	uint16_t	fw_build_number;
1074 	uint8_t		reserved2[100];
1075 	uint8_t		ctrl_mode;
1076 	uint8_t		reserved3[32];
1077 }OS_ATTRIBUTE_PACKED bmic_ident_ctrl_t;
1078 
1079 typedef struct bmic_identify_physical_device {
1080 	uint8_t	scsi_bus;		/* SCSI Bus number on controller */
1081 	uint8_t	scsi_id;		/* SCSI ID on this bus */
1082 	uint16_t	block_size;		/* sector size in bytes */
1083 	uint32_t	total_blocks;		/* number for sectors on drive */
1084 	uint32_t	reserved_blocks;	/* controller reserved (RIS) */
1085 	uint8_t	model[40];		/* Physical Drive Model */
1086 	uint8_t	serial_number[40];	/* Drive Serial Number */
1087 	uint8_t	firmware_revision[8];	/* drive firmware revision */
1088 	uint8_t	scsi_inquiry_bits;	/* inquiry byte 7 bits */
1089 	uint8_t	compaq_drive_stamp;	/* 0 means drive not stamped */
1090 	uint8_t	last_failure_reason;
1091 	uint8_t	flags;
1092 	uint8_t	more_flags;
1093 	uint8_t	scsi_lun;		/* SCSI LUN for phys drive */
1094 	uint8_t	yet_more_flags;
1095 	uint8_t	even_more_flags;
1096 	uint32_t	spi_speed_rules;
1097 	uint8_t	phys_connector[2];	/* connector number on controller */
1098 	uint8_t	phys_box_on_bus;	/* phys enclosure this drive resides */
1099 	uint8_t	phys_bay_in_box;	/* phys drv bay this drive resides */
1100 	uint32_t	rpm;			/* drive rotational speed in RPM */
1101 	uint8_t	device_type;		/* type of drive */
1102 	uint8_t	sata_version;		/* only valid when device_type =
1103 					   BMIC_DEVICE_TYPE_SATA */
1104 	uint64_t	big_total_block_count;
1105 	uint64_t	ris_starting_lba;
1106 	uint32_t	ris_size;
1107 	uint8_t	wwid[20];
1108 	uint8_t	controller_phy_map[32];
1109 	uint16_t	phy_count;
1110 	uint8_t	phy_connected_dev_type[256];
1111 	uint8_t	phy_to_drive_bay_num[256];
1112 	uint16_t	phy_to_attached_dev_index[256];
1113 	uint8_t	box_index;
1114 	uint8_t	reserved;
1115 	uint16_t	extra_physical_drive_flags;
1116 	uint8_t	negotiated_link_rate[256];
1117 	uint8_t	phy_to_phy_map[256];
1118 	uint8_t	redundant_path_present_map;
1119 	uint8_t	redundant_path_failure_map;
1120 	uint8_t	active_path_number;
1121 	uint16_t	alternate_paths_phys_connector[8];
1122 	uint8_t	alternate_paths_phys_box_on_port[8];
1123 	uint8_t	multi_lun_device_lun_count;
1124 	uint8_t	minimum_good_fw_revision[8];
1125 	uint8_t	unique_inquiry_bytes[20];
1126 	uint8_t	current_temperature_degreesC;
1127 	uint8_t	temperature_threshold_degreesC;
1128 	uint8_t	max_temperature_degreesC;
1129 	uint8_t	logical_blocks_per_phys_block_exp;
1130 	uint16_t	current_queue_depth_limit;
1131 	uint8_t	switch_name[10];
1132 	uint16_t	switch_port;
1133 	uint8_t	alternate_paths_switch_name[40];
1134 	uint8_t	alternate_paths_switch_port[8];
1135 	uint16_t	power_on_hours;
1136 	uint16_t	percent_endurance_used;
1137 	uint8_t	drive_authentication;
1138 	uint8_t	smart_carrier_authentication;
1139 	uint8_t	smart_carrier_app_fw_version;
1140 	uint8_t	smart_carrier_bootloader_fw_version;
1141 	uint8_t	encryption_key_name[64];
1142 	uint32_t	misc_drive_flags;
1143 	uint16_t	dek_index;
1144 	uint8_t		padding[112];
1145 }OS_ATTRIBUTE_PACKED bmic_ident_physdev_t;
1146 
1147 typedef struct bmic_sense_feature {
1148 	uint8_t opcode;
1149 	uint8_t reserved1[1];
1150 	uint8_t page;
1151 	uint8_t sub_page;
1152 	uint8_t reserved2[2];
1153 	uint8_t cmd;
1154 	uint16_t transfer_length;
1155 	uint8_t reserved3[7];
1156 }OS_ATTRIBUTE_PACKED bmic_sense_feature_t;
1157 
1158 typedef struct bmic_sense_feature_buffer_header {
1159 	uint8_t page;
1160 	uint8_t sub_page;
1161 	uint16_t buffer_length;
1162 } OS_ATTRIBUTE_PACKED bmic_sense_feature_buffer_header_t;
1163 
1164 typedef struct bmic_sense_feature_page_header {
1165 	uint8_t page;
1166 	uint8_t sub_page;
1167 	uint16_t total_length; /** Total length of the page.
1168 	* The length is the same wheteher the request buffer is too short or not.
1169 	* When printing out the page, only print the buffer length. */
1170 } OS_ATTRIBUTE_PACKED bmic_sense_feature_page_header_t;
1171 
1172 typedef struct bmic_sense_feature_page_io {
1173 	struct bmic_sense_feature_page_header header;
1174 	uint8_t flags1;
1175 } OS_ATTRIBUTE_PACKED bmic_sense_feature_page_io_t;
1176 
1177 typedef struct bmic_sense_feature_page_io_aio_subpage {
1178 	struct bmic_sense_feature_page_header header;
1179 	uint8_t fw_aio_read_support;
1180 	uint8_t driver_aio_read_support;
1181 	uint8_t fw_aio_write_support;
1182 	uint8_t driver_aio_write_support;
1183 	uint16_t max_aio_rw_xfer_crypto_sas_sata;	/* in kb */
1184 	uint16_t max_aio_rw_xfer_crypto_nvme;		/* in kb */
1185 	uint16_t max_aio_write_raid5_6;			/* in kb */
1186 	uint16_t max_aio_write_raid1_10_2drv;		/* in kb */
1187 	uint16_t max_aio_write_raid1_10_3drv;		/* in kb */
1188 } OS_ATTRIBUTE_PACKED bmic_sense_feature_page_io_aio_subpage_t;
1189 
1190 typedef struct bmic_sense_feature_aio_buffer {
1191 	struct bmic_sense_feature_buffer_header header;
1192 	struct bmic_sense_feature_page_io_aio_subpage aio_subpage;
1193 } OS_ATTRIBUTE_PACKED bmic_sense_feature_aio_buffer_t;
1194 
1195 
1196 typedef struct pqisrc_bmic_flush_cache {
1197 	uint8_t	disable_cache;
1198 	uint8_t	power_action;
1199 	uint8_t	ndu_flush_cache;
1200 	uint8_t	halt_event;
1201 	uint8_t	reserved[28];
1202 } OS_ATTRIBUTE_PACKED pqisrc_bmic_flush_cache_t;
1203 
1204 /* for halt_event member of pqisrc_bmic_flush_cache_t */
1205 enum pqisrc_flush_cache_event_type {
1206 	PQISRC_NONE_CACHE_FLUSH_ONLY = 0,
1207 	PQISRC_SHUTDOWN = 1,
1208 	PQISRC_HIBERNATE = 2,
1209 	PQISRC_SUSPEND = 3,
1210 	PQISRC_RESTART = 4
1211 };
1212 
1213 struct request_container_block;
1214 typedef void (*success_callback)(struct pqisrc_softstate *, struct request_container_block *);
1215 typedef void (*error_callback)(struct pqisrc_softstate *, struct request_container_block *, uint16_t);
1216 
1217 /* Request container block */
1218 typedef struct request_container_block {
1219 	void			*req;
1220 	void			*error_info;
1221 	int 			status;
1222 	uint32_t		tag;
1223 	sgt_t			*sg_chain_virt;
1224 	dma_addr_t		sg_chain_dma;
1225 	uint32_t		data_dir;
1226 	pqi_scsi_dev_t		*dvp;
1227 	struct pqisrc_softstate	*softs;
1228 	success_callback	success_cmp_callback;
1229 	error_callback		error_cmp_callback;
1230 	uint8_t			*cdbp; /* points to either the bypass_cdb below or original host cdb */
1231 	uint8_t		bypass_cdb[16]; /* bypass cmds will use this cdb memory */
1232 	int			cmdlen;
1233 	uint32_t		bcount;	/* buffer size in byte */
1234 	uint32_t		ioaccel_handle;
1235 	boolean_t 		encrypt_enable;
1236 	struct pqi_enc_info 	enc_info;
1237 	uint32_t		row_num;
1238 	uint32_t		blocks_per_row;
1239 	uint32_t		raid_map_index;
1240 	uint32_t		raid_map_row;
1241 	ib_queue_t		*req_q;
1242 	IO_PATH_T		path;
1243 	int 			resp_qid;
1244 	boolean_t		req_pending;
1245 	uint32_t		it_nexus[PQISRC_MAX_SUPPORTED_MIRRORS];
1246 	boolean_t		timedout;
1247 	int			tm_req;
1248 	int			aio_retry;
1249 	boolean_t	is_abort_cmd_from_host;		/* true if this is a TMF abort */
1250 	boolean_t	host_wants_to_abort_this;	/* set to true to ID the request targeted by TMF */
1251 	uint64_t		submit_time_user_secs;		/* host submit time in user seconds */
1252 	uint64_t		host_timeout_ms;				/* original host timeout value in msec */
1253 	int			cm_flags;
1254 	void			*cm_data; /* pointer to data in kernel space */
1255 	bus_dmamap_t		cm_datamap;
1256 	uint32_t		nseg;
1257 	union ccb		*cm_ccb;
1258 	sgt_t			*sgt;	/* sg table */
1259 }rcb_t;
1260 
1261 typedef struct bit_map {
1262 	boolean_t 			bit_vector[MAX_TARGET_BIT];
1263 }bit_map_t;
1264 
1265 typedef enum _io_type
1266 {
1267 	UNKNOWN_IO_TYPE, /* IO Type is TBD or cannot be determined */
1268 	NON_RW_IO_TYPE,  /* IO Type is non-Read/Write opcode (could separate BMIC, etc. if we wanted) */
1269 	READ_IO_TYPE,    /* IO Type is SCSI Read */
1270 	WRITE_IO_TYPE,   /* IO Type is SCSI Write */
1271 } io_type_t;
1272 
1273 typedef enum _counter_types
1274 {
1275 	UNKNOWN_COUNTER,
1276 	HBA_COUNTER,
1277 	RAID0_COUNTER,
1278 	RAID1_COUNTER,
1279 	RAID5_COUNTER,
1280 	RAID6_COUNTER,
1281 	MAX_IO_COUNTER,
1282 } counter_types_t;
1283 
1284 typedef struct _io_counters
1285 {
1286 	OS_ATOMIC64_T raid_read_cnt;
1287 	OS_ATOMIC64_T raid_write_cnt;
1288 	OS_ATOMIC64_T aio_read_cnt;
1289 	OS_ATOMIC64_T aio_write_cnt;
1290 	OS_ATOMIC64_T raid_non_read_write;
1291 	OS_ATOMIC64_T aio_non_read_write;
1292 } io_counters_t;
1293 
1294 typedef struct pqisrc_softstate {
1295 	OS_SPECIFIC_T			os_specific;
1296 	struct ioa_registers		*ioa_reg;
1297 	struct pqi_registers		*pqi_reg;
1298 	uint8_t				*pci_mem_base_vaddr;
1299 	PCI_ACC_HANDLE_T		pci_mem_handle;
1300 	struct pqi_cap			pqi_cap;
1301 	struct pqi_pref_settings	pref_settings;
1302 	char				fw_version[11];
1303 	uint16_t			fw_build_number;
1304 	uint32_t			card;		/* index to aac_cards */
1305 	uint16_t			vendid;		/* vendor id */
1306 	uint16_t			subvendid;	/* sub vendor id */
1307 	uint16_t			devid;		/* device id */
1308 	uint16_t			subsysid;	/* sub system id */
1309 	controller_state_t		ctlr_state;
1310 	struct dma_mem			err_buf_dma_mem;
1311 	struct dma_mem			sg_dma_desc[PQISRC_MAX_OUTSTANDING_REQ + 1];
1312 	ib_queue_t			admin_ib_queue;
1313 	ob_queue_t			admin_ob_queue;
1314 	ob_queue_t			event_q;
1315 	ob_queue_t			op_ob_q[PQISRC_MAX_SUPPORTED_OP_OB_Q - 1];/* 1 event queue */
1316 	ib_queue_t			op_raid_ib_q[PQISRC_MAX_SUPPORTED_OP_RAID_IB_Q];
1317 	ib_queue_t			op_aio_ib_q[PQISRC_MAX_SUPPORTED_OP_AIO_IB_Q];
1318 	uint32_t			max_outstanding_io;
1319 	uint32_t			max_io_for_scsi_ml;
1320 	uint32_t			num_op_raid_ibq;
1321 	uint32_t			num_op_aio_ibq;
1322 	uint32_t			num_op_obq;
1323 	uint32_t			num_elem_per_op_ibq;
1324 	uint32_t			num_elem_per_op_obq;
1325 	uint32_t			max_ibq_elem_size;
1326 	uint32_t			max_obq_elem_size;
1327 	pqi_dev_cap_t			pqi_dev_cap;
1328 	uint16_t			max_ib_iu_length_per_fw;
1329 	uint16_t			max_ib_iu_length;		/* should be 1152 */
1330 	uint16_t			max_spanning_elems;	/* should be 9 spanning elements */
1331 	unsigned			max_sg_per_single_iu_element;	/* should be 8 */
1332 	unsigned			max_sg_per_spanning_cmd;	/* should be 68, 67 with AIO writes */
1333 	uint8_t				ib_spanning_supported : 1;
1334 	uint8_t				ob_spanning_supported : 1;
1335 	pqi_event_config_t		event_config;
1336 	struct pqi_event		pending_events[PQI_NUM_SUPPORTED_EVENTS];
1337 	int				intr_type;
1338 	int				intr_count;
1339 	int				num_cpus_online;
1340 	int				num_devs;
1341 	boolean_t			share_opq_and_eventq;
1342 	rcb_t				*rcb;
1343 #ifndef LOCKFREE_STACK
1344 	pqi_taglist_t			taglist;
1345 #else
1346 	lockless_stack_t		taglist;
1347 #endif /* LOCKFREE_STACK */
1348 	boolean_t			devlist_lockcreated;
1349 	OS_LOCK_T			devlist_lock	OS_ATTRIBUTE_ALIGNED(8);
1350 	char				devlist_lock_name[LOCKNAME_SIZE];
1351 	pqi_scsi_dev_t			*device_list[PQI_MAX_DEVICES][PQI_MAX_MULTILUN];
1352 	pqi_scsi_dev_t			*dev_list[PQI_MAX_DEVICES];
1353 	OS_SEMA_LOCK_T			scan_lock;
1354 	uint8_t				lun_count[PQI_MAX_DEVICES];
1355 	uint64_t     		target_sas_addr[PQI_MAX_EXT_TARGETS];
1356 	uint64_t			phys_list_pos;
1357 	uint64_t			prev_heartbeat_count;
1358 	uint64_t			*heartbeat_counter_abs_addr;
1359 	uint64_t			heartbeat_counter_off;
1360 	uint32_t			bus_id;
1361 	uint32_t			device_id;
1362 	uint32_t			func_id;
1363 	uint8_t				adapter_num; /* globally unique adapter number */
1364 	char 				*os_name;
1365 	boolean_t			ctrl_online;
1366 	uint8_t				pqi_reset_quiesce_allowed : 1;
1367 	boolean_t 			ctrl_in_pqi_mode;
1368 	bit_map_t			bit_map;
1369 	uint32_t			adapterQDepth;
1370 	uint32_t 			dma_mem_consumed;
1371 	boolean_t			adv_aio_capable;
1372 	boolean_t			aio_raid1_write_bypass;
1373 	boolean_t			aio_raid5_write_bypass;
1374 	boolean_t			aio_raid6_write_bypass;
1375 	boolean_t			enable_stream_detection;
1376 	uint16_t			max_aio_write_raid5_6; /* bytes */
1377 	uint16_t			max_aio_write_raid1_10_2drv; /* bytes */
1378 	uint16_t			max_aio_write_raid1_10_3drv; /* bytes */
1379 	uint16_t			max_aio_rw_xfer_crypto_nvme; /* bytes */
1380 	uint16_t 			max_aio_rw_xfer_crypto_sas_sata;	/* bytes */
1381 	io_counters_t	counters[MAX_IO_COUNTER];
1382 	boolean_t			log_io_counters;
1383 	boolean_t			ld_rescan;
1384 
1385 #ifdef PQI_NEED_RESCAN_TIMER_FOR_RBOD_HOTPLUG
1386 	reportlun_data_ext_t *log_dev_list;
1387 	size_t				log_dev_data_length;
1388 	uint32_t			num_ptraid_targets;
1389 #endif
1390 	boolean_t			timeout_in_passthrough;
1391 	boolean_t			timeout_in_tmf;
1392 	boolean_t			sata_unique_wwn;
1393 	boolean_t			page83id_in_rpl;
1394 	boolean_t			err_resp_verbose;
1395 
1396 #ifdef DEVICE_HINT
1397 	device_hint			hint;
1398 #endif
1399 
1400 }pqisrc_softstate_t;
1401 
1402 struct pqi_config_table {
1403 	uint8_t	signature[8];		/* "CFGTABLE" */
1404 	uint32_t	first_section_offset;	/* offset in bytes from the base */
1405 					/* address of this table to the */
1406 					/* first section */
1407 }OS_ATTRIBUTE_PACKED;
1408 
1409 struct pqi_config_table_section_header {
1410 	uint16_t	section_id;		/* as defined by the */
1411 					/* PQI_CONFIG_TABLE_SECTION_* */
1412 					/* manifest constants above */
1413 	uint16_t	next_section_offset;	/* offset in bytes from base */
1414 					/* address of the table of the */
1415 					/* next section or 0 if last entry */
1416 }OS_ATTRIBUTE_PACKED;
1417 
1418 struct pqi_config_table_general_info {
1419 	struct pqi_config_table_section_header header;
1420 	uint32_t	section_length;		/* size of this section in bytes */
1421 					/* including the section header */
1422 	uint32_t	max_outstanding_requests;	/* max. outstanding */
1423 						/* commands supported by */
1424 						/* the controller */
1425 	uint32_t	max_sg_size;		/* max. transfer size of a single */
1426 					/* command */
1427 	uint32_t	max_sg_per_request;	/* max. number of scatter-gather */
1428 					/* entries supported in a single */
1429 					/* command */
1430 }OS_ATTRIBUTE_PACKED;
1431 
1432 struct pqi_config_table_firmware_features {
1433 	struct pqi_config_table_section_header header;
1434 	uint16_t	num_elements;
1435 	uint8_t	features_supported[];
1436 /*	u8	features_requested_by_host[]; */
1437 /*	u8	features_enabled[]; */
1438 /* The 2 fields below are only valid if the MAX_KNOWN_FEATURE bit is set. */
1439 /*	uint16_t	firmware_max_known_feature; */
1440 /*	uint16_t	host_max_known_feature; */
1441 }OS_ATTRIBUTE_PACKED;
1442 
1443 typedef struct pqi_vendor_general_request {
1444 	iu_header_t	header; /* bytes 0-3 */
1445 	uint16_t	response_id; /* bytes 4-5 */
1446 	uint16_t	work; /* bytes 6-7 */
1447 	uint16_t	request_id;
1448 	uint16_t	function_code;
1449 	union {
1450 		struct {
1451 			uint16_t	first_section;
1452 			uint16_t	last_section;
1453 			uint8_t	reserved[48];
1454 		} OS_ATTRIBUTE_PACKED config_table_update;
1455 
1456 		struct {
1457 			uint64_t	buffer_address;
1458 			uint32_t	buffer_length;
1459 			uint8_t	reserved[40];
1460 		} OS_ATTRIBUTE_PACKED ofa_memory_allocation;
1461 	} data;
1462 }OS_ATTRIBUTE_PACKED pqi_vendor_general_request_t;
1463 
1464 typedef struct vpd_logical_volume_status {
1465 	uint8_t         peripheral_info;
1466 	uint8_t         page_code;
1467 	uint8_t         reserved;
1468 	uint8_t         page_length;
1469 	uint8_t         volume_status;
1470 	uint8_t         reserved2[3];
1471 	uint32_t        flags;
1472 }vpd_volume_status;
1473 
1474 #endif
1475