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; | |
5e6e3a92 BZ |
38 | unsigned long flags; |
39 | ||
40 | bss_prio = kzalloc(sizeof(struct mwifiex_bss_prio_node), GFP_KERNEL); | |
41 | if (!bss_prio) { | |
42 | dev_err(adapter->dev, "%s: failed to alloc bss_prio\n", | |
43 | __func__); | |
44 | return -1; | |
45 | } | |
46 | ||
47 | bss_prio->priv = priv; | |
48 | INIT_LIST_HEAD(&bss_prio->list); | |
49 | if (!adapter->bss_prio_tbl[priv->bss_priority].bss_prio_cur) | |
50 | adapter->bss_prio_tbl[priv->bss_priority].bss_prio_cur = | |
51 | bss_prio; | |
52 | ||
53 | spin_lock_irqsave(&adapter->bss_prio_tbl[priv->bss_priority] | |
54 | .bss_prio_lock, flags); | |
55 | list_add_tail(&bss_prio->list, | |
56 | &adapter->bss_prio_tbl[priv->bss_priority] | |
57 | .bss_prio_head); | |
58 | spin_unlock_irqrestore(&adapter->bss_prio_tbl[priv->bss_priority] | |
59 | .bss_prio_lock, flags); | |
60 | ||
600f5d90 | 61 | return 0; |
5e6e3a92 BZ |
62 | } |
63 | ||
64 | /* | |
65 | * This function initializes the private structure and sets default | |
66 | * values to the members. | |
67 | * | |
68 | * Additionally, it also initializes all the locks and sets up all the | |
69 | * lists. | |
70 | */ | |
71 | static int mwifiex_init_priv(struct mwifiex_private *priv) | |
72 | { | |
73 | u32 i; | |
74 | int ret = 0; | |
75 | ||
76 | priv->media_connected = false; | |
77 | memset(priv->curr_addr, 0xff, ETH_ALEN); | |
78 | ||
79 | priv->pkt_tx_ctrl = 0; | |
eecd8250 | 80 | priv->bss_mode = NL80211_IFTYPE_STATION; |
5e6e3a92 BZ |
81 | priv->data_rate = 0; /* Initially indicate the rate as auto */ |
82 | priv->is_data_rate_auto = true; | |
83 | priv->bcn_avg_factor = DEFAULT_BCN_AVG_FACTOR; | |
84 | priv->data_avg_factor = DEFAULT_DATA_AVG_FACTOR; | |
85 | ||
86 | priv->sec_info.wep_status = MWIFIEX_802_11_WEP_DISABLED; | |
f986b6d5 | 87 | priv->sec_info.authentication_mode = NL80211_AUTHTYPE_OPEN_SYSTEM; |
2be50b8d | 88 | priv->sec_info.encryption_mode = 0; |
5e6e3a92 BZ |
89 | for (i = 0; i < ARRAY_SIZE(priv->wep_key); i++) |
90 | memset(&priv->wep_key[i], 0, sizeof(struct mwifiex_wep_key)); | |
91 | priv->wep_key_curr_index = 0; | |
92 | priv->curr_pkt_filter = HostCmd_ACT_MAC_RX_ON | HostCmd_ACT_MAC_TX_ON | | |
93 | HostCmd_ACT_MAC_ETHERNETII_ENABLE; | |
94 | ||
95 | priv->beacon_period = 100; /* beacon interval */ ; | |
96 | priv->attempted_bss_desc = NULL; | |
97 | memset(&priv->curr_bss_params, 0, sizeof(priv->curr_bss_params)); | |
98 | priv->listen_interval = MWIFIEX_DEFAULT_LISTEN_INTERVAL; | |
99 | ||
100 | memset(&priv->prev_ssid, 0, sizeof(priv->prev_ssid)); | |
101 | memset(&priv->prev_bssid, 0, sizeof(priv->prev_bssid)); | |
102 | memset(&priv->assoc_rsp_buf, 0, sizeof(priv->assoc_rsp_buf)); | |
103 | priv->assoc_rsp_size = 0; | |
104 | priv->adhoc_channel = DEFAULT_AD_HOC_CHANNEL; | |
105 | priv->atim_window = 0; | |
106 | priv->adhoc_state = ADHOC_IDLE; | |
107 | priv->tx_power_level = 0; | |
108 | priv->max_tx_power_level = 0; | |
109 | priv->min_tx_power_level = 0; | |
110 | priv->tx_rate = 0; | |
111 | priv->rxpd_htinfo = 0; | |
112 | priv->rxpd_rate = 0; | |
113 | priv->rate_bitmap = 0; | |
114 | priv->data_rssi_last = 0; | |
115 | priv->data_rssi_avg = 0; | |
116 | priv->data_nf_avg = 0; | |
117 | priv->data_nf_last = 0; | |
118 | priv->bcn_rssi_last = 0; | |
119 | priv->bcn_rssi_avg = 0; | |
120 | priv->bcn_nf_avg = 0; | |
121 | priv->bcn_nf_last = 0; | |
122 | memset(&priv->wpa_ie, 0, sizeof(priv->wpa_ie)); | |
123 | memset(&priv->aes_key, 0, sizeof(priv->aes_key)); | |
124 | priv->wpa_ie_len = 0; | |
125 | priv->wpa_is_gtk_set = false; | |
126 | ||
127 | memset(&priv->assoc_tlv_buf, 0, sizeof(priv->assoc_tlv_buf)); | |
128 | priv->assoc_tlv_buf_len = 0; | |
129 | memset(&priv->wps, 0, sizeof(priv->wps)); | |
130 | memset(&priv->gen_ie_buf, 0, sizeof(priv->gen_ie_buf)); | |
131 | priv->gen_ie_buf_len = 0; | |
132 | memset(priv->vs_ie, 0, sizeof(priv->vs_ie)); | |
133 | ||
134 | priv->wmm_required = true; | |
135 | priv->wmm_enabled = false; | |
136 | priv->wmm_qosinfo = 0; | |
137 | priv->curr_bcn_buf = NULL; | |
138 | priv->curr_bcn_size = 0; | |
139 | ||
140 | priv->scan_block = false; | |
141 | ||
142 | ret = mwifiex_add_bss_prio_tbl(priv); | |
143 | ||
144 | return ret; | |
145 | } | |
146 | ||
147 | /* | |
148 | * This function allocates buffers for members of the adapter | |
149 | * structure. | |
150 | * | |
151 | * The memory allocated includes scan table, command buffers, and | |
152 | * sleep confirm command buffer. In addition, the queues are | |
153 | * also initialized. | |
154 | */ | |
155 | static int mwifiex_allocate_adapter(struct mwifiex_adapter *adapter) | |
156 | { | |
157 | int ret = 0; | |
158 | u32 buf_size; | |
159 | struct mwifiex_bssdescriptor *temp_scan_table; | |
160 | ||
161 | /* Allocate buffer to store the BSSID list */ | |
162 | buf_size = sizeof(struct mwifiex_bssdescriptor) * IW_MAX_AP; | |
163 | temp_scan_table = kzalloc(buf_size, GFP_KERNEL); | |
164 | if (!temp_scan_table) { | |
165 | dev_err(adapter->dev, "%s: failed to alloc temp_scan_table\n", | |
166 | __func__); | |
167 | return -1; | |
168 | } | |
169 | ||
170 | adapter->scan_table = temp_scan_table; | |
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", | |
176 | __func__); | |
177 | return -1; | |
178 | } | |
179 | ||
180 | adapter->sleep_cfm = | |
181 | dev_alloc_skb(sizeof(struct mwifiex_opt_sleep_confirm_buffer) | |
182 | + INTF_HEADER_LEN); | |
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 | { | |
203 | struct mwifiex_opt_sleep_confirm_buffer *sleep_cfm_buf = NULL; | |
204 | ||
205 | skb_put(adapter->sleep_cfm, sizeof(sleep_cfm_buf->ps_cfm_sleep)); | |
206 | sleep_cfm_buf = (struct mwifiex_opt_sleep_confirm_buffer *) | |
207 | (adapter->sleep_cfm->data); | |
208 | ||
209 | adapter->cmd_sent = false; | |
210 | adapter->data_sent = true; | |
211 | adapter->cmd_resp_received = false; | |
212 | adapter->event_received = false; | |
213 | adapter->data_received = false; | |
214 | ||
215 | adapter->surprise_removed = false; | |
216 | ||
217 | adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING; | |
218 | ||
219 | adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM; | |
220 | adapter->ps_state = PS_STATE_AWAKE; | |
221 | adapter->need_to_wakeup = false; | |
222 | ||
223 | adapter->scan_mode = HostCmd_BSS_MODE_ANY; | |
224 | adapter->specific_scan_time = MWIFIEX_SPECIFIC_SCAN_CHAN_TIME; | |
225 | adapter->active_scan_time = MWIFIEX_ACTIVE_SCAN_CHAN_TIME; | |
226 | adapter->passive_scan_time = MWIFIEX_PASSIVE_SCAN_CHAN_TIME; | |
227 | ||
228 | adapter->num_in_scan_table = 0; | |
229 | memset(adapter->scan_table, 0, | |
230 | (sizeof(struct mwifiex_bssdescriptor) * IW_MAX_AP)); | |
231 | adapter->scan_probes = 1; | |
232 | ||
233 | memset(adapter->bcn_buf, 0, sizeof(adapter->bcn_buf)); | |
234 | adapter->bcn_buf_end = adapter->bcn_buf; | |
235 | ||
5e6e3a92 BZ |
236 | adapter->multiple_dtim = 1; |
237 | ||
238 | adapter->local_listen_interval = 0; /* default value in firmware | |
239 | will be used */ | |
240 | ||
241 | adapter->is_deep_sleep = false; | |
242 | ||
243 | adapter->delay_null_pkt = false; | |
244 | adapter->delay_to_ps = 1000; | |
245 | adapter->enhanced_ps_mode = PS_MODE_AUTO; | |
246 | ||
247 | adapter->gen_null_pkt = false; /* Disable NULL Pkg generation by | |
248 | default */ | |
249 | adapter->pps_uapsd_mode = false; /* Disable pps/uapsd mode by | |
250 | default */ | |
251 | adapter->pm_wakeup_card_req = false; | |
252 | ||
253 | adapter->pm_wakeup_fw_try = false; | |
254 | ||
255 | adapter->max_tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K; | |
256 | adapter->tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K; | |
257 | adapter->curr_tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K; | |
258 | ||
259 | adapter->is_hs_configured = false; | |
260 | adapter->hs_cfg.conditions = cpu_to_le32(HOST_SLEEP_CFG_COND_DEF); | |
261 | adapter->hs_cfg.gpio = HOST_SLEEP_CFG_GPIO_DEF; | |
262 | adapter->hs_cfg.gap = HOST_SLEEP_CFG_GAP_DEF; | |
263 | adapter->hs_activated = false; | |
264 | ||
265 | memset(adapter->event_body, 0, sizeof(adapter->event_body)); | |
266 | adapter->hw_dot_11n_dev_cap = 0; | |
267 | adapter->hw_dev_mcs_support = 0; | |
5e6e3a92 BZ |
268 | adapter->chan_offset = 0; |
269 | adapter->adhoc_11n_enabled = false; | |
270 | ||
271 | mwifiex_wmm_init(adapter); | |
272 | ||
273 | if (adapter->sleep_cfm) { | |
274 | memset(&sleep_cfm_buf->ps_cfm_sleep, 0, | |
275 | adapter->sleep_cfm->len); | |
276 | sleep_cfm_buf->ps_cfm_sleep.command = | |
277 | cpu_to_le16(HostCmd_CMD_802_11_PS_MODE_ENH); | |
278 | sleep_cfm_buf->ps_cfm_sleep.size = | |
279 | cpu_to_le16(adapter->sleep_cfm->len); | |
280 | sleep_cfm_buf->ps_cfm_sleep.result = 0; | |
281 | sleep_cfm_buf->ps_cfm_sleep.action = cpu_to_le16(SLEEP_CONFIRM); | |
2b06bdbe | 282 | sleep_cfm_buf->ps_cfm_sleep.resp_ctrl = |
5e6e3a92 BZ |
283 | cpu_to_le16(RESP_NEEDED); |
284 | } | |
285 | memset(&adapter->sleep_params, 0, sizeof(adapter->sleep_params)); | |
286 | memset(&adapter->sleep_period, 0, sizeof(adapter->sleep_period)); | |
287 | adapter->tx_lock_flag = false; | |
288 | adapter->null_pkt_interval = 0; | |
289 | adapter->fw_bands = 0; | |
290 | adapter->config_bands = 0; | |
291 | adapter->adhoc_start_band = 0; | |
292 | adapter->scan_channels = NULL; | |
293 | adapter->fw_release_number = 0; | |
294 | adapter->fw_cap_info = 0; | |
295 | memset(&adapter->upld_buf, 0, sizeof(adapter->upld_buf)); | |
296 | adapter->event_cause = 0; | |
297 | adapter->region_code = 0; | |
298 | adapter->bcn_miss_time_out = DEFAULT_BCN_MISS_TIMEOUT; | |
299 | adapter->adhoc_awake_period = 0; | |
300 | memset(&adapter->arp_filter, 0, sizeof(adapter->arp_filter)); | |
301 | adapter->arp_filter_size = 0; | |
5e6e3a92 BZ |
302 | } |
303 | ||
304 | /* | |
305 | * This function frees the adapter structure. | |
306 | * | |
307 | * The freeing operation is done recursively, by canceling all | |
308 | * pending commands, freeing the member buffers previously | |
309 | * allocated (command buffers, scan table buffer, sleep confirm | |
310 | * command buffer), stopping the timers and calling the cleanup | |
311 | * routines for every interface, before the actual adapter | |
312 | * structure is freed. | |
313 | */ | |
314 | static void | |
315 | mwifiex_free_adapter(struct mwifiex_adapter *adapter) | |
316 | { | |
317 | if (!adapter) { | |
318 | pr_err("%s: adapter is NULL\n", __func__); | |
319 | return; | |
320 | } | |
321 | ||
322 | mwifiex_cancel_all_pending_cmd(adapter); | |
323 | ||
324 | /* Free lock variables */ | |
325 | mwifiex_free_lock_list(adapter); | |
326 | ||
327 | /* Free command buffer */ | |
328 | dev_dbg(adapter->dev, "info: free cmd buffer\n"); | |
329 | mwifiex_free_cmd_buffer(adapter); | |
330 | ||
331 | del_timer(&adapter->cmd_timer); | |
332 | ||
333 | dev_dbg(adapter->dev, "info: free scan table\n"); | |
334 | kfree(adapter->scan_table); | |
335 | adapter->scan_table = NULL; | |
336 | ||
337 | adapter->if_ops.cleanup_if(adapter); | |
338 | ||
339 | dev_kfree_skb_any(adapter->sleep_cfm); | |
5e6e3a92 BZ |
340 | } |
341 | ||
342 | /* | |
343 | * This function intializes the lock variables and | |
344 | * the list heads. | |
345 | */ | |
346 | int mwifiex_init_lock_list(struct mwifiex_adapter *adapter) | |
347 | { | |
348 | struct mwifiex_private *priv = NULL; | |
349 | s32 i = 0; | |
350 | u32 j = 0; | |
351 | ||
352 | spin_lock_init(&adapter->mwifiex_lock); | |
353 | spin_lock_init(&adapter->int_lock); | |
354 | spin_lock_init(&adapter->main_proc_lock); | |
355 | spin_lock_init(&adapter->mwifiex_cmd_lock); | |
356 | for (i = 0; i < adapter->priv_num; i++) { | |
357 | if (adapter->priv[i]) { | |
358 | priv = adapter->priv[i]; | |
359 | spin_lock_init(&priv->rx_pkt_lock); | |
360 | spin_lock_init(&priv->wmm.ra_list_spinlock); | |
361 | spin_lock_init(&priv->curr_bcn_buf_lock); | |
362 | } | |
363 | } | |
364 | ||
365 | /* Initialize cmd_free_q */ | |
366 | INIT_LIST_HEAD(&adapter->cmd_free_q); | |
367 | /* Initialize cmd_pending_q */ | |
368 | INIT_LIST_HEAD(&adapter->cmd_pending_q); | |
369 | /* Initialize scan_pending_q */ | |
370 | INIT_LIST_HEAD(&adapter->scan_pending_q); | |
371 | ||
372 | spin_lock_init(&adapter->cmd_free_q_lock); | |
373 | spin_lock_init(&adapter->cmd_pending_q_lock); | |
374 | spin_lock_init(&adapter->scan_pending_q_lock); | |
375 | ||
376 | for (i = 0; i < adapter->priv_num; ++i) { | |
377 | INIT_LIST_HEAD(&adapter->bss_prio_tbl[i].bss_prio_head); | |
378 | adapter->bss_prio_tbl[i].bss_prio_cur = NULL; | |
379 | spin_lock_init(&adapter->bss_prio_tbl[i].bss_prio_lock); | |
380 | } | |
381 | ||
382 | for (i = 0; i < adapter->priv_num; i++) { | |
383 | if (!adapter->priv[i]) | |
384 | continue; | |
385 | priv = adapter->priv[i]; | |
386 | for (j = 0; j < MAX_NUM_TID; ++j) { | |
387 | INIT_LIST_HEAD(&priv->wmm.tid_tbl_ptr[j].ra_list); | |
388 | spin_lock_init(&priv->wmm.tid_tbl_ptr[j].tid_tbl_lock); | |
389 | } | |
390 | INIT_LIST_HEAD(&priv->tx_ba_stream_tbl_ptr); | |
391 | INIT_LIST_HEAD(&priv->rx_reorder_tbl_ptr); | |
392 | ||
393 | spin_lock_init(&priv->tx_ba_stream_tbl_lock); | |
394 | spin_lock_init(&priv->rx_reorder_tbl_lock); | |
395 | } | |
396 | ||
397 | return 0; | |
398 | } | |
399 | ||
400 | /* | |
401 | * This function releases the lock variables and frees the locks and | |
402 | * associated locks. | |
403 | */ | |
404 | void mwifiex_free_lock_list(struct mwifiex_adapter *adapter) | |
405 | { | |
406 | struct mwifiex_private *priv = NULL; | |
407 | s32 i = 0; | |
408 | s32 j = 0; | |
409 | ||
410 | /* Free lists */ | |
411 | list_del(&adapter->cmd_free_q); | |
412 | list_del(&adapter->cmd_pending_q); | |
413 | list_del(&adapter->scan_pending_q); | |
414 | ||
415 | for (i = 0; i < adapter->priv_num; i++) | |
416 | list_del(&adapter->bss_prio_tbl[i].bss_prio_head); | |
417 | ||
418 | for (i = 0; i < adapter->priv_num; i++) { | |
419 | if (adapter->priv[i]) { | |
420 | priv = adapter->priv[i]; | |
421 | for (j = 0; j < MAX_NUM_TID; ++j) | |
422 | list_del(&priv->wmm.tid_tbl_ptr[j].ra_list); | |
423 | list_del(&priv->tx_ba_stream_tbl_ptr); | |
424 | list_del(&priv->rx_reorder_tbl_ptr); | |
425 | } | |
426 | } | |
5e6e3a92 BZ |
427 | } |
428 | ||
429 | /* | |
430 | * This function initializes the firmware. | |
431 | * | |
432 | * The following operations are performed sequentially - | |
433 | * - Allocate adapter structure | |
434 | * - Initialize the adapter structure | |
435 | * - Initialize the private structure | |
436 | * - Add BSS priority tables to the adapter structure | |
437 | * - For each interface, send the init commands to firmware | |
438 | * - Send the first command in command pending queue, if available | |
439 | */ | |
440 | int mwifiex_init_fw(struct mwifiex_adapter *adapter) | |
441 | { | |
442 | int ret = 0; | |
443 | struct mwifiex_private *priv = NULL; | |
444 | u8 i = 0; | |
445 | u8 first_sta = true; | |
446 | int is_cmd_pend_q_empty; | |
447 | unsigned long flags; | |
448 | ||
449 | adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING; | |
450 | ||
451 | /* Allocate memory for member of adapter structure */ | |
452 | ret = mwifiex_allocate_adapter(adapter); | |
453 | if (ret) | |
454 | return -1; | |
455 | ||
456 | /* Initialize adapter structure */ | |
457 | mwifiex_init_adapter(adapter); | |
458 | ||
459 | for (i = 0; i < adapter->priv_num; i++) { | |
460 | if (adapter->priv[i]) { | |
461 | priv = adapter->priv[i]; | |
462 | ||
463 | /* Initialize private structure */ | |
464 | ret = mwifiex_init_priv(priv); | |
465 | if (ret) | |
466 | return -1; | |
467 | } | |
468 | } | |
469 | for (i = 0; i < adapter->priv_num; i++) { | |
470 | if (adapter->priv[i]) { | |
471 | ret = mwifiex_sta_init_cmd(adapter->priv[i], first_sta); | |
472 | if (ret == -1) | |
473 | return -1; | |
474 | ||
475 | first_sta = false; | |
476 | } | |
477 | } | |
478 | ||
479 | spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags); | |
480 | is_cmd_pend_q_empty = list_empty(&adapter->cmd_pending_q); | |
481 | spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, flags); | |
482 | if (!is_cmd_pend_q_empty) { | |
483 | /* Send the first command in queue and return */ | |
484 | if (mwifiex_main_process(adapter) != -1) | |
485 | ret = -EINPROGRESS; | |
486 | } else { | |
487 | adapter->hw_status = MWIFIEX_HW_STATUS_READY; | |
488 | } | |
489 | ||
490 | return ret; | |
491 | } | |
492 | ||
493 | /* | |
494 | * This function deletes the BSS priority tables. | |
495 | * | |
496 | * The function traverses through all the allocated BSS priority nodes | |
497 | * in every BSS priority table and frees them. | |
498 | */ | |
499 | static void mwifiex_delete_bss_prio_tbl(struct mwifiex_private *priv) | |
500 | { | |
501 | int i; | |
502 | struct mwifiex_adapter *adapter = priv->adapter; | |
503 | struct mwifiex_bss_prio_node *bssprio_node = NULL, *tmp_node = NULL, | |
504 | **cur = NULL; | |
505 | struct list_head *head; | |
506 | spinlock_t *lock; | |
507 | unsigned long flags; | |
508 | ||
509 | for (i = 0; i < adapter->priv_num; ++i) { | |
510 | head = &adapter->bss_prio_tbl[i].bss_prio_head; | |
511 | cur = &adapter->bss_prio_tbl[i].bss_prio_cur; | |
512 | lock = &adapter->bss_prio_tbl[i].bss_prio_lock; | |
513 | dev_dbg(adapter->dev, "info: delete BSS priority table," | |
514 | " index = %d, i = %d, head = %p, cur = %p\n", | |
515 | priv->bss_index, i, head, *cur); | |
516 | if (*cur) { | |
517 | spin_lock_irqsave(lock, flags); | |
518 | if (list_empty(head)) { | |
519 | spin_unlock_irqrestore(lock, flags); | |
520 | continue; | |
521 | } | |
522 | bssprio_node = list_first_entry(head, | |
523 | struct mwifiex_bss_prio_node, list); | |
524 | spin_unlock_irqrestore(lock, flags); | |
525 | ||
526 | list_for_each_entry_safe(bssprio_node, tmp_node, head, | |
527 | list) { | |
528 | if (bssprio_node->priv == priv) { | |
529 | dev_dbg(adapter->dev, "info: Delete " | |
530 | "node %p, next = %p\n", | |
531 | bssprio_node, tmp_node); | |
532 | spin_lock_irqsave(lock, flags); | |
533 | list_del(&bssprio_node->list); | |
534 | spin_unlock_irqrestore(lock, flags); | |
535 | kfree(bssprio_node); | |
536 | } | |
537 | } | |
538 | *cur = (struct mwifiex_bss_prio_node *)head; | |
539 | } | |
540 | } | |
541 | } | |
542 | ||
543 | /* | |
544 | * This function is used to shutdown the driver. | |
545 | * | |
546 | * The following operations are performed sequentially - | |
547 | * - Check if already shut down | |
548 | * - Make sure the main process has stopped | |
549 | * - Clean up the Tx and Rx queues | |
550 | * - Delete BSS priority tables | |
551 | * - Free the adapter | |
552 | * - Notify completion | |
553 | */ | |
554 | int | |
555 | mwifiex_shutdown_drv(struct mwifiex_adapter *adapter) | |
556 | { | |
557 | int ret = -EINPROGRESS; | |
558 | struct mwifiex_private *priv = NULL; | |
559 | s32 i = 0; | |
560 | unsigned long flags; | |
561 | ||
562 | /* mwifiex already shutdown */ | |
563 | if (adapter->hw_status == MWIFIEX_HW_STATUS_NOT_READY) | |
564 | return 0; | |
565 | ||
566 | adapter->hw_status = MWIFIEX_HW_STATUS_CLOSING; | |
567 | /* wait for mwifiex_process to complete */ | |
568 | if (adapter->mwifiex_processing) { | |
569 | dev_warn(adapter->dev, "main process is still running\n"); | |
570 | return ret; | |
571 | } | |
572 | ||
573 | /* shut down mwifiex */ | |
574 | dev_dbg(adapter->dev, "info: shutdown mwifiex...\n"); | |
575 | ||
576 | /* Clean up Tx/Rx queues and delete BSS priority table */ | |
577 | for (i = 0; i < adapter->priv_num; i++) { | |
578 | if (adapter->priv[i]) { | |
579 | priv = adapter->priv[i]; | |
580 | ||
581 | mwifiex_clean_txrx(priv); | |
582 | mwifiex_delete_bss_prio_tbl(priv); | |
583 | } | |
584 | } | |
585 | ||
586 | spin_lock_irqsave(&adapter->mwifiex_lock, flags); | |
587 | ||
588 | /* Free adapter structure */ | |
589 | mwifiex_free_adapter(adapter); | |
590 | ||
591 | spin_unlock_irqrestore(&adapter->mwifiex_lock, flags); | |
592 | ||
593 | /* Notify completion */ | |
594 | ret = mwifiex_shutdown_fw_complete(adapter); | |
595 | ||
596 | return ret; | |
597 | } | |
598 | ||
599 | /* | |
600 | * This function downloads the firmware to the card. | |
601 | * | |
602 | * The actual download is preceded by two sanity checks - | |
603 | * - Check if firmware is already running | |
604 | * - Check if the interface is the winner to download the firmware | |
605 | * | |
606 | * ...and followed by another - | |
607 | * - Check if the firmware is downloaded successfully | |
608 | * | |
609 | * After download is successfully completed, the host interrupts are enabled. | |
610 | */ | |
611 | int mwifiex_dnld_fw(struct mwifiex_adapter *adapter, | |
612 | struct mwifiex_fw_image *pmfw) | |
613 | { | |
614 | int ret = 0; | |
615 | u32 poll_num = 1; | |
616 | int winner; | |
617 | ||
618 | /* Check if firmware is already running */ | |
619 | ret = adapter->if_ops.check_fw_status(adapter, poll_num, &winner); | |
620 | if (!ret) { | |
621 | dev_notice(adapter->dev, | |
622 | "WLAN FW already running! Skip FW download\n"); | |
623 | goto done; | |
624 | } | |
625 | poll_num = MAX_FIRMWARE_POLL_TRIES; | |
626 | ||
627 | /* Check if we are the winner for downloading FW */ | |
628 | if (!winner) { | |
629 | dev_notice(adapter->dev, | |
630 | "Other interface already running!" | |
631 | " Skip FW download\n"); | |
632 | poll_num = MAX_MULTI_INTERFACE_POLL_TRIES; | |
633 | goto poll_fw; | |
634 | } | |
635 | if (pmfw) { | |
636 | /* Download firmware with helper */ | |
637 | ret = adapter->if_ops.prog_fw(adapter, pmfw); | |
638 | if (ret) { | |
639 | dev_err(adapter->dev, "prog_fw failed ret=%#x\n", ret); | |
640 | return ret; | |
641 | } | |
642 | } | |
643 | ||
644 | poll_fw: | |
645 | /* Check if the firmware is downloaded successfully or not */ | |
646 | ret = adapter->if_ops.check_fw_status(adapter, poll_num, NULL); | |
647 | if (ret) { | |
648 | dev_err(adapter->dev, "FW failed to be active in time\n"); | |
649 | return -1; | |
650 | } | |
651 | done: | |
652 | /* re-enable host interrupt for mwifiex after fw dnld is successful */ | |
653 | adapter->if_ops.enable_int(adapter); | |
654 | return ret; | |
655 | } |