blob: 1489c90192bd9f77ad6296159b718d61e1a63df7 [file] [log] [blame]
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001/*
2 * Marvell Wireless LAN device driver: HW/FW Initialization
3 *
Xinming Hu65da33f2014-06-19 21:38:57 -07004 * Copyright (C) 2011-2014, Marvell International Ltd.
Bing Zhao5e6e3a92011-03-21 18:00:50 -07005 *
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;
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -070038 struct mwifiex_bss_prio_tbl *tbl = adapter->bss_prio_tbl;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070039 unsigned long flags;
40
41 bss_prio = kzalloc(sizeof(struct mwifiex_bss_prio_node), GFP_KERNEL);
Joe Perches0d2e7a52013-02-03 17:28:14 +000042 if (!bss_prio)
Christoph Fritzb53575e2011-05-08 22:50:09 +020043 return -ENOMEM;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070044
45 bss_prio->priv = priv;
46 INIT_LIST_HEAD(&bss_prio->list);
Bing Zhao5e6e3a92011-03-21 18:00:50 -070047
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -070048 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);
Bing Zhao5e6e3a92011-03-21 18:00:50 -070051
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070052 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070053}
54
Amitkumar Karwar46361872014-12-31 02:36:41 -080055static void wakeup_timer_fn(unsigned long data)
56{
57 struct mwifiex_adapter *adapter = (struct mwifiex_adapter *)data;
58
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +053059 mwifiex_dbg(adapter, ERROR, "Firmware wakeup failed\n");
Amitkumar Karwar46361872014-12-31 02:36:41 -080060 adapter->hw_status = MWIFIEX_HW_STATUS_RESET;
61 mwifiex_cancel_all_pending_cmd(adapter);
62
Amitkumar Karwar437322e2016-06-16 18:52:24 +053063 if (adapter->if_ops.card_reset && !adapter->hs_activated)
Amitkumar Karwar46361872014-12-31 02:36:41 -080064 adapter->if_ops.card_reset(adapter);
65}
66
Bing Zhao5e6e3a92011-03-21 18:00:50 -070067/*
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 */
Stone Piao9197ab92012-09-25 20:23:42 -070074int mwifiex_init_priv(struct mwifiex_private *priv)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070075{
76 u32 i;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070077
78 priv->media_connected = false;
Joe Perches93803b32015-03-02 19:54:49 -080079 eth_broadcast_addr(priv->curr_addr);
Avinash Patil5c8946332015-06-22 19:06:18 +053080 priv->port_open = false;
Zhaoyang Liu2b0f9972015-09-18 06:32:15 -070081 priv->usb_port = MWIFIEX_USB_EP_DATA;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070082 priv->pkt_tx_ctrl = 0;
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -070083 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070084 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
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -080089 priv->sec_info.wep_enabled = 0;
Marc Yangf986b6d2011-03-28 17:55:42 -070090 priv->sec_info.authentication_mode = NL80211_AUTHTYPE_OPEN_SYSTEM;
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -070091 priv->sec_info.encryption_mode = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070092 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;
97
Julia Lawallfc30c302015-12-06 22:56:21 +010098 priv->beacon_period = 100; /* beacon interval */
Bing Zhao5e6e3a92011-03-21 18:00:50 -070099 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;
102
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;
Shengzhen Li3ee71282016-06-06 13:02:38 -0400113 priv->tx_ant = 0;
114 priv->rx_ant = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700115 priv->tx_rate = 0;
116 priv->rxpd_htinfo = 0;
117 priv->rxpd_rate = 0;
118 priv->rate_bitmap = 0;
119 priv->data_rssi_last = 0;
120 priv->data_rssi_avg = 0;
121 priv->data_nf_avg = 0;
122 priv->data_nf_last = 0;
123 priv->bcn_rssi_last = 0;
124 priv->bcn_rssi_avg = 0;
125 priv->bcn_nf_avg = 0;
126 priv->bcn_nf_last = 0;
127 memset(&priv->wpa_ie, 0, sizeof(priv->wpa_ie));
128 memset(&priv->aes_key, 0, sizeof(priv->aes_key));
129 priv->wpa_ie_len = 0;
130 priv->wpa_is_gtk_set = false;
131
132 memset(&priv->assoc_tlv_buf, 0, sizeof(priv->assoc_tlv_buf));
133 priv->assoc_tlv_buf_len = 0;
134 memset(&priv->wps, 0, sizeof(priv->wps));
135 memset(&priv->gen_ie_buf, 0, sizeof(priv->gen_ie_buf));
136 priv->gen_ie_buf_len = 0;
137 memset(priv->vs_ie, 0, sizeof(priv->vs_ie));
138
139 priv->wmm_required = true;
140 priv->wmm_enabled = false;
141 priv->wmm_qosinfo = 0;
142 priv->curr_bcn_buf = NULL;
143 priv->curr_bcn_size = 0;
Avinash Patil13d7ba72012-04-09 20:06:56 -0700144 priv->wps_ie = NULL;
145 priv->wps_ie_len = 0;
Avinash Patilc8258912012-08-03 18:06:05 -0700146 priv->ap_11n_enabled = 0;
Stone Piao7feb4c42012-09-25 20:23:36 -0700147 memset(&priv->roc_cfg, 0, sizeof(priv->roc_cfg));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700148
149 priv->scan_block = false;
150
Amitkumar Karwarb8876642013-06-18 16:36:58 -0700151 priv->csa_chan = 0;
152 priv->csa_expire_time = 0;
Avinash Patil61c873042013-07-22 19:17:41 -0700153 priv->del_list_idx = 0;
Avinash Patil587b36d2013-08-23 16:48:23 -0700154 priv->hs2_enabled = false;
Avinash Patil9927baa2014-11-13 21:54:16 +0530155 priv->check_tdls_tx = false;
Avinash Patil41a24a22014-02-07 16:27:29 -0800156 memcpy(priv->tos_to_tid_inv, tos_to_tid_inv, MAX_NUM_TID);
Amitkumar Karwarb8876642013-06-18 16:36:58 -0700157
Avinash Patilcf075ea2015-01-28 15:54:25 +0530158 mwifiex_init_11h_params(priv);
159
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700160 return mwifiex_add_bss_prio_tbl(priv);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700161}
162
163/*
164 * This function allocates buffers for members of the adapter
165 * structure.
166 *
167 * The memory allocated includes scan table, command buffers, and
168 * sleep confirm command buffer. In addition, the queues are
169 * also initialized.
170 */
171static int mwifiex_allocate_adapter(struct mwifiex_adapter *adapter)
172{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700173 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700174
175 /* Allocate command buffer */
176 ret = mwifiex_alloc_cmd_buffer(adapter);
177 if (ret) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530178 mwifiex_dbg(adapter, ERROR,
179 "%s: failed to alloc cmd buffer\n",
180 __func__);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700181 return -1;
182 }
183
184 adapter->sleep_cfm =
Amitkumar Karwar7cc5eb62011-05-09 19:00:18 -0700185 dev_alloc_skb(sizeof(struct mwifiex_opt_sleep_confirm)
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -0700186 + INTF_HEADER_LEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700187
188 if (!adapter->sleep_cfm) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530189 mwifiex_dbg(adapter, ERROR,
190 "%s: failed to alloc sleep cfm\t"
191 " cmd buffer\n", __func__);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700192 return -1;
193 }
194 skb_reserve(adapter->sleep_cfm, INTF_HEADER_LEN);
195
196 return 0;
197}
198
199/*
200 * This function initializes the adapter structure and sets default
201 * values to the members of adapter.
202 *
203 * This also initializes the WMM related parameters in the driver private
204 * structures.
205 */
206static void mwifiex_init_adapter(struct mwifiex_adapter *adapter)
207{
Amitkumar Karwar7cc5eb62011-05-09 19:00:18 -0700208 struct mwifiex_opt_sleep_confirm *sleep_cfm_buf = NULL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700209
Amitkumar Karwar7cc5eb62011-05-09 19:00:18 -0700210 skb_put(adapter->sleep_cfm, sizeof(struct mwifiex_opt_sleep_confirm));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700211
212 adapter->cmd_sent = false;
Amitkumar Karward930fae2011-10-11 17:41:21 -0700213
Amitkumar Karwar4daffe32012-04-18 20:08:28 -0700214 if (adapter->iface_type == MWIFIEX_SDIO)
Amitkumar Karward930fae2011-10-11 17:41:21 -0700215 adapter->data_sent = true;
Amitkumar Karwar4daffe32012-04-18 20:08:28 -0700216 else
217 adapter->data_sent = false;
Amitkumar Karward930fae2011-10-11 17:41:21 -0700218
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700219 adapter->cmd_resp_received = false;
220 adapter->event_received = false;
221 adapter->data_received = false;
222
223 adapter->surprise_removed = false;
224
225 adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING;
226
227 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
228 adapter->ps_state = PS_STATE_AWAKE;
229 adapter->need_to_wakeup = false;
230
231 adapter->scan_mode = HostCmd_BSS_MODE_ANY;
232 adapter->specific_scan_time = MWIFIEX_SPECIFIC_SCAN_CHAN_TIME;
233 adapter->active_scan_time = MWIFIEX_ACTIVE_SCAN_CHAN_TIME;
234 adapter->passive_scan_time = MWIFIEX_PASSIVE_SCAN_CHAN_TIME;
Avinash Patilcb91be82014-09-12 20:08:54 +0530235 adapter->scan_chan_gap_time = MWIFIEX_DEF_SCAN_CHAN_GAP_TIME;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700236
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700237 adapter->scan_probes = 1;
238
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700239 adapter->multiple_dtim = 1;
240
241 adapter->local_listen_interval = 0; /* default value in firmware
242 will be used */
243
244 adapter->is_deep_sleep = false;
245
246 adapter->delay_null_pkt = false;
247 adapter->delay_to_ps = 1000;
248 adapter->enhanced_ps_mode = PS_MODE_AUTO;
249
250 adapter->gen_null_pkt = false; /* Disable NULL Pkg generation by
251 default */
252 adapter->pps_uapsd_mode = false; /* Disable pps/uapsd mode by
253 default */
254 adapter->pm_wakeup_card_req = false;
255
256 adapter->pm_wakeup_fw_try = false;
257
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700258 adapter->curr_tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K;
259
260 adapter->is_hs_configured = false;
Amitkumar Karwarcc0b5a62013-03-04 16:27:57 -0800261 adapter->hs_cfg.conditions = cpu_to_le32(HS_CFG_COND_DEF);
262 adapter->hs_cfg.gpio = HS_CFG_GPIO_DEF;
263 adapter->hs_cfg.gap = HS_CFG_GAP_DEF;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700264 adapter->hs_activated = false;
265
266 memset(adapter->event_body, 0, sizeof(adapter->event_body));
267 adapter->hw_dot_11n_dev_cap = 0;
268 adapter->hw_dev_mcs_support = 0;
Amitkumar Karwar21c3ba32011-12-20 23:47:21 -0800269 adapter->sec_chan_offset = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700270 adapter->adhoc_11n_enabled = false;
271
272 mwifiex_wmm_init(adapter);
273
Dan Carpenter2d7defb2015-03-23 12:35:51 +0300274 sleep_cfm_buf = (struct mwifiex_opt_sleep_confirm *)
275 adapter->sleep_cfm->data;
276 memset(sleep_cfm_buf, 0, adapter->sleep_cfm->len);
277 sleep_cfm_buf->command = cpu_to_le16(HostCmd_CMD_802_11_PS_MODE_ENH);
278 sleep_cfm_buf->size = cpu_to_le16(adapter->sleep_cfm->len);
279 sleep_cfm_buf->result = 0;
280 sleep_cfm_buf->action = cpu_to_le16(SLEEP_CONFIRM);
281 sleep_cfm_buf->resp_ctrl = cpu_to_le16(RESP_NEEDED);
282
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700283 memset(&adapter->sleep_params, 0, sizeof(adapter->sleep_params));
284 memset(&adapter->sleep_period, 0, sizeof(adapter->sleep_period));
285 adapter->tx_lock_flag = false;
286 adapter->null_pkt_interval = 0;
287 adapter->fw_bands = 0;
288 adapter->config_bands = 0;
289 adapter->adhoc_start_band = 0;
290 adapter->scan_channels = NULL;
291 adapter->fw_release_number = 0;
292 adapter->fw_cap_info = 0;
293 memset(&adapter->upld_buf, 0, sizeof(adapter->upld_buf));
294 adapter->event_cause = 0;
295 adapter->region_code = 0;
296 adapter->bcn_miss_time_out = DEFAULT_BCN_MISS_TIMEOUT;
297 adapter->adhoc_awake_period = 0;
298 memset(&adapter->arp_filter, 0, sizeof(adapter->arp_filter));
299 adapter->arp_filter_size = 0;
Avinash Patilede98bf2012-05-08 18:30:28 -0700300 adapter->max_mgmt_ie_index = MAX_MGMT_IE_INDEX;
Amitkumar Karwar4b9fede2014-08-19 08:24:25 -0400301 adapter->key_api_major_ver = 0;
302 adapter->key_api_minor_ver = 0;
Joe Perches93803b32015-03-02 19:54:49 -0800303 eth_broadcast_addr(adapter->perm_addr);
Avinash Patilcf0523352015-01-28 15:42:03 +0530304 adapter->iface_limit.sta_intf = MWIFIEX_MAX_STA_NUM;
305 adapter->iface_limit.uap_intf = MWIFIEX_MAX_UAP_NUM;
306 adapter->iface_limit.p2p_intf = MWIFIEX_MAX_P2P_NUM;
chunfan chen2375fa22015-08-05 06:09:42 -0700307 adapter->active_scan_triggered = false;
Amitkumar Karwar46361872014-12-31 02:36:41 -0800308 setup_timer(&adapter->wakeup_timer, wakeup_timer_fn,
309 (unsigned long)adapter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700310}
311
312/*
Avinash Patilbbea3bc2011-12-08 20:41:05 -0800313 * This function sets trans_start per tx_queue
314 */
315void mwifiex_set_trans_start(struct net_device *dev)
316{
317 int i;
318
319 for (i = 0; i < dev->num_tx_queues; i++)
320 netdev_get_tx_queue(dev, i)->trans_start = jiffies;
321
Florian Westphal860e9532016-05-03 16:33:13 +0200322 netif_trans_update(dev);
Avinash Patilbbea3bc2011-12-08 20:41:05 -0800323}
324
325/*
326 * This function wakes up all queues in net_device
327 */
328void mwifiex_wake_up_net_dev_queue(struct net_device *netdev,
329 struct mwifiex_adapter *adapter)
330{
331 unsigned long dev_queue_flags;
Avinash Patil47411a02012-11-01 18:44:16 -0700332 unsigned int i;
Avinash Patilbbea3bc2011-12-08 20:41:05 -0800333
334 spin_lock_irqsave(&adapter->queue_lock, dev_queue_flags);
Avinash Patil47411a02012-11-01 18:44:16 -0700335
336 for (i = 0; i < netdev->num_tx_queues; i++) {
337 struct netdev_queue *txq = netdev_get_tx_queue(netdev, i);
338
339 if (netif_tx_queue_stopped(txq))
340 netif_tx_wake_queue(txq);
341 }
342
Avinash Patilbbea3bc2011-12-08 20:41:05 -0800343 spin_unlock_irqrestore(&adapter->queue_lock, dev_queue_flags);
344}
345
346/*
347 * This function stops all queues in net_device
348 */
349void mwifiex_stop_net_dev_queue(struct net_device *netdev,
350 struct mwifiex_adapter *adapter)
351{
352 unsigned long dev_queue_flags;
Avinash Patil47411a02012-11-01 18:44:16 -0700353 unsigned int i;
Avinash Patilbbea3bc2011-12-08 20:41:05 -0800354
355 spin_lock_irqsave(&adapter->queue_lock, dev_queue_flags);
Avinash Patil47411a02012-11-01 18:44:16 -0700356
357 for (i = 0; i < netdev->num_tx_queues; i++) {
358 struct netdev_queue *txq = netdev_get_tx_queue(netdev, i);
359
360 if (!netif_tx_queue_stopped(txq))
361 netif_tx_stop_queue(txq);
362 }
363
Avinash Patilbbea3bc2011-12-08 20:41:05 -0800364 spin_unlock_irqrestore(&adapter->queue_lock, dev_queue_flags);
365}
366
367/*
Amitkumar Karwar711825a2011-10-12 20:29:33 -0700368 * This function releases the lock variables and frees the locks and
369 * associated locks.
370 */
371static void mwifiex_free_lock_list(struct mwifiex_adapter *adapter)
372{
373 struct mwifiex_private *priv;
374 s32 i, j;
375
376 /* Free lists */
377 list_del(&adapter->cmd_free_q);
378 list_del(&adapter->cmd_pending_q);
379 list_del(&adapter->scan_pending_q);
380
381 for (i = 0; i < adapter->priv_num; i++)
382 list_del(&adapter->bss_prio_tbl[i].bss_prio_head);
383
384 for (i = 0; i < adapter->priv_num; i++) {
385 if (adapter->priv[i]) {
386 priv = adapter->priv[i];
387 for (j = 0; j < MAX_NUM_TID; ++j)
388 list_del(&priv->wmm.tid_tbl_ptr[j].ra_list);
389 list_del(&priv->tx_ba_stream_tbl_ptr);
390 list_del(&priv->rx_reorder_tbl_ptr);
Avinash Patil017a92a2012-08-03 18:06:07 -0700391 list_del(&priv->sta_list);
Avinash Patil9927baa2014-11-13 21:54:16 +0530392 list_del(&priv->auto_tdls_list);
Amitkumar Karwar711825a2011-10-12 20:29:33 -0700393 }
394 }
395}
396
397/*
Amitkumar Karwarc56ecf52013-05-17 17:50:18 -0700398 * This function performs cleanup for adapter structure.
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700399 *
Amitkumar Karwarc56ecf52013-05-17 17:50:18 -0700400 * The cleanup is done recursively, by canceling all pending
401 * commands, freeing the member buffers previously allocated
402 * (command buffers, scan table buffer, sleep confirm command
403 * buffer), stopping the timers and calling the cleanup routines
404 * for every interface.
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700405 */
406static void
Amitkumar Karwarc56ecf52013-05-17 17:50:18 -0700407mwifiex_adapter_cleanup(struct mwifiex_adapter *adapter)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700408{
Amitkumar Karwar92c25382014-06-19 21:38:52 -0700409 int idx;
410
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700411 if (!adapter) {
412 pr_err("%s: adapter is NULL\n", __func__);
413 return;
414 }
415
Amitkumar Karwar46361872014-12-31 02:36:41 -0800416 del_timer(&adapter->wakeup_timer);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700417 mwifiex_cancel_all_pending_cmd(adapter);
Amitkumar Karwarfc647462014-12-31 02:36:42 -0800418 wake_up_interruptible(&adapter->cmd_wait_q.wait);
419 wake_up_interruptible(&adapter->hs_activate_wait_q);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700420
421 /* Free lock variables */
422 mwifiex_free_lock_list(adapter);
423
424 /* Free command buffer */
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530425 mwifiex_dbg(adapter, INFO, "info: free cmd buffer\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700426 mwifiex_free_cmd_buffer(adapter);
427
Amitkumar Karwar92c25382014-06-19 21:38:52 -0700428 for (idx = 0; idx < adapter->num_mem_types; idx++) {
429 struct memory_type_mapping *entry =
430 &adapter->mem_type_mapping_tbl[idx];
431
432 if (entry->mem_ptr) {
433 vfree(entry->mem_ptr);
434 entry->mem_ptr = NULL;
435 }
436 entry->mem_size = 0;
437 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700438
Xinming Hu11cd07a2014-12-23 19:14:10 +0530439 if (adapter->drv_info_dump) {
440 vfree(adapter->drv_info_dump);
Amitkumar Karwar0769b272015-05-26 06:34:28 -0700441 adapter->drv_info_dump = NULL;
Xinming Hu11cd07a2014-12-23 19:14:10 +0530442 adapter->drv_info_size = 0;
443 }
444
Amitkumar Karwar2da8cbf2012-02-03 20:34:02 -0800445 if (adapter->sleep_cfm)
446 dev_kfree_skb_any(adapter->sleep_cfm);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700447}
448
449/*
450 * This function intializes the lock variables and
451 * the list heads.
452 */
453int mwifiex_init_lock_list(struct mwifiex_adapter *adapter)
454{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700455 struct mwifiex_private *priv;
456 s32 i, j;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700457
458 spin_lock_init(&adapter->mwifiex_lock);
459 spin_lock_init(&adapter->int_lock);
460 spin_lock_init(&adapter->main_proc_lock);
461 spin_lock_init(&adapter->mwifiex_cmd_lock);
Avinash Patilbbea3bc2011-12-08 20:41:05 -0800462 spin_lock_init(&adapter->queue_lock);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700463 for (i = 0; i < adapter->priv_num; i++) {
464 if (adapter->priv[i]) {
465 priv = adapter->priv[i];
466 spin_lock_init(&priv->rx_pkt_lock);
467 spin_lock_init(&priv->wmm.ra_list_spinlock);
468 spin_lock_init(&priv->curr_bcn_buf_lock);
Avinash Patil017a92a2012-08-03 18:06:07 -0700469 spin_lock_init(&priv->sta_list_spinlock);
Avinash Patil9927baa2014-11-13 21:54:16 +0530470 spin_lock_init(&priv->auto_tdls_lock);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700471 }
472 }
473
474 /* Initialize cmd_free_q */
475 INIT_LIST_HEAD(&adapter->cmd_free_q);
476 /* Initialize cmd_pending_q */
477 INIT_LIST_HEAD(&adapter->cmd_pending_q);
478 /* Initialize scan_pending_q */
479 INIT_LIST_HEAD(&adapter->scan_pending_q);
480
481 spin_lock_init(&adapter->cmd_free_q_lock);
482 spin_lock_init(&adapter->cmd_pending_q_lock);
483 spin_lock_init(&adapter->scan_pending_q_lock);
Avinash Patil6e251172014-09-12 20:08:59 +0530484 spin_lock_init(&adapter->rx_proc_lock);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700485
Avinash Patil6e251172014-09-12 20:08:59 +0530486 skb_queue_head_init(&adapter->rx_data_q);
Zhaoyang Liue35000e2015-03-13 17:37:57 +0530487 skb_queue_head_init(&adapter->tx_data_q);
Amitkumar Karwar4daffe32012-04-18 20:08:28 -0700488
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700489 for (i = 0; i < adapter->priv_num; ++i) {
490 INIT_LIST_HEAD(&adapter->bss_prio_tbl[i].bss_prio_head);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700491 spin_lock_init(&adapter->bss_prio_tbl[i].bss_prio_lock);
492 }
493
494 for (i = 0; i < adapter->priv_num; i++) {
495 if (!adapter->priv[i])
496 continue;
497 priv = adapter->priv[i];
Andreas Fenkart6d2344e2013-04-04 20:03:51 -0700498 for (j = 0; j < MAX_NUM_TID; ++j)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700499 INIT_LIST_HEAD(&priv->wmm.tid_tbl_ptr[j].ra_list);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700500 INIT_LIST_HEAD(&priv->tx_ba_stream_tbl_ptr);
501 INIT_LIST_HEAD(&priv->rx_reorder_tbl_ptr);
Avinash Patil017a92a2012-08-03 18:06:07 -0700502 INIT_LIST_HEAD(&priv->sta_list);
Avinash Patil9927baa2014-11-13 21:54:16 +0530503 INIT_LIST_HEAD(&priv->auto_tdls_list);
Avinash Patil56bd24a2014-02-07 16:30:35 -0800504 skb_queue_head_init(&priv->tdls_txq);
Avinash Patila1777322015-06-22 19:06:17 +0530505 skb_queue_head_init(&priv->bypass_txq);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700506
507 spin_lock_init(&priv->tx_ba_stream_tbl_lock);
508 spin_lock_init(&priv->rx_reorder_tbl_lock);
Amitkumar Karwar808bbeb2014-11-25 06:43:05 -0800509
510 spin_lock_init(&priv->ack_status_lock);
511 idr_init(&priv->ack_status_frames);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700512 }
513
514 return 0;
515}
516
517/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700518 * This function initializes the firmware.
519 *
520 * The following operations are performed sequentially -
521 * - Allocate adapter structure
522 * - Initialize the adapter structure
523 * - Initialize the private structure
524 * - Add BSS priority tables to the adapter structure
525 * - For each interface, send the init commands to firmware
526 * - Send the first command in command pending queue, if available
527 */
528int mwifiex_init_fw(struct mwifiex_adapter *adapter)
529{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700530 int ret;
531 struct mwifiex_private *priv;
532 u8 i, first_sta = true;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700533 int is_cmd_pend_q_empty;
534 unsigned long flags;
535
536 adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING;
537
538 /* Allocate memory for member of adapter structure */
539 ret = mwifiex_allocate_adapter(adapter);
540 if (ret)
541 return -1;
542
543 /* Initialize adapter structure */
544 mwifiex_init_adapter(adapter);
545
546 for (i = 0; i < adapter->priv_num; i++) {
547 if (adapter->priv[i]) {
548 priv = adapter->priv[i];
549
550 /* Initialize private structure */
551 ret = mwifiex_init_priv(priv);
552 if (ret)
553 return -1;
554 }
555 }
Avinash Patilc6d1d872013-01-03 21:21:29 -0800556
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700557 for (i = 0; i < adapter->priv_num; i++) {
558 if (adapter->priv[i]) {
Avinash Patil1247cc12015-01-28 15:42:02 +0530559 ret = mwifiex_sta_init_cmd(adapter->priv[i], first_sta,
560 true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700561 if (ret == -1)
562 return -1;
563
564 first_sta = false;
565 }
566 }
567
568 spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags);
569 is_cmd_pend_q_empty = list_empty(&adapter->cmd_pending_q);
570 spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, flags);
571 if (!is_cmd_pend_q_empty) {
572 /* Send the first command in queue and return */
573 if (mwifiex_main_process(adapter) != -1)
574 ret = -EINPROGRESS;
575 } else {
576 adapter->hw_status = MWIFIEX_HW_STATUS_READY;
577 }
578
579 return ret;
580}
581
582/*
583 * This function deletes the BSS priority tables.
584 *
585 * The function traverses through all the allocated BSS priority nodes
586 * in every BSS priority table and frees them.
587 */
588static void mwifiex_delete_bss_prio_tbl(struct mwifiex_private *priv)
589{
590 int i;
591 struct mwifiex_adapter *adapter = priv->adapter;
Andreas Fenkartb006ed52013-04-18 16:34:12 -0700592 struct mwifiex_bss_prio_node *bssprio_node, *tmp_node;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700593 struct list_head *head;
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -0700594 spinlock_t *lock; /* bss priority lock */
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700595 unsigned long flags;
596
597 for (i = 0; i < adapter->priv_num; ++i) {
598 head = &adapter->bss_prio_tbl[i].bss_prio_head;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700599 lock = &adapter->bss_prio_tbl[i].bss_prio_lock;
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530600 mwifiex_dbg(adapter, INFO,
601 "info: delete BSS priority table,\t"
602 "bss_type = %d, bss_num = %d, i = %d,\t"
603 "head = %p\n",
604 priv->bss_type, priv->bss_num, i, head);
Andreas Fenkartb006ed52013-04-18 16:34:12 -0700605
606 {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700607 spin_lock_irqsave(lock, flags);
608 if (list_empty(head)) {
609 spin_unlock_irqrestore(lock, flags);
610 continue;
611 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700612 list_for_each_entry_safe(bssprio_node, tmp_node, head,
613 list) {
614 if (bssprio_node->priv == priv) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530615 mwifiex_dbg(adapter, INFO,
616 "info: Delete\t"
617 "node %p, next = %p\n",
618 bssprio_node, tmp_node);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700619 list_del(&bssprio_node->list);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700620 kfree(bssprio_node);
621 }
622 }
Andreas Fenkartb006ed52013-04-18 16:34:12 -0700623 spin_unlock_irqrestore(lock, flags);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700624 }
625 }
626}
627
628/*
Stone Piao9197ab92012-09-25 20:23:42 -0700629 * This function frees the private structure, including cleans
630 * up the TX and RX queues and frees the BSS priority tables.
631 */
632void mwifiex_free_priv(struct mwifiex_private *priv)
633{
634 mwifiex_clean_txrx(priv);
635 mwifiex_delete_bss_prio_tbl(priv);
636 mwifiex_free_curr_bcn(priv);
637}
638
639/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700640 * This function is used to shutdown the driver.
641 *
642 * The following operations are performed sequentially -
643 * - Check if already shut down
644 * - Make sure the main process has stopped
645 * - Clean up the Tx and Rx queues
646 * - Delete BSS priority tables
647 * - Free the adapter
648 * - Notify completion
649 */
650int
651mwifiex_shutdown_drv(struct mwifiex_adapter *adapter)
652{
653 int ret = -EINPROGRESS;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700654 struct mwifiex_private *priv;
655 s32 i;
Avinash Patil6e251172014-09-12 20:08:59 +0530656 unsigned long flags;
Amitkumar Karwar4daffe32012-04-18 20:08:28 -0700657 struct sk_buff *skb;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700658
659 /* mwifiex already shutdown */
660 if (adapter->hw_status == MWIFIEX_HW_STATUS_NOT_READY)
661 return 0;
662
663 adapter->hw_status = MWIFIEX_HW_STATUS_CLOSING;
664 /* wait for mwifiex_process to complete */
665 if (adapter->mwifiex_processing) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530666 mwifiex_dbg(adapter, WARN,
667 "main process is still running\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700668 return ret;
669 }
670
Bing Zhao084c7182013-03-15 18:47:07 -0700671 /* cancel current command */
672 if (adapter->curr_cmd) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530673 mwifiex_dbg(adapter, WARN,
674 "curr_cmd is still in processing\n");
Avinash Patil629873f2014-02-18 15:47:55 -0800675 del_timer_sync(&adapter->cmd_timer);
Bing Zhao9908b072013-04-01 12:44:46 -0700676 mwifiex_recycle_cmd_node(adapter, adapter->curr_cmd);
Bing Zhao084c7182013-03-15 18:47:07 -0700677 adapter->curr_cmd = NULL;
678 }
679
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700680 /* shut down mwifiex */
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530681 mwifiex_dbg(adapter, MSG,
682 "info: shutdown mwifiex...\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700683
684 /* Clean up Tx/Rx queues and delete BSS priority table */
685 for (i = 0; i < adapter->priv_num; i++) {
686 if (adapter->priv[i]) {
687 priv = adapter->priv[i];
688
Avinash Patil9927baa2014-11-13 21:54:16 +0530689 mwifiex_clean_auto_tdls(priv);
Avinash Patil85afb182015-01-28 15:54:21 +0530690 mwifiex_abort_cac(priv);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700691 mwifiex_clean_txrx(priv);
692 mwifiex_delete_bss_prio_tbl(priv);
693 }
694 }
695
Zhaoyang Liue35000e2015-03-13 17:37:57 +0530696 atomic_set(&adapter->tx_queued, 0);
697 while ((skb = skb_dequeue(&adapter->tx_data_q)))
698 mwifiex_write_data_complete(adapter, skb, 0, 0);
699
Avinash Patil6e251172014-09-12 20:08:59 +0530700 spin_lock_irqsave(&adapter->rx_proc_lock, flags);
701
702 while ((skb = skb_dequeue(&adapter->rx_data_q))) {
703 struct mwifiex_rxinfo *rx_info = MWIFIEX_SKB_RXCB(skb);
704
705 atomic_dec(&adapter->rx_pending);
706 priv = adapter->priv[rx_info->bss_num];
707 if (priv)
708 priv->stats.rx_dropped++;
709
710 dev_kfree_skb_any(skb);
711 }
712
713 spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
714
Avinash Patil013a4922013-05-17 17:50:24 -0700715 spin_lock(&adapter->mwifiex_lock);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700716
Amitkumar Karwarc56ecf52013-05-17 17:50:18 -0700717 mwifiex_adapter_cleanup(adapter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700718
Avinash Patil013a4922013-05-17 17:50:24 -0700719 spin_unlock(&adapter->mwifiex_lock);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700720
721 /* Notify completion */
722 ret = mwifiex_shutdown_fw_complete(adapter);
723
724 return ret;
725}
726
727/*
728 * This function downloads the firmware to the card.
729 *
730 * The actual download is preceded by two sanity checks -
731 * - Check if firmware is already running
732 * - Check if the interface is the winner to download the firmware
733 *
734 * ...and followed by another -
735 * - Check if the firmware is downloaded successfully
736 *
737 * After download is successfully completed, the host interrupts are enabled.
738 */
739int mwifiex_dnld_fw(struct mwifiex_adapter *adapter,
740 struct mwifiex_fw_image *pmfw)
741{
Amitkumar Karward930fae2011-10-11 17:41:21 -0700742 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700743 u32 poll_num = 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700744
Amitkumar Karwar4daffe32012-04-18 20:08:28 -0700745 if (adapter->if_ops.check_fw_status) {
Amitkumar Karwar4daffe32012-04-18 20:08:28 -0700746 /* check if firmware is already running */
747 ret = adapter->if_ops.check_fw_status(adapter, poll_num);
748 if (!ret) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530749 mwifiex_dbg(adapter, MSG,
750 "WLAN FW already running! Skip FW dnld\n");
Daniel Drake232fde02013-07-13 10:57:10 -0400751 return 0;
Amitkumar Karwar4daffe32012-04-18 20:08:28 -0700752 }
chunfan chen2fd5c6e2016-01-06 23:40:47 -0800753 }
754
755 /* check if we are the winner for downloading FW */
756 if (adapter->if_ops.check_winner_status) {
757 adapter->winner = 0;
758 ret = adapter->if_ops.check_winner_status(adapter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700759
Amitkumar Karwar4daffe32012-04-18 20:08:28 -0700760 poll_num = MAX_FIRMWARE_POLL_TRIES;
chunfan chen2fd5c6e2016-01-06 23:40:47 -0800761 if (ret) {
762 mwifiex_dbg(adapter, MSG,
763 "WLAN read winner status failed!\n");
764 return ret;
765 }
Amitkumar Karwar4daffe32012-04-18 20:08:28 -0700766
Amitkumar Karwar4daffe32012-04-18 20:08:28 -0700767 if (!adapter->winner) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530768 mwifiex_dbg(adapter, MSG,
chunfan chen2fd5c6e2016-01-06 23:40:47 -0800769 "WLAN is not the winner! Skip FW dnld\n");
Amitkumar Karwar4daffe32012-04-18 20:08:28 -0700770 goto poll_fw;
771 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700772 }
Amitkumar Karwar4daffe32012-04-18 20:08:28 -0700773
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700774 if (pmfw) {
775 /* Download firmware with helper */
776 ret = adapter->if_ops.prog_fw(adapter, pmfw);
777 if (ret) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530778 mwifiex_dbg(adapter, ERROR,
779 "prog_fw failed ret=%#x\n", ret);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700780 return ret;
781 }
782 }
783
784poll_fw:
785 /* Check if the firmware is downloaded successfully or not */
Amitkumar Karward930fae2011-10-11 17:41:21 -0700786 ret = adapter->if_ops.check_fw_status(adapter, poll_num);
Daniel Drake232fde02013-07-13 10:57:10 -0400787 if (ret)
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530788 mwifiex_dbg(adapter, ERROR,
789 "FW failed to be active in time\n");
Amitkumar Karwar4daffe32012-04-18 20:08:28 -0700790
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700791 return ret;
792}
Arnd Bergmann2095b142016-06-16 11:01:10 +0200793EXPORT_SYMBOL_GPL(mwifiex_dnld_fw);