xref: /onnv-gate/usr/src/uts/common/avs/ns/rdc/rdc_bitmap.h (revision 7836:4e95154b5b7a)
1*7836SJohn.Forte@Sun.COM /*
2*7836SJohn.Forte@Sun.COM  * CDDL HEADER START
3*7836SJohn.Forte@Sun.COM  *
4*7836SJohn.Forte@Sun.COM  * The contents of this file are subject to the terms of the
5*7836SJohn.Forte@Sun.COM  * Common Development and Distribution License (the "License").
6*7836SJohn.Forte@Sun.COM  * You may not use this file except in compliance with the License.
7*7836SJohn.Forte@Sun.COM  *
8*7836SJohn.Forte@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*7836SJohn.Forte@Sun.COM  * or http://www.opensolaris.org/os/licensing.
10*7836SJohn.Forte@Sun.COM  * See the License for the specific language governing permissions
11*7836SJohn.Forte@Sun.COM  * and limitations under the License.
12*7836SJohn.Forte@Sun.COM  *
13*7836SJohn.Forte@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
14*7836SJohn.Forte@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*7836SJohn.Forte@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
16*7836SJohn.Forte@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
17*7836SJohn.Forte@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
18*7836SJohn.Forte@Sun.COM  *
19*7836SJohn.Forte@Sun.COM  * CDDL HEADER END
20*7836SJohn.Forte@Sun.COM  */
21*7836SJohn.Forte@Sun.COM /*
22*7836SJohn.Forte@Sun.COM  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23*7836SJohn.Forte@Sun.COM  * Use is subject to license terms.
24*7836SJohn.Forte@Sun.COM  */
25*7836SJohn.Forte@Sun.COM 
26*7836SJohn.Forte@Sun.COM #ifndef _RDC_BITMAP_H
27*7836SJohn.Forte@Sun.COM #define	_RDC_BITMAP_H
28*7836SJohn.Forte@Sun.COM 
29*7836SJohn.Forte@Sun.COM #ifdef	__cplusplus
30*7836SJohn.Forte@Sun.COM extern "C" {
31*7836SJohn.Forte@Sun.COM #endif
32*7836SJohn.Forte@Sun.COM 
33*7836SJohn.Forte@Sun.COM #ifdef _KERNEL
34*7836SJohn.Forte@Sun.COM 
35*7836SJohn.Forte@Sun.COM extern int rdc_bitmap_mode;	/* property from rdc.conf */
36*7836SJohn.Forte@Sun.COM 
37*7836SJohn.Forte@Sun.COM /*
38*7836SJohn.Forte@Sun.COM  * Possible values of rdc_bitmap_mode - integer flag.
39*7836SJohn.Forte@Sun.COM  */
40*7836SJohn.Forte@Sun.COM #define	RDC_BMP_AUTO	0x0	/* auto detect bitmap mode */
41*7836SJohn.Forte@Sun.COM #define	RDC_BMP_ALWAYS	0x1	/* always write the bitmap */
42*7836SJohn.Forte@Sun.COM #define	RDC_BMP_NEVER	0x2	/* never write the bitmap */
43*7836SJohn.Forte@Sun.COM 
44*7836SJohn.Forte@Sun.COM #endif	/* _KERNEL */
45*7836SJohn.Forte@Sun.COM 
46*7836SJohn.Forte@Sun.COM /*
47*7836SJohn.Forte@Sun.COM  * Public bitmap interface
48*7836SJohn.Forte@Sun.COM  * The bitmaps are maintained on 32 Kbyte segments
49*7836SJohn.Forte@Sun.COM  */
50*7836SJohn.Forte@Sun.COM 
51*7836SJohn.Forte@Sun.COM #define	LOG_SHFT		15
52*7836SJohn.Forte@Sun.COM #define	IND_BYTE(ind)		((ind) >> 3)
53*7836SJohn.Forte@Sun.COM #define	IND_BIT(ind)		(1 << ((ind) & 0x7))
54*7836SJohn.Forte@Sun.COM 
55*7836SJohn.Forte@Sun.COM #define	FBA_LOG_SHFT		(LOG_SHFT - FBA_SHFT)
56*7836SJohn.Forte@Sun.COM #define	FBA_TO_LOG_NUM(x)	((x) >> FBA_LOG_SHFT)
57*7836SJohn.Forte@Sun.COM #define	LOG_TO_FBA_NUM(x)	((x) << FBA_LOG_SHFT)
58*7836SJohn.Forte@Sun.COM #define	FBA_TO_LOG_LEN(x)	(FBA_TO_LOG_NUM((x)-1) + 1)
59*7836SJohn.Forte@Sun.COM 
60*7836SJohn.Forte@Sun.COM #define	BMAP_LOG_BYTES(fbas)	(IND_BYTE(FBA_TO_LOG_NUM((fbas)-1))+1)
61*7836SJohn.Forte@Sun.COM 
62*7836SJohn.Forte@Sun.COM #define	BITS_IN_BYTE		8
63*7836SJohn.Forte@Sun.COM 
64*7836SJohn.Forte@Sun.COM /*
65*7836SJohn.Forte@Sun.COM  * Private macros for bitmap manipulation
66*7836SJohn.Forte@Sun.COM  */
67*7836SJohn.Forte@Sun.COM 
68*7836SJohn.Forte@Sun.COM #define	BMAP_BIT_SET(bmap, ind) ((bmap)[IND_BYTE(ind)] |= IND_BIT(ind))
69*7836SJohn.Forte@Sun.COM #define	BMAP_BIT_CLR(bmap, ind) ((bmap)[IND_BYTE(ind)] &= ~IND_BIT(ind))
70*7836SJohn.Forte@Sun.COM #define	BMAP_BIT_ISSET(bmap, ind) \
71*7836SJohn.Forte@Sun.COM 				((bmap)[IND_BYTE(ind)] & IND_BIT(ind))
72*7836SJohn.Forte@Sun.COM 
73*7836SJohn.Forte@Sun.COM #define	BIT_TO_FBA(b)		(FBA_NUM(b) >> 3)
74*7836SJohn.Forte@Sun.COM 
75*7836SJohn.Forte@Sun.COM #define	BMAP_REF_SET(krdc, ind) (((krdc)->bm_refs->bmap_ref_set)(krdc, ind))
76*7836SJohn.Forte@Sun.COM #define	BMAP_REF_CLR(krdc, ind) (((krdc)->bm_refs->bmap_ref_clr)(krdc, ind))
77*7836SJohn.Forte@Sun.COM #define	BMAP_REF_ISSET(krdc, ind) (((krdc)->bm_refs->bmap_ref_isset)(krdc, ind))
78*7836SJohn.Forte@Sun.COM #define	BMAP_REF_FORCE(krdc, ind, val) \
79*7836SJohn.Forte@Sun.COM 			(((krdc)->bm_refs->bmap_ref_force)(krdc, ind, val))
80*7836SJohn.Forte@Sun.COM #define	BMAP_REF_MAXVAL(krdc) (((krdc)->bm_refs->bmap_ref_maxval)(krdc))
81*7836SJohn.Forte@Sun.COM #define	BMAP_REF_SIZE(krdc)	((krdc)->bm_refs->bmap_ref_size)
82*7836SJohn.Forte@Sun.COM #define	BMAP_REF_PREF_SIZE	(sizeof (unsigned int))
83*7836SJohn.Forte@Sun.COM 
84*7836SJohn.Forte@Sun.COM #ifndef _KERNEL
85*7836SJohn.Forte@Sun.COM 
86*7836SJohn.Forte@Sun.COM struct bm_ref_ops {
87*7836SJohn.Forte@Sun.COM 	void		(*bmap_ref_set)(void *, int);
88*7836SJohn.Forte@Sun.COM 	void		(*bmap_ref_clr)(void *, int);
89*7836SJohn.Forte@Sun.COM 	unsigned int	(*bmap_ref_isset)(void *, int);
90*7836SJohn.Forte@Sun.COM 	void		(*bmap_ref_force)(void *, int, unsigned int);
91*7836SJohn.Forte@Sun.COM 	unsigned int	(*bmap_ref_maxval)(void *);
92*7836SJohn.Forte@Sun.COM 	size_t		bmap_ref_size;
93*7836SJohn.Forte@Sun.COM };
94*7836SJohn.Forte@Sun.COM 
95*7836SJohn.Forte@Sun.COM #else
96*7836SJohn.Forte@Sun.COM 
97*7836SJohn.Forte@Sun.COM struct bm_ref_ops {
98*7836SJohn.Forte@Sun.COM 	void		(*bmap_ref_set)(rdc_k_info_t *, int);
99*7836SJohn.Forte@Sun.COM 	void		(*bmap_ref_clr)(rdc_k_info_t *, int);
100*7836SJohn.Forte@Sun.COM 	unsigned int	(*bmap_ref_isset)(rdc_k_info_t *, int);
101*7836SJohn.Forte@Sun.COM 	void		(*bmap_ref_force)(rdc_k_info_t *, int, unsigned int);
102*7836SJohn.Forte@Sun.COM 	unsigned int	(*bmap_ref_maxval)(rdc_k_info_t *);
103*7836SJohn.Forte@Sun.COM 	size_t		bmap_ref_size;
104*7836SJohn.Forte@Sun.COM };
105*7836SJohn.Forte@Sun.COM 
106*7836SJohn.Forte@Sun.COM 
107*7836SJohn.Forte@Sun.COM /* convert fba to block number */
108*7836SJohn.Forte@Sun.COM #define	_BNUM(x)		(FBA_TO_LOG_NUM(x))
109*7836SJohn.Forte@Sun.COM 
110*7836SJohn.Forte@Sun.COM /* force reference clear during sync */
111*7836SJohn.Forte@Sun.COM #define	RDC_BIT_BUMP	0x0
112*7836SJohn.Forte@Sun.COM #define	RDC_BIT_FORCE	0x1
113*7836SJohn.Forte@Sun.COM #define	RDC_BIT_FLUSHER	0x2
114*7836SJohn.Forte@Sun.COM 
115*7836SJohn.Forte@Sun.COM /* check for overlap, taking account of blocking factor */
116*7836SJohn.Forte@Sun.COM #define	RDC_OVERLAP(p1, l1, p2, l2)	\
117*7836SJohn.Forte@Sun.COM 		    ((_BNUM(((p1) + (l1) - 1)) >= _BNUM((p2))) && \
118*7836SJohn.Forte@Sun.COM 		    (_BNUM((p1)) <= _BNUM(((p2) + (l2) - 1))))
119*7836SJohn.Forte@Sun.COM 
120*7836SJohn.Forte@Sun.COM struct rdc_bitmap_ops {
121*7836SJohn.Forte@Sun.COM 	int	(*set_bitmap)(rdc_k_info_t *, const nsc_off_t, const nsc_size_t,
122*7836SJohn.Forte@Sun.COM 	    uint_t *);
123*7836SJohn.Forte@Sun.COM 	void	(*clr_bitmap)(rdc_k_info_t *, const nsc_off_t, const nsc_size_t,
124*7836SJohn.Forte@Sun.COM 	    const uint_t, const int);
125*7836SJohn.Forte@Sun.COM 	int	(*count_dirty)(rdc_k_info_t *);
126*7836SJohn.Forte@Sun.COM 	int	(*bit_isset)(rdc_k_info_t *, const int);
127*7836SJohn.Forte@Sun.COM 	int	(*fill_bitmap)(rdc_k_info_t *, const int);
128*7836SJohn.Forte@Sun.COM 	void	(*zero_bitmap)(rdc_k_info_t *);
129*7836SJohn.Forte@Sun.COM 	int	(*net_bmap)(const struct bmap6 *);
130*7836SJohn.Forte@Sun.COM 	int	(*net_b_data)(const struct net_bdata6 *);
131*7836SJohn.Forte@Sun.COM 	void	(*zero_bitref)(rdc_k_info_t *);
132*7836SJohn.Forte@Sun.COM 	void	(*set_bitmask)(const nsc_off_t, const nsc_size_t, uint_t *);
133*7836SJohn.Forte@Sun.COM 	void	(*check_bit)(rdc_k_info_t *, nsc_off_t, nsc_size_t);
134*7836SJohn.Forte@Sun.COM };
135*7836SJohn.Forte@Sun.COM 
136*7836SJohn.Forte@Sun.COM extern struct rdc_bitmap_ops *rdc_bitmap_ops;
137*7836SJohn.Forte@Sun.COM 
138*7836SJohn.Forte@Sun.COM #define	RDC_SET_BITMAP(krdc, pos, len, bitmaskp) \
139*7836SJohn.Forte@Sun.COM 		(*rdc_bitmap_ops->set_bitmap)(krdc, pos, len, bitmaskp)
140*7836SJohn.Forte@Sun.COM #define	RDC_CLR_BITMAP(krdc, pos, len, bitmask, flag) \
141*7836SJohn.Forte@Sun.COM 		(*rdc_bitmap_ops->clr_bitmap)(krdc, pos, len, bitmask, flag)
142*7836SJohn.Forte@Sun.COM #define	RDC_COUNT_BITMAP(krdc) \
143*7836SJohn.Forte@Sun.COM 		(*rdc_bitmap_ops->count_dirty)(krdc)
144*7836SJohn.Forte@Sun.COM #define	RDC_BIT_ISSET(krdc, bit) \
145*7836SJohn.Forte@Sun.COM 		(*rdc_bitmap_ops->bit_isset)(krdc, bit)
146*7836SJohn.Forte@Sun.COM #define	RDC_FILL_BITMAP(krdc, write) \
147*7836SJohn.Forte@Sun.COM 		(*rdc_bitmap_ops->fill_bitmap)(krdc, write)
148*7836SJohn.Forte@Sun.COM #define	RDC_ZERO_BITMAP(krdc) \
149*7836SJohn.Forte@Sun.COM 		(*rdc_bitmap_ops->zero_bitmap)(krdc)
150*7836SJohn.Forte@Sun.COM #define	RDC_SEND_BITMAP(argp) \
151*7836SJohn.Forte@Sun.COM 		(*rdc_bitmap_ops->net_bmap)(argp)
152*7836SJohn.Forte@Sun.COM #define	RDC_OR_BITMAP(argp) \
153*7836SJohn.Forte@Sun.COM 		(*rdc_bitmap_ops->net_b_data)(argp)
154*7836SJohn.Forte@Sun.COM #define	RDC_ZERO_BITREF(krdc) \
155*7836SJohn.Forte@Sun.COM 		(*rdc_bitmap_ops->zero_bitref)(krdc)
156*7836SJohn.Forte@Sun.COM #define	RDC_SET_BITMASK(off, len, maskp) \
157*7836SJohn.Forte@Sun.COM 		(*rdc_bitmap_ops->set_bitmask)(off, len, maskp)
158*7836SJohn.Forte@Sun.COM #define	RDC_CHECK_BIT(krdc, pos, len) \
159*7836SJohn.Forte@Sun.COM 		(*rdc_bitmap_ops->check_bit)(krdc, pos, len)
160*7836SJohn.Forte@Sun.COM 
161*7836SJohn.Forte@Sun.COM /*
162*7836SJohn.Forte@Sun.COM  * Functions
163*7836SJohn.Forte@Sun.COM  */
164*7836SJohn.Forte@Sun.COM 
165*7836SJohn.Forte@Sun.COM extern void rdc_bitmap_init(void);
166*7836SJohn.Forte@Sun.COM extern int rdc_move_bitmap(rdc_k_info_t *, char *);
167*7836SJohn.Forte@Sun.COM extern int rdc_enable_bitmap(rdc_k_info_t *, int);
168*7836SJohn.Forte@Sun.COM extern int rdc_resume_bitmap(rdc_k_info_t *);
169*7836SJohn.Forte@Sun.COM extern int rdc_reset_bitmap(rdc_k_info_t *);
170*7836SJohn.Forte@Sun.COM extern void rdc_free_bitmap(rdc_k_info_t *, int);
171*7836SJohn.Forte@Sun.COM extern void rdc_close_bitmap(rdc_k_info_t *);
172*7836SJohn.Forte@Sun.COM extern int rdc_write_bitmap(rdc_k_info_t *);
173*7836SJohn.Forte@Sun.COM extern int rdc_write_bitmap_fill(rdc_k_info_t *);
174*7836SJohn.Forte@Sun.COM extern void rdc_set_bitmap_many(rdc_k_info_t *, nsc_off_t, nsc_size_t);
175*7836SJohn.Forte@Sun.COM extern void rdc_merge_bitmaps(rdc_k_info_t *, rdc_k_info_t *);
176*7836SJohn.Forte@Sun.COM 
177*7836SJohn.Forte@Sun.COM extern int rdc_read_state(rdc_k_info_t *, int *, int *);
178*7836SJohn.Forte@Sun.COM extern int rdc_clear_state(rdc_k_info_t *);
179*7836SJohn.Forte@Sun.COM extern void rdc_write_state(rdc_u_info_t *);
180*7836SJohn.Forte@Sun.COM extern int rdc_ns_io(nsc_fd_t *, int, nsc_off_t, uchar_t *, nsc_size_t);
181*7836SJohn.Forte@Sun.COM extern int rdc_read_refcount(rdc_k_info_t *);
182*7836SJohn.Forte@Sun.COM extern int rdc_write_refcount(rdc_k_info_t *);
183*7836SJohn.Forte@Sun.COM extern size_t rdc_refcntsize(rdc_k_info_t *);
184*7836SJohn.Forte@Sun.COM 
185*7836SJohn.Forte@Sun.COM #endif /* _KERNEL */
186*7836SJohn.Forte@Sun.COM 
187*7836SJohn.Forte@Sun.COM #ifdef	__cplusplus
188*7836SJohn.Forte@Sun.COM }
189*7836SJohn.Forte@Sun.COM #endif
190*7836SJohn.Forte@Sun.COM 
191*7836SJohn.Forte@Sun.COM #endif /* _RDC_BITMAP_H */
192