dp_umac_reset.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. /*
  2. * Copyright (c) 2022-2023 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. if (wlan_cfg_get_dp_soc_is_ppeds_enabled(soc->wlan_cfg_ctx)) {
  60. dp_umac_reset_err(
  61. "Umac reset is currently not supported in DS config");
  62. return QDF_STATUS_E_NOSUPPORT;
  63. }
  64. umac_reset_ctx = &soc->umac_reset_ctx;
  65. qdf_mem_zero(&params, sizeof(params));
  66. ret = pld_get_user_msi_assignment(soc->osdev->dev, "DP",
  67. &msi_vector_count, &msi_base_data,
  68. &msi_vector_start);
  69. if (ret) {
  70. params.msi_data = UMAC_RESET_IPC;
  71. } else {
  72. params.msi_data = (umac_reset_ctx->intr_offset %
  73. msi_vector_count) + msi_base_data;
  74. }
  75. params.shmem_addr_low =
  76. qdf_get_lower_32_bits(umac_reset_ctx->shmem_paddr_aligned);
  77. params.shmem_addr_high =
  78. qdf_get_upper_32_bits(umac_reset_ctx->shmem_paddr_aligned);
  79. return dp_htt_umac_reset_send_setup_cmd(soc, &params);
  80. }
  81. QDF_STATUS dp_soc_umac_reset_init(struct dp_soc *soc)
  82. {
  83. struct dp_soc_umac_reset_ctx *umac_reset_ctx;
  84. size_t alloc_size;
  85. QDF_STATUS status;
  86. if (!soc) {
  87. dp_umac_reset_err("DP SOC is null");
  88. return QDF_STATUS_E_NULL_VALUE;
  89. }
  90. if (!soc->features.umac_hw_reset_support) {
  91. dp_umac_reset_info("Target doesn't support the UMAC HW reset feature");
  92. return QDF_STATUS_E_NOSUPPORT;
  93. }
  94. umac_reset_ctx = &soc->umac_reset_ctx;
  95. qdf_mem_zero(umac_reset_ctx, sizeof(*umac_reset_ctx));
  96. umac_reset_ctx->current_state = UMAC_RESET_STATE_WAIT_FOR_DO_PRE_RESET;
  97. umac_reset_ctx->shmem_exp_magic_num = DP_UMAC_RESET_SHMEM_MAGIC_NUM;
  98. status = dp_get_umac_reset_intr_ctx(soc, &umac_reset_ctx->intr_offset);
  99. if (QDF_IS_STATUS_ERROR(status)) {
  100. dp_umac_reset_err("No interrupt assignment");
  101. return status;
  102. }
  103. alloc_size = sizeof(htt_umac_hang_recovery_msg_shmem_t) +
  104. DP_UMAC_RESET_SHMEM_ALIGN - 1;
  105. umac_reset_ctx->shmem_vaddr_unaligned =
  106. qdf_mem_alloc_consistent(soc->osdev, soc->osdev->dev,
  107. alloc_size,
  108. &umac_reset_ctx->shmem_paddr_unaligned);
  109. if (!umac_reset_ctx->shmem_vaddr_unaligned) {
  110. dp_umac_reset_err("shmem allocation failed");
  111. return QDF_STATUS_E_NOMEM;
  112. }
  113. umac_reset_ctx->shmem_vaddr_aligned = (void *)(uintptr_t)qdf_roundup(
  114. (uint64_t)(uintptr_t)umac_reset_ctx->shmem_vaddr_unaligned,
  115. DP_UMAC_RESET_SHMEM_ALIGN);
  116. umac_reset_ctx->shmem_paddr_aligned = qdf_roundup(
  117. (uint64_t)umac_reset_ctx->shmem_paddr_unaligned,
  118. DP_UMAC_RESET_SHMEM_ALIGN);
  119. umac_reset_ctx->shmem_size = alloc_size;
  120. /* Write the magic number to the shared memory */
  121. umac_reset_ctx->shmem_vaddr_aligned->magic_num =
  122. DP_UMAC_RESET_SHMEM_MAGIC_NUM;
  123. /* Attach the interrupts */
  124. status = dp_umac_reset_interrupt_attach(soc);
  125. if (QDF_IS_STATUS_ERROR(status)) {
  126. dp_umac_reset_err("Interrupt attach failed");
  127. qdf_mem_free_consistent(soc->osdev, soc->osdev->dev,
  128. umac_reset_ctx->shmem_size,
  129. umac_reset_ctx->shmem_vaddr_unaligned,
  130. umac_reset_ctx->shmem_paddr_unaligned,
  131. 0);
  132. return status;
  133. }
  134. /* Send the setup cmd to the target */
  135. return dp_umac_reset_send_setup_cmd(soc);
  136. }
  137. QDF_STATUS dp_soc_umac_reset_deinit(struct cdp_soc_t *txrx_soc)
  138. {
  139. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  140. struct dp_soc_umac_reset_ctx *umac_reset_ctx;
  141. if (!soc) {
  142. dp_umac_reset_err("DP SOC is null");
  143. return QDF_STATUS_E_NULL_VALUE;
  144. }
  145. if (!soc->features.umac_hw_reset_support) {
  146. dp_umac_reset_info("Target doesn't support the UMAC HW reset feature");
  147. return QDF_STATUS_E_NOSUPPORT;
  148. }
  149. dp_umac_reset_interrupt_detach(soc);
  150. umac_reset_ctx = &soc->umac_reset_ctx;
  151. qdf_mem_free_consistent(soc->osdev, soc->osdev->dev,
  152. umac_reset_ctx->shmem_size,
  153. umac_reset_ctx->shmem_vaddr_unaligned,
  154. umac_reset_ctx->shmem_paddr_unaligned,
  155. 0);
  156. return QDF_STATUS_SUCCESS;
  157. }
  158. /**
  159. * dp_umac_reset_get_rx_event_from_shmem() - Extract the Rx event from the
  160. * shared memory
  161. * @umac_reset_ctx: UMAC reset context
  162. *
  163. * Return: Extracted Rx event in the form of enumeration umac_reset_rx_event
  164. */
  165. static enum umac_reset_rx_event
  166. dp_umac_reset_get_rx_event_from_shmem(
  167. struct dp_soc_umac_reset_ctx *umac_reset_ctx)
  168. {
  169. htt_umac_hang_recovery_msg_shmem_t *shmem_vaddr;
  170. uint32_t t2h_msg;
  171. uint8_t num_events = 0;
  172. enum umac_reset_rx_event rx_event;
  173. shmem_vaddr = umac_reset_ctx->shmem_vaddr_aligned;
  174. if (!shmem_vaddr) {
  175. dp_umac_reset_err("Shared memory address is NULL");
  176. goto err;
  177. }
  178. if (shmem_vaddr->magic_num != umac_reset_ctx->shmem_exp_magic_num) {
  179. dp_umac_reset_err("Shared memory got corrupted");
  180. goto err;
  181. }
  182. /* Read the shared memory into a local variable */
  183. t2h_msg = shmem_vaddr->t2h_msg;
  184. /* Clear the shared memory right away */
  185. shmem_vaddr->t2h_msg = 0;
  186. dp_umac_reset_debug("shmem value - t2h_msg: 0x%x", t2h_msg);
  187. rx_event = UMAC_RESET_RX_EVENT_NONE;
  188. if (HTT_UMAC_HANG_RECOVERY_MSG_SHMEM_DO_PRE_RESET_GET(t2h_msg)) {
  189. rx_event |= UMAC_RESET_RX_EVENT_DO_PRE_RESET;
  190. num_events++;
  191. }
  192. if (HTT_UMAC_HANG_RECOVERY_MSG_SHMEM_DO_POST_RESET_START_GET(t2h_msg)) {
  193. rx_event |= UMAC_RESET_RX_EVENT_DO_POST_RESET_START;
  194. num_events++;
  195. }
  196. if (HTT_UMAC_HANG_RECOVERY_MSG_SHMEM_DO_POST_RESET_COMPLETE_GET(t2h_msg)) {
  197. rx_event |= UMAC_RESET_RX_EVENT_DO_POST_RESET_COMPELTE;
  198. num_events++;
  199. }
  200. dp_umac_reset_debug("deduced rx event: 0x%x", rx_event);
  201. /* There should not be more than 1 event */
  202. if (num_events > 1) {
  203. dp_umac_reset_err("Multiple events(0x%x) got posted", rx_event);
  204. goto err;
  205. }
  206. return rx_event;
  207. err:
  208. qdf_assert_always(0);
  209. return UMAC_RESET_RX_EVENT_ERROR;
  210. }
  211. /**
  212. * dp_umac_reset_get_rx_event() - Extract the Rx event
  213. * @umac_reset_ctx: UMAC reset context
  214. *
  215. * Return: Extracted Rx event in the form of enumeration umac_reset_rx_event
  216. */
  217. static inline enum umac_reset_rx_event
  218. dp_umac_reset_get_rx_event(struct dp_soc_umac_reset_ctx *umac_reset_ctx)
  219. {
  220. return dp_umac_reset_get_rx_event_from_shmem(umac_reset_ctx);
  221. }
  222. /**
  223. * dp_umac_reset_validate_n_update_state_machine_on_rx() - Validate the state
  224. * machine for a given rx event and update the state machine
  225. * @umac_reset_ctx: UMAC reset context
  226. * @rx_event: Rx event
  227. * @current_exp_state: Expected state
  228. * @next_state: The state to which the state machine needs to be updated
  229. *
  230. * Return: QDF_STATUS of operation
  231. */
  232. static QDF_STATUS
  233. dp_umac_reset_validate_n_update_state_machine_on_rx(
  234. struct dp_soc_umac_reset_ctx *umac_reset_ctx,
  235. enum umac_reset_rx_event rx_event,
  236. enum umac_reset_state current_exp_state,
  237. enum umac_reset_state next_state)
  238. {
  239. if (umac_reset_ctx->current_state != current_exp_state) {
  240. dp_umac_reset_err("state machine validation failed on rx event: %d, current state is %d",
  241. rx_event,
  242. umac_reset_ctx->current_state);
  243. qdf_assert_always(0);
  244. return QDF_STATUS_E_FAILURE;
  245. }
  246. /* Update the state */
  247. umac_reset_ctx->current_state = next_state;
  248. return QDF_STATUS_SUCCESS;
  249. }
  250. /**
  251. * dp_umac_reset_rx_event_handler() - Main Rx event handler for UMAC reset
  252. * @dp_ctx: Interrupt context corresponding to UMAC reset
  253. *
  254. * Return: 0 incase of success, else failure
  255. */
  256. static int dp_umac_reset_rx_event_handler(void *dp_ctx)
  257. {
  258. struct dp_intr *int_ctx = (struct dp_intr *)dp_ctx;
  259. struct dp_soc *soc = int_ctx->soc;
  260. struct dp_soc_umac_reset_ctx *umac_reset_ctx;
  261. enum umac_reset_rx_event rx_event;
  262. QDF_STATUS status = QDF_STATUS_E_INVAL;
  263. enum umac_reset_action action;
  264. if (!soc) {
  265. dp_umac_reset_err("DP SOC is null");
  266. goto exit;
  267. }
  268. umac_reset_ctx = &soc->umac_reset_ctx;
  269. dp_umac_reset_debug("enter");
  270. rx_event = dp_umac_reset_get_rx_event(umac_reset_ctx);
  271. switch (rx_event) {
  272. case UMAC_RESET_RX_EVENT_NONE:
  273. /* This interrupt is not meant for us, so exit */
  274. dp_umac_reset_debug("Not a UMAC reset event");
  275. status = QDF_STATUS_SUCCESS;
  276. goto exit;
  277. case UMAC_RESET_RX_EVENT_DO_PRE_RESET:
  278. umac_reset_ctx->ts.pre_reset_start =
  279. qdf_get_log_timestamp_usecs();
  280. status = dp_umac_reset_validate_n_update_state_machine_on_rx(
  281. umac_reset_ctx, rx_event,
  282. UMAC_RESET_STATE_WAIT_FOR_DO_PRE_RESET,
  283. UMAC_RESET_STATE_DO_PRE_RESET_RECEIVED);
  284. action = UMAC_RESET_ACTION_DO_PRE_RESET;
  285. break;
  286. case UMAC_RESET_RX_EVENT_DO_POST_RESET_START:
  287. umac_reset_ctx->ts.post_reset_start =
  288. qdf_get_log_timestamp_usecs();
  289. status = dp_umac_reset_validate_n_update_state_machine_on_rx(
  290. umac_reset_ctx, rx_event,
  291. UMAC_RESET_STATE_WAIT_FOR_DO_POST_RESET_START,
  292. UMAC_RESET_STATE_DO_POST_RESET_START_RECEIVED);
  293. action = UMAC_RESET_ACTION_DO_POST_RESET_START;
  294. break;
  295. case UMAC_RESET_RX_EVENT_DO_POST_RESET_COMPELTE:
  296. umac_reset_ctx->ts.post_reset_complete_start =
  297. qdf_get_log_timestamp_usecs();
  298. status = dp_umac_reset_validate_n_update_state_machine_on_rx(
  299. umac_reset_ctx, rx_event,
  300. UMAC_RESET_STATE_WAIT_FOR_DO_POST_RESET_COMPLETE,
  301. UMAC_RESET_STATE_DO_POST_RESET_COMPLETE_RECEIVED);
  302. action = UMAC_RESET_ACTION_DO_POST_RESET_COMPLETE;
  303. break;
  304. case UMAC_RESET_RX_EVENT_ERROR:
  305. dp_umac_reset_err("Error Rx event");
  306. goto exit;
  307. default:
  308. dp_umac_reset_err("Invalid value(%u) for Rx event", rx_event);
  309. goto exit;
  310. }
  311. /* Call the handler for this event */
  312. if (QDF_IS_STATUS_SUCCESS(status)) {
  313. if (!umac_reset_ctx->rx_actions.cb[action]) {
  314. dp_umac_reset_err("rx callback is NULL");
  315. goto exit;
  316. }
  317. status = umac_reset_ctx->rx_actions.cb[action](soc);
  318. }
  319. exit:
  320. return qdf_status_to_os_return(status);
  321. }
  322. QDF_STATUS dp_umac_reset_interrupt_attach(struct dp_soc *soc)
  323. {
  324. struct dp_soc_umac_reset_ctx *umac_reset_ctx;
  325. int msi_vector_count, ret;
  326. uint32_t msi_base_data, msi_vector_start;
  327. uint32_t umac_reset_vector, umac_reset_irq;
  328. QDF_STATUS status;
  329. if (!soc) {
  330. dp_umac_reset_err("DP SOC is null");
  331. return QDF_STATUS_E_NULL_VALUE;
  332. }
  333. if (!soc->features.umac_hw_reset_support) {
  334. dp_umac_reset_info("Target doesn't support the UMAC HW reset feature");
  335. return QDF_STATUS_SUCCESS;
  336. }
  337. umac_reset_ctx = &soc->umac_reset_ctx;
  338. if (pld_get_enable_intx(soc->osdev->dev)) {
  339. dp_umac_reset_err("UMAC reset is not supported in legacy interrupt mode");
  340. return QDF_STATUS_E_FAILURE;
  341. }
  342. ret = pld_get_user_msi_assignment(soc->osdev->dev, "DP",
  343. &msi_vector_count, &msi_base_data,
  344. &msi_vector_start);
  345. if (ret) {
  346. /* UMAC reset uses IPC interrupt for AHB devices */
  347. status = hif_get_umac_reset_irq(soc->hif_handle,
  348. &umac_reset_irq);
  349. if (status) {
  350. dp_umac_reset_err("get_umac_reset_irq failed status %d",
  351. status);
  352. return QDF_STATUS_E_FAILURE;
  353. }
  354. } else {
  355. if (umac_reset_ctx->intr_offset < 0 ||
  356. umac_reset_ctx->intr_offset >= WLAN_CFG_INT_NUM_CONTEXTS) {
  357. dp_umac_reset_err("Invalid interrupt offset");
  358. return QDF_STATUS_E_FAILURE;
  359. }
  360. umac_reset_vector = msi_vector_start +
  361. (umac_reset_ctx->intr_offset % msi_vector_count);
  362. /* Get IRQ number */
  363. umac_reset_irq = pld_get_msi_irq(soc->osdev->dev,
  364. umac_reset_vector);
  365. }
  366. /* Finally register to this IRQ from HIF layer */
  367. return hif_register_umac_reset_handler(
  368. soc->hif_handle,
  369. dp_umac_reset_rx_event_handler,
  370. &soc->intr_ctx[umac_reset_ctx->intr_offset],
  371. umac_reset_irq);
  372. }
  373. QDF_STATUS dp_umac_reset_interrupt_detach(struct dp_soc *soc)
  374. {
  375. if (!soc) {
  376. dp_umac_reset_err("DP SOC is null");
  377. return QDF_STATUS_E_NULL_VALUE;
  378. }
  379. if (!soc->features.umac_hw_reset_support) {
  380. dp_umac_reset_info("Target doesn't support the UMAC HW reset feature");
  381. return QDF_STATUS_SUCCESS;
  382. }
  383. return hif_unregister_umac_reset_handler(soc->hif_handle);
  384. }
  385. QDF_STATUS dp_umac_reset_register_rx_action_callback(
  386. struct dp_soc *soc,
  387. QDF_STATUS (*handler)(struct dp_soc *soc),
  388. enum umac_reset_action action)
  389. {
  390. struct dp_soc_umac_reset_ctx *umac_reset_ctx;
  391. if (!soc) {
  392. dp_umac_reset_err("DP SOC is null");
  393. return QDF_STATUS_E_NULL_VALUE;
  394. }
  395. if (!soc->features.umac_hw_reset_support) {
  396. dp_umac_reset_info("Target doesn't support the UMAC HW reset feature");
  397. return QDF_STATUS_E_NOSUPPORT;
  398. }
  399. if (action >= UMAC_RESET_ACTION_MAX) {
  400. dp_umac_reset_err("invalid action: %d", action);
  401. return QDF_STATUS_E_INVAL;
  402. }
  403. umac_reset_ctx = &soc->umac_reset_ctx;
  404. umac_reset_ctx->rx_actions.cb[action] = handler;
  405. return QDF_STATUS_SUCCESS;
  406. }
  407. /**
  408. * dp_umac_reset_post_tx_cmd_via_shmem() - Post Tx command using shared memory
  409. * @umac_reset_ctx: UMAC reset context
  410. * @tx_cmd: Tx command to be posted
  411. *
  412. * Return: QDF status of operation
  413. */
  414. static QDF_STATUS
  415. dp_umac_reset_post_tx_cmd_via_shmem(
  416. struct dp_soc_umac_reset_ctx *umac_reset_ctx,
  417. enum umac_reset_tx_cmd tx_cmd)
  418. {
  419. htt_umac_hang_recovery_msg_shmem_t *shmem_vaddr;
  420. shmem_vaddr = umac_reset_ctx->shmem_vaddr_aligned;
  421. if (!shmem_vaddr) {
  422. dp_umac_reset_err("Shared memory address is NULL");
  423. return QDF_STATUS_E_NULL_VALUE;
  424. }
  425. switch (tx_cmd) {
  426. case UMAC_RESET_TX_CMD_PRE_RESET_DONE:
  427. HTT_UMAC_HANG_RECOVERY_MSG_SHMEM_PRE_RESET_DONE_SET(
  428. shmem_vaddr->h2t_msg, 1);
  429. umac_reset_ctx->ts.pre_reset_done =
  430. qdf_get_log_timestamp_usecs();
  431. break;
  432. case UMAC_RESET_TX_CMD_POST_RESET_START_DONE:
  433. HTT_UMAC_HANG_RECOVERY_MSG_SHMEM_POST_RESET_START_DONE_SET(
  434. shmem_vaddr->h2t_msg, 1);
  435. umac_reset_ctx->ts.post_reset_done =
  436. qdf_get_log_timestamp_usecs();
  437. break;
  438. case UMAC_RESET_TX_CMD_POST_RESET_COMPLETE_DONE:
  439. HTT_UMAC_HANG_RECOVERY_MSG_SHMEM_POST_RESET_COMPLETE_DONE_SET(
  440. shmem_vaddr->h2t_msg, 1);
  441. umac_reset_ctx->ts.post_reset_complete_done =
  442. qdf_get_log_timestamp_usecs();
  443. break;
  444. default:
  445. dp_umac_reset_err("Invalid tx cmd: %d", tx_cmd);
  446. return QDF_STATUS_E_FAILURE;
  447. }
  448. return QDF_STATUS_SUCCESS;
  449. }
  450. /**
  451. * dp_umac_reset_notify_target() - Notify the target about completion of action.
  452. * @umac_reset_ctx: UMAC reset context
  453. *
  454. * This API figures out the Tx command that needs to be posted based on the
  455. * current state in the state machine. Also, updates the state machine once the
  456. * Tx command has been posted.
  457. *
  458. * Return: QDF status of operation
  459. */
  460. static QDF_STATUS
  461. dp_umac_reset_notify_target(struct dp_soc_umac_reset_ctx *umac_reset_ctx)
  462. {
  463. enum umac_reset_state next_state;
  464. enum umac_reset_tx_cmd tx_cmd;
  465. QDF_STATUS status;
  466. switch (umac_reset_ctx->current_state) {
  467. case UMAC_RESET_STATE_HOST_PRE_RESET_DONE:
  468. tx_cmd = UMAC_RESET_TX_CMD_PRE_RESET_DONE;
  469. next_state = UMAC_RESET_STATE_WAIT_FOR_DO_POST_RESET_START;
  470. break;
  471. case UMAC_RESET_STATE_HOST_POST_RESET_START_DONE:
  472. tx_cmd = UMAC_RESET_TX_CMD_POST_RESET_START_DONE;
  473. next_state = UMAC_RESET_STATE_WAIT_FOR_DO_POST_RESET_COMPLETE;
  474. break;
  475. case UMAC_RESET_STATE_HOST_POST_RESET_COMPLETE_DONE:
  476. tx_cmd = UMAC_RESET_TX_CMD_POST_RESET_COMPLETE_DONE;
  477. next_state = UMAC_RESET_STATE_WAIT_FOR_DO_PRE_RESET;
  478. break;
  479. default:
  480. dp_umac_reset_err("Invalid state(%d) during Tx",
  481. umac_reset_ctx->current_state);
  482. qdf_assert_always(0);
  483. return QDF_STATUS_E_FAILURE;
  484. }
  485. status = dp_umac_reset_post_tx_cmd_via_shmem(umac_reset_ctx, tx_cmd);
  486. if (QDF_IS_STATUS_ERROR(status)) {
  487. dp_umac_reset_err("Couldn't post Tx cmd");
  488. qdf_assert_always(0);
  489. return status;
  490. }
  491. /* Update the state machine */
  492. umac_reset_ctx->current_state = next_state;
  493. return status;
  494. }
  495. /**
  496. * dp_umac_reset_notify_completion() - Notify that a given action has been
  497. * completed
  498. * @soc: DP soc object
  499. * @next_state: The state to which the state machine needs to be updated due to
  500. * this completion
  501. *
  502. * Return: QDF status of operation
  503. */
  504. static QDF_STATUS dp_umac_reset_notify_completion(
  505. struct dp_soc *soc,
  506. enum umac_reset_state next_state)
  507. {
  508. struct dp_soc_umac_reset_ctx *umac_reset_ctx;
  509. if (!soc) {
  510. dp_umac_reset_err("DP SOC is null");
  511. return QDF_STATUS_E_NULL_VALUE;
  512. }
  513. umac_reset_ctx = &soc->umac_reset_ctx;
  514. /* Update the state first */
  515. umac_reset_ctx->current_state = next_state;
  516. return dp_umac_reset_notify_target(umac_reset_ctx);
  517. }
  518. QDF_STATUS dp_umac_reset_notify_action_completion(
  519. struct dp_soc *soc,
  520. enum umac_reset_action action)
  521. {
  522. enum umac_reset_state next_state;
  523. if (!soc) {
  524. dp_umac_reset_err("DP SOC is null");
  525. return QDF_STATUS_E_NULL_VALUE;
  526. }
  527. if (!soc->features.umac_hw_reset_support) {
  528. dp_umac_reset_info("Target doesn't support the UMAC HW reset feature");
  529. return QDF_STATUS_E_NOSUPPORT;
  530. }
  531. switch (action) {
  532. case UMAC_RESET_ACTION_DO_PRE_RESET:
  533. next_state = UMAC_RESET_STATE_HOST_PRE_RESET_DONE;
  534. break;
  535. case UMAC_RESET_ACTION_DO_POST_RESET_START:
  536. next_state = UMAC_RESET_STATE_HOST_POST_RESET_START_DONE;
  537. break;
  538. case UMAC_RESET_ACTION_DO_POST_RESET_COMPLETE:
  539. next_state = UMAC_RESET_STATE_HOST_POST_RESET_COMPLETE_DONE;
  540. break;
  541. default:
  542. dp_umac_reset_err("Invalid action");
  543. return QDF_STATUS_E_FAILURE;
  544. }
  545. return dp_umac_reset_notify_completion(soc, next_state);
  546. }