dp_umac_reset.c 18 KB

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