]>
Commit | Line | Data |
---|---|---|
d5c65159 KV |
1 | // SPDX-License-Identifier: BSD-3-Clause-Clear |
2 | /* | |
3 | * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. | |
4 | */ | |
5 | ||
6 | #include <linux/module.h> | |
7 | #include <linux/slab.h> | |
8 | #include <linux/remoteproc.h> | |
9 | #include <linux/firmware.h> | |
10 | #include "ahb.h" | |
11 | #include "core.h" | |
12 | #include "dp_tx.h" | |
9c57d7e3 | 13 | #include "dp_rx.h" |
d5c65159 KV |
14 | #include "debug.h" |
15 | ||
16 | unsigned int ath11k_debug_mask; | |
17 | module_param_named(debug_mask, ath11k_debug_mask, uint, 0644); | |
18 | MODULE_PARM_DESC(debug_mask, "Debugging mask"); | |
19 | ||
20 | static const struct ath11k_hw_params ath11k_hw_params = { | |
21 | .name = "ipq8074", | |
22 | .fw = { | |
23 | .dir = IPQ8074_FW_DIR, | |
24 | .board_size = IPQ8074_MAX_BOARD_DATA_SZ, | |
25 | .cal_size = IPQ8074_MAX_CAL_DATA_SZ, | |
26 | }, | |
27 | }; | |
28 | ||
29 | /* Map from pdev index to hw mac index */ | |
30 | u8 ath11k_core_get_hw_mac_id(struct ath11k_base *ab, int pdev_idx) | |
31 | { | |
32 | switch (pdev_idx) { | |
33 | case 0: | |
34 | return 0; | |
35 | case 1: | |
36 | return 2; | |
37 | case 2: | |
38 | return 1; | |
39 | default: | |
40 | ath11k_warn(ab, "Invalid pdev idx %d\n", pdev_idx); | |
41 | return ATH11K_INVALID_HW_MAC_ID; | |
42 | } | |
43 | } | |
44 | ||
45 | static int ath11k_core_create_board_name(struct ath11k_base *ab, char *name, | |
46 | size_t name_len) | |
47 | { | |
48 | /* Note: bus is fixed to ahb. When other bus type supported, | |
49 | * make it to dynamic. | |
50 | */ | |
51 | scnprintf(name, name_len, | |
52 | "bus=ahb,qmi-chip-id=%d,qmi-board-id=%d", | |
53 | ab->qmi.target.chip_id, | |
54 | ab->qmi.target.board_id); | |
55 | ||
56 | ath11k_dbg(ab, ATH11K_DBG_BOOT, "boot using board name '%s'\n", name); | |
57 | ||
58 | return 0; | |
59 | } | |
60 | ||
61 | static const struct firmware *ath11k_fetch_fw_file(struct ath11k_base *ab, | |
62 | const char *dir, | |
63 | const char *file) | |
64 | { | |
65 | char filename[100]; | |
66 | const struct firmware *fw; | |
67 | int ret; | |
68 | ||
69 | if (file == NULL) | |
70 | return ERR_PTR(-ENOENT); | |
71 | ||
72 | if (dir == NULL) | |
73 | dir = "."; | |
74 | ||
75 | snprintf(filename, sizeof(filename), "%s/%s", dir, file); | |
76 | ret = firmware_request_nowarn(&fw, filename, ab->dev); | |
77 | ath11k_dbg(ab, ATH11K_DBG_BOOT, "boot fw request '%s': %d\n", | |
78 | filename, ret); | |
79 | ||
80 | if (ret) | |
81 | return ERR_PTR(ret); | |
82 | ath11k_warn(ab, "Downloading BDF: %s, size: %zu\n", | |
83 | filename, fw->size); | |
84 | ||
85 | return fw; | |
86 | } | |
87 | ||
88 | void ath11k_core_free_bdf(struct ath11k_base *ab, struct ath11k_board_data *bd) | |
89 | { | |
90 | if (!IS_ERR(bd->fw)) | |
91 | release_firmware(bd->fw); | |
92 | ||
93 | memset(bd, 0, sizeof(*bd)); | |
94 | } | |
95 | ||
96 | static int ath11k_core_parse_bd_ie_board(struct ath11k_base *ab, | |
97 | struct ath11k_board_data *bd, | |
98 | const void *buf, size_t buf_len, | |
99 | const char *boardname, | |
100 | int bd_ie_type) | |
101 | { | |
102 | const struct ath11k_fw_ie *hdr; | |
103 | bool name_match_found; | |
104 | int ret, board_ie_id; | |
105 | size_t board_ie_len; | |
106 | const void *board_ie_data; | |
107 | ||
108 | name_match_found = false; | |
109 | ||
110 | /* go through ATH11K_BD_IE_BOARD_ elements */ | |
111 | while (buf_len > sizeof(struct ath11k_fw_ie)) { | |
112 | hdr = buf; | |
113 | board_ie_id = le32_to_cpu(hdr->id); | |
114 | board_ie_len = le32_to_cpu(hdr->len); | |
115 | board_ie_data = hdr->data; | |
116 | ||
117 | buf_len -= sizeof(*hdr); | |
118 | buf += sizeof(*hdr); | |
119 | ||
120 | if (buf_len < ALIGN(board_ie_len, 4)) { | |
121 | ath11k_err(ab, "invalid ATH11K_BD_IE_BOARD length: %zu < %zu\n", | |
122 | buf_len, ALIGN(board_ie_len, 4)); | |
123 | ret = -EINVAL; | |
124 | goto out; | |
125 | } | |
126 | ||
127 | switch (board_ie_id) { | |
128 | case ATH11K_BD_IE_BOARD_NAME: | |
129 | ath11k_dbg_dump(ab, ATH11K_DBG_BOOT, "board name", "", | |
130 | board_ie_data, board_ie_len); | |
131 | ||
132 | if (board_ie_len != strlen(boardname)) | |
133 | break; | |
134 | ||
135 | ret = memcmp(board_ie_data, boardname, strlen(boardname)); | |
136 | if (ret) | |
137 | break; | |
138 | ||
139 | name_match_found = true; | |
140 | ath11k_dbg(ab, ATH11K_DBG_BOOT, | |
141 | "boot found match for name '%s'", | |
142 | boardname); | |
143 | break; | |
144 | case ATH11K_BD_IE_BOARD_DATA: | |
145 | if (!name_match_found) | |
146 | /* no match found */ | |
147 | break; | |
148 | ||
149 | ath11k_dbg(ab, ATH11K_DBG_BOOT, | |
150 | "boot found board data for '%s'", boardname); | |
151 | ||
152 | bd->data = board_ie_data; | |
153 | bd->len = board_ie_len; | |
154 | ||
155 | ret = 0; | |
156 | goto out; | |
157 | default: | |
158 | ath11k_warn(ab, "unknown ATH11K_BD_IE_BOARD found: %d\n", | |
159 | board_ie_id); | |
160 | break; | |
161 | } | |
162 | ||
163 | /* jump over the padding */ | |
164 | board_ie_len = ALIGN(board_ie_len, 4); | |
165 | ||
166 | buf_len -= board_ie_len; | |
167 | buf += board_ie_len; | |
168 | } | |
169 | ||
170 | /* no match found */ | |
171 | ret = -ENOENT; | |
172 | ||
173 | out: | |
174 | return ret; | |
175 | } | |
176 | ||
177 | static int ath11k_core_fetch_board_data_api_n(struct ath11k_base *ab, | |
178 | struct ath11k_board_data *bd, | |
179 | const char *boardname) | |
180 | { | |
181 | size_t len, magic_len; | |
182 | const u8 *data; | |
183 | char *filename = ATH11K_BOARD_API2_FILE; | |
184 | size_t ie_len; | |
185 | struct ath11k_fw_ie *hdr; | |
186 | int ret, ie_id; | |
187 | ||
188 | if (!bd->fw) | |
189 | bd->fw = ath11k_fetch_fw_file(ab, | |
190 | ab->hw_params.fw.dir, | |
191 | filename); | |
192 | if (IS_ERR(bd->fw)) | |
193 | return PTR_ERR(bd->fw); | |
194 | ||
195 | data = bd->fw->data; | |
196 | len = bd->fw->size; | |
197 | ||
198 | /* magic has extra null byte padded */ | |
199 | magic_len = strlen(ATH11K_BOARD_MAGIC) + 1; | |
200 | if (len < magic_len) { | |
201 | ath11k_err(ab, "failed to find magic value in %s/%s, file too short: %zu\n", | |
202 | ab->hw_params.fw.dir, filename, len); | |
203 | ret = -EINVAL; | |
204 | goto err; | |
205 | } | |
206 | ||
207 | if (memcmp(data, ATH11K_BOARD_MAGIC, magic_len)) { | |
208 | ath11k_err(ab, "found invalid board magic\n"); | |
209 | ret = -EINVAL; | |
210 | goto err; | |
211 | } | |
212 | ||
213 | /* magic is padded to 4 bytes */ | |
214 | magic_len = ALIGN(magic_len, 4); | |
215 | if (len < magic_len) { | |
216 | ath11k_err(ab, "failed: %s/%s too small to contain board data, len: %zu\n", | |
217 | ab->hw_params.fw.dir, filename, len); | |
218 | ret = -EINVAL; | |
219 | goto err; | |
220 | } | |
221 | ||
222 | data += magic_len; | |
223 | len -= magic_len; | |
224 | ||
225 | while (len > sizeof(struct ath11k_fw_ie)) { | |
226 | hdr = (struct ath11k_fw_ie *)data; | |
227 | ie_id = le32_to_cpu(hdr->id); | |
228 | ie_len = le32_to_cpu(hdr->len); | |
229 | ||
230 | len -= sizeof(*hdr); | |
231 | data = hdr->data; | |
232 | ||
233 | if (len < ALIGN(ie_len, 4)) { | |
234 | ath11k_err(ab, "invalid length for board ie_id %d ie_len %zu len %zu\n", | |
235 | ie_id, ie_len, len); | |
236 | return -EINVAL; | |
237 | } | |
238 | ||
239 | switch (ie_id) { | |
240 | case ATH11K_BD_IE_BOARD: | |
241 | ret = ath11k_core_parse_bd_ie_board(ab, bd, data, | |
242 | ie_len, | |
243 | boardname, | |
244 | ATH11K_BD_IE_BOARD); | |
245 | if (ret == -ENOENT) | |
246 | /* no match found, continue */ | |
247 | break; | |
248 | else if (ret) | |
249 | /* there was an error, bail out */ | |
250 | goto err; | |
251 | /* either found or error, so stop searching */ | |
252 | goto out; | |
253 | } | |
254 | ||
255 | /* jump over the padding */ | |
256 | ie_len = ALIGN(ie_len, 4); | |
257 | ||
258 | len -= ie_len; | |
259 | data += ie_len; | |
260 | } | |
261 | ||
262 | out: | |
263 | if (!bd->data || !bd->len) { | |
264 | ath11k_err(ab, | |
265 | "failed to fetch board data for %s from %s/%s\n", | |
266 | boardname, ab->hw_params.fw.dir, filename); | |
267 | ret = -ENODATA; | |
268 | goto err; | |
269 | } | |
270 | ||
271 | return 0; | |
272 | ||
273 | err: | |
274 | ath11k_core_free_bdf(ab, bd); | |
275 | return ret; | |
276 | } | |
277 | ||
278 | static int ath11k_core_fetch_board_data_api_1(struct ath11k_base *ab, | |
279 | struct ath11k_board_data *bd) | |
280 | { | |
281 | bd->fw = ath11k_fetch_fw_file(ab, | |
282 | ab->hw_params.fw.dir, | |
283 | ATH11K_DEFAULT_BOARD_FILE); | |
284 | if (IS_ERR(bd->fw)) | |
285 | return PTR_ERR(bd->fw); | |
286 | ||
287 | bd->data = bd->fw->data; | |
288 | bd->len = bd->fw->size; | |
289 | ||
290 | return 0; | |
291 | } | |
292 | ||
293 | #define BOARD_NAME_SIZE 100 | |
294 | int ath11k_core_fetch_bdf(struct ath11k_base *ab, struct ath11k_board_data *bd) | |
295 | { | |
296 | char boardname[BOARD_NAME_SIZE]; | |
297 | int ret; | |
298 | ||
299 | ret = ath11k_core_create_board_name(ab, boardname, BOARD_NAME_SIZE); | |
300 | if (ret) { | |
301 | ath11k_err(ab, "failed to create board name: %d", ret); | |
302 | return ret; | |
303 | } | |
304 | ||
305 | ab->bd_api = 2; | |
306 | ret = ath11k_core_fetch_board_data_api_n(ab, bd, boardname); | |
307 | if (!ret) | |
308 | goto success; | |
309 | ||
310 | ab->bd_api = 1; | |
311 | ret = ath11k_core_fetch_board_data_api_1(ab, bd); | |
312 | if (ret) { | |
313 | ath11k_err(ab, "failed to fetch board-2.bin or board.bin from %s\n", | |
314 | ab->hw_params.fw.dir); | |
315 | return ret; | |
316 | } | |
317 | ||
318 | success: | |
319 | ath11k_dbg(ab, ATH11K_DBG_BOOT, "using board api %d\n", ab->bd_api); | |
320 | return 0; | |
321 | } | |
322 | ||
323 | static void ath11k_core_stop(struct ath11k_base *ab) | |
324 | { | |
325 | if (!test_bit(ATH11K_FLAG_CRASH_FLUSH, &ab->dev_flags)) | |
326 | ath11k_qmi_firmware_stop(ab); | |
327 | ath11k_ahb_stop(ab); | |
328 | ath11k_wmi_detach(ab); | |
9c57d7e3 | 329 | ath11k_dp_pdev_reo_cleanup(ab); |
d5c65159 KV |
330 | |
331 | /* De-Init of components as needed */ | |
332 | } | |
333 | ||
334 | static int ath11k_core_soc_create(struct ath11k_base *ab) | |
335 | { | |
336 | int ret; | |
337 | ||
338 | ret = ath11k_qmi_init_service(ab); | |
339 | if (ret) { | |
340 | ath11k_err(ab, "failed to initialize qmi :%d\n", ret); | |
341 | return ret; | |
342 | } | |
343 | ||
344 | ret = ath11k_debug_soc_create(ab); | |
345 | if (ret) { | |
346 | ath11k_err(ab, "failed to create ath11k debugfs\n"); | |
347 | goto err_qmi_deinit; | |
348 | } | |
349 | ||
350 | ret = ath11k_ahb_power_up(ab); | |
351 | if (ret) { | |
352 | ath11k_err(ab, "failed to power up :%d\n", ret); | |
353 | goto err_debugfs_reg; | |
354 | } | |
355 | ||
356 | return 0; | |
357 | ||
358 | err_debugfs_reg: | |
359 | ath11k_debug_soc_destroy(ab); | |
360 | err_qmi_deinit: | |
361 | ath11k_qmi_deinit_service(ab); | |
362 | return ret; | |
363 | } | |
364 | ||
365 | static void ath11k_core_soc_destroy(struct ath11k_base *ab) | |
366 | { | |
367 | ath11k_debug_soc_destroy(ab); | |
368 | ath11k_dp_free(ab); | |
369 | ath11k_reg_free(ab); | |
370 | ath11k_qmi_deinit_service(ab); | |
371 | } | |
372 | ||
373 | static int ath11k_core_pdev_create(struct ath11k_base *ab) | |
374 | { | |
375 | int ret; | |
376 | ||
377 | ret = ath11k_debug_pdev_create(ab); | |
378 | if (ret) { | |
379 | ath11k_err(ab, "failed to create core pdev debugfs: %d\n", ret); | |
380 | return ret; | |
381 | } | |
382 | ||
0366f426 | 383 | ret = ath11k_mac_register(ab); |
d5c65159 | 384 | if (ret) { |
0366f426 | 385 | ath11k_err(ab, "failed register the radio with mac80211: %d\n", ret); |
d5c65159 KV |
386 | goto err_pdev_debug; |
387 | } | |
388 | ||
389 | ret = ath11k_dp_pdev_alloc(ab); | |
390 | if (ret) { | |
391 | ath11k_err(ab, "failed to attach DP pdev: %d\n", ret); | |
0366f426 | 392 | goto err_mac_unregister; |
d5c65159 KV |
393 | } |
394 | ||
395 | return 0; | |
396 | ||
0366f426 VT |
397 | err_mac_unregister: |
398 | ath11k_mac_unregister(ab); | |
d5c65159 KV |
399 | |
400 | err_pdev_debug: | |
401 | ath11k_debug_pdev_destroy(ab); | |
402 | ||
403 | return ret; | |
404 | } | |
405 | ||
406 | static void ath11k_core_pdev_destroy(struct ath11k_base *ab) | |
407 | { | |
408 | ath11k_mac_unregister(ab); | |
409 | ath11k_ahb_ext_irq_disable(ab); | |
410 | ath11k_dp_pdev_free(ab); | |
411 | ath11k_debug_pdev_destroy(ab); | |
412 | } | |
413 | ||
414 | static int ath11k_core_start(struct ath11k_base *ab, | |
415 | enum ath11k_firmware_mode mode) | |
416 | { | |
417 | int ret; | |
418 | ||
419 | ret = ath11k_qmi_firmware_start(ab, mode); | |
420 | if (ret) { | |
421 | ath11k_err(ab, "failed to attach wmi: %d\n", ret); | |
422 | return ret; | |
423 | } | |
424 | ||
425 | ret = ath11k_wmi_attach(ab); | |
426 | if (ret) { | |
427 | ath11k_err(ab, "failed to attach wmi: %d\n", ret); | |
428 | goto err_firmware_stop; | |
429 | } | |
430 | ||
431 | ret = ath11k_htc_init(ab); | |
432 | if (ret) { | |
433 | ath11k_err(ab, "failed to init htc: %d\n", ret); | |
434 | goto err_wmi_detach; | |
435 | } | |
436 | ||
437 | ret = ath11k_ahb_start(ab); | |
438 | if (ret) { | |
439 | ath11k_err(ab, "failed to start HIF: %d\n", ret); | |
440 | goto err_wmi_detach; | |
441 | } | |
442 | ||
443 | ret = ath11k_htc_wait_target(&ab->htc); | |
444 | if (ret) { | |
445 | ath11k_err(ab, "failed to connect to HTC: %d\n", ret); | |
446 | goto err_hif_stop; | |
447 | } | |
448 | ||
449 | ret = ath11k_dp_htt_connect(&ab->dp); | |
450 | if (ret) { | |
451 | ath11k_err(ab, "failed to connect to HTT: %d\n", ret); | |
452 | goto err_hif_stop; | |
453 | } | |
454 | ||
455 | ret = ath11k_wmi_connect(ab); | |
456 | if (ret) { | |
457 | ath11k_err(ab, "failed to connect wmi: %d\n", ret); | |
458 | goto err_hif_stop; | |
459 | } | |
460 | ||
461 | ret = ath11k_htc_start(&ab->htc); | |
462 | if (ret) { | |
463 | ath11k_err(ab, "failed to start HTC: %d\n", ret); | |
464 | goto err_hif_stop; | |
465 | } | |
466 | ||
467 | ret = ath11k_wmi_wait_for_service_ready(ab); | |
468 | if (ret) { | |
469 | ath11k_err(ab, "failed to receive wmi service ready event: %d\n", | |
470 | ret); | |
471 | goto err_hif_stop; | |
472 | } | |
473 | ||
0366f426 VT |
474 | ret = ath11k_mac_allocate(ab); |
475 | if (ret) { | |
476 | ath11k_err(ab, "failed to create new hw device with mac80211 :%d\n", | |
477 | ret); | |
478 | goto err_hif_stop; | |
479 | } | |
480 | ||
9c57d7e3 VT |
481 | ath11k_dp_pdev_pre_alloc(ab); |
482 | ||
483 | ret = ath11k_dp_pdev_reo_setup(ab); | |
484 | if (ret) { | |
485 | ath11k_err(ab, "failed to initialize reo destination rings: %d\n", ret); | |
486 | goto err_mac_destroy; | |
487 | } | |
488 | ||
d5c65159 KV |
489 | ret = ath11k_wmi_cmd_init(ab); |
490 | if (ret) { | |
491 | ath11k_err(ab, "failed to send wmi init cmd: %d\n", ret); | |
9c57d7e3 | 492 | goto err_reo_cleanup; |
d5c65159 KV |
493 | } |
494 | ||
495 | ret = ath11k_wmi_wait_for_unified_ready(ab); | |
496 | if (ret) { | |
497 | ath11k_err(ab, "failed to receive wmi unified ready event: %d\n", | |
498 | ret); | |
9c57d7e3 | 499 | goto err_reo_cleanup; |
d5c65159 KV |
500 | } |
501 | ||
502 | ret = ath11k_dp_tx_htt_h2t_ver_req_msg(ab); | |
503 | if (ret) { | |
504 | ath11k_err(ab, "failed to send htt version request message: %d\n", | |
505 | ret); | |
9c57d7e3 | 506 | goto err_reo_cleanup; |
d5c65159 KV |
507 | } |
508 | ||
509 | return 0; | |
510 | ||
9c57d7e3 VT |
511 | err_reo_cleanup: |
512 | ath11k_dp_pdev_reo_cleanup(ab); | |
0366f426 VT |
513 | err_mac_destroy: |
514 | ath11k_mac_destroy(ab); | |
d5c65159 KV |
515 | err_hif_stop: |
516 | ath11k_ahb_stop(ab); | |
517 | err_wmi_detach: | |
518 | ath11k_wmi_detach(ab); | |
519 | err_firmware_stop: | |
520 | ath11k_qmi_firmware_stop(ab); | |
521 | ||
522 | return ret; | |
523 | } | |
524 | ||
525 | int ath11k_core_qmi_firmware_ready(struct ath11k_base *ab) | |
526 | { | |
527 | int ret; | |
528 | ||
529 | ret = ath11k_ce_init_pipes(ab); | |
530 | if (ret) { | |
531 | ath11k_err(ab, "failed to initialize CE: %d\n", ret); | |
532 | return ret; | |
533 | } | |
534 | ||
535 | ret = ath11k_dp_alloc(ab); | |
536 | if (ret) { | |
537 | ath11k_err(ab, "failed to init DP: %d\n", ret); | |
538 | return ret; | |
539 | } | |
540 | ||
541 | mutex_lock(&ab->core_lock); | |
542 | ret = ath11k_core_start(ab, ATH11K_FIRMWARE_MODE_NORMAL); | |
543 | if (ret) { | |
544 | ath11k_err(ab, "failed to start core: %d\n", ret); | |
545 | goto err_dp_free; | |
546 | } | |
547 | ||
548 | ret = ath11k_core_pdev_create(ab); | |
549 | if (ret) { | |
550 | ath11k_err(ab, "failed to create pdev core: %d\n", ret); | |
551 | goto err_core_stop; | |
552 | } | |
553 | ath11k_ahb_ext_irq_enable(ab); | |
554 | mutex_unlock(&ab->core_lock); | |
555 | ||
556 | return 0; | |
557 | ||
558 | err_core_stop: | |
559 | ath11k_core_stop(ab); | |
0366f426 | 560 | ath11k_mac_destroy(ab); |
d5c65159 KV |
561 | err_dp_free: |
562 | ath11k_dp_free(ab); | |
ba479239 | 563 | mutex_unlock(&ab->core_lock); |
d5c65159 KV |
564 | return ret; |
565 | } | |
566 | ||
567 | static int ath11k_core_reconfigure_on_crash(struct ath11k_base *ab) | |
568 | { | |
569 | int ret; | |
570 | ||
571 | mutex_lock(&ab->core_lock); | |
572 | ath11k_ahb_ext_irq_disable(ab); | |
573 | ath11k_dp_pdev_free(ab); | |
574 | ath11k_ahb_stop(ab); | |
575 | ath11k_wmi_detach(ab); | |
9c57d7e3 | 576 | ath11k_dp_pdev_reo_cleanup(ab); |
d5c65159 KV |
577 | mutex_unlock(&ab->core_lock); |
578 | ||
579 | ath11k_dp_free(ab); | |
580 | ath11k_hal_srng_deinit(ab); | |
581 | ||
582 | ab->free_vdev_map = (1LL << (ab->num_radios * TARGET_NUM_VDEVS)) - 1; | |
583 | ||
584 | ret = ath11k_hal_srng_init(ab); | |
585 | if (ret) | |
586 | return ret; | |
587 | ||
588 | clear_bit(ATH11K_FLAG_CRASH_FLUSH, &ab->dev_flags); | |
589 | ||
590 | ret = ath11k_core_qmi_firmware_ready(ab); | |
591 | if (ret) | |
592 | goto err_hal_srng_deinit; | |
593 | ||
594 | clear_bit(ATH11K_FLAG_RECOVERY, &ab->dev_flags); | |
595 | ||
596 | return 0; | |
597 | ||
598 | err_hal_srng_deinit: | |
599 | ath11k_hal_srng_deinit(ab); | |
600 | return ret; | |
601 | } | |
602 | ||
603 | void ath11k_core_halt(struct ath11k *ar) | |
604 | { | |
605 | struct ath11k_base *ab = ar->ab; | |
606 | ||
607 | lockdep_assert_held(&ar->conf_mutex); | |
608 | ||
609 | ar->num_created_vdevs = 0; | |
610 | ||
611 | ath11k_mac_scan_finish(ar); | |
612 | ath11k_mac_peer_cleanup_all(ar); | |
613 | cancel_delayed_work_sync(&ar->scan.timeout); | |
614 | cancel_work_sync(&ar->regd_update_work); | |
615 | ||
616 | rcu_assign_pointer(ab->pdevs_active[ar->pdev_idx], NULL); | |
617 | synchronize_rcu(); | |
618 | INIT_LIST_HEAD(&ar->arvifs); | |
619 | idr_init(&ar->txmgmt_idr); | |
620 | } | |
621 | ||
622 | static void ath11k_core_restart(struct work_struct *work) | |
623 | { | |
624 | struct ath11k_base *ab = container_of(work, struct ath11k_base, restart_work); | |
625 | struct ath11k *ar; | |
626 | struct ath11k_pdev *pdev; | |
627 | int i, ret = 0; | |
628 | ||
629 | spin_lock_bh(&ab->base_lock); | |
630 | ab->stats.fw_crash_counter++; | |
631 | spin_unlock_bh(&ab->base_lock); | |
632 | ||
633 | for (i = 0; i < ab->num_radios; i++) { | |
634 | pdev = &ab->pdevs[i]; | |
635 | ar = pdev->ar; | |
636 | if (!ar || ar->state == ATH11K_STATE_OFF) | |
637 | continue; | |
638 | ||
639 | ieee80211_stop_queues(ar->hw); | |
640 | ath11k_mac_drain_tx(ar); | |
641 | complete(&ar->scan.started); | |
642 | complete(&ar->scan.completed); | |
643 | complete(&ar->peer_assoc_done); | |
644 | complete(&ar->install_key_done); | |
645 | complete(&ar->vdev_setup_done); | |
646 | complete(&ar->bss_survey_done); | |
647 | ||
648 | wake_up(&ar->dp.tx_empty_waitq); | |
649 | idr_for_each(&ar->txmgmt_idr, | |
650 | ath11k_mac_tx_mgmt_pending_free, ar); | |
651 | idr_destroy(&ar->txmgmt_idr); | |
652 | } | |
653 | ||
654 | wake_up(&ab->wmi_sc.tx_credits_wq); | |
655 | wake_up(&ab->peer_mapping_wq); | |
656 | ||
657 | ret = ath11k_core_reconfigure_on_crash(ab); | |
658 | if (ret) { | |
659 | ath11k_err(ab, "failed to reconfigure driver on crash recovery\n"); | |
660 | return; | |
661 | } | |
662 | ||
663 | for (i = 0; i < ab->num_radios; i++) { | |
664 | pdev = &ab->pdevs[i]; | |
665 | ar = pdev->ar; | |
666 | if (!ar || ar->state == ATH11K_STATE_OFF) | |
667 | continue; | |
668 | ||
669 | mutex_lock(&ar->conf_mutex); | |
670 | ||
671 | switch (ar->state) { | |
672 | case ATH11K_STATE_ON: | |
673 | ar->state = ATH11K_STATE_RESTARTING; | |
674 | ath11k_core_halt(ar); | |
675 | ieee80211_restart_hw(ar->hw); | |
676 | break; | |
677 | case ATH11K_STATE_OFF: | |
678 | ath11k_warn(ab, | |
679 | "cannot restart radio %d that hasn't been started\n", | |
680 | i); | |
681 | break; | |
682 | case ATH11K_STATE_RESTARTING: | |
683 | break; | |
684 | case ATH11K_STATE_RESTARTED: | |
685 | ar->state = ATH11K_STATE_WEDGED; | |
686 | /* fall through */ | |
687 | case ATH11K_STATE_WEDGED: | |
688 | ath11k_warn(ab, | |
689 | "device is wedged, will not restart radio %d\n", i); | |
690 | break; | |
691 | } | |
692 | mutex_unlock(&ar->conf_mutex); | |
693 | } | |
694 | complete(&ab->driver_recovery); | |
695 | } | |
696 | ||
697 | int ath11k_core_init(struct ath11k_base *ab) | |
698 | { | |
699 | struct device *dev = ab->dev; | |
700 | struct rproc *prproc; | |
701 | phandle rproc_phandle; | |
702 | int ret; | |
703 | ||
704 | if (of_property_read_u32(dev->of_node, "qcom,rproc", &rproc_phandle)) { | |
705 | ath11k_err(ab, "failed to get q6_rproc handle\n"); | |
706 | return -ENOENT; | |
707 | } | |
708 | ||
709 | prproc = rproc_get_by_phandle(rproc_phandle); | |
710 | if (!prproc) { | |
711 | ath11k_err(ab, "failed to get rproc\n"); | |
712 | return -EINVAL; | |
713 | } | |
714 | ab->tgt_rproc = prproc; | |
715 | ab->hw_params = ath11k_hw_params; | |
716 | ||
717 | ret = ath11k_core_soc_create(ab); | |
718 | if (ret) { | |
719 | ath11k_err(ab, "failed to create soc core: %d\n", ret); | |
720 | return ret; | |
721 | } | |
722 | ||
723 | return 0; | |
724 | } | |
725 | ||
726 | void ath11k_core_deinit(struct ath11k_base *ab) | |
727 | { | |
728 | mutex_lock(&ab->core_lock); | |
729 | ||
730 | ath11k_core_pdev_destroy(ab); | |
731 | ath11k_core_stop(ab); | |
732 | ||
733 | mutex_unlock(&ab->core_lock); | |
734 | ||
735 | ath11k_ahb_power_down(ab); | |
736 | ath11k_mac_destroy(ab); | |
737 | ath11k_core_soc_destroy(ab); | |
738 | } | |
739 | ||
740 | void ath11k_core_free(struct ath11k_base *ab) | |
741 | { | |
742 | kfree(ab); | |
743 | } | |
744 | ||
745 | struct ath11k_base *ath11k_core_alloc(struct device *dev) | |
746 | { | |
747 | struct ath11k_base *ab; | |
748 | ||
749 | ab = kzalloc(sizeof(*ab), GFP_KERNEL); | |
750 | if (!ab) | |
751 | return NULL; | |
752 | ||
753 | init_completion(&ab->driver_recovery); | |
754 | ||
755 | ab->workqueue = create_singlethread_workqueue("ath11k_wq"); | |
756 | if (!ab->workqueue) | |
757 | goto err_sc_free; | |
758 | ||
759 | mutex_init(&ab->core_lock); | |
760 | spin_lock_init(&ab->base_lock); | |
761 | ||
762 | INIT_LIST_HEAD(&ab->peers); | |
763 | init_waitqueue_head(&ab->peer_mapping_wq); | |
764 | init_waitqueue_head(&ab->wmi_sc.tx_credits_wq); | |
765 | INIT_WORK(&ab->restart_work, ath11k_core_restart); | |
766 | timer_setup(&ab->rx_replenish_retry, ath11k_ce_rx_replenish_retry, 0); | |
767 | ab->dev = dev; | |
768 | ||
769 | return ab; | |
770 | ||
771 | err_sc_free: | |
772 | kfree(ab); | |
773 | return NULL; | |
774 | } | |
775 | ||
776 | static int __init ath11k_init(void) | |
777 | { | |
778 | int ret; | |
779 | ||
780 | ret = ath11k_ahb_init(); | |
781 | if (ret) | |
782 | printk(KERN_ERR "failed to register ath11k ahb driver: %d\n", | |
783 | ret); | |
784 | return ret; | |
785 | } | |
786 | module_init(ath11k_init); | |
787 | ||
788 | static void __exit ath11k_exit(void) | |
789 | { | |
790 | ath11k_ahb_exit(); | |
791 | } | |
792 | module_exit(ath11k_exit); | |
793 | ||
794 | MODULE_DESCRIPTION("Driver support for Qualcomm Technologies 802.11ax wireless chip"); | |
795 | MODULE_LICENSE("Dual BSD/GPL"); |