1 // SPDX-License-Identifier: GPL-2.0-only
3 * NXP Wireless LAN device driver: major functions
5 * Copyright 2011-2020 NXP
8 #include <linux/suspend.h>
16 #define MFG_FIRMWARE "mwifiex_mfg.bin"
18 static unsigned int debug_mask = MWIFIEX_DEFAULT_DEBUG_MASK;
19 module_param(debug_mask, uint, 0);
20 MODULE_PARM_DESC(debug_mask, "bitmap for debug flags");
22 const char driver_version[] = "mwifiex " VERSION " (%s) ";
23 static char *cal_data_cfg;
24 module_param(cal_data_cfg, charp, 0);
26 static unsigned short driver_mode;
27 module_param(driver_mode, ushort, 0);
28 MODULE_PARM_DESC(driver_mode,
29 "station=0x1(default), ap-sta=0x3, station-p2p=0x5, ap-sta-p2p=0x7");
32 module_param(mfg_mode, bool, 0);
33 MODULE_PARM_DESC(mfg_mode, "manufacturing mode enable:1, disable:0");
36 module_param(aggr_ctrl, bool, 0000);
37 MODULE_PARM_DESC(aggr_ctrl, "usb tx aggregation enable:1, disable:0");
39 const u16 mwifiex_1d_to_wmm_queue[8] = { 1, 0, 0, 1, 2, 2, 3, 3 };
42 * This function registers the device and performs all the necessary
45 * The following initialization operations are performed -
46 * - Allocate adapter structure
47 * - Save interface specific operations table in adapter
48 * - Call interface specific initialization routine
49 * - Allocate private structures
50 * - Set default adapter structure parameters
53 * In case of any errors during inittialization, this function also ensures
54 * proper cleanup before exiting.
56 static int mwifiex_register(void *card, struct device *dev,
57 struct mwifiex_if_ops *if_ops, void **padapter)
59 struct mwifiex_adapter *adapter;
62 adapter = kzalloc(sizeof(struct mwifiex_adapter), GFP_KERNEL);
70 /* Save interface specific operations in adapter */
71 memmove(&adapter->if_ops, if_ops, sizeof(struct mwifiex_if_ops));
72 adapter->debug_mask = debug_mask;
74 /* card specific initialization has been deferred until now .. */
75 if (adapter->if_ops.init_if)
76 if (adapter->if_ops.init_if(adapter))
79 adapter->priv_num = 0;
81 for (i = 0; i < MWIFIEX_MAX_BSS_NUM; i++) {
82 /* Allocate memory for private structure */
84 kzalloc(sizeof(struct mwifiex_private), GFP_KERNEL);
85 if (!adapter->priv[i])
88 adapter->priv[i]->adapter = adapter;
91 mwifiex_init_lock_list(adapter);
93 timer_setup(&adapter->cmd_timer, mwifiex_cmd_timeout_func, 0);
98 mwifiex_dbg(adapter, ERROR,
99 "info: leave mwifiex_register with error\n");
101 for (i = 0; i < adapter->priv_num; i++)
102 kfree(adapter->priv[i]);
110 * This function unregisters the device and performs all the necessary
113 * The following cleanup operations are performed -
115 * - Free beacon buffers
116 * - Free private structures
117 * - Free adapter structure
119 static int mwifiex_unregister(struct mwifiex_adapter *adapter)
123 if (adapter->if_ops.cleanup_if)
124 adapter->if_ops.cleanup_if(adapter);
126 del_timer_sync(&adapter->cmd_timer);
128 /* Free private structures */
129 for (i = 0; i < adapter->priv_num; i++) {
130 if (adapter->priv[i]) {
131 mwifiex_free_curr_bcn(adapter->priv[i]);
132 kfree(adapter->priv[i]);
136 if (adapter->nd_info) {
137 for (i = 0 ; i < adapter->nd_info->n_matches ; i++)
138 kfree(adapter->nd_info->matches[i]);
139 kfree(adapter->nd_info);
140 adapter->nd_info = NULL;
143 kfree(adapter->regd);
149 void mwifiex_queue_main_work(struct mwifiex_adapter *adapter)
153 spin_lock_irqsave(&adapter->main_proc_lock, flags);
154 if (adapter->mwifiex_processing) {
155 adapter->more_task_flag = true;
156 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
158 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
159 queue_work(adapter->workqueue, &adapter->main_work);
162 EXPORT_SYMBOL_GPL(mwifiex_queue_main_work);
164 static void mwifiex_queue_rx_work(struct mwifiex_adapter *adapter)
166 spin_lock_bh(&adapter->rx_proc_lock);
167 if (adapter->rx_processing) {
168 spin_unlock_bh(&adapter->rx_proc_lock);
170 spin_unlock_bh(&adapter->rx_proc_lock);
171 queue_work(adapter->rx_workqueue, &adapter->rx_work);
175 static int mwifiex_process_rx(struct mwifiex_adapter *adapter)
178 struct mwifiex_rxinfo *rx_info;
180 spin_lock_bh(&adapter->rx_proc_lock);
181 if (adapter->rx_processing || adapter->rx_locked) {
182 spin_unlock_bh(&adapter->rx_proc_lock);
185 adapter->rx_processing = true;
186 spin_unlock_bh(&adapter->rx_proc_lock);
189 /* Check for Rx data */
190 while ((skb = skb_dequeue(&adapter->rx_data_q))) {
191 atomic_dec(&adapter->rx_pending);
192 if ((adapter->delay_main_work ||
193 adapter->iface_type == MWIFIEX_USB) &&
194 (atomic_read(&adapter->rx_pending) < LOW_RX_PENDING)) {
195 if (adapter->if_ops.submit_rem_rx_urbs)
196 adapter->if_ops.submit_rem_rx_urbs(adapter);
197 adapter->delay_main_work = false;
198 mwifiex_queue_main_work(adapter);
200 rx_info = MWIFIEX_SKB_RXCB(skb);
201 if (rx_info->buf_type == MWIFIEX_TYPE_AGGR_DATA) {
202 if (adapter->if_ops.deaggr_pkt)
203 adapter->if_ops.deaggr_pkt(adapter, skb);
204 dev_kfree_skb_any(skb);
206 mwifiex_handle_rx_packet(adapter, skb);
209 spin_lock_bh(&adapter->rx_proc_lock);
210 adapter->rx_processing = false;
211 spin_unlock_bh(&adapter->rx_proc_lock);
217 static void maybe_quirk_fw_disable_ds(struct mwifiex_adapter *adapter)
219 struct mwifiex_private *priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA);
220 struct mwifiex_ver_ext ver_ext;
222 if (test_and_set_bit(MWIFIEX_IS_REQUESTING_FW_VEREXT, &adapter->work_flags))
225 memset(&ver_ext, 0, sizeof(ver_ext));
226 ver_ext.version_str_sel = 1;
227 if (mwifiex_send_cmd(priv, HostCmd_CMD_VERSION_EXT,
228 HostCmd_ACT_GEN_GET, 0, &ver_ext, false)) {
229 mwifiex_dbg(priv->adapter, MSG,
230 "Checking hardware revision failed.\n");
237 * This function is the main procedure of the driver and handles various driver
238 * operations. It runs in a loop and provides the core functionalities.
240 * The main responsibilities of this function are -
241 * - Ensure concurrency control
242 * - Handle pending interrupts and call interrupt handlers
243 * - Wake up the card if required
244 * - Handle command responses and call response handlers
245 * - Handle events and call event handlers
246 * - Execute pending commands
247 * - Transmit pending data packets
249 int mwifiex_main_process(struct mwifiex_adapter *adapter)
254 spin_lock_irqsave(&adapter->main_proc_lock, flags);
256 /* Check if already processing */
257 if (adapter->mwifiex_processing || adapter->main_locked) {
258 adapter->more_task_flag = true;
259 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
262 adapter->mwifiex_processing = true;
263 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
267 if (adapter->hw_status == MWIFIEX_HW_STATUS_NOT_READY)
270 /* For non-USB interfaces, If we process interrupts first, it
271 * would increase RX pending even further. Avoid this by
272 * checking if rx_pending has crossed high threshold and
273 * schedule rx work queue and then process interrupts.
274 * For USB interface, there are no interrupts. We already have
275 * HIGH_RX_PENDING check in usb.c
277 if (atomic_read(&adapter->rx_pending) >= HIGH_RX_PENDING &&
278 adapter->iface_type != MWIFIEX_USB) {
279 adapter->delay_main_work = true;
280 mwifiex_queue_rx_work(adapter);
284 /* Handle pending interrupt if any */
285 if (adapter->int_status) {
286 if (adapter->hs_activated)
287 mwifiex_process_hs_config(adapter);
288 if (adapter->if_ops.process_int_status)
289 adapter->if_ops.process_int_status(adapter);
292 if (adapter->rx_work_enabled && adapter->data_received)
293 mwifiex_queue_rx_work(adapter);
295 /* Need to wake up the card ? */
296 if ((adapter->ps_state == PS_STATE_SLEEP) &&
297 (adapter->pm_wakeup_card_req &&
298 !adapter->pm_wakeup_fw_try) &&
299 (is_command_pending(adapter) ||
300 !skb_queue_empty(&adapter->tx_data_q) ||
301 !mwifiex_bypass_txlist_empty(adapter) ||
302 !mwifiex_wmm_lists_empty(adapter))) {
303 adapter->pm_wakeup_fw_try = true;
304 mod_timer(&adapter->wakeup_timer, jiffies + (HZ*3));
305 adapter->if_ops.wakeup(adapter);
309 if (IS_CARD_RX_RCVD(adapter)) {
310 adapter->data_received = false;
311 adapter->pm_wakeup_fw_try = false;
312 del_timer(&adapter->wakeup_timer);
313 if (adapter->ps_state == PS_STATE_SLEEP)
314 adapter->ps_state = PS_STATE_AWAKE;
316 /* We have tried to wakeup the card already */
317 if (adapter->pm_wakeup_fw_try)
319 if (adapter->ps_state == PS_STATE_PRE_SLEEP)
320 mwifiex_check_ps_cond(adapter);
322 if (adapter->ps_state != PS_STATE_AWAKE)
324 if (adapter->tx_lock_flag) {
325 if (adapter->iface_type == MWIFIEX_USB) {
326 if (!adapter->usb_mc_setup)
332 if ((!adapter->scan_chan_gap_enabled &&
333 adapter->scan_processing) || adapter->data_sent ||
334 mwifiex_is_tdls_chan_switching
335 (mwifiex_get_priv(adapter,
336 MWIFIEX_BSS_ROLE_STA)) ||
337 (mwifiex_wmm_lists_empty(adapter) &&
338 mwifiex_bypass_txlist_empty(adapter) &&
339 skb_queue_empty(&adapter->tx_data_q))) {
340 if (adapter->cmd_sent || adapter->curr_cmd ||
341 !mwifiex_is_send_cmd_allowed
342 (mwifiex_get_priv(adapter,
343 MWIFIEX_BSS_ROLE_STA)) ||
344 (!is_command_pending(adapter)))
349 /* Check for event */
350 if (adapter->event_received) {
351 adapter->event_received = false;
352 mwifiex_process_event(adapter);
355 /* Check for Cmd Resp */
356 if (adapter->cmd_resp_received) {
357 adapter->cmd_resp_received = false;
358 mwifiex_process_cmdresp(adapter);
360 /* call mwifiex back when init_fw is done */
361 if (adapter->hw_status == MWIFIEX_HW_STATUS_INIT_DONE) {
362 adapter->hw_status = MWIFIEX_HW_STATUS_READY;
363 mwifiex_init_fw_complete(adapter);
364 maybe_quirk_fw_disable_ds(adapter);
368 /* Check if we need to confirm Sleep Request
369 received previously */
370 if (adapter->ps_state == PS_STATE_PRE_SLEEP)
371 mwifiex_check_ps_cond(adapter);
373 /* * The ps_state may have been changed during processing of
374 * Sleep Request event.
376 if ((adapter->ps_state == PS_STATE_SLEEP) ||
377 (adapter->ps_state == PS_STATE_PRE_SLEEP) ||
378 (adapter->ps_state == PS_STATE_SLEEP_CFM)) {
382 if (adapter->tx_lock_flag) {
383 if (adapter->iface_type == MWIFIEX_USB) {
384 if (!adapter->usb_mc_setup)
390 if (!adapter->cmd_sent && !adapter->curr_cmd &&
391 mwifiex_is_send_cmd_allowed
392 (mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA))) {
393 if (mwifiex_exec_next_cmd(adapter) == -1) {
399 /** If USB Multi channel setup ongoing,
400 * wait for ready to tx data.
402 if (adapter->iface_type == MWIFIEX_USB &&
403 adapter->usb_mc_setup)
406 if ((adapter->scan_chan_gap_enabled ||
407 !adapter->scan_processing) &&
408 !adapter->data_sent &&
409 !skb_queue_empty(&adapter->tx_data_q)) {
410 if (adapter->hs_activated_manually) {
411 mwifiex_cancel_hs(mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY),
413 adapter->hs_activated_manually = false;
416 mwifiex_process_tx_queue(adapter);
417 if (adapter->hs_activated) {
418 clear_bit(MWIFIEX_IS_HS_CONFIGURED,
419 &adapter->work_flags);
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 &&
430 !mwifiex_bypass_txlist_empty(adapter) &&
431 !mwifiex_is_tdls_chan_switching
432 (mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA))) {
433 if (adapter->hs_activated_manually) {
434 mwifiex_cancel_hs(mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY),
436 adapter->hs_activated_manually = false;
439 mwifiex_process_bypass_tx(adapter);
440 if (adapter->hs_activated) {
441 clear_bit(MWIFIEX_IS_HS_CONFIGURED,
442 &adapter->work_flags);
443 mwifiex_hs_activated_event
445 (adapter, MWIFIEX_BSS_ROLE_ANY),
450 if ((adapter->scan_chan_gap_enabled ||
451 !adapter->scan_processing) &&
452 !adapter->data_sent && !mwifiex_wmm_lists_empty(adapter) &&
453 !mwifiex_is_tdls_chan_switching
454 (mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA))) {
455 if (adapter->hs_activated_manually) {
456 mwifiex_cancel_hs(mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY),
458 adapter->hs_activated_manually = false;
461 mwifiex_wmm_process_tx(adapter);
462 if (adapter->hs_activated) {
463 clear_bit(MWIFIEX_IS_HS_CONFIGURED,
464 &adapter->work_flags);
465 mwifiex_hs_activated_event
467 (adapter, MWIFIEX_BSS_ROLE_ANY),
472 if (adapter->delay_null_pkt && !adapter->cmd_sent &&
473 !adapter->curr_cmd && !is_command_pending(adapter) &&
474 (mwifiex_wmm_lists_empty(adapter) &&
475 mwifiex_bypass_txlist_empty(adapter) &&
476 skb_queue_empty(&adapter->tx_data_q))) {
477 if (!mwifiex_send_null_packet
478 (mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA),
479 MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET |
480 MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET)) {
481 adapter->delay_null_pkt = false;
482 adapter->ps_state = PS_STATE_SLEEP;
488 spin_lock_irqsave(&adapter->main_proc_lock, flags);
489 if (adapter->more_task_flag) {
490 adapter->more_task_flag = false;
491 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
494 adapter->mwifiex_processing = false;
495 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
499 EXPORT_SYMBOL_GPL(mwifiex_main_process);
502 * This function frees the adapter structure.
504 * Additionally, this closes the netlink socket, frees the timers
505 * and private structures.
507 static void mwifiex_free_adapter(struct mwifiex_adapter *adapter)
510 pr_err("%s: adapter is NULL\n", __func__);
514 mwifiex_unregister(adapter);
515 pr_debug("info: %s: free adapter\n", __func__);
519 * This function cancels all works in the queue and destroys
520 * the main workqueue.
522 static void mwifiex_terminate_workqueue(struct mwifiex_adapter *adapter)
524 if (adapter->workqueue) {
525 destroy_workqueue(adapter->workqueue);
526 adapter->workqueue = NULL;
529 if (adapter->rx_workqueue) {
530 destroy_workqueue(adapter->rx_workqueue);
531 adapter->rx_workqueue = NULL;
536 * This function gets firmware and initializes it.
538 * The main initialization steps followed are -
539 * - Download the correct firmware to card
540 * - Issue the init commands to firmware
542 static int _mwifiex_fw_dpc(const struct firmware *firmware, void *context)
546 struct mwifiex_adapter *adapter = context;
547 struct mwifiex_fw_image fw;
548 bool init_failed = false;
549 struct wireless_dev *wdev;
550 struct completion *fw_done = adapter->fw_done;
553 mwifiex_dbg(adapter, ERROR,
554 "Failed to get firmware %s\n", adapter->fw_name);
558 memset(&fw, 0, sizeof(struct mwifiex_fw_image));
559 adapter->firmware = firmware;
560 fw.fw_buf = (u8 *) adapter->firmware->data;
561 fw.fw_len = adapter->firmware->size;
563 if (adapter->if_ops.dnld_fw) {
564 ret = adapter->if_ops.dnld_fw(adapter, &fw);
566 ret = mwifiex_dnld_fw(adapter, &fw);
572 mwifiex_dbg(adapter, MSG, "WLAN FW is active\n");
575 if ((request_firmware(&adapter->cal_data, cal_data_cfg,
577 mwifiex_dbg(adapter, ERROR,
578 "Cal data request_firmware() failed\n");
581 /* enable host interrupt after fw dnld is successful */
582 if (adapter->if_ops.enable_int) {
583 if (adapter->if_ops.enable_int(adapter))
587 adapter->init_wait_q_woken = false;
588 ret = mwifiex_init_fw(adapter);
592 adapter->hw_status = MWIFIEX_HW_STATUS_READY;
595 /* Wait for mwifiex_init to complete */
596 if (!adapter->mfg_mode) {
597 wait_event_interruptible(adapter->init_wait_q,
598 adapter->init_wait_q_woken);
599 if (adapter->hw_status != MWIFIEX_HW_STATUS_READY)
603 if (!adapter->wiphy) {
604 if (mwifiex_register_cfg80211(adapter)) {
605 mwifiex_dbg(adapter, ERROR,
606 "cannot register with cfg80211\n");
611 if (mwifiex_init_channel_scan_gap(adapter)) {
612 mwifiex_dbg(adapter, ERROR,
613 "could not init channel stats table\n");
614 goto err_init_chan_scan;
618 driver_mode &= MWIFIEX_DRIVER_MODE_BITMASK;
619 driver_mode |= MWIFIEX_DRIVER_MODE_STA;
623 wiphy_lock(adapter->wiphy);
624 /* Create station interface by default */
625 wdev = mwifiex_add_virtual_intf(adapter->wiphy, "mlan%d", NET_NAME_ENUM,
626 NL80211_IFTYPE_STATION, NULL);
628 mwifiex_dbg(adapter, ERROR,
629 "cannot create default STA interface\n");
630 wiphy_unlock(adapter->wiphy);
635 if (driver_mode & MWIFIEX_DRIVER_MODE_UAP) {
636 wdev = mwifiex_add_virtual_intf(adapter->wiphy, "uap%d", NET_NAME_ENUM,
637 NL80211_IFTYPE_AP, NULL);
639 mwifiex_dbg(adapter, ERROR,
640 "cannot create AP interface\n");
641 wiphy_unlock(adapter->wiphy);
647 if (driver_mode & MWIFIEX_DRIVER_MODE_P2P) {
648 wdev = mwifiex_add_virtual_intf(adapter->wiphy, "p2p%d", NET_NAME_ENUM,
649 NL80211_IFTYPE_P2P_CLIENT, NULL);
651 mwifiex_dbg(adapter, ERROR,
652 "cannot create p2p client interface\n");
653 wiphy_unlock(adapter->wiphy);
658 wiphy_unlock(adapter->wiphy);
661 mwifiex_drv_get_driver_version(adapter, fmt, sizeof(fmt) - 1);
662 mwifiex_dbg(adapter, MSG, "driver_version = %s\n", fmt);
663 adapter->is_up = true;
667 vfree(adapter->chan_stats);
669 wiphy_unregister(adapter->wiphy);
670 wiphy_free(adapter->wiphy);
672 if (adapter->if_ops.disable_int)
673 adapter->if_ops.disable_int(adapter);
675 mwifiex_dbg(adapter, ERROR,
676 "info: %s: unregister device\n", __func__);
677 if (adapter->if_ops.unregister_dev)
678 adapter->if_ops.unregister_dev(adapter);
680 set_bit(MWIFIEX_SURPRISE_REMOVED, &adapter->work_flags);
681 mwifiex_terminate_workqueue(adapter);
683 if (adapter->hw_status == MWIFIEX_HW_STATUS_READY) {
684 pr_debug("info: %s: shutdown mwifiex\n", __func__);
685 mwifiex_shutdown_drv(adapter);
686 mwifiex_free_cmd_buffers(adapter);
691 if (adapter->cal_data) {
692 release_firmware(adapter->cal_data);
693 adapter->cal_data = NULL;
695 if (adapter->firmware) {
696 release_firmware(adapter->firmware);
697 adapter->firmware = NULL;
700 if (adapter->irq_wakeup >= 0)
701 device_init_wakeup(adapter->dev, false);
702 mwifiex_free_adapter(adapter);
704 /* Tell all current and future waiters we're finished */
705 complete_all(fw_done);
707 return init_failed ? -EIO : 0;
710 static void mwifiex_fw_dpc(const struct firmware *firmware, void *context)
712 _mwifiex_fw_dpc(firmware, context);
716 * This function gets the firmware and (if called asynchronously) kicks off the
719 static int mwifiex_init_hw_fw(struct mwifiex_adapter *adapter,
724 /* Override default firmware with manufacturing one if
725 * manufacturing mode is enabled
728 if (strlcpy(adapter->fw_name, MFG_FIRMWARE,
729 sizeof(adapter->fw_name)) >=
730 sizeof(adapter->fw_name)) {
731 pr_err("%s: fw_name too long!\n", __func__);
737 ret = request_firmware_nowait(THIS_MODULE, 1, adapter->fw_name,
738 adapter->dev, GFP_KERNEL, adapter,
741 ret = request_firmware(&adapter->firmware,
747 mwifiex_dbg(adapter, ERROR, "request_firmware%s error %d\n",
748 req_fw_nowait ? "_nowait" : "", ret);
753 * CFG802.11 network device handler for open.
755 * Starts the data queue.
758 mwifiex_open(struct net_device *dev)
760 netif_carrier_off(dev);
766 * CFG802.11 network device handler for close.
769 mwifiex_close(struct net_device *dev)
771 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
773 if (priv->scan_request) {
774 struct cfg80211_scan_info info = {
778 mwifiex_dbg(priv->adapter, INFO,
779 "aborting scan on ndo_stop\n");
780 cfg80211_scan_done(priv->scan_request, &info);
781 priv->scan_request = NULL;
782 priv->scan_aborting = true;
785 if (priv->sched_scanning) {
786 mwifiex_dbg(priv->adapter, INFO,
787 "aborting bgscan on ndo_stop\n");
788 mwifiex_stop_bg_scan(priv);
789 cfg80211_sched_scan_stopped(priv->wdev.wiphy, 0);
796 mwifiex_bypass_tx_queue(struct mwifiex_private *priv,
799 struct ethhdr *eth_hdr = (struct ethhdr *)skb->data;
801 if (ntohs(eth_hdr->h_proto) == ETH_P_PAE ||
802 mwifiex_is_skb_mgmt_frame(skb) ||
803 (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA &&
804 ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) &&
805 (ntohs(eth_hdr->h_proto) == ETH_P_TDLS))) {
806 mwifiex_dbg(priv->adapter, DATA,
807 "bypass txqueue; eth type %#x, mgmt %d\n",
808 ntohs(eth_hdr->h_proto),
809 mwifiex_is_skb_mgmt_frame(skb));
816 * Add buffer into wmm tx queue and queue work to transmit it.
818 int mwifiex_queue_tx_pkt(struct mwifiex_private *priv, struct sk_buff *skb)
820 struct netdev_queue *txq;
821 int index = mwifiex_1d_to_wmm_queue[skb->priority];
823 if (atomic_inc_return(&priv->wmm_tx_pending[index]) >= MAX_TX_PENDING) {
824 txq = netdev_get_tx_queue(priv->netdev, index);
825 if (!netif_tx_queue_stopped(txq)) {
826 netif_tx_stop_queue(txq);
827 mwifiex_dbg(priv->adapter, DATA,
828 "stop queue: %d\n", index);
832 if (mwifiex_bypass_tx_queue(priv, skb)) {
833 atomic_inc(&priv->adapter->tx_pending);
834 atomic_inc(&priv->adapter->bypass_tx_pending);
835 mwifiex_wmm_add_buf_bypass_txqueue(priv, skb);
837 atomic_inc(&priv->adapter->tx_pending);
838 mwifiex_wmm_add_buf_txqueue(priv, skb);
841 mwifiex_queue_main_work(priv->adapter);
847 mwifiex_clone_skb_for_tx_status(struct mwifiex_private *priv,
848 struct sk_buff *skb, u8 flag, u64 *cookie)
850 struct sk_buff *orig_skb = skb;
851 struct mwifiex_txinfo *tx_info, *orig_tx_info;
853 skb = skb_clone(skb, GFP_ATOMIC);
857 spin_lock_bh(&priv->ack_status_lock);
858 id = idr_alloc(&priv->ack_status_frames, orig_skb,
859 1, 0x10, GFP_ATOMIC);
860 spin_unlock_bh(&priv->ack_status_lock);
863 tx_info = MWIFIEX_SKB_TXCB(skb);
864 tx_info->ack_frame_id = id;
865 tx_info->flags |= flag;
866 orig_tx_info = MWIFIEX_SKB_TXCB(orig_skb);
867 orig_tx_info->ack_frame_id = id;
868 orig_tx_info->flags |= flag;
870 if (flag == MWIFIEX_BUF_FLAG_ACTION_TX_STATUS && cookie)
871 orig_tx_info->cookie = *cookie;
873 } else if (skb_shared(skb)) {
880 /* couldn't clone -- lose tx status ... */
888 * CFG802.11 network device handler for data transmission.
891 mwifiex_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
893 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
894 struct sk_buff *new_skb;
895 struct mwifiex_txinfo *tx_info;
898 mwifiex_dbg(priv->adapter, DATA,
899 "data: %lu BSS(%d-%d): Data <= kernel\n",
900 jiffies, priv->bss_type, priv->bss_num);
902 if (test_bit(MWIFIEX_SURPRISE_REMOVED, &priv->adapter->work_flags)) {
904 priv->stats.tx_dropped++;
907 if (!skb->len || (skb->len > ETH_FRAME_LEN)) {
908 mwifiex_dbg(priv->adapter, ERROR,
909 "Tx: bad skb len %d\n", skb->len);
911 priv->stats.tx_dropped++;
914 if (skb_headroom(skb) < MWIFIEX_MIN_DATA_HEADER_LEN) {
915 mwifiex_dbg(priv->adapter, DATA,
916 "data: Tx: insufficient skb headroom %d\n",
918 /* Insufficient skb headroom - allocate a new skb */
920 skb_realloc_headroom(skb, MWIFIEX_MIN_DATA_HEADER_LEN);
921 if (unlikely(!new_skb)) {
922 mwifiex_dbg(priv->adapter, ERROR,
923 "Tx: cannot alloca new_skb\n");
925 priv->stats.tx_dropped++;
930 mwifiex_dbg(priv->adapter, INFO,
931 "info: new skb headroomd %d\n",
935 tx_info = MWIFIEX_SKB_TXCB(skb);
936 memset(tx_info, 0, sizeof(*tx_info));
937 tx_info->bss_num = priv->bss_num;
938 tx_info->bss_type = priv->bss_type;
939 tx_info->pkt_len = skb->len;
941 multicast = is_multicast_ether_addr(skb->data);
943 if (unlikely(!multicast && skb->sk &&
944 skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS &&
945 priv->adapter->fw_api_ver == MWIFIEX_FW_V15))
946 skb = mwifiex_clone_skb_for_tx_status(priv,
948 MWIFIEX_BUF_FLAG_EAPOL_TX_STATUS, NULL);
950 /* Record the current time the packet was queued; used to
951 * determine the amount of time the packet was queued in
952 * the driver before it was sent to the firmware.
953 * The delay is then sent along with the packet to the
954 * firmware for aggregate delay calculation for stats and
955 * MSDU lifetime expiry.
957 __net_timestamp(skb);
959 if (ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) &&
960 priv->bss_type == MWIFIEX_BSS_TYPE_STA &&
961 !ether_addr_equal_unaligned(priv->cfg_bssid, skb->data)) {
962 if (priv->adapter->auto_tdls && priv->check_tdls_tx)
963 mwifiex_tdls_check_tx(priv, skb);
966 mwifiex_queue_tx_pkt(priv, skb);
971 int mwifiex_set_mac_address(struct mwifiex_private *priv,
972 struct net_device *dev, bool external,
976 u64 mac_addr, old_mac_addr;
978 old_mac_addr = ether_addr_to_u64(priv->curr_addr);
981 mac_addr = ether_addr_to_u64(new_mac);
983 /* Internal mac address change */
984 if (priv->bss_type == MWIFIEX_BSS_TYPE_ANY)
987 mac_addr = old_mac_addr;
989 if (priv->bss_type == MWIFIEX_BSS_TYPE_P2P) {
990 mac_addr |= BIT_ULL(MWIFIEX_MAC_LOCAL_ADMIN_BIT);
991 mac_addr += priv->bss_num;
992 } else if (priv->adapter->priv[0] != priv) {
993 /* Set mac address based on bss_type/bss_num */
994 mac_addr ^= BIT_ULL(priv->bss_type + 8);
995 mac_addr += priv->bss_num;
999 u64_to_ether_addr(mac_addr, priv->curr_addr);
1001 /* Send request to firmware */
1002 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_MAC_ADDRESS,
1003 HostCmd_ACT_GEN_SET, 0, NULL, true);
1006 u64_to_ether_addr(old_mac_addr, priv->curr_addr);
1007 mwifiex_dbg(priv->adapter, ERROR,
1008 "set mac address failed: ret=%d\n", ret);
1012 eth_hw_addr_set(dev, priv->curr_addr);
1016 /* CFG802.11 network device handler for setting MAC address.
1019 mwifiex_ndo_set_mac_address(struct net_device *dev, void *addr)
1021 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1022 struct sockaddr *hw_addr = addr;
1024 return mwifiex_set_mac_address(priv, dev, true, hw_addr->sa_data);
1028 * CFG802.11 network device handler for setting multicast list.
1030 static void mwifiex_set_multicast_list(struct net_device *dev)
1032 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1033 struct mwifiex_multicast_list mcast_list;
1035 if (dev->flags & IFF_PROMISC) {
1036 mcast_list.mode = MWIFIEX_PROMISC_MODE;
1037 } else if (dev->flags & IFF_ALLMULTI ||
1038 netdev_mc_count(dev) > MWIFIEX_MAX_MULTICAST_LIST_SIZE) {
1039 mcast_list.mode = MWIFIEX_ALL_MULTI_MODE;
1041 mcast_list.mode = MWIFIEX_MULTICAST_MODE;
1042 mcast_list.num_multicast_addr =
1043 mwifiex_copy_mcast_addr(&mcast_list, dev);
1045 mwifiex_request_set_multicast_list(priv, &mcast_list);
1049 * CFG802.11 network device handler for transmission timeout.
1052 mwifiex_tx_timeout(struct net_device *dev, unsigned int txqueue)
1054 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1056 priv->num_tx_timeout++;
1057 priv->tx_timeout_cnt++;
1058 mwifiex_dbg(priv->adapter, ERROR,
1059 "%lu : Tx timeout(#%d), bss_type-num = %d-%d\n",
1060 jiffies, priv->tx_timeout_cnt, priv->bss_type,
1062 mwifiex_set_trans_start(dev);
1064 if (priv->tx_timeout_cnt > TX_TIMEOUT_THRESHOLD &&
1065 priv->adapter->if_ops.card_reset) {
1066 mwifiex_dbg(priv->adapter, ERROR,
1067 "tx_timeout_cnt exceeds threshold.\t"
1068 "Triggering card reset!\n");
1069 priv->adapter->if_ops.card_reset(priv->adapter);
1073 void mwifiex_multi_chan_resync(struct mwifiex_adapter *adapter)
1075 struct usb_card_rec *card = adapter->card;
1076 struct mwifiex_private *priv;
1080 card->mc_resync_flag = true;
1081 for (i = 0; i < MWIFIEX_TX_DATA_PORT; i++) {
1082 if (atomic_read(&card->port[i].tx_data_urb_pending)) {
1083 mwifiex_dbg(adapter, WARN, "pending data urb in sys\n");
1088 card->mc_resync_flag = false;
1089 tx_buf_size = 0xffff;
1090 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
1091 ret = mwifiex_send_cmd(priv, HostCmd_CMD_RECONFIGURE_TX_BUFF,
1092 HostCmd_ACT_GEN_SET, 0, &tx_buf_size, false);
1094 mwifiex_dbg(adapter, ERROR,
1095 "send reconfig tx buf size cmd err\n");
1097 EXPORT_SYMBOL_GPL(mwifiex_multi_chan_resync);
1099 void mwifiex_upload_device_dump(struct mwifiex_adapter *adapter)
1101 /* Dump all the memory data into single file, a userspace script will
1102 * be used to split all the memory data to multiple files
1104 mwifiex_dbg(adapter, MSG,
1105 "== mwifiex dump information to /sys/class/devcoredump start\n");
1106 dev_coredumpv(adapter->dev, adapter->devdump_data, adapter->devdump_len,
1108 mwifiex_dbg(adapter, MSG,
1109 "== mwifiex dump information to /sys/class/devcoredump end\n");
1111 /* Device dump data will be freed in device coredump release function
1112 * after 5 min. Here reset adapter->devdump_data and ->devdump_len
1113 * to avoid it been accidentally reused.
1115 adapter->devdump_data = NULL;
1116 adapter->devdump_len = 0;
1118 EXPORT_SYMBOL_GPL(mwifiex_upload_device_dump);
1120 void mwifiex_drv_info_dump(struct mwifiex_adapter *adapter)
1123 char drv_version[64];
1124 struct usb_card_rec *cardp;
1125 struct sdio_mmc_card *sdio_card;
1126 struct mwifiex_private *priv;
1128 struct netdev_queue *txq;
1129 struct mwifiex_debug_info *debug_info;
1131 mwifiex_dbg(adapter, MSG, "===mwifiex driverinfo dump start===\n");
1133 p = adapter->devdump_data;
1134 strcpy(p, "========Start dump driverinfo========\n");
1135 p += strlen("========Start dump driverinfo========\n");
1136 p += sprintf(p, "driver_name = " "\"mwifiex\"\n");
1138 mwifiex_drv_get_driver_version(adapter, drv_version,
1139 sizeof(drv_version) - 1);
1140 p += sprintf(p, "driver_version = %s\n", drv_version);
1142 if (adapter->iface_type == MWIFIEX_USB) {
1143 cardp = (struct usb_card_rec *)adapter->card;
1144 p += sprintf(p, "tx_cmd_urb_pending = %d\n",
1145 atomic_read(&cardp->tx_cmd_urb_pending));
1146 p += sprintf(p, "tx_data_urb_pending_port_0 = %d\n",
1147 atomic_read(&cardp->port[0].tx_data_urb_pending));
1148 p += sprintf(p, "tx_data_urb_pending_port_1 = %d\n",
1149 atomic_read(&cardp->port[1].tx_data_urb_pending));
1150 p += sprintf(p, "rx_cmd_urb_pending = %d\n",
1151 atomic_read(&cardp->rx_cmd_urb_pending));
1152 p += sprintf(p, "rx_data_urb_pending = %d\n",
1153 atomic_read(&cardp->rx_data_urb_pending));
1156 p += sprintf(p, "tx_pending = %d\n",
1157 atomic_read(&adapter->tx_pending));
1158 p += sprintf(p, "rx_pending = %d\n",
1159 atomic_read(&adapter->rx_pending));
1161 if (adapter->iface_type == MWIFIEX_SDIO) {
1162 sdio_card = (struct sdio_mmc_card *)adapter->card;
1163 p += sprintf(p, "\nmp_rd_bitmap=0x%x curr_rd_port=0x%x\n",
1164 sdio_card->mp_rd_bitmap, sdio_card->curr_rd_port);
1165 p += sprintf(p, "mp_wr_bitmap=0x%x curr_wr_port=0x%x\n",
1166 sdio_card->mp_wr_bitmap, sdio_card->curr_wr_port);
1169 for (i = 0; i < adapter->priv_num; i++) {
1170 if (!adapter->priv[i] || !adapter->priv[i]->netdev)
1172 priv = adapter->priv[i];
1173 p += sprintf(p, "\n[interface : \"%s\"]\n",
1174 priv->netdev->name);
1175 p += sprintf(p, "wmm_tx_pending[0] = %d\n",
1176 atomic_read(&priv->wmm_tx_pending[0]));
1177 p += sprintf(p, "wmm_tx_pending[1] = %d\n",
1178 atomic_read(&priv->wmm_tx_pending[1]));
1179 p += sprintf(p, "wmm_tx_pending[2] = %d\n",
1180 atomic_read(&priv->wmm_tx_pending[2]));
1181 p += sprintf(p, "wmm_tx_pending[3] = %d\n",
1182 atomic_read(&priv->wmm_tx_pending[3]));
1183 p += sprintf(p, "media_state=\"%s\"\n", !priv->media_connected ?
1184 "Disconnected" : "Connected");
1185 p += sprintf(p, "carrier %s\n", (netif_carrier_ok(priv->netdev)
1187 for (idx = 0; idx < priv->netdev->num_tx_queues; idx++) {
1188 txq = netdev_get_tx_queue(priv->netdev, idx);
1189 p += sprintf(p, "tx queue %d:%s ", idx,
1190 netif_tx_queue_stopped(txq) ?
1191 "stopped" : "started");
1193 p += sprintf(p, "\n%s: num_tx_timeout = %d\n",
1194 priv->netdev->name, priv->num_tx_timeout);
1197 if (adapter->iface_type == MWIFIEX_SDIO ||
1198 adapter->iface_type == MWIFIEX_PCIE) {
1199 p += sprintf(p, "\n=== %s register dump===\n",
1200 adapter->iface_type == MWIFIEX_SDIO ?
1202 if (adapter->if_ops.reg_dump)
1203 p += adapter->if_ops.reg_dump(adapter, p);
1205 p += sprintf(p, "\n=== more debug information\n");
1206 debug_info = kzalloc(sizeof(*debug_info), GFP_KERNEL);
1208 for (i = 0; i < adapter->priv_num; i++) {
1209 if (!adapter->priv[i] || !adapter->priv[i]->netdev)
1211 priv = adapter->priv[i];
1212 mwifiex_get_debug_info(priv, debug_info);
1213 p += mwifiex_debug_info_to_buffer(priv, p, debug_info);
1219 strcpy(p, "\n========End dump========\n");
1220 p += strlen("\n========End dump========\n");
1221 mwifiex_dbg(adapter, MSG, "===mwifiex driverinfo dump end===\n");
1222 adapter->devdump_len = p - (char *)adapter->devdump_data;
1224 EXPORT_SYMBOL_GPL(mwifiex_drv_info_dump);
1226 void mwifiex_prepare_fw_dump_info(struct mwifiex_adapter *adapter)
1232 for (idx = 0; idx < adapter->num_mem_types; idx++) {
1233 struct memory_type_mapping *entry =
1234 &adapter->mem_type_mapping_tbl[idx];
1236 if (entry->mem_ptr) {
1237 dump_len += (strlen("========Start dump ") +
1238 strlen(entry->mem_name) +
1239 strlen("========\n") +
1240 (entry->mem_size + 1) +
1241 strlen("\n========End dump========\n"));
1245 if (dump_len + 1 + adapter->devdump_len > MWIFIEX_FW_DUMP_SIZE) {
1246 /* Realloc in case buffer overflow */
1247 fw_dump_ptr = vzalloc(dump_len + 1 + adapter->devdump_len);
1248 mwifiex_dbg(adapter, MSG, "Realloc device dump data.\n");
1250 vfree(adapter->devdump_data);
1251 mwifiex_dbg(adapter, ERROR,
1252 "vzalloc devdump data failure!\n");
1256 memmove(fw_dump_ptr, adapter->devdump_data,
1257 adapter->devdump_len);
1258 vfree(adapter->devdump_data);
1259 adapter->devdump_data = fw_dump_ptr;
1262 fw_dump_ptr = (char *)adapter->devdump_data + adapter->devdump_len;
1264 for (idx = 0; idx < adapter->num_mem_types; idx++) {
1265 struct memory_type_mapping *entry =
1266 &adapter->mem_type_mapping_tbl[idx];
1268 if (entry->mem_ptr) {
1269 strcpy(fw_dump_ptr, "========Start dump ");
1270 fw_dump_ptr += strlen("========Start dump ");
1272 strcpy(fw_dump_ptr, entry->mem_name);
1273 fw_dump_ptr += strlen(entry->mem_name);
1275 strcpy(fw_dump_ptr, "========\n");
1276 fw_dump_ptr += strlen("========\n");
1278 memcpy(fw_dump_ptr, entry->mem_ptr, entry->mem_size);
1279 fw_dump_ptr += entry->mem_size;
1281 strcpy(fw_dump_ptr, "\n========End dump========\n");
1282 fw_dump_ptr += strlen("\n========End dump========\n");
1286 adapter->devdump_len = fw_dump_ptr - (char *)adapter->devdump_data;
1288 for (idx = 0; idx < adapter->num_mem_types; idx++) {
1289 struct memory_type_mapping *entry =
1290 &adapter->mem_type_mapping_tbl[idx];
1292 vfree(entry->mem_ptr);
1293 entry->mem_ptr = NULL;
1294 entry->mem_size = 0;
1297 EXPORT_SYMBOL_GPL(mwifiex_prepare_fw_dump_info);
1300 * CFG802.11 network device handler for statistics retrieval.
1302 static struct net_device_stats *mwifiex_get_stats(struct net_device *dev)
1304 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1306 return &priv->stats;
1310 mwifiex_netdev_select_wmm_queue(struct net_device *dev, struct sk_buff *skb,
1311 struct net_device *sb_dev)
1313 skb->priority = cfg80211_classify8021d(skb, NULL);
1314 return mwifiex_1d_to_wmm_queue[skb->priority];
1317 /* Network device handlers */
1318 static const struct net_device_ops mwifiex_netdev_ops = {
1319 .ndo_open = mwifiex_open,
1320 .ndo_stop = mwifiex_close,
1321 .ndo_start_xmit = mwifiex_hard_start_xmit,
1322 .ndo_set_mac_address = mwifiex_ndo_set_mac_address,
1323 .ndo_validate_addr = eth_validate_addr,
1324 .ndo_tx_timeout = mwifiex_tx_timeout,
1325 .ndo_get_stats = mwifiex_get_stats,
1326 .ndo_set_rx_mode = mwifiex_set_multicast_list,
1327 .ndo_select_queue = mwifiex_netdev_select_wmm_queue,
1331 * This function initializes the private structure parameters.
1333 * The following wait queues are initialized -
1334 * - IOCTL wait queue
1335 * - Command wait queue
1336 * - Statistics wait queue
1338 * ...and the following default parameters are set -
1339 * - Current key index : Set to 0
1340 * - Rate index : Set to auto
1341 * - Media connected : Set to disconnected
1342 * - Adhoc link sensed : Set to false
1343 * - Nick name : Set to null
1344 * - Number of Tx timeout : Set to 0
1345 * - Device address : Set to current address
1346 * - Rx histogram statistc : Set to 0
1348 * In addition, the CFG80211 work queue is also created.
1350 void mwifiex_init_priv_params(struct mwifiex_private *priv,
1351 struct net_device *dev)
1353 dev->netdev_ops = &mwifiex_netdev_ops;
1354 dev->needs_free_netdev = true;
1355 /* Initialize private structure */
1356 priv->current_key_index = 0;
1357 priv->media_connected = false;
1358 memset(priv->mgmt_ie, 0,
1359 sizeof(struct mwifiex_ie) * MAX_MGMT_IE_INDEX);
1360 priv->beacon_idx = MWIFIEX_AUTO_IDX_MASK;
1361 priv->proberesp_idx = MWIFIEX_AUTO_IDX_MASK;
1362 priv->assocresp_idx = MWIFIEX_AUTO_IDX_MASK;
1363 priv->gen_idx = MWIFIEX_AUTO_IDX_MASK;
1364 priv->num_tx_timeout = 0;
1365 if (is_valid_ether_addr(dev->dev_addr))
1366 ether_addr_copy(priv->curr_addr, dev->dev_addr);
1368 ether_addr_copy(priv->curr_addr, priv->adapter->perm_addr);
1370 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA ||
1371 GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
1372 priv->hist_data = kmalloc(sizeof(*priv->hist_data), GFP_KERNEL);
1373 if (priv->hist_data)
1374 mwifiex_hist_data_reset(priv);
1379 * This function check if command is pending.
1381 int is_command_pending(struct mwifiex_adapter *adapter)
1383 int is_cmd_pend_q_empty;
1385 spin_lock_bh(&adapter->cmd_pending_q_lock);
1386 is_cmd_pend_q_empty = list_empty(&adapter->cmd_pending_q);
1387 spin_unlock_bh(&adapter->cmd_pending_q_lock);
1389 return !is_cmd_pend_q_empty;
1393 * This is the RX work queue function.
1395 * It handles the RX operations.
1397 static void mwifiex_rx_work_queue(struct work_struct *work)
1399 struct mwifiex_adapter *adapter =
1400 container_of(work, struct mwifiex_adapter, rx_work);
1402 if (test_bit(MWIFIEX_SURPRISE_REMOVED, &adapter->work_flags))
1404 mwifiex_process_rx(adapter);
1408 * This is the main work queue function.
1410 * It handles the main process, which in turn handles the complete
1411 * driver operations.
1413 static void mwifiex_main_work_queue(struct work_struct *work)
1415 struct mwifiex_adapter *adapter =
1416 container_of(work, struct mwifiex_adapter, main_work);
1418 if (test_bit(MWIFIEX_SURPRISE_REMOVED, &adapter->work_flags))
1420 mwifiex_main_process(adapter);
1423 /* Common teardown code used for both device removal and reset */
1424 static void mwifiex_uninit_sw(struct mwifiex_adapter *adapter)
1426 struct mwifiex_private *priv;
1429 /* We can no longer handle interrupts once we start doing the teardown
1432 if (adapter->if_ops.disable_int)
1433 adapter->if_ops.disable_int(adapter);
1435 set_bit(MWIFIEX_SURPRISE_REMOVED, &adapter->work_flags);
1436 mwifiex_terminate_workqueue(adapter);
1437 adapter->int_status = 0;
1440 for (i = 0; i < adapter->priv_num; i++) {
1441 priv = adapter->priv[i];
1442 if (priv && priv->netdev) {
1443 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
1444 if (netif_carrier_ok(priv->netdev))
1445 netif_carrier_off(priv->netdev);
1446 netif_device_detach(priv->netdev);
1450 mwifiex_dbg(adapter, CMD, "cmd: calling mwifiex_shutdown_drv...\n");
1451 mwifiex_shutdown_drv(adapter);
1452 mwifiex_dbg(adapter, CMD, "cmd: mwifiex_shutdown_drv done\n");
1454 if (atomic_read(&adapter->rx_pending) ||
1455 atomic_read(&adapter->tx_pending) ||
1456 atomic_read(&adapter->cmd_pending)) {
1457 mwifiex_dbg(adapter, ERROR,
1458 "rx_pending=%d, tx_pending=%d,\t"
1460 atomic_read(&adapter->rx_pending),
1461 atomic_read(&adapter->tx_pending),
1462 atomic_read(&adapter->cmd_pending));
1465 for (i = 0; i < adapter->priv_num; i++) {
1466 priv = adapter->priv[i];
1471 priv->wdev.iftype != NL80211_IFTYPE_UNSPECIFIED) {
1473 * Close the netdev now, because if we do it later, the
1474 * netdev notifiers will need to acquire the wiphy lock
1475 * again --> deadlock.
1477 dev_close(priv->wdev.netdev);
1478 wiphy_lock(adapter->wiphy);
1479 mwifiex_del_virtual_intf(adapter->wiphy, &priv->wdev);
1480 wiphy_unlock(adapter->wiphy);
1485 wiphy_unregister(adapter->wiphy);
1486 wiphy_free(adapter->wiphy);
1487 adapter->wiphy = NULL;
1489 vfree(adapter->chan_stats);
1490 mwifiex_free_cmd_buffers(adapter);
1494 * This function can be used for shutting down the adapter SW.
1496 int mwifiex_shutdown_sw(struct mwifiex_adapter *adapter)
1498 struct mwifiex_private *priv;
1503 wait_for_completion(adapter->fw_done);
1504 /* Caller should ensure we aren't suspending while this happens */
1505 reinit_completion(adapter->fw_done);
1507 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
1508 mwifiex_deauthenticate(priv, NULL);
1510 mwifiex_init_shutdown_fw(priv, MWIFIEX_FUNC_SHUTDOWN);
1512 mwifiex_uninit_sw(adapter);
1513 adapter->is_up = false;
1515 if (adapter->if_ops.down_dev)
1516 adapter->if_ops.down_dev(adapter);
1520 EXPORT_SYMBOL_GPL(mwifiex_shutdown_sw);
1522 /* This function can be used for reinitting the adapter SW. Required
1523 * code is extracted from mwifiex_add_card()
1526 mwifiex_reinit_sw(struct mwifiex_adapter *adapter)
1530 mwifiex_init_lock_list(adapter);
1531 if (adapter->if_ops.up_dev)
1532 adapter->if_ops.up_dev(adapter);
1534 adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING;
1535 clear_bit(MWIFIEX_SURPRISE_REMOVED, &adapter->work_flags);
1536 init_waitqueue_head(&adapter->init_wait_q);
1537 clear_bit(MWIFIEX_IS_SUSPENDED, &adapter->work_flags);
1538 adapter->hs_activated = false;
1539 clear_bit(MWIFIEX_IS_CMD_TIMEDOUT, &adapter->work_flags);
1540 init_waitqueue_head(&adapter->hs_activate_wait_q);
1541 init_waitqueue_head(&adapter->cmd_wait_q.wait);
1542 adapter->cmd_wait_q.status = 0;
1543 adapter->scan_wait_q_woken = false;
1545 if ((num_possible_cpus() > 1) || adapter->iface_type == MWIFIEX_USB)
1546 adapter->rx_work_enabled = true;
1548 adapter->workqueue =
1549 alloc_workqueue("MWIFIEX_WORK_QUEUE",
1550 WQ_HIGHPRI | WQ_MEM_RECLAIM | WQ_UNBOUND, 1);
1551 if (!adapter->workqueue)
1554 INIT_WORK(&adapter->main_work, mwifiex_main_work_queue);
1556 if (adapter->rx_work_enabled) {
1557 adapter->rx_workqueue = alloc_workqueue("MWIFIEX_RX_WORK_QUEUE",
1561 if (!adapter->rx_workqueue)
1563 INIT_WORK(&adapter->rx_work, mwifiex_rx_work_queue);
1566 /* Register the device. Fill up the private data structure with
1567 * relevant information from the card. Some code extracted from
1568 * mwifiex_register_dev()
1570 mwifiex_dbg(adapter, INFO, "%s, mwifiex_init_hw_fw()...\n", __func__);
1572 if (mwifiex_init_hw_fw(adapter, false)) {
1573 mwifiex_dbg(adapter, ERROR,
1574 "%s: firmware init failed\n", __func__);
1578 /* _mwifiex_fw_dpc() does its own cleanup */
1579 ret = _mwifiex_fw_dpc(adapter->firmware, adapter);
1581 pr_err("Failed to bring up adapter: %d\n", ret);
1584 mwifiex_dbg(adapter, INFO, "%s, successful\n", __func__);
1589 mwifiex_dbg(adapter, ERROR, "info: %s: unregister device\n", __func__);
1590 if (adapter->if_ops.unregister_dev)
1591 adapter->if_ops.unregister_dev(adapter);
1594 set_bit(MWIFIEX_SURPRISE_REMOVED, &adapter->work_flags);
1595 mwifiex_terminate_workqueue(adapter);
1596 if (adapter->hw_status == MWIFIEX_HW_STATUS_READY) {
1597 mwifiex_dbg(adapter, ERROR,
1598 "info: %s: shutdown mwifiex\n", __func__);
1599 mwifiex_shutdown_drv(adapter);
1600 mwifiex_free_cmd_buffers(adapter);
1603 complete_all(adapter->fw_done);
1604 mwifiex_dbg(adapter, INFO, "%s, error\n", __func__);
1608 EXPORT_SYMBOL_GPL(mwifiex_reinit_sw);
1610 static irqreturn_t mwifiex_irq_wakeup_handler(int irq, void *priv)
1612 struct mwifiex_adapter *adapter = priv;
1614 dev_dbg(adapter->dev, "%s: wake by wifi", __func__);
1615 adapter->wake_by_wifi = true;
1616 disable_irq_nosync(irq);
1618 /* Notify PM core we are wakeup source */
1619 pm_wakeup_event(adapter->dev, 0);
1625 static void mwifiex_probe_of(struct mwifiex_adapter *adapter)
1628 struct device *dev = adapter->dev;
1633 adapter->dt_node = dev->of_node;
1634 adapter->irq_wakeup = irq_of_parse_and_map(adapter->dt_node, 0);
1635 if (!adapter->irq_wakeup) {
1636 dev_dbg(dev, "fail to parse irq_wakeup from device tree\n");
1640 ret = devm_request_irq(dev, adapter->irq_wakeup,
1641 mwifiex_irq_wakeup_handler, IRQF_TRIGGER_LOW,
1642 "wifi_wake", adapter);
1644 dev_err(dev, "Failed to request irq_wakeup %d (%d)\n",
1645 adapter->irq_wakeup, ret);
1649 disable_irq(adapter->irq_wakeup);
1650 if (device_init_wakeup(dev, true)) {
1651 dev_err(dev, "fail to init wakeup for mwifiex\n");
1657 adapter->irq_wakeup = -1;
1661 * This function adds the card.
1663 * This function follows the following major steps to set up the device -
1664 * - Initialize software. This includes probing the card, registering
1665 * the interface operations table, and allocating/initializing the
1667 * - Set up the netlink socket
1668 * - Create and start the main work queue
1669 * - Register the device
1670 * - Initialize firmware and hardware
1671 * - Add logical interfaces
1674 mwifiex_add_card(void *card, struct completion *fw_done,
1675 struct mwifiex_if_ops *if_ops, u8 iface_type,
1678 struct mwifiex_adapter *adapter;
1680 if (mwifiex_register(card, dev, if_ops, (void **)&adapter)) {
1681 pr_err("%s: software init failed\n", __func__);
1685 mwifiex_probe_of(adapter);
1687 adapter->iface_type = iface_type;
1688 adapter->fw_done = fw_done;
1690 adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING;
1691 clear_bit(MWIFIEX_SURPRISE_REMOVED, &adapter->work_flags);
1692 init_waitqueue_head(&adapter->init_wait_q);
1693 clear_bit(MWIFIEX_IS_SUSPENDED, &adapter->work_flags);
1694 adapter->hs_activated = false;
1695 init_waitqueue_head(&adapter->hs_activate_wait_q);
1696 init_waitqueue_head(&adapter->cmd_wait_q.wait);
1697 adapter->cmd_wait_q.status = 0;
1698 adapter->scan_wait_q_woken = false;
1700 if ((num_possible_cpus() > 1) || adapter->iface_type == MWIFIEX_USB)
1701 adapter->rx_work_enabled = true;
1703 adapter->workqueue =
1704 alloc_workqueue("MWIFIEX_WORK_QUEUE",
1705 WQ_HIGHPRI | WQ_MEM_RECLAIM | WQ_UNBOUND, 1);
1706 if (!adapter->workqueue)
1709 INIT_WORK(&adapter->main_work, mwifiex_main_work_queue);
1711 if (adapter->rx_work_enabled) {
1712 adapter->rx_workqueue = alloc_workqueue("MWIFIEX_RX_WORK_QUEUE",
1716 if (!adapter->rx_workqueue)
1719 INIT_WORK(&adapter->rx_work, mwifiex_rx_work_queue);
1722 /* Register the device. Fill up the private data structure with relevant
1723 information from the card. */
1724 if (adapter->if_ops.register_dev(adapter)) {
1725 pr_err("%s: failed to register mwifiex device\n", __func__);
1726 goto err_registerdev;
1729 if (mwifiex_init_hw_fw(adapter, true)) {
1730 pr_err("%s: firmware init failed\n", __func__);
1737 pr_debug("info: %s: unregister device\n", __func__);
1738 if (adapter->if_ops.unregister_dev)
1739 adapter->if_ops.unregister_dev(adapter);
1741 set_bit(MWIFIEX_SURPRISE_REMOVED, &adapter->work_flags);
1742 mwifiex_terminate_workqueue(adapter);
1743 if (adapter->hw_status == MWIFIEX_HW_STATUS_READY) {
1744 pr_debug("info: %s: shutdown mwifiex\n", __func__);
1745 mwifiex_shutdown_drv(adapter);
1746 mwifiex_free_cmd_buffers(adapter);
1749 if (adapter->irq_wakeup >= 0)
1750 device_init_wakeup(adapter->dev, false);
1751 mwifiex_free_adapter(adapter);
1757 EXPORT_SYMBOL_GPL(mwifiex_add_card);
1760 * This function removes the card.
1762 * This function follows the following major steps to remove the device -
1763 * - Stop data traffic
1764 * - Shutdown firmware
1765 * - Remove the logical interfaces
1766 * - Terminate the work queue
1767 * - Unregister the device
1768 * - Free the adapter structure
1770 int mwifiex_remove_card(struct mwifiex_adapter *adapter)
1776 mwifiex_uninit_sw(adapter);
1778 if (adapter->irq_wakeup >= 0)
1779 device_init_wakeup(adapter->dev, false);
1781 /* Unregister device */
1782 mwifiex_dbg(adapter, INFO,
1783 "info: unregister device\n");
1784 if (adapter->if_ops.unregister_dev)
1785 adapter->if_ops.unregister_dev(adapter);
1786 /* Free adapter structure */
1787 mwifiex_dbg(adapter, INFO,
1788 "info: free adapter\n");
1789 mwifiex_free_adapter(adapter);
1793 EXPORT_SYMBOL_GPL(mwifiex_remove_card);
1795 void _mwifiex_dbg(const struct mwifiex_adapter *adapter, int mask,
1796 const char *fmt, ...)
1798 struct va_format vaf;
1801 if (!(adapter->debug_mask & mask))
1804 va_start(args, fmt);
1810 dev_info(adapter->dev, "%pV", &vaf);
1812 pr_info("%pV", &vaf);
1816 EXPORT_SYMBOL_GPL(_mwifiex_dbg);
1819 * This function initializes the module.
1821 * The debug FS is also initialized if configured.
1824 mwifiex_init_module(void)
1826 #ifdef CONFIG_DEBUG_FS
1827 mwifiex_debugfs_init();
1833 * This function cleans up the module.
1835 * The debug FS is removed if available.
1838 mwifiex_cleanup_module(void)
1840 #ifdef CONFIG_DEBUG_FS
1841 mwifiex_debugfs_remove();
1845 module_init(mwifiex_init_module);
1846 module_exit(mwifiex_cleanup_module);
1848 MODULE_AUTHOR("Marvell International Ltd.");
1849 MODULE_DESCRIPTION("Marvell WiFi-Ex Driver version " VERSION);
1850 MODULE_VERSION(VERSION);
1851 MODULE_LICENSE("GPL v2");