dp_umac_reset.c 29 KB

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