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 * DPDK callback to configure a VLAN filter.
50 * Pointer to Ethernet device structure.
57 * 0 on success, negative errno value on failure.
60 mlx5_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
62 struct priv *priv = dev->data->dev_private;
66 DEBUG("%p: %s VLAN filter ID %" PRIu16,
67 (void *)dev, (on ? "enable" : "disable"), vlan_id);
68 assert(priv->vlan_filter_n <= RTE_DIM(priv->vlan_filter));
69 for (i = 0; (i != priv->vlan_filter_n); ++i)
70 if (priv->vlan_filter[i] == vlan_id)
72 if (i < priv->vlan_filter_n) {
73 assert(priv->vlan_filter_n != 0);
74 /* Enabling an existing VLAN filter has no effect. */
77 /* Remove VLAN filter from list. */
78 --priv->vlan_filter_n;
79 memmove(&priv->vlan_filter[i],
80 &priv->vlan_filter[i + 1],
81 sizeof(priv->vlan_filter[i]) *
82 (priv->vlan_filter_n - i));
83 priv->vlan_filter[priv->vlan_filter_n] = 0;
85 assert(i == priv->vlan_filter_n);
86 /* Disabling an unknown VLAN filter has no effect. */
89 /* Add new VLAN filter. */
90 priv->vlan_filter[priv->vlan_filter_n] = vlan_id;
91 ++priv->vlan_filter_n;
93 if (dev->data->dev_started)
94 priv_dev_traffic_restart(priv, dev);
101 * Set/reset VLAN stripping for a specific queue.
104 * Pointer to private structure.
108 * Enable/disable VLAN stripping.
111 priv_vlan_strip_queue_set(struct priv *priv, uint16_t idx, int on)
113 struct mlx5_rxq_data *rxq = (*priv->rxqs)[idx];
114 struct mlx5_rxq_ctrl *rxq_ctrl =
115 container_of(rxq, struct mlx5_rxq_ctrl, rxq);
116 struct ibv_wq_attr mod;
117 uint16_t vlan_offloads =
118 (on ? IBV_WQ_FLAGS_CVLAN_STRIPPING : 0) |
122 DEBUG("set VLAN offloads 0x%x for port %d queue %d",
123 vlan_offloads, rxq->port_id, idx);
124 mod = (struct ibv_wq_attr){
125 .attr_mask = IBV_WQ_ATTR_FLAGS,
126 .flags_mask = IBV_WQ_FLAGS_CVLAN_STRIPPING,
127 .flags = vlan_offloads,
130 err = ibv_modify_wq(rxq_ctrl->ibv->wq, &mod);
132 ERROR("%p: failed to modified stripping mode: %s",
133 (void *)priv, strerror(err));
137 /* Update related bits in RX queue. */
138 rxq->vlan_strip = !!on;
142 * Callback to set/reset VLAN stripping for a specific queue.
145 * Pointer to Ethernet device structure.
149 * Enable/disable VLAN stripping.
152 mlx5_vlan_strip_queue_set(struct rte_eth_dev *dev, uint16_t queue, int on)
154 struct priv *priv = dev->data->dev_private;
156 /* Validate hw support */
157 if (!priv->hw_vlan_strip) {
158 ERROR("VLAN stripping is not supported");
162 /* Validate queue number */
163 if (queue >= priv->rxqs_n) {
164 ERROR("VLAN stripping, invalid queue number %d", queue);
169 priv_vlan_strip_queue_set(priv, queue, on);
174 * Callback to set/reset VLAN offloads for a port.
177 * Pointer to Ethernet device structure.
179 * VLAN offload bit mask.
182 mlx5_vlan_offload_set(struct rte_eth_dev *dev, int mask)
184 struct priv *priv = dev->data->dev_private;
187 if (mask & ETH_VLAN_STRIP_MASK) {
188 int hw_vlan_strip = !!dev->data->dev_conf.rxmode.hw_vlan_strip;
190 if (!priv->hw_vlan_strip) {
191 ERROR("VLAN stripping is not supported");
195 /* Run on every RX queue and set/reset VLAN stripping. */
197 for (i = 0; (i != priv->rxqs_n); i++)
198 priv_vlan_strip_queue_set(priv, i, hw_vlan_strip);