arm64: dts: qcom: sm8550: add TRNG node
[linux-modified.git] / include / linux / phylink.h
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
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  */
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  * @mac_get_caps: Get MAC capabilities for interface mode.
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         unsigned long (*mac_get_caps)(struct phylink_config *config,
242                                       phy_interface_t interface);
243         struct phylink_pcs *(*mac_select_pcs)(struct phylink_config *config,
244                                               phy_interface_t interface);
245         int (*mac_prepare)(struct phylink_config *config, unsigned int mode,
246                            phy_interface_t iface);
247         void (*mac_config)(struct phylink_config *config, unsigned int mode,
248                            const struct phylink_link_state *state);
249         int (*mac_finish)(struct phylink_config *config, unsigned int mode,
250                           phy_interface_t iface);
251         void (*mac_link_down)(struct phylink_config *config, unsigned int mode,
252                               phy_interface_t interface);
253         void (*mac_link_up)(struct phylink_config *config,
254                             struct phy_device *phy, unsigned int mode,
255                             phy_interface_t interface, int speed, int duplex,
256                             bool tx_pause, bool rx_pause);
257 };
258
259 #if 0 /* For kernel-doc purposes only. */
260 /**
261  * mac_get_caps: Get MAC capabilities for interface mode.
262  * @config: a pointer to a &struct phylink_config.
263  * @interface: PHY interface mode.
264  *
265  * Optional method. When not provided, config->mac_capabilities will be used.
266  * When implemented, this returns the MAC capabilities for the specified
267  * interface mode where there is some special handling required by the MAC
268  * driver (e.g. not supporting half-duplex in certain interface modes.)
269  */
270 unsigned long mac_get_caps(struct phylink_config *config,
271                            phy_interface_t interface);
272 /**
273  * mac_select_pcs: Select a PCS for the interface mode.
274  * @config: a pointer to a &struct phylink_config.
275  * @interface: PHY interface mode for PCS
276  *
277  * Return the &struct phylink_pcs for the specified interface mode, or
278  * NULL if none is required, or an error pointer on error.
279  *
280  * This must not modify any state. It is used to query which PCS should
281  * be used. Phylink will use this during validation to ensure that the
282  * configuration is valid, and when setting a configuration to internally
283  * set the PCS that will be used.
284  */
285 struct phylink_pcs *mac_select_pcs(struct phylink_config *config,
286                                    phy_interface_t interface);
287
288 /**
289  * mac_prepare() - prepare to change the PHY interface mode
290  * @config: a pointer to a &struct phylink_config.
291  * @mode: one of %MLO_AN_FIXED, %MLO_AN_PHY, %MLO_AN_INBAND.
292  * @iface: interface mode to switch to
293  *
294  * phylink will call this method at the beginning of a full initialisation
295  * of the link, which includes changing the interface mode or at initial
296  * startup time. It may be called for the current mode. The MAC driver
297  * should perform whatever actions are required, e.g. disabling the
298  * Serdes PHY.
299  *
300  * This will be the first call in the sequence:
301  * - mac_prepare()
302  * - mac_config()
303  * - pcs_config()
304  * - possible pcs_an_restart()
305  * - mac_finish()
306  *
307  * Returns zero on success, or negative errno on failure which will be
308  * reported to the kernel log.
309  */
310 int mac_prepare(struct phylink_config *config, unsigned int mode,
311                 phy_interface_t iface);
312
313 /**
314  * mac_config() - configure the MAC for the selected mode and state
315  * @config: a pointer to a &struct phylink_config.
316  * @mode: one of %MLO_AN_FIXED, %MLO_AN_PHY, %MLO_AN_INBAND.
317  * @state: a pointer to a &struct phylink_link_state.
318  *
319  * Note - not all members of @state are valid.  In particular,
320  * @state->lp_advertising, @state->link, @state->an_complete are never
321  * guaranteed to be correct, and so any mac_config() implementation must
322  * never reference these fields.
323  *
324  * This will only be called to reconfigure the MAC for a "major" change in
325  * e.g. interface mode. It will not be called for changes in speed, duplex
326  * or pause modes or to change the in-band advertisement.
327  *
328  * In all negotiation modes, as defined by @mode, @state->pause indicates the
329  * pause settings which should be applied as follows. If %MLO_PAUSE_AN is not
330  * set, %MLO_PAUSE_TX and %MLO_PAUSE_RX indicate whether the MAC should send
331  * pause frames and/or act on received pause frames respectively. Otherwise,
332  * the results of in-band negotiation/status from the MAC PCS should be used
333  * to control the MAC pause mode settings.
334  *
335  * The action performed depends on the currently selected mode:
336  *
337  * %MLO_AN_FIXED, %MLO_AN_PHY:
338  *   Configure for non-inband negotiation mode, where the link settings
339  *   are completely communicated via mac_link_up().  The physical link
340  *   protocol from the MAC is specified by @state->interface.
341  *
342  *   @state->advertising may be used, but is not required.
343  *
344  *   Older drivers (prior to the mac_link_up() change) may use @state->speed,
345  *   @state->duplex and @state->pause to configure the MAC, but this is
346  *   deprecated; such drivers should be converted to use mac_link_up().
347  *
348  *   Other members of @state must be ignored.
349  *
350  *   Valid state members: interface, advertising.
351  *   Deprecated state members: speed, duplex, pause.
352  *
353  * %MLO_AN_INBAND:
354  *   place the link in an inband negotiation mode (such as 802.3z
355  *   1000base-X or Cisco SGMII mode depending on the @state->interface
356  *   mode). In both cases, link state management (whether the link
357  *   is up or not) is performed by the MAC, and reported via the
358  *   pcs_get_state() callback. Changes in link state must be made
359  *   by calling phylink_mac_change().
360  *
361  *   Interface mode specific details are mentioned below.
362  *
363  *   If in 802.3z mode, the link speed is fixed, dependent on the
364  *   @state->interface. Duplex and pause modes are negotiated via
365  *   the in-band configuration word. Advertised pause modes are set
366  *   according to the @state->an_enabled and @state->advertising
367  *   flags. Beware of MACs which only support full duplex at gigabit
368  *   and higher speeds.
369  *
370  *   If in Cisco SGMII mode, the link speed and duplex mode are passed
371  *   in the serial bitstream 16-bit configuration word, and the MAC
372  *   should be configured to read these bits and acknowledge the
373  *   configuration word. Nothing is advertised by the MAC. The MAC is
374  *   responsible for reading the configuration word and configuring
375  *   itself accordingly.
376  *
377  *   Valid state members: interface, an_enabled, pause, advertising.
378  *
379  * Implementations are expected to update the MAC to reflect the
380  * requested settings - i.o.w., if nothing has changed between two
381  * calls, no action is expected.  If only flow control settings have
382  * changed, flow control should be updated *without* taking the link
383  * down.  This "update" behaviour is critical to avoid bouncing the
384  * link up status.
385  */
386 void mac_config(struct phylink_config *config, unsigned int mode,
387                 const struct phylink_link_state *state);
388
389 /**
390  * mac_finish() - finish a to change the PHY interface mode
391  * @config: a pointer to a &struct phylink_config.
392  * @mode: one of %MLO_AN_FIXED, %MLO_AN_PHY, %MLO_AN_INBAND.
393  * @iface: interface mode to switch to
394  *
395  * phylink will call this if it called mac_prepare() to allow the MAC to
396  * complete any necessary steps after the MAC and PCS have been configured
397  * for the @mode and @iface. E.g. a MAC driver may wish to re-enable the
398  * Serdes PHY here if it was previously disabled by mac_prepare().
399  *
400  * Returns zero on success, or negative errno on failure which will be
401  * reported to the kernel log.
402  */
403 int mac_finish(struct phylink_config *config, unsigned int mode,
404                 phy_interface_t iface);
405
406 /**
407  * mac_link_down() - take the link down
408  * @config: a pointer to a &struct phylink_config.
409  * @mode: link autonegotiation mode
410  * @interface: link &typedef phy_interface_t mode
411  *
412  * If @mode is not an in-band negotiation mode (as defined by
413  * phylink_autoneg_inband()), force the link down and disable any
414  * Energy Efficient Ethernet MAC configuration. Interface type
415  * selection must be done in mac_config().
416  */
417 void mac_link_down(struct phylink_config *config, unsigned int mode,
418                    phy_interface_t interface);
419
420 /**
421  * mac_link_up() - allow the link to come up
422  * @config: a pointer to a &struct phylink_config.
423  * @phy: any attached phy
424  * @mode: link autonegotiation mode
425  * @interface: link &typedef phy_interface_t mode
426  * @speed: link speed
427  * @duplex: link duplex
428  * @tx_pause: link transmit pause enablement status
429  * @rx_pause: link receive pause enablement status
430  *
431  * Configure the MAC for an established link.
432  *
433  * @speed, @duplex, @tx_pause and @rx_pause indicate the finalised link
434  * settings, and should be used to configure the MAC block appropriately
435  * where these settings are not automatically conveyed from the PCS block,
436  * or if in-band negotiation (as defined by phylink_autoneg_inband(@mode))
437  * is disabled.
438  *
439  * Note that when 802.3z in-band negotiation is in use, it is possible
440  * that the user wishes to override the pause settings, and this should
441  * be allowed when considering the implementation of this method.
442  *
443  * If in-band negotiation mode is disabled, allow the link to come up. If
444  * @phy is non-%NULL, configure Energy Efficient Ethernet by calling
445  * phy_init_eee() and perform appropriate MAC configuration for EEE.
446  * Interface type selection must be done in mac_config().
447  */
448 void mac_link_up(struct phylink_config *config, struct phy_device *phy,
449                  unsigned int mode, phy_interface_t interface,
450                  int speed, int duplex, bool tx_pause, bool rx_pause);
451 #endif
452
453 struct phylink_pcs_ops;
454
455 /**
456  * struct phylink_pcs - PHYLINK PCS instance
457  * @ops: a pointer to the &struct phylink_pcs_ops structure
458  * @phylink: pointer to &struct phylink_config
459  * @neg_mode: provide PCS neg mode via "mode" argument
460  * @poll: poll the PCS for link changes
461  *
462  * This structure is designed to be embedded within the PCS private data,
463  * and will be passed between phylink and the PCS.
464  *
465  * The @phylink member is private to phylink and must not be touched by
466  * the PCS driver.
467  */
468 struct phylink_pcs {
469         const struct phylink_pcs_ops *ops;
470         struct phylink *phylink;
471         bool neg_mode;
472         bool poll;
473 };
474
475 /**
476  * struct phylink_pcs_ops - MAC PCS operations structure.
477  * @pcs_validate: validate the link configuration.
478  * @pcs_enable: enable the PCS.
479  * @pcs_disable: disable the PCS.
480  * @pcs_pre_config: pre-mac_config method (for errata)
481  * @pcs_post_config: post-mac_config method (for arrata)
482  * @pcs_get_state: read the current MAC PCS link state from the hardware.
483  * @pcs_config: configure the MAC PCS for the selected mode and state.
484  * @pcs_an_restart: restart 802.3z BaseX autonegotiation.
485  * @pcs_link_up: program the PCS for the resolved link configuration
486  *               (where necessary).
487  */
488 struct phylink_pcs_ops {
489         int (*pcs_validate)(struct phylink_pcs *pcs, unsigned long *supported,
490                             const struct phylink_link_state *state);
491         int (*pcs_enable)(struct phylink_pcs *pcs);
492         void (*pcs_disable)(struct phylink_pcs *pcs);
493         void (*pcs_pre_config)(struct phylink_pcs *pcs,
494                                phy_interface_t interface);
495         int (*pcs_post_config)(struct phylink_pcs *pcs,
496                                phy_interface_t interface);
497         void (*pcs_get_state)(struct phylink_pcs *pcs,
498                               struct phylink_link_state *state);
499         int (*pcs_config)(struct phylink_pcs *pcs, unsigned int neg_mode,
500                           phy_interface_t interface,
501                           const unsigned long *advertising,
502                           bool permit_pause_to_mac);
503         void (*pcs_an_restart)(struct phylink_pcs *pcs);
504         void (*pcs_link_up)(struct phylink_pcs *pcs, unsigned int neg_mode,
505                             phy_interface_t interface, int speed, int duplex);
506 };
507
508 #if 0 /* For kernel-doc purposes only. */
509 /**
510  * pcs_validate() - validate the link configuration.
511  * @pcs: a pointer to a &struct phylink_pcs.
512  * @supported: ethtool bitmask for supported link modes.
513  * @state: a const pointer to a &struct phylink_link_state.
514  *
515  * Validate the interface mode, and advertising's autoneg bit, removing any
516  * media ethtool link modes that would not be supportable from the supported
517  * mask. Phylink will propagate the changes to the advertising mask. See the
518  * &struct phylink_mac_ops validate() method.
519  *
520  * Returns -EINVAL if the interface mode/autoneg mode is not supported.
521  * Returns non-zero positive if the link state can be supported.
522  */
523 int pcs_validate(struct phylink_pcs *pcs, unsigned long *supported,
524                  const struct phylink_link_state *state);
525
526 /**
527  * pcs_enable() - enable the PCS.
528  * @pcs: a pointer to a &struct phylink_pcs.
529  */
530 int pcs_enable(struct phylink_pcs *pcs);
531
532 /**
533  * pcs_disable() - disable the PCS.
534  * @pcs: a pointer to a &struct phylink_pcs.
535  */
536 void pcs_disable(struct phylink_pcs *pcs);
537
538 /**
539  * pcs_get_state() - Read the current inband link state from the hardware
540  * @pcs: a pointer to a &struct phylink_pcs.
541  * @state: a pointer to a &struct phylink_link_state.
542  *
543  * Read the current inband link state from the MAC PCS, reporting the
544  * current speed in @state->speed, duplex mode in @state->duplex, pause
545  * mode in @state->pause using the %MLO_PAUSE_RX and %MLO_PAUSE_TX bits,
546  * negotiation completion state in @state->an_complete, and link up state
547  * in @state->link. If possible, @state->lp_advertising should also be
548  * populated.
549  *
550  * When present, this overrides pcs_get_state() in &struct
551  * phylink_pcs_ops.
552  */
553 void pcs_get_state(struct phylink_pcs *pcs,
554                    struct phylink_link_state *state);
555
556 /**
557  * pcs_config() - Configure the PCS mode and advertisement
558  * @pcs: a pointer to a &struct phylink_pcs.
559  * @neg_mode: link negotiation mode (see below)
560  * @interface: interface mode to be used
561  * @advertising: adertisement ethtool link mode mask
562  * @permit_pause_to_mac: permit forwarding pause resolution to MAC
563  *
564  * Configure the PCS for the operating mode, the interface mode, and set
565  * the advertisement mask. @permit_pause_to_mac indicates whether the
566  * hardware may forward the pause mode resolution to the MAC.
567  *
568  * When operating in %MLO_AN_INBAND, inband should always be enabled,
569  * otherwise inband should be disabled.
570  *
571  * For SGMII, there is no advertisement from the MAC side, the PCS should
572  * be programmed to acknowledge the inband word from the PHY.
573  *
574  * For 1000BASE-X, the advertisement should be programmed into the PCS.
575  *
576  * For most 10GBASE-R, there is no advertisement.
577  *
578  * The %neg_mode argument should be tested via the phylink_mode_*() family of
579  * functions, or for PCS that set pcs->neg_mode true, should be tested
580  * against the PHYLINK_PCS_NEG_* definitions.
581  */
582 int pcs_config(struct phylink_pcs *pcs, unsigned int neg_mode,
583                phy_interface_t interface, const unsigned long *advertising,
584                bool permit_pause_to_mac);
585
586 /**
587  * pcs_an_restart() - restart 802.3z BaseX autonegotiation
588  * @pcs: a pointer to a &struct phylink_pcs.
589  *
590  * When PCS ops are present, this overrides mac_an_restart() in &struct
591  * phylink_mac_ops.
592  */
593 void pcs_an_restart(struct phylink_pcs *pcs);
594
595 /**
596  * pcs_link_up() - program the PCS for the resolved link configuration
597  * @pcs: a pointer to a &struct phylink_pcs.
598  * @neg_mode: link negotiation mode (see below)
599  * @interface: link &typedef phy_interface_t mode
600  * @speed: link speed
601  * @duplex: link duplex
602  *
603  * This call will be made just before mac_link_up() to inform the PCS of
604  * the resolved link parameters. For example, a PCS operating in SGMII
605  * mode without in-band AN needs to be manually configured for the link
606  * and duplex setting. Otherwise, this should be a no-op.
607  *
608  * The %mode argument should be tested via the phylink_mode_*() family of
609  * functions, or for PCS that set pcs->neg_mode true, should be tested
610  * against the PHYLINK_PCS_NEG_* definitions.
611  */
612 void pcs_link_up(struct phylink_pcs *pcs, unsigned int neg_mode,
613                  phy_interface_t interface, int speed, int duplex);
614 #endif
615
616 struct phylink *phylink_create(struct phylink_config *,
617                                const struct fwnode_handle *,
618                                phy_interface_t,
619                                const struct phylink_mac_ops *);
620 void phylink_destroy(struct phylink *);
621 bool phylink_expects_phy(struct phylink *pl);
622
623 int phylink_connect_phy(struct phylink *, struct phy_device *);
624 int phylink_of_phy_connect(struct phylink *, struct device_node *, u32 flags);
625 int phylink_fwnode_phy_connect(struct phylink *pl,
626                                const struct fwnode_handle *fwnode,
627                                u32 flags);
628 void phylink_disconnect_phy(struct phylink *);
629
630 void phylink_mac_change(struct phylink *, bool up);
631 void phylink_pcs_change(struct phylink_pcs *, bool up);
632
633 void phylink_start(struct phylink *);
634 void phylink_stop(struct phylink *);
635
636 void phylink_suspend(struct phylink *pl, bool mac_wol);
637 void phylink_resume(struct phylink *pl);
638
639 void phylink_ethtool_get_wol(struct phylink *, struct ethtool_wolinfo *);
640 int phylink_ethtool_set_wol(struct phylink *, struct ethtool_wolinfo *);
641
642 int phylink_ethtool_ksettings_get(struct phylink *,
643                                   struct ethtool_link_ksettings *);
644 int phylink_ethtool_ksettings_set(struct phylink *,
645                                   const struct ethtool_link_ksettings *);
646 int phylink_ethtool_nway_reset(struct phylink *);
647 void phylink_ethtool_get_pauseparam(struct phylink *,
648                                     struct ethtool_pauseparam *);
649 int phylink_ethtool_set_pauseparam(struct phylink *,
650                                    struct ethtool_pauseparam *);
651 int phylink_get_eee_err(struct phylink *);
652 int phylink_init_eee(struct phylink *, bool);
653 int phylink_ethtool_get_eee(struct phylink *, struct ethtool_eee *);
654 int phylink_ethtool_set_eee(struct phylink *, struct ethtool_eee *);
655 int phylink_mii_ioctl(struct phylink *, struct ifreq *, int);
656 int phylink_speed_down(struct phylink *pl, bool sync);
657 int phylink_speed_up(struct phylink *pl);
658
659 #define phylink_zero(bm) \
660         bitmap_zero(bm, __ETHTOOL_LINK_MODE_MASK_NBITS)
661 #define __phylink_do_bit(op, bm, mode) \
662         op(ETHTOOL_LINK_MODE_ ## mode ## _BIT, bm)
663
664 #define phylink_set(bm, mode)   __phylink_do_bit(__set_bit, bm, mode)
665 #define phylink_clear(bm, mode) __phylink_do_bit(__clear_bit, bm, mode)
666 #define phylink_test(bm, mode)  __phylink_do_bit(test_bit, bm, mode)
667
668 void phylink_set_port_modes(unsigned long *bits);
669
670 /**
671  * phylink_get_link_timer_ns - return the PCS link timer value
672  * @interface: link &typedef phy_interface_t mode
673  *
674  * Return the PCS link timer setting in nanoseconds for the PHY @interface
675  * mode, or -EINVAL if not appropriate.
676  */
677 static inline int phylink_get_link_timer_ns(phy_interface_t interface)
678 {
679         switch (interface) {
680         case PHY_INTERFACE_MODE_SGMII:
681         case PHY_INTERFACE_MODE_QSGMII:
682         case PHY_INTERFACE_MODE_USXGMII:
683                 return 1600000;
684
685         case PHY_INTERFACE_MODE_1000BASEX:
686         case PHY_INTERFACE_MODE_2500BASEX:
687                 return 10000000;
688
689         default:
690                 return -EINVAL;
691         }
692 }
693
694 void phylink_mii_c22_pcs_decode_state(struct phylink_link_state *state,
695                                       u16 bmsr, u16 lpa);
696 void phylink_mii_c22_pcs_get_state(struct mdio_device *pcs,
697                                    struct phylink_link_state *state);
698 int phylink_mii_c22_pcs_encode_advertisement(phy_interface_t interface,
699                                              const unsigned long *advertising);
700 int phylink_mii_c22_pcs_config(struct mdio_device *pcs,
701                                phy_interface_t interface,
702                                const unsigned long *advertising,
703                                unsigned int neg_mode);
704 void phylink_mii_c22_pcs_an_restart(struct mdio_device *pcs);
705
706 void phylink_resolve_c73(struct phylink_link_state *state);
707
708 void phylink_mii_c45_pcs_get_state(struct mdio_device *pcs,
709                                    struct phylink_link_state *state);
710
711 void phylink_decode_usxgmii_word(struct phylink_link_state *state,
712                                  uint16_t lpa);
713 #endif