Merge tag 'pull-18-rc1-work.mount' of git://git.kernel.org/pub/scm/linux/kernel/git...
[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,
4e5aeb41
RK
15 MLO_PAUSE_RX = BIT(0),
16 MLO_PAUSE_TX = BIT(1),
9525ae83 17 MLO_PAUSE_TXRX_MASK = MLO_PAUSE_TX | MLO_PAUSE_RX,
4e5aeb41 18 MLO_PAUSE_AN = BIT(2),
9525ae83
RK
19
20 MLO_AN_PHY = 0, /* Conventional PHY */
21 MLO_AN_FIXED, /* Fixed-link mode */
86a362c4 22 MLO_AN_INBAND, /* In-band protocol */
34ae2c09
RKO
23
24 MAC_SYM_PAUSE = BIT(0),
25 MAC_ASYM_PAUSE = BIT(1),
26 MAC_10HD = BIT(2),
27 MAC_10FD = BIT(3),
28 MAC_10 = MAC_10HD | MAC_10FD,
29 MAC_100HD = BIT(4),
30 MAC_100FD = BIT(5),
31 MAC_100 = MAC_100HD | MAC_100FD,
32 MAC_1000HD = BIT(6),
33 MAC_1000FD = BIT(7),
34 MAC_1000 = MAC_1000HD | MAC_1000FD,
35 MAC_2500FD = BIT(8),
36 MAC_5000FD = BIT(9),
37 MAC_10000FD = BIT(10),
38 MAC_20000FD = BIT(11),
39 MAC_25000FD = BIT(12),
40 MAC_40000FD = BIT(13),
41 MAC_50000FD = BIT(14),
42 MAC_56000FD = BIT(15),
43 MAC_100000FD = BIT(16),
44 MAC_200000FD = BIT(17),
45 MAC_400000FD = BIT(18),
9525ae83
RK
46};
47
48static inline bool phylink_autoneg_inband(unsigned int mode)
49{
86a362c4 50 return mode == MLO_AN_INBAND;
9525ae83
RK
51}
52
8796c892
RK
53/**
54 * struct phylink_link_state - link state structure
55 * @advertising: ethtool bitmask containing advertised link modes
56 * @lp_advertising: ethtool bitmask containing link partner advertised link
57 * modes
58 * @interface: link &typedef phy_interface_t mode
59 * @speed: link speed, one of the SPEED_* constants.
60 * @duplex: link duplex mode, one of DUPLEX_* constants.
61 * @pause: link pause state, described by MLO_PAUSE_* constants.
62 * @link: true if the link is up.
63 * @an_enabled: true if autonegotiation is enabled/desired.
64 * @an_complete: true if autonegotiation has completed.
65 */
9525ae83
RK
66struct phylink_link_state {
67 __ETHTOOL_DECLARE_LINK_MODE_MASK(advertising);
68 __ETHTOOL_DECLARE_LINK_MODE_MASK(lp_advertising);
8796c892 69 phy_interface_t interface;
9525ae83
RK
70 int speed;
71 int duplex;
72 int pause;
73 unsigned int link:1;
74 unsigned int an_enabled:1;
75 unsigned int an_complete:1;
76};
77
44cc27e4
IC
78enum phylink_op_type {
79 PHYLINK_NETDEV = 0,
43de6195 80 PHYLINK_DEV,
44cc27e4
IC
81};
82
83/**
84 * struct phylink_config - PHYLINK configuration structure
85 * @dev: a pointer to a struct device associated with the MAC
86 * @type: operation type of PHYLINK instance
3e5b1fec
RKO
87 * @legacy_pre_march2020: driver has not been updated for March 2020 updates
88 * (See commit 7cceb599d15d ("net: phylink: avoid mac_config calls")
5d682f5e
MCC
89 * @poll_fixed_state: if true, starts link_poll,
90 * if MAC link is at %MLO_AN_FIXED mode.
ab393850 91 * @ovr_an_inband: if true, override PCS to MLO_AN_INBAND
5d682f5e
MCC
92 * @get_fixed_state: callback to execute to determine the fixed link state,
93 * if MAC link is at %MLO_AN_FIXED mode.
d25f3a74
RKO
94 * @supported_interfaces: bitmap describing which PHY_INTERFACE_MODE_xxx
95 * are supported by the MAC/PCS.
34ae2c09 96 * @mac_capabilities: MAC pause/speed/duplex capabilities.
44cc27e4
IC
97 */
98struct phylink_config {
99 struct device *dev;
100 enum phylink_op_type type;
3e5b1fec 101 bool legacy_pre_march2020;
5c05c1db 102 bool poll_fixed_state;
ab393850 103 bool ovr_an_inband;
5c05c1db
RK
104 void (*get_fixed_state)(struct phylink_config *config,
105 struct phylink_link_state *state);
38c310eb 106 DECLARE_PHY_INTERFACE_MASK(supported_interfaces);
34ae2c09 107 unsigned long mac_capabilities;
44cc27e4
IC
108};
109
8796c892
RK
110/**
111 * struct phylink_mac_ops - MAC operations structure.
112 * @validate: Validate and update the link configuration.
d1e86325 113 * @mac_select_pcs: Select a PCS for the interface mode.
d46b7e4f 114 * @mac_pcs_get_state: Read the current link state from the hardware.
b7ad14c2 115 * @mac_prepare: prepare for a major reconfiguration of the interface.
8796c892 116 * @mac_config: configure the MAC for the selected mode and state.
b7ad14c2 117 * @mac_finish: finish a major reconfiguration of the interface.
8796c892
RK
118 * @mac_an_restart: restart 802.3z BaseX autonegotiation.
119 * @mac_link_down: take the link down.
120 * @mac_link_up: allow the link to come up.
121 *
122 * The individual methods are described more fully below.
123 */
9525ae83 124struct phylink_mac_ops {
44cc27e4
IC
125 void (*validate)(struct phylink_config *config,
126 unsigned long *supported,
9525ae83 127 struct phylink_link_state *state);
d1e86325
RKO
128 struct phylink_pcs *(*mac_select_pcs)(struct phylink_config *config,
129 phy_interface_t interface);
d46b7e4f
RK
130 void (*mac_pcs_get_state)(struct phylink_config *config,
131 struct phylink_link_state *state);
b7ad14c2
RK
132 int (*mac_prepare)(struct phylink_config *config, unsigned int mode,
133 phy_interface_t iface);
44cc27e4 134 void (*mac_config)(struct phylink_config *config, unsigned int mode,
9525ae83 135 const struct phylink_link_state *state);
b7ad14c2
RK
136 int (*mac_finish)(struct phylink_config *config, unsigned int mode,
137 phy_interface_t iface);
44cc27e4
IC
138 void (*mac_an_restart)(struct phylink_config *config);
139 void (*mac_link_down)(struct phylink_config *config, unsigned int mode,
c6ab3008 140 phy_interface_t interface);
91a208f2
RK
141 void (*mac_link_up)(struct phylink_config *config,
142 struct phy_device *phy, unsigned int mode,
143 phy_interface_t interface, int speed, int duplex,
144 bool tx_pause, bool rx_pause);
9525ae83
RK
145};
146
8796c892
RK
147#if 0 /* For kernel-doc purposes only. */
148/**
149 * validate - Validate and update the link configuration
44cc27e4 150 * @config: a pointer to a &struct phylink_config.
8796c892
RK
151 * @supported: ethtool bitmask for supported link modes.
152 * @state: a pointer to a &struct phylink_link_state.
153 *
154 * Clear bits in the @supported and @state->advertising masks that
155 * are not supportable by the MAC.
156 *
157 * Note that the PHY may be able to transform from one connection
158 * technology to another, so, eg, don't clear 1000BaseX just
159 * because the MAC is unable to BaseX mode. This is more about
32e454ef
RK
160 * clearing unsupported speeds and duplex settings. The port modes
161 * should not be cleared; phylink_set_port_modes() will help with this.
8796c892 162 *
d25f3a74
RKO
163 * When @config->supported_interfaces has been set, phylink will iterate
164 * over the supported interfaces to determine the full capability of the
165 * MAC. The validation function must not print errors if @state->interface
166 * is set to an unexpected value.
167 *
168 * When @config->supported_interfaces is empty, phylink will call this
169 * function with @state->interface set to %PHY_INTERFACE_MODE_NA, and
170 * expects the MAC driver to return all supported link modes.
32e454ef
RK
171 *
172 * If the @state->interface mode is not supported, then the @supported
173 * mask must be cleared.
8796c892 174 */
44cc27e4 175void validate(struct phylink_config *config, unsigned long *supported,
8796c892 176 struct phylink_link_state *state);
d1e86325
RKO
177/**
178 * mac_select_pcs: Select a PCS for the interface mode.
179 * @config: a pointer to a &struct phylink_config.
180 * @interface: PHY interface mode for PCS
181 *
182 * Return the &struct phylink_pcs for the specified interface mode, or
183 * NULL if none is required, or an error pointer on error.
184 *
185 * This must not modify any state. It is used to query which PCS should
186 * be used. Phylink will use this during validation to ensure that the
187 * configuration is valid, and when setting a configuration to internally
188 * set the PCS that will be used.
189 */
190struct phylink_pcs *mac_select_pcs(struct phylink_config *config,
191 phy_interface_t interface);
8796c892
RK
192
193/**
d46b7e4f 194 * mac_pcs_get_state() - Read the current inband link state from the hardware
44cc27e4 195 * @config: a pointer to a &struct phylink_config.
8796c892
RK
196 * @state: a pointer to a &struct phylink_link_state.
197 *
d46b7e4f
RK
198 * Read the current inband link state from the MAC PCS, reporting the
199 * current speed in @state->speed, duplex mode in @state->duplex, pause
200 * mode in @state->pause using the %MLO_PAUSE_RX and %MLO_PAUSE_TX bits,
201 * negotiation completion state in @state->an_complete, and link up state
202 * in @state->link. If possible, @state->lp_advertising should also be
203 * populated.
001f4261
RKO
204 *
205 * Note: This is a legacy method. This function will not be called unless
206 * legacy_pre_march2020 is set in &struct phylink_config and there is no
207 * PCS attached.
8796c892 208 */
d46b7e4f
RK
209void mac_pcs_get_state(struct phylink_config *config,
210 struct phylink_link_state *state);
8796c892 211
b7ad14c2
RK
212/**
213 * mac_prepare() - prepare to change the PHY interface mode
214 * @config: a pointer to a &struct phylink_config.
215 * @mode: one of %MLO_AN_FIXED, %MLO_AN_PHY, %MLO_AN_INBAND.
216 * @iface: interface mode to switch to
217 *
218 * phylink will call this method at the beginning of a full initialisation
219 * of the link, which includes changing the interface mode or at initial
220 * startup time. It may be called for the current mode. The MAC driver
221 * should perform whatever actions are required, e.g. disabling the
222 * Serdes PHY.
223 *
224 * This will be the first call in the sequence:
225 * - mac_prepare()
226 * - mac_config()
227 * - pcs_config()
228 * - possible pcs_an_restart()
229 * - mac_finish()
230 *
231 * Returns zero on success, or negative errno on failure which will be
232 * reported to the kernel log.
233 */
234int mac_prepare(struct phylink_config *config, unsigned int mode,
235 phy_interface_t iface);
236
8796c892
RK
237/**
238 * mac_config() - configure the MAC for the selected mode and state
44cc27e4 239 * @config: a pointer to a &struct phylink_config.
8796c892
RK
240 * @mode: one of %MLO_AN_FIXED, %MLO_AN_PHY, %MLO_AN_INBAND.
241 * @state: a pointer to a &struct phylink_link_state.
242 *
4add7009
RKAL
243 * Note - not all members of @state are valid. In particular,
244 * @state->lp_advertising, @state->link, @state->an_complete are never
245 * guaranteed to be correct, and so any mac_config() implementation must
246 * never reference these fields.
247 *
001f4261
RKO
248 * Note: For legacy March 2020 drivers (drivers with legacy_pre_march2020 set
249 * in their &phylnk_config and which don't have a PCS), this function will be
250 * called on each link up event, and to also change the in-band advert. For
251 * non-legacy drivers, it will only be called to reconfigure the MAC for a
252 * "major" change in e.g. interface mode. It will not be called for changes
253 * in speed, duplex or pause modes or to change the in-band advertisement.
254 * In any case, it is strongly preferred that speed, duplex and pause settings
255 * are handled in the mac_link_up() method and not in this method.
256 *
91a208f2
RK
257 * (this requires a rewrite - please refer to mac_link_up() for situations
258 * where the PCS and MAC are not tightly integrated.)
259 *
b70486f9
RK
260 * In all negotiation modes, as defined by @mode, @state->pause indicates the
261 * pause settings which should be applied as follows. If %MLO_PAUSE_AN is not
262 * set, %MLO_PAUSE_TX and %MLO_PAUSE_RX indicate whether the MAC should send
263 * pause frames and/or act on received pause frames respectively. Otherwise,
264 * the results of in-band negotiation/status from the MAC PCS should be used
265 * to control the MAC pause mode settings.
266 *
8796c892
RK
267 * The action performed depends on the currently selected mode:
268 *
269 * %MLO_AN_FIXED, %MLO_AN_PHY:
91a208f2
RK
270 * Configure for non-inband negotiation mode, where the link settings
271 * are completely communicated via mac_link_up(). The physical link
272 * protocol from the MAC is specified by @state->interface.
273 *
274 * @state->advertising may be used, but is not required.
275 *
276 * Older drivers (prior to the mac_link_up() change) may use @state->speed,
277 * @state->duplex and @state->pause to configure the MAC, but this is
278 * deprecated; such drivers should be converted to use mac_link_up().
4add7009 279 *
91a208f2
RK
280 * Other members of @state must be ignored.
281 *
282 * Valid state members: interface, advertising.
283 * Deprecated state members: speed, duplex, pause.
8796c892
RK
284 *
285 * %MLO_AN_INBAND:
286 * place the link in an inband negotiation mode (such as 802.3z
287 * 1000base-X or Cisco SGMII mode depending on the @state->interface
288 * mode). In both cases, link state management (whether the link
289 * is up or not) is performed by the MAC, and reported via the
d46b7e4f 290 * mac_pcs_get_state() callback. Changes in link state must be made
8796c892
RK
291 * by calling phylink_mac_change().
292 *
b70486f9
RK
293 * Interface mode specific details are mentioned below.
294 *
8796c892 295 * If in 802.3z mode, the link speed is fixed, dependent on the
b70486f9
RK
296 * @state->interface. Duplex and pause modes are negotiated via
297 * the in-band configuration word. Advertised pause modes are set
298 * according to the @state->an_enabled and @state->advertising
299 * flags. Beware of MACs which only support full duplex at gigabit
300 * and higher speeds.
8796c892
RK
301 *
302 * If in Cisco SGMII mode, the link speed and duplex mode are passed
303 * in the serial bitstream 16-bit configuration word, and the MAC
304 * should be configured to read these bits and acknowledge the
305 * configuration word. Nothing is advertised by the MAC. The MAC is
306 * responsible for reading the configuration word and configuring
307 * itself accordingly.
0e29ae03 308 *
4add7009
RKAL
309 * Valid state members: interface, an_enabled, pause, advertising.
310 *
0e29ae03
RK
311 * Implementations are expected to update the MAC to reflect the
312 * requested settings - i.o.w., if nothing has changed between two
313 * calls, no action is expected. If only flow control settings have
314 * changed, flow control should be updated *without* taking the link
315 * down. This "update" behaviour is critical to avoid bouncing the
316 * link up status.
8796c892 317 */
44cc27e4 318void mac_config(struct phylink_config *config, unsigned int mode,
8796c892
RK
319 const struct phylink_link_state *state);
320
b7ad14c2
RK
321/**
322 * mac_finish() - finish a to change the PHY interface mode
323 * @config: a pointer to a &struct phylink_config.
324 * @mode: one of %MLO_AN_FIXED, %MLO_AN_PHY, %MLO_AN_INBAND.
325 * @iface: interface mode to switch to
326 *
327 * phylink will call this if it called mac_prepare() to allow the MAC to
328 * complete any necessary steps after the MAC and PCS have been configured
329 * for the @mode and @iface. E.g. a MAC driver may wish to re-enable the
330 * Serdes PHY here if it was previously disabled by mac_prepare().
331 *
332 * Returns zero on success, or negative errno on failure which will be
333 * reported to the kernel log.
334 */
335int mac_finish(struct phylink_config *config, unsigned int mode,
336 phy_interface_t iface);
337
8796c892
RK
338/**
339 * mac_an_restart() - restart 802.3z BaseX autonegotiation
44cc27e4 340 * @config: a pointer to a &struct phylink_config.
001f4261
RKO
341 *
342 * Note: This is a legacy method. This function will not be called unless
343 * legacy_pre_march2020 is set in &struct phylink_config and there is no
344 * PCS attached.
8796c892 345 */
44cc27e4 346void mac_an_restart(struct phylink_config *config);
8796c892
RK
347
348/**
349 * mac_link_down() - take the link down
44cc27e4 350 * @config: a pointer to a &struct phylink_config.
8796c892 351 * @mode: link autonegotiation mode
c6ab3008 352 * @interface: link &typedef phy_interface_t mode
8796c892
RK
353 *
354 * If @mode is not an in-band negotiation mode (as defined by
355 * phylink_autoneg_inband()), force the link down and disable any
c6ab3008
FF
356 * Energy Efficient Ethernet MAC configuration. Interface type
357 * selection must be done in mac_config().
8796c892 358 */
44cc27e4 359void mac_link_down(struct phylink_config *config, unsigned int mode,
c6ab3008 360 phy_interface_t interface);
8796c892
RK
361
362/**
363 * mac_link_up() - allow the link to come up
44cc27e4 364 * @config: a pointer to a &struct phylink_config.
91a208f2 365 * @phy: any attached phy
8796c892 366 * @mode: link autonegotiation mode
c6ab3008 367 * @interface: link &typedef phy_interface_t mode
91a208f2
RK
368 * @speed: link speed
369 * @duplex: link duplex
370 * @tx_pause: link transmit pause enablement status
371 * @rx_pause: link receive pause enablement status
8796c892 372 *
91a208f2
RK
373 * Configure the MAC for an established link.
374 *
375 * @speed, @duplex, @tx_pause and @rx_pause indicate the finalised link
376 * settings, and should be used to configure the MAC block appropriately
377 * where these settings are not automatically conveyed from the PCS block,
378 * or if in-band negotiation (as defined by phylink_autoneg_inband(@mode))
379 * is disabled.
380 *
381 * Note that when 802.3z in-band negotiation is in use, it is possible
382 * that the user wishes to override the pause settings, and this should
383 * be allowed when considering the implementation of this method.
384 *
385 * If in-band negotiation mode is disabled, allow the link to come up. If
386 * @phy is non-%NULL, configure Energy Efficient Ethernet by calling
8796c892 387 * phy_init_eee() and perform appropriate MAC configuration for EEE.
c6ab3008 388 * Interface type selection must be done in mac_config().
8796c892 389 */
91a208f2
RK
390void mac_link_up(struct phylink_config *config, struct phy_device *phy,
391 unsigned int mode, phy_interface_t interface,
392 int speed, int duplex, bool tx_pause, bool rx_pause);
8796c892
RK
393#endif
394
7137e18f
RK
395struct phylink_pcs_ops;
396
397/**
398 * struct phylink_pcs - PHYLINK PCS instance
399 * @ops: a pointer to the &struct phylink_pcs_ops structure
400 * @poll: poll the PCS for link changes
401 *
402 * This structure is designed to be embedded within the PCS private data,
403 * and will be passed between phylink and the PCS.
404 */
405struct phylink_pcs {
406 const struct phylink_pcs_ops *ops;
407 bool poll;
408};
409
4c0d6d3a
RK
410/**
411 * struct phylink_pcs_ops - MAC PCS operations structure.
0d22d4b6 412 * @pcs_validate: validate the link configuration.
4c0d6d3a
RK
413 * @pcs_get_state: read the current MAC PCS link state from the hardware.
414 * @pcs_config: configure the MAC PCS for the selected mode and state.
415 * @pcs_an_restart: restart 802.3z BaseX autonegotiation.
416 * @pcs_link_up: program the PCS for the resolved link configuration
417 * (where necessary).
418 */
419struct phylink_pcs_ops {
0d22d4b6
RKO
420 int (*pcs_validate)(struct phylink_pcs *pcs, unsigned long *supported,
421 const struct phylink_link_state *state);
7137e18f 422 void (*pcs_get_state)(struct phylink_pcs *pcs,
4c0d6d3a 423 struct phylink_link_state *state);
7137e18f 424 int (*pcs_config)(struct phylink_pcs *pcs, unsigned int mode,
4c0d6d3a 425 phy_interface_t interface,
1571e700
RK
426 const unsigned long *advertising,
427 bool permit_pause_to_mac);
7137e18f
RK
428 void (*pcs_an_restart)(struct phylink_pcs *pcs);
429 void (*pcs_link_up)(struct phylink_pcs *pcs, unsigned int mode,
4c0d6d3a
RK
430 phy_interface_t interface, int speed, int duplex);
431};
432
433#if 0 /* For kernel-doc purposes only. */
0d22d4b6
RKO
434/**
435 * pcs_validate() - validate the link configuration.
436 * @pcs: a pointer to a &struct phylink_pcs.
437 * @supported: ethtool bitmask for supported link modes.
438 * @state: a const pointer to a &struct phylink_link_state.
439 *
440 * Validate the interface mode, and advertising's autoneg bit, removing any
441 * media ethtool link modes that would not be supportable from the supported
442 * mask. Phylink will propagate the changes to the advertising mask. See the
443 * &struct phylink_mac_ops validate() method.
444 *
445 * Returns -EINVAL if the interface mode/autoneg mode is not supported.
446 * Returns non-zero positive if the link state can be supported.
447 */
448int pcs_validate(struct phylink_pcs *pcs, unsigned long *supported,
449 const struct phylink_link_state *state);
450
4c0d6d3a
RK
451/**
452 * pcs_get_state() - Read the current inband link state from the hardware
7137e18f 453 * @pcs: a pointer to a &struct phylink_pcs.
4c0d6d3a
RK
454 * @state: a pointer to a &struct phylink_link_state.
455 *
456 * Read the current inband link state from the MAC PCS, reporting the
457 * current speed in @state->speed, duplex mode in @state->duplex, pause
458 * mode in @state->pause using the %MLO_PAUSE_RX and %MLO_PAUSE_TX bits,
459 * negotiation completion state in @state->an_complete, and link up state
460 * in @state->link. If possible, @state->lp_advertising should also be
461 * populated.
462 *
463 * When present, this overrides mac_pcs_get_state() in &struct
464 * phylink_mac_ops.
465 */
7137e18f 466void pcs_get_state(struct phylink_pcs *pcs,
4c0d6d3a
RK
467 struct phylink_link_state *state);
468
469/**
470 * pcs_config() - Configure the PCS mode and advertisement
7137e18f 471 * @pcs: a pointer to a &struct phylink_pcs.
4c0d6d3a
RK
472 * @mode: one of %MLO_AN_FIXED, %MLO_AN_PHY, %MLO_AN_INBAND.
473 * @interface: interface mode to be used
474 * @advertising: adertisement ethtool link mode mask
1571e700 475 * @permit_pause_to_mac: permit forwarding pause resolution to MAC
4c0d6d3a
RK
476 *
477 * Configure the PCS for the operating mode, the interface mode, and set
1571e700
RK
478 * the advertisement mask. @permit_pause_to_mac indicates whether the
479 * hardware may forward the pause mode resolution to the MAC.
4c0d6d3a
RK
480 *
481 * When operating in %MLO_AN_INBAND, inband should always be enabled,
482 * otherwise inband should be disabled.
483 *
484 * For SGMII, there is no advertisement from the MAC side, the PCS should
485 * be programmed to acknowledge the inband word from the PHY.
486 *
487 * For 1000BASE-X, the advertisement should be programmed into the PCS.
488 *
489 * For most 10GBASE-R, there is no advertisement.
490 */
7137e18f 491int pcs_config(struct phylink_pcs *pcs, unsigned int mode,
0b76e642
RD
492 phy_interface_t interface, const unsigned long *advertising,
493 bool permit_pause_to_mac);
4c0d6d3a
RK
494
495/**
496 * pcs_an_restart() - restart 802.3z BaseX autonegotiation
7137e18f 497 * @pcs: a pointer to a &struct phylink_pcs.
4c0d6d3a
RK
498 *
499 * When PCS ops are present, this overrides mac_an_restart() in &struct
500 * phylink_mac_ops.
501 */
7137e18f 502void pcs_an_restart(struct phylink_pcs *pcs);
4c0d6d3a
RK
503
504/**
505 * pcs_link_up() - program the PCS for the resolved link configuration
7137e18f 506 * @pcs: a pointer to a &struct phylink_pcs.
4c0d6d3a
RK
507 * @mode: link autonegotiation mode
508 * @interface: link &typedef phy_interface_t mode
509 * @speed: link speed
510 * @duplex: link duplex
511 *
512 * This call will be made just before mac_link_up() to inform the PCS of
513 * the resolved link parameters. For example, a PCS operating in SGMII
514 * mode without in-band AN needs to be manually configured for the link
515 * and duplex setting. Otherwise, this should be a no-op.
516 */
7137e18f
RK
517void pcs_link_up(struct phylink_pcs *pcs, unsigned int mode,
518 phy_interface_t interface, int speed, int duplex);
4c0d6d3a
RK
519#endif
520
34ae2c09
RKO
521void phylink_get_linkmodes(unsigned long *linkmodes, phy_interface_t interface,
522 unsigned long mac_capabilities);
523void phylink_generic_validate(struct phylink_config *config,
524 unsigned long *supported,
525 struct phylink_link_state *state);
526
44cc27e4
IC
527struct phylink *phylink_create(struct phylink_config *, struct fwnode_handle *,
528 phy_interface_t iface,
e7765d63 529 const struct phylink_mac_ops *mac_ops);
9525ae83
RK
530void phylink_destroy(struct phylink *);
531
532int phylink_connect_phy(struct phylink *, struct phy_device *);
0a62964c 533int phylink_of_phy_connect(struct phylink *, struct device_node *, u32 flags);
25396f68
CJ
534int phylink_fwnode_phy_connect(struct phylink *pl,
535 struct fwnode_handle *fwnode,
536 u32 flags);
9525ae83
RK
537void phylink_disconnect_phy(struct phylink *);
538
539void phylink_mac_change(struct phylink *, bool up);
540
541void phylink_start(struct phylink *);
542void phylink_stop(struct phylink *);
543
f9749365
RKO
544void phylink_suspend(struct phylink *pl, bool mac_wol);
545void phylink_resume(struct phylink *pl);
546
9525ae83
RK
547void phylink_ethtool_get_wol(struct phylink *, struct ethtool_wolinfo *);
548int phylink_ethtool_set_wol(struct phylink *, struct ethtool_wolinfo *);
549
550int phylink_ethtool_ksettings_get(struct phylink *,
551 struct ethtool_link_ksettings *);
552int phylink_ethtool_ksettings_set(struct phylink *,
553 const struct ethtool_link_ksettings *);
554int phylink_ethtool_nway_reset(struct phylink *);
555void phylink_ethtool_get_pauseparam(struct phylink *,
556 struct ethtool_pauseparam *);
557int phylink_ethtool_set_pauseparam(struct phylink *,
558 struct ethtool_pauseparam *);
9525ae83 559int phylink_get_eee_err(struct phylink *);
86e58135 560int phylink_init_eee(struct phylink *, bool);
9525ae83
RK
561int phylink_ethtool_get_eee(struct phylink *, struct ethtool_eee *);
562int phylink_ethtool_set_eee(struct phylink *, struct ethtool_eee *);
563int phylink_mii_ioctl(struct phylink *, struct ifreq *, int);
c6d5d843
RK
564int phylink_speed_down(struct phylink *pl, bool sync);
565int phylink_speed_up(struct phylink *pl);
9525ae83
RK
566
567#define phylink_zero(bm) \
568 bitmap_zero(bm, __ETHTOOL_LINK_MODE_MASK_NBITS)
569#define __phylink_do_bit(op, bm, mode) \
570 op(ETHTOOL_LINK_MODE_ ## mode ## _BIT, bm)
571
572#define phylink_set(bm, mode) __phylink_do_bit(__set_bit, bm, mode)
573#define phylink_clear(bm, mode) __phylink_do_bit(__clear_bit, bm, mode)
574#define phylink_test(bm, mode) __phylink_do_bit(test_bit, bm, mode)
575
576void phylink_set_port_modes(unsigned long *bits);
577
291dcae3
SA
578void phylink_mii_c22_pcs_decode_state(struct phylink_link_state *state,
579 u16 bmsr, u16 lpa);
74db1c18
RK
580void phylink_mii_c22_pcs_get_state(struct mdio_device *pcs,
581 struct phylink_link_state *state);
291dcae3
SA
582int phylink_mii_c22_pcs_encode_advertisement(phy_interface_t interface,
583 const unsigned long *advertising);
93eaceb0
RK
584int phylink_mii_c22_pcs_config(struct mdio_device *pcs, unsigned int mode,
585 phy_interface_t interface,
586 const unsigned long *advertising);
74db1c18
RK
587void phylink_mii_c22_pcs_an_restart(struct mdio_device *pcs);
588
b8679ef8
RK
589void phylink_mii_c45_pcs_get_state(struct mdio_device *pcs,
590 struct phylink_link_state *state);
afd62209
IC
591
592void phylink_decode_usxgmii_word(struct phylink_link_state *state,
593 uint16_t lpa);
9525ae83 594#endif