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 priv_txq_stop(struct priv *priv)
22 for (i = 0; i != priv->txqs_n; ++i)
23 mlx5_priv_txq_release(priv, i);
27 priv_txq_start(struct priv *priv)
32 /* Add memory regions to Tx queues. */
33 for (i = 0; i != priv->txqs_n; ++i) {
36 struct mlx5_txq_ctrl *txq_ctrl = mlx5_priv_txq_get(priv, i);
40 LIST_FOREACH(mr, &priv->mr, next) {
41 priv_txq_mp2mr_reg(priv, &txq_ctrl->txq, mr->mp, idx++);
42 if (idx == MLX5_PMD_TX_MP_CACHE)
45 txq_alloc_elts(txq_ctrl);
46 txq_ctrl->ibv = mlx5_priv_txq_ibv_new(priv, i);
52 ret = priv_tx_uar_remap(priv, priv->ctx->cmd_fd);
62 priv_rxq_stop(struct priv *priv)
66 for (i = 0; i != priv->rxqs_n; ++i)
67 mlx5_priv_rxq_release(priv, i);
71 priv_rxq_start(struct priv *priv)
76 for (i = 0; i != priv->rxqs_n; ++i) {
77 struct mlx5_rxq_ctrl *rxq_ctrl = mlx5_priv_rxq_get(priv, i);
81 ret = rxq_alloc_elts(rxq_ctrl);
84 rxq_ctrl->ibv = mlx5_priv_rxq_ibv_new(priv, i);
97 * DPDK callback to start the device.
99 * Simulate device start by attaching all configured flows.
102 * Pointer to Ethernet device structure.
105 * 0 on success, negative errno value on failure.
108 mlx5_dev_start(struct rte_eth_dev *dev)
110 struct priv *priv = dev->data->dev_private;
111 struct mlx5_mr *mr = NULL;
114 dev->data->dev_started = 1;
116 err = priv_flow_create_drop_queue(priv);
118 ERROR("%p: Drop queue allocation failed: %s",
119 (void *)dev, strerror(err));
122 DEBUG("%p: allocating and configuring hash RX queues", (void *)dev);
123 rte_mempool_walk(mlx5_mp2mr_iter, priv);
124 err = priv_txq_start(priv);
126 ERROR("%p: TXQ allocation failed: %s",
127 (void *)dev, strerror(err));
130 err = priv_rxq_start(priv);
132 ERROR("%p: RXQ allocation failed: %s",
133 (void *)dev, strerror(err));
136 err = priv_rx_intr_vec_enable(priv);
138 ERROR("%p: RX interrupt vector creation failed",
142 priv_xstats_init(priv);
143 /* Update link status and Tx/Rx callbacks for the first time. */
144 memset(&dev->data->dev_link, 0, sizeof(struct rte_eth_link));
145 INFO("Forcing port %u link to be up", dev->data->port_id);
146 err = priv_force_link_status_change(priv, ETH_LINK_UP);
148 DEBUG("Failed to set port %u link to be up",
152 priv_dev_interrupt_handler_install(priv, dev);
157 dev->data->dev_started = 0;
158 for (mr = LIST_FIRST(&priv->mr); mr; mr = LIST_FIRST(&priv->mr))
159 priv_mr_release(priv, mr);
160 priv_flow_stop(priv, &priv->flows);
161 priv_dev_traffic_disable(priv, dev);
164 priv_flow_delete_drop_queue(priv);
170 * DPDK callback to stop the device.
172 * Simulate device stop by detaching all configured flows.
175 * Pointer to Ethernet device structure.
178 mlx5_dev_stop(struct rte_eth_dev *dev)
180 struct priv *priv = dev->data->dev_private;
184 dev->data->dev_started = 0;
185 /* Prevent crashes when queues are still in use. */
186 dev->rx_pkt_burst = removed_rx_burst;
187 dev->tx_pkt_burst = removed_tx_burst;
189 usleep(1000 * priv->rxqs_n);
190 DEBUG("%p: cleaning up and destroying hash RX queues", (void *)dev);
191 priv_flow_stop(priv, &priv->flows);
192 priv_dev_traffic_disable(priv, dev);
193 priv_rx_intr_vec_disable(priv);
194 priv_dev_interrupt_handler_uninstall(priv, dev);
197 for (mr = LIST_FIRST(&priv->mr); mr; mr = LIST_FIRST(&priv->mr))
198 priv_mr_release(priv, mr);
199 priv_flow_delete_drop_queue(priv);
204 * Enable traffic flows configured by control plane
207 * Pointer to Ethernet device private data.
209 * Pointer to Ethernet device structure.
215 priv_dev_traffic_enable(struct priv *priv, struct rte_eth_dev *dev)
217 struct rte_flow_item_eth bcast = {
218 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
220 struct rte_flow_item_eth ipv6_multi_spec = {
221 .dst.addr_bytes = "\x33\x33\x00\x00\x00\x00",
223 struct rte_flow_item_eth ipv6_multi_mask = {
224 .dst.addr_bytes = "\xff\xff\x00\x00\x00\x00",
226 struct rte_flow_item_eth unicast = {
227 .src.addr_bytes = "\x00\x00\x00\x00\x00\x00",
229 struct rte_flow_item_eth unicast_mask = {
230 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
232 const unsigned int vlan_filter_n = priv->vlan_filter_n;
233 const struct ether_addr cmp = {
234 .addr_bytes = "\x00\x00\x00\x00\x00\x00",
242 if (dev->data->promiscuous) {
243 struct rte_flow_item_eth promisc = {
244 .dst.addr_bytes = "\x00\x00\x00\x00\x00\x00",
245 .src.addr_bytes = "\x00\x00\x00\x00\x00\x00",
249 claim_zero(mlx5_ctrl_flow(dev, &promisc, &promisc));
252 if (dev->data->all_multicast) {
253 struct rte_flow_item_eth multicast = {
254 .dst.addr_bytes = "\x01\x00\x00\x00\x00\x00",
255 .src.addr_bytes = "\x00\x00\x00\x00\x00\x00",
259 claim_zero(mlx5_ctrl_flow(dev, &multicast, &multicast));
261 /* Add broadcast/multicast flows. */
262 for (i = 0; i != vlan_filter_n; ++i) {
263 uint16_t vlan = priv->vlan_filter[i];
265 struct rte_flow_item_vlan vlan_spec = {
266 .tci = rte_cpu_to_be_16(vlan),
268 struct rte_flow_item_vlan vlan_mask = {
272 ret = mlx5_ctrl_flow_vlan(dev, &bcast, &bcast,
273 &vlan_spec, &vlan_mask);
276 ret = mlx5_ctrl_flow_vlan(dev, &ipv6_multi_spec,
278 &vlan_spec, &vlan_mask);
282 if (!vlan_filter_n) {
283 ret = mlx5_ctrl_flow(dev, &bcast, &bcast);
286 ret = mlx5_ctrl_flow(dev, &ipv6_multi_spec,
292 /* Add MAC address flows. */
293 for (i = 0; i != MLX5_MAX_MAC_ADDRESSES; ++i) {
294 struct ether_addr *mac = &dev->data->mac_addrs[i];
296 if (!memcmp(mac, &cmp, sizeof(*mac)))
298 memcpy(&unicast.dst.addr_bytes,
301 for (j = 0; j != vlan_filter_n; ++j) {
302 uint16_t vlan = priv->vlan_filter[j];
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, &unicast,
318 if (!vlan_filter_n) {
319 ret = mlx5_ctrl_flow(dev, &unicast,
332 * Disable traffic flows configured by control plane
335 * Pointer to Ethernet device private data.
337 * Pointer to Ethernet device structure.
343 priv_dev_traffic_disable(struct priv *priv,
344 struct rte_eth_dev *dev __rte_unused)
346 priv_flow_flush(priv, &priv->ctrl_flows);
351 * Restart traffic flows configured by control plane
354 * Pointer to Ethernet device private data.
356 * Pointer to Ethernet device structure.
362 priv_dev_traffic_restart(struct priv *priv, struct rte_eth_dev *dev)
364 if (dev->data->dev_started) {
365 priv_dev_traffic_disable(priv, dev);
366 priv_dev_traffic_enable(priv, dev);
372 * Restart traffic flows configured by control plane
375 * Pointer to Ethernet device structure.
381 mlx5_traffic_restart(struct rte_eth_dev *dev)
383 struct priv *priv = dev->data->dev_private;
386 priv_dev_traffic_restart(priv, dev);