dp_umac_reset.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039
  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_internal.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 cdp_soc_t *txrx_soc)
  77. {
  78. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  79. struct dp_soc_umac_reset_ctx *umac_reset_ctx;
  80. size_t alloc_size;
  81. QDF_STATUS status;
  82. if (!soc) {
  83. dp_umac_reset_err("DP SOC is null");
  84. return QDF_STATUS_E_NULL_VALUE;
  85. }
  86. if (!soc->features.umac_hw_reset_support) {
  87. dp_umac_reset_info("Target doesn't support the UMAC HW reset feature");
  88. return QDF_STATUS_E_NOSUPPORT;
  89. }
  90. umac_reset_ctx = &soc->umac_reset_ctx;
  91. qdf_mem_zero(umac_reset_ctx, sizeof(*umac_reset_ctx));
  92. umac_reset_ctx->current_state = UMAC_RESET_STATE_WAIT_FOR_TRIGGER;
  93. umac_reset_ctx->shmem_exp_magic_num = DP_UMAC_RESET_SHMEM_MAGIC_NUM;
  94. status = dp_get_umac_reset_intr_ctx(soc, &umac_reset_ctx->intr_offset);
  95. if (QDF_IS_STATUS_ERROR(status)) {
  96. dp_umac_reset_err("No interrupt assignment");
  97. return status;
  98. }
  99. alloc_size = sizeof(htt_umac_hang_recovery_msg_shmem_t) +
  100. DP_UMAC_RESET_SHMEM_ALIGN - 1;
  101. umac_reset_ctx->shmem_vaddr_unaligned =
  102. qdf_mem_alloc_consistent(soc->osdev, soc->osdev->dev,
  103. alloc_size,
  104. &umac_reset_ctx->shmem_paddr_unaligned);
  105. if (!umac_reset_ctx->shmem_vaddr_unaligned) {
  106. dp_umac_reset_err("shmem allocation failed");
  107. return QDF_STATUS_E_NOMEM;
  108. }
  109. umac_reset_ctx->shmem_vaddr_aligned = (void *)(uintptr_t)qdf_roundup(
  110. (uint64_t)(uintptr_t)umac_reset_ctx->shmem_vaddr_unaligned,
  111. DP_UMAC_RESET_SHMEM_ALIGN);
  112. umac_reset_ctx->shmem_paddr_aligned = qdf_roundup(
  113. (uint64_t)umac_reset_ctx->shmem_paddr_unaligned,
  114. DP_UMAC_RESET_SHMEM_ALIGN);
  115. umac_reset_ctx->shmem_size = alloc_size;
  116. /* Write the magic number to the shared memory */
  117. umac_reset_ctx->shmem_vaddr_aligned->magic_num =
  118. DP_UMAC_RESET_SHMEM_MAGIC_NUM;
  119. /* Attach the interrupts */
  120. status = dp_umac_reset_interrupt_attach(soc);
  121. if (QDF_IS_STATUS_ERROR(status)) {
  122. dp_umac_reset_err("Interrupt attach failed");
  123. qdf_mem_free_consistent(soc->osdev, soc->osdev->dev,
  124. umac_reset_ctx->shmem_size,
  125. umac_reset_ctx->shmem_vaddr_unaligned,
  126. umac_reset_ctx->shmem_paddr_unaligned,
  127. 0);
  128. return status;
  129. }
  130. /* Send the setup cmd to the target */
  131. return dp_umac_reset_send_setup_cmd(soc);
  132. }
  133. /**
  134. * dp_umac_reset_get_rx_event_from_shmem() - Extract the Rx event from the
  135. * shared memory
  136. * @umac_reset_ctx: UMAC reset context
  137. *
  138. * Return: Extracted Rx event in the form of enumeration umac_reset_rx_event
  139. */
  140. static enum umac_reset_rx_event
  141. dp_umac_reset_get_rx_event_from_shmem(
  142. struct dp_soc_umac_reset_ctx *umac_reset_ctx)
  143. {
  144. htt_umac_hang_recovery_msg_shmem_t *shmem_vaddr;
  145. uint32_t t2h_msg;
  146. uint8_t num_events = 0;
  147. enum umac_reset_rx_event rx_event;
  148. shmem_vaddr = umac_reset_ctx->shmem_vaddr_aligned;
  149. if (!shmem_vaddr) {
  150. dp_umac_reset_err("Shared memory address is NULL");
  151. goto err;
  152. }
  153. if (shmem_vaddr->magic_num != umac_reset_ctx->shmem_exp_magic_num) {
  154. dp_umac_reset_err("Shared memory got corrupted");
  155. goto err;
  156. }
  157. /* Read the shared memory into a local variable */
  158. t2h_msg = shmem_vaddr->t2h_msg;
  159. /* Clear the shared memory right away */
  160. shmem_vaddr->t2h_msg = 0;
  161. dp_umac_reset_debug("shmem value - t2h_msg: 0x%x", t2h_msg);
  162. rx_event = UMAC_RESET_RX_EVENT_NONE;
  163. if (HTT_UMAC_HANG_RECOVERY_MSG_SHMEM_INITIATE_UMAC_RECOVERY_GET(t2h_msg)) {
  164. rx_event |= UMAC_RESET_RX_EVENT_DO_TRIGGER_RECOVERY;
  165. num_events++;
  166. }
  167. if (HTT_UMAC_HANG_RECOVERY_MSG_SHMEM_INITIATE_TARGET_RECOVERY_SYNC_USING_UMAC_GET(t2h_msg)) {
  168. rx_event |= UMAC_RESET_RX_EVENT_DO_TRIGGER_TR_SYNC;
  169. num_events++;
  170. }
  171. if (HTT_UMAC_HANG_RECOVERY_MSG_SHMEM_DO_PRE_RESET_GET(t2h_msg)) {
  172. rx_event |= UMAC_RESET_RX_EVENT_DO_PRE_RESET;
  173. num_events++;
  174. }
  175. if (HTT_UMAC_HANG_RECOVERY_MSG_SHMEM_DO_POST_RESET_START_GET(t2h_msg)) {
  176. rx_event |= UMAC_RESET_RX_EVENT_DO_POST_RESET_START;
  177. num_events++;
  178. }
  179. if (HTT_UMAC_HANG_RECOVERY_MSG_SHMEM_DO_POST_RESET_COMPLETE_GET(t2h_msg)) {
  180. rx_event |= UMAC_RESET_RX_EVENT_DO_POST_RESET_COMPELTE;
  181. num_events++;
  182. }
  183. dp_umac_reset_debug("deduced rx event: 0x%x", rx_event);
  184. /* There should not be more than 1 event */
  185. if (num_events > 1) {
  186. dp_umac_reset_err("Multiple events(0x%x) got posted", rx_event);
  187. goto err;
  188. }
  189. return rx_event;
  190. err:
  191. qdf_assert_always(0);
  192. return UMAC_RESET_RX_EVENT_ERROR;
  193. }
  194. /**
  195. * dp_umac_reset_peek_rx_event_from_shmem() - Peek the Rx event from the
  196. * shared memory without clearing the bit
  197. * @umac_reset_ctx: UMAC reset context
  198. *
  199. * Return: true if the shared memory has any valid bits set
  200. */
  201. static inline bool dp_umac_reset_peek_rx_event_from_shmem(
  202. struct dp_soc_umac_reset_ctx *umac_reset_ctx)
  203. {
  204. htt_umac_hang_recovery_msg_shmem_t *shmem_vaddr;
  205. shmem_vaddr = umac_reset_ctx->shmem_vaddr_aligned;
  206. if (!shmem_vaddr) {
  207. dp_umac_reset_debug("Shared memory address is NULL");
  208. goto err;
  209. }
  210. if (shmem_vaddr->magic_num != umac_reset_ctx->shmem_exp_magic_num) {
  211. dp_umac_reset_debug("Shared memory got corrupted");
  212. goto err;
  213. }
  214. /* Read the shared memory into a local variable */
  215. return !!shmem_vaddr->t2h_msg;
  216. err:
  217. return false;
  218. }
  219. /**
  220. * dp_umac_reset_get_rx_event() - Extract the Rx event
  221. * @umac_reset_ctx: UMAC reset context
  222. *
  223. * Return: Extracted Rx event in the form of enumeration umac_reset_rx_event
  224. */
  225. static inline enum umac_reset_rx_event
  226. dp_umac_reset_get_rx_event(struct dp_soc_umac_reset_ctx *umac_reset_ctx)
  227. {
  228. return dp_umac_reset_get_rx_event_from_shmem(umac_reset_ctx);
  229. }
  230. /**
  231. * dp_umac_reset_validate_n_update_state_machine_on_rx() - Validate the state
  232. * machine for a given rx event and update the state machine
  233. * @umac_reset_ctx: UMAC reset context
  234. * @rx_event: Rx event
  235. * @current_exp_state: Expected state
  236. * @next_state: The state to which the state machine needs to be updated
  237. *
  238. * Return: QDF_STATUS of operation
  239. */
  240. QDF_STATUS
  241. dp_umac_reset_validate_n_update_state_machine_on_rx(
  242. struct dp_soc_umac_reset_ctx *umac_reset_ctx,
  243. enum umac_reset_rx_event rx_event,
  244. enum umac_reset_state current_exp_state,
  245. enum umac_reset_state next_state)
  246. {
  247. if (umac_reset_ctx->current_state != current_exp_state) {
  248. dp_umac_reset_err("state machine validation failed on rx event: %d, current state is %d",
  249. rx_event,
  250. umac_reset_ctx->current_state);
  251. if ((rx_event != UMAC_RESET_RX_EVENT_DO_TRIGGER_RECOVERY) &&
  252. (rx_event != UMAC_RESET_RX_EVENT_DO_TRIGGER_TR_SYNC))
  253. qdf_assert_always(0);
  254. return QDF_STATUS_E_FAILURE;
  255. }
  256. /* Update the state */
  257. umac_reset_ctx->current_state = next_state;
  258. return QDF_STATUS_SUCCESS;
  259. }
  260. static bool dp_umac_reset_peek_rx_event(void *dp_ctx)
  261. {
  262. struct dp_intr *int_ctx = (struct dp_intr *)dp_ctx;
  263. struct dp_soc *soc = int_ctx->soc;
  264. struct dp_soc_umac_reset_ctx *umac_reset_ctx = &soc->umac_reset_ctx;
  265. return dp_umac_reset_peek_rx_event_from_shmem(umac_reset_ctx);
  266. }
  267. /**
  268. * dp_check_umac_reset_in_progress() - Check if Umac reset is in progress
  269. * @soc: dp soc handle
  270. *
  271. * Return: true if Umac reset is in progress or false otherwise
  272. */
  273. bool dp_check_umac_reset_in_progress(struct dp_soc *soc)
  274. {
  275. return !!soc->umac_reset_ctx.intr_ctx_bkp;
  276. }
  277. #if !defined(QCA_SUPPORT_DP_GLOBAL_CTX) || \
  278. (defined(QCA_SUPPORT_DP_GLOBAL_CTX) && \
  279. !defined(WLAN_FEATURE_11BE_MLO) || !defined(WLAN_MLO_MULTI_CHIP))
  280. bool dp_get_global_tx_desc_cleanup_flag(struct dp_soc *soc)
  281. {
  282. return true;
  283. }
  284. void dp_reset_global_tx_desc_cleanup_flag(struct dp_soc *soc)
  285. {
  286. }
  287. #endif
  288. #if !defined(WLAN_FEATURE_11BE_MLO) || !defined(WLAN_MLO_MULTI_CHIP)
  289. /**
  290. * dp_umac_reset_initiate_umac_recovery() - Initiate Umac reset session
  291. * @soc: dp soc handle
  292. * @umac_reset_ctx: Umac reset context
  293. * @rx_event: Rx event received
  294. * @is_target_recovery: Flag to indicate if it is triggered for target recovery
  295. *
  296. * Return: status
  297. */
  298. static QDF_STATUS dp_umac_reset_initiate_umac_recovery(struct dp_soc *soc,
  299. struct dp_soc_umac_reset_ctx *umac_reset_ctx,
  300. enum umac_reset_rx_event rx_event,
  301. bool is_target_recovery)
  302. {
  303. return dp_umac_reset_validate_n_update_state_machine_on_rx(
  304. umac_reset_ctx, rx_event,
  305. UMAC_RESET_STATE_WAIT_FOR_TRIGGER,
  306. UMAC_RESET_STATE_DO_TRIGGER_RECEIVED);
  307. }
  308. /**
  309. * dp_umac_reset_complete_umac_recovery() - Complete Umac reset session
  310. * @soc: dp soc handle
  311. *
  312. * Return: void
  313. */
  314. static void dp_umac_reset_complete_umac_recovery(struct dp_soc *soc)
  315. {
  316. dp_umac_reset_alert("Umac reset was handled successfully on soc %pK",
  317. soc);
  318. }
  319. /**
  320. * dp_umac_reset_handle_action_cb() - Function to call action callback
  321. * @soc: dp soc handle
  322. * @umac_reset_ctx: Umac reset context
  323. * @action: Action to call the callback for
  324. *
  325. * Return: QDF_STATUS status
  326. */
  327. static QDF_STATUS dp_umac_reset_handle_action_cb(struct dp_soc *soc,
  328. struct dp_soc_umac_reset_ctx *umac_reset_ctx,
  329. enum umac_reset_action action)
  330. {
  331. QDF_STATUS status = QDF_STATUS_SUCCESS;
  332. if (!umac_reset_ctx->rx_actions.cb[action]) {
  333. dp_umac_reset_err("rx callback is NULL");
  334. return QDF_STATUS_E_FAILURE;
  335. }
  336. status = umac_reset_ctx->rx_actions.cb[action](soc);
  337. return QDF_STATUS_SUCCESS;
  338. }
  339. /**
  340. * dp_umac_reset_post_tx_cmd() - Iterate partner socs and post Tx command
  341. * @umac_reset_ctx: UMAC reset context
  342. * @tx_cmd: Tx command to be posted
  343. *
  344. * Return: QDF status of operation
  345. */
  346. static QDF_STATUS
  347. dp_umac_reset_post_tx_cmd(struct dp_soc_umac_reset_ctx *umac_reset_ctx,
  348. enum umac_reset_tx_cmd tx_cmd)
  349. {
  350. struct dp_soc *soc = container_of(umac_reset_ctx, struct dp_soc,
  351. umac_reset_ctx);
  352. dp_umac_reset_post_tx_cmd_via_shmem(soc, &tx_cmd, 0);
  353. return QDF_STATUS_SUCCESS;
  354. }
  355. /**
  356. * dp_umac_reset_initiator_check() - Check if soc is the Umac reset initiator
  357. * @soc: dp soc handle
  358. *
  359. * Return: true if the soc is initiator or false otherwise
  360. */
  361. static bool dp_umac_reset_initiator_check(struct dp_soc *soc)
  362. {
  363. return true;
  364. }
  365. /**
  366. * dp_umac_reset_target_recovery_check() - Check if this is for target recovery
  367. * @soc: dp soc handle
  368. *
  369. * Return: true if the session is for target recovery or false otherwise
  370. */
  371. static bool dp_umac_reset_target_recovery_check(struct dp_soc *soc)
  372. {
  373. return false;
  374. }
  375. /**
  376. * dp_umac_reset_is_soc_ignored() - Check if this soc is to be ignored
  377. * @soc: dp soc handle
  378. *
  379. * Return: true if the soc is ignored or false otherwise
  380. */
  381. static bool dp_umac_reset_is_soc_ignored(struct dp_soc *soc)
  382. {
  383. return false;
  384. }
  385. #endif
  386. /**
  387. * dp_umac_reset_rx_event_handler() - Main Rx event handler for UMAC reset
  388. * @dp_ctx: Interrupt context corresponding to UMAC reset
  389. *
  390. * Return: 0 incase of success, else failure
  391. */
  392. static int dp_umac_reset_rx_event_handler(void *dp_ctx)
  393. {
  394. struct dp_intr *int_ctx = (struct dp_intr *)dp_ctx;
  395. struct dp_soc *soc = int_ctx->soc;
  396. struct dp_soc_umac_reset_ctx *umac_reset_ctx;
  397. enum umac_reset_rx_event rx_event;
  398. QDF_STATUS status = QDF_STATUS_E_INVAL;
  399. enum umac_reset_action action = UMAC_RESET_ACTION_NONE;
  400. bool target_recovery = false;
  401. if (!soc) {
  402. dp_umac_reset_err("DP SOC is null");
  403. goto exit;
  404. }
  405. umac_reset_ctx = &soc->umac_reset_ctx;
  406. dp_umac_reset_debug("enter");
  407. rx_event = dp_umac_reset_get_rx_event(umac_reset_ctx);
  408. if (umac_reset_ctx->pending_action) {
  409. if (rx_event != UMAC_RESET_RX_EVENT_NONE) {
  410. dp_umac_reset_err("Invalid value(%u) for Rx event when "
  411. "action %u is pending\n", rx_event,
  412. umac_reset_ctx->pending_action);
  413. qdf_assert_always(0);
  414. }
  415. }
  416. switch (rx_event) {
  417. case UMAC_RESET_RX_EVENT_NONE:
  418. if (umac_reset_ctx->pending_action)
  419. action = umac_reset_ctx->pending_action;
  420. else
  421. dp_umac_reset_err("Not a UMAC reset event!!");
  422. status = QDF_STATUS_SUCCESS;
  423. break;
  424. case UMAC_RESET_RX_EVENT_DO_TRIGGER_TR_SYNC:
  425. target_recovery = true;
  426. /* Fall through */
  427. case UMAC_RESET_RX_EVENT_DO_TRIGGER_RECOVERY:
  428. status =
  429. dp_umac_reset_initiate_umac_recovery(soc, umac_reset_ctx,
  430. rx_event, target_recovery);
  431. if (status != QDF_STATUS_SUCCESS)
  432. break;
  433. umac_reset_ctx->ts.trigger_start =
  434. qdf_get_log_timestamp_usecs();
  435. action = UMAC_RESET_ACTION_DO_TRIGGER_RECOVERY;
  436. break;
  437. case UMAC_RESET_RX_EVENT_DO_PRE_RESET:
  438. status = dp_umac_reset_validate_n_update_state_machine_on_rx(
  439. umac_reset_ctx, rx_event,
  440. UMAC_RESET_STATE_WAIT_FOR_DO_PRE_RESET,
  441. UMAC_RESET_STATE_DO_PRE_RESET_RECEIVED);
  442. umac_reset_ctx->ts.pre_reset_start =
  443. qdf_get_log_timestamp_usecs();
  444. action = UMAC_RESET_ACTION_DO_PRE_RESET;
  445. break;
  446. case UMAC_RESET_RX_EVENT_DO_POST_RESET_START:
  447. status = dp_umac_reset_validate_n_update_state_machine_on_rx(
  448. umac_reset_ctx, rx_event,
  449. UMAC_RESET_STATE_WAIT_FOR_DO_POST_RESET_START,
  450. UMAC_RESET_STATE_DO_POST_RESET_START_RECEIVED);
  451. umac_reset_ctx->ts.post_reset_start =
  452. qdf_get_log_timestamp_usecs();
  453. action = UMAC_RESET_ACTION_DO_POST_RESET_START;
  454. break;
  455. case UMAC_RESET_RX_EVENT_DO_POST_RESET_COMPELTE:
  456. status = dp_umac_reset_validate_n_update_state_machine_on_rx(
  457. umac_reset_ctx, rx_event,
  458. UMAC_RESET_STATE_WAIT_FOR_DO_POST_RESET_COMPLETE,
  459. UMAC_RESET_STATE_DO_POST_RESET_COMPLETE_RECEIVED);
  460. umac_reset_ctx->ts.post_reset_complete_start =
  461. qdf_get_log_timestamp_usecs();
  462. action = UMAC_RESET_ACTION_DO_POST_RESET_COMPLETE;
  463. break;
  464. case UMAC_RESET_RX_EVENT_ERROR:
  465. dp_umac_reset_err("Error Rx event");
  466. goto exit;
  467. default:
  468. dp_umac_reset_err("Invalid value(%u) for Rx event", rx_event);
  469. goto exit;
  470. }
  471. /* Call the handler for this event */
  472. if (QDF_IS_STATUS_SUCCESS(status)) {
  473. dp_umac_reset_handle_action_cb(soc, umac_reset_ctx, action);
  474. }
  475. exit:
  476. return qdf_status_to_os_return(status);
  477. }
  478. QDF_STATUS dp_umac_reset_interrupt_attach(struct dp_soc *soc)
  479. {
  480. struct dp_soc_umac_reset_ctx *umac_reset_ctx;
  481. int msi_vector_count, ret;
  482. uint32_t msi_base_data, msi_vector_start;
  483. uint32_t umac_reset_vector, umac_reset_irq;
  484. QDF_STATUS status;
  485. if (!soc) {
  486. dp_umac_reset_err("DP SOC is null");
  487. return QDF_STATUS_E_NULL_VALUE;
  488. }
  489. if (!soc->features.umac_hw_reset_support) {
  490. dp_umac_reset_info("Target doesn't support the UMAC HW reset feature");
  491. return QDF_STATUS_SUCCESS;
  492. }
  493. umac_reset_ctx = &soc->umac_reset_ctx;
  494. if (pld_get_enable_intx(soc->osdev->dev)) {
  495. dp_umac_reset_err("UMAC reset is not supported in legacy interrupt mode");
  496. return QDF_STATUS_E_FAILURE;
  497. }
  498. ret = pld_get_user_msi_assignment(soc->osdev->dev, "DP",
  499. &msi_vector_count, &msi_base_data,
  500. &msi_vector_start);
  501. if (ret) {
  502. /* UMAC reset uses IPC interrupt for AHB devices */
  503. status = hif_get_umac_reset_irq(soc->hif_handle,
  504. &umac_reset_irq);
  505. if (status) {
  506. dp_umac_reset_err("get_umac_reset_irq failed status %d",
  507. status);
  508. return QDF_STATUS_E_FAILURE;
  509. }
  510. } else {
  511. if (umac_reset_ctx->intr_offset < 0 ||
  512. umac_reset_ctx->intr_offset >= WLAN_CFG_INT_NUM_CONTEXTS) {
  513. dp_umac_reset_err("Invalid interrupt offset: %d",
  514. umac_reset_ctx->intr_offset);
  515. return QDF_STATUS_E_FAILURE;
  516. }
  517. umac_reset_vector = msi_vector_start +
  518. (umac_reset_ctx->intr_offset % msi_vector_count);
  519. /* Get IRQ number */
  520. umac_reset_irq = pld_get_msi_irq(soc->osdev->dev,
  521. umac_reset_vector);
  522. }
  523. /* Finally register to this IRQ from HIF layer */
  524. return hif_register_umac_reset_handler(
  525. soc->hif_handle,
  526. dp_umac_reset_peek_rx_event,
  527. dp_umac_reset_rx_event_handler,
  528. &soc->intr_ctx[umac_reset_ctx->intr_offset],
  529. umac_reset_irq);
  530. }
  531. QDF_STATUS dp_umac_reset_interrupt_detach(struct dp_soc *soc)
  532. {
  533. if (!soc) {
  534. dp_umac_reset_err("DP SOC is null");
  535. return QDF_STATUS_E_NULL_VALUE;
  536. }
  537. if (!soc->features.umac_hw_reset_support) {
  538. dp_umac_reset_info("Target doesn't support the UMAC HW reset feature");
  539. return QDF_STATUS_SUCCESS;
  540. }
  541. return hif_unregister_umac_reset_handler(soc->hif_handle);
  542. }
  543. QDF_STATUS dp_umac_reset_register_rx_action_callback(
  544. struct dp_soc *soc,
  545. QDF_STATUS (*handler)(struct dp_soc *soc),
  546. enum umac_reset_action action)
  547. {
  548. struct dp_soc_umac_reset_ctx *umac_reset_ctx;
  549. if (!soc) {
  550. dp_umac_reset_err("DP SOC is null");
  551. return QDF_STATUS_E_NULL_VALUE;
  552. }
  553. if (!soc->features.umac_hw_reset_support) {
  554. dp_umac_reset_info("Target doesn't support UMAC HW reset");
  555. return QDF_STATUS_E_NOSUPPORT;
  556. }
  557. if (action >= UMAC_RESET_ACTION_MAX) {
  558. dp_umac_reset_err("invalid action: %d", action);
  559. return QDF_STATUS_E_INVAL;
  560. }
  561. umac_reset_ctx = &soc->umac_reset_ctx;
  562. umac_reset_ctx->rx_actions.cb[action] = handler;
  563. return QDF_STATUS_SUCCESS;
  564. }
  565. /**
  566. * dp_umac_reset_post_tx_cmd_via_shmem() - Post Tx command using shared memory
  567. * @soc: DP soc object
  568. * @ctxt: Tx command to be posted
  569. * @chip_id: Chip id of the mlo soc
  570. *
  571. * Return: None
  572. */
  573. void
  574. dp_umac_reset_post_tx_cmd_via_shmem(struct dp_soc *soc, void *ctxt, int chip_id)
  575. {
  576. enum umac_reset_tx_cmd tx_cmd = *((enum umac_reset_tx_cmd *)ctxt);
  577. htt_umac_hang_recovery_msg_shmem_t *shmem_vaddr;
  578. struct dp_soc_umac_reset_ctx *umac_reset_ctx = &soc->umac_reset_ctx;
  579. bool initiator;
  580. QDF_STATUS status;
  581. if (dp_umac_reset_is_soc_ignored(soc)) {
  582. dp_umac_reset_debug("Skipping soc (chip id %d)", chip_id);
  583. return;
  584. }
  585. shmem_vaddr = umac_reset_ctx->shmem_vaddr_aligned;
  586. if (!shmem_vaddr) {
  587. dp_umac_reset_err("Shared memory address is NULL");
  588. return;
  589. }
  590. dp_umac_reset_debug("Sending txcmd %u for chip id %u", tx_cmd, chip_id);
  591. switch (tx_cmd) {
  592. case UMAC_RESET_TX_CMD_TRIGGER_DONE:
  593. /* Send htt message to the partner soc */
  594. initiator = dp_umac_reset_initiator_check(soc);
  595. if (!initiator)
  596. umac_reset_ctx->current_state =
  597. UMAC_RESET_STATE_WAIT_FOR_DO_PRE_RESET;
  598. status = dp_htt_umac_reset_send_start_pre_reset_cmd(soc,
  599. initiator,
  600. !dp_umac_reset_target_recovery_check(soc));
  601. if (status != QDF_STATUS_SUCCESS) {
  602. dp_umac_reset_err("Unable to send Umac trigger");
  603. qdf_assert_always(0);
  604. } else {
  605. dp_umac_reset_debug("Sent trigger for soc (chip_id %d)",
  606. chip_id);
  607. }
  608. umac_reset_ctx->ts.trigger_done = qdf_get_log_timestamp_usecs();
  609. break;
  610. case UMAC_RESET_TX_CMD_PRE_RESET_DONE:
  611. HTT_UMAC_HANG_RECOVERY_MSG_SHMEM_PRE_RESET_DONE_SET(
  612. shmem_vaddr->h2t_msg, 1);
  613. umac_reset_ctx->ts.pre_reset_done =
  614. qdf_get_log_timestamp_usecs();
  615. break;
  616. case UMAC_RESET_TX_CMD_POST_RESET_START_DONE:
  617. HTT_UMAC_HANG_RECOVERY_MSG_SHMEM_POST_RESET_START_DONE_SET(
  618. shmem_vaddr->h2t_msg, 1);
  619. umac_reset_ctx->ts.post_reset_done =
  620. qdf_get_log_timestamp_usecs();
  621. break;
  622. case UMAC_RESET_TX_CMD_POST_RESET_COMPLETE_DONE:
  623. HTT_UMAC_HANG_RECOVERY_MSG_SHMEM_POST_RESET_COMPLETE_DONE_SET(
  624. shmem_vaddr->h2t_msg, 1);
  625. umac_reset_ctx->ts.post_reset_complete_done =
  626. qdf_get_log_timestamp_usecs();
  627. break;
  628. default:
  629. dp_umac_reset_err("Invalid tx cmd: %d", tx_cmd);
  630. return;
  631. }
  632. return;
  633. }
  634. /**
  635. * dp_umac_reset_notify_target() - Notify the target about completion of action.
  636. * @umac_reset_ctx: UMAC reset context
  637. *
  638. * This API figures out the Tx command that needs to be posted based on the
  639. * current state in the state machine. Also, updates the state machine once the
  640. * Tx command has been posted.
  641. *
  642. * Return: QDF status of operation
  643. */
  644. static QDF_STATUS
  645. dp_umac_reset_notify_target(struct dp_soc_umac_reset_ctx *umac_reset_ctx)
  646. {
  647. enum umac_reset_state next_state;
  648. enum umac_reset_tx_cmd tx_cmd;
  649. QDF_STATUS status;
  650. switch (umac_reset_ctx->current_state) {
  651. case UMAC_RESET_STATE_HOST_TRIGGER_DONE:
  652. tx_cmd = UMAC_RESET_TX_CMD_TRIGGER_DONE;
  653. next_state = UMAC_RESET_STATE_WAIT_FOR_DO_PRE_RESET;
  654. break;
  655. case UMAC_RESET_STATE_HOST_PRE_RESET_DONE:
  656. tx_cmd = UMAC_RESET_TX_CMD_PRE_RESET_DONE;
  657. next_state = UMAC_RESET_STATE_WAIT_FOR_DO_POST_RESET_START;
  658. break;
  659. case UMAC_RESET_STATE_HOST_POST_RESET_START_DONE:
  660. tx_cmd = UMAC_RESET_TX_CMD_POST_RESET_START_DONE;
  661. next_state = UMAC_RESET_STATE_WAIT_FOR_DO_POST_RESET_COMPLETE;
  662. break;
  663. case UMAC_RESET_STATE_HOST_POST_RESET_COMPLETE_DONE:
  664. tx_cmd = UMAC_RESET_TX_CMD_POST_RESET_COMPLETE_DONE;
  665. next_state = UMAC_RESET_STATE_WAIT_FOR_TRIGGER;
  666. break;
  667. default:
  668. dp_umac_reset_err("Invalid state(%d) during Tx",
  669. umac_reset_ctx->current_state);
  670. qdf_assert_always(0);
  671. return QDF_STATUS_E_FAILURE;
  672. }
  673. /*
  674. * Update the state machine before sending the command to firmware
  675. * as we might get the response from firmware even before the state
  676. * is updated.
  677. */
  678. umac_reset_ctx->current_state = next_state;
  679. status = dp_umac_reset_post_tx_cmd(umac_reset_ctx, tx_cmd);
  680. if (QDF_IS_STATUS_ERROR(status)) {
  681. dp_umac_reset_err("Couldn't post Tx cmd");
  682. qdf_assert_always(0);
  683. return status;
  684. }
  685. return status;
  686. }
  687. /**
  688. * dp_umac_reset_notify_completion() - Notify that a given action has been
  689. * completed
  690. * @soc: DP soc object
  691. * @next_state: The state to which the state machine needs to be updated due to
  692. * this completion
  693. *
  694. * Return: QDF status of operation
  695. */
  696. static QDF_STATUS dp_umac_reset_notify_completion(
  697. struct dp_soc *soc,
  698. enum umac_reset_state next_state)
  699. {
  700. struct dp_soc_umac_reset_ctx *umac_reset_ctx;
  701. if (!soc) {
  702. dp_umac_reset_err("DP SOC is null");
  703. return QDF_STATUS_E_NULL_VALUE;
  704. }
  705. umac_reset_ctx = &soc->umac_reset_ctx;
  706. /* Update the state first */
  707. umac_reset_ctx->current_state = next_state;
  708. return dp_umac_reset_notify_target(umac_reset_ctx);
  709. }
  710. static void dp_umac_wait_for_quiescent_state(struct dp_soc *soc)
  711. {
  712. enum umac_reset_state current_state;
  713. do {
  714. msleep(10);
  715. barrier();
  716. current_state = soc->umac_reset_ctx.current_state;
  717. } while ((current_state == UMAC_RESET_STATE_DO_TRIGGER_RECEIVED) ||
  718. (current_state == UMAC_RESET_STATE_DO_PRE_RESET_RECEIVED) ||
  719. (current_state == UMAC_RESET_STATE_DO_POST_RESET_START_RECEIVED) ||
  720. (current_state == UMAC_RESET_STATE_DO_POST_RESET_COMPLETE_RECEIVED));
  721. }
  722. QDF_STATUS dp_umac_reset_notify_action_completion(
  723. struct dp_soc *soc,
  724. enum umac_reset_action action)
  725. {
  726. enum umac_reset_state next_state;
  727. if (!soc) {
  728. dp_umac_reset_err("DP SOC is null");
  729. return QDF_STATUS_E_NULL_VALUE;
  730. }
  731. if (!soc->features.umac_hw_reset_support) {
  732. dp_umac_reset_info("Target doesn't support the UMAC HW reset feature");
  733. return QDF_STATUS_E_NOSUPPORT;
  734. }
  735. switch (action) {
  736. case UMAC_RESET_ACTION_DO_TRIGGER_RECOVERY:
  737. next_state = UMAC_RESET_STATE_HOST_TRIGGER_DONE;
  738. break;
  739. case UMAC_RESET_ACTION_DO_PRE_RESET:
  740. next_state = UMAC_RESET_STATE_HOST_PRE_RESET_DONE;
  741. break;
  742. case UMAC_RESET_ACTION_DO_POST_RESET_START:
  743. next_state = UMAC_RESET_STATE_HOST_POST_RESET_START_DONE;
  744. break;
  745. case UMAC_RESET_ACTION_DO_POST_RESET_COMPLETE:
  746. next_state = UMAC_RESET_STATE_HOST_POST_RESET_COMPLETE_DONE;
  747. break;
  748. case UMAC_RESET_ACTION_ABORT:
  749. next_state = UMAC_RESET_STATE_WAIT_FOR_TRIGGER;
  750. break;
  751. default:
  752. dp_umac_reset_err("Invalid action: %u", action);
  753. return QDF_STATUS_E_FAILURE;
  754. }
  755. return dp_umac_reset_notify_completion(soc, next_state);
  756. }
  757. /**
  758. * dp_soc_umac_reset_deinit() - Deinitialize the umac reset module
  759. * @txrx_soc: DP soc object
  760. *
  761. * Return: QDF status of operation
  762. */
  763. QDF_STATUS dp_soc_umac_reset_deinit(struct cdp_soc_t *txrx_soc)
  764. {
  765. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  766. struct dp_soc_umac_reset_ctx *umac_reset_ctx;
  767. qdf_nbuf_t nbuf_list;
  768. if (!soc) {
  769. dp_umac_reset_err("DP SOC is null");
  770. return QDF_STATUS_E_NULL_VALUE;
  771. }
  772. if (!soc->features.umac_hw_reset_support) {
  773. dp_umac_reset_info("No target support for UMAC reset feature");
  774. return QDF_STATUS_E_NOSUPPORT;
  775. }
  776. if (dp_check_umac_reset_in_progress(soc)) {
  777. dp_umac_reset_info("Cleaning up Umac reset context");
  778. dp_umac_wait_for_quiescent_state(soc);
  779. dp_resume_reo_send_cmd(soc);
  780. dp_umac_reset_notify_action_completion(soc,
  781. UMAC_RESET_ACTION_ABORT);
  782. }
  783. nbuf_list = soc->umac_reset_ctx.nbuf_list;
  784. soc->umac_reset_ctx.nbuf_list = NULL;
  785. while (nbuf_list) {
  786. qdf_nbuf_t nbuf = nbuf_list->next;
  787. qdf_nbuf_free(nbuf_list);
  788. nbuf_list = nbuf;
  789. }
  790. dp_umac_reset_interrupt_detach(soc);
  791. umac_reset_ctx = &soc->umac_reset_ctx;
  792. qdf_mem_free_consistent(soc->osdev, soc->osdev->dev,
  793. umac_reset_ctx->shmem_size,
  794. umac_reset_ctx->shmem_vaddr_unaligned,
  795. umac_reset_ctx->shmem_paddr_unaligned,
  796. 0);
  797. return QDF_STATUS_SUCCESS;
  798. }
  799. static inline const char *dp_umac_reset_current_state_to_str(
  800. enum umac_reset_state current_state)
  801. {
  802. switch (current_state) {
  803. case UMAC_RESET_STATE_WAIT_FOR_TRIGGER:
  804. return "UMAC_RESET_STATE_WAIT_FOR_TRIGGER";
  805. case UMAC_RESET_STATE_DO_TRIGGER_RECEIVED:
  806. return "UMAC_RESET_STATE_DO_TRIGGER_RECEIVED";
  807. case UMAC_RESET_STATE_HOST_TRIGGER_DONE:
  808. return "UMAC_RESET_STATE_HOST_TRIGGER_DONE";
  809. case UMAC_RESET_STATE_WAIT_FOR_DO_PRE_RESET:
  810. return "UMAC_RESET_STATE_WAIT_FOR_DO_PRE_RESET";
  811. case UMAC_RESET_STATE_DO_PRE_RESET_RECEIVED:
  812. return "UMAC_RESET_STATE_DO_PRE_RESET_RECEIVED";
  813. case UMAC_RESET_STATE_HOST_PRE_RESET_DONE:
  814. return "UMAC_RESET_STATE_HOST_PRE_RESET_DONE";
  815. case UMAC_RESET_STATE_WAIT_FOR_DO_POST_RESET_START:
  816. return "UMAC_RESET_STATE_WAIT_FOR_DO_POST_RESET_START";
  817. case UMAC_RESET_STATE_DO_POST_RESET_START_RECEIVED:
  818. return "UMAC_RESET_STATE_DO_POST_RESET_START_RECEIVED";
  819. case UMAC_RESET_STATE_HOST_POST_RESET_START_DONE:
  820. return "UMAC_RESET_STATE_HOST_POST_RESET_START_DONE";
  821. case UMAC_RESET_STATE_WAIT_FOR_DO_POST_RESET_COMPLETE:
  822. return "UMAC_RESET_STATE_WAIT_FOR_DO_POST_RESET_COMPLETE";
  823. case UMAC_RESET_STATE_DO_POST_RESET_COMPLETE_RECEIVED:
  824. return "UMAC_RESET_STATE_DO_POST_RESET_COMPLETE_RECEIVED";
  825. case UMAC_RESET_STATE_HOST_POST_RESET_COMPLETE_DONE:
  826. return "UMAC_RESET_STATE_HOST_POST_RESET_COMPLETE_DONE";
  827. default:
  828. return "Invalid UMAC Reset state";
  829. }
  830. }
  831. static inline const char *dp_umac_reset_pending_action_to_str(
  832. enum umac_reset_rx_event pending_action)
  833. {
  834. switch (pending_action) {
  835. case UMAC_RESET_RX_EVENT_NONE:
  836. return "UMAC_RESET_RX_EVENT_NONE";
  837. case UMAC_RESET_RX_EVENT_DO_TRIGGER_RECOVERY:
  838. return "UMAC_RESET_RX_EVENT_DO_TRIGGER_RECOVERY";
  839. case UMAC_RESET_RX_EVENT_DO_TRIGGER_TR_SYNC:
  840. return "UMAC_RESET_RX_EVENT_DO_TRIGGER_TR_SYNC";
  841. case UMAC_RESET_RX_EVENT_DO_PRE_RESET:
  842. return "UMAC_RESET_RX_EVENT_DO_PRE_RESET";
  843. case UMAC_RESET_RX_EVENT_DO_POST_RESET_START:
  844. return "UMAC_RESET_RX_EVENT_DO_POST_RESET_START";
  845. case UMAC_RESET_RX_EVENT_DO_POST_RESET_COMPELTE:
  846. return "UMAC_RESET_RX_EVENT_DO_POST_RESET_COMPELTE";
  847. default:
  848. return "Invalid pending action";
  849. }
  850. }
  851. QDF_STATUS dp_umac_reset_stats_print(struct dp_soc *soc)
  852. {
  853. struct dp_soc_umac_reset_ctx *umac_reset_ctx;
  854. umac_reset_ctx = &soc->umac_reset_ctx;
  855. DP_UMAC_RESET_PRINT_STATS("UMAC reset stats for soc:%pK\n"
  856. "\t\ttrigger time :%llu us\n"
  857. "\t\tPre_reset time :%llu us\n"
  858. "\t\tPost_reset time :%llu us\n"
  859. "\t\tPost_reset_complete time :%llu us\n"
  860. "\t\tCurrent state :%s\n"
  861. "\t\tPending action :%s",
  862. soc,
  863. umac_reset_ctx->ts.trigger_done -
  864. umac_reset_ctx->ts.trigger_start,
  865. umac_reset_ctx->ts.pre_reset_done -
  866. umac_reset_ctx->ts.pre_reset_start,
  867. umac_reset_ctx->ts.post_reset_done -
  868. umac_reset_ctx->ts.post_reset_start,
  869. umac_reset_ctx->ts.post_reset_complete_done -
  870. umac_reset_ctx->ts.post_reset_complete_start,
  871. dp_umac_reset_current_state_to_str(
  872. umac_reset_ctx->current_state),
  873. dp_umac_reset_pending_action_to_str(
  874. umac_reset_ctx->pending_action));
  875. return dp_mlo_umac_reset_stats_print(soc);
  876. }