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