[dpdk-dev,v2,10/32] net/i40e: implement ops for VF stats get/reset

Message ID 1481081535-37448-11-git-send-email-wenzhuo.lu@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Ferruh Yigit
Headers

Checks

Context Check Description
checkpatch/checkpatch success coding style OK

Commit Message

Wenzhuo Lu Dec. 7, 2016, 3:31 a.m. UTC
  This patch implement vf_stats_get and vf_stats_reset ops for i40e.

Signed-off-by: Qi Zhang <qi.z.zhang@intel.com>
---
 drivers/net/i40e/i40e_ethdev.c | 64 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 64 insertions(+)
  

Comments

Ferruh Yigit Dec. 7, 2016, 1:59 p.m. UTC | #1
On 12/7/2016 3:31 AM, Wenzhuo Lu wrote:
> This patch implement vf_stats_get and vf_stats_reset ops for i40e.
> 
> Signed-off-by: Qi Zhang <qi.z.zhang@intel.com>
> ---
<...>

> +static int
> +i40e_vf_stats_get(struct rte_eth_dev *dev,
> +		  uint16_t vf,
> +		  struct rte_eth_stats *stats)
> +{
> +	struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
> +	struct i40e_vsi *vsi;
> +
> +	int ret = 0;
> +
> +	if (pf->vf_num <= vf) {
> +		PMD_DRV_LOG(ERR, "Invalid VF id %d\n", vf);
> +		return -EINVAL;
> +	}

Do we need following check as it has been done in prev patches:

+	rte_eth_dev_info_get(port, &dev_info);
+
+	if (vf_id >= dev_info.max_vfs)
+		return -EINVAL;
  

Patch

diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
index 88ff6aa..5c9d6d1 100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -462,6 +462,13 @@  static void i40e_set_default_mac_addr(struct rte_eth_dev *dev,
 
 static int i40e_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
 
+static int i40e_vf_stats_get(struct rte_eth_dev *dev,
+			     uint16_t vf,
+			     struct rte_eth_stats *stats);
+
+static int i40e_vf_stats_reset(struct rte_eth_dev *dev,
+			       uint16_t vf);
+
 static const struct rte_pci_id pci_id_i40e_map[] = {
 	{ RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_XL710) },
 	{ RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QEMU) },
@@ -554,6 +561,8 @@  static void i40e_set_default_mac_addr(struct rte_eth_dev *dev,
 	.get_eeprom                   = i40e_get_eeprom,
 	.mac_addr_set                 = i40e_set_default_mac_addr,
 	.mtu_set                      = i40e_dev_mtu_set,
+	.vf_stats_get                 = i40e_vf_stats_get,
+	.vf_stats_reset               = i40e_vf_stats_reset,
 };
 
 /* store statistics names and its offset in stats structure */
@@ -10229,3 +10238,58 @@  static void i40e_set_default_mac_addr(struct rte_eth_dev *dev,
 
 	return ret;
 }
+
+static int
+i40e_vf_stats_get(struct rte_eth_dev *dev,
+		  uint16_t vf,
+		  struct rte_eth_stats *stats)
+{
+	struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
+	struct i40e_vsi *vsi;
+
+	int ret = 0;
+
+	if (pf->vf_num <= vf) {
+		PMD_DRV_LOG(ERR, "Invalid VF id %d\n", vf);
+		return -EINVAL;
+	}
+
+	vsi = pf->vfs[vf].vsi;
+
+	i40e_update_vsi_stats(vsi);
+
+	stats->ipackets = vsi->eth_stats.rx_unicast +
+			vsi->eth_stats.rx_multicast +
+			vsi->eth_stats.rx_broadcast;
+	stats->opackets = vsi->eth_stats.tx_unicast +
+			vsi->eth_stats.tx_multicast +
+			vsi->eth_stats.tx_broadcast;
+	stats->ibytes   = vsi->eth_stats.rx_bytes;
+	stats->obytes   = vsi->eth_stats.tx_bytes;
+	stats->ierrors  = vsi->eth_stats.rx_discards;
+	stats->oerrors  = vsi->eth_stats.tx_errors + vsi->eth_stats.tx_discards;
+
+	return ret;
+}
+
+static int
+i40e_vf_stats_reset(struct rte_eth_dev *dev,
+		    uint16_t vf)
+{
+	struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
+	struct i40e_vsi *vsi;
+
+	int ret = 0;
+
+	if (pf->vf_num <= vf) {
+		PMD_DRV_LOG(ERR, "Invalid VF id %d\n", vf);
+		return -EINVAL;
+	}
+
+	vsi = pf->vfs[vf].vsi;
+
+	vsi->offset_loaded = false;
+	i40e_update_vsi_stats(vsi);
+
+	return ret;
+}