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