core.c 23 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012
  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_2_0_VERSION,
  39. .name = "qca988x hw2.0",
  40. .patch_load_addr = QCA988X_HW_2_0_PATCH_LOAD_ADDR,
  41. .fw = {
  42. .dir = QCA988X_HW_2_0_FW_DIR,
  43. .fw = QCA988X_HW_2_0_FW_FILE,
  44. .otp = QCA988X_HW_2_0_OTP_FILE,
  45. .board = QCA988X_HW_2_0_BOARD_DATA_FILE,
  46. },
  47. },
  48. };
  49. static void ath10k_send_suspend_complete(struct ath10k *ar)
  50. {
  51. ath10k_dbg(ATH10K_DBG_BOOT, "boot suspend complete\n");
  52. ar->is_target_paused = true;
  53. wake_up(&ar->event_queue);
  54. }
  55. static int ath10k_init_connect_htc(struct ath10k *ar)
  56. {
  57. int status;
  58. status = ath10k_wmi_connect_htc_service(ar);
  59. if (status)
  60. goto conn_fail;
  61. /* Start HTC */
  62. status = ath10k_htc_start(&ar->htc);
  63. if (status)
  64. goto conn_fail;
  65. /* Wait for WMI event to be ready */
  66. status = ath10k_wmi_wait_for_service_ready(ar);
  67. if (status <= 0) {
  68. ath10k_warn("wmi service ready event not received");
  69. status = -ETIMEDOUT;
  70. goto timeout;
  71. }
  72. ath10k_dbg(ATH10K_DBG_BOOT, "boot wmi ready\n");
  73. return 0;
  74. timeout:
  75. ath10k_htc_stop(&ar->htc);
  76. conn_fail:
  77. return status;
  78. }
  79. static int ath10k_init_configure_target(struct ath10k *ar)
  80. {
  81. u32 param_host;
  82. int ret;
  83. /* tell target which HTC version it is used*/
  84. ret = ath10k_bmi_write32(ar, hi_app_host_interest,
  85. HTC_PROTOCOL_VERSION);
  86. if (ret) {
  87. ath10k_err("settings HTC version failed\n");
  88. return ret;
  89. }
  90. /* set the firmware mode to STA/IBSS/AP */
  91. ret = ath10k_bmi_read32(ar, hi_option_flag, &param_host);
  92. if (ret) {
  93. ath10k_err("setting firmware mode (1/2) failed\n");
  94. return ret;
  95. }
  96. /* TODO following parameters need to be re-visited. */
  97. /* num_device */
  98. param_host |= (1 << HI_OPTION_NUM_DEV_SHIFT);
  99. /* Firmware mode */
  100. /* FIXME: Why FW_MODE_AP ??.*/
  101. param_host |= (HI_OPTION_FW_MODE_AP << HI_OPTION_FW_MODE_SHIFT);
  102. /* mac_addr_method */
  103. param_host |= (1 << HI_OPTION_MAC_ADDR_METHOD_SHIFT);
  104. /* firmware_bridge */
  105. param_host |= (0 << HI_OPTION_FW_BRIDGE_SHIFT);
  106. /* fwsubmode */
  107. param_host |= (0 << HI_OPTION_FW_SUBMODE_SHIFT);
  108. ret = ath10k_bmi_write32(ar, hi_option_flag, param_host);
  109. if (ret) {
  110. ath10k_err("setting firmware mode (2/2) failed\n");
  111. return ret;
  112. }
  113. /* We do all byte-swapping on the host */
  114. ret = ath10k_bmi_write32(ar, hi_be, 0);
  115. if (ret) {
  116. ath10k_err("setting host CPU BE mode failed\n");
  117. return ret;
  118. }
  119. /* FW descriptor/Data swap flags */
  120. ret = ath10k_bmi_write32(ar, hi_fw_swap, 0);
  121. if (ret) {
  122. ath10k_err("setting FW data/desc swap flags failed\n");
  123. return ret;
  124. }
  125. return 0;
  126. }
  127. static const struct firmware *ath10k_fetch_fw_file(struct ath10k *ar,
  128. const char *dir,
  129. const char *file)
  130. {
  131. char filename[100];
  132. const struct firmware *fw;
  133. int ret;
  134. if (file == NULL)
  135. return ERR_PTR(-ENOENT);
  136. if (dir == NULL)
  137. dir = ".";
  138. snprintf(filename, sizeof(filename), "%s/%s", dir, file);
  139. ret = request_firmware(&fw, filename, ar->dev);
  140. if (ret)
  141. return ERR_PTR(ret);
  142. return fw;
  143. }
  144. static int ath10k_push_board_ext_data(struct ath10k *ar)
  145. {
  146. u32 board_data_size = QCA988X_BOARD_DATA_SZ;
  147. u32 board_ext_data_size = QCA988X_BOARD_EXT_DATA_SZ;
  148. u32 board_ext_data_addr;
  149. int ret;
  150. ret = ath10k_bmi_read32(ar, hi_board_ext_data, &board_ext_data_addr);
  151. if (ret) {
  152. ath10k_err("could not read board ext data addr (%d)\n", ret);
  153. return ret;
  154. }
  155. ath10k_dbg(ATH10K_DBG_BOOT,
  156. "boot push board extended data addr 0x%x\n",
  157. board_ext_data_addr);
  158. if (board_ext_data_addr == 0)
  159. return 0;
  160. if (ar->board_len != (board_data_size + board_ext_data_size)) {
  161. ath10k_err("invalid board (ext) data sizes %zu != %d+%d\n",
  162. ar->board_len, board_data_size, board_ext_data_size);
  163. return -EINVAL;
  164. }
  165. ret = ath10k_bmi_write_memory(ar, board_ext_data_addr,
  166. ar->board_data + board_data_size,
  167. board_ext_data_size);
  168. if (ret) {
  169. ath10k_err("could not write board ext data (%d)\n", ret);
  170. return ret;
  171. }
  172. ret = ath10k_bmi_write32(ar, hi_board_ext_data_config,
  173. (board_ext_data_size << 16) | 1);
  174. if (ret) {
  175. ath10k_err("could not write board ext data bit (%d)\n", ret);
  176. return ret;
  177. }
  178. return 0;
  179. }
  180. static int ath10k_download_board_data(struct ath10k *ar)
  181. {
  182. u32 board_data_size = QCA988X_BOARD_DATA_SZ;
  183. u32 address;
  184. int ret;
  185. ret = ath10k_push_board_ext_data(ar);
  186. if (ret) {
  187. ath10k_err("could not push board ext data (%d)\n", ret);
  188. goto exit;
  189. }
  190. ret = ath10k_bmi_read32(ar, hi_board_data, &address);
  191. if (ret) {
  192. ath10k_err("could not read board data addr (%d)\n", ret);
  193. goto exit;
  194. }
  195. ret = ath10k_bmi_write_memory(ar, address, ar->board_data,
  196. min_t(u32, board_data_size,
  197. ar->board_len));
  198. if (ret) {
  199. ath10k_err("could not write board data (%d)\n", ret);
  200. goto exit;
  201. }
  202. ret = ath10k_bmi_write32(ar, hi_board_data_initialized, 1);
  203. if (ret) {
  204. ath10k_err("could not write board data bit (%d)\n", ret);
  205. goto exit;
  206. }
  207. exit:
  208. return ret;
  209. }
  210. static int ath10k_download_and_run_otp(struct ath10k *ar)
  211. {
  212. u32 address = ar->hw_params.patch_load_addr;
  213. u32 exec_param;
  214. int ret;
  215. /* OTP is optional */
  216. if (!ar->otp_data || !ar->otp_len)
  217. return 0;
  218. ret = ath10k_bmi_fast_download(ar, address, ar->otp_data, ar->otp_len);
  219. if (ret) {
  220. ath10k_err("could not write otp (%d)\n", ret);
  221. goto exit;
  222. }
  223. exec_param = 0;
  224. ret = ath10k_bmi_execute(ar, address, &exec_param);
  225. if (ret) {
  226. ath10k_err("could not execute otp (%d)\n", ret);
  227. goto exit;
  228. }
  229. exit:
  230. return ret;
  231. }
  232. static int ath10k_download_fw(struct ath10k *ar)
  233. {
  234. u32 address;
  235. int ret;
  236. address = ar->hw_params.patch_load_addr;
  237. ret = ath10k_bmi_fast_download(ar, address, ar->firmware_data,
  238. ar->firmware_len);
  239. if (ret) {
  240. ath10k_err("could not write fw (%d)\n", ret);
  241. goto exit;
  242. }
  243. exit:
  244. return ret;
  245. }
  246. static void ath10k_core_free_firmware_files(struct ath10k *ar)
  247. {
  248. if (ar->board && !IS_ERR(ar->board))
  249. release_firmware(ar->board);
  250. if (ar->otp && !IS_ERR(ar->otp))
  251. release_firmware(ar->otp);
  252. if (ar->firmware && !IS_ERR(ar->firmware))
  253. release_firmware(ar->firmware);
  254. ar->board = NULL;
  255. ar->board_data = NULL;
  256. ar->board_len = 0;
  257. ar->otp = NULL;
  258. ar->otp_data = NULL;
  259. ar->otp_len = 0;
  260. ar->firmware = NULL;
  261. ar->firmware_data = NULL;
  262. ar->firmware_len = 0;
  263. }
  264. static int ath10k_core_fetch_firmware_api_1(struct ath10k *ar)
  265. {
  266. int ret = 0;
  267. if (ar->hw_params.fw.fw == NULL) {
  268. ath10k_err("firmware file not defined\n");
  269. return -EINVAL;
  270. }
  271. if (ar->hw_params.fw.board == NULL) {
  272. ath10k_err("board data file not defined");
  273. return -EINVAL;
  274. }
  275. ar->board = ath10k_fetch_fw_file(ar,
  276. ar->hw_params.fw.dir,
  277. ar->hw_params.fw.board);
  278. if (IS_ERR(ar->board)) {
  279. ret = PTR_ERR(ar->board);
  280. ath10k_err("could not fetch board data (%d)\n", ret);
  281. goto err;
  282. }
  283. ar->board_data = ar->board->data;
  284. ar->board_len = ar->board->size;
  285. ar->firmware = ath10k_fetch_fw_file(ar,
  286. ar->hw_params.fw.dir,
  287. ar->hw_params.fw.fw);
  288. if (IS_ERR(ar->firmware)) {
  289. ret = PTR_ERR(ar->firmware);
  290. ath10k_err("could not fetch firmware (%d)\n", ret);
  291. goto err;
  292. }
  293. ar->firmware_data = ar->firmware->data;
  294. ar->firmware_len = ar->firmware->size;
  295. /* OTP may be undefined. If so, don't fetch it at all */
  296. if (ar->hw_params.fw.otp == NULL)
  297. return 0;
  298. ar->otp = ath10k_fetch_fw_file(ar,
  299. ar->hw_params.fw.dir,
  300. ar->hw_params.fw.otp);
  301. if (IS_ERR(ar->otp)) {
  302. ret = PTR_ERR(ar->otp);
  303. ath10k_err("could not fetch otp (%d)\n", ret);
  304. goto err;
  305. }
  306. ar->otp_data = ar->otp->data;
  307. ar->otp_len = ar->otp->size;
  308. return 0;
  309. err:
  310. ath10k_core_free_firmware_files(ar);
  311. return ret;
  312. }
  313. static int ath10k_core_fetch_firmware_api_n(struct ath10k *ar, const char *name)
  314. {
  315. size_t magic_len, len, ie_len;
  316. int ie_id, i, index, bit, ret;
  317. struct ath10k_fw_ie *hdr;
  318. const u8 *data;
  319. __le32 *timestamp;
  320. /* first fetch the firmware file (firmware-*.bin) */
  321. ar->firmware = ath10k_fetch_fw_file(ar, ar->hw_params.fw.dir, name);
  322. if (IS_ERR(ar->firmware)) {
  323. ath10k_err("Could not fetch firmware file '%s': %ld\n",
  324. name, PTR_ERR(ar->firmware));
  325. return PTR_ERR(ar->firmware);
  326. }
  327. data = ar->firmware->data;
  328. len = ar->firmware->size;
  329. /* magic also includes the null byte, check that as well */
  330. magic_len = strlen(ATH10K_FIRMWARE_MAGIC) + 1;
  331. if (len < magic_len) {
  332. ath10k_err("firmware image too small to contain magic: %zu\n",
  333. len);
  334. ret = -EINVAL;
  335. goto err;
  336. }
  337. if (memcmp(data, ATH10K_FIRMWARE_MAGIC, magic_len) != 0) {
  338. ath10k_err("Invalid firmware magic\n");
  339. ret = -EINVAL;
  340. goto err;
  341. }
  342. /* jump over the padding */
  343. magic_len = ALIGN(magic_len, 4);
  344. len -= magic_len;
  345. data += magic_len;
  346. /* loop elements */
  347. while (len > sizeof(struct ath10k_fw_ie)) {
  348. hdr = (struct ath10k_fw_ie *)data;
  349. ie_id = le32_to_cpu(hdr->id);
  350. ie_len = le32_to_cpu(hdr->len);
  351. len -= sizeof(*hdr);
  352. data += sizeof(*hdr);
  353. if (len < ie_len) {
  354. ath10k_err("Invalid length for FW IE %d (%zu < %zu)\n",
  355. ie_id, len, ie_len);
  356. ret = -EINVAL;
  357. goto err;
  358. }
  359. switch (ie_id) {
  360. case ATH10K_FW_IE_FW_VERSION:
  361. if (ie_len > sizeof(ar->hw->wiphy->fw_version) - 1)
  362. break;
  363. memcpy(ar->hw->wiphy->fw_version, data, ie_len);
  364. ar->hw->wiphy->fw_version[ie_len] = '\0';
  365. ath10k_dbg(ATH10K_DBG_BOOT,
  366. "found fw version %s\n",
  367. ar->hw->wiphy->fw_version);
  368. break;
  369. case ATH10K_FW_IE_TIMESTAMP:
  370. if (ie_len != sizeof(u32))
  371. break;
  372. timestamp = (__le32 *)data;
  373. ath10k_dbg(ATH10K_DBG_BOOT, "found fw timestamp %d\n",
  374. le32_to_cpup(timestamp));
  375. break;
  376. case ATH10K_FW_IE_FEATURES:
  377. ath10k_dbg(ATH10K_DBG_BOOT,
  378. "found firmware features ie (%zd B)\n",
  379. ie_len);
  380. for (i = 0; i < ATH10K_FW_FEATURE_COUNT; i++) {
  381. index = i / 8;
  382. bit = i % 8;
  383. if (index == ie_len)
  384. break;
  385. if (data[index] & (1 << bit))
  386. __set_bit(i, ar->fw_features);
  387. }
  388. ath10k_dbg_dump(ATH10K_DBG_BOOT, "features", "",
  389. ar->fw_features,
  390. sizeof(ar->fw_features));
  391. break;
  392. case ATH10K_FW_IE_FW_IMAGE:
  393. ath10k_dbg(ATH10K_DBG_BOOT,
  394. "found fw image ie (%zd B)\n",
  395. ie_len);
  396. ar->firmware_data = data;
  397. ar->firmware_len = ie_len;
  398. break;
  399. case ATH10K_FW_IE_OTP_IMAGE:
  400. ath10k_dbg(ATH10K_DBG_BOOT,
  401. "found otp image ie (%zd B)\n",
  402. ie_len);
  403. ar->otp_data = data;
  404. ar->otp_len = ie_len;
  405. break;
  406. default:
  407. ath10k_warn("Unknown FW IE: %u\n",
  408. le32_to_cpu(hdr->id));
  409. break;
  410. }
  411. /* jump over the padding */
  412. ie_len = ALIGN(ie_len, 4);
  413. len -= ie_len;
  414. data += ie_len;
  415. }
  416. if (!ar->firmware_data || !ar->firmware_len) {
  417. ath10k_warn("No ATH10K_FW_IE_FW_IMAGE found from %s, skipping\n",
  418. name);
  419. ret = -ENOMEDIUM;
  420. goto err;
  421. }
  422. /* now fetch the board file */
  423. if (ar->hw_params.fw.board == NULL) {
  424. ath10k_err("board data file not defined");
  425. ret = -EINVAL;
  426. goto err;
  427. }
  428. ar->board = ath10k_fetch_fw_file(ar,
  429. ar->hw_params.fw.dir,
  430. ar->hw_params.fw.board);
  431. if (IS_ERR(ar->board)) {
  432. ret = PTR_ERR(ar->board);
  433. ath10k_err("could not fetch board data (%d)\n", ret);
  434. goto err;
  435. }
  436. ar->board_data = ar->board->data;
  437. ar->board_len = ar->board->size;
  438. return 0;
  439. err:
  440. ath10k_core_free_firmware_files(ar);
  441. return ret;
  442. }
  443. static int ath10k_core_fetch_firmware_files(struct ath10k *ar)
  444. {
  445. int ret;
  446. ret = ath10k_core_fetch_firmware_api_n(ar, ATH10K_FW_API2_FILE);
  447. if (ret == 0) {
  448. ar->fw_api = 2;
  449. goto out;
  450. }
  451. ret = ath10k_core_fetch_firmware_api_1(ar);
  452. if (ret)
  453. return ret;
  454. ar->fw_api = 1;
  455. out:
  456. ath10k_dbg(ATH10K_DBG_BOOT, "using fw api %d\n", ar->fw_api);
  457. return 0;
  458. }
  459. static int ath10k_init_download_firmware(struct ath10k *ar)
  460. {
  461. int ret;
  462. ret = ath10k_download_board_data(ar);
  463. if (ret)
  464. return ret;
  465. ret = ath10k_download_and_run_otp(ar);
  466. if (ret)
  467. return ret;
  468. ret = ath10k_download_fw(ar);
  469. if (ret)
  470. return ret;
  471. return ret;
  472. }
  473. static int ath10k_init_uart(struct ath10k *ar)
  474. {
  475. int ret;
  476. /*
  477. * Explicitly setting UART prints to zero as target turns it on
  478. * based on scratch registers.
  479. */
  480. ret = ath10k_bmi_write32(ar, hi_serial_enable, 0);
  481. if (ret) {
  482. ath10k_warn("could not disable UART prints (%d)\n", ret);
  483. return ret;
  484. }
  485. if (!uart_print)
  486. return 0;
  487. ret = ath10k_bmi_write32(ar, hi_dbg_uart_txpin, 7);
  488. if (ret) {
  489. ath10k_warn("could not enable UART prints (%d)\n", ret);
  490. return ret;
  491. }
  492. ret = ath10k_bmi_write32(ar, hi_serial_enable, 1);
  493. if (ret) {
  494. ath10k_warn("could not enable UART prints (%d)\n", ret);
  495. return ret;
  496. }
  497. /* Set the UART baud rate to 19200. */
  498. ret = ath10k_bmi_write32(ar, hi_desired_baud_rate, 19200);
  499. if (ret) {
  500. ath10k_warn("could not set the baud rate (%d)\n", ret);
  501. return ret;
  502. }
  503. ath10k_info("UART prints enabled\n");
  504. return 0;
  505. }
  506. static int ath10k_init_hw_params(struct ath10k *ar)
  507. {
  508. const struct ath10k_hw_params *uninitialized_var(hw_params);
  509. int i;
  510. for (i = 0; i < ARRAY_SIZE(ath10k_hw_params_list); i++) {
  511. hw_params = &ath10k_hw_params_list[i];
  512. if (hw_params->id == ar->target_version)
  513. break;
  514. }
  515. if (i == ARRAY_SIZE(ath10k_hw_params_list)) {
  516. ath10k_err("Unsupported hardware version: 0x%x\n",
  517. ar->target_version);
  518. return -EINVAL;
  519. }
  520. ar->hw_params = *hw_params;
  521. ath10k_dbg(ATH10K_DBG_BOOT, "Hardware name %s version 0x%x\n",
  522. ar->hw_params.name, ar->target_version);
  523. return 0;
  524. }
  525. static void ath10k_core_restart(struct work_struct *work)
  526. {
  527. struct ath10k *ar = container_of(work, struct ath10k, restart_work);
  528. mutex_lock(&ar->conf_mutex);
  529. switch (ar->state) {
  530. case ATH10K_STATE_ON:
  531. ath10k_halt(ar);
  532. ar->state = ATH10K_STATE_RESTARTING;
  533. ieee80211_restart_hw(ar->hw);
  534. break;
  535. case ATH10K_STATE_OFF:
  536. /* this can happen if driver is being unloaded
  537. * or if the crash happens during FW probing */
  538. ath10k_warn("cannot restart a device that hasn't been started\n");
  539. break;
  540. case ATH10K_STATE_RESTARTING:
  541. case ATH10K_STATE_RESTARTED:
  542. ar->state = ATH10K_STATE_WEDGED;
  543. /* fall through */
  544. case ATH10K_STATE_WEDGED:
  545. ath10k_warn("device is wedged, will not restart\n");
  546. break;
  547. }
  548. mutex_unlock(&ar->conf_mutex);
  549. }
  550. struct ath10k *ath10k_core_create(void *hif_priv, struct device *dev,
  551. const struct ath10k_hif_ops *hif_ops)
  552. {
  553. struct ath10k *ar;
  554. ar = ath10k_mac_create();
  555. if (!ar)
  556. return NULL;
  557. ar->ath_common.priv = ar;
  558. ar->ath_common.hw = ar->hw;
  559. ar->p2p = !!ath10k_p2p;
  560. ar->dev = dev;
  561. ar->hif.priv = hif_priv;
  562. ar->hif.ops = hif_ops;
  563. init_completion(&ar->scan.started);
  564. init_completion(&ar->scan.completed);
  565. init_completion(&ar->scan.on_channel);
  566. init_completion(&ar->install_key_done);
  567. init_completion(&ar->vdev_setup_done);
  568. setup_timer(&ar->scan.timeout, ath10k_reset_scan, (unsigned long)ar);
  569. ar->workqueue = create_singlethread_workqueue("ath10k_wq");
  570. if (!ar->workqueue)
  571. goto err_wq;
  572. mutex_init(&ar->conf_mutex);
  573. spin_lock_init(&ar->data_lock);
  574. INIT_LIST_HEAD(&ar->peers);
  575. init_waitqueue_head(&ar->peer_mapping_wq);
  576. init_completion(&ar->offchan_tx_completed);
  577. INIT_WORK(&ar->offchan_tx_work, ath10k_offchan_tx_work);
  578. skb_queue_head_init(&ar->offchan_tx_queue);
  579. INIT_WORK(&ar->wmi_mgmt_tx_work, ath10k_mgmt_over_wmi_tx_work);
  580. skb_queue_head_init(&ar->wmi_mgmt_tx_queue);
  581. init_waitqueue_head(&ar->event_queue);
  582. INIT_WORK(&ar->restart_work, ath10k_core_restart);
  583. return ar;
  584. err_wq:
  585. ath10k_mac_destroy(ar);
  586. return NULL;
  587. }
  588. EXPORT_SYMBOL(ath10k_core_create);
  589. void ath10k_core_destroy(struct ath10k *ar)
  590. {
  591. flush_workqueue(ar->workqueue);
  592. destroy_workqueue(ar->workqueue);
  593. ath10k_mac_destroy(ar);
  594. }
  595. EXPORT_SYMBOL(ath10k_core_destroy);
  596. int ath10k_core_start(struct ath10k *ar)
  597. {
  598. int status;
  599. lockdep_assert_held(&ar->conf_mutex);
  600. ath10k_bmi_start(ar);
  601. if (ath10k_init_configure_target(ar)) {
  602. status = -EINVAL;
  603. goto err;
  604. }
  605. status = ath10k_init_download_firmware(ar);
  606. if (status)
  607. goto err;
  608. status = ath10k_init_uart(ar);
  609. if (status)
  610. goto err;
  611. ar->htc.htc_ops.target_send_suspend_complete =
  612. ath10k_send_suspend_complete;
  613. status = ath10k_htc_init(ar);
  614. if (status) {
  615. ath10k_err("could not init HTC (%d)\n", status);
  616. goto err;
  617. }
  618. status = ath10k_bmi_done(ar);
  619. if (status)
  620. goto err;
  621. status = ath10k_wmi_attach(ar);
  622. if (status) {
  623. ath10k_err("WMI attach failed: %d\n", status);
  624. goto err;
  625. }
  626. status = ath10k_hif_start(ar);
  627. if (status) {
  628. ath10k_err("could not start HIF: %d\n", status);
  629. goto err_wmi_detach;
  630. }
  631. status = ath10k_htc_wait_target(&ar->htc);
  632. if (status) {
  633. ath10k_err("failed to connect to HTC: %d\n", status);
  634. goto err_hif_stop;
  635. }
  636. status = ath10k_htt_attach(ar);
  637. if (status) {
  638. ath10k_err("could not attach htt (%d)\n", status);
  639. goto err_hif_stop;
  640. }
  641. status = ath10k_init_connect_htc(ar);
  642. if (status)
  643. goto err_htt_detach;
  644. ath10k_dbg(ATH10K_DBG_BOOT, "firmware %s booted\n",
  645. ar->hw->wiphy->fw_version);
  646. status = ath10k_wmi_cmd_init(ar);
  647. if (status) {
  648. ath10k_err("could not send WMI init command (%d)\n", status);
  649. goto err_disconnect_htc;
  650. }
  651. status = ath10k_wmi_wait_for_unified_ready(ar);
  652. if (status <= 0) {
  653. ath10k_err("wmi unified ready event not received\n");
  654. status = -ETIMEDOUT;
  655. goto err_disconnect_htc;
  656. }
  657. status = ath10k_htt_attach_target(&ar->htt);
  658. if (status)
  659. goto err_disconnect_htc;
  660. status = ath10k_debug_start(ar);
  661. if (status)
  662. goto err_disconnect_htc;
  663. ar->free_vdev_map = (1 << TARGET_NUM_VDEVS) - 1;
  664. INIT_LIST_HEAD(&ar->arvifs);
  665. if (!test_bit(ATH10K_FLAG_FIRST_BOOT_DONE, &ar->dev_flags))
  666. ath10k_info("%s (0x%x) fw %s api %d htt %d.%d\n",
  667. ar->hw_params.name, ar->target_version,
  668. ar->hw->wiphy->fw_version, ar->fw_api,
  669. ar->htt.target_version_major,
  670. ar->htt.target_version_minor);
  671. __set_bit(ATH10K_FLAG_FIRST_BOOT_DONE, &ar->dev_flags);
  672. return 0;
  673. err_disconnect_htc:
  674. ath10k_htc_stop(&ar->htc);
  675. err_htt_detach:
  676. ath10k_htt_detach(&ar->htt);
  677. err_hif_stop:
  678. ath10k_hif_stop(ar);
  679. err_wmi_detach:
  680. ath10k_wmi_detach(ar);
  681. err:
  682. return status;
  683. }
  684. EXPORT_SYMBOL(ath10k_core_start);
  685. void ath10k_core_stop(struct ath10k *ar)
  686. {
  687. lockdep_assert_held(&ar->conf_mutex);
  688. ath10k_debug_stop(ar);
  689. ath10k_htc_stop(&ar->htc);
  690. ath10k_htt_detach(&ar->htt);
  691. ath10k_wmi_detach(ar);
  692. }
  693. EXPORT_SYMBOL(ath10k_core_stop);
  694. /* mac80211 manages fw/hw initialization through start/stop hooks. However in
  695. * order to know what hw capabilities should be advertised to mac80211 it is
  696. * necessary to load the firmware (and tear it down immediately since start
  697. * hook will try to init it again) before registering */
  698. static int ath10k_core_probe_fw(struct ath10k *ar)
  699. {
  700. struct bmi_target_info target_info;
  701. int ret = 0;
  702. ret = ath10k_hif_power_up(ar);
  703. if (ret) {
  704. ath10k_err("could not start pci hif (%d)\n", ret);
  705. return ret;
  706. }
  707. memset(&target_info, 0, sizeof(target_info));
  708. ret = ath10k_bmi_get_target_info(ar, &target_info);
  709. if (ret) {
  710. ath10k_err("could not get target info (%d)\n", ret);
  711. ath10k_hif_power_down(ar);
  712. return ret;
  713. }
  714. ar->target_version = target_info.version;
  715. ar->hw->wiphy->hw_version = target_info.version;
  716. ret = ath10k_init_hw_params(ar);
  717. if (ret) {
  718. ath10k_err("could not get hw params (%d)\n", ret);
  719. ath10k_hif_power_down(ar);
  720. return ret;
  721. }
  722. ret = ath10k_core_fetch_firmware_files(ar);
  723. if (ret) {
  724. ath10k_err("could not fetch firmware files (%d)\n", ret);
  725. ath10k_hif_power_down(ar);
  726. return ret;
  727. }
  728. mutex_lock(&ar->conf_mutex);
  729. ret = ath10k_core_start(ar);
  730. if (ret) {
  731. ath10k_err("could not init core (%d)\n", ret);
  732. ath10k_core_free_firmware_files(ar);
  733. ath10k_hif_power_down(ar);
  734. mutex_unlock(&ar->conf_mutex);
  735. return ret;
  736. }
  737. ath10k_core_stop(ar);
  738. mutex_unlock(&ar->conf_mutex);
  739. ath10k_hif_power_down(ar);
  740. return 0;
  741. }
  742. static int ath10k_core_check_chip_id(struct ath10k *ar)
  743. {
  744. u32 hw_revision = MS(ar->chip_id, SOC_CHIP_ID_REV);
  745. ath10k_dbg(ATH10K_DBG_BOOT, "boot chip_id 0x%08x hw_revision 0x%x\n",
  746. ar->chip_id, hw_revision);
  747. /* Check that we are not using hw1.0 (some of them have same pci id
  748. * as hw2.0) before doing anything else as ath10k crashes horribly
  749. * due to missing hw1.0 workarounds. */
  750. switch (hw_revision) {
  751. case QCA988X_HW_1_0_CHIP_ID_REV:
  752. ath10k_err("ERROR: qca988x hw1.0 is not supported\n");
  753. return -EOPNOTSUPP;
  754. case QCA988X_HW_2_0_CHIP_ID_REV:
  755. /* known hardware revision, continue normally */
  756. return 0;
  757. default:
  758. ath10k_warn("Warning: hardware revision unknown (0x%x), expect problems\n",
  759. ar->chip_id);
  760. return 0;
  761. }
  762. return 0;
  763. }
  764. int ath10k_core_register(struct ath10k *ar, u32 chip_id)
  765. {
  766. int status;
  767. ar->chip_id = chip_id;
  768. status = ath10k_core_check_chip_id(ar);
  769. if (status) {
  770. ath10k_err("Unsupported chip id 0x%08x\n", ar->chip_id);
  771. return status;
  772. }
  773. status = ath10k_core_probe_fw(ar);
  774. if (status) {
  775. ath10k_err("could not probe fw (%d)\n", status);
  776. return status;
  777. }
  778. status = ath10k_mac_register(ar);
  779. if (status) {
  780. ath10k_err("could not register to mac80211 (%d)\n", status);
  781. goto err_release_fw;
  782. }
  783. status = ath10k_debug_create(ar);
  784. if (status) {
  785. ath10k_err("unable to initialize debugfs\n");
  786. goto err_unregister_mac;
  787. }
  788. return 0;
  789. err_unregister_mac:
  790. ath10k_mac_unregister(ar);
  791. err_release_fw:
  792. ath10k_core_free_firmware_files(ar);
  793. return status;
  794. }
  795. EXPORT_SYMBOL(ath10k_core_register);
  796. void ath10k_core_unregister(struct ath10k *ar)
  797. {
  798. /* We must unregister from mac80211 before we stop HTC and HIF.
  799. * Otherwise we will fail to submit commands to FW and mac80211 will be
  800. * unhappy about callback failures. */
  801. ath10k_mac_unregister(ar);
  802. ath10k_core_free_firmware_files(ar);
  803. ath10k_debug_destroy(ar);
  804. }
  805. EXPORT_SYMBOL(ath10k_core_unregister);
  806. MODULE_AUTHOR("Qualcomm Atheros");
  807. MODULE_DESCRIPTION("Core module for QCA988X PCIe devices.");
  808. MODULE_LICENSE("Dual BSD/GPL");