qcacld-3.0: Runtime puts for HTT messages

HTT messages do not have a tx complete and should
have their runtime puts done when the firmware response
come.  Tag messages without responses so that the
put can be done after issuing the message.  Also do
runtime put in error case.

Change-Id: I7253ace95ca6bb4fa17bc6d82ec52fc598d17712
CRs-Fixed: 935300
diff --git a/core/dp/htt/htt_h2t.c b/core/dp/htt/htt_h2t.c
index 59b0f06..cbfa4a7 100644
--- a/core/dp/htt/htt_h2t.c
+++ b/core/dp/htt/htt_h2t.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011-2015 The Linux Foundation. All rights reserved.
+ * Copyright (c) 2011-2016 The Linux Foundation. All rights reserved.
  *
  * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
  *
@@ -417,7 +417,7 @@
 			       cdf_nbuf_data(msg),
 			       cdf_nbuf_len(msg),
 			       pdev->htc_endpoint,
-			       1); /* tag - not relevant here */
+			       HTC_TX_PACKET_TAG_RUNTIME_PUT);
 
 	SET_HTC_PACKET_NET_BUF_CONTEXT(&pkt->htc_pkt, msg);
 
@@ -439,6 +439,7 @@
 	struct htt_htc_pkt *pkt;
 	cdf_nbuf_t msg;
 	uint32_t *msg_word;
+	uint16_t htc_tag = 1;
 
 	pkt = htt_htc_pkt_alloc(pdev);
 	if (!pkt)
@@ -452,6 +453,9 @@
 		return -EINVAL;      /* failure */
 	}
 
+	if (stats_type_reset_mask)
+		htc_tag = HTC_TX_PACKET_TAG_RUNTIME_PUT;
+
 	/* show that this is not a tx frame download
 	 * (not required, but helpful)
 	 */
@@ -503,7 +507,7 @@
 			       cdf_nbuf_data(msg),
 			       cdf_nbuf_len(msg),
 			       pdev->htc_endpoint,
-			       1); /* tag - not relevant here */
+			       htc_tag); /* tag - not relevant here */
 
 	SET_HTC_PACKET_NET_BUF_CONTEXT(&pkt->htc_pkt, msg);
 
@@ -559,7 +563,7 @@
 			       cdf_nbuf_data(msg),
 			       cdf_nbuf_len(msg),
 			       pdev->htc_endpoint,
-			       1); /* tag - not relevant here */
+			       HTC_TX_PACKET_TAG_RUNTIME_PUT);
 
 	SET_HTC_PACKET_NET_BUF_CONTEXT(&pkt->htc_pkt, msg);
 
@@ -626,7 +630,7 @@
 			       cdf_nbuf_data(msg),
 			       cdf_nbuf_len(msg),
 			       pdev->htc_endpoint,
-			       1); /* tag - not relevant here */
+			       HTC_TX_PACKET_TAG_RUNTIME_PUT);
 
 	SET_HTC_PACKET_NET_BUF_CONTEXT(&pkt->htc_pkt, msg);
 
@@ -733,7 +737,7 @@
 			       cdf_nbuf_data(msg),
 			       cdf_nbuf_len(msg),
 			       pdev->htc_endpoint,
-			       1); /* tag - not relevant here */
+			       HTC_TX_PACKET_TAG_RUNTIME_PUT);
 
 	SET_HTC_PACKET_NET_BUF_CONTEXT(&pkt->htc_pkt, msg);
 
diff --git a/core/dp/htt/htt_t2h.c b/core/dp/htt/htt_t2h.c
index b4de172..639c345 100644
--- a/core/dp/htt/htt_t2h.c
+++ b/core/dp/htt/htt_t2h.c
@@ -141,6 +141,7 @@
 	switch (msg_type) {
 	case HTT_T2H_MSG_TYPE_VERSION_CONF:
 	{
+		cdf_runtime_pm_put();
 		pdev->tgt_ver.major = HTT_VER_CONF_MAJOR_GET(*msg_word);
 		pdev->tgt_ver.minor = HTT_VER_CONF_MINOR_GET(*msg_word);
 		cdf_print
@@ -287,6 +288,7 @@
 			ol_tx_single_completion_handler(pdev->txrx_pdev,
 							compl_msg->status,
 							compl_msg->desc_id);
+			cdf_runtime_pm_put();
 			HTT_TX_SCHED(pdev);
 		} else {
 			cdf_print("Ignoring HTT_T2H_MSG_TYPE_MGMT_TX_COMPL_IND indication\n");
@@ -302,6 +304,7 @@
 		cookie |= ((uint64_t) (*(msg_word + 2))) << 32;
 
 		stats_info_list = (uint8_t *) (msg_word + 3);
+		cdf_runtime_pm_put();
 		ol_txrx_fw_stats_handler(pdev->txrx_pdev, cookie,
 					 stats_info_list);
 		break;
@@ -357,6 +360,7 @@
 		uint8_t *op_msg_buffer;
 		uint8_t *msg_start_ptr;
 
+		cdf_runtime_pm_put();
 		msg_start_ptr = (uint8_t *) msg_word;
 		op_code =
 			HTT_WDI_IPA_OP_RESPONSE_OP_CODE_GET(*msg_word);
diff --git a/core/htc/htc_packet.h b/core/htc/htc_packet.h
index ea0d75f..ca3698f 100644
--- a/core/htc/htc_packet.h
+++ b/core/htc/htc_packet.h
@@ -75,6 +75,10 @@
 #define HTC_TX_PACKET_TAG_BUNDLED      (HTC_TX_PACKET_TAG_USER_DEFINED + 1)
 #define HTC_TX_PACKET_TAG_AUTO_PM      (HTC_TX_PACKET_TAG_USER_DEFINED + 2)
 
+/* Tag packet for runtime put after sending */
+#define HTC_TX_PACKET_TAG_RUNTIME_PUT  (HTC_TX_PACKET_TAG_USER_DEFINED + 3)
+
+
 #define HTC_TX_PACKET_FLAG_FIXUP_NETBUF (1 << 0)
 
 typedef struct _HTC_RX_PACKET_INFO {
diff --git a/core/htc/htc_send.c b/core/htc/htc_send.c
index 3b3d3c7..26821fd 100644
--- a/core/htc/htc_send.c
+++ b/core/htc/htc_send.c
@@ -577,6 +577,13 @@
 			break;
 		}
 
+		/*
+		 * For HTT messages without a response from fw,
+		 *   do the runtime put here.
+		 * otherwise runtime put will be done when the fw response comes
+		 */
+		if (pPacket->PktInfo.AsTx.Tag == HTC_TX_PACKET_TAG_RUNTIME_PUT)
+			hif_pm_runtime_put(target->hif_dev);
 	}
 	if (cdf_unlikely(A_FAILED(status))) {
 #if defined(HIF_USB)