]> git.karo-electronics.de Git - karo-tx-linux.git/blob - include/linux/mdio.h
phy: Add an mdio_device structure
[karo-tx-linux.git] / include / linux / mdio.h
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
14 struct mii_bus;
15
16 struct mdio_device {
17         struct device dev;
18
19         struct mii_bus *bus;
20         /* Bus address of the MDIO device (0-31) */
21         int addr;
22 };
23 #define to_mdio_device(d) container_of(d, struct mdio_device, dev)
24
25 static inline bool mdio_phy_id_is_c45(int phy_id)
26 {
27         return (phy_id & MDIO_PHY_ID_C45) && !(phy_id & ~MDIO_PHY_ID_C45_MASK);
28 }
29
30 static inline __u16 mdio_phy_id_prtad(int phy_id)
31 {
32         return (phy_id & MDIO_PHY_ID_PRTAD) >> 5;
33 }
34
35 static inline __u16 mdio_phy_id_devad(int phy_id)
36 {
37         return phy_id & MDIO_PHY_ID_DEVAD;
38 }
39
40 /**
41  * struct mdio_if_info - Ethernet controller MDIO interface
42  * @prtad: PRTAD of the PHY (%MDIO_PRTAD_NONE if not present/unknown)
43  * @mmds: Mask of MMDs expected to be present in the PHY.  This must be
44  *      non-zero unless @prtad = %MDIO_PRTAD_NONE.
45  * @mode_support: MDIO modes supported.  If %MDIO_SUPPORTS_C22 is set then
46  *      MII register access will be passed through with @devad =
47  *      %MDIO_DEVAD_NONE.  If %MDIO_EMULATE_C22 is set then access to
48  *      commonly used clause 22 registers will be translated into
49  *      clause 45 registers.
50  * @dev: Net device structure
51  * @mdio_read: Register read function; returns value or negative error code
52  * @mdio_write: Register write function; returns 0 or negative error code
53  */
54 struct mdio_if_info {
55         int prtad;
56         u32 mmds;
57         unsigned mode_support;
58
59         struct net_device *dev;
60         int (*mdio_read)(struct net_device *dev, int prtad, int devad,
61                          u16 addr);
62         int (*mdio_write)(struct net_device *dev, int prtad, int devad,
63                           u16 addr, u16 val);
64 };
65
66 #define MDIO_PRTAD_NONE                 (-1)
67 #define MDIO_DEVAD_NONE                 (-1)
68 #define MDIO_SUPPORTS_C22               1
69 #define MDIO_SUPPORTS_C45               2
70 #define MDIO_EMULATE_C22                4
71
72 struct ethtool_cmd;
73 struct ethtool_pauseparam;
74 extern int mdio45_probe(struct mdio_if_info *mdio, int prtad);
75 extern int mdio_set_flag(const struct mdio_if_info *mdio,
76                          int prtad, int devad, u16 addr, int mask,
77                          bool sense);
78 extern int mdio45_links_ok(const struct mdio_if_info *mdio, u32 mmds);
79 extern int mdio45_nway_restart(const struct mdio_if_info *mdio);
80 extern void mdio45_ethtool_gset_npage(const struct mdio_if_info *mdio,
81                                       struct ethtool_cmd *ecmd,
82                                       u32 npage_adv, u32 npage_lpa);
83
84 /**
85  * mdio45_ethtool_gset - get settings for ETHTOOL_GSET
86  * @mdio: MDIO interface
87  * @ecmd: Ethtool request structure
88  *
89  * Since the CSRs for auto-negotiation using next pages are not fully
90  * standardised, this function does not attempt to decode them.  Use
91  * mdio45_ethtool_gset_npage() to specify advertisement bits from next
92  * pages.
93  */
94 static inline void mdio45_ethtool_gset(const struct mdio_if_info *mdio,
95                                        struct ethtool_cmd *ecmd)
96 {
97         mdio45_ethtool_gset_npage(mdio, ecmd, 0, 0);
98 }
99
100 extern int mdio_mii_ioctl(const struct mdio_if_info *mdio,
101                           struct mii_ioctl_data *mii_data, int cmd);
102
103 /**
104  * mmd_eee_cap_to_ethtool_sup_t
105  * @eee_cap: value of the MMD EEE Capability register
106  *
107  * A small helper function that translates MMD EEE Capability (3.20) bits
108  * to ethtool supported settings.
109  */
110 static inline u32 mmd_eee_cap_to_ethtool_sup_t(u16 eee_cap)
111 {
112         u32 supported = 0;
113
114         if (eee_cap & MDIO_EEE_100TX)
115                 supported |= SUPPORTED_100baseT_Full;
116         if (eee_cap & MDIO_EEE_1000T)
117                 supported |= SUPPORTED_1000baseT_Full;
118         if (eee_cap & MDIO_EEE_10GT)
119                 supported |= SUPPORTED_10000baseT_Full;
120         if (eee_cap & MDIO_EEE_1000KX)
121                 supported |= SUPPORTED_1000baseKX_Full;
122         if (eee_cap & MDIO_EEE_10GKX4)
123                 supported |= SUPPORTED_10000baseKX4_Full;
124         if (eee_cap & MDIO_EEE_10GKR)
125                 supported |= SUPPORTED_10000baseKR_Full;
126
127         return supported;
128 }
129
130 /**
131  * mmd_eee_adv_to_ethtool_adv_t
132  * @eee_adv: value of the MMD EEE Advertisement/Link Partner Ability registers
133  *
134  * A small helper function that translates the MMD EEE Advertisment (7.60)
135  * and MMD EEE Link Partner Ability (7.61) bits to ethtool advertisement
136  * settings.
137  */
138 static inline u32 mmd_eee_adv_to_ethtool_adv_t(u16 eee_adv)
139 {
140         u32 adv = 0;
141
142         if (eee_adv & MDIO_EEE_100TX)
143                 adv |= ADVERTISED_100baseT_Full;
144         if (eee_adv & MDIO_EEE_1000T)
145                 adv |= ADVERTISED_1000baseT_Full;
146         if (eee_adv & MDIO_EEE_10GT)
147                 adv |= ADVERTISED_10000baseT_Full;
148         if (eee_adv & MDIO_EEE_1000KX)
149                 adv |= ADVERTISED_1000baseKX_Full;
150         if (eee_adv & MDIO_EEE_10GKX4)
151                 adv |= ADVERTISED_10000baseKX4_Full;
152         if (eee_adv & MDIO_EEE_10GKR)
153                 adv |= ADVERTISED_10000baseKR_Full;
154
155         return adv;
156 }
157
158 /**
159  * ethtool_adv_to_mmd_eee_adv_t
160  * @adv: the ethtool advertisement settings
161  *
162  * A small helper function that translates ethtool advertisement settings
163  * to EEE advertisements for the MMD EEE Advertisement (7.60) and
164  * MMD EEE Link Partner Ability (7.61) registers.
165  */
166 static inline u16 ethtool_adv_to_mmd_eee_adv_t(u32 adv)
167 {
168         u16 reg = 0;
169
170         if (adv & ADVERTISED_100baseT_Full)
171                 reg |= MDIO_EEE_100TX;
172         if (adv & ADVERTISED_1000baseT_Full)
173                 reg |= MDIO_EEE_1000T;
174         if (adv & ADVERTISED_10000baseT_Full)
175                 reg |= MDIO_EEE_10GT;
176         if (adv & ADVERTISED_1000baseKX_Full)
177                 reg |= MDIO_EEE_1000KX;
178         if (adv & ADVERTISED_10000baseKX4_Full)
179                 reg |= MDIO_EEE_10GKX4;
180         if (adv & ADVERTISED_10000baseKR_Full)
181                 reg |= MDIO_EEE_10GKR;
182
183         return reg;
184 }
185
186 int mdiobus_read(struct mii_bus *bus, int addr, u32 regnum);
187 int mdiobus_read_nested(struct mii_bus *bus, int addr, u32 regnum);
188 int mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val);
189 int mdiobus_write_nested(struct mii_bus *bus, int addr, u32 regnum, u16 val);
190
191 #endif /* __LINUX_MDIO_H__ */