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 (adapter
->scan_delay_cnt
== MWIFIEX_MAX_SCAN_DELAY_CNT
) {
69 * Abort scan operation by cancelling all pending scan
72 spin_lock_irqsave(&adapter
->scan_pending_q_lock
, flags
);
73 list_for_each_entry_safe(cmd_node
, tmp_node
,
74 &adapter
->scan_pending_q
, list
) {
75 list_del(&cmd_node
->list
);
76 mwifiex_insert_cmd_to_free_q(adapter
, cmd_node
);
78 spin_unlock_irqrestore(&adapter
->scan_pending_q_lock
, flags
);
80 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
81 adapter
->scan_processing
= false;
82 adapter
->scan_delay_cnt
= 0;
83 adapter
->empty_tx_q_cnt
= 0;
84 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
86 if (priv
->user_scan_cfg
) {
87 dev_dbg(priv
->adapter
->dev
,
88 "info: %s: scan aborted\n", __func__
);
89 cfg80211_scan_done(priv
->scan_request
, 1);
90 priv
->scan_request
= NULL
;
91 kfree(priv
->user_scan_cfg
);
92 priv
->user_scan_cfg
= NULL
;
95 if (priv
->scan_pending_on_block
) {
96 priv
->scan_pending_on_block
= false;
102 if (!atomic_read(&priv
->adapter
->is_tx_received
)) {
103 adapter
->empty_tx_q_cnt
++;
104 if (adapter
->empty_tx_q_cnt
== MWIFIEX_MAX_EMPTY_TX_Q_CNT
) {
106 * No Tx traffic for 200msec. Get scan command from
107 * scan pending queue and put to cmd pending queue to
108 * resume scan operation
110 adapter
->scan_delay_cnt
= 0;
111 adapter
->empty_tx_q_cnt
= 0;
112 spin_lock_irqsave(&adapter
->scan_pending_q_lock
, flags
);
113 cmd_node
= list_first_entry(&adapter
->scan_pending_q
,
114 struct cmd_ctrl_node
, list
);
115 list_del(&cmd_node
->list
);
116 spin_unlock_irqrestore(&adapter
->scan_pending_q_lock
,
119 mwifiex_insert_cmd_to_pending_q(adapter
, cmd_node
,
121 queue_work(adapter
->workqueue
, &adapter
->main_work
);
125 adapter
->empty_tx_q_cnt
= 0;
128 /* Delay scan operation further by 20msec */
129 mod_timer(&priv
->scan_delay_timer
, jiffies
+
130 msecs_to_jiffies(MWIFIEX_SCAN_DELAY_MSEC
));
131 adapter
->scan_delay_cnt
++;
134 if (atomic_read(&priv
->adapter
->is_tx_received
))
135 atomic_set(&priv
->adapter
->is_tx_received
, false);
141 * This function initializes the private structure and sets default
142 * values to the members.
144 * Additionally, it also initializes all the locks and sets up all the
147 int mwifiex_init_priv(struct mwifiex_private
*priv
)
151 priv
->media_connected
= false;
152 memset(priv
->curr_addr
, 0xff, ETH_ALEN
);
154 priv
->pkt_tx_ctrl
= 0;
155 priv
->bss_mode
= NL80211_IFTYPE_UNSPECIFIED
;
156 priv
->data_rate
= 0; /* Initially indicate the rate as auto */
157 priv
->is_data_rate_auto
= true;
158 priv
->bcn_avg_factor
= DEFAULT_BCN_AVG_FACTOR
;
159 priv
->data_avg_factor
= DEFAULT_DATA_AVG_FACTOR
;
161 priv
->sec_info
.wep_enabled
= 0;
162 priv
->sec_info
.authentication_mode
= NL80211_AUTHTYPE_OPEN_SYSTEM
;
163 priv
->sec_info
.encryption_mode
= 0;
164 for (i
= 0; i
< ARRAY_SIZE(priv
->wep_key
); i
++)
165 memset(&priv
->wep_key
[i
], 0, sizeof(struct mwifiex_wep_key
));
166 priv
->wep_key_curr_index
= 0;
167 priv
->curr_pkt_filter
= HostCmd_ACT_MAC_RX_ON
| HostCmd_ACT_MAC_TX_ON
|
168 HostCmd_ACT_MAC_ETHERNETII_ENABLE
;
170 priv
->beacon_period
= 100; /* beacon interval */ ;
171 priv
->attempted_bss_desc
= NULL
;
172 memset(&priv
->curr_bss_params
, 0, sizeof(priv
->curr_bss_params
));
173 priv
->listen_interval
= MWIFIEX_DEFAULT_LISTEN_INTERVAL
;
175 memset(&priv
->prev_ssid
, 0, sizeof(priv
->prev_ssid
));
176 memset(&priv
->prev_bssid
, 0, sizeof(priv
->prev_bssid
));
177 memset(&priv
->assoc_rsp_buf
, 0, sizeof(priv
->assoc_rsp_buf
));
178 priv
->assoc_rsp_size
= 0;
179 priv
->adhoc_channel
= DEFAULT_AD_HOC_CHANNEL
;
180 priv
->atim_window
= 0;
181 priv
->adhoc_state
= ADHOC_IDLE
;
182 priv
->tx_power_level
= 0;
183 priv
->max_tx_power_level
= 0;
184 priv
->min_tx_power_level
= 0;
186 priv
->rxpd_htinfo
= 0;
188 priv
->rate_bitmap
= 0;
189 priv
->data_rssi_last
= 0;
190 priv
->data_rssi_avg
= 0;
191 priv
->data_nf_avg
= 0;
192 priv
->data_nf_last
= 0;
193 priv
->bcn_rssi_last
= 0;
194 priv
->bcn_rssi_avg
= 0;
195 priv
->bcn_nf_avg
= 0;
196 priv
->bcn_nf_last
= 0;
197 memset(&priv
->wpa_ie
, 0, sizeof(priv
->wpa_ie
));
198 memset(&priv
->aes_key
, 0, sizeof(priv
->aes_key
));
199 priv
->wpa_ie_len
= 0;
200 priv
->wpa_is_gtk_set
= false;
202 memset(&priv
->assoc_tlv_buf
, 0, sizeof(priv
->assoc_tlv_buf
));
203 priv
->assoc_tlv_buf_len
= 0;
204 memset(&priv
->wps
, 0, sizeof(priv
->wps
));
205 memset(&priv
->gen_ie_buf
, 0, sizeof(priv
->gen_ie_buf
));
206 priv
->gen_ie_buf_len
= 0;
207 memset(priv
->vs_ie
, 0, sizeof(priv
->vs_ie
));
209 priv
->wmm_required
= true;
210 priv
->wmm_enabled
= false;
211 priv
->wmm_qosinfo
= 0;
212 priv
->curr_bcn_buf
= NULL
;
213 priv
->curr_bcn_size
= 0;
215 priv
->wps_ie_len
= 0;
216 priv
->ap_11n_enabled
= 0;
217 memset(&priv
->roc_cfg
, 0, sizeof(priv
->roc_cfg
));
219 priv
->scan_block
= false;
221 setup_timer(&priv
->scan_delay_timer
, scan_delay_timer_fn
,
222 (unsigned long)priv
);
224 return mwifiex_add_bss_prio_tbl(priv
);
228 * This function allocates buffers for members of the adapter
231 * The memory allocated includes scan table, command buffers, and
232 * sleep confirm command buffer. In addition, the queues are
235 static int mwifiex_allocate_adapter(struct mwifiex_adapter
*adapter
)
239 /* Allocate command buffer */
240 ret
= mwifiex_alloc_cmd_buffer(adapter
);
242 dev_err(adapter
->dev
, "%s: failed to alloc cmd buffer\n",
248 dev_alloc_skb(sizeof(struct mwifiex_opt_sleep_confirm
)
251 if (!adapter
->sleep_cfm
) {
252 dev_err(adapter
->dev
, "%s: failed to alloc sleep cfm"
253 " cmd buffer\n", __func__
);
256 skb_reserve(adapter
->sleep_cfm
, INTF_HEADER_LEN
);
262 * This function initializes the adapter structure and sets default
263 * values to the members of adapter.
265 * This also initializes the WMM related parameters in the driver private
268 static void mwifiex_init_adapter(struct mwifiex_adapter
*adapter
)
270 struct mwifiex_opt_sleep_confirm
*sleep_cfm_buf
= NULL
;
272 skb_put(adapter
->sleep_cfm
, sizeof(struct mwifiex_opt_sleep_confirm
));
274 adapter
->cmd_sent
= false;
276 if (adapter
->iface_type
== MWIFIEX_SDIO
)
277 adapter
->data_sent
= true;
279 adapter
->data_sent
= false;
281 adapter
->cmd_resp_received
= false;
282 adapter
->event_received
= false;
283 adapter
->data_received
= false;
285 adapter
->surprise_removed
= false;
287 adapter
->hw_status
= MWIFIEX_HW_STATUS_INITIALIZING
;
289 adapter
->ps_mode
= MWIFIEX_802_11_POWER_MODE_CAM
;
290 adapter
->ps_state
= PS_STATE_AWAKE
;
291 adapter
->need_to_wakeup
= false;
293 adapter
->scan_mode
= HostCmd_BSS_MODE_ANY
;
294 adapter
->specific_scan_time
= MWIFIEX_SPECIFIC_SCAN_CHAN_TIME
;
295 adapter
->active_scan_time
= MWIFIEX_ACTIVE_SCAN_CHAN_TIME
;
296 adapter
->passive_scan_time
= MWIFIEX_PASSIVE_SCAN_CHAN_TIME
;
298 adapter
->scan_probes
= 1;
300 adapter
->multiple_dtim
= 1;
302 adapter
->local_listen_interval
= 0; /* default value in firmware
305 adapter
->is_deep_sleep
= false;
307 adapter
->delay_null_pkt
= false;
308 adapter
->delay_to_ps
= 1000;
309 adapter
->enhanced_ps_mode
= PS_MODE_AUTO
;
311 adapter
->gen_null_pkt
= false; /* Disable NULL Pkg generation by
313 adapter
->pps_uapsd_mode
= false; /* Disable pps/uapsd mode by
315 adapter
->pm_wakeup_card_req
= false;
317 adapter
->pm_wakeup_fw_try
= false;
319 adapter
->max_tx_buf_size
= MWIFIEX_TX_DATA_BUF_SIZE_2K
;
320 adapter
->tx_buf_size
= MWIFIEX_TX_DATA_BUF_SIZE_2K
;
321 adapter
->curr_tx_buf_size
= MWIFIEX_TX_DATA_BUF_SIZE_2K
;
323 adapter
->is_hs_configured
= false;
324 adapter
->hs_cfg
.conditions
= cpu_to_le32(HOST_SLEEP_CFG_COND_DEF
);
325 adapter
->hs_cfg
.gpio
= HOST_SLEEP_CFG_GPIO_DEF
;
326 adapter
->hs_cfg
.gap
= HOST_SLEEP_CFG_GAP_DEF
;
327 adapter
->hs_activated
= false;
329 memset(adapter
->event_body
, 0, sizeof(adapter
->event_body
));
330 adapter
->hw_dot_11n_dev_cap
= 0;
331 adapter
->hw_dev_mcs_support
= 0;
332 adapter
->sec_chan_offset
= 0;
333 adapter
->adhoc_11n_enabled
= false;
335 mwifiex_wmm_init(adapter
);
337 if (adapter
->sleep_cfm
) {
338 sleep_cfm_buf
= (struct mwifiex_opt_sleep_confirm
*)
339 adapter
->sleep_cfm
->data
;
340 memset(sleep_cfm_buf
, 0, adapter
->sleep_cfm
->len
);
341 sleep_cfm_buf
->command
=
342 cpu_to_le16(HostCmd_CMD_802_11_PS_MODE_ENH
);
343 sleep_cfm_buf
->size
=
344 cpu_to_le16(adapter
->sleep_cfm
->len
);
345 sleep_cfm_buf
->result
= 0;
346 sleep_cfm_buf
->action
= cpu_to_le16(SLEEP_CONFIRM
);
347 sleep_cfm_buf
->resp_ctrl
= cpu_to_le16(RESP_NEEDED
);
349 memset(&adapter
->sleep_params
, 0, sizeof(adapter
->sleep_params
));
350 memset(&adapter
->sleep_period
, 0, sizeof(adapter
->sleep_period
));
351 adapter
->tx_lock_flag
= false;
352 adapter
->null_pkt_interval
= 0;
353 adapter
->fw_bands
= 0;
354 adapter
->config_bands
= 0;
355 adapter
->adhoc_start_band
= 0;
356 adapter
->scan_channels
= NULL
;
357 adapter
->fw_release_number
= 0;
358 adapter
->fw_cap_info
= 0;
359 memset(&adapter
->upld_buf
, 0, sizeof(adapter
->upld_buf
));
360 adapter
->event_cause
= 0;
361 adapter
->region_code
= 0;
362 adapter
->bcn_miss_time_out
= DEFAULT_BCN_MISS_TIMEOUT
;
363 adapter
->adhoc_awake_period
= 0;
364 memset(&adapter
->arp_filter
, 0, sizeof(adapter
->arp_filter
));
365 adapter
->arp_filter_size
= 0;
366 adapter
->max_mgmt_ie_index
= MAX_MGMT_IE_INDEX
;
367 adapter
->empty_tx_q_cnt
= 0;
371 * This function sets trans_start per tx_queue
373 void mwifiex_set_trans_start(struct net_device
*dev
)
377 for (i
= 0; i
< dev
->num_tx_queues
; i
++)
378 netdev_get_tx_queue(dev
, i
)->trans_start
= jiffies
;
380 dev
->trans_start
= jiffies
;
384 * This function wakes up all queues in net_device
386 void mwifiex_wake_up_net_dev_queue(struct net_device
*netdev
,
387 struct mwifiex_adapter
*adapter
)
389 unsigned long dev_queue_flags
;
391 spin_lock_irqsave(&adapter
->queue_lock
, dev_queue_flags
);
392 netif_tx_wake_all_queues(netdev
);
393 spin_unlock_irqrestore(&adapter
->queue_lock
, dev_queue_flags
);
397 * This function stops all queues in net_device
399 void mwifiex_stop_net_dev_queue(struct net_device
*netdev
,
400 struct mwifiex_adapter
*adapter
)
402 unsigned long dev_queue_flags
;
404 spin_lock_irqsave(&adapter
->queue_lock
, dev_queue_flags
);
405 netif_tx_stop_all_queues(netdev
);
406 spin_unlock_irqrestore(&adapter
->queue_lock
, dev_queue_flags
);
410 * This function releases the lock variables and frees the locks and
413 static void mwifiex_free_lock_list(struct mwifiex_adapter
*adapter
)
415 struct mwifiex_private
*priv
;
419 list_del(&adapter
->cmd_free_q
);
420 list_del(&adapter
->cmd_pending_q
);
421 list_del(&adapter
->scan_pending_q
);
423 for (i
= 0; i
< adapter
->priv_num
; i
++)
424 list_del(&adapter
->bss_prio_tbl
[i
].bss_prio_head
);
426 for (i
= 0; i
< adapter
->priv_num
; i
++) {
427 if (adapter
->priv
[i
]) {
428 priv
= adapter
->priv
[i
];
429 for (j
= 0; j
< MAX_NUM_TID
; ++j
)
430 list_del(&priv
->wmm
.tid_tbl_ptr
[j
].ra_list
);
431 list_del(&priv
->tx_ba_stream_tbl_ptr
);
432 list_del(&priv
->rx_reorder_tbl_ptr
);
433 list_del(&priv
->sta_list
);
439 * This function frees the adapter structure.
441 * The freeing operation is done recursively, by canceling all
442 * pending commands, freeing the member buffers previously
443 * allocated (command buffers, scan table buffer, sleep confirm
444 * command buffer), stopping the timers and calling the cleanup
445 * routines for every interface, before the actual adapter
446 * structure is freed.
449 mwifiex_free_adapter(struct mwifiex_adapter
*adapter
)
452 pr_err("%s: adapter is NULL\n", __func__
);
456 mwifiex_cancel_all_pending_cmd(adapter
);
458 /* Free lock variables */
459 mwifiex_free_lock_list(adapter
);
461 /* Free command buffer */
462 dev_dbg(adapter
->dev
, "info: free cmd buffer\n");
463 mwifiex_free_cmd_buffer(adapter
);
465 del_timer(&adapter
->cmd_timer
);
467 dev_dbg(adapter
->dev
, "info: free scan table\n");
469 if (adapter
->if_ops
.cleanup_if
)
470 adapter
->if_ops
.cleanup_if(adapter
);
472 if (adapter
->sleep_cfm
)
473 dev_kfree_skb_any(adapter
->sleep_cfm
);
477 * This function intializes the lock variables and
480 int mwifiex_init_lock_list(struct mwifiex_adapter
*adapter
)
482 struct mwifiex_private
*priv
;
485 spin_lock_init(&adapter
->mwifiex_lock
);
486 spin_lock_init(&adapter
->int_lock
);
487 spin_lock_init(&adapter
->main_proc_lock
);
488 spin_lock_init(&adapter
->mwifiex_cmd_lock
);
489 spin_lock_init(&adapter
->queue_lock
);
490 for (i
= 0; i
< adapter
->priv_num
; i
++) {
491 if (adapter
->priv
[i
]) {
492 priv
= adapter
->priv
[i
];
493 spin_lock_init(&priv
->rx_pkt_lock
);
494 spin_lock_init(&priv
->wmm
.ra_list_spinlock
);
495 spin_lock_init(&priv
->curr_bcn_buf_lock
);
496 spin_lock_init(&priv
->sta_list_spinlock
);
500 /* Initialize cmd_free_q */
501 INIT_LIST_HEAD(&adapter
->cmd_free_q
);
502 /* Initialize cmd_pending_q */
503 INIT_LIST_HEAD(&adapter
->cmd_pending_q
);
504 /* Initialize scan_pending_q */
505 INIT_LIST_HEAD(&adapter
->scan_pending_q
);
507 spin_lock_init(&adapter
->cmd_free_q_lock
);
508 spin_lock_init(&adapter
->cmd_pending_q_lock
);
509 spin_lock_init(&adapter
->scan_pending_q_lock
);
511 skb_queue_head_init(&adapter
->usb_rx_data_q
);
513 for (i
= 0; i
< adapter
->priv_num
; ++i
) {
514 INIT_LIST_HEAD(&adapter
->bss_prio_tbl
[i
].bss_prio_head
);
515 adapter
->bss_prio_tbl
[i
].bss_prio_cur
= NULL
;
516 spin_lock_init(&adapter
->bss_prio_tbl
[i
].bss_prio_lock
);
519 for (i
= 0; i
< adapter
->priv_num
; i
++) {
520 if (!adapter
->priv
[i
])
522 priv
= adapter
->priv
[i
];
523 for (j
= 0; j
< MAX_NUM_TID
; ++j
) {
524 INIT_LIST_HEAD(&priv
->wmm
.tid_tbl_ptr
[j
].ra_list
);
525 spin_lock_init(&priv
->wmm
.tid_tbl_ptr
[j
].tid_tbl_lock
);
527 INIT_LIST_HEAD(&priv
->tx_ba_stream_tbl_ptr
);
528 INIT_LIST_HEAD(&priv
->rx_reorder_tbl_ptr
);
529 INIT_LIST_HEAD(&priv
->sta_list
);
531 spin_lock_init(&priv
->tx_ba_stream_tbl_lock
);
532 spin_lock_init(&priv
->rx_reorder_tbl_lock
);
539 * This function initializes the firmware.
541 * The following operations are performed sequentially -
542 * - Allocate adapter structure
543 * - Initialize the adapter structure
544 * - Initialize the private structure
545 * - Add BSS priority tables to the adapter structure
546 * - For each interface, send the init commands to firmware
547 * - Send the first command in command pending queue, if available
549 int mwifiex_init_fw(struct mwifiex_adapter
*adapter
)
552 struct mwifiex_private
*priv
;
553 u8 i
, first_sta
= true;
554 int is_cmd_pend_q_empty
;
557 adapter
->hw_status
= MWIFIEX_HW_STATUS_INITIALIZING
;
559 /* Allocate memory for member of adapter structure */
560 ret
= mwifiex_allocate_adapter(adapter
);
564 /* Initialize adapter structure */
565 mwifiex_init_adapter(adapter
);
567 for (i
= 0; i
< adapter
->priv_num
; i
++) {
568 if (adapter
->priv
[i
]) {
569 priv
= adapter
->priv
[i
];
571 /* Initialize private structure */
572 ret
= mwifiex_init_priv(priv
);
577 for (i
= 0; i
< adapter
->priv_num
; i
++) {
578 if (adapter
->priv
[i
]) {
579 ret
= mwifiex_sta_init_cmd(adapter
->priv
[i
], first_sta
);
587 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, flags
);
588 is_cmd_pend_q_empty
= list_empty(&adapter
->cmd_pending_q
);
589 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
, flags
);
590 if (!is_cmd_pend_q_empty
) {
591 /* Send the first command in queue and return */
592 if (mwifiex_main_process(adapter
) != -1)
595 adapter
->hw_status
= MWIFIEX_HW_STATUS_READY
;
602 * This function deletes the BSS priority tables.
604 * The function traverses through all the allocated BSS priority nodes
605 * in every BSS priority table and frees them.
607 static void mwifiex_delete_bss_prio_tbl(struct mwifiex_private
*priv
)
610 struct mwifiex_adapter
*adapter
= priv
->adapter
;
611 struct mwifiex_bss_prio_node
*bssprio_node
, *tmp_node
, **cur
;
612 struct list_head
*head
;
613 spinlock_t
*lock
; /* bss priority lock */
616 for (i
= 0; i
< adapter
->priv_num
; ++i
) {
617 head
= &adapter
->bss_prio_tbl
[i
].bss_prio_head
;
618 cur
= &adapter
->bss_prio_tbl
[i
].bss_prio_cur
;
619 lock
= &adapter
->bss_prio_tbl
[i
].bss_prio_lock
;
620 dev_dbg(adapter
->dev
, "info: delete BSS priority table,"
621 " bss_type = %d, bss_num = %d, i = %d,"
622 " head = %p, cur = %p\n",
623 priv
->bss_type
, priv
->bss_num
, i
, head
, *cur
);
625 spin_lock_irqsave(lock
, flags
);
626 if (list_empty(head
)) {
627 spin_unlock_irqrestore(lock
, flags
);
630 bssprio_node
= list_first_entry(head
,
631 struct mwifiex_bss_prio_node
, list
);
632 spin_unlock_irqrestore(lock
, flags
);
634 list_for_each_entry_safe(bssprio_node
, tmp_node
, head
,
636 if (bssprio_node
->priv
== priv
) {
637 dev_dbg(adapter
->dev
, "info: Delete "
638 "node %p, next = %p\n",
639 bssprio_node
, tmp_node
);
640 spin_lock_irqsave(lock
, flags
);
641 list_del(&bssprio_node
->list
);
642 spin_unlock_irqrestore(lock
, flags
);
646 *cur
= (struct mwifiex_bss_prio_node
*)head
;
652 * This function frees the private structure, including cleans
653 * up the TX and RX queues and frees the BSS priority tables.
655 void mwifiex_free_priv(struct mwifiex_private
*priv
)
657 mwifiex_clean_txrx(priv
);
658 mwifiex_delete_bss_prio_tbl(priv
);
659 mwifiex_free_curr_bcn(priv
);
663 * This function is used to shutdown the driver.
665 * The following operations are performed sequentially -
666 * - Check if already shut down
667 * - Make sure the main process has stopped
668 * - Clean up the Tx and Rx queues
669 * - Delete BSS priority tables
671 * - Notify completion
674 mwifiex_shutdown_drv(struct mwifiex_adapter
*adapter
)
676 int ret
= -EINPROGRESS
;
677 struct mwifiex_private
*priv
;
682 /* mwifiex already shutdown */
683 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_NOT_READY
)
686 adapter
->hw_status
= MWIFIEX_HW_STATUS_CLOSING
;
687 /* wait for mwifiex_process to complete */
688 if (adapter
->mwifiex_processing
) {
689 dev_warn(adapter
->dev
, "main process is still running\n");
693 /* shut down mwifiex */
694 dev_dbg(adapter
->dev
, "info: shutdown mwifiex...\n");
696 /* Clean up Tx/Rx queues and delete BSS priority table */
697 for (i
= 0; i
< adapter
->priv_num
; i
++) {
698 if (adapter
->priv
[i
]) {
699 priv
= adapter
->priv
[i
];
701 mwifiex_clean_txrx(priv
);
702 mwifiex_delete_bss_prio_tbl(priv
);
706 spin_lock_irqsave(&adapter
->mwifiex_lock
, flags
);
708 if (adapter
->if_ops
.data_complete
) {
709 while ((skb
= skb_dequeue(&adapter
->usb_rx_data_q
))) {
710 struct mwifiex_rxinfo
*rx_info
= MWIFIEX_SKB_RXCB(skb
);
712 priv
= adapter
->priv
[rx_info
->bss_num
];
714 priv
->stats
.rx_dropped
++;
716 adapter
->if_ops
.data_complete(adapter
, skb
);
720 /* Free adapter structure */
721 mwifiex_free_adapter(adapter
);
723 spin_unlock_irqrestore(&adapter
->mwifiex_lock
, flags
);
725 /* Notify completion */
726 ret
= mwifiex_shutdown_fw_complete(adapter
);
732 * This function downloads the firmware to the card.
734 * The actual download is preceded by two sanity checks -
735 * - Check if firmware is already running
736 * - Check if the interface is the winner to download the firmware
738 * ...and followed by another -
739 * - Check if the firmware is downloaded successfully
741 * After download is successfully completed, the host interrupts are enabled.
743 int mwifiex_dnld_fw(struct mwifiex_adapter
*adapter
,
744 struct mwifiex_fw_image
*pmfw
)
749 if (adapter
->if_ops
.check_fw_status
) {
752 /* check if firmware is already running */
753 ret
= adapter
->if_ops
.check_fw_status(adapter
, poll_num
);
755 dev_notice(adapter
->dev
,
756 "WLAN FW already running! Skip FW dnld\n");
760 poll_num
= MAX_FIRMWARE_POLL_TRIES
;
762 /* check if we are the winner for downloading FW */
763 if (!adapter
->winner
) {
764 dev_notice(adapter
->dev
,
765 "FW already running! Skip FW dnld\n");
766 poll_num
= MAX_MULTI_INTERFACE_POLL_TRIES
;
772 /* Download firmware with helper */
773 ret
= adapter
->if_ops
.prog_fw(adapter
, pmfw
);
775 dev_err(adapter
->dev
, "prog_fw failed ret=%#x\n", ret
);
781 /* Check if the firmware is downloaded successfully or not */
782 ret
= adapter
->if_ops
.check_fw_status(adapter
, poll_num
);
784 dev_err(adapter
->dev
, "FW failed to be active in time\n");
788 /* re-enable host interrupt for mwifiex after fw dnld is successful */
789 if (adapter
->if_ops
.enable_int
)
790 adapter
->if_ops
.enable_int(adapter
);