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;
49 DEBUG("%p: %s VLAN filter ID %" PRIu16,
50 (void *)dev, (on ? "enable" : "disable"), vlan_id);
51 assert(priv->vlan_filter_n <= RTE_DIM(priv->vlan_filter));
52 for (i = 0; (i != priv->vlan_filter_n); ++i)
53 if (priv->vlan_filter[i] == vlan_id)
55 /* Check if there's room for another VLAN filter. */
56 if (i == RTE_DIM(priv->vlan_filter)) {
60 if (i < priv->vlan_filter_n) {
61 assert(priv->vlan_filter_n != 0);
62 /* Enabling an existing VLAN filter has no effect. */
65 /* Remove VLAN filter from list. */
66 --priv->vlan_filter_n;
67 memmove(&priv->vlan_filter[i],
68 &priv->vlan_filter[i + 1],
69 sizeof(priv->vlan_filter[i]) *
70 (priv->vlan_filter_n - i));
71 priv->vlan_filter[priv->vlan_filter_n] = 0;
73 assert(i == priv->vlan_filter_n);
74 /* Disabling an unknown VLAN filter has no effect. */
77 /* Add new VLAN filter. */
78 priv->vlan_filter[priv->vlan_filter_n] = vlan_id;
79 ++priv->vlan_filter_n;
81 if (dev->data->dev_started)
82 priv_dev_traffic_restart(priv, dev);
88 * Set/reset VLAN stripping for a specific queue.
91 * Pointer to private structure.
95 * Enable/disable VLAN stripping.
98 priv_vlan_strip_queue_set(struct priv *priv, uint16_t idx, int on)
100 struct mlx5_rxq_data *rxq = (*priv->rxqs)[idx];
101 struct mlx5_rxq_ctrl *rxq_ctrl =
102 container_of(rxq, struct mlx5_rxq_ctrl, rxq);
103 struct ibv_wq_attr mod;
104 uint16_t vlan_offloads =
105 (on ? IBV_WQ_FLAGS_CVLAN_STRIPPING : 0) |
109 DEBUG("set VLAN offloads 0x%x for port %d queue %d",
110 vlan_offloads, rxq->port_id, idx);
111 if (!rxq_ctrl->ibv) {
112 /* Update related bits in RX queue. */
113 rxq->vlan_strip = !!on;
116 mod = (struct ibv_wq_attr){
117 .attr_mask = IBV_WQ_ATTR_FLAGS,
118 .flags_mask = IBV_WQ_FLAGS_CVLAN_STRIPPING,
119 .flags = vlan_offloads,
121 err = mlx5_glue->modify_wq(rxq_ctrl->ibv->wq, &mod);
123 ERROR("%p: failed to modified stripping mode: %s",
124 (void *)priv, strerror(err));
127 /* Update related bits in RX queue. */
128 rxq->vlan_strip = !!on;
132 * Callback to set/reset VLAN stripping for a specific queue.
135 * Pointer to Ethernet device structure.
139 * Enable/disable VLAN stripping.
142 mlx5_vlan_strip_queue_set(struct rte_eth_dev *dev, uint16_t queue, int on)
144 struct priv *priv = dev->data->dev_private;
146 /* Validate hw support */
147 if (!priv->config.hw_vlan_strip) {
148 ERROR("VLAN stripping is not supported");
151 /* Validate queue number */
152 if (queue >= priv->rxqs_n) {
153 ERROR("VLAN stripping, invalid queue number %d", queue);
156 priv_vlan_strip_queue_set(priv, queue, on);
160 * Callback to set/reset VLAN offloads for a port.
163 * Pointer to Ethernet device structure.
165 * VLAN offload bit mask.
168 mlx5_vlan_offload_set(struct rte_eth_dev *dev, int mask)
170 struct priv *priv = dev->data->dev_private;
173 if (mask & ETH_VLAN_STRIP_MASK) {
174 int hw_vlan_strip = !!(dev->data->dev_conf.rxmode.offloads &
175 DEV_RX_OFFLOAD_VLAN_STRIP);
177 if (!priv->config.hw_vlan_strip) {
178 ERROR("VLAN stripping is not supported");
181 /* Run on every RX queue and set/reset VLAN stripping. */
182 for (i = 0; (i != priv->rxqs_n); i++)
183 priv_vlan_strip_queue_set(priv, i, hw_vlan_strip);