1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2015 6WIND S.A.
3 * Copyright 2015 Mellanox Technologies, Ltd
12 * Not needed by this file; included to work around the lack of off_t
13 * definition for mlx5dv.h with unpatched rdma-core versions.
15 #include <sys/types.h>
17 /* Verbs headers do not support -pedantic. */
19 #pragma GCC diagnostic ignored "-Wpedantic"
21 #include <infiniband/mlx5dv.h>
22 #include <infiniband/verbs.h>
24 #pragma GCC diagnostic error "-Wpedantic"
27 #include <rte_ethdev_driver.h>
28 #include <rte_common.h>
31 #include "mlx5_autoconf.h"
32 #include "mlx5_glue.h"
33 #include "mlx5_devx_cmds.h"
34 #include "mlx5_rxtx.h"
35 #include "mlx5_utils.h"
38 * DPDK callback to configure a VLAN filter.
41 * Pointer to Ethernet device structure.
48 * 0 on success, a negative errno value otherwise and rte_errno is set.
51 mlx5_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
53 struct mlx5_priv *priv = dev->data->dev_private;
56 DRV_LOG(DEBUG, "port %u %s VLAN filter ID %" PRIu16,
57 dev->data->port_id, (on ? "enable" : "disable"), vlan_id);
58 assert(priv->vlan_filter_n <= RTE_DIM(priv->vlan_filter));
59 for (i = 0; (i != priv->vlan_filter_n); ++i)
60 if (priv->vlan_filter[i] == vlan_id)
62 /* Check if there's room for another VLAN filter. */
63 if (i == RTE_DIM(priv->vlan_filter)) {
67 if (i < priv->vlan_filter_n) {
68 assert(priv->vlan_filter_n != 0);
69 /* Enabling an existing VLAN filter has no effect. */
72 /* Remove VLAN filter from list. */
73 --priv->vlan_filter_n;
74 memmove(&priv->vlan_filter[i],
75 &priv->vlan_filter[i + 1],
76 sizeof(priv->vlan_filter[i]) *
77 (priv->vlan_filter_n - i));
78 priv->vlan_filter[priv->vlan_filter_n] = 0;
80 assert(i == priv->vlan_filter_n);
81 /* Disabling an unknown VLAN filter has no effect. */
84 /* Add new VLAN filter. */
85 priv->vlan_filter[priv->vlan_filter_n] = vlan_id;
86 ++priv->vlan_filter_n;
89 if (dev->data->dev_started)
90 return mlx5_traffic_restart(dev);
95 * Callback to set/reset VLAN stripping for a specific queue.
98 * Pointer to Ethernet device structure.
102 * Enable/disable VLAN stripping.
105 mlx5_vlan_strip_queue_set(struct rte_eth_dev *dev, uint16_t queue, int on)
107 struct mlx5_priv *priv = dev->data->dev_private;
108 struct mlx5_rxq_data *rxq = (*priv->rxqs)[queue];
109 struct mlx5_rxq_ctrl *rxq_ctrl =
110 container_of(rxq, struct mlx5_rxq_ctrl, rxq);
111 struct ibv_wq_attr mod;
112 uint16_t vlan_offloads =
113 (on ? IBV_WQ_FLAGS_CVLAN_STRIPPING : 0) |
117 /* Validate hw support */
118 if (!priv->config.hw_vlan_strip) {
119 DRV_LOG(ERR, "port %u VLAN stripping is not supported",
123 /* Validate queue number */
124 if (queue >= priv->rxqs_n) {
125 DRV_LOG(ERR, "port %u VLAN stripping, invalid queue number %d",
126 dev->data->port_id, queue);
129 DRV_LOG(DEBUG, "port %u set VLAN offloads 0x%x for port %uqueue %d",
130 dev->data->port_id, vlan_offloads, rxq->port_id, queue);
131 if (!rxq_ctrl->obj) {
132 /* Update related bits in RX queue. */
133 rxq->vlan_strip = !!on;
136 if (rxq_ctrl->obj->type == MLX5_RXQ_OBJ_TYPE_IBV) {
137 mod = (struct ibv_wq_attr){
138 .attr_mask = IBV_WQ_ATTR_FLAGS,
139 .flags_mask = IBV_WQ_FLAGS_CVLAN_STRIPPING,
140 .flags = vlan_offloads,
142 ret = mlx5_glue->modify_wq(rxq_ctrl->obj->wq, &mod);
143 } else if (rxq_ctrl->obj->type == MLX5_RXQ_OBJ_TYPE_DEVX_RQ) {
144 struct mlx5_devx_modify_rq_attr rq_attr;
146 memset(&rq_attr, 0, sizeof(rq_attr));
147 rq_attr.rq_state = MLX5_RQC_STATE_RDY;
148 rq_attr.state = MLX5_RQC_STATE_RDY;
149 rq_attr.vsd = (on ? 0 : 1);
150 rq_attr.modify_bitmask = MLX5_MODIFY_RQ_IN_MODIFY_BITMASK_VSD;
151 ret = mlx5_devx_cmd_modify_rq(rxq_ctrl->obj->rq, &rq_attr);
154 DRV_LOG(ERR, "port %u failed to modify object %d stripping "
155 "mode: %s", dev->data->port_id,
156 rxq_ctrl->obj->type, strerror(rte_errno));
159 /* Update related bits in RX queue. */
160 rxq->vlan_strip = !!on;
164 * Callback to set/reset VLAN offloads for a port.
167 * Pointer to Ethernet device structure.
169 * VLAN offload bit mask.
172 * 0 on success, a negative errno value otherwise and rte_errno is set.
175 mlx5_vlan_offload_set(struct rte_eth_dev *dev, int mask)
177 struct mlx5_priv *priv = dev->data->dev_private;
180 if (mask & ETH_VLAN_STRIP_MASK) {
181 int hw_vlan_strip = !!(dev->data->dev_conf.rxmode.offloads &
182 DEV_RX_OFFLOAD_VLAN_STRIP);
184 if (!priv->config.hw_vlan_strip) {
185 DRV_LOG(ERR, "port %u VLAN stripping is not supported",
189 /* Run on every RX queue and set/reset VLAN stripping. */
190 for (i = 0; (i != priv->rxqs_n); i++)
191 mlx5_vlan_strip_queue_set(dev, i, hw_vlan_strip);