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