xref: /titanic_41/usr/src/uts/common/sys/mac_provider.h (revision 5547f1d8c68fa119522b859bbf38315dc773e696)
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_MAC_PROVIDER_H
28 #define	_SYS_MAC_PROVIDER_H
29 
30 #include <sys/types.h>
31 #include <sys/ddi.h>
32 #include <sys/sunddi.h>
33 #include <sys/stream.h>
34 #include <sys/mac_flow.h>
35 #include <sys/mac.h>
36 
37 /*
38  * MAC Provider Interface
39  */
40 
41 #ifdef	__cplusplus
42 extern "C" {
43 #endif
44 
45 /*
46  * MAC version identifier.  This is used by mac_alloc() mac_register() to
47  * verify that incompatible drivers don't register.
48  */
49 #define	MAC_VERSION	0x2
50 
51 /*
52  * Opaque handle types
53  */
54 typedef struct __mac_rule_handle	*mac_rule_handle_t;
55 
56 /*
57  * Statistics
58  */
59 
60 #define	XCVR_UNDEFINED		0
61 #define	XCVR_NONE		1
62 #define	XCVR_10			2
63 #define	XCVR_100T4		3
64 #define	XCVR_100X		4
65 #define	XCVR_100T2		5
66 #define	XCVR_1000X		6
67 #define	XCVR_1000T		7
68 
69 #ifdef	_KERNEL
70 
71 /*
72  * Definitions for MAC Drivers Capabilities
73  */
74 /*
75  * MAC layer capabilities.  These capabilities are handled by the drivers'
76  * mc_capab_get() callbacks.  Some capabilities require the driver to fill
77  * in a given data structure, and others are simply boolean capabilities.
78  * Note that capability values must be powers of 2 so that consumers and
79  * providers of this interface can keep track of which capabilities they
80  * care about by keeping a bitfield of these things around somewhere.
81  */
82 typedef enum {
83 	/*
84 	 * Capabilities reserved for internal use only
85 	 */
86 	MAC_CAPAB_VNIC		= 0x0001, /* data is mac_capab_vnic_t */
87 	MAC_CAPAB_ANCHOR_VNIC	= 0x0002, /* boolean only, no data */
88 	MAC_CAPAB_AGGR		= 0x0004, /* data is mac_capab_aggr_t */
89 	MAC_CAPAB_NO_NATIVEVLAN	= 0x0008, /* boolean only, no data */
90 	MAC_CAPAB_NO_ZCOPY	= 0x0010, /* boolean only, no data */
91 	MAC_CAPAB_LEGACY	= 0x0020, /* data is mac_capab_legacy_t */
92 
93 	/*
94 	 * Public Capabilities
95 	 */
96 	MAC_CAPAB_HCKSUM	= 0x0100, /* data is a uint32_t */
97 	MAC_CAPAB_LSO		= 0x0200, /* data is mac_capab_lso_t */
98 	MAC_CAPAB_RINGS		= 0x0400, /* data is mac_capab_rings_t */
99 	MAC_CAPAB_MULTIFACTADDR = 0x0800, /* mac_data_multifactaddr_t */
100 	MAC_CAPAB_SHARES	= 0x1000 /* data is mac_capab_share_t */
101 
102 	/* add new capabilities here */
103 } mac_capab_t;
104 
105 
106 /*
107  * LSO capability
108  */
109 typedef struct lso_basic_tcp_ipv4_s {
110 	t_uscalar_t	lso_max;		/* maximum payload */
111 } lso_basic_tcp_ipv4_t;
112 
113 /*
114  * Currently supported flags for LSO.
115  */
116 #define	LSO_TX_BASIC_TCP_IPV4	0x01		/* TCP LSO capability */
117 
118 /*
119  * Future LSO capabilities can be added at the end of the mac_capab_lso_t.
120  * When such capability is added to the GLDv3 framework, the size of the
121  * mac_capab_lso_t it allocates and passes to the drivers increases. Older
122  * drivers wil access only the (upper) sections of that structure, that is the
123  * sections carrying the capabilities they understand. This ensures the
124  * interface can be safely extended in a binary compatible way.
125  */
126 typedef	struct mac_capab_lso_s {
127 	t_uscalar_t		lso_flags;
128 	lso_basic_tcp_ipv4_t	lso_basic_tcp_ipv4;
129 	/* Add future lso capabilities here */
130 } mac_capab_lso_t;
131 
132 /*
133  * Multiple Factory MAC Addresses Capability
134  */
135 typedef struct mac_capab_multifactaddr_s {
136 	/*
137 	 * Number of factory addresses
138 	 */
139 	uint_t		mcm_naddr;
140 
141 	/*
142 	 * Callbacks to query all the factory addresses.
143 	 */
144 	void		(*mcm_getaddr)(void *, uint_t, uint8_t *);
145 } mac_capab_multifactaddr_t;
146 
147 /*
148  * Info and callbacks of legacy devices.
149  */
150 typedef struct mac_capab_legacy_s {
151 	/*
152 	 * Notifications that the legacy device does not support.
153 	 */
154 	uint32_t	ml_unsup_note;
155 	/*
156 	 * dev_t of the legacy device; can be held to force attach.
157 	 */
158 	dev_t		ml_dev;
159 	boolean_t	(*ml_active_set)(void *);
160 	void		(*ml_active_clear)(void *);
161 	int		(*ml_fastpath_disable)(void *);
162 	void		(*ml_fastpath_enable)(void *);
163 } mac_capab_legacy_t;
164 
165 /*
166  * MAC driver entry point types.
167  */
168 typedef int		(*mac_getstat_t)(void *, uint_t, uint64_t *);
169 typedef	int		(*mac_start_t)(void *);
170 typedef void		(*mac_stop_t)(void *);
171 typedef int		(*mac_setpromisc_t)(void *, boolean_t);
172 typedef int		(*mac_multicst_t)(void *, boolean_t, const uint8_t *);
173 typedef int		(*mac_unicst_t)(void *, const uint8_t *);
174 typedef void		(*mac_ioctl_t)(void *, queue_t *, mblk_t *);
175 typedef void		(*mac_resources_t)(void *);
176 typedef mblk_t		*(*mac_tx_t)(void *, mblk_t *);
177 typedef	boolean_t	(*mac_getcapab_t)(void *, mac_capab_t, void *);
178 typedef	int		(*mac_open_t)(void *);
179 typedef void		(*mac_close_t)(void *);
180 typedef	int		(*mac_set_prop_t)(void *, const char *, mac_prop_id_t,
181 			    uint_t, const void *);
182 typedef	int		(*mac_get_prop_t)(void *, const char *, mac_prop_id_t,
183 			    uint_t, uint_t, void *, uint_t *);
184 
185 /*
186  * Drivers must set all of these callbacks except for mc_resources,
187  * mc_ioctl, and mc_getcapab, which are optional.  If any of these optional
188  * callbacks are set, their appropriate flags must be set in mc_callbacks.
189  * Any future additions to this list must also be accompanied by an
190  * associated mc_callbacks flag so that the framework can grow without
191  * affecting the binary compatibility of the interface.
192  */
193 typedef struct mac_callbacks_s {
194 	uint_t		mc_callbacks;	/* Denotes which callbacks are set */
195 	mac_getstat_t	mc_getstat;	/* Get the value of a statistic */
196 	mac_start_t	mc_start;	/* Start the device */
197 	mac_stop_t	mc_stop;	/* Stop the device */
198 	mac_setpromisc_t mc_setpromisc;	/* Enable or disable promiscuous mode */
199 	mac_multicst_t	mc_multicst;	/* Enable or disable a multicast addr */
200 	mac_unicst_t	mc_unicst;	/* Set the unicast MAC address */
201 	mac_tx_t	mc_tx;		/* Transmit a packet */
202 	mac_ioctl_t	mc_ioctl;	/* Process an unknown ioctl */
203 	mac_getcapab_t	mc_getcapab;	/* Get capability information */
204 	mac_open_t	mc_open;	/* Open the device */
205 	mac_close_t	mc_close;	/* Close the device */
206 	mac_set_prop_t	mc_setprop;
207 	mac_get_prop_t	mc_getprop;
208 } mac_callbacks_t;
209 
210 typedef struct mac_priv_prop_s {
211 	char	mpp_name[MAXLINKPROPNAME];
212 	uint_t	mpp_flags;
213 } mac_priv_prop_t;
214 
215 /*
216  * Virtualization Capabilities
217  */
218 /*
219  * The ordering of entries below is important. MAC_HW_CLASSIFIER
220  * is the cutoff below which are entries which don't depend on
221  * H/W. MAC_HW_CLASSIFIER and entries after that are cases where
222  * H/W has been updated through add/modify/delete APIs.
223  */
224 typedef enum {
225 	MAC_NO_CLASSIFIER = 0,
226 	MAC_SW_CLASSIFIER,
227 	MAC_HW_CLASSIFIER
228 } mac_classify_type_t;
229 
230 typedef	void	(*mac_rx_func_t)(void *, mac_resource_handle_t, mblk_t *,
231     boolean_t);
232 
233 /*
234  * The virtualization level conveys the extent of the NIC hardware assistance
235  * for traffic steering employed for virtualization:
236  *
237  * MAC_VIRT_NONE:	No assist for v12n.
238  *
239  * MAC_VIRT_LEVEL1:	Multiple Rx rings with MAC address level
240  *			classification between groups of rings.
241  *			Requires the support of the MAC_CAPAB_RINGS
242  *			capability.
243  *
244  * MAC_VIRT_HIO:	Hybrid I/O capable MAC. Require the support
245  *			of the MAC_CAPAB_SHARES capability.
246  *
247  * MAC_VIRT_SERIALIZE:	Temporary flag *ONLY* for nxge. Mac layer
248  *			uses this to enable mac Tx serializer on
249  *			outbound traffic and to always enqueue
250  * 			incoming traffic on Rx soft rings in mac.
251  */
252 #define	MAC_VIRT_NONE		0x0
253 #define	MAC_VIRT_LEVEL1		0x1
254 #define	MAC_VIRT_HIO		0x2
255 #define	MAC_VIRT_SERIALIZE	0x4
256 
257 typedef enum {
258 	MAC_RING_TYPE_RX = 1,	/* Receive ring */
259 	MAC_RING_TYPE_TX	/* Transmit ring */
260 } mac_ring_type_t;
261 
262 #define	MAX_RINGS_PER_GROUP	128
263 
264 /*
265  * Grouping type of a ring group
266  *
267  * MAC_GROUP_TYPE_STATIC: The ring group can not be re-grouped.
268  * MAC_GROUP_TYPE_DYNAMIC: The ring group support dynamic re-grouping
269  */
270 typedef enum {
271 	MAC_GROUP_TYPE_STATIC = 1,	/* Static ring group */
272 	MAC_GROUP_TYPE_DYNAMIC		/* Dynamic ring group */
273 } mac_group_type_t;
274 
275 typedef	struct __mac_ring_driver	*mac_ring_driver_t;
276 typedef	struct __mac_group_driver	*mac_group_driver_t;
277 
278 typedef	struct mac_ring_info_s mac_ring_info_t;
279 typedef	struct mac_group_info_s mac_group_info_t;
280 
281 typedef void	(*mac_get_ring_t)(void *, mac_ring_type_t, const int, const int,
282     mac_ring_info_t *, mac_ring_handle_t);
283 typedef void	(*mac_get_group_t)(void *, mac_ring_type_t, const int,
284     mac_group_info_t *, mac_group_handle_t);
285 
286 typedef void	(*mac_group_add_ring_t)(mac_group_driver_t,
287     mac_ring_driver_t, mac_ring_type_t);
288 typedef void	(*mac_group_rem_ring_t)(mac_group_driver_t,
289     mac_ring_driver_t, mac_ring_type_t);
290 
291 /*
292  * Multiple Rings Capability
293  */
294 typedef struct	mac_capab_rings_s {
295 	mac_ring_type_t		mr_type;	/* Ring type: Rx vs Tx */
296 	mac_group_type_t	mr_group_type;	/* Dynamic vs static grouping */
297 	uint_t			mr_rnum;	/* Number of rings */
298 	uint_t			mr_gnum;	/* Number of ring groups */
299 	mac_get_ring_t		mr_rget;	/* Get ring from driver */
300 	mac_get_group_t		mr_gget;	/* Get ring group from driver */
301 	mac_group_add_ring_t	mr_gaddring;	/* Add ring into a group */
302 	mac_group_rem_ring_t	mr_gremring;	/* Remove ring from a group */
303 } mac_capab_rings_t;
304 
305 /*
306  * Common ring functions and driver interfaces
307  */
308 typedef	int	(*mac_ring_start_t)(mac_ring_driver_t, uint64_t);
309 typedef	void	(*mac_ring_stop_t)(mac_ring_driver_t);
310 
311 typedef	mblk_t	*(*mac_ring_send_t)(void *, mblk_t *);
312 typedef	mblk_t	*(*mac_ring_poll_t)(void *, int);
313 
314 typedef struct mac_ring_info_s {
315 	mac_ring_driver_t	mri_driver;
316 	mac_ring_start_t	mri_start;
317 	mac_ring_stop_t		mri_stop;
318 	mac_intr_t		mri_intr;
319 	union {
320 		mac_ring_send_t	send;
321 		mac_ring_poll_t	poll;
322 	} mrfunion;
323 } mac_ring_info_s;
324 
325 #define	mri_tx			mrfunion.send
326 #define	mri_poll		mrfunion.poll
327 
328 typedef	int	(*mac_group_start_t)(mac_group_driver_t);
329 typedef	void	(*mac_group_stop_t)(mac_group_driver_t);
330 typedef	int	(*mac_add_mac_addr_t)(void *, const uint8_t *);
331 typedef	int	(*mac_rem_mac_addr_t)(void *, const uint8_t *);
332 
333 struct mac_group_info_s {
334 	mac_group_driver_t	mgi_driver;	/* Driver reference */
335 	mac_group_start_t	mgi_start;	/* Start the group */
336 	mac_group_stop_t	mgi_stop;	/* Stop the group */
337 	uint_t			mgi_count;	/* Count of rings */
338 	mac_intr_t		mgi_intr;	/* Optional per-group intr */
339 
340 	/* Only used for rx groups */
341 	mac_add_mac_addr_t	mgi_addmac;	/* Add a MAC address */
342 	mac_rem_mac_addr_t	mgi_remmac;	/* Remove a MAC address */
343 };
344 
345 /*
346  * Share management functions.
347  */
348 typedef uint64_t mac_share_handle_t;
349 
350 /*
351  * Allocate and free a share. Returns ENOSPC if all shares have been
352  * previously allocated.
353  */
354 typedef int (*mac_alloc_share_t)(void *, mac_share_handle_t *);
355 typedef void (*mac_free_share_t)(mac_share_handle_t);
356 
357 /*
358  * Bind and unbind a share. Binding a share allows a domain
359  * to have direct access to the groups and rings associated with
360  * that share.
361  */
362 typedef int (*mac_bind_share_t)(mac_share_handle_t, uint64_t, uint64_t *);
363 typedef void (*mac_unbind_share_t)(mac_share_handle_t);
364 
365 /*
366  * Return information on about a share.
367  */
368 typedef void (*mac_share_query_t)(mac_share_handle_t, mac_ring_type_t,
369     mac_ring_handle_t *, uint_t *);
370 
371 /*
372  * Basic idea, bind previously created ring groups to shares
373  * for them to be exported (or shared) by another domain.
374  * These interfaces bind/unbind the ring group to a share.
375  * The groups and their rings will be shared with the guest
376  * as soon as the share is bound.
377  */
378 typedef int (*mac_share_add_group_t)(mac_share_handle_t,
379     mac_group_driver_t);
380 typedef int (*mac_share_rem_group_t)(mac_share_handle_t,
381     mac_group_driver_t);
382 
383 typedef struct  mac_capab_share_s {
384 	uint_t			ms_snum;	/* Number of shares (vr's) */
385 	void			*ms_handle;	/* Handle to driver. */
386 	mac_alloc_share_t	ms_salloc;	/* Get a share from driver. */
387 	mac_free_share_t	ms_sfree;	/* Return a share to driver. */
388 	mac_share_add_group_t	ms_sadd;	/* Add a group to the share. */
389 	mac_share_rem_group_t	ms_sremove;	/* Remove group from share. */
390 	mac_share_query_t	ms_squery;	/* Query share constraints */
391 	mac_bind_share_t	ms_sbind;	/* Bind a share */
392 	mac_unbind_share_t	ms_sunbind;	/* Unbind a share */
393 } mac_capab_share_t;
394 
395 /*
396  * MAC registration interface
397  */
398 typedef struct mac_register_s {
399 	uint_t			m_version;	/* set by mac_alloc() */
400 	const char		*m_type_ident;
401 	void			*m_driver;	/* Driver private data */
402 	dev_info_t		*m_dip;
403 	uint_t			m_instance;
404 	uint8_t			*m_src_addr;
405 	uint8_t			*m_dst_addr;
406 	mac_callbacks_t		*m_callbacks;
407 	uint_t			m_min_sdu;
408 	uint_t			m_max_sdu;
409 	void			*m_pdata;
410 	size_t			m_pdata_size;
411 	uint32_t		m_margin;
412 	mac_priv_prop_t		*m_priv_props;
413 	size_t			m_priv_prop_count;
414 	uint32_t		m_v12n;		/* Virtualization level */
415 } mac_register_t;
416 
417 /*
418  * Flags for mc_callbacks.  Requiring drivers to set the flags associated
419  * with optional callbacks initialized in the structure allows the mac
420  * module to add optional callbacks in the future without requiring drivers
421  * to recompile.
422  */
423 #define	MC_IOCTL	0x001
424 #define	MC_GETCAPAB	0x002
425 #define	MC_OPEN		0x004
426 #define	MC_CLOSE	0x008
427 #define	MC_SETPROP	0x010
428 #define	MC_GETPROP	0x020
429 
430 /*
431  * Driver interface functions.
432  */
433 extern void			mac_sdu_get(mac_handle_t, uint_t *, uint_t *);
434 extern int			mac_maxsdu_update(mac_handle_t, uint_t);
435 
436 extern mac_register_t		*mac_alloc(uint_t);
437 extern void			mac_free(mac_register_t *);
438 extern int			mac_register(mac_register_t *, mac_handle_t *);
439 extern int			mac_disable_nowait(mac_handle_t);
440 extern int			mac_disable(mac_handle_t);
441 extern int  			mac_unregister(mac_handle_t);
442 extern void 			mac_rx(mac_handle_t, mac_resource_handle_t,
443 				    mblk_t *);
444 extern void 			mac_rx_ring(mac_handle_t, mac_ring_handle_t,
445 				    mblk_t *, uint64_t);
446 extern void 			mac_link_update(mac_handle_t, link_state_t);
447 extern void 			mac_unicst_update(mac_handle_t,
448 				    const uint8_t *);
449 extern void			mac_tx_update(mac_handle_t);
450 extern void			mac_tx_ring_update(mac_handle_t,
451 				    mac_ring_handle_t);
452 extern void			mac_capab_update(mac_handle_t);
453 extern int			mac_pdata_update(mac_handle_t, void *,
454 				    size_t);
455 extern void			mac_multicast_refresh(mac_handle_t,
456 				    mac_multicst_t, void *, boolean_t);
457 extern void			mac_unicst_refresh(mac_handle_t, mac_unicst_t,
458 				    void *);
459 extern void			mac_promisc_refresh(mac_handle_t,
460 				    mac_setpromisc_t, void *);
461 extern boolean_t		mac_margin_update(mac_handle_t, uint32_t);
462 extern void			mac_margin_get(mac_handle_t, uint32_t *);
463 extern int			mac_margin_remove(mac_handle_t, uint32_t);
464 extern int			mac_margin_add(mac_handle_t, uint32_t *,
465 				    boolean_t);
466 extern void			mac_init_ops(struct dev_ops *, const char *);
467 extern void			mac_fini_ops(struct dev_ops *);
468 
469 extern mactype_register_t	*mactype_alloc(uint_t);
470 extern void			mactype_free(mactype_register_t *);
471 extern int			mactype_register(mactype_register_t *);
472 extern int			mactype_unregister(const char *);
473 
474 extern boolean_t		mac_unicst_verify(mac_handle_t,
475 				    const uint8_t *, uint_t);
476 
477 extern int			mac_group_add_ring(mac_group_handle_t, int);
478 extern void			mac_group_rem_ring(mac_group_handle_t,
479 				    mac_ring_handle_t);
480 
481 #endif	/* _KERNEL */
482 
483 #ifdef	__cplusplus
484 }
485 #endif
486 
487 #endif /* _SYS_MAC_PROVIDER_H */
488