1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2015 6WIND S.A.
3 * Copyright 2015 Mellanox.
11 /* Verbs headers do not support -pedantic. */
13 #pragma GCC diagnostic ignored "-Wpedantic"
15 #include <infiniband/mlx5dv.h>
16 #include <infiniband/verbs.h>
18 #pragma GCC diagnostic error "-Wpedantic"
21 #include <rte_ethdev_driver.h>
22 #include <rte_common.h>
24 #include "mlx5_utils.h"
26 #include "mlx5_autoconf.h"
27 #include "mlx5_glue.h"
30 * DPDK callback to configure a VLAN filter.
33 * Pointer to Ethernet device structure.
40 * 0 on success, negative errno value on failure.
43 mlx5_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
45 struct priv *priv = dev->data->dev_private;
50 DEBUG("%p: %s VLAN filter ID %" PRIu16,
51 (void *)dev, (on ? "enable" : "disable"), vlan_id);
52 assert(priv->vlan_filter_n <= RTE_DIM(priv->vlan_filter));
53 for (i = 0; (i != priv->vlan_filter_n); ++i)
54 if (priv->vlan_filter[i] == vlan_id)
56 /* Check if there's room for another VLAN filter. */
57 if (i == RTE_DIM(priv->vlan_filter)) {
61 if (i < priv->vlan_filter_n) {
62 assert(priv->vlan_filter_n != 0);
63 /* Enabling an existing VLAN filter has no effect. */
66 /* Remove VLAN filter from list. */
67 --priv->vlan_filter_n;
68 memmove(&priv->vlan_filter[i],
69 &priv->vlan_filter[i + 1],
70 sizeof(priv->vlan_filter[i]) *
71 (priv->vlan_filter_n - i));
72 priv->vlan_filter[priv->vlan_filter_n] = 0;
74 assert(i == priv->vlan_filter_n);
75 /* Disabling an unknown VLAN filter has no effect. */
78 /* Add new VLAN filter. */
79 priv->vlan_filter[priv->vlan_filter_n] = vlan_id;
80 ++priv->vlan_filter_n;
82 if (dev->data->dev_started)
83 priv_dev_traffic_restart(priv, dev);
90 * Set/reset VLAN stripping for a specific queue.
93 * Pointer to private structure.
97 * Enable/disable VLAN stripping.
100 priv_vlan_strip_queue_set(struct priv *priv, uint16_t idx, int on)
102 struct mlx5_rxq_data *rxq = (*priv->rxqs)[idx];
103 struct mlx5_rxq_ctrl *rxq_ctrl =
104 container_of(rxq, struct mlx5_rxq_ctrl, rxq);
105 struct ibv_wq_attr mod;
106 uint16_t vlan_offloads =
107 (on ? IBV_WQ_FLAGS_CVLAN_STRIPPING : 0) |
111 DEBUG("set VLAN offloads 0x%x for port %d queue %d",
112 vlan_offloads, rxq->port_id, idx);
113 if (!rxq_ctrl->ibv) {
114 /* Update related bits in RX queue. */
115 rxq->vlan_strip = !!on;
118 mod = (struct ibv_wq_attr){
119 .attr_mask = IBV_WQ_ATTR_FLAGS,
120 .flags_mask = IBV_WQ_FLAGS_CVLAN_STRIPPING,
121 .flags = vlan_offloads,
124 err = mlx5_glue->modify_wq(rxq_ctrl->ibv->wq, &mod);
126 ERROR("%p: failed to modified stripping mode: %s",
127 (void *)priv, strerror(err));
131 /* Update related bits in RX queue. */
132 rxq->vlan_strip = !!on;
136 * Callback to set/reset VLAN stripping for a specific queue.
139 * Pointer to Ethernet device structure.
143 * Enable/disable VLAN stripping.
146 mlx5_vlan_strip_queue_set(struct rte_eth_dev *dev, uint16_t queue, int on)
148 struct priv *priv = dev->data->dev_private;
150 /* Validate hw support */
151 if (!priv->config.hw_vlan_strip) {
152 ERROR("VLAN stripping is not supported");
156 /* Validate queue number */
157 if (queue >= priv->rxqs_n) {
158 ERROR("VLAN stripping, invalid queue number %d", queue);
163 priv_vlan_strip_queue_set(priv, queue, on);
168 * Callback to set/reset VLAN offloads for a port.
171 * Pointer to Ethernet device structure.
173 * VLAN offload bit mask.
176 mlx5_vlan_offload_set(struct rte_eth_dev *dev, int mask)
178 struct priv *priv = dev->data->dev_private;
181 if (mask & ETH_VLAN_STRIP_MASK) {
182 int hw_vlan_strip = !!(dev->data->dev_conf.rxmode.offloads &
183 DEV_RX_OFFLOAD_VLAN_STRIP);
185 if (!priv->config.hw_vlan_strip) {
186 ERROR("VLAN stripping is not supported");
190 /* Run on every RX queue and set/reset VLAN stripping. */
192 for (i = 0; (i != priv->rxqs_n); i++)
193 priv_vlan_strip_queue_set(priv, i, hw_vlan_strip);