1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2015 6WIND S.A.
3 * Copyright 2015 Mellanox.
9 #include <rte_ethdev_driver.h>
10 #include <rte_interrupts.h>
11 #include <rte_alarm.h>
14 #include "mlx5_rxtx.h"
15 #include "mlx5_utils.h"
18 * Stop traffic on Tx queues.
21 * Pointer to Ethernet device structure.
24 mlx5_txq_stop(struct rte_eth_dev *dev)
26 struct priv *priv = dev->data->dev_private;
29 for (i = 0; i != priv->txqs_n; ++i)
30 mlx5_txq_release(dev, i);
34 * Start traffic on Tx queues.
37 * Pointer to Ethernet device structure.
40 * 0 on success, a negative errno value otherwise and rte_errno is set.
43 mlx5_txq_start(struct rte_eth_dev *dev)
45 struct priv *priv = dev->data->dev_private;
49 /* Add memory regions to Tx queues. */
50 for (i = 0; i != priv->txqs_n; ++i) {
53 struct mlx5_txq_ctrl *txq_ctrl = mlx5_txq_get(dev, i);
57 LIST_FOREACH(mr, &priv->mr, next) {
58 mlx5_txq_mp2mr_reg(&txq_ctrl->txq, mr->mp, idx++);
59 if (idx == MLX5_PMD_TX_MP_CACHE)
62 txq_alloc_elts(txq_ctrl);
63 txq_ctrl->ibv = mlx5_txq_ibv_new(dev, i);
69 ret = mlx5_tx_uar_remap(dev, priv->ctx->cmd_fd);
74 ret = rte_errno; /* Save rte_errno before cleanup. */
76 rte_errno = ret; /* Restore rte_errno. */
81 * Stop traffic on Rx queues.
84 * Pointer to Ethernet device structure.
87 mlx5_rxq_stop(struct rte_eth_dev *dev)
89 struct priv *priv = dev->data->dev_private;
92 for (i = 0; i != priv->rxqs_n; ++i)
93 mlx5_rxq_release(dev, i);
97 * Start traffic on Rx queues.
100 * Pointer to Ethernet device structure.
103 * 0 on success, a negative errno value otherwise and rte_errno is set.
106 mlx5_rxq_start(struct rte_eth_dev *dev)
108 struct priv *priv = dev->data->dev_private;
112 for (i = 0; i != priv->rxqs_n; ++i) {
113 struct mlx5_rxq_ctrl *rxq_ctrl = mlx5_rxq_get(dev, i);
117 ret = rxq_alloc_elts(rxq_ctrl);
120 rxq_ctrl->ibv = mlx5_rxq_ibv_new(dev, i);
126 ret = rte_errno; /* Save rte_errno before cleanup. */
128 rte_errno = ret; /* Restore rte_errno. */
133 * DPDK callback to start the device.
135 * Simulate device start by attaching all configured flows.
138 * Pointer to Ethernet device structure.
141 * 0 on success, a negative errno value otherwise and rte_errno is set.
144 mlx5_dev_start(struct rte_eth_dev *dev)
146 struct priv *priv = dev->data->dev_private;
147 struct mlx5_mr *mr = NULL;
150 dev->data->dev_started = 1;
151 ret = mlx5_flow_create_drop_queue(dev);
153 DRV_LOG(ERR, "port %u drop queue allocation failed: %s",
154 dev->data->port_id, strerror(rte_errno));
157 DRV_LOG(DEBUG, "port %u allocating and configuring hash Rx queues",
159 rte_mempool_walk(mlx5_mp2mr_iter, priv);
160 ret = mlx5_txq_start(dev);
162 DRV_LOG(ERR, "port %u Tx queue allocation failed: %s",
163 dev->data->port_id, strerror(rte_errno));
166 ret = mlx5_rxq_start(dev);
168 DRV_LOG(ERR, "port %u Rx queue allocation failed: %s",
169 dev->data->port_id, strerror(rte_errno));
172 ret = mlx5_rx_intr_vec_enable(dev);
174 DRV_LOG(ERR, "port %u Rx interrupt vector creation failed",
178 mlx5_xstats_init(dev);
179 ret = mlx5_traffic_enable(dev);
181 DRV_LOG(DEBUG, "port %u failed to set defaults flows",
185 ret = mlx5_flow_start(dev, &priv->flows);
187 DRV_LOG(DEBUG, "port %u failed to set flows",
191 dev->tx_pkt_burst = mlx5_select_tx_function(dev);
192 dev->rx_pkt_burst = mlx5_select_rx_function(dev);
193 mlx5_dev_interrupt_handler_install(dev);
196 ret = rte_errno; /* Save rte_errno before cleanup. */
198 dev->data->dev_started = 0;
199 for (mr = LIST_FIRST(&priv->mr); mr; mr = LIST_FIRST(&priv->mr))
201 mlx5_flow_stop(dev, &priv->flows);
202 mlx5_traffic_disable(dev);
205 mlx5_flow_delete_drop_queue(dev);
206 rte_errno = ret; /* Restore rte_errno. */
211 * DPDK callback to stop the device.
213 * Simulate device stop by detaching all configured flows.
216 * Pointer to Ethernet device structure.
219 mlx5_dev_stop(struct rte_eth_dev *dev)
221 struct priv *priv = dev->data->dev_private;
224 dev->data->dev_started = 0;
225 /* Prevent crashes when queues are still in use. */
226 dev->rx_pkt_burst = removed_rx_burst;
227 dev->tx_pkt_burst = removed_tx_burst;
229 usleep(1000 * priv->rxqs_n);
230 DRV_LOG(DEBUG, "port %u cleaning up and destroying hash Rx queues",
232 mlx5_flow_stop(dev, &priv->flows);
233 mlx5_traffic_disable(dev);
234 mlx5_rx_intr_vec_disable(dev);
235 mlx5_dev_interrupt_handler_uninstall(dev);
238 for (mr = LIST_FIRST(&priv->mr); mr; mr = LIST_FIRST(&priv->mr))
240 mlx5_flow_delete_drop_queue(dev);
244 * Enable traffic flows configured by control plane
247 * Pointer to Ethernet device private data.
249 * Pointer to Ethernet device structure.
252 * 0 on success, a negative errno value otherwise and rte_errno is set.
255 mlx5_traffic_enable(struct rte_eth_dev *dev)
257 struct priv *priv = dev->data->dev_private;
258 struct rte_flow_item_eth bcast = {
259 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
261 struct rte_flow_item_eth ipv6_multi_spec = {
262 .dst.addr_bytes = "\x33\x33\x00\x00\x00\x00",
264 struct rte_flow_item_eth ipv6_multi_mask = {
265 .dst.addr_bytes = "\xff\xff\x00\x00\x00\x00",
267 struct rte_flow_item_eth unicast = {
268 .src.addr_bytes = "\x00\x00\x00\x00\x00\x00",
270 struct rte_flow_item_eth unicast_mask = {
271 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
273 const unsigned int vlan_filter_n = priv->vlan_filter_n;
274 const struct ether_addr cmp = {
275 .addr_bytes = "\x00\x00\x00\x00\x00\x00",
283 if (dev->data->promiscuous) {
284 struct rte_flow_item_eth promisc = {
285 .dst.addr_bytes = "\x00\x00\x00\x00\x00\x00",
286 .src.addr_bytes = "\x00\x00\x00\x00\x00\x00",
290 ret = mlx5_ctrl_flow(dev, &promisc, &promisc);
294 if (dev->data->all_multicast) {
295 struct rte_flow_item_eth multicast = {
296 .dst.addr_bytes = "\x01\x00\x00\x00\x00\x00",
297 .src.addr_bytes = "\x00\x00\x00\x00\x00\x00",
301 ret = mlx5_ctrl_flow(dev, &multicast, &multicast);
305 /* Add broadcast/multicast flows. */
306 for (i = 0; i != vlan_filter_n; ++i) {
307 uint16_t vlan = priv->vlan_filter[i];
309 struct rte_flow_item_vlan vlan_spec = {
310 .tci = rte_cpu_to_be_16(vlan),
312 struct rte_flow_item_vlan vlan_mask = {
316 ret = mlx5_ctrl_flow_vlan(dev, &bcast, &bcast,
317 &vlan_spec, &vlan_mask);
320 ret = mlx5_ctrl_flow_vlan(dev, &ipv6_multi_spec,
322 &vlan_spec, &vlan_mask);
326 if (!vlan_filter_n) {
327 ret = mlx5_ctrl_flow(dev, &bcast, &bcast);
330 ret = mlx5_ctrl_flow(dev, &ipv6_multi_spec,
336 /* Add MAC address flows. */
337 for (i = 0; i != MLX5_MAX_MAC_ADDRESSES; ++i) {
338 struct ether_addr *mac = &dev->data->mac_addrs[i];
340 if (!memcmp(mac, &cmp, sizeof(*mac)))
342 memcpy(&unicast.dst.addr_bytes,
345 for (j = 0; j != vlan_filter_n; ++j) {
346 uint16_t vlan = priv->vlan_filter[j];
348 struct rte_flow_item_vlan vlan_spec = {
349 .tci = rte_cpu_to_be_16(vlan),
351 struct rte_flow_item_vlan vlan_mask = {
355 ret = mlx5_ctrl_flow_vlan(dev, &unicast,
362 if (!vlan_filter_n) {
363 ret = mlx5_ctrl_flow(dev, &unicast, &unicast_mask);
370 ret = rte_errno; /* Save rte_errno before cleanup. */
371 mlx5_flow_list_flush(dev, &priv->ctrl_flows);
372 rte_errno = ret; /* Restore rte_errno. */
378 * Disable traffic flows configured by control plane
381 * Pointer to Ethernet device private data.
384 mlx5_traffic_disable(struct rte_eth_dev *dev)
386 struct priv *priv = dev->data->dev_private;
388 mlx5_flow_list_flush(dev, &priv->ctrl_flows);
392 * Restart traffic flows configured by control plane
395 * Pointer to Ethernet device private data.
398 * 0 on success, a negative errno value otherwise and rte_errno is set.
401 mlx5_traffic_restart(struct rte_eth_dev *dev)
403 if (dev->data->dev_started) {
404 mlx5_traffic_disable(dev);
405 return mlx5_traffic_enable(dev);