1 /* 2 * Copyright (c) 2012-2021 The Linux Foundation. All rights reserved. 3 * Copyright (c) 2021-2022 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 qdf_packed app_reg_rsp_vdev_info { 80 uint8_t dev_mode; 81 uint8_t vdev_id; 82 }; 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 qdf_packed wifi_app_reg_rsp { 91 uint8_t num_inf; 92 struct app_reg_rsp_vdev_info vdevs[1]; 93 }; 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 qdf_packed 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 }; 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 qdf_packed 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 }; 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 * @base_paddr_unaligned: base physical addr unaligned 195 * @base_vaddr_unaligned: base virtual addr unaligned 196 * @base_paddr_aligned: base physical addr aligned 197 * @base_vaddr_aligned: base virtual addr unaligned 198 * @head_idx_addr: head index addr 199 * @tail_idx_addr: tail index addr 200 * @srng: hal srng 201 */ 202 struct wifi_pos_dma_rings_cfg { 203 uint32_t pdev_id; 204 uint32_t num_ptr; 205 uint32_t ring_alloc_size; 206 void *base_paddr_unaligned; 207 void *base_vaddr_unaligned; 208 void *base_paddr_aligned; 209 void *base_vaddr_aligned; 210 void *head_idx_addr; 211 void *tail_idx_addr; 212 void *srng; 213 }; 214 215 typedef void (*wifi_pos_send_rsp_handler)(struct wlan_objmgr_psoc *, uint32_t, 216 enum wifi_pos_cmd_ids, 217 uint32_t, uint8_t *); 218 219 /** 220 * struct wifi_pos_legacy_ops - wifi pos module legacy callbacks 221 * @pasn_peer_create_cb: PASN peer create callback 222 * @pasn_peer_delete_cb: PASN peer delete callback 223 * @pasn_vdev_delete_resume_cb: PASN resume vdev delete callback 224 */ 225 struct wifi_pos_legacy_ops { 226 QDF_STATUS (*pasn_peer_create_cb)(struct wlan_objmgr_psoc *psoc, 227 struct qdf_mac_addr *peer_addr, 228 uint8_t vdev_id); 229 QDF_STATUS (*pasn_peer_delete_cb)(struct wlan_objmgr_psoc *psoc, 230 struct qdf_mac_addr *peer_addr, 231 uint8_t vdev_id, 232 bool no_fw_peer_delete); 233 QDF_STATUS (*pasn_vdev_delete_resume_cb)(struct wlan_objmgr_vdev *vdev); 234 }; 235 236 /** 237 * struct wifi_pos_psoc_priv_obj - psoc obj data for wifi_pos 238 * @app_pid: pid of app registered to host driver 239 * @is_app_registered: indicates if app is registered 240 * @fine_time_meas_cap: FTM cap for different roles, reflection of ini 241 * @ftm_rr: configured value of FTM Ranging Request capability 242 * @lci_capability: configured value of LCI capability 243 * @rsvd: reserved 244 * @oem_target_type 245 * @oem_target_type: oem target type, populated from HDD 246 * @oem_fw_version: firmware version, populated from HDD 247 * @driver_version: driver version, populated from HDD 248 * @allowed_dwell_time_min: allowed dwell time min, populated from HDD 249 * @allowed_dwell_time_max: allowed dwell time max, populated from HDD 250 * @current_dwell_time_min: current dwell time min, populated from HDD 251 * @current_dwell_time_max: current dwell time max, populated from HDD 252 * @hal_soc: hal_soc 253 * @num_rings: DMA ring cap requested by firmware 254 * @dma_cap: dma cap as read from service ready ext event 255 * @dma_cfg: DMA ring cfg to be programmed to firmware 256 * @dma_buf_pool: DMA buffer pools maintained at host: this will be 2-D array 257 * where with num_rows = number of rings num_elements in each row = ring depth 258 * @osif_cb: Callbacks to OS_IF 259 * @wifi_pos_lock: lock to access wifi pos priv object 260 * @oem_6g_support_disable: oem target 6ghz support is disabled if set 261 * @enable_rsta_secure_ltf_support: Enable RSTA secure LTF support 262 * @enable_rsta_11az_ranging: Enable RSTA 802.11 az secure ranging support 263 * @wifi_pos_req_handler: function pointer to handle TLV or non-TLV 264 * @wifi_pos_send_rsp: function pointer to send msg to userspace APP 265 * @wifi_pos_get_phy_mode: function pointer to get wlan phymode for given 266 * channel, channel width 267 * @wifi_pos_get_fw_phy_mode_for_freq: function pointer to get fw phymode 268 * for given freq and channel width 269 * @wifi_pos_send_action: function pointer to send registered action frames 270 * to userspace APP 271 * @wifi_pos_get_pdev_id_by_dev_name: get pdev_id from device name 272 * @wifi_pos_measurement_request_notification: Call this API when the driver 273 * receives measurement request 274 * from the LOWI application 275 * @legacy_ops: wifi pos legacy callbacks 276 * @rsp_version: rsp version 277 * 278 * wifi pos request messages 279 * <----- fine_time_meas_cap (in bits) -----> 280 *+----------+-----+-----+------+------+-------+-------+-----+-----+ 281 *| 8-31 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | 282 *+----------+-----+-----+------+------+-------+-------+-----+-----+ 283 *| reserved | SAP | SAP |P2P-GO|P2P-GO|P2P-CLI|P2P-CLI| STA | STA | 284 *| |resp |init |resp |init |resp |init |resp |init | 285 *+----------+-----+-----+------+------+-------+-------+-----+-----+ 286 * resp - responder role; init- initiator role 287 * @wifi_pos_get_max_fw_phymode_for_channels: function pointer to get max 288 * supported FW phymode for the given channels 289 * 290 */ 291 struct wifi_pos_psoc_priv_obj { 292 uint32_t app_pid; 293 bool is_app_registered; 294 uint32_t fine_time_meas_cap; 295 uint32_t ftm_rr:1; 296 uint32_t lci_capability:1; 297 uint32_t rsvd:30; 298 299 uint32_t oem_target_type; 300 uint32_t oem_fw_version; 301 struct wifi_pos_driver_version driver_version; 302 uint16_t allowed_dwell_time_min; 303 uint16_t allowed_dwell_time_max; 304 uint16_t current_dwell_time_min; 305 uint16_t current_dwell_time_max; 306 307 void *hal_soc; 308 uint8_t num_rings; 309 struct wifi_pos_dma_rings_cap *dma_cap; 310 struct wifi_pos_dma_rings_cfg *dma_cfg; 311 struct wifi_pos_dma_buf_info **dma_buf_pool; 312 313 struct wifi_pos_osif_ops *osif_cb; 314 315 qdf_spinlock_t wifi_pos_lock; 316 bool oem_6g_support_disable; 317 bool enable_rsta_secure_ltf_support; 318 bool enable_rsta_11az_ranging; 319 struct wifi_pos_legacy_ops *legacy_ops; 320 QDF_STATUS (*wifi_pos_req_handler)(struct wlan_objmgr_psoc *psoc, 321 struct wifi_pos_req_msg *req); 322 wifi_pos_send_rsp_handler wifi_pos_send_rsp; 323 void (*wifi_pos_get_phy_mode)(qdf_freq_t freq, uint32_t chan_width, 324 enum wlan_phymode *phy_mode); 325 void (*wifi_pos_get_fw_phy_mode_for_freq)(uint32_t, uint32_t, 326 uint32_t *); 327 void (*wifi_pos_send_action)(struct wlan_objmgr_psoc *psoc, 328 uint32_t oem_subtype, uint8_t *buf, 329 uint32_t len); 330 QDF_STATUS (*wifi_pos_get_pdev_id_by_dev_name)( 331 char *dev_name, uint8_t *pdev_id, 332 struct wlan_objmgr_psoc **psoc); 333 QDF_STATUS (*wifi_pos_measurement_request_notification)( 334 struct wlan_objmgr_pdev *pdev, 335 struct rtt_channel_info *chinfo); 336 uint32_t rsp_version; 337 QDF_STATUS (*wifi_pos_get_max_fw_phymode_for_channels)( 338 struct wlan_objmgr_pdev *pdev, 339 struct wifi_pos_channel_power *chan_list, 340 uint16_t wifi_pos_num_chans); 341 }; 342 343 /** 344 * wifi_pos_get_psoc_priv_obj: API to get wifi_psoc private object 345 * @psoc: pointer to psoc object 346 * 347 * Return: psoc private object on success, NULL otherwise 348 */ 349 struct wifi_pos_psoc_priv_obj *wifi_pos_get_psoc_priv_obj( 350 struct wlan_objmgr_psoc *psoc); 351 352 /** 353 * wifi_pos_lock_init: API to init lock used protect use of psoc global pointer 354 * variable 355 * 356 * Return: none. 357 */ 358 void wifi_pos_lock_init(void); 359 360 /** 361 * wifi_pos_lock_deinit: API to deinit lock used protect use of psoc global 362 * pointer variable 363 * 364 * Return: none. 365 */ 366 void wifi_pos_lock_deinit(void); 367 368 /** 369 * wifi_pos_set_psoc: API to set global PSOC object 370 * @psoc: pointer to psoc object 371 * 372 * Since request from userspace is not associated with any vdev/pdev/psoc, this 373 * API is used to set global psoc object. 374 * 375 * Return: none. 376 */ 377 void wifi_pos_set_psoc(struct wlan_objmgr_psoc *psoc); 378 379 /** 380 * wifi_pos_get_psoc: API to get global PSOC object 381 * 382 * Since request from userspace is not associated with any vdev/pdev/psoc, this 383 * API is used to get global psoc object. 384 * Return: global psoc object. 385 */ 386 struct wlan_objmgr_psoc *wifi_pos_get_psoc(void); 387 388 /** 389 * wifi_pos_get_psoc: API to clear global PSOC object 390 * 391 * Return: none. 392 */ 393 void wifi_pos_clear_psoc(void); 394 395 /** 396 * wifi_pos_populate_caps: API to get OEM caps 397 * @psoc: psoc object 398 * @caps: capabilities buffer to populate 399 * 400 * Return: status of operation. 401 */ 402 QDF_STATUS wifi_pos_populate_caps(struct wlan_objmgr_psoc *psoc, 403 struct wifi_pos_driver_caps *caps); 404 405 /** 406 * wifi_pos_get_app_pid: returns oem app pid. 407 * @psoc: pointer to psoc object 408 * 409 * Return: oem app pid 410 */ 411 uint32_t wifi_pos_get_app_pid(struct wlan_objmgr_psoc *psoc); 412 413 /** 414 * wifi_pos_is_app_registered: indicates if oem app is registered. 415 * @psoc: pointer to psoc object 416 * 417 * Return: true if app is registered, false otherwise 418 */ 419 bool wifi_pos_is_app_registered(struct wlan_objmgr_psoc *psoc); 420 421 /** 422 * wifi_pos_get_vdev_priv_obj() - Get WIfi pos module vdev private 423 * object 424 * @vdev: vdev pointer 425 * 426 * Return: Pointer to vdev private obj 427 */ 428 struct wifi_pos_vdev_priv_obj * 429 wifi_pos_get_vdev_priv_obj(struct wlan_objmgr_vdev *vdev); 430 431 #endif /* _WIFI_POS_UTILS_H_ */ 432 #endif /* WIFI_POS_CONVERGED */ 433