blob: f1393868d04ceb627ceec52c6205a0f821ea3481 [file] [log] [blame]
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001/*
2 * Marvell Wireless LAN device driver: major functions
3 *
Xinming Hu65da33f2014-06-19 21:38:57 -07004 * Copyright (C) 2011-2014, Marvell International Ltd.
Bing Zhao5e6e3a92011-03-21 18:00:50 -07005 *
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
27const char driver_version[] = "mwifiex " VERSION " (%s) ";
Amitkumar Karwar388ec382013-05-17 17:50:25 -070028static char *cal_data_cfg;
29module_param(cal_data_cfg, charp, 0);
Bing Zhao5e6e3a92011-03-21 18:00:50 -070030
Bing Zhao5e6e3a92011-03-21 18:00:50 -070031/*
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 */
46static int mwifiex_register(void *card, struct mwifiex_if_ops *if_ops,
Amitkumar Karwar287546d2011-06-08 20:39:20 +053047 void **padapter)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070048{
Amitkumar Karwar2be78592011-04-15 20:50:42 -070049 struct mwifiex_adapter *adapter;
50 int i;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070051
52 adapter = kzalloc(sizeof(struct mwifiex_adapter), GFP_KERNEL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -070053 if (!adapter)
Christoph Fritzb53575e2011-05-08 22:50:09 +020054 return -ENOMEM;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070055
Amitkumar Karwar287546d2011-06-08 20:39:20 +053056 *padapter = adapter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070057 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 Karwar4daffe32012-04-18 20:08:28 -070063 if (adapter->if_ops.init_if)
64 if (adapter->if_ops.init_if(adapter))
65 goto error;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070066
67 adapter->priv_num = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070068
Avinash Patil64b05e22012-05-08 18:30:13 -070069 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 Patil64b05e22012-05-08 18:30:13 -070077 adapter->priv_num++;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070078 }
Amitkumar Karwar44b815c2011-09-29 20:43:41 -070079 mwifiex_init_lock_list(adapter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -070080
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 Zhao5e6e3a92011-03-21 18:00:50 -070085 return 0;
86
87error:
88 dev_dbg(adapter->dev, "info: leave mwifiex_register with error\n");
89
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -070090 for (i = 0; i < adapter->priv_num; i++)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070091 kfree(adapter->priv[i]);
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -070092
Bing Zhao5e6e3a92011-03-21 18:00:50 -070093 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 */
108static int mwifiex_unregister(struct mwifiex_adapter *adapter)
109{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700110 s32 i;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700111
Amitkumar Karwar4cfda672013-07-22 19:17:50 -0700112 if (adapter->if_ops.cleanup_if)
113 adapter->if_ops.cleanup_if(adapter);
114
Avinash Patil629873f2014-02-18 15:47:55 -0800115 del_timer_sync(&adapter->cmd_timer);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700116
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
129/*
130 * The main process.
131 *
132 * This function is the main procedure of the driver and handles various driver
133 * operations. It runs in a loop and provides the core functionalities.
134 *
135 * The main responsibilities of this function are -
136 * - Ensure concurrency control
137 * - Handle pending interrupts and call interrupt handlers
138 * - Wake up the card if required
139 * - Handle command responses and call response handlers
140 * - Handle events and call event handlers
141 * - Execute pending commands
142 * - Transmit pending data packets
143 */
144int mwifiex_main_process(struct mwifiex_adapter *adapter)
145{
146 int ret = 0;
147 unsigned long flags;
Amitkumar Karwar4daffe32012-04-18 20:08:28 -0700148 struct sk_buff *skb;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700149
150 spin_lock_irqsave(&adapter->main_proc_lock, flags);
151
152 /* Check if already processing */
153 if (adapter->mwifiex_processing) {
154 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
155 goto exit_main_proc;
156 } else {
157 adapter->mwifiex_processing = true;
158 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
159 }
160process_start:
161 do {
162 if ((adapter->hw_status == MWIFIEX_HW_STATUS_CLOSING) ||
163 (adapter->hw_status == MWIFIEX_HW_STATUS_NOT_READY))
164 break;
165
166 /* Handle pending interrupt if any */
167 if (adapter->int_status) {
168 if (adapter->hs_activated)
169 mwifiex_process_hs_config(adapter);
Amitkumar Karwar4daffe32012-04-18 20:08:28 -0700170 if (adapter->if_ops.process_int_status)
171 adapter->if_ops.process_int_status(adapter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700172 }
173
174 /* Need to wake up the card ? */
175 if ((adapter->ps_state == PS_STATE_SLEEP) &&
176 (adapter->pm_wakeup_card_req &&
177 !adapter->pm_wakeup_fw_try) &&
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -0700178 (is_command_pending(adapter) ||
179 !mwifiex_wmm_lists_empty(adapter))) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700180 adapter->pm_wakeup_fw_try = true;
181 adapter->if_ops.wakeup(adapter);
182 continue;
183 }
Amitkumar Karwar4daffe32012-04-18 20:08:28 -0700184
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700185 if (IS_CARD_RX_RCVD(adapter)) {
186 adapter->pm_wakeup_fw_try = false;
187 if (adapter->ps_state == PS_STATE_SLEEP)
188 adapter->ps_state = PS_STATE_AWAKE;
189 } else {
190 /* We have tried to wakeup the card already */
191 if (adapter->pm_wakeup_fw_try)
192 break;
193 if (adapter->ps_state != PS_STATE_AWAKE ||
194 adapter->tx_lock_flag)
195 break;
196
Avinash Patil5ec39ef2014-09-12 20:08:56 +0530197 if ((!adapter->scan_chan_gap_enabled &&
Avinash Patil5ec39ef2014-09-12 20:08:56 +0530198 adapter->scan_processing) || adapter->data_sent ||
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -0700199 mwifiex_wmm_lists_empty(adapter)) {
200 if (adapter->cmd_sent || adapter->curr_cmd ||
201 (!is_command_pending(adapter)))
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700202 break;
203 }
204 }
205
Amitkumar Karwar4daffe32012-04-18 20:08:28 -0700206 /* Check Rx data for USB */
207 if (adapter->iface_type == MWIFIEX_USB)
208 while ((skb = skb_dequeue(&adapter->usb_rx_data_q)))
209 mwifiex_handle_rx_packet(adapter, skb);
210
Amitkumar Karwar20474122014-04-14 15:31:05 -0700211 /* Check for event */
212 if (adapter->event_received) {
213 adapter->event_received = false;
214 mwifiex_process_event(adapter);
215 }
216
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700217 /* Check for Cmd Resp */
218 if (adapter->cmd_resp_received) {
219 adapter->cmd_resp_received = false;
220 mwifiex_process_cmdresp(adapter);
221
222 /* call mwifiex back when init_fw is done */
223 if (adapter->hw_status == MWIFIEX_HW_STATUS_INIT_DONE) {
224 adapter->hw_status = MWIFIEX_HW_STATUS_READY;
225 mwifiex_init_fw_complete(adapter);
226 }
227 }
228
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700229 /* Check if we need to confirm Sleep Request
230 received previously */
231 if (adapter->ps_state == PS_STATE_PRE_SLEEP) {
232 if (!adapter->cmd_sent && !adapter->curr_cmd)
233 mwifiex_check_ps_cond(adapter);
234 }
235
236 /* * The ps_state may have been changed during processing of
237 * Sleep Request event.
238 */
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -0700239 if ((adapter->ps_state == PS_STATE_SLEEP) ||
240 (adapter->ps_state == PS_STATE_PRE_SLEEP) ||
241 (adapter->ps_state == PS_STATE_SLEEP_CFM) ||
242 adapter->tx_lock_flag)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700243 continue;
244
245 if (!adapter->cmd_sent && !adapter->curr_cmd) {
246 if (mwifiex_exec_next_cmd(adapter) == -1) {
247 ret = -1;
248 break;
249 }
250 }
251
Avinash Patil5ec39ef2014-09-12 20:08:56 +0530252 if ((adapter->scan_chan_gap_enabled ||
Amitkumar Karward8d91252014-09-12 20:08:58 +0530253 !adapter->scan_processing) &&
Amitkumar Karwar3249ba72012-06-06 21:12:41 -0700254 !adapter->data_sent && !mwifiex_wmm_lists_empty(adapter)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700255 mwifiex_wmm_process_tx(adapter);
256 if (adapter->hs_activated) {
257 adapter->is_hs_configured = false;
258 mwifiex_hs_activated_event
259 (mwifiex_get_priv
260 (adapter, MWIFIEX_BSS_ROLE_ANY),
261 false);
262 }
263 }
264
265 if (adapter->delay_null_pkt && !adapter->cmd_sent &&
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -0700266 !adapter->curr_cmd && !is_command_pending(adapter) &&
267 mwifiex_wmm_lists_empty(adapter)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700268 if (!mwifiex_send_null_packet
269 (mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA),
270 MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET |
271 MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET)) {
272 adapter->delay_null_pkt = false;
273 adapter->ps_state = PS_STATE_SLEEP;
274 }
275 break;
276 }
277 } while (true);
278
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700279 spin_lock_irqsave(&adapter->main_proc_lock, flags);
Amitkumar Karwar453b0c32013-09-27 10:55:38 -0700280 if ((adapter->int_status) || IS_CARD_RX_RCVD(adapter)) {
281 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
282 goto process_start;
283 }
284
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700285 adapter->mwifiex_processing = false;
286 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
287
288exit_main_proc:
289 if (adapter->hw_status == MWIFIEX_HW_STATUS_CLOSING)
290 mwifiex_shutdown_drv(adapter);
291 return ret;
292}
Bing Zhao601216e2012-11-05 16:59:15 -0800293EXPORT_SYMBOL_GPL(mwifiex_main_process);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700294
295/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700296 * This function frees the adapter structure.
297 *
298 * Additionally, this closes the netlink socket, frees the timers
299 * and private structures.
300 */
301static void mwifiex_free_adapter(struct mwifiex_adapter *adapter)
302{
303 if (!adapter) {
304 pr_err("%s: adapter is NULL\n", __func__);
305 return;
306 }
307
308 mwifiex_unregister(adapter);
309 pr_debug("info: %s: free adapter\n", __func__);
310}
311
312/*
Amitkumar Karwar6b41f942013-07-22 19:17:55 -0700313 * This function cancels all works in the queue and destroys
314 * the main workqueue.
315 */
316static void mwifiex_terminate_workqueue(struct mwifiex_adapter *adapter)
317{
318 flush_workqueue(adapter->workqueue);
319 destroy_workqueue(adapter->workqueue);
320 adapter->workqueue = NULL;
321}
322
323/*
Amitkumar Karwar59a4cc22012-04-09 20:06:57 -0700324 * This function gets firmware and initializes it.
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700325 *
326 * The main initialization steps followed are -
327 * - Download the correct firmware to card
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700328 * - Issue the init commands to firmware
329 */
Amitkumar Karwar59a4cc22012-04-09 20:06:57 -0700330static void mwifiex_fw_dpc(const struct firmware *firmware, void *context)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700331{
Amitkumar Karwarbec568f2013-11-14 19:10:38 -0800332 int ret;
Amitkumar Karwar59a4cc22012-04-09 20:06:57 -0700333 char fmt[64];
334 struct mwifiex_private *priv;
335 struct mwifiex_adapter *adapter = context;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700336 struct mwifiex_fw_image fw;
Amitkumar Karwarc3afd992013-07-30 17:18:15 -0700337 struct semaphore *sem = adapter->card_sem;
338 bool init_failed = false;
Amitkumar Karwar68b76e92013-11-14 19:10:37 -0800339 struct wireless_dev *wdev;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700340
Amitkumar Karwar59a4cc22012-04-09 20:06:57 -0700341 if (!firmware) {
342 dev_err(adapter->dev,
343 "Failed to get firmware %s\n", adapter->fw_name);
Amitkumar Karwar6b41f942013-07-22 19:17:55 -0700344 goto err_dnld_fw;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700345 }
Amitkumar Karwar59a4cc22012-04-09 20:06:57 -0700346
347 memset(&fw, 0, sizeof(struct mwifiex_fw_image));
348 adapter->firmware = firmware;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700349 fw.fw_buf = (u8 *) adapter->firmware->data;
350 fw.fw_len = adapter->firmware->size;
351
Amitkumar Karwar4daffe32012-04-18 20:08:28 -0700352 if (adapter->if_ops.dnld_fw)
353 ret = adapter->if_ops.dnld_fw(adapter, &fw);
354 else
355 ret = mwifiex_dnld_fw(adapter, &fw);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700356 if (ret == -1)
Amitkumar Karwar6b41f942013-07-22 19:17:55 -0700357 goto err_dnld_fw;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700358
359 dev_notice(adapter->dev, "WLAN FW is active\n");
360
Amitkumar Karwar388ec382013-05-17 17:50:25 -0700361 if (cal_data_cfg) {
362 if ((request_firmware(&adapter->cal_data, cal_data_cfg,
363 adapter->dev)) < 0)
364 dev_err(adapter->dev,
365 "Cal data request_firmware() failed\n");
366 }
367
Daniel Drake232fde02013-07-13 10:57:10 -0400368 /* enable host interrupt after fw dnld is successful */
Amitkumar Karwar6b41f942013-07-22 19:17:55 -0700369 if (adapter->if_ops.enable_int) {
370 if (adapter->if_ops.enable_int(adapter))
371 goto err_dnld_fw;
372 }
Daniel Drake232fde02013-07-13 10:57:10 -0400373
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700374 adapter->init_wait_q_woken = false;
375 ret = mwifiex_init_fw(adapter);
376 if (ret == -1) {
Amitkumar Karwar6b41f942013-07-22 19:17:55 -0700377 goto err_init_fw;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700378 } else if (!ret) {
379 adapter->hw_status = MWIFIEX_HW_STATUS_READY;
380 goto done;
381 }
382 /* Wait for mwifiex_init to complete */
383 wait_event_interruptible(adapter->init_wait_q,
384 adapter->init_wait_q_woken);
Amitkumar Karwar59a4cc22012-04-09 20:06:57 -0700385 if (adapter->hw_status != MWIFIEX_HW_STATUS_READY)
Amitkumar Karwar6b41f942013-07-22 19:17:55 -0700386 goto err_init_fw;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700387
Avinash Patild6bffe82012-05-08 18:30:15 -0700388 priv = adapter->priv[MWIFIEX_BSS_ROLE_STA];
389 if (mwifiex_register_cfg80211(adapter)) {
Amitkumar Karwar59a4cc22012-04-09 20:06:57 -0700390 dev_err(adapter->dev, "cannot register with cfg80211\n");
Amitkumar Karward1af2942013-11-14 19:10:39 -0800391 goto err_init_fw;
Amitkumar Karwar59a4cc22012-04-09 20:06:57 -0700392 }
393
394 rtnl_lock();
395 /* Create station interface by default */
Amitkumar Karwar68b76e92013-11-14 19:10:37 -0800396 wdev = mwifiex_add_virtual_intf(adapter->wiphy, "mlan%d",
397 NL80211_IFTYPE_STATION, NULL, NULL);
398 if (IS_ERR(wdev)) {
Amitkumar Karwar59a4cc22012-04-09 20:06:57 -0700399 dev_err(adapter->dev, "cannot create default STA interface\n");
Amitkumar Karwarbec568f2013-11-14 19:10:38 -0800400 rtnl_unlock();
Amitkumar Karwar59a4cc22012-04-09 20:06:57 -0700401 goto err_add_intf;
402 }
403 rtnl_unlock();
404
405 mwifiex_drv_get_driver_version(adapter, fmt, sizeof(fmt) - 1);
406 dev_notice(adapter->dev, "driver_version = %s\n", fmt);
407 goto done;
408
409err_add_intf:
Amitkumar Karwar6b41f942013-07-22 19:17:55 -0700410 wiphy_unregister(adapter->wiphy);
411 wiphy_free(adapter->wiphy);
Amitkumar Karwar59a4cc22012-04-09 20:06:57 -0700412err_init_fw:
Daniel Drake232fde02013-07-13 10:57:10 -0400413 if (adapter->if_ops.disable_int)
414 adapter->if_ops.disable_int(adapter);
Amitkumar Karwar6b41f942013-07-22 19:17:55 -0700415err_dnld_fw:
Amitkumar Karwar59a4cc22012-04-09 20:06:57 -0700416 pr_debug("info: %s: unregister device\n", __func__);
Amitkumar Karwar6b41f942013-07-22 19:17:55 -0700417 if (adapter->if_ops.unregister_dev)
418 adapter->if_ops.unregister_dev(adapter);
419
420 if ((adapter->hw_status == MWIFIEX_HW_STATUS_FW_READY) ||
421 (adapter->hw_status == MWIFIEX_HW_STATUS_READY)) {
422 pr_debug("info: %s: shutdown mwifiex\n", __func__);
423 adapter->init_wait_q_woken = false;
424
425 if (mwifiex_shutdown_drv(adapter) == -EINPROGRESS)
426 wait_event_interruptible(adapter->init_wait_q,
427 adapter->init_wait_q_woken);
428 }
429 adapter->surprise_removed = true;
430 mwifiex_terminate_workqueue(adapter);
Amitkumar Karwarc3afd992013-07-30 17:18:15 -0700431 init_failed = true;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700432done:
Amitkumar Karwar388ec382013-05-17 17:50:25 -0700433 if (adapter->cal_data) {
434 release_firmware(adapter->cal_data);
435 adapter->cal_data = NULL;
436 }
Amitkumar Karwarc3afd992013-07-30 17:18:15 -0700437 if (adapter->firmware) {
438 release_firmware(adapter->firmware);
439 adapter->firmware = NULL;
440 }
Amitkumar Karwarc3afd992013-07-30 17:18:15 -0700441 if (init_failed)
442 mwifiex_free_adapter(adapter);
443 up(sem);
Amitkumar Karwar59a4cc22012-04-09 20:06:57 -0700444 return;
445}
446
447/*
448 * This function initializes the hardware and gets firmware.
449 */
450static int mwifiex_init_hw_fw(struct mwifiex_adapter *adapter)
451{
452 int ret;
453
Amitkumar Karwar59a4cc22012-04-09 20:06:57 -0700454 ret = request_firmware_nowait(THIS_MODULE, 1, adapter->fw_name,
455 adapter->dev, GFP_KERNEL, adapter,
456 mwifiex_fw_dpc);
457 if (ret < 0)
458 dev_err(adapter->dev,
459 "request_firmware_nowait() returned error %d\n", ret);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700460 return ret;
461}
462
463/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700464 * CFG802.11 network device handler for open.
465 *
466 * Starts the data queue.
467 */
468static int
469mwifiex_open(struct net_device *dev)
470{
Avinash Patilbbea3bc2011-12-08 20:41:05 -0800471 netif_tx_start_all_queues(dev);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700472 return 0;
473}
474
475/*
476 * CFG802.11 network device handler for close.
477 */
478static int
479mwifiex_close(struct net_device *dev)
480{
Amitkumar Karwarf162cac2012-10-19 19:19:16 -0700481 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
482
483 if (priv->scan_request) {
484 dev_dbg(priv->adapter->dev, "aborting scan on ndo_stop\n");
485 cfg80211_scan_done(priv->scan_request, 1);
486 priv->scan_request = NULL;
Amitkumar Karwar75ab7532013-05-17 17:50:20 -0700487 priv->scan_aborting = true;
Amitkumar Karwarf162cac2012-10-19 19:19:16 -0700488 }
489
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700490 return 0;
491}
492
493/*
Stone Piaoe39faa72012-09-25 20:23:32 -0700494 * Add buffer into wmm tx queue and queue work to transmit it.
495 */
496int mwifiex_queue_tx_pkt(struct mwifiex_private *priv, struct sk_buff *skb)
497{
Avinash Patil47411a02012-11-01 18:44:16 -0700498 struct netdev_queue *txq;
499 int index = mwifiex_1d_to_wmm_queue[skb->priority];
500
501 if (atomic_inc_return(&priv->wmm_tx_pending[index]) >= MAX_TX_PENDING) {
502 txq = netdev_get_tx_queue(priv->netdev, index);
503 if (!netif_tx_queue_stopped(txq)) {
504 netif_tx_stop_queue(txq);
505 dev_dbg(priv->adapter->dev, "stop queue: %d\n", index);
506 }
507 }
508
Stone Piaoe39faa72012-09-25 20:23:32 -0700509 atomic_inc(&priv->adapter->tx_pending);
Avinash Patil47411a02012-11-01 18:44:16 -0700510 mwifiex_wmm_add_buf_txqueue(priv, skb);
Stone Piaoe39faa72012-09-25 20:23:32 -0700511
Stone Piaoe39faa72012-09-25 20:23:32 -0700512 queue_work(priv->adapter->workqueue, &priv->adapter->main_work);
513
514 return 0;
515}
516
517/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700518 * CFG802.11 network device handler for data transmission.
519 */
520static int
521mwifiex_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
522{
523 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700524 struct sk_buff *new_skb;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700525 struct mwifiex_txinfo *tx_info;
526
Yogesh Ashok Powar9da9a3b2012-01-11 20:06:11 -0800527 dev_dbg(priv->adapter->dev, "data: %lu BSS(%d-%d): Data <= kernel\n",
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -0700528 jiffies, priv->bss_type, priv->bss_num);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700529
530 if (priv->adapter->surprise_removed) {
Christoph Fritzb53575e2011-05-08 22:50:09 +0200531 kfree_skb(skb);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700532 priv->stats.tx_dropped++;
533 return 0;
534 }
535 if (!skb->len || (skb->len > ETH_FRAME_LEN)) {
536 dev_err(priv->adapter->dev, "Tx: bad skb len %d\n", skb->len);
Christoph Fritzb53575e2011-05-08 22:50:09 +0200537 kfree_skb(skb);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700538 priv->stats.tx_dropped++;
539 return 0;
540 }
541 if (skb_headroom(skb) < MWIFIEX_MIN_DATA_HEADER_LEN) {
542 dev_dbg(priv->adapter->dev,
543 "data: Tx: insufficient skb headroom %d\n",
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -0700544 skb_headroom(skb));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700545 /* Insufficient skb headroom - allocate a new skb */
546 new_skb =
547 skb_realloc_headroom(skb, MWIFIEX_MIN_DATA_HEADER_LEN);
548 if (unlikely(!new_skb)) {
549 dev_err(priv->adapter->dev, "Tx: cannot alloca new_skb\n");
Christoph Fritzb53575e2011-05-08 22:50:09 +0200550 kfree_skb(skb);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700551 priv->stats.tx_dropped++;
552 return 0;
553 }
554 kfree_skb(skb);
555 skb = new_skb;
556 dev_dbg(priv->adapter->dev, "info: new skb headroomd %d\n",
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -0700557 skb_headroom(skb));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700558 }
559
560 tx_info = MWIFIEX_SKB_TXCB(skb);
Amitkumar Karward76744a2014-06-20 11:45:25 -0700561 memset(tx_info, 0, sizeof(*tx_info));
Yogesh Ashok Powar9da9a3b2012-01-11 20:06:11 -0800562 tx_info->bss_num = priv->bss_num;
563 tx_info->bss_type = priv->bss_type;
Ujjal Roya1ed4842013-12-02 23:17:55 -0800564 tx_info->pkt_len = skb->len;
Avinash Patil47411a02012-11-01 18:44:16 -0700565
566 /* Record the current time the packet was queued; used to
567 * determine the amount of time the packet was queued in
568 * the driver before it was sent to the firmware.
569 * The delay is then sent along with the packet to the
570 * firmware for aggregate delay calculation for stats and
571 * MSDU lifetime expiry.
572 */
Thomas Gleixnerc64800e2014-06-12 08:31:34 +0100573 __net_timestamp(skb);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700574
Stone Piaoe39faa72012-09-25 20:23:32 -0700575 mwifiex_queue_tx_pkt(priv, skb);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700576
577 return 0;
578}
579
580/*
581 * CFG802.11 network device handler for setting MAC address.
582 */
583static int
584mwifiex_set_mac_address(struct net_device *dev, void *addr)
585{
586 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700587 struct sockaddr *hw_addr = addr;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700588 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700589
590 memcpy(priv->curr_addr, hw_addr->sa_data, ETH_ALEN);
591
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700592 /* Send request to firmware */
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800593 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_MAC_ADDRESS,
594 HostCmd_ACT_GEN_SET, 0, NULL, true);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700595
596 if (!ret)
597 memcpy(priv->netdev->dev_addr, priv->curr_addr, ETH_ALEN);
598 else
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -0700599 dev_err(priv->adapter->dev,
600 "set mac address failed: ret=%d\n", ret);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700601
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700602 memcpy(dev->dev_addr, priv->curr_addr, ETH_ALEN);
603
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700604 return ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700605}
606
607/*
608 * CFG802.11 network device handler for setting multicast list.
609 */
610static void mwifiex_set_multicast_list(struct net_device *dev)
611{
612 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700613 struct mwifiex_multicast_list mcast_list;
614
615 if (dev->flags & IFF_PROMISC) {
616 mcast_list.mode = MWIFIEX_PROMISC_MODE;
617 } else if (dev->flags & IFF_ALLMULTI ||
618 netdev_mc_count(dev) > MWIFIEX_MAX_MULTICAST_LIST_SIZE) {
619 mcast_list.mode = MWIFIEX_ALL_MULTI_MODE;
620 } else {
621 mcast_list.mode = MWIFIEX_MULTICAST_MODE;
Daniel Drake6390d882013-06-14 15:24:24 -0400622 mcast_list.num_multicast_addr =
623 mwifiex_copy_mcast_addr(&mcast_list, dev);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700624 }
625 mwifiex_request_set_multicast_list(priv, &mcast_list);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700626}
627
628/*
629 * CFG802.11 network device handler for transmission timeout.
630 */
631static void
632mwifiex_tx_timeout(struct net_device *dev)
633{
634 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
635
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700636 priv->num_tx_timeout++;
Ashok Nagarajan8908c7d2013-03-08 10:58:45 -0800637 priv->tx_timeout_cnt++;
638 dev_err(priv->adapter->dev,
639 "%lu : Tx timeout(#%d), bss_type-num = %d-%d\n",
640 jiffies, priv->tx_timeout_cnt, priv->bss_type, priv->bss_num);
641 mwifiex_set_trans_start(dev);
642
643 if (priv->tx_timeout_cnt > TX_TIMEOUT_THRESHOLD &&
644 priv->adapter->if_ops.card_reset) {
645 dev_err(priv->adapter->dev,
646 "tx_timeout_cnt exceeds threshold. Triggering card reset!\n");
647 priv->adapter->if_ops.card_reset(priv->adapter);
648 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700649}
650
651/*
652 * CFG802.11 network device handler for statistics retrieval.
653 */
654static struct net_device_stats *mwifiex_get_stats(struct net_device *dev)
655{
656 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
657
658 return &priv->stats;
659}
660
Avinash Patil47411a02012-11-01 18:44:16 -0700661static u16
Jason Wangf663dd92014-01-10 16:18:26 +0800662mwifiex_netdev_select_wmm_queue(struct net_device *dev, struct sk_buff *skb,
Daniel Borkmann99932d42014-02-16 15:55:20 +0100663 void *accel_priv, select_queue_fallback_t fallback)
Avinash Patil47411a02012-11-01 18:44:16 -0700664{
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800665 skb->priority = cfg80211_classify8021d(skb, NULL);
Avinash Patil47411a02012-11-01 18:44:16 -0700666 return mwifiex_1d_to_wmm_queue[skb->priority];
667}
668
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700669/* Network device handlers */
670static const struct net_device_ops mwifiex_netdev_ops = {
671 .ndo_open = mwifiex_open,
672 .ndo_stop = mwifiex_close,
673 .ndo_start_xmit = mwifiex_hard_start_xmit,
674 .ndo_set_mac_address = mwifiex_set_mac_address,
675 .ndo_tx_timeout = mwifiex_tx_timeout,
676 .ndo_get_stats = mwifiex_get_stats,
Jiri Pirkoafc4b132011-08-16 06:29:01 +0000677 .ndo_set_rx_mode = mwifiex_set_multicast_list,
Avinash Patil47411a02012-11-01 18:44:16 -0700678 .ndo_select_queue = mwifiex_netdev_select_wmm_queue,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700679};
680
681/*
682 * This function initializes the private structure parameters.
683 *
684 * The following wait queues are initialized -
685 * - IOCTL wait queue
686 * - Command wait queue
687 * - Statistics wait queue
688 *
689 * ...and the following default parameters are set -
690 * - Current key index : Set to 0
691 * - Rate index : Set to auto
692 * - Media connected : Set to disconnected
693 * - Adhoc link sensed : Set to false
694 * - Nick name : Set to null
695 * - Number of Tx timeout : Set to 0
696 * - Device address : Set to current address
697 *
698 * In addition, the CFG80211 work queue is also created.
699 */
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -0700700void mwifiex_init_priv_params(struct mwifiex_private *priv,
701 struct net_device *dev)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700702{
703 dev->netdev_ops = &mwifiex_netdev_ops;
Amitkumar Karwarf16fdc92013-05-06 19:46:54 -0700704 dev->destructor = free_netdev;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700705 /* Initialize private structure */
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700706 priv->current_key_index = 0;
707 priv->media_connected = false;
708 memset(&priv->nick_name, 0, sizeof(priv->nick_name));
Avinash Patilede98bf2012-05-08 18:30:28 -0700709 memset(priv->mgmt_ie, 0,
710 sizeof(struct mwifiex_ie) * MAX_MGMT_IE_INDEX);
Avinash Patilf31acab2012-05-08 18:30:29 -0700711 priv->beacon_idx = MWIFIEX_AUTO_IDX_MASK;
712 priv->proberesp_idx = MWIFIEX_AUTO_IDX_MASK;
713 priv->assocresp_idx = MWIFIEX_AUTO_IDX_MASK;
714 priv->rsn_idx = MWIFIEX_AUTO_IDX_MASK;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700715 priv->num_tx_timeout = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700716 memcpy(dev->dev_addr, priv->curr_addr, ETH_ALEN);
717}
718
719/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700720 * This function check if command is pending.
721 */
722int is_command_pending(struct mwifiex_adapter *adapter)
723{
724 unsigned long flags;
725 int is_cmd_pend_q_empty;
726
727 spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags);
728 is_cmd_pend_q_empty = list_empty(&adapter->cmd_pending_q);
729 spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, flags);
730
731 return !is_cmd_pend_q_empty;
732}
733
734/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700735 * This is the main work queue function.
736 *
737 * It handles the main process, which in turn handles the complete
738 * driver operations.
739 */
740static void mwifiex_main_work_queue(struct work_struct *work)
741{
742 struct mwifiex_adapter *adapter =
743 container_of(work, struct mwifiex_adapter, main_work);
744
745 if (adapter->surprise_removed)
746 return;
747 mwifiex_main_process(adapter);
748}
749
750/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700751 * This function adds the card.
752 *
753 * This function follows the following major steps to set up the device -
754 * - Initialize software. This includes probing the card, registering
755 * the interface operations table, and allocating/initializing the
756 * adapter structure
757 * - Set up the netlink socket
758 * - Create and start the main work queue
759 * - Register the device
760 * - Initialize firmware and hardware
761 * - Add logical interfaces
762 */
763int
764mwifiex_add_card(void *card, struct semaphore *sem,
Amitkumar Karward930fae2011-10-11 17:41:21 -0700765 struct mwifiex_if_ops *if_ops, u8 iface_type)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700766{
Amitkumar Karwar2be78592011-04-15 20:50:42 -0700767 struct mwifiex_adapter *adapter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700768
769 if (down_interruptible(sem))
770 goto exit_sem_err;
771
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -0700772 if (mwifiex_register(card, if_ops, (void **)&adapter)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700773 pr_err("%s: software init failed\n", __func__);
774 goto err_init_sw;
775 }
776
Amitkumar Karward930fae2011-10-11 17:41:21 -0700777 adapter->iface_type = iface_type;
Amitkumar Karwar6b41f942013-07-22 19:17:55 -0700778 adapter->card_sem = sem;
Amitkumar Karward930fae2011-10-11 17:41:21 -0700779
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700780 adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700781 adapter->surprise_removed = false;
782 init_waitqueue_head(&adapter->init_wait_q);
783 adapter->is_suspended = false;
784 adapter->hs_activated = false;
785 init_waitqueue_head(&adapter->hs_activate_wait_q);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700786 init_waitqueue_head(&adapter->cmd_wait_q.wait);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700787 adapter->cmd_wait_q.status = 0;
Amitkumar Karwarefaaa8b2011-10-12 20:28:06 -0700788 adapter->scan_wait_q_woken = false;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700789
Amitkumar Karwar448a71c2013-10-11 18:33:04 -0700790 adapter->workqueue =
791 alloc_workqueue("MWIFIEX_WORK_QUEUE",
792 WQ_HIGHPRI | WQ_MEM_RECLAIM | WQ_UNBOUND, 1);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700793 if (!adapter->workqueue)
794 goto err_kmalloc;
795
796 INIT_WORK(&adapter->main_work, mwifiex_main_work_queue);
Amitkumar Karwar92c25382014-06-19 21:38:52 -0700797 if (adapter->if_ops.iface_work)
798 INIT_WORK(&adapter->iface_work, adapter->if_ops.iface_work);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700799
800 /* Register the device. Fill up the private data structure with relevant
Daniel Drake232fde02013-07-13 10:57:10 -0400801 information from the card. */
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700802 if (adapter->if_ops.register_dev(adapter)) {
803 pr_err("%s: failed to register mwifiex device\n", __func__);
804 goto err_registerdev;
805 }
806
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700807 if (mwifiex_init_hw_fw(adapter)) {
808 pr_err("%s: firmware init failed\n", __func__);
809 goto err_init_fw;
810 }
Amitkumar Karwar2be78592011-04-15 20:50:42 -0700811
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700812 return 0;
813
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700814err_init_fw:
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700815 pr_debug("info: %s: unregister device\n", __func__);
Amitkumar Karwar4daffe32012-04-18 20:08:28 -0700816 if (adapter->if_ops.unregister_dev)
817 adapter->if_ops.unregister_dev(adapter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700818 if ((adapter->hw_status == MWIFIEX_HW_STATUS_FW_READY) ||
819 (adapter->hw_status == MWIFIEX_HW_STATUS_READY)) {
820 pr_debug("info: %s: shutdown mwifiex\n", __func__);
821 adapter->init_wait_q_woken = false;
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700822
823 if (mwifiex_shutdown_drv(adapter) == -EINPROGRESS)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700824 wait_event_interruptible(adapter->init_wait_q,
825 adapter->init_wait_q_woken);
826 }
Amitkumar Karwar6b41f942013-07-22 19:17:55 -0700827err_registerdev:
828 adapter->surprise_removed = true;
829 mwifiex_terminate_workqueue(adapter);
830err_kmalloc:
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700831 mwifiex_free_adapter(adapter);
832
833err_init_sw:
834 up(sem);
835
836exit_sem_err:
837 return -1;
838}
839EXPORT_SYMBOL_GPL(mwifiex_add_card);
840
841/*
842 * This function removes the card.
843 *
844 * This function follows the following major steps to remove the device -
845 * - Stop data traffic
846 * - Shutdown firmware
847 * - Remove the logical interfaces
848 * - Terminate the work queue
849 * - Unregister the device
850 * - Free the adapter structure
851 */
852int mwifiex_remove_card(struct mwifiex_adapter *adapter, struct semaphore *sem)
853{
854 struct mwifiex_private *priv = NULL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700855 int i;
856
857 if (down_interruptible(sem))
858 goto exit_sem_err;
859
860 if (!adapter)
861 goto exit_remove;
862
Daniel Drake232fde02013-07-13 10:57:10 -0400863 /* We can no longer handle interrupts once we start doing the teardown
864 * below. */
865 if (adapter->if_ops.disable_int)
866 adapter->if_ops.disable_int(adapter);
867
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700868 adapter->surprise_removed = true;
869
870 /* Stop data */
871 for (i = 0; i < adapter->priv_num; i++) {
872 priv = adapter->priv[i];
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -0700873 if (priv && priv->netdev) {
Avinash Patil47411a02012-11-01 18:44:16 -0700874 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700875 if (netif_carrier_ok(priv->netdev))
876 netif_carrier_off(priv->netdev);
877 }
878 }
879
880 dev_dbg(adapter->dev, "cmd: calling mwifiex_shutdown_drv...\n");
881 adapter->init_wait_q_woken = false;
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700882
883 if (mwifiex_shutdown_drv(adapter) == -EINPROGRESS)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700884 wait_event_interruptible(adapter->init_wait_q,
885 adapter->init_wait_q_woken);
886 dev_dbg(adapter->dev, "cmd: mwifiex_shutdown_drv done\n");
887 if (atomic_read(&adapter->rx_pending) ||
888 atomic_read(&adapter->tx_pending) ||
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700889 atomic_read(&adapter->cmd_pending)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700890 dev_err(adapter->dev, "rx_pending=%d, tx_pending=%d, "
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700891 "cmd_pending=%d\n",
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700892 atomic_read(&adapter->rx_pending),
893 atomic_read(&adapter->tx_pending),
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700894 atomic_read(&adapter->cmd_pending));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700895 }
896
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -0700897 for (i = 0; i < adapter->priv_num; i++) {
898 priv = adapter->priv[i];
899
900 if (!priv)
901 continue;
902
903 rtnl_lock();
Amitkumar Karwar2da8cbf2012-02-03 20:34:02 -0800904 if (priv->wdev && priv->netdev)
Johannes Berg84efbb82012-06-16 00:00:26 +0200905 mwifiex_del_virtual_intf(adapter->wiphy, priv->wdev);
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -0700906 rtnl_unlock();
907 }
908
Amitkumar Karwarc2868ad2013-12-02 23:17:57 -0800909 wiphy_unregister(adapter->wiphy);
910 wiphy_free(adapter->wiphy);
Avinash Patil64b05e22012-05-08 18:30:13 -0700911
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700912 mwifiex_terminate_workqueue(adapter);
913
914 /* Unregister device */
915 dev_dbg(adapter->dev, "info: unregister device\n");
Amitkumar Karwar4daffe32012-04-18 20:08:28 -0700916 if (adapter->if_ops.unregister_dev)
917 adapter->if_ops.unregister_dev(adapter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700918 /* Free adapter structure */
919 dev_dbg(adapter->dev, "info: free adapter\n");
920 mwifiex_free_adapter(adapter);
921
922exit_remove:
923 up(sem);
924exit_sem_err:
925 return 0;
926}
927EXPORT_SYMBOL_GPL(mwifiex_remove_card);
928
929/*
930 * This function initializes the module.
931 *
932 * The debug FS is also initialized if configured.
933 */
934static int
935mwifiex_init_module(void)
936{
937#ifdef CONFIG_DEBUG_FS
938 mwifiex_debugfs_init();
939#endif
940 return 0;
941}
942
943/*
944 * This function cleans up the module.
945 *
946 * The debug FS is removed if available.
947 */
948static void
949mwifiex_cleanup_module(void)
950{
951#ifdef CONFIG_DEBUG_FS
952 mwifiex_debugfs_remove();
953#endif
954}
955
956module_init(mwifiex_init_module);
957module_exit(mwifiex_cleanup_module);
958
959MODULE_AUTHOR("Marvell International Ltd.");
960MODULE_DESCRIPTION("Marvell WiFi-Ex Driver version " VERSION);
961MODULE_VERSION(VERSION);
962MODULE_LICENSE("GPL v2");