if_media.h revision 1.9 1 /* $NetBSD: if_media.h,v 1.9 1998/08/06 19:16:37 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 1998 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 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40 /*
41 * Copyright (c) 1997
42 * Jonathan Stone and Jason R. Thorpe. All rights reserved.
43 *
44 * This software is derived from information provided by Matt Thomas.
45 *
46 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
48 * are met:
49 * 1. Redistributions of source code must retain the above copyright
50 * notice, this list of conditions and the following disclaimer.
51 * 2. Redistributions in binary form must reproduce the above copyright
52 * notice, this list of conditions and the following disclaimer in the
53 * documentation and/or other materials provided with the distribution.
54 * 3. All advertising materials mentioning features or use of this software
55 * must display the following acknowledgement:
56 * This product includes software developed by Jonathan Stone
57 * and Jason R. Thorpe for the NetBSD Project.
58 * 4. The names of the authors may not be used to endorse or promote products
59 * derived from this software without specific prior written permission.
60 *
61 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
62 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
63 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
64 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
65 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
66 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
67 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
68 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
69 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
70 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
71 * SUCH DAMAGE.
72 */
73
74 #ifndef _NET_IF_MEDIA_H_
75 #define _NET_IF_MEDIA_H_
76
77 /*
78 * Prototypes and definitions for BSD/OS-compatible network interface
79 * media selection.
80 *
81 * Where it is safe to do so, this code strays slightly from the BSD/OS
82 * design. Software which uses the API (device drivers, basically)
83 * shouldn't notice any difference.
84 *
85 * Many thanks to Matt Thomas for providing the information necessary
86 * to implement this interface.
87 */
88
89 #ifdef _KERNEL
90
91 #include <sys/queue.h>
92
93 /*
94 * Driver callbacks for media status and change requests.
95 */
96 typedef int (*ifm_change_cb_t) __P((struct ifnet *ifp));
97 typedef void (*ifm_stat_cb_t) __P((struct ifnet *ifp, struct ifmediareq *req));
98
99 /*
100 * In-kernel representation of a single supported media type.
101 */
102 struct ifmedia_entry {
103 LIST_ENTRY(ifmedia_entry) ifm_list;
104 int ifm_media; /* description of this media attachment */
105 int ifm_data; /* for driver-specific use */
106 void *ifm_aux; /* for driver-specific use */
107 };
108
109 /*
110 * One of these goes into a network interface's softc structure.
111 * It is used to keep general media state.
112 */
113 struct ifmedia {
114 int ifm_mask; /* mask of changes we don't care about */
115 int ifm_media; /* current user-set media word */
116 struct ifmedia_entry *ifm_cur; /* currently selected media */
117 LIST_HEAD(, ifmedia_entry) ifm_list; /* list of all supported media */
118 ifm_change_cb_t ifm_change; /* media change driver callback */
119 ifm_stat_cb_t ifm_status; /* media status driver callback */
120 };
121
122 /* Initialize an interface's struct if_media field. */
123 void ifmedia_init __P((struct ifmedia *ifm, int dontcare_mask,
124 ifm_change_cb_t change_callback, ifm_stat_cb_t status_callback));
125
126 /* Add one supported medium to a struct ifmedia. */
127 void ifmedia_add __P((struct ifmedia *ifm, int mword, int data, void *aux));
128
129 /* Add an array (of ifmedia_entry) media to a struct ifmedia. */
130 void ifmedia_list_add(struct ifmedia *mp, struct ifmedia_entry *lp,
131 int count);
132
133 /* Set default media type on initialization. */
134 void ifmedia_set __P((struct ifmedia *ifm, int mword));
135
136 /* Common ioctl function for getting/setting media, called by driver. */
137 int ifmedia_ioctl __P((struct ifnet *ifp, struct ifreq *ifr,
138 struct ifmedia *ifm, u_long cmd));
139
140 #endif /*_KERNEL */
141
142 /*
143 * if_media Options word:
144 * Bits Use
145 * ---- -------
146 * 0-3 Media variant
147 * 4 RFU
148 * 5-7 Media type
149 * 8-15 Type specific options
150 * 16-19 RFU
151 * 20-27 Shared (global) options
152 * 28-31 Instance
153 */
154
155 /*
156 * Ethernet
157 */
158 #define IFM_ETHER 0x00000020
159 #define IFM_10_T 3 /* 10BaseT - RJ45 */
160 #define IFM_10_2 4 /* 10Base2 - Thinnet */
161 #define IFM_10_5 5 /* 10Base5 - AUI */
162 #define IFM_100_TX 6 /* 100BaseTX - RJ45 */
163 #define IFM_100_FX 7 /* 100BaseFX - Fiber */
164 #define IFM_100_T4 8 /* 100BaseT4 - 4 pair cat 3 */
165 #define IFM_100_VG 9 /* 100VG-AnyLAN */
166 #define IFM_100_T2 10 /* 100BaseT2 */
167 #define IFM_1000_FX 11 /* 1000BaseFX - gigabit over fiber */
168 #define IFM_10_STP 12 /* 10BaseT over shielded TP */
169 #define IFM_10_FL 13 /* 10BaseFL - Fiber */
170
171 /*
172 * Token ring
173 */
174 #define IFM_TOKEN 0x00000040
175 #define IFM_TOK_STP4 3 /* Shielded twisted pair 4m - DB9 */
176 #define IFM_TOK_STP16 4 /* Shielded twisted pair 16m - DB9 */
177 #define IFM_TOK_UTP4 5 /* Unshielded twisted pair 4m - RJ45 */
178 #define IFM_TOK_UTP16 6 /* Unshielded twisted pair 16m - RJ45 */
179 #define IFM_TOK_ETR 0x00000200 /* Early token release */
180 #define IFM_TOK_SRCRT 0x00000400 /* Enable source routing features */
181 #define IFM_TOK_ALLR 0x00000800 /* All routes / Single route bcast */
182
183 /*
184 * FDDI
185 */
186 #define IFM_FDDI 0x00000060
187 #define IFM_FDDI_SMF 3 /* Single-mode fiber */
188 #define IFM_FDDI_MMF 4 /* Multi-mode fiber */
189 #define IFM_FDDI_UTP 5 /* CDDI / UTP */
190 #define IFM_FDDI_DA 0x00000100 /* Dual attach / single attach */
191
192 /*
193 * Shared media sub-types
194 */
195 #define IFM_AUTO 0 /* Autoselect best media */
196 #define IFM_MANUAL 1 /* Jumper/dipswitch selects media */
197 #define IFM_NONE 2 /* Deselect all media */
198
199 /*
200 * Shared options
201 */
202 #define IFM_FDX 0x00100000 /* Force full duplex */
203 #define IFM_HDX 0x00200000 /* Force half duplex */
204 #define IFM_FLAG0 0x01000000 /* Driver defined flag */
205 #define IFM_FLAG1 0x02000000 /* Driver defined flag */
206 #define IFM_FLAG2 0x04000000 /* Driver defined flag */
207 #define IFM_LOOP 0x08000000 /* Put hardware in loopback */
208
209 /*
210 * Masks
211 */
212 #define IFM_NMASK 0x000000e0 /* Network type */
213 #define IFM_TMASK 0x0000000f /* Media sub-type */
214 #define IFM_IMASK 0xf0000000 /* Instance */
215 #define IFM_ISHIFT 28 /* Instance shift */
216 #define IFM_OMASK 0x0000ff00 /* Type specific options */
217 #define IFM_GMASK 0x0ff00000 /* Global options */
218
219 #define IFM_NMIN IFM_ETHER /* lowest Network type */
220 #define IFM_NMAX IFM_NMASK /* highest Network type */
221
222 /*
223 * Status bits
224 */
225 #define IFM_AVALID 0x00000001 /* Active bit valid */
226 #define IFM_ACTIVE 0x00000002 /* Interface attached to working net */
227
228 /*
229 * Macros to extract various bits of information from the media word.
230 */
231 #define IFM_TYPE(x) ((x) & IFM_NMASK)
232 #define IFM_SUBTYPE(x) ((x) & IFM_TMASK)
233 #define IFM_INST(x) (((x) & IFM_IMASK) >> IFM_ISHIFT)
234 #define IFM_OPTIONS(x) ((x) & (IFM_OMASK|IFM_GMASK))
235
236 /*
237 * Macro to create a media word.
238 */
239 #define IFM_MAKEWORD(type, subtype, options, instance) \
240 ((type) | (subtype) | (options) | ((instance) << IFM_ISHIFT))
241
242 /*
243 * NetBSD extension not defined in the BSDI API. This is used in various
244 * places to get the canonical description for a given type/subtype.
245 *
246 * In the subtype and mediaopt descriptions, the valid TYPE bits are OR'd
247 * in to indicate which TYPE the subtype/option corresponds to. If no
248 * TYPE is present, it is a shared media/mediaopt.
249 *
250 * Note that these are parsed case-insensitive.
251 *
252 * Order is important. The first matching entry is the canonical name
253 * for a media type; subsequent matches are aliases.
254 */
255 struct ifmedia_description {
256 int ifmt_word; /* word value; may be masked */
257 const char *ifmt_string; /* description */
258 };
259
260 #define IFM_TYPE_DESCRIPTIONS { \
261 { IFM_ETHER, "Ethernet" }, \
262 { IFM_ETHER, "ether" }, \
263 { IFM_TOKEN, "TokenRing" }, \
264 { IFM_TOKEN, "token" }, \
265 { IFM_FDDI, "FDDI" }, \
266 { 0, NULL }, \
267 }
268
269 #define IFM_TYPE_MATCH(dt, t) \
270 (IFM_TYPE((dt)) == 0 || IFM_TYPE((dt)) == IFM_TYPE((t)))
271
272 #define IFM_SUBTYPE_DESCRIPTIONS { \
273 { IFM_AUTO, "autoselect" }, \
274 { IFM_AUTO, "auto" }, \
275 { IFM_MANUAL, "manual" }, \
276 { IFM_NONE, "none" }, \
277 \
278 { IFM_ETHER|IFM_10_T, "10baseT" }, \
279 { IFM_ETHER|IFM_10_T, "UTP" }, \
280 { IFM_ETHER|IFM_10_T, "10UTP" }, \
281 { IFM_ETHER|IFM_10_2, "10base2" }, \
282 { IFM_ETHER|IFM_10_2, "BNC" }, \
283 { IFM_ETHER|IFM_10_2, "10BNC" }, \
284 { IFM_ETHER|IFM_10_5, "10base5" }, \
285 { IFM_ETHER|IFM_10_5, "AUI" }, \
286 { IFM_ETHER|IFM_10_5, "10AUI" }, \
287 { IFM_ETHER|IFM_100_TX, "100baseTX" }, \
288 { IFM_ETHER|IFM_100_TX, "100TX" }, \
289 { IFM_ETHER|IFM_100_FX, "100baseFX" }, \
290 { IFM_ETHER|IFM_100_FX, "100FX" }, \
291 { IFM_ETHER|IFM_100_T4, "100baseT4" }, \
292 { IFM_ETHER|IFM_100_T4, "100T4" }, \
293 { IFM_ETHER|IFM_100_VG, "100baseVG" }, \
294 { IFM_ETHER|IFM_100_VG, "100VG" }, \
295 { IFM_ETHER|IFM_100_T2, "100baseT2" }, \
296 { IFM_ETHER|IFM_100_T2, "100T2" }, \
297 { IFM_ETHER|IFM_1000_FX, "1000baseFX" }, \
298 { IFM_ETHER|IFM_1000_FX, "1000FX" }, \
299 { IFM_ETHER|IFM_10_STP, "10baseSTP" }, \
300 { IFM_ETHER|IFM_10_STP, "STP" }, \
301 { IFM_ETHER|IFM_10_STP, "10STP" }, \
302 { IFM_ETHER|IFM_10_FL, "10baseFL" }, \
303 { IFM_ETHER|IFM_10_FL, "FL" }, \
304 { IFM_ETHER|IFM_10_FL, "10FL" }, \
305 \
306 { IFM_TOKEN|IFM_TOK_STP4, "DB9/4Mbit" }, \
307 { IFM_TOKEN|IFM_TOK_STP4, "4STP" }, \
308 { IFM_TOKEN|IFM_TOK_STP16, "DB9/16Mbit" }, \
309 { IFM_TOKEN|IFM_TOK_STP16, "16STP" }, \
310 { IFM_TOKEN|IFM_TOK_UTP4, "UTP/4Mbit" }, \
311 { IFM_TOKEN|IFM_TOK_UTP4, "4UTP" }, \
312 { IFM_TOKEN|IFM_TOK_UTP16, "UTP/16Mbit" }, \
313 { IFM_TOKEN|IFM_TOK_UTP16, "16UTP" }, \
314 \
315 { IFM_FDDI|IFM_FDDI_SMF, "Single-mode" }, \
316 { IFM_FDDI|IFM_FDDI_SMF, "SMF" }, \
317 { IFM_FDDI|IFM_FDDI_MMF, "Multi-mode" }, \
318 { IFM_FDDI|IFM_FDDI_MMF, "MMF" }, \
319 { IFM_FDDI|IFM_FDDI_UTP, "UTP" }, \
320 { IFM_FDDI|IFM_FDDI_UTP, "CDDI" }, \
321 \
322 { 0, NULL }, \
323 }
324
325 #define IFM_OPTION_DESCRIPTIONS { \
326 { IFM_FDX, "full-duplex" }, \
327 { IFM_FDX, "fdx" }, \
328 { IFM_HDX, "half-duplex" }, \
329 { IFM_HDX, "hdx" }, \
330 { IFM_FLAG0, "flag0" }, \
331 { IFM_FLAG1, "flag1" }, \
332 { IFM_FLAG2, "flag2" }, \
333 { IFM_LOOP, "loopback" }, \
334 { IFM_LOOP, "hw-loopback"}, \
335 { IFM_LOOP, "loop" }, \
336 \
337 { IFM_TOKEN|IFM_TOK_ETR, "EarlyTokenRelease" }, \
338 { IFM_TOKEN|IFM_TOK_ETR, "ETR" }, \
339 { IFM_TOKEN|IFM_TOK_SRCRT, "SourceRouting" }, \
340 { IFM_TOKEN|IFM_TOK_SRCRT, "SRCRT" }, \
341 { IFM_TOKEN|IFM_TOK_ALLR, "AllRoutes" }, \
342 { IFM_TOKEN|IFM_TOK_ALLR, "ALLR" }, \
343 \
344 { IFM_FDDI|IFM_FDDI_DA, "dual-attach" }, \
345 { IFM_FDDI|IFM_FDDI_DA, "das" }, \
346 \
347 { 0, NULL }, \
348 }
349
350 #endif /* _NET_IF_MEDIA_H_ */
351