4 * Copyright 2015 6WIND S.A.
5 * Copyright 2015 Mellanox.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of 6WIND S.A. nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 /* DPDK headers don't like -pedantic. */
41 #pragma GCC diagnostic ignored "-pedantic"
43 #include <rte_ethdev.h>
44 #include <rte_common.h>
46 #pragma GCC diagnostic error "-pedantic"
49 #include "mlx5_utils.h"
53 * Configure a VLAN filter.
56 * Pointer to Ethernet device structure.
63 * 0 on success, errno value on failure.
66 vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
68 struct priv *priv = dev->data->dev_private;
71 DEBUG("%p: %s VLAN filter ID %" PRIu16,
72 (void *)dev, (on ? "enable" : "disable"), vlan_id);
73 assert(priv->vlan_filter_n <= RTE_DIM(priv->vlan_filter));
74 for (i = 0; (i != priv->vlan_filter_n); ++i)
75 if (priv->vlan_filter[i] == vlan_id)
77 /* Check if there's room for another VLAN filter. */
78 if (i == RTE_DIM(priv->vlan_filter))
80 if (i < priv->vlan_filter_n) {
81 assert(priv->vlan_filter_n != 0);
82 /* Enabling an existing VLAN filter has no effect. */
85 /* Remove VLAN filter from list. */
86 --priv->vlan_filter_n;
87 memmove(&priv->vlan_filter[i],
88 &priv->vlan_filter[i + 1],
89 priv->vlan_filter_n - i);
90 priv->vlan_filter[priv->vlan_filter_n] = 0;
92 assert(i == priv->vlan_filter_n);
93 /* Disabling an unknown VLAN filter has no effect. */
96 /* Add new VLAN filter. */
97 priv->vlan_filter[priv->vlan_filter_n] = vlan_id;
98 ++priv->vlan_filter_n;
100 /* Rehash MAC flows in all hash RX queues. */
101 priv_mac_addrs_disable(priv);
102 return priv_mac_addrs_enable(priv);
106 * DPDK callback to configure a VLAN filter.
109 * Pointer to Ethernet device structure.
116 * 0 on success, negative errno value on failure.
119 mlx5_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
121 struct priv *priv = dev->data->dev_private;
125 ret = vlan_filter_set(dev, vlan_id, on);