Merge branch 'work.aio' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
[linux-block.git] / include / linux / phylink.h
CommitLineData
9525ae83
RK
1#ifndef NETDEV_PCS_H
2#define NETDEV_PCS_H
3
4#include <linux/phy.h>
5#include <linux/spinlock.h>
6#include <linux/workqueue.h>
7
8struct device_node;
9struct ethtool_cmd;
8fa7b9b6 10struct fwnode_handle;
9525ae83
RK
11struct net_device;
12
13enum {
14 MLO_PAUSE_NONE,
15 MLO_PAUSE_ASYM = BIT(0),
16 MLO_PAUSE_SYM = BIT(1),
17 MLO_PAUSE_RX = BIT(2),
18 MLO_PAUSE_TX = BIT(3),
19 MLO_PAUSE_TXRX_MASK = MLO_PAUSE_TX | MLO_PAUSE_RX,
20 MLO_PAUSE_AN = BIT(4),
21
22 MLO_AN_PHY = 0, /* Conventional PHY */
23 MLO_AN_FIXED, /* Fixed-link mode */
86a362c4 24 MLO_AN_INBAND, /* In-band protocol */
9525ae83
RK
25};
26
27static inline bool phylink_autoneg_inband(unsigned int mode)
28{
86a362c4 29 return mode == MLO_AN_INBAND;
9525ae83
RK
30}
31
8796c892
RK
32/**
33 * struct phylink_link_state - link state structure
34 * @advertising: ethtool bitmask containing advertised link modes
35 * @lp_advertising: ethtool bitmask containing link partner advertised link
36 * modes
37 * @interface: link &typedef phy_interface_t mode
38 * @speed: link speed, one of the SPEED_* constants.
39 * @duplex: link duplex mode, one of DUPLEX_* constants.
40 * @pause: link pause state, described by MLO_PAUSE_* constants.
41 * @link: true if the link is up.
42 * @an_enabled: true if autonegotiation is enabled/desired.
43 * @an_complete: true if autonegotiation has completed.
44 */
9525ae83
RK
45struct phylink_link_state {
46 __ETHTOOL_DECLARE_LINK_MODE_MASK(advertising);
47 __ETHTOOL_DECLARE_LINK_MODE_MASK(lp_advertising);
8796c892 48 phy_interface_t interface;
9525ae83
RK
49 int speed;
50 int duplex;
51 int pause;
52 unsigned int link:1;
53 unsigned int an_enabled:1;
54 unsigned int an_complete:1;
55};
56
8796c892
RK
57/**
58 * struct phylink_mac_ops - MAC operations structure.
59 * @validate: Validate and update the link configuration.
60 * @mac_link_state: Read the current link state from the hardware.
61 * @mac_config: configure the MAC for the selected mode and state.
62 * @mac_an_restart: restart 802.3z BaseX autonegotiation.
63 * @mac_link_down: take the link down.
64 * @mac_link_up: allow the link to come up.
65 *
66 * The individual methods are described more fully below.
67 */
9525ae83 68struct phylink_mac_ops {
9525ae83
RK
69 void (*validate)(struct net_device *ndev, unsigned long *supported,
70 struct phylink_link_state *state);
8796c892
RK
71 int (*mac_link_state)(struct net_device *ndev,
72 struct phylink_link_state *state);
9525ae83
RK
73 void (*mac_config)(struct net_device *ndev, unsigned int mode,
74 const struct phylink_link_state *state);
9525ae83 75 void (*mac_an_restart)(struct net_device *ndev);
c6ab3008
FF
76 void (*mac_link_down)(struct net_device *ndev, unsigned int mode,
77 phy_interface_t interface);
8796c892 78 void (*mac_link_up)(struct net_device *ndev, unsigned int mode,
c6ab3008 79 phy_interface_t interface,
8796c892 80 struct phy_device *phy);
9525ae83
RK
81};
82
8796c892
RK
83#if 0 /* For kernel-doc purposes only. */
84/**
85 * validate - Validate and update the link configuration
86 * @ndev: a pointer to a &struct net_device for the MAC.
87 * @supported: ethtool bitmask for supported link modes.
88 * @state: a pointer to a &struct phylink_link_state.
89 *
90 * Clear bits in the @supported and @state->advertising masks that
91 * are not supportable by the MAC.
92 *
93 * Note that the PHY may be able to transform from one connection
94 * technology to another, so, eg, don't clear 1000BaseX just
95 * because the MAC is unable to BaseX mode. This is more about
96 * clearing unsupported speeds and duplex settings.
97 *
98 * If the @state->interface mode is %PHY_INTERFACE_MODE_1000BASEX
99 * or %PHY_INTERFACE_MODE_2500BASEX, select the appropriate mode
100 * based on @state->advertising and/or @state->speed and update
101 * @state->interface accordingly.
102 */
103void validate(struct net_device *ndev, unsigned long *supported,
104 struct phylink_link_state *state);
105
106/**
107 * mac_link_state() - Read the current link state from the hardware
108 * @ndev: a pointer to a &struct net_device for the MAC.
109 * @state: a pointer to a &struct phylink_link_state.
110 *
111 * Read the current link state from the MAC, reporting the current
112 * speed in @state->speed, duplex mode in @state->duplex, pause mode
113 * in @state->pause using the %MLO_PAUSE_RX and %MLO_PAUSE_TX bits,
114 * negotiation completion state in @state->an_complete, and link
115 * up state in @state->link.
116 */
117int mac_link_state(struct net_device *ndev,
118 struct phylink_link_state *state);
119
120/**
121 * mac_config() - configure the MAC for the selected mode and state
122 * @ndev: a pointer to a &struct net_device for the MAC.
123 * @mode: one of %MLO_AN_FIXED, %MLO_AN_PHY, %MLO_AN_INBAND.
124 * @state: a pointer to a &struct phylink_link_state.
125 *
126 * The action performed depends on the currently selected mode:
127 *
128 * %MLO_AN_FIXED, %MLO_AN_PHY:
129 * Configure the specified @state->speed, @state->duplex and
130 * @state->pause (%MLO_PAUSE_TX / %MLO_PAUSE_RX) mode.
131 *
132 * %MLO_AN_INBAND:
133 * place the link in an inband negotiation mode (such as 802.3z
134 * 1000base-X or Cisco SGMII mode depending on the @state->interface
135 * mode). In both cases, link state management (whether the link
136 * is up or not) is performed by the MAC, and reported via the
137 * mac_link_state() callback. Changes in link state must be made
138 * by calling phylink_mac_change().
139 *
140 * If in 802.3z mode, the link speed is fixed, dependent on the
141 * @state->interface. Duplex is negotiated, and pause is advertised
142 * according to @state->an_enabled, @state->pause and
143 * @state->advertising flags. Beware of MACs which only support full
144 * duplex at gigabit and higher speeds.
145 *
146 * If in Cisco SGMII mode, the link speed and duplex mode are passed
147 * in the serial bitstream 16-bit configuration word, and the MAC
148 * should be configured to read these bits and acknowledge the
149 * configuration word. Nothing is advertised by the MAC. The MAC is
150 * responsible for reading the configuration word and configuring
151 * itself accordingly.
152 */
153void mac_config(struct net_device *ndev, unsigned int mode,
154 const struct phylink_link_state *state);
155
156/**
157 * mac_an_restart() - restart 802.3z BaseX autonegotiation
158 * @ndev: a pointer to a &struct net_device for the MAC.
159 */
160void mac_an_restart(struct net_device *ndev);
161
162/**
163 * mac_link_down() - take the link down
164 * @ndev: a pointer to a &struct net_device for the MAC.
165 * @mode: link autonegotiation mode
c6ab3008 166 * @interface: link &typedef phy_interface_t mode
8796c892
RK
167 *
168 * If @mode is not an in-band negotiation mode (as defined by
169 * phylink_autoneg_inband()), force the link down and disable any
c6ab3008
FF
170 * Energy Efficient Ethernet MAC configuration. Interface type
171 * selection must be done in mac_config().
8796c892 172 */
c6ab3008
FF
173void mac_link_down(struct net_device *ndev, unsigned int mode,
174 phy_interface_t interface);
8796c892
RK
175
176/**
177 * mac_link_up() - allow the link to come up
178 * @ndev: a pointer to a &struct net_device for the MAC.
179 * @mode: link autonegotiation mode
c6ab3008 180 * @interface: link &typedef phy_interface_t mode
8796c892
RK
181 * @phy: any attached phy
182 *
183 * If @mode is not an in-band negotiation mode (as defined by
184 * phylink_autoneg_inband()), allow the link to come up. If @phy
185 * is non-%NULL, configure Energy Efficient Ethernet by calling
186 * phy_init_eee() and perform appropriate MAC configuration for EEE.
c6ab3008 187 * Interface type selection must be done in mac_config().
8796c892
RK
188 */
189void mac_link_up(struct net_device *ndev, unsigned int mode,
c6ab3008 190 phy_interface_t interface,
8796c892
RK
191 struct phy_device *phy);
192#endif
193
8fa7b9b6 194struct phylink *phylink_create(struct net_device *, struct fwnode_handle *,
9525ae83
RK
195 phy_interface_t iface, const struct phylink_mac_ops *ops);
196void phylink_destroy(struct phylink *);
197
198int phylink_connect_phy(struct phylink *, struct phy_device *);
0a62964c 199int phylink_of_phy_connect(struct phylink *, struct device_node *, u32 flags);
9525ae83 200void phylink_disconnect_phy(struct phylink *);
1ac63e39
FF
201int phylink_fixed_state_cb(struct phylink *,
202 void (*cb)(struct net_device *dev,
203 struct phylink_link_state *));
9525ae83
RK
204
205void phylink_mac_change(struct phylink *, bool up);
206
207void phylink_start(struct phylink *);
208void phylink_stop(struct phylink *);
209
210void phylink_ethtool_get_wol(struct phylink *, struct ethtool_wolinfo *);
211int phylink_ethtool_set_wol(struct phylink *, struct ethtool_wolinfo *);
212
213int phylink_ethtool_ksettings_get(struct phylink *,
214 struct ethtool_link_ksettings *);
215int phylink_ethtool_ksettings_set(struct phylink *,
216 const struct ethtool_link_ksettings *);
217int phylink_ethtool_nway_reset(struct phylink *);
218void phylink_ethtool_get_pauseparam(struct phylink *,
219 struct ethtool_pauseparam *);
220int phylink_ethtool_set_pauseparam(struct phylink *,
221 struct ethtool_pauseparam *);
9525ae83
RK
222int phylink_get_eee_err(struct phylink *);
223int phylink_ethtool_get_eee(struct phylink *, struct ethtool_eee *);
224int phylink_ethtool_set_eee(struct phylink *, struct ethtool_eee *);
225int phylink_mii_ioctl(struct phylink *, struct ifreq *, int);
226
227#define phylink_zero(bm) \
228 bitmap_zero(bm, __ETHTOOL_LINK_MODE_MASK_NBITS)
229#define __phylink_do_bit(op, bm, mode) \
230 op(ETHTOOL_LINK_MODE_ ## mode ## _BIT, bm)
231
232#define phylink_set(bm, mode) __phylink_do_bit(__set_bit, bm, mode)
233#define phylink_clear(bm, mode) __phylink_do_bit(__clear_bit, bm, mode)
234#define phylink_test(bm, mode) __phylink_do_bit(test_bit, bm, mode)
235
236void phylink_set_port_modes(unsigned long *bits);
237
238#endif