5 #include <linux/spinlock.h>
6 #include <linux/workqueue.h>
15 MLO_PAUSE_RX = BIT(0),
16 MLO_PAUSE_TX = BIT(1),
17 MLO_PAUSE_TXRX_MASK = MLO_PAUSE_TX | MLO_PAUSE_RX,
18 MLO_PAUSE_AN = BIT(2),
20 MLO_AN_PHY = 0, /* Conventional PHY */
21 MLO_AN_FIXED, /* Fixed-link mode */
22 MLO_AN_INBAND, /* In-band protocol */
24 /* PCS "negotiation" mode.
25 * PHYLINK_PCS_NEG_NONE - protocol has no inband capability
26 * PHYLINK_PCS_NEG_OUTBAND - some out of band or fixed link setting
27 * PHYLINK_PCS_NEG_INBAND_DISABLED - inband mode disabled, e.g.
28 * 1000base-X with autoneg off
29 * PHYLINK_PCS_NEG_INBAND_ENABLED - inband mode enabled
30 * Additionally, this can be tested using bitmasks:
31 * PHYLINK_PCS_NEG_INBAND - inband mode selected
32 * PHYLINK_PCS_NEG_ENABLED - negotiation mode enabled
34 PHYLINK_PCS_NEG_NONE = 0,
35 PHYLINK_PCS_NEG_ENABLED = BIT(4),
36 PHYLINK_PCS_NEG_OUTBAND = BIT(5),
37 PHYLINK_PCS_NEG_INBAND = BIT(6),
38 PHYLINK_PCS_NEG_INBAND_DISABLED = PHYLINK_PCS_NEG_INBAND,
39 PHYLINK_PCS_NEG_INBAND_ENABLED = PHYLINK_PCS_NEG_INBAND |
40 PHYLINK_PCS_NEG_ENABLED,
42 /* MAC_SYM_PAUSE and MAC_ASYM_PAUSE are used when configuring our
43 * autonegotiation advertisement. They correspond to the PAUSE and
44 * ASM_DIR bits defined by 802.3, respectively.
46 * The following table lists the values of tx_pause and rx_pause which
47 * might be requested in mac_link_up. The exact values depend on either
48 * the results of autonegotation (if MLO_PAUSE_AN is set) or user
49 * configuration (if MLO_PAUSE_AN is not set).
51 * MAC_SYM_PAUSE MAC_ASYM_PAUSE MLO_PAUSE_AN tx_pause/rx_pause
52 * ============= ============== ============ ==================
55 * 0 1 0 0/0, 0/1, 1/0, 1/1
59 * 1 1 0 0/0, 0/1, 1/0, 1/1
62 * If you set MAC_ASYM_PAUSE, the user may request any combination of
63 * tx_pause and rx_pause. You do not have to support these
66 * However, you should support combinations of tx_pause and rx_pause
67 * which might be the result of autonegotation. For example, don't set
68 * MAC_SYM_PAUSE unless your device can support tx_pause and rx_pause
71 MAC_SYM_PAUSE = BIT(0),
72 MAC_ASYM_PAUSE = BIT(1),
75 MAC_10 = MAC_10HD | MAC_10FD,
78 MAC_100 = MAC_100HD | MAC_100FD,
81 MAC_1000 = MAC_1000HD | MAC_1000FD,
84 MAC_10000FD = BIT(10),
85 MAC_20000FD = BIT(11),
86 MAC_25000FD = BIT(12),
87 MAC_40000FD = BIT(13),
88 MAC_50000FD = BIT(14),
89 MAC_56000FD = BIT(15),
90 MAC_100000FD = BIT(16),
91 MAC_200000FD = BIT(17),
92 MAC_400000FD = BIT(18),
95 static inline bool phylink_autoneg_inband(unsigned int mode)
97 return mode == MLO_AN_INBAND;
101 * phylink_pcs_neg_mode() - helper to determine PCS inband mode
102 * @mode: one of %MLO_AN_FIXED, %MLO_AN_PHY, %MLO_AN_INBAND.
103 * @interface: interface mode to be used
104 * @advertising: adertisement ethtool link mode mask
106 * Determines the negotiation mode to be used by the PCS, and returns
109 * - %PHYLINK_PCS_NEG_NONE: interface mode does not support inband
110 * - %PHYLINK_PCS_NEG_OUTBAND: an out of band mode (e.g. reading the PHY)
112 * - %PHYLINK_PCS_NEG_INBAND_DISABLED: inband mode selected but autoneg
114 * - %PHYLINK_PCS_NEG_INBAND_ENABLED: inband mode selected and autoneg enabled
116 * Note: this is for cases where the PCS itself is involved in negotiation
117 * (e.g. Clause 37, SGMII and similar) not Clause 73.
119 static inline unsigned int phylink_pcs_neg_mode(unsigned int mode,
120 phy_interface_t interface,
121 const unsigned long *advertising)
123 unsigned int neg_mode;
126 case PHY_INTERFACE_MODE_SGMII:
127 case PHY_INTERFACE_MODE_QSGMII:
128 case PHY_INTERFACE_MODE_QUSGMII:
129 case PHY_INTERFACE_MODE_USXGMII:
130 /* These protocols are designed for use with a PHY which
131 * communicates its negotiation result back to the MAC via
132 * inband communication. Note: there exist PHYs that run
133 * with SGMII but do not send the inband data.
135 if (!phylink_autoneg_inband(mode))
136 neg_mode = PHYLINK_PCS_NEG_OUTBAND;
138 neg_mode = PHYLINK_PCS_NEG_INBAND_ENABLED;
141 case PHY_INTERFACE_MODE_1000BASEX:
142 case PHY_INTERFACE_MODE_2500BASEX:
143 /* 1000base-X is designed for use media-side for Fibre
144 * connections, and thus the Autoneg bit needs to be
145 * taken into account. We also do this for 2500base-X
146 * as well, but drivers may not support this, so may
147 * need to override this.
149 if (!phylink_autoneg_inband(mode))
150 neg_mode = PHYLINK_PCS_NEG_OUTBAND;
151 else if (linkmode_test_bit(ETHTOOL_LINK_MODE_Autoneg_BIT,
153 neg_mode = PHYLINK_PCS_NEG_INBAND_ENABLED;
155 neg_mode = PHYLINK_PCS_NEG_INBAND_DISABLED;
159 neg_mode = PHYLINK_PCS_NEG_NONE;
167 * struct phylink_link_state - link state structure
168 * @advertising: ethtool bitmask containing advertised link modes
169 * @lp_advertising: ethtool bitmask containing link partner advertised link
171 * @interface: link &typedef phy_interface_t mode
172 * @speed: link speed, one of the SPEED_* constants.
173 * @duplex: link duplex mode, one of DUPLEX_* constants.
174 * @pause: link pause state, described by MLO_PAUSE_* constants.
175 * @rate_matching: rate matching being performed, one of the RATE_MATCH_*
176 * constants. If rate matching is taking place, then the speed/duplex of
177 * the medium link mode (@speed and @duplex) and the speed/duplex of the phy
178 * interface mode (@interface) are different.
179 * @link: true if the link is up.
180 * @an_complete: true if autonegotiation has completed.
182 struct phylink_link_state {
183 __ETHTOOL_DECLARE_LINK_MODE_MASK(advertising);
184 __ETHTOOL_DECLARE_LINK_MODE_MASK(lp_advertising);
185 phy_interface_t interface;
191 unsigned int an_complete:1;
194 enum phylink_op_type {
200 * struct phylink_config - PHYLINK configuration structure
201 * @dev: a pointer to a struct device associated with the MAC
202 * @type: operation type of PHYLINK instance
203 * @legacy_pre_march2020: driver has not been updated for March 2020 updates
204 * (See commit 7cceb599d15d ("net: phylink: avoid mac_config calls")
205 * @poll_fixed_state: if true, starts link_poll,
206 * if MAC link is at %MLO_AN_FIXED mode.
207 * @mac_managed_pm: if true, indicate the MAC driver is responsible for PHY PM.
208 * @ovr_an_inband: if true, override PCS to MLO_AN_INBAND
209 * @get_fixed_state: callback to execute to determine the fixed link state,
210 * if MAC link is at %MLO_AN_FIXED mode.
211 * @supported_interfaces: bitmap describing which PHY_INTERFACE_MODE_xxx
212 * are supported by the MAC/PCS.
213 * @mac_capabilities: MAC pause/speed/duplex capabilities.
215 struct phylink_config {
217 enum phylink_op_type type;
218 bool legacy_pre_march2020;
219 bool poll_fixed_state;
222 void (*get_fixed_state)(struct phylink_config *config,
223 struct phylink_link_state *state);
224 DECLARE_PHY_INTERFACE_MASK(supported_interfaces);
225 unsigned long mac_capabilities;
229 * struct phylink_mac_ops - MAC operations structure.
230 * @validate: Validate and update the link configuration.
231 * @mac_select_pcs: Select a PCS for the interface mode.
232 * @mac_pcs_get_state: Read the current link state from the hardware.
233 * @mac_prepare: prepare for a major reconfiguration of the interface.
234 * @mac_config: configure the MAC for the selected mode and state.
235 * @mac_finish: finish a major reconfiguration of the interface.
236 * @mac_an_restart: restart 802.3z BaseX autonegotiation.
237 * @mac_link_down: take the link down.
238 * @mac_link_up: allow the link to come up.
240 * The individual methods are described more fully below.
242 struct phylink_mac_ops {
243 void (*validate)(struct phylink_config *config,
244 unsigned long *supported,
245 struct phylink_link_state *state);
246 struct phylink_pcs *(*mac_select_pcs)(struct phylink_config *config,
247 phy_interface_t interface);
248 void (*mac_pcs_get_state)(struct phylink_config *config,
249 struct phylink_link_state *state);
250 int (*mac_prepare)(struct phylink_config *config, unsigned int mode,
251 phy_interface_t iface);
252 void (*mac_config)(struct phylink_config *config, unsigned int mode,
253 const struct phylink_link_state *state);
254 int (*mac_finish)(struct phylink_config *config, unsigned int mode,
255 phy_interface_t iface);
256 void (*mac_an_restart)(struct phylink_config *config);
257 void (*mac_link_down)(struct phylink_config *config, unsigned int mode,
258 phy_interface_t interface);
259 void (*mac_link_up)(struct phylink_config *config,
260 struct phy_device *phy, unsigned int mode,
261 phy_interface_t interface, int speed, int duplex,
262 bool tx_pause, bool rx_pause);
265 #if 0 /* For kernel-doc purposes only. */
267 * validate - Validate and update the link configuration
268 * @config: a pointer to a &struct phylink_config.
269 * @supported: ethtool bitmask for supported link modes.
270 * @state: a pointer to a &struct phylink_link_state.
272 * Clear bits in the @supported and @state->advertising masks that
273 * are not supportable by the MAC.
275 * Note that the PHY may be able to transform from one connection
276 * technology to another, so, eg, don't clear 1000BaseX just
277 * because the MAC is unable to BaseX mode. This is more about
278 * clearing unsupported speeds and duplex settings. The port modes
279 * should not be cleared; phylink_set_port_modes() will help with this.
281 * When @config->supported_interfaces has been set, phylink will iterate
282 * over the supported interfaces to determine the full capability of the
283 * MAC. The validation function must not print errors if @state->interface
284 * is set to an unexpected value.
286 * When @config->supported_interfaces is empty, phylink will call this
287 * function with @state->interface set to %PHY_INTERFACE_MODE_NA, and
288 * expects the MAC driver to return all supported link modes.
290 * If the @state->interface mode is not supported, then the @supported
291 * mask must be cleared.
293 * This member is optional; if not set, the generic validator will be
294 * used making use of @config->mac_capabilities and
295 * @config->supported_interfaces to determine which link modes are
298 void validate(struct phylink_config *config, unsigned long *supported,
299 struct phylink_link_state *state);
301 * mac_select_pcs: Select a PCS for the interface mode.
302 * @config: a pointer to a &struct phylink_config.
303 * @interface: PHY interface mode for PCS
305 * Return the &struct phylink_pcs for the specified interface mode, or
306 * NULL if none is required, or an error pointer on error.
308 * This must not modify any state. It is used to query which PCS should
309 * be used. Phylink will use this during validation to ensure that the
310 * configuration is valid, and when setting a configuration to internally
311 * set the PCS that will be used.
313 struct phylink_pcs *mac_select_pcs(struct phylink_config *config,
314 phy_interface_t interface);
317 * mac_pcs_get_state() - Read the current inband link state from the hardware
318 * @config: a pointer to a &struct phylink_config.
319 * @state: a pointer to a &struct phylink_link_state.
321 * Read the current inband link state from the MAC PCS, reporting the
322 * current speed in @state->speed, duplex mode in @state->duplex, pause
323 * mode in @state->pause using the %MLO_PAUSE_RX and %MLO_PAUSE_TX bits,
324 * negotiation completion state in @state->an_complete, and link up state
325 * in @state->link. If possible, @state->lp_advertising should also be
328 * Note: This is a legacy method. This function will not be called unless
329 * legacy_pre_march2020 is set in &struct phylink_config and there is no
332 void mac_pcs_get_state(struct phylink_config *config,
333 struct phylink_link_state *state);
336 * mac_prepare() - prepare to change the PHY interface mode
337 * @config: a pointer to a &struct phylink_config.
338 * @mode: one of %MLO_AN_FIXED, %MLO_AN_PHY, %MLO_AN_INBAND.
339 * @iface: interface mode to switch to
341 * phylink will call this method at the beginning of a full initialisation
342 * of the link, which includes changing the interface mode or at initial
343 * startup time. It may be called for the current mode. The MAC driver
344 * should perform whatever actions are required, e.g. disabling the
347 * This will be the first call in the sequence:
351 * - possible pcs_an_restart()
354 * Returns zero on success, or negative errno on failure which will be
355 * reported to the kernel log.
357 int mac_prepare(struct phylink_config *config, unsigned int mode,
358 phy_interface_t iface);
361 * mac_config() - configure the MAC for the selected mode and state
362 * @config: a pointer to a &struct phylink_config.
363 * @mode: one of %MLO_AN_FIXED, %MLO_AN_PHY, %MLO_AN_INBAND.
364 * @state: a pointer to a &struct phylink_link_state.
366 * Note - not all members of @state are valid. In particular,
367 * @state->lp_advertising, @state->link, @state->an_complete are never
368 * guaranteed to be correct, and so any mac_config() implementation must
369 * never reference these fields.
371 * Note: For legacy March 2020 drivers (drivers with legacy_pre_march2020 set
372 * in their &phylnk_config and which don't have a PCS), this function will be
373 * called on each link up event, and to also change the in-band advert. For
374 * non-legacy drivers, it will only be called to reconfigure the MAC for a
375 * "major" change in e.g. interface mode. It will not be called for changes
376 * in speed, duplex or pause modes or to change the in-band advertisement.
377 * In any case, it is strongly preferred that speed, duplex and pause settings
378 * are handled in the mac_link_up() method and not in this method.
380 * (this requires a rewrite - please refer to mac_link_up() for situations
381 * where the PCS and MAC are not tightly integrated.)
383 * In all negotiation modes, as defined by @mode, @state->pause indicates the
384 * pause settings which should be applied as follows. If %MLO_PAUSE_AN is not
385 * set, %MLO_PAUSE_TX and %MLO_PAUSE_RX indicate whether the MAC should send
386 * pause frames and/or act on received pause frames respectively. Otherwise,
387 * the results of in-band negotiation/status from the MAC PCS should be used
388 * to control the MAC pause mode settings.
390 * The action performed depends on the currently selected mode:
392 * %MLO_AN_FIXED, %MLO_AN_PHY:
393 * Configure for non-inband negotiation mode, where the link settings
394 * are completely communicated via mac_link_up(). The physical link
395 * protocol from the MAC is specified by @state->interface.
397 * @state->advertising may be used, but is not required.
399 * Older drivers (prior to the mac_link_up() change) may use @state->speed,
400 * @state->duplex and @state->pause to configure the MAC, but this is
401 * deprecated; such drivers should be converted to use mac_link_up().
403 * Other members of @state must be ignored.
405 * Valid state members: interface, advertising.
406 * Deprecated state members: speed, duplex, pause.
409 * place the link in an inband negotiation mode (such as 802.3z
410 * 1000base-X or Cisco SGMII mode depending on the @state->interface
411 * mode). In both cases, link state management (whether the link
412 * is up or not) is performed by the MAC, and reported via the
413 * mac_pcs_get_state() callback. Changes in link state must be made
414 * by calling phylink_mac_change().
416 * Interface mode specific details are mentioned below.
418 * If in 802.3z mode, the link speed is fixed, dependent on the
419 * @state->interface. Duplex and pause modes are negotiated via
420 * the in-band configuration word. Advertised pause modes are set
421 * according to the @state->an_enabled and @state->advertising
422 * flags. Beware of MACs which only support full duplex at gigabit
425 * If in Cisco SGMII mode, the link speed and duplex mode are passed
426 * in the serial bitstream 16-bit configuration word, and the MAC
427 * should be configured to read these bits and acknowledge the
428 * configuration word. Nothing is advertised by the MAC. The MAC is
429 * responsible for reading the configuration word and configuring
430 * itself accordingly.
432 * Valid state members: interface, an_enabled, pause, advertising.
434 * Implementations are expected to update the MAC to reflect the
435 * requested settings - i.o.w., if nothing has changed between two
436 * calls, no action is expected. If only flow control settings have
437 * changed, flow control should be updated *without* taking the link
438 * down. This "update" behaviour is critical to avoid bouncing the
441 void mac_config(struct phylink_config *config, unsigned int mode,
442 const struct phylink_link_state *state);
445 * mac_finish() - finish a to change the PHY interface mode
446 * @config: a pointer to a &struct phylink_config.
447 * @mode: one of %MLO_AN_FIXED, %MLO_AN_PHY, %MLO_AN_INBAND.
448 * @iface: interface mode to switch to
450 * phylink will call this if it called mac_prepare() to allow the MAC to
451 * complete any necessary steps after the MAC and PCS have been configured
452 * for the @mode and @iface. E.g. a MAC driver may wish to re-enable the
453 * Serdes PHY here if it was previously disabled by mac_prepare().
455 * Returns zero on success, or negative errno on failure which will be
456 * reported to the kernel log.
458 int mac_finish(struct phylink_config *config, unsigned int mode,
459 phy_interface_t iface);
462 * mac_an_restart() - restart 802.3z BaseX autonegotiation
463 * @config: a pointer to a &struct phylink_config.
465 * Note: This is a legacy method. This function will not be called unless
466 * legacy_pre_march2020 is set in &struct phylink_config and there is no
469 void mac_an_restart(struct phylink_config *config);
472 * mac_link_down() - take the link down
473 * @config: a pointer to a &struct phylink_config.
474 * @mode: link autonegotiation mode
475 * @interface: link &typedef phy_interface_t mode
477 * If @mode is not an in-band negotiation mode (as defined by
478 * phylink_autoneg_inband()), force the link down and disable any
479 * Energy Efficient Ethernet MAC configuration. Interface type
480 * selection must be done in mac_config().
482 void mac_link_down(struct phylink_config *config, unsigned int mode,
483 phy_interface_t interface);
486 * mac_link_up() - allow the link to come up
487 * @config: a pointer to a &struct phylink_config.
488 * @phy: any attached phy
489 * @mode: link autonegotiation mode
490 * @interface: link &typedef phy_interface_t mode
492 * @duplex: link duplex
493 * @tx_pause: link transmit pause enablement status
494 * @rx_pause: link receive pause enablement status
496 * Configure the MAC for an established link.
498 * @speed, @duplex, @tx_pause and @rx_pause indicate the finalised link
499 * settings, and should be used to configure the MAC block appropriately
500 * where these settings are not automatically conveyed from the PCS block,
501 * or if in-band negotiation (as defined by phylink_autoneg_inband(@mode))
504 * Note that when 802.3z in-band negotiation is in use, it is possible
505 * that the user wishes to override the pause settings, and this should
506 * be allowed when considering the implementation of this method.
508 * If in-band negotiation mode is disabled, allow the link to come up. If
509 * @phy is non-%NULL, configure Energy Efficient Ethernet by calling
510 * phy_init_eee() and perform appropriate MAC configuration for EEE.
511 * Interface type selection must be done in mac_config().
513 void mac_link_up(struct phylink_config *config, struct phy_device *phy,
514 unsigned int mode, phy_interface_t interface,
515 int speed, int duplex, bool tx_pause, bool rx_pause);
518 struct phylink_pcs_ops;
521 * struct phylink_pcs - PHYLINK PCS instance
522 * @ops: a pointer to the &struct phylink_pcs_ops structure
523 * @neg_mode: provide PCS neg mode via "mode" argument
524 * @poll: poll the PCS for link changes
526 * This structure is designed to be embedded within the PCS private data,
527 * and will be passed between phylink and the PCS.
530 const struct phylink_pcs_ops *ops;
536 * struct phylink_pcs_ops - MAC PCS operations structure.
537 * @pcs_validate: validate the link configuration.
538 * @pcs_enable: enable the PCS.
539 * @pcs_disable: disable the PCS.
540 * @pcs_pre_config: pre-mac_config method (for errata)
541 * @pcs_post_config: post-mac_config method (for arrata)
542 * @pcs_get_state: read the current MAC PCS link state from the hardware.
543 * @pcs_config: configure the MAC PCS for the selected mode and state.
544 * @pcs_an_restart: restart 802.3z BaseX autonegotiation.
545 * @pcs_link_up: program the PCS for the resolved link configuration
548 struct phylink_pcs_ops {
549 int (*pcs_validate)(struct phylink_pcs *pcs, unsigned long *supported,
550 const struct phylink_link_state *state);
551 int (*pcs_enable)(struct phylink_pcs *pcs);
552 void (*pcs_disable)(struct phylink_pcs *pcs);
553 void (*pcs_pre_config)(struct phylink_pcs *pcs,
554 phy_interface_t interface);
555 int (*pcs_post_config)(struct phylink_pcs *pcs,
556 phy_interface_t interface);
557 void (*pcs_get_state)(struct phylink_pcs *pcs,
558 struct phylink_link_state *state);
559 int (*pcs_config)(struct phylink_pcs *pcs, unsigned int neg_mode,
560 phy_interface_t interface,
561 const unsigned long *advertising,
562 bool permit_pause_to_mac);
563 void (*pcs_an_restart)(struct phylink_pcs *pcs);
564 void (*pcs_link_up)(struct phylink_pcs *pcs, unsigned int neg_mode,
565 phy_interface_t interface, int speed, int duplex);
568 #if 0 /* For kernel-doc purposes only. */
570 * pcs_validate() - validate the link configuration.
571 * @pcs: a pointer to a &struct phylink_pcs.
572 * @supported: ethtool bitmask for supported link modes.
573 * @state: a const pointer to a &struct phylink_link_state.
575 * Validate the interface mode, and advertising's autoneg bit, removing any
576 * media ethtool link modes that would not be supportable from the supported
577 * mask. Phylink will propagate the changes to the advertising mask. See the
578 * &struct phylink_mac_ops validate() method.
580 * Returns -EINVAL if the interface mode/autoneg mode is not supported.
581 * Returns non-zero positive if the link state can be supported.
583 int pcs_validate(struct phylink_pcs *pcs, unsigned long *supported,
584 const struct phylink_link_state *state);
587 * pcs_enable() - enable the PCS.
588 * @pcs: a pointer to a &struct phylink_pcs.
590 int pcs_enable(struct phylink_pcs *pcs);
593 * pcs_disable() - disable the PCS.
594 * @pcs: a pointer to a &struct phylink_pcs.
596 void pcs_disable(struct phylink_pcs *pcs);
599 * pcs_get_state() - Read the current inband link state from the hardware
600 * @pcs: a pointer to a &struct phylink_pcs.
601 * @state: a pointer to a &struct phylink_link_state.
603 * Read the current inband link state from the MAC PCS, reporting the
604 * current speed in @state->speed, duplex mode in @state->duplex, pause
605 * mode in @state->pause using the %MLO_PAUSE_RX and %MLO_PAUSE_TX bits,
606 * negotiation completion state in @state->an_complete, and link up state
607 * in @state->link. If possible, @state->lp_advertising should also be
610 * When present, this overrides mac_pcs_get_state() in &struct
613 void pcs_get_state(struct phylink_pcs *pcs,
614 struct phylink_link_state *state);
617 * pcs_config() - Configure the PCS mode and advertisement
618 * @pcs: a pointer to a &struct phylink_pcs.
619 * @neg_mode: link negotiation mode (see below)
620 * @interface: interface mode to be used
621 * @advertising: adertisement ethtool link mode mask
622 * @permit_pause_to_mac: permit forwarding pause resolution to MAC
624 * Configure the PCS for the operating mode, the interface mode, and set
625 * the advertisement mask. @permit_pause_to_mac indicates whether the
626 * hardware may forward the pause mode resolution to the MAC.
628 * When operating in %MLO_AN_INBAND, inband should always be enabled,
629 * otherwise inband should be disabled.
631 * For SGMII, there is no advertisement from the MAC side, the PCS should
632 * be programmed to acknowledge the inband word from the PHY.
634 * For 1000BASE-X, the advertisement should be programmed into the PCS.
636 * For most 10GBASE-R, there is no advertisement.
638 * The %neg_mode argument should be tested via the phylink_mode_*() family of
639 * functions, or for PCS that set pcs->neg_mode true, should be tested
640 * against the %PHYLINK_PCS_NEG_* definitions.
642 int pcs_config(struct phylink_pcs *pcs, unsigned int neg_mode,
643 phy_interface_t interface, const unsigned long *advertising,
644 bool permit_pause_to_mac);
647 * pcs_an_restart() - restart 802.3z BaseX autonegotiation
648 * @pcs: a pointer to a &struct phylink_pcs.
650 * When PCS ops are present, this overrides mac_an_restart() in &struct
653 void pcs_an_restart(struct phylink_pcs *pcs);
656 * pcs_link_up() - program the PCS for the resolved link configuration
657 * @pcs: a pointer to a &struct phylink_pcs.
658 * @neg_mode: link negotiation mode (see below)
659 * @interface: link &typedef phy_interface_t mode
661 * @duplex: link duplex
663 * This call will be made just before mac_link_up() to inform the PCS of
664 * the resolved link parameters. For example, a PCS operating in SGMII
665 * mode without in-band AN needs to be manually configured for the link
666 * and duplex setting. Otherwise, this should be a no-op.
668 * The %mode argument should be tested via the phylink_mode_*() family of
669 * functions, or for PCS that set pcs->neg_mode true, should be tested
670 * against the %PHYLINK_PCS_NEG_* definitions.
672 void pcs_link_up(struct phylink_pcs *pcs, unsigned int neg_mode,
673 phy_interface_t interface, int speed, int duplex);
676 void phylink_caps_to_linkmodes(unsigned long *linkmodes, unsigned long caps);
677 unsigned long phylink_get_capabilities(phy_interface_t interface,
678 unsigned long mac_capabilities,
680 void phylink_validate_mask_caps(unsigned long *supported,
681 struct phylink_link_state *state,
683 void phylink_generic_validate(struct phylink_config *config,
684 unsigned long *supported,
685 struct phylink_link_state *state);
687 struct phylink *phylink_create(struct phylink_config *,
688 const struct fwnode_handle *,
690 const struct phylink_mac_ops *);
691 void phylink_destroy(struct phylink *);
692 bool phylink_expects_phy(struct phylink *pl);
694 int phylink_connect_phy(struct phylink *, struct phy_device *);
695 int phylink_of_phy_connect(struct phylink *, struct device_node *, u32 flags);
696 int phylink_fwnode_phy_connect(struct phylink *pl,
697 const struct fwnode_handle *fwnode,
699 void phylink_disconnect_phy(struct phylink *);
701 void phylink_mac_change(struct phylink *, bool up);
703 void phylink_start(struct phylink *);
704 void phylink_stop(struct phylink *);
706 void phylink_suspend(struct phylink *pl, bool mac_wol);
707 void phylink_resume(struct phylink *pl);
709 void phylink_ethtool_get_wol(struct phylink *, struct ethtool_wolinfo *);
710 int phylink_ethtool_set_wol(struct phylink *, struct ethtool_wolinfo *);
712 int phylink_ethtool_ksettings_get(struct phylink *,
713 struct ethtool_link_ksettings *);
714 int phylink_ethtool_ksettings_set(struct phylink *,
715 const struct ethtool_link_ksettings *);
716 int phylink_ethtool_nway_reset(struct phylink *);
717 void phylink_ethtool_get_pauseparam(struct phylink *,
718 struct ethtool_pauseparam *);
719 int phylink_ethtool_set_pauseparam(struct phylink *,
720 struct ethtool_pauseparam *);
721 int phylink_get_eee_err(struct phylink *);
722 int phylink_init_eee(struct phylink *, bool);
723 int phylink_ethtool_get_eee(struct phylink *, struct ethtool_eee *);
724 int phylink_ethtool_set_eee(struct phylink *, struct ethtool_eee *);
725 int phylink_mii_ioctl(struct phylink *, struct ifreq *, int);
726 int phylink_speed_down(struct phylink *pl, bool sync);
727 int phylink_speed_up(struct phylink *pl);
729 #define phylink_zero(bm) \
730 bitmap_zero(bm, __ETHTOOL_LINK_MODE_MASK_NBITS)
731 #define __phylink_do_bit(op, bm, mode) \
732 op(ETHTOOL_LINK_MODE_ ## mode ## _BIT, bm)
734 #define phylink_set(bm, mode) __phylink_do_bit(__set_bit, bm, mode)
735 #define phylink_clear(bm, mode) __phylink_do_bit(__clear_bit, bm, mode)
736 #define phylink_test(bm, mode) __phylink_do_bit(test_bit, bm, mode)
738 void phylink_set_port_modes(unsigned long *bits);
741 * phylink_get_link_timer_ns - return the PCS link timer value
742 * @interface: link &typedef phy_interface_t mode
744 * Return the PCS link timer setting in nanoseconds for the PHY @interface
745 * mode, or -EINVAL if not appropriate.
747 static inline int phylink_get_link_timer_ns(phy_interface_t interface)
750 case PHY_INTERFACE_MODE_SGMII:
751 case PHY_INTERFACE_MODE_QSGMII:
752 case PHY_INTERFACE_MODE_USXGMII:
755 case PHY_INTERFACE_MODE_1000BASEX:
756 case PHY_INTERFACE_MODE_2500BASEX:
764 void phylink_mii_c22_pcs_decode_state(struct phylink_link_state *state,
766 void phylink_mii_c22_pcs_get_state(struct mdio_device *pcs,
767 struct phylink_link_state *state);
768 int phylink_mii_c22_pcs_encode_advertisement(phy_interface_t interface,
769 const unsigned long *advertising);
770 int phylink_mii_c22_pcs_config(struct mdio_device *pcs,
771 phy_interface_t interface,
772 const unsigned long *advertising,
773 unsigned int neg_mode);
774 void phylink_mii_c22_pcs_an_restart(struct mdio_device *pcs);
776 void phylink_resolve_c73(struct phylink_link_state *state);
778 void phylink_mii_c45_pcs_get_state(struct mdio_device *pcs,
779 struct phylink_link_state *state);
781 void phylink_decode_usxgmii_word(struct phylink_link_state *state,