xref: /linux-6.15/include/linux/phylink.h (revision ce681558)
19525ae83SRussell King #ifndef NETDEV_PCS_H
29525ae83SRussell King #define NETDEV_PCS_H
39525ae83SRussell King 
49525ae83SRussell King #include <linux/phy.h>
59525ae83SRussell King #include <linux/spinlock.h>
69525ae83SRussell King #include <linux/workqueue.h>
79525ae83SRussell King 
803abf2a7SRussell King (Oracle) #include <net/eee.h>
903abf2a7SRussell King (Oracle) 
109525ae83SRussell King struct device_node;
119525ae83SRussell King struct ethtool_cmd;
128fa7b9b6SRussell King struct fwnode_handle;
139525ae83SRussell King struct net_device;
1424699cc1SRussell King (Oracle) struct phylink;
159525ae83SRussell King 
169525ae83SRussell King enum {
179525ae83SRussell King 	MLO_PAUSE_NONE,
184e5aeb41SRussell King 	MLO_PAUSE_RX = BIT(0),
194e5aeb41SRussell King 	MLO_PAUSE_TX = BIT(1),
209525ae83SRussell King 	MLO_PAUSE_TXRX_MASK = MLO_PAUSE_TX | MLO_PAUSE_RX,
214e5aeb41SRussell King 	MLO_PAUSE_AN = BIT(2),
229525ae83SRussell King 
239525ae83SRussell King 	MLO_AN_PHY = 0,	/* Conventional PHY */
249525ae83SRussell King 	MLO_AN_FIXED,	/* Fixed-link mode */
2586a362c4SRussell King 	MLO_AN_INBAND,	/* In-band protocol */
2634ae2c09SRussell King (Oracle) 
27f99d471aSRussell King (Oracle) 	/* PCS "negotiation" mode.
28f99d471aSRussell King (Oracle) 	 *  PHYLINK_PCS_NEG_NONE - protocol has no inband capability
29f99d471aSRussell King (Oracle) 	 *  PHYLINK_PCS_NEG_OUTBAND - some out of band or fixed link setting
30f99d471aSRussell King (Oracle) 	 *  PHYLINK_PCS_NEG_INBAND_DISABLED - inband mode disabled, e.g.
31f99d471aSRussell King (Oracle) 	 *				      1000base-X with autoneg off
32f99d471aSRussell King (Oracle) 	 *  PHYLINK_PCS_NEG_INBAND_ENABLED - inband mode enabled
33f99d471aSRussell King (Oracle) 	 * Additionally, this can be tested using bitmasks:
34f99d471aSRussell King (Oracle) 	 *  PHYLINK_PCS_NEG_INBAND - inband mode selected
35f99d471aSRussell King (Oracle) 	 *  PHYLINK_PCS_NEG_ENABLED - negotiation mode enabled
36f99d471aSRussell King (Oracle) 	 */
37f99d471aSRussell King (Oracle) 	PHYLINK_PCS_NEG_NONE = 0,
38f99d471aSRussell King (Oracle) 	PHYLINK_PCS_NEG_ENABLED = BIT(4),
39f99d471aSRussell King (Oracle) 	PHYLINK_PCS_NEG_OUTBAND = BIT(5),
40f99d471aSRussell King (Oracle) 	PHYLINK_PCS_NEG_INBAND = BIT(6),
41f99d471aSRussell King (Oracle) 	PHYLINK_PCS_NEG_INBAND_DISABLED = PHYLINK_PCS_NEG_INBAND,
42f99d471aSRussell King (Oracle) 	PHYLINK_PCS_NEG_INBAND_ENABLED = PHYLINK_PCS_NEG_INBAND |
43f99d471aSRussell King (Oracle) 					 PHYLINK_PCS_NEG_ENABLED,
44f99d471aSRussell King (Oracle) 
4572bc3695SSean Anderson 	/* MAC_SYM_PAUSE and MAC_ASYM_PAUSE are used when configuring our
4672bc3695SSean Anderson 	 * autonegotiation advertisement. They correspond to the PAUSE and
4772bc3695SSean Anderson 	 * ASM_DIR bits defined by 802.3, respectively.
4872bc3695SSean Anderson 	 *
4972bc3695SSean Anderson 	 * The following table lists the values of tx_pause and rx_pause which
5072bc3695SSean Anderson 	 * might be requested in mac_link_up. The exact values depend on either
5172bc3695SSean Anderson 	 * the results of autonegotation (if MLO_PAUSE_AN is set) or user
5272bc3695SSean Anderson 	 * configuration (if MLO_PAUSE_AN is not set).
5372bc3695SSean Anderson 	 *
5472bc3695SSean Anderson 	 * MAC_SYM_PAUSE MAC_ASYM_PAUSE MLO_PAUSE_AN tx_pause/rx_pause
5572bc3695SSean Anderson 	 * ============= ============== ============ ==================
5672bc3695SSean Anderson 	 *             0              0            0 0/0
5772bc3695SSean Anderson 	 *             0              0            1 0/0
5872bc3695SSean Anderson 	 *             0              1            0 0/0, 0/1, 1/0, 1/1
5972bc3695SSean Anderson 	 *             0              1            1 0/0,      1/0
6072bc3695SSean Anderson 	 *             1              0            0 0/0,           1/1
6172bc3695SSean Anderson 	 *             1              0            1 0/0,           1/1
6272bc3695SSean Anderson 	 *             1              1            0 0/0, 0/1, 1/0, 1/1
6372bc3695SSean Anderson 	 *             1              1            1 0/0, 0/1,      1/1
6472bc3695SSean Anderson 	 *
6572bc3695SSean Anderson 	 * If you set MAC_ASYM_PAUSE, the user may request any combination of
6672bc3695SSean Anderson 	 * tx_pause and rx_pause. You do not have to support these
6772bc3695SSean Anderson 	 * combinations.
6872bc3695SSean Anderson 	 *
6972bc3695SSean Anderson 	 * However, you should support combinations of tx_pause and rx_pause
7072bc3695SSean Anderson 	 * which might be the result of autonegotation. For example, don't set
7172bc3695SSean Anderson 	 * MAC_SYM_PAUSE unless your device can support tx_pause and rx_pause
7272bc3695SSean Anderson 	 * at the same time.
7372bc3695SSean Anderson 	 */
7434ae2c09SRussell King (Oracle) 	MAC_SYM_PAUSE	= BIT(0),
7534ae2c09SRussell King (Oracle) 	MAC_ASYM_PAUSE	= BIT(1),
7634ae2c09SRussell King (Oracle) 	MAC_10HD	= BIT(2),
7734ae2c09SRussell King (Oracle) 	MAC_10FD	= BIT(3),
7834ae2c09SRussell King (Oracle) 	MAC_10		= MAC_10HD | MAC_10FD,
7934ae2c09SRussell King (Oracle) 	MAC_100HD	= BIT(4),
8034ae2c09SRussell King (Oracle) 	MAC_100FD	= BIT(5),
8134ae2c09SRussell King (Oracle) 	MAC_100		= MAC_100HD | MAC_100FD,
8234ae2c09SRussell King (Oracle) 	MAC_1000HD	= BIT(6),
8334ae2c09SRussell King (Oracle) 	MAC_1000FD	= BIT(7),
8434ae2c09SRussell King (Oracle) 	MAC_1000	= MAC_1000HD | MAC_1000FD,
8534ae2c09SRussell King (Oracle) 	MAC_2500FD	= BIT(8),
8634ae2c09SRussell King (Oracle) 	MAC_5000FD	= BIT(9),
8734ae2c09SRussell King (Oracle) 	MAC_10000FD	= BIT(10),
8834ae2c09SRussell King (Oracle) 	MAC_20000FD	= BIT(11),
8934ae2c09SRussell King (Oracle) 	MAC_25000FD	= BIT(12),
9034ae2c09SRussell King (Oracle) 	MAC_40000FD	= BIT(13),
9134ae2c09SRussell King (Oracle) 	MAC_50000FD	= BIT(14),
9234ae2c09SRussell King (Oracle) 	MAC_56000FD	= BIT(15),
9334ae2c09SRussell King (Oracle) 	MAC_100000FD	= BIT(16),
9434ae2c09SRussell King (Oracle) 	MAC_200000FD	= BIT(17),
9534ae2c09SRussell King (Oracle) 	MAC_400000FD	= BIT(18),
969525ae83SRussell King };
979525ae83SRussell King 
phylink_autoneg_inband(unsigned int mode)989525ae83SRussell King static inline bool phylink_autoneg_inband(unsigned int mode)
999525ae83SRussell King {
10086a362c4SRussell King 	return mode == MLO_AN_INBAND;
1019525ae83SRussell King }
1029525ae83SRussell King 
1038796c892SRussell King /**
1048796c892SRussell King  * struct phylink_link_state - link state structure
1058796c892SRussell King  * @advertising: ethtool bitmask containing advertised link modes
1068796c892SRussell King  * @lp_advertising: ethtool bitmask containing link partner advertised link
1078796c892SRussell King  *   modes
1088796c892SRussell King  * @interface: link &typedef phy_interface_t mode
1098796c892SRussell King  * @speed: link speed, one of the SPEED_* constants.
1108796c892SRussell King  * @duplex: link duplex mode, one of DUPLEX_* constants.
1118796c892SRussell King  * @pause: link pause state, described by MLO_PAUSE_* constants.
112ae0e4bb2SSean Anderson  * @rate_matching: rate matching being performed, one of the RATE_MATCH_*
113ae0e4bb2SSean Anderson  *   constants. If rate matching is taking place, then the speed/duplex of
114ae0e4bb2SSean Anderson  *   the medium link mode (@speed and @duplex) and the speed/duplex of the phy
115ae0e4bb2SSean Anderson  *   interface mode (@interface) are different.
1168796c892SRussell King  * @link: true if the link is up.
1178796c892SRussell King  * @an_complete: true if autonegotiation has completed.
1188796c892SRussell King  */
1199525ae83SRussell King struct phylink_link_state {
1209525ae83SRussell King 	__ETHTOOL_DECLARE_LINK_MODE_MASK(advertising);
1219525ae83SRussell King 	__ETHTOOL_DECLARE_LINK_MODE_MASK(lp_advertising);
1228796c892SRussell King 	phy_interface_t interface;
1239525ae83SRussell King 	int speed;
1249525ae83SRussell King 	int duplex;
1259525ae83SRussell King 	int pause;
126ae0e4bb2SSean Anderson 	int rate_matching;
1279525ae83SRussell King 	unsigned int link:1;
1289525ae83SRussell King 	unsigned int an_complete:1;
1299525ae83SRussell King };
1309525ae83SRussell King 
13144cc27e4SIoana Ciornei enum phylink_op_type {
13244cc27e4SIoana Ciornei 	PHYLINK_NETDEV = 0,
13343de6195SIoana Ciornei 	PHYLINK_DEV,
13444cc27e4SIoana Ciornei };
13544cc27e4SIoana Ciornei 
13644cc27e4SIoana Ciornei /**
13744cc27e4SIoana Ciornei  * struct phylink_config - PHYLINK configuration structure
13844cc27e4SIoana Ciornei  * @dev: a pointer to a struct device associated with the MAC
13944cc27e4SIoana Ciornei  * @type: operation type of PHYLINK instance
1405d682f5eSMauro Carvalho Chehab  * @poll_fixed_state: if true, starts link_poll,
1415d682f5eSMauro Carvalho Chehab  *		      if MAC link is at %MLO_AN_FIXED mode.
14296de900aSShenwei Wang  * @mac_managed_pm: if true, indicate the MAC driver is responsible for PHY PM.
14321d9ba5bSRussell King (Oracle)  * @mac_requires_rxc: if true, the MAC always requires a receive clock from PHY.
14421d9ba5bSRussell King (Oracle)  *                    The PHY driver should start the clock signal as soon as
14521d9ba5bSRussell King (Oracle)  *                    possible and avoid stopping it during suspend events.
14602d00dc7SRussell King (Oracle)  * @default_an_inband: if true, defaults to MLO_AN_INBAND rather than
14702d00dc7SRussell King (Oracle)  *		       MLO_AN_PHY. A fixed-link specification will override.
14803abf2a7SRussell King (Oracle)  * @eee_rx_clk_stop_enable: if true, PHY can stop the receive clock during LPI
1495d682f5eSMauro Carvalho Chehab  * @get_fixed_state: callback to execute to determine the fixed link state,
1505d682f5eSMauro Carvalho Chehab  *		     if MAC link is at %MLO_AN_FIXED mode.
151d25f3a74SRussell King (Oracle)  * @supported_interfaces: bitmap describing which PHY_INTERFACE_MODE_xxx
152d25f3a74SRussell King (Oracle)  *                        are supported by the MAC/PCS.
15303abf2a7SRussell King (Oracle)  * @lpi_interfaces: bitmap describing which PHY interface modes can support
15403abf2a7SRussell King (Oracle)  *		    LPI signalling.
15534ae2c09SRussell King (Oracle)  * @mac_capabilities: MAC pause/speed/duplex capabilities.
15603abf2a7SRussell King (Oracle)  * @lpi_capabilities: MAC speeds which can support LPI signalling
15703abf2a7SRussell King (Oracle)  * @lpi_timer_default: Default EEE LPI timer setting.
15803abf2a7SRussell King (Oracle)  * @eee_enabled_default: If set, EEE will be enabled by phylink at creation time
15944cc27e4SIoana Ciornei  */
16044cc27e4SIoana Ciornei struct phylink_config {
16144cc27e4SIoana Ciornei 	struct device *dev;
16244cc27e4SIoana Ciornei 	enum phylink_op_type type;
1635c05c1dbSRussell King 	bool poll_fixed_state;
16496de900aSShenwei Wang 	bool mac_managed_pm;
16521d9ba5bSRussell King (Oracle) 	bool mac_requires_rxc;
16602d00dc7SRussell King (Oracle) 	bool default_an_inband;
16703abf2a7SRussell King (Oracle) 	bool eee_rx_clk_stop_enable;
1685c05c1dbSRussell King 	void (*get_fixed_state)(struct phylink_config *config,
1695c05c1dbSRussell King 				struct phylink_link_state *state);
17038c310ebSRussell King 	DECLARE_PHY_INTERFACE_MASK(supported_interfaces);
17103abf2a7SRussell King (Oracle) 	DECLARE_PHY_INTERFACE_MASK(lpi_interfaces);
17234ae2c09SRussell King (Oracle) 	unsigned long mac_capabilities;
17303abf2a7SRussell King (Oracle) 	unsigned long lpi_capabilities;
17403abf2a7SRussell King (Oracle) 	u32 lpi_timer_default;
17503abf2a7SRussell King (Oracle) 	bool eee_enabled_default;
17644cc27e4SIoana Ciornei };
17744cc27e4SIoana Ciornei 
17870934c7cSRussell King (Oracle) void phylink_limit_mac_speed(struct phylink_config *config, u32 max_speed);
17970934c7cSRussell King (Oracle) 
1809525ae83SRussell King /**
1818796c892SRussell King  * struct phylink_mac_ops - MAC operations structure.
182b6f97747SRussell King (Oracle)  * @mac_get_caps: Get MAC capabilities for interface mode.
183d1e86325SRussell King (Oracle)  * @mac_select_pcs: Select a PCS for the interface mode.
184b7ad14c2SRussell King  * @mac_prepare: prepare for a major reconfiguration of the interface.
1858796c892SRussell King  * @mac_config: configure the MAC for the selected mode and state.
186b7ad14c2SRussell King  * @mac_finish: finish a major reconfiguration of the interface.
1878796c892SRussell King  * @mac_link_down: take the link down.
1888796c892SRussell King  * @mac_link_up: allow the link to come up.
18903abf2a7SRussell King (Oracle)  * @mac_disable_tx_lpi: disable LPI.
19003abf2a7SRussell King (Oracle)  * @mac_enable_tx_lpi: enable and configure LPI.
1919525ae83SRussell King  *
1928796c892SRussell King  * The individual methods are described more fully below.
1939525ae83SRussell King  */
1948796c892SRussell King struct phylink_mac_ops {
195b6f97747SRussell King (Oracle) 	unsigned long (*mac_get_caps)(struct phylink_config *config,
196b6f97747SRussell King (Oracle) 				      phy_interface_t interface);
197d1e86325SRussell King (Oracle) 	struct phylink_pcs *(*mac_select_pcs)(struct phylink_config *config,
198d1e86325SRussell King (Oracle) 					      phy_interface_t interface);
199b7ad14c2SRussell King 	int (*mac_prepare)(struct phylink_config *config, unsigned int mode,
200b7ad14c2SRussell King 			   phy_interface_t iface);
20144cc27e4SIoana Ciornei 	void (*mac_config)(struct phylink_config *config, unsigned int mode,
2028796c892SRussell King 			   const struct phylink_link_state *state);
203b7ad14c2SRussell King 	int (*mac_finish)(struct phylink_config *config, unsigned int mode,
204b7ad14c2SRussell King 			  phy_interface_t iface);
20544cc27e4SIoana Ciornei 	void (*mac_link_down)(struct phylink_config *config, unsigned int mode,
206c6ab3008SFlorian Fainelli 			      phy_interface_t interface);
20791a208f2SRussell King 	void (*mac_link_up)(struct phylink_config *config,
20891a208f2SRussell King 			    struct phy_device *phy, unsigned int mode,
20991a208f2SRussell King 			    phy_interface_t interface, int speed, int duplex,
21091a208f2SRussell King 			    bool tx_pause, bool rx_pause);
21103abf2a7SRussell King (Oracle) 	void (*mac_disable_tx_lpi)(struct phylink_config *config);
21203abf2a7SRussell King (Oracle) 	int (*mac_enable_tx_lpi)(struct phylink_config *config, u32 timer,
21303abf2a7SRussell King (Oracle) 				 bool tx_clk_stop);
2148796c892SRussell King };
2159525ae83SRussell King 
2168796c892SRussell King #if 0 /* For kernel-doc purposes only. */
2179525ae83SRussell King /**
218b6f97747SRussell King (Oracle)  * mac_get_caps: Get MAC capabilities for interface mode.
219b6f97747SRussell King (Oracle)  * @config: a pointer to a &struct phylink_config.
220b6f97747SRussell King (Oracle)  * @interface: PHY interface mode.
221b6f97747SRussell King (Oracle)  *
222b6f97747SRussell King (Oracle)  * Optional method. When not provided, config->mac_capabilities will be used.
223b6f97747SRussell King (Oracle)  * When implemented, this returns the MAC capabilities for the specified
224b6f97747SRussell King (Oracle)  * interface mode where there is some special handling required by the MAC
225b6f97747SRussell King (Oracle)  * driver (e.g. not supporting half-duplex in certain interface modes.)
226b6f97747SRussell King (Oracle)  */
227b6f97747SRussell King (Oracle) unsigned long mac_get_caps(struct phylink_config *config,
228b6f97747SRussell King (Oracle) 			   phy_interface_t interface);
229b6f97747SRussell King (Oracle) /**
230d1e86325SRussell King (Oracle)  * mac_select_pcs: Select a PCS for the interface mode.
231d1e86325SRussell King (Oracle)  * @config: a pointer to a &struct phylink_config.
232d1e86325SRussell King (Oracle)  * @interface: PHY interface mode for PCS
233d1e86325SRussell King (Oracle)  *
234d1e86325SRussell King (Oracle)  * Return the &struct phylink_pcs for the specified interface mode, or
235d1e86325SRussell King (Oracle)  * NULL if none is required, or an error pointer on error.
236d1e86325SRussell King (Oracle)  *
237d1e86325SRussell King (Oracle)  * This must not modify any state. It is used to query which PCS should
238d1e86325SRussell King (Oracle)  * be used. Phylink will use this during validation to ensure that the
239d1e86325SRussell King (Oracle)  * configuration is valid, and when setting a configuration to internally
240d1e86325SRussell King (Oracle)  * set the PCS that will be used.
241d1e86325SRussell King (Oracle)  */
242d1e86325SRussell King (Oracle) struct phylink_pcs *mac_select_pcs(struct phylink_config *config,
243d1e86325SRussell King (Oracle) 				   phy_interface_t interface);
2448796c892SRussell King 
2458796c892SRussell King /**
246b7ad14c2SRussell King  * mac_prepare() - prepare to change the PHY interface mode
247b7ad14c2SRussell King  * @config: a pointer to a &struct phylink_config.
248b7ad14c2SRussell King  * @mode: one of %MLO_AN_FIXED, %MLO_AN_PHY, %MLO_AN_INBAND.
249b7ad14c2SRussell King  * @iface: interface mode to switch to
250b7ad14c2SRussell King  *
251b7ad14c2SRussell King  * phylink will call this method at the beginning of a full initialisation
252b7ad14c2SRussell King  * of the link, which includes changing the interface mode or at initial
253b7ad14c2SRussell King  * startup time. It may be called for the current mode. The MAC driver
254b7ad14c2SRussell King  * should perform whatever actions are required, e.g. disabling the
255b7ad14c2SRussell King  * Serdes PHY.
256b7ad14c2SRussell King  *
257b7ad14c2SRussell King  * This will be the first call in the sequence:
258b7ad14c2SRussell King  * - mac_prepare()
259b7ad14c2SRussell King  * - mac_config()
260b7ad14c2SRussell King  * - pcs_config()
261b7ad14c2SRussell King  * - possible pcs_an_restart()
262b7ad14c2SRussell King  * - mac_finish()
263b7ad14c2SRussell King  *
264b7ad14c2SRussell King  * Returns zero on success, or negative errno on failure which will be
265b7ad14c2SRussell King  * reported to the kernel log.
266b7ad14c2SRussell King  */
267b7ad14c2SRussell King int mac_prepare(struct phylink_config *config, unsigned int mode,
268b7ad14c2SRussell King 		phy_interface_t iface);
269b7ad14c2SRussell King 
270b7ad14c2SRussell King /**
2718796c892SRussell King  * mac_config() - configure the MAC for the selected mode and state
27244cc27e4SIoana Ciornei  * @config: a pointer to a &struct phylink_config.
2738796c892SRussell King  * @mode: one of %MLO_AN_FIXED, %MLO_AN_PHY, %MLO_AN_INBAND.
2748796c892SRussell King  * @state: a pointer to a &struct phylink_link_state.
2759525ae83SRussell King  *
2764add7009SRussell King - ARM Linux admin  * Note - not all members of @state are valid.  In particular,
2774add7009SRussell King - ARM Linux admin  * @state->lp_advertising, @state->link, @state->an_complete are never
2784add7009SRussell King - ARM Linux admin  * guaranteed to be correct, and so any mac_config() implementation must
2794add7009SRussell King - ARM Linux admin  * never reference these fields.
2804add7009SRussell King - ARM Linux admin  *
2814d72c3bbSRussell King (Oracle)  * This will only be called to reconfigure the MAC for a "major" change in
2824d72c3bbSRussell King (Oracle)  * e.g. interface mode. It will not be called for changes in speed, duplex
2834d72c3bbSRussell King (Oracle)  * or pause modes or to change the in-band advertisement.
28491a208f2SRussell King  *
285b70486f9SRussell King  * In all negotiation modes, as defined by @mode, @state->pause indicates the
286b70486f9SRussell King  * pause settings which should be applied as follows. If %MLO_PAUSE_AN is not
287b70486f9SRussell King  * set, %MLO_PAUSE_TX and %MLO_PAUSE_RX indicate whether the MAC should send
288b70486f9SRussell King  * pause frames and/or act on received pause frames respectively. Otherwise,
289b70486f9SRussell King  * the results of in-band negotiation/status from the MAC PCS should be used
290b70486f9SRussell King  * to control the MAC pause mode settings.
291b70486f9SRussell King  *
2929525ae83SRussell King  * The action performed depends on the currently selected mode:
2939525ae83SRussell King  *
2949525ae83SRussell King  * %MLO_AN_FIXED, %MLO_AN_PHY:
29591a208f2SRussell King  *   Configure for non-inband negotiation mode, where the link settings
29691a208f2SRussell King  *   are completely communicated via mac_link_up().  The physical link
29791a208f2SRussell King  *   protocol from the MAC is specified by @state->interface.
2984add7009SRussell King - ARM Linux admin  *
29991a208f2SRussell King  *   @state->advertising may be used, but is not required.
30091a208f2SRussell King  *
30191a208f2SRussell King  *   Older drivers (prior to the mac_link_up() change) may use @state->speed,
30291a208f2SRussell King  *   @state->duplex and @state->pause to configure the MAC, but this is
30391a208f2SRussell King  *   deprecated; such drivers should be converted to use mac_link_up().
30491a208f2SRussell King  *
30591a208f2SRussell King  *   Other members of @state must be ignored.
30691a208f2SRussell King  *
30791a208f2SRussell King  *   Valid state members: interface, advertising.
30891a208f2SRussell King  *   Deprecated state members: speed, duplex, pause.
3098796c892SRussell King  *
31086a362c4SRussell King  * %MLO_AN_INBAND:
3118796c892SRussell King  *   place the link in an inband negotiation mode (such as 802.3z
3128796c892SRussell King  *   1000base-X or Cisco SGMII mode depending on the @state->interface
3138796c892SRussell King  *   mode). In both cases, link state management (whether the link
3148796c892SRussell King  *   is up or not) is performed by the MAC, and reported via the
3154d72c3bbSRussell King (Oracle)  *   pcs_get_state() callback. Changes in link state must be made
3168796c892SRussell King  *   by calling phylink_mac_change().
3178796c892SRussell King  *
318b70486f9SRussell King  *   Interface mode specific details are mentioned below.
319b70486f9SRussell King  *
3208796c892SRussell King  *   If in 802.3z mode, the link speed is fixed, dependent on the
321b70486f9SRussell King  *   @state->interface. Duplex and pause modes are negotiated via
322b70486f9SRussell King  *   the in-band configuration word. Advertised pause modes are set
323b70486f9SRussell King  *   according to the @state->an_enabled and @state->advertising
324b70486f9SRussell King  *   flags. Beware of MACs which only support full duplex at gigabit
325b70486f9SRussell King  *   and higher speeds.
3268796c892SRussell King  *
3278796c892SRussell King  *   If in Cisco SGMII mode, the link speed and duplex mode are passed
3288796c892SRussell King  *   in the serial bitstream 16-bit configuration word, and the MAC
3298796c892SRussell King  *   should be configured to read these bits and acknowledge the
3308796c892SRussell King  *   configuration word. Nothing is advertised by the MAC. The MAC is
3318796c892SRussell King  *   responsible for reading the configuration word and configuring
3328796c892SRussell King  *   itself accordingly.
3330e29ae03SRussell King  *
3344add7009SRussell King - ARM Linux admin  *   Valid state members: interface, an_enabled, pause, advertising.
3354add7009SRussell King - ARM Linux admin  *
3360e29ae03SRussell King  * Implementations are expected to update the MAC to reflect the
3370e29ae03SRussell King  * requested settings - i.o.w., if nothing has changed between two
3380e29ae03SRussell King  * calls, no action is expected.  If only flow control settings have
3390e29ae03SRussell King  * changed, flow control should be updated *without* taking the link
3400e29ae03SRussell King  * down.  This "update" behaviour is critical to avoid bouncing the
3410e29ae03SRussell King  * link up status.
3429525ae83SRussell King  */
34344cc27e4SIoana Ciornei void mac_config(struct phylink_config *config, unsigned int mode,
3449525ae83SRussell King 		const struct phylink_link_state *state);
3459525ae83SRussell King 
3469525ae83SRussell King /**
347b7ad14c2SRussell King  * mac_finish() - finish a to change the PHY interface mode
348b7ad14c2SRussell King  * @config: a pointer to a &struct phylink_config.
349b7ad14c2SRussell King  * @mode: one of %MLO_AN_FIXED, %MLO_AN_PHY, %MLO_AN_INBAND.
350b7ad14c2SRussell King  * @iface: interface mode to switch to
351b7ad14c2SRussell King  *
352b7ad14c2SRussell King  * phylink will call this if it called mac_prepare() to allow the MAC to
353b7ad14c2SRussell King  * complete any necessary steps after the MAC and PCS have been configured
354b7ad14c2SRussell King  * for the @mode and @iface. E.g. a MAC driver may wish to re-enable the
355b7ad14c2SRussell King  * Serdes PHY here if it was previously disabled by mac_prepare().
356b7ad14c2SRussell King  *
357b7ad14c2SRussell King  * Returns zero on success, or negative errno on failure which will be
358b7ad14c2SRussell King  * reported to the kernel log.
359b7ad14c2SRussell King  */
360b7ad14c2SRussell King int mac_finish(struct phylink_config *config, unsigned int mode,
361b7ad14c2SRussell King 		phy_interface_t iface);
362b7ad14c2SRussell King 
363b7ad14c2SRussell King /**
364*ce681558SRussell King (Oracle)  * mac_link_down() - notification that the link has gone down
36544cc27e4SIoana Ciornei  * @config: a pointer to a &struct phylink_config.
3668796c892SRussell King  * @mode: link autonegotiation mode
367c6ab3008SFlorian Fainelli  * @interface: link &typedef phy_interface_t mode
3688796c892SRussell King  *
369*ce681558SRussell King (Oracle)  * Notifies the MAC that the link has gone down. This will not be called
370*ce681558SRussell King (Oracle)  * unless mac_link_up() has been previously called.
371*ce681558SRussell King (Oracle)  *
372*ce681558SRussell King (Oracle)  * The MAC should stop processing packets for transmission and reception.
373*ce681558SRussell King (Oracle)  * phylink will have called netif_carrier_off() to notify the networking
374*ce681558SRussell King (Oracle)  * stack that the link has gone down, so MAC drivers should not make this
375*ce681558SRussell King (Oracle)  * call.
376*ce681558SRussell King (Oracle)  *
377*ce681558SRussell King (Oracle)  * If @mode is %MLO_AN_INBAND, then this function must not prevent the
378*ce681558SRussell King (Oracle)  * link coming up.
3798796c892SRussell King  */
38044cc27e4SIoana Ciornei void mac_link_down(struct phylink_config *config, unsigned int mode,
381c6ab3008SFlorian Fainelli 		   phy_interface_t interface);
3828796c892SRussell King 
3838796c892SRussell King /**
384*ce681558SRussell King (Oracle)  * mac_link_up() - notification that the link has come up
38544cc27e4SIoana Ciornei  * @config: a pointer to a &struct phylink_config.
386*ce681558SRussell King (Oracle)  * @phy: any attached phy (deprecated - please use LPI interfaces)
3878796c892SRussell King  * @mode: link autonegotiation mode
388c6ab3008SFlorian Fainelli  * @interface: link &typedef phy_interface_t mode
38991a208f2SRussell King  * @speed: link speed
39091a208f2SRussell King  * @duplex: link duplex
39191a208f2SRussell King  * @tx_pause: link transmit pause enablement status
39291a208f2SRussell King  * @rx_pause: link receive pause enablement status
3938796c892SRussell King  *
394*ce681558SRussell King (Oracle)  * Notifies the MAC that the link has come up, and the parameters of the
395*ce681558SRussell King (Oracle)  * link as seen from the MACs point of view. If mac_link_up() has been
396*ce681558SRussell King (Oracle)  * called previously, there will be an intervening call to mac_link_down()
397*ce681558SRussell King (Oracle)  * before this method will be subsequently called.
39891a208f2SRussell King  *
39991a208f2SRussell King  * @speed, @duplex, @tx_pause and @rx_pause indicate the finalised link
40091a208f2SRussell King  * settings, and should be used to configure the MAC block appropriately
40191a208f2SRussell King  * where these settings are not automatically conveyed from the PCS block,
40291a208f2SRussell King  * or if in-band negotiation (as defined by phylink_autoneg_inband(@mode))
40391a208f2SRussell King  * is disabled.
40491a208f2SRussell King  *
40591a208f2SRussell King  * Note that when 802.3z in-band negotiation is in use, it is possible
40691a208f2SRussell King  * that the user wishes to override the pause settings, and this should
40791a208f2SRussell King  * be allowed when considering the implementation of this method.
40891a208f2SRussell King  *
409*ce681558SRussell King (Oracle)  * Once configured, the MAC may begin to process packets for transmission
410*ce681558SRussell King (Oracle)  * and reception.
411*ce681558SRussell King (Oracle)  *
412c6ab3008SFlorian Fainelli  * Interface type selection must be done in mac_config().
4138796c892SRussell King  */
41491a208f2SRussell King void mac_link_up(struct phylink_config *config, struct phy_device *phy,
41591a208f2SRussell King 		 unsigned int mode, phy_interface_t interface,
41691a208f2SRussell King 		 int speed, int duplex, bool tx_pause, bool rx_pause);
41703abf2a7SRussell King (Oracle) 
41803abf2a7SRussell King (Oracle) /**
41903abf2a7SRussell King (Oracle)  * mac_disable_tx_lpi() - disable LPI generation at the MAC
42003abf2a7SRussell King (Oracle)  * @config: a pointer to a &struct phylink_config.
42103abf2a7SRussell King (Oracle)  *
42203abf2a7SRussell King (Oracle)  * Disable generation of LPI at the MAC, effectively preventing the MAC
42303abf2a7SRussell King (Oracle)  * from indicating that it is idle.
42403abf2a7SRussell King (Oracle)  */
42503abf2a7SRussell King (Oracle) void mac_disable_tx_lpi(struct phylink_config *config);
42603abf2a7SRussell King (Oracle) 
42703abf2a7SRussell King (Oracle) /**
42803abf2a7SRussell King (Oracle)  * mac_enable_tx_lpi() - configure and enable LPI generation at the MAC
42903abf2a7SRussell King (Oracle)  * @config: a pointer to a &struct phylink_config.
43003abf2a7SRussell King (Oracle)  * @timer: LPI timeout in microseconds.
43103abf2a7SRussell King (Oracle)  * @tx_clk_stop: allow xMII transmit clock to be stopped during LPI
43203abf2a7SRussell King (Oracle)  *
43303abf2a7SRussell King (Oracle)  * Configure the LPI timeout accordingly. This will only be called when
43403abf2a7SRussell King (Oracle)  * the link is already up, to cater for situations where the hardware
43503abf2a7SRussell King (Oracle)  * needs to be programmed according to the link speed.
43603abf2a7SRussell King (Oracle)  *
43703abf2a7SRussell King (Oracle)  * Enable LPI generation at the MAC, and configure whether the xMII transmit
43803abf2a7SRussell King (Oracle)  * clock may be stopped.
43903abf2a7SRussell King (Oracle)  *
44003abf2a7SRussell King (Oracle)  * Returns: 0 on success. Please consult with rmk before returning an error.
44103abf2a7SRussell King (Oracle)  */
44203abf2a7SRussell King (Oracle) int mac_enable_tx_lpi(struct phylink_config *config, u32 timer,
44303abf2a7SRussell King (Oracle) 		      bool tx_clk_stop);
4448796c892SRussell King #endif
4459525ae83SRussell King 
4467137e18fSRussell King struct phylink_pcs_ops;
4477137e18fSRussell King 
4487137e18fSRussell King /**
4497137e18fSRussell King  * struct phylink_pcs - PHYLINK PCS instance
450fbb9a9d2SRussell King (Oracle)  * @supported_interfaces: describing which PHY_INTERFACE_MODE_xxx
451fbb9a9d2SRussell King (Oracle)  *                        are supported by this PCS.
4527137e18fSRussell King  * @ops: a pointer to the &struct phylink_pcs_ops structure
45324699cc1SRussell King (Oracle)  * @phylink: pointer to &struct phylink_config
4547137e18fSRussell King  * @poll: poll the PCS for link changes
455dceb393aSRomain Gantois  * @rxc_always_on: The MAC driver requires the reference clock
456dceb393aSRomain Gantois  *                 to always be on. Standalone PCS drivers which
457dceb393aSRomain Gantois  *                 do not have access to a PHY device can check
458dceb393aSRomain Gantois  *                 this instead of PHY_F_RXC_ALWAYS_ON.
4597137e18fSRussell King  *
4607137e18fSRussell King  * This structure is designed to be embedded within the PCS private data,
4617137e18fSRussell King  * and will be passed between phylink and the PCS.
46224699cc1SRussell King (Oracle)  *
46324699cc1SRussell King (Oracle)  * The @phylink member is private to phylink and must not be touched by
46424699cc1SRussell King (Oracle)  * the PCS driver.
4657137e18fSRussell King  */
4667137e18fSRussell King struct phylink_pcs {
467fbb9a9d2SRussell King (Oracle) 	DECLARE_PHY_INTERFACE_MASK(supported_interfaces);
4687137e18fSRussell King 	const struct phylink_pcs_ops *ops;
46924699cc1SRussell King (Oracle) 	struct phylink *phylink;
4707137e18fSRussell King 	bool poll;
471dceb393aSRomain Gantois 	bool rxc_always_on;
4727137e18fSRussell King };
4737137e18fSRussell King 
4744c0d6d3aSRussell King /**
4754c0d6d3aSRussell King  * struct phylink_pcs_ops - MAC PCS operations structure.
4760d22d4b6SRussell King (Oracle)  * @pcs_validate: validate the link configuration.
477df874f9eSRussell King (Oracle)  * @pcs_inband_caps: query inband support for interface mode.
47890ef0a7bSRussell King (Oracle)  * @pcs_enable: enable the PCS.
47990ef0a7bSRussell King (Oracle)  * @pcs_disable: disable the PCS.
480aee60988SRussell King (Oracle)  * @pcs_pre_config: pre-mac_config method (for errata)
481aee60988SRussell King (Oracle)  * @pcs_post_config: post-mac_config method (for arrata)
4824c0d6d3aSRussell King  * @pcs_get_state: read the current MAC PCS link state from the hardware.
4834c0d6d3aSRussell King  * @pcs_config: configure the MAC PCS for the selected mode and state.
4844c0d6d3aSRussell King  * @pcs_an_restart: restart 802.3z BaseX autonegotiation.
4854c0d6d3aSRussell King  * @pcs_link_up: program the PCS for the resolved link configuration
4864c0d6d3aSRussell King  *               (where necessary).
487e9f03a6aSRussell King (Oracle)  * @pcs_disable_eee: optional notification to PCS that EEE has been disabled
488e9f03a6aSRussell King (Oracle)  *		     at the MAC.
489e9f03a6aSRussell King (Oracle)  * @pcs_enable_eee: optional notification to PCS that EEE will be enabled at
490e9f03a6aSRussell King (Oracle)  *		    the MAC.
491dceb393aSRomain Gantois  * @pcs_pre_init: configure PCS components necessary for MAC hardware
492dceb393aSRomain Gantois  *                initialization e.g. RX clock for stmmac.
4934c0d6d3aSRussell King  */
4944c0d6d3aSRussell King struct phylink_pcs_ops {
4950d22d4b6SRussell King (Oracle) 	int (*pcs_validate)(struct phylink_pcs *pcs, unsigned long *supported,
4960d22d4b6SRussell King (Oracle) 			    const struct phylink_link_state *state);
497df874f9eSRussell King (Oracle) 	unsigned int (*pcs_inband_caps)(struct phylink_pcs *pcs,
498df874f9eSRussell King (Oracle) 					phy_interface_t interface);
49990ef0a7bSRussell King (Oracle) 	int (*pcs_enable)(struct phylink_pcs *pcs);
50090ef0a7bSRussell King (Oracle) 	void (*pcs_disable)(struct phylink_pcs *pcs);
501aee60988SRussell King (Oracle) 	void (*pcs_pre_config)(struct phylink_pcs *pcs,
502aee60988SRussell King (Oracle) 			       phy_interface_t interface);
503aee60988SRussell King (Oracle) 	int (*pcs_post_config)(struct phylink_pcs *pcs,
504aee60988SRussell King (Oracle) 			       phy_interface_t interface);
505c6739623SRussell King (Oracle) 	void (*pcs_get_state)(struct phylink_pcs *pcs, unsigned int neg_mode,
5064c0d6d3aSRussell King 			      struct phylink_link_state *state);
507f99d471aSRussell King (Oracle) 	int (*pcs_config)(struct phylink_pcs *pcs, unsigned int neg_mode,
5084c0d6d3aSRussell King 			  phy_interface_t interface,
5091571e700SRussell King 			  const unsigned long *advertising,
5101571e700SRussell King 			  bool permit_pause_to_mac);
5117137e18fSRussell King 	void (*pcs_an_restart)(struct phylink_pcs *pcs);
512f99d471aSRussell King (Oracle) 	void (*pcs_link_up)(struct phylink_pcs *pcs, unsigned int neg_mode,
5134c0d6d3aSRussell King 			    phy_interface_t interface, int speed, int duplex);
514e9f03a6aSRussell King (Oracle) 	void (*pcs_disable_eee)(struct phylink_pcs *pcs);
515e9f03a6aSRussell King (Oracle) 	void (*pcs_enable_eee)(struct phylink_pcs *pcs);
516dceb393aSRomain Gantois 	int (*pcs_pre_init)(struct phylink_pcs *pcs);
5174c0d6d3aSRussell King };
5184c0d6d3aSRussell King 
5194c0d6d3aSRussell King #if 0 /* For kernel-doc purposes only. */
5204c0d6d3aSRussell King /**
5210d22d4b6SRussell King (Oracle)  * pcs_validate() - validate the link configuration.
5220d22d4b6SRussell King (Oracle)  * @pcs: a pointer to a &struct phylink_pcs.
5230d22d4b6SRussell King (Oracle)  * @supported: ethtool bitmask for supported link modes.
5240d22d4b6SRussell King (Oracle)  * @state: a const pointer to a &struct phylink_link_state.
5250d22d4b6SRussell King (Oracle)  *
5260d22d4b6SRussell King (Oracle)  * Validate the interface mode, and advertising's autoneg bit, removing any
5270d22d4b6SRussell King (Oracle)  * media ethtool link modes that would not be supportable from the supported
5280d22d4b6SRussell King (Oracle)  * mask. Phylink will propagate the changes to the advertising mask. See the
5290d22d4b6SRussell King (Oracle)  * &struct phylink_mac_ops validate() method.
5300d22d4b6SRussell King (Oracle)  *
5310d22d4b6SRussell King (Oracle)  * Returns -EINVAL if the interface mode/autoneg mode is not supported.
5320d22d4b6SRussell King (Oracle)  * Returns non-zero positive if the link state can be supported.
5330d22d4b6SRussell King (Oracle)  */
5340d22d4b6SRussell King (Oracle) int pcs_validate(struct phylink_pcs *pcs, unsigned long *supported,
5350d22d4b6SRussell King (Oracle) 		 const struct phylink_link_state *state);
5360d22d4b6SRussell King (Oracle) 
5370d22d4b6SRussell King (Oracle) /**
538df874f9eSRussell King (Oracle)  * pcs_inband_caps - query PCS in-band capabilities for interface mode.
539df874f9eSRussell King (Oracle)  * @pcs: a pointer to a &struct phylink_pcs.
540df874f9eSRussell King (Oracle)  * @interface: interface mode to be queried
541df874f9eSRussell King (Oracle)  *
542df874f9eSRussell King (Oracle)  * Returns zero if it is unknown what in-band signalling is supported by the
543df874f9eSRussell King (Oracle)  * PHY (e.g. because the PHY driver doesn't implement the method.) Otherwise,
544df874f9eSRussell King (Oracle)  * returns a bit mask of the LINK_INBAND_* values from
545df874f9eSRussell King (Oracle)  * &enum link_inband_signalling to describe which inband modes are supported
546df874f9eSRussell King (Oracle)  * for this interface mode.
547df874f9eSRussell King (Oracle)  */
548df874f9eSRussell King (Oracle) unsigned int pcs_inband_caps(struct phylink_pcs *pcs,
549df874f9eSRussell King (Oracle) 			     phy_interface_t interface);
550df874f9eSRussell King (Oracle) 
551df874f9eSRussell King (Oracle) /**
55290ef0a7bSRussell King (Oracle)  * pcs_enable() - enable the PCS.
55390ef0a7bSRussell King (Oracle)  * @pcs: a pointer to a &struct phylink_pcs.
55490ef0a7bSRussell King (Oracle)  */
55590ef0a7bSRussell King (Oracle) int pcs_enable(struct phylink_pcs *pcs);
55690ef0a7bSRussell King (Oracle) 
55790ef0a7bSRussell King (Oracle) /**
55890ef0a7bSRussell King (Oracle)  * pcs_disable() - disable the PCS.
55990ef0a7bSRussell King (Oracle)  * @pcs: a pointer to a &struct phylink_pcs.
56090ef0a7bSRussell King (Oracle)  */
56190ef0a7bSRussell King (Oracle) void pcs_disable(struct phylink_pcs *pcs);
56290ef0a7bSRussell King (Oracle) 
56390ef0a7bSRussell King (Oracle) /**
5644c0d6d3aSRussell King  * pcs_get_state() - Read the current inband link state from the hardware
5657137e18fSRussell King  * @pcs: a pointer to a &struct phylink_pcs.
566c6739623SRussell King (Oracle)  * @neg_mode: link negotiation mode (PHYLINK_PCS_NEG_xxx)
5674c0d6d3aSRussell King  * @state: a pointer to a &struct phylink_link_state.
5684c0d6d3aSRussell King  *
5694c0d6d3aSRussell King  * Read the current inband link state from the MAC PCS, reporting the
5704c0d6d3aSRussell King  * current speed in @state->speed, duplex mode in @state->duplex, pause
5714c0d6d3aSRussell King  * mode in @state->pause using the %MLO_PAUSE_RX and %MLO_PAUSE_TX bits,
5724c0d6d3aSRussell King  * negotiation completion state in @state->an_complete, and link up state
5734c0d6d3aSRussell King  * in @state->link. If possible, @state->lp_advertising should also be
5744c0d6d3aSRussell King  * populated.
575c6739623SRussell King (Oracle)  *
576c6739623SRussell King (Oracle)  * Note that the @neg_mode parameter is always the PHYLINK_PCS_NEG_xxx
577c6739623SRussell King (Oracle)  * state, not MLO_AN_xxx.
5784c0d6d3aSRussell King  */
579c6739623SRussell King (Oracle) void pcs_get_state(struct phylink_pcs *pcs, unsigned int neg_mode,
5804c0d6d3aSRussell King 		   struct phylink_link_state *state);
5814c0d6d3aSRussell King 
5824c0d6d3aSRussell King /**
5834c0d6d3aSRussell King  * pcs_config() - Configure the PCS mode and advertisement
5847137e18fSRussell King  * @pcs: a pointer to a &struct phylink_pcs.
585f99d471aSRussell King (Oracle)  * @neg_mode: link negotiation mode (see below)
5864c0d6d3aSRussell King  * @interface: interface mode to be used
5874c0d6d3aSRussell King  * @advertising: adertisement ethtool link mode mask
5881571e700SRussell King  * @permit_pause_to_mac: permit forwarding pause resolution to MAC
5894c0d6d3aSRussell King  *
5904c0d6d3aSRussell King  * Configure the PCS for the operating mode, the interface mode, and set
5911571e700SRussell King  * the advertisement mask. @permit_pause_to_mac indicates whether the
5921571e700SRussell King  * hardware may forward the pause mode resolution to the MAC.
5934c0d6d3aSRussell King  *
5944c0d6d3aSRussell King  * When operating in %MLO_AN_INBAND, inband should always be enabled,
5954c0d6d3aSRussell King  * otherwise inband should be disabled.
5964c0d6d3aSRussell King  *
5974c0d6d3aSRussell King  * For SGMII, there is no advertisement from the MAC side, the PCS should
5984c0d6d3aSRussell King  * be programmed to acknowledge the inband word from the PHY.
5994c0d6d3aSRussell King  *
6004c0d6d3aSRussell King  * For 1000BASE-X, the advertisement should be programmed into the PCS.
6014c0d6d3aSRussell King  *
6024c0d6d3aSRussell King  * For most 10GBASE-R, there is no advertisement.
603f99d471aSRussell King (Oracle)  *
604f99d471aSRussell King (Oracle)  * The %neg_mode argument should be tested via the phylink_mode_*() family of
605f99d471aSRussell King (Oracle)  * functions, or for PCS that set pcs->neg_mode true, should be tested
6061a961e74SJakub Kicinski  * against the PHYLINK_PCS_NEG_* definitions.
60735b862eaSRussell King (Oracle)  *
60835b862eaSRussell King (Oracle)  * pcs_config() will be called when configuration of the PCS is required
60935b862eaSRussell King (Oracle)  * or when the advertisement is possibly updated. It must not unnecessarily
61035b862eaSRussell King (Oracle)  * disrupt an established link.
61135b862eaSRussell King (Oracle)  *
61235b862eaSRussell King (Oracle)  * When an autonegotiation restart is required for 802.3z modes, .pcs_config()
61335b862eaSRussell King (Oracle)  * should return a positive non-zero integer (e.g. 1) to indicate to phylink
61435b862eaSRussell King (Oracle)  * to call the pcs_an_restart() method.
6154c0d6d3aSRussell King  */
616f99d471aSRussell King (Oracle) int pcs_config(struct phylink_pcs *pcs, unsigned int neg_mode,
6170b76e642SRandy Dunlap 	       phy_interface_t interface, const unsigned long *advertising,
6180b76e642SRandy Dunlap 	       bool permit_pause_to_mac);
6194c0d6d3aSRussell King 
6204c0d6d3aSRussell King /**
6214c0d6d3aSRussell King  * pcs_an_restart() - restart 802.3z BaseX autonegotiation
6227137e18fSRussell King  * @pcs: a pointer to a &struct phylink_pcs.
6234c0d6d3aSRussell King  *
6244c0d6d3aSRussell King  * When PCS ops are present, this overrides mac_an_restart() in &struct
6254c0d6d3aSRussell King  * phylink_mac_ops.
6264c0d6d3aSRussell King  */
6277137e18fSRussell King void pcs_an_restart(struct phylink_pcs *pcs);
6284c0d6d3aSRussell King 
6294c0d6d3aSRussell King /**
6304c0d6d3aSRussell King  * pcs_link_up() - program the PCS for the resolved link configuration
6317137e18fSRussell King  * @pcs: a pointer to a &struct phylink_pcs.
632f99d471aSRussell King (Oracle)  * @neg_mode: link negotiation mode (see below)
6334c0d6d3aSRussell King  * @interface: link &typedef phy_interface_t mode
6344c0d6d3aSRussell King  * @speed: link speed
6354c0d6d3aSRussell King  * @duplex: link duplex
6364c0d6d3aSRussell King  *
6374c0d6d3aSRussell King  * This call will be made just before mac_link_up() to inform the PCS of
6384c0d6d3aSRussell King  * the resolved link parameters. For example, a PCS operating in SGMII
6394c0d6d3aSRussell King  * mode without in-band AN needs to be manually configured for the link
6404c0d6d3aSRussell King  * and duplex setting. Otherwise, this should be a no-op.
641f99d471aSRussell King (Oracle)  *
642f99d471aSRussell King (Oracle)  * The %mode argument should be tested via the phylink_mode_*() family of
643f99d471aSRussell King (Oracle)  * functions, or for PCS that set pcs->neg_mode true, should be tested
6441a961e74SJakub Kicinski  * against the PHYLINK_PCS_NEG_* definitions.
6454c0d6d3aSRussell King  */
646f99d471aSRussell King (Oracle) void pcs_link_up(struct phylink_pcs *pcs, unsigned int neg_mode,
6474c0d6d3aSRussell King 		 phy_interface_t interface, int speed, int duplex);
648dceb393aSRomain Gantois 
649dceb393aSRomain Gantois /**
650e9f03a6aSRussell King (Oracle)  * pcs_disable_eee() - Disable EEE at the PCS
651e9f03a6aSRussell King (Oracle)  * @pcs: a pointer to a &struct phylink_pcs
652e9f03a6aSRussell King (Oracle)  *
653e9f03a6aSRussell King (Oracle)  * Optional method informing the PCS that EEE has been disabled at the MAC.
654e9f03a6aSRussell King (Oracle)  */
655e9f03a6aSRussell King (Oracle) void pcs_disable_eee(struct phylink_pcs *pcs);
656e9f03a6aSRussell King (Oracle) 
657e9f03a6aSRussell King (Oracle) /**
658e9f03a6aSRussell King (Oracle)  * pcs_enable_eee() - Enable EEE at the PCS
659e9f03a6aSRussell King (Oracle)  * @pcs: a pointer to a &struct phylink_pcs
660e9f03a6aSRussell King (Oracle)  *
661e9f03a6aSRussell King (Oracle)  * Optional method informing the PCS that EEE is about to be enabled at the MAC.
662e9f03a6aSRussell King (Oracle)  */
663e9f03a6aSRussell King (Oracle) void pcs_enable_eee(struct phylink_pcs *pcs);
664e9f03a6aSRussell King (Oracle) 
665e9f03a6aSRussell King (Oracle) /**
666dceb393aSRomain Gantois  * pcs_pre_init() - Configure PCS components necessary for MAC initialization
667dceb393aSRomain Gantois  * @pcs: a pointer to a &struct phylink_pcs.
668dceb393aSRomain Gantois  *
669dceb393aSRomain Gantois  * This function can be called by MAC drivers through the
670dceb393aSRomain Gantois  * phylink_pcs_pre_init() wrapper, before their hardware is initialized. It
671dceb393aSRomain Gantois  * should not be called after the link is brought up, as reconfiguring the PCS
672dceb393aSRomain Gantois  * at this point could break the link.
673dceb393aSRomain Gantois  *
674dceb393aSRomain Gantois  * Some MAC devices require specific hardware initialization to be performed by
675dceb393aSRomain Gantois  * their associated PCS device before they can properly initialize their own
676dceb393aSRomain Gantois  * hardware. An example of this is the initialization of stmmac controllers,
677dceb393aSRomain Gantois  * which requires an active REF_CLK signal to be provided by the PHY/PCS.
678dceb393aSRomain Gantois  *
679dceb393aSRomain Gantois  * By calling phylink_pcs_pre_init(), MAC drivers can ensure that the PCS is
680dceb393aSRomain Gantois  * setup in a way that allows for successful hardware initialization.
681dceb393aSRomain Gantois  *
682dceb393aSRomain Gantois  * The specific configuration performed by pcs_pre_init() is dependent on the
683dceb393aSRomain Gantois  * model of PCS and the requirements of the MAC device attached to it. PCS
684dceb393aSRomain Gantois  * driver authors should consider whether their target device is to be used in
685dceb393aSRomain Gantois  * conjunction with a MAC device whose driver calls phylink_pcs_pre_init(). MAC
686dceb393aSRomain Gantois  * driver authors should document their requirements for the PCS
687dceb393aSRomain Gantois  * pre-initialization.
688dceb393aSRomain Gantois  *
689dceb393aSRomain Gantois  */
690dceb393aSRomain Gantois int pcs_pre_init(struct phylink_pcs *pcs);
691dceb393aSRomain Gantois 
6924c0d6d3aSRussell King #endif
6934c0d6d3aSRussell King 
694a0b79553SRussell King (Oracle) struct phylink *phylink_create(struct phylink_config *,
695a0b79553SRussell King (Oracle) 			       const struct fwnode_handle *,
696a0b79553SRussell King (Oracle) 			       phy_interface_t,
697a0b79553SRussell King (Oracle) 			       const struct phylink_mac_ops *);
6989525ae83SRussell King void phylink_destroy(struct phylink *);
699653a1809SMichael Sit Wei Hong bool phylink_expects_phy(struct phylink *pl);
7009525ae83SRussell King 
7019525ae83SRussell King int phylink_connect_phy(struct phylink *, struct phy_device *);
7020a62964cSFlorian Fainelli int phylink_of_phy_connect(struct phylink *, struct device_node *, u32 flags);
70325396f68SCalvin Johnson int phylink_fwnode_phy_connect(struct phylink *pl,
704a0b79553SRussell King (Oracle) 			       const struct fwnode_handle *fwnode,
70525396f68SCalvin Johnson 			       u32 flags);
7069525ae83SRussell King void phylink_disconnect_phy(struct phylink *);
7074b3fc475SRussell King int phylink_set_fixed_link(struct phylink *,
7084b3fc475SRussell King 			   const struct phylink_link_state *);
7099525ae83SRussell King 
7109525ae83SRussell King void phylink_mac_change(struct phylink *, bool up);
71124699cc1SRussell King (Oracle) void phylink_pcs_change(struct phylink_pcs *, bool up);
7129525ae83SRussell King 
713dceb393aSRomain Gantois int phylink_pcs_pre_init(struct phylink *pl, struct phylink_pcs *pcs);
714dceb393aSRomain Gantois 
7159525ae83SRussell King void phylink_start(struct phylink *);
7169525ae83SRussell King void phylink_stop(struct phylink *);
7179525ae83SRussell King 
718ddf4bd3fSRussell King (Oracle) void phylink_rx_clk_stop_block(struct phylink *);
719ddf4bd3fSRussell King (Oracle) void phylink_rx_clk_stop_unblock(struct phylink *);
720ddf4bd3fSRussell King (Oracle) 
721f9749365SRussell King (Oracle) void phylink_suspend(struct phylink *pl, bool mac_wol);
722367f1854SRussell King (Oracle) void phylink_prepare_resume(struct phylink *pl);
723f9749365SRussell King (Oracle) void phylink_resume(struct phylink *pl);
724f9749365SRussell King (Oracle) 
7259525ae83SRussell King void phylink_ethtool_get_wol(struct phylink *, struct ethtool_wolinfo *);
7269525ae83SRussell King int phylink_ethtool_set_wol(struct phylink *, struct ethtool_wolinfo *);
7279525ae83SRussell King 
7289525ae83SRussell King int phylink_ethtool_ksettings_get(struct phylink *,
7299525ae83SRussell King 				  struct ethtool_link_ksettings *);
7309525ae83SRussell King int phylink_ethtool_ksettings_set(struct phylink *,
7319525ae83SRussell King 				  const struct ethtool_link_ksettings *);
7329525ae83SRussell King int phylink_ethtool_nway_reset(struct phylink *);
7339525ae83SRussell King void phylink_ethtool_get_pauseparam(struct phylink *,
7349525ae83SRussell King 				    struct ethtool_pauseparam *);
7359525ae83SRussell King int phylink_ethtool_set_pauseparam(struct phylink *,
7369525ae83SRussell King 				   struct ethtool_pauseparam *);
7379525ae83SRussell King int phylink_get_eee_err(struct phylink *);
738d80a5233SHeiner Kallweit int phylink_ethtool_get_eee(struct phylink *link, struct ethtool_keee *eee);
739d80a5233SHeiner Kallweit int phylink_ethtool_set_eee(struct phylink *link, struct ethtool_keee *eee);
7409525ae83SRussell King int phylink_mii_ioctl(struct phylink *, struct ifreq *, int);
741c6d5d843SRussell King int phylink_speed_down(struct phylink *pl, bool sync);
742c6d5d843SRussell King int phylink_speed_up(struct phylink *pl);
7439525ae83SRussell King 
7449525ae83SRussell King #define phylink_zero(bm) \
7459525ae83SRussell King 	bitmap_zero(bm, __ETHTOOL_LINK_MODE_MASK_NBITS)
7469525ae83SRussell King #define __phylink_do_bit(op, bm, mode) \
7479525ae83SRussell King 	op(ETHTOOL_LINK_MODE_ ## mode ## _BIT, bm)
7489525ae83SRussell King 
7499525ae83SRussell King #define phylink_set(bm, mode)	__phylink_do_bit(__set_bit, bm, mode)
7509525ae83SRussell King #define phylink_clear(bm, mode)	__phylink_do_bit(__clear_bit, bm, mode)
7519525ae83SRussell King #define phylink_test(bm, mode)	__phylink_do_bit(test_bit, bm, mode)
7529525ae83SRussell King 
7539525ae83SRussell King void phylink_set_port_modes(unsigned long *bits);
7549525ae83SRussell King 
7559c5a1706SRussell King (Oracle) /**
7569c5a1706SRussell King (Oracle)  * phylink_get_link_timer_ns - return the PCS link timer value
7579c5a1706SRussell King (Oracle)  * @interface: link &typedef phy_interface_t mode
7589c5a1706SRussell King (Oracle)  *
7599c5a1706SRussell King (Oracle)  * Return the PCS link timer setting in nanoseconds for the PHY @interface
7609c5a1706SRussell King (Oracle)  * mode, or -EINVAL if not appropriate.
7619c5a1706SRussell King (Oracle)  */
phylink_get_link_timer_ns(phy_interface_t interface)7629c5a1706SRussell King (Oracle) static inline int phylink_get_link_timer_ns(phy_interface_t interface)
7639c5a1706SRussell King (Oracle) {
7649c5a1706SRussell King (Oracle) 	switch (interface) {
7659c5a1706SRussell King (Oracle) 	case PHY_INTERFACE_MODE_SGMII:
7669c5a1706SRussell King (Oracle) 	case PHY_INTERFACE_MODE_QSGMII:
7679c5a1706SRussell King (Oracle) 	case PHY_INTERFACE_MODE_USXGMII:
768777b8afbSVladimir Oltean 	case PHY_INTERFACE_MODE_10G_QXGMII:
7699c5a1706SRussell King (Oracle) 		return 1600000;
7709c5a1706SRussell King (Oracle) 
7719c5a1706SRussell King (Oracle) 	case PHY_INTERFACE_MODE_1000BASEX:
7729c5a1706SRussell King (Oracle) 	case PHY_INTERFACE_MODE_2500BASEX:
7739c5a1706SRussell King (Oracle) 		return 10000000;
7749c5a1706SRussell King (Oracle) 
7759c5a1706SRussell King (Oracle) 	default:
7769c5a1706SRussell King (Oracle) 		return -EINVAL;
7779c5a1706SRussell King (Oracle) 	}
7789c5a1706SRussell King (Oracle) }
7799c5a1706SRussell King (Oracle) 
7802001d215SRussell King (Oracle) /**
7812001d215SRussell King (Oracle)  * phylink_mac_implements_lpi() - determine if MAC implements LPI ops
7822001d215SRussell King (Oracle)  * @ops: phylink_mac_ops structure
7832001d215SRussell King (Oracle)  *
7842001d215SRussell King (Oracle)  * Returns true if the phylink MAC operations structure indicates that the
7852001d215SRussell King (Oracle)  * LPI operations have been implemented, false otherwise.
7862001d215SRussell King (Oracle)  */
phylink_mac_implements_lpi(const struct phylink_mac_ops * ops)7872001d215SRussell King (Oracle) static inline bool phylink_mac_implements_lpi(const struct phylink_mac_ops *ops)
7882001d215SRussell King (Oracle) {
7892001d215SRussell King (Oracle) 	return ops && ops->mac_disable_tx_lpi && ops->mac_enable_tx_lpi;
7902001d215SRussell King (Oracle) }
7912001d215SRussell King (Oracle) 
792291dcae3SSean Anderson void phylink_mii_c22_pcs_decode_state(struct phylink_link_state *state,
7937e3cb4e8SRussell King (Oracle) 				      unsigned int neg_mode, u16 bmsr, u16 lpa);
79474db1c18SRussell King void phylink_mii_c22_pcs_get_state(struct mdio_device *pcs,
7957e3cb4e8SRussell King (Oracle) 				   unsigned int neg_mode,
79674db1c18SRussell King 				   struct phylink_link_state *state);
797291dcae3SSean Anderson int phylink_mii_c22_pcs_encode_advertisement(phy_interface_t interface,
7980bd27406SRussell King 					     const unsigned long *advertising);
799febf2aafSRussell King (Oracle) int phylink_mii_c22_pcs_config(struct mdio_device *pcs,
80093eaceb0SRussell King 			       phy_interface_t interface,
801febf2aafSRussell King (Oracle) 			       const unsigned long *advertising,
802febf2aafSRussell King (Oracle) 			       unsigned int neg_mode);
80374db1c18SRussell King void phylink_mii_c22_pcs_an_restart(struct mdio_device *pcs);
80474db1c18SRussell King 
805dad98748SRussell King (Oracle) void phylink_resolve_c73(struct phylink_link_state *state);
806dad98748SRussell King (Oracle) 
807b8679ef8SRussell King void phylink_mii_c45_pcs_get_state(struct mdio_device *pcs,
808b8679ef8SRussell King 				   struct phylink_link_state *state);
809afd62209SIoana Ciornei 
810afd62209SIoana Ciornei void phylink_decode_usxgmii_word(struct phylink_link_state *state,
811afd62209SIoana Ciornei 				 uint16_t lpa);
8129525ae83SRussell King #endif
813