From 396176575be9767a79d451fba4fe2931305f0435 Mon Sep 17 00:00:00 2001
From: Raj Kumar Bhagat <quic_rajkbhag@quicinc.com>
Date: Mon, 7 Nov 2022 21:49:20 +0530
Subject: [PATCH] ath11k: fix incorrect ast index assignment for wds peer

Currently, same ast index is assigned for different nss wds peer mac
addresses which is incorrect. However, firmware provides the correct
and different ast index for different mac addresses.

Hence, fix this issue by assigning the correct ast index provided by
the firmware.

Signed-off-by: Raj Kumar Bhagat <quic_rajkbhag@quicinc.com>
---
 drivers/net/wireless/ath/ath11k/nss.c  | 5 +++--
 drivers/net/wireless/ath/ath11k/nss.h  | 6 ++++--
 drivers/net/wireless/ath/ath11k/peer.c | 3 +--
 3 files changed, 8 insertions(+), 6 deletions(-)

--- a/drivers/net/wireless/ath/ath11k/nss.c
+++ b/drivers/net/wireless/ath/ath11k/nss.c
@@ -3874,13 +3874,14 @@ msg_free:
 }
 
 int ath11k_nss_map_wds_peer(struct ath11k *ar, struct ath11k_peer *peer,
-			    u8 *dest_mac, enum ath11k_ast_entry_type type)
+			    u8 *dest_mac, struct ath11k_ast_entry *ast_entry)
 {
 	struct ath11k_base *ab = ar->ab;
 	struct nss_wifili_wds_peer_map_msg *wds_peer_map_msg;
 	struct nss_wifili_msg *wlmsg = NULL;
 	nss_wifili_msg_callback_t msg_cb;
 	nss_tx_status_t status;
+	enum ath11k_ast_entry_type type = ast_entry->type;
 	int ret = 0;
 
 	wlmsg = kzalloc(sizeof(struct nss_wifili_msg), GFP_ATOMIC);
@@ -3890,7 +3891,7 @@ int ath11k_nss_map_wds_peer(struct ath11
 	wds_peer_map_msg = &wlmsg->msg.wdspeermapmsg;
 
 	wds_peer_map_msg->vdev_id = peer->vdev_id;
-	wds_peer_map_msg->ast_idx = peer->hw_peer_id;
+	wds_peer_map_msg->ast_idx = ast_entry->ast_idx;
 
 	if (type == ATH11K_AST_TYPE_MEC)
 		wds_peer_map_msg->peer_id = NSS_WIFILI_MEC_PEER_ID;
--- a/drivers/net/wireless/ath/ath11k/nss.h
+++ b/drivers/net/wireless/ath/ath11k/nss.h
@@ -20,6 +20,7 @@ struct ath11k;
 struct ath11k_base;
 struct ath11k_vif;
 struct ath11k_peer;
+struct ath11k_ast_entry;
 struct ath11k_sta;
 enum ath11k_ast_entry_type;
 struct hal_rx_mon_ppdu_info;
@@ -289,7 +290,7 @@ int ath11k_nss_add_wds_peer(struct ath11
 int ath11k_nss_update_wds_peer(struct ath11k *ar, struct ath11k_peer *peer,
 			       u8 *dest_mac);
 int ath11k_nss_map_wds_peer(struct ath11k *ar, struct ath11k_peer *peer,
-			    u8 *dest_mac, enum ath11k_ast_entry_type type);
+			    u8 *dest_mac, struct ath11k_ast_entry *ast_entry);
 int ath11k_nss_del_wds_peer(struct ath11k *ar, u8 *peer_addr,
 			    int peer_id, u8 *dest_mac);
 int ath11k_nss_ext_vdev_cfg_wds_peer(struct ath11k_vif *arvif,
@@ -408,7 +409,8 @@ static inline int ath11k_nss_update_wds_
 }
 
 static inline int ath11k_nss_map_wds_peer(struct ath11k *ar, struct ath11k_peer *peer,
-					  u8 *dest_mac, int type)
+					  u8 *dest_mac,
+					  struct ath11k_ast_entry *ast_entry)
 {
 	return 0;
 }
--- a/drivers/net/wireless/ath/ath11k/peer.c
+++ b/drivers/net/wireless/ath/ath11k/peer.c
@@ -373,8 +373,7 @@ void ath11k_peer_map_ast(struct ath11k *
 
 		if ((ast_entry->type == ATH11K_AST_TYPE_WDS) ||
 		    (ast_entry->type == ATH11K_AST_TYPE_MEC))
-			ath11k_nss_map_wds_peer(ar, peer, mac_addr,
-						ast_entry->type);
+			ath11k_nss_map_wds_peer(ar, peer, mac_addr, ast_entry);
 
 		ath11k_dbg(ab, ATH11K_DBG_MAC, "ath11k_peer_map_ast peer %pM ast_entry %pM\n",
 			   peer->addr, ast_entry->addr);
