1 /*
2  * Copyright (c) 2019-2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2021-2023 Qualcomm Innovation Center, Inc. All rights reserved.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for
6  * any purpose with or without fee is hereby granted, provided that the
7  * above copyright notice and this permission notice appear in all
8  * copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef _WLAN_CFR_UTILS_API_H_
21 #define _WLAN_CFR_UTILS_API_H_
22 
23 #include <wlan_objmgr_cmn.h>
24 #include <qdf_streamfs.h>
25 #ifdef WLAN_ENH_CFR_ENABLE
26 #include <qdf_timer.h>
27 #endif
28 
29 #define cfr_alert(format, args...) \
30 		QDF_TRACE_FATAL(QDF_MODULE_ID_CFR, format, ## args)
31 
32 #define cfr_err(format, args...) \
33 		QDF_TRACE_ERROR(QDF_MODULE_ID_CFR, format, ## args)
34 
35 #define cfr_warn(format, args...) \
36 		QDF_TRACE_WARN(QDF_MODULE_ID_CFR, format, ## args)
37 
38 #define cfr_info(format, args...) \
39 		QDF_TRACE_INFO(QDF_MODULE_ID_CFR, format, ## args)
40 
41 #define cfr_debug(format, args...) \
42 		QDF_TRACE_DEBUG(QDF_MODULE_ID_CFR, format, ## args)
43 
44 #define DBR_EVENT_TIMEOUT_IN_MS_CFR 1
45 #define DBR_NUM_RESP_PER_EVENT_CFR 1
46 #define MAX_CFR_ENABLED_CLIENTS 10
47 #define CFR_CAPTURE_HOST_MEM_REQ_ID 9
48 #define CFR_HOST_MEM_READ_INDEX_DEFAULT 8
49 #define CFR_VENDOR_ID 0x8cfdf0
50 #ifdef WLAN_ENH_CFR_ENABLE
51 #define MAX_CFR_MU_USERS 4
52 #define NUM_CHAN_CAPTURE_STATUS 4
53 #define NUM_CHAN_CAPTURE_REASON 6
54 #if defined(QCA_WIFI_QCA6750) || defined(QCA_WIFI_QCA6490) || \
55 	defined(QCA_WIFI_WCN6450)
56 #define MAX_TA_RA_ENTRIES 4
57 #define MAX_RESET_CFG_ENTRY 0xF
58 #else
59 #define MAX_TA_RA_ENTRIES 16
60 #define MAX_RESET_CFG_ENTRY 0xFFFF
61 #endif
62 #define CFR_INVALID_VDEV_ID 0xff
63 #define DEFAULT_SRNGID_CFR 0
64 #endif
65 
66 #define MAX_CFR_PRD  (10 * 60 * 1000)   /* 10 minutes */
67 #define CFR_MOD_PRD  10                 /* CFR period to be multiples of 10ms */
68 
69 #define MAX_AGC_GAIN 62
70 #define INVALID_AGC_GAIN 0xFFFF
71 
72 enum cfrmetaversion {
73 	CFR_META_VERSION_NONE,
74 	CFR_META_VERSION_1, /* initial version for legacy_cfr_metadata */
75 	CFR_META_VERSION_2, /* initial version for dbr_cfr_metadata */
76 	CFR_META_VERSION_3, /* initial version for enh_cfr_metadata */
77 	CFR_META_VERSION_4, /* agc gain, cfo, rx_start_ts in dbr_cfr_metadata */
78 	CFR_META_VERSION_5, /* agc gain, cfo, rx_start_ts in enh_cfr_metadata */
79 	CFR_META_VERSION_6, /* mcs, gi_type in dbr_cfr_metadata */
80 	CFR_META_VERSION_7, /* mcs, gi_type, sig_info in enh_cfr_metadata */
81 	CFR_META_VERSION_8, /* agc gain table index in dbr_cfr_metadata */
82 	CFR_META_VERSION_9, /* agc gain table index in enh_cfr_metadata */
83 	CFR_META_VERSION_MAX = 0xFF,
84 };
85 
86 enum cfrdataversion {
87 	CFR_DATA_VERSION_NONE,
88 	CFR_DATA_VERSION_1,
89 	CFR_DATA_VERSION_MAX = 0xFF,
90 };
91 
92 enum cfrplatformtype {
93 	CFR_PLATFORM_TYPE_NONE,
94 	CFR_PLATFORM_TYPE_MIPS,
95 	CFR_PLATFORM_TYPE_ARM,
96 	CFR_PLATFFORM_TYPE_MAX = 0xFF,
97 };
98 
99 enum cfrradiotype {
100 	CFR_CAPTURE_RADIO_NONE,
101 	CFR_CAPTURE_RADIO_OSPREY,
102 	CFR_CAPTURE_RADIO_PEAKCOCK,
103 	CFR_CAPTURE_RADIO_SCORPION,
104 	CFR_CAPTURE_RADIO_HONEYBEE,
105 	CFR_CAPTURE_RADIO_DRAGONFLY,
106 	CFR_CAPTURE_RADIO_JET,
107 	CFR_CAPTURE_RADIO_PEREGRINE = 17,
108 	CFR_CAPTURE_RADIO_SWIFT,
109 	CFR_CAPTURE_RADIO_BEELINER,
110 	CFR_CAPTURE_RADIO_CASCADE,
111 	CFR_CAPTURE_RADIO_DAKOTA,
112 	CFR_CAPTURE_RADIO_BESRA,
113 	CFR_CAPTURE_RADIO_HKV2,
114 	CFR_CAPTURE_RADIO_CYP,
115 	CFR_CAPTURE_RADIO_HSP,
116 	CFR_CAPTURE_RADIO_PINE,
117 	CFR_CAPTURE_RADIO_ADRASTEA,
118 	CFR_CAPTURE_RADIO_MAPLE,
119 	CFR_CAPTURE_RADIO_MOSELLE,
120 	CFR_CAPTURE_RADIO_SPRUCE,
121 	CFR_CAPTURE_RADIO_ALDER,
122 	CFR_CAPTURE_RADIO_WAIKIKI,
123 	CFR_CAPTURE_RADIO_KIWI,
124 	CFR_CAPTURE_RADIO_MANGO,
125 	CFR_CAPTURE_RADIO_MIAMI,
126 	CFR_CAPTURE_RADIO_YORK,
127 	CFR_CAPTURE_RADIO_PEACH,
128 	CFR_CAPTURE_RADIO_PEBBLE,
129 	CFR_CAPTURE_RADIO_EVROS,
130 	CFR_CAPTURE_RADIO_MAX = 0xFF,
131 };
132 
133 enum ack_capture_mode {
134 	CFR_LEGACY_ACK     = 0,
135 	CFR_DUP_LEGACY_ACK = 1,
136 	CFR_HT_ACK         = 2,
137 	CFR_VHT_ACK        = 3,
138 	CFR_INVALID_ACK, /*Always keep this at last*/
139 };
140 
141 /* Similar to WMI_PEER_CFR_CAPTURE_METHOD used in one-shot capture */
142 enum cfr_capture_type {
143 	CFR_TYPE_METHOD_NULL_FRAME = 0,
144 	CFR_TYPE_METHOD_NULL_FRAME_WITH_PHASE = 1,
145 	CFR_TYPE_METHOD_PROBE_RESP = 2,
146 	CFR_TYPE_METHOD_TM = 3,
147 	CFR_TYPE_METHOD_FTM = 4,
148 	CFR_TYPE_METHOD_ACK_RESP_TO_TM_FTM = 5,
149 	CFR_TYPE_METHOD_TA_RA_TYPE_FILTER = 6,
150 	CFR_TYPE_METHOD_NDPA_NDP = 7,
151 	CFR_TYPE_METHOD_ALL_PACKET = 8,
152 	/* Add new capture methods before this line */
153 	CFR_TYPE_METHOD_LAST_VALID,
154 	CFR_TYPE_METHOD_AUTO = 0xff,
155 	CFR_TYPE_METHOD_MAX,
156 };
157 
158 #define HOST_MAX_CHAINS 8
159 
160 /* ensure to add new members at the end of the structure only */
161 struct dbr_cfr_metadata {
162 	u_int8_t    peer_addr[QDF_MAC_ADDR_SIZE];
163 	u_int8_t    status;
164 	u_int8_t    capture_bw;
165 	u_int8_t    channel_bw;
166 	u_int8_t    phy_mode;
167 	u_int16_t   prim20_chan;
168 	u_int16_t   center_freq1;
169 	u_int16_t   center_freq2;
170 	u_int8_t    capture_mode;
171 	u_int8_t    capture_type;
172 	u_int8_t    sts_count;
173 	u_int8_t    num_rx_chain;
174 	u_int32_t   timestamp;
175 	u_int32_t   length;
176 	u_int32_t   chain_rssi[HOST_MAX_CHAINS];
177 	u_int16_t   chain_phase[HOST_MAX_CHAINS];
178 	u_int32_t   rtt_cfo_measurement;
179 	u_int8_t    agc_gain[HOST_MAX_CHAINS];
180 	u_int32_t   rx_start_ts;
181 	u_int16_t   mcs_rate;
182 	u_int16_t   gi_type;
183 	u_int8_t    agc_gain_tbl_index[HOST_MAX_CHAINS];
184 } __attribute__ ((__packed__));
185 
186 #ifdef WLAN_ENH_CFR_ENABLE
187 struct cfr_su_sig_info {
188 	u_int8_t coding;
189 	u_int8_t stbc;
190 	u_int8_t beamformed;
191 	u_int8_t dcm;
192 	u_int8_t ltf_size;
193 	u_int8_t sgi;
194 	u_int16_t reserved;
195 } __attribute__ ((__packed__));
196 
197 /* ensure to add new members at the end of the structure only */
198 struct enh_cfr_metadata {
199 	u_int8_t    status;
200 	u_int8_t    capture_bw;
201 	u_int8_t    channel_bw;
202 	u_int8_t    phy_mode;
203 	u_int16_t   prim20_chan;
204 	u_int16_t   center_freq1;
205 	u_int16_t   center_freq2;
206 	u_int8_t    capture_mode; /* ack_capture_mode */
207 	u_int8_t    capture_type; /* cfr_capture_type */
208 	u_int8_t    sts_count;
209 	u_int8_t    num_rx_chain;
210 	u_int64_t   timestamp;
211 	u_int32_t   length;
212 	u_int8_t    is_mu_ppdu;
213 	u_int8_t    num_mu_users;
214 	union {
215 		u_int8_t    su_peer_addr[QDF_MAC_ADDR_SIZE];
216 		u_int8_t    mu_peer_addr[MAX_CFR_MU_USERS][QDF_MAC_ADDR_SIZE];
217 	} peer_addr;
218 	u_int32_t   chain_rssi[HOST_MAX_CHAINS];
219 	u_int16_t   chain_phase[HOST_MAX_CHAINS];
220 	u_int32_t   rtt_cfo_measurement;
221 	u_int8_t    agc_gain[HOST_MAX_CHAINS];
222 	u_int32_t   rx_start_ts;
223 	u_int16_t   mcs_rate;
224 	u_int16_t   gi_type;
225 	struct cfr_su_sig_info sig_info;
226 	u_int8_t    agc_gain_tbl_index[HOST_MAX_CHAINS];
227 } __attribute__ ((__packed__));
228 #endif
229 
230 #define  CFR_META_DATA_LEN \
231 	(sizeof(struct csi_cfr_header) - sizeof(struct cfr_header_cmn))
232 
233 struct cfr_header_cmn {
234 	u_int32_t   start_magic_num;
235 	u_int32_t   vendorid;
236 	u_int8_t    cfr_metadata_version;
237 	u_int8_t    cfr_data_version;
238 	u_int8_t    chip_type;
239 	u_int8_t    pltform_type;
240 	u_int32_t   cfr_metadata_len;
241 	u_int64_t   host_real_ts;
242 } __attribute__ ((__packed__));
243 
244 struct csi_cfr_header {
245 	struct cfr_header_cmn cmn;
246 	union {
247 		struct dbr_cfr_metadata meta_dbr;
248 #ifdef WLAN_ENH_CFR_ENABLE
249 		struct enh_cfr_metadata meta_enh;
250 #endif
251 	} u;
252 } __attribute__ ((__packed__));
253 
254 /**
255  * struct cfr_capture_params - structure to store cfr config param
256  * @bandwidth: bandwidth of capture
257  * @period: period of capture
258  * @method: enum of method being followed to capture cfr data. 0-QoS null data
259  */
260 struct cfr_capture_params {
261 	u_int8_t   bandwidth;
262 	u_int32_t  period;
263 	u_int8_t   method;
264 };
265 
266 /**
267  * struct psoc_cfr - private psoc object for cfr
268  * @psoc_obj: pointer to psoc object
269  * @is_cfr_capable: flag to determine if cfr is enabled or not
270  * @is_cfr_pdev_id_soc: flag to send cfr request with PDEV_ID_SOC
271  * @is_cap_interval_mode_sel_support: flag to determine if target supports both
272  *				      capture_count and capture_duration modes
273  *				      with a nob provided to configure
274  * @is_mo_marking_support: flag to determine if MO marking is supported or not
275  * @is_aoa_for_rcc_support:
276  */
277 struct psoc_cfr {
278 	struct wlan_objmgr_psoc *psoc_obj;
279 	uint8_t is_cfr_capable;
280 	uint8_t is_cfr_pdev_id_soc;
281 #ifdef WLAN_ENH_CFR_ENABLE
282 	uint8_t is_cap_interval_mode_sel_support;
283 	uint8_t is_mo_marking_support;
284 	uint8_t is_aoa_for_rcc_support;
285 #endif
286 };
287 
288 /**
289  * struct cfr_wmi_host_mem_chunk - wmi mem chunk related
290  * @vaddr: pointer to virtual address
291  * @paddr: physical address
292  * @len: len of the mem chunk allocated
293  * @req_id: reqid related to the mem chunk
294  */
295 struct cfr_wmi_host_mem_chunk {
296 	uint32_t *vaddr;
297 	qdf_dma_addr_t paddr;
298 	uint32_t len;
299 	uint32_t req_id;
300 };
301 
302 struct whal_cfir_dma_hdr {
303 	uint16_t
304 		// 'BA'
305 		tag                 : 8,
306 		// '02', length of header in 4 octet units
307 		length              : 6,
308 		// 00
309 		reserved            : 2;
310 	uint16_t
311 		// [16]
312 		upload_done         : 1,
313 		// [17:18], 0: invalid, 1: CFR, 2: CIR, 3: DebugH
314 		capture_type        : 3,
315 		// [19:20], 0: Legacy, 1: HT, 2: VHT, 3: HE
316 		preamble_type       : 2,
317 		// [21:23], 0: 1-stream, 1: 2-stream, ..., 7: 8-stream
318 		nss                 : 3,
319 		// [24:27], 0: invalid, 1: 1-chain, 2: 2-chain, etc.
320 		num_chains          : 3,
321 		// [28:30], 0: 20 MHz, 1: 40 MHz, 2: 80 MHz, 3: 160 MHz
322 		upload_pkt_bw       : 3,    // [31]
323 		sw_peer_id_valid    : 1;
324 	uint16_t
325 		sw_peer_id          : 16;   // [15:0]
326 	uint16_t
327 		phy_ppdu_id         : 16;   // [15:0]
328 };
329 
330 #define MAX_LUT_ENTRIES 140 /* For HKv2 136 is max */
331 
332 /**
333  * struct look_up_table - Placeholder for 2 asynchronous events (DBR and
334  * TXRX event)
335  * @dbr_recv: Indicates whether WMI for DBR completion is received or not
336  * @tx_recv: Indicates whether WMI for TX completion (or) WDI event for RX
337  * status is received or not
338  * @data: pointer to CFR data that ucode DMAs to host memory
339  * @data_len: length of CFR data DMAed by ucode
340  * @dbr_ppdu_id: PPDU id retrieved from DBR completion WMI event
341  * @tx_ppdu_id: PPDU id retrieved from WMI TX completion event (or) PPDU status
342  * TLV
343  * @dbr_address: Physical address of the CFR data dump retrieved from DBR
344  * completion WMI event
345  * @tx_address1: Physical address of the CFR data from TX/RX event
346  * @tx_address2: Physical address of the CFR data from TX/RX event
347  * @header: CFR header constructed by host
348  * @dma_hdr: CFR header constructed by ucode
349  * @txrx_tstamp: Timestamp when TX/RX event was received
350  * @dbr_tstamp: Timestamp when DBR completion event was received
351  * @header_length: Length of header DMAed by ucode in words
352  * @payload_length: Length of CFR payload
353  */
354 struct look_up_table {
355 	bool dbr_recv;
356 	bool tx_recv;
357 	uint8_t *data; /* capture payload */
358 	uint32_t data_len; /* capture len */
359 	uint16_t dbr_ppdu_id; /* ppdu id from dbr */
360 	uint16_t tx_ppdu_id; /* ppdu id from TX event */
361 	qdf_dma_addr_t dbr_address; /* capture len */
362 	uint32_t tx_address1; /* capture len */
363 	uint32_t tx_address2; /* capture len */
364 	struct csi_cfr_header header;
365 	struct whal_cfir_dma_hdr dma_hdr;
366 	uint64_t txrx_tstamp;
367 	uint64_t dbr_tstamp;
368 	uint32_t header_length;
369 	uint32_t payload_length;
370 };
371 
372 struct unassoc_pool_entry {
373 	struct qdf_mac_addr mac;
374 	struct cfr_capture_params cfr_params;
375 	bool is_valid;
376 };
377 
378 #ifdef WLAN_ENH_CFR_ENABLE
379 /**
380  * struct ta_ra_cfr_cfg - structure to store configuration of 16 groups in
381  * M_TA_RA mode
382  * @filter_group_id: Filter group number for which the below filters needs to be
383  * applied
384  * @bw: CFR capture will be done for packets matching the bandwidths specified
385  * within this bitmask
386  * @nss: CFR capture will be done for packets matching the Nss specified within
387  * this bitmask
388  * @rsvd0: reserved bits
389  * @valid_ta: Ta_addr is valid if set
390  * @valid_ta_mask: Ta_addr_mask is valid if set
391  * @valid_ra: Ra_addr is valid if set
392  * @valid_ra_mask: Ra_addr_mask is valid if set
393  * @valid_bw_mask: Bandwidth is valid if set
394  * @valid_nss_mask: NSS is valid if set
395  * @valid_mgmt_subtype: Mgmt_subtype is valid if set
396  * @valid_ctrl_subtype: Ctrl_subtype is valid if set
397  * @valid_data_subtype: Data_subtype is valid if set
398  * @rsvd1: reserved bits
399  * @mgmt_subtype_filter: Managments Packets matching the subtype filter
400  * categories will be filtered in by MAC for CFR capture.
401  * @ctrl_subtype_filter: Control Packets matching the subtype filter
402  * categories will be filtered in by MAC for CFR capture.
403  * @data_subtype_filter: Data Packets matching the subtype filter
404  * categories will be filtered in by MAC for CFR capture.
405  * @tx_addr: Packets whose transmitter address matches (tx_addr & tx_addr_mask)
406  * will be filtered in by MAC
407  * @tx_addr_mask: Packets whose transmitter address matches (tx_addr &
408  * tx_addr_mask) will be filtered in by MAC
409  * @rx_addr: Packets whose receiver address matches (rx_addr & rx_addr_mask)
410  * will be filtered in by MAC
411  * @rx_addr_mask: Packets whose receiver address matches (rx_addr &
412  * rx_addr_mask) will be filtered in by MAC
413  */
414 struct ta_ra_cfr_cfg {
415 	uint8_t filter_group_id;
416 	uint16_t bw                          :6,
417 		 nss                         :8,
418 		 rsvd0                       :2;
419 	uint16_t valid_ta                    :1,
420 		 valid_ta_mask               :1,
421 		 valid_ra                    :1,
422 		 valid_ra_mask               :1,
423 		 valid_bw_mask               :1,
424 		 valid_nss_mask              :1,
425 		 valid_mgmt_subtype          :1,
426 		 valid_ctrl_subtype          :1,
427 		 valid_data_subtype          :1,
428 		 rsvd1                       :7;
429 	uint16_t mgmt_subtype_filter;
430 	uint16_t ctrl_subtype_filter;
431 	uint16_t data_subtype_filter;
432 	uint8_t tx_addr[QDF_MAC_ADDR_SIZE];
433 	uint8_t rx_addr[QDF_MAC_ADDR_SIZE];
434 	uint8_t tx_addr_mask[QDF_MAC_ADDR_SIZE];
435 	uint8_t rx_addr_mask[QDF_MAC_ADDR_SIZE];
436 
437 } qdf_packed;
438 
439 /**
440  * struct cfr_rcc_param - structure to store cfr config param
441  * @pdev_id: pdev_id for identifying the MAC
442  * @vdev_id: vdev_id of current rcc configures
443  * @srng_id: srng id of current rcc configures
444  * @capture_duration: Capture Duration field for which CFR capture has to
445  * happen, in microsecond units
446  * @capture_interval: Capture interval field which is time in between
447  * consecutive CFR capture, in microsecond units
448  * @ul_mu_user_mask_lower: Bitfields indicates which of the users in the current
449  * UL MU transmission are enabled for CFR capture.
450  * @ul_mu_user_mask_upper: This is continuation of the above lower mask.
451  * @freeze_tlv_delay_cnt_en: Enable Freeze TLV delay counter in MAC
452  * @freeze_tlv_delay_cnt_thr: Indicates the number of consecutive Rx packets to
453  * be skipped before CFR capture is enabled again.
454  * @rsvd0: reserved bits
455  * @filter_group_bitmap: Bitfields set indicates which of the CFR group config
456  * is enabled
457  * @m_directed_ftm: Filter Directed FTM ACK frames for CFR capture
458  * @m_all_ftm_ack: Filter All FTM ACK frames for CFR capture
459  * @m_ndpa_ndp_directed: Filter NDPA NDP Directed Frames for CFR capture
460  * @m_ndpa_ndp_all: Filter all NDPA NDP for CFR capture
461  * @m_ta_ra_filter: Filter Frames based on TA/RA/Subtype as provided in CFR
462  * Group config
463  * @m_all_packet: Filter in All packets for CFR Capture
464  * @en_ta_ra_filter_in_as_fp: Filter in frames as FP/MO in m_ta_ra_filter mode
465  * @rsvd1: reserved bits
466  * @num_grp_tlvs: Indicates the number of groups in M_TA_RA mode, that have
467  * changes in the current commit session, use to construct WMI group TLV(s)
468  * @curr: Placeholder for M_TA_RA group config in current commit session
469  * @modified_in_curr_session: Bitmap indicating number of groups in M_TA_RA mode
470  * that have changed in current commit session.
471  * @capture_count: After capture_count+1 number of captures, MAC stops RCC  and
472  * waits for capture_interval duration before enabling again
473  * @capture_intval_mode_sel: 0 indicates capture_duration mode, 1 indicates the
474  * capture_count mode.
475  * @rsvd2: reserved bits
476  */
477 struct cfr_rcc_param {
478 	uint8_t pdev_id;
479 	uint8_t vdev_id;
480 	uint8_t srng_id;
481 	uint32_t capture_duration;
482 	uint32_t capture_interval;
483 	uint32_t ul_mu_user_mask_lower;
484 	uint32_t ul_mu_user_mask_upper;
485 	uint16_t freeze_tlv_delay_cnt_en  :1,
486 		 freeze_tlv_delay_cnt_thr :8,
487 		 rsvd0 :7;
488 	uint16_t filter_group_bitmap;
489 	uint8_t m_directed_ftm           : 1,
490 		m_all_ftm_ack            : 1,
491 		m_ndpa_ndp_directed      : 1,
492 		m_ndpa_ndp_all           : 1,
493 		m_ta_ra_filter           : 1,
494 		m_all_packet             : 1,
495 		en_ta_ra_filter_in_as_fp : 1,
496 		rsvd1                    : 1;
497 	uint8_t num_grp_tlvs;
498 
499 	struct ta_ra_cfr_cfg curr[MAX_TA_RA_ENTRIES];
500 	unsigned long modified_in_curr_session;
501 	uint32_t capture_count            :16,
502 		 capture_intval_mode_sel  :1,
503 		 rsvd2                    :15;
504 };
505 #endif /* WLAN_ENH_CFR_ENABLE */
506 
507 /**
508  * struct nl_event_cb - nl event cb for cfr data
509  * @vdev_id: vdev id
510  * @pid: PID to which data is sent via unicast nl event
511  * @cfr_nl_cb: callback to send nl event
512  */
513 struct nl_event_cb {
514 	uint8_t vdev_id;
515 	uint32_t pid;
516 	void (*cfr_nl_cb)(uint8_t vdev_id, uint32_t pid,
517 			  const void *data, uint32_t data_len);
518 };
519 
520 /**
521  * struct pdev_cfr - private pdev object for cfr
522  * @pdev_obj: pointer to pdev object
523  * @is_cfr_capable: flag to determine if cfr is enabled or not
524  * @cfr_timer_enable: flag to enable/disable timer
525  * @chip_type: chip type which is defined in enum cfrradiotype
526  * @cfr_mem_chunk: Region of memory used for storing cfr data
527  * @cfr_max_sta_count: Maximum stations supported in one-shot capture mode
528  * @cfr_current_sta_count:
529  * @num_subbufs: No. of sub-buffers used in relayfs
530  * @subbuf_size: Size of sub-buffer used in relayfs
531  * @chan_ptr: Channel in relayfs
532  * @dir_ptr: Parent directory of relayfs file
533  * @lut: lookup table used to store asynchronous DBR and TX/RX events for
534  * correlation
535  * @lut_num: Number of lut
536  * @dbr_buf_size: Size of DBR completion buffer
537  * @dbr_num_bufs: No. of DBR completions
538  * @max_mu_users: Max number of MU users
539  * @tx_evt_cnt: No. of TX completion events till CFR stop was issued
540  * @total_tx_evt_cnt: No. of Tx completion events since wifi was up
541  * @dbr_evt_cnt: No. of WMI DBR completion events
542  * @release_cnt: No. of CFR data buffers relayed to userspace
543  * @tx_peer_status_cfr_fail: No. of tx events without tx status set to
544  * PEER_CFR_CAPTURE_EVT_STATUS_MASK indicating CFR capture failure on a peer.
545  * @tx_evt_status_cfr_fail: No. of tx events without tx status set to
546  * CFR_TX_EVT_STATUS_MASK indicating CFR capture status failure.
547  * @tx_dbr_cookie_lookup_fail: No. of dbr cookie lookup failures during tx event
548  * process.
549  * @rcc_param: Structure to store CFR config for the current commit session
550  * @global: Structure to store accumulated CFR config
551  * @rx_tlv_evt_cnt: Number of CFR WDI events from datapath
552  * @lut_age_timer: Timer to flush pending TXRX/DBR events in lookup table
553  * @lut_timer_init: flag to determine if lut_age_timer is initialized or not
554  * @is_cfr_rcc_capable: Flag to determine if RCC is enabled or not.
555  * @flush_dbr_cnt: No. of un-correlated DBR completions flushed when a newer
556  * PPDU is correlated successfully with newer DBR completion
557  * @invalid_dma_length_cnt: No. of buffers for which CFR DMA header length (or)
558  * data length was invalid
559  * @flush_timeout_dbr_cnt: No. of DBR completion flushed out in ageout logic
560  * @clear_txrx_event: No. of PPDU status TLVs over-written in LUT
561  * @last_success_tstamp: DBR timestamp which indicates that both DBR and TX/RX
562  * events have been received successfully.
563  * @cfr_dma_aborts: No. of CFR DMA aborts in ucode
564  * @is_cap_interval_mode_sel_support: flag to determine if target supports both
565  * @is_mo_marking_support: flag to determine if MO marking is supported or not
566  * @is_aoa_for_rcc_support: flag to determine if AoA is available for RCC or not
567  * capture_count and capture_duration modes with a nob provided to configure.
568  * @unassoc_pool: Pool of un-associated clients used when capture method is
569  * CFR_CAPTURE_METHOD_PROBE_RESPONSE
570  * @nl_cb: call back to register for nl event for cfr data
571  * @lut_lock: Lock to protect access to cfr lookup table
572  * @lut_lock_initialised: Check lut_lock initialised or not.
573  * @is_prevent_suspend: CFR wake lock acquired or not
574  * @wake_lock: wake lock for cfr
575  * @runtime_lock: runtime lock for cfr
576  * @freq: current operating freq for which AoA Phase delta values reported by FW
577  * @max_aoa_chains: Indicate the max number of chains to which target supports
578  * AoA data.
579  * @phase_delta: per chain phase delta associated with 62 gain values reported
580  * by FW via WMI_PDEV_AOA_PHASEDELTA_EVENTID. This is for the targets which
581  * supports only default gain table.
582  * @ibf_cal_val: Per chain IBF cal value from FW.
583  * @is_enh_aoa_data: flag to indicate the pdev supports enhanced AoA.
584  * @max_agc_gain_tbls: Max rx AGC gain tables supported & advertised by target.
585  * @max_agc_gain_per_tbl_2g: Max possible rx AGC gain per table on 2GHz band.
586  * @max_agc_gain_per_tbl_5g: Max possible rx AGC gain per table on 5GHz band.
587  * @max_agc_gain_per_tbl_6g: Max possbile rx AGC gain per table on 6GHz band.
588  * @max_bdf_entries_per_tbl: Max entries per table in gain & phase array.
589  * @max_entries_all_table: Max entries across table in gain & phase array.
590  * @gain_stop_index_array: This array has optimized gain range values stored.
591  * @enh_phase_delta_array: This array has optimized phase delta values stored
592  * aligning with gain_stop_index_array.
593  * @start_ent: array where each entry indicates the offset index per table to be
594  * applied on gain_stop_index_array and enh_phase_delta_array
595  * @xbar_config: xbar config to be used to map bb to rf chainmask.
596  */
597 /*
598  * To be extended if we get more capbality info
599  * from FW's extended service ready event.
600  */
601 struct pdev_cfr {
602 	struct wlan_objmgr_pdev *pdev_obj;
603 	uint8_t is_cfr_capable;
604 	uint8_t cfr_timer_enable;
605 	uint8_t chip_type;
606 	struct cfr_wmi_host_mem_chunk cfr_mem_chunk;
607 	uint16_t cfr_max_sta_count;
608 	uint16_t cfr_current_sta_count;
609 	uint32_t num_subbufs;
610 	uint32_t subbuf_size;
611 	qdf_streamfs_chan_t chan_ptr;
612 	qdf_dentry_t dir_ptr;
613 	struct look_up_table **lut;
614 	uint32_t lut_num;
615 	uint32_t dbr_buf_size;
616 	uint32_t dbr_num_bufs;
617 	uint32_t max_mu_users;
618 	uint64_t tx_evt_cnt;
619 	uint64_t total_tx_evt_cnt;
620 	uint64_t dbr_evt_cnt;
621 	uint64_t release_cnt;
622 	uint64_t tx_peer_status_cfr_fail;
623 	uint64_t tx_evt_status_cfr_fail;
624 	uint64_t tx_dbr_cookie_lookup_fail;
625 #ifdef WLAN_ENH_CFR_ENABLE
626 	struct cfr_rcc_param rcc_param;
627 	struct ta_ra_cfr_cfg global[MAX_TA_RA_ENTRIES];
628 	uint64_t rx_tlv_evt_cnt;
629 	qdf_timer_t lut_age_timer;
630 	uint8_t lut_timer_init;
631 	uint8_t is_cfr_rcc_capable;
632 	uint64_t flush_dbr_cnt;
633 	uint64_t invalid_dma_length_cnt;
634 	uint64_t flush_timeout_dbr_cnt;
635 	uint64_t clear_txrx_event;
636 	uint64_t last_success_tstamp;
637 	uint64_t cfr_dma_aborts;
638 	uint8_t is_cap_interval_mode_sel_support;
639 	uint8_t is_mo_marking_support;
640 	uint8_t is_aoa_for_rcc_support;
641 #endif
642 	struct unassoc_pool_entry unassoc_pool[MAX_CFR_ENABLED_CLIENTS];
643 	struct nl_event_cb nl_cb;
644 	qdf_spinlock_t lut_lock;
645 	bool lut_lock_initialised;
646 #ifdef WLAN_CFR_PM
647 	bool is_prevent_suspend;
648 	qdf_wake_lock_t wake_lock;
649 	qdf_runtime_lock_t runtime_lock;
650 #endif
651 #ifdef WLAN_ENH_CFR_ENABLE
652 	uint32_t freq;
653 	uint32_t max_aoa_chains;
654 	uint16_t phase_delta[HOST_MAX_CHAINS][MAX_AGC_GAIN];
655 	uint32_t ibf_cal_val[HOST_MAX_CHAINS];
656 #ifdef WLAN_RCC_ENHANCED_AOA_SUPPORT
657 	bool is_enh_aoa_data;
658 	uint32_t max_agc_gain_tbls;
659 	uint16_t max_agc_gain_per_tbl_2g[PSOC_MAX_NUM_AGC_GAIN_TBLS];
660 	uint16_t max_agc_gain_per_tbl_5g[PSOC_MAX_NUM_AGC_GAIN_TBLS];
661 	uint16_t max_agc_gain_per_tbl_6g[PSOC_MAX_NUM_AGC_GAIN_TBLS];
662 	uint8_t max_bdf_entries_per_tbl[PSOC_MAX_NUM_AGC_GAIN_TBLS];
663 	uint32_t max_entries_all_table;
664 	uint16_t *gain_stop_index_array;
665 	uint16_t *enh_phase_delta_array;
666 	uint8_t start_ent[PSOC_MAX_NUM_AGC_GAIN_TBLS];
667 	uint32_t xbar_config;
668 #endif /* WLAN_RCC_ENHANCED_AOA_SUPPORT */
669 #endif /* WLAN_ENH_CFR_ENABLE */
670 };
671 
672 /**
673  * enum cfr_capt_status - CFR capture status
674  * @PEER_CFR_CAPTURE_DISABLE: Capture not in progress
675  * @PEER_CFR_CAPTURE_ENABLE: Capture in progress
676  */
677 enum cfr_capt_status {
678 	PEER_CFR_CAPTURE_DISABLE,
679 	PEER_CFR_CAPTURE_ENABLE,
680 };
681 
682 /**
683  * struct peer_cfr - private peer object for cfr
684  * @peer_obj: pointer to peer_obj
685  * @request: Type of request (start/stop)
686  * @bandwidth: bandwidth of capture for this peer
687  * @period: period of capture for this peer
688  * @capture_method: enum determining type of cfr data capture.
689  *                 0-Qos null data
690  */
691 struct peer_cfr {
692 	struct wlan_objmgr_peer *peer_obj;
693 	u_int8_t   request;            /* start/stop */
694 	u_int8_t   bandwidth;
695 	u_int32_t  period;
696 	u_int8_t   capture_method;
697 };
698 
699 /**
700  * cfr_initialize_pdev() - cfr initialize pdev
701  * @pdev: Pointer to pdev_obj
702  *
703  * Return: status of cfr pdev init
704  */
705 QDF_STATUS cfr_initialize_pdev(struct wlan_objmgr_pdev *pdev);
706 
707 /**
708  * cfr_deinitialize_pdev() - cfr deinitialize pdev
709  * @pdev: Pointer to pdev_obj
710  *
711  * Return: status of cfr pdev deinit
712  */
713 QDF_STATUS cfr_deinitialize_pdev(struct wlan_objmgr_pdev *pdev);
714 
715 /**
716  * wlan_cfr_init() - Global init for cfr.
717  *
718  * Return: status of global init pass/fail
719  */
720 QDF_STATUS wlan_cfr_init(void);
721 
722 /**
723  * wlan_cfr_deinit() - Global de-init for cfr.
724  *
725  * Return: status of global de-init pass/fail
726  */
727 QDF_STATUS wlan_cfr_deinit(void);
728 
729 /**
730  * wlan_cfr_pdev_open() - pdev_open function for cfr.
731  * @pdev: pointer to pdev object
732  *
733  * Return: status of pdev_open pass/fail
734  */
735 QDF_STATUS wlan_cfr_pdev_open(struct wlan_objmgr_pdev *pdev);
736 
737 /**
738  * wlan_cfr_pdev_close() - pdev_close function for cfr.
739  * @pdev: pointer to pdev object
740  *
741  * Return: status of pdev_close pass/fail
742  */
743 QDF_STATUS wlan_cfr_pdev_close(struct wlan_objmgr_pdev *pdev);
744 
745 /**
746  * count_set_bits() - function to count set bits in a bitmap
747  * @value: input bitmap
748  *
749  * Return: No. of set bits
750  */
751 uint8_t count_set_bits(unsigned long value);
752 
753 /**
754  * wlan_cfr_is_feature_disabled() - Check if cfr feature is disabled
755  * @pdev: the physical device object.
756  *
757  * Return : true if cfr is disabled, else false.
758  */
759 bool wlan_cfr_is_feature_disabled(struct wlan_objmgr_pdev *pdev);
760 
761 #ifdef WLAN_ENH_CFR_ENABLE
762 /**
763  * wlan_cfr_rx_tlv_process() - Process PPDU status TLVs and store info in
764  * lookup table
765  * @pdev: PDEV object
766  * @nbuf: ppdu info
767  *
768  * Return: none
769  */
770 void wlan_cfr_rx_tlv_process(struct wlan_objmgr_pdev *pdev, void *nbuf);
771 #endif
772 #endif
773