2 * Marvell Wireless LAN device driver: major functions
4 * Copyright (C) 2011-2014, Marvell International Ltd.
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.
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.
20 #include <linux/suspend.h>
28 #define MFG_FIRMWARE "mwifiex_mfg.bin"
30 static unsigned int debug_mask
= MWIFIEX_DEFAULT_DEBUG_MASK
;
31 module_param(debug_mask
, uint
, 0);
32 MODULE_PARM_DESC(debug_mask
, "bitmap for debug flags");
34 const char driver_version
[] = "mwifiex " VERSION
" (%s) ";
35 static char *cal_data_cfg
;
36 module_param(cal_data_cfg
, charp
, 0);
38 static unsigned short driver_mode
;
39 module_param(driver_mode
, ushort
, 0);
40 MODULE_PARM_DESC(driver_mode
,
41 "station=0x1(default), ap-sta=0x3, station-p2p=0x5, ap-sta-p2p=0x7");
44 module_param(mfg_mode
, bool, 0);
45 MODULE_PARM_DESC(mfg_mode
, "manufacturing mode enable:1, disable:0");
48 module_param(aggr_ctrl
, bool, 0000);
49 MODULE_PARM_DESC(aggr_ctrl
, "usb tx aggreataon enable:1, disable:0");
52 * This function registers the device and performs all the necessary
55 * The following initialization operations are performed -
56 * - Allocate adapter structure
57 * - Save interface specific operations table in adapter
58 * - Call interface specific initialization routine
59 * - Allocate private structures
60 * - Set default adapter structure parameters
63 * In case of any errors during inittialization, this function also ensures
64 * proper cleanup before exiting.
66 static int mwifiex_register(void *card
, struct device
*dev
,
67 struct mwifiex_if_ops
*if_ops
, void **padapter
)
69 struct mwifiex_adapter
*adapter
;
72 adapter
= kzalloc(sizeof(struct mwifiex_adapter
), GFP_KERNEL
);
80 /* Save interface specific operations in adapter */
81 memmove(&adapter
->if_ops
, if_ops
, sizeof(struct mwifiex_if_ops
));
82 adapter
->debug_mask
= debug_mask
;
84 /* card specific initialization has been deferred until now .. */
85 if (adapter
->if_ops
.init_if
)
86 if (adapter
->if_ops
.init_if(adapter
))
89 adapter
->priv_num
= 0;
91 for (i
= 0; i
< MWIFIEX_MAX_BSS_NUM
; i
++) {
92 /* Allocate memory for private structure */
94 kzalloc(sizeof(struct mwifiex_private
), GFP_KERNEL
);
95 if (!adapter
->priv
[i
])
98 adapter
->priv
[i
]->adapter
= adapter
;
101 mwifiex_init_lock_list(adapter
);
103 setup_timer(&adapter
->cmd_timer
, mwifiex_cmd_timeout_func
,
104 (unsigned long)adapter
);
109 mwifiex_dbg(adapter
, ERROR
,
110 "info: leave mwifiex_register with error\n");
112 for (i
= 0; i
< adapter
->priv_num
; i
++)
113 kfree(adapter
->priv
[i
]);
121 * This function unregisters the device and performs all the necessary
124 * The following cleanup operations are performed -
126 * - Free beacon buffers
127 * - Free private structures
128 * - Free adapter structure
130 static int mwifiex_unregister(struct mwifiex_adapter
*adapter
)
134 if (adapter
->if_ops
.cleanup_if
)
135 adapter
->if_ops
.cleanup_if(adapter
);
137 del_timer_sync(&adapter
->cmd_timer
);
139 /* Free private structures */
140 for (i
= 0; i
< adapter
->priv_num
; i
++) {
141 if (adapter
->priv
[i
]) {
142 mwifiex_free_curr_bcn(adapter
->priv
[i
]);
143 kfree(adapter
->priv
[i
]);
147 if (adapter
->nd_info
) {
148 for (i
= 0 ; i
< adapter
->nd_info
->n_matches
; i
++)
149 kfree(adapter
->nd_info
->matches
[i
]);
150 kfree(adapter
->nd_info
);
151 adapter
->nd_info
= NULL
;
154 kfree(adapter
->regd
);
160 void mwifiex_queue_main_work(struct mwifiex_adapter
*adapter
)
164 spin_lock_irqsave(&adapter
->main_proc_lock
, flags
);
165 if (adapter
->mwifiex_processing
) {
166 adapter
->more_task_flag
= true;
167 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
169 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
170 queue_work(adapter
->workqueue
, &adapter
->main_work
);
173 EXPORT_SYMBOL_GPL(mwifiex_queue_main_work
);
175 static void mwifiex_queue_rx_work(struct mwifiex_adapter
*adapter
)
179 spin_lock_irqsave(&adapter
->rx_proc_lock
, flags
);
180 if (adapter
->rx_processing
) {
181 spin_unlock_irqrestore(&adapter
->rx_proc_lock
, flags
);
183 spin_unlock_irqrestore(&adapter
->rx_proc_lock
, flags
);
184 queue_work(adapter
->rx_workqueue
, &adapter
->rx_work
);
188 static int mwifiex_process_rx(struct mwifiex_adapter
*adapter
)
192 struct mwifiex_rxinfo
*rx_info
;
194 spin_lock_irqsave(&adapter
->rx_proc_lock
, flags
);
195 if (adapter
->rx_processing
|| adapter
->rx_locked
) {
196 spin_unlock_irqrestore(&adapter
->rx_proc_lock
, flags
);
199 adapter
->rx_processing
= true;
200 spin_unlock_irqrestore(&adapter
->rx_proc_lock
, flags
);
203 /* Check for Rx data */
204 while ((skb
= skb_dequeue(&adapter
->rx_data_q
))) {
205 atomic_dec(&adapter
->rx_pending
);
206 if ((adapter
->delay_main_work
||
207 adapter
->iface_type
== MWIFIEX_USB
) &&
208 (atomic_read(&adapter
->rx_pending
) < LOW_RX_PENDING
)) {
209 if (adapter
->if_ops
.submit_rem_rx_urbs
)
210 adapter
->if_ops
.submit_rem_rx_urbs(adapter
);
211 adapter
->delay_main_work
= false;
212 mwifiex_queue_main_work(adapter
);
214 rx_info
= MWIFIEX_SKB_RXCB(skb
);
215 if (rx_info
->buf_type
== MWIFIEX_TYPE_AGGR_DATA
) {
216 if (adapter
->if_ops
.deaggr_pkt
)
217 adapter
->if_ops
.deaggr_pkt(adapter
, skb
);
218 dev_kfree_skb_any(skb
);
220 mwifiex_handle_rx_packet(adapter
, skb
);
223 spin_lock_irqsave(&adapter
->rx_proc_lock
, flags
);
224 adapter
->rx_processing
= false;
225 spin_unlock_irqrestore(&adapter
->rx_proc_lock
, flags
);
234 * This function is the main procedure of the driver and handles various driver
235 * operations. It runs in a loop and provides the core functionalities.
237 * The main responsibilities of this function are -
238 * - Ensure concurrency control
239 * - Handle pending interrupts and call interrupt handlers
240 * - Wake up the card if required
241 * - Handle command responses and call response handlers
242 * - Handle events and call event handlers
243 * - Execute pending commands
244 * - Transmit pending data packets
246 int mwifiex_main_process(struct mwifiex_adapter
*adapter
)
251 spin_lock_irqsave(&adapter
->main_proc_lock
, flags
);
253 /* Check if already processing */
254 if (adapter
->mwifiex_processing
|| adapter
->main_locked
) {
255 adapter
->more_task_flag
= true;
256 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
259 adapter
->mwifiex_processing
= true;
260 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
264 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_NOT_READY
)
267 /* For non-USB interfaces, If we process interrupts first, it
268 * would increase RX pending even further. Avoid this by
269 * checking if rx_pending has crossed high threshold and
270 * schedule rx work queue and then process interrupts.
271 * For USB interface, there are no interrupts. We already have
272 * HIGH_RX_PENDING check in usb.c
274 if (atomic_read(&adapter
->rx_pending
) >= HIGH_RX_PENDING
&&
275 adapter
->iface_type
!= MWIFIEX_USB
) {
276 adapter
->delay_main_work
= true;
277 mwifiex_queue_rx_work(adapter
);
281 /* Handle pending interrupt if any */
282 if (adapter
->int_status
) {
283 if (adapter
->hs_activated
)
284 mwifiex_process_hs_config(adapter
);
285 if (adapter
->if_ops
.process_int_status
)
286 adapter
->if_ops
.process_int_status(adapter
);
289 if (adapter
->rx_work_enabled
&& adapter
->data_received
)
290 mwifiex_queue_rx_work(adapter
);
292 /* Need to wake up the card ? */
293 if ((adapter
->ps_state
== PS_STATE_SLEEP
) &&
294 (adapter
->pm_wakeup_card_req
&&
295 !adapter
->pm_wakeup_fw_try
) &&
296 (is_command_pending(adapter
) ||
297 !skb_queue_empty(&adapter
->tx_data_q
) ||
298 !mwifiex_bypass_txlist_empty(adapter
) ||
299 !mwifiex_wmm_lists_empty(adapter
))) {
300 adapter
->pm_wakeup_fw_try
= true;
301 mod_timer(&adapter
->wakeup_timer
, jiffies
+ (HZ
*3));
302 adapter
->if_ops
.wakeup(adapter
);
306 if (IS_CARD_RX_RCVD(adapter
)) {
307 adapter
->data_received
= false;
308 adapter
->pm_wakeup_fw_try
= false;
309 del_timer(&adapter
->wakeup_timer
);
310 if (adapter
->ps_state
== PS_STATE_SLEEP
)
311 adapter
->ps_state
= PS_STATE_AWAKE
;
313 /* We have tried to wakeup the card already */
314 if (adapter
->pm_wakeup_fw_try
)
316 if (adapter
->ps_state
== PS_STATE_PRE_SLEEP
)
317 mwifiex_check_ps_cond(adapter
);
319 if (adapter
->ps_state
!= PS_STATE_AWAKE
)
321 if (adapter
->tx_lock_flag
) {
322 if (adapter
->iface_type
== MWIFIEX_USB
) {
323 if (!adapter
->usb_mc_setup
)
329 if ((!adapter
->scan_chan_gap_enabled
&&
330 adapter
->scan_processing
) || adapter
->data_sent
||
331 mwifiex_is_tdls_chan_switching
332 (mwifiex_get_priv(adapter
,
333 MWIFIEX_BSS_ROLE_STA
)) ||
334 (mwifiex_wmm_lists_empty(adapter
) &&
335 mwifiex_bypass_txlist_empty(adapter
) &&
336 skb_queue_empty(&adapter
->tx_data_q
))) {
337 if (adapter
->cmd_sent
|| adapter
->curr_cmd
||
338 !mwifiex_is_send_cmd_allowed
339 (mwifiex_get_priv(adapter
,
340 MWIFIEX_BSS_ROLE_STA
)) ||
341 (!is_command_pending(adapter
)))
346 /* Check for event */
347 if (adapter
->event_received
) {
348 adapter
->event_received
= false;
349 mwifiex_process_event(adapter
);
352 /* Check for Cmd Resp */
353 if (adapter
->cmd_resp_received
) {
354 adapter
->cmd_resp_received
= false;
355 mwifiex_process_cmdresp(adapter
);
357 /* call mwifiex back when init_fw is done */
358 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_INIT_DONE
) {
359 adapter
->hw_status
= MWIFIEX_HW_STATUS_READY
;
360 mwifiex_init_fw_complete(adapter
);
364 /* Check if we need to confirm Sleep Request
365 received previously */
366 if (adapter
->ps_state
== PS_STATE_PRE_SLEEP
)
367 mwifiex_check_ps_cond(adapter
);
369 /* * The ps_state may have been changed during processing of
370 * Sleep Request event.
372 if ((adapter
->ps_state
== PS_STATE_SLEEP
) ||
373 (adapter
->ps_state
== PS_STATE_PRE_SLEEP
) ||
374 (adapter
->ps_state
== PS_STATE_SLEEP_CFM
)) {
378 if (adapter
->tx_lock_flag
) {
379 if (adapter
->iface_type
== MWIFIEX_USB
) {
380 if (!adapter
->usb_mc_setup
)
386 if (!adapter
->cmd_sent
&& !adapter
->curr_cmd
&&
387 mwifiex_is_send_cmd_allowed
388 (mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_STA
))) {
389 if (mwifiex_exec_next_cmd(adapter
) == -1) {
395 /** If USB Multi channel setup ongoing,
396 * wait for ready to tx data.
398 if (adapter
->iface_type
== MWIFIEX_USB
&&
399 adapter
->usb_mc_setup
)
402 if ((adapter
->scan_chan_gap_enabled
||
403 !adapter
->scan_processing
) &&
404 !adapter
->data_sent
&&
405 !skb_queue_empty(&adapter
->tx_data_q
)) {
406 mwifiex_process_tx_queue(adapter
);
407 if (adapter
->hs_activated
) {
408 adapter
->is_hs_configured
= false;
409 mwifiex_hs_activated_event
411 (adapter
, MWIFIEX_BSS_ROLE_ANY
),
416 if ((adapter
->scan_chan_gap_enabled
||
417 !adapter
->scan_processing
) &&
418 !adapter
->data_sent
&&
419 !mwifiex_bypass_txlist_empty(adapter
) &&
420 !mwifiex_is_tdls_chan_switching
421 (mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_STA
))) {
422 mwifiex_process_bypass_tx(adapter
);
423 if (adapter
->hs_activated
) {
424 adapter
->is_hs_configured
= false;
425 mwifiex_hs_activated_event
427 (adapter
, MWIFIEX_BSS_ROLE_ANY
),
432 if ((adapter
->scan_chan_gap_enabled
||
433 !adapter
->scan_processing
) &&
434 !adapter
->data_sent
&& !mwifiex_wmm_lists_empty(adapter
) &&
435 !mwifiex_is_tdls_chan_switching
436 (mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_STA
))) {
437 mwifiex_wmm_process_tx(adapter
);
438 if (adapter
->hs_activated
) {
439 adapter
->is_hs_configured
= false;
440 mwifiex_hs_activated_event
442 (adapter
, MWIFIEX_BSS_ROLE_ANY
),
447 if (adapter
->delay_null_pkt
&& !adapter
->cmd_sent
&&
448 !adapter
->curr_cmd
&& !is_command_pending(adapter
) &&
449 (mwifiex_wmm_lists_empty(adapter
) &&
450 mwifiex_bypass_txlist_empty(adapter
) &&
451 skb_queue_empty(&adapter
->tx_data_q
))) {
452 if (!mwifiex_send_null_packet
453 (mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_STA
),
454 MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET
|
455 MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET
)) {
456 adapter
->delay_null_pkt
= false;
457 adapter
->ps_state
= PS_STATE_SLEEP
;
463 spin_lock_irqsave(&adapter
->main_proc_lock
, flags
);
464 if (adapter
->more_task_flag
) {
465 adapter
->more_task_flag
= false;
466 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
469 adapter
->mwifiex_processing
= false;
470 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
474 EXPORT_SYMBOL_GPL(mwifiex_main_process
);
477 * This function frees the adapter structure.
479 * Additionally, this closes the netlink socket, frees the timers
480 * and private structures.
482 static void mwifiex_free_adapter(struct mwifiex_adapter
*adapter
)
485 pr_err("%s: adapter is NULL\n", __func__
);
489 mwifiex_unregister(adapter
);
490 pr_debug("info: %s: free adapter\n", __func__
);
494 * This function cancels all works in the queue and destroys
495 * the main workqueue.
497 static void mwifiex_terminate_workqueue(struct mwifiex_adapter
*adapter
)
499 if (adapter
->workqueue
) {
500 flush_workqueue(adapter
->workqueue
);
501 destroy_workqueue(adapter
->workqueue
);
502 adapter
->workqueue
= NULL
;
505 if (adapter
->rx_workqueue
) {
506 flush_workqueue(adapter
->rx_workqueue
);
507 destroy_workqueue(adapter
->rx_workqueue
);
508 adapter
->rx_workqueue
= NULL
;
513 * This function gets firmware and initializes it.
515 * The main initialization steps followed are -
516 * - Download the correct firmware to card
517 * - Issue the init commands to firmware
519 static int _mwifiex_fw_dpc(const struct firmware
*firmware
, void *context
)
523 struct mwifiex_adapter
*adapter
= context
;
524 struct mwifiex_fw_image fw
;
525 bool init_failed
= false;
526 struct wireless_dev
*wdev
;
527 struct completion
*fw_done
= adapter
->fw_done
;
530 mwifiex_dbg(adapter
, ERROR
,
531 "Failed to get firmware %s\n", adapter
->fw_name
);
535 memset(&fw
, 0, sizeof(struct mwifiex_fw_image
));
536 adapter
->firmware
= firmware
;
537 fw
.fw_buf
= (u8
*) adapter
->firmware
->data
;
538 fw
.fw_len
= adapter
->firmware
->size
;
540 if (adapter
->if_ops
.dnld_fw
) {
541 ret
= adapter
->if_ops
.dnld_fw(adapter
, &fw
);
543 ret
= mwifiex_dnld_fw(adapter
, &fw
);
549 mwifiex_dbg(adapter
, MSG
, "WLAN FW is active\n");
552 if ((request_firmware(&adapter
->cal_data
, cal_data_cfg
,
554 mwifiex_dbg(adapter
, ERROR
,
555 "Cal data request_firmware() failed\n");
558 /* enable host interrupt after fw dnld is successful */
559 if (adapter
->if_ops
.enable_int
) {
560 if (adapter
->if_ops
.enable_int(adapter
))
564 adapter
->init_wait_q_woken
= false;
565 ret
= mwifiex_init_fw(adapter
);
569 adapter
->hw_status
= MWIFIEX_HW_STATUS_READY
;
572 /* Wait for mwifiex_init to complete */
573 if (!adapter
->mfg_mode
) {
574 wait_event_interruptible(adapter
->init_wait_q
,
575 adapter
->init_wait_q_woken
);
576 if (adapter
->hw_status
!= MWIFIEX_HW_STATUS_READY
)
580 if (!adapter
->wiphy
) {
581 if (mwifiex_register_cfg80211(adapter
)) {
582 mwifiex_dbg(adapter
, ERROR
,
583 "cannot register with cfg80211\n");
588 if (mwifiex_init_channel_scan_gap(adapter
)) {
589 mwifiex_dbg(adapter
, ERROR
,
590 "could not init channel stats table\n");
595 driver_mode
&= MWIFIEX_DRIVER_MODE_BITMASK
;
596 driver_mode
|= MWIFIEX_DRIVER_MODE_STA
;
600 /* Create station interface by default */
601 wdev
= mwifiex_add_virtual_intf(adapter
->wiphy
, "mlan%d", NET_NAME_ENUM
,
602 NL80211_IFTYPE_STATION
, NULL
);
604 mwifiex_dbg(adapter
, ERROR
,
605 "cannot create default STA interface\n");
610 if (driver_mode
& MWIFIEX_DRIVER_MODE_UAP
) {
611 wdev
= mwifiex_add_virtual_intf(adapter
->wiphy
, "uap%d", NET_NAME_ENUM
,
612 NL80211_IFTYPE_AP
, NULL
);
614 mwifiex_dbg(adapter
, ERROR
,
615 "cannot create AP interface\n");
621 if (driver_mode
& MWIFIEX_DRIVER_MODE_P2P
) {
622 wdev
= mwifiex_add_virtual_intf(adapter
->wiphy
, "p2p%d", NET_NAME_ENUM
,
623 NL80211_IFTYPE_P2P_CLIENT
, NULL
);
625 mwifiex_dbg(adapter
, ERROR
,
626 "cannot create p2p client interface\n");
633 mwifiex_drv_get_driver_version(adapter
, fmt
, sizeof(fmt
) - 1);
634 mwifiex_dbg(adapter
, MSG
, "driver_version = %s\n", fmt
);
638 vfree(adapter
->chan_stats
);
639 wiphy_unregister(adapter
->wiphy
);
640 wiphy_free(adapter
->wiphy
);
642 if (adapter
->if_ops
.disable_int
)
643 adapter
->if_ops
.disable_int(adapter
);
645 mwifiex_dbg(adapter
, ERROR
,
646 "info: %s: unregister device\n", __func__
);
647 if (adapter
->if_ops
.unregister_dev
)
648 adapter
->if_ops
.unregister_dev(adapter
);
650 adapter
->surprise_removed
= true;
651 mwifiex_terminate_workqueue(adapter
);
653 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_READY
) {
654 pr_debug("info: %s: shutdown mwifiex\n", __func__
);
655 mwifiex_shutdown_drv(adapter
);
660 if (adapter
->cal_data
) {
661 release_firmware(adapter
->cal_data
);
662 adapter
->cal_data
= NULL
;
664 if (adapter
->firmware
) {
665 release_firmware(adapter
->firmware
);
666 adapter
->firmware
= NULL
;
669 mwifiex_free_adapter(adapter
);
670 /* Tell all current and future waiters we're finished */
671 complete_all(fw_done
);
673 return init_failed
? -EIO
: 0;
676 static void mwifiex_fw_dpc(const struct firmware
*firmware
, void *context
)
678 _mwifiex_fw_dpc(firmware
, context
);
682 * This function gets the firmware and (if called asynchronously) kicks off the
685 static int mwifiex_init_hw_fw(struct mwifiex_adapter
*adapter
,
690 /* Override default firmware with manufacturing one if
691 * manufacturing mode is enabled
694 if (strlcpy(adapter
->fw_name
, MFG_FIRMWARE
,
695 sizeof(adapter
->fw_name
)) >=
696 sizeof(adapter
->fw_name
)) {
697 pr_err("%s: fw_name too long!\n", __func__
);
703 ret
= request_firmware_nowait(THIS_MODULE
, 1, adapter
->fw_name
,
704 adapter
->dev
, GFP_KERNEL
, adapter
,
707 ret
= request_firmware(&adapter
->firmware
,
713 mwifiex_dbg(adapter
, ERROR
, "request_firmware%s error %d\n",
714 req_fw_nowait
? "_nowait" : "", ret
);
719 * CFG802.11 network device handler for open.
721 * Starts the data queue.
724 mwifiex_open(struct net_device
*dev
)
726 netif_carrier_off(dev
);
732 * CFG802.11 network device handler for close.
735 mwifiex_close(struct net_device
*dev
)
737 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
739 if (priv
->scan_request
) {
740 struct cfg80211_scan_info info
= {
744 mwifiex_dbg(priv
->adapter
, INFO
,
745 "aborting scan on ndo_stop\n");
746 cfg80211_scan_done(priv
->scan_request
, &info
);
747 priv
->scan_request
= NULL
;
748 priv
->scan_aborting
= true;
751 if (priv
->sched_scanning
) {
752 mwifiex_dbg(priv
->adapter
, INFO
,
753 "aborting bgscan on ndo_stop\n");
754 mwifiex_stop_bg_scan(priv
);
755 cfg80211_sched_scan_stopped(priv
->wdev
.wiphy
, 0);
762 mwifiex_bypass_tx_queue(struct mwifiex_private
*priv
,
765 struct ethhdr
*eth_hdr
= (struct ethhdr
*)skb
->data
;
767 if (ntohs(eth_hdr
->h_proto
) == ETH_P_PAE
||
768 mwifiex_is_skb_mgmt_frame(skb
) ||
769 (GET_BSS_ROLE(priv
) == MWIFIEX_BSS_ROLE_STA
&&
770 ISSUPP_TDLS_ENABLED(priv
->adapter
->fw_cap_info
) &&
771 (ntohs(eth_hdr
->h_proto
) == ETH_P_TDLS
))) {
772 mwifiex_dbg(priv
->adapter
, DATA
,
773 "bypass txqueue; eth type %#x, mgmt %d\n",
774 ntohs(eth_hdr
->h_proto
),
775 mwifiex_is_skb_mgmt_frame(skb
));
782 * Add buffer into wmm tx queue and queue work to transmit it.
784 int mwifiex_queue_tx_pkt(struct mwifiex_private
*priv
, struct sk_buff
*skb
)
786 struct netdev_queue
*txq
;
787 int index
= mwifiex_1d_to_wmm_queue
[skb
->priority
];
789 if (atomic_inc_return(&priv
->wmm_tx_pending
[index
]) >= MAX_TX_PENDING
) {
790 txq
= netdev_get_tx_queue(priv
->netdev
, index
);
791 if (!netif_tx_queue_stopped(txq
)) {
792 netif_tx_stop_queue(txq
);
793 mwifiex_dbg(priv
->adapter
, DATA
,
794 "stop queue: %d\n", index
);
798 if (mwifiex_bypass_tx_queue(priv
, skb
)) {
799 atomic_inc(&priv
->adapter
->tx_pending
);
800 atomic_inc(&priv
->adapter
->bypass_tx_pending
);
801 mwifiex_wmm_add_buf_bypass_txqueue(priv
, skb
);
803 atomic_inc(&priv
->adapter
->tx_pending
);
804 mwifiex_wmm_add_buf_txqueue(priv
, skb
);
807 mwifiex_queue_main_work(priv
->adapter
);
813 mwifiex_clone_skb_for_tx_status(struct mwifiex_private
*priv
,
814 struct sk_buff
*skb
, u8 flag
, u64
*cookie
)
816 struct sk_buff
*orig_skb
= skb
;
817 struct mwifiex_txinfo
*tx_info
, *orig_tx_info
;
819 skb
= skb_clone(skb
, GFP_ATOMIC
);
824 spin_lock_irqsave(&priv
->ack_status_lock
, flags
);
825 id
= idr_alloc(&priv
->ack_status_frames
, orig_skb
,
826 1, 0x10, GFP_ATOMIC
);
827 spin_unlock_irqrestore(&priv
->ack_status_lock
, flags
);
830 tx_info
= MWIFIEX_SKB_TXCB(skb
);
831 tx_info
->ack_frame_id
= id
;
832 tx_info
->flags
|= flag
;
833 orig_tx_info
= MWIFIEX_SKB_TXCB(orig_skb
);
834 orig_tx_info
->ack_frame_id
= id
;
835 orig_tx_info
->flags
|= flag
;
837 if (flag
== MWIFIEX_BUF_FLAG_ACTION_TX_STATUS
&& cookie
)
838 orig_tx_info
->cookie
= *cookie
;
840 } else if (skb_shared(skb
)) {
847 /* couldn't clone -- lose tx status ... */
855 * CFG802.11 network device handler for data transmission.
858 mwifiex_hard_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
860 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
861 struct sk_buff
*new_skb
;
862 struct mwifiex_txinfo
*tx_info
;
865 mwifiex_dbg(priv
->adapter
, DATA
,
866 "data: %lu BSS(%d-%d): Data <= kernel\n",
867 jiffies
, priv
->bss_type
, priv
->bss_num
);
869 if (priv
->adapter
->surprise_removed
) {
871 priv
->stats
.tx_dropped
++;
874 if (!skb
->len
|| (skb
->len
> ETH_FRAME_LEN
)) {
875 mwifiex_dbg(priv
->adapter
, ERROR
,
876 "Tx: bad skb len %d\n", skb
->len
);
878 priv
->stats
.tx_dropped
++;
881 if (skb_headroom(skb
) < MWIFIEX_MIN_DATA_HEADER_LEN
) {
882 mwifiex_dbg(priv
->adapter
, DATA
,
883 "data: Tx: insufficient skb headroom %d\n",
885 /* Insufficient skb headroom - allocate a new skb */
887 skb_realloc_headroom(skb
, MWIFIEX_MIN_DATA_HEADER_LEN
);
888 if (unlikely(!new_skb
)) {
889 mwifiex_dbg(priv
->adapter
, ERROR
,
890 "Tx: cannot alloca new_skb\n");
892 priv
->stats
.tx_dropped
++;
897 mwifiex_dbg(priv
->adapter
, INFO
,
898 "info: new skb headroomd %d\n",
902 tx_info
= MWIFIEX_SKB_TXCB(skb
);
903 memset(tx_info
, 0, sizeof(*tx_info
));
904 tx_info
->bss_num
= priv
->bss_num
;
905 tx_info
->bss_type
= priv
->bss_type
;
906 tx_info
->pkt_len
= skb
->len
;
908 multicast
= is_multicast_ether_addr(skb
->data
);
910 if (unlikely(!multicast
&& skb
->sk
&&
911 skb_shinfo(skb
)->tx_flags
& SKBTX_WIFI_STATUS
&&
912 priv
->adapter
->fw_api_ver
== MWIFIEX_FW_V15
))
913 skb
= mwifiex_clone_skb_for_tx_status(priv
,
915 MWIFIEX_BUF_FLAG_EAPOL_TX_STATUS
, NULL
);
917 /* Record the current time the packet was queued; used to
918 * determine the amount of time the packet was queued in
919 * the driver before it was sent to the firmware.
920 * The delay is then sent along with the packet to the
921 * firmware for aggregate delay calculation for stats and
922 * MSDU lifetime expiry.
924 __net_timestamp(skb
);
926 if (ISSUPP_TDLS_ENABLED(priv
->adapter
->fw_cap_info
) &&
927 priv
->bss_type
== MWIFIEX_BSS_TYPE_STA
&&
928 !ether_addr_equal_unaligned(priv
->cfg_bssid
, skb
->data
)) {
929 if (priv
->adapter
->auto_tdls
&& priv
->check_tdls_tx
)
930 mwifiex_tdls_check_tx(priv
, skb
);
933 mwifiex_queue_tx_pkt(priv
, skb
);
939 * CFG802.11 network device handler for setting MAC address.
942 mwifiex_set_mac_address(struct net_device
*dev
, void *addr
)
944 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
945 struct sockaddr
*hw_addr
= addr
;
948 memcpy(priv
->curr_addr
, hw_addr
->sa_data
, ETH_ALEN
);
950 /* Send request to firmware */
951 ret
= mwifiex_send_cmd(priv
, HostCmd_CMD_802_11_MAC_ADDRESS
,
952 HostCmd_ACT_GEN_SET
, 0, NULL
, true);
955 memcpy(priv
->netdev
->dev_addr
, priv
->curr_addr
, ETH_ALEN
);
957 mwifiex_dbg(priv
->adapter
, ERROR
,
958 "set mac address failed: ret=%d\n", ret
);
960 memcpy(dev
->dev_addr
, priv
->curr_addr
, ETH_ALEN
);
966 * CFG802.11 network device handler for setting multicast list.
968 static void mwifiex_set_multicast_list(struct net_device
*dev
)
970 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
971 struct mwifiex_multicast_list mcast_list
;
973 if (dev
->flags
& IFF_PROMISC
) {
974 mcast_list
.mode
= MWIFIEX_PROMISC_MODE
;
975 } else if (dev
->flags
& IFF_ALLMULTI
||
976 netdev_mc_count(dev
) > MWIFIEX_MAX_MULTICAST_LIST_SIZE
) {
977 mcast_list
.mode
= MWIFIEX_ALL_MULTI_MODE
;
979 mcast_list
.mode
= MWIFIEX_MULTICAST_MODE
;
980 mcast_list
.num_multicast_addr
=
981 mwifiex_copy_mcast_addr(&mcast_list
, dev
);
983 mwifiex_request_set_multicast_list(priv
, &mcast_list
);
987 * CFG802.11 network device handler for transmission timeout.
990 mwifiex_tx_timeout(struct net_device
*dev
)
992 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
994 priv
->num_tx_timeout
++;
995 priv
->tx_timeout_cnt
++;
996 mwifiex_dbg(priv
->adapter
, ERROR
,
997 "%lu : Tx timeout(#%d), bss_type-num = %d-%d\n",
998 jiffies
, priv
->tx_timeout_cnt
, priv
->bss_type
,
1000 mwifiex_set_trans_start(dev
);
1002 if (priv
->tx_timeout_cnt
> TX_TIMEOUT_THRESHOLD
&&
1003 priv
->adapter
->if_ops
.card_reset
) {
1004 mwifiex_dbg(priv
->adapter
, ERROR
,
1005 "tx_timeout_cnt exceeds threshold.\t"
1006 "Triggering card reset!\n");
1007 priv
->adapter
->if_ops
.card_reset(priv
->adapter
);
1011 void mwifiex_multi_chan_resync(struct mwifiex_adapter
*adapter
)
1013 struct usb_card_rec
*card
= adapter
->card
;
1014 struct mwifiex_private
*priv
;
1018 card
->mc_resync_flag
= true;
1019 for (i
= 0; i
< MWIFIEX_TX_DATA_PORT
; i
++) {
1020 if (atomic_read(&card
->port
[i
].tx_data_urb_pending
)) {
1021 mwifiex_dbg(adapter
, WARN
, "pending data urb in sys\n");
1026 card
->mc_resync_flag
= false;
1027 tx_buf_size
= 0xffff;
1028 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
1029 ret
= mwifiex_send_cmd(priv
, HostCmd_CMD_RECONFIGURE_TX_BUFF
,
1030 HostCmd_ACT_GEN_SET
, 0, &tx_buf_size
, false);
1032 mwifiex_dbg(adapter
, ERROR
,
1033 "send reconfig tx buf size cmd err\n");
1035 EXPORT_SYMBOL_GPL(mwifiex_multi_chan_resync
);
1037 int mwifiex_drv_info_dump(struct mwifiex_adapter
*adapter
, void **drv_info
)
1040 char drv_version
[64];
1041 struct usb_card_rec
*cardp
;
1042 struct sdio_mmc_card
*sdio_card
;
1043 struct mwifiex_private
*priv
;
1045 struct netdev_queue
*txq
;
1046 struct mwifiex_debug_info
*debug_info
;
1047 void *drv_info_dump
;
1049 mwifiex_dbg(adapter
, MSG
, "===mwifiex driverinfo dump start===\n");
1051 /* memory allocate here should be free in mwifiex_upload_device_dump*/
1052 drv_info_dump
= vzalloc(MWIFIEX_DRV_INFO_SIZE_MAX
);
1057 p
= (char *)(drv_info_dump
);
1058 p
+= sprintf(p
, "driver_name = " "\"mwifiex\"\n");
1060 mwifiex_drv_get_driver_version(adapter
, drv_version
,
1061 sizeof(drv_version
) - 1);
1062 p
+= sprintf(p
, "driver_version = %s\n", drv_version
);
1064 if (adapter
->iface_type
== MWIFIEX_USB
) {
1065 cardp
= (struct usb_card_rec
*)adapter
->card
;
1066 p
+= sprintf(p
, "tx_cmd_urb_pending = %d\n",
1067 atomic_read(&cardp
->tx_cmd_urb_pending
));
1068 p
+= sprintf(p
, "tx_data_urb_pending_port_0 = %d\n",
1069 atomic_read(&cardp
->port
[0].tx_data_urb_pending
));
1070 p
+= sprintf(p
, "tx_data_urb_pending_port_1 = %d\n",
1071 atomic_read(&cardp
->port
[1].tx_data_urb_pending
));
1072 p
+= sprintf(p
, "rx_cmd_urb_pending = %d\n",
1073 atomic_read(&cardp
->rx_cmd_urb_pending
));
1074 p
+= sprintf(p
, "rx_data_urb_pending = %d\n",
1075 atomic_read(&cardp
->rx_data_urb_pending
));
1078 p
+= sprintf(p
, "tx_pending = %d\n",
1079 atomic_read(&adapter
->tx_pending
));
1080 p
+= sprintf(p
, "rx_pending = %d\n",
1081 atomic_read(&adapter
->rx_pending
));
1083 if (adapter
->iface_type
== MWIFIEX_SDIO
) {
1084 sdio_card
= (struct sdio_mmc_card
*)adapter
->card
;
1085 p
+= sprintf(p
, "\nmp_rd_bitmap=0x%x curr_rd_port=0x%x\n",
1086 sdio_card
->mp_rd_bitmap
, sdio_card
->curr_rd_port
);
1087 p
+= sprintf(p
, "mp_wr_bitmap=0x%x curr_wr_port=0x%x\n",
1088 sdio_card
->mp_wr_bitmap
, sdio_card
->curr_wr_port
);
1091 for (i
= 0; i
< adapter
->priv_num
; i
++) {
1092 if (!adapter
->priv
[i
] || !adapter
->priv
[i
]->netdev
)
1094 priv
= adapter
->priv
[i
];
1095 p
+= sprintf(p
, "\n[interface : \"%s\"]\n",
1096 priv
->netdev
->name
);
1097 p
+= sprintf(p
, "wmm_tx_pending[0] = %d\n",
1098 atomic_read(&priv
->wmm_tx_pending
[0]));
1099 p
+= sprintf(p
, "wmm_tx_pending[1] = %d\n",
1100 atomic_read(&priv
->wmm_tx_pending
[1]));
1101 p
+= sprintf(p
, "wmm_tx_pending[2] = %d\n",
1102 atomic_read(&priv
->wmm_tx_pending
[2]));
1103 p
+= sprintf(p
, "wmm_tx_pending[3] = %d\n",
1104 atomic_read(&priv
->wmm_tx_pending
[3]));
1105 p
+= sprintf(p
, "media_state=\"%s\"\n", !priv
->media_connected
?
1106 "Disconnected" : "Connected");
1107 p
+= sprintf(p
, "carrier %s\n", (netif_carrier_ok(priv
->netdev
)
1109 for (idx
= 0; idx
< priv
->netdev
->num_tx_queues
; idx
++) {
1110 txq
= netdev_get_tx_queue(priv
->netdev
, idx
);
1111 p
+= sprintf(p
, "tx queue %d:%s ", idx
,
1112 netif_tx_queue_stopped(txq
) ?
1113 "stopped" : "started");
1115 p
+= sprintf(p
, "\n%s: num_tx_timeout = %d\n",
1116 priv
->netdev
->name
, priv
->num_tx_timeout
);
1119 if (adapter
->iface_type
== MWIFIEX_SDIO
||
1120 adapter
->iface_type
== MWIFIEX_PCIE
) {
1121 p
+= sprintf(p
, "\n=== %s register dump===\n",
1122 adapter
->iface_type
== MWIFIEX_SDIO
?
1124 if (adapter
->if_ops
.reg_dump
)
1125 p
+= adapter
->if_ops
.reg_dump(adapter
, p
);
1127 p
+= sprintf(p
, "\n=== more debug information\n");
1128 debug_info
= kzalloc(sizeof(*debug_info
), GFP_KERNEL
);
1130 for (i
= 0; i
< adapter
->priv_num
; i
++) {
1131 if (!adapter
->priv
[i
] || !adapter
->priv
[i
]->netdev
)
1133 priv
= adapter
->priv
[i
];
1134 mwifiex_get_debug_info(priv
, debug_info
);
1135 p
+= mwifiex_debug_info_to_buffer(priv
, p
, debug_info
);
1141 mwifiex_dbg(adapter
, MSG
, "===mwifiex driverinfo dump end===\n");
1142 *drv_info
= drv_info_dump
;
1143 return p
- drv_info_dump
;
1145 EXPORT_SYMBOL_GPL(mwifiex_drv_info_dump
);
1147 void mwifiex_upload_device_dump(struct mwifiex_adapter
*adapter
, void *drv_info
,
1150 u8 idx
, *dump_data
, *fw_dump_ptr
;
1153 dump_len
= (strlen("========Start dump driverinfo========\n") +
1155 strlen("\n========End dump========\n"));
1157 for (idx
= 0; idx
< adapter
->num_mem_types
; idx
++) {
1158 struct memory_type_mapping
*entry
=
1159 &adapter
->mem_type_mapping_tbl
[idx
];
1161 if (entry
->mem_ptr
) {
1162 dump_len
+= (strlen("========Start dump ") +
1163 strlen(entry
->mem_name
) +
1164 strlen("========\n") +
1165 (entry
->mem_size
+ 1) +
1166 strlen("\n========End dump========\n"));
1170 dump_data
= vzalloc(dump_len
+ 1);
1174 fw_dump_ptr
= dump_data
;
1176 /* Dump all the memory data into single file, a userspace script will
1177 * be used to split all the memory data to multiple files
1179 mwifiex_dbg(adapter
, MSG
,
1180 "== mwifiex dump information to /sys/class/devcoredump start");
1182 strcpy(fw_dump_ptr
, "========Start dump driverinfo========\n");
1183 fw_dump_ptr
+= strlen("========Start dump driverinfo========\n");
1184 memcpy(fw_dump_ptr
, drv_info
, drv_info_size
);
1185 fw_dump_ptr
+= drv_info_size
;
1186 strcpy(fw_dump_ptr
, "\n========End dump========\n");
1187 fw_dump_ptr
+= strlen("\n========End dump========\n");
1189 for (idx
= 0; idx
< adapter
->num_mem_types
; idx
++) {
1190 struct memory_type_mapping
*entry
=
1191 &adapter
->mem_type_mapping_tbl
[idx
];
1193 if (entry
->mem_ptr
) {
1194 strcpy(fw_dump_ptr
, "========Start dump ");
1195 fw_dump_ptr
+= strlen("========Start dump ");
1197 strcpy(fw_dump_ptr
, entry
->mem_name
);
1198 fw_dump_ptr
+= strlen(entry
->mem_name
);
1200 strcpy(fw_dump_ptr
, "========\n");
1201 fw_dump_ptr
+= strlen("========\n");
1203 memcpy(fw_dump_ptr
, entry
->mem_ptr
, entry
->mem_size
);
1204 fw_dump_ptr
+= entry
->mem_size
;
1206 strcpy(fw_dump_ptr
, "\n========End dump========\n");
1207 fw_dump_ptr
+= strlen("\n========End dump========\n");
1211 /* device dump data will be free in device coredump release function
1214 dev_coredumpv(adapter
->dev
, dump_data
, dump_len
, GFP_KERNEL
);
1215 mwifiex_dbg(adapter
, MSG
,
1216 "== mwifiex dump information to /sys/class/devcoredump end");
1219 for (idx
= 0; idx
< adapter
->num_mem_types
; idx
++) {
1220 struct memory_type_mapping
*entry
=
1221 &adapter
->mem_type_mapping_tbl
[idx
];
1223 vfree(entry
->mem_ptr
);
1224 entry
->mem_ptr
= NULL
;
1225 entry
->mem_size
= 0;
1230 EXPORT_SYMBOL_GPL(mwifiex_upload_device_dump
);
1233 * CFG802.11 network device handler for statistics retrieval.
1235 static struct net_device_stats
*mwifiex_get_stats(struct net_device
*dev
)
1237 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
1239 return &priv
->stats
;
1243 mwifiex_netdev_select_wmm_queue(struct net_device
*dev
, struct sk_buff
*skb
,
1244 void *accel_priv
, select_queue_fallback_t fallback
)
1246 skb
->priority
= cfg80211_classify8021d(skb
, NULL
);
1247 return mwifiex_1d_to_wmm_queue
[skb
->priority
];
1250 /* Network device handlers */
1251 static const struct net_device_ops mwifiex_netdev_ops
= {
1252 .ndo_open
= mwifiex_open
,
1253 .ndo_stop
= mwifiex_close
,
1254 .ndo_start_xmit
= mwifiex_hard_start_xmit
,
1255 .ndo_set_mac_address
= mwifiex_set_mac_address
,
1256 .ndo_validate_addr
= eth_validate_addr
,
1257 .ndo_tx_timeout
= mwifiex_tx_timeout
,
1258 .ndo_get_stats
= mwifiex_get_stats
,
1259 .ndo_set_rx_mode
= mwifiex_set_multicast_list
,
1260 .ndo_select_queue
= mwifiex_netdev_select_wmm_queue
,
1264 * This function initializes the private structure parameters.
1266 * The following wait queues are initialized -
1267 * - IOCTL wait queue
1268 * - Command wait queue
1269 * - Statistics wait queue
1271 * ...and the following default parameters are set -
1272 * - Current key index : Set to 0
1273 * - Rate index : Set to auto
1274 * - Media connected : Set to disconnected
1275 * - Adhoc link sensed : Set to false
1276 * - Nick name : Set to null
1277 * - Number of Tx timeout : Set to 0
1278 * - Device address : Set to current address
1279 * - Rx histogram statistc : Set to 0
1281 * In addition, the CFG80211 work queue is also created.
1283 void mwifiex_init_priv_params(struct mwifiex_private
*priv
,
1284 struct net_device
*dev
)
1286 dev
->netdev_ops
= &mwifiex_netdev_ops
;
1287 dev
->needs_free_netdev
= true;
1288 /* Initialize private structure */
1289 priv
->current_key_index
= 0;
1290 priv
->media_connected
= false;
1291 memset(priv
->mgmt_ie
, 0,
1292 sizeof(struct mwifiex_ie
) * MAX_MGMT_IE_INDEX
);
1293 priv
->beacon_idx
= MWIFIEX_AUTO_IDX_MASK
;
1294 priv
->proberesp_idx
= MWIFIEX_AUTO_IDX_MASK
;
1295 priv
->assocresp_idx
= MWIFIEX_AUTO_IDX_MASK
;
1296 priv
->gen_idx
= MWIFIEX_AUTO_IDX_MASK
;
1297 priv
->num_tx_timeout
= 0;
1298 ether_addr_copy(priv
->curr_addr
, priv
->adapter
->perm_addr
);
1299 memcpy(dev
->dev_addr
, priv
->curr_addr
, ETH_ALEN
);
1301 if (GET_BSS_ROLE(priv
) == MWIFIEX_BSS_ROLE_STA
||
1302 GET_BSS_ROLE(priv
) == MWIFIEX_BSS_ROLE_UAP
) {
1303 priv
->hist_data
= kmalloc(sizeof(*priv
->hist_data
), GFP_KERNEL
);
1304 if (priv
->hist_data
)
1305 mwifiex_hist_data_reset(priv
);
1310 * This function check if command is pending.
1312 int is_command_pending(struct mwifiex_adapter
*adapter
)
1314 unsigned long flags
;
1315 int is_cmd_pend_q_empty
;
1317 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, flags
);
1318 is_cmd_pend_q_empty
= list_empty(&adapter
->cmd_pending_q
);
1319 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
, flags
);
1321 return !is_cmd_pend_q_empty
;
1325 * This is the RX work queue function.
1327 * It handles the RX operations.
1329 static void mwifiex_rx_work_queue(struct work_struct
*work
)
1331 struct mwifiex_adapter
*adapter
=
1332 container_of(work
, struct mwifiex_adapter
, rx_work
);
1334 if (adapter
->surprise_removed
)
1336 mwifiex_process_rx(adapter
);
1340 * This is the main work queue function.
1342 * It handles the main process, which in turn handles the complete
1343 * driver operations.
1345 static void mwifiex_main_work_queue(struct work_struct
*work
)
1347 struct mwifiex_adapter
*adapter
=
1348 container_of(work
, struct mwifiex_adapter
, main_work
);
1350 if (adapter
->surprise_removed
)
1352 mwifiex_main_process(adapter
);
1356 * This function gets called during PCIe function level reset. Required
1357 * code is extracted from mwifiex_remove_card()
1360 mwifiex_shutdown_sw(struct mwifiex_adapter
*adapter
)
1362 struct mwifiex_private
*priv
;
1368 wait_for_completion(adapter
->fw_done
);
1369 /* Caller should ensure we aren't suspending while this happens */
1370 reinit_completion(adapter
->fw_done
);
1372 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
1373 mwifiex_deauthenticate(priv
, NULL
);
1375 /* We can no longer handle interrupts once we start doing the teardown
1378 if (adapter
->if_ops
.disable_int
)
1379 adapter
->if_ops
.disable_int(adapter
);
1381 adapter
->surprise_removed
= true;
1382 mwifiex_terminate_workqueue(adapter
);
1385 for (i
= 0; i
< adapter
->priv_num
; i
++) {
1386 priv
= adapter
->priv
[i
];
1387 if (priv
&& priv
->netdev
) {
1388 mwifiex_stop_net_dev_queue(priv
->netdev
, adapter
);
1389 if (netif_carrier_ok(priv
->netdev
))
1390 netif_carrier_off(priv
->netdev
);
1391 netif_device_detach(priv
->netdev
);
1395 mwifiex_dbg(adapter
, CMD
, "cmd: calling mwifiex_shutdown_drv...\n");
1397 mwifiex_shutdown_drv(adapter
);
1398 if (adapter
->if_ops
.down_dev
)
1399 adapter
->if_ops
.down_dev(adapter
);
1401 mwifiex_dbg(adapter
, CMD
, "cmd: mwifiex_shutdown_drv done\n");
1402 if (atomic_read(&adapter
->rx_pending
) ||
1403 atomic_read(&adapter
->tx_pending
) ||
1404 atomic_read(&adapter
->cmd_pending
)) {
1405 mwifiex_dbg(adapter
, ERROR
,
1406 "rx_pending=%d, tx_pending=%d,\t"
1408 atomic_read(&adapter
->rx_pending
),
1409 atomic_read(&adapter
->tx_pending
),
1410 atomic_read(&adapter
->cmd_pending
));
1413 for (i
= 0; i
< adapter
->priv_num
; i
++) {
1414 priv
= adapter
->priv
[i
];
1419 priv
->wdev
.iftype
!= NL80211_IFTYPE_UNSPECIFIED
)
1420 mwifiex_del_virtual_intf(adapter
->wiphy
, &priv
->wdev
);
1423 vfree(adapter
->chan_stats
);
1425 mwifiex_dbg(adapter
, INFO
, "%s, successful\n", __func__
);
1429 EXPORT_SYMBOL_GPL(mwifiex_shutdown_sw
);
1431 /* This function gets called during PCIe function level reset. Required
1432 * code is extracted from mwifiex_add_card()
1435 mwifiex_reinit_sw(struct mwifiex_adapter
*adapter
)
1439 mwifiex_init_lock_list(adapter
);
1440 if (adapter
->if_ops
.up_dev
)
1441 adapter
->if_ops
.up_dev(adapter
);
1443 adapter
->hw_status
= MWIFIEX_HW_STATUS_INITIALIZING
;
1444 adapter
->surprise_removed
= false;
1445 init_waitqueue_head(&adapter
->init_wait_q
);
1446 adapter
->is_suspended
= false;
1447 adapter
->hs_activated
= false;
1448 adapter
->is_cmd_timedout
= 0;
1449 init_waitqueue_head(&adapter
->hs_activate_wait_q
);
1450 init_waitqueue_head(&adapter
->cmd_wait_q
.wait
);
1451 adapter
->cmd_wait_q
.status
= 0;
1452 adapter
->scan_wait_q_woken
= false;
1454 if ((num_possible_cpus() > 1) || adapter
->iface_type
== MWIFIEX_USB
)
1455 adapter
->rx_work_enabled
= true;
1457 adapter
->workqueue
=
1458 alloc_workqueue("MWIFIEX_WORK_QUEUE",
1459 WQ_HIGHPRI
| WQ_MEM_RECLAIM
| WQ_UNBOUND
, 1);
1460 if (!adapter
->workqueue
)
1463 INIT_WORK(&adapter
->main_work
, mwifiex_main_work_queue
);
1465 if (adapter
->rx_work_enabled
) {
1466 adapter
->rx_workqueue
= alloc_workqueue("MWIFIEX_RX_WORK_QUEUE",
1470 if (!adapter
->rx_workqueue
)
1472 INIT_WORK(&adapter
->rx_work
, mwifiex_rx_work_queue
);
1475 /* Register the device. Fill up the private data structure with
1476 * relevant information from the card. Some code extracted from
1477 * mwifiex_register_dev()
1479 mwifiex_dbg(adapter
, INFO
, "%s, mwifiex_init_hw_fw()...\n", __func__
);
1481 if (mwifiex_init_hw_fw(adapter
, false)) {
1482 mwifiex_dbg(adapter
, ERROR
,
1483 "%s: firmware init failed\n", __func__
);
1487 /* _mwifiex_fw_dpc() does its own cleanup */
1488 ret
= _mwifiex_fw_dpc(adapter
->firmware
, adapter
);
1490 pr_err("Failed to bring up adapter: %d\n", ret
);
1493 mwifiex_dbg(adapter
, INFO
, "%s, successful\n", __func__
);
1498 mwifiex_dbg(adapter
, ERROR
, "info: %s: unregister device\n", __func__
);
1499 if (adapter
->if_ops
.unregister_dev
)
1500 adapter
->if_ops
.unregister_dev(adapter
);
1503 adapter
->surprise_removed
= true;
1504 mwifiex_terminate_workqueue(adapter
);
1505 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_READY
) {
1506 mwifiex_dbg(adapter
, ERROR
,
1507 "info: %s: shutdown mwifiex\n", __func__
);
1508 mwifiex_shutdown_drv(adapter
);
1511 complete_all(adapter
->fw_done
);
1512 mwifiex_dbg(adapter
, INFO
, "%s, error\n", __func__
);
1516 EXPORT_SYMBOL_GPL(mwifiex_reinit_sw
);
1518 static irqreturn_t
mwifiex_irq_wakeup_handler(int irq
, void *priv
)
1520 struct mwifiex_adapter
*adapter
= priv
;
1522 dev_dbg(adapter
->dev
, "%s: wake by wifi", __func__
);
1523 adapter
->wake_by_wifi
= true;
1524 disable_irq_nosync(irq
);
1526 /* Notify PM core we are wakeup source */
1527 pm_wakeup_event(adapter
->dev
, 0);
1533 static void mwifiex_probe_of(struct mwifiex_adapter
*adapter
)
1536 struct device
*dev
= adapter
->dev
;
1541 adapter
->dt_node
= dev
->of_node
;
1542 adapter
->irq_wakeup
= irq_of_parse_and_map(adapter
->dt_node
, 0);
1543 if (!adapter
->irq_wakeup
) {
1544 dev_dbg(dev
, "fail to parse irq_wakeup from device tree\n");
1548 ret
= devm_request_irq(dev
, adapter
->irq_wakeup
,
1549 mwifiex_irq_wakeup_handler
, IRQF_TRIGGER_LOW
,
1550 "wifi_wake", adapter
);
1552 dev_err(dev
, "Failed to request irq_wakeup %d (%d)\n",
1553 adapter
->irq_wakeup
, ret
);
1557 disable_irq(adapter
->irq_wakeup
);
1558 if (device_init_wakeup(dev
, true)) {
1559 dev_err(dev
, "fail to init wakeup for mwifiex\n");
1565 adapter
->irq_wakeup
= -1;
1569 * This function adds the card.
1571 * This function follows the following major steps to set up the device -
1572 * - Initialize software. This includes probing the card, registering
1573 * the interface operations table, and allocating/initializing the
1575 * - Set up the netlink socket
1576 * - Create and start the main work queue
1577 * - Register the device
1578 * - Initialize firmware and hardware
1579 * - Add logical interfaces
1582 mwifiex_add_card(void *card
, struct completion
*fw_done
,
1583 struct mwifiex_if_ops
*if_ops
, u8 iface_type
,
1586 struct mwifiex_adapter
*adapter
;
1588 if (mwifiex_register(card
, dev
, if_ops
, (void **)&adapter
)) {
1589 pr_err("%s: software init failed\n", __func__
);
1593 mwifiex_probe_of(adapter
);
1595 adapter
->iface_type
= iface_type
;
1596 adapter
->fw_done
= fw_done
;
1598 adapter
->hw_status
= MWIFIEX_HW_STATUS_INITIALIZING
;
1599 adapter
->surprise_removed
= false;
1600 init_waitqueue_head(&adapter
->init_wait_q
);
1601 adapter
->is_suspended
= false;
1602 adapter
->hs_activated
= false;
1603 init_waitqueue_head(&adapter
->hs_activate_wait_q
);
1604 init_waitqueue_head(&adapter
->cmd_wait_q
.wait
);
1605 adapter
->cmd_wait_q
.status
= 0;
1606 adapter
->scan_wait_q_woken
= false;
1608 if ((num_possible_cpus() > 1) || adapter
->iface_type
== MWIFIEX_USB
) {
1609 adapter
->rx_work_enabled
= true;
1610 pr_notice("rx work enabled, cpus %d\n", num_possible_cpus());
1613 adapter
->workqueue
=
1614 alloc_workqueue("MWIFIEX_WORK_QUEUE",
1615 WQ_HIGHPRI
| WQ_MEM_RECLAIM
| WQ_UNBOUND
, 1);
1616 if (!adapter
->workqueue
)
1619 INIT_WORK(&adapter
->main_work
, mwifiex_main_work_queue
);
1621 if (adapter
->rx_work_enabled
) {
1622 adapter
->rx_workqueue
= alloc_workqueue("MWIFIEX_RX_WORK_QUEUE",
1626 if (!adapter
->rx_workqueue
)
1629 INIT_WORK(&adapter
->rx_work
, mwifiex_rx_work_queue
);
1632 /* Register the device. Fill up the private data structure with relevant
1633 information from the card. */
1634 if (adapter
->if_ops
.register_dev(adapter
)) {
1635 pr_err("%s: failed to register mwifiex device\n", __func__
);
1636 goto err_registerdev
;
1639 if (mwifiex_init_hw_fw(adapter
, true)) {
1640 pr_err("%s: firmware init failed\n", __func__
);
1647 pr_debug("info: %s: unregister device\n", __func__
);
1648 if (adapter
->if_ops
.unregister_dev
)
1649 adapter
->if_ops
.unregister_dev(adapter
);
1651 adapter
->surprise_removed
= true;
1652 mwifiex_terminate_workqueue(adapter
);
1653 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_READY
) {
1654 pr_debug("info: %s: shutdown mwifiex\n", __func__
);
1655 mwifiex_shutdown_drv(adapter
);
1658 mwifiex_free_adapter(adapter
);
1664 EXPORT_SYMBOL_GPL(mwifiex_add_card
);
1667 * This function removes the card.
1669 * This function follows the following major steps to remove the device -
1670 * - Stop data traffic
1671 * - Shutdown firmware
1672 * - Remove the logical interfaces
1673 * - Terminate the work queue
1674 * - Unregister the device
1675 * - Free the adapter structure
1677 int mwifiex_remove_card(struct mwifiex_adapter
*adapter
)
1679 struct mwifiex_private
*priv
= NULL
;
1685 /* We can no longer handle interrupts once we start doing the teardown
1687 if (adapter
->if_ops
.disable_int
)
1688 adapter
->if_ops
.disable_int(adapter
);
1690 adapter
->surprise_removed
= true;
1692 mwifiex_terminate_workqueue(adapter
);
1695 for (i
= 0; i
< adapter
->priv_num
; i
++) {
1696 priv
= adapter
->priv
[i
];
1697 if (priv
&& priv
->netdev
) {
1698 mwifiex_stop_net_dev_queue(priv
->netdev
, adapter
);
1699 if (netif_carrier_ok(priv
->netdev
))
1700 netif_carrier_off(priv
->netdev
);
1704 mwifiex_dbg(adapter
, CMD
,
1705 "cmd: calling mwifiex_shutdown_drv...\n");
1707 mwifiex_shutdown_drv(adapter
);
1708 mwifiex_dbg(adapter
, CMD
,
1709 "cmd: mwifiex_shutdown_drv done\n");
1710 if (atomic_read(&adapter
->rx_pending
) ||
1711 atomic_read(&adapter
->tx_pending
) ||
1712 atomic_read(&adapter
->cmd_pending
)) {
1713 mwifiex_dbg(adapter
, ERROR
,
1714 "rx_pending=%d, tx_pending=%d,\t"
1716 atomic_read(&adapter
->rx_pending
),
1717 atomic_read(&adapter
->tx_pending
),
1718 atomic_read(&adapter
->cmd_pending
));
1721 for (i
= 0; i
< adapter
->priv_num
; i
++) {
1722 priv
= adapter
->priv
[i
];
1729 priv
->wdev
.iftype
!= NL80211_IFTYPE_UNSPECIFIED
)
1730 mwifiex_del_virtual_intf(adapter
->wiphy
, &priv
->wdev
);
1733 vfree(adapter
->chan_stats
);
1735 wiphy_unregister(adapter
->wiphy
);
1736 wiphy_free(adapter
->wiphy
);
1738 if (adapter
->irq_wakeup
>= 0)
1739 device_init_wakeup(adapter
->dev
, false);
1741 /* Unregister device */
1742 mwifiex_dbg(adapter
, INFO
,
1743 "info: unregister device\n");
1744 if (adapter
->if_ops
.unregister_dev
)
1745 adapter
->if_ops
.unregister_dev(adapter
);
1746 /* Free adapter structure */
1747 mwifiex_dbg(adapter
, INFO
,
1748 "info: free adapter\n");
1749 mwifiex_free_adapter(adapter
);
1754 EXPORT_SYMBOL_GPL(mwifiex_remove_card
);
1756 void _mwifiex_dbg(const struct mwifiex_adapter
*adapter
, int mask
,
1757 const char *fmt
, ...)
1759 struct va_format vaf
;
1762 if (!(adapter
->debug_mask
& mask
))
1765 va_start(args
, fmt
);
1771 dev_info(adapter
->dev
, "%pV", &vaf
);
1773 pr_info("%pV", &vaf
);
1777 EXPORT_SYMBOL_GPL(_mwifiex_dbg
);
1780 * This function initializes the module.
1782 * The debug FS is also initialized if configured.
1785 mwifiex_init_module(void)
1787 #ifdef CONFIG_DEBUG_FS
1788 mwifiex_debugfs_init();
1794 * This function cleans up the module.
1796 * The debug FS is removed if available.
1799 mwifiex_cleanup_module(void)
1801 #ifdef CONFIG_DEBUG_FS
1802 mwifiex_debugfs_remove();
1806 module_init(mwifiex_init_module
);
1807 module_exit(mwifiex_cleanup_module
);
1809 MODULE_AUTHOR("Marvell International Ltd.");
1810 MODULE_DESCRIPTION("Marvell WiFi-Ex Driver version " VERSION
);
1811 MODULE_VERSION(VERSION
);
1812 MODULE_LICENSE("GPL v2");