xref: /linux/drivers/net/wireless/ath/ath12k/peer.h (revision ab93e0dd72c37d378dd936f031ffb83ff2bd87ce)
1 /* SPDX-License-Identifier: BSD-3-Clause-Clear */
2 /*
3  * Copyright (c) 2018-2021 The Linux Foundation. All rights reserved.
4  * Copyright (c) 2021-2025 Qualcomm Innovation Center, Inc. All rights reserved.
5  */
6 
7 #ifndef ATH12K_PEER_H
8 #define ATH12K_PEER_H
9 
10 #include "dp_rx.h"
11 
12 struct ppdu_user_delayba {
13 	u16 sw_peer_id;
14 	u32 info0;
15 	u16 ru_end;
16 	u16 ru_start;
17 	u32 info1;
18 	u32 rate_flags;
19 	u32 resp_rate_flags;
20 };
21 
22 #define ATH12K_PEER_ML_ID_VALID         BIT(13)
23 
24 struct ath12k_peer {
25 	struct list_head list;
26 	struct ieee80211_sta *sta;
27 	int vdev_id;
28 	u8 addr[ETH_ALEN];
29 	int peer_id;
30 	u16 ast_hash;
31 	u8 pdev_idx;
32 	u16 hw_peer_id;
33 
34 	/* protected by ab->data_lock */
35 	struct ieee80211_key_conf *keys[WMI_MAX_KEY_INDEX + 1];
36 	struct ath12k_dp_rx_tid rx_tid[IEEE80211_NUM_TIDS + 1];
37 
38 	/* Info used in MMIC verification of
39 	 * RX fragments
40 	 */
41 	struct crypto_shash *tfm_mmic;
42 	u8 mcast_keyidx;
43 	u8 ucast_keyidx;
44 	u16 sec_type;
45 	u16 sec_type_grp;
46 	struct ppdu_user_delayba ppdu_stats_delayba;
47 	bool delayba_flag;
48 	bool is_authorized;
49 	bool mlo;
50 	/* protected by ab->data_lock */
51 	bool dp_setup_done;
52 
53 	u16 ml_id;
54 
55 	/* any other ML info common for all partners can be added
56 	 * here and would be same for all partner peers.
57 	 */
58 	u8 ml_addr[ETH_ALEN];
59 
60 	/* To ensure only certain work related to dp is done once */
61 	bool primary_link;
62 
63 	/* for reference to ath12k_link_sta */
64 	u8 link_id;
65 	bool ucast_ra_only;
66 };
67 
68 struct ath12k_ml_peer {
69 	struct list_head list;
70 	u8 addr[ETH_ALEN];
71 	u16 id;
72 };
73 
74 void ath12k_peer_unmap_event(struct ath12k_base *ab, u16 peer_id);
75 void ath12k_peer_map_event(struct ath12k_base *ab, u8 vdev_id, u16 peer_id,
76 			   u8 *mac_addr, u16 ast_hash, u16 hw_peer_id);
77 struct ath12k_peer *ath12k_peer_find(struct ath12k_base *ab, int vdev_id,
78 				     const u8 *addr);
79 struct ath12k_peer *ath12k_peer_find_by_addr(struct ath12k_base *ab,
80 					     const u8 *addr);
81 struct ath12k_peer *ath12k_peer_find_by_id(struct ath12k_base *ab, int peer_id);
82 void ath12k_peer_cleanup(struct ath12k *ar, u32 vdev_id);
83 int ath12k_peer_delete(struct ath12k *ar, u32 vdev_id, u8 *addr);
84 int ath12k_peer_create(struct ath12k *ar, struct ath12k_link_vif *arvif,
85 		       struct ieee80211_sta *sta,
86 		       struct ath12k_wmi_peer_create_arg *arg);
87 int ath12k_wait_for_peer_delete_done(struct ath12k *ar, u32 vdev_id,
88 				     const u8 *addr);
89 bool ath12k_peer_exist_by_vdev_id(struct ath12k_base *ab, int vdev_id);
90 struct ath12k_peer *ath12k_peer_find_by_ast(struct ath12k_base *ab, int ast_hash);
91 int ath12k_peer_ml_create(struct ath12k_hw *ah, struct ieee80211_sta *sta);
92 int ath12k_peer_ml_delete(struct ath12k_hw *ah, struct ieee80211_sta *sta);
93 int ath12k_peer_mlo_link_peers_delete(struct ath12k_vif *ahvif, struct ath12k_sta *ahsta);
94 struct ath12k_ml_peer *ath12k_peer_ml_find(struct ath12k_hw *ah,
95 					   const u8 *addr);
96 static inline
ath12k_peer_get_link_sta(struct ath12k_base * ab,struct ath12k_peer * peer)97 struct ath12k_link_sta *ath12k_peer_get_link_sta(struct ath12k_base *ab,
98 						 struct ath12k_peer *peer)
99 {
100 	struct ath12k_sta *ahsta;
101 	struct ath12k_link_sta *arsta;
102 
103 	if (!peer->sta)
104 		return NULL;
105 
106 	ahsta = ath12k_sta_to_ahsta(peer->sta);
107 	if (peer->ml_id & ATH12K_PEER_ML_ID_VALID) {
108 		if (!(ahsta->links_map & BIT(peer->link_id))) {
109 			ath12k_warn(ab, "peer %pM id %d link_id %d can't found in STA link_map 0x%x\n",
110 				    peer->addr, peer->peer_id, peer->link_id,
111 				    ahsta->links_map);
112 			return NULL;
113 		}
114 		arsta = rcu_dereference(ahsta->link[peer->link_id]);
115 		if (!arsta)
116 			return NULL;
117 	} else {
118 		arsta =  &ahsta->deflink;
119 	}
120 	return arsta;
121 }
122 
123 #endif /* _PEER_H_ */
124