core.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  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. static void ath10k_core_restart(struct work_struct *work)
  393. {
  394. struct ath10k *ar = container_of(work, struct ath10k, restart_work);
  395. mutex_lock(&ar->conf_mutex);
  396. switch (ar->state) {
  397. case ATH10K_STATE_ON:
  398. ath10k_halt(ar);
  399. ar->state = ATH10K_STATE_RESTARTING;
  400. ieee80211_restart_hw(ar->hw);
  401. break;
  402. case ATH10K_STATE_OFF:
  403. /* this can happen if driver is being unloaded */
  404. ath10k_warn("cannot restart a device that hasn't been started\n");
  405. break;
  406. case ATH10K_STATE_RESTARTING:
  407. case ATH10K_STATE_RESTARTED:
  408. ar->state = ATH10K_STATE_WEDGED;
  409. /* fall through */
  410. case ATH10K_STATE_WEDGED:
  411. ath10k_warn("device is wedged, will not restart\n");
  412. break;
  413. }
  414. mutex_unlock(&ar->conf_mutex);
  415. }
  416. struct ath10k *ath10k_core_create(void *hif_priv, struct device *dev,
  417. const struct ath10k_hif_ops *hif_ops)
  418. {
  419. struct ath10k *ar;
  420. ar = ath10k_mac_create();
  421. if (!ar)
  422. return NULL;
  423. ar->ath_common.priv = ar;
  424. ar->ath_common.hw = ar->hw;
  425. ar->p2p = !!ath10k_p2p;
  426. ar->dev = dev;
  427. ar->hif.priv = hif_priv;
  428. ar->hif.ops = hif_ops;
  429. init_completion(&ar->scan.started);
  430. init_completion(&ar->scan.completed);
  431. init_completion(&ar->scan.on_channel);
  432. init_completion(&ar->install_key_done);
  433. init_completion(&ar->vdev_setup_done);
  434. setup_timer(&ar->scan.timeout, ath10k_reset_scan, (unsigned long)ar);
  435. ar->workqueue = create_singlethread_workqueue("ath10k_wq");
  436. if (!ar->workqueue)
  437. goto err_wq;
  438. mutex_init(&ar->conf_mutex);
  439. spin_lock_init(&ar->data_lock);
  440. INIT_LIST_HEAD(&ar->peers);
  441. init_waitqueue_head(&ar->peer_mapping_wq);
  442. init_completion(&ar->offchan_tx_completed);
  443. INIT_WORK(&ar->offchan_tx_work, ath10k_offchan_tx_work);
  444. skb_queue_head_init(&ar->offchan_tx_queue);
  445. init_waitqueue_head(&ar->event_queue);
  446. INIT_WORK(&ar->restart_work, ath10k_core_restart);
  447. return ar;
  448. err_wq:
  449. ath10k_mac_destroy(ar);
  450. return NULL;
  451. }
  452. EXPORT_SYMBOL(ath10k_core_create);
  453. void ath10k_core_destroy(struct ath10k *ar)
  454. {
  455. flush_workqueue(ar->workqueue);
  456. destroy_workqueue(ar->workqueue);
  457. ath10k_mac_destroy(ar);
  458. }
  459. EXPORT_SYMBOL(ath10k_core_destroy);
  460. int ath10k_core_start(struct ath10k *ar)
  461. {
  462. int status;
  463. ath10k_bmi_start(ar);
  464. if (ath10k_init_configure_target(ar)) {
  465. status = -EINVAL;
  466. goto err;
  467. }
  468. status = ath10k_init_download_firmware(ar);
  469. if (status)
  470. goto err;
  471. status = ath10k_init_uart(ar);
  472. if (status)
  473. goto err;
  474. ar->htc.htc_ops.target_send_suspend_complete =
  475. ath10k_send_suspend_complete;
  476. status = ath10k_htc_init(ar);
  477. if (status) {
  478. ath10k_err("could not init HTC (%d)\n", status);
  479. goto err;
  480. }
  481. status = ath10k_bmi_done(ar);
  482. if (status)
  483. goto err;
  484. status = ath10k_wmi_attach(ar);
  485. if (status) {
  486. ath10k_err("WMI attach failed: %d\n", status);
  487. goto err;
  488. }
  489. status = ath10k_htc_wait_target(&ar->htc);
  490. if (status)
  491. goto err_wmi_detach;
  492. status = ath10k_htt_attach(ar);
  493. if (status) {
  494. ath10k_err("could not attach htt (%d)\n", status);
  495. goto err_wmi_detach;
  496. }
  497. status = ath10k_init_connect_htc(ar);
  498. if (status)
  499. goto err_htt_detach;
  500. ath10k_info("firmware %s booted\n", ar->hw->wiphy->fw_version);
  501. status = ath10k_check_fw_version(ar);
  502. if (status)
  503. goto err_disconnect_htc;
  504. status = ath10k_wmi_cmd_init(ar);
  505. if (status) {
  506. ath10k_err("could not send WMI init command (%d)\n", status);
  507. goto err_disconnect_htc;
  508. }
  509. status = ath10k_wmi_wait_for_unified_ready(ar);
  510. if (status <= 0) {
  511. ath10k_err("wmi unified ready event not received\n");
  512. status = -ETIMEDOUT;
  513. goto err_disconnect_htc;
  514. }
  515. status = ath10k_htt_attach_target(&ar->htt);
  516. if (status)
  517. goto err_disconnect_htc;
  518. ar->free_vdev_map = (1 << TARGET_NUM_VDEVS) - 1;
  519. return 0;
  520. err_disconnect_htc:
  521. ath10k_htc_stop(&ar->htc);
  522. err_htt_detach:
  523. ath10k_htt_detach(&ar->htt);
  524. err_wmi_detach:
  525. ath10k_wmi_detach(ar);
  526. err:
  527. return status;
  528. }
  529. EXPORT_SYMBOL(ath10k_core_start);
  530. void ath10k_core_stop(struct ath10k *ar)
  531. {
  532. ath10k_htc_stop(&ar->htc);
  533. ath10k_htt_detach(&ar->htt);
  534. ath10k_wmi_detach(ar);
  535. }
  536. EXPORT_SYMBOL(ath10k_core_stop);
  537. /* mac80211 manages fw/hw initialization through start/stop hooks. However in
  538. * order to know what hw capabilities should be advertised to mac80211 it is
  539. * necessary to load the firmware (and tear it down immediately since start
  540. * hook will try to init it again) before registering */
  541. static int ath10k_core_probe_fw(struct ath10k *ar)
  542. {
  543. struct bmi_target_info target_info;
  544. int ret = 0;
  545. ret = ath10k_hif_power_up(ar);
  546. if (ret) {
  547. ath10k_err("could not start pci hif (%d)\n", ret);
  548. return ret;
  549. }
  550. memset(&target_info, 0, sizeof(target_info));
  551. ret = ath10k_bmi_get_target_info(ar, &target_info);
  552. if (ret) {
  553. ath10k_err("could not get target info (%d)\n", ret);
  554. ath10k_hif_power_down(ar);
  555. return ret;
  556. }
  557. ar->target_version = target_info.version;
  558. ar->hw->wiphy->hw_version = target_info.version;
  559. ret = ath10k_init_hw_params(ar);
  560. if (ret) {
  561. ath10k_err("could not get hw params (%d)\n", ret);
  562. ath10k_hif_power_down(ar);
  563. return ret;
  564. }
  565. ret = ath10k_core_fetch_firmware_files(ar);
  566. if (ret) {
  567. ath10k_err("could not fetch firmware files (%d)\n", ret);
  568. ath10k_hif_power_down(ar);
  569. return ret;
  570. }
  571. ret = ath10k_core_start(ar);
  572. if (ret) {
  573. ath10k_err("could not init core (%d)\n", ret);
  574. ath10k_core_free_firmware_files(ar);
  575. ath10k_hif_power_down(ar);
  576. return ret;
  577. }
  578. ath10k_core_stop(ar);
  579. ath10k_hif_power_down(ar);
  580. return 0;
  581. }
  582. int ath10k_core_register(struct ath10k *ar)
  583. {
  584. int status;
  585. status = ath10k_core_probe_fw(ar);
  586. if (status) {
  587. ath10k_err("could not probe fw (%d)\n", status);
  588. return status;
  589. }
  590. status = ath10k_mac_register(ar);
  591. if (status) {
  592. ath10k_err("could not register to mac80211 (%d)\n", status);
  593. goto err_release_fw;
  594. }
  595. status = ath10k_debug_create(ar);
  596. if (status) {
  597. ath10k_err("unable to initialize debugfs\n");
  598. goto err_unregister_mac;
  599. }
  600. return 0;
  601. err_unregister_mac:
  602. ath10k_mac_unregister(ar);
  603. err_release_fw:
  604. ath10k_core_free_firmware_files(ar);
  605. return status;
  606. }
  607. EXPORT_SYMBOL(ath10k_core_register);
  608. void ath10k_core_unregister(struct ath10k *ar)
  609. {
  610. /* We must unregister from mac80211 before we stop HTC and HIF.
  611. * Otherwise we will fail to submit commands to FW and mac80211 will be
  612. * unhappy about callback failures. */
  613. ath10k_mac_unregister(ar);
  614. ath10k_core_free_firmware_files(ar);
  615. }
  616. EXPORT_SYMBOL(ath10k_core_unregister);
  617. MODULE_AUTHOR("Qualcomm Atheros");
  618. MODULE_DESCRIPTION("Core module for QCA988X PCIe devices.");
  619. MODULE_LICENSE("Dual BSD/GPL");