[qca-nss-drv] Enable configuration for EOGRE tunnel.

1.) Added API to get GRE interface number with core ID.
2.) Store next_dev_outer in GRE priv.
3.) Add DSCP per packet flag for GRE configure.

Change-Id: I5cfb74eb806110574859ab4f9ca501516cc84f61
Signed-off-by: Suruchi Suman <surusuma@codeaurora.org>
diff --git a/exports/nss_gre.h b/exports/nss_gre.h
index bb5955b..f6e9f38 100644
--- a/exports/nss_gre.h
+++ b/exports/nss_gre.h
@@ -1,6 +1,6 @@
 /*
  **************************************************************************
- * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2017-2019, The Linux Foundation. All rights reserved.
  * Permission to use, copy, modify, and/or distribute this software for
  * any purpose with or without fee is hereby granted, provided that the
  * above copyright notice and this permission notice appear in all copies.
@@ -48,23 +48,28 @@
 #define NSS_GRE_CONFIG_SET_DF		0x00000100	/**< Enable DF bit on tunnel IP header. */
 #define NSS_GRE_CONFIG_SET_MAC		0x00000200	/**< Add MAC header to GRE+IP tunnel header. */
 #define NSS_GRE_CONFIG_SET_PADDING	0x00000400	/**< Add PADDING to align tunnel IP/GRE header. */
-#define NSS_GRE_CONFIG_NEXT_NODE_AVAILABLE  0x00000800	/**< Use provided next_node instead of existing next node. */
+#define NSS_GRE_CONFIG_NEXT_NODE_AVAILABLE  0x00000800	/**< Use provided next node instead of existing next node. */
 #define NSS_GRE_CONFIG_COPY_METADATA 	0x00001000	/**< Enable metadata copy in NSS during alignment. */
 #define NSS_GRE_CONFIG_USE_UNALIGNED 	0x00002000	/**< Use unaligned infrastructure in NSS. */
+#define NSS_GRE_CONFIG_DSCP_VALID	0x00004000	/**< Add DSCP per packet. */
 
 /**
  * nss_gre_info
  *	GRE private information.
  */
 struct nss_gre_info {
+	/**
+	 * Union of IPv4/IPv6 tunnel.
+	 */
 	union {
-		struct ip_tunnel t4;	/**< IPv4 tunnel */
-		struct ip6_tnl t6;	/**< IPv6 tunnel */
-	} t;
-	int nss_if_number;		/**< NSS interface number */
-	struct net_device *next_dev;	/**< Next net device */
-	uint8_t gre_hlen;		/**< GRE header length */
-	uint8_t pad_len;		/**< Pad length */
+		struct ip_tunnel t4;		/**< IPv4 tunnel. */
+		struct ip6_tnl t6;		/**< IPv6 tunnel. */
+	} t;		/**< IPv4 and IPv6 tunnel. */
+	int nss_if_number_inner;		/**< NSS interface number for GRE inner. */
+	struct net_device *next_dev_inner;	/**< Next network device for inner flow. */
+	struct net_device *next_dev_outer;	/**< Next network device for outer flow. */
+	uint8_t gre_hlen;			/**< GRE header length. */
+	uint8_t pad_len;			/**< Pad length. */
 };
 
 /**
@@ -288,6 +293,18 @@
 extern struct nss_ctx_instance *nss_gre_get_context(void);
 
 /**
+ *
+ * nss_gre_ifnum_with_core_id
+ * 	Append core ID on GRE interface.
+ *
+ * @param[in] if_num   NSS interface number.
+ *
+ * @return
+ * GRE interface number with core ID.
+ */
+extern int nss_gre_ifnum_with_core_id(int if_num);
+
+/**
  * Callback function for receiving GRE session data.
  *
  * @datatypes
diff --git a/nss_gre.c b/nss_gre.c
index 7178ed7..d1f06c7 100644
--- a/nss_gre.c
+++ b/nss_gre.c
@@ -1,6 +1,6 @@
 /*
  **************************************************************************
- * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2017-2019, The Linux Foundation. All rights reserved.
  * Permission to use, copy, modify, and/or distribute this software for
  * any purpose with or without fee is hereby granted, provided that the
  * above copyright notice and this permission notice appear in all copies.
@@ -31,6 +31,9 @@
 	void *app_data;
 } nss_gre_pvt;
 
+/*
+ * TODO: Register separate callbacks for inner and outer GRE nodes.
+ */
 static atomic64_t pkt_cb_addr = ATOMIC64_INIT(0);
 
 /*
@@ -45,8 +48,8 @@
 	nss_gre_pkt_callback_t scb = (nss_gre_pkt_callback_t)(unsigned long)atomic64_read(&pkt_cb_addr);
 	if (unlikely(scb)) {
 		struct nss_gre_info *info = (struct nss_gre_info *)netdev_priv(dev);
-		if (likely(info->next_dev)) {
-			scb(info->next_dev, skb);
+		if (likely(info->next_dev_inner)) {
+			scb(info->next_dev_inner, skb);
 		}
 	}
 
@@ -66,8 +69,8 @@
 	nss_gre_pkt_callback_t scb = (nss_gre_pkt_callback_t)(unsigned long)atomic64_read(&pkt_cb_addr);
 	if (unlikely(scb)) {
 		struct nss_gre_info *info = (struct nss_gre_info *)netdev_priv(dev);
-		if (likely(info->next_dev)) {
-			scb(info->next_dev, skb);
+		if (likely(info->next_dev_outer)) {
+			scb(info->next_dev_outer, skb);
 		}
 	}
 
@@ -361,6 +364,24 @@
 EXPORT_SYMBOL(nss_gre_get_context);
 
 /*
+ * nss_gre_ifnum_with_core_id()
+ *	Append core id to GRE interface num.
+ */
+int nss_gre_ifnum_with_core_id(int if_num)
+{
+	struct nss_ctx_instance *nss_ctx = nss_gre_get_context();
+
+	NSS_VERIFY_CTX_MAGIC(nss_ctx);
+	if (!nss_is_dynamic_interface(if_num)) {
+		nss_warning("%p: Invalid if_num: %d, must be a dynamic interface\n", nss_ctx, if_num);
+		return 0;
+	}
+
+	return NSS_INTERFACE_NUM_APPEND_COREID(nss_ctx, if_num);
+}
+EXPORT_SYMBOL(nss_gre_ifnum_with_core_id);
+
+/*
  * nss_gre_msg_init()
  *	Initialize nss_gre msg.
  */