dp_umac_reset.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. /*
  2. * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <dp_types.h>
  17. #include <wlan_cfg.h>
  18. #include <hif.h>
  19. #include <dp_htt.h>
  20. /**
  21. * dp_get_umac_reset_intr_ctx() - Get the interrupt context to be used by
  22. * UMAC reset feature
  23. * @soc: DP soc object
  24. * @intr_ctx: Interrupt context variable to be populated by this API
  25. *
  26. * Return: QDF_STATUS of operation
  27. */
  28. static QDF_STATUS dp_get_umac_reset_intr_ctx(struct dp_soc *soc, int *intr_ctx)
  29. {
  30. int umac_reset_mask, i;
  31. /**
  32. * Go over all the contexts and check which interrupt context has
  33. * the UMAC reset mask set.
  34. */
  35. for (i = 0; i < wlan_cfg_get_num_contexts(soc->wlan_cfg_ctx); i++) {
  36. umac_reset_mask = wlan_cfg_get_umac_reset_intr_mask(
  37. soc->wlan_cfg_ctx, i);
  38. if (umac_reset_mask) {
  39. *intr_ctx = i;
  40. return QDF_STATUS_SUCCESS;
  41. }
  42. }
  43. *intr_ctx = -1;
  44. return QDF_STATUS_E_FAILURE;
  45. }
  46. /**
  47. * dp_umac_reset_send_setup_cmd(): Send the UMAC reset setup command
  48. * @soc: dp soc object
  49. *
  50. * Return: QDF_STATUS of operation
  51. */
  52. static QDF_STATUS
  53. dp_umac_reset_send_setup_cmd(struct dp_soc *soc)
  54. {
  55. struct dp_soc_umac_reset_ctx *umac_reset_ctx;
  56. int msi_vector_count, ret;
  57. uint32_t msi_base_data, msi_vector_start;
  58. struct dp_htt_umac_reset_setup_cmd_params params;
  59. umac_reset_ctx = &soc->umac_reset_ctx;
  60. ret = pld_get_user_msi_assignment(soc->osdev->dev, "DP",
  61. &msi_vector_count, &msi_base_data,
  62. &msi_vector_start);
  63. if (ret)
  64. return QDF_STATUS_E_FAILURE;
  65. qdf_mem_zero(&params, sizeof(params));
  66. params.msi_data = (umac_reset_ctx->intr_offset % msi_vector_count) +
  67. msi_base_data;
  68. params.shmem_addr_low =
  69. qdf_get_lower_32_bits(umac_reset_ctx->shmem_paddr_aligned);
  70. params.shmem_addr_high =
  71. qdf_get_upper_32_bits(umac_reset_ctx->shmem_paddr_aligned);
  72. return dp_htt_umac_reset_send_setup_cmd(soc, &params);
  73. }
  74. QDF_STATUS dp_soc_umac_reset_init(struct dp_soc *soc)
  75. {
  76. struct dp_soc_umac_reset_ctx *umac_reset_ctx;
  77. size_t alloc_size;
  78. QDF_STATUS status;
  79. if (!soc) {
  80. dp_umac_reset_err("DP SOC is null");
  81. return QDF_STATUS_E_NULL_VALUE;
  82. }
  83. if (!soc->features.umac_hw_reset_support) {
  84. dp_umac_reset_info("Target doesn't support the UMAC HW reset feature");
  85. return QDF_STATUS_E_NOSUPPORT;
  86. }
  87. umac_reset_ctx = &soc->umac_reset_ctx;
  88. qdf_mem_zero(umac_reset_ctx, sizeof(*umac_reset_ctx));
  89. umac_reset_ctx->current_state = UMAC_RESET_STATE_WAIT_FOR_DO_PRE_RESET;
  90. umac_reset_ctx->shmem_exp_magic_num = DP_UMAC_RESET_SHMEM_MAGIC_NUM;
  91. status = dp_get_umac_reset_intr_ctx(soc, &umac_reset_ctx->intr_offset);
  92. if (QDF_IS_STATUS_ERROR(status)) {
  93. dp_umac_reset_err("No interrupt assignment");
  94. return status;
  95. }
  96. alloc_size = sizeof(htt_umac_hang_recovery_msg_shmem_t) +
  97. DP_UMAC_RESET_SHMEM_ALIGN - 1;
  98. umac_reset_ctx->shmem_vaddr_unaligned =
  99. qdf_mem_alloc_consistent(soc->osdev, soc->osdev->dev,
  100. alloc_size,
  101. &umac_reset_ctx->shmem_paddr_unaligned);
  102. if (!umac_reset_ctx->shmem_vaddr_unaligned) {
  103. dp_umac_reset_err("shmem allocation failed");
  104. return QDF_STATUS_E_NOMEM;
  105. }
  106. umac_reset_ctx->shmem_vaddr_aligned = (void *)(uintptr_t)qdf_roundup(
  107. (uint64_t)(uintptr_t)umac_reset_ctx->shmem_vaddr_unaligned,
  108. DP_UMAC_RESET_SHMEM_ALIGN);
  109. umac_reset_ctx->shmem_paddr_aligned = qdf_roundup(
  110. (uint64_t)umac_reset_ctx->shmem_paddr_unaligned,
  111. DP_UMAC_RESET_SHMEM_ALIGN);
  112. umac_reset_ctx->shmem_size = alloc_size;
  113. /* Write the magic number to the shared memory */
  114. umac_reset_ctx->shmem_vaddr_aligned->magic_num =
  115. DP_UMAC_RESET_SHMEM_MAGIC_NUM;
  116. /* Attach the interrupts */
  117. status = dp_umac_reset_interrupt_attach(soc);
  118. if (QDF_IS_STATUS_ERROR(status)) {
  119. dp_umac_reset_err("Interrupt attach failed");
  120. qdf_mem_free_consistent(soc->osdev, soc->osdev->dev,
  121. umac_reset_ctx->shmem_size,
  122. umac_reset_ctx->shmem_vaddr_unaligned,
  123. umac_reset_ctx->shmem_paddr_unaligned,
  124. 0);
  125. return status;
  126. }
  127. /* Send the setup cmd to the target */
  128. return dp_umac_reset_send_setup_cmd(soc);
  129. }
  130. QDF_STATUS dp_soc_umac_reset_deinit(struct cdp_soc_t *txrx_soc)
  131. {
  132. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  133. struct dp_soc_umac_reset_ctx *umac_reset_ctx;
  134. if (!soc) {
  135. dp_umac_reset_err("DP SOC is null");
  136. return QDF_STATUS_E_NULL_VALUE;
  137. }
  138. if (!soc->features.umac_hw_reset_support) {
  139. dp_umac_reset_info("Target doesn't support the UMAC HW reset feature");
  140. return QDF_STATUS_E_NOSUPPORT;
  141. }
  142. dp_umac_reset_interrupt_detach(soc);
  143. umac_reset_ctx = &soc->umac_reset_ctx;
  144. qdf_mem_free_consistent(soc->osdev, soc->osdev->dev,
  145. umac_reset_ctx->shmem_size,
  146. umac_reset_ctx->shmem_vaddr_unaligned,
  147. umac_reset_ctx->shmem_paddr_unaligned,
  148. 0);
  149. return QDF_STATUS_SUCCESS;
  150. }
  151. /**
  152. * dp_umac_reset_get_rx_event() - Extract the Rx event from the shared memory
  153. * @umac_reset_ctx: UMAC reset context
  154. *
  155. * Return: Extracted Rx event in the form of enumeration umac_reset_rx_event
  156. */
  157. static enum umac_reset_rx_event
  158. dp_umac_reset_get_rx_event_from_shmem(
  159. struct dp_soc_umac_reset_ctx *umac_reset_ctx)
  160. {
  161. htt_umac_hang_recovery_msg_shmem_t *shmem_vaddr;
  162. uint32_t t2h_msg;
  163. uint8_t num_events = 0;
  164. enum umac_reset_rx_event rx_event;
  165. shmem_vaddr = umac_reset_ctx->shmem_vaddr_aligned;
  166. if (!shmem_vaddr) {
  167. dp_umac_reset_err("Shared memory address is NULL");
  168. goto err;
  169. }
  170. if (shmem_vaddr->magic_num != umac_reset_ctx->shmem_exp_magic_num) {
  171. dp_umac_reset_err("Shared memory got corrupted");
  172. goto err;
  173. }
  174. /* Read the shared memory into a local variable */
  175. t2h_msg = shmem_vaddr->t2h_msg;
  176. /* Clear the shared memory right away */
  177. shmem_vaddr->t2h_msg = 0;
  178. dp_umac_reset_debug("shmem value - t2h_msg: 0x%x", t2h_msg);
  179. rx_event = UMAC_RESET_RX_EVENT_NONE;
  180. if (HTT_UMAC_HANG_RECOVERY_MSG_SHMEM_DO_PRE_RESET_GET(t2h_msg)) {
  181. rx_event |= UMAC_RESET_RX_EVENT_DO_PRE_RESET;
  182. num_events++;
  183. }
  184. if (HTT_UMAC_HANG_RECOVERY_MSG_SHMEM_DO_POST_RESET_START_GET(t2h_msg)) {
  185. rx_event |= UMAC_RESET_RX_EVENT_DO_POST_RESET_START;
  186. num_events++;
  187. }
  188. if (HTT_UMAC_HANG_RECOVERY_MSG_SHMEM_DO_POST_RESET_COMPLETE_GET(t2h_msg)) {
  189. rx_event |= UMAC_RESET_RX_EVENT_DO_POST_RESET_COMPELTE;
  190. num_events++;
  191. }
  192. dp_umac_reset_debug("deduced rx event: 0x%x", rx_event);
  193. /* There should not be more than 1 event */
  194. if (num_events > 1) {
  195. dp_umac_reset_err("Multiple events(0x%x) got posted", rx_event);
  196. goto err;
  197. }
  198. return rx_event;
  199. err:
  200. qdf_assert_always(0);
  201. return UMAC_RESET_RX_EVENT_ERROR;
  202. }
  203. /**
  204. * dp_umac_reset_get_rx_event() - Extract the Rx event
  205. * @umac_reset_ctx: UMAC reset context
  206. *
  207. * Return: Extracted Rx event in the form of enumeration umac_reset_rx_event
  208. */
  209. static inline enum umac_reset_rx_event
  210. dp_umac_reset_get_rx_event(struct dp_soc_umac_reset_ctx *umac_reset_ctx)
  211. {
  212. return dp_umac_reset_get_rx_event_from_shmem(umac_reset_ctx);
  213. }
  214. /**
  215. * dp_umac_reset_validate_n_update_state_machine_on_rx() - Validate the state
  216. * machine for a given rx event and update the state machine
  217. * @umac_reset_ctx: UMAC reset context
  218. * @rx_event: Rx event
  219. * @current_exp_state: Expected state
  220. * @next_state: The state to which the state machine needs to be updated
  221. *
  222. * Return: QDF_STATUS of operation
  223. */
  224. static QDF_STATUS
  225. dp_umac_reset_validate_n_update_state_machine_on_rx(
  226. struct dp_soc_umac_reset_ctx *umac_reset_ctx,
  227. enum umac_reset_rx_event rx_event,
  228. enum umac_reset_state current_exp_state,
  229. enum umac_reset_state next_state)
  230. {
  231. if (umac_reset_ctx->current_state != current_exp_state) {
  232. dp_umac_reset_err("state machine validation failed on rx event: %d, current state is %d",
  233. rx_event,
  234. umac_reset_ctx->current_state);
  235. qdf_assert_always(0);
  236. return QDF_STATUS_E_FAILURE;
  237. }
  238. /* Update the state */
  239. umac_reset_ctx->current_state = next_state;
  240. return QDF_STATUS_SUCCESS;
  241. }
  242. /**
  243. * dp_umac_reset_rx_event_handler() - Main Rx event handler for UMAC reset
  244. * @dp_ctx: Interrupt context corresponding to UMAC reset
  245. *
  246. * Return: 0 incase of success, else failure
  247. */
  248. static int dp_umac_reset_rx_event_handler(void *dp_ctx)
  249. {
  250. struct dp_intr *int_ctx = (struct dp_intr *)dp_ctx;
  251. struct dp_soc *soc = int_ctx->soc;
  252. struct dp_soc_umac_reset_ctx *umac_reset_ctx;
  253. enum umac_reset_rx_event rx_event;
  254. QDF_STATUS status = QDF_STATUS_E_INVAL;
  255. enum umac_reset_action action;
  256. if (!soc) {
  257. dp_umac_reset_err("DP SOC is null");
  258. goto exit;
  259. }
  260. umac_reset_ctx = &soc->umac_reset_ctx;
  261. dp_umac_reset_debug("enter");
  262. rx_event = dp_umac_reset_get_rx_event(umac_reset_ctx);
  263. switch (rx_event) {
  264. case UMAC_RESET_RX_EVENT_NONE:
  265. /* This interrupt is not meant for us, so exit */
  266. dp_umac_reset_debug("Not a UMAC reset event");
  267. status = QDF_STATUS_SUCCESS;
  268. goto exit;
  269. case UMAC_RESET_RX_EVENT_DO_PRE_RESET:
  270. status = dp_umac_reset_validate_n_update_state_machine_on_rx(
  271. umac_reset_ctx, rx_event,
  272. UMAC_RESET_STATE_WAIT_FOR_DO_PRE_RESET,
  273. UMAC_RESET_STATE_DO_PRE_RESET_RECEIVED);
  274. action = UMAC_RESET_ACTION_DO_PRE_RESET;
  275. break;
  276. case UMAC_RESET_RX_EVENT_DO_POST_RESET_START:
  277. status = dp_umac_reset_validate_n_update_state_machine_on_rx(
  278. umac_reset_ctx, rx_event,
  279. UMAC_RESET_STATE_WAIT_FOR_DO_POST_RESET_START,
  280. UMAC_RESET_STATE_DO_POST_RESET_START_RECEIVED);
  281. action = UMAC_RESET_ACTION_DO_POST_RESET_START;
  282. break;
  283. case UMAC_RESET_RX_EVENT_DO_POST_RESET_COMPELTE:
  284. status = dp_umac_reset_validate_n_update_state_machine_on_rx(
  285. umac_reset_ctx, rx_event,
  286. UMAC_RESET_STATE_WAIT_FOR_DO_POST_RESET_COMPLETE,
  287. UMAC_RESET_STATE_DO_POST_RESET_COMPLETE_RECEIVED);
  288. action = UMAC_RESET_ACTION_DO_POST_RESET_COMPLETE;
  289. break;
  290. case UMAC_RESET_RX_EVENT_ERROR:
  291. dp_umac_reset_err("Error Rx event");
  292. goto exit;
  293. default:
  294. dp_umac_reset_err("Invalid value(%u) for Rx event", rx_event);
  295. goto exit;
  296. }
  297. /* Call the handler for this event */
  298. if (QDF_IS_STATUS_SUCCESS(status)) {
  299. if (!umac_reset_ctx->rx_actions.cb[action]) {
  300. dp_umac_reset_err("rx callback is NULL");
  301. goto exit;
  302. }
  303. status = umac_reset_ctx->rx_actions.cb[action](soc);
  304. }
  305. exit:
  306. return qdf_status_to_os_return(status);
  307. }
  308. QDF_STATUS dp_umac_reset_interrupt_attach(struct dp_soc *soc)
  309. {
  310. struct dp_soc_umac_reset_ctx *umac_reset_ctx;
  311. int msi_vector_count, ret;
  312. uint32_t msi_base_data, msi_vector_start;
  313. uint32_t umac_reset_vector, umac_reset_irq;
  314. if (!soc) {
  315. dp_umac_reset_err("DP SOC is null");
  316. return QDF_STATUS_E_NULL_VALUE;
  317. }
  318. if (!soc->features.umac_hw_reset_support) {
  319. dp_umac_reset_info("Target doesn't support the UMAC HW reset feature");
  320. return QDF_STATUS_SUCCESS;
  321. }
  322. umac_reset_ctx = &soc->umac_reset_ctx;
  323. if (pld_get_enable_intx(soc->osdev->dev)) {
  324. dp_umac_reset_err("UMAC reset is not supported in legacy interrupt mode");
  325. return QDF_STATUS_E_FAILURE;
  326. }
  327. ret = pld_get_user_msi_assignment(soc->osdev->dev, "DP",
  328. &msi_vector_count, &msi_base_data,
  329. &msi_vector_start);
  330. if (ret) {
  331. dp_umac_reset_err("UMAC reset is only supported in MSI interrupt mode");
  332. return QDF_STATUS_E_FAILURE;
  333. }
  334. if (umac_reset_ctx->intr_offset < 0 ||
  335. umac_reset_ctx->intr_offset >= WLAN_CFG_INT_NUM_CONTEXTS) {
  336. dp_umac_reset_err("Invalid interrupt offset");
  337. return QDF_STATUS_E_FAILURE;
  338. }
  339. umac_reset_vector = msi_vector_start +
  340. (umac_reset_ctx->intr_offset % msi_vector_count);
  341. /* Get IRQ number */
  342. umac_reset_irq = pld_get_msi_irq(soc->osdev->dev, umac_reset_vector);
  343. /* Finally register to this IRQ from HIF layer */
  344. return hif_register_umac_reset_handler(
  345. soc->hif_handle,
  346. dp_umac_reset_rx_event_handler,
  347. &soc->intr_ctx[umac_reset_ctx->intr_offset],
  348. umac_reset_irq);
  349. }
  350. QDF_STATUS dp_umac_reset_interrupt_detach(struct dp_soc *soc)
  351. {
  352. if (!soc) {
  353. dp_umac_reset_err("DP SOC is null");
  354. return QDF_STATUS_E_NULL_VALUE;
  355. }
  356. if (!soc->features.umac_hw_reset_support) {
  357. dp_umac_reset_info("Target doesn't support the UMAC HW reset feature");
  358. return QDF_STATUS_SUCCESS;
  359. }
  360. return hif_unregister_umac_reset_handler(soc->hif_handle);
  361. }
  362. QDF_STATUS dp_umac_reset_register_rx_action_callback(
  363. struct dp_soc *soc,
  364. QDF_STATUS (*handler)(struct dp_soc *soc),
  365. enum umac_reset_action action)
  366. {
  367. struct dp_soc_umac_reset_ctx *umac_reset_ctx;
  368. if (!soc) {
  369. dp_umac_reset_err("DP SOC is null");
  370. return QDF_STATUS_E_NULL_VALUE;
  371. }
  372. if (!soc->features.umac_hw_reset_support) {
  373. dp_umac_reset_info("Target doesn't support the UMAC HW reset feature");
  374. return QDF_STATUS_E_NOSUPPORT;
  375. }
  376. if (action >= UMAC_RESET_ACTION_MAX) {
  377. dp_umac_reset_err("invalid action: %d", action);
  378. return QDF_STATUS_E_INVAL;
  379. }
  380. umac_reset_ctx = &soc->umac_reset_ctx;
  381. umac_reset_ctx->rx_actions.cb[action] = handler;
  382. return QDF_STATUS_SUCCESS;
  383. }
  384. /**
  385. * dp_umac_reset_post_tx_cmd_via_shmem() - Post Tx command using shared memory
  386. * @umac_reset_ctx: UMAC reset context
  387. * @tx_cmd: Tx command to be posted
  388. *
  389. * Return: QDF status of operation
  390. */
  391. static QDF_STATUS
  392. dp_umac_reset_post_tx_cmd_via_shmem(
  393. struct dp_soc_umac_reset_ctx *umac_reset_ctx,
  394. enum umac_reset_tx_cmd tx_cmd)
  395. {
  396. htt_umac_hang_recovery_msg_shmem_t *shmem_vaddr;
  397. shmem_vaddr = umac_reset_ctx->shmem_vaddr_aligned;
  398. if (!shmem_vaddr) {
  399. dp_umac_reset_err("Shared memory address is NULL");
  400. return QDF_STATUS_E_NULL_VALUE;
  401. }
  402. switch (tx_cmd) {
  403. case UMAC_RESET_TX_CMD_PRE_RESET_DONE:
  404. HTT_UMAC_HANG_RECOVERY_MSG_SHMEM_PRE_RESET_DONE_SET(
  405. shmem_vaddr->h2t_msg, 1);
  406. break;
  407. case UMAC_RESET_TX_CMD_POST_RESET_START_DONE:
  408. HTT_UMAC_HANG_RECOVERY_MSG_SHMEM_POST_RESET_START_DONE_SET(
  409. shmem_vaddr->h2t_msg, 1);
  410. break;
  411. case UMAC_RESET_TX_CMD_POST_RESET_COMPLETE_DONE:
  412. HTT_UMAC_HANG_RECOVERY_MSG_SHMEM_POST_RESET_COMPLETE_DONE_SET(
  413. shmem_vaddr->h2t_msg, 1);
  414. break;
  415. default:
  416. dp_umac_reset_err("Invalid tx cmd: %d", tx_cmd);
  417. return QDF_STATUS_E_FAILURE;
  418. }
  419. return QDF_STATUS_SUCCESS;
  420. }
  421. /**
  422. * dp_umac_reset_notify_target() - Notify the target about completion of action.
  423. * @umac_reset_ctx: UMAC reset context
  424. *
  425. * This API figures out the Tx command that needs to be posted based on the
  426. * current state in the state machine. Also, updates the state machine once the
  427. * Tx command has been posted.
  428. *
  429. * Return: QDF status of operation
  430. */
  431. static QDF_STATUS
  432. dp_umac_reset_notify_target(struct dp_soc_umac_reset_ctx *umac_reset_ctx)
  433. {
  434. enum umac_reset_state next_state;
  435. enum umac_reset_tx_cmd tx_cmd;
  436. QDF_STATUS status;
  437. switch (umac_reset_ctx->current_state) {
  438. case UMAC_RESET_STATE_HOST_PRE_RESET_DONE:
  439. tx_cmd = UMAC_RESET_TX_CMD_PRE_RESET_DONE;
  440. next_state = UMAC_RESET_STATE_WAIT_FOR_DO_POST_RESET_START;
  441. break;
  442. case UMAC_RESET_STATE_HOST_POST_RESET_START_DONE:
  443. tx_cmd = UMAC_RESET_TX_CMD_POST_RESET_START_DONE;
  444. next_state = UMAC_RESET_STATE_WAIT_FOR_DO_POST_RESET_COMPLETE;
  445. break;
  446. case UMAC_RESET_STATE_HOST_POST_RESET_COMPLETE_DONE:
  447. tx_cmd = UMAC_RESET_TX_CMD_POST_RESET_COMPLETE_DONE;
  448. next_state = UMAC_RESET_STATE_WAIT_FOR_DO_PRE_RESET;
  449. break;
  450. default:
  451. dp_umac_reset_err("Invalid state(%d) during Tx",
  452. umac_reset_ctx->current_state);
  453. qdf_assert_always(0);
  454. return QDF_STATUS_E_FAILURE;
  455. }
  456. status = dp_umac_reset_post_tx_cmd_via_shmem(umac_reset_ctx, tx_cmd);
  457. if (QDF_IS_STATUS_ERROR(status)) {
  458. dp_umac_reset_err("Couldn't post Tx cmd");
  459. qdf_assert_always(0);
  460. return status;
  461. }
  462. /* Update the state machine */
  463. umac_reset_ctx->current_state = next_state;
  464. return status;
  465. }
  466. /**
  467. * dp_umac_reset_notify_completion() - Notify that a given action has been
  468. * completed
  469. * @soc: DP soc object
  470. * @next_state: The state to which the state machine needs to be updated due to
  471. * this completion
  472. *
  473. * Return: QDF status of operation
  474. */
  475. static QDF_STATUS dp_umac_reset_notify_completion(
  476. struct dp_soc *soc,
  477. enum umac_reset_state next_state)
  478. {
  479. struct dp_soc_umac_reset_ctx *umac_reset_ctx;
  480. if (!soc) {
  481. dp_umac_reset_err("DP SOC is null");
  482. return QDF_STATUS_E_NULL_VALUE;
  483. }
  484. umac_reset_ctx = &soc->umac_reset_ctx;
  485. /* Update the state first */
  486. umac_reset_ctx->current_state = next_state;
  487. return dp_umac_reset_notify_target(umac_reset_ctx);
  488. }
  489. QDF_STATUS dp_umac_reset_notify_action_completion(
  490. struct dp_soc *soc,
  491. enum umac_reset_action action)
  492. {
  493. enum umac_reset_state next_state;
  494. if (!soc) {
  495. dp_umac_reset_err("DP SOC is null");
  496. return QDF_STATUS_E_NULL_VALUE;
  497. }
  498. if (!soc->features.umac_hw_reset_support) {
  499. dp_umac_reset_info("Target doesn't support the UMAC HW reset feature");
  500. return QDF_STATUS_E_NOSUPPORT;
  501. }
  502. switch (action) {
  503. case UMAC_RESET_ACTION_DO_PRE_RESET:
  504. next_state = UMAC_RESET_STATE_HOST_PRE_RESET_DONE;
  505. break;
  506. case UMAC_RESET_ACTION_DO_POST_RESET_START:
  507. next_state = UMAC_RESET_STATE_HOST_POST_RESET_START_DONE;
  508. break;
  509. case UMAC_RESET_ACTION_DO_POST_RESET_COMPLETE:
  510. next_state = UMAC_RESET_STATE_HOST_POST_RESET_COMPLETE_DONE;
  511. break;
  512. default:
  513. dp_umac_reset_err("Invalid action");
  514. return QDF_STATUS_E_FAILURE;
  515. }
  516. return dp_umac_reset_notify_completion(soc, next_state);
  517. }