xref: /onnv-gate/usr/src/uts/common/avs/ns/sdbc/sd_cache.h (revision 9093:cd587b0bd19c)
17836SJohn.Forte@Sun.COM /*
27836SJohn.Forte@Sun.COM  * CDDL HEADER START
37836SJohn.Forte@Sun.COM  *
47836SJohn.Forte@Sun.COM  * The contents of this file are subject to the terms of the
57836SJohn.Forte@Sun.COM  * Common Development and Distribution License (the "License").
67836SJohn.Forte@Sun.COM  * You may not use this file except in compliance with the License.
77836SJohn.Forte@Sun.COM  *
87836SJohn.Forte@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97836SJohn.Forte@Sun.COM  * or http://www.opensolaris.org/os/licensing.
107836SJohn.Forte@Sun.COM  * See the License for the specific language governing permissions
117836SJohn.Forte@Sun.COM  * and limitations under the License.
127836SJohn.Forte@Sun.COM  *
137836SJohn.Forte@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
147836SJohn.Forte@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157836SJohn.Forte@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
167836SJohn.Forte@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
177836SJohn.Forte@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
187836SJohn.Forte@Sun.COM  *
197836SJohn.Forte@Sun.COM  * CDDL HEADER END
207836SJohn.Forte@Sun.COM  */
217836SJohn.Forte@Sun.COM /*
22*9093SRamana.Srikanth@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237836SJohn.Forte@Sun.COM  * Use is subject to license terms.
247836SJohn.Forte@Sun.COM  */
257836SJohn.Forte@Sun.COM 
267836SJohn.Forte@Sun.COM #ifndef _SD_CACHE_H
277836SJohn.Forte@Sun.COM #define	_SD_CACHE_H
287836SJohn.Forte@Sun.COM 
297836SJohn.Forte@Sun.COM #ifdef __cplusplus
307836SJohn.Forte@Sun.COM extern "C" {
317836SJohn.Forte@Sun.COM #endif
327836SJohn.Forte@Sun.COM 
337836SJohn.Forte@Sun.COM #include	<sys/debug.h>
347836SJohn.Forte@Sun.COM #include <sys/nsctl/nsctl.h>
357836SJohn.Forte@Sun.COM 
367836SJohn.Forte@Sun.COM /*
377836SJohn.Forte@Sun.COM  * Compiler defines
387836SJohn.Forte@Sun.COM  */
397836SJohn.Forte@Sun.COM 
407836SJohn.Forte@Sun.COM #define	_SD_FAULT_RES		/* Enable Fault tolerance		*/
417836SJohn.Forte@Sun.COM 
427836SJohn.Forte@Sun.COM #define	_SD_USE_THREADS		/* Use own threadset			*/
437836SJohn.Forte@Sun.COM #define	_SD_LRU_OPTIMIZE	/* Enable LRU queue optimizations  	*/
447836SJohn.Forte@Sun.COM #define	_SD_HASH_OPTIMIZE	/* Enable Hash optimizations		*/
457836SJohn.Forte@Sun.COM 
467836SJohn.Forte@Sun.COM #if !defined(_SD_NO_GENERIC)
477836SJohn.Forte@Sun.COM #define	_SD_MULTIUSER		/* Block locking (concurrent/dual copy) */
487836SJohn.Forte@Sun.COM #endif /* (_SD_NO_GENERIC) */
497836SJohn.Forte@Sun.COM 
507836SJohn.Forte@Sun.COM #if defined(_SD_OPTIM_ALLOC)
517836SJohn.Forte@Sun.COM #define	_SD_NOCHECKS		/* Disable handle allocation checks	*/
527836SJohn.Forte@Sun.COM #define	_SD_NOTRACE		/* Disable SDTRACE() macro		*/
537836SJohn.Forte@Sun.COM #undef	_SD_MULTIUSER		/* Disable Block locking		*/
547836SJohn.Forte@Sun.COM #if (_SD_OPTIM_ALLOC+0 > 1)
557836SJohn.Forte@Sun.COM #define	_SD_NOSTATS		/* Disable read/write counts		*/
567836SJohn.Forte@Sun.COM #endif
577836SJohn.Forte@Sun.COM #endif /* (_SD_OPTIM_ALLOC) */
587836SJohn.Forte@Sun.COM 
597836SJohn.Forte@Sun.COM #if defined(_SD_CHECKS)		/* Enable checks, stats, and tracing	*/
607836SJohn.Forte@Sun.COM #undef	_SD_NOCHECKS
617836SJohn.Forte@Sun.COM #undef	_SD_NOTRACE
627836SJohn.Forte@Sun.COM #undef	_SD_NOSTATS
637836SJohn.Forte@Sun.COM #define	_SD_STATS		/* Enable cache hits/longevity stats	*/
647836SJohn.Forte@Sun.COM #if (_SD_CHECKS+0 > 1)
657836SJohn.Forte@Sun.COM #define	_SD_DEBUG		/* Extra debugging checks		*/
667836SJohn.Forte@Sun.COM #endif
677836SJohn.Forte@Sun.COM #endif /* (_SD_CHECKS) */
687836SJohn.Forte@Sun.COM 
697836SJohn.Forte@Sun.COM #if defined(_SD_NOTRACE) && defined(_SD_STATS)
707836SJohn.Forte@Sun.COM #undef _SD_STATS		/* _SD_STATS requires SDTRACE() macro	*/
717836SJohn.Forte@Sun.COM #endif
727836SJohn.Forte@Sun.COM 
737836SJohn.Forte@Sun.COM /*
747836SJohn.Forte@Sun.COM  * Other compiler defines currently not enabled.
757836SJohn.Forte@Sun.COM  * 	#define	_SD_FBA_DATA_LOG  Enable data logging per 512 bytes.
767836SJohn.Forte@Sun.COM  * Other compiler defines enabled in the Makefile.
777836SJohn.Forte@Sun.COM  *	#define	_SD_8K_BLKSIZE	  Allow 8K cache block size
787836SJohn.Forte@Sun.COM  */
797836SJohn.Forte@Sun.COM 
807836SJohn.Forte@Sun.COM extern	int	_sd_cblock_shift;
817836SJohn.Forte@Sun.COM #define	BLK_SHFT	(_sd_cblock_shift)
827836SJohn.Forte@Sun.COM #define	BLK_MASK	((1 << BLK_SHFT) - 1)
837836SJohn.Forte@Sun.COM #define	BLK_SIZE(x)	((x) << BLK_SHFT)
847836SJohn.Forte@Sun.COM #define	BLK_NUM(x)	((x) >> BLK_SHFT)
857836SJohn.Forte@Sun.COM #define	BLK_LEN(x)	((x + BLK_MASK) >> BLK_SHFT)
867836SJohn.Forte@Sun.COM #define	BLK_OFF(x)	((x) & BLK_MASK)
877836SJohn.Forte@Sun.COM 
887836SJohn.Forte@Sun.COM 
897836SJohn.Forte@Sun.COM 
907836SJohn.Forte@Sun.COM #define	BLK_FBA_SHFT	(BLK_SHFT - FBA_SHFT)
917836SJohn.Forte@Sun.COM #define	BLK_FBA_MASK	((1 << BLK_FBA_SHFT) - 1)
927836SJohn.Forte@Sun.COM #define	BLK_TO_FBA_NUM(x) \
937836SJohn.Forte@Sun.COM 			((x) << BLK_FBA_SHFT)	/* block_num to fba_num */
947836SJohn.Forte@Sun.COM #define	BLK_FBA_OFF(x)	((x) & BLK_FBA_MASK)	/* fba offset within */
957836SJohn.Forte@Sun.COM 						/* a cache block */
967836SJohn.Forte@Sun.COM 
977836SJohn.Forte@Sun.COM #define	FBA_TO_BLK_NUM(x) \
987836SJohn.Forte@Sun.COM 			((x) >> BLK_FBA_SHFT)	/* fba_num to a */
997836SJohn.Forte@Sun.COM 						/* block_num */
1007836SJohn.Forte@Sun.COM 
1017836SJohn.Forte@Sun.COM /* fba_num to the next higher block_num */
1027836SJohn.Forte@Sun.COM #define	FBA_TO_BLK_LEN(x)	((x + BLK_FBA_MASK) >> BLK_FBA_SHFT)
1037836SJohn.Forte@Sun.COM 
1047836SJohn.Forte@Sun.COM /*
1057836SJohn.Forte@Sun.COM  * This is the set of flags that are valid. Anything else set in the
1067836SJohn.Forte@Sun.COM  * handle is invalid and the handle should be rejected during an allocation.
1077836SJohn.Forte@Sun.COM  */
1087836SJohn.Forte@Sun.COM 
1097836SJohn.Forte@Sun.COM #define	_SD_VALID_FLAGS (NSC_RDWRBUF | NSC_NOBLOCK | NSC_WRTHRU | NSC_NOCACHE\
1107836SJohn.Forte@Sun.COM 			| NSC_HALLOCATED | NSC_BCOPY | NSC_PAGEIO \
1117836SJohn.Forte@Sun.COM 			| NSC_PINNABLE | NSC_MIXED | NSC_FORCED_WRTHRU \
1127836SJohn.Forte@Sun.COM 			| NSC_METADATA)
1137836SJohn.Forte@Sun.COM 
1147836SJohn.Forte@Sun.COM 
1157836SJohn.Forte@Sun.COM #define	_SD_FLAG_MASK   	(NSC_FLAGS)
1167836SJohn.Forte@Sun.COM #define	_SD_HINT_MASK		(NSC_HINTS)
1177836SJohn.Forte@Sun.COM #define	_SD_WRTHRU_MASK		(NSC_WRTHRU | NSC_FORCED_WRTHRU)
1187836SJohn.Forte@Sun.COM #define	_SD_NOCACHE_MASK	(NSC_NOCACHE)
1197836SJohn.Forte@Sun.COM 
1207836SJohn.Forte@Sun.COM 
1217836SJohn.Forte@Sun.COM 
1227836SJohn.Forte@Sun.COM #define	_SD_INVALID_CD(cd)	((cd) > sdbc_max_devs)
1237836SJohn.Forte@Sun.COM 
1247836SJohn.Forte@Sun.COM #define	_INFSD_NODE_UP(i)	(nsc_node_up(i))
1257836SJohn.Forte@Sun.COM 
1267836SJohn.Forte@Sun.COM #ifdef m88k
1277836SJohn.Forte@Sun.COM #define	_sd_cache_initialized	_INFSD_cache_initialized
1287836SJohn.Forte@Sun.COM #endif
1297836SJohn.Forte@Sun.COM 
1307836SJohn.Forte@Sun.COM #define	_SD_MAX_FBAS	1024
1317836SJohn.Forte@Sun.COM /*
1327836SJohn.Forte@Sun.COM  * Allow one entry for null terminator and another to handle
1337836SJohn.Forte@Sun.COM  * requests that are not cache block aligned.
1347836SJohn.Forte@Sun.COM  */
1357836SJohn.Forte@Sun.COM #if defined(_SD_8K_BLKSIZE)
1367836SJohn.Forte@Sun.COM #define	_SD_MAX_BLKS	(2 + ((_SD_MAX_FBAS) >> 4))
1377836SJohn.Forte@Sun.COM #else
1387836SJohn.Forte@Sun.COM #define	_SD_MAX_BLKS	(2 + ((_SD_MAX_FBAS) >> 3))
1397836SJohn.Forte@Sun.COM #endif
1407836SJohn.Forte@Sun.COM 
1417836SJohn.Forte@Sun.COM /* cd to use for _sd_centry_alloc to avoid entering hash table */
1427836SJohn.Forte@Sun.COM 
1437836SJohn.Forte@Sun.COM #define	_CD_NOHASH	-1
1447836SJohn.Forte@Sun.COM 
1457836SJohn.Forte@Sun.COM #if defined(_KERNEL) || defined(_KMEMUSER)
1467836SJohn.Forte@Sun.COM 
1477836SJohn.Forte@Sun.COM struct _sd_buf_handle;
1487836SJohn.Forte@Sun.COM typedef void (*sdbc_callback_fn_t)(struct _sd_buf_handle *);
1497836SJohn.Forte@Sun.COM 
1507836SJohn.Forte@Sun.COM typedef struct _sd_buf_handle {
1517836SJohn.Forte@Sun.COM 	nsc_buf_t bh_buf;		/* Generic buffer - must be first */
1527836SJohn.Forte@Sun.COM 	nsc_vec_t bh_bufvec[_SD_MAX_BLKS]; /* Scatter gather list */
1537836SJohn.Forte@Sun.COM 	int bh_cd;
1547836SJohn.Forte@Sun.COM 	sdbc_callback_fn_t bh_disconnect_cb;
1557836SJohn.Forte@Sun.COM 	sdbc_callback_fn_t bh_read_cb;
1567836SJohn.Forte@Sun.COM 	sdbc_callback_fn_t bh_write_cb;
1577836SJohn.Forte@Sun.COM 	struct _sd_cctl *bh_centry;
1587836SJohn.Forte@Sun.COM 	struct _sd_buf_handle *bh_next;
1597836SJohn.Forte@Sun.COM 	struct _sd_buf_handle *bh_prev;
1607836SJohn.Forte@Sun.COM 	void *bh_alloc_thread; /* debug: kthread that alloc'd this handle */
1617836SJohn.Forte@Sun.COM 	void *bh_busy_thread; /* debug: kthread that is using this handle */
1627836SJohn.Forte@Sun.COM 	void *bh_param;
1637836SJohn.Forte@Sun.COM } _sd_buf_handle_t;
1647836SJohn.Forte@Sun.COM 
1657836SJohn.Forte@Sun.COM #define	bh_fba_pos	bh_buf.sb_pos
1667836SJohn.Forte@Sun.COM #define	bh_fba_len	bh_buf.sb_len
1677836SJohn.Forte@Sun.COM #define	bh_flag		bh_buf.sb_flag
1687836SJohn.Forte@Sun.COM #define	bh_error	bh_buf.sb_error
1697836SJohn.Forte@Sun.COM #define	bh_vec		bh_buf.sb_vec
1707836SJohn.Forte@Sun.COM 
1717836SJohn.Forte@Sun.COM #define	_sd_bufvec_t	nsc_vec_t
1727836SJohn.Forte@Sun.COM #define	buflen		sv_len
1737836SJohn.Forte@Sun.COM #define	bufaddr		sv_addr
1747836SJohn.Forte@Sun.COM #define	bufvmeaddr	sv_vme
1757836SJohn.Forte@Sun.COM 
1767836SJohn.Forte@Sun.COM #endif /* _KERNEL || _KMEMUSER */
1777836SJohn.Forte@Sun.COM 
1787836SJohn.Forte@Sun.COM #ifdef __cplusplus
1797836SJohn.Forte@Sun.COM }
1807836SJohn.Forte@Sun.COM #endif
1817836SJohn.Forte@Sun.COM 
1827836SJohn.Forte@Sun.COM #endif /* _SD_CACHE_H */
183