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);
59 priv_rxq_stop(struct priv *priv)
63 for (i = 0; i != priv->rxqs_n; ++i)
64 mlx5_priv_rxq_release(priv, i);
68 priv_rxq_start(struct priv *priv)
73 for (i = 0; i != priv->rxqs_n; ++i) {
74 struct mlx5_rxq_ctrl *rxq_ctrl = mlx5_priv_rxq_get(priv, i);
78 ret = rxq_alloc_elts(rxq_ctrl);
81 rxq_ctrl->ibv = mlx5_priv_rxq_ibv_new(priv, i);
94 * DPDK callback to start the device.
96 * Simulate device start by attaching all configured flows.
99 * Pointer to Ethernet device structure.
102 * 0 on success, negative errno value on failure.
105 mlx5_dev_start(struct rte_eth_dev *dev)
107 struct priv *priv = dev->data->dev_private;
108 struct mlx5_mr *mr = NULL;
111 dev->data->dev_started = 1;
113 err = priv_flow_create_drop_queue(priv);
115 ERROR("%p: Drop queue allocation failed: %s",
116 (void *)dev, strerror(err));
119 DEBUG("%p: allocating and configuring hash RX queues", (void *)dev);
120 rte_mempool_walk(mlx5_mp2mr_iter, priv);
121 err = priv_txq_start(priv);
123 ERROR("%p: TXQ allocation failed: %s",
124 (void *)dev, strerror(err));
127 err = priv_rxq_start(priv);
129 ERROR("%p: RXQ allocation failed: %s",
130 (void *)dev, strerror(err));
133 err = priv_rx_intr_vec_enable(priv);
135 ERROR("%p: RX interrupt vector creation failed",
139 priv_xstats_init(priv);
140 /* Update link status and Tx/Rx callbacks for the first time. */
141 memset(&dev->data->dev_link, 0, sizeof(struct rte_eth_link));
142 priv_link_update(priv, 1);
143 priv_dev_interrupt_handler_install(priv, dev);
148 dev->data->dev_started = 0;
149 for (mr = LIST_FIRST(&priv->mr); mr; mr = LIST_FIRST(&priv->mr))
150 priv_mr_release(priv, mr);
151 priv_flow_stop(priv, &priv->flows);
152 priv_dev_traffic_disable(priv, dev);
155 priv_flow_delete_drop_queue(priv);
161 * DPDK callback to stop the device.
163 * Simulate device stop by detaching all configured flows.
166 * Pointer to Ethernet device structure.
169 mlx5_dev_stop(struct rte_eth_dev *dev)
171 struct priv *priv = dev->data->dev_private;
175 dev->data->dev_started = 0;
176 /* Prevent crashes when queues are still in use. */
177 dev->rx_pkt_burst = removed_rx_burst;
178 dev->tx_pkt_burst = removed_tx_burst;
180 usleep(1000 * priv->rxqs_n);
181 DEBUG("%p: cleaning up and destroying hash RX queues", (void *)dev);
182 priv_flow_stop(priv, &priv->flows);
183 priv_dev_traffic_disable(priv, dev);
184 priv_rx_intr_vec_disable(priv);
185 priv_dev_interrupt_handler_uninstall(priv, dev);
188 for (mr = LIST_FIRST(&priv->mr); mr; mr = LIST_FIRST(&priv->mr))
189 priv_mr_release(priv, mr);
190 priv_flow_delete_drop_queue(priv);
195 * Enable traffic flows configured by control plane
198 * Pointer to Ethernet device private data.
200 * Pointer to Ethernet device structure.
206 priv_dev_traffic_enable(struct priv *priv, struct rte_eth_dev *dev)
208 struct rte_flow_item_eth bcast = {
209 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
211 struct rte_flow_item_eth ipv6_multi_spec = {
212 .dst.addr_bytes = "\x33\x33\x00\x00\x00\x00",
214 struct rte_flow_item_eth ipv6_multi_mask = {
215 .dst.addr_bytes = "\xff\xff\x00\x00\x00\x00",
217 struct rte_flow_item_eth unicast = {
218 .src.addr_bytes = "\x00\x00\x00\x00\x00\x00",
220 struct rte_flow_item_eth unicast_mask = {
221 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
223 const unsigned int vlan_filter_n = priv->vlan_filter_n;
224 const struct ether_addr cmp = {
225 .addr_bytes = "\x00\x00\x00\x00\x00\x00",
233 if (dev->data->promiscuous) {
234 struct rte_flow_item_eth promisc = {
235 .dst.addr_bytes = "\x00\x00\x00\x00\x00\x00",
236 .src.addr_bytes = "\x00\x00\x00\x00\x00\x00",
240 claim_zero(mlx5_ctrl_flow(dev, &promisc, &promisc));
243 if (dev->data->all_multicast) {
244 struct rte_flow_item_eth multicast = {
245 .dst.addr_bytes = "\x01\x00\x00\x00\x00\x00",
246 .src.addr_bytes = "\x00\x00\x00\x00\x00\x00",
250 claim_zero(mlx5_ctrl_flow(dev, &multicast, &multicast));
252 /* Add broadcast/multicast flows. */
253 for (i = 0; i != vlan_filter_n; ++i) {
254 uint16_t vlan = priv->vlan_filter[i];
256 struct rte_flow_item_vlan vlan_spec = {
257 .tci = rte_cpu_to_be_16(vlan),
259 struct rte_flow_item_vlan vlan_mask = {
263 ret = mlx5_ctrl_flow_vlan(dev, &bcast, &bcast,
264 &vlan_spec, &vlan_mask);
267 ret = mlx5_ctrl_flow_vlan(dev, &ipv6_multi_spec,
269 &vlan_spec, &vlan_mask);
273 if (!vlan_filter_n) {
274 ret = mlx5_ctrl_flow(dev, &bcast, &bcast);
277 ret = mlx5_ctrl_flow(dev, &ipv6_multi_spec,
283 /* Add MAC address flows. */
284 for (i = 0; i != MLX5_MAX_MAC_ADDRESSES; ++i) {
285 struct ether_addr *mac = &dev->data->mac_addrs[i];
287 if (!memcmp(mac, &cmp, sizeof(*mac)))
289 memcpy(&unicast.dst.addr_bytes,
292 for (j = 0; j != vlan_filter_n; ++j) {
293 uint16_t vlan = priv->vlan_filter[j];
295 struct rte_flow_item_vlan vlan_spec = {
296 .tci = rte_cpu_to_be_16(vlan),
298 struct rte_flow_item_vlan vlan_mask = {
302 ret = mlx5_ctrl_flow_vlan(dev, &unicast,
309 if (!vlan_filter_n) {
310 ret = mlx5_ctrl_flow(dev, &unicast,
323 * Disable traffic flows configured by control plane
326 * Pointer to Ethernet device private data.
328 * Pointer to Ethernet device structure.
334 priv_dev_traffic_disable(struct priv *priv, struct rte_eth_dev *dev)
337 priv_flow_flush(priv, &priv->ctrl_flows);
342 * Restart traffic flows configured by control plane
345 * Pointer to Ethernet device private data.
347 * Pointer to Ethernet device structure.
353 priv_dev_traffic_restart(struct priv *priv, struct rte_eth_dev *dev)
355 if (dev->data->dev_started) {
356 priv_dev_traffic_disable(priv, dev);
357 priv_dev_traffic_enable(priv, dev);
363 * Restart traffic flows configured by control plane
366 * Pointer to Ethernet device structure.
372 mlx5_traffic_restart(struct rte_eth_dev *dev)
374 struct priv *priv = dev->data->dev_private;
377 priv_dev_traffic_restart(priv, dev);