htc_credit_history.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. * Copyright (c) 2018,2020 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. uint32_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. #ifdef QCA_WIFI_NAPIER_EMULATION
  40. #define HTC_EMULATION_DELAY_IN_MS 20
  41. /**
  42. * htc_add_delay(): Adds a delay in before proceeding, only for emulation
  43. *
  44. * Return: None
  45. */
  46. static inline void htc_add_emulation_delay(void)
  47. {
  48. qdf_mdelay(HTC_EMULATION_DELAY_IN_MS);
  49. }
  50. #else
  51. static inline void htc_add_emulation_delay(void)
  52. {
  53. }
  54. #endif
  55. void htc_credit_history_init(void)
  56. {
  57. qdf_spinlock_create(&g_htc_credit_lock);
  58. g_htc_credit_history_idx = 0;
  59. g_htc_credit_history_length = 0;
  60. }
  61. /**
  62. * htc_credit_record() - records tx que state & credit transactions
  63. * @type: type of echange can be HTC_REQUEST_CREDIT
  64. * or HTC_PROCESS_CREDIT_REPORT
  65. * @tx_credits: current number of tx_credits
  66. * @htc_tx_queue_depth: current hct tx queue depth
  67. *
  68. * This function records the credits and pending commands whenever a command is
  69. * sent or credits are returned. Call this after the credits have been updated
  70. * according to the transaction. Call this before dequeing commands.
  71. *
  72. * Consider making this function accept an HTC_ENDPOINT and find the current
  73. * credits and queue depth itself.
  74. *
  75. */
  76. void htc_credit_record(enum htc_credit_exchange_type type, uint32_t tx_credit,
  77. uint32_t htc_tx_queue_depth)
  78. {
  79. qdf_spin_lock_bh(&g_htc_credit_lock);
  80. if (g_htc_credit_history_idx >= HTC_CREDIT_HISTORY_MAX)
  81. g_htc_credit_history_idx = 0;
  82. htc_credit_history_buffer[g_htc_credit_history_idx].type = type;
  83. htc_credit_history_buffer[g_htc_credit_history_idx].time =
  84. qdf_get_log_timestamp();
  85. htc_credit_history_buffer[g_htc_credit_history_idx].tx_credit =
  86. tx_credit;
  87. htc_credit_history_buffer[g_htc_credit_history_idx].htc_tx_queue_depth =
  88. htc_tx_queue_depth;
  89. g_htc_credit_history_idx++;
  90. g_htc_credit_history_length++;
  91. htc_add_emulation_delay();
  92. qdf_spin_unlock_bh(&g_htc_credit_lock);
  93. }
  94. void htc_print_credit_history(HTC_HANDLE htc, uint32_t count,
  95. qdf_abstract_print *print, void *print_priv)
  96. {
  97. uint32_t idx;
  98. print(print_priv, "HTC Credit History (count %u)", count);
  99. qdf_spin_lock_bh(&g_htc_credit_lock);
  100. if (count > HTC_CREDIT_HISTORY_MAX)
  101. count = HTC_CREDIT_HISTORY_MAX;
  102. if (count > g_htc_credit_history_length)
  103. count = g_htc_credit_history_length;
  104. /* subtract count from index, and wrap if necessary */
  105. idx = HTC_CREDIT_HISTORY_MAX + g_htc_credit_history_idx - count;
  106. idx %= HTC_CREDIT_HISTORY_MAX;
  107. print(print_priv,
  108. "Time (seconds) Type Credits Queue Depth");
  109. while (count) {
  110. struct HTC_CREDIT_HISTORY *hist =
  111. &htc_credit_history_buffer[idx];
  112. uint64_t secs, usecs;
  113. qdf_log_timestamp_to_secs(hist->time, &secs, &usecs);
  114. print(print_priv, "% 8lld.%06lld %-25s %-7.d %d",
  115. secs,
  116. usecs,
  117. htc_credit_exchange_type_str(hist->type),
  118. hist->tx_credit,
  119. hist->htc_tx_queue_depth);
  120. --count;
  121. ++idx;
  122. if (idx >= HTC_CREDIT_HISTORY_MAX)
  123. idx = 0;
  124. }
  125. qdf_spin_unlock_bh(&g_htc_credit_lock);
  126. }
  127. #ifdef WLAN_HANG_EVENT
  128. void htc_log_hang_credit_history(struct notifier_block *block, void *data)
  129. {
  130. qdf_notif_block *notif_block = qdf_container_of(block, qdf_notif_block,
  131. notif_block);
  132. struct qdf_notifer_data *htc_hang_data = data;
  133. uint32_t count = 3, idx, total_len;
  134. HTC_HANDLE htc;
  135. struct htc_hang_data_fixed_param *cmd;
  136. uint8_t *htc_buf_ptr;
  137. htc = notif_block->priv_data;
  138. if (!htc)
  139. return;
  140. if (!htc_hang_data)
  141. return;
  142. if (htc_hang_data->offset >= QDF_WLAN_MAX_HOST_OFFSET)
  143. return;
  144. total_len = sizeof(struct htc_hang_data_fixed_param);
  145. qdf_spin_lock_bh(&g_htc_credit_lock);
  146. if (count > HTC_CREDIT_HISTORY_MAX)
  147. count = HTC_CREDIT_HISTORY_MAX;
  148. if (count > g_htc_credit_history_length)
  149. count = g_htc_credit_history_length;
  150. idx = HTC_CREDIT_HISTORY_MAX + g_htc_credit_history_idx - count;
  151. idx %= HTC_CREDIT_HISTORY_MAX;
  152. qdf_spin_unlock_bh(&g_htc_credit_lock);
  153. while (count) {
  154. struct HTC_CREDIT_HISTORY *hist =
  155. &htc_credit_history_buffer[idx];
  156. htc_buf_ptr = htc_hang_data->hang_data + htc_hang_data->offset;
  157. cmd = (struct htc_hang_data_fixed_param *)htc_buf_ptr;
  158. QDF_HANG_EVT_SET_HDR(&cmd->tlv_header,
  159. HANG_EVT_TAG_HTC_CREDIT_HIST,
  160. QDF_HANG_GET_STRUCT_TLVLEN(struct htc_hang_data_fixed_param));
  161. qdf_mem_copy(&cmd->credit_hist, hist, sizeof(*hist));
  162. --count;
  163. ++idx;
  164. if (idx >= HTC_CREDIT_HISTORY_MAX)
  165. idx = 0;
  166. htc_hang_data->offset += total_len;
  167. }
  168. }
  169. #endif