dp_umac_reset.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  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. umac_reset_ctx->ts.pre_reset_start =
  271. qdf_get_log_timestamp_usecs();
  272. status = dp_umac_reset_validate_n_update_state_machine_on_rx(
  273. umac_reset_ctx, rx_event,
  274. UMAC_RESET_STATE_WAIT_FOR_DO_PRE_RESET,
  275. UMAC_RESET_STATE_DO_PRE_RESET_RECEIVED);
  276. action = UMAC_RESET_ACTION_DO_PRE_RESET;
  277. break;
  278. case UMAC_RESET_RX_EVENT_DO_POST_RESET_START:
  279. umac_reset_ctx->ts.post_reset_start =
  280. qdf_get_log_timestamp_usecs();
  281. status = dp_umac_reset_validate_n_update_state_machine_on_rx(
  282. umac_reset_ctx, rx_event,
  283. UMAC_RESET_STATE_WAIT_FOR_DO_POST_RESET_START,
  284. UMAC_RESET_STATE_DO_POST_RESET_START_RECEIVED);
  285. action = UMAC_RESET_ACTION_DO_POST_RESET_START;
  286. break;
  287. case UMAC_RESET_RX_EVENT_DO_POST_RESET_COMPELTE:
  288. umac_reset_ctx->ts.post_reset_complete_start =
  289. qdf_get_log_timestamp_usecs();
  290. status = dp_umac_reset_validate_n_update_state_machine_on_rx(
  291. umac_reset_ctx, rx_event,
  292. UMAC_RESET_STATE_WAIT_FOR_DO_POST_RESET_COMPLETE,
  293. UMAC_RESET_STATE_DO_POST_RESET_COMPLETE_RECEIVED);
  294. action = UMAC_RESET_ACTION_DO_POST_RESET_COMPLETE;
  295. break;
  296. case UMAC_RESET_RX_EVENT_ERROR:
  297. dp_umac_reset_err("Error Rx event");
  298. goto exit;
  299. default:
  300. dp_umac_reset_err("Invalid value(%u) for Rx event", rx_event);
  301. goto exit;
  302. }
  303. /* Call the handler for this event */
  304. if (QDF_IS_STATUS_SUCCESS(status)) {
  305. if (!umac_reset_ctx->rx_actions.cb[action]) {
  306. dp_umac_reset_err("rx callback is NULL");
  307. goto exit;
  308. }
  309. status = umac_reset_ctx->rx_actions.cb[action](soc);
  310. }
  311. exit:
  312. return qdf_status_to_os_return(status);
  313. }
  314. QDF_STATUS dp_umac_reset_interrupt_attach(struct dp_soc *soc)
  315. {
  316. struct dp_soc_umac_reset_ctx *umac_reset_ctx;
  317. int msi_vector_count, ret;
  318. uint32_t msi_base_data, msi_vector_start;
  319. uint32_t umac_reset_vector, umac_reset_irq;
  320. if (!soc) {
  321. dp_umac_reset_err("DP SOC is null");
  322. return QDF_STATUS_E_NULL_VALUE;
  323. }
  324. if (!soc->features.umac_hw_reset_support) {
  325. dp_umac_reset_info("Target doesn't support the UMAC HW reset feature");
  326. return QDF_STATUS_SUCCESS;
  327. }
  328. umac_reset_ctx = &soc->umac_reset_ctx;
  329. if (pld_get_enable_intx(soc->osdev->dev)) {
  330. dp_umac_reset_err("UMAC reset is not supported in legacy interrupt mode");
  331. return QDF_STATUS_E_FAILURE;
  332. }
  333. ret = pld_get_user_msi_assignment(soc->osdev->dev, "DP",
  334. &msi_vector_count, &msi_base_data,
  335. &msi_vector_start);
  336. if (ret) {
  337. dp_umac_reset_err("UMAC reset is only supported in MSI interrupt mode");
  338. return QDF_STATUS_E_FAILURE;
  339. }
  340. if (umac_reset_ctx->intr_offset < 0 ||
  341. umac_reset_ctx->intr_offset >= WLAN_CFG_INT_NUM_CONTEXTS) {
  342. dp_umac_reset_err("Invalid interrupt offset");
  343. return QDF_STATUS_E_FAILURE;
  344. }
  345. umac_reset_vector = msi_vector_start +
  346. (umac_reset_ctx->intr_offset % msi_vector_count);
  347. /* Get IRQ number */
  348. umac_reset_irq = pld_get_msi_irq(soc->osdev->dev, umac_reset_vector);
  349. /* Finally register to this IRQ from HIF layer */
  350. return hif_register_umac_reset_handler(
  351. soc->hif_handle,
  352. dp_umac_reset_rx_event_handler,
  353. &soc->intr_ctx[umac_reset_ctx->intr_offset],
  354. umac_reset_irq);
  355. }
  356. QDF_STATUS dp_umac_reset_interrupt_detach(struct dp_soc *soc)
  357. {
  358. if (!soc) {
  359. dp_umac_reset_err("DP SOC is null");
  360. return QDF_STATUS_E_NULL_VALUE;
  361. }
  362. if (!soc->features.umac_hw_reset_support) {
  363. dp_umac_reset_info("Target doesn't support the UMAC HW reset feature");
  364. return QDF_STATUS_SUCCESS;
  365. }
  366. return hif_unregister_umac_reset_handler(soc->hif_handle);
  367. }
  368. QDF_STATUS dp_umac_reset_register_rx_action_callback(
  369. struct dp_soc *soc,
  370. QDF_STATUS (*handler)(struct dp_soc *soc),
  371. enum umac_reset_action action)
  372. {
  373. struct dp_soc_umac_reset_ctx *umac_reset_ctx;
  374. if (!soc) {
  375. dp_umac_reset_err("DP SOC is null");
  376. return QDF_STATUS_E_NULL_VALUE;
  377. }
  378. if (!soc->features.umac_hw_reset_support) {
  379. dp_umac_reset_info("Target doesn't support the UMAC HW reset feature");
  380. return QDF_STATUS_E_NOSUPPORT;
  381. }
  382. if (action >= UMAC_RESET_ACTION_MAX) {
  383. dp_umac_reset_err("invalid action: %d", action);
  384. return QDF_STATUS_E_INVAL;
  385. }
  386. umac_reset_ctx = &soc->umac_reset_ctx;
  387. umac_reset_ctx->rx_actions.cb[action] = handler;
  388. return QDF_STATUS_SUCCESS;
  389. }
  390. /**
  391. * dp_umac_reset_post_tx_cmd_via_shmem() - Post Tx command using shared memory
  392. * @umac_reset_ctx: UMAC reset context
  393. * @tx_cmd: Tx command to be posted
  394. *
  395. * Return: QDF status of operation
  396. */
  397. static QDF_STATUS
  398. dp_umac_reset_post_tx_cmd_via_shmem(
  399. struct dp_soc_umac_reset_ctx *umac_reset_ctx,
  400. enum umac_reset_tx_cmd tx_cmd)
  401. {
  402. htt_umac_hang_recovery_msg_shmem_t *shmem_vaddr;
  403. shmem_vaddr = umac_reset_ctx->shmem_vaddr_aligned;
  404. if (!shmem_vaddr) {
  405. dp_umac_reset_err("Shared memory address is NULL");
  406. return QDF_STATUS_E_NULL_VALUE;
  407. }
  408. switch (tx_cmd) {
  409. case UMAC_RESET_TX_CMD_PRE_RESET_DONE:
  410. HTT_UMAC_HANG_RECOVERY_MSG_SHMEM_PRE_RESET_DONE_SET(
  411. shmem_vaddr->h2t_msg, 1);
  412. umac_reset_ctx->ts.pre_reset_done =
  413. qdf_get_log_timestamp_usecs();
  414. break;
  415. case UMAC_RESET_TX_CMD_POST_RESET_START_DONE:
  416. HTT_UMAC_HANG_RECOVERY_MSG_SHMEM_POST_RESET_START_DONE_SET(
  417. shmem_vaddr->h2t_msg, 1);
  418. umac_reset_ctx->ts.post_reset_done =
  419. qdf_get_log_timestamp_usecs();
  420. break;
  421. case UMAC_RESET_TX_CMD_POST_RESET_COMPLETE_DONE:
  422. HTT_UMAC_HANG_RECOVERY_MSG_SHMEM_POST_RESET_COMPLETE_DONE_SET(
  423. shmem_vaddr->h2t_msg, 1);
  424. umac_reset_ctx->ts.post_reset_complete_done =
  425. qdf_get_log_timestamp_usecs();
  426. break;
  427. default:
  428. dp_umac_reset_err("Invalid tx cmd: %d", tx_cmd);
  429. return QDF_STATUS_E_FAILURE;
  430. }
  431. return QDF_STATUS_SUCCESS;
  432. }
  433. /**
  434. * dp_umac_reset_notify_target() - Notify the target about completion of action.
  435. * @umac_reset_ctx: UMAC reset context
  436. *
  437. * This API figures out the Tx command that needs to be posted based on the
  438. * current state in the state machine. Also, updates the state machine once the
  439. * Tx command has been posted.
  440. *
  441. * Return: QDF status of operation
  442. */
  443. static QDF_STATUS
  444. dp_umac_reset_notify_target(struct dp_soc_umac_reset_ctx *umac_reset_ctx)
  445. {
  446. enum umac_reset_state next_state;
  447. enum umac_reset_tx_cmd tx_cmd;
  448. QDF_STATUS status;
  449. switch (umac_reset_ctx->current_state) {
  450. case UMAC_RESET_STATE_HOST_PRE_RESET_DONE:
  451. tx_cmd = UMAC_RESET_TX_CMD_PRE_RESET_DONE;
  452. next_state = UMAC_RESET_STATE_WAIT_FOR_DO_POST_RESET_START;
  453. break;
  454. case UMAC_RESET_STATE_HOST_POST_RESET_START_DONE:
  455. tx_cmd = UMAC_RESET_TX_CMD_POST_RESET_START_DONE;
  456. next_state = UMAC_RESET_STATE_WAIT_FOR_DO_POST_RESET_COMPLETE;
  457. break;
  458. case UMAC_RESET_STATE_HOST_POST_RESET_COMPLETE_DONE:
  459. tx_cmd = UMAC_RESET_TX_CMD_POST_RESET_COMPLETE_DONE;
  460. next_state = UMAC_RESET_STATE_WAIT_FOR_DO_PRE_RESET;
  461. break;
  462. default:
  463. dp_umac_reset_err("Invalid state(%d) during Tx",
  464. umac_reset_ctx->current_state);
  465. qdf_assert_always(0);
  466. return QDF_STATUS_E_FAILURE;
  467. }
  468. status = dp_umac_reset_post_tx_cmd_via_shmem(umac_reset_ctx, tx_cmd);
  469. if (QDF_IS_STATUS_ERROR(status)) {
  470. dp_umac_reset_err("Couldn't post Tx cmd");
  471. qdf_assert_always(0);
  472. return status;
  473. }
  474. /* Update the state machine */
  475. umac_reset_ctx->current_state = next_state;
  476. return status;
  477. }
  478. /**
  479. * dp_umac_reset_notify_completion() - Notify that a given action has been
  480. * completed
  481. * @soc: DP soc object
  482. * @next_state: The state to which the state machine needs to be updated due to
  483. * this completion
  484. *
  485. * Return: QDF status of operation
  486. */
  487. static QDF_STATUS dp_umac_reset_notify_completion(
  488. struct dp_soc *soc,
  489. enum umac_reset_state next_state)
  490. {
  491. struct dp_soc_umac_reset_ctx *umac_reset_ctx;
  492. if (!soc) {
  493. dp_umac_reset_err("DP SOC is null");
  494. return QDF_STATUS_E_NULL_VALUE;
  495. }
  496. umac_reset_ctx = &soc->umac_reset_ctx;
  497. /* Update the state first */
  498. umac_reset_ctx->current_state = next_state;
  499. return dp_umac_reset_notify_target(umac_reset_ctx);
  500. }
  501. QDF_STATUS dp_umac_reset_notify_action_completion(
  502. struct dp_soc *soc,
  503. enum umac_reset_action action)
  504. {
  505. enum umac_reset_state next_state;
  506. if (!soc) {
  507. dp_umac_reset_err("DP SOC is null");
  508. return QDF_STATUS_E_NULL_VALUE;
  509. }
  510. if (!soc->features.umac_hw_reset_support) {
  511. dp_umac_reset_info("Target doesn't support the UMAC HW reset feature");
  512. return QDF_STATUS_E_NOSUPPORT;
  513. }
  514. switch (action) {
  515. case UMAC_RESET_ACTION_DO_PRE_RESET:
  516. next_state = UMAC_RESET_STATE_HOST_PRE_RESET_DONE;
  517. break;
  518. case UMAC_RESET_ACTION_DO_POST_RESET_START:
  519. next_state = UMAC_RESET_STATE_HOST_POST_RESET_START_DONE;
  520. break;
  521. case UMAC_RESET_ACTION_DO_POST_RESET_COMPLETE:
  522. next_state = UMAC_RESET_STATE_HOST_POST_RESET_COMPLETE_DONE;
  523. break;
  524. default:
  525. dp_umac_reset_err("Invalid action");
  526. return QDF_STATUS_E_FAILURE;
  527. }
  528. return dp_umac_reset_notify_completion(soc, next_state);
  529. }