xref: /titanic_50/usr/src/uts/common/sys/damap_impl.h (revision aedf2b3bb56b025fcaf87b49ec6c8aeea07f16d7)
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 int (*configure_cb_t)(void *, dam_t *mapp, id_t map_id);
61 typedef int (*unconfig_cb_t)(void *, dam_t *mapp, id_t map_id);
62 
63 
64 struct dam {
65 	char		*dam_name;
66 	int		dam_flags;		/* map state and cv flags */
67 	int		dam_options;		/* map options */
68 	int		dam_rptmode;		/* report mode */
69 	clock_t		dam_stabletmo;		/* stabilization (ticks) */
70 	uint_t		dam_size;		/* max index for addr hash */
71 	id_t		dam_high;		/* highest index allocated */
72 	timeout_id_t	dam_tid;		/* timeout(9F) ID */
73 
74 	void		*dam_activate_arg;	/* activation private */
75 	activate_cb_t	dam_activate_cb;	/* activation callback */
76 	deactivate_cb_t	dam_deactivate_cb;	/* deactivation callback */
77 
78 	void		*dam_config_arg;	/* config-private */
79 	configure_cb_t	dam_configure_cb;	/* configure callout */
80 	unconfig_cb_t	dam_unconfig_cb;	/* unconfigure callout */
81 
82 	ddi_strid	*dam_addr_hash;		/* addresss to ID hash */
83 	bitset_t	dam_active_set;		/* activated address set */
84 	bitset_t	dam_stable_set;		/* stable address set */
85 	bitset_t	dam_report_set;		/* reported address set */
86 	void		*dam_da;		/* per-address soft state */
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 #define	DAM_SPEND		0x10	/* stable pending */
97 #define	DAM_DESTROYPEND		0x20	/* in process of being destroyed */
98 #define	DAM_SETADD		0x100	/* fullset update pending */
99 
100 /*
101  * per address softstate stucture
102  */
103 typedef struct {
104 	uint_t		da_flags;	/* flags */
105 	int		da_jitter;	/* address re-report count */
106 	int		da_ref;		/* refcount on address */
107 	void		*da_ppriv;	/* stable provider private */
108 	void		*da_cfg_priv;	/* config/unconfig private */
109 	nvlist_t	*da_nvl;	/* stable nvlist */
110 	void		*da_ppriv_rpt;	/* reported provider-private */
111 	nvlist_t	*da_nvl_rpt;	/* reported nvlist */
112 	int64_t		da_deadline;	/* lbolt64 value when stable */
113 	hrtime_t	da_last_report;	/* timestamp of last report */
114 	int		da_report_cnt;	/* # of times address reported */
115 	hrtime_t	da_last_stable;	/* timestamp of last stable address */
116 	int		da_stable_cnt;	/* # of times address has stabilized */
117 	char		*da_addr;	/* string in dam_addr_hash (for mdb) */
118 } dam_da_t;
119 
120 /*
121  * dam_da_t.da_flags
122  */
123 #define	DA_INIT			0x1	/* address initizized */
124 #define	DA_FAILED_CONFIG	0x2	/* address failed configure */
125 #define	DA_RELE			0x4	/* adddress released */
126 
127 
128 /*
129  * report type
130  */
131 #define	RPT_ADDR_ADD		0
132 #define	RPT_ADDR_DEL		1
133 
134 #define	DAM_IN_REPORT(m, i)	(bitset_in_set(&(m)->dam_report_set, (i)))
135 #define	DAM_IS_STABLE(m, i)	(bitset_in_set(&(m)->dam_active_set, (i)))
136 
137 /*
138  * DAM statistics
139  */
140 struct dam_kstats {
141 	struct kstat_named dam_cycles;
142 	struct kstat_named dam_overrun;
143 	struct kstat_named dam_jitter;
144 	struct kstat_named dam_active;
145 };
146 
147 #ifdef	__cplusplus
148 }
149 #endif
150 
151 #endif	/* _SYS_DAMAP_IMPL_H */
152