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
->max_mgmt_ie_index
= MAX_MGMT_IE_INDEX
;
351 * This function sets trans_start per tx_queue
353 void mwifiex_set_trans_start(struct net_device
*dev
)
357 for (i
= 0; i
< dev
->num_tx_queues
; i
++)
358 netdev_get_tx_queue(dev
, i
)->trans_start
= jiffies
;
360 dev
->trans_start
= jiffies
;
364 * This function wakes up all queues in net_device
366 void mwifiex_wake_up_net_dev_queue(struct net_device
*netdev
,
367 struct mwifiex_adapter
*adapter
)
369 unsigned long dev_queue_flags
;
371 spin_lock_irqsave(&adapter
->queue_lock
, dev_queue_flags
);
372 netif_tx_wake_all_queues(netdev
);
373 spin_unlock_irqrestore(&adapter
->queue_lock
, dev_queue_flags
);
377 * This function stops all queues in net_device
379 void mwifiex_stop_net_dev_queue(struct net_device
*netdev
,
380 struct mwifiex_adapter
*adapter
)
382 unsigned long dev_queue_flags
;
384 spin_lock_irqsave(&adapter
->queue_lock
, dev_queue_flags
);
385 netif_tx_stop_all_queues(netdev
);
386 spin_unlock_irqrestore(&adapter
->queue_lock
, dev_queue_flags
);
390 * This function releases the lock variables and frees the locks and
393 static void mwifiex_free_lock_list(struct mwifiex_adapter
*adapter
)
395 struct mwifiex_private
*priv
;
399 list_del(&adapter
->cmd_free_q
);
400 list_del(&adapter
->cmd_pending_q
);
401 list_del(&adapter
->scan_pending_q
);
403 for (i
= 0; i
< adapter
->priv_num
; i
++)
404 list_del(&adapter
->bss_prio_tbl
[i
].bss_prio_head
);
406 for (i
= 0; i
< adapter
->priv_num
; i
++) {
407 if (adapter
->priv
[i
]) {
408 priv
= adapter
->priv
[i
];
409 for (j
= 0; j
< MAX_NUM_TID
; ++j
)
410 list_del(&priv
->wmm
.tid_tbl_ptr
[j
].ra_list
);
411 list_del(&priv
->tx_ba_stream_tbl_ptr
);
412 list_del(&priv
->rx_reorder_tbl_ptr
);
418 * This function frees the adapter structure.
420 * The freeing operation is done recursively, by canceling all
421 * pending commands, freeing the member buffers previously
422 * allocated (command buffers, scan table buffer, sleep confirm
423 * command buffer), stopping the timers and calling the cleanup
424 * routines for every interface, before the actual adapter
425 * structure is freed.
428 mwifiex_free_adapter(struct mwifiex_adapter
*adapter
)
431 pr_err("%s: adapter is NULL\n", __func__
);
435 mwifiex_cancel_all_pending_cmd(adapter
);
437 /* Free lock variables */
438 mwifiex_free_lock_list(adapter
);
440 /* Free command buffer */
441 dev_dbg(adapter
->dev
, "info: free cmd buffer\n");
442 mwifiex_free_cmd_buffer(adapter
);
444 del_timer(&adapter
->cmd_timer
);
446 dev_dbg(adapter
->dev
, "info: free scan table\n");
448 if (adapter
->if_ops
.cleanup_if
)
449 adapter
->if_ops
.cleanup_if(adapter
);
451 if (adapter
->sleep_cfm
)
452 dev_kfree_skb_any(adapter
->sleep_cfm
);
456 * This function intializes the lock variables and
459 int mwifiex_init_lock_list(struct mwifiex_adapter
*adapter
)
461 struct mwifiex_private
*priv
;
464 spin_lock_init(&adapter
->mwifiex_lock
);
465 spin_lock_init(&adapter
->int_lock
);
466 spin_lock_init(&adapter
->main_proc_lock
);
467 spin_lock_init(&adapter
->mwifiex_cmd_lock
);
468 spin_lock_init(&adapter
->queue_lock
);
469 for (i
= 0; i
< adapter
->priv_num
; i
++) {
470 if (adapter
->priv
[i
]) {
471 priv
= adapter
->priv
[i
];
472 spin_lock_init(&priv
->rx_pkt_lock
);
473 spin_lock_init(&priv
->wmm
.ra_list_spinlock
);
474 spin_lock_init(&priv
->curr_bcn_buf_lock
);
478 /* Initialize cmd_free_q */
479 INIT_LIST_HEAD(&adapter
->cmd_free_q
);
480 /* Initialize cmd_pending_q */
481 INIT_LIST_HEAD(&adapter
->cmd_pending_q
);
482 /* Initialize scan_pending_q */
483 INIT_LIST_HEAD(&adapter
->scan_pending_q
);
485 spin_lock_init(&adapter
->cmd_free_q_lock
);
486 spin_lock_init(&adapter
->cmd_pending_q_lock
);
487 spin_lock_init(&adapter
->scan_pending_q_lock
);
489 skb_queue_head_init(&adapter
->usb_rx_data_q
);
491 for (i
= 0; i
< adapter
->priv_num
; ++i
) {
492 INIT_LIST_HEAD(&adapter
->bss_prio_tbl
[i
].bss_prio_head
);
493 adapter
->bss_prio_tbl
[i
].bss_prio_cur
= NULL
;
494 spin_lock_init(&adapter
->bss_prio_tbl
[i
].bss_prio_lock
);
497 for (i
= 0; i
< adapter
->priv_num
; i
++) {
498 if (!adapter
->priv
[i
])
500 priv
= adapter
->priv
[i
];
501 for (j
= 0; j
< MAX_NUM_TID
; ++j
) {
502 INIT_LIST_HEAD(&priv
->wmm
.tid_tbl_ptr
[j
].ra_list
);
503 spin_lock_init(&priv
->wmm
.tid_tbl_ptr
[j
].tid_tbl_lock
);
505 INIT_LIST_HEAD(&priv
->tx_ba_stream_tbl_ptr
);
506 INIT_LIST_HEAD(&priv
->rx_reorder_tbl_ptr
);
508 spin_lock_init(&priv
->tx_ba_stream_tbl_lock
);
509 spin_lock_init(&priv
->rx_reorder_tbl_lock
);
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
);
554 for (i
= 0; i
< adapter
->priv_num
; i
++) {
555 if (adapter
->priv
[i
]) {
556 ret
= mwifiex_sta_init_cmd(adapter
->priv
[i
], first_sta
);
564 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, flags
);
565 is_cmd_pend_q_empty
= list_empty(&adapter
->cmd_pending_q
);
566 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
, flags
);
567 if (!is_cmd_pend_q_empty
) {
568 /* Send the first command in queue and return */
569 if (mwifiex_main_process(adapter
) != -1)
572 adapter
->hw_status
= MWIFIEX_HW_STATUS_READY
;
579 * This function deletes the BSS priority tables.
581 * The function traverses through all the allocated BSS priority nodes
582 * in every BSS priority table and frees them.
584 static void mwifiex_delete_bss_prio_tbl(struct mwifiex_private
*priv
)
587 struct mwifiex_adapter
*adapter
= priv
->adapter
;
588 struct mwifiex_bss_prio_node
*bssprio_node
, *tmp_node
, **cur
;
589 struct list_head
*head
;
590 spinlock_t
*lock
; /* bss priority lock */
593 for (i
= 0; i
< adapter
->priv_num
; ++i
) {
594 head
= &adapter
->bss_prio_tbl
[i
].bss_prio_head
;
595 cur
= &adapter
->bss_prio_tbl
[i
].bss_prio_cur
;
596 lock
= &adapter
->bss_prio_tbl
[i
].bss_prio_lock
;
597 dev_dbg(adapter
->dev
, "info: delete BSS priority table,"
598 " bss_type = %d, bss_num = %d, i = %d,"
599 " head = %p, cur = %p\n",
600 priv
->bss_type
, priv
->bss_num
, i
, head
, *cur
);
602 spin_lock_irqsave(lock
, flags
);
603 if (list_empty(head
)) {
604 spin_unlock_irqrestore(lock
, flags
);
607 bssprio_node
= list_first_entry(head
,
608 struct mwifiex_bss_prio_node
, list
);
609 spin_unlock_irqrestore(lock
, flags
);
611 list_for_each_entry_safe(bssprio_node
, tmp_node
, head
,
613 if (bssprio_node
->priv
== priv
) {
614 dev_dbg(adapter
->dev
, "info: Delete "
615 "node %p, next = %p\n",
616 bssprio_node
, tmp_node
);
617 spin_lock_irqsave(lock
, flags
);
618 list_del(&bssprio_node
->list
);
619 spin_unlock_irqrestore(lock
, flags
);
623 *cur
= (struct mwifiex_bss_prio_node
*)head
;
629 * This function is used to shutdown the driver.
631 * The following operations are performed sequentially -
632 * - Check if already shut down
633 * - Make sure the main process has stopped
634 * - Clean up the Tx and Rx queues
635 * - Delete BSS priority tables
637 * - Notify completion
640 mwifiex_shutdown_drv(struct mwifiex_adapter
*adapter
)
642 int ret
= -EINPROGRESS
;
643 struct mwifiex_private
*priv
;
648 /* mwifiex already shutdown */
649 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_NOT_READY
)
652 adapter
->hw_status
= MWIFIEX_HW_STATUS_CLOSING
;
653 /* wait for mwifiex_process to complete */
654 if (adapter
->mwifiex_processing
) {
655 dev_warn(adapter
->dev
, "main process is still running\n");
659 /* shut down mwifiex */
660 dev_dbg(adapter
->dev
, "info: shutdown mwifiex...\n");
662 /* Clean up Tx/Rx queues and delete BSS priority table */
663 for (i
= 0; i
< adapter
->priv_num
; i
++) {
664 if (adapter
->priv
[i
]) {
665 priv
= adapter
->priv
[i
];
667 mwifiex_clean_txrx(priv
);
668 mwifiex_delete_bss_prio_tbl(priv
);
672 spin_lock_irqsave(&adapter
->mwifiex_lock
, flags
);
674 if (adapter
->if_ops
.data_complete
) {
675 while ((skb
= skb_dequeue(&adapter
->usb_rx_data_q
))) {
676 struct mwifiex_rxinfo
*rx_info
= MWIFIEX_SKB_RXCB(skb
);
678 priv
= adapter
->priv
[rx_info
->bss_num
];
680 priv
->stats
.rx_dropped
++;
682 adapter
->if_ops
.data_complete(adapter
, skb
);
686 /* Free adapter structure */
687 mwifiex_free_adapter(adapter
);
689 spin_unlock_irqrestore(&adapter
->mwifiex_lock
, flags
);
691 /* Notify completion */
692 ret
= mwifiex_shutdown_fw_complete(adapter
);
698 * This function downloads the firmware to the card.
700 * The actual download is preceded by two sanity checks -
701 * - Check if firmware is already running
702 * - Check if the interface is the winner to download the firmware
704 * ...and followed by another -
705 * - Check if the firmware is downloaded successfully
707 * After download is successfully completed, the host interrupts are enabled.
709 int mwifiex_dnld_fw(struct mwifiex_adapter
*adapter
,
710 struct mwifiex_fw_image
*pmfw
)
715 if (adapter
->if_ops
.check_fw_status
) {
718 /* check if firmware is already running */
719 ret
= adapter
->if_ops
.check_fw_status(adapter
, poll_num
);
721 dev_notice(adapter
->dev
,
722 "WLAN FW already running! Skip FW dnld\n");
726 poll_num
= MAX_FIRMWARE_POLL_TRIES
;
728 /* check if we are the winner for downloading FW */
729 if (!adapter
->winner
) {
730 dev_notice(adapter
->dev
,
731 "FW already running! Skip FW dnld\n");
732 poll_num
= MAX_MULTI_INTERFACE_POLL_TRIES
;
738 /* Download firmware with helper */
739 ret
= adapter
->if_ops
.prog_fw(adapter
, pmfw
);
741 dev_err(adapter
->dev
, "prog_fw failed ret=%#x\n", ret
);
747 /* Check if the firmware is downloaded successfully or not */
748 ret
= adapter
->if_ops
.check_fw_status(adapter
, poll_num
);
750 dev_err(adapter
->dev
, "FW failed to be active in time\n");
754 /* re-enable host interrupt for mwifiex after fw dnld is successful */
755 if (adapter
->if_ops
.enable_int
)
756 adapter
->if_ops
.enable_int(adapter
);