]> git.droids-corp.org - dpdk.git/commitdiff
net/mlx4: add VLAN filter configuration support
authorAdrien Mazarguil <adrien.mazarguil@6wind.com>
Thu, 12 Oct 2017 12:19:32 +0000 (14:19 +0200)
committerFerruh Yigit <ferruh.yigit@intel.com>
Fri, 13 Oct 2017 00:18:48 +0000 (01:18 +0100)
This commit brings back VLAN filter configuration support without any
artificial limitation on the number of simultaneous VLANs that can be
configured (previously 127).

Also thanks to the fact it does not rely on fixed per-queue arrays for
potential Verbs flow handle storage anymore, this version wastes a lot less
memory (previously 128 * 127 * pointer size, i.e. 130 kiB per Rx queue,
only one of which actually had any use for this room: the RSS parent
queue).

The number of internal flow rules generated still depends on the number of
configured MAC addresses times that of configured VLAN filters though.

Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
Acked-by: Nelio Laranjeiro <nelio.laranjeiro@6wind.com>
doc/guides/nics/features/mlx4.ini
drivers/net/mlx4/mlx4.c
drivers/net/mlx4/mlx4.h
drivers/net/mlx4/mlx4_ethdev.c
drivers/net/mlx4/mlx4_flow.c

index d17774fe4f2bd5e00815068dae9799fab2def652..bfe0eb1228271ab4878cef2e3d92b432b4ae7fea 100644 (file)
@@ -14,6 +14,7 @@ MTU update           = Y
 Jumbo frame          = Y
 Unicast MAC filter   = Y
 SR-IOV               = Y
+VLAN filter          = Y
 Basic stats          = Y
 Stats per queue      = Y
 Other kdrv           = Y
index 99c87fffee6e70e318a11a37a53dcf66a7f57100..e25e9581aa7629e4174ac910a00cc164025fd324 100644 (file)
@@ -227,6 +227,7 @@ static const struct eth_dev_ops mlx4_dev_ops = {
        .stats_get = mlx4_stats_get,
        .stats_reset = mlx4_stats_reset,
        .dev_infos_get = mlx4_dev_infos_get,
+       .vlan_filter_set = mlx4_vlan_filter_set,
        .rx_queue_setup = mlx4_rx_queue_setup,
        .tx_queue_setup = mlx4_tx_queue_setup,
        .rx_queue_release = mlx4_rx_queue_release,
index 15ecd95ff9351ece6f02b0be6d036b1d6310ff25..cc403ead226ec059b0da56ac98c7365737ef1f87 100644 (file)
@@ -128,6 +128,7 @@ void mlx4_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index);
 int mlx4_mac_addr_add(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
                      uint32_t index, uint32_t vmdq);
 void mlx4_mac_addr_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr);
+int mlx4_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on);
 int mlx4_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats);
 void mlx4_stats_reset(struct rte_eth_dev *dev);
 void mlx4_dev_infos_get(struct rte_eth_dev *dev,
index 52924df03e1794a53ba9b1cf6f9bcdf8f876378a..7721f13ed21df3685473820297124f7bda1afa8d 100644 (file)
@@ -587,6 +587,48 @@ mlx4_mac_addr_add(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
        return ret;
 }
 
+/**
+ * DPDK callback to configure a VLAN filter.
+ *
+ * @param dev
+ *   Pointer to Ethernet device structure.
+ * @param vlan_id
+ *   VLAN ID to filter.
+ * @param on
+ *   Toggle filter.
+ *
+ * @return
+ *   0 on success, negative errno value otherwise and rte_errno is set.
+ */
+int
+mlx4_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
+{
+       struct priv *priv = dev->data->dev_private;
+       struct rte_flow_error error;
+       unsigned int vidx = vlan_id / 64;
+       unsigned int vbit = vlan_id % 64;
+       uint64_t *v;
+       int ret;
+
+       if (vidx >= RTE_DIM(dev->data->vlan_filter_conf.ids)) {
+               rte_errno = EINVAL;
+               return -rte_errno;
+       }
+       v = &dev->data->vlan_filter_conf.ids[vidx];
+       *v &= ~(UINT64_C(1) << vbit);
+       *v |= (uint64_t)!!on << vbit;
+       ret = mlx4_flow_sync(priv, &error);
+       if (!ret)
+               return 0;
+       ERROR("failed to synchronize flow rules after %s VLAN filter on ID %u"
+             " (code %d, \"%s\"), "
+             " flow error type %d, cause %p, message: %s",
+             on ? "enabling" : "disabling", vlan_id,
+             rte_errno, strerror(rte_errno), error.type, error.cause,
+             error.message ? error.message : "(unspecified)");
+       return ret;
+}
+
 /**
  * DPDK callback to set the primary MAC address.
  *
index 14d2ed30c5e449174cd1ac95334bcf0bcd875fb2..377b48be75cd38bc9a154df2ab3f28477388178f 100644 (file)
@@ -1008,12 +1008,37 @@ mlx4_flow_flush(struct rte_eth_dev *dev,
        return 0;
 }
 
+/**
+ * Helper function to determine the next configured VLAN filter.
+ *
+ * @param priv
+ *   Pointer to private structure.
+ * @param vlan
+ *   VLAN ID to use as a starting point.
+ *
+ * @return
+ *   Next configured VLAN ID or a high value (>= 4096) if there is none.
+ */
+static uint16_t
+mlx4_flow_internal_next_vlan(struct priv *priv, uint16_t vlan)
+{
+       while (vlan < 4096) {
+               if (priv->dev->data->vlan_filter_conf.ids[vlan / 64] &
+                   (UINT64_C(1) << (vlan % 64)))
+                       return vlan;
+               ++vlan;
+       }
+       return vlan;
+}
+
 /**
  * Generate internal flow rules.
  *
  * - MAC flow rules are generated from @p dev->data->mac_addrs
  *   (@p priv->mac array).
  * - An additional flow rule for Ethernet broadcasts is also generated.
+ * - All these are per-VLAN if @p dev->data->dev_conf.rxmode.hw_vlan_filter
+ *   is enabled and VLAN filters are configured.
  *
  * @param priv
  *   Pointer to private structure.
@@ -1034,6 +1059,10 @@ mlx4_flow_internal(struct priv *priv, struct rte_flow_error *error)
        const struct rte_flow_item_eth eth_mask = {
                .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
        };
+       struct rte_flow_item_vlan vlan_spec;
+       const struct rte_flow_item_vlan vlan_mask = {
+               .tci = RTE_BE16(0x0fff),
+       };
        struct rte_flow_item pattern[] = {
                {
                        .type = MLX4_FLOW_ITEM_TYPE_INTERNAL,
@@ -1043,6 +1072,10 @@ mlx4_flow_internal(struct priv *priv, struct rte_flow_error *error)
                        .spec = &eth_spec,
                        .mask = &eth_mask,
                },
+               {
+                       /* Replaced with VLAN if filtering is enabled. */
+                       .type = RTE_FLOW_ITEM_TYPE_END,
+               },
                {
                        .type = RTE_FLOW_ITEM_TYPE_END,
                },
@@ -1059,10 +1092,33 @@ mlx4_flow_internal(struct priv *priv, struct rte_flow_error *error)
                },
        };
        struct ether_addr *rule_mac = &eth_spec.dst;
+       rte_be16_t *rule_vlan =
+               priv->dev->data->dev_conf.rxmode.hw_vlan_filter ?
+               &vlan_spec.tci :
+               NULL;
+       uint16_t vlan = 0;
        struct rte_flow *flow;
        unsigned int i;
        int err = 0;
 
+       /*
+        * Set up VLAN item if filtering is enabled and at least one VLAN
+        * filter is configured.
+        */
+       if (rule_vlan) {
+               vlan = mlx4_flow_internal_next_vlan(priv, 0);
+               if (vlan < 4096) {
+                       pattern[2] = (struct rte_flow_item){
+                               .type = RTE_FLOW_ITEM_TYPE_VLAN,
+                               .spec = &vlan_spec,
+                               .mask = &vlan_mask,
+                       };
+next_vlan:
+                       *rule_vlan = rte_cpu_to_be_16(vlan);
+               } else {
+                       rule_vlan = NULL;
+               }
+       }
        for (i = 0; i != RTE_DIM(priv->mac) + 1; ++i) {
                const struct ether_addr *mac;
 
@@ -1087,6 +1143,12 @@ mlx4_flow_internal(struct priv *priv, struct rte_flow_error *error)
                        assert(flow->ibv_attr->type == IBV_FLOW_ATTR_NORMAL);
                        assert(flow->ibv_attr->num_of_specs == 1);
                        assert(eth->type == IBV_FLOW_SPEC_ETH);
+                       if (rule_vlan &&
+                           (eth->val.vlan_tag != *rule_vlan ||
+                            eth->mask.vlan_tag != RTE_BE16(0x0fff)))
+                               continue;
+                       if (!rule_vlan && eth->mask.vlan_tag)
+                               continue;
                        for (j = 0; j != sizeof(mac->addr_bytes); ++j)
                                if (eth->val.dst_mac[j] != mac->addr_bytes[j] ||
                                    eth->mask.dst_mac[j] != UINT8_C(0xff) ||
@@ -1109,6 +1171,11 @@ mlx4_flow_internal(struct priv *priv, struct rte_flow_error *error)
                flow->select = 1;
                flow->mac = 1;
        }
+       if (!err && rule_vlan) {
+               vlan = mlx4_flow_internal_next_vlan(priv, vlan + 1);
+               if (vlan < 4096)
+                       goto next_vlan;
+       }
        /* Clear selection and clean up stale MAC flow rules. */
        flow = LIST_FIRST(&priv->flows);
        while (flow && flow->internal) {