fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_DISKQ_HEADER_OFF 0 /* beginning of disk */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_DISKQ_DATA_OFF FBA_LEN(1024) /* beginning of queue */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t pos; /* position it will be in the rdc_aio_t */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t hpos; /* starting pos of orig nsc_buf_t */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t qpos; /* where this info is in the queue */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_IOHDR_DONE 0xDEADCAFE /* this q entry has been flushed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_IOHDR_WAITING 0xBEEFCAFE /* this q entry is waiting for ack */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int head_offset; /* offset of meta-info of head (fbas) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int auxqwrap; /* if the tail wraps again, before head wraps once */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t seq_last; /* last sequence before suspend */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t head_offset; /* offset of meta-info of head (fbas) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t tail_offset; /* addr of next write (fbas) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t auxqwrap; /* if the tail wraps again, before head wraps once */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t seq_last; /* last sequence before suspend */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* flags for the state field in the header */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define QTAILBUSY 0x10 /* tell flusher not to grab, incomplete */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_QNOBLOCK 0x10000 /* can also be passed out by status */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_QBADRESUME 0x20 /* don't resume bit ref */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_QFULL 0x40 /* the queue is in a full delay loop */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_QFILLSTOP 0x01 /* diskq->memq flusher kill switch */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_QFILLSLEEP 0x02 /* explicit diskq->memq flusher sleep */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_MAX_DISKQREAD 0x1000 /* max 2 mb q read */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct diskqueue { /* the incore info about the diskq */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t last_tail; /* pos of the last tail write */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte volatile int inflbls; /* number of inflight blocks */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte volatile int inflitems; /* number of inflight blocks */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmutex_t disk_qlock; /* protects all things in diskq */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* and all things in dqheader */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t coalesc_bounds; /* don't coalesce below this offset */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_aio_t *lastio; /* cached copy of the last write on q */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte io_hdr *iohdrs; /* flushed, not ack'd on queue */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* diskq macros (gets) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define QEMPTY(q) ((QTAIL(q) == QHEAD(q))&&(!(QNITEMS(q))))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* diskq macros (sets) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define INC_QHEAD(q, n) q->disk_hdr.h.head_offset += n
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define DEC_QHEAD(q, n) q->disk_hdr.h.head_offset -= n
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define INC_QTAIL(q, n) q->disk_hdr.h.tail_offset += n
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define DEC_QTAIL(q, n) q->disk_hdr.h.tail_offset -= n
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define INC_QNITEMS(q, n) q->disk_hdr.h.nitems += n
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define DEC_QNITEMS(q, n) q->disk_hdr.h.nitems -= n
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define INC_QBLOCKS(q, n) q->disk_hdr.h.blocks += n
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define DEC_QBLOCKS(q, n) q->disk_hdr.h.blocks -= n
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CLR_QSTATE(q, n) q->disk_hdr.h.state &= ~n
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SET_QHEAD(q, n) q->disk_hdr.h.head_offset = n
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SET_QTAIL(q, n) q->disk_hdr.h.tail_offset = n
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SET_QSIZE(q, n) q->disk_hdr.h.disk_size = n
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SET_QNITEMS(q, n) q->disk_hdr.h.nitems = n
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SET_QBLOCKS(q, n) q->disk_hdr.h.blocks = n
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SET_AUXQWRAP(q, n) q->disk_hdr.h.auxqwrap = n
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CLR_AUXQWRAP(q) q->disk_hdr.h.auxqwrap = 0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SET_QCOALBOUNDS(q, n) q->coalesc_bounds = n
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* these can be wrapped by different threads, avoid the race */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (((QBLOCKS(q)+QNITEMS(q)+RDC_DISKQ_DATA_OFF+n) >= \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* diskq defines/macros (non-specific) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_DOLOG 0x04 /* put the group into logging */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_NOFAIL 0x08 /* don't fail the queue, just init */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_GROUP_LOCKED 0x10 /* trust me, I have the group lock */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_WRITTEN 0x10 /* data has been commited to queue */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_LAST 0x20 /* end of dequeued buffer, discard */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* CSTYLED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_BETWEEN(a,b,c) (a<b?((c>=a)&&(c<=b)):((a!=b)&&((c<b)||(c>=a))))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* CSTYLED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define QHEADSHLDWRAP(q) (QWRAP(q) && (QHEAD(q) >= QWRAP(q)))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define QNXTIOSHLDWRAP(q) (QWRAP(q) && (QNXTIO(q) >= QWRAP(q)))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define QTAILSHLDWRAP(q, size) (QTAIL(q) + size > QSIZE(q))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define QCOALESCEOK(q, dec) ((q->lastio->iostatus & RDC_WRITTEN) && \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (((QTAIL(q) - dec) > QNXTIO(q)) && ((QTAIL(q) - dec) > \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (QNXTIOSHLDWRAP(q) && QTAIL(q) > RDC_DISKQ_DATA_OFF)))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define QDISPLAY(q) "qmagic: %x qvers: %d qstate: %x qhead: %" \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_SZFMT " qnxtio: %" NSC_SZFMT " qtail: %" NSC_SZFMT " qtaillast: %" \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_SZFMT " qsize: %" NSC_SZFMT " qnitems: %" RDC_DQFMT \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " qblocks: %" RDC_DQFMT " coalbounds %" NSC_SZFMT, QMAGIC(q), \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte QVERS(q), QSTATE(q), QHEAD(q), QNXTIO(q), QTAIL(q), LASTQTAIL(q), \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define QDISPLAYND(q) "m: %x v: %d s: %d h: %" NSC_SZFMT " n: %" \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_SZFMT " t: %" NSC_SZFMT " l: %" NSC_SZFMT " z: %" NSC_SZFMT \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " i: %" RDC_DQFMT " b: %" RDC_DQFMT " w: %" NSC_SZFMT \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte QNXTIO(q), QTAIL(q), LASTQTAIL(q), QSIZE(q), QNITEMS(q), \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* Disk queue flusher state */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* functions */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint rdc_add_diskq(rdc_config_t *uparms, spcs_s_info_t kstatus);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint rdc_rem_diskq(rdc_config_t *uparms, spcs_s_info_t kstatus);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint rdc_kill_diskq(rdc_config_t *uparms, spcs_s_info_t kstatus);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint rdc_init_diskq(rdc_config_t *uparms, spcs_s_info_t kstatus);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _KERNEL */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _RDC_DISKQ_H */