fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
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 *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or http://www.opensolaris.org/os/licensing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
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 *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifndef _SD_IOB_H
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define _SD_IOB_H
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef __cplusplus
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern "C" {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define MAX_HOOK_LOCKS 32
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef int (*dcb_t)(struct buf *); /* driver callback type */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * order of end action calls:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * driver callback (iob_drv_iodone) is stuffed in b_iodone and called by
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the device driver when i/o completes. It calls the hook end action
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * (iob_hook_iodone) which maintains the completion count (iob_hook.count)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and calls the clients end action (iob_hook.func) when the chain is complete.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct iob_hook {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct iob_hook *next_hook;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct buf *chain; /* all the buffers for this iob */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct buf *tail; /* tail of buffer chain */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int count; /* number of bufs on the chain */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t start_fba; /* initial disk block for the xfer */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t last_fba; /* last disk block for the xfer */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t size; /* # bytes for entire transfer */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned char *last_vaddr; /* ending addr of last i/o request */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_ea_fn_t func; /* clients end action routine */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int (* iob_hook_iodone)(struct buf *, struct iob_hook *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dcb_t iob_drv_iodone; /* driver call back */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte blind_t param; /* param for clnt end action routine */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int flags; /* flags for each buffer */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int error; /* any error */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int skipped; /* this iob used sd_add_mem */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmutex_t *lockp; /* mutex for releasing buffers */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kcondvar_t wait; /* sync for sleeping on synch i/o */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef _SD_BIO_STATS
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int PAGE_IO, NORM_IO, SKIP_IO;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int PAGE_COMBINED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t NORM_IO_SIZE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _SD_BIO_STATS */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } iob_hook_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct _sd_buf_list {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iob_hook_t *hooks; /* all of the iob hooks */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iob_hook_t *hook_head; /* free iob hook */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int bl_init_count; /* total count */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int bl_hooks_avail; /* monitor available hook count */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int bl_hook_lowmark; /* record if ever run out of hooks */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int hook_waiters; /* count of waiters */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int max_hook_waiters; /* record max ever waiters */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kcondvar_t hook_wait; /* sync for sleeping on synch i/o */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmutex_t hook_locks[MAX_HOOK_LOCKS];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} _sd_buf_list_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NOTE: if you change this, then also make changes to the generation
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * of sd_iob_impl*.c in src/uts/common/Makefile.files and Makefile.rules!
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define _SD_DEFAULT_IOBUFS 4096
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* define driver callback and driver callback function table */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define IOB_DCBP(i) (sd_iob_dcb ## i)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define IOB_DCB(i) \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte IOB_DCBP(i)(struct buf *bp) \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return ((*_sd_buflist.hooks[i].iob_hook_iodone) \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (bp, &_sd_buflist.hooks[i])); \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern _sd_buf_list_t _sd_buflist;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef __cplusplus
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _SD_IOB_H */