dp_umac_reset.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024
  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(WLAN_FEATURE_11BE_MLO) || !defined(WLAN_MLO_MULTI_CHIP)
  278. /**
  279. * dp_umac_reset_initiate_umac_recovery() - Initiate Umac reset session
  280. * @soc: dp soc handle
  281. * @umac_reset_ctx: Umac reset context
  282. * @rx_event: Rx event received
  283. * @is_target_recovery: Flag to indicate if it is triggered for target recovery
  284. *
  285. * Return: status
  286. */
  287. static QDF_STATUS dp_umac_reset_initiate_umac_recovery(struct dp_soc *soc,
  288. struct dp_soc_umac_reset_ctx *umac_reset_ctx,
  289. enum umac_reset_rx_event rx_event,
  290. bool is_target_recovery)
  291. {
  292. return dp_umac_reset_validate_n_update_state_machine_on_rx(
  293. umac_reset_ctx, rx_event,
  294. UMAC_RESET_STATE_WAIT_FOR_TRIGGER,
  295. UMAC_RESET_STATE_DO_TRIGGER_RECEIVED);
  296. }
  297. /**
  298. * dp_umac_reset_complete_umac_recovery() - Complete Umac reset session
  299. * @soc: dp soc handle
  300. *
  301. * Return: void
  302. */
  303. static void dp_umac_reset_complete_umac_recovery(struct dp_soc *soc)
  304. {
  305. dp_umac_reset_alert("Umac reset was handled successfully on soc %pK",
  306. soc);
  307. }
  308. /**
  309. * dp_umac_reset_handle_action_cb() - Function to call action callback
  310. * @soc: dp soc handle
  311. * @umac_reset_ctx: Umac reset context
  312. * @action: Action to call the callback for
  313. *
  314. * Return: QDF_STATUS status
  315. */
  316. static QDF_STATUS dp_umac_reset_handle_action_cb(struct dp_soc *soc,
  317. struct dp_soc_umac_reset_ctx *umac_reset_ctx,
  318. enum umac_reset_action action)
  319. {
  320. QDF_STATUS status = QDF_STATUS_SUCCESS;
  321. if (!umac_reset_ctx->rx_actions.cb[action]) {
  322. dp_umac_reset_err("rx callback is NULL");
  323. return QDF_STATUS_E_FAILURE;
  324. }
  325. status = umac_reset_ctx->rx_actions.cb[action](soc);
  326. return QDF_STATUS_SUCCESS;
  327. }
  328. /**
  329. * dp_umac_reset_post_tx_cmd() - Iterate partner socs and post Tx command
  330. * @umac_reset_ctx: UMAC reset context
  331. * @tx_cmd: Tx command to be posted
  332. *
  333. * Return: QDF status of operation
  334. */
  335. static QDF_STATUS
  336. dp_umac_reset_post_tx_cmd(struct dp_soc_umac_reset_ctx *umac_reset_ctx,
  337. enum umac_reset_tx_cmd tx_cmd)
  338. {
  339. struct dp_soc *soc = container_of(umac_reset_ctx, struct dp_soc,
  340. umac_reset_ctx);
  341. dp_umac_reset_post_tx_cmd_via_shmem(soc, &tx_cmd, 0);
  342. return QDF_STATUS_SUCCESS;
  343. }
  344. /**
  345. * dp_umac_reset_initiator_check() - Check if soc is the Umac reset initiator
  346. * @soc: dp soc handle
  347. *
  348. * Return: true if the soc is initiator or false otherwise
  349. */
  350. static bool dp_umac_reset_initiator_check(struct dp_soc *soc)
  351. {
  352. return true;
  353. }
  354. /**
  355. * dp_umac_reset_target_recovery_check() - Check if this is for target recovery
  356. * @soc: dp soc handle
  357. *
  358. * Return: true if the session is for target recovery or false otherwise
  359. */
  360. static bool dp_umac_reset_target_recovery_check(struct dp_soc *soc)
  361. {
  362. return false;
  363. }
  364. /**
  365. * dp_umac_reset_is_soc_ignored() - Check if this soc is to be ignored
  366. * @soc: dp soc handle
  367. *
  368. * Return: true if the soc is ignored or false otherwise
  369. */
  370. static bool dp_umac_reset_is_soc_ignored(struct dp_soc *soc)
  371. {
  372. return false;
  373. }
  374. #endif
  375. /**
  376. * dp_umac_reset_rx_event_handler() - Main Rx event handler for UMAC reset
  377. * @dp_ctx: Interrupt context corresponding to UMAC reset
  378. *
  379. * Return: 0 incase of success, else failure
  380. */
  381. static int dp_umac_reset_rx_event_handler(void *dp_ctx)
  382. {
  383. struct dp_intr *int_ctx = (struct dp_intr *)dp_ctx;
  384. struct dp_soc *soc = int_ctx->soc;
  385. struct dp_soc_umac_reset_ctx *umac_reset_ctx;
  386. enum umac_reset_rx_event rx_event;
  387. QDF_STATUS status = QDF_STATUS_E_INVAL;
  388. enum umac_reset_action action = UMAC_RESET_ACTION_NONE;
  389. bool target_recovery = false;
  390. if (!soc) {
  391. dp_umac_reset_err("DP SOC is null");
  392. goto exit;
  393. }
  394. umac_reset_ctx = &soc->umac_reset_ctx;
  395. dp_umac_reset_debug("enter");
  396. rx_event = dp_umac_reset_get_rx_event(umac_reset_ctx);
  397. if (umac_reset_ctx->pending_action) {
  398. if (rx_event != UMAC_RESET_RX_EVENT_NONE) {
  399. dp_umac_reset_err("Invalid value(%u) for Rx event when "
  400. "action %u is pending\n", rx_event,
  401. umac_reset_ctx->pending_action);
  402. qdf_assert_always(0);
  403. }
  404. }
  405. switch (rx_event) {
  406. case UMAC_RESET_RX_EVENT_NONE:
  407. if (umac_reset_ctx->pending_action)
  408. action = umac_reset_ctx->pending_action;
  409. else
  410. dp_umac_reset_err("Not a UMAC reset event!!");
  411. status = QDF_STATUS_SUCCESS;
  412. break;
  413. case UMAC_RESET_RX_EVENT_DO_TRIGGER_TR_SYNC:
  414. target_recovery = true;
  415. /* Fall through */
  416. case UMAC_RESET_RX_EVENT_DO_TRIGGER_RECOVERY:
  417. status =
  418. dp_umac_reset_initiate_umac_recovery(soc, umac_reset_ctx,
  419. rx_event, target_recovery);
  420. if (status != QDF_STATUS_SUCCESS)
  421. break;
  422. umac_reset_ctx->ts.trigger_start =
  423. qdf_get_log_timestamp_usecs();
  424. action = UMAC_RESET_ACTION_DO_TRIGGER_RECOVERY;
  425. break;
  426. case UMAC_RESET_RX_EVENT_DO_PRE_RESET:
  427. status = dp_umac_reset_validate_n_update_state_machine_on_rx(
  428. umac_reset_ctx, rx_event,
  429. UMAC_RESET_STATE_WAIT_FOR_DO_PRE_RESET,
  430. UMAC_RESET_STATE_DO_PRE_RESET_RECEIVED);
  431. umac_reset_ctx->ts.pre_reset_start =
  432. qdf_get_log_timestamp_usecs();
  433. action = UMAC_RESET_ACTION_DO_PRE_RESET;
  434. break;
  435. case UMAC_RESET_RX_EVENT_DO_POST_RESET_START:
  436. status = dp_umac_reset_validate_n_update_state_machine_on_rx(
  437. umac_reset_ctx, rx_event,
  438. UMAC_RESET_STATE_WAIT_FOR_DO_POST_RESET_START,
  439. UMAC_RESET_STATE_DO_POST_RESET_START_RECEIVED);
  440. umac_reset_ctx->ts.post_reset_start =
  441. qdf_get_log_timestamp_usecs();
  442. action = UMAC_RESET_ACTION_DO_POST_RESET_START;
  443. break;
  444. case UMAC_RESET_RX_EVENT_DO_POST_RESET_COMPELTE:
  445. status = dp_umac_reset_validate_n_update_state_machine_on_rx(
  446. umac_reset_ctx, rx_event,
  447. UMAC_RESET_STATE_WAIT_FOR_DO_POST_RESET_COMPLETE,
  448. UMAC_RESET_STATE_DO_POST_RESET_COMPLETE_RECEIVED);
  449. umac_reset_ctx->ts.post_reset_complete_start =
  450. qdf_get_log_timestamp_usecs();
  451. action = UMAC_RESET_ACTION_DO_POST_RESET_COMPLETE;
  452. break;
  453. case UMAC_RESET_RX_EVENT_ERROR:
  454. dp_umac_reset_err("Error Rx event");
  455. goto exit;
  456. default:
  457. dp_umac_reset_err("Invalid value(%u) for Rx event", rx_event);
  458. goto exit;
  459. }
  460. /* Call the handler for this event */
  461. if (QDF_IS_STATUS_SUCCESS(status)) {
  462. dp_umac_reset_handle_action_cb(soc, umac_reset_ctx, action);
  463. }
  464. exit:
  465. return qdf_status_to_os_return(status);
  466. }
  467. QDF_STATUS dp_umac_reset_interrupt_attach(struct dp_soc *soc)
  468. {
  469. struct dp_soc_umac_reset_ctx *umac_reset_ctx;
  470. int msi_vector_count, ret;
  471. uint32_t msi_base_data, msi_vector_start;
  472. uint32_t umac_reset_vector, umac_reset_irq;
  473. QDF_STATUS status;
  474. if (!soc) {
  475. dp_umac_reset_err("DP SOC is null");
  476. return QDF_STATUS_E_NULL_VALUE;
  477. }
  478. if (!soc->features.umac_hw_reset_support) {
  479. dp_umac_reset_info("Target doesn't support the UMAC HW reset feature");
  480. return QDF_STATUS_SUCCESS;
  481. }
  482. umac_reset_ctx = &soc->umac_reset_ctx;
  483. if (pld_get_enable_intx(soc->osdev->dev)) {
  484. dp_umac_reset_err("UMAC reset is not supported in legacy interrupt mode");
  485. return QDF_STATUS_E_FAILURE;
  486. }
  487. ret = pld_get_user_msi_assignment(soc->osdev->dev, "DP",
  488. &msi_vector_count, &msi_base_data,
  489. &msi_vector_start);
  490. if (ret) {
  491. /* UMAC reset uses IPC interrupt for AHB devices */
  492. status = hif_get_umac_reset_irq(soc->hif_handle,
  493. &umac_reset_irq);
  494. if (status) {
  495. dp_umac_reset_err("get_umac_reset_irq failed status %d",
  496. status);
  497. return QDF_STATUS_E_FAILURE;
  498. }
  499. } else {
  500. if (umac_reset_ctx->intr_offset < 0 ||
  501. umac_reset_ctx->intr_offset >= WLAN_CFG_INT_NUM_CONTEXTS) {
  502. dp_umac_reset_err("Invalid interrupt offset");
  503. return QDF_STATUS_E_FAILURE;
  504. }
  505. umac_reset_vector = msi_vector_start +
  506. (umac_reset_ctx->intr_offset % msi_vector_count);
  507. /* Get IRQ number */
  508. umac_reset_irq = pld_get_msi_irq(soc->osdev->dev,
  509. umac_reset_vector);
  510. }
  511. /* Finally register to this IRQ from HIF layer */
  512. return hif_register_umac_reset_handler(
  513. soc->hif_handle,
  514. dp_umac_reset_peek_rx_event,
  515. dp_umac_reset_rx_event_handler,
  516. &soc->intr_ctx[umac_reset_ctx->intr_offset],
  517. umac_reset_irq);
  518. }
  519. QDF_STATUS dp_umac_reset_interrupt_detach(struct dp_soc *soc)
  520. {
  521. if (!soc) {
  522. dp_umac_reset_err("DP SOC is null");
  523. return QDF_STATUS_E_NULL_VALUE;
  524. }
  525. if (!soc->features.umac_hw_reset_support) {
  526. dp_umac_reset_info("Target doesn't support the UMAC HW reset feature");
  527. return QDF_STATUS_SUCCESS;
  528. }
  529. return hif_unregister_umac_reset_handler(soc->hif_handle);
  530. }
  531. QDF_STATUS dp_umac_reset_register_rx_action_callback(
  532. struct dp_soc *soc,
  533. QDF_STATUS (*handler)(struct dp_soc *soc),
  534. enum umac_reset_action action)
  535. {
  536. struct dp_soc_umac_reset_ctx *umac_reset_ctx;
  537. if (!soc) {
  538. dp_umac_reset_err("DP SOC is null");
  539. return QDF_STATUS_E_NULL_VALUE;
  540. }
  541. if (!soc->features.umac_hw_reset_support) {
  542. dp_umac_reset_info("Target doesn't support UMAC HW reset");
  543. return QDF_STATUS_E_NOSUPPORT;
  544. }
  545. if (action >= UMAC_RESET_ACTION_MAX) {
  546. dp_umac_reset_err("invalid action: %d", action);
  547. return QDF_STATUS_E_INVAL;
  548. }
  549. umac_reset_ctx = &soc->umac_reset_ctx;
  550. umac_reset_ctx->rx_actions.cb[action] = handler;
  551. return QDF_STATUS_SUCCESS;
  552. }
  553. /**
  554. * dp_umac_reset_post_tx_cmd_via_shmem() - Post Tx command using shared memory
  555. * @soc: DP soc object
  556. * @ctxt: Tx command to be posted
  557. * @chip_id: Chip id of the mlo soc
  558. *
  559. * Return: None
  560. */
  561. void
  562. dp_umac_reset_post_tx_cmd_via_shmem(struct dp_soc *soc, void *ctxt, int chip_id)
  563. {
  564. enum umac_reset_tx_cmd tx_cmd = *((enum umac_reset_tx_cmd *)ctxt);
  565. htt_umac_hang_recovery_msg_shmem_t *shmem_vaddr;
  566. struct dp_soc_umac_reset_ctx *umac_reset_ctx = &soc->umac_reset_ctx;
  567. bool initiator;
  568. QDF_STATUS status;
  569. if (dp_umac_reset_is_soc_ignored(soc)) {
  570. dp_umac_reset_debug("Skipping soc (chip id %d)", chip_id);
  571. return;
  572. }
  573. shmem_vaddr = umac_reset_ctx->shmem_vaddr_aligned;
  574. if (!shmem_vaddr) {
  575. dp_umac_reset_err("Shared memory address is NULL");
  576. return;
  577. }
  578. dp_umac_reset_debug("Sending txcmd %u for chip id %u", tx_cmd, chip_id);
  579. switch (tx_cmd) {
  580. case UMAC_RESET_TX_CMD_TRIGGER_DONE:
  581. /* Send htt message to the partner soc */
  582. initiator = dp_umac_reset_initiator_check(soc);
  583. if (!initiator)
  584. umac_reset_ctx->current_state =
  585. UMAC_RESET_STATE_WAIT_FOR_DO_PRE_RESET;
  586. status = dp_htt_umac_reset_send_start_pre_reset_cmd(soc,
  587. initiator,
  588. !dp_umac_reset_target_recovery_check(soc));
  589. if (status != QDF_STATUS_SUCCESS) {
  590. dp_umac_reset_err("Unable to send Umac trigger");
  591. qdf_assert_always(0);
  592. } else {
  593. dp_umac_reset_debug("Sent trigger for soc (chip_id %d)",
  594. chip_id);
  595. }
  596. umac_reset_ctx->ts.trigger_done = qdf_get_log_timestamp_usecs();
  597. break;
  598. case UMAC_RESET_TX_CMD_PRE_RESET_DONE:
  599. HTT_UMAC_HANG_RECOVERY_MSG_SHMEM_PRE_RESET_DONE_SET(
  600. shmem_vaddr->h2t_msg, 1);
  601. umac_reset_ctx->ts.pre_reset_done =
  602. qdf_get_log_timestamp_usecs();
  603. break;
  604. case UMAC_RESET_TX_CMD_POST_RESET_START_DONE:
  605. HTT_UMAC_HANG_RECOVERY_MSG_SHMEM_POST_RESET_START_DONE_SET(
  606. shmem_vaddr->h2t_msg, 1);
  607. umac_reset_ctx->ts.post_reset_done =
  608. qdf_get_log_timestamp_usecs();
  609. break;
  610. case UMAC_RESET_TX_CMD_POST_RESET_COMPLETE_DONE:
  611. HTT_UMAC_HANG_RECOVERY_MSG_SHMEM_POST_RESET_COMPLETE_DONE_SET(
  612. shmem_vaddr->h2t_msg, 1);
  613. umac_reset_ctx->ts.post_reset_complete_done =
  614. qdf_get_log_timestamp_usecs();
  615. break;
  616. default:
  617. dp_umac_reset_err("Invalid tx cmd: %d", tx_cmd);
  618. return;
  619. }
  620. return;
  621. }
  622. /**
  623. * dp_umac_reset_notify_target() - Notify the target about completion of action.
  624. * @umac_reset_ctx: UMAC reset context
  625. *
  626. * This API figures out the Tx command that needs to be posted based on the
  627. * current state in the state machine. Also, updates the state machine once the
  628. * Tx command has been posted.
  629. *
  630. * Return: QDF status of operation
  631. */
  632. static QDF_STATUS
  633. dp_umac_reset_notify_target(struct dp_soc_umac_reset_ctx *umac_reset_ctx)
  634. {
  635. enum umac_reset_state next_state;
  636. enum umac_reset_tx_cmd tx_cmd;
  637. QDF_STATUS status;
  638. switch (umac_reset_ctx->current_state) {
  639. case UMAC_RESET_STATE_HOST_TRIGGER_DONE:
  640. tx_cmd = UMAC_RESET_TX_CMD_TRIGGER_DONE;
  641. next_state = UMAC_RESET_STATE_WAIT_FOR_DO_PRE_RESET;
  642. break;
  643. case UMAC_RESET_STATE_HOST_PRE_RESET_DONE:
  644. tx_cmd = UMAC_RESET_TX_CMD_PRE_RESET_DONE;
  645. next_state = UMAC_RESET_STATE_WAIT_FOR_DO_POST_RESET_START;
  646. break;
  647. case UMAC_RESET_STATE_HOST_POST_RESET_START_DONE:
  648. tx_cmd = UMAC_RESET_TX_CMD_POST_RESET_START_DONE;
  649. next_state = UMAC_RESET_STATE_WAIT_FOR_DO_POST_RESET_COMPLETE;
  650. break;
  651. case UMAC_RESET_STATE_HOST_POST_RESET_COMPLETE_DONE:
  652. tx_cmd = UMAC_RESET_TX_CMD_POST_RESET_COMPLETE_DONE;
  653. next_state = UMAC_RESET_STATE_WAIT_FOR_TRIGGER;
  654. break;
  655. default:
  656. dp_umac_reset_err("Invalid state(%d) during Tx",
  657. umac_reset_ctx->current_state);
  658. qdf_assert_always(0);
  659. return QDF_STATUS_E_FAILURE;
  660. }
  661. /*
  662. * Update the state machine before sending the command to firmware
  663. * as we might get the response from firmware even before the state
  664. * is updated.
  665. */
  666. umac_reset_ctx->current_state = next_state;
  667. status = dp_umac_reset_post_tx_cmd(umac_reset_ctx, tx_cmd);
  668. if (QDF_IS_STATUS_ERROR(status)) {
  669. dp_umac_reset_err("Couldn't post Tx cmd");
  670. qdf_assert_always(0);
  671. return status;
  672. }
  673. return status;
  674. }
  675. /**
  676. * dp_umac_reset_notify_completion() - Notify that a given action has been
  677. * completed
  678. * @soc: DP soc object
  679. * @next_state: The state to which the state machine needs to be updated due to
  680. * this completion
  681. *
  682. * Return: QDF status of operation
  683. */
  684. static QDF_STATUS dp_umac_reset_notify_completion(
  685. struct dp_soc *soc,
  686. enum umac_reset_state next_state)
  687. {
  688. struct dp_soc_umac_reset_ctx *umac_reset_ctx;
  689. if (!soc) {
  690. dp_umac_reset_err("DP SOC is null");
  691. return QDF_STATUS_E_NULL_VALUE;
  692. }
  693. umac_reset_ctx = &soc->umac_reset_ctx;
  694. /* Update the state first */
  695. umac_reset_ctx->current_state = next_state;
  696. return dp_umac_reset_notify_target(umac_reset_ctx);
  697. }
  698. static void dp_umac_wait_for_quiescent_state(struct dp_soc *soc)
  699. {
  700. enum umac_reset_state current_state;
  701. do {
  702. msleep(10);
  703. barrier();
  704. current_state = soc->umac_reset_ctx.current_state;
  705. } while ((current_state == UMAC_RESET_STATE_DO_TRIGGER_RECEIVED) ||
  706. (current_state == UMAC_RESET_STATE_DO_PRE_RESET_RECEIVED) ||
  707. (current_state == UMAC_RESET_STATE_DO_POST_RESET_START_RECEIVED) ||
  708. (current_state == UMAC_RESET_STATE_DO_POST_RESET_COMPLETE_RECEIVED));
  709. }
  710. QDF_STATUS dp_umac_reset_notify_action_completion(
  711. struct dp_soc *soc,
  712. enum umac_reset_action action)
  713. {
  714. enum umac_reset_state next_state;
  715. if (!soc) {
  716. dp_umac_reset_err("DP SOC is null");
  717. return QDF_STATUS_E_NULL_VALUE;
  718. }
  719. if (!soc->features.umac_hw_reset_support) {
  720. dp_umac_reset_info("Target doesn't support the UMAC HW reset feature");
  721. return QDF_STATUS_E_NOSUPPORT;
  722. }
  723. switch (action) {
  724. case UMAC_RESET_ACTION_DO_TRIGGER_RECOVERY:
  725. next_state = UMAC_RESET_STATE_HOST_TRIGGER_DONE;
  726. break;
  727. case UMAC_RESET_ACTION_DO_PRE_RESET:
  728. next_state = UMAC_RESET_STATE_HOST_PRE_RESET_DONE;
  729. break;
  730. case UMAC_RESET_ACTION_DO_POST_RESET_START:
  731. next_state = UMAC_RESET_STATE_HOST_POST_RESET_START_DONE;
  732. break;
  733. case UMAC_RESET_ACTION_DO_POST_RESET_COMPLETE:
  734. next_state = UMAC_RESET_STATE_HOST_POST_RESET_COMPLETE_DONE;
  735. break;
  736. case UMAC_RESET_ACTION_ABORT:
  737. next_state = UMAC_RESET_STATE_WAIT_FOR_TRIGGER;
  738. break;
  739. default:
  740. dp_umac_reset_err("Invalid action");
  741. return QDF_STATUS_E_FAILURE;
  742. }
  743. return dp_umac_reset_notify_completion(soc, next_state);
  744. }
  745. /**
  746. * dp_soc_umac_reset_deinit() - Deinitialize the umac reset module
  747. * @txrx_soc: DP soc object
  748. *
  749. * Return: QDF status of operation
  750. */
  751. QDF_STATUS dp_soc_umac_reset_deinit(struct cdp_soc_t *txrx_soc)
  752. {
  753. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  754. struct dp_soc_umac_reset_ctx *umac_reset_ctx;
  755. qdf_nbuf_t nbuf_list;
  756. if (!soc) {
  757. dp_umac_reset_err("DP SOC is null");
  758. return QDF_STATUS_E_NULL_VALUE;
  759. }
  760. if (!soc->features.umac_hw_reset_support) {
  761. dp_umac_reset_info("No target support for UMAC reset feature");
  762. return QDF_STATUS_E_NOSUPPORT;
  763. }
  764. if (dp_check_umac_reset_in_progress(soc)) {
  765. dp_umac_reset_info("Cleaning up Umac reset context");
  766. dp_umac_wait_for_quiescent_state(soc);
  767. dp_resume_reo_send_cmd(soc);
  768. dp_umac_reset_notify_action_completion(soc,
  769. UMAC_RESET_ACTION_ABORT);
  770. }
  771. nbuf_list = soc->umac_reset_ctx.nbuf_list;
  772. soc->umac_reset_ctx.nbuf_list = NULL;
  773. while (nbuf_list) {
  774. qdf_nbuf_t nbuf = nbuf_list->next;
  775. qdf_nbuf_free(nbuf_list);
  776. nbuf_list = nbuf;
  777. }
  778. dp_umac_reset_interrupt_detach(soc);
  779. umac_reset_ctx = &soc->umac_reset_ctx;
  780. qdf_mem_free_consistent(soc->osdev, soc->osdev->dev,
  781. umac_reset_ctx->shmem_size,
  782. umac_reset_ctx->shmem_vaddr_unaligned,
  783. umac_reset_ctx->shmem_paddr_unaligned,
  784. 0);
  785. return QDF_STATUS_SUCCESS;
  786. }
  787. static inline const char *dp_umac_reset_current_state_to_str(
  788. enum umac_reset_state current_state)
  789. {
  790. switch (current_state) {
  791. case UMAC_RESET_STATE_WAIT_FOR_TRIGGER:
  792. return "UMAC_RESET_STATE_WAIT_FOR_TRIGGER";
  793. case UMAC_RESET_STATE_DO_TRIGGER_RECEIVED:
  794. return "UMAC_RESET_STATE_DO_TRIGGER_RECEIVED";
  795. case UMAC_RESET_STATE_HOST_TRIGGER_DONE:
  796. return "UMAC_RESET_STATE_HOST_TRIGGER_DONE";
  797. case UMAC_RESET_STATE_WAIT_FOR_DO_PRE_RESET:
  798. return "UMAC_RESET_STATE_WAIT_FOR_DO_PRE_RESET";
  799. case UMAC_RESET_STATE_DO_PRE_RESET_RECEIVED:
  800. return "UMAC_RESET_STATE_DO_PRE_RESET_RECEIVED";
  801. case UMAC_RESET_STATE_HOST_PRE_RESET_DONE:
  802. return "UMAC_RESET_STATE_HOST_PRE_RESET_DONE";
  803. case UMAC_RESET_STATE_WAIT_FOR_DO_POST_RESET_START:
  804. return "UMAC_RESET_STATE_WAIT_FOR_DO_POST_RESET_START";
  805. case UMAC_RESET_STATE_DO_POST_RESET_START_RECEIVED:
  806. return "UMAC_RESET_STATE_DO_POST_RESET_START_RECEIVED";
  807. case UMAC_RESET_STATE_HOST_POST_RESET_START_DONE:
  808. return "UMAC_RESET_STATE_HOST_POST_RESET_START_DONE";
  809. case UMAC_RESET_STATE_WAIT_FOR_DO_POST_RESET_COMPLETE:
  810. return "UMAC_RESET_STATE_WAIT_FOR_DO_POST_RESET_COMPLETE";
  811. case UMAC_RESET_STATE_DO_POST_RESET_COMPLETE_RECEIVED:
  812. return "UMAC_RESET_STATE_DO_POST_RESET_COMPLETE_RECEIVED";
  813. case UMAC_RESET_STATE_HOST_POST_RESET_COMPLETE_DONE:
  814. return "UMAC_RESET_STATE_HOST_POST_RESET_COMPLETE_DONE";
  815. default:
  816. return "Invalid UMAC Reset state";
  817. }
  818. }
  819. static inline const char *dp_umac_reset_pending_action_to_str(
  820. enum umac_reset_rx_event pending_action)
  821. {
  822. switch (pending_action) {
  823. case UMAC_RESET_RX_EVENT_NONE:
  824. return "UMAC_RESET_RX_EVENT_NONE";
  825. case UMAC_RESET_RX_EVENT_DO_TRIGGER_RECOVERY:
  826. return "UMAC_RESET_RX_EVENT_DO_TRIGGER_RECOVERY";
  827. case UMAC_RESET_RX_EVENT_DO_TRIGGER_TR_SYNC:
  828. return "UMAC_RESET_RX_EVENT_DO_TRIGGER_TR_SYNC";
  829. case UMAC_RESET_RX_EVENT_DO_PRE_RESET:
  830. return "UMAC_RESET_RX_EVENT_DO_PRE_RESET";
  831. case UMAC_RESET_RX_EVENT_DO_POST_RESET_START:
  832. return "UMAC_RESET_RX_EVENT_DO_POST_RESET_START";
  833. case UMAC_RESET_RX_EVENT_DO_POST_RESET_COMPELTE:
  834. return "UMAC_RESET_RX_EVENT_DO_POST_RESET_COMPELTE";
  835. default:
  836. return "Invalid pending action";
  837. }
  838. }
  839. QDF_STATUS dp_umac_reset_stats_print(struct dp_soc *soc)
  840. {
  841. struct dp_soc_umac_reset_ctx *umac_reset_ctx;
  842. umac_reset_ctx = &soc->umac_reset_ctx;
  843. DP_UMAC_RESET_PRINT_STATS("UMAC reset stats for soc:%pK\n"
  844. "\t\ttrigger time :%u us\n"
  845. "\t\tPre_reset time :%u us\n"
  846. "\t\tPost_reset time :%u us\n"
  847. "\t\tPost_reset_complete time :%u us\n"
  848. "\t\tCurrent state :%s\n"
  849. "\t\tPending action :%s",
  850. soc,
  851. umac_reset_ctx->ts.trigger_done -
  852. umac_reset_ctx->ts.trigger_start,
  853. umac_reset_ctx->ts.pre_reset_done -
  854. umac_reset_ctx->ts.pre_reset_start,
  855. umac_reset_ctx->ts.post_reset_done -
  856. umac_reset_ctx->ts.post_reset_start,
  857. umac_reset_ctx->ts.post_reset_complete_done -
  858. umac_reset_ctx->ts.post_reset_complete_start,
  859. dp_umac_reset_current_state_to_str(
  860. umac_reset_ctx->current_state),
  861. dp_umac_reset_pending_action_to_str(
  862. umac_reset_ctx->pending_action));
  863. return dp_mlo_umac_reset_stats_print(soc);
  864. }