xref: /illumos-gate/usr/src/uts/common/io/scsi/adapters/smartpqi/smartpqi.h (revision 9164a50bf932130cbb5097a16f6986873ce0e6e5)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2023 Tintri by DDN, Inc. All rights reserved.
14  * Copyright 2021 RackTop Systems, Inc.
15  */
16 
17 #ifndef _SMARTPQI_H
18 #define	_SMARTPQI_H
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 /* ---- Standard header files. ---- */
25 #include <sys/note.h>
26 #include <sys/byteorder.h>
27 #include <sys/scsi/scsi.h>
28 #include <sys/pci.h>
29 #include <sys/file.h>
30 #include <sys/policy.h>
31 #include <sys/model.h>
32 #include <sys/sysevent.h>
33 #include <sys/sysevent/eventdefs.h>
34 #include <sys/sysevent/dr.h>
35 #include <sys/sata/sata_defs.h>
36 #include <sys/sata/sata_hba.h>
37 #include <sys/scsi/generic/sas.h>
38 #include <sys/scsi/impl/scsi_sas.h>
39 #include <sys/scsi/impl/scsi_reset_notify.h>
40 #include <sys/sdt.h>
41 #include <sys/mdi_impldefs.h>
42 #include <sys/fs/dv_node.h>
43 #include <sys/sysmacros.h>
44 #include <sys/systm.h>
45 #include <smartpqi_hw.h>
46 
47 /* ---- Hint for ddi_soft_state_init() on amount of structs to alloc ---- */
48 #define	SMARTPQI_INITIAL_SOFT_SPACE	1
49 
50 #define	SMARTPQI_MOD_STRING	"smartpqi RT-20210716"
51 
52 /* ---- Handy constants ---- */
53 #define	UNDEFINED				-1
54 #define	MAX_NAME_PROP_SIZE			256
55 #define	LUN_PROP				"lun"
56 #define	LUN64_PROP				"lun64"
57 #define	MDI_GUID				"wwn"
58 #define	NDI_GUID				"guid"
59 #define	TARGET_PROP				"target"
60 #define	LUN_PROP				"lun"
61 #define	COMPAT_PROP				"compatible"
62 #define	NAME_DISK				"disk"
63 #define	NAME_ENCLOSURE				"enclosure"
64 
65 #define	CMD_TIMEOUT_SCAN_SECS			10
66 #define	SYNC_CMDS_TIMEOUT_SECS			5
67 #define	IO_SPACE				1
68 #define	PQI_MAXTGTS				256
69 
70 #define	PQI_MIN_MSIX_VECTORS			1
71 #define	PQI_MAX_MSIX_VECTORS			16
72 #define	PQI_DEFAULT_QUEUE_GROUP			0
73 #define	PQI_MAX_QUEUE_GROUPS			PQI_MAX_MSIX_VECTORS
74 #define	PQI_MIN_OPERATIONAL_QUEUE_ID		1
75 #define	PQI_NGENS				16
76 #define	PQI_MAX_IO_SLOTS			(1 << 12)
77 #define	PQI_SLOT_INDEX_MASK			0xfff
78 #define	PQI_GENSHIFT				12
79 /*
80  * Generate and extract fields from a 16 bit io request id.
81  * We generate a request id by combining a 12 bit slot index with a
82  * 4 bit generation count.
83  */
84 #define	PQI_MAKE_REQID(index, gen) (((gen) << PQI_GENSHIFT) | (index))
85 #define	PQI_REQID_GEN(id)	((id) >> PQI_GENSHIFT)
86 #define	PQI_REQID_INDEX(id)	((id) & PQI_SLOT_INDEX_MASK)
87 
88 /* ---- Size of structure scsi_arq_status without sense data. ---- */
89 #define	PQI_ARQ_STATUS_NOSENSE_LEN	(sizeof (struct scsi_arq_status) - \
90     sizeof (struct scsi_extended_sense))
91 
92 /* ---- macros to return various addresses ---- */
93 #define	ADDR2TRAN(ap)	((ap)->a_hba_tran)
94 #define	TRAN2PQI(hba)	((pqi_state_t *)(hba)->tran_hba_private)
95 #define	ADDR2PQI(ap)	(TRAN2PQI(ADDR2TRAN(ap)))
96 #define	PKT2CMD(pkt)	((pqi_cmd_t *)(pkt)->pkt_ha_private)
97 #define	CMD2PKT(cmd)	((struct scsi_pkt *)(cmd)->pc_pkt)
98 
99 /* ---- PQI configuration ---- */
100 #define	PQI_MAX_OUTSTANDING_REQUESTS		32
101 #define	PQI_ERROR_BUFFER_ELEMENT_LENGTH sizeof (struct pqi_raid_error_info)
102 #define	PQI_CREATE_ADMIN_QUEUE_PAIR		1
103 #define	PQI_DELETE_ADMIN_QUEUE_PAIR		2
104 #define	PQI_MAX_TRANSFER_SIZE			(4 * 1024U * 1024U)
105 #define	PQI_MAX_RESET_XFER_SIZE			(512 * 1024)
106 #define	PQI_NUM_SUPPORTED_EVENTS		7
107 #define	PQI_RESERVED_IO_SLOTS_LUN_RESET		1
108 #define	PQI_RESERVED_IO_SLOTS_EVENT_ACK	PQI_NUM_SUPPORTED_EVENTS
109 #define	PQI_RESERVED_IO_SLOTS_SYNCHRONOUS_REQUESTS	3
110 #define	PQI_RESERVED_IO_SLOTS \
111 	(PQI_RESERVED_IO_SLOTS_LUN_RESET + PQI_RESERVED_IO_SLOTS_EVENT_ACK + \
112 	PQI_RESERVED_IO_SLOTS_SYNCHRONOUS_REQUESTS)
113 #define	PQI_MAX_SCATTER_GATHER			0x200
114 
115 /* ---- SIS constants ---- */
116 #define	SIS_BASE_STRUCT_ALIGNMENT		16
117 
118 /* ---- Once every 10 seconds ---- */
119 #define	WATCHDOG (10 * MICROSEC)
120 
121 /* ---- Update HBA time of day clock once a day ---- */
122 #define	MINUTE		60
123 #define	HOUR		(60 * MINUTE)
124 #define	DAY		(24 * HOUR)
125 
126 #define	HBA_IS_QUIESCED(s)	(((s)->s_flags & PQI_HBA_QUIESCED) != 0)
127 #define	HBA_QUIESCED_PENDING(s)	\
128 	(((s)->s_flags & PQI_HBA_QUIESCED_PENDING) != 0 && \
129 	((s)->s_cmd_queue_len == 0))
130 
131 /*
132  * The PQIALIGN_TYPED() does round up to produce aligned value,
133  * and is built to support pointers.
134  * We could use P2ROUNDUP_TYPED from sysmacros.h, but unfortunately,
135  * P2ROUNDUP_TYPED does not work with pointer types.
136  */
137 #define	PQIALIGN_TYPED(addr, align, type) \
138 	(type)(((uintptr_t)(addr) + align - 1) & ~(align - 1))
139 
140 /* ---- Handy macros to get/set device registers ---- */
141 #define	G8(state, __reg__) \
142     ddi_get8(state->s_datap, &state->s_reg->__reg__)
143 #define	G16(state, __reg__) \
144     ddi_get16(state->s_datap, &state->s_reg->__reg__)
145 #define	G32(state, __reg__) \
146     ddi_get32(state->s_datap, &state->s_reg->__reg__)
147 #define	S8(state, __reg__, val) \
148     ddi_put8(state->s_datap, &state->s_reg->__reg__, val)
149 #define	S32(state, __reg__, val) \
150     ddi_put32(state->s_datap, &state->s_reg->__reg__, val)
151 #define	S64(state, __reg__, val) \
152     ddi_put64(state->s_datap, &state->s_reg->__reg__, val)
153 #define	G64(state, __reg__) \
154     ddi_get64(state->s_datap, &state->s_reg->__reg__)
155 
156 /*
157  * Yuck! Internal knowledge of MPxIO, but since this variable is required
158  * to use MPxIO and there's no public API it must be declared here. Both
159  * the iSCSI Initiator and MPT SAS drivers do the same thing.
160  */
161 extern dev_info_t *scsi_vhci_dip;
162 
163 typedef enum pqi_io_path {
164 	RAID_PATH = 0,
165 	AIO_PATH = 1
166 } pqi_path_t;
167 
168 typedef struct dma_overhead {
169 	ddi_dma_handle_t	handle;
170 	ddi_acc_handle_t	acc;
171 	caddr_t			alloc_memory;
172 	size_t			len_to_alloc;
173 	size_t			allocated_len;
174 	uint64_t		dma_addr;
175 	uint_t			cookie_count;
176 	ddi_dma_cookie_t	second;
177 } pqi_dma_overhead_t;
178 
179 typedef struct pqi_admin_queues {
180 	caddr_t			iq_element_array;
181 	caddr_t			oq_element_array;
182 	volatile pqi_index_t	*iq_ci;
183 	pqi_index_t		*oq_pi;
184 	uint64_t		iq_element_array_bus_addr;
185 	uint64_t		oq_element_array_bus_addr;
186 	uint64_t		iq_ci_bus_addr;
187 	uint64_t		oq_pi_bus_addr;
188 	uint32_t		*iq_pi;
189 	pqi_index_t		iq_pi_copy;
190 	uint32_t		*oq_ci;
191 	pqi_index_t		oq_ci_copy;
192 	struct task_struct	*task;
193 	uint16_t		int_msg_num;
194 } pqi_admin_queues_t;
195 
196 typedef struct pqi_event_queue {
197 	uint16_t		oq_id;
198 	uint16_t		int_msg_num;
199 	void			*oq_element_array;
200 	pqi_index_t		*oq_pi;		/* In s_queue_dma space */
201 	uint64_t		oq_element_array_bus_addr;
202 	uint64_t		oq_pi_bus_addr;
203 	uint32_t		*oq_ci;		/* In s_reg space */
204 	pqi_index_t		oq_ci_copy;
205 } pqi_event_queue_t;
206 
207 typedef struct pqi_queue_group {
208 	struct pqi_state	*qg_softc;	/* backpointer */
209 	uint16_t		iq_id[2];
210 	uint16_t		oq_id;
211 	uint16_t		int_msg_num;
212 	caddr_t			iq_element_array[2];
213 	caddr_t			oq_element_array;
214 	uint64_t		iq_element_array_bus_addr[2];
215 	uint64_t		oq_element_array_bus_addr;
216 	pqi_index_t		iq_pi_copy[2];
217 	pqi_index_t		oq_ci_copy;
218 	/* ---- In s_reg space ---- */
219 	uint32_t		*iq_pi[2];
220 	uint32_t		*oq_ci;
221 
222 	/* ---- In s_queue_dma space ---- */
223 	pqi_index_t		*iq_ci[2];
224 	pqi_index_t		*oq_pi;
225 
226 	uint64_t		iq_ci_bus_addr[2];
227 	uint64_t		oq_pi_bus_addr;
228 
229 	kmutex_t		submit_lock[2]; /* protect submission queue */
230 	list_t			request_list[2];
231 	int			submit_count;
232 	int			cmplt_count;
233 	boolean_t		qg_active;
234 } pqi_queue_group_t;
235 
236 typedef struct pqi_io_request {
237 	kmutex_t		io_lock; /* protect generation/serviced flag */
238 	uint32_t		io_refcount;
239 	uint16_t		io_index;
240 	void			(*io_cb)(struct pqi_io_request *, void *);
241 	void			*io_context;
242 	uint8_t			io_raid_bypass : 1;
243 	uint8_t			io_gen;
244 	boolean_t		io_serviced;
245 	int			io_status;
246 	pqi_queue_group_t	*io_queue_group;
247 	int			io_queue_path;
248 	struct pqi_cmd		*io_cmd;
249 	void			*io_error_info;
250 	pqi_dma_overhead_t	*io_sg_chain_dma;
251 	void			*io_iu;
252 	list_node_t		io_list_node;
253 
254 	/* ---- Debug aids ---- */
255 	pqi_index_t		io_pi;
256 	int			io_iu_type;
257 
258 	struct pqi_state	*io_softc;
259 } pqi_io_request_t;
260 
261 typedef struct pqi_event {
262 	boolean_t		ev_pending;
263 	uint8_t			ev_type;
264 	uint16_t		ev_id;
265 	uint32_t		ev_additional;
266 } pqi_event_t;
267 
268 /* ---- Flags used in pqi_state ---- */
269 #define	PQI_HBA_DRIVER_SHUTDOWN			0x0001
270 #define	PQI_HBA_QUIESCED			0x0002
271 #define	PQI_HBA_QUIESCED_PENDING		0x0004
272 #define	PQI_HBA_AUTO_REQUEST_SENSE		0x0008
273 #define	PQI_HBA_LUN_RESET_CAP			0x0010
274 
275 /* ---- Debug flags, example debug=0x10; in .conf file ---- */
276 #define	DBG_LVL_CDB				0x0001
277 #define	DBG_LVL_RQST				0x0002
278 #define	DBG_LVL_STATE				0x0004
279 #define	DBG_LVL_RAW_RQST			0x0008
280 
281 typedef struct pqi_device {
282 	list_node_t		pd_list;
283 	kmutex_t		pd_mutex;
284 
285 	/* ---- Protected by pd_mutex ---- */
286 	list_t			pd_cmd_list;
287 	int			pd_flags;
288 
289 	int			pd_active_cmds;
290 	int			pd_target;
291 	int			pd_lun;
292 
293 	/* ---- Only one will be valid, MPxIO uses s_pip ---- */
294 	dev_info_t		*pd_dip;
295 	mdi_pathinfo_t		*pd_pip;
296 	mdi_pathinfo_t		*pd_pip_offlined;
297 
298 	dev_info_t		*pd_parent;
299 	int			pd_devtype;
300 	int			pd_online : 1;
301 	int			pd_scanned : 1;
302 	int			pd_phys_dev : 1;
303 	int			pd_external_raid : 1;
304 	int			pd_aio_enabled : 1;
305 	uint32_t		pd_aio_handle;
306 	char			pd_scsi3addr[8];
307 	uint64_t		pd_wwid;
308 	char			*pd_guid;
309 	uint8_t			pd_volume_id[16];
310 	char			pd_vendor[8];	/* From INQUIRY */
311 	char			pd_model[16];	/* From INQUIRY */
312 	char			pd_unit_address[32];
313 
314 	/* ---- Debug stats ---- */
315 	uint32_t		pd_killed;
316 	uint32_t		pd_posted;
317 	uint32_t		pd_timedout;
318 	uint32_t		pd_sense_errors;
319 } pqi_device_t;
320 
321 typedef struct pqi_state {
322 	int			s_instance;
323 	dev_info_t		*s_dip;
324 	int			s_flags;
325 	kmutex_t		s_mutex;
326 	kmutex_t		s_intr_mutex;
327 	kcondvar_t		s_quiescedvar;
328 	uint32_t		s_next_target;
329 
330 	/* ---- Used for serialized commands through driver ---- */
331 	struct pqi_device	s_special_device;
332 
333 	boolean_t		s_intr_ready;
334 	boolean_t		s_offline;
335 	boolean_t		s_disable_mpxio;
336 	kmem_cache_t		*s_cmd_cache;
337 	ddi_taskq_t		*s_events_taskq;
338 	ddi_taskq_t		*s_complete_taskq;
339 	timeout_id_t		s_time_of_day;
340 	timeout_id_t		s_cmd_timeout;
341 
342 	/* ---- Debug related state ---- */
343 	int			s_debug_level;
344 
345 	/* ---- State for watchdog ---- */
346 	timeout_id_t		s_watchdog;
347 	uint32_t		s_last_intr_count;
348 	uint32_t		s_last_heartbeat_count;
349 	uint32_t		s_intr_count;
350 
351 	/* ---- Interrupt related fields ---- */
352 	int			s_intr_type;	/* Type of interrupt used */
353 	int			s_intr_cnt;	/* # of interrupts */
354 	uint_t			s_intr_pri;	/* Interrupt priority */
355 	int			s_intr_cap;	/* Interrupt capabilities */
356 	int			s_intr_size;	/* Size of s_htable */
357 	ddi_intr_handle_t	*s_itable;	/* Interrupt table */
358 
359 	scsi_hba_tran_t		*s_tran;
360 	ddi_dma_attr_t		s_msg_dma_attr;	/* Used for message frames */
361 
362 	/* ---- list of reset notification requests ---- */
363 	struct scsi_reset_notify_entry	*s_reset_notify_listf;
364 
365 	pqi_ctrl_regs_t		*s_reg;
366 	ddi_device_acc_attr_t	s_reg_acc_attr;
367 	/* ---- operating regs data access handle ---- */
368 	ddi_acc_handle_t	s_datap;
369 
370 	list_t			s_devnodes;
371 	volatile uint32_t	s_cmd_queue_len;
372 
373 	/* ---- SIS capabilities from controller ---- */
374 	uint32_t		s_max_sg_entries;
375 	uint32_t		s_max_xfer_size;
376 	uint32_t		s_max_outstanding_requests;
377 	uint32_t		s_config_table_offset;
378 	uint32_t		s_config_table_len;
379 
380 	/* ---- PQI capabilities from controller ---- */
381 	uint32_t		*s_heartbeat_counter;
382 	uint16_t		s_max_inbound_queues;
383 	uint16_t		s_max_elements_per_iq;
384 	uint16_t		s_max_iq_element_length;
385 	uint16_t		s_max_outbound_queues;
386 	uint16_t		s_max_elements_per_oq;
387 	uint16_t		s_max_oq_element_length;
388 	uint16_t		s_max_inbound_iu_length_per_firmware;
389 	uint8_t			s_inbound_spanning_supported : 1,
390 				s_outbound_spanning_supported:1,
391 				s_pqi_mode_enabled : 1;
392 	char			s_firmware_version[11];
393 
394 	/* ---- Computed values from config ---- */
395 	uint32_t		s_max_sg_per_iu;
396 	uint32_t		s_num_elements_per_iq;
397 	uint32_t		s_num_elements_per_oq;
398 	uint32_t		s_max_inbound_iu_length;
399 	uint32_t		s_num_queue_groups;
400 	uint32_t		s_max_io_slots;
401 	uint32_t		s_sg_chain_buf_length;
402 	uint32_t		s_max_sectors;
403 
404 	/* ---- allocation/free is protected by s_io_mutex ---- */
405 	kmutex_t		s_io_mutex;
406 	kcondvar_t		s_io_condvar;
407 	pqi_io_request_t	*s_io_rqst_pool;
408 	int			s_io_wait_cnt;
409 	int			s_next_io_slot;
410 	uint32_t		s_io_need;
411 	uint32_t		s_io_had2wait;
412 	uint32_t		s_io_sig;
413 
414 	pqi_dma_overhead_t	*s_error_dma;
415 	pqi_dma_overhead_t	*s_adminq_dma;
416 	pqi_admin_queues_t	s_admin_queues;
417 	pqi_dma_overhead_t	*s_queue_dma;
418 	pqi_queue_group_t	s_queue_groups[PQI_MAX_QUEUE_GROUPS];
419 	pqi_event_queue_t	s_event_queue;
420 	struct pqi_event	s_events[PQI_NUM_SUPPORTED_EVENTS];
421 } pqi_state_t;
422 
423 /* ---- Flags used in pqi_cmd_t ---- */
424 #define	PQI_FLAG_ABORTED	0x0001
425 #define	PQI_FLAG_TIMED_OUT	0x0002
426 #define	PQI_FLAG_RESET		0x0004
427 #define	PQI_FLAG_IO_IOPB	0x0040
428 #define	PQI_FLAG_DMA_VALID	0x0100
429 #define	PQI_FLAG_CDB_EXT	0x0200
430 #define	PQI_FLAG_SCB_EXT	0x0400
431 #define	PQI_FLAG_PRIV_EXT	0x0800
432 #define	PQI_FLAG_IO_READ	0x1000
433 #define	PQI_FLAG_IO_BOUNCE	0x2000
434 #define	PQI_FLAG_FINISHING	0x4000
435 
436 typedef enum pqi_cmd_action {
437 	PQI_CMD_UNINIT,
438 	PQI_CMD_QUEUE,
439 	PQI_CMD_START,
440 	PQI_CMD_CMPLT,
441 	PQI_CMD_TIMEOUT,
442 	PQI_CMD_FAIL
443 } pqi_cmd_action_t;
444 
445 #define	PQI_FLAGS_PERSISTENT	\
446 	(PQI_FLAG_DMA_VALID	|\
447 	PQI_FLAG_IO_IOPB)
448 
449 #define	PQI_FLAGS_NON_HW_COMPLETION \
450 	(PQI_FLAG_ABORTED	|\
451 	PQI_FLAG_TIMED_OUT	|\
452 	PQI_FLAG_RESET)
453 
454 typedef struct pqi_cmd {
455 	list_node_t		pc_list;
456 	kmutex_t		pc_mutex;	// protects pc_cmd_state
457 
458 	pqi_cmd_action_t	pc_cur_action;
459 	pqi_cmd_action_t	pc_last_action;
460 
461 	struct scsi_pkt		*pc_pkt;
462 	pqi_state_t		*pc_softc;
463 	pqi_device_t		*pc_device;
464 	ksema_t			*pc_poll;
465 	uint8_t			pc_cdb[SCSI_CDB_SIZE];
466 	struct scsi_arq_status	pc_cmd_scb;
467 
468 	uint64_t		pc_tgt_priv[2];
469 	int			pc_dma_count;	/* bytes to transfer */
470 
471 	/*
472 	 * Setting/clearing/testing of ABORT and FINISHING are
473 	 * protected by pqi_device->pd_mutex. The other bits in
474 	 * this flag are set during init_pkt and read only during
475 	 * cleanup.
476 	 */
477 	int			pc_flags;
478 
479 	int			pc_tgtlen;
480 	int			pc_statuslen;
481 	int			pc_cmdlen;
482 	hrtime_t		pc_expiration;
483 	hrtime_t		pc_start_time;
484 
485 	/* ---- For partial DMA transfers ---- */
486 	uint_t			pc_nwin;
487 	uint_t			pc_winidx;
488 	off_t			pc_dma_offset;
489 	size_t			pc_dma_len;
490 
491 	/* ---- Valid after call to pqi_transport_command ---- */
492 	pqi_io_request_t	*pc_io_rqst;
493 
494 	ddi_dma_handle_t	pc_dmahdl;
495 	ddi_dma_cookie_t	pc_dmac;
496 	uint_t			pc_dmaccount;	/* cookie count */
497 	struct scsi_pkt		pc_cached_pkt;
498 	ddi_dma_cookie_t	pc_cached_cookies[PQI_MAX_SCATTER_GATHER];
499 } pqi_cmd_t;
500 
501 /* ---- configuration table section IDs ---- */
502 #define	PQI_CONFIG_TABLE_SECTION_GENERAL_INFO		0
503 #define	PQI_CONFIG_TABLE_SECTION_FIRMWARE_FEATURES	1
504 #define	PQI_CONFIG_TABLE_SECTION_FIRMWARE_ERRATA	2
505 #define	PQI_CONFIG_TABLE_SECTION_DEBUG			3
506 #define	PQI_CONFIG_TABLE_SECTION_HEARTBEAT		4
507 
508 /* ---- manifest constants for the flags field of pqi_sg_descriptor ---- */
509 #define	CISS_SG_NORMAL				0x00000000
510 #define	CISS_SG_LAST				0x40000000
511 #define	CISS_SG_CHAIN				0x80000000
512 
513 /*
514  * According to the PQI spec, the IU header is only the first 4 bytes of our
515  * pqi_iu_header structure.
516  */
517 #define	PQI_REQUEST_HEADER_LENGTH			4
518 #define	PQI_REQUEST_IU_TASK_MANAGEMENT			0x13
519 #define	PQI_REQUEST_IU_RAID_PATH_IO			0x14
520 #define	PQI_REQUEST_IU_AIO_PATH_IO			0x15
521 #define	PQI_REQUEST_IU_GENERAL_ADMIN			0x60
522 #define	PQI_REQUEST_IU_REPORT_VENDOR_EVENT_CONFIG	0x72
523 #define	PQI_REQUEST_IU_SET_VENDOR_EVENT_CONFIG		0x73
524 #define	PQI_REQUEST_IU_ACKNOWLEDGE_VENDOR_EVENT		0xf6
525 
526 #define	MASKED_DEVICE(lunid)				((lunid)[3] & 0xc0)
527 
528 #define	MEMP(args...) (void) snprintf(m.mem + strlen(m.mem), \
529 	m.len - strlen(m.mem), args)
530 
531 typedef struct mem_len_pair {
532 	caddr_t	mem;
533 	int	len;
534 } mem_len_pair_t;
535 
536 /* ---- Defines for PQI mode ---- */
537 #define	IRQ_MODE_NONE			0x00
538 #define	VPD_PAGE			(1 << 8)
539 
540 /* ---- Defines for use in Legacy mode ---- */
541 #define	SIS_CTRL_KERNEL_UP		0x080
542 #define	SIS_CTRL_KERNEL_PANIC		0x100
543 #define	SIS_MODE			0x0
544 #define	PQI_MODE			0x1
545 
546 /* ---- smartpqi_main.c ---- */
547 extern void *pqi_state;
548 extern int pqi_do_scan;
549 extern int pqi_do_ctrl;
550 
551 /* ---- smartpqi_intr.c ---- */
552 int smartpqi_register_intrs(pqi_state_t *);
553 void smartpqi_unregister_intrs(pqi_state_t *);
554 void pqi_process_io_intr(pqi_state_t *s, pqi_queue_group_t *qg);
555 
556 /* ---- smartpqi_sis.c ---- */
557 boolean_t sis_reenable_mode(pqi_state_t *s);
558 void sis_write_scratch(pqi_state_t *s, int mode);
559 uint32_t sis_read_scratch(pqi_state_t *s);
560 boolean_t sis_wait_for_ctrl_ready(pqi_state_t *s);
561 boolean_t sis_get_ctrl_props(pqi_state_t *s);
562 boolean_t sis_init_base_struct_addr(pqi_state_t *s);
563 boolean_t sis_get_pqi_capabilities(pqi_state_t *s);
564 
565 /* ---- smartpqi_init.c ---- */
566 void pqi_free_io_resource(pqi_state_t *s);
567 boolean_t pqi_scsi_inquiry(pqi_state_t *s, pqi_device_t *dev, int vpd,
568     struct scsi_inquiry *inq, int len);
569 void pqi_rescan_devices(pqi_state_t *s);
570 boolean_t pqi_check_firmware(pqi_state_t *s);
571 boolean_t pqi_prep_full(pqi_state_t *s);
572 boolean_t pqi_reset_ctl(pqi_state_t *s);
573 boolean_t pqi_hba_reset(pqi_state_t *s);
574 
575 /* ---- smartpqi_hba.c ---- */
576 boolean_t smartpqi_register_hba(pqi_state_t *);
577 void smartpqi_unregister_hba(pqi_state_t *);
578 pqi_device_t *pqi_find_target_ua(pqi_state_t *s, char *);
579 int pqi_cache_constructor(void *buf, void *un, int flags);
580 void pqi_cache_destructor(void *buf, void *un);
581 int pqi_config_all(dev_info_t *pdip, pqi_state_t *s);
582 void pqi_quiesced_notify(pqi_state_t *s);
583 
584 /* ---- smartpqi_hw.c ---- */
585 void pqi_start_io(pqi_state_t *s, pqi_queue_group_t *qg, pqi_path_t path,
586     pqi_io_request_t *io);
587 int pqi_transport_command(pqi_state_t *s, pqi_cmd_t *cmd);
588 pqi_cmd_action_t pqi_fail_cmd(pqi_cmd_t *cmd, uchar_t reason, uint_t stats);
589 void pqi_fail_drive_cmds(pqi_device_t *devp, uchar_t reason);
590 void pqi_watchdog(void *v);
591 void pqi_do_rescan(void *v);
592 void pqi_event_worker(void *v);
593 uint32_t pqi_disable_intr(pqi_state_t *s);
594 void pqi_enable_intr(pqi_state_t *s, uint32_t old_state);
595 void pqi_lun_reset(pqi_state_t *s, pqi_device_t *d);
596 
597 /* ---- smartpqi_util.c ---- */
598 pqi_dma_overhead_t *pqi_alloc_single(pqi_state_t *s, size_t len);
599 void pqi_free_single(pqi_state_t *s, pqi_dma_overhead_t *d);
600 pqi_io_request_t *pqi_alloc_io(pqi_state_t *s);
601 void pqi_free_io(pqi_io_request_t *io);
602 boolean_t pqi_timeout_io(pqi_io_request_t *io);
603 boolean_t pqi_service_io(pqi_io_request_t *io, uint8_t generation);
604 void pqi_dump_io(pqi_io_request_t *io);
605 pqi_cmd_action_t pqi_cmd_action(pqi_cmd_t *cmd, pqi_cmd_action_t a);
606 pqi_cmd_action_t pqi_cmd_action_nolock(pqi_cmd_t *cmd, pqi_cmd_action_t a);
607 char *pqi_event_to_str(uint8_t event);
608 int pqi_map_event(uint8_t event);
609 boolean_t pqi_supported_event(uint8_t event_type);
610 char *bool_to_str(int v);
611 char *dtype_to_str(int t);
612 void pqi_free_mem_len(mem_len_pair_t *m);
613 mem_len_pair_t pqi_alloc_mem_len(int len);
614 mem_len_pair_t build_cdb_str(uint8_t *cdb);
615 boolean_t pqi_is_offline(pqi_state_t *s);
616 void pqi_show_dev_state(pqi_state_t *s);
617 char *cdb_to_str(uint8_t scsi_cmd);
618 char *io_status_to_str(int val);
619 char *scsi_status_to_str(uint8_t val);
620 char *iu_type_to_str(int val);
621 
622 #ifdef __cplusplus
623 }
624 #endif
625 
626 #endif /* _SMARTPQI_H */
627