qede: Add ethtool support for Energy efficient ethernet.
authorSudarsana Reddy Kalluru <sudarsana.kalluru@cavium.com>
Wed, 26 Jul 2017 13:07:12 +0000 (06:07 -0700)
committerDavid S. Miller <davem@davemloft.net>
Thu, 27 Jul 2017 07:05:22 +0000 (00:05 -0700)
The patch adds ethtool callback implementations for querying/configuring
the Energy Efficient Ethernet (EEE) parameters.

Signed-off-by: Sudarsana Reddy Kalluru <Sudarsana.Kalluru@cavium.com>
Signed-off-by: Yuval Mintz <yuval.mintz@cavium.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/qlogic/qede/qede_ethtool.c

index e31266d..55fa2ef 100644 (file)
@@ -1631,6 +1631,87 @@ static int qede_get_tunable(struct net_device *dev,
        return 0;
 }
 
+static int qede_get_eee(struct net_device *dev, struct ethtool_eee *edata)
+{
+       struct qede_dev *edev = netdev_priv(dev);
+       struct qed_link_output current_link;
+
+       memset(&current_link, 0, sizeof(current_link));
+       edev->ops->common->get_link(edev->cdev, &current_link);
+
+       if (!current_link.eee_supported) {
+               DP_INFO(edev, "EEE is not supported\n");
+               return -EOPNOTSUPP;
+       }
+
+       if (current_link.eee.adv_caps & QED_EEE_1G_ADV)
+               edata->advertised = ADVERTISED_1000baseT_Full;
+       if (current_link.eee.adv_caps & QED_EEE_10G_ADV)
+               edata->advertised |= ADVERTISED_10000baseT_Full;
+       if (current_link.sup_caps & QED_EEE_1G_ADV)
+               edata->supported = ADVERTISED_1000baseT_Full;
+       if (current_link.sup_caps & QED_EEE_10G_ADV)
+               edata->supported |= ADVERTISED_10000baseT_Full;
+       if (current_link.eee.lp_adv_caps & QED_EEE_1G_ADV)
+               edata->lp_advertised = ADVERTISED_1000baseT_Full;
+       if (current_link.eee.lp_adv_caps & QED_EEE_10G_ADV)
+               edata->lp_advertised |= ADVERTISED_10000baseT_Full;
+
+       edata->tx_lpi_timer = current_link.eee.tx_lpi_timer;
+       edata->eee_enabled = current_link.eee.enable;
+       edata->tx_lpi_enabled = current_link.eee.tx_lpi_enable;
+       edata->eee_active = current_link.eee_active;
+
+       return 0;
+}
+
+static int qede_set_eee(struct net_device *dev, struct ethtool_eee *edata)
+{
+       struct qede_dev *edev = netdev_priv(dev);
+       struct qed_link_output current_link;
+       struct qed_link_params params;
+
+       if (!edev->ops->common->can_link_change(edev->cdev)) {
+               DP_INFO(edev, "Link settings are not allowed to be changed\n");
+               return -EOPNOTSUPP;
+       }
+
+       memset(&current_link, 0, sizeof(current_link));
+       edev->ops->common->get_link(edev->cdev, &current_link);
+
+       if (!current_link.eee_supported) {
+               DP_INFO(edev, "EEE is not supported\n");
+               return -EOPNOTSUPP;
+       }
+
+       memset(&params, 0, sizeof(params));
+       params.override_flags |= QED_LINK_OVERRIDE_EEE_CONFIG;
+
+       if (!(edata->advertised & (ADVERTISED_1000baseT_Full |
+                                  ADVERTISED_10000baseT_Full)) ||
+           ((edata->advertised & (ADVERTISED_1000baseT_Full |
+                                  ADVERTISED_10000baseT_Full)) !=
+            edata->advertised)) {
+               DP_VERBOSE(edev, QED_MSG_DEBUG,
+                          "Invalid advertised capabilities %d\n",
+                          edata->advertised);
+               return -EINVAL;
+       }
+
+       if (edata->advertised & ADVERTISED_1000baseT_Full)
+               params.eee.adv_caps = QED_EEE_1G_ADV;
+       if (edata->advertised & ADVERTISED_10000baseT_Full)
+               params.eee.adv_caps |= QED_EEE_10G_ADV;
+       params.eee.enable = edata->eee_enabled;
+       params.eee.tx_lpi_enable = edata->tx_lpi_enabled;
+       params.eee.tx_lpi_timer = edata->tx_lpi_timer;
+
+       params.link_up = true;
+       edev->ops->common->set_link(edev->cdev, &params);
+
+       return 0;
+}
+
 static const struct ethtool_ops qede_ethtool_ops = {
        .get_link_ksettings = qede_get_link_ksettings,
        .set_link_ksettings = qede_set_link_ksettings,
@@ -1664,6 +1745,9 @@ static const struct ethtool_ops qede_ethtool_ops = {
        .get_channels = qede_get_channels,
        .set_channels = qede_set_channels,
        .self_test = qede_self_test,
+       .get_eee = qede_get_eee,
+       .set_eee = qede_set_eee,
+
        .get_tunable = qede_get_tunable,
        .set_tunable = qede_set_tunable,
 };