ath10k: drop the fw versioning sanity check
[cascardo/linux.git] / drivers / net / wireless / ath / ath10k / core.c
1 /*
2  * Copyright (c) 2005-2011 Atheros Communications Inc.
3  * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17
18 #include <linux/module.h>
19 #include <linux/firmware.h>
20
21 #include "core.h"
22 #include "mac.h"
23 #include "htc.h"
24 #include "hif.h"
25 #include "wmi.h"
26 #include "bmi.h"
27 #include "debug.h"
28 #include "htt.h"
29
30 unsigned int ath10k_debug_mask;
31 static bool uart_print;
32 static unsigned int ath10k_p2p;
33 module_param_named(debug_mask, ath10k_debug_mask, uint, 0644);
34 module_param(uart_print, bool, 0644);
35 module_param_named(p2p, ath10k_p2p, uint, 0644);
36 MODULE_PARM_DESC(debug_mask, "Debugging mask");
37 MODULE_PARM_DESC(uart_print, "Uart target debugging");
38 MODULE_PARM_DESC(p2p, "Enable ath10k P2P support");
39
40 static const struct ath10k_hw_params ath10k_hw_params_list[] = {
41         {
42                 .id = QCA988X_HW_2_0_VERSION,
43                 .name = "qca988x hw2.0",
44                 .patch_load_addr = QCA988X_HW_2_0_PATCH_LOAD_ADDR,
45                 .fw = {
46                         .dir = QCA988X_HW_2_0_FW_DIR,
47                         .fw = QCA988X_HW_2_0_FW_FILE,
48                         .otp = QCA988X_HW_2_0_OTP_FILE,
49                         .board = QCA988X_HW_2_0_BOARD_DATA_FILE,
50                 },
51         },
52 };
53
54 static void ath10k_send_suspend_complete(struct ath10k *ar)
55 {
56         ath10k_dbg(ATH10K_DBG_BOOT, "boot suspend complete\n");
57
58         ar->is_target_paused = true;
59         wake_up(&ar->event_queue);
60 }
61
62 static int ath10k_init_connect_htc(struct ath10k *ar)
63 {
64         int status;
65
66         status = ath10k_wmi_connect_htc_service(ar);
67         if (status)
68                 goto conn_fail;
69
70         /* Start HTC */
71         status = ath10k_htc_start(&ar->htc);
72         if (status)
73                 goto conn_fail;
74
75         /* Wait for WMI event to be ready */
76         status = ath10k_wmi_wait_for_service_ready(ar);
77         if (status <= 0) {
78                 ath10k_warn("wmi service ready event not received");
79                 status = -ETIMEDOUT;
80                 goto timeout;
81         }
82
83         ath10k_dbg(ATH10K_DBG_BOOT, "boot wmi ready\n");
84         return 0;
85
86 timeout:
87         ath10k_htc_stop(&ar->htc);
88 conn_fail:
89         return status;
90 }
91
92 static int ath10k_init_configure_target(struct ath10k *ar)
93 {
94         u32 param_host;
95         int ret;
96
97         /* tell target which HTC version it is used*/
98         ret = ath10k_bmi_write32(ar, hi_app_host_interest,
99                                  HTC_PROTOCOL_VERSION);
100         if (ret) {
101                 ath10k_err("settings HTC version failed\n");
102                 return ret;
103         }
104
105         /* set the firmware mode to STA/IBSS/AP */
106         ret = ath10k_bmi_read32(ar, hi_option_flag, &param_host);
107         if (ret) {
108                 ath10k_err("setting firmware mode (1/2) failed\n");
109                 return ret;
110         }
111
112         /* TODO following parameters need to be re-visited. */
113         /* num_device */
114         param_host |= (1 << HI_OPTION_NUM_DEV_SHIFT);
115         /* Firmware mode */
116         /* FIXME: Why FW_MODE_AP ??.*/
117         param_host |= (HI_OPTION_FW_MODE_AP << HI_OPTION_FW_MODE_SHIFT);
118         /* mac_addr_method */
119         param_host |= (1 << HI_OPTION_MAC_ADDR_METHOD_SHIFT);
120         /* firmware_bridge */
121         param_host |= (0 << HI_OPTION_FW_BRIDGE_SHIFT);
122         /* fwsubmode */
123         param_host |= (0 << HI_OPTION_FW_SUBMODE_SHIFT);
124
125         ret = ath10k_bmi_write32(ar, hi_option_flag, param_host);
126         if (ret) {
127                 ath10k_err("setting firmware mode (2/2) failed\n");
128                 return ret;
129         }
130
131         /* We do all byte-swapping on the host */
132         ret = ath10k_bmi_write32(ar, hi_be, 0);
133         if (ret) {
134                 ath10k_err("setting host CPU BE mode failed\n");
135                 return ret;
136         }
137
138         /* FW descriptor/Data swap flags */
139         ret = ath10k_bmi_write32(ar, hi_fw_swap, 0);
140
141         if (ret) {
142                 ath10k_err("setting FW data/desc swap flags failed\n");
143                 return ret;
144         }
145
146         return 0;
147 }
148
149 static const struct firmware *ath10k_fetch_fw_file(struct ath10k *ar,
150                                                    const char *dir,
151                                                    const char *file)
152 {
153         char filename[100];
154         const struct firmware *fw;
155         int ret;
156
157         if (file == NULL)
158                 return ERR_PTR(-ENOENT);
159
160         if (dir == NULL)
161                 dir = ".";
162
163         snprintf(filename, sizeof(filename), "%s/%s", dir, file);
164         ret = request_firmware(&fw, filename, ar->dev);
165         if (ret)
166                 return ERR_PTR(ret);
167
168         return fw;
169 }
170
171 static int ath10k_push_board_ext_data(struct ath10k *ar,
172                                       const struct firmware *fw)
173 {
174         u32 board_data_size = QCA988X_BOARD_DATA_SZ;
175         u32 board_ext_data_size = QCA988X_BOARD_EXT_DATA_SZ;
176         u32 board_ext_data_addr;
177         int ret;
178
179         ret = ath10k_bmi_read32(ar, hi_board_ext_data, &board_ext_data_addr);
180         if (ret) {
181                 ath10k_err("could not read board ext data addr (%d)\n", ret);
182                 return ret;
183         }
184
185         ath10k_dbg(ATH10K_DBG_BOOT,
186                    "boot push board extended data addr 0x%x\n",
187                    board_ext_data_addr);
188
189         if (board_ext_data_addr == 0)
190                 return 0;
191
192         if (fw->size != (board_data_size + board_ext_data_size)) {
193                 ath10k_err("invalid board (ext) data sizes %zu != %d+%d\n",
194                            fw->size, board_data_size, board_ext_data_size);
195                 return -EINVAL;
196         }
197
198         ret = ath10k_bmi_write_memory(ar, board_ext_data_addr,
199                                       fw->data + board_data_size,
200                                       board_ext_data_size);
201         if (ret) {
202                 ath10k_err("could not write board ext data (%d)\n", ret);
203                 return ret;
204         }
205
206         ret = ath10k_bmi_write32(ar, hi_board_ext_data_config,
207                                  (board_ext_data_size << 16) | 1);
208         if (ret) {
209                 ath10k_err("could not write board ext data bit (%d)\n", ret);
210                 return ret;
211         }
212
213         return 0;
214 }
215
216 static int ath10k_download_board_data(struct ath10k *ar)
217 {
218         const struct firmware *fw = ar->board_data;
219         u32 board_data_size = QCA988X_BOARD_DATA_SZ;
220         u32 address;
221         int ret;
222
223         ret = ath10k_push_board_ext_data(ar, fw);
224         if (ret) {
225                 ath10k_err("could not push board ext data (%d)\n", ret);
226                 goto exit;
227         }
228
229         ret = ath10k_bmi_read32(ar, hi_board_data, &address);
230         if (ret) {
231                 ath10k_err("could not read board data addr (%d)\n", ret);
232                 goto exit;
233         }
234
235         ret = ath10k_bmi_write_memory(ar, address, fw->data,
236                                       min_t(u32, board_data_size, fw->size));
237         if (ret) {
238                 ath10k_err("could not write board data (%d)\n", ret);
239                 goto exit;
240         }
241
242         ret = ath10k_bmi_write32(ar, hi_board_data_initialized, 1);
243         if (ret) {
244                 ath10k_err("could not write board data bit (%d)\n", ret);
245                 goto exit;
246         }
247
248 exit:
249         return ret;
250 }
251
252 static int ath10k_download_and_run_otp(struct ath10k *ar)
253 {
254         const struct firmware *fw = ar->otp;
255         u32 address = ar->hw_params.patch_load_addr;
256         u32 exec_param;
257         int ret;
258
259         /* OTP is optional */
260
261         if (!ar->otp)
262                 return 0;
263
264         ret = ath10k_bmi_fast_download(ar, address, fw->data, fw->size);
265         if (ret) {
266                 ath10k_err("could not write otp (%d)\n", ret);
267                 goto exit;
268         }
269
270         exec_param = 0;
271         ret = ath10k_bmi_execute(ar, address, &exec_param);
272         if (ret) {
273                 ath10k_err("could not execute otp (%d)\n", ret);
274                 goto exit;
275         }
276
277 exit:
278         return ret;
279 }
280
281 static int ath10k_download_fw(struct ath10k *ar)
282 {
283         const struct firmware *fw = ar->firmware;
284         u32 address;
285         int ret;
286
287         address = ar->hw_params.patch_load_addr;
288
289         ret = ath10k_bmi_fast_download(ar, address, fw->data, fw->size);
290         if (ret) {
291                 ath10k_err("could not write fw (%d)\n", ret);
292                 goto exit;
293         }
294
295 exit:
296         return ret;
297 }
298
299 static void ath10k_core_free_firmware_files(struct ath10k *ar)
300 {
301         if (ar->board_data && !IS_ERR(ar->board_data))
302                 release_firmware(ar->board_data);
303
304         if (ar->otp && !IS_ERR(ar->otp))
305                 release_firmware(ar->otp);
306
307         if (ar->firmware && !IS_ERR(ar->firmware))
308                 release_firmware(ar->firmware);
309
310         ar->board_data = NULL;
311         ar->otp = NULL;
312         ar->firmware = NULL;
313 }
314
315 static int ath10k_core_fetch_firmware_files(struct ath10k *ar)
316 {
317         int ret = 0;
318
319         if (ar->hw_params.fw.fw == NULL) {
320                 ath10k_err("firmware file not defined\n");
321                 return -EINVAL;
322         }
323
324         if (ar->hw_params.fw.board == NULL) {
325                 ath10k_err("board data file not defined");
326                 return -EINVAL;
327         }
328
329         ar->board_data = ath10k_fetch_fw_file(ar,
330                                               ar->hw_params.fw.dir,
331                                               ar->hw_params.fw.board);
332         if (IS_ERR(ar->board_data)) {
333                 ret = PTR_ERR(ar->board_data);
334                 ath10k_err("could not fetch board data (%d)\n", ret);
335                 goto err;
336         }
337
338         ar->firmware = ath10k_fetch_fw_file(ar,
339                                             ar->hw_params.fw.dir,
340                                             ar->hw_params.fw.fw);
341         if (IS_ERR(ar->firmware)) {
342                 ret = PTR_ERR(ar->firmware);
343                 ath10k_err("could not fetch firmware (%d)\n", ret);
344                 goto err;
345         }
346
347         /* OTP may be undefined. If so, don't fetch it at all */
348         if (ar->hw_params.fw.otp == NULL)
349                 return 0;
350
351         ar->otp = ath10k_fetch_fw_file(ar,
352                                        ar->hw_params.fw.dir,
353                                        ar->hw_params.fw.otp);
354         if (IS_ERR(ar->otp)) {
355                 ret = PTR_ERR(ar->otp);
356                 ath10k_err("could not fetch otp (%d)\n", ret);
357                 goto err;
358         }
359
360         return 0;
361
362 err:
363         ath10k_core_free_firmware_files(ar);
364         return ret;
365 }
366
367 static int ath10k_init_download_firmware(struct ath10k *ar)
368 {
369         int ret;
370
371         ret = ath10k_download_board_data(ar);
372         if (ret)
373                 return ret;
374
375         ret = ath10k_download_and_run_otp(ar);
376         if (ret)
377                 return ret;
378
379         ret = ath10k_download_fw(ar);
380         if (ret)
381                 return ret;
382
383         return ret;
384 }
385
386 static int ath10k_init_uart(struct ath10k *ar)
387 {
388         int ret;
389
390         /*
391          * Explicitly setting UART prints to zero as target turns it on
392          * based on scratch registers.
393          */
394         ret = ath10k_bmi_write32(ar, hi_serial_enable, 0);
395         if (ret) {
396                 ath10k_warn("could not disable UART prints (%d)\n", ret);
397                 return ret;
398         }
399
400         if (!uart_print) {
401                 ath10k_info("UART prints disabled\n");
402                 return 0;
403         }
404
405         ret = ath10k_bmi_write32(ar, hi_dbg_uart_txpin, 7);
406         if (ret) {
407                 ath10k_warn("could not enable UART prints (%d)\n", ret);
408                 return ret;
409         }
410
411         ret = ath10k_bmi_write32(ar, hi_serial_enable, 1);
412         if (ret) {
413                 ath10k_warn("could not enable UART prints (%d)\n", ret);
414                 return ret;
415         }
416
417         /* Set the UART baud rate to 19200. */
418         ret = ath10k_bmi_write32(ar, hi_desired_baud_rate, 19200);
419         if (ret) {
420                 ath10k_warn("could not set the baud rate (%d)\n", ret);
421                 return ret;
422         }
423
424         ath10k_info("UART prints enabled\n");
425         return 0;
426 }
427
428 static int ath10k_init_hw_params(struct ath10k *ar)
429 {
430         const struct ath10k_hw_params *uninitialized_var(hw_params);
431         int i;
432
433         for (i = 0; i < ARRAY_SIZE(ath10k_hw_params_list); i++) {
434                 hw_params = &ath10k_hw_params_list[i];
435
436                 if (hw_params->id == ar->target_version)
437                         break;
438         }
439
440         if (i == ARRAY_SIZE(ath10k_hw_params_list)) {
441                 ath10k_err("Unsupported hardware version: 0x%x\n",
442                            ar->target_version);
443                 return -EINVAL;
444         }
445
446         ar->hw_params = *hw_params;
447
448         ath10k_info("Hardware name %s version 0x%x\n",
449                     ar->hw_params.name, ar->target_version);
450
451         return 0;
452 }
453
454 static void ath10k_core_restart(struct work_struct *work)
455 {
456         struct ath10k *ar = container_of(work, struct ath10k, restart_work);
457
458         mutex_lock(&ar->conf_mutex);
459
460         switch (ar->state) {
461         case ATH10K_STATE_ON:
462                 ath10k_halt(ar);
463                 ar->state = ATH10K_STATE_RESTARTING;
464                 ieee80211_restart_hw(ar->hw);
465                 break;
466         case ATH10K_STATE_OFF:
467                 /* this can happen if driver is being unloaded */
468                 ath10k_warn("cannot restart a device that hasn't been started\n");
469                 break;
470         case ATH10K_STATE_RESTARTING:
471         case ATH10K_STATE_RESTARTED:
472                 ar->state = ATH10K_STATE_WEDGED;
473                 /* fall through */
474         case ATH10K_STATE_WEDGED:
475                 ath10k_warn("device is wedged, will not restart\n");
476                 break;
477         }
478
479         mutex_unlock(&ar->conf_mutex);
480 }
481
482 struct ath10k *ath10k_core_create(void *hif_priv, struct device *dev,
483                                   const struct ath10k_hif_ops *hif_ops)
484 {
485         struct ath10k *ar;
486
487         ar = ath10k_mac_create();
488         if (!ar)
489                 return NULL;
490
491         ar->ath_common.priv = ar;
492         ar->ath_common.hw = ar->hw;
493
494         ar->p2p = !!ath10k_p2p;
495         ar->dev = dev;
496
497         ar->hif.priv = hif_priv;
498         ar->hif.ops = hif_ops;
499
500         init_completion(&ar->scan.started);
501         init_completion(&ar->scan.completed);
502         init_completion(&ar->scan.on_channel);
503
504         init_completion(&ar->install_key_done);
505         init_completion(&ar->vdev_setup_done);
506
507         setup_timer(&ar->scan.timeout, ath10k_reset_scan, (unsigned long)ar);
508
509         ar->workqueue = create_singlethread_workqueue("ath10k_wq");
510         if (!ar->workqueue)
511                 goto err_wq;
512
513         mutex_init(&ar->conf_mutex);
514         spin_lock_init(&ar->data_lock);
515
516         INIT_LIST_HEAD(&ar->peers);
517         init_waitqueue_head(&ar->peer_mapping_wq);
518
519         init_completion(&ar->offchan_tx_completed);
520         INIT_WORK(&ar->offchan_tx_work, ath10k_offchan_tx_work);
521         skb_queue_head_init(&ar->offchan_tx_queue);
522
523         init_waitqueue_head(&ar->event_queue);
524
525         INIT_WORK(&ar->restart_work, ath10k_core_restart);
526
527         return ar;
528
529 err_wq:
530         ath10k_mac_destroy(ar);
531         return NULL;
532 }
533 EXPORT_SYMBOL(ath10k_core_create);
534
535 void ath10k_core_destroy(struct ath10k *ar)
536 {
537         flush_workqueue(ar->workqueue);
538         destroy_workqueue(ar->workqueue);
539
540         ath10k_mac_destroy(ar);
541 }
542 EXPORT_SYMBOL(ath10k_core_destroy);
543
544 int ath10k_core_start(struct ath10k *ar)
545 {
546         int status;
547
548         ath10k_bmi_start(ar);
549
550         if (ath10k_init_configure_target(ar)) {
551                 status = -EINVAL;
552                 goto err;
553         }
554
555         status = ath10k_init_download_firmware(ar);
556         if (status)
557                 goto err;
558
559         status = ath10k_init_uart(ar);
560         if (status)
561                 goto err;
562
563         ar->htc.htc_ops.target_send_suspend_complete =
564                 ath10k_send_suspend_complete;
565
566         status = ath10k_htc_init(ar);
567         if (status) {
568                 ath10k_err("could not init HTC (%d)\n", status);
569                 goto err;
570         }
571
572         status = ath10k_bmi_done(ar);
573         if (status)
574                 goto err;
575
576         status = ath10k_wmi_attach(ar);
577         if (status) {
578                 ath10k_err("WMI attach failed: %d\n", status);
579                 goto err;
580         }
581
582         status = ath10k_htc_wait_target(&ar->htc);
583         if (status)
584                 goto err_wmi_detach;
585
586         status = ath10k_htt_attach(ar);
587         if (status) {
588                 ath10k_err("could not attach htt (%d)\n", status);
589                 goto err_wmi_detach;
590         }
591
592         status = ath10k_init_connect_htc(ar);
593         if (status)
594                 goto err_htt_detach;
595
596         ath10k_info("firmware %s booted\n", ar->hw->wiphy->fw_version);
597
598         status = ath10k_wmi_cmd_init(ar);
599         if (status) {
600                 ath10k_err("could not send WMI init command (%d)\n", status);
601                 goto err_disconnect_htc;
602         }
603
604         status = ath10k_wmi_wait_for_unified_ready(ar);
605         if (status <= 0) {
606                 ath10k_err("wmi unified ready event not received\n");
607                 status = -ETIMEDOUT;
608                 goto err_disconnect_htc;
609         }
610
611         status = ath10k_htt_attach_target(&ar->htt);
612         if (status)
613                 goto err_disconnect_htc;
614
615         status = ath10k_debug_start(ar);
616         if (status)
617                 goto err_disconnect_htc;
618
619         ar->free_vdev_map = (1 << TARGET_NUM_VDEVS) - 1;
620
621         return 0;
622
623 err_disconnect_htc:
624         ath10k_htc_stop(&ar->htc);
625 err_htt_detach:
626         ath10k_htt_detach(&ar->htt);
627 err_wmi_detach:
628         ath10k_wmi_detach(ar);
629 err:
630         return status;
631 }
632 EXPORT_SYMBOL(ath10k_core_start);
633
634 void ath10k_core_stop(struct ath10k *ar)
635 {
636         ath10k_debug_stop(ar);
637         ath10k_htc_stop(&ar->htc);
638         ath10k_htt_detach(&ar->htt);
639         ath10k_wmi_detach(ar);
640 }
641 EXPORT_SYMBOL(ath10k_core_stop);
642
643 /* mac80211 manages fw/hw initialization through start/stop hooks. However in
644  * order to know what hw capabilities should be advertised to mac80211 it is
645  * necessary to load the firmware (and tear it down immediately since start
646  * hook will try to init it again) before registering */
647 static int ath10k_core_probe_fw(struct ath10k *ar)
648 {
649         struct bmi_target_info target_info;
650         int ret = 0;
651
652         ret = ath10k_hif_power_up(ar);
653         if (ret) {
654                 ath10k_err("could not start pci hif (%d)\n", ret);
655                 return ret;
656         }
657
658         memset(&target_info, 0, sizeof(target_info));
659         ret = ath10k_bmi_get_target_info(ar, &target_info);
660         if (ret) {
661                 ath10k_err("could not get target info (%d)\n", ret);
662                 ath10k_hif_power_down(ar);
663                 return ret;
664         }
665
666         ar->target_version = target_info.version;
667         ar->hw->wiphy->hw_version = target_info.version;
668
669         ret = ath10k_init_hw_params(ar);
670         if (ret) {
671                 ath10k_err("could not get hw params (%d)\n", ret);
672                 ath10k_hif_power_down(ar);
673                 return ret;
674         }
675
676         ret = ath10k_core_fetch_firmware_files(ar);
677         if (ret) {
678                 ath10k_err("could not fetch firmware files (%d)\n", ret);
679                 ath10k_hif_power_down(ar);
680                 return ret;
681         }
682
683         ret = ath10k_core_start(ar);
684         if (ret) {
685                 ath10k_err("could not init core (%d)\n", ret);
686                 ath10k_core_free_firmware_files(ar);
687                 ath10k_hif_power_down(ar);
688                 return ret;
689         }
690
691         ath10k_core_stop(ar);
692         ath10k_hif_power_down(ar);
693         return 0;
694 }
695
696 static int ath10k_core_check_chip_id(struct ath10k *ar)
697 {
698         u32 hw_revision = MS(ar->chip_id, SOC_CHIP_ID_REV);
699
700         ath10k_dbg(ATH10K_DBG_BOOT, "boot chip_id 0x%08x hw_revision 0x%x\n",
701                    ar->chip_id, hw_revision);
702
703         /* Check that we are not using hw1.0 (some of them have same pci id
704          * as hw2.0) before doing anything else as ath10k crashes horribly
705          * due to missing hw1.0 workarounds. */
706         switch (hw_revision) {
707         case QCA988X_HW_1_0_CHIP_ID_REV:
708                 ath10k_err("ERROR: qca988x hw1.0 is not supported\n");
709                 return -EOPNOTSUPP;
710
711         case QCA988X_HW_2_0_CHIP_ID_REV:
712                 /* known hardware revision, continue normally */
713                 return 0;
714
715         default:
716                 ath10k_warn("Warning: hardware revision unknown (0x%x), expect problems\n",
717                             ar->chip_id);
718                 return 0;
719         }
720
721         return 0;
722 }
723
724 int ath10k_core_register(struct ath10k *ar, u32 chip_id)
725 {
726         int status;
727
728         ar->chip_id = chip_id;
729
730         status = ath10k_core_check_chip_id(ar);
731         if (status) {
732                 ath10k_err("Unsupported chip id 0x%08x\n", ar->chip_id);
733                 return status;
734         }
735
736         status = ath10k_core_probe_fw(ar);
737         if (status) {
738                 ath10k_err("could not probe fw (%d)\n", status);
739                 return status;
740         }
741
742         status = ath10k_mac_register(ar);
743         if (status) {
744                 ath10k_err("could not register to mac80211 (%d)\n", status);
745                 goto err_release_fw;
746         }
747
748         status = ath10k_debug_create(ar);
749         if (status) {
750                 ath10k_err("unable to initialize debugfs\n");
751                 goto err_unregister_mac;
752         }
753
754         return 0;
755
756 err_unregister_mac:
757         ath10k_mac_unregister(ar);
758 err_release_fw:
759         ath10k_core_free_firmware_files(ar);
760         return status;
761 }
762 EXPORT_SYMBOL(ath10k_core_register);
763
764 void ath10k_core_unregister(struct ath10k *ar)
765 {
766         /* We must unregister from mac80211 before we stop HTC and HIF.
767          * Otherwise we will fail to submit commands to FW and mac80211 will be
768          * unhappy about callback failures. */
769         ath10k_mac_unregister(ar);
770
771         ath10k_core_free_firmware_files(ar);
772 }
773 EXPORT_SYMBOL(ath10k_core_unregister);
774
775 MODULE_AUTHOR("Qualcomm Atheros");
776 MODULE_DESCRIPTION("Core module for QCA988X PCIe devices.");
777 MODULE_LICENSE("Dual BSD/GPL");