[PATCH iwl-next v2 5/6] ixgbe: move EEE config validation out of ixgbe_set_eee()

Jedrzej Jagielski
2026-01-20T14:02:33Z

To make this part of the code mode reusable move all
EEE input checks out of ixgbe_set_eee().

Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
Signed-off-by: Jedrzej Jagielski <jedrzej.jagielski@intel.com>
---
v2: add comment on returning EALREADY
---
.../net/ethernet/intel/ixgbe/ixgbe_ethtool.c | 98 +++++++++++--------
1 file changed, 57 insertions(+), 41 deletions(-)

diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
index 779e2425e4aa..b5b9b9335d52 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
@@ -3556,6 +3556,47 @@ static const struct {
{ FW_PHY_ACT_UD_2_10G_KR_EEE, ETHTOOL_LINK_MODE_10000baseKR_Full_BIT},
};

+static int ixgbe_validate_keee(struct net_device *netdev,
+ struct ethtool_keee *keee_requested)
+{
+ struct ixgbe_adapter *adapter = ixgbe_from_netdev(netdev);
+ struct ethtool_keee keee_stored = {};
+ int err;
+
+ if (!(adapter->flags2 & IXGBE_FLAG2_EEE_CAPABLE))
+ return -EOPNOTSUPP;
+
+ err = netdev->ethtool_ops->get_eee(netdev, &keee_stored);
+ if (err)
+ return err;
+
+ if (keee_stored.tx_lpi_enabled != keee_requested->tx_lpi_enabled) {
+ e_err(drv, "Setting EEE tx-lpi is not supported\n");
+ return -EINVAL;
+ }
+
+ if (keee_stored.tx_lpi_timer != keee_requested->tx_lpi_timer) {
+ e_err(drv,
+ "Setting EEE Tx LPI timer is not supported\n");
+ return -EINVAL;
+ }
+
+ if (!linkmode_equal(keee_stored.advertised,
+ keee_requested->advertised)) {
+ e_err(drv,
+ "Setting EEE advertised speeds is not supported\n");
+ return -EINVAL;
+ }
+
+ /* -EALREADY here is for internal use only, must be converted into
+ * early bail out with 0 by caller
+ */
+ if (keee_stored.eee_enabled == keee_requested->eee_enabled)
+ return -EALREADY;
+
+ return 0;
+}
+
static int
ixgbe_get_eee_fw(struct ixgbe_adapter *adapter, struct ethtool_keee *edata)
{
@@ -3614,53 +3655,28 @@ static int ixgbe_set_eee(struct net_device *netdev, struct ethtool_keee *edata)
{
struct ixgbe_adapter *adapter = ixgbe_from_netdev(netdev);
struct ixgbe_hw *hw = &adapter->hw;
- struct ethtool_keee eee_data;
int ret_val;

- if (!(adapter->flags2 & IXGBE_FLAG2_EEE_CAPABLE))
- return -EOPNOTSUPP;
-
- memset(&eee_data, 0, sizeof(struct ethtool_keee));
-
- ret_val = ixgbe_get_eee(netdev, &eee_data);
- if (ret_val)
+ ret_val = ixgbe_validate_keee(netdev, edata);
+ if (ret_val == -EALREADY)
+ return 0;
+ else if (ret_val)
return ret_val;

- if (eee_data.eee_enabled && !edata->eee_enabled) {
- if (eee_data.tx_lpi_enabled != edata->tx_lpi_enabled) {
- e_err(drv, "Setting EEE tx-lpi is not supported\n");
- return -EINVAL;
- }
-
- if (eee_data.tx_lpi_timer != edata->tx_lpi_timer) {
- e_err(drv,
- "Setting EEE Tx LPI timer is not supported\n");
- return -EINVAL;
- }
-
- if (!linkmode_equal(eee_data.advertised, edata->advertised)) {
- e_err(drv,
- "Setting EEE advertised speeds is not supported\n");
- return -EINVAL;
- }
+ if (edata->eee_enabled) {
+ adapter->flags2 |= IXGBE_FLAG2_EEE_ENABLED;
+ hw->phy.eee_speeds_advertised =
+ hw->phy.eee_speeds_supported;
+ } else {
+ adapter->flags2 &= ~IXGBE_FLAG2_EEE_ENABLED;
+ hw->phy.eee_speeds_advertised = 0;
}

- if (eee_data.eee_enabled != edata->eee_enabled) {
- if (edata->eee_enabled) {
- adapter->flags2 |= IXGBE_FLAG2_EEE_ENABLED;
- hw->phy.eee_speeds_advertised =
- hw->phy.eee_speeds_supported;
- } else {
- adapter->flags2 &= ~IXGBE_FLAG2_EEE_ENABLED;
- hw->phy.eee_speeds_advertised = 0;
- }
-
- /* reset link */
- if (netif_running(netdev))
- ixgbe_reinit_locked(adapter);
- else
- ixgbe_reset(adapter);
- }
+ /* reset link */
+ if (netif_running(netdev))
+ ixgbe_reinit_locked(adapter);
+ else
+ ixgbe_reset(adapter);

return 0;
}
--
2.31.1