core.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  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. #include <linux/module.h>
  18. #include <linux/firmware.h>
  19. #include "core.h"
  20. #include "mac.h"
  21. #include "htc.h"
  22. #include "hif.h"
  23. #include "wmi.h"
  24. #include "bmi.h"
  25. #include "debug.h"
  26. #include "htt.h"
  27. unsigned int ath10k_debug_mask;
  28. static bool uart_print;
  29. static unsigned int ath10k_p2p;
  30. module_param_named(debug_mask, ath10k_debug_mask, uint, 0644);
  31. module_param(uart_print, bool, 0644);
  32. module_param_named(p2p, ath10k_p2p, uint, 0644);
  33. MODULE_PARM_DESC(debug_mask, "Debugging mask");
  34. MODULE_PARM_DESC(uart_print, "Uart target debugging");
  35. MODULE_PARM_DESC(p2p, "Enable ath10k P2P support");
  36. static const struct ath10k_hw_params ath10k_hw_params_list[] = {
  37. {
  38. .id = QCA988X_HW_1_0_VERSION,
  39. .name = "qca988x hw1.0",
  40. .patch_load_addr = QCA988X_HW_1_0_PATCH_LOAD_ADDR,
  41. .fw = {
  42. .dir = QCA988X_HW_1_0_FW_DIR,
  43. .fw = QCA988X_HW_1_0_FW_FILE,
  44. .otp = QCA988X_HW_1_0_OTP_FILE,
  45. .board = QCA988X_HW_1_0_BOARD_DATA_FILE,
  46. },
  47. },
  48. {
  49. .id = QCA988X_HW_2_0_VERSION,
  50. .name = "qca988x hw2.0",
  51. .patch_load_addr = QCA988X_HW_2_0_PATCH_LOAD_ADDR,
  52. .fw = {
  53. .dir = QCA988X_HW_2_0_FW_DIR,
  54. .fw = QCA988X_HW_2_0_FW_FILE,
  55. .otp = QCA988X_HW_2_0_OTP_FILE,
  56. .board = QCA988X_HW_2_0_BOARD_DATA_FILE,
  57. },
  58. },
  59. };
  60. static void ath10k_send_suspend_complete(struct ath10k *ar)
  61. {
  62. ath10k_dbg(ATH10K_DBG_CORE, "%s\n", __func__);
  63. ar->is_target_paused = true;
  64. wake_up(&ar->event_queue);
  65. }
  66. static int ath10k_check_fw_version(struct ath10k *ar)
  67. {
  68. char version[32];
  69. if (ar->fw_version_major >= SUPPORTED_FW_MAJOR &&
  70. ar->fw_version_minor >= SUPPORTED_FW_MINOR &&
  71. ar->fw_version_release >= SUPPORTED_FW_RELEASE &&
  72. ar->fw_version_build >= SUPPORTED_FW_BUILD)
  73. return 0;
  74. snprintf(version, sizeof(version), "%u.%u.%u.%u",
  75. SUPPORTED_FW_MAJOR, SUPPORTED_FW_MINOR,
  76. SUPPORTED_FW_RELEASE, SUPPORTED_FW_BUILD);
  77. ath10k_warn("WARNING: Firmware version %s is not officially supported.\n",
  78. ar->hw->wiphy->fw_version);
  79. ath10k_warn("Please upgrade to version %s (or newer)\n", version);
  80. return 0;
  81. }
  82. static int ath10k_init_connect_htc(struct ath10k *ar)
  83. {
  84. int status;
  85. status = ath10k_wmi_connect_htc_service(ar);
  86. if (status)
  87. goto conn_fail;
  88. /* Start HTC */
  89. status = ath10k_htc_start(&ar->htc);
  90. if (status)
  91. goto conn_fail;
  92. /* Wait for WMI event to be ready */
  93. status = ath10k_wmi_wait_for_service_ready(ar);
  94. if (status <= 0) {
  95. ath10k_warn("wmi service ready event not received");
  96. status = -ETIMEDOUT;
  97. goto timeout;
  98. }
  99. ath10k_dbg(ATH10K_DBG_CORE, "core wmi ready\n");
  100. return 0;
  101. timeout:
  102. ath10k_htc_stop(&ar->htc);
  103. conn_fail:
  104. return status;
  105. }
  106. static int ath10k_init_configure_target(struct ath10k *ar)
  107. {
  108. u32 param_host;
  109. int ret;
  110. /* tell target which HTC version it is used*/
  111. ret = ath10k_bmi_write32(ar, hi_app_host_interest,
  112. HTC_PROTOCOL_VERSION);
  113. if (ret) {
  114. ath10k_err("settings HTC version failed\n");
  115. return ret;
  116. }
  117. /* set the firmware mode to STA/IBSS/AP */
  118. ret = ath10k_bmi_read32(ar, hi_option_flag, &param_host);
  119. if (ret) {
  120. ath10k_err("setting firmware mode (1/2) failed\n");
  121. return ret;
  122. }
  123. /* TODO following parameters need to be re-visited. */
  124. /* num_device */
  125. param_host |= (1 << HI_OPTION_NUM_DEV_SHIFT);
  126. /* Firmware mode */
  127. /* FIXME: Why FW_MODE_AP ??.*/
  128. param_host |= (HI_OPTION_FW_MODE_AP << HI_OPTION_FW_MODE_SHIFT);
  129. /* mac_addr_method */
  130. param_host |= (1 << HI_OPTION_MAC_ADDR_METHOD_SHIFT);
  131. /* firmware_bridge */
  132. param_host |= (0 << HI_OPTION_FW_BRIDGE_SHIFT);
  133. /* fwsubmode */
  134. param_host |= (0 << HI_OPTION_FW_SUBMODE_SHIFT);
  135. ret = ath10k_bmi_write32(ar, hi_option_flag, param_host);
  136. if (ret) {
  137. ath10k_err("setting firmware mode (2/2) failed\n");
  138. return ret;
  139. }
  140. /* We do all byte-swapping on the host */
  141. ret = ath10k_bmi_write32(ar, hi_be, 0);
  142. if (ret) {
  143. ath10k_err("setting host CPU BE mode failed\n");
  144. return ret;
  145. }
  146. /* FW descriptor/Data swap flags */
  147. ret = ath10k_bmi_write32(ar, hi_fw_swap, 0);
  148. if (ret) {
  149. ath10k_err("setting FW data/desc swap flags failed\n");
  150. return ret;
  151. }
  152. return 0;
  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. if (file == NULL)
  162. return ERR_PTR(-ENOENT);
  163. if (dir == NULL)
  164. dir = ".";
  165. snprintf(filename, sizeof(filename), "%s/%s", dir, file);
  166. ret = request_firmware(&fw, filename, ar->dev);
  167. if (ret)
  168. return ERR_PTR(ret);
  169. return fw;
  170. }
  171. static int ath10k_push_board_ext_data(struct ath10k *ar,
  172. const struct firmware *fw)
  173. {
  174. u32 board_data_size = QCA988X_BOARD_DATA_SZ;
  175. u32 board_ext_data_size = QCA988X_BOARD_EXT_DATA_SZ;
  176. u32 board_ext_data_addr;
  177. int ret;
  178. ret = ath10k_bmi_read32(ar, hi_board_ext_data, &board_ext_data_addr);
  179. if (ret) {
  180. ath10k_err("could not read board ext data addr (%d)\n", ret);
  181. return ret;
  182. }
  183. ath10k_dbg(ATH10K_DBG_CORE,
  184. "ath10k: Board extended Data download addr: 0x%x\n",
  185. board_ext_data_addr);
  186. if (board_ext_data_addr == 0)
  187. return 0;
  188. if (fw->size != (board_data_size + board_ext_data_size)) {
  189. ath10k_err("invalid board (ext) data sizes %zu != %d+%d\n",
  190. fw->size, board_data_size, board_ext_data_size);
  191. return -EINVAL;
  192. }
  193. ret = ath10k_bmi_write_memory(ar, board_ext_data_addr,
  194. fw->data + board_data_size,
  195. board_ext_data_size);
  196. if (ret) {
  197. ath10k_err("could not write board ext data (%d)\n", ret);
  198. return ret;
  199. }
  200. ret = ath10k_bmi_write32(ar, hi_board_ext_data_config,
  201. (board_ext_data_size << 16) | 1);
  202. if (ret) {
  203. ath10k_err("could not write board ext data bit (%d)\n", ret);
  204. return ret;
  205. }
  206. return 0;
  207. }
  208. static int ath10k_download_board_data(struct ath10k *ar)
  209. {
  210. const struct firmware *fw = ar->board_data;
  211. u32 board_data_size = QCA988X_BOARD_DATA_SZ;
  212. u32 address;
  213. int ret;
  214. ret = ath10k_push_board_ext_data(ar, fw);
  215. if (ret) {
  216. ath10k_err("could not push board ext data (%d)\n", ret);
  217. goto exit;
  218. }
  219. ret = ath10k_bmi_read32(ar, hi_board_data, &address);
  220. if (ret) {
  221. ath10k_err("could not read board data addr (%d)\n", ret);
  222. goto exit;
  223. }
  224. ret = ath10k_bmi_write_memory(ar, address, fw->data,
  225. min_t(u32, board_data_size, fw->size));
  226. if (ret) {
  227. ath10k_err("could not write board data (%d)\n", ret);
  228. goto exit;
  229. }
  230. ret = ath10k_bmi_write32(ar, hi_board_data_initialized, 1);
  231. if (ret) {
  232. ath10k_err("could not write board data bit (%d)\n", ret);
  233. goto exit;
  234. }
  235. exit:
  236. return ret;
  237. }
  238. static int ath10k_download_and_run_otp(struct ath10k *ar)
  239. {
  240. const struct firmware *fw = ar->otp;
  241. u32 address = ar->hw_params.patch_load_addr;
  242. u32 exec_param;
  243. int ret;
  244. /* OTP is optional */
  245. if (!ar->otp)
  246. return 0;
  247. ret = ath10k_bmi_fast_download(ar, address, fw->data, fw->size);
  248. if (ret) {
  249. ath10k_err("could not write otp (%d)\n", ret);
  250. goto exit;
  251. }
  252. exec_param = 0;
  253. ret = ath10k_bmi_execute(ar, address, &exec_param);
  254. if (ret) {
  255. ath10k_err("could not execute otp (%d)\n", ret);
  256. goto exit;
  257. }
  258. exit:
  259. return ret;
  260. }
  261. static int ath10k_download_fw(struct ath10k *ar)
  262. {
  263. const struct firmware *fw = ar->firmware;
  264. u32 address;
  265. int ret;
  266. address = ar->hw_params.patch_load_addr;
  267. ret = ath10k_bmi_fast_download(ar, address, fw->data, fw->size);
  268. if (ret) {
  269. ath10k_err("could not write fw (%d)\n", ret);
  270. goto exit;
  271. }
  272. exit:
  273. return ret;
  274. }
  275. static void ath10k_core_free_firmware_files(struct ath10k *ar)
  276. {
  277. if (ar->board_data && !IS_ERR(ar->board_data))
  278. release_firmware(ar->board_data);
  279. if (ar->otp && !IS_ERR(ar->otp))
  280. release_firmware(ar->otp);
  281. if (ar->firmware && !IS_ERR(ar->firmware))
  282. release_firmware(ar->firmware);
  283. ar->board_data = NULL;
  284. ar->otp = NULL;
  285. ar->firmware = NULL;
  286. }
  287. static int ath10k_core_fetch_firmware_files(struct ath10k *ar)
  288. {
  289. int ret = 0;
  290. if (ar->hw_params.fw.fw == NULL) {
  291. ath10k_err("firmware file not defined\n");
  292. return -EINVAL;
  293. }
  294. if (ar->hw_params.fw.board == NULL) {
  295. ath10k_err("board data file not defined");
  296. return -EINVAL;
  297. }
  298. ar->board_data = ath10k_fetch_fw_file(ar,
  299. ar->hw_params.fw.dir,
  300. ar->hw_params.fw.board);
  301. if (IS_ERR(ar->board_data)) {
  302. ret = PTR_ERR(ar->board_data);
  303. ath10k_err("could not fetch board data (%d)\n", ret);
  304. goto err;
  305. }
  306. ar->firmware = ath10k_fetch_fw_file(ar,
  307. ar->hw_params.fw.dir,
  308. ar->hw_params.fw.fw);
  309. if (IS_ERR(ar->firmware)) {
  310. ret = PTR_ERR(ar->firmware);
  311. ath10k_err("could not fetch firmware (%d)\n", ret);
  312. goto err;
  313. }
  314. /* OTP may be undefined. If so, don't fetch it at all */
  315. if (ar->hw_params.fw.otp == NULL)
  316. return 0;
  317. ar->otp = ath10k_fetch_fw_file(ar,
  318. ar->hw_params.fw.dir,
  319. ar->hw_params.fw.otp);
  320. if (IS_ERR(ar->otp)) {
  321. ret = PTR_ERR(ar->otp);
  322. ath10k_err("could not fetch otp (%d)\n", ret);
  323. goto err;
  324. }
  325. return 0;
  326. err:
  327. ath10k_core_free_firmware_files(ar);
  328. return ret;
  329. }
  330. static int ath10k_init_download_firmware(struct ath10k *ar)
  331. {
  332. int ret;
  333. ret = ath10k_download_board_data(ar);
  334. if (ret)
  335. return ret;
  336. ret = ath10k_download_and_run_otp(ar);
  337. if (ret)
  338. return ret;
  339. ret = ath10k_download_fw(ar);
  340. if (ret)
  341. return ret;
  342. return ret;
  343. }
  344. static int ath10k_init_uart(struct ath10k *ar)
  345. {
  346. int ret;
  347. /*
  348. * Explicitly setting UART prints to zero as target turns it on
  349. * based on scratch registers.
  350. */
  351. ret = ath10k_bmi_write32(ar, hi_serial_enable, 0);
  352. if (ret) {
  353. ath10k_warn("could not disable UART prints (%d)\n", ret);
  354. return ret;
  355. }
  356. if (!uart_print) {
  357. ath10k_info("UART prints disabled\n");
  358. return 0;
  359. }
  360. ret = ath10k_bmi_write32(ar, hi_dbg_uart_txpin, 7);
  361. if (ret) {
  362. ath10k_warn("could not enable UART prints (%d)\n", ret);
  363. return ret;
  364. }
  365. ret = ath10k_bmi_write32(ar, hi_serial_enable, 1);
  366. if (ret) {
  367. ath10k_warn("could not enable UART prints (%d)\n", ret);
  368. return ret;
  369. }
  370. ath10k_info("UART prints enabled\n");
  371. return 0;
  372. }
  373. static int ath10k_init_hw_params(struct ath10k *ar)
  374. {
  375. const struct ath10k_hw_params *uninitialized_var(hw_params);
  376. int i;
  377. for (i = 0; i < ARRAY_SIZE(ath10k_hw_params_list); i++) {
  378. hw_params = &ath10k_hw_params_list[i];
  379. if (hw_params->id == ar->target_version)
  380. break;
  381. }
  382. if (i == ARRAY_SIZE(ath10k_hw_params_list)) {
  383. ath10k_err("Unsupported hardware version: 0x%x\n",
  384. ar->target_version);
  385. return -EINVAL;
  386. }
  387. ar->hw_params = *hw_params;
  388. ath10k_info("Hardware name %s version 0x%x\n",
  389. ar->hw_params.name, ar->target_version);
  390. return 0;
  391. }
  392. struct ath10k *ath10k_core_create(void *hif_priv, struct device *dev,
  393. const struct ath10k_hif_ops *hif_ops)
  394. {
  395. struct ath10k *ar;
  396. ar = ath10k_mac_create();
  397. if (!ar)
  398. return NULL;
  399. ar->ath_common.priv = ar;
  400. ar->ath_common.hw = ar->hw;
  401. ar->p2p = !!ath10k_p2p;
  402. ar->dev = dev;
  403. ar->hif.priv = hif_priv;
  404. ar->hif.ops = hif_ops;
  405. init_completion(&ar->scan.started);
  406. init_completion(&ar->scan.completed);
  407. init_completion(&ar->scan.on_channel);
  408. init_completion(&ar->install_key_done);
  409. init_completion(&ar->vdev_setup_done);
  410. setup_timer(&ar->scan.timeout, ath10k_reset_scan, (unsigned long)ar);
  411. ar->workqueue = create_singlethread_workqueue("ath10k_wq");
  412. if (!ar->workqueue)
  413. goto err_wq;
  414. mutex_init(&ar->conf_mutex);
  415. spin_lock_init(&ar->data_lock);
  416. INIT_LIST_HEAD(&ar->peers);
  417. init_waitqueue_head(&ar->peer_mapping_wq);
  418. init_completion(&ar->offchan_tx_completed);
  419. INIT_WORK(&ar->offchan_tx_work, ath10k_offchan_tx_work);
  420. skb_queue_head_init(&ar->offchan_tx_queue);
  421. init_waitqueue_head(&ar->event_queue);
  422. return ar;
  423. err_wq:
  424. ath10k_mac_destroy(ar);
  425. return NULL;
  426. }
  427. EXPORT_SYMBOL(ath10k_core_create);
  428. void ath10k_core_destroy(struct ath10k *ar)
  429. {
  430. flush_workqueue(ar->workqueue);
  431. destroy_workqueue(ar->workqueue);
  432. ath10k_mac_destroy(ar);
  433. }
  434. EXPORT_SYMBOL(ath10k_core_destroy);
  435. int ath10k_core_start(struct ath10k *ar)
  436. {
  437. int status;
  438. ath10k_bmi_start(ar);
  439. if (ath10k_init_configure_target(ar)) {
  440. status = -EINVAL;
  441. goto err;
  442. }
  443. status = ath10k_init_download_firmware(ar);
  444. if (status)
  445. goto err;
  446. status = ath10k_init_uart(ar);
  447. if (status)
  448. goto err;
  449. ar->htc.htc_ops.target_send_suspend_complete =
  450. ath10k_send_suspend_complete;
  451. status = ath10k_htc_init(ar);
  452. if (status) {
  453. ath10k_err("could not init HTC (%d)\n", status);
  454. goto err;
  455. }
  456. status = ath10k_bmi_done(ar);
  457. if (status)
  458. goto err;
  459. status = ath10k_wmi_attach(ar);
  460. if (status) {
  461. ath10k_err("WMI attach failed: %d\n", status);
  462. goto err;
  463. }
  464. status = ath10k_htc_wait_target(&ar->htc);
  465. if (status)
  466. goto err_wmi_detach;
  467. status = ath10k_htt_attach(ar);
  468. if (status) {
  469. ath10k_err("could not attach htt (%d)\n", status);
  470. goto err_wmi_detach;
  471. }
  472. status = ath10k_init_connect_htc(ar);
  473. if (status)
  474. goto err_htt_detach;
  475. ath10k_info("firmware %s booted\n", ar->hw->wiphy->fw_version);
  476. status = ath10k_check_fw_version(ar);
  477. if (status)
  478. goto err_disconnect_htc;
  479. status = ath10k_wmi_cmd_init(ar);
  480. if (status) {
  481. ath10k_err("could not send WMI init command (%d)\n", status);
  482. goto err_disconnect_htc;
  483. }
  484. status = ath10k_wmi_wait_for_unified_ready(ar);
  485. if (status <= 0) {
  486. ath10k_err("wmi unified ready event not received\n");
  487. status = -ETIMEDOUT;
  488. goto err_disconnect_htc;
  489. }
  490. status = ath10k_htt_attach_target(&ar->htt);
  491. if (status)
  492. goto err_disconnect_htc;
  493. ar->free_vdev_map = (1 << TARGET_NUM_VDEVS) - 1;
  494. return 0;
  495. err_disconnect_htc:
  496. ath10k_htc_stop(&ar->htc);
  497. err_htt_detach:
  498. ath10k_htt_detach(&ar->htt);
  499. err_wmi_detach:
  500. ath10k_wmi_detach(ar);
  501. err:
  502. return status;
  503. }
  504. EXPORT_SYMBOL(ath10k_core_start);
  505. void ath10k_core_stop(struct ath10k *ar)
  506. {
  507. ath10k_htc_stop(&ar->htc);
  508. ath10k_htt_detach(&ar->htt);
  509. ath10k_wmi_detach(ar);
  510. }
  511. EXPORT_SYMBOL(ath10k_core_stop);
  512. /* mac80211 manages fw/hw initialization through start/stop hooks. However in
  513. * order to know what hw capabilities should be advertised to mac80211 it is
  514. * necessary to load the firmware (and tear it down immediately since start
  515. * hook will try to init it again) before registering */
  516. static int ath10k_core_probe_fw(struct ath10k *ar)
  517. {
  518. struct bmi_target_info target_info;
  519. int ret = 0;
  520. ret = ath10k_hif_power_up(ar);
  521. if (ret) {
  522. ath10k_err("could not start pci hif (%d)\n", ret);
  523. return ret;
  524. }
  525. memset(&target_info, 0, sizeof(target_info));
  526. ret = ath10k_bmi_get_target_info(ar, &target_info);
  527. if (ret) {
  528. ath10k_err("could not get target info (%d)\n", ret);
  529. ath10k_hif_power_down(ar);
  530. return ret;
  531. }
  532. ar->target_version = target_info.version;
  533. ar->hw->wiphy->hw_version = target_info.version;
  534. ret = ath10k_init_hw_params(ar);
  535. if (ret) {
  536. ath10k_err("could not get hw params (%d)\n", ret);
  537. ath10k_hif_power_down(ar);
  538. return ret;
  539. }
  540. ret = ath10k_core_fetch_firmware_files(ar);
  541. if (ret) {
  542. ath10k_err("could not fetch firmware files (%d)\n", ret);
  543. ath10k_hif_power_down(ar);
  544. return ret;
  545. }
  546. ret = ath10k_core_start(ar);
  547. if (ret) {
  548. ath10k_err("could not init core (%d)\n", ret);
  549. ath10k_core_free_firmware_files(ar);
  550. ath10k_hif_power_down(ar);
  551. return ret;
  552. }
  553. ath10k_core_stop(ar);
  554. ath10k_hif_power_down(ar);
  555. return 0;
  556. }
  557. int ath10k_core_register(struct ath10k *ar)
  558. {
  559. int status;
  560. status = ath10k_core_probe_fw(ar);
  561. if (status) {
  562. ath10k_err("could not probe fw (%d)\n", status);
  563. return status;
  564. }
  565. status = ath10k_mac_register(ar);
  566. if (status) {
  567. ath10k_err("could not register to mac80211 (%d)\n", status);
  568. goto err_release_fw;
  569. }
  570. status = ath10k_debug_create(ar);
  571. if (status) {
  572. ath10k_err("unable to initialize debugfs\n");
  573. goto err_unregister_mac;
  574. }
  575. return 0;
  576. err_unregister_mac:
  577. ath10k_mac_unregister(ar);
  578. err_release_fw:
  579. ath10k_core_free_firmware_files(ar);
  580. return status;
  581. }
  582. EXPORT_SYMBOL(ath10k_core_register);
  583. void ath10k_core_unregister(struct ath10k *ar)
  584. {
  585. /* We must unregister from mac80211 before we stop HTC and HIF.
  586. * Otherwise we will fail to submit commands to FW and mac80211 will be
  587. * unhappy about callback failures. */
  588. ath10k_mac_unregister(ar);
  589. ath10k_core_free_firmware_files(ar);
  590. }
  591. EXPORT_SYMBOL(ath10k_core_unregister);
  592. MODULE_AUTHOR("Qualcomm Atheros");
  593. MODULE_DESCRIPTION("Core module for QCA988X PCIe devices.");
  594. MODULE_LICENSE("Dual BSD/GPL");