dp_umac_reset.c 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025
  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: %d",
  503. umac_reset_ctx->intr_offset);
  504. return QDF_STATUS_E_FAILURE;
  505. }
  506. umac_reset_vector = msi_vector_start +
  507. (umac_reset_ctx->intr_offset % msi_vector_count);
  508. /* Get IRQ number */
  509. umac_reset_irq = pld_get_msi_irq(soc->osdev->dev,
  510. umac_reset_vector);
  511. }
  512. /* Finally register to this IRQ from HIF layer */
  513. return hif_register_umac_reset_handler(
  514. soc->hif_handle,
  515. dp_umac_reset_peek_rx_event,
  516. dp_umac_reset_rx_event_handler,
  517. &soc->intr_ctx[umac_reset_ctx->intr_offset],
  518. umac_reset_irq);
  519. }
  520. QDF_STATUS dp_umac_reset_interrupt_detach(struct dp_soc *soc)
  521. {
  522. if (!soc) {
  523. dp_umac_reset_err("DP SOC is null");
  524. return QDF_STATUS_E_NULL_VALUE;
  525. }
  526. if (!soc->features.umac_hw_reset_support) {
  527. dp_umac_reset_info("Target doesn't support the UMAC HW reset feature");
  528. return QDF_STATUS_SUCCESS;
  529. }
  530. return hif_unregister_umac_reset_handler(soc->hif_handle);
  531. }
  532. QDF_STATUS dp_umac_reset_register_rx_action_callback(
  533. struct dp_soc *soc,
  534. QDF_STATUS (*handler)(struct dp_soc *soc),
  535. enum umac_reset_action action)
  536. {
  537. struct dp_soc_umac_reset_ctx *umac_reset_ctx;
  538. if (!soc) {
  539. dp_umac_reset_err("DP SOC is null");
  540. return QDF_STATUS_E_NULL_VALUE;
  541. }
  542. if (!soc->features.umac_hw_reset_support) {
  543. dp_umac_reset_info("Target doesn't support UMAC HW reset");
  544. return QDF_STATUS_E_NOSUPPORT;
  545. }
  546. if (action >= UMAC_RESET_ACTION_MAX) {
  547. dp_umac_reset_err("invalid action: %d", action);
  548. return QDF_STATUS_E_INVAL;
  549. }
  550. umac_reset_ctx = &soc->umac_reset_ctx;
  551. umac_reset_ctx->rx_actions.cb[action] = handler;
  552. return QDF_STATUS_SUCCESS;
  553. }
  554. /**
  555. * dp_umac_reset_post_tx_cmd_via_shmem() - Post Tx command using shared memory
  556. * @soc: DP soc object
  557. * @ctxt: Tx command to be posted
  558. * @chip_id: Chip id of the mlo soc
  559. *
  560. * Return: None
  561. */
  562. void
  563. dp_umac_reset_post_tx_cmd_via_shmem(struct dp_soc *soc, void *ctxt, int chip_id)
  564. {
  565. enum umac_reset_tx_cmd tx_cmd = *((enum umac_reset_tx_cmd *)ctxt);
  566. htt_umac_hang_recovery_msg_shmem_t *shmem_vaddr;
  567. struct dp_soc_umac_reset_ctx *umac_reset_ctx = &soc->umac_reset_ctx;
  568. bool initiator;
  569. QDF_STATUS status;
  570. if (dp_umac_reset_is_soc_ignored(soc)) {
  571. dp_umac_reset_debug("Skipping soc (chip id %d)", chip_id);
  572. return;
  573. }
  574. shmem_vaddr = umac_reset_ctx->shmem_vaddr_aligned;
  575. if (!shmem_vaddr) {
  576. dp_umac_reset_err("Shared memory address is NULL");
  577. return;
  578. }
  579. dp_umac_reset_debug("Sending txcmd %u for chip id %u", tx_cmd, chip_id);
  580. switch (tx_cmd) {
  581. case UMAC_RESET_TX_CMD_TRIGGER_DONE:
  582. /* Send htt message to the partner soc */
  583. initiator = dp_umac_reset_initiator_check(soc);
  584. if (!initiator)
  585. umac_reset_ctx->current_state =
  586. UMAC_RESET_STATE_WAIT_FOR_DO_PRE_RESET;
  587. status = dp_htt_umac_reset_send_start_pre_reset_cmd(soc,
  588. initiator,
  589. !dp_umac_reset_target_recovery_check(soc));
  590. if (status != QDF_STATUS_SUCCESS) {
  591. dp_umac_reset_err("Unable to send Umac trigger");
  592. qdf_assert_always(0);
  593. } else {
  594. dp_umac_reset_debug("Sent trigger for soc (chip_id %d)",
  595. chip_id);
  596. }
  597. umac_reset_ctx->ts.trigger_done = qdf_get_log_timestamp_usecs();
  598. break;
  599. case UMAC_RESET_TX_CMD_PRE_RESET_DONE:
  600. HTT_UMAC_HANG_RECOVERY_MSG_SHMEM_PRE_RESET_DONE_SET(
  601. shmem_vaddr->h2t_msg, 1);
  602. umac_reset_ctx->ts.pre_reset_done =
  603. qdf_get_log_timestamp_usecs();
  604. break;
  605. case UMAC_RESET_TX_CMD_POST_RESET_START_DONE:
  606. HTT_UMAC_HANG_RECOVERY_MSG_SHMEM_POST_RESET_START_DONE_SET(
  607. shmem_vaddr->h2t_msg, 1);
  608. umac_reset_ctx->ts.post_reset_done =
  609. qdf_get_log_timestamp_usecs();
  610. break;
  611. case UMAC_RESET_TX_CMD_POST_RESET_COMPLETE_DONE:
  612. HTT_UMAC_HANG_RECOVERY_MSG_SHMEM_POST_RESET_COMPLETE_DONE_SET(
  613. shmem_vaddr->h2t_msg, 1);
  614. umac_reset_ctx->ts.post_reset_complete_done =
  615. qdf_get_log_timestamp_usecs();
  616. break;
  617. default:
  618. dp_umac_reset_err("Invalid tx cmd: %d", tx_cmd);
  619. return;
  620. }
  621. return;
  622. }
  623. /**
  624. * dp_umac_reset_notify_target() - Notify the target about completion of action.
  625. * @umac_reset_ctx: UMAC reset context
  626. *
  627. * This API figures out the Tx command that needs to be posted based on the
  628. * current state in the state machine. Also, updates the state machine once the
  629. * Tx command has been posted.
  630. *
  631. * Return: QDF status of operation
  632. */
  633. static QDF_STATUS
  634. dp_umac_reset_notify_target(struct dp_soc_umac_reset_ctx *umac_reset_ctx)
  635. {
  636. enum umac_reset_state next_state;
  637. enum umac_reset_tx_cmd tx_cmd;
  638. QDF_STATUS status;
  639. switch (umac_reset_ctx->current_state) {
  640. case UMAC_RESET_STATE_HOST_TRIGGER_DONE:
  641. tx_cmd = UMAC_RESET_TX_CMD_TRIGGER_DONE;
  642. next_state = UMAC_RESET_STATE_WAIT_FOR_DO_PRE_RESET;
  643. break;
  644. case UMAC_RESET_STATE_HOST_PRE_RESET_DONE:
  645. tx_cmd = UMAC_RESET_TX_CMD_PRE_RESET_DONE;
  646. next_state = UMAC_RESET_STATE_WAIT_FOR_DO_POST_RESET_START;
  647. break;
  648. case UMAC_RESET_STATE_HOST_POST_RESET_START_DONE:
  649. tx_cmd = UMAC_RESET_TX_CMD_POST_RESET_START_DONE;
  650. next_state = UMAC_RESET_STATE_WAIT_FOR_DO_POST_RESET_COMPLETE;
  651. break;
  652. case UMAC_RESET_STATE_HOST_POST_RESET_COMPLETE_DONE:
  653. tx_cmd = UMAC_RESET_TX_CMD_POST_RESET_COMPLETE_DONE;
  654. next_state = UMAC_RESET_STATE_WAIT_FOR_TRIGGER;
  655. break;
  656. default:
  657. dp_umac_reset_err("Invalid state(%d) during Tx",
  658. umac_reset_ctx->current_state);
  659. qdf_assert_always(0);
  660. return QDF_STATUS_E_FAILURE;
  661. }
  662. /*
  663. * Update the state machine before sending the command to firmware
  664. * as we might get the response from firmware even before the state
  665. * is updated.
  666. */
  667. umac_reset_ctx->current_state = next_state;
  668. status = dp_umac_reset_post_tx_cmd(umac_reset_ctx, tx_cmd);
  669. if (QDF_IS_STATUS_ERROR(status)) {
  670. dp_umac_reset_err("Couldn't post Tx cmd");
  671. qdf_assert_always(0);
  672. return status;
  673. }
  674. return status;
  675. }
  676. /**
  677. * dp_umac_reset_notify_completion() - Notify that a given action has been
  678. * completed
  679. * @soc: DP soc object
  680. * @next_state: The state to which the state machine needs to be updated due to
  681. * this completion
  682. *
  683. * Return: QDF status of operation
  684. */
  685. static QDF_STATUS dp_umac_reset_notify_completion(
  686. struct dp_soc *soc,
  687. enum umac_reset_state next_state)
  688. {
  689. struct dp_soc_umac_reset_ctx *umac_reset_ctx;
  690. if (!soc) {
  691. dp_umac_reset_err("DP SOC is null");
  692. return QDF_STATUS_E_NULL_VALUE;
  693. }
  694. umac_reset_ctx = &soc->umac_reset_ctx;
  695. /* Update the state first */
  696. umac_reset_ctx->current_state = next_state;
  697. return dp_umac_reset_notify_target(umac_reset_ctx);
  698. }
  699. static void dp_umac_wait_for_quiescent_state(struct dp_soc *soc)
  700. {
  701. enum umac_reset_state current_state;
  702. do {
  703. msleep(10);
  704. barrier();
  705. current_state = soc->umac_reset_ctx.current_state;
  706. } while ((current_state == UMAC_RESET_STATE_DO_TRIGGER_RECEIVED) ||
  707. (current_state == UMAC_RESET_STATE_DO_PRE_RESET_RECEIVED) ||
  708. (current_state == UMAC_RESET_STATE_DO_POST_RESET_START_RECEIVED) ||
  709. (current_state == UMAC_RESET_STATE_DO_POST_RESET_COMPLETE_RECEIVED));
  710. }
  711. QDF_STATUS dp_umac_reset_notify_action_completion(
  712. struct dp_soc *soc,
  713. enum umac_reset_action action)
  714. {
  715. enum umac_reset_state next_state;
  716. if (!soc) {
  717. dp_umac_reset_err("DP SOC is null");
  718. return QDF_STATUS_E_NULL_VALUE;
  719. }
  720. if (!soc->features.umac_hw_reset_support) {
  721. dp_umac_reset_info("Target doesn't support the UMAC HW reset feature");
  722. return QDF_STATUS_E_NOSUPPORT;
  723. }
  724. switch (action) {
  725. case UMAC_RESET_ACTION_DO_TRIGGER_RECOVERY:
  726. next_state = UMAC_RESET_STATE_HOST_TRIGGER_DONE;
  727. break;
  728. case UMAC_RESET_ACTION_DO_PRE_RESET:
  729. next_state = UMAC_RESET_STATE_HOST_PRE_RESET_DONE;
  730. break;
  731. case UMAC_RESET_ACTION_DO_POST_RESET_START:
  732. next_state = UMAC_RESET_STATE_HOST_POST_RESET_START_DONE;
  733. break;
  734. case UMAC_RESET_ACTION_DO_POST_RESET_COMPLETE:
  735. next_state = UMAC_RESET_STATE_HOST_POST_RESET_COMPLETE_DONE;
  736. break;
  737. case UMAC_RESET_ACTION_ABORT:
  738. next_state = UMAC_RESET_STATE_WAIT_FOR_TRIGGER;
  739. break;
  740. default:
  741. dp_umac_reset_err("Invalid action: %u", action);
  742. return QDF_STATUS_E_FAILURE;
  743. }
  744. return dp_umac_reset_notify_completion(soc, next_state);
  745. }
  746. /**
  747. * dp_soc_umac_reset_deinit() - Deinitialize the umac reset module
  748. * @txrx_soc: DP soc object
  749. *
  750. * Return: QDF status of operation
  751. */
  752. QDF_STATUS dp_soc_umac_reset_deinit(struct cdp_soc_t *txrx_soc)
  753. {
  754. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  755. struct dp_soc_umac_reset_ctx *umac_reset_ctx;
  756. qdf_nbuf_t nbuf_list;
  757. if (!soc) {
  758. dp_umac_reset_err("DP SOC is null");
  759. return QDF_STATUS_E_NULL_VALUE;
  760. }
  761. if (!soc->features.umac_hw_reset_support) {
  762. dp_umac_reset_info("No target support for UMAC reset feature");
  763. return QDF_STATUS_E_NOSUPPORT;
  764. }
  765. if (dp_check_umac_reset_in_progress(soc)) {
  766. dp_umac_reset_info("Cleaning up Umac reset context");
  767. dp_umac_wait_for_quiescent_state(soc);
  768. dp_resume_reo_send_cmd(soc);
  769. dp_umac_reset_notify_action_completion(soc,
  770. UMAC_RESET_ACTION_ABORT);
  771. }
  772. nbuf_list = soc->umac_reset_ctx.nbuf_list;
  773. soc->umac_reset_ctx.nbuf_list = NULL;
  774. while (nbuf_list) {
  775. qdf_nbuf_t nbuf = nbuf_list->next;
  776. qdf_nbuf_free(nbuf_list);
  777. nbuf_list = nbuf;
  778. }
  779. dp_umac_reset_interrupt_detach(soc);
  780. umac_reset_ctx = &soc->umac_reset_ctx;
  781. qdf_mem_free_consistent(soc->osdev, soc->osdev->dev,
  782. umac_reset_ctx->shmem_size,
  783. umac_reset_ctx->shmem_vaddr_unaligned,
  784. umac_reset_ctx->shmem_paddr_unaligned,
  785. 0);
  786. return QDF_STATUS_SUCCESS;
  787. }
  788. static inline const char *dp_umac_reset_current_state_to_str(
  789. enum umac_reset_state current_state)
  790. {
  791. switch (current_state) {
  792. case UMAC_RESET_STATE_WAIT_FOR_TRIGGER:
  793. return "UMAC_RESET_STATE_WAIT_FOR_TRIGGER";
  794. case UMAC_RESET_STATE_DO_TRIGGER_RECEIVED:
  795. return "UMAC_RESET_STATE_DO_TRIGGER_RECEIVED";
  796. case UMAC_RESET_STATE_HOST_TRIGGER_DONE:
  797. return "UMAC_RESET_STATE_HOST_TRIGGER_DONE";
  798. case UMAC_RESET_STATE_WAIT_FOR_DO_PRE_RESET:
  799. return "UMAC_RESET_STATE_WAIT_FOR_DO_PRE_RESET";
  800. case UMAC_RESET_STATE_DO_PRE_RESET_RECEIVED:
  801. return "UMAC_RESET_STATE_DO_PRE_RESET_RECEIVED";
  802. case UMAC_RESET_STATE_HOST_PRE_RESET_DONE:
  803. return "UMAC_RESET_STATE_HOST_PRE_RESET_DONE";
  804. case UMAC_RESET_STATE_WAIT_FOR_DO_POST_RESET_START:
  805. return "UMAC_RESET_STATE_WAIT_FOR_DO_POST_RESET_START";
  806. case UMAC_RESET_STATE_DO_POST_RESET_START_RECEIVED:
  807. return "UMAC_RESET_STATE_DO_POST_RESET_START_RECEIVED";
  808. case UMAC_RESET_STATE_HOST_POST_RESET_START_DONE:
  809. return "UMAC_RESET_STATE_HOST_POST_RESET_START_DONE";
  810. case UMAC_RESET_STATE_WAIT_FOR_DO_POST_RESET_COMPLETE:
  811. return "UMAC_RESET_STATE_WAIT_FOR_DO_POST_RESET_COMPLETE";
  812. case UMAC_RESET_STATE_DO_POST_RESET_COMPLETE_RECEIVED:
  813. return "UMAC_RESET_STATE_DO_POST_RESET_COMPLETE_RECEIVED";
  814. case UMAC_RESET_STATE_HOST_POST_RESET_COMPLETE_DONE:
  815. return "UMAC_RESET_STATE_HOST_POST_RESET_COMPLETE_DONE";
  816. default:
  817. return "Invalid UMAC Reset state";
  818. }
  819. }
  820. static inline const char *dp_umac_reset_pending_action_to_str(
  821. enum umac_reset_rx_event pending_action)
  822. {
  823. switch (pending_action) {
  824. case UMAC_RESET_RX_EVENT_NONE:
  825. return "UMAC_RESET_RX_EVENT_NONE";
  826. case UMAC_RESET_RX_EVENT_DO_TRIGGER_RECOVERY:
  827. return "UMAC_RESET_RX_EVENT_DO_TRIGGER_RECOVERY";
  828. case UMAC_RESET_RX_EVENT_DO_TRIGGER_TR_SYNC:
  829. return "UMAC_RESET_RX_EVENT_DO_TRIGGER_TR_SYNC";
  830. case UMAC_RESET_RX_EVENT_DO_PRE_RESET:
  831. return "UMAC_RESET_RX_EVENT_DO_PRE_RESET";
  832. case UMAC_RESET_RX_EVENT_DO_POST_RESET_START:
  833. return "UMAC_RESET_RX_EVENT_DO_POST_RESET_START";
  834. case UMAC_RESET_RX_EVENT_DO_POST_RESET_COMPELTE:
  835. return "UMAC_RESET_RX_EVENT_DO_POST_RESET_COMPELTE";
  836. default:
  837. return "Invalid pending action";
  838. }
  839. }
  840. QDF_STATUS dp_umac_reset_stats_print(struct dp_soc *soc)
  841. {
  842. struct dp_soc_umac_reset_ctx *umac_reset_ctx;
  843. umac_reset_ctx = &soc->umac_reset_ctx;
  844. DP_UMAC_RESET_PRINT_STATS("UMAC reset stats for soc:%pK\n"
  845. "\t\ttrigger time :%u us\n"
  846. "\t\tPre_reset time :%u us\n"
  847. "\t\tPost_reset time :%u us\n"
  848. "\t\tPost_reset_complete time :%u us\n"
  849. "\t\tCurrent state :%s\n"
  850. "\t\tPending action :%s",
  851. soc,
  852. umac_reset_ctx->ts.trigger_done -
  853. umac_reset_ctx->ts.trigger_start,
  854. umac_reset_ctx->ts.pre_reset_done -
  855. umac_reset_ctx->ts.pre_reset_start,
  856. umac_reset_ctx->ts.post_reset_done -
  857. umac_reset_ctx->ts.post_reset_start,
  858. umac_reset_ctx->ts.post_reset_complete_done -
  859. umac_reset_ctx->ts.post_reset_complete_start,
  860. dp_umac_reset_current_state_to_str(
  861. umac_reset_ctx->current_state),
  862. dp_umac_reset_pending_action_to_str(
  863. umac_reset_ctx->pending_action));
  864. return dp_mlo_umac_reset_stats_print(soc);
  865. }