htc_credit_history.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /*
  2. * Copyright (c) 2018,2020-2021 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for
  5. * any purpose with or without fee is hereby granted, provided that the
  6. * above copyright notice and this permission notice appear in all
  7. * copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  10. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  11. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  12. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  14. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. * PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. #include "htc_debug.h"
  19. #include "htc_internal.h"
  20. #include "htc_credit_history.h"
  21. #include <qdf_lock.h>
  22. #include <qdf_hang_event_notifier.h>
  23. #include <qdf_notifier.h>
  24. struct HTC_CREDIT_HISTORY {
  25. enum htc_credit_exchange_type type;
  26. uint64_t time;
  27. uint32_t tx_credit;
  28. uint32_t htc_tx_queue_depth;
  29. };
  30. struct htc_hang_data_fixed_param {
  31. uint16_t tlv_header;
  32. struct HTC_CREDIT_HISTORY credit_hist;
  33. } qdf_packed;
  34. static qdf_spinlock_t g_htc_credit_lock;
  35. static uint32_t g_htc_credit_history_idx;
  36. static uint32_t g_htc_credit_history_length;
  37. static
  38. struct HTC_CREDIT_HISTORY htc_credit_history_buffer[HTC_CREDIT_HISTORY_MAX];
  39. #define NUM_HANG_CREDIT_HISTORY 1
  40. #ifdef QCA_WIFI_EMULATION
  41. #define HTC_EMULATION_DELAY_IN_MS 20
  42. /**
  43. * htc_add_delay(): Adds a delay in before proceeding, only for emulation
  44. *
  45. * Return: None
  46. */
  47. static inline void htc_add_emulation_delay(void)
  48. {
  49. qdf_mdelay(HTC_EMULATION_DELAY_IN_MS);
  50. }
  51. #else
  52. static inline void htc_add_emulation_delay(void)
  53. {
  54. }
  55. #endif
  56. void htc_credit_history_deinit(void)
  57. {
  58. qdf_minidump_remove(&htc_credit_history_buffer,
  59. sizeof(htc_credit_history_buffer), "htc_credit");
  60. }
  61. void htc_credit_history_init(void)
  62. {
  63. qdf_spinlock_create(&g_htc_credit_lock);
  64. g_htc_credit_history_idx = 0;
  65. g_htc_credit_history_length = 0;
  66. qdf_minidump_log(&htc_credit_history_buffer,
  67. sizeof(htc_credit_history_buffer), "htc_credit");
  68. }
  69. /**
  70. * htc_credit_record() - records tx que state & credit transactions
  71. * @type: type of echange can be HTC_REQUEST_CREDIT
  72. * or HTC_PROCESS_CREDIT_REPORT
  73. * @tx_credits: current number of tx_credits
  74. * @htc_tx_queue_depth: current hct tx queue depth
  75. *
  76. * This function records the credits and pending commands whenever a command is
  77. * sent or credits are returned. Call this after the credits have been updated
  78. * according to the transaction. Call this before dequeing commands.
  79. *
  80. * Consider making this function accept an HTC_ENDPOINT and find the current
  81. * credits and queue depth itself.
  82. *
  83. */
  84. void htc_credit_record(enum htc_credit_exchange_type type, uint32_t tx_credit,
  85. uint32_t htc_tx_queue_depth)
  86. {
  87. qdf_spin_lock_bh(&g_htc_credit_lock);
  88. if (g_htc_credit_history_idx >= HTC_CREDIT_HISTORY_MAX)
  89. g_htc_credit_history_idx = 0;
  90. htc_credit_history_buffer[g_htc_credit_history_idx].type = type;
  91. htc_credit_history_buffer[g_htc_credit_history_idx].time =
  92. qdf_get_log_timestamp();
  93. htc_credit_history_buffer[g_htc_credit_history_idx].tx_credit =
  94. tx_credit;
  95. htc_credit_history_buffer[g_htc_credit_history_idx].htc_tx_queue_depth =
  96. htc_tx_queue_depth;
  97. g_htc_credit_history_idx++;
  98. g_htc_credit_history_length++;
  99. htc_add_emulation_delay();
  100. qdf_spin_unlock_bh(&g_htc_credit_lock);
  101. }
  102. void htc_print_credit_history(HTC_HANDLE htc, uint32_t count,
  103. qdf_abstract_print *print, void *print_priv)
  104. {
  105. uint32_t idx;
  106. print(print_priv, "HTC Credit History (count %u)", count);
  107. qdf_spin_lock_bh(&g_htc_credit_lock);
  108. if (count > HTC_CREDIT_HISTORY_MAX)
  109. count = HTC_CREDIT_HISTORY_MAX;
  110. if (count > g_htc_credit_history_length)
  111. count = g_htc_credit_history_length;
  112. /* subtract count from index, and wrap if necessary */
  113. idx = HTC_CREDIT_HISTORY_MAX + g_htc_credit_history_idx - count;
  114. idx %= HTC_CREDIT_HISTORY_MAX;
  115. print(print_priv,
  116. "Time (seconds) Type Credits Queue Depth");
  117. while (count) {
  118. struct HTC_CREDIT_HISTORY *hist =
  119. &htc_credit_history_buffer[idx];
  120. uint64_t secs, usecs;
  121. qdf_log_timestamp_to_secs(hist->time, &secs, &usecs);
  122. print(print_priv, "% 8lld.%06lld %-25s %-7.d %d",
  123. secs,
  124. usecs,
  125. htc_credit_exchange_type_str(hist->type),
  126. hist->tx_credit,
  127. hist->htc_tx_queue_depth);
  128. --count;
  129. ++idx;
  130. if (idx >= HTC_CREDIT_HISTORY_MAX)
  131. idx = 0;
  132. }
  133. qdf_spin_unlock_bh(&g_htc_credit_lock);
  134. }
  135. #ifdef WLAN_HANG_EVENT
  136. void htc_log_hang_credit_history(struct notifier_block *block, void *data)
  137. {
  138. qdf_notif_block *notif_block = qdf_container_of(block, qdf_notif_block,
  139. notif_block);
  140. struct qdf_notifer_data *htc_hang_data = data;
  141. uint32_t count = NUM_HANG_CREDIT_HISTORY, idx, total_len;
  142. HTC_HANDLE htc;
  143. struct htc_hang_data_fixed_param *cmd;
  144. uint8_t *htc_buf_ptr;
  145. htc = notif_block->priv_data;
  146. if (!htc)
  147. return;
  148. if (!htc_hang_data)
  149. return;
  150. total_len = sizeof(struct htc_hang_data_fixed_param);
  151. qdf_spin_lock_bh(&g_htc_credit_lock);
  152. if (count > HTC_CREDIT_HISTORY_MAX)
  153. count = HTC_CREDIT_HISTORY_MAX;
  154. if (count > g_htc_credit_history_length)
  155. count = g_htc_credit_history_length;
  156. idx = HTC_CREDIT_HISTORY_MAX + g_htc_credit_history_idx - count;
  157. idx %= HTC_CREDIT_HISTORY_MAX;
  158. qdf_spin_unlock_bh(&g_htc_credit_lock);
  159. while (count) {
  160. struct HTC_CREDIT_HISTORY *hist =
  161. &htc_credit_history_buffer[idx];
  162. htc_buf_ptr = htc_hang_data->hang_data + htc_hang_data->offset;
  163. cmd = (struct htc_hang_data_fixed_param *)htc_buf_ptr;
  164. if (htc_hang_data->offset + total_len > QDF_WLAN_HANG_FW_OFFSET)
  165. return;
  166. QDF_HANG_EVT_SET_HDR(&cmd->tlv_header,
  167. HANG_EVT_TAG_HTC_CREDIT_HIST,
  168. QDF_HANG_GET_STRUCT_TLVLEN(struct htc_hang_data_fixed_param));
  169. qdf_mem_copy(&cmd->credit_hist, hist, sizeof(*hist));
  170. --count;
  171. ++idx;
  172. if (idx >= HTC_CREDIT_HISTORY_MAX)
  173. idx = 0;
  174. htc_hang_data->offset += total_len;
  175. }
  176. }
  177. #endif