mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	net: phy: Immediately call adjust_link if only tx_lpi_enabled changes
The MAC driver changes its EEE hardware configuration in its adjust_link callback. This is called when auto-neg completes. Disabling EEE via eee_enabled false will trigger an autoneg, and as a result the adjust_link callback will be called with phydev->enable_tx_lpi set to false. Similarly, eee_enabled set to true and with a change of advertised link modes will result in a new autoneg, and a call the adjust_link call. If set_eee is called with only a change to tx_lpi_enabled which does not trigger an auto-neg, it is necessary to call the adjust_link callback so that the MAC is reconfigured to take this change into account. When setting phydev->enable_tx_lpi, take both eee_enabled and tx_lpi_enabled into account, so the MAC drivers just needs to act on phydev->enable_tx_lpi and not the whole EEE configuration. The same check should be done for tx_lpi_timer too. Signed-off-by: Andrew Lunn <andrew@lunn.ch> Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Link: https://lore.kernel.org/r/20240302195306.3207716-5-o.rempel@pengutronix.de Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
		
							parent
							
								
									fe0d4fd928
								
							
						
					
					
						commit
						3e43b903da
					
				
					 2 changed files with 49 additions and 5 deletions
				
			
		| 
						 | 
					@ -1550,6 +1550,8 @@ EXPORT_SYMBOL(genphy_c45_ethtool_get_eee);
 | 
				
			||||||
 * advertised, but the previously advertised link modes are
 | 
					 * advertised, but the previously advertised link modes are
 | 
				
			||||||
 * retained. This allows EEE to be enabled/disabled in a
 | 
					 * retained. This allows EEE to be enabled/disabled in a
 | 
				
			||||||
 * non-destructive way.
 | 
					 * non-destructive way.
 | 
				
			||||||
 | 
					 * Returns either error code, 0 if there was no change, or positive
 | 
				
			||||||
 | 
					 * value if there was a change which triggered auto-neg.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
int genphy_c45_ethtool_set_eee(struct phy_device *phydev,
 | 
					int genphy_c45_ethtool_set_eee(struct phy_device *phydev,
 | 
				
			||||||
			       struct ethtool_keee *data)
 | 
								       struct ethtool_keee *data)
 | 
				
			||||||
| 
						 | 
					@ -1576,8 +1578,16 @@ int genphy_c45_ethtool_set_eee(struct phy_device *phydev,
 | 
				
			||||||
	phydev->eee_enabled = data->eee_enabled;
 | 
						phydev->eee_enabled = data->eee_enabled;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ret = genphy_c45_an_config_eee_aneg(phydev);
 | 
						ret = genphy_c45_an_config_eee_aneg(phydev);
 | 
				
			||||||
	if (ret > 0)
 | 
						if (ret > 0) {
 | 
				
			||||||
		return phy_restart_aneg(phydev);
 | 
							ret = phy_restart_aneg(phydev);
 | 
				
			||||||
 | 
							if (ret < 0)
 | 
				
			||||||
 | 
								return ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							/* explicitly return 1, otherwise (ret > 0) value will be
 | 
				
			||||||
 | 
							 * overwritten by phy_restart_aneg().
 | 
				
			||||||
 | 
							 */
 | 
				
			||||||
 | 
							return 1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return ret;
 | 
						return ret;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -988,7 +988,8 @@ static int phy_check_link_status(struct phy_device *phydev)
 | 
				
			||||||
		if (err < 0)
 | 
							if (err < 0)
 | 
				
			||||||
			phydev->enable_tx_lpi = false;
 | 
								phydev->enable_tx_lpi = false;
 | 
				
			||||||
		else
 | 
							else
 | 
				
			||||||
			phydev->enable_tx_lpi = !!err;
 | 
								phydev->enable_tx_lpi = (err & phydev->eee_cfg.tx_lpi_enabled);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		phy_link_up(phydev);
 | 
							phy_link_up(phydev);
 | 
				
			||||||
	} else if (!phydev->link && phydev->state != PHY_NOLINK) {
 | 
						} else if (!phydev->link && phydev->state != PHY_NOLINK) {
 | 
				
			||||||
		phydev->state = PHY_NOLINK;
 | 
							phydev->state = PHY_NOLINK;
 | 
				
			||||||
| 
						 | 
					@ -1659,6 +1660,36 @@ int phy_ethtool_get_eee(struct phy_device *phydev, struct ethtool_keee *data)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
EXPORT_SYMBOL(phy_ethtool_get_eee);
 | 
					EXPORT_SYMBOL(phy_ethtool_get_eee);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * phy_ethtool_set_eee_noneg - Adjusts MAC LPI configuration without PHY
 | 
				
			||||||
 | 
					 *			       renegotiation
 | 
				
			||||||
 | 
					 * @phydev: pointer to the target PHY device structure
 | 
				
			||||||
 | 
					 * @data: pointer to the ethtool_keee structure containing the new EEE settings
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This function updates the Energy Efficient Ethernet (EEE) configuration
 | 
				
			||||||
 | 
					 * for cases where only the MAC's Low Power Idle (LPI) configuration changes,
 | 
				
			||||||
 | 
					 * without triggering PHY renegotiation. It ensures that the MAC is properly
 | 
				
			||||||
 | 
					 * informed of the new LPI settings by cycling the link down and up, which
 | 
				
			||||||
 | 
					 * is necessary for the MAC to adopt the new configuration. This adjustment
 | 
				
			||||||
 | 
					 * is done only if there is a change in the tx_lpi_enabled or tx_lpi_timer
 | 
				
			||||||
 | 
					 * configuration.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					static void phy_ethtool_set_eee_noneg(struct phy_device *phydev,
 | 
				
			||||||
 | 
									      struct ethtool_keee *data)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (phydev->eee_cfg.tx_lpi_enabled != data->tx_lpi_enabled ||
 | 
				
			||||||
 | 
						    phydev->eee_cfg.tx_lpi_timer != data->tx_lpi_timer) {
 | 
				
			||||||
 | 
							eee_to_eeecfg(&phydev->eee_cfg, data);
 | 
				
			||||||
 | 
							phydev->enable_tx_lpi = eeecfg_mac_can_tx_lpi(&phydev->eee_cfg);
 | 
				
			||||||
 | 
							if (phydev->link) {
 | 
				
			||||||
 | 
								phydev->link = false;
 | 
				
			||||||
 | 
								phy_link_down(phydev);
 | 
				
			||||||
 | 
								phydev->link = true;
 | 
				
			||||||
 | 
								phy_link_up(phydev);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * phy_ethtool_set_eee - set EEE supported and status
 | 
					 * phy_ethtool_set_eee - set EEE supported and status
 | 
				
			||||||
 * @phydev: target phy_device struct
 | 
					 * @phydev: target phy_device struct
 | 
				
			||||||
| 
						 | 
					@ -1675,11 +1706,14 @@ int phy_ethtool_set_eee(struct phy_device *phydev, struct ethtool_keee *data)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	mutex_lock(&phydev->lock);
 | 
						mutex_lock(&phydev->lock);
 | 
				
			||||||
	ret = genphy_c45_ethtool_set_eee(phydev, data);
 | 
						ret = genphy_c45_ethtool_set_eee(phydev, data);
 | 
				
			||||||
	if (!ret)
 | 
						if (ret >= 0) {
 | 
				
			||||||
 | 
							if (ret == 0)
 | 
				
			||||||
 | 
								phy_ethtool_set_eee_noneg(phydev, data);
 | 
				
			||||||
		eee_to_eeecfg(&phydev->eee_cfg, data);
 | 
							eee_to_eeecfg(&phydev->eee_cfg, data);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	mutex_unlock(&phydev->lock);
 | 
						mutex_unlock(&phydev->lock);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return ret;
 | 
						return ret < 0 ? ret : 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
EXPORT_SYMBOL(phy_ethtool_set_eee);
 | 
					EXPORT_SYMBOL(phy_ethtool_set_eee);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue