FreeBSD/Linux Kernel Cross Reference
sys/net/if_media.h
1 /* $NetBSD: if_media.h,v 1.71 2020/03/15 23:04:51 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 1998, 2000, 2001, 2020 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 /*
34 * Copyright (c) 1997
35 * Jonathan Stone and Jason R. Thorpe. All rights reserved.
36 *
37 * This software is derived from information provided by Matt Thomas.
38 *
39 * Redistribution and use in source and binary forms, with or without
40 * modification, are permitted provided that the following conditions
41 * are met:
42 * 1. Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * 2. Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in the
46 * documentation and/or other materials provided with the distribution.
47 * 3. All advertising materials mentioning features or use of this software
48 * must display the following acknowledgement:
49 * This product includes software developed by Jonathan Stone
50 * and Jason R. Thorpe for the NetBSD Project.
51 * 4. The names of the authors may not be used to endorse or promote products
52 * derived from this software without specific prior written permission.
53 *
54 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
55 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
56 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
57 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
58 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
59 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
60 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
61 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
62 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 * SUCH DAMAGE.
65 */
66
67 #ifndef _NET_IF_MEDIA_H_
68 #define _NET_IF_MEDIA_H_
69
70 /*
71 * Prototypes and definitions for BSD/OS-compatible network interface
72 * media selection.
73 *
74 * Where it is safe to do so, this code strays slightly from the BSD/OS
75 * design. Software which uses the API (device drivers, basically)
76 * shouldn't notice any difference.
77 *
78 * Many thanks to Matt Thomas for providing the information necessary
79 * to implement this interface.
80 */
81
82 /*
83 * Status bits. THIS IS NOT A MEDIA WORD.
84 */
85 #define IFM_AVALID 0x00000001 /* Active bit valid */
86 #define IFM_ACTIVE 0x00000002 /* Interface attached to working net */
87
88 /*
89 * if_media Options word:
90 * Bits Use
91 * ---- -------
92 * 0-4 Media subtype MAX SUBTYPE == 255 for ETH and 31 for others
93 * See below (IFM_ETHER part) for the detail.
94 * 5-7 Media type
95 * 8-15 Type specific options
96 * 16-18 Mode (for multi-mode devices)
97 * 19 (Reserved for Future Use)
98 * 20-27 Shared (global) options
99 * 28-31 Instance
100 *
101 * 3 2 1
102 * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
103 * +-------+---------------+-+-----+---------------+-----+---------+
104 * | | |R| | | | |
105 * | IMASK | GMASK |F|MMASK+-----+ OMASK |NMASK| TMASK |
106 * | | |U| |XTMSK| | | |
107 * +-------+---------------+-+-----+-----+---------+-----+---------+
108 * <-----> <---> <--->
109 * IFM_INST() IFM_MODE() IFM_TYPE()
110 *
111 * IFM_SUBTYPE(other than ETH)<------->
112 *
113 * <---> IFM_SUBTYPE(ETH)<------->
114 *
115 *
116 * <-------------> <------------->
117 * IFM_OPTIONS()
118 */
119
120 /*
121 * Masks
122 */
123 #define IFM_NMASK 0x000000e0 /* Network type */
124 #define IFM_TMASK 0x0000001f /* Media sub-type */
125 #define IFM_IMASK 0xf0000000 /* Instance */
126 #define IFM_ISHIFT 28 /* Instance shift */
127 #define IFM_OMASK 0x0000ff00 /* Type specific options */
128 #define IFM_MMASK 0x00070000 /* Mode */
129 #define IFM_MSHIFT 16 /* Mode shift */
130 #define IFM_GMASK 0x0ff00000 /* Global options */
131
132 /*
133 * Macros to extract various bits of information from the media word.
134 */
135 #define IFM_TYPE(x) ((x) & IFM_NMASK)
136 #define IFM_SUBTYPE(x) (IFM_TYPE(x) == IFM_ETHER ? \
137 IFM_ETHER_SUBTYPE_GET(x) : ((x) & IFM_TMASK))
138 #define IFM_TYPE_MATCH(dt, t) \
139 (IFM_TYPE(dt) == 0 || IFM_TYPE(dt) == IFM_TYPE(t))
140 #define IFM_TYPE_SUBTYPE_MATCH(dt, t) \
141 (IFM_TYPE(dt) == IFM_TYPE(t) && IFM_SUBTYPE(dt) == IFM_SUBTYPE(t))
142 #define IFM_INST(x) (((x) & IFM_IMASK) >> IFM_ISHIFT)
143 #define IFM_OPTIONS(x) ((x) & (IFM_OMASK | IFM_GMASK))
144 #define IFM_MODE(x) ((x) & IFM_MMASK)
145
146 #define IFM_INST_MAX IFM_INST(IFM_IMASK)
147 #define IFM_INST_ANY ((u_int) -1)
148
149 /* Mask of "status valid" bits, for ifconfig(8). */
150 #define IFM_STATUS_VALID IFM_AVALID
151
152 /* List of "status valid" bits, for ifconfig(8). */
153 #define IFM_STATUS_VALID_LIST { \
154 IFM_AVALID, \
155 0, \
156 }
157
158 /*
159 * Macro to create a media word.
160 */
161 #define IFM_MAKEWORD(type, subtype, options, instance) \
162 ((type) | (subtype) | (options) | ((instance) << IFM_ISHIFT))
163 #define IFM_MAKEMODE(mode) \
164 (((mode) << IFM_MSHIFT) & IFM_MMASK)
165
166 /*
167 * Media type (IFM_NMASK).
168 */
169 #define IFM_GENERIC 0x00000000 /* Only used for link status reporting */
170 #define IFM_ETHER 0x00000020
171 #define IFM_TOKEN 0x00000040
172 #define IFM_FDDI 0x00000060
173 #define IFM_IEEE80211 0x00000080
174 #define IFM_CARP 0x000000c0 /* Common Address Redundancy Protocol */
175
176 #define IFM_NMIN IFM_ETHER /* lowest Network type */
177 #define IFM_NMAX IFM_NMASK /* highest Network type */
178
179 /*
180 * Shared media sub-types (IFM_TMASK)
181 */
182 #define IFM_AUTO 0 /* Autoselect best media */
183 #define IFM_MANUAL 1 /* Jumper/dipswitch selects media */
184 #define IFM_NONE 2 /* Deselect all media */
185
186 /*
187 * Shared (global) options (IFM_GMASK)
188 */
189 #define IFM_FDX 0x00100000 /* Force full duplex */
190 #define IFM_HDX 0x00200000 /* Force half duplex */
191 #define IFM_FLOW 0x00400000 /* enable hardware flow control */
192 #define IFM_FLAG0 0x01000000 /* Driver defined flag */
193 #define IFM_FLAG1 0x02000000 /* Driver defined flag */
194 #define IFM_FLAG2 0x04000000 /* Driver defined flag */
195 #define IFM_LOOP 0x08000000 /* Put hardware in loopback */
196
197 /*
198 * 0: Generic (IFM_GENERIC). Only used for link status reporting.
199 * No any media specific flag.
200 */
201
202 /*
203 * 1: Ethernet (IFM_ETHER)
204 *
205 * In order to use more than 31 subtypes, Ethernet uses some of the option
206 * bits as part of the subtype field. See the options section below for
207 * relevant definitions.
208 */
209 #define IFM_ETHER_SUBTYPE(x) (((x) & IFM_TMASK) | \
210 (((x) & (_IFM_ETH_XTMASK >> IFM_ETH_XSHIFT)) << IFM_ETH_XSHIFT))
211 #define IFM_ETHER_SUBTYPE_GET(x) ((x) & (IFM_TMASK | _IFM_ETH_XTMASK))
212 #define _IFM_EX(x) IFM_ETHER_SUBTYPE(x) /* internal shorthand */
213
214 #define IFM_10_T 3 /* 10BaseT - RJ45 */
215 #define IFM_10_2 4 /* 10Base2 - Thinnet */
216 #define IFM_10_5 5 /* 10Base5 - AUI */
217 #define IFM_100_TX 6 /* 100BaseTX - RJ45 */
218 #define IFM_100_FX 7 /* 100BaseFX - Fiber */
219 #define IFM_100_T4 8 /* 100BaseT4 - 4 pair cat 3 */
220 #define IFM_100_VG 9 /* 100VG-AnyLAN */
221 #define IFM_100_T2 10 /* 100BaseT2 */
222 #define IFM_1000_SX 11 /* 1000BaseSX - multi-mode fiber */
223 #define IFM_10_STP 12 /* 10BaseT over shielded TP */
224 #define IFM_10_FL 13 /* 10BaseFL - Fiber */
225 #define IFM_1000_LX 14 /* 1000baseLX - single-mode fiber */
226 #define IFM_1000_CX 15 /* 1000baseCX - 150ohm STP */
227 #define IFM_1000_T 16 /* 1000baseT - 4 pair cat 5 */
228 #define IFM_HPNA_1 17 /* HomePNA 1.0 (1Mb/s) */
229 #define IFM_10G_LR 18 /* 10GbaseLR - single-mode fiber */
230 #define IFM_10G_SR 19 /* 10GBase-SR 850nm Multi-mode */
231 #define IFM_10G_CX4 20 /* 10GBase CX4 copper */
232 #define IFM_2500_SX 21 /* 2500baseSX - multi-mode fiber */
233 #define IFM_1000_BX10 22 /* 1000base-BX10 */
234 #define IFM_10G_TWINAX 23 /* 10GBase Twinax copper */
235 #define IFM_10G_TWINAX_LONG 24 /* 10GBase Twinax Long copper */
236 #define IFM_10G_LRM 25 /* 10GBase-LRM 850nm Multi-mode */
237 #define IFM_10G_T 26 /* 10GBase-T - RJ45 */
238 #define IFM_1000_KX 27 /* 1000base-KX backplane */
239 #define IFM_2500_KX 28 /* 2500base-KX backplane */
240 #define IFM_2500_T 29 /* 2500base-T - RJ45 */
241 #define IFM_5000_T 30 /* 5Gbase-T - RJ45 */
242 #define IFM_OTHER 31 /*
243 * This number indicates "Not listed".
244 * and also used for backward
245 * compatibility.
246 */
247 #define IFM_1000_SGMII _IFM_EX(32) /* 1G SGMII */
248 #define IFM_5000_KR _IFM_EX(33) /* 5GBASE-KR backplane */
249 #define IFM_10G_AOC _IFM_EX(34) /* 10G active optical cable */
250 #define IFM_10G_CR1 _IFM_EX(35) /* 10GBASE-CR1 Twinax splitter */
251 #define IFM_10G_ER _IFM_EX(36) /* 10GBASE-ER */
252 #define IFM_10G_KR _IFM_EX(37) /* 10GBASE-KR backplane */
253 #define IFM_10G_KX4 _IFM_EX(38) /* 10GBASE-KX4 backplane */
254 #define IFM_10G_LX4 _IFM_EX(39) /* 10GBASE-LX4 */
255 #define IFM_10G_SFI _IFM_EX(40) /* 10G SFI */
256 #define IFM_10G_ZR _IFM_EX(41) /* 10GBASE-ZR */
257 #define IFM_20G_KR2 _IFM_EX(42) /* 20GBASE-KR2 backplane */
258 #define IFM_25G_AOC _IFM_EX(43) /* 25G active optical cable */
259 #define IFM_25G_AUI _IFM_EX(44) /* 25G-AUI-C2C (chip to chip) */
260 #define IFM_25G_CR _IFM_EX(45) /* 25GBASE-CR (twinax) */
261 #define IFM_25G_ACC _IFM_EX(46) /* 25GBASE-ACC */
262 #define IFM_25G_CR_S _IFM_EX(47) /* 25GBASE-CR-S (CR short) */
263 #define IFM_25G_ER _IFM_EX(48) /* 25GBASE-ER */
264 #define IFM_25G_KR _IFM_EX(49) /* 25GBASE-KR */
265 #define IFM_25G_KR_S _IFM_EX(50) /* 25GBASE-KR-S (KR short) */
266 #define IFM_25G_LR _IFM_EX(51) /* 25GBASE-LR */
267 #define IFM_25G_SR _IFM_EX(52) /* 25GBASE-SR */
268 #define IFM_25G_T _IFM_EX(53) /* 25GBASE-T - RJ45 */
269 #define IFM_40G_AOC _IFM_EX(54) /* 40G Active Optical Cable */
270 #define IFM_40G_CR4 _IFM_EX(55) /* 40GBASE-CR4 */
271 #define IFM_40G_ER4 _IFM_EX(56) /* 40GBASE-ER4 */
272 #define IFM_40G_FR _IFM_EX(57) /* 40GBASE-FR */
273 #define IFM_40G_KR4 _IFM_EX(58) /* 40GBASE-KR4 */
274 #define IFM_40G_LR4 _IFM_EX(59) /* 40GBASE-LR4 */
275 #define IFM_40G_SR4 _IFM_EX(60) /* 40GBASE-SR4 */
276 #define IFM_40G_T _IFM_EX(61) /* 40GBASE-T */
277 #define IFM_40G_XLPPI _IFM_EX(62) /* 40G XLPPI */
278 #define IFM_50G_AUI1 _IFM_EX(63) /* 50GAUI-1 */
279 #define IFM_50G_AUI2 _IFM_EX(64) /* 50GAUI-2 */
280 #define IFM_50G_CR _IFM_EX(65) /* 50GBASE-CR */
281 #define IFM_50G_CR2 _IFM_EX(66) /* 50GBASE-CR2 */
282 #define IFM_50G_FR _IFM_EX(67) /* 50GBASE-FR */
283 #define IFM_50G_KR _IFM_EX(68) /* 50GBASE-KR */
284 #define IFM_50G_KR2 _IFM_EX(69) /* 50GBASE-KR2 */
285 #define IFM_50G_LAUI2 _IFM_EX(70) /* 50GLAUI-2 */
286 #define IFM_50G_LR _IFM_EX(71) /* 50GBASE-LR */
287 /* _IFM_EX(72) Not defined yet */
288 #define IFM_50G_SR _IFM_EX(73) /* 50GBASE-SR */
289 #define IFM_50G_SR2 _IFM_EX(74) /* 50GBASE-SR2 */
290 #define IFM_56G_R4 _IFM_EX(75) /* 56GBASE-R4 */
291 #define IFM_100G_CR2 _IFM_EX(76) /* 100GBASE-CR2 (CP2?) */
292 #define IFM_100G_CR4 _IFM_EX(77) /* 100GBASE-CR4 */
293 #define IFM_100G_CR10 _IFM_EX(78) /* 100GBASE-CR10 */
294 #define IFM_100G_DR _IFM_EX(79) /* 100GBASE-DR */
295 #define IFM_100G_ER4 _IFM_EX(80) /* 100GBASE-ER4 */
296 #define IFM_100G_KP4 _IFM_EX(81) /* 100GBASE-KP4 */
297 #define IFM_100G_KR2 _IFM_EX(82) /* 100GBASE-KR2 */
298 #define IFM_100G_KR4 _IFM_EX(83) /* 100GBASE-KR4 */
299 #define IFM_100G_LR4 _IFM_EX(84) /* 100GBASE-LR4 */
300 #define IFM_100G_SR2 _IFM_EX(85) /* 100GBASE-SR2 */
301 #define IFM_100G_SR4 _IFM_EX(86) /* 100GBASE-SR4 */
302 #define IFM_100G_SR10 _IFM_EX(87) /* 100GBASE-SR10 */
303 #define IFM_200G_CR2 _IFM_EX(88) /* 200GBASE-CR2 */
304 #define IFM_200G_CR4 _IFM_EX(89) /* 200GBASE-CR4 */
305 #define IFM_200G_DR4 _IFM_EX(90) /* 200GBASE-DR4 */
306 #define IFM_200G_FR4 _IFM_EX(91) /* 200GBASE-FR4 */
307 #define IFM_200G_KR2 _IFM_EX(92) /* 200GBASE-KR2 */
308 #define IFM_200G_KR4 _IFM_EX(93) /* 200GBASE-KR4 */
309 #define IFM_200G_LR4 _IFM_EX(94) /* 200GBASE-LR4 */
310 #define IFM_200G_SR4 _IFM_EX(95) /* 200GBASE-SR4 */
311 #define IFM_400G_CR4 _IFM_EX(96) /* 400GBASE-CR4 */
312 #define IFM_400G_DR4 _IFM_EX(97) /* 400GBASE-DR4 */
313 #define IFM_400G_FR8 _IFM_EX(98) /* 400GBASE-FR8 */
314 #define IFM_400G_KR4 _IFM_EX(99) /* 400GBASE-KR4 */
315 #define IFM_400G_LR8 _IFM_EX(100) /* 400GBASE-LR8 */
316 #define IFM_400G_SR16 _IFM_EX(101) /* 400GBASE-SR16 */
317 #define IFM_100G_ACC _IFM_EX(102) /* 100GBASE-ACC */
318 #define IFM_100G_AOC _IFM_EX(103) /* 100GBASE-AOC */
319 #define IFM_100G_FR _IFM_EX(104) /* 100GBASE-FR */
320 #define IFM_100G_LR _IFM_EX(105) /* 100GBASE-LR */
321 #define IFM_200G_ER4 _IFM_EX(106) /* 200GBASE-ER4 */
322 #define IFM_400G_ER8 _IFM_EX(107) /* 400GBASE-ER8 */
323 #define IFM_400G_FR4 _IFM_EX(108) /* 400GBASE-FR4 */
324 #define IFM_400G_LR4 _IFM_EX(109) /* 400GBASE-LR4 */
325 #define IFM_400G_SR4_2 _IFM_EX(110) /* 400GBASE-SR4.2 */
326 #define IFM_400G_SR8 _IFM_EX(111) /* 400GBASE-SR8 */
327
328 /* IFM_OMASK bits */
329 #define IFM_ETH_MASTER 0x00000100 /* master mode (1000baseT) */
330 #define IFM_ETH_RXPAUSE 0x00000200 /* receive PAUSE frames */
331 #define IFM_ETH_TXPAUSE 0x00000400 /* transmit PAUSE frames */
332 #define _IFM_ETH_XTMASK 0x0000e000 /* Media sub-type (MSB) */
333 #define IFM_ETH_XSHIFT (13 - 5) /* shift XTYPE next to TMASK */
334
335 /* Ethernet flow control mask */
336 #define IFM_ETH_FMASK (IFM_FLOW | IFM_ETH_RXPAUSE | IFM_ETH_TXPAUSE)
337
338 /*
339 * 2: Token ring (IFM_TOKEN)
340 */
341 #define IFM_TOK_STP4 3 /* Shielded twisted pair 4m - DB9 */
342 #define IFM_TOK_STP16 4 /* Shielded twisted pair 16m - DB9 */
343 #define IFM_TOK_UTP4 5 /* Unshielded twisted pair 4m - RJ45 */
344 #define IFM_TOK_UTP16 6 /* Unshielded twisted pair 16m - RJ45 */
345 /* IFM_OMASK bits */
346 #define IFM_TOK_ETR 0x00000200 /* Early token release */
347 #define IFM_TOK_SRCRT 0x00000400 /* Enable source routing features */
348 #define IFM_TOK_ALLR 0x00000800 /* All routes / Single route bcast */
349
350 /*
351 * 3: FDDI (IFM_FDDI)
352 */
353 #define IFM_FDDI_SMF 3 /* Single-mode fiber */
354 #define IFM_FDDI_MMF 4 /* Multi-mode fiber */
355 #define IFM_FDDI_UTP 5 /* CDDI / UTP */
356 #define IFM_FDDI_DA 0x00000100 /* Dual attach / single attach */
357
358 /*
359 * 4: IEEE 802.11 Wireless (IFM_IEEE80211)
360 */
361 #define IFM_IEEE80211_FH1 3 /* Frequency Hopping 1Mbps */
362 #define IFM_IEEE80211_FH2 4 /* Frequency Hopping 2Mbps */
363 #define IFM_IEEE80211_DS2 5 /* Direct Sequence 2Mbps */
364 #define IFM_IEEE80211_DS5 6 /* Direct Sequence 5Mbps*/
365 #define IFM_IEEE80211_DS11 7 /* Direct Sequence 11Mbps*/
366 #define IFM_IEEE80211_DS1 8 /* Direct Sequence 1Mbps */
367 #define IFM_IEEE80211_DS22 9 /* Direct Sequence 22Mbps */
368 #define IFM_IEEE80211_OFDM6 10 /* OFDM 6Mbps */
369 #define IFM_IEEE80211_OFDM9 11 /* OFDM 9Mbps */
370 #define IFM_IEEE80211_OFDM12 12 /* OFDM 12Mbps */
371 #define IFM_IEEE80211_OFDM18 13 /* OFDM 18Mbps */
372 #define IFM_IEEE80211_OFDM24 14 /* OFDM 24Mbps */
373 #define IFM_IEEE80211_OFDM36 15 /* OFDM 36Mbps */
374 #define IFM_IEEE80211_OFDM48 16 /* OFDM 48Mbps */
375 #define IFM_IEEE80211_OFDM54 17 /* OFDM 54Mbps */
376 #define IFM_IEEE80211_OFDM72 18 /* OFDM 72Mbps */
377 #define IFM_IEEE80211_DS354k 19 /* Direct Sequence 354Kbps */
378 #define IFM_IEEE80211_DS512k 20 /* Direct Sequence 512Kbps */
379 #define IFM_IEEE80211_OFDM3 21 /* OFDM 3Mbps */
380 #define IFM_IEEE80211_OFDM4 22 /* OFDM 4.5Mbps */
381 #define IFM_IEEE80211_OFDM27 23 /* OFDM 27Mbps */
382 /* NB: not enough bits to express MCS fully */
383 #define IFM_IEEE80211_MCS 24 /* HT MCS rate */
384 #define IFM_IEEE80211_VHT 25 /* VHT MCS rate */
385
386 /* IFM_OMASK bits */
387 #define IFM_IEEE80211_ADHOC 0x00000100 /* Operate in Adhoc mode */
388 #define IFM_IEEE80211_HOSTAP 0x00000200 /* Operate in Host AP mode */
389 #define IFM_IEEE80211_MONITOR 0x00000400 /* Operate in Monitor mode */
390 #define IFM_IEEE80211_TURBO 0x00000800 /* Operate in Turbo mode */
391 #define IFM_IEEE80211_IBSS 0x00001000 /* Operate in IBSS mode */
392 #define IFM_IEEE80211_WDS 0x00002000 /* Operate as an WDS master */
393 #define IFM_IEEE80211_MBSS 0x00004000 /* Operate in MBSS mode */
394
395 /* Operating mode (IFM_MMASK) for multi-mode devices */
396 #define IFM_IEEE80211_11A 0x00010000 /* 5 GHz, OFDM mode */
397 #define IFM_IEEE80211_11B 0x00020000 /* Direct Sequence mode */
398 #define IFM_IEEE80211_11G 0x00030000 /* 2 GHz, CCK mode */
399 #define IFM_IEEE80211_FH 0x00040000 /* 2 GHz, GFSK mode */
400 #define IFM_IEEE80211_11NA 0x00050000 /* 5Ghz, HT mode */
401 #define IFM_IEEE80211_11NG 0x00060000 /* 2Ghz, HT mode */
402 #define IFM_IEEE80211_11AC 0x00070000 /* 2Ghz/5Ghz, VHT mode */
403
404
405 /*
406 * 6: Common Address Redundancy Protocol (IFM_CARP)
407 * No any media specific flag.
408 */
409
410 /*
411 * NetBSD extension not defined in the BSDI API. This is used in various
412 * places to get the canonical description for a given type/subtype.
413 *
414 * In the subtype and mediaopt descriptions, the valid TYPE bits are OR'd
415 * in to indicate which TYPE the subtype/option corresponds to. If no
416 * TYPE is present, it is a shared media/mediaopt.
417 *
418 * Note that these are parsed case-insensitive.
419 *
420 * Order is important. The first matching entry is the canonical name
421 * for a media type; subsequent matches are aliases.
422 */
423 struct ifmedia_description {
424 int ifmt_word; /* word value; may be masked */
425 const char *ifmt_string; /* description */
426 };
427
428 #define IFM_TYPE_DESCRIPTIONS { \
429 { IFM_ETHER, "Ethernet" }, \
430 { IFM_ETHER, "ether" }, \
431 { IFM_TOKEN, "TokenRing" }, \
432 { IFM_TOKEN, "token" }, \
433 { IFM_FDDI, "FDDI" }, \
434 { IFM_IEEE80211, "IEEE802.11" }, \
435 { IFM_CARP, "CARP" }, \
436 { 0, NULL }, \
437 }
438
439 #define IFM_SUBTYPE_DESCRIPTIONS { \
440 { IFM_AUTO, "autoselect" }, \
441 { IFM_AUTO, "auto" }, \
442 { IFM_MANUAL, "manual" }, \
443 { IFM_NONE, "none" }, \
444 \
445 { IFM_ETHER | IFM_10_T, "10baseT" }, \
446 { IFM_ETHER | IFM_10_T, "10baseT/UTP" }, \
447 { IFM_ETHER | IFM_10_T, "UTP" }, \
448 { IFM_ETHER | IFM_10_T, "10UTP" }, \
449 { IFM_ETHER | IFM_10_T, "10BASE-T" }, \
450 { IFM_ETHER | IFM_10_2, "10base2" }, \
451 { IFM_ETHER | IFM_10_2, "10base2/BNC" }, \
452 { IFM_ETHER | IFM_10_2, "BNC" }, \
453 { IFM_ETHER | IFM_10_2, "10BNC" }, \
454 { IFM_ETHER | IFM_10_2, "10BASE2" }, \
455 { IFM_ETHER | IFM_10_5, "10base5" }, \
456 { IFM_ETHER | IFM_10_5, "10base5/AUI" }, \
457 { IFM_ETHER | IFM_10_5, "AUI" }, \
458 { IFM_ETHER | IFM_10_5, "10AUI" }, \
459 { IFM_ETHER | IFM_10_5, "10BASE5" }, \
460 { IFM_ETHER | IFM_100_TX, "100baseTX" }, \
461 { IFM_ETHER | IFM_100_TX, "100TX" }, \
462 { IFM_ETHER | IFM_100_TX, "100BASE-TX" }, \
463 { IFM_ETHER | IFM_100_FX, "100baseFX" }, \
464 { IFM_ETHER | IFM_100_FX, "100FX" }, \
465 { IFM_ETHER | IFM_100_FX, "100BASE-FX" }, \
466 { IFM_ETHER | IFM_100_T4, "100baseT4" }, \
467 { IFM_ETHER | IFM_100_T4, "100T4" }, \
468 { IFM_ETHER | IFM_100_T4, "100BASE-T4" }, \
469 { IFM_ETHER | IFM_100_VG, "100baseVG" }, \
470 { IFM_ETHER | IFM_100_VG, "100VG" }, \
471 { IFM_ETHER | IFM_100_VG, "100VG-AnyLAN" }, \
472 { IFM_ETHER | IFM_100_T2, "100baseT2" }, \
473 { IFM_ETHER | IFM_100_T2, "100T2" }, \
474 { IFM_ETHER | IFM_100_T2, "100BASE-T2" }, \
475 { IFM_ETHER | IFM_1000_SX, "1000baseSX" }, \
476 { IFM_ETHER | IFM_1000_SX, "1000SX" }, \
477 { IFM_ETHER | IFM_1000_SX, "1000BASE-SX" }, \
478 { IFM_ETHER | IFM_10_STP, "10baseSTP" }, \
479 { IFM_ETHER | IFM_10_STP, "STP" }, \
480 { IFM_ETHER | IFM_10_STP, "10STP" }, \
481 { IFM_ETHER | IFM_10_STP, "10BASE-STP" }, \
482 { IFM_ETHER | IFM_10_FL, "10baseFL" }, \
483 { IFM_ETHER | IFM_10_FL, "FL" }, \
484 { IFM_ETHER | IFM_10_FL, "10FL" }, \
485 { IFM_ETHER | IFM_10_FL, "10BASE-FL" }, \
486 { IFM_ETHER | IFM_1000_LX, "1000baseLX" }, \
487 { IFM_ETHER | IFM_1000_LX, "1000LX" }, \
488 { IFM_ETHER | IFM_1000_LX, "1000BASE-LX" }, \
489 { IFM_ETHER | IFM_1000_CX, "1000baseCX" }, \
490 { IFM_ETHER | IFM_1000_CX, "1000CX" }, \
491 { IFM_ETHER | IFM_1000_CX, "1000BASE-CX" }, \
492 { IFM_ETHER | IFM_1000_BX10, "1000BASE-BX10" }, \
493 { IFM_ETHER | IFM_1000_KX, "1000BASE-KX" }, \
494 { IFM_ETHER | IFM_1000_KX, "1000baseKX" }, \
495 { IFM_ETHER | IFM_1000_T, "1000baseT" }, \
496 { IFM_ETHER | IFM_1000_T, "1000T" }, \
497 { IFM_ETHER | IFM_1000_T, "1000BASE-T" }, \
498 { IFM_ETHER | IFM_HPNA_1, "HomePNA1" }, \
499 { IFM_ETHER | IFM_HPNA_1, "HPNA1" }, \
500 { IFM_ETHER | IFM_2500_KX | IFM_FDX, "2500BASE-KX" }, \
501 { IFM_ETHER | IFM_2500_KX | IFM_FDX, "2500baseKX" }, \
502 { IFM_ETHER | IFM_2500_T | IFM_FDX, "2.5GBASE-T" }, \
503 { IFM_ETHER | IFM_2500_T | IFM_FDX, "2500baseT" }, \
504 { IFM_ETHER | IFM_5000_T | IFM_FDX, "5GBASE-T" }, \
505 { IFM_ETHER | IFM_5000_T | IFM_FDX, "5GbaseT" }, \
506 { IFM_ETHER | IFM_OTHER, "Other" }, \
507 { IFM_ETHER | IFM_10G_LR | IFM_FDX, "10GbaseLR" }, \
508 { IFM_ETHER | IFM_10G_LR | IFM_FDX, "10GLR" }, \
509 { IFM_ETHER | IFM_10G_LR | IFM_FDX, "10GBASE-LR" }, \
510 { IFM_ETHER | IFM_10G_SR | IFM_FDX, "10GbaseSR" }, \
511 { IFM_ETHER | IFM_10G_SR | IFM_FDX, "10GSR" }, \
512 { IFM_ETHER | IFM_10G_SR | IFM_FDX, "10GBASE-SR" }, \
513 { IFM_ETHER | IFM_10G_LRM | IFM_FDX, "10Gbase-LRM" }, \
514 { IFM_ETHER | IFM_10G_TWINAX | IFM_FDX, "10Gbase-Twinax" }, \
515 { IFM_ETHER | IFM_10G_TWINAX_LONG | IFM_FDX, "10Gbase-Twinax-Long" },\
516 { IFM_ETHER | IFM_10G_T | IFM_FDX, "10Gbase-T" }, \
517 { IFM_ETHER | IFM_10G_CX4 | IFM_FDX, "10GbaseCX4" }, \
518 { IFM_ETHER | IFM_10G_CX4 | IFM_FDX, "10GCX4" }, \
519 { IFM_ETHER | IFM_10G_CX4 | IFM_FDX, "10GBASE-CX4" }, \
520 { IFM_ETHER | IFM_2500_SX | IFM_FDX, "2500baseSX" }, \
521 { IFM_ETHER | IFM_2500_SX | IFM_FDX, "2500SX" }, \
522 { IFM_ETHER | IFM_1000_SGMII | IFM_FDX, "1000BASE-SGMII" }, \
523 { IFM_ETHER | IFM_5000_KR | IFM_FDX, "5GBASE-KR" }, \
524 { IFM_ETHER | IFM_10G_AOC | IFM_FDX, "10GBASE-AOC" }, \
525 { IFM_ETHER | IFM_10G_CR1 | IFM_FDX, "10GBASE-CR1" }, \
526 { IFM_ETHER | IFM_10G_ER | IFM_FDX, "10GBASE-ER" }, \
527 { IFM_ETHER | IFM_10G_KR | IFM_FDX, "10GBASE-KR" }, \
528 { IFM_ETHER | IFM_10G_KX4 | IFM_FDX, "10GBASE-KX4" }, \
529 { IFM_ETHER | IFM_10G_LX4 | IFM_FDX, "10GBASE-LX4" }, \
530 { IFM_ETHER | IFM_10G_SFI | IFM_FDX, "10GBASE-SFI" }, \
531 { IFM_ETHER | IFM_10G_ZR | IFM_FDX, "10GBASE-ZR" }, \
532 { IFM_ETHER | IFM_20G_KR2 | IFM_FDX, "20GBASE-KR2" }, \
533 { IFM_ETHER | IFM_25G_ACC | IFM_FDX, "25GBASE-ACC" }, \
534 { IFM_ETHER | IFM_25G_AOC | IFM_FDX, "25GBASE-AOC" }, \
535 { IFM_ETHER | IFM_25G_AUI | IFM_FDX, "25G-AUI" }, \
536 { IFM_ETHER | IFM_25G_CR | IFM_FDX, "25GBASE-CR" }, \
537 { IFM_ETHER | IFM_25G_CR_S | IFM_FDX, "25GBASE-CR-S" }, \
538 { IFM_ETHER | IFM_25G_ER | IFM_FDX, "25GBASE-ER" }, \
539 { IFM_ETHER | IFM_25G_KR | IFM_FDX, "25GBASE-KR" }, \
540 { IFM_ETHER | IFM_25G_KR_S | IFM_FDX, "25GBASE-KR-S" }, \
541 { IFM_ETHER | IFM_25G_LR | IFM_FDX, "25GBASE-LR" }, \
542 { IFM_ETHER | IFM_25G_SR | IFM_FDX, "25GBASE-SR" }, \
543 { IFM_ETHER | IFM_25G_T | IFM_FDX, "25GBASE-T" }, \
544 { IFM_ETHER | IFM_40G_AOC | IFM_FDX, "40GBASE-AOC" }, \
545 { IFM_ETHER | IFM_40G_CR4 | IFM_FDX, "40GBASE-CR4" }, \
546 { IFM_ETHER | IFM_40G_ER4 | IFM_FDX, "40GBASE-ER4" }, \
547 { IFM_ETHER | IFM_40G_FR | IFM_FDX, "40GBASE-FR" }, \
548 { IFM_ETHER | IFM_40G_KR4 | IFM_FDX, "40GBASE-KR4" }, \
549 { IFM_ETHER | IFM_40G_LR4 | IFM_FDX, "40GBASE-LR4" }, \
550 { IFM_ETHER | IFM_40G_SR4 | IFM_FDX, "40GBASE-SR4" }, \
551 { IFM_ETHER | IFM_40G_T | IFM_FDX, "40GBASE-T" }, \
552 { IFM_ETHER | IFM_40G_XLPPI | IFM_FDX, "40G-XLPPI" }, \
553 { IFM_ETHER | IFM_50G_AUI1 | IFM_FDX, "50GAUI-1" }, \
554 { IFM_ETHER | IFM_50G_AUI2 | IFM_FDX, "50GAUI-2" }, \
555 { IFM_ETHER | IFM_50G_CR | IFM_FDX, "50GBASE-CR" }, \
556 { IFM_ETHER | IFM_50G_CR2 | IFM_FDX, "50GBASE-CR2" }, \
557 { IFM_ETHER | IFM_50G_FR | IFM_FDX, "50GBASE-FR" }, \
558 { IFM_ETHER | IFM_50G_KR | IFM_FDX, "50GBASE-KR" }, \
559 { IFM_ETHER | IFM_50G_KR2 | IFM_FDX, "50GBASE-KR2" }, \
560 { IFM_ETHER | IFM_50G_LAUI2 | IFM_FDX, "50GLAUI-2" }, \
561 { IFM_ETHER | IFM_50G_LR | IFM_FDX, "50GBASE-LR" }, \
562 { IFM_ETHER | IFM_50G_SR | IFM_FDX, "50GBASE-SR" }, \
563 { IFM_ETHER | IFM_50G_SR2 | IFM_FDX, "50GBASE-SR2" }, \
564 { IFM_ETHER | IFM_56G_R4 | IFM_FDX, "56GBASE-R4" }, \
565 { IFM_ETHER | IFM_100G_ACC | IFM_FDX, "100GBASE-ACC" }, \
566 { IFM_ETHER | IFM_100G_AOC | IFM_FDX, "100GBASE-AOC" }, \
567 { IFM_ETHER | IFM_100G_CR2 | IFM_FDX, "100GBASE-CR2" }, \
568 { IFM_ETHER | IFM_100G_CR4 | IFM_FDX, "100GBASE-CR4" }, \
569 { IFM_ETHER | IFM_100G_CR10 | IFM_FDX, "100GBASE-CR10" }, \
570 { IFM_ETHER | IFM_100G_DR | IFM_FDX, "100GBASE-DR" }, \
571 { IFM_ETHER | IFM_100G_ER4 | IFM_FDX, "100GBASE-ER4" }, \
572 { IFM_ETHER | IFM_100G_FR | IFM_FDX, "100GBASE-FR" }, \
573 { IFM_ETHER | IFM_100G_KP4 | IFM_FDX, "100GBASE-KP4" }, \
574 { IFM_ETHER | IFM_100G_KR2 | IFM_FDX, "100GBASE-KR2" }, \
575 { IFM_ETHER | IFM_100G_KR4 | IFM_FDX, "100GBASE-KR4" }, \
576 { IFM_ETHER | IFM_100G_LR | IFM_FDX, "100GBASE-LR" }, \
577 { IFM_ETHER | IFM_100G_LR4 | IFM_FDX, "100GBASE-LR4" }, \
578 { IFM_ETHER | IFM_100G_SR2 | IFM_FDX, "100GBASE-SR2" }, \
579 { IFM_ETHER | IFM_100G_SR4 | IFM_FDX, "100GBASE-SR4" }, \
580 { IFM_ETHER | IFM_100G_SR10 | IFM_FDX, "100GBASE-SR10" }, \
581 { IFM_ETHER | IFM_200G_CR2 | IFM_FDX, "200GBASE-CR2" }, \
582 { IFM_ETHER | IFM_200G_CR4 | IFM_FDX, "200GBASE-CR4" }, \
583 { IFM_ETHER | IFM_200G_DR4 | IFM_FDX, "200GBASE-DR4" }, \
584 { IFM_ETHER | IFM_200G_ER4 | IFM_FDX, "200GBASE-ER4" }, \
585 { IFM_ETHER | IFM_200G_FR4 | IFM_FDX, "200GBASE-FR4" }, \
586 { IFM_ETHER | IFM_200G_KR2 | IFM_FDX, "200GBASE-KR2" }, \
587 { IFM_ETHER | IFM_200G_KR4 | IFM_FDX, "200GBASE-KR4" }, \
588 { IFM_ETHER | IFM_200G_LR4 | IFM_FDX, "200GBASE-LR4" }, \
589 { IFM_ETHER | IFM_200G_SR4 | IFM_FDX, "200GBASE-SR4" }, \
590 { IFM_ETHER | IFM_400G_CR4 | IFM_FDX, "400GBASE-CR4" }, \
591 { IFM_ETHER | IFM_400G_DR4 | IFM_FDX, "400GBASE-DR4" }, \
592 { IFM_ETHER | IFM_400G_ER8 | IFM_FDX, "400GBASE-ER8" }, \
593 { IFM_ETHER | IFM_400G_FR4 | IFM_FDX, "400GBASE-FR4" }, \
594 { IFM_ETHER | IFM_400G_FR8 | IFM_FDX, "400GBASE-FR8" }, \
595 { IFM_ETHER | IFM_400G_KR4 | IFM_FDX, "400GBASE-KR4" }, \
596 { IFM_ETHER | IFM_400G_LR4 | IFM_FDX, "400GBASE-LR4" }, \
597 { IFM_ETHER | IFM_400G_LR8 | IFM_FDX, "400GBASE-LR8" }, \
598 { IFM_ETHER | IFM_400G_SR4_2 | IFM_FDX, "400GBASE-SR4.2" }, \
599 { IFM_ETHER | IFM_400G_SR8 | IFM_FDX, "400GBASE-SR8" }, \
600 { IFM_ETHER | IFM_400G_SR16 | IFM_FDX, "400GBASE-SR16" }, \
601 \
602 { IFM_TOKEN | IFM_TOK_STP4, "DB9/4Mbit" }, \
603 { IFM_TOKEN | IFM_TOK_STP4, "4STP" }, \
604 { IFM_TOKEN | IFM_TOK_STP16, "DB9/16Mbit" }, \
605 { IFM_TOKEN | IFM_TOK_STP16, "16STP" }, \
606 { IFM_TOKEN | IFM_TOK_UTP4, "UTP/4Mbit" }, \
607 { IFM_TOKEN | IFM_TOK_UTP4, "4UTP" }, \
608 { IFM_TOKEN | IFM_TOK_UTP16, "UTP/16Mbit" }, \
609 { IFM_TOKEN | IFM_TOK_UTP16, "16UTP" }, \
610 \
611 { IFM_FDDI | IFM_FDDI_SMF, "Single-mode" }, \
612 { IFM_FDDI | IFM_FDDI_SMF, "SMF" }, \
613 { IFM_FDDI | IFM_FDDI_MMF, "Multi-mode" }, \
614 { IFM_FDDI | IFM_FDDI_MMF, "MMF" }, \
615 { IFM_FDDI | IFM_FDDI_UTP, "UTP" }, \
616 { IFM_FDDI | IFM_FDDI_UTP, "CDDI" }, \
617 \
618 /* \
619 * Short-hand for common media+option combos. \
620 */ \
621 { IFM_ETHER | IFM_10_T | IFM_FDX, "10baseT-FDX" }, \
622 { IFM_ETHER | IFM_10_T | IFM_FDX, "10BASE-T-FDX" }, \
623 { IFM_ETHER | IFM_100_TX | IFM_FDX, "100baseTX-FDX" }, \
624 { IFM_ETHER | IFM_100_TX | IFM_FDX, "100BASE-TX-FDX" }, \
625 { IFM_ETHER | IFM_1000_T | IFM_FDX, "1000baseT-FDX" }, \
626 \
627 /* \
628 * IEEE 802.11 \
629 */ \
630 { IFM_IEEE80211 | IFM_IEEE80211_FH1, "FH1" }, \
631 { IFM_IEEE80211 | IFM_IEEE80211_FH2, "FH2" }, \
632 { IFM_IEEE80211 | IFM_IEEE80211_DS1, "DS1" }, \
633 { IFM_IEEE80211 | IFM_IEEE80211_DS2, "DS2" }, \
634 { IFM_IEEE80211 | IFM_IEEE80211_DS5, "DS5" }, \
635 { IFM_IEEE80211 | IFM_IEEE80211_DS11, "DS11" }, \
636 { IFM_IEEE80211 | IFM_IEEE80211_DS22, "DS22" }, \
637 { IFM_IEEE80211 | IFM_IEEE80211_OFDM6, "OFDM6" }, \
638 { IFM_IEEE80211 | IFM_IEEE80211_OFDM9, "OFDM9" }, \
639 { IFM_IEEE80211 | IFM_IEEE80211_OFDM12, "OFDM12" }, \
640 { IFM_IEEE80211 | IFM_IEEE80211_OFDM18, "OFDM18" }, \
641 { IFM_IEEE80211 | IFM_IEEE80211_OFDM24, "OFDM24" }, \
642 { IFM_IEEE80211 | IFM_IEEE80211_OFDM36, "OFDM36" }, \
643 { IFM_IEEE80211 | IFM_IEEE80211_OFDM48, "OFDM48" }, \
644 { IFM_IEEE80211 | IFM_IEEE80211_OFDM54, "OFDM54" }, \
645 { IFM_IEEE80211 | IFM_IEEE80211_OFDM72, "OFDM72" }, \
646 { IFM_IEEE80211 | IFM_IEEE80211_DS354k, "DS/354Kbps" }, \
647 { IFM_IEEE80211 | IFM_IEEE80211_DS512k, "DS/512Kbps" }, \
648 { IFM_IEEE80211 | IFM_IEEE80211_OFDM3, "OFDM/3Mbps" }, \
649 { IFM_IEEE80211 | IFM_IEEE80211_OFDM4, "OFDM/4.5Mbps" }, \
650 { IFM_IEEE80211 | IFM_IEEE80211_OFDM27, "OFDM/27Mbps" }, \
651 { IFM_IEEE80211 | IFM_IEEE80211_MCS, "HT" }, \
652 { IFM_IEEE80211 | IFM_IEEE80211_VHT, "VHT" }, \
653 \
654 { 0, NULL }, \
655 }
656
657 #define IFM_MODE_DESCRIPTIONS { \
658 { IFM_AUTO, "autoselect" }, \
659 { IFM_AUTO, "auto" }, \
660 { IFM_IEEE80211 | IFM_IEEE80211_11A, "11a" }, \
661 { IFM_IEEE80211 | IFM_IEEE80211_11B, "11b" }, \
662 { IFM_IEEE80211 | IFM_IEEE80211_11G, "11g" }, \
663 { IFM_IEEE80211 | IFM_IEEE80211_FH, "fh" }, \
664 { IFM_IEEE80211 | IFM_IEEE80211_11NA, "11na" }, \
665 { IFM_IEEE80211 | IFM_IEEE80211_11NG, "11ng" }, \
666 { IFM_IEEE80211 | IFM_IEEE80211_11AC, "11ac" }, \
667 { 0, NULL }, \
668 }
669
670 #define IFM_OPTION_DESCRIPTIONS { \
671 { IFM_FDX, "full-duplex" }, \
672 { IFM_FDX, "fdx" }, \
673 { IFM_HDX, "half-duplex" }, \
674 { IFM_HDX, "hdx" }, \
675 { IFM_FLOW, "flowcontrol" }, \
676 { IFM_FLOW, "flow" }, \
677 { IFM_FLAG0, "flag0" }, \
678 { IFM_FLAG1, "flag1" }, \
679 { IFM_FLAG2, "flag2" }, \
680 { IFM_LOOP, "loopback" }, \
681 { IFM_LOOP, "hw-loopback"}, \
682 { IFM_LOOP, "loop" }, \
683 \
684 { IFM_ETHER | IFM_ETH_MASTER, "master" }, \
685 { IFM_ETHER | IFM_ETH_RXPAUSE, "rxpause" }, \
686 { IFM_ETHER | IFM_ETH_TXPAUSE, "txpause" }, \
687 \
688 { IFM_TOKEN | IFM_TOK_ETR, "EarlyTokenRelease" }, \
689 { IFM_TOKEN | IFM_TOK_ETR, "ETR" }, \
690 { IFM_TOKEN | IFM_TOK_SRCRT, "SourceRouting" }, \
691 { IFM_TOKEN | IFM_TOK_SRCRT, "SRCRT" }, \
692 { IFM_TOKEN | IFM_TOK_ALLR, "AllRoutes" }, \
693 { IFM_TOKEN | IFM_TOK_ALLR, "ALLR" }, \
694 \
695 { IFM_FDDI | IFM_FDDI_DA, "dual-attach" }, \
696 { IFM_FDDI | IFM_FDDI_DA, "das" }, \
697 \
698 { IFM_IEEE80211 | IFM_IEEE80211_ADHOC, "adhoc" }, \
699 { IFM_IEEE80211 | IFM_IEEE80211_HOSTAP, "hostap" }, \
700 { IFM_IEEE80211 | IFM_IEEE80211_MONITOR,"monitor" }, \
701 { IFM_IEEE80211 | IFM_IEEE80211_TURBO, "turbo" }, \
702 { IFM_IEEE80211 | IFM_IEEE80211_IBSS, "ibss" }, \
703 { IFM_IEEE80211 | IFM_IEEE80211_WDS, "wds" }, \
704 { IFM_IEEE80211 | IFM_IEEE80211_MBSS, "mesh" }, \
705 \
706 { 0, NULL }, \
707 }
708
709 /*
710 * Baudrate descriptions for the various media types.
711 */
712 struct ifmedia_baudrate {
713 int ifmb_word; /* media word */
714 uint64_t ifmb_baudrate; /* corresponding baudrate */
715 };
716
717 #define IFM_BAUDRATE_DESCRIPTIONS { \
718 { IFM_ETHER | IFM_10_T, IF_Mbps(10) }, \
719 { IFM_ETHER | IFM_10_2, IF_Mbps(10) }, \
720 { IFM_ETHER | IFM_10_5, IF_Mbps(10) }, \
721 { IFM_ETHER | IFM_100_TX, IF_Mbps(100) }, \
722 { IFM_ETHER | IFM_100_FX, IF_Mbps(100) }, \
723 { IFM_ETHER | IFM_100_T4, IF_Mbps(100) }, \
724 { IFM_ETHER | IFM_100_VG, IF_Mbps(100) }, \
725 { IFM_ETHER | IFM_100_T2, IF_Mbps(100) }, \
726 { IFM_ETHER | IFM_1000_SX, IF_Mbps(1000) }, \
727 { IFM_ETHER | IFM_10_STP, IF_Mbps(10) }, \
728 { IFM_ETHER | IFM_10_FL, IF_Mbps(10) }, \
729 { IFM_ETHER | IFM_1000_LX, IF_Mbps(1000) }, \
730 { IFM_ETHER | IFM_1000_CX, IF_Mbps(1000) }, \
731 { IFM_ETHER | IFM_1000_T, IF_Mbps(1000) }, \
732 { IFM_ETHER | IFM_HPNA_1, IF_Mbps(1) }, \
733 { IFM_ETHER | IFM_10G_LR, IF_Gbps(10ULL) }, \
734 { IFM_ETHER | IFM_10G_SR, IF_Gbps(10ULL) }, \
735 { IFM_ETHER | IFM_10G_CX4, IF_Gbps(10ULL) }, \
736 { IFM_ETHER | IFM_2500_SX, IF_Mbps(2500ULL) }, \
737 { IFM_ETHER | IFM_1000_BX10, IF_Mbps(1000ULL) }, \
738 { IFM_ETHER | IFM_10G_TWINAX, IF_Gbps(10) }, \
739 { IFM_ETHER | IFM_10G_TWINAX_LONG, IF_Gbps(10) }, \
740 { IFM_ETHER | IFM_10G_LRM, IF_Gbps(10) }, \
741 { IFM_ETHER | IFM_10G_T, IF_Gbps(10) }, \
742 { IFM_ETHER | IFM_1000_KX, IF_Mbps(1000ULL) }, \
743 { IFM_ETHER | IFM_2500_KX, IF_Mbps(2500ULL) }, \
744 { IFM_ETHER | IFM_2500_T, IF_Mbps(2500ULL) }, \
745 { IFM_ETHER | IFM_5000_T, IF_Gbps(5) }, \
746 { IFM_ETHER | IFM_1000_SGMII, IF_Gbps(1) }, \
747 { IFM_ETHER | IFM_5000_KR, IF_Gbps(5) }, \
748 { IFM_ETHER | IFM_10G_AOC, IF_Gbps(10) }, \
749 { IFM_ETHER | IFM_10G_CR1, IF_Gbps(10) }, \
750 { IFM_ETHER | IFM_10G_ER, IF_Gbps(10) }, \
751 { IFM_ETHER | IFM_10G_KR, IF_Gbps(10) }, \
752 { IFM_ETHER | IFM_10G_KX4, IF_Gbps(10) }, \
753 { IFM_ETHER | IFM_10G_LX4, IF_Gbps(10) }, \
754 { IFM_ETHER | IFM_10G_SFI, IF_Gbps(10) }, \
755 { IFM_ETHER | IFM_10G_ZR, IF_Gbps(10) }, \
756 { IFM_ETHER | IFM_20G_KR2, IF_Gbps(20) }, \
757 { IFM_ETHER | IFM_25G_ACC, IF_Gbps(25) }, \
758 { IFM_ETHER | IFM_25G_AOC, IF_Gbps(25) }, \
759 { IFM_ETHER | IFM_25G_AUI, IF_Gbps(25) }, \
760 { IFM_ETHER | IFM_25G_CR, IF_Gbps(25) }, \
761 { IFM_ETHER | IFM_25G_CR_S, IF_Gbps(25) }, \
762 { IFM_ETHER | IFM_25G_ER, IF_Gbps(25) }, \
763 { IFM_ETHER | IFM_25G_KR, IF_Gbps(25) }, \
764 { IFM_ETHER | IFM_25G_KR_S, IF_Gbps(25) }, \
765 { IFM_ETHER | IFM_25G_LR, IF_Gbps(25) }, \
766 { IFM_ETHER | IFM_25G_SR, IF_Gbps(25) }, \
767 { IFM_ETHER | IFM_25G_T, IF_Gbps(25) }, \
768 { IFM_ETHER | IFM_40G_AOC, IF_Gbps(40) }, \
769 { IFM_ETHER | IFM_40G_CR4, IF_Gbps(40) }, \
770 { IFM_ETHER | IFM_40G_ER4, IF_Gbps(40) }, \
771 { IFM_ETHER | IFM_40G_FR, IF_Gbps(40) }, \
772 { IFM_ETHER | IFM_40G_KR4, IF_Gbps(40) }, \
773 { IFM_ETHER | IFM_40G_LR4, IF_Gbps(40) }, \
774 { IFM_ETHER | IFM_40G_SR4, IF_Gbps(40) }, \
775 { IFM_ETHER | IFM_40G_T, IF_Gbps(40) }, \
776 { IFM_ETHER | IFM_40G_XLPPI, IF_Gbps(40) }, \
777 { IFM_ETHER | IFM_50G_AUI1, IF_Gbps(50) }, \
778 { IFM_ETHER | IFM_50G_AUI2, IF_Gbps(50) }, \
779 { IFM_ETHER | IFM_50G_CR, IF_Gbps(50) }, \
780 { IFM_ETHER | IFM_50G_CR2, IF_Gbps(50) }, \
781 { IFM_ETHER | IFM_50G_FR, IF_Gbps(50) }, \
782 { IFM_ETHER | IFM_50G_KR, IF_Gbps(50) }, \
783 { IFM_ETHER | IFM_50G_KR2, IF_Gbps(50) }, \
784 { IFM_ETHER | IFM_50G_LAUI2, IF_Gbps(50) }, \
785 { IFM_ETHER | IFM_50G_LR, IF_Gbps(50) }, \
786 { IFM_ETHER | IFM_50G_SR, IF_Gbps(50) }, \
787 { IFM_ETHER | IFM_50G_SR2, IF_Gbps(50) }, \
788 { IFM_ETHER | IFM_56G_R4, IF_Gbps(56) }, \
789 { IFM_ETHER | IFM_100G_ACC, IF_Gbps(100) }, \
790 { IFM_ETHER | IFM_100G_AOC, IF_Gbps(100) }, \
791 { IFM_ETHER | IFM_100G_CR2, IF_Gbps(100) }, \
792 { IFM_ETHER | IFM_100G_CR4, IF_Gbps(100) }, \
793 { IFM_ETHER | IFM_100G_CR10, IF_Gbps(100) }, \
794 { IFM_ETHER | IFM_100G_DR, IF_Gbps(100) }, \
795 { IFM_ETHER | IFM_100G_ER4, IF_Gbps(100) }, \
796 { IFM_ETHER | IFM_100G_FR, IF_Gbps(100) }, \
797 { IFM_ETHER | IFM_100G_KP4, IF_Gbps(100) }, \
798 { IFM_ETHER | IFM_100G_KR2, IF_Gbps(100) }, \
799 { IFM_ETHER | IFM_100G_KR4, IF_Gbps(100) }, \
800 { IFM_ETHER | IFM_100G_LR, IF_Gbps(100) }, \
801 { IFM_ETHER | IFM_100G_LR4, IF_Gbps(100) }, \
802 { IFM_ETHER | IFM_100G_SR2, IF_Gbps(100) }, \
803 { IFM_ETHER | IFM_100G_SR4, IF_Gbps(100) }, \
804 { IFM_ETHER | IFM_100G_SR10, IF_Gbps(100) }, \
805 { IFM_ETHER | IFM_200G_CR2, IF_Gbps(200) }, \
806 { IFM_ETHER | IFM_200G_CR4, IF_Gbps(200) }, \
807 { IFM_ETHER | IFM_200G_DR4, IF_Gbps(200) }, \
808 { IFM_ETHER | IFM_200G_ER4, IF_Gbps(200) }, \
809 { IFM_ETHER | IFM_200G_FR4, IF_Gbps(200) }, \
810 { IFM_ETHER | IFM_200G_KR2, IF_Gbps(200) }, \
811 { IFM_ETHER | IFM_200G_KR4, IF_Gbps(200) }, \
812 { IFM_ETHER | IFM_200G_LR4, IF_Gbps(200) }, \
813 { IFM_ETHER | IFM_200G_SR4, IF_Gbps(200) }, \
814 { IFM_ETHER | IFM_400G_CR4, IF_Gbps(400) }, \
815 { IFM_ETHER | IFM_400G_DR4, IF_Gbps(400) }, \
816 { IFM_ETHER | IFM_400G_ER8, IF_Gbps(400) }, \
817 { IFM_ETHER | IFM_400G_FR4, IF_Gbps(400) }, \
818 { IFM_ETHER | IFM_400G_FR8, IF_Gbps(400) }, \
819 { IFM_ETHER | IFM_400G_KR4, IF_Gbps(400) }, \
820 { IFM_ETHER | IFM_400G_LR4, IF_Gbps(400) }, \
821 { IFM_ETHER | IFM_400G_LR8, IF_Gbps(400) }, \
822 { IFM_ETHER | IFM_400G_SR4_2, IF_Gbps(400) }, \
823 { IFM_ETHER | IFM_400G_SR8, IF_Gbps(400) }, \
824 { IFM_ETHER | IFM_400G_SR16, IF_Gbps(400) }, \
825 \
826 { IFM_TOKEN | IFM_TOK_STP4, IF_Mbps(4) }, \
827 { IFM_TOKEN | IFM_TOK_STP16, IF_Mbps(16) }, \
828 { IFM_TOKEN | IFM_TOK_UTP4, IF_Mbps(4) }, \
829 { IFM_TOKEN | IFM_TOK_UTP16, IF_Mbps(16) }, \
830 \
831 { IFM_FDDI | IFM_FDDI_SMF, IF_Mbps(100) }, \
832 { IFM_FDDI | IFM_FDDI_MMF, IF_Mbps(100) }, \
833 { IFM_FDDI | IFM_FDDI_UTP, IF_Mbps(100) }, \
834 \
835 { IFM_IEEE80211 | IFM_IEEE80211_FH1, IF_Mbps(1) }, \
836 { IFM_IEEE80211 | IFM_IEEE80211_FH2, IF_Mbps(2) }, \
837 { IFM_IEEE80211 | IFM_IEEE80211_DS2, IF_Mbps(2) }, \
838 { IFM_IEEE80211 | IFM_IEEE80211_DS5, IF_Kbps(5500) }, \
839 { IFM_IEEE80211 | IFM_IEEE80211_DS11, IF_Mbps(11) }, \
840 { IFM_IEEE80211 | IFM_IEEE80211_DS1, IF_Mbps(1) }, \
841 { IFM_IEEE80211 | IFM_IEEE80211_DS22, IF_Mbps(22) }, \
842 { IFM_IEEE80211 | IFM_IEEE80211_OFDM6, IF_Mbps(6) }, \
843 { IFM_IEEE80211 | IFM_IEEE80211_OFDM9, IF_Mbps(9) }, \
844 { IFM_IEEE80211 | IFM_IEEE80211_OFDM12, IF_Mbps(12) }, \
845 { IFM_IEEE80211 | IFM_IEEE80211_OFDM18, IF_Mbps(18) }, \
846 { IFM_IEEE80211 | IFM_IEEE80211_OFDM24, IF_Mbps(24) }, \
847 { IFM_IEEE80211 | IFM_IEEE80211_OFDM36, IF_Mbps(36) }, \
848 { IFM_IEEE80211 | IFM_IEEE80211_OFDM48, IF_Mbps(48) }, \
849 { IFM_IEEE80211 | IFM_IEEE80211_OFDM54, IF_Mbps(54) }, \
850 { IFM_IEEE80211 | IFM_IEEE80211_OFDM72, IF_Mbps(72) }, \
851 \
852 { 0, 0 }, \
853 }
854
855 /*
856 * Status bit descriptions for the various media types.
857 */
858 struct ifmedia_status_description {
859 int ifms_type;
860 int ifms_valid;
861 int ifms_bit;
862 const char *ifms_string[2];
863 };
864
865 #define IFM_STATUS_DESC(ifms, bit) \
866 (ifms)->ifms_string[((ifms)->ifms_bit & (bit)) ? 1 : 0]
867
868 #define IFM_STATUS_DESCRIPTIONS { \
869 { IFM_GENERIC, IFM_AVALID, IFM_ACTIVE, \
870 { "no network", "active" } }, \
871 \
872 { IFM_ETHER, IFM_AVALID, IFM_ACTIVE, \
873 { "no carrier", "active" } }, \
874 \
875 { IFM_FDDI, IFM_AVALID, IFM_ACTIVE, \
876 { "no ring", "inserted" } }, \
877 \
878 { IFM_TOKEN, IFM_AVALID, IFM_ACTIVE, \
879 { "no ring", "inserted" } }, \
880 \
881 { IFM_IEEE80211, IFM_AVALID, IFM_ACTIVE, \
882 { "no network", "active" } }, \
883 \
884 { IFM_CARP, IFM_AVALID, IFM_ACTIVE, \
885 { "backup", "master" } }, \
886 \
887 { 0, 0, 0, \
888 { NULL, NULL } }, \
889 }
890
891 #ifdef _KERNEL
892 #include <sys/mutex.h>
893 #include <sys/queue.h>
894
895 /*
896 * Driver callbacks for media status and change requests.
897 */
898 typedef int (*ifm_change_cb_t)(struct ifnet *);
899 typedef void (*ifm_stat_cb_t)(struct ifnet *, struct ifmediareq *);
900
901 /*
902 * In-kernel representation of a single supported media type.
903 */
904 struct ifmedia_entry {
905 TAILQ_ENTRY(ifmedia_entry) ifm_list;
906 u_int ifm_media; /* IFMWD: description of this media */
907 u_int ifm_data; /* for driver-specific use */
908 void *ifm_aux; /* for driver-specific use */
909 };
910
911 /*
912 * One of these goes into a network interface's softc structure.
913 * It is used to keep general media state.
914 *
915 * LOCKING
916 * =======
917 * The ifmedia is protected by a lock provided by the interface
918 * driver. All ifmedia API entry points (with the exception of one)
919 * are expect to be called with this mutex NOT HELD.
920 *
921 * ifmedia_ioctl() is called with the interface's if_ioctl_lock held,
922 * and thus the locking order is:
923 *
924 * IFNET_LOCK -> ifm_lock
925 *
926 * Driver callbacks (ifm_change / ifm_status) are called with ifm_lock HELD.
927 *
928 * Field markings and the corresponding locks:
929 *
930 * m: ifm_lock
931 * :: unlocked, stable
932 */
933 struct ifmedia {
934 kmutex_t *ifm_lock; /* :: mutex (provided by interface driver) */
935 u_int ifm_mask; /* :: IFMWD: mask of changes we don't care */
936 u_int ifm_media; /*
937 * m: IFMWD: current user-set media word.
938 *
939 * XXX some drivers misuse this entry as
940 * current active media word. Don't use this
941 * entry as this purpose but use driver
942 * specific entry if you don't use mii(4).
943 */
944 struct ifmedia_entry *ifm_cur; /*
945 * m: entry corresponding to
946 * ifm_media
947 */
948 TAILQ_HEAD(, ifmedia_entry) ifm_list; /*
949 * m: list of all supported
950 * media
951 */
952 ifm_change_cb_t ifm_change; /* :: media change driver callback */
953 ifm_stat_cb_t ifm_status; /* :: media status driver callback */
954 uintptr_t ifm_legacy; /* m: legacy driver handling */
955 };
956
957 #define ifmedia_lock(ifm) mutex_enter((ifm)->ifm_lock)
958 #define ifmedia_unlock(ifm) mutex_exit((ifm)->ifm_lock)
959 #define ifmedia_locked(ifm) mutex_owned((ifm)->ifm_lock)
960
961 #ifdef __IFMEDIA_PRIVATE
962 #define ifmedia_islegacy(ifm) ((ifm)->ifm_legacy)
963 void ifmedia_lock_for_legacy(struct ifmedia *);
964 void ifmedia_unlock_for_legacy(struct ifmedia *);
965
966 #define IFMEDIA_LOCK_FOR_LEGACY(ifm) \
967 do { \
968 if (ifmedia_islegacy(ifm)) \
969 ifmedia_lock_for_legacy(ifm); \
970 } while (/*CONSTCOND*/0)
971
972 #define IFMEDIA_UNLOCK_FOR_LEGACY(ifm) \
973 do { \
974 if (ifmedia_islegacy(ifm)) \
975 ifmedia_unlock_for_legacy(ifm); \
976 } while (/*CONSTCOND*/0)
977 #endif /* __IFMEDIA_PRIVATE */
978
979 /* Initialize an interface's struct if_media field. */
980 void ifmedia_init(struct ifmedia *, int, ifm_change_cb_t, ifm_stat_cb_t);
981 void ifmedia_init_with_lock(struct ifmedia *, int, ifm_change_cb_t,
982 ifm_stat_cb_t, kmutex_t *);
983
984 /* Release resourecs associated with an ifmedia. */
985 void ifmedia_fini(struct ifmedia *);
986
987
988 /* Add one supported medium to a struct ifmedia. */
989 void ifmedia_add(struct ifmedia *, int, int, void *);
990
991 /* Add an array (of ifmedia_entry) media to a struct ifmedia. */
992 void ifmedia_list_add(struct ifmedia *, struct ifmedia_entry *, int);
993
994 /* Set default media type on initialization. */
995 void ifmedia_set(struct ifmedia *ifm, int mword);
996
997 /* Common ioctl function for getting/setting media, called by driver. */
998 int ifmedia_ioctl(struct ifnet *, struct ifreq *, struct ifmedia *, u_long);
999
1000 /* Look up a media entry. */
1001 struct ifmedia_entry *ifmedia_match(struct ifmedia *, u_int, u_int);
1002
1003 /* Delete all media for a given media instance */
1004 void ifmedia_delete_instance(struct ifmedia *, u_int);
1005
1006 /* Remove all media */
1007 void ifmedia_removeall(struct ifmedia *);
1008
1009 /* Compute baudrate for a given media. */
1010 uint64_t ifmedia_baudrate(int);
1011
1012 /*
1013 * This is a thin wrapper around the ifmedia "change" callback that
1014 * is available to drivers to use within their own initialization
1015 * routines.
1016 *
1017 * IFMEDIA must be LOCKED.
1018 */
1019 int ifmedia_change(struct ifmedia *, struct ifnet *);
1020
1021 #else
1022 /* Functions for converting media to/from strings, in libutil/if_media.c */
1023 const char *get_media_type_string(int);
1024 const char *get_media_subtype_string(int);
1025 const char *get_media_mode_string(int);
1026 const char *get_media_option_string(int *);
1027 int get_media_mode(int, const char *);
1028 int get_media_subtype(int, const char *);
1029 int get_media_options(int, const char *, char **);
1030 int lookup_media_word(struct ifmedia_description *, int, const char *);
1031 #endif /* _KERNEL */
1032
1033 #endif /* !_NET_IF_MEDIA_H_ */
Cache object: 973b089902ce4736dbe2c8b581a16374
|