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