htc_credit_history.c 6.7 KB

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