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