]> git.karo-electronics.de Git - linux-beck.git/blob - drivers/net/wireless/ath/ath10k/core.c
99a4e145c9b60559a0562d84ac335d9c97bb60a2
[linux-beck.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 #include <linux/of.h>
21
22 #include "core.h"
23 #include "mac.h"
24 #include "htc.h"
25 #include "hif.h"
26 #include "wmi.h"
27 #include "bmi.h"
28 #include "debug.h"
29 #include "htt.h"
30 #include "testmode.h"
31 #include "wmi-ops.h"
32
33 unsigned int ath10k_debug_mask;
34 static unsigned int ath10k_cryptmode_param;
35 static bool uart_print;
36 static bool skip_otp;
37 static bool rawmode;
38
39 module_param_named(debug_mask, ath10k_debug_mask, uint, 0644);
40 module_param_named(cryptmode, ath10k_cryptmode_param, uint, 0644);
41 module_param(uart_print, bool, 0644);
42 module_param(skip_otp, bool, 0644);
43 module_param(rawmode, bool, 0644);
44
45 MODULE_PARM_DESC(debug_mask, "Debugging mask");
46 MODULE_PARM_DESC(uart_print, "Uart target debugging");
47 MODULE_PARM_DESC(skip_otp, "Skip otp failure for calibration in testmode");
48 MODULE_PARM_DESC(cryptmode, "Crypto mode: 0-hardware, 1-software");
49 MODULE_PARM_DESC(rawmode, "Use raw 802.11 frame datapath");
50
51 static const struct ath10k_hw_params ath10k_hw_params_list[] = {
52         {
53                 .id = QCA988X_HW_2_0_VERSION,
54                 .name = "qca988x hw2.0",
55                 .patch_load_addr = QCA988X_HW_2_0_PATCH_LOAD_ADDR,
56                 .uart_pin = 7,
57                 .has_shifted_cc_wraparound = true,
58                 .otp_exe_param = 0,
59                 .channel_counters_freq_hz = 88000,
60                 .max_probe_resp_desc_thres = 0,
61                 .fw = {
62                         .dir = QCA988X_HW_2_0_FW_DIR,
63                         .fw = QCA988X_HW_2_0_FW_FILE,
64                         .otp = QCA988X_HW_2_0_OTP_FILE,
65                         .board = QCA988X_HW_2_0_BOARD_DATA_FILE,
66                         .board_size = QCA988X_BOARD_DATA_SZ,
67                         .board_ext_size = QCA988X_BOARD_EXT_DATA_SZ,
68                 },
69         },
70         {
71                 .id = QCA6174_HW_2_1_VERSION,
72                 .name = "qca6174 hw2.1",
73                 .patch_load_addr = QCA6174_HW_2_1_PATCH_LOAD_ADDR,
74                 .uart_pin = 6,
75                 .otp_exe_param = 0,
76                 .channel_counters_freq_hz = 88000,
77                 .max_probe_resp_desc_thres = 0,
78                 .fw = {
79                         .dir = QCA6174_HW_2_1_FW_DIR,
80                         .fw = QCA6174_HW_2_1_FW_FILE,
81                         .otp = QCA6174_HW_2_1_OTP_FILE,
82                         .board = QCA6174_HW_2_1_BOARD_DATA_FILE,
83                         .board_size = QCA6174_BOARD_DATA_SZ,
84                         .board_ext_size = QCA6174_BOARD_EXT_DATA_SZ,
85                 },
86         },
87         {
88                 .id = QCA6174_HW_3_0_VERSION,
89                 .name = "qca6174 hw3.0",
90                 .patch_load_addr = QCA6174_HW_3_0_PATCH_LOAD_ADDR,
91                 .uart_pin = 6,
92                 .otp_exe_param = 0,
93                 .channel_counters_freq_hz = 88000,
94                 .max_probe_resp_desc_thres = 0,
95                 .fw = {
96                         .dir = QCA6174_HW_3_0_FW_DIR,
97                         .fw = QCA6174_HW_3_0_FW_FILE,
98                         .otp = QCA6174_HW_3_0_OTP_FILE,
99                         .board = QCA6174_HW_3_0_BOARD_DATA_FILE,
100                         .board_size = QCA6174_BOARD_DATA_SZ,
101                         .board_ext_size = QCA6174_BOARD_EXT_DATA_SZ,
102                 },
103         },
104         {
105                 .id = QCA6174_HW_3_2_VERSION,
106                 .name = "qca6174 hw3.2",
107                 .patch_load_addr = QCA6174_HW_3_0_PATCH_LOAD_ADDR,
108                 .uart_pin = 6,
109                 .otp_exe_param = 0,
110                 .channel_counters_freq_hz = 88000,
111                 .max_probe_resp_desc_thres = 0,
112                 .fw = {
113                         /* uses same binaries as hw3.0 */
114                         .dir = QCA6174_HW_3_0_FW_DIR,
115                         .fw = QCA6174_HW_3_0_FW_FILE,
116                         .otp = QCA6174_HW_3_0_OTP_FILE,
117                         .board = QCA6174_HW_3_0_BOARD_DATA_FILE,
118                         .board_size = QCA6174_BOARD_DATA_SZ,
119                         .board_ext_size = QCA6174_BOARD_EXT_DATA_SZ,
120                 },
121         },
122         {
123                 .id = QCA99X0_HW_2_0_DEV_VERSION,
124                 .name = "qca99x0 hw2.0",
125                 .patch_load_addr = QCA99X0_HW_2_0_PATCH_LOAD_ADDR,
126                 .uart_pin = 7,
127                 .otp_exe_param = 0x00000700,
128                 .continuous_frag_desc = true,
129                 .channel_counters_freq_hz = 150000,
130                 .max_probe_resp_desc_thres = 24,
131                 .fw = {
132                         .dir = QCA99X0_HW_2_0_FW_DIR,
133                         .fw = QCA99X0_HW_2_0_FW_FILE,
134                         .otp = QCA99X0_HW_2_0_OTP_FILE,
135                         .board = QCA99X0_HW_2_0_BOARD_DATA_FILE,
136                         .board_size = QCA99X0_BOARD_DATA_SZ,
137                         .board_ext_size = QCA99X0_BOARD_EXT_DATA_SZ,
138                 },
139         },
140 };
141
142 static const char *const ath10k_core_fw_feature_str[] = {
143         [ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX] = "wmi-mgmt-rx",
144         [ATH10K_FW_FEATURE_WMI_10X] = "wmi-10.x",
145         [ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX] = "has-wmi-mgmt-tx",
146         [ATH10K_FW_FEATURE_NO_P2P] = "no-p2p",
147         [ATH10K_FW_FEATURE_WMI_10_2] = "wmi-10.2",
148         [ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT] = "multi-vif-ps",
149         [ATH10K_FW_FEATURE_WOWLAN_SUPPORT] = "wowlan",
150         [ATH10K_FW_FEATURE_IGNORE_OTP_RESULT] = "ignore-otp",
151         [ATH10K_FW_FEATURE_NO_NWIFI_DECAP_4ADDR_PADDING] = "no-4addr-pad",
152         [ATH10K_FW_FEATURE_SUPPORTS_SKIP_CLOCK_INIT] = "skip-clock-init",
153         [ATH10K_FW_FEATURE_RAW_MODE_SUPPORT] = "raw-mode",
154 };
155
156 static unsigned int ath10k_core_get_fw_feature_str(char *buf,
157                                                    size_t buf_len,
158                                                    enum ath10k_fw_features feat)
159 {
160         /* make sure that ath10k_core_fw_feature_str[] gets updated */
161         BUILD_BUG_ON(ARRAY_SIZE(ath10k_core_fw_feature_str) !=
162                      ATH10K_FW_FEATURE_COUNT);
163
164         if (feat >= ARRAY_SIZE(ath10k_core_fw_feature_str) ||
165             WARN_ON(!ath10k_core_fw_feature_str[feat])) {
166                 return scnprintf(buf, buf_len, "bit%d", feat);
167         }
168
169         return scnprintf(buf, buf_len, "%s", ath10k_core_fw_feature_str[feat]);
170 }
171
172 void ath10k_core_get_fw_features_str(struct ath10k *ar,
173                                      char *buf,
174                                      size_t buf_len)
175 {
176         unsigned int len = 0;
177         int i;
178
179         for (i = 0; i < ATH10K_FW_FEATURE_COUNT; i++) {
180                 if (test_bit(i, ar->fw_features)) {
181                         if (len > 0)
182                                 len += scnprintf(buf + len, buf_len - len, ",");
183
184                         len += ath10k_core_get_fw_feature_str(buf + len,
185                                                               buf_len - len,
186                                                               i);
187                 }
188         }
189 }
190
191 static void ath10k_send_suspend_complete(struct ath10k *ar)
192 {
193         ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot suspend complete\n");
194
195         complete(&ar->target_suspend);
196 }
197
198 static int ath10k_init_configure_target(struct ath10k *ar)
199 {
200         u32 param_host;
201         int ret;
202
203         /* tell target which HTC version it is used*/
204         ret = ath10k_bmi_write32(ar, hi_app_host_interest,
205                                  HTC_PROTOCOL_VERSION);
206         if (ret) {
207                 ath10k_err(ar, "settings HTC version failed\n");
208                 return ret;
209         }
210
211         /* set the firmware mode to STA/IBSS/AP */
212         ret = ath10k_bmi_read32(ar, hi_option_flag, &param_host);
213         if (ret) {
214                 ath10k_err(ar, "setting firmware mode (1/2) failed\n");
215                 return ret;
216         }
217
218         /* TODO following parameters need to be re-visited. */
219         /* num_device */
220         param_host |= (1 << HI_OPTION_NUM_DEV_SHIFT);
221         /* Firmware mode */
222         /* FIXME: Why FW_MODE_AP ??.*/
223         param_host |= (HI_OPTION_FW_MODE_AP << HI_OPTION_FW_MODE_SHIFT);
224         /* mac_addr_method */
225         param_host |= (1 << HI_OPTION_MAC_ADDR_METHOD_SHIFT);
226         /* firmware_bridge */
227         param_host |= (0 << HI_OPTION_FW_BRIDGE_SHIFT);
228         /* fwsubmode */
229         param_host |= (0 << HI_OPTION_FW_SUBMODE_SHIFT);
230
231         ret = ath10k_bmi_write32(ar, hi_option_flag, param_host);
232         if (ret) {
233                 ath10k_err(ar, "setting firmware mode (2/2) failed\n");
234                 return ret;
235         }
236
237         /* We do all byte-swapping on the host */
238         ret = ath10k_bmi_write32(ar, hi_be, 0);
239         if (ret) {
240                 ath10k_err(ar, "setting host CPU BE mode failed\n");
241                 return ret;
242         }
243
244         /* FW descriptor/Data swap flags */
245         ret = ath10k_bmi_write32(ar, hi_fw_swap, 0);
246
247         if (ret) {
248                 ath10k_err(ar, "setting FW data/desc swap flags failed\n");
249                 return ret;
250         }
251
252         /* Some devices have a special sanity check that verifies the PCI
253          * Device ID is written to this host interest var. It is known to be
254          * required to boot QCA6164.
255          */
256         ret = ath10k_bmi_write32(ar, hi_hci_uart_pwr_mgmt_params_ext,
257                                  ar->dev_id);
258         if (ret) {
259                 ath10k_err(ar, "failed to set pwr_mgmt_params: %d\n", ret);
260                 return ret;
261         }
262
263         return 0;
264 }
265
266 static const struct firmware *ath10k_fetch_fw_file(struct ath10k *ar,
267                                                    const char *dir,
268                                                    const char *file)
269 {
270         char filename[100];
271         const struct firmware *fw;
272         int ret;
273
274         if (file == NULL)
275                 return ERR_PTR(-ENOENT);
276
277         if (dir == NULL)
278                 dir = ".";
279
280         snprintf(filename, sizeof(filename), "%s/%s", dir, file);
281         ret = request_firmware(&fw, filename, ar->dev);
282         if (ret)
283                 return ERR_PTR(ret);
284
285         return fw;
286 }
287
288 static int ath10k_push_board_ext_data(struct ath10k *ar, const void *data,
289                                       size_t data_len)
290 {
291         u32 board_data_size = ar->hw_params.fw.board_size;
292         u32 board_ext_data_size = ar->hw_params.fw.board_ext_size;
293         u32 board_ext_data_addr;
294         int ret;
295
296         ret = ath10k_bmi_read32(ar, hi_board_ext_data, &board_ext_data_addr);
297         if (ret) {
298                 ath10k_err(ar, "could not read board ext data addr (%d)\n",
299                            ret);
300                 return ret;
301         }
302
303         ath10k_dbg(ar, ATH10K_DBG_BOOT,
304                    "boot push board extended data addr 0x%x\n",
305                    board_ext_data_addr);
306
307         if (board_ext_data_addr == 0)
308                 return 0;
309
310         if (data_len != (board_data_size + board_ext_data_size)) {
311                 ath10k_err(ar, "invalid board (ext) data sizes %zu != %d+%d\n",
312                            data_len, board_data_size, board_ext_data_size);
313                 return -EINVAL;
314         }
315
316         ret = ath10k_bmi_write_memory(ar, board_ext_data_addr,
317                                       data + board_data_size,
318                                       board_ext_data_size);
319         if (ret) {
320                 ath10k_err(ar, "could not write board ext data (%d)\n", ret);
321                 return ret;
322         }
323
324         ret = ath10k_bmi_write32(ar, hi_board_ext_data_config,
325                                  (board_ext_data_size << 16) | 1);
326         if (ret) {
327                 ath10k_err(ar, "could not write board ext data bit (%d)\n",
328                            ret);
329                 return ret;
330         }
331
332         return 0;
333 }
334
335 static int ath10k_download_board_data(struct ath10k *ar, const void *data,
336                                       size_t data_len)
337 {
338         u32 board_data_size = ar->hw_params.fw.board_size;
339         u32 address;
340         int ret;
341
342         ret = ath10k_push_board_ext_data(ar, data, data_len);
343         if (ret) {
344                 ath10k_err(ar, "could not push board ext data (%d)\n", ret);
345                 goto exit;
346         }
347
348         ret = ath10k_bmi_read32(ar, hi_board_data, &address);
349         if (ret) {
350                 ath10k_err(ar, "could not read board data addr (%d)\n", ret);
351                 goto exit;
352         }
353
354         ret = ath10k_bmi_write_memory(ar, address, data,
355                                       min_t(u32, board_data_size,
356                                             data_len));
357         if (ret) {
358                 ath10k_err(ar, "could not write board data (%d)\n", ret);
359                 goto exit;
360         }
361
362         ret = ath10k_bmi_write32(ar, hi_board_data_initialized, 1);
363         if (ret) {
364                 ath10k_err(ar, "could not write board data bit (%d)\n", ret);
365                 goto exit;
366         }
367
368 exit:
369         return ret;
370 }
371
372 static int ath10k_download_cal_file(struct ath10k *ar)
373 {
374         int ret;
375
376         if (!ar->cal_file)
377                 return -ENOENT;
378
379         if (IS_ERR(ar->cal_file))
380                 return PTR_ERR(ar->cal_file);
381
382         ret = ath10k_download_board_data(ar, ar->cal_file->data,
383                                          ar->cal_file->size);
384         if (ret) {
385                 ath10k_err(ar, "failed to download cal_file data: %d\n", ret);
386                 return ret;
387         }
388
389         ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot cal file downloaded\n");
390
391         return 0;
392 }
393
394 static int ath10k_download_cal_dt(struct ath10k *ar)
395 {
396         struct device_node *node;
397         int data_len;
398         void *data;
399         int ret;
400
401         node = ar->dev->of_node;
402         if (!node)
403                 /* Device Tree is optional, don't print any warnings if
404                  * there's no node for ath10k.
405                  */
406                 return -ENOENT;
407
408         if (!of_get_property(node, "qcom,ath10k-calibration-data",
409                              &data_len)) {
410                 /* The calibration data node is optional */
411                 return -ENOENT;
412         }
413
414         if (data_len != QCA988X_CAL_DATA_LEN) {
415                 ath10k_warn(ar, "invalid calibration data length in DT: %d\n",
416                             data_len);
417                 ret = -EMSGSIZE;
418                 goto out;
419         }
420
421         data = kmalloc(data_len, GFP_KERNEL);
422         if (!data) {
423                 ret = -ENOMEM;
424                 goto out;
425         }
426
427         ret = of_property_read_u8_array(node, "qcom,ath10k-calibration-data",
428                                         data, data_len);
429         if (ret) {
430                 ath10k_warn(ar, "failed to read calibration data from DT: %d\n",
431                             ret);
432                 goto out_free;
433         }
434
435         ret = ath10k_download_board_data(ar, data, data_len);
436         if (ret) {
437                 ath10k_warn(ar, "failed to download calibration data from Device Tree: %d\n",
438                             ret);
439                 goto out_free;
440         }
441
442         ret = 0;
443
444 out_free:
445         kfree(data);
446
447 out:
448         return ret;
449 }
450
451 static int ath10k_download_and_run_otp(struct ath10k *ar)
452 {
453         u32 result, address = ar->hw_params.patch_load_addr;
454         u32 bmi_otp_exe_param = ar->hw_params.otp_exe_param;
455         int ret;
456
457         ret = ath10k_download_board_data(ar, ar->board_data, ar->board_len);
458         if (ret) {
459                 ath10k_err(ar, "failed to download board data: %d\n", ret);
460                 return ret;
461         }
462
463         /* OTP is optional */
464
465         if (!ar->otp_data || !ar->otp_len) {
466                 ath10k_warn(ar, "Not running otp, calibration will be incorrect (otp-data %p otp_len %zd)!\n",
467                             ar->otp_data, ar->otp_len);
468                 return 0;
469         }
470
471         ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot upload otp to 0x%x len %zd\n",
472                    address, ar->otp_len);
473
474         ret = ath10k_bmi_fast_download(ar, address, ar->otp_data, ar->otp_len);
475         if (ret) {
476                 ath10k_err(ar, "could not write otp (%d)\n", ret);
477                 return ret;
478         }
479
480         ret = ath10k_bmi_execute(ar, address, bmi_otp_exe_param, &result);
481         if (ret) {
482                 ath10k_err(ar, "could not execute otp (%d)\n", ret);
483                 return ret;
484         }
485
486         ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot otp execute result %d\n", result);
487
488         if (!(skip_otp || test_bit(ATH10K_FW_FEATURE_IGNORE_OTP_RESULT,
489                                    ar->fw_features)) &&
490             result != 0) {
491                 ath10k_err(ar, "otp calibration failed: %d", result);
492                 return -EINVAL;
493         }
494
495         return 0;
496 }
497
498 static int ath10k_download_fw(struct ath10k *ar, enum ath10k_firmware_mode mode)
499 {
500         u32 address, data_len;
501         const char *mode_name;
502         const void *data;
503         int ret;
504
505         address = ar->hw_params.patch_load_addr;
506
507         switch (mode) {
508         case ATH10K_FIRMWARE_MODE_NORMAL:
509                 data = ar->firmware_data;
510                 data_len = ar->firmware_len;
511                 mode_name = "normal";
512                 ret = ath10k_swap_code_seg_configure(ar,
513                                                      ATH10K_SWAP_CODE_SEG_BIN_TYPE_FW);
514                 if (ret) {
515                         ath10k_err(ar, "failed to configure fw code swap: %d\n",
516                                    ret);
517                         return ret;
518                 }
519                 break;
520         case ATH10K_FIRMWARE_MODE_UTF:
521                 data = ar->testmode.utf->data;
522                 data_len = ar->testmode.utf->size;
523                 mode_name = "utf";
524                 break;
525         default:
526                 ath10k_err(ar, "unknown firmware mode: %d\n", mode);
527                 return -EINVAL;
528         }
529
530         ath10k_dbg(ar, ATH10K_DBG_BOOT,
531                    "boot uploading firmware image %p len %d mode %s\n",
532                    data, data_len, mode_name);
533
534         ret = ath10k_bmi_fast_download(ar, address, data, data_len);
535         if (ret) {
536                 ath10k_err(ar, "failed to download %s firmware: %d\n",
537                            mode_name, ret);
538                 return ret;
539         }
540
541         return ret;
542 }
543
544 static void ath10k_core_free_board_files(struct ath10k *ar)
545 {
546         if (!IS_ERR(ar->board))
547                 release_firmware(ar->board);
548
549         ar->board = NULL;
550         ar->board_data = NULL;
551         ar->board_len = 0;
552 }
553
554 static void ath10k_core_free_firmware_files(struct ath10k *ar)
555 {
556         if (!IS_ERR(ar->otp))
557                 release_firmware(ar->otp);
558
559         if (!IS_ERR(ar->firmware))
560                 release_firmware(ar->firmware);
561
562         if (!IS_ERR(ar->cal_file))
563                 release_firmware(ar->cal_file);
564
565         ath10k_swap_code_seg_release(ar);
566
567         ar->otp = NULL;
568         ar->otp_data = NULL;
569         ar->otp_len = 0;
570
571         ar->firmware = NULL;
572         ar->firmware_data = NULL;
573         ar->firmware_len = 0;
574
575         ar->cal_file = NULL;
576 }
577
578 static int ath10k_fetch_cal_file(struct ath10k *ar)
579 {
580         char filename[100];
581
582         /* cal-<bus>-<id>.bin */
583         scnprintf(filename, sizeof(filename), "cal-%s-%s.bin",
584                   ath10k_bus_str(ar->hif.bus), dev_name(ar->dev));
585
586         ar->cal_file = ath10k_fetch_fw_file(ar, ATH10K_FW_DIR, filename);
587         if (IS_ERR(ar->cal_file))
588                 /* calibration file is optional, don't print any warnings */
589                 return PTR_ERR(ar->cal_file);
590
591         ath10k_dbg(ar, ATH10K_DBG_BOOT, "found calibration file %s/%s\n",
592                    ATH10K_FW_DIR, filename);
593
594         return 0;
595 }
596
597 static int ath10k_core_fetch_board_data_api_1(struct ath10k *ar)
598 {
599         if (!ar->hw_params.fw.board) {
600                 ath10k_err(ar, "failed to find board file fw entry\n");
601                 return -EINVAL;
602         }
603
604         ar->board = ath10k_fetch_fw_file(ar,
605                                          ar->hw_params.fw.dir,
606                                          ar->hw_params.fw.board);
607         if (IS_ERR(ar->board))
608                 return PTR_ERR(ar->board);
609
610         ar->board_data = ar->board->data;
611         ar->board_len = ar->board->size;
612
613         return 0;
614 }
615
616 static int ath10k_core_parse_bd_ie_board(struct ath10k *ar,
617                                          const void *buf, size_t buf_len,
618                                          const char *boardname)
619 {
620         const struct ath10k_fw_ie *hdr;
621         bool name_match_found;
622         int ret, board_ie_id;
623         size_t board_ie_len;
624         const void *board_ie_data;
625
626         name_match_found = false;
627
628         /* go through ATH10K_BD_IE_BOARD_ elements */
629         while (buf_len > sizeof(struct ath10k_fw_ie)) {
630                 hdr = buf;
631                 board_ie_id = le32_to_cpu(hdr->id);
632                 board_ie_len = le32_to_cpu(hdr->len);
633                 board_ie_data = hdr->data;
634
635                 buf_len -= sizeof(*hdr);
636                 buf += sizeof(*hdr);
637
638                 if (buf_len < ALIGN(board_ie_len, 4)) {
639                         ath10k_err(ar, "invalid ATH10K_BD_IE_BOARD length: %zu < %zu\n",
640                                    buf_len, ALIGN(board_ie_len, 4));
641                         ret = -EINVAL;
642                         goto out;
643                 }
644
645                 switch (board_ie_id) {
646                 case ATH10K_BD_IE_BOARD_NAME:
647                         ath10k_dbg_dump(ar, ATH10K_DBG_BOOT, "board name", "",
648                                         board_ie_data, board_ie_len);
649
650                         if (board_ie_len != strlen(boardname))
651                                 break;
652
653                         ret = memcmp(board_ie_data, boardname, strlen(boardname));
654                         if (ret)
655                                 break;
656
657                         name_match_found = true;
658                         ath10k_dbg(ar, ATH10K_DBG_BOOT,
659                                    "boot found match for name '%s'",
660                                    boardname);
661                         break;
662                 case ATH10K_BD_IE_BOARD_DATA:
663                         if (!name_match_found)
664                                 /* no match found */
665                                 break;
666
667                         ath10k_dbg(ar, ATH10K_DBG_BOOT,
668                                    "boot found board data for '%s'",
669                                    boardname);
670
671                         ar->board_data = board_ie_data;
672                         ar->board_len = board_ie_len;
673
674                         ret = 0;
675                         goto out;
676                 default:
677                         ath10k_warn(ar, "unknown ATH10K_BD_IE_BOARD found: %d\n",
678                                     board_ie_id);
679                         break;
680                 }
681
682                 /* jump over the padding */
683                 board_ie_len = ALIGN(board_ie_len, 4);
684
685                 buf_len -= board_ie_len;
686                 buf += board_ie_len;
687         }
688
689         /* no match found */
690         ret = -ENOENT;
691
692 out:
693         return ret;
694 }
695
696 static int ath10k_core_fetch_board_data_api_n(struct ath10k *ar,
697                                               const char *boardname,
698                                               const char *filename)
699 {
700         size_t len, magic_len, ie_len;
701         struct ath10k_fw_ie *hdr;
702         const u8 *data;
703         int ret, ie_id;
704
705         ar->board = ath10k_fetch_fw_file(ar, ar->hw_params.fw.dir, filename);
706         if (IS_ERR(ar->board))
707                 return PTR_ERR(ar->board);
708
709         data = ar->board->data;
710         len = ar->board->size;
711
712         /* magic has extra null byte padded */
713         magic_len = strlen(ATH10K_BOARD_MAGIC) + 1;
714         if (len < magic_len) {
715                 ath10k_err(ar, "failed to find magic value in %s/%s, file too short: %zu\n",
716                            ar->hw_params.fw.dir, filename, len);
717                 ret = -EINVAL;
718                 goto err;
719         }
720
721         if (memcmp(data, ATH10K_BOARD_MAGIC, magic_len)) {
722                 ath10k_err(ar, "found invalid board magic\n");
723                 ret = -EINVAL;
724                 goto err;
725         }
726
727         /* magic is padded to 4 bytes */
728         magic_len = ALIGN(magic_len, 4);
729         if (len < magic_len) {
730                 ath10k_err(ar, "failed: %s/%s too small to contain board data, len: %zu\n",
731                            ar->hw_params.fw.dir, filename, len);
732                 ret = -EINVAL;
733                 goto err;
734         }
735
736         data += magic_len;
737         len -= magic_len;
738
739         while (len > sizeof(struct ath10k_fw_ie)) {
740                 hdr = (struct ath10k_fw_ie *)data;
741                 ie_id = le32_to_cpu(hdr->id);
742                 ie_len = le32_to_cpu(hdr->len);
743
744                 len -= sizeof(*hdr);
745                 data = hdr->data;
746
747                 if (len < ALIGN(ie_len, 4)) {
748                         ath10k_err(ar, "invalid length for board ie_id %d ie_len %zu len %zu\n",
749                                    ie_id, ie_len, len);
750                         ret = -EINVAL;
751                         goto err;
752                 }
753
754                 switch (ie_id) {
755                 case ATH10K_BD_IE_BOARD:
756                         ret = ath10k_core_parse_bd_ie_board(ar, data, ie_len,
757                                                             boardname);
758                         if (ret == -ENOENT)
759                                 /* no match found, continue */
760                                 break;
761                         else if (ret)
762                                 /* there was an error, bail out */
763                                 goto err;
764
765                         /* board data found */
766                         goto out;
767                 }
768
769                 /* jump over the padding */
770                 ie_len = ALIGN(ie_len, 4);
771
772                 len -= ie_len;
773                 data += ie_len;
774         }
775
776 out:
777         if (!ar->board_data || !ar->board_len) {
778                 ath10k_err(ar,
779                            "failed to fetch board data for %s from %s/%s\n",
780                            ar->hw_params.fw.dir, boardname, filename);
781                 ret = -ENODATA;
782                 goto err;
783         }
784
785         return 0;
786
787 err:
788         ath10k_core_free_board_files(ar);
789         return ret;
790 }
791
792 static int ath10k_core_create_board_name(struct ath10k *ar, char *name,
793                                          size_t name_len)
794 {
795         scnprintf(name, name_len,
796                   "bus=%s,vendor=%04x,device=%04x,subsystem-vendor=%04x,subsystem-device=%04x",
797                   ath10k_bus_str(ar->hif.bus),
798                   ar->id.vendor, ar->id.device,
799                   ar->id.subsystem_vendor, ar->id.subsystem_device);
800
801         ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot using board name '%s'\n", name);
802
803         return 0;
804 }
805
806 static int ath10k_core_fetch_board_file(struct ath10k *ar)
807 {
808         char boardname[100];
809         int ret;
810
811         ret = ath10k_core_create_board_name(ar, boardname, sizeof(boardname));
812         if (ret) {
813                 ath10k_err(ar, "failed to create board name: %d", ret);
814                 return ret;
815         }
816
817         ar->bd_api = 2;
818         ret = ath10k_core_fetch_board_data_api_n(ar, boardname,
819                                                  ATH10K_BOARD_API2_FILE);
820         if (!ret)
821                 goto success;
822
823         ar->bd_api = 1;
824         ret = ath10k_core_fetch_board_data_api_1(ar);
825         if (ret) {
826                 ath10k_err(ar, "failed to fetch board data\n");
827                 return ret;
828         }
829
830 success:
831         ath10k_dbg(ar, ATH10K_DBG_BOOT, "using board api %d\n", ar->bd_api);
832         return 0;
833 }
834
835 static int ath10k_core_fetch_firmware_api_1(struct ath10k *ar)
836 {
837         int ret = 0;
838
839         if (ar->hw_params.fw.fw == NULL) {
840                 ath10k_err(ar, "firmware file not defined\n");
841                 return -EINVAL;
842         }
843
844         ar->firmware = ath10k_fetch_fw_file(ar,
845                                             ar->hw_params.fw.dir,
846                                             ar->hw_params.fw.fw);
847         if (IS_ERR(ar->firmware)) {
848                 ret = PTR_ERR(ar->firmware);
849                 ath10k_err(ar, "could not fetch firmware (%d)\n", ret);
850                 goto err;
851         }
852
853         ar->firmware_data = ar->firmware->data;
854         ar->firmware_len = ar->firmware->size;
855
856         /* OTP may be undefined. If so, don't fetch it at all */
857         if (ar->hw_params.fw.otp == NULL)
858                 return 0;
859
860         ar->otp = ath10k_fetch_fw_file(ar,
861                                        ar->hw_params.fw.dir,
862                                        ar->hw_params.fw.otp);
863         if (IS_ERR(ar->otp)) {
864                 ret = PTR_ERR(ar->otp);
865                 ath10k_err(ar, "could not fetch otp (%d)\n", ret);
866                 goto err;
867         }
868
869         ar->otp_data = ar->otp->data;
870         ar->otp_len = ar->otp->size;
871
872         return 0;
873
874 err:
875         ath10k_core_free_firmware_files(ar);
876         return ret;
877 }
878
879 static int ath10k_core_fetch_firmware_api_n(struct ath10k *ar, const char *name)
880 {
881         size_t magic_len, len, ie_len;
882         int ie_id, i, index, bit, ret;
883         struct ath10k_fw_ie *hdr;
884         const u8 *data;
885         __le32 *timestamp, *version;
886
887         /* first fetch the firmware file (firmware-*.bin) */
888         ar->firmware = ath10k_fetch_fw_file(ar, ar->hw_params.fw.dir, name);
889         if (IS_ERR(ar->firmware)) {
890                 ath10k_err(ar, "could not fetch firmware file '%s/%s': %ld\n",
891                            ar->hw_params.fw.dir, name, PTR_ERR(ar->firmware));
892                 return PTR_ERR(ar->firmware);
893         }
894
895         data = ar->firmware->data;
896         len = ar->firmware->size;
897
898         /* magic also includes the null byte, check that as well */
899         magic_len = strlen(ATH10K_FIRMWARE_MAGIC) + 1;
900
901         if (len < magic_len) {
902                 ath10k_err(ar, "firmware file '%s/%s' too small to contain magic: %zu\n",
903                            ar->hw_params.fw.dir, name, len);
904                 ret = -EINVAL;
905                 goto err;
906         }
907
908         if (memcmp(data, ATH10K_FIRMWARE_MAGIC, magic_len) != 0) {
909                 ath10k_err(ar, "invalid firmware magic\n");
910                 ret = -EINVAL;
911                 goto err;
912         }
913
914         /* jump over the padding */
915         magic_len = ALIGN(magic_len, 4);
916
917         len -= magic_len;
918         data += magic_len;
919
920         /* loop elements */
921         while (len > sizeof(struct ath10k_fw_ie)) {
922                 hdr = (struct ath10k_fw_ie *)data;
923
924                 ie_id = le32_to_cpu(hdr->id);
925                 ie_len = le32_to_cpu(hdr->len);
926
927                 len -= sizeof(*hdr);
928                 data += sizeof(*hdr);
929
930                 if (len < ie_len) {
931                         ath10k_err(ar, "invalid length for FW IE %d (%zu < %zu)\n",
932                                    ie_id, len, ie_len);
933                         ret = -EINVAL;
934                         goto err;
935                 }
936
937                 switch (ie_id) {
938                 case ATH10K_FW_IE_FW_VERSION:
939                         if (ie_len > sizeof(ar->hw->wiphy->fw_version) - 1)
940                                 break;
941
942                         memcpy(ar->hw->wiphy->fw_version, data, ie_len);
943                         ar->hw->wiphy->fw_version[ie_len] = '\0';
944
945                         ath10k_dbg(ar, ATH10K_DBG_BOOT,
946                                    "found fw version %s\n",
947                                     ar->hw->wiphy->fw_version);
948                         break;
949                 case ATH10K_FW_IE_TIMESTAMP:
950                         if (ie_len != sizeof(u32))
951                                 break;
952
953                         timestamp = (__le32 *)data;
954
955                         ath10k_dbg(ar, ATH10K_DBG_BOOT, "found fw timestamp %d\n",
956                                    le32_to_cpup(timestamp));
957                         break;
958                 case ATH10K_FW_IE_FEATURES:
959                         ath10k_dbg(ar, ATH10K_DBG_BOOT,
960                                    "found firmware features ie (%zd B)\n",
961                                    ie_len);
962
963                         for (i = 0; i < ATH10K_FW_FEATURE_COUNT; i++) {
964                                 index = i / 8;
965                                 bit = i % 8;
966
967                                 if (index == ie_len)
968                                         break;
969
970                                 if (data[index] & (1 << bit)) {
971                                         ath10k_dbg(ar, ATH10K_DBG_BOOT,
972                                                    "Enabling feature bit: %i\n",
973                                                    i);
974                                         __set_bit(i, ar->fw_features);
975                                 }
976                         }
977
978                         ath10k_dbg_dump(ar, ATH10K_DBG_BOOT, "features", "",
979                                         ar->fw_features,
980                                         sizeof(ar->fw_features));
981                         break;
982                 case ATH10K_FW_IE_FW_IMAGE:
983                         ath10k_dbg(ar, ATH10K_DBG_BOOT,
984                                    "found fw image ie (%zd B)\n",
985                                    ie_len);
986
987                         ar->firmware_data = data;
988                         ar->firmware_len = ie_len;
989
990                         break;
991                 case ATH10K_FW_IE_OTP_IMAGE:
992                         ath10k_dbg(ar, ATH10K_DBG_BOOT,
993                                    "found otp image ie (%zd B)\n",
994                                    ie_len);
995
996                         ar->otp_data = data;
997                         ar->otp_len = ie_len;
998
999                         break;
1000                 case ATH10K_FW_IE_WMI_OP_VERSION:
1001                         if (ie_len != sizeof(u32))
1002                                 break;
1003
1004                         version = (__le32 *)data;
1005
1006                         ar->wmi.op_version = le32_to_cpup(version);
1007
1008                         ath10k_dbg(ar, ATH10K_DBG_BOOT, "found fw ie wmi op version %d\n",
1009                                    ar->wmi.op_version);
1010                         break;
1011                 case ATH10K_FW_IE_HTT_OP_VERSION:
1012                         if (ie_len != sizeof(u32))
1013                                 break;
1014
1015                         version = (__le32 *)data;
1016
1017                         ar->htt.op_version = le32_to_cpup(version);
1018
1019                         ath10k_dbg(ar, ATH10K_DBG_BOOT, "found fw ie htt op version %d\n",
1020                                    ar->htt.op_version);
1021                         break;
1022                 case ATH10K_FW_IE_FW_CODE_SWAP_IMAGE:
1023                         ath10k_dbg(ar, ATH10K_DBG_BOOT,
1024                                    "found fw code swap image ie (%zd B)\n",
1025                                    ie_len);
1026                         ar->swap.firmware_codeswap_data = data;
1027                         ar->swap.firmware_codeswap_len = ie_len;
1028                         break;
1029                 default:
1030                         ath10k_warn(ar, "Unknown FW IE: %u\n",
1031                                     le32_to_cpu(hdr->id));
1032                         break;
1033                 }
1034
1035                 /* jump over the padding */
1036                 ie_len = ALIGN(ie_len, 4);
1037
1038                 len -= ie_len;
1039                 data += ie_len;
1040         }
1041
1042         if (!ar->firmware_data || !ar->firmware_len) {
1043                 ath10k_warn(ar, "No ATH10K_FW_IE_FW_IMAGE found from '%s/%s', skipping\n",
1044                             ar->hw_params.fw.dir, name);
1045                 ret = -ENOMEDIUM;
1046                 goto err;
1047         }
1048
1049         return 0;
1050
1051 err:
1052         ath10k_core_free_firmware_files(ar);
1053         return ret;
1054 }
1055
1056 static int ath10k_core_fetch_firmware_files(struct ath10k *ar)
1057 {
1058         int ret;
1059
1060         /* calibration file is optional, don't check for any errors */
1061         ath10k_fetch_cal_file(ar);
1062
1063         ret = ath10k_core_fetch_board_file(ar);
1064         if (ret) {
1065                 ath10k_err(ar, "failed to fetch board file: %d\n", ret);
1066                 return ret;
1067         }
1068
1069         ar->fw_api = 5;
1070         ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
1071
1072         ret = ath10k_core_fetch_firmware_api_n(ar, ATH10K_FW_API5_FILE);
1073         if (ret == 0)
1074                 goto success;
1075
1076         ar->fw_api = 4;
1077         ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
1078
1079         ret = ath10k_core_fetch_firmware_api_n(ar, ATH10K_FW_API4_FILE);
1080         if (ret == 0)
1081                 goto success;
1082
1083         ar->fw_api = 3;
1084         ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
1085
1086         ret = ath10k_core_fetch_firmware_api_n(ar, ATH10K_FW_API3_FILE);
1087         if (ret == 0)
1088                 goto success;
1089
1090         ar->fw_api = 2;
1091         ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
1092
1093         ret = ath10k_core_fetch_firmware_api_n(ar, ATH10K_FW_API2_FILE);
1094         if (ret == 0)
1095                 goto success;
1096
1097         ar->fw_api = 1;
1098         ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
1099
1100         ret = ath10k_core_fetch_firmware_api_1(ar);
1101         if (ret)
1102                 return ret;
1103
1104 success:
1105         ath10k_dbg(ar, ATH10K_DBG_BOOT, "using fw api %d\n", ar->fw_api);
1106
1107         return 0;
1108 }
1109
1110 static int ath10k_download_cal_data(struct ath10k *ar)
1111 {
1112         int ret;
1113
1114         ret = ath10k_download_cal_file(ar);
1115         if (ret == 0) {
1116                 ar->cal_mode = ATH10K_CAL_MODE_FILE;
1117                 goto done;
1118         }
1119
1120         ath10k_dbg(ar, ATH10K_DBG_BOOT,
1121                    "boot did not find a calibration file, try DT next: %d\n",
1122                    ret);
1123
1124         ret = ath10k_download_cal_dt(ar);
1125         if (ret == 0) {
1126                 ar->cal_mode = ATH10K_CAL_MODE_DT;
1127                 goto done;
1128         }
1129
1130         ath10k_dbg(ar, ATH10K_DBG_BOOT,
1131                    "boot did not find DT entry, try OTP next: %d\n",
1132                    ret);
1133
1134         ret = ath10k_download_and_run_otp(ar);
1135         if (ret) {
1136                 ath10k_err(ar, "failed to run otp: %d\n", ret);
1137                 return ret;
1138         }
1139
1140         ar->cal_mode = ATH10K_CAL_MODE_OTP;
1141
1142 done:
1143         ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot using calibration mode %s\n",
1144                    ath10k_cal_mode_str(ar->cal_mode));
1145         return 0;
1146 }
1147
1148 static int ath10k_init_uart(struct ath10k *ar)
1149 {
1150         int ret;
1151
1152         /*
1153          * Explicitly setting UART prints to zero as target turns it on
1154          * based on scratch registers.
1155          */
1156         ret = ath10k_bmi_write32(ar, hi_serial_enable, 0);
1157         if (ret) {
1158                 ath10k_warn(ar, "could not disable UART prints (%d)\n", ret);
1159                 return ret;
1160         }
1161
1162         if (!uart_print)
1163                 return 0;
1164
1165         ret = ath10k_bmi_write32(ar, hi_dbg_uart_txpin, ar->hw_params.uart_pin);
1166         if (ret) {
1167                 ath10k_warn(ar, "could not enable UART prints (%d)\n", ret);
1168                 return ret;
1169         }
1170
1171         ret = ath10k_bmi_write32(ar, hi_serial_enable, 1);
1172         if (ret) {
1173                 ath10k_warn(ar, "could not enable UART prints (%d)\n", ret);
1174                 return ret;
1175         }
1176
1177         /* Set the UART baud rate to 19200. */
1178         ret = ath10k_bmi_write32(ar, hi_desired_baud_rate, 19200);
1179         if (ret) {
1180                 ath10k_warn(ar, "could not set the baud rate (%d)\n", ret);
1181                 return ret;
1182         }
1183
1184         ath10k_info(ar, "UART prints enabled\n");
1185         return 0;
1186 }
1187
1188 static int ath10k_init_hw_params(struct ath10k *ar)
1189 {
1190         const struct ath10k_hw_params *uninitialized_var(hw_params);
1191         int i;
1192
1193         for (i = 0; i < ARRAY_SIZE(ath10k_hw_params_list); i++) {
1194                 hw_params = &ath10k_hw_params_list[i];
1195
1196                 if (hw_params->id == ar->target_version)
1197                         break;
1198         }
1199
1200         if (i == ARRAY_SIZE(ath10k_hw_params_list)) {
1201                 ath10k_err(ar, "Unsupported hardware version: 0x%x\n",
1202                            ar->target_version);
1203                 return -EINVAL;
1204         }
1205
1206         ar->hw_params = *hw_params;
1207
1208         ath10k_dbg(ar, ATH10K_DBG_BOOT, "Hardware name %s version 0x%x\n",
1209                    ar->hw_params.name, ar->target_version);
1210
1211         return 0;
1212 }
1213
1214 static void ath10k_core_restart(struct work_struct *work)
1215 {
1216         struct ath10k *ar = container_of(work, struct ath10k, restart_work);
1217
1218         set_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags);
1219
1220         /* Place a barrier to make sure the compiler doesn't reorder
1221          * CRASH_FLUSH and calling other functions.
1222          */
1223         barrier();
1224
1225         ieee80211_stop_queues(ar->hw);
1226         ath10k_drain_tx(ar);
1227         complete_all(&ar->scan.started);
1228         complete_all(&ar->scan.completed);
1229         complete_all(&ar->scan.on_channel);
1230         complete_all(&ar->offchan_tx_completed);
1231         complete_all(&ar->install_key_done);
1232         complete_all(&ar->vdev_setup_done);
1233         complete_all(&ar->thermal.wmi_sync);
1234         wake_up(&ar->htt.empty_tx_wq);
1235         wake_up(&ar->wmi.tx_credits_wq);
1236         wake_up(&ar->peer_mapping_wq);
1237
1238         mutex_lock(&ar->conf_mutex);
1239
1240         switch (ar->state) {
1241         case ATH10K_STATE_ON:
1242                 ar->state = ATH10K_STATE_RESTARTING;
1243                 ath10k_hif_stop(ar);
1244                 ath10k_scan_finish(ar);
1245                 ieee80211_restart_hw(ar->hw);
1246                 break;
1247         case ATH10K_STATE_OFF:
1248                 /* this can happen if driver is being unloaded
1249                  * or if the crash happens during FW probing */
1250                 ath10k_warn(ar, "cannot restart a device that hasn't been started\n");
1251                 break;
1252         case ATH10K_STATE_RESTARTING:
1253                 /* hw restart might be requested from multiple places */
1254                 break;
1255         case ATH10K_STATE_RESTARTED:
1256                 ar->state = ATH10K_STATE_WEDGED;
1257                 /* fall through */
1258         case ATH10K_STATE_WEDGED:
1259                 ath10k_warn(ar, "device is wedged, will not restart\n");
1260                 break;
1261         case ATH10K_STATE_UTF:
1262                 ath10k_warn(ar, "firmware restart in UTF mode not supported\n");
1263                 break;
1264         }
1265
1266         mutex_unlock(&ar->conf_mutex);
1267 }
1268
1269 static int ath10k_core_init_firmware_features(struct ath10k *ar)
1270 {
1271         if (test_bit(ATH10K_FW_FEATURE_WMI_10_2, ar->fw_features) &&
1272             !test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
1273                 ath10k_err(ar, "feature bits corrupted: 10.2 feature requires 10.x feature to be set as well");
1274                 return -EINVAL;
1275         }
1276
1277         if (ar->wmi.op_version >= ATH10K_FW_WMI_OP_VERSION_MAX) {
1278                 ath10k_err(ar, "unsupported WMI OP version (max %d): %d\n",
1279                            ATH10K_FW_WMI_OP_VERSION_MAX, ar->wmi.op_version);
1280                 return -EINVAL;
1281         }
1282
1283         ar->wmi.rx_decap_mode = ATH10K_HW_TXRX_NATIVE_WIFI;
1284         switch (ath10k_cryptmode_param) {
1285         case ATH10K_CRYPT_MODE_HW:
1286                 clear_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags);
1287                 clear_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags);
1288                 break;
1289         case ATH10K_CRYPT_MODE_SW:
1290                 if (!test_bit(ATH10K_FW_FEATURE_RAW_MODE_SUPPORT,
1291                               ar->fw_features)) {
1292                         ath10k_err(ar, "cryptmode > 0 requires raw mode support from firmware");
1293                         return -EINVAL;
1294                 }
1295
1296                 set_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags);
1297                 set_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags);
1298                 break;
1299         default:
1300                 ath10k_info(ar, "invalid cryptmode: %d\n",
1301                             ath10k_cryptmode_param);
1302                 return -EINVAL;
1303         }
1304
1305         ar->htt.max_num_amsdu = ATH10K_HTT_MAX_NUM_AMSDU_DEFAULT;
1306         ar->htt.max_num_ampdu = ATH10K_HTT_MAX_NUM_AMPDU_DEFAULT;
1307
1308         if (rawmode) {
1309                 if (!test_bit(ATH10K_FW_FEATURE_RAW_MODE_SUPPORT,
1310                               ar->fw_features)) {
1311                         ath10k_err(ar, "rawmode = 1 requires support from firmware");
1312                         return -EINVAL;
1313                 }
1314                 set_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags);
1315         }
1316
1317         if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
1318                 ar->wmi.rx_decap_mode = ATH10K_HW_TXRX_RAW;
1319
1320                 /* Workaround:
1321                  *
1322                  * Firmware A-MSDU aggregation breaks with RAW Tx encap mode
1323                  * and causes enormous performance issues (malformed frames,
1324                  * etc).
1325                  *
1326                  * Disabling A-MSDU makes RAW mode stable with heavy traffic
1327                  * albeit a bit slower compared to regular operation.
1328                  */
1329                 ar->htt.max_num_amsdu = 1;
1330         }
1331
1332         /* Backwards compatibility for firmwares without
1333          * ATH10K_FW_IE_WMI_OP_VERSION.
1334          */
1335         if (ar->wmi.op_version == ATH10K_FW_WMI_OP_VERSION_UNSET) {
1336                 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
1337                         if (test_bit(ATH10K_FW_FEATURE_WMI_10_2,
1338                                      ar->fw_features))
1339                                 ar->wmi.op_version = ATH10K_FW_WMI_OP_VERSION_10_2;
1340                         else
1341                                 ar->wmi.op_version = ATH10K_FW_WMI_OP_VERSION_10_1;
1342                 } else {
1343                         ar->wmi.op_version = ATH10K_FW_WMI_OP_VERSION_MAIN;
1344                 }
1345         }
1346
1347         switch (ar->wmi.op_version) {
1348         case ATH10K_FW_WMI_OP_VERSION_MAIN:
1349                 ar->max_num_peers = TARGET_NUM_PEERS;
1350                 ar->max_num_stations = TARGET_NUM_STATIONS;
1351                 ar->max_num_vdevs = TARGET_NUM_VDEVS;
1352                 ar->htt.max_num_pending_tx = TARGET_NUM_MSDU_DESC;
1353                 ar->fw_stats_req_mask = WMI_STAT_PDEV | WMI_STAT_VDEV |
1354                         WMI_STAT_PEER;
1355                 ar->max_spatial_stream = WMI_MAX_SPATIAL_STREAM;
1356                 break;
1357         case ATH10K_FW_WMI_OP_VERSION_10_1:
1358         case ATH10K_FW_WMI_OP_VERSION_10_2:
1359         case ATH10K_FW_WMI_OP_VERSION_10_2_4:
1360                 ar->max_num_peers = TARGET_10X_NUM_PEERS;
1361                 ar->max_num_stations = TARGET_10X_NUM_STATIONS;
1362                 ar->max_num_vdevs = TARGET_10X_NUM_VDEVS;
1363                 ar->htt.max_num_pending_tx = TARGET_10X_NUM_MSDU_DESC;
1364                 ar->fw_stats_req_mask = WMI_STAT_PEER;
1365                 ar->max_spatial_stream = WMI_MAX_SPATIAL_STREAM;
1366                 break;
1367         case ATH10K_FW_WMI_OP_VERSION_TLV:
1368                 ar->max_num_peers = TARGET_TLV_NUM_PEERS;
1369                 ar->max_num_stations = TARGET_TLV_NUM_STATIONS;
1370                 ar->max_num_vdevs = TARGET_TLV_NUM_VDEVS;
1371                 ar->max_num_tdls_vdevs = TARGET_TLV_NUM_TDLS_VDEVS;
1372                 ar->htt.max_num_pending_tx = TARGET_TLV_NUM_MSDU_DESC;
1373                 ar->wow.max_num_patterns = TARGET_TLV_NUM_WOW_PATTERNS;
1374                 ar->fw_stats_req_mask = WMI_STAT_PDEV | WMI_STAT_VDEV |
1375                         WMI_STAT_PEER;
1376                 ar->max_spatial_stream = WMI_MAX_SPATIAL_STREAM;
1377                 break;
1378         case ATH10K_FW_WMI_OP_VERSION_10_4:
1379                 ar->max_num_peers = TARGET_10_4_NUM_PEERS;
1380                 ar->max_num_stations = TARGET_10_4_NUM_STATIONS;
1381                 ar->num_active_peers = TARGET_10_4_ACTIVE_PEERS;
1382                 ar->max_num_vdevs = TARGET_10_4_NUM_VDEVS;
1383                 ar->num_tids = TARGET_10_4_TGT_NUM_TIDS;
1384                 ar->htt.max_num_pending_tx = TARGET_10_4_NUM_MSDU_DESC;
1385                 ar->fw_stats_req_mask = WMI_STAT_PEER;
1386                 ar->max_spatial_stream = WMI_10_4_MAX_SPATIAL_STREAM;
1387                 break;
1388         case ATH10K_FW_WMI_OP_VERSION_UNSET:
1389         case ATH10K_FW_WMI_OP_VERSION_MAX:
1390                 WARN_ON(1);
1391                 return -EINVAL;
1392         }
1393
1394         /* Backwards compatibility for firmwares without
1395          * ATH10K_FW_IE_HTT_OP_VERSION.
1396          */
1397         if (ar->htt.op_version == ATH10K_FW_HTT_OP_VERSION_UNSET) {
1398                 switch (ar->wmi.op_version) {
1399                 case ATH10K_FW_WMI_OP_VERSION_MAIN:
1400                         ar->htt.op_version = ATH10K_FW_HTT_OP_VERSION_MAIN;
1401                         break;
1402                 case ATH10K_FW_WMI_OP_VERSION_10_1:
1403                 case ATH10K_FW_WMI_OP_VERSION_10_2:
1404                 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
1405                         ar->htt.op_version = ATH10K_FW_HTT_OP_VERSION_10_1;
1406                         break;
1407                 case ATH10K_FW_WMI_OP_VERSION_TLV:
1408                         ar->htt.op_version = ATH10K_FW_HTT_OP_VERSION_TLV;
1409                         break;
1410                 case ATH10K_FW_WMI_OP_VERSION_10_4:
1411                 case ATH10K_FW_WMI_OP_VERSION_UNSET:
1412                 case ATH10K_FW_WMI_OP_VERSION_MAX:
1413                         WARN_ON(1);
1414                         return -EINVAL;
1415                 }
1416         }
1417
1418         return 0;
1419 }
1420
1421 int ath10k_core_start(struct ath10k *ar, enum ath10k_firmware_mode mode)
1422 {
1423         int status;
1424
1425         lockdep_assert_held(&ar->conf_mutex);
1426
1427         clear_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags);
1428
1429         ath10k_bmi_start(ar);
1430
1431         if (ath10k_init_configure_target(ar)) {
1432                 status = -EINVAL;
1433                 goto err;
1434         }
1435
1436         status = ath10k_download_cal_data(ar);
1437         if (status)
1438                 goto err;
1439
1440         /* Some of of qca988x solutions are having global reset issue
1441          * during target initialization. Bypassing PLL setting before
1442          * downloading firmware and letting the SoC run on REF_CLK is
1443          * fixing the problem. Corresponding firmware change is also needed
1444          * to set the clock source once the target is initialized.
1445          */
1446         if (test_bit(ATH10K_FW_FEATURE_SUPPORTS_SKIP_CLOCK_INIT,
1447                      ar->fw_features)) {
1448                 status = ath10k_bmi_write32(ar, hi_skip_clock_init, 1);
1449                 if (status) {
1450                         ath10k_err(ar, "could not write to skip_clock_init: %d\n",
1451                                    status);
1452                         goto err;
1453                 }
1454         }
1455
1456         status = ath10k_download_fw(ar, mode);
1457         if (status)
1458                 goto err;
1459
1460         status = ath10k_init_uart(ar);
1461         if (status)
1462                 goto err;
1463
1464         ar->htc.htc_ops.target_send_suspend_complete =
1465                 ath10k_send_suspend_complete;
1466
1467         status = ath10k_htc_init(ar);
1468         if (status) {
1469                 ath10k_err(ar, "could not init HTC (%d)\n", status);
1470                 goto err;
1471         }
1472
1473         status = ath10k_bmi_done(ar);
1474         if (status)
1475                 goto err;
1476
1477         status = ath10k_wmi_attach(ar);
1478         if (status) {
1479                 ath10k_err(ar, "WMI attach failed: %d\n", status);
1480                 goto err;
1481         }
1482
1483         status = ath10k_htt_init(ar);
1484         if (status) {
1485                 ath10k_err(ar, "failed to init htt: %d\n", status);
1486                 goto err_wmi_detach;
1487         }
1488
1489         status = ath10k_htt_tx_alloc(&ar->htt);
1490         if (status) {
1491                 ath10k_err(ar, "failed to alloc htt tx: %d\n", status);
1492                 goto err_wmi_detach;
1493         }
1494
1495         status = ath10k_htt_rx_alloc(&ar->htt);
1496         if (status) {
1497                 ath10k_err(ar, "failed to alloc htt rx: %d\n", status);
1498                 goto err_htt_tx_detach;
1499         }
1500
1501         status = ath10k_hif_start(ar);
1502         if (status) {
1503                 ath10k_err(ar, "could not start HIF: %d\n", status);
1504                 goto err_htt_rx_detach;
1505         }
1506
1507         status = ath10k_htc_wait_target(&ar->htc);
1508         if (status) {
1509                 ath10k_err(ar, "failed to connect to HTC: %d\n", status);
1510                 goto err_hif_stop;
1511         }
1512
1513         if (mode == ATH10K_FIRMWARE_MODE_NORMAL) {
1514                 status = ath10k_htt_connect(&ar->htt);
1515                 if (status) {
1516                         ath10k_err(ar, "failed to connect htt (%d)\n", status);
1517                         goto err_hif_stop;
1518                 }
1519         }
1520
1521         status = ath10k_wmi_connect(ar);
1522         if (status) {
1523                 ath10k_err(ar, "could not connect wmi: %d\n", status);
1524                 goto err_hif_stop;
1525         }
1526
1527         status = ath10k_htc_start(&ar->htc);
1528         if (status) {
1529                 ath10k_err(ar, "failed to start htc: %d\n", status);
1530                 goto err_hif_stop;
1531         }
1532
1533         if (mode == ATH10K_FIRMWARE_MODE_NORMAL) {
1534                 status = ath10k_wmi_wait_for_service_ready(ar);
1535                 if (status) {
1536                         ath10k_warn(ar, "wmi service ready event not received");
1537                         goto err_hif_stop;
1538                 }
1539         }
1540
1541         ath10k_dbg(ar, ATH10K_DBG_BOOT, "firmware %s booted\n",
1542                    ar->hw->wiphy->fw_version);
1543
1544         status = ath10k_wmi_cmd_init(ar);
1545         if (status) {
1546                 ath10k_err(ar, "could not send WMI init command (%d)\n",
1547                            status);
1548                 goto err_hif_stop;
1549         }
1550
1551         status = ath10k_wmi_wait_for_unified_ready(ar);
1552         if (status) {
1553                 ath10k_err(ar, "wmi unified ready event not received\n");
1554                 goto err_hif_stop;
1555         }
1556
1557         /* If firmware indicates Full Rx Reorder support it must be used in a
1558          * slightly different manner. Let HTT code know.
1559          */
1560         ar->htt.rx_ring.in_ord_rx = !!(test_bit(WMI_SERVICE_RX_FULL_REORDER,
1561                                                 ar->wmi.svc_map));
1562
1563         status = ath10k_htt_rx_ring_refill(ar);
1564         if (status) {
1565                 ath10k_err(ar, "failed to refill htt rx ring: %d\n", status);
1566                 goto err_hif_stop;
1567         }
1568
1569         /* we don't care about HTT in UTF mode */
1570         if (mode == ATH10K_FIRMWARE_MODE_NORMAL) {
1571                 status = ath10k_htt_setup(&ar->htt);
1572                 if (status) {
1573                         ath10k_err(ar, "failed to setup htt: %d\n", status);
1574                         goto err_hif_stop;
1575                 }
1576         }
1577
1578         status = ath10k_debug_start(ar);
1579         if (status)
1580                 goto err_hif_stop;
1581
1582         ar->free_vdev_map = (1LL << ar->max_num_vdevs) - 1;
1583
1584         INIT_LIST_HEAD(&ar->arvifs);
1585
1586         return 0;
1587
1588 err_hif_stop:
1589         ath10k_hif_stop(ar);
1590 err_htt_rx_detach:
1591         ath10k_htt_rx_free(&ar->htt);
1592 err_htt_tx_detach:
1593         ath10k_htt_tx_free(&ar->htt);
1594 err_wmi_detach:
1595         ath10k_wmi_detach(ar);
1596 err:
1597         return status;
1598 }
1599 EXPORT_SYMBOL(ath10k_core_start);
1600
1601 int ath10k_wait_for_suspend(struct ath10k *ar, u32 suspend_opt)
1602 {
1603         int ret;
1604         unsigned long time_left;
1605
1606         reinit_completion(&ar->target_suspend);
1607
1608         ret = ath10k_wmi_pdev_suspend_target(ar, suspend_opt);
1609         if (ret) {
1610                 ath10k_warn(ar, "could not suspend target (%d)\n", ret);
1611                 return ret;
1612         }
1613
1614         time_left = wait_for_completion_timeout(&ar->target_suspend, 1 * HZ);
1615
1616         if (!time_left) {
1617                 ath10k_warn(ar, "suspend timed out - target pause event never came\n");
1618                 return -ETIMEDOUT;
1619         }
1620
1621         return 0;
1622 }
1623
1624 void ath10k_core_stop(struct ath10k *ar)
1625 {
1626         lockdep_assert_held(&ar->conf_mutex);
1627         ath10k_debug_stop(ar);
1628
1629         /* try to suspend target */
1630         if (ar->state != ATH10K_STATE_RESTARTING &&
1631             ar->state != ATH10K_STATE_UTF)
1632                 ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND_AND_DISABLE_INTR);
1633
1634         ath10k_hif_stop(ar);
1635         ath10k_htt_tx_free(&ar->htt);
1636         ath10k_htt_rx_free(&ar->htt);
1637         ath10k_wmi_detach(ar);
1638 }
1639 EXPORT_SYMBOL(ath10k_core_stop);
1640
1641 /* mac80211 manages fw/hw initialization through start/stop hooks. However in
1642  * order to know what hw capabilities should be advertised to mac80211 it is
1643  * necessary to load the firmware (and tear it down immediately since start
1644  * hook will try to init it again) before registering */
1645 static int ath10k_core_probe_fw(struct ath10k *ar)
1646 {
1647         struct bmi_target_info target_info;
1648         int ret = 0;
1649
1650         ret = ath10k_hif_power_up(ar);
1651         if (ret) {
1652                 ath10k_err(ar, "could not start pci hif (%d)\n", ret);
1653                 return ret;
1654         }
1655
1656         memset(&target_info, 0, sizeof(target_info));
1657         ret = ath10k_bmi_get_target_info(ar, &target_info);
1658         if (ret) {
1659                 ath10k_err(ar, "could not get target info (%d)\n", ret);
1660                 goto err_power_down;
1661         }
1662
1663         ar->target_version = target_info.version;
1664         ar->hw->wiphy->hw_version = target_info.version;
1665
1666         ret = ath10k_init_hw_params(ar);
1667         if (ret) {
1668                 ath10k_err(ar, "could not get hw params (%d)\n", ret);
1669                 goto err_power_down;
1670         }
1671
1672         ret = ath10k_core_fetch_firmware_files(ar);
1673         if (ret) {
1674                 ath10k_err(ar, "could not fetch firmware files (%d)\n", ret);
1675                 goto err_power_down;
1676         }
1677
1678         ret = ath10k_core_init_firmware_features(ar);
1679         if (ret) {
1680                 ath10k_err(ar, "fatal problem with firmware features: %d\n",
1681                            ret);
1682                 goto err_free_firmware_files;
1683         }
1684
1685         ret = ath10k_swap_code_seg_init(ar);
1686         if (ret) {
1687                 ath10k_err(ar, "failed to initialize code swap segment: %d\n",
1688                            ret);
1689                 goto err_free_firmware_files;
1690         }
1691
1692         mutex_lock(&ar->conf_mutex);
1693
1694         ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
1695         if (ret) {
1696                 ath10k_err(ar, "could not init core (%d)\n", ret);
1697                 goto err_unlock;
1698         }
1699
1700         ath10k_print_driver_info(ar);
1701         ath10k_core_stop(ar);
1702
1703         mutex_unlock(&ar->conf_mutex);
1704
1705         ath10k_hif_power_down(ar);
1706         return 0;
1707
1708 err_unlock:
1709         mutex_unlock(&ar->conf_mutex);
1710
1711 err_free_firmware_files:
1712         ath10k_core_free_firmware_files(ar);
1713
1714 err_power_down:
1715         ath10k_hif_power_down(ar);
1716
1717         return ret;
1718 }
1719
1720 static void ath10k_core_register_work(struct work_struct *work)
1721 {
1722         struct ath10k *ar = container_of(work, struct ath10k, register_work);
1723         int status;
1724
1725         status = ath10k_core_probe_fw(ar);
1726         if (status) {
1727                 ath10k_err(ar, "could not probe fw (%d)\n", status);
1728                 goto err;
1729         }
1730
1731         status = ath10k_mac_register(ar);
1732         if (status) {
1733                 ath10k_err(ar, "could not register to mac80211 (%d)\n", status);
1734                 goto err_release_fw;
1735         }
1736
1737         status = ath10k_debug_register(ar);
1738         if (status) {
1739                 ath10k_err(ar, "unable to initialize debugfs\n");
1740                 goto err_unregister_mac;
1741         }
1742
1743         status = ath10k_spectral_create(ar);
1744         if (status) {
1745                 ath10k_err(ar, "failed to initialize spectral\n");
1746                 goto err_debug_destroy;
1747         }
1748
1749         status = ath10k_thermal_register(ar);
1750         if (status) {
1751                 ath10k_err(ar, "could not register thermal device: %d\n",
1752                            status);
1753                 goto err_spectral_destroy;
1754         }
1755
1756         set_bit(ATH10K_FLAG_CORE_REGISTERED, &ar->dev_flags);
1757         return;
1758
1759 err_spectral_destroy:
1760         ath10k_spectral_destroy(ar);
1761 err_debug_destroy:
1762         ath10k_debug_destroy(ar);
1763 err_unregister_mac:
1764         ath10k_mac_unregister(ar);
1765 err_release_fw:
1766         ath10k_core_free_firmware_files(ar);
1767 err:
1768         /* TODO: It's probably a good idea to release device from the driver
1769          * but calling device_release_driver() here will cause a deadlock.
1770          */
1771         return;
1772 }
1773
1774 int ath10k_core_register(struct ath10k *ar, u32 chip_id)
1775 {
1776         ar->chip_id = chip_id;
1777         queue_work(ar->workqueue, &ar->register_work);
1778
1779         return 0;
1780 }
1781 EXPORT_SYMBOL(ath10k_core_register);
1782
1783 void ath10k_core_unregister(struct ath10k *ar)
1784 {
1785         cancel_work_sync(&ar->register_work);
1786
1787         if (!test_bit(ATH10K_FLAG_CORE_REGISTERED, &ar->dev_flags))
1788                 return;
1789
1790         ath10k_thermal_unregister(ar);
1791         /* Stop spectral before unregistering from mac80211 to remove the
1792          * relayfs debugfs file cleanly. Otherwise the parent debugfs tree
1793          * would be already be free'd recursively, leading to a double free.
1794          */
1795         ath10k_spectral_destroy(ar);
1796
1797         /* We must unregister from mac80211 before we stop HTC and HIF.
1798          * Otherwise we will fail to submit commands to FW and mac80211 will be
1799          * unhappy about callback failures. */
1800         ath10k_mac_unregister(ar);
1801
1802         ath10k_testmode_destroy(ar);
1803
1804         ath10k_core_free_firmware_files(ar);
1805         ath10k_core_free_board_files(ar);
1806
1807         ath10k_debug_unregister(ar);
1808 }
1809 EXPORT_SYMBOL(ath10k_core_unregister);
1810
1811 struct ath10k *ath10k_core_create(size_t priv_size, struct device *dev,
1812                                   enum ath10k_bus bus,
1813                                   enum ath10k_hw_rev hw_rev,
1814                                   const struct ath10k_hif_ops *hif_ops)
1815 {
1816         struct ath10k *ar;
1817         int ret;
1818
1819         ar = ath10k_mac_create(priv_size);
1820         if (!ar)
1821                 return NULL;
1822
1823         ar->ath_common.priv = ar;
1824         ar->ath_common.hw = ar->hw;
1825         ar->dev = dev;
1826         ar->hw_rev = hw_rev;
1827         ar->hif.ops = hif_ops;
1828         ar->hif.bus = bus;
1829
1830         switch (hw_rev) {
1831         case ATH10K_HW_QCA988X:
1832                 ar->regs = &qca988x_regs;
1833                 ar->hw_values = &qca988x_values;
1834                 break;
1835         case ATH10K_HW_QCA6174:
1836                 ar->regs = &qca6174_regs;
1837                 ar->hw_values = &qca6174_values;
1838                 break;
1839         case ATH10K_HW_QCA99X0:
1840                 ar->regs = &qca99x0_regs;
1841                 ar->hw_values = &qca99x0_values;
1842                 break;
1843         default:
1844                 ath10k_err(ar, "unsupported core hardware revision %d\n",
1845                            hw_rev);
1846                 ret = -ENOTSUPP;
1847                 goto err_free_mac;
1848         }
1849
1850         init_completion(&ar->scan.started);
1851         init_completion(&ar->scan.completed);
1852         init_completion(&ar->scan.on_channel);
1853         init_completion(&ar->target_suspend);
1854         init_completion(&ar->wow.wakeup_completed);
1855
1856         init_completion(&ar->install_key_done);
1857         init_completion(&ar->vdev_setup_done);
1858         init_completion(&ar->thermal.wmi_sync);
1859
1860         INIT_DELAYED_WORK(&ar->scan.timeout, ath10k_scan_timeout_work);
1861
1862         ar->workqueue = create_singlethread_workqueue("ath10k_wq");
1863         if (!ar->workqueue)
1864                 goto err_free_mac;
1865
1866         ar->workqueue_aux = create_singlethread_workqueue("ath10k_aux_wq");
1867         if (!ar->workqueue_aux)
1868                 goto err_free_wq;
1869
1870         mutex_init(&ar->conf_mutex);
1871         spin_lock_init(&ar->data_lock);
1872
1873         INIT_LIST_HEAD(&ar->peers);
1874         init_waitqueue_head(&ar->peer_mapping_wq);
1875         init_waitqueue_head(&ar->htt.empty_tx_wq);
1876         init_waitqueue_head(&ar->wmi.tx_credits_wq);
1877
1878         init_completion(&ar->offchan_tx_completed);
1879         INIT_WORK(&ar->offchan_tx_work, ath10k_offchan_tx_work);
1880         skb_queue_head_init(&ar->offchan_tx_queue);
1881
1882         INIT_WORK(&ar->wmi_mgmt_tx_work, ath10k_mgmt_over_wmi_tx_work);
1883         skb_queue_head_init(&ar->wmi_mgmt_tx_queue);
1884
1885         INIT_WORK(&ar->register_work, ath10k_core_register_work);
1886         INIT_WORK(&ar->restart_work, ath10k_core_restart);
1887
1888         ret = ath10k_debug_create(ar);
1889         if (ret)
1890                 goto err_free_aux_wq;
1891
1892         return ar;
1893
1894 err_free_aux_wq:
1895         destroy_workqueue(ar->workqueue_aux);
1896 err_free_wq:
1897         destroy_workqueue(ar->workqueue);
1898
1899 err_free_mac:
1900         ath10k_mac_destroy(ar);
1901
1902         return NULL;
1903 }
1904 EXPORT_SYMBOL(ath10k_core_create);
1905
1906 void ath10k_core_destroy(struct ath10k *ar)
1907 {
1908         flush_workqueue(ar->workqueue);
1909         destroy_workqueue(ar->workqueue);
1910
1911         flush_workqueue(ar->workqueue_aux);
1912         destroy_workqueue(ar->workqueue_aux);
1913
1914         ath10k_debug_destroy(ar);
1915         ath10k_wmi_free_host_mem(ar);
1916         ath10k_mac_destroy(ar);
1917 }
1918 EXPORT_SYMBOL(ath10k_core_destroy);
1919
1920 MODULE_AUTHOR("Qualcomm Atheros");
1921 MODULE_DESCRIPTION("Core module for QCA988X PCIe devices.");
1922 MODULE_LICENSE("Dual BSD/GPL");