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