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