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;
12struct phylink;
13
14enum {
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
96static inline bool phylink_autoneg_inband(unsigned int mode)
97{
98	return mode == MLO_AN_INBAND;
99}
100
101/**
102 * struct phylink_link_state - link state structure
103 * @advertising: ethtool bitmask containing advertised link modes
104 * @lp_advertising: ethtool bitmask containing link partner advertised link
105 *   modes
106 * @interface: link &typedef phy_interface_t mode
107 * @speed: link speed, one of the SPEED_* constants.
108 * @duplex: link duplex mode, one of DUPLEX_* constants.
109 * @pause: link pause state, described by MLO_PAUSE_* constants.
110 * @rate_matching: rate matching being performed, one of the RATE_MATCH_*
111 *   constants. If rate matching is taking place, then the speed/duplex of
112 *   the medium link mode (@speed and @duplex) and the speed/duplex of the phy
113 *   interface mode (@interface) are different.
114 * @link: true if the link is up.
115 * @an_complete: true if autonegotiation has completed.
116 */
117struct phylink_link_state {
118	__ETHTOOL_DECLARE_LINK_MODE_MASK(advertising);
119	__ETHTOOL_DECLARE_LINK_MODE_MASK(lp_advertising);
120	phy_interface_t interface;
121	int speed;
122	int duplex;
123	int pause;
124	int rate_matching;
125	unsigned int link:1;
126	unsigned int an_complete:1;
127};
128
129enum phylink_op_type {
130	PHYLINK_NETDEV = 0,
131	PHYLINK_DEV,
132};
133
134/**
135 * struct phylink_config - PHYLINK configuration structure
136 * @dev: a pointer to a struct device associated with the MAC
137 * @type: operation type of PHYLINK instance
138 * @poll_fixed_state: if true, starts link_poll,
139 *		      if MAC link is at %MLO_AN_FIXED mode.
140 * @mac_managed_pm: if true, indicate the MAC driver is responsible for PHY PM.
141 * @ovr_an_inband: if true, override PCS to MLO_AN_INBAND
142 * @get_fixed_state: callback to execute to determine the fixed link state,
143 *		     if MAC link is at %MLO_AN_FIXED mode.
144 * @supported_interfaces: bitmap describing which PHY_INTERFACE_MODE_xxx
145 *                        are supported by the MAC/PCS.
146 * @mac_capabilities: MAC pause/speed/duplex capabilities.
147 */
148struct phylink_config {
149	struct device *dev;
150	enum phylink_op_type type;
151	bool poll_fixed_state;
152	bool mac_managed_pm;
153	bool ovr_an_inband;
154	void (*get_fixed_state)(struct phylink_config *config,
155				struct phylink_link_state *state);
156	DECLARE_PHY_INTERFACE_MASK(supported_interfaces);
157	unsigned long mac_capabilities;
158};
159
160void phylink_limit_mac_speed(struct phylink_config *config, u32 max_speed);
161
162/**
163 * struct phylink_mac_ops - MAC operations structure.
164 * @mac_get_caps: Get MAC capabilities for interface mode.
165 * @mac_select_pcs: Select a PCS for the interface mode.
166 * @mac_prepare: prepare for a major reconfiguration of the interface.
167 * @mac_config: configure the MAC for the selected mode and state.
168 * @mac_finish: finish a major reconfiguration of the interface.
169 * @mac_link_down: take the link down.
170 * @mac_link_up: allow the link to come up.
171 *
172 * The individual methods are described more fully below.
173 */
174struct phylink_mac_ops {
175	unsigned long (*mac_get_caps)(struct phylink_config *config,
176				      phy_interface_t interface);
177	struct phylink_pcs *(*mac_select_pcs)(struct phylink_config *config,
178					      phy_interface_t interface);
179	int (*mac_prepare)(struct phylink_config *config, unsigned int mode,
180			   phy_interface_t iface);
181	void (*mac_config)(struct phylink_config *config, unsigned int mode,
182			   const struct phylink_link_state *state);
183	int (*mac_finish)(struct phylink_config *config, unsigned int mode,
184			  phy_interface_t iface);
185	void (*mac_link_down)(struct phylink_config *config, unsigned int mode,
186			      phy_interface_t interface);
187	void (*mac_link_up)(struct phylink_config *config,
188			    struct phy_device *phy, unsigned int mode,
189			    phy_interface_t interface, int speed, int duplex,
190			    bool tx_pause, bool rx_pause);
191};
192
193#if 0 /* For kernel-doc purposes only. */
194/**
195 * mac_get_caps: Get MAC capabilities for interface mode.
196 * @config: a pointer to a &struct phylink_config.
197 * @interface: PHY interface mode.
198 *
199 * Optional method. When not provided, config->mac_capabilities will be used.
200 * When implemented, this returns the MAC capabilities for the specified
201 * interface mode where there is some special handling required by the MAC
202 * driver (e.g. not supporting half-duplex in certain interface modes.)
203 */
204unsigned long mac_get_caps(struct phylink_config *config,
205			   phy_interface_t interface);
206/**
207 * mac_select_pcs: Select a PCS for the interface mode.
208 * @config: a pointer to a &struct phylink_config.
209 * @interface: PHY interface mode for PCS
210 *
211 * Return the &struct phylink_pcs for the specified interface mode, or
212 * NULL if none is required, or an error pointer on error.
213 *
214 * This must not modify any state. It is used to query which PCS should
215 * be used. Phylink will use this during validation to ensure that the
216 * configuration is valid, and when setting a configuration to internally
217 * set the PCS that will be used.
218 */
219struct phylink_pcs *mac_select_pcs(struct phylink_config *config,
220				   phy_interface_t interface);
221
222/**
223 * mac_prepare() - prepare to change the PHY interface mode
224 * @config: a pointer to a &struct phylink_config.
225 * @mode: one of %MLO_AN_FIXED, %MLO_AN_PHY, %MLO_AN_INBAND.
226 * @iface: interface mode to switch to
227 *
228 * phylink will call this method at the beginning of a full initialisation
229 * of the link, which includes changing the interface mode or at initial
230 * startup time. It may be called for the current mode. The MAC driver
231 * should perform whatever actions are required, e.g. disabling the
232 * Serdes PHY.
233 *
234 * This will be the first call in the sequence:
235 * - mac_prepare()
236 * - mac_config()
237 * - pcs_config()
238 * - possible pcs_an_restart()
239 * - mac_finish()
240 *
241 * Returns zero on success, or negative errno on failure which will be
242 * reported to the kernel log.
243 */
244int mac_prepare(struct phylink_config *config, unsigned int mode,
245		phy_interface_t iface);
246
247/**
248 * mac_config() - configure the MAC for the selected mode and state
249 * @config: a pointer to a &struct phylink_config.
250 * @mode: one of %MLO_AN_FIXED, %MLO_AN_PHY, %MLO_AN_INBAND.
251 * @state: a pointer to a &struct phylink_link_state.
252 *
253 * Note - not all members of @state are valid.  In particular,
254 * @state->lp_advertising, @state->link, @state->an_complete are never
255 * guaranteed to be correct, and so any mac_config() implementation must
256 * never reference these fields.
257 *
258 * This will only be called to reconfigure the MAC for a "major" change in
259 * e.g. interface mode. It will not be called for changes in speed, duplex
260 * or pause modes or to change the in-band advertisement.
261 *
262 * In all negotiation modes, as defined by @mode, @state->pause indicates the
263 * pause settings which should be applied as follows. If %MLO_PAUSE_AN is not
264 * set, %MLO_PAUSE_TX and %MLO_PAUSE_RX indicate whether the MAC should send
265 * pause frames and/or act on received pause frames respectively. Otherwise,
266 * the results of in-band negotiation/status from the MAC PCS should be used
267 * to control the MAC pause mode settings.
268 *
269 * The action performed depends on the currently selected mode:
270 *
271 * %MLO_AN_FIXED, %MLO_AN_PHY:
272 *   Configure for non-inband negotiation mode, where the link settings
273 *   are completely communicated via mac_link_up().  The physical link
274 *   protocol from the MAC is specified by @state->interface.
275 *
276 *   @state->advertising may be used, but is not required.
277 *
278 *   Older drivers (prior to the mac_link_up() change) may use @state->speed,
279 *   @state->duplex and @state->pause to configure the MAC, but this is
280 *   deprecated; such drivers should be converted to use mac_link_up().
281 *
282 *   Other members of @state must be ignored.
283 *
284 *   Valid state members: interface, advertising.
285 *   Deprecated state members: speed, duplex, pause.
286 *
287 * %MLO_AN_INBAND:
288 *   place the link in an inband negotiation mode (such as 802.3z
289 *   1000base-X or Cisco SGMII mode depending on the @state->interface
290 *   mode). In both cases, link state management (whether the link
291 *   is up or not) is performed by the MAC, and reported via the
292 *   pcs_get_state() callback. Changes in link state must be made
293 *   by calling phylink_mac_change().
294 *
295 *   Interface mode specific details are mentioned below.
296 *
297 *   If in 802.3z mode, the link speed is fixed, dependent on the
298 *   @state->interface. Duplex and pause modes are negotiated via
299 *   the in-band configuration word. Advertised pause modes are set
300 *   according to the @state->an_enabled and @state->advertising
301 *   flags. Beware of MACs which only support full duplex at gigabit
302 *   and higher speeds.
303 *
304 *   If in Cisco SGMII mode, the link speed and duplex mode are passed
305 *   in the serial bitstream 16-bit configuration word, and the MAC
306 *   should be configured to read these bits and acknowledge the
307 *   configuration word. Nothing is advertised by the MAC. The MAC is
308 *   responsible for reading the configuration word and configuring
309 *   itself accordingly.
310 *
311 *   Valid state members: interface, an_enabled, pause, advertising.
312 *
313 * Implementations are expected to update the MAC to reflect the
314 * requested settings - i.o.w., if nothing has changed between two
315 * calls, no action is expected.  If only flow control settings have
316 * changed, flow control should be updated *without* taking the link
317 * down.  This "update" behaviour is critical to avoid bouncing the
318 * link up status.
319 */
320void mac_config(struct phylink_config *config, unsigned int mode,
321		const struct phylink_link_state *state);
322
323/**
324 * mac_finish() - finish a to change the PHY interface mode
325 * @config: a pointer to a &struct phylink_config.
326 * @mode: one of %MLO_AN_FIXED, %MLO_AN_PHY, %MLO_AN_INBAND.
327 * @iface: interface mode to switch to
328 *
329 * phylink will call this if it called mac_prepare() to allow the MAC to
330 * complete any necessary steps after the MAC and PCS have been configured
331 * for the @mode and @iface. E.g. a MAC driver may wish to re-enable the
332 * Serdes PHY here if it was previously disabled by mac_prepare().
333 *
334 * Returns zero on success, or negative errno on failure which will be
335 * reported to the kernel log.
336 */
337int mac_finish(struct phylink_config *config, unsigned int mode,
338		phy_interface_t iface);
339
340/**
341 * mac_link_down() - take the link down
342 * @config: a pointer to a &struct phylink_config.
343 * @mode: link autonegotiation mode
344 * @interface: link &typedef phy_interface_t mode
345 *
346 * If @mode is not an in-band negotiation mode (as defined by
347 * phylink_autoneg_inband()), force the link down and disable any
348 * Energy Efficient Ethernet MAC configuration. Interface type
349 * selection must be done in mac_config().
350 */
351void mac_link_down(struct phylink_config *config, unsigned int mode,
352		   phy_interface_t interface);
353
354/**
355 * mac_link_up() - allow the link to come up
356 * @config: a pointer to a &struct phylink_config.
357 * @phy: any attached phy
358 * @mode: link autonegotiation mode
359 * @interface: link &typedef phy_interface_t mode
360 * @speed: link speed
361 * @duplex: link duplex
362 * @tx_pause: link transmit pause enablement status
363 * @rx_pause: link receive pause enablement status
364 *
365 * Configure the MAC for an established link.
366 *
367 * @speed, @duplex, @tx_pause and @rx_pause indicate the finalised link
368 * settings, and should be used to configure the MAC block appropriately
369 * where these settings are not automatically conveyed from the PCS block,
370 * or if in-band negotiation (as defined by phylink_autoneg_inband(@mode))
371 * is disabled.
372 *
373 * Note that when 802.3z in-band negotiation is in use, it is possible
374 * that the user wishes to override the pause settings, and this should
375 * be allowed when considering the implementation of this method.
376 *
377 * If in-band negotiation mode is disabled, allow the link to come up. If
378 * @phy is non-%NULL, configure Energy Efficient Ethernet by calling
379 * phy_init_eee() and perform appropriate MAC configuration for EEE.
380 * Interface type selection must be done in mac_config().
381 */
382void mac_link_up(struct phylink_config *config, struct phy_device *phy,
383		 unsigned int mode, phy_interface_t interface,
384		 int speed, int duplex, bool tx_pause, bool rx_pause);
385#endif
386
387struct phylink_pcs_ops;
388
389/**
390 * struct phylink_pcs - PHYLINK PCS instance
391 * @ops: a pointer to the &struct phylink_pcs_ops structure
392 * @phylink: pointer to &struct phylink_config
393 * @neg_mode: provide PCS neg mode via "mode" argument
394 * @poll: poll the PCS for link changes
395 *
396 * This structure is designed to be embedded within the PCS private data,
397 * and will be passed between phylink and the PCS.
398 *
399 * The @phylink member is private to phylink and must not be touched by
400 * the PCS driver.
401 */
402struct phylink_pcs {
403	const struct phylink_pcs_ops *ops;
404	struct phylink *phylink;
405	bool neg_mode;
406	bool poll;
407};
408
409/**
410 * struct phylink_pcs_ops - MAC PCS operations structure.
411 * @pcs_validate: validate the link configuration.
412 * @pcs_enable: enable the PCS.
413 * @pcs_disable: disable the PCS.
414 * @pcs_pre_config: pre-mac_config method (for errata)
415 * @pcs_post_config: post-mac_config method (for arrata)
416 * @pcs_get_state: read the current MAC PCS link state from the hardware.
417 * @pcs_config: configure the MAC PCS for the selected mode and state.
418 * @pcs_an_restart: restart 802.3z BaseX autonegotiation.
419 * @pcs_link_up: program the PCS for the resolved link configuration
420 *               (where necessary).
421 */
422struct phylink_pcs_ops {
423	int (*pcs_validate)(struct phylink_pcs *pcs, unsigned long *supported,
424			    const struct phylink_link_state *state);
425	int (*pcs_enable)(struct phylink_pcs *pcs);
426	void (*pcs_disable)(struct phylink_pcs *pcs);
427	void (*pcs_pre_config)(struct phylink_pcs *pcs,
428			       phy_interface_t interface);
429	int (*pcs_post_config)(struct phylink_pcs *pcs,
430			       phy_interface_t interface);
431	void (*pcs_get_state)(struct phylink_pcs *pcs,
432			      struct phylink_link_state *state);
433	int (*pcs_config)(struct phylink_pcs *pcs, unsigned int neg_mode,
434			  phy_interface_t interface,
435			  const unsigned long *advertising,
436			  bool permit_pause_to_mac);
437	void (*pcs_an_restart)(struct phylink_pcs *pcs);
438	void (*pcs_link_up)(struct phylink_pcs *pcs, unsigned int neg_mode,
439			    phy_interface_t interface, int speed, int duplex);
440};
441
442#if 0 /* For kernel-doc purposes only. */
443/**
444 * pcs_validate() - validate the link configuration.
445 * @pcs: a pointer to a &struct phylink_pcs.
446 * @supported: ethtool bitmask for supported link modes.
447 * @state: a const pointer to a &struct phylink_link_state.
448 *
449 * Validate the interface mode, and advertising's autoneg bit, removing any
450 * media ethtool link modes that would not be supportable from the supported
451 * mask. Phylink will propagate the changes to the advertising mask. See the
452 * &struct phylink_mac_ops validate() method.
453 *
454 * Returns -EINVAL if the interface mode/autoneg mode is not supported.
455 * Returns non-zero positive if the link state can be supported.
456 */
457int pcs_validate(struct phylink_pcs *pcs, unsigned long *supported,
458		 const struct phylink_link_state *state);
459
460/**
461 * pcs_enable() - enable the PCS.
462 * @pcs: a pointer to a &struct phylink_pcs.
463 */
464int pcs_enable(struct phylink_pcs *pcs);
465
466/**
467 * pcs_disable() - disable the PCS.
468 * @pcs: a pointer to a &struct phylink_pcs.
469 */
470void pcs_disable(struct phylink_pcs *pcs);
471
472/**
473 * pcs_get_state() - Read the current inband link state from the hardware
474 * @pcs: a pointer to a &struct phylink_pcs.
475 * @state: a pointer to a &struct phylink_link_state.
476 *
477 * Read the current inband link state from the MAC PCS, reporting the
478 * current speed in @state->speed, duplex mode in @state->duplex, pause
479 * mode in @state->pause using the %MLO_PAUSE_RX and %MLO_PAUSE_TX bits,
480 * negotiation completion state in @state->an_complete, and link up state
481 * in @state->link. If possible, @state->lp_advertising should also be
482 * populated.
483 */
484void pcs_get_state(struct phylink_pcs *pcs,
485		   struct phylink_link_state *state);
486
487/**
488 * pcs_config() - Configure the PCS mode and advertisement
489 * @pcs: a pointer to a &struct phylink_pcs.
490 * @neg_mode: link negotiation mode (see below)
491 * @interface: interface mode to be used
492 * @advertising: adertisement ethtool link mode mask
493 * @permit_pause_to_mac: permit forwarding pause resolution to MAC
494 *
495 * Configure the PCS for the operating mode, the interface mode, and set
496 * the advertisement mask. @permit_pause_to_mac indicates whether the
497 * hardware may forward the pause mode resolution to the MAC.
498 *
499 * When operating in %MLO_AN_INBAND, inband should always be enabled,
500 * otherwise inband should be disabled.
501 *
502 * For SGMII, there is no advertisement from the MAC side, the PCS should
503 * be programmed to acknowledge the inband word from the PHY.
504 *
505 * For 1000BASE-X, the advertisement should be programmed into the PCS.
506 *
507 * For most 10GBASE-R, there is no advertisement.
508 *
509 * The %neg_mode argument should be tested via the phylink_mode_*() family of
510 * functions, or for PCS that set pcs->neg_mode true, should be tested
511 * against the PHYLINK_PCS_NEG_* definitions.
512 */
513int pcs_config(struct phylink_pcs *pcs, unsigned int neg_mode,
514	       phy_interface_t interface, const unsigned long *advertising,
515	       bool permit_pause_to_mac);
516
517/**
518 * pcs_an_restart() - restart 802.3z BaseX autonegotiation
519 * @pcs: a pointer to a &struct phylink_pcs.
520 *
521 * When PCS ops are present, this overrides mac_an_restart() in &struct
522 * phylink_mac_ops.
523 */
524void pcs_an_restart(struct phylink_pcs *pcs);
525
526/**
527 * pcs_link_up() - program the PCS for the resolved link configuration
528 * @pcs: a pointer to a &struct phylink_pcs.
529 * @neg_mode: link negotiation mode (see below)
530 * @interface: link &typedef phy_interface_t mode
531 * @speed: link speed
532 * @duplex: link duplex
533 *
534 * This call will be made just before mac_link_up() to inform the PCS of
535 * the resolved link parameters. For example, a PCS operating in SGMII
536 * mode without in-band AN needs to be manually configured for the link
537 * and duplex setting. Otherwise, this should be a no-op.
538 *
539 * The %mode argument should be tested via the phylink_mode_*() family of
540 * functions, or for PCS that set pcs->neg_mode true, should be tested
541 * against the PHYLINK_PCS_NEG_* definitions.
542 */
543void pcs_link_up(struct phylink_pcs *pcs, unsigned int neg_mode,
544		 phy_interface_t interface, int speed, int duplex);
545#endif
546
547struct phylink *phylink_create(struct phylink_config *,
548			       const struct fwnode_handle *,
549			       phy_interface_t,
550			       const struct phylink_mac_ops *);
551void phylink_destroy(struct phylink *);
552bool phylink_expects_phy(struct phylink *pl);
553
554int phylink_connect_phy(struct phylink *, struct phy_device *);
555int phylink_of_phy_connect(struct phylink *, struct device_node *, u32 flags);
556int phylink_fwnode_phy_connect(struct phylink *pl,
557			       const struct fwnode_handle *fwnode,
558			       u32 flags);
559void phylink_disconnect_phy(struct phylink *);
560
561void phylink_mac_change(struct phylink *, bool up);
562void phylink_pcs_change(struct phylink_pcs *, bool up);
563
564void phylink_start(struct phylink *);
565void phylink_stop(struct phylink *);
566
567void phylink_suspend(struct phylink *pl, bool mac_wol);
568void phylink_resume(struct phylink *pl);
569
570void phylink_ethtool_get_wol(struct phylink *, struct ethtool_wolinfo *);
571int phylink_ethtool_set_wol(struct phylink *, struct ethtool_wolinfo *);
572
573int phylink_ethtool_ksettings_get(struct phylink *,
574				  struct ethtool_link_ksettings *);
575int phylink_ethtool_ksettings_set(struct phylink *,
576				  const struct ethtool_link_ksettings *);
577int phylink_ethtool_nway_reset(struct phylink *);
578void phylink_ethtool_get_pauseparam(struct phylink *,
579				    struct ethtool_pauseparam *);
580int phylink_ethtool_set_pauseparam(struct phylink *,
581				   struct ethtool_pauseparam *);
582int phylink_get_eee_err(struct phylink *);
583int phylink_init_eee(struct phylink *, bool);
584int phylink_ethtool_get_eee(struct phylink *link, struct ethtool_keee *eee);
585int phylink_ethtool_set_eee(struct phylink *link, struct ethtool_keee *eee);
586int phylink_mii_ioctl(struct phylink *, struct ifreq *, int);
587int phylink_speed_down(struct phylink *pl, bool sync);
588int phylink_speed_up(struct phylink *pl);
589
590#define phylink_zero(bm) \
591	bitmap_zero(bm, __ETHTOOL_LINK_MODE_MASK_NBITS)
592#define __phylink_do_bit(op, bm, mode) \
593	op(ETHTOOL_LINK_MODE_ ## mode ## _BIT, bm)
594
595#define phylink_set(bm, mode)	__phylink_do_bit(__set_bit, bm, mode)
596#define phylink_clear(bm, mode)	__phylink_do_bit(__clear_bit, bm, mode)
597#define phylink_test(bm, mode)	__phylink_do_bit(test_bit, bm, mode)
598
599void phylink_set_port_modes(unsigned long *bits);
600
601/**
602 * phylink_get_link_timer_ns - return the PCS link timer value
603 * @interface: link &typedef phy_interface_t mode
604 *
605 * Return the PCS link timer setting in nanoseconds for the PHY @interface
606 * mode, or -EINVAL if not appropriate.
607 */
608static inline int phylink_get_link_timer_ns(phy_interface_t interface)
609{
610	switch (interface) {
611	case PHY_INTERFACE_MODE_SGMII:
612	case PHY_INTERFACE_MODE_QSGMII:
613	case PHY_INTERFACE_MODE_USXGMII:
614		return 1600000;
615
616	case PHY_INTERFACE_MODE_1000BASEX:
617	case PHY_INTERFACE_MODE_2500BASEX:
618		return 10000000;
619
620	default:
621		return -EINVAL;
622	}
623}
624
625void phylink_mii_c22_pcs_decode_state(struct phylink_link_state *state,
626				      u16 bmsr, u16 lpa);
627void phylink_mii_c22_pcs_get_state(struct mdio_device *pcs,
628				   struct phylink_link_state *state);
629int phylink_mii_c22_pcs_encode_advertisement(phy_interface_t interface,
630					     const unsigned long *advertising);
631int phylink_mii_c22_pcs_config(struct mdio_device *pcs,
632			       phy_interface_t interface,
633			       const unsigned long *advertising,
634			       unsigned int neg_mode);
635void phylink_mii_c22_pcs_an_restart(struct mdio_device *pcs);
636
637void phylink_resolve_c73(struct phylink_link_state *state);
638
639void phylink_mii_c45_pcs_get_state(struct mdio_device *pcs,
640				   struct phylink_link_state *state);
641
642void phylink_decode_usxgmii_word(struct phylink_link_state *state,
643				 uint16_t lpa);
644#endif
645