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/*
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifndef _SD_BCACHE_H
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define _SD_BCACHE_H
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef __cplusplus
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern "C" {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DS_DDICT
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/contract.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/nsctl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/sdbc_ioctl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/sd_hash.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/sd_cache.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/sd_conf.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/safestore.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Definitions for kstats
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_KSTAT_CLASS "storedge"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_KSTAT_MODULE "sdbc"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_KSTAT_DYNMEM "dynmem"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_KSTAT_CDNAME "cdname"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_KSTAT_CDSTATS "cd"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_KSTAT_GSTATS "global"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_KSTAT_STATS "sdbcstats"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_IOKSTAT_GSTATS "gsdbc"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_IOKSTAT_CDSTATS "sdbc"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* Global kstat field names */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_GKSTAT_COUNT "sdbc_count"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_GKSTAT_LOC_COUNT "sdbc_loc_count"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_GKSTAT_RDHITS "sdbc_rdhits"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_GKSTAT_RDMISS "sdbc_rdmiss"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_GKSTAT_WRHITS "sdbc_wrhits"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_GKSTAT_WRMISS "sdbc_wrmiss"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_GKSTAT_BLKSIZE "sdbc_blksize"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_GKSTAT_LRU_BLOCKS "sdbc_lru_blocks"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_GKSTAT_LRU_NOREQ "sdbc_lru_noreq"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_GKSTAT_LRU_REQ "sdbc_lru_req"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_GKSTAT_WLRU_INQ "sdbc_wlru_inq"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_GKSTAT_CACHESIZE "sdbc_cachesize"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_GKSTAT_NUMBLOCKS "sdbc_numblocks"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_GKSTAT_NUM_SHARED "sdbc_num_shared"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_GKSTAT_WRCANCELNS "sdbc_wrcancelns"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_GKSTAT_DESTAGED "sdbc_destaged"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_GKSTAT_NODEHINTS "sdbc_nodehints"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* per-cache descriptor kstats field names */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_CDKSTAT_VOL_NAME "sdbc_vol_name"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_CDKSTAT_FAILED "sdbc_failed"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_CDKSTAT_CD "sdbc_cd"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_CDKSTAT_CACHE_READ "sdbc_cache_read"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_CDKSTAT_CACHE_WRITE "sdbc_cache_write"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_CDKSTAT_DISK_READ "sdbc_disk_read"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_CDKSTAT_DISK_WRITE "sdbc_disk_write"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_CDKSTAT_FILESIZE "sdbc_filesize"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_CDKSTAT_NUMDIRTY "sdbc_numdirty"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_CDKSTAT_NUMIO "sdbc_numio"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_CDKSTAT_NUMFAIL "sdbc_numfail"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_CDKSTAT_DESTAGED "sdbc_destaged"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_CDKSTAT_WRCANCELNS "sdbc_wrcancelns"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_CDKSTAT_CDHINTS "sdbc_cdhints"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* dynmem kstats field names */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_DMKSTAT_MONITOR_DYNMEM "sdbc_monitor_dynmem"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_DMKSTAT_MAX_DYN_LIST "sdbc_max_dyn_list"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_DMKSTAT_CACHE_AGING_CT1 "sdbc_cache_aging_ct1"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_DMKSTAT_CACHE_AGING_CT2 "sdbc_cache_aging_ct2"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_DMKSTAT_CACHE_AGING_CT3 "sdbc_cache_aging_ct3"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_DMKSTAT_CACHE_AGING_SEC1 "sdbc_cache_aging_sec1"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_DMKSTAT_CACHE_AGING_SEC2 "sdbc_cache_aging_sec2"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_DMKSTAT_CACHE_AGING_SEC3 "sdbc_cache_aging_sec3"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_DMKSTAT_CACHE_AGING_PCNT1 "sdbc_cache_aging_pcnt1"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_DMKSTAT_CACHE_AGING_PCNT2 "sdbc_cache_aging_pcnt2"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_DMKSTAT_MAX_HOLDS_PCNT "sdbc_max_holds_pcnt"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_DMKSTAT_ALLOC_CNT "sdbc_alloc_cnt"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_DMKSTAT_DEALLOC_CNT "sdbc_dealloc_cnt"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_DMKSTAT_HISTORY "sdbc_history"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_DMKSTAT_NODATAS "sdbc_nodatas"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_DMKSTAT_CANDIDATES "sdbc_candidates"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_DMKSTAT_DEALLOCS "sdbc_deallocs"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_DMKSTAT_HOSTS "sdbc_hosts"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_DMKSTAT_PESTS "sdbc_pests"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_DMKSTAT_METAS "sdbc_metas"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_DMKSTAT_HOLDS "sdbc_holds"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_DMKSTAT_OTHERS "sdbc_others"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_DMKSTAT_NOTAVAIL "sdbc_notavail"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_DMKSTAT_PROCESS_DIRECTIVE "sdbc_process_directive"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_DMKSTAT_SIMPLECT "sdbc_simplect"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ... values are in range [0-BLK_FBAS] */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef uint32_t sdbc_cblk_fba_t; /* FBA len or offset in cache block */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef unsigned char *ucaddr_t; /* unsigned char pointer */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Atomic exchange function
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef _KERNEL
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Note: ldstub sets all bits in the memory byte.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * so far this is compatible with the usage of xmem_bu() whereby
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the values of ptr are either 0 or 1, and the xmem_bu() is used
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to set the byte to 1.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define xmem_bu(val, ptr) nsc_ldstub((uint8_t *)ptr)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define atomic_swap xmem_bu
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define sd_serialize nsc_membar_stld
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _KERNEL */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(_KERNEL) || defined(_KMEMUSER)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(_SD_8K_BLKSIZE)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef unsigned short _sd_bitmap_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef unsigned char _sd_bitmap_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CCTL flag types
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Note: CC_INUSE and CC_PAGEIO are dummy flags that are used in
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * individual flags bytes (cc_inuse and cc_pageio) NOT cc_flag.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Thus they can take any convenient value, however, they must be
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * distinct and non-zero.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CC_INUSE 0x01 /* Cache entry is in use */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CC_PAGEIO 0x02 /* Pagelist IO is active for cache entry */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Real cc_flag values.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CC_PEND_DIRTY 0x02 /* The entry needs to be reprocessed for io */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CC_PINNED 0x04 /* The entry has data that is "pinned" */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CC_PINNABLE 0x08 /* Issue pin if write fails */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CC_QHEAD 0x10 /* NSC_NOCACHE: requeue at head */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* specify the size of _sd_cctl[] array */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define _SD_CCTL_GROUPS 32
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Individual SDBC cache block entry
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * "cc_lock" must be held when changing dirty/valid bits.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * "cc_inuse" (optimistic) atomic exchange replaces check/set of
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CC_INUSE bit in cc_flag; special handling of rare collisions.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * "cc_pageio" flusher / client locking of pagelist io operations,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * atomic exchange - needs machine ld/st protection.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * "cc_iostatus" is set by flusher without holding cc_lock,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * writer will set CC_PEND_DIRTY if cc_iostatus is set.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Thus "cc_inuse", "cc_iostatus" and "cc_pageio" are volatile.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The cc_await_* values are in the main _sd_cctl to avoid over
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * signalling _cc_blkcv.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The _sd_cctl structure is aligned to group related members and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to ensure good packing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct _sd_cctl_sync {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kcondvar_t _cc_blkcv; /* Synchronisation var to block on */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmutex_t _cc_lock; /* Cache entry spinlock */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} _sd_cctl_sync_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct sd_addr_s { /* Generic address structure */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned char *sa_virt; /* Virtual address of data */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} sd_addr_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See notes above.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct _sd_cctl {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_hash_hd_t cc_head; /* hash information - must be first */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct _sd_cctl *cc_next, *cc_prev; /* next and prev in a chain */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct _sd_cctl *cc_chain; /* chaining request centries */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct _sd_cctl *cc_dirty_next; /* for chaining sequential writes */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct _sd_cctl *cc_dirty_link; /* for chaining the dirty lists */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct _sd_cctl *cc_dirty_net_next; /* for chaining net writes */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct _sd_cctl *cc_dirty_net_link; /* for chaining net lists */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t cc_seq; /* sequence number: for lru optim */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte volatile int net_iostatus; /* net status of io */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte volatile _sd_bitmap_t net_dirty; /* net cache block dirty mask */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_bitmap_t cc_valid; /* Cache block valid mask */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_bitmap_t cc_toflush; /* Cache block deferred dirty mask */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte volatile _sd_bitmap_t cc_dirty; /* Cache block dirty mask */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte volatile ushort_t cc_await_use; /* # waiting for this entry (inuse) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte volatile ushort_t cc_await_page; /* # waiting for this entry (pageio) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte volatile uchar_t cc_inuse; /* atomic_swap(CC_INUSE, cc_inuse) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte volatile uchar_t cc_pageio; /* atomic_swap(CC_PAGEIO, cc_pageio) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uchar_t cc_flag; /* flag */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char cc_iocount; /* number of ios in progress */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte volatile uchar_t cc_iostatus; /* status of io */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uchar_t cc_prot; /* Segmented LRU protection flag */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sd_addr_t cc_addr; /* Data address information */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ss_centry_info_t *cc_write; /* mirrored writes control block */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct _sd_cctl_sync *cc_sync; /* Cache block synchronisation blk */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* support for backend i/o memory coalescing */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sd_addr_t cc_anon_addr; /* address for backend mem coalescing */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cc_anon_len; /* length of anon mem */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte clock_t cc_creat;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cc_hits;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* dynamic memory support fields */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t cc_aging_dm; /* For bit settings */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* see defines */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cc_alloc_size_dm; /* mem allocation */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* size bytes */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct _sd_cctl *cc_head_dm; /* ptr to host centry */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* for a host/pest */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* chain */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct _sd_cctl *cc_next_dm; /* ptr to next centry */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* in host/pest chain */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct _sd_cctl *cc_link_list_dm; /* simple link list */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* ptr of all centrys */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* dynmem chains */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* _sd_queue_t *cc_dmchain_q; dmqueue */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cc_cblocks; /* number of centrys for size_dm */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* debugging stats */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cc_alloc_ct_dm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cc_dealloc_ct_dm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} _sd_cctl_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* cache entry allocation tokens */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct sdbc_allocbuf_s {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte intptr_t opaque[2]; /* must be initialized to 0 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} sdbc_allocbuf_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct sdbc_allocbuf_impl_s {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *sab_dmchain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int sab_q; /* dmqueue of last chain allocated */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int reserved; /* stats ? */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} sdbc_allocbuf_impl_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * bits for flag argument to sdbc_centry_alloc() and callees.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define ALLOC_LOCKED 0x1 /* locked status of sdbc_queue_lock */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define ALLOC_NOWAIT 0x2 /* do not block, return NULL */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * definitions supporting the dynmem dealloc thread
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define LOW_RESOURCES_DM -1
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define NO_THREAD_DM -1
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define PROCESS_CACHE_DM 0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CACHE_SHUTDOWN_DM 1
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CACHE_THREAD_TERMINATED_DM 2
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define TIME_DELAY_LVL0 3
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define TIME_DELAY_LVL1 4
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define TIME_DELAY_LVL2 5
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define HISTORY_LVL0 (ushort_t)0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define HISTORY_LVL1 (ushort_t)0x00ff
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define HISTORY_LVL2 (ushort_t)0xff00
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * definitions supporing the ddditional fields in the cache
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * entry structure for dyn mem
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define FIRST_AGING_DM 0x00000001
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define FINAL_AGING_DM 0x000000ff
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define FOUND_IN_HASH_DM 0x00000100 /* used to bring cent info */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* out of sd_centry_alloc() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define FOUND_HOLD_OVER_DM 0x00000200 /* used to bring cent info */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* out of sd_centry_alloc() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define HOST_ENTRY_DM 0x00000400
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define PARASITIC_ENTRY_DM 0x00000800
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define STICKY_METADATA_DM 0x00001000
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CATAGORY_ENTRY_DM (HOST_ENTRY_DM|PARASITIC_ENTRY_DM| \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STICKY_METADATA_DM)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define ELIGIBLE_ENTRY_DM 0x00002000
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define HASH_ENTRY_DM 0x00008000
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define HOLD_ENTRY_DM 0x00010000
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define ENTRY_FIELD_DM (ELIGIBLE_ENTRY_DM|HASH_ENTRY_DM|HOLD_ENTRY_DM)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define AVAIL_ENTRY_DM 0x00020000
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* info only */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define PREFETCH_BUF_I 0x00040000 /* implicit read-ahead */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define PREFETCH_BUF_E 0x00080000 /* explicit read-ahead */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define PREFETCH_BUF_IR 0x00100000 /* release when read complete */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* error processing */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define BAD_ENTRY_DM 0x20000000 /* inconsistent ccent */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define BAD_CHAIN_DM 0x40000000 /* chain containing bad ccent */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * definitions supporting the dynmem monitoring
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RPT_SHUTDOWN_PROCESS_DM 0x00000001
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RPT_DEALLOC_STATS1_DM 0x00000002 /* nodat,cand,host,pest,meta, */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* other,dealloc */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RPT_DEALLOC_STATS2_DM 0x00000004 /* hysterisis,grossct */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * definitions supporting the processing directive bit flags
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define WAKE_DEALLOC_THREAD_DM 0x00000001 /* one shot - acted */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* on then cleared */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define MAX_OUT_ACCEL_HIST_FLAG_DM 0x00000002 /* one shot - acted */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* on then cleared */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Default - Max - Min definitions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define MAX_DYN_LIST_DEFAULT 8
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define MONITOR_DYNMEM_PROCESS_DEFAULT 0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CACHE_AGING_CT_DEFAULT 3
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CACHE_AGING_SEC1_DEFAULT 10
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CACHE_AGING_SEC2_DEFAULT 5
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CACHE_AGING_SEC3_DEFAULT 1
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CACHE_AGING_PCNT1_DEFAULT 50
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CACHE_AGING_PCNT2_DEFAULT 25
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define MAX_HOLDS_PCNT_DEFAULT 0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define PROCESS_DIRECTIVE_DEFAULT 0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CACHE_AGING_CT_MAX FINAL_AGING_DM /* 255 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CACHE_AGING_SEC1_MAX 255 /* arbitrary but easy to remember */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CACHE_AGING_SEC2_MAX 255 /* arbitrary but easy to remember */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CACHE_AGING_SEC3_MAX 255 /* arbitrary but easy to remember */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CACHE_AGING_PCNT1_MAX 100
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CACHE_AGING_PCNT2_MAX 100
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define MAX_HOLDS_PCNT_MAX 100
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * dynmem global structure defn
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct _dm_process_vars {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kcondvar_t thread_dm_cv;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmutex_t thread_dm_lock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int sd_dealloc_flagx; /* gen'l purpose bit flag */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int monitor_dynmem_process; /* bit flag indicating what to report */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int max_dyn_list; /* max num of pages to allow list to */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* grow */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* cache aging parameter set */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cache_aging_ct1; /* hosts/pests - aging hits which */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* trigger dealloc */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cache_aging_ct2; /* metas - aging hits which */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* trigger dealloc not yet imple */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cache_aging_ct3; /* holds - aging hits which */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* trigger dealloc */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cache_aging_sec1; /* sleep time between cache list */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* exam - 100% to pcnt1 free */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cache_aging_sec2; /* sleep time between cache list */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* exam - pcnt1 to pcnt2 free */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cache_aging_sec3; /* sleep time between cache list */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* exam - pcnt2 to 0% free */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cache_aging_pcnt1; /* % free when to kick in accel */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* aging - sec2 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cache_aging_pcnt2; /* % free when to kick in accel */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* aging - sec3 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int max_holds_pcnt; /* max % of cents to act as holdovers */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* stats - debug */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int alloc_ct; /* gross count */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int dealloc_ct; /* gross count */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* thread stats - debug and on the fly tuning of dealloc vars */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int history; /* history flag */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int nodatas; /* # cctls w/o data assigned */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int notavail; /* # cctls w/data but in use */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int candidates; /* # cand. for dealloc checking */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int deallocs; /* # deallocs */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int hosts; /* # hosts */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int pests; /* # pests */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int metas; /* # metas - sticky meata data */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int holds; /* # holdovers - single page, fully */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* aged but not dealloc'd or hash */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* del'd */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int others; /* # everybody else */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int process_directive; /* processing directive bitmap flag */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* standard stats (no prefetch tallies here) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int read_hits; /* found in cache memory */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int read_misses; /* not found in cache memory */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int write_hits; /* found in cache memory */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int write_misses; /* not found in cache memory */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int write_thru; /* not bothering to put in cache mem */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * prefetch tracked by _sd_prefetch_valid_cnt and _sd_prefetch_busy_cnt
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * might want different usage ?
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int prefetch_hits;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int prefetch_misses;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} _dm_process_vars_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * dynmem interface
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint sdbc_edit_xfer_process_vars_dm(_dm_process_vars_t *process_vars);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Defines to hide the sd_addr_t structure
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define cc_data cc_addr.sa_virt
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Defines to hide the synchronisation block
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define cc_blkcv cc_sync->_cc_blkcv
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define cc_lock cc_sync->_cc_lock
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This struct exists solely so that sd_info is able to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * extract this kind of data from sdbc without passing out
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the entire _sd_cctl_t which has lots of pointers which
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * makes it impossible to deal with in 32bit program and an
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * LP64 kernel.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ci_write; /* 0 == no wrt data */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_bitmap_t ci_dirty; /* dirty bits */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_bitmap_t ci_valid; /* valid bits */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ci_cd; /* the cd */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t ci_dblk; /* the disk block number */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} sdbc_info_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct _sd_wr_cctl {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ss_resource_t wc_res;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ss_centry_info_t wc_centry_info;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} _sd_wr_cctl_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct _sd_queue {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct _sd_cctl sq_qhead; /* LRU queue head */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmutex_t sq_qlock; /* LRU spinlock */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char sq_await; /* number blocked on lru sema */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int sq_inq; /* Number of LRU entries in q */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned int sq_seq; /* sequence number for lru optim */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned int sq_req_stat;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned int sq_noreq_stat;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* dmchain support */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int sq_dmchain_cblocks; /* dmchain len in ccents */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} _sd_queue_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The net structure contains which memory net has been configured for
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cache, the amount of space allocated, the write control and fault
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * tolerant blocks etc
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct _sd_net {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned short sn_psize; /* Page size of memory in this net */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned char sn_configured; /* is this network configured */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size_t sn_csize; /* Cache size in bytes */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t sn_wsize; /* Write size in bytes */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int sn_cpages; /* number of pages for Cache */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}_sd_net_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _KERNEL || _KMEMUSER */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Shared structure shared between cds and statistics
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NOTE - this structure is visible as an ioctl result.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If anything changes here _sd_get_stats() and convert_stats()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * will need to be changed.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct _sd_shared {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t sh_filesize; /* Filesize (in FBAs) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte volatile uchar_t sh_alloc; /* Is this allocated? */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte volatile uchar_t sh_failed; /* Disk failure status (0 == ok, */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* 1 == i/o error, 2 == open failed ) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned short sh_cd; /* the cache descriptor. (for stats) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int sh_cache_read; /* Number of FBAs read from cache */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int sh_cache_write; /* Number of FBAs written to cache */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int sh_disk_read; /* Number of FBAs read from disk */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int sh_disk_write; /* Number of FBAs written to disk */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte volatile int sh_numdirty; /* Number of dirty blocks */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte volatile int sh_numio; /* Number of blocks on way to disk */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte volatile int sh_numfail; /* Number of blocks failed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int sh_flushloop; /* Loops delayed so far */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int sh_flag; /* Flags visible to user programs */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int sh_destaged; /* number of bytes destaged to disk */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int sh_wrcancelns; /* number of writes to dirty blocks */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char sh_filename[NSC_MAXPATH];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} _sd_shared_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(_KERNEL) || defined(_KMEMUSER)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Cache descriptor information.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct _sd_cd_info {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cd_desc; /* The cache descriptor */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cd_flag; /* Flag */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_fd_t *cd_rawfd; /* File descriptor for raw device */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strategy_fn_t cd_strategy; /* Cached copy of strategy func */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dev_t cd_crdev; /* The device this represents */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_iodev_t *cd_iodev; /* I/O device for callbacks */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmutex_t cd_lock; /* spinlock guarding this cd */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte volatile uchar_t cd_writer; /* Disk writer status */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned int cd_hint; /* Hints for this descriptor */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ss_voldata_t *cd_global; /* RM information for this cd */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct _sd_cctl *cd_dirty_head, *cd_dirty_tail; /* dirty chain */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct _sd_cctl *cd_last_ent; /* last entry in dirty chain, for */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cd_lastchain; /* sequential optimization */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct _sd_cctl *cd_lastchain_ptr; /* last sequential chain */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct _sd_cctl *cd_io_head, *cd_io_tail; /* io in progress q */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct _sd_cctl *cd_fail_head;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct _sd_shared *cd_info; /* shared info (filename, size) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char cd_failover; /* done nsc_reserve during failover */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte volatile char cd_recovering; /* cd is being recovered failover or */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* disk_online */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char cd_write_inprogress;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct sd_net_hnd *net_hnd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} _sd_cd_info_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct _sd_buf_hlist {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_buf_handle_t hl_top;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmutex_t hl_lock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte short hl_count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} _sd_buf_hlist_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _KERNEL || _KMEMUSER */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Index into the following st_mem_sizes[] array
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define _SD_LOCAL_MEM 0x00 /* type of memory to allocate */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define _SD_CACHE_MEM 0x01
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define _SD_IOBUF_MEM 0x02
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define _SD_HASH_MEM 0x03
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define _SD_GLOBAL_MEM 0x04
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define _SD_STATS_MEM 0x05
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define _SD_MAX_MEM _SD_STATS_MEM + 1
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* maintain stat struct layout */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define NUM_WQ_PAD 4
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cache statistics structure
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NOTE - if anything changes here _sd_get_stats() and convert_stats()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * must be changed and _sd_stats32_t must also be synchronized.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct _sd_stats {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int net_dirty;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int net_pending;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int net_free;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int st_count; /* number of opens for device */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int st_loc_count; /* number of open devices */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int st_rdhits; /* number of read hits */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int st_rdmiss; /* number of read misses */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int st_wrhits; /* number of write hits */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int st_wrmiss; /* number of write misses */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int st_blksize; /* cache block size (in bytes) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t st_lru_blocks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t st_lru_noreq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t st_lru_req;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int st_wlru_inq; /* number of write blocks */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int st_cachesize; /* cache size (in bytes) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int st_numblocks; /* # of cache blocks */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int st_wrcancelns; /* # of write cancellations */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int st_destaged; /* # of bytes destaged to disk */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_shared_t st_shared[1]; /* shared structures */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} _sd_stats_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct _sd_stats_32 {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int net_dirty;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int net_pending;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int net_free;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int st_count; /* number of opens for device */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int st_loc_count; /* number of open devices */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int st_rdhits; /* number of read hits */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int st_rdmiss; /* number of read misses */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int st_wrhits; /* number of write hits */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int st_wrmiss; /* number of write misses */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int st_blksize; /* cache block size (in bytes) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t st_lru_blocks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t st_lru_noreq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t st_lru_req;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int st_wlru_inq; /* number of write blocks */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int st_cachesize; /* cache size (in bytes) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int st_numblocks; /* # of cache blocks */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int st_wrcancelns; /* # of write cancellations */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int st_destaged; /* # of bytes destaged to disk */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_shared_t st_shared[1]; /* shared structures */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} _sd_stats32_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(_KERNEL) || defined(_KMEMUSER)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The map structure contains mapping between a mask and relevent information
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * that would take some computation at runtime.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Given a mask, what is the first LSB set (stpos)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Given a mask, what are the consecutive number of LSB bits set (len)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Given a mask, what would be a new mask if the consecutive LSB bits are reset
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Given a mask, how many ios would be needed to flush this block.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Given a mask, how many buffer descriptor lists (bdls) would be needed
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * on a read.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct _sd_map_info {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned char mi_stpos; /* position of first LSB set */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned char mi_len; /* Length of consecutive LSB set */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned char mi_dirty_count; /* number of fragmented bits */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned char mi_io_count; /* number of bdls for a given mask */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_bitmap_t mi_mask; /* new mask with cons. LSB's reset */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} _sd_map_info_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cc_inuse is set with atomic exchange instruction
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * when clearing, must check for waiters.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sd_serialize prohibits speculative reads
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CENTRY_INUSE(centry) ((centry)->cc_inuse)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SET_CENTRY_INUSE(centry) \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((centry)->cc_inuse || atomic_swap(CC_INUSE, &(centry)->cc_inuse))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CLEAR_CENTRY_INUSE(centry) { \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (centry)->cc_inuse = 0; \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sd_serialize(); \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((centry)->cc_await_use) { \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&(centry)->cc_lock); \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_broadcast(&(centry)->cc_blkcv); \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&(centry)->cc_lock); \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cc_pageio is set with atomic exchange instruction
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * when clearing, must check for waiters.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sd_serialize prohibits speculative reads
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CENTRY_PAGEIO(centry) ((centry)->cc_pageio)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SET_CENTRY_PAGEIO(centry) \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((centry)->cc_pageio || atomic_swap(CC_PAGEIO, &(centry)->cc_pageio))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define WAIT_CENTRY_PAGEIO(centry, stat) { \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (SET_CENTRY_PAGEIO(centry)) { \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (stat)++; \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cc_wait(CENTRY_CD(centry), CENTRY_BLK(centry), \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry, CC_PAGEIO); \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CLEAR_CENTRY_PAGEIO(centry) { \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (centry)->cc_pageio = 0; \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sd_serialize(); \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((centry)->cc_await_page) { \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&(centry)->cc_lock); \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_broadcast(&(centry)->cc_blkcv); \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&(centry)->cc_lock); \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CENTRY_DIRTY_PENDING(centry) ((centry)->cc_flag & CC_PEND_DIRTY)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CENTRY_PINNED(centry) ((centry)->cc_flag & CC_PINNED)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CENTRY_PINNABLE(centry) ((centry)->cc_flag & CC_PINNABLE)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CENTRY_QHEAD(centry) ((centry)->cc_flag & CC_QHEAD)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CENTRY_DIRTY(centry) ((centry)->cc_dirty)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CENTRY_CD(centry) ((centry)->cc_head.hh_cd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CENTRY_BLK(centry) ((centry)->cc_head.hh_blk_num)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CENTRY_IO_INPROGRESS(centry) ((centry)->cc_iostatus)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define HANDLE_CD(handle) ((handle)->bh_cd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _KERNEL || _KMEMUSER */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(_KERNEL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CENTRY_SET_FTPOS(centry) \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (centry)->cc_write->sc_cd = CENTRY_CD(centry), \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (centry)->cc_write->sc_fpos = CENTRY_BLK(centry)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CC_CD_BLK_MATCH(cd, blk, centry) \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (((centry)->cc_head.hh_cd == cd) && \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((centry)->cc_head.hh_blk_num == blk))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define _SD_ZEROADDR ((ucaddr_t)(_sd_net_config.sn_zeroaddr))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define ASSERT_LEN(len) \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (len > _SD_MAX_FBAS) {\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN, \
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!sdbc(ASSERT_LEN) fba exceeds limits. fba_len %" \
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana NSC_SZFMT ". Max %d", len, _SD_MAX_FBAS); \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EIO); }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define ASSERT_IO_SIZE(fba_num, fba_len, cd) \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fba_num + fba_len) > \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (_sd_cache_files[(cd)].cd_info->sh_filesize)) { \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN, \
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!sdbc(ASSERT_IO_SIZE) io beyond end of file." \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " fpos %" NSC_SZFMT " len %" NSC_SZFMT " file size 0 - %" \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_SZFMT "\n", fba_num, fba_len, \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (_sd_cache_files[(cd)].cd_info->sh_filesize)); \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EIO); \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define ASSERT_HANDLE_LIMITS(m_h1, m_fpos, m_flen) \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (((m_fpos) < (m_h1)->bh_fba_pos) || \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (((m_fpos) + (m_flen)) > \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((m_h1)->bh_fba_pos + (m_h1)->bh_fba_len))) { \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN, \
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!sdbc(ASSERT_HANDLE_LIMITS) operation out of bounds" \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " cd %x want %" NSC_SZFMT " to %" NSC_SZFMT ". Handle %" \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_SZFMT " to %" NSC_SZFMT, HANDLE_CD(m_h1), m_fpos,\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte m_flen, (m_h1)->bh_fba_pos, (m_h1)->bh_fba_len); \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL); \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define _SD_HANDLE_ACTIVE(handle) ((handle)->bh_flag & NSC_HACTIVE)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define _SD_CD_HINTS(cd) (_sd_cache_files[(cd)].cd_hint)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define _SD_NODE_HINTS (_sd_node_hint)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define _SD_SETUP_HANDLE(hndl, cd, fpos, flen, flag) { \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hndl->bh_cd = cd; \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hndl->bh_vec = hndl->bh_bufvec; \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hndl->bh_fba_pos = fpos; \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hndl->bh_fba_len = flen; \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hndl->bh_busy_thread = nsc_threadp(); \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cd == _CD_NOHASH) \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hndl->bh_flag |= \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (flag | _SD_NODE_HINTS | NSC_HACTIVE); \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hndl->bh_flag |= \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (flag | _SD_CD_HINTS(cd) | \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _SD_NODE_HINTS | NSC_HACTIVE); \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define _SD_NOT_WRTHRU(handle) (((handle)->bh_flag & _SD_WRTHRU_MASK) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define _SD_IS_WRTHRU(handle) ((handle)->bh_flag & _SD_WRTHRU_MASK)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define FILE_OPENED(cd) (((cd) >= 0) && ((cd) < (sdbc_max_devs)) && \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (_sd_cache_files[(cd)].cd_info != NULL) && \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (_sd_cache_files[(cd)].cd_info->sh_alloc \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte & CD_ALLOCATED))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * bitmap stuff
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_LOOKUP_STPOS(mask) (_sd_lookup_map[(mask)].mi_stpos)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_LOOKUP_LEN(mask) (_sd_lookup_map[(mask)].mi_len)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_LOOKUP_MASK(mask) (_sd_lookup_map[(mask)].mi_mask)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_LOOKUP_DTCOUNT(mask) (_sd_lookup_map[(mask)].mi_dirty_count)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_LOOKUP_IOCOUNT(mask) (_sd_lookup_map[(mask)].mi_io_count)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_LOOKUP_MODIFY(mask) (mask &= ~(_sd_lookup_map[(mask)].mi_mask))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_IS_FRAGMENTED(bmap) (!_sd_contig_bmap[(bmap)])
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_IS_CONTIGUOUS(bmap) (_sd_contig_bmap[(bmap)])
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _KERNEL */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(_KERNEL) || defined(_KMEMUSER)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_GET_BITS(fba_off, fba_len) \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (_fba_bits[(fba_len)] << (fba_off))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_SET_VALID_BITS(fba_off, fba_len, cc_entry) \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (cc_entry)->cc_valid |= SDBC_GET_BITS(fba_off, fba_len)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_SET_DIRTY(fba_off, fba_len, cc_entry) { \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_bitmap_t dirty, newdb = SDBC_GET_BITS(fba_off, fba_len); \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ss_centry_info_t *gl = (cc_entry)->cc_write; \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (cc_entry)->cc_valid |= newdb; \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dirty = ((cc_entry)->cc_dirty |= newdb); \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gl->sc_dirty = dirty; \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gl->sc_flag = (int)(cc_entry)->cc_flag; \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SSOP_SETCENTRY(sdbc_safestore, gl); }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_SET_TOFLUSH(fba_off, fba_len, cc_entry) { \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_bitmap_t dirty, newdb = SDBC_GET_BITS(fba_off, fba_len); \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ss_centry_info_t *gl = (cc_entry)->cc_write; \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (cc_entry)->cc_toflush |= newdb; \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (cc_entry)->cc_valid |= newdb; \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dirty = (cc_entry)->cc_toflush | (cc_entry)->cc_dirty; \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gl->sc_dirty = dirty; \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SSOP_SETCENTRY(sdbc_safestore, gl); }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_VALID_BITS(fba_off, fba_len, cc_entry) \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((((cc_entry)->cc_valid) & (SDBC_GET_BITS(fba_off, fba_len))) \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte == (SDBC_GET_BITS(fba_off, fba_len)))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_DIRTY_NEIGHBORS(last, next) \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((SDBC_IS_CONTIGUOUS((last)->cc_dirty)) && \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (SDBC_IS_CONTIGUOUS((next)->cc_dirty)) && \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte(((last)->cc_dirty & (1 << (BLK_FBAS - 1))) && ((next)->cc_dirty & 0x01)))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define FULLY_VALID(cc_entry) ((cc_entry)->cc_valid == BLK_FBA_BITS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SET_FULLY_VALID(cc_entry) \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((cc_entry)->cc_valid = BLK_FBA_BITS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define FULLY_DIRTY(cc_entry) ((cc_entry)->cc_dirty == BLK_FBA_BITS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define _SD_BIT_ISSET(bmap, bit) ((bmap & (1 << bit)) ? 1 : 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define _SD_BMAP_ISFULL(bmap) (bmap == BLK_FBA_BITS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _KERNEL || _KMEMUSER */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(_KERNEL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if !defined(_SD_NOSTATS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CACHE_FBA_READ(cd, blks) \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (((cd) >= 0) && ((cd) < sdbc_max_devs))\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats->st_shared[(cd)].sh_cache_read += (blks)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define DISK_FBA_READ(cd, blks) \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (((cd) >= 0) && ((cd) < sdbc_max_devs))\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats->st_shared[(cd)].sh_disk_read += (blks)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CACHE_FBA_WRITE(cd, blks) \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (((cd) >= 0) && ((cd) < sdbc_max_devs))\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats->st_shared[(cd)].sh_cache_write += (blks)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define DISK_FBA_WRITE(cd, blks) \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (((cd) >= 0) && ((cd) < sdbc_max_devs))\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats->st_shared[(cd)].sh_disk_write += (blks)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CACHE_READ_HIT _sd_cache_stats->st_rdhits++
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CACHE_READ_MISS _sd_cache_stats->st_rdmiss++
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CACHE_WRITE_HIT _sd_cache_stats->st_wrhits++
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CACHE_WRITE_MISS _sd_cache_stats->st_wrmiss++
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CACHE_WRITE_CANCELLATION(cd) {\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((cd) < sdbc_max_devs)\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats->st_shared[(cd)].sh_wrcancelns++;\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats->st_wrcancelns++;\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define WRITE_DESTAGED(cd, bytes) {\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (((cd) >= 0) && ((cd) < sdbc_max_devs))\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats->st_shared[(cd)].sh_destaged += (bytes);\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats->st_destaged += (bytes);\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define FBA_READ_IO_KSTATS(cd, bytes) {\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (((cd) >= 0) && ((cd) < sdbc_max_devs) && sdbc_cd_io_kstats[(cd)]) {\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte KSTAT_IO_PTR(sdbc_cd_io_kstats[(cd)])->reads++;\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte KSTAT_IO_PTR(sdbc_cd_io_kstats[(cd)])->nread += (bytes);\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_global_io_kstat) {\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte KSTAT_IO_PTR(sdbc_global_io_kstat)->reads++;\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte KSTAT_IO_PTR(sdbc_global_io_kstat)->nread += (bytes);\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define FBA_WRITE_IO_KSTATS(cd, bytes) {\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (((cd) >= 0) && ((cd) < sdbc_max_devs) && sdbc_cd_io_kstats[(cd)]) {\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte KSTAT_IO_PTR(sdbc_cd_io_kstats[(cd)])->writes++;\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte KSTAT_IO_PTR(sdbc_cd_io_kstats[(cd)])->nwritten += (bytes);\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_global_io_kstat) {\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte KSTAT_IO_PTR(sdbc_global_io_kstat)->writes++;\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte KSTAT_IO_PTR(sdbc_global_io_kstat)->nwritten += (bytes);\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* start timer measuring amount of time spent in the cache */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define KSTAT_RUNQ_ENTER(cd) {\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (((cd) >= 0) && ((cd) < sdbc_max_devs) && \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cd_io_kstats[(cd)] && sdbc_cd_io_kstats_mutexes) {\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(sdbc_cd_io_kstats[(cd)]->ks_lock);\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_runq_enter(KSTAT_IO_PTR(sdbc_cd_io_kstats[(cd)]));\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(sdbc_cd_io_kstats[(cd)]->ks_lock);\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_global_io_kstat) {\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(sdbc_global_io_kstat->ks_lock);\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_runq_enter(KSTAT_IO_PTR(sdbc_global_io_kstat));\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(sdbc_global_io_kstat->ks_lock);\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* stop timer measuring amount of time spent in the cache */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define KSTAT_RUNQ_EXIT(cd) {\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (((cd) >= 0) && ((cd) < sdbc_max_devs) && \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cd_io_kstats[(cd)] && sdbc_cd_io_kstats_mutexes) {\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(sdbc_cd_io_kstats[(cd)]->ks_lock);\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_runq_exit(KSTAT_IO_PTR(sdbc_cd_io_kstats[(cd)]));\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(sdbc_cd_io_kstats[(cd)]->ks_lock);\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_global_io_kstat) {\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(sdbc_global_io_kstat->ks_lock);\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_runq_exit(KSTAT_IO_PTR(sdbc_global_io_kstat));\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(sdbc_global_io_kstat->ks_lock);\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CACHE_FBA_READ(cd, blks)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define DISK_FBA_READ(cd, blks)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CACHE_FBA_WRITE(cd, blks)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define DISK_FBA_WRITE(cd, blks)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CACHE_READ_HIT
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CACHE_READ_MISS
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CACHE_WRITE_HIT
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CACHE_WRITE_MISS
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CACHE_WRITE_CANCELLATION(cd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define WRITE_DESTAGED(cd, bytes)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _KERNEL */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* defines for sh_alloc */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CD_ALLOC_IN_PROGRESS 0x0001
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CD_ALLOCATED 0x0002
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CD_CLOSE_IN_PROGRESS 0x0010
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* defines for sh_flag */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CD_ATTACHED 0x0001
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef _KERNEL
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef void (*sdbc_ea_fn_t) (blind_t, nsc_off_t, nsc_size_t, int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define _SD_DISCONNECT_CALLBACK(hndl) \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((hndl)->bh_disconnect_cb) { \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(SDF_DISCONNECT, (hndl)->bh_cd, (hndl)->bh_fba_len, \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (hndl)->bh_fba_pos, (hndl)->bh_flag, 0); \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((*((hndl)->bh_disconnect_cb))(hndl)); \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define _SD_READ_CALLBACK(hndl) \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((hndl)->bh_read_cb) \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((*((hndl)->bh_read_cb))(hndl)); \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else cmn_err(CE_WARN, \
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!sdbc(_SD_READ_CALLBACK) not registered. io lost");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define _SD_WRITE_CALLBACK(hndl) \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((hndl)->bh_write_cb) \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((*((hndl)->bh_write_cb))(hndl)); \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else cmn_err(CE_WARN, \
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!sdbc(_SD_WRITE_CALLBACK) not registered. io lost");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _KERNEL */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(_SD_LRU_OPTIMIZE)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Do not requeue if we fall into the tail 25% of the lru
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define LRU_REQ_LIMIT(q) (q->sq_inq >> 2)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define _sd_lru_reinsert(q, ent) \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (((q->sq_seq - ent->cc_seq) > LRU_REQ_LIMIT(q)) ?\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 1 : ((q->sq_noreq_stat)++, 0))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define _sd_lru_reinsert(ent) 1
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(_KERNEL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SD_WR_NUMIO 100
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SD_DCON_THRESH 0x10000 /* Disconnect if io len greater than 64 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * These defines are the hardwired values after sd_config_param was
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * zapped. Ought to remove the use of these entirely ....
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define _SD_CD_WRITER(cd) ((_sd_cache_files[(cd)].cd_info->sh_numdirty>\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SD_WR_NUMIO) ? \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cd_writer(cd) : 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define _SD_FORCE_DISCONNECT(len) (SD_DCON_THRESH < FBA_SIZE(len))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* -------------------------------- END sd_config_param defines ---------- */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define _SD_CD_WBLK_USED(cd) (_sd_cache_stats->st_shared[(cd)].sh_numio +\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats->st_shared[(cd)].sh_numdirty)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define _SD_CD_ALL_WRITES(cd) (_sd_cache_stats->st_shared[(cd)].sh_numio +\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats->st_shared[(cd)].sh_numdirty+\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats->st_shared[(cd)].sh_numfail)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ncall usage
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SD_ENABLE (NCALL_SDBC + 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SD_DISABLE (NCALL_SDBC + 1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SD_DUAL_WRITE (NCALL_SDBC + 2)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SD_DUAL_READ (NCALL_SDBC + 3)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SD_SET_CD (NCALL_SDBC + 4)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SD_GETSIZE (NCALL_SDBC + 5)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SD_DUAL_OPEN (NCALL_SDBC + 6)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SD_REMOTE_FLUSH (NCALL_SDBC + 7)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SD_SGREMOTE_FLUSH (NCALL_SDBC + 8)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SD_DISK_IO (NCALL_SDBC + 9)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SD_GET_BMAP (NCALL_SDBC + 10)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SD_CD_DISCARD (NCALL_SDBC + 11)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SD_PING (NCALL_SDBC + 12)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SD_DC_MAIN_LOOP (NCALL_SDBC + 13)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SD_DATA (NCALL_SDBC + 14)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SD_BDATA (NCALL_SDBC + 15)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SD_UPDATE (NCALL_SDBC + 16)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SD_GET_SYSID (NCALL_SDBC + 17)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef lint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/nsctl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define LINTUSED(x) (void)(x)++
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define LINTUSED(x)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int BLK_FBAS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern _sd_bitmap_t BLK_FBA_BITS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern _sd_bitmap_t _fba_bits[];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern _sd_cctl_t *_sd_cctl[];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern _sd_cd_info_t *_sd_cache_files;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern _sd_hash_table_t *_sd_htable;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern _sd_map_info_t _sd_lookup_map[];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern _sd_net_t _sd_net_config;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern _sd_queue_t _sd_lru_q;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern _sd_stats_t *_sd_cache_stats;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern char _sd_contig_bmap[];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int CACHE_BLOCK_SIZE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int CBLOCKS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int _sd_cctl_groupsz;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int sdbc_static_cache;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern kmutex_t _sd_cache_lock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern nsc_def_t _sd_sdbc_def[];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern nsc_io_t *sdbc_io;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern nsc_mem_t *sdbc_iobuf_mem, *sdbc_hash_mem;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern uint_t _sd_node_hint;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int _sd_minidsp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern krwlock_t sdbc_queue_lock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern safestore_ops_t *sdbc_safestore;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern ss_common_config_t safestore_config;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern ss_voldata_t *_sdbc_gl_file_info;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int _sdbc_cache_configure(int cblocks, spcs_s_info_t kstatus);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern void _sdbc_cache_deconfigure(void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern void _sd_requeue(_sd_cctl_t *centry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern void _sd_requeue_head(_sd_cctl_t *centry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int _sd_open(char *filename, int flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int _sd_open_cd(char *filename, const int cd, const int flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int _sd_close(int cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int _sdbc_remote_store_pinned(int cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int _sdbc_io_attach_cd(blind_t xcd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int _sdbc_io_detach_cd(blind_t xcd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int _sd_get_pinned(blind_t cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern void _sd_cc_copy(_sd_cctl_t *cc_real, _sd_cctl_t *cc_shadow);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern _sd_buf_handle_t *_sd_allocate_buf(int cd, nsc_off_t fba_pos,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t fba_len, int flag, int *sts);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern void _sd_cc_wait(int cd, nsc_off_t cblk, _sd_cctl_t *centry, int flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int _sd_alloc_buf(blind_t xcd, nsc_off_t fba_pos, nsc_size_t fba_len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int flag, _sd_buf_handle_t **handle_p);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int _sd_free_buf(_sd_buf_handle_t *handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern _sd_cctl_t *_sd_centry_alloc(int, int, int *, int, int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int _sd_centry_setup_dm(_sd_cctl_t *, int, int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern void _sdbc_dealloc_deconfigure_dm(void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int _sdbc_dealloc_configure_dm(void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern _sd_cctl_t *_sd_shadow_centry(_sd_cctl_t *, _sd_cctl_t *, int, int, int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern void _sd_centry_release(_sd_cctl_t *centry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int _sd_alloc_write(_sd_cctl_t *centry, int *stall);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int _sd_read(_sd_buf_handle_t *handle, nsc_off_t fba_pos,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t fba_len, int flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern void _sd_read_complete(_sd_buf_handle_t *handle, nsc_off_t fba_pos,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t fba_len, int error);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int _sd_write(_sd_buf_handle_t *handle, nsc_off_t fba_pos,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t fba_len, int flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int _sd_zero(_sd_buf_handle_t *handle, nsc_off_t fba_pos,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t fba_len, int flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int _sd_copy(_sd_buf_handle_t *handle1, _sd_buf_handle_t *handle2,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t fba_pos1, nsc_off_t fba_pos2, nsc_size_t fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern void _sd_enqueue_dirty(int cd, _sd_cctl_t *chain, _sd_cctl_t *cc_last,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int numq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern void _sd_enqueue_dirty_chain(int cd, _sd_cctl_t *chain_first,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *chain_last, int numq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int _sd_get_stats(_sd_stats_t *uptr, int convert_32);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int _sd_set_hint(int cd, uint_t hint);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int _sd_clear_hint(int cd, uint_t hint);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int _sd_get_cd_hint(int cd, uint_t *hint);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int _sd_set_node_hint(uint_t hint);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int _sd_clear_node_hint(uint_t hint);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int _sd_get_node_hint(uint_t *hint);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int _sd_get_partsize(blind_t cd, nsc_size_t *ptr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int _sd_get_maxfbas(blind_t cd, int flag, nsc_size_t *ptr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int _sd_discard_pinned(blind_t cd, nsc_off_t fba_pos,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern void _sdbc_handles_unload(void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int _sdbc_handles_load(void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int _sdbc_handles_configure();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern void _sdbc_handles_deconfigure(void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern _sd_buf_handle_t *_sd_alloc_handle(sdbc_callback_fn_t d_cb,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_callback_fn_t r_cb, sdbc_callback_fn_t w_cb);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int _sd_free_handle(_sd_buf_handle_t *handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern void _sd_init_contig_bmap(void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern void _sd_init_lookup_map(void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int sd_get_file_info_size(void *uaddrp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int sd_get_file_info_data(char *uaddrp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int sd_get_glmul_sizes(int *uaddrp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int sd_get_glmul_info(char *uaddrp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern _sd_cctl_t *sdbc_centry_alloc(int, nsc_off_t, nsc_size_t, int *,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_allocbuf_t *, int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern _sd_cctl_t *sdbc_centry_alloc_blks(int, nsc_off_t, nsc_size_t, int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int _sdbc_ft_hold_io;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern kcondvar_t _sdbc_ft_hold_io_cv;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern kmutex_t _sdbc_ft_hold_io_lk;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* for testing only */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int _sdbc_flush_flag; /* inhibit flush for testing */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int _sdbc_clear_ioerr(int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int _sdbc_inject_ioerr(int, int, int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern void _sdbc_ioj_set_dev(int, dev_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern void _sdbc_ioj_load();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern void _sdbc_ioj_unload();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _KERNEL */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef __cplusplus
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _SD_BCACHE_H */