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 #include <rte_ethdev.h>
40 #include <rte_common.h>
42 #include "mlx5_utils.h"
44 #include "mlx5_autoconf.h"
47 * Configure a VLAN filter.
50 * Pointer to Ethernet device structure.
57 * 0 on success, errno value on failure.
60 vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
62 struct priv *priv = dev->data->dev_private;
65 DEBUG("%p: %s VLAN filter ID %" PRIu16,
66 (void *)dev, (on ? "enable" : "disable"), vlan_id);
67 assert(priv->vlan_filter_n <= RTE_DIM(priv->vlan_filter));
68 for (i = 0; (i != priv->vlan_filter_n); ++i)
69 if (priv->vlan_filter[i] == vlan_id)
71 /* Check if there's room for another VLAN filter. */
72 if (i == RTE_DIM(priv->vlan_filter))
74 if (i < priv->vlan_filter_n) {
75 assert(priv->vlan_filter_n != 0);
76 /* Enabling an existing VLAN filter has no effect. */
79 /* Remove VLAN filter from list. */
80 --priv->vlan_filter_n;
81 memmove(&priv->vlan_filter[i],
82 &priv->vlan_filter[i + 1],
83 sizeof(priv->vlan_filter[i]) *
84 (priv->vlan_filter_n - i));
85 priv->vlan_filter[priv->vlan_filter_n] = 0;
87 assert(i == priv->vlan_filter_n);
88 /* Disabling an unknown VLAN filter has no effect. */
91 /* Add new VLAN filter. */
92 priv->vlan_filter[priv->vlan_filter_n] = vlan_id;
93 ++priv->vlan_filter_n;
95 /* Rehash flows in all hash RX queues. */
96 priv_mac_addrs_disable(priv);
97 priv_special_flow_disable_all(priv);
98 return priv_rehash_flows(priv);
102 * DPDK callback to configure a VLAN filter.
105 * Pointer to Ethernet device structure.
112 * 0 on success, negative errno value on failure.
115 mlx5_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
117 struct priv *priv = dev->data->dev_private;
121 ret = vlan_filter_set(dev, vlan_id, on);
128 * Set/reset VLAN stripping for a specific queue.
131 * Pointer to private structure.
135 * Enable/disable VLAN stripping.
138 priv_vlan_strip_queue_set(struct priv *priv, uint16_t idx, int on)
140 struct rxq *rxq = (*priv->rxqs)[idx];
141 struct rxq_ctrl *rxq_ctrl = container_of(rxq, struct rxq_ctrl, rxq);
142 struct ibv_exp_wq_attr mod;
143 uint16_t vlan_offloads =
144 (on ? IBV_EXP_RECEIVE_WQ_CVLAN_STRIP : 0) |
148 DEBUG("set VLAN offloads 0x%x for port %d queue %d",
149 vlan_offloads, rxq->port_id, idx);
150 mod = (struct ibv_exp_wq_attr){
151 .attr_mask = IBV_EXP_WQ_ATTR_VLAN_OFFLOADS,
152 .vlan_offloads = vlan_offloads,
155 err = ibv_exp_modify_wq(rxq_ctrl->wq, &mod);
157 ERROR("%p: failed to modified stripping mode: %s",
158 (void *)priv, strerror(err));
162 /* Update related bits in RX queue. */
163 rxq->vlan_strip = !!on;
167 * Callback to set/reset VLAN stripping for a specific queue.
170 * Pointer to Ethernet device structure.
174 * Enable/disable VLAN stripping.
177 mlx5_vlan_strip_queue_set(struct rte_eth_dev *dev, uint16_t queue, int on)
179 struct priv *priv = dev->data->dev_private;
181 /* Validate hw support */
182 if (!priv->hw_vlan_strip) {
183 ERROR("VLAN stripping is not supported");
187 /* Validate queue number */
188 if (queue >= priv->rxqs_n) {
189 ERROR("VLAN stripping, invalid queue number %d", queue);
194 priv_vlan_strip_queue_set(priv, queue, on);
199 * Callback to set/reset VLAN offloads for a port.
202 * Pointer to Ethernet device structure.
204 * VLAN offload bit mask.
207 mlx5_vlan_offload_set(struct rte_eth_dev *dev, int mask)
209 struct priv *priv = dev->data->dev_private;
212 if (mask & ETH_VLAN_STRIP_MASK) {
213 int hw_vlan_strip = !!dev->data->dev_conf.rxmode.hw_vlan_strip;
215 if (!priv->hw_vlan_strip) {
216 ERROR("VLAN stripping is not supported");
220 /* Run on every RX queue and set/reset VLAN stripping. */
222 for (i = 0; (i != priv->rxqs_n); i++)
223 priv_vlan_strip_queue_set(priv, i, hw_vlan_strip);