1 /*
   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 
  26 #ifndef _SD_HASH_H
  27 #define _SD_HASH_H
  28 
  29 #ifdef  __cplusplus
  30 extern "C" {
  31 #endif
  32 
  33 #include <sys/nsctl/nsctl.h>
  34 
  35 #if defined(_KERNEL) || defined(_KMEMUSER)
  36 
  37 typedef struct _sd_hash_hd {
  38         unsigned short hh_hashed;               /* Is this block in hash */
  39         unsigned short hh_cd;                   /* The cache descriptor */
  40         nsc_off_t hh_blk_num;                   /* Cache block number   */
  41         struct _sd_hash_hd *hh_prev;            /* for chaining withing */
  42         struct _sd_hash_hd *hh_next;            /* hash table           */
  43 } _sd_hash_hd_t;
  44 
  45 
  46 typedef struct _sd_hash_bucket {
  47         struct _sd_hash_hd *hb_head;
  48         struct _sd_hash_hd *hb_tail;
  49         kmutex_t *hb_lock;
  50         unsigned short hb_inlist;
  51         volatile unsigned int hb_seq;
  52 } _sd_hash_bucket_t;
  53 
  54 
  55 typedef struct _sd_hash_table  {
  56         int ht_size;
  57         int ht_bits;
  58         int ht_mask;
  59         int ht_nmask;
  60         struct _sd_hash_bucket *ht_buckets;
  61 } _sd_hash_table_t;
  62 
  63 
  64 #endif /* _KERNEL && _KMEMUSER */
  65 
  66 
  67 #if defined(_KERNEL)
  68 
  69 #define HASH(cd, blk, table) \
  70         (((cd << 6) ^ ((blk) ^ ((blk) >> table->ht_bits)))       \
  71             & (table->ht_mask))
  72 
  73 #define HT_SEARCH       0
  74 #define HT_NOSEARCH     1
  75 
  76 extern int _sdbc_hash_load(void);
  77 extern void _sdbc_hash_unload(void);
  78 extern _sd_hash_table_t *_sdbc_hash_configure(int num_ents);
  79 extern void _sdbc_hash_deconfigure(_sd_hash_table_t *hash_table);
  80 extern _sd_hash_hd_t *_sd_hash_search(int cd, nsc_off_t block_num,
  81     _sd_hash_table_t *table);
  82 extern _sd_hash_hd_t *_sd_hash_insert(int cd, nsc_off_t block_num,
  83     _sd_hash_hd_t *hptr, _sd_hash_table_t *table);
  84 extern int _sd_hash_delete(_sd_hash_hd_t *hptr, _sd_hash_table_t *table);
  85 extern _sd_hash_hd_t *_sd_hash_replace(_sd_hash_hd_t *old, _sd_hash_hd_t *new,
  86     _sd_hash_table_t *table);
  87 #endif /* _KERNEL */
  88 
  89 #ifdef  __cplusplus
  90 }
  91 #endif
  92 
  93 #endif /* _SD_HASH_H */