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