1 // SPDX-License-Identifier: BSD-3-Clause-Clear
2 /*
3 * Copyright (c) 2018-2021 The Linux Foundation. All rights reserved.
4 * Copyright (c) 2021-2024 Qualcomm Innovation Center, Inc. All rights reserved.
5 */
6
7 #include <linux/module.h>
8 #include <linux/slab.h>
9 #include <linux/remoteproc.h>
10 #include <linux/firmware.h>
11 #include <linux/of.h>
12 #include "core.h"
13 #include "dp_tx.h"
14 #include "dp_rx.h"
15 #include "debug.h"
16 #include "hif.h"
17 #include "fw.h"
18 #include "debugfs.h"
19 #include "wow.h"
20
21 unsigned int ath12k_debug_mask;
22 module_param_named(debug_mask, ath12k_debug_mask, uint, 0644);
23 MODULE_PARM_DESC(debug_mask, "Debugging mask");
24
ath12k_core_rfkill_config(struct ath12k_base * ab)25 static int ath12k_core_rfkill_config(struct ath12k_base *ab)
26 {
27 struct ath12k *ar;
28 int ret = 0, i;
29
30 if (!(ab->target_caps.sys_cap_info & WMI_SYS_CAP_INFO_RFKILL))
31 return 0;
32
33 for (i = 0; i < ab->num_radios; i++) {
34 ar = ab->pdevs[i].ar;
35
36 ret = ath12k_mac_rfkill_config(ar);
37 if (ret && ret != -EOPNOTSUPP) {
38 ath12k_warn(ab, "failed to configure rfkill: %d", ret);
39 return ret;
40 }
41 }
42
43 return ret;
44 }
45
46 /* Check if we need to continue with suspend/resume operation.
47 * Return:
48 * a negative value: error happens and don't continue.
49 * 0: no error but don't continue.
50 * positive value: no error and do continue.
51 */
ath12k_core_continue_suspend_resume(struct ath12k_base * ab)52 static int ath12k_core_continue_suspend_resume(struct ath12k_base *ab)
53 {
54 struct ath12k *ar;
55
56 if (!ab->hw_params->supports_suspend)
57 return -EOPNOTSUPP;
58
59 /* so far single_pdev_only chips have supports_suspend as true
60 * so pass 0 as a dummy pdev_id here.
61 */
62 ar = ab->pdevs[0].ar;
63 if (!ar || !ar->ah || ar->ah->state != ATH12K_HW_STATE_OFF)
64 return 0;
65
66 return 1;
67 }
68
ath12k_core_suspend(struct ath12k_base * ab)69 int ath12k_core_suspend(struct ath12k_base *ab)
70 {
71 struct ath12k *ar;
72 int ret, i;
73
74 ret = ath12k_core_continue_suspend_resume(ab);
75 if (ret <= 0)
76 return ret;
77
78 for (i = 0; i < ab->num_radios; i++) {
79 ar = ab->pdevs[i].ar;
80 if (!ar)
81 continue;
82 ret = ath12k_mac_wait_tx_complete(ar);
83 if (ret) {
84 ath12k_warn(ab, "failed to wait tx complete: %d\n", ret);
85 return ret;
86 }
87 }
88
89 /* PM framework skips suspend_late/resume_early callbacks
90 * if other devices report errors in their suspend callbacks.
91 * However ath12k_core_resume() would still be called because
92 * here we return success thus kernel put us on dpm_suspended_list.
93 * Since we won't go through a power down/up cycle, there is
94 * no chance to call complete(&ab->restart_completed) in
95 * ath12k_core_restart(), making ath12k_core_resume() timeout.
96 * So call it here to avoid this issue. This also works in case
97 * no error happens thus suspend_late/resume_early get called,
98 * because it will be reinitialized in ath12k_core_resume_early().
99 */
100 complete(&ab->restart_completed);
101
102 return 0;
103 }
104 EXPORT_SYMBOL(ath12k_core_suspend);
105
ath12k_core_suspend_late(struct ath12k_base * ab)106 int ath12k_core_suspend_late(struct ath12k_base *ab)
107 {
108 int ret;
109
110 ret = ath12k_core_continue_suspend_resume(ab);
111 if (ret <= 0)
112 return ret;
113
114 ath12k_acpi_stop(ab);
115
116 ath12k_hif_irq_disable(ab);
117 ath12k_hif_ce_irq_disable(ab);
118
119 ath12k_hif_power_down(ab, true);
120
121 return 0;
122 }
123 EXPORT_SYMBOL(ath12k_core_suspend_late);
124
ath12k_core_resume_early(struct ath12k_base * ab)125 int ath12k_core_resume_early(struct ath12k_base *ab)
126 {
127 int ret;
128
129 ret = ath12k_core_continue_suspend_resume(ab);
130 if (ret <= 0)
131 return ret;
132
133 reinit_completion(&ab->restart_completed);
134 ret = ath12k_hif_power_up(ab);
135 if (ret)
136 ath12k_warn(ab, "failed to power up hif during resume: %d\n", ret);
137
138 return ret;
139 }
140 EXPORT_SYMBOL(ath12k_core_resume_early);
141
ath12k_core_resume(struct ath12k_base * ab)142 int ath12k_core_resume(struct ath12k_base *ab)
143 {
144 long time_left;
145 int ret;
146
147 ret = ath12k_core_continue_suspend_resume(ab);
148 if (ret <= 0)
149 return ret;
150
151 time_left = wait_for_completion_timeout(&ab->restart_completed,
152 ATH12K_RESET_TIMEOUT_HZ);
153 if (time_left == 0) {
154 ath12k_warn(ab, "timeout while waiting for restart complete");
155 return -ETIMEDOUT;
156 }
157
158 return 0;
159 }
160 EXPORT_SYMBOL(ath12k_core_resume);
161
__ath12k_core_create_board_name(struct ath12k_base * ab,char * name,size_t name_len,bool with_variant,bool bus_type_mode,bool with_default)162 static int __ath12k_core_create_board_name(struct ath12k_base *ab, char *name,
163 size_t name_len, bool with_variant,
164 bool bus_type_mode, bool with_default)
165 {
166 /* strlen(',variant=') + strlen(ab->qmi.target.bdf_ext) */
167 char variant[9 + ATH12K_QMI_BDF_EXT_STR_LENGTH] = { 0 };
168
169 if (with_variant && ab->qmi.target.bdf_ext[0] != '\0')
170 scnprintf(variant, sizeof(variant), ",variant=%s",
171 ab->qmi.target.bdf_ext);
172
173 switch (ab->id.bdf_search) {
174 case ATH12K_BDF_SEARCH_BUS_AND_BOARD:
175 if (bus_type_mode)
176 scnprintf(name, name_len,
177 "bus=%s",
178 ath12k_bus_str(ab->hif.bus));
179 else
180 scnprintf(name, name_len,
181 "bus=%s,vendor=%04x,device=%04x,subsystem-vendor=%04x,subsystem-device=%04x,qmi-chip-id=%d,qmi-board-id=%d%s",
182 ath12k_bus_str(ab->hif.bus),
183 ab->id.vendor, ab->id.device,
184 ab->id.subsystem_vendor,
185 ab->id.subsystem_device,
186 ab->qmi.target.chip_id,
187 ab->qmi.target.board_id,
188 variant);
189 break;
190 default:
191 scnprintf(name, name_len,
192 "bus=%s,qmi-chip-id=%d,qmi-board-id=%d%s",
193 ath12k_bus_str(ab->hif.bus),
194 ab->qmi.target.chip_id,
195 with_default ?
196 ATH12K_BOARD_ID_DEFAULT : ab->qmi.target.board_id,
197 variant);
198 break;
199 }
200
201 ath12k_dbg(ab, ATH12K_DBG_BOOT, "boot using board name '%s'\n", name);
202
203 return 0;
204 }
205
ath12k_core_create_board_name(struct ath12k_base * ab,char * name,size_t name_len)206 static int ath12k_core_create_board_name(struct ath12k_base *ab, char *name,
207 size_t name_len)
208 {
209 return __ath12k_core_create_board_name(ab, name, name_len, true, false, false);
210 }
211
ath12k_core_create_fallback_board_name(struct ath12k_base * ab,char * name,size_t name_len)212 static int ath12k_core_create_fallback_board_name(struct ath12k_base *ab, char *name,
213 size_t name_len)
214 {
215 return __ath12k_core_create_board_name(ab, name, name_len, false, false, true);
216 }
217
ath12k_core_create_bus_type_board_name(struct ath12k_base * ab,char * name,size_t name_len)218 static int ath12k_core_create_bus_type_board_name(struct ath12k_base *ab, char *name,
219 size_t name_len)
220 {
221 return __ath12k_core_create_board_name(ab, name, name_len, false, true, true);
222 }
223
ath12k_core_firmware_request(struct ath12k_base * ab,const char * file)224 const struct firmware *ath12k_core_firmware_request(struct ath12k_base *ab,
225 const char *file)
226 {
227 const struct firmware *fw;
228 char path[100];
229 int ret;
230
231 if (!file)
232 return ERR_PTR(-ENOENT);
233
234 ath12k_core_create_firmware_path(ab, file, path, sizeof(path));
235
236 ret = firmware_request_nowarn(&fw, path, ab->dev);
237 if (ret)
238 return ERR_PTR(ret);
239
240 ath12k_dbg(ab, ATH12K_DBG_BOOT, "boot firmware request %s size %zu\n",
241 path, fw->size);
242
243 return fw;
244 }
245
ath12k_core_free_bdf(struct ath12k_base * ab,struct ath12k_board_data * bd)246 void ath12k_core_free_bdf(struct ath12k_base *ab, struct ath12k_board_data *bd)
247 {
248 if (!IS_ERR(bd->fw))
249 release_firmware(bd->fw);
250
251 memset(bd, 0, sizeof(*bd));
252 }
253
ath12k_core_parse_bd_ie_board(struct ath12k_base * ab,struct ath12k_board_data * bd,const void * buf,size_t buf_len,const char * boardname,int ie_id,int name_id,int data_id)254 static int ath12k_core_parse_bd_ie_board(struct ath12k_base *ab,
255 struct ath12k_board_data *bd,
256 const void *buf, size_t buf_len,
257 const char *boardname,
258 int ie_id,
259 int name_id,
260 int data_id)
261 {
262 const struct ath12k_fw_ie *hdr;
263 bool name_match_found;
264 int ret, board_ie_id;
265 size_t board_ie_len;
266 const void *board_ie_data;
267
268 name_match_found = false;
269
270 /* go through ATH12K_BD_IE_BOARD_/ATH12K_BD_IE_REGDB_ elements */
271 while (buf_len > sizeof(struct ath12k_fw_ie)) {
272 hdr = buf;
273 board_ie_id = le32_to_cpu(hdr->id);
274 board_ie_len = le32_to_cpu(hdr->len);
275 board_ie_data = hdr->data;
276
277 buf_len -= sizeof(*hdr);
278 buf += sizeof(*hdr);
279
280 if (buf_len < ALIGN(board_ie_len, 4)) {
281 ath12k_err(ab, "invalid %s length: %zu < %zu\n",
282 ath12k_bd_ie_type_str(ie_id),
283 buf_len, ALIGN(board_ie_len, 4));
284 ret = -EINVAL;
285 goto out;
286 }
287
288 if (board_ie_id == name_id) {
289 ath12k_dbg_dump(ab, ATH12K_DBG_BOOT, "board name", "",
290 board_ie_data, board_ie_len);
291
292 if (board_ie_len != strlen(boardname))
293 goto next;
294
295 ret = memcmp(board_ie_data, boardname, strlen(boardname));
296 if (ret)
297 goto next;
298
299 name_match_found = true;
300 ath12k_dbg(ab, ATH12K_DBG_BOOT,
301 "boot found match %s for name '%s'",
302 ath12k_bd_ie_type_str(ie_id),
303 boardname);
304 } else if (board_ie_id == data_id) {
305 if (!name_match_found)
306 /* no match found */
307 goto next;
308
309 ath12k_dbg(ab, ATH12K_DBG_BOOT,
310 "boot found %s for '%s'",
311 ath12k_bd_ie_type_str(ie_id),
312 boardname);
313
314 bd->data = board_ie_data;
315 bd->len = board_ie_len;
316
317 ret = 0;
318 goto out;
319 } else {
320 ath12k_warn(ab, "unknown %s id found: %d\n",
321 ath12k_bd_ie_type_str(ie_id),
322 board_ie_id);
323 }
324 next:
325 /* jump over the padding */
326 board_ie_len = ALIGN(board_ie_len, 4);
327
328 buf_len -= board_ie_len;
329 buf += board_ie_len;
330 }
331
332 /* no match found */
333 ret = -ENOENT;
334
335 out:
336 return ret;
337 }
338
ath12k_core_fetch_board_data_api_n(struct ath12k_base * ab,struct ath12k_board_data * bd,const char * boardname,int ie_id_match,int name_id,int data_id)339 static int ath12k_core_fetch_board_data_api_n(struct ath12k_base *ab,
340 struct ath12k_board_data *bd,
341 const char *boardname,
342 int ie_id_match,
343 int name_id,
344 int data_id)
345 {
346 size_t len, magic_len;
347 const u8 *data;
348 char *filename, filepath[100];
349 size_t ie_len;
350 struct ath12k_fw_ie *hdr;
351 int ret, ie_id;
352
353 filename = ATH12K_BOARD_API2_FILE;
354
355 if (!bd->fw)
356 bd->fw = ath12k_core_firmware_request(ab, filename);
357
358 if (IS_ERR(bd->fw))
359 return PTR_ERR(bd->fw);
360
361 data = bd->fw->data;
362 len = bd->fw->size;
363
364 ath12k_core_create_firmware_path(ab, filename,
365 filepath, sizeof(filepath));
366
367 /* magic has extra null byte padded */
368 magic_len = strlen(ATH12K_BOARD_MAGIC) + 1;
369 if (len < magic_len) {
370 ath12k_err(ab, "failed to find magic value in %s, file too short: %zu\n",
371 filepath, len);
372 ret = -EINVAL;
373 goto err;
374 }
375
376 if (memcmp(data, ATH12K_BOARD_MAGIC, magic_len)) {
377 ath12k_err(ab, "found invalid board magic\n");
378 ret = -EINVAL;
379 goto err;
380 }
381
382 /* magic is padded to 4 bytes */
383 magic_len = ALIGN(magic_len, 4);
384 if (len < magic_len) {
385 ath12k_err(ab, "failed: %s too small to contain board data, len: %zu\n",
386 filepath, len);
387 ret = -EINVAL;
388 goto err;
389 }
390
391 data += magic_len;
392 len -= magic_len;
393
394 while (len > sizeof(struct ath12k_fw_ie)) {
395 hdr = (struct ath12k_fw_ie *)data;
396 ie_id = le32_to_cpu(hdr->id);
397 ie_len = le32_to_cpu(hdr->len);
398
399 len -= sizeof(*hdr);
400 data = hdr->data;
401
402 if (len < ALIGN(ie_len, 4)) {
403 ath12k_err(ab, "invalid length for board ie_id %d ie_len %zu len %zu\n",
404 ie_id, ie_len, len);
405 ret = -EINVAL;
406 goto err;
407 }
408
409 if (ie_id == ie_id_match) {
410 ret = ath12k_core_parse_bd_ie_board(ab, bd, data,
411 ie_len,
412 boardname,
413 ie_id_match,
414 name_id,
415 data_id);
416 if (ret == -ENOENT)
417 /* no match found, continue */
418 goto next;
419 else if (ret)
420 /* there was an error, bail out */
421 goto err;
422 /* either found or error, so stop searching */
423 goto out;
424 }
425 next:
426 /* jump over the padding */
427 ie_len = ALIGN(ie_len, 4);
428
429 len -= ie_len;
430 data += ie_len;
431 }
432
433 out:
434 if (!bd->data || !bd->len) {
435 ath12k_dbg(ab, ATH12K_DBG_BOOT,
436 "failed to fetch %s for %s from %s\n",
437 ath12k_bd_ie_type_str(ie_id_match),
438 boardname, filepath);
439 ret = -ENODATA;
440 goto err;
441 }
442
443 return 0;
444
445 err:
446 ath12k_core_free_bdf(ab, bd);
447 return ret;
448 }
449
ath12k_core_fetch_board_data_api_1(struct ath12k_base * ab,struct ath12k_board_data * bd,char * filename)450 int ath12k_core_fetch_board_data_api_1(struct ath12k_base *ab,
451 struct ath12k_board_data *bd,
452 char *filename)
453 {
454 bd->fw = ath12k_core_firmware_request(ab, filename);
455 if (IS_ERR(bd->fw))
456 return PTR_ERR(bd->fw);
457
458 bd->data = bd->fw->data;
459 bd->len = bd->fw->size;
460
461 return 0;
462 }
463
464 #define BOARD_NAME_SIZE 200
ath12k_core_fetch_bdf(struct ath12k_base * ab,struct ath12k_board_data * bd)465 int ath12k_core_fetch_bdf(struct ath12k_base *ab, struct ath12k_board_data *bd)
466 {
467 char boardname[BOARD_NAME_SIZE], fallback_boardname[BOARD_NAME_SIZE];
468 char *filename, filepath[100];
469 int bd_api;
470 int ret;
471
472 filename = ATH12K_BOARD_API2_FILE;
473
474 ret = ath12k_core_create_board_name(ab, boardname, sizeof(boardname));
475 if (ret) {
476 ath12k_err(ab, "failed to create board name: %d", ret);
477 return ret;
478 }
479
480 bd_api = 2;
481 ret = ath12k_core_fetch_board_data_api_n(ab, bd, boardname,
482 ATH12K_BD_IE_BOARD,
483 ATH12K_BD_IE_BOARD_NAME,
484 ATH12K_BD_IE_BOARD_DATA);
485 if (!ret)
486 goto success;
487
488 ret = ath12k_core_create_fallback_board_name(ab, fallback_boardname,
489 sizeof(fallback_boardname));
490 if (ret) {
491 ath12k_err(ab, "failed to create fallback board name: %d", ret);
492 return ret;
493 }
494
495 ret = ath12k_core_fetch_board_data_api_n(ab, bd, fallback_boardname,
496 ATH12K_BD_IE_BOARD,
497 ATH12K_BD_IE_BOARD_NAME,
498 ATH12K_BD_IE_BOARD_DATA);
499 if (!ret)
500 goto success;
501
502 bd_api = 1;
503 ret = ath12k_core_fetch_board_data_api_1(ab, bd, ATH12K_DEFAULT_BOARD_FILE);
504 if (ret) {
505 ath12k_core_create_firmware_path(ab, filename,
506 filepath, sizeof(filepath));
507 ath12k_err(ab, "failed to fetch board data for %s from %s\n",
508 boardname, filepath);
509 if (memcmp(boardname, fallback_boardname, strlen(boardname)))
510 ath12k_err(ab, "failed to fetch board data for %s from %s\n",
511 fallback_boardname, filepath);
512
513 ath12k_err(ab, "failed to fetch board.bin from %s\n",
514 ab->hw_params->fw.dir);
515 return ret;
516 }
517
518 success:
519 ath12k_dbg(ab, ATH12K_DBG_BOOT, "using board api %d\n", bd_api);
520 return 0;
521 }
522
ath12k_core_fetch_regdb(struct ath12k_base * ab,struct ath12k_board_data * bd)523 int ath12k_core_fetch_regdb(struct ath12k_base *ab, struct ath12k_board_data *bd)
524 {
525 char boardname[BOARD_NAME_SIZE], default_boardname[BOARD_NAME_SIZE];
526 int ret;
527
528 ret = ath12k_core_create_board_name(ab, boardname, BOARD_NAME_SIZE);
529 if (ret) {
530 ath12k_dbg(ab, ATH12K_DBG_BOOT,
531 "failed to create board name for regdb: %d", ret);
532 goto exit;
533 }
534
535 ret = ath12k_core_fetch_board_data_api_n(ab, bd, boardname,
536 ATH12K_BD_IE_REGDB,
537 ATH12K_BD_IE_REGDB_NAME,
538 ATH12K_BD_IE_REGDB_DATA);
539 if (!ret)
540 goto exit;
541
542 ret = ath12k_core_create_bus_type_board_name(ab, default_boardname,
543 BOARD_NAME_SIZE);
544 if (ret) {
545 ath12k_dbg(ab, ATH12K_DBG_BOOT,
546 "failed to create default board name for regdb: %d", ret);
547 goto exit;
548 }
549
550 ret = ath12k_core_fetch_board_data_api_n(ab, bd, default_boardname,
551 ATH12K_BD_IE_REGDB,
552 ATH12K_BD_IE_REGDB_NAME,
553 ATH12K_BD_IE_REGDB_DATA);
554 if (!ret)
555 goto exit;
556
557 ret = ath12k_core_fetch_board_data_api_1(ab, bd, ATH12K_REGDB_FILE_NAME);
558 if (ret)
559 ath12k_dbg(ab, ATH12K_DBG_BOOT, "failed to fetch %s from %s\n",
560 ATH12K_REGDB_FILE_NAME, ab->hw_params->fw.dir);
561
562 exit:
563 if (!ret)
564 ath12k_dbg(ab, ATH12K_DBG_BOOT, "fetched regdb\n");
565
566 return ret;
567 }
568
ath12k_core_get_max_station_per_radio(struct ath12k_base * ab)569 u32 ath12k_core_get_max_station_per_radio(struct ath12k_base *ab)
570 {
571 if (ab->num_radios == 2)
572 return TARGET_NUM_STATIONS_DBS;
573 else if (ab->num_radios == 3)
574 return TARGET_NUM_PEERS_PDEV_DBS_SBS;
575 return TARGET_NUM_STATIONS_SINGLE;
576 }
577
ath12k_core_get_max_peers_per_radio(struct ath12k_base * ab)578 u32 ath12k_core_get_max_peers_per_radio(struct ath12k_base *ab)
579 {
580 if (ab->num_radios == 2)
581 return TARGET_NUM_PEERS_PDEV_DBS;
582 else if (ab->num_radios == 3)
583 return TARGET_NUM_PEERS_PDEV_DBS_SBS;
584 return TARGET_NUM_PEERS_PDEV_SINGLE;
585 }
586
ath12k_core_get_max_num_tids(struct ath12k_base * ab)587 u32 ath12k_core_get_max_num_tids(struct ath12k_base *ab)
588 {
589 if (ab->num_radios == 2)
590 return TARGET_NUM_TIDS(DBS);
591 else if (ab->num_radios == 3)
592 return TARGET_NUM_TIDS(DBS_SBS);
593 return TARGET_NUM_TIDS(SINGLE);
594 }
595
ath12k_core_stop(struct ath12k_base * ab)596 static void ath12k_core_stop(struct ath12k_base *ab)
597 {
598 if (!test_bit(ATH12K_FLAG_CRASH_FLUSH, &ab->dev_flags))
599 ath12k_qmi_firmware_stop(ab);
600
601 ath12k_acpi_stop(ab);
602
603 ath12k_hif_stop(ab);
604 ath12k_wmi_detach(ab);
605 ath12k_dp_rx_pdev_reo_cleanup(ab);
606
607 /* De-Init of components as needed */
608 }
609
ath12k_core_check_bdfext(const struct dmi_header * hdr,void * data)610 static void ath12k_core_check_bdfext(const struct dmi_header *hdr, void *data)
611 {
612 struct ath12k_base *ab = data;
613 const char *magic = ATH12K_SMBIOS_BDF_EXT_MAGIC;
614 struct ath12k_smbios_bdf *smbios = (struct ath12k_smbios_bdf *)hdr;
615 ssize_t copied;
616 size_t len;
617 int i;
618
619 if (ab->qmi.target.bdf_ext[0] != '\0')
620 return;
621
622 if (hdr->type != ATH12K_SMBIOS_BDF_EXT_TYPE)
623 return;
624
625 if (hdr->length != ATH12K_SMBIOS_BDF_EXT_LENGTH) {
626 ath12k_dbg(ab, ATH12K_DBG_BOOT,
627 "wrong smbios bdf ext type length (%d).\n",
628 hdr->length);
629 return;
630 }
631
632 if (!smbios->bdf_enabled) {
633 ath12k_dbg(ab, ATH12K_DBG_BOOT, "bdf variant name not found.\n");
634 return;
635 }
636
637 /* Only one string exists (per spec) */
638 if (memcmp(smbios->bdf_ext, magic, strlen(magic)) != 0) {
639 ath12k_dbg(ab, ATH12K_DBG_BOOT,
640 "bdf variant magic does not match.\n");
641 return;
642 }
643
644 len = min_t(size_t,
645 strlen(smbios->bdf_ext), sizeof(ab->qmi.target.bdf_ext));
646 for (i = 0; i < len; i++) {
647 if (!isascii(smbios->bdf_ext[i]) || !isprint(smbios->bdf_ext[i])) {
648 ath12k_dbg(ab, ATH12K_DBG_BOOT,
649 "bdf variant name contains non ascii chars.\n");
650 return;
651 }
652 }
653
654 /* Copy extension name without magic prefix */
655 copied = strscpy(ab->qmi.target.bdf_ext, smbios->bdf_ext + strlen(magic),
656 sizeof(ab->qmi.target.bdf_ext));
657 if (copied < 0) {
658 ath12k_dbg(ab, ATH12K_DBG_BOOT,
659 "bdf variant string is longer than the buffer can accommodate\n");
660 return;
661 }
662
663 ath12k_dbg(ab, ATH12K_DBG_BOOT,
664 "found and validated bdf variant smbios_type 0x%x bdf %s\n",
665 ATH12K_SMBIOS_BDF_EXT_TYPE, ab->qmi.target.bdf_ext);
666 }
667
ath12k_core_check_smbios(struct ath12k_base * ab)668 int ath12k_core_check_smbios(struct ath12k_base *ab)
669 {
670 ab->qmi.target.bdf_ext[0] = '\0';
671 dmi_walk(ath12k_core_check_bdfext, ab);
672
673 if (ab->qmi.target.bdf_ext[0] == '\0')
674 return -ENODATA;
675
676 return 0;
677 }
678
ath12k_core_soc_create(struct ath12k_base * ab)679 static int ath12k_core_soc_create(struct ath12k_base *ab)
680 {
681 int ret;
682
683 ret = ath12k_qmi_init_service(ab);
684 if (ret) {
685 ath12k_err(ab, "failed to initialize qmi :%d\n", ret);
686 return ret;
687 }
688
689 ath12k_debugfs_soc_create(ab);
690
691 ret = ath12k_hif_power_up(ab);
692 if (ret) {
693 ath12k_err(ab, "failed to power up :%d\n", ret);
694 goto err_qmi_deinit;
695 }
696
697 return 0;
698
699 err_qmi_deinit:
700 ath12k_debugfs_soc_destroy(ab);
701 ath12k_qmi_deinit_service(ab);
702 return ret;
703 }
704
ath12k_core_soc_destroy(struct ath12k_base * ab)705 static void ath12k_core_soc_destroy(struct ath12k_base *ab)
706 {
707 ath12k_dp_free(ab);
708 ath12k_reg_free(ab);
709 ath12k_debugfs_soc_destroy(ab);
710 ath12k_qmi_deinit_service(ab);
711 }
712
ath12k_core_pdev_create(struct ath12k_base * ab)713 static int ath12k_core_pdev_create(struct ath12k_base *ab)
714 {
715 int ret;
716
717 ret = ath12k_mac_register(ab);
718 if (ret) {
719 ath12k_err(ab, "failed register the radio with mac80211: %d\n", ret);
720 return ret;
721 }
722
723 ret = ath12k_dp_pdev_alloc(ab);
724 if (ret) {
725 ath12k_err(ab, "failed to attach DP pdev: %d\n", ret);
726 goto err_mac_unregister;
727 }
728
729 return 0;
730
731 err_mac_unregister:
732 ath12k_mac_unregister(ab);
733
734 return ret;
735 }
736
ath12k_core_pdev_destroy(struct ath12k_base * ab)737 static void ath12k_core_pdev_destroy(struct ath12k_base *ab)
738 {
739 ath12k_mac_unregister(ab);
740 ath12k_hif_irq_disable(ab);
741 ath12k_dp_pdev_free(ab);
742 }
743
ath12k_core_start(struct ath12k_base * ab,enum ath12k_firmware_mode mode)744 static int ath12k_core_start(struct ath12k_base *ab,
745 enum ath12k_firmware_mode mode)
746 {
747 int ret;
748
749 ret = ath12k_wmi_attach(ab);
750 if (ret) {
751 ath12k_err(ab, "failed to attach wmi: %d\n", ret);
752 return ret;
753 }
754
755 ret = ath12k_htc_init(ab);
756 if (ret) {
757 ath12k_err(ab, "failed to init htc: %d\n", ret);
758 goto err_wmi_detach;
759 }
760
761 ret = ath12k_hif_start(ab);
762 if (ret) {
763 ath12k_err(ab, "failed to start HIF: %d\n", ret);
764 goto err_wmi_detach;
765 }
766
767 ret = ath12k_htc_wait_target(&ab->htc);
768 if (ret) {
769 ath12k_err(ab, "failed to connect to HTC: %d\n", ret);
770 goto err_hif_stop;
771 }
772
773 ret = ath12k_dp_htt_connect(&ab->dp);
774 if (ret) {
775 ath12k_err(ab, "failed to connect to HTT: %d\n", ret);
776 goto err_hif_stop;
777 }
778
779 ret = ath12k_wmi_connect(ab);
780 if (ret) {
781 ath12k_err(ab, "failed to connect wmi: %d\n", ret);
782 goto err_hif_stop;
783 }
784
785 ret = ath12k_htc_start(&ab->htc);
786 if (ret) {
787 ath12k_err(ab, "failed to start HTC: %d\n", ret);
788 goto err_hif_stop;
789 }
790
791 ret = ath12k_wmi_wait_for_service_ready(ab);
792 if (ret) {
793 ath12k_err(ab, "failed to receive wmi service ready event: %d\n",
794 ret);
795 goto err_hif_stop;
796 }
797
798 ret = ath12k_mac_allocate(ab);
799 if (ret) {
800 ath12k_err(ab, "failed to create new hw device with mac80211 :%d\n",
801 ret);
802 goto err_hif_stop;
803 }
804
805 ath12k_dp_cc_config(ab);
806
807 ret = ath12k_dp_rx_pdev_reo_setup(ab);
808 if (ret) {
809 ath12k_err(ab, "failed to initialize reo destination rings: %d\n", ret);
810 goto err_mac_destroy;
811 }
812
813 ath12k_dp_hal_rx_desc_init(ab);
814
815 ret = ath12k_wmi_cmd_init(ab);
816 if (ret) {
817 ath12k_err(ab, "failed to send wmi init cmd: %d\n", ret);
818 goto err_reo_cleanup;
819 }
820
821 ret = ath12k_wmi_wait_for_unified_ready(ab);
822 if (ret) {
823 ath12k_err(ab, "failed to receive wmi unified ready event: %d\n",
824 ret);
825 goto err_reo_cleanup;
826 }
827
828 /* put hardware to DBS mode */
829 if (ab->hw_params->single_pdev_only) {
830 ret = ath12k_wmi_set_hw_mode(ab, WMI_HOST_HW_MODE_DBS);
831 if (ret) {
832 ath12k_err(ab, "failed to send dbs mode: %d\n", ret);
833 goto err_reo_cleanup;
834 }
835 }
836
837 ret = ath12k_dp_tx_htt_h2t_ver_req_msg(ab);
838 if (ret) {
839 ath12k_err(ab, "failed to send htt version request message: %d\n",
840 ret);
841 goto err_reo_cleanup;
842 }
843
844 ret = ath12k_acpi_start(ab);
845 if (ret)
846 /* ACPI is optional so continue in case of an error */
847 ath12k_dbg(ab, ATH12K_DBG_BOOT, "acpi failed: %d\n", ret);
848
849 return 0;
850
851 err_reo_cleanup:
852 ath12k_dp_rx_pdev_reo_cleanup(ab);
853 err_mac_destroy:
854 ath12k_mac_destroy(ab);
855 err_hif_stop:
856 ath12k_hif_stop(ab);
857 err_wmi_detach:
858 ath12k_wmi_detach(ab);
859 return ret;
860 }
861
ath12k_core_start_firmware(struct ath12k_base * ab,enum ath12k_firmware_mode mode)862 static int ath12k_core_start_firmware(struct ath12k_base *ab,
863 enum ath12k_firmware_mode mode)
864 {
865 int ret;
866
867 ath12k_ce_get_shadow_config(ab, &ab->qmi.ce_cfg.shadow_reg_v3,
868 &ab->qmi.ce_cfg.shadow_reg_v3_len);
869
870 ret = ath12k_qmi_firmware_start(ab, mode);
871 if (ret) {
872 ath12k_err(ab, "failed to send firmware start: %d\n", ret);
873 return ret;
874 }
875
876 return ret;
877 }
878
ath12k_core_qmi_firmware_ready(struct ath12k_base * ab)879 int ath12k_core_qmi_firmware_ready(struct ath12k_base *ab)
880 {
881 int ret;
882
883 ret = ath12k_core_start_firmware(ab, ATH12K_FIRMWARE_MODE_NORMAL);
884 if (ret) {
885 ath12k_err(ab, "failed to start firmware: %d\n", ret);
886 return ret;
887 }
888
889 ret = ath12k_ce_init_pipes(ab);
890 if (ret) {
891 ath12k_err(ab, "failed to initialize CE: %d\n", ret);
892 goto err_firmware_stop;
893 }
894
895 ret = ath12k_dp_alloc(ab);
896 if (ret) {
897 ath12k_err(ab, "failed to init DP: %d\n", ret);
898 goto err_firmware_stop;
899 }
900
901 mutex_lock(&ab->core_lock);
902 ret = ath12k_core_start(ab, ATH12K_FIRMWARE_MODE_NORMAL);
903 if (ret) {
904 ath12k_err(ab, "failed to start core: %d\n", ret);
905 goto err_dp_free;
906 }
907
908 ret = ath12k_core_pdev_create(ab);
909 if (ret) {
910 ath12k_err(ab, "failed to create pdev core: %d\n", ret);
911 goto err_core_stop;
912 }
913 ath12k_hif_irq_enable(ab);
914
915 ret = ath12k_core_rfkill_config(ab);
916 if (ret && ret != -EOPNOTSUPP) {
917 ath12k_err(ab, "failed to config rfkill: %d\n", ret);
918 goto err_core_pdev_destroy;
919 }
920
921 mutex_unlock(&ab->core_lock);
922
923 return 0;
924
925 err_core_pdev_destroy:
926 ath12k_core_pdev_destroy(ab);
927 err_core_stop:
928 ath12k_core_stop(ab);
929 ath12k_mac_destroy(ab);
930 err_dp_free:
931 ath12k_dp_free(ab);
932 mutex_unlock(&ab->core_lock);
933 err_firmware_stop:
934 ath12k_qmi_firmware_stop(ab);
935
936 return ret;
937 }
938
ath12k_core_reconfigure_on_crash(struct ath12k_base * ab)939 static int ath12k_core_reconfigure_on_crash(struct ath12k_base *ab)
940 {
941 int ret;
942
943 mutex_lock(&ab->core_lock);
944 ath12k_dp_pdev_free(ab);
945 ath12k_ce_cleanup_pipes(ab);
946 ath12k_wmi_detach(ab);
947 ath12k_dp_rx_pdev_reo_cleanup(ab);
948 mutex_unlock(&ab->core_lock);
949
950 ath12k_dp_free(ab);
951 ath12k_hal_srng_deinit(ab);
952
953 ab->free_vdev_map = (1LL << (ab->num_radios * TARGET_NUM_VDEVS)) - 1;
954
955 ret = ath12k_hal_srng_init(ab);
956 if (ret)
957 return ret;
958
959 clear_bit(ATH12K_FLAG_CRASH_FLUSH, &ab->dev_flags);
960
961 ret = ath12k_core_qmi_firmware_ready(ab);
962 if (ret)
963 goto err_hal_srng_deinit;
964
965 clear_bit(ATH12K_FLAG_RECOVERY, &ab->dev_flags);
966
967 return 0;
968
969 err_hal_srng_deinit:
970 ath12k_hal_srng_deinit(ab);
971 return ret;
972 }
973
ath12k_rfkill_work(struct work_struct * work)974 static void ath12k_rfkill_work(struct work_struct *work)
975 {
976 struct ath12k_base *ab = container_of(work, struct ath12k_base, rfkill_work);
977 struct ath12k *ar;
978 struct ath12k_hw *ah;
979 struct ieee80211_hw *hw;
980 bool rfkill_radio_on;
981 int i, j;
982
983 spin_lock_bh(&ab->base_lock);
984 rfkill_radio_on = ab->rfkill_radio_on;
985 spin_unlock_bh(&ab->base_lock);
986
987 for (i = 0; i < ab->num_hw; i++) {
988 ah = ab->ah[i];
989 if (!ah)
990 continue;
991
992 for (j = 0; j < ah->num_radio; j++) {
993 ar = &ah->radio[j];
994 if (!ar)
995 continue;
996
997 ath12k_mac_rfkill_enable_radio(ar, rfkill_radio_on);
998 }
999
1000 hw = ah->hw;
1001 wiphy_rfkill_set_hw_state(hw->wiphy, !rfkill_radio_on);
1002 }
1003 }
1004
ath12k_core_halt(struct ath12k * ar)1005 void ath12k_core_halt(struct ath12k *ar)
1006 {
1007 struct list_head *pos, *n;
1008 struct ath12k_base *ab = ar->ab;
1009
1010 lockdep_assert_held(&ar->conf_mutex);
1011
1012 ar->num_created_vdevs = 0;
1013 ar->allocated_vdev_map = 0;
1014
1015 ath12k_mac_scan_finish(ar);
1016 ath12k_mac_peer_cleanup_all(ar);
1017 cancel_delayed_work_sync(&ar->scan.timeout);
1018 cancel_work_sync(&ar->regd_update_work);
1019 cancel_work_sync(&ab->rfkill_work);
1020
1021 rcu_assign_pointer(ab->pdevs_active[ar->pdev_idx], NULL);
1022 synchronize_rcu();
1023
1024 spin_lock_bh(&ar->data_lock);
1025 list_for_each_safe(pos, n, &ar->arvifs)
1026 list_del_init(pos);
1027 spin_unlock_bh(&ar->data_lock);
1028
1029 idr_init(&ar->txmgmt_idr);
1030 }
1031
ath12k_core_pre_reconfigure_recovery(struct ath12k_base * ab)1032 static void ath12k_core_pre_reconfigure_recovery(struct ath12k_base *ab)
1033 {
1034 struct ath12k *ar;
1035 struct ath12k_hw *ah;
1036 int i, j;
1037
1038 spin_lock_bh(&ab->base_lock);
1039 ab->stats.fw_crash_counter++;
1040 spin_unlock_bh(&ab->base_lock);
1041
1042 if (ab->is_reset)
1043 set_bit(ATH12K_FLAG_CRASH_FLUSH, &ab->dev_flags);
1044
1045 for (i = 0; i < ab->num_hw; i++) {
1046 ah = ab->ah[i];
1047 if (!ah || ah->state == ATH12K_HW_STATE_OFF)
1048 continue;
1049
1050 ieee80211_stop_queues(ah->hw);
1051
1052 for (j = 0; j < ah->num_radio; j++) {
1053 ar = &ah->radio[j];
1054
1055 ath12k_mac_drain_tx(ar);
1056 complete(&ar->scan.started);
1057 complete(&ar->scan.completed);
1058 complete(&ar->scan.on_channel);
1059 complete(&ar->peer_assoc_done);
1060 complete(&ar->peer_delete_done);
1061 complete(&ar->install_key_done);
1062 complete(&ar->vdev_setup_done);
1063 complete(&ar->vdev_delete_done);
1064 complete(&ar->bss_survey_done);
1065
1066 wake_up(&ar->dp.tx_empty_waitq);
1067 idr_for_each(&ar->txmgmt_idr,
1068 ath12k_mac_tx_mgmt_pending_free, ar);
1069 idr_destroy(&ar->txmgmt_idr);
1070 wake_up(&ar->txmgmt_empty_waitq);
1071 }
1072 }
1073
1074 wake_up(&ab->wmi_ab.tx_credits_wq);
1075 wake_up(&ab->peer_mapping_wq);
1076 }
1077
ath12k_core_post_reconfigure_recovery(struct ath12k_base * ab)1078 static void ath12k_core_post_reconfigure_recovery(struct ath12k_base *ab)
1079 {
1080 struct ath12k_hw *ah;
1081 struct ath12k *ar;
1082 int i, j;
1083
1084 for (i = 0; i < ab->num_hw; i++) {
1085 ah = ab->ah[i];
1086 if (!ah || ah->state == ATH12K_HW_STATE_OFF)
1087 continue;
1088
1089 mutex_lock(&ah->hw_mutex);
1090
1091 switch (ah->state) {
1092 case ATH12K_HW_STATE_ON:
1093 ah->state = ATH12K_HW_STATE_RESTARTING;
1094
1095 for (j = 0; j < ah->num_radio; j++) {
1096 ar = &ah->radio[j];
1097
1098 mutex_lock(&ar->conf_mutex);
1099 ath12k_core_halt(ar);
1100 mutex_unlock(&ar->conf_mutex);
1101 }
1102
1103 break;
1104 case ATH12K_HW_STATE_OFF:
1105 ath12k_warn(ab,
1106 "cannot restart hw %d that hasn't been started\n",
1107 i);
1108 break;
1109 case ATH12K_HW_STATE_RESTARTING:
1110 break;
1111 case ATH12K_HW_STATE_RESTARTED:
1112 ah->state = ATH12K_HW_STATE_WEDGED;
1113 fallthrough;
1114 case ATH12K_HW_STATE_WEDGED:
1115 ath12k_warn(ab,
1116 "device is wedged, will not restart hw %d\n", i);
1117 break;
1118 }
1119
1120 mutex_unlock(&ah->hw_mutex);
1121 }
1122
1123 complete(&ab->driver_recovery);
1124 }
1125
ath12k_core_restart(struct work_struct * work)1126 static void ath12k_core_restart(struct work_struct *work)
1127 {
1128 struct ath12k_base *ab = container_of(work, struct ath12k_base, restart_work);
1129 struct ath12k_hw *ah;
1130 int ret, i;
1131
1132 ret = ath12k_core_reconfigure_on_crash(ab);
1133 if (ret) {
1134 ath12k_err(ab, "failed to reconfigure driver on crash recovery\n");
1135 return;
1136 }
1137
1138 if (ab->is_reset) {
1139 for (i = 0; i < ab->num_hw; i++) {
1140 ah = ab->ah[i];
1141 ieee80211_restart_hw(ah->hw);
1142 }
1143 }
1144
1145 complete(&ab->restart_completed);
1146 }
1147
ath12k_core_reset(struct work_struct * work)1148 static void ath12k_core_reset(struct work_struct *work)
1149 {
1150 struct ath12k_base *ab = container_of(work, struct ath12k_base, reset_work);
1151 int reset_count, fail_cont_count;
1152 long time_left;
1153
1154 if (!(test_bit(ATH12K_FLAG_REGISTERED, &ab->dev_flags))) {
1155 ath12k_warn(ab, "ignore reset dev flags 0x%lx\n", ab->dev_flags);
1156 return;
1157 }
1158
1159 /* Sometimes the recovery will fail and then the next all recovery fail,
1160 * this is to avoid infinite recovery since it can not recovery success
1161 */
1162 fail_cont_count = atomic_read(&ab->fail_cont_count);
1163
1164 if (fail_cont_count >= ATH12K_RESET_MAX_FAIL_COUNT_FINAL)
1165 return;
1166
1167 if (fail_cont_count >= ATH12K_RESET_MAX_FAIL_COUNT_FIRST &&
1168 time_before(jiffies, ab->reset_fail_timeout))
1169 return;
1170
1171 reset_count = atomic_inc_return(&ab->reset_count);
1172
1173 if (reset_count > 1) {
1174 /* Sometimes it happened another reset worker before the previous one
1175 * completed, then the second reset worker will destroy the previous one,
1176 * thus below is to avoid that.
1177 */
1178 ath12k_warn(ab, "already resetting count %d\n", reset_count);
1179
1180 reinit_completion(&ab->reset_complete);
1181 time_left = wait_for_completion_timeout(&ab->reset_complete,
1182 ATH12K_RESET_TIMEOUT_HZ);
1183 if (time_left) {
1184 ath12k_dbg(ab, ATH12K_DBG_BOOT, "to skip reset\n");
1185 atomic_dec(&ab->reset_count);
1186 return;
1187 }
1188
1189 ab->reset_fail_timeout = jiffies + ATH12K_RESET_FAIL_TIMEOUT_HZ;
1190 /* Record the continuous recovery fail count when recovery failed*/
1191 fail_cont_count = atomic_inc_return(&ab->fail_cont_count);
1192 }
1193
1194 ath12k_dbg(ab, ATH12K_DBG_BOOT, "reset starting\n");
1195
1196 ab->is_reset = true;
1197 atomic_set(&ab->recovery_count, 0);
1198
1199 ath12k_core_pre_reconfigure_recovery(ab);
1200
1201 ath12k_core_post_reconfigure_recovery(ab);
1202
1203 ath12k_dbg(ab, ATH12K_DBG_BOOT, "waiting recovery start...\n");
1204
1205 ath12k_hif_irq_disable(ab);
1206 ath12k_hif_ce_irq_disable(ab);
1207
1208 ath12k_hif_power_down(ab, false);
1209 ath12k_hif_power_up(ab);
1210
1211 ath12k_dbg(ab, ATH12K_DBG_BOOT, "reset started\n");
1212 }
1213
ath12k_core_pre_init(struct ath12k_base * ab)1214 int ath12k_core_pre_init(struct ath12k_base *ab)
1215 {
1216 int ret;
1217
1218 ret = ath12k_hw_init(ab);
1219 if (ret) {
1220 ath12k_err(ab, "failed to init hw params: %d\n", ret);
1221 return ret;
1222 }
1223
1224 ath12k_fw_map(ab);
1225
1226 return 0;
1227 }
1228
ath12k_core_panic_handler(struct notifier_block * nb,unsigned long action,void * data)1229 static int ath12k_core_panic_handler(struct notifier_block *nb,
1230 unsigned long action, void *data)
1231 {
1232 struct ath12k_base *ab = container_of(nb, struct ath12k_base,
1233 panic_nb);
1234
1235 return ath12k_hif_panic_handler(ab);
1236 }
1237
ath12k_core_panic_notifier_register(struct ath12k_base * ab)1238 static int ath12k_core_panic_notifier_register(struct ath12k_base *ab)
1239 {
1240 ab->panic_nb.notifier_call = ath12k_core_panic_handler;
1241
1242 return atomic_notifier_chain_register(&panic_notifier_list,
1243 &ab->panic_nb);
1244 }
1245
ath12k_core_panic_notifier_unregister(struct ath12k_base * ab)1246 static void ath12k_core_panic_notifier_unregister(struct ath12k_base *ab)
1247 {
1248 atomic_notifier_chain_unregister(&panic_notifier_list,
1249 &ab->panic_nb);
1250 }
1251
ath12k_core_init(struct ath12k_base * ab)1252 int ath12k_core_init(struct ath12k_base *ab)
1253 {
1254 int ret;
1255
1256 ret = ath12k_core_soc_create(ab);
1257 if (ret) {
1258 ath12k_err(ab, "failed to create soc core: %d\n", ret);
1259 return ret;
1260 }
1261
1262 ret = ath12k_core_panic_notifier_register(ab);
1263 if (ret)
1264 ath12k_warn(ab, "failed to register panic handler: %d\n", ret);
1265
1266 return 0;
1267 }
1268
ath12k_core_deinit(struct ath12k_base * ab)1269 void ath12k_core_deinit(struct ath12k_base *ab)
1270 {
1271 ath12k_core_panic_notifier_unregister(ab);
1272
1273 mutex_lock(&ab->core_lock);
1274
1275 ath12k_core_pdev_destroy(ab);
1276 ath12k_core_stop(ab);
1277
1278 mutex_unlock(&ab->core_lock);
1279
1280 ath12k_hif_power_down(ab, false);
1281 ath12k_mac_destroy(ab);
1282 ath12k_core_soc_destroy(ab);
1283 ath12k_fw_unmap(ab);
1284 }
1285
ath12k_core_free(struct ath12k_base * ab)1286 void ath12k_core_free(struct ath12k_base *ab)
1287 {
1288 timer_delete_sync(&ab->rx_replenish_retry);
1289 destroy_workqueue(ab->workqueue_aux);
1290 destroy_workqueue(ab->workqueue);
1291 kfree(ab);
1292 }
1293
ath12k_core_alloc(struct device * dev,size_t priv_size,enum ath12k_bus bus)1294 struct ath12k_base *ath12k_core_alloc(struct device *dev, size_t priv_size,
1295 enum ath12k_bus bus)
1296 {
1297 struct ath12k_base *ab;
1298
1299 ab = kzalloc(sizeof(*ab) + priv_size, GFP_KERNEL);
1300 if (!ab)
1301 return NULL;
1302
1303 init_completion(&ab->driver_recovery);
1304
1305 ab->workqueue = create_singlethread_workqueue("ath12k_wq");
1306 if (!ab->workqueue)
1307 goto err_sc_free;
1308
1309 ab->workqueue_aux = create_singlethread_workqueue("ath12k_aux_wq");
1310 if (!ab->workqueue_aux)
1311 goto err_free_wq;
1312
1313 mutex_init(&ab->core_lock);
1314 spin_lock_init(&ab->base_lock);
1315 init_completion(&ab->reset_complete);
1316
1317 INIT_LIST_HEAD(&ab->peers);
1318 init_waitqueue_head(&ab->peer_mapping_wq);
1319 init_waitqueue_head(&ab->wmi_ab.tx_credits_wq);
1320 INIT_WORK(&ab->restart_work, ath12k_core_restart);
1321 INIT_WORK(&ab->reset_work, ath12k_core_reset);
1322 INIT_WORK(&ab->rfkill_work, ath12k_rfkill_work);
1323
1324 timer_setup(&ab->rx_replenish_retry, ath12k_ce_rx_replenish_retry, 0);
1325 init_completion(&ab->htc_suspend);
1326 init_completion(&ab->restart_completed);
1327 init_completion(&ab->wow.wakeup_completed);
1328
1329 ab->dev = dev;
1330 ab->hif.bus = bus;
1331 ab->qmi.num_radios = U8_MAX;
1332 ab->mlo_capable_flags = ATH12K_INTRA_DEVICE_MLO_SUPPORT;
1333
1334 /* Device index used to identify the devices in a group.
1335 *
1336 * In Intra-device MLO, only one device present in a group,
1337 * so it is always zero.
1338 *
1339 * In Inter-device MLO, Multiple device present in a group,
1340 * expect non-zero value.
1341 */
1342 ab->device_id = 0;
1343
1344 return ab;
1345
1346 err_free_wq:
1347 destroy_workqueue(ab->workqueue);
1348 err_sc_free:
1349 kfree(ab);
1350 return NULL;
1351 }
1352
1353 MODULE_DESCRIPTION("Core module for Qualcomm Atheros 802.11be wireless LAN cards.");
1354 MODULE_LICENSE("Dual BSD/GPL");
1355