From 3f962ed9a4079964c48e321fd928a2719038d881 Mon Sep 17 00:00:00 2001
From: P Praneesh <ppranees@codeaurora.org>
Date: Fri, 28 May 2021 23:53:57 +0530
Subject: [PATCH] ath11k: add ampdu id in 802.11 radiotap header

AMPDU aggregate reference number is generated by
driver internally which is same across each
subframe of an ampdu.

For fetching AMPDU-ID, we need to concatenate
ppdu_id from mpdu_info and tlv_usr from tlv heder.
while parsing monitor TLV data with HAL_RX_MPDU_START
TLV tag, ampdu id is fetched from mpdu_info and
updated to corresponding mac80211 structure during
ath11k_update_radiotap.

Signed-off-by: P Praneesh <ppranees@codeaurora.org>
---
 drivers/net/wireless/ath/ath11k/dp_rx.c  |  6 ++++++
 drivers/net/wireless/ath/ath11k/hal_rx.c | 13 ++++++++++++
 drivers/net/wireless/ath/ath11k/hal_rx.h | 16 ++++++++------
 drivers/net/wireless/ath/ath11k/hw.c     | 36 +++++++++++++++++++++++++-------
 drivers/net/wireless/ath/ath11k/hw.h     |  1 +
 5 files changed, 58 insertions(+), 14 deletions(-)

diff --git a/drivers/net/wireless/ath/ath11k/dp_rx.c b/drivers/net/wireless/ath/ath11k/dp_rx.c
index 85fc903..bfdb8c2 100644
--- a/drivers/net/wireless/ath/ath11k/dp_rx.c
+++ b/drivers/net/wireless/ath/ath11k/dp_rx.c
@@ -5912,11 +5912,17 @@ static void ath11k_update_radiotap(struct ath11k *ar,
 {
 	struct ieee80211_supported_band *sband;
 	u8 *ptr = NULL;
+	u16 ampdu_id = ppduinfo->ampdu_id[ppduinfo->userid];
 
 	rxs->flag |= RX_FLAG_MACTIME_START;
 	rxs->signal = ppduinfo->rssi_comb + ATH11K_DEFAULT_NOISE_FLOOR;
 	rxs->nss = ppduinfo->nss + 1;
 
+	if (ampdu_id) {
+		rxs->flag |= RX_FLAG_AMPDU_DETAILS;
+		rxs->ampdu_reference = ampdu_id;
+	}
+
 	if (ppduinfo->he_mu_flags) {
 		rxs->flag |= RX_FLAG_RADIOTAP_HE_MU;
 		rxs->encoding = RX_ENC_HE;
diff --git a/drivers/net/wireless/ath/ath11k/hal_rx.c b/drivers/net/wireless/ath/ath11k/hal_rx.c
index c376fe8..38146ba 100644
--- a/drivers/net/wireless/ath/ath11k/hal_rx.c
+++ b/drivers/net/wireless/ath/ath11k/hal_rx.c
@@ -903,6 +903,13 @@ ath11k_hal_rx_populate_mu_user_info(void *rx_tlv, struct hal_rx_mon_ppdu_info *p
 }
 
 static
+u16 ath11k_hal_rxdesc_get_hal_mpdu_ppdu_id(struct ath11k_base *ab,
+					   struct hal_rx_mpdu_info *mpdu_info)
+{
+	return ab->hw_params.hw_ops->rx_desc_get_hal_ppdu_id(mpdu_info);
+}
+
+static
 u16 ath11k_hal_rxdesc_get_hal_mpdu_peerid(struct ath11k_base *ab,
 					  struct hal_rx_mpdu_info *mpdu_info)
 {
@@ -1564,6 +1571,12 @@ ath11k_hal_rx_parse_mon_status_tlv(struct ath11k_base *ab,
 			ppdu_info->peer_id = peer_id;
 
 		ppdu_info->mpdu_len += ath11k_hal_rxdesc_get_hal_mpdu_len(ab,mpdu_info);
+
+		if (userid < HAL_MAX_UL_MU_USERS) {
+			ppdu_info->userid = userid;
+			ppdu_info->ampdu_id[userid] =
+				ath11k_hal_rxdesc_get_hal_mpdu_ppdu_id(ab, mpdu_info);
+		}
 		break;
 	}
 	case HAL_RXPCU_PPDU_END_INFO: {
diff --git a/drivers/net/wireless/ath/ath11k/hal_rx.h b/drivers/net/wireless/ath/ath11k/hal_rx.h
index bdc0735..282a27b 100644
--- a/drivers/net/wireless/ath/ath11k/hal_rx.h
+++ b/drivers/net/wireless/ath/ath11k/hal_rx.h
@@ -222,6 +222,8 @@ struct hal_rx_mon_ppdu_info {
 	u32 num_users;
 	u32 mpdu_fcs_ok_bitmap[HAL_RX_NUM_WORDS_PER_PPDU_BITMAP];
 	struct hal_rx_user_status userstats[HAL_MAX_UL_MU_USERS];
+	u8 userid;
+	u16 ampdu_id[HAL_MAX_UL_MU_USERS];
 };
 
 #define HAL_RX_UL_OFDMA_USER_INFO_V0_W0_VALID			BIT(30)
@@ -443,21 +445,23 @@ struct hal_rx_phyrx_rssi_legacy_info {
 	__le32 info0;
 } __packed;
 
-#define HAL_RX_MPDU_INFO_INFO0_PEERID	GENMASK(31, 16)
-#define HAL_RX_MPDU_INFO_INFO1_MPDU_LEN        GENMASK(13, 0)
+#define HAL_RX_MPDU_INFO_INFO0_PPDU_ID		GENMASK(31, 16)
+#define HAL_RX_MPDU_INFO_INFO1_PEERID		GENMASK(31, 16)
+#define HAL_RX_MPDU_INFO_INFO2_MPDU_LEN		GENMASK(13, 0)
 struct hal_rx_mpdu_info_ipq8074 {
-	__le32 rsvd0;
 	__le32 info0;
-	__le32 rsvd1[11];
 	__le32 info1;
+	__le32 rsvd1[11];
+	__le32 info2;
 	__le32 rsvd2[9];
 } __packed;
 
 struct hal_rx_mpdu_info_ipq9074 {
-	__le32 rsvd0[10];
+	__le32 rsvd0[9];
 	__le32 info0;
-	__le32 rsvd1[2];
 	__le32 info1;
+	__le32 rsvd1[2];
+	__le32 info2;
 	__le32 rsvd2[9];
 } __packed;
 
diff --git a/drivers/net/wireless/ath/ath11k/hw.c b/drivers/net/wireless/ath/ath11k/hw.c
index af40d7f..548c09f 100644
--- a/drivers/net/wireless/ath/ath11k/hw.c
+++ b/drivers/net/wireless/ath/ath11k/hw.c
@@ -368,19 +368,26 @@ static u8 *ath11k_hw_ipq8074_rx_desc_get_msdu_payload(struct hal_rx_desc *desc)
 }
 
 static
-u16 ath11k_hw_ipq8074_rx_desc_get_hal_mpdu_peerid(struct hal_rx_mpdu_info *mpdu_info)
+u16 ath11k_hw_ipq8074_rx_desc_get_hal_mpdu_ppdu_id(struct hal_rx_mpdu_info *mpdu_info)
 {
-	return FIELD_GET(HAL_RX_MPDU_INFO_INFO0_PEERID,
+	return FIELD_GET(HAL_RX_MPDU_INFO_INFO0_PPDU_ID,
 			 __le32_to_cpu(mpdu_info->u.ipq8074.info0));
 }
 
 static
-u32 ath11k_hw_ipq8074_rx_desc_get_hal_mpdu_len(struct hal_rx_mpdu_info *mpdu_info)
+u16 ath11k_hw_ipq8074_rx_desc_get_hal_mpdu_peerid(struct hal_rx_mpdu_info *mpdu_info)
 {
-	return FIELD_GET(HAL_RX_MPDU_INFO_INFO1_MPDU_LEN,
+	return FIELD_GET(HAL_RX_MPDU_INFO_INFO1_PEERID,
 			 __le32_to_cpu(mpdu_info->u.ipq8074.info1));
 }
 
+static
+u32 ath11k_hw_ipq8074_rx_desc_get_hal_mpdu_len(struct hal_rx_mpdu_info *mpdu_info)
+{
+	return FIELD_GET(HAL_RX_MPDU_INFO_INFO2_MPDU_LEN,
+			 __le32_to_cpu(mpdu_info->u.ipq8074.info2));
+}
+
 #ifdef CPTCFG_ATH11K_MEM_PROFILE_512M
 static void ath11k_hw_ipq8074_rx_desc_get_offset(struct htt_rx_ring_tlv_filter *tlv_filter)
 {
@@ -703,19 +710,26 @@ static void ath11k_hw_ipq5018_set_rx_fragmentation_dst_ring(struct ath11k_base *
 }
 
 static
-u16 ath11k_hw_qcn9074_rx_desc_get_hal_mpdu_peerid(struct hal_rx_mpdu_info *mpdu_info)
+u16 ath11k_hw_qcn9074_rx_desc_get_hal_mpdu_ppdu_id(struct hal_rx_mpdu_info *mpdu_info)
 {
-	return FIELD_GET(HAL_RX_MPDU_INFO_INFO0_PEERID,
+	return FIELD_GET(HAL_RX_MPDU_INFO_INFO0_PPDU_ID,
 			 __le32_to_cpu(mpdu_info->u.qcn9074.info0));
 }
 
 static
-u32 ath11k_hw_qcn9074_rx_desc_get_hal_mpdu_len(struct hal_rx_mpdu_info *mpdu_info)
+u16 ath11k_hw_qcn9074_rx_desc_get_hal_mpdu_peerid(struct hal_rx_mpdu_info *mpdu_info)
 {
-	return FIELD_GET(HAL_RX_MPDU_INFO_INFO1_MPDU_LEN,
+	return FIELD_GET(HAL_RX_MPDU_INFO_INFO1_PEERID,
 			 __le32_to_cpu(mpdu_info->u.qcn9074.info1));
 }
 
+static
+u32 ath11k_hw_qcn9074_rx_desc_get_hal_mpdu_len(struct hal_rx_mpdu_info *mpdu_info)
+{
+	return FIELD_GET(HAL_RX_MPDU_INFO_INFO2_MPDU_LEN,
+			 __le32_to_cpu(mpdu_info->u.qcn9074.info2));
+}
+
 #ifdef CPTCFG_ATH11K_MEM_PROFILE_512M
 static void ath11k_hw_qcn9074_rx_desc_get_offset(struct htt_rx_ring_tlv_filter *tlv_filter)
 {
@@ -966,6 +980,7 @@ const struct ath11k_hw_ops ipq8074_ops = {
 	.rx_desc_get_dot11_hdr = ath11k_hw_ipq8074_rx_desc_get_dot11_hdr,
 	.rx_desc_get_crypto_header = ath11k_hw_ipq8074_rx_desc_get_crypto_hdr,
 	.fill_cfr_hdr_info = ath11k_hw_ipq8074_fill_cfr_hdr_info,
+	.rx_desc_get_hal_ppdu_id = ath11k_hw_ipq8074_rx_desc_get_hal_mpdu_ppdu_id,
 };
 
 const struct ath11k_hw_ops ipq6018_ops = {
@@ -1015,6 +1030,7 @@ const struct ath11k_hw_ops ipq6018_ops = {
 	.rx_desc_dot11_hdr_fields_valid = ath11k_hw_ipq8074_rx_desc_dot11_hdr_fields_valid,
 	.rx_desc_get_dot11_hdr = ath11k_hw_ipq8074_rx_desc_get_dot11_hdr,
 	.rx_desc_get_crypto_header = ath11k_hw_ipq8074_rx_desc_get_crypto_hdr,
+	.rx_desc_get_hal_ppdu_id = ath11k_hw_ipq8074_rx_desc_get_hal_mpdu_ppdu_id,
 };
 
 const struct ath11k_hw_ops qca6390_ops = {
@@ -1061,6 +1077,7 @@ const struct ath11k_hw_ops qca6390_ops = {
 	.rx_desc_dot11_hdr_fields_valid = ath11k_hw_ipq8074_rx_desc_dot11_hdr_fields_valid,
 	.rx_desc_get_dot11_hdr = ath11k_hw_ipq8074_rx_desc_get_dot11_hdr,
 	.rx_desc_get_crypto_header = ath11k_hw_ipq8074_rx_desc_get_crypto_hdr,
+	.rx_desc_get_hal_ppdu_id = ath11k_hw_ipq8074_rx_desc_get_hal_mpdu_ppdu_id,
 	//TODO
 	/*	.rx_desc_get_da_mcbc,
 		.rx_desc_mac_addr2_valid,
@@ -1115,6 +1132,7 @@ const struct ath11k_hw_ops qcn9074_ops = {
 	.rx_desc_get_dot11_hdr = ath11k_hw_qcn9074_rx_desc_get_dot11_hdr,
 	.rx_desc_get_crypto_header = ath11k_hw_qcn9074_rx_desc_get_crypto_hdr,
 	.fill_cfr_hdr_info = ath11k_hw_qcn9074_fill_cfr_hdr_info,
+	.rx_desc_get_hal_ppdu_id = ath11k_hw_qcn9074_rx_desc_get_hal_mpdu_ppdu_id,
 };
 
 /* IPQ5018 hw ops is similar to QCN9074 except for the dest ring remap */
@@ -1165,6 +1183,7 @@ const struct ath11k_hw_ops ipq5018_ops = {
 	.rx_desc_dot11_hdr_fields_valid = ath11k_hw_qcn9074_rx_desc_dot11_hdr_fields_valid,
 	.rx_desc_get_dot11_hdr = ath11k_hw_qcn9074_rx_desc_get_dot11_hdr,
 	.rx_desc_get_crypto_header = ath11k_hw_qcn9074_rx_desc_get_crypto_hdr,
+	.rx_desc_get_hal_ppdu_id = ath11k_hw_qcn9074_rx_desc_get_hal_mpdu_ppdu_id,
  };
 
 const struct ath11k_hw_ops qcn6122_ops = {
@@ -1215,6 +1234,7 @@ const struct ath11k_hw_ops qcn6122_ops = {
 	.rx_desc_dot11_hdr_fields_valid = ath11k_hw_qcn9074_rx_desc_dot11_hdr_fields_valid,
 	.rx_desc_get_dot11_hdr = ath11k_hw_qcn9074_rx_desc_get_dot11_hdr,
 	.rx_desc_get_crypto_header = ath11k_hw_qcn9074_rx_desc_get_crypto_hdr,
+	.rx_desc_get_hal_ppdu_id = ath11k_hw_qcn9074_rx_desc_get_hal_mpdu_ppdu_id,
 };
 
 #define ATH11K_TX_RING_MASK_0 0x1
diff --git a/drivers/net/wireless/ath/ath11k/hw.h b/drivers/net/wireless/ath/ath11k/hw.h
index c1b2ab9..ae5241b 100644
--- a/drivers/net/wireless/ath/ath11k/hw.h
+++ b/drivers/net/wireless/ath/ath11k/hw.h
@@ -273,6 +273,7 @@ struct ath11k_hw_ops {
 	void (*fill_cfr_hdr_info)(struct ath11k *ar,
 				  struct ath11k_csi_cfr_header *header,
 				  struct ath11k_cfr_peer_tx_param *params);
+	u16 (*rx_desc_get_hal_ppdu_id) (struct hal_rx_mpdu_info *mpdu_info);
 };
 
 extern const struct ath11k_hw_ops ipq8074_ops;
-- 
2.7.4

