Merge "qca-wifi: Add command for disabling inactivity probing"
diff --git a/dp/wifi3.0/dp_tx_capture.c b/dp/wifi3.0/dp_tx_capture.c
index 9774310..5a0d3b8 100644
--- a/dp/wifi3.0/dp_tx_capture.c
+++ b/dp/wifi3.0/dp_tx_capture.c
@@ -147,7 +147,7 @@
 	if (qdf_unlikely(!qdf_nbuf_is_queue_empty(qhead))) {
 		QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE, QDF_TRACE_LEVEL_FATAL,
 			  "Queue is not empty len(%d) !!",
-			  qdf_nbuf_queue_len(q_head));
+			  qdf_nbuf_queue_len(qhead));
 		QDF_BUG(0);
 	}
 }
@@ -558,14 +558,15 @@
 	int tid;
 	struct dp_tx_tid *tx_tid;
 
+	/*
+	 * For the newly created peer after tx monitor turned ON,
+	 * initialization check is already taken care in queue init
+	 */
 	dp_peer_tid_queue_init(peer);
 	for (tid = 0; tid < DP_MAX_TIDS; tid++) {
 		tx_tid = &peer->tx_capture.tx_tid[tid];
 		tx_tid->peer_id = peer_id;
-		if (tx_tid->tid != tid) {
-			qdf_err("tx tid is corrupted for tid %d, peer_id %d", tid, peer_id);
-			tx_tid->tid = tid;
-		}
+		tx_tid->tid = tid;
 	}
 }
 
@@ -576,9 +577,26 @@
  */
 void dp_peer_tid_queue_init(struct dp_peer *peer)
 {
+	struct dp_pdev *pdev;
+	struct dp_vdev *vdev;
 	int tid;
 	struct dp_tx_tid *tx_tid;
 
+	if (!peer)
+		return;
+
+	vdev = peer->vdev;
+	pdev = vdev->pdev;
+
+	/* only if tx capture is turned on we will initialize the tid */
+	if (qdf_atomic_read(&pdev->tx_capture.tx_cap_usr_mode) ==
+	    CDP_TX_ENH_CAPTURE_DISABLED)
+		return;
+
+	QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE,
+		  QDF_TRACE_LEVEL_INFO_LOW,
+		  "peer(%p) id:%d init!!", peer, peer->peer_id);
+
 	for (tid = 0; tid < DP_MAX_TIDS; tid++) {
 		tx_tid = &peer->tx_capture.tx_tid[tid];
 
@@ -586,6 +604,7 @@
 						&tx_tid->tid_flags))
 			continue;
 
+		tx_tid->peer_id = peer->peer_id;
 		tx_tid->tid = tid;
 
 		check_queue_empty(&tx_tid->defer_msdu_q);
@@ -609,6 +628,7 @@
 			for (i = 0; i < tid; i++) {
 				tx_tid = &peer->tx_capture.tx_tid[i];
 				qdf_mem_free(tx_tid->xretry_ppdu);
+				tx_tid->xretry_ppdu = NULL;
 				qdf_atomic_clear_bit(DP_PEER_TX_TID_INIT_DONE_BIT,
 							&tx_tid->tid_flags);
 			}
@@ -670,6 +690,10 @@
 	if (!peer->tx_capture.is_tid_initialized)
 		return;
 
+	QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE,
+		  QDF_TRACE_LEVEL_INFO_LOW,
+		  "peer(%p) id:%d cleanup!!", peer, peer->peer_id);
+
 	for (tid = 0; tid < DP_MAX_TIDS; tid++) {
 		uint32_t len = 0;
 		uint32_t actual_len = 0;
@@ -731,6 +755,7 @@
 
 		TX_CAP_NBUF_QUEUE_FREE(&xretry_user->mpdu_q);
 		qdf_mem_free(xretry_ppdu);
+		tx_tid->xretry_ppdu = NULL;
 
 		tx_tid->max_ppdu_id = 0;
 	}
@@ -1669,9 +1694,18 @@
 				 struct dp_peer *peer,
 				 void *arg)
 {
+	/* disable tx capture flag in peer */
+	peer->tx_cap_enabled = 0;
 	dp_peer_tid_queue_cleanup(peer);
 }
 
+static void  dp_peer_init_msdu_q(struct dp_soc *soc,
+				 struct dp_peer *peer,
+				 void *arg)
+{
+	dp_peer_tid_queue_init(peer);
+}
+
 /*
  * dp_soc_is_tx_capture_set_in_pdev() - API to get tx capture set in any pdev
  * @soc_handle: DP_SOC handle
@@ -1753,6 +1787,9 @@
 void
 dp_enh_tx_capture_enable(struct dp_pdev *pdev, uint8_t user_mode)
 {
+	dp_pdev_iterate_peer(pdev, dp_peer_init_msdu_q, NULL,
+			     DP_MOD_ID_TX_CAPTURE);
+
 	if (dp_soc_is_tx_capture_set_in_pdev(pdev->soc) == 1)
 		dp_soc_set_txrx_ring_map_single(pdev->soc);
 
@@ -4563,6 +4600,14 @@
 				continue;
 			}
 
+			if (!peer->tx_capture.is_tid_initialized) {
+				dp_ppdu_desc_free(ptr_nbuf_list, usr_idx);
+				user->skip = 1;
+				dp_peer_unref_delete(peer,
+						     DP_MOD_ID_TX_CAPTURE);
+				continue;
+			}
+
 			tx_tid = &peer->tx_capture.tx_tid[user->tid];
 			ppdu_id = ppdu_desc->ppdu_id;
 
@@ -5098,7 +5143,7 @@
 		 */
 		/* print ppdu_desc info for debugging purpose */
 		QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE,
-			  QDF_TRACE_LEVEL_INFO_HIGH,
+			  QDF_TRACE_LEVEL_INFO_LOW,
 			  "%s: ppdu[%d], p_id[%d], tid[%d], fctrl[0x%x 0x%x] ftype[%d] h_frm_t[%d] seq[%d] tsf[%u b %u] dur[%u]",
 			  __func__, ppdu_desc->ppdu_id,
 			  ppdu_desc->user[0].peer_id,
@@ -5389,11 +5434,13 @@
 		ppdu_desc->sched_cmdid = ppdu_info->sched_cmdid;
 
 		if (starved) {
-			qdf_err("ppdu starved fc[0x%x] h_ftype[%d] tlv_bitmap[0x%x] cs[%d]\n",
-				ppdu_desc->frame_ctrl,
-				ppdu_desc->htt_frame_type,
-				ppdu_desc->tlv_bitmap,
-				ppdu_desc->user[0].completion_status);
+			QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE,
+				  QDF_TRACE_LEVEL_INFO_MED,
+				  "ppdu starved fc[0x%x] h_ftype[%d] tlv_bitmap[0x%x] cs[%d]\n",
+				  ppdu_desc->frame_ctrl,
+				  ppdu_desc->htt_frame_type,
+				  ppdu_desc->tlv_bitmap,
+				  ppdu_desc->user[0].completion_status);
 			starved = 0;
 		}
 
diff --git a/dp/wifi3.0/dp_txrx_wds.h b/dp/wifi3.0/dp_txrx_wds.h
index e468651..899c249 100644
--- a/dp/wifi3.0/dp_txrx_wds.h
+++ b/dp/wifi3.0/dp_txrx_wds.h
@@ -393,13 +393,23 @@
 	qdf_spin_lock_bh(&soc->ast_lock);
 	ast = soc->ast_table[sa_idx];
 
+	if (!ast) {
+		qdf_spin_unlock_bh(&soc->ast_lock);
+		return QDF_STATUS_E_NULL_VALUE;
+	}
+
+	if (!ast->is_mapped) {
+		qdf_spin_unlock_bh(&soc->ast_lock);
+		return QDF_STATUS_E_INVAL;
+	}
+
 	/*
 	 * Ensure we are updating the right AST entry by
 	 * validating ast_idx.
 	 * There is a possibility we might arrive here without
 	 * AST MAP event , so this check is mandatory
 	 */
-	if (ast && ast->is_mapped && (ast->ast_idx == sa_idx)) {
+	if (ast->ast_idx == sa_idx) {
 		ast->is_active = is_active;
 		qdf_spin_unlock_bh(&soc->ast_lock);
 		return QDF_STATUS_SUCCESS;