xref: /wlan-dirver/qca-wifi-host-cmn/target_if/cfr/inc/target_if_cfr_enh.h (revision 45a38684b07295822dc8eba39e293408f203eec8)
1 /*
2  * Copyright (c) 2019-2020 The Linux Foundation. All rights reserved.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for
5  * any purpose with or without fee is hereby granted, provided that the
6  * above copyright notice and this permission notice appear in all
7  * copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16  * PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #ifndef _TARGET_IF_CFR_ENH_H_
20 #define _TARGET_IF_CFR_ENH_H_
21 
22 #ifdef WLAN_ENH_CFR_ENABLE
23 /*
24  * Memory requirements :
25  *
26  *  1. DMA header :
27  *
28  * Legacy DMA header(QCA8074V2) : 2 words (length = 8 bytes)
29  * Enhanced DMA header(QCA6018) : Upto 16 words depending on no. of MU users
30  *                       in UL-MU-PPDU (Max length = 64 bytes)
31  *
32  * Fixed 4 words for whal_cfir_enhanced_hdr + freeze TLV
33  *                                          + uplink_user_info TLV (MAX 4)
34  *
35  * mu_rx_num_users -> No. of words in CFR DMA header
36  * 0 -> 12  =  4 + 7(freeze TLV) + 1(for 64-bit alignment)
37  * 1 -> 12  =  4 + 7(freeze TLV) + 1(user1)
38  * 2 -> 14  =  4 + 7(freeze TLV) + 2(users 1,2) + 1(for 64-bit alignment)
39  * 3 -> 14  =  4 + 7(freeze TLV) + 3(users 1,2,3)
40  * 4 -> 16  =  4 + 7(freeze TLV) + 4(users 1,2,3,4) + 1(for 64-bit alignment)
41  *
42  *
43  * 2. CFR data size for max BW/Nss/Nrx
44  *
45  *	Cypress : Max BW = 80 MHz
46  *			 NSS = 2
47  *			 Nrx = 2
48  *			 Size of one tone = 4 bytes
49  *
50  *		a. RTT-H - 2048 bytes
51  *
52  *		b. Debug-H (MIMO CFR) - 16016 bytes
53  *
54  *		c. RTT-H + CIR - 10240 bytes = 2048(RTT-H) + 8192(CIR)
55  */
56 
57 /* Max 4 users in MU case */
58 #define CYP_CFR_MU_USERS 4
59 
60 #define CYP_MAX_HEADER_LENGTH_WORDS 16
61 
62 /* payload_len = Max(2048, 16016, 10240) = 16064 (64-bit alignment) */
63 #define CYP_MAX_DATA_LENGTH_BYTES 16064
64 
65 /* in ms */
66 #define LUT_AGE_TIMER 3000
67 #define LUT_AGE_THRESHOLD 3000
68 
69 /* Max size :
70  * sizeof(csi_cfr_header) + 64 bytes(cfr header) + 16064 bytes(cfr payload)
71  */
72 #define STREAMFS_MAX_SUBBUF_CYP \
73 	(sizeof(struct csi_cfr_header) + \
74 	 (CYP_MAX_HEADER_LENGTH_WORDS * 4) + \
75 	 CYP_MAX_DATA_LENGTH_BYTES)
76 
77 #define STREAMFS_NUM_SUBBUF_CYP 255
78 
79 /* Max 37 users in MU case for Pine */
80 #define PINE_CFR_MU_USERS 37
81 
82 #define PINE_MAX_HEADER_LENGTH_WORDS 50
83 
84 #define PINE_MAX_DATA_LENGTH_BYTES 16384
85 
86 /* Max size :
87  * sizeof(csi_cfr_header) + 200 bytes(cfr header) + 16384 bytes(cfr payload)
88  */
89 #define STREAMFS_MAX_SUBBUF_PINE \
90 	(sizeof(struct csi_cfr_header) + \
91 	 (PINE_MAX_HEADER_LENGTH_WORDS * 4) + \
92 	 PINE_MAX_DATA_LENGTH_BYTES)
93 
94 #define STREAMFS_NUM_SUBBUF_PINE 255
95 
96 /* enum macrx_freeze_tlv_version: Reported by uCode in enh_dma_header
97  * MACRX_FREEZE_TLV_VERSION_1: Single MU UL user info reported by MAC
98  * MACRX_FREEZE_TLV_VERSION_2: Upto 4 MU UL user info reported by MAC
99  * MACRX_FREEZE_TLV_VERSION_3: Upto 37 MU UL user info reported by MAC
100  */
101 enum macrx_freeze_tlv_version {
102 	MACRX_FREEZE_TLV_VERSION_1 = 1,
103 	MACRX_FREEZE_TLV_VERSION_2 = 2,
104 	MACRX_FREEZE_TLV_VERSION_3 = 3,
105 	MACRX_FREEZE_TLV_VERSION_MAX
106 };
107 
108 /*
109  * @tag: ucode fills this with 0xBA
110  *
111  * @length: length of CFR header in words (32-bit)
112  *
113  * @upload_done: ucode sets this to 1 to indicate DMA completion
114  *
115  * @capture_type:
116  *
117  *			0 - None
118  *			1 - RTT-H (Nss = 1, Nrx)
119  *			2 - Debug-H (Nss, Nrx)
120  *			3 - Reserved
121  *			5 - RTT-H + CIR(Nss, Nrx)
122  *
123  * @preamble_type:
124  *
125  *			0 - Legacy
126  *			1 - HT
127  *			2 - VHT
128  *			3 - HE
129  *
130  * @nss:
131  *
132  *			0 - 1-stream
133  *			1 - 2-stream
134  *			..	..
135  *			7 - 8-stream
136  *
137  *@num_chains:
138  *
139  *			0 - 1-chain
140  *			1 - 2-chain
141  *			..  ..
142  *			7 - 8-chain
143  *
144  *@upload_bw_pkt:
145  *
146  *			0 - 20 MHz
147  *			1 - 40 MHz
148  *			2 - 80 MHz
149  *			3 - 160 MHz
150  *
151  * @sw_peer_id_valid: Indicates whether sw_peer_id field is valid or not,
152  * sent from MAC to PHY via the MACRX_FREEZE_CAPTURE_CHANNEL TLV
153  *
154  * @sw_peer_id: Indicates peer id based on AST search, sent from MAC to PHY
155  * via the MACRX_FREEZE_CAPTURE_CHANNEL TLV
156  *
157  * @phy_ppdu_id: sent from PHY to MAC, copied to MACRX_FREEZE_CAPTURE_CHANNEL
158  * TLV
159  *
160  * @total_bytes: Total size of CFR payload (FFT bins)
161  *
162  * @header_version:
163  *
164  *			1 - HKV2/Hastings
165  *			2 - Cypress
166  *
167  * @target_id:
168  *
169  *			1 - Hastings
170  *			2 - Cypress
171  *			3 - Hastings Prime
172  *			4 - Pine
173  *
174  * @cfr_fmt:
175  *
176  *			0 - raw (32-bit format)
177  *			1 - compressed (24-bit format)
178  *
179  * @mu_rx_data_incl: Indicates whether CFR header contains UL-MU-MIMO info
180  *
181  * @freeze_data_incl: Indicates whether CFR header contains
182  * MACRX_FREEZE_CAPTURE_CHANNEL TLV
183  *
184  * @freeze_tlv_version: Indicates the version of freeze_tlv
185  *			1 - HSP, Cypress
186  *			2 - Maple/Spruce/Moselle
187  *			3 - Pine
188  *
189  * @decimation_factor: FFT bins decimation
190  * @mu_rx_num_users: Number of users in UL-MU-PPDU
191  */
192 struct whal_cfir_enhanced_hdr {
193 	uint16_t tag              :  8,
194 		 length           :  6,
195 		 rsvd1            :  2;
196 
197 	uint16_t upload_done        :  1,
198 		 capture_type       :  3,
199 		 preamble_type      :  2,
200 		 nss                :  3,
201 		 num_chains         :  3,
202 		 upload_pkt_bw      :  3,
203 		 sw_peer_id_valid   :  1;
204 
205 	uint16_t sw_peer_id         : 16;
206 
207 	uint16_t phy_ppdu_id        : 16;
208 
209 	uint16_t total_bytes;
210 
211 	uint16_t header_version     :4,
212 		 target_id          :4,
213 		 cfr_fmt            :1,
214 		 rsvd2              :1,
215 		 mu_rx_data_incl    :1,
216 		 freeze_data_incl   :1,
217 		 freeze_tlv_version :4;
218 
219 	uint16_t mu_rx_num_users   :8,
220 		 decimation_factor :4,
221 		 rsvd3             :4;
222 
223 	uint16_t rsvd4;
224 };
225 
226 /*
227  * freeze_tlv v1/v2 used by Hastings/Cypress/Maple/Spruce/Moselle supports upto
228  * 4 UL MU users
229  *
230  * @freeze:
231  *		0: Allow channel capture
232  *		1: Freeze channel capture
233  *
234  * @capture_reason: Field only valid when the freeze field is 1. Indicates why
235  * the MAC asked to capture the channel
236  *		0: freeze_reason_TM
237  *		1: freeze_reason_FTM
238  *		2: freeze_reason_ACK_resp_to_TM_FTM
239  *		3: freeze_reason_TA_RA_TYPE_FILTER
240  *		4: freeze readon NDP_NDP
241  *		5: freeze_reason_ALL_PACKET
242  *
243  * @packet_type: Packet type of captured packets.
244  *		0: Management
245  *		1: Control
246  *		2: Data
247  *		3: Extension
248  *
249  * @packet_sub_type: packet subtype of the captured packets.
250  * @sw_peer_id_valid: It is valid only when the freeze field is set to 1.
251  *		0: no TA address search on the received frame has been
252  *		   performed. This is due to the frame not having a TA address
253  *		   (like ACK frame), or the received frame being from an other
254  *		   AP to which this device is not associated.
255  *		1: field sw_peer_id will contain valid information.
256  *		   This implies that a (successful) address search has been
257  *		   performed on the TA address of the received frame.
258  *
259  * @sw_peer_id: Valid only when sw_peer_id_valid field is set. It is an
260  * identifier that allows SW to double check that the CSI info stored belongs
261  * to the device with this SW identifier.
262  *
263  * @phy_ppdu_id: ppdu_id of ppdu which has channel capture performed. Field
264  * only valid when the freeze field is set to 1.
265  *
266  * @packet_ta_lower_16: Packet’s lower 16bits transmit address in MAC header.
267  *
268  * @packet_ta_mid_16: Packet’s middle 16bits transmit address in MAC header.
269  *
270  * @packet_ta_upper_16: Packet’s upper 16bits transmit address in MAC header.
271  *
272  * @packet_ra_lower_16: Packet’s lower 16bits receive address in MAC header.
273  *
274  * @packet_ra_mid_16: Packet’s middle 16bits receive address in MAC header.
275  *
276  * @packet_ra_upper_16: Packet’s upper 16bits receive address in MAC header.
277  *
278  * @tsf_timestamp_15_0: MAC side 64bit TSF timestamp when this TLV is sent to
279  * PHY. Bits [15:0].
280  *
281  * @tsf_timestamp_31_16: MAC side 64bit TSF timestamp when this TLV is sent to
282  * PHY. Bits [31:16].
283  *
284  * @tsf_timestamp_47_32: MAC side 64bit TSF timestamp when this TLV is sent to
285  * PHY. Bits [47:32].
286  *
287  * @tsf_timestamp_63_48: MAC side 64bit TSF timestamp when this TLV is sent to
288  * PHY. Bits [63:48].
289  *
290  * @user_index_or_user_mask_5_0: When freeze_tlv_version is 1, this field from
291  * MAC, indicate to PHY which user's channel information need to be uploaded.
292  * When freeze_tlv_version is 2 & MU_SUPPORT_IN_TLV is 1, this field indicates
293  * bitmap of users upto 4 to which channel capture need to be uploaded. And if
294  * freeze_tlv_version is 2 & MU_SUPPORT_IN_TLV is 0, this field indicate to PHY
295  * which user's channel information need to be uploaded
296  *
297  * @directed: Indicate the frame is directed to us or not when NDPA/NDP capture
298  * or FTM/TM/ACK capture. 1=directed. For other modes, it is 0.
299  */
300 struct macrx_freeze_capture_channel {
301 	uint16_t freeze                          :  1, //[0]
302 		 capture_reason                  :  3, //[3:1]
303 		 packet_type                     :  2, //[5:4]
304 		 packet_sub_type                 :  4, //[9:6]
305 		 reserved                        :  5, //[14:10]
306 		 sw_peer_id_valid                :  1; //[15]
307 	uint16_t sw_peer_id                      : 16; //[15:0]
308 	uint16_t phy_ppdu_id                     : 16; //[15:0]
309 	uint16_t packet_ta_lower_16              : 16; //[15:0]
310 	uint16_t packet_ta_mid_16                : 16; //[15:0]
311 	uint16_t packet_ta_upper_16              : 16; //[15:0]
312 	uint16_t packet_ra_lower_16              : 16; //[15:0]
313 	uint16_t packet_ra_mid_16                : 16; //[15:0]
314 	uint16_t packet_ra_upper_16              : 16; //[15:0]
315 	uint16_t tsf_timestamp_15_0              : 16; //[15:0]
316 	uint16_t tsf_timestamp_31_16             : 16; //[15:0]
317 	uint16_t tsf_timestamp_47_32             : 16; //[15:0]
318 	uint16_t tsf_timestamp_63_48             : 16; //[15:0]
319 	uint16_t user_index_or_user_mask_5_0     :  6, //[5:0]
320 		 directed                        :  1, //[6]
321 		 reserved_13                     :  9; //[15:7]
322 };
323 
324 /*
325  * freeze_tlv v3 used by Pine
326  *
327  * @freeze:
328  *		0: Allow channel capture
329  *		1: Freeze channel capture
330  *
331  * @capture_reason: Field only valid when the freeze field is 1. Indicates why
332  * the MAC asked to capture the channel
333  *		0: freeze_reason_TM
334  *		1: freeze_reason_FTM
335  *		2: freeze_reason_ACK_resp_to_TM_FTM
336  *		3: freeze_reason_TA_RA_TYPE_FILTER
337  *		4: freeze readon NDP_NDP
338  *		5: freeze_reason_ALL_PACKET
339  *
340  * @packet_type: Packet type of captured packets.
341  *		0: Management
342  *		1: Control
343  *		2: Data
344  *		3: Extension
345  *
346  * @packet_sub_type: packet subtype of the captured packets.
347  *
348  * @directed: Indicate the frame is directed to us or not when NDPA/NDP capture
349  * or FTM/TM/ACK capture. 1=directed. For other modes, it is 0.
350  *
351  * @sw_peer_id_valid: It is valid only when the freeze field is set to 1.
352  *		0: no TA address search on the received frame has been
353  *		   performed. This is due to the frame not having a TA address
354  *		   (like ACK frame), or the received frame being from an other
355  *		   AP to which this device is not associated.
356  *		1: field sw_peer_id will contain valid information.
357  *		   This implies that a (successful) address search has been
358  *		   performed on the TA address of the received frame.
359  *
360  * @sw_peer_id: Valid only when sw_peer_id_valid field is set. It is an
361  * identifier that allows SW to double check that the CSI info stored belongs
362  * to the device with this SW identifier.
363  *
364  * @phy_ppdu_id: ppdu_id of ppdu which has channel capture performed. Field
365  * only valid when the freeze field is set to 1.
366  *
367  * @packet_ta_lower_16: Packet’s lower 16bits transmit address in MAC header.
368  *
369  * @packet_ta_mid_16: Packet’s middle 16bits transmit address in MAC header.
370  *
371  * @packet_ta_upper_16: Packet’s upper 16bits transmit address in MAC header.
372  *
373  * @packet_ra_lower_16: Packet’s lower 16bits receive address in MAC header.
374  *
375  * @packet_ra_mid_16: Packet’s middle 16bits receive address in MAC header.
376  *
377  * @packet_ra_upper_16: Packet’s upper 16bits receive address in MAC header.
378  *
379  * @tsf_timestamp_15_0: MAC side 64bit TSF timestamp when this TLV is sent to
380  * PHY. Bits [15:0].
381  *
382  * @tsf_timestamp_31_16: MAC side 64bit TSF timestamp when this TLV is sent to
383  * PHY. Bits [31:16].
384  *
385  * @tsf_timestamp_47_32: MAC side 64bit TSF timestamp when this TLV is sent to
386  * PHY. Bits [47:32].
387  *
388  * @tsf_63_48_or_user_mask_36_32: Indicates to PHY which user's channel info
389  * need to be uploaded. Only valid in UL MU case with MU_SUPPORT_IN_TLV = 1.
390  * Otherwise this indicates to PHY MSBs 63:48 of the MAC side 64bit TSF
391  * timestamp when this TLV is sent to PHY.
392  *
393  * @user_index_or_user_mask_15_0: Indicate to PHY which user's channel info
394  * need to be uploaded in UL MU case with MU_SUPPORT_IN_TLV = 1. Otherwise it
395  * indicate PHY which user’s channel information need to be uploaded.
396  *
397  * @user_mask_31_16: Indicate to PHY which user’s channel information need to
398  * be uploaded. Only valid in UL MU case with MU_SUPPORT_IN_TLV = 1.
399  */
400 struct macrx_freeze_capture_channel_v3 {
401 	uint16_t freeze                          :  1, //[0]
402 		 capture_reason                  :  3, //[3:1]
403 		 packet_type                     :  2, //[5:4]
404 		 packet_sub_type                 :  4, //[9:6]
405 		 directed                        :  1, //[10]
406 		 reserved                        :  4, //[14:11]
407 		 sw_peer_id_valid                :  1; //[15]
408 	uint16_t sw_peer_id                      : 16; //[15:0]
409 	uint16_t phy_ppdu_id                     : 16; //[15:0]
410 	uint16_t packet_ta_lower_16              : 16; //[15:0]
411 	uint16_t packet_ta_mid_16                : 16; //[15:0]
412 	uint16_t packet_ta_upper_16              : 16; //[15:0]
413 	uint16_t packet_ra_lower_16              : 16; //[15:0]
414 	uint16_t packet_ra_mid_16                : 16; //[15:0]
415 	uint16_t packet_ra_upper_16              : 16; //[15:0]
416 	uint16_t tsf_timestamp_15_0              : 16; //[15:0]
417 	uint16_t tsf_timestamp_31_16             : 16; //[15:0]
418 	uint16_t tsf_timestamp_47_32             : 16; //[15:0]
419 	uint16_t tsf_63_48_or_user_mask_36_32    : 16; //[15:0]
420 	uint16_t user_index_or_user_mask_15_0    : 16; //[15:0]
421 	uint16_t user_mask_31_16                 : 16; //[15:0]
422 };
423 
424 struct uplink_user_setup_info {
425 	uint32_t bw_info_valid                   :  1, //[0]
426 		 uplink_receive_type             :  2, //[2:1]
427 		 reserved_0a                     :  1, //[3]
428 		 uplink_11ax_mcs                 :  4, //[7:4]
429 		 ru_width                        :  7, //[14:8]
430 		 reserved_0b                     :  1, //[15]
431 		 nss                             :  3, //[18:16]
432 		 stream_offset                   :  3, //[21:19]
433 		 sta_dcm                         :  1, //[22]
434 		 sta_coding                      :  1, //[23]
435 		 ru_start_index                  :  7, //[30:24]
436 		 reserved_0c                     :  1; //[31]
437 };
438 
439 /**
440  * cfr_enh_init_pdev() - Inits cfr pdev and registers necessary handlers.
441  * @psoc: pointer to psoc object
442  * @pdev: pointer to pdev object
443  *
444  * Return: Registration status for necessary handlers
445  */
446 QDF_STATUS cfr_enh_init_pdev(
447 		struct wlan_objmgr_psoc *psoc,
448 		struct wlan_objmgr_pdev *pdev);
449 
450 /**
451  * cfr_enh_deinit_pdev() - De-inits corresponding pdev and handlers.
452  * @psoc: pointer to psoc object
453  * @pdev: pointer to pdev object
454  *
455  * Return: De-registration status for necessary handlers
456  */
457 QDF_STATUS cfr_enh_deinit_pdev(
458 		struct wlan_objmgr_psoc *psoc,
459 		struct wlan_objmgr_pdev *pdev);
460 
461 /**
462  * target_if_cfr_start_lut_age_timer() - Start timer to flush aged-out LUT
463  * entries
464  * @pdev: pointer to pdev object
465  *
466  * Return: None
467  */
468 void target_if_cfr_start_lut_age_timer(struct wlan_objmgr_pdev *pdev);
469 
470 /**
471  * target_if_cfr_stop_lut_age_timer() - Stop timer to flush aged-out LUT
472  * entries
473  * @pdev: pointer to pdev object
474  *
475  * Return: None
476  */
477 void target_if_cfr_stop_lut_age_timer(struct wlan_objmgr_pdev *pdev);
478 
479 /**
480  * target_if_cfr_dump_lut_enh() - Dump all valid LUT entries
481  * @pdev: objmgr PDEV
482  *
483  * Return: none
484  */
485 void target_if_cfr_dump_lut_enh(struct wlan_objmgr_pdev *pdev);
486 
487 /**
488  * target_if_cfr_config_rcc() - Start repetitive channel capture
489  * @pdev: pointer to pdev object
490  * @rcc_param: rcc configurations
491  *
492  * Return: Success/Failure status
493  */
494 QDF_STATUS target_if_cfr_config_rcc(struct wlan_objmgr_pdev *pdev,
495 				    struct cfr_rcc_param *rcc_param);
496 
497 /**
498  *  target_if_cfr_default_ta_ra_config() - Configure default values to all
499  *  params(BW/NSS/TA/RA) in TA_RA mode
500  * @rcc_param: rcc configurations
501  * @allvalid: Indicates whether all TA_RA params are valid or not.
502  *            It could be either 0 or 1.
503  *            1: should be sent to FW during CFR initialization
504  *            0: should be set, after a successful commit session.
505  * @reset_cfg: This bitmap is being used to determine which groups'
506  *            parameters are needed to be reset to its default state.
507  */
508 void target_if_cfr_default_ta_ra_config(struct cfr_rcc_param *rcc_param,
509 					bool allvalid, uint16_t reset_cfg);
510 
511 /**
512  * target_if_cfr_rx_tlv_process() - Process PPDU status TLVs and store info in
513  * lookup table
514  * @pdev: PDEV object
515  * @nbuf: ppdu info
516  *
517  * Return: none
518  */
519 void target_if_cfr_rx_tlv_process(struct wlan_objmgr_pdev *pdev, void *nbuf);
520 
521 /**
522  * target_if_cfr_update_global_cfg() - Update global config after a successful
523  * commit
524  * @pdev: pointer to pdev object
525  *
526  * Return: None
527  */
528 void target_if_cfr_update_global_cfg(struct wlan_objmgr_pdev *pdev);
529 #else
530 static inline QDF_STATUS cfr_enh_init_pdev(
531 		struct wlan_objmgr_psoc *psoc,
532 		struct wlan_objmgr_pdev *pdev)
533 {
534 	return QDF_STATUS_SUCCESS;
535 }
536 
537 static inline QDF_STATUS cfr_enh_deinit_pdev(
538 		struct wlan_objmgr_psoc *psoc,
539 		struct wlan_objmgr_pdev *pdev)
540 {
541 	return QDF_STATUS_SUCCESS;
542 }
543 #endif
544 #endif
545