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