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