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

Change-Id: I65390ff70a2544445617909666127bba4a382b2e
---
 .../mellanox/mlx5/core/en/tc_tun_geneve.c     | 54 ++++++++++++++++++-
 1 file changed, 52 insertions(+), 2 deletions(-)

--- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_geneve.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_geneve.c
@@ -21,9 +21,12 @@ static int mlx5e_tc_tun_calc_hlen_geneve
 
 static int mlx5e_tc_tun_check_udp_dport_geneve(struct mlx5e_priv *priv,
 					       struct flow_cls_offload *f)
+
 {
 	struct flow_rule *rule = flow_cls_offload_flow_rule(f);
-	struct netlink_ext_ack *extack = f->common.extack;
+#ifdef HAVE_TC_CLS_OFFLOAD_EXTACK
+       struct netlink_ext_ack *extack = f->common.extack;
+#endif
 	struct flow_match_ports enc_ports;
 
 	if (!flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ENC_PORTS))
@@ -35,8 +38,10 @@ static int mlx5e_tc_tun_check_udp_dport_
 	 * port, so udp dst port must match.
 	 */
 	if (be16_to_cpu(enc_ports.key->dst) != GENEVE_UDP_PORT) {
+#ifdef HAVE_TC_CLS_OFFLOAD_EXTACK
 		NL_SET_ERR_MSG_MOD(extack,
 				   "Matched UDP dst port is not registered as a GENEVE port");
+#endif
 		netdev_warn(priv->netdev,
 			    "UDP port %d is not registered as a GENEVE port\n",
 			    be16_to_cpu(enc_ports.key->dst));
@@ -55,6 +60,7 @@ static int mlx5e_tc_tun_parse_udp_ports_
 	int err;
 
 	err = mlx5e_tc_tun_parse_udp_ports(priv, spec, f, headers_c, headers_v);
+
 	if (err)
 		return err;
 
@@ -106,12 +112,22 @@ static int mlx5e_gen_ip_tunnel_header_ge
 	memset(geneveh, 0, sizeof(*geneveh));
 	geneveh->ver = MLX5E_GENEVE_VER;
 	geneveh->opt_len = tun_info->options_len / 4;
+#ifdef HAVE_CONVERT_BE16_TUNNEL_FLAGS_TO_BITMAPS //forwardport 
+	geneveh->oam = test_bit(IP_TUNNEL_OAM_BIT, tun_info->key.tun_flags);
+	geneveh->critical = test_bit(IP_TUNNEL_CRIT_OPT_BIT,
+				     tun_info->key.tun_flags);
+#else
 	geneveh->oam = !!(tun_info->key.tun_flags & TUNNEL_OAM);
 	geneveh->critical = !!(tun_info->key.tun_flags & TUNNEL_CRIT_OPT);
+#endif
 	mlx5e_tunnel_id_to_vni(tun_info->key.tun_id, geneveh->vni);
 	geneveh->proto_type = htons(ETH_P_TEB);
 
+#ifdef HAVE_CONVERT_BE16_TUNNEL_FLAGS_TO_BITMAPS //forwardport 
+	if (test_bit(IP_TUNNEL_GENEVE_OPT_BIT, tun_info->key.tun_flags)) {
+#else
 	if (tun_info->key.tun_flags & TUNNEL_GENEVE_OPT) {
+#endif
 		if (!geneveh->opt_len)
 			return -EOPNOTSUPP;
 		ip_tunnel_info_opts_get(geneveh->options, tun_info);
@@ -125,7 +141,9 @@ static int mlx5e_tc_tun_parse_geneve_vni
 					 struct flow_cls_offload *f)
 {
 	struct flow_rule *rule = flow_cls_offload_flow_rule(f);
-	struct netlink_ext_ack *extack = f->common.extack;
+#ifdef HAVE_TC_CLS_OFFLOAD_EXTACK
+       struct netlink_ext_ack *extack = f->common.extack;
+#endif
 	struct flow_match_enc_keyid enc_keyid;
 	void *misc_c, *misc_v;
 
@@ -141,7 +159,9 @@ static int mlx5e_tc_tun_parse_geneve_vni
 		return 0;
 
 	if (!MLX5_CAP_ESW_FLOWTABLE_FDB(priv->mdev, ft_field_support.outer_geneve_vni)) {
+#ifdef HAVE_TC_CLS_OFFLOAD_EXTACK
 		NL_SET_ERR_MSG_MOD(extack, "Matching on GENEVE VNI is not supported");
+#endif
 		netdev_warn(priv->netdev, "Matching on GENEVE VNI is not supported\n");
 		return -EOPNOTSUPP;
 	}
@@ -159,7 +179,9 @@ static int mlx5e_tc_tun_parse_geneve_opt
 	u8 max_tlv_option_data_len = MLX5_CAP_GEN(priv->mdev, max_geneve_tlv_option_data_len);
 	u8 max_tlv_options = MLX5_CAP_GEN(priv->mdev, max_geneve_tlv_options);
 	struct flow_rule *rule = flow_cls_offload_flow_rule(f);
+#ifdef HAVE_TC_CLS_OFFLOAD_EXTACK
 	struct netlink_ext_ack *extack = f->common.extack;
+#endif
 	void *misc_c, *misc_v, *misc_3_c, *misc_3_v;
 	struct geneve_opt *option_key, *option_mask;
 	__be32 opt_data_key = 0, opt_data_mask = 0;
@@ -179,8 +201,10 @@ static int mlx5e_tc_tun_parse_geneve_opt
 	if (memchr_inv(&enc_opts.mask->data, 0, sizeof(enc_opts.mask->data)) &&
 	    !MLX5_CAP_ESW_FLOWTABLE_FDB(priv->mdev,
 					ft_field_support.geneve_tlv_option_0_data)) {
+#ifdef HAVE_TC_CLS_OFFLOAD_EXTACK
 		NL_SET_ERR_MSG_MOD(extack,
 				   "Matching on GENEVE options is not supported");
+#endif
 		netdev_warn(priv->netdev,
 			    "Matching on GENEVE options is not supported\n");
 		return -EOPNOTSUPP;
@@ -188,9 +212,15 @@ static int mlx5e_tc_tun_parse_geneve_opt
 
 	/* make sure that we're talking about GENEVE options */
 
+#ifdef HAVE_CONVERT_BE16_TUNNEL_FLAGS_TO_BITMAPS //forwardport
+	if (enc_opts.key->dst_opt_type != IP_TUNNEL_GENEVE_OPT_BIT) {
+#else
 	if (enc_opts.key->dst_opt_type != TUNNEL_GENEVE_OPT) {
+#endif
+#ifdef HAVE_TC_CLS_OFFLOAD_EXTACK
 		NL_SET_ERR_MSG_MOD(extack,
 				   "Matching on GENEVE options: option type is not GENEVE");
+#endif
 		netdev_warn(priv->netdev,
 			    "Matching on GENEVE options: option type is not GENEVE\n");
 		return -EOPNOTSUPP;
@@ -199,7 +229,9 @@ static int mlx5e_tc_tun_parse_geneve_opt
 	if (enc_opts.mask->len &&
 	    !MLX5_CAP_ESW_FLOWTABLE_FDB(priv->mdev,
 					ft_field_support.outer_geneve_opt_len)) {
+#ifdef HAVE_TC_CLS_OFFLOAD_EXTACK
 		NL_SET_ERR_MSG_MOD(extack, "Matching on GENEVE options len is not supported");
+#endif
 		netdev_warn(priv->netdev,
 			    "Matching on GENEVE options len is not supported\n");
 		return -EOPNOTSUPP;
@@ -212,8 +244,10 @@ static int mlx5e_tc_tun_parse_geneve_opt
 	 */
 
 	if ((enc_opts.key->len / 4) > ((max_tlv_option_data_len + 1) * max_tlv_options)) {
+#ifdef HAVE_TC_CLS_OFFLOAD_EXTACK
 		NL_SET_ERR_MSG_MOD(extack,
 				   "Matching on GENEVE options: unsupported options len");
+#endif
 		netdev_warn(priv->netdev,
 			    "Matching on GENEVE options: unsupported options len (len=%d)\n",
 			    enc_opts.key->len);
@@ -232,8 +266,10 @@ static int mlx5e_tc_tun_parse_geneve_opt
 		return 0;
 
 	if (option_key->length > max_tlv_option_data_len) {
+#ifdef HAVE_TC_CLS_OFFLOAD_EXTACK
 		NL_SET_ERR_MSG_MOD(extack,
 				   "Matching on GENEVE options: unsupported option len");
+#endif
 		netdev_warn(priv->netdev,
 			    "Matching on GENEVE options: unsupported option len (key=%d, mask=%d)\n",
 			    option_key->length, option_mask->length);
@@ -242,8 +278,10 @@ static int mlx5e_tc_tun_parse_geneve_opt
 
 	/* data can't be all 0 - fail to offload such rule */
 	if (!memchr_inv(option_key->opt_data, 0, option_key->length * 4)) {
+#ifdef HAVE_TC_CLS_OFFLOAD_EXTACK
 		NL_SET_ERR_MSG_MOD(extack,
 				   "Matching on GENEVE options: can't match on 0 data field");
+#endif
 		netdev_warn(priv->netdev,
 			    "Matching on GENEVE options: can't match on 0 data field\n");
 		return -EOPNOTSUPP;
@@ -252,8 +290,10 @@ static int mlx5e_tc_tun_parse_geneve_opt
 	/* add new GENEVE TLV options object */
 	res = mlx5_geneve_tlv_option_add(priv->mdev->geneve, option_key);
 	if (res) {
+#ifdef HAVE_TC_CLS_OFFLOAD_EXTACK
 		NL_SET_ERR_MSG_MOD(extack,
 				   "Matching on GENEVE options: failed creating TLV opt object");
+#endif
 		netdev_warn(priv->netdev,
 			    "Matching on GENEVE options: failed creating TLV opt object (class:type:len = 0x%x:0x%x:%d)\n",
 			    be16_to_cpu(option_key->opt_class),
@@ -290,12 +330,16 @@ static int mlx5e_tc_tun_parse_geneve_par
 {
 	void *misc_c = MLX5_ADDR_OF(fte_match_param, spec->match_criteria, misc_parameters);
 	void *misc_v = MLX5_ADDR_OF(fte_match_param, spec->match_value,  misc_parameters);
+#ifdef HAVE_TC_CLS_OFFLOAD_EXTACK
 	struct netlink_ext_ack *extack = f->common.extack;
+#endif
 
 	/* match on OAM - packets with OAM bit on should NOT be offloaded */
 
 	if (!MLX5_CAP_ESW_FLOWTABLE_FDB(priv->mdev, ft_field_support.outer_geneve_oam)) {
+#ifdef HAVE_TC_CLS_OFFLOAD_EXTACK
 		NL_SET_ERR_MSG_MOD(extack, "Matching on GENEVE OAM is not supported");
+#endif
 		netdev_warn(priv->netdev, "Matching on GENEVE OAM is not supported\n");
 		return -EOPNOTSUPP;
 	}
@@ -337,7 +381,12 @@ static int mlx5e_tc_tun_parse_geneve(str
 static bool mlx5e_tc_tun_encap_info_equal_geneve(struct mlx5e_encap_key *a,
 						 struct mlx5e_encap_key *b)
 {
+#ifdef HAVE_CONVERT_BE16_TUNNEL_FLAGS_TO_BITMAPS //forwardport
+	return mlx5e_tc_tun_encap_info_equal_options(a, b,
+						     IP_TUNNEL_GENEVE_OPT_BIT);
+#else
 	return mlx5e_tc_tun_encap_info_equal_options(a, b, TUNNEL_GENEVE_OPT);
+#endif
 }
 
 struct mlx5e_tc_tunnel geneve_tunnel = {
@@ -351,3 +400,4 @@ struct mlx5e_tc_tunnel geneve_tunnel = {
 	.parse_tunnel         = mlx5e_tc_tun_parse_geneve,
 	.encap_info_equal     = mlx5e_tc_tun_encap_info_equal_geneve,
 };
+
