5e9e1a6958f481ba3a8a8548ec1df13873f3b234
[deliverable/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 #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 bool uart_print;
35 static bool skip_otp;
36
37 module_param_named(debug_mask, ath10k_debug_mask, uint, 0644);
38 module_param(uart_print, bool, 0644);
39 module_param(skip_otp, bool, 0644);
40
41 MODULE_PARM_DESC(debug_mask, "Debugging mask");
42 MODULE_PARM_DESC(uart_print, "Uart target debugging");
43 MODULE_PARM_DESC(skip_otp, "Skip otp failure for calibration in testmode");
44
45 static const struct ath10k_hw_params ath10k_hw_params_list[] = {
46 {
47 .id = QCA988X_HW_2_0_VERSION,
48 .name = "qca988x hw2.0",
49 .patch_load_addr = QCA988X_HW_2_0_PATCH_LOAD_ADDR,
50 .uart_pin = 7,
51 .fw = {
52 .dir = QCA988X_HW_2_0_FW_DIR,
53 .fw = QCA988X_HW_2_0_FW_FILE,
54 .otp = QCA988X_HW_2_0_OTP_FILE,
55 .board = QCA988X_HW_2_0_BOARD_DATA_FILE,
56 .board_size = QCA988X_BOARD_DATA_SZ,
57 .board_ext_size = QCA988X_BOARD_EXT_DATA_SZ,
58 },
59 },
60 {
61 .id = QCA6174_HW_2_1_VERSION,
62 .name = "qca6174 hw2.1",
63 .patch_load_addr = QCA6174_HW_2_1_PATCH_LOAD_ADDR,
64 .uart_pin = 6,
65 .fw = {
66 .dir = QCA6174_HW_2_1_FW_DIR,
67 .fw = QCA6174_HW_2_1_FW_FILE,
68 .otp = QCA6174_HW_2_1_OTP_FILE,
69 .board = QCA6174_HW_2_1_BOARD_DATA_FILE,
70 .board_size = QCA6174_BOARD_DATA_SZ,
71 .board_ext_size = QCA6174_BOARD_EXT_DATA_SZ,
72 },
73 },
74 {
75 .id = QCA6174_HW_3_0_VERSION,
76 .name = "qca6174 hw3.0",
77 .patch_load_addr = QCA6174_HW_3_0_PATCH_LOAD_ADDR,
78 .uart_pin = 6,
79 .fw = {
80 .dir = QCA6174_HW_3_0_FW_DIR,
81 .fw = QCA6174_HW_3_0_FW_FILE,
82 .otp = QCA6174_HW_3_0_OTP_FILE,
83 .board = QCA6174_HW_3_0_BOARD_DATA_FILE,
84 .board_size = QCA6174_BOARD_DATA_SZ,
85 .board_ext_size = QCA6174_BOARD_EXT_DATA_SZ,
86 },
87 },
88 };
89
90 static void ath10k_send_suspend_complete(struct ath10k *ar)
91 {
92 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot suspend complete\n");
93
94 complete(&ar->target_suspend);
95 }
96
97 static int ath10k_init_configure_target(struct ath10k *ar)
98 {
99 u32 param_host;
100 int ret;
101
102 /* tell target which HTC version it is used*/
103 ret = ath10k_bmi_write32(ar, hi_app_host_interest,
104 HTC_PROTOCOL_VERSION);
105 if (ret) {
106 ath10k_err(ar, "settings HTC version failed\n");
107 return ret;
108 }
109
110 /* set the firmware mode to STA/IBSS/AP */
111 ret = ath10k_bmi_read32(ar, hi_option_flag, &param_host);
112 if (ret) {
113 ath10k_err(ar, "setting firmware mode (1/2) failed\n");
114 return ret;
115 }
116
117 /* TODO following parameters need to be re-visited. */
118 /* num_device */
119 param_host |= (1 << HI_OPTION_NUM_DEV_SHIFT);
120 /* Firmware mode */
121 /* FIXME: Why FW_MODE_AP ??.*/
122 param_host |= (HI_OPTION_FW_MODE_AP << HI_OPTION_FW_MODE_SHIFT);
123 /* mac_addr_method */
124 param_host |= (1 << HI_OPTION_MAC_ADDR_METHOD_SHIFT);
125 /* firmware_bridge */
126 param_host |= (0 << HI_OPTION_FW_BRIDGE_SHIFT);
127 /* fwsubmode */
128 param_host |= (0 << HI_OPTION_FW_SUBMODE_SHIFT);
129
130 ret = ath10k_bmi_write32(ar, hi_option_flag, param_host);
131 if (ret) {
132 ath10k_err(ar, "setting firmware mode (2/2) failed\n");
133 return ret;
134 }
135
136 /* We do all byte-swapping on the host */
137 ret = ath10k_bmi_write32(ar, hi_be, 0);
138 if (ret) {
139 ath10k_err(ar, "setting host CPU BE mode failed\n");
140 return ret;
141 }
142
143 /* FW descriptor/Data swap flags */
144 ret = ath10k_bmi_write32(ar, hi_fw_swap, 0);
145
146 if (ret) {
147 ath10k_err(ar, "setting FW data/desc swap flags failed\n");
148 return ret;
149 }
150
151 return 0;
152 }
153
154 static const struct firmware *ath10k_fetch_fw_file(struct ath10k *ar,
155 const char *dir,
156 const char *file)
157 {
158 char filename[100];
159 const struct firmware *fw;
160 int ret;
161
162 if (file == NULL)
163 return ERR_PTR(-ENOENT);
164
165 if (dir == NULL)
166 dir = ".";
167
168 snprintf(filename, sizeof(filename), "%s/%s", dir, file);
169 ret = request_firmware(&fw, filename, ar->dev);
170 if (ret)
171 return ERR_PTR(ret);
172
173 return fw;
174 }
175
176 static int ath10k_push_board_ext_data(struct ath10k *ar, const void *data,
177 size_t data_len)
178 {
179 u32 board_data_size = ar->hw_params.fw.board_size;
180 u32 board_ext_data_size = ar->hw_params.fw.board_ext_size;
181 u32 board_ext_data_addr;
182 int ret;
183
184 ret = ath10k_bmi_read32(ar, hi_board_ext_data, &board_ext_data_addr);
185 if (ret) {
186 ath10k_err(ar, "could not read board ext data addr (%d)\n",
187 ret);
188 return ret;
189 }
190
191 ath10k_dbg(ar, ATH10K_DBG_BOOT,
192 "boot push board extended data addr 0x%x\n",
193 board_ext_data_addr);
194
195 if (board_ext_data_addr == 0)
196 return 0;
197
198 if (data_len != (board_data_size + board_ext_data_size)) {
199 ath10k_err(ar, "invalid board (ext) data sizes %zu != %d+%d\n",
200 data_len, board_data_size, board_ext_data_size);
201 return -EINVAL;
202 }
203
204 ret = ath10k_bmi_write_memory(ar, board_ext_data_addr,
205 data + board_data_size,
206 board_ext_data_size);
207 if (ret) {
208 ath10k_err(ar, "could not write board ext data (%d)\n", ret);
209 return ret;
210 }
211
212 ret = ath10k_bmi_write32(ar, hi_board_ext_data_config,
213 (board_ext_data_size << 16) | 1);
214 if (ret) {
215 ath10k_err(ar, "could not write board ext data bit (%d)\n",
216 ret);
217 return ret;
218 }
219
220 return 0;
221 }
222
223 static int ath10k_download_board_data(struct ath10k *ar, const void *data,
224 size_t data_len)
225 {
226 u32 board_data_size = ar->hw_params.fw.board_size;
227 u32 address;
228 int ret;
229
230 ret = ath10k_push_board_ext_data(ar, data, data_len);
231 if (ret) {
232 ath10k_err(ar, "could not push board ext data (%d)\n", ret);
233 goto exit;
234 }
235
236 ret = ath10k_bmi_read32(ar, hi_board_data, &address);
237 if (ret) {
238 ath10k_err(ar, "could not read board data addr (%d)\n", ret);
239 goto exit;
240 }
241
242 ret = ath10k_bmi_write_memory(ar, address, data,
243 min_t(u32, board_data_size,
244 data_len));
245 if (ret) {
246 ath10k_err(ar, "could not write board data (%d)\n", ret);
247 goto exit;
248 }
249
250 ret = ath10k_bmi_write32(ar, hi_board_data_initialized, 1);
251 if (ret) {
252 ath10k_err(ar, "could not write board data bit (%d)\n", ret);
253 goto exit;
254 }
255
256 exit:
257 return ret;
258 }
259
260 static int ath10k_download_cal_file(struct ath10k *ar)
261 {
262 int ret;
263
264 if (!ar->cal_file)
265 return -ENOENT;
266
267 if (IS_ERR(ar->cal_file))
268 return PTR_ERR(ar->cal_file);
269
270 ret = ath10k_download_board_data(ar, ar->cal_file->data,
271 ar->cal_file->size);
272 if (ret) {
273 ath10k_err(ar, "failed to download cal_file data: %d\n", ret);
274 return ret;
275 }
276
277 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot cal file downloaded\n");
278
279 return 0;
280 }
281
282 static int ath10k_download_cal_dt(struct ath10k *ar)
283 {
284 struct device_node *node;
285 int data_len;
286 void *data;
287 int ret;
288
289 node = ar->dev->of_node;
290 if (!node)
291 /* Device Tree is optional, don't print any warnings if
292 * there's no node for ath10k.
293 */
294 return -ENOENT;
295
296 if (!of_get_property(node, "qcom,ath10k-calibration-data",
297 &data_len)) {
298 /* The calibration data node is optional */
299 return -ENOENT;
300 }
301
302 if (data_len != QCA988X_CAL_DATA_LEN) {
303 ath10k_warn(ar, "invalid calibration data length in DT: %d\n",
304 data_len);
305 ret = -EMSGSIZE;
306 goto out;
307 }
308
309 data = kmalloc(data_len, GFP_KERNEL);
310 if (!data) {
311 ret = -ENOMEM;
312 goto out;
313 }
314
315 ret = of_property_read_u8_array(node, "qcom,ath10k-calibration-data",
316 data, data_len);
317 if (ret) {
318 ath10k_warn(ar, "failed to read calibration data from DT: %d\n",
319 ret);
320 goto out_free;
321 }
322
323 ret = ath10k_download_board_data(ar, data, data_len);
324 if (ret) {
325 ath10k_warn(ar, "failed to download calibration data from Device Tree: %d\n",
326 ret);
327 goto out_free;
328 }
329
330 ret = 0;
331
332 out_free:
333 kfree(data);
334
335 out:
336 return ret;
337 }
338
339 static int ath10k_download_and_run_otp(struct ath10k *ar)
340 {
341 u32 result, address = ar->hw_params.patch_load_addr;
342 int ret;
343
344 ret = ath10k_download_board_data(ar, ar->board_data, ar->board_len);
345 if (ret) {
346 ath10k_err(ar, "failed to download board data: %d\n", ret);
347 return ret;
348 }
349
350 /* OTP is optional */
351
352 if (!ar->otp_data || !ar->otp_len) {
353 ath10k_warn(ar, "Not running otp, calibration will be incorrect (otp-data %p otp_len %zd)!\n",
354 ar->otp_data, ar->otp_len);
355 return 0;
356 }
357
358 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot upload otp to 0x%x len %zd\n",
359 address, ar->otp_len);
360
361 ret = ath10k_bmi_fast_download(ar, address, ar->otp_data, ar->otp_len);
362 if (ret) {
363 ath10k_err(ar, "could not write otp (%d)\n", ret);
364 return ret;
365 }
366
367 ret = ath10k_bmi_execute(ar, address, 0, &result);
368 if (ret) {
369 ath10k_err(ar, "could not execute otp (%d)\n", ret);
370 return ret;
371 }
372
373 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot otp execute result %d\n", result);
374
375 if (!skip_otp && result != 0) {
376 ath10k_err(ar, "otp calibration failed: %d", result);
377 return -EINVAL;
378 }
379
380 return 0;
381 }
382
383 static int ath10k_download_fw(struct ath10k *ar, enum ath10k_firmware_mode mode)
384 {
385 u32 address, data_len;
386 const char *mode_name;
387 const void *data;
388 int ret;
389
390 address = ar->hw_params.patch_load_addr;
391
392 switch (mode) {
393 case ATH10K_FIRMWARE_MODE_NORMAL:
394 data = ar->firmware_data;
395 data_len = ar->firmware_len;
396 mode_name = "normal";
397 break;
398 case ATH10K_FIRMWARE_MODE_UTF:
399 data = ar->testmode.utf->data;
400 data_len = ar->testmode.utf->size;
401 mode_name = "utf";
402 break;
403 default:
404 ath10k_err(ar, "unknown firmware mode: %d\n", mode);
405 return -EINVAL;
406 }
407
408 ath10k_dbg(ar, ATH10K_DBG_BOOT,
409 "boot uploading firmware image %p len %d mode %s\n",
410 data, data_len, mode_name);
411
412 ret = ath10k_bmi_fast_download(ar, address, data, data_len);
413 if (ret) {
414 ath10k_err(ar, "failed to download %s firmware: %d\n",
415 mode_name, ret);
416 return ret;
417 }
418
419 return ret;
420 }
421
422 static void ath10k_core_free_firmware_files(struct ath10k *ar)
423 {
424 if (ar->board && !IS_ERR(ar->board))
425 release_firmware(ar->board);
426
427 if (ar->otp && !IS_ERR(ar->otp))
428 release_firmware(ar->otp);
429
430 if (ar->firmware && !IS_ERR(ar->firmware))
431 release_firmware(ar->firmware);
432
433 if (ar->cal_file && !IS_ERR(ar->cal_file))
434 release_firmware(ar->cal_file);
435
436 ar->board = NULL;
437 ar->board_data = NULL;
438 ar->board_len = 0;
439
440 ar->otp = NULL;
441 ar->otp_data = NULL;
442 ar->otp_len = 0;
443
444 ar->firmware = NULL;
445 ar->firmware_data = NULL;
446 ar->firmware_len = 0;
447
448 ar->cal_file = NULL;
449 }
450
451 static int ath10k_fetch_cal_file(struct ath10k *ar)
452 {
453 char filename[100];
454
455 /* cal-<bus>-<id>.bin */
456 scnprintf(filename, sizeof(filename), "cal-%s-%s.bin",
457 ath10k_bus_str(ar->hif.bus), dev_name(ar->dev));
458
459 ar->cal_file = ath10k_fetch_fw_file(ar, ATH10K_FW_DIR, filename);
460 if (IS_ERR(ar->cal_file))
461 /* calibration file is optional, don't print any warnings */
462 return PTR_ERR(ar->cal_file);
463
464 ath10k_dbg(ar, ATH10K_DBG_BOOT, "found calibration file %s/%s\n",
465 ATH10K_FW_DIR, filename);
466
467 return 0;
468 }
469
470 static int ath10k_core_fetch_firmware_api_1(struct ath10k *ar)
471 {
472 int ret = 0;
473
474 if (ar->hw_params.fw.fw == NULL) {
475 ath10k_err(ar, "firmware file not defined\n");
476 return -EINVAL;
477 }
478
479 if (ar->hw_params.fw.board == NULL) {
480 ath10k_err(ar, "board data file not defined");
481 return -EINVAL;
482 }
483
484 ar->board = ath10k_fetch_fw_file(ar,
485 ar->hw_params.fw.dir,
486 ar->hw_params.fw.board);
487 if (IS_ERR(ar->board)) {
488 ret = PTR_ERR(ar->board);
489 ath10k_err(ar, "could not fetch board data (%d)\n", ret);
490 goto err;
491 }
492
493 ar->board_data = ar->board->data;
494 ar->board_len = ar->board->size;
495
496 ar->firmware = ath10k_fetch_fw_file(ar,
497 ar->hw_params.fw.dir,
498 ar->hw_params.fw.fw);
499 if (IS_ERR(ar->firmware)) {
500 ret = PTR_ERR(ar->firmware);
501 ath10k_err(ar, "could not fetch firmware (%d)\n", ret);
502 goto err;
503 }
504
505 ar->firmware_data = ar->firmware->data;
506 ar->firmware_len = ar->firmware->size;
507
508 /* OTP may be undefined. If so, don't fetch it at all */
509 if (ar->hw_params.fw.otp == NULL)
510 return 0;
511
512 ar->otp = ath10k_fetch_fw_file(ar,
513 ar->hw_params.fw.dir,
514 ar->hw_params.fw.otp);
515 if (IS_ERR(ar->otp)) {
516 ret = PTR_ERR(ar->otp);
517 ath10k_err(ar, "could not fetch otp (%d)\n", ret);
518 goto err;
519 }
520
521 ar->otp_data = ar->otp->data;
522 ar->otp_len = ar->otp->size;
523
524 return 0;
525
526 err:
527 ath10k_core_free_firmware_files(ar);
528 return ret;
529 }
530
531 static int ath10k_core_fetch_firmware_api_n(struct ath10k *ar, const char *name)
532 {
533 size_t magic_len, len, ie_len;
534 int ie_id, i, index, bit, ret;
535 struct ath10k_fw_ie *hdr;
536 const u8 *data;
537 __le32 *timestamp, *version;
538
539 /* first fetch the firmware file (firmware-*.bin) */
540 ar->firmware = ath10k_fetch_fw_file(ar, ar->hw_params.fw.dir, name);
541 if (IS_ERR(ar->firmware)) {
542 ath10k_err(ar, "could not fetch firmware file '%s/%s': %ld\n",
543 ar->hw_params.fw.dir, name, PTR_ERR(ar->firmware));
544 return PTR_ERR(ar->firmware);
545 }
546
547 data = ar->firmware->data;
548 len = ar->firmware->size;
549
550 /* magic also includes the null byte, check that as well */
551 magic_len = strlen(ATH10K_FIRMWARE_MAGIC) + 1;
552
553 if (len < magic_len) {
554 ath10k_err(ar, "firmware file '%s/%s' too small to contain magic: %zu\n",
555 ar->hw_params.fw.dir, name, len);
556 ret = -EINVAL;
557 goto err;
558 }
559
560 if (memcmp(data, ATH10K_FIRMWARE_MAGIC, magic_len) != 0) {
561 ath10k_err(ar, "invalid firmware magic\n");
562 ret = -EINVAL;
563 goto err;
564 }
565
566 /* jump over the padding */
567 magic_len = ALIGN(magic_len, 4);
568
569 len -= magic_len;
570 data += magic_len;
571
572 /* loop elements */
573 while (len > sizeof(struct ath10k_fw_ie)) {
574 hdr = (struct ath10k_fw_ie *)data;
575
576 ie_id = le32_to_cpu(hdr->id);
577 ie_len = le32_to_cpu(hdr->len);
578
579 len -= sizeof(*hdr);
580 data += sizeof(*hdr);
581
582 if (len < ie_len) {
583 ath10k_err(ar, "invalid length for FW IE %d (%zu < %zu)\n",
584 ie_id, len, ie_len);
585 ret = -EINVAL;
586 goto err;
587 }
588
589 switch (ie_id) {
590 case ATH10K_FW_IE_FW_VERSION:
591 if (ie_len > sizeof(ar->hw->wiphy->fw_version) - 1)
592 break;
593
594 memcpy(ar->hw->wiphy->fw_version, data, ie_len);
595 ar->hw->wiphy->fw_version[ie_len] = '\0';
596
597 ath10k_dbg(ar, ATH10K_DBG_BOOT,
598 "found fw version %s\n",
599 ar->hw->wiphy->fw_version);
600 break;
601 case ATH10K_FW_IE_TIMESTAMP:
602 if (ie_len != sizeof(u32))
603 break;
604
605 timestamp = (__le32 *)data;
606
607 ath10k_dbg(ar, ATH10K_DBG_BOOT, "found fw timestamp %d\n",
608 le32_to_cpup(timestamp));
609 break;
610 case ATH10K_FW_IE_FEATURES:
611 ath10k_dbg(ar, ATH10K_DBG_BOOT,
612 "found firmware features ie (%zd B)\n",
613 ie_len);
614
615 for (i = 0; i < ATH10K_FW_FEATURE_COUNT; i++) {
616 index = i / 8;
617 bit = i % 8;
618
619 if (index == ie_len)
620 break;
621
622 if (data[index] & (1 << bit)) {
623 ath10k_dbg(ar, ATH10K_DBG_BOOT,
624 "Enabling feature bit: %i\n",
625 i);
626 __set_bit(i, ar->fw_features);
627 }
628 }
629
630 ath10k_dbg_dump(ar, ATH10K_DBG_BOOT, "features", "",
631 ar->fw_features,
632 sizeof(ar->fw_features));
633 break;
634 case ATH10K_FW_IE_FW_IMAGE:
635 ath10k_dbg(ar, ATH10K_DBG_BOOT,
636 "found fw image ie (%zd B)\n",
637 ie_len);
638
639 ar->firmware_data = data;
640 ar->firmware_len = ie_len;
641
642 break;
643 case ATH10K_FW_IE_OTP_IMAGE:
644 ath10k_dbg(ar, ATH10K_DBG_BOOT,
645 "found otp image ie (%zd B)\n",
646 ie_len);
647
648 ar->otp_data = data;
649 ar->otp_len = ie_len;
650
651 break;
652 case ATH10K_FW_IE_WMI_OP_VERSION:
653 if (ie_len != sizeof(u32))
654 break;
655
656 version = (__le32 *)data;
657
658 ar->wmi.op_version = le32_to_cpup(version);
659
660 ath10k_dbg(ar, ATH10K_DBG_BOOT, "found fw ie wmi op version %d\n",
661 ar->wmi.op_version);
662 break;
663 default:
664 ath10k_warn(ar, "Unknown FW IE: %u\n",
665 le32_to_cpu(hdr->id));
666 break;
667 }
668
669 /* jump over the padding */
670 ie_len = ALIGN(ie_len, 4);
671
672 len -= ie_len;
673 data += ie_len;
674 }
675
676 if (!ar->firmware_data || !ar->firmware_len) {
677 ath10k_warn(ar, "No ATH10K_FW_IE_FW_IMAGE found from '%s/%s', skipping\n",
678 ar->hw_params.fw.dir, name);
679 ret = -ENOMEDIUM;
680 goto err;
681 }
682
683 /* now fetch the board file */
684 if (ar->hw_params.fw.board == NULL) {
685 ath10k_err(ar, "board data file not defined");
686 ret = -EINVAL;
687 goto err;
688 }
689
690 ar->board = ath10k_fetch_fw_file(ar,
691 ar->hw_params.fw.dir,
692 ar->hw_params.fw.board);
693 if (IS_ERR(ar->board)) {
694 ret = PTR_ERR(ar->board);
695 ath10k_err(ar, "could not fetch board data '%s/%s' (%d)\n",
696 ar->hw_params.fw.dir, ar->hw_params.fw.board,
697 ret);
698 goto err;
699 }
700
701 ar->board_data = ar->board->data;
702 ar->board_len = ar->board->size;
703
704 return 0;
705
706 err:
707 ath10k_core_free_firmware_files(ar);
708 return ret;
709 }
710
711 static int ath10k_core_fetch_firmware_files(struct ath10k *ar)
712 {
713 int ret;
714
715 /* calibration file is optional, don't check for any errors */
716 ath10k_fetch_cal_file(ar);
717
718 ar->fw_api = 4;
719 ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
720
721 ret = ath10k_core_fetch_firmware_api_n(ar, ATH10K_FW_API4_FILE);
722 if (ret == 0)
723 goto success;
724
725 ar->fw_api = 3;
726 ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
727
728 ret = ath10k_core_fetch_firmware_api_n(ar, ATH10K_FW_API3_FILE);
729 if (ret == 0)
730 goto success;
731
732 ar->fw_api = 2;
733 ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
734
735 ret = ath10k_core_fetch_firmware_api_n(ar, ATH10K_FW_API2_FILE);
736 if (ret == 0)
737 goto success;
738
739 ar->fw_api = 1;
740 ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
741
742 ret = ath10k_core_fetch_firmware_api_1(ar);
743 if (ret)
744 return ret;
745
746 success:
747 ath10k_dbg(ar, ATH10K_DBG_BOOT, "using fw api %d\n", ar->fw_api);
748
749 return 0;
750 }
751
752 static int ath10k_download_cal_data(struct ath10k *ar)
753 {
754 int ret;
755
756 ret = ath10k_download_cal_file(ar);
757 if (ret == 0) {
758 ar->cal_mode = ATH10K_CAL_MODE_FILE;
759 goto done;
760 }
761
762 ath10k_dbg(ar, ATH10K_DBG_BOOT,
763 "boot did not find a calibration file, try DT next: %d\n",
764 ret);
765
766 ret = ath10k_download_cal_dt(ar);
767 if (ret == 0) {
768 ar->cal_mode = ATH10K_CAL_MODE_DT;
769 goto done;
770 }
771
772 ath10k_dbg(ar, ATH10K_DBG_BOOT,
773 "boot did not find DT entry, try OTP next: %d\n",
774 ret);
775
776 ret = ath10k_download_and_run_otp(ar);
777 if (ret) {
778 ath10k_err(ar, "failed to run otp: %d\n", ret);
779 return ret;
780 }
781
782 ar->cal_mode = ATH10K_CAL_MODE_OTP;
783
784 done:
785 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot using calibration mode %s\n",
786 ath10k_cal_mode_str(ar->cal_mode));
787 return 0;
788 }
789
790 static int ath10k_init_uart(struct ath10k *ar)
791 {
792 int ret;
793
794 /*
795 * Explicitly setting UART prints to zero as target turns it on
796 * based on scratch registers.
797 */
798 ret = ath10k_bmi_write32(ar, hi_serial_enable, 0);
799 if (ret) {
800 ath10k_warn(ar, "could not disable UART prints (%d)\n", ret);
801 return ret;
802 }
803
804 if (!uart_print)
805 return 0;
806
807 ret = ath10k_bmi_write32(ar, hi_dbg_uart_txpin, ar->hw_params.uart_pin);
808 if (ret) {
809 ath10k_warn(ar, "could not enable UART prints (%d)\n", ret);
810 return ret;
811 }
812
813 ret = ath10k_bmi_write32(ar, hi_serial_enable, 1);
814 if (ret) {
815 ath10k_warn(ar, "could not enable UART prints (%d)\n", ret);
816 return ret;
817 }
818
819 /* Set the UART baud rate to 19200. */
820 ret = ath10k_bmi_write32(ar, hi_desired_baud_rate, 19200);
821 if (ret) {
822 ath10k_warn(ar, "could not set the baud rate (%d)\n", ret);
823 return ret;
824 }
825
826 ath10k_info(ar, "UART prints enabled\n");
827 return 0;
828 }
829
830 static int ath10k_init_hw_params(struct ath10k *ar)
831 {
832 const struct ath10k_hw_params *uninitialized_var(hw_params);
833 int i;
834
835 for (i = 0; i < ARRAY_SIZE(ath10k_hw_params_list); i++) {
836 hw_params = &ath10k_hw_params_list[i];
837
838 if (hw_params->id == ar->target_version)
839 break;
840 }
841
842 if (i == ARRAY_SIZE(ath10k_hw_params_list)) {
843 ath10k_err(ar, "Unsupported hardware version: 0x%x\n",
844 ar->target_version);
845 return -EINVAL;
846 }
847
848 ar->hw_params = *hw_params;
849
850 ath10k_dbg(ar, ATH10K_DBG_BOOT, "Hardware name %s version 0x%x\n",
851 ar->hw_params.name, ar->target_version);
852
853 return 0;
854 }
855
856 static void ath10k_core_restart(struct work_struct *work)
857 {
858 struct ath10k *ar = container_of(work, struct ath10k, restart_work);
859
860 set_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags);
861
862 /* Place a barrier to make sure the compiler doesn't reorder
863 * CRASH_FLUSH and calling other functions.
864 */
865 barrier();
866
867 ieee80211_stop_queues(ar->hw);
868 ath10k_drain_tx(ar);
869 complete_all(&ar->scan.started);
870 complete_all(&ar->scan.completed);
871 complete_all(&ar->scan.on_channel);
872 complete_all(&ar->offchan_tx_completed);
873 complete_all(&ar->install_key_done);
874 complete_all(&ar->vdev_setup_done);
875 complete_all(&ar->thermal.wmi_sync);
876 wake_up(&ar->htt.empty_tx_wq);
877 wake_up(&ar->wmi.tx_credits_wq);
878 wake_up(&ar->peer_mapping_wq);
879
880 mutex_lock(&ar->conf_mutex);
881
882 switch (ar->state) {
883 case ATH10K_STATE_ON:
884 ar->state = ATH10K_STATE_RESTARTING;
885 ath10k_hif_stop(ar);
886 ath10k_scan_finish(ar);
887 ieee80211_restart_hw(ar->hw);
888 break;
889 case ATH10K_STATE_OFF:
890 /* this can happen if driver is being unloaded
891 * or if the crash happens during FW probing */
892 ath10k_warn(ar, "cannot restart a device that hasn't been started\n");
893 break;
894 case ATH10K_STATE_RESTARTING:
895 /* hw restart might be requested from multiple places */
896 break;
897 case ATH10K_STATE_RESTARTED:
898 ar->state = ATH10K_STATE_WEDGED;
899 /* fall through */
900 case ATH10K_STATE_WEDGED:
901 ath10k_warn(ar, "device is wedged, will not restart\n");
902 break;
903 case ATH10K_STATE_UTF:
904 ath10k_warn(ar, "firmware restart in UTF mode not supported\n");
905 break;
906 }
907
908 mutex_unlock(&ar->conf_mutex);
909 }
910
911 static int ath10k_core_init_firmware_features(struct ath10k *ar)
912 {
913 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2, ar->fw_features) &&
914 !test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
915 ath10k_err(ar, "feature bits corrupted: 10.2 feature requires 10.x feature to be set as well");
916 return -EINVAL;
917 }
918
919 if (ar->wmi.op_version >= ATH10K_FW_WMI_OP_VERSION_MAX) {
920 ath10k_err(ar, "unsupported WMI OP version (max %d): %d\n",
921 ATH10K_FW_WMI_OP_VERSION_MAX, ar->wmi.op_version);
922 return -EINVAL;
923 }
924
925 /* Backwards compatibility for firmwares without
926 * ATH10K_FW_IE_WMI_OP_VERSION.
927 */
928 if (ar->wmi.op_version == ATH10K_FW_WMI_OP_VERSION_UNSET) {
929 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
930 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2,
931 ar->fw_features))
932 ar->wmi.op_version = ATH10K_FW_WMI_OP_VERSION_10_2;
933 else
934 ar->wmi.op_version = ATH10K_FW_WMI_OP_VERSION_10_1;
935 } else {
936 ar->wmi.op_version = ATH10K_FW_WMI_OP_VERSION_MAIN;
937 }
938 }
939
940 switch (ar->wmi.op_version) {
941 case ATH10K_FW_WMI_OP_VERSION_MAIN:
942 ar->max_num_peers = TARGET_NUM_PEERS;
943 ar->max_num_stations = TARGET_NUM_STATIONS;
944 ar->max_num_vdevs = TARGET_NUM_VDEVS;
945 ar->htt.max_num_pending_tx = TARGET_NUM_MSDU_DESC;
946 break;
947 case ATH10K_FW_WMI_OP_VERSION_10_1:
948 case ATH10K_FW_WMI_OP_VERSION_10_2:
949 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
950 ar->max_num_peers = TARGET_10X_NUM_PEERS;
951 ar->max_num_stations = TARGET_10X_NUM_STATIONS;
952 ar->max_num_vdevs = TARGET_10X_NUM_VDEVS;
953 ar->htt.max_num_pending_tx = TARGET_10X_NUM_MSDU_DESC;
954 break;
955 case ATH10K_FW_WMI_OP_VERSION_TLV:
956 ar->max_num_peers = TARGET_TLV_NUM_PEERS;
957 ar->max_num_stations = TARGET_TLV_NUM_STATIONS;
958 ar->max_num_vdevs = TARGET_TLV_NUM_VDEVS;
959 ar->htt.max_num_pending_tx = TARGET_TLV_NUM_MSDU_DESC;
960 break;
961 case ATH10K_FW_WMI_OP_VERSION_UNSET:
962 case ATH10K_FW_WMI_OP_VERSION_MAX:
963 WARN_ON(1);
964 return -EINVAL;
965 }
966
967 return 0;
968 }
969
970 int ath10k_core_start(struct ath10k *ar, enum ath10k_firmware_mode mode)
971 {
972 int status;
973
974 lockdep_assert_held(&ar->conf_mutex);
975
976 clear_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags);
977
978 ath10k_bmi_start(ar);
979
980 if (ath10k_init_configure_target(ar)) {
981 status = -EINVAL;
982 goto err;
983 }
984
985 status = ath10k_download_cal_data(ar);
986 if (status)
987 goto err;
988
989 status = ath10k_download_fw(ar, mode);
990 if (status)
991 goto err;
992
993 status = ath10k_init_uart(ar);
994 if (status)
995 goto err;
996
997 ar->htc.htc_ops.target_send_suspend_complete =
998 ath10k_send_suspend_complete;
999
1000 status = ath10k_htc_init(ar);
1001 if (status) {
1002 ath10k_err(ar, "could not init HTC (%d)\n", status);
1003 goto err;
1004 }
1005
1006 status = ath10k_bmi_done(ar);
1007 if (status)
1008 goto err;
1009
1010 status = ath10k_wmi_attach(ar);
1011 if (status) {
1012 ath10k_err(ar, "WMI attach failed: %d\n", status);
1013 goto err;
1014 }
1015
1016 status = ath10k_htt_init(ar);
1017 if (status) {
1018 ath10k_err(ar, "failed to init htt: %d\n", status);
1019 goto err_wmi_detach;
1020 }
1021
1022 status = ath10k_htt_tx_alloc(&ar->htt);
1023 if (status) {
1024 ath10k_err(ar, "failed to alloc htt tx: %d\n", status);
1025 goto err_wmi_detach;
1026 }
1027
1028 status = ath10k_htt_rx_alloc(&ar->htt);
1029 if (status) {
1030 ath10k_err(ar, "failed to alloc htt rx: %d\n", status);
1031 goto err_htt_tx_detach;
1032 }
1033
1034 status = ath10k_hif_start(ar);
1035 if (status) {
1036 ath10k_err(ar, "could not start HIF: %d\n", status);
1037 goto err_htt_rx_detach;
1038 }
1039
1040 status = ath10k_htc_wait_target(&ar->htc);
1041 if (status) {
1042 ath10k_err(ar, "failed to connect to HTC: %d\n", status);
1043 goto err_hif_stop;
1044 }
1045
1046 if (mode == ATH10K_FIRMWARE_MODE_NORMAL) {
1047 status = ath10k_htt_connect(&ar->htt);
1048 if (status) {
1049 ath10k_err(ar, "failed to connect htt (%d)\n", status);
1050 goto err_hif_stop;
1051 }
1052 }
1053
1054 status = ath10k_wmi_connect(ar);
1055 if (status) {
1056 ath10k_err(ar, "could not connect wmi: %d\n", status);
1057 goto err_hif_stop;
1058 }
1059
1060 status = ath10k_htc_start(&ar->htc);
1061 if (status) {
1062 ath10k_err(ar, "failed to start htc: %d\n", status);
1063 goto err_hif_stop;
1064 }
1065
1066 if (mode == ATH10K_FIRMWARE_MODE_NORMAL) {
1067 status = ath10k_wmi_wait_for_service_ready(ar);
1068 if (status <= 0) {
1069 ath10k_warn(ar, "wmi service ready event not received");
1070 status = -ETIMEDOUT;
1071 goto err_hif_stop;
1072 }
1073 }
1074
1075 ath10k_dbg(ar, ATH10K_DBG_BOOT, "firmware %s booted\n",
1076 ar->hw->wiphy->fw_version);
1077
1078 status = ath10k_wmi_cmd_init(ar);
1079 if (status) {
1080 ath10k_err(ar, "could not send WMI init command (%d)\n",
1081 status);
1082 goto err_hif_stop;
1083 }
1084
1085 status = ath10k_wmi_wait_for_unified_ready(ar);
1086 if (status <= 0) {
1087 ath10k_err(ar, "wmi unified ready event not received\n");
1088 status = -ETIMEDOUT;
1089 goto err_hif_stop;
1090 }
1091
1092 /* If firmware indicates Full Rx Reorder support it must be used in a
1093 * slightly different manner. Let HTT code know.
1094 */
1095 ar->htt.rx_ring.in_ord_rx = !!(test_bit(WMI_SERVICE_RX_FULL_REORDER,
1096 ar->wmi.svc_map));
1097
1098 status = ath10k_htt_rx_ring_refill(ar);
1099 if (status) {
1100 ath10k_err(ar, "failed to refill htt rx ring: %d\n", status);
1101 goto err_hif_stop;
1102 }
1103
1104 /* we don't care about HTT in UTF mode */
1105 if (mode == ATH10K_FIRMWARE_MODE_NORMAL) {
1106 status = ath10k_htt_setup(&ar->htt);
1107 if (status) {
1108 ath10k_err(ar, "failed to setup htt: %d\n", status);
1109 goto err_hif_stop;
1110 }
1111 }
1112
1113 status = ath10k_debug_start(ar);
1114 if (status)
1115 goto err_hif_stop;
1116
1117 ar->free_vdev_map = (1LL << ar->max_num_vdevs) - 1;
1118
1119 INIT_LIST_HEAD(&ar->arvifs);
1120
1121 return 0;
1122
1123 err_hif_stop:
1124 ath10k_hif_stop(ar);
1125 err_htt_rx_detach:
1126 ath10k_htt_rx_free(&ar->htt);
1127 err_htt_tx_detach:
1128 ath10k_htt_tx_free(&ar->htt);
1129 err_wmi_detach:
1130 ath10k_wmi_detach(ar);
1131 err:
1132 return status;
1133 }
1134 EXPORT_SYMBOL(ath10k_core_start);
1135
1136 int ath10k_wait_for_suspend(struct ath10k *ar, u32 suspend_opt)
1137 {
1138 int ret;
1139
1140 reinit_completion(&ar->target_suspend);
1141
1142 ret = ath10k_wmi_pdev_suspend_target(ar, suspend_opt);
1143 if (ret) {
1144 ath10k_warn(ar, "could not suspend target (%d)\n", ret);
1145 return ret;
1146 }
1147
1148 ret = wait_for_completion_timeout(&ar->target_suspend, 1 * HZ);
1149
1150 if (ret == 0) {
1151 ath10k_warn(ar, "suspend timed out - target pause event never came\n");
1152 return -ETIMEDOUT;
1153 }
1154
1155 return 0;
1156 }
1157
1158 void ath10k_core_stop(struct ath10k *ar)
1159 {
1160 lockdep_assert_held(&ar->conf_mutex);
1161
1162 /* try to suspend target */
1163 if (ar->state != ATH10K_STATE_RESTARTING &&
1164 ar->state != ATH10K_STATE_UTF)
1165 ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND_AND_DISABLE_INTR);
1166
1167 ath10k_debug_stop(ar);
1168 ath10k_hif_stop(ar);
1169 ath10k_htt_tx_free(&ar->htt);
1170 ath10k_htt_rx_free(&ar->htt);
1171 ath10k_wmi_detach(ar);
1172 }
1173 EXPORT_SYMBOL(ath10k_core_stop);
1174
1175 /* mac80211 manages fw/hw initialization through start/stop hooks. However in
1176 * order to know what hw capabilities should be advertised to mac80211 it is
1177 * necessary to load the firmware (and tear it down immediately since start
1178 * hook will try to init it again) before registering */
1179 static int ath10k_core_probe_fw(struct ath10k *ar)
1180 {
1181 struct bmi_target_info target_info;
1182 int ret = 0;
1183
1184 ret = ath10k_hif_power_up(ar);
1185 if (ret) {
1186 ath10k_err(ar, "could not start pci hif (%d)\n", ret);
1187 return ret;
1188 }
1189
1190 memset(&target_info, 0, sizeof(target_info));
1191 ret = ath10k_bmi_get_target_info(ar, &target_info);
1192 if (ret) {
1193 ath10k_err(ar, "could not get target info (%d)\n", ret);
1194 goto err_power_down;
1195 }
1196
1197 ar->target_version = target_info.version;
1198 ar->hw->wiphy->hw_version = target_info.version;
1199
1200 ret = ath10k_init_hw_params(ar);
1201 if (ret) {
1202 ath10k_err(ar, "could not get hw params (%d)\n", ret);
1203 goto err_power_down;
1204 }
1205
1206 ret = ath10k_core_fetch_firmware_files(ar);
1207 if (ret) {
1208 ath10k_err(ar, "could not fetch firmware files (%d)\n", ret);
1209 goto err_power_down;
1210 }
1211
1212 ret = ath10k_core_init_firmware_features(ar);
1213 if (ret) {
1214 ath10k_err(ar, "fatal problem with firmware features: %d\n",
1215 ret);
1216 goto err_free_firmware_files;
1217 }
1218
1219 mutex_lock(&ar->conf_mutex);
1220
1221 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
1222 if (ret) {
1223 ath10k_err(ar, "could not init core (%d)\n", ret);
1224 goto err_unlock;
1225 }
1226
1227 ath10k_print_driver_info(ar);
1228 ath10k_core_stop(ar);
1229
1230 mutex_unlock(&ar->conf_mutex);
1231
1232 ath10k_hif_power_down(ar);
1233 return 0;
1234
1235 err_unlock:
1236 mutex_unlock(&ar->conf_mutex);
1237
1238 err_free_firmware_files:
1239 ath10k_core_free_firmware_files(ar);
1240
1241 err_power_down:
1242 ath10k_hif_power_down(ar);
1243
1244 return ret;
1245 }
1246
1247 static void ath10k_core_register_work(struct work_struct *work)
1248 {
1249 struct ath10k *ar = container_of(work, struct ath10k, register_work);
1250 int status;
1251
1252 status = ath10k_core_probe_fw(ar);
1253 if (status) {
1254 ath10k_err(ar, "could not probe fw (%d)\n", status);
1255 goto err;
1256 }
1257
1258 status = ath10k_mac_register(ar);
1259 if (status) {
1260 ath10k_err(ar, "could not register to mac80211 (%d)\n", status);
1261 goto err_release_fw;
1262 }
1263
1264 status = ath10k_debug_register(ar);
1265 if (status) {
1266 ath10k_err(ar, "unable to initialize debugfs\n");
1267 goto err_unregister_mac;
1268 }
1269
1270 status = ath10k_spectral_create(ar);
1271 if (status) {
1272 ath10k_err(ar, "failed to initialize spectral\n");
1273 goto err_debug_destroy;
1274 }
1275
1276 status = ath10k_thermal_register(ar);
1277 if (status) {
1278 ath10k_err(ar, "could not register thermal device: %d\n",
1279 status);
1280 goto err_spectral_destroy;
1281 }
1282
1283 set_bit(ATH10K_FLAG_CORE_REGISTERED, &ar->dev_flags);
1284 return;
1285
1286 err_spectral_destroy:
1287 ath10k_spectral_destroy(ar);
1288 err_debug_destroy:
1289 ath10k_debug_destroy(ar);
1290 err_unregister_mac:
1291 ath10k_mac_unregister(ar);
1292 err_release_fw:
1293 ath10k_core_free_firmware_files(ar);
1294 err:
1295 /* TODO: It's probably a good idea to release device from the driver
1296 * but calling device_release_driver() here will cause a deadlock.
1297 */
1298 return;
1299 }
1300
1301 int ath10k_core_register(struct ath10k *ar, u32 chip_id)
1302 {
1303 ar->chip_id = chip_id;
1304 queue_work(ar->workqueue, &ar->register_work);
1305
1306 return 0;
1307 }
1308 EXPORT_SYMBOL(ath10k_core_register);
1309
1310 void ath10k_core_unregister(struct ath10k *ar)
1311 {
1312 cancel_work_sync(&ar->register_work);
1313
1314 if (!test_bit(ATH10K_FLAG_CORE_REGISTERED, &ar->dev_flags))
1315 return;
1316
1317 ath10k_thermal_unregister(ar);
1318 /* Stop spectral before unregistering from mac80211 to remove the
1319 * relayfs debugfs file cleanly. Otherwise the parent debugfs tree
1320 * would be already be free'd recursively, leading to a double free.
1321 */
1322 ath10k_spectral_destroy(ar);
1323
1324 /* We must unregister from mac80211 before we stop HTC and HIF.
1325 * Otherwise we will fail to submit commands to FW and mac80211 will be
1326 * unhappy about callback failures. */
1327 ath10k_mac_unregister(ar);
1328
1329 ath10k_testmode_destroy(ar);
1330
1331 ath10k_core_free_firmware_files(ar);
1332
1333 ath10k_debug_unregister(ar);
1334 }
1335 EXPORT_SYMBOL(ath10k_core_unregister);
1336
1337 struct ath10k *ath10k_core_create(size_t priv_size, struct device *dev,
1338 enum ath10k_bus bus,
1339 enum ath10k_hw_rev hw_rev,
1340 const struct ath10k_hif_ops *hif_ops)
1341 {
1342 struct ath10k *ar;
1343 int ret;
1344
1345 ar = ath10k_mac_create(priv_size);
1346 if (!ar)
1347 return NULL;
1348
1349 ar->ath_common.priv = ar;
1350 ar->ath_common.hw = ar->hw;
1351 ar->dev = dev;
1352 ar->hw_rev = hw_rev;
1353 ar->hif.ops = hif_ops;
1354 ar->hif.bus = bus;
1355
1356 switch (hw_rev) {
1357 case ATH10K_HW_QCA988X:
1358 ar->regs = &qca988x_regs;
1359 break;
1360 case ATH10K_HW_QCA6174:
1361 ar->regs = &qca6174_regs;
1362 break;
1363 default:
1364 ath10k_err(ar, "unsupported core hardware revision %d\n",
1365 hw_rev);
1366 ret = -ENOTSUPP;
1367 goto err_free_mac;
1368 }
1369
1370 init_completion(&ar->scan.started);
1371 init_completion(&ar->scan.completed);
1372 init_completion(&ar->scan.on_channel);
1373 init_completion(&ar->target_suspend);
1374
1375 init_completion(&ar->install_key_done);
1376 init_completion(&ar->vdev_setup_done);
1377 init_completion(&ar->thermal.wmi_sync);
1378
1379 INIT_DELAYED_WORK(&ar->scan.timeout, ath10k_scan_timeout_work);
1380
1381 ar->workqueue = create_singlethread_workqueue("ath10k_wq");
1382 if (!ar->workqueue)
1383 goto err_free_mac;
1384
1385 mutex_init(&ar->conf_mutex);
1386 spin_lock_init(&ar->data_lock);
1387
1388 INIT_LIST_HEAD(&ar->peers);
1389 init_waitqueue_head(&ar->peer_mapping_wq);
1390 init_waitqueue_head(&ar->htt.empty_tx_wq);
1391 init_waitqueue_head(&ar->wmi.tx_credits_wq);
1392
1393 init_completion(&ar->offchan_tx_completed);
1394 INIT_WORK(&ar->offchan_tx_work, ath10k_offchan_tx_work);
1395 skb_queue_head_init(&ar->offchan_tx_queue);
1396
1397 INIT_WORK(&ar->wmi_mgmt_tx_work, ath10k_mgmt_over_wmi_tx_work);
1398 skb_queue_head_init(&ar->wmi_mgmt_tx_queue);
1399
1400 INIT_WORK(&ar->register_work, ath10k_core_register_work);
1401 INIT_WORK(&ar->restart_work, ath10k_core_restart);
1402
1403 ret = ath10k_debug_create(ar);
1404 if (ret)
1405 goto err_free_wq;
1406
1407 return ar;
1408
1409 err_free_wq:
1410 destroy_workqueue(ar->workqueue);
1411
1412 err_free_mac:
1413 ath10k_mac_destroy(ar);
1414
1415 return NULL;
1416 }
1417 EXPORT_SYMBOL(ath10k_core_create);
1418
1419 void ath10k_core_destroy(struct ath10k *ar)
1420 {
1421 flush_workqueue(ar->workqueue);
1422 destroy_workqueue(ar->workqueue);
1423
1424 ath10k_debug_destroy(ar);
1425 ath10k_mac_destroy(ar);
1426 }
1427 EXPORT_SYMBOL(ath10k_core_destroy);
1428
1429 MODULE_AUTHOR("Qualcomm Atheros");
1430 MODULE_DESCRIPTION("Core module for QCA988X PCIe devices.");
1431 MODULE_LICENSE("Dual BSD/GPL");
This page took 0.775673 seconds and 4 git commands to generate.