OSDN Git Service

Merge "ARM: dts: msm: remove CARVEOUT ION for msm8996 ivi multi-gvm vplatform"
[sagit-ice-cold/kernel_xiaomi_msm8998.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 mdio_device {
15         struct device dev;
16
17         const struct dev_pm_ops *pm_ops;
18         struct mii_bus *bus;
19
20         int (*bus_match)(struct device *dev, struct device_driver *drv);
21         void (*device_free)(struct mdio_device *mdiodev);
22         void (*device_remove)(struct mdio_device *mdiodev);
23
24         /* Bus address of the MDIO device (0-31) */
25         int addr;
26         int flags;
27 };
28 #define to_mdio_device(d) container_of(d, struct mdio_device, dev)
29
30 /* struct mdio_driver_common: Common to all MDIO drivers */
31 struct mdio_driver_common {
32         struct device_driver driver;
33         int flags;
34 };
35 #define MDIO_DEVICE_FLAG_PHY            1
36 #define to_mdio_common_driver(d) \
37         container_of(d, struct mdio_driver_common, driver)
38
39 /* struct mdio_driver: Generic MDIO driver */
40 struct mdio_driver {
41         struct mdio_driver_common mdiodrv;
42
43         /*
44          * Called during discovery.  Used to set
45          * up device-specific structures, if any
46          */
47         int (*probe)(struct mdio_device *mdiodev);
48
49         /* Clears up any memory if needed */
50         void (*remove)(struct mdio_device *mdiodev);
51 };
52 #define to_mdio_driver(d)                                               \
53         container_of(to_mdio_common_driver(d), struct mdio_driver, mdiodrv)
54
55 void mdio_device_free(struct mdio_device *mdiodev);
56 struct mdio_device *mdio_device_create(struct mii_bus *bus, int addr);
57 int mdio_device_register(struct mdio_device *mdiodev);
58 void mdio_device_remove(struct mdio_device *mdiodev);
59 int mdio_driver_register(struct mdio_driver *drv);
60 void mdio_driver_unregister(struct mdio_driver *drv);
61
62 static inline bool mdio_phy_id_is_c45(int phy_id)
63 {
64         return (phy_id & MDIO_PHY_ID_C45) && !(phy_id & ~MDIO_PHY_ID_C45_MASK);
65 }
66
67 static inline __u16 mdio_phy_id_prtad(int phy_id)
68 {
69         return (phy_id & MDIO_PHY_ID_PRTAD) >> 5;
70 }
71
72 static inline __u16 mdio_phy_id_devad(int phy_id)
73 {
74         return phy_id & MDIO_PHY_ID_DEVAD;
75 }
76
77 /**
78  * struct mdio_if_info - Ethernet controller MDIO interface
79  * @prtad: PRTAD of the PHY (%MDIO_PRTAD_NONE if not present/unknown)
80  * @mmds: Mask of MMDs expected to be present in the PHY.  This must be
81  *      non-zero unless @prtad = %MDIO_PRTAD_NONE.
82  * @mode_support: MDIO modes supported.  If %MDIO_SUPPORTS_C22 is set then
83  *      MII register access will be passed through with @devad =
84  *      %MDIO_DEVAD_NONE.  If %MDIO_EMULATE_C22 is set then access to
85  *      commonly used clause 22 registers will be translated into
86  *      clause 45 registers.
87  * @dev: Net device structure
88  * @mdio_read: Register read function; returns value or negative error code
89  * @mdio_write: Register write function; returns 0 or negative error code
90  */
91 struct mdio_if_info {
92         int prtad;
93         u32 mmds;
94         unsigned mode_support;
95
96         struct net_device *dev;
97         int (*mdio_read)(struct net_device *dev, int prtad, int devad,
98                          u16 addr);
99         int (*mdio_write)(struct net_device *dev, int prtad, int devad,
100                           u16 addr, u16 val);
101 };
102
103 #define MDIO_PRTAD_NONE                 (-1)
104 #define MDIO_DEVAD_NONE                 (-1)
105 #define MDIO_SUPPORTS_C22               1
106 #define MDIO_SUPPORTS_C45               2
107 #define MDIO_EMULATE_C22                4
108
109 struct ethtool_cmd;
110 struct ethtool_pauseparam;
111 extern int mdio45_probe(struct mdio_if_info *mdio, int prtad);
112 extern int mdio_set_flag(const struct mdio_if_info *mdio,
113                          int prtad, int devad, u16 addr, int mask,
114                          bool sense);
115 extern int mdio45_links_ok(const struct mdio_if_info *mdio, u32 mmds);
116 extern int mdio45_nway_restart(const struct mdio_if_info *mdio);
117 extern void mdio45_ethtool_gset_npage(const struct mdio_if_info *mdio,
118                                       struct ethtool_cmd *ecmd,
119                                       u32 npage_adv, u32 npage_lpa);
120
121 /**
122  * mdio45_ethtool_gset - get settings for ETHTOOL_GSET
123  * @mdio: MDIO interface
124  * @ecmd: Ethtool request structure
125  *
126  * Since the CSRs for auto-negotiation using next pages are not fully
127  * standardised, this function does not attempt to decode them.  Use
128  * mdio45_ethtool_gset_npage() to specify advertisement bits from next
129  * pages.
130  */
131 static inline void mdio45_ethtool_gset(const struct mdio_if_info *mdio,
132                                        struct ethtool_cmd *ecmd)
133 {
134         mdio45_ethtool_gset_npage(mdio, ecmd, 0, 0);
135 }
136
137 extern int mdio_mii_ioctl(const struct mdio_if_info *mdio,
138                           struct mii_ioctl_data *mii_data, int cmd);
139
140 /**
141  * mmd_eee_cap_to_ethtool_sup_t
142  * @eee_cap: value of the MMD EEE Capability register
143  *
144  * A small helper function that translates MMD EEE Capability (3.20) bits
145  * to ethtool supported settings.
146  */
147 static inline u32 mmd_eee_cap_to_ethtool_sup_t(u16 eee_cap)
148 {
149         u32 supported = 0;
150
151         if (eee_cap & MDIO_EEE_100TX)
152                 supported |= SUPPORTED_100baseT_Full;
153         if (eee_cap & MDIO_EEE_1000T)
154                 supported |= SUPPORTED_1000baseT_Full;
155         if (eee_cap & MDIO_EEE_10GT)
156                 supported |= SUPPORTED_10000baseT_Full;
157         if (eee_cap & MDIO_EEE_1000KX)
158                 supported |= SUPPORTED_1000baseKX_Full;
159         if (eee_cap & MDIO_EEE_10GKX4)
160                 supported |= SUPPORTED_10000baseKX4_Full;
161         if (eee_cap & MDIO_EEE_10GKR)
162                 supported |= SUPPORTED_10000baseKR_Full;
163
164         return supported;
165 }
166
167 /**
168  * mmd_eee_adv_to_ethtool_adv_t
169  * @eee_adv: value of the MMD EEE Advertisement/Link Partner Ability registers
170  *
171  * A small helper function that translates the MMD EEE Advertisment (7.60)
172  * and MMD EEE Link Partner Ability (7.61) bits to ethtool advertisement
173  * settings.
174  */
175 static inline u32 mmd_eee_adv_to_ethtool_adv_t(u16 eee_adv)
176 {
177         u32 adv = 0;
178
179         if (eee_adv & MDIO_EEE_100TX)
180                 adv |= ADVERTISED_100baseT_Full;
181         if (eee_adv & MDIO_EEE_1000T)
182                 adv |= ADVERTISED_1000baseT_Full;
183         if (eee_adv & MDIO_EEE_10GT)
184                 adv |= ADVERTISED_10000baseT_Full;
185         if (eee_adv & MDIO_EEE_1000KX)
186                 adv |= ADVERTISED_1000baseKX_Full;
187         if (eee_adv & MDIO_EEE_10GKX4)
188                 adv |= ADVERTISED_10000baseKX4_Full;
189         if (eee_adv & MDIO_EEE_10GKR)
190                 adv |= ADVERTISED_10000baseKR_Full;
191
192         return adv;
193 }
194
195 /**
196  * ethtool_adv_to_mmd_eee_adv_t
197  * @adv: the ethtool advertisement settings
198  *
199  * A small helper function that translates ethtool advertisement settings
200  * to EEE advertisements for the MMD EEE Advertisement (7.60) and
201  * MMD EEE Link Partner Ability (7.61) registers.
202  */
203 static inline u16 ethtool_adv_to_mmd_eee_adv_t(u32 adv)
204 {
205         u16 reg = 0;
206
207         if (adv & ADVERTISED_100baseT_Full)
208                 reg |= MDIO_EEE_100TX;
209         if (adv & ADVERTISED_1000baseT_Full)
210                 reg |= MDIO_EEE_1000T;
211         if (adv & ADVERTISED_10000baseT_Full)
212                 reg |= MDIO_EEE_10GT;
213         if (adv & ADVERTISED_1000baseKX_Full)
214                 reg |= MDIO_EEE_1000KX;
215         if (adv & ADVERTISED_10000baseKX4_Full)
216                 reg |= MDIO_EEE_10GKX4;
217         if (adv & ADVERTISED_10000baseKR_Full)
218                 reg |= MDIO_EEE_10GKR;
219
220         return reg;
221 }
222
223 #endif /* __LINUX_MDIO_H__ */