numam-dpdk/drivers/net/mlx5/mlx5_trigger.c

409 lines
9.3 KiB
C
Raw Normal View History

/* SPDX-License-Identifier: BSD-3-Clause
* Copyright 2015 6WIND S.A.
* Copyright 2015 Mellanox Technologies, Ltd
*/
#include <unistd.h>
#include <rte_ether.h>
#include <rte_ethdev_driver.h>
#include <rte_interrupts.h>
#include <rte_alarm.h>
#include "mlx5.h"
#include "mlx5_rxtx.h"
#include "mlx5_utils.h"
/**
* Stop traffic on Tx queues.
*
* @param dev
* Pointer to Ethernet device structure.
*/
static void
mlx5_txq_stop(struct rte_eth_dev *dev)
{
struct priv *priv = dev->data->dev_private;
unsigned int i;
for (i = 0; i != priv->txqs_n; ++i)
mlx5_txq_release(dev, i);
}
/**
* Start traffic on Tx queues.
*
* @param dev
* Pointer to Ethernet device structure.
*
* @return
* 0 on success, a negative errno value otherwise and rte_errno is set.
*/
static int
mlx5_txq_start(struct rte_eth_dev *dev)
{
struct priv *priv = dev->data->dev_private;
unsigned int i;
int ret;
/* Add memory regions to Tx queues. */
for (i = 0; i != priv->txqs_n; ++i) {
unsigned int idx = 0;
struct mlx5_mr *mr;
struct mlx5_txq_ctrl *txq_ctrl = mlx5_txq_get(dev, i);
if (!txq_ctrl)
continue;
LIST_FOREACH(mr, &priv->mr, next) {
mlx5_txq_mp2mr_reg(&txq_ctrl->txq, mr->mp, idx++);
if (idx == MLX5_PMD_TX_MP_CACHE)
break;
}
txq_alloc_elts(txq_ctrl);
txq_ctrl->ibv = mlx5_txq_ibv_new(dev, i);
if (!txq_ctrl->ibv) {
rte_errno = ENOMEM;
goto error;
}
}
ret = mlx5_tx_uar_remap(dev, priv->ctx->cmd_fd);
if (ret)
goto error;
return 0;
error:
ret = rte_errno; /* Save rte_errno before cleanup. */
mlx5_txq_stop(dev);
rte_errno = ret; /* Restore rte_errno. */
return -rte_errno;
}
/**
* Stop traffic on Rx queues.
*
* @param dev
* Pointer to Ethernet device structure.
*/
static void
mlx5_rxq_stop(struct rte_eth_dev *dev)
{
struct priv *priv = dev->data->dev_private;
unsigned int i;
for (i = 0; i != priv->rxqs_n; ++i)
mlx5_rxq_release(dev, i);
}
/**
* Start traffic on Rx queues.
*
* @param dev
* Pointer to Ethernet device structure.
*
* @return
* 0 on success, a negative errno value otherwise and rte_errno is set.
*/
static int
mlx5_rxq_start(struct rte_eth_dev *dev)
{
struct priv *priv = dev->data->dev_private;
unsigned int i;
int ret = 0;
for (i = 0; i != priv->rxqs_n; ++i) {
struct mlx5_rxq_ctrl *rxq_ctrl = mlx5_rxq_get(dev, i);
if (!rxq_ctrl)
continue;
ret = rxq_alloc_elts(rxq_ctrl);
if (ret)
goto error;
rxq_ctrl->ibv = mlx5_rxq_ibv_new(dev, i);
if (!rxq_ctrl->ibv)
goto error;
}
return 0;
error:
ret = rte_errno; /* Save rte_errno before cleanup. */
mlx5_rxq_stop(dev);
rte_errno = ret; /* Restore rte_errno. */
return -rte_errno;
}
/**
* DPDK callback to start the device.
*
* Simulate device start by attaching all configured flows.
*
* @param dev
* Pointer to Ethernet device structure.
*
* @return
* 0 on success, a negative errno value otherwise and rte_errno is set.
*/
int
mlx5_dev_start(struct rte_eth_dev *dev)
{
struct priv *priv = dev->data->dev_private;
struct mlx5_mr *mr = NULL;
int ret;
dev->data->dev_started = 1;
ret = mlx5_flow_create_drop_queue(dev);
if (ret) {
DRV_LOG(ERR, "port %u drop queue allocation failed: %s",
dev->data->port_id, strerror(rte_errno));
goto error;
}
DRV_LOG(DEBUG, "port %u allocating and configuring hash Rx queues",
dev->data->port_id);
rte_mempool_walk(mlx5_mp2mr_iter, priv);
ret = mlx5_txq_start(dev);
if (ret) {
DRV_LOG(ERR, "port %u Tx queue allocation failed: %s",
dev->data->port_id, strerror(rte_errno));
goto error;
}
ret = mlx5_rxq_start(dev);
if (ret) {
DRV_LOG(ERR, "port %u Rx queue allocation failed: %s",
dev->data->port_id, strerror(rte_errno));
goto error;
}
ret = mlx5_rx_intr_vec_enable(dev);
if (ret) {
DRV_LOG(ERR, "port %u Rx interrupt vector creation failed",
dev->data->port_id);
net/mlx5: fix Rx interrupts management This commit addresses various issues that may lead to undefined behavior when configuring Rx interrupts. While failure to create a Rx queue completion channel in rxq_ctrl_setup() prevents that queue from being created, existing queues still have theirs. Since the error handler disables dev_conf.intr_conf.rxq as well, subsequent calls to rxq_ctrl_setup() create Rx queues without interrupts. This leads to a scenario where not all Rx queues support interrupts; missing checks on the presence of completion channels may crash the application. Considering that the PMD is not supposed to disable user-provided configuration parameters (dev_conf.intr_conf.rxq), and that these can change for subsequent rxq_ctrl_setup() calls anyway, properly supporting a mixed mode where not all Rx queues have interrupts enabled is a better approach. To do so with a minimum set of changes, priv_intr_efd_enable() and priv_create_intr_vec() are first refactored as a single priv_rx_intr_vec_enable() function (same for their "disable" counterparts). Since they had to be used together, there was no point in keeping them separate. Remaining changes: - Always clean up before reconfiguring interrupts to avoid memory leaks. - Always clean up when closing the device. - Use malloc()/free() instead of their rte_*() counterparts since there is no need to store the vector in huge pages-backed memory. - Allow more Rx queues than the size of the event file descriptor array as long as Rx interrupts are not requested on all of them. - Properly clean up interrupt handle when disabling Rx interrupts (nb_efd and intr_vec reset to 0). - Check completion channel presence while toggling Rx interrupts on a given queue. Fixes: 3c7d44af252a ("net/mlx5: support user space Rx interrupt event") Cc: stable@dpdk.org Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
2017-06-14 11:49:17 +00:00
goto error;
}
mlx5_xstats_init(dev);
net/mlx5: fix link status behavior This behavior is mixed between what should be handled by the application and what is under PMD responsibility. According to DPDK API: - link_update() should only query the link status [1] - link_set_{up,down}() should only set the link to the according status [1] - dev_{start,stop}() should enable/disable traffic reception/emission [2] On this PMD, the link status is retrieved from the net device associated owned by the Linux Kernel, it does not means that even when this interface is down, the PMD cannot send/receive traffic from the NIC those two information are unrelated, until the physical port is active and has a link, the PMD can receive/send traffic on the wire. According to DPDK API, calling the rte_eth_dev_start() even when the Linux interface link is down is then possible and allowed, as the traffic will flow between the DPDK application and the Physical port. This also means that a synchronization between the Linux interface and the DPDK application remains under the DPDK application responsibility. To handle such synchronization the application should behave as the following scheme, to start: rte_eth_get_link(port_id, &link); if (link.link_status == ETH_DOWN) rte_eth_dev_set_link_up(port_id); rte_eth_dev_start(port_id); Taking in account the possible returned values for each function. and to stop: rte_eth_dev_stop(port_id); rte_eth_dev_set_link_down(port_id); The application should also set the LSC interrupt callbacks to catch and behave accordingly when the administrator set the Linux device down/up. The same callbacks are called when the link on the medium falls/raise. [1] https://dpdk.org/browse/dpdk/tree/lib/librte_ether/rte_ethdev_core.h [2] https://dpdk.org/browse/dpdk/tree/lib/librte_ether/rte_ethdev.h#n1677 Fixes: c7bf62255edf ("net/mlx5: fix handling link status event") Fixes: e313ef4c2fe8 ("net/mlx5: fix link state on device start") Cc: stable@dpdk.org Signed-off-by: Nelio Laranjeiro <nelio.laranjeiro@6wind.com> Acked-by: Adrien Mazarguil <adrien.mazarguil@6wind.com> Acked-by: Yongseok Koh <yskoh@mellanox.com>
2018-03-12 13:43:18 +00:00
ret = mlx5_traffic_enable(dev);
if (ret) {
net/mlx5: fix link status behavior This behavior is mixed between what should be handled by the application and what is under PMD responsibility. According to DPDK API: - link_update() should only query the link status [1] - link_set_{up,down}() should only set the link to the according status [1] - dev_{start,stop}() should enable/disable traffic reception/emission [2] On this PMD, the link status is retrieved from the net device associated owned by the Linux Kernel, it does not means that even when this interface is down, the PMD cannot send/receive traffic from the NIC those two information are unrelated, until the physical port is active and has a link, the PMD can receive/send traffic on the wire. According to DPDK API, calling the rte_eth_dev_start() even when the Linux interface link is down is then possible and allowed, as the traffic will flow between the DPDK application and the Physical port. This also means that a synchronization between the Linux interface and the DPDK application remains under the DPDK application responsibility. To handle such synchronization the application should behave as the following scheme, to start: rte_eth_get_link(port_id, &link); if (link.link_status == ETH_DOWN) rte_eth_dev_set_link_up(port_id); rte_eth_dev_start(port_id); Taking in account the possible returned values for each function. and to stop: rte_eth_dev_stop(port_id); rte_eth_dev_set_link_down(port_id); The application should also set the LSC interrupt callbacks to catch and behave accordingly when the administrator set the Linux device down/up. The same callbacks are called when the link on the medium falls/raise. [1] https://dpdk.org/browse/dpdk/tree/lib/librte_ether/rte_ethdev_core.h [2] https://dpdk.org/browse/dpdk/tree/lib/librte_ether/rte_ethdev.h#n1677 Fixes: c7bf62255edf ("net/mlx5: fix handling link status event") Fixes: e313ef4c2fe8 ("net/mlx5: fix link state on device start") Cc: stable@dpdk.org Signed-off-by: Nelio Laranjeiro <nelio.laranjeiro@6wind.com> Acked-by: Adrien Mazarguil <adrien.mazarguil@6wind.com> Acked-by: Yongseok Koh <yskoh@mellanox.com>
2018-03-12 13:43:18 +00:00
DRV_LOG(DEBUG, "port %u failed to set defaults flows",
dev->data->port_id);
goto error;
}
net/mlx5: fix link status behavior This behavior is mixed between what should be handled by the application and what is under PMD responsibility. According to DPDK API: - link_update() should only query the link status [1] - link_set_{up,down}() should only set the link to the according status [1] - dev_{start,stop}() should enable/disable traffic reception/emission [2] On this PMD, the link status is retrieved from the net device associated owned by the Linux Kernel, it does not means that even when this interface is down, the PMD cannot send/receive traffic from the NIC those two information are unrelated, until the physical port is active and has a link, the PMD can receive/send traffic on the wire. According to DPDK API, calling the rte_eth_dev_start() even when the Linux interface link is down is then possible and allowed, as the traffic will flow between the DPDK application and the Physical port. This also means that a synchronization between the Linux interface and the DPDK application remains under the DPDK application responsibility. To handle such synchronization the application should behave as the following scheme, to start: rte_eth_get_link(port_id, &link); if (link.link_status == ETH_DOWN) rte_eth_dev_set_link_up(port_id); rte_eth_dev_start(port_id); Taking in account the possible returned values for each function. and to stop: rte_eth_dev_stop(port_id); rte_eth_dev_set_link_down(port_id); The application should also set the LSC interrupt callbacks to catch and behave accordingly when the administrator set the Linux device down/up. The same callbacks are called when the link on the medium falls/raise. [1] https://dpdk.org/browse/dpdk/tree/lib/librte_ether/rte_ethdev_core.h [2] https://dpdk.org/browse/dpdk/tree/lib/librte_ether/rte_ethdev.h#n1677 Fixes: c7bf62255edf ("net/mlx5: fix handling link status event") Fixes: e313ef4c2fe8 ("net/mlx5: fix link state on device start") Cc: stable@dpdk.org Signed-off-by: Nelio Laranjeiro <nelio.laranjeiro@6wind.com> Acked-by: Adrien Mazarguil <adrien.mazarguil@6wind.com> Acked-by: Yongseok Koh <yskoh@mellanox.com>
2018-03-12 13:43:18 +00:00
ret = mlx5_flow_start(dev, &priv->flows);
if (ret) {
DRV_LOG(DEBUG, "port %u failed to set flows",
dev->data->port_id);
goto error;
}
dev->tx_pkt_burst = mlx5_select_tx_function(dev);
dev->rx_pkt_burst = mlx5_select_rx_function(dev);
mlx5_dev_interrupt_handler_install(dev);
return 0;
error:
ret = rte_errno; /* Save rte_errno before cleanup. */
/* Rollback. */
dev->data->dev_started = 0;
for (mr = LIST_FIRST(&priv->mr); mr; mr = LIST_FIRST(&priv->mr))
mlx5_mr_release(mr);
mlx5_flow_stop(dev, &priv->flows);
mlx5_traffic_disable(dev);
mlx5_txq_stop(dev);
mlx5_rxq_stop(dev);
mlx5_flow_delete_drop_queue(dev);
rte_errno = ret; /* Restore rte_errno. */
return -rte_errno;
}
/**
* DPDK callback to stop the device.
*
* Simulate device stop by detaching all configured flows.
*
* @param dev
* Pointer to Ethernet device structure.
*/
void
mlx5_dev_stop(struct rte_eth_dev *dev)
{
struct priv *priv = dev->data->dev_private;
struct mlx5_mr *mr;
dev->data->dev_started = 0;
/* Prevent crashes when queues are still in use. */
dev->rx_pkt_burst = removed_rx_burst;
dev->tx_pkt_burst = removed_tx_burst;
rte_wmb();
usleep(1000 * priv->rxqs_n);
DRV_LOG(DEBUG, "port %u cleaning up and destroying hash Rx queues",
dev->data->port_id);
mlx5_flow_stop(dev, &priv->flows);
mlx5_traffic_disable(dev);
mlx5_rx_intr_vec_disable(dev);
mlx5_dev_interrupt_handler_uninstall(dev);
mlx5_txq_stop(dev);
mlx5_rxq_stop(dev);
for (mr = LIST_FIRST(&priv->mr); mr; mr = LIST_FIRST(&priv->mr))
mlx5_mr_release(mr);
mlx5_flow_delete_drop_queue(dev);
}
/**
* Enable traffic flows configured by control plane
*
* @param dev
* Pointer to Ethernet device private data.
* @param dev
* Pointer to Ethernet device structure.
*
* @return
* 0 on success, a negative errno value otherwise and rte_errno is set.
*/
int
mlx5_traffic_enable(struct rte_eth_dev *dev)
{
struct priv *priv = dev->data->dev_private;
struct rte_flow_item_eth bcast = {
.dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
};
struct rte_flow_item_eth ipv6_multi_spec = {
.dst.addr_bytes = "\x33\x33\x00\x00\x00\x00",
};
struct rte_flow_item_eth ipv6_multi_mask = {
.dst.addr_bytes = "\xff\xff\x00\x00\x00\x00",
};
struct rte_flow_item_eth unicast = {
.src.addr_bytes = "\x00\x00\x00\x00\x00\x00",
};
struct rte_flow_item_eth unicast_mask = {
.dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
};
const unsigned int vlan_filter_n = priv->vlan_filter_n;
const struct ether_addr cmp = {
.addr_bytes = "\x00\x00\x00\x00\x00\x00",
};
unsigned int i;
unsigned int j;
int ret;
if (priv->isolated)
return 0;
if (dev->data->promiscuous) {
struct rte_flow_item_eth promisc = {
.dst.addr_bytes = "\x00\x00\x00\x00\x00\x00",
.src.addr_bytes = "\x00\x00\x00\x00\x00\x00",
.type = 0,
};
ret = mlx5_ctrl_flow(dev, &promisc, &promisc);
if (ret)
goto error;
}
if (dev->data->all_multicast) {
struct rte_flow_item_eth multicast = {
.dst.addr_bytes = "\x01\x00\x00\x00\x00\x00",
.src.addr_bytes = "\x00\x00\x00\x00\x00\x00",
.type = 0,
};
ret = mlx5_ctrl_flow(dev, &multicast, &multicast);
if (ret)
goto error;
} else {
/* Add broadcast/multicast flows. */
for (i = 0; i != vlan_filter_n; ++i) {
uint16_t vlan = priv->vlan_filter[i];
struct rte_flow_item_vlan vlan_spec = {
.tci = rte_cpu_to_be_16(vlan),
};
struct rte_flow_item_vlan vlan_mask = {
.tci = 0xffff,
};
ret = mlx5_ctrl_flow_vlan(dev, &bcast, &bcast,
&vlan_spec, &vlan_mask);
if (ret)
goto error;
ret = mlx5_ctrl_flow_vlan(dev, &ipv6_multi_spec,
&ipv6_multi_mask,
&vlan_spec, &vlan_mask);
if (ret)
goto error;
}
if (!vlan_filter_n) {
ret = mlx5_ctrl_flow(dev, &bcast, &bcast);
if (ret)
goto error;
ret = mlx5_ctrl_flow(dev, &ipv6_multi_spec,
&ipv6_multi_mask);
if (ret)
goto error;
}
}
/* Add MAC address flows. */
for (i = 0; i != MLX5_MAX_MAC_ADDRESSES; ++i) {
struct ether_addr *mac = &dev->data->mac_addrs[i];
if (!memcmp(mac, &cmp, sizeof(*mac)))
continue;
memcpy(&unicast.dst.addr_bytes,
mac->addr_bytes,
ETHER_ADDR_LEN);
for (j = 0; j != vlan_filter_n; ++j) {
uint16_t vlan = priv->vlan_filter[j];
struct rte_flow_item_vlan vlan_spec = {
.tci = rte_cpu_to_be_16(vlan),
};
struct rte_flow_item_vlan vlan_mask = {
.tci = 0xffff,
};
ret = mlx5_ctrl_flow_vlan(dev, &unicast,
&unicast_mask,
&vlan_spec,
&vlan_mask);
if (ret)
goto error;
}
if (!vlan_filter_n) {
ret = mlx5_ctrl_flow(dev, &unicast, &unicast_mask);
if (ret)
goto error;
}
}
return 0;
error:
ret = rte_errno; /* Save rte_errno before cleanup. */
mlx5_flow_list_flush(dev, &priv->ctrl_flows);
rte_errno = ret; /* Restore rte_errno. */
return -rte_errno;
}
/**
* Disable traffic flows configured by control plane
*
* @param dev
* Pointer to Ethernet device private data.
*/
void
mlx5_traffic_disable(struct rte_eth_dev *dev)
{
struct priv *priv = dev->data->dev_private;
mlx5_flow_list_flush(dev, &priv->ctrl_flows);
}
/**
* Restart traffic flows configured by control plane
*
* @param dev
* Pointer to Ethernet device private data.
*
* @return
* 0 on success, a negative errno value otherwise and rte_errno is set.
*/
int
mlx5_traffic_restart(struct rte_eth_dev *dev)
{
if (dev->data->dev_started) {
mlx5_traffic_disable(dev);
return mlx5_traffic_enable(dev);
}
return 0;
}