Commit | Line | Data |
---|---|---|
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 | */ | |
34 | static 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 |
55 | static 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 | 74 | int 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; | |
95 | priv->curr_pkt_filter = HostCmd_ACT_MAC_RX_ON | HostCmd_ACT_MAC_TX_ON | | |
96 | HostCmd_ACT_MAC_ETHERNETII_ENABLE; | |
97 | ||
fc30c305 | 98 | priv->beacon_period = 100; /* beacon interval */ |
5e6e3a92 BZ |
99 | 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; | |
3ee71285 SL |
113 | priv->tx_ant = 0; |
114 | priv->rx_ant = 0; | |
5e6e3a92 BZ |
115 | 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; | |
13d7ba78 AP |
144 | priv->wps_ie = NULL; |
145 | priv->wps_ie_len = 0; | |
c8258913 | 146 | priv->ap_11n_enabled = 0; |
7feb4c48 | 147 | memset(&priv->roc_cfg, 0, sizeof(priv->roc_cfg)); |
5e6e3a92 BZ |
148 | |
149 | priv->scan_block = false; | |
150 | ||
b887664d AK |
151 | priv->csa_chan = 0; |
152 | priv->csa_expire_time = 0; | |
61c87304 | 153 | priv->del_list_idx = 0; |
587b36d3 | 154 | priv->hs2_enabled = false; |
9927baa3 | 155 | priv->check_tdls_tx = false; |
41a24a29 | 156 | memcpy(priv->tos_to_tid_inv, tos_to_tid_inv, MAX_NUM_TID); |
b887664d | 157 | |
cf075eac AP |
158 | mwifiex_init_11h_params(priv); |
159 | ||
636c4598 | 160 | return mwifiex_add_bss_prio_tbl(priv); |
5e6e3a92 BZ |
161 | } |
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 | */ | |
171 | static int mwifiex_allocate_adapter(struct mwifiex_adapter *adapter) | |
172 | { | |
270e58e8 | 173 | int ret; |
5e6e3a92 BZ |
174 | |
175 | /* Allocate command buffer */ | |
176 | ret = mwifiex_alloc_cmd_buffer(adapter); | |
177 | if (ret) { | |
acebe8c1 ZL |
178 | mwifiex_dbg(adapter, ERROR, |
179 | "%s: failed to alloc cmd buffer\n", | |
180 | __func__); | |
5e6e3a92 BZ |
181 | return -1; |
182 | } | |
183 | ||
184 | adapter->sleep_cfm = | |
7cc5eb62 | 185 | dev_alloc_skb(sizeof(struct mwifiex_opt_sleep_confirm) |
931f1584 | 186 | + INTF_HEADER_LEN); |
5e6e3a92 BZ |
187 | |
188 | if (!adapter->sleep_cfm) { | |
acebe8c1 ZL |
189 | mwifiex_dbg(adapter, ERROR, |
190 | "%s: failed to alloc sleep cfm\t" | |
191 | " cmd buffer\n", __func__); | |
5e6e3a92 BZ |
192 | 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 | */ | |
206 | static void mwifiex_init_adapter(struct mwifiex_adapter *adapter) | |
207 | { | |
7cc5eb62 | 208 | struct mwifiex_opt_sleep_confirm *sleep_cfm_buf = NULL; |
5e6e3a92 | 209 | |
7cc5eb62 | 210 | skb_put(adapter->sleep_cfm, sizeof(struct mwifiex_opt_sleep_confirm)); |
5e6e3a92 BZ |
211 | |
212 | adapter->cmd_sent = false; | |
d930faee | 213 | |
4daffe35 | 214 | if (adapter->iface_type == MWIFIEX_SDIO) |
d930faee | 215 | adapter->data_sent = true; |
4daffe35 AK |
216 | else |
217 | adapter->data_sent = false; | |
d930faee | 218 | |
5e6e3a92 BZ |
219 | 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; | |
cb91be87 | 235 | adapter->scan_chan_gap_time = MWIFIEX_DEF_SCAN_CHAN_GAP_TIME; |
5e6e3a92 | 236 | |
5e6e3a92 BZ |
237 | adapter->scan_probes = 1; |
238 | ||
5e6e3a92 BZ |
239 | 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 | ||
5e6e3a92 BZ |
258 | adapter->curr_tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K; |
259 | ||
260 | adapter->is_hs_configured = false; | |
cc0b5a64 AK |
261 | 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; | |
5e6e3a92 BZ |
264 | 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; | |
21c3ba34 | 269 | adapter->sec_chan_offset = 0; |
5e6e3a92 BZ |
270 | adapter->adhoc_11n_enabled = false; |
271 | ||
272 | mwifiex_wmm_init(adapter); | |
273 | ||
2d7defb0 DC |
274 | 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 | ||
5e6e3a92 BZ |
283 | 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; | |
ede98bfa | 300 | adapter->max_mgmt_ie_index = MAX_MGMT_IE_INDEX; |
cf5383b0 | 301 | adapter->mfg_mode = mfg_mode; |
4b9fede5 AK |
302 | adapter->key_api_major_ver = 0; |
303 | adapter->key_api_minor_ver = 0; | |
93803b33 | 304 | eth_broadcast_addr(adapter->perm_addr); |
cf052335 AP |
305 | adapter->iface_limit.sta_intf = MWIFIEX_MAX_STA_NUM; |
306 | adapter->iface_limit.uap_intf = MWIFIEX_MAX_UAP_NUM; | |
307 | adapter->iface_limit.p2p_intf = MWIFIEX_MAX_P2P_NUM; | |
2375fa2b | 308 | adapter->active_scan_triggered = false; |
4636187d AK |
309 | setup_timer(&adapter->wakeup_timer, wakeup_timer_fn, |
310 | (unsigned long)adapter); | |
5e6e3a92 BZ |
311 | } |
312 | ||
bbea3bc4 AP |
313 | /* |
314 | * This function sets trans_start per tx_queue | |
315 | */ | |
316 | void mwifiex_set_trans_start(struct net_device *dev) | |
317 | { | |
318 | int i; | |
319 | ||
320 | for (i = 0; i < dev->num_tx_queues; i++) | |
321 | netdev_get_tx_queue(dev, i)->trans_start = jiffies; | |
322 | ||
860e9538 | 323 | netif_trans_update(dev); |
bbea3bc4 AP |
324 | } |
325 | ||
326 | /* | |
327 | * This function wakes up all queues in net_device | |
328 | */ | |
329 | void mwifiex_wake_up_net_dev_queue(struct net_device *netdev, | |
330 | struct mwifiex_adapter *adapter) | |
331 | { | |
332 | unsigned long dev_queue_flags; | |
47411a06 | 333 | unsigned int i; |
bbea3bc4 AP |
334 | |
335 | spin_lock_irqsave(&adapter->queue_lock, dev_queue_flags); | |
47411a06 AP |
336 | |
337 | for (i = 0; i < netdev->num_tx_queues; i++) { | |
338 | struct netdev_queue *txq = netdev_get_tx_queue(netdev, i); | |
339 | ||
340 | if (netif_tx_queue_stopped(txq)) | |
341 | netif_tx_wake_queue(txq); | |
342 | } | |
343 | ||
bbea3bc4 AP |
344 | spin_unlock_irqrestore(&adapter->queue_lock, dev_queue_flags); |
345 | } | |
346 | ||
347 | /* | |
348 | * This function stops all queues in net_device | |
349 | */ | |
350 | void mwifiex_stop_net_dev_queue(struct net_device *netdev, | |
351 | struct mwifiex_adapter *adapter) | |
352 | { | |
353 | unsigned long dev_queue_flags; | |
47411a06 | 354 | unsigned int i; |
bbea3bc4 AP |
355 | |
356 | spin_lock_irqsave(&adapter->queue_lock, dev_queue_flags); | |
47411a06 AP |
357 | |
358 | for (i = 0; i < netdev->num_tx_queues; i++) { | |
359 | struct netdev_queue *txq = netdev_get_tx_queue(netdev, i); | |
360 | ||
361 | if (!netif_tx_queue_stopped(txq)) | |
362 | netif_tx_stop_queue(txq); | |
363 | } | |
364 | ||
bbea3bc4 AP |
365 | spin_unlock_irqrestore(&adapter->queue_lock, dev_queue_flags); |
366 | } | |
367 | ||
711825a0 AK |
368 | /* |
369 | * This function releases the lock variables and frees the locks and | |
370 | * associated locks. | |
371 | */ | |
372 | static void mwifiex_free_lock_list(struct mwifiex_adapter *adapter) | |
373 | { | |
374 | struct mwifiex_private *priv; | |
375 | s32 i, j; | |
376 | ||
377 | /* Free lists */ | |
378 | list_del(&adapter->cmd_free_q); | |
379 | list_del(&adapter->cmd_pending_q); | |
380 | list_del(&adapter->scan_pending_q); | |
381 | ||
382 | for (i = 0; i < adapter->priv_num; i++) | |
383 | list_del(&adapter->bss_prio_tbl[i].bss_prio_head); | |
384 | ||
385 | for (i = 0; i < adapter->priv_num; i++) { | |
386 | if (adapter->priv[i]) { | |
387 | priv = adapter->priv[i]; | |
388 | for (j = 0; j < MAX_NUM_TID; ++j) | |
389 | list_del(&priv->wmm.tid_tbl_ptr[j].ra_list); | |
390 | list_del(&priv->tx_ba_stream_tbl_ptr); | |
391 | list_del(&priv->rx_reorder_tbl_ptr); | |
017a92a1 | 392 | list_del(&priv->sta_list); |
9927baa3 | 393 | list_del(&priv->auto_tdls_list); |
711825a0 AK |
394 | } |
395 | } | |
396 | } | |
397 | ||
5e6e3a92 | 398 | /* |
c56ecf5a | 399 | * This function performs cleanup for adapter structure. |
5e6e3a92 | 400 | * |
c56ecf5a AK |
401 | * The cleanup is done recursively, by canceling all pending |
402 | * commands, freeing the member buffers previously allocated | |
403 | * (command buffers, scan table buffer, sleep confirm command | |
404 | * buffer), stopping the timers and calling the cleanup routines | |
405 | * for every interface. | |
5e6e3a92 BZ |
406 | */ |
407 | static void | |
c56ecf5a | 408 | mwifiex_adapter_cleanup(struct mwifiex_adapter *adapter) |
5e6e3a92 | 409 | { |
92c2538f AK |
410 | int idx; |
411 | ||
5e6e3a92 BZ |
412 | if (!adapter) { |
413 | pr_err("%s: adapter is NULL\n", __func__); | |
414 | return; | |
415 | } | |
416 | ||
4636187d | 417 | del_timer(&adapter->wakeup_timer); |
5e6e3a92 | 418 | mwifiex_cancel_all_pending_cmd(adapter); |
fc647467 AK |
419 | wake_up_interruptible(&adapter->cmd_wait_q.wait); |
420 | wake_up_interruptible(&adapter->hs_activate_wait_q); | |
5e6e3a92 BZ |
421 | |
422 | /* Free lock variables */ | |
423 | mwifiex_free_lock_list(adapter); | |
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 | ||
92c2538f AK |
429 | for (idx = 0; idx < adapter->num_mem_types; idx++) { |
430 | struct memory_type_mapping *entry = | |
431 | &adapter->mem_type_mapping_tbl[idx]; | |
432 | ||
433 | if (entry->mem_ptr) { | |
434 | vfree(entry->mem_ptr); | |
435 | entry->mem_ptr = NULL; | |
436 | } | |
437 | entry->mem_size = 0; | |
438 | } | |
5e6e3a92 | 439 | |
11cd07a9 XH |
440 | if (adapter->drv_info_dump) { |
441 | vfree(adapter->drv_info_dump); | |
0769b277 | 442 | adapter->drv_info_dump = NULL; |
11cd07a9 XH |
443 | adapter->drv_info_size = 0; |
444 | } | |
445 | ||
2da8cbf8 AK |
446 | if (adapter->sleep_cfm) |
447 | dev_kfree_skb_any(adapter->sleep_cfm); | |
5e6e3a92 BZ |
448 | } |
449 | ||
450 | /* | |
451 | * This function intializes the lock variables and | |
452 | * the list heads. | |
453 | */ | |
454 | int mwifiex_init_lock_list(struct mwifiex_adapter *adapter) | |
455 | { | |
270e58e8 YAP |
456 | struct mwifiex_private *priv; |
457 | s32 i, j; | |
5e6e3a92 BZ |
458 | |
459 | spin_lock_init(&adapter->mwifiex_lock); | |
460 | spin_lock_init(&adapter->int_lock); | |
461 | spin_lock_init(&adapter->main_proc_lock); | |
462 | spin_lock_init(&adapter->mwifiex_cmd_lock); | |
bbea3bc4 | 463 | spin_lock_init(&adapter->queue_lock); |
5e6e3a92 BZ |
464 | for (i = 0; i < adapter->priv_num; i++) { |
465 | if (adapter->priv[i]) { | |
466 | priv = adapter->priv[i]; | |
467 | spin_lock_init(&priv->rx_pkt_lock); | |
468 | spin_lock_init(&priv->wmm.ra_list_spinlock); | |
469 | spin_lock_init(&priv->curr_bcn_buf_lock); | |
017a92a1 | 470 | spin_lock_init(&priv->sta_list_spinlock); |
9927baa3 | 471 | spin_lock_init(&priv->auto_tdls_lock); |
5e6e3a92 BZ |
472 | } |
473 | } | |
474 | ||
475 | /* Initialize cmd_free_q */ | |
476 | INIT_LIST_HEAD(&adapter->cmd_free_q); | |
477 | /* Initialize cmd_pending_q */ | |
478 | INIT_LIST_HEAD(&adapter->cmd_pending_q); | |
479 | /* Initialize scan_pending_q */ | |
480 | INIT_LIST_HEAD(&adapter->scan_pending_q); | |
481 | ||
482 | spin_lock_init(&adapter->cmd_free_q_lock); | |
483 | spin_lock_init(&adapter->cmd_pending_q_lock); | |
484 | spin_lock_init(&adapter->scan_pending_q_lock); | |
6e251174 | 485 | spin_lock_init(&adapter->rx_proc_lock); |
5e6e3a92 | 486 | |
6e251174 | 487 | skb_queue_head_init(&adapter->rx_data_q); |
e35000ea | 488 | skb_queue_head_init(&adapter->tx_data_q); |
4daffe35 | 489 | |
5e6e3a92 BZ |
490 | for (i = 0; i < adapter->priv_num; ++i) { |
491 | INIT_LIST_HEAD(&adapter->bss_prio_tbl[i].bss_prio_head); | |
5e6e3a92 BZ |
492 | spin_lock_init(&adapter->bss_prio_tbl[i].bss_prio_lock); |
493 | } | |
494 | ||
495 | for (i = 0; i < adapter->priv_num; i++) { | |
496 | if (!adapter->priv[i]) | |
497 | continue; | |
498 | priv = adapter->priv[i]; | |
6d2344ec | 499 | for (j = 0; j < MAX_NUM_TID; ++j) |
5e6e3a92 | 500 | INIT_LIST_HEAD(&priv->wmm.tid_tbl_ptr[j].ra_list); |
5e6e3a92 BZ |
501 | INIT_LIST_HEAD(&priv->tx_ba_stream_tbl_ptr); |
502 | INIT_LIST_HEAD(&priv->rx_reorder_tbl_ptr); | |
017a92a1 | 503 | INIT_LIST_HEAD(&priv->sta_list); |
9927baa3 | 504 | INIT_LIST_HEAD(&priv->auto_tdls_list); |
56bd24a1 | 505 | skb_queue_head_init(&priv->tdls_txq); |
a1777327 | 506 | skb_queue_head_init(&priv->bypass_txq); |
5e6e3a92 BZ |
507 | |
508 | spin_lock_init(&priv->tx_ba_stream_tbl_lock); | |
509 | spin_lock_init(&priv->rx_reorder_tbl_lock); | |
808bbebc AK |
510 | |
511 | spin_lock_init(&priv->ack_status_lock); | |
512 | idr_init(&priv->ack_status_frames); | |
5e6e3a92 BZ |
513 | } |
514 | ||
515 | return 0; | |
516 | } | |
517 | ||
5e6e3a92 BZ |
518 | /* |
519 | * This function initializes the firmware. | |
520 | * | |
521 | * The following operations are performed sequentially - | |
522 | * - Allocate adapter structure | |
523 | * - Initialize the adapter structure | |
524 | * - Initialize the private structure | |
525 | * - Add BSS priority tables to the adapter structure | |
526 | * - For each interface, send the init commands to firmware | |
527 | * - Send the first command in command pending queue, if available | |
528 | */ | |
529 | int mwifiex_init_fw(struct mwifiex_adapter *adapter) | |
530 | { | |
270e58e8 YAP |
531 | int ret; |
532 | struct mwifiex_private *priv; | |
533 | u8 i, first_sta = true; | |
5e6e3a92 BZ |
534 | int is_cmd_pend_q_empty; |
535 | unsigned long flags; | |
536 | ||
537 | adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING; | |
538 | ||
539 | /* Allocate memory for member of adapter structure */ | |
540 | ret = mwifiex_allocate_adapter(adapter); | |
541 | if (ret) | |
542 | return -1; | |
543 | ||
544 | /* Initialize adapter structure */ | |
545 | mwifiex_init_adapter(adapter); | |
546 | ||
547 | for (i = 0; i < adapter->priv_num; i++) { | |
548 | if (adapter->priv[i]) { | |
549 | priv = adapter->priv[i]; | |
550 | ||
551 | /* Initialize private structure */ | |
552 | ret = mwifiex_init_priv(priv); | |
553 | if (ret) | |
554 | return -1; | |
555 | } | |
556 | } | |
cf5383b0 XH |
557 | if (adapter->mfg_mode) { |
558 | adapter->hw_status = MWIFIEX_HW_STATUS_READY; | |
559 | ret = -EINPROGRESS; | |
560 | } else { | |
561 | for (i = 0; i < adapter->priv_num; i++) { | |
562 | if (adapter->priv[i]) { | |
563 | ret = mwifiex_sta_init_cmd(adapter->priv[i], | |
564 | first_sta, true); | |
565 | if (ret == -1) | |
566 | return -1; | |
567 | ||
568 | first_sta = false; | |
569 | } | |
570 | ||
c6d1d87a | 571 | |
5e6e3a92 | 572 | |
5e6e3a92 BZ |
573 | } |
574 | } | |
575 | ||
576 | spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags); | |
577 | is_cmd_pend_q_empty = list_empty(&adapter->cmd_pending_q); | |
578 | spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, flags); | |
579 | if (!is_cmd_pend_q_empty) { | |
580 | /* Send the first command in queue and return */ | |
581 | if (mwifiex_main_process(adapter) != -1) | |
582 | ret = -EINPROGRESS; | |
583 | } else { | |
584 | adapter->hw_status = MWIFIEX_HW_STATUS_READY; | |
585 | } | |
586 | ||
587 | return ret; | |
588 | } | |
589 | ||
590 | /* | |
591 | * This function deletes the BSS priority tables. | |
592 | * | |
593 | * The function traverses through all the allocated BSS priority nodes | |
594 | * in every BSS priority table and frees them. | |
595 | */ | |
596 | static void mwifiex_delete_bss_prio_tbl(struct mwifiex_private *priv) | |
597 | { | |
598 | int i; | |
599 | struct mwifiex_adapter *adapter = priv->adapter; | |
b006ed54 | 600 | struct mwifiex_bss_prio_node *bssprio_node, *tmp_node; |
5e6e3a92 | 601 | struct list_head *head; |
931f1584 | 602 | spinlock_t *lock; /* bss priority lock */ |
5e6e3a92 BZ |
603 | unsigned long flags; |
604 | ||
605 | for (i = 0; i < adapter->priv_num; ++i) { | |
606 | head = &adapter->bss_prio_tbl[i].bss_prio_head; | |
5e6e3a92 | 607 | lock = &adapter->bss_prio_tbl[i].bss_prio_lock; |
acebe8c1 ZL |
608 | mwifiex_dbg(adapter, INFO, |
609 | "info: delete BSS priority table,\t" | |
610 | "bss_type = %d, bss_num = %d, i = %d,\t" | |
611 | "head = %p\n", | |
612 | priv->bss_type, priv->bss_num, i, head); | |
b006ed54 AF |
613 | |
614 | { | |
5e6e3a92 BZ |
615 | spin_lock_irqsave(lock, flags); |
616 | if (list_empty(head)) { | |
617 | spin_unlock_irqrestore(lock, flags); | |
618 | continue; | |
619 | } | |
5e6e3a92 BZ |
620 | list_for_each_entry_safe(bssprio_node, tmp_node, head, |
621 | list) { | |
622 | if (bssprio_node->priv == priv) { | |
acebe8c1 ZL |
623 | mwifiex_dbg(adapter, INFO, |
624 | "info: Delete\t" | |
625 | "node %p, next = %p\n", | |
626 | bssprio_node, tmp_node); | |
5e6e3a92 | 627 | list_del(&bssprio_node->list); |
5e6e3a92 BZ |
628 | kfree(bssprio_node); |
629 | } | |
630 | } | |
b006ed54 | 631 | spin_unlock_irqrestore(lock, flags); |
5e6e3a92 BZ |
632 | } |
633 | } | |
634 | } | |
635 | ||
9197ab9e SP |
636 | /* |
637 | * This function frees the private structure, including cleans | |
638 | * up the TX and RX queues and frees the BSS priority tables. | |
639 | */ | |
640 | void mwifiex_free_priv(struct mwifiex_private *priv) | |
641 | { | |
642 | mwifiex_clean_txrx(priv); | |
643 | mwifiex_delete_bss_prio_tbl(priv); | |
644 | mwifiex_free_curr_bcn(priv); | |
645 | } | |
646 | ||
5e6e3a92 BZ |
647 | /* |
648 | * This function is used to shutdown the driver. | |
649 | * | |
650 | * The following operations are performed sequentially - | |
651 | * - Check if already shut down | |
652 | * - Make sure the main process has stopped | |
653 | * - Clean up the Tx and Rx queues | |
654 | * - Delete BSS priority tables | |
655 | * - Free the adapter | |
656 | * - Notify completion | |
657 | */ | |
658 | int | |
659 | mwifiex_shutdown_drv(struct mwifiex_adapter *adapter) | |
660 | { | |
661 | int ret = -EINPROGRESS; | |
270e58e8 YAP |
662 | struct mwifiex_private *priv; |
663 | s32 i; | |
6e251174 | 664 | unsigned long flags; |
4daffe35 | 665 | struct sk_buff *skb; |
5e6e3a92 BZ |
666 | |
667 | /* mwifiex already shutdown */ | |
668 | if (adapter->hw_status == MWIFIEX_HW_STATUS_NOT_READY) | |
669 | return 0; | |
670 | ||
671 | adapter->hw_status = MWIFIEX_HW_STATUS_CLOSING; | |
672 | /* wait for mwifiex_process to complete */ | |
673 | if (adapter->mwifiex_processing) { | |
acebe8c1 ZL |
674 | mwifiex_dbg(adapter, WARN, |
675 | "main process is still running\n"); | |
5e6e3a92 BZ |
676 | return ret; |
677 | } | |
678 | ||
084c7189 BZ |
679 | /* cancel current command */ |
680 | if (adapter->curr_cmd) { | |
acebe8c1 ZL |
681 | mwifiex_dbg(adapter, WARN, |
682 | "curr_cmd is still in processing\n"); | |
629873f2 | 683 | del_timer_sync(&adapter->cmd_timer); |
9908b074 | 684 | mwifiex_recycle_cmd_node(adapter, adapter->curr_cmd); |
084c7189 BZ |
685 | adapter->curr_cmd = NULL; |
686 | } | |
687 | ||
5e6e3a92 | 688 | /* shut down mwifiex */ |
acebe8c1 ZL |
689 | mwifiex_dbg(adapter, MSG, |
690 | "info: shutdown mwifiex...\n"); | |
5e6e3a92 BZ |
691 | |
692 | /* Clean up Tx/Rx queues and delete BSS priority table */ | |
693 | for (i = 0; i < adapter->priv_num; i++) { | |
694 | if (adapter->priv[i]) { | |
695 | priv = adapter->priv[i]; | |
696 | ||
9927baa3 | 697 | mwifiex_clean_auto_tdls(priv); |
85afb186 | 698 | mwifiex_abort_cac(priv); |
5e6e3a92 BZ |
699 | mwifiex_clean_txrx(priv); |
700 | mwifiex_delete_bss_prio_tbl(priv); | |
701 | } | |
702 | } | |
703 | ||
e35000ea ZL |
704 | atomic_set(&adapter->tx_queued, 0); |
705 | while ((skb = skb_dequeue(&adapter->tx_data_q))) | |
706 | mwifiex_write_data_complete(adapter, skb, 0, 0); | |
707 | ||
6e251174 AP |
708 | spin_lock_irqsave(&adapter->rx_proc_lock, flags); |
709 | ||
710 | while ((skb = skb_dequeue(&adapter->rx_data_q))) { | |
711 | struct mwifiex_rxinfo *rx_info = MWIFIEX_SKB_RXCB(skb); | |
712 | ||
713 | atomic_dec(&adapter->rx_pending); | |
714 | priv = adapter->priv[rx_info->bss_num]; | |
715 | if (priv) | |
716 | priv->stats.rx_dropped++; | |
717 | ||
718 | dev_kfree_skb_any(skb); | |
719 | } | |
720 | ||
721 | spin_unlock_irqrestore(&adapter->rx_proc_lock, flags); | |
722 | ||
013a492e | 723 | spin_lock(&adapter->mwifiex_lock); |
5e6e3a92 | 724 | |
c56ecf5a | 725 | mwifiex_adapter_cleanup(adapter); |
5e6e3a92 | 726 | |
013a492e | 727 | spin_unlock(&adapter->mwifiex_lock); |
5e6e3a92 BZ |
728 | |
729 | /* Notify completion */ | |
730 | ret = mwifiex_shutdown_fw_complete(adapter); | |
731 | ||
732 | return ret; | |
733 | } | |
734 | ||
735 | /* | |
736 | * This function downloads the firmware to the card. | |
737 | * | |
738 | * The actual download is preceded by two sanity checks - | |
739 | * - Check if firmware is already running | |
740 | * - Check if the interface is the winner to download the firmware | |
741 | * | |
742 | * ...and followed by another - | |
743 | * - Check if the firmware is downloaded successfully | |
744 | * | |
745 | * After download is successfully completed, the host interrupts are enabled. | |
746 | */ | |
747 | int mwifiex_dnld_fw(struct mwifiex_adapter *adapter, | |
748 | struct mwifiex_fw_image *pmfw) | |
749 | { | |
d930faee | 750 | int ret; |
5e6e3a92 | 751 | u32 poll_num = 1; |
5e6e3a92 | 752 | |
4daffe35 | 753 | if (adapter->if_ops.check_fw_status) { |
4daffe35 AK |
754 | /* check if firmware is already running */ |
755 | ret = adapter->if_ops.check_fw_status(adapter, poll_num); | |
756 | if (!ret) { | |
acebe8c1 ZL |
757 | mwifiex_dbg(adapter, MSG, |
758 | "WLAN FW already running! Skip FW dnld\n"); | |
232fde06 | 759 | return 0; |
4daffe35 | 760 | } |
2fd5c6ed | 761 | } |
762 | ||
763 | /* check if we are the winner for downloading FW */ | |
764 | if (adapter->if_ops.check_winner_status) { | |
765 | adapter->winner = 0; | |
766 | ret = adapter->if_ops.check_winner_status(adapter); | |
4daffe35 AK |
767 | |
768 | poll_num = MAX_FIRMWARE_POLL_TRIES; | |
2fd5c6ed | 769 | if (ret) { |
770 | mwifiex_dbg(adapter, MSG, | |
771 | "WLAN read winner status failed!\n"); | |
772 | return ret; | |
773 | } | |
4daffe35 | 774 | |
4daffe35 | 775 | if (!adapter->winner) { |
acebe8c1 | 776 | mwifiex_dbg(adapter, MSG, |
2fd5c6ed | 777 | "WLAN is not the winner! Skip FW dnld\n"); |
4daffe35 AK |
778 | goto poll_fw; |
779 | } | |
5e6e3a92 | 780 | } |
4daffe35 | 781 | |
5e6e3a92 BZ |
782 | if (pmfw) { |
783 | /* Download firmware with helper */ | |
784 | ret = adapter->if_ops.prog_fw(adapter, pmfw); | |
785 | if (ret) { | |
acebe8c1 ZL |
786 | mwifiex_dbg(adapter, ERROR, |
787 | "prog_fw failed ret=%#x\n", ret); | |
5e6e3a92 BZ |
788 | return ret; |
789 | } | |
790 | } | |
791 | ||
792 | poll_fw: | |
793 | /* Check if the firmware is downloaded successfully or not */ | |
d930faee | 794 | ret = adapter->if_ops.check_fw_status(adapter, poll_num); |
232fde06 | 795 | if (ret) |
acebe8c1 ZL |
796 | mwifiex_dbg(adapter, ERROR, |
797 | "FW failed to be active in time\n"); | |
4daffe35 | 798 | |
5e6e3a92 BZ |
799 | return ret; |
800 | } | |
2095b142 | 801 | EXPORT_SYMBOL_GPL(mwifiex_dnld_fw); |