blob: 87c831c940f4023d411f70d127a56d0cbc18b048 [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Yeshwanth Sriram Guntuka508ffb72021-01-05 12:11:39 +05302 * Copyright (c) 2013-2021 The Linux Foundation. All rights reserved.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004 * 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
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080019/**
20 * DOC: wlan_hdd_ipa.c
21 *
22 * WLAN HDD and ipa interface implementation
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080023 */
24
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080025/* Include Files */
26#include <wlan_hdd_includes.h>
27#include <wlan_hdd_ipa.h>
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +053028#include "wlan_policy_mgr_api.h"
29#include "wlan_ipa_ucfg_api.h"
Yun Parkc3e35562018-03-08 12:05:52 -080030#include <wlan_hdd_softap_tx_rx.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080031#include <linux/inetdevice.h>
Rakshith Suresh Patkar388e7452019-03-19 16:28:55 +053032#include <qdf_trace.h>
Yun Parkb187d542016-11-14 18:10:04 -080033
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080034void hdd_ipa_set_tx_flow_info(void)
35{
Abdul Muqtadeer Ahmed6a082c62021-01-07 17:19:48 +053036 struct hdd_adapter *adapter, *next_adapter = NULL;
Jeff Johnsond377dce2017-10-04 10:32:42 -070037 struct hdd_station_ctx *sta_ctx;
Jeff Johnson87251032017-08-29 13:31:11 -070038 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070039 struct hdd_hostapd_state *hostapd_state;
Dustin Brown4e565a42018-01-17 14:59:14 -080040 struct qdf_mac_addr staBssid = QDF_MAC_ADDR_ZERO_INIT;
41 struct qdf_mac_addr p2pBssid = QDF_MAC_ADDR_ZERO_INIT;
42 struct qdf_mac_addr apBssid = QDF_MAC_ADDR_ZERO_INIT;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080043 uint8_t staChannel = 0, p2pChannel = 0, apChannel = 0;
44 const char *p2pMode = "DEV";
Jeff Johnsondd595cb2017-08-28 11:58:09 -070045 struct hdd_context *hdd_ctx;
Jeff Johnson2b6982c2018-05-29 14:56:11 -070046 struct cds_context *cds_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080047#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
48 uint8_t targetChannel = 0;
49 uint8_t preAdapterChannel = 0;
50 uint8_t channel24;
51 uint8_t channel5;
Jeff Johnson49d45e62017-08-29 14:30:42 -070052 struct hdd_adapter *preAdapterContext = NULL;
53 struct hdd_adapter *adapter2_4 = NULL;
54 struct hdd_adapter *adapter5 = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080055 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
56#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
57 struct wlan_objmgr_psoc *psoc;
Bapiraju Alla797b21b2020-11-23 13:44:21 +053058 wlan_net_dev_ref_dbgid dbgid = NET_DEV_HOLD_IPA_SET_TX_FLOW_INFO;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080059
60 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
61 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070062 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080063 return;
64 }
65
66 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
67 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070068 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080069 return;
70 }
71
Dustin Brown1dbefe62018-09-11 16:32:03 -070072 psoc = hdd_ctx->psoc;
Dustin Brown920397d2017-12-13 16:27:50 -080073
Bapiraju Alla797b21b2020-11-23 13:44:21 +053074 hdd_for_each_adapter_dev_held_safe(hdd_ctx, adapter, next_adapter,
75 dbgid) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080076 switch (adapter->device_mode) {
77 case QDF_STA_MODE:
Jeff Johnsond377dce2017-10-04 10:32:42 -070078 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080079 if (eConnectionState_Associated ==
Jeff Johnsone7951512019-02-27 10:02:51 -080080 sta_ctx->conn_info.conn_state) {
Jingxiang Gece7c5472019-07-23 16:19:23 +080081 staChannel = wlan_reg_freq_to_chan(
82 hdd_ctx->pdev,
Jingxiang Geae80dc62019-08-13 17:32:22 +080083 sta_ctx->conn_info.chan_freq);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080084 qdf_copy_macaddr(&staBssid,
Jeff Johnsone04b6992019-02-27 14:06:55 -080085 &sta_ctx->conn_info.bssid);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080086#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
87 targetChannel = staChannel;
88#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
89 }
90 break;
91 case QDF_P2P_CLIENT_MODE:
Jeff Johnsond377dce2017-10-04 10:32:42 -070092 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080093 if (eConnectionState_Associated ==
Jeff Johnsone7951512019-02-27 10:02:51 -080094 sta_ctx->conn_info.conn_state) {
Jingxiang Gece7c5472019-07-23 16:19:23 +080095 p2pChannel = wlan_reg_freq_to_chan(
96 hdd_ctx->pdev,
Jingxiang Geae80dc62019-08-13 17:32:22 +080097 sta_ctx->conn_info.chan_freq);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080098 qdf_copy_macaddr(&p2pBssid,
Jeff Johnsone04b6992019-02-27 14:06:55 -080099 &sta_ctx->conn_info.bssid);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -0800100 p2pMode = "CLI";
101#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
102 targetChannel = p2pChannel;
103#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
104 }
105 break;
106 case QDF_P2P_GO_MODE:
107 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
108 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Jeff Johnson0f9f87b2017-10-28 09:21:06 -0700109 if (hostapd_state->bss_state == BSS_START
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -0800110 && hostapd_state->qdf_status ==
111 QDF_STATUS_SUCCESS) {
Will Huang4b097f52019-08-29 10:51:56 -0700112 p2pChannel = wlan_reg_freq_to_chan(
113 hdd_ctx->pdev,
114 hdd_ap_ctx->operating_chan_freq);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -0800115 qdf_copy_macaddr(&p2pBssid,
Jeff Johnson1e851a12017-10-28 14:36:12 -0700116 &adapter->mac_addr);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -0800117#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
118 targetChannel = p2pChannel;
119#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
120 }
121 p2pMode = "GO";
122 break;
123 case QDF_SAP_MODE:
124 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
125 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Jeff Johnson0f9f87b2017-10-28 09:21:06 -0700126 if (hostapd_state->bss_state == BSS_START
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -0800127 && hostapd_state->qdf_status ==
128 QDF_STATUS_SUCCESS) {
Will Huang4b097f52019-08-29 10:51:56 -0700129 apChannel = wlan_reg_freq_to_chan(
130 hdd_ctx->pdev,
131 hdd_ap_ctx->operating_chan_freq);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -0800132 qdf_copy_macaddr(&apBssid,
Jeff Johnson1e851a12017-10-28 14:36:12 -0700133 &adapter->mac_addr);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -0800134#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
135 targetChannel = apChannel;
136#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
137 }
138 break;
139 case QDF_IBSS_MODE:
140 default:
141 break;
142 }
143#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
144 if (targetChannel) {
145 /*
146 * This is first adapter detected as active
147 * set as default for none concurrency case
148 */
149 if (!preAdapterChannel) {
150 /* If IPA UC data path is enabled,
151 * target should reserve extra tx descriptors
152 * for IPA data path.
153 * Then host data path should allow less TX
154 * packet pumping in case IPA
155 * data path enabled
156 */
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +0530157 if (ucfg_ipa_uc_is_enabled() &&
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -0800158 (QDF_SAP_MODE == adapter->device_mode)) {
159 adapter->tx_flow_low_watermark =
jitiphil869b9f72018-09-25 17:14:01 +0530160 hdd_ctx->config->tx_flow_low_watermark +
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -0800161 WLAN_TFC_IPAUC_TX_DESC_RESERVE;
162 } else {
163 adapter->tx_flow_low_watermark =
164 hdd_ctx->config->
jitiphil869b9f72018-09-25 17:14:01 +0530165 tx_flow_low_watermark;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -0800166 }
jitiphil869b9f72018-09-25 17:14:01 +0530167 adapter->tx_flow_hi_watermark_offset =
168 hdd_ctx->config->tx_flow_hi_watermark_offset;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -0800169 cdp_fc_ll_set_tx_pause_q_depth(soc,
Jeff Johnson9597f3b2019-02-04 14:27:56 -0800170 adapter->vdev_id,
jitiphil869b9f72018-09-25 17:14:01 +0530171 hdd_ctx->config->
172 tx_flow_max_queue_depth);
Jeff Johnson6867ec32017-09-29 20:30:20 -0700173 hdd_info("MODE %d,CH %d,LWM %d,HWM %d,TXQDEP %d",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -0800174 adapter->device_mode,
175 targetChannel,
176 adapter->tx_flow_low_watermark,
177 adapter->tx_flow_low_watermark +
jitiphil869b9f72018-09-25 17:14:01 +0530178 adapter->tx_flow_hi_watermark_offset,
179 hdd_ctx->config->tx_flow_max_queue_depth);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -0800180 preAdapterChannel = targetChannel;
181 preAdapterContext = adapter;
182 } else {
183 /*
184 * SCC, disable TX flow control for both
185 * SCC each adapter cannot reserve dedicated
186 * channel resource, as a result, if any adapter
187 * blocked OS Q by flow control,
188 * blocked adapter will lost chance to recover
189 */
190 if (preAdapterChannel == targetChannel) {
191 /* Current adapter */
192 adapter->tx_flow_low_watermark = 0;
193 adapter->
jitiphil869b9f72018-09-25 17:14:01 +0530194 tx_flow_hi_watermark_offset = 0;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -0800195 cdp_fc_ll_set_tx_pause_q_depth(soc,
Jeff Johnson9597f3b2019-02-04 14:27:56 -0800196 adapter->vdev_id,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -0800197 hdd_ctx->config->
jitiphil869b9f72018-09-25 17:14:01 +0530198 tx_hbw_flow_max_queue_depth);
Jeff Johnson6867ec32017-09-29 20:30:20 -0700199 hdd_info("SCC: MODE %s(%d), CH %d, LWM %d, HWM %d, TXQDEP %d",
Dustin Brown458027c2018-10-19 12:26:27 -0700200 qdf_opmode_str(
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -0800201 adapter->device_mode),
202 adapter->device_mode,
203 targetChannel,
204 adapter->tx_flow_low_watermark,
205 adapter->tx_flow_low_watermark +
206 adapter->
jitiphil869b9f72018-09-25 17:14:01 +0530207 tx_flow_hi_watermark_offset,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -0800208 hdd_ctx->config->
jitiphil869b9f72018-09-25 17:14:01 +0530209 tx_hbw_flow_max_queue_depth);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -0800210
211 if (!preAdapterContext) {
Jeff Johnson6867ec32017-09-29 20:30:20 -0700212 hdd_err("SCC: Previous adapter context NULL");
Bapiraju Alla797b21b2020-11-23 13:44:21 +0530213 hdd_adapter_dev_put_debug(
214 adapter, dbgid);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -0800215 continue;
216 }
217
218 /* Previous adapter */
219 preAdapterContext->
220 tx_flow_low_watermark = 0;
221 preAdapterContext->
jitiphil869b9f72018-09-25 17:14:01 +0530222 tx_flow_hi_watermark_offset = 0;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -0800223 cdp_fc_ll_set_tx_pause_q_depth(soc,
Wu Gaod07ea692019-10-29 10:32:25 +0800224 preAdapterContext->vdev_id,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -0800225 hdd_ctx->config->
jitiphil869b9f72018-09-25 17:14:01 +0530226 tx_hbw_flow_max_queue_depth);
Jeff Johnson6867ec32017-09-29 20:30:20 -0700227 hdd_info("SCC: MODE %s(%d), CH %d, LWM %d, HWM %d, TXQDEP %d",
Dustin Brown458027c2018-10-19 12:26:27 -0700228 qdf_opmode_str(
229 preAdapterContext->device_mode),
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -0800230 preAdapterContext->device_mode,
231 targetChannel,
232 preAdapterContext->
233 tx_flow_low_watermark,
234 preAdapterContext->
235 tx_flow_low_watermark +
236 preAdapterContext->
jitiphil869b9f72018-09-25 17:14:01 +0530237 tx_flow_hi_watermark_offset,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -0800238 hdd_ctx->config->
jitiphil869b9f72018-09-25 17:14:01 +0530239 tx_hbw_flow_max_queue_depth);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -0800240 }
241 /*
242 * MCC, each adapter will have dedicated
243 * resource
244 */
245 else {
246 /* current channel is 2.4 */
247 if (targetChannel <=
248 WLAN_HDD_TX_FLOW_CONTROL_MAX_24BAND_CH) {
249 channel24 = targetChannel;
250 channel5 = preAdapterChannel;
251 adapter2_4 = adapter;
252 adapter5 = preAdapterContext;
253 } else {
254 /* Current channel is 5 */
255 channel24 = preAdapterChannel;
256 channel5 = targetChannel;
257 adapter2_4 = preAdapterContext;
258 adapter5 = adapter;
259 }
260
261 if (!adapter5) {
Jeff Johnson6867ec32017-09-29 20:30:20 -0700262 hdd_err("MCC: 5GHz adapter context NULL");
Bapiraju Alla797b21b2020-11-23 13:44:21 +0530263 hdd_adapter_dev_put_debug(
264 adapter, dbgid);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -0800265 continue;
266 }
267 adapter5->tx_flow_low_watermark =
268 hdd_ctx->config->
jitiphil869b9f72018-09-25 17:14:01 +0530269 tx_hbw_flow_low_watermark;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -0800270 adapter5->
jitiphil869b9f72018-09-25 17:14:01 +0530271 tx_flow_hi_watermark_offset =
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -0800272 hdd_ctx->config->
jitiphil869b9f72018-09-25 17:14:01 +0530273 tx_hbw_flow_hi_watermark_offset;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -0800274 cdp_fc_ll_set_tx_pause_q_depth(soc,
Wu Gaod07ea692019-10-29 10:32:25 +0800275 adapter5->vdev_id,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -0800276 hdd_ctx->config->
jitiphil869b9f72018-09-25 17:14:01 +0530277 tx_hbw_flow_max_queue_depth);
Jeff Johnson6867ec32017-09-29 20:30:20 -0700278 hdd_info("MCC: MODE %s(%d), CH %d, LWM %d, HWM %d, TXQDEP %d",
Dustin Brown458027c2018-10-19 12:26:27 -0700279 qdf_opmode_str(
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -0800280 adapter5->device_mode),
281 adapter5->device_mode,
282 channel5,
283 adapter5->tx_flow_low_watermark,
284 adapter5->
285 tx_flow_low_watermark +
286 adapter5->
jitiphil869b9f72018-09-25 17:14:01 +0530287 tx_flow_hi_watermark_offset,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -0800288 hdd_ctx->config->
jitiphil869b9f72018-09-25 17:14:01 +0530289 tx_hbw_flow_max_queue_depth);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -0800290
291 if (!adapter2_4) {
Jeff Johnson6867ec32017-09-29 20:30:20 -0700292 hdd_err("MCC: 2.4GHz adapter context NULL");
Bapiraju Alla797b21b2020-11-23 13:44:21 +0530293 hdd_adapter_dev_put_debug(
294 adapter, dbgid);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -0800295 continue;
296 }
297 adapter2_4->tx_flow_low_watermark =
298 hdd_ctx->config->
jitiphil869b9f72018-09-25 17:14:01 +0530299 tx_lbw_flow_low_watermark;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -0800300 adapter2_4->
jitiphil869b9f72018-09-25 17:14:01 +0530301 tx_flow_hi_watermark_offset =
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -0800302 hdd_ctx->config->
jitiphil869b9f72018-09-25 17:14:01 +0530303 tx_lbw_flow_hi_watermark_offset;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -0800304 cdp_fc_ll_set_tx_pause_q_depth(soc,
Wu Gaod07ea692019-10-29 10:32:25 +0800305 adapter2_4->vdev_id,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -0800306 hdd_ctx->config->
jitiphil869b9f72018-09-25 17:14:01 +0530307 tx_lbw_flow_max_queue_depth);
Jeff Johnson6867ec32017-09-29 20:30:20 -0700308 hdd_info("MCC: MODE %s(%d), CH %d, LWM %d, HWM %d, TXQDEP %d",
Dustin Brown458027c2018-10-19 12:26:27 -0700309 qdf_opmode_str(
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -0800310 adapter2_4->device_mode),
311 adapter2_4->device_mode,
312 channel24,
313 adapter2_4->
314 tx_flow_low_watermark,
315 adapter2_4->
316 tx_flow_low_watermark +
317 adapter2_4->
jitiphil869b9f72018-09-25 17:14:01 +0530318 tx_flow_hi_watermark_offset,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -0800319 hdd_ctx->config->
jitiphil869b9f72018-09-25 17:14:01 +0530320 tx_lbw_flow_max_queue_depth);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -0800321
322 }
323 }
324 }
325 targetChannel = 0;
326#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
Bapiraju Alla797b21b2020-11-23 13:44:21 +0530327 hdd_adapter_dev_put_debug(adapter, dbgid);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -0800328 }
Prakash Dhavali412cdb02016-10-20 21:19:31 -0700329}
330
Yun Park5fe20502018-04-09 10:43:08 -0700331#if defined(QCA_CONFIG_SMP) && defined(PF_WAKE_UP_IDLE)
332/**
333 * hdd_ipa_get_wake_up_idle() - Get PF_WAKE_UP_IDLE flag in the task structure
334 *
335 * Get PF_WAKE_UP_IDLE flag in the task structure
336 *
337 * Return: 1 if PF_WAKE_UP_IDLE flag is set, 0 otherwise
338 */
339static uint32_t hdd_ipa_get_wake_up_idle(void)
340{
341 return sched_get_wake_up_idle(current);
342}
343
344/**
345 * hdd_ipa_set_wake_up_idle() - Set PF_WAKE_UP_IDLE flag in the task structure
346 *
347 * Set PF_WAKE_UP_IDLE flag in the task structure
348 * This task and any task woken by this will be waken to idle CPU
349 *
350 * Return: None
351 */
352static void hdd_ipa_set_wake_up_idle(bool wake_up_idle)
353{
354 sched_set_wake_up_idle(current, wake_up_idle);
355}
356#else
357static uint32_t hdd_ipa_get_wake_up_idle(void)
358{
359 return 0;
360}
361
362static void hdd_ipa_set_wake_up_idle(bool wake_up_idle)
363{
364}
365#endif
366
Nisha Menon9db78812019-12-11 16:09:04 -0800367/**
368 * hdd_ipa_send_to_nw_stack() - Check if IPA supports NAPI
369 * polling during RX
370 * @skb : data buffer sent to network stack
371 *
372 * If IPA LAN RX supports NAPI polling mechanism use
373 * netif_receive_skb instead of netif_rx_ni to forward the skb
374 * to network stack.
375 *
376 * Return: Return value from netif_rx_ni/netif_receive_skb
377 */
378static int hdd_ipa_send_to_nw_stack(qdf_nbuf_t skb)
379{
380 int result;
381
382 if (qdf_ipa_get_lan_rx_napi())
383 result = netif_receive_skb(skb);
384 else
385 result = netif_rx_ni(skb);
386 return result;
387}
388
tfyu0380a972017-07-13 18:19:37 +0800389#ifdef QCA_CONFIG_SMP
Mohit Khannacabf5e72018-07-24 13:28:43 -0700390
391/**
392 * hdd_ipa_aggregated_rx_ind() - Submit aggregated packets to the stack
393 * @skb: skb to be submitted to the stack
394 *
395 * For CONFIG_SMP systems, simply call netif_rx_ni.
396 * For non CONFIG_SMP systems call netif_rx till
397 * IPA_WLAN_RX_SOFTIRQ_THRESH. When threshold is reached call netif_rx_ni.
398 * In this manner, UDP/TCP packets are sent in an aggregated way to the stack.
399 * For IP/ICMP packets, simply call netif_rx_ni.
400 *
Nisha Menon9db78812019-12-11 16:09:04 -0800401 * Check if IPA supports NAPI polling then use netif_receive_skb
402 * instead of netif_rx_ni.
403 *
Mohit Khannacabf5e72018-07-24 13:28:43 -0700404 * Return: return value from the netif_rx_ni/netif_rx api.
405 */
tfyu0380a972017-07-13 18:19:37 +0800406static int hdd_ipa_aggregated_rx_ind(qdf_nbuf_t skb)
407{
Mohit Khannacabf5e72018-07-24 13:28:43 -0700408 int ret;
409
Nisha Menon9db78812019-12-11 16:09:04 -0800410 ret = hdd_ipa_send_to_nw_stack(skb);
Mohit Khannacabf5e72018-07-24 13:28:43 -0700411 return ret;
tfyu0380a972017-07-13 18:19:37 +0800412}
413#else
414static int hdd_ipa_aggregated_rx_ind(qdf_nbuf_t skb)
415{
416 struct iphdr *ip_h;
417 static atomic_t softirq_mitigation_cntr =
418 ATOMIC_INIT(IPA_WLAN_RX_SOFTIRQ_THRESH);
419 int result;
420
421 ip_h = (struct iphdr *)(skb->data);
422 if ((skb->protocol == htons(ETH_P_IP)) &&
423 (ip_h->protocol == IPPROTO_ICMP)) {
Nisha Menon9db78812019-12-11 16:09:04 -0800424 result = hdd_ipa_send_to_nw_stack(skb);
tfyu0380a972017-07-13 18:19:37 +0800425 } else {
426 /* Call netif_rx_ni for every IPA_WLAN_RX_SOFTIRQ_THRESH packets
427 * to avoid excessive softirq's.
428 */
429 if (atomic_dec_and_test(&softirq_mitigation_cntr)) {
Nisha Menon9db78812019-12-11 16:09:04 -0800430 result = hdd_ipa_send_to_nw_stack(skb);
tfyu0380a972017-07-13 18:19:37 +0800431 atomic_set(&softirq_mitigation_cntr,
432 IPA_WLAN_RX_SOFTIRQ_THRESH);
433 } else {
434 result = netif_rx(skb);
435 }
436 }
437
438 return result;
439}
440#endif
441
Vevek Venkatesan3b6be822019-05-28 18:19:15 +0530442void hdd_ipa_send_nbuf_to_network(qdf_nbuf_t nbuf, qdf_netdev_t dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800443{
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +0530444 struct hdd_adapter *adapter = (struct hdd_adapter *) netdev_priv(dev);
tfyu0380a972017-07-13 18:19:37 +0800445 int result;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800446 unsigned int cpu_index;
Yun Park5fe20502018-04-09 10:43:08 -0700447 uint32_t enabled;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800448
Yun Park21ec4902018-04-24 12:11:01 -0700449 if (hdd_validate_adapter(adapter)) {
Vevek Venkatesan3b6be822019-05-28 18:19:15 +0530450 kfree_skb(nbuf);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800451 return;
452 }
453
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800454 if (cds_is_driver_unloading()) {
Vevek Venkatesan3b6be822019-05-28 18:19:15 +0530455 kfree_skb(nbuf);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800456 return;
457 }
458
Manjunathappa Prakash028d4712018-10-07 07:24:26 -0700459 if ((adapter->device_mode == QDF_SAP_MODE) &&
Vevek Venkatesan3b6be822019-05-28 18:19:15 +0530460 (qdf_nbuf_is_ipv4_dhcp_pkt(nbuf) == true)) {
Yun Parkc3e35562018-03-08 12:05:52 -0800461 /* Send DHCP Indication to FW */
Nirav Shaha7fa1922019-08-05 22:59:56 +0530462 hdd_softap_inspect_dhcp_packet(adapter, nbuf, QDF_RX);
Yun Parkc3e35562018-03-08 12:05:52 -0800463 }
464
Vevek Venkatesan3b6be822019-05-28 18:19:15 +0530465 qdf_dp_trace_set_track(nbuf, QDF_RX);
jiaddd2c64d2019-05-11 10:35:21 +0800466
Vevek Venkatesan3b6be822019-05-28 18:19:15 +0530467 hdd_event_eapol_log(nbuf, QDF_RX);
jiaddd2c64d2019-05-11 10:35:21 +0800468 qdf_dp_trace_log_pkt(adapter->vdev_id,
Vevek Venkatesan3b6be822019-05-28 18:19:15 +0530469 nbuf, QDF_RX, QDF_TRACE_DEFAULT_PDEV_ID);
470 DPTRACE(qdf_dp_trace(nbuf,
jiaddd2c64d2019-05-11 10:35:21 +0800471 QDF_DP_TRACE_RX_HDD_PACKET_PTR_RECORD,
472 QDF_TRACE_DEFAULT_PDEV_ID,
Vevek Venkatesan3b6be822019-05-28 18:19:15 +0530473 qdf_nbuf_data_addr(nbuf),
474 sizeof(qdf_nbuf_data(nbuf)), QDF_RX));
475 DPTRACE(qdf_dp_trace_data_pkt(nbuf, QDF_TRACE_DEFAULT_PDEV_ID,
jiaddd2c64d2019-05-11 10:35:21 +0800476 QDF_DP_TRACE_RX_PACKET_RECORD, 0,
477 QDF_RX));
478
Yun Park5fe20502018-04-09 10:43:08 -0700479 /*
480 * Set PF_WAKE_UP_IDLE flag in the task structure
481 * This task and any task woken by this will be waken to idle CPU
482 */
483 enabled = hdd_ipa_get_wake_up_idle();
484 if (!enabled)
485 hdd_ipa_set_wake_up_idle(true);
486
Vevek Venkatesan3b6be822019-05-28 18:19:15 +0530487 nbuf->dev = adapter->dev;
488 nbuf->protocol = eth_type_trans(nbuf, nbuf->dev);
489 nbuf->ip_summed = CHECKSUM_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800490
491 cpu_index = wlan_hdd_get_cpu();
492
Jeff Johnson6ced42c2017-10-20 12:48:11 -0700493 ++adapter->hdd_stats.tx_rx_stats.rx_packets[cpu_index];
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +0530494
495 /*
496 * Update STA RX exception packet stats.
497 * For SAP as part of IPA HW stats are updated.
498 */
Sravan Kumar Kairam30338442018-03-26 15:09:21 +0530499
Mohit Khannacabf5e72018-07-24 13:28:43 -0700500 ++adapter->stats.rx_packets;
Vevek Venkatesan3b6be822019-05-28 18:19:15 +0530501 adapter->stats.rx_bytes += nbuf->len;
Rakshith Suresh Patkar388e7452019-03-19 16:28:55 +0530502
Vevek Venkatesan3b6be822019-05-28 18:19:15 +0530503 result = hdd_ipa_aggregated_rx_ind(nbuf);
Yeshwanth Sriram Guntuka508ffb72021-01-05 12:11:39 +0530504 if (result == NET_RX_SUCCESS)
Jeff Johnson6ced42c2017-10-20 12:48:11 -0700505 ++adapter->hdd_stats.tx_rx_stats.rx_delivered[cpu_index];
Yeshwanth Sriram Guntuka508ffb72021-01-05 12:11:39 +0530506 else
Jeff Johnson6ced42c2017-10-20 12:48:11 -0700507 ++adapter->hdd_stats.tx_rx_stats.rx_refused[cpu_index];
Yun Park5fe20502018-04-09 10:43:08 -0700508
509 /*
510 * Restore PF_WAKE_UP_IDLE flag in the task structure
511 */
512 if (!enabled)
513 hdd_ipa_set_wake_up_idle(false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800514}
jiadbb47e132018-03-30 16:28:30 +0800515
516void hdd_ipa_set_mcc_mode(bool mcc_mode)
517{
518 struct hdd_context *hdd_ctx;
519
520 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
521 if (!hdd_ctx) {
522 hdd_err("HDD context is NULL");
523 return;
524 }
525
Dustin Brown07901ec2018-09-07 11:02:41 -0700526 ucfg_ipa_set_mcc_mode(hdd_ctx->pdev, mcc_mode);
jiadbb47e132018-03-30 16:28:30 +0800527}