1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2015 6WIND S.A.
3 * Copyright 2015 Mellanox Technologies, Ltd
11 #include <ethdev_driver.h>
12 #include <rte_common.h>
13 #include <rte_malloc.h>
14 #include <rte_hypervisor.h>
17 #include "mlx5_autoconf.h"
18 #include "mlx5_rxtx.h"
20 #include "mlx5_utils.h"
21 #include "mlx5_devx.h"
24 * DPDK callback to configure a VLAN filter.
27 * Pointer to Ethernet device structure.
34 * 0 on success, a negative errno value otherwise and rte_errno is set.
37 mlx5_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
39 struct mlx5_priv *priv = dev->data->dev_private;
42 DRV_LOG(DEBUG, "port %u %s VLAN filter ID %" PRIu16,
43 dev->data->port_id, (on ? "enable" : "disable"), vlan_id);
44 MLX5_ASSERT(priv->vlan_filter_n <= RTE_DIM(priv->vlan_filter));
45 for (i = 0; (i != priv->vlan_filter_n); ++i)
46 if (priv->vlan_filter[i] == vlan_id)
48 /* Check if there's room for another VLAN filter. */
49 if (i == RTE_DIM(priv->vlan_filter)) {
53 if (i < priv->vlan_filter_n) {
54 MLX5_ASSERT(priv->vlan_filter_n != 0);
55 /* Enabling an existing VLAN filter has no effect. */
58 /* Remove VLAN filter from list. */
59 --priv->vlan_filter_n;
60 memmove(&priv->vlan_filter[i],
61 &priv->vlan_filter[i + 1],
62 sizeof(priv->vlan_filter[i]) *
63 (priv->vlan_filter_n - i));
64 priv->vlan_filter[priv->vlan_filter_n] = 0;
66 MLX5_ASSERT(i == priv->vlan_filter_n);
67 /* Disabling an unknown VLAN filter has no effect. */
70 /* Add new VLAN filter. */
71 priv->vlan_filter[priv->vlan_filter_n] = vlan_id;
72 ++priv->vlan_filter_n;
75 if (dev->data->dev_started)
76 return mlx5_traffic_restart(dev);
81 * Callback to set/reset VLAN stripping for a specific queue.
84 * Pointer to Ethernet device structure.
88 * Enable/disable VLAN stripping.
91 mlx5_vlan_strip_queue_set(struct rte_eth_dev *dev, uint16_t queue, int on)
93 struct mlx5_priv *priv = dev->data->dev_private;
94 struct mlx5_rxq_data *rxq = (*priv->rxqs)[queue];
95 struct mlx5_rxq_ctrl *rxq_ctrl =
96 container_of(rxq, struct mlx5_rxq_ctrl, rxq);
99 /* Validate hw support */
100 if (!priv->config.hw_vlan_strip) {
101 DRV_LOG(ERR, "port %u VLAN stripping is not supported",
105 /* Validate queue number */
106 if (queue >= priv->rxqs_n) {
107 DRV_LOG(ERR, "port %u VLAN stripping, invalid queue number %d",
108 dev->data->port_id, queue);
111 DRV_LOG(DEBUG, "port %u set VLAN stripping offloads %d for port %uqueue %d",
112 dev->data->port_id, on, rxq->port_id, queue);
113 if (!rxq_ctrl->obj) {
114 /* Update related bits in RX queue. */
115 rxq->vlan_strip = !!on;
118 ret = priv->obj_ops.rxq_obj_modify_vlan_strip(rxq_ctrl->obj, on);
120 DRV_LOG(ERR, "Port %u failed to modify object stripping mode:"
121 " %s", dev->data->port_id, strerror(rte_errno));
124 /* Update related bits in RX queue. */
125 rxq->vlan_strip = !!on;
129 * Callback to set/reset VLAN offloads for a port.
132 * Pointer to Ethernet device structure.
134 * VLAN offload bit mask.
137 * 0 on success, a negative errno value otherwise and rte_errno is set.
140 mlx5_vlan_offload_set(struct rte_eth_dev *dev, int mask)
142 struct mlx5_priv *priv = dev->data->dev_private;
145 if (mask & ETH_VLAN_STRIP_MASK) {
146 int hw_vlan_strip = !!(dev->data->dev_conf.rxmode.offloads &
147 DEV_RX_OFFLOAD_VLAN_STRIP);
149 if (!priv->config.hw_vlan_strip) {
150 DRV_LOG(ERR, "port %u VLAN stripping is not supported",
154 /* Run on every RX queue and set/reset VLAN stripping. */
155 for (i = 0; (i != priv->rxqs_n); i++)
156 mlx5_vlan_strip_queue_set(dev, i, hw_vlan_strip);