1 /* 2 * Copyright (c) 2017-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 any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18 #ifndef _DP_IPA_H_ 19 #define _DP_IPA_H_ 20 21 #if defined(QCA_WIFI_KIWI) || defined(QCA_WIFI_KIWI_V2) 22 /* Index into soc->tcl_data_ring[] */ 23 #define IPA_TCL_DATA_RING_IDX 3 24 #else 25 #define IPA_TCL_DATA_RING_IDX 2 26 #endif 27 /* Index into soc->tx_comp_ring[] */ 28 #define IPA_TX_COMP_RING_IDX IPA_TCL_DATA_RING_IDX 29 30 #ifdef IPA_OFFLOAD 31 32 #define DP_IPA_MAX_IFACE 3 33 #define IPA_REO_DEST_RING_IDX 3 34 #define IPA_REO_DEST_RING_IDX_2 7 35 36 #define IPA_RX_REFILL_BUF_RING_IDX 2 37 38 #define IPA_ALT_REO_DEST_RING_IDX 2 39 #define IPA_RX_ALT_REFILL_BUF_RING_IDX 3 40 41 /* Adding delay before disabling ipa pipes if any Tx Completions are pending */ 42 #define TX_COMP_DRAIN_WAIT_MS 50 43 #define TX_COMP_DRAIN_WAIT_TIMEOUT_MS 100 44 45 #ifdef IPA_WDI3_TX_TWO_PIPES 46 #if defined(QCA_WIFI_KIWI) || defined(QCA_WIFI_KIWI_V2) 47 /* Index into soc->tcl_data_ring[] and soc->tx_comp_ring[] */ 48 #define IPA_TX_ALT_RING_IDX 4 49 #define IPA_TX_ALT_COMP_RING_IDX IPA_TX_ALT_RING_IDX 50 #else /* !KIWI */ 51 #define IPA_TX_ALT_RING_IDX 1 52 /* 53 * must be same as IPA_TX_ALT_RING_IDX as tcl and wbm ring 54 * are initialized with same index as a pair. 55 */ 56 #define IPA_TX_ALT_COMP_RING_IDX 1 57 #endif /* KIWI */ 58 59 #define IPA_SESSION_ID_SHIFT 1 60 #endif /* IPA_WDI3_TX_TWO_PIPES */ 61 62 /** 63 * struct dp_ipa_uc_tx_hdr - full tx header registered to IPA hardware 64 * @eth: ether II header 65 */ 66 struct dp_ipa_uc_tx_hdr { 67 struct ethhdr eth; 68 } __packed; 69 70 /** 71 * struct dp_ipa_uc_tx_hdr - full tx header registered to IPA hardware 72 * @eth: ether II header 73 */ 74 struct dp_ipa_uc_tx_vlan_hdr { 75 struct vlan_ethhdr eth; 76 } __packed; 77 78 /** 79 * struct dp_ipa_uc_rx_hdr - full rx header registered to IPA hardware 80 * @eth: ether II header 81 */ 82 struct dp_ipa_uc_rx_hdr { 83 struct ethhdr eth; 84 } __packed; 85 86 #define DP_IPA_UC_WLAN_TX_HDR_LEN sizeof(struct dp_ipa_uc_tx_hdr) 87 #define DP_IPA_UC_WLAN_TX_VLAN_HDR_LEN sizeof(struct dp_ipa_uc_tx_vlan_hdr) 88 #define DP_IPA_UC_WLAN_RX_HDR_LEN sizeof(struct dp_ipa_uc_rx_hdr) 89 /* 28 <bytes of rx_msdu_end_tlv> + 16 <bytes of attn tlv> + 90 * 52 <bytes of rx_mpdu_start_tlv> + <L2 Header> 91 */ 92 #define DP_IPA_UC_WLAN_RX_HDR_LEN_AST 110 93 #define DP_IPA_UC_WLAN_RX_HDR_LEN_AST_VLAN 114 94 #define DP_IPA_UC_WLAN_HDR_DES_MAC_OFFSET 0 95 96 #define DP_IPA_HDL_INVALID 0xFF 97 #define DP_IPA_HDL_FIRST 0 98 #define DP_IPA_HDL_SECOND 1 99 /** 100 * wlan_ipa_get_hdl() - Get ipa handle from IPA component 101 * @psoc - control psoc object 102 * @pdev_id - pdev id 103 * 104 * IPA componenet will return the IPA handle based on pdev_id 105 * 106 * Return: IPA handle 107 */ 108 qdf_ipa_wdi_hdl_t wlan_ipa_get_hdl(void *psoc, uint8_t pdev_id); 109 110 /** 111 * dp_ipa_get_resource() - Client request resource information 112 * @soc_hdl - data path soc handle 113 * @pdev_id - device instance id 114 * 115 * IPA client will request IPA UC related resource information 116 * Resource information will be distributed to IPA module 117 * All of the required resources should be pre-allocated 118 * 119 * Return: QDF_STATUS 120 */ 121 QDF_STATUS dp_ipa_get_resource(struct cdp_soc_t *soc_hdl, uint8_t pdev_id); 122 123 /** 124 * dp_ipa_set_doorbell_paddr () - Set doorbell register physical address to SRNG 125 * @soc_hdl - data path soc handle 126 * @pdev_id - device instance id 127 * 128 * Set TX_COMP_DOORBELL register physical address to WBM Head_Ptr_MemAddr_LSB 129 * Set RX_READ_DOORBELL register physical address to REO Head_Ptr_MemAddr_LSB 130 * 131 * Return: none 132 */ 133 QDF_STATUS dp_ipa_set_doorbell_paddr(struct cdp_soc_t *soc_hdl, 134 uint8_t pdev_id); 135 136 /** 137 * dp_ipa_iounmap_doorbell_vaddr() - unmap ipa RX db vaddr 138 * @soc_hdl - data path soc handle 139 * @pdev_id - device instance id 140 * 141 * Return: none 142 */ 143 QDF_STATUS dp_ipa_iounmap_doorbell_vaddr(struct cdp_soc_t *soc_hdl, 144 uint8_t pdev_id); 145 146 /** 147 * dp_ipa_op_response() - Handle OP command response from firmware 148 * @soc_hdl - data path soc handle 149 * @pdev_id - device instance id 150 * @op_msg: op response message from firmware 151 * 152 * Return: none 153 */ 154 QDF_STATUS dp_ipa_op_response(struct cdp_soc_t *soc_hdl, uint8_t pdev_id, 155 uint8_t *op_msg); 156 157 /** 158 * dp_ipa_register_op_cb() - Register OP handler function 159 * @soc_hdl - data path soc handle 160 * @pdev_id - device instance id 161 * @op_cb: handler function pointer 162 * 163 * Return: none 164 */ 165 QDF_STATUS dp_ipa_register_op_cb(struct cdp_soc_t *soc_hdl, uint8_t pdev_id, 166 ipa_uc_op_cb_type op_cb, void *usr_ctxt); 167 168 /** 169 * dp_ipa_register_op_cb() - Deregister OP handler function 170 * @soc_hdl - data path soc handle 171 * @pdev_id - device instance id 172 * 173 * Return: none 174 */ 175 void dp_ipa_deregister_op_cb(struct cdp_soc_t *soc_hdl, uint8_t pdev_id); 176 177 /** 178 * dp_ipa_get_stat() - Get firmware wdi status 179 * @soc_hdl - data path soc handle 180 * @pdev_id - device instance id 181 * 182 * Return: none 183 */ 184 QDF_STATUS dp_ipa_get_stat(struct cdp_soc_t *soc_hdl, uint8_t pdev_id); 185 186 /** 187 * dp_tx_send_ipa_data_frame() - send IPA data frame 188 * @soc_hdl: datapath soc handle 189 * @vdev_id: virtual device/interface id 190 * @skb: skb 191 * 192 * Return: skb/ NULL is for success 193 */ 194 qdf_nbuf_t dp_tx_send_ipa_data_frame(struct cdp_soc_t *soc_hdl, uint8_t vdev_id, 195 qdf_nbuf_t skb); 196 197 /** 198 * dp_ipa_enable_autonomy() – Enable autonomy RX path 199 * @soc_hdl - data path soc handle 200 * @pdev_id - device instance id 201 * 202 * Set all RX packet route to IPA REO ring 203 * Program Destination_Ring_Ctrl_IX_0 REO register to point IPA REO ring 204 * Return: none 205 */ 206 QDF_STATUS dp_ipa_enable_autonomy(struct cdp_soc_t *soc_hdl, uint8_t pdev_id); 207 208 /** 209 * dp_ipa_disable_autonomy() – Disable autonomy RX path 210 * @soc_hdl - data path soc handle 211 * @pdev_id - device instance id 212 * 213 * Disable RX packet routing to IPA REO 214 * Program Destination_Ring_Ctrl_IX_0 REO register to disable 215 * Return: none 216 */ 217 QDF_STATUS dp_ipa_disable_autonomy(struct cdp_soc_t *soc_hdl, uint8_t pdev_id); 218 219 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0)) || \ 220 defined(CONFIG_IPA_WDI_UNIFIED_API) 221 /** 222 * dp_ipa_setup() - Setup and connect IPA pipes 223 * @soc_hdl - data path soc handle 224 * @pdev_id - device instance id 225 * @ipa_i2w_cb: IPA to WLAN callback 226 * @ipa_w2i_cb: WLAN to IPA callback 227 * @ipa_wdi_meter_notifier_cb: IPA WDI metering callback 228 * @ipa_desc_size: IPA descriptor size 229 * @ipa_priv: handle to the HTT instance 230 * @is_rm_enabled: Is IPA RM enabled or not 231 * @tx_pipe_handle: pointer to Tx pipe handle 232 * @rx_pipe_handle: pointer to Rx pipe handle 233 * @is_smmu_enabled: Is SMMU enabled or not 234 * @sys_in: parameters to setup sys pipe in mcc mode 235 * @hdl: IPA handle 236 * @id: IPA instance id 237 * @ipa_ast_notify_cb: IPA to WLAN callback for ast create and update 238 * 239 * Return: QDF_STATUS 240 */ 241 QDF_STATUS dp_ipa_setup(struct cdp_soc_t *soc_hdl, uint8_t pdev_id, 242 void *ipa_i2w_cb, void *ipa_w2i_cb, 243 void *ipa_wdi_meter_notifier_cb, 244 uint32_t ipa_desc_size, void *ipa_priv, 245 bool is_rm_enabled, uint32_t *tx_pipe_handle, 246 uint32_t *rx_pipe_handle, 247 bool is_smmu_enabled, 248 qdf_ipa_sys_connect_params_t *sys_in, bool over_gsi, 249 qdf_ipa_wdi_hdl_t hdl, qdf_ipa_wdi_hdl_t id, 250 void *ipa_ast_notify_cb); 251 #else /* CONFIG_IPA_WDI_UNIFIED_API */ 252 /** 253 * dp_ipa_setup() - Setup and connect IPA pipes 254 * @soc_hdl - data path soc handle 255 * @pdev_id - device instance id 256 * @ipa_i2w_cb: IPA to WLAN callback 257 * @ipa_w2i_cb: WLAN to IPA callback 258 * @ipa_wdi_meter_notifier_cb: IPA WDI metering callback 259 * @ipa_desc_size: IPA descriptor size 260 * @ipa_priv: handle to the HTT instance 261 * @is_rm_enabled: Is IPA RM enabled or not 262 * @tx_pipe_handle: pointer to Tx pipe handle 263 * @rx_pipe_handle: pointer to Rx pipe handle 264 * @hdl: IPA handle 265 * 266 * Return: QDF_STATUS 267 */ 268 QDF_STATUS dp_ipa_setup(struct cdp_soc_t *soc_hdl, uint8_t pdev_id, 269 void *ipa_i2w_cb, void *ipa_w2i_cb, 270 void *ipa_wdi_meter_notifier_cb, 271 uint32_t ipa_desc_size, void *ipa_priv, 272 bool is_rm_enabled, uint32_t *tx_pipe_handle, 273 uint32_t *rx_pipe_handle); 274 #endif /* CONFIG_IPA_WDI_UNIFIED_API */ 275 QDF_STATUS dp_ipa_cleanup(struct cdp_soc_t *soc_hdl, uint8_t pdev_id, 276 uint32_t tx_pipe_handle, 277 uint32_t rx_pipe_handle, qdf_ipa_wdi_hdl_t hdl); 278 QDF_STATUS dp_ipa_setup_iface(char *ifname, uint8_t *mac_addr, 279 qdf_ipa_client_type_t prod_client, 280 qdf_ipa_client_type_t cons_client, 281 uint8_t session_id, bool is_ipv6_enabled, 282 qdf_ipa_wdi_hdl_t hdl); 283 QDF_STATUS dp_ipa_cleanup_iface(char *ifname, bool is_ipv6_enabled, 284 qdf_ipa_wdi_hdl_t hdl); 285 286 /** 287 * dp_ipa_uc_enable_pipes() - Enable and resume traffic on Tx/Rx pipes 288 * @soc_hdl - handle to the soc 289 * @pdev_id - pdev id number, to get the handle 290 * @hdl: IPA handle 291 * 292 * Return: QDF_STATUS 293 */ 294 QDF_STATUS dp_ipa_enable_pipes(struct cdp_soc_t *soc_hdl, uint8_t pdev_id, 295 qdf_ipa_wdi_hdl_t hdl); 296 297 /** 298 * dp_ipa_disable_pipes() – Suspend traffic and disable Tx/Rx pipes 299 * @soc_hdl - handle to the soc 300 * @pdev_id - pdev id number, to get the handle 301 * @hdl: IPA handle 302 * 303 * Return: QDF_STATUS 304 */ 305 QDF_STATUS dp_ipa_disable_pipes(struct cdp_soc_t *soc_hdl, uint8_t pdev_id, 306 qdf_ipa_wdi_hdl_t hdl); 307 QDF_STATUS dp_ipa_set_perf_level(int client, uint32_t max_supported_bw_mbps, 308 qdf_ipa_wdi_hdl_t hdl); 309 310 /** 311 * dp_ipa_rx_intrabss_fwd() - Perform intra-bss fwd for IPA RX path 312 * 313 * @soc_hdl: data path soc handle 314 * @vdev_id: virtual device/interface id 315 * @nbuf: pointer to skb of ethernet packet received from IPA RX path 316 * @fwd_success: pointer to indicate if skb succeeded in intra-bss TX 317 * 318 * This function performs intra-bss forwarding for WDI 3.0 IPA RX path. 319 * 320 * Return: true if packet is intra-bss fwd-ed and no need to pass to 321 * network stack. false if packet needs to be passed to network stack. 322 */ 323 bool dp_ipa_rx_intrabss_fwd(struct cdp_soc_t *soc_hdl, uint8_t vdev_id, 324 qdf_nbuf_t nbuf, bool *fwd_success); 325 int dp_ipa_uc_detach(struct dp_soc *soc, struct dp_pdev *pdev); 326 int dp_ipa_uc_attach(struct dp_soc *soc, struct dp_pdev *pdev); 327 int dp_ipa_ring_resource_setup(struct dp_soc *soc, 328 struct dp_pdev *pdev); 329 bool dp_reo_remap_config(struct dp_soc *soc, uint32_t *remap0, 330 uint32_t *remap1, uint32_t *remap2); 331 bool dp_ipa_is_mdm_platform(void); 332 333 qdf_nbuf_t dp_ipa_handle_rx_reo_reinject(struct dp_soc *soc, qdf_nbuf_t nbuf); 334 335 QDF_STATUS dp_ipa_handle_rx_buf_smmu_mapping(struct dp_soc *soc, 336 qdf_nbuf_t nbuf, 337 uint32_t size, 338 bool create, 339 const char *func, 340 uint32_t line); 341 342 /** 343 * dp_ipa_tx_buf_smmu_mapping() - Create SMMU mappings for IPA 344 * allocated TX buffers 345 * @soc_hdl: handle to the soc 346 * @pdev_id: pdev id number, to get the handle 347 * @func: caller function 348 * @line: line number 349 * 350 * Return: QDF_STATUS 351 */ 352 QDF_STATUS dp_ipa_tx_buf_smmu_mapping(struct cdp_soc_t *soc_hdl, 353 uint8_t pdev_id, const char *func, 354 uint32_t line); 355 356 /** 357 * dp_ipa_tx_buf_smmu_unmapping() - Release SMMU mappings for IPA 358 * allocated TX buffers 359 * @soc_hdl: handle to the soc 360 * @pdev_id: pdev id number, to get the handle 361 * @func: caller function 362 * @line: line number 363 * 364 * Return: QDF_STATUS 365 */ 366 QDF_STATUS dp_ipa_tx_buf_smmu_unmapping(struct cdp_soc_t *soc_hdl, 367 uint8_t pdev_id, const char *func, 368 uint32_t line); 369 370 #ifndef QCA_OL_DP_SRNG_LOCK_LESS_ACCESS 371 static inline void 372 dp_ipa_rx_buf_smmu_mapping_lock(struct dp_soc *soc) 373 { 374 if (soc->ipa_rx_buf_map_lock_initialized) 375 qdf_spin_lock_bh(&soc->ipa_rx_buf_map_lock); 376 } 377 378 static inline void 379 dp_ipa_rx_buf_smmu_mapping_unlock(struct dp_soc *soc) 380 { 381 if (soc->ipa_rx_buf_map_lock_initialized) 382 qdf_spin_unlock_bh(&soc->ipa_rx_buf_map_lock); 383 } 384 385 static inline void 386 dp_ipa_reo_ctx_buf_mapping_lock(struct dp_soc *soc, 387 uint32_t reo_ring_num) 388 { 389 if (!soc->ipa_reo_ctx_lock_required[reo_ring_num]) 390 return; 391 392 qdf_spin_lock_bh(&soc->ipa_rx_buf_map_lock); 393 } 394 395 static inline void 396 dp_ipa_reo_ctx_buf_mapping_unlock(struct dp_soc *soc, 397 uint32_t reo_ring_num) 398 { 399 if (!soc->ipa_reo_ctx_lock_required[reo_ring_num]) 400 return; 401 402 qdf_spin_unlock_bh(&soc->ipa_rx_buf_map_lock); 403 } 404 #else 405 406 static inline void 407 dp_ipa_rx_buf_smmu_mapping_lock(struct dp_soc *soc) 408 { 409 } 410 411 static inline void 412 dp_ipa_rx_buf_smmu_mapping_unlock(struct dp_soc *soc) 413 { 414 } 415 416 static inline void 417 dp_ipa_reo_ctx_buf_mapping_lock(struct dp_soc *soc, 418 uint32_t reo_ring_num) 419 { 420 } 421 422 static inline void 423 dp_ipa_reo_ctx_buf_mapping_unlock(struct dp_soc *soc, 424 uint32_t reo_ring_num) 425 { 426 } 427 #endif 428 429 #ifdef IPA_WDS_EASYMESH_FEATURE 430 /** 431 * dp_ipa_ast_create() - Create/update AST entry in AST table 432 * for learning/roaming packets from IPA 433 * @soc: data path soc handle 434 * @data: Structure used for updating the AST table 435 * 436 * Create/update AST entry in AST table for learning/roaming packets from IPA 437 * 438 * Return: QDF_STATUS 439 */ 440 QDF_STATUS dp_ipa_ast_create(struct cdp_soc_t *soc_hdl, 441 qdf_ipa_ast_info_type_t *data); 442 443 /** 444 * dp_ipa_ast_notify_cb() - Provide ast notify cb to IPA 445 * @pipe_in: WDI conn pipe in params 446 * @ipa_ast_notify_cb: ipa ast notify cb 447 * 448 * Return: None 449 */ 450 static inline void 451 dp_ipa_ast_notify_cb(qdf_ipa_wdi_conn_in_params_t *pipe_in, 452 void *ipa_ast_notify_cb) 453 { 454 QDF_IPA_WDI_CONN_IN_PARAMS_AST_NOTIFY(pipe_in) = ipa_ast_notify_cb; 455 } 456 #else 457 static inline void 458 dp_ipa_ast_notify_cb(qdf_ipa_wdi_conn_in_params_t *pipe_in, 459 void *ipa_ast_notify_cb) 460 { 461 } 462 #endif 463 464 #ifdef QCA_ENHANCED_STATS_SUPPORT 465 QDF_STATUS dp_ipa_txrx_get_peer_stats(struct cdp_soc_t *soc, uint8_t vdev_id, 466 uint8_t *peer_mac, 467 struct cdp_peer_stats *peer_stats); 468 int dp_ipa_txrx_get_vdev_stats(struct cdp_soc_t *soc_hdl, uint8_t vdev_id, 469 void *buf, bool is_aggregate); 470 QDF_STATUS dp_ipa_txrx_get_pdev_stats(struct cdp_soc_t *soc, uint8_t pdev_id, 471 struct cdp_pdev_stats *pdev_stats); 472 QDF_STATUS dp_ipa_update_peer_rx_stats(struct cdp_soc_t *soc, uint8_t pdev_id, 473 uint8_t *peer_mac, qdf_nbuf_t nbuf); 474 #endif 475 #else 476 static inline int dp_ipa_uc_detach(struct dp_soc *soc, struct dp_pdev *pdev) 477 { 478 return QDF_STATUS_SUCCESS; 479 } 480 481 static inline int dp_ipa_uc_attach(struct dp_soc *soc, struct dp_pdev *pdev) 482 { 483 return QDF_STATUS_SUCCESS; 484 } 485 486 static inline int dp_ipa_ring_resource_setup(struct dp_soc *soc, 487 struct dp_pdev *pdev) 488 { 489 return 0; 490 } 491 492 static inline QDF_STATUS dp_ipa_handle_rx_buf_smmu_mapping(struct dp_soc *soc, 493 qdf_nbuf_t nbuf, 494 uint32_t size, 495 bool create, 496 const char *func, 497 uint32_t line) 498 { 499 return QDF_STATUS_SUCCESS; 500 } 501 502 static inline void 503 dp_ipa_rx_buf_smmu_mapping_lock(struct dp_soc *soc) 504 { 505 } 506 507 static inline void 508 dp_ipa_rx_buf_smmu_mapping_unlock(struct dp_soc *soc) 509 { 510 } 511 512 static inline void 513 dp_ipa_reo_ctx_buf_mapping_lock(struct dp_soc *soc, 514 uint32_t reo_ring_num) 515 { 516 } 517 518 static inline void 519 dp_ipa_reo_ctx_buf_mapping_unlock(struct dp_soc *soc, 520 uint32_t reo_ring_num) 521 { 522 } 523 524 static inline qdf_nbuf_t dp_ipa_handle_rx_reo_reinject(struct dp_soc *soc, 525 qdf_nbuf_t nbuf) 526 { 527 return nbuf; 528 } 529 530 static inline QDF_STATUS dp_ipa_tx_buf_smmu_mapping(struct cdp_soc_t *soc_hdl, 531 uint8_t pdev_id, 532 const char *func, 533 uint32_t line) 534 { 535 return QDF_STATUS_SUCCESS; 536 } 537 538 static inline QDF_STATUS dp_ipa_tx_buf_smmu_unmapping(struct cdp_soc_t *soc_hdl, 539 uint8_t pdev_id, 540 const char *func, 541 uint32_t line) 542 { 543 return QDF_STATUS_SUCCESS; 544 } 545 546 #ifdef IPA_WDS_EASYMESH_FEATURE 547 static inline QDF_STATUS dp_ipa_ast_create(struct cdp_soc_t *soc_hdl, 548 qdf_ipa_ast_info_type_t *data) 549 { 550 return QDF_STATUS_SUCCESS; 551 } 552 #endif 553 554 #endif 555 #endif /* _DP_IPA_H_ */ 556