2 * Marvell Wireless LAN device driver: HW/FW Initialization
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.
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);
43 dev_err(adapter->dev, "%s: failed to alloc bss_prio\n",
48 bss_prio->priv = priv;
49 INIT_LIST_HEAD(&bss_prio->list);
50 if (!tbl[priv->bss_priority].bss_prio_cur)
51 tbl[priv->bss_priority].bss_prio_cur = bss_prio;
53 spin_lock_irqsave(&tbl[priv->bss_priority].bss_prio_lock, flags);
54 list_add_tail(&bss_prio->list, &tbl[priv->bss_priority].bss_prio_head);
55 spin_unlock_irqrestore(&tbl[priv->bss_priority].bss_prio_lock, flags);
60 static void scan_delay_timer_fn(unsigned long data)
62 struct mwifiex_private *priv = (struct mwifiex_private *)data;
63 struct mwifiex_adapter *adapter = priv->adapter;
64 struct cmd_ctrl_node *cmd_node, *tmp_node;
67 if (!mwifiex_wmm_lists_empty(adapter)) {
68 if (adapter->scan_delay_cnt == MWIFIEX_MAX_SCAN_DELAY_CNT) {
70 * Abort scan operation by cancelling all pending scan
73 spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
74 list_for_each_entry_safe(cmd_node, tmp_node,
75 &adapter->scan_pending_q,
77 list_del(&cmd_node->list);
78 cmd_node->wait_q_enabled = false;
79 mwifiex_insert_cmd_to_free_q(adapter, cmd_node);
81 spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
84 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
85 adapter->scan_processing = false;
86 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock,
89 if (priv->user_scan_cfg) {
90 dev_dbg(priv->adapter->dev,
91 "info: %s: scan aborted\n", __func__);
92 cfg80211_scan_done(priv->scan_request, 1);
93 priv->scan_request = NULL;
94 kfree(priv->user_scan_cfg);
95 priv->user_scan_cfg = NULL;
99 * Tx data queue is still not empty, delay scan
100 * operation further by 20msec.
102 mod_timer(&priv->scan_delay_timer, jiffies +
103 msecs_to_jiffies(MWIFIEX_SCAN_DELAY_MSEC));
104 adapter->scan_delay_cnt++;
106 queue_work(priv->adapter->workqueue, &priv->adapter->main_work);
109 * Tx data queue is empty. Get scan command from scan_pending_q
110 * and put to cmd_pending_q to resume scan operation
112 adapter->scan_delay_cnt = 0;
113 spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
114 cmd_node = list_first_entry(&adapter->scan_pending_q,
115 struct cmd_ctrl_node, list);
116 list_del(&cmd_node->list);
117 spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
119 mwifiex_insert_cmd_to_pending_q(adapter, cmd_node, true);
124 * This function initializes the private structure and sets default
125 * values to the members.
127 * Additionally, it also initializes all the locks and sets up all the
130 static int mwifiex_init_priv(struct mwifiex_private *priv)
134 priv->media_connected = false;
135 memset(priv->curr_addr, 0xff, ETH_ALEN);
137 priv->pkt_tx_ctrl = 0;
138 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
139 priv->data_rate = 0; /* Initially indicate the rate as auto */
140 priv->is_data_rate_auto = true;
141 priv->bcn_avg_factor = DEFAULT_BCN_AVG_FACTOR;
142 priv->data_avg_factor = DEFAULT_DATA_AVG_FACTOR;
144 priv->sec_info.wep_enabled = 0;
145 priv->sec_info.authentication_mode = NL80211_AUTHTYPE_OPEN_SYSTEM;
146 priv->sec_info.encryption_mode = 0;
147 for (i = 0; i < ARRAY_SIZE(priv->wep_key); i++)
148 memset(&priv->wep_key[i], 0, sizeof(struct mwifiex_wep_key));
149 priv->wep_key_curr_index = 0;
150 priv->curr_pkt_filter = HostCmd_ACT_MAC_RX_ON | HostCmd_ACT_MAC_TX_ON |
151 HostCmd_ACT_MAC_ETHERNETII_ENABLE;
153 priv->beacon_period = 100; /* beacon interval */ ;
154 priv->attempted_bss_desc = NULL;
155 memset(&priv->curr_bss_params, 0, sizeof(priv->curr_bss_params));
156 priv->listen_interval = MWIFIEX_DEFAULT_LISTEN_INTERVAL;
158 memset(&priv->prev_ssid, 0, sizeof(priv->prev_ssid));
159 memset(&priv->prev_bssid, 0, sizeof(priv->prev_bssid));
160 memset(&priv->assoc_rsp_buf, 0, sizeof(priv->assoc_rsp_buf));
161 priv->assoc_rsp_size = 0;
162 priv->adhoc_channel = DEFAULT_AD_HOC_CHANNEL;
163 priv->atim_window = 0;
164 priv->adhoc_state = ADHOC_IDLE;
165 priv->tx_power_level = 0;
166 priv->max_tx_power_level = 0;
167 priv->min_tx_power_level = 0;
169 priv->rxpd_htinfo = 0;
171 priv->rate_bitmap = 0;
172 priv->data_rssi_last = 0;
173 priv->data_rssi_avg = 0;
174 priv->data_nf_avg = 0;
175 priv->data_nf_last = 0;
176 priv->bcn_rssi_last = 0;
177 priv->bcn_rssi_avg = 0;
178 priv->bcn_nf_avg = 0;
179 priv->bcn_nf_last = 0;
180 memset(&priv->wpa_ie, 0, sizeof(priv->wpa_ie));
181 memset(&priv->aes_key, 0, sizeof(priv->aes_key));
182 priv->wpa_ie_len = 0;
183 priv->wpa_is_gtk_set = false;
185 memset(&priv->assoc_tlv_buf, 0, sizeof(priv->assoc_tlv_buf));
186 priv->assoc_tlv_buf_len = 0;
187 memset(&priv->wps, 0, sizeof(priv->wps));
188 memset(&priv->gen_ie_buf, 0, sizeof(priv->gen_ie_buf));
189 priv->gen_ie_buf_len = 0;
190 memset(priv->vs_ie, 0, sizeof(priv->vs_ie));
192 priv->wmm_required = true;
193 priv->wmm_enabled = false;
194 priv->wmm_qosinfo = 0;
195 priv->curr_bcn_buf = NULL;
196 priv->curr_bcn_size = 0;
198 priv->wps_ie_len = 0;
200 priv->scan_block = false;
202 setup_timer(&priv->scan_delay_timer, scan_delay_timer_fn,
203 (unsigned long)priv);
205 return mwifiex_add_bss_prio_tbl(priv);
209 * This function allocates buffers for members of the adapter
212 * The memory allocated includes scan table, command buffers, and
213 * sleep confirm command buffer. In addition, the queues are
216 static int mwifiex_allocate_adapter(struct mwifiex_adapter *adapter)
220 /* Allocate command buffer */
221 ret = mwifiex_alloc_cmd_buffer(adapter);
223 dev_err(adapter->dev, "%s: failed to alloc cmd buffer\n",
229 dev_alloc_skb(sizeof(struct mwifiex_opt_sleep_confirm)
232 if (!adapter->sleep_cfm) {
233 dev_err(adapter->dev, "%s: failed to alloc sleep cfm"
234 " cmd buffer\n", __func__);
237 skb_reserve(adapter->sleep_cfm, INTF_HEADER_LEN);
243 * This function initializes the adapter structure and sets default
244 * values to the members of adapter.
246 * This also initializes the WMM related parameters in the driver private
249 static void mwifiex_init_adapter(struct mwifiex_adapter *adapter)
251 struct mwifiex_opt_sleep_confirm *sleep_cfm_buf = NULL;
253 skb_put(adapter->sleep_cfm, sizeof(struct mwifiex_opt_sleep_confirm));
255 adapter->cmd_sent = false;
257 if (adapter->iface_type == MWIFIEX_SDIO)
258 adapter->data_sent = true;
260 adapter->data_sent = false;
262 adapter->cmd_resp_received = false;
263 adapter->event_received = false;
264 adapter->data_received = false;
266 adapter->surprise_removed = false;
268 adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING;
270 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
271 adapter->ps_state = PS_STATE_AWAKE;
272 adapter->need_to_wakeup = false;
274 adapter->scan_mode = HostCmd_BSS_MODE_ANY;
275 adapter->specific_scan_time = MWIFIEX_SPECIFIC_SCAN_CHAN_TIME;
276 adapter->active_scan_time = MWIFIEX_ACTIVE_SCAN_CHAN_TIME;
277 adapter->passive_scan_time = MWIFIEX_PASSIVE_SCAN_CHAN_TIME;
279 adapter->scan_probes = 1;
281 adapter->multiple_dtim = 1;
283 adapter->local_listen_interval = 0; /* default value in firmware
286 adapter->is_deep_sleep = false;
288 adapter->delay_null_pkt = false;
289 adapter->delay_to_ps = 1000;
290 adapter->enhanced_ps_mode = PS_MODE_AUTO;
292 adapter->gen_null_pkt = false; /* Disable NULL Pkg generation by
294 adapter->pps_uapsd_mode = false; /* Disable pps/uapsd mode by
296 adapter->pm_wakeup_card_req = false;
298 adapter->pm_wakeup_fw_try = false;
300 adapter->max_tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K;
301 adapter->tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K;
302 adapter->curr_tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K;
304 adapter->is_hs_configured = false;
305 adapter->hs_cfg.conditions = cpu_to_le32(HOST_SLEEP_CFG_COND_DEF);
306 adapter->hs_cfg.gpio = HOST_SLEEP_CFG_GPIO_DEF;
307 adapter->hs_cfg.gap = HOST_SLEEP_CFG_GAP_DEF;
308 adapter->hs_activated = false;
310 memset(adapter->event_body, 0, sizeof(adapter->event_body));
311 adapter->hw_dot_11n_dev_cap = 0;
312 adapter->hw_dev_mcs_support = 0;
313 adapter->sec_chan_offset = 0;
314 adapter->adhoc_11n_enabled = false;
316 mwifiex_wmm_init(adapter);
318 if (adapter->sleep_cfm) {
319 sleep_cfm_buf = (struct mwifiex_opt_sleep_confirm *)
320 adapter->sleep_cfm->data;
321 memset(sleep_cfm_buf, 0, adapter->sleep_cfm->len);
322 sleep_cfm_buf->command =
323 cpu_to_le16(HostCmd_CMD_802_11_PS_MODE_ENH);
324 sleep_cfm_buf->size =
325 cpu_to_le16(adapter->sleep_cfm->len);
326 sleep_cfm_buf->result = 0;
327 sleep_cfm_buf->action = cpu_to_le16(SLEEP_CONFIRM);
328 sleep_cfm_buf->resp_ctrl = cpu_to_le16(RESP_NEEDED);
330 memset(&adapter->sleep_params, 0, sizeof(adapter->sleep_params));
331 memset(&adapter->sleep_period, 0, sizeof(adapter->sleep_period));
332 adapter->tx_lock_flag = false;
333 adapter->null_pkt_interval = 0;
334 adapter->fw_bands = 0;
335 adapter->config_bands = 0;
336 adapter->adhoc_start_band = 0;
337 adapter->scan_channels = NULL;
338 adapter->fw_release_number = 0;
339 adapter->fw_cap_info = 0;
340 memset(&adapter->upld_buf, 0, sizeof(adapter->upld_buf));
341 adapter->event_cause = 0;
342 adapter->region_code = 0;
343 adapter->bcn_miss_time_out = DEFAULT_BCN_MISS_TIMEOUT;
344 adapter->adhoc_awake_period = 0;
345 memset(&adapter->arp_filter, 0, sizeof(adapter->arp_filter));
346 adapter->arp_filter_size = 0;
347 adapter->channel_type = NL80211_CHAN_HT20;
348 adapter->max_mgmt_ie_index = MAX_MGMT_IE_INDEX;
352 * This function sets trans_start per tx_queue
354 void mwifiex_set_trans_start(struct net_device *dev)
358 for (i = 0; i < dev->num_tx_queues; i++)
359 netdev_get_tx_queue(dev, i)->trans_start = jiffies;
361 dev->trans_start = jiffies;
365 * This function wakes up all queues in net_device
367 void mwifiex_wake_up_net_dev_queue(struct net_device *netdev,
368 struct mwifiex_adapter *adapter)
370 unsigned long dev_queue_flags;
372 spin_lock_irqsave(&adapter->queue_lock, dev_queue_flags);
373 netif_tx_wake_all_queues(netdev);
374 spin_unlock_irqrestore(&adapter->queue_lock, dev_queue_flags);
378 * This function stops all queues in net_device
380 void mwifiex_stop_net_dev_queue(struct net_device *netdev,
381 struct mwifiex_adapter *adapter)
383 unsigned long dev_queue_flags;
385 spin_lock_irqsave(&adapter->queue_lock, dev_queue_flags);
386 netif_tx_stop_all_queues(netdev);
387 spin_unlock_irqrestore(&adapter->queue_lock, dev_queue_flags);
391 * This function releases the lock variables and frees the locks and
394 static void mwifiex_free_lock_list(struct mwifiex_adapter *adapter)
396 struct mwifiex_private *priv;
400 list_del(&adapter->cmd_free_q);
401 list_del(&adapter->cmd_pending_q);
402 list_del(&adapter->scan_pending_q);
404 for (i = 0; i < adapter->priv_num; i++)
405 list_del(&adapter->bss_prio_tbl[i].bss_prio_head);
407 for (i = 0; i < adapter->priv_num; i++) {
408 if (adapter->priv[i]) {
409 priv = adapter->priv[i];
410 for (j = 0; j < MAX_NUM_TID; ++j)
411 list_del(&priv->wmm.tid_tbl_ptr[j].ra_list);
412 list_del(&priv->tx_ba_stream_tbl_ptr);
413 list_del(&priv->rx_reorder_tbl_ptr);
419 * This function frees the adapter structure.
421 * The freeing operation is done recursively, by canceling all
422 * pending commands, freeing the member buffers previously
423 * allocated (command buffers, scan table buffer, sleep confirm
424 * command buffer), stopping the timers and calling the cleanup
425 * routines for every interface, before the actual adapter
426 * structure is freed.
429 mwifiex_free_adapter(struct mwifiex_adapter *adapter)
432 pr_err("%s: adapter is NULL\n", __func__);
436 mwifiex_cancel_all_pending_cmd(adapter);
438 /* Free lock variables */
439 mwifiex_free_lock_list(adapter);
441 /* Free command buffer */
442 dev_dbg(adapter->dev, "info: free cmd buffer\n");
443 mwifiex_free_cmd_buffer(adapter);
445 del_timer(&adapter->cmd_timer);
447 dev_dbg(adapter->dev, "info: free scan table\n");
449 if (adapter->if_ops.cleanup_if)
450 adapter->if_ops.cleanup_if(adapter);
452 if (adapter->sleep_cfm)
453 dev_kfree_skb_any(adapter->sleep_cfm);
457 * This function intializes the lock variables and
460 int mwifiex_init_lock_list(struct mwifiex_adapter *adapter)
462 struct mwifiex_private *priv;
465 spin_lock_init(&adapter->mwifiex_lock);
466 spin_lock_init(&adapter->int_lock);
467 spin_lock_init(&adapter->main_proc_lock);
468 spin_lock_init(&adapter->mwifiex_cmd_lock);
469 spin_lock_init(&adapter->queue_lock);
470 for (i = 0; i < adapter->priv_num; i++) {
471 if (adapter->priv[i]) {
472 priv = adapter->priv[i];
473 spin_lock_init(&priv->rx_pkt_lock);
474 spin_lock_init(&priv->wmm.ra_list_spinlock);
475 spin_lock_init(&priv->curr_bcn_buf_lock);
479 /* Initialize cmd_free_q */
480 INIT_LIST_HEAD(&adapter->cmd_free_q);
481 /* Initialize cmd_pending_q */
482 INIT_LIST_HEAD(&adapter->cmd_pending_q);
483 /* Initialize scan_pending_q */
484 INIT_LIST_HEAD(&adapter->scan_pending_q);
486 spin_lock_init(&adapter->cmd_free_q_lock);
487 spin_lock_init(&adapter->cmd_pending_q_lock);
488 spin_lock_init(&adapter->scan_pending_q_lock);
490 skb_queue_head_init(&adapter->usb_rx_data_q);
492 for (i = 0; i < adapter->priv_num; ++i) {
493 INIT_LIST_HEAD(&adapter->bss_prio_tbl[i].bss_prio_head);
494 adapter->bss_prio_tbl[i].bss_prio_cur = NULL;
495 spin_lock_init(&adapter->bss_prio_tbl[i].bss_prio_lock);
498 for (i = 0; i < adapter->priv_num; i++) {
499 if (!adapter->priv[i])
501 priv = adapter->priv[i];
502 for (j = 0; j < MAX_NUM_TID; ++j) {
503 INIT_LIST_HEAD(&priv->wmm.tid_tbl_ptr[j].ra_list);
504 spin_lock_init(&priv->wmm.tid_tbl_ptr[j].tid_tbl_lock);
506 INIT_LIST_HEAD(&priv->tx_ba_stream_tbl_ptr);
507 INIT_LIST_HEAD(&priv->rx_reorder_tbl_ptr);
509 spin_lock_init(&priv->tx_ba_stream_tbl_lock);
510 spin_lock_init(&priv->rx_reorder_tbl_lock);
517 * This function initializes the firmware.
519 * The following operations are performed sequentially -
520 * - Allocate adapter structure
521 * - Initialize the adapter structure
522 * - Initialize the private structure
523 * - Add BSS priority tables to the adapter structure
524 * - For each interface, send the init commands to firmware
525 * - Send the first command in command pending queue, if available
527 int mwifiex_init_fw(struct mwifiex_adapter *adapter)
530 struct mwifiex_private *priv;
531 u8 i, first_sta = true;
532 int is_cmd_pend_q_empty;
535 adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING;
537 /* Allocate memory for member of adapter structure */
538 ret = mwifiex_allocate_adapter(adapter);
542 /* Initialize adapter structure */
543 mwifiex_init_adapter(adapter);
545 for (i = 0; i < adapter->priv_num; i++) {
546 if (adapter->priv[i]) {
547 priv = adapter->priv[i];
549 /* Initialize private structure */
550 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);
565 spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags);
566 is_cmd_pend_q_empty = list_empty(&adapter->cmd_pending_q);
567 spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, flags);
568 if (!is_cmd_pend_q_empty) {
569 /* Send the first command in queue and return */
570 if (mwifiex_main_process(adapter) != -1)
573 adapter->hw_status = MWIFIEX_HW_STATUS_READY;
580 * This function deletes the BSS priority tables.
582 * The function traverses through all the allocated BSS priority nodes
583 * in every BSS priority table and frees them.
585 static void mwifiex_delete_bss_prio_tbl(struct mwifiex_private *priv)
588 struct mwifiex_adapter *adapter = priv->adapter;
589 struct mwifiex_bss_prio_node *bssprio_node, *tmp_node, **cur;
590 struct list_head *head;
591 spinlock_t *lock; /* bss priority lock */
594 for (i = 0; i < adapter->priv_num; ++i) {
595 head = &adapter->bss_prio_tbl[i].bss_prio_head;
596 cur = &adapter->bss_prio_tbl[i].bss_prio_cur;
597 lock = &adapter->bss_prio_tbl[i].bss_prio_lock;
598 dev_dbg(adapter->dev, "info: delete BSS priority table,"
599 " bss_type = %d, bss_num = %d, i = %d,"
600 " head = %p, cur = %p\n",
601 priv->bss_type, priv->bss_num, i, head, *cur);
603 spin_lock_irqsave(lock, flags);
604 if (list_empty(head)) {
605 spin_unlock_irqrestore(lock, flags);
608 bssprio_node = list_first_entry(head,
609 struct mwifiex_bss_prio_node, list);
610 spin_unlock_irqrestore(lock, flags);
612 list_for_each_entry_safe(bssprio_node, tmp_node, head,
614 if (bssprio_node->priv == priv) {
615 dev_dbg(adapter->dev, "info: Delete "
616 "node %p, next = %p\n",
617 bssprio_node, tmp_node);
618 spin_lock_irqsave(lock, flags);
619 list_del(&bssprio_node->list);
620 spin_unlock_irqrestore(lock, flags);
624 *cur = (struct mwifiex_bss_prio_node *)head;
630 * This function is used to shutdown the driver.
632 * The following operations are performed sequentially -
633 * - Check if already shut down
634 * - Make sure the main process has stopped
635 * - Clean up the Tx and Rx queues
636 * - Delete BSS priority tables
638 * - Notify completion
641 mwifiex_shutdown_drv(struct mwifiex_adapter *adapter)
643 int ret = -EINPROGRESS;
644 struct mwifiex_private *priv;
649 /* mwifiex already shutdown */
650 if (adapter->hw_status == MWIFIEX_HW_STATUS_NOT_READY)
653 adapter->hw_status = MWIFIEX_HW_STATUS_CLOSING;
654 /* wait for mwifiex_process to complete */
655 if (adapter->mwifiex_processing) {
656 dev_warn(adapter->dev, "main process is still running\n");
660 /* shut down mwifiex */
661 dev_dbg(adapter->dev, "info: shutdown mwifiex...\n");
663 /* Clean up Tx/Rx queues and delete BSS priority table */
664 for (i = 0; i < adapter->priv_num; i++) {
665 if (adapter->priv[i]) {
666 priv = adapter->priv[i];
668 mwifiex_clean_txrx(priv);
669 mwifiex_delete_bss_prio_tbl(priv);
673 spin_lock_irqsave(&adapter->mwifiex_lock, flags);
675 if (adapter->if_ops.data_complete) {
676 while ((skb = skb_dequeue(&adapter->usb_rx_data_q))) {
677 struct mwifiex_rxinfo *rx_info = MWIFIEX_SKB_RXCB(skb);
679 priv = adapter->priv[rx_info->bss_num];
681 priv->stats.rx_dropped++;
683 adapter->if_ops.data_complete(adapter, skb);
687 /* Free adapter structure */
688 mwifiex_free_adapter(adapter);
690 spin_unlock_irqrestore(&adapter->mwifiex_lock, flags);
692 /* Notify completion */
693 ret = mwifiex_shutdown_fw_complete(adapter);
699 * This function downloads the firmware to the card.
701 * The actual download is preceded by two sanity checks -
702 * - Check if firmware is already running
703 * - Check if the interface is the winner to download the firmware
705 * ...and followed by another -
706 * - Check if the firmware is downloaded successfully
708 * After download is successfully completed, the host interrupts are enabled.
710 int mwifiex_dnld_fw(struct mwifiex_adapter *adapter,
711 struct mwifiex_fw_image *pmfw)
716 if (adapter->if_ops.check_fw_status) {
719 /* check if firmware is already running */
720 ret = adapter->if_ops.check_fw_status(adapter, poll_num);
722 dev_notice(adapter->dev,
723 "WLAN FW already running! Skip FW dnld\n");
727 poll_num = MAX_FIRMWARE_POLL_TRIES;
729 /* check if we are the winner for downloading FW */
730 if (!adapter->winner) {
731 dev_notice(adapter->dev,
732 "FW already running! Skip FW dnld\n");
733 poll_num = MAX_MULTI_INTERFACE_POLL_TRIES;
739 /* Download firmware with helper */
740 ret = adapter->if_ops.prog_fw(adapter, pmfw);
742 dev_err(adapter->dev, "prog_fw failed ret=%#x\n", ret);
748 /* Check if the firmware is downloaded successfully or not */
749 ret = adapter->if_ops.check_fw_status(adapter, poll_num);
751 dev_err(adapter->dev, "FW failed to be active in time\n");
755 /* re-enable host interrupt for mwifiex after fw dnld is successful */
756 if (adapter->if_ops.enable_int)
757 adapter->if_ops.enable_int(adapter);