xref: /titanic_52/usr/src/uts/common/sys/damap_impl.h (revision 9525b14bcdeb5b5f6f95ab27c2f48f18bd2ec829)
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 /*
23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_DAMAP_IMPL_H
28 #define	_SYS_DAMAP_IMPL_H
29 
30 #include <sys/isa_defs.h>
31 #include <sys/dditypes.h>
32 #include <sys/time.h>
33 #include <sys/cmn_err.h>
34 #include <sys/ddi_impldefs.h>
35 #include <sys/ddi_implfuncs.h>
36 #include <sys/ddi_isa.h>
37 #include <sys/model.h>
38 #include <sys/devctl.h>
39 #include <sys/nvpair.h>
40 #include <sys/sysevent.h>
41 #include <sys/bitset.h>
42 #include <sys/sdt.h>
43 
44 #ifdef	__cplusplus
45 extern "C" {
46 #endif
47 
48 typedef struct dam dam_t;
49 
50 /*
51  * activate_cb:		Provider callback when reported address is activated
52  * deactivate_cb:	Provider callback when address has been released
53  *
54  * configure_cb:	Class callout to configure newly activated addresses
55  * unconfig_cb:		Class callout to unconfigure deactivated addresses
56  */
57 typedef void (*activate_cb_t)(void *, char *addr, int idx, void **privp);
58 typedef void (*deactivate_cb_t)(void *, char *addr, int idx, void *priv);
59 
60 typedef void (*configure_cb_t)(void *, dam_t *mapp, bitset_t *config_ids);
61 typedef void (*unconfig_cb_t)(void *, dam_t *mapp, bitset_t *unconfig_ids);
62 
63 struct dam {
64 	char		*dam_name;
65 	int		dam_flags;		/* state and locks */
66 	int		dam_options;		/* options at map creation */
67 	int		dam_rptmode;		/* report mode */
68 	clock_t		dam_stabletmo;		/* stabilization (ticks) */
69 	uint_t		dam_size;		/* max index for addr hash */
70 	id_t		dam_high;		/* highest index allocated */
71 	timeout_id_t	dam_tid;		/* timeout(9F) ID */
72 
73 	void		*dam_activate_arg;	/* activation private */
74 	activate_cb_t	dam_activate_cb;	/* activation callback */
75 	deactivate_cb_t	dam_deactivate_cb;	/* deactivation callback */
76 
77 	void		*dam_config_arg;	/* config-private */
78 	configure_cb_t	dam_configure_cb;	/* configure callout */
79 	unconfig_cb_t	dam_unconfig_cb;	/* unconfigure callout */
80 
81 	ddi_strid	*dam_addr_hash;		/* addresss to ID hash */
82 	bitset_t	dam_active_set;		/* activated address set */
83 	bitset_t	dam_stable_set;		/* stable address set */
84 	bitset_t	dam_report_set;		/* reported address set */
85 	void		*dam_da;		/* per-address soft state */
86 	ddi_taskq_t	*dam_taskqp;		/* taskq for map activation */
87 	hrtime_t	dam_last_update;	/* last map update */
88 	hrtime_t	dam_last_stable;	/* last map stable */
89 	int		dam_stable_cnt;		/* # of times map stabilized */
90 	int		dam_stable_overrun;
91 	kcondvar_t	dam_cv;
92 	kmutex_t	dam_lock;
93 	kstat_t		*dam_kstatsp;
94 };
95 
96 /*
97  * damap.dam_flags
98  */
99 #define	ADDR_LOCK		0x1000	/* per-addr lock */
100 #define	MAP_LOCK		0x2000	/* global map lock */
101 #define	DAM_LOCK(m, l)		{					\
102 	mutex_enter(&(m)->dam_lock);					\
103 	while ((m)->dam_flags & (l))					\
104 		cv_wait(&(m)->dam_cv, &(m)->dam_lock);			\
105 	(m)->dam_flags |= (l);						\
106 	mutex_exit(&(m)->dam_lock);					\
107 }
108 #define	DAM_UNLOCK(m, l)	{					\
109 	mutex_enter(&(m)->dam_lock);					\
110 	(m)->dam_flags &= ~(l);						\
111 	cv_signal(&(m)->dam_cv);					\
112 	mutex_exit(&(m)->dam_lock);					\
113 }
114 #define	DAM_ASSERT_LOCKED(m, l) ASSERT((m)->dam_flags & (l))
115 
116 #define	DAM_SPEND		0x10	/* stable pending */
117 #define	DAM_DESTROYPEND		0x20	/* in process of being destroyed */
118 #define	DAM_SETADD		0x100	/* fullset update pending */
119 #define	DAM_FLAG_SET(m, f)	{					\
120 	mutex_enter(&(m)->dam_lock);					\
121 	(m)->dam_flags |= f;						\
122 	mutex_exit(&(m)->dam_lock);					\
123 }
124 #define	DAM_FLAG_CLR(m, f)	{					\
125 	mutex_enter(&(m)->dam_lock);					\
126 	(m)->dam_flags &= ~f;						\
127 	mutex_exit(&(m)->dam_lock);					\
128 }
129 
130 /*
131  * per address softstate stucture
132  */
133 typedef struct {
134 	uint_t		da_flags;	/* flags */
135 	int		da_jitter;	/* address report count */
136 	int		da_ref;		/* refcount on address */
137 	void		*da_ppriv;	/* stable provider private */
138 	void		*da_cfg_priv;	/* config/unconfig private */
139 	nvlist_t	*da_nvl;	/* stable nvlist */
140 	void		*da_ppriv_rpt;	/* reported provider-private */
141 	nvlist_t	*da_nvl_rpt;	/* reported nvlist */
142 	int64_t		da_deadline;	/* lbolt64 value when stable */
143 	hrtime_t	da_last_report;	/* timestamp of last report */
144 	int		da_report_cnt;	/* # of times address reported */
145 	hrtime_t	da_last_stable;	/* timestamp of last stable address */
146 	int		da_stable_cnt;	/* # of times address has stabilized */
147 	char		*da_addr;	/* string in dam_addr_hash (for mdb) */
148 } dam_da_t;
149 
150 /*
151  * dam_da_t.da_flags
152  */
153 #define	DA_INIT			0x1	/* address initizized */
154 #define	DA_ACTIVE		0x2	/* address stable */
155 #define	DA_RELE			0x4	/* adddress released */
156 
157 
158 /*
159  * report type
160  */
161 #define	RPT_ADDR_ADD		0
162 #define	RPT_ADDR_DEL		1
163 
164 #define	DAM_IN_REPORT(m, i)	(bitset_in_set(&(m)->dam_report_set, (i)))
165 #define	DAM_IS_STABLE(m, i)	(bitset_in_set(&(m)->dam_active_set, (i)))
166 
167 /*
168  * DAM statistics
169  */
170 struct dam_kstats {
171 	struct kstat_named dam_stable;
172 	struct kstat_named dam_stable_blocked;
173 	struct kstat_named dam_rereport;
174 	struct kstat_named dam_numstable;
175 };
176 
177 #ifdef	__cplusplus
178 }
179 #endif
180 
181 #endif	/* _SYS_DAMAP_IMPL_H */
182