dp_umac_reset.c 28 KB

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