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

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

Version: ~ [ linux-5.3 ] ~ [ linux-5.2.15 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.73 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.144 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.193 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.193 ] ~ [ 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.73 ] ~ [ 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 gpio_desc;
 16 struct mii_bus;
 17 
 18 /* Multiple levels of nesting are possible. However typically this is
 19  * limited to nested DSA like layer, a MUX layer, and the normal
 20  * user. Instead of trying to handle the general case, just define
 21  * these cases.
 22  */
 23 enum mdio_mutex_lock_class {
 24         MDIO_MUTEX_NORMAL,
 25         MDIO_MUTEX_MUX,
 26         MDIO_MUTEX_NESTED,
 27 };
 28 
 29 struct mdio_device {
 30         struct device dev;
 31 
 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         struct gpio_desc *reset;
 43         unsigned int reset_assert_delay;
 44         unsigned int reset_deassert_delay;
 45 };
 46 #define to_mdio_device(d) container_of(d, struct mdio_device, dev)
 47 
 48 /* struct mdio_driver_common: Common to all MDIO drivers */
 49 struct mdio_driver_common {
 50         struct device_driver driver;
 51         int flags;
 52 };
 53 #define MDIO_DEVICE_FLAG_PHY            1
 54 #define to_mdio_common_driver(d) \
 55         container_of(d, struct mdio_driver_common, driver)
 56 
 57 /* struct mdio_driver: Generic MDIO driver */
 58 struct mdio_driver {
 59         struct mdio_driver_common mdiodrv;
 60 
 61         /*
 62          * Called during discovery.  Used to set
 63          * up device-specific structures, if any
 64          */
 65         int (*probe)(struct mdio_device *mdiodev);
 66 
 67         /* Clears up any memory if needed */
 68         void (*remove)(struct mdio_device *mdiodev);
 69 };
 70 #define to_mdio_driver(d)                                               \
 71         container_of(to_mdio_common_driver(d), struct mdio_driver, mdiodrv)
 72 
 73 void mdio_device_free(struct mdio_device *mdiodev);
 74 struct mdio_device *mdio_device_create(struct mii_bus *bus, int addr);
 75 int mdio_device_register(struct mdio_device *mdiodev);
 76 void mdio_device_remove(struct mdio_device *mdiodev);
 77 void mdio_device_reset(struct mdio_device *mdiodev, int value);
 78 int mdio_driver_register(struct mdio_driver *drv);
 79 void mdio_driver_unregister(struct mdio_driver *drv);
 80 int mdio_device_bus_match(struct device *dev, struct device_driver *drv);
 81 
 82 static inline bool mdio_phy_id_is_c45(int phy_id)
 83 {
 84         return (phy_id & MDIO_PHY_ID_C45) && !(phy_id & ~MDIO_PHY_ID_C45_MASK);
 85 }
 86 
 87 static inline __u16 mdio_phy_id_prtad(int phy_id)
 88 {
 89         return (phy_id & MDIO_PHY_ID_PRTAD) >> 5;
 90 }
 91 
 92 static inline __u16 mdio_phy_id_devad(int phy_id)
 93 {
 94         return phy_id & MDIO_PHY_ID_DEVAD;
 95 }
 96 
 97 /**
 98  * struct mdio_if_info - Ethernet controller MDIO interface
 99  * @prtad: PRTAD of the PHY (%MDIO_PRTAD_NONE if not present/unknown)
100  * @mmds: Mask of MMDs expected to be present in the PHY.  This must be
101  *      non-zero unless @prtad = %MDIO_PRTAD_NONE.
102  * @mode_support: MDIO modes supported.  If %MDIO_SUPPORTS_C22 is set then
103  *      MII register access will be passed through with @devad =
104  *      %MDIO_DEVAD_NONE.  If %MDIO_EMULATE_C22 is set then access to
105  *      commonly used clause 22 registers will be translated into
106  *      clause 45 registers.
107  * @dev: Net device structure
108  * @mdio_read: Register read function; returns value or negative error code
109  * @mdio_write: Register write function; returns 0 or negative error code
110  */
111 struct mdio_if_info {
112         int prtad;
113         u32 mmds;
114         unsigned mode_support;
115 
116         struct net_device *dev;
117         int (*mdio_read)(struct net_device *dev, int prtad, int devad,
118                          u16 addr);
119         int (*mdio_write)(struct net_device *dev, int prtad, int devad,
120                           u16 addr, u16 val);
121 };
122 
123 #define MDIO_PRTAD_NONE                 (-1)
124 #define MDIO_DEVAD_NONE                 (-1)
125 #define MDIO_SUPPORTS_C22               1
126 #define MDIO_SUPPORTS_C45               2
127 #define MDIO_EMULATE_C22                4
128 
129 struct ethtool_cmd;
130 struct ethtool_pauseparam;
131 extern int mdio45_probe(struct mdio_if_info *mdio, int prtad);
132 extern int mdio_set_flag(const struct mdio_if_info *mdio,
133                          int prtad, int devad, u16 addr, int mask,
134                          bool sense);
135 extern int mdio45_links_ok(const struct mdio_if_info *mdio, u32 mmds);
136 extern int mdio45_nway_restart(const struct mdio_if_info *mdio);
137 extern void mdio45_ethtool_gset_npage(const struct mdio_if_info *mdio,
138                                       struct ethtool_cmd *ecmd,
139                                       u32 npage_adv, u32 npage_lpa);
140 extern void
141 mdio45_ethtool_ksettings_get_npage(const struct mdio_if_info *mdio,
142                                    struct ethtool_link_ksettings *cmd,
143                                    u32 npage_adv, u32 npage_lpa);
144 
145 /**
146  * mdio45_ethtool_gset - get settings for ETHTOOL_GSET
147  * @mdio: MDIO interface
148  * @ecmd: Ethtool request structure
149  *
150  * Since the CSRs for auto-negotiation using next pages are not fully
151  * standardised, this function does not attempt to decode them.  Use
152  * mdio45_ethtool_gset_npage() to specify advertisement bits from next
153  * pages.
154  */
155 static inline void mdio45_ethtool_gset(const struct mdio_if_info *mdio,
156                                        struct ethtool_cmd *ecmd)
157 {
158         mdio45_ethtool_gset_npage(mdio, ecmd, 0, 0);
159 }
160 
161 /**
162  * mdio45_ethtool_ksettings_get - get settings for ETHTOOL_GLINKSETTINGS
163  * @mdio: MDIO interface
164  * @cmd: Ethtool request structure
165  *
166  * Since the CSRs for auto-negotiation using next pages are not fully
167  * standardised, this function does not attempt to decode them.  Use
168  * mdio45_ethtool_ksettings_get_npage() to specify advertisement bits
169  * from next pages.
170  */
171 static inline void
172 mdio45_ethtool_ksettings_get(const struct mdio_if_info *mdio,
173                              struct ethtool_link_ksettings *cmd)
174 {
175         mdio45_ethtool_ksettings_get_npage(mdio, cmd, 0, 0);
176 }
177 
178 extern int mdio_mii_ioctl(const struct mdio_if_info *mdio,
179                           struct mii_ioctl_data *mii_data, int cmd);
180 
181 /**
182  * mmd_eee_cap_to_ethtool_sup_t
183  * @eee_cap: value of the MMD EEE Capability register
184  *
185  * A small helper function that translates MMD EEE Capability (3.20) bits
186  * to ethtool supported settings.
187  */
188 static inline u32 mmd_eee_cap_to_ethtool_sup_t(u16 eee_cap)
189 {
190         u32 supported = 0;
191 
192         if (eee_cap & MDIO_EEE_100TX)
193                 supported |= SUPPORTED_100baseT_Full;
194         if (eee_cap & MDIO_EEE_1000T)
195                 supported |= SUPPORTED_1000baseT_Full;
196         if (eee_cap & MDIO_EEE_10GT)
197                 supported |= SUPPORTED_10000baseT_Full;
198         if (eee_cap & MDIO_EEE_1000KX)
199                 supported |= SUPPORTED_1000baseKX_Full;
200         if (eee_cap & MDIO_EEE_10GKX4)
201                 supported |= SUPPORTED_10000baseKX4_Full;
202         if (eee_cap & MDIO_EEE_10GKR)
203                 supported |= SUPPORTED_10000baseKR_Full;
204 
205         return supported;
206 }
207 
208 /**
209  * mmd_eee_adv_to_ethtool_adv_t
210  * @eee_adv: value of the MMD EEE Advertisement/Link Partner Ability registers
211  *
212  * A small helper function that translates the MMD EEE Advertisment (7.60)
213  * and MMD EEE Link Partner Ability (7.61) bits to ethtool advertisement
214  * settings.
215  */
216 static inline u32 mmd_eee_adv_to_ethtool_adv_t(u16 eee_adv)
217 {
218         u32 adv = 0;
219 
220         if (eee_adv & MDIO_EEE_100TX)
221                 adv |= ADVERTISED_100baseT_Full;
222         if (eee_adv & MDIO_EEE_1000T)
223                 adv |= ADVERTISED_1000baseT_Full;
224         if (eee_adv & MDIO_EEE_10GT)
225                 adv |= ADVERTISED_10000baseT_Full;
226         if (eee_adv & MDIO_EEE_1000KX)
227                 adv |= ADVERTISED_1000baseKX_Full;
228         if (eee_adv & MDIO_EEE_10GKX4)
229                 adv |= ADVERTISED_10000baseKX4_Full;
230         if (eee_adv & MDIO_EEE_10GKR)
231                 adv |= ADVERTISED_10000baseKR_Full;
232 
233         return adv;
234 }
235 
236 /**
237  * ethtool_adv_to_mmd_eee_adv_t
238  * @adv: the ethtool advertisement settings
239  *
240  * A small helper function that translates ethtool advertisement settings
241  * to EEE advertisements for the MMD EEE Advertisement (7.60) and
242  * MMD EEE Link Partner Ability (7.61) registers.
243  */
244 static inline u16 ethtool_adv_to_mmd_eee_adv_t(u32 adv)
245 {
246         u16 reg = 0;
247 
248         if (adv & ADVERTISED_100baseT_Full)
249                 reg |= MDIO_EEE_100TX;
250         if (adv & ADVERTISED_1000baseT_Full)
251                 reg |= MDIO_EEE_1000T;
252         if (adv & ADVERTISED_10000baseT_Full)
253                 reg |= MDIO_EEE_10GT;
254         if (adv & ADVERTISED_1000baseKX_Full)
255                 reg |= MDIO_EEE_1000KX;
256         if (adv & ADVERTISED_10000baseKX4_Full)
257                 reg |= MDIO_EEE_10GKX4;
258         if (adv & ADVERTISED_10000baseKR_Full)
259                 reg |= MDIO_EEE_10GKR;
260 
261         return reg;
262 }
263 
264 /**
265  * linkmode_adv_to_mii_10gbt_adv_t
266  * @advertising: the linkmode advertisement settings
267  *
268  * A small helper function that translates linkmode advertisement
269  * settings to phy autonegotiation advertisements for the C45
270  * 10GBASE-T AN CONTROL (7.32) register.
271  */
272 static inline u32 linkmode_adv_to_mii_10gbt_adv_t(unsigned long *advertising)
273 {
274         u32 result = 0;
275 
276         if (linkmode_test_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
277                               advertising))
278                 result |= MDIO_AN_10GBT_CTRL_ADV2_5G;
279         if (linkmode_test_bit(ETHTOOL_LINK_MODE_5000baseT_Full_BIT,
280                               advertising))
281                 result |= MDIO_AN_10GBT_CTRL_ADV5G;
282         if (linkmode_test_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT,
283                               advertising))
284                 result |= MDIO_AN_10GBT_CTRL_ADV10G;
285 
286         return result;
287 }
288 
289 /**
290  * mii_10gbt_stat_mod_linkmode_lpa_t
291  * @advertising: target the linkmode advertisement settings
292  * @adv: value of the C45 10GBASE-T AN STATUS register
293  *
294  * A small helper function that translates C45 10GBASE-T AN STATUS register bits
295  * to linkmode advertisement settings. Other bits in advertising aren't changed.
296  */
297 static inline void mii_10gbt_stat_mod_linkmode_lpa_t(unsigned long *advertising,
298                                                      u32 lpa)
299 {
300         linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
301                          advertising, lpa & MDIO_AN_10GBT_STAT_LP2_5G);
302         linkmode_mod_bit(ETHTOOL_LINK_MODE_5000baseT_Full_BIT,
303                          advertising, lpa & MDIO_AN_10GBT_STAT_LP5G);
304         linkmode_mod_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT,
305                          advertising, lpa & MDIO_AN_10GBT_STAT_LP10G);
306 }
307 
308 int __mdiobus_read(struct mii_bus *bus, int addr, u32 regnum);
309 int __mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val);
310 
311 int mdiobus_read(struct mii_bus *bus, int addr, u32 regnum);
312 int mdiobus_read_nested(struct mii_bus *bus, int addr, u32 regnum);
313 int mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val);
314 int mdiobus_write_nested(struct mii_bus *bus, int addr, u32 regnum, u16 val);
315 
316 int mdiobus_register_device(struct mdio_device *mdiodev);
317 int mdiobus_unregister_device(struct mdio_device *mdiodev);
318 bool mdiobus_is_registered_device(struct mii_bus *bus, int addr);
319 struct phy_device *mdiobus_get_phy(struct mii_bus *bus, int addr);
320 
321 /**
322  * mdio_module_driver() - Helper macro for registering mdio drivers
323  *
324  * Helper macro for MDIO drivers which do not do anything special in module
325  * init/exit. Each module may only use this macro once, and calling it
326  * replaces module_init() and module_exit().
327  */
328 #define mdio_module_driver(_mdio_driver)                                \
329 static int __init mdio_module_init(void)                                \
330 {                                                                       \
331         return mdio_driver_register(&_mdio_driver);                     \
332 }                                                                       \
333 module_init(mdio_module_init);                                          \
334 static void __exit mdio_module_exit(void)                               \
335 {                                                                       \
336         mdio_driver_unregister(&_mdio_driver);                          \
337 }                                                                       \
338 module_exit(mdio_module_exit)
339 
340 #endif /* __LINUX_MDIO_H__ */
341 

~ [ 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