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 /* Update link status and Tx/Rx callbacks for the first time. */
180 memset(&dev->data->dev_link, 0, sizeof(struct rte_eth_link));
181 DRV_LOG(INFO, "forcing port %u link to be up", dev->data->port_id);
182 ret = mlx5_force_link_status_change(dev, ETH_LINK_UP);
184 DRV_LOG(DEBUG, "failed to set port %u link to be up",
188 mlx5_dev_interrupt_handler_install(dev);
191 ret = rte_errno; /* Save rte_errno before cleanup. */
193 dev->data->dev_started = 0;
194 for (mr = LIST_FIRST(&priv->mr); mr; mr = LIST_FIRST(&priv->mr))
196 mlx5_flow_stop(dev, &priv->flows);
197 mlx5_traffic_disable(dev);
200 mlx5_flow_delete_drop_queue(dev);
201 rte_errno = ret; /* Restore rte_errno. */
206 * DPDK callback to stop the device.
208 * Simulate device stop by detaching all configured flows.
211 * Pointer to Ethernet device structure.
214 mlx5_dev_stop(struct rte_eth_dev *dev)
216 struct priv *priv = dev->data->dev_private;
219 dev->data->dev_started = 0;
220 /* Prevent crashes when queues are still in use. */
221 dev->rx_pkt_burst = removed_rx_burst;
222 dev->tx_pkt_burst = removed_tx_burst;
224 usleep(1000 * priv->rxqs_n);
225 DRV_LOG(DEBUG, "port %u cleaning up and destroying hash Rx queues",
227 mlx5_flow_stop(dev, &priv->flows);
228 mlx5_traffic_disable(dev);
229 mlx5_rx_intr_vec_disable(dev);
230 mlx5_dev_interrupt_handler_uninstall(dev);
233 for (mr = LIST_FIRST(&priv->mr); mr; mr = LIST_FIRST(&priv->mr))
235 mlx5_flow_delete_drop_queue(dev);
239 * Enable traffic flows configured by control plane
242 * Pointer to Ethernet device private data.
244 * Pointer to Ethernet device structure.
247 * 0 on success, a negative errno value otherwise and rte_errno is set.
250 mlx5_traffic_enable(struct rte_eth_dev *dev)
252 struct priv *priv = dev->data->dev_private;
253 struct rte_flow_item_eth bcast = {
254 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
256 struct rte_flow_item_eth ipv6_multi_spec = {
257 .dst.addr_bytes = "\x33\x33\x00\x00\x00\x00",
259 struct rte_flow_item_eth ipv6_multi_mask = {
260 .dst.addr_bytes = "\xff\xff\x00\x00\x00\x00",
262 struct rte_flow_item_eth unicast = {
263 .src.addr_bytes = "\x00\x00\x00\x00\x00\x00",
265 struct rte_flow_item_eth unicast_mask = {
266 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
268 const unsigned int vlan_filter_n = priv->vlan_filter_n;
269 const struct ether_addr cmp = {
270 .addr_bytes = "\x00\x00\x00\x00\x00\x00",
278 if (dev->data->promiscuous) {
279 struct rte_flow_item_eth promisc = {
280 .dst.addr_bytes = "\x00\x00\x00\x00\x00\x00",
281 .src.addr_bytes = "\x00\x00\x00\x00\x00\x00",
285 ret = mlx5_ctrl_flow(dev, &promisc, &promisc);
289 if (dev->data->all_multicast) {
290 struct rte_flow_item_eth multicast = {
291 .dst.addr_bytes = "\x01\x00\x00\x00\x00\x00",
292 .src.addr_bytes = "\x00\x00\x00\x00\x00\x00",
296 ret = mlx5_ctrl_flow(dev, &multicast, &multicast);
300 /* Add broadcast/multicast flows. */
301 for (i = 0; i != vlan_filter_n; ++i) {
302 uint16_t vlan = priv->vlan_filter[i];
304 struct rte_flow_item_vlan vlan_spec = {
305 .tci = rte_cpu_to_be_16(vlan),
307 struct rte_flow_item_vlan vlan_mask = {
311 ret = mlx5_ctrl_flow_vlan(dev, &bcast, &bcast,
312 &vlan_spec, &vlan_mask);
315 ret = mlx5_ctrl_flow_vlan(dev, &ipv6_multi_spec,
317 &vlan_spec, &vlan_mask);
321 if (!vlan_filter_n) {
322 ret = mlx5_ctrl_flow(dev, &bcast, &bcast);
325 ret = mlx5_ctrl_flow(dev, &ipv6_multi_spec,
331 /* Add MAC address flows. */
332 for (i = 0; i != MLX5_MAX_MAC_ADDRESSES; ++i) {
333 struct ether_addr *mac = &dev->data->mac_addrs[i];
335 if (!memcmp(mac, &cmp, sizeof(*mac)))
337 memcpy(&unicast.dst.addr_bytes,
340 for (j = 0; j != vlan_filter_n; ++j) {
341 uint16_t vlan = priv->vlan_filter[j];
343 struct rte_flow_item_vlan vlan_spec = {
344 .tci = rte_cpu_to_be_16(vlan),
346 struct rte_flow_item_vlan vlan_mask = {
350 ret = mlx5_ctrl_flow_vlan(dev, &unicast,
357 if (!vlan_filter_n) {
358 ret = mlx5_ctrl_flow(dev, &unicast, &unicast_mask);
365 ret = rte_errno; /* Save rte_errno before cleanup. */
366 mlx5_flow_list_flush(dev, &priv->ctrl_flows);
367 rte_errno = ret; /* Restore rte_errno. */
373 * Disable traffic flows configured by control plane
376 * Pointer to Ethernet device private data.
379 mlx5_traffic_disable(struct rte_eth_dev *dev)
381 struct priv *priv = dev->data->dev_private;
383 mlx5_flow_list_flush(dev, &priv->ctrl_flows);
387 * Restart traffic flows configured by control plane
390 * Pointer to Ethernet device private data.
393 * 0 on success, a negative errno value otherwise and rte_errno is set.
396 mlx5_traffic_restart(struct rte_eth_dev *dev)
398 if (dev->data->dev_started) {
399 mlx5_traffic_disable(dev);
400 return mlx5_traffic_enable(dev);