Blame SOURCES/0273-netdrv-net-mlx5e-Add-support-for-devlink-port-in-non.patch

d8f823
From 5fa5489fb414fc500bb9eeef1f1600d8a1e0e2aa Mon Sep 17 00:00:00 2001
d8f823
From: Alaa Hleihel <ahleihel@redhat.com>
d8f823
Date: Mon, 1 Jun 2020 15:40:25 -0400
d8f823
Subject: [PATCH 273/312] [netdrv] net/mlx5e: Add support for devlink-port in
d8f823
 non-representors mode
d8f823
d8f823
Message-id: <20200601154102.25980-3-ahleihel@redhat.com>
d8f823
Patchwork-id: 315707
d8f823
Patchwork-instance: patchwork
d8f823
O-Subject: [RHEL8.3 BZ 1842258 02/39] net/mlx5e: Add support for devlink-port in non-representors mode
d8f823
Bugzilla: 1842258 1790226
d8f823
RH-Acked-by: Honggang Li <honli@redhat.com>
d8f823
RH-Acked-by: Kamal Heib <kheib@redhat.com>
d8f823
RH-Acked-by: Marcelo Leitner <mleitner@redhat.com>
d8f823
RH-Acked-by: Jarod Wilson <jarod@redhat.com>
d8f823
d8f823
Bugzilla: http://bugzilla.redhat.com/1790226
d8f823
Bugzilla: http://bugzilla.redhat.com/1842258
d8f823
Upstream: v5.7-rc1
d8f823
d8f823
commit c6acd629eec754a9679f922d51f90e44c769b80c
d8f823
Author: Vladyslav Tarasiuk <vladyslavt@mellanox.com>
d8f823
Date:   Wed Nov 13 17:19:47 2019 +0200
d8f823
d8f823
    net/mlx5e: Add support for devlink-port in non-representors mode
d8f823
d8f823
    Added devlink_port field to mlx5e_priv structure and a callback to
d8f823
    netdev ops to enable devlink to get info about the port. The port
d8f823
    registration happens at driver initialization.
d8f823
d8f823
    Signed-off-by: Vladyslav Tarasiuk <vladyslavt@mellanox.com>
d8f823
    Reviewed-by: Moshe Shemesh <moshe@mellanox.com>
d8f823
    Reviewed-by: Jiri Pirko <jiri@mellanox.com>
d8f823
    Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
d8f823
d8f823
Signed-off-by: Alaa Hleihel <ahleihel@redhat.com>
d8f823
Signed-off-by: Frantisek Hrbata <fhrbata@redhat.com>
d8f823
---
d8f823
 drivers/net/ethernet/mellanox/mlx5/core/Makefile   |  2 +-
d8f823
 drivers/net/ethernet/mellanox/mlx5/core/en.h       |  1 +
d8f823
 .../net/ethernet/mellanox/mlx5/core/en/devlink.c   | 38 ++++++++++++++++++++++
d8f823
 .../net/ethernet/mellanox/mlx5/core/en/devlink.h   | 15 +++++++++
d8f823
 drivers/net/ethernet/mellanox/mlx5/core/en_main.c  | 11 +++++++
d8f823
 5 files changed, 66 insertions(+), 1 deletion(-)
d8f823
 create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en/devlink.c
d8f823
 create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en/devlink.h
d8f823
d8f823
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/Makefile b/drivers/net/ethernet/mellanox/mlx5/core/Makefile
d8f823
index 9e85def607b9..51d6cc94adba 100644
d8f823
--- a/drivers/net/ethernet/mellanox/mlx5/core/Makefile
d8f823
+++ b/drivers/net/ethernet/mellanox/mlx5/core/Makefile
d8f823
@@ -25,7 +25,7 @@ mlx5_core-$(CONFIG_MLX5_CORE_EN) += en_main.o en_common.o en_fs.o en_ethtool.o \
d8f823
 		en_tx.o en_rx.o en_dim.o en_txrx.o en/xdp.o en_stats.o \
d8f823
 		en_selftest.o en/port.o en/monitor_stats.o en/health.o \
d8f823
 		en/reporter_tx.o en/reporter_rx.o en/params.o en/xsk/umem.o \
d8f823
-		en/xsk/setup.o en/xsk/rx.o en/xsk/tx.o
d8f823
+		en/xsk/setup.o en/xsk/rx.o en/xsk/tx.o en/devlink.o
d8f823
 
d8f823
 #
d8f823
 # Netdev extra
d8f823
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en.h b/drivers/net/ethernet/mellanox/mlx5/core/en.h
d8f823
index 2e3a4ba96793..db0f2d9936cd 100644
d8f823
--- a/drivers/net/ethernet/mellanox/mlx5/core/en.h
d8f823
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en.h
d8f823
@@ -872,6 +872,7 @@ struct mlx5e_priv {
d8f823
 #endif
d8f823
 	struct devlink_health_reporter *tx_reporter;
d8f823
 	struct devlink_health_reporter *rx_reporter;
d8f823
+	struct devlink_port             dl_phy_port;
d8f823
 	struct mlx5e_xsk           xsk;
d8f823
 	struct mlx5e_scratchpad    scratchpad;
d8f823
 };
d8f823
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/devlink.c b/drivers/net/ethernet/mellanox/mlx5/core/en/devlink.c
d8f823
new file mode 100644
d8f823
index 000000000000..1a87a3fc6b44
d8f823
--- /dev/null
d8f823
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/devlink.c
d8f823
@@ -0,0 +1,38 @@
d8f823
+// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
d8f823
+/* Copyright (c) 2020, Mellanox Technologies inc.  All rights reserved. */
d8f823
+
d8f823
+#include "en/devlink.h"
d8f823
+
d8f823
+int mlx5e_devlink_phy_port_register(struct net_device *dev)
d8f823
+{
d8f823
+	struct mlx5e_priv *priv;
d8f823
+	struct devlink *devlink;
d8f823
+	int err;
d8f823
+
d8f823
+	priv = netdev_priv(dev);
d8f823
+	devlink = priv_to_devlink(priv->mdev);
d8f823
+
d8f823
+	devlink_port_attrs_set(&priv->dl_phy_port,
d8f823
+			       DEVLINK_PORT_FLAVOUR_PHYSICAL,
d8f823
+			       PCI_FUNC(priv->mdev->pdev->devfn),
d8f823
+			       false, 0,
d8f823
+			       NULL, 0);
d8f823
+	err = devlink_port_register(devlink, &priv->dl_phy_port, 1);
d8f823
+	if (err)
d8f823
+		return err;
d8f823
+	devlink_port_type_eth_set(&priv->dl_phy_port, dev);
d8f823
+	return 0;
d8f823
+}
d8f823
+
d8f823
+void mlx5e_devlink_phy_port_unregister(struct mlx5e_priv *priv)
d8f823
+{
d8f823
+	devlink_port_unregister(&priv->dl_phy_port);
d8f823
+}
d8f823
+
d8f823
+struct devlink_port *mlx5e_get_devlink_phy_port(struct net_device *dev)
d8f823
+{
d8f823
+	struct mlx5e_priv *priv = netdev_priv(dev);
d8f823
+
d8f823
+	return &priv->dl_phy_port;
d8f823
+}
d8f823
+
d8f823
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/devlink.h b/drivers/net/ethernet/mellanox/mlx5/core/en/devlink.h
d8f823
new file mode 100644
d8f823
index 000000000000..b8cd63b88688
d8f823
--- /dev/null
d8f823
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/devlink.h
d8f823
@@ -0,0 +1,15 @@
d8f823
+/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
d8f823
+/* Copyright (c) 2020, Mellanox Technologies inc.  All rights reserved. */
d8f823
+
d8f823
+#ifndef __MLX5E_EN_DEVLINK_H
d8f823
+#define __MLX5E_EN_DEVLINK_H
d8f823
+
d8f823
+#include <net/devlink.h>
d8f823
+#include "en.h"
d8f823
+
d8f823
+int mlx5e_devlink_phy_port_register(struct net_device *dev);
d8f823
+void mlx5e_devlink_phy_port_unregister(struct mlx5e_priv *priv);
d8f823
+struct devlink_port *mlx5e_get_devlink_phy_port(struct net_device *dev);
d8f823
+
d8f823
+#endif
d8f823
+
d8f823
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
d8f823
index 22298f67fbd2..0f48804f7fd2 100644
d8f823
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
d8f823
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
d8f823
@@ -62,6 +62,7 @@
d8f823
 #include "en/xsk/setup.h"
d8f823
 #include "en/xsk/rx.h"
d8f823
 #include "en/xsk/tx.h"
d8f823
+#include "en/devlink.h"
d8f823
 
d8f823
 
d8f823
 bool mlx5e_check_fragmented_striding_rq_cap(struct mlx5_core_dev *mdev)
d8f823
@@ -4634,6 +4635,7 @@ const struct net_device_ops mlx5e_netdev_ops = {
d8f823
 	.ndo_set_vf_link_state   = mlx5e_set_vf_link_state,
d8f823
 	.ndo_get_vf_stats        = mlx5e_get_vf_stats,
d8f823
 #endif
d8f823
+	.ndo_get_devlink_port    = mlx5e_get_devlink_phy_port,
d8f823
 };
d8f823
 
d8f823
 static int mlx5e_check_required_hca_cap(struct mlx5_core_dev *mdev)
d8f823
@@ -5497,11 +5499,19 @@ static void *mlx5e_add(struct mlx5_core_dev *mdev)
d8f823
 		goto err_detach;
d8f823
 	}
d8f823
 
d8f823
+	err = mlx5e_devlink_phy_port_register(netdev);
d8f823
+	if (err) {
d8f823
+		mlx5_core_err(mdev, "mlx5e_devlink_phy_port_register failed, %d\n", err);
d8f823
+		goto err_unregister_netdev;
d8f823
+	}
d8f823
+
d8f823
 #ifdef CONFIG_MLX5_CORE_EN_DCB
d8f823
 	mlx5e_dcbnl_init_app(priv);
d8f823
 #endif
d8f823
 	return priv;
d8f823
 
d8f823
+err_unregister_netdev:
d8f823
+	unregister_netdev(netdev);
d8f823
 err_detach:
d8f823
 	mlx5e_detach(mdev, priv);
d8f823
 err_destroy_netdev:
d8f823
@@ -5523,6 +5533,7 @@ static void mlx5e_remove(struct mlx5_core_dev *mdev, void *vpriv)
d8f823
 #ifdef CONFIG_MLX5_CORE_EN_DCB
d8f823
 	mlx5e_dcbnl_delete_app(priv);
d8f823
 #endif
d8f823
+	mlx5e_devlink_phy_port_unregister(priv);
d8f823
 	unregister_netdev(priv->netdev);
d8f823
 	mlx5e_detach(mdev, vpriv);
d8f823
 	mlx5e_destroy_netdev(priv);
d8f823
-- 
d8f823
2.13.6
d8f823