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
8 struct device_node;
9 struct ethtool_cmd;
10 struct fwnode_handle;
11 struct net_device;
12 struct phylink;
13
14 enum {
15 MLO_PAUSE_NONE,
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),
20
21 MLO_AN_PHY = 0, /* Conventional PHY */
22 MLO_AN_FIXED, /* Fixed-link mode */
23 MLO_AN_INBAND, /* In-band protocol */
24
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
34 */
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,
42
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.
46 *
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).
51 *
52 * MAC_SYM_PAUSE MAC_ASYM_PAUSE MLO_PAUSE_AN tx_pause/rx_pause
53 * ============= ============== ============ ==================
54 * 0 0 0 0/0
55 * 0 0 1 0/0
56 * 0 1 0 0/0, 0/1, 1/0, 1/1
57 * 0 1 1 0/0, 1/0
58 * 1 0 0 0/0, 1/1
59 * 1 0 1 0/0, 1/1
60 * 1 1 0 0/0, 0/1, 1/0, 1/1
61 * 1 1 1 0/0, 0/1, 1/1
62 *
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
65 * combinations.
66 *
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
70 * at the same time.
71 */
72 MAC_SYM_PAUSE = BIT(0),
73 MAC_ASYM_PAUSE = BIT(1),
74 MAC_10HD = BIT(2),
75 MAC_10FD = BIT(3),
76 MAC_10 = MAC_10HD | MAC_10FD,
77 MAC_100HD = BIT(4),
78 MAC_100FD = BIT(5),
79 MAC_100 = MAC_100HD | MAC_100FD,
80 MAC_1000HD = BIT(6),
81 MAC_1000FD = BIT(7),
82 MAC_1000 = MAC_1000HD | MAC_1000FD,
83 MAC_2500FD = BIT(8),
84 MAC_5000FD = BIT(9),
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),
94 };
95
phylink_autoneg_inband(unsigned int mode)96 static inline bool phylink_autoneg_inband(unsigned int mode)
97 {
98 return mode == MLO_AN_INBAND;
99 }
100
101 /**
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
106 *
107 * Determines the negotiation mode to be used by the PCS, and returns
108 * one of:
109 *
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)
112 * will be used.
113 * - %PHYLINK_PCS_NEG_INBAND_DISABLED: inband mode selected but autoneg
114 * disabled
115 * - %PHYLINK_PCS_NEG_INBAND_ENABLED: inband mode selected and autoneg enabled
116 *
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.
119 */
phylink_pcs_neg_mode(unsigned int mode,phy_interface_t interface,const unsigned long * advertising)120 static inline unsigned int phylink_pcs_neg_mode(unsigned int mode,
121 phy_interface_t interface,
122 const unsigned long *advertising)
123 {
124 unsigned int neg_mode;
125
126 switch (interface) {
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.
135 */
136 if (!phylink_autoneg_inband(mode))
137 neg_mode = PHYLINK_PCS_NEG_OUTBAND;
138 else
139 neg_mode = PHYLINK_PCS_NEG_INBAND_ENABLED;
140 break;
141
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.
149 */
150 if (!phylink_autoneg_inband(mode))
151 neg_mode = PHYLINK_PCS_NEG_OUTBAND;
152 else if (linkmode_test_bit(ETHTOOL_LINK_MODE_Autoneg_BIT,
153 advertising))
154 neg_mode = PHYLINK_PCS_NEG_INBAND_ENABLED;
155 else
156 neg_mode = PHYLINK_PCS_NEG_INBAND_DISABLED;
157 break;
158
159 default:
160 neg_mode = PHYLINK_PCS_NEG_NONE;
161 break;
162 }
163
164 return neg_mode;
165 }
166
167 /**
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
171 * modes
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.
182 */
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;
187 int speed;
188 int duplex;
189 int pause;
190 int rate_matching;
191 unsigned int link:1;
192 unsigned int an_complete:1;
193 };
194
195 enum phylink_op_type {
196 PHYLINK_NETDEV = 0,
197 PHYLINK_DEV,
198 };
199
200 /**
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 * @poll_fixed_state: if true, starts link_poll,
205 * if MAC link is at %MLO_AN_FIXED mode.
206 * @mac_managed_pm: if true, indicate the MAC driver is responsible for PHY PM.
207 * @ovr_an_inband: if true, override PCS to MLO_AN_INBAND
208 * @get_fixed_state: callback to execute to determine the fixed link state,
209 * if MAC link is at %MLO_AN_FIXED mode.
210 * @supported_interfaces: bitmap describing which PHY_INTERFACE_MODE_xxx
211 * are supported by the MAC/PCS.
212 * @mac_capabilities: MAC pause/speed/duplex capabilities.
213 */
214 struct phylink_config {
215 struct device *dev;
216 enum phylink_op_type type;
217 bool poll_fixed_state;
218 bool mac_managed_pm;
219 bool ovr_an_inband;
220 void (*get_fixed_state)(struct phylink_config *config,
221 struct phylink_link_state *state);
222 DECLARE_PHY_INTERFACE_MASK(supported_interfaces);
223 unsigned long mac_capabilities;
224 };
225
226 void phylink_limit_mac_speed(struct phylink_config *config, u32 max_speed);
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_prepare: prepare for a major reconfiguration of the interface.
233 * @mac_config: configure the MAC for the selected mode and state.
234 * @mac_finish: finish a major reconfiguration of the interface.
235 * @mac_link_down: take the link down.
236 * @mac_link_up: allow the link to come up.
237 *
238 * The individual methods are described more fully below.
239 */
240 struct phylink_mac_ops {
241 void (*validate)(struct phylink_config *config,
242 unsigned long *supported,
243 struct phylink_link_state *state);
244 struct phylink_pcs *(*mac_select_pcs)(struct phylink_config *config,
245 phy_interface_t interface);
246 int (*mac_prepare)(struct phylink_config *config, unsigned int mode,
247 phy_interface_t iface);
248 void (*mac_config)(struct phylink_config *config, unsigned int mode,
249 const struct phylink_link_state *state);
250 int (*mac_finish)(struct phylink_config *config, unsigned int mode,
251 phy_interface_t iface);
252 void (*mac_link_down)(struct phylink_config *config, unsigned int mode,
253 phy_interface_t interface);
254 void (*mac_link_up)(struct phylink_config *config,
255 struct phy_device *phy, unsigned int mode,
256 phy_interface_t interface, int speed, int duplex,
257 bool tx_pause, bool rx_pause);
258 };
259
260 #if 0 /* For kernel-doc purposes only. */
261 /**
262 * validate - Validate and update the link configuration
263 * @config: a pointer to a &struct phylink_config.
264 * @supported: ethtool bitmask for supported link modes.
265 * @state: a pointer to a &struct phylink_link_state.
266 *
267 * Clear bits in the @supported and @state->advertising masks that
268 * are not supportable by the MAC.
269 *
270 * Note that the PHY may be able to transform from one connection
271 * technology to another, so, eg, don't clear 1000BaseX just
272 * because the MAC is unable to BaseX mode. This is more about
273 * clearing unsupported speeds and duplex settings. The port modes
274 * should not be cleared; phylink_set_port_modes() will help with this.
275 *
276 * When @config->supported_interfaces has been set, phylink will iterate
277 * over the supported interfaces to determine the full capability of the
278 * MAC. The validation function must not print errors if @state->interface
279 * is set to an unexpected value.
280 *
281 * When @config->supported_interfaces is empty, phylink will call this
282 * function with @state->interface set to %PHY_INTERFACE_MODE_NA, and
283 * expects the MAC driver to return all supported link modes.
284 *
285 * If the @state->interface mode is not supported, then the @supported
286 * mask must be cleared.
287 *
288 * This member is optional; if not set, the generic validator will be
289 * used making use of @config->mac_capabilities and
290 * @config->supported_interfaces to determine which link modes are
291 * supported.
292 */
293 void validate(struct phylink_config *config, unsigned long *supported,
294 struct phylink_link_state *state);
295 /**
296 * mac_select_pcs: Select a PCS for the interface mode.
297 * @config: a pointer to a &struct phylink_config.
298 * @interface: PHY interface mode for PCS
299 *
300 * Return the &struct phylink_pcs for the specified interface mode, or
301 * NULL if none is required, or an error pointer on error.
302 *
303 * This must not modify any state. It is used to query which PCS should
304 * be used. Phylink will use this during validation to ensure that the
305 * configuration is valid, and when setting a configuration to internally
306 * set the PCS that will be used.
307 */
308 struct phylink_pcs *mac_select_pcs(struct phylink_config *config,
309 phy_interface_t interface);
310
311 /**
312 * mac_prepare() - prepare to change the PHY interface mode
313 * @config: a pointer to a &struct phylink_config.
314 * @mode: one of %MLO_AN_FIXED, %MLO_AN_PHY, %MLO_AN_INBAND.
315 * @iface: interface mode to switch to
316 *
317 * phylink will call this method at the beginning of a full initialisation
318 * of the link, which includes changing the interface mode or at initial
319 * startup time. It may be called for the current mode. The MAC driver
320 * should perform whatever actions are required, e.g. disabling the
321 * Serdes PHY.
322 *
323 * This will be the first call in the sequence:
324 * - mac_prepare()
325 * - mac_config()
326 * - pcs_config()
327 * - possible pcs_an_restart()
328 * - mac_finish()
329 *
330 * Returns zero on success, or negative errno on failure which will be
331 * reported to the kernel log.
332 */
333 int mac_prepare(struct phylink_config *config, unsigned int mode,
334 phy_interface_t iface);
335
336 /**
337 * mac_config() - configure the MAC for the selected mode and state
338 * @config: a pointer to a &struct phylink_config.
339 * @mode: one of %MLO_AN_FIXED, %MLO_AN_PHY, %MLO_AN_INBAND.
340 * @state: a pointer to a &struct phylink_link_state.
341 *
342 * Note - not all members of @state are valid. In particular,
343 * @state->lp_advertising, @state->link, @state->an_complete are never
344 * guaranteed to be correct, and so any mac_config() implementation must
345 * never reference these fields.
346 *
347 * This will only be called to reconfigure the MAC for a "major" change in
348 * e.g. interface mode. It will not be called for changes in speed, duplex
349 * or pause modes or to change the in-band advertisement.
350 *
351 * In all negotiation modes, as defined by @mode, @state->pause indicates the
352 * pause settings which should be applied as follows. If %MLO_PAUSE_AN is not
353 * set, %MLO_PAUSE_TX and %MLO_PAUSE_RX indicate whether the MAC should send
354 * pause frames and/or act on received pause frames respectively. Otherwise,
355 * the results of in-band negotiation/status from the MAC PCS should be used
356 * to control the MAC pause mode settings.
357 *
358 * The action performed depends on the currently selected mode:
359 *
360 * %MLO_AN_FIXED, %MLO_AN_PHY:
361 * Configure for non-inband negotiation mode, where the link settings
362 * are completely communicated via mac_link_up(). The physical link
363 * protocol from the MAC is specified by @state->interface.
364 *
365 * @state->advertising may be used, but is not required.
366 *
367 * Older drivers (prior to the mac_link_up() change) may use @state->speed,
368 * @state->duplex and @state->pause to configure the MAC, but this is
369 * deprecated; such drivers should be converted to use mac_link_up().
370 *
371 * Other members of @state must be ignored.
372 *
373 * Valid state members: interface, advertising.
374 * Deprecated state members: speed, duplex, pause.
375 *
376 * %MLO_AN_INBAND:
377 * place the link in an inband negotiation mode (such as 802.3z
378 * 1000base-X or Cisco SGMII mode depending on the @state->interface
379 * mode). In both cases, link state management (whether the link
380 * is up or not) is performed by the MAC, and reported via the
381 * pcs_get_state() callback. Changes in link state must be made
382 * by calling phylink_mac_change().
383 *
384 * Interface mode specific details are mentioned below.
385 *
386 * If in 802.3z mode, the link speed is fixed, dependent on the
387 * @state->interface. Duplex and pause modes are negotiated via
388 * the in-band configuration word. Advertised pause modes are set
389 * according to the @state->an_enabled and @state->advertising
390 * flags. Beware of MACs which only support full duplex at gigabit
391 * and higher speeds.
392 *
393 * If in Cisco SGMII mode, the link speed and duplex mode are passed
394 * in the serial bitstream 16-bit configuration word, and the MAC
395 * should be configured to read these bits and acknowledge the
396 * configuration word. Nothing is advertised by the MAC. The MAC is
397 * responsible for reading the configuration word and configuring
398 * itself accordingly.
399 *
400 * Valid state members: interface, an_enabled, pause, advertising.
401 *
402 * Implementations are expected to update the MAC to reflect the
403 * requested settings - i.o.w., if nothing has changed between two
404 * calls, no action is expected. If only flow control settings have
405 * changed, flow control should be updated *without* taking the link
406 * down. This "update" behaviour is critical to avoid bouncing the
407 * link up status.
408 */
409 void mac_config(struct phylink_config *config, unsigned int mode,
410 const struct phylink_link_state *state);
411
412 /**
413 * mac_finish() - finish a to change the PHY interface mode
414 * @config: a pointer to a &struct phylink_config.
415 * @mode: one of %MLO_AN_FIXED, %MLO_AN_PHY, %MLO_AN_INBAND.
416 * @iface: interface mode to switch to
417 *
418 * phylink will call this if it called mac_prepare() to allow the MAC to
419 * complete any necessary steps after the MAC and PCS have been configured
420 * for the @mode and @iface. E.g. a MAC driver may wish to re-enable the
421 * Serdes PHY here if it was previously disabled by mac_prepare().
422 *
423 * Returns zero on success, or negative errno on failure which will be
424 * reported to the kernel log.
425 */
426 int mac_finish(struct phylink_config *config, unsigned int mode,
427 phy_interface_t iface);
428
429 /**
430 * mac_link_down() - take the link down
431 * @config: a pointer to a &struct phylink_config.
432 * @mode: link autonegotiation mode
433 * @interface: link &typedef phy_interface_t mode
434 *
435 * If @mode is not an in-band negotiation mode (as defined by
436 * phylink_autoneg_inband()), force the link down and disable any
437 * Energy Efficient Ethernet MAC configuration. Interface type
438 * selection must be done in mac_config().
439 */
440 void mac_link_down(struct phylink_config *config, unsigned int mode,
441 phy_interface_t interface);
442
443 /**
444 * mac_link_up() - allow the link to come up
445 * @config: a pointer to a &struct phylink_config.
446 * @phy: any attached phy
447 * @mode: link autonegotiation mode
448 * @interface: link &typedef phy_interface_t mode
449 * @speed: link speed
450 * @duplex: link duplex
451 * @tx_pause: link transmit pause enablement status
452 * @rx_pause: link receive pause enablement status
453 *
454 * Configure the MAC for an established link.
455 *
456 * @speed, @duplex, @tx_pause and @rx_pause indicate the finalised link
457 * settings, and should be used to configure the MAC block appropriately
458 * where these settings are not automatically conveyed from the PCS block,
459 * or if in-band negotiation (as defined by phylink_autoneg_inband(@mode))
460 * is disabled.
461 *
462 * Note that when 802.3z in-band negotiation is in use, it is possible
463 * that the user wishes to override the pause settings, and this should
464 * be allowed when considering the implementation of this method.
465 *
466 * If in-band negotiation mode is disabled, allow the link to come up. If
467 * @phy is non-%NULL, configure Energy Efficient Ethernet by calling
468 * phy_init_eee() and perform appropriate MAC configuration for EEE.
469 * Interface type selection must be done in mac_config().
470 */
471 void mac_link_up(struct phylink_config *config, struct phy_device *phy,
472 unsigned int mode, phy_interface_t interface,
473 int speed, int duplex, bool tx_pause, bool rx_pause);
474 #endif
475
476 struct phylink_pcs_ops;
477
478 /**
479 * struct phylink_pcs - PHYLINK PCS instance
480 * @ops: a pointer to the &struct phylink_pcs_ops structure
481 * @phylink: pointer to &struct phylink_config
482 * @neg_mode: provide PCS neg mode via "mode" argument
483 * @poll: poll the PCS for link changes
484 *
485 * This structure is designed to be embedded within the PCS private data,
486 * and will be passed between phylink and the PCS.
487 *
488 * The @phylink member is private to phylink and must not be touched by
489 * the PCS driver.
490 */
491 struct phylink_pcs {
492 const struct phylink_pcs_ops *ops;
493 struct phylink *phylink;
494 bool neg_mode;
495 bool poll;
496 };
497
498 /**
499 * struct phylink_pcs_ops - MAC PCS operations structure.
500 * @pcs_validate: validate the link configuration.
501 * @pcs_enable: enable the PCS.
502 * @pcs_disable: disable the PCS.
503 * @pcs_pre_config: pre-mac_config method (for errata)
504 * @pcs_post_config: post-mac_config method (for arrata)
505 * @pcs_get_state: read the current MAC PCS link state from the hardware.
506 * @pcs_config: configure the MAC PCS for the selected mode and state.
507 * @pcs_an_restart: restart 802.3z BaseX autonegotiation.
508 * @pcs_link_up: program the PCS for the resolved link configuration
509 * (where necessary).
510 */
511 struct phylink_pcs_ops {
512 int (*pcs_validate)(struct phylink_pcs *pcs, unsigned long *supported,
513 const struct phylink_link_state *state);
514 int (*pcs_enable)(struct phylink_pcs *pcs);
515 void (*pcs_disable)(struct phylink_pcs *pcs);
516 void (*pcs_pre_config)(struct phylink_pcs *pcs,
517 phy_interface_t interface);
518 int (*pcs_post_config)(struct phylink_pcs *pcs,
519 phy_interface_t interface);
520 void (*pcs_get_state)(struct phylink_pcs *pcs,
521 struct phylink_link_state *state);
522 int (*pcs_config)(struct phylink_pcs *pcs, unsigned int neg_mode,
523 phy_interface_t interface,
524 const unsigned long *advertising,
525 bool permit_pause_to_mac);
526 void (*pcs_an_restart)(struct phylink_pcs *pcs);
527 void (*pcs_link_up)(struct phylink_pcs *pcs, unsigned int neg_mode,
528 phy_interface_t interface, int speed, int duplex);
529 };
530
531 #if 0 /* For kernel-doc purposes only. */
532 /**
533 * pcs_validate() - validate the link configuration.
534 * @pcs: a pointer to a &struct phylink_pcs.
535 * @supported: ethtool bitmask for supported link modes.
536 * @state: a const pointer to a &struct phylink_link_state.
537 *
538 * Validate the interface mode, and advertising's autoneg bit, removing any
539 * media ethtool link modes that would not be supportable from the supported
540 * mask. Phylink will propagate the changes to the advertising mask. See the
541 * &struct phylink_mac_ops validate() method.
542 *
543 * Returns -EINVAL if the interface mode/autoneg mode is not supported.
544 * Returns non-zero positive if the link state can be supported.
545 */
546 int pcs_validate(struct phylink_pcs *pcs, unsigned long *supported,
547 const struct phylink_link_state *state);
548
549 /**
550 * pcs_enable() - enable the PCS.
551 * @pcs: a pointer to a &struct phylink_pcs.
552 */
553 int pcs_enable(struct phylink_pcs *pcs);
554
555 /**
556 * pcs_disable() - disable the PCS.
557 * @pcs: a pointer to a &struct phylink_pcs.
558 */
559 void pcs_disable(struct phylink_pcs *pcs);
560
561 /**
562 * pcs_get_state() - Read the current inband link state from the hardware
563 * @pcs: a pointer to a &struct phylink_pcs.
564 * @state: a pointer to a &struct phylink_link_state.
565 *
566 * Read the current inband link state from the MAC PCS, reporting the
567 * current speed in @state->speed, duplex mode in @state->duplex, pause
568 * mode in @state->pause using the %MLO_PAUSE_RX and %MLO_PAUSE_TX bits,
569 * negotiation completion state in @state->an_complete, and link up state
570 * in @state->link. If possible, @state->lp_advertising should also be
571 * populated.
572 *
573 * When present, this overrides pcs_get_state() in &struct
574 * phylink_pcs_ops.
575 */
576 void pcs_get_state(struct phylink_pcs *pcs,
577 struct phylink_link_state *state);
578
579 /**
580 * pcs_config() - Configure the PCS mode and advertisement
581 * @pcs: a pointer to a &struct phylink_pcs.
582 * @neg_mode: link negotiation mode (see below)
583 * @interface: interface mode to be used
584 * @advertising: adertisement ethtool link mode mask
585 * @permit_pause_to_mac: permit forwarding pause resolution to MAC
586 *
587 * Configure the PCS for the operating mode, the interface mode, and set
588 * the advertisement mask. @permit_pause_to_mac indicates whether the
589 * hardware may forward the pause mode resolution to the MAC.
590 *
591 * When operating in %MLO_AN_INBAND, inband should always be enabled,
592 * otherwise inband should be disabled.
593 *
594 * For SGMII, there is no advertisement from the MAC side, the PCS should
595 * be programmed to acknowledge the inband word from the PHY.
596 *
597 * For 1000BASE-X, the advertisement should be programmed into the PCS.
598 *
599 * For most 10GBASE-R, there is no advertisement.
600 *
601 * The %neg_mode argument should be tested via the phylink_mode_*() family of
602 * functions, or for PCS that set pcs->neg_mode true, should be tested
603 * against the PHYLINK_PCS_NEG_* definitions.
604 */
605 int pcs_config(struct phylink_pcs *pcs, unsigned int neg_mode,
606 phy_interface_t interface, const unsigned long *advertising,
607 bool permit_pause_to_mac);
608
609 /**
610 * pcs_an_restart() - restart 802.3z BaseX autonegotiation
611 * @pcs: a pointer to a &struct phylink_pcs.
612 *
613 * When PCS ops are present, this overrides mac_an_restart() in &struct
614 * phylink_mac_ops.
615 */
616 void pcs_an_restart(struct phylink_pcs *pcs);
617
618 /**
619 * pcs_link_up() - program the PCS for the resolved link configuration
620 * @pcs: a pointer to a &struct phylink_pcs.
621 * @neg_mode: link negotiation mode (see below)
622 * @interface: link &typedef phy_interface_t mode
623 * @speed: link speed
624 * @duplex: link duplex
625 *
626 * This call will be made just before mac_link_up() to inform the PCS of
627 * the resolved link parameters. For example, a PCS operating in SGMII
628 * mode without in-band AN needs to be manually configured for the link
629 * and duplex setting. Otherwise, this should be a no-op.
630 *
631 * The %mode argument should be tested via the phylink_mode_*() family of
632 * functions, or for PCS that set pcs->neg_mode true, should be tested
633 * against the PHYLINK_PCS_NEG_* definitions.
634 */
635 void pcs_link_up(struct phylink_pcs *pcs, unsigned int neg_mode,
636 phy_interface_t interface, int speed, int duplex);
637 #endif
638
639 void phylink_caps_to_linkmodes(unsigned long *linkmodes, unsigned long caps);
640 unsigned long phylink_get_capabilities(phy_interface_t interface,
641 unsigned long mac_capabilities,
642 int rate_matching);
643 void phylink_validate_mask_caps(unsigned long *supported,
644 struct phylink_link_state *state,
645 unsigned long caps);
646 void phylink_generic_validate(struct phylink_config *config,
647 unsigned long *supported,
648 struct phylink_link_state *state);
649
650 struct phylink *phylink_create(struct phylink_config *,
651 const struct fwnode_handle *,
652 phy_interface_t,
653 const struct phylink_mac_ops *);
654 void phylink_destroy(struct phylink *);
655 bool phylink_expects_phy(struct phylink *pl);
656
657 int phylink_connect_phy(struct phylink *, struct phy_device *);
658 int phylink_of_phy_connect(struct phylink *, struct device_node *, u32 flags);
659 int phylink_fwnode_phy_connect(struct phylink *pl,
660 const struct fwnode_handle *fwnode,
661 u32 flags);
662 void phylink_disconnect_phy(struct phylink *);
663
664 void phylink_mac_change(struct phylink *, bool up);
665 void phylink_pcs_change(struct phylink_pcs *, bool up);
666
667 void phylink_start(struct phylink *);
668 void phylink_stop(struct phylink *);
669
670 void phylink_suspend(struct phylink *pl, bool mac_wol);
671 void phylink_resume(struct phylink *pl);
672
673 void phylink_ethtool_get_wol(struct phylink *, struct ethtool_wolinfo *);
674 int phylink_ethtool_set_wol(struct phylink *, struct ethtool_wolinfo *);
675
676 int phylink_ethtool_ksettings_get(struct phylink *,
677 struct ethtool_link_ksettings *);
678 int phylink_ethtool_ksettings_set(struct phylink *,
679 const struct ethtool_link_ksettings *);
680 int phylink_ethtool_nway_reset(struct phylink *);
681 void phylink_ethtool_get_pauseparam(struct phylink *,
682 struct ethtool_pauseparam *);
683 int phylink_ethtool_set_pauseparam(struct phylink *,
684 struct ethtool_pauseparam *);
685 int phylink_get_eee_err(struct phylink *);
686 int phylink_init_eee(struct phylink *, bool);
687 int phylink_ethtool_get_eee(struct phylink *, struct ethtool_eee *);
688 int phylink_ethtool_set_eee(struct phylink *, struct ethtool_eee *);
689 int phylink_mii_ioctl(struct phylink *, struct ifreq *, int);
690 int phylink_speed_down(struct phylink *pl, bool sync);
691 int phylink_speed_up(struct phylink *pl);
692
693 #define phylink_zero(bm) \
694 bitmap_zero(bm, __ETHTOOL_LINK_MODE_MASK_NBITS)
695 #define __phylink_do_bit(op, bm, mode) \
696 op(ETHTOOL_LINK_MODE_ ## mode ## _BIT, bm)
697
698 #define phylink_set(bm, mode) __phylink_do_bit(__set_bit, bm, mode)
699 #define phylink_clear(bm, mode) __phylink_do_bit(__clear_bit, bm, mode)
700 #define phylink_test(bm, mode) __phylink_do_bit(test_bit, bm, mode)
701
702 void phylink_set_port_modes(unsigned long *bits);
703
704 /**
705 * phylink_get_link_timer_ns - return the PCS link timer value
706 * @interface: link &typedef phy_interface_t mode
707 *
708 * Return the PCS link timer setting in nanoseconds for the PHY @interface
709 * mode, or -EINVAL if not appropriate.
710 */
phylink_get_link_timer_ns(phy_interface_t interface)711 static inline int phylink_get_link_timer_ns(phy_interface_t interface)
712 {
713 switch (interface) {
714 case PHY_INTERFACE_MODE_SGMII:
715 case PHY_INTERFACE_MODE_QSGMII:
716 case PHY_INTERFACE_MODE_USXGMII:
717 return 1600000;
718
719 case PHY_INTERFACE_MODE_1000BASEX:
720 case PHY_INTERFACE_MODE_2500BASEX:
721 return 10000000;
722
723 default:
724 return -EINVAL;
725 }
726 }
727
728 void phylink_mii_c22_pcs_decode_state(struct phylink_link_state *state,
729 u16 bmsr, u16 lpa);
730 void phylink_mii_c22_pcs_get_state(struct mdio_device *pcs,
731 struct phylink_link_state *state);
732 int phylink_mii_c22_pcs_encode_advertisement(phy_interface_t interface,
733 const unsigned long *advertising);
734 int phylink_mii_c22_pcs_config(struct mdio_device *pcs,
735 phy_interface_t interface,
736 const unsigned long *advertising,
737 unsigned int neg_mode);
738 void phylink_mii_c22_pcs_an_restart(struct mdio_device *pcs);
739
740 void phylink_resolve_c73(struct phylink_link_state *state);
741
742 void phylink_mii_c45_pcs_get_state(struct mdio_device *pcs,
743 struct phylink_link_state *state);
744
745 void phylink_decode_usxgmii_word(struct phylink_link_state *state,
746 uint16_t lpa);
747 #endif
748