blob: 2478ccd6f2d936c9e962f5cc6cdeeb9a5908219a [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"
Xinming Hucf5383b2016-09-02 13:05:06 +053026#define MFG_FIRMWARE "mwifiex_mfg.bin"
Bing Zhao5e6e3a92011-03-21 18:00:50 -070027
Zhaoyang Liuc687a002015-05-12 00:48:18 +053028static unsigned int debug_mask = MWIFIEX_DEFAULT_DEBUG_MASK;
29module_param(debug_mask, uint, 0);
30MODULE_PARM_DESC(debug_mask, "bitmap for debug flags");
31
Bing Zhao5e6e3a92011-03-21 18:00:50 -070032const char driver_version[] = "mwifiex " VERSION " (%s) ";
Amitkumar Karwar388ec382013-05-17 17:50:25 -070033static char *cal_data_cfg;
34module_param(cal_data_cfg, charp, 0);
Bing Zhao5e6e3a92011-03-21 18:00:50 -070035
Avinash Patil0013c7c2014-11-05 19:38:11 +053036static unsigned short driver_mode;
37module_param(driver_mode, ushort, 0);
38MODULE_PARM_DESC(driver_mode,
39 "station=0x1(default), ap-sta=0x3, station-p2p=0x5, ap-sta-p2p=0x7");
40
Xinming Hucf5383b2016-09-02 13:05:06 +053041bool mfg_mode;
42module_param(mfg_mode, bool, 0);
43MODULE_PARM_DESC(mfg_mode, "manufacturing mode enable:1, disable:0");
44
Bing Zhao5e6e3a92011-03-21 18:00:50 -070045/*
46 * This function registers the device and performs all the necessary
47 * initializations.
48 *
49 * The following initialization operations are performed -
50 * - Allocate adapter structure
51 * - Save interface specific operations table in adapter
52 * - Call interface specific initialization routine
53 * - Allocate private structures
54 * - Set default adapter structure parameters
55 * - Initialize locks
56 *
57 * In case of any errors during inittialization, this function also ensures
58 * proper cleanup before exiting.
59 */
60static int mwifiex_register(void *card, struct mwifiex_if_ops *if_ops,
Amitkumar Karwar287546d2011-06-08 20:39:20 +053061 void **padapter)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070062{
Amitkumar Karwar2be78592011-04-15 20:50:42 -070063 struct mwifiex_adapter *adapter;
64 int i;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070065
66 adapter = kzalloc(sizeof(struct mwifiex_adapter), GFP_KERNEL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -070067 if (!adapter)
Christoph Fritzb53575e2011-05-08 22:50:09 +020068 return -ENOMEM;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070069
Amitkumar Karwar287546d2011-06-08 20:39:20 +053070 *padapter = adapter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070071 adapter->card = card;
72
73 /* Save interface specific operations in adapter */
74 memmove(&adapter->if_ops, if_ops, sizeof(struct mwifiex_if_ops));
Zhaoyang Liuc687a002015-05-12 00:48:18 +053075 adapter->debug_mask = debug_mask;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070076
77 /* card specific initialization has been deferred until now .. */
Amitkumar Karwar4daffe32012-04-18 20:08:28 -070078 if (adapter->if_ops.init_if)
79 if (adapter->if_ops.init_if(adapter))
80 goto error;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070081
82 adapter->priv_num = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070083
Avinash Patil64b05e22012-05-08 18:30:13 -070084 for (i = 0; i < MWIFIEX_MAX_BSS_NUM; i++) {
85 /* Allocate memory for private structure */
86 adapter->priv[i] =
87 kzalloc(sizeof(struct mwifiex_private), GFP_KERNEL);
88 if (!adapter->priv[i])
89 goto error;
90
91 adapter->priv[i]->adapter = adapter;
Avinash Patil64b05e22012-05-08 18:30:13 -070092 adapter->priv_num++;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070093 }
Amitkumar Karwar44b815c2011-09-29 20:43:41 -070094 mwifiex_init_lock_list(adapter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -070095
Julia Lawallc6c33e72014-12-26 15:35:56 +010096 setup_timer(&adapter->cmd_timer, mwifiex_cmd_timeout_func,
97 (unsigned long)adapter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -070098
Bing Zhao5e6e3a92011-03-21 18:00:50 -070099 return 0;
100
101error:
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530102 mwifiex_dbg(adapter, ERROR,
103 "info: leave mwifiex_register with error\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700104
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -0700105 for (i = 0; i < adapter->priv_num; i++)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700106 kfree(adapter->priv[i]);
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -0700107
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700108 kfree(adapter);
109
110 return -1;
111}
112
113/*
114 * This function unregisters the device and performs all the necessary
115 * cleanups.
116 *
117 * The following cleanup operations are performed -
118 * - Free the timers
119 * - Free beacon buffers
120 * - Free private structures
121 * - Free adapter structure
122 */
123static int mwifiex_unregister(struct mwifiex_adapter *adapter)
124{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700125 s32 i;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700126
Amitkumar Karwar4cfda672013-07-22 19:17:50 -0700127 if (adapter->if_ops.cleanup_if)
128 adapter->if_ops.cleanup_if(adapter);
129
Avinash Patil629873f2014-02-18 15:47:55 -0800130 del_timer_sync(&adapter->cmd_timer);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700131
132 /* Free private structures */
133 for (i = 0; i < adapter->priv_num; i++) {
134 if (adapter->priv[i]) {
135 mwifiex_free_curr_bcn(adapter->priv[i]);
136 kfree(adapter->priv[i]);
137 }
138 }
139
chunfan chen7d7f07d2016-01-13 01:26:54 -0800140 if (adapter->nd_info) {
141 for (i = 0 ; i < adapter->nd_info->n_matches ; i++)
142 kfree(adapter->nd_info->matches[i]);
143 kfree(adapter->nd_info);
144 adapter->nd_info = NULL;
145 }
146
Amitkumar Karwar72539792016-08-09 20:20:46 +0530147 kfree(adapter->regd);
148
Avinash Patilbf354432014-10-31 16:08:26 +0530149 vfree(adapter->chan_stats);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700150 kfree(adapter);
151 return 0;
152}
153
Shengzhen Lib2713f62015-03-13 17:37:54 +0530154void mwifiex_queue_main_work(struct mwifiex_adapter *adapter)
155{
156 unsigned long flags;
157
158 spin_lock_irqsave(&adapter->main_proc_lock, flags);
159 if (adapter->mwifiex_processing) {
160 adapter->more_task_flag = true;
161 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
162 } else {
163 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
164 queue_work(adapter->workqueue, &adapter->main_work);
165 }
166}
167EXPORT_SYMBOL_GPL(mwifiex_queue_main_work);
168
169static void mwifiex_queue_rx_work(struct mwifiex_adapter *adapter)
170{
171 unsigned long flags;
172
173 spin_lock_irqsave(&adapter->rx_proc_lock, flags);
174 if (adapter->rx_processing) {
175 spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
176 } else {
177 spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
178 queue_work(adapter->rx_workqueue, &adapter->rx_work);
179 }
180}
181
Avinash Patil6e251172014-09-12 20:08:59 +0530182static int mwifiex_process_rx(struct mwifiex_adapter *adapter)
183{
184 unsigned long flags;
185 struct sk_buff *skb;
Zhaoyang Liu92263a82015-03-13 17:37:58 +0530186 struct mwifiex_rxinfo *rx_info;
Avinash Patil6e251172014-09-12 20:08:59 +0530187
188 spin_lock_irqsave(&adapter->rx_proc_lock, flags);
189 if (adapter->rx_processing || adapter->rx_locked) {
190 spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
191 goto exit_rx_proc;
192 } else {
193 adapter->rx_processing = true;
194 spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
195 }
196
197 /* Check for Rx data */
198 while ((skb = skb_dequeue(&adapter->rx_data_q))) {
199 atomic_dec(&adapter->rx_pending);
Amitkumar Karwar381e9ff2014-11-25 06:43:04 -0800200 if ((adapter->delay_main_work ||
201 adapter->iface_type == MWIFIEX_USB) &&
Avinash Patilb43a0d92014-09-29 21:44:14 +0530202 (atomic_read(&adapter->rx_pending) < LOW_RX_PENDING)) {
Amitkumar Karwarcf6a64f2014-11-05 17:04:29 +0530203 if (adapter->if_ops.submit_rem_rx_urbs)
204 adapter->if_ops.submit_rem_rx_urbs(adapter);
Avinash Patil6e251172014-09-12 20:08:59 +0530205 adapter->delay_main_work = false;
Shengzhen Lib2713f62015-03-13 17:37:54 +0530206 mwifiex_queue_main_work(adapter);
Avinash Patil6e251172014-09-12 20:08:59 +0530207 }
Zhaoyang Liu92263a82015-03-13 17:37:58 +0530208 rx_info = MWIFIEX_SKB_RXCB(skb);
209 if (rx_info->buf_type == MWIFIEX_TYPE_AGGR_DATA) {
210 if (adapter->if_ops.deaggr_pkt)
211 adapter->if_ops.deaggr_pkt(adapter, skb);
212 dev_kfree_skb_any(skb);
213 } else {
214 mwifiex_handle_rx_packet(adapter, skb);
215 }
Avinash Patil6e251172014-09-12 20:08:59 +0530216 }
217 spin_lock_irqsave(&adapter->rx_proc_lock, flags);
218 adapter->rx_processing = false;
219 spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
220
Avinash Patil6e251172014-09-12 20:08:59 +0530221exit_rx_proc:
222 return 0;
223}
224
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700225/*
226 * The main process.
227 *
228 * This function is the main procedure of the driver and handles various driver
229 * operations. It runs in a loop and provides the core functionalities.
230 *
231 * The main responsibilities of this function are -
232 * - Ensure concurrency control
233 * - Handle pending interrupts and call interrupt handlers
234 * - Wake up the card if required
235 * - Handle command responses and call response handlers
236 * - Handle events and call event handlers
237 * - Execute pending commands
238 * - Transmit pending data packets
239 */
240int mwifiex_main_process(struct mwifiex_adapter *adapter)
241{
242 int ret = 0;
243 unsigned long flags;
244
245 spin_lock_irqsave(&adapter->main_proc_lock, flags);
246
247 /* Check if already processing */
Avinash Patila9adbcb2015-03-13 17:37:51 +0530248 if (adapter->mwifiex_processing || adapter->main_locked) {
Shengzhen Li04c7b362015-02-11 23:12:24 +0530249 adapter->more_task_flag = true;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700250 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
251 goto exit_main_proc;
252 } else {
253 adapter->mwifiex_processing = true;
Cathy Luo91457ea2015-04-17 04:18:29 -0700254 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700255 }
256process_start:
257 do {
258 if ((adapter->hw_status == MWIFIEX_HW_STATUS_CLOSING) ||
259 (adapter->hw_status == MWIFIEX_HW_STATUS_NOT_READY))
260 break;
261
Amitkumar Karwar381e9ff2014-11-25 06:43:04 -0800262 /* For non-USB interfaces, If we process interrupts first, it
263 * would increase RX pending even further. Avoid this by
264 * checking if rx_pending has crossed high threshold and
265 * schedule rx work queue and then process interrupts.
266 * For USB interface, there are no interrupts. We already have
267 * HIGH_RX_PENDING check in usb.c
Avinash Patil6e251172014-09-12 20:08:59 +0530268 */
Amitkumar Karwar381e9ff2014-11-25 06:43:04 -0800269 if (atomic_read(&adapter->rx_pending) >= HIGH_RX_PENDING &&
270 adapter->iface_type != MWIFIEX_USB) {
Avinash Patil6e251172014-09-12 20:08:59 +0530271 adapter->delay_main_work = true;
Shengzhen Lib2713f62015-03-13 17:37:54 +0530272 mwifiex_queue_rx_work(adapter);
Avinash Patil6e251172014-09-12 20:08:59 +0530273 break;
274 }
275
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700276 /* Handle pending interrupt if any */
277 if (adapter->int_status) {
278 if (adapter->hs_activated)
279 mwifiex_process_hs_config(adapter);
Amitkumar Karwar4daffe32012-04-18 20:08:28 -0700280 if (adapter->if_ops.process_int_status)
281 adapter->if_ops.process_int_status(adapter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700282 }
283
Avinash Patil6e251172014-09-12 20:08:59 +0530284 if (adapter->rx_work_enabled && adapter->data_received)
Shengzhen Lib2713f62015-03-13 17:37:54 +0530285 mwifiex_queue_rx_work(adapter);
Avinash Patil6e251172014-09-12 20:08:59 +0530286
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700287 /* Need to wake up the card ? */
288 if ((adapter->ps_state == PS_STATE_SLEEP) &&
289 (adapter->pm_wakeup_card_req &&
290 !adapter->pm_wakeup_fw_try) &&
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -0700291 (is_command_pending(adapter) ||
Zhaoyang Liue35000e2015-03-13 17:37:57 +0530292 !skb_queue_empty(&adapter->tx_data_q) ||
Avinash Patila1777322015-06-22 19:06:17 +0530293 !mwifiex_bypass_txlist_empty(adapter) ||
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -0700294 !mwifiex_wmm_lists_empty(adapter))) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700295 adapter->pm_wakeup_fw_try = true;
Amitkumar Karwar46361872014-12-31 02:36:41 -0800296 mod_timer(&adapter->wakeup_timer, jiffies + (HZ*3));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700297 adapter->if_ops.wakeup(adapter);
298 continue;
299 }
Amitkumar Karwar4daffe32012-04-18 20:08:28 -0700300
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700301 if (IS_CARD_RX_RCVD(adapter)) {
Avinash Patil6e251172014-09-12 20:08:59 +0530302 adapter->data_received = false;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700303 adapter->pm_wakeup_fw_try = false;
Amitkumar Karwar6e9344f2015-03-12 00:38:40 -0700304 del_timer(&adapter->wakeup_timer);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700305 if (adapter->ps_state == PS_STATE_SLEEP)
306 adapter->ps_state = PS_STATE_AWAKE;
307 } else {
308 /* We have tried to wakeup the card already */
309 if (adapter->pm_wakeup_fw_try)
310 break;
Zhaoyang Liu7e4e5d22015-09-18 06:32:17 -0700311 if (adapter->ps_state != PS_STATE_AWAKE)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700312 break;
Zhaoyang Liu7e4e5d22015-09-18 06:32:17 -0700313 if (adapter->tx_lock_flag) {
314 if (adapter->iface_type == MWIFIEX_USB) {
315 if (!adapter->usb_mc_setup)
316 break;
317 } else
318 break;
319 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700320
Avinash Patil5ec39ef2014-09-12 20:08:56 +0530321 if ((!adapter->scan_chan_gap_enabled &&
Avinash Patil5ec39ef2014-09-12 20:08:56 +0530322 adapter->scan_processing) || adapter->data_sent ||
Xinming Huba101ad2015-06-22 19:06:10 +0530323 mwifiex_is_tdls_chan_switching
324 (mwifiex_get_priv(adapter,
325 MWIFIEX_BSS_ROLE_STA)) ||
Zhaoyang Liue35000e2015-03-13 17:37:57 +0530326 (mwifiex_wmm_lists_empty(adapter) &&
Avinash Patila1777322015-06-22 19:06:17 +0530327 mwifiex_bypass_txlist_empty(adapter) &&
Zhaoyang Liue35000e2015-03-13 17:37:57 +0530328 skb_queue_empty(&adapter->tx_data_q))) {
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -0700329 if (adapter->cmd_sent || adapter->curr_cmd ||
Xinming Huba101ad2015-06-22 19:06:10 +0530330 !mwifiex_is_send_cmd_allowed
331 (mwifiex_get_priv(adapter,
332 MWIFIEX_BSS_ROLE_STA)) ||
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -0700333 (!is_command_pending(adapter)))
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700334 break;
335 }
336 }
337
Amitkumar Karwar20474122014-04-14 15:31:05 -0700338 /* Check for event */
339 if (adapter->event_received) {
340 adapter->event_received = false;
341 mwifiex_process_event(adapter);
342 }
343
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700344 /* Check for Cmd Resp */
345 if (adapter->cmd_resp_received) {
346 adapter->cmd_resp_received = false;
347 mwifiex_process_cmdresp(adapter);
348
349 /* call mwifiex back when init_fw is done */
350 if (adapter->hw_status == MWIFIEX_HW_STATUS_INIT_DONE) {
351 adapter->hw_status = MWIFIEX_HW_STATUS_READY;
352 mwifiex_init_fw_complete(adapter);
353 }
354 }
355
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700356 /* Check if we need to confirm Sleep Request
357 received previously */
358 if (adapter->ps_state == PS_STATE_PRE_SLEEP) {
359 if (!adapter->cmd_sent && !adapter->curr_cmd)
360 mwifiex_check_ps_cond(adapter);
361 }
362
363 /* * The ps_state may have been changed during processing of
364 * Sleep Request event.
365 */
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -0700366 if ((adapter->ps_state == PS_STATE_SLEEP) ||
367 (adapter->ps_state == PS_STATE_PRE_SLEEP) ||
Zhaoyang Liu7e4e5d22015-09-18 06:32:17 -0700368 (adapter->ps_state == PS_STATE_SLEEP_CFM)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700369 continue;
Shengzhen Li04c7b362015-02-11 23:12:24 +0530370 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700371
Zhaoyang Liu7e4e5d22015-09-18 06:32:17 -0700372 if (adapter->tx_lock_flag) {
373 if (adapter->iface_type == MWIFIEX_USB) {
374 if (!adapter->usb_mc_setup)
375 continue;
376 } else
377 continue;
378 }
379
Xinming Huba101ad2015-06-22 19:06:10 +0530380 if (!adapter->cmd_sent && !adapter->curr_cmd &&
381 mwifiex_is_send_cmd_allowed
382 (mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA))) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700383 if (mwifiex_exec_next_cmd(adapter) == -1) {
384 ret = -1;
385 break;
386 }
387 }
388
Zhaoyang Liu7e4e5d22015-09-18 06:32:17 -0700389 /** If USB Multi channel setup ongoing,
390 * wait for ready to tx data.
391 */
392 if (adapter->iface_type == MWIFIEX_USB &&
393 adapter->usb_mc_setup)
394 continue;
395
Avinash Patil5ec39ef2014-09-12 20:08:56 +0530396 if ((adapter->scan_chan_gap_enabled ||
Amitkumar Karward8d91252014-09-12 20:08:58 +0530397 !adapter->scan_processing) &&
Zhaoyang Liue35000e2015-03-13 17:37:57 +0530398 !adapter->data_sent &&
399 !skb_queue_empty(&adapter->tx_data_q)) {
400 mwifiex_process_tx_queue(adapter);
401 if (adapter->hs_activated) {
402 adapter->is_hs_configured = false;
403 mwifiex_hs_activated_event
404 (mwifiex_get_priv
405 (adapter, MWIFIEX_BSS_ROLE_ANY),
406 false);
407 }
408 }
409
410 if ((adapter->scan_chan_gap_enabled ||
411 !adapter->scan_processing) &&
Avinash Patila1777322015-06-22 19:06:17 +0530412 !adapter->data_sent &&
413 !mwifiex_bypass_txlist_empty(adapter) &&
414 !mwifiex_is_tdls_chan_switching
415 (mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA))) {
416 mwifiex_process_bypass_tx(adapter);
417 if (adapter->hs_activated) {
418 adapter->is_hs_configured = false;
419 mwifiex_hs_activated_event
420 (mwifiex_get_priv
421 (adapter, MWIFIEX_BSS_ROLE_ANY),
422 false);
423 }
424 }
425
426 if ((adapter->scan_chan_gap_enabled ||
427 !adapter->scan_processing) &&
Xinming Huba101ad2015-06-22 19:06:10 +0530428 !adapter->data_sent && !mwifiex_wmm_lists_empty(adapter) &&
429 !mwifiex_is_tdls_chan_switching
430 (mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA))) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700431 mwifiex_wmm_process_tx(adapter);
432 if (adapter->hs_activated) {
433 adapter->is_hs_configured = false;
434 mwifiex_hs_activated_event
435 (mwifiex_get_priv
436 (adapter, MWIFIEX_BSS_ROLE_ANY),
437 false);
438 }
439 }
440
441 if (adapter->delay_null_pkt && !adapter->cmd_sent &&
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -0700442 !adapter->curr_cmd && !is_command_pending(adapter) &&
Zhaoyang Liue35000e2015-03-13 17:37:57 +0530443 (mwifiex_wmm_lists_empty(adapter) &&
Avinash Patila1777322015-06-22 19:06:17 +0530444 mwifiex_bypass_txlist_empty(adapter) &&
Zhaoyang Liue35000e2015-03-13 17:37:57 +0530445 skb_queue_empty(&adapter->tx_data_q))) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700446 if (!mwifiex_send_null_packet
447 (mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA),
448 MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET |
449 MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET)) {
450 adapter->delay_null_pkt = false;
451 adapter->ps_state = PS_STATE_SLEEP;
452 }
453 break;
454 }
455 } while (true);
456
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700457 spin_lock_irqsave(&adapter->main_proc_lock, flags);
Cathy Luo91457ea2015-04-17 04:18:29 -0700458 if (adapter->more_task_flag) {
459 adapter->more_task_flag = false;
460 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
Amitkumar Karwar453b0c32013-09-27 10:55:38 -0700461 goto process_start;
Cathy Luo91457ea2015-04-17 04:18:29 -0700462 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700463 adapter->mwifiex_processing = false;
464 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
465
466exit_main_proc:
467 if (adapter->hw_status == MWIFIEX_HW_STATUS_CLOSING)
468 mwifiex_shutdown_drv(adapter);
469 return ret;
470}
Bing Zhao601216e2012-11-05 16:59:15 -0800471EXPORT_SYMBOL_GPL(mwifiex_main_process);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700472
473/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700474 * This function frees the adapter structure.
475 *
476 * Additionally, this closes the netlink socket, frees the timers
477 * and private structures.
478 */
479static void mwifiex_free_adapter(struct mwifiex_adapter *adapter)
480{
481 if (!adapter) {
482 pr_err("%s: adapter is NULL\n", __func__);
483 return;
484 }
485
486 mwifiex_unregister(adapter);
487 pr_debug("info: %s: free adapter\n", __func__);
488}
489
490/*
Amitkumar Karwar6b41f942013-07-22 19:17:55 -0700491 * This function cancels all works in the queue and destroys
492 * the main workqueue.
493 */
494static void mwifiex_terminate_workqueue(struct mwifiex_adapter *adapter)
495{
Amitkumar Karwar4c5dae52016-07-26 19:31:44 +0530496 if (adapter->workqueue) {
497 flush_workqueue(adapter->workqueue);
498 destroy_workqueue(adapter->workqueue);
499 adapter->workqueue = NULL;
500 }
Avinash Patil6e251172014-09-12 20:08:59 +0530501
502 if (adapter->rx_workqueue) {
503 flush_workqueue(adapter->rx_workqueue);
504 destroy_workqueue(adapter->rx_workqueue);
505 adapter->rx_workqueue = NULL;
506 }
Amitkumar Karwar6b41f942013-07-22 19:17:55 -0700507}
508
509/*
Amitkumar Karwar59a4cc22012-04-09 20:06:57 -0700510 * This function gets firmware and initializes it.
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700511 *
512 * The main initialization steps followed are -
513 * - Download the correct firmware to card
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700514 * - Issue the init commands to firmware
515 */
Amitkumar Karwar59a4cc22012-04-09 20:06:57 -0700516static void mwifiex_fw_dpc(const struct firmware *firmware, void *context)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700517{
Amitkumar Karwarbec568f2013-11-14 19:10:38 -0800518 int ret;
Amitkumar Karwar59a4cc22012-04-09 20:06:57 -0700519 char fmt[64];
520 struct mwifiex_private *priv;
521 struct mwifiex_adapter *adapter = context;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700522 struct mwifiex_fw_image fw;
Amitkumar Karwarc3afd992013-07-30 17:18:15 -0700523 struct semaphore *sem = adapter->card_sem;
524 bool init_failed = false;
Amitkumar Karwar68b76e92013-11-14 19:10:37 -0800525 struct wireless_dev *wdev;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700526
Amitkumar Karwar59a4cc22012-04-09 20:06:57 -0700527 if (!firmware) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530528 mwifiex_dbg(adapter, ERROR,
529 "Failed to get firmware %s\n", adapter->fw_name);
Amitkumar Karwar6b41f942013-07-22 19:17:55 -0700530 goto err_dnld_fw;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700531 }
Amitkumar Karwar59a4cc22012-04-09 20:06:57 -0700532
533 memset(&fw, 0, sizeof(struct mwifiex_fw_image));
534 adapter->firmware = firmware;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700535 fw.fw_buf = (u8 *) adapter->firmware->data;
536 fw.fw_len = adapter->firmware->size;
537
Wei-Ning Huang65c71ef2016-05-19 11:53:43 +0800538 if (adapter->if_ops.dnld_fw) {
Amitkumar Karwar4daffe32012-04-18 20:08:28 -0700539 ret = adapter->if_ops.dnld_fw(adapter, &fw);
Wei-Ning Huang65c71ef2016-05-19 11:53:43 +0800540 } else {
Amitkumar Karwar4daffe32012-04-18 20:08:28 -0700541 ret = mwifiex_dnld_fw(adapter, &fw);
Wei-Ning Huang65c71ef2016-05-19 11:53:43 +0800542 }
543
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700544 if (ret == -1)
Amitkumar Karwar6b41f942013-07-22 19:17:55 -0700545 goto err_dnld_fw;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700546
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530547 mwifiex_dbg(adapter, MSG, "WLAN FW is active\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700548
Amitkumar Karwar388ec382013-05-17 17:50:25 -0700549 if (cal_data_cfg) {
550 if ((request_firmware(&adapter->cal_data, cal_data_cfg,
551 adapter->dev)) < 0)
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530552 mwifiex_dbg(adapter, ERROR,
553 "Cal data request_firmware() failed\n");
Amitkumar Karwar388ec382013-05-17 17:50:25 -0700554 }
555
Daniel Drake232fde02013-07-13 10:57:10 -0400556 /* enable host interrupt after fw dnld is successful */
Amitkumar Karwar6b41f942013-07-22 19:17:55 -0700557 if (adapter->if_ops.enable_int) {
558 if (adapter->if_ops.enable_int(adapter))
559 goto err_dnld_fw;
560 }
Daniel Drake232fde02013-07-13 10:57:10 -0400561
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700562 adapter->init_wait_q_woken = false;
563 ret = mwifiex_init_fw(adapter);
564 if (ret == -1) {
Amitkumar Karwar6b41f942013-07-22 19:17:55 -0700565 goto err_init_fw;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700566 } else if (!ret) {
567 adapter->hw_status = MWIFIEX_HW_STATUS_READY;
568 goto done;
569 }
570 /* Wait for mwifiex_init to complete */
Xinming Hucf5383b2016-09-02 13:05:06 +0530571 if (!adapter->mfg_mode) {
572 wait_event_interruptible(adapter->init_wait_q,
573 adapter->init_wait_q_woken);
574 if (adapter->hw_status != MWIFIEX_HW_STATUS_READY)
575 goto err_init_fw;
576 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700577
Avinash Patild6bffe82012-05-08 18:30:15 -0700578 priv = adapter->priv[MWIFIEX_BSS_ROLE_STA];
Amitkumar Karwar4c5dae52016-07-26 19:31:44 +0530579
580 if (!adapter->wiphy) {
581 if (mwifiex_register_cfg80211(adapter)) {
582 mwifiex_dbg(adapter, ERROR,
583 "cannot register with cfg80211\n");
584 goto err_init_fw;
585 }
Amitkumar Karwar59a4cc22012-04-09 20:06:57 -0700586 }
587
Avinash Patilbf354432014-10-31 16:08:26 +0530588 if (mwifiex_init_channel_scan_gap(adapter)) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530589 mwifiex_dbg(adapter, ERROR,
590 "could not init channel stats table\n");
Avinash Patilbf354432014-10-31 16:08:26 +0530591 goto err_init_fw;
592 }
593
Avinash Patil0013c7c2014-11-05 19:38:11 +0530594 if (driver_mode) {
595 driver_mode &= MWIFIEX_DRIVER_MODE_BITMASK;
596 driver_mode |= MWIFIEX_DRIVER_MODE_STA;
597 }
598
Amitkumar Karwar59a4cc22012-04-09 20:06:57 -0700599 rtnl_lock();
600 /* Create station interface by default */
Tom Gundersen6bab2e192015-03-18 11:13:39 +0100601 wdev = mwifiex_add_virtual_intf(adapter->wiphy, "mlan%d", NET_NAME_ENUM,
Amitkumar Karwar68b76e92013-11-14 19:10:37 -0800602 NL80211_IFTYPE_STATION, NULL, NULL);
603 if (IS_ERR(wdev)) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530604 mwifiex_dbg(adapter, ERROR,
605 "cannot create default STA interface\n");
Amitkumar Karwarbec568f2013-11-14 19:10:38 -0800606 rtnl_unlock();
Amitkumar Karwar59a4cc22012-04-09 20:06:57 -0700607 goto err_add_intf;
608 }
Avinash Patil0013c7c2014-11-05 19:38:11 +0530609
610 if (driver_mode & MWIFIEX_DRIVER_MODE_UAP) {
Tom Gundersen6bab2e192015-03-18 11:13:39 +0100611 wdev = mwifiex_add_virtual_intf(adapter->wiphy, "uap%d", NET_NAME_ENUM,
Avinash Patil0013c7c2014-11-05 19:38:11 +0530612 NL80211_IFTYPE_AP, NULL, NULL);
613 if (IS_ERR(wdev)) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530614 mwifiex_dbg(adapter, ERROR,
615 "cannot create AP interface\n");
Avinash Patil0013c7c2014-11-05 19:38:11 +0530616 rtnl_unlock();
617 goto err_add_intf;
618 }
619 }
620
621 if (driver_mode & MWIFIEX_DRIVER_MODE_P2P) {
Tom Gundersen6bab2e192015-03-18 11:13:39 +0100622 wdev = mwifiex_add_virtual_intf(adapter->wiphy, "p2p%d", NET_NAME_ENUM,
Avinash Patil0013c7c2014-11-05 19:38:11 +0530623 NL80211_IFTYPE_P2P_CLIENT, NULL,
624 NULL);
625 if (IS_ERR(wdev)) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530626 mwifiex_dbg(adapter, ERROR,
627 "cannot create p2p client interface\n");
Avinash Patil0013c7c2014-11-05 19:38:11 +0530628 rtnl_unlock();
629 goto err_add_intf;
630 }
631 }
Amitkumar Karwar59a4cc22012-04-09 20:06:57 -0700632 rtnl_unlock();
633
634 mwifiex_drv_get_driver_version(adapter, fmt, sizeof(fmt) - 1);
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530635 mwifiex_dbg(adapter, MSG, "driver_version = %s\n", fmt);
Amitkumar Karwar59a4cc22012-04-09 20:06:57 -0700636 goto done;
637
638err_add_intf:
Amitkumar Karwar6b41f942013-07-22 19:17:55 -0700639 wiphy_unregister(adapter->wiphy);
640 wiphy_free(adapter->wiphy);
Amitkumar Karwar59a4cc22012-04-09 20:06:57 -0700641err_init_fw:
Daniel Drake232fde02013-07-13 10:57:10 -0400642 if (adapter->if_ops.disable_int)
643 adapter->if_ops.disable_int(adapter);
Amitkumar Karwar6b41f942013-07-22 19:17:55 -0700644err_dnld_fw:
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530645 mwifiex_dbg(adapter, ERROR,
646 "info: %s: unregister device\n", __func__);
Amitkumar Karwar6b41f942013-07-22 19:17:55 -0700647 if (adapter->if_ops.unregister_dev)
648 adapter->if_ops.unregister_dev(adapter);
649
Amitkumar Karwar71973252014-12-31 02:36:38 -0800650 if (adapter->hw_status == MWIFIEX_HW_STATUS_READY) {
Amitkumar Karwar6b41f942013-07-22 19:17:55 -0700651 pr_debug("info: %s: shutdown mwifiex\n", __func__);
652 adapter->init_wait_q_woken = false;
653
654 if (mwifiex_shutdown_drv(adapter) == -EINPROGRESS)
655 wait_event_interruptible(adapter->init_wait_q,
656 adapter->init_wait_q_woken);
657 }
658 adapter->surprise_removed = true;
659 mwifiex_terminate_workqueue(adapter);
Amitkumar Karwarc3afd992013-07-30 17:18:15 -0700660 init_failed = true;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700661done:
Amitkumar Karwar388ec382013-05-17 17:50:25 -0700662 if (adapter->cal_data) {
663 release_firmware(adapter->cal_data);
664 adapter->cal_data = NULL;
665 }
Amitkumar Karwarc3afd992013-07-30 17:18:15 -0700666 if (adapter->firmware) {
667 release_firmware(adapter->firmware);
668 adapter->firmware = NULL;
669 }
Amitkumar Karwarc3afd992013-07-30 17:18:15 -0700670 if (init_failed)
671 mwifiex_free_adapter(adapter);
672 up(sem);
Amitkumar Karwar59a4cc22012-04-09 20:06:57 -0700673 return;
674}
675
676/*
677 * This function initializes the hardware and gets firmware.
678 */
Amitkumar Karwar4c5dae52016-07-26 19:31:44 +0530679static int mwifiex_init_hw_fw(struct mwifiex_adapter *adapter,
680 bool req_fw_nowait)
Amitkumar Karwar59a4cc22012-04-09 20:06:57 -0700681{
682 int ret;
683
Xinming Hucf5383b2016-09-02 13:05:06 +0530684 /* Override default firmware with manufacturing one if
685 * manufacturing mode is enabled
686 */
687 if (mfg_mode) {
688 if (strlcpy(adapter->fw_name, MFG_FIRMWARE,
689 sizeof(adapter->fw_name)) >=
690 sizeof(adapter->fw_name)) {
691 pr_err("%s: fw_name too long!\n", __func__);
692 return -1;
693 }
694 }
Amitkumar Karwar4c5dae52016-07-26 19:31:44 +0530695
696 if (req_fw_nowait) {
697 ret = request_firmware_nowait(THIS_MODULE, 1, adapter->fw_name,
698 adapter->dev, GFP_KERNEL, adapter,
699 mwifiex_fw_dpc);
700 if (ret < 0)
701 mwifiex_dbg(adapter, ERROR,
702 "request_firmware_nowait error %d\n", ret);
703 } else {
704 ret = request_firmware(&adapter->firmware,
705 adapter->fw_name,
706 adapter->dev);
707 if (ret < 0)
708 mwifiex_dbg(adapter, ERROR,
709 "request_firmware error %d\n", ret);
710 else
711 mwifiex_fw_dpc(adapter->firmware, (void *)adapter);
712 }
713
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700714 return ret;
715}
716
717/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700718 * CFG802.11 network device handler for open.
719 *
720 * Starts the data queue.
721 */
722static int
723mwifiex_open(struct net_device *dev)
724{
Johannes Bergea2325b2015-01-19 15:54:36 +0530725 netif_carrier_off(dev);
726
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700727 return 0;
728}
729
730/*
731 * CFG802.11 network device handler for close.
732 */
733static int
734mwifiex_close(struct net_device *dev)
735{
Amitkumar Karwarf162cac2012-10-19 19:19:16 -0700736 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
737
738 if (priv->scan_request) {
Avraham Stern1d762502016-07-05 17:10:13 +0300739 struct cfg80211_scan_info info = {
740 .aborted = true,
741 };
742
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530743 mwifiex_dbg(priv->adapter, INFO,
744 "aborting scan on ndo_stop\n");
Avraham Stern1d762502016-07-05 17:10:13 +0300745 cfg80211_scan_done(priv->scan_request, &info);
Amitkumar Karwarf162cac2012-10-19 19:19:16 -0700746 priv->scan_request = NULL;
Amitkumar Karwar75ab7532013-05-17 17:50:20 -0700747 priv->scan_aborting = true;
Amitkumar Karwarf162cac2012-10-19 19:19:16 -0700748 }
749
Xinming Hueaf46b52016-04-18 06:42:55 -0700750 if (priv->sched_scanning) {
751 mwifiex_dbg(priv->adapter, INFO,
752 "aborting bgscan on ndo_stop\n");
753 mwifiex_stop_bg_scan(priv);
754 cfg80211_sched_scan_stopped(priv->wdev.wiphy);
755 }
756
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700757 return 0;
758}
759
Avinash Patila1777322015-06-22 19:06:17 +0530760static bool
761mwifiex_bypass_tx_queue(struct mwifiex_private *priv,
762 struct sk_buff *skb)
763{
764 struct ethhdr *eth_hdr = (struct ethhdr *)skb->data;
765
766 if (ntohs(eth_hdr->h_proto) == ETH_P_PAE ||
767 mwifiex_is_skb_mgmt_frame(skb) ||
768 (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA &&
769 ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) &&
770 (ntohs(eth_hdr->h_proto) == ETH_P_TDLS))) {
771 mwifiex_dbg(priv->adapter, DATA,
772 "bypass txqueue; eth type %#x, mgmt %d\n",
773 ntohs(eth_hdr->h_proto),
774 mwifiex_is_skb_mgmt_frame(skb));
775 return true;
776 }
777
778 return false;
779}
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700780/*
Stone Piaoe39faa72012-09-25 20:23:32 -0700781 * Add buffer into wmm tx queue and queue work to transmit it.
782 */
783int mwifiex_queue_tx_pkt(struct mwifiex_private *priv, struct sk_buff *skb)
784{
Avinash Patil47411a02012-11-01 18:44:16 -0700785 struct netdev_queue *txq;
786 int index = mwifiex_1d_to_wmm_queue[skb->priority];
787
788 if (atomic_inc_return(&priv->wmm_tx_pending[index]) >= MAX_TX_PENDING) {
789 txq = netdev_get_tx_queue(priv->netdev, index);
790 if (!netif_tx_queue_stopped(txq)) {
791 netif_tx_stop_queue(txq);
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530792 mwifiex_dbg(priv->adapter, DATA,
793 "stop queue: %d\n", index);
Avinash Patil47411a02012-11-01 18:44:16 -0700794 }
795 }
796
Avinash Patila1777322015-06-22 19:06:17 +0530797 if (mwifiex_bypass_tx_queue(priv, skb)) {
798 atomic_inc(&priv->adapter->tx_pending);
799 atomic_inc(&priv->adapter->bypass_tx_pending);
800 mwifiex_wmm_add_buf_bypass_txqueue(priv, skb);
801 } else {
802 atomic_inc(&priv->adapter->tx_pending);
803 mwifiex_wmm_add_buf_txqueue(priv, skb);
804 }
Stone Piaoe39faa72012-09-25 20:23:32 -0700805
Shengzhen Lib2713f62015-03-13 17:37:54 +0530806 mwifiex_queue_main_work(priv->adapter);
Stone Piaoe39faa72012-09-25 20:23:32 -0700807
808 return 0;
809}
810
Amitkumar Karwar18ca4382014-11-25 06:43:06 -0800811struct sk_buff *
Amitkumar Karwar808bbeb2014-11-25 06:43:05 -0800812mwifiex_clone_skb_for_tx_status(struct mwifiex_private *priv,
Amitkumar Karwar18ca4382014-11-25 06:43:06 -0800813 struct sk_buff *skb, u8 flag, u64 *cookie)
Amitkumar Karwar808bbeb2014-11-25 06:43:05 -0800814{
815 struct sk_buff *orig_skb = skb;
816 struct mwifiex_txinfo *tx_info, *orig_tx_info;
817
818 skb = skb_clone(skb, GFP_ATOMIC);
819 if (skb) {
820 unsigned long flags;
821 int id;
822
823 spin_lock_irqsave(&priv->ack_status_lock, flags);
824 id = idr_alloc(&priv->ack_status_frames, orig_skb,
Amitkumar Karwaree548d42015-12-31 06:24:15 -0800825 1, 0x10, GFP_ATOMIC);
Amitkumar Karwar808bbeb2014-11-25 06:43:05 -0800826 spin_unlock_irqrestore(&priv->ack_status_lock, flags);
827
828 if (id >= 0) {
829 tx_info = MWIFIEX_SKB_TXCB(skb);
830 tx_info->ack_frame_id = id;
831 tx_info->flags |= flag;
832 orig_tx_info = MWIFIEX_SKB_TXCB(orig_skb);
833 orig_tx_info->ack_frame_id = id;
834 orig_tx_info->flags |= flag;
Amitkumar Karwar18ca4382014-11-25 06:43:06 -0800835
836 if (flag == MWIFIEX_BUF_FLAG_ACTION_TX_STATUS && cookie)
837 orig_tx_info->cookie = *cookie;
838
Amitkumar Karwar808bbeb2014-11-25 06:43:05 -0800839 } else if (skb_shared(skb)) {
840 kfree_skb(orig_skb);
841 } else {
842 kfree_skb(skb);
843 skb = orig_skb;
844 }
845 } else {
846 /* couldn't clone -- lose tx status ... */
847 skb = orig_skb;
848 }
849
850 return skb;
851}
852
Stone Piaoe39faa72012-09-25 20:23:32 -0700853/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700854 * CFG802.11 network device handler for data transmission.
855 */
856static int
857mwifiex_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
858{
859 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700860 struct sk_buff *new_skb;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700861 struct mwifiex_txinfo *tx_info;
Amitkumar Karwar808bbeb2014-11-25 06:43:05 -0800862 bool multicast;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700863
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530864 mwifiex_dbg(priv->adapter, DATA,
865 "data: %lu BSS(%d-%d): Data <= kernel\n",
866 jiffies, priv->bss_type, priv->bss_num);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700867
868 if (priv->adapter->surprise_removed) {
Christoph Fritzb53575e2011-05-08 22:50:09 +0200869 kfree_skb(skb);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700870 priv->stats.tx_dropped++;
871 return 0;
872 }
873 if (!skb->len || (skb->len > ETH_FRAME_LEN)) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530874 mwifiex_dbg(priv->adapter, ERROR,
875 "Tx: bad skb len %d\n", skb->len);
Christoph Fritzb53575e2011-05-08 22:50:09 +0200876 kfree_skb(skb);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700877 priv->stats.tx_dropped++;
878 return 0;
879 }
880 if (skb_headroom(skb) < MWIFIEX_MIN_DATA_HEADER_LEN) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530881 mwifiex_dbg(priv->adapter, DATA,
882 "data: Tx: insufficient skb headroom %d\n",
883 skb_headroom(skb));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700884 /* Insufficient skb headroom - allocate a new skb */
885 new_skb =
886 skb_realloc_headroom(skb, MWIFIEX_MIN_DATA_HEADER_LEN);
887 if (unlikely(!new_skb)) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530888 mwifiex_dbg(priv->adapter, ERROR,
889 "Tx: cannot alloca new_skb\n");
Christoph Fritzb53575e2011-05-08 22:50:09 +0200890 kfree_skb(skb);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700891 priv->stats.tx_dropped++;
892 return 0;
893 }
894 kfree_skb(skb);
895 skb = new_skb;
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530896 mwifiex_dbg(priv->adapter, INFO,
897 "info: new skb headroomd %d\n",
898 skb_headroom(skb));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700899 }
900
901 tx_info = MWIFIEX_SKB_TXCB(skb);
Amitkumar Karward76744a2014-06-20 11:45:25 -0700902 memset(tx_info, 0, sizeof(*tx_info));
Yogesh Ashok Powar9da9a3b2012-01-11 20:06:11 -0800903 tx_info->bss_num = priv->bss_num;
904 tx_info->bss_type = priv->bss_type;
Ujjal Roya1ed4842013-12-02 23:17:55 -0800905 tx_info->pkt_len = skb->len;
Avinash Patil47411a02012-11-01 18:44:16 -0700906
Amitkumar Karwar808bbeb2014-11-25 06:43:05 -0800907 multicast = is_multicast_ether_addr(skb->data);
908
909 if (unlikely(!multicast && skb->sk &&
910 skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS &&
911 priv->adapter->fw_api_ver == MWIFIEX_FW_V15))
912 skb = mwifiex_clone_skb_for_tx_status(priv,
913 skb,
Amitkumar Karwar18ca4382014-11-25 06:43:06 -0800914 MWIFIEX_BUF_FLAG_EAPOL_TX_STATUS, NULL);
Amitkumar Karwar808bbeb2014-11-25 06:43:05 -0800915
Avinash Patil47411a02012-11-01 18:44:16 -0700916 /* Record the current time the packet was queued; used to
917 * determine the amount of time the packet was queued in
918 * the driver before it was sent to the firmware.
919 * The delay is then sent along with the packet to the
920 * firmware for aggregate delay calculation for stats and
921 * MSDU lifetime expiry.
922 */
Thomas Gleixnerc64800e2014-06-12 08:31:34 +0100923 __net_timestamp(skb);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700924
Avinash Patil9927baa2014-11-13 21:54:16 +0530925 if (ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) &&
926 priv->bss_type == MWIFIEX_BSS_TYPE_STA &&
927 !ether_addr_equal_unaligned(priv->cfg_bssid, skb->data)) {
928 if (priv->adapter->auto_tdls && priv->check_tdls_tx)
929 mwifiex_tdls_check_tx(priv, skb);
930 }
931
Stone Piaoe39faa72012-09-25 20:23:32 -0700932 mwifiex_queue_tx_pkt(priv, skb);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700933
934 return 0;
935}
936
937/*
938 * CFG802.11 network device handler for setting MAC address.
939 */
940static int
941mwifiex_set_mac_address(struct net_device *dev, void *addr)
942{
943 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700944 struct sockaddr *hw_addr = addr;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700945 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700946
947 memcpy(priv->curr_addr, hw_addr->sa_data, ETH_ALEN);
948
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700949 /* Send request to firmware */
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800950 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_MAC_ADDRESS,
951 HostCmd_ACT_GEN_SET, 0, NULL, true);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700952
953 if (!ret)
954 memcpy(priv->netdev->dev_addr, priv->curr_addr, ETH_ALEN);
955 else
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530956 mwifiex_dbg(priv->adapter, ERROR,
957 "set mac address failed: ret=%d\n", ret);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700958
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700959 memcpy(dev->dev_addr, priv->curr_addr, ETH_ALEN);
960
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700961 return ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700962}
963
964/*
965 * CFG802.11 network device handler for setting multicast list.
966 */
967static void mwifiex_set_multicast_list(struct net_device *dev)
968{
969 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700970 struct mwifiex_multicast_list mcast_list;
971
972 if (dev->flags & IFF_PROMISC) {
973 mcast_list.mode = MWIFIEX_PROMISC_MODE;
974 } else if (dev->flags & IFF_ALLMULTI ||
975 netdev_mc_count(dev) > MWIFIEX_MAX_MULTICAST_LIST_SIZE) {
976 mcast_list.mode = MWIFIEX_ALL_MULTI_MODE;
977 } else {
978 mcast_list.mode = MWIFIEX_MULTICAST_MODE;
Daniel Drake6390d882013-06-14 15:24:24 -0400979 mcast_list.num_multicast_addr =
980 mwifiex_copy_mcast_addr(&mcast_list, dev);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700981 }
982 mwifiex_request_set_multicast_list(priv, &mcast_list);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700983}
984
985/*
986 * CFG802.11 network device handler for transmission timeout.
987 */
988static void
989mwifiex_tx_timeout(struct net_device *dev)
990{
991 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
992
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700993 priv->num_tx_timeout++;
Ashok Nagarajan8908c7d2013-03-08 10:58:45 -0800994 priv->tx_timeout_cnt++;
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530995 mwifiex_dbg(priv->adapter, ERROR,
996 "%lu : Tx timeout(#%d), bss_type-num = %d-%d\n",
997 jiffies, priv->tx_timeout_cnt, priv->bss_type,
998 priv->bss_num);
Ashok Nagarajan8908c7d2013-03-08 10:58:45 -0800999 mwifiex_set_trans_start(dev);
1000
1001 if (priv->tx_timeout_cnt > TX_TIMEOUT_THRESHOLD &&
1002 priv->adapter->if_ops.card_reset) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301003 mwifiex_dbg(priv->adapter, ERROR,
1004 "tx_timeout_cnt exceeds threshold.\t"
1005 "Triggering card reset!\n");
Ashok Nagarajan8908c7d2013-03-08 10:58:45 -08001006 priv->adapter->if_ops.card_reset(priv->adapter);
1007 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001008}
1009
Zhaoyang Liu7e4e5d22015-09-18 06:32:17 -07001010void mwifiex_multi_chan_resync(struct mwifiex_adapter *adapter)
1011{
1012 struct usb_card_rec *card = adapter->card;
1013 struct mwifiex_private *priv;
1014 u16 tx_buf_size;
1015 int i, ret;
1016
1017 card->mc_resync_flag = true;
1018 for (i = 0; i < MWIFIEX_TX_DATA_PORT; i++) {
1019 if (atomic_read(&card->port[i].tx_data_urb_pending)) {
1020 mwifiex_dbg(adapter, WARN, "pending data urb in sys\n");
1021 return;
1022 }
1023 }
1024
1025 card->mc_resync_flag = false;
1026 tx_buf_size = 0xffff;
1027 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
1028 ret = mwifiex_send_cmd(priv, HostCmd_CMD_RECONFIGURE_TX_BUFF,
1029 HostCmd_ACT_GEN_SET, 0, &tx_buf_size, false);
1030 if (ret)
1031 mwifiex_dbg(adapter, ERROR,
1032 "send reconfig tx buf size cmd err\n");
1033}
1034EXPORT_SYMBOL_GPL(mwifiex_multi_chan_resync);
1035
Amitkumar Karwarfc697152015-05-26 06:34:31 -07001036void mwifiex_drv_info_dump(struct mwifiex_adapter *adapter)
Xinming Hu11cd07a2014-12-23 19:14:10 +05301037{
1038 void *p;
1039 char drv_version[64];
1040 struct usb_card_rec *cardp;
1041 struct sdio_mmc_card *sdio_card;
1042 struct mwifiex_private *priv;
1043 int i, idx;
1044 struct netdev_queue *txq;
1045 struct mwifiex_debug_info *debug_info;
1046
1047 if (adapter->drv_info_dump) {
1048 vfree(adapter->drv_info_dump);
Amitkumar Karwar0769b272015-05-26 06:34:28 -07001049 adapter->drv_info_dump = NULL;
Xinming Hu11cd07a2014-12-23 19:14:10 +05301050 adapter->drv_info_size = 0;
1051 }
1052
Amitkumar Karwar9cc0dbf02015-05-26 06:34:30 -07001053 mwifiex_dbg(adapter, MSG, "===mwifiex driverinfo dump start===\n");
Xinming Hu11cd07a2014-12-23 19:14:10 +05301054
1055 adapter->drv_info_dump = vzalloc(MWIFIEX_DRV_INFO_SIZE_MAX);
1056
1057 if (!adapter->drv_info_dump)
1058 return;
1059
1060 p = (char *)(adapter->drv_info_dump);
1061 p += sprintf(p, "driver_name = " "\"mwifiex\"\n");
1062
1063 mwifiex_drv_get_driver_version(adapter, drv_version,
1064 sizeof(drv_version) - 1);
1065 p += sprintf(p, "driver_version = %s\n", drv_version);
1066
1067 if (adapter->iface_type == MWIFIEX_USB) {
1068 cardp = (struct usb_card_rec *)adapter->card;
1069 p += sprintf(p, "tx_cmd_urb_pending = %d\n",
1070 atomic_read(&cardp->tx_cmd_urb_pending));
Zhaoyang Liu308fe292015-09-18 06:32:16 -07001071 p += sprintf(p, "tx_data_urb_pending_port_0 = %d\n",
1072 atomic_read(&cardp->port[0].tx_data_urb_pending));
1073 p += sprintf(p, "tx_data_urb_pending_port_1 = %d\n",
1074 atomic_read(&cardp->port[1].tx_data_urb_pending));
Xinming Hu11cd07a2014-12-23 19:14:10 +05301075 p += sprintf(p, "rx_cmd_urb_pending = %d\n",
1076 atomic_read(&cardp->rx_cmd_urb_pending));
1077 p += sprintf(p, "rx_data_urb_pending = %d\n",
1078 atomic_read(&cardp->rx_data_urb_pending));
1079 }
1080
1081 p += sprintf(p, "tx_pending = %d\n",
1082 atomic_read(&adapter->tx_pending));
1083 p += sprintf(p, "rx_pending = %d\n",
1084 atomic_read(&adapter->rx_pending));
1085
1086 if (adapter->iface_type == MWIFIEX_SDIO) {
1087 sdio_card = (struct sdio_mmc_card *)adapter->card;
1088 p += sprintf(p, "\nmp_rd_bitmap=0x%x curr_rd_port=0x%x\n",
1089 sdio_card->mp_rd_bitmap, sdio_card->curr_rd_port);
1090 p += sprintf(p, "mp_wr_bitmap=0x%x curr_wr_port=0x%x\n",
1091 sdio_card->mp_wr_bitmap, sdio_card->curr_wr_port);
1092 }
1093
1094 for (i = 0; i < adapter->priv_num; i++) {
1095 if (!adapter->priv[i] || !adapter->priv[i]->netdev)
1096 continue;
1097 priv = adapter->priv[i];
1098 p += sprintf(p, "\n[interface : \"%s\"]\n",
1099 priv->netdev->name);
1100 p += sprintf(p, "wmm_tx_pending[0] = %d\n",
1101 atomic_read(&priv->wmm_tx_pending[0]));
1102 p += sprintf(p, "wmm_tx_pending[1] = %d\n",
1103 atomic_read(&priv->wmm_tx_pending[1]));
1104 p += sprintf(p, "wmm_tx_pending[2] = %d\n",
1105 atomic_read(&priv->wmm_tx_pending[2]));
1106 p += sprintf(p, "wmm_tx_pending[3] = %d\n",
1107 atomic_read(&priv->wmm_tx_pending[3]));
1108 p += sprintf(p, "media_state=\"%s\"\n", !priv->media_connected ?
1109 "Disconnected" : "Connected");
1110 p += sprintf(p, "carrier %s\n", (netif_carrier_ok(priv->netdev)
1111 ? "on" : "off"));
1112 for (idx = 0; idx < priv->netdev->num_tx_queues; idx++) {
1113 txq = netdev_get_tx_queue(priv->netdev, idx);
1114 p += sprintf(p, "tx queue %d:%s ", idx,
1115 netif_tx_queue_stopped(txq) ?
1116 "stopped" : "started");
1117 }
1118 p += sprintf(p, "\n%s: num_tx_timeout = %d\n",
1119 priv->netdev->name, priv->num_tx_timeout);
1120 }
1121
Xinming Hu46469682016-04-05 01:04:40 -07001122 if (adapter->iface_type == MWIFIEX_SDIO ||
1123 adapter->iface_type == MWIFIEX_PCIE) {
1124 p += sprintf(p, "\n=== %s register dump===\n",
1125 adapter->iface_type == MWIFIEX_SDIO ?
1126 "SDIO" : "PCIE");
Xinming Hu809c6ea2014-12-23 19:14:11 +05301127 if (adapter->if_ops.reg_dump)
1128 p += adapter->if_ops.reg_dump(adapter, p);
1129 }
Amitkumar Karwar9cc0dbf02015-05-26 06:34:30 -07001130 p += sprintf(p, "\n=== more debug information\n");
Xinming Hu11cd07a2014-12-23 19:14:10 +05301131 debug_info = kzalloc(sizeof(*debug_info), GFP_KERNEL);
1132 if (debug_info) {
1133 for (i = 0; i < adapter->priv_num; i++) {
1134 if (!adapter->priv[i] || !adapter->priv[i]->netdev)
1135 continue;
1136 priv = adapter->priv[i];
1137 mwifiex_get_debug_info(priv, debug_info);
1138 p += mwifiex_debug_info_to_buffer(priv, p, debug_info);
1139 break;
1140 }
1141 kfree(debug_info);
1142 }
1143
1144 adapter->drv_info_size = p - adapter->drv_info_dump;
Amitkumar Karwar9cc0dbf02015-05-26 06:34:30 -07001145 mwifiex_dbg(adapter, MSG, "===mwifiex driverinfo dump end===\n");
Xinming Hu11cd07a2014-12-23 19:14:10 +05301146}
Amitkumar Karwarfc697152015-05-26 06:34:31 -07001147EXPORT_SYMBOL_GPL(mwifiex_drv_info_dump);
Xinming Hu11cd07a2014-12-23 19:14:10 +05301148
Amitkumar Karwar57670ee2015-05-26 06:34:32 -07001149void mwifiex_upload_device_dump(struct mwifiex_adapter *adapter)
1150{
1151 u8 idx, *dump_data, *fw_dump_ptr;
1152 u32 dump_len;
1153
1154 dump_len = (strlen("========Start dump driverinfo========\n") +
1155 adapter->drv_info_size +
1156 strlen("\n========End dump========\n"));
1157
1158 for (idx = 0; idx < adapter->num_mem_types; idx++) {
1159 struct memory_type_mapping *entry =
1160 &adapter->mem_type_mapping_tbl[idx];
1161
1162 if (entry->mem_ptr) {
1163 dump_len += (strlen("========Start dump ") +
1164 strlen(entry->mem_name) +
1165 strlen("========\n") +
1166 (entry->mem_size + 1) +
1167 strlen("\n========End dump========\n"));
1168 }
1169 }
1170
1171 dump_data = vzalloc(dump_len + 1);
1172 if (!dump_data)
1173 goto done;
1174
1175 fw_dump_ptr = dump_data;
1176
1177 /* Dump all the memory data into single file, a userspace script will
1178 * be used to split all the memory data to multiple files
1179 */
1180 mwifiex_dbg(adapter, MSG,
1181 "== mwifiex dump information to /sys/class/devcoredump start");
1182
1183 strcpy(fw_dump_ptr, "========Start dump driverinfo========\n");
1184 fw_dump_ptr += strlen("========Start dump driverinfo========\n");
1185 memcpy(fw_dump_ptr, adapter->drv_info_dump, adapter->drv_info_size);
1186 fw_dump_ptr += adapter->drv_info_size;
1187 strcpy(fw_dump_ptr, "\n========End dump========\n");
1188 fw_dump_ptr += strlen("\n========End dump========\n");
1189
1190 for (idx = 0; idx < adapter->num_mem_types; idx++) {
1191 struct memory_type_mapping *entry =
1192 &adapter->mem_type_mapping_tbl[idx];
1193
1194 if (entry->mem_ptr) {
1195 strcpy(fw_dump_ptr, "========Start dump ");
1196 fw_dump_ptr += strlen("========Start dump ");
1197
1198 strcpy(fw_dump_ptr, entry->mem_name);
1199 fw_dump_ptr += strlen(entry->mem_name);
1200
1201 strcpy(fw_dump_ptr, "========\n");
1202 fw_dump_ptr += strlen("========\n");
1203
1204 memcpy(fw_dump_ptr, entry->mem_ptr, entry->mem_size);
1205 fw_dump_ptr += entry->mem_size;
1206
1207 strcpy(fw_dump_ptr, "\n========End dump========\n");
1208 fw_dump_ptr += strlen("\n========End dump========\n");
1209 }
1210 }
1211
1212 /* device dump data will be free in device coredump release function
1213 * after 5 min
1214 */
1215 dev_coredumpv(adapter->dev, dump_data, dump_len, GFP_KERNEL);
1216 mwifiex_dbg(adapter, MSG,
1217 "== mwifiex dump information to /sys/class/devcoredump end");
1218
1219done:
1220 for (idx = 0; idx < adapter->num_mem_types; idx++) {
1221 struct memory_type_mapping *entry =
1222 &adapter->mem_type_mapping_tbl[idx];
1223
1224 if (entry->mem_ptr) {
1225 vfree(entry->mem_ptr);
1226 entry->mem_ptr = NULL;
1227 }
1228 entry->mem_size = 0;
1229 }
1230
1231 if (adapter->drv_info_dump) {
1232 vfree(adapter->drv_info_dump);
1233 adapter->drv_info_dump = NULL;
1234 adapter->drv_info_size = 0;
1235 }
1236}
1237EXPORT_SYMBOL_GPL(mwifiex_upload_device_dump);
1238
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001239/*
1240 * CFG802.11 network device handler for statistics retrieval.
1241 */
1242static struct net_device_stats *mwifiex_get_stats(struct net_device *dev)
1243{
1244 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1245
1246 return &priv->stats;
1247}
1248
Avinash Patil47411a02012-11-01 18:44:16 -07001249static u16
Jason Wangf663dd92014-01-10 16:18:26 +08001250mwifiex_netdev_select_wmm_queue(struct net_device *dev, struct sk_buff *skb,
Daniel Borkmann99932d42014-02-16 15:55:20 +01001251 void *accel_priv, select_queue_fallback_t fallback)
Avinash Patil47411a02012-11-01 18:44:16 -07001252{
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -08001253 skb->priority = cfg80211_classify8021d(skb, NULL);
Avinash Patil47411a02012-11-01 18:44:16 -07001254 return mwifiex_1d_to_wmm_queue[skb->priority];
1255}
1256
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001257/* Network device handlers */
1258static const struct net_device_ops mwifiex_netdev_ops = {
1259 .ndo_open = mwifiex_open,
1260 .ndo_stop = mwifiex_close,
1261 .ndo_start_xmit = mwifiex_hard_start_xmit,
1262 .ndo_set_mac_address = mwifiex_set_mac_address,
Amitkumar Karwarfe243722015-10-09 04:26:34 -07001263 .ndo_validate_addr = eth_validate_addr,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001264 .ndo_tx_timeout = mwifiex_tx_timeout,
1265 .ndo_get_stats = mwifiex_get_stats,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00001266 .ndo_set_rx_mode = mwifiex_set_multicast_list,
Avinash Patil47411a02012-11-01 18:44:16 -07001267 .ndo_select_queue = mwifiex_netdev_select_wmm_queue,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001268};
1269
1270/*
1271 * This function initializes the private structure parameters.
1272 *
1273 * The following wait queues are initialized -
1274 * - IOCTL wait queue
1275 * - Command wait queue
1276 * - Statistics wait queue
1277 *
1278 * ...and the following default parameters are set -
1279 * - Current key index : Set to 0
1280 * - Rate index : Set to auto
1281 * - Media connected : Set to disconnected
1282 * - Adhoc link sensed : Set to false
1283 * - Nick name : Set to null
1284 * - Number of Tx timeout : Set to 0
1285 * - Device address : Set to current address
Xinming Hucbf6e052014-12-23 19:14:07 +05301286 * - Rx histogram statistc : Set to 0
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001287 *
1288 * In addition, the CFG80211 work queue is also created.
1289 */
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001290void mwifiex_init_priv_params(struct mwifiex_private *priv,
Avinash Patil047eaaf2015-01-28 15:42:05 +05301291 struct net_device *dev)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001292{
1293 dev->netdev_ops = &mwifiex_netdev_ops;
Amitkumar Karwarf16fdc92013-05-06 19:46:54 -07001294 dev->destructor = free_netdev;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001295 /* Initialize private structure */
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001296 priv->current_key_index = 0;
1297 priv->media_connected = false;
Avinash Patilede98bf2012-05-08 18:30:28 -07001298 memset(priv->mgmt_ie, 0,
1299 sizeof(struct mwifiex_ie) * MAX_MGMT_IE_INDEX);
Avinash Patilf31acab2012-05-08 18:30:29 -07001300 priv->beacon_idx = MWIFIEX_AUTO_IDX_MASK;
1301 priv->proberesp_idx = MWIFIEX_AUTO_IDX_MASK;
1302 priv->assocresp_idx = MWIFIEX_AUTO_IDX_MASK;
Avinash Patil2ade5662015-01-28 15:54:20 +05301303 priv->gen_idx = MWIFIEX_AUTO_IDX_MASK;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001304 priv->num_tx_timeout = 0;
Avinash Patil8d05eb22015-01-28 15:42:01 +05301305 ether_addr_copy(priv->curr_addr, priv->adapter->perm_addr);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001306 memcpy(dev->dev_addr, priv->curr_addr, ETH_ALEN);
Xinming Hucbf6e052014-12-23 19:14:07 +05301307
1308 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA ||
1309 GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
1310 priv->hist_data = kmalloc(sizeof(*priv->hist_data), GFP_KERNEL);
1311 if (priv->hist_data)
1312 mwifiex_hist_data_reset(priv);
1313 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001314}
1315
1316/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001317 * This function check if command is pending.
1318 */
1319int is_command_pending(struct mwifiex_adapter *adapter)
1320{
1321 unsigned long flags;
1322 int is_cmd_pend_q_empty;
1323
1324 spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags);
1325 is_cmd_pend_q_empty = list_empty(&adapter->cmd_pending_q);
1326 spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, flags);
1327
1328 return !is_cmd_pend_q_empty;
1329}
1330
1331/*
Avinash Patil6e251172014-09-12 20:08:59 +05301332 * This is the RX work queue function.
1333 *
1334 * It handles the RX operations.
1335 */
1336static void mwifiex_rx_work_queue(struct work_struct *work)
1337{
1338 struct mwifiex_adapter *adapter =
1339 container_of(work, struct mwifiex_adapter, rx_work);
1340
1341 if (adapter->surprise_removed)
1342 return;
1343 mwifiex_process_rx(adapter);
1344}
1345
1346/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001347 * This is the main work queue function.
1348 *
1349 * It handles the main process, which in turn handles the complete
1350 * driver operations.
1351 */
1352static void mwifiex_main_work_queue(struct work_struct *work)
1353{
1354 struct mwifiex_adapter *adapter =
1355 container_of(work, struct mwifiex_adapter, main_work);
1356
1357 if (adapter->surprise_removed)
1358 return;
1359 mwifiex_main_process(adapter);
1360}
1361
1362/*
Amitkumar Karwar4c5dae52016-07-26 19:31:44 +05301363 * This function gets called during PCIe function level reset. Required
1364 * code is extracted from mwifiex_remove_card()
1365 */
1366static int
1367mwifiex_shutdown_sw(struct mwifiex_adapter *adapter, struct semaphore *sem)
1368{
1369 struct mwifiex_private *priv;
1370 int i;
1371
Colin Ian King80ba4f12016-09-16 10:37:31 +01001372 if (!adapter)
1373 goto exit_return;
1374
Amitkumar Karwar4c5dae52016-07-26 19:31:44 +05301375 if (down_interruptible(sem))
1376 goto exit_sem_err;
1377
Amitkumar Karwar4c5dae52016-07-26 19:31:44 +05301378 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
1379 mwifiex_deauthenticate(priv, NULL);
1380
1381 /* We can no longer handle interrupts once we start doing the teardown
1382 * below.
1383 */
1384 if (adapter->if_ops.disable_int)
1385 adapter->if_ops.disable_int(adapter);
1386
1387 adapter->surprise_removed = true;
1388 mwifiex_terminate_workqueue(adapter);
1389
1390 /* Stop data */
1391 for (i = 0; i < adapter->priv_num; i++) {
1392 priv = adapter->priv[i];
1393 if (priv && priv->netdev) {
1394 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
1395 if (netif_carrier_ok(priv->netdev))
1396 netif_carrier_off(priv->netdev);
1397 netif_device_detach(priv->netdev);
1398 }
1399 }
1400
1401 mwifiex_dbg(adapter, CMD, "cmd: calling mwifiex_shutdown_drv...\n");
1402 adapter->init_wait_q_woken = false;
1403
1404 if (mwifiex_shutdown_drv(adapter) == -EINPROGRESS)
1405 wait_event_interruptible(adapter->init_wait_q,
1406 adapter->init_wait_q_woken);
1407 if (adapter->if_ops.down_dev)
1408 adapter->if_ops.down_dev(adapter);
1409
1410 mwifiex_dbg(adapter, CMD, "cmd: mwifiex_shutdown_drv done\n");
1411 if (atomic_read(&adapter->rx_pending) ||
1412 atomic_read(&adapter->tx_pending) ||
1413 atomic_read(&adapter->cmd_pending)) {
1414 mwifiex_dbg(adapter, ERROR,
1415 "rx_pending=%d, tx_pending=%d,\t"
1416 "cmd_pending=%d\n",
1417 atomic_read(&adapter->rx_pending),
1418 atomic_read(&adapter->tx_pending),
1419 atomic_read(&adapter->cmd_pending));
1420 }
1421
1422 for (i = 0; i < adapter->priv_num; i++) {
1423 priv = adapter->priv[i];
1424 if (!priv)
1425 continue;
1426 rtnl_lock();
1427 if (priv->netdev &&
1428 priv->wdev.iftype != NL80211_IFTYPE_UNSPECIFIED)
1429 mwifiex_del_virtual_intf(adapter->wiphy, &priv->wdev);
1430 rtnl_unlock();
1431 }
1432
Amitkumar Karwar4c5dae52016-07-26 19:31:44 +05301433 up(sem);
1434exit_sem_err:
1435 mwifiex_dbg(adapter, INFO, "%s, successful\n", __func__);
Colin Ian King80ba4f12016-09-16 10:37:31 +01001436exit_return:
Amitkumar Karwar4c5dae52016-07-26 19:31:44 +05301437 return 0;
1438}
1439
1440/* This function gets called during PCIe function level reset. Required
1441 * code is extracted from mwifiex_add_card()
1442 */
1443static int
1444mwifiex_reinit_sw(struct mwifiex_adapter *adapter, struct semaphore *sem,
1445 struct mwifiex_if_ops *if_ops, u8 iface_type)
1446{
1447 char fw_name[32];
1448 struct pcie_service_card *card = adapter->card;
1449
1450 if (down_interruptible(sem))
1451 goto exit_sem_err;
1452
1453 mwifiex_init_lock_list(adapter);
1454 if (adapter->if_ops.up_dev)
1455 adapter->if_ops.up_dev(adapter);
1456
1457 adapter->iface_type = iface_type;
1458 adapter->card_sem = sem;
1459
1460 adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING;
1461 adapter->surprise_removed = false;
1462 init_waitqueue_head(&adapter->init_wait_q);
1463 adapter->is_suspended = false;
1464 adapter->hs_activated = false;
1465 init_waitqueue_head(&adapter->hs_activate_wait_q);
1466 init_waitqueue_head(&adapter->cmd_wait_q.wait);
1467 adapter->cmd_wait_q.status = 0;
1468 adapter->scan_wait_q_woken = false;
1469
1470 if ((num_possible_cpus() > 1) || adapter->iface_type == MWIFIEX_USB)
1471 adapter->rx_work_enabled = true;
1472
1473 adapter->workqueue =
1474 alloc_workqueue("MWIFIEX_WORK_QUEUE",
1475 WQ_HIGHPRI | WQ_MEM_RECLAIM | WQ_UNBOUND, 1);
1476 if (!adapter->workqueue)
1477 goto err_kmalloc;
1478
1479 INIT_WORK(&adapter->main_work, mwifiex_main_work_queue);
1480
1481 if (adapter->rx_work_enabled) {
1482 adapter->rx_workqueue = alloc_workqueue("MWIFIEX_RX_WORK_QUEUE",
1483 WQ_HIGHPRI |
1484 WQ_MEM_RECLAIM |
1485 WQ_UNBOUND, 1);
1486 if (!adapter->rx_workqueue)
1487 goto err_kmalloc;
1488 INIT_WORK(&adapter->rx_work, mwifiex_rx_work_queue);
1489 }
1490
1491 /* Register the device. Fill up the private data structure with
1492 * relevant information from the card. Some code extracted from
1493 * mwifiex_register_dev()
1494 */
1495 mwifiex_dbg(adapter, INFO, "%s, mwifiex_init_hw_fw()...\n", __func__);
1496 strcpy(fw_name, adapter->fw_name);
1497 strcpy(adapter->fw_name, PCIE8997_DEFAULT_WIFIFW_NAME);
1498
1499 adapter->tx_buf_size = card->pcie.tx_buf_size;
1500 adapter->ext_scan = card->pcie.can_ext_scan;
1501 if (mwifiex_init_hw_fw(adapter, false)) {
1502 strcpy(adapter->fw_name, fw_name);
1503 mwifiex_dbg(adapter, ERROR,
1504 "%s: firmware init failed\n", __func__);
1505 goto err_init_fw;
1506 }
1507 strcpy(adapter->fw_name, fw_name);
1508 mwifiex_dbg(adapter, INFO, "%s, successful\n", __func__);
1509 up(sem);
1510 return 0;
1511
1512err_init_fw:
1513 mwifiex_dbg(adapter, ERROR, "info: %s: unregister device\n", __func__);
1514 if (adapter->if_ops.unregister_dev)
1515 adapter->if_ops.unregister_dev(adapter);
1516 if (adapter->hw_status == MWIFIEX_HW_STATUS_READY) {
1517 mwifiex_dbg(adapter, ERROR,
1518 "info: %s: shutdown mwifiex\n", __func__);
1519 adapter->init_wait_q_woken = false;
1520
1521 if (mwifiex_shutdown_drv(adapter) == -EINPROGRESS)
1522 wait_event_interruptible(adapter->init_wait_q,
1523 adapter->init_wait_q_woken);
1524 }
1525
1526err_kmalloc:
1527 mwifiex_terminate_workqueue(adapter);
1528 adapter->surprise_removed = true;
1529 up(sem);
1530exit_sem_err:
1531 mwifiex_dbg(adapter, INFO, "%s, error\n", __func__);
1532
1533 return -1;
1534}
1535
1536/* This function processes pre and post PCIe function level resets.
1537 * It performs software cleanup without touching PCIe specific code.
1538 * Also, during initialization PCIe stuff is skipped.
1539 */
1540void mwifiex_do_flr(struct mwifiex_adapter *adapter, bool prepare)
1541{
1542 struct mwifiex_if_ops if_ops;
1543
1544 if (!prepare) {
1545 mwifiex_reinit_sw(adapter, adapter->card_sem, &if_ops,
1546 adapter->iface_type);
1547 } else {
1548 memcpy(&if_ops, &adapter->if_ops,
1549 sizeof(struct mwifiex_if_ops));
1550 mwifiex_shutdown_sw(adapter, adapter->card_sem);
1551 }
1552}
1553EXPORT_SYMBOL_GPL(mwifiex_do_flr);
1554
1555/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001556 * This function adds the card.
1557 *
1558 * This function follows the following major steps to set up the device -
1559 * - Initialize software. This includes probing the card, registering
1560 * the interface operations table, and allocating/initializing the
1561 * adapter structure
1562 * - Set up the netlink socket
1563 * - Create and start the main work queue
1564 * - Register the device
1565 * - Initialize firmware and hardware
1566 * - Add logical interfaces
1567 */
1568int
1569mwifiex_add_card(void *card, struct semaphore *sem,
Amitkumar Karward930fae2011-10-11 17:41:21 -07001570 struct mwifiex_if_ops *if_ops, u8 iface_type)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001571{
Amitkumar Karwar2be78592011-04-15 20:50:42 -07001572 struct mwifiex_adapter *adapter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001573
1574 if (down_interruptible(sem))
1575 goto exit_sem_err;
1576
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001577 if (mwifiex_register(card, if_ops, (void **)&adapter)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001578 pr_err("%s: software init failed\n", __func__);
1579 goto err_init_sw;
1580 }
1581
Amitkumar Karward930fae2011-10-11 17:41:21 -07001582 adapter->iface_type = iface_type;
Amitkumar Karwar6b41f942013-07-22 19:17:55 -07001583 adapter->card_sem = sem;
Amitkumar Karward930fae2011-10-11 17:41:21 -07001584
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001585 adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001586 adapter->surprise_removed = false;
1587 init_waitqueue_head(&adapter->init_wait_q);
1588 adapter->is_suspended = false;
1589 adapter->hs_activated = false;
1590 init_waitqueue_head(&adapter->hs_activate_wait_q);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001591 init_waitqueue_head(&adapter->cmd_wait_q.wait);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001592 adapter->cmd_wait_q.status = 0;
Amitkumar Karwarefaaa8b2011-10-12 20:28:06 -07001593 adapter->scan_wait_q_woken = false;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001594
Avinash Patilec4a16b2014-11-05 17:04:27 +05301595 if ((num_possible_cpus() > 1) || adapter->iface_type == MWIFIEX_USB) {
Avinash Patil6e251172014-09-12 20:08:59 +05301596 adapter->rx_work_enabled = true;
1597 pr_notice("rx work enabled, cpus %d\n", num_possible_cpus());
1598 }
1599
Amitkumar Karwar448a71c2013-10-11 18:33:04 -07001600 adapter->workqueue =
1601 alloc_workqueue("MWIFIEX_WORK_QUEUE",
1602 WQ_HIGHPRI | WQ_MEM_RECLAIM | WQ_UNBOUND, 1);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001603 if (!adapter->workqueue)
1604 goto err_kmalloc;
1605
1606 INIT_WORK(&adapter->main_work, mwifiex_main_work_queue);
Avinash Patil6e251172014-09-12 20:08:59 +05301607
1608 if (adapter->rx_work_enabled) {
1609 adapter->rx_workqueue = alloc_workqueue("MWIFIEX_RX_WORK_QUEUE",
1610 WQ_HIGHPRI |
1611 WQ_MEM_RECLAIM |
1612 WQ_UNBOUND, 1);
1613 if (!adapter->rx_workqueue)
1614 goto err_kmalloc;
1615
1616 INIT_WORK(&adapter->rx_work, mwifiex_rx_work_queue);
1617 }
1618
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001619 /* Register the device. Fill up the private data structure with relevant
Daniel Drake232fde02013-07-13 10:57:10 -04001620 information from the card. */
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001621 if (adapter->if_ops.register_dev(adapter)) {
1622 pr_err("%s: failed to register mwifiex device\n", __func__);
1623 goto err_registerdev;
1624 }
1625
Amitkumar Karwar4c5dae52016-07-26 19:31:44 +05301626 if (mwifiex_init_hw_fw(adapter, true)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001627 pr_err("%s: firmware init failed\n", __func__);
1628 goto err_init_fw;
1629 }
Amitkumar Karwar2be78592011-04-15 20:50:42 -07001630
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001631 return 0;
1632
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001633err_init_fw:
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001634 pr_debug("info: %s: unregister device\n", __func__);
Amitkumar Karwar4daffe32012-04-18 20:08:28 -07001635 if (adapter->if_ops.unregister_dev)
1636 adapter->if_ops.unregister_dev(adapter);
Amitkumar Karwar71973252014-12-31 02:36:38 -08001637 if (adapter->hw_status == MWIFIEX_HW_STATUS_READY) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001638 pr_debug("info: %s: shutdown mwifiex\n", __func__);
1639 adapter->init_wait_q_woken = false;
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001640
1641 if (mwifiex_shutdown_drv(adapter) == -EINPROGRESS)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001642 wait_event_interruptible(adapter->init_wait_q,
1643 adapter->init_wait_q_woken);
1644 }
Amitkumar Karwar6b41f942013-07-22 19:17:55 -07001645err_registerdev:
1646 adapter->surprise_removed = true;
1647 mwifiex_terminate_workqueue(adapter);
1648err_kmalloc:
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001649 mwifiex_free_adapter(adapter);
1650
1651err_init_sw:
1652 up(sem);
1653
1654exit_sem_err:
1655 return -1;
1656}
1657EXPORT_SYMBOL_GPL(mwifiex_add_card);
1658
1659/*
1660 * This function removes the card.
1661 *
1662 * This function follows the following major steps to remove the device -
1663 * - Stop data traffic
1664 * - Shutdown firmware
1665 * - Remove the logical interfaces
1666 * - Terminate the work queue
1667 * - Unregister the device
1668 * - Free the adapter structure
1669 */
1670int mwifiex_remove_card(struct mwifiex_adapter *adapter, struct semaphore *sem)
1671{
1672 struct mwifiex_private *priv = NULL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001673 int i;
1674
Xinming Huc3ec0ff2016-04-11 07:52:40 -07001675 if (down_trylock(sem))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001676 goto exit_sem_err;
1677
1678 if (!adapter)
1679 goto exit_remove;
1680
Daniel Drake232fde02013-07-13 10:57:10 -04001681 /* We can no longer handle interrupts once we start doing the teardown
1682 * below. */
1683 if (adapter->if_ops.disable_int)
1684 adapter->if_ops.disable_int(adapter);
1685
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001686 adapter->surprise_removed = true;
1687
Marc Yang9d2e85e2014-12-31 02:36:39 -08001688 mwifiex_terminate_workqueue(adapter);
1689
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001690 /* Stop data */
1691 for (i = 0; i < adapter->priv_num; i++) {
1692 priv = adapter->priv[i];
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001693 if (priv && priv->netdev) {
Avinash Patil47411a02012-11-01 18:44:16 -07001694 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001695 if (netif_carrier_ok(priv->netdev))
1696 netif_carrier_off(priv->netdev);
1697 }
1698 }
1699
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301700 mwifiex_dbg(adapter, CMD,
1701 "cmd: calling mwifiex_shutdown_drv...\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001702 adapter->init_wait_q_woken = false;
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001703
1704 if (mwifiex_shutdown_drv(adapter) == -EINPROGRESS)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001705 wait_event_interruptible(adapter->init_wait_q,
1706 adapter->init_wait_q_woken);
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301707 mwifiex_dbg(adapter, CMD,
1708 "cmd: mwifiex_shutdown_drv done\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001709 if (atomic_read(&adapter->rx_pending) ||
1710 atomic_read(&adapter->tx_pending) ||
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001711 atomic_read(&adapter->cmd_pending)) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301712 mwifiex_dbg(adapter, ERROR,
1713 "rx_pending=%d, tx_pending=%d,\t"
1714 "cmd_pending=%d\n",
1715 atomic_read(&adapter->rx_pending),
1716 atomic_read(&adapter->tx_pending),
1717 atomic_read(&adapter->cmd_pending));
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001718 }
1719
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001720 for (i = 0; i < adapter->priv_num; i++) {
1721 priv = adapter->priv[i];
1722
1723 if (!priv)
1724 continue;
1725
1726 rtnl_lock();
Avinash Patil4facc342015-01-28 15:42:00 +05301727 if (priv->netdev &&
1728 priv->wdev.iftype != NL80211_IFTYPE_UNSPECIFIED)
1729 mwifiex_del_virtual_intf(adapter->wiphy, &priv->wdev);
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001730 rtnl_unlock();
1731 }
1732
Amitkumar Karwarc2868ad2013-12-02 23:17:57 -08001733 wiphy_unregister(adapter->wiphy);
1734 wiphy_free(adapter->wiphy);
Avinash Patil64b05e22012-05-08 18:30:13 -07001735
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001736 /* Unregister device */
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301737 mwifiex_dbg(adapter, INFO,
1738 "info: unregister device\n");
Amitkumar Karwar4daffe32012-04-18 20:08:28 -07001739 if (adapter->if_ops.unregister_dev)
1740 adapter->if_ops.unregister_dev(adapter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001741 /* Free adapter structure */
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301742 mwifiex_dbg(adapter, INFO,
1743 "info: free adapter\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001744 mwifiex_free_adapter(adapter);
1745
1746exit_remove:
1747 up(sem);
1748exit_sem_err:
1749 return 0;
1750}
1751EXPORT_SYMBOL_GPL(mwifiex_remove_card);
1752
Joe Perches36925e52015-08-31 10:46:45 -07001753void _mwifiex_dbg(const struct mwifiex_adapter *adapter, int mask,
1754 const char *fmt, ...)
1755{
1756 struct va_format vaf;
1757 va_list args;
1758
1759 if (!adapter->dev || !(adapter->debug_mask & mask))
1760 return;
1761
1762 va_start(args, fmt);
1763
1764 vaf.fmt = fmt;
1765 vaf.va = &args;
1766
1767 dev_info(adapter->dev, "%pV", &vaf);
1768
1769 va_end(args);
1770}
1771EXPORT_SYMBOL_GPL(_mwifiex_dbg);
1772
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001773/*
1774 * This function initializes the module.
1775 *
1776 * The debug FS is also initialized if configured.
1777 */
1778static int
1779mwifiex_init_module(void)
1780{
1781#ifdef CONFIG_DEBUG_FS
1782 mwifiex_debugfs_init();
1783#endif
1784 return 0;
1785}
1786
1787/*
1788 * This function cleans up the module.
1789 *
1790 * The debug FS is removed if available.
1791 */
1792static void
1793mwifiex_cleanup_module(void)
1794{
1795#ifdef CONFIG_DEBUG_FS
1796 mwifiex_debugfs_remove();
1797#endif
1798}
1799
1800module_init(mwifiex_init_module);
1801module_exit(mwifiex_cleanup_module);
1802
1803MODULE_AUTHOR("Marvell International Ltd.");
1804MODULE_DESCRIPTION("Marvell WiFi-Ex Driver version " VERSION);
1805MODULE_VERSION(VERSION);
1806MODULE_LICENSE("GPL v2");