1 /* 2 * Copyright (c) 2013-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 /* Include Files */ 21 #include "wlan_ipa_core.h" 22 #include "wlan_ipa_main.h" 23 #include "cdp_txrx_ipa.h" 24 #include "cdp_txrx_ctrl.h" 25 #include "wal_rx_desc.h" 26 #include "qdf_str.h" 27 #include "host_diag_core_event.h" 28 #include "wlan_objmgr_vdev_obj.h" 29 #include "qdf_platform.h" 30 #include <wmi_unified_param.h> 31 #include <wlan_osif_priv.h> 32 #include <net/cfg80211.h> 33 #ifdef QCA_LL_TX_FLOW_CONTROL_V2 34 #include <cdp_txrx_flow_ctrl_v2.h> 35 #include <cdp_txrx_peer_ops.h> 36 #endif 37 #include <qal_vbus_dev.h> 38 39 #define IPA_SPS_DESC_SIZE 8 40 #define IPA_DEFAULT_HDL 0 41 #ifdef IPA_WDS_EASYMESH_FEATURE 42 #define IPA_TA_PEER_ID_ATTRI 2 43 #endif 44 45 static struct wlan_ipa_priv *gp_ipa; 46 static void wlan_ipa_set_pending_tx_timer(struct wlan_ipa_priv *ipa_ctx); 47 static void wlan_ipa_reset_pending_tx_timer(struct wlan_ipa_priv *ipa_ctx); 48 49 static inline 50 bool wlan_ipa_is_driver_unloading(struct wlan_ipa_priv *ipa_ctx) 51 { 52 if (ipa_ctx->driver_is_unloading) 53 return ipa_ctx->driver_is_unloading(); 54 return false; 55 } 56 57 static struct wlan_ipa_iface_2_client { 58 qdf_ipa_client_type_t cons_client; 59 qdf_ipa_client_type_t prod_client; 60 } wlan_ipa_iface_2_client[WLAN_IPA_CLIENT_MAX_IFACE] = { 61 { 62 QDF_IPA_CLIENT_WLAN2_CONS, QDF_IPA_CLIENT_WLAN1_PROD 63 }, 64 { 65 QDF_IPA_CLIENT_MCC2_CONS, QDF_IPA_CLIENT_WLAN1_PROD 66 }, 67 #if WLAN_IPA_CLIENT_MAX_IFACE >= 3 68 { 69 QDF_IPA_CLIENT_WLAN4_CONS, QDF_IPA_CLIENT_WLAN1_PROD 70 }, 71 #if WLAN_IPA_CLIENT_MAX_IFACE == 4 72 { 73 QDF_IPA_CLIENT_WLAN4_CONS, QDF_IPA_CLIENT_WLAN1_PROD 74 }, 75 #endif 76 #endif 77 }; 78 79 /* Local Function Prototypes */ 80 static void wlan_ipa_i2w_cb(void *priv, qdf_ipa_dp_evt_type_t evt, 81 unsigned long data); 82 static void wlan_ipa_w2i_cb(void *priv, qdf_ipa_dp_evt_type_t evt, 83 unsigned long data); 84 static void wlan_ipa_update_wds_params(struct wlan_ipa_priv *ipa_ctx, 85 qdf_ipa_wdi_init_in_params_t *in); 86 static void wlan_ipa_msg_wds_update(bool ipa_wds, qdf_ipa_wlan_msg_t *msg); 87 88 /** 89 * wlan_ipa_uc_sta_is_enabled() - Is STA mode IPA uC offload enabled? 90 * @ipa_cfg: IPA config 91 * 92 * Return: true if STA mode IPA uC offload is enabled, false otherwise 93 */ 94 static inline bool wlan_ipa_uc_sta_is_enabled(struct wlan_ipa_config *ipa_cfg) 95 { 96 return WLAN_IPA_IS_CONFIG_ENABLED(ipa_cfg, WLAN_IPA_UC_STA_ENABLE_MASK); 97 } 98 99 /** 100 * wlan_ipa_is_pre_filter_enabled() - Is IPA pre-filter enabled? 101 * @ipa_cfg: IPA config 102 * 103 * Return: true if pre-filter is enabled, otherwise false 104 */ 105 static inline 106 bool wlan_ipa_is_pre_filter_enabled(struct wlan_ipa_config *ipa_cfg) 107 { 108 return WLAN_IPA_IS_CONFIG_ENABLED(ipa_cfg, 109 WLAN_IPA_PRE_FILTER_ENABLE_MASK); 110 } 111 112 /** 113 * wlan_ipa_is_ipv6_enabled() - Is IPA IPv6 enabled? 114 * @ipa_cfg: IPA config 115 * 116 * Return: true if IPv6 is enabled, otherwise false 117 */ 118 static inline bool wlan_ipa_is_ipv6_enabled(struct wlan_ipa_config *ipa_cfg) 119 { 120 return WLAN_IPA_IS_CONFIG_ENABLED(ipa_cfg, WLAN_IPA_IPV6_ENABLE_MASK); 121 } 122 123 /** 124 * wlan_ipa_is_sta_only_offload_enabled() - Is IPA STA only offload enabled 125 * 126 * STA only IPA offload is needed on MDM platforms to support 127 * tethering scenarios in STA-SAP configurations when SAP is idle. 128 * 129 * Currently in STA-SAP configurations, IPA pipes are enabled only 130 * when a wifi client is connected to SAP. 131 * 132 * Impact of this API is only limited to when IPA pipes are enabled 133 * and disabled. To take effect, WLAN_IPA_UC_STA_ENABLE_MASK needs to 134 * set to 1. 135 * 136 * Return: true if MDM_PLATFORM is defined, false otherwise 137 */ 138 #ifdef MDM_PLATFORM 139 static inline bool wlan_ipa_is_sta_only_offload_enabled(void) 140 { 141 return true; 142 } 143 #else 144 static inline bool wlan_ipa_is_sta_only_offload_enabled(void) 145 { 146 return false; 147 } 148 #endif 149 150 /** 151 * wlan_ipa_msg_free_fn() - Free an IPA message 152 * @buff: pointer to the IPA message 153 * @len: length of the IPA message 154 * @type: type of IPA message 155 * 156 * Return: None 157 */ 158 static void wlan_ipa_msg_free_fn(void *buff, uint32_t len, uint32_t type) 159 { 160 ipa_debug("msg type:%d, len:%d", type, len); 161 qdf_mem_free(buff); 162 } 163 164 /** 165 * wlan_ipa_uc_loaded_uc_cb() - IPA UC loaded event callback 166 * @priv_ctxt: IPA context 167 * 168 * Will be called by IPA context. 169 * It's atomic context, then should be scheduled to kworker thread 170 * 171 * Return: None 172 */ 173 static void wlan_ipa_uc_loaded_uc_cb(void *priv_ctxt) 174 { 175 struct wlan_ipa_priv *ipa_ctx; 176 struct op_msg_type *msg; 177 struct uc_op_work_struct *uc_op_work; 178 179 if (!ipa_cb_is_ready()) { 180 ipa_info("IPA is not READY"); 181 return; 182 } 183 184 if (!priv_ctxt) { 185 ipa_err("Invalid IPA context"); 186 return; 187 } 188 189 ipa_ctx = priv_ctxt; 190 191 uc_op_work = &ipa_ctx->uc_op_work[WLAN_IPA_UC_OPCODE_UC_READY]; 192 if (!list_empty(&uc_op_work->work.work.entry)) { 193 /* uc_op_work is not initialized yet */ 194 ipa_ctx->uc_loaded = true; 195 return; 196 } 197 198 msg = qdf_mem_malloc(sizeof(*msg)); 199 if (!msg) 200 return; 201 202 msg->op_code = WLAN_IPA_UC_OPCODE_UC_READY; 203 204 /* When the same uC OPCODE is already pended, just return */ 205 if (uc_op_work->msg) 206 goto done; 207 208 uc_op_work->msg = msg; 209 210 if (!qdf_atomic_read(&ipa_ctx->deinit_in_prog)) { 211 qdf_sched_work(0, &uc_op_work->work); 212 } else { 213 uc_op_work->msg = NULL; 214 goto done; 215 } 216 217 /* work handler will free the msg buffer */ 218 return; 219 220 done: 221 qdf_mem_free(msg); 222 } 223 224 struct wlan_ipa_priv *wlan_ipa_get_obj_context(void) 225 { 226 return gp_ipa; 227 } 228 229 /** 230 * wlan_ipa_send_pkt_to_tl() - Send an IPA packet to TL 231 * @iface_context: interface-specific IPA context 232 * @ipa_tx_desc: packet data descriptor 233 * 234 * Return: None 235 */ 236 static void wlan_ipa_send_pkt_to_tl( 237 struct wlan_ipa_iface_context *iface_context, 238 qdf_ipa_rx_data_t *ipa_tx_desc) 239 { 240 struct wlan_ipa_priv *ipa_ctx = iface_context->ipa_ctx; 241 struct wlan_objmgr_pdev *pdev; 242 struct wlan_objmgr_psoc *psoc; 243 qdf_device_t osdev; 244 qdf_nbuf_t skb; 245 struct wlan_ipa_tx_desc *tx_desc; 246 qdf_dma_addr_t paddr; 247 QDF_STATUS status; 248 249 if (!ipa_ctx) 250 return; 251 pdev = ipa_ctx->pdev; 252 psoc = wlan_pdev_get_psoc(pdev); 253 osdev = wlan_psoc_get_qdf_dev(psoc); 254 255 qdf_spin_lock_bh(&iface_context->interface_lock); 256 /* 257 * During CAC period, data packets shouldn't be sent over the air so 258 * drop all the packets here 259 */ 260 if (iface_context->device_mode == QDF_SAP_MODE || 261 iface_context->device_mode == QDF_P2P_GO_MODE) { 262 if (ipa_ctx->dfs_cac_block_tx) { 263 ipa_free_skb(ipa_tx_desc); 264 qdf_spin_unlock_bh(&iface_context->interface_lock); 265 iface_context->stats.num_tx_cac_drop++; 266 wlan_ipa_wdi_rm_try_release(ipa_ctx); 267 return; 268 } 269 } 270 271 if (!osdev) { 272 ipa_free_skb(ipa_tx_desc); 273 iface_context->stats.num_tx_drop++; 274 qdf_spin_unlock_bh(&iface_context->interface_lock); 275 wlan_ipa_wdi_rm_try_release(ipa_ctx); 276 return; 277 } 278 qdf_spin_unlock_bh(&iface_context->interface_lock); 279 280 skb = QDF_IPA_RX_DATA_SKB(ipa_tx_desc); 281 282 qdf_mem_zero(skb->cb, sizeof(skb->cb)); 283 284 /* Store IPA Tx buffer ownership into SKB CB */ 285 qdf_nbuf_ipa_owned_set(skb); 286 287 if (qdf_mem_smmu_s1_enabled(osdev)) { 288 status = qdf_nbuf_map(osdev, skb, QDF_DMA_TO_DEVICE); 289 if (QDF_IS_STATUS_SUCCESS(status)) { 290 paddr = qdf_nbuf_get_frag_paddr(skb, 0); 291 } else { 292 ipa_free_skb(ipa_tx_desc); 293 qdf_spin_lock_bh(&iface_context->interface_lock); 294 iface_context->stats.num_tx_drop++; 295 qdf_spin_unlock_bh(&iface_context->interface_lock); 296 wlan_ipa_wdi_rm_try_release(ipa_ctx); 297 return; 298 } 299 } else { 300 paddr = QDF_IPA_RX_DATA_DMA_ADDR(ipa_tx_desc); 301 } 302 303 if (wlan_ipa_uc_sta_is_enabled(ipa_ctx->config)) { 304 qdf_nbuf_mapped_paddr_set(skb, 305 paddr + 306 WLAN_IPA_WLAN_FRAG_HEADER + 307 WLAN_IPA_WLAN_IPA_HEADER); 308 QDF_IPA_RX_DATA_SKB_LEN(ipa_tx_desc) -= 309 WLAN_IPA_WLAN_FRAG_HEADER + WLAN_IPA_WLAN_IPA_HEADER; 310 } else { 311 qdf_nbuf_mapped_paddr_set(skb, paddr); 312 } 313 314 qdf_spin_lock_bh(&ipa_ctx->q_lock); 315 /* get free Tx desc and assign ipa_tx_desc pointer */ 316 if (ipa_ctx->tx_desc_free_list.count && 317 qdf_list_remove_front(&ipa_ctx->tx_desc_free_list, 318 (qdf_list_node_t **)&tx_desc) == 319 QDF_STATUS_SUCCESS) { 320 tx_desc->ipa_tx_desc_ptr = ipa_tx_desc; 321 ipa_ctx->stats.num_tx_desc_q_cnt++; 322 qdf_spin_unlock_bh(&ipa_ctx->q_lock); 323 /* Store Tx Desc index into SKB CB */ 324 qdf_nbuf_ipa_priv_set(skb, tx_desc->id); 325 } else { 326 ipa_ctx->stats.num_tx_desc_error++; 327 qdf_spin_unlock_bh(&ipa_ctx->q_lock); 328 329 if (qdf_mem_smmu_s1_enabled(osdev)) { 330 if (wlan_ipa_uc_sta_is_enabled(ipa_ctx->config)) 331 qdf_nbuf_mapped_paddr_set(skb, paddr); 332 333 qdf_nbuf_unmap(osdev, skb, QDF_DMA_TO_DEVICE); 334 } 335 336 qdf_ipa_free_skb(ipa_tx_desc); 337 wlan_ipa_wdi_rm_try_release(ipa_ctx); 338 return; 339 } 340 341 skb = cdp_ipa_tx_send_data_frame(ipa_ctx->dp_soc, 342 iface_context->session_id, 343 QDF_IPA_RX_DATA_SKB(ipa_tx_desc)); 344 if (skb) { 345 qdf_nbuf_free(skb); 346 iface_context->stats.num_tx_err++; 347 return; 348 } 349 350 atomic_inc(&ipa_ctx->tx_ref_cnt); 351 352 iface_context->stats.num_tx++; 353 } 354 355 /** 356 * wlan_ipa_forward() - handle packet forwarding to wlan tx 357 * @ipa_ctx: pointer to ipa ipa context 358 * @iface_ctx: interface context 359 * @skb: data pointer 360 * 361 * if exception packet has set forward bit, copied new packet should be 362 * forwarded to wlan tx. if wlan subsystem is in suspend state, packet should 363 * put into pm queue and tx procedure will be differed 364 * 365 * Return: None 366 */ 367 static void wlan_ipa_forward(struct wlan_ipa_priv *ipa_ctx, 368 struct wlan_ipa_iface_context *iface_ctx, 369 qdf_nbuf_t skb) 370 { 371 struct wlan_ipa_pm_tx_cb *pm_tx_cb; 372 373 qdf_spin_lock_bh(&ipa_ctx->pm_lock); 374 375 /* Set IPA ownership for intra-BSS Tx packets to avoid skb_orphan */ 376 qdf_nbuf_ipa_owned_set(skb); 377 378 /* WLAN subsystem is in suspend, put in queue */ 379 if (ipa_ctx->suspended) { 380 qdf_spin_unlock_bh(&ipa_ctx->pm_lock); 381 ipa_info_rl("Tx in suspend, put in queue"); 382 qdf_mem_zero(skb->cb, sizeof(skb->cb)); 383 pm_tx_cb = (struct wlan_ipa_pm_tx_cb *)skb->cb; 384 pm_tx_cb->exception = true; 385 pm_tx_cb->iface_context = iface_ctx; 386 qdf_spin_lock_bh(&ipa_ctx->pm_lock); 387 qdf_nbuf_queue_add(&ipa_ctx->pm_queue_head, skb); 388 qdf_spin_unlock_bh(&ipa_ctx->pm_lock); 389 ipa_ctx->stats.num_tx_queued++; 390 } else { 391 /* Resume, put packet into WLAN TX */ 392 qdf_spin_unlock_bh(&ipa_ctx->pm_lock); 393 394 if (ipa_ctx->softap_xmit) { 395 if (ipa_ctx->softap_xmit(skb, iface_ctx->dev)) { 396 ipa_err_rl("packet Tx fail"); 397 ipa_ctx->stats.num_tx_fwd_err++; 398 } else { 399 ipa_ctx->stats.num_tx_fwd_ok++; 400 } 401 } else { 402 dev_kfree_skb_any(skb); 403 } 404 } 405 } 406 407 /** 408 * wlan_ipa_intrabss_forward() - Forward intra bss packets. 409 * @ipa_ctx: pointer to IPA IPA struct 410 * @iface_ctx: ipa interface context 411 * @desc: Firmware descriptor 412 * @skb: Data buffer 413 * 414 * Return: 415 * WLAN_IPA_FORWARD_PKT_NONE 416 * WLAN_IPA_FORWARD_PKT_DISCARD 417 * WLAN_IPA_FORWARD_PKT_LOCAL_STACK 418 * 419 */ 420 421 #ifndef QCA_IPA_LL_TX_FLOW_CONTROL 422 static inline 423 bool wlan_ipa_tx_desc_thresh_reached(struct cdp_soc_t *soc, uint8_t vdev_id) 424 { 425 return cdp_tx_desc_thresh_reached(soc, vdev_id); 426 } 427 428 static inline 429 bool wlan_ipa_get_peer_state(struct cdp_soc_t *soc, uint8_t vdev_id, 430 uint8_t *peer_mac) 431 { 432 if (cdp_peer_state_get(soc, vdev_id, peer_mac) == 433 OL_TXRX_PEER_STATE_AUTH) 434 return true; 435 436 return false; 437 } 438 #else 439 static inline 440 bool wlan_ipa_tx_desc_thresh_reached(struct cdp_soc_t *soc, uint8_t vdev_id) 441 { 442 return false; 443 } 444 445 static inline 446 bool wlan_ipa_get_peer_state(struct cdp_soc_t *soc, uint8_t vdev_id, 447 uint8_t *peer_mac) 448 { 449 return cdp_peer_get_authorize(soc, vdev_id, peer_mac); 450 } 451 #endif 452 453 static enum wlan_ipa_forward_type wlan_ipa_intrabss_forward( 454 struct wlan_ipa_priv *ipa_ctx, 455 struct wlan_ipa_iface_context *iface_ctx, 456 uint8_t desc, 457 qdf_nbuf_t skb) 458 { 459 int ret = WLAN_IPA_FORWARD_PKT_NONE; 460 void *soc = ipa_ctx->dp_soc; 461 462 if ((desc & FW_RX_DESC_FORWARD_M)) { 463 if (wlan_ipa_tx_desc_thresh_reached(soc, 464 iface_ctx->session_id)) { 465 /* Drop the packet*/ 466 ipa_ctx->stats.num_tx_fwd_err++; 467 goto drop_pkt; 468 } 469 470 ipa_debug_rl("Forward packet to Tx (fw_desc=%d)", desc); 471 ipa_ctx->ipa_tx_forward++; 472 473 if ((desc & FW_RX_DESC_DISCARD_M)) { 474 wlan_ipa_forward(ipa_ctx, iface_ctx, skb); 475 ipa_ctx->ipa_rx_internal_drop_count++; 476 ipa_ctx->ipa_rx_discard++; 477 ret = WLAN_IPA_FORWARD_PKT_DISCARD; 478 } else { 479 struct sk_buff *cloned_skb = skb_clone(skb, GFP_ATOMIC); 480 481 if (cloned_skb) 482 wlan_ipa_forward(ipa_ctx, iface_ctx, 483 cloned_skb); 484 else 485 ipa_err_rl("tx skb alloc failed"); 486 ret = WLAN_IPA_FORWARD_PKT_LOCAL_STACK; 487 } 488 } 489 return ret; 490 491 drop_pkt: 492 dev_kfree_skb_any(skb); 493 ret = WLAN_IPA_FORWARD_PKT_DISCARD; 494 return ret; 495 } 496 497 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0)) || \ 498 defined(CONFIG_IPA_WDI_UNIFIED_API) 499 /* 500 * TODO: Get WDI version through FW capabilities 501 */ 502 #if defined(QCA_WIFI_QCA6290) || defined(QCA_WIFI_QCA6390) || \ 503 defined(QCA_WIFI_QCA6490) || defined(QCA_WIFI_QCA6750) || \ 504 defined(QCA_WIFI_WCN7850) || defined(QCA_WIFI_QCN9000) 505 static inline void wlan_ipa_wdi_get_wdi_version(struct wlan_ipa_priv *ipa_ctx) 506 { 507 ipa_ctx->wdi_version = IPA_WDI_3; 508 } 509 #elif defined(QCA_WIFI_3_0) 510 static inline void wlan_ipa_wdi_get_wdi_version(struct wlan_ipa_priv *ipa_ctx) 511 { 512 ipa_ctx->wdi_version = IPA_WDI_2; 513 } 514 #else 515 static inline void wlan_ipa_wdi_get_wdi_version(struct wlan_ipa_priv *ipa_ctx) 516 { 517 ipa_ctx->wdi_version = IPA_WDI_1; 518 } 519 #endif 520 521 static inline bool wlan_ipa_wdi_is_smmu_enabled(struct wlan_ipa_priv *ipa_ctx, 522 qdf_device_t osdev) 523 { 524 return ipa_ctx->is_smmu_enabled && qdf_mem_smmu_s1_enabled(osdev); 525 } 526 527 #ifdef IPA_WDS_EASYMESH_FEATURE 528 /** 529 * wlan_ipa_ast_notify_cb() - IPA AST create/update CB 530 * @priv: IPA context 531 * @data: Structure used for updating the AST table 532 * 533 * Will be called by IPA context. 534 * 535 * Return: None 536 */ 537 static void wlan_ipa_ast_notify_cb(void *priv, void *data) 538 { 539 qdf_ipa_ast_info_type_t *ast_info; 540 struct wlan_ipa_priv *ipa_ctx; 541 542 if (!data) { 543 dp_err("Invalid IPA AST data context"); 544 return; 545 } 546 547 if (!priv) { 548 dp_err("Invalid IPA context"); 549 return; 550 } 551 552 ast_info = (qdf_ipa_ast_info_type_t *)data; 553 ipa_ctx = (struct wlan_ipa_priv *)priv; 554 555 cdp_ipa_ast_create(ipa_ctx->dp_soc, ast_info); 556 } 557 #else 558 static inline void wlan_ipa_ast_notify_cb(void *priv, void *data) 559 { 560 } 561 #endif 562 563 static inline QDF_STATUS 564 wlan_ipa_wdi_setup(struct wlan_ipa_priv *ipa_ctx, 565 qdf_device_t osdev) 566 { 567 qdf_ipa_sys_connect_params_t *sys_in = NULL; 568 int i; 569 QDF_STATUS qdf_status = QDF_STATUS_SUCCESS; 570 571 sys_in = qdf_mem_malloc(sizeof(*sys_in) * WLAN_IPA_MAX_IFACE); 572 if (!sys_in) 573 return QDF_STATUS_E_NOMEM; 574 575 for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) 576 qdf_mem_copy(sys_in + i, 577 &ipa_ctx->sys_pipe[i].ipa_sys_params, 578 sizeof(qdf_ipa_sys_connect_params_t)); 579 580 qdf_status = cdp_ipa_setup(ipa_ctx->dp_soc, ipa_ctx->dp_pdev_id, 581 wlan_ipa_i2w_cb, wlan_ipa_w2i_cb, 582 wlan_ipa_wdi_meter_notifier_cb, 583 ipa_ctx->config->desc_size, 584 ipa_ctx, 585 wlan_ipa_is_rm_enabled(ipa_ctx->config), 586 &ipa_ctx->tx_pipe_handle, 587 &ipa_ctx->rx_pipe_handle, 588 wlan_ipa_wdi_is_smmu_enabled(ipa_ctx, osdev), 589 sys_in, ipa_ctx->over_gsi, ipa_ctx->hdl, 590 (qdf_ipa_wdi_hdl_t)ipa_ctx->instance_id, 591 wlan_ipa_ast_notify_cb); 592 593 qdf_mem_free(sys_in); 594 595 return qdf_status; 596 } 597 598 #ifdef FEATURE_METERING 599 /** 600 * wlan_ipa_wdi_init_metering() - IPA WDI metering init 601 * @ipa_ctx: IPA context 602 * @in: IPA WDI in param 603 * 604 * Return: QDF_STATUS 605 */ 606 static inline void wlan_ipa_wdi_init_metering(struct wlan_ipa_priv *ipa_ctxt, 607 qdf_ipa_wdi_init_in_params_t *in) 608 { 609 QDF_IPA_WDI_INIT_IN_PARAMS_WDI_NOTIFY(in) = 610 wlan_ipa_wdi_meter_notifier_cb; 611 } 612 #else 613 static inline void wlan_ipa_wdi_init_metering(struct wlan_ipa_priv *ipa_ctxt, 614 qdf_ipa_wdi_init_in_params_t *in) 615 { 616 } 617 #endif 618 619 #ifdef IPA_WDS_EASYMESH_FEATURE 620 /** 621 * wlan_ipa_update_wds_params(); 622 * @ipa_ctx: IPA context 623 * @in: IPA wdi init in params 624 * 625 * This function is to update wds status to IPA in wdi init params 626 * 627 * Return: None 628 */ 629 static void wlan_ipa_update_wds_params(struct wlan_ipa_priv *ipa_ctx, 630 qdf_ipa_wdi_init_in_params_t *in) 631 { 632 QDF_IPA_WDI_INIT_IN_PARAMS_WDS_UPDATE(in) = ipa_ctx->config->ipa_wds; 633 } 634 635 /** 636 * wlan_ipa_msg_wds_update(); 637 * @ipa_wds: IPA WDS status 638 * @msg: Meta data message for IPA 639 * 640 * This function is to update wds status to IPA in meta message 641 * 642 * Return: None 643 */ 644 static void wlan_ipa_msg_wds_update(bool ipa_wds, 645 qdf_ipa_wlan_msg_t *msg) 646 { 647 QDF_IPA_WLAN_MSG_WDS_UPDATE(msg) = ipa_wds; 648 } 649 #else 650 static void wlan_ipa_update_wds_params(struct wlan_ipa_priv *ipa_ctx, 651 qdf_ipa_wdi_init_in_params_t *in) 652 { 653 } 654 655 static void wlan_ipa_msg_wds_update(bool ipa_wds, 656 qdf_ipa_wlan_msg_t *msg) 657 { 658 } 659 #endif 660 661 /** 662 * wlan_ipa_wdi_init() - IPA WDI init 663 * @ipa_ctx: IPA context 664 * 665 * Return: QDF_STATUS 666 */ 667 static inline QDF_STATUS wlan_ipa_wdi_init(struct wlan_ipa_priv *ipa_ctx) 668 { 669 qdf_ipa_wdi_init_in_params_t in; 670 qdf_ipa_wdi_init_out_params_t out; 671 int ret; 672 673 ipa_ctx->uc_loaded = false; 674 675 qdf_mem_zero(&in, sizeof(in)); 676 qdf_mem_zero(&out, sizeof(out)); 677 678 QDF_IPA_WDI_INIT_IN_PARAMS_WDI_VERSION(&in) = ipa_ctx->wdi_version; 679 QDF_IPA_WDI_INIT_IN_PARAMS_NOTIFY(&in) = wlan_ipa_uc_loaded_uc_cb; 680 QDF_IPA_WDI_INIT_IN_PARAMS_PRIV(&in) = ipa_ctx; 681 QDF_IPA_WDI_INIT_IN_PARAMS_INSTANCE_ID(&in) = ipa_ctx->instance_id; 682 wlan_ipa_update_wds_params(ipa_ctx, &in); 683 wlan_ipa_wdi_init_metering(ipa_ctx, &in); 684 ret = qdf_ipa_wdi_init(&in, &out); 685 if (ret) { 686 ipa_err("ipa_wdi_init failed with ret=%d", ret); 687 return QDF_STATUS_E_FAILURE; 688 } 689 690 ipa_ctx->over_gsi = 691 QDF_IPA_WDI_INIT_OUT_PARAMS_IS_OVER_GSI(&out); 692 ipa_ctx->is_smmu_enabled = 693 QDF_IPA_WDI_INIT_OUT_PARAMS_IS_SMMU_ENABLED(&out); 694 ipa_ctx->hdl = QDF_IPA_WDI_INIT_OUT_PARAMS_HANDLE(&out); 695 696 ipa_info("ipa_over_gsi: %d, is_smmu_enabled: %d, handle: %d", 697 ipa_ctx->over_gsi, ipa_ctx->is_smmu_enabled, ipa_ctx->hdl); 698 699 if (QDF_IPA_WDI_INIT_OUT_PARAMS_IS_UC_READY(&out)) { 700 ipa_debug("IPA uC READY"); 701 ipa_ctx->uc_loaded = true; 702 } else { 703 ipa_info("IPA uc not ready"); 704 return QDF_STATUS_E_BUSY; 705 } 706 707 return QDF_STATUS_SUCCESS; 708 } 709 710 static inline int wlan_ipa_wdi_cleanup(qdf_ipa_wdi_hdl_t hdl) 711 { 712 int ret; 713 714 ret = qdf_ipa_wdi_cleanup(hdl); 715 if (ret) 716 ipa_info("ipa_wdi_cleanup failed ret=%d", ret); 717 return ret; 718 } 719 720 static inline int wlan_ipa_wdi_setup_sys_pipe(struct wlan_ipa_priv *ipa_ctx, 721 struct ipa_sys_connect_params *sys, 722 uint32_t *handle) 723 { 724 return 0; 725 } 726 727 static inline int wlan_ipa_wdi_teardown_sys_pipe(struct wlan_ipa_priv *ipa_ctx, 728 uint32_t handle) 729 { 730 return 0; 731 } 732 733 /** 734 * wlan_ipa_pm_flush() - flush queued packets 735 * @work: pointer to the scheduled work 736 * 737 * Called during PM resume to send packets to TL which were queued 738 * while host was in the process of suspending. 739 * 740 * Return: None 741 */ 742 static void wlan_ipa_pm_flush(void *data) 743 { 744 struct wlan_ipa_priv *ipa_ctx = (struct wlan_ipa_priv *)data; 745 struct wlan_ipa_pm_tx_cb *pm_tx_cb = NULL; 746 qdf_nbuf_t skb; 747 uint32_t dequeued = 0; 748 749 qdf_spin_lock_bh(&ipa_ctx->pm_lock); 750 while (((skb = qdf_nbuf_queue_remove(&ipa_ctx->pm_queue_head)) != 751 NULL)) { 752 qdf_spin_unlock_bh(&ipa_ctx->pm_lock); 753 754 pm_tx_cb = (struct wlan_ipa_pm_tx_cb *)skb->cb; 755 dequeued++; 756 757 if (pm_tx_cb->exception) { 758 if (ipa_ctx->softap_xmit && 759 pm_tx_cb->iface_context->dev) { 760 ipa_ctx->softap_xmit(skb, 761 pm_tx_cb->iface_context->dev); 762 ipa_ctx->stats.num_tx_fwd_ok++; 763 } else { 764 dev_kfree_skb_any(skb); 765 } 766 } else { 767 wlan_ipa_send_pkt_to_tl(pm_tx_cb->iface_context, 768 pm_tx_cb->ipa_tx_desc); 769 } 770 771 qdf_spin_lock_bh(&ipa_ctx->pm_lock); 772 } 773 qdf_spin_unlock_bh(&ipa_ctx->pm_lock); 774 775 ipa_ctx->stats.num_tx_dequeued += dequeued; 776 if (dequeued > ipa_ctx->stats.num_max_pm_queue) 777 ipa_ctx->stats.num_max_pm_queue = dequeued; 778 } 779 780 int wlan_ipa_uc_smmu_map(bool map, uint32_t num_buf, qdf_mem_info_t *buf_arr) 781 { 782 if (!ipa_cb_is_ready()) { 783 ipa_info("IPA is not READY"); 784 return 0; 785 } 786 787 if (!num_buf) { 788 ipa_info("No buffers to map/unmap"); 789 return 0; 790 } 791 /** 792 * This API will compile for prelithium chipset 793 * where we have only one soc so passing default 794 * handle to IPA which is 0. 795 */ 796 if (map) 797 return qdf_ipa_wdi_create_smmu_mapping(IPA_DEFAULT_HDL, 798 num_buf, buf_arr); 799 else 800 return qdf_ipa_wdi_release_smmu_mapping(IPA_DEFAULT_HDL, 801 num_buf, buf_arr); 802 return 0; 803 } 804 805 #ifdef MDM_PLATFORM 806 /** 807 * is_rx_dest_bridge_dev() - is RX skb bridge device terminated 808 * @iface_ctx: pointer to WLAN IPA interface context 809 * @nbuf: skb buffer 810 * 811 * Check if skb is destined for bridge device, where SAP is a bridge 812 * port of it. 813 * 814 * FIXME: If there's a BH lockless API to check if destination MAC 815 * address is a valid peer, this check can be deleted. Currently 816 * dp_find_peer_by_addr() is used to check if destination MAC 817 * is a valid peer. Since WLAN IPA RX is in process context, 818 * qdf_spin_lock_bh in dp_find_peer_by_addr() turns to spin_lock_bh 819 * and this BH lock hurts netif_rx. 820 * 821 * Return: true/false 822 */ 823 static bool is_rx_dest_bridge_dev(struct wlan_ipa_iface_context *iface_ctx, 824 qdf_nbuf_t nbuf) 825 { 826 qdf_netdev_t master_ndev; 827 qdf_netdev_t ndev; 828 struct ethhdr *eh; 829 uint8_t da_is_bcmc; 830 bool ret; 831 832 /* 833 * WDI 3.0 skb->cb[] info from IPA driver 834 * skb->cb[0] = vdev_id 835 * skb->cb[1].bit#1 = da_is_bcmc 836 */ 837 da_is_bcmc = ((uint8_t)nbuf->cb[1]) & 0x2; 838 if (da_is_bcmc) 839 return false; 840 841 ndev = iface_ctx->dev; 842 if (!ndev) 843 return false; 844 845 if (!netif_is_bridge_port(ndev)) 846 return false; 847 848 qal_vbus_rcu_read_lock(); 849 850 master_ndev = netdev_master_upper_dev_get_rcu(ndev); 851 if (!master_ndev) { 852 ret = false; 853 goto out; 854 } 855 856 eh = (struct ethhdr *)qdf_nbuf_data(nbuf); 857 if (qdf_mem_cmp(eh->h_dest, master_ndev->dev_addr, QDF_MAC_ADDR_SIZE)) { 858 ret = false; 859 goto out; 860 } 861 862 ret = true; 863 864 out: 865 qal_vbus_rcu_read_unlock(); 866 return ret; 867 } 868 #else /* !MDM_PLATFORM */ 869 static bool is_rx_dest_bridge_dev(struct wlan_ipa_iface_context *iface_ctx, 870 qdf_nbuf_t nbuf) 871 { 872 return false; 873 } 874 #endif /* MDM_PLATFORM */ 875 876 static enum wlan_ipa_forward_type 877 wlan_ipa_rx_intrabss_fwd(struct wlan_ipa_priv *ipa_ctx, 878 struct wlan_ipa_iface_context *iface_ctx, 879 qdf_nbuf_t nbuf) 880 { 881 uint8_t fw_desc = 0; 882 bool fwd_success; 883 int ret; 884 885 /* legacy intra-bss fowarding for WDI 1.0 and 2.0 */ 886 if (ipa_ctx->wdi_version != IPA_WDI_3) { 887 fw_desc = (uint8_t)nbuf->cb[1]; 888 return wlan_ipa_intrabss_forward(ipa_ctx, iface_ctx, fw_desc, 889 nbuf); 890 } 891 892 if (is_rx_dest_bridge_dev(iface_ctx, nbuf)) { 893 fwd_success = 0; 894 ret = WLAN_IPA_FORWARD_PKT_LOCAL_STACK; 895 goto exit; 896 } 897 898 if (cdp_ipa_rx_intrabss_fwd(ipa_ctx->dp_soc, iface_ctx->session_id, 899 nbuf, &fwd_success)) { 900 ipa_ctx->ipa_rx_internal_drop_count++; 901 ipa_ctx->ipa_rx_discard++; 902 903 ret = WLAN_IPA_FORWARD_PKT_DISCARD; 904 } else { 905 ret = WLAN_IPA_FORWARD_PKT_LOCAL_STACK; 906 } 907 908 exit: 909 if (fwd_success) 910 ipa_ctx->stats.num_tx_fwd_ok++; 911 else 912 ipa_ctx->stats.num_tx_fwd_err++; 913 914 return ret; 915 } 916 917 #else /* CONFIG_IPA_WDI_UNIFIED_API */ 918 919 static inline void wlan_ipa_wdi_get_wdi_version(struct wlan_ipa_priv *ipa_ctx) 920 { 921 } 922 923 static inline int wlan_ipa_wdi_is_smmu_enabled(struct wlan_ipa_priv *ipa_ctx, 924 qdf_device_t osdev) 925 { 926 return qdf_mem_smmu_s1_enabled(osdev); 927 } 928 929 static inline QDF_STATUS wlan_ipa_wdi_setup(struct wlan_ipa_priv *ipa_ctx, 930 qdf_device_t osdev) 931 { 932 return cdp_ipa_setup(ipa_ctx->dp_soc, ipa_ctx->dp_pdev_id, 933 wlan_ipa_i2w_cb, wlan_ipa_w2i_cb, 934 wlan_ipa_wdi_meter_notifier_cb, 935 ipa_ctx->config->desc_size, 936 ipa_ctx, wlan_ipa_is_rm_enabled(ipa_ctx->config), 937 &ipa_ctx->tx_pipe_handle, 938 &ipa_ctx->rx_pipe_handle); 939 } 940 941 static inline QDF_STATUS wlan_ipa_wdi_init(struct wlan_ipa_priv *ipa_ctx) 942 { 943 struct ipa_wdi_uc_ready_params uc_ready_param; 944 945 ipa_ctx->uc_loaded = false; 946 uc_ready_param.priv = (void *)ipa_ctx; 947 uc_ready_param.notify = wlan_ipa_uc_loaded_uc_cb; 948 if (qdf_ipa_uc_reg_rdyCB(&uc_ready_param)) { 949 ipa_info("UC Ready CB register fail"); 950 return QDF_STATUS_E_FAILURE; 951 } 952 953 if (true == uc_ready_param.is_uC_ready) { 954 ipa_info("UC Ready"); 955 ipa_ctx->uc_loaded = true; 956 } else { 957 return QDF_STATUS_E_BUSY; 958 } 959 960 return QDF_STATUS_SUCCESS; 961 } 962 963 static inline int wlan_ipa_wdi_cleanup(void) 964 { 965 int ret; 966 967 ret = qdf_ipa_uc_dereg_rdyCB(); 968 if (ret) 969 ipa_info("UC Ready CB deregister fail"); 970 return ret; 971 } 972 973 static inline int wlan_ipa_wdi_setup_sys_pipe( 974 struct wlan_ipa_priv *ipa_ctx, 975 struct ipa_sys_connect_params *sys, uint32_t *handle) 976 { 977 return qdf_ipa_setup_sys_pipe(sys, handle); 978 } 979 980 static inline int wlan_ipa_wdi_teardown_sys_pipe( 981 struct wlan_ipa_priv *ipa_ctx, 982 uint32_t handle) 983 { 984 return qdf_ipa_teardown_sys_pipe(handle); 985 } 986 987 /** 988 * wlan_ipa_pm_flush() - flush queued packets 989 * @work: pointer to the scheduled work 990 * 991 * Called during PM resume to send packets to TL which were queued 992 * while host was in the process of suspending. 993 * 994 * Return: None 995 */ 996 static void wlan_ipa_pm_flush(void *data) 997 { 998 struct wlan_ipa_priv *ipa_ctx = (struct wlan_ipa_priv *)data; 999 struct wlan_ipa_pm_tx_cb *pm_tx_cb = NULL; 1000 qdf_nbuf_t skb; 1001 uint32_t dequeued = 0; 1002 1003 qdf_wake_lock_acquire(&ipa_ctx->wake_lock, 1004 WIFI_POWER_EVENT_WAKELOCK_IPA); 1005 qdf_spin_lock_bh(&ipa_ctx->pm_lock); 1006 while (((skb = qdf_nbuf_queue_remove(&ipa_ctx->pm_queue_head)) != 1007 NULL)) { 1008 qdf_spin_unlock_bh(&ipa_ctx->pm_lock); 1009 1010 pm_tx_cb = (struct wlan_ipa_pm_tx_cb *)skb->cb; 1011 dequeued++; 1012 1013 if (pm_tx_cb->exception) { 1014 if (ipa_ctx->softap_xmit && 1015 pm_tx_cb->iface_context->dev) { 1016 ipa_ctx->softap_xmit(skb, 1017 pm_tx_cb->iface_context->dev); 1018 ipa_ctx->stats.num_tx_fwd_ok++; 1019 } else { 1020 dev_kfree_skb_any(skb); 1021 } 1022 } else { 1023 wlan_ipa_send_pkt_to_tl(pm_tx_cb->iface_context, 1024 pm_tx_cb->ipa_tx_desc); 1025 } 1026 1027 qdf_spin_lock_bh(&ipa_ctx->pm_lock); 1028 } 1029 qdf_spin_unlock_bh(&ipa_ctx->pm_lock); 1030 qdf_wake_lock_release(&ipa_ctx->wake_lock, 1031 WIFI_POWER_EVENT_WAKELOCK_IPA); 1032 1033 ipa_ctx->stats.num_tx_dequeued += dequeued; 1034 if (dequeued > ipa_ctx->stats.num_max_pm_queue) 1035 ipa_ctx->stats.num_max_pm_queue = dequeued; 1036 } 1037 1038 int wlan_ipa_uc_smmu_map(bool map, uint32_t num_buf, qdf_mem_info_t *buf_arr) 1039 { 1040 if (!num_buf) { 1041 ipa_info("No buffers to map/unmap"); 1042 return 0; 1043 } 1044 1045 if (map) 1046 return qdf_ipa_wdi_create_smmu_mapping(IPA_DEFAULT_HDL, 1047 num_buf, buf_arr); 1048 else 1049 return qdf_ipa_wdi_release_smmu_mapping(IPA_DEFAULT_HDL, 1050 num_buf, buf_arr); 1051 return 0; 1052 } 1053 1054 static enum wlan_ipa_forward_type 1055 wlan_ipa_rx_intrabss_fwd(struct wlan_ipa_priv *ipa_ctx, 1056 struct wlan_ipa_iface_context *iface_ctx, 1057 qdf_nbuf_t nbuf) 1058 { 1059 uint8_t fw_desc; 1060 1061 fw_desc = (uint8_t)nbuf->cb[1]; 1062 1063 return wlan_ipa_intrabss_forward(ipa_ctx, iface_ctx, fw_desc, nbuf); 1064 } 1065 1066 #endif /* CONFIG_IPA_WDI_UNIFIED_API */ 1067 1068 /** 1069 * wlan_ipa_send_sta_eapol_to_nw() - Send Rx EAPOL pkt for STA to Kernel 1070 * @skb: network buffer 1071 * 1072 * Called when a EAPOL packet is received via IPA Exception path 1073 * before wlan_ipa_setup_iface is done for STA. 1074 * 1075 * Return: 0 on success, err_code for failure. 1076 */ 1077 static int wlan_ipa_send_sta_eapol_to_nw(qdf_nbuf_t skb, 1078 struct wlan_objmgr_pdev *pdev) 1079 { 1080 struct wlan_ipa_priv *ipa_ctx; 1081 struct ethhdr *eh; 1082 struct wlan_objmgr_vdev *vdev = NULL; 1083 1084 ipa_ctx = ipa_pdev_get_priv_obj(pdev); 1085 if (!ipa_ctx) 1086 return -EINVAL; 1087 1088 eh = (struct ethhdr *)qdf_nbuf_data(skb); 1089 vdev = wlan_objmgr_get_vdev_by_macaddr_from_pdev( 1090 pdev, eh->h_dest, WLAN_IPA_ID); 1091 if (!vdev) { 1092 ipa_err_rl("Invalid vdev"); 1093 return -EINVAL; 1094 } 1095 1096 if (wlan_vdev_mlme_get_opmode(vdev) != QDF_STA_MODE) { 1097 ipa_err_rl("device_mode is not STA"); 1098 wlan_objmgr_vdev_release_ref(vdev, WLAN_IPA_ID); 1099 return -EINVAL; 1100 } 1101 1102 skb->destructor = wlan_ipa_uc_rt_debug_destructor; 1103 1104 if (ipa_ctx->send_to_nw) 1105 ipa_ctx->send_to_nw(skb, vdev->vdev_nif.osdev->wdev->netdev); 1106 1107 ipa_ctx->ipa_rx_net_send_count++; 1108 ipa_ctx->stats.num_rx_no_iface_eapol++; 1109 wlan_objmgr_vdev_release_ref(vdev, WLAN_IPA_ID); 1110 return 0; 1111 } 1112 1113 /** 1114 * wlan_ipa_send_skb_to_network() - Send skb to kernel 1115 * @skb: network buffer 1116 * @iface_ctx: IPA interface context 1117 * 1118 * Called when a network buffer is received which should not be routed 1119 * to the IPA module. 1120 * 1121 * Return: None 1122 */ 1123 static void 1124 wlan_ipa_send_skb_to_network(qdf_nbuf_t skb, 1125 struct wlan_ipa_iface_context *iface_ctx) 1126 { 1127 struct wlan_ipa_priv *ipa_ctx; 1128 1129 ipa_ctx = iface_ctx->ipa_ctx; 1130 1131 if (!iface_ctx->dev) { 1132 ipa_debug_rl("Invalid interface"); 1133 ipa_ctx->ipa_rx_internal_drop_count++; 1134 dev_kfree_skb_any(skb); 1135 return; 1136 } 1137 1138 skb->destructor = wlan_ipa_uc_rt_debug_destructor; 1139 1140 if (ipa_ctx->send_to_nw) 1141 ipa_ctx->send_to_nw(skb, iface_ctx->dev); 1142 1143 ipa_ctx->ipa_rx_net_send_count++; 1144 } 1145 1146 /** 1147 * wlan_ipa_eapol_intrabss_fwd_check() - Check if eapol pkt intrabss fwd is 1148 * allowed or not 1149 * @ipa_ctx: IPA global context 1150 * @vdev_id: vdev id 1151 * @nbuf: network buffer 1152 * 1153 * Return: true if intrabss fwd is allowed for eapol else false 1154 */ 1155 static bool 1156 wlan_ipa_eapol_intrabss_fwd_check(struct wlan_ipa_priv *ipa_ctx, 1157 uint8_t vdev_id, qdf_nbuf_t nbuf) 1158 { 1159 uint8_t *vdev_mac_addr; 1160 1161 vdev_mac_addr = cdp_get_vdev_mac_addr(ipa_ctx->dp_soc, vdev_id); 1162 1163 if (!vdev_mac_addr) 1164 return false; 1165 1166 if (qdf_mem_cmp(qdf_nbuf_data(nbuf) + QDF_NBUF_DEST_MAC_OFFSET, 1167 vdev_mac_addr, QDF_MAC_ADDR_SIZE)) 1168 return false; 1169 1170 return true; 1171 } 1172 1173 #ifdef MDM_PLATFORM 1174 static inline void 1175 wlan_ipa_set_sap_client_auth(struct wlan_ipa_priv *ipa_ctx, uint8_t *peer_mac, 1176 uint8_t is_authenticated) 1177 { 1178 uint8_t idx; 1179 struct ipa_uc_stas_map *sta_map; 1180 1181 for (idx = 0; idx < WLAN_IPA_MAX_STA_COUNT; idx++) { 1182 sta_map = &ipa_ctx->assoc_stas_map[idx]; 1183 if (sta_map->is_reserved && 1184 qdf_is_macaddr_equal(&sta_map->mac_addr, 1185 (struct qdf_mac_addr *)peer_mac)) { 1186 sta_map->is_authenticated = is_authenticated; 1187 break; 1188 } 1189 } 1190 } 1191 1192 static inline uint8_t 1193 wlan_ipa_get_sap_client_auth(struct wlan_ipa_priv *ipa_ctx, uint8_t *peer_mac) 1194 { 1195 uint8_t idx; 1196 struct ipa_uc_stas_map *sta_map; 1197 1198 for (idx = 0; idx < WLAN_IPA_MAX_STA_COUNT; idx++) { 1199 sta_map = &ipa_ctx->assoc_stas_map[idx]; 1200 if (sta_map->is_reserved && 1201 qdf_is_macaddr_equal(&sta_map->mac_addr, 1202 (struct qdf_mac_addr *)peer_mac)) { 1203 return sta_map->is_authenticated; 1204 } 1205 } 1206 1207 return false; 1208 } 1209 1210 #ifdef IPA_WDS_EASYMESH_FEATURE 1211 static inline uint8_t 1212 wlan_ipa_get_peer_auth_state(ol_txrx_soc_handle dp_soc, uint8_t *peer_mac, 1213 struct wlan_ipa_iface_context *iface) 1214 { 1215 uint8_t is_authenticated = false; 1216 struct cdp_ast_entry_info ast_info = {0}; 1217 1218 if (ipa_is_wds_enabled()) { 1219 cdp_peer_get_ast_info_by_soc(dp_soc, peer_mac, 1220 &ast_info); 1221 peer_mac = &ast_info.peer_mac_addr[0]; 1222 is_authenticated = wlan_ipa_get_peer_state(dp_soc, 1223 iface->session_id, 1224 peer_mac); 1225 } else { 1226 is_authenticated = wlan_ipa_get_peer_state(dp_soc, 1227 iface->session_id, 1228 peer_mac); 1229 } 1230 1231 return is_authenticated; 1232 } 1233 #else 1234 static inline uint8_t 1235 wlan_ipa_get_peer_auth_state(ol_txrx_soc_handle dp_soc, uint8_t *peer_mac, 1236 struct wlan_ipa_iface_context *iface) 1237 { 1238 uint8_t is_authenticated = false; 1239 1240 is_authenticated = wlan_ipa_get_peer_state(dp_soc, iface->session_id, 1241 peer_mac); 1242 1243 return is_authenticated; 1244 } 1245 #endif 1246 1247 static inline bool 1248 wlan_ipa_is_peer_authenticated(ol_txrx_soc_handle dp_soc, 1249 struct wlan_ipa_iface_context *iface, 1250 uint8_t *peer_mac) 1251 { 1252 uint8_t is_authenticated = false; 1253 1254 if (iface->device_mode == QDF_SAP_MODE) { 1255 is_authenticated = wlan_ipa_get_sap_client_auth(iface->ipa_ctx, 1256 peer_mac); 1257 if (is_authenticated) 1258 return is_authenticated; 1259 1260 is_authenticated = wlan_ipa_get_peer_auth_state(dp_soc, 1261 peer_mac, 1262 iface); 1263 1264 if (is_authenticated) 1265 wlan_ipa_set_sap_client_auth(iface->ipa_ctx, 1266 peer_mac, 1267 true); 1268 1269 } else if (iface->device_mode == QDF_STA_MODE) { 1270 is_authenticated = iface->is_authenticated; 1271 if (is_authenticated) 1272 return is_authenticated; 1273 is_authenticated = wlan_ipa_get_peer_state(dp_soc, 1274 iface->session_id, 1275 peer_mac); 1276 if (is_authenticated) 1277 iface->is_authenticated = true; 1278 } 1279 1280 return is_authenticated; 1281 } 1282 #else /* !MDM_PLATFORM */ 1283 static inline void 1284 wlan_ipa_set_sap_client_auth(struct wlan_ipa_priv *ipa_ctx, uint8_t *peer_mac, 1285 uint8_t is_authenticated) 1286 {} 1287 1288 static inline bool 1289 wlan_ipa_is_peer_authenticated(ol_txrx_soc_handle dp_soc, 1290 struct wlan_ipa_iface_context *iface, 1291 uint8_t *peer_mac) 1292 { 1293 uint8_t is_authenticated = 0; 1294 1295 is_authenticated = wlan_ipa_get_peer_state(dp_soc, 1296 iface->session_id, 1297 peer_mac); 1298 1299 return is_authenticated; 1300 } 1301 #endif /* MDM_PLATFORM */ 1302 1303 /** 1304 * __wlan_ipa_w2i_cb() - WLAN to IPA callback handler 1305 * @priv: pointer to private data registered with IPA (we register a 1306 * pointer to the global IPA context) 1307 * @evt: the IPA event which triggered the callback 1308 * @data: data associated with the event 1309 * 1310 * Return: None 1311 */ 1312 static void __wlan_ipa_w2i_cb(void *priv, qdf_ipa_dp_evt_type_t evt, 1313 unsigned long data) 1314 { 1315 struct wlan_ipa_priv *ipa_ctx = NULL; 1316 qdf_nbuf_t skb; 1317 uint8_t iface_id; 1318 uint8_t session_id = 0xff; 1319 struct wlan_ipa_iface_context *iface_context; 1320 bool is_eapol_wapi = false; 1321 struct qdf_mac_addr peer_mac_addr = QDF_MAC_ADDR_ZERO_INIT; 1322 1323 ipa_ctx = (struct wlan_ipa_priv *)priv; 1324 if (!ipa_ctx) { 1325 if (evt == IPA_RECEIVE) { 1326 skb = (qdf_nbuf_t)data; 1327 dev_kfree_skb_any(skb); 1328 } 1329 return; 1330 } 1331 1332 switch (evt) { 1333 case IPA_RECEIVE: 1334 skb = (qdf_nbuf_t) data; 1335 if (wlan_ipa_uc_is_enabled(ipa_ctx->config)) { 1336 session_id = (uint8_t)skb->cb[0]; 1337 iface_id = ipa_ctx->vdev_to_iface[session_id]; 1338 ipa_ctx->stats.num_rx_excep++; 1339 qdf_nbuf_pull_head(skb, WLAN_IPA_UC_WLAN_CLD_HDR_LEN); 1340 } else { 1341 iface_id = WLAN_IPA_GET_IFACE_ID(skb->data); 1342 qdf_nbuf_pull_head(skb, WLAN_IPA_WLAN_CLD_HDR_LEN); 1343 } 1344 1345 if (iface_id >= WLAN_IPA_MAX_IFACE) { 1346 ipa_err_rl("Invalid iface_id %u,session_id %x %x %x %x", 1347 iface_id, session_id, (uint8_t)skb->cb[1], 1348 (uint8_t)skb->cb[2], (uint8_t)skb->cb[3]); 1349 1350 if (qdf_nbuf_is_ipv4_eapol_pkt(skb)) { 1351 ipa_err_rl("EAPOL pkt. Sending to NW!"); 1352 if (!wlan_ipa_send_sta_eapol_to_nw( 1353 skb, ipa_ctx->pdev)) 1354 break; 1355 } 1356 ipa_err_rl("Pkt Dropped!"); 1357 ipa_ctx->ipa_rx_internal_drop_count++; 1358 dev_kfree_skb_any(skb); 1359 return; 1360 } 1361 1362 iface_context = &ipa_ctx->iface_context[iface_id]; 1363 if (iface_context->session_id >= WLAN_IPA_MAX_SESSION) { 1364 ipa_err_rl("session_id of iface_id %u is invalid:%d", 1365 iface_id, iface_context->session_id); 1366 ipa_ctx->ipa_rx_internal_drop_count++; 1367 dev_kfree_skb_any(skb); 1368 return; 1369 } 1370 iface_context->stats.num_rx_ipa_excep++; 1371 1372 if (iface_context->device_mode == QDF_STA_MODE) 1373 qdf_copy_macaddr(&peer_mac_addr, &iface_context->bssid); 1374 else if (iface_context->device_mode == QDF_SAP_MODE) 1375 qdf_mem_copy(&peer_mac_addr.bytes[0], 1376 qdf_nbuf_data(skb) + 1377 QDF_NBUF_SRC_MAC_OFFSET, 1378 QDF_MAC_ADDR_SIZE); 1379 1380 if (qdf_nbuf_is_ipv4_eapol_pkt(skb)) { 1381 is_eapol_wapi = true; 1382 if (iface_context->device_mode == QDF_SAP_MODE && 1383 !wlan_ipa_eapol_intrabss_fwd_check(ipa_ctx, 1384 iface_context->session_id, skb)) { 1385 ipa_err_rl("EAPOL intrabss fwd drop DA:" QDF_MAC_ADDR_FMT, 1386 QDF_MAC_ADDR_REF(qdf_nbuf_data(skb) + 1387 QDF_NBUF_DEST_MAC_OFFSET)); 1388 ipa_ctx->ipa_rx_internal_drop_count++; 1389 dev_kfree_skb_any(skb); 1390 return; 1391 } 1392 } else if (qdf_nbuf_is_ipv4_wapi_pkt(skb)) { 1393 is_eapol_wapi = true; 1394 } 1395 1396 /* 1397 * Check for peer authorized state before allowing 1398 * non-EAPOL/WAPI frames to be intrabss forwarded 1399 * or submitted to stack. 1400 */ 1401 if (!wlan_ipa_is_peer_authenticated(ipa_ctx->dp_soc, 1402 iface_context, 1403 &peer_mac_addr.bytes[0]) && 1404 !is_eapol_wapi) { 1405 ipa_err_rl("Non EAPOL/WAPI packet received when peer " QDF_MAC_ADDR_FMT " is unauthorized", 1406 QDF_MAC_ADDR_REF(peer_mac_addr.bytes)); 1407 ipa_ctx->ipa_rx_internal_drop_count++; 1408 dev_kfree_skb_any(skb); 1409 return; 1410 } 1411 1412 /* Disable to forward Intra-BSS Rx packets when 1413 * ap_isolate=1 in hostapd.conf 1414 */ 1415 if (!ipa_ctx->disable_intrabss_fwd[iface_context->session_id] && 1416 iface_context->device_mode == QDF_SAP_MODE) { 1417 /* 1418 * When INTRA_BSS_FWD_OFFLOAD is enabled, FW will send 1419 * all Rx packets to IPA uC, which need to be forwarded 1420 * to other interface. 1421 * And, IPA driver will send back to WLAN host driver 1422 * through exception pipe with fw_desc field set by FW. 1423 * Here we are checking fw_desc field for FORWARD bit 1424 * set, and forward to Tx. Then copy to kernel stack 1425 * only when DISCARD bit is not set. 1426 */ 1427 if (WLAN_IPA_FORWARD_PKT_DISCARD == 1428 wlan_ipa_rx_intrabss_fwd(ipa_ctx, iface_context, 1429 skb)) 1430 break; 1431 } else { 1432 ipa_debug_rl("Intra-BSS fwd disabled for session_id %u", 1433 iface_context->session_id); 1434 } 1435 1436 wlan_ipa_send_skb_to_network(skb, iface_context); 1437 break; 1438 1439 default: 1440 ipa_err_rl("w2i cb wrong event: 0x%x", evt); 1441 return; 1442 } 1443 } 1444 1445 #ifndef MDM_PLATFORM 1446 /** 1447 * wlan_ipa_w2i_cb() - SSR wrapper for __wlan_ipa_w2i_cb 1448 * @priv: pointer to private data registered with IPA (we register a 1449 * pointer to the global IPA context) 1450 * @evt: the IPA event which triggered the callback 1451 * @data: data associated with the event 1452 * 1453 * Return: None 1454 */ 1455 static void wlan_ipa_w2i_cb(void *priv, qdf_ipa_dp_evt_type_t evt, 1456 unsigned long data) 1457 { 1458 struct qdf_op_sync *op_sync; 1459 1460 if (qdf_op_protect(&op_sync)) { 1461 if (evt == IPA_RECEIVE) { 1462 struct wlan_ipa_priv *ipa_ctx = priv; 1463 qdf_nbuf_t skb = (qdf_nbuf_t)data; 1464 1465 ipa_ctx->ipa_rx_internal_drop_count++; 1466 dev_kfree_skb_any(skb); 1467 } 1468 1469 return; 1470 } 1471 1472 __wlan_ipa_w2i_cb(priv, evt, data); 1473 1474 qdf_op_unprotect(op_sync); 1475 } 1476 #else /* MDM_PLATFORM */ 1477 static void wlan_ipa_w2i_cb(void *priv, qdf_ipa_dp_evt_type_t evt, 1478 unsigned long data) 1479 { 1480 __wlan_ipa_w2i_cb(priv, evt, data); 1481 } 1482 #endif /* MDM_PLATFORM */ 1483 1484 #if !defined(QCA_LL_TX_FLOW_CONTROL_V2) && !defined(QCA_IPA_LL_TX_FLOW_CONTROL) 1485 1486 /** 1487 * __wlan_ipa_i2w_cb() - IPA to WLAN callback 1488 * @priv: pointer to private data registered with IPA (we register a 1489 * pointer to the interface-specific IPA context) 1490 * @evt: the IPA event which triggered the callback 1491 * @data: data associated with the event 1492 * 1493 * Return: None 1494 */ 1495 static void __wlan_ipa_i2w_cb(void *priv, qdf_ipa_dp_evt_type_t evt, 1496 unsigned long data) 1497 { 1498 struct wlan_ipa_priv *ipa_ctx = NULL; 1499 qdf_ipa_rx_data_t *ipa_tx_desc; 1500 struct wlan_ipa_iface_context *iface_context; 1501 qdf_nbuf_t skb; 1502 struct wlan_ipa_pm_tx_cb *pm_tx_cb = NULL; 1503 1504 iface_context = (struct wlan_ipa_iface_context *)priv; 1505 ipa_tx_desc = (qdf_ipa_rx_data_t *)data; 1506 ipa_ctx = iface_context->ipa_ctx; 1507 1508 if (evt != IPA_RECEIVE) { 1509 ipa_err_rl("Event is not IPA_RECEIVE"); 1510 ipa_free_skb(ipa_tx_desc); 1511 iface_context->stats.num_tx_drop++; 1512 return; 1513 } 1514 1515 skb = QDF_IPA_RX_DATA_SKB(ipa_tx_desc); 1516 1517 /* 1518 * If PROD resource is not requested here then there may be cases where 1519 * IPA hardware may be clocked down because of not having proper 1520 * dependency graph between WLAN CONS and modem PROD pipes. Adding the 1521 * workaround to request PROD resource while data is going over CONS 1522 * pipe to prevent the IPA hardware clockdown. 1523 */ 1524 wlan_ipa_wdi_rm_request(ipa_ctx); 1525 1526 qdf_spin_lock_bh(&ipa_ctx->pm_lock); 1527 /* 1528 * If host is still suspended then queue the packets and these will be 1529 * drained later when resume completes. When packet is arrived here and 1530 * host is suspended, this means that there is already resume is in 1531 * progress. 1532 */ 1533 if (ipa_ctx->suspended) { 1534 qdf_mem_zero(skb->cb, sizeof(skb->cb)); 1535 pm_tx_cb = (struct wlan_ipa_pm_tx_cb *)skb->cb; 1536 pm_tx_cb->iface_context = iface_context; 1537 pm_tx_cb->ipa_tx_desc = ipa_tx_desc; 1538 qdf_nbuf_queue_add(&ipa_ctx->pm_queue_head, skb); 1539 ipa_ctx->stats.num_tx_queued++; 1540 1541 qdf_spin_unlock_bh(&ipa_ctx->pm_lock); 1542 return; 1543 } 1544 1545 qdf_spin_unlock_bh(&ipa_ctx->pm_lock); 1546 1547 /* 1548 * If we are here means, host is not suspended, wait for the work queue 1549 * to finish. 1550 */ 1551 qdf_flush_work(&ipa_ctx->pm_work); 1552 1553 return wlan_ipa_send_pkt_to_tl(iface_context, ipa_tx_desc); 1554 } 1555 1556 /** 1557 * wlan_ipa_i2w_cb() - IPA to WLAN callback 1558 * @priv: pointer to private data registered with IPA (we register a 1559 * pointer to the interface-specific IPA context) 1560 * @evt: the IPA event which triggered the callback 1561 * @data: data associated with the event 1562 * 1563 * Return: None 1564 */ 1565 static void wlan_ipa_i2w_cb(void *priv, qdf_ipa_dp_evt_type_t evt, 1566 unsigned long data) 1567 { 1568 struct qdf_op_sync *op_sync; 1569 1570 if (qdf_op_protect(&op_sync)) { 1571 qdf_ipa_rx_data_t *ipa_tx_desc = (qdf_ipa_rx_data_t *)data; 1572 struct wlan_ipa_iface_context *iface_context = priv; 1573 1574 ipa_free_skb(ipa_tx_desc); 1575 iface_context->stats.num_tx_drop++; 1576 1577 return; 1578 } 1579 1580 __wlan_ipa_i2w_cb(priv, evt, data); 1581 1582 qdf_op_unprotect(op_sync); 1583 } 1584 1585 #else /* QCA_LL_TX_FLOW_CONTROL_V2 */ 1586 1587 /** 1588 * wlan_ipa_i2w_cb() - IPA to WLAN callback 1589 * @priv: pointer to private data registered with IPA (we register a 1590 * pointer to the interface-specific IPA context) 1591 * @evt: the IPA event which triggered the callback 1592 * @data: data associated with the event 1593 * 1594 * Return: None 1595 */ 1596 static void wlan_ipa_i2w_cb(void *priv, qdf_ipa_dp_evt_type_t evt, 1597 unsigned long data) 1598 { 1599 } 1600 1601 #endif /* QCA_LL_TX_FLOW_CONTROL_V2 */ 1602 1603 QDF_STATUS wlan_ipa_suspend(struct wlan_ipa_priv *ipa_ctx) 1604 { 1605 /* 1606 * Check if IPA is ready for suspend, If we are here means, there is 1607 * high chance that suspend would go through but just to avoid any race 1608 * condition after suspend started, these checks are conducted before 1609 * allowing to suspend. 1610 */ 1611 if (atomic_read(&ipa_ctx->tx_ref_cnt)) 1612 return QDF_STATUS_E_AGAIN; 1613 1614 if (!wlan_ipa_is_rm_released(ipa_ctx)) 1615 return QDF_STATUS_E_AGAIN; 1616 1617 qdf_spin_lock_bh(&ipa_ctx->pm_lock); 1618 ipa_ctx->suspended = true; 1619 qdf_spin_unlock_bh(&ipa_ctx->pm_lock); 1620 1621 if (ipa_ctx->config->ipa_force_voting && 1622 !ipa_ctx->ipa_pipes_down) 1623 wlan_ipa_set_perf_level(ipa_ctx, 1624 ipa_ctx->config->bus_bw_high, 1625 ipa_ctx->config->bus_bw_high); 1626 1627 return QDF_STATUS_SUCCESS; 1628 } 1629 1630 QDF_STATUS wlan_ipa_resume(struct wlan_ipa_priv *ipa_ctx) 1631 { 1632 qdf_sched_work(0, &ipa_ctx->pm_work); 1633 1634 qdf_spin_lock_bh(&ipa_ctx->pm_lock); 1635 ipa_ctx->suspended = false; 1636 qdf_spin_unlock_bh(&ipa_ctx->pm_lock); 1637 1638 return QDF_STATUS_SUCCESS; 1639 } 1640 1641 QDF_STATUS wlan_ipa_uc_enable_pipes(struct wlan_ipa_priv *ipa_ctx) 1642 { 1643 int result; 1644 QDF_STATUS qdf_status = QDF_STATUS_SUCCESS; 1645 1646 ipa_debug("enter"); 1647 1648 qdf_spin_lock_bh(&ipa_ctx->enable_disable_lock); 1649 if (ipa_ctx->pipes_enable_in_progress) { 1650 ipa_warn("IPA Pipes Enable in progress"); 1651 qdf_spin_unlock_bh(&ipa_ctx->enable_disable_lock); 1652 return QDF_STATUS_E_ALREADY; 1653 } 1654 ipa_ctx->pipes_enable_in_progress = true; 1655 qdf_spin_unlock_bh(&ipa_ctx->enable_disable_lock); 1656 1657 if (qdf_atomic_read(&ipa_ctx->waiting_on_pending_tx)) 1658 wlan_ipa_reset_pending_tx_timer(ipa_ctx); 1659 1660 if (qdf_atomic_read(&ipa_ctx->pipes_disabled)) { 1661 result = cdp_ipa_enable_pipes(ipa_ctx->dp_soc, 1662 ipa_ctx->dp_pdev_id, 1663 ipa_ctx->hdl); 1664 if (result) { 1665 ipa_err("Enable IPA WDI PIPE failed: ret=%d", result); 1666 qdf_status = QDF_STATUS_E_FAILURE; 1667 goto end; 1668 } 1669 qdf_atomic_set(&ipa_ctx->pipes_disabled, 0); 1670 } 1671 1672 qdf_event_reset(&ipa_ctx->ipa_resource_comp); 1673 1674 if (qdf_atomic_read(&ipa_ctx->autonomy_disabled)) { 1675 cdp_ipa_enable_autonomy(ipa_ctx->dp_soc, 1676 ipa_ctx->dp_pdev_id); 1677 qdf_atomic_set(&ipa_ctx->autonomy_disabled, 0); 1678 } 1679 end: 1680 qdf_spin_lock_bh(&ipa_ctx->enable_disable_lock); 1681 if (!qdf_atomic_read(&ipa_ctx->autonomy_disabled) && 1682 !qdf_atomic_read(&ipa_ctx->pipes_disabled)) 1683 ipa_ctx->ipa_pipes_down = false; 1684 1685 ipa_ctx->pipes_enable_in_progress = false; 1686 qdf_spin_unlock_bh(&ipa_ctx->enable_disable_lock); 1687 1688 ipa_debug("exit: ipa_pipes_down=%d", ipa_ctx->ipa_pipes_down); 1689 return qdf_status; 1690 } 1691 1692 QDF_STATUS 1693 wlan_ipa_uc_disable_pipes(struct wlan_ipa_priv *ipa_ctx, bool force_disable) 1694 { 1695 QDF_STATUS qdf_status = QDF_STATUS_SUCCESS; 1696 1697 ipa_debug("enter: force_disable %u autonomy_disabled %u pipes_disabled %u", 1698 force_disable, 1699 qdf_atomic_read(&ipa_ctx->autonomy_disabled), 1700 qdf_atomic_read(&ipa_ctx->pipes_disabled)); 1701 1702 qdf_spin_lock_bh(&ipa_ctx->enable_disable_lock); 1703 if (ipa_ctx->ipa_pipes_down || ipa_ctx->pipes_down_in_progress) { 1704 qdf_spin_unlock_bh(&ipa_ctx->enable_disable_lock); 1705 ipa_info("IPA WDI Pipes are already deactivated"); 1706 return QDF_STATUS_E_ALREADY; 1707 } 1708 ipa_ctx->pipes_down_in_progress = true; 1709 qdf_spin_unlock_bh(&ipa_ctx->enable_disable_lock); 1710 1711 1712 if (!qdf_atomic_read(&ipa_ctx->autonomy_disabled)) { 1713 cdp_ipa_disable_autonomy(ipa_ctx->dp_soc, 1714 ipa_ctx->dp_pdev_id); 1715 qdf_atomic_set(&ipa_ctx->autonomy_disabled, 1); 1716 } 1717 1718 if (!qdf_atomic_read(&ipa_ctx->pipes_disabled)) { 1719 if (!force_disable) { 1720 wlan_ipa_set_pending_tx_timer(ipa_ctx); 1721 } else { 1722 qdf_status = cdp_ipa_disable_pipes(ipa_ctx->dp_soc, 1723 ipa_ctx->dp_pdev_id, 1724 ipa_ctx->hdl); 1725 if (QDF_IS_STATUS_ERROR(qdf_status)) { 1726 ipa_err("Disable IPA WDI PIPE failed: ret=%u", 1727 qdf_status); 1728 qdf_status = QDF_STATUS_E_FAILURE; 1729 goto end; 1730 } 1731 qdf_atomic_set(&ipa_ctx->pipes_disabled, 1); 1732 wlan_ipa_reset_pending_tx_timer(ipa_ctx); 1733 } 1734 } 1735 1736 end: 1737 qdf_spin_lock_bh(&ipa_ctx->enable_disable_lock); 1738 if (qdf_atomic_read(&ipa_ctx->pipes_disabled) && 1739 qdf_atomic_read(&ipa_ctx->autonomy_disabled)) { 1740 ipa_ctx->ipa_pipes_down = true; 1741 } 1742 ipa_ctx->pipes_down_in_progress = false; 1743 qdf_spin_unlock_bh(&ipa_ctx->enable_disable_lock); 1744 1745 ipa_debug("exit: ipa_pipes_down %u autonomy_disabled %u pipes_disabled %u", 1746 ipa_ctx->ipa_pipes_down, 1747 qdf_atomic_read(&ipa_ctx->autonomy_disabled), 1748 qdf_atomic_read(&ipa_ctx->pipes_disabled)); 1749 return qdf_status; 1750 } 1751 1752 /** 1753 * wlan_ipa_uc_find_add_assoc_sta() - Find associated station 1754 * @ipa_ctx: Global IPA IPA context 1755 * @sta_add: Should station be added 1756 * @mac_addr: mac address of station being queried 1757 * 1758 * Return: true if the station was found 1759 */ 1760 static bool wlan_ipa_uc_find_add_assoc_sta(struct wlan_ipa_priv *ipa_ctx, 1761 bool sta_add, 1762 uint8_t *mac_addr) 1763 { 1764 bool sta_found = false; 1765 uint8_t idx; 1766 1767 for (idx = 0; idx < WLAN_IPA_MAX_STA_COUNT; idx++) { 1768 if ((ipa_ctx->assoc_stas_map[idx].is_reserved) && 1769 (qdf_is_macaddr_equal( 1770 &ipa_ctx->assoc_stas_map[idx].mac_addr, 1771 (struct qdf_mac_addr *)mac_addr))) { 1772 sta_found = true; 1773 break; 1774 } 1775 } 1776 if (sta_add && sta_found) { 1777 ipa_err("STA already exist, cannot add: " QDF_MAC_ADDR_FMT, 1778 QDF_MAC_ADDR_REF(mac_addr)); 1779 return sta_found; 1780 } 1781 if (sta_add) { 1782 for (idx = 0; idx < WLAN_IPA_MAX_STA_COUNT; idx++) { 1783 if (!ipa_ctx->assoc_stas_map[idx].is_reserved) { 1784 ipa_ctx->assoc_stas_map[idx].is_reserved = true; 1785 qdf_mem_copy(&ipa_ctx->assoc_stas_map[idx]. 1786 mac_addr, mac_addr, 1787 QDF_NET_ETH_LEN); 1788 return sta_found; 1789 } 1790 } 1791 } 1792 if (!sta_add && !sta_found) { 1793 ipa_info("STA does not exist, cannot delete: " 1794 QDF_MAC_ADDR_FMT, QDF_MAC_ADDR_REF(mac_addr)); 1795 return sta_found; 1796 } 1797 if (!sta_add) { 1798 for (idx = 0; idx < WLAN_IPA_MAX_STA_COUNT; idx++) { 1799 if ((ipa_ctx->assoc_stas_map[idx].is_reserved) && 1800 (qdf_is_macaddr_equal( 1801 &ipa_ctx->assoc_stas_map[idx].mac_addr, 1802 (struct qdf_mac_addr *)mac_addr))) { 1803 ipa_ctx->assoc_stas_map[idx].is_reserved = 1804 false; 1805 qdf_mem_zero( 1806 &ipa_ctx->assoc_stas_map[idx].mac_addr, 1807 QDF_NET_ETH_LEN); 1808 return sta_found; 1809 } 1810 } 1811 } 1812 1813 return sta_found; 1814 } 1815 1816 /** 1817 * wlan_ipa_get_ifaceid() - Get IPA context interface ID 1818 * @ipa_ctx: IPA context 1819 * @session_id: Session ID 1820 * 1821 * Return: None 1822 */ 1823 static int wlan_ipa_get_ifaceid(struct wlan_ipa_priv *ipa_ctx, 1824 uint8_t session_id) 1825 { 1826 struct wlan_ipa_iface_context *iface_ctx; 1827 int i; 1828 1829 for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) { 1830 iface_ctx = &ipa_ctx->iface_context[i]; 1831 if (iface_ctx->session_id == session_id) 1832 break; 1833 } 1834 1835 return i; 1836 } 1837 1838 /** 1839 * wlan_ipa_cleanup_iface() - Cleanup IPA on a given interface 1840 * @iface_context: interface-specific IPA context 1841 * 1842 * Return: None 1843 */ 1844 static void wlan_ipa_cleanup_iface(struct wlan_ipa_iface_context *iface_context, 1845 uint8_t *mac_addr) 1846 { 1847 struct wlan_ipa_priv *ipa_ctx = iface_context->ipa_ctx; 1848 1849 ipa_debug("enter"); 1850 ipa_err("net:%pK mode:%d MAC:"QDF_MAC_ADDR_FMT" id:%d", 1851 iface_context->dev, iface_context->device_mode, 1852 QDF_MAC_ADDR_REF(mac_addr), iface_context->session_id); 1853 1854 if (iface_context->session_id == WLAN_IPA_MAX_SESSION) 1855 return; 1856 1857 if (mac_addr && qdf_mem_cmp(iface_context->mac_addr, 1858 mac_addr, QDF_MAC_ADDR_SIZE)) { 1859 ipa_err("MAC mismatch "QDF_MAC_ADDR_FMT":"QDF_MAC_ADDR_FMT"", 1860 QDF_MAC_ADDR_REF(mac_addr), 1861 QDF_MAC_ADDR_REF(iface_context->mac_addr)); 1862 } 1863 1864 if (cdp_ipa_cleanup_iface(ipa_ctx->dp_soc, 1865 iface_context->dev->name, 1866 wlan_ipa_is_ipv6_enabled(ipa_ctx->config), 1867 ipa_ctx->hdl)) { 1868 ipa_err("ipa_cleanup_iface failed"); 1869 } 1870 1871 if (iface_context->device_mode == QDF_SAP_MODE) 1872 ipa_ctx->num_sap_connected--; 1873 1874 qdf_spin_lock_bh(&iface_context->interface_lock); 1875 if (qdf_atomic_read(&iface_context->disconn_count) == 1876 qdf_atomic_read(&iface_context->conn_count) - 1) { 1877 qdf_atomic_inc(&iface_context->disconn_count); 1878 } else { 1879 ipa_err("connect/disconnect out of sync"); 1880 QDF_BUG(0); 1881 } 1882 1883 iface_context->is_authenticated = false; 1884 iface_context->dev = NULL; 1885 iface_context->device_mode = QDF_MAX_NO_OF_MODE; 1886 iface_context->session_id = WLAN_IPA_MAX_SESSION; 1887 qdf_mem_set(iface_context->mac_addr, QDF_MAC_ADDR_SIZE, 0); 1888 qdf_spin_unlock_bh(&iface_context->interface_lock); 1889 iface_context->ifa_address = 0; 1890 qdf_zero_macaddr(&iface_context->bssid); 1891 if (!iface_context->ipa_ctx->num_iface) { 1892 ipa_err("NUM INTF 0, Invalid"); 1893 QDF_ASSERT(0); 1894 } 1895 iface_context->ipa_ctx->num_iface--; 1896 ipa_debug("exit: num_iface=%d", iface_context->ipa_ctx->num_iface); 1897 } 1898 1899 #if !defined(QCA_LL_TX_FLOW_CONTROL_V2) && !defined(QCA_IPA_LL_TX_FLOW_CONTROL) 1900 1901 /** 1902 * wlan_ipa_nbuf_cb() - IPA TX complete callback 1903 * @skb: packet buffer which was transmitted 1904 * 1905 * Return: None 1906 */ 1907 static void wlan_ipa_nbuf_cb(qdf_nbuf_t skb) 1908 { 1909 struct wlan_ipa_priv *ipa_ctx = gp_ipa; 1910 qdf_ipa_rx_data_t *ipa_tx_desc; 1911 struct wlan_ipa_tx_desc *tx_desc; 1912 uint16_t id; 1913 struct wlan_objmgr_pdev *pdev; 1914 struct wlan_objmgr_psoc *psoc; 1915 qdf_device_t osdev; 1916 1917 if (!qdf_nbuf_ipa_owned_get(skb)) { 1918 dev_kfree_skb_any(skb); 1919 return; 1920 } 1921 1922 if (!ipa_ctx) 1923 return; 1924 pdev = ipa_ctx->pdev; 1925 psoc = wlan_pdev_get_psoc(pdev); 1926 osdev = wlan_psoc_get_qdf_dev(psoc); 1927 1928 if (osdev && qdf_mem_smmu_s1_enabled(osdev)) { 1929 if (wlan_ipa_uc_sta_is_enabled(ipa_ctx->config)) { 1930 qdf_dma_addr_t paddr = QDF_NBUF_CB_PADDR(skb); 1931 1932 qdf_nbuf_mapped_paddr_set(skb, 1933 paddr - 1934 WLAN_IPA_WLAN_FRAG_HEADER - 1935 WLAN_IPA_WLAN_IPA_HEADER); 1936 } 1937 1938 qdf_nbuf_unmap(osdev, skb, QDF_DMA_TO_DEVICE); 1939 } 1940 1941 /* Get Tx desc pointer from SKB CB */ 1942 id = qdf_nbuf_ipa_priv_get(skb); 1943 tx_desc = &ipa_ctx->tx_desc_pool[id]; 1944 ipa_tx_desc = tx_desc->ipa_tx_desc_ptr; 1945 1946 /* Return Tx Desc to IPA */ 1947 qdf_ipa_free_skb(ipa_tx_desc); 1948 1949 /* Return to free tx desc list */ 1950 qdf_spin_lock_bh(&ipa_ctx->q_lock); 1951 tx_desc->ipa_tx_desc_ptr = NULL; 1952 qdf_list_insert_back(&ipa_ctx->tx_desc_free_list, &tx_desc->node); 1953 ipa_ctx->stats.num_tx_desc_q_cnt--; 1954 qdf_spin_unlock_bh(&ipa_ctx->q_lock); 1955 1956 ipa_ctx->stats.num_tx_comp_cnt++; 1957 1958 qdf_atomic_dec(&ipa_ctx->tx_ref_cnt); 1959 1960 wlan_ipa_wdi_rm_try_release(ipa_ctx); 1961 } 1962 1963 #else /* QCA_LL_TX_FLOW_CONTROL_V2 */ 1964 1965 /** 1966 * wlan_ipa_nbuf_cb() - IPA TX complete callback 1967 * @skb: packet buffer which was transmitted 1968 * 1969 * Return: None 1970 */ 1971 static void wlan_ipa_nbuf_cb(qdf_nbuf_t skb) 1972 { 1973 dev_kfree_skb_any(skb); 1974 } 1975 1976 #endif /* QCA_LL_TX_FLOW_CONTROL_V2 */ 1977 1978 #ifdef IPA_WDI3_TX_TWO_PIPES 1979 #define WLAN_IPA_SESSION_ID_SHIFT 1 1980 static uint8_t wlan_ipa_set_session_id(uint8_t session_id, bool is_2g_iface) 1981 { 1982 return (session_id << WLAN_IPA_SESSION_ID_SHIFT) | is_2g_iface; 1983 } 1984 #else 1985 static uint8_t wlan_ipa_set_session_id(uint8_t session_id, bool is_2g_iface) 1986 { 1987 return session_id; 1988 } 1989 #endif 1990 1991 /** 1992 * wlan_ipa_setup_iface() - Setup IPA on a given interface 1993 * @ipa_ctx: IPA IPA global context 1994 * @net_dev: Interface net device 1995 * @device_mode: Net interface device mode 1996 * @adapter: Interface upon which IPA is being setup 1997 * @session_id: Station ID of the API instance 1998 * @mac_addr: MAC addr of the API instance 1999 * @is_2g_iface: true if Net interface is operating on 2G band, otherwise false 2000 * 2001 * Return: QDF STATUS 2002 */ 2003 static QDF_STATUS wlan_ipa_setup_iface(struct wlan_ipa_priv *ipa_ctx, 2004 qdf_netdev_t net_dev, 2005 uint8_t device_mode, 2006 uint8_t session_id, 2007 uint8_t *mac_addr, 2008 bool is_2g_iface) 2009 { 2010 struct wlan_ipa_iface_context *iface_context = NULL; 2011 int i; 2012 QDF_STATUS status; 2013 2014 ipa_err("net:%pK mode:%d MAC:"QDF_MAC_ADDR_FMT" id:%d", 2015 net_dev, device_mode, QDF_MAC_ADDR_REF(mac_addr), session_id); 2016 2017 for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) { 2018 iface_context = &(ipa_ctx->iface_context[i]); 2019 if (iface_context->dev == net_dev) { 2020 if (iface_context->device_mode == device_mode) { 2021 /** 2022 * Lower layer may send multiple START_BSS_EVENT 2023 * in DFS mode or during channel change. 2024 * Since these indications are sent by lower 2025 * layer as SAP updates and IPA doesn't have to 2026 * do anything for these updates so ignoring! 2027 */ 2028 if (device_mode == QDF_SAP_MODE) { 2029 ipa_debug("found iface %u device_mode %u", 2030 i, device_mode); 2031 return QDF_STATUS_SUCCESS; 2032 } else if (device_mode == QDF_STA_MODE && 2033 qdf_mem_cmp( 2034 iface_context->mac_addr, 2035 mac_addr, 2036 QDF_MAC_ADDR_SIZE) == 0) { 2037 ipa_err("same STA iface already connected"); 2038 } 2039 2040 } 2041 2042 ipa_err("Obsolete iface %u found, device_mode %u, will remove it.", 2043 i, iface_context->device_mode); 2044 wlan_ipa_cleanup_iface(iface_context, NULL); 2045 } else if (iface_context->session_id == session_id) { 2046 ipa_err("Obsolete iface %u found, net_dev %pK, will remove it.", 2047 i, iface_context->dev); 2048 wlan_ipa_cleanup_iface(iface_context, NULL); 2049 } 2050 } 2051 2052 if (WLAN_IPA_MAX_IFACE == ipa_ctx->num_iface) { 2053 ipa_err("Max interface reached %d", WLAN_IPA_MAX_IFACE); 2054 status = QDF_STATUS_E_NOMEM; 2055 iface_context = NULL; 2056 QDF_ASSERT(0); 2057 goto end; 2058 } 2059 2060 for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) { 2061 if (ipa_ctx->iface_context[i].session_id == 2062 WLAN_IPA_MAX_SESSION) { 2063 iface_context = &(ipa_ctx->iface_context[i]); 2064 break; 2065 } 2066 } 2067 2068 if (!iface_context) { 2069 ipa_err("All the IPA interfaces are in use"); 2070 status = QDF_STATUS_E_NOMEM; 2071 QDF_ASSERT(0); 2072 goto end; 2073 } 2074 2075 qdf_spin_lock_bh(&iface_context->interface_lock); 2076 if (qdf_atomic_read(&iface_context->conn_count) == 2077 qdf_atomic_read(&iface_context->disconn_count)) { 2078 qdf_atomic_inc(&iface_context->conn_count); 2079 } else { 2080 ipa_err("connect/disconnect out of sync"); 2081 QDF_BUG(0); 2082 } 2083 2084 iface_context->dev = net_dev; 2085 iface_context->device_mode = device_mode; 2086 iface_context->session_id = session_id; 2087 qdf_mem_copy(iface_context->mac_addr, mac_addr, QDF_MAC_ADDR_SIZE); 2088 qdf_spin_unlock_bh(&iface_context->interface_lock); 2089 2090 status = cdp_ipa_setup_iface(ipa_ctx->dp_soc, net_dev->name, 2091 net_dev->dev_addr, 2092 iface_context->prod_client, 2093 iface_context->cons_client, 2094 wlan_ipa_set_session_id(session_id, 2095 is_2g_iface), 2096 wlan_ipa_is_ipv6_enabled(ipa_ctx->config), 2097 ipa_ctx->hdl); 2098 if (status != QDF_STATUS_SUCCESS) 2099 goto end; 2100 2101 /* Register IPA Tx desc free callback */ 2102 qdf_nbuf_reg_free_cb(wlan_ipa_nbuf_cb); 2103 2104 ipa_ctx->num_iface++; 2105 2106 if (device_mode == QDF_SAP_MODE) 2107 ipa_ctx->num_sap_connected++; 2108 2109 ipa_debug("exit: num_iface=%d", ipa_ctx->num_iface); 2110 2111 return status; 2112 2113 end: 2114 if (iface_context) 2115 wlan_ipa_cleanup_iface(iface_context, mac_addr); 2116 2117 return status; 2118 } 2119 2120 #if defined(QCA_WIFI_QCA6290) || defined(QCA_WIFI_QCA6390) || \ 2121 defined(QCA_WIFI_QCA6490) || defined(QCA_WIFI_QCA6750) || \ 2122 defined(QCA_WIFI_WCN7850) || defined(QCA_WIFI_QCN9000) 2123 2124 #ifdef QCA_CONFIG_RPS 2125 void ipa_set_rps(struct wlan_ipa_priv *ipa_ctx, enum QDF_OPMODE mode, 2126 bool enable) 2127 { 2128 struct wlan_ipa_iface_context *iface_ctx; 2129 wlan_ipa_rps_enable cb = ipa_ctx->rps_enable; 2130 int i; 2131 2132 if (!cb) 2133 return; 2134 2135 for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) { 2136 iface_ctx = &ipa_ctx->iface_context[i]; 2137 if (iface_ctx->device_mode == mode) 2138 cb(iface_ctx->session_id, enable); 2139 } 2140 } 2141 #endif 2142 2143 #ifdef QCA_CONFIG_RPS 2144 /** 2145 * wlan_ipa_uc_handle_first_con() - Handle first uC IPA connection 2146 * @ipa_ctx: IPA context 2147 * 2148 * Return: QDF STATUS 2149 */ 2150 static QDF_STATUS wlan_ipa_uc_handle_first_con(struct wlan_ipa_priv *ipa_ctx) 2151 { 2152 ipa_debug("enter"); 2153 2154 if (qdf_ipa_get_lan_rx_napi() && (ipa_ctx->num_sap_connected > 1)) { 2155 ipa_debug("Multiple SAP connected. Not enabling pipes. Exit"); 2156 return QDF_STATUS_E_PERM; 2157 } 2158 2159 if (qdf_ipa_get_lan_rx_napi() && ipa_ctx->sta_connected) 2160 ipa_set_rps(ipa_ctx, QDF_STA_MODE, true); 2161 2162 if (wlan_ipa_uc_enable_pipes(ipa_ctx) != QDF_STATUS_SUCCESS) { 2163 ipa_err("IPA WDI Pipe activation failed"); 2164 return QDF_STATUS_E_BUSY; 2165 } 2166 2167 ipa_debug("exit"); 2168 2169 return QDF_STATUS_SUCCESS; 2170 } 2171 #else 2172 static QDF_STATUS wlan_ipa_uc_handle_first_con(struct wlan_ipa_priv *ipa_ctx) 2173 { 2174 ipa_debug("enter"); 2175 2176 if (wlan_ipa_uc_enable_pipes(ipa_ctx) != QDF_STATUS_SUCCESS) { 2177 ipa_err("IPA WDI Pipe activation failed"); 2178 return QDF_STATUS_E_BUSY; 2179 } 2180 2181 ipa_debug("exit"); 2182 2183 return QDF_STATUS_SUCCESS; 2184 } 2185 #endif 2186 2187 static 2188 void wlan_ipa_uc_handle_last_discon(struct wlan_ipa_priv *ipa_ctx, 2189 bool force_disable) 2190 { 2191 ipa_debug("enter"); 2192 2193 wlan_ipa_uc_disable_pipes(ipa_ctx, force_disable); 2194 2195 if (qdf_ipa_get_lan_rx_napi() && ipa_ctx->sta_connected) 2196 ipa_set_rps(ipa_ctx, QDF_STA_MODE, false); 2197 2198 ipa_debug("exit: IPA WDI Pipes deactivated"); 2199 } 2200 2201 bool wlan_ipa_is_fw_wdi_activated(struct wlan_ipa_priv *ipa_ctx) 2202 { 2203 return !ipa_ctx->ipa_pipes_down; 2204 } 2205 2206 /* Time(ms) to wait for pending TX comps after last SAP client disconnects */ 2207 #define WLAN_IPA_TX_PENDING_TIMEOUT_MS 15000 2208 2209 static void wlan_ipa_set_pending_tx_timer(struct wlan_ipa_priv *ipa_ctx) 2210 { 2211 ipa_ctx->pending_tx_start_ticks = qdf_system_ticks(); 2212 qdf_atomic_set(&ipa_ctx->waiting_on_pending_tx, 1); 2213 ipa_info("done. pending_tx_start_ticks %llu wait_on_pending %u", 2214 ipa_ctx->pending_tx_start_ticks, 2215 qdf_atomic_read(&ipa_ctx->waiting_on_pending_tx)); 2216 } 2217 2218 bool wlan_ipa_is_tx_pending(struct wlan_ipa_priv *ipa_ctx) 2219 { 2220 bool ret = false; 2221 uint64_t diff_ms = 0; 2222 uint64_t current_ticks = 0; 2223 2224 if (!ipa_ctx) { 2225 ipa_err("IPA private context is NULL"); 2226 return false; 2227 } 2228 2229 if (!qdf_atomic_read(&ipa_ctx->waiting_on_pending_tx)) { 2230 ipa_debug("nothing pending"); 2231 return false; 2232 } 2233 2234 current_ticks = qdf_system_ticks(); 2235 2236 diff_ms = qdf_system_ticks_to_msecs(current_ticks - 2237 ipa_ctx->pending_tx_start_ticks); 2238 2239 if (diff_ms < WLAN_IPA_TX_PENDING_TIMEOUT_MS) { 2240 ret = true; 2241 } else { 2242 ipa_debug("disabling pipes"); 2243 wlan_ipa_uc_disable_pipes(ipa_ctx, true); 2244 } 2245 2246 ipa_debug("diff_ms %llu pending_tx_start_ticks %llu current_ticks %llu wait_on_pending %u", 2247 diff_ms, ipa_ctx->pending_tx_start_ticks, current_ticks, 2248 qdf_atomic_read(&ipa_ctx->waiting_on_pending_tx)); 2249 2250 return ret; 2251 } 2252 2253 static void wlan_ipa_reset_pending_tx_timer(struct wlan_ipa_priv *ipa_ctx) 2254 { 2255 ipa_ctx->pending_tx_start_ticks = 0; 2256 qdf_atomic_set(&ipa_ctx->waiting_on_pending_tx, 0); 2257 ipa_info("done"); 2258 } 2259 2260 #else 2261 2262 /** 2263 * wlan_ipa_uc_handle_first_con() - Handle first uC IPA connection 2264 * @ipa_ctx: IPA context 2265 * 2266 * Return: QDF STATUS 2267 */ 2268 static QDF_STATUS wlan_ipa_uc_handle_first_con(struct wlan_ipa_priv *ipa_ctx) 2269 { 2270 ipa_debug("enter"); 2271 2272 ipa_ctx->activated_fw_pipe = 0; 2273 ipa_ctx->resource_loading = true; 2274 2275 /* If RM feature enabled 2276 * Request PROD Resource first 2277 * PROD resource may return sync or async manners 2278 */ 2279 if (wlan_ipa_is_rm_enabled(ipa_ctx->config)) { 2280 if (!wlan_ipa_wdi_rm_request_resource(ipa_ctx, 2281 IPA_RM_RESOURCE_WLAN_PROD)) { 2282 /* RM PROD request sync return 2283 * enable pipe immediately 2284 */ 2285 if (wlan_ipa_uc_enable_pipes(ipa_ctx)) { 2286 ipa_err("IPA WDI Pipe activation failed"); 2287 ipa_ctx->resource_loading = false; 2288 return QDF_STATUS_E_BUSY; 2289 } 2290 } else { 2291 ipa_err("IPA WDI Pipe activation deferred"); 2292 } 2293 } else { 2294 /* RM Disabled 2295 * Just enabled all the PIPEs 2296 */ 2297 if (wlan_ipa_uc_enable_pipes(ipa_ctx)) { 2298 ipa_err("IPA WDI Pipe activation failed"); 2299 ipa_ctx->resource_loading = false; 2300 return QDF_STATUS_E_BUSY; 2301 } 2302 ipa_ctx->resource_loading = false; 2303 } 2304 2305 ipa_debug("exit"); 2306 2307 return QDF_STATUS_SUCCESS; 2308 } 2309 2310 /** 2311 * wlan_ipa_uc_handle_last_discon() - Handle last uC IPA disconnection 2312 * @ipa_ctx: IPA context 2313 * @force_disable: force IPA pipes disablement 2314 * 2315 * Return: None 2316 */ 2317 static 2318 void wlan_ipa_uc_handle_last_discon(struct wlan_ipa_priv *ipa_ctx, 2319 bool force_disable) 2320 { 2321 ipa_debug("enter"); 2322 2323 ipa_ctx->resource_unloading = true; 2324 qdf_event_reset(&ipa_ctx->ipa_resource_comp); 2325 ipa_info("Disable FW RX PIPE"); 2326 cdp_ipa_set_active(ipa_ctx->dp_soc, ipa_ctx->dp_pdev_id, false, false); 2327 2328 ipa_debug("exit: IPA WDI Pipes deactivated"); 2329 } 2330 2331 bool wlan_ipa_is_fw_wdi_activated(struct wlan_ipa_priv *ipa_ctx) 2332 { 2333 return (WLAN_IPA_UC_NUM_WDI_PIPE == ipa_ctx->activated_fw_pipe); 2334 } 2335 2336 static inline 2337 void wlan_ipa_set_pending_tx_timer(struct wlan_ipa_priv *ipa_ctx) 2338 { 2339 } 2340 2341 bool wlan_ipa_is_tx_pending(struct wlan_ipa_priv *ipa_ctx) 2342 { 2343 return false; 2344 } 2345 2346 static inline 2347 void wlan_ipa_reset_pending_tx_timer(struct wlan_ipa_priv *ipa_ctx) 2348 { 2349 } 2350 2351 #endif 2352 2353 static inline 2354 bool wlan_sap_no_client_connected(struct wlan_ipa_priv *ipa_ctx) 2355 { 2356 return !(ipa_ctx->sap_num_connected_sta); 2357 } 2358 2359 static inline 2360 bool wlan_sta_is_connected(struct wlan_ipa_priv *ipa_ctx) 2361 { 2362 return ipa_ctx->sta_connected; 2363 } 2364 2365 static inline 2366 bool wlan_ipa_uc_is_loaded(struct wlan_ipa_priv *ipa_ctx) 2367 { 2368 return ipa_ctx->uc_loaded; 2369 } 2370 2371 #ifdef INTRA_BSS_FWD_OFFLOAD 2372 /** 2373 * wlan_ipa_intrabss_enable_disable() - wdi intrabss enable/disable notify to fw 2374 * @ipa_ctx: global IPA context 2375 * @offload_type: MCC or SCC 2376 * @session_id: Session Id 2377 * @enable: intrabss enable or disable 2378 * 2379 * Return: none 2380 */ 2381 static void wlan_ipa_intrabss_enable_disable(struct wlan_ipa_priv *ipa_ctx, 2382 uint8_t session_id, 2383 bool enable) 2384 { 2385 struct ipa_intrabss_control_params intrabss_req = {0}; 2386 uint32_t intra_bss_fwd = 0; 2387 2388 if (!enable || ipa_ctx->disable_intrabss_fwd[session_id]) { 2389 ipa_debug("%s: ipa_offload->enable=%d, rx_fwd_disabled=%d", 2390 __func__, enable, 2391 ipa_ctx->disable_intrabss_fwd[session_id]); 2392 intra_bss_fwd = 1; 2393 } 2394 2395 intrabss_req.vdev_id = session_id; 2396 intrabss_req.enable = intra_bss_fwd; 2397 2398 if (QDF_STATUS_SUCCESS != 2399 ipa_send_intrabss_enable_disable(ipa_ctx->pdev, &intrabss_req)) { 2400 ipa_err("intrabss offload vdev_id=%d, enable=%d failure", 2401 session_id, intra_bss_fwd); 2402 } 2403 } 2404 #else 2405 static inline 2406 void wlan_ipa_intrabss_enable_disable(struct wlan_ipa_priv *ipa_ctx, 2407 uint8_t session_id, 2408 bool enable) 2409 {} 2410 #endif 2411 2412 /** 2413 * wlan_ipa_uc_offload_enable_disable() - wdi enable/disable notify to fw 2414 * @ipa_ctx: global IPA context 2415 * @offload_type: MCC or SCC 2416 * @session_id: Session Id 2417 * @enable: TX offload enable or disable 2418 * 2419 * Return: none 2420 */ 2421 static void wlan_ipa_uc_offload_enable_disable(struct wlan_ipa_priv *ipa_ctx, 2422 uint32_t offload_type, 2423 uint8_t session_id, 2424 bool enable) 2425 { 2426 2427 struct ipa_uc_offload_control_params req = {0}; 2428 2429 if (session_id >= WLAN_IPA_MAX_SESSION) { 2430 ipa_err("invalid session id: %d", session_id); 2431 return; 2432 } 2433 2434 if (enable == ipa_ctx->vdev_offload_enabled[session_id]) { 2435 ipa_info("IPA offload status is already set"); 2436 ipa_info("offload_type=%d, vdev_id=%d, enable=%d", 2437 offload_type, session_id, enable); 2438 return; 2439 } 2440 2441 ipa_info("offload_type=%d, session_id=%d, enable=%d", 2442 offload_type, session_id, enable); 2443 2444 req.offload_type = offload_type; 2445 req.vdev_id = session_id; 2446 req.enable = enable; 2447 2448 if (QDF_STATUS_SUCCESS != 2449 ipa_send_uc_offload_enable_disable(ipa_ctx->pdev, &req)) { 2450 ipa_err("Fail to enable IPA offload"); 2451 ipa_err("offload type=%d, vdev_id=%d, enable=%d", 2452 offload_type, session_id, enable); 2453 } else { 2454 ipa_ctx->vdev_offload_enabled[session_id] = enable; 2455 } 2456 2457 wlan_ipa_intrabss_enable_disable(ipa_ctx, session_id, enable); 2458 } 2459 2460 #ifdef WDI3_STATS_BW_MONITOR 2461 static void wlan_ipa_uc_bw_monitor(struct wlan_ipa_priv *ipa_ctx, bool stop) 2462 { 2463 qdf_ipa_wdi_bw_info_t bw_info; 2464 uint32_t bw_low = ipa_ctx->config->ipa_bw_low; 2465 uint32_t bw_medium = ipa_ctx->config->ipa_bw_medium; 2466 uint32_t bw_high = ipa_ctx->config->ipa_bw_high; 2467 int ret; 2468 2469 bw_info.num = WLAN_IPA_UC_BW_MONITOR_LEVEL; 2470 /* IPA uc will mobitor three bw levels for wlan client */ 2471 QDF_IPA_WDI_BW_INFO_THRESHOLD_LEVEL_1(&bw_info) = bw_low; 2472 QDF_IPA_WDI_BW_INFO_THRESHOLD_LEVEL_2(&bw_info) = bw_medium; 2473 QDF_IPA_WDI_BW_INFO_THRESHOLD_LEVEL_3(&bw_info) = bw_high; 2474 QDF_IPA_WDI_BW_INFO_START_STOP(&bw_info) = stop; 2475 2476 ret = qdf_ipa_uc_bw_monitor(&bw_info); 2477 if (ret) 2478 ipa_err("ipa uc bw monitor fails"); 2479 2480 if (!stop) { 2481 cdp_ipa_set_perf_level(ipa_ctx->dp_soc, 2482 QDF_IPA_CLIENT_WLAN2_CONS, 2483 ipa_ctx->config->ipa_bw_low); 2484 ipa_ctx->curr_bw_level = WLAN_IPA_BW_LEVEL_LOW; 2485 } 2486 2487 ipa_debug("ipa uc bw monitor %s", stop ? "stop" : "start"); 2488 } 2489 #else 2490 static inline 2491 void wlan_ipa_uc_bw_monitor(struct wlan_ipa_priv *ipa_ctx, bool stop) 2492 { 2493 } 2494 #endif 2495 2496 /** 2497 * wlan_ipa_send_msg() - Allocate and send message to IPA 2498 * @net_dev: Interface net device 2499 * @type: event enum of type ipa_wlan_event 2500 * @mac_address: MAC address associated with the event 2501 * 2502 * Return: QDF STATUS 2503 */ 2504 static QDF_STATUS wlan_ipa_send_msg(qdf_netdev_t net_dev, 2505 qdf_ipa_wlan_event type, 2506 uint8_t *mac_addr) 2507 { 2508 qdf_ipa_msg_meta_t meta; 2509 qdf_ipa_wlan_msg_t *msg; 2510 2511 QDF_IPA_MSG_META_MSG_LEN(&meta) = sizeof(qdf_ipa_wlan_msg_t); 2512 2513 msg = qdf_mem_malloc(QDF_IPA_MSG_META_MSG_LEN(&meta)); 2514 if (!msg) 2515 return QDF_STATUS_E_NOMEM; 2516 2517 QDF_IPA_SET_META_MSG_TYPE(&meta, type); 2518 strlcpy(QDF_IPA_WLAN_MSG_NAME(msg), net_dev->name, IPA_RESOURCE_NAME_MAX); 2519 qdf_mem_copy(QDF_IPA_WLAN_MSG_MAC_ADDR(msg), mac_addr, QDF_NET_ETH_LEN); 2520 QDF_IPA_WLAN_MSG_NETDEV_IF_ID(msg) = net_dev->ifindex; 2521 2522 ipa_debug("%s: Evt: %d", QDF_IPA_WLAN_MSG_NAME(msg), QDF_IPA_MSG_META_MSG_TYPE(&meta)); 2523 2524 if (qdf_ipa_send_msg(&meta, msg, wlan_ipa_msg_free_fn)) { 2525 ipa_err("%s: Evt: %d fail", 2526 QDF_IPA_WLAN_MSG_NAME(msg), 2527 QDF_IPA_MSG_META_MSG_TYPE(&meta)); 2528 qdf_mem_free(msg); 2529 return QDF_STATUS_E_FAILURE; 2530 } 2531 2532 return QDF_STATUS_SUCCESS; 2533 } 2534 2535 #ifdef QCA_CONFIG_RPS 2536 void wlan_ipa_handle_multiple_sap_evt(struct wlan_ipa_priv *ipa_ctx, 2537 qdf_ipa_wlan_event type) 2538 { 2539 struct wlan_ipa_iface_context *iface_ctx; 2540 int i; 2541 2542 if (type == QDF_IPA_AP_DISCONNECT) { 2543 ipa_debug("Multiple SAP disconnecting. Enabling IPA"); 2544 2545 if (ipa_ctx->sap_num_connected_sta > 0) 2546 wlan_ipa_uc_handle_first_con(ipa_ctx); 2547 2548 for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) { 2549 iface_ctx = &ipa_ctx->iface_context[i]; 2550 2551 if (iface_ctx->device_mode == QDF_SAP_MODE) { 2552 wlan_ipa_uc_offload_enable_disable(ipa_ctx, 2553 WMI_AP_RX_DATA_OFFLOAD, 2554 iface_ctx->session_id, 2555 true); 2556 break; 2557 } 2558 } 2559 } else if (type == QDF_IPA_AP_CONNECT) { 2560 ipa_debug("Multiple SAP connected. Disabling IPA"); 2561 2562 for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) { 2563 iface_ctx = &ipa_ctx->iface_context[i]; 2564 2565 if (iface_ctx->device_mode == QDF_SAP_MODE) { 2566 wlan_ipa_uc_offload_enable_disable(ipa_ctx, 2567 WMI_AP_RX_DATA_OFFLOAD, 2568 iface_ctx->session_id, 2569 false); 2570 } 2571 } 2572 2573 if (!ipa_ctx->ipa_pipes_down) 2574 wlan_ipa_uc_handle_last_discon(ipa_ctx, true); 2575 } 2576 } 2577 #endif 2578 2579 static inline void 2580 wlan_ipa_save_bssid_iface_ctx(struct wlan_ipa_priv *ipa_ctx, uint8_t iface_id, 2581 uint8_t *mac_addr) 2582 { 2583 qdf_mem_copy(ipa_ctx->iface_context[iface_id].bssid.bytes, 2584 mac_addr, QDF_MAC_ADDR_SIZE); 2585 } 2586 2587 #ifdef IPA_WDS_EASYMESH_FEATURE 2588 /** wlan_ipa_set_peer_id() - Set ta_peer_id in IPA 2589 * @ipa_ctx: ipa context 2590 * @meta: Meta data for IPA 2591 * @net_dev: Interface net device 2592 * @type: WLAN IPA event 2593 * @mac_addr: mac_addr of peer 2594 * 2595 * Return: QDF STATUS 2596 */ 2597 static QDF_STATUS 2598 wlan_ipa_set_peer_id(struct wlan_ipa_priv *ipa_ctx, 2599 qdf_ipa_msg_meta_t *meta, 2600 qdf_netdev_t net_dev, 2601 qdf_ipa_wlan_event type, 2602 uint8_t *mac_addr) 2603 { 2604 uint8_t ta_peer_id; 2605 struct cdp_ast_entry_info peer_ast_info = {0}; 2606 struct cdp_soc_t *cdp_soc; 2607 qdf_ipa_wlan_msg_ex_t *msg_ex; 2608 bool status; 2609 2610 QDF_IPA_MSG_META_MSG_LEN(meta) = 2611 (sizeof(qdf_ipa_wlan_msg_ex_t) + 2612 sizeof(qdf_ipa_wlan_hdr_attrib_val_t) * 2613 IPA_TA_PEER_ID_ATTRI); 2614 2615 msg_ex = qdf_mem_malloc(QDF_IPA_MSG_META_MSG_LEN(meta)); 2616 if (!msg_ex) 2617 return QDF_STATUS_E_NOMEM; 2618 2619 strlcpy(msg_ex->name, net_dev->name, IPA_RESOURCE_NAME_MAX); 2620 msg_ex->num_of_attribs = IPA_TA_PEER_ID_ATTRI; 2621 ipa_info("Num of attribute set to: %d", IPA_TA_PEER_ID_ATTRI); 2622 2623 msg_ex->attribs[0].attrib_type = WLAN_HDR_ATTRIB_MAC_ADDR; 2624 if (wlan_ipa_uc_is_enabled(ipa_ctx->config)) { 2625 msg_ex->attribs[0].offset = 2626 WLAN_IPA_UC_WLAN_HDR_DES_MAC_OFFSET; 2627 } else { 2628 msg_ex->attribs[0].offset = 2629 WLAN_IPA_WLAN_HDR_DES_MAC_OFFSET; 2630 } 2631 memcpy(msg_ex->attribs[0].u.mac_addr, mac_addr, IPA_MAC_ADDR_SIZE); 2632 2633 msg_ex->attribs[1].attrib_type = WLAN_HDR_ATTRIB_TA_PEER_ID; 2634 cdp_soc = (struct cdp_soc_t *)ipa_ctx->dp_soc; 2635 status = cdp_peer_get_ast_info_by_soc(cdp_soc, mac_addr, 2636 &peer_ast_info); 2637 2638 if (!status) { 2639 qdf_mem_free(msg_ex); 2640 return QDF_STATUS_E_FAILURE; 2641 } 2642 2643 ta_peer_id = peer_ast_info.peer_id; 2644 ipa_info("ta_peer_id set to: %d", ta_peer_id); 2645 msg_ex->attribs[1].u.ta_peer_id = ta_peer_id; 2646 2647 if (qdf_ipa_send_msg(meta, msg_ex, wlan_ipa_msg_free_fn)) { 2648 ipa_info("%s: Evt: %d send ipa msg fail", 2649 net_dev->name, type); 2650 qdf_mem_free(msg_ex); 2651 return QDF_STATUS_E_FAILURE; 2652 } 2653 ipa_ctx->stats.num_send_msg++; 2654 2655 return QDF_STATUS_SUCCESS; 2656 } 2657 #else 2658 static QDF_STATUS 2659 wlan_ipa_set_peer_id(struct wlan_ipa_priv *ipa_ctx, 2660 qdf_ipa_msg_meta_t *meta, 2661 qdf_netdev_t net_dev, 2662 qdf_ipa_wlan_event type, 2663 uint8_t *mac_addr) 2664 { 2665 qdf_ipa_wlan_msg_ex_t *msg_ex; 2666 2667 QDF_IPA_MSG_META_MSG_LEN(meta) = 2668 (sizeof(qdf_ipa_wlan_msg_ex_t) + 2669 sizeof(qdf_ipa_wlan_hdr_attrib_val_t)); 2670 2671 msg_ex = qdf_mem_malloc(QDF_IPA_MSG_META_MSG_LEN(meta)); 2672 if (!msg_ex) 2673 return QDF_STATUS_E_NOMEM; 2674 2675 strlcpy(msg_ex->name, net_dev->name, IPA_RESOURCE_NAME_MAX); 2676 msg_ex->num_of_attribs = 1; 2677 msg_ex->attribs[0].attrib_type = WLAN_HDR_ATTRIB_MAC_ADDR; 2678 2679 if (wlan_ipa_uc_is_enabled(ipa_ctx->config)) { 2680 msg_ex->attribs[0].offset = 2681 WLAN_IPA_UC_WLAN_HDR_DES_MAC_OFFSET; 2682 } else { 2683 msg_ex->attribs[0].offset = WLAN_IPA_WLAN_HDR_DES_MAC_OFFSET; 2684 } 2685 memcpy(msg_ex->attribs[0].u.mac_addr, mac_addr, IPA_MAC_ADDR_SIZE); 2686 2687 if (qdf_ipa_send_msg(meta, msg_ex, wlan_ipa_msg_free_fn)) { 2688 ipa_info("%s: Evt: %d send ipa msg fail", 2689 net_dev->name, type); 2690 qdf_mem_free(msg_ex); 2691 return QDF_STATUS_E_FAILURE; 2692 } 2693 ipa_ctx->stats.num_send_msg++; 2694 2695 return QDF_STATUS_SUCCESS; 2696 } 2697 #endif 2698 2699 /** 2700 * __wlan_ipa_wlan_evt() - IPA event handler 2701 * @net_dev: Interface net device 2702 * @device_mode: Net interface device mode 2703 * @session_id: session id for the event 2704 * @type: event enum of type ipa_wlan_event 2705 * @mac_address: MAC address associated with the event 2706 * @is_2g_iface: @net_dev is 2G or not for QDF_IPA_STA_CONNECT and 2707 * QDF_IPA_AP_CONNECT 2708 * 2709 * This function is meant to be called from within wlan_ipa_ctx.c 2710 * 2711 * Return: QDF STATUS 2712 */ 2713 static QDF_STATUS __wlan_ipa_wlan_evt(qdf_netdev_t net_dev, uint8_t device_mode, 2714 uint8_t session_id, 2715 qdf_ipa_wlan_event type, 2716 uint8_t *mac_addr, bool is_2g_iface, 2717 struct wlan_ipa_priv *ipa_obj) 2718 { 2719 struct wlan_ipa_priv *ipa_ctx; 2720 struct wlan_ipa_iface_context *iface_ctx = NULL; 2721 qdf_ipa_msg_meta_t meta; 2722 qdf_ipa_wlan_msg_t *msg; 2723 qdf_ipa_wlan_msg_ex_t *msg_ex = NULL; 2724 int i; 2725 QDF_STATUS status; 2726 uint8_t sta_session_id = WLAN_IPA_MAX_SESSION; 2727 struct wlan_objmgr_pdev *pdev; 2728 struct wlan_objmgr_psoc *psoc; 2729 struct wlan_objmgr_vdev *vdev; 2730 bool ipa_wds = false; 2731 2732 ipa_debug("%s: EVT: %d, MAC: "QDF_MAC_ADDR_FMT", session_id: %u", 2733 net_dev->name, type, QDF_MAC_ADDR_REF(mac_addr), session_id); 2734 2735 if (type >= QDF_IPA_WLAN_EVENT_MAX) 2736 return QDF_STATUS_E_INVAL; 2737 2738 ipa_ctx = ipa_obj; 2739 if (wlan_ipa_uc_is_enabled(ipa_ctx->config) && 2740 !wlan_ipa_uc_sta_is_enabled(ipa_ctx->config) && 2741 (device_mode != QDF_SAP_MODE)) { 2742 return QDF_STATUS_SUCCESS; 2743 } 2744 2745 pdev = ipa_ctx->pdev; 2746 psoc = wlan_pdev_get_psoc(pdev); 2747 vdev = wlan_objmgr_get_vdev_by_id_from_psoc(psoc, session_id, 2748 WLAN_IPA_ID); 2749 QDF_BUG(session_id < WLAN_IPA_MAX_SESSION); 2750 2751 if (vdev) 2752 wlan_objmgr_vdev_release_ref(vdev, WLAN_IPA_ID); 2753 else 2754 ipa_err("vdev is NULL, session_id: %u", session_id); 2755 2756 if (ipa_ctx->sta_connected) { 2757 iface_ctx = wlan_ipa_get_iface(ipa_ctx, QDF_STA_MODE); 2758 if (iface_ctx) 2759 sta_session_id = iface_ctx->session_id; 2760 else 2761 ipa_err("sta iface_ctx is NULL"); 2762 } 2763 2764 /* 2765 * During IPA UC resource loading/unloading new events can be issued. 2766 */ 2767 if (wlan_ipa_uc_is_enabled(ipa_ctx->config) && 2768 (ipa_ctx->resource_loading || ipa_ctx->resource_unloading)) { 2769 unsigned int pending_event_count; 2770 struct wlan_ipa_uc_pending_event *pending_event = NULL; 2771 2772 ipa_info("Event:%d IPA resource %s inprogress", type, 2773 ipa_ctx->resource_loading ? 2774 "load" : "unload"); 2775 2776 /* Wait until completion of the long/unloading */ 2777 status = qdf_wait_for_event_completion( 2778 &ipa_ctx->ipa_resource_comp, 2779 IPA_RESOURCE_COMP_WAIT_TIME); 2780 if (status != QDF_STATUS_SUCCESS) { 2781 /* 2782 * If timed out, store the events separately and 2783 * handle them later. 2784 */ 2785 ipa_info("IPA resource %s timed out", 2786 ipa_ctx->resource_loading ? 2787 "load" : "unload"); 2788 2789 if (type == QDF_IPA_AP_DISCONNECT) { 2790 wlan_ipa_uc_offload_enable_disable(ipa_ctx, 2791 WMI_AP_RX_DATA_OFFLOAD, 2792 session_id, false); 2793 } else if (type == QDF_IPA_CLIENT_CONNECT_EX && 2794 wlan_sap_no_client_connected(ipa_ctx)) { 2795 if (wlan_sta_is_connected(ipa_ctx) && 2796 wlan_ipa_uc_is_loaded(ipa_ctx) && 2797 wlan_ipa_uc_sta_is_enabled(ipa_ctx-> 2798 config) && 2799 !wlan_ipa_is_sta_only_offload_enabled()) { 2800 wlan_ipa_uc_offload_enable_disable( 2801 ipa_ctx, 2802 WMI_STA_RX_DATA_OFFLOAD, 2803 sta_session_id, true); 2804 } 2805 } 2806 2807 qdf_mutex_acquire(&ipa_ctx->ipa_lock); 2808 2809 pending_event_count = 2810 qdf_list_size(&ipa_ctx->pending_event); 2811 if (pending_event_count >= 2812 WLAN_IPA_MAX_PENDING_EVENT_COUNT) { 2813 ipa_info("Reached max pending evt count"); 2814 qdf_list_remove_front( 2815 &ipa_ctx->pending_event, 2816 (qdf_list_node_t **)&pending_event); 2817 } else { 2818 pending_event = 2819 (struct wlan_ipa_uc_pending_event *) 2820 qdf_mem_malloc(sizeof( 2821 struct wlan_ipa_uc_pending_event)); 2822 } 2823 2824 if (!pending_event) { 2825 qdf_mutex_release(&ipa_ctx->ipa_lock); 2826 return QDF_STATUS_E_NOMEM; 2827 } 2828 2829 pending_event->net_dev = net_dev; 2830 pending_event->device_mode = device_mode; 2831 pending_event->session_id = session_id; 2832 pending_event->type = type; 2833 pending_event->is_loading = ipa_ctx->resource_loading; 2834 qdf_mem_copy(pending_event->mac_addr, 2835 mac_addr, QDF_MAC_ADDR_SIZE); 2836 pending_event->is_2g_iface = is_2g_iface; 2837 qdf_list_insert_back(&ipa_ctx->pending_event, 2838 &pending_event->node); 2839 2840 qdf_mutex_release(&ipa_ctx->ipa_lock); 2841 2842 /* Cleanup interface */ 2843 if (type == QDF_IPA_STA_DISCONNECT || 2844 type == QDF_IPA_AP_DISCONNECT) { 2845 for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) { 2846 iface_ctx = &ipa_ctx->iface_context[i]; 2847 if (iface_ctx->dev == net_dev) { 2848 wlan_ipa_cleanup_iface( 2849 iface_ctx, 2850 mac_addr); 2851 break; 2852 } 2853 } 2854 2855 if (qdf_ipa_get_lan_rx_napi() && 2856 ipa_ctx->num_sap_connected == 1) { 2857 wlan_ipa_handle_multiple_sap_evt(ipa_ctx, 2858 type); 2859 } 2860 } 2861 2862 return QDF_STATUS_SUCCESS; 2863 } 2864 ipa_info("IPA resource %s completed", 2865 ipa_ctx->resource_loading ? 2866 "load" : "unload"); 2867 } 2868 2869 ipa_ctx->stats.event[type]++; 2870 2871 QDF_IPA_SET_META_MSG_TYPE(&meta, type); 2872 switch (type) { 2873 case QDF_IPA_STA_CONNECT: 2874 qdf_mutex_acquire(&ipa_ctx->event_lock); 2875 2876 /* STA already connected and without disconnect, connect again 2877 * This is Roaming scenario, clean up ipa iface first, then add 2878 * ipa iface later, sta_connected-- first, sta_connected++ 2879 * later to reflect real sta number on DUT. 2880 */ 2881 if (ipa_ctx->sta_connected) { 2882 iface_ctx = wlan_ipa_get_iface_by_mode_netdev( 2883 ipa_ctx, net_dev, QDF_STA_MODE); 2884 if (iface_ctx) { 2885 ipa_ctx->sta_connected--; 2886 wlan_ipa_cleanup_iface(iface_ctx, NULL); 2887 } 2888 status = wlan_ipa_send_msg(net_dev, 2889 QDF_IPA_STA_DISCONNECT, 2890 mac_addr); 2891 if (status != QDF_STATUS_SUCCESS) { 2892 ipa_err("QDF_IPA_STA_DISCONNECT send failed %u", 2893 status); 2894 qdf_mutex_release(&ipa_ctx->event_lock); 2895 goto end; 2896 } 2897 } 2898 2899 status = wlan_ipa_setup_iface(ipa_ctx, net_dev, device_mode, 2900 session_id, mac_addr, 2901 is_2g_iface); 2902 if (status != QDF_STATUS_SUCCESS) { 2903 ipa_err("wlan_ipa_setup_iface failed %u", status); 2904 qdf_mutex_release(&ipa_ctx->event_lock); 2905 goto end; 2906 } 2907 2908 ipa_ctx->vdev_to_iface[session_id] = 2909 wlan_ipa_get_ifaceid(ipa_ctx, session_id); 2910 2911 wlan_ipa_save_bssid_iface_ctx(ipa_ctx, 2912 ipa_ctx->vdev_to_iface[session_id], 2913 mac_addr); 2914 2915 if (wlan_ipa_uc_sta_is_enabled(ipa_ctx->config) && 2916 (ipa_ctx->sap_num_connected_sta > 0 || 2917 wlan_ipa_is_sta_only_offload_enabled()) && 2918 !ipa_ctx->sta_connected) { 2919 qdf_mutex_release(&ipa_ctx->event_lock); 2920 wlan_ipa_uc_offload_enable_disable(ipa_ctx, 2921 WMI_STA_RX_DATA_OFFLOAD, session_id, 2922 true); 2923 qdf_mutex_acquire(&ipa_ctx->event_lock); 2924 qdf_atomic_set(&ipa_ctx->stats_quota, 1); 2925 } 2926 2927 if (!wlan_ipa_is_sta_only_offload_enabled()) { 2928 ipa_debug("IPA STA only offload not enabled"); 2929 } else if (ipa_ctx->uc_loaded && 2930 !ipa_ctx->sap_num_connected_sta && 2931 !ipa_ctx->sta_connected) { 2932 status = wlan_ipa_uc_handle_first_con(ipa_ctx); 2933 if (status) { 2934 qdf_mutex_release(&ipa_ctx->event_lock); 2935 ipa_info("handle 1st conn failed %d", status); 2936 wlan_ipa_uc_offload_enable_disable( 2937 ipa_ctx, 2938 WMI_STA_RX_DATA_OFFLOAD, 2939 session_id, 2940 false); 2941 ipa_ctx->vdev_to_iface[session_id] = 2942 WLAN_IPA_MAX_SESSION; 2943 goto end; 2944 } 2945 } 2946 2947 ipa_ctx->sta_connected++; 2948 2949 if (qdf_ipa_get_lan_rx_napi() && ipa_ctx->sap_num_connected_sta) 2950 ipa_set_rps_per_vdev(ipa_ctx, session_id, true); 2951 2952 qdf_mutex_release(&ipa_ctx->event_lock); 2953 2954 ipa_debug("sta_connected=%d vdev_to_iface[%u] %u", 2955 ipa_ctx->sta_connected, 2956 session_id, 2957 ipa_ctx->vdev_to_iface[session_id]); 2958 break; 2959 2960 case QDF_IPA_AP_CONNECT: 2961 qdf_mutex_acquire(&ipa_ctx->event_lock); 2962 2963 /* For DFS channel we get two start_bss event (before and after 2964 * CAC). Also when ACS range includes both DFS and non DFS 2965 * channels, we could possibly change channel many times due to 2966 * RADAR detection and chosen channel may not be a DFS channels. 2967 * So dont return error here. Just discard the event. 2968 */ 2969 if (ipa_ctx->vdev_to_iface[session_id] != 2970 WLAN_IPA_MAX_SESSION) { 2971 qdf_mutex_release(&ipa_ctx->event_lock); 2972 return 0; 2973 } 2974 2975 status = wlan_ipa_setup_iface(ipa_ctx, net_dev, device_mode, 2976 session_id, mac_addr, 2977 is_2g_iface); 2978 if (status != QDF_STATUS_SUCCESS) { 2979 qdf_mutex_release(&ipa_ctx->event_lock); 2980 ipa_err("%s: Evt: %d, Interface setup failed", 2981 msg_ex->name, QDF_IPA_MSG_META_MSG_TYPE(&meta)); 2982 goto end; 2983 } 2984 2985 if (wlan_ipa_uc_is_enabled(ipa_ctx->config)) { 2986 qdf_mutex_release(&ipa_ctx->event_lock); 2987 if (qdf_ipa_get_lan_rx_napi() && 2988 (ipa_ctx->num_sap_connected > 1)) { 2989 wlan_ipa_handle_multiple_sap_evt(ipa_ctx, type); 2990 } else { 2991 wlan_ipa_uc_offload_enable_disable(ipa_ctx, 2992 WMI_AP_RX_DATA_OFFLOAD, 2993 session_id, true); 2994 } 2995 qdf_mutex_acquire(&ipa_ctx->event_lock); 2996 } 2997 2998 ipa_ctx->vdev_to_iface[session_id] = 2999 wlan_ipa_get_ifaceid(ipa_ctx, session_id); 3000 ipa_debug("vdev_to_iface[%u]=%u", 3001 session_id, 3002 ipa_ctx->vdev_to_iface[session_id]); 3003 ipa_wds = ipa_ctx->config->ipa_wds; 3004 qdf_mutex_release(&ipa_ctx->event_lock); 3005 break; 3006 3007 case QDF_IPA_STA_DISCONNECT: 3008 qdf_mutex_acquire(&ipa_ctx->event_lock); 3009 3010 if (!ipa_ctx->sta_connected) { 3011 struct wlan_ipa_iface_context *iface; 3012 3013 qdf_mutex_release(&ipa_ctx->event_lock); 3014 ipa_info("%s: Evt: %d, STA already disconnected", 3015 msg_ex->name, 3016 QDF_IPA_MSG_META_MSG_TYPE(&meta)); 3017 3018 iface = wlan_ipa_get_iface_by_mode_netdev(ipa_ctx, 3019 net_dev, 3020 QDF_STA_MODE); 3021 if (iface) 3022 wlan_ipa_cleanup_iface(iface, mac_addr); 3023 3024 return QDF_STATUS_E_INVAL; 3025 } 3026 3027 ipa_ctx->sta_connected--; 3028 3029 if (!wlan_ipa_uc_is_enabled(ipa_ctx->config)) { 3030 ipa_debug("%s: IPA UC OFFLOAD NOT ENABLED", 3031 msg_ex->name); 3032 } else { 3033 /* 3034 * Disable IPA pipes when 3035 * 1. STA is the last interface or 3036 * 2. STA only offload enabled and no clients connected 3037 * to SAP 3038 */ 3039 if ((ipa_ctx->num_iface == 1 || 3040 (wlan_ipa_is_sta_only_offload_enabled() && 3041 !ipa_ctx->sap_num_connected_sta)) && 3042 wlan_ipa_is_fw_wdi_activated(ipa_ctx) && 3043 !ipa_ctx->ipa_pipes_down && 3044 (ipa_ctx->resource_unloading == false)) { 3045 if (wlan_ipa_is_driver_unloading(ipa_ctx)) { 3046 /* 3047 * We disable WDI pipes directly here 3048 * since IPA_OPCODE_TX/RX_SUSPEND 3049 * message will not be processed when 3050 * unloading WLAN driver is in progress 3051 */ 3052 wlan_ipa_uc_disable_pipes(ipa_ctx, 3053 true); 3054 } else { 3055 wlan_ipa_uc_handle_last_discon(ipa_ctx, 3056 true); 3057 } 3058 } 3059 } 3060 3061 if (wlan_ipa_uc_sta_is_enabled(ipa_ctx->config) && 3062 (ipa_ctx->sap_num_connected_sta > 0 || 3063 wlan_ipa_is_sta_only_offload_enabled())) { 3064 qdf_atomic_set(&ipa_ctx->stats_quota, 0); 3065 qdf_mutex_release(&ipa_ctx->event_lock); 3066 wlan_ipa_uc_offload_enable_disable(ipa_ctx, 3067 WMI_STA_RX_DATA_OFFLOAD, session_id, false); 3068 qdf_mutex_acquire(&ipa_ctx->event_lock); 3069 } 3070 3071 ipa_ctx->vdev_to_iface[session_id] = WLAN_IPA_MAX_SESSION; 3072 ipa_debug("vdev_to_iface[%u]=%u", session_id, 3073 ipa_ctx->vdev_to_iface[session_id]); 3074 3075 iface_ctx = wlan_ipa_get_iface_by_mode_netdev(ipa_ctx, 3076 net_dev, 3077 QDF_STA_MODE); 3078 if (iface_ctx) 3079 wlan_ipa_cleanup_iface(iface_ctx, mac_addr); 3080 3081 if (qdf_ipa_get_lan_rx_napi() && ipa_ctx->sap_num_connected_sta) 3082 ipa_set_rps_per_vdev(ipa_ctx, session_id, false); 3083 3084 qdf_mutex_release(&ipa_ctx->event_lock); 3085 3086 ipa_debug("sta_connected=%d", ipa_ctx->sta_connected); 3087 break; 3088 3089 case QDF_IPA_AP_DISCONNECT: 3090 qdf_mutex_acquire(&ipa_ctx->event_lock); 3091 3092 if ((ipa_ctx->num_iface == 1) && 3093 wlan_ipa_is_fw_wdi_activated(ipa_ctx) && 3094 !ipa_ctx->ipa_pipes_down && 3095 (ipa_ctx->resource_unloading == false)) { 3096 if (wlan_ipa_is_driver_unloading(ipa_ctx)) { 3097 /* 3098 * We disable WDI pipes directly here since 3099 * IPA_OPCODE_TX/RX_SUSPEND message will not be 3100 * processed when unloading WLAN driver is in 3101 * progress 3102 */ 3103 wlan_ipa_uc_disable_pipes(ipa_ctx, true); 3104 } else { 3105 /* 3106 * This shouldn't happen : 3107 * No interface left but WDI pipes are still 3108 * active - force close WDI pipes 3109 */ 3110 ipa_err("No interface left but WDI pipes are still active"); 3111 wlan_ipa_uc_handle_last_discon(ipa_ctx, true); 3112 } 3113 } 3114 3115 if (wlan_ipa_uc_is_enabled(ipa_ctx->config)) { 3116 qdf_mutex_release(&ipa_ctx->event_lock); 3117 wlan_ipa_uc_offload_enable_disable(ipa_ctx, 3118 WMI_AP_RX_DATA_OFFLOAD, session_id, false); 3119 qdf_mutex_acquire(&ipa_ctx->event_lock); 3120 ipa_ctx->vdev_to_iface[session_id] = 3121 WLAN_IPA_MAX_SESSION; 3122 ipa_debug("vdev_to_iface[%u]=%u", 3123 session_id, 3124 ipa_ctx->vdev_to_iface[session_id]); 3125 } 3126 3127 for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) { 3128 iface_ctx = &ipa_ctx->iface_context[i]; 3129 if (iface_ctx->dev == net_dev) { 3130 wlan_ipa_cleanup_iface(iface_ctx, mac_addr); 3131 break; 3132 } 3133 } 3134 3135 if (qdf_ipa_get_lan_rx_napi() && 3136 (ipa_ctx->num_sap_connected == 1)) 3137 wlan_ipa_handle_multiple_sap_evt(ipa_ctx, type); 3138 3139 qdf_mutex_release(&ipa_ctx->event_lock); 3140 break; 3141 3142 case QDF_IPA_CLIENT_CONNECT_EX: 3143 if (!wlan_ipa_uc_is_enabled(ipa_ctx->config)) { 3144 ipa_debug("%s: Evt: %d, IPA UC OFFLOAD NOT ENABLED", 3145 net_dev->name, type); 3146 return QDF_STATUS_SUCCESS; 3147 } 3148 3149 qdf_mutex_acquire(&ipa_ctx->event_lock); 3150 if (wlan_ipa_uc_find_add_assoc_sta(ipa_ctx, true, 3151 mac_addr)) { 3152 qdf_mutex_release(&ipa_ctx->event_lock); 3153 ipa_err("%s: STA found, addr: " QDF_MAC_ADDR_FMT, 3154 net_dev->name, 3155 QDF_MAC_ADDR_REF(mac_addr)); 3156 return QDF_STATUS_SUCCESS; 3157 } 3158 3159 /* Enable IPA UC Data PIPEs when first STA connected */ 3160 if (ipa_ctx->sap_num_connected_sta == 0 && 3161 ipa_ctx->uc_loaded == true) { 3162 3163 if (wlan_ipa_uc_sta_is_enabled(ipa_ctx->config) && 3164 ipa_ctx->sta_connected && 3165 !wlan_ipa_is_sta_only_offload_enabled()) { 3166 qdf_mutex_release(&ipa_ctx->event_lock); 3167 wlan_ipa_uc_offload_enable_disable(ipa_ctx, 3168 WMI_STA_RX_DATA_OFFLOAD, 3169 sta_session_id, true); 3170 qdf_mutex_acquire(&ipa_ctx->event_lock); 3171 qdf_atomic_set(&ipa_ctx->stats_quota, 1); 3172 } 3173 3174 /* 3175 * IPA pipes already enabled if STA only offload 3176 * is enabled and STA is connected to remote AP. 3177 */ 3178 if (wlan_ipa_is_sta_only_offload_enabled() && 3179 ipa_ctx->sta_connected) { 3180 ipa_debug("IPA pipes already enabled"); 3181 } else if (wlan_ipa_uc_handle_first_con(ipa_ctx)) { 3182 ipa_info("%s: handle 1st con fail", 3183 net_dev->name); 3184 3185 if (wlan_ipa_uc_sta_is_enabled( 3186 ipa_ctx->config) && 3187 ipa_ctx->sta_connected && 3188 !wlan_ipa_is_sta_only_offload_enabled()) { 3189 qdf_atomic_set(&ipa_ctx->stats_quota, 3190 0); 3191 qdf_mutex_release(&ipa_ctx->event_lock); 3192 wlan_ipa_uc_offload_enable_disable( 3193 ipa_ctx, 3194 WMI_STA_RX_DATA_OFFLOAD, 3195 sta_session_id, false); 3196 } else { 3197 qdf_mutex_release(&ipa_ctx->event_lock); 3198 } 3199 3200 return QDF_STATUS_E_BUSY; 3201 } 3202 wlan_ipa_uc_bw_monitor(ipa_ctx, false); 3203 ipa_info("first sap client connected"); 3204 } 3205 3206 ipa_ctx->sap_num_connected_sta++; 3207 3208 qdf_mutex_release(&ipa_ctx->event_lock); 3209 3210 QDF_IPA_SET_META_MSG_TYPE(&meta, type); 3211 3212 status = wlan_ipa_set_peer_id(ipa_ctx, &meta, net_dev, 3213 type, (uint8_t *)mac_addr); 3214 if (QDF_IS_STATUS_ERROR(status)) 3215 return QDF_STATUS_E_FAILURE; 3216 3217 ipa_debug("sap_num_connected_sta=%d", 3218 ipa_ctx->sap_num_connected_sta); 3219 3220 return QDF_STATUS_SUCCESS; 3221 3222 case WLAN_CLIENT_DISCONNECT: 3223 if (!wlan_ipa_uc_is_enabled(ipa_ctx->config)) { 3224 ipa_debug("%s: IPA UC OFFLOAD NOT ENABLED", 3225 msg_ex->name); 3226 return QDF_STATUS_SUCCESS; 3227 } 3228 3229 qdf_mutex_acquire(&ipa_ctx->event_lock); 3230 wlan_ipa_set_sap_client_auth(ipa_ctx, mac_addr, false); 3231 if (!ipa_ctx->sap_num_connected_sta) { 3232 qdf_mutex_release(&ipa_ctx->event_lock); 3233 ipa_debug("%s: Evt: %d, Client already disconnected", 3234 msg_ex->name, 3235 QDF_IPA_MSG_META_MSG_TYPE(&meta)); 3236 3237 return QDF_STATUS_SUCCESS; 3238 } 3239 if (!wlan_ipa_uc_find_add_assoc_sta(ipa_ctx, false, 3240 mac_addr)) { 3241 qdf_mutex_release(&ipa_ctx->event_lock); 3242 ipa_debug("%s: STA NOT found, not valid: " 3243 QDF_MAC_ADDR_FMT, 3244 msg_ex->name, QDF_MAC_ADDR_REF(mac_addr)); 3245 3246 return QDF_STATUS_SUCCESS; 3247 } 3248 ipa_ctx->sap_num_connected_sta--; 3249 3250 /* 3251 * Disable IPA pipes when 3252 * 1. last client disconnected and 3253 * 2. STA is not connected if STA only offload is enabled 3254 */ 3255 if (!ipa_ctx->sap_num_connected_sta && 3256 ipa_ctx->uc_loaded && 3257 !(wlan_ipa_is_sta_only_offload_enabled() && 3258 ipa_ctx->sta_connected)) { 3259 if ((false == ipa_ctx->resource_unloading) && 3260 wlan_ipa_is_fw_wdi_activated(ipa_ctx) && 3261 !ipa_ctx->ipa_pipes_down) { 3262 if (wlan_ipa_is_driver_unloading(ipa_ctx)) { 3263 /* 3264 * We disable WDI pipes directly here 3265 * since IPA_OPCODE_TX/RX_SUSPEND 3266 * message will not be processed when 3267 * unloading WLAN driver is in progress 3268 */ 3269 3270 wlan_ipa_uc_bw_monitor(ipa_ctx, true); 3271 wlan_ipa_uc_disable_pipes(ipa_ctx, 3272 true); 3273 } else { 3274 /* 3275 * If STA is connected, wait for IPA TX 3276 * completions before disabling 3277 * IPA pipes 3278 */ 3279 wlan_ipa_uc_handle_last_discon(ipa_ctx, 3280 !ipa_ctx->sta_connected); 3281 wlan_ipa_uc_bw_monitor(ipa_ctx, true); 3282 } 3283 ipa_info("last sap client disconnected"); 3284 } 3285 3286 if (wlan_ipa_uc_sta_is_enabled(ipa_ctx->config) && 3287 ipa_ctx->sta_connected && 3288 !wlan_ipa_is_sta_only_offload_enabled()) { 3289 qdf_atomic_set(&ipa_ctx->stats_quota, 0); 3290 qdf_mutex_release(&ipa_ctx->event_lock); 3291 wlan_ipa_uc_offload_enable_disable(ipa_ctx, 3292 WMI_STA_RX_DATA_OFFLOAD, 3293 sta_session_id, false); 3294 } else { 3295 qdf_mutex_release(&ipa_ctx->event_lock); 3296 } 3297 } else { 3298 qdf_mutex_release(&ipa_ctx->event_lock); 3299 } 3300 3301 ipa_debug("sap_num_connected_sta=%d", 3302 ipa_ctx->sap_num_connected_sta); 3303 break; 3304 3305 default: 3306 return QDF_STATUS_SUCCESS; 3307 } 3308 3309 QDF_IPA_MSG_META_MSG_LEN(&meta) = sizeof(qdf_ipa_wlan_msg_t); 3310 msg = qdf_mem_malloc(QDF_IPA_MSG_META_MSG_LEN(&meta)); 3311 if (!msg) 3312 return QDF_STATUS_E_NOMEM; 3313 3314 QDF_IPA_SET_META_MSG_TYPE(&meta, type); 3315 strlcpy(QDF_IPA_WLAN_MSG_NAME(msg), net_dev->name, 3316 IPA_RESOURCE_NAME_MAX); 3317 qdf_mem_copy(QDF_IPA_WLAN_MSG_MAC_ADDR(msg), mac_addr, QDF_NET_ETH_LEN); 3318 QDF_IPA_WLAN_MSG_NETDEV_IF_ID(msg) = net_dev->ifindex; 3319 3320 wlan_ipa_msg_wds_update(ipa_wds, msg); 3321 3322 ipa_debug("%s: Evt: %d", QDF_IPA_WLAN_MSG_NAME(msg), 3323 QDF_IPA_MSG_META_MSG_TYPE(&meta)); 3324 3325 if (qdf_ipa_send_msg(&meta, msg, wlan_ipa_msg_free_fn)) { 3326 3327 ipa_err("%s: Evt: %d fail", 3328 QDF_IPA_WLAN_MSG_NAME(msg), 3329 QDF_IPA_MSG_META_MSG_TYPE(&meta)); 3330 qdf_mem_free(msg); 3331 3332 return QDF_STATUS_E_FAILURE; 3333 } 3334 3335 ipa_ctx->stats.num_send_msg++; 3336 3337 end: 3338 return QDF_STATUS_SUCCESS; 3339 } 3340 3341 /** 3342 * wlan_host_to_ipa_wlan_event() - convert wlan_ipa_wlan_event to ipa_wlan_event 3343 * @wlan_ipa_event_type: event to be converted to an ipa_wlan_event 3344 * 3345 * Return: qdf_ipa_wlan_event representing the wlan_ipa_wlan_event 3346 */ 3347 static qdf_ipa_wlan_event 3348 wlan_host_to_ipa_wlan_event(enum wlan_ipa_wlan_event wlan_ipa_event_type) 3349 { 3350 qdf_ipa_wlan_event ipa_event; 3351 3352 switch (wlan_ipa_event_type) { 3353 case WLAN_IPA_CLIENT_CONNECT: 3354 ipa_event = QDF_IPA_CLIENT_CONNECT; 3355 break; 3356 case WLAN_IPA_CLIENT_DISCONNECT: 3357 ipa_event = QDF_IPA_CLIENT_DISCONNECT; 3358 break; 3359 case WLAN_IPA_AP_CONNECT: 3360 ipa_event = QDF_IPA_AP_CONNECT; 3361 break; 3362 case WLAN_IPA_AP_DISCONNECT: 3363 ipa_event = QDF_IPA_AP_DISCONNECT; 3364 break; 3365 case WLAN_IPA_STA_CONNECT: 3366 ipa_event = QDF_IPA_STA_CONNECT; 3367 break; 3368 case WLAN_IPA_STA_DISCONNECT: 3369 ipa_event = QDF_IPA_STA_DISCONNECT; 3370 break; 3371 case WLAN_IPA_CLIENT_CONNECT_EX: 3372 ipa_event = QDF_IPA_CLIENT_CONNECT_EX; 3373 break; 3374 case WLAN_IPA_WLAN_EVENT_MAX: 3375 default: 3376 ipa_event = QDF_IPA_WLAN_EVENT_MAX; 3377 break; 3378 } 3379 3380 return ipa_event; 3381 } 3382 3383 #ifdef IPA_P2P_SUPPORT 3384 /** 3385 * wlan_ipa_device_mode_switch() - Switch P2p GO/CLI to SAP/STA mode 3386 * @device_mode: device mode 3387 * 3388 * Return: New device mode after switching 3389 */ 3390 static uint8_t wlan_ipa_device_mode_switch(uint8_t device_mode) 3391 { 3392 switch (device_mode) { 3393 case QDF_P2P_CLIENT_MODE: 3394 return QDF_STA_MODE; 3395 case QDF_P2P_GO_MODE: 3396 return QDF_SAP_MODE; 3397 default: 3398 break; 3399 } 3400 3401 return device_mode; 3402 } 3403 #else 3404 static uint8_t wlan_ipa_device_mode_switch(uint8_t device_mode) 3405 { 3406 return device_mode; 3407 } 3408 #endif 3409 3410 /** 3411 * wlan_ipa_wlan_evt() - SSR wrapper for __wlan_ipa_wlan_evt 3412 * @net_dev: Interface net device 3413 * @device_mode: Net interface device mode 3414 * @session_id: session id for the event 3415 * @ipa_event_type: event enum of type wlan_ipa_wlan_event 3416 * @mac_address: MAC address associated with the event 3417 * @is_2g_iface: @net_dev is 2g interface or not 3418 * 3419 * Return: QDF_STATUS 3420 */ 3421 QDF_STATUS wlan_ipa_wlan_evt(qdf_netdev_t net_dev, uint8_t device_mode, 3422 uint8_t session_id, 3423 enum wlan_ipa_wlan_event ipa_event_type, 3424 uint8_t *mac_addr, bool is_2g_iface, 3425 struct wlan_ipa_priv *ipa_obj) 3426 { 3427 qdf_ipa_wlan_event type = wlan_host_to_ipa_wlan_event(ipa_event_type); 3428 QDF_STATUS status = QDF_STATUS_SUCCESS; 3429 3430 device_mode = wlan_ipa_device_mode_switch(device_mode); 3431 3432 /* Data path offload only support for STA and SAP mode */ 3433 if ((device_mode == QDF_STA_MODE) || 3434 (device_mode == QDF_SAP_MODE)) 3435 status = __wlan_ipa_wlan_evt(net_dev, device_mode, 3436 session_id, type, mac_addr, 3437 is_2g_iface, ipa_obj); 3438 3439 return status; 3440 } 3441 3442 /** 3443 * wlan_ipa_uc_proc_pending_event() - Process IPA uC pending events 3444 * @ipa_ctx: Global IPA IPA context 3445 * @is_loading: Indicate if invoked during loading 3446 * 3447 * Return: None 3448 */ 3449 static void 3450 wlan_ipa_uc_proc_pending_event(struct wlan_ipa_priv *ipa_ctx, bool is_loading) 3451 { 3452 unsigned int pending_event_count; 3453 struct wlan_ipa_uc_pending_event *pending_event = NULL; 3454 3455 pending_event_count = qdf_list_size(&ipa_ctx->pending_event); 3456 ipa_debug("Pending Event Count %d", pending_event_count); 3457 if (!pending_event_count) { 3458 ipa_debug("No Pending Event"); 3459 return; 3460 } 3461 3462 qdf_list_remove_front(&ipa_ctx->pending_event, 3463 (qdf_list_node_t **)&pending_event); 3464 while (pending_event) { 3465 struct wlan_objmgr_pdev *pdev = ipa_ctx->pdev; 3466 struct wlan_objmgr_psoc *psoc = wlan_pdev_get_psoc(pdev); 3467 struct wlan_objmgr_vdev *vdev = 3468 wlan_objmgr_get_vdev_by_id_from_psoc(psoc, 3469 pending_event->session_id, 3470 WLAN_IPA_ID); 3471 if (pending_event->is_loading == is_loading && vdev) { 3472 __wlan_ipa_wlan_evt(pending_event->net_dev, 3473 pending_event->device_mode, 3474 pending_event->session_id, 3475 pending_event->type, 3476 pending_event->mac_addr, 3477 pending_event->is_2g_iface, ipa_ctx); 3478 } 3479 3480 if (vdev) 3481 wlan_objmgr_vdev_release_ref(vdev, WLAN_IPA_ID); 3482 qdf_mem_free(pending_event); 3483 pending_event = NULL; 3484 qdf_list_remove_front(&ipa_ctx->pending_event, 3485 (qdf_list_node_t **)&pending_event); 3486 } 3487 } 3488 3489 #if !defined(QCA_LL_TX_FLOW_CONTROL_V2) && !defined(QCA_IPA_LL_TX_FLOW_CONTROL) 3490 3491 /** 3492 * wlan_ipa_free_tx_desc_list() - Free IPA Tx desc list 3493 * @ipa_ctx: IPA context 3494 * 3495 * Return: None 3496 */ 3497 static inline void wlan_ipa_free_tx_desc_list(struct wlan_ipa_priv *ipa_ctx) 3498 { 3499 int i; 3500 qdf_ipa_rx_data_t *ipa_tx_desc; 3501 uint32_t pool_size; 3502 3503 if (!ipa_ctx->tx_desc_pool) 3504 return; 3505 3506 qdf_spin_lock_bh(&ipa_ctx->q_lock); 3507 pool_size = ipa_ctx->tx_desc_free_list.max_size; 3508 for (i = 0; i < pool_size; i++) { 3509 ipa_tx_desc = ipa_ctx->tx_desc_pool[i].ipa_tx_desc_ptr; 3510 if (ipa_tx_desc) 3511 qdf_ipa_free_skb(ipa_tx_desc); 3512 3513 if (ipa_ctx->tx_desc_free_list.count && 3514 qdf_list_remove_node(&ipa_ctx->tx_desc_free_list, 3515 &ipa_ctx->tx_desc_pool[i].node) != 3516 QDF_STATUS_SUCCESS) 3517 ipa_err("Failed to remove node from tx desc freelist"); 3518 } 3519 qdf_spin_unlock_bh(&ipa_ctx->q_lock); 3520 3521 qdf_list_destroy(&ipa_ctx->tx_desc_free_list); 3522 qdf_mem_free(ipa_ctx->tx_desc_pool); 3523 ipa_ctx->tx_desc_pool = NULL; 3524 3525 ipa_ctx->stats.num_tx_desc_q_cnt = 0; 3526 ipa_ctx->stats.num_tx_desc_error = 0; 3527 } 3528 3529 /** 3530 * wlan_ipa_alloc_tx_desc_free_list() - Allocate IPA Tx desc list 3531 * @ipa_ctx: IPA context 3532 * 3533 * Return: QDF_STATUS 3534 */ 3535 static QDF_STATUS 3536 wlan_ipa_alloc_tx_desc_free_list(struct wlan_ipa_priv *ipa_ctx) 3537 { 3538 int i; 3539 uint32_t max_desc_cnt; 3540 3541 max_desc_cnt = ipa_ctx->config->txbuf_count; 3542 3543 ipa_ctx->tx_desc_pool = qdf_mem_malloc(sizeof(struct wlan_ipa_tx_desc) * 3544 max_desc_cnt); 3545 if (!ipa_ctx->tx_desc_pool) 3546 return QDF_STATUS_E_NOMEM; 3547 3548 qdf_list_create(&ipa_ctx->tx_desc_free_list, max_desc_cnt); 3549 3550 qdf_spin_lock_bh(&ipa_ctx->q_lock); 3551 for (i = 0; i < max_desc_cnt; i++) { 3552 ipa_ctx->tx_desc_pool[i].id = i; 3553 ipa_ctx->tx_desc_pool[i].ipa_tx_desc_ptr = NULL; 3554 qdf_list_insert_back(&ipa_ctx->tx_desc_free_list, 3555 &ipa_ctx->tx_desc_pool[i].node); 3556 } 3557 3558 ipa_ctx->stats.num_tx_desc_q_cnt = 0; 3559 ipa_ctx->stats.num_tx_desc_error = 0; 3560 3561 qdf_spin_unlock_bh(&ipa_ctx->q_lock); 3562 3563 return QDF_STATUS_SUCCESS; 3564 } 3565 3566 /** 3567 * wlan_ipa_setup_tx_sys_pipe() - Setup IPA Tx system pipes 3568 * @ipa_ctx: Global IPA IPA context 3569 * @desc_fifo_sz: Number of descriptors 3570 * 3571 * Return: 0 on success, negative errno on error 3572 */ 3573 static int wlan_ipa_setup_tx_sys_pipe(struct wlan_ipa_priv *ipa_ctx, 3574 int32_t desc_fifo_sz) 3575 { 3576 int i, ret = 0; 3577 qdf_ipa_sys_connect_params_t *ipa; 3578 3579 /*setup TX pipes */ 3580 for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) { 3581 ipa = &ipa_ctx->sys_pipe[i].ipa_sys_params; 3582 3583 ipa->client = wlan_ipa_iface_2_client[i].cons_client; 3584 ipa->desc_fifo_sz = desc_fifo_sz; 3585 ipa->priv = &ipa_ctx->iface_context[i]; 3586 ipa->notify = wlan_ipa_i2w_cb; 3587 3588 if (wlan_ipa_uc_sta_is_enabled(ipa_ctx->config)) { 3589 ipa->ipa_ep_cfg.hdr.hdr_len = 3590 WLAN_IPA_UC_WLAN_TX_HDR_LEN; 3591 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT; 3592 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1; 3593 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0; 3594 ipa->ipa_ep_cfg.hdr.hdr_additional_const_len = 3595 WLAN_IPA_UC_WLAN_8023_HDR_SIZE; 3596 ipa->ipa_ep_cfg.hdr_ext.hdr_little_endian = true; 3597 } else { 3598 ipa->ipa_ep_cfg.hdr.hdr_len = WLAN_IPA_WLAN_TX_HDR_LEN; 3599 } 3600 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC; 3601 3602 ret = wlan_ipa_wdi_setup_sys_pipe(ipa_ctx, ipa, 3603 &ipa_ctx->sys_pipe[i].conn_hdl); 3604 if (ret) { 3605 ipa_err("Failed for pipe %d ret: %d", i, ret); 3606 return ret; 3607 } 3608 ipa_ctx->sys_pipe[i].conn_hdl_valid = 1; 3609 } 3610 3611 return ret; 3612 } 3613 #else /* QCA_LL_TX_FLOW_CONTROL_V2 */ 3614 3615 /** 3616 * wlan_ipa_free_tx_desc_list() - Free IPA Tx desc list 3617 * @ipa_ctx: IPA context 3618 * 3619 * Return: None 3620 */ 3621 static inline void wlan_ipa_free_tx_desc_list(struct wlan_ipa_priv *ipa_ctx) 3622 { 3623 } 3624 3625 /** 3626 * wlan_ipa_alloc_tx_desc_free_list() - Allocate IPA Tx desc list 3627 * @ipa_ctx: IPA context 3628 * 3629 * Return: QDF_STATUS 3630 */ 3631 static QDF_STATUS 3632 wlan_ipa_alloc_tx_desc_free_list(struct wlan_ipa_priv *ipa_ctx) 3633 { 3634 return QDF_STATUS_SUCCESS; 3635 } 3636 3637 /** 3638 * wlan_ipa_setup_tx_sys_pipe() - Setup IPA Tx system pipes 3639 * @ipa_ctx: IPA context 3640 * @desc_fifo_sz: Number of descriptors 3641 * 3642 * Return: 0 on success, negative errno on error 3643 */ 3644 static int wlan_ipa_setup_tx_sys_pipe(struct wlan_ipa_priv *ipa_ctx, 3645 int32_t desc_fifo_sz) 3646 { 3647 /* 3648 * The Tx system pipes are not needed for MCC when TX_FLOW_CONTROL_V2 3649 * is enabled, where per vdev descriptors are supported in firmware. 3650 */ 3651 return 0; 3652 } 3653 #endif /* QCA_LL_TX_FLOW_CONTROL_V2 */ 3654 3655 #if defined(CONFIG_IPA_WDI_UNIFIED_API) && defined(IPA_WDI3_GSI) 3656 /** 3657 * wlan_ipa_get_rx_ipa_client() - Get IPA RX ipa client 3658 * @ipa_ctx: IPA context 3659 * 3660 * Return: rx ipa sys client 3661 */ 3662 static inline uint8_t wlan_ipa_get_rx_ipa_client(struct wlan_ipa_priv *ipa_ctx) 3663 { 3664 if (ipa_ctx->over_gsi) 3665 return IPA_CLIENT_WLAN2_PROD; 3666 else 3667 return IPA_CLIENT_WLAN1_PROD; 3668 } 3669 3670 /** 3671 * wlan_ipa_uc_send_wdi_control_msg() - Set WDI control message 3672 * @ctrl: WDI control value 3673 * 3674 * Send WLAN_WDI_ENABLE for ctrl = true and WLAN_WDI_DISABLE otherwise. 3675 * 3676 * Return: QDF_STATUS 3677 */ 3678 static QDF_STATUS wlan_ipa_uc_send_wdi_control_msg(struct wlan_ipa_priv *ipa_ctx, 3679 bool ctrl) 3680 { 3681 return QDF_STATUS_SUCCESS; 3682 } 3683 3684 #else 3685 static inline uint8_t wlan_ipa_get_rx_ipa_client(struct wlan_ipa_priv *ipa_ctx) 3686 { 3687 return IPA_CLIENT_WLAN1_PROD; 3688 } 3689 3690 static QDF_STATUS wlan_ipa_uc_send_wdi_control_msg(struct wlan_ipa_priv *ipa_ctx, 3691 bool ctrl) 3692 { 3693 struct wlan_ipa_priv *ipa_obj = ipa_ctx; 3694 qdf_ipa_msg_meta_t meta; 3695 qdf_ipa_wlan_msg_t *ipa_msg; 3696 int ret = 0; 3697 3698 /* WDI enable message to IPA */ 3699 QDF_IPA_MSG_META_MSG_LEN(&meta) = sizeof(*ipa_msg); 3700 ipa_msg = qdf_mem_malloc(QDF_IPA_MSG_META_MSG_LEN(&meta)); 3701 if (!ipa_msg) 3702 return QDF_STATUS_E_NOMEM; 3703 3704 if (ctrl) { 3705 QDF_IPA_SET_META_MSG_TYPE(&meta, QDF_WDI_ENABLE); 3706 ipa_obj->stats.event[QDF_WDI_ENABLE]++; 3707 } else { 3708 QDF_IPA_SET_META_MSG_TYPE(&meta, QDF_WDI_DISABLE); 3709 ipa_obj->stats.event[QDF_WDI_DISABLE]++; 3710 } 3711 3712 ipa_debug("ipa_send_msg(Evt:%d)", QDF_IPA_MSG_META_MSG_TYPE(&meta)); 3713 ret = qdf_ipa_send_msg(&meta, ipa_msg, wlan_ipa_msg_free_fn); 3714 if (ret) { 3715 ipa_err("ipa_send_msg(Evt:%d)-fail=%d", 3716 QDF_IPA_MSG_META_MSG_TYPE(&meta), ret); 3717 qdf_mem_free(ipa_msg); 3718 return QDF_STATUS_E_FAILURE; 3719 } 3720 3721 return QDF_STATUS_SUCCESS; 3722 } 3723 #endif 3724 3725 /** 3726 * wlan_ipa_setup_rx_sys_pipe() - Setup IPA Rx system pipes 3727 * @ipa_ctx: Global IPA IPA context 3728 * @desc_fifo_sz: Number of descriptors 3729 * 3730 * Return: 0 on success, negative errno on error 3731 */ 3732 static int wlan_ipa_setup_rx_sys_pipe(struct wlan_ipa_priv *ipa_ctx, 3733 int32_t desc_fifo_sz) 3734 { 3735 int ret = 0; 3736 qdf_ipa_sys_connect_params_t *ipa; 3737 3738 /* 3739 * Hard code it here, this can be extended if in case 3740 * PROD pipe is also per interface. 3741 * Right now there is no advantage of doing this. 3742 */ 3743 ipa = &ipa_ctx->sys_pipe[WLAN_IPA_RX_PIPE].ipa_sys_params; 3744 3745 ipa->client = wlan_ipa_get_rx_ipa_client(ipa_ctx); 3746 ipa->desc_fifo_sz = desc_fifo_sz; 3747 ipa->priv = ipa_ctx; 3748 ipa->notify = wlan_ipa_w2i_cb; 3749 3750 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT; 3751 ipa->ipa_ep_cfg.hdr.hdr_len = WLAN_IPA_WLAN_RX_HDR_LEN; 3752 ipa->ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 1; 3753 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC; 3754 3755 ret = qdf_ipa_setup_sys_pipe(ipa, 3756 &ipa_ctx->sys_pipe[WLAN_IPA_RX_PIPE].conn_hdl); 3757 if (ret) { 3758 ipa_err("Failed for RX pipe: %d", ret); 3759 return ret; 3760 } 3761 ipa_ctx->sys_pipe[WLAN_IPA_RX_PIPE].conn_hdl_valid = 1; 3762 3763 return ret; 3764 } 3765 3766 /** 3767 * wlan_ipa_teardown_sys_pipe() - Tear down all IPA Sys pipes 3768 * @ipa_ctx: Global IPA IPA context 3769 * 3770 * Return: None 3771 */ 3772 static void wlan_ipa_teardown_sys_pipe(struct wlan_ipa_priv *ipa_ctx) 3773 { 3774 int ret, i; 3775 3776 if (!ipa_ctx) 3777 return; 3778 3779 for (i = 0; i < WLAN_IPA_MAX_SYSBAM_PIPE; i++) { 3780 if (ipa_ctx->sys_pipe[i].conn_hdl_valid) { 3781 ret = wlan_ipa_wdi_teardown_sys_pipe(ipa_ctx, 3782 ipa_ctx->sys_pipe[i].conn_hdl); 3783 if (ret) 3784 ipa_err("Failed:%d", ret); 3785 3786 ipa_ctx->sys_pipe[i].conn_hdl_valid = 0; 3787 } 3788 } 3789 3790 wlan_ipa_free_tx_desc_list(ipa_ctx); 3791 } 3792 3793 /** 3794 * wlan_ipa_setup_sys_pipe() - Setup all IPA system pipes 3795 * @ipa_ctx: Global IPA IPA context 3796 * 3797 * Return: 0 on success, negative errno on error 3798 */ 3799 static int wlan_ipa_setup_sys_pipe(struct wlan_ipa_priv *ipa_ctx) 3800 { 3801 int ret = 0; 3802 uint32_t desc_fifo_sz; 3803 3804 /* The maximum number of descriptors that can be provided to a BAM at 3805 * once is one less than the total number of descriptors that the buffer 3806 * can contain. 3807 * If max_num_of_descriptors = (BAM_PIPE_DESCRIPTOR_FIFO_SIZE / sizeof 3808 * (SPS_DESCRIPTOR)), then (max_num_of_descriptors - 1) descriptors can 3809 * be provided at once. 3810 * Because of above requirement, one extra descriptor will be added to 3811 * make sure hardware always has one descriptor. 3812 */ 3813 desc_fifo_sz = ipa_ctx->config->desc_size + IPA_SPS_DESC_SIZE; 3814 3815 ret = wlan_ipa_setup_tx_sys_pipe(ipa_ctx, desc_fifo_sz); 3816 if (ret) { 3817 ipa_err("Failed for TX pipe: %d", ret); 3818 goto setup_sys_pipe_fail; 3819 } 3820 3821 if (!wlan_ipa_uc_sta_is_enabled(ipa_ctx->config)) { 3822 ret = wlan_ipa_setup_rx_sys_pipe(ipa_ctx, desc_fifo_sz); 3823 if (ret) { 3824 ipa_err("Failed for RX pipe: %d", ret); 3825 goto setup_sys_pipe_fail; 3826 } 3827 } 3828 3829 /* Allocate free Tx desc list */ 3830 ret = wlan_ipa_alloc_tx_desc_free_list(ipa_ctx); 3831 if (ret) 3832 goto setup_sys_pipe_fail; 3833 3834 return ret; 3835 3836 setup_sys_pipe_fail: 3837 wlan_ipa_teardown_sys_pipe(ipa_ctx); 3838 3839 return ret; 3840 } 3841 3842 #if !defined(QCA_LL_TX_FLOW_CONTROL_V2) && !defined(QCA_IPA_LL_TX_FLOW_CONTROL) 3843 QDF_STATUS wlan_ipa_send_mcc_scc_msg(struct wlan_ipa_priv *ipa_ctx, 3844 bool mcc_mode) 3845 { 3846 qdf_ipa_msg_meta_t meta; 3847 qdf_ipa_wlan_msg_t *msg; 3848 int ret; 3849 3850 if (!wlan_ipa_uc_sta_is_enabled(ipa_ctx->config)) 3851 return QDF_STATUS_SUCCESS; 3852 3853 /* Send SCC/MCC Switching event to IPA */ 3854 QDF_IPA_MSG_META_MSG_LEN(&meta) = sizeof(*msg); 3855 msg = qdf_mem_malloc(QDF_IPA_MSG_META_MSG_LEN(&meta)); 3856 if (!msg) 3857 return QDF_STATUS_E_NOMEM; 3858 3859 if (mcc_mode) { 3860 QDF_IPA_SET_META_MSG_TYPE(&meta, QDF_SWITCH_TO_MCC); 3861 ipa_ctx->stats.event[QDF_SWITCH_TO_MCC]++; 3862 } else { 3863 QDF_IPA_SET_META_MSG_TYPE(&meta, QDF_SWITCH_TO_SCC); 3864 ipa_ctx->stats.event[QDF_SWITCH_TO_SCC]++; 3865 } 3866 3867 WLAN_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, 3868 "ipa_send_msg(Evt:%d)", 3869 QDF_IPA_MSG_META_MSG_TYPE(&meta)); 3870 3871 ret = qdf_ipa_send_msg(&meta, msg, wlan_ipa_msg_free_fn); 3872 3873 if (ret) { 3874 ipa_err("ipa_send_msg(Evt:%d) - fail=%d", 3875 QDF_IPA_MSG_META_MSG_TYPE(&meta), ret); 3876 qdf_mem_free(msg); 3877 return QDF_STATUS_E_FAILURE; 3878 } 3879 3880 return QDF_STATUS_SUCCESS; 3881 } 3882 3883 static void wlan_ipa_mcc_work_handler(void *data) 3884 { 3885 struct wlan_ipa_priv *ipa_ctx = (struct wlan_ipa_priv *)data; 3886 3887 wlan_ipa_send_mcc_scc_msg(ipa_ctx, ipa_ctx->mcc_mode); 3888 } 3889 #endif 3890 3891 /** 3892 * wlan_ipa_setup() - IPA initialization function 3893 * @ipa_ctx: IPA context 3894 * @ipa_cfg: IPA config 3895 * 3896 * Allocate ipa_ctx resources, ipa pipe resource and register 3897 * wlan interface with IPA module. 3898 * 3899 * Return: QDF_STATUS enumeration 3900 */ 3901 QDF_STATUS wlan_ipa_setup(struct wlan_ipa_priv *ipa_ctx, 3902 struct wlan_ipa_config *ipa_cfg) 3903 { 3904 int ret, i; 3905 struct wlan_ipa_iface_context *iface_context = NULL; 3906 QDF_STATUS status; 3907 3908 ipa_debug("enter"); 3909 3910 gp_ipa = ipa_ctx; 3911 ipa_ctx->num_iface = 0; 3912 ipa_ctx->config = ipa_cfg; 3913 3914 wlan_ipa_wdi_get_wdi_version(ipa_ctx); 3915 3916 /* Create the interface context */ 3917 for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) { 3918 iface_context = &ipa_ctx->iface_context[i]; 3919 iface_context->ipa_ctx = ipa_ctx; 3920 iface_context->cons_client = 3921 wlan_ipa_iface_2_client[i].cons_client; 3922 iface_context->prod_client = 3923 wlan_ipa_iface_2_client[i].prod_client; 3924 iface_context->iface_id = i; 3925 iface_context->dev = NULL; 3926 iface_context->device_mode = QDF_MAX_NO_OF_MODE; 3927 iface_context->session_id = WLAN_IPA_MAX_SESSION; 3928 qdf_atomic_init(&iface_context->conn_count); 3929 qdf_atomic_init(&iface_context->disconn_count); 3930 qdf_spinlock_create(&iface_context->interface_lock); 3931 } 3932 3933 qdf_create_work(0, &ipa_ctx->pm_work, wlan_ipa_pm_flush, ipa_ctx); 3934 qdf_spinlock_create(&ipa_ctx->pm_lock); 3935 qdf_spinlock_create(&ipa_ctx->q_lock); 3936 qdf_spinlock_create(&ipa_ctx->enable_disable_lock); 3937 ipa_ctx->pipes_down_in_progress = false; 3938 ipa_ctx->pipes_enable_in_progress = false; 3939 qdf_nbuf_queue_init(&ipa_ctx->pm_queue_head); 3940 qdf_list_create(&ipa_ctx->pending_event, 1000); 3941 qdf_mutex_create(&ipa_ctx->event_lock); 3942 qdf_mutex_create(&ipa_ctx->ipa_lock); 3943 qdf_atomic_init(&ipa_ctx->deinit_in_prog); 3944 3945 status = wlan_ipa_wdi_setup_rm(ipa_ctx); 3946 if (status != QDF_STATUS_SUCCESS) 3947 goto fail_setup_rm; 3948 3949 for (i = 0; i < WLAN_IPA_MAX_SYSBAM_PIPE; i++) 3950 qdf_mem_zero(&ipa_ctx->sys_pipe[i], 3951 sizeof(struct wlan_ipa_sys_pipe)); 3952 3953 if (wlan_ipa_uc_is_enabled(ipa_ctx->config)) { 3954 qdf_mem_zero(&ipa_ctx->stats, sizeof(ipa_ctx->stats)); 3955 ipa_ctx->sap_num_connected_sta = 0; 3956 ipa_ctx->ipa_tx_packets_diff = 0; 3957 ipa_ctx->ipa_rx_packets_diff = 0; 3958 ipa_ctx->ipa_p_tx_packets = 0; 3959 ipa_ctx->ipa_p_rx_packets = 0; 3960 ipa_ctx->resource_loading = false; 3961 ipa_ctx->resource_unloading = false; 3962 ipa_ctx->num_sap_connected = 0; 3963 ipa_ctx->sta_connected = 0; 3964 ipa_ctx->ipa_pipes_down = true; 3965 qdf_atomic_set(&ipa_ctx->pipes_disabled, 1); 3966 qdf_atomic_set(&ipa_ctx->autonomy_disabled, 1); 3967 ipa_ctx->wdi_enabled = false; 3968 3969 status = wlan_ipa_wdi_init(ipa_ctx); 3970 if (status == QDF_STATUS_SUCCESS) { 3971 /* Setup IPA system pipes */ 3972 if (wlan_ipa_uc_sta_is_enabled(ipa_ctx->config)) { 3973 ret = wlan_ipa_setup_sys_pipe(ipa_ctx); 3974 if (ret) 3975 goto ipa_wdi_destroy; 3976 3977 qdf_create_work(0, &ipa_ctx->mcc_work, 3978 wlan_ipa_mcc_work_handler, 3979 ipa_ctx); 3980 } 3981 } else if (status == QDF_STATUS_E_BUSY) { 3982 ret = wlan_ipa_uc_send_wdi_control_msg(ipa_ctx, false); 3983 if (ret) { 3984 ipa_err("IPA WDI msg send failed: ret=%d", ret); 3985 goto ipa_wdi_destroy; 3986 } 3987 } else { 3988 ipa_err("IPA WDI init failed: ret=%d", status); 3989 goto ipa_wdi_destroy; 3990 } 3991 } else { 3992 ret = wlan_ipa_setup_sys_pipe(ipa_ctx); 3993 if (ret) 3994 goto ipa_wdi_destroy; 3995 } 3996 3997 qdf_event_create(&ipa_ctx->ipa_resource_comp); 3998 3999 ipa_debug("exit: success"); 4000 4001 return QDF_STATUS_SUCCESS; 4002 4003 ipa_wdi_destroy: 4004 wlan_ipa_wdi_destroy_rm(ipa_ctx); 4005 4006 fail_setup_rm: 4007 qdf_spinlock_destroy(&ipa_ctx->pm_lock); 4008 qdf_spinlock_destroy(&ipa_ctx->q_lock); 4009 qdf_spinlock_destroy(&ipa_ctx->enable_disable_lock); 4010 for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) { 4011 iface_context = &ipa_ctx->iface_context[i]; 4012 qdf_spinlock_destroy(&iface_context->interface_lock); 4013 } 4014 qdf_mutex_destroy(&ipa_ctx->event_lock); 4015 qdf_mutex_destroy(&ipa_ctx->ipa_lock); 4016 qdf_list_destroy(&ipa_ctx->pending_event); 4017 gp_ipa = NULL; 4018 ipa_debug("exit: fail"); 4019 4020 return QDF_STATUS_E_FAILURE; 4021 } 4022 4023 void wlan_ipa_flush(struct wlan_ipa_priv *ipa_ctx) 4024 { 4025 qdf_nbuf_t skb; 4026 struct wlan_ipa_pm_tx_cb *pm_tx_cb; 4027 4028 if (!wlan_ipa_is_enabled(ipa_ctx->config)) 4029 return; 4030 4031 qdf_cancel_work(&ipa_ctx->pm_work); 4032 4033 qdf_spin_lock_bh(&ipa_ctx->pm_lock); 4034 4035 while (((skb = qdf_nbuf_queue_remove(&ipa_ctx->pm_queue_head)) 4036 != NULL)) { 4037 qdf_spin_unlock_bh(&ipa_ctx->pm_lock); 4038 4039 pm_tx_cb = (struct wlan_ipa_pm_tx_cb *)skb->cb; 4040 4041 if (pm_tx_cb->exception) { 4042 dev_kfree_skb_any(skb); 4043 } else { 4044 if (pm_tx_cb->ipa_tx_desc) 4045 ipa_free_skb(pm_tx_cb->ipa_tx_desc); 4046 } 4047 4048 qdf_spin_lock_bh(&ipa_ctx->pm_lock); 4049 } 4050 qdf_spin_unlock_bh(&ipa_ctx->pm_lock); 4051 } 4052 4053 QDF_STATUS wlan_ipa_cleanup(struct wlan_ipa_priv *ipa_ctx) 4054 { 4055 struct wlan_ipa_iface_context *iface_context; 4056 int i; 4057 4058 if (!ipa_cb_is_ready()) 4059 return QDF_STATUS_SUCCESS; 4060 qdf_event_destroy(&ipa_ctx->ipa_resource_comp); 4061 if (!wlan_ipa_uc_is_enabled(ipa_ctx->config)) 4062 wlan_ipa_teardown_sys_pipe(ipa_ctx); 4063 4064 /* Teardown IPA sys_pipe for MCC */ 4065 if (wlan_ipa_uc_sta_is_enabled(ipa_ctx->config)) { 4066 wlan_ipa_teardown_sys_pipe(ipa_ctx); 4067 if (ipa_ctx->uc_loaded) 4068 qdf_cancel_work(&ipa_ctx->mcc_work); 4069 } 4070 4071 wlan_ipa_wdi_destroy_rm(ipa_ctx); 4072 4073 wlan_ipa_flush(ipa_ctx); 4074 4075 qdf_spinlock_destroy(&ipa_ctx->pm_lock); 4076 qdf_spinlock_destroy(&ipa_ctx->q_lock); 4077 qdf_spinlock_destroy(&ipa_ctx->enable_disable_lock); 4078 qdf_destroy_work(0, &ipa_ctx->pm_work); 4079 4080 /* destroy the interface lock */ 4081 for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) { 4082 iface_context = &ipa_ctx->iface_context[i]; 4083 qdf_spinlock_destroy(&iface_context->interface_lock); 4084 } 4085 4086 if (wlan_ipa_uc_is_enabled(ipa_ctx->config)) { 4087 wlan_ipa_wdi_cleanup(ipa_ctx->hdl); 4088 qdf_mutex_destroy(&ipa_ctx->event_lock); 4089 qdf_mutex_destroy(&ipa_ctx->ipa_lock); 4090 qdf_list_destroy(&ipa_ctx->pending_event); 4091 4092 } 4093 4094 gp_ipa = NULL; 4095 4096 /* Acquire lock */ 4097 ipa_init_deinit_lock(); 4098 if (g_instances_added) 4099 g_instances_added--; 4100 /* Unlock */ 4101 ipa_init_deinit_unlock(); 4102 4103 ipa_ctx->handle_initialized = false; 4104 4105 return QDF_STATUS_SUCCESS; 4106 } 4107 4108 struct wlan_ipa_iface_context 4109 *wlan_ipa_get_iface(struct wlan_ipa_priv *ipa_ctx, uint8_t mode) 4110 { 4111 struct wlan_ipa_iface_context *iface_ctx = NULL; 4112 int i; 4113 4114 for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) { 4115 iface_ctx = &ipa_ctx->iface_context[i]; 4116 4117 if (iface_ctx->device_mode == mode) 4118 return iface_ctx; 4119 } 4120 4121 return NULL; 4122 } 4123 4124 struct wlan_ipa_iface_context * 4125 wlan_ipa_get_iface_by_mode_netdev(struct wlan_ipa_priv *ipa_ctx, 4126 qdf_netdev_t ndev, uint8_t mode) 4127 { 4128 struct wlan_ipa_iface_context *iface_ctx = NULL; 4129 int i; 4130 4131 for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) { 4132 iface_ctx = &ipa_ctx->iface_context[i]; 4133 4134 if (iface_ctx->device_mode == mode && iface_ctx->dev == ndev) 4135 return iface_ctx; 4136 } 4137 4138 return NULL; 4139 } 4140 4141 void wlan_ipa_set_mcc_mode(struct wlan_ipa_priv *ipa_ctx, bool mcc_mode) 4142 { 4143 if (!wlan_ipa_uc_sta_is_enabled(ipa_ctx->config)) 4144 return; 4145 4146 if (ipa_ctx->mcc_mode == mcc_mode) 4147 return; 4148 4149 ipa_ctx->mcc_mode = mcc_mode; 4150 qdf_sched_work(0, &ipa_ctx->mcc_work); 4151 } 4152 4153 /** 4154 * wlan_ipa_uc_loaded_handler() - Process IPA uC loaded indication 4155 * @ipa_ctx: ipa ipa local context 4156 * 4157 * Will handle IPA UC image loaded indication comes from IPA kernel 4158 * 4159 * Return: None 4160 */ 4161 static void wlan_ipa_uc_loaded_handler(struct wlan_ipa_priv *ipa_ctx) 4162 { 4163 struct wlan_objmgr_pdev *pdev = ipa_ctx->pdev; 4164 struct wlan_objmgr_psoc *psoc = wlan_pdev_get_psoc(pdev); 4165 qdf_device_t qdf_dev = wlan_psoc_get_qdf_dev(psoc); 4166 QDF_STATUS status; 4167 4168 ipa_info("UC READY"); 4169 4170 if (true == ipa_ctx->uc_loaded) { 4171 ipa_info("UC already loaded"); 4172 return; 4173 } 4174 4175 if (!qdf_dev) { 4176 ipa_err("qdf_dev is null"); 4177 return; 4178 } 4179 4180 if (wlan_ipa_uc_sta_is_enabled(ipa_ctx->config)) { 4181 /* Setup IPA system pipes */ 4182 status = wlan_ipa_setup_sys_pipe(ipa_ctx); 4183 if (status) { 4184 ipa_err("Fail to setup sys pipes (status=%d)", status); 4185 return; 4186 } 4187 qdf_create_work(0, &ipa_ctx->mcc_work, 4188 wlan_ipa_mcc_work_handler, ipa_ctx); 4189 } 4190 4191 /* Connect pipe */ 4192 status = wlan_ipa_wdi_setup(ipa_ctx, qdf_dev); 4193 if (status) { 4194 ipa_err("Failure to setup IPA pipes (status=%d)", 4195 status); 4196 goto connect_pipe_fail; 4197 } 4198 /* Setup the Tx buffer SMMU mapings */ 4199 status = cdp_ipa_tx_buf_smmu_mapping(ipa_ctx->dp_soc, 4200 ipa_ctx->dp_pdev_id); 4201 if (status) { 4202 ipa_err("Failure to map Tx buffers for IPA(status=%d)", 4203 status); 4204 goto smmu_map_fail; 4205 } 4206 ipa_info("TX buffers mapped to IPA"); 4207 cdp_ipa_set_doorbell_paddr(ipa_ctx->dp_soc, ipa_ctx->dp_pdev_id); 4208 wlan_ipa_init_metering(ipa_ctx); 4209 4210 if (QDF_IS_STATUS_ERROR(wlan_ipa_init_perf_level(ipa_ctx))) 4211 ipa_err("Failed to init perf level"); 4212 4213 /* 4214 * Enable IPA/FW PIPEs if 4215 * 1. any clients connected to SAP or 4216 * 2. STA connected to remote AP if STA only offload is enabled 4217 */ 4218 if (ipa_ctx->sap_num_connected_sta || 4219 (wlan_ipa_is_sta_only_offload_enabled() && 4220 ipa_ctx->sta_connected)) { 4221 ipa_debug("Client already connected, enable IPA/FW PIPEs"); 4222 wlan_ipa_uc_handle_first_con(ipa_ctx); 4223 } 4224 4225 ipa_ctx->uc_loaded = true; 4226 4227 return; 4228 4229 smmu_map_fail: 4230 qdf_ipa_wdi_disconn_pipes(ipa_ctx->hdl); 4231 4232 connect_pipe_fail: 4233 if (wlan_ipa_uc_sta_is_enabled(ipa_ctx->config)) { 4234 qdf_cancel_work(&ipa_ctx->mcc_work); 4235 wlan_ipa_teardown_sys_pipe(ipa_ctx); 4236 } 4237 } 4238 4239 /** 4240 * wlan_ipa_uc_op_cb() - IPA uC operation callback 4241 * @op_msg: operation message received from firmware 4242 * @usr_ctxt: user context registered with TL (we register the IPA Global 4243 * context) 4244 * 4245 * Return: None 4246 */ 4247 static void wlan_ipa_uc_op_cb(struct op_msg_type *op_msg, 4248 struct wlan_ipa_priv *ipa_ctx) 4249 { 4250 struct op_msg_type *msg = op_msg; 4251 struct ipa_uc_fw_stats *uc_fw_stat; 4252 4253 if (!ipa_ctx || !op_msg) { 4254 ipa_err("INVALID ARG"); 4255 return; 4256 } 4257 4258 if (msg->op_code >= WLAN_IPA_UC_OPCODE_MAX) { 4259 ipa_err("INVALID OPCODE %d", msg->op_code); 4260 qdf_mem_free(op_msg); 4261 return; 4262 } 4263 4264 ipa_debug("OPCODE=%d", msg->op_code); 4265 4266 if ((msg->op_code == WLAN_IPA_UC_OPCODE_TX_RESUME) || 4267 (msg->op_code == WLAN_IPA_UC_OPCODE_RX_RESUME)) { 4268 qdf_mutex_acquire(&ipa_ctx->ipa_lock); 4269 ipa_ctx->activated_fw_pipe++; 4270 if (wlan_ipa_is_fw_wdi_activated(ipa_ctx)) { 4271 ipa_ctx->resource_loading = false; 4272 qdf_event_set(&ipa_ctx->ipa_resource_comp); 4273 if (ipa_ctx->wdi_enabled == false) { 4274 ipa_ctx->wdi_enabled = true; 4275 if (wlan_ipa_uc_send_wdi_control_msg(ipa_ctx, true) == 0) 4276 wlan_ipa_send_mcc_scc_msg(ipa_ctx, 4277 ipa_ctx->mcc_mode); 4278 } 4279 wlan_ipa_uc_proc_pending_event(ipa_ctx, true); 4280 if (ipa_ctx->pending_cons_req) 4281 wlan_ipa_wdi_rm_notify_completion( 4282 QDF_IPA_RM_RESOURCE_GRANTED, 4283 QDF_IPA_RM_RESOURCE_WLAN_CONS); 4284 ipa_ctx->pending_cons_req = false; 4285 } 4286 qdf_mutex_release(&ipa_ctx->ipa_lock); 4287 } else if ((msg->op_code == WLAN_IPA_UC_OPCODE_TX_SUSPEND) || 4288 (msg->op_code == WLAN_IPA_UC_OPCODE_RX_SUSPEND)) { 4289 qdf_mutex_acquire(&ipa_ctx->ipa_lock); 4290 4291 if (msg->op_code == WLAN_IPA_UC_OPCODE_RX_SUSPEND) { 4292 wlan_ipa_uc_disable_pipes(ipa_ctx, true); 4293 ipa_info("Disable FW TX PIPE"); 4294 cdp_ipa_set_active(ipa_ctx->dp_soc, ipa_ctx->dp_pdev_id, 4295 false, true); 4296 } 4297 4298 ipa_ctx->activated_fw_pipe--; 4299 if (!ipa_ctx->activated_fw_pipe) { 4300 /* 4301 * Async return success from FW 4302 * Disable/suspend all the PIPEs 4303 */ 4304 ipa_ctx->resource_unloading = false; 4305 qdf_event_set(&ipa_ctx->ipa_resource_comp); 4306 if (wlan_ipa_is_rm_enabled(ipa_ctx->config)) 4307 wlan_ipa_wdi_rm_release_resource(ipa_ctx, 4308 QDF_IPA_RM_RESOURCE_WLAN_PROD); 4309 wlan_ipa_uc_proc_pending_event(ipa_ctx, false); 4310 ipa_ctx->pending_cons_req = false; 4311 } 4312 qdf_mutex_release(&ipa_ctx->ipa_lock); 4313 } else if ((msg->op_code == WLAN_IPA_UC_OPCODE_STATS) && 4314 (ipa_ctx->stat_req_reason == WLAN_IPA_UC_STAT_REASON_DEBUG)) { 4315 uc_fw_stat = (struct ipa_uc_fw_stats *) 4316 ((uint8_t *)op_msg + sizeof(struct op_msg_type)); 4317 4318 /* WLAN FW WDI stats */ 4319 wlan_ipa_print_fw_wdi_stats(ipa_ctx, uc_fw_stat); 4320 } else if ((msg->op_code == WLAN_IPA_UC_OPCODE_STATS) && 4321 (ipa_ctx->stat_req_reason == WLAN_IPA_UC_STAT_REASON_BW_CAL)) { 4322 /* STATs from FW */ 4323 uc_fw_stat = (struct ipa_uc_fw_stats *) 4324 ((uint8_t *)op_msg + sizeof(struct op_msg_type)); 4325 qdf_mutex_acquire(&ipa_ctx->ipa_lock); 4326 ipa_ctx->ipa_tx_packets_diff = BW_GET_DIFF( 4327 uc_fw_stat->tx_pkts_completed, 4328 ipa_ctx->ipa_p_tx_packets); 4329 ipa_ctx->ipa_rx_packets_diff = BW_GET_DIFF( 4330 (uc_fw_stat->rx_num_ind_drop_no_space + 4331 uc_fw_stat->rx_num_ind_drop_no_buf + 4332 uc_fw_stat->rx_num_pkts_indicated), 4333 ipa_ctx->ipa_p_rx_packets); 4334 4335 ipa_ctx->ipa_p_tx_packets = uc_fw_stat->tx_pkts_completed; 4336 ipa_ctx->ipa_p_rx_packets = 4337 (uc_fw_stat->rx_num_ind_drop_no_space + 4338 uc_fw_stat->rx_num_ind_drop_no_buf + 4339 uc_fw_stat->rx_num_pkts_indicated); 4340 qdf_mutex_release(&ipa_ctx->ipa_lock); 4341 } else if (msg->op_code == WLAN_IPA_UC_OPCODE_UC_READY) { 4342 qdf_mutex_acquire(&ipa_ctx->ipa_lock); 4343 wlan_ipa_uc_loaded_handler(ipa_ctx); 4344 qdf_mutex_release(&ipa_ctx->ipa_lock); 4345 } else if (wlan_ipa_uc_op_metering(ipa_ctx, op_msg)) { 4346 ipa_err("Invalid message: op_code=%d, reason=%d", 4347 msg->op_code, ipa_ctx->stat_req_reason); 4348 } 4349 4350 qdf_mem_free(op_msg); 4351 } 4352 4353 /** 4354 * __wlan_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler 4355 * @data: uC OP work 4356 * 4357 * Return: None 4358 */ 4359 static void __wlan_ipa_uc_fw_op_event_handler(void *data) 4360 { 4361 struct op_msg_type *msg; 4362 struct uc_op_work_struct *uc_op_work = 4363 (struct uc_op_work_struct *)data; 4364 struct wlan_ipa_priv *ipa_ctx = uc_op_work->ipa_priv_bp; 4365 4366 msg = uc_op_work->msg; 4367 uc_op_work->msg = NULL; 4368 ipa_debug("posted msg %d", msg->op_code); 4369 4370 wlan_ipa_uc_op_cb(msg, ipa_ctx); 4371 } 4372 4373 /** 4374 * wlan_ipa_uc_fw_op_event_handler - SSR wrapper for 4375 * __wlan_ipa_uc_fw_op_event_handler 4376 * @data: uC OP work 4377 * 4378 * Return: None 4379 */ 4380 static void wlan_ipa_uc_fw_op_event_handler(void *data) 4381 { 4382 if (qdf_is_recovering()) { 4383 ipa_err("in recovering"); 4384 return; 4385 } 4386 4387 __wlan_ipa_uc_fw_op_event_handler(data); 4388 } 4389 4390 /** 4391 * wlan_ipa_uc_op_event_handler() - IPA UC OP event handler 4392 * @op_msg: operation message received from firmware 4393 * @ipa_ctx: Global IPA context 4394 * 4395 * Return: None 4396 */ 4397 static void wlan_ipa_uc_op_event_handler(uint8_t *op_msg, void *ctx) 4398 { 4399 struct wlan_ipa_priv *ipa_ctx = (struct wlan_ipa_priv *)ctx; 4400 struct op_msg_type *msg; 4401 struct uc_op_work_struct *uc_op_work; 4402 4403 if (!ipa_ctx) 4404 goto end; 4405 4406 msg = (struct op_msg_type *)op_msg; 4407 4408 if (msg->op_code >= WLAN_IPA_UC_OPCODE_MAX) { 4409 ipa_err("Invalid OP Code (%d)", msg->op_code); 4410 goto end; 4411 } 4412 4413 uc_op_work = &ipa_ctx->uc_op_work[msg->op_code]; 4414 if (uc_op_work->msg) { 4415 /* When the same uC OPCODE is already pended, just return */ 4416 goto end; 4417 } 4418 4419 uc_op_work->msg = msg; 4420 qdf_sched_work(0, &uc_op_work->work); 4421 return; 4422 4423 end: 4424 qdf_mem_free(op_msg); 4425 } 4426 4427 QDF_STATUS wlan_ipa_uc_ol_init(struct wlan_ipa_priv *ipa_ctx, 4428 qdf_device_t osdev) 4429 { 4430 uint8_t i; 4431 QDF_STATUS status = QDF_STATUS_SUCCESS; 4432 4433 if (!wlan_ipa_uc_is_enabled(ipa_ctx->config)) 4434 return QDF_STATUS_SUCCESS; 4435 4436 ipa_debug("enter"); 4437 4438 if (!osdev) { 4439 ipa_err("osdev null"); 4440 status = QDF_STATUS_E_FAILURE; 4441 goto fail_return; 4442 } 4443 4444 for (i = 0; i < WLAN_IPA_MAX_SESSION; i++) { 4445 ipa_ctx->vdev_to_iface[i] = WLAN_IPA_MAX_SESSION; 4446 ipa_ctx->vdev_offload_enabled[i] = false; 4447 ipa_ctx->disable_intrabss_fwd[i] = false; 4448 } 4449 4450 if (cdp_ipa_get_resource(ipa_ctx->dp_soc, ipa_ctx->dp_pdev_id)) { 4451 ipa_err("IPA UC resource alloc fail"); 4452 status = QDF_STATUS_E_FAILURE; 4453 goto fail_return; 4454 } 4455 4456 for (i = 0; i < WLAN_IPA_UC_OPCODE_MAX; i++) { 4457 ipa_ctx->uc_op_work[i].osdev = osdev; 4458 ipa_ctx->uc_op_work[i].msg = NULL; 4459 ipa_ctx->uc_op_work[i].ipa_priv_bp = ipa_ctx; 4460 qdf_create_work(0, &ipa_ctx->uc_op_work[i].work, 4461 wlan_ipa_uc_fw_op_event_handler, 4462 &ipa_ctx->uc_op_work[i]); 4463 } 4464 4465 if (true == ipa_ctx->uc_loaded) { 4466 status = wlan_ipa_wdi_setup(ipa_ctx, osdev); 4467 if (status) { 4468 ipa_err("Failure to setup IPA pipes (status=%d)", 4469 status); 4470 status = QDF_STATUS_E_FAILURE; 4471 4472 if (wlan_ipa_uc_sta_is_enabled(ipa_ctx->config)) { 4473 qdf_cancel_work(&ipa_ctx->mcc_work); 4474 wlan_ipa_teardown_sys_pipe(ipa_ctx); 4475 } 4476 ipa_ctx->uc_loaded = false; 4477 4478 goto fail_return; 4479 } 4480 4481 /* Setup the Tx buffer SMMU mapings */ 4482 status = cdp_ipa_tx_buf_smmu_mapping(ipa_ctx->dp_soc, 4483 ipa_ctx->dp_pdev_id); 4484 if (status) { 4485 ipa_err("Failure to map Tx buffers for IPA(status=%d)", 4486 status); 4487 return status; 4488 } 4489 ipa_info("TX buffers mapped to IPA"); 4490 cdp_ipa_set_doorbell_paddr(ipa_ctx->dp_soc, 4491 ipa_ctx->dp_pdev_id); 4492 wlan_ipa_init_metering(ipa_ctx); 4493 4494 if (wlan_ipa_init_perf_level(ipa_ctx) != QDF_STATUS_SUCCESS) 4495 ipa_err("Failed to init perf level"); 4496 } 4497 4498 cdp_ipa_register_op_cb(ipa_ctx->dp_soc, ipa_ctx->dp_pdev_id, 4499 wlan_ipa_uc_op_event_handler, (void *)ipa_ctx); 4500 fail_return: 4501 ipa_debug("exit: status=%d", status); 4502 return status; 4503 } 4504 4505 /** 4506 * wlan_ipa_cleanup_pending_event() - Cleanup IPA pending event list 4507 * @ipa_ctx: pointer to IPA IPA struct 4508 * 4509 * Return: none 4510 */ 4511 static void wlan_ipa_cleanup_pending_event(struct wlan_ipa_priv *ipa_ctx) 4512 { 4513 struct wlan_ipa_uc_pending_event *pending_event = NULL; 4514 4515 while (qdf_list_remove_front(&ipa_ctx->pending_event, 4516 (qdf_list_node_t **)&pending_event) == QDF_STATUS_SUCCESS) 4517 qdf_mem_free(pending_event); 4518 } 4519 4520 QDF_STATUS wlan_ipa_uc_ol_deinit(struct wlan_ipa_priv *ipa_ctx) 4521 { 4522 QDF_STATUS status = QDF_STATUS_SUCCESS; 4523 int i; 4524 4525 ipa_debug("enter"); 4526 4527 if (!wlan_ipa_uc_is_enabled(ipa_ctx->config)) 4528 return status; 4529 4530 wlan_ipa_uc_disable_pipes(ipa_ctx, true); 4531 4532 cdp_ipa_deregister_op_cb(ipa_ctx->dp_soc, ipa_ctx->dp_pdev_id); 4533 qdf_atomic_set(&ipa_ctx->deinit_in_prog, 1); 4534 4535 for (i = 0; i < WLAN_IPA_UC_OPCODE_MAX; i++) { 4536 qdf_cancel_work(&ipa_ctx->uc_op_work[i].work); 4537 qdf_mem_free(ipa_ctx->uc_op_work[i].msg); 4538 ipa_ctx->uc_op_work[i].msg = NULL; 4539 } 4540 4541 cdp_ipa_iounmap_doorbell_vaddr(ipa_ctx->dp_soc, 4542 ipa_ctx->dp_pdev_id); 4543 4544 if (true == ipa_ctx->uc_loaded) { 4545 cdp_ipa_tx_buf_smmu_unmapping(ipa_ctx->dp_soc, 4546 ipa_ctx->dp_pdev_id); 4547 status = cdp_ipa_cleanup(ipa_ctx->dp_soc, 4548 ipa_ctx->dp_pdev_id, 4549 ipa_ctx->tx_pipe_handle, 4550 ipa_ctx->rx_pipe_handle, ipa_ctx->hdl); 4551 if (status) 4552 ipa_err("Failure to cleanup IPA pipes (status=%d)", 4553 status); 4554 } 4555 4556 qdf_mutex_acquire(&ipa_ctx->ipa_lock); 4557 wlan_ipa_cleanup_pending_event(ipa_ctx); 4558 qdf_mutex_release(&ipa_ctx->ipa_lock); 4559 4560 ipa_debug("exit: ret=%d", status); 4561 return status; 4562 } 4563 4564 /** 4565 * wlan_ipa_uc_send_evt() - send event to ipa 4566 * @net_dev: Interface net device 4567 * @type: event type 4568 * @mac_addr: pointer to mac address 4569 * 4570 * Send event to IPA driver 4571 * 4572 * Return: QDF_STATUS 4573 */ 4574 static QDF_STATUS wlan_ipa_uc_send_evt(qdf_netdev_t net_dev, 4575 qdf_ipa_wlan_event type, 4576 uint8_t *mac_addr, 4577 struct wlan_ipa_priv *ipa_priv) 4578 { 4579 struct wlan_ipa_priv *ipa_ctx; 4580 qdf_ipa_msg_meta_t meta; 4581 qdf_ipa_wlan_msg_t *msg; 4582 4583 if (!ipa_priv) 4584 return QDF_STATUS_E_INVAL; 4585 4586 ipa_ctx = ipa_priv; 4587 4588 QDF_IPA_MSG_META_MSG_LEN(&meta) = sizeof(qdf_ipa_wlan_msg_t); 4589 msg = qdf_mem_malloc(QDF_IPA_MSG_META_MSG_LEN(&meta)); 4590 if (!msg) 4591 return QDF_STATUS_E_NOMEM; 4592 4593 QDF_IPA_SET_META_MSG_TYPE(&meta, type); 4594 qdf_str_lcopy(QDF_IPA_WLAN_MSG_NAME(msg), net_dev->name, 4595 IPA_RESOURCE_NAME_MAX); 4596 qdf_mem_copy(QDF_IPA_WLAN_MSG_MAC_ADDR(msg), mac_addr, QDF_NET_ETH_LEN); 4597 QDF_IPA_WLAN_MSG_NETDEV_IF_ID(msg) = net_dev->ifindex; 4598 4599 if (qdf_ipa_send_msg(&meta, msg, wlan_ipa_msg_free_fn)) { 4600 ipa_err("%s: Evt: %d fail", 4601 QDF_IPA_WLAN_MSG_NAME(msg), 4602 QDF_IPA_MSG_META_MSG_TYPE(&meta)); 4603 qdf_mem_free(msg); 4604 4605 return QDF_STATUS_E_FAILURE; 4606 } 4607 4608 ipa_ctx->stats.num_send_msg++; 4609 4610 return QDF_STATUS_SUCCESS; 4611 } 4612 4613 void wlan_ipa_uc_cleanup_sta(struct wlan_ipa_priv *ipa_ctx, 4614 qdf_netdev_t net_dev) 4615 { 4616 struct wlan_ipa_iface_context *iface_ctx; 4617 int i; 4618 4619 ipa_debug("enter"); 4620 4621 for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) { 4622 iface_ctx = &ipa_ctx->iface_context[i]; 4623 if (iface_ctx && iface_ctx->device_mode == QDF_STA_MODE && 4624 iface_ctx->dev && iface_ctx->dev == net_dev) { 4625 wlan_ipa_uc_send_evt(net_dev, QDF_IPA_STA_DISCONNECT, 4626 net_dev->dev_addr, ipa_ctx); 4627 wlan_ipa_cleanup_iface(iface_ctx, NULL); 4628 } 4629 } 4630 4631 ipa_debug("exit"); 4632 } 4633 4634 QDF_STATUS wlan_ipa_uc_disconnect_ap(struct wlan_ipa_priv *ipa_ctx, 4635 qdf_netdev_t net_dev) 4636 { 4637 struct wlan_ipa_iface_context *iface_ctx; 4638 QDF_STATUS status; 4639 4640 ipa_debug("enter"); 4641 4642 iface_ctx = wlan_ipa_get_iface(ipa_ctx, QDF_SAP_MODE); 4643 if (iface_ctx) 4644 status = wlan_ipa_uc_send_evt(net_dev, QDF_IPA_AP_DISCONNECT, 4645 net_dev->dev_addr, ipa_ctx); 4646 else 4647 return QDF_STATUS_E_INVAL; 4648 4649 ipa_debug("exit :%d", status); 4650 4651 return status; 4652 } 4653 4654 void wlan_ipa_cleanup_dev_iface(struct wlan_ipa_priv *ipa_ctx, 4655 qdf_netdev_t net_dev) 4656 { 4657 struct wlan_ipa_iface_context *iface_ctx; 4658 int i; 4659 4660 for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) { 4661 iface_ctx = &ipa_ctx->iface_context[i]; 4662 if (iface_ctx->dev == net_dev) { 4663 wlan_ipa_cleanup_iface(iface_ctx, NULL); 4664 break; 4665 } 4666 } 4667 } 4668 4669 void wlan_ipa_uc_ssr_cleanup(struct wlan_ipa_priv *ipa_ctx) 4670 { 4671 struct wlan_ipa_iface_context *iface; 4672 int i; 4673 4674 ipa_info("enter"); 4675 4676 for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) { 4677 iface = &ipa_ctx->iface_context[i]; 4678 if (iface->dev) { 4679 if (iface->device_mode == QDF_SAP_MODE) 4680 wlan_ipa_uc_send_evt(iface->dev, 4681 QDF_IPA_AP_DISCONNECT, 4682 iface->dev->dev_addr, 4683 ipa_ctx); 4684 else if (iface->device_mode == QDF_STA_MODE) 4685 wlan_ipa_uc_send_evt(iface->dev, 4686 QDF_IPA_STA_DISCONNECT, 4687 iface->dev->dev_addr, 4688 ipa_ctx); 4689 wlan_ipa_cleanup_iface(iface, NULL); 4690 } 4691 } 4692 } 4693 4694 void wlan_ipa_fw_rejuvenate_send_msg(struct wlan_ipa_priv *ipa_ctx) 4695 { 4696 qdf_ipa_msg_meta_t meta; 4697 qdf_ipa_wlan_msg_t *msg; 4698 int ret; 4699 4700 meta.msg_len = sizeof(*msg); 4701 msg = qdf_mem_malloc(meta.msg_len); 4702 if (!msg) 4703 return; 4704 4705 QDF_IPA_SET_META_MSG_TYPE(&meta, QDF_FWR_SSR_BEFORE_SHUTDOWN); 4706 ipa_debug("ipa_send_msg(Evt:%d)", 4707 meta.msg_type); 4708 ret = qdf_ipa_send_msg(&meta, msg, wlan_ipa_msg_free_fn); 4709 4710 if (ret) { 4711 ipa_err("ipa_send_msg(Evt:%d)-fail=%d", 4712 meta.msg_type, ret); 4713 qdf_mem_free(msg); 4714 } 4715 ipa_ctx->stats.num_send_msg++; 4716 } 4717 4718 void wlan_ipa_flush_pending_vdev_events(struct wlan_ipa_priv *ipa_ctx, 4719 uint8_t vdev_id) 4720 { 4721 struct wlan_ipa_uc_pending_event *event; 4722 struct wlan_ipa_uc_pending_event *next_event; 4723 4724 qdf_mutex_acquire(&ipa_ctx->ipa_lock); 4725 4726 qdf_list_for_each_del(&ipa_ctx->pending_event, event, next_event, 4727 node) { 4728 if (event->session_id == vdev_id) { 4729 qdf_list_remove_node(&ipa_ctx->pending_event, 4730 &event->node); 4731 qdf_mem_free(event); 4732 } 4733 } 4734 4735 qdf_mutex_release(&ipa_ctx->ipa_lock); 4736 } 4737