From 537a8f2292ba9052957e8284161bcee0635e4223 Mon Sep 17 00:00:00 2001
From: Ramya Gnanasekar <quic_rgnanase@quicinc.com>
Date: Tue, 11 Apr 2023 14:15:36 +0530
Subject: [PATCH] ath11k: Fix ppdu_id from firmware PPDU stats

ppdu_id in USR_COMPLTN_ACK_BA_STATUS TLV will have firmware meta data
last 7 bits.
When ppdu_id is taken as such, during parsing this is treated as different
ppdu_id which causes incorrect stats update. Since firmware will use
this MSB 7 bits for internal accounting and optimization,
it is recommended to use first 25 bits when fetching ppdu for USR_COMPLTN_ACK_BA_STATUS.

Signed-off-by: Ramya Gnanasekar <quic_rgnanase@quicinc.com>

--- a/drivers/net/wireless/ath/ath11k/dp.h
+++ b/drivers/net/wireless/ath/ath11k/dp.h
@@ -1419,6 +1419,7 @@ struct htt_ppdu_stats_usr_cmpltn_cmn {
 #define HTT_PPDU_STATS_ACK_BA_INFO_TID_NUM	GENMASK(31, 25)
 
 #define HTT_PPDU_STATS_NON_QOS_TID	16
+#define HTT_PPDU_STATS_PPDU_ID		GENMASK(24, 0)
 
 struct htt_ppdu_stats_usr_cmpltn_ack_ba_status {
 	u32 ppdu_id;
--- a/drivers/net/wireless/ath/ath11k/dp_rx.c
+++ b/drivers/net/wireless/ath/ath11k/dp_rx.c
@@ -1289,7 +1289,7 @@ static int ath11k_htt_tlv_ppdu_stats_par
 	struct htt_ppdu_user_stats *user_stats = NULL;
 	int cur_user;
 	u16 peer_id;
-	u32 frame_type;
+	u32 frame_type, ppdu_id;
 
 	ppdu_info = data;
 
@@ -1370,6 +1370,8 @@ static int ath11k_htt_tlv_ppdu_stats_par
 			return -EINVAL;
 		}
 
+		ppdu_id =
+		((struct htt_ppdu_stats_usr_cmpltn_ack_ba_status *)ptr)->ppdu_id;
 		peer_id =
 		((struct htt_ppdu_stats_usr_cmpltn_ack_ba_status *)ptr)->sw_peer_id;
 		cur_user = ath11k_get_ppdu_user_index(&ppdu_info->ppdu_stats,
@@ -1381,6 +1383,7 @@ static int ath11k_htt_tlv_ppdu_stats_par
 		user_stats->is_valid_peer_id = true;
 		memcpy((void *)&user_stats->ack_ba, ptr,
 		       sizeof(struct htt_ppdu_stats_usr_cmpltn_ack_ba_status));
+		ppdu_info->ppdu_id = FIELD_GET(HTT_PPDU_STATS_PPDU_ID, ppdu_id);
 		user_stats->tlv_flags |= BIT(tag);
 		break;
 	case HTT_PPDU_STATS_TAG_USR_COMMON:
