fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or http://www.opensolaris.org/os/licensing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifndef _SD_HASH_H
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define _SD_HASH_H
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef __cplusplus
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern "C" {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/nsctl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(_KERNEL) || defined(_KMEMUSER)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct _sd_hash_hd {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned short hh_hashed; /* Is this block in hash */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned short hh_cd; /* The cache descriptor */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t hh_blk_num; /* Cache block number */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct _sd_hash_hd *hh_prev; /* for chaining withing */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct _sd_hash_hd *hh_next; /* hash table */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} _sd_hash_hd_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct _sd_hash_bucket {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct _sd_hash_hd *hb_head;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct _sd_hash_hd *hb_tail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmutex_t *hb_lock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned short hb_inlist;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte volatile unsigned int hb_seq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} _sd_hash_bucket_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct _sd_hash_table {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ht_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ht_bits;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ht_mask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ht_nmask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct _sd_hash_bucket *ht_buckets;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} _sd_hash_table_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _KERNEL && _KMEMUSER */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(_KERNEL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define HASH(cd, blk, table) \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (((cd << 6) ^ ((blk) ^ ((blk) >> table->ht_bits))) \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte & (table->ht_mask))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define HT_SEARCH 0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define HT_NOSEARCH 1
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int _sdbc_hash_load(void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern void _sdbc_hash_unload(void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern _sd_hash_table_t *_sdbc_hash_configure(int num_ents);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern void _sdbc_hash_deconfigure(_sd_hash_table_t *hash_table);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern _sd_hash_hd_t *_sd_hash_search(int cd, nsc_off_t block_num,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_hash_table_t *table);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern _sd_hash_hd_t *_sd_hash_insert(int cd, nsc_off_t block_num,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_hash_hd_t *hptr, _sd_hash_table_t *table);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int _sd_hash_delete(_sd_hash_hd_t *hptr, _sd_hash_table_t *table);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern _sd_hash_hd_t *_sd_hash_replace(_sd_hash_hd_t *old, _sd_hash_hd_t *new,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_hash_table_t *table);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _KERNEL */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef __cplusplus
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _SD_HASH_H */