xref: /wlan-driver/qca-wifi-host-cmn/umac/wifi_pos/inc/wifi_pos_utils_i.h (revision 5113495b16420b49004c444715d2daae2066e7dc)
1 /*
2  * Copyright (c) 2012-2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2021-2024 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 /**
21  * DOC: wifi_pos_utils_i.h
22  * This file defines the prototypes for the utility helper functions
23  * for the wifi_pos component.
24  */
25 
26 #ifdef WIFI_POS_CONVERGED
27 #ifndef _WIFI_POS_UTILS_H_
28 #define _WIFI_POS_UTILS_H_
29 /* Include files */
30 #include "qdf_types.h"
31 #include "qdf_status.h"
32 #include "ol_defines.h"
33 #include "qdf_trace.h"
34 #include "qdf_module.h"
35 #include "wifi_pos_utils_pub.h"
36 #include "wlan_objmgr_vdev_obj.h"
37 #include "wlan_cmn.h"
38 
39 struct wlan_objmgr_psoc;
40 struct wifi_pos_req_msg;
41 
42 #define wifi_pos_alert(params...) \
43 	QDF_TRACE_FATAL(QDF_MODULE_ID_WIFIPOS, params)
44 #define wifi_pos_err(params...) \
45 	QDF_TRACE_ERROR(QDF_MODULE_ID_WIFIPOS, params)
46 #define wifi_pos_warn(params...) \
47 	QDF_TRACE_WARN(QDF_MODULE_ID_WIFIPOS, params)
48 #define wifi_pos_notice(params...) \
49 	QDF_TRACE_INFO(QDF_MODULE_ID_WIFIPOS, params)
50 #define wifi_pos_debug(params...) \
51 	QDF_TRACE_DEBUG(QDF_MODULE_ID_WIFIPOS, params)
52 
53 #define wifipos_nofl_alert(params...) \
54 	QDF_TRACE_FATAL_NO_FL(QDF_MODULE_ID_WIFIPOS, params)
55 #define wifipos_nofl_err(params...) \
56 	QDF_TRACE_ERROR_NO_FL(QDF_MODULE_ID_WIFIPOS, params)
57 #define wifipos_nofl_warn(params...) \
58 	QDF_TRACE_WARN_NO_FL(QDF_MODULE_ID_WIFIPOS, params)
59 #define wifipos_nofl_notice(params...) \
60 	QDF_TRACE_INFO_NO_FL(QDF_MODULE_ID_WIFIPOS, params)
61 #define wifipos_nofl_debug(params...) \
62 	QDF_TRACE_DEBUG_NO_FL(QDF_MODULE_ID_WIFIPOS, params)
63 
64 #define OEM_APP_SIGNATURE_STR      "QUALCOMM-OEM-APP"
65 #define OEM_APP_SIGNATURE_LEN      (sizeof(OEM_APP_SIGNATURE_STR) - 1)
66 
67 #ifndef OEM_DATA_RSP_SIZE
68 #define OEM_DATA_RSP_SIZE 1724
69 /* Header + VHT80 CIR * 2 chains */
70 #define OEM_DATA_DMA_BUFF_SIZE (64 + 512 * 4 * 2)
71 #endif
72 
73 /**
74  * struct app_reg_rsp_vdev_info - vdev info struct
75  * @dev_mode: device mode
76  * @vdev_id: vdev id
77  *
78  */
79 struct app_reg_rsp_vdev_info {
80 	uint8_t dev_mode;
81 	uint8_t vdev_id;
82 } qdf_packed;
83 
84 /**
85  * struct wifi_app_reg_rsp - app registration response struct
86  * @num_inf: number of interfaces active
87  * @vdevs: array indicating all active vdev's information
88  *
89  */
90 struct wifi_app_reg_rsp {
91 	uint8_t num_inf;
92 	QDF_FLEX_ARRAY(struct app_reg_rsp_vdev_info, vdevs);
93 } qdf_packed;
94 
95 /**
96  * struct oem_data_req - data request to be sent to firmware
97  * @data_len: len of data
98  * @data: buffer containing data
99  *
100  */
101 struct oem_data_req {
102 	uint32_t data_len;
103 	uint8_t *data;
104 };
105 
106 /**
107  * struct oem_data_rsp - response from firmware to data request sent earlier
108  * @rsp_len_1: len of data_1
109  * @data_1: first part of payload
110  * @rsp_len_2: len of data_2
111  * @data_2: second part of payload
112  * @dma_len: len of DMAed data
113  * @vaddr: virtual address of DMA data start
114  *
115  */
116 struct oem_data_rsp {
117 	uint32_t rsp_len_1;
118 	uint8_t *data_1;
119 	uint32_t rsp_len_2;
120 	uint8_t *data_2;
121 	uint32_t dma_len;
122 	void *vaddr;
123 };
124 
125 /**
126  * struct wifi_pos_err_rpt - Error report response for userspace.
127  * @tag_len: tlv header of the message.
128  * @info: Report info. Reserved for error report.
129  * @dest_mac: Mac address of the sta in the request.
130  * @reserved: Reserved in error report.
131  */
132 struct wifi_pos_err_rpt {
133 	uint32_t tag_len;
134 	uint32_t info;
135 	uint8_t  dest_mac[QDF_MAC_ADDR_SIZE + 2];
136 	uint32_t reserved;
137 } qdf_packed;
138 
139 #define OEM_MSG_RSP_HEAD_TAG_ID 33
140 #define OEM_MEAS_RSP_HEAD_TAG_ID 41
141 /**
142  * struct wifi_pos_err_msg_report - Error report message
143  * @msg_tag_len: Message tlv header
144  * @msg_subtype: Message subtype
145  * @req_id: id corresponding to the request.
146  * @fragment_info: Valid only for fragments.
147  * @pdev_id: pdev_id of radion.
148  * @time_left: time left in the measurement req.
149  * @err_rpt: Error report data.
150  */
151 struct wifi_pos_err_msg_report {
152 	uint32_t msg_tag_len;
153 	uint32_t msg_subtype;
154 	uint32_t req_id;
155 	uint32_t fragment_info;
156 	uint32_t pdev_id;
157 	uint32_t time_left;
158 	struct wifi_pos_err_rpt err_rpt;
159 } qdf_packed;
160 
161 /**
162  * struct wifi_pos_dma_rings_cap - capabilities requested by firmware.
163  * @pdev_id: pdev_id or mac_id of ring
164  * @min_num_ptr: minimum depth of ring required
165  * @min_buf_size: minimum size of each buffer
166  * @min_buf_align: minimum alignment of buffer memory
167  */
168 struct wifi_pos_dma_rings_cap {
169 	uint32_t pdev_id;
170 	uint32_t min_num_ptr;
171 	uint32_t min_buf_size;
172 	uint32_t min_buf_align;
173 };
174 
175 /**
176  * struct wifi_pos_dma_buf_info - buffer info struct containing phy to virtual
177  * mapping.
178  * @cookie: this identifies location of DMA buffer in pool array
179  * @paddr: aligned physical address as exchanged with firmware
180  * @vaddr: virtual address - unaligned. this helps in freeing later
181  * @offset: offset of aligned address from unaligned
182  */
183 struct wifi_pos_dma_buf_info {
184 	uint32_t cookie;
185 	void *paddr;
186 	void *vaddr;
187 	uint8_t offset;
188 };
189 
190 /**
191  * struct wifi_pos_dma_rings_cfg - DMA ring parameters to be programmed to FW.
192  * @pdev_id: pdev_id of ring
193  * @num_ptr: depth of ring
194  * @ring_alloc_size: size of the ring allocation
195  * @base_paddr_unaligned: base physical addr unaligned
196  * @base_vaddr_unaligned: base virtual addr unaligned
197  * @base_paddr_aligned: base physical addr aligned
198  * @base_vaddr_aligned: base virtual addr unaligned
199  * @head_idx_addr: head index addr
200  * @tail_idx_addr: tail index addr
201  * @srng: hal srng
202  */
203 struct wifi_pos_dma_rings_cfg {
204 	uint32_t pdev_id;
205 	uint32_t num_ptr;
206 	uint32_t ring_alloc_size;
207 	void *base_paddr_unaligned;
208 	void *base_vaddr_unaligned;
209 	void *base_paddr_aligned;
210 	void *base_vaddr_aligned;
211 	void *head_idx_addr;
212 	void *tail_idx_addr;
213 	void *srng;
214 };
215 
216 typedef void (*wifi_pos_send_rsp_handler)(struct wlan_objmgr_psoc *, uint32_t,
217 					  enum wifi_pos_cmd_ids,
218 					  uint32_t, uint8_t *);
219 
220 /**
221  * struct wifi_pos_legacy_ops  - wifi pos module legacy callbacks
222  * @pasn_peer_create_cb: PASN peer create callback
223  * @pasn_peer_delete_cb: PASN peer delete callback
224  * @pasn_vdev_delete_resume_cb: PASN resume vdev delete callback
225  */
226 struct wifi_pos_legacy_ops {
227 	QDF_STATUS (*pasn_peer_create_cb)(struct wlan_objmgr_psoc *psoc,
228 					  struct qdf_mac_addr *peer_addr,
229 					  uint8_t vdev_id);
230 	QDF_STATUS (*pasn_peer_delete_cb)(struct wlan_objmgr_psoc *psoc,
231 					  struct qdf_mac_addr *peer_addr,
232 					  uint8_t vdev_id,
233 					  bool no_fw_peer_delete);
234 	QDF_STATUS (*pasn_vdev_delete_resume_cb)(struct wlan_objmgr_vdev *vdev);
235 };
236 
237 /**
238  * struct wifi_pos_psoc_priv_obj - psoc obj data for wifi_pos
239  * @app_pid: pid of app registered to host driver
240  * @is_app_registered: indicates if app is registered
241  * @fine_time_meas_cap: FTM cap for different roles, reflection of ini
242  * @ftm_rr: configured value of FTM Ranging Request capability
243  * @lci_capability: configured value of LCI capability
244  * @rsvd: reserved
245  * @oem_target_type
246  * @oem_target_type: oem target type, populated from HDD
247  * @oem_fw_version: firmware version, populated from HDD
248  * @driver_version: driver version, populated from HDD
249  * @allowed_dwell_time_min: allowed dwell time min, populated from HDD
250  * @allowed_dwell_time_max: allowed dwell time max, populated from HDD
251  * @current_dwell_time_min: current dwell time min, populated from HDD
252  * @current_dwell_time_max: current dwell time max, populated from HDD
253  * @hal_soc: hal_soc
254  * @num_rings: DMA ring cap requested by firmware
255  * @dma_cap: dma cap as read from service ready ext event
256  * @dma_cfg: DMA ring cfg to be programmed to firmware
257  * @dma_buf_pool: DMA buffer pools maintained at host: this will be 2-D array
258  * where with num_rows = number of rings num_elements in each row = ring depth
259  * @osif_cb: Callbacks to OS_IF
260  * @wifi_pos_lock: lock to access wifi pos priv object
261  * @oem_6g_support_disable: oem target 6ghz support is disabled if set
262  * @enable_rsta_secure_ltf_support: Enable RSTA secure LTF support
263  * @enable_rsta_11az_ranging: Enable RSTA 802.11 az secure ranging support
264  * @wifi_pos_req_handler: function pointer to handle TLV or non-TLV
265  * @wifi_pos_send_rsp: function pointer to send msg to userspace APP
266  * @wifi_pos_get_phy_mode: function pointer to get wlan phymode for given
267  *                         channel, channel width
268  * @wifi_pos_get_fw_phy_mode_for_freq: function pointer to get fw phymode
269  *                                     for given freq and channel width
270  * @wifi_pos_send_action: function pointer to send registered action frames
271  *                        to userspace APP
272  * @wifi_pos_get_pdev_id_by_dev_name: get pdev_id from device name
273  * @wifi_pos_measurement_request_notification: Call this API when the driver
274  *                                             receives measurement request
275  *                                             from the LOWI application
276  * @legacy_ops: wifi pos legacy callbacks
277  * @rsp_version: rsp version
278  *
279  * wifi pos request messages
280  * <----- fine_time_meas_cap (in bits) ----->
281  *+----------+-----+-----+------+------+-------+-------+-----+-----+
282  *|   8-31   |  7  |  6  |   5  |   4  |   3   |   2   |  1  |  0  |
283  *+----------+-----+-----+------+------+-------+-------+-----+-----+
284  *| reserved | SAP | SAP |P2P-GO|P2P-GO|P2P-CLI|P2P-CLI| STA | STA |
285  *|          |resp |init |resp  |init  |resp   |init   |resp |init |
286  *+----------+-----+-----+------+------+-------+-------+-----+-----+
287  * resp - responder role; init- initiator role
288  * @wifi_pos_get_max_fw_phymode_for_channels: function pointer to get max
289  *            supported FW phymode for the given channels
290  *
291  */
292 struct wifi_pos_psoc_priv_obj {
293 	uint32_t app_pid;
294 	bool is_app_registered;
295 	uint32_t fine_time_meas_cap;
296 	uint32_t ftm_rr:1;
297 	uint32_t lci_capability:1;
298 	uint32_t rsvd:30;
299 
300 	uint32_t oem_target_type;
301 	uint32_t oem_fw_version;
302 	struct wifi_pos_driver_version driver_version;
303 	uint16_t allowed_dwell_time_min;
304 	uint16_t allowed_dwell_time_max;
305 	uint16_t current_dwell_time_min;
306 	uint16_t current_dwell_time_max;
307 
308 	void *hal_soc;
309 	uint8_t num_rings;
310 	struct wifi_pos_dma_rings_cap *dma_cap;
311 	struct wifi_pos_dma_rings_cfg *dma_cfg;
312 	struct wifi_pos_dma_buf_info **dma_buf_pool;
313 
314 	struct wifi_pos_osif_ops *osif_cb;
315 
316 	qdf_spinlock_t wifi_pos_lock;
317 	bool oem_6g_support_disable;
318 	bool enable_rsta_secure_ltf_support;
319 	uint32_t enable_rsta_11az_ranging;
320 	struct wifi_pos_legacy_ops *legacy_ops;
321 	QDF_STATUS (*wifi_pos_req_handler)(struct wlan_objmgr_psoc *psoc,
322 				    struct wifi_pos_req_msg *req);
323 	wifi_pos_send_rsp_handler wifi_pos_send_rsp;
324 	void (*wifi_pos_get_phy_mode)(qdf_freq_t freq, uint32_t chan_width,
325 				      enum wlan_phymode *phy_mode);
326 	void (*wifi_pos_get_fw_phy_mode_for_freq)(uint32_t, uint32_t,
327 						  uint32_t *);
328 	void (*wifi_pos_send_action)(struct wlan_objmgr_psoc *psoc,
329 				     uint32_t oem_subtype, uint8_t *buf,
330 				     uint32_t len);
331 	QDF_STATUS (*wifi_pos_get_pdev_id_by_dev_name)(
332 			char *dev_name, uint8_t *pdev_id,
333 			struct wlan_objmgr_psoc **psoc);
334 	QDF_STATUS (*wifi_pos_measurement_request_notification)(
335 			struct wlan_objmgr_pdev *pdev,
336 			struct rtt_channel_info *chinfo);
337 	uint32_t rsp_version;
338 	QDF_STATUS (*wifi_pos_get_max_fw_phymode_for_channels)(
339 			struct wlan_objmgr_pdev *pdev,
340 			struct wifi_pos_channel_power *chan_list,
341 			uint16_t wifi_pos_num_chans);
342 };
343 
344 /**
345  * wifi_pos_get_psoc_priv_obj: API to get wifi_psoc private object
346  * @psoc: pointer to psoc object
347  *
348  * Return: psoc private object on success, NULL otherwise
349  */
350 struct wifi_pos_psoc_priv_obj *wifi_pos_get_psoc_priv_obj(
351 		struct wlan_objmgr_psoc *psoc);
352 
353 /**
354  * wifi_pos_lock_init: API to init lock used protect use of psoc global pointer
355  * variable
356  *
357  * Return: none.
358  */
359 void wifi_pos_lock_init(void);
360 
361 /**
362  * wifi_pos_lock_deinit: API to deinit lock used protect use of psoc global
363  * pointer variable
364  *
365  * Return: none.
366  */
367 void wifi_pos_lock_deinit(void);
368 
369 /**
370  * wifi_pos_set_psoc: API to set global PSOC object
371  * @psoc: pointer to psoc object
372  *
373  * Since request from userspace is not associated with any vdev/pdev/psoc, this
374  * API is used to set global psoc object.
375  *
376  * Return: none.
377  */
378 void wifi_pos_set_psoc(struct wlan_objmgr_psoc *psoc);
379 
380 /**
381  * wifi_pos_get_psoc: API to get global PSOC object
382  *
383  * Since request from userspace is not associated with any vdev/pdev/psoc, this
384  * API is used to get global psoc object.
385  * Return: global psoc object.
386  */
387 struct wlan_objmgr_psoc *wifi_pos_get_psoc(void);
388 
389 /**
390  * wifi_pos_clear_psoc: API to clear global PSOC object
391  *
392  * Return: none.
393  */
394 void wifi_pos_clear_psoc(void);
395 
396 /**
397  * wifi_pos_populate_caps: API to get OEM caps
398  * @psoc: psoc object
399  * @caps: capabilities buffer to populate
400  *
401  * Return: status of operation.
402  */
403 QDF_STATUS wifi_pos_populate_caps(struct wlan_objmgr_psoc *psoc,
404 				  struct wifi_pos_driver_caps *caps);
405 
406 /**
407  * wifi_pos_get_app_pid: returns oem app pid.
408  * @psoc: pointer to psoc object
409  *
410  * Return: oem app pid
411  */
412 uint32_t wifi_pos_get_app_pid(struct wlan_objmgr_psoc *psoc);
413 
414 /**
415  * wifi_pos_is_app_registered: indicates if oem app is registered.
416  * @psoc: pointer to psoc object
417  *
418  * Return: true if app is registered, false otherwise
419  */
420 bool wifi_pos_is_app_registered(struct wlan_objmgr_psoc *psoc);
421 
422 /**
423  * wifi_pos_get_vdev_priv_obj() - Get WIfi pos module vdev private
424  * object
425  * @vdev: vdev pointer
426  *
427  * Return: Pointer to vdev private obj
428  */
429 struct wifi_pos_vdev_priv_obj *
430 wifi_pos_get_vdev_priv_obj(struct wlan_objmgr_vdev *vdev);
431 
432 #endif /* _WIFI_POS_UTILS_H_ */
433 #endif /* WIFI_POS_CONVERGED */
434