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