1 /*
   2  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
   3  * Use is subject to license terms.
   4  */
   5 
   6 /*
   7  * Copyright (c) 2010-12 PMC-Sierra, Inc.
   8  * Copyright (c) 2005-10 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 
  36 #ifndef _AAC_H_
  37 #define _AAC_H_
  38 
  39 #pragma ident   "@(#)aac.h      1.16    08/01/29 SMI"
  40 
  41 #ifdef  __cplusplus
  42 extern "C" {
  43 #endif
  44 
  45 #ifdef AAC_DEBUG_ALL
  46 #define AAC_DEBUG
  47 #define DEBUG                   /* activate assertions */
  48 #endif
  49 
  50 #define AAC_ROUNDUP(x, y)               (((x) + (y) - 1) / (y) * (y))
  51 
  52 #define AAC_TYPE_DEVO                   1
  53 #define AAC_TYPE_ALPHA                  2
  54 #define AAC_TYPE_BETA                   3
  55 #define AAC_TYPE_RELEASE                4
  56 
  57 #ifndef AAC_DRIVER_BUILD
  58 #define AAC_DRIVER_BUILD                1
  59 #endif
  60 
  61 #define AAC_DRIVER_MAJOR_VERSION        2
  62 #define AAC_DRIVER_MINOR_VERSION        7
  63 #define AAC_DRIVER_BUGFIX_LEVEL         1
  64 #define AAC_DRIVER_TYPE                 AAC_TYPE_RELEASE
  65 
  66 #define STR(s)                          # s
  67 #define AAC_VERSION(a, b, c)            STR(a.b.c)
  68 #define AAC_DRIVER_VERSION              AAC_VERSION(AAC_DRIVER_MAJOR_VERSION, \
  69                                         AAC_DRIVER_MINOR_VERSION, \
  70                                         AAC_DRIVER_BUGFIX_LEVEL)
  71 
  72 #define AACOK                           0
  73 #define AACOK2                          1
  74 #define AACERR                          -1
  75 
  76 #define AAC_MAX_ADAPTERS                64
  77 
  78 /* Definitions for mode sense */
  79 #ifndef SD_MODE_SENSE_PAGE3_CODE
  80 #define SD_MODE_SENSE_PAGE3_CODE        0x03
  81 #endif
  82 
  83 #ifndef SD_MODE_SENSE_PAGE4_CODE
  84 #define SD_MODE_SENSE_PAGE4_CODE        0x04
  85 #endif
  86 
  87 #ifndef SCMD_SYNCHRONIZE_CACHE
  88 #define SCMD_SYNCHRONIZE_CACHE          0x35
  89 #endif
  90 
  91 /*
  92  * The controller reports status events in AIFs. We hang on to a number of
  93  * these in order to pass them out to user-space management tools.
  94  */
  95 #define AAC_AIFQ_LENGTH                 64
  96 
  97 #ifdef __x86
  98 #define AAC_IMMEDIATE_TIMEOUT           30      /* seconds */
  99 #else
 100 #define AAC_IMMEDIATE_TIMEOUT           60      /* seconds */
 101 #endif
 102 #define AAC_FWUP_TIMEOUT                180     /* wait up to 3 minutes */
 103 #define AAC_IOCTL_TIMEOUT               900     /* wait up to 15 minutes */
 104 #define AAC_AIF_TIMEOUT         180 /* up to 3 minutes */
 105 
 106 /* Adapter hardware interface types */
 107 #define AAC_HWIF_UNKNOWN                0
 108 #define AAC_HWIF_I960RX                 1
 109 #define AAC_HWIF_RKT                    2
 110 #define AAC_HWIF_NARK                   3
 111 #define AAC_HWIF_SRC                    4
 112 #define AAC_HWIF_SRCV                   5
 113 
 114 #define AAC_TYPE_UNKNOWN                0
 115 #define AAC_TYPE_SCSI                   1
 116 #define AAC_TYPE_SATA                   2
 117 #define AAC_TYPE_SAS                    3
 118 
 119 #define AAC_LS32(d)                     ((uint32_t)((d) & 0xffffffffull))
 120 #define AAC_MS32(d)                     ((uint32_t)((d) >> 32))
 121 #define AAC_LO32(p64)                   ((uint32_t *)(p64))
 122 #define AAC_HI32(p64)                   ((uint32_t *)(p64) + 1)
 123 
 124 /*
 125  * AAC_CMDQ_SYNC should be 0 and AAC_CMDQ_ASYNC be 1 for Sync FIB io
 126  * to be served before async FIB io, see aac_start_waiting_io().
 127  * So that io requests sent by interactive userland commands get
 128  * responded asap.
 129  */
 130 enum aac_cmdq {
 131         AAC_CMDQ_SYNC,  /* sync FIB queue */
 132         AAC_CMDQ_ASYNC, /* async FIB queue */
 133         AAC_CMDQ_NUM
 134 };
 135 
 136 /*
 137  * IO command flags
 138  */
 139 #define AAC_IOCMD_SYNC          (1 << AAC_CMDQ_SYNC)
 140 #define AAC_IOCMD_ASYNC         (1 << AAC_CMDQ_ASYNC)
 141 #define AAC_IOCMD_OUTSTANDING   (1 << AAC_CMDQ_NUM)
 142 #define AAC_IOCMD_ALL           (AAC_IOCMD_SYNC | AAC_IOCMD_ASYNC | \
 143                                 AAC_IOCMD_OUTSTANDING)
 144 
 145 struct aac_cmd_queue {
 146         struct aac_cmd *q_head; /* also as the header of aac_cmd */
 147         struct aac_cmd *q_tail;
 148 };
 149 
 150 struct aac_card_type {
 151         uint16_t vendor;        /* PCI Vendor ID */
 152         uint16_t device;        /* PCI Device ID */
 153         uint16_t subvendor;     /* PCI Subsystem Vendor ID */
 154         uint16_t subsys;        /* PCI Subsystem ID */
 155         uint16_t hwif;          /* card chip type: i960 or Rocket */
 156         uint16_t quirks;        /* card odd limits */
 157         uint16_t type;          /* hard drive type */
 158         char *vid;              /* ASCII data for INQUIRY command vendor id */
 159         char *desc;             /* ASCII data for INQUIRY command product id */
 160 };
 161 
 162 #define AAC_DEV_LD      0       /* logical device */
 163 #define AAC_DEV_PD      1       /* physical device */
 164 
 165 #define AAC_DEV_NONE    0
 166 #define AAC_DEV_ONLINE  1
 167 #define AAC_DEV_OFFLINE 2
 168 struct aac_device {
 169         uint8_t valid;
 170         uint8_t type;
 171         dev_info_t *dip;
 172         int ncmds[AAC_CMDQ_NUM];        /* outstanding cmds of the device */
 173         int throttle[AAC_CMDQ_NUM];     /* hold IO cmds for the device */
 174 };
 175 
 176 /* Array description */
 177 struct aac_container {
 178         struct aac_device dev;
 179 
 180         uint32_t cid;           /* container id */
 181         uint32_t uid;           /* container uid */
 182         uint64_t size;          /* in block */
 183         uint8_t locked;
 184         uint8_t deleted;
 185         uint8_t reset;          /* container is being reseted */
 186 };
 187 
 188 /* Non-DASD phys. device descrption, eg. CDROM or tape */
 189 struct aac_nondasd {
 190         struct aac_device dev;
 191 
 192         uint32_t bus;
 193         uint32_t tid;
 194         uint8_t dtype;          /* SCSI device type */
 195 };
 196 
 197 /*
 198  * The firmware can support a lot of outstanding commands. Each aac_slot
 199  * is corresponding to one of such commands. It records the command and
 200  * associated DMA resource for FIB command.
 201  */
 202 struct aac_slot {
 203         struct aac_slot *next;  /* next slot in the free slot list */
 204         int index;              /* index of this slot */
 205         ddi_acc_handle_t fib_acc_handle;
 206         ddi_dma_handle_t fib_dma_handle;
 207         uint64_t fib_phyaddr;   /* physical address of FIB memory */
 208         struct aac_cmd *acp;    /* command using this slot */
 209         struct aac_fib *fibp;   /* virtual address of FIB memory */
 210 };
 211 
 212 /* Flags for attach tracking */
 213 #define AAC_ATTACH_SOFTSTATE_ALLOCED    (1 << 0)
 214 #define AAC_ATTACH_CARD_DETECTED        (1 << 1)
 215 #define AAC_ATTACH_PCI_MEM_MAPPED       (1 << 2)
 216 #define AAC_ATTACH_KMUTEX_INITED        (1 << 3)
 217 #define AAC_ATTACH_HARD_INTR_SETUP      (1 << 4)
 218 #define AAC_ATTACH_SOFT_INTR_SETUP      (1 << 5)
 219 #define AAC_ATTACH_SCSI_TRAN_SETUP      (1 << 6)
 220 #define AAC_ATTACH_COMM_SPACE_SETUP     (1 << 7)
 221 #define AAC_ATTACH_CREATE_DEVCTL        (1 << 8)
 222 #define AAC_ATTACH_CREATE_SCSI          (1 << 9)
 223 
 224 /* Driver running states */
 225 #define AAC_STATE_STOPPED       0
 226 #define AAC_STATE_RUN           (1 << 0)
 227 #define AAC_STATE_RESET         (1 << 1)
 228 #define AAC_STATE_QUIESCED      (1 << 2)
 229 #define AAC_STATE_DEAD          (1 << 3)
 230 
 231 /*
 232  * Flags for aac firmware
 233  * Note: Quirks are only valid for the older cards. These cards only supported
 234  * old comm. Thus they are not valid for any cards that support new comm.
 235  */
 236 #define AAC_FLAGS_SG_64BIT      (1 << 0) /* Use 64-bit S/G addresses */
 237 #define AAC_FLAGS_4GB_WINDOW    (1 << 1) /* Can access host mem 2-4GB range */
 238 #define AAC_FLAGS_NO4GB (1 << 2)  /* quirk: FIB addresses must reside */
 239                                         /*        between 0x2000 & 0x7FFFFFFF */
 240 #define AAC_FLAGS_256FIBS       (1 << 3) /* quirk: Can only do 256 commands */
 241 #define AAC_FLAGS_NEW_COMM      (1 << 4) /* New comm. interface supported */
 242 #define AAC_FLAGS_RAW_IO        (1 << 5) /* Raw I/O interface */
 243 #define AAC_FLAGS_ARRAY_64BIT   (1 << 6) /* 64-bit array size */
 244 #define AAC_FLAGS_LBA_64BIT     (1 << 7) /* 64-bit LBA supported */
 245 #define AAC_FLAGS_17SG          (1 << 8) /* quirk: 17 scatter gather maximum */
 246 #define AAC_FLAGS_34SG          (1 << 9) /* quirk: 34 scatter gather maximum */
 247 #define AAC_FLAGS_NONDASD       (1 << 10) /* non-DASD device supported */
 248 #define AAC_FLAGS_NEW_COMM_TYPE1        (1 << 11) /* New comm. type1 supported */
 249 #define AAC_FLAGS_NEW_COMM_TYPE2        (1 << 12) /* New comm. type2 supported */
 250 #define AAC_FLAGS_NEW_COMM_TYPE34       (1 << 13) /* New comm. type3-4 */
 251 #define AAC_FLAGS_SYNC_MODE     (1 << 14) /* Sync. transfer mode */
 252 
 253 struct aac_softstate;
 254 struct aac_interface {
 255         void (*aif_set_intr)(struct aac_softstate *, int enable);
 256         void (*aif_status_clr)(struct aac_softstate *, int mask);
 257         int (*aif_status_get)(struct aac_softstate *);
 258         void (*aif_notify)(struct aac_softstate *, int val);
 259         int (*aif_get_fwstatus)(struct aac_softstate *);
 260         int (*aif_get_mailbox)(struct aac_softstate *, int);
 261         void (*aif_set_mailbox)(struct aac_softstate *, uint32_t,
 262             uint32_t, uint32_t, uint32_t, uint32_t);
 263         int (*aif_send_command)(struct aac_softstate *, struct aac_slot *);
 264 };
 265 
 266 struct aac_fib_context {
 267         uint32_t unique;
 268         int ctx_idx;
 269         int ctx_filled;         /* aifq is full for this fib context */
 270         struct aac_fib_context *next, *prev;
 271 };
 272 
 273 typedef void (*aac_cmd_fib_t)(struct aac_softstate *, struct aac_cmd *);
 274 
 275 #define AAC_VENDOR_LEN          8
 276 #define AAC_PRODUCT_LEN         16
 277 
 278 struct aac_softstate {
 279         int card;               /* index to aac_cards */
 280         uint16_t hwif;          /* card chip type: i960 or Rocket */
 281         uint16_t vendid;        /* vendor id */
 282         uint16_t subvendid;     /* sub vendor id */
 283         uint16_t devid;         /* device id */
 284         uint16_t subsysid;      /* sub system id */
 285         char vendor_name[AAC_VENDOR_LEN + 1];
 286         char product_name[AAC_PRODUCT_LEN + 1];
 287         uint32_t support_opt;   /* firmware features */
 288         uint32_t atu_size;      /* actual size of PCI mem space */
 289         uint32_t map_size;      /* mapped PCI mem space size */
 290         uint32_t map_size_min;  /* minimum size of PCI mem that must be */
 291                                 /* mapped to address the card */
 292         int flags;              /* firmware features enabled */
 293         int instance;
 294         dev_info_t *devinfo_p;
 295         scsi_hba_tran_t *hba_tran;
 296         int slen;
 297         int legacy;
 298         int sync_mode;
 299         int no_sgl_conv;
 300 
 301         /* DMA attributes */
 302         ddi_dma_attr_t buf_dma_attr;
 303         ddi_dma_attr_t addr_dma_attr;
 304 
 305         /* PCI spaces */
 306         ddi_acc_handle_t pci_mem_handle[AAC_MAX_MEM_SPACE];
 307         char *pci_mem_base_vaddr[AAC_MAX_MEM_SPACE];
 308         uint32_t pci_mem_base_paddr[AAC_MAX_MEM_SPACE];
 309 
 310         struct aac_interface aac_if;    /* adapter hardware interface */
 311 
 312         struct aac_slot *sync_slot;      /* sync FIB */
 313         int sync_slot_busy;
 314         struct aac_slot *sync_mode_slot;
 315     
 316         /* Communication space */
 317         struct aac_comm_space *comm_space;
 318         ddi_acc_handle_t comm_space_acc_handle;
 319         ddi_dma_handle_t comm_space_dma_handle;
 320         uint32_t comm_space_phyaddr;
 321 
 322         /* New Comm. type1: response buffer index */
 323         uint32_t aac_host_rrq_idx;
 324 
 325     /* Old Comm. interface: message queues */
 326         struct aac_queue_table *qtablep;
 327         struct aac_queue_entry *qentries[AAC_QUEUE_COUNT];
 328 
 329         /* New Comm. interface */
 330         uint32_t aac_max_fibs;          /* max. FIB count */
 331         uint32_t aac_max_fib_size;      /* max. FIB size */
 332         uint32_t aac_sg_tablesize;      /* max. sg count from host */
 333         uint32_t aac_max_sectors;       /* max. I/O size from host (blocks) */
 334         uint32_t aac_max_aif;           /* max. AIF count */
 335 
 336         aac_cmd_fib_t aac_cmd_fib;      /* IO cmd FIB construct function */
 337         aac_cmd_fib_t aac_cmd_fib_scsi; /* SRB construct function */
 338 
 339         ddi_iblock_cookie_t iblock_cookie;
 340         ddi_softintr_t softint_id;      /* soft intr */
 341 
 342         kmutex_t io_lock;
 343         int state;                      /* driver state */
 344 
 345         struct aac_container containers[AAC_MAX_LD];
 346         int container_count;            /* max container id + 1 */
 347         struct aac_nondasd *nondasds;
 348         uint32_t bus_max;               /* max FW buses exposed */
 349         uint32_t tgt_max;               /* max FW target per bus */
 350         uint32_t aac_feature_bits;
 351         uint32_t aac_support_opt2;
 352 
 353         /*
 354          * Command queues
 355          * Each aac command flows through wait(or wait_sync) queue,
 356          * busy queue, and complete queue sequentially.
 357          */
 358         struct aac_cmd_queue q_wait[AAC_CMDQ_NUM];
 359         struct aac_cmd_queue q_busy;    /* outstanding cmd queue */
 360         kmutex_t q_comp_mutex;
 361         struct aac_cmd_queue q_comp;    /* completed io requests */
 362 
 363         /* I/O slots and FIBs */
 364         int total_slots;                /* total slots allocated */
 365         int total_fibs;                 /* total FIBs allocated */
 366         struct aac_slot *io_slot;       /* static list for allocated slots */
 367         struct aac_slot *free_io_slot_head;
 368 
 369         timeout_id_t timeout_id;        /* for timeout daemon */
 370 
 371         kcondvar_t event;               /* for ioctl_send_fib() and sync IO */
 372 
 373         int bus_ncmds[AAC_CMDQ_NUM];    /* total outstanding async cmds */
 374         int bus_throttle[AAC_CMDQ_NUM]; /* hold IO cmds for the bus */
 375         int ndrains;                    /* number of draining threads */
 376         timeout_id_t drain_timeid;      /* for outstanding cmd drain */
 377         kcondvar_t drain_cv;            /* for quiesce drain */
 378 
 379         /* AIF */
 380         kmutex_t aifq_mutex;            /* for AIF queue aifq */
 381         kcondvar_t aifv;
 382         union aac_fib_align aifq[AAC_AIFQ_LENGTH];
 383         int aifq_idx;                   /* slot for next new AIF */
 384         int aifq_wrap;                  /* AIF queue has ever been wrapped */
 385         struct aac_fib_context *fibctx;
 386         int devcfg_wait_on;             /* AIF event waited for rescan */
 387 
 388         int fm_capabilities;
 389         ddi_taskq_t *taskq;
 390 
 391 #ifdef AAC_DEBUG
 392         /* UART trace printf variables */
 393         uint32_t debug_flags;           /* debug print flags bitmap */
 394         uint32_t debug_fw_flags;        /* FW debug flags */
 395         uint32_t debug_buf_offset;      /* offset from DPMEM start */
 396         uint32_t debug_buf_size;        /* FW debug buffer size in bytes */
 397         uint32_t debug_header_size;     /* size of debug header */
 398 #endif
 399 };
 400 
 401 /*
 402  * The following data are kept stable because they are only written at driver
 403  * initialization, and we do not allow them changed otherwise even at driver
 404  * re-initialization.
 405  */
 406 _NOTE(SCHEME_PROTECTS_DATA("stable data", aac_softstate::{flags slen \
 407     buf_dma_attr pci_mem_handle pci_mem_base_vaddr \
 408     comm_space_acc_handle comm_space_dma_handle aac_max_fib_size \
 409     aac_sg_tablesize aac_cmd_fib aac_cmd_fib_scsi debug_flags bus_max tgt_max \
 410         aac_feature_bits}))
 411 
 412 /*
 413  * Scatter-gather list structure defined by HBA hardware
 414  */
 415 struct aac_sge {
 416         uint32_t bcount;        /* byte count */
 417         union {
 418                 uint32_t ad32;  /* 32 bit address */
 419                 struct {
 420                         uint32_t lo;
 421                         uint32_t hi;
 422                 } ad64;         /* 64 bit address */
 423         } addr;
 424 };
 425 
 426 /* aac_cmd flags */
 427 #define AAC_CMD_CONSISTENT              (1 << 0)
 428 #define AAC_CMD_DMA_PARTIAL             (1 << 1)
 429 #define AAC_CMD_DMA_VALID               (1 << 2)
 430 #define AAC_CMD_BUF_READ                (1 << 3)
 431 #define AAC_CMD_BUF_WRITE               (1 << 4)
 432 #define AAC_CMD_SYNC                    (1 << 5) /* use sync FIB */
 433 #define AAC_CMD_NO_INTR                 (1 << 6) /* poll IO, no intr */
 434 #define AAC_CMD_NO_CB                   (1 << 7) /* sync IO, no callback */
 435 #define AAC_CMD_NTAG                    (1 << 8)
 436 #define AAC_CMD_CMPLT                   (1 << 9) /* cmd exec'ed by driver/fw */
 437 #define AAC_CMD_ABORT                   (1 << 10)
 438 #define AAC_CMD_TIMEOUT                 (1 << 11)
 439 #define AAC_CMD_ERR                     (1 << 12)
 440 #define AAC_CMD_AIF                     (1 << 13)
 441 #define AAC_CMD_AIF_NOMORE              (1 << 14)
 442 #define AAC_CMD_FASTRESP                (1 << 15)
 443 
 444 #define AAC_MAXSEGMENTS         16
 445 
 446 struct aac_cmd {
 447         /*
 448          * Note: should be the first member for aac_cmd_queue to work
 449          * correctly.
 450          */
 451         struct aac_cmd *next;
 452         struct aac_cmd *prev;
 453 
 454         struct scsi_pkt *pkt;
 455         int cmdlen;
 456         int flags;
 457         uint32_t timeout; /* time when the cmd should have completed */
 458         struct buf *bp;
 459 
 460         uint_t segment_cnt;
 461         uint_t left_cookien;
 462         struct {
 463                 ddi_dma_handle_t buf_dma_handle;
 464                 /* For non-aligned buffer and SRB */
 465                 caddr_t abp;
 466                 ddi_acc_handle_t abh;
 467                 uint32_t abp_size;
 468                 size_t abp_real_size;
 469 
 470                 /* Data transfer state */
 471                 ddi_dma_cookie_t cookie;
 472                 uint_t left_cookien;
 473                 struct aac_sge *sgt;
 474         } segments[AAC_MAXSEGMENTS];
 475         uint_t cur_segment;
 476         uint_t cur_win;
 477         uint_t total_nwin;
 478         size_t total_xfer;
 479         uint64_t blkno;
 480         uint32_t bcount;        /* buffer size in byte */
 481         struct aac_sge *sgt;    /* sg table */
 482 
 483         /* FIB construct function */
 484         aac_cmd_fib_t aac_cmd_fib;
 485         /* Call back function for completed command */
 486         void (*ac_comp)(struct aac_softstate *, struct aac_cmd *);
 487 
 488         struct aac_slot *slotp; /* slot used by this command */
 489         struct aac_device *dvp; /* target device */
 490 
 491         /* FIB for this IO command */
 492         int fib_size; /* size of the FIB xferred to/from the card */
 493         struct aac_fib *fibp;
 494 };
 495 
 496 #ifdef AAC_DEBUG
 497 #define AACDB_FLAGS_MASK                0x0000ffff
 498 #define AACDB_FLAGS_KERNEL_PRINT        0x00000001
 499 #define AACDB_FLAGS_FW_PRINT            0x00000002
 500 #define AACDB_FLAGS_NO_HEADERS          0x00000004
 501 
 502 #define AACDB_FLAGS_MISC                0x00000010
 503 #define AACDB_FLAGS_FUNC1               0x00000020
 504 #define AACDB_FLAGS_FUNC2               0x00000040
 505 #define AACDB_FLAGS_SCMD                0x00000080
 506 #define AACDB_FLAGS_AIF                 0x00000100
 507 #define AACDB_FLAGS_FIB                 0x00000200
 508 #define AACDB_FLAGS_IOCTL               0x00000400
 509 
 510 extern uint32_t aac_debug_flags;
 511 extern int aac_dbflag_on(struct aac_softstate *, int);
 512 extern void aac_printf(struct aac_softstate *, uint_t, const char *, ...);
 513 
 514 #define AACDB_PRINT(s, lev, ...) { \
 515         if (aac_dbflag_on((s), AACDB_FLAGS_MISC)) \
 516                 aac_printf((s), (lev), __VA_ARGS__); }
 517 
 518 #define AACDB_PRINT_IOCTL(s, ...) { \
 519         if (aac_dbflag_on((s), AACDB_FLAGS_IOCTL)) \
 520                 aac_printf((s), CE_NOTE, __VA_ARGS__); }
 521 
 522 #define AACDB_PRINT_TRAN(s, ...) { \
 523         if (aac_dbflag_on((s), AACDB_FLAGS_SCMD)) \
 524                 aac_printf((s), CE_NOTE, __VA_ARGS__); }
 525 
 526 #define DBCALLED(s, n) { \
 527         if (aac_dbflag_on((s), AACDB_FLAGS_FUNC ## n)) \
 528                 aac_printf((s), CE_NOTE, "--- %s() called ---", __func__); }
 529 #else
 530 #define AACDB_PRINT(s, lev, ...)
 531 #define AACDB_PRINT_IOCTL(s, ...)
 532 #define AACDB_PRINT_TRAN(s, ...)
 533 #define DBCALLED(s, n)
 534 #endif /* AAC_DEBUG */
 535 
 536 #ifdef AAC_DEBUG_ALL
 537 extern void aac_print_fib(struct aac_softstate *, struct aac_fib *);
 538 
 539 #define AACDB_PRINT_SCMD(s, x) { \
 540         if (aac_dbflag_on((s), AACDB_FLAGS_SCMD)) aac_print_scmd((s), (x)); }
 541 
 542 #define AACDB_PRINT_AIF(s, x) { \
 543         if (aac_dbflag_on((s), AACDB_FLAGS_AIF)) aac_print_aif((s), (x)); }
 544 
 545 #define AACDB_PRINT_FIB(s, x) { \
 546         if (aac_dbflag_on((s), AACDB_FLAGS_FIB)) aac_print_fib((s), (x)); }
 547 #else
 548 #define AACDB_PRINT_FIB(s, x)
 549 #define AACDB_PRINT_SCMD(s, x)
 550 #define AACDB_PRINT_AIF(s, x)
 551 #endif /* AAC_DEBUG_ALL */
 552 
 553 #ifdef  __cplusplus
 554 }
 555 #endif
 556 
 557 #endif /* _AAC_H_ */