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 2009 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #ifndef _SD_CACHE_H 27 #define _SD_CACHE_H 28 29 #ifdef __cplusplus 30 extern "C" { 31 #endif 32 33 #include <sys/debug.h> 34 #include <sys/nsctl/nsctl.h> 35 36 /* 37 * Compiler defines 38 */ 39 40 #define _SD_FAULT_RES /* Enable Fault tolerance */ 41 42 #define _SD_USE_THREADS /* Use own threadset */ 43 #define _SD_LRU_OPTIMIZE /* Enable LRU queue optimizations */ 44 #define _SD_HASH_OPTIMIZE /* Enable Hash optimizations */ 45 46 #if !defined(_SD_NO_GENERIC) 47 #define _SD_MULTIUSER /* Block locking (concurrent/dual copy) */ 48 #endif /* (_SD_NO_GENERIC) */ 49 50 #if defined(_SD_OPTIM_ALLOC) 51 #define _SD_NOCHECKS /* Disable handle allocation checks */ 52 #define _SD_NOTRACE /* Disable SDTRACE() macro */ 53 #undef _SD_MULTIUSER /* Disable Block locking */ 54 #if (_SD_OPTIM_ALLOC+0 > 1) 55 #define _SD_NOSTATS /* Disable read/write counts */ 56 #endif 57 #endif /* (_SD_OPTIM_ALLOC) */ 58 59 #if defined(_SD_CHECKS) /* Enable checks, stats, and tracing */ 60 #undef _SD_NOCHECKS 61 #undef _SD_NOTRACE 62 #undef _SD_NOSTATS 63 #define _SD_STATS /* Enable cache hits/longevity stats */ 64 #if (_SD_CHECKS+0 > 1) 65 #define _SD_DEBUG /* Extra debugging checks */ 66 #endif 67 #endif /* (_SD_CHECKS) */ 68 69 #if defined(_SD_NOTRACE) && defined(_SD_STATS) 70 #undef _SD_STATS /* _SD_STATS requires SDTRACE() macro */ 71 #endif 72 73 /* 74 * Other compiler defines currently not enabled. 75 * #define _SD_FBA_DATA_LOG Enable data logging per 512 bytes. 76 * Other compiler defines enabled in the Makefile. 77 * #define _SD_8K_BLKSIZE Allow 8K cache block size 78 */ 79 80 extern int _sd_cblock_shift; 81 #define BLK_SHFT (_sd_cblock_shift) 82 #define BLK_MASK ((1 << BLK_SHFT) - 1) 83 #define BLK_SIZE(x) ((x) << BLK_SHFT) 84 #define BLK_NUM(x) ((x) >> BLK_SHFT) 85 #define BLK_LEN(x) ((x + BLK_MASK) >> BLK_SHFT) 86 #define BLK_OFF(x) ((x) & BLK_MASK) 87 88 89 90 #define BLK_FBA_SHFT (BLK_SHFT - FBA_SHFT) 91 #define BLK_FBA_MASK ((1 << BLK_FBA_SHFT) - 1) 92 #define BLK_TO_FBA_NUM(x) \ 93 ((x) << BLK_FBA_SHFT) /* block_num to fba_num */ 94 #define BLK_FBA_OFF(x) ((x) & BLK_FBA_MASK) /* fba offset within */ 95 /* a cache block */ 96 97 #define FBA_TO_BLK_NUM(x) \ 98 ((x) >> BLK_FBA_SHFT) /* fba_num to a */ 99 /* block_num */ 100 101 /* fba_num to the next higher block_num */ 102 #define FBA_TO_BLK_LEN(x) ((x + BLK_FBA_MASK) >> BLK_FBA_SHFT) 103 104 /* 105 * This is the set of flags that are valid. Anything else set in the 106 * handle is invalid and the handle should be rejected during an allocation. 107 */ 108 109 #define _SD_VALID_FLAGS (NSC_RDWRBUF | NSC_NOBLOCK | NSC_WRTHRU | NSC_NOCACHE\ 110 | NSC_HALLOCATED | NSC_BCOPY | NSC_PAGEIO \ 111 | NSC_PINNABLE | NSC_MIXED | NSC_FORCED_WRTHRU \ 112 | NSC_METADATA) 113 114 115 #define _SD_FLAG_MASK (NSC_FLAGS) 116 #define _SD_HINT_MASK (NSC_HINTS) 117 #define _SD_WRTHRU_MASK (NSC_WRTHRU | NSC_FORCED_WRTHRU) 118 #define _SD_NOCACHE_MASK (NSC_NOCACHE) 119 120 121 122 #define _SD_INVALID_CD(cd) ((cd) > sdbc_max_devs) 123 124 #define _INFSD_NODE_UP(i) (nsc_node_up(i)) 125 126 #ifdef m88k 127 #define _sd_cache_initialized _INFSD_cache_initialized 128 #endif 129 130 #define _SD_MAX_FBAS 1024 131 /* 132 * Allow one entry for null terminator and another to handle 133 * requests that are not cache block aligned. 134 */ 135 #if defined(_SD_8K_BLKSIZE) 136 #define _SD_MAX_BLKS (2 + ((_SD_MAX_FBAS) >> 4)) 137 #else 138 #define _SD_MAX_BLKS (2 + ((_SD_MAX_FBAS) >> 3)) 139 #endif 140 141 /* cd to use for _sd_centry_alloc to avoid entering hash table */ 142 143 #define _CD_NOHASH -1 144 145 #if defined(_KERNEL) || defined(_KMEMUSER) 146 147 struct _sd_buf_handle; 148 typedef void (*sdbc_callback_fn_t)(struct _sd_buf_handle *); 149 150 typedef struct _sd_buf_handle { 151 nsc_buf_t bh_buf; /* Generic buffer - must be first */ 152 nsc_vec_t bh_bufvec[_SD_MAX_BLKS]; /* Scatter gather list */ 153 int bh_cd; 154 sdbc_callback_fn_t bh_disconnect_cb; 155 sdbc_callback_fn_t bh_read_cb; 156 sdbc_callback_fn_t bh_write_cb; 157 struct _sd_cctl *bh_centry; 158 struct _sd_buf_handle *bh_next; 159 struct _sd_buf_handle *bh_prev; 160 void *bh_alloc_thread; /* debug: kthread that alloc'd this handle */ 161 void *bh_busy_thread; /* debug: kthread that is using this handle */ 162 void *bh_param; 163 } _sd_buf_handle_t; 164 165 #define bh_fba_pos bh_buf.sb_pos 166 #define bh_fba_len bh_buf.sb_len 167 #define bh_flag bh_buf.sb_flag 168 #define bh_error bh_buf.sb_error 169 #define bh_vec bh_buf.sb_vec 170 171 #define _sd_bufvec_t nsc_vec_t 172 #define buflen sv_len 173 #define bufaddr sv_addr 174 #define bufvmeaddr sv_vme 175 176 #endif /* _KERNEL || _KMEMUSER */ 177 178 #ifdef __cplusplus 179 } 180 #endif 181 182 #endif /* _SD_CACHE_H */ 183