From: Dmitry Kozlyuk <dkozlyuk@nvidia.com>
To: <stable@dpdk.org>
Cc: Christian Ehrhardt <christian.ehrhardt@canonical.com>,
"Viacheslav Ovsiienko" <viacheslavo@nvidia.com>
Subject: [PATCH 19.11 2/3] net/mlx5: fix link status change detection
Date: Fri, 11 Mar 2022 10:06:26 +0200 [thread overview]
Message-ID: <20220311080627.1195847-3-dkozlyuk@nvidia.com> (raw)
In-Reply-To: <20220311080627.1195847-1-dkozlyuk@nvidia.com>
[ upstream commit 17f95513adca1f4ee5bba305b154ac984ee50cee ]
Sometimes net/mlx5 devices did not detect link status change to "up".
Each shared device was monitoring IBV_EVENT_PORT_{ACTIVE,ERR}
and queried the link status upon receiving the event.
IBV_EVENT_PORT_ACTIVE is delivered when the logical link status
(UP flag) is set, but the physical link status (RUNNING flag)
may be down at that time, in which case the new link status
would be errornously considered down.
IBV interface is insufficient for the task.
Monitor interface events using Netlink.
Fixes: 198a3c339a8f ("mlx5: handle link status interrupts")
Signed-off-by: Dmitry Kozlyuk <dkozlyuk@nvidia.com>
Reviewed-by: Viacheslav Ovsiienko <viacheslavo@nvidia.com>
---
drivers/net/mlx5/mlx5.c | 40 +++++++++++++++++++++
drivers/net/mlx5/mlx5.h | 3 ++
drivers/net/mlx5/mlx5_ethdev.c | 63 ++++++++++++++++++++++++++-------
drivers/net/mlx5/mlx5_trigger.c | 12 +++++--
4 files changed, 104 insertions(+), 14 deletions(-)
diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c
index 27e04b5d9e..068b0ef981 100644
--- a/drivers/net/mlx5/mlx5.c
+++ b/drivers/net/mlx5/mlx5.c
@@ -470,6 +470,40 @@ mlx5_restore_doorbell_mapping_env(int value)
setenv(MLX5_SHUT_UP_BF, value ? "1" : "0", 1);
}
+static int
+mlx5_os_dev_shared_handler_install_lsc(struct mlx5_ibv_shared *sh)
+{
+ int nlsk_fd, flags, ret;
+
+ nlsk_fd = mlx5_nl_init(NETLINK_ROUTE, RTMGRP_LINK);
+ if (nlsk_fd < 0) {
+ DRV_LOG(ERR, "Failed to create a socket for Netlink events: %s",
+ rte_strerror(rte_errno));
+ return -1;
+ }
+ flags = fcntl(nlsk_fd, F_GETFL);
+ ret = fcntl(nlsk_fd, F_SETFL, flags | O_NONBLOCK);
+ if (ret != 0) {
+ DRV_LOG(ERR, "Failed to make Netlink event socket non-blocking: %s",
+ strerror(errno));
+ rte_errno = errno;
+ goto error;
+ }
+ sh->intr_handle_nl.type = RTE_INTR_HANDLE_EXT;
+ sh->intr_handle_nl.fd = nlsk_fd;
+ if (rte_intr_callback_register(&sh->intr_handle_nl,
+ mlx5_dev_interrupt_handler_nl,
+ sh) != 0) {
+ DRV_LOG(ERR, "Failed to register Netlink events interrupt");
+ sh->intr_handle_nl.fd = -1;
+ goto error;
+ }
+ return 0;
+error:
+ close(nlsk_fd);
+ return -1;
+}
+
/**
* Install shared asynchronous device events handler.
* This function is implemented to support event sharing
@@ -499,6 +533,11 @@ mlx5_dev_shared_handler_install(struct mlx5_ibv_shared *sh)
sh->intr_handle.fd = -1;
}
}
+ sh->intr_handle_nl.fd = -1;
+ if (mlx5_os_dev_shared_handler_install_lsc(sh) < 0) {
+ DRV_LOG(INFO, "Fail to install the shared Netlink event handler.");
+ sh->intr_handle_nl.fd = -1;
+ }
if (sh->devx) {
#ifdef HAVE_IBV_DEVX_ASYNC
sh->intr_handle_devx.fd = -1;
@@ -651,6 +690,7 @@ mlx5_alloc_shared_ibctx(const struct mlx5_dev_spawn_data *spawn,
for (i = 0; i < sh->max_port; i++) {
sh->port[i].ih_port_id = RTE_MAX_ETHPORTS;
sh->port[i].devx_ih_port_id = RTE_MAX_ETHPORTS;
+ sh->port[i].nl_ih_port_id = RTE_MAX_ETHPORTS;
}
sh->pd = mlx5_glue->alloc_pd(sh->ctx);
if (sh->pd == NULL) {
diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
index b74f1bbc83..1cf5f41689 100644
--- a/drivers/net/mlx5/mlx5.h
+++ b/drivers/net/mlx5/mlx5.h
@@ -575,6 +575,7 @@ struct mlx5_flow_counter_mng {
struct mlx5_ibv_shared_port {
uint32_t ih_port_id;
uint32_t devx_ih_port_id;
+ uint32_t nl_ih_port_id;
/*
* Interrupt handler port_id. Used by shared interrupt
* handler to find the corresponding rte_eth device
@@ -693,6 +694,7 @@ struct mlx5_ibv_shared {
/* Shared interrupt handler section. */
struct rte_intr_handle intr_handle; /* Interrupt handler for device. */
struct rte_intr_handle intr_handle_devx; /* DEVX interrupt handler. */
+ struct rte_intr_handle intr_handle_nl; /* Netlink interrupt handler. */
struct mlx5dv_devx_cmd_comp *devx_comp; /* DEVX async comp obj. */
struct mlx5_devx_obj *tis; /* TIS object. */
struct mlx5_devx_obj *td; /* Transport domain. */
@@ -841,6 +843,7 @@ int mlx5_dev_to_pci_addr(const char *dev_path,
void mlx5_dev_link_status_handler(void *arg);
void mlx5_dev_interrupt_handler(void *arg);
void mlx5_dev_interrupt_handler_devx(void *arg);
+void mlx5_dev_interrupt_handler_nl(void *arg);
void mlx5_dev_interrupt_handler_uninstall(struct rte_eth_dev *dev);
void mlx5_dev_interrupt_handler_install(struct rte_eth_dev *dev);
int mlx5_set_link_down(struct rte_eth_dev *dev);
diff --git a/drivers/net/mlx5/mlx5_ethdev.c b/drivers/net/mlx5/mlx5_ethdev.c
index 7af7fb0f9f..5334377c10 100644
--- a/drivers/net/mlx5/mlx5_ethdev.c
+++ b/drivers/net/mlx5/mlx5_ethdev.c
@@ -1301,6 +1301,57 @@ mlx5_dev_interrupt_device_fatal(struct mlx5_ibv_shared *sh)
}
}
+static void
+mlx5_dev_interrupt_nl_cb(struct nlmsghdr *hdr, void *cb_arg)
+{
+ struct mlx5_ibv_shared *sh = cb_arg;
+ uint32_t i;
+ uint32_t if_index;
+
+ if (mlx5_nl_parse_link_status_update(hdr, &if_index) < 0)
+ return;
+ for (i = 0; i < sh->max_port; i++) {
+ struct mlx5_ibv_shared_port *port = &sh->port[i];
+ struct rte_eth_dev *dev;
+ struct mlx5_priv *priv;
+ bool configured;
+
+ if (port->nl_ih_port_id >= RTE_MAX_ETHPORTS)
+ continue;
+ dev = &rte_eth_devices[port->nl_ih_port_id];
+ configured = dev->process_private != NULL;
+ /* Probing may initiate an LSC before configuration is done. */
+ if (configured && !dev->data->dev_conf.intr_conf.lsc)
+ break;
+ priv = dev->data->dev_private;
+ if (priv->if_index == if_index) {
+ /* Block logical LSC events. */
+ uint16_t prev_status = dev->data->dev_link.link_status;
+
+ if (mlx5_link_update(dev, 0) < 0)
+ DRV_LOG(ERR, "Failed to update link status: %s",
+ rte_strerror(rte_errno));
+ else if (prev_status != dev->data->dev_link.link_status)
+ _rte_eth_dev_callback_process
+ (dev, RTE_ETH_EVENT_INTR_LSC, NULL);
+ break;
+ }
+ }
+}
+
+void
+mlx5_dev_interrupt_handler_nl(void *arg)
+{
+ struct mlx5_ibv_shared *sh = arg;
+ int nlsk_fd = sh->intr_handle_nl.fd;
+
+ if (nlsk_fd < 0)
+ return;
+ if (mlx5_nl_read_events(nlsk_fd, mlx5_dev_interrupt_nl_cb, sh) < 0)
+ DRV_LOG(ERR, "Failed to process Netlink events: %s",
+ rte_strerror(rte_errno));
+}
+
/**
* Handle shared asynchronous events the NIC (removal event
* and link status change). Supports multiport IB device.
@@ -1364,18 +1415,6 @@ mlx5_dev_interrupt_handler(void *cb_arg)
tmp = sh->port[tmp - 1].ih_port_id;
dev = &rte_eth_devices[tmp];
assert(dev);
- if ((event.event_type == IBV_EVENT_PORT_ACTIVE ||
- event.event_type == IBV_EVENT_PORT_ERR) &&
- dev->data->dev_conf.intr_conf.lsc) {
- mlx5_glue->ack_async_event(&event);
- if (mlx5_link_update(dev, 0) == -EAGAIN) {
- usleep(0);
- continue;
- }
- _rte_eth_dev_callback_process
- (dev, RTE_ETH_EVENT_INTR_LSC, NULL);
- continue;
- }
DRV_LOG(DEBUG,
"port %u cannot handle an unknown event (type %d)",
dev->data->port_id, event.event_type);
diff --git a/drivers/net/mlx5/mlx5_trigger.c b/drivers/net/mlx5/mlx5_trigger.c
index 04b06e11d7..e91970ddae 100644
--- a/drivers/net/mlx5/mlx5_trigger.c
+++ b/drivers/net/mlx5/mlx5_trigger.c
@@ -331,11 +331,18 @@ mlx5_dev_start(struct rte_eth_dev *dev)
priv->sh->port[priv->ibv_port - 1].ih_port_id =
(uint32_t)dev->data->port_id;
} else {
- DRV_LOG(INFO, "port %u starts without LSC and RMV interrupts.",
+ DRV_LOG(INFO, "port %u starts without RMV interrupts.",
dev->data->port_id);
- dev->data->dev_conf.intr_conf.lsc = 0;
dev->data->dev_conf.intr_conf.rmv = 0;
}
+ if (priv->sh->intr_handle_nl.fd >= 0) {
+ priv->sh->port[priv->ibv_port - 1].nl_ih_port_id =
+ (uint32_t)dev->data->port_id;
+ } else {
+ DRV_LOG(INFO, "port %u starts without LSC interrupts.",
+ dev->data->port_id);
+ dev->data->dev_conf.intr_conf.lsc = 0;
+ }
if (priv->sh->intr_handle_devx.fd >= 0)
priv->sh->port[priv->ibv_port - 1].devx_ih_port_id =
(uint32_t)dev->data->port_id;
@@ -379,6 +386,7 @@ mlx5_dev_stop(struct rte_eth_dev *dev)
mlx5_rx_intr_vec_disable(dev);
priv->sh->port[priv->ibv_port - 1].ih_port_id = RTE_MAX_ETHPORTS;
priv->sh->port[priv->ibv_port - 1].devx_ih_port_id = RTE_MAX_ETHPORTS;
+ priv->sh->port[priv->ibv_port - 1].nl_ih_port_id = RTE_MAX_ETHPORTS;
mlx5_txq_stop(dev);
mlx5_rxq_stop(dev);
}
--
2.25.1
next prev parent reply other threads:[~2022-03-11 8:06 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-11 8:06 [PATCH 19.11 0/3] net/mlx5: fix link state detection Dmitry Kozlyuk
2022-03-11 8:06 ` [PATCH 19.11 1/3] common/mlx5: add Netlink event helpers Dmitry Kozlyuk
2022-03-11 8:06 ` Dmitry Kozlyuk [this message]
2022-03-11 8:06 ` [PATCH 19.11 3/3] net/mlx5: fix initial link status detection Dmitry Kozlyuk
2022-03-11 10:06 ` [PATCH 19.11 0/3] net/mlx5: fix link state detection Christian Ehrhardt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220311080627.1195847-3-dkozlyuk@nvidia.com \
--to=dkozlyuk@nvidia.com \
--cc=christian.ehrhardt@canonical.com \
--cc=stable@dpdk.org \
--cc=viacheslavo@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).