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;
73 DEBUG("%p: %s VLAN filter ID %" PRIu16,
74 (void *)dev, (on ? "enable" : "disable"), vlan_id);
75 assert(priv->vlan_filter_n <= RTE_DIM(priv->vlan_filter));
76 for (i = 0; (i != priv->vlan_filter_n); ++i)
77 if (priv->vlan_filter[i] == vlan_id)
79 /* Check if there's room for another VLAN filter. */
80 if (i == RTE_DIM(priv->vlan_filter))
82 if (i < priv->vlan_filter_n) {
83 assert(priv->vlan_filter_n != 0);
84 /* Enabling an existing VLAN filter has no effect. */
87 /* Remove VLAN filter from list. */
88 --priv->vlan_filter_n;
89 memmove(&priv->vlan_filter[i],
90 &priv->vlan_filter[i + 1],
91 priv->vlan_filter_n - i);
92 priv->vlan_filter[priv->vlan_filter_n] = 0;
94 assert(i == priv->vlan_filter_n);
95 /* Disabling an unknown VLAN filter has no effect. */
98 /* Add new VLAN filter. */
99 priv->vlan_filter[priv->vlan_filter_n] = vlan_id;
100 ++priv->vlan_filter_n;
104 /* Rehash MAC flows in all RX queues. */
106 rxq = &priv->rxq_parent;
109 rxq = (*priv->rxqs)[0];
112 for (i = 0; (i < r); rxq = (*priv->rxqs)[++i]) {
117 rxq_mac_addrs_del(rxq);
118 ret = rxq_mac_addrs_add(rxq);
123 rxq = (*priv->rxqs)[--i];
125 rxq_mac_addrs_del(rxq);
133 * DPDK callback to configure a VLAN filter.
136 * Pointer to Ethernet device structure.
143 * 0 on success, negative errno value on failure.
146 mlx5_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
148 struct priv *priv = dev->data->dev_private;
152 ret = vlan_filter_set(dev, vlan_id, on);