net/i40e: set VF max bandwidth from PF
authorWenzhuo Lu <wenzhuo.lu@intel.com>
Fri, 24 Feb 2017 03:24:28 +0000 (11:24 +0800)
committerFerruh Yigit <ferruh.yigit@intel.com>
Tue, 4 Apr 2017 16:59:50 +0000 (18:59 +0200)
Support setting VF max bandwidth from PF.
User can call the API on PF to set a specific VF's
max bandwidth.

Signed-off-by: Wenzhuo Lu <wenzhuo.lu@intel.com>
Acked-by: Jingjing Wu <jingjing.wu@intel.com>
doc/guides/rel_notes/release_17_05.rst
drivers/net/i40e/i40e_ethdev.c
drivers/net/i40e/rte_pmd_i40e.h
drivers/net/i40e/rte_pmd_i40e_version.map

index 2c21a71..bce1b15 100644 (file)
@@ -79,6 +79,10 @@ New Features
 
   i40e PMD and its vector PMD enabled by default in powerpc.
 
+* **Added VF max bandwidth setting on i40e.**
+
+  i40e HW supports to set the max bandwidth for a VF. Enable this capability.
+
 * **Added TSO support for tunneled and non-tunneled packets on mlx5 driver.**
 
   Added support for Hardware TSO for tunneled and non-tunneled packets.
index 5e80f46..bfcbc4b 100644 (file)
 /* Bit mask of Extended Tag enable/disable */
 #define PCI_DEV_CTRL_EXT_TAG_MASK  (1 << PCI_DEV_CTRL_EXT_TAG_SHIFT)
 
+/* The max bandwidth of i40e is 40Gbps. */
+#define I40E_QOS_BW_MAX 40000
+/* The bandwidth should be the multiple of 50Mbps. */
+#define I40E_QOS_BW_GRANULARITY 50
+
 static int eth_i40e_dev_init(struct rte_eth_dev *eth_dev);
 static int eth_i40e_dev_uninit(struct rte_eth_dev *eth_dev);
 static int i40e_dev_configure(struct rte_eth_dev *dev);
@@ -11261,3 +11266,92 @@ rte_pmd_i40e_reset_vf_stats(uint8_t port,
 
        return 0;
 }
+
+int
+rte_pmd_i40e_set_vf_max_bw(uint8_t port, uint16_t vf_id, uint32_t bw)
+{
+       struct rte_eth_dev *dev;
+       struct i40e_pf *pf;
+       struct i40e_vsi *vsi;
+       struct i40e_hw *hw;
+       int ret = 0;
+       int i;
+
+       RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
+
+       dev = &rte_eth_devices[port];
+
+       if (!is_device_supported(dev, &rte_i40e_pmd))
+               return -ENOTSUP;
+
+       pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
+
+       if (vf_id >= pf->vf_num || !pf->vfs) {
+               PMD_DRV_LOG(ERR, "Invalid VF ID.");
+               return -EINVAL;
+       }
+
+       vsi = pf->vfs[vf_id].vsi;
+       if (!vsi) {
+               PMD_DRV_LOG(ERR, "Invalid VSI.");
+               return -EINVAL;
+       }
+
+       if (bw > I40E_QOS_BW_MAX) {
+               PMD_DRV_LOG(ERR, "Bandwidth should not be larger than %dMbps.",
+                           I40E_QOS_BW_MAX);
+               return -EINVAL;
+       }
+
+       if (bw % I40E_QOS_BW_GRANULARITY) {
+               PMD_DRV_LOG(ERR, "Bandwidth should be the multiple of %dMbps.",
+                           I40E_QOS_BW_GRANULARITY);
+               return -EINVAL;
+       }
+
+       bw /= I40E_QOS_BW_GRANULARITY;
+
+       hw = I40E_VSI_TO_HW(vsi);
+
+       /* No change. */
+       if (bw == vsi->bw_info.bw_limit) {
+               PMD_DRV_LOG(INFO,
+                           "No change for VF max bandwidth. Nothing to do.");
+               return 0;
+       }
+
+       /**
+        * VF bandwidth limitation and TC bandwidth limitation cannot be
+        * enabled in parallel, quit if TC bandwidth limitation is enabled.
+        *
+        * If bw is 0, means disable bandwidth limitation. Then no need to
+        * check TC bandwidth limitation.
+        */
+       if (bw) {
+               for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
+                       if ((vsi->enabled_tc & BIT_ULL(i)) &&
+                           vsi->bw_info.bw_ets_credits[i])
+                               break;
+               }
+               if (i != I40E_MAX_TRAFFIC_CLASS) {
+                       PMD_DRV_LOG(ERR,
+                                   "TC max bandwidth has been set on this VF,"
+                                   " please disable it first.");
+                       return -EINVAL;
+               }
+       }
+
+       ret = i40e_aq_config_vsi_bw_limit(hw, vsi->seid, (uint16_t)bw, 0, NULL);
+       if (ret) {
+               PMD_DRV_LOG(ERR,
+                           "Failed to set VF %d bandwidth, err(%d).",
+                           vf_id, ret);
+               return -EINVAL;
+       }
+
+       /* Store the configuration. */
+       vsi->bw_info.bw_limit = (uint16_t)bw;
+       vsi->bw_info.bw_max = 0;
+
+       return 0;
+}
index a0ad88c..224ec4f 100644 (file)
@@ -332,4 +332,27 @@ int rte_pmd_i40e_get_vf_stats(uint8_t port,
 int rte_pmd_i40e_reset_vf_stats(uint8_t port,
                                uint16_t vf_id);
 
+/**
+ * Set VF's max bandwidth.
+ *
+ * Per VF bandwidth limitation and per TC bandwidth limitation cannot
+ * be enabled in parallel. If per TC bandwidth is enabled, this function
+ * will disable it.
+ *
+ * @param port
+ *    The port identifier of the Ethernet device.
+ * @param vf_id
+ *    ID specifying VF.
+ * @param bw
+ *    Bandwidth for this VF.
+ * @return
+ *   - (0) if successful.
+ *   - (-ENODEV) if *port* invalid.
+ *   - (-EINVAL) if bad parameter.
+ *   - (-ENOTSUP) not supported by firmware.
+ */
+int rte_pmd_i40e_set_vf_max_bw(uint8_t port,
+                              uint16_t vf_id,
+                              uint32_t bw);
+
 #endif /* _PMD_I40E_H_ */
index 7a5d211..1d9dcf8 100644 (file)
@@ -22,3 +22,10 @@ DPDK_17.02 {
        rte_pmd_i40e_set_vf_vlan_tag;
 
 } DPDK_2.0;
+
+DPDK_17.05 {
+       global:
+
+       rte_pmd_i40e_set_vf_max_bw;
+
+} DPDK_17.02;