From: Maher Sanalla <msanalla@nvidia.com>
Subject: [PATCH] BACKPORT:
 drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c

Change-Id: I923d56ef3bd76c7fddb4cabb6046ad93127f3c16
---
 .../ethernet/mellanox/mlx5/core/sf/devlink.c  | 42 +++++++++++++++++--
 1 file changed, 38 insertions(+), 4 deletions(-)

--- a/drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c
@@ -166,8 +166,12 @@ static bool mlx5_sf_is_active(const stru
 {
 	return sf->hw_state == MLX5_VHCA_STATE_ACTIVE || sf->hw_state == MLX5_VHCA_STATE_IN_USE;
 }
-
-int mlx5_devlink_sf_port_fn_state_get(struct devlink_port *dl_port,
+#ifdef HAVE_PORT_FUNCTION_STATE_GET_4_PARAM
+int mlx5_devlink_sf_port_fn_state_get(
+#else
+int mlx5_devlink_sf_port_fn_state_get(struct devlink *devlink,
+#endif
+				      struct devlink_port *dl_port,
 				      enum devlink_port_fn_state *state,
 				      enum devlink_port_fn_opstate *opstate,
 				      struct netlink_ext_ack *extack)
@@ -253,7 +257,12 @@ out:
 	return err;
 }
 
-int mlx5_devlink_sf_port_fn_state_set(struct devlink_port *dl_port,
+#ifdef HAVE_PORT_FUNCTION_STATE_GET_4_PARAM
+int mlx5_devlink_sf_port_fn_state_set(
+#else
+int mlx5_devlink_sf_port_fn_state_set(struct devlink *devlink,
+#endif
+				      struct devlink_port *dl_port,
 				      enum devlink_port_fn_state state,
 				      struct netlink_ext_ack *extack)
 {
@@ -283,7 +292,11 @@ out:
 static int mlx5_sf_add(struct mlx5_core_dev *dev, struct mlx5_sf_table *table,
 		       const struct devlink_port_new_attrs *new_attr,
 		       struct netlink_ext_ack *extack,
+#ifdef HAVE_DEVLINK_PORT_OPS
+		       struct devlink_port **dl_port)
+#else
 		       unsigned int *new_port_index)
+#endif
 {
 	struct mlx5_eswitch *esw = dev->priv.eswitch;
 	struct mlx5_sf *sf;
@@ -297,7 +310,11 @@ static int mlx5_sf_add(struct mlx5_core_
 						new_attr->controller, new_attr->sfnum);
 	if (err)
 		goto esw_err;
+#ifdef HAVE_DEVLINK_PORT_OPS
+	*dl_port = &sf->dl_port;
+#else
 	*new_port_index = sf->port_index;
+#endif
 	trace_mlx5_sf_add(dev, sf->port_index, sf->controller, sf->hw_fn_id, new_attr->sfnum);
 	return 0;
 
@@ -339,7 +356,11 @@ mlx5_sf_new_check_attr(struct mlx5_core_
 int mlx5_devlink_sf_port_new(struct devlink *devlink,
 			     const struct devlink_port_new_attrs *new_attr,
 			     struct netlink_ext_ack *extack,
+#ifdef HAVE_DEVLINK_PORT_OPS
+			     struct devlink_port **dl_port)
+#else
 			     unsigned int *new_port_index)
+#endif
 {
 	struct mlx5_core_dev *dev = devlink_priv(devlink);
 	struct mlx5_sf_table *table;
@@ -355,7 +376,11 @@ int mlx5_devlink_sf_port_new(struct devl
 				   "Port add is only supported in eswitch switchdev mode or SF ports are disabled.");
 		return -EOPNOTSUPP;
 	}
+#ifdef HAVE_DEVLINK_PORT_OPS
+	err = mlx5_sf_add(dev, table, new_attr, extack, dl_port);
+#else
 	err = mlx5_sf_add(dev, table, new_attr, extack, new_port_index);
+#endif
 	mlx5_sf_table_put(table);
 	return err;
 }
@@ -379,7 +404,12 @@ static void mlx5_sf_dealloc(struct mlx5_
 	}
 }
 
-int mlx5_devlink_sf_port_del(struct devlink *devlink, unsigned int port_index,
+int mlx5_devlink_sf_port_del(struct devlink *devlink,
+#ifdef HAVE_DEVLINK_PORT_OPS
+			     struct devlink_port *dl_port,
+#else
+			     unsigned int port_index,
+#endif
 			     struct netlink_ext_ack *extack)
 {
 	struct mlx5_core_dev *dev = devlink_priv(devlink);
@@ -394,7 +424,11 @@ int mlx5_devlink_sf_port_del(struct devl
 				   "Port del is only supported in eswitch switchdev mode or SF ports are disabled.");
 		return -EOPNOTSUPP;
 	}
+#ifdef HAVE_DEVLINK_PORT_OPS
+	sf = mlx5_sf_lookup_by_index(table, dl_port->index);
+#else
 	sf = mlx5_sf_lookup_by_index(table, port_index);
+#endif
 	if (!sf) {
 		err = -ENODEV;
 		goto sf_err;
