2 * Marvell Wireless LAN device driver: major functions
4 * Copyright (C) 2011, 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.
27 const char driver_version[] = "mwifiex " VERSION " (%s) ";
28 static char *cal_data_cfg;
29 module_param(cal_data_cfg, charp, 0);
32 * This function registers the device and performs all the necessary
35 * The following initialization operations are performed -
36 * - Allocate adapter structure
37 * - Save interface specific operations table in adapter
38 * - Call interface specific initialization routine
39 * - Allocate private structures
40 * - Set default adapter structure parameters
43 * In case of any errors during inittialization, this function also ensures
44 * proper cleanup before exiting.
46 static int mwifiex_register(void *card, struct mwifiex_if_ops *if_ops,
49 struct mwifiex_adapter *adapter;
52 adapter = kzalloc(sizeof(struct mwifiex_adapter), GFP_KERNEL);
59 /* Save interface specific operations in adapter */
60 memmove(&adapter->if_ops, if_ops, sizeof(struct mwifiex_if_ops));
62 /* card specific initialization has been deferred until now .. */
63 if (adapter->if_ops.init_if)
64 if (adapter->if_ops.init_if(adapter))
67 adapter->priv_num = 0;
69 for (i = 0; i < MWIFIEX_MAX_BSS_NUM; i++) {
70 /* Allocate memory for private structure */
72 kzalloc(sizeof(struct mwifiex_private), GFP_KERNEL);
73 if (!adapter->priv[i])
76 adapter->priv[i]->adapter = adapter;
79 mwifiex_init_lock_list(adapter);
81 init_timer(&adapter->cmd_timer);
82 adapter->cmd_timer.function = mwifiex_cmd_timeout_func;
83 adapter->cmd_timer.data = (unsigned long) adapter;
88 dev_dbg(adapter->dev, "info: leave mwifiex_register with error\n");
90 for (i = 0; i < adapter->priv_num; i++)
91 kfree(adapter->priv[i]);
99 * This function unregisters the device and performs all the necessary
102 * The following cleanup operations are performed -
104 * - Free beacon buffers
105 * - Free private structures
106 * - Free adapter structure
108 static int mwifiex_unregister(struct mwifiex_adapter *adapter)
112 del_timer(&adapter->cmd_timer);
114 /* Free private structures */
115 for (i = 0; i < adapter->priv_num; i++) {
116 if (adapter->priv[i]) {
117 mwifiex_free_curr_bcn(adapter->priv[i]);
118 kfree(adapter->priv[i]);
129 * This function is the main procedure of the driver and handles various driver
130 * operations. It runs in a loop and provides the core functionalities.
132 * The main responsibilities of this function are -
133 * - Ensure concurrency control
134 * - Handle pending interrupts and call interrupt handlers
135 * - Wake up the card if required
136 * - Handle command responses and call response handlers
137 * - Handle events and call event handlers
138 * - Execute pending commands
139 * - Transmit pending data packets
141 int mwifiex_main_process(struct mwifiex_adapter *adapter)
147 spin_lock_irqsave(&adapter->main_proc_lock, flags);
149 /* Check if already processing */
150 if (adapter->mwifiex_processing) {
151 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
154 adapter->mwifiex_processing = true;
155 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
159 if ((adapter->hw_status == MWIFIEX_HW_STATUS_CLOSING) ||
160 (adapter->hw_status == MWIFIEX_HW_STATUS_NOT_READY))
163 /* Handle pending interrupt if any */
164 if (adapter->int_status) {
165 if (adapter->hs_activated)
166 mwifiex_process_hs_config(adapter);
167 if (adapter->if_ops.process_int_status)
168 adapter->if_ops.process_int_status(adapter);
171 /* Need to wake up the card ? */
172 if ((adapter->ps_state == PS_STATE_SLEEP) &&
173 (adapter->pm_wakeup_card_req &&
174 !adapter->pm_wakeup_fw_try) &&
175 (is_command_pending(adapter) ||
176 !mwifiex_wmm_lists_empty(adapter))) {
177 adapter->pm_wakeup_fw_try = true;
178 adapter->if_ops.wakeup(adapter);
182 if (IS_CARD_RX_RCVD(adapter)) {
183 adapter->pm_wakeup_fw_try = false;
184 if (adapter->ps_state == PS_STATE_SLEEP)
185 adapter->ps_state = PS_STATE_AWAKE;
187 /* We have tried to wakeup the card already */
188 if (adapter->pm_wakeup_fw_try)
190 if (adapter->ps_state != PS_STATE_AWAKE ||
191 adapter->tx_lock_flag)
194 if ((adapter->scan_processing &&
195 !adapter->scan_delay_cnt) || adapter->data_sent ||
196 mwifiex_wmm_lists_empty(adapter)) {
197 if (adapter->cmd_sent || adapter->curr_cmd ||
198 (!is_command_pending(adapter)))
203 /* Check Rx data for USB */
204 if (adapter->iface_type == MWIFIEX_USB)
205 while ((skb = skb_dequeue(&adapter->usb_rx_data_q)))
206 mwifiex_handle_rx_packet(adapter, skb);
208 /* Check for Cmd Resp */
209 if (adapter->cmd_resp_received) {
210 adapter->cmd_resp_received = false;
211 mwifiex_process_cmdresp(adapter);
213 /* call mwifiex back when init_fw is done */
214 if (adapter->hw_status == MWIFIEX_HW_STATUS_INIT_DONE) {
215 adapter->hw_status = MWIFIEX_HW_STATUS_READY;
216 mwifiex_init_fw_complete(adapter);
220 /* Check for event */
221 if (adapter->event_received) {
222 adapter->event_received = false;
223 mwifiex_process_event(adapter);
226 /* Check if we need to confirm Sleep Request
227 received previously */
228 if (adapter->ps_state == PS_STATE_PRE_SLEEP) {
229 if (!adapter->cmd_sent && !adapter->curr_cmd)
230 mwifiex_check_ps_cond(adapter);
233 /* * The ps_state may have been changed during processing of
234 * Sleep Request event.
236 if ((adapter->ps_state == PS_STATE_SLEEP) ||
237 (adapter->ps_state == PS_STATE_PRE_SLEEP) ||
238 (adapter->ps_state == PS_STATE_SLEEP_CFM) ||
239 adapter->tx_lock_flag)
242 if (!adapter->cmd_sent && !adapter->curr_cmd) {
243 if (mwifiex_exec_next_cmd(adapter) == -1) {
249 if ((!adapter->scan_processing || adapter->scan_delay_cnt) &&
250 !adapter->data_sent && !mwifiex_wmm_lists_empty(adapter)) {
251 mwifiex_wmm_process_tx(adapter);
252 if (adapter->hs_activated) {
253 adapter->is_hs_configured = false;
254 mwifiex_hs_activated_event
256 (adapter, MWIFIEX_BSS_ROLE_ANY),
261 if (adapter->delay_null_pkt && !adapter->cmd_sent &&
262 !adapter->curr_cmd && !is_command_pending(adapter) &&
263 mwifiex_wmm_lists_empty(adapter)) {
264 if (!mwifiex_send_null_packet
265 (mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA),
266 MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET |
267 MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET)) {
268 adapter->delay_null_pkt = false;
269 adapter->ps_state = PS_STATE_SLEEP;
275 if ((adapter->int_status) || IS_CARD_RX_RCVD(adapter))
278 spin_lock_irqsave(&adapter->main_proc_lock, flags);
279 adapter->mwifiex_processing = false;
280 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
283 if (adapter->hw_status == MWIFIEX_HW_STATUS_CLOSING)
284 mwifiex_shutdown_drv(adapter);
287 EXPORT_SYMBOL_GPL(mwifiex_main_process);
290 * This function frees the adapter structure.
292 * Additionally, this closes the netlink socket, frees the timers
293 * and private structures.
295 static void mwifiex_free_adapter(struct mwifiex_adapter *adapter)
298 pr_err("%s: adapter is NULL\n", __func__);
302 mwifiex_unregister(adapter);
303 pr_debug("info: %s: free adapter\n", __func__);
307 * This function gets firmware and initializes it.
309 * The main initialization steps followed are -
310 * - Download the correct firmware to card
311 * - Issue the init commands to firmware
313 static void mwifiex_fw_dpc(const struct firmware *firmware, void *context)
317 struct mwifiex_private *priv;
318 struct mwifiex_adapter *adapter = context;
319 struct mwifiex_fw_image fw;
322 dev_err(adapter->dev,
323 "Failed to get firmware %s\n", adapter->fw_name);
327 memset(&fw, 0, sizeof(struct mwifiex_fw_image));
328 adapter->firmware = firmware;
329 fw.fw_buf = (u8 *) adapter->firmware->data;
330 fw.fw_len = adapter->firmware->size;
332 if (adapter->if_ops.dnld_fw)
333 ret = adapter->if_ops.dnld_fw(adapter, &fw);
335 ret = mwifiex_dnld_fw(adapter, &fw);
339 dev_notice(adapter->dev, "WLAN FW is active\n");
342 if ((request_firmware(&adapter->cal_data, cal_data_cfg,
344 dev_err(adapter->dev,
345 "Cal data request_firmware() failed\n");
348 adapter->init_wait_q_woken = false;
349 ret = mwifiex_init_fw(adapter);
353 adapter->hw_status = MWIFIEX_HW_STATUS_READY;
356 /* Wait for mwifiex_init to complete */
357 wait_event_interruptible(adapter->init_wait_q,
358 adapter->init_wait_q_woken);
359 if (adapter->hw_status != MWIFIEX_HW_STATUS_READY)
362 priv = adapter->priv[MWIFIEX_BSS_ROLE_STA];
363 if (mwifiex_register_cfg80211(adapter)) {
364 dev_err(adapter->dev, "cannot register with cfg80211\n");
369 /* Create station interface by default */
370 if (!mwifiex_add_virtual_intf(adapter->wiphy, "mlan%d",
371 NL80211_IFTYPE_STATION, NULL, NULL)) {
372 dev_err(adapter->dev, "cannot create default STA interface\n");
376 /* Create AP interface by default */
377 if (!mwifiex_add_virtual_intf(adapter->wiphy, "uap%d",
378 NL80211_IFTYPE_AP, NULL, NULL)) {
379 dev_err(adapter->dev, "cannot create default AP interface\n");
383 /* Create P2P interface by default */
384 if (!mwifiex_add_virtual_intf(adapter->wiphy, "p2p%d",
385 NL80211_IFTYPE_P2P_CLIENT, NULL, NULL)) {
386 dev_err(adapter->dev, "cannot create default P2P interface\n");
391 mwifiex_drv_get_driver_version(adapter, fmt, sizeof(fmt) - 1);
392 dev_notice(adapter->dev, "driver_version = %s\n", fmt);
396 mwifiex_del_virtual_intf(adapter->wiphy, priv->wdev);
399 pr_debug("info: %s: unregister device\n", __func__);
400 adapter->if_ops.unregister_dev(adapter);
402 if (adapter->cal_data) {
403 release_firmware(adapter->cal_data);
404 adapter->cal_data = NULL;
406 release_firmware(adapter->firmware);
407 complete(&adapter->fw_load);
412 * This function initializes the hardware and gets firmware.
414 static int mwifiex_init_hw_fw(struct mwifiex_adapter *adapter)
418 init_completion(&adapter->fw_load);
419 ret = request_firmware_nowait(THIS_MODULE, 1, adapter->fw_name,
420 adapter->dev, GFP_KERNEL, adapter,
423 dev_err(adapter->dev,
424 "request_firmware_nowait() returned error %d\n", ret);
429 * CFG802.11 network device handler for open.
431 * Starts the data queue.
434 mwifiex_open(struct net_device *dev)
436 netif_tx_start_all_queues(dev);
441 * CFG802.11 network device handler for close.
444 mwifiex_close(struct net_device *dev)
446 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
448 if (priv->scan_request) {
449 dev_dbg(priv->adapter->dev, "aborting scan on ndo_stop\n");
450 cfg80211_scan_done(priv->scan_request, 1);
451 priv->scan_request = NULL;
452 priv->scan_aborting = true;
459 * Add buffer into wmm tx queue and queue work to transmit it.
461 int mwifiex_queue_tx_pkt(struct mwifiex_private *priv, struct sk_buff *skb)
463 struct netdev_queue *txq;
464 int index = mwifiex_1d_to_wmm_queue[skb->priority];
466 if (atomic_inc_return(&priv->wmm_tx_pending[index]) >= MAX_TX_PENDING) {
467 txq = netdev_get_tx_queue(priv->netdev, index);
468 if (!netif_tx_queue_stopped(txq)) {
469 netif_tx_stop_queue(txq);
470 dev_dbg(priv->adapter->dev, "stop queue: %d\n", index);
474 atomic_inc(&priv->adapter->tx_pending);
475 mwifiex_wmm_add_buf_txqueue(priv, skb);
477 if (priv->adapter->scan_delay_cnt)
478 atomic_set(&priv->adapter->is_tx_received, true);
480 queue_work(priv->adapter->workqueue, &priv->adapter->main_work);
486 * CFG802.11 network device handler for data transmission.
489 mwifiex_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
491 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
492 struct sk_buff *new_skb;
493 struct mwifiex_txinfo *tx_info;
496 dev_dbg(priv->adapter->dev, "data: %lu BSS(%d-%d): Data <= kernel\n",
497 jiffies, priv->bss_type, priv->bss_num);
499 if (priv->adapter->surprise_removed) {
501 priv->stats.tx_dropped++;
504 if (!skb->len || (skb->len > ETH_FRAME_LEN)) {
505 dev_err(priv->adapter->dev, "Tx: bad skb len %d\n", skb->len);
507 priv->stats.tx_dropped++;
510 if (skb_headroom(skb) < MWIFIEX_MIN_DATA_HEADER_LEN) {
511 dev_dbg(priv->adapter->dev,
512 "data: Tx: insufficient skb headroom %d\n",
514 /* Insufficient skb headroom - allocate a new skb */
516 skb_realloc_headroom(skb, MWIFIEX_MIN_DATA_HEADER_LEN);
517 if (unlikely(!new_skb)) {
518 dev_err(priv->adapter->dev, "Tx: cannot alloca new_skb\n");
520 priv->stats.tx_dropped++;
525 dev_dbg(priv->adapter->dev, "info: new skb headroomd %d\n",
529 tx_info = MWIFIEX_SKB_TXCB(skb);
530 tx_info->bss_num = priv->bss_num;
531 tx_info->bss_type = priv->bss_type;
533 /* Record the current time the packet was queued; used to
534 * determine the amount of time the packet was queued in
535 * the driver before it was sent to the firmware.
536 * The delay is then sent along with the packet to the
537 * firmware for aggregate delay calculation for stats and
538 * MSDU lifetime expiry.
540 do_gettimeofday(&tv);
541 skb->tstamp = timeval_to_ktime(tv);
543 mwifiex_queue_tx_pkt(priv, skb);
549 * CFG802.11 network device handler for setting MAC address.
552 mwifiex_set_mac_address(struct net_device *dev, void *addr)
554 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
555 struct sockaddr *hw_addr = addr;
558 memcpy(priv->curr_addr, hw_addr->sa_data, ETH_ALEN);
560 /* Send request to firmware */
561 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_MAC_ADDRESS,
562 HostCmd_ACT_GEN_SET, 0, NULL);
565 memcpy(priv->netdev->dev_addr, priv->curr_addr, ETH_ALEN);
567 dev_err(priv->adapter->dev,
568 "set mac address failed: ret=%d\n", ret);
570 memcpy(dev->dev_addr, priv->curr_addr, ETH_ALEN);
576 * CFG802.11 network device handler for setting multicast list.
578 static void mwifiex_set_multicast_list(struct net_device *dev)
580 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
581 struct mwifiex_multicast_list mcast_list;
583 if (dev->flags & IFF_PROMISC) {
584 mcast_list.mode = MWIFIEX_PROMISC_MODE;
585 } else if (dev->flags & IFF_ALLMULTI ||
586 netdev_mc_count(dev) > MWIFIEX_MAX_MULTICAST_LIST_SIZE) {
587 mcast_list.mode = MWIFIEX_ALL_MULTI_MODE;
589 mcast_list.mode = MWIFIEX_MULTICAST_MODE;
590 if (netdev_mc_count(dev))
591 mcast_list.num_multicast_addr =
592 mwifiex_copy_mcast_addr(&mcast_list, dev);
594 mwifiex_request_set_multicast_list(priv, &mcast_list);
598 * CFG802.11 network device handler for transmission timeout.
601 mwifiex_tx_timeout(struct net_device *dev)
603 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
605 priv->num_tx_timeout++;
606 priv->tx_timeout_cnt++;
607 dev_err(priv->adapter->dev,
608 "%lu : Tx timeout(#%d), bss_type-num = %d-%d\n",
609 jiffies, priv->tx_timeout_cnt, priv->bss_type, priv->bss_num);
610 mwifiex_set_trans_start(dev);
612 if (priv->tx_timeout_cnt > TX_TIMEOUT_THRESHOLD &&
613 priv->adapter->if_ops.card_reset) {
614 dev_err(priv->adapter->dev,
615 "tx_timeout_cnt exceeds threshold. Triggering card reset!\n");
616 priv->adapter->if_ops.card_reset(priv->adapter);
621 * CFG802.11 network device handler for statistics retrieval.
623 static struct net_device_stats *mwifiex_get_stats(struct net_device *dev)
625 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
631 mwifiex_netdev_select_wmm_queue(struct net_device *dev, struct sk_buff *skb)
633 skb->priority = cfg80211_classify8021d(skb);
634 return mwifiex_1d_to_wmm_queue[skb->priority];
637 /* Network device handlers */
638 static const struct net_device_ops mwifiex_netdev_ops = {
639 .ndo_open = mwifiex_open,
640 .ndo_stop = mwifiex_close,
641 .ndo_start_xmit = mwifiex_hard_start_xmit,
642 .ndo_set_mac_address = mwifiex_set_mac_address,
643 .ndo_tx_timeout = mwifiex_tx_timeout,
644 .ndo_get_stats = mwifiex_get_stats,
645 .ndo_set_rx_mode = mwifiex_set_multicast_list,
646 .ndo_select_queue = mwifiex_netdev_select_wmm_queue,
650 * This function initializes the private structure parameters.
652 * The following wait queues are initialized -
654 * - Command wait queue
655 * - Statistics wait queue
657 * ...and the following default parameters are set -
658 * - Current key index : Set to 0
659 * - Rate index : Set to auto
660 * - Media connected : Set to disconnected
661 * - Adhoc link sensed : Set to false
662 * - Nick name : Set to null
663 * - Number of Tx timeout : Set to 0
664 * - Device address : Set to current address
666 * In addition, the CFG80211 work queue is also created.
668 void mwifiex_init_priv_params(struct mwifiex_private *priv,
669 struct net_device *dev)
671 dev->netdev_ops = &mwifiex_netdev_ops;
672 /* Initialize private structure */
673 priv->current_key_index = 0;
674 priv->media_connected = false;
675 memset(&priv->nick_name, 0, sizeof(priv->nick_name));
676 memset(priv->mgmt_ie, 0,
677 sizeof(struct mwifiex_ie) * MAX_MGMT_IE_INDEX);
678 priv->beacon_idx = MWIFIEX_AUTO_IDX_MASK;
679 priv->proberesp_idx = MWIFIEX_AUTO_IDX_MASK;
680 priv->assocresp_idx = MWIFIEX_AUTO_IDX_MASK;
681 priv->rsn_idx = MWIFIEX_AUTO_IDX_MASK;
682 priv->num_tx_timeout = 0;
683 memcpy(dev->dev_addr, priv->curr_addr, ETH_ALEN);
687 * This function check if command is pending.
689 int is_command_pending(struct mwifiex_adapter *adapter)
692 int is_cmd_pend_q_empty;
694 spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags);
695 is_cmd_pend_q_empty = list_empty(&adapter->cmd_pending_q);
696 spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, flags);
698 return !is_cmd_pend_q_empty;
702 * This is the main work queue function.
704 * It handles the main process, which in turn handles the complete
707 static void mwifiex_main_work_queue(struct work_struct *work)
709 struct mwifiex_adapter *adapter =
710 container_of(work, struct mwifiex_adapter, main_work);
712 if (adapter->surprise_removed)
714 mwifiex_main_process(adapter);
718 * This function cancels all works in the queue and destroys
719 * the main workqueue.
722 mwifiex_terminate_workqueue(struct mwifiex_adapter *adapter)
724 flush_workqueue(adapter->workqueue);
725 destroy_workqueue(adapter->workqueue);
726 adapter->workqueue = NULL;
730 * This function adds the card.
732 * This function follows the following major steps to set up the device -
733 * - Initialize software. This includes probing the card, registering
734 * the interface operations table, and allocating/initializing the
736 * - Set up the netlink socket
737 * - Create and start the main work queue
738 * - Register the device
739 * - Initialize firmware and hardware
740 * - Add logical interfaces
743 mwifiex_add_card(void *card, struct semaphore *sem,
744 struct mwifiex_if_ops *if_ops, u8 iface_type)
746 struct mwifiex_adapter *adapter;
748 if (down_interruptible(sem))
751 if (mwifiex_register(card, if_ops, (void **)&adapter)) {
752 pr_err("%s: software init failed\n", __func__);
756 adapter->iface_type = iface_type;
758 adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING;
759 adapter->surprise_removed = false;
760 init_waitqueue_head(&adapter->init_wait_q);
761 adapter->is_suspended = false;
762 adapter->hs_activated = false;
763 init_waitqueue_head(&adapter->hs_activate_wait_q);
764 adapter->cmd_wait_q_required = false;
765 init_waitqueue_head(&adapter->cmd_wait_q.wait);
766 adapter->cmd_wait_q.status = 0;
767 adapter->scan_wait_q_woken = false;
769 adapter->workqueue = create_workqueue("MWIFIEX_WORK_QUEUE");
770 if (!adapter->workqueue)
773 INIT_WORK(&adapter->main_work, mwifiex_main_work_queue);
775 /* Register the device. Fill up the private data structure with relevant
776 information from the card and request for the required IRQ. */
777 if (adapter->if_ops.register_dev(adapter)) {
778 pr_err("%s: failed to register mwifiex device\n", __func__);
779 goto err_registerdev;
782 if (mwifiex_init_hw_fw(adapter)) {
783 pr_err("%s: firmware init failed\n", __func__);
791 pr_debug("info: %s: unregister device\n", __func__);
792 if (adapter->if_ops.unregister_dev)
793 adapter->if_ops.unregister_dev(adapter);
795 adapter->surprise_removed = true;
796 mwifiex_terminate_workqueue(adapter);
798 if ((adapter->hw_status == MWIFIEX_HW_STATUS_FW_READY) ||
799 (adapter->hw_status == MWIFIEX_HW_STATUS_READY)) {
800 pr_debug("info: %s: shutdown mwifiex\n", __func__);
801 adapter->init_wait_q_woken = false;
803 if (mwifiex_shutdown_drv(adapter) == -EINPROGRESS)
804 wait_event_interruptible(adapter->init_wait_q,
805 adapter->init_wait_q_woken);
808 mwifiex_free_adapter(adapter);
816 EXPORT_SYMBOL_GPL(mwifiex_add_card);
819 * This function removes the card.
821 * This function follows the following major steps to remove the device -
822 * - Stop data traffic
823 * - Shutdown firmware
824 * - Remove the logical interfaces
825 * - Terminate the work queue
826 * - Unregister the device
827 * - Free the adapter structure
829 int mwifiex_remove_card(struct mwifiex_adapter *adapter, struct semaphore *sem)
831 struct mwifiex_private *priv = NULL;
834 if (down_interruptible(sem))
840 adapter->surprise_removed = true;
843 for (i = 0; i < adapter->priv_num; i++) {
844 priv = adapter->priv[i];
845 if (priv && priv->netdev) {
846 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
847 if (netif_carrier_ok(priv->netdev))
848 netif_carrier_off(priv->netdev);
852 dev_dbg(adapter->dev, "cmd: calling mwifiex_shutdown_drv...\n");
853 adapter->init_wait_q_woken = false;
855 if (mwifiex_shutdown_drv(adapter) == -EINPROGRESS)
856 wait_event_interruptible(adapter->init_wait_q,
857 adapter->init_wait_q_woken);
858 dev_dbg(adapter->dev, "cmd: mwifiex_shutdown_drv done\n");
859 if (atomic_read(&adapter->rx_pending) ||
860 atomic_read(&adapter->tx_pending) ||
861 atomic_read(&adapter->cmd_pending)) {
862 dev_err(adapter->dev, "rx_pending=%d, tx_pending=%d, "
864 atomic_read(&adapter->rx_pending),
865 atomic_read(&adapter->tx_pending),
866 atomic_read(&adapter->cmd_pending));
869 for (i = 0; i < adapter->priv_num; i++) {
870 priv = adapter->priv[i];
876 if (priv->wdev && priv->netdev)
877 mwifiex_del_virtual_intf(adapter->wiphy, priv->wdev);
881 priv = adapter->priv[0];
882 if (!priv || !priv->wdev)
885 wiphy_unregister(priv->wdev->wiphy);
886 wiphy_free(priv->wdev->wiphy);
888 for (i = 0; i < adapter->priv_num; i++) {
889 priv = adapter->priv[i];
894 mwifiex_terminate_workqueue(adapter);
896 /* Unregister device */
897 dev_dbg(adapter->dev, "info: unregister device\n");
898 if (adapter->if_ops.unregister_dev)
899 adapter->if_ops.unregister_dev(adapter);
900 /* Free adapter structure */
901 dev_dbg(adapter->dev, "info: free adapter\n");
902 mwifiex_free_adapter(adapter);
909 EXPORT_SYMBOL_GPL(mwifiex_remove_card);
912 * This function initializes the module.
914 * The debug FS is also initialized if configured.
917 mwifiex_init_module(void)
919 #ifdef CONFIG_DEBUG_FS
920 mwifiex_debugfs_init();
926 * This function cleans up the module.
928 * The debug FS is removed if available.
931 mwifiex_cleanup_module(void)
933 #ifdef CONFIG_DEBUG_FS
934 mwifiex_debugfs_remove();
938 module_init(mwifiex_init_module);
939 module_exit(mwifiex_cleanup_module);
941 MODULE_AUTHOR("Marvell International Ltd.");
942 MODULE_DESCRIPTION("Marvell WiFi-Ex Driver version " VERSION);
943 MODULE_VERSION(VERSION);
944 MODULE_LICENSE("GPL v2");