Commit | Line | Data |
---|---|---|
5e6e3a92 BZ |
1 | /* |
2 | * Marvell Wireless LAN device driver: HW/FW Initialization | |
3 | * | |
4 | * Copyright (C) 2011, Marvell International Ltd. | |
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; |
b887664d | 140 | |
636c4598 | 141 | return mwifiex_add_bss_prio_tbl(priv); |
5e6e3a92 BZ |
142 | } |
143 | ||
144 | /* | |
145 | * This function allocates buffers for members of the adapter | |
146 | * structure. | |
147 | * | |
148 | * The memory allocated includes scan table, command buffers, and | |
149 | * sleep confirm command buffer. In addition, the queues are | |
150 | * also initialized. | |
151 | */ | |
152 | static int mwifiex_allocate_adapter(struct mwifiex_adapter *adapter) | |
153 | { | |
270e58e8 | 154 | int ret; |
5e6e3a92 BZ |
155 | |
156 | /* Allocate command buffer */ | |
157 | ret = mwifiex_alloc_cmd_buffer(adapter); | |
158 | if (ret) { | |
159 | dev_err(adapter->dev, "%s: failed to alloc cmd buffer\n", | |
931f1584 | 160 | __func__); |
5e6e3a92 BZ |
161 | return -1; |
162 | } | |
163 | ||
164 | adapter->sleep_cfm = | |
7cc5eb62 | 165 | dev_alloc_skb(sizeof(struct mwifiex_opt_sleep_confirm) |
931f1584 | 166 | + INTF_HEADER_LEN); |
5e6e3a92 BZ |
167 | |
168 | if (!adapter->sleep_cfm) { | |
169 | dev_err(adapter->dev, "%s: failed to alloc sleep cfm" | |
170 | " cmd buffer\n", __func__); | |
171 | return -1; | |
172 | } | |
173 | skb_reserve(adapter->sleep_cfm, INTF_HEADER_LEN); | |
174 | ||
175 | return 0; | |
176 | } | |
177 | ||
178 | /* | |
179 | * This function initializes the adapter structure and sets default | |
180 | * values to the members of adapter. | |
181 | * | |
182 | * This also initializes the WMM related parameters in the driver private | |
183 | * structures. | |
184 | */ | |
185 | static void mwifiex_init_adapter(struct mwifiex_adapter *adapter) | |
186 | { | |
7cc5eb62 | 187 | struct mwifiex_opt_sleep_confirm *sleep_cfm_buf = NULL; |
5e6e3a92 | 188 | |
7cc5eb62 | 189 | skb_put(adapter->sleep_cfm, sizeof(struct mwifiex_opt_sleep_confirm)); |
5e6e3a92 BZ |
190 | |
191 | adapter->cmd_sent = false; | |
d930faee | 192 | |
4daffe35 | 193 | if (adapter->iface_type == MWIFIEX_SDIO) |
d930faee | 194 | adapter->data_sent = true; |
4daffe35 AK |
195 | else |
196 | adapter->data_sent = false; | |
d930faee | 197 | |
5e6e3a92 BZ |
198 | adapter->cmd_resp_received = false; |
199 | adapter->event_received = false; | |
200 | adapter->data_received = false; | |
201 | ||
202 | adapter->surprise_removed = false; | |
203 | ||
204 | adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING; | |
205 | ||
206 | adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM; | |
207 | adapter->ps_state = PS_STATE_AWAKE; | |
208 | adapter->need_to_wakeup = false; | |
209 | ||
210 | adapter->scan_mode = HostCmd_BSS_MODE_ANY; | |
211 | adapter->specific_scan_time = MWIFIEX_SPECIFIC_SCAN_CHAN_TIME; | |
212 | adapter->active_scan_time = MWIFIEX_ACTIVE_SCAN_CHAN_TIME; | |
213 | adapter->passive_scan_time = MWIFIEX_PASSIVE_SCAN_CHAN_TIME; | |
214 | ||
5e6e3a92 BZ |
215 | adapter->scan_probes = 1; |
216 | ||
5e6e3a92 BZ |
217 | adapter->multiple_dtim = 1; |
218 | ||
219 | adapter->local_listen_interval = 0; /* default value in firmware | |
220 | will be used */ | |
221 | ||
222 | adapter->is_deep_sleep = false; | |
223 | ||
224 | adapter->delay_null_pkt = false; | |
225 | adapter->delay_to_ps = 1000; | |
226 | adapter->enhanced_ps_mode = PS_MODE_AUTO; | |
227 | ||
228 | adapter->gen_null_pkt = false; /* Disable NULL Pkg generation by | |
229 | default */ | |
230 | adapter->pps_uapsd_mode = false; /* Disable pps/uapsd mode by | |
231 | default */ | |
232 | adapter->pm_wakeup_card_req = false; | |
233 | ||
234 | adapter->pm_wakeup_fw_try = false; | |
235 | ||
5e6e3a92 BZ |
236 | adapter->tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K; |
237 | adapter->curr_tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K; | |
238 | ||
239 | adapter->is_hs_configured = false; | |
cc0b5a64 AK |
240 | adapter->hs_cfg.conditions = cpu_to_le32(HS_CFG_COND_DEF); |
241 | adapter->hs_cfg.gpio = HS_CFG_GPIO_DEF; | |
242 | adapter->hs_cfg.gap = HS_CFG_GAP_DEF; | |
5e6e3a92 BZ |
243 | adapter->hs_activated = false; |
244 | ||
245 | memset(adapter->event_body, 0, sizeof(adapter->event_body)); | |
246 | adapter->hw_dot_11n_dev_cap = 0; | |
247 | adapter->hw_dev_mcs_support = 0; | |
21c3ba34 | 248 | adapter->sec_chan_offset = 0; |
5e6e3a92 BZ |
249 | adapter->adhoc_11n_enabled = false; |
250 | ||
251 | mwifiex_wmm_init(adapter); | |
252 | ||
253 | if (adapter->sleep_cfm) { | |
8ed13033 YAP |
254 | sleep_cfm_buf = (struct mwifiex_opt_sleep_confirm *) |
255 | adapter->sleep_cfm->data; | |
7cc5eb62 AK |
256 | memset(sleep_cfm_buf, 0, adapter->sleep_cfm->len); |
257 | sleep_cfm_buf->command = | |
258 | cpu_to_le16(HostCmd_CMD_802_11_PS_MODE_ENH); | |
259 | sleep_cfm_buf->size = | |
260 | cpu_to_le16(adapter->sleep_cfm->len); | |
261 | sleep_cfm_buf->result = 0; | |
262 | sleep_cfm_buf->action = cpu_to_le16(SLEEP_CONFIRM); | |
263 | sleep_cfm_buf->resp_ctrl = cpu_to_le16(RESP_NEEDED); | |
5e6e3a92 BZ |
264 | } |
265 | memset(&adapter->sleep_params, 0, sizeof(adapter->sleep_params)); | |
266 | memset(&adapter->sleep_period, 0, sizeof(adapter->sleep_period)); | |
267 | adapter->tx_lock_flag = false; | |
268 | adapter->null_pkt_interval = 0; | |
269 | adapter->fw_bands = 0; | |
270 | adapter->config_bands = 0; | |
271 | adapter->adhoc_start_band = 0; | |
272 | adapter->scan_channels = NULL; | |
273 | adapter->fw_release_number = 0; | |
274 | adapter->fw_cap_info = 0; | |
275 | memset(&adapter->upld_buf, 0, sizeof(adapter->upld_buf)); | |
276 | adapter->event_cause = 0; | |
277 | adapter->region_code = 0; | |
278 | adapter->bcn_miss_time_out = DEFAULT_BCN_MISS_TIMEOUT; | |
279 | adapter->adhoc_awake_period = 0; | |
280 | memset(&adapter->arp_filter, 0, sizeof(adapter->arp_filter)); | |
281 | adapter->arp_filter_size = 0; | |
ede98bfa | 282 | adapter->max_mgmt_ie_index = MAX_MGMT_IE_INDEX; |
bdd37bed | 283 | adapter->empty_tx_q_cnt = 0; |
5e6e3a92 BZ |
284 | } |
285 | ||
bbea3bc4 AP |
286 | /* |
287 | * This function sets trans_start per tx_queue | |
288 | */ | |
289 | void mwifiex_set_trans_start(struct net_device *dev) | |
290 | { | |
291 | int i; | |
292 | ||
293 | for (i = 0; i < dev->num_tx_queues; i++) | |
294 | netdev_get_tx_queue(dev, i)->trans_start = jiffies; | |
295 | ||
296 | dev->trans_start = jiffies; | |
297 | } | |
298 | ||
299 | /* | |
300 | * This function wakes up all queues in net_device | |
301 | */ | |
302 | void mwifiex_wake_up_net_dev_queue(struct net_device *netdev, | |
303 | struct mwifiex_adapter *adapter) | |
304 | { | |
305 | unsigned long dev_queue_flags; | |
47411a06 | 306 | unsigned int i; |
bbea3bc4 AP |
307 | |
308 | spin_lock_irqsave(&adapter->queue_lock, dev_queue_flags); | |
47411a06 AP |
309 | |
310 | for (i = 0; i < netdev->num_tx_queues; i++) { | |
311 | struct netdev_queue *txq = netdev_get_tx_queue(netdev, i); | |
312 | ||
313 | if (netif_tx_queue_stopped(txq)) | |
314 | netif_tx_wake_queue(txq); | |
315 | } | |
316 | ||
bbea3bc4 AP |
317 | spin_unlock_irqrestore(&adapter->queue_lock, dev_queue_flags); |
318 | } | |
319 | ||
320 | /* | |
321 | * This function stops all queues in net_device | |
322 | */ | |
323 | void mwifiex_stop_net_dev_queue(struct net_device *netdev, | |
324 | struct mwifiex_adapter *adapter) | |
325 | { | |
326 | unsigned long dev_queue_flags; | |
47411a06 | 327 | unsigned int i; |
bbea3bc4 AP |
328 | |
329 | spin_lock_irqsave(&adapter->queue_lock, dev_queue_flags); | |
47411a06 AP |
330 | |
331 | for (i = 0; i < netdev->num_tx_queues; i++) { | |
332 | struct netdev_queue *txq = netdev_get_tx_queue(netdev, i); | |
333 | ||
334 | if (!netif_tx_queue_stopped(txq)) | |
335 | netif_tx_stop_queue(txq); | |
336 | } | |
337 | ||
bbea3bc4 AP |
338 | spin_unlock_irqrestore(&adapter->queue_lock, dev_queue_flags); |
339 | } | |
340 | ||
711825a0 AK |
341 | /* |
342 | * This function releases the lock variables and frees the locks and | |
343 | * associated locks. | |
344 | */ | |
345 | static void mwifiex_free_lock_list(struct mwifiex_adapter *adapter) | |
346 | { | |
347 | struct mwifiex_private *priv; | |
348 | s32 i, j; | |
349 | ||
350 | /* Free lists */ | |
351 | list_del(&adapter->cmd_free_q); | |
352 | list_del(&adapter->cmd_pending_q); | |
353 | list_del(&adapter->scan_pending_q); | |
354 | ||
355 | for (i = 0; i < adapter->priv_num; i++) | |
356 | list_del(&adapter->bss_prio_tbl[i].bss_prio_head); | |
357 | ||
358 | for (i = 0; i < adapter->priv_num; i++) { | |
359 | if (adapter->priv[i]) { | |
360 | priv = adapter->priv[i]; | |
361 | for (j = 0; j < MAX_NUM_TID; ++j) | |
362 | list_del(&priv->wmm.tid_tbl_ptr[j].ra_list); | |
363 | list_del(&priv->tx_ba_stream_tbl_ptr); | |
364 | list_del(&priv->rx_reorder_tbl_ptr); | |
017a92a1 | 365 | list_del(&priv->sta_list); |
711825a0 AK |
366 | } |
367 | } | |
368 | } | |
369 | ||
5e6e3a92 | 370 | /* |
c56ecf5a | 371 | * This function performs cleanup for adapter structure. |
5e6e3a92 | 372 | * |
c56ecf5a AK |
373 | * The cleanup is done recursively, by canceling all pending |
374 | * commands, freeing the member buffers previously allocated | |
375 | * (command buffers, scan table buffer, sleep confirm command | |
376 | * buffer), stopping the timers and calling the cleanup routines | |
377 | * for every interface. | |
5e6e3a92 BZ |
378 | */ |
379 | static void | |
c56ecf5a | 380 | mwifiex_adapter_cleanup(struct mwifiex_adapter *adapter) |
5e6e3a92 BZ |
381 | { |
382 | if (!adapter) { | |
383 | pr_err("%s: adapter is NULL\n", __func__); | |
384 | return; | |
385 | } | |
386 | ||
387 | mwifiex_cancel_all_pending_cmd(adapter); | |
388 | ||
389 | /* Free lock variables */ | |
390 | mwifiex_free_lock_list(adapter); | |
391 | ||
392 | /* Free command buffer */ | |
393 | dev_dbg(adapter->dev, "info: free cmd buffer\n"); | |
394 | mwifiex_free_cmd_buffer(adapter); | |
395 | ||
5e6e3a92 | 396 | dev_dbg(adapter->dev, "info: free scan table\n"); |
5e6e3a92 | 397 | |
2da8cbf8 AK |
398 | if (adapter->sleep_cfm) |
399 | dev_kfree_skb_any(adapter->sleep_cfm); | |
5e6e3a92 BZ |
400 | } |
401 | ||
402 | /* | |
403 | * This function intializes the lock variables and | |
404 | * the list heads. | |
405 | */ | |
406 | int mwifiex_init_lock_list(struct mwifiex_adapter *adapter) | |
407 | { | |
270e58e8 YAP |
408 | struct mwifiex_private *priv; |
409 | s32 i, j; | |
5e6e3a92 BZ |
410 | |
411 | spin_lock_init(&adapter->mwifiex_lock); | |
412 | spin_lock_init(&adapter->int_lock); | |
413 | spin_lock_init(&adapter->main_proc_lock); | |
414 | spin_lock_init(&adapter->mwifiex_cmd_lock); | |
bbea3bc4 | 415 | spin_lock_init(&adapter->queue_lock); |
5e6e3a92 BZ |
416 | for (i = 0; i < adapter->priv_num; i++) { |
417 | if (adapter->priv[i]) { | |
418 | priv = adapter->priv[i]; | |
419 | spin_lock_init(&priv->rx_pkt_lock); | |
420 | spin_lock_init(&priv->wmm.ra_list_spinlock); | |
421 | spin_lock_init(&priv->curr_bcn_buf_lock); | |
017a92a1 | 422 | spin_lock_init(&priv->sta_list_spinlock); |
5e6e3a92 BZ |
423 | } |
424 | } | |
425 | ||
426 | /* Initialize cmd_free_q */ | |
427 | INIT_LIST_HEAD(&adapter->cmd_free_q); | |
428 | /* Initialize cmd_pending_q */ | |
429 | INIT_LIST_HEAD(&adapter->cmd_pending_q); | |
430 | /* Initialize scan_pending_q */ | |
431 | INIT_LIST_HEAD(&adapter->scan_pending_q); | |
432 | ||
433 | spin_lock_init(&adapter->cmd_free_q_lock); | |
434 | spin_lock_init(&adapter->cmd_pending_q_lock); | |
435 | spin_lock_init(&adapter->scan_pending_q_lock); | |
436 | ||
4daffe35 AK |
437 | skb_queue_head_init(&adapter->usb_rx_data_q); |
438 | ||
5e6e3a92 BZ |
439 | for (i = 0; i < adapter->priv_num; ++i) { |
440 | INIT_LIST_HEAD(&adapter->bss_prio_tbl[i].bss_prio_head); | |
5e6e3a92 BZ |
441 | spin_lock_init(&adapter->bss_prio_tbl[i].bss_prio_lock); |
442 | } | |
443 | ||
444 | for (i = 0; i < adapter->priv_num; i++) { | |
445 | if (!adapter->priv[i]) | |
446 | continue; | |
447 | priv = adapter->priv[i]; | |
6d2344ec | 448 | for (j = 0; j < MAX_NUM_TID; ++j) |
5e6e3a92 | 449 | INIT_LIST_HEAD(&priv->wmm.tid_tbl_ptr[j].ra_list); |
5e6e3a92 BZ |
450 | INIT_LIST_HEAD(&priv->tx_ba_stream_tbl_ptr); |
451 | INIT_LIST_HEAD(&priv->rx_reorder_tbl_ptr); | |
017a92a1 | 452 | INIT_LIST_HEAD(&priv->sta_list); |
5e6e3a92 BZ |
453 | |
454 | spin_lock_init(&priv->tx_ba_stream_tbl_lock); | |
455 | spin_lock_init(&priv->rx_reorder_tbl_lock); | |
456 | } | |
457 | ||
458 | return 0; | |
459 | } | |
460 | ||
5e6e3a92 BZ |
461 | /* |
462 | * This function initializes the firmware. | |
463 | * | |
464 | * The following operations are performed sequentially - | |
465 | * - Allocate adapter structure | |
466 | * - Initialize the adapter structure | |
467 | * - Initialize the private structure | |
468 | * - Add BSS priority tables to the adapter structure | |
469 | * - For each interface, send the init commands to firmware | |
470 | * - Send the first command in command pending queue, if available | |
471 | */ | |
472 | int mwifiex_init_fw(struct mwifiex_adapter *adapter) | |
473 | { | |
270e58e8 YAP |
474 | int ret; |
475 | struct mwifiex_private *priv; | |
476 | u8 i, first_sta = true; | |
5e6e3a92 BZ |
477 | int is_cmd_pend_q_empty; |
478 | unsigned long flags; | |
479 | ||
480 | adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING; | |
481 | ||
482 | /* Allocate memory for member of adapter structure */ | |
483 | ret = mwifiex_allocate_adapter(adapter); | |
484 | if (ret) | |
485 | return -1; | |
486 | ||
487 | /* Initialize adapter structure */ | |
488 | mwifiex_init_adapter(adapter); | |
489 | ||
490 | for (i = 0; i < adapter->priv_num; i++) { | |
491 | if (adapter->priv[i]) { | |
492 | priv = adapter->priv[i]; | |
493 | ||
494 | /* Initialize private structure */ | |
495 | ret = mwifiex_init_priv(priv); | |
496 | if (ret) | |
497 | return -1; | |
498 | } | |
499 | } | |
c6d1d87a AP |
500 | |
501 | if (adapter->if_ops.init_fw_port) { | |
502 | if (adapter->if_ops.init_fw_port(adapter)) | |
503 | return -1; | |
504 | } | |
505 | ||
5e6e3a92 BZ |
506 | for (i = 0; i < adapter->priv_num; i++) { |
507 | if (adapter->priv[i]) { | |
508 | ret = mwifiex_sta_init_cmd(adapter->priv[i], first_sta); | |
509 | if (ret == -1) | |
510 | return -1; | |
511 | ||
512 | first_sta = false; | |
513 | } | |
514 | } | |
515 | ||
516 | spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags); | |
517 | is_cmd_pend_q_empty = list_empty(&adapter->cmd_pending_q); | |
518 | spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, flags); | |
519 | if (!is_cmd_pend_q_empty) { | |
520 | /* Send the first command in queue and return */ | |
521 | if (mwifiex_main_process(adapter) != -1) | |
522 | ret = -EINPROGRESS; | |
523 | } else { | |
524 | adapter->hw_status = MWIFIEX_HW_STATUS_READY; | |
525 | } | |
526 | ||
527 | return ret; | |
528 | } | |
529 | ||
530 | /* | |
531 | * This function deletes the BSS priority tables. | |
532 | * | |
533 | * The function traverses through all the allocated BSS priority nodes | |
534 | * in every BSS priority table and frees them. | |
535 | */ | |
536 | static void mwifiex_delete_bss_prio_tbl(struct mwifiex_private *priv) | |
537 | { | |
538 | int i; | |
539 | struct mwifiex_adapter *adapter = priv->adapter; | |
b006ed54 | 540 | struct mwifiex_bss_prio_node *bssprio_node, *tmp_node; |
5e6e3a92 | 541 | struct list_head *head; |
931f1584 | 542 | spinlock_t *lock; /* bss priority lock */ |
5e6e3a92 BZ |
543 | unsigned long flags; |
544 | ||
545 | for (i = 0; i < adapter->priv_num; ++i) { | |
546 | head = &adapter->bss_prio_tbl[i].bss_prio_head; | |
5e6e3a92 BZ |
547 | lock = &adapter->bss_prio_tbl[i].bss_prio_lock; |
548 | dev_dbg(adapter->dev, "info: delete BSS priority table," | |
9da9a3b2 | 549 | " bss_type = %d, bss_num = %d, i = %d," |
b006ed54 AF |
550 | " head = %p\n", |
551 | priv->bss_type, priv->bss_num, i, head); | |
552 | ||
553 | { | |
5e6e3a92 BZ |
554 | spin_lock_irqsave(lock, flags); |
555 | if (list_empty(head)) { | |
556 | spin_unlock_irqrestore(lock, flags); | |
557 | continue; | |
558 | } | |
5e6e3a92 BZ |
559 | list_for_each_entry_safe(bssprio_node, tmp_node, head, |
560 | list) { | |
561 | if (bssprio_node->priv == priv) { | |
562 | dev_dbg(adapter->dev, "info: Delete " | |
563 | "node %p, next = %p\n", | |
564 | bssprio_node, tmp_node); | |
5e6e3a92 | 565 | list_del(&bssprio_node->list); |
5e6e3a92 BZ |
566 | kfree(bssprio_node); |
567 | } | |
568 | } | |
b006ed54 | 569 | spin_unlock_irqrestore(lock, flags); |
5e6e3a92 BZ |
570 | } |
571 | } | |
572 | } | |
573 | ||
9197ab9e SP |
574 | /* |
575 | * This function frees the private structure, including cleans | |
576 | * up the TX and RX queues and frees the BSS priority tables. | |
577 | */ | |
578 | void mwifiex_free_priv(struct mwifiex_private *priv) | |
579 | { | |
580 | mwifiex_clean_txrx(priv); | |
581 | mwifiex_delete_bss_prio_tbl(priv); | |
582 | mwifiex_free_curr_bcn(priv); | |
583 | } | |
584 | ||
5e6e3a92 BZ |
585 | /* |
586 | * This function is used to shutdown the driver. | |
587 | * | |
588 | * The following operations are performed sequentially - | |
589 | * - Check if already shut down | |
590 | * - Make sure the main process has stopped | |
591 | * - Clean up the Tx and Rx queues | |
592 | * - Delete BSS priority tables | |
593 | * - Free the adapter | |
594 | * - Notify completion | |
595 | */ | |
596 | int | |
597 | mwifiex_shutdown_drv(struct mwifiex_adapter *adapter) | |
598 | { | |
599 | int ret = -EINPROGRESS; | |
270e58e8 YAP |
600 | struct mwifiex_private *priv; |
601 | s32 i; | |
4daffe35 | 602 | struct sk_buff *skb; |
5e6e3a92 BZ |
603 | |
604 | /* mwifiex already shutdown */ | |
605 | if (adapter->hw_status == MWIFIEX_HW_STATUS_NOT_READY) | |
606 | return 0; | |
607 | ||
608 | adapter->hw_status = MWIFIEX_HW_STATUS_CLOSING; | |
609 | /* wait for mwifiex_process to complete */ | |
610 | if (adapter->mwifiex_processing) { | |
611 | dev_warn(adapter->dev, "main process is still running\n"); | |
612 | return ret; | |
613 | } | |
614 | ||
084c7189 BZ |
615 | /* cancel current command */ |
616 | if (adapter->curr_cmd) { | |
617 | dev_warn(adapter->dev, "curr_cmd is still in processing\n"); | |
618 | del_timer(&adapter->cmd_timer); | |
9908b074 | 619 | mwifiex_recycle_cmd_node(adapter, adapter->curr_cmd); |
084c7189 BZ |
620 | adapter->curr_cmd = NULL; |
621 | } | |
622 | ||
5e6e3a92 BZ |
623 | /* shut down mwifiex */ |
624 | dev_dbg(adapter->dev, "info: shutdown mwifiex...\n"); | |
625 | ||
626 | /* Clean up Tx/Rx queues and delete BSS priority table */ | |
627 | for (i = 0; i < adapter->priv_num; i++) { | |
628 | if (adapter->priv[i]) { | |
629 | priv = adapter->priv[i]; | |
630 | ||
631 | mwifiex_clean_txrx(priv); | |
632 | mwifiex_delete_bss_prio_tbl(priv); | |
633 | } | |
634 | } | |
635 | ||
013a492e | 636 | spin_lock(&adapter->mwifiex_lock); |
5e6e3a92 | 637 | |
4daffe35 AK |
638 | if (adapter->if_ops.data_complete) { |
639 | while ((skb = skb_dequeue(&adapter->usb_rx_data_q))) { | |
640 | struct mwifiex_rxinfo *rx_info = MWIFIEX_SKB_RXCB(skb); | |
641 | ||
642 | priv = adapter->priv[rx_info->bss_num]; | |
643 | if (priv) | |
644 | priv->stats.rx_dropped++; | |
645 | ||
ca8d6dfc UR |
646 | dev_kfree_skb_any(skb); |
647 | adapter->if_ops.data_complete(adapter); | |
4daffe35 AK |
648 | } |
649 | } | |
650 | ||
c56ecf5a | 651 | mwifiex_adapter_cleanup(adapter); |
5e6e3a92 | 652 | |
013a492e | 653 | spin_unlock(&adapter->mwifiex_lock); |
5e6e3a92 BZ |
654 | |
655 | /* Notify completion */ | |
656 | ret = mwifiex_shutdown_fw_complete(adapter); | |
657 | ||
658 | return ret; | |
659 | } | |
660 | ||
661 | /* | |
662 | * This function downloads the firmware to the card. | |
663 | * | |
664 | * The actual download is preceded by two sanity checks - | |
665 | * - Check if firmware is already running | |
666 | * - Check if the interface is the winner to download the firmware | |
667 | * | |
668 | * ...and followed by another - | |
669 | * - Check if the firmware is downloaded successfully | |
670 | * | |
671 | * After download is successfully completed, the host interrupts are enabled. | |
672 | */ | |
673 | int mwifiex_dnld_fw(struct mwifiex_adapter *adapter, | |
674 | struct mwifiex_fw_image *pmfw) | |
675 | { | |
d930faee | 676 | int ret; |
5e6e3a92 | 677 | u32 poll_num = 1; |
5e6e3a92 | 678 | |
4daffe35 AK |
679 | if (adapter->if_ops.check_fw_status) { |
680 | adapter->winner = 0; | |
d930faee | 681 | |
4daffe35 AK |
682 | /* check if firmware is already running */ |
683 | ret = adapter->if_ops.check_fw_status(adapter, poll_num); | |
684 | if (!ret) { | |
685 | dev_notice(adapter->dev, | |
686 | "WLAN FW already running! Skip FW dnld\n"); | |
232fde06 | 687 | return 0; |
4daffe35 AK |
688 | } |
689 | ||
690 | poll_num = MAX_FIRMWARE_POLL_TRIES; | |
691 | ||
692 | /* check if we are the winner for downloading FW */ | |
693 | if (!adapter->winner) { | |
694 | dev_notice(adapter->dev, | |
695 | "FW already running! Skip FW dnld\n"); | |
4daffe35 AK |
696 | goto poll_fw; |
697 | } | |
5e6e3a92 | 698 | } |
4daffe35 | 699 | |
5e6e3a92 BZ |
700 | if (pmfw) { |
701 | /* Download firmware with helper */ | |
702 | ret = adapter->if_ops.prog_fw(adapter, pmfw); | |
703 | if (ret) { | |
704 | dev_err(adapter->dev, "prog_fw failed ret=%#x\n", ret); | |
705 | return ret; | |
706 | } | |
707 | } | |
708 | ||
709 | poll_fw: | |
710 | /* Check if the firmware is downloaded successfully or not */ | |
d930faee | 711 | ret = adapter->if_ops.check_fw_status(adapter, poll_num); |
232fde06 | 712 | if (ret) |
5e6e3a92 | 713 | dev_err(adapter->dev, "FW failed to be active in time\n"); |
4daffe35 | 714 | |
5e6e3a92 BZ |
715 | return ret; |
716 | } |