diff options
Diffstat (limited to 'include/linux/phylink.h')
| -rw-r--r-- | include/linux/phylink.h | 201 | 
1 files changed, 143 insertions, 58 deletions
diff --git a/include/linux/phylink.h b/include/linux/phylink.h index af67edd4ae38..bd137c273d38 100644 --- a/include/linux/phylink.h +++ b/include/linux/phylink.h @@ -7,6 +7,7 @@  struct device_node;  struct ethtool_cmd; +struct fwnode_handle;  struct net_device;  enum { @@ -20,19 +21,31 @@ enum {  	MLO_AN_PHY = 0,	/* Conventional PHY */  	MLO_AN_FIXED,	/* Fixed-link mode */ -	MLO_AN_SGMII,	/* Cisco SGMII protocol */ -	MLO_AN_8023Z,	/* 1000base-X protocol */ +	MLO_AN_INBAND,	/* In-band protocol */  };  static inline bool phylink_autoneg_inband(unsigned int mode)  { -	return mode == MLO_AN_SGMII || mode == MLO_AN_8023Z; +	return mode == MLO_AN_INBAND;  } +/** + * struct phylink_link_state - link state structure + * @advertising: ethtool bitmask containing advertised link modes + * @lp_advertising: ethtool bitmask containing link partner advertised link + *   modes + * @interface: link &typedef phy_interface_t mode + * @speed: link speed, one of the SPEED_* constants. + * @duplex: link duplex mode, one of DUPLEX_* constants. + * @pause: link pause state, described by MLO_PAUSE_* constants. + * @link: true if the link is up. + * @an_enabled: true if autonegotiation is enabled/desired. + * @an_complete: true if autonegotiation has completed. + */  struct phylink_link_state {  	__ETHTOOL_DECLARE_LINK_MODE_MASK(advertising);  	__ETHTOOL_DECLARE_LINK_MODE_MASK(lp_advertising); -	phy_interface_t interface;	/* PHY_INTERFACE_xxx */ +	phy_interface_t interface;  	int speed;  	int duplex;  	int pause; @@ -41,72 +54,145 @@ struct phylink_link_state {  	unsigned int an_complete:1;  }; +/** + * struct phylink_mac_ops - MAC operations structure. + * @validate: Validate and update the link configuration. + * @mac_link_state: Read the current link state from the hardware. + * @mac_config: configure the MAC for the selected mode and state. + * @mac_an_restart: restart 802.3z BaseX autonegotiation. + * @mac_link_down: take the link down. + * @mac_link_up: allow the link to come up. + * + * The individual methods are described more fully below. + */  struct phylink_mac_ops { -	/** -	 * validate: validate and update the link configuration -	 * @ndev: net_device structure associated with MAC -	 * @config: configuration to validate -	 * -	 * Update the %config->supported and %config->advertised masks -	 * clearing bits that can not be supported. -	 * -	 * Note: the PHY may be able to transform from one connection -	 * technology to another, so, eg, don't clear 1000BaseX just -	 * because the MAC is unable to support it.  This is more about -	 * clearing unsupported speeds and duplex settings. -	 * -	 * If the %config->interface mode is %PHY_INTERFACE_MODE_1000BASEX -	 * or %PHY_INTERFACE_MODE_2500BASEX, select the appropriate mode -	 * based on %config->advertised and/or %config->speed. -	 */  	void (*validate)(struct net_device *ndev, unsigned long *supported,  			 struct phylink_link_state *state); - -	/* Read the current link state from the hardware */ -	int (*mac_link_state)(struct net_device *, struct phylink_link_state *); - -	/* Configure the MAC */ -	/** -	 * mac_config: configure the MAC for the selected mode and state -	 * @ndev: net_device structure for the MAC -	 * @mode: one of MLO_AN_FIXED, MLO_AN_PHY, MLO_AN_8023Z, MLO_AN_SGMII -	 * @state: state structure -	 * -	 * The action performed depends on the currently selected mode: -	 * -	 * %MLO_AN_FIXED, %MLO_AN_PHY: -	 *   set the specified speed, duplex, pause mode, and phy interface -	 *   mode in the provided @state. -	 * %MLO_AN_8023Z: -	 *   place the link in 1000base-X mode, advertising the parameters -	 *   given in advertising in @state. -	 * %MLO_AN_SGMII: -	 *   place the link in Cisco SGMII mode - there is no advertisment -	 *   to make as the PHY communicates the speed and duplex to the -	 *   MAC over the in-band control word.  Configuration of the pause -	 *   mode is as per MLO_AN_PHY since this is not included. -	 */ +	int (*mac_link_state)(struct net_device *ndev, +			      struct phylink_link_state *state);  	void (*mac_config)(struct net_device *ndev, unsigned int mode,  			   const struct phylink_link_state *state); - -	/** -	 * mac_an_restart: restart 802.3z BaseX autonegotiation -	 * @ndev: net_device structure for the MAC -	 */  	void (*mac_an_restart)(struct net_device *ndev); - -	void (*mac_link_down)(struct net_device *, unsigned int mode); -	void (*mac_link_up)(struct net_device *, unsigned int mode, -			    struct phy_device *); +	void (*mac_link_down)(struct net_device *ndev, unsigned int mode); +	void (*mac_link_up)(struct net_device *ndev, unsigned int mode, +			    struct phy_device *phy);  }; -struct phylink *phylink_create(struct net_device *, struct device_node *, +#if 0 /* For kernel-doc purposes only. */ +/** + * validate - Validate and update the link configuration + * @ndev: a pointer to a &struct net_device for the MAC. + * @supported: ethtool bitmask for supported link modes. + * @state: a pointer to a &struct phylink_link_state. + * + * Clear bits in the @supported and @state->advertising masks that + * are not supportable by the MAC. + * + * Note that the PHY may be able to transform from one connection + * technology to another, so, eg, don't clear 1000BaseX just + * because the MAC is unable to BaseX mode. This is more about + * clearing unsupported speeds and duplex settings. + * + * If the @state->interface mode is %PHY_INTERFACE_MODE_1000BASEX + * or %PHY_INTERFACE_MODE_2500BASEX, select the appropriate mode + * based on @state->advertising and/or @state->speed and update + * @state->interface accordingly. + */ +void validate(struct net_device *ndev, unsigned long *supported, +	      struct phylink_link_state *state); + +/** + * mac_link_state() - Read the current link state from the hardware + * @ndev: a pointer to a &struct net_device for the MAC. + * @state: a pointer to a &struct phylink_link_state. + * + * Read the current link state from the MAC, reporting the current + * speed in @state->speed, duplex mode in @state->duplex, pause mode + * in @state->pause using the %MLO_PAUSE_RX and %MLO_PAUSE_TX bits, + * negotiation completion state in @state->an_complete, and link + * up state in @state->link. + */ +int mac_link_state(struct net_device *ndev, +		   struct phylink_link_state *state); + +/** + * mac_config() - configure the MAC for the selected mode and state + * @ndev: a pointer to a &struct net_device for the MAC. + * @mode: one of %MLO_AN_FIXED, %MLO_AN_PHY, %MLO_AN_INBAND. + * @state: a pointer to a &struct phylink_link_state. + * + * The action performed depends on the currently selected mode: + * + * %MLO_AN_FIXED, %MLO_AN_PHY: + *   Configure the specified @state->speed, @state->duplex and + *   @state->pause (%MLO_PAUSE_TX / %MLO_PAUSE_RX) mode. + * + * %MLO_AN_INBAND: + *   place the link in an inband negotiation mode (such as 802.3z + *   1000base-X or Cisco SGMII mode depending on the @state->interface + *   mode). In both cases, link state management (whether the link + *   is up or not) is performed by the MAC, and reported via the + *   mac_link_state() callback. Changes in link state must be made + *   by calling phylink_mac_change(). + * + *   If in 802.3z mode, the link speed is fixed, dependent on the + *   @state->interface. Duplex is negotiated, and pause is advertised + *   according to @state->an_enabled, @state->pause and + *   @state->advertising flags. Beware of MACs which only support full + *   duplex at gigabit and higher speeds. + * + *   If in Cisco SGMII mode, the link speed and duplex mode are passed + *   in the serial bitstream 16-bit configuration word, and the MAC + *   should be configured to read these bits and acknowledge the + *   configuration word. Nothing is advertised by the MAC. The MAC is + *   responsible for reading the configuration word and configuring + *   itself accordingly. + */ +void mac_config(struct net_device *ndev, unsigned int mode, +		const struct phylink_link_state *state); + +/** + * mac_an_restart() - restart 802.3z BaseX autonegotiation + * @ndev: a pointer to a &struct net_device for the MAC. + */ +void mac_an_restart(struct net_device *ndev); + +/** + * mac_link_down() - take the link down + * @ndev: a pointer to a &struct net_device for the MAC. + * @mode: link autonegotiation mode + * + * If @mode is not an in-band negotiation mode (as defined by + * phylink_autoneg_inband()), force the link down and disable any + * Energy Efficient Ethernet MAC configuration. + */ +void mac_link_down(struct net_device *ndev, unsigned int mode); + +/** + * mac_link_up() - allow the link to come up + * @ndev: a pointer to a &struct net_device for the MAC. + * @mode: link autonegotiation mode + * @phy: any attached phy + * + * If @mode is not an in-band negotiation mode (as defined by + * phylink_autoneg_inband()), allow the link to come up. If @phy + * is non-%NULL, configure Energy Efficient Ethernet by calling + * phy_init_eee() and perform appropriate MAC configuration for EEE. + */ +void mac_link_up(struct net_device *ndev, unsigned int mode, +		 struct phy_device *phy); +#endif + +struct phylink *phylink_create(struct net_device *, struct fwnode_handle *,  	phy_interface_t iface, const struct phylink_mac_ops *ops);  void phylink_destroy(struct phylink *);  int phylink_connect_phy(struct phylink *, struct phy_device *); -int phylink_of_phy_connect(struct phylink *, struct device_node *); +int phylink_of_phy_connect(struct phylink *, struct device_node *, u32 flags);  void phylink_disconnect_phy(struct phylink *); +int phylink_fixed_state_cb(struct phylink *, +			   void (*cb)(struct net_device *dev, +				      struct phylink_link_state *));  void phylink_mac_change(struct phylink *, bool up); @@ -128,7 +214,6 @@ int phylink_ethtool_set_pauseparam(struct phylink *,  int phylink_ethtool_get_module_info(struct phylink *, struct ethtool_modinfo *);  int phylink_ethtool_get_module_eeprom(struct phylink *,  				      struct ethtool_eeprom *, u8 *); -int phylink_init_eee(struct phylink *, bool);  int phylink_get_eee_err(struct phylink *);  int phylink_ethtool_get_eee(struct phylink *, struct ethtool_eee *);  int phylink_ethtool_set_eee(struct phylink *, struct ethtool_eee *);  |