The link_update function pointer is called directly on a sub-device, via
its rte_eth_dev structure. In addition, it assumes that if link_update
returns a value other than 0 or -1, an error occurred. That's not
accurate. For example, the mlx5 PMD returns a positive value to indicate
that the link status was updated. This results in fs_link_update failing
when it really should have succeeded.

The code now uses the public APIs rte_eth_link_get and
rte_eth_link_get_nowait to query the link status of each sub-device. It
also uses rte_eth_linkstatus_set to set the link status of the failsafe
device.

Fixes: ae80146c5a1b ("net/failsafe: fix removed device handling")
Cc: Matan Azrad <ma...@nvidia.com>
Cc: sta...@dpdk.org

Signed-off-by: Luc Pelletier <lucp.at.w...@gmail.com>
---
 drivers/net/failsafe/failsafe_ops.c | 37 +++++++++++++----------------
 1 file changed, 17 insertions(+), 20 deletions(-)

diff --git a/drivers/net/failsafe/failsafe_ops.c 
b/drivers/net/failsafe/failsafe_ops.c
index d357e1bc83..b66dfa269b 100644
--- a/drivers/net/failsafe/failsafe_ops.c
+++ b/drivers/net/failsafe/failsafe_ops.c
@@ -820,34 +820,31 @@ fs_link_update(struct rte_eth_dev *dev,
 {
        struct sub_device *sdev;
        uint8_t i;
-       int ret;
+       int ret = -1;
+       int sdev_link_ret;
+       struct rte_eth_link link_info;
 
        fs_lock(dev, 0);
        FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
-               DEBUG("Calling link_update on sub_device %d", i);
-               ret = (SUBOPS(sdev, link_update))(ETH(sdev), wait_to_complete);
-               if (ret && ret != -1 && sdev->remove == 0 &&
-                   rte_eth_dev_is_removed(PORT_ID(sdev)) == 0) {
-                       ERROR("Link update failed for sub_device %d with error 
%d",
-                             i, ret);
-                       fs_unlock(dev, 0);
-                       return ret;
+               DEBUG("Calling rte_eth_link_get on sub_device %d", i);
+               if (wait_to_complete) {
+                       sdev_link_ret = rte_eth_link_get(PORT_ID(sdev), 
&link_info);
+               } else {
+                       sdev_link_ret = rte_eth_link_get_nowait(PORT_ID(sdev),
+                               &link_info);
                }
-       }
-       if (TX_SUBDEV(dev)) {
-               struct rte_eth_link *l1;
-               struct rte_eth_link *l2;
 
-               l1 = &dev->data->dev_link;
-               l2 = &ETH(TX_SUBDEV(dev))->data->dev_link;
-               if (memcmp(l1, l2, sizeof(*l1))) {
-                       *l1 = *l2;
-                       fs_unlock(dev, 0);
-                       return 0;
+               if (likely(sdev_link_ret == 0)) {
+                       if (TX_SUBDEV(dev) == sdev)
+                               ret = rte_eth_linkstatus_set(dev, &link_info);
+               } else if (sdev->remove == 0 &&
+                               rte_eth_dev_is_removed(PORT_ID(sdev)) == 0) {
+                       ERROR("Link get failed for sub_device %d with error %d",
+                               i, sdev_link_ret);
                }
        }
        fs_unlock(dev, 0);
-       return -1;
+       return ret;
 }
 
 static int
-- 
2.38.1

Reply via email to