blob: b242c3e8df3fe3dbb8785ee76179f80a22b14be2 [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
Avinash Patil0013c7c2014-11-05 19:38:11 +053031static unsigned short driver_mode;
32module_param(driver_mode, ushort, 0);
33MODULE_PARM_DESC(driver_mode,
34 "station=0x1(default), ap-sta=0x3, station-p2p=0x5, ap-sta-p2p=0x7");
35
Bing Zhao5e6e3a92011-03-21 18:00:50 -070036/*
37 * This function registers the device and performs all the necessary
38 * initializations.
39 *
40 * The following initialization operations are performed -
41 * - Allocate adapter structure
42 * - Save interface specific operations table in adapter
43 * - Call interface specific initialization routine
44 * - Allocate private structures
45 * - Set default adapter structure parameters
46 * - Initialize locks
47 *
48 * In case of any errors during inittialization, this function also ensures
49 * proper cleanup before exiting.
50 */
51static int mwifiex_register(void *card, struct mwifiex_if_ops *if_ops,
Amitkumar Karwar287546d2011-06-08 20:39:20 +053052 void **padapter)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070053{
Amitkumar Karwar2be78592011-04-15 20:50:42 -070054 struct mwifiex_adapter *adapter;
55 int i;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070056
57 adapter = kzalloc(sizeof(struct mwifiex_adapter), GFP_KERNEL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -070058 if (!adapter)
Christoph Fritzb53575e2011-05-08 22:50:09 +020059 return -ENOMEM;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070060
Amitkumar Karwar287546d2011-06-08 20:39:20 +053061 *padapter = adapter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070062 adapter->card = card;
63
64 /* Save interface specific operations in adapter */
65 memmove(&adapter->if_ops, if_ops, sizeof(struct mwifiex_if_ops));
66
67 /* card specific initialization has been deferred until now .. */
Amitkumar Karwar4daffe32012-04-18 20:08:28 -070068 if (adapter->if_ops.init_if)
69 if (adapter->if_ops.init_if(adapter))
70 goto error;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070071
72 adapter->priv_num = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070073
Avinash Patil64b05e22012-05-08 18:30:13 -070074 for (i = 0; i < MWIFIEX_MAX_BSS_NUM; i++) {
75 /* Allocate memory for private structure */
76 adapter->priv[i] =
77 kzalloc(sizeof(struct mwifiex_private), GFP_KERNEL);
78 if (!adapter->priv[i])
79 goto error;
80
81 adapter->priv[i]->adapter = adapter;
Avinash Patil64b05e22012-05-08 18:30:13 -070082 adapter->priv_num++;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070083 }
Amitkumar Karwar44b815c2011-09-29 20:43:41 -070084 mwifiex_init_lock_list(adapter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -070085
Julia Lawallc6c33e72014-12-26 15:35:56 +010086 setup_timer(&adapter->cmd_timer, mwifiex_cmd_timeout_func,
87 (unsigned long)adapter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -070088
Bing Zhao5e6e3a92011-03-21 18:00:50 -070089 return 0;
90
91error:
92 dev_dbg(adapter->dev, "info: leave mwifiex_register with error\n");
93
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -070094 for (i = 0; i < adapter->priv_num; i++)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070095 kfree(adapter->priv[i]);
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -070096
Bing Zhao5e6e3a92011-03-21 18:00:50 -070097 kfree(adapter);
98
99 return -1;
100}
101
102/*
103 * This function unregisters the device and performs all the necessary
104 * cleanups.
105 *
106 * The following cleanup operations are performed -
107 * - Free the timers
108 * - Free beacon buffers
109 * - Free private structures
110 * - Free adapter structure
111 */
112static int mwifiex_unregister(struct mwifiex_adapter *adapter)
113{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700114 s32 i;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700115
Amitkumar Karwar4cfda672013-07-22 19:17:50 -0700116 if (adapter->if_ops.cleanup_if)
117 adapter->if_ops.cleanup_if(adapter);
118
Avinash Patil629873f2014-02-18 15:47:55 -0800119 del_timer_sync(&adapter->cmd_timer);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700120
121 /* Free private structures */
122 for (i = 0; i < adapter->priv_num; i++) {
123 if (adapter->priv[i]) {
124 mwifiex_free_curr_bcn(adapter->priv[i]);
125 kfree(adapter->priv[i]);
126 }
127 }
128
Avinash Patilbf354432014-10-31 16:08:26 +0530129 vfree(adapter->chan_stats);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700130 kfree(adapter);
131 return 0;
132}
133
Shengzhen Lib2713f62015-03-13 17:37:54 +0530134void mwifiex_queue_main_work(struct mwifiex_adapter *adapter)
135{
136 unsigned long flags;
137
138 spin_lock_irqsave(&adapter->main_proc_lock, flags);
139 if (adapter->mwifiex_processing) {
140 adapter->more_task_flag = true;
141 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
142 } else {
143 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
144 queue_work(adapter->workqueue, &adapter->main_work);
145 }
146}
147EXPORT_SYMBOL_GPL(mwifiex_queue_main_work);
148
149static void mwifiex_queue_rx_work(struct mwifiex_adapter *adapter)
150{
151 unsigned long flags;
152
153 spin_lock_irqsave(&adapter->rx_proc_lock, flags);
154 if (adapter->rx_processing) {
155 spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
156 } else {
157 spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
158 queue_work(adapter->rx_workqueue, &adapter->rx_work);
159 }
160}
161
Avinash Patil6e251172014-09-12 20:08:59 +0530162static int mwifiex_process_rx(struct mwifiex_adapter *adapter)
163{
164 unsigned long flags;
165 struct sk_buff *skb;
Avinash Patil6e251172014-09-12 20:08:59 +0530166
167 spin_lock_irqsave(&adapter->rx_proc_lock, flags);
168 if (adapter->rx_processing || adapter->rx_locked) {
169 spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
170 goto exit_rx_proc;
171 } else {
172 adapter->rx_processing = true;
173 spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
174 }
175
176 /* Check for Rx data */
177 while ((skb = skb_dequeue(&adapter->rx_data_q))) {
178 atomic_dec(&adapter->rx_pending);
Amitkumar Karwar381e9ff2014-11-25 06:43:04 -0800179 if ((adapter->delay_main_work ||
180 adapter->iface_type == MWIFIEX_USB) &&
Avinash Patilb43a0d92014-09-29 21:44:14 +0530181 (atomic_read(&adapter->rx_pending) < LOW_RX_PENDING)) {
Amitkumar Karwarcf6a64f2014-11-05 17:04:29 +0530182 if (adapter->if_ops.submit_rem_rx_urbs)
183 adapter->if_ops.submit_rem_rx_urbs(adapter);
Avinash Patil6e251172014-09-12 20:08:59 +0530184 adapter->delay_main_work = false;
Shengzhen Lib2713f62015-03-13 17:37:54 +0530185 mwifiex_queue_main_work(adapter);
Avinash Patil6e251172014-09-12 20:08:59 +0530186 }
187 mwifiex_handle_rx_packet(adapter, skb);
188 }
189 spin_lock_irqsave(&adapter->rx_proc_lock, flags);
190 adapter->rx_processing = false;
191 spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
192
Avinash Patil6e251172014-09-12 20:08:59 +0530193exit_rx_proc:
194 return 0;
195}
196
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700197/*
198 * The main process.
199 *
200 * This function is the main procedure of the driver and handles various driver
201 * operations. It runs in a loop and provides the core functionalities.
202 *
203 * The main responsibilities of this function are -
204 * - Ensure concurrency control
205 * - Handle pending interrupts and call interrupt handlers
206 * - Wake up the card if required
207 * - Handle command responses and call response handlers
208 * - Handle events and call event handlers
209 * - Execute pending commands
210 * - Transmit pending data packets
211 */
212int mwifiex_main_process(struct mwifiex_adapter *adapter)
213{
214 int ret = 0;
215 unsigned long flags;
216
217 spin_lock_irqsave(&adapter->main_proc_lock, flags);
218
219 /* Check if already processing */
Avinash Patila9adbcb2015-03-13 17:37:51 +0530220 if (adapter->mwifiex_processing || adapter->main_locked) {
Shengzhen Li04c7b362015-02-11 23:12:24 +0530221 adapter->more_task_flag = true;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700222 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
223 goto exit_main_proc;
224 } else {
225 adapter->mwifiex_processing = true;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700226 }
227process_start:
228 do {
Shengzhen Li04c7b362015-02-11 23:12:24 +0530229 adapter->more_task_flag = false;
230 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700231 if ((adapter->hw_status == MWIFIEX_HW_STATUS_CLOSING) ||
232 (adapter->hw_status == MWIFIEX_HW_STATUS_NOT_READY))
233 break;
234
Amitkumar Karwar381e9ff2014-11-25 06:43:04 -0800235 /* For non-USB interfaces, If we process interrupts first, it
236 * would increase RX pending even further. Avoid this by
237 * checking if rx_pending has crossed high threshold and
238 * schedule rx work queue and then process interrupts.
239 * For USB interface, there are no interrupts. We already have
240 * HIGH_RX_PENDING check in usb.c
Avinash Patil6e251172014-09-12 20:08:59 +0530241 */
Amitkumar Karwar381e9ff2014-11-25 06:43:04 -0800242 if (atomic_read(&adapter->rx_pending) >= HIGH_RX_PENDING &&
243 adapter->iface_type != MWIFIEX_USB) {
Avinash Patil6e251172014-09-12 20:08:59 +0530244 adapter->delay_main_work = true;
Shengzhen Lib2713f62015-03-13 17:37:54 +0530245 mwifiex_queue_rx_work(adapter);
Avinash Patil6e251172014-09-12 20:08:59 +0530246 break;
247 }
248
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700249 /* Handle pending interrupt if any */
250 if (adapter->int_status) {
251 if (adapter->hs_activated)
252 mwifiex_process_hs_config(adapter);
Amitkumar Karwar4daffe32012-04-18 20:08:28 -0700253 if (adapter->if_ops.process_int_status)
254 adapter->if_ops.process_int_status(adapter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700255 }
256
Avinash Patil6e251172014-09-12 20:08:59 +0530257 if (adapter->rx_work_enabled && adapter->data_received)
Shengzhen Lib2713f62015-03-13 17:37:54 +0530258 mwifiex_queue_rx_work(adapter);
Avinash Patil6e251172014-09-12 20:08:59 +0530259
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700260 /* Need to wake up the card ? */
261 if ((adapter->ps_state == PS_STATE_SLEEP) &&
262 (adapter->pm_wakeup_card_req &&
263 !adapter->pm_wakeup_fw_try) &&
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -0700264 (is_command_pending(adapter) ||
Zhaoyang Liue35000e2015-03-13 17:37:57 +0530265 !skb_queue_empty(&adapter->tx_data_q) ||
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -0700266 !mwifiex_wmm_lists_empty(adapter))) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700267 adapter->pm_wakeup_fw_try = true;
Amitkumar Karwar46361872014-12-31 02:36:41 -0800268 mod_timer(&adapter->wakeup_timer, jiffies + (HZ*3));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700269 adapter->if_ops.wakeup(adapter);
Shengzhen Li04c7b362015-02-11 23:12:24 +0530270 spin_lock_irqsave(&adapter->main_proc_lock, flags);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700271 continue;
272 }
Amitkumar Karwar4daffe32012-04-18 20:08:28 -0700273
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700274 if (IS_CARD_RX_RCVD(adapter)) {
Avinash Patil6e251172014-09-12 20:08:59 +0530275 adapter->data_received = false;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700276 adapter->pm_wakeup_fw_try = false;
Amitkumar Karwar6e9344f2015-03-12 00:38:40 -0700277 del_timer(&adapter->wakeup_timer);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700278 if (adapter->ps_state == PS_STATE_SLEEP)
279 adapter->ps_state = PS_STATE_AWAKE;
280 } else {
281 /* We have tried to wakeup the card already */
282 if (adapter->pm_wakeup_fw_try)
283 break;
284 if (adapter->ps_state != PS_STATE_AWAKE ||
285 adapter->tx_lock_flag)
286 break;
287
Avinash Patil5ec39ef2014-09-12 20:08:56 +0530288 if ((!adapter->scan_chan_gap_enabled &&
Avinash Patil5ec39ef2014-09-12 20:08:56 +0530289 adapter->scan_processing) || adapter->data_sent ||
Zhaoyang Liue35000e2015-03-13 17:37:57 +0530290 (mwifiex_wmm_lists_empty(adapter) &&
291 skb_queue_empty(&adapter->tx_data_q))) {
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -0700292 if (adapter->cmd_sent || adapter->curr_cmd ||
293 (!is_command_pending(adapter)))
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700294 break;
295 }
296 }
297
Amitkumar Karwar20474122014-04-14 15:31:05 -0700298 /* Check for event */
299 if (adapter->event_received) {
300 adapter->event_received = false;
301 mwifiex_process_event(adapter);
302 }
303
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700304 /* Check for Cmd Resp */
305 if (adapter->cmd_resp_received) {
306 adapter->cmd_resp_received = false;
307 mwifiex_process_cmdresp(adapter);
308
309 /* call mwifiex back when init_fw is done */
310 if (adapter->hw_status == MWIFIEX_HW_STATUS_INIT_DONE) {
311 adapter->hw_status = MWIFIEX_HW_STATUS_READY;
312 mwifiex_init_fw_complete(adapter);
313 }
314 }
315
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700316 /* Check if we need to confirm Sleep Request
317 received previously */
318 if (adapter->ps_state == PS_STATE_PRE_SLEEP) {
319 if (!adapter->cmd_sent && !adapter->curr_cmd)
320 mwifiex_check_ps_cond(adapter);
321 }
322
323 /* * The ps_state may have been changed during processing of
324 * Sleep Request event.
325 */
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -0700326 if ((adapter->ps_state == PS_STATE_SLEEP) ||
327 (adapter->ps_state == PS_STATE_PRE_SLEEP) ||
328 (adapter->ps_state == PS_STATE_SLEEP_CFM) ||
Shengzhen Li04c7b362015-02-11 23:12:24 +0530329 adapter->tx_lock_flag){
330 spin_lock_irqsave(&adapter->main_proc_lock, flags);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700331 continue;
Shengzhen Li04c7b362015-02-11 23:12:24 +0530332 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700333
334 if (!adapter->cmd_sent && !adapter->curr_cmd) {
335 if (mwifiex_exec_next_cmd(adapter) == -1) {
336 ret = -1;
337 break;
338 }
339 }
340
Avinash Patil5ec39ef2014-09-12 20:08:56 +0530341 if ((adapter->scan_chan_gap_enabled ||
Amitkumar Karward8d91252014-09-12 20:08:58 +0530342 !adapter->scan_processing) &&
Zhaoyang Liue35000e2015-03-13 17:37:57 +0530343 !adapter->data_sent &&
344 !skb_queue_empty(&adapter->tx_data_q)) {
345 mwifiex_process_tx_queue(adapter);
346 if (adapter->hs_activated) {
347 adapter->is_hs_configured = false;
348 mwifiex_hs_activated_event
349 (mwifiex_get_priv
350 (adapter, MWIFIEX_BSS_ROLE_ANY),
351 false);
352 }
353 }
354
355 if ((adapter->scan_chan_gap_enabled ||
356 !adapter->scan_processing) &&
Amitkumar Karwar3249ba72012-06-06 21:12:41 -0700357 !adapter->data_sent && !mwifiex_wmm_lists_empty(adapter)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700358 mwifiex_wmm_process_tx(adapter);
359 if (adapter->hs_activated) {
360 adapter->is_hs_configured = false;
361 mwifiex_hs_activated_event
362 (mwifiex_get_priv
363 (adapter, MWIFIEX_BSS_ROLE_ANY),
364 false);
365 }
366 }
367
368 if (adapter->delay_null_pkt && !adapter->cmd_sent &&
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -0700369 !adapter->curr_cmd && !is_command_pending(adapter) &&
Zhaoyang Liue35000e2015-03-13 17:37:57 +0530370 (mwifiex_wmm_lists_empty(adapter) &&
371 skb_queue_empty(&adapter->tx_data_q))) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700372 if (!mwifiex_send_null_packet
373 (mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA),
374 MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET |
375 MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET)) {
376 adapter->delay_null_pkt = false;
377 adapter->ps_state = PS_STATE_SLEEP;
378 }
379 break;
380 }
Shengzhen Li04c7b362015-02-11 23:12:24 +0530381 spin_lock_irqsave(&adapter->main_proc_lock, flags);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700382 } while (true);
383
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700384 spin_lock_irqsave(&adapter->main_proc_lock, flags);
Shengzhen Li04c7b362015-02-11 23:12:24 +0530385 if (adapter->more_task_flag)
Amitkumar Karwar453b0c32013-09-27 10:55:38 -0700386 goto process_start;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700387 adapter->mwifiex_processing = false;
388 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
389
390exit_main_proc:
391 if (adapter->hw_status == MWIFIEX_HW_STATUS_CLOSING)
392 mwifiex_shutdown_drv(adapter);
393 return ret;
394}
Bing Zhao601216e2012-11-05 16:59:15 -0800395EXPORT_SYMBOL_GPL(mwifiex_main_process);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700396
397/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700398 * This function frees the adapter structure.
399 *
400 * Additionally, this closes the netlink socket, frees the timers
401 * and private structures.
402 */
403static void mwifiex_free_adapter(struct mwifiex_adapter *adapter)
404{
405 if (!adapter) {
406 pr_err("%s: adapter is NULL\n", __func__);
407 return;
408 }
409
410 mwifiex_unregister(adapter);
411 pr_debug("info: %s: free adapter\n", __func__);
412}
413
414/*
Amitkumar Karwar6b41f942013-07-22 19:17:55 -0700415 * This function cancels all works in the queue and destroys
416 * the main workqueue.
417 */
418static void mwifiex_terminate_workqueue(struct mwifiex_adapter *adapter)
419{
420 flush_workqueue(adapter->workqueue);
421 destroy_workqueue(adapter->workqueue);
422 adapter->workqueue = NULL;
Avinash Patil6e251172014-09-12 20:08:59 +0530423
424 if (adapter->rx_workqueue) {
425 flush_workqueue(adapter->rx_workqueue);
426 destroy_workqueue(adapter->rx_workqueue);
427 adapter->rx_workqueue = NULL;
428 }
Amitkumar Karwar6b41f942013-07-22 19:17:55 -0700429}
430
431/*
Amitkumar Karwar59a4cc22012-04-09 20:06:57 -0700432 * This function gets firmware and initializes it.
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700433 *
434 * The main initialization steps followed are -
435 * - Download the correct firmware to card
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700436 * - Issue the init commands to firmware
437 */
Amitkumar Karwar59a4cc22012-04-09 20:06:57 -0700438static void mwifiex_fw_dpc(const struct firmware *firmware, void *context)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700439{
Amitkumar Karwarbec568f2013-11-14 19:10:38 -0800440 int ret;
Amitkumar Karwar59a4cc22012-04-09 20:06:57 -0700441 char fmt[64];
442 struct mwifiex_private *priv;
443 struct mwifiex_adapter *adapter = context;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700444 struct mwifiex_fw_image fw;
Amitkumar Karwarc3afd992013-07-30 17:18:15 -0700445 struct semaphore *sem = adapter->card_sem;
446 bool init_failed = false;
Amitkumar Karwar68b76e92013-11-14 19:10:37 -0800447 struct wireless_dev *wdev;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700448
Amitkumar Karwar59a4cc22012-04-09 20:06:57 -0700449 if (!firmware) {
450 dev_err(adapter->dev,
451 "Failed to get firmware %s\n", adapter->fw_name);
Amitkumar Karwar6b41f942013-07-22 19:17:55 -0700452 goto err_dnld_fw;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700453 }
Amitkumar Karwar59a4cc22012-04-09 20:06:57 -0700454
455 memset(&fw, 0, sizeof(struct mwifiex_fw_image));
456 adapter->firmware = firmware;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700457 fw.fw_buf = (u8 *) adapter->firmware->data;
458 fw.fw_len = adapter->firmware->size;
459
Amitkumar Karwar4daffe32012-04-18 20:08:28 -0700460 if (adapter->if_ops.dnld_fw)
461 ret = adapter->if_ops.dnld_fw(adapter, &fw);
462 else
463 ret = mwifiex_dnld_fw(adapter, &fw);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700464 if (ret == -1)
Amitkumar Karwar6b41f942013-07-22 19:17:55 -0700465 goto err_dnld_fw;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700466
467 dev_notice(adapter->dev, "WLAN FW is active\n");
468
Amitkumar Karwar388ec382013-05-17 17:50:25 -0700469 if (cal_data_cfg) {
470 if ((request_firmware(&adapter->cal_data, cal_data_cfg,
471 adapter->dev)) < 0)
472 dev_err(adapter->dev,
473 "Cal data request_firmware() failed\n");
474 }
475
Daniel Drake232fde02013-07-13 10:57:10 -0400476 /* enable host interrupt after fw dnld is successful */
Amitkumar Karwar6b41f942013-07-22 19:17:55 -0700477 if (adapter->if_ops.enable_int) {
478 if (adapter->if_ops.enable_int(adapter))
479 goto err_dnld_fw;
480 }
Daniel Drake232fde02013-07-13 10:57:10 -0400481
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700482 adapter->init_wait_q_woken = false;
483 ret = mwifiex_init_fw(adapter);
484 if (ret == -1) {
Amitkumar Karwar6b41f942013-07-22 19:17:55 -0700485 goto err_init_fw;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700486 } else if (!ret) {
487 adapter->hw_status = MWIFIEX_HW_STATUS_READY;
488 goto done;
489 }
490 /* Wait for mwifiex_init to complete */
491 wait_event_interruptible(adapter->init_wait_q,
492 adapter->init_wait_q_woken);
Amitkumar Karwar59a4cc22012-04-09 20:06:57 -0700493 if (adapter->hw_status != MWIFIEX_HW_STATUS_READY)
Amitkumar Karwar6b41f942013-07-22 19:17:55 -0700494 goto err_init_fw;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700495
Avinash Patild6bffe82012-05-08 18:30:15 -0700496 priv = adapter->priv[MWIFIEX_BSS_ROLE_STA];
497 if (mwifiex_register_cfg80211(adapter)) {
Amitkumar Karwar59a4cc22012-04-09 20:06:57 -0700498 dev_err(adapter->dev, "cannot register with cfg80211\n");
Amitkumar Karward1af2942013-11-14 19:10:39 -0800499 goto err_init_fw;
Amitkumar Karwar59a4cc22012-04-09 20:06:57 -0700500 }
501
Avinash Patilbf354432014-10-31 16:08:26 +0530502 if (mwifiex_init_channel_scan_gap(adapter)) {
503 dev_err(adapter->dev, "could not init channel stats table\n");
504 goto err_init_fw;
505 }
506
Avinash Patil0013c7c2014-11-05 19:38:11 +0530507 if (driver_mode) {
508 driver_mode &= MWIFIEX_DRIVER_MODE_BITMASK;
509 driver_mode |= MWIFIEX_DRIVER_MODE_STA;
510 }
511
Amitkumar Karwar59a4cc22012-04-09 20:06:57 -0700512 rtnl_lock();
513 /* Create station interface by default */
Amitkumar Karwar68b76e92013-11-14 19:10:37 -0800514 wdev = mwifiex_add_virtual_intf(adapter->wiphy, "mlan%d",
515 NL80211_IFTYPE_STATION, NULL, NULL);
516 if (IS_ERR(wdev)) {
Amitkumar Karwar59a4cc22012-04-09 20:06:57 -0700517 dev_err(adapter->dev, "cannot create default STA interface\n");
Amitkumar Karwarbec568f2013-11-14 19:10:38 -0800518 rtnl_unlock();
Amitkumar Karwar59a4cc22012-04-09 20:06:57 -0700519 goto err_add_intf;
520 }
Avinash Patil0013c7c2014-11-05 19:38:11 +0530521
522 if (driver_mode & MWIFIEX_DRIVER_MODE_UAP) {
523 wdev = mwifiex_add_virtual_intf(adapter->wiphy, "uap%d",
524 NL80211_IFTYPE_AP, NULL, NULL);
525 if (IS_ERR(wdev)) {
526 dev_err(adapter->dev, "cannot create AP interface\n");
527 rtnl_unlock();
528 goto err_add_intf;
529 }
530 }
531
532 if (driver_mode & MWIFIEX_DRIVER_MODE_P2P) {
533 wdev = mwifiex_add_virtual_intf(adapter->wiphy, "p2p%d",
534 NL80211_IFTYPE_P2P_CLIENT, NULL,
535 NULL);
536 if (IS_ERR(wdev)) {
537 dev_err(adapter->dev,
538 "cannot create p2p client interface\n");
539 rtnl_unlock();
540 goto err_add_intf;
541 }
542 }
Amitkumar Karwar59a4cc22012-04-09 20:06:57 -0700543 rtnl_unlock();
544
545 mwifiex_drv_get_driver_version(adapter, fmt, sizeof(fmt) - 1);
546 dev_notice(adapter->dev, "driver_version = %s\n", fmt);
547 goto done;
548
549err_add_intf:
Amitkumar Karwar6b41f942013-07-22 19:17:55 -0700550 wiphy_unregister(adapter->wiphy);
551 wiphy_free(adapter->wiphy);
Amitkumar Karwar59a4cc22012-04-09 20:06:57 -0700552err_init_fw:
Daniel Drake232fde02013-07-13 10:57:10 -0400553 if (adapter->if_ops.disable_int)
554 adapter->if_ops.disable_int(adapter);
Amitkumar Karwar6b41f942013-07-22 19:17:55 -0700555err_dnld_fw:
Amitkumar Karwar59a4cc22012-04-09 20:06:57 -0700556 pr_debug("info: %s: unregister device\n", __func__);
Amitkumar Karwar6b41f942013-07-22 19:17:55 -0700557 if (adapter->if_ops.unregister_dev)
558 adapter->if_ops.unregister_dev(adapter);
559
Amitkumar Karwar71973252014-12-31 02:36:38 -0800560 if (adapter->hw_status == MWIFIEX_HW_STATUS_READY) {
Amitkumar Karwar6b41f942013-07-22 19:17:55 -0700561 pr_debug("info: %s: shutdown mwifiex\n", __func__);
562 adapter->init_wait_q_woken = false;
563
564 if (mwifiex_shutdown_drv(adapter) == -EINPROGRESS)
565 wait_event_interruptible(adapter->init_wait_q,
566 adapter->init_wait_q_woken);
567 }
568 adapter->surprise_removed = true;
569 mwifiex_terminate_workqueue(adapter);
Amitkumar Karwarc3afd992013-07-30 17:18:15 -0700570 init_failed = true;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700571done:
Amitkumar Karwar388ec382013-05-17 17:50:25 -0700572 if (adapter->cal_data) {
573 release_firmware(adapter->cal_data);
574 adapter->cal_data = NULL;
575 }
Amitkumar Karwarc3afd992013-07-30 17:18:15 -0700576 if (adapter->firmware) {
577 release_firmware(adapter->firmware);
578 adapter->firmware = NULL;
579 }
Amitkumar Karwarc3afd992013-07-30 17:18:15 -0700580 if (init_failed)
581 mwifiex_free_adapter(adapter);
582 up(sem);
Amitkumar Karwar59a4cc22012-04-09 20:06:57 -0700583 return;
584}
585
586/*
587 * This function initializes the hardware and gets firmware.
588 */
589static int mwifiex_init_hw_fw(struct mwifiex_adapter *adapter)
590{
591 int ret;
592
Amitkumar Karwar59a4cc22012-04-09 20:06:57 -0700593 ret = request_firmware_nowait(THIS_MODULE, 1, adapter->fw_name,
594 adapter->dev, GFP_KERNEL, adapter,
595 mwifiex_fw_dpc);
596 if (ret < 0)
597 dev_err(adapter->dev,
598 "request_firmware_nowait() returned error %d\n", ret);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700599 return ret;
600}
601
602/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700603 * CFG802.11 network device handler for open.
604 *
605 * Starts the data queue.
606 */
607static int
608mwifiex_open(struct net_device *dev)
609{
Johannes Bergea2325b2015-01-19 15:54:36 +0530610 netif_carrier_off(dev);
611
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700612 return 0;
613}
614
615/*
616 * CFG802.11 network device handler for close.
617 */
618static int
619mwifiex_close(struct net_device *dev)
620{
Amitkumar Karwarf162cac2012-10-19 19:19:16 -0700621 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
622
623 if (priv->scan_request) {
624 dev_dbg(priv->adapter->dev, "aborting scan on ndo_stop\n");
625 cfg80211_scan_done(priv->scan_request, 1);
626 priv->scan_request = NULL;
Amitkumar Karwar75ab7532013-05-17 17:50:20 -0700627 priv->scan_aborting = true;
Amitkumar Karwarf162cac2012-10-19 19:19:16 -0700628 }
629
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700630 return 0;
631}
632
633/*
Stone Piaoe39faa72012-09-25 20:23:32 -0700634 * Add buffer into wmm tx queue and queue work to transmit it.
635 */
636int mwifiex_queue_tx_pkt(struct mwifiex_private *priv, struct sk_buff *skb)
637{
Avinash Patil47411a02012-11-01 18:44:16 -0700638 struct netdev_queue *txq;
639 int index = mwifiex_1d_to_wmm_queue[skb->priority];
640
641 if (atomic_inc_return(&priv->wmm_tx_pending[index]) >= MAX_TX_PENDING) {
642 txq = netdev_get_tx_queue(priv->netdev, index);
643 if (!netif_tx_queue_stopped(txq)) {
644 netif_tx_stop_queue(txq);
645 dev_dbg(priv->adapter->dev, "stop queue: %d\n", index);
646 }
647 }
648
Stone Piaoe39faa72012-09-25 20:23:32 -0700649 atomic_inc(&priv->adapter->tx_pending);
Avinash Patil47411a02012-11-01 18:44:16 -0700650 mwifiex_wmm_add_buf_txqueue(priv, skb);
Stone Piaoe39faa72012-09-25 20:23:32 -0700651
Shengzhen Lib2713f62015-03-13 17:37:54 +0530652 mwifiex_queue_main_work(priv->adapter);
Stone Piaoe39faa72012-09-25 20:23:32 -0700653
654 return 0;
655}
656
Amitkumar Karwar18ca4382014-11-25 06:43:06 -0800657struct sk_buff *
Amitkumar Karwar808bbeb2014-11-25 06:43:05 -0800658mwifiex_clone_skb_for_tx_status(struct mwifiex_private *priv,
Amitkumar Karwar18ca4382014-11-25 06:43:06 -0800659 struct sk_buff *skb, u8 flag, u64 *cookie)
Amitkumar Karwar808bbeb2014-11-25 06:43:05 -0800660{
661 struct sk_buff *orig_skb = skb;
662 struct mwifiex_txinfo *tx_info, *orig_tx_info;
663
664 skb = skb_clone(skb, GFP_ATOMIC);
665 if (skb) {
666 unsigned long flags;
667 int id;
668
669 spin_lock_irqsave(&priv->ack_status_lock, flags);
670 id = idr_alloc(&priv->ack_status_frames, orig_skb,
671 1, 0xff, GFP_ATOMIC);
672 spin_unlock_irqrestore(&priv->ack_status_lock, flags);
673
674 if (id >= 0) {
675 tx_info = MWIFIEX_SKB_TXCB(skb);
676 tx_info->ack_frame_id = id;
677 tx_info->flags |= flag;
678 orig_tx_info = MWIFIEX_SKB_TXCB(orig_skb);
679 orig_tx_info->ack_frame_id = id;
680 orig_tx_info->flags |= flag;
Amitkumar Karwar18ca4382014-11-25 06:43:06 -0800681
682 if (flag == MWIFIEX_BUF_FLAG_ACTION_TX_STATUS && cookie)
683 orig_tx_info->cookie = *cookie;
684
Amitkumar Karwar808bbeb2014-11-25 06:43:05 -0800685 } else if (skb_shared(skb)) {
686 kfree_skb(orig_skb);
687 } else {
688 kfree_skb(skb);
689 skb = orig_skb;
690 }
691 } else {
692 /* couldn't clone -- lose tx status ... */
693 skb = orig_skb;
694 }
695
696 return skb;
697}
698
Stone Piaoe39faa72012-09-25 20:23:32 -0700699/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700700 * CFG802.11 network device handler for data transmission.
701 */
702static int
703mwifiex_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
704{
705 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700706 struct sk_buff *new_skb;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700707 struct mwifiex_txinfo *tx_info;
Amitkumar Karwar808bbeb2014-11-25 06:43:05 -0800708 bool multicast;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700709
Yogesh Ashok Powar9da9a3b2012-01-11 20:06:11 -0800710 dev_dbg(priv->adapter->dev, "data: %lu BSS(%d-%d): Data <= kernel\n",
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -0700711 jiffies, priv->bss_type, priv->bss_num);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700712
713 if (priv->adapter->surprise_removed) {
Christoph Fritzb53575e2011-05-08 22:50:09 +0200714 kfree_skb(skb);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700715 priv->stats.tx_dropped++;
716 return 0;
717 }
718 if (!skb->len || (skb->len > ETH_FRAME_LEN)) {
719 dev_err(priv->adapter->dev, "Tx: bad skb len %d\n", skb->len);
Christoph Fritzb53575e2011-05-08 22:50:09 +0200720 kfree_skb(skb);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700721 priv->stats.tx_dropped++;
722 return 0;
723 }
724 if (skb_headroom(skb) < MWIFIEX_MIN_DATA_HEADER_LEN) {
725 dev_dbg(priv->adapter->dev,
726 "data: Tx: insufficient skb headroom %d\n",
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -0700727 skb_headroom(skb));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700728 /* Insufficient skb headroom - allocate a new skb */
729 new_skb =
730 skb_realloc_headroom(skb, MWIFIEX_MIN_DATA_HEADER_LEN);
731 if (unlikely(!new_skb)) {
732 dev_err(priv->adapter->dev, "Tx: cannot alloca new_skb\n");
Christoph Fritzb53575e2011-05-08 22:50:09 +0200733 kfree_skb(skb);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700734 priv->stats.tx_dropped++;
735 return 0;
736 }
737 kfree_skb(skb);
738 skb = new_skb;
739 dev_dbg(priv->adapter->dev, "info: new skb headroomd %d\n",
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -0700740 skb_headroom(skb));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700741 }
742
743 tx_info = MWIFIEX_SKB_TXCB(skb);
Amitkumar Karward76744a2014-06-20 11:45:25 -0700744 memset(tx_info, 0, sizeof(*tx_info));
Yogesh Ashok Powar9da9a3b2012-01-11 20:06:11 -0800745 tx_info->bss_num = priv->bss_num;
746 tx_info->bss_type = priv->bss_type;
Ujjal Roya1ed4842013-12-02 23:17:55 -0800747 tx_info->pkt_len = skb->len;
Avinash Patil47411a02012-11-01 18:44:16 -0700748
Amitkumar Karwar808bbeb2014-11-25 06:43:05 -0800749 multicast = is_multicast_ether_addr(skb->data);
750
751 if (unlikely(!multicast && skb->sk &&
752 skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS &&
753 priv->adapter->fw_api_ver == MWIFIEX_FW_V15))
754 skb = mwifiex_clone_skb_for_tx_status(priv,
755 skb,
Amitkumar Karwar18ca4382014-11-25 06:43:06 -0800756 MWIFIEX_BUF_FLAG_EAPOL_TX_STATUS, NULL);
Amitkumar Karwar808bbeb2014-11-25 06:43:05 -0800757
Avinash Patil47411a02012-11-01 18:44:16 -0700758 /* Record the current time the packet was queued; used to
759 * determine the amount of time the packet was queued in
760 * the driver before it was sent to the firmware.
761 * The delay is then sent along with the packet to the
762 * firmware for aggregate delay calculation for stats and
763 * MSDU lifetime expiry.
764 */
Thomas Gleixnerc64800e2014-06-12 08:31:34 +0100765 __net_timestamp(skb);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700766
Avinash Patil9927baa2014-11-13 21:54:16 +0530767 if (ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) &&
768 priv->bss_type == MWIFIEX_BSS_TYPE_STA &&
769 !ether_addr_equal_unaligned(priv->cfg_bssid, skb->data)) {
770 if (priv->adapter->auto_tdls && priv->check_tdls_tx)
771 mwifiex_tdls_check_tx(priv, skb);
772 }
773
Stone Piaoe39faa72012-09-25 20:23:32 -0700774 mwifiex_queue_tx_pkt(priv, skb);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700775
776 return 0;
777}
778
779/*
780 * CFG802.11 network device handler for setting MAC address.
781 */
782static int
783mwifiex_set_mac_address(struct net_device *dev, void *addr)
784{
785 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700786 struct sockaddr *hw_addr = addr;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700787 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700788
789 memcpy(priv->curr_addr, hw_addr->sa_data, ETH_ALEN);
790
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700791 /* Send request to firmware */
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800792 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_MAC_ADDRESS,
793 HostCmd_ACT_GEN_SET, 0, NULL, true);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700794
795 if (!ret)
796 memcpy(priv->netdev->dev_addr, priv->curr_addr, ETH_ALEN);
797 else
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -0700798 dev_err(priv->adapter->dev,
799 "set mac address failed: ret=%d\n", ret);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700800
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700801 memcpy(dev->dev_addr, priv->curr_addr, ETH_ALEN);
802
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700803 return ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700804}
805
806/*
807 * CFG802.11 network device handler for setting multicast list.
808 */
809static void mwifiex_set_multicast_list(struct net_device *dev)
810{
811 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700812 struct mwifiex_multicast_list mcast_list;
813
814 if (dev->flags & IFF_PROMISC) {
815 mcast_list.mode = MWIFIEX_PROMISC_MODE;
816 } else if (dev->flags & IFF_ALLMULTI ||
817 netdev_mc_count(dev) > MWIFIEX_MAX_MULTICAST_LIST_SIZE) {
818 mcast_list.mode = MWIFIEX_ALL_MULTI_MODE;
819 } else {
820 mcast_list.mode = MWIFIEX_MULTICAST_MODE;
Daniel Drake6390d882013-06-14 15:24:24 -0400821 mcast_list.num_multicast_addr =
822 mwifiex_copy_mcast_addr(&mcast_list, dev);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700823 }
824 mwifiex_request_set_multicast_list(priv, &mcast_list);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700825}
826
827/*
828 * CFG802.11 network device handler for transmission timeout.
829 */
830static void
831mwifiex_tx_timeout(struct net_device *dev)
832{
833 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
834
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700835 priv->num_tx_timeout++;
Ashok Nagarajan8908c7d2013-03-08 10:58:45 -0800836 priv->tx_timeout_cnt++;
837 dev_err(priv->adapter->dev,
838 "%lu : Tx timeout(#%d), bss_type-num = %d-%d\n",
839 jiffies, priv->tx_timeout_cnt, priv->bss_type, priv->bss_num);
840 mwifiex_set_trans_start(dev);
841
842 if (priv->tx_timeout_cnt > TX_TIMEOUT_THRESHOLD &&
843 priv->adapter->if_ops.card_reset) {
844 dev_err(priv->adapter->dev,
845 "tx_timeout_cnt exceeds threshold. Triggering card reset!\n");
846 priv->adapter->if_ops.card_reset(priv->adapter);
847 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700848}
849
Xinming Hu11cd07a2014-12-23 19:14:10 +0530850void mwifiex_dump_drv_info(struct mwifiex_adapter *adapter)
851{
852 void *p;
853 char drv_version[64];
854 struct usb_card_rec *cardp;
855 struct sdio_mmc_card *sdio_card;
856 struct mwifiex_private *priv;
857 int i, idx;
858 struct netdev_queue *txq;
859 struct mwifiex_debug_info *debug_info;
860
861 if (adapter->drv_info_dump) {
862 vfree(adapter->drv_info_dump);
863 adapter->drv_info_size = 0;
864 }
865
866 dev_info(adapter->dev, "=== DRIVER INFO DUMP START===\n");
867
868 adapter->drv_info_dump = vzalloc(MWIFIEX_DRV_INFO_SIZE_MAX);
869
870 if (!adapter->drv_info_dump)
871 return;
872
873 p = (char *)(adapter->drv_info_dump);
874 p += sprintf(p, "driver_name = " "\"mwifiex\"\n");
875
876 mwifiex_drv_get_driver_version(adapter, drv_version,
877 sizeof(drv_version) - 1);
878 p += sprintf(p, "driver_version = %s\n", drv_version);
879
880 if (adapter->iface_type == MWIFIEX_USB) {
881 cardp = (struct usb_card_rec *)adapter->card;
882 p += sprintf(p, "tx_cmd_urb_pending = %d\n",
883 atomic_read(&cardp->tx_cmd_urb_pending));
884 p += sprintf(p, "tx_data_urb_pending = %d\n",
885 atomic_read(&cardp->tx_data_urb_pending));
886 p += sprintf(p, "rx_cmd_urb_pending = %d\n",
887 atomic_read(&cardp->rx_cmd_urb_pending));
888 p += sprintf(p, "rx_data_urb_pending = %d\n",
889 atomic_read(&cardp->rx_data_urb_pending));
890 }
891
892 p += sprintf(p, "tx_pending = %d\n",
893 atomic_read(&adapter->tx_pending));
894 p += sprintf(p, "rx_pending = %d\n",
895 atomic_read(&adapter->rx_pending));
896
897 if (adapter->iface_type == MWIFIEX_SDIO) {
898 sdio_card = (struct sdio_mmc_card *)adapter->card;
899 p += sprintf(p, "\nmp_rd_bitmap=0x%x curr_rd_port=0x%x\n",
900 sdio_card->mp_rd_bitmap, sdio_card->curr_rd_port);
901 p += sprintf(p, "mp_wr_bitmap=0x%x curr_wr_port=0x%x\n",
902 sdio_card->mp_wr_bitmap, sdio_card->curr_wr_port);
903 }
904
905 for (i = 0; i < adapter->priv_num; i++) {
906 if (!adapter->priv[i] || !adapter->priv[i]->netdev)
907 continue;
908 priv = adapter->priv[i];
909 p += sprintf(p, "\n[interface : \"%s\"]\n",
910 priv->netdev->name);
911 p += sprintf(p, "wmm_tx_pending[0] = %d\n",
912 atomic_read(&priv->wmm_tx_pending[0]));
913 p += sprintf(p, "wmm_tx_pending[1] = %d\n",
914 atomic_read(&priv->wmm_tx_pending[1]));
915 p += sprintf(p, "wmm_tx_pending[2] = %d\n",
916 atomic_read(&priv->wmm_tx_pending[2]));
917 p += sprintf(p, "wmm_tx_pending[3] = %d\n",
918 atomic_read(&priv->wmm_tx_pending[3]));
919 p += sprintf(p, "media_state=\"%s\"\n", !priv->media_connected ?
920 "Disconnected" : "Connected");
921 p += sprintf(p, "carrier %s\n", (netif_carrier_ok(priv->netdev)
922 ? "on" : "off"));
923 for (idx = 0; idx < priv->netdev->num_tx_queues; idx++) {
924 txq = netdev_get_tx_queue(priv->netdev, idx);
925 p += sprintf(p, "tx queue %d:%s ", idx,
926 netif_tx_queue_stopped(txq) ?
927 "stopped" : "started");
928 }
929 p += sprintf(p, "\n%s: num_tx_timeout = %d\n",
930 priv->netdev->name, priv->num_tx_timeout);
931 }
932
Xinming Hu809c6ea2014-12-23 19:14:11 +0530933 if (adapter->iface_type == MWIFIEX_SDIO) {
934 p += sprintf(p, "\n=== SDIO register DUMP===\n");
935 if (adapter->if_ops.reg_dump)
936 p += adapter->if_ops.reg_dump(adapter, p);
937 }
938
Xinming Hu11cd07a2014-12-23 19:14:10 +0530939 p += sprintf(p, "\n=== MORE DEBUG INFORMATION\n");
940 debug_info = kzalloc(sizeof(*debug_info), GFP_KERNEL);
941 if (debug_info) {
942 for (i = 0; i < adapter->priv_num; i++) {
943 if (!adapter->priv[i] || !adapter->priv[i]->netdev)
944 continue;
945 priv = adapter->priv[i];
946 mwifiex_get_debug_info(priv, debug_info);
947 p += mwifiex_debug_info_to_buffer(priv, p, debug_info);
948 break;
949 }
950 kfree(debug_info);
951 }
952
953 adapter->drv_info_size = p - adapter->drv_info_dump;
954 dev_info(adapter->dev, "=== DRIVER INFO DUMP END===\n");
955}
956EXPORT_SYMBOL_GPL(mwifiex_dump_drv_info);
957
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700958/*
959 * CFG802.11 network device handler for statistics retrieval.
960 */
961static struct net_device_stats *mwifiex_get_stats(struct net_device *dev)
962{
963 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
964
965 return &priv->stats;
966}
967
Avinash Patil47411a02012-11-01 18:44:16 -0700968static u16
Jason Wangf663dd92014-01-10 16:18:26 +0800969mwifiex_netdev_select_wmm_queue(struct net_device *dev, struct sk_buff *skb,
Daniel Borkmann99932d42014-02-16 15:55:20 +0100970 void *accel_priv, select_queue_fallback_t fallback)
Avinash Patil47411a02012-11-01 18:44:16 -0700971{
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800972 skb->priority = cfg80211_classify8021d(skb, NULL);
Avinash Patil47411a02012-11-01 18:44:16 -0700973 return mwifiex_1d_to_wmm_queue[skb->priority];
974}
975
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700976/* Network device handlers */
977static const struct net_device_ops mwifiex_netdev_ops = {
978 .ndo_open = mwifiex_open,
979 .ndo_stop = mwifiex_close,
980 .ndo_start_xmit = mwifiex_hard_start_xmit,
981 .ndo_set_mac_address = mwifiex_set_mac_address,
982 .ndo_tx_timeout = mwifiex_tx_timeout,
983 .ndo_get_stats = mwifiex_get_stats,
Jiri Pirkoafc4b132011-08-16 06:29:01 +0000984 .ndo_set_rx_mode = mwifiex_set_multicast_list,
Avinash Patil47411a02012-11-01 18:44:16 -0700985 .ndo_select_queue = mwifiex_netdev_select_wmm_queue,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700986};
987
988/*
989 * This function initializes the private structure parameters.
990 *
991 * The following wait queues are initialized -
992 * - IOCTL wait queue
993 * - Command wait queue
994 * - Statistics wait queue
995 *
996 * ...and the following default parameters are set -
997 * - Current key index : Set to 0
998 * - Rate index : Set to auto
999 * - Media connected : Set to disconnected
1000 * - Adhoc link sensed : Set to false
1001 * - Nick name : Set to null
1002 * - Number of Tx timeout : Set to 0
1003 * - Device address : Set to current address
Xinming Hucbf6e052014-12-23 19:14:07 +05301004 * - Rx histogram statistc : Set to 0
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001005 *
1006 * In addition, the CFG80211 work queue is also created.
1007 */
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001008void mwifiex_init_priv_params(struct mwifiex_private *priv,
Avinash Patil047eaaf2015-01-28 15:42:05 +05301009 struct net_device *dev)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001010{
1011 dev->netdev_ops = &mwifiex_netdev_ops;
Amitkumar Karwarf16fdc92013-05-06 19:46:54 -07001012 dev->destructor = free_netdev;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001013 /* Initialize private structure */
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001014 priv->current_key_index = 0;
1015 priv->media_connected = false;
Avinash Patilede98bf2012-05-08 18:30:28 -07001016 memset(priv->mgmt_ie, 0,
1017 sizeof(struct mwifiex_ie) * MAX_MGMT_IE_INDEX);
Avinash Patilf31acab2012-05-08 18:30:29 -07001018 priv->beacon_idx = MWIFIEX_AUTO_IDX_MASK;
1019 priv->proberesp_idx = MWIFIEX_AUTO_IDX_MASK;
1020 priv->assocresp_idx = MWIFIEX_AUTO_IDX_MASK;
Avinash Patil2ade5662015-01-28 15:54:20 +05301021 priv->gen_idx = MWIFIEX_AUTO_IDX_MASK;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001022 priv->num_tx_timeout = 0;
Avinash Patil8d05eb22015-01-28 15:42:01 +05301023 ether_addr_copy(priv->curr_addr, priv->adapter->perm_addr);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001024 memcpy(dev->dev_addr, priv->curr_addr, ETH_ALEN);
Xinming Hucbf6e052014-12-23 19:14:07 +05301025
1026 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA ||
1027 GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
1028 priv->hist_data = kmalloc(sizeof(*priv->hist_data), GFP_KERNEL);
1029 if (priv->hist_data)
1030 mwifiex_hist_data_reset(priv);
1031 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001032}
1033
1034/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001035 * This function check if command is pending.
1036 */
1037int is_command_pending(struct mwifiex_adapter *adapter)
1038{
1039 unsigned long flags;
1040 int is_cmd_pend_q_empty;
1041
1042 spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags);
1043 is_cmd_pend_q_empty = list_empty(&adapter->cmd_pending_q);
1044 spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, flags);
1045
1046 return !is_cmd_pend_q_empty;
1047}
1048
1049/*
Avinash Patil6e251172014-09-12 20:08:59 +05301050 * This is the RX work queue function.
1051 *
1052 * It handles the RX operations.
1053 */
1054static void mwifiex_rx_work_queue(struct work_struct *work)
1055{
1056 struct mwifiex_adapter *adapter =
1057 container_of(work, struct mwifiex_adapter, rx_work);
1058
1059 if (adapter->surprise_removed)
1060 return;
1061 mwifiex_process_rx(adapter);
1062}
1063
1064/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001065 * This is the main work queue function.
1066 *
1067 * It handles the main process, which in turn handles the complete
1068 * driver operations.
1069 */
1070static void mwifiex_main_work_queue(struct work_struct *work)
1071{
1072 struct mwifiex_adapter *adapter =
1073 container_of(work, struct mwifiex_adapter, main_work);
1074
1075 if (adapter->surprise_removed)
1076 return;
1077 mwifiex_main_process(adapter);
1078}
1079
1080/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001081 * This function adds the card.
1082 *
1083 * This function follows the following major steps to set up the device -
1084 * - Initialize software. This includes probing the card, registering
1085 * the interface operations table, and allocating/initializing the
1086 * adapter structure
1087 * - Set up the netlink socket
1088 * - Create and start the main work queue
1089 * - Register the device
1090 * - Initialize firmware and hardware
1091 * - Add logical interfaces
1092 */
1093int
1094mwifiex_add_card(void *card, struct semaphore *sem,
Amitkumar Karward930fae2011-10-11 17:41:21 -07001095 struct mwifiex_if_ops *if_ops, u8 iface_type)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001096{
Amitkumar Karwar2be78592011-04-15 20:50:42 -07001097 struct mwifiex_adapter *adapter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001098
1099 if (down_interruptible(sem))
1100 goto exit_sem_err;
1101
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001102 if (mwifiex_register(card, if_ops, (void **)&adapter)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001103 pr_err("%s: software init failed\n", __func__);
1104 goto err_init_sw;
1105 }
1106
Amitkumar Karward930fae2011-10-11 17:41:21 -07001107 adapter->iface_type = iface_type;
Amitkumar Karwar6b41f942013-07-22 19:17:55 -07001108 adapter->card_sem = sem;
Amitkumar Karward930fae2011-10-11 17:41:21 -07001109
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001110 adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001111 adapter->surprise_removed = false;
1112 init_waitqueue_head(&adapter->init_wait_q);
1113 adapter->is_suspended = false;
1114 adapter->hs_activated = false;
1115 init_waitqueue_head(&adapter->hs_activate_wait_q);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001116 init_waitqueue_head(&adapter->cmd_wait_q.wait);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001117 adapter->cmd_wait_q.status = 0;
Amitkumar Karwarefaaa8b2011-10-12 20:28:06 -07001118 adapter->scan_wait_q_woken = false;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001119
Avinash Patilec4a16b2014-11-05 17:04:27 +05301120 if ((num_possible_cpus() > 1) || adapter->iface_type == MWIFIEX_USB) {
Avinash Patil6e251172014-09-12 20:08:59 +05301121 adapter->rx_work_enabled = true;
1122 pr_notice("rx work enabled, cpus %d\n", num_possible_cpus());
1123 }
1124
Amitkumar Karwar448a71c2013-10-11 18:33:04 -07001125 adapter->workqueue =
1126 alloc_workqueue("MWIFIEX_WORK_QUEUE",
1127 WQ_HIGHPRI | WQ_MEM_RECLAIM | WQ_UNBOUND, 1);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001128 if (!adapter->workqueue)
1129 goto err_kmalloc;
1130
1131 INIT_WORK(&adapter->main_work, mwifiex_main_work_queue);
Avinash Patil6e251172014-09-12 20:08:59 +05301132
1133 if (adapter->rx_work_enabled) {
1134 adapter->rx_workqueue = alloc_workqueue("MWIFIEX_RX_WORK_QUEUE",
1135 WQ_HIGHPRI |
1136 WQ_MEM_RECLAIM |
1137 WQ_UNBOUND, 1);
1138 if (!adapter->rx_workqueue)
1139 goto err_kmalloc;
1140
1141 INIT_WORK(&adapter->rx_work, mwifiex_rx_work_queue);
1142 }
1143
Amitkumar Karwar92c25382014-06-19 21:38:52 -07001144 if (adapter->if_ops.iface_work)
1145 INIT_WORK(&adapter->iface_work, adapter->if_ops.iface_work);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001146
1147 /* Register the device. Fill up the private data structure with relevant
Daniel Drake232fde02013-07-13 10:57:10 -04001148 information from the card. */
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001149 if (adapter->if_ops.register_dev(adapter)) {
1150 pr_err("%s: failed to register mwifiex device\n", __func__);
1151 goto err_registerdev;
1152 }
1153
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001154 if (mwifiex_init_hw_fw(adapter)) {
1155 pr_err("%s: firmware init failed\n", __func__);
1156 goto err_init_fw;
1157 }
Amitkumar Karwar2be78592011-04-15 20:50:42 -07001158
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001159 return 0;
1160
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001161err_init_fw:
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001162 pr_debug("info: %s: unregister device\n", __func__);
Amitkumar Karwar4daffe32012-04-18 20:08:28 -07001163 if (adapter->if_ops.unregister_dev)
1164 adapter->if_ops.unregister_dev(adapter);
Amitkumar Karwar71973252014-12-31 02:36:38 -08001165 if (adapter->hw_status == MWIFIEX_HW_STATUS_READY) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001166 pr_debug("info: %s: shutdown mwifiex\n", __func__);
1167 adapter->init_wait_q_woken = false;
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001168
1169 if (mwifiex_shutdown_drv(adapter) == -EINPROGRESS)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001170 wait_event_interruptible(adapter->init_wait_q,
1171 adapter->init_wait_q_woken);
1172 }
Amitkumar Karwar6b41f942013-07-22 19:17:55 -07001173err_registerdev:
1174 adapter->surprise_removed = true;
1175 mwifiex_terminate_workqueue(adapter);
1176err_kmalloc:
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001177 mwifiex_free_adapter(adapter);
1178
1179err_init_sw:
1180 up(sem);
1181
1182exit_sem_err:
1183 return -1;
1184}
1185EXPORT_SYMBOL_GPL(mwifiex_add_card);
1186
1187/*
1188 * This function removes the card.
1189 *
1190 * This function follows the following major steps to remove the device -
1191 * - Stop data traffic
1192 * - Shutdown firmware
1193 * - Remove the logical interfaces
1194 * - Terminate the work queue
1195 * - Unregister the device
1196 * - Free the adapter structure
1197 */
1198int mwifiex_remove_card(struct mwifiex_adapter *adapter, struct semaphore *sem)
1199{
1200 struct mwifiex_private *priv = NULL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001201 int i;
1202
1203 if (down_interruptible(sem))
1204 goto exit_sem_err;
1205
1206 if (!adapter)
1207 goto exit_remove;
1208
Daniel Drake232fde02013-07-13 10:57:10 -04001209 /* We can no longer handle interrupts once we start doing the teardown
1210 * below. */
1211 if (adapter->if_ops.disable_int)
1212 adapter->if_ops.disable_int(adapter);
1213
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001214 adapter->surprise_removed = true;
1215
Marc Yang9d2e85e2014-12-31 02:36:39 -08001216 mwifiex_terminate_workqueue(adapter);
1217
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001218 /* Stop data */
1219 for (i = 0; i < adapter->priv_num; i++) {
1220 priv = adapter->priv[i];
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001221 if (priv && priv->netdev) {
Avinash Patil47411a02012-11-01 18:44:16 -07001222 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001223 if (netif_carrier_ok(priv->netdev))
1224 netif_carrier_off(priv->netdev);
1225 }
1226 }
1227
1228 dev_dbg(adapter->dev, "cmd: calling mwifiex_shutdown_drv...\n");
1229 adapter->init_wait_q_woken = false;
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001230
1231 if (mwifiex_shutdown_drv(adapter) == -EINPROGRESS)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001232 wait_event_interruptible(adapter->init_wait_q,
1233 adapter->init_wait_q_woken);
1234 dev_dbg(adapter->dev, "cmd: mwifiex_shutdown_drv done\n");
1235 if (atomic_read(&adapter->rx_pending) ||
1236 atomic_read(&adapter->tx_pending) ||
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001237 atomic_read(&adapter->cmd_pending)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001238 dev_err(adapter->dev, "rx_pending=%d, tx_pending=%d, "
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001239 "cmd_pending=%d\n",
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001240 atomic_read(&adapter->rx_pending),
1241 atomic_read(&adapter->tx_pending),
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001242 atomic_read(&adapter->cmd_pending));
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001243 }
1244
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001245 for (i = 0; i < adapter->priv_num; i++) {
1246 priv = adapter->priv[i];
1247
1248 if (!priv)
1249 continue;
1250
1251 rtnl_lock();
Avinash Patil4facc342015-01-28 15:42:00 +05301252 if (priv->netdev &&
1253 priv->wdev.iftype != NL80211_IFTYPE_UNSPECIFIED)
1254 mwifiex_del_virtual_intf(adapter->wiphy, &priv->wdev);
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001255 rtnl_unlock();
1256 }
1257
Amitkumar Karwarc2868ad2013-12-02 23:17:57 -08001258 wiphy_unregister(adapter->wiphy);
1259 wiphy_free(adapter->wiphy);
Avinash Patil64b05e22012-05-08 18:30:13 -07001260
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001261 /* Unregister device */
1262 dev_dbg(adapter->dev, "info: unregister device\n");
Amitkumar Karwar4daffe32012-04-18 20:08:28 -07001263 if (adapter->if_ops.unregister_dev)
1264 adapter->if_ops.unregister_dev(adapter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001265 /* Free adapter structure */
1266 dev_dbg(adapter->dev, "info: free adapter\n");
1267 mwifiex_free_adapter(adapter);
1268
1269exit_remove:
1270 up(sem);
1271exit_sem_err:
1272 return 0;
1273}
1274EXPORT_SYMBOL_GPL(mwifiex_remove_card);
1275
1276/*
1277 * This function initializes the module.
1278 *
1279 * The debug FS is also initialized if configured.
1280 */
1281static int
1282mwifiex_init_module(void)
1283{
1284#ifdef CONFIG_DEBUG_FS
1285 mwifiex_debugfs_init();
1286#endif
1287 return 0;
1288}
1289
1290/*
1291 * This function cleans up the module.
1292 *
1293 * The debug FS is removed if available.
1294 */
1295static void
1296mwifiex_cleanup_module(void)
1297{
1298#ifdef CONFIG_DEBUG_FS
1299 mwifiex_debugfs_remove();
1300#endif
1301}
1302
1303module_init(mwifiex_init_module);
1304module_exit(mwifiex_cleanup_module);
1305
1306MODULE_AUTHOR("Marvell International Ltd.");
1307MODULE_DESCRIPTION("Marvell WiFi-Ex Driver version " VERSION);
1308MODULE_VERSION(VERSION);
1309MODULE_LICENSE("GPL v2");