Merge commit '7e3488dc6cdcb0c04e1ce167a1a3bfef83b5f2e0'
[unleashed.git] / include / sys / mac_provider.h
blob4c91c039678d3bfd0612e3bda26728dabd8aaf37
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
23 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright (c) 2017, Joyent, Inc.
27 #ifndef _SYS_MAC_PROVIDER_H
28 #define _SYS_MAC_PROVIDER_H
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.h>
36 #include <sys/mac_flow.h>
39 * MAC Provider Interface
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
47 * MAC version identifiers. Drivers compiled against the stable V1 version
48 * of the API should register with MAC_VERSION_V1. ON drivers should use
49 * MAC_VERSION. This is used by mac_alloc() mac_register() to
50 * verify that incompatible drivers don't register.
52 #define MAC_VERSION_V1 0x1
53 #define MAC_VERSION MAC_VERSION_V1
56 * Possible values for ETHER_STAT_XCVR_INUSE statistic.
59 #define XCVR_UNDEFINED 0
60 #define XCVR_NONE 1
61 #define XCVR_10 2
62 #define XCVR_100T4 3
63 #define XCVR_100X 4
64 #define XCVR_100T2 5
65 #define XCVR_1000X 6
66 #define XCVR_1000T 7
68 #ifdef _KERNEL
71 * Definitions for MAC Drivers Capabilities
74 * MAC layer capabilities. These capabilities are handled by the drivers'
75 * mc_capab_get() callbacks. Some capabilities require the driver to fill
76 * in a given data structure, and others are simply boolean capabilities.
77 * Note that capability values must be powers of 2 so that consumers and
78 * providers of this interface can keep track of which capabilities they
79 * care about by keeping a bitfield of these things around somewhere.
81 typedef enum {
83 * Public Capabilities (MAC_VERSION_V1)
85 MAC_CAPAB_HCKSUM = 0x00000001, /* data is a uint32_t */
86 MAC_CAPAB_LSO = 0x00000008, /* data is mac_capab_lso_t */
89 * Reserved capabilities, do not use
91 MAC_CAPAB_RESERVED1 = 0x00000002,
92 MAC_CAPAB_RESERVED2 = 0x00000004,
95 * Private driver capabilities
97 MAC_CAPAB_RINGS = 0x00000010, /* data is mac_capab_rings_t */
98 MAC_CAPAB_SHARES = 0x00000020, /* data is mac_capab_share_t */
99 MAC_CAPAB_MULTIFACTADDR = 0x00000040, /* mac_data_multifactaddr_t */
102 * Private driver capabilities for use by the GLDv3 framework only
104 MAC_CAPAB_VNIC = 0x00010000, /* data is mac_capab_vnic_t */
105 MAC_CAPAB_ANCHOR_VNIC = 0x00020000, /* boolean only, no data */
106 MAC_CAPAB_AGGR = 0x00040000, /* data is mac_capab_aggr_t */
107 MAC_CAPAB_NO_NATIVEVLAN = 0x00080000, /* boolean only, no data */
108 MAC_CAPAB_NO_ZCOPY = 0x00100000, /* boolean only, no data */
109 MAC_CAPAB_LEGACY = 0x00200000, /* data is mac_capab_legacy_t */
110 MAC_CAPAB_VRRP = 0x00400000, /* data is mac_capab_vrrp_t */
111 MAC_CAPAB_TRANSCEIVER = 0x01000000, /* mac_capab_transciever_t */
112 MAC_CAPAB_LED = 0x02000000 /* data is mac_capab_led_t */
113 } mac_capab_t;
116 * LSO capability
118 typedef struct lso_basic_tcp_ipv4_s {
119 t_uscalar_t lso_max; /* maximum payload */
120 } lso_basic_tcp_ipv4_t;
123 * Currently supported flags for LSO.
125 #define LSO_TX_BASIC_TCP_IPV4 0x01 /* TCP LSO capability */
128 * Future LSO capabilities can be added at the end of the mac_capab_lso_t.
129 * When such capability is added to the GLDv3 framework, the size of the
130 * mac_capab_lso_t it allocates and passes to the drivers increases. Older
131 * drivers wil access only the (upper) sections of that structure, that is the
132 * sections carrying the capabilities they understand. This ensures the
133 * interface can be safely extended in a binary compatible way.
135 typedef struct mac_capab_lso_s {
136 t_uscalar_t lso_flags;
137 lso_basic_tcp_ipv4_t lso_basic_tcp_ipv4;
138 /* Add future lso capabilities here */
139 } mac_capab_lso_t;
142 * Multiple Factory MAC Addresses Capability
144 typedef struct mac_capab_multifactaddr_s {
146 * Number of factory addresses
148 uint_t mcm_naddr;
151 * Callbacks to query all the factory addresses.
153 void (*mcm_getaddr)(void *, uint_t, uint8_t *);
154 } mac_capab_multifactaddr_t;
157 * Info and callbacks of legacy devices.
159 typedef struct mac_capab_legacy_s {
161 * Notifications that the legacy device does not support.
163 uint32_t ml_unsup_note;
165 * dev_t of the legacy device; can be held to force attach.
167 dev_t ml_dev;
168 boolean_t (*ml_active_set)(void *);
169 void (*ml_active_clear)(void *);
170 int (*ml_fastpath_disable)(void *);
171 void (*ml_fastpath_enable)(void *);
172 } mac_capab_legacy_t;
174 typedef struct __mac_prop_info_handle *mac_prop_info_handle_t;
177 * MAC driver entry point types.
179 typedef int (*mac_getstat_t)(void *, uint_t, uint64_t *);
180 typedef int (*mac_start_t)(void *);
181 typedef void (*mac_stop_t)(void *);
182 typedef int (*mac_setpromisc_t)(void *, boolean_t);
183 typedef int (*mac_multicst_t)(void *, boolean_t, const uint8_t *);
184 typedef int (*mac_unicst_t)(void *, const uint8_t *);
185 typedef void (*mac_ioctl_t)(void *, queue_t *, mblk_t *);
186 typedef void (*mac_resources_t)(void *);
187 typedef mblk_t *(*mac_tx_t)(void *, mblk_t *);
188 typedef boolean_t (*mac_getcapab_t)(void *, mac_capab_t, void *);
189 typedef int (*mac_open_t)(void *);
190 typedef void (*mac_close_t)(void *);
191 typedef int (*mac_set_prop_t)(void *, const char *, mac_prop_id_t,
192 uint_t, const void *);
193 typedef int (*mac_get_prop_t)(void *, const char *, mac_prop_id_t,
194 uint_t, void *);
195 typedef void (*mac_prop_info_t)(void *, const char *, mac_prop_id_t,
196 mac_prop_info_handle_t);
199 * Driver callbacks. The following capabilities are optional, and if
200 * implemented by the driver, must have a corresponding MC_ flag set
201 * in the mc_callbacks field.
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.
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 void *mc_reserved; /* Reserved, do not use */
217 mac_ioctl_t mc_ioctl; /* Process an unknown ioctl */
218 mac_getcapab_t mc_getcapab; /* Get capability information */
219 mac_open_t mc_open; /* Open the device */
220 mac_close_t mc_close; /* Close the device */
221 mac_set_prop_t mc_setprop;
222 mac_get_prop_t mc_getprop;
223 mac_prop_info_t mc_propinfo;
224 } mac_callbacks_t;
227 * Flags for mc_callbacks. Requiring drivers to set the flags associated
228 * with optional callbacks initialized in the structure allows the mac
229 * module to add optional callbacks in the future without requiring drivers
230 * to recompile.
232 #define MC_RESERVED 0x0001
233 #define MC_IOCTL 0x0002
234 #define MC_GETCAPAB 0x0004
235 #define MC_OPEN 0x0008
236 #define MC_CLOSE 0x0010
237 #define MC_SETPROP 0x0020
238 #define MC_GETPROP 0x0040
239 #define MC_PROPINFO 0x0080
240 #define MC_PROPERTIES (MC_SETPROP | MC_GETPROP | MC_PROPINFO)
243 * Virtualization Capabilities
246 * The ordering of entries below is important. MAC_HW_CLASSIFIER
247 * is the cutoff below which are entries which don't depend on
248 * H/W. MAC_HW_CLASSIFIER and entries after that are cases where
249 * H/W has been updated through add/modify/delete APIs.
251 typedef enum {
252 MAC_NO_CLASSIFIER = 0,
253 MAC_SW_CLASSIFIER,
254 MAC_HW_CLASSIFIER
255 } mac_classify_type_t;
257 typedef void (*mac_rx_func_t)(void *, mac_resource_handle_t, mblk_t *,
258 boolean_t);
261 * The virtualization level conveys the extent of the NIC hardware assistance
262 * for traffic steering employed for virtualization:
264 * MAC_VIRT_NONE: No assist for v12n.
266 * MAC_VIRT_LEVEL1: Multiple Rx rings with MAC address level
267 * classification between groups of rings.
268 * Requires the support of the MAC_CAPAB_RINGS
269 * capability.
271 * MAC_VIRT_HIO: Hybrid I/O capable MAC. Require the support
272 * of the MAC_CAPAB_SHARES capability.
274 #define MAC_VIRT_NONE 0x0
275 #define MAC_VIRT_LEVEL1 0x1
276 #define MAC_VIRT_HIO 0x2
278 typedef enum {
279 MAC_RING_TYPE_RX = 1, /* Receive ring */
280 MAC_RING_TYPE_TX /* Transmit ring */
281 } mac_ring_type_t;
284 * Grouping type of a ring group
286 * MAC_GROUP_TYPE_STATIC: The ring group can not be re-grouped.
287 * MAC_GROUP_TYPE_DYNAMIC: The ring group support dynamic re-grouping
289 typedef enum {
290 MAC_GROUP_TYPE_STATIC = 1, /* Static ring group */
291 MAC_GROUP_TYPE_DYNAMIC /* Dynamic ring group */
292 } mac_group_type_t;
294 typedef struct __mac_ring_driver *mac_ring_driver_t;
295 typedef struct __mac_group_driver *mac_group_driver_t;
297 typedef struct mac_ring_info_s mac_ring_info_t;
298 typedef struct mac_group_info_s mac_group_info_t;
300 typedef void (*mac_get_ring_t)(void *, mac_ring_type_t, const int, const int,
301 mac_ring_info_t *, mac_ring_handle_t);
302 typedef void (*mac_get_group_t)(void *, mac_ring_type_t, const int,
303 mac_group_info_t *, mac_group_handle_t);
305 typedef void (*mac_group_add_ring_t)(mac_group_driver_t,
306 mac_ring_driver_t, mac_ring_type_t);
307 typedef void (*mac_group_rem_ring_t)(mac_group_driver_t,
308 mac_ring_driver_t, mac_ring_type_t);
311 * Multiple Rings Capability
313 typedef struct mac_capab_rings_s {
314 mac_ring_type_t mr_type; /* Ring type: Rx vs Tx */
315 mac_group_type_t mr_group_type; /* Dynamic vs static grouping */
316 uint_t mr_rnum; /* Number of rings */
317 uint_t mr_gnum; /* Number of ring groups */
318 mac_get_ring_t mr_rget; /* Get ring from driver */
319 mac_get_group_t mr_gget; /* Get ring group from driver */
320 mac_group_add_ring_t mr_gaddring; /* Add ring into a group */
321 mac_group_rem_ring_t mr_gremring; /* Remove ring from a group */
322 } mac_capab_rings_t;
325 * Common ring functions and driver interfaces
327 typedef int (*mac_ring_start_t)(mac_ring_driver_t, uint64_t);
328 typedef void (*mac_ring_stop_t)(mac_ring_driver_t);
330 typedef mblk_t *(*mac_ring_send_t)(void *, mblk_t *);
331 typedef mblk_t *(*mac_ring_poll_t)(void *, int);
333 typedef int (*mac_ring_stat_t)(mac_ring_driver_t, uint_t, uint64_t *);
335 typedef struct mac_ring_info_s {
336 mac_ring_driver_t mri_driver;
337 mac_ring_start_t mri_start;
338 mac_ring_stop_t mri_stop;
339 mac_intr_t mri_intr;
340 union {
341 mac_ring_send_t send;
342 mac_ring_poll_t poll;
343 } mrfunion;
344 mac_ring_stat_t mri_stat;
346 * mri_flags will have some bits set to indicate some special
347 * property/feature of a ring like serialization needed for a
348 * Tx ring or packets should always need enqueuing on Rx side,
349 * etc.
351 uint_t mri_flags;
352 } mac_ring_info_s;
354 #define mri_tx mrfunion.send
355 #define mri_poll mrfunion.poll
358 * #defines for mri_flags. The flags are temporary flags that are provided
359 * only to workaround issues in specific drivers, and they will be
360 * removed in the future.
362 #define MAC_RING_TX_SERIALIZE 0x1
363 #define MAC_RING_RX_ENQUEUE 0x2
365 typedef int (*mac_group_start_t)(mac_group_driver_t);
366 typedef void (*mac_group_stop_t)(mac_group_driver_t);
367 typedef int (*mac_add_mac_addr_t)(void *, const uint8_t *);
368 typedef int (*mac_rem_mac_addr_t)(void *, const uint8_t *);
370 struct mac_group_info_s {
371 mac_group_driver_t mgi_driver; /* Driver reference */
372 mac_group_start_t mgi_start; /* Start the group */
373 mac_group_stop_t mgi_stop; /* Stop the group */
374 uint_t mgi_count; /* Count of rings */
375 mac_intr_t mgi_intr; /* Optional per-group intr */
377 /* Only used for rx groups */
378 mac_add_mac_addr_t mgi_addmac; /* Add a MAC address */
379 mac_rem_mac_addr_t mgi_remmac; /* Remove a MAC address */
383 * Share management functions.
385 typedef uint64_t mac_share_handle_t;
388 * Allocate and free a share. Returns ENOSPC if all shares have been
389 * previously allocated.
391 typedef int (*mac_alloc_share_t)(void *, mac_share_handle_t *);
392 typedef void (*mac_free_share_t)(mac_share_handle_t);
395 * Bind and unbind a share. Binding a share allows a domain
396 * to have direct access to the groups and rings associated with
397 * that share.
399 typedef int (*mac_bind_share_t)(mac_share_handle_t, uint64_t, uint64_t *);
400 typedef void (*mac_unbind_share_t)(mac_share_handle_t);
403 * Return information on about a share.
405 typedef void (*mac_share_query_t)(mac_share_handle_t, mac_ring_type_t,
406 mac_ring_handle_t *, uint_t *);
409 * Basic idea, bind previously created ring groups to shares
410 * for them to be exported (or shared) by another domain.
411 * These interfaces bind/unbind the ring group to a share.
412 * The groups and their rings will be shared with the guest
413 * as soon as the share is bound.
415 typedef int (*mac_share_add_group_t)(mac_share_handle_t,
416 mac_group_driver_t);
417 typedef int (*mac_share_rem_group_t)(mac_share_handle_t,
418 mac_group_driver_t);
420 typedef struct mac_capab_share_s {
421 uint_t ms_snum; /* Number of shares (vr's) */
422 void *ms_handle; /* Handle to driver. */
423 mac_alloc_share_t ms_salloc; /* Get a share from driver. */
424 mac_free_share_t ms_sfree; /* Return a share to driver. */
425 mac_share_add_group_t ms_sadd; /* Add a group to the share. */
426 mac_share_rem_group_t ms_sremove; /* Remove group from share. */
427 mac_share_query_t ms_squery; /* Query share constraints */
428 mac_bind_share_t ms_sbind; /* Bind a share */
429 mac_unbind_share_t ms_sunbind; /* Unbind a share */
430 } mac_capab_share_t;
432 typedef struct mac_capab_vrrp_s {
433 /* IPv6 or IPv4? */
434 int mcv_af;
435 } mac_capab_vrrp_t;
438 * Transceiver capability
440 typedef struct mac_transceiver_info mac_transceiver_info_t;
442 typedef struct mac_capab_transceiver {
443 uint_t mct_flags;
444 uint_t mct_ntransceivers;
445 int (*mct_info)(void *, uint_t, mac_transceiver_info_t *);
446 int (*mct_read)(void *, uint_t, uint_t, void *, size_t, off_t,
447 size_t *);
448 } mac_capab_transceiver_t;
451 * LED capability
453 typedef struct mac_capab_led {
454 uint_t mcl_flags;
455 mac_led_mode_t mcl_modes;
456 int (*mcl_set)(void *, mac_led_mode_t, uint_t);
457 } mac_capab_led_t;
460 * MAC registration interface
462 typedef struct mac_register_s {
463 uint_t m_version; /* set by mac_alloc() */
464 const char *m_type_ident;
465 void *m_driver; /* Driver private data */
466 dev_info_t *m_dip;
467 uint_t m_instance;
468 uint8_t *m_src_addr;
469 uint8_t *m_dst_addr;
470 mac_callbacks_t *m_callbacks;
471 uint_t m_min_sdu;
472 uint_t m_max_sdu;
473 void *m_pdata;
474 size_t m_pdata_size;
475 char **m_priv_props;
476 uint32_t m_margin;
477 uint32_t m_v12n; /* Virtualization level */
478 uint_t m_multicast_sdu;
479 } mac_register_t;
482 * Driver interface functions.
484 extern mac_protect_t *mac_protect_get(mac_handle_t);
485 extern void mac_sdu_get(mac_handle_t, uint_t *, uint_t *);
486 extern void mac_sdu_get2(mac_handle_t, uint_t *, uint_t *,
487 uint_t *);
488 extern int mac_maxsdu_update(mac_handle_t, uint_t);
489 extern int mac_maxsdu_update2(mac_handle_t, uint_t,
490 uint_t);
492 extern mac_register_t *mac_alloc(uint_t);
493 extern void mac_free(mac_register_t *);
494 extern int mac_register(mac_register_t *, mac_handle_t *);
495 extern int mac_disable_nowait(mac_handle_t);
496 extern int mac_disable(mac_handle_t);
497 extern int mac_unregister(mac_handle_t);
498 extern void mac_rx(mac_handle_t, mac_resource_handle_t,
499 mblk_t *);
500 extern void mac_rx_ring(mac_handle_t, mac_ring_handle_t,
501 mblk_t *, uint64_t);
502 extern void mac_link_update(mac_handle_t, link_state_t);
503 extern void mac_link_redo(mac_handle_t, link_state_t);
504 extern void mac_unicst_update(mac_handle_t,
505 const uint8_t *);
506 extern void mac_dst_update(mac_handle_t, const uint8_t *);
507 extern void mac_tx_update(mac_handle_t);
508 extern void mac_tx_ring_update(mac_handle_t,
509 mac_ring_handle_t);
510 extern void mac_capab_update(mac_handle_t);
511 extern int mac_pdata_update(mac_handle_t, void *,
512 size_t);
513 extern void mac_multicast_refresh(mac_handle_t,
514 mac_multicst_t, void *, boolean_t);
515 extern void mac_unicst_refresh(mac_handle_t, mac_unicst_t,
516 void *);
517 extern void mac_promisc_refresh(mac_handle_t,
518 mac_setpromisc_t, void *);
519 extern boolean_t mac_margin_update(mac_handle_t, uint32_t);
520 extern void mac_margin_get(mac_handle_t, uint32_t *);
521 extern int mac_margin_remove(mac_handle_t, uint32_t);
522 extern int mac_margin_add(mac_handle_t, uint32_t *,
523 boolean_t);
524 extern void mac_init_ops(struct dev_ops *, const char *);
525 extern void mac_fini_ops(struct dev_ops *);
526 extern int mac_devt_to_instance(dev_t);
527 extern minor_t mac_private_minor(void);
528 extern void mac_ring_intr_set(mac_ring_handle_t,
529 ddi_intr_handle_t);
532 extern mactype_register_t *mactype_alloc(uint_t);
533 extern void mactype_free(mactype_register_t *);
534 extern int mactype_register(mactype_register_t *);
535 extern int mactype_unregister(const char *);
537 extern boolean_t mac_unicst_verify(mac_handle_t,
538 const uint8_t *, uint_t);
540 extern int mac_group_add_ring(mac_group_handle_t, int);
541 extern void mac_group_rem_ring(mac_group_handle_t,
542 mac_ring_handle_t);
543 extern mac_ring_handle_t mac_find_ring(mac_group_handle_t, int);
545 extern void mac_prop_info_set_default_uint8(
546 mac_prop_info_handle_t, uint8_t);
547 extern void mac_prop_info_set_default_str(
548 mac_prop_info_handle_t, const char *);
549 extern void mac_prop_info_set_default_uint64(
550 mac_prop_info_handle_t, uint64_t);
551 extern void mac_prop_info_set_default_uint32(
552 mac_prop_info_handle_t, uint32_t);
553 extern void mac_prop_info_set_default_link_flowctrl(
554 mac_prop_info_handle_t, link_flowctrl_t);
555 extern void mac_prop_info_set_range_uint32(
556 mac_prop_info_handle_t,
557 uint32_t, uint32_t);
558 extern void mac_prop_info_set_perm(mac_prop_info_handle_t,
559 uint8_t);
561 extern void mac_hcksum_get(mblk_t *, uint32_t *,
562 uint32_t *, uint32_t *, uint32_t *,
563 uint32_t *);
564 extern void mac_hcksum_set(mblk_t *, uint32_t, uint32_t,
565 uint32_t, uint32_t, uint32_t);
567 extern void mac_lso_get(mblk_t *, uint32_t *, uint32_t *);
569 extern void mac_transceiver_info_set_present(
570 mac_transceiver_info_t *,
571 boolean_t);
572 extern void mac_transceiver_info_set_usable(
573 mac_transceiver_info_t *,
574 boolean_t);
576 #endif /* _KERNEL */
578 #ifdef __cplusplus
580 #endif
582 #endif /* _SYS_MAC_PROVIDER_H */