cxgb4vf: define get_fecparam ethtool callback
authorGanesh Goudar <ganeshgr@chelsio.com>
Thu, 2 Nov 2017 13:58:20 +0000 (19:28 +0530)
committerDavid S. Miller <davem@davemloft.net>
Fri, 3 Nov 2017 06:45:40 +0000 (15:45 +0900)
Add support to new ethtool operation get_fecparam to
fetch FEC parameters.

Original Work by: Casey Leedom <leedom@chelsio.com>
Signed-off-by: Ganesh Goudar <ganeshgr@chelsio.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/chelsio/cxgb4vf/cxgb4vf_main.c

index 8996ebbd222e0834c71bfa4c8165a9e5533847aa..b48361cfdc78f98f4b4159ba8f76cbcaf1cedcc7 100644 (file)
@@ -1401,6 +1401,63 @@ static int cxgb4vf_get_link_ksettings(struct net_device *dev,
        return 0;
 }
 
+/* Translate the Firmware FEC value into the ethtool value. */
+static inline unsigned int fwcap_to_eth_fec(unsigned int fw_fec)
+{
+       unsigned int eth_fec = 0;
+
+       if (fw_fec & FW_PORT_CAP32_FEC_RS)
+               eth_fec |= ETHTOOL_FEC_RS;
+       if (fw_fec & FW_PORT_CAP32_FEC_BASER_RS)
+               eth_fec |= ETHTOOL_FEC_BASER;
+
+       /* if nothing is set, then FEC is off */
+       if (!eth_fec)
+               eth_fec = ETHTOOL_FEC_OFF;
+
+       return eth_fec;
+}
+
+/* Translate Common Code FEC value into ethtool value. */
+static inline unsigned int cc_to_eth_fec(unsigned int cc_fec)
+{
+       unsigned int eth_fec = 0;
+
+       if (cc_fec & FEC_AUTO)
+               eth_fec |= ETHTOOL_FEC_AUTO;
+       if (cc_fec & FEC_RS)
+               eth_fec |= ETHTOOL_FEC_RS;
+       if (cc_fec & FEC_BASER_RS)
+               eth_fec |= ETHTOOL_FEC_BASER;
+
+       /* if nothing is set, then FEC is off */
+       if (!eth_fec)
+               eth_fec = ETHTOOL_FEC_OFF;
+
+       return eth_fec;
+}
+
+static int cxgb4vf_get_fecparam(struct net_device *dev,
+                               struct ethtool_fecparam *fec)
+{
+       const struct port_info *pi = netdev_priv(dev);
+       const struct link_config *lc = &pi->link_cfg;
+
+       /* Translate the Firmware FEC Support into the ethtool value.  We
+        * always support IEEE 802.3 "automatic" selection of Link FEC type if
+        * any FEC is supported.
+        */
+       fec->fec = fwcap_to_eth_fec(lc->pcaps);
+       if (fec->fec != ETHTOOL_FEC_OFF)
+               fec->fec |= ETHTOOL_FEC_AUTO;
+
+       /* Translate the current internal FEC parameters into the
+        * ethtool values.
+        */
+       fec->active_fec = cc_to_eth_fec(lc->fec);
+       return 0;
+}
+
 /*
  * Return our driver information.
  */
@@ -1774,6 +1831,7 @@ static void cxgb4vf_get_wol(struct net_device *dev,
 
 static const struct ethtool_ops cxgb4vf_ethtool_ops = {
        .get_link_ksettings     = cxgb4vf_get_link_ksettings,
+       .get_fecparam           = cxgb4vf_get_fecparam,
        .get_drvinfo            = cxgb4vf_get_drvinfo,
        .get_msglevel           = cxgb4vf_get_msglevel,
        .set_msglevel           = cxgb4vf_set_msglevel,