5 #include <linux/spinlock.h>
6 #include <linux/workqueue.h>
16 MLO_PAUSE_RX = BIT(0),
17 MLO_PAUSE_TX = BIT(1),
18 MLO_PAUSE_TXRX_MASK = MLO_PAUSE_TX | MLO_PAUSE_RX,
19 MLO_PAUSE_AN = BIT(2),
21 MLO_AN_PHY = 0, /* Conventional PHY */
22 MLO_AN_FIXED, /* Fixed-link mode */
23 MLO_AN_INBAND, /* In-band protocol */
25 /* PCS "negotiation" mode.
26 * PHYLINK_PCS_NEG_NONE - protocol has no inband capability
27 * PHYLINK_PCS_NEG_OUTBAND - some out of band or fixed link setting
28 * PHYLINK_PCS_NEG_INBAND_DISABLED - inband mode disabled, e.g.
29 * 1000base-X with autoneg off
30 * PHYLINK_PCS_NEG_INBAND_ENABLED - inband mode enabled
31 * Additionally, this can be tested using bitmasks:
32 * PHYLINK_PCS_NEG_INBAND - inband mode selected
33 * PHYLINK_PCS_NEG_ENABLED - negotiation mode enabled
35 PHYLINK_PCS_NEG_NONE = 0,
36 PHYLINK_PCS_NEG_ENABLED = BIT(4),
37 PHYLINK_PCS_NEG_OUTBAND = BIT(5),
38 PHYLINK_PCS_NEG_INBAND = BIT(6),
39 PHYLINK_PCS_NEG_INBAND_DISABLED = PHYLINK_PCS_NEG_INBAND,
40 PHYLINK_PCS_NEG_INBAND_ENABLED = PHYLINK_PCS_NEG_INBAND |
41 PHYLINK_PCS_NEG_ENABLED,
43 /* MAC_SYM_PAUSE and MAC_ASYM_PAUSE are used when configuring our
44 * autonegotiation advertisement. They correspond to the PAUSE and
45 * ASM_DIR bits defined by 802.3, respectively.
47 * The following table lists the values of tx_pause and rx_pause which
48 * might be requested in mac_link_up. The exact values depend on either
49 * the results of autonegotation (if MLO_PAUSE_AN is set) or user
50 * configuration (if MLO_PAUSE_AN is not set).
52 * MAC_SYM_PAUSE MAC_ASYM_PAUSE MLO_PAUSE_AN tx_pause/rx_pause
53 * ============= ============== ============ ==================
56 * 0 1 0 0/0, 0/1, 1/0, 1/1
60 * 1 1 0 0/0, 0/1, 1/0, 1/1
63 * If you set MAC_ASYM_PAUSE, the user may request any combination of
64 * tx_pause and rx_pause. You do not have to support these
67 * However, you should support combinations of tx_pause and rx_pause
68 * which might be the result of autonegotation. For example, don't set
69 * MAC_SYM_PAUSE unless your device can support tx_pause and rx_pause
72 MAC_SYM_PAUSE = BIT(0),
73 MAC_ASYM_PAUSE = BIT(1),
76 MAC_10 = MAC_10HD | MAC_10FD,
79 MAC_100 = MAC_100HD | MAC_100FD,
82 MAC_1000 = MAC_1000HD | MAC_1000FD,
85 MAC_10000FD = BIT(10),
86 MAC_20000FD = BIT(11),
87 MAC_25000FD = BIT(12),
88 MAC_40000FD = BIT(13),
89 MAC_50000FD = BIT(14),
90 MAC_56000FD = BIT(15),
91 MAC_100000FD = BIT(16),
92 MAC_200000FD = BIT(17),
93 MAC_400000FD = BIT(18),
96 static inline bool phylink_autoneg_inband(unsigned int mode)
98 return mode == MLO_AN_INBAND;
102 * phylink_pcs_neg_mode() - helper to determine PCS inband mode
103 * @mode: one of %MLO_AN_FIXED, %MLO_AN_PHY, %MLO_AN_INBAND.
104 * @interface: interface mode to be used
105 * @advertising: adertisement ethtool link mode mask
107 * Determines the negotiation mode to be used by the PCS, and returns
110 * - %PHYLINK_PCS_NEG_NONE: interface mode does not support inband
111 * - %PHYLINK_PCS_NEG_OUTBAND: an out of band mode (e.g. reading the PHY)
113 * - %PHYLINK_PCS_NEG_INBAND_DISABLED: inband mode selected but autoneg
115 * - %PHYLINK_PCS_NEG_INBAND_ENABLED: inband mode selected and autoneg enabled
117 * Note: this is for cases where the PCS itself is involved in negotiation
118 * (e.g. Clause 37, SGMII and similar) not Clause 73.
120 static inline unsigned int phylink_pcs_neg_mode(unsigned int mode,
121 phy_interface_t interface,
122 const unsigned long *advertising)
124 unsigned int neg_mode;
127 case PHY_INTERFACE_MODE_SGMII:
128 case PHY_INTERFACE_MODE_QSGMII:
129 case PHY_INTERFACE_MODE_QUSGMII:
130 case PHY_INTERFACE_MODE_USXGMII:
131 /* These protocols are designed for use with a PHY which
132 * communicates its negotiation result back to the MAC via
133 * inband communication. Note: there exist PHYs that run
134 * with SGMII but do not send the inband data.
136 if (!phylink_autoneg_inband(mode))
137 neg_mode = PHYLINK_PCS_NEG_OUTBAND;
139 neg_mode = PHYLINK_PCS_NEG_INBAND_ENABLED;
142 case PHY_INTERFACE_MODE_1000BASEX:
143 case PHY_INTERFACE_MODE_2500BASEX:
144 /* 1000base-X is designed for use media-side for Fibre
145 * connections, and thus the Autoneg bit needs to be
146 * taken into account. We also do this for 2500base-X
147 * as well, but drivers may not support this, so may
148 * need to override this.
150 if (!phylink_autoneg_inband(mode))
151 neg_mode = PHYLINK_PCS_NEG_OUTBAND;
152 else if (linkmode_test_bit(ETHTOOL_LINK_MODE_Autoneg_BIT,
154 neg_mode = PHYLINK_PCS_NEG_INBAND_ENABLED;
156 neg_mode = PHYLINK_PCS_NEG_INBAND_DISABLED;
160 neg_mode = PHYLINK_PCS_NEG_NONE;
168 * struct phylink_link_state - link state structure
169 * @advertising: ethtool bitmask containing advertised link modes
170 * @lp_advertising: ethtool bitmask containing link partner advertised link
172 * @interface: link &typedef phy_interface_t mode
173 * @speed: link speed, one of the SPEED_* constants.
174 * @duplex: link duplex mode, one of DUPLEX_* constants.
175 * @pause: link pause state, described by MLO_PAUSE_* constants.
176 * @rate_matching: rate matching being performed, one of the RATE_MATCH_*
177 * constants. If rate matching is taking place, then the speed/duplex of
178 * the medium link mode (@speed and @duplex) and the speed/duplex of the phy
179 * interface mode (@interface) are different.
180 * @link: true if the link is up.
181 * @an_complete: true if autonegotiation has completed.
183 struct phylink_link_state {
184 __ETHTOOL_DECLARE_LINK_MODE_MASK(advertising);
185 __ETHTOOL_DECLARE_LINK_MODE_MASK(lp_advertising);
186 phy_interface_t interface;
192 unsigned int an_complete:1;
195 enum phylink_op_type {
201 * struct phylink_config - PHYLINK configuration structure
202 * @dev: a pointer to a struct device associated with the MAC
203 * @type: operation type of PHYLINK instance
204 * @legacy_pre_march2020: driver has not been updated for March 2020 updates
205 * (See commit 7cceb599d15d ("net: phylink: avoid mac_config calls")
206 * @poll_fixed_state: if true, starts link_poll,
207 * if MAC link is at %MLO_AN_FIXED mode.
208 * @mac_managed_pm: if true, indicate the MAC driver is responsible for PHY PM.
209 * @ovr_an_inband: if true, override PCS to MLO_AN_INBAND
210 * @get_fixed_state: callback to execute to determine the fixed link state,
211 * if MAC link is at %MLO_AN_FIXED mode.
212 * @supported_interfaces: bitmap describing which PHY_INTERFACE_MODE_xxx
213 * are supported by the MAC/PCS.
214 * @mac_capabilities: MAC pause/speed/duplex capabilities.
216 struct phylink_config {
218 enum phylink_op_type type;
219 bool legacy_pre_march2020;
220 bool poll_fixed_state;
223 void (*get_fixed_state)(struct phylink_config *config,
224 struct phylink_link_state *state);
225 DECLARE_PHY_INTERFACE_MASK(supported_interfaces);
226 unsigned long mac_capabilities;
230 * struct phylink_mac_ops - MAC operations structure.
231 * @validate: Validate and update the link configuration.
232 * @mac_select_pcs: Select a PCS for the interface mode.
233 * @mac_pcs_get_state: Read the current link state from the hardware.
234 * @mac_prepare: prepare for a major reconfiguration of the interface.
235 * @mac_config: configure the MAC for the selected mode and state.
236 * @mac_finish: finish a major reconfiguration of the interface.
237 * @mac_an_restart: restart 802.3z BaseX autonegotiation.
238 * @mac_link_down: take the link down.
239 * @mac_link_up: allow the link to come up.
241 * The individual methods are described more fully below.
243 struct phylink_mac_ops {
244 void (*validate)(struct phylink_config *config,
245 unsigned long *supported,
246 struct phylink_link_state *state);
247 struct phylink_pcs *(*mac_select_pcs)(struct phylink_config *config,
248 phy_interface_t interface);
249 void (*mac_pcs_get_state)(struct phylink_config *config,
250 struct phylink_link_state *state);
251 int (*mac_prepare)(struct phylink_config *config, unsigned int mode,
252 phy_interface_t iface);
253 void (*mac_config)(struct phylink_config *config, unsigned int mode,
254 const struct phylink_link_state *state);
255 int (*mac_finish)(struct phylink_config *config, unsigned int mode,
256 phy_interface_t iface);
257 void (*mac_an_restart)(struct phylink_config *config);
258 void (*mac_link_down)(struct phylink_config *config, unsigned int mode,
259 phy_interface_t interface);
260 void (*mac_link_up)(struct phylink_config *config,
261 struct phy_device *phy, unsigned int mode,
262 phy_interface_t interface, int speed, int duplex,
263 bool tx_pause, bool rx_pause);
266 #if 0 /* For kernel-doc purposes only. */
268 * validate - Validate and update the link configuration
269 * @config: a pointer to a &struct phylink_config.
270 * @supported: ethtool bitmask for supported link modes.
271 * @state: a pointer to a &struct phylink_link_state.
273 * Clear bits in the @supported and @state->advertising masks that
274 * are not supportable by the MAC.
276 * Note that the PHY may be able to transform from one connection
277 * technology to another, so, eg, don't clear 1000BaseX just
278 * because the MAC is unable to BaseX mode. This is more about
279 * clearing unsupported speeds and duplex settings. The port modes
280 * should not be cleared; phylink_set_port_modes() will help with this.
282 * When @config->supported_interfaces has been set, phylink will iterate
283 * over the supported interfaces to determine the full capability of the
284 * MAC. The validation function must not print errors if @state->interface
285 * is set to an unexpected value.
287 * When @config->supported_interfaces is empty, phylink will call this
288 * function with @state->interface set to %PHY_INTERFACE_MODE_NA, and
289 * expects the MAC driver to return all supported link modes.
291 * If the @state->interface mode is not supported, then the @supported
292 * mask must be cleared.
294 * This member is optional; if not set, the generic validator will be
295 * used making use of @config->mac_capabilities and
296 * @config->supported_interfaces to determine which link modes are
299 void validate(struct phylink_config *config, unsigned long *supported,
300 struct phylink_link_state *state);
302 * mac_select_pcs: Select a PCS for the interface mode.
303 * @config: a pointer to a &struct phylink_config.
304 * @interface: PHY interface mode for PCS
306 * Return the &struct phylink_pcs for the specified interface mode, or
307 * NULL if none is required, or an error pointer on error.
309 * This must not modify any state. It is used to query which PCS should
310 * be used. Phylink will use this during validation to ensure that the
311 * configuration is valid, and when setting a configuration to internally
312 * set the PCS that will be used.
314 struct phylink_pcs *mac_select_pcs(struct phylink_config *config,
315 phy_interface_t interface);
318 * mac_pcs_get_state() - Read the current inband link state from the hardware
319 * @config: a pointer to a &struct phylink_config.
320 * @state: a pointer to a &struct phylink_link_state.
322 * Read the current inband link state from the MAC PCS, reporting the
323 * current speed in @state->speed, duplex mode in @state->duplex, pause
324 * mode in @state->pause using the %MLO_PAUSE_RX and %MLO_PAUSE_TX bits,
325 * negotiation completion state in @state->an_complete, and link up state
326 * in @state->link. If possible, @state->lp_advertising should also be
329 * Note: This is a legacy method. This function will not be called unless
330 * legacy_pre_march2020 is set in &struct phylink_config and there is no
333 void mac_pcs_get_state(struct phylink_config *config,
334 struct phylink_link_state *state);
337 * mac_prepare() - prepare to change the PHY interface mode
338 * @config: a pointer to a &struct phylink_config.
339 * @mode: one of %MLO_AN_FIXED, %MLO_AN_PHY, %MLO_AN_INBAND.
340 * @iface: interface mode to switch to
342 * phylink will call this method at the beginning of a full initialisation
343 * of the link, which includes changing the interface mode or at initial
344 * startup time. It may be called for the current mode. The MAC driver
345 * should perform whatever actions are required, e.g. disabling the
348 * This will be the first call in the sequence:
352 * - possible pcs_an_restart()
355 * Returns zero on success, or negative errno on failure which will be
356 * reported to the kernel log.
358 int mac_prepare(struct phylink_config *config, unsigned int mode,
359 phy_interface_t iface);
362 * mac_config() - configure the MAC for the selected mode and state
363 * @config: a pointer to a &struct phylink_config.
364 * @mode: one of %MLO_AN_FIXED, %MLO_AN_PHY, %MLO_AN_INBAND.
365 * @state: a pointer to a &struct phylink_link_state.
367 * Note - not all members of @state are valid. In particular,
368 * @state->lp_advertising, @state->link, @state->an_complete are never
369 * guaranteed to be correct, and so any mac_config() implementation must
370 * never reference these fields.
372 * Note: For legacy March 2020 drivers (drivers with legacy_pre_march2020 set
373 * in their &phylnk_config and which don't have a PCS), this function will be
374 * called on each link up event, and to also change the in-band advert. For
375 * non-legacy drivers, it will only be called to reconfigure the MAC for a
376 * "major" change in e.g. interface mode. It will not be called for changes
377 * in speed, duplex or pause modes or to change the in-band advertisement.
378 * In any case, it is strongly preferred that speed, duplex and pause settings
379 * are handled in the mac_link_up() method and not in this method.
381 * (this requires a rewrite - please refer to mac_link_up() for situations
382 * where the PCS and MAC are not tightly integrated.)
384 * In all negotiation modes, as defined by @mode, @state->pause indicates the
385 * pause settings which should be applied as follows. If %MLO_PAUSE_AN is not
386 * set, %MLO_PAUSE_TX and %MLO_PAUSE_RX indicate whether the MAC should send
387 * pause frames and/or act on received pause frames respectively. Otherwise,
388 * the results of in-band negotiation/status from the MAC PCS should be used
389 * to control the MAC pause mode settings.
391 * The action performed depends on the currently selected mode:
393 * %MLO_AN_FIXED, %MLO_AN_PHY:
394 * Configure for non-inband negotiation mode, where the link settings
395 * are completely communicated via mac_link_up(). The physical link
396 * protocol from the MAC is specified by @state->interface.
398 * @state->advertising may be used, but is not required.
400 * Older drivers (prior to the mac_link_up() change) may use @state->speed,
401 * @state->duplex and @state->pause to configure the MAC, but this is
402 * deprecated; such drivers should be converted to use mac_link_up().
404 * Other members of @state must be ignored.
406 * Valid state members: interface, advertising.
407 * Deprecated state members: speed, duplex, pause.
410 * place the link in an inband negotiation mode (such as 802.3z
411 * 1000base-X or Cisco SGMII mode depending on the @state->interface
412 * mode). In both cases, link state management (whether the link
413 * is up or not) is performed by the MAC, and reported via the
414 * mac_pcs_get_state() callback. Changes in link state must be made
415 * by calling phylink_mac_change().
417 * Interface mode specific details are mentioned below.
419 * If in 802.3z mode, the link speed is fixed, dependent on the
420 * @state->interface. Duplex and pause modes are negotiated via
421 * the in-band configuration word. Advertised pause modes are set
422 * according to the @state->an_enabled and @state->advertising
423 * flags. Beware of MACs which only support full duplex at gigabit
426 * If in Cisco SGMII mode, the link speed and duplex mode are passed
427 * in the serial bitstream 16-bit configuration word, and the MAC
428 * should be configured to read these bits and acknowledge the
429 * configuration word. Nothing is advertised by the MAC. The MAC is
430 * responsible for reading the configuration word and configuring
431 * itself accordingly.
433 * Valid state members: interface, an_enabled, pause, advertising.
435 * Implementations are expected to update the MAC to reflect the
436 * requested settings - i.o.w., if nothing has changed between two
437 * calls, no action is expected. If only flow control settings have
438 * changed, flow control should be updated *without* taking the link
439 * down. This "update" behaviour is critical to avoid bouncing the
442 void mac_config(struct phylink_config *config, unsigned int mode,
443 const struct phylink_link_state *state);
446 * mac_finish() - finish a to change the PHY interface mode
447 * @config: a pointer to a &struct phylink_config.
448 * @mode: one of %MLO_AN_FIXED, %MLO_AN_PHY, %MLO_AN_INBAND.
449 * @iface: interface mode to switch to
451 * phylink will call this if it called mac_prepare() to allow the MAC to
452 * complete any necessary steps after the MAC and PCS have been configured
453 * for the @mode and @iface. E.g. a MAC driver may wish to re-enable the
454 * Serdes PHY here if it was previously disabled by mac_prepare().
456 * Returns zero on success, or negative errno on failure which will be
457 * reported to the kernel log.
459 int mac_finish(struct phylink_config *config, unsigned int mode,
460 phy_interface_t iface);
463 * mac_an_restart() - restart 802.3z BaseX autonegotiation
464 * @config: a pointer to a &struct phylink_config.
466 * Note: This is a legacy method. This function will not be called unless
467 * legacy_pre_march2020 is set in &struct phylink_config and there is no
470 void mac_an_restart(struct phylink_config *config);
473 * mac_link_down() - take the link down
474 * @config: a pointer to a &struct phylink_config.
475 * @mode: link autonegotiation mode
476 * @interface: link &typedef phy_interface_t mode
478 * If @mode is not an in-band negotiation mode (as defined by
479 * phylink_autoneg_inband()), force the link down and disable any
480 * Energy Efficient Ethernet MAC configuration. Interface type
481 * selection must be done in mac_config().
483 void mac_link_down(struct phylink_config *config, unsigned int mode,
484 phy_interface_t interface);
487 * mac_link_up() - allow the link to come up
488 * @config: a pointer to a &struct phylink_config.
489 * @phy: any attached phy
490 * @mode: link autonegotiation mode
491 * @interface: link &typedef phy_interface_t mode
493 * @duplex: link duplex
494 * @tx_pause: link transmit pause enablement status
495 * @rx_pause: link receive pause enablement status
497 * Configure the MAC for an established link.
499 * @speed, @duplex, @tx_pause and @rx_pause indicate the finalised link
500 * settings, and should be used to configure the MAC block appropriately
501 * where these settings are not automatically conveyed from the PCS block,
502 * or if in-band negotiation (as defined by phylink_autoneg_inband(@mode))
505 * Note that when 802.3z in-band negotiation is in use, it is possible
506 * that the user wishes to override the pause settings, and this should
507 * be allowed when considering the implementation of this method.
509 * If in-band negotiation mode is disabled, allow the link to come up. If
510 * @phy is non-%NULL, configure Energy Efficient Ethernet by calling
511 * phy_init_eee() and perform appropriate MAC configuration for EEE.
512 * Interface type selection must be done in mac_config().
514 void mac_link_up(struct phylink_config *config, struct phy_device *phy,
515 unsigned int mode, phy_interface_t interface,
516 int speed, int duplex, bool tx_pause, bool rx_pause);
519 struct phylink_pcs_ops;
522 * struct phylink_pcs - PHYLINK PCS instance
523 * @ops: a pointer to the &struct phylink_pcs_ops structure
524 * @phylink: pointer to &struct phylink_config
525 * @neg_mode: provide PCS neg mode via "mode" argument
526 * @poll: poll the PCS for link changes
528 * This structure is designed to be embedded within the PCS private data,
529 * and will be passed between phylink and the PCS.
531 * The @phylink member is private to phylink and must not be touched by
535 const struct phylink_pcs_ops *ops;
536 struct phylink *phylink;
542 * struct phylink_pcs_ops - MAC PCS operations structure.
543 * @pcs_validate: validate the link configuration.
544 * @pcs_enable: enable the PCS.
545 * @pcs_disable: disable the PCS.
546 * @pcs_pre_config: pre-mac_config method (for errata)
547 * @pcs_post_config: post-mac_config method (for arrata)
548 * @pcs_get_state: read the current MAC PCS link state from the hardware.
549 * @pcs_config: configure the MAC PCS for the selected mode and state.
550 * @pcs_an_restart: restart 802.3z BaseX autonegotiation.
551 * @pcs_link_up: program the PCS for the resolved link configuration
554 struct phylink_pcs_ops {
555 int (*pcs_validate)(struct phylink_pcs *pcs, unsigned long *supported,
556 const struct phylink_link_state *state);
557 int (*pcs_enable)(struct phylink_pcs *pcs);
558 void (*pcs_disable)(struct phylink_pcs *pcs);
559 void (*pcs_pre_config)(struct phylink_pcs *pcs,
560 phy_interface_t interface);
561 int (*pcs_post_config)(struct phylink_pcs *pcs,
562 phy_interface_t interface);
563 void (*pcs_get_state)(struct phylink_pcs *pcs,
564 struct phylink_link_state *state);
565 int (*pcs_config)(struct phylink_pcs *pcs, unsigned int neg_mode,
566 phy_interface_t interface,
567 const unsigned long *advertising,
568 bool permit_pause_to_mac);
569 void (*pcs_an_restart)(struct phylink_pcs *pcs);
570 void (*pcs_link_up)(struct phylink_pcs *pcs, unsigned int neg_mode,
571 phy_interface_t interface, int speed, int duplex);
574 #if 0 /* For kernel-doc purposes only. */
576 * pcs_validate() - validate the link configuration.
577 * @pcs: a pointer to a &struct phylink_pcs.
578 * @supported: ethtool bitmask for supported link modes.
579 * @state: a const pointer to a &struct phylink_link_state.
581 * Validate the interface mode, and advertising's autoneg bit, removing any
582 * media ethtool link modes that would not be supportable from the supported
583 * mask. Phylink will propagate the changes to the advertising mask. See the
584 * &struct phylink_mac_ops validate() method.
586 * Returns -EINVAL if the interface mode/autoneg mode is not supported.
587 * Returns non-zero positive if the link state can be supported.
589 int pcs_validate(struct phylink_pcs *pcs, unsigned long *supported,
590 const struct phylink_link_state *state);
593 * pcs_enable() - enable the PCS.
594 * @pcs: a pointer to a &struct phylink_pcs.
596 int pcs_enable(struct phylink_pcs *pcs);
599 * pcs_disable() - disable the PCS.
600 * @pcs: a pointer to a &struct phylink_pcs.
602 void pcs_disable(struct phylink_pcs *pcs);
605 * pcs_get_state() - Read the current inband link state from the hardware
606 * @pcs: a pointer to a &struct phylink_pcs.
607 * @state: a pointer to a &struct phylink_link_state.
609 * Read the current inband link state from the MAC PCS, reporting the
610 * current speed in @state->speed, duplex mode in @state->duplex, pause
611 * mode in @state->pause using the %MLO_PAUSE_RX and %MLO_PAUSE_TX bits,
612 * negotiation completion state in @state->an_complete, and link up state
613 * in @state->link. If possible, @state->lp_advertising should also be
616 * When present, this overrides mac_pcs_get_state() in &struct
619 void pcs_get_state(struct phylink_pcs *pcs,
620 struct phylink_link_state *state);
623 * pcs_config() - Configure the PCS mode and advertisement
624 * @pcs: a pointer to a &struct phylink_pcs.
625 * @neg_mode: link negotiation mode (see below)
626 * @interface: interface mode to be used
627 * @advertising: adertisement ethtool link mode mask
628 * @permit_pause_to_mac: permit forwarding pause resolution to MAC
630 * Configure the PCS for the operating mode, the interface mode, and set
631 * the advertisement mask. @permit_pause_to_mac indicates whether the
632 * hardware may forward the pause mode resolution to the MAC.
634 * When operating in %MLO_AN_INBAND, inband should always be enabled,
635 * otherwise inband should be disabled.
637 * For SGMII, there is no advertisement from the MAC side, the PCS should
638 * be programmed to acknowledge the inband word from the PHY.
640 * For 1000BASE-X, the advertisement should be programmed into the PCS.
642 * For most 10GBASE-R, there is no advertisement.
644 * The %neg_mode argument should be tested via the phylink_mode_*() family of
645 * functions, or for PCS that set pcs->neg_mode true, should be tested
646 * against the %PHYLINK_PCS_NEG_* definitions.
648 int pcs_config(struct phylink_pcs *pcs, unsigned int neg_mode,
649 phy_interface_t interface, const unsigned long *advertising,
650 bool permit_pause_to_mac);
653 * pcs_an_restart() - restart 802.3z BaseX autonegotiation
654 * @pcs: a pointer to a &struct phylink_pcs.
656 * When PCS ops are present, this overrides mac_an_restart() in &struct
659 void pcs_an_restart(struct phylink_pcs *pcs);
662 * pcs_link_up() - program the PCS for the resolved link configuration
663 * @pcs: a pointer to a &struct phylink_pcs.
664 * @neg_mode: link negotiation mode (see below)
665 * @interface: link &typedef phy_interface_t mode
667 * @duplex: link duplex
669 * This call will be made just before mac_link_up() to inform the PCS of
670 * the resolved link parameters. For example, a PCS operating in SGMII
671 * mode without in-band AN needs to be manually configured for the link
672 * and duplex setting. Otherwise, this should be a no-op.
674 * The %mode argument should be tested via the phylink_mode_*() family of
675 * functions, or for PCS that set pcs->neg_mode true, should be tested
676 * against the %PHYLINK_PCS_NEG_* definitions.
678 void pcs_link_up(struct phylink_pcs *pcs, unsigned int neg_mode,
679 phy_interface_t interface, int speed, int duplex);
682 void phylink_caps_to_linkmodes(unsigned long *linkmodes, unsigned long caps);
683 unsigned long phylink_get_capabilities(phy_interface_t interface,
684 unsigned long mac_capabilities,
686 void phylink_validate_mask_caps(unsigned long *supported,
687 struct phylink_link_state *state,
689 void phylink_generic_validate(struct phylink_config *config,
690 unsigned long *supported,
691 struct phylink_link_state *state);
693 struct phylink *phylink_create(struct phylink_config *,
694 const struct fwnode_handle *,
696 const struct phylink_mac_ops *);
697 void phylink_destroy(struct phylink *);
698 bool phylink_expects_phy(struct phylink *pl);
700 int phylink_connect_phy(struct phylink *, struct phy_device *);
701 int phylink_of_phy_connect(struct phylink *, struct device_node *, u32 flags);
702 int phylink_fwnode_phy_connect(struct phylink *pl,
703 const struct fwnode_handle *fwnode,
705 void phylink_disconnect_phy(struct phylink *);
707 void phylink_mac_change(struct phylink *, bool up);
708 void phylink_pcs_change(struct phylink_pcs *, bool up);
710 void phylink_start(struct phylink *);
711 void phylink_stop(struct phylink *);
713 void phylink_suspend(struct phylink *pl, bool mac_wol);
714 void phylink_resume(struct phylink *pl);
716 void phylink_ethtool_get_wol(struct phylink *, struct ethtool_wolinfo *);
717 int phylink_ethtool_set_wol(struct phylink *, struct ethtool_wolinfo *);
719 int phylink_ethtool_ksettings_get(struct phylink *,
720 struct ethtool_link_ksettings *);
721 int phylink_ethtool_ksettings_set(struct phylink *,
722 const struct ethtool_link_ksettings *);
723 int phylink_ethtool_nway_reset(struct phylink *);
724 void phylink_ethtool_get_pauseparam(struct phylink *,
725 struct ethtool_pauseparam *);
726 int phylink_ethtool_set_pauseparam(struct phylink *,
727 struct ethtool_pauseparam *);
728 int phylink_get_eee_err(struct phylink *);
729 int phylink_init_eee(struct phylink *, bool);
730 int phylink_ethtool_get_eee(struct phylink *, struct ethtool_eee *);
731 int phylink_ethtool_set_eee(struct phylink *, struct ethtool_eee *);
732 int phylink_mii_ioctl(struct phylink *, struct ifreq *, int);
733 int phylink_speed_down(struct phylink *pl, bool sync);
734 int phylink_speed_up(struct phylink *pl);
736 #define phylink_zero(bm) \
737 bitmap_zero(bm, __ETHTOOL_LINK_MODE_MASK_NBITS)
738 #define __phylink_do_bit(op, bm, mode) \
739 op(ETHTOOL_LINK_MODE_ ## mode ## _BIT, bm)
741 #define phylink_set(bm, mode) __phylink_do_bit(__set_bit, bm, mode)
742 #define phylink_clear(bm, mode) __phylink_do_bit(__clear_bit, bm, mode)
743 #define phylink_test(bm, mode) __phylink_do_bit(test_bit, bm, mode)
745 void phylink_set_port_modes(unsigned long *bits);
748 * phylink_get_link_timer_ns - return the PCS link timer value
749 * @interface: link &typedef phy_interface_t mode
751 * Return the PCS link timer setting in nanoseconds for the PHY @interface
752 * mode, or -EINVAL if not appropriate.
754 static inline int phylink_get_link_timer_ns(phy_interface_t interface)
757 case PHY_INTERFACE_MODE_SGMII:
758 case PHY_INTERFACE_MODE_QSGMII:
759 case PHY_INTERFACE_MODE_USXGMII:
762 case PHY_INTERFACE_MODE_1000BASEX:
763 case PHY_INTERFACE_MODE_2500BASEX:
771 void phylink_mii_c22_pcs_decode_state(struct phylink_link_state *state,
773 void phylink_mii_c22_pcs_get_state(struct mdio_device *pcs,
774 struct phylink_link_state *state);
775 int phylink_mii_c22_pcs_encode_advertisement(phy_interface_t interface,
776 const unsigned long *advertising);
777 int phylink_mii_c22_pcs_config(struct mdio_device *pcs,
778 phy_interface_t interface,
779 const unsigned long *advertising,
780 unsigned int neg_mode);
781 void phylink_mii_c22_pcs_an_restart(struct mdio_device *pcs);
783 void phylink_resolve_c73(struct phylink_link_state *state);
785 void phylink_mii_c45_pcs_get_state(struct mdio_device *pcs,
786 struct phylink_link_state *state);
788 void phylink_decode_usxgmii_word(struct phylink_link_state *state,