Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Marvell Wireless LAN device driver: major 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 "main.h" |
| 21 | #include "wmm.h" |
| 22 | #include "cfg80211.h" |
| 23 | #include "11n.h" |
| 24 | |
| 25 | #define VERSION "1.0" |
| 26 | |
| 27 | const char driver_version[] = "mwifiex " VERSION " (%s) "; |
Amitkumar Karwar | 388ec38 | 2013-05-17 17:50:25 -0700 | [diff] [blame] | 28 | static char *cal_data_cfg; |
| 29 | module_param(cal_data_cfg, charp, 0); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 30 | |
Avinash Patil | 0013c7c | 2014-11-05 19:38:11 +0530 | [diff] [blame] | 31 | static unsigned short driver_mode; |
| 32 | module_param(driver_mode, ushort, 0); |
| 33 | MODULE_PARM_DESC(driver_mode, |
| 34 | "station=0x1(default), ap-sta=0x3, station-p2p=0x5, ap-sta-p2p=0x7"); |
| 35 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 36 | /* |
| 37 | * This function registers the device and performs all the necessary |
| 38 | * initializations. |
| 39 | * |
| 40 | * The following initialization operations are performed - |
| 41 | * - Allocate adapter structure |
| 42 | * - Save interface specific operations table in adapter |
| 43 | * - Call interface specific initialization routine |
| 44 | * - Allocate private structures |
| 45 | * - Set default adapter structure parameters |
| 46 | * - Initialize locks |
| 47 | * |
| 48 | * In case of any errors during inittialization, this function also ensures |
| 49 | * proper cleanup before exiting. |
| 50 | */ |
| 51 | static int mwifiex_register(void *card, struct mwifiex_if_ops *if_ops, |
Amitkumar Karwar | 287546d | 2011-06-08 20:39:20 +0530 | [diff] [blame] | 52 | void **padapter) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 53 | { |
Amitkumar Karwar | 2be7859 | 2011-04-15 20:50:42 -0700 | [diff] [blame] | 54 | struct mwifiex_adapter *adapter; |
| 55 | int i; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 56 | |
| 57 | adapter = kzalloc(sizeof(struct mwifiex_adapter), GFP_KERNEL); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 58 | if (!adapter) |
Christoph Fritz | b53575e | 2011-05-08 22:50:09 +0200 | [diff] [blame] | 59 | return -ENOMEM; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 60 | |
Amitkumar Karwar | 287546d | 2011-06-08 20:39:20 +0530 | [diff] [blame] | 61 | *padapter = adapter; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 62 | adapter->card = card; |
| 63 | |
| 64 | /* Save interface specific operations in adapter */ |
| 65 | memmove(&adapter->if_ops, if_ops, sizeof(struct mwifiex_if_ops)); |
| 66 | |
| 67 | /* card specific initialization has been deferred until now .. */ |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 68 | if (adapter->if_ops.init_if) |
| 69 | if (adapter->if_ops.init_if(adapter)) |
| 70 | goto error; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 71 | |
| 72 | adapter->priv_num = 0; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 73 | |
Avinash Patil | 64b05e2 | 2012-05-08 18:30:13 -0700 | [diff] [blame] | 74 | for (i = 0; i < MWIFIEX_MAX_BSS_NUM; i++) { |
| 75 | /* Allocate memory for private structure */ |
| 76 | adapter->priv[i] = |
| 77 | kzalloc(sizeof(struct mwifiex_private), GFP_KERNEL); |
| 78 | if (!adapter->priv[i]) |
| 79 | goto error; |
| 80 | |
| 81 | adapter->priv[i]->adapter = adapter; |
Avinash Patil | 64b05e2 | 2012-05-08 18:30:13 -0700 | [diff] [blame] | 82 | adapter->priv_num++; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 83 | } |
Amitkumar Karwar | 44b815c | 2011-09-29 20:43:41 -0700 | [diff] [blame] | 84 | mwifiex_init_lock_list(adapter); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 85 | |
| 86 | init_timer(&adapter->cmd_timer); |
| 87 | adapter->cmd_timer.function = mwifiex_cmd_timeout_func; |
| 88 | adapter->cmd_timer.data = (unsigned long) adapter; |
| 89 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 90 | return 0; |
| 91 | |
| 92 | error: |
| 93 | dev_dbg(adapter->dev, "info: leave mwifiex_register with error\n"); |
| 94 | |
Yogesh Ashok Powar | 93a1df4 | 2011-09-26 20:37:26 -0700 | [diff] [blame] | 95 | for (i = 0; i < adapter->priv_num; i++) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 96 | kfree(adapter->priv[i]); |
Yogesh Ashok Powar | 93a1df4 | 2011-09-26 20:37:26 -0700 | [diff] [blame] | 97 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 98 | kfree(adapter); |
| 99 | |
| 100 | return -1; |
| 101 | } |
| 102 | |
| 103 | /* |
| 104 | * This function unregisters the device and performs all the necessary |
| 105 | * cleanups. |
| 106 | * |
| 107 | * The following cleanup operations are performed - |
| 108 | * - Free the timers |
| 109 | * - Free beacon buffers |
| 110 | * - Free private structures |
| 111 | * - Free adapter structure |
| 112 | */ |
| 113 | static int mwifiex_unregister(struct mwifiex_adapter *adapter) |
| 114 | { |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 115 | s32 i; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 116 | |
Amitkumar Karwar | 4cfda67 | 2013-07-22 19:17:50 -0700 | [diff] [blame] | 117 | if (adapter->if_ops.cleanup_if) |
| 118 | adapter->if_ops.cleanup_if(adapter); |
| 119 | |
Avinash Patil | 629873f | 2014-02-18 15:47:55 -0800 | [diff] [blame] | 120 | del_timer_sync(&adapter->cmd_timer); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 121 | |
| 122 | /* Free private structures */ |
| 123 | for (i = 0; i < adapter->priv_num; i++) { |
| 124 | if (adapter->priv[i]) { |
| 125 | mwifiex_free_curr_bcn(adapter->priv[i]); |
| 126 | kfree(adapter->priv[i]); |
| 127 | } |
| 128 | } |
| 129 | |
Avinash Patil | bf35443 | 2014-10-31 16:08:26 +0530 | [diff] [blame] | 130 | vfree(adapter->chan_stats); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 131 | kfree(adapter); |
| 132 | return 0; |
| 133 | } |
| 134 | |
Avinash Patil | 6e25117 | 2014-09-12 20:08:59 +0530 | [diff] [blame] | 135 | static int mwifiex_process_rx(struct mwifiex_adapter *adapter) |
| 136 | { |
| 137 | unsigned long flags; |
| 138 | struct sk_buff *skb; |
Avinash Patil | 6e25117 | 2014-09-12 20:08:59 +0530 | [diff] [blame] | 139 | |
| 140 | spin_lock_irqsave(&adapter->rx_proc_lock, flags); |
| 141 | if (adapter->rx_processing || adapter->rx_locked) { |
| 142 | spin_unlock_irqrestore(&adapter->rx_proc_lock, flags); |
| 143 | goto exit_rx_proc; |
| 144 | } else { |
| 145 | adapter->rx_processing = true; |
| 146 | spin_unlock_irqrestore(&adapter->rx_proc_lock, flags); |
| 147 | } |
| 148 | |
| 149 | /* Check for Rx data */ |
| 150 | while ((skb = skb_dequeue(&adapter->rx_data_q))) { |
| 151 | atomic_dec(&adapter->rx_pending); |
Amitkumar Karwar | 381e9ff | 2014-11-25 06:43:04 -0800 | [diff] [blame] | 152 | if ((adapter->delay_main_work || |
| 153 | adapter->iface_type == MWIFIEX_USB) && |
Avinash Patil | b43a0d9 | 2014-09-29 21:44:14 +0530 | [diff] [blame] | 154 | (atomic_read(&adapter->rx_pending) < LOW_RX_PENDING)) { |
Amitkumar Karwar | cf6a64f | 2014-11-05 17:04:29 +0530 | [diff] [blame] | 155 | if (adapter->if_ops.submit_rem_rx_urbs) |
| 156 | adapter->if_ops.submit_rem_rx_urbs(adapter); |
Avinash Patil | 6e25117 | 2014-09-12 20:08:59 +0530 | [diff] [blame] | 157 | adapter->delay_main_work = false; |
Avinash Patil | b43a0d9 | 2014-09-29 21:44:14 +0530 | [diff] [blame] | 158 | queue_work(adapter->workqueue, &adapter->main_work); |
Avinash Patil | 6e25117 | 2014-09-12 20:08:59 +0530 | [diff] [blame] | 159 | } |
| 160 | mwifiex_handle_rx_packet(adapter, skb); |
| 161 | } |
| 162 | spin_lock_irqsave(&adapter->rx_proc_lock, flags); |
| 163 | adapter->rx_processing = false; |
| 164 | spin_unlock_irqrestore(&adapter->rx_proc_lock, flags); |
| 165 | |
Avinash Patil | 6e25117 | 2014-09-12 20:08:59 +0530 | [diff] [blame] | 166 | exit_rx_proc: |
| 167 | return 0; |
| 168 | } |
| 169 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 170 | /* |
| 171 | * The main process. |
| 172 | * |
| 173 | * This function is the main procedure of the driver and handles various driver |
| 174 | * operations. It runs in a loop and provides the core functionalities. |
| 175 | * |
| 176 | * The main responsibilities of this function are - |
| 177 | * - Ensure concurrency control |
| 178 | * - Handle pending interrupts and call interrupt handlers |
| 179 | * - Wake up the card if required |
| 180 | * - Handle command responses and call response handlers |
| 181 | * - Handle events and call event handlers |
| 182 | * - Execute pending commands |
| 183 | * - Transmit pending data packets |
| 184 | */ |
| 185 | int mwifiex_main_process(struct mwifiex_adapter *adapter) |
| 186 | { |
| 187 | int ret = 0; |
| 188 | unsigned long flags; |
| 189 | |
| 190 | spin_lock_irqsave(&adapter->main_proc_lock, flags); |
| 191 | |
| 192 | /* Check if already processing */ |
| 193 | if (adapter->mwifiex_processing) { |
| 194 | spin_unlock_irqrestore(&adapter->main_proc_lock, flags); |
| 195 | goto exit_main_proc; |
| 196 | } else { |
| 197 | adapter->mwifiex_processing = true; |
| 198 | spin_unlock_irqrestore(&adapter->main_proc_lock, flags); |
| 199 | } |
| 200 | process_start: |
| 201 | do { |
| 202 | if ((adapter->hw_status == MWIFIEX_HW_STATUS_CLOSING) || |
| 203 | (adapter->hw_status == MWIFIEX_HW_STATUS_NOT_READY)) |
| 204 | break; |
| 205 | |
Amitkumar Karwar | 381e9ff | 2014-11-25 06:43:04 -0800 | [diff] [blame] | 206 | /* For non-USB interfaces, If we process interrupts first, it |
| 207 | * would increase RX pending even further. Avoid this by |
| 208 | * checking if rx_pending has crossed high threshold and |
| 209 | * schedule rx work queue and then process interrupts. |
| 210 | * For USB interface, there are no interrupts. We already have |
| 211 | * HIGH_RX_PENDING check in usb.c |
Avinash Patil | 6e25117 | 2014-09-12 20:08:59 +0530 | [diff] [blame] | 212 | */ |
Amitkumar Karwar | 381e9ff | 2014-11-25 06:43:04 -0800 | [diff] [blame] | 213 | if (atomic_read(&adapter->rx_pending) >= HIGH_RX_PENDING && |
| 214 | adapter->iface_type != MWIFIEX_USB) { |
Avinash Patil | 6e25117 | 2014-09-12 20:08:59 +0530 | [diff] [blame] | 215 | adapter->delay_main_work = true; |
| 216 | if (!adapter->rx_processing) |
| 217 | queue_work(adapter->rx_workqueue, |
| 218 | &adapter->rx_work); |
| 219 | break; |
| 220 | } |
| 221 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 222 | /* Handle pending interrupt if any */ |
| 223 | if (adapter->int_status) { |
| 224 | if (adapter->hs_activated) |
| 225 | mwifiex_process_hs_config(adapter); |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 226 | if (adapter->if_ops.process_int_status) |
| 227 | adapter->if_ops.process_int_status(adapter); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 228 | } |
| 229 | |
Avinash Patil | 6e25117 | 2014-09-12 20:08:59 +0530 | [diff] [blame] | 230 | if (adapter->rx_work_enabled && adapter->data_received) |
| 231 | queue_work(adapter->rx_workqueue, &adapter->rx_work); |
| 232 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 233 | /* Need to wake up the card ? */ |
| 234 | if ((adapter->ps_state == PS_STATE_SLEEP) && |
| 235 | (adapter->pm_wakeup_card_req && |
| 236 | !adapter->pm_wakeup_fw_try) && |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 237 | (is_command_pending(adapter) || |
| 238 | !mwifiex_wmm_lists_empty(adapter))) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 239 | adapter->pm_wakeup_fw_try = true; |
| 240 | adapter->if_ops.wakeup(adapter); |
| 241 | continue; |
| 242 | } |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 243 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 244 | if (IS_CARD_RX_RCVD(adapter)) { |
Avinash Patil | 6e25117 | 2014-09-12 20:08:59 +0530 | [diff] [blame] | 245 | adapter->data_received = false; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 246 | adapter->pm_wakeup_fw_try = false; |
| 247 | if (adapter->ps_state == PS_STATE_SLEEP) |
| 248 | adapter->ps_state = PS_STATE_AWAKE; |
| 249 | } else { |
| 250 | /* We have tried to wakeup the card already */ |
| 251 | if (adapter->pm_wakeup_fw_try) |
| 252 | break; |
| 253 | if (adapter->ps_state != PS_STATE_AWAKE || |
| 254 | adapter->tx_lock_flag) |
| 255 | break; |
| 256 | |
Avinash Patil | 5ec39ef | 2014-09-12 20:08:56 +0530 | [diff] [blame] | 257 | if ((!adapter->scan_chan_gap_enabled && |
Avinash Patil | 5ec39ef | 2014-09-12 20:08:56 +0530 | [diff] [blame] | 258 | adapter->scan_processing) || adapter->data_sent || |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 259 | mwifiex_wmm_lists_empty(adapter)) { |
| 260 | if (adapter->cmd_sent || adapter->curr_cmd || |
| 261 | (!is_command_pending(adapter))) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 262 | break; |
| 263 | } |
| 264 | } |
| 265 | |
Amitkumar Karwar | 2047412 | 2014-04-14 15:31:05 -0700 | [diff] [blame] | 266 | /* Check for event */ |
| 267 | if (adapter->event_received) { |
| 268 | adapter->event_received = false; |
| 269 | mwifiex_process_event(adapter); |
| 270 | } |
| 271 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 272 | /* Check for Cmd Resp */ |
| 273 | if (adapter->cmd_resp_received) { |
| 274 | adapter->cmd_resp_received = false; |
| 275 | mwifiex_process_cmdresp(adapter); |
| 276 | |
| 277 | /* call mwifiex back when init_fw is done */ |
| 278 | if (adapter->hw_status == MWIFIEX_HW_STATUS_INIT_DONE) { |
| 279 | adapter->hw_status = MWIFIEX_HW_STATUS_READY; |
| 280 | mwifiex_init_fw_complete(adapter); |
| 281 | } |
| 282 | } |
| 283 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 284 | /* Check if we need to confirm Sleep Request |
| 285 | received previously */ |
| 286 | if (adapter->ps_state == PS_STATE_PRE_SLEEP) { |
| 287 | if (!adapter->cmd_sent && !adapter->curr_cmd) |
| 288 | mwifiex_check_ps_cond(adapter); |
| 289 | } |
| 290 | |
| 291 | /* * The ps_state may have been changed during processing of |
| 292 | * Sleep Request event. |
| 293 | */ |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 294 | if ((adapter->ps_state == PS_STATE_SLEEP) || |
| 295 | (adapter->ps_state == PS_STATE_PRE_SLEEP) || |
| 296 | (adapter->ps_state == PS_STATE_SLEEP_CFM) || |
| 297 | adapter->tx_lock_flag) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 298 | continue; |
| 299 | |
| 300 | if (!adapter->cmd_sent && !adapter->curr_cmd) { |
| 301 | if (mwifiex_exec_next_cmd(adapter) == -1) { |
| 302 | ret = -1; |
| 303 | break; |
| 304 | } |
| 305 | } |
| 306 | |
Avinash Patil | 5ec39ef | 2014-09-12 20:08:56 +0530 | [diff] [blame] | 307 | if ((adapter->scan_chan_gap_enabled || |
Amitkumar Karwar | d8d9125 | 2014-09-12 20:08:58 +0530 | [diff] [blame] | 308 | !adapter->scan_processing) && |
Amitkumar Karwar | 3249ba7 | 2012-06-06 21:12:41 -0700 | [diff] [blame] | 309 | !adapter->data_sent && !mwifiex_wmm_lists_empty(adapter)) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 310 | mwifiex_wmm_process_tx(adapter); |
| 311 | if (adapter->hs_activated) { |
| 312 | adapter->is_hs_configured = false; |
| 313 | mwifiex_hs_activated_event |
| 314 | (mwifiex_get_priv |
| 315 | (adapter, MWIFIEX_BSS_ROLE_ANY), |
| 316 | false); |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | if (adapter->delay_null_pkt && !adapter->cmd_sent && |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 321 | !adapter->curr_cmd && !is_command_pending(adapter) && |
| 322 | mwifiex_wmm_lists_empty(adapter)) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 323 | if (!mwifiex_send_null_packet |
| 324 | (mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA), |
| 325 | MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET | |
| 326 | MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET)) { |
| 327 | adapter->delay_null_pkt = false; |
| 328 | adapter->ps_state = PS_STATE_SLEEP; |
| 329 | } |
| 330 | break; |
| 331 | } |
| 332 | } while (true); |
| 333 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 334 | spin_lock_irqsave(&adapter->main_proc_lock, flags); |
Avinash Patil | f73e557 | 2014-09-29 21:44:13 +0530 | [diff] [blame] | 335 | if (!adapter->delay_main_work && |
| 336 | (adapter->int_status || IS_CARD_RX_RCVD(adapter))) { |
Amitkumar Karwar | 453b0c3 | 2013-09-27 10:55:38 -0700 | [diff] [blame] | 337 | spin_unlock_irqrestore(&adapter->main_proc_lock, flags); |
| 338 | goto process_start; |
| 339 | } |
| 340 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 341 | adapter->mwifiex_processing = false; |
| 342 | spin_unlock_irqrestore(&adapter->main_proc_lock, flags); |
| 343 | |
| 344 | exit_main_proc: |
| 345 | if (adapter->hw_status == MWIFIEX_HW_STATUS_CLOSING) |
| 346 | mwifiex_shutdown_drv(adapter); |
| 347 | return ret; |
| 348 | } |
Bing Zhao | 601216e | 2012-11-05 16:59:15 -0800 | [diff] [blame] | 349 | EXPORT_SYMBOL_GPL(mwifiex_main_process); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 350 | |
| 351 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 352 | * This function frees the adapter structure. |
| 353 | * |
| 354 | * Additionally, this closes the netlink socket, frees the timers |
| 355 | * and private structures. |
| 356 | */ |
| 357 | static void mwifiex_free_adapter(struct mwifiex_adapter *adapter) |
| 358 | { |
| 359 | if (!adapter) { |
| 360 | pr_err("%s: adapter is NULL\n", __func__); |
| 361 | return; |
| 362 | } |
| 363 | |
| 364 | mwifiex_unregister(adapter); |
| 365 | pr_debug("info: %s: free adapter\n", __func__); |
| 366 | } |
| 367 | |
| 368 | /* |
Amitkumar Karwar | 6b41f94 | 2013-07-22 19:17:55 -0700 | [diff] [blame] | 369 | * This function cancels all works in the queue and destroys |
| 370 | * the main workqueue. |
| 371 | */ |
| 372 | static void mwifiex_terminate_workqueue(struct mwifiex_adapter *adapter) |
| 373 | { |
| 374 | flush_workqueue(adapter->workqueue); |
| 375 | destroy_workqueue(adapter->workqueue); |
| 376 | adapter->workqueue = NULL; |
Avinash Patil | 6e25117 | 2014-09-12 20:08:59 +0530 | [diff] [blame] | 377 | |
| 378 | if (adapter->rx_workqueue) { |
| 379 | flush_workqueue(adapter->rx_workqueue); |
| 380 | destroy_workqueue(adapter->rx_workqueue); |
| 381 | adapter->rx_workqueue = NULL; |
| 382 | } |
Amitkumar Karwar | 6b41f94 | 2013-07-22 19:17:55 -0700 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | /* |
Amitkumar Karwar | 59a4cc2 | 2012-04-09 20:06:57 -0700 | [diff] [blame] | 386 | * This function gets firmware and initializes it. |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 387 | * |
| 388 | * The main initialization steps followed are - |
| 389 | * - Download the correct firmware to card |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 390 | * - Issue the init commands to firmware |
| 391 | */ |
Amitkumar Karwar | 59a4cc2 | 2012-04-09 20:06:57 -0700 | [diff] [blame] | 392 | static void mwifiex_fw_dpc(const struct firmware *firmware, void *context) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 393 | { |
Amitkumar Karwar | bec568f | 2013-11-14 19:10:38 -0800 | [diff] [blame] | 394 | int ret; |
Amitkumar Karwar | 59a4cc2 | 2012-04-09 20:06:57 -0700 | [diff] [blame] | 395 | char fmt[64]; |
| 396 | struct mwifiex_private *priv; |
| 397 | struct mwifiex_adapter *adapter = context; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 398 | struct mwifiex_fw_image fw; |
Amitkumar Karwar | c3afd99 | 2013-07-30 17:18:15 -0700 | [diff] [blame] | 399 | struct semaphore *sem = adapter->card_sem; |
| 400 | bool init_failed = false; |
Amitkumar Karwar | 68b76e9 | 2013-11-14 19:10:37 -0800 | [diff] [blame] | 401 | struct wireless_dev *wdev; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 402 | |
Amitkumar Karwar | 59a4cc2 | 2012-04-09 20:06:57 -0700 | [diff] [blame] | 403 | if (!firmware) { |
| 404 | dev_err(adapter->dev, |
| 405 | "Failed to get firmware %s\n", adapter->fw_name); |
Amitkumar Karwar | 6b41f94 | 2013-07-22 19:17:55 -0700 | [diff] [blame] | 406 | goto err_dnld_fw; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 407 | } |
Amitkumar Karwar | 59a4cc2 | 2012-04-09 20:06:57 -0700 | [diff] [blame] | 408 | |
| 409 | memset(&fw, 0, sizeof(struct mwifiex_fw_image)); |
| 410 | adapter->firmware = firmware; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 411 | fw.fw_buf = (u8 *) adapter->firmware->data; |
| 412 | fw.fw_len = adapter->firmware->size; |
| 413 | |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 414 | if (adapter->if_ops.dnld_fw) |
| 415 | ret = adapter->if_ops.dnld_fw(adapter, &fw); |
| 416 | else |
| 417 | ret = mwifiex_dnld_fw(adapter, &fw); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 418 | if (ret == -1) |
Amitkumar Karwar | 6b41f94 | 2013-07-22 19:17:55 -0700 | [diff] [blame] | 419 | goto err_dnld_fw; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 420 | |
| 421 | dev_notice(adapter->dev, "WLAN FW is active\n"); |
| 422 | |
Amitkumar Karwar | 388ec38 | 2013-05-17 17:50:25 -0700 | [diff] [blame] | 423 | if (cal_data_cfg) { |
| 424 | if ((request_firmware(&adapter->cal_data, cal_data_cfg, |
| 425 | adapter->dev)) < 0) |
| 426 | dev_err(adapter->dev, |
| 427 | "Cal data request_firmware() failed\n"); |
| 428 | } |
| 429 | |
Daniel Drake | 232fde0 | 2013-07-13 10:57:10 -0400 | [diff] [blame] | 430 | /* enable host interrupt after fw dnld is successful */ |
Amitkumar Karwar | 6b41f94 | 2013-07-22 19:17:55 -0700 | [diff] [blame] | 431 | if (adapter->if_ops.enable_int) { |
| 432 | if (adapter->if_ops.enable_int(adapter)) |
| 433 | goto err_dnld_fw; |
| 434 | } |
Daniel Drake | 232fde0 | 2013-07-13 10:57:10 -0400 | [diff] [blame] | 435 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 436 | adapter->init_wait_q_woken = false; |
| 437 | ret = mwifiex_init_fw(adapter); |
| 438 | if (ret == -1) { |
Amitkumar Karwar | 6b41f94 | 2013-07-22 19:17:55 -0700 | [diff] [blame] | 439 | goto err_init_fw; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 440 | } else if (!ret) { |
| 441 | adapter->hw_status = MWIFIEX_HW_STATUS_READY; |
| 442 | goto done; |
| 443 | } |
| 444 | /* Wait for mwifiex_init to complete */ |
| 445 | wait_event_interruptible(adapter->init_wait_q, |
| 446 | adapter->init_wait_q_woken); |
Amitkumar Karwar | 59a4cc2 | 2012-04-09 20:06:57 -0700 | [diff] [blame] | 447 | if (adapter->hw_status != MWIFIEX_HW_STATUS_READY) |
Amitkumar Karwar | 6b41f94 | 2013-07-22 19:17:55 -0700 | [diff] [blame] | 448 | goto err_init_fw; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 449 | |
Avinash Patil | d6bffe8 | 2012-05-08 18:30:15 -0700 | [diff] [blame] | 450 | priv = adapter->priv[MWIFIEX_BSS_ROLE_STA]; |
| 451 | if (mwifiex_register_cfg80211(adapter)) { |
Amitkumar Karwar | 59a4cc2 | 2012-04-09 20:06:57 -0700 | [diff] [blame] | 452 | dev_err(adapter->dev, "cannot register with cfg80211\n"); |
Amitkumar Karwar | d1af294 | 2013-11-14 19:10:39 -0800 | [diff] [blame] | 453 | goto err_init_fw; |
Amitkumar Karwar | 59a4cc2 | 2012-04-09 20:06:57 -0700 | [diff] [blame] | 454 | } |
| 455 | |
Avinash Patil | bf35443 | 2014-10-31 16:08:26 +0530 | [diff] [blame] | 456 | if (mwifiex_init_channel_scan_gap(adapter)) { |
| 457 | dev_err(adapter->dev, "could not init channel stats table\n"); |
| 458 | goto err_init_fw; |
| 459 | } |
| 460 | |
Avinash Patil | 0013c7c | 2014-11-05 19:38:11 +0530 | [diff] [blame] | 461 | if (driver_mode) { |
| 462 | driver_mode &= MWIFIEX_DRIVER_MODE_BITMASK; |
| 463 | driver_mode |= MWIFIEX_DRIVER_MODE_STA; |
| 464 | } |
| 465 | |
Amitkumar Karwar | 59a4cc2 | 2012-04-09 20:06:57 -0700 | [diff] [blame] | 466 | rtnl_lock(); |
| 467 | /* Create station interface by default */ |
Amitkumar Karwar | 68b76e9 | 2013-11-14 19:10:37 -0800 | [diff] [blame] | 468 | wdev = mwifiex_add_virtual_intf(adapter->wiphy, "mlan%d", |
| 469 | NL80211_IFTYPE_STATION, NULL, NULL); |
| 470 | if (IS_ERR(wdev)) { |
Amitkumar Karwar | 59a4cc2 | 2012-04-09 20:06:57 -0700 | [diff] [blame] | 471 | dev_err(adapter->dev, "cannot create default STA interface\n"); |
Amitkumar Karwar | bec568f | 2013-11-14 19:10:38 -0800 | [diff] [blame] | 472 | rtnl_unlock(); |
Amitkumar Karwar | 59a4cc2 | 2012-04-09 20:06:57 -0700 | [diff] [blame] | 473 | goto err_add_intf; |
| 474 | } |
Avinash Patil | 0013c7c | 2014-11-05 19:38:11 +0530 | [diff] [blame] | 475 | |
| 476 | if (driver_mode & MWIFIEX_DRIVER_MODE_UAP) { |
| 477 | wdev = mwifiex_add_virtual_intf(adapter->wiphy, "uap%d", |
| 478 | NL80211_IFTYPE_AP, NULL, NULL); |
| 479 | if (IS_ERR(wdev)) { |
| 480 | dev_err(adapter->dev, "cannot create AP interface\n"); |
| 481 | rtnl_unlock(); |
| 482 | goto err_add_intf; |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | if (driver_mode & MWIFIEX_DRIVER_MODE_P2P) { |
| 487 | wdev = mwifiex_add_virtual_intf(adapter->wiphy, "p2p%d", |
| 488 | NL80211_IFTYPE_P2P_CLIENT, NULL, |
| 489 | NULL); |
| 490 | if (IS_ERR(wdev)) { |
| 491 | dev_err(adapter->dev, |
| 492 | "cannot create p2p client interface\n"); |
| 493 | rtnl_unlock(); |
| 494 | goto err_add_intf; |
| 495 | } |
| 496 | } |
Amitkumar Karwar | 59a4cc2 | 2012-04-09 20:06:57 -0700 | [diff] [blame] | 497 | rtnl_unlock(); |
| 498 | |
| 499 | mwifiex_drv_get_driver_version(adapter, fmt, sizeof(fmt) - 1); |
| 500 | dev_notice(adapter->dev, "driver_version = %s\n", fmt); |
| 501 | goto done; |
| 502 | |
| 503 | err_add_intf: |
Amitkumar Karwar | 6b41f94 | 2013-07-22 19:17:55 -0700 | [diff] [blame] | 504 | wiphy_unregister(adapter->wiphy); |
| 505 | wiphy_free(adapter->wiphy); |
Amitkumar Karwar | 59a4cc2 | 2012-04-09 20:06:57 -0700 | [diff] [blame] | 506 | err_init_fw: |
Daniel Drake | 232fde0 | 2013-07-13 10:57:10 -0400 | [diff] [blame] | 507 | if (adapter->if_ops.disable_int) |
| 508 | adapter->if_ops.disable_int(adapter); |
Amitkumar Karwar | 6b41f94 | 2013-07-22 19:17:55 -0700 | [diff] [blame] | 509 | err_dnld_fw: |
Amitkumar Karwar | 59a4cc2 | 2012-04-09 20:06:57 -0700 | [diff] [blame] | 510 | pr_debug("info: %s: unregister device\n", __func__); |
Amitkumar Karwar | 6b41f94 | 2013-07-22 19:17:55 -0700 | [diff] [blame] | 511 | if (adapter->if_ops.unregister_dev) |
| 512 | adapter->if_ops.unregister_dev(adapter); |
| 513 | |
| 514 | if ((adapter->hw_status == MWIFIEX_HW_STATUS_FW_READY) || |
| 515 | (adapter->hw_status == MWIFIEX_HW_STATUS_READY)) { |
| 516 | pr_debug("info: %s: shutdown mwifiex\n", __func__); |
| 517 | adapter->init_wait_q_woken = false; |
| 518 | |
| 519 | if (mwifiex_shutdown_drv(adapter) == -EINPROGRESS) |
| 520 | wait_event_interruptible(adapter->init_wait_q, |
| 521 | adapter->init_wait_q_woken); |
| 522 | } |
| 523 | adapter->surprise_removed = true; |
| 524 | mwifiex_terminate_workqueue(adapter); |
Amitkumar Karwar | c3afd99 | 2013-07-30 17:18:15 -0700 | [diff] [blame] | 525 | init_failed = true; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 526 | done: |
Amitkumar Karwar | 388ec38 | 2013-05-17 17:50:25 -0700 | [diff] [blame] | 527 | if (adapter->cal_data) { |
| 528 | release_firmware(adapter->cal_data); |
| 529 | adapter->cal_data = NULL; |
| 530 | } |
Amitkumar Karwar | c3afd99 | 2013-07-30 17:18:15 -0700 | [diff] [blame] | 531 | if (adapter->firmware) { |
| 532 | release_firmware(adapter->firmware); |
| 533 | adapter->firmware = NULL; |
| 534 | } |
Amitkumar Karwar | c3afd99 | 2013-07-30 17:18:15 -0700 | [diff] [blame] | 535 | if (init_failed) |
| 536 | mwifiex_free_adapter(adapter); |
| 537 | up(sem); |
Amitkumar Karwar | 59a4cc2 | 2012-04-09 20:06:57 -0700 | [diff] [blame] | 538 | return; |
| 539 | } |
| 540 | |
| 541 | /* |
| 542 | * This function initializes the hardware and gets firmware. |
| 543 | */ |
| 544 | static int mwifiex_init_hw_fw(struct mwifiex_adapter *adapter) |
| 545 | { |
| 546 | int ret; |
| 547 | |
Amitkumar Karwar | 59a4cc2 | 2012-04-09 20:06:57 -0700 | [diff] [blame] | 548 | ret = request_firmware_nowait(THIS_MODULE, 1, adapter->fw_name, |
| 549 | adapter->dev, GFP_KERNEL, adapter, |
| 550 | mwifiex_fw_dpc); |
| 551 | if (ret < 0) |
| 552 | dev_err(adapter->dev, |
| 553 | "request_firmware_nowait() returned error %d\n", ret); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 554 | return ret; |
| 555 | } |
| 556 | |
| 557 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 558 | * CFG802.11 network device handler for open. |
| 559 | * |
| 560 | * Starts the data queue. |
| 561 | */ |
| 562 | static int |
| 563 | mwifiex_open(struct net_device *dev) |
| 564 | { |
Avinash Patil | bbea3bc | 2011-12-08 20:41:05 -0800 | [diff] [blame] | 565 | netif_tx_start_all_queues(dev); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 566 | return 0; |
| 567 | } |
| 568 | |
| 569 | /* |
| 570 | * CFG802.11 network device handler for close. |
| 571 | */ |
| 572 | static int |
| 573 | mwifiex_close(struct net_device *dev) |
| 574 | { |
Amitkumar Karwar | f162cac | 2012-10-19 19:19:16 -0700 | [diff] [blame] | 575 | struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); |
| 576 | |
| 577 | if (priv->scan_request) { |
| 578 | dev_dbg(priv->adapter->dev, "aborting scan on ndo_stop\n"); |
| 579 | cfg80211_scan_done(priv->scan_request, 1); |
| 580 | priv->scan_request = NULL; |
Amitkumar Karwar | 75ab753 | 2013-05-17 17:50:20 -0700 | [diff] [blame] | 581 | priv->scan_aborting = true; |
Amitkumar Karwar | f162cac | 2012-10-19 19:19:16 -0700 | [diff] [blame] | 582 | } |
| 583 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 584 | return 0; |
| 585 | } |
| 586 | |
| 587 | /* |
Stone Piao | e39faa7 | 2012-09-25 20:23:32 -0700 | [diff] [blame] | 588 | * Add buffer into wmm tx queue and queue work to transmit it. |
| 589 | */ |
| 590 | int mwifiex_queue_tx_pkt(struct mwifiex_private *priv, struct sk_buff *skb) |
| 591 | { |
Avinash Patil | 47411a0 | 2012-11-01 18:44:16 -0700 | [diff] [blame] | 592 | struct netdev_queue *txq; |
| 593 | int index = mwifiex_1d_to_wmm_queue[skb->priority]; |
| 594 | |
| 595 | if (atomic_inc_return(&priv->wmm_tx_pending[index]) >= MAX_TX_PENDING) { |
| 596 | txq = netdev_get_tx_queue(priv->netdev, index); |
| 597 | if (!netif_tx_queue_stopped(txq)) { |
| 598 | netif_tx_stop_queue(txq); |
| 599 | dev_dbg(priv->adapter->dev, "stop queue: %d\n", index); |
| 600 | } |
| 601 | } |
| 602 | |
Stone Piao | e39faa7 | 2012-09-25 20:23:32 -0700 | [diff] [blame] | 603 | atomic_inc(&priv->adapter->tx_pending); |
Avinash Patil | 47411a0 | 2012-11-01 18:44:16 -0700 | [diff] [blame] | 604 | mwifiex_wmm_add_buf_txqueue(priv, skb); |
Stone Piao | e39faa7 | 2012-09-25 20:23:32 -0700 | [diff] [blame] | 605 | |
Stone Piao | e39faa7 | 2012-09-25 20:23:32 -0700 | [diff] [blame] | 606 | queue_work(priv->adapter->workqueue, &priv->adapter->main_work); |
| 607 | |
| 608 | return 0; |
| 609 | } |
| 610 | |
Amitkumar Karwar | 18ca438 | 2014-11-25 06:43:06 -0800 | [diff] [blame] | 611 | struct sk_buff * |
Amitkumar Karwar | 808bbeb | 2014-11-25 06:43:05 -0800 | [diff] [blame] | 612 | mwifiex_clone_skb_for_tx_status(struct mwifiex_private *priv, |
Amitkumar Karwar | 18ca438 | 2014-11-25 06:43:06 -0800 | [diff] [blame] | 613 | struct sk_buff *skb, u8 flag, u64 *cookie) |
Amitkumar Karwar | 808bbeb | 2014-11-25 06:43:05 -0800 | [diff] [blame] | 614 | { |
| 615 | struct sk_buff *orig_skb = skb; |
| 616 | struct mwifiex_txinfo *tx_info, *orig_tx_info; |
| 617 | |
| 618 | skb = skb_clone(skb, GFP_ATOMIC); |
| 619 | if (skb) { |
| 620 | unsigned long flags; |
| 621 | int id; |
| 622 | |
| 623 | spin_lock_irqsave(&priv->ack_status_lock, flags); |
| 624 | id = idr_alloc(&priv->ack_status_frames, orig_skb, |
| 625 | 1, 0xff, GFP_ATOMIC); |
| 626 | spin_unlock_irqrestore(&priv->ack_status_lock, flags); |
| 627 | |
| 628 | if (id >= 0) { |
| 629 | tx_info = MWIFIEX_SKB_TXCB(skb); |
| 630 | tx_info->ack_frame_id = id; |
| 631 | tx_info->flags |= flag; |
| 632 | orig_tx_info = MWIFIEX_SKB_TXCB(orig_skb); |
| 633 | orig_tx_info->ack_frame_id = id; |
| 634 | orig_tx_info->flags |= flag; |
Amitkumar Karwar | 18ca438 | 2014-11-25 06:43:06 -0800 | [diff] [blame] | 635 | |
| 636 | if (flag == MWIFIEX_BUF_FLAG_ACTION_TX_STATUS && cookie) |
| 637 | orig_tx_info->cookie = *cookie; |
| 638 | |
Amitkumar Karwar | 808bbeb | 2014-11-25 06:43:05 -0800 | [diff] [blame] | 639 | } else if (skb_shared(skb)) { |
| 640 | kfree_skb(orig_skb); |
| 641 | } else { |
| 642 | kfree_skb(skb); |
| 643 | skb = orig_skb; |
| 644 | } |
| 645 | } else { |
| 646 | /* couldn't clone -- lose tx status ... */ |
| 647 | skb = orig_skb; |
| 648 | } |
| 649 | |
| 650 | return skb; |
| 651 | } |
| 652 | |
Stone Piao | e39faa7 | 2012-09-25 20:23:32 -0700 | [diff] [blame] | 653 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 654 | * CFG802.11 network device handler for data transmission. |
| 655 | */ |
| 656 | static int |
| 657 | mwifiex_hard_start_xmit(struct sk_buff *skb, struct net_device *dev) |
| 658 | { |
| 659 | struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 660 | struct sk_buff *new_skb; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 661 | struct mwifiex_txinfo *tx_info; |
Amitkumar Karwar | 808bbeb | 2014-11-25 06:43:05 -0800 | [diff] [blame] | 662 | bool multicast; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 663 | |
Yogesh Ashok Powar | 9da9a3b | 2012-01-11 20:06:11 -0800 | [diff] [blame] | 664 | dev_dbg(priv->adapter->dev, "data: %lu BSS(%d-%d): Data <= kernel\n", |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 665 | jiffies, priv->bss_type, priv->bss_num); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 666 | |
| 667 | if (priv->adapter->surprise_removed) { |
Christoph Fritz | b53575e | 2011-05-08 22:50:09 +0200 | [diff] [blame] | 668 | kfree_skb(skb); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 669 | priv->stats.tx_dropped++; |
| 670 | return 0; |
| 671 | } |
| 672 | if (!skb->len || (skb->len > ETH_FRAME_LEN)) { |
| 673 | dev_err(priv->adapter->dev, "Tx: bad skb len %d\n", skb->len); |
Christoph Fritz | b53575e | 2011-05-08 22:50:09 +0200 | [diff] [blame] | 674 | kfree_skb(skb); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 675 | priv->stats.tx_dropped++; |
| 676 | return 0; |
| 677 | } |
| 678 | if (skb_headroom(skb) < MWIFIEX_MIN_DATA_HEADER_LEN) { |
| 679 | dev_dbg(priv->adapter->dev, |
| 680 | "data: Tx: insufficient skb headroom %d\n", |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 681 | skb_headroom(skb)); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 682 | /* Insufficient skb headroom - allocate a new skb */ |
| 683 | new_skb = |
| 684 | skb_realloc_headroom(skb, MWIFIEX_MIN_DATA_HEADER_LEN); |
| 685 | if (unlikely(!new_skb)) { |
| 686 | dev_err(priv->adapter->dev, "Tx: cannot alloca new_skb\n"); |
Christoph Fritz | b53575e | 2011-05-08 22:50:09 +0200 | [diff] [blame] | 687 | kfree_skb(skb); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 688 | priv->stats.tx_dropped++; |
| 689 | return 0; |
| 690 | } |
| 691 | kfree_skb(skb); |
| 692 | skb = new_skb; |
| 693 | dev_dbg(priv->adapter->dev, "info: new skb headroomd %d\n", |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 694 | skb_headroom(skb)); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | tx_info = MWIFIEX_SKB_TXCB(skb); |
Amitkumar Karwar | d76744a | 2014-06-20 11:45:25 -0700 | [diff] [blame] | 698 | memset(tx_info, 0, sizeof(*tx_info)); |
Yogesh Ashok Powar | 9da9a3b | 2012-01-11 20:06:11 -0800 | [diff] [blame] | 699 | tx_info->bss_num = priv->bss_num; |
| 700 | tx_info->bss_type = priv->bss_type; |
Ujjal Roy | a1ed484 | 2013-12-02 23:17:55 -0800 | [diff] [blame] | 701 | tx_info->pkt_len = skb->len; |
Avinash Patil | 47411a0 | 2012-11-01 18:44:16 -0700 | [diff] [blame] | 702 | |
Amitkumar Karwar | 808bbeb | 2014-11-25 06:43:05 -0800 | [diff] [blame] | 703 | multicast = is_multicast_ether_addr(skb->data); |
| 704 | |
| 705 | if (unlikely(!multicast && skb->sk && |
| 706 | skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS && |
| 707 | priv->adapter->fw_api_ver == MWIFIEX_FW_V15)) |
| 708 | skb = mwifiex_clone_skb_for_tx_status(priv, |
| 709 | skb, |
Amitkumar Karwar | 18ca438 | 2014-11-25 06:43:06 -0800 | [diff] [blame] | 710 | MWIFIEX_BUF_FLAG_EAPOL_TX_STATUS, NULL); |
Amitkumar Karwar | 808bbeb | 2014-11-25 06:43:05 -0800 | [diff] [blame] | 711 | |
Avinash Patil | 47411a0 | 2012-11-01 18:44:16 -0700 | [diff] [blame] | 712 | /* Record the current time the packet was queued; used to |
| 713 | * determine the amount of time the packet was queued in |
| 714 | * the driver before it was sent to the firmware. |
| 715 | * The delay is then sent along with the packet to the |
| 716 | * firmware for aggregate delay calculation for stats and |
| 717 | * MSDU lifetime expiry. |
| 718 | */ |
Thomas Gleixner | c64800e | 2014-06-12 08:31:34 +0100 | [diff] [blame] | 719 | __net_timestamp(skb); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 720 | |
Avinash Patil | 9927baa | 2014-11-13 21:54:16 +0530 | [diff] [blame] | 721 | if (ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) && |
| 722 | priv->bss_type == MWIFIEX_BSS_TYPE_STA && |
| 723 | !ether_addr_equal_unaligned(priv->cfg_bssid, skb->data)) { |
| 724 | if (priv->adapter->auto_tdls && priv->check_tdls_tx) |
| 725 | mwifiex_tdls_check_tx(priv, skb); |
| 726 | } |
| 727 | |
Stone Piao | e39faa7 | 2012-09-25 20:23:32 -0700 | [diff] [blame] | 728 | mwifiex_queue_tx_pkt(priv, skb); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 729 | |
| 730 | return 0; |
| 731 | } |
| 732 | |
| 733 | /* |
| 734 | * CFG802.11 network device handler for setting MAC address. |
| 735 | */ |
| 736 | static int |
| 737 | mwifiex_set_mac_address(struct net_device *dev, void *addr) |
| 738 | { |
| 739 | struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); |
Amitkumar Karwar | a5ffddb | 2011-06-20 15:21:48 -0700 | [diff] [blame] | 740 | struct sockaddr *hw_addr = addr; |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 741 | int ret; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 742 | |
| 743 | memcpy(priv->curr_addr, hw_addr->sa_data, ETH_ALEN); |
| 744 | |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 745 | /* Send request to firmware */ |
Bing Zhao | fa0ecbb | 2014-02-27 19:35:12 -0800 | [diff] [blame] | 746 | ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_MAC_ADDRESS, |
| 747 | HostCmd_ACT_GEN_SET, 0, NULL, true); |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 748 | |
| 749 | if (!ret) |
| 750 | memcpy(priv->netdev->dev_addr, priv->curr_addr, ETH_ALEN); |
| 751 | else |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 752 | dev_err(priv->adapter->dev, |
| 753 | "set mac address failed: ret=%d\n", ret); |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 754 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 755 | memcpy(dev->dev_addr, priv->curr_addr, ETH_ALEN); |
| 756 | |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 757 | return ret; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 758 | } |
| 759 | |
| 760 | /* |
| 761 | * CFG802.11 network device handler for setting multicast list. |
| 762 | */ |
| 763 | static void mwifiex_set_multicast_list(struct net_device *dev) |
| 764 | { |
| 765 | struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 766 | struct mwifiex_multicast_list mcast_list; |
| 767 | |
| 768 | if (dev->flags & IFF_PROMISC) { |
| 769 | mcast_list.mode = MWIFIEX_PROMISC_MODE; |
| 770 | } else if (dev->flags & IFF_ALLMULTI || |
| 771 | netdev_mc_count(dev) > MWIFIEX_MAX_MULTICAST_LIST_SIZE) { |
| 772 | mcast_list.mode = MWIFIEX_ALL_MULTI_MODE; |
| 773 | } else { |
| 774 | mcast_list.mode = MWIFIEX_MULTICAST_MODE; |
Daniel Drake | 6390d88 | 2013-06-14 15:24:24 -0400 | [diff] [blame] | 775 | mcast_list.num_multicast_addr = |
| 776 | mwifiex_copy_mcast_addr(&mcast_list, dev); |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 777 | } |
| 778 | mwifiex_request_set_multicast_list(priv, &mcast_list); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | /* |
| 782 | * CFG802.11 network device handler for transmission timeout. |
| 783 | */ |
| 784 | static void |
| 785 | mwifiex_tx_timeout(struct net_device *dev) |
| 786 | { |
| 787 | struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); |
| 788 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 789 | priv->num_tx_timeout++; |
Ashok Nagarajan | 8908c7d | 2013-03-08 10:58:45 -0800 | [diff] [blame] | 790 | priv->tx_timeout_cnt++; |
| 791 | dev_err(priv->adapter->dev, |
| 792 | "%lu : Tx timeout(#%d), bss_type-num = %d-%d\n", |
| 793 | jiffies, priv->tx_timeout_cnt, priv->bss_type, priv->bss_num); |
| 794 | mwifiex_set_trans_start(dev); |
| 795 | |
| 796 | if (priv->tx_timeout_cnt > TX_TIMEOUT_THRESHOLD && |
| 797 | priv->adapter->if_ops.card_reset) { |
| 798 | dev_err(priv->adapter->dev, |
| 799 | "tx_timeout_cnt exceeds threshold. Triggering card reset!\n"); |
| 800 | priv->adapter->if_ops.card_reset(priv->adapter); |
| 801 | } |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 802 | } |
| 803 | |
Xinming Hu | 11cd07a | 2014-12-23 19:14:10 +0530 | [diff] [blame] | 804 | void mwifiex_dump_drv_info(struct mwifiex_adapter *adapter) |
| 805 | { |
| 806 | void *p; |
| 807 | char drv_version[64]; |
| 808 | struct usb_card_rec *cardp; |
| 809 | struct sdio_mmc_card *sdio_card; |
| 810 | struct mwifiex_private *priv; |
| 811 | int i, idx; |
| 812 | struct netdev_queue *txq; |
| 813 | struct mwifiex_debug_info *debug_info; |
| 814 | |
| 815 | if (adapter->drv_info_dump) { |
| 816 | vfree(adapter->drv_info_dump); |
| 817 | adapter->drv_info_size = 0; |
| 818 | } |
| 819 | |
| 820 | dev_info(adapter->dev, "=== DRIVER INFO DUMP START===\n"); |
| 821 | |
| 822 | adapter->drv_info_dump = vzalloc(MWIFIEX_DRV_INFO_SIZE_MAX); |
| 823 | |
| 824 | if (!adapter->drv_info_dump) |
| 825 | return; |
| 826 | |
| 827 | p = (char *)(adapter->drv_info_dump); |
| 828 | p += sprintf(p, "driver_name = " "\"mwifiex\"\n"); |
| 829 | |
| 830 | mwifiex_drv_get_driver_version(adapter, drv_version, |
| 831 | sizeof(drv_version) - 1); |
| 832 | p += sprintf(p, "driver_version = %s\n", drv_version); |
| 833 | |
| 834 | if (adapter->iface_type == MWIFIEX_USB) { |
| 835 | cardp = (struct usb_card_rec *)adapter->card; |
| 836 | p += sprintf(p, "tx_cmd_urb_pending = %d\n", |
| 837 | atomic_read(&cardp->tx_cmd_urb_pending)); |
| 838 | p += sprintf(p, "tx_data_urb_pending = %d\n", |
| 839 | atomic_read(&cardp->tx_data_urb_pending)); |
| 840 | p += sprintf(p, "rx_cmd_urb_pending = %d\n", |
| 841 | atomic_read(&cardp->rx_cmd_urb_pending)); |
| 842 | p += sprintf(p, "rx_data_urb_pending = %d\n", |
| 843 | atomic_read(&cardp->rx_data_urb_pending)); |
| 844 | } |
| 845 | |
| 846 | p += sprintf(p, "tx_pending = %d\n", |
| 847 | atomic_read(&adapter->tx_pending)); |
| 848 | p += sprintf(p, "rx_pending = %d\n", |
| 849 | atomic_read(&adapter->rx_pending)); |
| 850 | |
| 851 | if (adapter->iface_type == MWIFIEX_SDIO) { |
| 852 | sdio_card = (struct sdio_mmc_card *)adapter->card; |
| 853 | p += sprintf(p, "\nmp_rd_bitmap=0x%x curr_rd_port=0x%x\n", |
| 854 | sdio_card->mp_rd_bitmap, sdio_card->curr_rd_port); |
| 855 | p += sprintf(p, "mp_wr_bitmap=0x%x curr_wr_port=0x%x\n", |
| 856 | sdio_card->mp_wr_bitmap, sdio_card->curr_wr_port); |
| 857 | } |
| 858 | |
| 859 | for (i = 0; i < adapter->priv_num; i++) { |
| 860 | if (!adapter->priv[i] || !adapter->priv[i]->netdev) |
| 861 | continue; |
| 862 | priv = adapter->priv[i]; |
| 863 | p += sprintf(p, "\n[interface : \"%s\"]\n", |
| 864 | priv->netdev->name); |
| 865 | p += sprintf(p, "wmm_tx_pending[0] = %d\n", |
| 866 | atomic_read(&priv->wmm_tx_pending[0])); |
| 867 | p += sprintf(p, "wmm_tx_pending[1] = %d\n", |
| 868 | atomic_read(&priv->wmm_tx_pending[1])); |
| 869 | p += sprintf(p, "wmm_tx_pending[2] = %d\n", |
| 870 | atomic_read(&priv->wmm_tx_pending[2])); |
| 871 | p += sprintf(p, "wmm_tx_pending[3] = %d\n", |
| 872 | atomic_read(&priv->wmm_tx_pending[3])); |
| 873 | p += sprintf(p, "media_state=\"%s\"\n", !priv->media_connected ? |
| 874 | "Disconnected" : "Connected"); |
| 875 | p += sprintf(p, "carrier %s\n", (netif_carrier_ok(priv->netdev) |
| 876 | ? "on" : "off")); |
| 877 | for (idx = 0; idx < priv->netdev->num_tx_queues; idx++) { |
| 878 | txq = netdev_get_tx_queue(priv->netdev, idx); |
| 879 | p += sprintf(p, "tx queue %d:%s ", idx, |
| 880 | netif_tx_queue_stopped(txq) ? |
| 881 | "stopped" : "started"); |
| 882 | } |
| 883 | p += sprintf(p, "\n%s: num_tx_timeout = %d\n", |
| 884 | priv->netdev->name, priv->num_tx_timeout); |
| 885 | } |
| 886 | |
Xinming Hu | 809c6ea | 2014-12-23 19:14:11 +0530 | [diff] [blame] | 887 | if (adapter->iface_type == MWIFIEX_SDIO) { |
| 888 | p += sprintf(p, "\n=== SDIO register DUMP===\n"); |
| 889 | if (adapter->if_ops.reg_dump) |
| 890 | p += adapter->if_ops.reg_dump(adapter, p); |
| 891 | } |
| 892 | |
Xinming Hu | 11cd07a | 2014-12-23 19:14:10 +0530 | [diff] [blame] | 893 | p += sprintf(p, "\n=== MORE DEBUG INFORMATION\n"); |
| 894 | debug_info = kzalloc(sizeof(*debug_info), GFP_KERNEL); |
| 895 | if (debug_info) { |
| 896 | for (i = 0; i < adapter->priv_num; i++) { |
| 897 | if (!adapter->priv[i] || !adapter->priv[i]->netdev) |
| 898 | continue; |
| 899 | priv = adapter->priv[i]; |
| 900 | mwifiex_get_debug_info(priv, debug_info); |
| 901 | p += mwifiex_debug_info_to_buffer(priv, p, debug_info); |
| 902 | break; |
| 903 | } |
| 904 | kfree(debug_info); |
| 905 | } |
| 906 | |
| 907 | adapter->drv_info_size = p - adapter->drv_info_dump; |
| 908 | dev_info(adapter->dev, "=== DRIVER INFO DUMP END===\n"); |
| 909 | } |
| 910 | EXPORT_SYMBOL_GPL(mwifiex_dump_drv_info); |
| 911 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 912 | /* |
| 913 | * CFG802.11 network device handler for statistics retrieval. |
| 914 | */ |
| 915 | static struct net_device_stats *mwifiex_get_stats(struct net_device *dev) |
| 916 | { |
| 917 | struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); |
| 918 | |
| 919 | return &priv->stats; |
| 920 | } |
| 921 | |
Avinash Patil | 47411a0 | 2012-11-01 18:44:16 -0700 | [diff] [blame] | 922 | static u16 |
Jason Wang | f663dd9 | 2014-01-10 16:18:26 +0800 | [diff] [blame] | 923 | mwifiex_netdev_select_wmm_queue(struct net_device *dev, struct sk_buff *skb, |
Daniel Borkmann | 99932d4 | 2014-02-16 15:55:20 +0100 | [diff] [blame] | 924 | void *accel_priv, select_queue_fallback_t fallback) |
Avinash Patil | 47411a0 | 2012-11-01 18:44:16 -0700 | [diff] [blame] | 925 | { |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 926 | skb->priority = cfg80211_classify8021d(skb, NULL); |
Avinash Patil | 47411a0 | 2012-11-01 18:44:16 -0700 | [diff] [blame] | 927 | return mwifiex_1d_to_wmm_queue[skb->priority]; |
| 928 | } |
| 929 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 930 | /* Network device handlers */ |
| 931 | static const struct net_device_ops mwifiex_netdev_ops = { |
| 932 | .ndo_open = mwifiex_open, |
| 933 | .ndo_stop = mwifiex_close, |
| 934 | .ndo_start_xmit = mwifiex_hard_start_xmit, |
| 935 | .ndo_set_mac_address = mwifiex_set_mac_address, |
| 936 | .ndo_tx_timeout = mwifiex_tx_timeout, |
| 937 | .ndo_get_stats = mwifiex_get_stats, |
Jiri Pirko | afc4b13 | 2011-08-16 06:29:01 +0000 | [diff] [blame] | 938 | .ndo_set_rx_mode = mwifiex_set_multicast_list, |
Avinash Patil | 47411a0 | 2012-11-01 18:44:16 -0700 | [diff] [blame] | 939 | .ndo_select_queue = mwifiex_netdev_select_wmm_queue, |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 940 | }; |
| 941 | |
| 942 | /* |
| 943 | * This function initializes the private structure parameters. |
| 944 | * |
| 945 | * The following wait queues are initialized - |
| 946 | * - IOCTL wait queue |
| 947 | * - Command wait queue |
| 948 | * - Statistics wait queue |
| 949 | * |
| 950 | * ...and the following default parameters are set - |
| 951 | * - Current key index : Set to 0 |
| 952 | * - Rate index : Set to auto |
| 953 | * - Media connected : Set to disconnected |
| 954 | * - Adhoc link sensed : Set to false |
| 955 | * - Nick name : Set to null |
| 956 | * - Number of Tx timeout : Set to 0 |
| 957 | * - Device address : Set to current address |
Xinming Hu | cbf6e05 | 2014-12-23 19:14:07 +0530 | [diff] [blame] | 958 | * - Rx histogram statistc : Set to 0 |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 959 | * |
| 960 | * In addition, the CFG80211 work queue is also created. |
| 961 | */ |
Yogesh Ashok Powar | 93a1df4 | 2011-09-26 20:37:26 -0700 | [diff] [blame] | 962 | void mwifiex_init_priv_params(struct mwifiex_private *priv, |
| 963 | struct net_device *dev) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 964 | { |
| 965 | dev->netdev_ops = &mwifiex_netdev_ops; |
Amitkumar Karwar | f16fdc9 | 2013-05-06 19:46:54 -0700 | [diff] [blame] | 966 | dev->destructor = free_netdev; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 967 | /* Initialize private structure */ |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 968 | priv->current_key_index = 0; |
| 969 | priv->media_connected = false; |
| 970 | memset(&priv->nick_name, 0, sizeof(priv->nick_name)); |
Avinash Patil | ede98bf | 2012-05-08 18:30:28 -0700 | [diff] [blame] | 971 | memset(priv->mgmt_ie, 0, |
| 972 | sizeof(struct mwifiex_ie) * MAX_MGMT_IE_INDEX); |
Avinash Patil | f31acab | 2012-05-08 18:30:29 -0700 | [diff] [blame] | 973 | priv->beacon_idx = MWIFIEX_AUTO_IDX_MASK; |
| 974 | priv->proberesp_idx = MWIFIEX_AUTO_IDX_MASK; |
| 975 | priv->assocresp_idx = MWIFIEX_AUTO_IDX_MASK; |
| 976 | priv->rsn_idx = MWIFIEX_AUTO_IDX_MASK; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 977 | priv->num_tx_timeout = 0; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 978 | memcpy(dev->dev_addr, priv->curr_addr, ETH_ALEN); |
Xinming Hu | cbf6e05 | 2014-12-23 19:14:07 +0530 | [diff] [blame] | 979 | |
| 980 | if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA || |
| 981 | GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) { |
| 982 | priv->hist_data = kmalloc(sizeof(*priv->hist_data), GFP_KERNEL); |
| 983 | if (priv->hist_data) |
| 984 | mwifiex_hist_data_reset(priv); |
| 985 | } |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 989 | * This function check if command is pending. |
| 990 | */ |
| 991 | int is_command_pending(struct mwifiex_adapter *adapter) |
| 992 | { |
| 993 | unsigned long flags; |
| 994 | int is_cmd_pend_q_empty; |
| 995 | |
| 996 | spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags); |
| 997 | is_cmd_pend_q_empty = list_empty(&adapter->cmd_pending_q); |
| 998 | spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, flags); |
| 999 | |
| 1000 | return !is_cmd_pend_q_empty; |
| 1001 | } |
| 1002 | |
| 1003 | /* |
Avinash Patil | 6e25117 | 2014-09-12 20:08:59 +0530 | [diff] [blame] | 1004 | * This is the RX work queue function. |
| 1005 | * |
| 1006 | * It handles the RX operations. |
| 1007 | */ |
| 1008 | static void mwifiex_rx_work_queue(struct work_struct *work) |
| 1009 | { |
| 1010 | struct mwifiex_adapter *adapter = |
| 1011 | container_of(work, struct mwifiex_adapter, rx_work); |
| 1012 | |
| 1013 | if (adapter->surprise_removed) |
| 1014 | return; |
| 1015 | mwifiex_process_rx(adapter); |
| 1016 | } |
| 1017 | |
| 1018 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1019 | * This is the main work queue function. |
| 1020 | * |
| 1021 | * It handles the main process, which in turn handles the complete |
| 1022 | * driver operations. |
| 1023 | */ |
| 1024 | static void mwifiex_main_work_queue(struct work_struct *work) |
| 1025 | { |
| 1026 | struct mwifiex_adapter *adapter = |
| 1027 | container_of(work, struct mwifiex_adapter, main_work); |
| 1028 | |
| 1029 | if (adapter->surprise_removed) |
| 1030 | return; |
| 1031 | mwifiex_main_process(adapter); |
| 1032 | } |
| 1033 | |
| 1034 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1035 | * This function adds the card. |
| 1036 | * |
| 1037 | * This function follows the following major steps to set up the device - |
| 1038 | * - Initialize software. This includes probing the card, registering |
| 1039 | * the interface operations table, and allocating/initializing the |
| 1040 | * adapter structure |
| 1041 | * - Set up the netlink socket |
| 1042 | * - Create and start the main work queue |
| 1043 | * - Register the device |
| 1044 | * - Initialize firmware and hardware |
| 1045 | * - Add logical interfaces |
| 1046 | */ |
| 1047 | int |
| 1048 | mwifiex_add_card(void *card, struct semaphore *sem, |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1049 | struct mwifiex_if_ops *if_ops, u8 iface_type) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1050 | { |
Amitkumar Karwar | 2be7859 | 2011-04-15 20:50:42 -0700 | [diff] [blame] | 1051 | struct mwifiex_adapter *adapter; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1052 | |
| 1053 | if (down_interruptible(sem)) |
| 1054 | goto exit_sem_err; |
| 1055 | |
Yogesh Ashok Powar | 93a1df4 | 2011-09-26 20:37:26 -0700 | [diff] [blame] | 1056 | if (mwifiex_register(card, if_ops, (void **)&adapter)) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1057 | pr_err("%s: software init failed\n", __func__); |
| 1058 | goto err_init_sw; |
| 1059 | } |
| 1060 | |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1061 | adapter->iface_type = iface_type; |
Amitkumar Karwar | 6b41f94 | 2013-07-22 19:17:55 -0700 | [diff] [blame] | 1062 | adapter->card_sem = sem; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1063 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1064 | adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1065 | adapter->surprise_removed = false; |
| 1066 | init_waitqueue_head(&adapter->init_wait_q); |
| 1067 | adapter->is_suspended = false; |
| 1068 | adapter->hs_activated = false; |
| 1069 | init_waitqueue_head(&adapter->hs_activate_wait_q); |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1070 | init_waitqueue_head(&adapter->cmd_wait_q.wait); |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1071 | adapter->cmd_wait_q.status = 0; |
Amitkumar Karwar | efaaa8b | 2011-10-12 20:28:06 -0700 | [diff] [blame] | 1072 | adapter->scan_wait_q_woken = false; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1073 | |
Avinash Patil | ec4a16b | 2014-11-05 17:04:27 +0530 | [diff] [blame] | 1074 | if ((num_possible_cpus() > 1) || adapter->iface_type == MWIFIEX_USB) { |
Avinash Patil | 6e25117 | 2014-09-12 20:08:59 +0530 | [diff] [blame] | 1075 | adapter->rx_work_enabled = true; |
| 1076 | pr_notice("rx work enabled, cpus %d\n", num_possible_cpus()); |
| 1077 | } |
| 1078 | |
Amitkumar Karwar | 448a71c | 2013-10-11 18:33:04 -0700 | [diff] [blame] | 1079 | adapter->workqueue = |
| 1080 | alloc_workqueue("MWIFIEX_WORK_QUEUE", |
| 1081 | WQ_HIGHPRI | WQ_MEM_RECLAIM | WQ_UNBOUND, 1); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1082 | if (!adapter->workqueue) |
| 1083 | goto err_kmalloc; |
| 1084 | |
| 1085 | INIT_WORK(&adapter->main_work, mwifiex_main_work_queue); |
Avinash Patil | 6e25117 | 2014-09-12 20:08:59 +0530 | [diff] [blame] | 1086 | |
| 1087 | if (adapter->rx_work_enabled) { |
| 1088 | adapter->rx_workqueue = alloc_workqueue("MWIFIEX_RX_WORK_QUEUE", |
| 1089 | WQ_HIGHPRI | |
| 1090 | WQ_MEM_RECLAIM | |
| 1091 | WQ_UNBOUND, 1); |
| 1092 | if (!adapter->rx_workqueue) |
| 1093 | goto err_kmalloc; |
| 1094 | |
| 1095 | INIT_WORK(&adapter->rx_work, mwifiex_rx_work_queue); |
| 1096 | } |
| 1097 | |
Amitkumar Karwar | 92c2538 | 2014-06-19 21:38:52 -0700 | [diff] [blame] | 1098 | if (adapter->if_ops.iface_work) |
| 1099 | INIT_WORK(&adapter->iface_work, adapter->if_ops.iface_work); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1100 | |
| 1101 | /* Register the device. Fill up the private data structure with relevant |
Daniel Drake | 232fde0 | 2013-07-13 10:57:10 -0400 | [diff] [blame] | 1102 | information from the card. */ |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1103 | if (adapter->if_ops.register_dev(adapter)) { |
| 1104 | pr_err("%s: failed to register mwifiex device\n", __func__); |
| 1105 | goto err_registerdev; |
| 1106 | } |
| 1107 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1108 | if (mwifiex_init_hw_fw(adapter)) { |
| 1109 | pr_err("%s: firmware init failed\n", __func__); |
| 1110 | goto err_init_fw; |
| 1111 | } |
Amitkumar Karwar | 2be7859 | 2011-04-15 20:50:42 -0700 | [diff] [blame] | 1112 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1113 | return 0; |
| 1114 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1115 | err_init_fw: |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1116 | pr_debug("info: %s: unregister device\n", __func__); |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 1117 | if (adapter->if_ops.unregister_dev) |
| 1118 | adapter->if_ops.unregister_dev(adapter); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1119 | if ((adapter->hw_status == MWIFIEX_HW_STATUS_FW_READY) || |
| 1120 | (adapter->hw_status == MWIFIEX_HW_STATUS_READY)) { |
| 1121 | pr_debug("info: %s: shutdown mwifiex\n", __func__); |
| 1122 | adapter->init_wait_q_woken = false; |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 1123 | |
| 1124 | if (mwifiex_shutdown_drv(adapter) == -EINPROGRESS) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1125 | wait_event_interruptible(adapter->init_wait_q, |
| 1126 | adapter->init_wait_q_woken); |
| 1127 | } |
Amitkumar Karwar | 6b41f94 | 2013-07-22 19:17:55 -0700 | [diff] [blame] | 1128 | err_registerdev: |
| 1129 | adapter->surprise_removed = true; |
| 1130 | mwifiex_terminate_workqueue(adapter); |
| 1131 | err_kmalloc: |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1132 | mwifiex_free_adapter(adapter); |
| 1133 | |
| 1134 | err_init_sw: |
| 1135 | up(sem); |
| 1136 | |
| 1137 | exit_sem_err: |
| 1138 | return -1; |
| 1139 | } |
| 1140 | EXPORT_SYMBOL_GPL(mwifiex_add_card); |
| 1141 | |
| 1142 | /* |
| 1143 | * This function removes the card. |
| 1144 | * |
| 1145 | * This function follows the following major steps to remove the device - |
| 1146 | * - Stop data traffic |
| 1147 | * - Shutdown firmware |
| 1148 | * - Remove the logical interfaces |
| 1149 | * - Terminate the work queue |
| 1150 | * - Unregister the device |
| 1151 | * - Free the adapter structure |
| 1152 | */ |
| 1153 | int mwifiex_remove_card(struct mwifiex_adapter *adapter, struct semaphore *sem) |
| 1154 | { |
| 1155 | struct mwifiex_private *priv = NULL; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1156 | int i; |
| 1157 | |
| 1158 | if (down_interruptible(sem)) |
| 1159 | goto exit_sem_err; |
| 1160 | |
| 1161 | if (!adapter) |
| 1162 | goto exit_remove; |
| 1163 | |
Daniel Drake | 232fde0 | 2013-07-13 10:57:10 -0400 | [diff] [blame] | 1164 | /* We can no longer handle interrupts once we start doing the teardown |
| 1165 | * below. */ |
| 1166 | if (adapter->if_ops.disable_int) |
| 1167 | adapter->if_ops.disable_int(adapter); |
| 1168 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1169 | adapter->surprise_removed = true; |
| 1170 | |
| 1171 | /* Stop data */ |
| 1172 | for (i = 0; i < adapter->priv_num; i++) { |
| 1173 | priv = adapter->priv[i]; |
Yogesh Ashok Powar | 93a1df4 | 2011-09-26 20:37:26 -0700 | [diff] [blame] | 1174 | if (priv && priv->netdev) { |
Avinash Patil | 47411a0 | 2012-11-01 18:44:16 -0700 | [diff] [blame] | 1175 | mwifiex_stop_net_dev_queue(priv->netdev, adapter); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1176 | if (netif_carrier_ok(priv->netdev)) |
| 1177 | netif_carrier_off(priv->netdev); |
| 1178 | } |
| 1179 | } |
| 1180 | |
| 1181 | dev_dbg(adapter->dev, "cmd: calling mwifiex_shutdown_drv...\n"); |
| 1182 | adapter->init_wait_q_woken = false; |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 1183 | |
| 1184 | if (mwifiex_shutdown_drv(adapter) == -EINPROGRESS) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1185 | wait_event_interruptible(adapter->init_wait_q, |
| 1186 | adapter->init_wait_q_woken); |
| 1187 | dev_dbg(adapter->dev, "cmd: mwifiex_shutdown_drv done\n"); |
| 1188 | if (atomic_read(&adapter->rx_pending) || |
| 1189 | atomic_read(&adapter->tx_pending) || |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1190 | atomic_read(&adapter->cmd_pending)) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1191 | dev_err(adapter->dev, "rx_pending=%d, tx_pending=%d, " |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1192 | "cmd_pending=%d\n", |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1193 | atomic_read(&adapter->rx_pending), |
| 1194 | atomic_read(&adapter->tx_pending), |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1195 | atomic_read(&adapter->cmd_pending)); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1196 | } |
| 1197 | |
Yogesh Ashok Powar | 93a1df4 | 2011-09-26 20:37:26 -0700 | [diff] [blame] | 1198 | for (i = 0; i < adapter->priv_num; i++) { |
| 1199 | priv = adapter->priv[i]; |
| 1200 | |
| 1201 | if (!priv) |
| 1202 | continue; |
| 1203 | |
| 1204 | rtnl_lock(); |
Amitkumar Karwar | 2da8cbf | 2012-02-03 20:34:02 -0800 | [diff] [blame] | 1205 | if (priv->wdev && priv->netdev) |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 1206 | mwifiex_del_virtual_intf(adapter->wiphy, priv->wdev); |
Yogesh Ashok Powar | 93a1df4 | 2011-09-26 20:37:26 -0700 | [diff] [blame] | 1207 | rtnl_unlock(); |
| 1208 | } |
| 1209 | |
Amitkumar Karwar | c2868ad | 2013-12-02 23:17:57 -0800 | [diff] [blame] | 1210 | wiphy_unregister(adapter->wiphy); |
| 1211 | wiphy_free(adapter->wiphy); |
Avinash Patil | 64b05e2 | 2012-05-08 18:30:13 -0700 | [diff] [blame] | 1212 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1213 | mwifiex_terminate_workqueue(adapter); |
| 1214 | |
| 1215 | /* Unregister device */ |
| 1216 | dev_dbg(adapter->dev, "info: unregister device\n"); |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 1217 | if (adapter->if_ops.unregister_dev) |
| 1218 | adapter->if_ops.unregister_dev(adapter); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1219 | /* Free adapter structure */ |
| 1220 | dev_dbg(adapter->dev, "info: free adapter\n"); |
| 1221 | mwifiex_free_adapter(adapter); |
| 1222 | |
| 1223 | exit_remove: |
| 1224 | up(sem); |
| 1225 | exit_sem_err: |
| 1226 | return 0; |
| 1227 | } |
| 1228 | EXPORT_SYMBOL_GPL(mwifiex_remove_card); |
| 1229 | |
| 1230 | /* |
| 1231 | * This function initializes the module. |
| 1232 | * |
| 1233 | * The debug FS is also initialized if configured. |
| 1234 | */ |
| 1235 | static int |
| 1236 | mwifiex_init_module(void) |
| 1237 | { |
| 1238 | #ifdef CONFIG_DEBUG_FS |
| 1239 | mwifiex_debugfs_init(); |
| 1240 | #endif |
| 1241 | return 0; |
| 1242 | } |
| 1243 | |
| 1244 | /* |
| 1245 | * This function cleans up the module. |
| 1246 | * |
| 1247 | * The debug FS is removed if available. |
| 1248 | */ |
| 1249 | static void |
| 1250 | mwifiex_cleanup_module(void) |
| 1251 | { |
| 1252 | #ifdef CONFIG_DEBUG_FS |
| 1253 | mwifiex_debugfs_remove(); |
| 1254 | #endif |
| 1255 | } |
| 1256 | |
| 1257 | module_init(mwifiex_init_module); |
| 1258 | module_exit(mwifiex_cleanup_module); |
| 1259 | |
| 1260 | MODULE_AUTHOR("Marvell International Ltd."); |
| 1261 | MODULE_DESCRIPTION("Marvell WiFi-Ex Driver version " VERSION); |
| 1262 | MODULE_VERSION(VERSION); |
| 1263 | MODULE_LICENSE("GPL v2"); |