xref: /illumos-gate/usr/src/uts/common/sys/overlay_impl.h (revision e3ae4b35c024af1196582063ecee3ab79367227d)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2016 Joyent, Inc.
14  */
15 
16 #ifndef _SYS_OVERLAY_IMPL_H
17 #define	_SYS_OVERLAY_IMPL_H
18 
19 /*
20  * Overlay device support
21  */
22 
23 #include <sys/overlay.h>
24 #include <sys/overlay_common.h>
25 #include <sys/overlay_plugin.h>
26 #include <sys/overlay_target.h>
27 #include <sys/ksynch.h>
28 #include <sys/list.h>
29 #include <sys/avl.h>
30 #include <sys/ksocket.h>
31 #include <sys/socket.h>
32 #include <sys/refhash.h>
33 #include <sys/ethernet.h>
34 #include <sys/list.h>
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 #define	OVEP_VERSION_ONE	0x1
41 
42 typedef struct overlay_plugin {
43 	kmutex_t ovp_mutex;
44 	list_node_t ovp_link;			/* overlay_plugin_lock */
45 	uint_t ovp_active;			/* ovp_mutex */
46 	const char *ovp_name;			/* RO */
47 	const overlay_plugin_ops_t *ovp_ops;	/* RO */
48 	const char *const *ovp_props;		/* RO */
49 	uint_t ovp_nprops;			/* RO */
50 	uint_t ovp_id_size;			/* RO */
51 	overlay_plugin_flags_t ovp_flags;	/* RO */
52 	overlay_plugin_dest_t ovp_dest;		/* RO */
53 } overlay_plugin_t;
54 
55 typedef struct overlay_mux {
56 	list_node_t		omux_lnode;
57 	ksocket_t		omux_ksock;	/* RO */
58 	overlay_plugin_t	*omux_plugin;	/* RO: associated encap */
59 	int			omux_domain;	/* RO: socket domain */
60 	int			omux_family;	/* RO: socket family */
61 	int			omux_protocol;	/* RO: socket protocol */
62 	struct sockaddr		*omux_addr;	/* RO: socket address */
63 	socklen_t		omux_alen;	/* RO: sockaddr len */
64 	kmutex_t		omux_lock;	/* Protects everything below */
65 	uint_t			omux_count;	/* Active instances */
66 	avl_tree_t		omux_devices;	/* Tree of devices */
67 } overlay_mux_t;
68 
69 typedef enum overlay_target_flag {
70 	OVERLAY_T_TEARDOWN	= 0x1
71 } overlay_target_flag_t;
72 
73 typedef struct overlay_target {
74 	kmutex_t		ott_lock;
75 	kcondvar_t		ott_cond;
76 	overlay_target_mode_t	ott_mode;	/* RO */
77 	overlay_plugin_dest_t	ott_dest;	/* RO */
78 	uint64_t		ott_id;		/* RO */
79 	overlay_target_flag_t	ott_flags;	/* ott_lock */
80 	uint_t			ott_ocount;	/* ott_lock */
81 	union {					/* ott_lock */
82 		overlay_target_point_t	ott_point;
83 		struct overlay_target_dyn {
84 			refhash_t	*ott_dhash;
85 			avl_tree_t	ott_tree;
86 		} ott_dyn;
87 	} ott_u;
88 } overlay_target_t;
89 
90 typedef enum overlay_dev_flag {
91 	OVERLAY_F_ACTIVATED	= 0x01, /* Activate ioctl completed */
92 	OVERLAY_F_IN_MUX	= 0x02,	/* Currently in a mux */
93 	OVERLAY_F_IN_TX		= 0x04,	/* Currently doing tx */
94 	OVERLAY_F_IN_RX		= 0x08, /* Currently doing rx */
95 	OVERLAY_F_IOMASK	= 0x0c,	/* A mask for rx and tx */
96 	OVERLAY_F_MDDROP	= 0x10,	/* Drop traffic for metadata update */
97 	OVERLAY_F_STOPMASK	= 0x1e,	/* None set when stopping */
98 	OVERLAY_F_VARPD		= 0x20,	/* varpd plugin exists */
99 	OVERLAY_F_DEGRADED	= 0x40,	/* device is degraded */
100 	OVERLAY_F_MASK		= 0x7f	/* mask of everything */
101 } overlay_dev_flag_t;
102 
103 typedef struct overlay_dev {
104 	kmutex_t	odd_lock;
105 	kcondvar_t	odd_iowait;
106 	list_node_t	odd_link;		/* overlay_dev_lock */
107 	mac_handle_t	odd_mh;			/* RO */
108 	overlay_plugin_t *odd_plugin;		/* RO */
109 	datalink_id_t	odd_linkid;		/* RO */
110 	void		*odd_pvoid;		/* RO -- only used by plugin */
111 	uint_t		odd_ref;		/* protected by odd_lock */
112 	uint_t		odd_mtu;		/* protected by odd_lock */
113 	overlay_dev_flag_t odd_flags;		/* protected by odd_lock */
114 	uint_t		odd_rxcount;		/* protected by odd_lock */
115 	uint_t		odd_txcount;		/* protected by odd_lock */
116 	overlay_mux_t	*odd_mux;		/* protected by odd_lock */
117 	uint64_t	odd_vid;		/* RO if active else odd_lock */
118 	avl_node_t	odd_muxnode;		/* managed by mux */
119 	overlay_target_t *odd_target;		/* See big theory statement */
120 	char		odd_fmamsg[OVERLAY_STATUS_BUFLEN];	/* odd_lock */
121 } overlay_dev_t;
122 
123 typedef enum overlay_target_entry_flags {
124 	OVERLAY_ENTRY_F_PENDING		= 0x01,	/* lookup in progress */
125 	OVERLAY_ENTRY_F_VALID		= 0x02,	/* entry is currently valid */
126 	OVERLAY_ENTRY_F_DROP		= 0x04,	/* always drop target */
127 	OVERLAY_ENTRY_F_VALID_MASK	= 0x06
128 } overlay_target_entry_flags_t;
129 
130 typedef struct overlay_target_entry {
131 	kmutex_t		ote_lock;
132 	refhash_link_t		ote_reflink;	/* hashtable link */
133 	avl_node_t		ote_avllink;	/* iteration link */
134 	list_node_t		ote_qlink;
135 	overlay_target_entry_flags_t ote_flags;	/* RW: state flags */
136 	uint8_t			ote_addr[ETHERADDRL];	/* RO: mac addr */
137 	overlay_target_t	*ote_ott;	/* RO */
138 	overlay_dev_t		*ote_odd;	/* RO */
139 	overlay_target_point_t	ote_dest;	/* RW: destination */
140 	mblk_t			*ote_chead;	/* RW: blocked mb chain head */
141 	mblk_t			*ote_ctail;	/* RW: blocked mb chain tail */
142 	size_t			ote_mbsize;	/* RW: outstanding mblk size */
143 	hrtime_t		ote_vtime;	/* RW: valid timestamp */
144 } overlay_target_entry_t;
145 
146 
147 #define	OVERLAY_CTL	"overlay"
148 
149 #define	OVERLAY_FREEMSG(mp, reason) \
150     DTRACE_PROBE2(overlay__freemsg, mblk_t *, mp, char *, reason)
151 
152 extern dev_info_t *overlay_dip;
153 
154 extern mblk_t *overlay_m_tx(void *, mblk_t *);
155 
156 typedef int (*overlay_dev_iter_f)(overlay_dev_t *, void *);
157 extern void overlay_dev_iter(overlay_dev_iter_f, void *);
158 
159 extern void overlay_plugin_init(void);
160 extern overlay_plugin_t *overlay_plugin_lookup(const char *);
161 extern void overlay_plugin_rele(overlay_plugin_t *);
162 extern void overlay_plugin_fini(void);
163 typedef int (*overlay_plugin_walk_f)(overlay_plugin_t *, void *);
164 extern void overlay_plugin_walk(overlay_plugin_walk_f, void *);
165 
166 extern void overlay_io_start(overlay_dev_t *, overlay_dev_flag_t);
167 extern void overlay_io_done(overlay_dev_t *, overlay_dev_flag_t);
168 
169 extern void overlay_mux_init(void);
170 extern void overlay_mux_fini(void);
171 
172 extern overlay_mux_t *overlay_mux_open(overlay_plugin_t *, int, int, int,
173     struct sockaddr *, socklen_t, int *);
174 extern void overlay_mux_close(overlay_mux_t *);
175 extern void overlay_mux_add_dev(overlay_mux_t *, overlay_dev_t *);
176 extern void overlay_mux_remove_dev(overlay_mux_t *, overlay_dev_t *);
177 extern int overlay_mux_tx(overlay_mux_t *, struct msghdr *, mblk_t *);
178 
179 extern void overlay_prop_init(overlay_prop_handle_t);
180 
181 extern void overlay_target_init(void);
182 extern int overlay_target_busy(void);
183 extern int overlay_target_open(dev_t *, int, int, cred_t *);
184 extern int overlay_target_ioctl(dev_t, int, intptr_t, int, cred_t *, int *);
185 extern int overlay_target_close(dev_t, int, int, cred_t *);
186 extern void overlay_target_free(overlay_dev_t *);
187 
188 #define	OVERLAY_TARGET_OK	0
189 #define	OVERLAY_TARGET_DROP	1
190 #define	OVERLAY_TARGET_ASYNC	2
191 extern int overlay_target_lookup(overlay_dev_t *, mblk_t *, struct sockaddr *,
192     socklen_t *);
193 extern void overlay_target_quiesce(overlay_target_t *);
194 extern void overlay_target_fini(void);
195 
196 extern void overlay_fm_init(void);
197 extern void overlay_fm_fini(void);
198 extern void overlay_fm_degrade(overlay_dev_t *, const char *);
199 extern void overlay_fm_restore(overlay_dev_t *);
200 
201 extern overlay_dev_t *overlay_hold_by_dlid(datalink_id_t);
202 extern void overlay_hold_rele(overlay_dev_t *);
203 
204 #ifdef __cplusplus
205 }
206 #endif
207 
208 #endif /* _SYS_OVERLAY_IMPL_H */
209