~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/linux/mdio.h

Version: ~ [ linux-5.3-rc5 ] ~ [ linux-5.2.9 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.67 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.139 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.189 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.189 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.72 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * linux/mdio.h: definitions for MDIO (clause 45) transceivers
  3  * Copyright 2006-2009 Solarflare Communications Inc.
  4  *
  5  * This program is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 as published
  7  * by the Free Software Foundation, incorporated herein by reference.
  8  */
  9 #ifndef __LINUX_MDIO_H__
 10 #define __LINUX_MDIO_H__
 11 
 12 #include <uapi/linux/mdio.h>
 13 #include <linux/mod_devicetable.h>
 14 
 15 struct mii_bus;
 16 
 17 /* Multiple levels of nesting are possible. However typically this is
 18  * limited to nested DSA like layer, a MUX layer, and the normal
 19  * user. Instead of trying to handle the general case, just define
 20  * these cases.
 21  */
 22 enum mdio_mutex_lock_class {
 23         MDIO_MUTEX_NORMAL,
 24         MDIO_MUTEX_MUX,
 25         MDIO_MUTEX_NESTED,
 26 };
 27 
 28 struct mdio_device {
 29         struct device dev;
 30 
 31         const struct dev_pm_ops *pm_ops;
 32         struct mii_bus *bus;
 33         char modalias[MDIO_NAME_SIZE];
 34 
 35         int (*bus_match)(struct device *dev, struct device_driver *drv);
 36         void (*device_free)(struct mdio_device *mdiodev);
 37         void (*device_remove)(struct mdio_device *mdiodev);
 38 
 39         /* Bus address of the MDIO device (0-31) */
 40         int addr;
 41         int flags;
 42 };
 43 #define to_mdio_device(d) container_of(d, struct mdio_device, dev)
 44 
 45 /* struct mdio_driver_common: Common to all MDIO drivers */
 46 struct mdio_driver_common {
 47         struct device_driver driver;
 48         int flags;
 49 };
 50 #define MDIO_DEVICE_FLAG_PHY            1
 51 #define to_mdio_common_driver(d) \
 52         container_of(d, struct mdio_driver_common, driver)
 53 
 54 /* struct mdio_driver: Generic MDIO driver */
 55 struct mdio_driver {
 56         struct mdio_driver_common mdiodrv;
 57 
 58         /*
 59          * Called during discovery.  Used to set
 60          * up device-specific structures, if any
 61          */
 62         int (*probe)(struct mdio_device *mdiodev);
 63 
 64         /* Clears up any memory if needed */
 65         void (*remove)(struct mdio_device *mdiodev);
 66 };
 67 #define to_mdio_driver(d)                                               \
 68         container_of(to_mdio_common_driver(d), struct mdio_driver, mdiodrv)
 69 
 70 void mdio_device_free(struct mdio_device *mdiodev);
 71 struct mdio_device *mdio_device_create(struct mii_bus *bus, int addr);
 72 int mdio_device_register(struct mdio_device *mdiodev);
 73 void mdio_device_remove(struct mdio_device *mdiodev);
 74 int mdio_driver_register(struct mdio_driver *drv);
 75 void mdio_driver_unregister(struct mdio_driver *drv);
 76 int mdio_device_bus_match(struct device *dev, struct device_driver *drv);
 77 
 78 static inline bool mdio_phy_id_is_c45(int phy_id)
 79 {
 80         return (phy_id & MDIO_PHY_ID_C45) && !(phy_id & ~MDIO_PHY_ID_C45_MASK);
 81 }
 82 
 83 static inline __u16 mdio_phy_id_prtad(int phy_id)
 84 {
 85         return (phy_id & MDIO_PHY_ID_PRTAD) >> 5;
 86 }
 87 
 88 static inline __u16 mdio_phy_id_devad(int phy_id)
 89 {
 90         return phy_id & MDIO_PHY_ID_DEVAD;
 91 }
 92 
 93 /**
 94  * struct mdio_if_info - Ethernet controller MDIO interface
 95  * @prtad: PRTAD of the PHY (%MDIO_PRTAD_NONE if not present/unknown)
 96  * @mmds: Mask of MMDs expected to be present in the PHY.  This must be
 97  *      non-zero unless @prtad = %MDIO_PRTAD_NONE.
 98  * @mode_support: MDIO modes supported.  If %MDIO_SUPPORTS_C22 is set then
 99  *      MII register access will be passed through with @devad =
100  *      %MDIO_DEVAD_NONE.  If %MDIO_EMULATE_C22 is set then access to
101  *      commonly used clause 22 registers will be translated into
102  *      clause 45 registers.
103  * @dev: Net device structure
104  * @mdio_read: Register read function; returns value or negative error code
105  * @mdio_write: Register write function; returns 0 or negative error code
106  */
107 struct mdio_if_info {
108         int prtad;
109         u32 mmds;
110         unsigned mode_support;
111 
112         struct net_device *dev;
113         int (*mdio_read)(struct net_device *dev, int prtad, int devad,
114                          u16 addr);
115         int (*mdio_write)(struct net_device *dev, int prtad, int devad,
116                           u16 addr, u16 val);
117 };
118 
119 #define MDIO_PRTAD_NONE                 (-1)
120 #define MDIO_DEVAD_NONE                 (-1)
121 #define MDIO_SUPPORTS_C22               1
122 #define MDIO_SUPPORTS_C45               2
123 #define MDIO_EMULATE_C22                4
124 
125 struct ethtool_cmd;
126 struct ethtool_pauseparam;
127 extern int mdio45_probe(struct mdio_if_info *mdio, int prtad);
128 extern int mdio_set_flag(const struct mdio_if_info *mdio,
129                          int prtad, int devad, u16 addr, int mask,
130                          bool sense);
131 extern int mdio45_links_ok(const struct mdio_if_info *mdio, u32 mmds);
132 extern int mdio45_nway_restart(const struct mdio_if_info *mdio);
133 extern void mdio45_ethtool_gset_npage(const struct mdio_if_info *mdio,
134                                       struct ethtool_cmd *ecmd,
135                                       u32 npage_adv, u32 npage_lpa);
136 extern void
137 mdio45_ethtool_ksettings_get_npage(const struct mdio_if_info *mdio,
138                                    struct ethtool_link_ksettings *cmd,
139                                    u32 npage_adv, u32 npage_lpa);
140 
141 /**
142  * mdio45_ethtool_gset - get settings for ETHTOOL_GSET
143  * @mdio: MDIO interface
144  * @ecmd: Ethtool request structure
145  *
146  * Since the CSRs for auto-negotiation using next pages are not fully
147  * standardised, this function does not attempt to decode them.  Use
148  * mdio45_ethtool_gset_npage() to specify advertisement bits from next
149  * pages.
150  */
151 static inline void mdio45_ethtool_gset(const struct mdio_if_info *mdio,
152                                        struct ethtool_cmd *ecmd)
153 {
154         mdio45_ethtool_gset_npage(mdio, ecmd, 0, 0);
155 }
156 
157 /**
158  * mdio45_ethtool_ksettings_get - get settings for ETHTOOL_GLINKSETTINGS
159  * @mdio: MDIO interface
160  * @cmd: Ethtool request structure
161  *
162  * Since the CSRs for auto-negotiation using next pages are not fully
163  * standardised, this function does not attempt to decode them.  Use
164  * mdio45_ethtool_ksettings_get_npage() to specify advertisement bits
165  * from next pages.
166  */
167 static inline void
168 mdio45_ethtool_ksettings_get(const struct mdio_if_info *mdio,
169                              struct ethtool_link_ksettings *cmd)
170 {
171         mdio45_ethtool_ksettings_get_npage(mdio, cmd, 0, 0);
172 }
173 
174 extern int mdio_mii_ioctl(const struct mdio_if_info *mdio,
175                           struct mii_ioctl_data *mii_data, int cmd);
176 
177 /**
178  * mmd_eee_cap_to_ethtool_sup_t
179  * @eee_cap: value of the MMD EEE Capability register
180  *
181  * A small helper function that translates MMD EEE Capability (3.20) bits
182  * to ethtool supported settings.
183  */
184 static inline u32 mmd_eee_cap_to_ethtool_sup_t(u16 eee_cap)
185 {
186         u32 supported = 0;
187 
188         if (eee_cap & MDIO_EEE_100TX)
189                 supported |= SUPPORTED_100baseT_Full;
190         if (eee_cap & MDIO_EEE_1000T)
191                 supported |= SUPPORTED_1000baseT_Full;
192         if (eee_cap & MDIO_EEE_10GT)
193                 supported |= SUPPORTED_10000baseT_Full;
194         if (eee_cap & MDIO_EEE_1000KX)
195                 supported |= SUPPORTED_1000baseKX_Full;
196         if (eee_cap & MDIO_EEE_10GKX4)
197                 supported |= SUPPORTED_10000baseKX4_Full;
198         if (eee_cap & MDIO_EEE_10GKR)
199                 supported |= SUPPORTED_10000baseKR_Full;
200 
201         return supported;
202 }
203 
204 /**
205  * mmd_eee_adv_to_ethtool_adv_t
206  * @eee_adv: value of the MMD EEE Advertisement/Link Partner Ability registers
207  *
208  * A small helper function that translates the MMD EEE Advertisment (7.60)
209  * and MMD EEE Link Partner Ability (7.61) bits to ethtool advertisement
210  * settings.
211  */
212 static inline u32 mmd_eee_adv_to_ethtool_adv_t(u16 eee_adv)
213 {
214         u32 adv = 0;
215 
216         if (eee_adv & MDIO_EEE_100TX)
217                 adv |= ADVERTISED_100baseT_Full;
218         if (eee_adv & MDIO_EEE_1000T)
219                 adv |= ADVERTISED_1000baseT_Full;
220         if (eee_adv & MDIO_EEE_10GT)
221                 adv |= ADVERTISED_10000baseT_Full;
222         if (eee_adv & MDIO_EEE_1000KX)
223                 adv |= ADVERTISED_1000baseKX_Full;
224         if (eee_adv & MDIO_EEE_10GKX4)
225                 adv |= ADVERTISED_10000baseKX4_Full;
226         if (eee_adv & MDIO_EEE_10GKR)
227                 adv |= ADVERTISED_10000baseKR_Full;
228 
229         return adv;
230 }
231 
232 /**
233  * ethtool_adv_to_mmd_eee_adv_t
234  * @adv: the ethtool advertisement settings
235  *
236  * A small helper function that translates ethtool advertisement settings
237  * to EEE advertisements for the MMD EEE Advertisement (7.60) and
238  * MMD EEE Link Partner Ability (7.61) registers.
239  */
240 static inline u16 ethtool_adv_to_mmd_eee_adv_t(u32 adv)
241 {
242         u16 reg = 0;
243 
244         if (adv & ADVERTISED_100baseT_Full)
245                 reg |= MDIO_EEE_100TX;
246         if (adv & ADVERTISED_1000baseT_Full)
247                 reg |= MDIO_EEE_1000T;
248         if (adv & ADVERTISED_10000baseT_Full)
249                 reg |= MDIO_EEE_10GT;
250         if (adv & ADVERTISED_1000baseKX_Full)
251                 reg |= MDIO_EEE_1000KX;
252         if (adv & ADVERTISED_10000baseKX4_Full)
253                 reg |= MDIO_EEE_10GKX4;
254         if (adv & ADVERTISED_10000baseKR_Full)
255                 reg |= MDIO_EEE_10GKR;
256 
257         return reg;
258 }
259 
260 int mdiobus_read(struct mii_bus *bus, int addr, u32 regnum);
261 int mdiobus_read_nested(struct mii_bus *bus, int addr, u32 regnum);
262 int mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val);
263 int mdiobus_write_nested(struct mii_bus *bus, int addr, u32 regnum, u16 val);
264 
265 int mdiobus_register_device(struct mdio_device *mdiodev);
266 int mdiobus_unregister_device(struct mdio_device *mdiodev);
267 bool mdiobus_is_registered_device(struct mii_bus *bus, int addr);
268 struct phy_device *mdiobus_get_phy(struct mii_bus *bus, int addr);
269 
270 /**
271  * mdio_module_driver() - Helper macro for registering mdio drivers
272  *
273  * Helper macro for MDIO drivers which do not do anything special in module
274  * init/exit. Each module may only use this macro once, and calling it
275  * replaces module_init() and module_exit().
276  */
277 #define mdio_module_driver(_mdio_driver)                                \
278 static int __init mdio_module_init(void)                                \
279 {                                                                       \
280         return mdio_driver_register(&_mdio_driver);                     \
281 }                                                                       \
282 module_init(mdio_module_init);                                          \
283 static void __exit mdio_module_exit(void)                               \
284 {                                                                       \
285         mdio_driver_unregister(&_mdio_driver);                          \
286 }                                                                       \
287 module_exit(mdio_module_exit)
288 
289 #endif /* __LINUX_MDIO_H__ */
290 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp