]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - drivers/net/wireless/marvell/mwifiex/init.c
mwifiex: fix misnomers in mwifiex_free_lock_list()
[mirror_ubuntu-jammy-kernel.git] / drivers / net / wireless / marvell / mwifiex / init.c
CommitLineData
5e6e3a92
BZ
1/*
2 * Marvell Wireless LAN device driver: HW/FW Initialization
3 *
65da33f5 4 * Copyright (C) 2011-2014, Marvell International Ltd.
5e6e3a92
BZ
5 *
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.
13 *
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.
18 */
19
20#include "decl.h"
21#include "ioctl.h"
22#include "util.h"
23#include "fw.h"
24#include "main.h"
25#include "wmm.h"
26#include "11n.h"
27
28/*
29 * This function adds a BSS priority table to the table list.
30 *
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.
33 */
34static int mwifiex_add_bss_prio_tbl(struct mwifiex_private *priv)
35{
36 struct mwifiex_adapter *adapter = priv->adapter;
37 struct mwifiex_bss_prio_node *bss_prio;
931f1584 38 struct mwifiex_bss_prio_tbl *tbl = adapter->bss_prio_tbl;
5e6e3a92
BZ
39 unsigned long flags;
40
41 bss_prio = kzalloc(sizeof(struct mwifiex_bss_prio_node), GFP_KERNEL);
0d2e7a5c 42 if (!bss_prio)
b53575ec 43 return -ENOMEM;
5e6e3a92
BZ
44
45 bss_prio->priv = priv;
46 INIT_LIST_HEAD(&bss_prio->list);
931f1584
YAP
47
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);
5e6e3a92 51
600f5d90 52 return 0;
5e6e3a92
BZ
53}
54
4636187d
AK
55static void wakeup_timer_fn(unsigned long data)
56{
57 struct mwifiex_adapter *adapter = (struct mwifiex_adapter *)data;
58
acebe8c1 59 mwifiex_dbg(adapter, ERROR, "Firmware wakeup failed\n");
4636187d
AK
60 adapter->hw_status = MWIFIEX_HW_STATUS_RESET;
61 mwifiex_cancel_all_pending_cmd(adapter);
62
437322ea 63 if (adapter->if_ops.card_reset && !adapter->hs_activated)
4636187d
AK
64 adapter->if_ops.card_reset(adapter);
65}
66
5e6e3a92
BZ
67/*
68 * This function initializes the private structure and sets default
69 * values to the members.
70 *
71 * Additionally, it also initializes all the locks and sets up all the
72 * lists.
73 */
9197ab9e 74int mwifiex_init_priv(struct mwifiex_private *priv)
5e6e3a92
BZ
75{
76 u32 i;
5e6e3a92
BZ
77
78 priv->media_connected = false;
93803b33 79 eth_broadcast_addr(priv->curr_addr);
5c894633 80 priv->port_open = false;
2b0f997d 81 priv->usb_port = MWIFIEX_USB_EP_DATA;
5e6e3a92 82 priv->pkt_tx_ctrl = 0;
93a1df48 83 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
5e6e3a92
BZ
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;
88
5eb02e44 89 priv->sec_info.wep_enabled = 0;
f986b6d5 90 priv->sec_info.authentication_mode = NL80211_AUTHTYPE_OPEN_SYSTEM;
2be50b8d 91 priv->sec_info.encryption_mode = 0;
5e6e3a92
BZ
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;
d7864cf2
AK
95 priv->curr_pkt_filter = HostCmd_ACT_MAC_DYNAMIC_BW_ENABLE |
96 HostCmd_ACT_MAC_RX_ON | HostCmd_ACT_MAC_TX_ON |
5e6e3a92
BZ
97 HostCmd_ACT_MAC_ETHERNETII_ENABLE;
98
fc30c305 99 priv->beacon_period = 100; /* beacon interval */
5e6e3a92
BZ
100 priv->attempted_bss_desc = NULL;
101 memset(&priv->curr_bss_params, 0, sizeof(priv->curr_bss_params));
102 priv->listen_interval = MWIFIEX_DEFAULT_LISTEN_INTERVAL;
103
104 memset(&priv->prev_ssid, 0, sizeof(priv->prev_ssid));
105 memset(&priv->prev_bssid, 0, sizeof(priv->prev_bssid));
106 memset(&priv->assoc_rsp_buf, 0, sizeof(priv->assoc_rsp_buf));
107 priv->assoc_rsp_size = 0;
108 priv->adhoc_channel = DEFAULT_AD_HOC_CHANNEL;
109 priv->atim_window = 0;
110 priv->adhoc_state = ADHOC_IDLE;
111 priv->tx_power_level = 0;
112 priv->max_tx_power_level = 0;
113 priv->min_tx_power_level = 0;
3ee71285
SL
114 priv->tx_ant = 0;
115 priv->rx_ant = 0;
5e6e3a92
BZ
116 priv->tx_rate = 0;
117 priv->rxpd_htinfo = 0;
118 priv->rxpd_rate = 0;
119 priv->rate_bitmap = 0;
120 priv->data_rssi_last = 0;
121 priv->data_rssi_avg = 0;
122 priv->data_nf_avg = 0;
123 priv->data_nf_last = 0;
124 priv->bcn_rssi_last = 0;
125 priv->bcn_rssi_avg = 0;
126 priv->bcn_nf_avg = 0;
127 priv->bcn_nf_last = 0;
128 memset(&priv->wpa_ie, 0, sizeof(priv->wpa_ie));
129 memset(&priv->aes_key, 0, sizeof(priv->aes_key));
130 priv->wpa_ie_len = 0;
131 priv->wpa_is_gtk_set = false;
132
133 memset(&priv->assoc_tlv_buf, 0, sizeof(priv->assoc_tlv_buf));
134 priv->assoc_tlv_buf_len = 0;
135 memset(&priv->wps, 0, sizeof(priv->wps));
136 memset(&priv->gen_ie_buf, 0, sizeof(priv->gen_ie_buf));
137 priv->gen_ie_buf_len = 0;
138 memset(priv->vs_ie, 0, sizeof(priv->vs_ie));
139
140 priv->wmm_required = true;
141 priv->wmm_enabled = false;
142 priv->wmm_qosinfo = 0;
143 priv->curr_bcn_buf = NULL;
144 priv->curr_bcn_size = 0;
13d7ba78
AP
145 priv->wps_ie = NULL;
146 priv->wps_ie_len = 0;
c8258913 147 priv->ap_11n_enabled = 0;
7feb4c48 148 memset(&priv->roc_cfg, 0, sizeof(priv->roc_cfg));
5e6e3a92
BZ
149
150 priv->scan_block = false;
151
b887664d
AK
152 priv->csa_chan = 0;
153 priv->csa_expire_time = 0;
61c87304 154 priv->del_list_idx = 0;
587b36d3 155 priv->hs2_enabled = false;
9927baa3 156 priv->check_tdls_tx = false;
41a24a29 157 memcpy(priv->tos_to_tid_inv, tos_to_tid_inv, MAX_NUM_TID);
b887664d 158
cf075eac
AP
159 mwifiex_init_11h_params(priv);
160
636c4598 161 return mwifiex_add_bss_prio_tbl(priv);
5e6e3a92
BZ
162}
163
164/*
165 * This function allocates buffers for members of the adapter
166 * structure.
167 *
168 * The memory allocated includes scan table, command buffers, and
169 * sleep confirm command buffer. In addition, the queues are
170 * also initialized.
171 */
172static int mwifiex_allocate_adapter(struct mwifiex_adapter *adapter)
173{
270e58e8 174 int ret;
5e6e3a92
BZ
175
176 /* Allocate command buffer */
177 ret = mwifiex_alloc_cmd_buffer(adapter);
178 if (ret) {
acebe8c1
ZL
179 mwifiex_dbg(adapter, ERROR,
180 "%s: failed to alloc cmd buffer\n",
181 __func__);
5e6e3a92
BZ
182 return -1;
183 }
184
185 adapter->sleep_cfm =
7cc5eb62 186 dev_alloc_skb(sizeof(struct mwifiex_opt_sleep_confirm)
931f1584 187 + INTF_HEADER_LEN);
5e6e3a92
BZ
188
189 if (!adapter->sleep_cfm) {
acebe8c1
ZL
190 mwifiex_dbg(adapter, ERROR,
191 "%s: failed to alloc sleep cfm\t"
192 " cmd buffer\n", __func__);
5e6e3a92
BZ
193 return -1;
194 }
195 skb_reserve(adapter->sleep_cfm, INTF_HEADER_LEN);
196
197 return 0;
198}
199
200/*
201 * This function initializes the adapter structure and sets default
202 * values to the members of adapter.
203 *
204 * This also initializes the WMM related parameters in the driver private
205 * structures.
206 */
207static void mwifiex_init_adapter(struct mwifiex_adapter *adapter)
208{
7cc5eb62 209 struct mwifiex_opt_sleep_confirm *sleep_cfm_buf = NULL;
5e6e3a92 210
7cc5eb62 211 skb_put(adapter->sleep_cfm, sizeof(struct mwifiex_opt_sleep_confirm));
5e6e3a92
BZ
212
213 adapter->cmd_sent = false;
d930faee 214
4daffe35 215 if (adapter->iface_type == MWIFIEX_SDIO)
d930faee 216 adapter->data_sent = true;
4daffe35
AK
217 else
218 adapter->data_sent = false;
d930faee 219
f4c5d599
XH
220 if (adapter->iface_type == MWIFIEX_USB)
221 adapter->intf_hdr_len = 0;
222 else
223 adapter->intf_hdr_len = INTF_HEADER_LEN;
224
5e6e3a92
BZ
225 adapter->cmd_resp_received = false;
226 adapter->event_received = false;
227 adapter->data_received = false;
228
229 adapter->surprise_removed = false;
230
231 adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING;
232
233 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
234 adapter->ps_state = PS_STATE_AWAKE;
235 adapter->need_to_wakeup = false;
236
237 adapter->scan_mode = HostCmd_BSS_MODE_ANY;
238 adapter->specific_scan_time = MWIFIEX_SPECIFIC_SCAN_CHAN_TIME;
239 adapter->active_scan_time = MWIFIEX_ACTIVE_SCAN_CHAN_TIME;
240 adapter->passive_scan_time = MWIFIEX_PASSIVE_SCAN_CHAN_TIME;
cb91be87 241 adapter->scan_chan_gap_time = MWIFIEX_DEF_SCAN_CHAN_GAP_TIME;
5e6e3a92 242
5e6e3a92
BZ
243 adapter->scan_probes = 1;
244
5e6e3a92
BZ
245 adapter->multiple_dtim = 1;
246
247 adapter->local_listen_interval = 0; /* default value in firmware
248 will be used */
249
250 adapter->is_deep_sleep = false;
251
252 adapter->delay_null_pkt = false;
253 adapter->delay_to_ps = 1000;
254 adapter->enhanced_ps_mode = PS_MODE_AUTO;
255
256 adapter->gen_null_pkt = false; /* Disable NULL Pkg generation by
257 default */
258 adapter->pps_uapsd_mode = false; /* Disable pps/uapsd mode by
259 default */
260 adapter->pm_wakeup_card_req = false;
261
262 adapter->pm_wakeup_fw_try = false;
263
5e6e3a92
BZ
264 adapter->curr_tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K;
265
266 adapter->is_hs_configured = false;
cc0b5a64
AK
267 adapter->hs_cfg.conditions = cpu_to_le32(HS_CFG_COND_DEF);
268 adapter->hs_cfg.gpio = HS_CFG_GPIO_DEF;
269 adapter->hs_cfg.gap = HS_CFG_GAP_DEF;
5e6e3a92
BZ
270 adapter->hs_activated = false;
271
272 memset(adapter->event_body, 0, sizeof(adapter->event_body));
273 adapter->hw_dot_11n_dev_cap = 0;
274 adapter->hw_dev_mcs_support = 0;
21c3ba34 275 adapter->sec_chan_offset = 0;
5e6e3a92
BZ
276 adapter->adhoc_11n_enabled = false;
277
278 mwifiex_wmm_init(adapter);
eb2428fb 279 atomic_set(&adapter->tx_hw_pending, 0);
5e6e3a92 280
2d7defb0
DC
281 sleep_cfm_buf = (struct mwifiex_opt_sleep_confirm *)
282 adapter->sleep_cfm->data;
283 memset(sleep_cfm_buf, 0, adapter->sleep_cfm->len);
284 sleep_cfm_buf->command = cpu_to_le16(HostCmd_CMD_802_11_PS_MODE_ENH);
285 sleep_cfm_buf->size = cpu_to_le16(adapter->sleep_cfm->len);
286 sleep_cfm_buf->result = 0;
287 sleep_cfm_buf->action = cpu_to_le16(SLEEP_CONFIRM);
288 sleep_cfm_buf->resp_ctrl = cpu_to_le16(RESP_NEEDED);
289
5e6e3a92
BZ
290 memset(&adapter->sleep_params, 0, sizeof(adapter->sleep_params));
291 memset(&adapter->sleep_period, 0, sizeof(adapter->sleep_period));
292 adapter->tx_lock_flag = false;
293 adapter->null_pkt_interval = 0;
294 adapter->fw_bands = 0;
295 adapter->config_bands = 0;
296 adapter->adhoc_start_band = 0;
297 adapter->scan_channels = NULL;
298 adapter->fw_release_number = 0;
299 adapter->fw_cap_info = 0;
300 memset(&adapter->upld_buf, 0, sizeof(adapter->upld_buf));
301 adapter->event_cause = 0;
302 adapter->region_code = 0;
303 adapter->bcn_miss_time_out = DEFAULT_BCN_MISS_TIMEOUT;
304 adapter->adhoc_awake_period = 0;
305 memset(&adapter->arp_filter, 0, sizeof(adapter->arp_filter));
306 adapter->arp_filter_size = 0;
ede98bfa 307 adapter->max_mgmt_ie_index = MAX_MGMT_IE_INDEX;
cf5383b0 308 adapter->mfg_mode = mfg_mode;
4b9fede5
AK
309 adapter->key_api_major_ver = 0;
310 adapter->key_api_minor_ver = 0;
93803b33 311 eth_broadcast_addr(adapter->perm_addr);
cf052335
AP
312 adapter->iface_limit.sta_intf = MWIFIEX_MAX_STA_NUM;
313 adapter->iface_limit.uap_intf = MWIFIEX_MAX_UAP_NUM;
314 adapter->iface_limit.p2p_intf = MWIFIEX_MAX_P2P_NUM;
2375fa2b 315 adapter->active_scan_triggered = false;
4636187d
AK
316 setup_timer(&adapter->wakeup_timer, wakeup_timer_fn,
317 (unsigned long)adapter);
5e6e3a92
BZ
318}
319
bbea3bc4
AP
320/*
321 * This function sets trans_start per tx_queue
322 */
323void mwifiex_set_trans_start(struct net_device *dev)
324{
325 int i;
326
327 for (i = 0; i < dev->num_tx_queues; i++)
328 netdev_get_tx_queue(dev, i)->trans_start = jiffies;
329
860e9538 330 netif_trans_update(dev);
bbea3bc4
AP
331}
332
333/*
334 * This function wakes up all queues in net_device
335 */
336void mwifiex_wake_up_net_dev_queue(struct net_device *netdev,
337 struct mwifiex_adapter *adapter)
338{
339 unsigned long dev_queue_flags;
47411a06 340 unsigned int i;
bbea3bc4
AP
341
342 spin_lock_irqsave(&adapter->queue_lock, dev_queue_flags);
47411a06
AP
343
344 for (i = 0; i < netdev->num_tx_queues; i++) {
345 struct netdev_queue *txq = netdev_get_tx_queue(netdev, i);
346
347 if (netif_tx_queue_stopped(txq))
348 netif_tx_wake_queue(txq);
349 }
350
bbea3bc4
AP
351 spin_unlock_irqrestore(&adapter->queue_lock, dev_queue_flags);
352}
353
354/*
355 * This function stops all queues in net_device
356 */
357void mwifiex_stop_net_dev_queue(struct net_device *netdev,
358 struct mwifiex_adapter *adapter)
359{
360 unsigned long dev_queue_flags;
47411a06 361 unsigned int i;
bbea3bc4
AP
362
363 spin_lock_irqsave(&adapter->queue_lock, dev_queue_flags);
47411a06
AP
364
365 for (i = 0; i < netdev->num_tx_queues; i++) {
366 struct netdev_queue *txq = netdev_get_tx_queue(netdev, i);
367
368 if (!netif_tx_queue_stopped(txq))
369 netif_tx_stop_queue(txq);
370 }
371
bbea3bc4
AP
372 spin_unlock_irqrestore(&adapter->queue_lock, dev_queue_flags);
373}
374
711825a0 375/*
5e6588b9 376 * This function invalidates the list heads.
711825a0 377 */
5e6588b9 378static void mwifiex_invalidate_lists(struct mwifiex_adapter *adapter)
711825a0
AK
379{
380 struct mwifiex_private *priv;
381 s32 i, j;
382
711825a0
AK
383 list_del(&adapter->cmd_free_q);
384 list_del(&adapter->cmd_pending_q);
385 list_del(&adapter->scan_pending_q);
386
387 for (i = 0; i < adapter->priv_num; i++)
388 list_del(&adapter->bss_prio_tbl[i].bss_prio_head);
389
390 for (i = 0; i < adapter->priv_num; i++) {
391 if (adapter->priv[i]) {
392 priv = adapter->priv[i];
393 for (j = 0; j < MAX_NUM_TID; ++j)
394 list_del(&priv->wmm.tid_tbl_ptr[j].ra_list);
395 list_del(&priv->tx_ba_stream_tbl_ptr);
396 list_del(&priv->rx_reorder_tbl_ptr);
017a92a1 397 list_del(&priv->sta_list);
9927baa3 398 list_del(&priv->auto_tdls_list);
711825a0
AK
399 }
400 }
401}
402
5e6e3a92 403/*
c56ecf5a 404 * This function performs cleanup for adapter structure.
5e6e3a92 405 *
c56ecf5a
AK
406 * The cleanup is done recursively, by canceling all pending
407 * commands, freeing the member buffers previously allocated
408 * (command buffers, scan table buffer, sleep confirm command
409 * buffer), stopping the timers and calling the cleanup routines
410 * for every interface.
5e6e3a92
BZ
411 */
412static void
c56ecf5a 413mwifiex_adapter_cleanup(struct mwifiex_adapter *adapter)
5e6e3a92 414{
4636187d 415 del_timer(&adapter->wakeup_timer);
5e6e3a92 416 mwifiex_cancel_all_pending_cmd(adapter);
fc647467
AK
417 wake_up_interruptible(&adapter->cmd_wait_q.wait);
418 wake_up_interruptible(&adapter->hs_activate_wait_q);
ce32d1d8 419}
5e6e3a92 420
ce32d1d8
BN
421void mwifiex_free_cmd_buffers(struct mwifiex_adapter *adapter)
422{
5e6588b9 423 mwifiex_invalidate_lists(adapter);
5e6e3a92
BZ
424
425 /* Free command buffer */
acebe8c1 426 mwifiex_dbg(adapter, INFO, "info: free cmd buffer\n");
5e6e3a92
BZ
427 mwifiex_free_cmd_buffer(adapter);
428
2da8cbf8
AK
429 if (adapter->sleep_cfm)
430 dev_kfree_skb_any(adapter->sleep_cfm);
5e6e3a92
BZ
431}
432
433/*
434 * This function intializes the lock variables and
435 * the list heads.
436 */
437int mwifiex_init_lock_list(struct mwifiex_adapter *adapter)
438{
270e58e8
YAP
439 struct mwifiex_private *priv;
440 s32 i, j;
5e6e3a92 441
5e6e3a92
BZ
442 spin_lock_init(&adapter->int_lock);
443 spin_lock_init(&adapter->main_proc_lock);
444 spin_lock_init(&adapter->mwifiex_cmd_lock);
bbea3bc4 445 spin_lock_init(&adapter->queue_lock);
5e6e3a92
BZ
446 for (i = 0; i < adapter->priv_num; i++) {
447 if (adapter->priv[i]) {
448 priv = adapter->priv[i];
449 spin_lock_init(&priv->rx_pkt_lock);
450 spin_lock_init(&priv->wmm.ra_list_spinlock);
451 spin_lock_init(&priv->curr_bcn_buf_lock);
017a92a1 452 spin_lock_init(&priv->sta_list_spinlock);
9927baa3 453 spin_lock_init(&priv->auto_tdls_lock);
5e6e3a92
BZ
454 }
455 }
456
457 /* Initialize cmd_free_q */
458 INIT_LIST_HEAD(&adapter->cmd_free_q);
459 /* Initialize cmd_pending_q */
460 INIT_LIST_HEAD(&adapter->cmd_pending_q);
461 /* Initialize scan_pending_q */
462 INIT_LIST_HEAD(&adapter->scan_pending_q);
463
464 spin_lock_init(&adapter->cmd_free_q_lock);
465 spin_lock_init(&adapter->cmd_pending_q_lock);
466 spin_lock_init(&adapter->scan_pending_q_lock);
6e251174 467 spin_lock_init(&adapter->rx_proc_lock);
5e6e3a92 468
6e251174 469 skb_queue_head_init(&adapter->rx_data_q);
e35000ea 470 skb_queue_head_init(&adapter->tx_data_q);
4daffe35 471
5e6e3a92
BZ
472 for (i = 0; i < adapter->priv_num; ++i) {
473 INIT_LIST_HEAD(&adapter->bss_prio_tbl[i].bss_prio_head);
5e6e3a92
BZ
474 spin_lock_init(&adapter->bss_prio_tbl[i].bss_prio_lock);
475 }
476
477 for (i = 0; i < adapter->priv_num; i++) {
478 if (!adapter->priv[i])
479 continue;
480 priv = adapter->priv[i];
6d2344ec 481 for (j = 0; j < MAX_NUM_TID; ++j)
5e6e3a92 482 INIT_LIST_HEAD(&priv->wmm.tid_tbl_ptr[j].ra_list);
5e6e3a92
BZ
483 INIT_LIST_HEAD(&priv->tx_ba_stream_tbl_ptr);
484 INIT_LIST_HEAD(&priv->rx_reorder_tbl_ptr);
017a92a1 485 INIT_LIST_HEAD(&priv->sta_list);
9927baa3 486 INIT_LIST_HEAD(&priv->auto_tdls_list);
56bd24a1 487 skb_queue_head_init(&priv->tdls_txq);
a1777327 488 skb_queue_head_init(&priv->bypass_txq);
5e6e3a92
BZ
489
490 spin_lock_init(&priv->tx_ba_stream_tbl_lock);
491 spin_lock_init(&priv->rx_reorder_tbl_lock);
808bbebc
AK
492
493 spin_lock_init(&priv->ack_status_lock);
494 idr_init(&priv->ack_status_frames);
5e6e3a92
BZ
495 }
496
497 return 0;
498}
499
5e6e3a92
BZ
500/*
501 * This function initializes the firmware.
502 *
503 * The following operations are performed sequentially -
504 * - Allocate adapter structure
505 * - Initialize the adapter structure
506 * - Initialize the private structure
507 * - Add BSS priority tables to the adapter structure
508 * - For each interface, send the init commands to firmware
509 * - Send the first command in command pending queue, if available
510 */
511int mwifiex_init_fw(struct mwifiex_adapter *adapter)
512{
270e58e8
YAP
513 int ret;
514 struct mwifiex_private *priv;
515 u8 i, first_sta = true;
5e6e3a92
BZ
516 int is_cmd_pend_q_empty;
517 unsigned long flags;
518
519 adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING;
520
521 /* Allocate memory for member of adapter structure */
522 ret = mwifiex_allocate_adapter(adapter);
523 if (ret)
524 return -1;
525
526 /* Initialize adapter structure */
527 mwifiex_init_adapter(adapter);
528
529 for (i = 0; i < adapter->priv_num; i++) {
530 if (adapter->priv[i]) {
531 priv = adapter->priv[i];
532
533 /* Initialize private structure */
534 ret = mwifiex_init_priv(priv);
535 if (ret)
536 return -1;
537 }
538 }
cf5383b0
XH
539 if (adapter->mfg_mode) {
540 adapter->hw_status = MWIFIEX_HW_STATUS_READY;
541 ret = -EINPROGRESS;
542 } else {
543 for (i = 0; i < adapter->priv_num; i++) {
544 if (adapter->priv[i]) {
545 ret = mwifiex_sta_init_cmd(adapter->priv[i],
546 first_sta, true);
547 if (ret == -1)
548 return -1;
549
550 first_sta = false;
551 }
552
c6d1d87a 553
5e6e3a92 554
5e6e3a92
BZ
555 }
556 }
557
558 spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags);
559 is_cmd_pend_q_empty = list_empty(&adapter->cmd_pending_q);
560 spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, flags);
561 if (!is_cmd_pend_q_empty) {
562 /* Send the first command in queue and return */
563 if (mwifiex_main_process(adapter) != -1)
564 ret = -EINPROGRESS;
565 } else {
566 adapter->hw_status = MWIFIEX_HW_STATUS_READY;
567 }
568
569 return ret;
570}
571
572/*
573 * This function deletes the BSS priority tables.
574 *
575 * The function traverses through all the allocated BSS priority nodes
576 * in every BSS priority table and frees them.
577 */
578static void mwifiex_delete_bss_prio_tbl(struct mwifiex_private *priv)
579{
580 int i;
581 struct mwifiex_adapter *adapter = priv->adapter;
b006ed54 582 struct mwifiex_bss_prio_node *bssprio_node, *tmp_node;
5e6e3a92 583 struct list_head *head;
931f1584 584 spinlock_t *lock; /* bss priority lock */
5e6e3a92
BZ
585 unsigned long flags;
586
587 for (i = 0; i < adapter->priv_num; ++i) {
588 head = &adapter->bss_prio_tbl[i].bss_prio_head;
5e6e3a92 589 lock = &adapter->bss_prio_tbl[i].bss_prio_lock;
acebe8c1
ZL
590 mwifiex_dbg(adapter, INFO,
591 "info: delete BSS priority table,\t"
592 "bss_type = %d, bss_num = %d, i = %d,\t"
593 "head = %p\n",
594 priv->bss_type, priv->bss_num, i, head);
b006ed54
AF
595
596 {
5e6e3a92
BZ
597 spin_lock_irqsave(lock, flags);
598 if (list_empty(head)) {
599 spin_unlock_irqrestore(lock, flags);
600 continue;
601 }
5e6e3a92
BZ
602 list_for_each_entry_safe(bssprio_node, tmp_node, head,
603 list) {
604 if (bssprio_node->priv == priv) {
acebe8c1
ZL
605 mwifiex_dbg(adapter, INFO,
606 "info: Delete\t"
607 "node %p, next = %p\n",
608 bssprio_node, tmp_node);
5e6e3a92 609 list_del(&bssprio_node->list);
5e6e3a92
BZ
610 kfree(bssprio_node);
611 }
612 }
b006ed54 613 spin_unlock_irqrestore(lock, flags);
5e6e3a92
BZ
614 }
615 }
616}
617
9197ab9e
SP
618/*
619 * This function frees the private structure, including cleans
620 * up the TX and RX queues and frees the BSS priority tables.
621 */
622void mwifiex_free_priv(struct mwifiex_private *priv)
623{
624 mwifiex_clean_txrx(priv);
625 mwifiex_delete_bss_prio_tbl(priv);
626 mwifiex_free_curr_bcn(priv);
627}
628
5e6e3a92
BZ
629/*
630 * This function is used to shutdown the driver.
631 *
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
637 * - Free the adapter
638 * - Notify completion
639 */
5bf15e3f 640void
5e6e3a92
BZ
641mwifiex_shutdown_drv(struct mwifiex_adapter *adapter)
642{
270e58e8
YAP
643 struct mwifiex_private *priv;
644 s32 i;
6e251174 645 unsigned long flags;
4daffe35 646 struct sk_buff *skb;
5e6e3a92
BZ
647
648 /* mwifiex already shutdown */
649 if (adapter->hw_status == MWIFIEX_HW_STATUS_NOT_READY)
5bf15e3f 650 return;
5e6e3a92 651
084c7189
BZ
652 /* cancel current command */
653 if (adapter->curr_cmd) {
acebe8c1
ZL
654 mwifiex_dbg(adapter, WARN,
655 "curr_cmd is still in processing\n");
629873f2 656 del_timer_sync(&adapter->cmd_timer);
9908b074 657 mwifiex_recycle_cmd_node(adapter, adapter->curr_cmd);
084c7189
BZ
658 adapter->curr_cmd = NULL;
659 }
660
5e6e3a92 661 /* shut down mwifiex */
acebe8c1
ZL
662 mwifiex_dbg(adapter, MSG,
663 "info: shutdown mwifiex...\n");
5e6e3a92
BZ
664
665 /* Clean up Tx/Rx queues and delete BSS priority table */
666 for (i = 0; i < adapter->priv_num; i++) {
667 if (adapter->priv[i]) {
668 priv = adapter->priv[i];
669
9927baa3 670 mwifiex_clean_auto_tdls(priv);
85afb186 671 mwifiex_abort_cac(priv);
6eb2d002 672 mwifiex_free_priv(priv);
5e6e3a92
BZ
673 }
674 }
675
e35000ea
ZL
676 atomic_set(&adapter->tx_queued, 0);
677 while ((skb = skb_dequeue(&adapter->tx_data_q)))
678 mwifiex_write_data_complete(adapter, skb, 0, 0);
679
6e251174
AP
680 spin_lock_irqsave(&adapter->rx_proc_lock, flags);
681
682 while ((skb = skb_dequeue(&adapter->rx_data_q))) {
683 struct mwifiex_rxinfo *rx_info = MWIFIEX_SKB_RXCB(skb);
684
685 atomic_dec(&adapter->rx_pending);
686 priv = adapter->priv[rx_info->bss_num];
687 if (priv)
688 priv->stats.rx_dropped++;
689
690 dev_kfree_skb_any(skb);
691 }
692
693 spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
694
c56ecf5a 695 mwifiex_adapter_cleanup(adapter);
5e6e3a92 696
5bf15e3f 697 adapter->hw_status = MWIFIEX_HW_STATUS_NOT_READY;
5e6e3a92
BZ
698}
699
700/*
701 * This function downloads the firmware to the card.
702 *
703 * The actual download is preceded by two sanity checks -
704 * - Check if firmware is already running
705 * - Check if the interface is the winner to download the firmware
706 *
707 * ...and followed by another -
708 * - Check if the firmware is downloaded successfully
709 *
710 * After download is successfully completed, the host interrupts are enabled.
711 */
712int mwifiex_dnld_fw(struct mwifiex_adapter *adapter,
713 struct mwifiex_fw_image *pmfw)
714{
d930faee 715 int ret;
5e6e3a92 716 u32 poll_num = 1;
5e6e3a92 717
4daffe35 718 if (adapter->if_ops.check_fw_status) {
4daffe35
AK
719 /* check if firmware is already running */
720 ret = adapter->if_ops.check_fw_status(adapter, poll_num);
721 if (!ret) {
acebe8c1
ZL
722 mwifiex_dbg(adapter, MSG,
723 "WLAN FW already running! Skip FW dnld\n");
232fde06 724 return 0;
4daffe35 725 }
2fd5c6ed 726 }
727
728 /* check if we are the winner for downloading FW */
729 if (adapter->if_ops.check_winner_status) {
730 adapter->winner = 0;
731 ret = adapter->if_ops.check_winner_status(adapter);
4daffe35
AK
732
733 poll_num = MAX_FIRMWARE_POLL_TRIES;
2fd5c6ed 734 if (ret) {
735 mwifiex_dbg(adapter, MSG,
736 "WLAN read winner status failed!\n");
737 return ret;
738 }
4daffe35 739
4daffe35 740 if (!adapter->winner) {
acebe8c1 741 mwifiex_dbg(adapter, MSG,
2fd5c6ed 742 "WLAN is not the winner! Skip FW dnld\n");
4daffe35
AK
743 goto poll_fw;
744 }
5e6e3a92 745 }
4daffe35 746
5e6e3a92
BZ
747 if (pmfw) {
748 /* Download firmware with helper */
749 ret = adapter->if_ops.prog_fw(adapter, pmfw);
750 if (ret) {
acebe8c1
ZL
751 mwifiex_dbg(adapter, ERROR,
752 "prog_fw failed ret=%#x\n", ret);
5e6e3a92
BZ
753 return ret;
754 }
755 }
756
757poll_fw:
758 /* Check if the firmware is downloaded successfully or not */
d930faee 759 ret = adapter->if_ops.check_fw_status(adapter, poll_num);
232fde06 760 if (ret)
acebe8c1
ZL
761 mwifiex_dbg(adapter, ERROR,
762 "FW failed to be active in time\n");
4daffe35 763
5e6e3a92
BZ
764 return ret;
765}
2095b142 766EXPORT_SYMBOL_GPL(mwifiex_dnld_fw);