[qca-nss-drv] PPE messages for inline IPsec acceleration

Changes implement required messages between Host and PPE
for enabling inline EIP flow acceleration.

Change-Id: If3abe374becf62073326b40f15aaf2efca7cb343
Signed-off-by: Amit Gupta <amitgupt@codeaurora.org>
diff --git a/exports/arch/nss_ipq807x.h b/exports/arch/nss_ipq807x.h
index 05122bc..1f80f98 100644
--- a/exports/arch/nss_ipq807x.h
+++ b/exports/arch/nss_ipq807x.h
@@ -1,6 +1,6 @@
 /*
  **************************************************************************
- * Copyright (c) 2017, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2017-2018, 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.
@@ -28,6 +28,7 @@
 
 #define NSS_MAX_NUM_PRI 4		/**< Maximum number of priority queues in NSS for the IPQ807x chipsets. */
 #define NSS_HOST_CORES 4		/**< Number of host cores for the IPQ807x chipsets. */
+#define NSS_PPE_SUPPORTED		/**< PPE supported flag for the IPQ807x chipsets. */
 
 /**
  * @}
diff --git a/exports/arch/nss_ipq807x_64.h b/exports/arch/nss_ipq807x_64.h
index ca6d07f..ae32665 100644
--- a/exports/arch/nss_ipq807x_64.h
+++ b/exports/arch/nss_ipq807x_64.h
@@ -1,6 +1,6 @@
 /*
  **************************************************************************
- * Copyright (c) 2017, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2017-2018, 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.
@@ -28,6 +28,7 @@
 
 #define NSS_MAX_NUM_PRI 4		/**< Maximum number of priority queues in NSS for the IPQ807x 64-bit chipsets. */
 #define NSS_HOST_CORES 4		/**< Number of host cores for the IPQ807x 64-bit chipsets. */
+#define NSS_PPE_SUPPORTED		/**< PPE supported flag for the IPQ807x 64-bit chipsets. */
 
 /**
  * @}
diff --git a/exports/nss_ppe.h b/exports/nss_ppe.h
index f3ac045..8bb6274 100644
--- a/exports/nss_ppe.h
+++ b/exports/nss_ppe.h
@@ -1,6 +1,6 @@
 /*
  **************************************************************************
- * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2016-2018, 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,15 +31,24 @@
  * NSS PORT defines
  */
 #define NSS_PPE_NUM_PHY_PORTS_MAX		8
-		/**< Maximum number of PPE phsyical ports. */
+		/**< Maximum number of PPE physical ports. */
+#define NSS_PPE_PORT_IPSEC			7
+		/**< Port number of PPE inline IPsec port. */
 
 /**
- * nss_ppe_metadata_types
+ * nss_ppe_message_types
  *	Message types for Packet Processing Engine (PPE) requests and responses.
+ *
+ * Note: PPE messages are added as short term approach, expect all
+ * messages below to be deprecated for more integrated approach.
  */
-enum nss_ppe_metadata_types {
+enum nss_ppe_message_types {
 	NSS_PPE_MSG_SYNC_STATS,
 	NSS_PPE_MSG_L2_EXCEPTION,
+	NSS_PPE_MSG_IPSEC_PORT_CONFIG,
+	NSS_PPE_MSG_IPSEC_PORT_MTU_CHANGE,
+	NSS_PPE_MSG_IPSEC_ADD_INTF,
+	NSS_PPE_MSG_IPSEC_DEL_INTF,
 	NSS_PPE_MSG_MAX,
 };
 
@@ -50,6 +59,13 @@
 enum nss_ppe_msg_error_type {
 	PPE_MSG_ERROR_OK,
 	PPE_MSG_ERROR_UNKNOWN_TYPE,
+	PPE_MSG_ERROR_PORT_CREATION_FAIL,
+	PPE_MSG_ERROR_INVALID_PORT_VSI,
+	PPE_MSG_ERROR_INVALID_L3_IF,
+	PPE_MSG_ERROR_IPSEC_PORT_CONFIG,
+	PPE_MSG_ERROR_IPSEC_INTF_TABLE_FULL,
+	PPE_MSG_ERROR_IPSEC_INTF_ATTACHED,
+	PPE_MSG_ERROR_IPSEC_INTF_UNATTACHED
 };
 
 /**
@@ -104,12 +120,12 @@
 	uint32_t nss_ppe_fail_ppe_unresponsive;
 			/**< Request failed because the PPE is not responding. */
 	uint32_t nss_ppe_ce_opaque_invalid;
-			/**< Request failed because of invalid opaque in connection entry */
+			/**< Request failed because of invalid opaque in connection entry. */
 	uint32_t nss_ppe_fail_fqg_full;
 			/**< Request failed because the flow QoS group is full. */
 };
 
-/*
+/**
  * nss_ppe_l2_exception_msg
  *	Message structure for L2 exception.
  */
@@ -118,6 +134,41 @@
 };
 
 /**
+ * nss_ppe_ipsec_port_config_msg
+ *	Message structure for inline IPsec port configuration.
+ */
+struct nss_ppe_ipsec_port_config_msg {
+	uint32_t nss_ifnum;		/**< NSS interface number corresponding to inline IPsec port. */
+	uint16_t mtu;			/**< MTU value for inline IPsec port. */
+	uint8_t vsi_num;		/**< Default port VSI for inline IPsec port. */
+};
+
+/**
+ * nss_ppe_ipsec_port_mtu_msg
+ *	Message structure for inline IPsec port MTU change.
+ */
+struct nss_ppe_ipsec_port_mtu_msg {
+	uint32_t nss_ifnum;		/**< NSS interface number corresponding to inline IPsec port. */
+	uint16_t mtu;			/**< MTU value for inline IPsec port. */
+};
+
+/**
+ * nss_ppe_ipsec_add_intf_msg
+ *	Message structure for adding dynamic IPsec/DTLS interface to inline IPsec port.
+ */
+struct nss_ppe_ipsec_add_intf_msg {
+	uint32_t nss_ifnum;	/**< Dynamic IPsec/DTLS interface number. */
+};
+
+/**
+ * nss_ppe_ipsec_del_intf_msg
+ *	Message structure for deleting dynamic IPsec/DTLS interface to inline IPsec port.
+ */
+struct nss_ppe_ipsec_del_intf_msg {
+	uint32_t nss_ifnum;	/**< Dynamic IPsec/DTLS interface number. */
+};
+
+/**
  * nss_ppe_msg
  *	Data for sending and receiving PPE host-to-NSS messages.
  */
@@ -132,6 +183,14 @@
 				/**< Synchronization statistics. */
 		struct nss_ppe_l2_exception_msg l2_exception;
 				/**< L2 exception message. */
+		struct nss_ppe_ipsec_port_config_msg ipsec_config;
+				/**< PPE inline IPsec port configuration message. */
+		struct nss_ppe_ipsec_port_mtu_msg ipsec_mtu;
+				/**< Inline IPsec port MTU change message. */
+		struct nss_ppe_ipsec_add_intf_msg ipsec_addif;
+				/**< Inline IPsec NSS interface attach message. */
+		struct nss_ppe_ipsec_del_intf_msg ipsec_delif;
+				/**< Inline IPsec NSS interface detach message. */
 	} msg;			/**< Message payload. */
 };
 
@@ -228,6 +287,53 @@
 nss_tx_status_t nss_ppe_tx_l2_exception_msg(uint32_t if_num, bool exception_enable);
 
 /**
+ * nss_ppe_tx_ipsec_config_msg
+ *      Sends the PPE a message to configure inline IPsec port.
+ *
+ * @param[in] if_num        Static IPsec interface number.
+ * @param[in] vsi_num       Default VSI number associated with inline IPsec port.
+ * @param[in] mtu           Default MTU of static inline IPsec port.
+ *
+ * @return
+ * Status of the Tx operation.
+ */
+nss_tx_status_t nss_ppe_tx_ipsec_config_msg(uint32_t nss_ifnum, uint32_t vsi_num, uint16_t mtu);
+
+/**
+ * nss_ppe_tx_ipsec_mtu_msg
+ *      Sends the PPE a message to configure MTU value on IPsec port.
+ *
+ * @param[in] nss_ifnum  Static IPsec interface number.
+ * @param[in] mtu        MTU of static IPsec interface.
+ *
+ * @return
+ * Status of the Tx operation.
+ */
+nss_tx_status_t nss_ppe_tx_ipsec_mtu_msg(uint32_t nss_ifnum, uint16_t mtu);
+
+/**
+ * nss_ppe_tx_ipsec_add_intf_msg
+ *      Sends the PPE a message to attach a dynamic interface number to IPsec port.
+ *
+ * @param[in] if_num  Dynamic IPsec/DTLS interface number.
+ *
+ * @return
+ * Status of the Tx operation.
+ */
+nss_tx_status_t nss_ppe_tx_ipsec_add_intf_msg(uint32_t nss_ifnum);
+
+/**
+ * nss_ppe_tx_ipsec_del_intf_msg
+ *      Sends the PPE a message to detach a dynamic interface number to IPsec port.
+ *
+ * @param[in] if_num  Dynamic IPsec/DTLS interface number.
+ *
+ * @return
+ * Status of the Tx operation.
+ */
+nss_tx_status_t nss_ppe_tx_ipsec_del_intf_msg(uint32_t nss_ifnum);
+
+/**
  * nss_ppe_stats_conn_get
  *	Gets PPE connection statistics.
  *
diff --git a/nss_ppe.c b/nss_ppe.c
index a914880..90f0c5d 100644
--- a/nss_ppe.c
+++ b/nss_ppe.c
@@ -1,6 +1,6 @@
 /*
  **************************************************************************
- * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2016-2018, 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.
@@ -196,6 +196,106 @@
 EXPORT_SYMBOL(nss_ppe_tx_l2_exception_msg);
 
 /*
+ * nss_ppe_tx_ipsec_config_msg
+ *	API to send inline IPsec port configure message to NSS FW
+ */
+nss_tx_status_t nss_ppe_tx_ipsec_config_msg(uint32_t nss_ifnum, uint32_t vsi_num, uint16_t mtu)
+{
+	struct nss_ctx_instance *nss_ctx = nss_ppe_get_context();
+	struct nss_ppe_msg npm = {0};
+
+	if (!nss_ctx) {
+		nss_warning("Can't get nss context\n");
+		return NSS_TX_FAILURE;
+	}
+
+	if (vsi_num >= NSS_PPE_VSI_NUM_MAX) {
+		nss_warning("Invalid vsi number:%u\n", vsi_num);
+		return NSS_TX_FAILURE;
+	}
+
+	nss_ppe_msg_init(&npm, NSS_PPE_INTERFACE, NSS_PPE_MSG_IPSEC_PORT_CONFIG,
+			sizeof(struct nss_ppe_ipsec_port_config_msg), NULL, NULL);
+
+	npm.msg.ipsec_config.nss_ifnum = nss_ifnum;
+	npm.msg.ipsec_config.vsi_num = vsi_num;
+	npm.msg.ipsec_config.mtu = mtu;
+
+	return nss_ppe_tx_msg_sync(nss_ctx, &npm);
+}
+EXPORT_SYMBOL(nss_ppe_tx_ipsec_config_msg);
+
+/*
+ * nss_ppe_tx_ipsec_mtu_msg
+ *	API to send IPsec port MTU change message to NSS FW
+ */
+nss_tx_status_t nss_ppe_tx_ipsec_mtu_msg(uint32_t nss_ifnum, uint16_t mtu)
+{
+	struct nss_ctx_instance *nss_ctx = nss_ppe_get_context();
+	struct nss_ppe_msg npm = {0};
+
+	if (!nss_ctx) {
+		nss_warning("Can't get nss context\n");
+		return NSS_TX_FAILURE;
+	}
+
+	nss_ppe_msg_init(&npm, NSS_PPE_INTERFACE, NSS_PPE_MSG_IPSEC_PORT_MTU_CHANGE,
+			sizeof(struct nss_ppe_ipsec_port_mtu_msg), NULL, NULL);
+
+	npm.msg.ipsec_mtu.nss_ifnum = nss_ifnum;
+	npm.msg.ipsec_mtu.mtu = mtu;
+
+	return nss_ppe_tx_msg_sync(nss_ctx, &npm);
+}
+EXPORT_SYMBOL(nss_ppe_tx_ipsec_mtu_msg);
+
+/*
+ * nss_ppe_tx_ipsec_add_intf_msg
+ *	API to attach NSS interface to IPsec port
+ */
+nss_tx_status_t nss_ppe_tx_ipsec_add_intf_msg(uint32_t nss_ifnum)
+{
+	struct nss_ctx_instance *nss_ctx = nss_ppe_get_context();
+	struct nss_ppe_msg npm = {0};
+
+	if (!nss_ctx) {
+		nss_warning("Can't get nss context\n");
+		return NSS_TX_FAILURE;
+	}
+
+	nss_ppe_msg_init(&npm, NSS_PPE_INTERFACE, NSS_PPE_MSG_IPSEC_ADD_INTF,
+			sizeof(struct nss_ppe_ipsec_add_intf_msg), NULL, NULL);
+
+	npm.msg.ipsec_addif.nss_ifnum = nss_ifnum;
+
+	return nss_ppe_tx_msg_sync(nss_ctx, &npm);
+}
+EXPORT_SYMBOL(nss_ppe_tx_ipsec_add_intf_msg);
+
+/*
+ * nss_ppe_tx_ipsec_del_intf_msg
+ *	API to detach NSS interface to IPsec port
+ */
+nss_tx_status_t nss_ppe_tx_ipsec_del_intf_msg(uint32_t nss_ifnum)
+{
+	struct nss_ctx_instance *nss_ctx = nss_ppe_get_context();
+	struct nss_ppe_msg npm = {0};
+
+	if (!nss_ctx) {
+		nss_warning("Can't get nss context\n");
+		return NSS_TX_FAILURE;
+	}
+
+	nss_ppe_msg_init(&npm, NSS_PPE_INTERFACE, NSS_PPE_MSG_IPSEC_DEL_INTF,
+			sizeof(struct nss_ppe_ipsec_del_intf_msg), NULL, NULL);
+
+	npm.msg.ipsec_delif.nss_ifnum = nss_ifnum;
+
+	return nss_ppe_tx_msg_sync(nss_ctx, &npm);
+}
+EXPORT_SYMBOL(nss_ppe_tx_ipsec_del_intf_msg);
+
+/*
  * nss_ppe_handler()
  *	Handle NSS -> HLOS messages for ppe
  */
diff --git a/nss_ppe.h b/nss_ppe.h
index bc5e53f..797793a 100644
--- a/nss_ppe.h
+++ b/nss_ppe.h
@@ -1,6 +1,6 @@
 /*
  **************************************************************************
- * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2016-2018, 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.
@@ -71,6 +71,11 @@
 #define NSS_PPE_TX_TIMEOUT 1000 /* 1 Second */
 
 /*
+ * Maximum number of VSI
+ */
+#define NSS_PPE_VSI_NUM_MAX 32
+
+/*
  * ppe nss debug stats lock
  */
 extern spinlock_t nss_ppe_stats_lock;