Sravan Kumar Kairam | d01b445 | 2018-03-07 17:37:09 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013-2018 The Linux Foundation. All rights reserved. |
| 3 | * |
Sravan Kumar Kairam | d01b445 | 2018-03-07 17:37:09 +0530 | [diff] [blame] | 4 | * Permission to use, copy, modify, and/or distribute this software for |
| 5 | * any purpose with or without fee is hereby granted, provided that the |
| 6 | * above copyright notice and this permission notice appear in all |
| 7 | * copies. |
| 8 | * |
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL |
| 10 | * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED |
| 11 | * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE |
| 12 | * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL |
| 13 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 14 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 15 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 16 | * PERFORMANCE OF THIS SOFTWARE. |
| 17 | */ |
| 18 | |
Sravan Kumar Kairam | d01b445 | 2018-03-07 17:37:09 +0530 | [diff] [blame] | 19 | /* Include Files */ |
| 20 | #include "wlan_ipa_core.h" |
| 21 | #include "wlan_ipa_main.h" |
| 22 | #include <ol_txrx.h> |
| 23 | #include "cdp_txrx_ipa.h" |
| 24 | #include "wal_rx_desc.h" |
| 25 | |
| 26 | static struct wlan_ipa_priv *gp_ipa; |
| 27 | |
| 28 | static struct wlan_ipa_iface_2_client { |
| 29 | qdf_ipa_client_type_t cons_client; |
| 30 | qdf_ipa_client_type_t prod_client; |
| 31 | } wlan_ipa_iface_2_client[WLAN_IPA_MAX_IFACE] = { |
| 32 | { |
| 33 | QDF_IPA_CLIENT_WLAN2_CONS, QDF_IPA_CLIENT_WLAN1_PROD |
| 34 | }, { |
| 35 | QDF_IPA_CLIENT_WLAN3_CONS, QDF_IPA_CLIENT_WLAN1_PROD |
| 36 | }, { |
| 37 | QDF_IPA_CLIENT_WLAN4_CONS, QDF_IPA_CLIENT_WLAN1_PROD |
| 38 | } |
| 39 | }; |
| 40 | |
Sravan Kumar Kairam | 1309e7e | 2018-03-13 09:29:52 +0530 | [diff] [blame] | 41 | /* Local Function Prototypes */ |
| 42 | static void wlan_ipa_i2w_cb(void *priv, qdf_ipa_dp_evt_type_t evt, |
| 43 | unsigned long data); |
| 44 | static void wlan_ipa_w2i_cb(void *priv, qdf_ipa_dp_evt_type_t evt, |
| 45 | unsigned long data); |
| 46 | |
Sravan Kumar Kairam | d01b445 | 2018-03-07 17:37:09 +0530 | [diff] [blame] | 47 | /** |
| 48 | * wlan_ipa_uc_sta_is_enabled() - Is STA mode IPA uC offload enabled? |
| 49 | * @ipa_cfg: IPA config |
| 50 | * |
| 51 | * Return: true if STA mode IPA uC offload is enabled, false otherwise |
| 52 | */ |
| 53 | static inline bool wlan_ipa_uc_sta_is_enabled(struct wlan_ipa_config *ipa_cfg) |
| 54 | { |
| 55 | return WLAN_IPA_IS_CONFIG_ENABLED(ipa_cfg, WLAN_IPA_UC_STA_ENABLE_MASK); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * wlan_ipa_is_pre_filter_enabled() - Is IPA pre-filter enabled? |
| 60 | * @ipa_cfg: IPA config |
| 61 | * |
| 62 | * Return: true if pre-filter is enabled, otherwise false |
| 63 | */ |
| 64 | static inline |
| 65 | bool wlan_ipa_is_pre_filter_enabled(struct wlan_ipa_config *ipa_cfg) |
| 66 | { |
| 67 | return WLAN_IPA_IS_CONFIG_ENABLED(ipa_cfg, |
| 68 | WLAN_IPA_PRE_FILTER_ENABLE_MASK); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * wlan_ipa_is_ipv6_enabled() - Is IPA IPv6 enabled? |
| 73 | * @ipa_cfg: IPA config |
| 74 | * |
| 75 | * Return: true if IPv6 is enabled, otherwise false |
| 76 | */ |
| 77 | static inline bool wlan_ipa_is_ipv6_enabled(struct wlan_ipa_config *ipa_cfg) |
| 78 | { |
| 79 | return WLAN_IPA_IS_CONFIG_ENABLED(ipa_cfg, WLAN_IPA_IPV6_ENABLE_MASK); |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * wlan_ipa_msg_free_fn() - Free an IPA message |
| 84 | * @buff: pointer to the IPA message |
| 85 | * @len: length of the IPA message |
| 86 | * @type: type of IPA message |
| 87 | * |
| 88 | * Return: None |
| 89 | */ |
| 90 | static void wlan_ipa_msg_free_fn(void *buff, uint32_t len, uint32_t type) |
| 91 | { |
| 92 | ipa_debug("msg type:%d, len:%d", type, len); |
| 93 | qdf_mem_free(buff); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * wlan_ipa_uc_loaded_uc_cb() - IPA UC loaded event callback |
| 98 | * @priv_ctxt: IPA context |
| 99 | * |
| 100 | * Will be called by IPA context. |
| 101 | * It's atomic context, then should be scheduled to kworker thread |
| 102 | * |
| 103 | * Return: None |
| 104 | */ |
| 105 | static void wlan_ipa_uc_loaded_uc_cb(void *priv_ctxt) |
| 106 | { |
| 107 | struct wlan_ipa_priv *ipa_ctx; |
| 108 | struct op_msg_type *msg; |
| 109 | struct uc_op_work_struct *uc_op_work; |
| 110 | |
| 111 | if (!priv_ctxt) { |
| 112 | ipa_err("Invalid IPA context"); |
| 113 | return; |
| 114 | } |
| 115 | |
| 116 | ipa_ctx = priv_ctxt; |
Sravan Kumar Kairam | 7eb6e4c | 2018-04-26 15:35:47 +0530 | [diff] [blame] | 117 | ipa_ctx->uc_loaded = true; |
| 118 | |
| 119 | uc_op_work = &ipa_ctx->uc_op_work[WLAN_IPA_UC_OPCODE_UC_READY]; |
| 120 | if (!list_empty(&uc_op_work->work.work.entry)) { |
| 121 | /* uc_op_work is not initialized yet */ |
| 122 | return; |
| 123 | } |
Sravan Kumar Kairam | d01b445 | 2018-03-07 17:37:09 +0530 | [diff] [blame] | 124 | |
| 125 | msg = qdf_mem_malloc(sizeof(*msg)); |
| 126 | if (!msg) { |
| 127 | ipa_err("op_msg allocation fails"); |
| 128 | return; |
| 129 | } |
| 130 | |
| 131 | msg->op_code = WLAN_IPA_UC_OPCODE_UC_READY; |
| 132 | |
Sravan Kumar Kairam | d01b445 | 2018-03-07 17:37:09 +0530 | [diff] [blame] | 133 | /* When the same uC OPCODE is already pended, just return */ |
| 134 | if (uc_op_work->msg) |
| 135 | goto done; |
| 136 | |
| 137 | uc_op_work->msg = msg; |
| 138 | qdf_sched_work(0, &uc_op_work->work); |
Sravan Kumar Kairam | 7eb6e4c | 2018-04-26 15:35:47 +0530 | [diff] [blame] | 139 | |
Sravan Kumar Kairam | d01b445 | 2018-03-07 17:37:09 +0530 | [diff] [blame] | 140 | /* work handler will free the msg buffer */ |
| 141 | return; |
| 142 | |
| 143 | done: |
| 144 | qdf_mem_free(msg); |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * wlan_ipa_uc_send_wdi_control_msg() - Set WDI control message |
| 149 | * @ctrl: WDI control value |
| 150 | * |
| 151 | * Send WLAN_WDI_ENABLE for ctrl = true and WLAN_WDI_DISABLE otherwise. |
| 152 | * |
| 153 | * Return: QDF_STATUS |
| 154 | */ |
| 155 | static QDF_STATUS wlan_ipa_uc_send_wdi_control_msg(bool ctrl) |
| 156 | { |
jiad | 629b217 | 2018-05-11 15:34:22 +0800 | [diff] [blame] | 157 | struct wlan_ipa_priv *ipa_ctx = gp_ipa; |
Sravan Kumar Kairam | d01b445 | 2018-03-07 17:37:09 +0530 | [diff] [blame] | 158 | qdf_ipa_msg_meta_t meta; |
| 159 | qdf_ipa_wlan_msg_t *ipa_msg; |
| 160 | int ret = 0; |
| 161 | |
| 162 | /* WDI enable message to IPA */ |
| 163 | QDF_IPA_MSG_META_MSG_LEN(&meta) = sizeof(*ipa_msg); |
| 164 | ipa_msg = qdf_mem_malloc(QDF_IPA_MSG_META_MSG_LEN(&meta)); |
| 165 | if (!ipa_msg) { |
| 166 | ipa_err("msg allocation failed"); |
| 167 | return QDF_STATUS_E_NOMEM; |
| 168 | } |
| 169 | |
jiad | 629b217 | 2018-05-11 15:34:22 +0800 | [diff] [blame] | 170 | if (ctrl) { |
Sravan Kumar Kairam | d01b445 | 2018-03-07 17:37:09 +0530 | [diff] [blame] | 171 | QDF_IPA_SET_META_MSG_TYPE(&meta, QDF_WDI_ENABLE); |
jiad | 629b217 | 2018-05-11 15:34:22 +0800 | [diff] [blame] | 172 | ipa_ctx->stats.event[QDF_WDI_ENABLE]++; |
| 173 | } else { |
Sravan Kumar Kairam | d01b445 | 2018-03-07 17:37:09 +0530 | [diff] [blame] | 174 | QDF_IPA_SET_META_MSG_TYPE(&meta, QDF_WDI_DISABLE); |
jiad | 629b217 | 2018-05-11 15:34:22 +0800 | [diff] [blame] | 175 | ipa_ctx->stats.event[QDF_WDI_DISABLE]++; |
| 176 | } |
Sravan Kumar Kairam | d01b445 | 2018-03-07 17:37:09 +0530 | [diff] [blame] | 177 | |
| 178 | ipa_debug("ipa_send_msg(Evt:%d)", QDF_IPA_MSG_META_MSG_TYPE(&meta)); |
| 179 | ret = qdf_ipa_send_msg(&meta, ipa_msg, wlan_ipa_msg_free_fn); |
| 180 | if (ret) { |
| 181 | ipa_err("ipa_send_msg(Evt:%d)-fail=%d", |
| 182 | QDF_IPA_MSG_META_MSG_TYPE(&meta), ret); |
| 183 | qdf_mem_free(ipa_msg); |
| 184 | return QDF_STATUS_E_FAILURE; |
| 185 | } |
| 186 | |
| 187 | return QDF_STATUS_SUCCESS; |
| 188 | } |
| 189 | |
Sravan Kumar Kairam | 271fab2 | 2018-03-07 18:57:41 +0530 | [diff] [blame] | 190 | struct wlan_ipa_priv *wlan_ipa_get_obj_context(void) |
| 191 | { |
| 192 | return gp_ipa; |
| 193 | } |
| 194 | |
Yun Park | e74e609 | 2018-04-27 11:36:34 -0700 | [diff] [blame] | 195 | /** |
| 196 | * wlan_ipa_send_pkt_to_tl() - Send an IPA packet to TL |
| 197 | * @iface_context: interface-specific IPA context |
| 198 | * @ipa_tx_desc: packet data descriptor |
| 199 | * |
| 200 | * Return: None |
| 201 | */ |
| 202 | static void wlan_ipa_send_pkt_to_tl( |
| 203 | struct wlan_ipa_iface_context *iface_context, |
| 204 | qdf_ipa_rx_data_t *ipa_tx_desc) |
| 205 | { |
| 206 | struct wlan_ipa_priv *ipa_ctx = iface_context->ipa_ctx; |
| 207 | qdf_nbuf_t skb; |
| 208 | struct wlan_ipa_tx_desc *tx_desc; |
| 209 | |
| 210 | qdf_spin_lock_bh(&iface_context->interface_lock); |
| 211 | /* |
| 212 | * During CAC period, data packets shouldn't be sent over the air so |
| 213 | * drop all the packets here |
| 214 | */ |
| 215 | if (iface_context->device_mode == QDF_SAP_MODE || |
| 216 | iface_context->device_mode == QDF_P2P_GO_MODE) { |
| 217 | if (ipa_ctx->dfs_cac_block_tx) { |
| 218 | ipa_free_skb(ipa_tx_desc); |
| 219 | qdf_spin_unlock_bh(&iface_context->interface_lock); |
| 220 | iface_context->stats.num_tx_cac_drop++; |
| 221 | wlan_ipa_wdi_rm_try_release(ipa_ctx); |
| 222 | return; |
| 223 | } |
| 224 | } |
| 225 | qdf_spin_unlock_bh(&iface_context->interface_lock); |
| 226 | |
| 227 | skb = QDF_IPA_RX_DATA_SKB(ipa_tx_desc); |
| 228 | |
| 229 | qdf_mem_set(skb->cb, sizeof(skb->cb), 0); |
| 230 | |
| 231 | /* Store IPA Tx buffer ownership into SKB CB */ |
| 232 | qdf_nbuf_ipa_owned_set(skb); |
| 233 | if (wlan_ipa_uc_sta_is_enabled(ipa_ctx->config)) { |
| 234 | qdf_nbuf_mapped_paddr_set(skb, |
| 235 | QDF_IPA_RX_DATA_DMA_ADDR(ipa_tx_desc) |
| 236 | + WLAN_IPA_WLAN_FRAG_HEADER |
| 237 | + WLAN_IPA_WLAN_IPA_HEADER); |
| 238 | QDF_IPA_RX_DATA_SKB_LEN(ipa_tx_desc) -= |
| 239 | WLAN_IPA_WLAN_FRAG_HEADER + WLAN_IPA_WLAN_IPA_HEADER; |
| 240 | } else |
| 241 | qdf_nbuf_mapped_paddr_set(skb, ipa_tx_desc->dma_addr); |
| 242 | |
| 243 | qdf_spin_lock_bh(&ipa_ctx->q_lock); |
| 244 | /* get free Tx desc and assign ipa_tx_desc pointer */ |
| 245 | if (qdf_list_remove_front(&ipa_ctx->tx_desc_list, |
| 246 | (qdf_list_node_t **)&tx_desc) == |
| 247 | QDF_STATUS_SUCCESS) { |
| 248 | tx_desc->ipa_tx_desc_ptr = ipa_tx_desc; |
| 249 | ipa_ctx->stats.num_tx_desc_q_cnt++; |
| 250 | qdf_spin_unlock_bh(&ipa_ctx->q_lock); |
| 251 | /* Store Tx Desc index into SKB CB */ |
| 252 | QDF_NBUF_CB_TX_IPA_PRIV(skb) = tx_desc->id; |
| 253 | } else { |
| 254 | ipa_ctx->stats.num_tx_desc_error++; |
| 255 | qdf_spin_unlock_bh(&ipa_ctx->q_lock); |
| 256 | qdf_ipa_free_skb(ipa_tx_desc); |
| 257 | wlan_ipa_wdi_rm_try_release(ipa_ctx); |
| 258 | return; |
| 259 | } |
| 260 | |
| 261 | skb = cdp_ipa_tx_send_data_frame(cds_get_context(QDF_MODULE_ID_SOC), |
| 262 | (struct cdp_vdev *)iface_context->tl_context, |
| 263 | QDF_IPA_RX_DATA_SKB(ipa_tx_desc)); |
| 264 | if (skb) { |
| 265 | qdf_nbuf_free(skb); |
| 266 | iface_context->stats.num_tx_err++; |
| 267 | return; |
| 268 | } |
| 269 | |
| 270 | atomic_inc(&ipa_ctx->tx_ref_cnt); |
| 271 | |
| 272 | iface_context->stats.num_tx++; |
| 273 | } |
| 274 | |
Sravan Kumar Kairam | d01b445 | 2018-03-07 17:37:09 +0530 | [diff] [blame] | 275 | #ifdef CONFIG_IPA_WDI_UNIFIED_API |
| 276 | |
| 277 | /* |
| 278 | * TODO: Get WDI version through FW capabilities |
| 279 | */ |
| 280 | #ifdef CONFIG_LITHIUM |
| 281 | static inline void wlan_ipa_wdi_get_wdi_version(struct wlan_ipa_priv *ipa_ctx) |
| 282 | { |
| 283 | ipa_ctx->wdi_version = IPA_WDI_3; |
| 284 | } |
| 285 | #elif defined(QCA_WIFI_3_0) |
| 286 | static inline void wlan_ipa_wdi_get_wdi_version(struct wlan_ipa_priv *ipa_ctx) |
| 287 | { |
| 288 | ipa_ctx->wdi_version = IPA_WDI_2; |
| 289 | } |
| 290 | #else |
| 291 | static inline void wlan_ipa_wdi_get_wdi_version(struct wlan_ipa_priv *ipa_ctx) |
| 292 | { |
| 293 | ipa_ctx->wdi_version = IPA_WDI_1; |
| 294 | } |
| 295 | #endif |
| 296 | |
Sravan Kumar Kairam | 1309e7e | 2018-03-13 09:29:52 +0530 | [diff] [blame] | 297 | static inline bool wlan_ipa_wdi_is_smmu_enabled(struct wlan_ipa_priv *ipa_ctx, |
| 298 | qdf_device_t osdev) |
| 299 | { |
Sravan Kumar Kairam | 983a445 | 2018-03-20 13:30:22 +0530 | [diff] [blame] | 300 | return ipa_ctx->is_smmu_enabled && qdf_mem_smmu_s1_enabled(osdev); |
Sravan Kumar Kairam | 1309e7e | 2018-03-13 09:29:52 +0530 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | static inline QDF_STATUS wlan_ipa_wdi_setup(struct wlan_ipa_priv *ipa_ctx, |
| 304 | qdf_device_t osdev) |
| 305 | { |
| 306 | qdf_ipa_sys_connect_params_t sys_in[WLAN_IPA_MAX_IFACE]; |
| 307 | int i; |
| 308 | |
| 309 | for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) |
| 310 | qdf_mem_copy(&sys_in[i], |
| 311 | &ipa_ctx->sys_pipe[i].ipa_sys_params, |
| 312 | sizeof(qdf_ipa_sys_connect_params_t)); |
| 313 | |
| 314 | return cdp_ipa_setup(ipa_ctx->dp_soc, ipa_ctx->dp_pdev, |
| 315 | wlan_ipa_i2w_cb, wlan_ipa_w2i_cb, |
| 316 | wlan_ipa_wdi_meter_notifier_cb, |
| 317 | ipa_ctx->config->desc_size, |
| 318 | ipa_ctx, wlan_ipa_is_rm_enabled(ipa_ctx->config), |
| 319 | &ipa_ctx->tx_pipe_handle, |
| 320 | &ipa_ctx->rx_pipe_handle, |
| 321 | wlan_ipa_wdi_is_smmu_enabled(ipa_ctx, osdev), |
| 322 | sys_in); |
| 323 | } |
| 324 | |
Sravan Kumar Kairam | 271fab2 | 2018-03-07 18:57:41 +0530 | [diff] [blame] | 325 | #ifdef FEATURE_METERING |
| 326 | /** |
| 327 | * wlan_ipa_wdi_init_metering() - IPA WDI metering init |
| 328 | * @ipa_ctx: IPA context |
| 329 | * @in: IPA WDI in param |
| 330 | * |
| 331 | * Return: QDF_STATUS |
| 332 | */ |
| 333 | static inline void wlan_ipa_wdi_init_metering(struct wlan_ipa_priv *ipa_ctxt, |
| 334 | qdf_ipa_wdi_init_in_params_t *in) |
| 335 | { |
| 336 | QDF_IPA_WDI_INIT_IN_PARAMS_WDI_NOTIFY(in) = |
| 337 | wlan_ipa_wdi_meter_notifier_cb; |
| 338 | } |
| 339 | #else |
| 340 | static inline void wlan_ipa_wdi_init_metering(struct wlan_ipa_priv *ipa_ctxt, |
| 341 | qdf_ipa_wdi_init_in_params_t *in) |
| 342 | { |
| 343 | } |
| 344 | #endif |
| 345 | |
| 346 | /** |
| 347 | * wlan_ipa_wdi_init() - IPA WDI init |
| 348 | * @ipa_ctx: IPA context |
| 349 | * |
| 350 | * Return: QDF_STATUS |
| 351 | */ |
Sravan Kumar Kairam | d01b445 | 2018-03-07 17:37:09 +0530 | [diff] [blame] | 352 | static inline QDF_STATUS wlan_ipa_wdi_init(struct wlan_ipa_priv *ipa_ctx) |
| 353 | { |
| 354 | qdf_ipa_wdi_init_in_params_t in; |
| 355 | qdf_ipa_wdi_init_out_params_t out; |
| 356 | int ret; |
| 357 | |
| 358 | ipa_ctx->uc_loaded = false; |
| 359 | |
| 360 | QDF_IPA_WDI_INIT_IN_PARAMS_WDI_VERSION(&in) = ipa_ctx->wdi_version; |
| 361 | QDF_IPA_WDI_INIT_IN_PARAMS_NOTIFY(&in) = wlan_ipa_uc_loaded_uc_cb; |
Sravan Kumar Kairam | 271fab2 | 2018-03-07 18:57:41 +0530 | [diff] [blame] | 362 | QDF_IPA_WDI_INIT_IN_PARAMS_PRIV(&in) = ipa_ctx; |
| 363 | wlan_ipa_wdi_init_metering(ipa_ctx, &in); |
Sravan Kumar Kairam | d01b445 | 2018-03-07 17:37:09 +0530 | [diff] [blame] | 364 | |
| 365 | ret = qdf_ipa_wdi_init(&in, &out); |
| 366 | if (ret) { |
| 367 | ipa_err("ipa_wdi_init failed with ret=%d", ret); |
| 368 | return QDF_STATUS_E_FAILURE; |
| 369 | } |
| 370 | |
| 371 | if (QDF_IPA_WDI_INIT_OUT_PARAMS_IS_UC_READY(&out)) { |
| 372 | ipa_info("IPA uC READY"); |
| 373 | ipa_ctx->uc_loaded = true; |
| 374 | ipa_ctx->is_smmu_enabled = |
| 375 | QDF_IPA_WDI_INIT_OUT_PARAMS_IS_SMMU_ENABLED(&out); |
| 376 | ipa_info("is_smmu_enabled=%d", ipa_ctx->is_smmu_enabled); |
| 377 | } else { |
| 378 | return QDF_STATUS_E_BUSY; |
| 379 | } |
| 380 | |
| 381 | return QDF_STATUS_SUCCESS; |
| 382 | } |
| 383 | |
| 384 | static inline int wlan_ipa_wdi_cleanup(void) |
| 385 | { |
| 386 | int ret; |
| 387 | |
| 388 | ret = qdf_ipa_wdi_cleanup(); |
| 389 | if (ret) |
| 390 | ipa_info("ipa_wdi_cleanup failed ret=%d", ret); |
| 391 | return ret; |
| 392 | } |
| 393 | |
| 394 | static inline int wlan_ipa_wdi_setup_sys_pipe(struct wlan_ipa_priv *ipa_ctx, |
| 395 | struct ipa_sys_connect_params *sys, |
| 396 | uint32_t *handle) |
| 397 | { |
| 398 | return 0; |
| 399 | } |
| 400 | |
| 401 | static inline int wlan_ipa_wdi_teardown_sys_pipe(struct wlan_ipa_priv *ipa_ctx, |
| 402 | uint32_t handle) |
| 403 | { |
| 404 | return 0; |
| 405 | } |
| 406 | |
Yun Park | e74e609 | 2018-04-27 11:36:34 -0700 | [diff] [blame] | 407 | /** |
| 408 | * wlan_ipa_pm_flush() - flush queued packets |
| 409 | * @work: pointer to the scheduled work |
| 410 | * |
| 411 | * Called during PM resume to send packets to TL which were queued |
| 412 | * while host was in the process of suspending. |
| 413 | * |
| 414 | * Return: None |
| 415 | */ |
| 416 | static void wlan_ipa_pm_flush(void *data) |
| 417 | { |
| 418 | struct wlan_ipa_priv *ipa_ctx = (struct wlan_ipa_priv *)data; |
| 419 | struct wlan_ipa_pm_tx_cb *pm_tx_cb = NULL; |
| 420 | qdf_nbuf_t skb; |
| 421 | uint32_t dequeued = 0; |
| 422 | |
| 423 | qdf_spin_lock_bh(&ipa_ctx->pm_lock); |
| 424 | while (((skb = qdf_nbuf_queue_remove(&ipa_ctx->pm_queue_head)) != |
| 425 | NULL)) { |
| 426 | qdf_spin_unlock_bh(&ipa_ctx->pm_lock); |
| 427 | |
| 428 | pm_tx_cb = (struct wlan_ipa_pm_tx_cb *)skb->cb; |
| 429 | dequeued++; |
| 430 | |
jiad | ab8cea0 | 2018-05-24 09:16:14 +0800 | [diff] [blame^] | 431 | if (pm_tx_cb->exception) { |
| 432 | if (ipa_ctx->softap_xmit && |
| 433 | pm_tx_cb->iface_context->dev) { |
| 434 | ipa_ctx->softap_xmit(skb, |
| 435 | pm_tx_cb->iface_context->dev); |
| 436 | ipa_ctx->stats.num_tx_fwd_ok++; |
| 437 | } else { |
| 438 | dev_kfree_skb_any(skb); |
| 439 | } |
| 440 | } else { |
| 441 | wlan_ipa_send_pkt_to_tl(pm_tx_cb->iface_context, |
| 442 | pm_tx_cb->ipa_tx_desc); |
| 443 | } |
Yun Park | e74e609 | 2018-04-27 11:36:34 -0700 | [diff] [blame] | 444 | |
| 445 | qdf_spin_lock_bh(&ipa_ctx->pm_lock); |
| 446 | } |
| 447 | qdf_spin_unlock_bh(&ipa_ctx->pm_lock); |
| 448 | |
| 449 | ipa_ctx->stats.num_tx_dequeued += dequeued; |
| 450 | if (dequeued > ipa_ctx->stats.num_max_pm_queue) |
| 451 | ipa_ctx->stats.num_max_pm_queue = dequeued; |
| 452 | } |
| 453 | |
jiad | ae9959f | 2018-05-08 11:19:07 +0800 | [diff] [blame] | 454 | int wlan_ipa_uc_smmu_map(bool map, uint32_t num_buf, qdf_mem_info_t *buf_arr) |
| 455 | { |
| 456 | if (!num_buf) { |
| 457 | ipa_info("No buffers to map/unmap"); |
| 458 | return 0; |
| 459 | } |
| 460 | |
| 461 | if (map) |
| 462 | return qdf_ipa_wdi_create_smmu_mapping(num_buf, buf_arr); |
| 463 | else |
| 464 | return qdf_ipa_wdi_release_smmu_mapping(num_buf, buf_arr); |
| 465 | } |
| 466 | |
Sravan Kumar Kairam | d01b445 | 2018-03-07 17:37:09 +0530 | [diff] [blame] | 467 | #else /* CONFIG_IPA_WDI_UNIFIED_API */ |
| 468 | |
| 469 | static inline void wlan_ipa_wdi_get_wdi_version(struct wlan_ipa_priv *ipa_ctx) |
| 470 | { |
| 471 | } |
| 472 | |
Sravan Kumar Kairam | 983a445 | 2018-03-20 13:30:22 +0530 | [diff] [blame] | 473 | static inline int wlan_ipa_wdi_is_smmu_enabled(struct wlan_ipa_priv *ipa_ctx, |
| 474 | qdf_device_t osdev) |
| 475 | { |
| 476 | return qdf_mem_smmu_s1_enabled(osdev); |
| 477 | } |
| 478 | |
Sravan Kumar Kairam | 1309e7e | 2018-03-13 09:29:52 +0530 | [diff] [blame] | 479 | static inline QDF_STATUS wlan_ipa_wdi_setup(struct wlan_ipa_priv *ipa_ctx, |
| 480 | qdf_device_t osdev) |
| 481 | { |
| 482 | return cdp_ipa_setup(ipa_ctx->dp_soc, ipa_ctx->dp_pdev, |
| 483 | wlan_ipa_i2w_cb, wlan_ipa_w2i_cb, |
| 484 | wlan_ipa_wdi_meter_notifier_cb, |
| 485 | ipa_ctx->config->desc_size, |
| 486 | ipa_ctx, wlan_ipa_is_rm_enabled(ipa_ctx->config), |
| 487 | &ipa_ctx->tx_pipe_handle, |
| 488 | &ipa_ctx->rx_pipe_handle); |
| 489 | } |
| 490 | |
Sravan Kumar Kairam | d01b445 | 2018-03-07 17:37:09 +0530 | [diff] [blame] | 491 | static inline QDF_STATUS wlan_ipa_wdi_init(struct wlan_ipa_priv *ipa_ctx) |
| 492 | { |
| 493 | struct ipa_wdi_uc_ready_params uc_ready_param; |
| 494 | |
| 495 | ipa_ctx->uc_loaded = false; |
| 496 | uc_ready_param.priv = (void *)ipa_ctx; |
| 497 | uc_ready_param.notify = wlan_ipa_uc_loaded_uc_cb; |
| 498 | if (qdf_ipa_uc_reg_rdyCB(&uc_ready_param)) { |
| 499 | ipa_info("UC Ready CB register fail"); |
| 500 | return QDF_STATUS_E_FAILURE; |
| 501 | } |
| 502 | |
| 503 | if (true == uc_ready_param.is_uC_ready) { |
| 504 | ipa_info("UC Ready"); |
| 505 | ipa_ctx->uc_loaded = true; |
| 506 | } else { |
| 507 | return QDF_STATUS_E_BUSY; |
| 508 | } |
| 509 | |
| 510 | return QDF_STATUS_SUCCESS; |
| 511 | } |
| 512 | |
| 513 | static inline int wlan_ipa_wdi_cleanup(void) |
| 514 | { |
| 515 | int ret; |
| 516 | |
| 517 | ret = qdf_ipa_uc_dereg_rdyCB(); |
| 518 | if (ret) |
| 519 | ipa_info("UC Ready CB deregister fail"); |
| 520 | return ret; |
| 521 | } |
| 522 | |
| 523 | static inline int wlan_ipa_wdi_setup_sys_pipe( |
| 524 | struct wlan_ipa_priv *ipa_ctx, |
| 525 | struct ipa_sys_connect_params *sys, uint32_t *handle) |
| 526 | { |
| 527 | return qdf_ipa_setup_sys_pipe(sys, handle); |
| 528 | } |
| 529 | |
| 530 | static inline int wlan_ipa_wdi_teardown_sys_pipe( |
| 531 | struct wlan_ipa_priv *ipa_ctx, |
| 532 | uint32_t handle) |
| 533 | { |
| 534 | return qdf_ipa_teardown_sys_pipe(handle); |
| 535 | } |
| 536 | |
Yun Park | e74e609 | 2018-04-27 11:36:34 -0700 | [diff] [blame] | 537 | /** |
| 538 | * wlan_ipa_pm_flush() - flush queued packets |
| 539 | * @work: pointer to the scheduled work |
| 540 | * |
| 541 | * Called during PM resume to send packets to TL which were queued |
| 542 | * while host was in the process of suspending. |
| 543 | * |
| 544 | * Return: None |
| 545 | */ |
| 546 | static void wlan_ipa_pm_flush(void *data) |
| 547 | { |
| 548 | struct wlan_ipa_priv *ipa_ctx = (struct wlan_ipa_priv *)data; |
| 549 | struct wlan_ipa_pm_tx_cb *pm_tx_cb = NULL; |
| 550 | qdf_nbuf_t skb; |
| 551 | uint32_t dequeued = 0; |
| 552 | |
| 553 | qdf_wake_lock_acquire(&ipa_ctx->wake_lock, |
| 554 | WIFI_POWER_EVENT_WAKELOCK_IPA); |
| 555 | qdf_spin_lock_bh(&ipa_ctx->pm_lock); |
| 556 | while (((skb = qdf_nbuf_queue_remove(&ipa_ctx->pm_queue_head)) != |
| 557 | NULL)) { |
| 558 | qdf_spin_unlock_bh(&ipa_ctx->pm_lock); |
| 559 | |
| 560 | pm_tx_cb = (struct wlan_ipa_pm_tx_cb *)skb->cb; |
| 561 | dequeued++; |
| 562 | |
jiad | ab8cea0 | 2018-05-24 09:16:14 +0800 | [diff] [blame^] | 563 | if (pm_tx_cb->exception) { |
| 564 | if (ipa_ctx->softap_xmit && |
| 565 | pm_tx_cb->iface_context->dev) { |
| 566 | ipa_ctx->softap_xmit(skb, |
| 567 | pm_tx_cb->iface_context->dev); |
| 568 | ipa_ctx->stats.num_tx_fwd_ok++; |
| 569 | } else { |
| 570 | dev_kfree_skb_any(skb); |
| 571 | } |
| 572 | } else { |
| 573 | wlan_ipa_send_pkt_to_tl(pm_tx_cb->iface_context, |
| 574 | pm_tx_cb->ipa_tx_desc); |
| 575 | } |
Yun Park | e74e609 | 2018-04-27 11:36:34 -0700 | [diff] [blame] | 576 | |
| 577 | qdf_spin_lock_bh(&ipa_ctx->pm_lock); |
| 578 | } |
| 579 | qdf_spin_unlock_bh(&ipa_ctx->pm_lock); |
| 580 | qdf_wake_lock_release(&ipa_ctx->wake_lock, |
| 581 | WIFI_POWER_EVENT_WAKELOCK_IPA); |
| 582 | |
| 583 | ipa_ctx->stats.num_tx_dequeued += dequeued; |
| 584 | if (dequeued > ipa_ctx->stats.num_max_pm_queue) |
| 585 | ipa_ctx->stats.num_max_pm_queue = dequeued; |
| 586 | } |
| 587 | |
jiad | ae9959f | 2018-05-08 11:19:07 +0800 | [diff] [blame] | 588 | int wlan_ipa_uc_smmu_map(bool map, uint32_t num_buf, qdf_mem_info_t *buf_arr) |
| 589 | { |
| 590 | if (!num_buf) { |
| 591 | ipa_info("No buffers to map/unmap"); |
| 592 | return 0; |
| 593 | } |
| 594 | |
| 595 | if (map) |
| 596 | return qdf_ipa_create_wdi_mapping(num_buf, buf_arr); |
| 597 | else |
| 598 | return qdf_ipa_release_wdi_mapping(num_buf, buf_arr); |
| 599 | } |
| 600 | |
Sravan Kumar Kairam | d01b445 | 2018-03-07 17:37:09 +0530 | [diff] [blame] | 601 | #endif /* CONFIG_IPA_WDI_UNIFIED_API */ |
| 602 | |
Sravan Kumar Kairam | 1309e7e | 2018-03-13 09:29:52 +0530 | [diff] [blame] | 603 | /** |
| 604 | * wlan_ipa_send_skb_to_network() - Send skb to kernel |
| 605 | * @skb: network buffer |
| 606 | * @iface_ctx: IPA interface context |
| 607 | * |
| 608 | * Called when a network buffer is received which should not be routed |
| 609 | * to the IPA module. |
| 610 | * |
| 611 | * Return: None |
| 612 | */ |
| 613 | static void |
| 614 | wlan_ipa_send_skb_to_network(qdf_nbuf_t skb, |
| 615 | struct wlan_ipa_iface_context *iface_ctx) |
| 616 | { |
| 617 | struct wlan_ipa_priv *ipa_ctx = gp_ipa; |
| 618 | |
| 619 | if (!iface_ctx->dev) { |
| 620 | WLAN_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Invalid interface"); |
| 621 | ipa_ctx->ipa_rx_internal_drop_count++; |
| 622 | qdf_nbuf_free(skb); |
| 623 | return; |
| 624 | } |
| 625 | |
| 626 | skb->destructor = wlan_ipa_uc_rt_debug_destructor; |
| 627 | |
| 628 | if (ipa_ctx->send_to_nw) |
| 629 | ipa_ctx->send_to_nw(skb, iface_ctx->dev); |
| 630 | |
| 631 | ipa_ctx->ipa_rx_net_send_count++; |
| 632 | } |
| 633 | |
| 634 | /** |
| 635 | * wlan_ipa_forward() - handle packet forwarding to wlan tx |
| 636 | * @ipa_ctx: pointer to ipa ipa context |
| 637 | * @iface_ctx: interface context |
| 638 | * @skb: data pointer |
| 639 | * |
| 640 | * if exception packet has set forward bit, copied new packet should be |
| 641 | * forwarded to wlan tx. if wlan subsystem is in suspend state, packet should |
| 642 | * put into pm queue and tx procedure will be differed |
| 643 | * |
| 644 | * Return: None |
| 645 | */ |
| 646 | static void wlan_ipa_forward(struct wlan_ipa_priv *ipa_ctx, |
| 647 | struct wlan_ipa_iface_context *iface_ctx, |
| 648 | qdf_nbuf_t skb) |
| 649 | { |
| 650 | struct wlan_ipa_pm_tx_cb *pm_tx_cb; |
| 651 | |
| 652 | qdf_spin_lock_bh(&ipa_ctx->pm_lock); |
| 653 | |
| 654 | /* Set IPA ownership for intra-BSS Tx packets to avoid skb_orphan */ |
| 655 | qdf_nbuf_ipa_owned_set(skb); |
| 656 | |
| 657 | /* WLAN subsystem is in suspend, put in queue */ |
| 658 | if (ipa_ctx->suspended) { |
| 659 | qdf_spin_unlock_bh(&ipa_ctx->pm_lock); |
| 660 | WLAN_IPA_LOG(QDF_TRACE_LEVEL_INFO, |
| 661 | "Tx in suspend, put in queue"); |
| 662 | qdf_mem_set(skb->cb, sizeof(skb->cb), 0); |
| 663 | pm_tx_cb = (struct wlan_ipa_pm_tx_cb *)skb->cb; |
| 664 | pm_tx_cb->exception = true; |
| 665 | pm_tx_cb->iface_context = iface_ctx; |
| 666 | qdf_spin_lock_bh(&ipa_ctx->pm_lock); |
| 667 | qdf_nbuf_queue_add(&ipa_ctx->pm_queue_head, skb); |
| 668 | qdf_spin_unlock_bh(&ipa_ctx->pm_lock); |
| 669 | ipa_ctx->stats.num_tx_queued++; |
| 670 | } else { |
| 671 | /* Resume, put packet into WLAN TX */ |
| 672 | qdf_spin_unlock_bh(&ipa_ctx->pm_lock); |
| 673 | |
| 674 | if (ipa_ctx->softap_xmit) { |
| 675 | if (ipa_ctx->softap_xmit(skb, iface_ctx->dev)) { |
| 676 | WLAN_IPA_LOG(QDF_TRACE_LEVEL_ERROR, |
| 677 | "packet Tx fail"); |
| 678 | ipa_ctx->stats.num_tx_fwd_err++; |
| 679 | } else { |
| 680 | ipa_ctx->stats.num_tx_fwd_ok++; |
| 681 | } |
| 682 | } else { |
jiad | ab8cea0 | 2018-05-24 09:16:14 +0800 | [diff] [blame^] | 683 | dev_kfree_skb_any(skb); |
Sravan Kumar Kairam | 1309e7e | 2018-03-13 09:29:52 +0530 | [diff] [blame] | 684 | } |
| 685 | } |
| 686 | } |
| 687 | |
| 688 | /** |
| 689 | * wlan_ipa_intrabss_forward() - Forward intra bss packets. |
| 690 | * @ipa_ctx: pointer to IPA IPA struct |
| 691 | * @iface_ctx: ipa interface context |
| 692 | * @desc: Firmware descriptor |
| 693 | * @skb: Data buffer |
| 694 | * |
| 695 | * Return: |
| 696 | * WLAN_IPA_FORWARD_PKT_NONE |
| 697 | * WLAN_IPA_FORWARD_PKT_DISCARD |
| 698 | * WLAN_IPA_FORWARD_PKT_LOCAL_STACK |
| 699 | * |
| 700 | */ |
| 701 | |
| 702 | static enum wlan_ipa_forward_type wlan_ipa_intrabss_forward( |
| 703 | struct wlan_ipa_priv *ipa_ctx, |
| 704 | struct wlan_ipa_iface_context *iface_ctx, |
| 705 | uint8_t desc, |
| 706 | qdf_nbuf_t skb) |
| 707 | { |
| 708 | int ret = WLAN_IPA_FORWARD_PKT_NONE; |
| 709 | void *soc = cds_get_context(QDF_MODULE_ID_SOC); |
| 710 | struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX); |
| 711 | |
| 712 | if ((desc & FW_RX_DESC_FORWARD_M)) { |
| 713 | if (!ol_txrx_fwd_desc_thresh_check( |
| 714 | (struct ol_txrx_vdev_t *)cdp_get_vdev_from_vdev_id(soc, |
| 715 | (struct cdp_pdev *)pdev, |
| 716 | iface_ctx->session_id))) { |
| 717 | /* Drop the packet*/ |
| 718 | ipa_ctx->stats.num_tx_fwd_err++; |
jiad | ab8cea0 | 2018-05-24 09:16:14 +0800 | [diff] [blame^] | 719 | dev_kfree_skb_any(skb); |
Sravan Kumar Kairam | 1309e7e | 2018-03-13 09:29:52 +0530 | [diff] [blame] | 720 | ret = WLAN_IPA_FORWARD_PKT_DISCARD; |
| 721 | return ret; |
| 722 | } |
| 723 | WLAN_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, |
| 724 | "Forward packet to Tx (fw_desc=%d)", desc); |
| 725 | ipa_ctx->ipa_tx_forward++; |
| 726 | |
| 727 | if ((desc & FW_RX_DESC_DISCARD_M)) { |
| 728 | wlan_ipa_forward(ipa_ctx, iface_ctx, skb); |
| 729 | ipa_ctx->ipa_rx_internal_drop_count++; |
| 730 | ipa_ctx->ipa_rx_discard++; |
| 731 | ret = WLAN_IPA_FORWARD_PKT_DISCARD; |
| 732 | } else { |
| 733 | struct sk_buff *cloned_skb = skb_clone(skb, GFP_ATOMIC); |
| 734 | |
| 735 | if (cloned_skb) |
| 736 | wlan_ipa_forward(ipa_ctx, iface_ctx, |
| 737 | cloned_skb); |
| 738 | else |
| 739 | WLAN_IPA_LOG(QDF_TRACE_LEVEL_ERROR, |
| 740 | "tx skb alloc failed"); |
| 741 | ret = WLAN_IPA_FORWARD_PKT_LOCAL_STACK; |
| 742 | } |
| 743 | } |
| 744 | |
| 745 | return ret; |
| 746 | } |
| 747 | |
| 748 | /** |
| 749 | * wlan_ipa_w2i_cb() - WLAN to IPA callback handler |
| 750 | * @priv: pointer to private data registered with IPA (we register a |
| 751 | * pointer to the global IPA context) |
| 752 | * @evt: the IPA event which triggered the callback |
| 753 | * @data: data associated with the event |
| 754 | * |
| 755 | * Return: None |
| 756 | */ |
| 757 | static void wlan_ipa_w2i_cb(void *priv, qdf_ipa_dp_evt_type_t evt, |
| 758 | unsigned long data) |
| 759 | { |
| 760 | struct wlan_ipa_priv *ipa_ctx = NULL; |
| 761 | qdf_nbuf_t skb; |
| 762 | uint8_t iface_id; |
| 763 | uint8_t session_id; |
| 764 | struct wlan_ipa_iface_context *iface_context; |
| 765 | uint8_t fw_desc; |
| 766 | |
| 767 | ipa_ctx = (struct wlan_ipa_priv *)priv; |
| 768 | |
| 769 | if (!ipa_ctx) |
| 770 | return; |
| 771 | |
| 772 | switch (evt) { |
| 773 | case IPA_RECEIVE: |
| 774 | skb = (qdf_nbuf_t) data; |
| 775 | |
| 776 | if (wlan_ipa_uc_is_enabled(ipa_ctx->config)) { |
| 777 | session_id = (uint8_t)skb->cb[0]; |
| 778 | iface_id = ipa_ctx->vdev_to_iface[session_id]; |
| 779 | ipa_debug("IPA_RECEIVE: session_id=%u, iface_id=%u", |
| 780 | session_id, iface_id); |
| 781 | } else { |
| 782 | iface_id = WLAN_IPA_GET_IFACE_ID(skb->data); |
| 783 | } |
| 784 | if (iface_id >= WLAN_IPA_MAX_IFACE) { |
| 785 | ipa_err("IPA_RECEIVE: Invalid iface_id: %u", |
| 786 | iface_id); |
| 787 | ipa_ctx->ipa_rx_internal_drop_count++; |
jiad | ab8cea0 | 2018-05-24 09:16:14 +0800 | [diff] [blame^] | 788 | dev_kfree_skb_any(skb); |
Sravan Kumar Kairam | 1309e7e | 2018-03-13 09:29:52 +0530 | [diff] [blame] | 789 | return; |
| 790 | } |
| 791 | |
| 792 | iface_context = &ipa_ctx->iface_context[iface_id]; |
| 793 | if (!iface_context->tl_context) { |
| 794 | ipa_err("IPA_RECEIVE: TL context is NULL"); |
| 795 | ipa_ctx->ipa_rx_internal_drop_count++; |
jiad | ab8cea0 | 2018-05-24 09:16:14 +0800 | [diff] [blame^] | 796 | dev_kfree_skb_any(skb); |
Sravan Kumar Kairam | 1309e7e | 2018-03-13 09:29:52 +0530 | [diff] [blame] | 797 | return; |
| 798 | } |
| 799 | |
| 800 | if (wlan_ipa_uc_is_enabled(ipa_ctx->config)) { |
| 801 | ipa_ctx->stats.num_rx_excep++; |
| 802 | qdf_nbuf_pull_head(skb, WLAN_IPA_UC_WLAN_CLD_HDR_LEN); |
| 803 | } else { |
| 804 | qdf_nbuf_pull_head(skb, WLAN_IPA_WLAN_CLD_HDR_LEN); |
| 805 | } |
| 806 | |
| 807 | iface_context->stats.num_rx_ipa_excep++; |
| 808 | |
| 809 | /* Disable to forward Intra-BSS Rx packets when |
| 810 | * ap_isolate=1 in hostapd.conf |
| 811 | */ |
| 812 | if (!ipa_ctx->ap_intrabss_fwd) { |
| 813 | /* |
| 814 | * When INTRA_BSS_FWD_OFFLOAD is enabled, FW will send |
| 815 | * all Rx packets to IPA uC, which need to be forwarded |
| 816 | * to other interface. |
| 817 | * And, IPA driver will send back to WLAN host driver |
| 818 | * through exception pipe with fw_desc field set by FW. |
| 819 | * Here we are checking fw_desc field for FORWARD bit |
| 820 | * set, and forward to Tx. Then copy to kernel stack |
| 821 | * only when DISCARD bit is not set. |
| 822 | */ |
| 823 | fw_desc = (uint8_t)skb->cb[1]; |
| 824 | if (WLAN_IPA_FORWARD_PKT_DISCARD == |
| 825 | wlan_ipa_intrabss_forward(ipa_ctx, iface_context, |
| 826 | fw_desc, skb)) |
| 827 | break; |
| 828 | } else { |
| 829 | ipa_debug("Intra-BSS FWD is disabled-skip forward to Tx"); |
| 830 | } |
| 831 | |
| 832 | wlan_ipa_send_skb_to_network(skb, iface_context); |
| 833 | break; |
| 834 | |
| 835 | default: |
| 836 | ipa_err("w2i cb wrong event: 0x%x", evt); |
| 837 | return; |
| 838 | } |
| 839 | } |
| 840 | |
| 841 | /** |
Sravan Kumar Kairam | 1309e7e | 2018-03-13 09:29:52 +0530 | [diff] [blame] | 842 | * wlan_ipa_i2w_cb() - IPA to WLAN callback |
| 843 | * @priv: pointer to private data registered with IPA (we register a |
| 844 | * pointer to the interface-specific IPA context) |
| 845 | * @evt: the IPA event which triggered the callback |
| 846 | * @data: data associated with the event |
| 847 | * |
| 848 | * Return: None |
| 849 | */ |
| 850 | static void wlan_ipa_i2w_cb(void *priv, qdf_ipa_dp_evt_type_t evt, |
| 851 | unsigned long data) |
| 852 | { |
| 853 | struct wlan_ipa_priv *ipa_ctx = NULL; |
| 854 | qdf_ipa_rx_data_t *ipa_tx_desc; |
| 855 | struct wlan_ipa_iface_context *iface_context; |
| 856 | qdf_nbuf_t skb; |
| 857 | struct wlan_ipa_pm_tx_cb *pm_tx_cb = NULL; |
| 858 | |
| 859 | iface_context = (struct wlan_ipa_iface_context *)priv; |
| 860 | ipa_tx_desc = (qdf_ipa_rx_data_t *)data; |
| 861 | ipa_ctx = iface_context->ipa_ctx; |
| 862 | |
| 863 | if (evt != IPA_RECEIVE) { |
| 864 | WLAN_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Event is not IPA_RECEIVE"); |
| 865 | ipa_free_skb(ipa_tx_desc); |
| 866 | iface_context->stats.num_tx_drop++; |
| 867 | return; |
| 868 | } |
| 869 | |
| 870 | skb = QDF_IPA_RX_DATA_SKB(ipa_tx_desc); |
| 871 | |
| 872 | /* |
| 873 | * If PROD resource is not requested here then there may be cases where |
| 874 | * IPA hardware may be clocked down because of not having proper |
| 875 | * dependency graph between WLAN CONS and modem PROD pipes. Adding the |
| 876 | * workaround to request PROD resource while data is going over CONS |
| 877 | * pipe to prevent the IPA hardware clockdown. |
| 878 | */ |
| 879 | wlan_ipa_wdi_rm_request(ipa_ctx); |
| 880 | |
| 881 | qdf_spin_lock_bh(&ipa_ctx->pm_lock); |
| 882 | /* |
| 883 | * If host is still suspended then queue the packets and these will be |
| 884 | * drained later when resume completes. When packet is arrived here and |
| 885 | * host is suspended, this means that there is already resume is in |
| 886 | * progress. |
| 887 | */ |
| 888 | if (ipa_ctx->suspended) { |
| 889 | qdf_mem_set(skb->cb, sizeof(skb->cb), 0); |
| 890 | pm_tx_cb = (struct wlan_ipa_pm_tx_cb *)skb->cb; |
| 891 | pm_tx_cb->iface_context = iface_context; |
| 892 | pm_tx_cb->ipa_tx_desc = ipa_tx_desc; |
| 893 | qdf_nbuf_queue_add(&ipa_ctx->pm_queue_head, skb); |
| 894 | ipa_ctx->stats.num_tx_queued++; |
| 895 | |
| 896 | qdf_spin_unlock_bh(&ipa_ctx->pm_lock); |
| 897 | return; |
| 898 | } |
| 899 | |
| 900 | qdf_spin_unlock_bh(&ipa_ctx->pm_lock); |
| 901 | |
| 902 | /* |
| 903 | * If we are here means, host is not suspended, wait for the work queue |
| 904 | * to finish. |
| 905 | */ |
| 906 | qdf_flush_work(&ipa_ctx->pm_work); |
| 907 | |
| 908 | return wlan_ipa_send_pkt_to_tl(iface_context, ipa_tx_desc); |
| 909 | } |
| 910 | |
| 911 | QDF_STATUS wlan_ipa_suspend(struct wlan_ipa_priv *ipa_ctx) |
| 912 | { |
| 913 | /* |
| 914 | * Check if IPA is ready for suspend, If we are here means, there is |
| 915 | * high chance that suspend would go through but just to avoid any race |
| 916 | * condition after suspend started, these checks are conducted before |
| 917 | * allowing to suspend. |
| 918 | */ |
| 919 | if (atomic_read(&ipa_ctx->tx_ref_cnt)) |
| 920 | return QDF_STATUS_E_AGAIN; |
| 921 | |
Yun Park | e74e609 | 2018-04-27 11:36:34 -0700 | [diff] [blame] | 922 | if (!wlan_ipa_is_rm_released(ipa_ctx)) |
Sravan Kumar Kairam | 1309e7e | 2018-03-13 09:29:52 +0530 | [diff] [blame] | 923 | return QDF_STATUS_E_AGAIN; |
Sravan Kumar Kairam | 1309e7e | 2018-03-13 09:29:52 +0530 | [diff] [blame] | 924 | |
| 925 | qdf_spin_lock_bh(&ipa_ctx->pm_lock); |
| 926 | ipa_ctx->suspended = true; |
| 927 | qdf_spin_unlock_bh(&ipa_ctx->pm_lock); |
| 928 | |
| 929 | return QDF_STATUS_SUCCESS; |
| 930 | } |
| 931 | |
| 932 | QDF_STATUS wlan_ipa_resume(struct wlan_ipa_priv *ipa_ctx) |
| 933 | { |
| 934 | qdf_sched_work(0, &ipa_ctx->pm_work); |
| 935 | |
| 936 | qdf_spin_lock_bh(&ipa_ctx->pm_lock); |
| 937 | ipa_ctx->suspended = false; |
| 938 | qdf_spin_unlock_bh(&ipa_ctx->pm_lock); |
| 939 | |
| 940 | return QDF_STATUS_SUCCESS; |
| 941 | } |
| 942 | |
Sravan Kumar Kairam | 2e7aae9 | 2018-03-06 19:32:49 +0530 | [diff] [blame] | 943 | QDF_STATUS wlan_ipa_uc_enable_pipes(struct wlan_ipa_priv *ipa_ctx) |
| 944 | { |
| 945 | int result; |
| 946 | |
| 947 | ipa_debug("enter"); |
| 948 | |
| 949 | if (!ipa_ctx->ipa_pipes_down) { |
| 950 | /* |
| 951 | * IPA WDI Pipes are already activated due to |
| 952 | * rm deferred resources grant |
| 953 | */ |
| 954 | ipa_warn("IPA WDI Pipes are already activated"); |
| 955 | goto end; |
| 956 | } |
| 957 | |
| 958 | result = cdp_ipa_enable_pipes(ipa_ctx->dp_soc, |
| 959 | ipa_ctx->dp_pdev); |
| 960 | if (result) { |
| 961 | ipa_err("Enable IPA WDI PIPE failed: ret=%d", result); |
| 962 | return QDF_STATUS_E_FAILURE; |
| 963 | } |
| 964 | |
| 965 | qdf_event_reset(&ipa_ctx->ipa_resource_comp); |
| 966 | ipa_ctx->ipa_pipes_down = false; |
| 967 | |
| 968 | cdp_ipa_enable_autonomy(ipa_ctx->dp_soc, |
| 969 | ipa_ctx->dp_pdev); |
| 970 | |
| 971 | end: |
| 972 | ipa_debug("exit: ipa_pipes_down=%d", ipa_ctx->ipa_pipes_down); |
| 973 | |
| 974 | return QDF_STATUS_SUCCESS; |
| 975 | } |
| 976 | |
| 977 | QDF_STATUS wlan_ipa_uc_disable_pipes(struct wlan_ipa_priv *ipa_ctx) |
| 978 | { |
| 979 | int result; |
| 980 | |
| 981 | ipa_debug("enter"); |
| 982 | |
| 983 | if (ipa_ctx->ipa_pipes_down) { |
| 984 | /* |
| 985 | * This shouldn't happen : |
| 986 | * IPA WDI Pipes are already deactivated |
| 987 | */ |
| 988 | QDF_ASSERT(0); |
| 989 | ipa_warn("IPA WDI Pipes are already deactivated"); |
| 990 | goto end; |
| 991 | } |
| 992 | |
| 993 | cdp_ipa_disable_autonomy(ipa_ctx->dp_soc, |
| 994 | ipa_ctx->dp_pdev); |
| 995 | |
| 996 | result = cdp_ipa_disable_pipes(ipa_ctx->dp_soc, |
| 997 | ipa_ctx->dp_pdev); |
| 998 | if (result) { |
| 999 | ipa_err("Disable IPA WDI PIPE failed: ret=%d", result); |
| 1000 | return QDF_STATUS_E_FAILURE; |
| 1001 | } |
| 1002 | |
| 1003 | ipa_ctx->ipa_pipes_down = true; |
| 1004 | |
| 1005 | end: |
| 1006 | ipa_debug("exit: ipa_pipes_down=%d", ipa_ctx->ipa_pipes_down); |
| 1007 | |
| 1008 | return QDF_STATUS_SUCCESS; |
| 1009 | } |
| 1010 | |
Sravan Kumar Kairam | d01b445 | 2018-03-07 17:37:09 +0530 | [diff] [blame] | 1011 | /** |
Sravan Kumar Kairam | 5214f65 | 2018-03-13 09:52:31 +0530 | [diff] [blame] | 1012 | * wlan_ipa_uc_find_add_assoc_sta() - Find associated station |
| 1013 | * @ipa_ctx: Global IPA IPA context |
| 1014 | * @sta_add: Should station be added |
| 1015 | * @sta_id: ID of the station being queried |
| 1016 | * |
| 1017 | * Return: true if the station was found |
| 1018 | */ |
| 1019 | static bool wlan_ipa_uc_find_add_assoc_sta(struct wlan_ipa_priv *ipa_ctx, |
| 1020 | bool sta_add, uint8_t sta_id, |
| 1021 | uint8_t *mac_addr) |
| 1022 | { |
| 1023 | bool sta_found = false; |
| 1024 | uint8_t idx; |
| 1025 | |
| 1026 | for (idx = 0; idx < WLAN_IPA_MAX_STA_COUNT; idx++) { |
| 1027 | if ((ipa_ctx->assoc_stas_map[idx].is_reserved) && |
| 1028 | (ipa_ctx->assoc_stas_map[idx].sta_id == sta_id)) { |
| 1029 | sta_found = true; |
| 1030 | break; |
| 1031 | } |
| 1032 | } |
| 1033 | if (sta_add && sta_found) { |
| 1034 | ipa_err("STA ID %d already exist, cannot add", sta_id); |
| 1035 | return sta_found; |
| 1036 | } |
| 1037 | if (sta_add) { |
| 1038 | for (idx = 0; idx < WLAN_IPA_MAX_STA_COUNT; idx++) { |
| 1039 | if (!ipa_ctx->assoc_stas_map[idx].is_reserved) { |
| 1040 | ipa_ctx->assoc_stas_map[idx].is_reserved = true; |
| 1041 | ipa_ctx->assoc_stas_map[idx].sta_id = sta_id; |
| 1042 | qdf_mem_copy(&ipa_ctx->assoc_stas_map[idx]. |
| 1043 | mac_addr, mac_addr, |
| 1044 | QDF_NET_ETH_LEN); |
| 1045 | return sta_found; |
| 1046 | } |
| 1047 | } |
| 1048 | } |
| 1049 | if (!sta_add && !sta_found) { |
| 1050 | ipa_err("STA ID %d does not exist, cannot delete", sta_id); |
| 1051 | return sta_found; |
| 1052 | } |
| 1053 | if (!sta_add) { |
| 1054 | for (idx = 0; idx < WLAN_IPA_MAX_STA_COUNT; idx++) { |
| 1055 | if ((ipa_ctx->assoc_stas_map[idx].is_reserved) && |
| 1056 | (ipa_ctx->assoc_stas_map[idx].sta_id == sta_id)) { |
| 1057 | ipa_ctx->assoc_stas_map[idx].is_reserved = |
| 1058 | false; |
| 1059 | ipa_ctx->assoc_stas_map[idx].sta_id = 0xFF; |
| 1060 | qdf_mem_set(&ipa_ctx->assoc_stas_map[idx]. |
| 1061 | mac_addr, 0, QDF_NET_ETH_LEN); |
| 1062 | return sta_found; |
| 1063 | } |
| 1064 | } |
| 1065 | } |
| 1066 | |
| 1067 | return sta_found; |
| 1068 | } |
| 1069 | |
| 1070 | /** |
| 1071 | * wlan_ipa_get_ifaceid() - Get IPA context interface ID |
| 1072 | * @ipa_ctx: IPA context |
| 1073 | * @session_id: Session ID |
| 1074 | * |
| 1075 | * Return: None |
| 1076 | */ |
| 1077 | static int wlan_ipa_get_ifaceid(struct wlan_ipa_priv *ipa_ctx, |
| 1078 | uint8_t session_id) |
| 1079 | { |
| 1080 | struct wlan_ipa_iface_context *iface_ctx; |
| 1081 | int i; |
| 1082 | |
| 1083 | for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) { |
| 1084 | iface_ctx = &ipa_ctx->iface_context[i]; |
| 1085 | if (iface_ctx->session_id == session_id) |
| 1086 | break; |
| 1087 | } |
| 1088 | |
| 1089 | return i; |
| 1090 | } |
| 1091 | |
| 1092 | /** |
| 1093 | * wlan_ipa_cleanup_iface() - Cleanup IPA on a given interface |
| 1094 | * @iface_context: interface-specific IPA context |
| 1095 | * |
| 1096 | * Return: None |
| 1097 | */ |
| 1098 | static void wlan_ipa_cleanup_iface(struct wlan_ipa_iface_context *iface_context) |
| 1099 | { |
| 1100 | struct wlan_ipa_priv *ipa_ctx = iface_context->ipa_ctx; |
| 1101 | |
| 1102 | ipa_debug("enter"); |
| 1103 | |
| 1104 | if (!iface_context->tl_context) |
| 1105 | return; |
| 1106 | |
| 1107 | cdp_ipa_cleanup_iface(ipa_ctx->dp_soc, |
| 1108 | iface_context->dev->name, |
| 1109 | wlan_ipa_is_ipv6_enabled(ipa_ctx->config)); |
| 1110 | |
| 1111 | qdf_spin_lock_bh(&iface_context->interface_lock); |
| 1112 | iface_context->tl_context = NULL; |
| 1113 | iface_context->dev = NULL; |
| 1114 | iface_context->device_mode = QDF_MAX_NO_OF_MODE; |
| 1115 | iface_context->session_id = WLAN_IPA_MAX_SESSION; |
| 1116 | iface_context->sta_id = WLAN_IPA_MAX_STA_COUNT; |
| 1117 | qdf_spin_unlock_bh(&iface_context->interface_lock); |
| 1118 | iface_context->ifa_address = 0; |
| 1119 | if (!iface_context->ipa_ctx->num_iface) { |
| 1120 | ipa_err("NUM INTF 0, Invalid"); |
| 1121 | QDF_ASSERT(0); |
| 1122 | } |
| 1123 | iface_context->ipa_ctx->num_iface--; |
| 1124 | ipa_debug("exit: num_iface=%d", iface_context->ipa_ctx->num_iface); |
| 1125 | } |
| 1126 | |
| 1127 | /** |
| 1128 | * wlan_ipa_setup_iface() - Setup IPA on a given interface |
| 1129 | * @ipa_ctx: IPA IPA global context |
| 1130 | * @net_dev: Interface net device |
| 1131 | * @device_mode: Net interface device mode |
| 1132 | * @adapter: Interface upon which IPA is being setup |
| 1133 | * @sta_id: Station ID of the API instance |
| 1134 | * @session_id: Station ID of the API instance |
| 1135 | * |
| 1136 | * Return: QDF STATUS |
| 1137 | */ |
| 1138 | static QDF_STATUS wlan_ipa_setup_iface(struct wlan_ipa_priv *ipa_ctx, |
| 1139 | qdf_netdev_t net_dev, |
| 1140 | uint8_t device_mode, uint8_t sta_id, |
| 1141 | uint8_t session_id) |
| 1142 | { |
| 1143 | struct wlan_ipa_iface_context *iface_context = NULL; |
| 1144 | void *tl_context = NULL; |
| 1145 | int i; |
| 1146 | QDF_STATUS status; |
| 1147 | |
| 1148 | /* Lower layer may send multiple START_BSS_EVENT in DFS mode or during |
| 1149 | * channel change indication. Since these indications are sent by lower |
| 1150 | * layer as SAP updates and IPA doesn't have to do anything for these |
| 1151 | * updates so ignoring! |
| 1152 | */ |
| 1153 | if (device_mode == QDF_SAP_MODE) { |
| 1154 | for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) { |
| 1155 | iface_context = &(ipa_ctx->iface_context[i]); |
| 1156 | if (iface_context->dev == net_dev) |
| 1157 | return QDF_STATUS_SUCCESS; |
| 1158 | } |
| 1159 | } |
| 1160 | |
Yun Park | 21ec490 | 2018-04-24 12:11:01 -0700 | [diff] [blame] | 1161 | if (WLAN_IPA_MAX_IFACE == ipa_ctx->num_iface) { |
| 1162 | ipa_err("Max interface reached %d", WLAN_IPA_MAX_IFACE); |
| 1163 | status = QDF_STATUS_E_NOMEM; |
| 1164 | QDF_ASSERT(0); |
| 1165 | goto end; |
| 1166 | } |
| 1167 | |
Sravan Kumar Kairam | 5214f65 | 2018-03-13 09:52:31 +0530 | [diff] [blame] | 1168 | for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) { |
| 1169 | if (ipa_ctx->iface_context[i].tl_context == NULL) { |
| 1170 | iface_context = &(ipa_ctx->iface_context[i]); |
| 1171 | break; |
| 1172 | } |
| 1173 | } |
| 1174 | |
| 1175 | if (iface_context == NULL) { |
| 1176 | ipa_err("All the IPA interfaces are in use"); |
| 1177 | status = QDF_STATUS_E_NOMEM; |
Yun Park | 21ec490 | 2018-04-24 12:11:01 -0700 | [diff] [blame] | 1178 | QDF_ASSERT(0); |
Sravan Kumar Kairam | 5214f65 | 2018-03-13 09:52:31 +0530 | [diff] [blame] | 1179 | goto end; |
| 1180 | } |
| 1181 | |
| 1182 | iface_context->sta_id = sta_id; |
| 1183 | tl_context = (void *)cdp_peer_get_vdev_by_sta_id(ipa_ctx->dp_soc, |
| 1184 | ipa_ctx->dp_pdev, |
| 1185 | sta_id); |
| 1186 | if (tl_context == NULL) { |
| 1187 | ipa_err("Not able to get TL context sta_id: %d", sta_id); |
| 1188 | status = QDF_STATUS_E_INVAL; |
| 1189 | goto end; |
| 1190 | } |
| 1191 | |
| 1192 | iface_context->tl_context = tl_context; |
| 1193 | iface_context->dev = net_dev; |
| 1194 | iface_context->device_mode = device_mode; |
| 1195 | iface_context->session_id = session_id; |
| 1196 | |
| 1197 | status = cdp_ipa_setup_iface(ipa_ctx->dp_soc, net_dev->name, |
| 1198 | net_dev->dev_addr, |
| 1199 | iface_context->prod_client, |
| 1200 | iface_context->cons_client, |
| 1201 | session_id, |
| 1202 | wlan_ipa_is_ipv6_enabled(ipa_ctx->config)); |
| 1203 | if (status != QDF_STATUS_SUCCESS) |
| 1204 | goto end; |
| 1205 | |
| 1206 | ipa_ctx->num_iface++; |
| 1207 | |
| 1208 | ipa_debug("exit: num_iface=%d", ipa_ctx->num_iface); |
| 1209 | |
| 1210 | return status; |
| 1211 | |
| 1212 | end: |
| 1213 | if (iface_context) |
| 1214 | wlan_ipa_cleanup_iface(iface_context); |
| 1215 | |
| 1216 | return status; |
| 1217 | } |
| 1218 | |
| 1219 | /** |
| 1220 | * wlan_ipa_uc_handle_first_con() - Handle first uC IPA connection |
| 1221 | * @ipa_ctx: IPA context |
| 1222 | * |
| 1223 | * Return: QDF STATUS |
| 1224 | */ |
| 1225 | static QDF_STATUS wlan_ipa_uc_handle_first_con(struct wlan_ipa_priv *ipa_ctx) |
| 1226 | { |
| 1227 | ipa_debug("enter"); |
| 1228 | |
| 1229 | ipa_ctx->activated_fw_pipe = 0; |
| 1230 | ipa_ctx->resource_loading = true; |
| 1231 | |
| 1232 | /* If RM feature enabled |
| 1233 | * Request PROD Resource first |
| 1234 | * PROD resource may return sync or async manners |
| 1235 | */ |
| 1236 | if (wlan_ipa_is_rm_enabled(ipa_ctx->config)) { |
Yun Park | e114fbf | 2018-04-05 20:02:12 -0700 | [diff] [blame] | 1237 | if (!wlan_ipa_wdi_rm_request_resource(ipa_ctx, |
| 1238 | IPA_RM_RESOURCE_WLAN_PROD)) { |
Sravan Kumar Kairam | 5214f65 | 2018-03-13 09:52:31 +0530 | [diff] [blame] | 1239 | /* RM PROD request sync return |
| 1240 | * enable pipe immediately |
| 1241 | */ |
| 1242 | if (wlan_ipa_uc_enable_pipes(ipa_ctx)) { |
| 1243 | ipa_err("IPA WDI Pipe activation failed"); |
| 1244 | ipa_ctx->resource_loading = false; |
| 1245 | return QDF_STATUS_E_BUSY; |
| 1246 | } |
| 1247 | } else { |
| 1248 | ipa_err("IPA WDI Pipe activation deferred"); |
| 1249 | } |
| 1250 | } else { |
| 1251 | /* RM Disabled |
| 1252 | * Just enabled all the PIPEs |
| 1253 | */ |
| 1254 | if (wlan_ipa_uc_enable_pipes(ipa_ctx)) { |
| 1255 | ipa_err("IPA WDI Pipe activation failed"); |
| 1256 | ipa_ctx->resource_loading = false; |
| 1257 | return QDF_STATUS_E_BUSY; |
| 1258 | } |
| 1259 | ipa_ctx->resource_loading = false; |
| 1260 | } |
| 1261 | |
| 1262 | ipa_debug("exit"); |
| 1263 | |
| 1264 | return QDF_STATUS_SUCCESS; |
| 1265 | } |
| 1266 | |
| 1267 | /** |
| 1268 | * wlan_ipa_uc_handle_last_discon() - Handle last uC IPA disconnection |
| 1269 | * @ipa_ctx: IPA context |
| 1270 | * |
| 1271 | * Return: None |
| 1272 | */ |
| 1273 | static void wlan_ipa_uc_handle_last_discon(struct wlan_ipa_priv *ipa_ctx) |
| 1274 | { |
| 1275 | ipa_debug("enter"); |
| 1276 | |
| 1277 | ipa_ctx->resource_unloading = true; |
| 1278 | qdf_event_reset(&ipa_ctx->ipa_resource_comp); |
| 1279 | ipa_info("Disable FW RX PIPE"); |
| 1280 | cdp_ipa_set_active(ipa_ctx->dp_soc, ipa_ctx->dp_pdev, false, false); |
| 1281 | ipa_info("Disable FW TX PIPE"); |
| 1282 | cdp_ipa_set_active(ipa_ctx->dp_soc, ipa_ctx->dp_pdev, false, true); |
| 1283 | |
| 1284 | ipa_debug("exit: IPA WDI Pipes deactivated"); |
| 1285 | } |
| 1286 | |
| 1287 | /** |
| 1288 | * wlan_ipa_uc_offload_enable_disable() - wdi enable/disable notify to fw |
| 1289 | * @ipa_ctx: global IPA context |
| 1290 | * @offload_type: MCC or SCC |
| 1291 | * @session_id: Session Id |
| 1292 | * @enable: TX offload enable or disable |
| 1293 | * |
| 1294 | * Return: none |
| 1295 | */ |
| 1296 | static void wlan_ipa_uc_offload_enable_disable(struct wlan_ipa_priv *ipa_ctx, |
| 1297 | uint32_t offload_type, |
| 1298 | uint8_t session_id, |
| 1299 | bool enable) |
| 1300 | { |
| 1301 | |
| 1302 | struct ipa_uc_offload_control_params req = {0}; |
| 1303 | |
| 1304 | if (session_id >= WLAN_IPA_MAX_SESSION) { |
| 1305 | ipa_err("invalid session id: %d", session_id); |
| 1306 | return; |
| 1307 | } |
| 1308 | |
| 1309 | if (enable == ipa_ctx->vdev_offload_enabled[session_id]) { |
| 1310 | /* |
| 1311 | * This shouldn't happen : |
| 1312 | * IPA offload status is already set as desired |
| 1313 | */ |
| 1314 | QDF_ASSERT(0); |
| 1315 | ipa_warn("IPA offload status is already set"); |
| 1316 | ipa_warn("offload_type=%d, vdev_id=%d, enable=%d", |
| 1317 | offload_type, session_id, enable); |
| 1318 | return; |
| 1319 | } |
| 1320 | |
| 1321 | ipa_info("offload_type=%d, session_id=%d, enable=%d", |
| 1322 | offload_type, session_id, enable); |
| 1323 | |
| 1324 | req.offload_type = offload_type; |
| 1325 | req.vdev_id = session_id; |
| 1326 | req.enable = enable; |
| 1327 | |
| 1328 | if (QDF_STATUS_SUCCESS != |
| 1329 | ipa_send_uc_offload_enable_disable(ipa_ctx->pdev, &req)) { |
| 1330 | ipa_err("Fail to enable IPA offload"); |
| 1331 | ipa_err("offload type=%d, vdev_id=%d, enable=%d", |
| 1332 | offload_type, session_id, enable); |
| 1333 | } else { |
| 1334 | ipa_ctx->vdev_offload_enabled[session_id] = enable; |
| 1335 | } |
| 1336 | } |
| 1337 | |
| 1338 | /** |
| 1339 | * __wlan_ipa_wlan_evt() - IPA event handler |
| 1340 | * @net_dev: Interface net device |
| 1341 | * @device_mode: Net interface device mode |
| 1342 | * @sta_id: station id for the event |
| 1343 | * @session_id: session id for the event |
| 1344 | * @type: event enum of type ipa_wlan_event |
| 1345 | * @mac_address: MAC address associated with the event |
| 1346 | * |
| 1347 | * This function is meant to be called from within wlan_ipa_ctx.c |
| 1348 | * |
| 1349 | * Return: QDF STATUS |
| 1350 | */ |
| 1351 | static QDF_STATUS __wlan_ipa_wlan_evt(qdf_netdev_t net_dev, uint8_t device_mode, |
| 1352 | uint8_t sta_id, uint8_t session_id, |
| 1353 | qdf_ipa_wlan_event type, |
| 1354 | uint8_t *mac_addr) |
| 1355 | { |
| 1356 | struct wlan_ipa_priv *ipa_ctx = gp_ipa; |
| 1357 | struct wlan_ipa_iface_context *iface_ctx = NULL; |
| 1358 | qdf_ipa_msg_meta_t meta; |
| 1359 | qdf_ipa_wlan_msg_t *msg; |
| 1360 | qdf_ipa_wlan_msg_ex_t *msg_ex = NULL; |
| 1361 | int i; |
| 1362 | QDF_STATUS status; |
| 1363 | |
| 1364 | ipa_debug("%s: EVT: %d, MAC: %pM, sta_id: %d", |
| 1365 | net_dev->name, type, mac_addr, sta_id); |
| 1366 | |
| 1367 | if (type >= QDF_IPA_WLAN_EVENT_MAX) |
| 1368 | return QDF_STATUS_E_INVAL; |
| 1369 | |
| 1370 | if (wlan_ipa_uc_is_enabled(ipa_ctx->config) && |
| 1371 | !wlan_ipa_uc_sta_is_enabled(ipa_ctx->config) && |
| 1372 | (device_mode != QDF_SAP_MODE)) { |
| 1373 | return QDF_STATUS_SUCCESS; |
| 1374 | } |
| 1375 | |
| 1376 | /* |
| 1377 | * During IPA UC resource loading/unloading new events can be issued. |
| 1378 | */ |
| 1379 | if (wlan_ipa_uc_is_enabled(ipa_ctx->config) && |
| 1380 | (ipa_ctx->resource_loading || ipa_ctx->resource_unloading)) { |
| 1381 | unsigned int pending_event_count; |
| 1382 | struct wlan_ipa_uc_pending_event *pending_event = NULL; |
| 1383 | |
| 1384 | ipa_info("Event:%d IPA resource %s inprogress", type, |
| 1385 | ipa_ctx->resource_loading ? |
| 1386 | "load" : "unload"); |
| 1387 | |
| 1388 | /* Wait until completion of the long/unloading */ |
| 1389 | status = qdf_wait_for_event_completion( |
| 1390 | &ipa_ctx->ipa_resource_comp, |
jiad | a8c542c | 2018-05-29 16:24:13 +0800 | [diff] [blame] | 1391 | IPA_RESOURCE_COMP_WAIT_TIME); |
Sravan Kumar Kairam | 5214f65 | 2018-03-13 09:52:31 +0530 | [diff] [blame] | 1392 | if (status != QDF_STATUS_SUCCESS) { |
| 1393 | /* |
| 1394 | * If timed out, store the events separately and |
| 1395 | * handle them later. |
| 1396 | */ |
| 1397 | ipa_info("IPA resource %s timed out", |
| 1398 | ipa_ctx->resource_loading ? |
| 1399 | "load" : "unload"); |
| 1400 | |
| 1401 | qdf_mutex_acquire(&ipa_ctx->ipa_lock); |
| 1402 | |
| 1403 | pending_event_count = |
| 1404 | qdf_list_size(&ipa_ctx->pending_event); |
| 1405 | if (pending_event_count >= |
| 1406 | WLAN_IPA_MAX_PENDING_EVENT_COUNT) { |
| 1407 | ipa_info("Reached max pending evt count"); |
| 1408 | qdf_list_remove_front( |
| 1409 | &ipa_ctx->pending_event, |
| 1410 | (qdf_list_node_t **)&pending_event); |
| 1411 | } else { |
| 1412 | pending_event = |
| 1413 | (struct wlan_ipa_uc_pending_event *) |
| 1414 | qdf_mem_malloc(sizeof( |
| 1415 | struct wlan_ipa_uc_pending_event)); |
| 1416 | } |
| 1417 | |
| 1418 | if (!pending_event) { |
| 1419 | ipa_err("Pending event memory alloc fail"); |
| 1420 | qdf_mutex_release(&ipa_ctx->ipa_lock); |
| 1421 | return QDF_STATUS_E_NOMEM; |
| 1422 | } |
| 1423 | |
| 1424 | pending_event->net_dev = net_dev; |
| 1425 | pending_event->device_mode = device_mode; |
| 1426 | pending_event->sta_id = sta_id; |
| 1427 | pending_event->session_id = session_id; |
| 1428 | pending_event->type = type; |
| 1429 | pending_event->is_loading = ipa_ctx->resource_loading; |
| 1430 | qdf_mem_copy(pending_event->mac_addr, |
| 1431 | mac_addr, QDF_MAC_ADDR_SIZE); |
| 1432 | qdf_list_insert_back(&ipa_ctx->pending_event, |
| 1433 | &pending_event->node); |
| 1434 | |
| 1435 | qdf_mutex_release(&ipa_ctx->ipa_lock); |
| 1436 | |
Yun Park | 21ec490 | 2018-04-24 12:11:01 -0700 | [diff] [blame] | 1437 | /* Cleanup interface */ |
| 1438 | if (type == QDF_IPA_STA_DISCONNECT || |
| 1439 | type == QDF_IPA_AP_DISCONNECT) { |
| 1440 | for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) { |
| 1441 | iface_ctx = &ipa_ctx->iface_context[i]; |
| 1442 | |
| 1443 | if (iface_ctx->dev == net_dev) |
| 1444 | break; |
| 1445 | } |
| 1446 | if (iface_ctx) |
| 1447 | wlan_ipa_cleanup_iface(iface_ctx); |
| 1448 | } |
| 1449 | |
Sravan Kumar Kairam | 5214f65 | 2018-03-13 09:52:31 +0530 | [diff] [blame] | 1450 | return QDF_STATUS_SUCCESS; |
| 1451 | } |
| 1452 | ipa_info("IPA resource %s completed", |
| 1453 | ipa_ctx->resource_loading ? |
| 1454 | "load" : "unload"); |
| 1455 | } |
| 1456 | |
| 1457 | ipa_ctx->stats.event[type]++; |
| 1458 | |
| 1459 | QDF_IPA_SET_META_MSG_TYPE(&meta, type); |
| 1460 | switch (type) { |
| 1461 | case QDF_IPA_STA_CONNECT: |
| 1462 | qdf_mutex_acquire(&ipa_ctx->event_lock); |
| 1463 | |
| 1464 | /* STA already connected and without disconnect, connect again |
| 1465 | * This is Roaming scenario |
| 1466 | */ |
| 1467 | if (ipa_ctx->sta_connected) { |
| 1468 | iface_ctx = wlan_ipa_get_iface(ipa_ctx, QDF_STA_MODE); |
| 1469 | if (iface_ctx) |
| 1470 | wlan_ipa_cleanup_iface(iface_ctx); |
| 1471 | } |
| 1472 | |
| 1473 | status = wlan_ipa_setup_iface(ipa_ctx, net_dev, device_mode, |
| 1474 | sta_id, session_id); |
| 1475 | if (status != QDF_STATUS_SUCCESS) { |
| 1476 | qdf_mutex_release(&ipa_ctx->event_lock); |
| 1477 | goto end; |
| 1478 | } |
| 1479 | |
| 1480 | if (wlan_ipa_uc_sta_is_enabled(ipa_ctx->config) && |
| 1481 | (ipa_ctx->sap_num_connected_sta > 0) && |
| 1482 | !ipa_ctx->sta_connected) { |
| 1483 | qdf_mutex_release(&ipa_ctx->event_lock); |
| 1484 | wlan_ipa_uc_offload_enable_disable(ipa_ctx, |
| 1485 | SIR_STA_RX_DATA_OFFLOAD, session_id, |
| 1486 | true); |
| 1487 | qdf_mutex_acquire(&ipa_ctx->event_lock); |
| 1488 | } |
| 1489 | |
| 1490 | ipa_ctx->vdev_to_iface[session_id] = |
| 1491 | wlan_ipa_get_ifaceid(ipa_ctx, session_id); |
| 1492 | |
| 1493 | ipa_ctx->sta_connected = 1; |
| 1494 | |
| 1495 | qdf_mutex_release(&ipa_ctx->event_lock); |
| 1496 | |
| 1497 | ipa_debug("sta_connected=%d", ipa_ctx->sta_connected); |
| 1498 | break; |
| 1499 | |
| 1500 | case QDF_IPA_AP_CONNECT: |
| 1501 | qdf_mutex_acquire(&ipa_ctx->event_lock); |
| 1502 | |
| 1503 | /* For DFS channel we get two start_bss event (before and after |
| 1504 | * CAC). Also when ACS range includes both DFS and non DFS |
| 1505 | * channels, we could possibly change channel many times due to |
| 1506 | * RADAR detection and chosen channel may not be a DFS channels. |
| 1507 | * So dont return error here. Just discard the event. |
| 1508 | */ |
jiad | c908ada | 2018-05-11 14:40:54 +0800 | [diff] [blame] | 1509 | if (ipa_ctx->vdev_to_iface[session_id] != |
| 1510 | WLAN_IPA_MAX_SESSION) { |
Sravan Kumar Kairam | 5214f65 | 2018-03-13 09:52:31 +0530 | [diff] [blame] | 1511 | qdf_mutex_release(&ipa_ctx->event_lock); |
| 1512 | return 0; |
| 1513 | } |
| 1514 | |
| 1515 | status = wlan_ipa_setup_iface(ipa_ctx, net_dev, device_mode, |
| 1516 | sta_id, session_id); |
| 1517 | if (status != QDF_STATUS_SUCCESS) { |
| 1518 | qdf_mutex_release(&ipa_ctx->event_lock); |
| 1519 | ipa_err("%s: Evt: %d, Interface setup failed", |
| 1520 | msg_ex->name, QDF_IPA_MSG_META_MSG_TYPE(&meta)); |
| 1521 | goto end; |
| 1522 | } |
| 1523 | |
| 1524 | if (wlan_ipa_uc_is_enabled(ipa_ctx->config)) { |
| 1525 | qdf_mutex_release(&ipa_ctx->event_lock); |
| 1526 | wlan_ipa_uc_offload_enable_disable(ipa_ctx, |
| 1527 | SIR_AP_RX_DATA_OFFLOAD, session_id, true); |
| 1528 | qdf_mutex_acquire(&ipa_ctx->event_lock); |
| 1529 | } |
| 1530 | |
| 1531 | ipa_ctx->vdev_to_iface[session_id] = |
| 1532 | wlan_ipa_get_ifaceid(ipa_ctx, session_id); |
| 1533 | qdf_mutex_release(&ipa_ctx->event_lock); |
| 1534 | break; |
| 1535 | |
| 1536 | case QDF_IPA_STA_DISCONNECT: |
| 1537 | qdf_mutex_acquire(&ipa_ctx->event_lock); |
| 1538 | |
| 1539 | if (!ipa_ctx->sta_connected) { |
| 1540 | qdf_mutex_release(&ipa_ctx->event_lock); |
| 1541 | ipa_err("%s: Evt: %d, STA already disconnected", |
| 1542 | msg_ex->name, QDF_IPA_MSG_META_MSG_TYPE(&meta)); |
| 1543 | return QDF_STATUS_E_INVAL; |
| 1544 | } |
| 1545 | |
| 1546 | ipa_ctx->sta_connected = 0; |
| 1547 | |
| 1548 | if (!wlan_ipa_uc_is_enabled(ipa_ctx->config)) { |
| 1549 | ipa_debug("%s: IPA UC OFFLOAD NOT ENABLED", |
| 1550 | msg_ex->name); |
| 1551 | } else { |
| 1552 | /* Disable IPA UC TX PIPE when STA disconnected */ |
| 1553 | if ((ipa_ctx->num_iface == 1) && |
Yun Park | a29974a | 2018-04-09 12:05:49 -0700 | [diff] [blame] | 1554 | wlan_ipa_is_fw_wdi_activated(ipa_ctx) && |
Sravan Kumar Kairam | 5214f65 | 2018-03-13 09:52:31 +0530 | [diff] [blame] | 1555 | !ipa_ctx->ipa_pipes_down) |
| 1556 | wlan_ipa_uc_handle_last_discon(ipa_ctx); |
| 1557 | } |
| 1558 | |
| 1559 | if (wlan_ipa_uc_sta_is_enabled(ipa_ctx->config) && |
| 1560 | (ipa_ctx->sap_num_connected_sta > 0)) { |
| 1561 | qdf_mutex_release(&ipa_ctx->event_lock); |
| 1562 | wlan_ipa_uc_offload_enable_disable(ipa_ctx, |
| 1563 | SIR_STA_RX_DATA_OFFLOAD, session_id, false); |
| 1564 | qdf_mutex_acquire(&ipa_ctx->event_lock); |
| 1565 | ipa_ctx->vdev_to_iface[session_id] = |
| 1566 | WLAN_IPA_MAX_SESSION; |
| 1567 | } |
| 1568 | |
| 1569 | for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) { |
| 1570 | iface_ctx = &ipa_ctx->iface_context[i]; |
| 1571 | |
| 1572 | if (iface_ctx->dev == net_dev) |
| 1573 | break; |
| 1574 | } |
| 1575 | if (i < WLAN_IPA_MAX_IFACE) |
| 1576 | wlan_ipa_cleanup_iface(iface_ctx); |
| 1577 | |
| 1578 | qdf_mutex_release(&ipa_ctx->event_lock); |
| 1579 | |
| 1580 | ipa_debug("sta_connected=%d", ipa_ctx->sta_connected); |
| 1581 | break; |
| 1582 | |
| 1583 | case QDF_IPA_AP_DISCONNECT: |
| 1584 | qdf_mutex_acquire(&ipa_ctx->event_lock); |
| 1585 | |
| 1586 | if ((ipa_ctx->num_iface == 1) && |
Yun Park | a29974a | 2018-04-09 12:05:49 -0700 | [diff] [blame] | 1587 | wlan_ipa_is_fw_wdi_activated(ipa_ctx) && |
Sravan Kumar Kairam | 5214f65 | 2018-03-13 09:52:31 +0530 | [diff] [blame] | 1588 | !ipa_ctx->ipa_pipes_down) { |
| 1589 | if (cds_is_driver_unloading()) { |
| 1590 | /* |
| 1591 | * We disable WDI pipes directly here since |
| 1592 | * IPA_OPCODE_TX/RX_SUSPEND message will not be |
| 1593 | * processed when unloading WLAN driver is in |
| 1594 | * progress |
| 1595 | */ |
| 1596 | wlan_ipa_uc_disable_pipes(ipa_ctx); |
| 1597 | } else { |
| 1598 | /* |
| 1599 | * This shouldn't happen : |
| 1600 | * No interface left but WDI pipes are still |
| 1601 | * active - force close WDI pipes |
| 1602 | */ |
| 1603 | ipa_err("No interface left but WDI pipes are still active"); |
| 1604 | wlan_ipa_uc_handle_last_discon(ipa_ctx); |
| 1605 | } |
| 1606 | } |
| 1607 | |
| 1608 | if (wlan_ipa_uc_is_enabled(ipa_ctx->config)) { |
| 1609 | qdf_mutex_release(&ipa_ctx->event_lock); |
| 1610 | wlan_ipa_uc_offload_enable_disable(ipa_ctx, |
| 1611 | SIR_AP_RX_DATA_OFFLOAD, session_id, false); |
| 1612 | qdf_mutex_acquire(&ipa_ctx->event_lock); |
| 1613 | ipa_ctx->vdev_to_iface[session_id] = |
| 1614 | WLAN_IPA_MAX_SESSION; |
| 1615 | } |
| 1616 | |
| 1617 | for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) { |
| 1618 | iface_ctx = &ipa_ctx->iface_context[i]; |
| 1619 | |
| 1620 | if (iface_ctx->dev == net_dev) |
| 1621 | break; |
| 1622 | } |
| 1623 | if (i < WLAN_IPA_MAX_IFACE) |
| 1624 | wlan_ipa_cleanup_iface(iface_ctx); |
| 1625 | |
| 1626 | qdf_mutex_release(&ipa_ctx->event_lock); |
| 1627 | break; |
| 1628 | |
| 1629 | case QDF_IPA_CLIENT_CONNECT_EX: |
| 1630 | if (!wlan_ipa_uc_is_enabled(ipa_ctx->config)) { |
| 1631 | ipa_debug("%s: Evt: %d, IPA UC OFFLOAD NOT ENABLED", |
| 1632 | net_dev->name, type); |
| 1633 | return QDF_STATUS_SUCCESS; |
| 1634 | } |
| 1635 | |
| 1636 | qdf_mutex_acquire(&ipa_ctx->event_lock); |
| 1637 | if (wlan_ipa_uc_find_add_assoc_sta(ipa_ctx, true, sta_id, |
| 1638 | mac_addr)) { |
| 1639 | qdf_mutex_release(&ipa_ctx->event_lock); |
| 1640 | ipa_err("%s: STA ID %d found", net_dev->name, sta_id); |
| 1641 | return QDF_STATUS_SUCCESS; |
| 1642 | } |
| 1643 | |
| 1644 | /* Enable IPA UC Data PIPEs when first STA connected */ |
| 1645 | if (ipa_ctx->sap_num_connected_sta == 0 && |
| 1646 | ipa_ctx->uc_loaded == true) { |
Sravan Kumar Kairam | f59aec1 | 2018-03-23 19:35:01 +0530 | [diff] [blame] | 1647 | struct wlan_ipa_iface_context *iface_ctx; |
| 1648 | uint8_t sta_session_id; |
| 1649 | |
Sravan Kumar Kairam | 5214f65 | 2018-03-13 09:52:31 +0530 | [diff] [blame] | 1650 | if (wlan_ipa_uc_sta_is_enabled(ipa_ctx->config) && |
| 1651 | ipa_ctx->sta_connected) { |
| 1652 | qdf_mutex_release(&ipa_ctx->event_lock); |
Sravan Kumar Kairam | f59aec1 | 2018-03-23 19:35:01 +0530 | [diff] [blame] | 1653 | iface_ctx = wlan_ipa_get_iface(ipa_ctx, QDF_STA_MODE); |
| 1654 | sta_session_id = iface_ctx->session_id; |
Sravan Kumar Kairam | 5214f65 | 2018-03-13 09:52:31 +0530 | [diff] [blame] | 1655 | wlan_ipa_uc_offload_enable_disable(ipa_ctx, |
| 1656 | SIR_STA_RX_DATA_OFFLOAD, |
Sravan Kumar Kairam | f59aec1 | 2018-03-23 19:35:01 +0530 | [diff] [blame] | 1657 | sta_session_id, true); |
Sravan Kumar Kairam | 5214f65 | 2018-03-13 09:52:31 +0530 | [diff] [blame] | 1658 | qdf_mutex_acquire(&ipa_ctx->event_lock); |
| 1659 | } |
| 1660 | |
| 1661 | status = wlan_ipa_uc_handle_first_con(ipa_ctx); |
| 1662 | if (status != QDF_STATUS_SUCCESS) { |
| 1663 | ipa_info("%s: handle 1st con fail", |
| 1664 | net_dev->name); |
| 1665 | |
| 1666 | if (wlan_ipa_uc_sta_is_enabled( |
| 1667 | ipa_ctx->config) && |
| 1668 | ipa_ctx->sta_connected) { |
| 1669 | qdf_mutex_release(&ipa_ctx->event_lock); |
Sravan Kumar Kairam | f59aec1 | 2018-03-23 19:35:01 +0530 | [diff] [blame] | 1670 | iface_ctx = wlan_ipa_get_iface(ipa_ctx, |
| 1671 | QDF_STA_MODE); |
| 1672 | sta_session_id = iface_ctx->session_id; |
Sravan Kumar Kairam | 5214f65 | 2018-03-13 09:52:31 +0530 | [diff] [blame] | 1673 | wlan_ipa_uc_offload_enable_disable( |
| 1674 | ipa_ctx, |
| 1675 | SIR_STA_RX_DATA_OFFLOAD, |
Sravan Kumar Kairam | f59aec1 | 2018-03-23 19:35:01 +0530 | [diff] [blame] | 1676 | sta_session_id, false); |
Sravan Kumar Kairam | 5214f65 | 2018-03-13 09:52:31 +0530 | [diff] [blame] | 1677 | } else { |
| 1678 | qdf_mutex_release(&ipa_ctx->event_lock); |
| 1679 | } |
| 1680 | |
| 1681 | return status; |
| 1682 | } |
| 1683 | } |
| 1684 | |
| 1685 | ipa_ctx->sap_num_connected_sta++; |
| 1686 | |
| 1687 | qdf_mutex_release(&ipa_ctx->event_lock); |
| 1688 | |
| 1689 | QDF_IPA_SET_META_MSG_TYPE(&meta, type); |
| 1690 | QDF_IPA_MSG_META_MSG_LEN(&meta) = |
| 1691 | (sizeof(qdf_ipa_wlan_msg_ex_t) + |
| 1692 | sizeof(qdf_ipa_wlan_hdr_attrib_val_t)); |
| 1693 | msg_ex = qdf_mem_malloc(QDF_IPA_MSG_META_MSG_LEN(&meta)); |
| 1694 | |
| 1695 | if (msg_ex == NULL) { |
| 1696 | ipa_err("msg_ex allocation failed"); |
| 1697 | return QDF_STATUS_E_NOMEM; |
| 1698 | } |
| 1699 | strlcpy(msg_ex->name, net_dev->name, |
| 1700 | IPA_RESOURCE_NAME_MAX); |
| 1701 | msg_ex->num_of_attribs = 1; |
| 1702 | msg_ex->attribs[0].attrib_type = WLAN_HDR_ATTRIB_MAC_ADDR; |
| 1703 | if (wlan_ipa_uc_is_enabled(ipa_ctx->config)) { |
| 1704 | msg_ex->attribs[0].offset = |
| 1705 | WLAN_IPA_UC_WLAN_HDR_DES_MAC_OFFSET; |
| 1706 | } else { |
| 1707 | msg_ex->attribs[0].offset = |
| 1708 | WLAN_IPA_WLAN_HDR_DES_MAC_OFFSET; |
| 1709 | } |
| 1710 | memcpy(msg_ex->attribs[0].u.mac_addr, mac_addr, |
| 1711 | IPA_MAC_ADDR_SIZE); |
| 1712 | |
| 1713 | if (qdf_ipa_send_msg(&meta, msg_ex, wlan_ipa_msg_free_fn)) { |
| 1714 | ipa_info("%s: Evt: %d send ipa msg fail", |
| 1715 | net_dev->name, type); |
| 1716 | qdf_mem_free(msg_ex); |
| 1717 | return QDF_STATUS_E_FAILURE; |
| 1718 | } |
| 1719 | ipa_ctx->stats.num_send_msg++; |
| 1720 | |
| 1721 | ipa_info("sap_num_connected_sta=%d", |
| 1722 | ipa_ctx->sap_num_connected_sta); |
| 1723 | |
| 1724 | return QDF_STATUS_SUCCESS; |
| 1725 | |
| 1726 | case WLAN_CLIENT_DISCONNECT: |
| 1727 | if (!wlan_ipa_uc_is_enabled(ipa_ctx->config)) { |
| 1728 | ipa_debug("%s: IPA UC OFFLOAD NOT ENABLED", |
| 1729 | msg_ex->name); |
| 1730 | return QDF_STATUS_SUCCESS; |
| 1731 | } |
| 1732 | |
| 1733 | qdf_mutex_acquire(&ipa_ctx->event_lock); |
| 1734 | if (!ipa_ctx->sap_num_connected_sta) { |
| 1735 | qdf_mutex_release(&ipa_ctx->event_lock); |
| 1736 | ipa_err("%s: Evt: %d, Client already disconnected", |
| 1737 | msg_ex->name, |
| 1738 | QDF_IPA_MSG_META_MSG_TYPE(&meta)); |
| 1739 | |
| 1740 | return QDF_STATUS_SUCCESS; |
| 1741 | } |
| 1742 | if (!wlan_ipa_uc_find_add_assoc_sta(ipa_ctx, false, |
| 1743 | sta_id, mac_addr)) { |
| 1744 | qdf_mutex_release(&ipa_ctx->event_lock); |
| 1745 | ipa_err("%s: STA ID %d NOT found, not valid", |
| 1746 | msg_ex->name, sta_id); |
| 1747 | |
| 1748 | return QDF_STATUS_SUCCESS; |
| 1749 | } |
| 1750 | ipa_ctx->sap_num_connected_sta--; |
| 1751 | |
| 1752 | /* Disable IPA UC TX PIPE when last STA disconnected */ |
| 1753 | if (!ipa_ctx->sap_num_connected_sta && |
| 1754 | ipa_ctx->uc_loaded == true) { |
Yun Park | a29974a | 2018-04-09 12:05:49 -0700 | [diff] [blame] | 1755 | if ((false == ipa_ctx->resource_unloading) && |
| 1756 | wlan_ipa_is_fw_wdi_activated(ipa_ctx) && |
| 1757 | !ipa_ctx->ipa_pipes_down) { |
Sravan Kumar Kairam | 5214f65 | 2018-03-13 09:52:31 +0530 | [diff] [blame] | 1758 | wlan_ipa_uc_handle_last_discon(ipa_ctx); |
| 1759 | } |
| 1760 | |
| 1761 | if (wlan_ipa_uc_sta_is_enabled(ipa_ctx->config) && |
| 1762 | ipa_ctx->sta_connected) { |
Sravan Kumar Kairam | f59aec1 | 2018-03-23 19:35:01 +0530 | [diff] [blame] | 1763 | struct wlan_ipa_iface_context *iface_ctx; |
| 1764 | uint8_t sta_session_id; |
| 1765 | |
| 1766 | iface_ctx = wlan_ipa_get_iface(ipa_ctx, |
| 1767 | QDF_STA_MODE); |
| 1768 | sta_session_id = iface_ctx->session_id; |
| 1769 | |
Sravan Kumar Kairam | 5214f65 | 2018-03-13 09:52:31 +0530 | [diff] [blame] | 1770 | qdf_mutex_release(&ipa_ctx->event_lock); |
| 1771 | wlan_ipa_uc_offload_enable_disable(ipa_ctx, |
| 1772 | SIR_STA_RX_DATA_OFFLOAD, |
Sravan Kumar Kairam | f59aec1 | 2018-03-23 19:35:01 +0530 | [diff] [blame] | 1773 | sta_session_id, false); |
Sravan Kumar Kairam | 5214f65 | 2018-03-13 09:52:31 +0530 | [diff] [blame] | 1774 | } else { |
| 1775 | qdf_mutex_release(&ipa_ctx->event_lock); |
| 1776 | } |
| 1777 | } else { |
| 1778 | qdf_mutex_release(&ipa_ctx->event_lock); |
| 1779 | } |
| 1780 | |
| 1781 | ipa_info("sap_num_connected_sta=%d", |
| 1782 | ipa_ctx->sap_num_connected_sta); |
| 1783 | break; |
| 1784 | |
| 1785 | default: |
| 1786 | return QDF_STATUS_SUCCESS; |
| 1787 | } |
| 1788 | |
| 1789 | QDF_IPA_MSG_META_MSG_LEN(&meta) = sizeof(qdf_ipa_wlan_msg_t); |
| 1790 | msg = qdf_mem_malloc(QDF_IPA_MSG_META_MSG_LEN(&meta)); |
| 1791 | if (!msg) { |
| 1792 | ipa_err("msg allocation failed"); |
| 1793 | return QDF_STATUS_E_NOMEM; |
| 1794 | } |
| 1795 | |
| 1796 | QDF_IPA_SET_META_MSG_TYPE(&meta, type); |
| 1797 | strlcpy(QDF_IPA_WLAN_MSG_NAME(msg), net_dev->name, |
| 1798 | IPA_RESOURCE_NAME_MAX); |
| 1799 | qdf_mem_copy(QDF_IPA_WLAN_MSG_MAC_ADDR(msg), mac_addr, QDF_NET_ETH_LEN); |
| 1800 | |
| 1801 | ipa_debug("%s: Evt: %d", QDF_IPA_WLAN_MSG_NAME(msg), |
| 1802 | QDF_IPA_MSG_META_MSG_TYPE(&meta)); |
| 1803 | |
| 1804 | if (qdf_ipa_send_msg(&meta, msg, wlan_ipa_msg_free_fn)) { |
| 1805 | |
| 1806 | ipa_err("%s: Evt: %d fail", |
| 1807 | QDF_IPA_WLAN_MSG_NAME(msg), |
| 1808 | QDF_IPA_MSG_META_MSG_TYPE(&meta)); |
| 1809 | qdf_mem_free(msg); |
| 1810 | |
| 1811 | return QDF_STATUS_E_FAILURE; |
| 1812 | } |
| 1813 | |
| 1814 | ipa_ctx->stats.num_send_msg++; |
| 1815 | |
| 1816 | end: |
| 1817 | return QDF_STATUS_SUCCESS; |
| 1818 | } |
| 1819 | |
| 1820 | /** |
| 1821 | * wlan_host_to_ipa_wlan_event() - convert wlan_ipa_wlan_event to ipa_wlan_event |
Yun Park | 84fbb27 | 2018-04-02 15:31:01 -0700 | [diff] [blame] | 1822 | * @wlan_ipa_event_type: event to be converted to an ipa_wlan_event |
Sravan Kumar Kairam | 5214f65 | 2018-03-13 09:52:31 +0530 | [diff] [blame] | 1823 | * |
| 1824 | * Return: qdf_ipa_wlan_event representing the wlan_ipa_wlan_event |
| 1825 | */ |
| 1826 | static qdf_ipa_wlan_event |
| 1827 | wlan_host_to_ipa_wlan_event(enum wlan_ipa_wlan_event wlan_ipa_event_type) |
| 1828 | { |
Yun Park | 84fbb27 | 2018-04-02 15:31:01 -0700 | [diff] [blame] | 1829 | qdf_ipa_wlan_event ipa_event; |
Sravan Kumar Kairam | 5214f65 | 2018-03-13 09:52:31 +0530 | [diff] [blame] | 1830 | |
| 1831 | switch (wlan_ipa_event_type) { |
| 1832 | case WLAN_IPA_CLIENT_CONNECT: |
| 1833 | ipa_event = QDF_IPA_CLIENT_CONNECT; |
| 1834 | break; |
| 1835 | case WLAN_IPA_CLIENT_DISCONNECT: |
| 1836 | ipa_event = QDF_IPA_CLIENT_DISCONNECT; |
| 1837 | break; |
| 1838 | case WLAN_IPA_AP_CONNECT: |
| 1839 | ipa_event = QDF_IPA_AP_CONNECT; |
| 1840 | break; |
| 1841 | case WLAN_IPA_AP_DISCONNECT: |
| 1842 | ipa_event = QDF_IPA_AP_DISCONNECT; |
| 1843 | break; |
| 1844 | case WLAN_IPA_STA_CONNECT: |
| 1845 | ipa_event = QDF_IPA_STA_CONNECT; |
| 1846 | break; |
| 1847 | case WLAN_IPA_STA_DISCONNECT: |
| 1848 | ipa_event = QDF_IPA_STA_DISCONNECT; |
| 1849 | break; |
| 1850 | case WLAN_IPA_CLIENT_CONNECT_EX: |
| 1851 | ipa_event = QDF_IPA_CLIENT_CONNECT_EX; |
| 1852 | break; |
| 1853 | case WLAN_IPA_WLAN_EVENT_MAX: |
| 1854 | default: |
| 1855 | ipa_event = QDF_IPA_WLAN_EVENT_MAX; |
| 1856 | break; |
| 1857 | } |
| 1858 | |
| 1859 | return ipa_event; |
| 1860 | } |
| 1861 | |
| 1862 | /** |
| 1863 | * wlan_ipa_wlan_evt() - SSR wrapper for __wlan_ipa_wlan_evt |
| 1864 | * @net_dev: Interface net device |
| 1865 | * @device_mode: Net interface device mode |
| 1866 | * @sta_id: station id for the event |
| 1867 | * @session_id: session id for the event |
| 1868 | * @ipa_event_type: event enum of type wlan_ipa_wlan_event |
| 1869 | * @mac_address: MAC address associated with the event |
| 1870 | * |
| 1871 | * Return: QDF_STATUS |
| 1872 | */ |
| 1873 | QDF_STATUS wlan_ipa_wlan_evt(qdf_netdev_t net_dev, uint8_t device_mode, |
| 1874 | uint8_t sta_id, uint8_t session_id, |
| 1875 | enum wlan_ipa_wlan_event ipa_event_type, |
| 1876 | uint8_t *mac_addr) |
| 1877 | { |
| 1878 | qdf_ipa_wlan_event type = wlan_host_to_ipa_wlan_event(ipa_event_type); |
| 1879 | QDF_STATUS status = QDF_STATUS_SUCCESS; |
| 1880 | |
| 1881 | /* Data path offload only support for STA and SAP mode */ |
| 1882 | if ((device_mode == QDF_STA_MODE) || |
| 1883 | (device_mode == QDF_SAP_MODE)) |
| 1884 | status = __wlan_ipa_wlan_evt(net_dev, device_mode, sta_id, |
| 1885 | session_id, type, mac_addr); |
| 1886 | |
| 1887 | return status; |
| 1888 | } |
| 1889 | |
| 1890 | /** |
| 1891 | * wlan_ipa_uc_proc_pending_event() - Process IPA uC pending events |
| 1892 | * @ipa_ctx: Global IPA IPA context |
| 1893 | * @is_loading: Indicate if invoked during loading |
| 1894 | * |
| 1895 | * Return: None |
| 1896 | */ |
| 1897 | static void |
| 1898 | wlan_ipa_uc_proc_pending_event(struct wlan_ipa_priv *ipa_ctx, bool is_loading) |
| 1899 | { |
| 1900 | unsigned int pending_event_count; |
| 1901 | struct wlan_ipa_uc_pending_event *pending_event = NULL; |
| 1902 | |
| 1903 | pending_event_count = qdf_list_size(&ipa_ctx->pending_event); |
| 1904 | ipa_debug("Pending Event Count %d", pending_event_count); |
| 1905 | if (!pending_event_count) { |
| 1906 | ipa_debug("No Pending Event"); |
| 1907 | return; |
| 1908 | } |
| 1909 | |
| 1910 | qdf_list_remove_front(&ipa_ctx->pending_event, |
| 1911 | (qdf_list_node_t **)&pending_event); |
| 1912 | while (pending_event != NULL) { |
| 1913 | if (pending_event->is_loading == is_loading) { |
| 1914 | __wlan_ipa_wlan_evt(pending_event->net_dev, |
| 1915 | pending_event->device_mode, |
| 1916 | pending_event->sta_id, |
| 1917 | pending_event->session_id, |
| 1918 | pending_event->type, |
| 1919 | pending_event->mac_addr); |
| 1920 | } |
| 1921 | qdf_mem_free(pending_event); |
| 1922 | pending_event = NULL; |
| 1923 | qdf_list_remove_front(&ipa_ctx->pending_event, |
| 1924 | (qdf_list_node_t **)&pending_event); |
| 1925 | } |
| 1926 | } |
| 1927 | |
| 1928 | /** |
Sravan Kumar Kairam | d01b445 | 2018-03-07 17:37:09 +0530 | [diff] [blame] | 1929 | * wlan_ipa_alloc_tx_desc_list() - Allocate IPA Tx desc list |
| 1930 | * @ipa_ctx: IPA context |
| 1931 | * |
| 1932 | * Return: QDF_STATUS |
| 1933 | */ |
| 1934 | static int wlan_ipa_alloc_tx_desc_list(struct wlan_ipa_priv *ipa_ctx) |
| 1935 | { |
| 1936 | int i; |
| 1937 | uint32_t max_desc_cnt; |
| 1938 | struct wlan_ipa_tx_desc *tmp_desc; |
| 1939 | |
| 1940 | max_desc_cnt = ipa_ctx->config->txbuf_count; |
| 1941 | |
| 1942 | qdf_list_create(&ipa_ctx->tx_desc_list, max_desc_cnt); |
| 1943 | |
| 1944 | qdf_spin_lock_bh(&ipa_ctx->q_lock); |
| 1945 | for (i = 0; i < max_desc_cnt; i++) { |
| 1946 | tmp_desc = qdf_mem_malloc(sizeof(*tmp_desc)); |
| 1947 | tmp_desc->id = i; |
| 1948 | tmp_desc->ipa_tx_desc_ptr = NULL; |
| 1949 | qdf_list_insert_back(&ipa_ctx->tx_desc_list, |
| 1950 | &tmp_desc->node); |
| 1951 | tmp_desc++; |
| 1952 | } |
| 1953 | |
| 1954 | ipa_ctx->stats.num_tx_desc_q_cnt = 0; |
| 1955 | ipa_ctx->stats.num_tx_desc_error = 0; |
| 1956 | |
| 1957 | qdf_spin_unlock_bh(&ipa_ctx->q_lock); |
| 1958 | |
| 1959 | return QDF_STATUS_SUCCESS; |
| 1960 | } |
| 1961 | |
| 1962 | #ifndef QCA_LL_TX_FLOW_CONTROL_V2 |
| 1963 | /** |
| 1964 | * wlan_ipa_setup_tx_sys_pipe() - Setup IPA Tx system pipes |
| 1965 | * @ipa_ctx: Global IPA IPA context |
| 1966 | * @desc_fifo_sz: Number of descriptors |
| 1967 | * |
| 1968 | * Return: 0 on success, negative errno on error |
| 1969 | */ |
| 1970 | static int wlan_ipa_setup_tx_sys_pipe(struct wlan_ipa_priv *ipa_ctx, |
| 1971 | int32_t desc_fifo_sz) |
| 1972 | { |
| 1973 | int i, ret = 0; |
| 1974 | qdf_ipa_sys_connect_params_t *ipa; |
| 1975 | |
| 1976 | /*setup TX pipes */ |
| 1977 | for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) { |
| 1978 | ipa = &ipa_ctx->sys_pipe[i].ipa_sys_params; |
| 1979 | |
| 1980 | ipa->client = wlan_ipa_iface_2_client[i].cons_client; |
| 1981 | ipa->desc_fifo_sz = desc_fifo_sz; |
| 1982 | ipa->priv = &ipa_ctx->iface_context[i]; |
Sravan Kumar Kairam | 1309e7e | 2018-03-13 09:29:52 +0530 | [diff] [blame] | 1983 | ipa->notify = wlan_ipa_i2w_cb; |
Sravan Kumar Kairam | d01b445 | 2018-03-07 17:37:09 +0530 | [diff] [blame] | 1984 | |
| 1985 | if (wlan_ipa_uc_sta_is_enabled(ipa_ctx->config)) { |
| 1986 | ipa->ipa_ep_cfg.hdr.hdr_len = |
| 1987 | WLAN_IPA_UC_WLAN_TX_HDR_LEN; |
| 1988 | ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT; |
| 1989 | ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1; |
| 1990 | ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0; |
| 1991 | ipa->ipa_ep_cfg.hdr.hdr_additional_const_len = |
| 1992 | WLAN_IPA_UC_WLAN_8023_HDR_SIZE; |
| 1993 | ipa->ipa_ep_cfg.hdr_ext.hdr_little_endian = true; |
| 1994 | } else { |
| 1995 | ipa->ipa_ep_cfg.hdr.hdr_len = WLAN_IPA_WLAN_TX_HDR_LEN; |
| 1996 | } |
| 1997 | ipa->ipa_ep_cfg.mode.mode = IPA_BASIC; |
| 1998 | |
| 1999 | ret = wlan_ipa_wdi_setup_sys_pipe(ipa_ctx, ipa, |
| 2000 | &ipa_ctx->sys_pipe[i].conn_hdl); |
| 2001 | if (ret) { |
| 2002 | ipa_err("Failed for pipe %d ret: %d", i, ret); |
| 2003 | return ret; |
| 2004 | } |
| 2005 | ipa_ctx->sys_pipe[i].conn_hdl_valid = 1; |
| 2006 | } |
| 2007 | |
| 2008 | return ret; |
| 2009 | } |
| 2010 | #else |
| 2011 | /** |
| 2012 | * wlan_ipa_setup_tx_sys_pipe() - Setup IPA Tx system pipes |
| 2013 | * @ipa_ctx: Global IPA IPA context |
| 2014 | * @desc_fifo_sz: Number of descriptors |
| 2015 | * |
| 2016 | * Return: 0 on success, negative errno on error |
| 2017 | */ |
| 2018 | static int wlan_ipa_setup_tx_sys_pipe(struct wlan_ipa_priv *ipa_ctx, |
| 2019 | int32_t desc_fifo_sz) |
| 2020 | { |
| 2021 | /* |
| 2022 | * The Tx system pipes are not needed for MCC when TX_FLOW_CONTROL_V2 |
| 2023 | * is enabled, where per vdev descriptors are supported in firmware. |
| 2024 | */ |
| 2025 | return 0; |
| 2026 | } |
| 2027 | #endif |
| 2028 | |
| 2029 | /** |
| 2030 | * wlan_ipa_setup_rx_sys_pipe() - Setup IPA Rx system pipes |
| 2031 | * @ipa_ctx: Global IPA IPA context |
| 2032 | * @desc_fifo_sz: Number of descriptors |
| 2033 | * |
| 2034 | * Return: 0 on success, negative errno on error |
| 2035 | */ |
| 2036 | static int wlan_ipa_setup_rx_sys_pipe(struct wlan_ipa_priv *ipa_ctx, |
| 2037 | int32_t desc_fifo_sz) |
| 2038 | { |
| 2039 | int ret = 0; |
| 2040 | qdf_ipa_sys_connect_params_t *ipa; |
| 2041 | |
| 2042 | /* |
| 2043 | * Hard code it here, this can be extended if in case |
| 2044 | * PROD pipe is also per interface. |
| 2045 | * Right now there is no advantage of doing this. |
| 2046 | */ |
| 2047 | ipa = &ipa_ctx->sys_pipe[WLAN_IPA_RX_PIPE].ipa_sys_params; |
| 2048 | |
| 2049 | ipa->client = IPA_CLIENT_WLAN1_PROD; |
| 2050 | |
| 2051 | ipa->desc_fifo_sz = desc_fifo_sz; |
| 2052 | ipa->priv = ipa_ctx; |
Sravan Kumar Kairam | 1309e7e | 2018-03-13 09:29:52 +0530 | [diff] [blame] | 2053 | ipa->notify = wlan_ipa_w2i_cb; |
Sravan Kumar Kairam | d01b445 | 2018-03-07 17:37:09 +0530 | [diff] [blame] | 2054 | |
| 2055 | ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT; |
| 2056 | ipa->ipa_ep_cfg.hdr.hdr_len = WLAN_IPA_WLAN_RX_HDR_LEN; |
| 2057 | ipa->ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 1; |
| 2058 | ipa->ipa_ep_cfg.mode.mode = IPA_BASIC; |
| 2059 | |
| 2060 | ret = qdf_ipa_setup_sys_pipe(ipa, |
| 2061 | &ipa_ctx->sys_pipe[WLAN_IPA_RX_PIPE].conn_hdl); |
| 2062 | if (ret) { |
| 2063 | ipa_err("Failed for RX pipe: %d", ret); |
| 2064 | return ret; |
| 2065 | } |
| 2066 | ipa_ctx->sys_pipe[WLAN_IPA_RX_PIPE].conn_hdl_valid = 1; |
| 2067 | |
| 2068 | return ret; |
| 2069 | } |
| 2070 | |
| 2071 | /** |
| 2072 | * wlan_ipa_setup_sys_pipe() - Setup all IPA system pipes |
| 2073 | * @ipa_ctx: Global IPA IPA context |
| 2074 | * |
| 2075 | * Return: 0 on success, negative errno on error |
| 2076 | */ |
| 2077 | static int wlan_ipa_setup_sys_pipe(struct wlan_ipa_priv *ipa_ctx) |
| 2078 | { |
| 2079 | int i = WLAN_IPA_MAX_IFACE, ret = 0; |
| 2080 | uint32_t desc_fifo_sz; |
| 2081 | |
| 2082 | /* The maximum number of descriptors that can be provided to a BAM at |
| 2083 | * once is one less than the total number of descriptors that the buffer |
| 2084 | * can contain. |
| 2085 | * If max_num_of_descriptors = (BAM_PIPE_DESCRIPTOR_FIFO_SIZE / sizeof |
| 2086 | * (SPS_DESCRIPTOR)), then (max_num_of_descriptors - 1) descriptors can |
| 2087 | * be provided at once. |
| 2088 | * Because of above requirement, one extra descriptor will be added to |
| 2089 | * make sure hardware always has one descriptor. |
| 2090 | */ |
| 2091 | desc_fifo_sz = ipa_ctx->config->desc_size |
| 2092 | + SPS_DESC_SIZE; |
| 2093 | |
| 2094 | ret = wlan_ipa_setup_tx_sys_pipe(ipa_ctx, desc_fifo_sz); |
| 2095 | if (ret) { |
| 2096 | ipa_err("Failed for TX pipe: %d", ret); |
| 2097 | goto setup_sys_pipe_fail; |
| 2098 | } |
| 2099 | |
| 2100 | if (!wlan_ipa_uc_sta_is_enabled(ipa_ctx->config)) { |
| 2101 | ret = wlan_ipa_setup_rx_sys_pipe(ipa_ctx, desc_fifo_sz); |
| 2102 | if (ret) { |
| 2103 | ipa_err("Failed for RX pipe: %d", ret); |
| 2104 | goto setup_sys_pipe_fail; |
| 2105 | } |
| 2106 | } |
| 2107 | |
| 2108 | /* Allocate free Tx desc list */ |
| 2109 | ret = wlan_ipa_alloc_tx_desc_list(ipa_ctx); |
| 2110 | if (ret) |
| 2111 | goto setup_sys_pipe_fail; |
| 2112 | |
| 2113 | return ret; |
| 2114 | |
| 2115 | setup_sys_pipe_fail: |
| 2116 | |
| 2117 | for (i = 0; i < WLAN_IPA_MAX_SYSBAM_PIPE; i++) { |
| 2118 | if (ipa_ctx->sys_pipe[i].conn_hdl_valid) |
| 2119 | qdf_ipa_teardown_sys_pipe( |
| 2120 | ipa_ctx->sys_pipe[i].conn_hdl); |
| 2121 | qdf_mem_zero(&ipa_ctx->sys_pipe[i], |
| 2122 | sizeof(struct wlan_ipa_sys_pipe)); |
| 2123 | } |
| 2124 | |
| 2125 | return ret; |
| 2126 | } |
| 2127 | |
| 2128 | /** |
| 2129 | * wlan_ipa_teardown_sys_pipe() - Tear down all IPA Sys pipes |
| 2130 | * @ipa_ctx: Global IPA IPA context |
| 2131 | * |
| 2132 | * Return: None |
| 2133 | */ |
| 2134 | static void wlan_ipa_teardown_sys_pipe(struct wlan_ipa_priv *ipa_ctx) |
| 2135 | { |
| 2136 | int ret = 0, i; |
| 2137 | struct wlan_ipa_tx_desc *tmp_desc; |
| 2138 | qdf_ipa_rx_data_t *ipa_tx_desc; |
| 2139 | qdf_list_node_t *node; |
| 2140 | |
| 2141 | for (i = 0; i < WLAN_IPA_MAX_SYSBAM_PIPE; i++) { |
| 2142 | if (ipa_ctx->sys_pipe[i].conn_hdl_valid) { |
| 2143 | ret = wlan_ipa_wdi_teardown_sys_pipe(ipa_ctx, |
| 2144 | ipa_ctx->sys_pipe[i].conn_hdl); |
| 2145 | if (ret) |
| 2146 | ipa_err("Failed:%d", ret); |
| 2147 | |
| 2148 | ipa_ctx->sys_pipe[i].conn_hdl_valid = 0; |
| 2149 | } |
| 2150 | } |
| 2151 | |
| 2152 | while (qdf_list_remove_front(&ipa_ctx->tx_desc_list, &node) == |
| 2153 | QDF_STATUS_SUCCESS) { |
| 2154 | tmp_desc = qdf_container_of(node, struct wlan_ipa_tx_desc, |
| 2155 | node); |
| 2156 | ipa_tx_desc = tmp_desc->ipa_tx_desc_ptr; |
| 2157 | if (ipa_tx_desc) |
| 2158 | qdf_ipa_free_skb(ipa_tx_desc); |
| 2159 | |
| 2160 | qdf_mem_free(tmp_desc); |
| 2161 | } |
| 2162 | } |
| 2163 | |
jiad | bb47e13 | 2018-03-30 16:28:30 +0800 | [diff] [blame] | 2164 | #ifndef QCA_LL_TX_FLOW_CONTROL_V2 |
| 2165 | QDF_STATUS wlan_ipa_send_mcc_scc_msg(struct wlan_ipa_priv *ipa_ctx, |
| 2166 | bool mcc_mode) |
| 2167 | { |
| 2168 | qdf_ipa_msg_meta_t meta; |
| 2169 | qdf_ipa_wlan_msg_t *msg; |
| 2170 | int ret; |
| 2171 | |
| 2172 | if (!wlan_ipa_uc_sta_is_enabled(ipa_ctx->config)) |
| 2173 | return QDF_STATUS_SUCCESS; |
| 2174 | |
| 2175 | /* Send SCC/MCC Switching event to IPA */ |
| 2176 | QDF_IPA_MSG_META_MSG_LEN(&meta) = sizeof(*msg); |
| 2177 | msg = qdf_mem_malloc(QDF_IPA_MSG_META_MSG_LEN(&meta)); |
| 2178 | if (msg == NULL) { |
| 2179 | ipa_err("msg allocation failed"); |
| 2180 | return QDF_STATUS_E_NOMEM; |
| 2181 | } |
| 2182 | |
jiad | 629b217 | 2018-05-11 15:34:22 +0800 | [diff] [blame] | 2183 | if (mcc_mode) { |
jiad | bb47e13 | 2018-03-30 16:28:30 +0800 | [diff] [blame] | 2184 | QDF_IPA_SET_META_MSG_TYPE(&meta, QDF_SWITCH_TO_MCC); |
jiad | 629b217 | 2018-05-11 15:34:22 +0800 | [diff] [blame] | 2185 | ipa_ctx->stats.event[QDF_SWITCH_TO_MCC]++; |
| 2186 | } else { |
jiad | bb47e13 | 2018-03-30 16:28:30 +0800 | [diff] [blame] | 2187 | QDF_IPA_SET_META_MSG_TYPE(&meta, QDF_SWITCH_TO_SCC); |
jiad | 629b217 | 2018-05-11 15:34:22 +0800 | [diff] [blame] | 2188 | ipa_ctx->stats.event[QDF_SWITCH_TO_SCC]++; |
| 2189 | } |
| 2190 | |
jiad | bb47e13 | 2018-03-30 16:28:30 +0800 | [diff] [blame] | 2191 | WLAN_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, |
| 2192 | "ipa_send_msg(Evt:%d)", |
| 2193 | QDF_IPA_MSG_META_MSG_TYPE(&meta)); |
| 2194 | |
| 2195 | ret = qdf_ipa_send_msg(&meta, msg, wlan_ipa_msg_free_fn); |
| 2196 | |
| 2197 | if (ret) { |
| 2198 | ipa_err("ipa_send_msg(Evt:%d) - fail=%d", |
| 2199 | QDF_IPA_MSG_META_MSG_TYPE(&meta), ret); |
| 2200 | qdf_mem_free(msg); |
| 2201 | return QDF_STATUS_E_FAILURE; |
| 2202 | } |
| 2203 | |
| 2204 | return QDF_STATUS_SUCCESS; |
| 2205 | } |
| 2206 | |
| 2207 | static void wlan_ipa_mcc_work_handler(void *data) |
| 2208 | { |
| 2209 | struct wlan_ipa_priv *ipa_ctx = (struct wlan_ipa_priv *)data; |
| 2210 | |
| 2211 | wlan_ipa_send_mcc_scc_msg(ipa_ctx, ipa_ctx->mcc_mode); |
| 2212 | } |
| 2213 | #endif |
| 2214 | |
Sravan Kumar Kairam | d01b445 | 2018-03-07 17:37:09 +0530 | [diff] [blame] | 2215 | /** |
| 2216 | * wlan_ipa_setup() - IPA initialization function |
| 2217 | * @ipa_ctx: IPA context |
| 2218 | * @ipa_cfg: IPA config |
| 2219 | * |
| 2220 | * Allocate ipa_ctx resources, ipa pipe resource and register |
| 2221 | * wlan interface with IPA module. |
| 2222 | * |
| 2223 | * Return: QDF_STATUS enumeration |
| 2224 | */ |
| 2225 | QDF_STATUS wlan_ipa_setup(struct wlan_ipa_priv *ipa_ctx, |
| 2226 | struct wlan_ipa_config *ipa_cfg) |
| 2227 | { |
| 2228 | int ret, i; |
| 2229 | struct wlan_ipa_iface_context *iface_context = NULL; |
| 2230 | QDF_STATUS status; |
| 2231 | |
| 2232 | ipa_debug("enter"); |
| 2233 | |
| 2234 | gp_ipa = ipa_ctx; |
| 2235 | ipa_ctx->num_iface = 0; |
| 2236 | ipa_ctx->config = ipa_cfg; |
| 2237 | |
| 2238 | wlan_ipa_wdi_get_wdi_version(ipa_ctx); |
| 2239 | |
| 2240 | /* Create the interface context */ |
| 2241 | for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) { |
| 2242 | iface_context = &ipa_ctx->iface_context[i]; |
| 2243 | iface_context->ipa_ctx = ipa_ctx; |
| 2244 | iface_context->cons_client = |
| 2245 | wlan_ipa_iface_2_client[i].cons_client; |
| 2246 | iface_context->prod_client = |
| 2247 | wlan_ipa_iface_2_client[i].prod_client; |
| 2248 | iface_context->iface_id = i; |
| 2249 | iface_context->dev = NULL; |
| 2250 | iface_context->device_mode = QDF_MAX_NO_OF_MODE; |
| 2251 | iface_context->tl_context = NULL; |
| 2252 | qdf_spinlock_create(&iface_context->interface_lock); |
| 2253 | } |
| 2254 | |
Sravan Kumar Kairam | 1309e7e | 2018-03-13 09:29:52 +0530 | [diff] [blame] | 2255 | qdf_create_work(0, &ipa_ctx->pm_work, wlan_ipa_pm_flush, ipa_ctx); |
Sravan Kumar Kairam | d01b445 | 2018-03-07 17:37:09 +0530 | [diff] [blame] | 2256 | qdf_spinlock_create(&ipa_ctx->pm_lock); |
| 2257 | qdf_spinlock_create(&ipa_ctx->q_lock); |
| 2258 | qdf_nbuf_queue_init(&ipa_ctx->pm_queue_head); |
| 2259 | qdf_list_create(&ipa_ctx->pending_event, 1000); |
| 2260 | qdf_mutex_create(&ipa_ctx->event_lock); |
| 2261 | qdf_mutex_create(&ipa_ctx->ipa_lock); |
| 2262 | |
Sravan Kumar Kairam | 2e7aae9 | 2018-03-06 19:32:49 +0530 | [diff] [blame] | 2263 | status = wlan_ipa_wdi_setup_rm(ipa_ctx); |
| 2264 | if (status != QDF_STATUS_SUCCESS) |
| 2265 | goto fail_setup_rm; |
| 2266 | |
Sravan Kumar Kairam | d01b445 | 2018-03-07 17:37:09 +0530 | [diff] [blame] | 2267 | for (i = 0; i < WLAN_IPA_MAX_SYSBAM_PIPE; i++) |
| 2268 | qdf_mem_zero(&ipa_ctx->sys_pipe[i], |
| 2269 | sizeof(struct wlan_ipa_sys_pipe)); |
| 2270 | |
| 2271 | if (wlan_ipa_uc_is_enabled(ipa_ctx->config)) { |
| 2272 | qdf_mem_zero(&ipa_ctx->stats, sizeof(ipa_ctx->stats)); |
| 2273 | ipa_ctx->sap_num_connected_sta = 0; |
| 2274 | ipa_ctx->ipa_tx_packets_diff = 0; |
| 2275 | ipa_ctx->ipa_rx_packets_diff = 0; |
| 2276 | ipa_ctx->ipa_p_tx_packets = 0; |
| 2277 | ipa_ctx->ipa_p_rx_packets = 0; |
| 2278 | ipa_ctx->resource_loading = false; |
| 2279 | ipa_ctx->resource_unloading = false; |
| 2280 | ipa_ctx->sta_connected = 0; |
| 2281 | ipa_ctx->ipa_pipes_down = true; |
| 2282 | ipa_ctx->wdi_enabled = false; |
| 2283 | /* Setup IPA system pipes */ |
| 2284 | if (wlan_ipa_uc_sta_is_enabled(ipa_ctx->config)) { |
| 2285 | ret = wlan_ipa_setup_sys_pipe(ipa_ctx); |
| 2286 | if (ret) |
| 2287 | goto fail_create_sys_pipe; |
jiad | bb47e13 | 2018-03-30 16:28:30 +0800 | [diff] [blame] | 2288 | |
| 2289 | qdf_create_work(0, &ipa_ctx->mcc_work, |
| 2290 | wlan_ipa_mcc_work_handler, ipa_ctx); |
Sravan Kumar Kairam | d01b445 | 2018-03-07 17:37:09 +0530 | [diff] [blame] | 2291 | } |
| 2292 | |
| 2293 | status = wlan_ipa_wdi_init(ipa_ctx); |
| 2294 | if (status == QDF_STATUS_E_BUSY) |
| 2295 | status = wlan_ipa_uc_send_wdi_control_msg(false); |
| 2296 | if (status != QDF_STATUS_SUCCESS) { |
| 2297 | ipa_err("IPA WDI init failed: ret=%d", ret); |
| 2298 | goto fail_create_sys_pipe; |
| 2299 | } |
| 2300 | } else { |
| 2301 | ret = wlan_ipa_setup_sys_pipe(ipa_ctx); |
| 2302 | if (ret) |
| 2303 | goto fail_create_sys_pipe; |
| 2304 | } |
| 2305 | |
| 2306 | qdf_event_create(&ipa_ctx->ipa_resource_comp); |
| 2307 | |
| 2308 | ipa_debug("exit: success"); |
| 2309 | |
| 2310 | return QDF_STATUS_SUCCESS; |
| 2311 | |
| 2312 | fail_create_sys_pipe: |
Sravan Kumar Kairam | 2e7aae9 | 2018-03-06 19:32:49 +0530 | [diff] [blame] | 2313 | wlan_ipa_wdi_destroy_rm(ipa_ctx); |
| 2314 | |
| 2315 | fail_setup_rm: |
Sravan Kumar Kairam | d01b445 | 2018-03-07 17:37:09 +0530 | [diff] [blame] | 2316 | qdf_spinlock_destroy(&ipa_ctx->pm_lock); |
Sravan Kumar Kairam | 2e7aae9 | 2018-03-06 19:32:49 +0530 | [diff] [blame] | 2317 | qdf_spinlock_destroy(&ipa_ctx->q_lock); |
| 2318 | for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) { |
| 2319 | iface_context = &ipa_ctx->iface_context[i]; |
| 2320 | qdf_spinlock_destroy(&iface_context->interface_lock); |
| 2321 | } |
| 2322 | qdf_mutex_destroy(&ipa_ctx->event_lock); |
| 2323 | qdf_mutex_destroy(&ipa_ctx->ipa_lock); |
| 2324 | qdf_list_destroy(&ipa_ctx->pending_event); |
Sravan Kumar Kairam | d01b445 | 2018-03-07 17:37:09 +0530 | [diff] [blame] | 2325 | gp_ipa = NULL; |
| 2326 | ipa_debug("exit: fail"); |
| 2327 | |
| 2328 | return QDF_STATUS_E_FAILURE; |
| 2329 | } |
| 2330 | |
Sravan Kumar Kairam | 1309e7e | 2018-03-13 09:29:52 +0530 | [diff] [blame] | 2331 | void wlan_ipa_flush(struct wlan_ipa_priv *ipa_ctx) |
| 2332 | { |
| 2333 | qdf_nbuf_t skb; |
| 2334 | struct wlan_ipa_pm_tx_cb *pm_tx_cb; |
| 2335 | |
| 2336 | if (!wlan_ipa_is_enabled(ipa_ctx->config)) |
| 2337 | return; |
| 2338 | |
| 2339 | qdf_cancel_work(&ipa_ctx->pm_work); |
| 2340 | |
| 2341 | qdf_spin_lock_bh(&ipa_ctx->pm_lock); |
| 2342 | |
| 2343 | while (((skb = qdf_nbuf_queue_remove(&ipa_ctx->pm_queue_head)) |
| 2344 | != NULL)) { |
| 2345 | qdf_spin_unlock_bh(&ipa_ctx->pm_lock); |
| 2346 | |
| 2347 | pm_tx_cb = (struct wlan_ipa_pm_tx_cb *)skb->cb; |
jiad | ab8cea0 | 2018-05-24 09:16:14 +0800 | [diff] [blame^] | 2348 | |
| 2349 | if (pm_tx_cb->exception) { |
| 2350 | dev_kfree_skb_any(skb); |
| 2351 | } else { |
| 2352 | if (pm_tx_cb->ipa_tx_desc) |
| 2353 | ipa_free_skb(pm_tx_cb->ipa_tx_desc); |
| 2354 | } |
Sravan Kumar Kairam | 1309e7e | 2018-03-13 09:29:52 +0530 | [diff] [blame] | 2355 | |
| 2356 | qdf_spin_lock_bh(&ipa_ctx->pm_lock); |
| 2357 | } |
| 2358 | qdf_spin_unlock_bh(&ipa_ctx->pm_lock); |
| 2359 | } |
| 2360 | |
Sravan Kumar Kairam | d01b445 | 2018-03-07 17:37:09 +0530 | [diff] [blame] | 2361 | QDF_STATUS wlan_ipa_cleanup(struct wlan_ipa_priv *ipa_ctx) |
| 2362 | { |
Sravan Kumar Kairam | 1309e7e | 2018-03-13 09:29:52 +0530 | [diff] [blame] | 2363 | struct wlan_ipa_iface_context *iface_context; |
Sravan Kumar Kairam | d01b445 | 2018-03-07 17:37:09 +0530 | [diff] [blame] | 2364 | int i; |
| 2365 | |
| 2366 | if (!wlan_ipa_uc_is_enabled(ipa_ctx->config)) |
| 2367 | wlan_ipa_teardown_sys_pipe(ipa_ctx); |
| 2368 | |
| 2369 | /* Teardown IPA sys_pipe for MCC */ |
jiad | bb47e13 | 2018-03-30 16:28:30 +0800 | [diff] [blame] | 2370 | if (wlan_ipa_uc_sta_is_enabled(ipa_ctx->config)) { |
Sravan Kumar Kairam | d01b445 | 2018-03-07 17:37:09 +0530 | [diff] [blame] | 2371 | wlan_ipa_teardown_sys_pipe(ipa_ctx); |
jiad | bb47e13 | 2018-03-30 16:28:30 +0800 | [diff] [blame] | 2372 | qdf_cancel_work(&ipa_ctx->mcc_work); |
| 2373 | } |
Sravan Kumar Kairam | d01b445 | 2018-03-07 17:37:09 +0530 | [diff] [blame] | 2374 | |
Sravan Kumar Kairam | 2e7aae9 | 2018-03-06 19:32:49 +0530 | [diff] [blame] | 2375 | wlan_ipa_wdi_destroy_rm(ipa_ctx); |
| 2376 | |
Sravan Kumar Kairam | 1309e7e | 2018-03-13 09:29:52 +0530 | [diff] [blame] | 2377 | wlan_ipa_flush(ipa_ctx); |
| 2378 | |
Sravan Kumar Kairam | d01b445 | 2018-03-07 17:37:09 +0530 | [diff] [blame] | 2379 | qdf_spinlock_destroy(&ipa_ctx->pm_lock); |
| 2380 | qdf_spinlock_destroy(&ipa_ctx->q_lock); |
| 2381 | |
| 2382 | /* destroy the interface lock */ |
| 2383 | for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) { |
| 2384 | iface_context = &ipa_ctx->iface_context[i]; |
| 2385 | qdf_spinlock_destroy(&iface_context->interface_lock); |
| 2386 | } |
| 2387 | |
| 2388 | if (wlan_ipa_uc_is_enabled(ipa_ctx->config)) { |
| 2389 | wlan_ipa_wdi_cleanup(); |
| 2390 | qdf_mutex_destroy(&ipa_ctx->event_lock); |
| 2391 | qdf_mutex_destroy(&ipa_ctx->ipa_lock); |
| 2392 | qdf_list_destroy(&ipa_ctx->pending_event); |
| 2393 | |
| 2394 | } |
| 2395 | |
| 2396 | gp_ipa = NULL; |
| 2397 | |
| 2398 | return QDF_STATUS_SUCCESS; |
| 2399 | } |
Sravan Kumar Kairam | 271fab2 | 2018-03-07 18:57:41 +0530 | [diff] [blame] | 2400 | |
| 2401 | struct wlan_ipa_iface_context |
| 2402 | *wlan_ipa_get_iface(struct wlan_ipa_priv *ipa_ctx, uint8_t mode) |
| 2403 | { |
| 2404 | struct wlan_ipa_iface_context *iface_ctx = NULL; |
| 2405 | int i; |
| 2406 | |
| 2407 | for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) { |
| 2408 | iface_ctx = &ipa_ctx->iface_context[i]; |
| 2409 | |
| 2410 | if (iface_ctx->device_mode == mode) |
| 2411 | return iface_ctx; |
| 2412 | } |
| 2413 | |
| 2414 | return NULL; |
| 2415 | } |
Sravan Kumar Kairam | 1309e7e | 2018-03-13 09:29:52 +0530 | [diff] [blame] | 2416 | |
jiad | bb47e13 | 2018-03-30 16:28:30 +0800 | [diff] [blame] | 2417 | void wlan_ipa_set_mcc_mode(struct wlan_ipa_priv *ipa_ctx, bool mcc_mode) |
Sravan Kumar Kairam | 7d931ff | 2018-03-13 09:42:02 +0530 | [diff] [blame] | 2418 | { |
Sravan Kumar Kairam | 7d931ff | 2018-03-13 09:42:02 +0530 | [diff] [blame] | 2419 | if (!wlan_ipa_uc_sta_is_enabled(ipa_ctx->config)) |
jiad | bb47e13 | 2018-03-30 16:28:30 +0800 | [diff] [blame] | 2420 | return; |
Sravan Kumar Kairam | 7d931ff | 2018-03-13 09:42:02 +0530 | [diff] [blame] | 2421 | |
jiad | bb47e13 | 2018-03-30 16:28:30 +0800 | [diff] [blame] | 2422 | if (ipa_ctx->mcc_mode == mcc_mode) |
| 2423 | return; |
Sravan Kumar Kairam | 7d931ff | 2018-03-13 09:42:02 +0530 | [diff] [blame] | 2424 | |
jiad | bb47e13 | 2018-03-30 16:28:30 +0800 | [diff] [blame] | 2425 | ipa_ctx->mcc_mode = mcc_mode; |
| 2426 | qdf_sched_work(0, &ipa_ctx->mcc_work); |
Sravan Kumar Kairam | 7d931ff | 2018-03-13 09:42:02 +0530 | [diff] [blame] | 2427 | } |
Sravan Kumar Kairam | 7d931ff | 2018-03-13 09:42:02 +0530 | [diff] [blame] | 2428 | |
| 2429 | /** |
| 2430 | * wlan_ipa_uc_loaded_handler() - Process IPA uC loaded indication |
| 2431 | * @ipa_ctx: ipa ipa local context |
| 2432 | * |
| 2433 | * Will handle IPA UC image loaded indication comes from IPA kernel |
| 2434 | * |
| 2435 | * Return: None |
| 2436 | */ |
| 2437 | static void wlan_ipa_uc_loaded_handler(struct wlan_ipa_priv *ipa_ctx) |
| 2438 | { |
| 2439 | struct wlan_objmgr_pdev *pdev = ipa_ctx->pdev; |
| 2440 | struct wlan_objmgr_psoc *psoc = wlan_pdev_get_psoc(pdev); |
| 2441 | qdf_device_t qdf_dev = wlan_psoc_get_qdf_dev(psoc); |
| 2442 | QDF_STATUS status; |
| 2443 | |
| 2444 | ipa_info("UC READY"); |
| 2445 | if (true == ipa_ctx->uc_loaded) { |
| 2446 | ipa_info("UC already loaded"); |
| 2447 | return; |
| 2448 | } |
| 2449 | |
Sravan Kumar Kairam | 7d931ff | 2018-03-13 09:42:02 +0530 | [diff] [blame] | 2450 | /* Connect pipe */ |
| 2451 | status = wlan_ipa_wdi_setup(ipa_ctx, qdf_dev); |
| 2452 | if (status) { |
| 2453 | ipa_err("Failure to setup IPA pipes (status=%d)", |
| 2454 | status); |
| 2455 | return; |
| 2456 | } |
| 2457 | |
| 2458 | cdp_ipa_set_doorbell_paddr(ipa_ctx->dp_soc, ipa_ctx->dp_pdev); |
Sravan Kumar Kairam | 5214f65 | 2018-03-13 09:52:31 +0530 | [diff] [blame] | 2459 | |
| 2460 | /* If already any STA connected, enable IPA/FW PIPEs */ |
| 2461 | if (ipa_ctx->sap_num_connected_sta) { |
| 2462 | ipa_debug("Client already connected, enable IPA/FW PIPEs"); |
| 2463 | wlan_ipa_uc_handle_first_con(ipa_ctx); |
| 2464 | } |
Sravan Kumar Kairam | 7d931ff | 2018-03-13 09:42:02 +0530 | [diff] [blame] | 2465 | } |
| 2466 | |
| 2467 | /** |
| 2468 | * wlan_ipa_uc_op_cb() - IPA uC operation callback |
| 2469 | * @op_msg: operation message received from firmware |
| 2470 | * @usr_ctxt: user context registered with TL (we register the IPA Global |
| 2471 | * context) |
| 2472 | * |
| 2473 | * Return: None |
| 2474 | */ |
| 2475 | static void wlan_ipa_uc_op_cb(struct op_msg_type *op_msg, |
| 2476 | struct wlan_ipa_priv *ipa_ctx) |
| 2477 | { |
| 2478 | struct op_msg_type *msg = op_msg; |
| 2479 | struct ipa_uc_fw_stats *uc_fw_stat; |
| 2480 | |
| 2481 | if (!op_msg) { |
| 2482 | ipa_err("INVALID ARG"); |
| 2483 | return; |
| 2484 | } |
| 2485 | |
| 2486 | if (msg->op_code >= WLAN_IPA_UC_OPCODE_MAX) { |
| 2487 | ipa_err("INVALID OPCODE %d", msg->op_code); |
| 2488 | qdf_mem_free(op_msg); |
| 2489 | return; |
| 2490 | } |
| 2491 | |
| 2492 | ipa_debug("OPCODE=%d", msg->op_code); |
| 2493 | |
| 2494 | if ((msg->op_code == WLAN_IPA_UC_OPCODE_TX_RESUME) || |
| 2495 | (msg->op_code == WLAN_IPA_UC_OPCODE_RX_RESUME)) { |
| 2496 | qdf_mutex_acquire(&ipa_ctx->ipa_lock); |
| 2497 | ipa_ctx->activated_fw_pipe++; |
Yun Park | a29974a | 2018-04-09 12:05:49 -0700 | [diff] [blame] | 2498 | if (wlan_ipa_is_fw_wdi_activated(ipa_ctx)) { |
Sravan Kumar Kairam | 7d931ff | 2018-03-13 09:42:02 +0530 | [diff] [blame] | 2499 | ipa_ctx->resource_loading = false; |
| 2500 | qdf_event_set(&ipa_ctx->ipa_resource_comp); |
| 2501 | if (ipa_ctx->wdi_enabled == false) { |
| 2502 | ipa_ctx->wdi_enabled = true; |
| 2503 | if (wlan_ipa_uc_send_wdi_control_msg(true) == 0) |
| 2504 | wlan_ipa_send_mcc_scc_msg(ipa_ctx, |
| 2505 | ipa_ctx->mcc_mode); |
| 2506 | } |
Sravan Kumar Kairam | 5214f65 | 2018-03-13 09:52:31 +0530 | [diff] [blame] | 2507 | wlan_ipa_uc_proc_pending_event(ipa_ctx, true); |
Sravan Kumar Kairam | 7d931ff | 2018-03-13 09:42:02 +0530 | [diff] [blame] | 2508 | if (ipa_ctx->pending_cons_req) |
Yun Park | e114fbf | 2018-04-05 20:02:12 -0700 | [diff] [blame] | 2509 | wlan_ipa_wdi_rm_notify_completion( |
Sravan Kumar Kairam | 7d931ff | 2018-03-13 09:42:02 +0530 | [diff] [blame] | 2510 | QDF_IPA_RM_RESOURCE_GRANTED, |
| 2511 | QDF_IPA_RM_RESOURCE_WLAN_CONS); |
| 2512 | ipa_ctx->pending_cons_req = false; |
| 2513 | } |
| 2514 | qdf_mutex_release(&ipa_ctx->ipa_lock); |
| 2515 | } else if ((msg->op_code == WLAN_IPA_UC_OPCODE_TX_SUSPEND) || |
| 2516 | (msg->op_code == WLAN_IPA_UC_OPCODE_RX_SUSPEND)) { |
| 2517 | qdf_mutex_acquire(&ipa_ctx->ipa_lock); |
| 2518 | ipa_ctx->activated_fw_pipe--; |
| 2519 | if (!ipa_ctx->activated_fw_pipe) { |
| 2520 | /* |
| 2521 | * Async return success from FW |
| 2522 | * Disable/suspend all the PIPEs |
| 2523 | */ |
| 2524 | ipa_ctx->resource_unloading = false; |
| 2525 | qdf_event_set(&ipa_ctx->ipa_resource_comp); |
| 2526 | wlan_ipa_uc_disable_pipes(ipa_ctx); |
| 2527 | if (wlan_ipa_is_rm_enabled(ipa_ctx->config)) |
Yun Park | e114fbf | 2018-04-05 20:02:12 -0700 | [diff] [blame] | 2528 | wlan_ipa_wdi_rm_release_resource(ipa_ctx, |
| 2529 | QDF_IPA_RM_RESOURCE_WLAN_PROD); |
Sravan Kumar Kairam | 5214f65 | 2018-03-13 09:52:31 +0530 | [diff] [blame] | 2530 | wlan_ipa_uc_proc_pending_event(ipa_ctx, false); |
Sravan Kumar Kairam | 7d931ff | 2018-03-13 09:42:02 +0530 | [diff] [blame] | 2531 | ipa_ctx->pending_cons_req = false; |
| 2532 | } |
| 2533 | qdf_mutex_release(&ipa_ctx->ipa_lock); |
| 2534 | } else if ((msg->op_code == WLAN_IPA_UC_OPCODE_STATS) && |
| 2535 | (ipa_ctx->stat_req_reason == WLAN_IPA_UC_STAT_REASON_DEBUG)) { |
| 2536 | uc_fw_stat = (struct ipa_uc_fw_stats *) |
| 2537 | ((uint8_t *)op_msg + sizeof(struct op_msg_type)); |
| 2538 | |
| 2539 | /* WLAN FW WDI stats */ |
| 2540 | wlan_ipa_print_fw_wdi_stats(ipa_ctx, uc_fw_stat); |
| 2541 | } else if ((msg->op_code == WLAN_IPA_UC_OPCODE_STATS) && |
| 2542 | (ipa_ctx->stat_req_reason == WLAN_IPA_UC_STAT_REASON_BW_CAL)) { |
| 2543 | /* STATs from FW */ |
| 2544 | uc_fw_stat = (struct ipa_uc_fw_stats *) |
| 2545 | ((uint8_t *)op_msg + sizeof(struct op_msg_type)); |
| 2546 | qdf_mutex_acquire(&ipa_ctx->ipa_lock); |
| 2547 | ipa_ctx->ipa_tx_packets_diff = BW_GET_DIFF( |
| 2548 | uc_fw_stat->tx_pkts_completed, |
| 2549 | ipa_ctx->ipa_p_tx_packets); |
| 2550 | ipa_ctx->ipa_rx_packets_diff = BW_GET_DIFF( |
| 2551 | (uc_fw_stat->rx_num_ind_drop_no_space + |
| 2552 | uc_fw_stat->rx_num_ind_drop_no_buf + |
| 2553 | uc_fw_stat->rx_num_pkts_indicated), |
| 2554 | ipa_ctx->ipa_p_rx_packets); |
| 2555 | |
| 2556 | ipa_ctx->ipa_p_tx_packets = uc_fw_stat->tx_pkts_completed; |
| 2557 | ipa_ctx->ipa_p_rx_packets = |
| 2558 | (uc_fw_stat->rx_num_ind_drop_no_space + |
| 2559 | uc_fw_stat->rx_num_ind_drop_no_buf + |
| 2560 | uc_fw_stat->rx_num_pkts_indicated); |
| 2561 | qdf_mutex_release(&ipa_ctx->ipa_lock); |
| 2562 | } else if (msg->op_code == WLAN_IPA_UC_OPCODE_UC_READY) { |
| 2563 | qdf_mutex_acquire(&ipa_ctx->ipa_lock); |
| 2564 | wlan_ipa_uc_loaded_handler(ipa_ctx); |
| 2565 | qdf_mutex_release(&ipa_ctx->ipa_lock); |
| 2566 | } else if (wlan_ipa_uc_op_metering(ipa_ctx, op_msg)) { |
| 2567 | ipa_err("Invalid message: op_code=%d, reason=%d", |
| 2568 | msg->op_code, ipa_ctx->stat_req_reason); |
| 2569 | } |
| 2570 | |
| 2571 | qdf_mem_free(op_msg); |
| 2572 | } |
| 2573 | |
| 2574 | /** |
| 2575 | * wlan_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler |
| 2576 | * @work: uC OP work |
| 2577 | * |
| 2578 | * Return: None |
| 2579 | */ |
| 2580 | static void wlan_ipa_uc_fw_op_event_handler(void *data) |
| 2581 | { |
| 2582 | struct op_msg_type *msg; |
| 2583 | struct uc_op_work_struct *uc_op_work = |
| 2584 | (struct uc_op_work_struct *)data; |
| 2585 | struct wlan_ipa_priv *ipa_ctx = gp_ipa; |
| 2586 | |
| 2587 | msg = uc_op_work->msg; |
| 2588 | uc_op_work->msg = NULL; |
| 2589 | ipa_debug("posted msg %d", msg->op_code); |
| 2590 | |
| 2591 | wlan_ipa_uc_op_cb(msg, ipa_ctx); |
| 2592 | } |
| 2593 | |
| 2594 | /** |
| 2595 | * wlan_ipa_uc_op_event_handler() - IPA UC OP event handler |
| 2596 | * @op_msg: operation message received from firmware |
| 2597 | * @ipa_ctx: Global IPA context |
| 2598 | * |
| 2599 | * Return: None |
| 2600 | */ |
| 2601 | static void wlan_ipa_uc_op_event_handler(uint8_t *op_msg, void *ctx) |
| 2602 | { |
| 2603 | struct wlan_ipa_priv *ipa_ctx = (struct wlan_ipa_priv *)ctx; |
| 2604 | struct op_msg_type *msg; |
| 2605 | struct uc_op_work_struct *uc_op_work; |
| 2606 | |
| 2607 | if (!ipa_ctx) |
| 2608 | goto end; |
| 2609 | |
| 2610 | msg = (struct op_msg_type *)op_msg; |
| 2611 | |
| 2612 | if (msg->op_code >= WLAN_IPA_UC_OPCODE_MAX) { |
| 2613 | ipa_err("Invalid OP Code (%d)", msg->op_code); |
| 2614 | goto end; |
| 2615 | } |
| 2616 | |
| 2617 | uc_op_work = &ipa_ctx->uc_op_work[msg->op_code]; |
| 2618 | if (uc_op_work->msg) { |
| 2619 | /* When the same uC OPCODE is already pended, just return */ |
| 2620 | goto end; |
| 2621 | } |
| 2622 | |
| 2623 | uc_op_work->msg = msg; |
| 2624 | qdf_sched_work(0, &uc_op_work->work); |
| 2625 | return; |
| 2626 | |
| 2627 | end: |
| 2628 | qdf_mem_free(op_msg); |
| 2629 | } |
| 2630 | |
Sravan Kumar Kairam | 1309e7e | 2018-03-13 09:29:52 +0530 | [diff] [blame] | 2631 | QDF_STATUS wlan_ipa_uc_ol_init(struct wlan_ipa_priv *ipa_ctx, |
| 2632 | qdf_device_t osdev) |
| 2633 | { |
| 2634 | uint8_t i; |
| 2635 | QDF_STATUS status = QDF_STATUS_SUCCESS; |
| 2636 | |
| 2637 | if (!wlan_ipa_uc_is_enabled(ipa_ctx->config)) |
| 2638 | return QDF_STATUS_SUCCESS; |
| 2639 | |
| 2640 | ipa_debug("enter"); |
| 2641 | |
| 2642 | for (i = 0; i < WLAN_IPA_MAX_SESSION; i++) { |
| 2643 | ipa_ctx->vdev_to_iface[i] = WLAN_IPA_MAX_SESSION; |
| 2644 | ipa_ctx->vdev_offload_enabled[i] = false; |
| 2645 | } |
| 2646 | |
| 2647 | /* Set the lowest bandwidth to start with */ |
| 2648 | status = wlan_ipa_set_perf_level(ipa_ctx, 0, 0); |
| 2649 | if (status != QDF_STATUS_SUCCESS) { |
| 2650 | ipa_err("Set perf level failed: %d", status); |
Yun Park | e114fbf | 2018-04-05 20:02:12 -0700 | [diff] [blame] | 2651 | wlan_ipa_wdi_rm_inactivity_timer_destroy( |
Sravan Kumar Kairam | 1309e7e | 2018-03-13 09:29:52 +0530 | [diff] [blame] | 2652 | QDF_IPA_RM_RESOURCE_WLAN_PROD); |
| 2653 | goto fail_return; |
| 2654 | } |
| 2655 | |
| 2656 | if (cdp_ipa_get_resource(ipa_ctx->dp_soc, ipa_ctx->dp_pdev)) { |
| 2657 | ipa_err("IPA UC resource alloc fail"); |
| 2658 | status = QDF_STATUS_E_FAILURE; |
| 2659 | goto fail_return; |
| 2660 | } |
| 2661 | |
| 2662 | if (true == ipa_ctx->uc_loaded) { |
| 2663 | status = wlan_ipa_wdi_setup(ipa_ctx, osdev); |
| 2664 | if (status) { |
| 2665 | ipa_err("Failure to setup IPA pipes (status=%d)", |
| 2666 | status); |
| 2667 | status = QDF_STATUS_E_FAILURE; |
| 2668 | goto fail_return; |
| 2669 | } |
| 2670 | |
| 2671 | cdp_ipa_set_doorbell_paddr(ipa_ctx->dp_soc, ipa_ctx->dp_pdev); |
| 2672 | wlan_ipa_init_metering(ipa_ctx); |
| 2673 | } |
| 2674 | |
Sravan Kumar Kairam | 7d931ff | 2018-03-13 09:42:02 +0530 | [diff] [blame] | 2675 | cdp_ipa_register_op_cb(ipa_ctx->dp_soc, ipa_ctx->dp_pdev, |
| 2676 | wlan_ipa_uc_op_event_handler, (void *)ipa_ctx); |
| 2677 | |
| 2678 | for (i = 0; i < WLAN_IPA_UC_OPCODE_MAX; i++) { |
| 2679 | qdf_create_work(0, &ipa_ctx->uc_op_work[i].work, |
| 2680 | wlan_ipa_uc_fw_op_event_handler, |
| 2681 | &ipa_ctx->uc_op_work[i]); |
| 2682 | ipa_ctx->uc_op_work[i].msg = NULL; |
| 2683 | } |
| 2684 | |
Sravan Kumar Kairam | 1309e7e | 2018-03-13 09:29:52 +0530 | [diff] [blame] | 2685 | fail_return: |
| 2686 | ipa_debug("exit: status=%d", status); |
| 2687 | return status; |
| 2688 | } |
| 2689 | |
Sravan Kumar Kairam | 7d931ff | 2018-03-13 09:42:02 +0530 | [diff] [blame] | 2690 | /** |
| 2691 | * wlan_ipa_cleanup_pending_event() - Cleanup IPA pending event list |
| 2692 | * @ipa_ctx: pointer to IPA IPA struct |
| 2693 | * |
| 2694 | * Return: none |
| 2695 | */ |
| 2696 | static void wlan_ipa_cleanup_pending_event(struct wlan_ipa_priv *ipa_ctx) |
| 2697 | { |
| 2698 | struct wlan_ipa_uc_pending_event *pending_event = NULL; |
| 2699 | |
| 2700 | while (qdf_list_remove_front(&ipa_ctx->pending_event, |
| 2701 | (qdf_list_node_t **)&pending_event) == QDF_STATUS_SUCCESS) |
| 2702 | qdf_mem_free(pending_event); |
| 2703 | } |
| 2704 | |
Sravan Kumar Kairam | 1309e7e | 2018-03-13 09:29:52 +0530 | [diff] [blame] | 2705 | QDF_STATUS wlan_ipa_uc_ol_deinit(struct wlan_ipa_priv *ipa_ctx) |
| 2706 | { |
| 2707 | QDF_STATUS status = QDF_STATUS_SUCCESS; |
Sravan Kumar Kairam | 7d931ff | 2018-03-13 09:42:02 +0530 | [diff] [blame] | 2708 | int i; |
Sravan Kumar Kairam | 1309e7e | 2018-03-13 09:29:52 +0530 | [diff] [blame] | 2709 | |
| 2710 | ipa_debug("enter"); |
| 2711 | |
| 2712 | if (!wlan_ipa_uc_is_enabled(ipa_ctx->config)) |
| 2713 | return status; |
| 2714 | |
| 2715 | if (!ipa_ctx->ipa_pipes_down) |
| 2716 | wlan_ipa_uc_disable_pipes(ipa_ctx); |
| 2717 | |
| 2718 | if (true == ipa_ctx->uc_loaded) { |
| 2719 | status = cdp_ipa_cleanup(ipa_ctx->dp_soc, |
| 2720 | ipa_ctx->tx_pipe_handle, |
| 2721 | ipa_ctx->rx_pipe_handle); |
| 2722 | if (status) |
| 2723 | ipa_err("Failure to cleanup IPA pipes (status=%d)", |
| 2724 | status); |
| 2725 | } |
| 2726 | |
Sravan Kumar Kairam | 7d931ff | 2018-03-13 09:42:02 +0530 | [diff] [blame] | 2727 | qdf_mutex_acquire(&ipa_ctx->ipa_lock); |
| 2728 | wlan_ipa_cleanup_pending_event(ipa_ctx); |
| 2729 | qdf_mutex_release(&ipa_ctx->ipa_lock); |
| 2730 | |
| 2731 | for (i = 0; i < WLAN_IPA_UC_OPCODE_MAX; i++) { |
| 2732 | qdf_cancel_work(&ipa_ctx->uc_op_work[i].work); |
| 2733 | qdf_mem_free(ipa_ctx->uc_op_work[i].msg); |
| 2734 | ipa_ctx->uc_op_work[i].msg = NULL; |
| 2735 | } |
| 2736 | |
Sravan Kumar Kairam | 1309e7e | 2018-03-13 09:29:52 +0530 | [diff] [blame] | 2737 | ipa_debug("exit: ret=%d", status); |
| 2738 | return status; |
| 2739 | } |
Sravan Kumar Kairam | 983a445 | 2018-03-20 13:30:22 +0530 | [diff] [blame] | 2740 | |
Yun Park | a29974a | 2018-04-09 12:05:49 -0700 | [diff] [blame] | 2741 | /** |
| 2742 | * wlan_ipa_is_fw_wdi_activated() - Is FW WDI actived? |
| 2743 | * @ipa_ctx: IPA contex |
| 2744 | * |
| 2745 | * Return: true if FW WDI actived, false otherwise |
| 2746 | */ |
| 2747 | bool wlan_ipa_is_fw_wdi_activated(struct wlan_ipa_priv *ipa_ctx) |
| 2748 | { |
| 2749 | return (WLAN_IPA_UC_NUM_WDI_PIPE == ipa_ctx->activated_fw_pipe); |
| 2750 | } |
| 2751 | |