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