From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id 8F4171B704 for ; Wed, 9 May 2018 17:29:14 +0200 (CEST) Received: from Internal Mail-Server by MTLPINE1 (envelope-from shahafs@mellanox.com) with ESMTPS (AES256-SHA encrypted); 9 May 2018 18:06:12 +0300 Received: from unicorn01.mtl.labs.mlnx. (unicorn01.mtl.labs.mlnx [10.7.12.62]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id w49F4SrT008373; Wed, 9 May 2018 18:04:29 +0300 From: Shahaf Shuler To: bluca@debian.org Cc: stable@dpdk.org, nelio.laranjeiro@6wind.com, adrien.mazarguil@6wind.com, yskoh@mellanox.com Date: Wed, 9 May 2018 18:04:04 +0300 Message-Id: X-Mailer: git-send-email 2.12.0 MIME-Version: 1.0 In-Reply-To: References: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [dpdk-stable] [PATCH v2 12/20] net/mlx5: fix link status behavior X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 May 2018 15:29:14 -0000 From: Nélio Laranjeiro [ backported from upstream commit 7ba5320baa3285bf8beca96cc025ff56b494060d ] 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 Acked-by: Adrien Mazarguil Acked-by: Yongseok Koh --- drivers/net/mlx5/mlx5.c | 2 +- drivers/net/mlx5/mlx5_ethdev.c | 90 +----------------------------------- drivers/net/mlx5/mlx5_trigger.c | 14 ++++-- 3 files changed, 11 insertions(+), 95 deletions(-) diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index a3b705f351..fc934b8018 100644 --- a/drivers/net/mlx5/mlx5.c +++ b/drivers/net/mlx5/mlx5.c @@ -927,7 +927,7 @@ mlx5_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, (void *)((uintptr_t)&alctr)); /* Bring Ethernet device up. */ DEBUG("forcing Ethernet interface up"); - mlx5_set_flags(eth_dev, ~IFF_UP, IFF_UP); + mlx5_set_link_up(eth_dev); /* Store device configuration on private structure. */ priv->config = config; continue; diff --git a/drivers/net/mlx5/mlx5_ethdev.c b/drivers/net/mlx5/mlx5_ethdev.c index 8a9e00c3b7..03ee3281e8 100644 --- a/drivers/net/mlx5/mlx5_ethdev.c +++ b/drivers/net/mlx5/mlx5_ethdev.c @@ -636,78 +636,6 @@ mlx5_link_update_unlocked_gs(struct rte_eth_dev *dev) } /** - * Enable receiving and transmitting traffic. - * - * @param dev - * Pointer to Ethernet device. - */ -static void -mlx5_link_start(struct rte_eth_dev *dev) -{ - struct priv *priv = dev->data->dev_private; - int ret; - - dev->tx_pkt_burst = mlx5_select_tx_function(dev); - dev->rx_pkt_burst = mlx5_select_rx_function(dev); - ret = mlx5_traffic_enable(dev); - if (ret) { - ERROR("%p: error occurred while configuring control flows: %s", - (void *)dev, strerror(rte_errno)); - return; - } - ret = mlx5_flow_start(dev, &priv->flows); - if (ret) { - ERROR("%p: error occurred while configuring flows: %s", - (void *)dev, strerror(rte_errno)); - } -} - -/** - * Disable receiving and transmitting traffic. - * - * @param dev - * Pointer to Ethernet device. - */ -static void -mlx5_link_stop(struct rte_eth_dev *dev) -{ - struct priv *priv = dev->data->dev_private; - - mlx5_flow_stop(dev, &priv->flows); - mlx5_traffic_disable(dev); - dev->rx_pkt_burst = removed_rx_burst; - dev->tx_pkt_burst = removed_tx_burst; -} - -/** - * Querying the link status till it changes to the desired state. - * Number of query attempts is bounded by MLX5_MAX_LINK_QUERY_ATTEMPTS. - * - * @param dev - * Pointer to Ethernet device. - * @param status - * Link desired status. - * - * @return - * 0 on success, a negative errno value otherwise and rte_errno is set. - */ -int -mlx5_force_link_status_change(struct rte_eth_dev *dev, int status) -{ - int try = 0; - - while (try < MLX5_MAX_LINK_QUERY_ATTEMPTS) { - mlx5_link_update(dev, 0); - if (dev->data->dev_link.link_status == status) - return 0; - try++; - sleep(1); - } - rte_errno = EAGAIN; - return -rte_errno; -} - -/** * DPDK callback to retrieve physical link information. * * @param dev @@ -722,26 +650,10 @@ int mlx5_link_update(struct rte_eth_dev *dev, int wait_to_complete __rte_unused) { int ret; - struct rte_eth_link dev_link = dev->data->dev_link; ret = mlx5_link_update_unlocked_gset(dev); - if (ret) { + if (ret) ret = mlx5_link_update_unlocked_gs(dev); - if (ret) - return ret; - } - /* If lsc interrupt is disabled, should always be ready for traffic. */ - if (!dev->data->dev_conf.intr_conf.lsc) { - mlx5_link_start(dev); - return 0; - } - /* Re-select burst callbacks only if link status has been changed. */ - if (!ret && dev_link.link_status != dev->data->dev_link.link_status) { - if (dev->data->dev_link.link_status == ETH_LINK_UP) - mlx5_link_start(dev); - else - mlx5_link_stop(dev); - } return 0; } diff --git a/drivers/net/mlx5/mlx5_trigger.c b/drivers/net/mlx5/mlx5_trigger.c index 4e396b7f02..ecef88cdf6 100644 --- a/drivers/net/mlx5/mlx5_trigger.c +++ b/drivers/net/mlx5/mlx5_trigger.c @@ -175,15 +175,19 @@ mlx5_dev_start(struct rte_eth_dev *dev) goto error; } mlx5_xstats_init(dev); - /* Update link status and Tx/Rx callbacks for the first time. */ - memset(&dev->data->dev_link, 0, sizeof(struct rte_eth_link)); - INFO("Forcing port %u link to be up", dev->data->port_id); - ret = mlx5_force_link_status_change(dev, ETH_LINK_UP); + ret = mlx5_traffic_enable(dev); if (ret) { - DEBUG("Failed to set port %u link to be up", + DEBUG("port %u failed to set defaults flows", dev->data->port_id); goto error; } + ret = mlx5_flow_start(dev, &priv->flows); + if (ret) { + 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: -- 2.12.0 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id C6FB11B6FA for ; Wed, 9 May 2018 17:29:33 +0200 (CEST) Received: from Internal Mail-Server by MTLPINE1 (envelope-from shahafs@mellanox.com) with ESMTPS (AES256-SHA encrypted); 9 May 2018 18:19:34 +0300 Received: from unicorn01.mtl.labs.mlnx. (unicorn01.mtl.labs.mlnx [10.7.12.62]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id w49FHoVJ003207; Wed, 9 May 2018 18:17:51 +0300 From: Shahaf Shuler To: shahafs@mellanox.com Cc: yskoh@mellanox.com, =?UTF-8?q?N=C3=A9lio=20Laranjeiro?= , stable@dpdk.org Date: Wed, 9 May 2018 18:17:40 +0300 Message-Id: X-Mailer: git-send-email 2.12.0 MIME-Version: 1.0 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit Subject: [dpdk-stable] [PATCH v2 12/20] net/mlx5: fix link status behavior X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 May 2018 15:29:34 -0000 Message-ID: <20180509151740.xI4SvdGXLUg_pZZwqV7Z-wbfSJWhaReSEdlpMwbt_ao@z> From: Nélio Laranjeiro [ backported from upstream commit 7ba5320baa3285bf8beca96cc025ff56b494060d ] 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 Acked-by: Adrien Mazarguil Acked-by: Yongseok Koh --- drivers/net/mlx5/mlx5.c | 2 +- drivers/net/mlx5/mlx5_ethdev.c | 90 +----------------------------------- drivers/net/mlx5/mlx5_trigger.c | 14 ++++-- 3 files changed, 11 insertions(+), 95 deletions(-) diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index a3b705f351..fc934b8018 100644 --- a/drivers/net/mlx5/mlx5.c +++ b/drivers/net/mlx5/mlx5.c @@ -927,7 +927,7 @@ mlx5_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, (void *)((uintptr_t)&alctr)); /* Bring Ethernet device up. */ DEBUG("forcing Ethernet interface up"); - mlx5_set_flags(eth_dev, ~IFF_UP, IFF_UP); + mlx5_set_link_up(eth_dev); /* Store device configuration on private structure. */ priv->config = config; continue; diff --git a/drivers/net/mlx5/mlx5_ethdev.c b/drivers/net/mlx5/mlx5_ethdev.c index 8a9e00c3b7..03ee3281e8 100644 --- a/drivers/net/mlx5/mlx5_ethdev.c +++ b/drivers/net/mlx5/mlx5_ethdev.c @@ -636,78 +636,6 @@ mlx5_link_update_unlocked_gs(struct rte_eth_dev *dev) } /** - * Enable receiving and transmitting traffic. - * - * @param dev - * Pointer to Ethernet device. - */ -static void -mlx5_link_start(struct rte_eth_dev *dev) -{ - struct priv *priv = dev->data->dev_private; - int ret; - - dev->tx_pkt_burst = mlx5_select_tx_function(dev); - dev->rx_pkt_burst = mlx5_select_rx_function(dev); - ret = mlx5_traffic_enable(dev); - if (ret) { - ERROR("%p: error occurred while configuring control flows: %s", - (void *)dev, strerror(rte_errno)); - return; - } - ret = mlx5_flow_start(dev, &priv->flows); - if (ret) { - ERROR("%p: error occurred while configuring flows: %s", - (void *)dev, strerror(rte_errno)); - } -} - -/** - * Disable receiving and transmitting traffic. - * - * @param dev - * Pointer to Ethernet device. - */ -static void -mlx5_link_stop(struct rte_eth_dev *dev) -{ - struct priv *priv = dev->data->dev_private; - - mlx5_flow_stop(dev, &priv->flows); - mlx5_traffic_disable(dev); - dev->rx_pkt_burst = removed_rx_burst; - dev->tx_pkt_burst = removed_tx_burst; -} - -/** - * Querying the link status till it changes to the desired state. - * Number of query attempts is bounded by MLX5_MAX_LINK_QUERY_ATTEMPTS. - * - * @param dev - * Pointer to Ethernet device. - * @param status - * Link desired status. - * - * @return - * 0 on success, a negative errno value otherwise and rte_errno is set. - */ -int -mlx5_force_link_status_change(struct rte_eth_dev *dev, int status) -{ - int try = 0; - - while (try < MLX5_MAX_LINK_QUERY_ATTEMPTS) { - mlx5_link_update(dev, 0); - if (dev->data->dev_link.link_status == status) - return 0; - try++; - sleep(1); - } - rte_errno = EAGAIN; - return -rte_errno; -} - -/** * DPDK callback to retrieve physical link information. * * @param dev @@ -722,26 +650,10 @@ int mlx5_link_update(struct rte_eth_dev *dev, int wait_to_complete __rte_unused) { int ret; - struct rte_eth_link dev_link = dev->data->dev_link; ret = mlx5_link_update_unlocked_gset(dev); - if (ret) { + if (ret) ret = mlx5_link_update_unlocked_gs(dev); - if (ret) - return ret; - } - /* If lsc interrupt is disabled, should always be ready for traffic. */ - if (!dev->data->dev_conf.intr_conf.lsc) { - mlx5_link_start(dev); - return 0; - } - /* Re-select burst callbacks only if link status has been changed. */ - if (!ret && dev_link.link_status != dev->data->dev_link.link_status) { - if (dev->data->dev_link.link_status == ETH_LINK_UP) - mlx5_link_start(dev); - else - mlx5_link_stop(dev); - } return 0; } diff --git a/drivers/net/mlx5/mlx5_trigger.c b/drivers/net/mlx5/mlx5_trigger.c index 4e396b7f02..ecef88cdf6 100644 --- a/drivers/net/mlx5/mlx5_trigger.c +++ b/drivers/net/mlx5/mlx5_trigger.c @@ -175,15 +175,19 @@ mlx5_dev_start(struct rte_eth_dev *dev) goto error; } mlx5_xstats_init(dev); - /* Update link status and Tx/Rx callbacks for the first time. */ - memset(&dev->data->dev_link, 0, sizeof(struct rte_eth_link)); - INFO("Forcing port %u link to be up", dev->data->port_id); - ret = mlx5_force_link_status_change(dev, ETH_LINK_UP); + ret = mlx5_traffic_enable(dev); if (ret) { - DEBUG("Failed to set port %u link to be up", + DEBUG("port %u failed to set defaults flows", dev->data->port_id); goto error; } + ret = mlx5_flow_start(dev, &priv->flows); + if (ret) { + 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: -- 2.12.0