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