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