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, a negative errno value otherwise and rte_errno is set.
43 mlx5_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
45 struct priv *priv = dev->data->dev_private;
48 DEBUG("%p: %s VLAN filter ID %" PRIu16,
49 (void *)dev, (on ? "enable" : "disable"), vlan_id);
50 assert(priv->vlan_filter_n <= RTE_DIM(priv->vlan_filter));
51 for (i = 0; (i != priv->vlan_filter_n); ++i)
52 if (priv->vlan_filter[i] == vlan_id)
54 /* Check if there's room for another VLAN filter. */
55 if (i == RTE_DIM(priv->vlan_filter)) {
59 if (i < priv->vlan_filter_n) {
60 assert(priv->vlan_filter_n != 0);
61 /* Enabling an existing VLAN filter has no effect. */
64 /* Remove VLAN filter from list. */
65 --priv->vlan_filter_n;
66 memmove(&priv->vlan_filter[i],
67 &priv->vlan_filter[i + 1],
68 sizeof(priv->vlan_filter[i]) *
69 (priv->vlan_filter_n - i));
70 priv->vlan_filter[priv->vlan_filter_n] = 0;
72 assert(i == priv->vlan_filter_n);
73 /* Disabling an unknown VLAN filter has no effect. */
76 /* Add new VLAN filter. */
77 priv->vlan_filter[priv->vlan_filter_n] = vlan_id;
78 ++priv->vlan_filter_n;
81 if (dev->data->dev_started)
82 return mlx5_traffic_restart(dev);
87 * Callback to set/reset VLAN stripping for a specific queue.
90 * Pointer to Ethernet device structure.
94 * Enable/disable VLAN stripping.
97 mlx5_vlan_strip_queue_set(struct rte_eth_dev *dev, uint16_t queue, int on)
99 struct priv *priv = dev->data->dev_private;
100 struct mlx5_rxq_data *rxq = (*priv->rxqs)[queue];
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 /* Validate hw support */
110 if (!priv->config.hw_vlan_strip) {
111 ERROR("VLAN stripping is not supported");
114 /* Validate queue number */
115 if (queue >= priv->rxqs_n) {
116 ERROR("VLAN stripping, invalid queue number %d", queue);
119 DEBUG("set VLAN offloads 0x%x for port %d queue %d",
120 vlan_offloads, rxq->port_id, queue);
121 if (!rxq_ctrl->ibv) {
122 /* Update related bits in RX queue. */
123 rxq->vlan_strip = !!on;
126 mod = (struct ibv_wq_attr){
127 .attr_mask = IBV_WQ_ATTR_FLAGS,
128 .flags_mask = IBV_WQ_FLAGS_CVLAN_STRIPPING,
129 .flags = vlan_offloads,
131 ret = mlx5_glue->modify_wq(rxq_ctrl->ibv->wq, &mod);
133 ERROR("%p: failed to modified stripping mode: %s",
134 (void *)dev, strerror(rte_errno));
137 /* Update related bits in RX queue. */
138 rxq->vlan_strip = !!on;
142 * Callback to set/reset VLAN offloads for a port.
145 * Pointer to Ethernet device structure.
147 * VLAN offload bit mask.
150 * 0 on success, a negative errno value otherwise and rte_errno is set.
153 mlx5_vlan_offload_set(struct rte_eth_dev *dev, int mask)
155 struct priv *priv = dev->data->dev_private;
158 if (mask & ETH_VLAN_STRIP_MASK) {
159 int hw_vlan_strip = !!(dev->data->dev_conf.rxmode.offloads &
160 DEV_RX_OFFLOAD_VLAN_STRIP);
162 if (!priv->config.hw_vlan_strip) {
163 ERROR("VLAN stripping is not supported");
166 /* Run on every RX queue and set/reset VLAN stripping. */
167 for (i = 0; (i != priv->rxqs_n); i++)
168 mlx5_vlan_strip_queue_set(dev, i, hw_vlan_strip);