From 1d7b7494274e98488c4add1d238f2e55ab6f7f2a Mon Sep 17 00:00:00 2001
From: Ravinder Konka <rkonka@codeaurora.org>
Date: Wed, 2 Mar 2016 21:58:53 +0530
Subject: [PATCH] msm: ipa: use timeout mechanism for holb monitoring command

When we use polling mechanism for holb monitoring command
Uc will still try to send a interrupt to notify the response.
This can result in a sync mismatch between AP and Uc and will
result in a panic. Make changes to use timeout mechanism
for holb monitoring command as well.

Change-Id: I8c74cfedff30f90dceec7f89b153018c307afa0a
Acked-by: Chaitanya Pratapa <cpratapa@qti.qualcomm.com>
Signed-off-by: Ravinder Konka <rkonka@codeaurora.org>
---
 drivers/platform/msm/ipa/ipa_v2/ipa_uc.c | 30 +++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)

diff --git a/drivers/platform/msm/ipa/ipa_v2/ipa_uc.c b/drivers/platform/msm/ipa/ipa_v2/ipa_uc.c
index f66c978bfd53..0142dace47d8 100644
--- a/drivers/platform/msm/ipa/ipa_v2/ipa_uc.c
+++ b/drivers/platform/msm/ipa/ipa_v2/ipa_uc.c
@@ -18,6 +18,9 @@
 #define IPA_UC_POLL_SLEEP_USEC 100
 #define IPA_UC_POLL_MAX_RETRY 10000
 
+static void ipa_start_monitor_holb(struct work_struct *work);
+static DECLARE_WORK(ipa_holb_work, ipa_start_monitor_holb);
+
 /**
  * enum ipa_cpu_2_hw_commands - Values that represent the commands from the CPU
  * IPA_CPU_2_HW_CMD_NO_OP : No operation is required.
@@ -463,8 +466,11 @@ static void ipa_uc_response_hdlr(enum ipa_irq_type interrupt,
 			if (uc_hdlrs[i].ipa_uc_loaded_hdlr)
 				uc_hdlrs[i].ipa_uc_loaded_hdlr();
 		}
-		/* Enable holb monitoring on IPA-USB Producer pipe if valid. */
-		ipa_uc_monitor_holb(IPA_CLIENT_USB_CONS, true);
+		/* Queue the work to enable holb monitoring on IPA-USB Producer
+		 * pipe if valid.
+		 */
+		if (ipa_ctx->ipa_hw_type == IPA_HW_v2_6L)
+			queue_work(ipa_ctx->power_mgmt_wq, &ipa_holb_work);
 	} else if (ipa_ctx->uc_ctx.uc_sram_mmio->responseOp ==
 		   IPA_HW_2_CPU_RESPONSE_CMD_COMPLETED) {
 		uc_rsp.raw32b = ipa_ctx->uc_ctx.uc_sram_mmio->responseParams;
@@ -791,12 +797,30 @@ int ipa_uc_monitor_holb(enum ipa_client_type ipa_client, bool enable)
 
 	ret = ipa_uc_send_cmd(cmd.raw32b,
 				IPA_CPU_2_HW_CMD_UPDATE_HOLB_MONITORING, 0,
-				true, 10*HZ);
+				false, 10*HZ);
 
 	return ret;
 }
 EXPORT_SYMBOL(ipa_uc_monitor_holb);
 
+/**
+ * ipa_start_monitor_holb() - Send HOLB command to monitor IPA-USB
+ * producer pipe.
+ *
+ * This function is called after uc is loaded to start monitoring
+ * IPA pipe towrds USB in case if USB is already connected.
+ *
+ * Return codes:
+ * None
+ */
+static void ipa_start_monitor_holb(struct work_struct *work)
+{
+	IPADBG("starting holb monitoring on IPA_CLIENT_USB_CONS\n");
+	IPA2_ACTIVE_CLIENTS_INC_SIMPLE();
+	ipa_uc_monitor_holb(IPA_CLIENT_USB_CONS, true);
+	IPA2_ACTIVE_CLIENTS_DEC_SIMPLE();
+}
+
 
 /**
  * ipa_uc_notify_clk_state() - notify to uC of clock enable / disable