Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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;
10struct fwnode_handle;
11struct net_device;
12
13enum {
14 MLO_PAUSE_NONE,
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),
19
20 MLO_AN_PHY = 0, /* Conventional PHY */
21 MLO_AN_FIXED, /* Fixed-link mode */
22 MLO_AN_INBAND, /* In-band protocol */
23
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
33 */
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,
41
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.
45 *
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).
50 *
51 * MAC_SYM_PAUSE MAC_ASYM_PAUSE MLO_PAUSE_AN tx_pause/rx_pause
52 * ============= ============== ============ ==================
53 * 0 0 0 0/0
54 * 0 0 1 0/0
55 * 0 1 0 0/0, 0/1, 1/0, 1/1
56 * 0 1 1 0/0, 1/0
57 * 1 0 0 0/0, 1/1
58 * 1 0 1 0/0, 1/1
59 * 1 1 0 0/0, 0/1, 1/0, 1/1
60 * 1 1 1 0/0, 0/1, 1/1
61 *
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
64 * combinations.
65 *
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
69 * at the same time.
70 */
71 MAC_SYM_PAUSE = BIT(0),
72 MAC_ASYM_PAUSE = BIT(1),
73 MAC_10HD = BIT(2),
74 MAC_10FD = BIT(3),
75 MAC_10 = MAC_10HD | MAC_10FD,
76 MAC_100HD = BIT(4),
77 MAC_100FD = BIT(5),
78 MAC_100 = MAC_100HD | MAC_100FD,
79 MAC_1000HD = BIT(6),
80 MAC_1000FD = BIT(7),
81 MAC_1000 = MAC_1000HD | MAC_1000FD,
82 MAC_2500FD = BIT(8),
83 MAC_5000FD = BIT(9),
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),
93};
94
95static inline bool phylink_autoneg_inband(unsigned int mode)
96{
97 return mode == MLO_AN_INBAND;
98}
99
100/**
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
105 *
106 * Determines the negotiation mode to be used by the PCS, and returns
107 * one of:
108 *
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)
111 * will be used.
112 * - %PHYLINK_PCS_NEG_INBAND_DISABLED: inband mode selected but autoneg
113 * disabled
114 * - %PHYLINK_PCS_NEG_INBAND_ENABLED: inband mode selected and autoneg enabled
115 *
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.
118 */
119static inline unsigned int phylink_pcs_neg_mode(unsigned int mode,
120 phy_interface_t interface,
121 const unsigned long *advertising)
122{
123 unsigned int neg_mode;
124
125 switch (interface) {
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.
134 */
135 if (!phylink_autoneg_inband(mode))
136 neg_mode = PHYLINK_PCS_NEG_OUTBAND;
137 else
138 neg_mode = PHYLINK_PCS_NEG_INBAND_ENABLED;
139 break;
140
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.
148 */
149 if (!phylink_autoneg_inband(mode))
150 neg_mode = PHYLINK_PCS_NEG_OUTBAND;
151 else if (linkmode_test_bit(ETHTOOL_LINK_MODE_Autoneg_BIT,
152 advertising))
153 neg_mode = PHYLINK_PCS_NEG_INBAND_ENABLED;
154 else
155 neg_mode = PHYLINK_PCS_NEG_INBAND_DISABLED;
156 break;
157
158 default:
159 neg_mode = PHYLINK_PCS_NEG_NONE;
160 break;
161 }
162
163 return neg_mode;
164}
165
166/**
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
170 * modes
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.
181 */
182struct phylink_link_state {
183 __ETHTOOL_DECLARE_LINK_MODE_MASK(advertising);
184 __ETHTOOL_DECLARE_LINK_MODE_MASK(lp_advertising);
185 phy_interface_t interface;
186 int speed;
187 int duplex;
188 int pause;
189 int rate_matching;
190 unsigned int link:1;
191 unsigned int an_complete:1;
192};
193
194enum phylink_op_type {
195 PHYLINK_NETDEV = 0,
196 PHYLINK_DEV,
197};
198
199/**
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.
214 */
215struct phylink_config {
216 struct device *dev;
217 enum phylink_op_type type;
218 bool legacy_pre_march2020;
219 bool poll_fixed_state;
220 bool mac_managed_pm;
221 bool ovr_an_inband;
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;
226};
227
228/**
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.
239 *
240 * The individual methods are described more fully below.
241 */
242struct 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);
263};
264
265#if 0 /* For kernel-doc purposes only. */
266/**
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.
271 *
272 * Clear bits in the @supported and @state->advertising masks that
273 * are not supportable by the MAC.
274 *
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.
280 *
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.
285 *
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.
289 *
290 * If the @state->interface mode is not supported, then the @supported
291 * mask must be cleared.
292 *
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
296 * supported.
297 */
298void validate(struct phylink_config *config, unsigned long *supported,
299 struct phylink_link_state *state);
300/**
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
304 *
305 * Return the &struct phylink_pcs for the specified interface mode, or
306 * NULL if none is required, or an error pointer on error.
307 *
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.
312 */
313struct phylink_pcs *mac_select_pcs(struct phylink_config *config,
314 phy_interface_t interface);
315
316/**
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.
320 *
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
326 * populated.
327 *
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
330 * PCS attached.
331 */
332void mac_pcs_get_state(struct phylink_config *config,
333 struct phylink_link_state *state);
334
335/**
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
340 *
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
345 * Serdes PHY.
346 *
347 * This will be the first call in the sequence:
348 * - mac_prepare()
349 * - mac_config()
350 * - pcs_config()
351 * - possible pcs_an_restart()
352 * - mac_finish()
353 *
354 * Returns zero on success, or negative errno on failure which will be
355 * reported to the kernel log.
356 */
357int mac_prepare(struct phylink_config *config, unsigned int mode,
358 phy_interface_t iface);
359
360/**
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.
365 *
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.
370 *
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.
379 *
380 * (this requires a rewrite - please refer to mac_link_up() for situations
381 * where the PCS and MAC are not tightly integrated.)
382 *
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.
389 *
390 * The action performed depends on the currently selected mode:
391 *
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.
396 *
397 * @state->advertising may be used, but is not required.
398 *
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().
402 *
403 * Other members of @state must be ignored.
404 *
405 * Valid state members: interface, advertising.
406 * Deprecated state members: speed, duplex, pause.
407 *
408 * %MLO_AN_INBAND:
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().
415 *
416 * Interface mode specific details are mentioned below.
417 *
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
423 * and higher speeds.
424 *
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.
431 *
432 * Valid state members: interface, an_enabled, pause, advertising.
433 *
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
439 * link up status.
440 */
441void mac_config(struct phylink_config *config, unsigned int mode,
442 const struct phylink_link_state *state);
443
444/**
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
449 *
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().
454 *
455 * Returns zero on success, or negative errno on failure which will be
456 * reported to the kernel log.
457 */
458int mac_finish(struct phylink_config *config, unsigned int mode,
459 phy_interface_t iface);
460
461/**
462 * mac_an_restart() - restart 802.3z BaseX autonegotiation
463 * @config: a pointer to a &struct phylink_config.
464 *
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
467 * PCS attached.
468 */
469void mac_an_restart(struct phylink_config *config);
470
471/**
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
476 *
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().
481 */
482void mac_link_down(struct phylink_config *config, unsigned int mode,
483 phy_interface_t interface);
484
485/**
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
491 * @speed: link speed
492 * @duplex: link duplex
493 * @tx_pause: link transmit pause enablement status
494 * @rx_pause: link receive pause enablement status
495 *
496 * Configure the MAC for an established link.
497 *
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))
502 * is disabled.
503 *
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.
507 *
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().
512 */
513void 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);
516#endif
517
518struct phylink_pcs_ops;
519
520/**
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
525 *
526 * This structure is designed to be embedded within the PCS private data,
527 * and will be passed between phylink and the PCS.
528 */
529struct phylink_pcs {
530 const struct phylink_pcs_ops *ops;
531 bool neg_mode;
532 bool poll;
533};
534
535/**
536 * struct phylink_pcs_ops - MAC PCS operations structure.
537 * @pcs_validate: validate the link configuration.
538 * @pcs_get_state: read the current MAC PCS link state from the hardware.
539 * @pcs_config: configure the MAC PCS for the selected mode and state.
540 * @pcs_an_restart: restart 802.3z BaseX autonegotiation.
541 * @pcs_link_up: program the PCS for the resolved link configuration
542 * (where necessary).
543 */
544struct phylink_pcs_ops {
545 int (*pcs_validate)(struct phylink_pcs *pcs, unsigned long *supported,
546 const struct phylink_link_state *state);
547 void (*pcs_get_state)(struct phylink_pcs *pcs,
548 struct phylink_link_state *state);
549 int (*pcs_config)(struct phylink_pcs *pcs, unsigned int neg_mode,
550 phy_interface_t interface,
551 const unsigned long *advertising,
552 bool permit_pause_to_mac);
553 void (*pcs_an_restart)(struct phylink_pcs *pcs);
554 void (*pcs_link_up)(struct phylink_pcs *pcs, unsigned int neg_mode,
555 phy_interface_t interface, int speed, int duplex);
556};
557
558#if 0 /* For kernel-doc purposes only. */
559/**
560 * pcs_validate() - validate the link configuration.
561 * @pcs: a pointer to a &struct phylink_pcs.
562 * @supported: ethtool bitmask for supported link modes.
563 * @state: a const pointer to a &struct phylink_link_state.
564 *
565 * Validate the interface mode, and advertising's autoneg bit, removing any
566 * media ethtool link modes that would not be supportable from the supported
567 * mask. Phylink will propagate the changes to the advertising mask. See the
568 * &struct phylink_mac_ops validate() method.
569 *
570 * Returns -EINVAL if the interface mode/autoneg mode is not supported.
571 * Returns non-zero positive if the link state can be supported.
572 */
573int pcs_validate(struct phylink_pcs *pcs, unsigned long *supported,
574 const struct phylink_link_state *state);
575
576/**
577 * pcs_get_state() - Read the current inband link state from the hardware
578 * @pcs: a pointer to a &struct phylink_pcs.
579 * @state: a pointer to a &struct phylink_link_state.
580 *
581 * Read the current inband link state from the MAC PCS, reporting the
582 * current speed in @state->speed, duplex mode in @state->duplex, pause
583 * mode in @state->pause using the %MLO_PAUSE_RX and %MLO_PAUSE_TX bits,
584 * negotiation completion state in @state->an_complete, and link up state
585 * in @state->link. If possible, @state->lp_advertising should also be
586 * populated.
587 *
588 * When present, this overrides mac_pcs_get_state() in &struct
589 * phylink_mac_ops.
590 */
591void pcs_get_state(struct phylink_pcs *pcs,
592 struct phylink_link_state *state);
593
594/**
595 * pcs_config() - Configure the PCS mode and advertisement
596 * @pcs: a pointer to a &struct phylink_pcs.
597 * @neg_mode: link negotiation mode (see below)
598 * @interface: interface mode to be used
599 * @advertising: adertisement ethtool link mode mask
600 * @permit_pause_to_mac: permit forwarding pause resolution to MAC
601 *
602 * Configure the PCS for the operating mode, the interface mode, and set
603 * the advertisement mask. @permit_pause_to_mac indicates whether the
604 * hardware may forward the pause mode resolution to the MAC.
605 *
606 * When operating in %MLO_AN_INBAND, inband should always be enabled,
607 * otherwise inband should be disabled.
608 *
609 * For SGMII, there is no advertisement from the MAC side, the PCS should
610 * be programmed to acknowledge the inband word from the PHY.
611 *
612 * For 1000BASE-X, the advertisement should be programmed into the PCS.
613 *
614 * For most 10GBASE-R, there is no advertisement.
615 *
616 * The %neg_mode argument should be tested via the phylink_mode_*() family of
617 * functions, or for PCS that set pcs->neg_mode true, should be tested
618 * against the %PHYLINK_PCS_NEG_* definitions.
619 */
620int pcs_config(struct phylink_pcs *pcs, unsigned int neg_mode,
621 phy_interface_t interface, const unsigned long *advertising,
622 bool permit_pause_to_mac);
623
624/**
625 * pcs_an_restart() - restart 802.3z BaseX autonegotiation
626 * @pcs: a pointer to a &struct phylink_pcs.
627 *
628 * When PCS ops are present, this overrides mac_an_restart() in &struct
629 * phylink_mac_ops.
630 */
631void pcs_an_restart(struct phylink_pcs *pcs);
632
633/**
634 * pcs_link_up() - program the PCS for the resolved link configuration
635 * @pcs: a pointer to a &struct phylink_pcs.
636 * @neg_mode: link negotiation mode (see below)
637 * @interface: link &typedef phy_interface_t mode
638 * @speed: link speed
639 * @duplex: link duplex
640 *
641 * This call will be made just before mac_link_up() to inform the PCS of
642 * the resolved link parameters. For example, a PCS operating in SGMII
643 * mode without in-band AN needs to be manually configured for the link
644 * and duplex setting. Otherwise, this should be a no-op.
645 *
646 * The %mode argument should be tested via the phylink_mode_*() family of
647 * functions, or for PCS that set pcs->neg_mode true, should be tested
648 * against the %PHYLINK_PCS_NEG_* definitions.
649 */
650void pcs_link_up(struct phylink_pcs *pcs, unsigned int neg_mode,
651 phy_interface_t interface, int speed, int duplex);
652#endif
653
654void phylink_caps_to_linkmodes(unsigned long *linkmodes, unsigned long caps);
655unsigned long phylink_get_capabilities(phy_interface_t interface,
656 unsigned long mac_capabilities,
657 int rate_matching);
658void phylink_validate_mask_caps(unsigned long *supported,
659 struct phylink_link_state *state,
660 unsigned long caps);
661void phylink_generic_validate(struct phylink_config *config,
662 unsigned long *supported,
663 struct phylink_link_state *state);
664
665struct phylink *phylink_create(struct phylink_config *,
666 const struct fwnode_handle *,
667 phy_interface_t,
668 const struct phylink_mac_ops *);
669void phylink_destroy(struct phylink *);
670bool phylink_expects_phy(struct phylink *pl);
671
672int phylink_connect_phy(struct phylink *, struct phy_device *);
673int phylink_of_phy_connect(struct phylink *, struct device_node *, u32 flags);
674int phylink_fwnode_phy_connect(struct phylink *pl,
675 const struct fwnode_handle *fwnode,
676 u32 flags);
677void phylink_disconnect_phy(struct phylink *);
678
679void phylink_mac_change(struct phylink *, bool up);
680
681void phylink_start(struct phylink *);
682void phylink_stop(struct phylink *);
683
684void phylink_suspend(struct phylink *pl, bool mac_wol);
685void phylink_resume(struct phylink *pl);
686
687void phylink_ethtool_get_wol(struct phylink *, struct ethtool_wolinfo *);
688int phylink_ethtool_set_wol(struct phylink *, struct ethtool_wolinfo *);
689
690int phylink_ethtool_ksettings_get(struct phylink *,
691 struct ethtool_link_ksettings *);
692int phylink_ethtool_ksettings_set(struct phylink *,
693 const struct ethtool_link_ksettings *);
694int phylink_ethtool_nway_reset(struct phylink *);
695void phylink_ethtool_get_pauseparam(struct phylink *,
696 struct ethtool_pauseparam *);
697int phylink_ethtool_set_pauseparam(struct phylink *,
698 struct ethtool_pauseparam *);
699int phylink_get_eee_err(struct phylink *);
700int phylink_init_eee(struct phylink *, bool);
701int phylink_ethtool_get_eee(struct phylink *, struct ethtool_eee *);
702int phylink_ethtool_set_eee(struct phylink *, struct ethtool_eee *);
703int phylink_mii_ioctl(struct phylink *, struct ifreq *, int);
704int phylink_speed_down(struct phylink *pl, bool sync);
705int phylink_speed_up(struct phylink *pl);
706
707#define phylink_zero(bm) \
708 bitmap_zero(bm, __ETHTOOL_LINK_MODE_MASK_NBITS)
709#define __phylink_do_bit(op, bm, mode) \
710 op(ETHTOOL_LINK_MODE_ ## mode ## _BIT, bm)
711
712#define phylink_set(bm, mode) __phylink_do_bit(__set_bit, bm, mode)
713#define phylink_clear(bm, mode) __phylink_do_bit(__clear_bit, bm, mode)
714#define phylink_test(bm, mode) __phylink_do_bit(test_bit, bm, mode)
715
716void phylink_set_port_modes(unsigned long *bits);
717
718/**
719 * phylink_get_link_timer_ns - return the PCS link timer value
720 * @interface: link &typedef phy_interface_t mode
721 *
722 * Return the PCS link timer setting in nanoseconds for the PHY @interface
723 * mode, or -EINVAL if not appropriate.
724 */
725static inline int phylink_get_link_timer_ns(phy_interface_t interface)
726{
727 switch (interface) {
728 case PHY_INTERFACE_MODE_SGMII:
729 case PHY_INTERFACE_MODE_QSGMII:
730 case PHY_INTERFACE_MODE_USXGMII:
731 return 1600000;
732
733 case PHY_INTERFACE_MODE_1000BASEX:
734 case PHY_INTERFACE_MODE_2500BASEX:
735 return 10000000;
736
737 default:
738 return -EINVAL;
739 }
740}
741
742void phylink_mii_c22_pcs_decode_state(struct phylink_link_state *state,
743 u16 bmsr, u16 lpa);
744void phylink_mii_c22_pcs_get_state(struct mdio_device *pcs,
745 struct phylink_link_state *state);
746int phylink_mii_c22_pcs_encode_advertisement(phy_interface_t interface,
747 const unsigned long *advertising);
748int phylink_mii_c22_pcs_config(struct mdio_device *pcs,
749 phy_interface_t interface,
750 const unsigned long *advertising,
751 unsigned int neg_mode);
752void phylink_mii_c22_pcs_an_restart(struct mdio_device *pcs);
753
754void phylink_resolve_c73(struct phylink_link_state *state);
755
756void phylink_mii_c45_pcs_get_state(struct mdio_device *pcs,
757 struct phylink_link_state *state);
758
759void phylink_decode_usxgmii_word(struct phylink_link_state *state,
760 uint16_t lpa);
761#endif