[qca-nss-drv] Crypto PM event notification

Add Crypto PM event notification for Crypto driver
to scale the Crypto clocks when NSS fabrix clocks scale

Change-Id: I39c1df85d9e94b0b5c59d4630f818eef9044119c
Signed-off-by: Samarjeet Banerjee <banerjee@codeaurora.org>
diff --git a/exports/nss_crypto.h b/exports/nss_crypto.h
index e310460..daf3438 100644
--- a/exports/nss_crypto.h
+++ b/exports/nss_crypto.h
@@ -1,6 +1,6 @@
 /*
  **************************************************************************
- * Copyright (c) 2014,2015, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2014 - 2016, 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.
@@ -183,6 +183,16 @@
 typedef void (*nss_crypto_buf_callback_t)(void *app_data, void *buf, uint32_t paddr, uint16_t len);
 
 /**
+ * @brief PM event callback
+ *
+ * @param app_data[IN] context of the callback user
+ * @param turbo[IN] turbo mode event
+ *
+ * @return
+ */
+typedef void (*nss_crypto_pm_event_callback_t)(void *app_data, bool turbo);
+
+/**
  * @brief send an Crypto message
  *
  * @param nss_ctx[IN] NSS HLOS driver's context
@@ -218,13 +228,21 @@
  * @brief register a data callback handler with HLOS driver
  *
  * @param cb[IN] data callback function
- * @param app_data[IN] conext of the callback user
+ * @param app_data[IN] context of the callback user
  *
  * @return
  */
 extern struct nss_ctx_instance *nss_crypto_data_register(nss_crypto_buf_callback_t cb, void *app_data);
 
 /**
+ * @brief register PM event callback function
+ *
+ * @param cb[IN] callack handler
+ * @param app_data[IN] context of the callback user
+ */
+extern void nss_crypto_pm_notify_register(nss_crypto_pm_event_callback_t cb, void *app_data);
+
+/**
  * @brief unregister the message notifier
  *
  * @param ctx[IN] HLOS driver's context
diff --git a/nss_core.h b/nss_core.h
index d3aaab3..f45bec9 100755
--- a/nss_core.h
+++ b/nss_core.h
@@ -862,6 +862,7 @@
 					/* IPsec event callback function */
 	nss_crypto_msg_callback_t crypto_msg_callback;
 	nss_crypto_buf_callback_t crypto_buf_callback;
+	nss_crypto_pm_event_callback_t crypto_pm_callback;
 					/* crypto interface callback functions */
 	nss_profiler_callback_t profiler_callback[NSS_MAX_CORES];
 					/* Profiler interface callback function */
@@ -895,6 +896,7 @@
 	void *ipv4_ctx;			/* IPv4 connection manager context */
 	void *ipv6_ctx;			/* IPv6 connection manager context */
 	void *crypto_ctx;		/* Crypto interface context */
+	void *crypto_pm_ctx;		/* Crypto PM context */
 	void *profiler_ctx[NSS_MAX_CORES];
 					/* Profiler interface context */
 
diff --git a/nss_crypto.c b/nss_crypto.c
index bf2ba61..4f76d93 100644
--- a/nss_crypto.c
+++ b/nss_crypto.c
@@ -297,6 +297,16 @@
 }
 
 /*
+ * nss_crypto_pm_notify_register()
+ * 	register a PM notify callback routine
+ */
+void nss_crypto_pm_notify_register(nss_crypto_pm_event_callback_t cb, void *app_data)
+{
+	nss_top_main.crypto_pm_ctx = app_data;
+	nss_top_main.crypto_pm_callback = cb;
+}
+
+/*
  * nss_crypto_register_handler()
  */
 void nss_crypto_register_handler()
@@ -318,6 +328,7 @@
 EXPORT_SYMBOL(nss_crypto_notify_unregister);
 EXPORT_SYMBOL(nss_crypto_data_register);
 EXPORT_SYMBOL(nss_crypto_data_unregister);
+EXPORT_SYMBOL(nss_crypto_pm_notify_register);
 EXPORT_SYMBOL(nss_crypto_tx_msg);
 EXPORT_SYMBOL(nss_crypto_tx_buf);
 EXPORT_SYMBOL(nss_crypto_msg_init);
diff --git a/nss_init.c b/nss_init.c
index 9bfcc46..435554d 100644
--- a/nss_init.c
+++ b/nss_init.c
@@ -160,7 +160,9 @@
  */
 void nss_wq_function (struct work_struct *work)
 {
+	nss_crypto_pm_event_callback_t crypto_pm_cb;
 	nss_work_t *my_work = (nss_work_t *)work;
+	bool turbo = false;
 
 	nss_freq_change(&nss_top_main.nss[NSS_CORE_0], my_work->frequency, my_work->stats_enable, 0);
 	if (nss_top_main.nss[NSS_CORE_1].state == NSS_CORE_STATE_INITIALIZED) {
@@ -207,6 +209,15 @@
 			clk_set_rate(nss_fab0_clk, NSS_FABRIC0_IDLE);
 			clk_set_rate(nss_fab1_clk, NSS_FABRIC1_IDLE);
 		}
+
+		/*
+		 * notify crypto about the clock change
+		 */
+		crypto_pm_cb = nss_top_main.crypto_pm_callback;
+		if (crypto_pm_cb) {
+			turbo = (my_work->frequency >= NSS_FREQ_733);
+			crypto_pm_cb(nss_top_main.crypto_pm_ctx, turbo);
+		}
 	}
 #endif
 #endif