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