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 mlx5_traffic_restart(dev);
88 * Callback to set/reset VLAN stripping for a specific queue.
91 * Pointer to Ethernet device structure.
95 * Enable/disable VLAN stripping.
98 mlx5_vlan_strip_queue_set(struct rte_eth_dev *dev, uint16_t queue, int on)
100 struct priv *priv = dev->data->dev_private;
101 struct mlx5_rxq_data *rxq = (*priv->rxqs)[queue];
102 struct mlx5_rxq_ctrl *rxq_ctrl =
103 container_of(rxq, struct mlx5_rxq_ctrl, rxq);
104 struct ibv_wq_attr mod;
105 uint16_t vlan_offloads =
106 (on ? IBV_WQ_FLAGS_CVLAN_STRIPPING : 0) |
110 /* Validate hw support */
111 if (!priv->config.hw_vlan_strip) {
112 ERROR("VLAN stripping is not supported");
115 /* Validate queue number */
116 if (queue >= priv->rxqs_n) {
117 ERROR("VLAN stripping, invalid queue number %d", queue);
120 DEBUG("set VLAN offloads 0x%x for port %d queue %d",
121 vlan_offloads, rxq->port_id, queue);
122 if (!rxq_ctrl->ibv) {
123 /* Update related bits in RX queue. */
124 rxq->vlan_strip = !!on;
127 mod = (struct ibv_wq_attr){
128 .attr_mask = IBV_WQ_ATTR_FLAGS,
129 .flags_mask = IBV_WQ_FLAGS_CVLAN_STRIPPING,
130 .flags = vlan_offloads,
132 err = mlx5_glue->modify_wq(rxq_ctrl->ibv->wq, &mod);
134 ERROR("%p: failed to modified stripping mode: %s",
135 (void *)dev, strerror(err));
138 /* Update related bits in RX queue. */
139 rxq->vlan_strip = !!on;
143 * Callback to set/reset VLAN offloads for a port.
146 * Pointer to Ethernet device structure.
148 * VLAN offload bit mask.
151 mlx5_vlan_offload_set(struct rte_eth_dev *dev, int mask)
153 struct priv *priv = dev->data->dev_private;
156 if (mask & ETH_VLAN_STRIP_MASK) {
157 int hw_vlan_strip = !!(dev->data->dev_conf.rxmode.offloads &
158 DEV_RX_OFFLOAD_VLAN_STRIP);
160 if (!priv->config.hw_vlan_strip) {
161 ERROR("VLAN stripping is not supported");
164 /* Run on every RX queue and set/reset VLAN stripping. */
165 for (i = 0; (i != priv->rxqs_n); i++)
166 mlx5_vlan_strip_queue_set(dev, i, hw_vlan_strip);