blob: d75756c68e16e999af48cfb304e274a7d6d47d37 [file] [log] [blame]
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001/*
2 * Marvell Wireless LAN device driver: utility functions
3 *
Xinming Hu65da33f2014-06-19 21:38:57 -07004 * Copyright (C) 2011-2014, Marvell International Ltd.
Bing Zhao5e6e3a92011-03-21 18:00:50 -07005 *
6 * This software file (the "File") is distributed by Marvell International
7 * Ltd. under the terms of the GNU General Public License Version 2, June 1991
8 * (the "License"). You may use, redistribute and/or modify this File in
9 * accordance with the terms and conditions of the License, a copy of which
10 * is available by writing to the Free Software Foundation, Inc.,
11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
13 *
14 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
16 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
17 * this warranty disclaimer.
18 */
19
20#include "decl.h"
21#include "ioctl.h"
22#include "util.h"
23#include "fw.h"
24#include "main.h"
25#include "wmm.h"
26#include "11n.h"
27
Xinming Hubb5097f2014-12-23 19:14:09 +053028static struct mwifiex_debug_data items[] = {
Zhaoyang Liuc687a002015-05-12 00:48:18 +053029 {"debug_mask", item_size(debug_mask),
30 item_addr(debug_mask), 1},
Xinming Hubb5097f2014-12-23 19:14:09 +053031 {"int_counter", item_size(int_counter),
32 item_addr(int_counter), 1},
33 {"wmm_ac_vo", item_size(packets_out[WMM_AC_VO]),
34 item_addr(packets_out[WMM_AC_VO]), 1},
35 {"wmm_ac_vi", item_size(packets_out[WMM_AC_VI]),
36 item_addr(packets_out[WMM_AC_VI]), 1},
37 {"wmm_ac_be", item_size(packets_out[WMM_AC_BE]),
38 item_addr(packets_out[WMM_AC_BE]), 1},
39 {"wmm_ac_bk", item_size(packets_out[WMM_AC_BK]),
40 item_addr(packets_out[WMM_AC_BK]), 1},
41 {"tx_buf_size", item_size(tx_buf_size),
42 item_addr(tx_buf_size), 1},
43 {"curr_tx_buf_size", item_size(curr_tx_buf_size),
44 item_addr(curr_tx_buf_size), 1},
45 {"ps_mode", item_size(ps_mode),
46 item_addr(ps_mode), 1},
47 {"ps_state", item_size(ps_state),
48 item_addr(ps_state), 1},
49 {"is_deep_sleep", item_size(is_deep_sleep),
50 item_addr(is_deep_sleep), 1},
51 {"wakeup_dev_req", item_size(pm_wakeup_card_req),
52 item_addr(pm_wakeup_card_req), 1},
53 {"wakeup_tries", item_size(pm_wakeup_fw_try),
54 item_addr(pm_wakeup_fw_try), 1},
55 {"hs_configured", item_size(is_hs_configured),
56 item_addr(is_hs_configured), 1},
57 {"hs_activated", item_size(hs_activated),
58 item_addr(hs_activated), 1},
59 {"num_tx_timeout", item_size(num_tx_timeout),
60 item_addr(num_tx_timeout), 1},
61 {"is_cmd_timedout", item_size(is_cmd_timedout),
62 item_addr(is_cmd_timedout), 1},
63 {"timeout_cmd_id", item_size(timeout_cmd_id),
64 item_addr(timeout_cmd_id), 1},
65 {"timeout_cmd_act", item_size(timeout_cmd_act),
66 item_addr(timeout_cmd_act), 1},
67 {"last_cmd_id", item_size(last_cmd_id),
68 item_addr(last_cmd_id), DBG_CMD_NUM},
69 {"last_cmd_act", item_size(last_cmd_act),
70 item_addr(last_cmd_act), DBG_CMD_NUM},
71 {"last_cmd_index", item_size(last_cmd_index),
72 item_addr(last_cmd_index), 1},
73 {"last_cmd_resp_id", item_size(last_cmd_resp_id),
74 item_addr(last_cmd_resp_id), DBG_CMD_NUM},
75 {"last_cmd_resp_index", item_size(last_cmd_resp_index),
76 item_addr(last_cmd_resp_index), 1},
77 {"last_event", item_size(last_event),
78 item_addr(last_event), DBG_CMD_NUM},
79 {"last_event_index", item_size(last_event_index),
80 item_addr(last_event_index), 1},
Xinming Hu8b7ef8b2016-02-23 05:16:18 -080081 {"last_mp_wr_bitmap", item_size(last_mp_wr_bitmap),
82 item_addr(last_mp_wr_bitmap), MWIFIEX_DBG_SDIO_MP_NUM},
83 {"last_mp_wr_ports", item_size(last_mp_wr_ports),
84 item_addr(last_mp_wr_ports), MWIFIEX_DBG_SDIO_MP_NUM},
85 {"last_mp_wr_len", item_size(last_mp_wr_len),
86 item_addr(last_mp_wr_len), MWIFIEX_DBG_SDIO_MP_NUM},
87 {"last_mp_curr_wr_port", item_size(last_mp_curr_wr_port),
88 item_addr(last_mp_curr_wr_port), MWIFIEX_DBG_SDIO_MP_NUM},
89 {"last_sdio_mp_index", item_size(last_sdio_mp_index),
90 item_addr(last_sdio_mp_index), 1},
Xinming Hubb5097f2014-12-23 19:14:09 +053091 {"num_cmd_h2c_fail", item_size(num_cmd_host_to_card_failure),
92 item_addr(num_cmd_host_to_card_failure), 1},
93 {"num_cmd_sleep_cfm_fail",
94 item_size(num_cmd_sleep_cfm_host_to_card_failure),
95 item_addr(num_cmd_sleep_cfm_host_to_card_failure), 1},
96 {"num_tx_h2c_fail", item_size(num_tx_host_to_card_failure),
97 item_addr(num_tx_host_to_card_failure), 1},
98 {"num_evt_deauth", item_size(num_event_deauth),
99 item_addr(num_event_deauth), 1},
100 {"num_evt_disassoc", item_size(num_event_disassoc),
101 item_addr(num_event_disassoc), 1},
102 {"num_evt_link_lost", item_size(num_event_link_lost),
103 item_addr(num_event_link_lost), 1},
104 {"num_cmd_deauth", item_size(num_cmd_deauth),
105 item_addr(num_cmd_deauth), 1},
106 {"num_cmd_assoc_ok", item_size(num_cmd_assoc_success),
107 item_addr(num_cmd_assoc_success), 1},
108 {"num_cmd_assoc_fail", item_size(num_cmd_assoc_failure),
109 item_addr(num_cmd_assoc_failure), 1},
110 {"cmd_sent", item_size(cmd_sent),
111 item_addr(cmd_sent), 1},
112 {"data_sent", item_size(data_sent),
113 item_addr(data_sent), 1},
114 {"cmd_resp_received", item_size(cmd_resp_received),
115 item_addr(cmd_resp_received), 1},
116 {"event_received", item_size(event_received),
117 item_addr(event_received), 1},
118
119 /* variables defined in struct mwifiex_adapter */
120 {"cmd_pending", adapter_item_size(cmd_pending),
121 adapter_item_addr(cmd_pending), 1},
122 {"tx_pending", adapter_item_size(tx_pending),
123 adapter_item_addr(tx_pending), 1},
124 {"rx_pending", adapter_item_size(rx_pending),
125 adapter_item_addr(rx_pending), 1},
126};
127
128static int num_of_items = ARRAY_SIZE(items);
129
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700130/*
131 * Firmware initialization complete callback handler.
132 *
133 * This function wakes up the function waiting on the init
134 * wait queue for the firmware initialization to complete.
135 */
136int mwifiex_init_fw_complete(struct mwifiex_adapter *adapter)
137{
138
Zhaoyang Liu39875092015-07-22 04:53:43 -0700139 if (adapter->hw_status == MWIFIEX_HW_STATUS_READY)
140 if (adapter->if_ops.init_fw_port)
141 adapter->if_ops.init_fw_port(adapter);
142
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700143 adapter->init_wait_q_woken = true;
144 wake_up_interruptible(&adapter->init_wait_q);
145 return 0;
146}
147
148/*
149 * Firmware shutdown complete callback handler.
150 *
151 * This function sets the hardware status to not ready and wakes up
152 * the function waiting on the init wait queue for the firmware
153 * shutdown to complete.
154 */
155int mwifiex_shutdown_fw_complete(struct mwifiex_adapter *adapter)
156{
157 adapter->hw_status = MWIFIEX_HW_STATUS_NOT_READY;
158 adapter->init_wait_q_woken = true;
159 wake_up_interruptible(&adapter->init_wait_q);
160 return 0;
161}
162
163/*
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700164 * This function sends init/shutdown command
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700165 * to firmware.
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700166 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700167int mwifiex_init_shutdown_fw(struct mwifiex_private *priv,
168 u32 func_init_shutdown)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700169{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700170 u16 cmd;
171
172 if (func_init_shutdown == MWIFIEX_FUNC_INIT) {
173 cmd = HostCmd_CMD_FUNC_INIT;
174 } else if (func_init_shutdown == MWIFIEX_FUNC_SHUTDOWN) {
175 cmd = HostCmd_CMD_FUNC_SHUTDOWN;
176 } else {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530177 mwifiex_dbg(priv->adapter, ERROR,
178 "unsupported parameter\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700179 return -1;
180 }
181
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800182 return mwifiex_send_cmd(priv, cmd, HostCmd_ACT_GEN_SET, 0, NULL, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700183}
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700184EXPORT_SYMBOL_GPL(mwifiex_init_shutdown_fw);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700185
186/*
187 * IOCTL request handler to set/get debug information.
188 *
189 * This function collates/sets the information from/to different driver
190 * structures.
191 */
192int mwifiex_get_debug_info(struct mwifiex_private *priv,
193 struct mwifiex_debug_info *info)
194{
195 struct mwifiex_adapter *adapter = priv->adapter;
196
197 if (info) {
Zhaoyang Liuc687a002015-05-12 00:48:18 +0530198 info->debug_mask = adapter->debug_mask;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700199 memcpy(info->packets_out,
200 priv->wmm.packets_out,
201 sizeof(priv->wmm.packets_out));
Bing Zhao5e3175f2013-01-30 19:56:02 -0800202 info->curr_tx_buf_size = (u32) adapter->curr_tx_buf_size;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700203 info->tx_buf_size = (u32) adapter->tx_buf_size;
Yogesh Ashok Powarc65a30f2012-03-13 19:22:42 -0700204 info->rx_tbl_num = mwifiex_get_rx_reorder_tbl(priv,
205 info->rx_tbl);
206 info->tx_tbl_num = mwifiex_get_tx_ba_stream_tbl(priv,
207 info->tx_tbl);
Xinming Hu72df6312014-12-23 19:14:05 +0530208 info->tdls_peer_num = mwifiex_get_tdls_list(priv,
209 info->tdls_list);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700210 info->ps_mode = adapter->ps_mode;
211 info->ps_state = adapter->ps_state;
212 info->is_deep_sleep = adapter->is_deep_sleep;
213 info->pm_wakeup_card_req = adapter->pm_wakeup_card_req;
214 info->pm_wakeup_fw_try = adapter->pm_wakeup_fw_try;
215 info->is_hs_configured = adapter->is_hs_configured;
216 info->hs_activated = adapter->hs_activated;
Amitkumar Karwar0c9c4a02014-02-27 19:35:17 -0800217 info->is_cmd_timedout = adapter->is_cmd_timedout;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700218 info->num_cmd_host_to_card_failure
Yogesh Ashok Powarc65a30f2012-03-13 19:22:42 -0700219 = adapter->dbg.num_cmd_host_to_card_failure;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700220 info->num_cmd_sleep_cfm_host_to_card_failure
221 = adapter->dbg.num_cmd_sleep_cfm_host_to_card_failure;
222 info->num_tx_host_to_card_failure
Yogesh Ashok Powarc65a30f2012-03-13 19:22:42 -0700223 = adapter->dbg.num_tx_host_to_card_failure;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700224 info->num_event_deauth = adapter->dbg.num_event_deauth;
225 info->num_event_disassoc = adapter->dbg.num_event_disassoc;
226 info->num_event_link_lost = adapter->dbg.num_event_link_lost;
227 info->num_cmd_deauth = adapter->dbg.num_cmd_deauth;
228 info->num_cmd_assoc_success =
Yogesh Ashok Powarc65a30f2012-03-13 19:22:42 -0700229 adapter->dbg.num_cmd_assoc_success;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700230 info->num_cmd_assoc_failure =
Yogesh Ashok Powarc65a30f2012-03-13 19:22:42 -0700231 adapter->dbg.num_cmd_assoc_failure;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700232 info->num_tx_timeout = adapter->dbg.num_tx_timeout;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700233 info->timeout_cmd_id = adapter->dbg.timeout_cmd_id;
234 info->timeout_cmd_act = adapter->dbg.timeout_cmd_act;
235 memcpy(info->last_cmd_id, adapter->dbg.last_cmd_id,
236 sizeof(adapter->dbg.last_cmd_id));
237 memcpy(info->last_cmd_act, adapter->dbg.last_cmd_act,
238 sizeof(adapter->dbg.last_cmd_act));
239 info->last_cmd_index = adapter->dbg.last_cmd_index;
240 memcpy(info->last_cmd_resp_id, adapter->dbg.last_cmd_resp_id,
241 sizeof(adapter->dbg.last_cmd_resp_id));
242 info->last_cmd_resp_index = adapter->dbg.last_cmd_resp_index;
243 memcpy(info->last_event, adapter->dbg.last_event,
244 sizeof(adapter->dbg.last_event));
245 info->last_event_index = adapter->dbg.last_event_index;
Xinming Hu8b7ef8b2016-02-23 05:16:18 -0800246 memcpy(info->last_mp_wr_bitmap, adapter->dbg.last_mp_wr_bitmap,
247 sizeof(adapter->dbg.last_mp_wr_bitmap));
248 memcpy(info->last_mp_wr_ports, adapter->dbg.last_mp_wr_ports,
249 sizeof(adapter->dbg.last_mp_wr_ports));
250 memcpy(info->last_mp_curr_wr_port,
251 adapter->dbg.last_mp_curr_wr_port,
252 sizeof(adapter->dbg.last_mp_curr_wr_port));
253 memcpy(info->last_mp_wr_len, adapter->dbg.last_mp_wr_len,
254 sizeof(adapter->dbg.last_mp_wr_len));
255 info->last_sdio_mp_index = adapter->dbg.last_sdio_mp_index;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700256 info->data_sent = adapter->data_sent;
257 info->cmd_sent = adapter->cmd_sent;
258 info->cmd_resp_received = adapter->cmd_resp_received;
259 }
260
261 return 0;
262}
263
Xinming Hubb5097f2014-12-23 19:14:09 +0530264int mwifiex_debug_info_to_buffer(struct mwifiex_private *priv, char *buf,
265 struct mwifiex_debug_info *info)
266{
267 char *p = buf;
268 struct mwifiex_debug_data *d = &items[0];
269 size_t size, addr;
270 long val;
271 int i, j;
272
273 if (!info)
274 return 0;
275
276 for (i = 0; i < num_of_items; i++) {
277 p += sprintf(p, "%s=", d[i].name);
278
279 size = d[i].size / d[i].num;
280
281 if (i < (num_of_items - 3))
282 addr = d[i].addr + (size_t)info;
283 else /* The last 3 items are struct mwifiex_adapter variables */
284 addr = d[i].addr + (size_t)priv->adapter;
285
286 for (j = 0; j < d[i].num; j++) {
287 switch (size) {
288 case 1:
289 val = *((u8 *)addr);
290 break;
291 case 2:
292 val = *((u16 *)addr);
293 break;
294 case 4:
295 val = *((u32 *)addr);
296 break;
297 case 8:
298 val = *((long long *)addr);
299 break;
300 default:
301 val = -1;
302 break;
303 }
304
305 p += sprintf(p, "%#lx ", val);
306 addr += size;
307 }
308
309 p += sprintf(p, "\n");
310 }
311
312 if (info->tx_tbl_num) {
313 p += sprintf(p, "Tx BA stream table:\n");
314 for (i = 0; i < info->tx_tbl_num; i++)
315 p += sprintf(p, "tid = %d, ra = %pM\n",
316 info->tx_tbl[i].tid, info->tx_tbl[i].ra);
317 }
318
319 if (info->rx_tbl_num) {
320 p += sprintf(p, "Rx reorder table:\n");
321 for (i = 0; i < info->rx_tbl_num; i++) {
322 p += sprintf(p, "tid = %d, ta = %pM, ",
323 info->rx_tbl[i].tid,
324 info->rx_tbl[i].ta);
325 p += sprintf(p, "start_win = %d, ",
326 info->rx_tbl[i].start_win);
327 p += sprintf(p, "win_size = %d, buffer: ",
328 info->rx_tbl[i].win_size);
329
330 for (j = 0; j < info->rx_tbl[i].win_size; j++)
331 p += sprintf(p, "%c ",
332 info->rx_tbl[i].buffer[j] ?
333 '1' : '0');
334
335 p += sprintf(p, "\n");
336 }
337 }
338
339 if (info->tdls_peer_num) {
340 p += sprintf(p, "TDLS peer table:\n");
341 for (i = 0; i < info->tdls_peer_num; i++) {
342 p += sprintf(p, "peer = %pM",
343 info->tdls_list[i].peer_addr);
344 p += sprintf(p, "\n");
345 }
346 }
347
348 return p - buf;
349}
350
Avinash Patil72e5aa82014-11-13 21:54:17 +0530351static int
352mwifiex_parse_mgmt_packet(struct mwifiex_private *priv, u8 *payload, u16 len,
353 struct rxpd *rx_pd)
354{
355 u16 stype;
Avinash Patil3e6f8a42015-06-03 16:59:43 +0530356 u8 category, action_code, *addr2;
Avinash Patil72e5aa82014-11-13 21:54:17 +0530357 struct ieee80211_hdr *ieee_hdr = (void *)payload;
358
Amitkumar Karwar51974612014-11-25 06:43:02 -0800359 stype = (le16_to_cpu(ieee_hdr->frame_control) & IEEE80211_FCTL_STYPE);
Avinash Patil72e5aa82014-11-13 21:54:17 +0530360
361 switch (stype) {
362 case IEEE80211_STYPE_ACTION:
363 category = *(payload + sizeof(struct ieee80211_hdr));
Avinash Patil3e6f8a42015-06-03 16:59:43 +0530364 switch (category) {
365 case WLAN_CATEGORY_PUBLIC:
366 action_code = *(payload + sizeof(struct ieee80211_hdr)
367 + 1);
368 if (action_code == WLAN_PUB_ACTION_TDLS_DISCOVER_RES) {
369 addr2 = ieee_hdr->addr2;
370 mwifiex_dbg(priv->adapter, INFO,
371 "TDLS discovery response %pM nf=%d, snr=%d\n",
372 addr2, rx_pd->nf, rx_pd->snr);
373 mwifiex_auto_tdls_update_peer_signal(priv,
374 addr2,
375 rx_pd->snr,
376 rx_pd->nf);
377 }
378 break;
379 case WLAN_CATEGORY_BACK:
380 /*we dont indicate BACK action frames to cfg80211*/
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530381 mwifiex_dbg(priv->adapter, INFO,
Avinash Patil3e6f8a42015-06-03 16:59:43 +0530382 "drop BACK action frames");
383 return -1;
384 default:
385 mwifiex_dbg(priv->adapter, INFO,
386 "unknown public action frame category %d\n",
387 category);
Avinash Patil72e5aa82014-11-13 21:54:17 +0530388 }
Colin Ian Kingd393be32016-08-16 13:10:13 +0100389 break;
Avinash Patil72e5aa82014-11-13 21:54:17 +0530390 default:
Avinash Patilec21dc42015-05-20 16:36:06 +0530391 mwifiex_dbg(priv->adapter, INFO,
Avinash Patil3e6f8a42015-06-03 16:59:43 +0530392 "unknown mgmt frame subtype %#x\n", stype);
393 return 0;
Avinash Patil72e5aa82014-11-13 21:54:17 +0530394 }
395
396 return 0;
397}
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700398/*
Stone Piao2dbaf752012-09-25 20:23:35 -0700399 * This function processes the received management packet and send it
400 * to the kernel.
401 */
402int
Avinash Patilf3b369e2012-10-19 19:19:21 -0700403mwifiex_process_mgmt_packet(struct mwifiex_private *priv,
Stone Piao2dbaf752012-09-25 20:23:35 -0700404 struct sk_buff *skb)
405{
406 struct rxpd *rx_pd;
Stone Piao2dbaf752012-09-25 20:23:35 -0700407 u16 pkt_len;
Avinash Patil72e5aa82014-11-13 21:54:17 +0530408 struct ieee80211_hdr *ieee_hdr;
Stone Piao2dbaf752012-09-25 20:23:35 -0700409
410 if (!skb)
411 return -1;
412
Avinash Patil7521ce62015-02-11 23:12:25 +0530413 if (!priv->mgmt_frame_mask ||
414 priv->wdev.iftype == NL80211_IFTYPE_UNSPECIFIED) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530415 mwifiex_dbg(priv->adapter, ERROR,
416 "do not receive mgmt frames on uninitialized intf");
Avinash Patil7521ce62015-02-11 23:12:25 +0530417 return -1;
418 }
419
Stone Piao2dbaf752012-09-25 20:23:35 -0700420 rx_pd = (struct rxpd *)skb->data;
Stone Piao2dbaf752012-09-25 20:23:35 -0700421
422 skb_pull(skb, le16_to_cpu(rx_pd->rx_pkt_offset));
423 skb_pull(skb, sizeof(pkt_len));
424
425 pkt_len = le16_to_cpu(rx_pd->rx_pkt_length);
426
Avinash Patil72e5aa82014-11-13 21:54:17 +0530427 ieee_hdr = (void *)skb->data;
428 if (ieee80211_is_mgmt(ieee_hdr->frame_control)) {
Avinash Patil3e6f8a42015-06-03 16:59:43 +0530429 if (mwifiex_parse_mgmt_packet(priv, (u8 *)ieee_hdr,
430 pkt_len, rx_pd))
431 return -1;
Avinash Patil72e5aa82014-11-13 21:54:17 +0530432 }
Stone Piao2dbaf752012-09-25 20:23:35 -0700433 /* Remove address4 */
434 memmove(skb->data + sizeof(struct ieee80211_hdr_3addr),
435 skb->data + sizeof(struct ieee80211_hdr),
436 pkt_len - sizeof(struct ieee80211_hdr));
437
438 pkt_len -= ETH_ALEN + sizeof(pkt_len);
439 rx_pd->rx_pkt_length = cpu_to_le16(pkt_len);
440
Avinash Patil4facc342015-01-28 15:42:00 +0530441 cfg80211_rx_mgmt(&priv->wdev, priv->roc_cfg.chan.center_freq,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +0300442 CAL_RSSI(rx_pd->snr, rx_pd->nf), skb->data, pkt_len,
Vladimir Kondratiev970fdfa2014-08-11 03:29:57 -0700443 0);
Stone Piao2dbaf752012-09-25 20:23:35 -0700444
445 return 0;
446}
447
448/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700449 * This function processes the received packet before sending it to the
450 * kernel.
451 *
452 * It extracts the SKB from the received buffer and sends it to kernel.
453 * In case the received buffer does not contain the data in SKB format,
454 * the function creates a blank SKB, fills it with the data from the
455 * received buffer and then sends this new SKB to the kernel.
456 */
Avinash Patilf3b369e2012-10-19 19:19:21 -0700457int mwifiex_recv_packet(struct mwifiex_private *priv, struct sk_buff *skb)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700458{
Xinming Hu442f6f92015-06-03 16:59:38 +0530459 struct mwifiex_sta_node *src_node;
460 struct ethhdr *p_ethhdr;
461
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700462 if (!skb)
463 return -1;
464
Ujjal Royf49c6e82013-12-02 23:17:54 -0800465 priv->stats.rx_bytes += skb->len;
466 priv->stats.rx_packets++;
467
Xinming Hu442f6f92015-06-03 16:59:38 +0530468 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
469 p_ethhdr = (void *)skb->data;
470 src_node = mwifiex_get_sta_entry(priv, p_ethhdr->h_source);
471 if (src_node) {
472 src_node->stats.last_rx = jiffies;
473 src_node->stats.rx_bytes += skb->len;
474 src_node->stats.rx_packets++;
475 }
476 }
477
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700478 skb->dev = priv->netdev;
479 skb->protocol = eth_type_trans(skb, priv->netdev);
480 skb->ip_summed = CHECKSUM_NONE;
Amitkumar Karwar4daffe32012-04-18 20:08:28 -0700481
Avinash Patilf553e1a2013-03-04 16:27:56 -0800482 /* This is required only in case of 11n and USB/PCIE as we alloc
Amitkumar Karwar4daffe32012-04-18 20:08:28 -0700483 * a buffer of 4K only if its 11N (to be able to receive 4K
484 * AMSDU packets). In case of SD we allocate buffers based
485 * on the size of packet and hence this is not needed.
486 *
487 * Modifying the truesize here as our allocation for each
488 * skb is 4K but we only receive 2K packets and this cause
489 * the kernel to start dropping packets in case where
490 * application has allocated buffer based on 2K size i.e.
491 * if there a 64K packet received (in IP fragments and
492 * application allocates 64K to receive this packet but
493 * this packet would almost double up because we allocate
494 * each 1.5K fragment in 4K and pass it up. As soon as the
495 * 64K limit hits kernel will start to drop rest of the
496 * fragments. Currently we fail the Filesndl-ht.scr script
497 * for UDP, hence this fix
498 */
Avinash Patilf553e1a2013-03-04 16:27:56 -0800499 if ((priv->adapter->iface_type == MWIFIEX_USB ||
500 priv->adapter->iface_type == MWIFIEX_PCIE) &&
Amitkumar Karwar4daffe32012-04-18 20:08:28 -0700501 (skb->truesize > MWIFIEX_RX_DATA_BUF_SIZE))
502 skb->truesize += (skb->len - MWIFIEX_RX_DATA_BUF_SIZE);
503
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700504 if (in_interrupt())
505 netif_rx(skb);
506 else
507 netif_rx_ni(skb);
508
509 return 0;
510}
511
512/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700513 * IOCTL completion callback handler.
514 *
515 * This function is called when a pending IOCTL is completed.
516 *
517 * If work queue support is enabled, the function wakes up the
518 * corresponding waiting function. Otherwise, it processes the
519 * IOCTL response and frees the response buffer.
520 */
Amitkumar Karwarefaaa8b2011-10-12 20:28:06 -0700521int mwifiex_complete_cmd(struct mwifiex_adapter *adapter,
522 struct cmd_ctrl_node *cmd_node)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700523{
Andreas Fenkartc5bc15f2015-07-17 09:13:06 +0200524 WARN_ON(!cmd_node->wait_q_enabled);
525 mwifiex_dbg(adapter, CMD, "cmd completed: status=%d\n",
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530526 adapter->cmd_wait_q.status);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700527
Andreas Fenkartc5bc15f2015-07-17 09:13:06 +0200528 *cmd_node->condition = true;
529 wake_up_interruptible(&adapter->cmd_wait_q.wait);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700530
531 return 0;
532}
Avinash Patil4bcf93d2014-02-07 16:27:30 -0800533
534/* This function will return the pointer to station entry in station list
535 * table which matches specified mac address.
536 * This function should be called after acquiring RA list spinlock.
537 * NULL is returned if station entry is not found in associated STA list.
538 */
539struct mwifiex_sta_node *
Johannes Berg3b3a0162014-05-19 17:19:31 +0200540mwifiex_get_sta_entry(struct mwifiex_private *priv, const u8 *mac)
Avinash Patil4bcf93d2014-02-07 16:27:30 -0800541{
542 struct mwifiex_sta_node *node;
543
544 if (!mac)
545 return NULL;
546
547 list_for_each_entry(node, &priv->sta_list, list) {
548 if (!memcmp(node->mac_addr, mac, ETH_ALEN))
549 return node;
550 }
551
552 return NULL;
553}
554
Xinming Huba101ad2015-06-22 19:06:10 +0530555static struct mwifiex_sta_node *
556mwifiex_get_tdls_sta_entry(struct mwifiex_private *priv, u8 status)
557{
558 struct mwifiex_sta_node *node;
559
560 list_for_each_entry(node, &priv->sta_list, list) {
561 if (node->tdls_status == status)
562 return node;
563 }
564
565 return NULL;
566}
567
568/* If tdls channel switching is on-going, tx data traffic should be
569 * blocked until the switching stage completed.
570 */
571u8 mwifiex_is_tdls_chan_switching(struct mwifiex_private *priv)
572{
573 struct mwifiex_sta_node *sta_ptr;
574
575 if (!priv || !ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info))
576 return false;
577
578 sta_ptr = mwifiex_get_tdls_sta_entry(priv, TDLS_CHAN_SWITCHING);
579 if (sta_ptr)
580 return true;
581
582 return false;
583}
584
585u8 mwifiex_is_tdls_off_chan(struct mwifiex_private *priv)
586{
587 struct mwifiex_sta_node *sta_ptr;
588
589 if (!priv || !ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info))
590 return false;
591
592 sta_ptr = mwifiex_get_tdls_sta_entry(priv, TDLS_IN_OFF_CHAN);
593 if (sta_ptr)
594 return true;
595
596 return false;
597}
598
599/* If tdls channel switching is on-going or tdls operate on off-channel,
600 * cmd path should be blocked until tdls switched to base-channel.
601 */
602u8 mwifiex_is_send_cmd_allowed(struct mwifiex_private *priv)
603{
604 if (!priv || !ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info))
605 return true;
606
607 if (mwifiex_is_tdls_chan_switching(priv) ||
608 mwifiex_is_tdls_off_chan(priv))
609 return false;
610
611 return true;
612}
613
Avinash Patil4bcf93d2014-02-07 16:27:30 -0800614/* This function will add a sta_node entry to associated station list
615 * table with the given mac address.
616 * If entry exist already, existing entry is returned.
617 * If received mac address is NULL, NULL is returned.
618 */
619struct mwifiex_sta_node *
Johannes Berg3b3a0162014-05-19 17:19:31 +0200620mwifiex_add_sta_entry(struct mwifiex_private *priv, const u8 *mac)
Avinash Patil4bcf93d2014-02-07 16:27:30 -0800621{
622 struct mwifiex_sta_node *node;
623 unsigned long flags;
624
625 if (!mac)
626 return NULL;
627
628 spin_lock_irqsave(&priv->sta_list_spinlock, flags);
629 node = mwifiex_get_sta_entry(priv, mac);
630 if (node)
631 goto done;
632
633 node = kzalloc(sizeof(*node), GFP_ATOMIC);
634 if (!node)
635 goto done;
636
637 memcpy(node->mac_addr, mac, ETH_ALEN);
638 list_add_tail(&node->list, &priv->sta_list);
639
640done:
641 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
642 return node;
643}
644
645/* This function will search for HT IE in association request IEs
646 * and set station HT parameters accordingly.
647 */
648void
649mwifiex_set_sta_ht_cap(struct mwifiex_private *priv, const u8 *ies,
650 int ies_len, struct mwifiex_sta_node *node)
651{
Zhaoyang Liu9ab7b5b2015-04-13 21:32:25 +0530652 struct ieee_types_header *ht_cap_ie;
Avinash Patil4bcf93d2014-02-07 16:27:30 -0800653 const struct ieee80211_ht_cap *ht_cap;
654
655 if (!ies)
656 return;
657
Zhaoyang Liu9ab7b5b2015-04-13 21:32:25 +0530658 ht_cap_ie = (void *)cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies,
659 ies_len);
660 if (ht_cap_ie) {
661 ht_cap = (void *)(ht_cap_ie + 1);
Avinash Patil4bcf93d2014-02-07 16:27:30 -0800662 node->is_11n_enabled = 1;
663 node->max_amsdu = le16_to_cpu(ht_cap->cap_info) &
664 IEEE80211_HT_CAP_MAX_AMSDU ?
665 MWIFIEX_TX_DATA_BUF_SIZE_8K :
666 MWIFIEX_TX_DATA_BUF_SIZE_4K;
667 } else {
668 node->is_11n_enabled = 0;
669 }
670
671 return;
672}
673
674/* This function will delete a station entry from station list */
Johannes Berg3b3a0162014-05-19 17:19:31 +0200675void mwifiex_del_sta_entry(struct mwifiex_private *priv, const u8 *mac)
Avinash Patil4bcf93d2014-02-07 16:27:30 -0800676{
677 struct mwifiex_sta_node *node;
678 unsigned long flags;
679
680 spin_lock_irqsave(&priv->sta_list_spinlock, flags);
681
682 node = mwifiex_get_sta_entry(priv, mac);
683 if (node) {
684 list_del(&node->list);
685 kfree(node);
686 }
687
688 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
689 return;
690}
691
692/* This function will delete all stations from associated station list. */
693void mwifiex_del_all_sta_list(struct mwifiex_private *priv)
694{
695 struct mwifiex_sta_node *node, *tmp;
696 unsigned long flags;
697
698 spin_lock_irqsave(&priv->sta_list_spinlock, flags);
699
700 list_for_each_entry_safe(node, tmp, &priv->sta_list, list) {
701 list_del(&node->list);
702 kfree(node);
703 }
704
705 INIT_LIST_HEAD(&priv->sta_list);
706 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
707 return;
708}
Xinming Hucbf6e052014-12-23 19:14:07 +0530709
710/* This function adds histogram data to histogram array*/
711void mwifiex_hist_data_add(struct mwifiex_private *priv,
712 u8 rx_rate, s8 snr, s8 nflr)
713{
714 struct mwifiex_histogram_data *phist_data = priv->hist_data;
715
716 if (atomic_read(&phist_data->num_samples) > MWIFIEX_HIST_MAX_SAMPLES)
717 mwifiex_hist_data_reset(priv);
718 mwifiex_hist_data_set(priv, rx_rate, snr, nflr);
719}
720
721/* function to add histogram record */
722void mwifiex_hist_data_set(struct mwifiex_private *priv, u8 rx_rate, s8 snr,
723 s8 nflr)
724{
725 struct mwifiex_histogram_data *phist_data = priv->hist_data;
Xinming Hudb687272018-05-18 15:38:54 +0800726 s8 nf = -nflr;
727 s8 rssi = snr - nflr;
Xinming Hucbf6e052014-12-23 19:14:07 +0530728
729 atomic_inc(&phist_data->num_samples);
730 atomic_inc(&phist_data->rx_rate[rx_rate]);
Xinming Hudb687272018-05-18 15:38:54 +0800731 atomic_inc(&phist_data->snr[snr + 128]);
732 atomic_inc(&phist_data->noise_flr[nf + 128]);
733 atomic_inc(&phist_data->sig_str[rssi + 128]);
Xinming Hucbf6e052014-12-23 19:14:07 +0530734}
735
736/* function to reset histogram data during init/reset */
737void mwifiex_hist_data_reset(struct mwifiex_private *priv)
738{
739 int ix;
740 struct mwifiex_histogram_data *phist_data = priv->hist_data;
741
742 atomic_set(&phist_data->num_samples, 0);
743 for (ix = 0; ix < MWIFIEX_MAX_AC_RX_RATES; ix++)
744 atomic_set(&phist_data->rx_rate[ix], 0);
745 for (ix = 0; ix < MWIFIEX_MAX_SNR; ix++)
746 atomic_set(&phist_data->snr[ix], 0);
747 for (ix = 0; ix < MWIFIEX_MAX_NOISE_FLR; ix++)
748 atomic_set(&phist_data->noise_flr[ix], 0);
749 for (ix = 0; ix < MWIFIEX_MAX_SIG_STRENGTH; ix++)
750 atomic_set(&phist_data->sig_str[ix], 0);
751}
Avinash Patil31def912015-02-13 17:41:08 +0530752
Avinash Patil62159942015-03-13 17:37:52 +0530753void *mwifiex_alloc_dma_align_buf(int rx_len, gfp_t flags)
Avinash Patil31def912015-02-13 17:41:08 +0530754{
755 struct sk_buff *skb;
756 int buf_len, pad;
757
758 buf_len = rx_len + MWIFIEX_RX_HEADROOM + MWIFIEX_DMA_ALIGN_SZ;
759
760 skb = __dev_alloc_skb(buf_len, flags);
761
762 if (!skb)
763 return NULL;
764
765 skb_reserve(skb, MWIFIEX_RX_HEADROOM);
766
767 pad = MWIFIEX_ALIGN_ADDR(skb->data, MWIFIEX_DMA_ALIGN_SZ) -
768 (long)skb->data;
769
770 skb_reserve(skb, pad);
771
772 return skb;
773}
Avinash Patil62159942015-03-13 17:37:52 +0530774EXPORT_SYMBOL_GPL(mwifiex_alloc_dma_align_buf);