Linux-libre 5.7.6-gnu
[librecmc/linux-libre.git] / drivers / net / wireless / ath / ath11k / core.c
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"
13 #include "dp_rx.h"
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_reject_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 /*(DEBLOBBED)*/ or /*(DEBLOBBED)*/ 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);
329         ath11k_dp_pdev_reo_cleanup(ab);
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
383         ret = ath11k_mac_register(ab);
384         if (ret) {
385                 ath11k_err(ab, "failed register the radio with mac80211: %d\n", ret);
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);
392                 goto err_mac_unregister;
393         }
394
395         ret = ath11k_thermal_register(ab);
396         if (ret) {
397                 ath11k_err(ab, "could not register thermal device: %d\n",
398                            ret);
399                 goto err_dp_pdev_free;
400         }
401
402         return 0;
403
404 err_dp_pdev_free:
405         ath11k_dp_pdev_free(ab);
406 err_mac_unregister:
407         ath11k_mac_unregister(ab);
408 err_pdev_debug:
409         ath11k_debug_pdev_destroy(ab);
410
411         return ret;
412 }
413
414 static void ath11k_core_pdev_destroy(struct ath11k_base *ab)
415 {
416         ath11k_thermal_unregister(ab);
417         ath11k_mac_unregister(ab);
418         ath11k_ahb_ext_irq_disable(ab);
419         ath11k_dp_pdev_free(ab);
420         ath11k_debug_pdev_destroy(ab);
421 }
422
423 static int ath11k_core_start(struct ath11k_base *ab,
424                              enum ath11k_firmware_mode mode)
425 {
426         int ret;
427
428         ret = ath11k_qmi_firmware_start(ab, mode);
429         if (ret) {
430                 ath11k_err(ab, "failed to attach wmi: %d\n", ret);
431                 return ret;
432         }
433
434         ret = ath11k_wmi_attach(ab);
435         if (ret) {
436                 ath11k_err(ab, "failed to attach wmi: %d\n", ret);
437                 goto err_firmware_stop;
438         }
439
440         ret = ath11k_htc_init(ab);
441         if (ret) {
442                 ath11k_err(ab, "failed to init htc: %d\n", ret);
443                 goto err_wmi_detach;
444         }
445
446         ret = ath11k_ahb_start(ab);
447         if (ret) {
448                 ath11k_err(ab, "failed to start HIF: %d\n", ret);
449                 goto err_wmi_detach;
450         }
451
452         ret = ath11k_htc_wait_target(&ab->htc);
453         if (ret) {
454                 ath11k_err(ab, "failed to connect to HTC: %d\n", ret);
455                 goto err_hif_stop;
456         }
457
458         ret = ath11k_dp_htt_connect(&ab->dp);
459         if (ret) {
460                 ath11k_err(ab, "failed to connect to HTT: %d\n", ret);
461                 goto err_hif_stop;
462         }
463
464         ret = ath11k_wmi_connect(ab);
465         if (ret) {
466                 ath11k_err(ab, "failed to connect wmi: %d\n", ret);
467                 goto err_hif_stop;
468         }
469
470         ret = ath11k_htc_start(&ab->htc);
471         if (ret) {
472                 ath11k_err(ab, "failed to start HTC: %d\n", ret);
473                 goto err_hif_stop;
474         }
475
476         ret = ath11k_wmi_wait_for_service_ready(ab);
477         if (ret) {
478                 ath11k_err(ab, "failed to receive wmi service ready event: %d\n",
479                            ret);
480                 goto err_hif_stop;
481         }
482
483         ret = ath11k_mac_allocate(ab);
484         if (ret) {
485                 ath11k_err(ab, "failed to create new hw device with mac80211 :%d\n",
486                            ret);
487                 goto err_hif_stop;
488         }
489
490         ath11k_dp_pdev_pre_alloc(ab);
491
492         ret = ath11k_dp_pdev_reo_setup(ab);
493         if (ret) {
494                 ath11k_err(ab, "failed to initialize reo destination rings: %d\n", ret);
495                 goto err_mac_destroy;
496         }
497
498         ret = ath11k_wmi_cmd_init(ab);
499         if (ret) {
500                 ath11k_err(ab, "failed to send wmi init cmd: %d\n", ret);
501                 goto err_reo_cleanup;
502         }
503
504         ret = ath11k_wmi_wait_for_unified_ready(ab);
505         if (ret) {
506                 ath11k_err(ab, "failed to receive wmi unified ready event: %d\n",
507                            ret);
508                 goto err_reo_cleanup;
509         }
510
511         ret = ath11k_dp_tx_htt_h2t_ver_req_msg(ab);
512         if (ret) {
513                 ath11k_err(ab, "failed to send htt version request message: %d\n",
514                            ret);
515                 goto err_reo_cleanup;
516         }
517
518         return 0;
519
520 err_reo_cleanup:
521         ath11k_dp_pdev_reo_cleanup(ab);
522 err_mac_destroy:
523         ath11k_mac_destroy(ab);
524 err_hif_stop:
525         ath11k_ahb_stop(ab);
526 err_wmi_detach:
527         ath11k_wmi_detach(ab);
528 err_firmware_stop:
529         ath11k_qmi_firmware_stop(ab);
530
531         return ret;
532 }
533
534 int ath11k_core_qmi_firmware_ready(struct ath11k_base *ab)
535 {
536         int ret;
537
538         ret = ath11k_ce_init_pipes(ab);
539         if (ret) {
540                 ath11k_err(ab, "failed to initialize CE: %d\n", ret);
541                 return ret;
542         }
543
544         ret = ath11k_dp_alloc(ab);
545         if (ret) {
546                 ath11k_err(ab, "failed to init DP: %d\n", ret);
547                 return ret;
548         }
549
550         mutex_lock(&ab->core_lock);
551         ret = ath11k_core_start(ab, ATH11K_FIRMWARE_MODE_NORMAL);
552         if (ret) {
553                 ath11k_err(ab, "failed to start core: %d\n", ret);
554                 goto err_dp_free;
555         }
556
557         ret = ath11k_core_pdev_create(ab);
558         if (ret) {
559                 ath11k_err(ab, "failed to create pdev core: %d\n", ret);
560                 goto err_core_stop;
561         }
562         ath11k_ahb_ext_irq_enable(ab);
563         mutex_unlock(&ab->core_lock);
564
565         return 0;
566
567 err_core_stop:
568         ath11k_core_stop(ab);
569         ath11k_mac_destroy(ab);
570 err_dp_free:
571         ath11k_dp_free(ab);
572         mutex_unlock(&ab->core_lock);
573         return ret;
574 }
575
576 static int ath11k_core_reconfigure_on_crash(struct ath11k_base *ab)
577 {
578         int ret;
579
580         mutex_lock(&ab->core_lock);
581         ath11k_thermal_unregister(ab);
582         ath11k_ahb_ext_irq_disable(ab);
583         ath11k_dp_pdev_free(ab);
584         ath11k_ahb_stop(ab);
585         ath11k_wmi_detach(ab);
586         ath11k_dp_pdev_reo_cleanup(ab);
587         mutex_unlock(&ab->core_lock);
588
589         ath11k_dp_free(ab);
590         ath11k_hal_srng_deinit(ab);
591
592         ab->free_vdev_map = (1LL << (ab->num_radios * TARGET_NUM_VDEVS)) - 1;
593
594         ret = ath11k_hal_srng_init(ab);
595         if (ret)
596                 return ret;
597
598         clear_bit(ATH11K_FLAG_CRASH_FLUSH, &ab->dev_flags);
599
600         ret = ath11k_core_qmi_firmware_ready(ab);
601         if (ret)
602                 goto err_hal_srng_deinit;
603
604         clear_bit(ATH11K_FLAG_RECOVERY, &ab->dev_flags);
605
606         return 0;
607
608 err_hal_srng_deinit:
609         ath11k_hal_srng_deinit(ab);
610         return ret;
611 }
612
613 void ath11k_core_halt(struct ath11k *ar)
614 {
615         struct ath11k_base *ab = ar->ab;
616
617         lockdep_assert_held(&ar->conf_mutex);
618
619         ar->num_created_vdevs = 0;
620         ar->allocated_vdev_map = 0;
621
622         ath11k_mac_scan_finish(ar);
623         ath11k_mac_peer_cleanup_all(ar);
624         cancel_delayed_work_sync(&ar->scan.timeout);
625         cancel_work_sync(&ar->regd_update_work);
626
627         rcu_assign_pointer(ab->pdevs_active[ar->pdev_idx], NULL);
628         synchronize_rcu();
629         INIT_LIST_HEAD(&ar->arvifs);
630         idr_init(&ar->txmgmt_idr);
631 }
632
633 static void ath11k_core_restart(struct work_struct *work)
634 {
635         struct ath11k_base *ab = container_of(work, struct ath11k_base, restart_work);
636         struct ath11k *ar;
637         struct ath11k_pdev *pdev;
638         int i, ret = 0;
639
640         spin_lock_bh(&ab->base_lock);
641         ab->stats.fw_crash_counter++;
642         spin_unlock_bh(&ab->base_lock);
643
644         for (i = 0; i < ab->num_radios; i++) {
645                 pdev = &ab->pdevs[i];
646                 ar = pdev->ar;
647                 if (!ar || ar->state == ATH11K_STATE_OFF)
648                         continue;
649
650                 ieee80211_stop_queues(ar->hw);
651                 ath11k_mac_drain_tx(ar);
652                 complete(&ar->scan.started);
653                 complete(&ar->scan.completed);
654                 complete(&ar->peer_assoc_done);
655                 complete(&ar->install_key_done);
656                 complete(&ar->vdev_setup_done);
657                 complete(&ar->bss_survey_done);
658                 complete(&ar->thermal.wmi_sync);
659
660                 wake_up(&ar->dp.tx_empty_waitq);
661                 idr_for_each(&ar->txmgmt_idr,
662                              ath11k_mac_tx_mgmt_pending_free, ar);
663                 idr_destroy(&ar->txmgmt_idr);
664         }
665
666         wake_up(&ab->wmi_ab.tx_credits_wq);
667         wake_up(&ab->peer_mapping_wq);
668
669         ret = ath11k_core_reconfigure_on_crash(ab);
670         if (ret) {
671                 ath11k_err(ab, "failed to reconfigure driver on crash recovery\n");
672                 return;
673         }
674
675         for (i = 0; i < ab->num_radios; i++) {
676                 pdev = &ab->pdevs[i];
677                 ar = pdev->ar;
678                 if (!ar || ar->state == ATH11K_STATE_OFF)
679                         continue;
680
681                 mutex_lock(&ar->conf_mutex);
682
683                 switch (ar->state) {
684                 case ATH11K_STATE_ON:
685                         ar->state = ATH11K_STATE_RESTARTING;
686                         ath11k_core_halt(ar);
687                         ieee80211_restart_hw(ar->hw);
688                         break;
689                 case ATH11K_STATE_OFF:
690                         ath11k_warn(ab,
691                                     "cannot restart radio %d that hasn't been started\n",
692                                     i);
693                         break;
694                 case ATH11K_STATE_RESTARTING:
695                         break;
696                 case ATH11K_STATE_RESTARTED:
697                         ar->state = ATH11K_STATE_WEDGED;
698                         /* fall through */
699                 case ATH11K_STATE_WEDGED:
700                         ath11k_warn(ab,
701                                     "device is wedged, will not restart radio %d\n", i);
702                         break;
703                 }
704                 mutex_unlock(&ar->conf_mutex);
705         }
706         complete(&ab->driver_recovery);
707 }
708
709 int ath11k_core_init(struct ath11k_base *ab)
710 {
711         struct device *dev = ab->dev;
712         struct rproc *prproc;
713         phandle rproc_phandle;
714         int ret;
715
716         if (of_property_read_u32(dev->of_node, "qcom,rproc", &rproc_phandle)) {
717                 ath11k_err(ab, "failed to get q6_rproc handle\n");
718                 return -ENOENT;
719         }
720
721         prproc = rproc_get_by_phandle(rproc_phandle);
722         if (!prproc) {
723                 ath11k_err(ab, "failed to get rproc\n");
724                 return -EINVAL;
725         }
726         ab->tgt_rproc = prproc;
727         ab->hw_params = ath11k_hw_params;
728
729         ret = ath11k_core_soc_create(ab);
730         if (ret) {
731                 ath11k_err(ab, "failed to create soc core: %d\n", ret);
732                 return ret;
733         }
734
735         return 0;
736 }
737
738 void ath11k_core_deinit(struct ath11k_base *ab)
739 {
740         mutex_lock(&ab->core_lock);
741
742         ath11k_core_pdev_destroy(ab);
743         ath11k_core_stop(ab);
744
745         mutex_unlock(&ab->core_lock);
746
747         ath11k_ahb_power_down(ab);
748         ath11k_mac_destroy(ab);
749         ath11k_core_soc_destroy(ab);
750 }
751
752 void ath11k_core_free(struct ath11k_base *ab)
753 {
754         kfree(ab);
755 }
756
757 struct ath11k_base *ath11k_core_alloc(struct device *dev)
758 {
759         struct ath11k_base *ab;
760
761         ab = kzalloc(sizeof(*ab), GFP_KERNEL);
762         if (!ab)
763                 return NULL;
764
765         init_completion(&ab->driver_recovery);
766
767         ab->workqueue = create_singlethread_workqueue("ath11k_wq");
768         if (!ab->workqueue)
769                 goto err_sc_free;
770
771         mutex_init(&ab->core_lock);
772         spin_lock_init(&ab->base_lock);
773
774         INIT_LIST_HEAD(&ab->peers);
775         init_waitqueue_head(&ab->peer_mapping_wq);
776         init_waitqueue_head(&ab->wmi_ab.tx_credits_wq);
777         INIT_WORK(&ab->restart_work, ath11k_core_restart);
778         timer_setup(&ab->rx_replenish_retry, ath11k_ce_rx_replenish_retry, 0);
779         ab->dev = dev;
780
781         return ab;
782
783 err_sc_free:
784         kfree(ab);
785         return NULL;
786 }
787
788 static int __init ath11k_init(void)
789 {
790         int ret;
791
792         ret = ath11k_ahb_init();
793         if (ret)
794                 printk(KERN_ERR "failed to register ath11k ahb driver: %d\n",
795                        ret);
796         return ret;
797 }
798 module_init(ath11k_init);
799
800 static void __exit ath11k_exit(void)
801 {
802         ath11k_ahb_exit();
803 }
804 module_exit(ath11k_exit);
805
806 MODULE_DESCRIPTION("Driver support for Qualcomm Technologies 802.11ax wireless chip");
807 MODULE_LICENSE("Dual BSD/GPL");