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