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 DRV_LOG(DEBUG, "port %u %s VLAN filter ID %" PRIu16,
49 dev->data->port_id, (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 DRV_LOG(ERR, "port %u VLAN stripping is not supported",
115 /* Validate queue number */
116 if (queue >= priv->rxqs_n) {
117 DRV_LOG(ERR, "port %u VLAN stripping, invalid queue number %d",
118 dev->data->port_id, queue);
121 DRV_LOG(DEBUG, "port %u set VLAN offloads 0x%x for port %uqueue %d",
122 dev->data->port_id, vlan_offloads, rxq->port_id, queue);
123 if (!rxq_ctrl->ibv) {
124 /* Update related bits in RX queue. */
125 rxq->vlan_strip = !!on;
128 mod = (struct ibv_wq_attr){
129 .attr_mask = IBV_WQ_ATTR_FLAGS,
130 .flags_mask = IBV_WQ_FLAGS_CVLAN_STRIPPING,
131 .flags = vlan_offloads,
133 ret = mlx5_glue->modify_wq(rxq_ctrl->ibv->wq, &mod);
135 DRV_LOG(ERR, "port %u failed to modified stripping mode: %s",
136 dev->data->port_id, strerror(rte_errno));
139 /* Update related bits in RX queue. */
140 rxq->vlan_strip = !!on;
144 * Callback to set/reset VLAN offloads for a port.
147 * Pointer to Ethernet device structure.
149 * VLAN offload bit mask.
152 * 0 on success, a negative errno value otherwise and rte_errno is set.
155 mlx5_vlan_offload_set(struct rte_eth_dev *dev, int mask)
157 struct priv *priv = dev->data->dev_private;
160 if (mask & ETH_VLAN_STRIP_MASK) {
161 int hw_vlan_strip = !!(dev->data->dev_conf.rxmode.offloads &
162 DEV_RX_OFFLOAD_VLAN_STRIP);
164 if (!priv->config.hw_vlan_strip) {
165 DRV_LOG(ERR, "port %u VLAN stripping is not supported",
169 /* Run on every RX queue and set/reset VLAN stripping. */
170 for (i = 0; (i != priv->rxqs_n); i++)
171 mlx5_vlan_strip_queue_set(dev, i, hw_vlan_strip);