xref: /illumos-gate/usr/src/uts/common/sys/mac_client.h (revision a7cee4e9766ebda975dd156d1f10a70f51c242f0)
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 2010 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  * Copyright 2019 Joyent, Inc.
26  * Copyright 2026 Oxide Computer Company
27  */
28 
29 /*
30  * This file captures the MAC client API definitions. It can be
31  * included from any MAC clients.
32  */
33 
34 #ifndef	_SYS_MAC_CLIENT_H
35 #define	_SYS_MAC_CLIENT_H
36 
37 #include <sys/mac.h>
38 #include <sys/mac_flow.h>
39 
40 #ifdef	__cplusplus
41 extern "C" {
42 #endif
43 
44 #ifdef	_KERNEL
45 
46 /*
47  * MAC client interface.
48  */
49 
50 typedef struct __mac_client_handle *mac_client_handle_t;
51 typedef struct __mac_unicast_handle *mac_unicast_handle_t;
52 typedef struct __mac_promisc_handle *mac_promisc_handle_t;
53 typedef struct __mac_perim_handle *mac_perim_handle_t;
54 typedef uintptr_t mac_tx_cookie_t;
55 
56 typedef void (*mac_tx_notify_t)(void *, mac_tx_cookie_t);
57 
58 typedef enum {
59 	MAC_DIAG_NONE,
60 	MAC_DIAG_MACADDR_NIC,
61 	MAC_DIAG_MACADDR_INUSE,
62 	MAC_DIAG_MACADDR_INVALID,
63 	MAC_DIAG_MACADDRLEN_INVALID,
64 	MAC_DIAG_MACFACTORYSLOTINVALID,
65 	MAC_DIAG_MACFACTORYSLOTUSED,
66 	MAC_DIAG_MACFACTORYSLOTALLUSED,
67 	MAC_DIAG_MACFACTORYNOTSUP,
68 	MAC_DIAG_MACPREFIX_INVALID,
69 	MAC_DIAG_MACPREFIXLEN_INVALID,
70 	MAC_DIAG_MACNO_HWRINGS
71 } mac_diag_t;
72 
73 /*
74  * These are used when MAC clients what to specify tx and rx rings
75  * properties. MAC_RXRINGS_NONE/MAC_TXRINGS_NONE mean that we should
76  * not reserve any rings while MAC_RXRINGS_DONTCARE/MAC_TXRINGS_DONTCARE
77  * mean that the system can decide if it wants to reserve rings or
78  * not.
79  */
80 #define	MAC_RXRINGS_NONE	0
81 #define	MAC_TXRINGS_NONE	MAC_RXRINGS_NONE
82 #define	MAC_RXRINGS_DONTCARE	-1
83 #define	MAC_TXRINGS_DONTCARE	MAC_RXRINGS_DONTCARE
84 
85 typedef enum {
86 	MAC_CLIENT_PROMISC_ALL,
87 	MAC_CLIENT_PROMISC_FILTERED,
88 	MAC_CLIENT_PROMISC_MULTI
89 } mac_client_promisc_type_t;
90 
91 /* flags passed to mac_unicast_add() */
92 
93 #define	MAC_UNICAST_PRIMARY			0x0001
94 #define	MAC_UNICAST_HW				0x0002
95 #define	MAC_UNICAST_VNIC_PRIMARY		0x0004
96 #define	MAC_UNICAST_TAG_DISABLE			0x0008
97 #define	MAC_UNICAST_STRIP_DISABLE		0x0010
98 #define	MAC_UNICAST_DISABLE_TX_VID_CHECK	0x0020
99 
100 /* flags passed to mac_client_open */
101 #define	MAC_OPEN_FLAGS_IS_VNIC			0x0001
102 #define	MAC_OPEN_FLAGS_EXCLUSIVE		0x0002
103 #define	MAC_OPEN_FLAGS_IS_AGGR_PORT		0x0004
104 #define	MAC_OPEN_FLAGS_SHARES_DESIRED		0x0008
105 #define	MAC_OPEN_FLAGS_USE_DATALINK_NAME	0x0010
106 #define	MAC_OPEN_FLAGS_MULTI_PRIMARY		0x0020
107 #define	MAC_OPEN_FLAGS_NO_UNICAST_ADDR		0x0040
108 
109 /* flags passed to mac_client_close */
110 #define	MAC_CLOSE_FLAGS_IS_VNIC		0x0001
111 #define	MAC_CLOSE_FLAGS_EXCLUSIVE	0x0002
112 #define	MAC_CLOSE_FLAGS_IS_AGGR_PORT	0x0004
113 
114 /* flags passed to mac_promisc_add() */
115 #define	MAC_PROMISC_FLAGS_NO_TX_LOOP		0x0001
116 #define	MAC_PROMISC_FLAGS_NO_PHYS		0x0002
117 #define	MAC_PROMISC_FLAGS_VLAN_TAG_STRIP	0x0004
118 #define	MAC_PROMISC_FLAGS_NO_COPY		0x0008
119 #define	MAC_PROMISC_FLAGS_RX_ONLY		0x0010
120 #define	MAC_PROMISC_FLAGS_TX_ONLY		0x0020
121 
122 /* flags passed to mac_tx() */
123 #define	MAC_DROP_ON_NO_DESC	0x01 /* freemsg() if no tx descs */
124 #define	MAC_TX_NO_ENQUEUE	0x02 /* don't enqueue mblks if not xmit'ed */
125 #define	MAC_TX_NO_HOLD		0x04 /* don't bump the active Tx count */
126 
127 extern int mac_client_open(mac_handle_t, mac_client_handle_t *, char *,
128     uint16_t);
129 extern void mac_client_close(mac_client_handle_t, uint16_t);
130 
131 extern int mac_unicast_add(mac_client_handle_t, uint8_t *, uint16_t,
132     mac_unicast_handle_t *, uint16_t, mac_diag_t *);
133 extern int mac_unicast_add_set_rx(mac_client_handle_t, uint8_t *, uint16_t,
134     mac_unicast_handle_t *, uint16_t, mac_diag_t *, mac_rx_t, void *);
135 extern int mac_unicast_remove(mac_client_handle_t, mac_unicast_handle_t);
136 
137 extern int mac_multicast_add(mac_client_handle_t, const uint8_t *);
138 extern void mac_multicast_remove(mac_client_handle_t, const uint8_t *);
139 
140 extern void mac_rx_set(mac_client_handle_t, mac_rx_t, void *);
141 extern void mac_rx_clear(mac_client_handle_t);
142 extern void mac_rx_barrier(mac_client_handle_t);
143 extern void mac_secondary_dup(mac_client_handle_t, mac_client_handle_t);
144 extern void mac_secondary_cleanup(mac_client_handle_t);
145 extern mac_tx_cookie_t mac_tx(mac_client_handle_t, mblk_t *,
146     uintptr_t, uint16_t, mblk_t **);
147 extern boolean_t mac_tx_is_flow_blocked(mac_client_handle_t, mac_tx_cookie_t);
148 extern uint64_t mac_client_stat_get(mac_client_handle_t, uint_t);
149 
150 extern int mac_promisc_add(mac_client_handle_t, mac_client_promisc_type_t,
151     mac_rx_t, void *, mac_promisc_handle_t *, uint16_t);
152 extern void mac_promisc_remove(mac_promisc_handle_t);
153 
154 extern mac_notify_handle_t mac_notify_add(mac_handle_t, mac_notify_t, void *);
155 extern int mac_notify_remove(mac_notify_handle_t, boolean_t);
156 extern void mac_notify_remove_wait(mac_handle_t);
157 extern int mac_rename_primary(mac_handle_t, const char *);
158 extern char *mac_client_name(mac_client_handle_t);
159 
160 extern int mac_open(const char *, mac_handle_t *);
161 extern void mac_close(mac_handle_t);
162 extern uint64_t mac_stat_get(mac_handle_t, uint_t);
163 
164 extern int mac_unicast_primary_set(mac_handle_t, const uint8_t *);
165 extern void mac_unicast_primary_get(mac_handle_t, uint8_t *);
166 extern void mac_unicast_primary_info(mac_handle_t, char *, boolean_t *);
167 
168 extern void mac_unicast_secondary_get(mac_client_handle_t, uint8_t *);
169 
170 extern boolean_t mac_dst_get(mac_handle_t, uint8_t *);
171 
172 extern int mac_addr_random(mac_client_handle_t, uint_t, uint8_t *,
173     mac_diag_t *);
174 
175 extern int mac_addr_factory_reserve(mac_client_handle_t, int *);
176 extern void mac_addr_factory_release(mac_client_handle_t, uint_t);
177 extern void mac_addr_factory_value(mac_handle_t, int, uchar_t *, uint_t *,
178     char *, boolean_t *);
179 extern uint_t mac_addr_factory_num(mac_handle_t);
180 
181 extern mac_tx_notify_handle_t mac_client_tx_notify(mac_client_handle_t,
182     mac_tx_notify_t, void *);
183 
184 extern int mac_client_set_resources(mac_client_handle_t,
185     mac_resource_props_t *);
186 extern void mac_client_get_resources(mac_client_handle_t,
187     mac_resource_props_t *);
188 
189 /* bridging-related interfaces */
190 extern int mac_set_pvid(mac_handle_t, uint16_t);
191 extern uint16_t mac_get_pvid(mac_handle_t);
192 extern uint32_t mac_get_llimit(mac_handle_t);
193 extern uint32_t mac_get_ldecay(mac_handle_t);
194 
195 extern int mac_share_capable(mac_handle_t);
196 extern int mac_share_bind(mac_client_handle_t, uint64_t, uint64_t *);
197 extern void mac_share_unbind(mac_client_handle_t);
198 
199 extern int mac_set_mtu(mac_handle_t, uint_t, uint_t *);
200 
201 extern void mac_client_set_rings(mac_client_handle_t, int, int);
202 
203 extern void mac_hw_emul(mblk_t **, mblk_t **, uint_t *, mac_emul_t);
204 
205 #endif	/* _KERNEL */
206 
207 #ifdef	__cplusplus
208 }
209 #endif
210 
211 #endif /* _SYS_MAC_CLIENT_H */
212