RTEMS CPU Kit with SuperCore  4.11.3
rtems_mii_ioctl.h
Go to the documentation of this file.
1 /* Simple (default) implementation for SIOCGIFMEDIA/SIOCSIFMEDIA
2  * to be used by ethernet drivers [from their ioctl].
3  *
4  * NOTE: This much simpler than the BSD ifmedia API
5  */
6 
7 /*
8  * Authorship
9  * ----------
10  * This software was created by
11  * Till Straumann <strauman@slac.stanford.edu>, 2005,
12  * Stanford Linear Accelerator Center, Stanford University.
13  *
14  * Acknowledgement of sponsorship
15  * ------------------------------
16  * This software was produced by
17  * the Stanford Linear Accelerator Center, Stanford University,
18  * under Contract DE-AC03-76SFO0515 with the Department of Energy.
19  *
20  * Government disclaimer of liability
21  * ----------------------------------
22  * Neither the United States nor the United States Department of Energy,
23  * nor any of their employees, makes any warranty, express or implied, or
24  * assumes any legal liability or responsibility for the accuracy,
25  * completeness, or usefulness of any data, apparatus, product, or process
26  * disclosed, or represents that its use would not infringe privately owned
27  * rights.
28  *
29  * Stanford disclaimer of liability
30  * --------------------------------
31  * Stanford University makes no representations or warranties, express or
32  * implied, nor assumes any liability for the use of this software.
33  *
34  * Stanford disclaimer of copyright
35  * --------------------------------
36  * Stanford University, owner of the copyright, hereby disclaims its
37  * copyright and all other rights in this software. Hence, anyone may
38  * freely use it for any purpose without restriction.
39  *
40  * Maintenance of notices
41  * ----------------------
42  * In the interest of clarity regarding the origin and status of this
43  * SLAC software, this and all the preceding Stanford University notices
44  * are to remain affixed to any copy or derivative of this software made
45  * or distributed by the recipient and are to be affixed to any copy of
46  * software made or distributed by the recipient that contains a copy or
47  * derivative of this software.
48  *
49  * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03
50  */
51 #ifndef RTEMS_MII_IOCTL_H
52 #define RTEMS_MII_IOCTL_H
53 
54 #include <dev/mii/mii.h> /* MII register definitions */
55 #include <net/if_media.h> /* media word definitions; rest of API (ifmedia) unused! */
56 
57 #ifdef __cplusplus
58 extern "C" {
59 #endif
60 
61 #if defined(_KERNEL) || defined(KERNEL) || \
62  defined(__KERNEL) || defined(__KERNEL__)
63 /* mdio routines to be provided by driver */
64 
65 /* read mii register 'reg' at 'phy' (-1 meaning any/currently active)
66  * RETURNS 0 on success, -1 otherwise (e.g., illegal phy)
67  */
68 typedef int (*rtems_mdio_read_func) (int phy, void *uarg, unsigned reg,
69  uint32_t * pval);
70 
71 /* write mii register 'reg' at 'phy' (-1 meaning any/currently active)
72  * RETURNS 0 on success, -1 otherwise (e.g., illegal phy)
73  */
74 typedef int (*rtems_mdio_write_func) (int phy, void *uarg, unsigned reg,
75  uint32_t val);
76 
77 /* Values to this must be provided by the driver */
78 struct rtems_mdio_info {
79  rtems_mdio_read_func mdio_r;
80  rtems_mdio_write_func mdio_w;
81  unsigned has_gmii:1; /* supports gigabit */
82 };
83 
84 /* Implement SIOCSIFMEDIA/SIOCGIFMEDIA; get/set the current media word. Note
85  * that this does NOT implement the full BSD 'ifmedia' API; also, it only
86  * implements IFM_ETHER...
87  *
88  * INPUT:
89  * SIOCGIFMEDIA: the media word must set the phy instance (-1 for 'any')
90  *
91  */
92 int
93 rtems_mii_ioctl (struct rtems_mdio_info *info, void *uarg, uint32_t cmd,
94  int *media);
95 
96 #endif
97 
98 /* The driver flags have the following meaning (SIOCGIFMEDIA only):
99  */
100 #define IFM_LINK_OK IFM_FLAG0
101 #define IFM_ANEG_DIS IFM_FLAG1 /* autoneg. disabled; media forced */
102 
103 /* convert a media word to a string;
104  *
105  * RETURNS: number of characters written to 'buf'
106  *
107  * INPUT: if 'bufsz' is set to IFMEDIA2STR_PRINT_TO_FILE, 'buf' can be a FILE
108  * pointer where the info is printed insted. This can be NULL in which
109  * case 'stdout' is used.
110  */
111 
112 #define IFMEDIA2STR_PRINT_TO_FILE 0
113 
114 int rtems_ifmedia2str (int media, char *buf, int bufsz);
115 
116 /* convert a string to a media word
117  * RETURNS: 0 on failure (unrecognized or invalid mode);
118  * valid results have always at least IFM_ETHER set.
119  *
120  * In addition to IFM_SUBTYPE_ETHERNET_DESCRIPTIONS and
121  * IFM_SUBTYPE_ETHERNET_ALIASES, the strings
122  *
123  * '10' [ '0' [ '0' ]] 'b' [ 'ase' ] ( 't' | 'T' )
124  * (* if 100bT [ 'x' | 'X' ] is required here *)
125  *
126  * are recognized (e.g., 10bT, 100bTX)
127  *
128  * if any of the strings 'full' or 'FDX' or 'fdx' is present, a full-duplex mode
129  * is selected (half-duplex otherwise).
130  * e.g., '100bTx-full'
131  */
132 
133 int rtems_str2ifmedia (const char *str, int phy);
134 
135 #ifdef __cplusplus
136 }
137 #endif
138 
139 #endif