xref: /linux/drivers/net/wireless/ath/ath12k/mac.h (revision 5374c334d64f8e1dfc4aadcbcd3a1090fbe39acb)
1 /* SPDX-License-Identifier: BSD-3-Clause-Clear */
2 /*
3  * Copyright (c) 2018-2021 The Linux Foundation. All rights reserved.
4  * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
5  */
6 
7 #ifndef ATH12K_MAC_H
8 #define ATH12K_MAC_H
9 
10 #include <net/mac80211.h>
11 #include <net/cfg80211.h>
12 #include "wmi.h"
13 
14 struct ath12k;
15 struct ath12k_base;
16 struct ath12k_hw;
17 struct ath12k_hw_group;
18 struct ath12k_pdev_map;
19 
20 struct ath12k_generic_iter {
21 	struct ath12k *ar;
22 	int ret;
23 };
24 
25 /* number of failed packets (20 packets with 16 sw reties each) */
26 #define ATH12K_KICKOUT_THRESHOLD		(20 * 16)
27 
28 /* Use insanely high numbers to make sure that the firmware implementation
29  * won't start, we have the same functionality already in hostapd. Unit
30  * is seconds.
31  */
32 #define ATH12K_KEEPALIVE_MIN_IDLE		3747
33 #define ATH12K_KEEPALIVE_MAX_IDLE		3895
34 #define ATH12K_KEEPALIVE_MAX_UNRESPONSIVE	3900
35 
36 #define ATH12K_PDEV_TX_POWER_INVALID		((u32)-1)
37 #define ATH12K_PDEV_TX_POWER_REFRESH_TIME_MSECS	5000 /* msecs */
38 
39 /* FIXME: should these be in ieee80211.h? */
40 #define IEEE80211_VHT_MCS_SUPPORT_0_11_MASK	GENMASK(23, 16)
41 #define IEEE80211_DISABLE_VHT_MCS_SUPPORT_0_11	BIT(24)
42 
43 #define ATH12K_CHAN_WIDTH_NUM			14
44 #define ATH12K_BW_NSS_MAP_ENABLE		BIT(31)
45 #define ATH12K_PEER_RX_NSS_160MHZ		GENMASK(2, 0)
46 
47 #define ATH12K_TX_POWER_MAX_VAL	70
48 #define ATH12K_TX_POWER_MIN_VAL	0
49 
50 #define ATH12K_DEFAULT_LINK_ID	0
51 #define ATH12K_INVALID_LINK_ID	255
52 
53 /* Default link after the IEEE802.11 defined Max link id limit
54  * for driver usage purpose.
55  */
56 #define ATH12K_FIRST_SCAN_LINK	IEEE80211_MLD_MAX_NUM_LINKS
57 #define ATH12K_SCAN_LINKS_MASK	GENMASK(ATH12K_NUM_MAX_LINKS, IEEE80211_MLD_MAX_NUM_LINKS)
58 
59 #define ATH12K_NUM_MAX_ACTIVE_LINKS_PER_DEVICE	2
60 
61 #define HECAP_PHY_SUBFMR_GET(hecap_phy) \
62 	u8_get_bits(hecap_phy[3], IEEE80211_HE_PHY_CAP3_SU_BEAMFORMER)
63 
64 #define HECAP_PHY_SUBFME_GET(hecap_phy) \
65 	u8_get_bits(hecap_phy[4], IEEE80211_HE_PHY_CAP4_SU_BEAMFORMEE)
66 
67 #define HECAP_PHY_MUBFMR_GET(hecap_phy) \
68 	u8_get_bits(hecap_phy[4], IEEE80211_HE_PHY_CAP4_MU_BEAMFORMER)
69 
70 #define HECAP_PHY_ULMUMIMO_GET(hecap_phy) \
71 	u8_get_bits(hecap_phy[2], IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO)
72 
73 #define HECAP_PHY_ULOFDMA_GET(hecap_phy) \
74 	u8_get_bits(hecap_phy[2], IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO)
75 
76 enum ath12k_supported_bw {
77 	ATH12K_BW_20    = 0,
78 	ATH12K_BW_40    = 1,
79 	ATH12K_BW_80    = 2,
80 	ATH12K_BW_160   = 3,
81 	ATH12K_BW_320   = 4,
82 };
83 
84 enum ath12k_gi {
85 	ATH12K_RATE_INFO_GI_0_8,
86 	ATH12K_RATE_INFO_GI_1_6,
87 	ATH12K_RATE_INFO_GI_3_2,
88 };
89 
90 enum ath12k_ltf {
91 	ATH12K_RATE_INFO_1XLTF,
92 	ATH12K_RATE_INFO_2XLTF,
93 	ATH12K_RATE_INFO_4XLTF,
94 };
95 
96 struct ath12k_mac_get_any_chanctx_conf_arg {
97 	struct ath12k *ar;
98 	struct ieee80211_chanctx_conf *chanctx_conf;
99 };
100 
101 /**
102  * struct ath12k_chan_power_info - TPE containing power info per channel chunk
103  * @chan_cfreq: channel center freq (MHz)
104  * e.g.
105  * channel 37/20 MHz,  it is 6135
106  * channel 37/40 MHz,  it is 6125
107  * channel 37/80 MHz,  it is 6145
108  * channel 37/160 MHz, it is 6185
109  * @tx_power: transmit power (dBm)
110  */
111 struct ath12k_chan_power_info {
112 	u16 chan_cfreq;
113 	s8 tx_power;
114 };
115 
116 /* ath12k only deals with 320 MHz, so 16 subchannels */
117 #define ATH12K_NUM_PWR_LEVELS  16
118 
119 /**
120  * struct ath12k_reg_tpc_power_info - regulatory TPC power info
121  * @is_psd_power: is PSD power or not
122  * @eirp_power: Maximum EIRP power (dBm), valid only if power is PSD
123  * @ap_power_type: type of power (SP/LPI/VLP)
124  * @num_pwr_levels: number of power levels
125  * @reg_max: Array of maximum TX power (dBm) per PSD value
126  * @ap_constraint_power: AP constraint power (dBm)
127  * @tpe: TPE values processed from TPE IE
128  * @chan_power_info: power info to send to firmware
129  */
130 struct ath12k_reg_tpc_power_info {
131 	bool is_psd_power;
132 	u8 eirp_power;
133 	enum wmi_reg_6g_ap_type ap_power_type;
134 	u8 num_pwr_levels;
135 	u8 reg_max[ATH12K_NUM_PWR_LEVELS];
136 	u8 ap_constraint_power;
137 	s8 tpe[ATH12K_NUM_PWR_LEVELS];
138 	struct ath12k_chan_power_info chan_power_info[ATH12K_NUM_PWR_LEVELS];
139 };
140 
141 #define ATH12K_OBSS_PD_MAX_THRESHOLD		-82
142 #define ATH12K_OBSS_PD_NON_SRG_MAX_THRESHOLD	-62
143 
144 extern const struct htt_rx_ring_tlv_filter ath12k_mac_mon_status_filter_default;
145 
146 #define ATH12K_SCAN_11D_INTERVAL		600000
147 #define ATH12K_11D_INVALID_VDEV_ID		0xFFFF
148 
149 void ath12k_mac_11d_scan_start(struct ath12k *ar, u32 vdev_id);
150 void ath12k_mac_11d_scan_stop(struct ath12k *ar);
151 void ath12k_mac_11d_scan_stop_all(struct ath12k_base *ab);
152 
153 void ath12k_mac_destroy(struct ath12k_hw_group *ag);
154 void ath12k_mac_unregister(struct ath12k_hw_group *ag);
155 int ath12k_mac_register(struct ath12k_hw_group *ag);
156 int ath12k_mac_allocate(struct ath12k_hw_group *ag);
157 int ath12k_mac_hw_ratecode_to_legacy_rate(u8 hw_rc, u8 preamble, u8 *rateidx,
158 					  u16 *rate);
159 u8 ath12k_mac_bitrate_to_idx(const struct ieee80211_supported_band *sband,
160 			     u32 bitrate);
161 u8 ath12k_mac_hw_rate_to_idx(const struct ieee80211_supported_band *sband,
162 			     u8 hw_rate, bool cck);
163 
164 void __ath12k_mac_scan_finish(struct ath12k *ar);
165 void ath12k_mac_scan_finish(struct ath12k *ar);
166 
167 struct ath12k_link_vif *ath12k_mac_get_arvif(struct ath12k *ar, u32 vdev_id);
168 struct ath12k_link_vif *ath12k_mac_get_arvif_by_vdev_id(struct ath12k_base *ab,
169 							u32 vdev_id);
170 struct ath12k *ath12k_mac_get_ar_by_vdev_id(struct ath12k_base *ab, u32 vdev_id);
171 struct ath12k *ath12k_mac_get_ar_by_pdev_id(struct ath12k_base *ab, u32 pdev_id);
172 
173 void ath12k_mac_drain_tx(struct ath12k *ar);
174 void ath12k_mac_peer_cleanup_all(struct ath12k *ar);
175 void ath12k_mac_dp_peer_cleanup(struct ath12k_hw *ah);
176 int ath12k_mac_tx_mgmt_pending_free(int buf_id, void *skb, void *ctx);
177 enum rate_info_bw ath12k_mac_bw_to_mac80211_bw(enum ath12k_supported_bw bw);
178 enum ath12k_supported_bw ath12k_mac_mac80211_bw_to_ath12k_bw(enum rate_info_bw bw);
179 enum hal_encrypt_type ath12k_dp_tx_get_encrypt_type(u32 cipher);
180 int ath12k_mac_rfkill_enable_radio(struct ath12k *ar, bool enable);
181 int ath12k_mac_rfkill_config(struct ath12k *ar);
182 int ath12k_mac_wait_tx_complete(struct ath12k *ar);
183 void ath12k_mac_handle_beacon(struct ath12k *ar, struct sk_buff *skb);
184 void ath12k_mac_handle_beacon_miss(struct ath12k *ar,
185 				   struct ath12k_link_vif *arvif);
186 int ath12k_mac_vif_set_keepalive(struct ath12k_link_vif *arvif,
187 				 enum wmi_sta_keepalive_method method,
188 				 u32 interval);
189 u8 ath12k_mac_get_target_pdev_id(struct ath12k *ar);
190 int ath12k_mac_mlo_setup(struct ath12k_hw_group *ag);
191 int ath12k_mac_mlo_ready(struct ath12k_hw_group *ag);
192 void ath12k_mac_mlo_teardown(struct ath12k_hw_group *ag);
193 int ath12k_mac_vdev_stop(struct ath12k_link_vif *arvif);
194 void ath12k_mac_get_any_chanctx_conf_iter(struct ieee80211_hw *hw,
195 					  struct ieee80211_chanctx_conf *conf,
196 					  void *data);
197 u16 ath12k_mac_he_convert_tones_to_ru_tones(u16 tones);
198 enum nl80211_eht_ru_alloc ath12k_mac_eht_ru_tones_to_nl80211_eht_ru_alloc(u16 ru_tones);
199 enum nl80211_eht_gi ath12k_mac_eht_gi_to_nl80211_eht_gi(u8 sgi);
200 struct ieee80211_bss_conf *ath12k_mac_get_link_bss_conf(struct ath12k_link_vif *arvif);
201 struct ath12k *ath12k_get_ar_by_vif(struct ieee80211_hw *hw,
202 				    struct ieee80211_vif *vif,
203 				    u8 link_id);
204 int ath12k_mac_get_fw_stats(struct ath12k *ar, struct ath12k_fw_stats_req_params *param);
205 void ath12k_mac_update_freq_range(struct ath12k *ar,
206 				  u32 freq_low, u32 freq_high);
207 void ath12k_mac_fill_reg_tpc_info(struct ath12k *ar,
208 				  struct ath12k_link_vif *arvif,
209 				  struct ieee80211_chanctx_conf *ctx);
210 int ath12k_mac_op_start(struct ieee80211_hw *hw);
211 void ath12k_mac_op_stop(struct ieee80211_hw *hw, bool suspend);
212 void
213 ath12k_mac_op_reconfig_complete(struct ieee80211_hw *hw,
214 				enum ieee80211_reconfig_type reconfig_type);
215 int ath12k_mac_op_add_interface(struct ieee80211_hw *hw,
216 				struct ieee80211_vif *vif);
217 void ath12k_mac_op_remove_interface(struct ieee80211_hw *hw,
218 				    struct ieee80211_vif *vif);
219 void ath12k_mac_op_update_vif_offload(struct ieee80211_hw *hw,
220 				      struct ieee80211_vif *vif);
221 int ath12k_mac_op_config(struct ieee80211_hw *hw, int radio_idx, u32 changed);
222 void ath12k_mac_op_link_info_changed(struct ieee80211_hw *hw,
223 				     struct ieee80211_vif *vif,
224 				     struct ieee80211_bss_conf *info,
225 				     u64 changed);
226 void ath12k_mac_op_vif_cfg_changed(struct ieee80211_hw *hw,
227 				   struct ieee80211_vif *vif,
228 				   u64 changed);
229 int
230 ath12k_mac_op_change_vif_links
231 			(struct ieee80211_hw *hw,
232 			 struct ieee80211_vif *vif,
233 			 u16 old_links, u16 new_links,
234 			 struct ieee80211_bss_conf *ol[IEEE80211_MLD_MAX_NUM_LINKS]);
235 void ath12k_mac_op_configure_filter(struct ieee80211_hw *hw,
236 				    unsigned int changed_flags,
237 				    unsigned int *total_flags,
238 				    u64 multicast);
239 int ath12k_mac_op_hw_scan(struct ieee80211_hw *hw,
240 			  struct ieee80211_vif *vif,
241 			  struct ieee80211_scan_request *hw_req);
242 void ath12k_mac_op_cancel_hw_scan(struct ieee80211_hw *hw,
243 				  struct ieee80211_vif *vif);
244 int ath12k_mac_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
245 			  struct ieee80211_vif *vif, struct ieee80211_sta *sta,
246 			  struct ieee80211_key_conf *key);
247 void ath12k_mac_op_set_rekey_data(struct ieee80211_hw *hw,
248 				  struct ieee80211_vif *vif,
249 				  struct cfg80211_gtk_rekey_data *data);
250 int ath12k_mac_op_sta_state(struct ieee80211_hw *hw,
251 			    struct ieee80211_vif *vif,
252 			    struct ieee80211_sta *sta,
253 			    enum ieee80211_sta_state old_state,
254 			    enum ieee80211_sta_state new_state);
255 int ath12k_mac_op_sta_set_txpwr(struct ieee80211_hw *hw,
256 				struct ieee80211_vif *vif,
257 				struct ieee80211_sta *sta);
258 void ath12k_mac_op_link_sta_rc_update(struct ieee80211_hw *hw,
259 				      struct ieee80211_vif *vif,
260 				      struct ieee80211_link_sta *link_sta,
261 				      u32 changed);
262 int ath12k_mac_op_conf_tx(struct ieee80211_hw *hw,
263 			  struct ieee80211_vif *vif,
264 			  unsigned int link_id, u16 ac,
265 			  const struct ieee80211_tx_queue_params *params);
266 int ath12k_mac_op_set_antenna(struct ieee80211_hw *hw, int radio_idx,
267 			      u32 tx_ant, u32 rx_ant);
268 int ath12k_mac_op_get_antenna(struct ieee80211_hw *hw, int radio_idx,
269 			      u32 *tx_ant, u32 *rx_ant);
270 int ath12k_mac_op_ampdu_action(struct ieee80211_hw *hw,
271 			       struct ieee80211_vif *vif,
272 			       struct ieee80211_ampdu_params *params);
273 int ath12k_mac_op_add_chanctx(struct ieee80211_hw *hw,
274 			      struct ieee80211_chanctx_conf *ctx);
275 void ath12k_mac_op_remove_chanctx(struct ieee80211_hw *hw,
276 				  struct ieee80211_chanctx_conf *ctx);
277 void ath12k_mac_op_change_chanctx(struct ieee80211_hw *hw,
278 				  struct ieee80211_chanctx_conf *ctx,
279 				  u32 changed);
280 int
281 ath12k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
282 				 struct ieee80211_vif *vif,
283 				 struct ieee80211_bss_conf *link_conf,
284 				 struct ieee80211_chanctx_conf *ctx);
285 void
286 ath12k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
287 				   struct ieee80211_vif *vif,
288 				   struct ieee80211_bss_conf *link_conf,
289 				   struct ieee80211_chanctx_conf *ctx);
290 int
291 ath12k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw,
292 				 struct ieee80211_vif_chanctx_switch *vifs,
293 				 int n_vifs,
294 				 enum ieee80211_chanctx_switch_mode mode);
295 int ath12k_mac_op_set_rts_threshold(struct ieee80211_hw *hw,
296 				    int radio_idx, u32 value);
297 int ath12k_mac_op_set_frag_threshold(struct ieee80211_hw *hw,
298 				     int radio_idx, u32 value);
299 int
300 ath12k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw,
301 			       struct ieee80211_vif *vif,
302 			       const struct cfg80211_bitrate_mask *mask);
303 int ath12k_mac_op_get_survey(struct ieee80211_hw *hw, int idx,
304 			     struct survey_info *survey);
305 void ath12k_mac_op_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
306 			 u32 queues, bool drop);
307 void ath12k_mac_op_sta_statistics(struct ieee80211_hw *hw,
308 				  struct ieee80211_vif *vif,
309 				  struct ieee80211_sta *sta,
310 				  struct station_info *sinfo);
311 void ath12k_mac_op_link_sta_statistics(struct ieee80211_hw *hw,
312 				       struct ieee80211_vif *vif,
313 				       struct ieee80211_link_sta *link_sta,
314 				       struct link_station_info *link_sinfo);
315 int ath12k_mac_op_remain_on_channel(struct ieee80211_hw *hw,
316 				    struct ieee80211_vif *vif,
317 				    struct ieee80211_channel *chan,
318 				    int duration,
319 				    enum ieee80211_roc_type type);
320 int ath12k_mac_op_cancel_remain_on_channel(struct ieee80211_hw *hw,
321 					   struct ieee80211_vif *vif);
322 int ath12k_mac_op_change_sta_links(struct ieee80211_hw *hw,
323 				   struct ieee80211_vif *vif,
324 				   struct ieee80211_sta *sta,
325 				   u16 old_links, u16 new_links);
326 bool ath12k_mac_op_can_activate_links(struct ieee80211_hw *hw,
327 				      struct ieee80211_vif *vif,
328 				      u16 active_links);
329 int ath12k_mac_op_get_txpower(struct ieee80211_hw *hw,
330 			      struct ieee80211_vif *vif,
331 			      unsigned int link_id,
332 			      int *dbm);
333 int ath12k_mac_mgmt_tx(struct ath12k *ar, struct sk_buff *skb,
334 		       bool is_prb_rsp);
335 void ath12k_mac_add_p2p_noa_ie(struct ath12k *ar,
336 			       struct ieee80211_vif *vif,
337 			       struct sk_buff *skb,
338 			       bool is_prb_rsp);
339 u8 ath12k_mac_get_tx_link(struct ieee80211_sta *sta, struct ieee80211_vif *vif,
340 			  u8 link, struct sk_buff *skb, u32 info_flags);
341 
342 void ath12k_mlo_mcast_update_tx_link_address(struct ieee80211_vif *vif,
343 					     u8 link_id, struct sk_buff *skb,
344 					     u32 info_flags);
345 #endif
346