qcacmn: Fix peer ref_cnt usage and add logs for the same

Enable logs to print peer ref_cnt and decrement ref_cnt
in helper functions.

Change-Id: I6e6a275fba35003011095d93c79d7a052d5ec56e
CRs-Fixed: 1116647
diff --git a/dp/wifi3.0/dp_main.c b/dp/wifi3.0/dp_main.c
index 6c52dac..d862235 100644
--- a/dp/wifi3.0/dp_main.c
+++ b/dp/wifi3.0/dp_main.c
@@ -1383,8 +1383,9 @@
 	dp_peer_find_hash_add(soc, peer);
 
 	QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_HIGH,
-		"vdev %p created peer %p (%pM)",
-		vdev, peer, peer->mac_addr.raw);
+		"vdev %p created peer %p (%pM) ref_cnt: %d",
+		vdev, peer, peer->mac_addr.raw,
+		qdf_atomic_read(&peer->ref_cnt));
 	/*
 	 * For every peer MAp message search and set if bss_peer
 	 */
@@ -1481,6 +1482,9 @@
 	 * concurrently with the empty check.
 	 */
 	qdf_spin_lock_bh(&soc->peer_ref_mutex);
+	QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
+		  "%s: peer %p ref_cnt(before decrement): %d\n", __func__,
+		  peer, qdf_atomic_read(&peer->ref_cnt));
 	if (qdf_atomic_dec_and_test(&peer->ref_cnt)) {
 		peer_id = peer->peer_ids[0];
 
diff --git a/dp/wifi3.0/dp_peer.c b/dp/wifi3.0/dp_peer.c
index 6097631..6f08e86 100644
--- a/dp/wifi3.0/dp_peer.c
+++ b/dp/wifi3.0/dp_peer.c
@@ -336,6 +336,9 @@
 		/* peer's ref count was already incremented by
 		 * peer_find_hash_find
 		 */
+		QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
+			  "%s: ref_cnt: %d", __func__,
+			   qdf_atomic_read(&peer->ref_cnt));
 		soc->peer_id_to_obj_map[peer_id] = peer;
 
 		if (dp_peer_find_add_id_to_obj(peer, peer_id)) {
@@ -445,6 +448,12 @@
 	/* Multiple peer ids? How can know peer id? */
 	*local_id = peer->local_id;
 	DP_TRACE(INFO, "%s: peer %p id %d", __func__, peer, *local_id);
+
+	/* ref_cnt is incremented inside dp_peer_find_hash_find().
+	 * Decrement it here.
+	 */
+	qdf_atomic_dec(&peer->ref_cnt);
+
 	return peer;
 }
 
@@ -1007,9 +1016,12 @@
 		return NULL;
 
 	*local_id = peer->local_id;
+	DP_TRACE(INFO, "peer %p vdev %p lcoal id %d", peer, vdev, *local_id);
 
-	DP_TRACE(INFO, "peer %p vdev %p lcoal id %d",
-			peer, vdev, *local_id);
+	/* ref_cnt is incremented inside dp_peer_find_hash_find().
+	 * Decrement it here.
+	 */
+	qdf_atomic_dec(&peer->ref_cnt);
 
 	return peer;
 }
@@ -1073,8 +1085,13 @@
 		return QDF_STATUS_E_FAILURE;
 	}
 	peer->state = state;
-	DP_TRACE(INFO, "peer %p state %d",
-			peer, peer->state);
+
+	DP_TRACE(INFO, "peer %p state %d", peer, peer->state);
+	/* ref_cnt is incremented inside dp_peer_find_hash_find().
+	 * Decrement it here.
+	 */
+	qdf_atomic_dec(&peer->ref_cnt);
+
 	return QDF_STATUS_SUCCESS;
 }