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.
26 #define MFG_FIRMWARE "mwifiex_mfg.bin"
28 static unsigned int debug_mask
= MWIFIEX_DEFAULT_DEBUG_MASK
;
29 module_param(debug_mask
, uint
, 0);
30 MODULE_PARM_DESC(debug_mask
, "bitmap for debug flags");
32 const char driver_version
[] = "mwifiex " VERSION
" (%s) ";
33 static char *cal_data_cfg
;
34 module_param(cal_data_cfg
, charp
, 0);
36 static unsigned short driver_mode
;
37 module_param(driver_mode
, ushort
, 0);
38 MODULE_PARM_DESC(driver_mode
,
39 "station=0x1(default), ap-sta=0x3, station-p2p=0x5, ap-sta-p2p=0x7");
42 module_param(mfg_mode
, bool, 0);
43 MODULE_PARM_DESC(mfg_mode
, "manufacturing mode enable:1, disable:0");
46 * This function registers the device and performs all the necessary
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
57 * In case of any errors during inittialization, this function also ensures
58 * proper cleanup before exiting.
60 static int mwifiex_register(void *card
, struct device
*dev
,
61 struct mwifiex_if_ops
*if_ops
, void **padapter
)
63 struct mwifiex_adapter
*adapter
;
66 adapter
= kzalloc(sizeof(struct mwifiex_adapter
), GFP_KERNEL
);
74 /* Save interface specific operations in adapter */
75 memmove(&adapter
->if_ops
, if_ops
, sizeof(struct mwifiex_if_ops
));
76 adapter
->debug_mask
= debug_mask
;
78 /* card specific initialization has been deferred until now .. */
79 if (adapter
->if_ops
.init_if
)
80 if (adapter
->if_ops
.init_if(adapter
))
83 adapter
->priv_num
= 0;
85 for (i
= 0; i
< MWIFIEX_MAX_BSS_NUM
; i
++) {
86 /* Allocate memory for private structure */
88 kzalloc(sizeof(struct mwifiex_private
), GFP_KERNEL
);
89 if (!adapter
->priv
[i
])
92 adapter
->priv
[i
]->adapter
= adapter
;
95 mwifiex_init_lock_list(adapter
);
97 setup_timer(&adapter
->cmd_timer
, mwifiex_cmd_timeout_func
,
98 (unsigned long)adapter
);
103 mwifiex_dbg(adapter
, ERROR
,
104 "info: leave mwifiex_register with error\n");
106 for (i
= 0; i
< adapter
->priv_num
; i
++)
107 kfree(adapter
->priv
[i
]);
115 * This function unregisters the device and performs all the necessary
118 * The following cleanup operations are performed -
120 * - Free beacon buffers
121 * - Free private structures
122 * - Free adapter structure
124 static int mwifiex_unregister(struct mwifiex_adapter
*adapter
)
128 if (adapter
->if_ops
.cleanup_if
)
129 adapter
->if_ops
.cleanup_if(adapter
);
131 del_timer_sync(&adapter
->cmd_timer
);
133 /* Free private structures */
134 for (i
= 0; i
< adapter
->priv_num
; i
++) {
135 if (adapter
->priv
[i
]) {
136 mwifiex_free_curr_bcn(adapter
->priv
[i
]);
137 kfree(adapter
->priv
[i
]);
141 if (adapter
->nd_info
) {
142 for (i
= 0 ; i
< adapter
->nd_info
->n_matches
; i
++)
143 kfree(adapter
->nd_info
->matches
[i
]);
144 kfree(adapter
->nd_info
);
145 adapter
->nd_info
= NULL
;
148 kfree(adapter
->regd
);
150 vfree(adapter
->chan_stats
);
155 void mwifiex_queue_main_work(struct mwifiex_adapter
*adapter
)
159 spin_lock_irqsave(&adapter
->main_proc_lock
, flags
);
160 if (adapter
->mwifiex_processing
) {
161 adapter
->more_task_flag
= true;
162 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
164 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
165 queue_work(adapter
->workqueue
, &adapter
->main_work
);
168 EXPORT_SYMBOL_GPL(mwifiex_queue_main_work
);
170 static void mwifiex_queue_rx_work(struct mwifiex_adapter
*adapter
)
174 spin_lock_irqsave(&adapter
->rx_proc_lock
, flags
);
175 if (adapter
->rx_processing
) {
176 spin_unlock_irqrestore(&adapter
->rx_proc_lock
, flags
);
178 spin_unlock_irqrestore(&adapter
->rx_proc_lock
, flags
);
179 queue_work(adapter
->rx_workqueue
, &adapter
->rx_work
);
183 static int mwifiex_process_rx(struct mwifiex_adapter
*adapter
)
187 struct mwifiex_rxinfo
*rx_info
;
189 spin_lock_irqsave(&adapter
->rx_proc_lock
, flags
);
190 if (adapter
->rx_processing
|| adapter
->rx_locked
) {
191 spin_unlock_irqrestore(&adapter
->rx_proc_lock
, flags
);
194 adapter
->rx_processing
= true;
195 spin_unlock_irqrestore(&adapter
->rx_proc_lock
, flags
);
198 /* Check for Rx data */
199 while ((skb
= skb_dequeue(&adapter
->rx_data_q
))) {
200 atomic_dec(&adapter
->rx_pending
);
201 if ((adapter
->delay_main_work
||
202 adapter
->iface_type
== MWIFIEX_USB
) &&
203 (atomic_read(&adapter
->rx_pending
) < LOW_RX_PENDING
)) {
204 if (adapter
->if_ops
.submit_rem_rx_urbs
)
205 adapter
->if_ops
.submit_rem_rx_urbs(adapter
);
206 adapter
->delay_main_work
= false;
207 mwifiex_queue_main_work(adapter
);
209 rx_info
= MWIFIEX_SKB_RXCB(skb
);
210 if (rx_info
->buf_type
== MWIFIEX_TYPE_AGGR_DATA
) {
211 if (adapter
->if_ops
.deaggr_pkt
)
212 adapter
->if_ops
.deaggr_pkt(adapter
, skb
);
213 dev_kfree_skb_any(skb
);
215 mwifiex_handle_rx_packet(adapter
, skb
);
218 spin_lock_irqsave(&adapter
->rx_proc_lock
, flags
);
219 adapter
->rx_processing
= false;
220 spin_unlock_irqrestore(&adapter
->rx_proc_lock
, flags
);
229 * This function is the main procedure of the driver and handles various driver
230 * operations. It runs in a loop and provides the core functionalities.
232 * The main responsibilities of this function are -
233 * - Ensure concurrency control
234 * - Handle pending interrupts and call interrupt handlers
235 * - Wake up the card if required
236 * - Handle command responses and call response handlers
237 * - Handle events and call event handlers
238 * - Execute pending commands
239 * - Transmit pending data packets
241 int mwifiex_main_process(struct mwifiex_adapter
*adapter
)
246 spin_lock_irqsave(&adapter
->main_proc_lock
, flags
);
248 /* Check if already processing */
249 if (adapter
->mwifiex_processing
|| adapter
->main_locked
) {
250 adapter
->more_task_flag
= true;
251 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
254 adapter
->mwifiex_processing
= true;
255 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
259 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_NOT_READY
)
262 /* 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
269 if (atomic_read(&adapter
->rx_pending
) >= HIGH_RX_PENDING
&&
270 adapter
->iface_type
!= MWIFIEX_USB
) {
271 adapter
->delay_main_work
= true;
272 mwifiex_queue_rx_work(adapter
);
276 /* Handle pending interrupt if any */
277 if (adapter
->int_status
) {
278 if (adapter
->hs_activated
)
279 mwifiex_process_hs_config(adapter
);
280 if (adapter
->if_ops
.process_int_status
)
281 adapter
->if_ops
.process_int_status(adapter
);
284 if (adapter
->rx_work_enabled
&& adapter
->data_received
)
285 mwifiex_queue_rx_work(adapter
);
287 /* 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
) &&
291 (is_command_pending(adapter
) ||
292 !skb_queue_empty(&adapter
->tx_data_q
) ||
293 !mwifiex_bypass_txlist_empty(adapter
) ||
294 !mwifiex_wmm_lists_empty(adapter
))) {
295 adapter
->pm_wakeup_fw_try
= true;
296 mod_timer(&adapter
->wakeup_timer
, jiffies
+ (HZ
*3));
297 adapter
->if_ops
.wakeup(adapter
);
301 if (IS_CARD_RX_RCVD(adapter
)) {
302 adapter
->data_received
= false;
303 adapter
->pm_wakeup_fw_try
= false;
304 del_timer(&adapter
->wakeup_timer
);
305 if (adapter
->ps_state
== PS_STATE_SLEEP
)
306 adapter
->ps_state
= PS_STATE_AWAKE
;
308 /* We have tried to wakeup the card already */
309 if (adapter
->pm_wakeup_fw_try
)
311 if (adapter
->ps_state
== PS_STATE_PRE_SLEEP
)
312 mwifiex_check_ps_cond(adapter
);
314 if (adapter
->ps_state
!= PS_STATE_AWAKE
)
316 if (adapter
->tx_lock_flag
) {
317 if (adapter
->iface_type
== MWIFIEX_USB
) {
318 if (!adapter
->usb_mc_setup
)
324 if ((!adapter
->scan_chan_gap_enabled
&&
325 adapter
->scan_processing
) || adapter
->data_sent
||
326 mwifiex_is_tdls_chan_switching
327 (mwifiex_get_priv(adapter
,
328 MWIFIEX_BSS_ROLE_STA
)) ||
329 (mwifiex_wmm_lists_empty(adapter
) &&
330 mwifiex_bypass_txlist_empty(adapter
) &&
331 skb_queue_empty(&adapter
->tx_data_q
))) {
332 if (adapter
->cmd_sent
|| adapter
->curr_cmd
||
333 !mwifiex_is_send_cmd_allowed
334 (mwifiex_get_priv(adapter
,
335 MWIFIEX_BSS_ROLE_STA
)) ||
336 (!is_command_pending(adapter
)))
341 /* Check for event */
342 if (adapter
->event_received
) {
343 adapter
->event_received
= false;
344 mwifiex_process_event(adapter
);
347 /* Check for Cmd Resp */
348 if (adapter
->cmd_resp_received
) {
349 adapter
->cmd_resp_received
= false;
350 mwifiex_process_cmdresp(adapter
);
352 /* call mwifiex back when init_fw is done */
353 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_INIT_DONE
) {
354 adapter
->hw_status
= MWIFIEX_HW_STATUS_READY
;
355 mwifiex_init_fw_complete(adapter
);
359 /* Check if we need to confirm Sleep Request
360 received previously */
361 if (adapter
->ps_state
== PS_STATE_PRE_SLEEP
)
362 mwifiex_check_ps_cond(adapter
);
364 /* * The ps_state may have been changed during processing of
365 * Sleep Request event.
367 if ((adapter
->ps_state
== PS_STATE_SLEEP
) ||
368 (adapter
->ps_state
== PS_STATE_PRE_SLEEP
) ||
369 (adapter
->ps_state
== PS_STATE_SLEEP_CFM
)) {
373 if (adapter
->tx_lock_flag
) {
374 if (adapter
->iface_type
== MWIFIEX_USB
) {
375 if (!adapter
->usb_mc_setup
)
381 if (!adapter
->cmd_sent
&& !adapter
->curr_cmd
&&
382 mwifiex_is_send_cmd_allowed
383 (mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_STA
))) {
384 if (mwifiex_exec_next_cmd(adapter
) == -1) {
390 /** If USB Multi channel setup ongoing,
391 * wait for ready to tx data.
393 if (adapter
->iface_type
== MWIFIEX_USB
&&
394 adapter
->usb_mc_setup
)
397 if ((adapter
->scan_chan_gap_enabled
||
398 !adapter
->scan_processing
) &&
399 !adapter
->data_sent
&&
400 !skb_queue_empty(&adapter
->tx_data_q
)) {
401 mwifiex_process_tx_queue(adapter
);
402 if (adapter
->hs_activated
) {
403 adapter
->is_hs_configured
= false;
404 mwifiex_hs_activated_event
406 (adapter
, MWIFIEX_BSS_ROLE_ANY
),
411 if ((adapter
->scan_chan_gap_enabled
||
412 !adapter
->scan_processing
) &&
413 !adapter
->data_sent
&&
414 !mwifiex_bypass_txlist_empty(adapter
) &&
415 !mwifiex_is_tdls_chan_switching
416 (mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_STA
))) {
417 mwifiex_process_bypass_tx(adapter
);
418 if (adapter
->hs_activated
) {
419 adapter
->is_hs_configured
= false;
420 mwifiex_hs_activated_event
422 (adapter
, MWIFIEX_BSS_ROLE_ANY
),
427 if ((adapter
->scan_chan_gap_enabled
||
428 !adapter
->scan_processing
) &&
429 !adapter
->data_sent
&& !mwifiex_wmm_lists_empty(adapter
) &&
430 !mwifiex_is_tdls_chan_switching
431 (mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_STA
))) {
432 mwifiex_wmm_process_tx(adapter
);
433 if (adapter
->hs_activated
) {
434 adapter
->is_hs_configured
= false;
435 mwifiex_hs_activated_event
437 (adapter
, MWIFIEX_BSS_ROLE_ANY
),
442 if (adapter
->delay_null_pkt
&& !adapter
->cmd_sent
&&
443 !adapter
->curr_cmd
&& !is_command_pending(adapter
) &&
444 (mwifiex_wmm_lists_empty(adapter
) &&
445 mwifiex_bypass_txlist_empty(adapter
) &&
446 skb_queue_empty(&adapter
->tx_data_q
))) {
447 if (!mwifiex_send_null_packet
448 (mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_STA
),
449 MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET
|
450 MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET
)) {
451 adapter
->delay_null_pkt
= false;
452 adapter
->ps_state
= PS_STATE_SLEEP
;
458 spin_lock_irqsave(&adapter
->main_proc_lock
, flags
);
459 if (adapter
->more_task_flag
) {
460 adapter
->more_task_flag
= false;
461 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
464 adapter
->mwifiex_processing
= false;
465 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
469 EXPORT_SYMBOL_GPL(mwifiex_main_process
);
472 * This function frees the adapter structure.
474 * Additionally, this closes the netlink socket, frees the timers
475 * and private structures.
477 static void mwifiex_free_adapter(struct mwifiex_adapter
*adapter
)
480 pr_err("%s: adapter is NULL\n", __func__
);
484 mwifiex_unregister(adapter
);
485 pr_debug("info: %s: free adapter\n", __func__
);
489 * This function cancels all works in the queue and destroys
490 * the main workqueue.
492 static void mwifiex_terminate_workqueue(struct mwifiex_adapter
*adapter
)
494 if (adapter
->workqueue
) {
495 flush_workqueue(adapter
->workqueue
);
496 destroy_workqueue(adapter
->workqueue
);
497 adapter
->workqueue
= NULL
;
500 if (adapter
->rx_workqueue
) {
501 flush_workqueue(adapter
->rx_workqueue
);
502 destroy_workqueue(adapter
->rx_workqueue
);
503 adapter
->rx_workqueue
= NULL
;
508 * This function gets firmware and initializes it.
510 * The main initialization steps followed are -
511 * - Download the correct firmware to card
512 * - Issue the init commands to firmware
514 static void mwifiex_fw_dpc(const struct firmware
*firmware
, void *context
)
518 struct mwifiex_adapter
*adapter
= context
;
519 struct mwifiex_fw_image fw
;
520 bool init_failed
= false;
521 struct wireless_dev
*wdev
;
522 struct completion
*fw_done
= adapter
->fw_done
;
525 mwifiex_dbg(adapter
, ERROR
,
526 "Failed to get firmware %s\n", adapter
->fw_name
);
530 memset(&fw
, 0, sizeof(struct mwifiex_fw_image
));
531 adapter
->firmware
= firmware
;
532 fw
.fw_buf
= (u8
*) adapter
->firmware
->data
;
533 fw
.fw_len
= adapter
->firmware
->size
;
535 if (adapter
->if_ops
.dnld_fw
) {
536 ret
= adapter
->if_ops
.dnld_fw(adapter
, &fw
);
538 ret
= mwifiex_dnld_fw(adapter
, &fw
);
544 mwifiex_dbg(adapter
, MSG
, "WLAN FW is active\n");
547 if ((request_firmware(&adapter
->cal_data
, cal_data_cfg
,
549 mwifiex_dbg(adapter
, ERROR
,
550 "Cal data request_firmware() failed\n");
553 /* enable host interrupt after fw dnld is successful */
554 if (adapter
->if_ops
.enable_int
) {
555 if (adapter
->if_ops
.enable_int(adapter
))
559 adapter
->init_wait_q_woken
= false;
560 ret
= mwifiex_init_fw(adapter
);
564 adapter
->hw_status
= MWIFIEX_HW_STATUS_READY
;
567 /* Wait for mwifiex_init to complete */
568 if (!adapter
->mfg_mode
) {
569 wait_event_interruptible(adapter
->init_wait_q
,
570 adapter
->init_wait_q_woken
);
571 if (adapter
->hw_status
!= MWIFIEX_HW_STATUS_READY
)
575 if (!adapter
->wiphy
) {
576 if (mwifiex_register_cfg80211(adapter
)) {
577 mwifiex_dbg(adapter
, ERROR
,
578 "cannot register with cfg80211\n");
583 if (mwifiex_init_channel_scan_gap(adapter
)) {
584 mwifiex_dbg(adapter
, ERROR
,
585 "could not init channel stats table\n");
590 driver_mode
&= MWIFIEX_DRIVER_MODE_BITMASK
;
591 driver_mode
|= MWIFIEX_DRIVER_MODE_STA
;
595 /* Create station interface by default */
596 wdev
= mwifiex_add_virtual_intf(adapter
->wiphy
, "mlan%d", NET_NAME_ENUM
,
597 NL80211_IFTYPE_STATION
, NULL
, NULL
);
599 mwifiex_dbg(adapter
, ERROR
,
600 "cannot create default STA interface\n");
605 if (driver_mode
& MWIFIEX_DRIVER_MODE_UAP
) {
606 wdev
= mwifiex_add_virtual_intf(adapter
->wiphy
, "uap%d", NET_NAME_ENUM
,
607 NL80211_IFTYPE_AP
, NULL
, NULL
);
609 mwifiex_dbg(adapter
, ERROR
,
610 "cannot create AP interface\n");
616 if (driver_mode
& MWIFIEX_DRIVER_MODE_P2P
) {
617 wdev
= mwifiex_add_virtual_intf(adapter
->wiphy
, "p2p%d", NET_NAME_ENUM
,
618 NL80211_IFTYPE_P2P_CLIENT
, NULL
,
621 mwifiex_dbg(adapter
, ERROR
,
622 "cannot create p2p client interface\n");
629 mwifiex_drv_get_driver_version(adapter
, fmt
, sizeof(fmt
) - 1);
630 mwifiex_dbg(adapter
, MSG
, "driver_version = %s\n", fmt
);
634 wiphy_unregister(adapter
->wiphy
);
635 wiphy_free(adapter
->wiphy
);
637 if (adapter
->if_ops
.disable_int
)
638 adapter
->if_ops
.disable_int(adapter
);
640 mwifiex_dbg(adapter
, ERROR
,
641 "info: %s: unregister device\n", __func__
);
642 if (adapter
->if_ops
.unregister_dev
)
643 adapter
->if_ops
.unregister_dev(adapter
);
645 adapter
->surprise_removed
= true;
646 mwifiex_terminate_workqueue(adapter
);
648 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_READY
) {
649 pr_debug("info: %s: shutdown mwifiex\n", __func__
);
650 mwifiex_shutdown_drv(adapter
);
655 if (adapter
->cal_data
) {
656 release_firmware(adapter
->cal_data
);
657 adapter
->cal_data
= NULL
;
659 if (adapter
->firmware
) {
660 release_firmware(adapter
->firmware
);
661 adapter
->firmware
= NULL
;
664 mwifiex_free_adapter(adapter
);
665 /* Tell all current and future waiters we're finished */
666 complete_all(fw_done
);
671 * This function initializes the hardware and gets firmware.
673 static int mwifiex_init_hw_fw(struct mwifiex_adapter
*adapter
,
678 /* Override default firmware with manufacturing one if
679 * manufacturing mode is enabled
682 if (strlcpy(adapter
->fw_name
, MFG_FIRMWARE
,
683 sizeof(adapter
->fw_name
)) >=
684 sizeof(adapter
->fw_name
)) {
685 pr_err("%s: fw_name too long!\n", __func__
);
691 ret
= request_firmware_nowait(THIS_MODULE
, 1, adapter
->fw_name
,
692 adapter
->dev
, GFP_KERNEL
, adapter
,
695 mwifiex_dbg(adapter
, ERROR
,
696 "request_firmware_nowait error %d\n", ret
);
698 ret
= request_firmware(&adapter
->firmware
,
702 mwifiex_dbg(adapter
, ERROR
,
703 "request_firmware error %d\n", ret
);
705 mwifiex_fw_dpc(adapter
->firmware
, (void *)adapter
);
712 * CFG802.11 network device handler for open.
714 * Starts the data queue.
717 mwifiex_open(struct net_device
*dev
)
719 netif_carrier_off(dev
);
725 * CFG802.11 network device handler for close.
728 mwifiex_close(struct net_device
*dev
)
730 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
732 if (priv
->scan_request
) {
733 struct cfg80211_scan_info info
= {
737 mwifiex_dbg(priv
->adapter
, INFO
,
738 "aborting scan on ndo_stop\n");
739 cfg80211_scan_done(priv
->scan_request
, &info
);
740 priv
->scan_request
= NULL
;
741 priv
->scan_aborting
= true;
744 if (priv
->sched_scanning
) {
745 mwifiex_dbg(priv
->adapter
, INFO
,
746 "aborting bgscan on ndo_stop\n");
747 mwifiex_stop_bg_scan(priv
);
748 cfg80211_sched_scan_stopped(priv
->wdev
.wiphy
);
755 mwifiex_bypass_tx_queue(struct mwifiex_private
*priv
,
758 struct ethhdr
*eth_hdr
= (struct ethhdr
*)skb
->data
;
760 if (ntohs(eth_hdr
->h_proto
) == ETH_P_PAE
||
761 mwifiex_is_skb_mgmt_frame(skb
) ||
762 (GET_BSS_ROLE(priv
) == MWIFIEX_BSS_ROLE_STA
&&
763 ISSUPP_TDLS_ENABLED(priv
->adapter
->fw_cap_info
) &&
764 (ntohs(eth_hdr
->h_proto
) == ETH_P_TDLS
))) {
765 mwifiex_dbg(priv
->adapter
, DATA
,
766 "bypass txqueue; eth type %#x, mgmt %d\n",
767 ntohs(eth_hdr
->h_proto
),
768 mwifiex_is_skb_mgmt_frame(skb
));
775 * Add buffer into wmm tx queue and queue work to transmit it.
777 int mwifiex_queue_tx_pkt(struct mwifiex_private
*priv
, struct sk_buff
*skb
)
779 struct netdev_queue
*txq
;
780 int index
= mwifiex_1d_to_wmm_queue
[skb
->priority
];
782 if (atomic_inc_return(&priv
->wmm_tx_pending
[index
]) >= MAX_TX_PENDING
) {
783 txq
= netdev_get_tx_queue(priv
->netdev
, index
);
784 if (!netif_tx_queue_stopped(txq
)) {
785 netif_tx_stop_queue(txq
);
786 mwifiex_dbg(priv
->adapter
, DATA
,
787 "stop queue: %d\n", index
);
791 if (mwifiex_bypass_tx_queue(priv
, skb
)) {
792 atomic_inc(&priv
->adapter
->tx_pending
);
793 atomic_inc(&priv
->adapter
->bypass_tx_pending
);
794 mwifiex_wmm_add_buf_bypass_txqueue(priv
, skb
);
796 atomic_inc(&priv
->adapter
->tx_pending
);
797 mwifiex_wmm_add_buf_txqueue(priv
, skb
);
800 mwifiex_queue_main_work(priv
->adapter
);
806 mwifiex_clone_skb_for_tx_status(struct mwifiex_private
*priv
,
807 struct sk_buff
*skb
, u8 flag
, u64
*cookie
)
809 struct sk_buff
*orig_skb
= skb
;
810 struct mwifiex_txinfo
*tx_info
, *orig_tx_info
;
812 skb
= skb_clone(skb
, GFP_ATOMIC
);
817 spin_lock_irqsave(&priv
->ack_status_lock
, flags
);
818 id
= idr_alloc(&priv
->ack_status_frames
, orig_skb
,
819 1, 0x10, GFP_ATOMIC
);
820 spin_unlock_irqrestore(&priv
->ack_status_lock
, flags
);
823 tx_info
= MWIFIEX_SKB_TXCB(skb
);
824 tx_info
->ack_frame_id
= id
;
825 tx_info
->flags
|= flag
;
826 orig_tx_info
= MWIFIEX_SKB_TXCB(orig_skb
);
827 orig_tx_info
->ack_frame_id
= id
;
828 orig_tx_info
->flags
|= flag
;
830 if (flag
== MWIFIEX_BUF_FLAG_ACTION_TX_STATUS
&& cookie
)
831 orig_tx_info
->cookie
= *cookie
;
833 } else if (skb_shared(skb
)) {
840 /* couldn't clone -- lose tx status ... */
848 * CFG802.11 network device handler for data transmission.
851 mwifiex_hard_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
853 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
854 struct sk_buff
*new_skb
;
855 struct mwifiex_txinfo
*tx_info
;
858 mwifiex_dbg(priv
->adapter
, DATA
,
859 "data: %lu BSS(%d-%d): Data <= kernel\n",
860 jiffies
, priv
->bss_type
, priv
->bss_num
);
862 if (priv
->adapter
->surprise_removed
) {
864 priv
->stats
.tx_dropped
++;
867 if (!skb
->len
|| (skb
->len
> ETH_FRAME_LEN
)) {
868 mwifiex_dbg(priv
->adapter
, ERROR
,
869 "Tx: bad skb len %d\n", skb
->len
);
871 priv
->stats
.tx_dropped
++;
874 if (skb_headroom(skb
) < MWIFIEX_MIN_DATA_HEADER_LEN
) {
875 mwifiex_dbg(priv
->adapter
, DATA
,
876 "data: Tx: insufficient skb headroom %d\n",
878 /* Insufficient skb headroom - allocate a new skb */
880 skb_realloc_headroom(skb
, MWIFIEX_MIN_DATA_HEADER_LEN
);
881 if (unlikely(!new_skb
)) {
882 mwifiex_dbg(priv
->adapter
, ERROR
,
883 "Tx: cannot alloca new_skb\n");
885 priv
->stats
.tx_dropped
++;
890 mwifiex_dbg(priv
->adapter
, INFO
,
891 "info: new skb headroomd %d\n",
895 tx_info
= MWIFIEX_SKB_TXCB(skb
);
896 memset(tx_info
, 0, sizeof(*tx_info
));
897 tx_info
->bss_num
= priv
->bss_num
;
898 tx_info
->bss_type
= priv
->bss_type
;
899 tx_info
->pkt_len
= skb
->len
;
901 multicast
= is_multicast_ether_addr(skb
->data
);
903 if (unlikely(!multicast
&& skb
->sk
&&
904 skb_shinfo(skb
)->tx_flags
& SKBTX_WIFI_STATUS
&&
905 priv
->adapter
->fw_api_ver
== MWIFIEX_FW_V15
))
906 skb
= mwifiex_clone_skb_for_tx_status(priv
,
908 MWIFIEX_BUF_FLAG_EAPOL_TX_STATUS
, NULL
);
910 /* Record the current time the packet was queued; used to
911 * determine the amount of time the packet was queued in
912 * the driver before it was sent to the firmware.
913 * The delay is then sent along with the packet to the
914 * firmware for aggregate delay calculation for stats and
915 * MSDU lifetime expiry.
917 __net_timestamp(skb
);
919 if (ISSUPP_TDLS_ENABLED(priv
->adapter
->fw_cap_info
) &&
920 priv
->bss_type
== MWIFIEX_BSS_TYPE_STA
&&
921 !ether_addr_equal_unaligned(priv
->cfg_bssid
, skb
->data
)) {
922 if (priv
->adapter
->auto_tdls
&& priv
->check_tdls_tx
)
923 mwifiex_tdls_check_tx(priv
, skb
);
926 mwifiex_queue_tx_pkt(priv
, skb
);
932 * CFG802.11 network device handler for setting MAC address.
935 mwifiex_set_mac_address(struct net_device
*dev
, void *addr
)
937 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
938 struct sockaddr
*hw_addr
= addr
;
941 memcpy(priv
->curr_addr
, hw_addr
->sa_data
, ETH_ALEN
);
943 /* Send request to firmware */
944 ret
= mwifiex_send_cmd(priv
, HostCmd_CMD_802_11_MAC_ADDRESS
,
945 HostCmd_ACT_GEN_SET
, 0, NULL
, true);
948 memcpy(priv
->netdev
->dev_addr
, priv
->curr_addr
, ETH_ALEN
);
950 mwifiex_dbg(priv
->adapter
, ERROR
,
951 "set mac address failed: ret=%d\n", ret
);
953 memcpy(dev
->dev_addr
, priv
->curr_addr
, ETH_ALEN
);
959 * CFG802.11 network device handler for setting multicast list.
961 static void mwifiex_set_multicast_list(struct net_device
*dev
)
963 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
964 struct mwifiex_multicast_list mcast_list
;
966 if (dev
->flags
& IFF_PROMISC
) {
967 mcast_list
.mode
= MWIFIEX_PROMISC_MODE
;
968 } else if (dev
->flags
& IFF_ALLMULTI
||
969 netdev_mc_count(dev
) > MWIFIEX_MAX_MULTICAST_LIST_SIZE
) {
970 mcast_list
.mode
= MWIFIEX_ALL_MULTI_MODE
;
972 mcast_list
.mode
= MWIFIEX_MULTICAST_MODE
;
973 mcast_list
.num_multicast_addr
=
974 mwifiex_copy_mcast_addr(&mcast_list
, dev
);
976 mwifiex_request_set_multicast_list(priv
, &mcast_list
);
980 * CFG802.11 network device handler for transmission timeout.
983 mwifiex_tx_timeout(struct net_device
*dev
)
985 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
987 priv
->num_tx_timeout
++;
988 priv
->tx_timeout_cnt
++;
989 mwifiex_dbg(priv
->adapter
, ERROR
,
990 "%lu : Tx timeout(#%d), bss_type-num = %d-%d\n",
991 jiffies
, priv
->tx_timeout_cnt
, priv
->bss_type
,
993 mwifiex_set_trans_start(dev
);
995 if (priv
->tx_timeout_cnt
> TX_TIMEOUT_THRESHOLD
&&
996 priv
->adapter
->if_ops
.card_reset
) {
997 mwifiex_dbg(priv
->adapter
, ERROR
,
998 "tx_timeout_cnt exceeds threshold.\t"
999 "Triggering card reset!\n");
1000 priv
->adapter
->if_ops
.card_reset(priv
->adapter
);
1004 void mwifiex_multi_chan_resync(struct mwifiex_adapter
*adapter
)
1006 struct usb_card_rec
*card
= adapter
->card
;
1007 struct mwifiex_private
*priv
;
1011 card
->mc_resync_flag
= true;
1012 for (i
= 0; i
< MWIFIEX_TX_DATA_PORT
; i
++) {
1013 if (atomic_read(&card
->port
[i
].tx_data_urb_pending
)) {
1014 mwifiex_dbg(adapter
, WARN
, "pending data urb in sys\n");
1019 card
->mc_resync_flag
= false;
1020 tx_buf_size
= 0xffff;
1021 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
1022 ret
= mwifiex_send_cmd(priv
, HostCmd_CMD_RECONFIGURE_TX_BUFF
,
1023 HostCmd_ACT_GEN_SET
, 0, &tx_buf_size
, false);
1025 mwifiex_dbg(adapter
, ERROR
,
1026 "send reconfig tx buf size cmd err\n");
1028 EXPORT_SYMBOL_GPL(mwifiex_multi_chan_resync
);
1030 int mwifiex_drv_info_dump(struct mwifiex_adapter
*adapter
, void **drv_info
)
1033 char drv_version
[64];
1034 struct usb_card_rec
*cardp
;
1035 struct sdio_mmc_card
*sdio_card
;
1036 struct mwifiex_private
*priv
;
1038 struct netdev_queue
*txq
;
1039 struct mwifiex_debug_info
*debug_info
;
1040 void *drv_info_dump
;
1042 mwifiex_dbg(adapter
, MSG
, "===mwifiex driverinfo dump start===\n");
1044 /* memory allocate here should be free in mwifiex_upload_device_dump*/
1045 drv_info_dump
= vzalloc(MWIFIEX_DRV_INFO_SIZE_MAX
);
1050 p
= (char *)(drv_info_dump
);
1051 p
+= sprintf(p
, "driver_name = " "\"mwifiex\"\n");
1053 mwifiex_drv_get_driver_version(adapter
, drv_version
,
1054 sizeof(drv_version
) - 1);
1055 p
+= sprintf(p
, "driver_version = %s\n", drv_version
);
1057 if (adapter
->iface_type
== MWIFIEX_USB
) {
1058 cardp
= (struct usb_card_rec
*)adapter
->card
;
1059 p
+= sprintf(p
, "tx_cmd_urb_pending = %d\n",
1060 atomic_read(&cardp
->tx_cmd_urb_pending
));
1061 p
+= sprintf(p
, "tx_data_urb_pending_port_0 = %d\n",
1062 atomic_read(&cardp
->port
[0].tx_data_urb_pending
));
1063 p
+= sprintf(p
, "tx_data_urb_pending_port_1 = %d\n",
1064 atomic_read(&cardp
->port
[1].tx_data_urb_pending
));
1065 p
+= sprintf(p
, "rx_cmd_urb_pending = %d\n",
1066 atomic_read(&cardp
->rx_cmd_urb_pending
));
1067 p
+= sprintf(p
, "rx_data_urb_pending = %d\n",
1068 atomic_read(&cardp
->rx_data_urb_pending
));
1071 p
+= sprintf(p
, "tx_pending = %d\n",
1072 atomic_read(&adapter
->tx_pending
));
1073 p
+= sprintf(p
, "rx_pending = %d\n",
1074 atomic_read(&adapter
->rx_pending
));
1076 if (adapter
->iface_type
== MWIFIEX_SDIO
) {
1077 sdio_card
= (struct sdio_mmc_card
*)adapter
->card
;
1078 p
+= sprintf(p
, "\nmp_rd_bitmap=0x%x curr_rd_port=0x%x\n",
1079 sdio_card
->mp_rd_bitmap
, sdio_card
->curr_rd_port
);
1080 p
+= sprintf(p
, "mp_wr_bitmap=0x%x curr_wr_port=0x%x\n",
1081 sdio_card
->mp_wr_bitmap
, sdio_card
->curr_wr_port
);
1084 for (i
= 0; i
< adapter
->priv_num
; i
++) {
1085 if (!adapter
->priv
[i
] || !adapter
->priv
[i
]->netdev
)
1087 priv
= adapter
->priv
[i
];
1088 p
+= sprintf(p
, "\n[interface : \"%s\"]\n",
1089 priv
->netdev
->name
);
1090 p
+= sprintf(p
, "wmm_tx_pending[0] = %d\n",
1091 atomic_read(&priv
->wmm_tx_pending
[0]));
1092 p
+= sprintf(p
, "wmm_tx_pending[1] = %d\n",
1093 atomic_read(&priv
->wmm_tx_pending
[1]));
1094 p
+= sprintf(p
, "wmm_tx_pending[2] = %d\n",
1095 atomic_read(&priv
->wmm_tx_pending
[2]));
1096 p
+= sprintf(p
, "wmm_tx_pending[3] = %d\n",
1097 atomic_read(&priv
->wmm_tx_pending
[3]));
1098 p
+= sprintf(p
, "media_state=\"%s\"\n", !priv
->media_connected
?
1099 "Disconnected" : "Connected");
1100 p
+= sprintf(p
, "carrier %s\n", (netif_carrier_ok(priv
->netdev
)
1102 for (idx
= 0; idx
< priv
->netdev
->num_tx_queues
; idx
++) {
1103 txq
= netdev_get_tx_queue(priv
->netdev
, idx
);
1104 p
+= sprintf(p
, "tx queue %d:%s ", idx
,
1105 netif_tx_queue_stopped(txq
) ?
1106 "stopped" : "started");
1108 p
+= sprintf(p
, "\n%s: num_tx_timeout = %d\n",
1109 priv
->netdev
->name
, priv
->num_tx_timeout
);
1112 if (adapter
->iface_type
== MWIFIEX_SDIO
||
1113 adapter
->iface_type
== MWIFIEX_PCIE
) {
1114 p
+= sprintf(p
, "\n=== %s register dump===\n",
1115 adapter
->iface_type
== MWIFIEX_SDIO
?
1117 if (adapter
->if_ops
.reg_dump
)
1118 p
+= adapter
->if_ops
.reg_dump(adapter
, p
);
1120 p
+= sprintf(p
, "\n=== more debug information\n");
1121 debug_info
= kzalloc(sizeof(*debug_info
), GFP_KERNEL
);
1123 for (i
= 0; i
< adapter
->priv_num
; i
++) {
1124 if (!adapter
->priv
[i
] || !adapter
->priv
[i
]->netdev
)
1126 priv
= adapter
->priv
[i
];
1127 mwifiex_get_debug_info(priv
, debug_info
);
1128 p
+= mwifiex_debug_info_to_buffer(priv
, p
, debug_info
);
1134 mwifiex_dbg(adapter
, MSG
, "===mwifiex driverinfo dump end===\n");
1135 *drv_info
= drv_info_dump
;
1136 return p
- drv_info_dump
;
1138 EXPORT_SYMBOL_GPL(mwifiex_drv_info_dump
);
1140 void mwifiex_upload_device_dump(struct mwifiex_adapter
*adapter
, void *drv_info
,
1143 u8 idx
, *dump_data
, *fw_dump_ptr
;
1146 dump_len
= (strlen("========Start dump driverinfo========\n") +
1148 strlen("\n========End dump========\n"));
1150 for (idx
= 0; idx
< adapter
->num_mem_types
; idx
++) {
1151 struct memory_type_mapping
*entry
=
1152 &adapter
->mem_type_mapping_tbl
[idx
];
1154 if (entry
->mem_ptr
) {
1155 dump_len
+= (strlen("========Start dump ") +
1156 strlen(entry
->mem_name
) +
1157 strlen("========\n") +
1158 (entry
->mem_size
+ 1) +
1159 strlen("\n========End dump========\n"));
1163 dump_data
= vzalloc(dump_len
+ 1);
1167 fw_dump_ptr
= dump_data
;
1169 /* Dump all the memory data into single file, a userspace script will
1170 * be used to split all the memory data to multiple files
1172 mwifiex_dbg(adapter
, MSG
,
1173 "== mwifiex dump information to /sys/class/devcoredump start");
1175 strcpy(fw_dump_ptr
, "========Start dump driverinfo========\n");
1176 fw_dump_ptr
+= strlen("========Start dump driverinfo========\n");
1177 memcpy(fw_dump_ptr
, drv_info
, drv_info_size
);
1178 fw_dump_ptr
+= drv_info_size
;
1179 strcpy(fw_dump_ptr
, "\n========End dump========\n");
1180 fw_dump_ptr
+= strlen("\n========End dump========\n");
1182 for (idx
= 0; idx
< adapter
->num_mem_types
; idx
++) {
1183 struct memory_type_mapping
*entry
=
1184 &adapter
->mem_type_mapping_tbl
[idx
];
1186 if (entry
->mem_ptr
) {
1187 strcpy(fw_dump_ptr
, "========Start dump ");
1188 fw_dump_ptr
+= strlen("========Start dump ");
1190 strcpy(fw_dump_ptr
, entry
->mem_name
);
1191 fw_dump_ptr
+= strlen(entry
->mem_name
);
1193 strcpy(fw_dump_ptr
, "========\n");
1194 fw_dump_ptr
+= strlen("========\n");
1196 memcpy(fw_dump_ptr
, entry
->mem_ptr
, entry
->mem_size
);
1197 fw_dump_ptr
+= entry
->mem_size
;
1199 strcpy(fw_dump_ptr
, "\n========End dump========\n");
1200 fw_dump_ptr
+= strlen("\n========End dump========\n");
1204 /* device dump data will be free in device coredump release function
1207 dev_coredumpv(adapter
->dev
, dump_data
, dump_len
, GFP_KERNEL
);
1208 mwifiex_dbg(adapter
, MSG
,
1209 "== mwifiex dump information to /sys/class/devcoredump end");
1212 for (idx
= 0; idx
< adapter
->num_mem_types
; idx
++) {
1213 struct memory_type_mapping
*entry
=
1214 &adapter
->mem_type_mapping_tbl
[idx
];
1216 vfree(entry
->mem_ptr
);
1217 entry
->mem_ptr
= NULL
;
1218 entry
->mem_size
= 0;
1223 EXPORT_SYMBOL_GPL(mwifiex_upload_device_dump
);
1226 * CFG802.11 network device handler for statistics retrieval.
1228 static struct net_device_stats
*mwifiex_get_stats(struct net_device
*dev
)
1230 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
1232 return &priv
->stats
;
1236 mwifiex_netdev_select_wmm_queue(struct net_device
*dev
, struct sk_buff
*skb
,
1237 void *accel_priv
, select_queue_fallback_t fallback
)
1239 skb
->priority
= cfg80211_classify8021d(skb
, NULL
);
1240 return mwifiex_1d_to_wmm_queue
[skb
->priority
];
1243 /* Network device handlers */
1244 static const struct net_device_ops mwifiex_netdev_ops
= {
1245 .ndo_open
= mwifiex_open
,
1246 .ndo_stop
= mwifiex_close
,
1247 .ndo_start_xmit
= mwifiex_hard_start_xmit
,
1248 .ndo_set_mac_address
= mwifiex_set_mac_address
,
1249 .ndo_validate_addr
= eth_validate_addr
,
1250 .ndo_tx_timeout
= mwifiex_tx_timeout
,
1251 .ndo_get_stats
= mwifiex_get_stats
,
1252 .ndo_set_rx_mode
= mwifiex_set_multicast_list
,
1253 .ndo_select_queue
= mwifiex_netdev_select_wmm_queue
,
1257 * This function initializes the private structure parameters.
1259 * The following wait queues are initialized -
1260 * - IOCTL wait queue
1261 * - Command wait queue
1262 * - Statistics wait queue
1264 * ...and the following default parameters are set -
1265 * - Current key index : Set to 0
1266 * - Rate index : Set to auto
1267 * - Media connected : Set to disconnected
1268 * - Adhoc link sensed : Set to false
1269 * - Nick name : Set to null
1270 * - Number of Tx timeout : Set to 0
1271 * - Device address : Set to current address
1272 * - Rx histogram statistc : Set to 0
1274 * In addition, the CFG80211 work queue is also created.
1276 void mwifiex_init_priv_params(struct mwifiex_private
*priv
,
1277 struct net_device
*dev
)
1279 dev
->netdev_ops
= &mwifiex_netdev_ops
;
1280 dev
->destructor
= free_netdev
;
1281 /* Initialize private structure */
1282 priv
->current_key_index
= 0;
1283 priv
->media_connected
= false;
1284 memset(priv
->mgmt_ie
, 0,
1285 sizeof(struct mwifiex_ie
) * MAX_MGMT_IE_INDEX
);
1286 priv
->beacon_idx
= MWIFIEX_AUTO_IDX_MASK
;
1287 priv
->proberesp_idx
= MWIFIEX_AUTO_IDX_MASK
;
1288 priv
->assocresp_idx
= MWIFIEX_AUTO_IDX_MASK
;
1289 priv
->gen_idx
= MWIFIEX_AUTO_IDX_MASK
;
1290 priv
->num_tx_timeout
= 0;
1291 ether_addr_copy(priv
->curr_addr
, priv
->adapter
->perm_addr
);
1292 memcpy(dev
->dev_addr
, priv
->curr_addr
, ETH_ALEN
);
1294 if (GET_BSS_ROLE(priv
) == MWIFIEX_BSS_ROLE_STA
||
1295 GET_BSS_ROLE(priv
) == MWIFIEX_BSS_ROLE_UAP
) {
1296 priv
->hist_data
= kmalloc(sizeof(*priv
->hist_data
), GFP_KERNEL
);
1297 if (priv
->hist_data
)
1298 mwifiex_hist_data_reset(priv
);
1303 * This function check if command is pending.
1305 int is_command_pending(struct mwifiex_adapter
*adapter
)
1307 unsigned long flags
;
1308 int is_cmd_pend_q_empty
;
1310 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, flags
);
1311 is_cmd_pend_q_empty
= list_empty(&adapter
->cmd_pending_q
);
1312 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
, flags
);
1314 return !is_cmd_pend_q_empty
;
1318 * This is the RX work queue function.
1320 * It handles the RX operations.
1322 static void mwifiex_rx_work_queue(struct work_struct
*work
)
1324 struct mwifiex_adapter
*adapter
=
1325 container_of(work
, struct mwifiex_adapter
, rx_work
);
1327 if (adapter
->surprise_removed
)
1329 mwifiex_process_rx(adapter
);
1333 * This is the main work queue function.
1335 * It handles the main process, which in turn handles the complete
1336 * driver operations.
1338 static void mwifiex_main_work_queue(struct work_struct
*work
)
1340 struct mwifiex_adapter
*adapter
=
1341 container_of(work
, struct mwifiex_adapter
, main_work
);
1343 if (adapter
->surprise_removed
)
1345 mwifiex_main_process(adapter
);
1349 * This function gets called during PCIe function level reset. Required
1350 * code is extracted from mwifiex_remove_card()
1353 mwifiex_shutdown_sw(struct mwifiex_adapter
*adapter
)
1355 struct mwifiex_private
*priv
;
1361 wait_for_completion(adapter
->fw_done
);
1362 /* Caller should ensure we aren't suspending while this happens */
1363 reinit_completion(adapter
->fw_done
);
1365 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
1366 mwifiex_deauthenticate(priv
, NULL
);
1368 /* We can no longer handle interrupts once we start doing the teardown
1371 if (adapter
->if_ops
.disable_int
)
1372 adapter
->if_ops
.disable_int(adapter
);
1374 adapter
->surprise_removed
= true;
1375 mwifiex_terminate_workqueue(adapter
);
1378 for (i
= 0; i
< adapter
->priv_num
; i
++) {
1379 priv
= adapter
->priv
[i
];
1380 if (priv
&& priv
->netdev
) {
1381 mwifiex_stop_net_dev_queue(priv
->netdev
, adapter
);
1382 if (netif_carrier_ok(priv
->netdev
))
1383 netif_carrier_off(priv
->netdev
);
1384 netif_device_detach(priv
->netdev
);
1388 mwifiex_dbg(adapter
, CMD
, "cmd: calling mwifiex_shutdown_drv...\n");
1390 mwifiex_shutdown_drv(adapter
);
1391 if (adapter
->if_ops
.down_dev
)
1392 adapter
->if_ops
.down_dev(adapter
);
1394 mwifiex_dbg(adapter
, CMD
, "cmd: mwifiex_shutdown_drv done\n");
1395 if (atomic_read(&adapter
->rx_pending
) ||
1396 atomic_read(&adapter
->tx_pending
) ||
1397 atomic_read(&adapter
->cmd_pending
)) {
1398 mwifiex_dbg(adapter
, ERROR
,
1399 "rx_pending=%d, tx_pending=%d,\t"
1401 atomic_read(&adapter
->rx_pending
),
1402 atomic_read(&adapter
->tx_pending
),
1403 atomic_read(&adapter
->cmd_pending
));
1406 for (i
= 0; i
< adapter
->priv_num
; i
++) {
1407 priv
= adapter
->priv
[i
];
1412 priv
->wdev
.iftype
!= NL80211_IFTYPE_UNSPECIFIED
)
1413 mwifiex_del_virtual_intf(adapter
->wiphy
, &priv
->wdev
);
1417 mwifiex_dbg(adapter
, INFO
, "%s, successful\n", __func__
);
1421 EXPORT_SYMBOL_GPL(mwifiex_shutdown_sw
);
1423 /* This function gets called during PCIe function level reset. Required
1424 * code is extracted from mwifiex_add_card()
1427 mwifiex_reinit_sw(struct mwifiex_adapter
*adapter
)
1429 mwifiex_init_lock_list(adapter
);
1430 if (adapter
->if_ops
.up_dev
)
1431 adapter
->if_ops
.up_dev(adapter
);
1433 adapter
->hw_status
= MWIFIEX_HW_STATUS_INITIALIZING
;
1434 adapter
->surprise_removed
= false;
1435 init_waitqueue_head(&adapter
->init_wait_q
);
1436 adapter
->is_suspended
= false;
1437 adapter
->hs_activated
= false;
1438 init_waitqueue_head(&adapter
->hs_activate_wait_q
);
1439 init_waitqueue_head(&adapter
->cmd_wait_q
.wait
);
1440 adapter
->cmd_wait_q
.status
= 0;
1441 adapter
->scan_wait_q_woken
= false;
1443 if ((num_possible_cpus() > 1) || adapter
->iface_type
== MWIFIEX_USB
)
1444 adapter
->rx_work_enabled
= true;
1446 adapter
->workqueue
=
1447 alloc_workqueue("MWIFIEX_WORK_QUEUE",
1448 WQ_HIGHPRI
| WQ_MEM_RECLAIM
| WQ_UNBOUND
, 1);
1449 if (!adapter
->workqueue
)
1452 INIT_WORK(&adapter
->main_work
, mwifiex_main_work_queue
);
1454 if (adapter
->rx_work_enabled
) {
1455 adapter
->rx_workqueue
= alloc_workqueue("MWIFIEX_RX_WORK_QUEUE",
1459 if (!adapter
->rx_workqueue
)
1461 INIT_WORK(&adapter
->rx_work
, mwifiex_rx_work_queue
);
1464 /* Register the device. Fill up the private data structure with
1465 * relevant information from the card. Some code extracted from
1466 * mwifiex_register_dev()
1468 mwifiex_dbg(adapter
, INFO
, "%s, mwifiex_init_hw_fw()...\n", __func__
);
1470 if (mwifiex_init_hw_fw(adapter
, false)) {
1471 mwifiex_dbg(adapter
, ERROR
,
1472 "%s: firmware init failed\n", __func__
);
1475 mwifiex_dbg(adapter
, INFO
, "%s, successful\n", __func__
);
1477 complete_all(adapter
->fw_done
);
1481 mwifiex_dbg(adapter
, ERROR
, "info: %s: unregister device\n", __func__
);
1482 if (adapter
->if_ops
.unregister_dev
)
1483 adapter
->if_ops
.unregister_dev(adapter
);
1486 adapter
->surprise_removed
= true;
1487 mwifiex_terminate_workqueue(adapter
);
1488 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_READY
) {
1489 mwifiex_dbg(adapter
, ERROR
,
1490 "info: %s: shutdown mwifiex\n", __func__
);
1491 mwifiex_shutdown_drv(adapter
);
1494 complete_all(adapter
->fw_done
);
1495 mwifiex_dbg(adapter
, INFO
, "%s, error\n", __func__
);
1499 EXPORT_SYMBOL_GPL(mwifiex_reinit_sw
);
1501 static irqreturn_t
mwifiex_irq_wakeup_handler(int irq
, void *priv
)
1503 struct mwifiex_adapter
*adapter
= priv
;
1505 if (adapter
->irq_wakeup
>= 0) {
1506 dev_dbg(adapter
->dev
, "%s: wake by wifi", __func__
);
1507 adapter
->wake_by_wifi
= true;
1508 disable_irq_nosync(irq
);
1511 /* Notify PM core we are wakeup source */
1512 pm_wakeup_event(adapter
->dev
, 0);
1517 static void mwifiex_probe_of(struct mwifiex_adapter
*adapter
)
1520 struct device
*dev
= adapter
->dev
;
1525 adapter
->dt_node
= dev
->of_node
;
1526 adapter
->irq_wakeup
= irq_of_parse_and_map(adapter
->dt_node
, 0);
1527 if (!adapter
->irq_wakeup
) {
1528 dev_dbg(dev
, "fail to parse irq_wakeup from device tree\n");
1532 ret
= devm_request_irq(dev
, adapter
->irq_wakeup
,
1533 mwifiex_irq_wakeup_handler
, IRQF_TRIGGER_LOW
,
1534 "wifi_wake", adapter
);
1536 dev_err(dev
, "Failed to request irq_wakeup %d (%d)\n",
1537 adapter
->irq_wakeup
, ret
);
1541 disable_irq(adapter
->irq_wakeup
);
1542 if (device_init_wakeup(dev
, true)) {
1543 dev_err(dev
, "fail to init wakeup for mwifiex\n");
1549 adapter
->irq_wakeup
= -1;
1553 * This function adds the card.
1555 * This function follows the following major steps to set up the device -
1556 * - Initialize software. This includes probing the card, registering
1557 * the interface operations table, and allocating/initializing the
1559 * - Set up the netlink socket
1560 * - Create and start the main work queue
1561 * - Register the device
1562 * - Initialize firmware and hardware
1563 * - Add logical interfaces
1566 mwifiex_add_card(void *card
, struct completion
*fw_done
,
1567 struct mwifiex_if_ops
*if_ops
, u8 iface_type
,
1570 struct mwifiex_adapter
*adapter
;
1572 if (mwifiex_register(card
, dev
, if_ops
, (void **)&adapter
)) {
1573 pr_err("%s: software init failed\n", __func__
);
1577 mwifiex_probe_of(adapter
);
1579 adapter
->iface_type
= iface_type
;
1580 adapter
->fw_done
= fw_done
;
1582 adapter
->hw_status
= MWIFIEX_HW_STATUS_INITIALIZING
;
1583 adapter
->surprise_removed
= false;
1584 init_waitqueue_head(&adapter
->init_wait_q
);
1585 adapter
->is_suspended
= false;
1586 adapter
->hs_activated
= false;
1587 init_waitqueue_head(&adapter
->hs_activate_wait_q
);
1588 init_waitqueue_head(&adapter
->cmd_wait_q
.wait
);
1589 adapter
->cmd_wait_q
.status
= 0;
1590 adapter
->scan_wait_q_woken
= false;
1592 if ((num_possible_cpus() > 1) || adapter
->iface_type
== MWIFIEX_USB
) {
1593 adapter
->rx_work_enabled
= true;
1594 pr_notice("rx work enabled, cpus %d\n", num_possible_cpus());
1597 adapter
->workqueue
=
1598 alloc_workqueue("MWIFIEX_WORK_QUEUE",
1599 WQ_HIGHPRI
| WQ_MEM_RECLAIM
| WQ_UNBOUND
, 1);
1600 if (!adapter
->workqueue
)
1603 INIT_WORK(&adapter
->main_work
, mwifiex_main_work_queue
);
1605 if (adapter
->rx_work_enabled
) {
1606 adapter
->rx_workqueue
= alloc_workqueue("MWIFIEX_RX_WORK_QUEUE",
1610 if (!adapter
->rx_workqueue
)
1613 INIT_WORK(&adapter
->rx_work
, mwifiex_rx_work_queue
);
1616 /* Register the device. Fill up the private data structure with relevant
1617 information from the card. */
1618 if (adapter
->if_ops
.register_dev(adapter
)) {
1619 pr_err("%s: failed to register mwifiex device\n", __func__
);
1620 goto err_registerdev
;
1623 if (mwifiex_init_hw_fw(adapter
, true)) {
1624 pr_err("%s: firmware init failed\n", __func__
);
1631 pr_debug("info: %s: unregister device\n", __func__
);
1632 if (adapter
->if_ops
.unregister_dev
)
1633 adapter
->if_ops
.unregister_dev(adapter
);
1635 adapter
->surprise_removed
= true;
1636 mwifiex_terminate_workqueue(adapter
);
1637 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_READY
) {
1638 pr_debug("info: %s: shutdown mwifiex\n", __func__
);
1639 mwifiex_shutdown_drv(adapter
);
1642 mwifiex_free_adapter(adapter
);
1648 EXPORT_SYMBOL_GPL(mwifiex_add_card
);
1651 * This function removes the card.
1653 * This function follows the following major steps to remove the device -
1654 * - Stop data traffic
1655 * - Shutdown firmware
1656 * - Remove the logical interfaces
1657 * - Terminate the work queue
1658 * - Unregister the device
1659 * - Free the adapter structure
1661 int mwifiex_remove_card(struct mwifiex_adapter
*adapter
)
1663 struct mwifiex_private
*priv
= NULL
;
1669 /* We can no longer handle interrupts once we start doing the teardown
1671 if (adapter
->if_ops
.disable_int
)
1672 adapter
->if_ops
.disable_int(adapter
);
1674 adapter
->surprise_removed
= true;
1676 mwifiex_terminate_workqueue(adapter
);
1679 for (i
= 0; i
< adapter
->priv_num
; i
++) {
1680 priv
= adapter
->priv
[i
];
1681 if (priv
&& priv
->netdev
) {
1682 mwifiex_stop_net_dev_queue(priv
->netdev
, adapter
);
1683 if (netif_carrier_ok(priv
->netdev
))
1684 netif_carrier_off(priv
->netdev
);
1688 mwifiex_dbg(adapter
, CMD
,
1689 "cmd: calling mwifiex_shutdown_drv...\n");
1691 mwifiex_shutdown_drv(adapter
);
1692 mwifiex_dbg(adapter
, CMD
,
1693 "cmd: mwifiex_shutdown_drv done\n");
1694 if (atomic_read(&adapter
->rx_pending
) ||
1695 atomic_read(&adapter
->tx_pending
) ||
1696 atomic_read(&adapter
->cmd_pending
)) {
1697 mwifiex_dbg(adapter
, ERROR
,
1698 "rx_pending=%d, tx_pending=%d,\t"
1700 atomic_read(&adapter
->rx_pending
),
1701 atomic_read(&adapter
->tx_pending
),
1702 atomic_read(&adapter
->cmd_pending
));
1705 for (i
= 0; i
< adapter
->priv_num
; i
++) {
1706 priv
= adapter
->priv
[i
];
1713 priv
->wdev
.iftype
!= NL80211_IFTYPE_UNSPECIFIED
)
1714 mwifiex_del_virtual_intf(adapter
->wiphy
, &priv
->wdev
);
1718 wiphy_unregister(adapter
->wiphy
);
1719 wiphy_free(adapter
->wiphy
);
1721 if (adapter
->irq_wakeup
>= 0)
1722 device_init_wakeup(adapter
->dev
, false);
1724 /* Unregister device */
1725 mwifiex_dbg(adapter
, INFO
,
1726 "info: unregister device\n");
1727 if (adapter
->if_ops
.unregister_dev
)
1728 adapter
->if_ops
.unregister_dev(adapter
);
1729 /* Free adapter structure */
1730 mwifiex_dbg(adapter
, INFO
,
1731 "info: free adapter\n");
1732 mwifiex_free_adapter(adapter
);
1737 EXPORT_SYMBOL_GPL(mwifiex_remove_card
);
1739 void _mwifiex_dbg(const struct mwifiex_adapter
*adapter
, int mask
,
1740 const char *fmt
, ...)
1742 struct va_format vaf
;
1745 if (!adapter
->dev
|| !(adapter
->debug_mask
& mask
))
1748 va_start(args
, fmt
);
1753 dev_info(adapter
->dev
, "%pV", &vaf
);
1757 EXPORT_SYMBOL_GPL(_mwifiex_dbg
);
1760 * This function initializes the module.
1762 * The debug FS is also initialized if configured.
1765 mwifiex_init_module(void)
1767 #ifdef CONFIG_DEBUG_FS
1768 mwifiex_debugfs_init();
1774 * This function cleans up the module.
1776 * The debug FS is removed if available.
1779 mwifiex_cleanup_module(void)
1781 #ifdef CONFIG_DEBUG_FS
1782 mwifiex_debugfs_remove();
1786 module_init(mwifiex_init_module
);
1787 module_exit(mwifiex_cleanup_module
);
1789 MODULE_AUTHOR("Marvell International Ltd.");
1790 MODULE_DESCRIPTION("Marvell WiFi-Ex Driver version " VERSION
);
1791 MODULE_VERSION(VERSION
);
1792 MODULE_LICENSE("GPL v2");