ethdev: support dynamic configuration of QinQ strip
authorVivek Sharma <viveksharma@marvell.com>
Tue, 2 Jul 2019 03:37:07 +0000 (09:07 +0530)
committerFerruh Yigit <ferruh.yigit@intel.com>
Thu, 4 Jul 2019 23:52:01 +0000 (01:52 +0200)
Enable missing support for runtime configuration (setting/getting)
of QinQ strip rx offload for a given ethdev.

Signed-off-by: Vivek Sharma <viveksharma@marvell.com>
Acked-by: Andrew Rybchenko <arybchenko@solarflare.com>
lib/librte_ethdev/rte_ethdev.c
lib/librte_ethdev/rte_ethdev.h

index 31f02ec..6419173 100644 (file)
@@ -2733,53 +2733,56 @@ rte_eth_dev_set_vlan_offload(uint16_t port_id, int offload_mask)
        int mask = 0;
        int cur, org = 0;
        uint64_t orig_offloads;
+       uint64_t *dev_offloads;
 
        RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
        dev = &rte_eth_devices[port_id];
 
        /* save original values in case of failure */
        orig_offloads = dev->data->dev_conf.rxmode.offloads;
+       dev_offloads = &dev->data->dev_conf.rxmode.offloads;
 
        /*check which option changed by application*/
        cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
-       org = !!(dev->data->dev_conf.rxmode.offloads &
-                DEV_RX_OFFLOAD_VLAN_STRIP);
+       org = !!(*dev_offloads & DEV_RX_OFFLOAD_VLAN_STRIP);
        if (cur != org) {
                if (cur)
-                       dev->data->dev_conf.rxmode.offloads |=
-                               DEV_RX_OFFLOAD_VLAN_STRIP;
+                       *dev_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
                else
-                       dev->data->dev_conf.rxmode.offloads &=
-                               ~DEV_RX_OFFLOAD_VLAN_STRIP;
+                       *dev_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
                mask |= ETH_VLAN_STRIP_MASK;
        }
 
        cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
-       org = !!(dev->data->dev_conf.rxmode.offloads &
-                DEV_RX_OFFLOAD_VLAN_FILTER);
+       org = !!(*dev_offloads & DEV_RX_OFFLOAD_VLAN_FILTER);
        if (cur != org) {
                if (cur)
-                       dev->data->dev_conf.rxmode.offloads |=
-                               DEV_RX_OFFLOAD_VLAN_FILTER;
+                       *dev_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
                else
-                       dev->data->dev_conf.rxmode.offloads &=
-                               ~DEV_RX_OFFLOAD_VLAN_FILTER;
+                       *dev_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
                mask |= ETH_VLAN_FILTER_MASK;
        }
 
        cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
-       org = !!(dev->data->dev_conf.rxmode.offloads &
-                DEV_RX_OFFLOAD_VLAN_EXTEND);
+       org = !!(*dev_offloads & DEV_RX_OFFLOAD_VLAN_EXTEND);
        if (cur != org) {
                if (cur)
-                       dev->data->dev_conf.rxmode.offloads |=
-                               DEV_RX_OFFLOAD_VLAN_EXTEND;
+                       *dev_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
                else
-                       dev->data->dev_conf.rxmode.offloads &=
-                               ~DEV_RX_OFFLOAD_VLAN_EXTEND;
+                       *dev_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
                mask |= ETH_VLAN_EXTEND_MASK;
        }
 
+       cur = !!(offload_mask & ETH_QINQ_STRIP_OFFLOAD);
+       org = !!(*dev_offloads & DEV_RX_OFFLOAD_QINQ_STRIP);
+       if (cur != org) {
+               if (cur)
+                       *dev_offloads |= DEV_RX_OFFLOAD_QINQ_STRIP;
+               else
+                       *dev_offloads &= ~DEV_RX_OFFLOAD_QINQ_STRIP;
+               mask |= ETH_QINQ_STRIP_MASK;
+       }
+
        /*no change*/
        if (mask == 0)
                return ret;
@@ -2788,7 +2791,7 @@ rte_eth_dev_set_vlan_offload(uint16_t port_id, int offload_mask)
        ret = (*dev->dev_ops->vlan_offload_set)(dev, mask);
        if (ret) {
                /* hit an error restore  original values */
-               dev->data->dev_conf.rxmode.offloads = orig_offloads;
+               *dev_offloads = orig_offloads;
        }
 
        return eth_err(port_id, ret);
@@ -2798,23 +2801,25 @@ int
 rte_eth_dev_get_vlan_offload(uint16_t port_id)
 {
        struct rte_eth_dev *dev;
+       uint64_t *dev_offloads;
        int ret = 0;
 
        RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
        dev = &rte_eth_devices[port_id];
+       dev_offloads = &dev->data->dev_conf.rxmode.offloads;
 
-       if (dev->data->dev_conf.rxmode.offloads &
-           DEV_RX_OFFLOAD_VLAN_STRIP)
+       if (*dev_offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
                ret |= ETH_VLAN_STRIP_OFFLOAD;
 
-       if (dev->data->dev_conf.rxmode.offloads &
-           DEV_RX_OFFLOAD_VLAN_FILTER)
+       if (*dev_offloads & DEV_RX_OFFLOAD_VLAN_FILTER)
                ret |= ETH_VLAN_FILTER_OFFLOAD;
 
-       if (dev->data->dev_conf.rxmode.offloads &
-           DEV_RX_OFFLOAD_VLAN_EXTEND)
+       if (*dev_offloads & DEV_RX_OFFLOAD_VLAN_EXTEND)
                ret |= ETH_VLAN_EXTEND_OFFLOAD;
 
+       if (*dev_offloads & DEV_RX_OFFLOAD_QINQ_STRIP)
+               ret |= DEV_RX_OFFLOAD_QINQ_STRIP;
+
        return ret;
 }
 
index c852126..dc6596b 100644 (file)
@@ -584,11 +584,13 @@ struct rte_eth_rss_conf {
 #define ETH_VLAN_STRIP_OFFLOAD   0x0001 /**< VLAN Strip  On/Off */
 #define ETH_VLAN_FILTER_OFFLOAD  0x0002 /**< VLAN Filter On/Off */
 #define ETH_VLAN_EXTEND_OFFLOAD  0x0004 /**< VLAN Extend On/Off */
+#define ETH_QINQ_STRIP_OFFLOAD   0x0008 /**< QINQ Strip On/Off */
 
 /* Definitions used for mask VLAN setting */
 #define ETH_VLAN_STRIP_MASK   0x0001 /**< VLAN Strip  setting mask */
 #define ETH_VLAN_FILTER_MASK  0x0002 /**< VLAN Filter  setting mask*/
 #define ETH_VLAN_EXTEND_MASK  0x0004 /**< VLAN Extend  setting mask*/
+#define ETH_QINQ_STRIP_MASK   0x0008 /**< QINQ Strip  setting mask */
 #define ETH_VLAN_ID_MAX       0x0FFF /**< VLAN ID is in lower 12 bits*/
 
 /* Definitions used for receive MAC address   */
@@ -1017,7 +1019,8 @@ struct rte_eth_conf {
                                 DEV_RX_OFFLOAD_TCP_CKSUM)
 #define DEV_RX_OFFLOAD_VLAN (DEV_RX_OFFLOAD_VLAN_STRIP | \
                             DEV_RX_OFFLOAD_VLAN_FILTER | \
-                            DEV_RX_OFFLOAD_VLAN_EXTEND)
+                            DEV_RX_OFFLOAD_VLAN_EXTEND | \
+                            DEV_RX_OFFLOAD_QINQ_STRIP)
 
 /*
  * If new Rx offload capabilities are defined, they also must be
@@ -2540,6 +2543,7 @@ int rte_eth_dev_set_vlan_ether_type(uint16_t port_id,
  *       ETH_VLAN_STRIP_OFFLOAD
  *       ETH_VLAN_FILTER_OFFLOAD
  *       ETH_VLAN_EXTEND_OFFLOAD
+ *       ETH_QINQ_STRIP_OFFLOAD
  * @return
  *   - (0) if successful.
  *   - (-ENOSUP) if hardware-assisted VLAN filtering not configured.
@@ -2558,6 +2562,7 @@ int rte_eth_dev_set_vlan_offload(uint16_t port_id, int offload_mask);
  *       ETH_VLAN_STRIP_OFFLOAD
  *       ETH_VLAN_FILTER_OFFLOAD
  *       ETH_VLAN_EXTEND_OFFLOAD
+ *       ETH_QINQ_STRIP_OFFLOAD
  *   - (-ENODEV) if *port_id* invalid.
  */
 int rte_eth_dev_get_vlan_offload(uint16_t port_id);