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