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