dp_umac_reset.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * Copyright (c) 2022 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_types.h>
  17. #include <wlan_cfg.h>
  18. #include <hif.h>
  19. /**
  20. * dp_get_umac_reset_intr_ctx() - Get the interrupt context to be used by
  21. * UMAC reset feature
  22. * @soc: DP soc object
  23. * @intr_ctx: Interrupt context variable to be populated by this API
  24. *
  25. * Return: QDF_STATUS of operation
  26. */
  27. static QDF_STATUS dp_get_umac_reset_intr_ctx(struct dp_soc *soc, int *intr_ctx)
  28. {
  29. int umac_reset_mask, i;
  30. /**
  31. * Go over all the contexts and check which interrupt context has
  32. * the UMAC reset mask set.
  33. */
  34. for (i = 0; i < wlan_cfg_get_num_contexts(soc->wlan_cfg_ctx); i++) {
  35. umac_reset_mask = wlan_cfg_get_umac_reset_intr_mask(
  36. soc->wlan_cfg_ctx, i);
  37. if (umac_reset_mask) {
  38. *intr_ctx = i;
  39. return QDF_STATUS_SUCCESS;
  40. }
  41. }
  42. *intr_ctx = -1;
  43. return QDF_STATUS_E_FAILURE;
  44. }
  45. QDF_STATUS dp_soc_umac_reset_init(struct dp_soc *soc)
  46. {
  47. struct dp_soc_umac_reset_ctx *umac_reset_ctx;
  48. size_t alloc_size;
  49. QDF_STATUS status;
  50. if (!soc) {
  51. dp_umac_reset_err("DP SOC is null");
  52. return QDF_STATUS_E_NULL_VALUE;
  53. }
  54. umac_reset_ctx = &soc->umac_reset_ctx;
  55. qdf_mem_zero(umac_reset_ctx, sizeof(*umac_reset_ctx));
  56. umac_reset_ctx->supported = true;
  57. umac_reset_ctx->current_state = UMAC_RESET_STATE_WAIT_FOR_PRE_RESET;
  58. status = dp_get_umac_reset_intr_ctx(soc, &umac_reset_ctx->intr_offset);
  59. if (QDF_IS_STATUS_ERROR(status)) {
  60. dp_umac_reset_err("No interrupt assignment");
  61. return status;
  62. }
  63. alloc_size = sizeof(struct umac_reset_shmem) +
  64. DP_UMAC_RESET_SHMEM_ALIGN - 1;
  65. umac_reset_ctx->shmem_vaddr_unaligned =
  66. qdf_mem_alloc_consistent(soc->osdev, soc->osdev->dev,
  67. alloc_size,
  68. &umac_reset_ctx->shmem_paddr_unaligned);
  69. if (!umac_reset_ctx->shmem_vaddr_unaligned) {
  70. dp_umac_reset_err("shmem allocation failed");
  71. return QDF_STATUS_E_NOMEM;
  72. }
  73. umac_reset_ctx->shmem_vaddr_aligned = (void *)(uintptr_t)qdf_roundup(
  74. (uint64_t)(uintptr_t)umac_reset_ctx->shmem_vaddr_unaligned,
  75. DP_UMAC_RESET_SHMEM_ALIGN);
  76. umac_reset_ctx->shmem_paddr_aligned = qdf_roundup(
  77. (uint64_t)umac_reset_ctx->shmem_paddr_unaligned,
  78. DP_UMAC_RESET_SHMEM_ALIGN);
  79. return QDF_STATUS_SUCCESS;
  80. }
  81. /**
  82. * dp_umac_reset_rx_event_handler() - Main Rx event handler for UMAC reset
  83. * @dp_ctx: Interrupt context corresponding to UMAC reset
  84. *
  85. * Return: 0 incase of success, else failure
  86. */
  87. static int dp_umac_reset_rx_event_handler(void *dp_ctx)
  88. {
  89. /* Note: This will be implemented in an upcoming change */
  90. return 0;
  91. }
  92. QDF_STATUS dp_umac_reset_interrupt_attach(struct dp_soc *soc)
  93. {
  94. struct dp_soc_umac_reset_ctx *umac_reset_ctx;
  95. int msi_vector_count, ret;
  96. uint32_t msi_base_data, msi_vector_start;
  97. uint32_t umac_reset_vector, umac_reset_irq;
  98. if (!soc) {
  99. dp_umac_reset_err("DP SOC is null");
  100. return QDF_STATUS_E_NULL_VALUE;
  101. }
  102. umac_reset_ctx = &soc->umac_reset_ctx;
  103. /* return if feature is not supported */
  104. if (!umac_reset_ctx->supported) {
  105. dp_umac_reset_info("UMAC reset is not supported on this SOC");
  106. return QDF_STATUS_SUCCESS;
  107. }
  108. if (pld_get_enable_intx(soc->osdev->dev)) {
  109. dp_umac_reset_err("UMAC reset is not supported in legacy interrupt mode");
  110. return QDF_STATUS_E_FAILURE;
  111. }
  112. ret = pld_get_user_msi_assignment(soc->osdev->dev, "DP",
  113. &msi_vector_count, &msi_base_data,
  114. &msi_vector_start);
  115. if (ret) {
  116. dp_umac_reset_err("UMAC reset is only supported in MSI interrupt mode");
  117. return QDF_STATUS_E_FAILURE;
  118. }
  119. if (umac_reset_ctx->intr_offset < 0 ||
  120. umac_reset_ctx->intr_offset >= WLAN_CFG_INT_NUM_CONTEXTS) {
  121. dp_umac_reset_err("Invalid interrupt offset");
  122. return QDF_STATUS_E_FAILURE;
  123. }
  124. umac_reset_vector = msi_vector_start +
  125. (umac_reset_ctx->intr_offset % msi_vector_count);
  126. /* Get IRQ number */
  127. umac_reset_irq = pld_get_msi_irq(soc->osdev->dev, umac_reset_vector);
  128. /* Finally register to this IRQ from HIF layer */
  129. return hif_register_umac_reset_handler(
  130. soc->hif_handle,
  131. dp_umac_reset_rx_event_handler,
  132. &soc->intr_ctx[umac_reset_ctx->intr_offset],
  133. umac_reset_irq);
  134. }
  135. QDF_STATUS dp_umac_reset_interrupt_detach(struct dp_soc *soc)
  136. {
  137. struct dp_soc_umac_reset_ctx *umac_reset_ctx;
  138. if (!soc) {
  139. dp_umac_reset_err("DP SOC is null");
  140. return QDF_STATUS_E_NULL_VALUE;
  141. }
  142. umac_reset_ctx = &soc->umac_reset_ctx;
  143. /* return if feature is not supported */
  144. if (!umac_reset_ctx->supported) {
  145. dp_umac_reset_info("UMAC reset is not supported on this SOC");
  146. return QDF_STATUS_SUCCESS;
  147. }
  148. return hif_unregister_umac_reset_handler(soc->hif_handle);
  149. }