mwifiex: add prints debug ctrl support
[deliverable/linux.git] / drivers / net / wireless / mwifiex / util.c
1 /*
2 * Marvell Wireless LAN device driver: utility functions
3 *
4 * Copyright (C) 2011-2014, Marvell International Ltd.
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
28 static struct mwifiex_debug_data items[] = {
29 {"debug_mask", item_size(debug_mask),
30 item_addr(debug_mask), 1},
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
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
129 adapter->init_wait_q_woken = true;
130 wake_up_interruptible(&adapter->init_wait_q);
131 return 0;
132 }
133
134 /*
135 * Firmware shutdown complete callback handler.
136 *
137 * This function sets the hardware status to not ready and wakes up
138 * the function waiting on the init wait queue for the firmware
139 * shutdown to complete.
140 */
141 int mwifiex_shutdown_fw_complete(struct mwifiex_adapter *adapter)
142 {
143 adapter->hw_status = MWIFIEX_HW_STATUS_NOT_READY;
144 adapter->init_wait_q_woken = true;
145 wake_up_interruptible(&adapter->init_wait_q);
146 return 0;
147 }
148
149 /*
150 * This function sends init/shutdown command
151 * to firmware.
152 */
153 int mwifiex_init_shutdown_fw(struct mwifiex_private *priv,
154 u32 func_init_shutdown)
155 {
156 u16 cmd;
157
158 if (func_init_shutdown == MWIFIEX_FUNC_INIT) {
159 cmd = HostCmd_CMD_FUNC_INIT;
160 } else if (func_init_shutdown == MWIFIEX_FUNC_SHUTDOWN) {
161 cmd = HostCmd_CMD_FUNC_SHUTDOWN;
162 } else {
163 dev_err(priv->adapter->dev, "unsupported parameter\n");
164 return -1;
165 }
166
167 return mwifiex_send_cmd(priv, cmd, HostCmd_ACT_GEN_SET, 0, NULL, true);
168 }
169 EXPORT_SYMBOL_GPL(mwifiex_init_shutdown_fw);
170
171 /*
172 * IOCTL request handler to set/get debug information.
173 *
174 * This function collates/sets the information from/to different driver
175 * structures.
176 */
177 int mwifiex_get_debug_info(struct mwifiex_private *priv,
178 struct mwifiex_debug_info *info)
179 {
180 struct mwifiex_adapter *adapter = priv->adapter;
181
182 if (info) {
183 info->debug_mask = adapter->debug_mask;
184 memcpy(info->packets_out,
185 priv->wmm.packets_out,
186 sizeof(priv->wmm.packets_out));
187 info->curr_tx_buf_size = (u32) adapter->curr_tx_buf_size;
188 info->tx_buf_size = (u32) adapter->tx_buf_size;
189 info->rx_tbl_num = mwifiex_get_rx_reorder_tbl(priv,
190 info->rx_tbl);
191 info->tx_tbl_num = mwifiex_get_tx_ba_stream_tbl(priv,
192 info->tx_tbl);
193 info->tdls_peer_num = mwifiex_get_tdls_list(priv,
194 info->tdls_list);
195 info->ps_mode = adapter->ps_mode;
196 info->ps_state = adapter->ps_state;
197 info->is_deep_sleep = adapter->is_deep_sleep;
198 info->pm_wakeup_card_req = adapter->pm_wakeup_card_req;
199 info->pm_wakeup_fw_try = adapter->pm_wakeup_fw_try;
200 info->is_hs_configured = adapter->is_hs_configured;
201 info->hs_activated = adapter->hs_activated;
202 info->is_cmd_timedout = adapter->is_cmd_timedout;
203 info->num_cmd_host_to_card_failure
204 = adapter->dbg.num_cmd_host_to_card_failure;
205 info->num_cmd_sleep_cfm_host_to_card_failure
206 = adapter->dbg.num_cmd_sleep_cfm_host_to_card_failure;
207 info->num_tx_host_to_card_failure
208 = adapter->dbg.num_tx_host_to_card_failure;
209 info->num_event_deauth = adapter->dbg.num_event_deauth;
210 info->num_event_disassoc = adapter->dbg.num_event_disassoc;
211 info->num_event_link_lost = adapter->dbg.num_event_link_lost;
212 info->num_cmd_deauth = adapter->dbg.num_cmd_deauth;
213 info->num_cmd_assoc_success =
214 adapter->dbg.num_cmd_assoc_success;
215 info->num_cmd_assoc_failure =
216 adapter->dbg.num_cmd_assoc_failure;
217 info->num_tx_timeout = adapter->dbg.num_tx_timeout;
218 info->timeout_cmd_id = adapter->dbg.timeout_cmd_id;
219 info->timeout_cmd_act = adapter->dbg.timeout_cmd_act;
220 memcpy(info->last_cmd_id, adapter->dbg.last_cmd_id,
221 sizeof(adapter->dbg.last_cmd_id));
222 memcpy(info->last_cmd_act, adapter->dbg.last_cmd_act,
223 sizeof(adapter->dbg.last_cmd_act));
224 info->last_cmd_index = adapter->dbg.last_cmd_index;
225 memcpy(info->last_cmd_resp_id, adapter->dbg.last_cmd_resp_id,
226 sizeof(adapter->dbg.last_cmd_resp_id));
227 info->last_cmd_resp_index = adapter->dbg.last_cmd_resp_index;
228 memcpy(info->last_event, adapter->dbg.last_event,
229 sizeof(adapter->dbg.last_event));
230 info->last_event_index = adapter->dbg.last_event_index;
231 info->data_sent = adapter->data_sent;
232 info->cmd_sent = adapter->cmd_sent;
233 info->cmd_resp_received = adapter->cmd_resp_received;
234 }
235
236 return 0;
237 }
238
239 int mwifiex_debug_info_to_buffer(struct mwifiex_private *priv, char *buf,
240 struct mwifiex_debug_info *info)
241 {
242 char *p = buf;
243 struct mwifiex_debug_data *d = &items[0];
244 size_t size, addr;
245 long val;
246 int i, j;
247
248 if (!info)
249 return 0;
250
251 for (i = 0; i < num_of_items; i++) {
252 p += sprintf(p, "%s=", d[i].name);
253
254 size = d[i].size / d[i].num;
255
256 if (i < (num_of_items - 3))
257 addr = d[i].addr + (size_t)info;
258 else /* The last 3 items are struct mwifiex_adapter variables */
259 addr = d[i].addr + (size_t)priv->adapter;
260
261 for (j = 0; j < d[i].num; j++) {
262 switch (size) {
263 case 1:
264 val = *((u8 *)addr);
265 break;
266 case 2:
267 val = *((u16 *)addr);
268 break;
269 case 4:
270 val = *((u32 *)addr);
271 break;
272 case 8:
273 val = *((long long *)addr);
274 break;
275 default:
276 val = -1;
277 break;
278 }
279
280 p += sprintf(p, "%#lx ", val);
281 addr += size;
282 }
283
284 p += sprintf(p, "\n");
285 }
286
287 if (info->tx_tbl_num) {
288 p += sprintf(p, "Tx BA stream table:\n");
289 for (i = 0; i < info->tx_tbl_num; i++)
290 p += sprintf(p, "tid = %d, ra = %pM\n",
291 info->tx_tbl[i].tid, info->tx_tbl[i].ra);
292 }
293
294 if (info->rx_tbl_num) {
295 p += sprintf(p, "Rx reorder table:\n");
296 for (i = 0; i < info->rx_tbl_num; i++) {
297 p += sprintf(p, "tid = %d, ta = %pM, ",
298 info->rx_tbl[i].tid,
299 info->rx_tbl[i].ta);
300 p += sprintf(p, "start_win = %d, ",
301 info->rx_tbl[i].start_win);
302 p += sprintf(p, "win_size = %d, buffer: ",
303 info->rx_tbl[i].win_size);
304
305 for (j = 0; j < info->rx_tbl[i].win_size; j++)
306 p += sprintf(p, "%c ",
307 info->rx_tbl[i].buffer[j] ?
308 '1' : '0');
309
310 p += sprintf(p, "\n");
311 }
312 }
313
314 if (info->tdls_peer_num) {
315 p += sprintf(p, "TDLS peer table:\n");
316 for (i = 0; i < info->tdls_peer_num; i++) {
317 p += sprintf(p, "peer = %pM",
318 info->tdls_list[i].peer_addr);
319 p += sprintf(p, "\n");
320 }
321 }
322
323 return p - buf;
324 }
325
326 static int
327 mwifiex_parse_mgmt_packet(struct mwifiex_private *priv, u8 *payload, u16 len,
328 struct rxpd *rx_pd)
329 {
330 u16 stype;
331 u8 category, action_code;
332 struct ieee80211_hdr *ieee_hdr = (void *)payload;
333
334 stype = (le16_to_cpu(ieee_hdr->frame_control) & IEEE80211_FCTL_STYPE);
335
336 switch (stype) {
337 case IEEE80211_STYPE_ACTION:
338 category = *(payload + sizeof(struct ieee80211_hdr));
339 action_code = *(payload + sizeof(struct ieee80211_hdr) + 1);
340 if (category == WLAN_CATEGORY_PUBLIC &&
341 action_code == WLAN_PUB_ACTION_TDLS_DISCOVER_RES) {
342 dev_dbg(priv->adapter->dev,
343 "TDLS discovery response %pM nf=%d, snr=%d\n",
344 ieee_hdr->addr2, rx_pd->nf, rx_pd->snr);
345 mwifiex_auto_tdls_update_peer_signal(priv,
346 ieee_hdr->addr2,
347 rx_pd->snr,
348 rx_pd->nf);
349 }
350 break;
351 default:
352 dev_dbg(priv->adapter->dev,
353 "unknown mgmt frame subytpe %#x\n", stype);
354 }
355
356 return 0;
357 }
358 /*
359 * This function processes the received management packet and send it
360 * to the kernel.
361 */
362 int
363 mwifiex_process_mgmt_packet(struct mwifiex_private *priv,
364 struct sk_buff *skb)
365 {
366 struct rxpd *rx_pd;
367 u16 pkt_len;
368 struct ieee80211_hdr *ieee_hdr;
369
370 if (!skb)
371 return -1;
372
373 if (!priv->mgmt_frame_mask ||
374 priv->wdev.iftype == NL80211_IFTYPE_UNSPECIFIED) {
375 dev_dbg(priv->adapter->dev,
376 "do not receive mgmt frames on uninitialized intf");
377 return -1;
378 }
379
380 rx_pd = (struct rxpd *)skb->data;
381
382 skb_pull(skb, le16_to_cpu(rx_pd->rx_pkt_offset));
383 skb_pull(skb, sizeof(pkt_len));
384
385 pkt_len = le16_to_cpu(rx_pd->rx_pkt_length);
386
387 ieee_hdr = (void *)skb->data;
388 if (ieee80211_is_mgmt(ieee_hdr->frame_control)) {
389 mwifiex_parse_mgmt_packet(priv, (u8 *)ieee_hdr,
390 pkt_len, rx_pd);
391 }
392 /* Remove address4 */
393 memmove(skb->data + sizeof(struct ieee80211_hdr_3addr),
394 skb->data + sizeof(struct ieee80211_hdr),
395 pkt_len - sizeof(struct ieee80211_hdr));
396
397 pkt_len -= ETH_ALEN + sizeof(pkt_len);
398 rx_pd->rx_pkt_length = cpu_to_le16(pkt_len);
399
400 cfg80211_rx_mgmt(&priv->wdev, priv->roc_cfg.chan.center_freq,
401 CAL_RSSI(rx_pd->snr, rx_pd->nf), skb->data, pkt_len,
402 0);
403
404 return 0;
405 }
406
407 /*
408 * This function processes the received packet before sending it to the
409 * kernel.
410 *
411 * It extracts the SKB from the received buffer and sends it to kernel.
412 * In case the received buffer does not contain the data in SKB format,
413 * the function creates a blank SKB, fills it with the data from the
414 * received buffer and then sends this new SKB to the kernel.
415 */
416 int mwifiex_recv_packet(struct mwifiex_private *priv, struct sk_buff *skb)
417 {
418 if (!skb)
419 return -1;
420
421 priv->stats.rx_bytes += skb->len;
422 priv->stats.rx_packets++;
423
424 skb->dev = priv->netdev;
425 skb->protocol = eth_type_trans(skb, priv->netdev);
426 skb->ip_summed = CHECKSUM_NONE;
427
428 /* This is required only in case of 11n and USB/PCIE as we alloc
429 * a buffer of 4K only if its 11N (to be able to receive 4K
430 * AMSDU packets). In case of SD we allocate buffers based
431 * on the size of packet and hence this is not needed.
432 *
433 * Modifying the truesize here as our allocation for each
434 * skb is 4K but we only receive 2K packets and this cause
435 * the kernel to start dropping packets in case where
436 * application has allocated buffer based on 2K size i.e.
437 * if there a 64K packet received (in IP fragments and
438 * application allocates 64K to receive this packet but
439 * this packet would almost double up because we allocate
440 * each 1.5K fragment in 4K and pass it up. As soon as the
441 * 64K limit hits kernel will start to drop rest of the
442 * fragments. Currently we fail the Filesndl-ht.scr script
443 * for UDP, hence this fix
444 */
445 if ((priv->adapter->iface_type == MWIFIEX_USB ||
446 priv->adapter->iface_type == MWIFIEX_PCIE) &&
447 (skb->truesize > MWIFIEX_RX_DATA_BUF_SIZE))
448 skb->truesize += (skb->len - MWIFIEX_RX_DATA_BUF_SIZE);
449
450 if (in_interrupt())
451 netif_rx(skb);
452 else
453 netif_rx_ni(skb);
454
455 return 0;
456 }
457
458 /*
459 * IOCTL completion callback handler.
460 *
461 * This function is called when a pending IOCTL is completed.
462 *
463 * If work queue support is enabled, the function wakes up the
464 * corresponding waiting function. Otherwise, it processes the
465 * IOCTL response and frees the response buffer.
466 */
467 int mwifiex_complete_cmd(struct mwifiex_adapter *adapter,
468 struct cmd_ctrl_node *cmd_node)
469 {
470 dev_dbg(adapter->dev, "cmd completed: status=%d\n",
471 adapter->cmd_wait_q.status);
472
473 *(cmd_node->condition) = true;
474
475 if (adapter->cmd_wait_q.status == -ETIMEDOUT)
476 dev_err(adapter->dev, "cmd timeout\n");
477 else
478 wake_up_interruptible(&adapter->cmd_wait_q.wait);
479
480 return 0;
481 }
482
483 /* This function will return the pointer to station entry in station list
484 * table which matches specified mac address.
485 * This function should be called after acquiring RA list spinlock.
486 * NULL is returned if station entry is not found in associated STA list.
487 */
488 struct mwifiex_sta_node *
489 mwifiex_get_sta_entry(struct mwifiex_private *priv, const u8 *mac)
490 {
491 struct mwifiex_sta_node *node;
492
493 if (!mac)
494 return NULL;
495
496 list_for_each_entry(node, &priv->sta_list, list) {
497 if (!memcmp(node->mac_addr, mac, ETH_ALEN))
498 return node;
499 }
500
501 return NULL;
502 }
503
504 /* This function will add a sta_node entry to associated station list
505 * table with the given mac address.
506 * If entry exist already, existing entry is returned.
507 * If received mac address is NULL, NULL is returned.
508 */
509 struct mwifiex_sta_node *
510 mwifiex_add_sta_entry(struct mwifiex_private *priv, const u8 *mac)
511 {
512 struct mwifiex_sta_node *node;
513 unsigned long flags;
514
515 if (!mac)
516 return NULL;
517
518 spin_lock_irqsave(&priv->sta_list_spinlock, flags);
519 node = mwifiex_get_sta_entry(priv, mac);
520 if (node)
521 goto done;
522
523 node = kzalloc(sizeof(*node), GFP_ATOMIC);
524 if (!node)
525 goto done;
526
527 memcpy(node->mac_addr, mac, ETH_ALEN);
528 list_add_tail(&node->list, &priv->sta_list);
529
530 done:
531 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
532 return node;
533 }
534
535 /* This function will search for HT IE in association request IEs
536 * and set station HT parameters accordingly.
537 */
538 void
539 mwifiex_set_sta_ht_cap(struct mwifiex_private *priv, const u8 *ies,
540 int ies_len, struct mwifiex_sta_node *node)
541 {
542 struct ieee_types_header *ht_cap_ie;
543 const struct ieee80211_ht_cap *ht_cap;
544
545 if (!ies)
546 return;
547
548 ht_cap_ie = (void *)cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies,
549 ies_len);
550 if (ht_cap_ie) {
551 ht_cap = (void *)(ht_cap_ie + 1);
552 node->is_11n_enabled = 1;
553 node->max_amsdu = le16_to_cpu(ht_cap->cap_info) &
554 IEEE80211_HT_CAP_MAX_AMSDU ?
555 MWIFIEX_TX_DATA_BUF_SIZE_8K :
556 MWIFIEX_TX_DATA_BUF_SIZE_4K;
557 } else {
558 node->is_11n_enabled = 0;
559 }
560
561 return;
562 }
563
564 /* This function will delete a station entry from station list */
565 void mwifiex_del_sta_entry(struct mwifiex_private *priv, const u8 *mac)
566 {
567 struct mwifiex_sta_node *node;
568 unsigned long flags;
569
570 spin_lock_irqsave(&priv->sta_list_spinlock, flags);
571
572 node = mwifiex_get_sta_entry(priv, mac);
573 if (node) {
574 list_del(&node->list);
575 kfree(node);
576 }
577
578 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
579 return;
580 }
581
582 /* This function will delete all stations from associated station list. */
583 void mwifiex_del_all_sta_list(struct mwifiex_private *priv)
584 {
585 struct mwifiex_sta_node *node, *tmp;
586 unsigned long flags;
587
588 spin_lock_irqsave(&priv->sta_list_spinlock, flags);
589
590 list_for_each_entry_safe(node, tmp, &priv->sta_list, list) {
591 list_del(&node->list);
592 kfree(node);
593 }
594
595 INIT_LIST_HEAD(&priv->sta_list);
596 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
597 return;
598 }
599
600 /* This function adds histogram data to histogram array*/
601 void mwifiex_hist_data_add(struct mwifiex_private *priv,
602 u8 rx_rate, s8 snr, s8 nflr)
603 {
604 struct mwifiex_histogram_data *phist_data = priv->hist_data;
605
606 if (atomic_read(&phist_data->num_samples) > MWIFIEX_HIST_MAX_SAMPLES)
607 mwifiex_hist_data_reset(priv);
608 mwifiex_hist_data_set(priv, rx_rate, snr, nflr);
609 }
610
611 /* function to add histogram record */
612 void mwifiex_hist_data_set(struct mwifiex_private *priv, u8 rx_rate, s8 snr,
613 s8 nflr)
614 {
615 struct mwifiex_histogram_data *phist_data = priv->hist_data;
616
617 atomic_inc(&phist_data->num_samples);
618 atomic_inc(&phist_data->rx_rate[rx_rate]);
619 atomic_inc(&phist_data->snr[snr]);
620 atomic_inc(&phist_data->noise_flr[128 + nflr]);
621 atomic_inc(&phist_data->sig_str[nflr - snr]);
622 }
623
624 /* function to reset histogram data during init/reset */
625 void mwifiex_hist_data_reset(struct mwifiex_private *priv)
626 {
627 int ix;
628 struct mwifiex_histogram_data *phist_data = priv->hist_data;
629
630 atomic_set(&phist_data->num_samples, 0);
631 for (ix = 0; ix < MWIFIEX_MAX_AC_RX_RATES; ix++)
632 atomic_set(&phist_data->rx_rate[ix], 0);
633 for (ix = 0; ix < MWIFIEX_MAX_SNR; ix++)
634 atomic_set(&phist_data->snr[ix], 0);
635 for (ix = 0; ix < MWIFIEX_MAX_NOISE_FLR; ix++)
636 atomic_set(&phist_data->noise_flr[ix], 0);
637 for (ix = 0; ix < MWIFIEX_MAX_SIG_STRENGTH; ix++)
638 atomic_set(&phist_data->sig_str[ix], 0);
639 }
640
641 void *mwifiex_alloc_dma_align_buf(int rx_len, gfp_t flags)
642 {
643 struct sk_buff *skb;
644 int buf_len, pad;
645
646 buf_len = rx_len + MWIFIEX_RX_HEADROOM + MWIFIEX_DMA_ALIGN_SZ;
647
648 skb = __dev_alloc_skb(buf_len, flags);
649
650 if (!skb)
651 return NULL;
652
653 skb_reserve(skb, MWIFIEX_RX_HEADROOM);
654
655 pad = MWIFIEX_ALIGN_ADDR(skb->data, MWIFIEX_DMA_ALIGN_SZ) -
656 (long)skb->data;
657
658 skb_reserve(skb, pad);
659
660 return skb;
661 }
662 EXPORT_SYMBOL_GPL(mwifiex_alloc_dma_align_buf);
This page took 0.055375 seconds and 6 git commands to generate.