2 * Marvell Wireless LAN device driver: HW/FW Initialization
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.
29 * This function adds a BSS priority table to the table list.
31 * The function allocates a new BSS priority table node and adds it to
32 * the end of BSS priority table list, kept in driver memory.
34 static int mwifiex_add_bss_prio_tbl(struct mwifiex_private *priv)
36 struct mwifiex_adapter *adapter = priv->adapter;
37 struct mwifiex_bss_prio_node *bss_prio;
38 struct mwifiex_bss_prio_tbl *tbl = adapter->bss_prio_tbl;
41 bss_prio = kzalloc(sizeof(struct mwifiex_bss_prio_node), GFP_KERNEL);
45 bss_prio->priv = priv;
46 INIT_LIST_HEAD(&bss_prio->list);
48 spin_lock_irqsave(&tbl[priv->bss_priority].bss_prio_lock, flags);
49 list_add_tail(&bss_prio->list, &tbl[priv->bss_priority].bss_prio_head);
50 spin_unlock_irqrestore(&tbl[priv->bss_priority].bss_prio_lock, flags);
55 static void wakeup_timer_fn(unsigned long data)
57 struct mwifiex_adapter *adapter = (struct mwifiex_adapter *)data;
59 mwifiex_dbg(adapter, ERROR, "Firmware wakeup failed\n");
60 adapter->hw_status = MWIFIEX_HW_STATUS_RESET;
61 mwifiex_cancel_all_pending_cmd(adapter);
63 if (adapter->if_ops.card_reset)
64 adapter->if_ops.card_reset(adapter);
68 * This function initializes the private structure and sets default
69 * values to the members.
71 * Additionally, it also initializes all the locks and sets up all the
74 int mwifiex_init_priv(struct mwifiex_private *priv)
78 priv->media_connected = false;
79 eth_broadcast_addr(priv->curr_addr);
80 priv->port_open = false;
81 priv->usb_port = MWIFIEX_USB_EP_DATA;
82 priv->pkt_tx_ctrl = 0;
83 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
84 priv->data_rate = 0; /* Initially indicate the rate as auto */
85 priv->is_data_rate_auto = true;
86 priv->bcn_avg_factor = DEFAULT_BCN_AVG_FACTOR;
87 priv->data_avg_factor = DEFAULT_DATA_AVG_FACTOR;
89 priv->sec_info.wep_enabled = 0;
90 priv->sec_info.authentication_mode = NL80211_AUTHTYPE_OPEN_SYSTEM;
91 priv->sec_info.encryption_mode = 0;
92 for (i = 0; i < ARRAY_SIZE(priv->wep_key); i++)
93 memset(&priv->wep_key[i], 0, sizeof(struct mwifiex_wep_key));
94 priv->wep_key_curr_index = 0;
95 priv->curr_pkt_filter = HostCmd_ACT_MAC_RX_ON | HostCmd_ACT_MAC_TX_ON |
96 HostCmd_ACT_MAC_ETHERNETII_ENABLE;
98 priv->beacon_period = 100; /* beacon interval */
99 priv->attempted_bss_desc = NULL;
100 memset(&priv->curr_bss_params, 0, sizeof(priv->curr_bss_params));
101 priv->listen_interval = MWIFIEX_DEFAULT_LISTEN_INTERVAL;
103 memset(&priv->prev_ssid, 0, sizeof(priv->prev_ssid));
104 memset(&priv->prev_bssid, 0, sizeof(priv->prev_bssid));
105 memset(&priv->assoc_rsp_buf, 0, sizeof(priv->assoc_rsp_buf));
106 priv->assoc_rsp_size = 0;
107 priv->adhoc_channel = DEFAULT_AD_HOC_CHANNEL;
108 priv->atim_window = 0;
109 priv->adhoc_state = ADHOC_IDLE;
110 priv->tx_power_level = 0;
111 priv->max_tx_power_level = 0;
112 priv->min_tx_power_level = 0;
114 priv->rxpd_htinfo = 0;
116 priv->rate_bitmap = 0;
117 priv->data_rssi_last = 0;
118 priv->data_rssi_avg = 0;
119 priv->data_nf_avg = 0;
120 priv->data_nf_last = 0;
121 priv->bcn_rssi_last = 0;
122 priv->bcn_rssi_avg = 0;
123 priv->bcn_nf_avg = 0;
124 priv->bcn_nf_last = 0;
125 memset(&priv->wpa_ie, 0, sizeof(priv->wpa_ie));
126 memset(&priv->aes_key, 0, sizeof(priv->aes_key));
127 priv->wpa_ie_len = 0;
128 priv->wpa_is_gtk_set = false;
130 memset(&priv->assoc_tlv_buf, 0, sizeof(priv->assoc_tlv_buf));
131 priv->assoc_tlv_buf_len = 0;
132 memset(&priv->wps, 0, sizeof(priv->wps));
133 memset(&priv->gen_ie_buf, 0, sizeof(priv->gen_ie_buf));
134 priv->gen_ie_buf_len = 0;
135 memset(priv->vs_ie, 0, sizeof(priv->vs_ie));
137 priv->wmm_required = true;
138 priv->wmm_enabled = false;
139 priv->wmm_qosinfo = 0;
140 priv->curr_bcn_buf = NULL;
141 priv->curr_bcn_size = 0;
143 priv->wps_ie_len = 0;
144 priv->ap_11n_enabled = 0;
145 memset(&priv->roc_cfg, 0, sizeof(priv->roc_cfg));
147 priv->scan_block = false;
150 priv->csa_expire_time = 0;
151 priv->del_list_idx = 0;
152 priv->hs2_enabled = false;
153 priv->check_tdls_tx = false;
154 memcpy(priv->tos_to_tid_inv, tos_to_tid_inv, MAX_NUM_TID);
156 mwifiex_init_11h_params(priv);
158 return mwifiex_add_bss_prio_tbl(priv);
162 * This function allocates buffers for members of the adapter
165 * The memory allocated includes scan table, command buffers, and
166 * sleep confirm command buffer. In addition, the queues are
169 static int mwifiex_allocate_adapter(struct mwifiex_adapter *adapter)
173 /* Allocate command buffer */
174 ret = mwifiex_alloc_cmd_buffer(adapter);
176 mwifiex_dbg(adapter, ERROR,
177 "%s: failed to alloc cmd buffer\n",
183 dev_alloc_skb(sizeof(struct mwifiex_opt_sleep_confirm)
186 if (!adapter->sleep_cfm) {
187 mwifiex_dbg(adapter, ERROR,
188 "%s: failed to alloc sleep cfm\t"
189 " cmd buffer\n", __func__);
192 skb_reserve(adapter->sleep_cfm, INTF_HEADER_LEN);
198 * This function initializes the adapter structure and sets default
199 * values to the members of adapter.
201 * This also initializes the WMM related parameters in the driver private
204 static void mwifiex_init_adapter(struct mwifiex_adapter *adapter)
206 struct mwifiex_opt_sleep_confirm *sleep_cfm_buf = NULL;
208 skb_put(adapter->sleep_cfm, sizeof(struct mwifiex_opt_sleep_confirm));
210 adapter->cmd_sent = false;
212 if (adapter->iface_type == MWIFIEX_SDIO)
213 adapter->data_sent = true;
215 adapter->data_sent = false;
217 adapter->cmd_resp_received = false;
218 adapter->event_received = false;
219 adapter->data_received = false;
221 adapter->surprise_removed = false;
223 adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING;
225 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
226 adapter->ps_state = PS_STATE_AWAKE;
227 adapter->need_to_wakeup = false;
229 adapter->scan_mode = HostCmd_BSS_MODE_ANY;
230 adapter->specific_scan_time = MWIFIEX_SPECIFIC_SCAN_CHAN_TIME;
231 adapter->active_scan_time = MWIFIEX_ACTIVE_SCAN_CHAN_TIME;
232 adapter->passive_scan_time = MWIFIEX_PASSIVE_SCAN_CHAN_TIME;
233 adapter->scan_chan_gap_time = MWIFIEX_DEF_SCAN_CHAN_GAP_TIME;
235 adapter->scan_probes = 1;
237 adapter->multiple_dtim = 1;
239 adapter->local_listen_interval = 0; /* default value in firmware
242 adapter->is_deep_sleep = false;
244 adapter->delay_null_pkt = false;
245 adapter->delay_to_ps = 1000;
246 adapter->enhanced_ps_mode = PS_MODE_AUTO;
248 adapter->gen_null_pkt = false; /* Disable NULL Pkg generation by
250 adapter->pps_uapsd_mode = false; /* Disable pps/uapsd mode by
252 adapter->pm_wakeup_card_req = false;
254 adapter->pm_wakeup_fw_try = false;
256 adapter->curr_tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K;
258 adapter->is_hs_configured = false;
259 adapter->hs_cfg.conditions = cpu_to_le32(HS_CFG_COND_DEF);
260 adapter->hs_cfg.gpio = HS_CFG_GPIO_DEF;
261 adapter->hs_cfg.gap = HS_CFG_GAP_DEF;
262 adapter->hs_activated = false;
264 memset(adapter->event_body, 0, sizeof(adapter->event_body));
265 adapter->hw_dot_11n_dev_cap = 0;
266 adapter->hw_dev_mcs_support = 0;
267 adapter->sec_chan_offset = 0;
268 adapter->adhoc_11n_enabled = false;
270 mwifiex_wmm_init(adapter);
272 sleep_cfm_buf = (struct mwifiex_opt_sleep_confirm *)
273 adapter->sleep_cfm->data;
274 memset(sleep_cfm_buf, 0, adapter->sleep_cfm->len);
275 sleep_cfm_buf->command = cpu_to_le16(HostCmd_CMD_802_11_PS_MODE_ENH);
276 sleep_cfm_buf->size = cpu_to_le16(adapter->sleep_cfm->len);
277 sleep_cfm_buf->result = 0;
278 sleep_cfm_buf->action = cpu_to_le16(SLEEP_CONFIRM);
279 sleep_cfm_buf->resp_ctrl = cpu_to_le16(RESP_NEEDED);
281 memset(&adapter->sleep_params, 0, sizeof(adapter->sleep_params));
282 memset(&adapter->sleep_period, 0, sizeof(adapter->sleep_period));
283 adapter->tx_lock_flag = false;
284 adapter->null_pkt_interval = 0;
285 adapter->fw_bands = 0;
286 adapter->config_bands = 0;
287 adapter->adhoc_start_band = 0;
288 adapter->scan_channels = NULL;
289 adapter->fw_release_number = 0;
290 adapter->fw_cap_info = 0;
291 memset(&adapter->upld_buf, 0, sizeof(adapter->upld_buf));
292 adapter->event_cause = 0;
293 adapter->region_code = 0;
294 adapter->bcn_miss_time_out = DEFAULT_BCN_MISS_TIMEOUT;
295 adapter->adhoc_awake_period = 0;
296 memset(&adapter->arp_filter, 0, sizeof(adapter->arp_filter));
297 adapter->arp_filter_size = 0;
298 adapter->max_mgmt_ie_index = MAX_MGMT_IE_INDEX;
299 adapter->key_api_major_ver = 0;
300 adapter->key_api_minor_ver = 0;
301 eth_broadcast_addr(adapter->perm_addr);
302 adapter->iface_limit.sta_intf = MWIFIEX_MAX_STA_NUM;
303 adapter->iface_limit.uap_intf = MWIFIEX_MAX_UAP_NUM;
304 adapter->iface_limit.p2p_intf = MWIFIEX_MAX_P2P_NUM;
305 adapter->active_scan_triggered = false;
306 setup_timer(&adapter->wakeup_timer, wakeup_timer_fn,
307 (unsigned long)adapter);
311 * This function sets trans_start per tx_queue
313 void mwifiex_set_trans_start(struct net_device *dev)
317 for (i = 0; i < dev->num_tx_queues; i++)
318 netdev_get_tx_queue(dev, i)->trans_start = jiffies;
320 dev->trans_start = jiffies;
324 * This function wakes up all queues in net_device
326 void mwifiex_wake_up_net_dev_queue(struct net_device *netdev,
327 struct mwifiex_adapter *adapter)
329 unsigned long dev_queue_flags;
332 spin_lock_irqsave(&adapter->queue_lock, dev_queue_flags);
334 for (i = 0; i < netdev->num_tx_queues; i++) {
335 struct netdev_queue *txq = netdev_get_tx_queue(netdev, i);
337 if (netif_tx_queue_stopped(txq))
338 netif_tx_wake_queue(txq);
341 spin_unlock_irqrestore(&adapter->queue_lock, dev_queue_flags);
345 * This function stops all queues in net_device
347 void mwifiex_stop_net_dev_queue(struct net_device *netdev,
348 struct mwifiex_adapter *adapter)
350 unsigned long dev_queue_flags;
353 spin_lock_irqsave(&adapter->queue_lock, dev_queue_flags);
355 for (i = 0; i < netdev->num_tx_queues; i++) {
356 struct netdev_queue *txq = netdev_get_tx_queue(netdev, i);
358 if (!netif_tx_queue_stopped(txq))
359 netif_tx_stop_queue(txq);
362 spin_unlock_irqrestore(&adapter->queue_lock, dev_queue_flags);
366 * This function releases the lock variables and frees the locks and
369 static void mwifiex_free_lock_list(struct mwifiex_adapter *adapter)
371 struct mwifiex_private *priv;
375 list_del(&adapter->cmd_free_q);
376 list_del(&adapter->cmd_pending_q);
377 list_del(&adapter->scan_pending_q);
379 for (i = 0; i < adapter->priv_num; i++)
380 list_del(&adapter->bss_prio_tbl[i].bss_prio_head);
382 for (i = 0; i < adapter->priv_num; i++) {
383 if (adapter->priv[i]) {
384 priv = adapter->priv[i];
385 for (j = 0; j < MAX_NUM_TID; ++j)
386 list_del(&priv->wmm.tid_tbl_ptr[j].ra_list);
387 list_del(&priv->tx_ba_stream_tbl_ptr);
388 list_del(&priv->rx_reorder_tbl_ptr);
389 list_del(&priv->sta_list);
390 list_del(&priv->auto_tdls_list);
396 * This function performs cleanup for adapter structure.
398 * The cleanup is done recursively, by canceling all pending
399 * commands, freeing the member buffers previously allocated
400 * (command buffers, scan table buffer, sleep confirm command
401 * buffer), stopping the timers and calling the cleanup routines
402 * for every interface.
405 mwifiex_adapter_cleanup(struct mwifiex_adapter *adapter)
410 pr_err("%s: adapter is NULL\n", __func__);
414 del_timer(&adapter->wakeup_timer);
415 mwifiex_cancel_all_pending_cmd(adapter);
416 wake_up_interruptible(&adapter->cmd_wait_q.wait);
417 wake_up_interruptible(&adapter->hs_activate_wait_q);
419 /* Free lock variables */
420 mwifiex_free_lock_list(adapter);
422 /* Free command buffer */
423 mwifiex_dbg(adapter, INFO, "info: free cmd buffer\n");
424 mwifiex_free_cmd_buffer(adapter);
426 for (idx = 0; idx < adapter->num_mem_types; idx++) {
427 struct memory_type_mapping *entry =
428 &adapter->mem_type_mapping_tbl[idx];
430 if (entry->mem_ptr) {
431 vfree(entry->mem_ptr);
432 entry->mem_ptr = NULL;
437 if (adapter->drv_info_dump) {
438 vfree(adapter->drv_info_dump);
439 adapter->drv_info_dump = NULL;
440 adapter->drv_info_size = 0;
443 if (adapter->sleep_cfm)
444 dev_kfree_skb_any(adapter->sleep_cfm);
448 * This function intializes the lock variables and
451 int mwifiex_init_lock_list(struct mwifiex_adapter *adapter)
453 struct mwifiex_private *priv;
456 spin_lock_init(&adapter->mwifiex_lock);
457 spin_lock_init(&adapter->int_lock);
458 spin_lock_init(&adapter->main_proc_lock);
459 spin_lock_init(&adapter->mwifiex_cmd_lock);
460 spin_lock_init(&adapter->queue_lock);
461 for (i = 0; i < adapter->priv_num; i++) {
462 if (adapter->priv[i]) {
463 priv = adapter->priv[i];
464 spin_lock_init(&priv->rx_pkt_lock);
465 spin_lock_init(&priv->wmm.ra_list_spinlock);
466 spin_lock_init(&priv->curr_bcn_buf_lock);
467 spin_lock_init(&priv->sta_list_spinlock);
468 spin_lock_init(&priv->auto_tdls_lock);
472 /* Initialize cmd_free_q */
473 INIT_LIST_HEAD(&adapter->cmd_free_q);
474 /* Initialize cmd_pending_q */
475 INIT_LIST_HEAD(&adapter->cmd_pending_q);
476 /* Initialize scan_pending_q */
477 INIT_LIST_HEAD(&adapter->scan_pending_q);
479 spin_lock_init(&adapter->cmd_free_q_lock);
480 spin_lock_init(&adapter->cmd_pending_q_lock);
481 spin_lock_init(&adapter->scan_pending_q_lock);
482 spin_lock_init(&adapter->rx_proc_lock);
484 skb_queue_head_init(&adapter->rx_data_q);
485 skb_queue_head_init(&adapter->tx_data_q);
487 for (i = 0; i < adapter->priv_num; ++i) {
488 INIT_LIST_HEAD(&adapter->bss_prio_tbl[i].bss_prio_head);
489 spin_lock_init(&adapter->bss_prio_tbl[i].bss_prio_lock);
492 for (i = 0; i < adapter->priv_num; i++) {
493 if (!adapter->priv[i])
495 priv = adapter->priv[i];
496 for (j = 0; j < MAX_NUM_TID; ++j)
497 INIT_LIST_HEAD(&priv->wmm.tid_tbl_ptr[j].ra_list);
498 INIT_LIST_HEAD(&priv->tx_ba_stream_tbl_ptr);
499 INIT_LIST_HEAD(&priv->rx_reorder_tbl_ptr);
500 INIT_LIST_HEAD(&priv->sta_list);
501 INIT_LIST_HEAD(&priv->auto_tdls_list);
502 skb_queue_head_init(&priv->tdls_txq);
503 skb_queue_head_init(&priv->bypass_txq);
505 spin_lock_init(&priv->tx_ba_stream_tbl_lock);
506 spin_lock_init(&priv->rx_reorder_tbl_lock);
508 spin_lock_init(&priv->ack_status_lock);
509 idr_init(&priv->ack_status_frames);
516 * This function initializes the firmware.
518 * The following operations are performed sequentially -
519 * - Allocate adapter structure
520 * - Initialize the adapter structure
521 * - Initialize the private structure
522 * - Add BSS priority tables to the adapter structure
523 * - For each interface, send the init commands to firmware
524 * - Send the first command in command pending queue, if available
526 int mwifiex_init_fw(struct mwifiex_adapter *adapter)
529 struct mwifiex_private *priv;
530 u8 i, first_sta = true;
531 int is_cmd_pend_q_empty;
534 adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING;
536 /* Allocate memory for member of adapter structure */
537 ret = mwifiex_allocate_adapter(adapter);
541 /* Initialize adapter structure */
542 mwifiex_init_adapter(adapter);
544 for (i = 0; i < adapter->priv_num; i++) {
545 if (adapter->priv[i]) {
546 priv = adapter->priv[i];
548 /* Initialize private structure */
549 ret = mwifiex_init_priv(priv);
555 for (i = 0; i < adapter->priv_num; i++) {
556 if (adapter->priv[i]) {
557 ret = mwifiex_sta_init_cmd(adapter->priv[i], first_sta,
566 spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags);
567 is_cmd_pend_q_empty = list_empty(&adapter->cmd_pending_q);
568 spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, flags);
569 if (!is_cmd_pend_q_empty) {
570 /* Send the first command in queue and return */
571 if (mwifiex_main_process(adapter) != -1)
574 adapter->hw_status = MWIFIEX_HW_STATUS_READY;
581 * This function deletes the BSS priority tables.
583 * The function traverses through all the allocated BSS priority nodes
584 * in every BSS priority table and frees them.
586 static void mwifiex_delete_bss_prio_tbl(struct mwifiex_private *priv)
589 struct mwifiex_adapter *adapter = priv->adapter;
590 struct mwifiex_bss_prio_node *bssprio_node, *tmp_node;
591 struct list_head *head;
592 spinlock_t *lock; /* bss priority lock */
595 for (i = 0; i < adapter->priv_num; ++i) {
596 head = &adapter->bss_prio_tbl[i].bss_prio_head;
597 lock = &adapter->bss_prio_tbl[i].bss_prio_lock;
598 mwifiex_dbg(adapter, INFO,
599 "info: delete BSS priority table,\t"
600 "bss_type = %d, bss_num = %d, i = %d,\t"
602 priv->bss_type, priv->bss_num, i, head);
605 spin_lock_irqsave(lock, flags);
606 if (list_empty(head)) {
607 spin_unlock_irqrestore(lock, flags);
610 list_for_each_entry_safe(bssprio_node, tmp_node, head,
612 if (bssprio_node->priv == priv) {
613 mwifiex_dbg(adapter, INFO,
615 "node %p, next = %p\n",
616 bssprio_node, tmp_node);
617 list_del(&bssprio_node->list);
621 spin_unlock_irqrestore(lock, flags);
627 * This function frees the private structure, including cleans
628 * up the TX and RX queues and frees the BSS priority tables.
630 void mwifiex_free_priv(struct mwifiex_private *priv)
632 mwifiex_clean_txrx(priv);
633 mwifiex_delete_bss_prio_tbl(priv);
634 mwifiex_free_curr_bcn(priv);
638 * This function is used to shutdown the driver.
640 * The following operations are performed sequentially -
641 * - Check if already shut down
642 * - Make sure the main process has stopped
643 * - Clean up the Tx and Rx queues
644 * - Delete BSS priority tables
646 * - Notify completion
649 mwifiex_shutdown_drv(struct mwifiex_adapter *adapter)
651 int ret = -EINPROGRESS;
652 struct mwifiex_private *priv;
657 /* mwifiex already shutdown */
658 if (adapter->hw_status == MWIFIEX_HW_STATUS_NOT_READY)
661 adapter->hw_status = MWIFIEX_HW_STATUS_CLOSING;
662 /* wait for mwifiex_process to complete */
663 if (adapter->mwifiex_processing) {
664 mwifiex_dbg(adapter, WARN,
665 "main process is still running\n");
669 /* cancel current command */
670 if (adapter->curr_cmd) {
671 mwifiex_dbg(adapter, WARN,
672 "curr_cmd is still in processing\n");
673 del_timer_sync(&adapter->cmd_timer);
674 mwifiex_recycle_cmd_node(adapter, adapter->curr_cmd);
675 adapter->curr_cmd = NULL;
678 /* shut down mwifiex */
679 mwifiex_dbg(adapter, MSG,
680 "info: shutdown mwifiex...\n");
682 /* Clean up Tx/Rx queues and delete BSS priority table */
683 for (i = 0; i < adapter->priv_num; i++) {
684 if (adapter->priv[i]) {
685 priv = adapter->priv[i];
687 mwifiex_clean_auto_tdls(priv);
688 mwifiex_abort_cac(priv);
689 mwifiex_clean_txrx(priv);
690 mwifiex_delete_bss_prio_tbl(priv);
694 atomic_set(&adapter->tx_queued, 0);
695 while ((skb = skb_dequeue(&adapter->tx_data_q)))
696 mwifiex_write_data_complete(adapter, skb, 0, 0);
698 spin_lock_irqsave(&adapter->rx_proc_lock, flags);
700 while ((skb = skb_dequeue(&adapter->rx_data_q))) {
701 struct mwifiex_rxinfo *rx_info = MWIFIEX_SKB_RXCB(skb);
703 atomic_dec(&adapter->rx_pending);
704 priv = adapter->priv[rx_info->bss_num];
706 priv->stats.rx_dropped++;
708 dev_kfree_skb_any(skb);
711 spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
713 spin_lock(&adapter->mwifiex_lock);
715 mwifiex_adapter_cleanup(adapter);
717 spin_unlock(&adapter->mwifiex_lock);
719 /* Notify completion */
720 ret = mwifiex_shutdown_fw_complete(adapter);
726 * This function downloads the firmware to the card.
728 * The actual download is preceded by two sanity checks -
729 * - Check if firmware is already running
730 * - Check if the interface is the winner to download the firmware
732 * ...and followed by another -
733 * - Check if the firmware is downloaded successfully
735 * After download is successfully completed, the host interrupts are enabled.
737 int mwifiex_dnld_fw(struct mwifiex_adapter *adapter,
738 struct mwifiex_fw_image *pmfw)
743 if (adapter->if_ops.check_fw_status) {
746 /* check if firmware is already running */
747 ret = adapter->if_ops.check_fw_status(adapter, poll_num);
749 mwifiex_dbg(adapter, MSG,
750 "WLAN FW already running! Skip FW dnld\n");
754 poll_num = MAX_FIRMWARE_POLL_TRIES;
756 /* check if we are the winner for downloading FW */
757 if (!adapter->winner) {
758 mwifiex_dbg(adapter, MSG,
759 "FW already running! Skip FW dnld\n");
765 /* Download firmware with helper */
766 ret = adapter->if_ops.prog_fw(adapter, pmfw);
768 mwifiex_dbg(adapter, ERROR,
769 "prog_fw failed ret=%#x\n", ret);
775 /* Check if the firmware is downloaded successfully or not */
776 ret = adapter->if_ops.check_fw_status(adapter, poll_num);
778 mwifiex_dbg(adapter, ERROR,
779 "FW failed to be active in time\n");