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