From: Valentine Fatiev <valentinef@nvidia.com>
Subject: [PATCH] BACKPORT: drivers/net/ethernet/mellanox/mlx5/core/eswitch.h

Change-Id: I4a061a58fe706013b3a0326b5c560cfa836c8c0a
---
 .../net/ethernet/mellanox/mlx5/core/eswitch.h | 97 +++++++++++++++----
 1 file changed, 78 insertions(+), 19 deletions(-)

--- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
@@ -70,10 +70,11 @@ struct mlx5_mapped_obj {
 	};
 };
 
-#ifdef CONFIG_MLX5_ESWITCH
-
 #define ESW_OFFLOADS_DEFAULT_NUM_GROUPS 15
 
+#ifdef CONFIG_MLX5_ESWITCH
+#include "en/tc_ct.h"
+
 #define MLX5_MAX_UC_PER_VPORT(dev) \
 	(1 << MLX5_CAP_GEN(dev, log_max_current_uc_list))
 
@@ -512,6 +513,10 @@ int mlx5_esw_qos_modify_vport_rate(struc
 int mlx5_eswitch_init(struct mlx5_core_dev *dev);
 void mlx5_eswitch_cleanup(struct mlx5_eswitch *esw);
 
+#if (defined(HAVE_DEVLINK_PARAMS_PUBLISHED) || defined(HAVE_DEVLINK_REGISTER_GET_1_PARAMS)) && !defined(HAVE_DEVL_PARAM_DRIVERINIT_VALUE_GET)
+int mlx5_register_eswitch_params(struct mlx5_core_dev *dev);
+void mlx5_unregister_eswitch_params(struct mlx5_core_dev *dev);
+#endif
 #define MLX5_ESWITCH_IGNORE_NUM_VFS (-1)
 int mlx5_eswitch_enable_locked(struct mlx5_eswitch *esw, int num_vfs);
 int mlx5_eswitch_enable(struct mlx5_eswitch *esw, int num_vfs);
@@ -666,11 +671,17 @@ struct mlx5_esw_flow_attr {
 	struct mlx5_pkt_reformat *decap_pkt_reformat;
 };
 
-int mlx5_devlink_eswitch_mode_set(struct devlink *devlink, u16 mode,
-				  struct netlink_ext_ack *extack);
+int mlx5_devlink_eswitch_mode_set(struct devlink *devlink, u16 mode
+#ifdef HAVE_DEVLINK_ESWITCH_MODE_SET_EXTACK
+				 , struct netlink_ext_ack *extack
+#endif
+				 );
 int mlx5_devlink_eswitch_mode_get(struct devlink *devlink, u16 *mode);
-int mlx5_devlink_eswitch_inline_mode_set(struct devlink *devlink, u8 mode,
-					 struct netlink_ext_ack *extack);
+int mlx5_devlink_eswitch_inline_mode_set(struct devlink *devlink, u8 mode
+#ifdef HAVE_DEVLINK_ESWITCH_MODE_SET_EXTACK
+					, struct netlink_ext_ack *extack
+#endif
+					);
 int mlx5_devlink_eswitch_inline_mode_get(struct devlink *devlink, u8 *mode);
 
 int mlx5_eswitch_vport_modify_other_hca_cap_roce(struct mlx5_eswitch *esw,
@@ -679,14 +690,35 @@ int mlx5_eswitch_vport_get_other_hca_cap
 					      struct mlx5_vport *vport, bool *value);
 
 int mlx5_devlink_eswitch_encap_mode_set(struct devlink *devlink,
-					enum devlink_eswitch_encap_mode encap,
-					struct netlink_ext_ack *extack);
+#ifdef HAVE_DEVLINK_HAS_ESWITCH_ENCAP_MODE_SET_GET_WITH_ENUM
+					enum devlink_eswitch_encap_mode encap
+#else
+					u8 encap
+#endif
+#ifdef HAVE_DEVLINK_ESWITCH_MODE_SET_EXTACK
+					, struct netlink_ext_ack *extack
+#endif
+					);
 int mlx5_devlink_eswitch_encap_mode_get(struct devlink *devlink,
+#ifdef HAVE_DEVLINK_HAS_ESWITCH_ENCAP_MODE_SET_GET_WITH_ENUM
 					enum devlink_eswitch_encap_mode *encap);
-int mlx5_devlink_port_fn_hw_addr_get(struct devlink_port *port,
+#else
+					u8 *encap);
+#endif
+#if defined(HAVE_PORT_FUNCTION_HW_ADDR_GET_GET_4_PARAM) || defined(HAVE_DEVLINK_PORT_OPS)
+int mlx5_devlink_port_fn_hw_addr_get(
+#else
+int mlx5_devlink_port_fn_hw_addr_get(struct devlink *devlink,
+#endif
+				     struct devlink_port *port,
 				     u8 *hw_addr, int *hw_addr_len,
 				     struct netlink_ext_ack *extack);
-int mlx5_devlink_port_fn_hw_addr_set(struct devlink_port *port,
+#if defined(HAVE_PORT_FUNCTION_HW_ADDR_GET_GET_4_PARAM) || defined(HAVE_DEVLINK_PORT_OPS)
+int mlx5_devlink_port_fn_hw_addr_set(
+#else
+int mlx5_devlink_port_fn_hw_addr_set(struct devlink *devlink,
+#endif
+				     struct devlink_port *port,
 				     const u8 *hw_addr, int hw_addr_len,
 				     struct netlink_ext_ack *extack);
 int mlx5_devlink_port_fn_roce_get(struct devlink_port *port, bool *is_enabled,
@@ -697,6 +729,20 @@ int mlx5_devlink_port_fn_migratable_get(
 					struct netlink_ext_ack *extack);
 int mlx5_devlink_port_fn_migratable_set(struct devlink_port *port, bool enable,
 					struct netlink_ext_ack *extack);
+#ifdef CONFIG_XFRM_OFFLOAD
+#ifdef HAVE_DEVLINK_IPSEC_CRYPTO
+int mlx5_devlink_port_fn_ipsec_crypto_get(struct devlink_port *port, bool *is_enabled,
+					  struct netlink_ext_ack *extack);
+int mlx5_devlink_port_fn_ipsec_crypto_set(struct devlink_port *port, bool enable,
+					  struct netlink_ext_ack *extack);
+#endif /* HAVE_DEVLINK_IPSEC_CRYPTO */
+#ifdef HAVE_DEVLINK_IPSEC_PACKET
+int mlx5_devlink_port_fn_ipsec_packet_get(struct devlink_port *port, bool *is_enabled,
+					  struct netlink_ext_ack *extack);
+int mlx5_devlink_port_fn_ipsec_packet_set(struct devlink_port *port, bool enable,
+					  struct netlink_ext_ack *extack);
+#endif /* HAVE_DEVLINK_IPSEC_PACKET */
+#endif /* CONFIG_XFRM_OFFLOAD */
 int mlx5_devlink_rate_node_tx_max_set(struct devlink *devlink,
 				      const char *group, u64 tx_max,
 				      struct netlink_ext_ack *extack);
@@ -729,8 +775,11 @@ int mlx5_devlink_port_fn_max_io_eqs_set_
 void *mlx5_eswitch_get_uplink_priv(struct mlx5_eswitch *esw, u8 rep_type);
 
 int mlx5_devlink_eswitch_ipsec_mode_set(struct devlink *devlink,
-					enum devlink_eswitch_ipsec_mode ipsec,
-					struct netlink_ext_ack *extack);
+					enum devlink_eswitch_ipsec_mode ipsec
+#ifdef HAVE_DEVLINK_ESWITCH_MODE_SET_EXTACK
+                                        , struct netlink_ext_ack *extack
+#endif
+					);
 int mlx5_devlink_eswitch_ipsec_mode_get(struct devlink *devlink,
 					enum devlink_eswitch_ipsec_mode *ipsec);
 
@@ -1008,6 +1057,12 @@ struct mlx5_esw_event_info {
 
 int mlx5_esw_event_notifier_register(struct mlx5_eswitch *esw, struct notifier_block *n);
 void mlx5_esw_event_notifier_unregister(struct mlx5_eswitch *esw, struct notifier_block *n);
+#ifdef HAVE_BASECODE_EXTRAS
+int mlx5_eswitch_set_vport_mac(struct mlx5_eswitch *esw,
+			       u16 vport, const u8 *mac);
+int mlx5_eswitch_set_vport_state(struct mlx5_eswitch *esw,
+				 u16 vport, int link_state);
+#endif
 bool mlx5e_esw_offloads_pet_enabled(const struct mlx5_eswitch *esw);
 int mlx5e_esw_offloads_pet_setup(struct mlx5_eswitch *esw, struct mlx5_flow_table *ft);
 void mlx5e_esw_offloads_pet_cleanup(struct mlx5_eswitch *esw);
@@ -1106,12 +1161,6 @@ static inline const u32 *mlx5_esw_query_
 	return ERR_PTR(-EOPNOTSUPP);
 }
 
-static inline struct mlx5_flow_handle *
-esw_add_restore_rule(struct mlx5_eswitch *esw, u32 tag)
-{
-	return ERR_PTR(-EOPNOTSUPP);
-}
-
 static inline unsigned int
 mlx5_esw_vport_to_devlink_port_index(const struct mlx5_core_dev *dev,
 				     u16 vport_num)
@@ -1146,7 +1195,12 @@ static inline bool mlx5_eswitch_block_en
 static inline void mlx5_eswitch_unblock_encap(struct mlx5_core_dev *dev)
 {
 }
-
+#ifdef HAVE_BASECODE_EXTRAS
+static inline int mlx5_eswitch_set_vport_mac(struct mlx5_eswitch *esw,
+		                                             u16 vport, u8 mac[ETH_ALEN]){ return 0; }
+static inline int mlx5_eswitch_get_vport_mac(struct mlx5_eswitch *esw,
+		                                             u16 vport, u8 *mac){ return 0; }
+#endif
 static inline int mlx5_eswitch_block_mode(struct mlx5_core_dev *dev) { return 0; }
 static inline void mlx5_eswitch_unblock_mode(struct mlx5_core_dev *dev) {}
 static inline bool mlx5_eswitch_mode_is_blocked(struct mlx5_core_dev *dev) { return false; }
@@ -1157,6 +1211,11 @@ static inline bool mlx5_eswitch_block_ip
 
 static inline void mlx5_eswitch_unblock_ipsec(struct mlx5_core_dev *dev) {}
 
+static inline bool mlx5e_esw_offloads_pet_enabled(const struct mlx5_eswitch *esw)
+{
+	return false;
+};
+
 static inline bool mlx5_esw_host_functions_enabled(const struct mlx5_core_dev *dev)
 {
 	return true;
