xref: /illumos-gate/usr/src/uts/common/io/aac/aac.h (revision 6d02032db7b674f185405d42cc8bf10a46a9ab3a)
1 /*
2  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 /*
7  * Copyright 2005-06 Adaptec, Inc.
8  * Copyright (c) 2005-06 Adaptec Inc., Achim Leubner
9  * Copyright (c) 2000 Michael Smith
10  * Copyright (c) 2001 Scott Long
11  * Copyright (c) 2000 BSDi
12  * All rights reserved.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions
16  * are met:
17  * 1. Redistributions of source code must retain the above copyright
18  *    notice, this list of conditions and the following disclaimer.
19  * 2. Redistributions in binary form must reproduce the above copyright
20  *    notice, this list of conditions and the following disclaimer in the
21  *    documentation and/or other materials provided with the distribution.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  *
35  *    $FreeBSD: src/sys/dev/aac/aacvar.h,v 1.47 2005/10/08 15:55:09 scottl Exp $
36  */
37 
38 #ifndef	_AAC_H_
39 #define	_AAC_H_
40 
41 #ifdef	__cplusplus
42 extern "C" {
43 #endif
44 
45 #define	AAC_ROUNDUP(x, y)		(((x) + (y) - 1) / (y) * (y))
46 
47 #define	AAC_TYPE_DEVO			1
48 #define	AAC_TYPE_ALPHA			2
49 #define	AAC_TYPE_BETA			3
50 #define	AAC_TYPE_RELEASE		4
51 
52 #ifndef	AAC_DRIVER_BUILD
53 #define	AAC_DRIVER_BUILD		1
54 #endif
55 
56 #define	AAC_DRIVER_MAJOR_VERSION	2
57 #define	AAC_DRIVER_MINOR_VERSION	2
58 #define	AAC_DRIVER_BUGFIX_LEVEL		10
59 #define	AAC_DRIVER_TYPE			AAC_TYPE_RELEASE
60 
61 #define	STR(s)				# s
62 #define	AAC_VERSION(a, b, c)		STR(a.b.c)
63 #define	AAC_DRIVER_VERSION		AAC_VERSION(AAC_DRIVER_MAJOR_VERSION, \
64 					AAC_DRIVER_MINOR_VERSION, \
65 					AAC_DRIVER_BUGFIX_LEVEL)
66 
67 #define	AACOK				0
68 #define	AACERR				-1
69 
70 #define	AAC_MAX_ADAPTERS		64
71 
72 /* Definitions for mode sense */
73 #ifndef	SD_MODE_SENSE_PAGE3_CODE
74 #define	SD_MODE_SENSE_PAGE3_CODE	0x03
75 #endif
76 
77 #ifndef	SD_MODE_SENSE_PAGE4_CODE
78 #define	SD_MODE_SENSE_PAGE4_CODE	0x04
79 #endif
80 
81 #ifndef	SCMD_SYNCHRONIZE_CACHE
82 #define	SCMD_SYNCHRONIZE_CACHE		0x35
83 #endif
84 
85 /*
86  * The controller reports status events in AIFs. We hang on to a number of
87  * these in order to pass them out to user-space management tools.
88  */
89 #define	AAC_AIFQ_LENGTH			64
90 
91 #ifdef __x86
92 #define	AAC_IMMEDIATE_TIMEOUT		30	/* seconds */
93 #else
94 #define	AAC_IMMEDIATE_TIMEOUT		60	/* seconds */
95 #endif
96 #define	AAC_FWUP_TIMEOUT		180	/* wait up to 3 minutes */
97 #define	AAC_IOCTL_TIMEOUT		900	/* wait up to 15 minutes */
98 #define	AAC_SYNC_TIMEOUT		900	/* wait up to 15 minutes */
99 
100 /* Adapter hardware interface types */
101 #define	AAC_HWIF_UNKNOWN		0
102 #define	AAC_HWIF_I960RX			1
103 #define	AAC_HWIF_RKT			2
104 
105 #define	AAC_TYPE_UNKNOWN		0
106 #define	AAC_TYPE_SCSI			1
107 #define	AAC_TYPE_SATA			2
108 #define	AAC_TYPE_SAS			3
109 
110 #define	AAC_LS32(d)			((uint32_t)((d) & 0xffffffffull))
111 #define	AAC_MS32(d)			((uint32_t)((d) >> 32))
112 #define	AAC_LO32(p64)			((uint32_t *)(p64))
113 #define	AAC_HI32(p64)			((uint32_t *)(p64) + 1)
114 
115 /*
116  * Internal events that will be handled serially by aac_event_thread()
117  */
118 #define	AAC_EVENT_AIF			(1 << 0)
119 #define	AAC_EVENT_TIMEOUT		(1 << 1)
120 #define	AAC_EVENT_SYNCTICK		(1 << 2)
121 
122 /*
123  * AAC_CMDQ_SYNC should be 0 and AAC_CMDQ_ASYNC be 1 for Sync FIB io
124  * to be served before async FIB io, see aac_start_waiting_io().
125  * So that io requests sent by interactive userland commands get
126  * responded asap.
127  */
128 enum aac_cmdq {
129 	AAC_CMDQ_SYNC,	/* sync FIB queue */
130 	AAC_CMDQ_ASYNC,	/* async FIB queue */
131 	AAC_CMDQ_NUM
132 };
133 
134 /*
135  * IO command flags
136  */
137 #define	AAC_IOCMD_SYNC		(1 << AAC_CMDQ_SYNC)
138 #define	AAC_IOCMD_ASYNC		(1 << AAC_CMDQ_ASYNC)
139 #define	AAC_IOCMD_OUTSTANDING	(1 << AAC_CMDQ_NUM)
140 #define	AAC_IOCMD_ALL		(AAC_IOCMD_SYNC | AAC_IOCMD_ASYNC | \
141 				AAC_IOCMD_OUTSTANDING)
142 
143 struct aac_cmd_queue {
144 	struct aac_cmd *q_head; /* also as the header of aac_cmd */
145 	struct aac_cmd *q_tail;
146 };
147 
148 struct aac_card_type {
149 	uint16_t vendor;	/* PCI Vendor ID */
150 	uint16_t device;	/* PCI Device ID */
151 	uint16_t subvendor;	/* PCI Subsystem Vendor ID */
152 	uint16_t subsys;	/* PCI Subsystem ID */
153 	uint16_t hwif;		/* card chip type: i960 or Rocket */
154 	uint16_t quirks;	/* card odd limits */
155 	uint16_t type;		/* hard drive type */
156 	char *vid;		/* ASCII data for INQUIRY command vendor id */
157 	char *desc;		/* ASCII data for INQUIRY command product id */
158 };
159 
160 /* Device types */
161 #define	AAC_DEV_LD		0	/* logical device */
162 #define	AAC_DEV_PD		1	/* physical device */
163 
164 /* Device flags */
165 #define	AAC_DFLAG_VALID		(1 << 0)
166 #define	AAC_DFLAG_CONFIGURING	(1 << 1)
167 
168 #define	AAC_DEV_IS_VALID(dvp)	((dvp)->flags & AAC_DFLAG_VALID)
169 
170 /*
171  * Device config change events
172  */
173 enum aac_cfg_event {
174 	AAC_CFG_NULL_NOEXIST = 0,	/* No change with no device */
175 	AAC_CFG_NULL_EXIST,		/* No change but have device */
176 	AAC_CFG_ADD,			/* Device added */
177 	AAC_CFG_DELETE,			/* Device deleted */
178 	AAC_CFG_CHANGE			/* Device changed */
179 };
180 
181 struct aac_device {
182 	int flags;
183 
184 	uint8_t type;
185 	dev_info_t *dip;
186 	int ncmds[AAC_CMDQ_NUM];	/* outstanding cmds of the device */
187 	int throttle[AAC_CMDQ_NUM];	/* hold IO cmds for the device */
188 };
189 
190 /* Array description */
191 struct aac_container {
192 	struct aac_device dev;
193 
194 	uint32_t cid;		/* container id */
195 	uint32_t uid;		/* container uid */
196 	uint64_t size;		/* in block */
197 	uint8_t locked;
198 	uint8_t deleted;
199 	uint8_t reset;		/* container is being reseted */
200 };
201 
202 /* Non-DASD phys. device descrption, eg. CDROM or tape */
203 struct aac_nondasd {
204 	struct aac_device dev;
205 
206 	uint32_t bus;
207 	uint32_t tid;
208 };
209 
210 /*
211  * The firmware can support a lot of outstanding commands. Each aac_slot
212  * is corresponding to one of such commands. It records the command and
213  * associated DMA resource for FIB command.
214  */
215 struct aac_slot {
216 	struct aac_slot *next;	/* next slot in the free slot list */
217 	int index;		/* index of this slot */
218 	ddi_acc_handle_t fib_acc_handle;
219 	ddi_dma_handle_t fib_dma_handle;
220 	uint64_t fib_phyaddr;	/* physical address of FIB memory */
221 	struct aac_cmd *acp;	/* command using this slot */
222 	struct aac_fib *fibp;	/* virtual address of FIB memory */
223 };
224 
225 /*
226  * Scatter-gather list structure defined by HBA hardware
227  */
228 struct aac_sge {
229 	uint32_t bcount;	/* byte count */
230 	union {
231 		uint32_t ad32;	/* 32 bit address */
232 		struct {
233 			uint32_t lo;
234 			uint32_t hi;
235 		} ad64;		/* 64 bit address */
236 	} addr;
237 };
238 
239 /* aac_cmd flags */
240 #define	AAC_CMD_CONSISTENT		(1 << 0)
241 #define	AAC_CMD_DMA_PARTIAL		(1 << 1)
242 #define	AAC_CMD_DMA_VALID		(1 << 2)
243 #define	AAC_CMD_BUF_READ		(1 << 3)
244 #define	AAC_CMD_BUF_WRITE		(1 << 4)
245 #define	AAC_CMD_SYNC			(1 << 5) /* use sync FIB */
246 #define	AAC_CMD_NO_INTR			(1 << 6) /* poll IO, no intr */
247 #define	AAC_CMD_NO_CB			(1 << 7) /* sync IO, no callback */
248 #define	AAC_CMD_NTAG			(1 << 8)
249 #define	AAC_CMD_CMPLT			(1 << 9) /* cmd exec'ed by driver/fw */
250 #define	AAC_CMD_ABORT			(1 << 10)
251 #define	AAC_CMD_TIMEOUT			(1 << 11)
252 #define	AAC_CMD_ERR			(1 << 12)
253 #define	AAC_CMD_IN_SYNC_SLOT		(1 << 13)
254 
255 struct aac_softstate;
256 typedef void (*aac_cmd_fib_t)(struct aac_softstate *, struct aac_cmd *);
257 
258 struct aac_cmd {
259 	/*
260 	 * Note: should be the first member for aac_cmd_queue to work
261 	 * correctly.
262 	 */
263 	struct aac_cmd *next;
264 	struct aac_cmd *prev;
265 
266 	struct scsi_pkt *pkt;
267 	int cmdlen;
268 	int flags;
269 	uint32_t timeout; /* time when the cmd should have completed */
270 	struct buf *bp;
271 	ddi_dma_handle_t buf_dma_handle;
272 
273 	/* For non-aligned buffer and SRB */
274 	caddr_t abp;
275 	ddi_acc_handle_t abh;
276 
277 	/* Data transfer state */
278 	ddi_dma_cookie_t cookie;
279 	uint_t left_cookien;
280 	uint_t cur_win;
281 	uint_t total_nwin;
282 	size_t total_xfer;
283 	uint64_t blkno;
284 	uint32_t bcount;	/* buffer size in byte */
285 	struct aac_sge *sgt;	/* sg table */
286 
287 	/* FIB construct function */
288 	aac_cmd_fib_t aac_cmd_fib;
289 	/* Call back function for completed command */
290 	void (*ac_comp)(struct aac_softstate *, struct aac_cmd *);
291 
292 	struct aac_slot *slotp;	/* slot used by this command */
293 	struct aac_device *dvp;	/* target device */
294 
295 	/* FIB for this IO command */
296 	int fib_size; /* size of the FIB xferred to/from the card */
297 	struct aac_fib *fibp;
298 
299 #ifdef DEBUG
300 	uint32_t fib_flags;
301 #endif
302 };
303 
304 /* Flags for attach tracking */
305 #define	AAC_ATTACH_SOFTSTATE_ALLOCED	(1 << 0)
306 #define	AAC_ATTACH_CARD_DETECTED	(1 << 1)
307 #define	AAC_ATTACH_PCI_MEM_MAPPED	(1 << 2)
308 #define	AAC_ATTACH_KMUTEX_INITED	(1 << 3)
309 #define	AAC_ATTACH_SCSI_TRAN_SETUP	(1 << 4)
310 #define	AAC_ATTACH_COMM_SPACE_SETUP	(1 << 5)
311 #define	AAC_ATTACH_CREATE_DEVCTL	(1 << 6)
312 #define	AAC_ATTACH_CREATE_SCSI		(1 << 7)
313 
314 /* Driver running states */
315 #define	AAC_STATE_STOPPED	0
316 #define	AAC_STATE_RUN		(1 << 0)
317 #define	AAC_STATE_RESET		(1 << 1)
318 #define	AAC_STATE_QUIESCED	(1 << 2)
319 #define	AAC_STATE_DEAD		(1 << 3)
320 #define	AAC_STATE_INTR		(1 << 4)
321 
322 /*
323  * Flags for aac firmware
324  * Note: Quirks are only valid for the older cards. These cards only supported
325  * old comm. Thus they are not valid for any cards that support new comm.
326  */
327 #define	AAC_FLAGS_SG_64BIT	(1 << 0) /* Use 64-bit S/G addresses */
328 #define	AAC_FLAGS_4GB_WINDOW	(1 << 1) /* Can access host mem 2-4GB range */
329 #define	AAC_FLAGS_NO4GB	(1 << 2)	/* quirk: FIB addresses must reside */
330 					/*	  between 0x2000 & 0x7FFFFFFF */
331 #define	AAC_FLAGS_256FIBS	(1 << 3) /* quirk: Can only do 256 commands */
332 #define	AAC_FLAGS_NEW_COMM	(1 << 4) /* New comm. interface supported */
333 #define	AAC_FLAGS_RAW_IO	(1 << 5) /* Raw I/O interface */
334 #define	AAC_FLAGS_ARRAY_64BIT	(1 << 6) /* 64-bit array size */
335 #define	AAC_FLAGS_LBA_64BIT	(1 << 7) /* 64-bit LBA supported */
336 #define	AAC_FLAGS_17SG		(1 << 8) /* quirk: 17 scatter gather maximum */
337 #define	AAC_FLAGS_34SG		(1 << 9) /* quirk: 34 scatter gather maximum */
338 #define	AAC_FLAGS_NONDASD	(1 << 10) /* non-DASD device supported */
339 #define	AAC_FLAGS_BRKUP		(1 << 11) /* pkt breakup support */
340 
341 struct aac_softstate;
342 struct aac_interface {
343 	int (*aif_get_fwstatus)(struct aac_softstate *);
344 	int (*aif_get_mailbox)(struct aac_softstate *, int);
345 	void (*aif_set_mailbox)(struct aac_softstate *, uint32_t,
346 	    uint32_t, uint32_t, uint32_t, uint32_t);
347 };
348 
349 #define	AAC_CTXFLAG_FILLED	0x01	/* aifq's full for this ctx */
350 #define	AAC_CTXFLAG_RESETED	0x02
351 
352 struct aac_fib_context {
353 	uint32_t unique;
354 	int ctx_idx;
355 	int ctx_filled;		/* aifq is full for this fib context */
356 	int ctx_flags;
357 	int ctx_overrun;
358 	struct aac_fib_context *next, *prev;
359 };
360 
361 #define	AAC_VENDOR_LEN		8
362 #define	AAC_PRODUCT_LEN		16
363 
364 struct aac_softstate {
365 	int card;		/* index to aac_cards */
366 	uint16_t hwif;		/* card chip type: i960 or Rocket */
367 	uint16_t vendid;	/* vendor id */
368 	uint16_t subvendid;	/* sub vendor id */
369 	uint16_t devid;		/* device id */
370 	uint16_t subsysid;	/* sub system id */
371 	char vendor_name[AAC_VENDOR_LEN + 1];
372 	char product_name[AAC_PRODUCT_LEN + 1];
373 	uint32_t support_opt;	/* firmware features */
374 	uint32_t support_opt2;
375 	uint32_t feature_bits;
376 	uint32_t atu_size;	/* actual size of PCI mem space */
377 	uint32_t map_size;	/* mapped PCI mem space size */
378 	uint32_t map_size_min;	/* minimum size of PCI mem that must be */
379 				/* mapped to address the card */
380 	int flags;		/* firmware features enabled */
381 	int instance;
382 	dev_info_t *devinfo_p;
383 	scsi_hba_tran_t *hba_tran;
384 	int slen;
385 	int legacy;		/* legacy device naming */
386 	uint32_t dma_max;	/* for buf breakup */
387 
388 	/* DMA attributes */
389 	ddi_dma_attr_t buf_dma_attr;
390 	ddi_dma_attr_t addr_dma_attr;
391 
392 	/* PCI spaces */
393 	ddi_device_acc_attr_t acc_attr;
394 	ddi_device_acc_attr_t reg_attr;
395 	ddi_acc_handle_t pci_mem_handle;
396 	uint8_t *pci_mem_base_vaddr;
397 	uint32_t pci_mem_base_paddr;
398 
399 	struct aac_interface aac_if;	/* adapter hardware interface */
400 
401 	struct aac_cmd sync_ac;		/* sync FIB */
402 
403 	/* Communication space */
404 	struct aac_comm_space *comm_space;
405 	ddi_acc_handle_t comm_space_acc_handle;
406 	ddi_dma_handle_t comm_space_dma_handle;
407 	uint32_t comm_space_phyaddr;
408 
409 	/* Old Comm. interface: message queues */
410 	struct aac_queue_table *qtablep;
411 	struct aac_queue_entry *qentries[AAC_QUEUE_COUNT];
412 
413 	/* New Comm. interface */
414 	uint32_t aac_max_fibs;		/* max. FIB count */
415 	uint32_t aac_max_fib_size;	/* max. FIB size */
416 	uint32_t aac_sg_tablesize;	/* max. sg count from host */
417 	uint32_t aac_max_sectors;	/* max. I/O size from host (blocks) */
418 
419 	aac_cmd_fib_t aac_cmd_fib;	/* IO cmd FIB construct function */
420 	aac_cmd_fib_t aac_cmd_fib_scsi;	/* SRB construct function */
421 
422 	ddi_softintr_t softint_id;	/* soft intr */
423 
424 	kmutex_t io_lock;
425 	int state;			/* driver state */
426 
427 	struct aac_container containers[AAC_MAX_LD];
428 	int container_count;		/* max container id + 1 */
429 	struct aac_nondasd *nondasds;
430 	uint32_t bus_max;		/* max FW buses exposed */
431 	uint32_t tgt_max;		/* max FW target per bus */
432 
433 	/*
434 	 * Command queues
435 	 * Each aac command flows through wait(or wait_sync) queue,
436 	 * busy queue, and complete queue sequentially.
437 	 */
438 	struct aac_cmd_queue q_wait[AAC_CMDQ_NUM];
439 	struct aac_cmd_queue q_busy;	/* outstanding cmd queue */
440 	kmutex_t q_comp_mutex;
441 	struct aac_cmd_queue q_comp;	/* completed io requests */
442 
443 	/* I/O slots and FIBs */
444 	int total_slots;		/* total slots allocated */
445 	int total_fibs;			/* total FIBs allocated */
446 	struct aac_slot *io_slot;	/* static list for allocated slots */
447 	struct aac_slot *free_io_slot_head;
448 
449 	kcondvar_t event;		/* for ioctl_send_fib() and sync IO */
450 	kcondvar_t sync_fib_cv;		/* for sync_fib_slot_bind/release */
451 
452 	int bus_ncmds[AAC_CMDQ_NUM];	/* total outstanding async cmds */
453 	int bus_throttle[AAC_CMDQ_NUM];	/* hold IO cmds for the bus */
454 	int ndrains;			/* number of draining threads */
455 	timeout_id_t drain_timeid;	/* for outstanding cmd drain */
456 	kcondvar_t drain_cv;		/* for quiesce drain */
457 
458 	/* Internal timer */
459 	kmutex_t time_mutex;
460 	timeout_id_t timeout_id;	/* for timeout daemon */
461 	uint32_t timebase;		/* internal timer in seconds */
462 	uint32_t time_sync;		/* next time to sync with firmware */
463 	uint32_t time_out;		/* next time to check timeout */
464 	uint32_t time_throttle;		/* next time to restore throttle */
465 
466 	/* Internal events handling */
467 	kmutex_t ev_lock;
468 	int events;
469 	kthread_t *event_thread;	/* for AIF & timeout */
470 	kcondvar_t event_wait_cv;
471 	kcondvar_t event_disp_cv;
472 
473 	/* AIF */
474 	kmutex_t aifq_mutex;		/* for AIF queue aifq */
475 	kcondvar_t aifq_cv;
476 	union aac_fib_align aifq[AAC_AIFQ_LENGTH];
477 	int aifq_idx;			/* slot for next new AIF */
478 	int aifq_wrap;			/* AIF queue has ever been wrapped */
479 	struct aac_fib_context aifctx;	/* sys aif ctx */
480 	struct aac_fib_context *fibctx_p;
481 	int devcfg_wait_on;		/* AIF event waited for rescan */
482 
483 	int fm_capabilities;
484 
485 	/* MSI specific fields */
486 	ddi_intr_handle_t *htable;	/* For array of interrupts */
487 	int intr_type;			/* What type of interrupt */
488 	int intr_cnt;			/* # of intrs count returned */
489 	int intr_size;
490 	uint_t intr_pri;		/* Interrupt priority   */
491 	int intr_cap;			/* Interrupt capabilities */
492 
493 #ifdef DEBUG
494 	/* UART trace printf variables */
495 	uint32_t debug_flags;		/* debug print flags bitmap */
496 	uint32_t debug_fib_flags;	/* debug FIB print flags bitmap */
497 	uint32_t debug_fw_flags;	/* FW debug flags */
498 	uint32_t debug_buf_offset;	/* offset from DPMEM start */
499 	uint32_t debug_buf_size;	/* FW debug buffer size in bytes */
500 	uint32_t debug_header_size;	/* size of debug header */
501 #endif
502 };
503 
504 /*
505  * The following data are kept stable because they are only written at driver
506  * initialization, and we do not allow them changed otherwise even at driver
507  * re-initialization.
508  */
509 _NOTE(SCHEME_PROTECTS_DATA("stable data", aac_softstate::{flags slen \
510     buf_dma_attr pci_mem_handle pci_mem_base_vaddr \
511     comm_space_acc_handle comm_space_dma_handle aac_max_fib_size \
512     aac_sg_tablesize aac_cmd_fib aac_cmd_fib_scsi debug_flags bus_max tgt_max}))
513 
514 #ifdef DEBUG
515 
516 #define	AACDB_FLAGS_MASK		0x0000ffff
517 #define	AACDB_FLAGS_KERNEL_PRINT	0x00000001
518 #define	AACDB_FLAGS_FW_PRINT		0x00000002
519 #define	AACDB_FLAGS_NO_HEADERS		0x00000004
520 
521 #define	AACDB_FLAGS_MISC		0x00000010
522 #define	AACDB_FLAGS_FUNC1		0x00000020
523 #define	AACDB_FLAGS_FUNC2		0x00000040
524 #define	AACDB_FLAGS_SCMD		0x00000080
525 #define	AACDB_FLAGS_AIF			0x00000100
526 #define	AACDB_FLAGS_FIB			0x00000200
527 #define	AACDB_FLAGS_IOCTL		0x00000400
528 
529 /*
530  * Flags for FIB print
531  */
532 /* FIB sources */
533 #define	AACDB_FLAGS_FIB_SCMD		0x00000001
534 #define	AACDB_FLAGS_FIB_IOCTL		0x00000002
535 #define	AACDB_FLAGS_FIB_SRB		0x00000004
536 #define	AACDB_FLAGS_FIB_SYNC		0x00000008
537 /* FIB components */
538 #define	AACDB_FLAGS_FIB_HEADER		0x00000010
539 /* FIB states */
540 #define	AACDB_FLAGS_FIB_TIMEOUT		0x00000100
541 
542 extern uint32_t aac_debug_flags;
543 extern int aac_dbflag_on(struct aac_softstate *, int);
544 extern void aac_printf(struct aac_softstate *, uint_t, const char *, ...);
545 extern void aac_print_fib(struct aac_softstate *, struct aac_slot *);
546 
547 #define	AACDB_PRINT(s, lev, ...) { \
548 	if (aac_dbflag_on((s), AACDB_FLAGS_MISC)) \
549 		aac_printf((s), (lev), __VA_ARGS__); }
550 
551 #define	AACDB_PRINT_IOCTL(s, ...) { \
552 	if (aac_dbflag_on((s), AACDB_FLAGS_IOCTL)) \
553 		aac_printf((s), CE_NOTE, __VA_ARGS__); }
554 
555 #define	AACDB_PRINT_TRAN(s, ...) { \
556 	if (aac_dbflag_on((s), AACDB_FLAGS_SCMD)) \
557 		aac_printf((s), CE_NOTE, __VA_ARGS__); }
558 
559 #define	DBCALLED(s, n) { \
560 	if (aac_dbflag_on((s), AACDB_FLAGS_FUNC ## n)) \
561 		aac_printf((s), CE_NOTE, "--- %s() called ---", __func__); }
562 
563 #define	AACDB_PRINT_SCMD(s, x) { \
564 	if (aac_dbflag_on((s), AACDB_FLAGS_SCMD)) aac_print_scmd((s), (x)); }
565 
566 #define	AACDB_PRINT_AIF(s, x) { \
567 	if (aac_dbflag_on((s), AACDB_FLAGS_AIF)) aac_print_aif((s), (x)); }
568 
569 #define	AACDB_PRINT_FIB(s, x) { \
570 	if (aac_dbflag_on((s), AACDB_FLAGS_FIB)) aac_print_fib((s), (x)); }
571 
572 #else /* DEBUG */
573 
574 #define	AACDB_PRINT(s, lev, ...)
575 #define	AACDB_PRINT_IOCTL(s, ...)
576 #define	AACDB_PRINT_TRAN(s, ...)
577 #define	AACDB_PRINT_FIB(s, x)
578 #define	AACDB_PRINT_SCMD(s, x)
579 #define	AACDB_PRINT_AIF(s, x)
580 #define	DBCALLED(s, n)
581 
582 #endif /* DEBUG */
583 
584 #ifdef	__cplusplus
585 }
586 #endif
587 
588 #endif /* _AAC_H_ */
589