4 * Copyright 2015 6WIND S.A.
5 * Copyright 2015 Mellanox.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of 6WIND S.A. nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include <rte_ether.h>
36 #include <rte_ethdev.h>
37 #include <rte_interrupts.h>
38 #include <rte_alarm.h>
41 #include "mlx5_rxtx.h"
42 #include "mlx5_utils.h"
45 priv_txq_stop(struct priv *priv)
49 for (i = 0; i != priv->txqs_n; ++i)
50 mlx5_priv_txq_release(priv, i);
54 priv_txq_start(struct priv *priv)
59 /* Add memory regions to Tx queues. */
60 for (i = 0; i != priv->txqs_n; ++i) {
63 struct mlx5_txq_ctrl *txq_ctrl = mlx5_priv_txq_get(priv, i);
67 LIST_FOREACH(mr, &priv->mr, next)
68 priv_txq_mp2mr_reg(priv, &txq_ctrl->txq, mr->mp, idx++);
69 txq_alloc_elts(txq_ctrl);
70 txq_ctrl->ibv = mlx5_priv_txq_ibv_new(priv, i);
83 priv_rxq_stop(struct priv *priv)
87 for (i = 0; i != priv->rxqs_n; ++i)
88 mlx5_priv_rxq_release(priv, i);
92 priv_rxq_start(struct priv *priv)
97 for (i = 0; i != priv->rxqs_n; ++i) {
98 struct mlx5_rxq_ctrl *rxq_ctrl = mlx5_priv_rxq_get(priv, i);
102 ret = rxq_alloc_elts(rxq_ctrl);
105 rxq_ctrl->ibv = mlx5_priv_rxq_ibv_new(priv, i);
106 if (!rxq_ctrl->ibv) {
118 * DPDK callback to start the device.
120 * Simulate device start by attaching all configured flows.
123 * Pointer to Ethernet device structure.
126 * 0 on success, negative errno value on failure.
129 mlx5_dev_start(struct rte_eth_dev *dev)
131 struct priv *priv = dev->data->dev_private;
132 struct mlx5_mr *mr = NULL;
135 if (mlx5_is_secondary())
136 return -E_RTE_SECONDARY;
138 dev->data->dev_started = 1;
140 err = priv_flow_create_drop_queue(priv);
142 ERROR("%p: Drop queue allocation failed: %s",
143 (void *)dev, strerror(err));
146 DEBUG("%p: allocating and configuring hash RX queues", (void *)dev);
147 rte_mempool_walk(mlx5_mp2mr_iter, priv);
148 err = priv_txq_start(priv);
150 ERROR("%p: TXQ allocation failed: %s",
151 (void *)dev, strerror(err));
154 /* Update send callback. */
155 priv_dev_select_tx_function(priv, dev);
156 err = priv_rxq_start(priv);
158 ERROR("%p: RXQ allocation failed: %s",
159 (void *)dev, strerror(err));
162 /* Update receive callback. */
163 priv_dev_select_rx_function(priv, dev);
164 err = priv_dev_traffic_enable(priv, dev);
166 ERROR("%p: an error occurred while configuring control flows:"
168 (void *)priv, strerror(err));
171 err = priv_flow_start(priv, &priv->flows);
173 ERROR("%p: an error occurred while configuring flows:"
175 (void *)priv, strerror(err));
178 err = priv_rx_intr_vec_enable(priv);
180 ERROR("%p: RX interrupt vector creation failed",
184 priv_dev_interrupt_handler_install(priv, dev);
185 priv_xstats_init(priv);
190 dev->data->dev_started = 0;
191 LIST_FOREACH(mr, &priv->mr, next)
192 priv_mr_release(priv, mr);
193 priv_flow_stop(priv, &priv->flows);
194 priv_dev_traffic_disable(priv, dev);
197 priv_flow_delete_drop_queue(priv);
203 * DPDK callback to stop the device.
205 * Simulate device stop by detaching all configured flows.
208 * Pointer to Ethernet device structure.
211 mlx5_dev_stop(struct rte_eth_dev *dev)
213 struct priv *priv = dev->data->dev_private;
216 if (mlx5_is_secondary())
220 dev->data->dev_started = 0;
221 /* Prevent crashes when queues are still in use. */
222 dev->rx_pkt_burst = removed_rx_burst;
223 dev->tx_pkt_burst = removed_tx_burst;
225 usleep(1000 * priv->rxqs_n);
226 DEBUG("%p: cleaning up and destroying hash RX queues", (void *)dev);
227 priv_flow_stop(priv, &priv->flows);
228 priv_dev_traffic_disable(priv, dev);
229 priv_rx_intr_vec_disable(priv);
230 priv_dev_interrupt_handler_uninstall(priv, dev);
233 LIST_FOREACH(mr, &priv->mr, next) {
234 priv_mr_release(priv, mr);
236 priv_flow_delete_drop_queue(priv);
241 * Enable traffic flows configured by control plane
244 * Pointer to Ethernet device private data.
246 * Pointer to Ethernet device structure.
252 priv_dev_traffic_enable(struct priv *priv, struct rte_eth_dev *dev)
254 struct rte_flow_item_eth bcast = {
255 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
257 struct rte_flow_item_eth ipv6_multi_spec = {
258 .dst.addr_bytes = "\x33\x33\x00\x00\x00\x00",
260 struct rte_flow_item_eth ipv6_multi_mask = {
261 .dst.addr_bytes = "\xff\xff\x00\x00\x00\x00",
263 struct rte_flow_item_eth unicast = {
264 .src.addr_bytes = "\x00\x00\x00\x00\x00\x00",
266 struct rte_flow_item_eth unicast_mask = {
267 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
269 const unsigned int vlan_filter_n = priv->vlan_filter_n;
270 const struct ether_addr cmp = {
271 .addr_bytes = "\x00\x00\x00\x00\x00\x00",
279 if (dev->data->promiscuous) {
280 struct rte_flow_item_eth promisc = {
281 .dst.addr_bytes = "\x00\x00\x00\x00\x00\x00",
282 .src.addr_bytes = "\x00\x00\x00\x00\x00\x00",
286 claim_zero(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 claim_zero(mlx5_ctrl_flow(dev, &multicast, &multicast));
298 /* Add broadcast/multicast flows. */
299 for (i = 0; i != vlan_filter_n; ++i) {
300 uint16_t vlan = priv->vlan_filter[i];
302 struct rte_flow_item_vlan vlan_spec = {
303 .tci = rte_cpu_to_be_16(vlan),
305 struct rte_flow_item_vlan vlan_mask = {
309 ret = mlx5_ctrl_flow_vlan(dev, &bcast, &bcast,
310 &vlan_spec, &vlan_mask);
313 ret = mlx5_ctrl_flow_vlan(dev, &ipv6_multi_spec,
315 &vlan_spec, &vlan_mask);
319 if (!vlan_filter_n) {
320 ret = mlx5_ctrl_flow(dev, &bcast, &bcast);
323 ret = mlx5_ctrl_flow(dev, &ipv6_multi_spec,
329 /* Add MAC address flows. */
330 for (i = 0; i != MLX5_MAX_MAC_ADDRESSES; ++i) {
331 struct ether_addr *mac = &dev->data->mac_addrs[i];
333 if (!memcmp(mac, &cmp, sizeof(*mac)))
335 memcpy(&unicast.dst.addr_bytes,
338 for (j = 0; j != vlan_filter_n; ++j) {
339 uint16_t vlan = priv->vlan_filter[j];
341 struct rte_flow_item_vlan vlan_spec = {
342 .tci = rte_cpu_to_be_16(vlan),
344 struct rte_flow_item_vlan vlan_mask = {
348 ret = mlx5_ctrl_flow_vlan(dev, &unicast,
355 if (!vlan_filter_n) {
356 ret = mlx5_ctrl_flow(dev, &unicast,
369 * Disable traffic flows configured by control plane
372 * Pointer to Ethernet device private data.
374 * Pointer to Ethernet device structure.
380 priv_dev_traffic_disable(struct priv *priv, struct rte_eth_dev *dev)
383 priv_flow_flush(priv, &priv->ctrl_flows);
388 * Restart traffic flows configured by control plane
391 * Pointer to Ethernet device private data.
393 * Pointer to Ethernet device structure.
399 priv_dev_traffic_restart(struct priv *priv, struct rte_eth_dev *dev)
401 if (dev->data->dev_started) {
402 priv_dev_traffic_disable(priv, dev);
403 priv_dev_traffic_enable(priv, dev);
409 * Restart traffic flows configured by control plane
412 * Pointer to Ethernet device structure.
418 mlx5_traffic_restart(struct rte_eth_dev *dev)
420 struct priv *priv = dev->data->dev_private;
423 priv_dev_traffic_restart(priv, dev);