Clean up the namespace of <sys/timeb.h>.
[dragonfly.git] / sys / dev / raid / aac / aacvar.h
CommitLineData
984263bc
MD
1/*-
2 * Copyright (c) 2000 Michael Smith
3 * Copyright (c) 2001 Scott Long
4 * Copyright (c) 2000 BSDi
5 * Copyright (c) 2001 Adaptec, Inc.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
b4df2201 29 * $FreeBSD: head/sys/dev/aac/aacvar.h 258780 2013-11-30 22:17:27Z eadler $
984263bc
MD
30 */
31
e9ae7f4f
SW
32#include <sys/bio.h>
33#include <sys/callout.h>
d9773475 34#include <sys/lock.h>
d9773475 35#include <sys/taskqueue.h>
e9ae7f4f
SW
36#include <sys/buf2.h>
37#include <sys/devicestat.h>
38#include <sys/disk.h>
39#include <sys/eventhandler.h>
7f8935d3 40#include <sys/sysctl.h>
e9ae7f4f 41
b4df2201
SW
42SYSCTL_DECL(_hw_aac);
43
e9ae7f4f
SW
44#define AAC_TYPE_DEVO 1
45#define AAC_TYPE_ALPHA 2
46#define AAC_TYPE_BETA 3
47#define AAC_TYPE_RELEASE 4
48
49#define AAC_DRIVER_MAJOR_VERSION 2
50#define AAC_DRIVER_MINOR_VERSION 1
51#define AAC_DRIVER_BUGFIX_LEVEL 9
52#define AAC_DRIVER_TYPE AAC_TYPE_RELEASE
53
54#ifndef AAC_DRIVER_BUILD
55# define AAC_DRIVER_BUILD 1
56#endif
7f2216bc 57
984263bc
MD
58/*
59 * Driver Parameter Definitions
60 */
61
62/*
e9ae7f4f 63 * The firmware interface allows for a 16-bit s/g list length. We limit
984263bc
MD
64 * ourselves to a reasonable maximum and ensure alignment.
65 */
b4df2201 66#define AAC_MAXSGENTRIES 64 /* max S/G entries, limit 65535 */
984263bc
MD
67
68/*
69 * We allocate a small set of FIBs for the adapter to use to send us messages.
70 */
71#define AAC_ADAPTER_FIBS 8
72
984263bc
MD
73/*
74 * The controller reports status events in AIFs. We hang on to a number of
75 * these in order to pass them out to user-space management tools.
76 */
77#define AAC_AIFQ_LENGTH 64
78
79/*
e3869ec7 80 * Firmware messages are passed in the kprintf buffer.
984263bc
MD
81 */
82#define AAC_PRINTF_BUFSIZE 256
83
84/*
e9ae7f4f 85 * We wait this many seconds for the adapter to come ready if it is still
984263bc
MD
86 * booting
87 */
88#define AAC_BOOT_TIMEOUT (3 * 60)
89
90/*
91 * Timeout for immediate commands.
92 */
93#define AAC_IMMEDIATE_TIMEOUT 30 /* seconds */
94
95/*
96 * Timeout for normal commands
97 */
e9ae7f4f 98#define AAC_CMD_TIMEOUT 120 /* seconds */
984263bc
MD
99
100/*
101 * Rate at which we periodically check for timed out commands and kick the
102 * controller.
103 */
104#define AAC_PERIODIC_INTERVAL 20 /* seconds */
105
984263bc
MD
106/*
107 * Per-container data structure
108 */
109struct aac_container
110{
111 struct aac_mntobj co_mntobj;
112 device_t co_disk;
113 int co_found;
114 TAILQ_ENTRY(aac_container) co_link;
115};
116
d9773475
PA
117/*
118 * Per-SIM data structure
119 */
e9ae7f4f 120struct aac_cam;
d9773475
PA
121struct aac_sim
122{
123 device_t sim_dev;
124 int TargetsPerBus;
125 int BusNumber;
126 int InitiatorBusId;
127 struct aac_softc *aac_sc;
e9ae7f4f 128 struct aac_cam *aac_cam;
d9773475
PA
129 TAILQ_ENTRY(aac_sim) sim_link;
130};
131
984263bc
MD
132/*
133 * Per-disk structure
134 */
e9ae7f4f 135struct aac_disk
984263bc
MD
136{
137 device_t ad_dev;
b13267a5 138 cdev_t ad_dev_t;
984263bc
MD
139 struct aac_softc *ad_controller;
140 struct aac_container *ad_container;
141 struct disk ad_disk;
142 struct devstat ad_stats;
984263bc
MD
143 int ad_flags;
144#define AAC_DISK_OPEN (1<<0)
145 int ad_cylinders;
146 int ad_heads;
147 int ad_sectors;
e9ae7f4f 148 u_int64_t ad_size;
984263bc
MD
149 int unit;
150};
151
152/*
153 * Per-command control structure.
154 */
155struct aac_command
156{
157 TAILQ_ENTRY(aac_command) cm_link; /* list linkage */
158
159 struct aac_softc *cm_sc; /* controller that owns us */
160
161 struct aac_fib *cm_fib; /* FIB associated with this
162 * command */
d9773475 163 u_int64_t cm_fibphys; /* bus address of the FIB */
b4df2201 164 void *cm_data; /* pointer to data in kernel
984263bc
MD
165 * space */
166 u_int32_t cm_datalen; /* data length */
167 bus_dmamap_t cm_datamap; /* DMA map for bio data */
168 struct aac_sg_table *cm_sgtable; /* pointer to s/g table in
169 * command */
b4df2201 170 u_int cm_flags;
984263bc
MD
171#define AAC_CMD_MAPPED (1<<0) /* command has had its data
172 * mapped */
173#define AAC_CMD_DATAIN (1<<1) /* command involves data moving
174 * from controller to host */
175#define AAC_CMD_DATAOUT (1<<2) /* command involves data moving
176 * from host to controller */
177#define AAC_CMD_COMPLETED (1<<3) /* command has been completed */
178#define AAC_CMD_TIMEDOUT (1<<4) /* command taken too long */
179#define AAC_ON_AACQ_FREE (1<<5)
180#define AAC_ON_AACQ_READY (1<<6)
181#define AAC_ON_AACQ_BUSY (1<<7)
e9ae7f4f 182#define AAC_ON_AACQ_AIF (1<<8)
d9773475 183#define AAC_ON_AACQ_NORM (1<<10)
e9ae7f4f 184#define AAC_ON_AACQ_MASK ((1<<5)|(1<<6)|(1<<7)|(1<<8)|(1<<10))
d9773475
PA
185#define AAC_QUEUE_FRZN (1<<9) /* Freeze the processing of
186 * commands on the queue. */
984263bc 187
b4df2201 188 void (*cm_complete)(struct aac_command *cm);
984263bc
MD
189 void *cm_private;
190 time_t cm_timestamp; /* command creation time */
191 int cm_queue;
d9773475
PA
192 int cm_index;
193};
194
195struct aac_fibmap {
196 TAILQ_ENTRY(aac_fibmap) fm_link; /* list linkage */
197 struct aac_fib *aac_fibs;
198 bus_dmamap_t aac_fibmap;
199 struct aac_command *aac_commands;
984263bc
MD
200};
201
202/*
203 * We gather a number of adapter-visible items into a single structure.
204 *
205 * The ordering of this strucure may be important; we copy the Linux driver:
206 *
207 * Adapter FIBs
208 * Init struct
209 * Queue headers (Comm Area)
210 * Printf buffer
211 *
212 * In addition, we add:
213 * Sync Fib
214 */
215struct aac_common {
216 /* fibs for the controller to send us messages */
217 struct aac_fib ac_fibs[AAC_ADAPTER_FIBS];
218
219 /* the init structure */
220 struct aac_adapter_init ac_init;
221
222 /* arena within which the queue structures are kept */
223 u_int8_t ac_qbuf[sizeof(struct aac_queue_table) +
224 AAC_QUEUE_ALIGN];
225
226 /* buffer for text messages from the controller */
e9ae7f4f 227 char ac_printf[AAC_PRINTF_BUFSIZE];
b4df2201 228
984263bc
MD
229 /* fib for synchronous commands */
230 struct aac_fib ac_sync_fib;
231};
232
233/*
234 * Interface operations
235 */
e9ae7f4f 236struct aac_interface
984263bc
MD
237{
238 int (*aif_get_fwstatus)(struct aac_softc *sc);
239 void (*aif_qnotify)(struct aac_softc *sc, int qbit);
240 int (*aif_get_istatus)(struct aac_softc *sc);
241 void (*aif_clr_istatus)(struct aac_softc *sc, int mask);
242 void (*aif_set_mailbox)(struct aac_softc *sc, u_int32_t command,
243 u_int32_t arg0, u_int32_t arg1,
244 u_int32_t arg2, u_int32_t arg3);
245 int (*aif_get_mailbox)(struct aac_softc *sc, int mb);
246 void (*aif_set_interrupts)(struct aac_softc *sc, int enable);
e9ae7f4f
SW
247 int (*aif_send_command)(struct aac_softc *sc, struct aac_command *cm);
248 int (*aif_get_outb_queue)(struct aac_softc *sc);
249 void (*aif_set_outb_queue)(struct aac_softc *sc, int index);
984263bc 250};
b4df2201
SW
251extern const struct aac_interface aac_rx_interface;
252extern const struct aac_interface aac_sa_interface;
253extern const struct aac_interface aac_rkt_interface;
254
255#define AAC_GET_FWSTATUS(sc) ((sc)->aac_if->aif_get_fwstatus((sc)))
256#define AAC_QNOTIFY(sc, qbit) ((sc)->aac_if->aif_qnotify((sc), (qbit)))
257#define AAC_GET_ISTATUS(sc) ((sc)->aac_if->aif_get_istatus((sc)))
258#define AAC_CLEAR_ISTATUS(sc, mask) ((sc)->aac_if->aif_clr_istatus((sc), \
984263bc
MD
259 (mask)))
260#define AAC_SET_MAILBOX(sc, command, arg0, arg1, arg2, arg3) \
b4df2201 261 ((sc)->aac_if->aif_set_mailbox((sc), (command), (arg0), (arg1), (arg2), \
984263bc 262 (arg3)))
b4df2201 263#define AAC_GET_MAILBOX(sc, mb) ((sc)->aac_if->aif_get_mailbox((sc), \
984263bc 264 (mb)))
b4df2201 265#define AAC_MASK_INTERRUPTS(sc) ((sc)->aac_if->aif_set_interrupts((sc), \
984263bc 266 0))
b4df2201 267#define AAC_UNMASK_INTERRUPTS(sc) ((sc)->aac_if->aif_set_interrupts((sc), \
984263bc 268 1))
b4df2201
SW
269#define AAC_SEND_COMMAND(sc, cm) ((sc)->aac_if->aif_send_command((sc), (cm)))
270#define AAC_GET_OUTB_QUEUE(sc) ((sc)->aac_if->aif_get_outb_queue((sc)))
271#define AAC_SET_OUTB_QUEUE(sc, idx) ((sc)->aac_if->aif_set_outb_queue((sc), (idx)))
984263bc 272
e9ae7f4f
SW
273#define AAC_MEM0_SETREG4(sc, reg, val) bus_space_write_4(sc->aac_btag0, \
274 sc->aac_bhandle0, reg, val)
275#define AAC_MEM0_GETREG4(sc, reg) bus_space_read_4(sc->aac_btag0, \
276 sc->aac_bhandle0, reg)
277#define AAC_MEM0_SETREG2(sc, reg, val) bus_space_write_2(sc->aac_btag0, \
278 sc->aac_bhandle0, reg, val)
279#define AAC_MEM0_GETREG2(sc, reg) bus_space_read_2(sc->aac_btag0, \
280 sc->aac_bhandle0, reg)
281#define AAC_MEM0_SETREG1(sc, reg, val) bus_space_write_1(sc->aac_btag0, \
282 sc->aac_bhandle0, reg, val)
283#define AAC_MEM0_GETREG1(sc, reg) bus_space_read_1(sc->aac_btag0, \
284 sc->aac_bhandle0, reg)
285
286#define AAC_MEM1_SETREG4(sc, reg, val) bus_space_write_4(sc->aac_btag1, \
287 sc->aac_bhandle1, reg, val)
288#define AAC_MEM1_GETREG4(sc, reg) bus_space_read_4(sc->aac_btag1, \
289 sc->aac_bhandle1, reg)
290#define AAC_MEM1_SETREG2(sc, reg, val) bus_space_write_2(sc->aac_btag1, \
291 sc->aac_bhandle1, reg, val)
292#define AAC_MEM1_GETREG2(sc, reg) bus_space_read_2(sc->aac_btag1, \
293 sc->aac_bhandle1, reg)
294#define AAC_MEM1_SETREG1(sc, reg, val) bus_space_write_1(sc->aac_btag1, \
295 sc->aac_bhandle1, reg, val)
296#define AAC_MEM1_GETREG1(sc, reg) bus_space_read_1(sc->aac_btag1, \
297 sc->aac_bhandle1, reg)
298
299/* fib context (IOCTL) */
300struct aac_fib_context {
301 u_int32_t unique;
302 int ctx_idx;
303 int ctx_wrap;
304 struct aac_fib_context *next, *prev;
305};
984263bc
MD
306
307/*
308 * Per-controller structure.
309 */
e9ae7f4f 310struct aac_softc
984263bc
MD
311{
312 /* bus connections */
313 device_t aac_dev;
e9ae7f4f 314 struct resource *aac_regs_res0, *aac_regs_res1; /* reg. if. window */
e9ae7f4f
SW
315 bus_space_handle_t aac_bhandle0, aac_bhandle1; /* bus space handle */
316 bus_space_tag_t aac_btag0, aac_btag1; /* bus space tag */
984263bc
MD
317 bus_dma_tag_t aac_parent_dmat; /* parent DMA tag */
318 bus_dma_tag_t aac_buffer_dmat; /* data buffer/command
319 * DMA tag */
b4df2201 320
984263bc 321 struct resource *aac_irq; /* interrupt */
984263bc 322 void *aac_intr; /* interrupt handle */
b4df2201
SW
323 int aac_irq_rid;
324 int aac_irq_type;
d9773475 325 eventhandler_tag eh;
984263bc
MD
326
327 /* controller features, limits and status */
328 int aac_state;
329#define AAC_STATE_SUSPEND (1<<0)
e9ae7f4f 330#define AAC_STATE_UNUSED0 (1<<1)
984263bc
MD
331#define AAC_STATE_INTERRUPTS_ON (1<<2)
332#define AAC_STATE_AIF_SLEEPER (1<<3)
333 struct FsaRevision aac_revision;
334
335 /* controller hardware interface */
336 int aac_hwif;
337#define AAC_HWIF_I960RX 0
338#define AAC_HWIF_STRONGARM 1
d9773475 339#define AAC_HWIF_RKT 3
e9ae7f4f 340#define AAC_HWIF_NARK 4
984263bc
MD
341#define AAC_HWIF_UNKNOWN -1
342 bus_dma_tag_t aac_common_dmat; /* common structure
343 * DMA tag */
344 bus_dmamap_t aac_common_dmamap; /* common structure
345 * DMA map */
346 struct aac_common *aac_common;
347 u_int32_t aac_common_busaddr;
b4df2201 348 const struct aac_interface *aac_if;
984263bc
MD
349
350 /* command/fib resources */
351 bus_dma_tag_t aac_fib_dmat; /* DMA tag for allocing FIBs */
d9773475
PA
352 TAILQ_HEAD(,aac_fibmap) aac_fibmap_tqh;
353 u_int total_fibs;
354 struct aac_command *aac_commands;
984263bc
MD
355
356 /* command management */
e9ae7f4f 357 TAILQ_HEAD(,aac_command) aac_free; /* command structures
984263bc
MD
358 * available for reuse */
359 TAILQ_HEAD(,aac_command) aac_ready; /* commands on hold for
360 * controller resources */
361 TAILQ_HEAD(,aac_command) aac_busy;
e9ae7f4f 362 TAILQ_HEAD(,aac_event) aac_ev_cmfree;
81b5c339 363 struct bio_queue_head aac_bioq;
984263bc
MD
364 struct aac_queue_table *aac_queues;
365 struct aac_queue_entry *aac_qentries[AAC_QUEUE_COUNT];
366
367 struct aac_qstat aac_qstat[AACQ_COUNT]; /* queue statistics */
368
369 /* connected containters */
d9773475 370 TAILQ_HEAD(,aac_container) aac_container_tqh;
e9ae7f4f 371 struct lock aac_container_lock;
984263bc 372
d9773475
PA
373 /*
374 * The general I/O lock. This protects the sync fib, the lists, the
375 * queues, and the registers.
376 */
e9ae7f4f 377 struct lock aac_io_lock;
984263bc
MD
378
379 /* delayed activity infrastructure */
984263bc
MD
380 struct task aac_task_complete; /* deferred-completion
381 * task */
984263bc
MD
382 struct intr_config_hook aac_ich;
383
384 /* management interface */
e9ae7f4f
SW
385 struct cdev *aac_dev_t;
386 struct lock aac_aifq_lock;
387 struct aac_fib aac_aifq[AAC_AIFQ_LENGTH];
388 int aifq_idx;
389 int aifq_filled;
390 struct aac_fib_context *fibctx;
5b22f1a7 391 struct kqinfo rcv_kq;
41c20dac 392 struct thread *aifthread;
984263bc
MD
393 int aifflags;
394#define AAC_AIFFLAGS_RUNNING (1 << 0)
7f8935d3 395#define AAC_AIFFLAGS_UNUSED0 (1 << 1)
984263bc
MD
396#define AAC_AIFFLAGS_EXIT (1 << 2)
397#define AAC_AIFFLAGS_EXITED (1 << 3)
7f8935d3 398#define AAC_AIFFLAGS_UNUSED1 (1 << 4)
d9773475 399#define AAC_AIFFLAGS_ALLOCFIBS (1 << 5)
7f8935d3 400#define AAC_AIFFLAGS_PENDING AAC_AIFFLAGS_ALLOCFIBS
984263bc
MD
401 u_int32_t flags;
402#define AAC_FLAGS_PERC2QC (1 << 0)
403#define AAC_FLAGS_ENABLE_CAM (1 << 1) /* No SCSI passthrough */
404#define AAC_FLAGS_CAM_NORESET (1 << 2) /* Fake SCSI resets */
405#define AAC_FLAGS_CAM_PASSONLY (1 << 3) /* Only create pass devices */
d9773475 406#define AAC_FLAGS_SG_64BIT (1 << 4) /* Use 64-bit S/G addresses */
984263bc 407#define AAC_FLAGS_4GB_WINDOW (1 << 5) /* Device can access host mem
e9ae7f4f 408 * 2GB-4GB range */
984263bc
MD
409#define AAC_FLAGS_NO4GB (1 << 6) /* Can't access host mem >2GB */
410#define AAC_FLAGS_256FIBS (1 << 7) /* Can only do 256 commands */
e9ae7f4f 411#define AAC_FLAGS_BROKEN_MEMMAP (1 << 8) /* Broken HostPhysMemPages */
b4df2201 412#define AAC_FLAGS_SLAVE (1 << 9)
d9773475
PA
413#define AAC_FLAGS_MASTER (1 << 10)
414#define AAC_FLAGS_NEW_COMM (1 << 11) /* New comm. interface supported */
415#define AAC_FLAGS_RAW_IO (1 << 12) /* Raw I/O interface */
416#define AAC_FLAGS_ARRAY_64BIT (1 << 13) /* 64-bit array size */
e9ae7f4f 417#define AAC_FLAGS_LBA_64BIT (1 << 14) /* 64-bit LBA support */
b4df2201 418#define AAC_FLAGS_NOMSI (1U << 31) /* Broken MSI */
e9ae7f4f 419
984263bc
MD
420 u_int32_t supported_options;
421 u_int32_t scsi_method_id;
d9773475
PA
422 TAILQ_HEAD(,aac_sim) aac_sim_tqh;
423
e9ae7f4f
SW
424 struct callout aac_daemontime; /* clock daemon callout */
425
d9773475 426 u_int32_t aac_max_fibs; /* max. FIB count */
e9ae7f4f
SW
427 u_int32_t aac_max_fibs_alloc; /* max. alloc. per alloc_commands() */
428 u_int32_t aac_max_fib_size; /* max. FIB size */
429 u_int32_t aac_sg_tablesize; /* max. sg count from host */
430 u_int32_t aac_max_sectors; /* max. I/O size from host (blocks) */
431#define AAC_CAM_TARGET_WILDCARD ~0
432 void (*cam_rescan_cb)(struct aac_softc *, uint32_t,
433 uint32_t);
d9773475
PA
434};
435
436/*
437 * Event callback mechanism for the driver
438 */
439#define AAC_EVENT_NONE 0x00
440#define AAC_EVENT_CMFREE 0x01
e9ae7f4f 441#define AAC_EVENT_MASK 0xff
d9773475
PA
442#define AAC_EVENT_REPEAT 0x100
443
444typedef void aac_event_cb_t(struct aac_softc *sc, struct aac_event *event,
445 void *arg);
446struct aac_event {
447 TAILQ_ENTRY(aac_event) ev_links;
448 int ev_type;
449 aac_event_cb_t *ev_callback;
450 void *ev_arg;
984263bc
MD
451};
452
984263bc
MD
453/*
454 * Public functions
455 */
456extern void aac_free(struct aac_softc *sc);
457extern int aac_attach(struct aac_softc *sc);
458extern int aac_detach(device_t dev);
e9ae7f4f
SW
459extern int aac_shutdown(device_t dev);
460extern int aac_suspend(device_t dev);
984263bc 461extern int aac_resume(device_t dev);
d9773475 462extern void aac_new_intr(void *arg);
e9ae7f4f 463extern void aac_filter(void *arg);
81b5c339
MD
464extern void aac_submit_bio(struct aac_disk *ad, struct bio *bio);
465extern void aac_biodone(struct bio *bio, const char *code);
984263bc
MD
466extern void aac_startio(struct aac_softc *sc);
467extern int aac_alloc_command(struct aac_softc *sc,
468 struct aac_command **cmp);
469extern void aac_release_command(struct aac_command *cm);
984263bc
MD
470extern int aac_sync_fib(struct aac_softc *sc, u_int32_t command,
471 u_int32_t xferstate, struct aac_fib *fib,
472 u_int16_t datasize);
d9773475
PA
473extern void aac_add_event(struct aac_softc *sc, struct aac_event
474 *event);
984263bc 475
984263bc 476#ifdef AAC_DEBUG
e9ae7f4f
SW
477extern int aac_debug_enable;
478# define fwprintf(sc, flags, fmt, args...) \
479do { \
480 if (!aac_debug_enable) \
481 break; \
482 if (sc != NULL) \
483 device_printf(((struct aac_softc *)sc)->aac_dev, \
484 "%s: " fmt "\n", __func__, ##args); \
485 else \
486 kprintf("%s: " fmt "\n", __func__, ##args); \
487} while(0)
488
489extern void aac_print_queues(struct aac_softc *sc);
490extern void aac_panic(struct aac_softc *sc, char *reason);
984263bc 491extern void aac_print_fib(struct aac_softc *sc, struct aac_fib *fib,
09ccaff3 492 const char *caller);
984263bc
MD
493extern void aac_print_aif(struct aac_softc *sc,
494 struct aac_aif_command *aif);
495
e9ae7f4f 496#define AAC_PRINT_FIB(sc, fib) aac_print_fib(sc, fib, __func__)
984263bc
MD
497
498#else
e9ae7f4f
SW
499# define fwprintf(sc, flags, fmt, args...)
500
501# define aac_print_queues(sc)
502# define aac_panic(sc, reason)
984263bc 503
984263bc
MD
504# define AAC_PRINT_FIB(sc, fib)
505# define aac_print_aif(sc, aac_aif_command)
506#endif
507
508struct aac_code_lookup {
b4df2201 509 const char *string;
984263bc
MD
510 u_int32_t code;
511};
512
513/*
514 * Queue primitives for driver queues.
515 */
516#define AACQ_ADD(sc, qname) \
517 do { \
518 struct aac_qstat *qs; \
519 \
520 qs = &(sc)->aac_qstat[qname]; \
521 \
522 qs->q_length++; \
523 if (qs->q_length > qs->q_max) \
524 qs->q_max = qs->q_length; \
525 } while (0)
526
527#define AACQ_REMOVE(sc, qname) (sc)->aac_qstat[qname].q_length--
528#define AACQ_INIT(sc, qname) \
529 do { \
530 sc->aac_qstat[qname].q_length = 0; \
531 sc->aac_qstat[qname].q_max = 0; \
532 } while (0)
533
984263bc
MD
534#define AACQ_COMMAND_QUEUE(name, index) \
535static __inline void \
536aac_initq_ ## name (struct aac_softc *sc) \
537{ \
538 TAILQ_INIT(&sc->aac_ ## name); \
539 AACQ_INIT(sc, index); \
540} \
541static __inline void \
542aac_enqueue_ ## name (struct aac_command *cm) \
543{ \
984263bc 544 if ((cm->cm_flags & AAC_ON_AACQ_MASK) != 0) { \
7f8935d3
SW
545 panic("aac: command %p is on another queue, flags = %#x", \
546 cm, cm->cm_flags); \
984263bc
MD
547 } \
548 TAILQ_INSERT_TAIL(&cm->cm_sc->aac_ ## name, cm, cm_link); \
549 cm->cm_flags |= AAC_ON_ ## index; \
550 AACQ_ADD(cm->cm_sc, index); \
984263bc
MD
551} \
552static __inline void \
553aac_requeue_ ## name (struct aac_command *cm) \
554{ \
984263bc 555 if ((cm->cm_flags & AAC_ON_AACQ_MASK) != 0) { \
7f8935d3
SW
556 panic("aac: command %p is on another queue, flags = %#x", \
557 cm, cm->cm_flags); \
984263bc
MD
558 } \
559 TAILQ_INSERT_HEAD(&cm->cm_sc->aac_ ## name, cm, cm_link); \
560 cm->cm_flags |= AAC_ON_ ## index; \
561 AACQ_ADD(cm->cm_sc, index); \
984263bc
MD
562} \
563static __inline struct aac_command * \
564aac_dequeue_ ## name (struct aac_softc *sc) \
565{ \
566 struct aac_command *cm; \
984263bc 567 \
984263bc
MD
568 if ((cm = TAILQ_FIRST(&sc->aac_ ## name)) != NULL) { \
569 if ((cm->cm_flags & AAC_ON_ ## index) == 0) { \
7f8935d3
SW
570 panic("aac: command %p not in queue, flags = %#x, bit = %#x", \
571 cm, cm->cm_flags, AAC_ON_ ## index); \
984263bc
MD
572 } \
573 TAILQ_REMOVE(&sc->aac_ ## name, cm, cm_link); \
574 cm->cm_flags &= ~AAC_ON_ ## index; \
575 AACQ_REMOVE(sc, index); \
576 } \
984263bc
MD
577 return(cm); \
578} \
579static __inline void \
580aac_remove_ ## name (struct aac_command *cm) \
581{ \
984263bc 582 if ((cm->cm_flags & AAC_ON_ ## index) == 0) { \
7f8935d3
SW
583 panic("aac: command %p not in queue, flags = %#x, bit = %#x", \
584 cm, cm->cm_flags, AAC_ON_ ## index); \
984263bc
MD
585 } \
586 TAILQ_REMOVE(&cm->cm_sc->aac_ ## name, cm, cm_link); \
587 cm->cm_flags &= ~AAC_ON_ ## index; \
588 AACQ_REMOVE(cm->cm_sc, index); \
45568ff2 589}
984263bc
MD
590
591AACQ_COMMAND_QUEUE(free, AACQ_FREE);
592AACQ_COMMAND_QUEUE(ready, AACQ_READY);
593AACQ_COMMAND_QUEUE(busy, AACQ_BUSY);
984263bc
MD
594
595/*
596 * outstanding bio queue
597 */
598static __inline void
599aac_initq_bio(struct aac_softc *sc)
600{
601 bioq_init(&sc->aac_bioq);
602 AACQ_INIT(sc, AACQ_BIO);
603}
604
605static __inline void
6e4ab345 606aac_enqueue_bio(struct aac_softc *sc, struct bio *bio)
984263bc 607{
6e4ab345 608 bioq_insert_tail(&sc->aac_bioq, bio);
984263bc 609 AACQ_ADD(sc, AACQ_BIO);
984263bc
MD
610}
611
81b5c339 612static __inline struct bio *
984263bc
MD
613aac_dequeue_bio(struct aac_softc *sc)
614{
6e4ab345 615 struct bio *bio;
984263bc 616
6e4ab345
SW
617 if ((bio = bioq_first(&sc->aac_bioq)) != NULL) {
618 bioq_remove(&sc->aac_bioq, bio);
984263bc
MD
619 AACQ_REMOVE(sc, AACQ_BIO);
620 }
6e4ab345 621 return(bio);
984263bc
MD
622}
623
624static __inline void
625aac_print_printf(struct aac_softc *sc)
626{
627 /*
e3869ec7 628 * XXX We have the ability to read the length of the kprintf string
984263bc
MD
629 * from out of the mailboxes.
630 */
631 device_printf(sc->aac_dev, "**Monitor** %.*s", AAC_PRINTF_BUFSIZE,
632 sc->aac_common->ac_printf);
d9773475 633 sc->aac_common->ac_printf[0] = 0;
984263bc
MD
634 AAC_QNOTIFY(sc, AAC_DB_PRINTF);
635}
d9773475
PA
636
637static __inline int
638aac_alloc_sync_fib(struct aac_softc *sc, struct aac_fib **fib)
639{
640
641 KKASSERT(lockstatus(&sc->aac_io_lock, curthread) != 0);
642 *fib = &sc->aac_common->ac_sync_fib;
643 return (0);
644}
d9773475
PA
645static __inline void
646aac_release_sync_fib(struct aac_softc *sc)
647{
648
649 KKASSERT(lockstatus(&sc->aac_io_lock, curthread) != 0);
650}
651