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_LEN 16 65 #define OEM_APP_SIGNATURE_STR "QUALCOMM-OEM-APP" 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 measurment 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 allignment 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 * @wifi_pos_req_handler: function pointer to handle TLV or non-TLV 262 * @wifi_pos_send_rsp: function pointer to send msg to userspace APP 263 * @wifi_pos_get_phy_mode: function pointer to get wlan phymode for given 264 * channel, channel width 265 * @wifi_pos_get_fw_phy_mode_for_freq: function pointer to get fw phymode 266 * for given freq and channel width 267 * @wifi_pos_send_action: function pointer to send registered action frames 268 * to userspace APP 269 * @wifi_pos_get_pdev_id_by_dev_name: get pdev_id from device name 270 * @wifi_pos_measurement_request_notification: Call this API when the driver 271 * receives measurement request 272 * from the LOWI application 273 * @legacy_ops: wifi pos legacy callbacks 274 * @rsp_version: rsp version 275 * 276 * wifi pos request messages 277 * <----- fine_time_meas_cap (in bits) -----> 278 *+----------+-----+-----+------+------+-------+-------+-----+-----+ 279 *| 8-31 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | 280 *+----------+-----+-----+------+------+-------+-------+-----+-----+ 281 *| reserved | SAP | SAP |P2P-GO|P2P-GO|P2P-CLI|P2P-CLI| STA | STA | 282 *| |resp |init |resp |init |resp |init |resp |init | 283 *+----------+-----+-----+------+------+-------+-------+-----+-----+ 284 * resp - responder role; init- initiator role 285 * @wifi_pos_get_max_fw_phymode_for_channels: function pointer to get max 286 * supported FW phymode for the given channels 287 * 288 */ 289 struct wifi_pos_psoc_priv_obj { 290 uint32_t app_pid; 291 bool is_app_registered; 292 uint32_t fine_time_meas_cap; 293 uint32_t ftm_rr:1; 294 uint32_t lci_capability:1; 295 uint32_t rsvd:30; 296 297 uint32_t oem_target_type; 298 uint32_t oem_fw_version; 299 struct wifi_pos_driver_version driver_version; 300 uint16_t allowed_dwell_time_min; 301 uint16_t allowed_dwell_time_max; 302 uint16_t current_dwell_time_min; 303 uint16_t current_dwell_time_max; 304 305 void *hal_soc; 306 uint8_t num_rings; 307 struct wifi_pos_dma_rings_cap *dma_cap; 308 struct wifi_pos_dma_rings_cfg *dma_cfg; 309 struct wifi_pos_dma_buf_info **dma_buf_pool; 310 311 struct wifi_pos_osif_ops *osif_cb; 312 313 qdf_spinlock_t wifi_pos_lock; 314 bool oem_6g_support_disable; 315 struct wifi_pos_legacy_ops *legacy_ops; 316 QDF_STATUS (*wifi_pos_req_handler)(struct wlan_objmgr_psoc *psoc, 317 struct wifi_pos_req_msg *req); 318 wifi_pos_send_rsp_handler wifi_pos_send_rsp; 319 void (*wifi_pos_get_phy_mode)(qdf_freq_t freq, uint32_t chan_width, 320 enum wlan_phymode *phy_mode); 321 void (*wifi_pos_get_fw_phy_mode_for_freq)(uint32_t, uint32_t, 322 uint32_t *); 323 void (*wifi_pos_send_action)(struct wlan_objmgr_psoc *psoc, 324 uint32_t oem_subtype, uint8_t *buf, 325 uint32_t len); 326 QDF_STATUS (*wifi_pos_get_pdev_id_by_dev_name)( 327 char *dev_name, uint8_t *pdev_id, 328 struct wlan_objmgr_psoc **psoc); 329 QDF_STATUS (*wifi_pos_measurement_request_notification)( 330 struct wlan_objmgr_pdev *pdev, 331 struct rtt_channel_info *chinfo); 332 uint32_t rsp_version; 333 QDF_STATUS (*wifi_pos_get_max_fw_phymode_for_channels)( 334 struct wlan_objmgr_pdev *pdev, 335 struct wifi_pos_channel_power *chan_list, 336 uint16_t wifi_pos_num_chans); 337 }; 338 339 /** 340 * wifi_pos_get_psoc_priv_obj: API to get wifi_psoc private object 341 * @psoc: pointer to psoc object 342 * 343 * Return: psoc private object on success, NULL otherwise 344 */ 345 struct wifi_pos_psoc_priv_obj *wifi_pos_get_psoc_priv_obj( 346 struct wlan_objmgr_psoc *psoc); 347 348 /** 349 * wifi_pos_lock_init: API to init lock used protect use of psoc global pointer 350 * variable 351 * 352 * Return: none. 353 */ 354 void wifi_pos_lock_init(void); 355 356 /** 357 * wifi_pos_lock_deinit: API to deinit lock used protect use of psoc global 358 * pointer variable 359 * 360 * Return: none. 361 */ 362 void wifi_pos_lock_deinit(void); 363 364 /** 365 * wifi_pos_set_psoc: API to set global PSOC object 366 * @psoc: pointer to psoc object 367 * 368 * Since request from userspace is not associated with any vdev/pdev/psoc, this 369 * API is used to set global psoc object. 370 * 371 * Return: none. 372 */ 373 void wifi_pos_set_psoc(struct wlan_objmgr_psoc *psoc); 374 375 /** 376 * wifi_pos_get_psoc: API to get global PSOC object 377 * 378 * Since request from userspace is not associated with any vdev/pdev/psoc, this 379 * API is used to get global psoc object. 380 * Return: global psoc object. 381 */ 382 struct wlan_objmgr_psoc *wifi_pos_get_psoc(void); 383 384 /** 385 * wifi_pos_get_psoc: API to clear global PSOC object 386 * 387 * Return: none. 388 */ 389 void wifi_pos_clear_psoc(void); 390 391 /** 392 * wifi_pos_populate_caps: API to get OEM caps 393 * @psoc: psoc object 394 * @caps: capabilities buffer to populate 395 * 396 * Return: status of operation. 397 */ 398 QDF_STATUS wifi_pos_populate_caps(struct wlan_objmgr_psoc *psoc, 399 struct wifi_pos_driver_caps *caps); 400 401 /** 402 * wifi_pos_get_app_pid: returns oem app pid. 403 * @psoc: pointer to psoc object 404 * 405 * Return: oem app pid 406 */ 407 uint32_t wifi_pos_get_app_pid(struct wlan_objmgr_psoc *psoc); 408 409 /** 410 * wifi_pos_is_app_registered: indicates if oem app is registered. 411 * @psoc: pointer to psoc object 412 * 413 * Return: true if app is registered, false otherwise 414 */ 415 bool wifi_pos_is_app_registered(struct wlan_objmgr_psoc *psoc); 416 417 /** 418 * wifi_pos_get_vdev_priv_obj() - Get WIfi pos module vdev private 419 * object 420 * @vdev: vdev pointer 421 * 422 * Return: Pointer to vdev private obj 423 */ 424 struct wifi_pos_vdev_priv_obj * 425 wifi_pos_get_vdev_priv_obj(struct wlan_objmgr_vdev *vdev); 426 427 #endif /* _WIFI_POS_UTILS_H_ */ 428 #endif /* WIFI_POS_CONVERGED */ 429