]>
Commit | Line | Data |
---|---|---|
bb9f8692 ZY |
1 | /* |
2 | * Intel Wireless Multicomm 3200 WiFi driver | |
3 | * | |
4 | * Copyright (C) 2009 Intel Corporation. All rights reserved. | |
5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions | |
8 | * are met: | |
9 | * | |
10 | * * Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | |
12 | * * Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in | |
14 | * the documentation and/or other materials provided with the | |
15 | * distribution. | |
16 | * * Neither the name of Intel Corporation nor the names of its | |
17 | * contributors may be used to endorse or promote products derived | |
18 | * from this software without specific prior written permission. | |
19 | * | |
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
31 | * | |
32 | * | |
33 | * Intel Corporation <ilw@linux.intel.com> | |
34 | * Samuel Ortiz <samuel.ortiz@intel.com> | |
35 | * Zhu Yi <yi.zhu@intel.com> | |
36 | * | |
37 | */ | |
38 | ||
39 | #include <linux/kernel.h> | |
40 | #include <linux/netdevice.h> | |
41 | #include <linux/ieee80211.h> | |
42 | #include <linux/wireless.h> | |
43 | ||
44 | #include "iwm.h" | |
45 | #include "debug.h" | |
46 | #include "bus.h" | |
47 | #include "umac.h" | |
48 | #include "commands.h" | |
49 | #include "hal.h" | |
50 | #include "fw.h" | |
51 | #include "rx.h" | |
52 | ||
53 | static struct iwm_conf def_iwm_conf = { | |
54 | ||
55 | .sdio_ior_timeout = 5000, | |
d04bd628 SO |
56 | .calib_map = BIT(CALIB_CFG_DC_IDX) | |
57 | BIT(CALIB_CFG_LO_IDX) | | |
58 | BIT(CALIB_CFG_TX_IQ_IDX) | | |
59 | BIT(CALIB_CFG_RX_IQ_IDX) | | |
60 | BIT(SHILOH_PHY_CALIBRATE_BASE_BAND_CMD), | |
61 | .expected_calib_map = BIT(PHY_CALIBRATE_DC_CMD) | | |
bb9f8692 ZY |
62 | BIT(PHY_CALIBRATE_LO_CMD) | |
63 | BIT(PHY_CALIBRATE_TX_IQ_CMD) | | |
64 | BIT(PHY_CALIBRATE_RX_IQ_CMD) | | |
65 | BIT(SHILOH_PHY_CALIBRATE_BASE_BAND_CMD), | |
e85498b2 SO |
66 | .ct_kill_entry = 110, |
67 | .ct_kill_exit = 110, | |
bb9f8692 ZY |
68 | .reset_on_fatal_err = 1, |
69 | .auto_connect = 1, | |
70 | .wimax_not_present = 0, | |
71 | .enable_qos = 1, | |
72 | .mode = UMAC_MODE_BSS, | |
73 | ||
74 | /* UMAC configuration */ | |
75 | .power_index = 0, | |
76 | .frag_threshold = IEEE80211_MAX_FRAG_THRESHOLD, | |
77 | .rts_threshold = IEEE80211_MAX_RTS_THRESHOLD, | |
78 | .cts_to_self = 0, | |
79 | ||
80 | .assoc_timeout = 2, | |
81 | .roam_timeout = 10, | |
82 | .wireless_mode = WIRELESS_MODE_11A | WIRELESS_MODE_11G, | |
83 | .coexist_mode = COEX_MODE_CM, | |
84 | ||
85 | /* IBSS */ | |
86 | .ibss_band = UMAC_BAND_2GHZ, | |
87 | .ibss_channel = 1, | |
88 | ||
89 | .mac_addr = {0x00, 0x02, 0xb3, 0x01, 0x02, 0x03}, | |
90 | }; | |
91 | ||
92 | static int modparam_reset; | |
93 | module_param_named(reset, modparam_reset, bool, 0644); | |
94 | MODULE_PARM_DESC(reset, "reset on firmware errors (default 0 [not reset])"); | |
95 | ||
96 | int iwm_mode_to_nl80211_iftype(int mode) | |
97 | { | |
98 | switch (mode) { | |
99 | case UMAC_MODE_BSS: | |
100 | return NL80211_IFTYPE_STATION; | |
101 | case UMAC_MODE_IBSS: | |
102 | return NL80211_IFTYPE_ADHOC; | |
103 | default: | |
104 | return NL80211_IFTYPE_UNSPECIFIED; | |
105 | } | |
106 | ||
107 | return 0; | |
108 | } | |
109 | ||
110 | static void iwm_statistics_request(struct work_struct *work) | |
111 | { | |
112 | struct iwm_priv *iwm = | |
113 | container_of(work, struct iwm_priv, stats_request.work); | |
114 | ||
115 | iwm_send_umac_stats_req(iwm, 0); | |
116 | } | |
117 | ||
c7436273 ZY |
118 | static void iwm_disconnect_work(struct work_struct *work) |
119 | { | |
120 | struct iwm_priv *iwm = | |
121 | container_of(work, struct iwm_priv, disconnect.work); | |
122 | ||
123 | if (iwm->umac_profile_active) | |
124 | iwm_invalidate_mlme_profile(iwm); | |
125 | ||
126 | clear_bit(IWM_STATUS_ASSOCIATED, &iwm->status); | |
127 | iwm->umac_profile_active = 0; | |
128 | memset(iwm->bssid, 0, ETH_ALEN); | |
129 | iwm->channel = 0; | |
130 | ||
131 | iwm_link_off(iwm); | |
132 | ||
133 | wake_up_interruptible(&iwm->mlme_queue); | |
134 | ||
135 | cfg80211_disconnected(iwm_to_ndev(iwm), 0, NULL, 0, GFP_KERNEL); | |
136 | } | |
137 | ||
e85498b2 SO |
138 | static void iwm_ct_kill_work(struct work_struct *work) |
139 | { | |
140 | struct iwm_priv *iwm = | |
141 | container_of(work, struct iwm_priv, ct_kill_delay.work); | |
142 | struct wiphy *wiphy = iwm_to_wiphy(iwm); | |
143 | ||
144 | IWM_INFO(iwm, "CT kill delay timeout\n"); | |
145 | ||
146 | wiphy_rfkill_set_hw_state(wiphy, false); | |
147 | } | |
148 | ||
31452420 ZY |
149 | static int __iwm_up(struct iwm_priv *iwm); |
150 | static int __iwm_down(struct iwm_priv *iwm); | |
68810c5d | 151 | |
bb9f8692 ZY |
152 | static void iwm_reset_worker(struct work_struct *work) |
153 | { | |
154 | struct iwm_priv *iwm; | |
155 | struct iwm_umac_profile *profile = NULL; | |
156 | int uninitialized_var(ret), retry = 0; | |
157 | ||
158 | iwm = container_of(work, struct iwm_priv, reset_worker); | |
159 | ||
68810c5d ZY |
160 | /* |
161 | * XXX: The iwm->mutex is introduced purely for this reset work, | |
162 | * because the other users for iwm_up and iwm_down are only netdev | |
163 | * ndo_open and ndo_stop which are already protected by rtnl. | |
164 | * Please remove iwm->mutex together if iwm_reset_worker() is not | |
165 | * required in the future. | |
166 | */ | |
167 | if (!mutex_trylock(&iwm->mutex)) { | |
168 | IWM_WARN(iwm, "We are in the middle of interface bringing " | |
169 | "UP/DOWN. Skip driver resetting.\n"); | |
170 | return; | |
171 | } | |
172 | ||
bb9f8692 ZY |
173 | if (iwm->umac_profile_active) { |
174 | profile = kmalloc(sizeof(struct iwm_umac_profile), GFP_KERNEL); | |
175 | if (profile) | |
176 | memcpy(profile, iwm->umac_profile, sizeof(*profile)); | |
177 | else | |
178 | IWM_ERR(iwm, "Couldn't alloc memory for profile\n"); | |
179 | } | |
180 | ||
68810c5d | 181 | __iwm_down(iwm); |
bb9f8692 ZY |
182 | |
183 | while (retry++ < 3) { | |
68810c5d | 184 | ret = __iwm_up(iwm); |
bb9f8692 ZY |
185 | if (!ret) |
186 | break; | |
187 | ||
188 | schedule_timeout_uninterruptible(10 * HZ); | |
189 | } | |
190 | ||
191 | if (ret) { | |
192 | IWM_WARN(iwm, "iwm_up() failed: %d\n", ret); | |
193 | ||
194 | kfree(profile); | |
68810c5d | 195 | goto out; |
bb9f8692 ZY |
196 | } |
197 | ||
198 | if (profile) { | |
199 | IWM_DBG_MLME(iwm, DBG, "Resend UMAC profile\n"); | |
200 | memcpy(iwm->umac_profile, profile, sizeof(*profile)); | |
201 | iwm_send_mlme_profile(iwm); | |
202 | kfree(profile); | |
d210176e SO |
203 | } else |
204 | clear_bit(IWM_STATUS_RESETTING, &iwm->status); | |
68810c5d ZY |
205 | |
206 | out: | |
207 | mutex_unlock(&iwm->mutex); | |
bb9f8692 ZY |
208 | } |
209 | ||
9829e1b5 SO |
210 | static void iwm_auth_retry_worker(struct work_struct *work) |
211 | { | |
212 | struct iwm_priv *iwm; | |
213 | int i, ret; | |
214 | ||
215 | iwm = container_of(work, struct iwm_priv, auth_retry_worker); | |
216 | if (iwm->umac_profile_active) { | |
217 | ret = iwm_invalidate_mlme_profile(iwm); | |
218 | if (ret < 0) | |
219 | return; | |
220 | } | |
221 | ||
222 | iwm->umac_profile->sec.auth_type = UMAC_AUTH_TYPE_LEGACY_PSK; | |
223 | ||
224 | ret = iwm_send_mlme_profile(iwm); | |
225 | if (ret < 0) | |
226 | return; | |
227 | ||
228 | for (i = 0; i < IWM_NUM_KEYS; i++) | |
229 | if (iwm->keys[i].key_len) | |
230 | iwm_set_key(iwm, 0, &iwm->keys[i]); | |
231 | ||
232 | iwm_set_tx_key(iwm, iwm->default_key); | |
233 | } | |
234 | ||
235 | ||
236 | ||
bb9f8692 ZY |
237 | static void iwm_watchdog(unsigned long data) |
238 | { | |
239 | struct iwm_priv *iwm = (struct iwm_priv *)data; | |
240 | ||
241 | IWM_WARN(iwm, "Watchdog expired: UMAC stalls!\n"); | |
242 | ||
243 | if (modparam_reset) | |
d210176e | 244 | iwm_resetting(iwm); |
bb9f8692 ZY |
245 | } |
246 | ||
247 | int iwm_priv_init(struct iwm_priv *iwm) | |
248 | { | |
249 | int i; | |
250 | char name[32]; | |
251 | ||
252 | iwm->status = 0; | |
253 | INIT_LIST_HEAD(&iwm->pending_notif); | |
254 | init_waitqueue_head(&iwm->notif_queue); | |
255 | init_waitqueue_head(&iwm->nonwifi_queue); | |
a70742f1 | 256 | init_waitqueue_head(&iwm->wifi_ntfy_queue); |
bb9f8692 ZY |
257 | init_waitqueue_head(&iwm->mlme_queue); |
258 | memcpy(&iwm->conf, &def_iwm_conf, sizeof(struct iwm_conf)); | |
259 | spin_lock_init(&iwm->tx_credit.lock); | |
260 | INIT_LIST_HEAD(&iwm->wifi_pending_cmd); | |
261 | INIT_LIST_HEAD(&iwm->nonwifi_pending_cmd); | |
262 | iwm->wifi_seq_num = UMAC_WIFI_SEQ_NUM_BASE; | |
263 | iwm->nonwifi_seq_num = UMAC_NONWIFI_SEQ_NUM_BASE; | |
264 | spin_lock_init(&iwm->cmd_lock); | |
265 | iwm->scan_id = 1; | |
266 | INIT_DELAYED_WORK(&iwm->stats_request, iwm_statistics_request); | |
c7436273 | 267 | INIT_DELAYED_WORK(&iwm->disconnect, iwm_disconnect_work); |
e85498b2 | 268 | INIT_DELAYED_WORK(&iwm->ct_kill_delay, iwm_ct_kill_work); |
bb9f8692 | 269 | INIT_WORK(&iwm->reset_worker, iwm_reset_worker); |
9829e1b5 | 270 | INIT_WORK(&iwm->auth_retry_worker, iwm_auth_retry_worker); |
bb9f8692 ZY |
271 | INIT_LIST_HEAD(&iwm->bss_list); |
272 | ||
273 | skb_queue_head_init(&iwm->rx_list); | |
274 | INIT_LIST_HEAD(&iwm->rx_tickets); | |
275 | for (i = 0; i < IWM_RX_ID_HASH; i++) | |
276 | INIT_LIST_HEAD(&iwm->rx_packets[i]); | |
277 | ||
278 | INIT_WORK(&iwm->rx_worker, iwm_rx_worker); | |
279 | ||
280 | iwm->rx_wq = create_singlethread_workqueue(KBUILD_MODNAME "_rx"); | |
281 | if (!iwm->rx_wq) | |
282 | return -EAGAIN; | |
283 | ||
284 | for (i = 0; i < IWM_TX_QUEUES; i++) { | |
285 | INIT_WORK(&iwm->txq[i].worker, iwm_tx_worker); | |
286 | snprintf(name, 32, KBUILD_MODNAME "_tx_%d", i); | |
287 | iwm->txq[i].id = i; | |
288 | iwm->txq[i].wq = create_singlethread_workqueue(name); | |
289 | if (!iwm->txq[i].wq) | |
290 | return -EAGAIN; | |
291 | ||
292 | skb_queue_head_init(&iwm->txq[i].queue); | |
293 | } | |
294 | ||
295 | for (i = 0; i < IWM_NUM_KEYS; i++) | |
296 | memset(&iwm->keys[i], 0, sizeof(struct iwm_key)); | |
297 | ||
13e0fe70 | 298 | iwm->default_key = -1; |
bb9f8692 ZY |
299 | |
300 | init_timer(&iwm->watchdog); | |
301 | iwm->watchdog.function = iwm_watchdog; | |
302 | iwm->watchdog.data = (unsigned long)iwm; | |
68810c5d | 303 | mutex_init(&iwm->mutex); |
bb9f8692 | 304 | |
04e715cd SO |
305 | iwm->last_fw_err = kzalloc(sizeof(struct iwm_fw_error_hdr), |
306 | GFP_KERNEL); | |
307 | if (iwm->last_fw_err == NULL) | |
308 | return -ENOMEM; | |
309 | ||
bb9f8692 ZY |
310 | return 0; |
311 | } | |
312 | ||
8d96e796 ZY |
313 | void iwm_priv_deinit(struct iwm_priv *iwm) |
314 | { | |
315 | int i; | |
316 | ||
317 | for (i = 0; i < IWM_TX_QUEUES; i++) | |
318 | destroy_workqueue(iwm->txq[i].wq); | |
319 | ||
320 | destroy_workqueue(iwm->rx_wq); | |
04e715cd | 321 | kfree(iwm->last_fw_err); |
8d96e796 ZY |
322 | } |
323 | ||
bb9f8692 ZY |
324 | /* |
325 | * We reset all the structures, and we reset the UMAC. | |
326 | * After calling this routine, you're expected to reload | |
327 | * the firmware. | |
328 | */ | |
329 | void iwm_reset(struct iwm_priv *iwm) | |
330 | { | |
331 | struct iwm_notif *notif, *next; | |
332 | ||
333 | if (test_bit(IWM_STATUS_READY, &iwm->status)) | |
334 | iwm_target_reset(iwm); | |
335 | ||
d210176e SO |
336 | if (test_bit(IWM_STATUS_RESETTING, &iwm->status)) { |
337 | iwm->status = 0; | |
338 | set_bit(IWM_STATUS_RESETTING, &iwm->status); | |
339 | } else | |
340 | iwm->status = 0; | |
bb9f8692 ZY |
341 | iwm->scan_id = 1; |
342 | ||
343 | list_for_each_entry_safe(notif, next, &iwm->pending_notif, pending) { | |
344 | list_del(¬if->pending); | |
345 | kfree(notif->buf); | |
346 | kfree(notif); | |
347 | } | |
348 | ||
349 | iwm_cmd_flush(iwm); | |
350 | ||
351 | flush_workqueue(iwm->rx_wq); | |
352 | ||
353 | iwm_link_off(iwm); | |
354 | } | |
355 | ||
d210176e SO |
356 | void iwm_resetting(struct iwm_priv *iwm) |
357 | { | |
358 | set_bit(IWM_STATUS_RESETTING, &iwm->status); | |
359 | ||
360 | schedule_work(&iwm->reset_worker); | |
361 | } | |
362 | ||
bb9f8692 ZY |
363 | /* |
364 | * Notification code: | |
365 | * | |
366 | * We're faced with the following issue: Any host command can | |
367 | * have an answer or not, and if there's an answer to expect, | |
368 | * it can be treated synchronously or asynchronously. | |
369 | * To work around the synchronous answer case, we implemented | |
370 | * our notification mechanism. | |
371 | * When a code path needs to wait for a command response | |
372 | * synchronously, it calls notif_handle(), which waits for the | |
373 | * right notification to show up, and then process it. Before | |
374 | * starting to wait, it registered as a waiter for this specific | |
375 | * answer (by toggling a bit in on of the handler_map), so that | |
376 | * the rx code knows that it needs to send a notification to the | |
377 | * waiting processes. It does so by calling iwm_notif_send(), | |
378 | * which adds the notification to the pending notifications list, | |
379 | * and then wakes the waiting processes up. | |
380 | */ | |
381 | int iwm_notif_send(struct iwm_priv *iwm, struct iwm_wifi_cmd *cmd, | |
382 | u8 cmd_id, u8 source, u8 *buf, unsigned long buf_size) | |
383 | { | |
384 | struct iwm_notif *notif; | |
385 | ||
386 | notif = kzalloc(sizeof(struct iwm_notif), GFP_KERNEL); | |
387 | if (!notif) { | |
388 | IWM_ERR(iwm, "Couldn't alloc memory for notification\n"); | |
389 | return -ENOMEM; | |
390 | } | |
391 | ||
392 | INIT_LIST_HEAD(¬if->pending); | |
393 | notif->cmd = cmd; | |
394 | notif->cmd_id = cmd_id; | |
395 | notif->src = source; | |
396 | notif->buf = kzalloc(buf_size, GFP_KERNEL); | |
397 | if (!notif->buf) { | |
398 | IWM_ERR(iwm, "Couldn't alloc notification buffer\n"); | |
399 | kfree(notif); | |
400 | return -ENOMEM; | |
401 | } | |
402 | notif->buf_size = buf_size; | |
403 | memcpy(notif->buf, buf, buf_size); | |
404 | list_add_tail(¬if->pending, &iwm->pending_notif); | |
405 | ||
406 | wake_up_interruptible(&iwm->notif_queue); | |
407 | ||
408 | return 0; | |
409 | } | |
410 | ||
411 | static struct iwm_notif *iwm_notif_find(struct iwm_priv *iwm, u32 cmd, | |
412 | u8 source) | |
413 | { | |
414 | struct iwm_notif *notif, *next; | |
415 | ||
416 | list_for_each_entry_safe(notif, next, &iwm->pending_notif, pending) { | |
417 | if ((notif->cmd_id == cmd) && (notif->src == source)) { | |
418 | list_del(¬if->pending); | |
419 | return notif; | |
420 | } | |
421 | } | |
422 | ||
423 | return NULL; | |
424 | } | |
425 | ||
426 | static struct iwm_notif *iwm_notif_wait(struct iwm_priv *iwm, u32 cmd, | |
427 | u8 source, long timeout) | |
428 | { | |
429 | int ret; | |
430 | struct iwm_notif *notif; | |
431 | unsigned long *map = NULL; | |
432 | ||
433 | switch (source) { | |
434 | case IWM_SRC_LMAC: | |
435 | map = &iwm->lmac_handler_map[0]; | |
436 | break; | |
437 | case IWM_SRC_UMAC: | |
438 | map = &iwm->umac_handler_map[0]; | |
439 | break; | |
440 | case IWM_SRC_UDMA: | |
441 | map = &iwm->udma_handler_map[0]; | |
442 | break; | |
443 | } | |
444 | ||
445 | set_bit(cmd, map); | |
446 | ||
447 | ret = wait_event_interruptible_timeout(iwm->notif_queue, | |
448 | ((notif = iwm_notif_find(iwm, cmd, source)) != NULL), | |
449 | timeout); | |
450 | clear_bit(cmd, map); | |
451 | ||
452 | if (!ret) | |
453 | return NULL; | |
454 | ||
455 | return notif; | |
456 | } | |
457 | ||
458 | int iwm_notif_handle(struct iwm_priv *iwm, u32 cmd, u8 source, long timeout) | |
459 | { | |
460 | int ret; | |
461 | struct iwm_notif *notif; | |
462 | ||
463 | notif = iwm_notif_wait(iwm, cmd, source, timeout); | |
464 | if (!notif) | |
465 | return -ETIME; | |
466 | ||
467 | ret = iwm_rx_handle_resp(iwm, notif->buf, notif->buf_size, notif->cmd); | |
468 | kfree(notif->buf); | |
469 | kfree(notif); | |
470 | ||
471 | return ret; | |
472 | } | |
473 | ||
474 | static int iwm_config_boot_params(struct iwm_priv *iwm) | |
475 | { | |
476 | struct iwm_udma_nonwifi_cmd target_cmd; | |
477 | int ret; | |
478 | ||
479 | /* check Wimax is off and config debug monitor */ | |
480 | if (iwm->conf.wimax_not_present) { | |
481 | u32 data1 = 0x1f; | |
482 | u32 addr1 = 0x606BE258; | |
483 | ||
484 | u32 data2_set = 0x0; | |
485 | u32 data2_clr = 0x1; | |
486 | u32 addr2 = 0x606BE100; | |
487 | ||
488 | u32 data3 = 0x1; | |
489 | u32 addr3 = 0x606BEC00; | |
490 | ||
491 | target_cmd.resp = 0; | |
492 | target_cmd.handle_by_hw = 0; | |
493 | target_cmd.eop = 1; | |
494 | ||
495 | target_cmd.opcode = UMAC_HDI_OUT_OPCODE_WRITE; | |
496 | target_cmd.addr = cpu_to_le32(addr1); | |
497 | target_cmd.op1_sz = cpu_to_le32(sizeof(u32)); | |
498 | target_cmd.op2 = 0; | |
499 | ||
500 | ret = iwm_hal_send_target_cmd(iwm, &target_cmd, &data1); | |
501 | if (ret < 0) { | |
502 | IWM_ERR(iwm, "iwm_hal_send_target_cmd failed\n"); | |
503 | return ret; | |
504 | } | |
505 | ||
506 | target_cmd.opcode = UMAC_HDI_OUT_OPCODE_READ_MODIFY_WRITE; | |
507 | target_cmd.addr = cpu_to_le32(addr2); | |
508 | target_cmd.op1_sz = cpu_to_le32(data2_set); | |
509 | target_cmd.op2 = cpu_to_le32(data2_clr); | |
510 | ||
511 | ret = iwm_hal_send_target_cmd(iwm, &target_cmd, &data1); | |
512 | if (ret < 0) { | |
513 | IWM_ERR(iwm, "iwm_hal_send_target_cmd failed\n"); | |
514 | return ret; | |
515 | } | |
516 | ||
517 | target_cmd.opcode = UMAC_HDI_OUT_OPCODE_WRITE; | |
518 | target_cmd.addr = cpu_to_le32(addr3); | |
519 | target_cmd.op1_sz = cpu_to_le32(sizeof(u32)); | |
520 | target_cmd.op2 = 0; | |
521 | ||
522 | ret = iwm_hal_send_target_cmd(iwm, &target_cmd, &data3); | |
523 | if (ret < 0) { | |
524 | IWM_ERR(iwm, "iwm_hal_send_target_cmd failed\n"); | |
525 | return ret; | |
526 | } | |
527 | } | |
528 | ||
529 | return 0; | |
530 | } | |
531 | ||
532 | void iwm_init_default_profile(struct iwm_priv *iwm, | |
533 | struct iwm_umac_profile *profile) | |
534 | { | |
535 | memset(profile, 0, sizeof(struct iwm_umac_profile)); | |
536 | ||
537 | profile->sec.auth_type = UMAC_AUTH_TYPE_OPEN; | |
538 | profile->sec.flags = UMAC_SEC_FLG_LEGACY_PROFILE; | |
539 | profile->sec.ucast_cipher = UMAC_CIPHER_TYPE_NONE; | |
540 | profile->sec.mcast_cipher = UMAC_CIPHER_TYPE_NONE; | |
541 | ||
542 | if (iwm->conf.enable_qos) | |
543 | profile->flags |= cpu_to_le16(UMAC_PROFILE_QOS_ALLOWED); | |
544 | ||
545 | profile->wireless_mode = iwm->conf.wireless_mode; | |
546 | profile->mode = cpu_to_le32(iwm->conf.mode); | |
547 | ||
548 | profile->ibss.atim = 0; | |
549 | profile->ibss.beacon_interval = 100; | |
550 | profile->ibss.join_only = 0; | |
551 | profile->ibss.band = iwm->conf.ibss_band; | |
552 | profile->ibss.channel = iwm->conf.ibss_channel; | |
553 | } | |
554 | ||
555 | void iwm_link_on(struct iwm_priv *iwm) | |
556 | { | |
557 | netif_carrier_on(iwm_to_ndev(iwm)); | |
558 | netif_tx_wake_all_queues(iwm_to_ndev(iwm)); | |
559 | ||
560 | iwm_send_umac_stats_req(iwm, 0); | |
561 | } | |
562 | ||
563 | void iwm_link_off(struct iwm_priv *iwm) | |
564 | { | |
565 | struct iw_statistics *wstats = &iwm->wstats; | |
566 | int i; | |
567 | ||
568 | netif_tx_stop_all_queues(iwm_to_ndev(iwm)); | |
569 | netif_carrier_off(iwm_to_ndev(iwm)); | |
570 | ||
571 | for (i = 0; i < IWM_TX_QUEUES; i++) { | |
572 | skb_queue_purge(&iwm->txq[i].queue); | |
573 | ||
574 | iwm->txq[i].concat_count = 0; | |
575 | iwm->txq[i].concat_ptr = iwm->txq[i].concat_buf; | |
576 | ||
577 | flush_workqueue(iwm->txq[i].wq); | |
578 | } | |
579 | ||
580 | iwm_rx_free(iwm); | |
581 | ||
68810c5d | 582 | cancel_delayed_work_sync(&iwm->stats_request); |
bb9f8692 ZY |
583 | memset(wstats, 0, sizeof(struct iw_statistics)); |
584 | wstats->qual.updated = IW_QUAL_ALL_INVALID; | |
585 | ||
b68518fc ZY |
586 | kfree(iwm->req_ie); |
587 | iwm->req_ie = NULL; | |
588 | iwm->req_ie_len = 0; | |
589 | kfree(iwm->resp_ie); | |
590 | iwm->resp_ie = NULL; | |
591 | iwm->resp_ie_len = 0; | |
592 | ||
bb9f8692 ZY |
593 | del_timer_sync(&iwm->watchdog); |
594 | } | |
595 | ||
596 | static void iwm_bss_list_clean(struct iwm_priv *iwm) | |
597 | { | |
598 | struct iwm_bss_info *bss, *next; | |
599 | ||
600 | list_for_each_entry_safe(bss, next, &iwm->bss_list, node) { | |
601 | list_del(&bss->node); | |
602 | kfree(bss->bss); | |
603 | kfree(bss); | |
604 | } | |
605 | } | |
606 | ||
607 | static int iwm_channels_init(struct iwm_priv *iwm) | |
608 | { | |
609 | int ret; | |
610 | ||
bb9f8692 ZY |
611 | ret = iwm_send_umac_channel_list(iwm); |
612 | if (ret) { | |
613 | IWM_ERR(iwm, "Send channel list failed\n"); | |
614 | return ret; | |
615 | } | |
616 | ||
617 | ret = iwm_notif_handle(iwm, UMAC_CMD_OPCODE_GET_CHAN_INFO_LIST, | |
618 | IWM_SRC_UMAC, WAIT_NOTIF_TIMEOUT); | |
619 | if (ret) { | |
620 | IWM_ERR(iwm, "Didn't get a channel list notification\n"); | |
621 | return ret; | |
622 | } | |
623 | ||
624 | return 0; | |
625 | } | |
626 | ||
31452420 | 627 | static int __iwm_up(struct iwm_priv *iwm) |
bb9f8692 ZY |
628 | { |
629 | int ret; | |
630 | struct iwm_notif *notif_reboot, *notif_ack = NULL; | |
5dc53163 | 631 | struct wiphy *wiphy = iwm_to_wiphy(iwm); |
bb9f8692 ZY |
632 | |
633 | ret = iwm_bus_enable(iwm); | |
634 | if (ret) { | |
635 | IWM_ERR(iwm, "Couldn't enable function\n"); | |
636 | return ret; | |
637 | } | |
638 | ||
639 | iwm_rx_setup_handlers(iwm); | |
640 | ||
641 | /* Wait for initial BARKER_REBOOT from hardware */ | |
642 | notif_reboot = iwm_notif_wait(iwm, IWM_BARKER_REBOOT_NOTIFICATION, | |
643 | IWM_SRC_UDMA, 2 * HZ); | |
644 | if (!notif_reboot) { | |
645 | IWM_ERR(iwm, "Wait for REBOOT_BARKER timeout\n"); | |
646 | goto err_disable; | |
647 | } | |
648 | ||
649 | /* We send the barker back */ | |
650 | ret = iwm_bus_send_chunk(iwm, notif_reboot->buf, 16); | |
651 | if (ret) { | |
652 | IWM_ERR(iwm, "REBOOT barker response failed\n"); | |
653 | kfree(notif_reboot); | |
654 | goto err_disable; | |
655 | } | |
656 | ||
657 | kfree(notif_reboot->buf); | |
658 | kfree(notif_reboot); | |
659 | ||
660 | /* Wait for ACK_BARKER from hardware */ | |
661 | notif_ack = iwm_notif_wait(iwm, IWM_ACK_BARKER_NOTIFICATION, | |
662 | IWM_SRC_UDMA, 2 * HZ); | |
663 | if (!notif_ack) { | |
664 | IWM_ERR(iwm, "Wait for ACK_BARKER timeout\n"); | |
665 | goto err_disable; | |
666 | } | |
667 | ||
668 | kfree(notif_ack->buf); | |
669 | kfree(notif_ack); | |
670 | ||
671 | /* We start to config static boot parameters */ | |
672 | ret = iwm_config_boot_params(iwm); | |
673 | if (ret) { | |
674 | IWM_ERR(iwm, "Config boot parameters failed\n"); | |
675 | goto err_disable; | |
676 | } | |
677 | ||
678 | ret = iwm_read_mac(iwm, iwm_to_ndev(iwm)->dev_addr); | |
679 | if (ret) { | |
680 | IWM_ERR(iwm, "MAC reading failed\n"); | |
681 | goto err_disable; | |
682 | } | |
5b367378 JL |
683 | memcpy(iwm_to_ndev(iwm)->perm_addr, iwm_to_ndev(iwm)->dev_addr, |
684 | ETH_ALEN); | |
bb9f8692 ZY |
685 | |
686 | /* We can load the FWs */ | |
687 | ret = iwm_load_fw(iwm); | |
688 | if (ret) { | |
689 | IWM_ERR(iwm, "FW loading failed\n"); | |
690 | goto err_disable; | |
691 | } | |
692 | ||
5dc53163 SO |
693 | snprintf(wiphy->fw_version, sizeof(wiphy->fw_version), "L%s_U%s", |
694 | iwm->lmac_version, iwm->umac_version); | |
695 | ||
bb9f8692 ZY |
696 | /* We configure the UMAC and enable the wifi module */ |
697 | ret = iwm_send_umac_config(iwm, | |
698 | cpu_to_le32(UMAC_RST_CTRL_FLG_WIFI_CORE_EN) | | |
699 | cpu_to_le32(UMAC_RST_CTRL_FLG_WIFI_LINK_EN) | | |
700 | cpu_to_le32(UMAC_RST_CTRL_FLG_WIFI_MLME_EN)); | |
701 | if (ret) { | |
702 | IWM_ERR(iwm, "UMAC config failed\n"); | |
703 | goto err_fw; | |
704 | } | |
705 | ||
706 | ret = iwm_notif_handle(iwm, UMAC_NOTIFY_OPCODE_WIFI_CORE_STATUS, | |
707 | IWM_SRC_UMAC, WAIT_NOTIF_TIMEOUT); | |
708 | if (ret) { | |
709 | IWM_ERR(iwm, "Didn't get a wifi core status notification\n"); | |
710 | goto err_fw; | |
711 | } | |
712 | ||
713 | if (iwm->core_enabled != (UMAC_NTFY_WIFI_CORE_STATUS_LINK_EN | | |
714 | UMAC_NTFY_WIFI_CORE_STATUS_MLME_EN)) { | |
715 | IWM_DBG_BOOT(iwm, DBG, "Not all cores enabled:0x%x\n", | |
716 | iwm->core_enabled); | |
717 | ret = iwm_notif_handle(iwm, UMAC_NOTIFY_OPCODE_WIFI_CORE_STATUS, | |
718 | IWM_SRC_UMAC, WAIT_NOTIF_TIMEOUT); | |
719 | if (ret) { | |
720 | IWM_ERR(iwm, "Didn't get a core status notification\n"); | |
721 | goto err_fw; | |
722 | } | |
723 | ||
724 | if (iwm->core_enabled != (UMAC_NTFY_WIFI_CORE_STATUS_LINK_EN | | |
725 | UMAC_NTFY_WIFI_CORE_STATUS_MLME_EN)) { | |
726 | IWM_ERR(iwm, "Not all cores enabled: 0x%x\n", | |
727 | iwm->core_enabled); | |
728 | goto err_fw; | |
729 | } else { | |
730 | IWM_INFO(iwm, "All cores enabled\n"); | |
731 | } | |
732 | } | |
733 | ||
bb9f8692 ZY |
734 | ret = iwm_channels_init(iwm); |
735 | if (ret < 0) { | |
736 | IWM_ERR(iwm, "Couldn't init channels\n"); | |
35497164 | 737 | goto err_fw; |
bb9f8692 ZY |
738 | } |
739 | ||
740 | /* Set the READY bit to indicate interface is brought up successfully */ | |
741 | set_bit(IWM_STATUS_READY, &iwm->status); | |
742 | ||
743 | return 0; | |
744 | ||
bb9f8692 ZY |
745 | err_fw: |
746 | iwm_eeprom_exit(iwm); | |
747 | ||
748 | err_disable: | |
749 | ret = iwm_bus_disable(iwm); | |
750 | if (ret < 0) | |
751 | IWM_ERR(iwm, "Couldn't disable function\n"); | |
752 | ||
753 | return -EIO; | |
754 | } | |
755 | ||
68810c5d ZY |
756 | int iwm_up(struct iwm_priv *iwm) |
757 | { | |
758 | int ret; | |
759 | ||
760 | mutex_lock(&iwm->mutex); | |
761 | ret = __iwm_up(iwm); | |
762 | mutex_unlock(&iwm->mutex); | |
763 | ||
764 | return ret; | |
765 | } | |
766 | ||
31452420 | 767 | static int __iwm_down(struct iwm_priv *iwm) |
bb9f8692 ZY |
768 | { |
769 | int ret; | |
770 | ||
771 | /* The interface is already down */ | |
772 | if (!test_bit(IWM_STATUS_READY, &iwm->status)) | |
773 | return 0; | |
774 | ||
775 | if (iwm->scan_request) { | |
776 | cfg80211_scan_done(iwm->scan_request, true); | |
777 | iwm->scan_request = NULL; | |
778 | } | |
779 | ||
780 | clear_bit(IWM_STATUS_READY, &iwm->status); | |
781 | ||
782 | iwm_eeprom_exit(iwm); | |
bb9f8692 | 783 | iwm_bss_list_clean(iwm); |
35497164 SO |
784 | iwm_init_default_profile(iwm, iwm->umac_profile); |
785 | iwm->umac_profile_active = false; | |
13e0fe70 | 786 | iwm->default_key = -1; |
bb9f8692 ZY |
787 | iwm->core_enabled = 0; |
788 | ||
789 | ret = iwm_bus_disable(iwm); | |
790 | if (ret < 0) { | |
791 | IWM_ERR(iwm, "Couldn't disable function\n"); | |
792 | return ret; | |
793 | } | |
794 | ||
795 | return 0; | |
796 | } | |
68810c5d ZY |
797 | |
798 | int iwm_down(struct iwm_priv *iwm) | |
799 | { | |
800 | int ret; | |
801 | ||
802 | mutex_lock(&iwm->mutex); | |
803 | ret = __iwm_down(iwm); | |
804 | mutex_unlock(&iwm->mutex); | |
805 | ||
806 | return ret; | |
807 | } |