Commit | Line | Data |
---|---|---|
5e6e3a92 BZ |
1 | /* |
2 | * Marvell Wireless LAN device driver: utility functions | |
3 | * | |
65da33f5 | 4 | * Copyright (C) 2011-2014, Marvell International Ltd. |
5e6e3a92 BZ |
5 | * |
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 | ||
bb5097fe | 28 | static struct mwifiex_debug_data items[] = { |
c687a007 ZL |
29 | {"debug_mask", item_size(debug_mask), |
30 | item_addr(debug_mask), 1}, | |
bb5097fe XH |
31 | {"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}, | |
81 | {"num_cmd_h2c_fail", item_size(num_cmd_host_to_card_failure), | |
82 | item_addr(num_cmd_host_to_card_failure), 1}, | |
83 | {"num_cmd_sleep_cfm_fail", | |
84 | item_size(num_cmd_sleep_cfm_host_to_card_failure), | |
85 | item_addr(num_cmd_sleep_cfm_host_to_card_failure), 1}, | |
86 | {"num_tx_h2c_fail", item_size(num_tx_host_to_card_failure), | |
87 | item_addr(num_tx_host_to_card_failure), 1}, | |
88 | {"num_evt_deauth", item_size(num_event_deauth), | |
89 | item_addr(num_event_deauth), 1}, | |
90 | {"num_evt_disassoc", item_size(num_event_disassoc), | |
91 | item_addr(num_event_disassoc), 1}, | |
92 | {"num_evt_link_lost", item_size(num_event_link_lost), | |
93 | item_addr(num_event_link_lost), 1}, | |
94 | {"num_cmd_deauth", item_size(num_cmd_deauth), | |
95 | item_addr(num_cmd_deauth), 1}, | |
96 | {"num_cmd_assoc_ok", item_size(num_cmd_assoc_success), | |
97 | item_addr(num_cmd_assoc_success), 1}, | |
98 | {"num_cmd_assoc_fail", item_size(num_cmd_assoc_failure), | |
99 | item_addr(num_cmd_assoc_failure), 1}, | |
100 | {"cmd_sent", item_size(cmd_sent), | |
101 | item_addr(cmd_sent), 1}, | |
102 | {"data_sent", item_size(data_sent), | |
103 | item_addr(data_sent), 1}, | |
104 | {"cmd_resp_received", item_size(cmd_resp_received), | |
105 | item_addr(cmd_resp_received), 1}, | |
106 | {"event_received", item_size(event_received), | |
107 | item_addr(event_received), 1}, | |
108 | ||
109 | /* variables defined in struct mwifiex_adapter */ | |
110 | {"cmd_pending", adapter_item_size(cmd_pending), | |
111 | adapter_item_addr(cmd_pending), 1}, | |
112 | {"tx_pending", adapter_item_size(tx_pending), | |
113 | adapter_item_addr(tx_pending), 1}, | |
114 | {"rx_pending", adapter_item_size(rx_pending), | |
115 | adapter_item_addr(rx_pending), 1}, | |
116 | }; | |
117 | ||
118 | static int num_of_items = ARRAY_SIZE(items); | |
119 | ||
5e6e3a92 BZ |
120 | /* |
121 | * Firmware initialization complete callback handler. | |
122 | * | |
123 | * This function wakes up the function waiting on the init | |
124 | * wait queue for the firmware initialization to complete. | |
125 | */ | |
126 | int mwifiex_init_fw_complete(struct mwifiex_adapter *adapter) | |
127 | { | |
128 | ||
39875099 ZL |
129 | if (adapter->hw_status == MWIFIEX_HW_STATUS_READY) |
130 | if (adapter->if_ops.init_fw_port) | |
131 | adapter->if_ops.init_fw_port(adapter); | |
132 | ||
5e6e3a92 BZ |
133 | adapter->init_wait_q_woken = true; |
134 | wake_up_interruptible(&adapter->init_wait_q); | |
135 | return 0; | |
136 | } | |
137 | ||
138 | /* | |
139 | * Firmware shutdown complete callback handler. | |
140 | * | |
141 | * This function sets the hardware status to not ready and wakes up | |
142 | * the function waiting on the init wait queue for the firmware | |
143 | * shutdown to complete. | |
144 | */ | |
145 | int mwifiex_shutdown_fw_complete(struct mwifiex_adapter *adapter) | |
146 | { | |
147 | adapter->hw_status = MWIFIEX_HW_STATUS_NOT_READY; | |
148 | adapter->init_wait_q_woken = true; | |
149 | wake_up_interruptible(&adapter->init_wait_q); | |
150 | return 0; | |
151 | } | |
152 | ||
153 | /* | |
600f5d90 | 154 | * This function sends init/shutdown command |
5e6e3a92 | 155 | * to firmware. |
5e6e3a92 | 156 | */ |
600f5d90 AK |
157 | int mwifiex_init_shutdown_fw(struct mwifiex_private *priv, |
158 | u32 func_init_shutdown) | |
5e6e3a92 | 159 | { |
5e6e3a92 BZ |
160 | u16 cmd; |
161 | ||
162 | if (func_init_shutdown == MWIFIEX_FUNC_INIT) { | |
163 | cmd = HostCmd_CMD_FUNC_INIT; | |
164 | } else if (func_init_shutdown == MWIFIEX_FUNC_SHUTDOWN) { | |
165 | cmd = HostCmd_CMD_FUNC_SHUTDOWN; | |
166 | } else { | |
acebe8c1 ZL |
167 | mwifiex_dbg(priv->adapter, ERROR, |
168 | "unsupported parameter\n"); | |
5e6e3a92 BZ |
169 | return -1; |
170 | } | |
171 | ||
fa0ecbb9 | 172 | return mwifiex_send_cmd(priv, cmd, HostCmd_ACT_GEN_SET, 0, NULL, true); |
5e6e3a92 | 173 | } |
600f5d90 | 174 | EXPORT_SYMBOL_GPL(mwifiex_init_shutdown_fw); |
5e6e3a92 BZ |
175 | |
176 | /* | |
177 | * IOCTL request handler to set/get debug information. | |
178 | * | |
179 | * This function collates/sets the information from/to different driver | |
180 | * structures. | |
181 | */ | |
182 | int mwifiex_get_debug_info(struct mwifiex_private *priv, | |
183 | struct mwifiex_debug_info *info) | |
184 | { | |
185 | struct mwifiex_adapter *adapter = priv->adapter; | |
186 | ||
187 | if (info) { | |
c687a007 | 188 | info->debug_mask = adapter->debug_mask; |
5e6e3a92 BZ |
189 | memcpy(info->packets_out, |
190 | priv->wmm.packets_out, | |
191 | sizeof(priv->wmm.packets_out)); | |
5e3175fb | 192 | info->curr_tx_buf_size = (u32) adapter->curr_tx_buf_size; |
5e6e3a92 | 193 | info->tx_buf_size = (u32) adapter->tx_buf_size; |
c65a30f3 YAP |
194 | info->rx_tbl_num = mwifiex_get_rx_reorder_tbl(priv, |
195 | info->rx_tbl); | |
196 | info->tx_tbl_num = mwifiex_get_tx_ba_stream_tbl(priv, | |
197 | info->tx_tbl); | |
72df6310 XH |
198 | info->tdls_peer_num = mwifiex_get_tdls_list(priv, |
199 | info->tdls_list); | |
5e6e3a92 BZ |
200 | info->ps_mode = adapter->ps_mode; |
201 | info->ps_state = adapter->ps_state; | |
202 | info->is_deep_sleep = adapter->is_deep_sleep; | |
203 | info->pm_wakeup_card_req = adapter->pm_wakeup_card_req; | |
204 | info->pm_wakeup_fw_try = adapter->pm_wakeup_fw_try; | |
205 | info->is_hs_configured = adapter->is_hs_configured; | |
206 | info->hs_activated = adapter->hs_activated; | |
0c9c4a09 | 207 | info->is_cmd_timedout = adapter->is_cmd_timedout; |
5e6e3a92 | 208 | info->num_cmd_host_to_card_failure |
c65a30f3 | 209 | = adapter->dbg.num_cmd_host_to_card_failure; |
5e6e3a92 BZ |
210 | info->num_cmd_sleep_cfm_host_to_card_failure |
211 | = adapter->dbg.num_cmd_sleep_cfm_host_to_card_failure; | |
212 | info->num_tx_host_to_card_failure | |
c65a30f3 | 213 | = adapter->dbg.num_tx_host_to_card_failure; |
5e6e3a92 BZ |
214 | info->num_event_deauth = adapter->dbg.num_event_deauth; |
215 | info->num_event_disassoc = adapter->dbg.num_event_disassoc; | |
216 | info->num_event_link_lost = adapter->dbg.num_event_link_lost; | |
217 | info->num_cmd_deauth = adapter->dbg.num_cmd_deauth; | |
218 | info->num_cmd_assoc_success = | |
c65a30f3 | 219 | adapter->dbg.num_cmd_assoc_success; |
5e6e3a92 | 220 | info->num_cmd_assoc_failure = |
c65a30f3 | 221 | adapter->dbg.num_cmd_assoc_failure; |
5e6e3a92 | 222 | info->num_tx_timeout = adapter->dbg.num_tx_timeout; |
5e6e3a92 BZ |
223 | info->timeout_cmd_id = adapter->dbg.timeout_cmd_id; |
224 | info->timeout_cmd_act = adapter->dbg.timeout_cmd_act; | |
225 | memcpy(info->last_cmd_id, adapter->dbg.last_cmd_id, | |
226 | sizeof(adapter->dbg.last_cmd_id)); | |
227 | memcpy(info->last_cmd_act, adapter->dbg.last_cmd_act, | |
228 | sizeof(adapter->dbg.last_cmd_act)); | |
229 | info->last_cmd_index = adapter->dbg.last_cmd_index; | |
230 | memcpy(info->last_cmd_resp_id, adapter->dbg.last_cmd_resp_id, | |
231 | sizeof(adapter->dbg.last_cmd_resp_id)); | |
232 | info->last_cmd_resp_index = adapter->dbg.last_cmd_resp_index; | |
233 | memcpy(info->last_event, adapter->dbg.last_event, | |
234 | sizeof(adapter->dbg.last_event)); | |
235 | info->last_event_index = adapter->dbg.last_event_index; | |
236 | info->data_sent = adapter->data_sent; | |
237 | info->cmd_sent = adapter->cmd_sent; | |
238 | info->cmd_resp_received = adapter->cmd_resp_received; | |
239 | } | |
240 | ||
241 | return 0; | |
242 | } | |
243 | ||
bb5097fe XH |
244 | int mwifiex_debug_info_to_buffer(struct mwifiex_private *priv, char *buf, |
245 | struct mwifiex_debug_info *info) | |
246 | { | |
247 | char *p = buf; | |
248 | struct mwifiex_debug_data *d = &items[0]; | |
249 | size_t size, addr; | |
250 | long val; | |
251 | int i, j; | |
252 | ||
253 | if (!info) | |
254 | return 0; | |
255 | ||
256 | for (i = 0; i < num_of_items; i++) { | |
257 | p += sprintf(p, "%s=", d[i].name); | |
258 | ||
259 | size = d[i].size / d[i].num; | |
260 | ||
261 | if (i < (num_of_items - 3)) | |
262 | addr = d[i].addr + (size_t)info; | |
263 | else /* The last 3 items are struct mwifiex_adapter variables */ | |
264 | addr = d[i].addr + (size_t)priv->adapter; | |
265 | ||
266 | for (j = 0; j < d[i].num; j++) { | |
267 | switch (size) { | |
268 | case 1: | |
269 | val = *((u8 *)addr); | |
270 | break; | |
271 | case 2: | |
272 | val = *((u16 *)addr); | |
273 | break; | |
274 | case 4: | |
275 | val = *((u32 *)addr); | |
276 | break; | |
277 | case 8: | |
278 | val = *((long long *)addr); | |
279 | break; | |
280 | default: | |
281 | val = -1; | |
282 | break; | |
283 | } | |
284 | ||
285 | p += sprintf(p, "%#lx ", val); | |
286 | addr += size; | |
287 | } | |
288 | ||
289 | p += sprintf(p, "\n"); | |
290 | } | |
291 | ||
292 | if (info->tx_tbl_num) { | |
293 | p += sprintf(p, "Tx BA stream table:\n"); | |
294 | for (i = 0; i < info->tx_tbl_num; i++) | |
295 | p += sprintf(p, "tid = %d, ra = %pM\n", | |
296 | info->tx_tbl[i].tid, info->tx_tbl[i].ra); | |
297 | } | |
298 | ||
299 | if (info->rx_tbl_num) { | |
300 | p += sprintf(p, "Rx reorder table:\n"); | |
301 | for (i = 0; i < info->rx_tbl_num; i++) { | |
302 | p += sprintf(p, "tid = %d, ta = %pM, ", | |
303 | info->rx_tbl[i].tid, | |
304 | info->rx_tbl[i].ta); | |
305 | p += sprintf(p, "start_win = %d, ", | |
306 | info->rx_tbl[i].start_win); | |
307 | p += sprintf(p, "win_size = %d, buffer: ", | |
308 | info->rx_tbl[i].win_size); | |
309 | ||
310 | for (j = 0; j < info->rx_tbl[i].win_size; j++) | |
311 | p += sprintf(p, "%c ", | |
312 | info->rx_tbl[i].buffer[j] ? | |
313 | '1' : '0'); | |
314 | ||
315 | p += sprintf(p, "\n"); | |
316 | } | |
317 | } | |
318 | ||
319 | if (info->tdls_peer_num) { | |
320 | p += sprintf(p, "TDLS peer table:\n"); | |
321 | for (i = 0; i < info->tdls_peer_num; i++) { | |
322 | p += sprintf(p, "peer = %pM", | |
323 | info->tdls_list[i].peer_addr); | |
324 | p += sprintf(p, "\n"); | |
325 | } | |
326 | } | |
327 | ||
328 | return p - buf; | |
329 | } | |
330 | ||
72e5aa8d AP |
331 | static int |
332 | mwifiex_parse_mgmt_packet(struct mwifiex_private *priv, u8 *payload, u16 len, | |
333 | struct rxpd *rx_pd) | |
334 | { | |
335 | u16 stype; | |
3e6f8a4b | 336 | u8 category, action_code, *addr2; |
72e5aa8d AP |
337 | struct ieee80211_hdr *ieee_hdr = (void *)payload; |
338 | ||
51974611 | 339 | stype = (le16_to_cpu(ieee_hdr->frame_control) & IEEE80211_FCTL_STYPE); |
72e5aa8d AP |
340 | |
341 | switch (stype) { | |
342 | case IEEE80211_STYPE_ACTION: | |
343 | category = *(payload + sizeof(struct ieee80211_hdr)); | |
3e6f8a4b AP |
344 | switch (category) { |
345 | case WLAN_CATEGORY_PUBLIC: | |
346 | action_code = *(payload + sizeof(struct ieee80211_hdr) | |
347 | + 1); | |
348 | if (action_code == WLAN_PUB_ACTION_TDLS_DISCOVER_RES) { | |
349 | addr2 = ieee_hdr->addr2; | |
350 | mwifiex_dbg(priv->adapter, INFO, | |
351 | "TDLS discovery response %pM nf=%d, snr=%d\n", | |
352 | addr2, rx_pd->nf, rx_pd->snr); | |
353 | mwifiex_auto_tdls_update_peer_signal(priv, | |
354 | addr2, | |
355 | rx_pd->snr, | |
356 | rx_pd->nf); | |
357 | } | |
358 | break; | |
359 | case WLAN_CATEGORY_BACK: | |
360 | /*we dont indicate BACK action frames to cfg80211*/ | |
361 | mwifiex_dbg(priv->adapter, INFO, | |
362 | "drop BACK action frames"); | |
363 | return -1; | |
364 | default: | |
acebe8c1 | 365 | mwifiex_dbg(priv->adapter, INFO, |
3e6f8a4b AP |
366 | "unknown public action frame category %d\n", |
367 | category); | |
72e5aa8d | 368 | } |
72e5aa8d | 369 | default: |
ec21dc4a | 370 | mwifiex_dbg(priv->adapter, INFO, |
3e6f8a4b AP |
371 | "unknown mgmt frame subtype %#x\n", stype); |
372 | return 0; | |
72e5aa8d AP |
373 | } |
374 | ||
375 | return 0; | |
376 | } | |
2dbaf751 SP |
377 | /* |
378 | * This function processes the received management packet and send it | |
379 | * to the kernel. | |
380 | */ | |
381 | int | |
f3b369e4 | 382 | mwifiex_process_mgmt_packet(struct mwifiex_private *priv, |
2dbaf751 SP |
383 | struct sk_buff *skb) |
384 | { | |
385 | struct rxpd *rx_pd; | |
2dbaf751 | 386 | u16 pkt_len; |
72e5aa8d | 387 | struct ieee80211_hdr *ieee_hdr; |
2dbaf751 SP |
388 | |
389 | if (!skb) | |
390 | return -1; | |
391 | ||
7521ce6e AP |
392 | if (!priv->mgmt_frame_mask || |
393 | priv->wdev.iftype == NL80211_IFTYPE_UNSPECIFIED) { | |
acebe8c1 ZL |
394 | mwifiex_dbg(priv->adapter, ERROR, |
395 | "do not receive mgmt frames on uninitialized intf"); | |
7521ce6e AP |
396 | return -1; |
397 | } | |
398 | ||
2dbaf751 | 399 | rx_pd = (struct rxpd *)skb->data; |
2dbaf751 SP |
400 | |
401 | skb_pull(skb, le16_to_cpu(rx_pd->rx_pkt_offset)); | |
402 | skb_pull(skb, sizeof(pkt_len)); | |
403 | ||
404 | pkt_len = le16_to_cpu(rx_pd->rx_pkt_length); | |
405 | ||
72e5aa8d AP |
406 | ieee_hdr = (void *)skb->data; |
407 | if (ieee80211_is_mgmt(ieee_hdr->frame_control)) { | |
3e6f8a4b AP |
408 | if (mwifiex_parse_mgmt_packet(priv, (u8 *)ieee_hdr, |
409 | pkt_len, rx_pd)) | |
410 | return -1; | |
72e5aa8d | 411 | } |
2dbaf751 SP |
412 | /* Remove address4 */ |
413 | memmove(skb->data + sizeof(struct ieee80211_hdr_3addr), | |
414 | skb->data + sizeof(struct ieee80211_hdr), | |
415 | pkt_len - sizeof(struct ieee80211_hdr)); | |
416 | ||
417 | pkt_len -= ETH_ALEN + sizeof(pkt_len); | |
418 | rx_pd->rx_pkt_length = cpu_to_le16(pkt_len); | |
419 | ||
4facc34a | 420 | cfg80211_rx_mgmt(&priv->wdev, priv->roc_cfg.chan.center_freq, |
19504cf5 | 421 | CAL_RSSI(rx_pd->snr, rx_pd->nf), skb->data, pkt_len, |
970fdfa8 | 422 | 0); |
2dbaf751 SP |
423 | |
424 | return 0; | |
425 | } | |
426 | ||
5e6e3a92 BZ |
427 | /* |
428 | * This function processes the received packet before sending it to the | |
429 | * kernel. | |
430 | * | |
431 | * It extracts the SKB from the received buffer and sends it to kernel. | |
432 | * In case the received buffer does not contain the data in SKB format, | |
433 | * the function creates a blank SKB, fills it with the data from the | |
434 | * received buffer and then sends this new SKB to the kernel. | |
435 | */ | |
f3b369e4 | 436 | int mwifiex_recv_packet(struct mwifiex_private *priv, struct sk_buff *skb) |
5e6e3a92 | 437 | { |
442f6f9b XH |
438 | struct mwifiex_sta_node *src_node; |
439 | struct ethhdr *p_ethhdr; | |
440 | ||
5e6e3a92 BZ |
441 | if (!skb) |
442 | return -1; | |
443 | ||
f49c6e81 UR |
444 | priv->stats.rx_bytes += skb->len; |
445 | priv->stats.rx_packets++; | |
446 | ||
442f6f9b XH |
447 | if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) { |
448 | p_ethhdr = (void *)skb->data; | |
449 | src_node = mwifiex_get_sta_entry(priv, p_ethhdr->h_source); | |
450 | if (src_node) { | |
451 | src_node->stats.last_rx = jiffies; | |
452 | src_node->stats.rx_bytes += skb->len; | |
453 | src_node->stats.rx_packets++; | |
454 | } | |
455 | } | |
456 | ||
5e6e3a92 BZ |
457 | skb->dev = priv->netdev; |
458 | skb->protocol = eth_type_trans(skb, priv->netdev); | |
459 | skb->ip_summed = CHECKSUM_NONE; | |
4daffe35 | 460 | |
f553e1aa | 461 | /* This is required only in case of 11n and USB/PCIE as we alloc |
4daffe35 AK |
462 | * a buffer of 4K only if its 11N (to be able to receive 4K |
463 | * AMSDU packets). In case of SD we allocate buffers based | |
464 | * on the size of packet and hence this is not needed. | |
465 | * | |
466 | * Modifying the truesize here as our allocation for each | |
467 | * skb is 4K but we only receive 2K packets and this cause | |
468 | * the kernel to start dropping packets in case where | |
469 | * application has allocated buffer based on 2K size i.e. | |
470 | * if there a 64K packet received (in IP fragments and | |
471 | * application allocates 64K to receive this packet but | |
472 | * this packet would almost double up because we allocate | |
473 | * each 1.5K fragment in 4K and pass it up. As soon as the | |
474 | * 64K limit hits kernel will start to drop rest of the | |
475 | * fragments. Currently we fail the Filesndl-ht.scr script | |
476 | * for UDP, hence this fix | |
477 | */ | |
f553e1aa AP |
478 | if ((priv->adapter->iface_type == MWIFIEX_USB || |
479 | priv->adapter->iface_type == MWIFIEX_PCIE) && | |
4daffe35 AK |
480 | (skb->truesize > MWIFIEX_RX_DATA_BUF_SIZE)) |
481 | skb->truesize += (skb->len - MWIFIEX_RX_DATA_BUF_SIZE); | |
482 | ||
5e6e3a92 BZ |
483 | if (in_interrupt()) |
484 | netif_rx(skb); | |
485 | else | |
486 | netif_rx_ni(skb); | |
487 | ||
488 | return 0; | |
489 | } | |
490 | ||
5e6e3a92 BZ |
491 | /* |
492 | * IOCTL completion callback handler. | |
493 | * | |
494 | * This function is called when a pending IOCTL is completed. | |
495 | * | |
496 | * If work queue support is enabled, the function wakes up the | |
497 | * corresponding waiting function. Otherwise, it processes the | |
498 | * IOCTL response and frees the response buffer. | |
499 | */ | |
efaaa8b8 AK |
500 | int mwifiex_complete_cmd(struct mwifiex_adapter *adapter, |
501 | struct cmd_ctrl_node *cmd_node) | |
5e6e3a92 | 502 | { |
c5bc15fc AF |
503 | WARN_ON(!cmd_node->wait_q_enabled); |
504 | mwifiex_dbg(adapter, CMD, "cmd completed: status=%d\n", | |
acebe8c1 | 505 | adapter->cmd_wait_q.status); |
5e6e3a92 | 506 | |
c5bc15fc AF |
507 | *cmd_node->condition = true; |
508 | wake_up_interruptible(&adapter->cmd_wait_q.wait); | |
5e6e3a92 BZ |
509 | |
510 | return 0; | |
511 | } | |
4bcf93d3 AP |
512 | |
513 | /* This function will return the pointer to station entry in station list | |
514 | * table which matches specified mac address. | |
515 | * This function should be called after acquiring RA list spinlock. | |
516 | * NULL is returned if station entry is not found in associated STA list. | |
517 | */ | |
518 | struct mwifiex_sta_node * | |
3b3a0162 | 519 | mwifiex_get_sta_entry(struct mwifiex_private *priv, const u8 *mac) |
4bcf93d3 AP |
520 | { |
521 | struct mwifiex_sta_node *node; | |
522 | ||
523 | if (!mac) | |
524 | return NULL; | |
525 | ||
526 | list_for_each_entry(node, &priv->sta_list, list) { | |
527 | if (!memcmp(node->mac_addr, mac, ETH_ALEN)) | |
528 | return node; | |
529 | } | |
530 | ||
531 | return NULL; | |
532 | } | |
533 | ||
ba101ad5 XH |
534 | static struct mwifiex_sta_node * |
535 | mwifiex_get_tdls_sta_entry(struct mwifiex_private *priv, u8 status) | |
536 | { | |
537 | struct mwifiex_sta_node *node; | |
538 | ||
539 | list_for_each_entry(node, &priv->sta_list, list) { | |
540 | if (node->tdls_status == status) | |
541 | return node; | |
542 | } | |
543 | ||
544 | return NULL; | |
545 | } | |
546 | ||
547 | /* If tdls channel switching is on-going, tx data traffic should be | |
548 | * blocked until the switching stage completed. | |
549 | */ | |
550 | u8 mwifiex_is_tdls_chan_switching(struct mwifiex_private *priv) | |
551 | { | |
552 | struct mwifiex_sta_node *sta_ptr; | |
553 | ||
554 | if (!priv || !ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info)) | |
555 | return false; | |
556 | ||
557 | sta_ptr = mwifiex_get_tdls_sta_entry(priv, TDLS_CHAN_SWITCHING); | |
558 | if (sta_ptr) | |
559 | return true; | |
560 | ||
561 | return false; | |
562 | } | |
563 | ||
564 | u8 mwifiex_is_tdls_off_chan(struct mwifiex_private *priv) | |
565 | { | |
566 | struct mwifiex_sta_node *sta_ptr; | |
567 | ||
568 | if (!priv || !ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info)) | |
569 | return false; | |
570 | ||
571 | sta_ptr = mwifiex_get_tdls_sta_entry(priv, TDLS_IN_OFF_CHAN); | |
572 | if (sta_ptr) | |
573 | return true; | |
574 | ||
575 | return false; | |
576 | } | |
577 | ||
578 | /* If tdls channel switching is on-going or tdls operate on off-channel, | |
579 | * cmd path should be blocked until tdls switched to base-channel. | |
580 | */ | |
581 | u8 mwifiex_is_send_cmd_allowed(struct mwifiex_private *priv) | |
582 | { | |
583 | if (!priv || !ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info)) | |
584 | return true; | |
585 | ||
586 | if (mwifiex_is_tdls_chan_switching(priv) || | |
587 | mwifiex_is_tdls_off_chan(priv)) | |
588 | return false; | |
589 | ||
590 | return true; | |
591 | } | |
592 | ||
4bcf93d3 AP |
593 | /* This function will add a sta_node entry to associated station list |
594 | * table with the given mac address. | |
595 | * If entry exist already, existing entry is returned. | |
596 | * If received mac address is NULL, NULL is returned. | |
597 | */ | |
598 | struct mwifiex_sta_node * | |
3b3a0162 | 599 | mwifiex_add_sta_entry(struct mwifiex_private *priv, const u8 *mac) |
4bcf93d3 AP |
600 | { |
601 | struct mwifiex_sta_node *node; | |
602 | unsigned long flags; | |
603 | ||
604 | if (!mac) | |
605 | return NULL; | |
606 | ||
607 | spin_lock_irqsave(&priv->sta_list_spinlock, flags); | |
608 | node = mwifiex_get_sta_entry(priv, mac); | |
609 | if (node) | |
610 | goto done; | |
611 | ||
612 | node = kzalloc(sizeof(*node), GFP_ATOMIC); | |
613 | if (!node) | |
614 | goto done; | |
615 | ||
616 | memcpy(node->mac_addr, mac, ETH_ALEN); | |
617 | list_add_tail(&node->list, &priv->sta_list); | |
618 | ||
619 | done: | |
620 | spin_unlock_irqrestore(&priv->sta_list_spinlock, flags); | |
621 | return node; | |
622 | } | |
623 | ||
624 | /* This function will search for HT IE in association request IEs | |
625 | * and set station HT parameters accordingly. | |
626 | */ | |
627 | void | |
628 | mwifiex_set_sta_ht_cap(struct mwifiex_private *priv, const u8 *ies, | |
629 | int ies_len, struct mwifiex_sta_node *node) | |
630 | { | |
9ab7b5b9 | 631 | struct ieee_types_header *ht_cap_ie; |
4bcf93d3 AP |
632 | const struct ieee80211_ht_cap *ht_cap; |
633 | ||
634 | if (!ies) | |
635 | return; | |
636 | ||
9ab7b5b9 ZL |
637 | ht_cap_ie = (void *)cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies, |
638 | ies_len); | |
639 | if (ht_cap_ie) { | |
640 | ht_cap = (void *)(ht_cap_ie + 1); | |
4bcf93d3 AP |
641 | node->is_11n_enabled = 1; |
642 | node->max_amsdu = le16_to_cpu(ht_cap->cap_info) & | |
643 | IEEE80211_HT_CAP_MAX_AMSDU ? | |
644 | MWIFIEX_TX_DATA_BUF_SIZE_8K : | |
645 | MWIFIEX_TX_DATA_BUF_SIZE_4K; | |
646 | } else { | |
647 | node->is_11n_enabled = 0; | |
648 | } | |
649 | ||
650 | return; | |
651 | } | |
652 | ||
653 | /* This function will delete a station entry from station list */ | |
3b3a0162 | 654 | void mwifiex_del_sta_entry(struct mwifiex_private *priv, const u8 *mac) |
4bcf93d3 AP |
655 | { |
656 | struct mwifiex_sta_node *node; | |
657 | unsigned long flags; | |
658 | ||
659 | spin_lock_irqsave(&priv->sta_list_spinlock, flags); | |
660 | ||
661 | node = mwifiex_get_sta_entry(priv, mac); | |
662 | if (node) { | |
663 | list_del(&node->list); | |
664 | kfree(node); | |
665 | } | |
666 | ||
667 | spin_unlock_irqrestore(&priv->sta_list_spinlock, flags); | |
668 | return; | |
669 | } | |
670 | ||
671 | /* This function will delete all stations from associated station list. */ | |
672 | void mwifiex_del_all_sta_list(struct mwifiex_private *priv) | |
673 | { | |
674 | struct mwifiex_sta_node *node, *tmp; | |
675 | unsigned long flags; | |
676 | ||
677 | spin_lock_irqsave(&priv->sta_list_spinlock, flags); | |
678 | ||
679 | list_for_each_entry_safe(node, tmp, &priv->sta_list, list) { | |
680 | list_del(&node->list); | |
681 | kfree(node); | |
682 | } | |
683 | ||
684 | INIT_LIST_HEAD(&priv->sta_list); | |
685 | spin_unlock_irqrestore(&priv->sta_list_spinlock, flags); | |
686 | return; | |
687 | } | |
cbf6e055 XH |
688 | |
689 | /* This function adds histogram data to histogram array*/ | |
690 | void mwifiex_hist_data_add(struct mwifiex_private *priv, | |
691 | u8 rx_rate, s8 snr, s8 nflr) | |
692 | { | |
693 | struct mwifiex_histogram_data *phist_data = priv->hist_data; | |
694 | ||
695 | if (atomic_read(&phist_data->num_samples) > MWIFIEX_HIST_MAX_SAMPLES) | |
696 | mwifiex_hist_data_reset(priv); | |
697 | mwifiex_hist_data_set(priv, rx_rate, snr, nflr); | |
698 | } | |
699 | ||
700 | /* function to add histogram record */ | |
701 | void mwifiex_hist_data_set(struct mwifiex_private *priv, u8 rx_rate, s8 snr, | |
702 | s8 nflr) | |
703 | { | |
704 | struct mwifiex_histogram_data *phist_data = priv->hist_data; | |
705 | ||
706 | atomic_inc(&phist_data->num_samples); | |
707 | atomic_inc(&phist_data->rx_rate[rx_rate]); | |
708 | atomic_inc(&phist_data->snr[snr]); | |
709 | atomic_inc(&phist_data->noise_flr[128 + nflr]); | |
710 | atomic_inc(&phist_data->sig_str[nflr - snr]); | |
711 | } | |
712 | ||
713 | /* function to reset histogram data during init/reset */ | |
714 | void mwifiex_hist_data_reset(struct mwifiex_private *priv) | |
715 | { | |
716 | int ix; | |
717 | struct mwifiex_histogram_data *phist_data = priv->hist_data; | |
718 | ||
719 | atomic_set(&phist_data->num_samples, 0); | |
720 | for (ix = 0; ix < MWIFIEX_MAX_AC_RX_RATES; ix++) | |
721 | atomic_set(&phist_data->rx_rate[ix], 0); | |
722 | for (ix = 0; ix < MWIFIEX_MAX_SNR; ix++) | |
723 | atomic_set(&phist_data->snr[ix], 0); | |
724 | for (ix = 0; ix < MWIFIEX_MAX_NOISE_FLR; ix++) | |
725 | atomic_set(&phist_data->noise_flr[ix], 0); | |
726 | for (ix = 0; ix < MWIFIEX_MAX_SIG_STRENGTH; ix++) | |
727 | atomic_set(&phist_data->sig_str[ix], 0); | |
728 | } | |
31def91b | 729 | |
62159944 | 730 | void *mwifiex_alloc_dma_align_buf(int rx_len, gfp_t flags) |
31def91b AP |
731 | { |
732 | struct sk_buff *skb; | |
733 | int buf_len, pad; | |
734 | ||
735 | buf_len = rx_len + MWIFIEX_RX_HEADROOM + MWIFIEX_DMA_ALIGN_SZ; | |
736 | ||
737 | skb = __dev_alloc_skb(buf_len, flags); | |
738 | ||
739 | if (!skb) | |
740 | return NULL; | |
741 | ||
742 | skb_reserve(skb, MWIFIEX_RX_HEADROOM); | |
743 | ||
744 | pad = MWIFIEX_ALIGN_ADDR(skb->data, MWIFIEX_DMA_ALIGN_SZ) - | |
745 | (long)skb->data; | |
746 | ||
747 | skb_reserve(skb, pad); | |
748 | ||
749 | return skb; | |
750 | } | |
62159944 | 751 | EXPORT_SYMBOL_GPL(mwifiex_alloc_dma_align_buf); |