dp_htt_logger.c 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252
  1. /*
  2. * Copyright (c) 2019-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 <linux/debugfs.h>
  19. #include <linux/uaccess.h>
  20. #include "qdf_lock.h"
  21. #include "qdf_debugfs.h"
  22. #include "qdf_module.h"
  23. #include "qdf_list.h"
  24. #include "dp_htt_logger.h"
  25. #include "dp_types.h"
  26. #include "dp_internal.h"
  27. #define HTT_DBG_FILE_PERM (QDF_FILE_USR_READ | QDF_FILE_USR_WRITE | \
  28. QDF_FILE_GRP_READ | \
  29. QDF_FILE_OTH_READ)
  30. /**
  31. * HTT_DISPLAY_SIZE : Supported Number of command/event/wbm_event to be
  32. * read at one shot through wdf debugfs framework
  33. */
  34. #define HTT_DISPLAY_SIZE 25
  35. /**
  36. * Used for stop_seq
  37. * Bit 0: htt_command_log
  38. * Bit 1: htt_event_log
  39. * Bit 2: htt_wbm_event_log
  40. * Bit 3: htt_log_size
  41. * Bit 4: htt_enable
  42. * Bit 5: htt_cmd_disable_list
  43. * Bit 6: htt_event_disable_list
  44. * Bit 7: htt_wbm_event_disable_list
  45. * Bit 8-15: Reserved
  46. */
  47. #define HTT_COMMAND_LOG_BP 0
  48. #define HTT_EVENT_LOG_BP 1
  49. #define HTT_WBM_EVENT_LOG_BP 2
  50. #define HTT_LOG_SIZE_BP 3
  51. #define HTT_ENABLE_BP 4
  52. #define HTT_CMD_DISABLE_LIST_BP 5
  53. #define HTT_EVENT_DISABLE_LIST 6
  54. #define HTT_WBM_EVENT_DISABLE_LIST 7
  55. /**
  56. * Host messages which needs to be enabled by default
  57. *
  58. * Note: Below macro definition is cloned from
  59. * enum htt_t2h_msg_type fw_hdr/fw/htt.h and any
  60. * change in enum htt_t2h_msg_type for below field
  61. * will need a change here as well.
  62. */
  63. #define HTT_T2H_MSG_TYPE_PEER_MAP_C 0x3
  64. #define HTT_T2H_MSG_TYPE_PEER_UNMAP_C 0x4
  65. #define HTT_T2H_MSG_TYPE_RX_ADDBA_C 0x5
  66. #define HTT_T2H_MSG_TYPE_RX_DELBA_C 0x6
  67. #define HTT_T2H_MSG_TYPE_PEER_MAP_V2_C 0x1e
  68. #define HTT_T2H_MSG_TYPE_PEER_UNMAP_V2_C 0x1f
  69. /**
  70. * disable_all_command(): Disable all command
  71. * disable_all_event(): Disable all event
  72. * enable_event(): Enable specific event
  73. */
  74. #define disable_all_command(htt_logger_handle) \
  75. htt_logger_handle->log_info.htt_cmd_disable_list = 0xFFFFFFFFFFFFFFFF
  76. #define disable_all_event(htt_logger_handle)\
  77. htt_logger_handle->log_info.htt_event_disable_list = 0xFFFFFFFFFFFFFFFF
  78. #define disable_wbm_success_status(htt_logger_handle) \
  79. htt_logger_handle->log_info.htt_wbm_event_disable_list = 0x1
  80. #define enable_htt_logging(htt_logger_handle) \
  81. htt_logger_handle->log_info.htt_logging_enable = 1
  82. #define enable_event(htt_logger_handle, eventid) \
  83. do { \
  84. htt_disable_mask = ~(0x1 << eventid); \
  85. htt_logger_handle->log_info.htt_event_disable_list &= \
  86. htt_disable_mask; \
  87. } while (0)
  88. /**
  89. * log_buf_init() - Initialize htt buffer
  90. */
  91. static inline void log_buf_init(struct htt_log_buf_t *buf)
  92. {
  93. buf->length = 0;
  94. buf->buf_tail_idx = 0;
  95. buf->size = HTT_EVENT_DEBUG_MAX_ENTRY;
  96. }
  97. /**
  98. * htt_command_record() - Record Command
  99. * @ h - htt logger handle
  100. * @ msg_type - Command Id
  101. * @ msg_data - Data to be logged
  102. */
  103. int htt_command_record(struct htt_logger *h, uint8_t msg_type,
  104. uint8_t *msg_data)
  105. {
  106. struct htt_command_debug *buf = NULL;
  107. uint32_t *p_buf_tail_idx = NULL;
  108. uint8_t tdata[HTT_COMMAND_DEBUG_ENTRY_MAX_LENGTH];
  109. struct htt_log_buf_t *cmd_log_buf;
  110. /* return 0 if:
  111. * 1. Initialization failed.
  112. * 2. htt_logging_enable is 0 -> can get disable from file ops
  113. * 3. This specific msg_type is disabled
  114. */
  115. if (!h)
  116. return 0;
  117. cmd_log_buf = &h->log_info.htt_command_log_buf_info;
  118. if ((0 == h->log_info.htt_logging_enable) ||
  119. ((1 << msg_type) & h->log_info.htt_cmd_disable_list))
  120. return 0;
  121. qdf_spin_lock(&cmd_log_buf->record_lock);
  122. if (!msg_data) {
  123. /* if msg_data is NULL then fill 0xFF in data field */
  124. qdf_mem_set(tdata, HTT_COMMAND_DEBUG_ENTRY_MAX_LENGTH, 0xFF);
  125. msg_data = tdata;
  126. }
  127. p_buf_tail_idx = &h->log_info.htt_command_log_buf_info.buf_tail_idx;
  128. /* rewind pointer index if buffer became full */
  129. if (HTT_EVENT_DEBUG_MAX_ENTRY <= *p_buf_tail_idx)
  130. *p_buf_tail_idx = 0;
  131. buf = h->log_info.htt_command_log_buf_info.buf;
  132. buf[*p_buf_tail_idx].command = msg_type;
  133. qdf_mem_copy(buf[*p_buf_tail_idx].data, msg_data,
  134. HTT_COMMAND_DEBUG_ENTRY_MAX_LENGTH);
  135. buf[*p_buf_tail_idx].time = qdf_get_log_timestamp();
  136. buf[*p_buf_tail_idx].cpu_id = smp_processor_id();
  137. (*p_buf_tail_idx)++;
  138. h->log_info.htt_command_log_buf_info.length++;
  139. qdf_spin_unlock(&cmd_log_buf->record_lock);
  140. return 0;
  141. }
  142. /**
  143. * htt_event_record() - Record Event
  144. * @ h - htt logger handle
  145. * @ msg_type - Event Id
  146. * @ msg_data - Data to be logged
  147. */
  148. int htt_event_record(struct htt_logger *h, uint8_t msg_type, uint8_t *msg_data)
  149. {
  150. struct htt_event_debug *buf = NULL;
  151. uint32_t *p_buf_tail_idx = NULL;
  152. uint8_t tdata[HTT_EVENT_DEBUG_ENTRY_MAX_LENGTH];
  153. struct htt_log_buf_t *event_log_buf;
  154. /* return 0 if:
  155. * 1. Initialization failed.
  156. * 2. htt_logging_enable is 0 -> can get disable from file ops
  157. * 3. This specific msg_type is disabled
  158. */
  159. if (!h)
  160. return 0;
  161. event_log_buf = &h->log_info.htt_event_log_buf_info;
  162. if ((0 == h->log_info.htt_logging_enable) ||
  163. ((1 << msg_type) & h->log_info.htt_event_disable_list))
  164. return 0;
  165. qdf_spin_lock(&event_log_buf->record_lock);
  166. if (!msg_data) {
  167. /* if msg_data is NULL then fill 0xFF in data field */
  168. qdf_mem_set(tdata, HTT_EVENT_DEBUG_ENTRY_MAX_LENGTH, 0xFF);
  169. msg_data = tdata;
  170. }
  171. p_buf_tail_idx = &h->log_info.htt_event_log_buf_info.buf_tail_idx;
  172. /* rewind pointer index if buffer became full */
  173. if (HTT_EVENT_DEBUG_MAX_ENTRY <= *p_buf_tail_idx)
  174. *p_buf_tail_idx = 0;
  175. buf = h->log_info.htt_event_log_buf_info.buf;
  176. buf[*p_buf_tail_idx].event = msg_type;
  177. qdf_mem_copy(buf[*p_buf_tail_idx].data, msg_data,
  178. HTT_EVENT_DEBUG_ENTRY_MAX_LENGTH);
  179. buf[*p_buf_tail_idx].time = qdf_get_log_timestamp();
  180. buf[*p_buf_tail_idx].cpu_id = smp_processor_id();
  181. (*p_buf_tail_idx)++;
  182. h->log_info.htt_event_log_buf_info.length++;
  183. qdf_spin_unlock(&event_log_buf->record_lock);
  184. return 0;
  185. }
  186. /**
  187. * htt_wbm_event_recored() - Record HTT wbm event
  188. *
  189. * @ h - Pointer for HTT tracer
  190. * @ tx_status - Status flag
  191. * @ msg_data - Event data
  192. */
  193. int htt_wbm_event_record(struct htt_logger *h, uint8_t tx_status,
  194. uint8_t *msg_data)
  195. {
  196. uint32_t *p_buf_tail_idx = NULL;
  197. struct htt_wbm_event_debug *buf = NULL;
  198. uint8_t tdata[HTT_WBM_EVENT_DEBUG_ENTRY_MAX_LENGTH];
  199. struct htt_log_buf_t *wbm_event_log_buf;
  200. /* return 0 if:
  201. * 1. Initialization failed.
  202. * 2. htt_logging_enable is 0 -> can get disable from file ops
  203. * 3. This specific tx_status is disabled can be used to disable
  204. * tx_Status when tx_status is successful.
  205. */
  206. if (!h)
  207. return 0;
  208. wbm_event_log_buf = &h->log_info.htt_wbm_event_log_buf_info;
  209. if ((0 == h->log_info.htt_logging_enable) ||
  210. ((1 << tx_status) & h->log_info.htt_wbm_event_disable_list))
  211. return 0;
  212. qdf_spin_lock(&wbm_event_log_buf->record_lock);
  213. if (!msg_data) {
  214. /* if msg_data is NULL then fill 0xFF in data field */
  215. qdf_mem_set(tdata, HTT_WBM_EVENT_DEBUG_ENTRY_MAX_LENGTH, 0xFF);
  216. msg_data = tdata;
  217. }
  218. p_buf_tail_idx = &h->log_info.htt_wbm_event_log_buf_info.buf_tail_idx;
  219. if (HTT_EVENT_DEBUG_MAX_ENTRY <= *p_buf_tail_idx)
  220. *p_buf_tail_idx = 0;
  221. buf = h->log_info.htt_wbm_event_log_buf_info.buf;
  222. buf[*p_buf_tail_idx].tx_status = tx_status;
  223. qdf_mem_copy(buf[*p_buf_tail_idx].data, msg_data,
  224. HTT_WBM_EVENT_DEBUG_ENTRY_MAX_LENGTH);
  225. buf[*p_buf_tail_idx].time = qdf_get_log_timestamp();
  226. buf[*p_buf_tail_idx].cpu_id = smp_processor_id();
  227. (*p_buf_tail_idx)++;
  228. h->log_info.htt_wbm_event_log_buf_info.length++;
  229. qdf_spin_unlock(&wbm_event_log_buf->record_lock);
  230. return 0;
  231. }
  232. /* debugfs routines */
  233. /**
  234. * debug_htt_command_log_show() - debugfs functions to display content of
  235. * command and event buffers. Macro uses max buffer length to display
  236. * buffer when it is wraparound.
  237. *
  238. * @m: qdf_debugfs handler to access htt_logger_handle
  239. * @arg: Private data htt_logger_hand here
  240. *
  241. * Return: Status
  242. */
  243. static QDF_STATUS debug_htt_command_log_show(qdf_debugfs_file_t file, void *arg)
  244. {
  245. struct htt_logger *htt_logger_handle = (struct htt_logger *)arg;
  246. struct htt_log_buf_t *htt_log = NULL;
  247. int pos, nread, i;
  248. uint64_t secs, usecs;
  249. htt_log = &htt_logger_handle->log_info.htt_command_log_buf_info;
  250. /* If message already read, return and reset this bit*/
  251. /* Bit set to 1 : indicates it is read
  252. * Bit set to 0 : indicates 1st time read
  253. */
  254. if ((htt_logger_handle->log_info.stop_seq &
  255. (0x1 << HTT_COMMAND_LOG_BP))) {
  256. htt_logger_handle->log_info.stop_seq &=
  257. (~(0x1 << HTT_COMMAND_LOG_BP));
  258. return QDF_STATUS_SUCCESS;
  259. }
  260. qdf_spin_lock(&htt_logger_handle->log_info.htt_record_lock);
  261. if (!htt_log->length) {
  262. qdf_spin_unlock(&htt_logger_handle->log_info.htt_record_lock);
  263. qdf_debugfs_printf(file,
  264. "no elements to read from ring buffer!\n");
  265. /* setting bit sothat in next come we will return in start */
  266. htt_logger_handle->log_info.stop_seq |=
  267. (0x1 << HTT_COMMAND_LOG_BP);
  268. return QDF_STATUS_SUCCESS;
  269. }
  270. if (htt_log->length <= HTT_DISPLAY_SIZE)
  271. nread = htt_log->length;
  272. else
  273. nread = HTT_DISPLAY_SIZE;
  274. if (htt_log->buf_tail_idx == 0)
  275. pos = HTT_DISPLAY_SIZE - 1;
  276. else
  277. pos = htt_log->buf_tail_idx - 1;
  278. qdf_debugfs_printf(file, "Length = %d\n", htt_log->length);
  279. qdf_spin_unlock(&htt_logger_handle->log_info.htt_record_lock);
  280. while (nread--) {
  281. struct htt_command_debug *htt_record;
  282. htt_record = (struct htt_command_debug *)
  283. &(((struct htt_command_debug *)htt_log->buf)[pos]);
  284. qdf_debugfs_printf(file, "CMD ID = %x\n",
  285. htt_record->command);
  286. qdf_debugfs_printf(file, "DATA[0-%d]:",
  287. HTT_COMMAND_DEBUG_ENTRY_MAX_LENGTH - 1);
  288. for (i = 0; i < HTT_COMMAND_DEBUG_ENTRY_MAX_LENGTH; i++)
  289. qdf_debugfs_printf(file, "%x ", htt_record->data[i]);
  290. qdf_log_timestamp_to_secs(htt_record->time, &secs, &usecs);
  291. qdf_debugfs_printf(file, "\nCPU ID = %d", htt_record->cpu_id);
  292. qdf_debugfs_printf(file, "\nCMD TIME = [%llu.%06llu]\n",
  293. secs, usecs);
  294. if (pos == 0)
  295. pos = HTT_DISPLAY_SIZE - 1;
  296. else
  297. pos--;
  298. }
  299. htt_logger_handle->log_info.stop_seq |=
  300. (0x1 << HTT_COMMAND_LOG_BP);
  301. return QDF_STATUS_SUCCESS;
  302. }
  303. static QDF_STATUS debug_htt_event_log_show(qdf_debugfs_file_t file, void *arg)
  304. {
  305. struct htt_logger *htt_logger_handle = (struct htt_logger *)arg;
  306. struct htt_log_buf_t *htt_log = NULL;
  307. int pos, nread, i;
  308. uint64_t secs, usecs;
  309. htt_log = &htt_logger_handle->log_info.htt_event_log_buf_info;
  310. if ((htt_logger_handle->log_info.stop_seq &
  311. (0x1 << HTT_EVENT_LOG_BP))) {
  312. htt_logger_handle->log_info.stop_seq &=
  313. (~(0x1 << HTT_EVENT_LOG_BP));
  314. return QDF_STATUS_SUCCESS;
  315. }
  316. qdf_spin_lock(&htt_logger_handle->log_info.htt_record_lock);
  317. if (!htt_log->length) {
  318. qdf_spin_unlock(&htt_logger_handle->log_info.htt_record_lock);
  319. qdf_debugfs_printf(file,
  320. "no elements to read from ring buffer!\n");
  321. htt_logger_handle->log_info.stop_seq |=
  322. (0x1 << HTT_EVENT_LOG_BP);
  323. return QDF_STATUS_SUCCESS;
  324. }
  325. if (htt_log->length <= HTT_DISPLAY_SIZE)
  326. nread = htt_log->length;
  327. else
  328. nread = HTT_DISPLAY_SIZE;
  329. if (htt_log->buf_tail_idx == 0)
  330. pos = HTT_DISPLAY_SIZE - 1;
  331. else
  332. pos = htt_log->buf_tail_idx - 1;
  333. qdf_debugfs_printf(file, "Length = %d\n", htt_log->length);
  334. qdf_spin_unlock(&htt_logger_handle->log_info.htt_record_lock);
  335. while (nread--) {
  336. struct htt_event_debug *htt_record;
  337. htt_record = (struct htt_event_debug *)
  338. &(((struct htt_event_debug *)htt_log->buf)[pos]);
  339. qdf_debugfs_printf(file, "EVENT ID = %x\n", htt_record->event);
  340. qdf_debugfs_printf(file, "DATA[0 - %d]:",
  341. HTT_EVENT_DEBUG_ENTRY_MAX_LENGTH - 1);
  342. for (i = 0; i < HTT_EVENT_DEBUG_ENTRY_MAX_LENGTH; i++)
  343. qdf_debugfs_printf(file, "%x ", htt_record->data[i]);
  344. qdf_log_timestamp_to_secs(htt_record->time, &secs, &usecs);
  345. qdf_debugfs_printf(file, "\nCPU ID = %d", (htt_record->cpu_id));
  346. qdf_debugfs_printf(file, "\nEVENT TIME = [%llu.%06llu]\n",
  347. secs, usecs);
  348. if (pos == 0)
  349. pos = HTT_DISPLAY_SIZE - 1;
  350. else
  351. pos--;
  352. }
  353. htt_logger_handle->log_info.stop_seq |=
  354. (0x1 << HTT_EVENT_LOG_BP);
  355. return QDF_STATUS_SUCCESS;
  356. }
  357. static QDF_STATUS debug_htt_wbm_event_log_show(qdf_debugfs_file_t file,
  358. void *arg)
  359. {
  360. struct htt_logger *htt_logger_handle = (struct htt_logger *)arg;
  361. struct htt_log_buf_t *htt_log = NULL;
  362. int pos, nread, i;
  363. uint64_t secs, usecs;
  364. htt_log = &htt_logger_handle->log_info.htt_wbm_event_log_buf_info;
  365. if ((htt_logger_handle->log_info.stop_seq &
  366. (0x1 << HTT_WBM_EVENT_LOG_BP))) {
  367. htt_logger_handle->log_info.stop_seq &=
  368. (~(0x1 << HTT_WBM_EVENT_LOG_BP));
  369. return QDF_STATUS_SUCCESS;
  370. }
  371. qdf_spin_lock(&htt_logger_handle->log_info.htt_record_lock);
  372. if (!htt_log->length) {
  373. qdf_spin_unlock(&htt_logger_handle->log_info.htt_record_lock);
  374. qdf_debugfs_printf(file,
  375. "no elements to read from ring buffer!\n");
  376. htt_logger_handle->log_info.stop_seq |=
  377. (0x1 << HTT_WBM_EVENT_LOG_BP);
  378. return QDF_STATUS_SUCCESS;
  379. }
  380. if (htt_log->length <= HTT_DISPLAY_SIZE)
  381. nread = htt_log->length;
  382. else
  383. nread = HTT_DISPLAY_SIZE;
  384. if (htt_log->buf_tail_idx == 0)
  385. pos = HTT_DISPLAY_SIZE - 1;
  386. else
  387. pos = htt_log->buf_tail_idx - 1;
  388. qdf_debugfs_printf(file, "Length = %d\n", htt_log->length);
  389. qdf_spin_unlock(&htt_logger_handle->log_info.htt_record_lock);
  390. while (nread--) {
  391. struct htt_wbm_event_debug *htt_record;
  392. htt_record = (struct htt_wbm_event_debug *)
  393. &(((struct htt_wbm_event_debug *)htt_log->buf)[pos]);
  394. qdf_debugfs_printf(file, "WBM Event Tx status = = %x\n",
  395. htt_record->tx_status);
  396. qdf_debugfs_printf(file, "DATA[0-%d]:",
  397. HTT_WBM_EVENT_DEBUG_ENTRY_MAX_LENGTH - 1);
  398. for (i = 0; i < HTT_WBM_EVENT_DEBUG_ENTRY_MAX_LENGTH; i++)
  399. qdf_debugfs_printf(file, "%x ", htt_record->data[i]);
  400. qdf_log_timestamp_to_secs(htt_record->time, &secs, &usecs);
  401. qdf_debugfs_printf(file, "\nCPU ID = %d", (htt_record->cpu_id));
  402. qdf_debugfs_printf(file, "\nWBM EVENT TIME = [%llu.%06llu]\n",
  403. secs, usecs);
  404. if (pos == 0)
  405. pos = HTT_DISPLAY_SIZE - 1;
  406. else
  407. pos--;
  408. }
  409. htt_logger_handle->log_info.stop_seq |=
  410. (0x1 << HTT_WBM_EVENT_LOG_BP);
  411. return QDF_STATUS_SUCCESS;
  412. }
  413. /**
  414. * debug_htt_enable_show() - debugfs functions to display enable state of
  415. * htt logging feature.
  416. *
  417. * @file: qdf debugfs handler
  418. * @arg: priv data used to get htt_logger_handler
  419. *
  420. * Return: Status
  421. */
  422. static QDF_STATUS debug_htt_enable_show(qdf_debugfs_file_t file, void *arg)
  423. {
  424. struct htt_logger *htt_logger_handle = (struct htt_logger *)arg;
  425. struct htt_debug_log_info *log_info_p = &htt_logger_handle->log_info;
  426. if ((htt_logger_handle->log_info.stop_seq &
  427. (0x1 << HTT_ENABLE_BP))) {
  428. htt_logger_handle->log_info.stop_seq &=
  429. (~(0x1 << HTT_ENABLE_BP));
  430. return QDF_STATUS_SUCCESS;
  431. }
  432. qdf_debugfs_printf(file, "%d\n",
  433. log_info_p->htt_logging_enable);
  434. htt_logger_handle->log_info.stop_seq |=
  435. (0x1 << HTT_ENABLE_BP);
  436. return QDF_STATUS_SUCCESS;
  437. }
  438. /**
  439. * debug_htt_cmd_disable_list_show() - debugfs functions to display disabled
  440. * command id for tracing.
  441. *
  442. * @file: qdf debugfs handler
  443. * @arg: priv data used to get htt_logger_handler
  444. *
  445. * Return: Status
  446. */
  447. static QDF_STATUS debug_htt_cmd_disable_list_show(qdf_debugfs_file_t file,
  448. void *arg)
  449. {
  450. struct htt_logger *htt_logger_handle = (struct htt_logger *)arg;
  451. struct htt_debug_log_info *log_info_p = &htt_logger_handle->log_info;
  452. if ((htt_logger_handle->log_info.stop_seq &
  453. (0x1 << HTT_CMD_DISABLE_LIST_BP))) {
  454. htt_logger_handle->log_info.stop_seq &=
  455. (~(0x1 << HTT_CMD_DISABLE_LIST_BP));
  456. return QDF_STATUS_SUCCESS;
  457. }
  458. qdf_debugfs_printf(file, "%llu\n",
  459. log_info_p->htt_cmd_disable_list);
  460. htt_logger_handle->log_info.stop_seq |=
  461. (0x1 << HTT_CMD_DISABLE_LIST_BP);
  462. return QDF_STATUS_SUCCESS;
  463. }
  464. /**
  465. * debug_htt_event_disable_list_show() - debugfs functions to display disabled
  466. * event id for tracing.
  467. *
  468. * @file: qdf debugfs handler
  469. * @arg: priv data used to get htt_logger_handler
  470. *
  471. * Return: Status
  472. */
  473. static QDF_STATUS debug_htt_event_disable_list_show(qdf_debugfs_file_t file,
  474. void *arg)
  475. {
  476. struct htt_logger *htt_logger_handle = (struct htt_logger *)arg;
  477. struct htt_debug_log_info *log_info_p = &htt_logger_handle->log_info;
  478. if ((htt_logger_handle->log_info.stop_seq &
  479. (0x1 << HTT_EVENT_DISABLE_LIST))) {
  480. htt_logger_handle->log_info.stop_seq &=
  481. (~(0x1 << HTT_EVENT_DISABLE_LIST));
  482. return QDF_STATUS_SUCCESS;
  483. }
  484. qdf_debugfs_printf(file, "%llu\n",
  485. log_info_p->htt_event_disable_list);
  486. htt_logger_handle->log_info.stop_seq |=
  487. (0x1 << HTT_EVENT_DISABLE_LIST);
  488. return QDF_STATUS_SUCCESS;
  489. }
  490. /**
  491. * debug_htt_cmd_disable_list_show() - debugfs functions to display disabled
  492. * wbm event id for tracing.
  493. *
  494. * @file: qdf debugfs handler
  495. * @arg: priv data used to get htt_logger_handler
  496. *
  497. * Return: Status
  498. */
  499. static QDF_STATUS debug_htt_wbm_event_disable_list_show(qdf_debugfs_file_t file
  500. , void *arg)
  501. {
  502. struct htt_logger *htt_logger_handle = (struct htt_logger *)arg;
  503. struct htt_debug_log_info *log_info_p = &htt_logger_handle->log_info;
  504. if ((htt_logger_handle->log_info.stop_seq &
  505. (0x1 << HTT_WBM_EVENT_DISABLE_LIST))) {
  506. htt_logger_handle->log_info.stop_seq &=
  507. (~(0x1 << HTT_WBM_EVENT_DISABLE_LIST));
  508. return QDF_STATUS_SUCCESS;
  509. }
  510. qdf_debugfs_printf(file, "%llu\n",
  511. log_info_p->htt_wbm_event_disable_list);
  512. htt_logger_handle->log_info.stop_seq |=
  513. (0x1 << HTT_WBM_EVENT_DISABLE_LIST);
  514. return QDF_STATUS_SUCCESS;
  515. }
  516. /**
  517. * debug_htt_log_size_show() - debugfs functions to display configured size of
  518. * htt logging command/event buffer and management command/event buffer.
  519. *
  520. * @file: qdf debugfs handler
  521. * @arg: priv data used to get htt_logger_handler
  522. *
  523. * Return: Status
  524. */
  525. static QDF_STATUS debug_htt_log_size_show(qdf_debugfs_file_t file, void *arg)
  526. {
  527. struct htt_logger *htt_logger_handle = (struct htt_logger *)arg;
  528. if ((htt_logger_handle->log_info.stop_seq &
  529. (0x1 << HTT_LOG_SIZE_BP))) {
  530. htt_logger_handle->log_info.stop_seq &=
  531. (~(0x1 << HTT_LOG_SIZE_BP));
  532. return QDF_STATUS_SUCCESS;
  533. }
  534. qdf_debugfs_printf(file, "HTT command/event log max size:%d\n",
  535. HTT_EVENT_DEBUG_MAX_ENTRY);
  536. htt_logger_handle->log_info.stop_seq |=
  537. (0x1 << HTT_LOG_SIZE_BP);
  538. return QDF_STATUS_SUCCESS;
  539. }
  540. /**
  541. * debug_htt_##func_base##_write() - debugfs functions to clear
  542. * htt logging command/event buffer and management command/event buffer.
  543. *
  544. * @priv: file handler to access htt_logger_handle
  545. * @buf: received data buffer
  546. * @len: length of received buffer
  547. *
  548. * Return: Status
  549. */
  550. #define GENERATE_DEBUG_WRITE_FUNCS(func_base, htt_ring_size, htt_record_type) \
  551. static QDF_STATUS debug_htt_##func_base##_write(void *priv, \
  552. const char *buf, qdf_size_t len) \
  553. { \
  554. int k, ret; \
  555. struct htt_logger *htt_logger_handle = (struct htt_logger *)priv; \
  556. struct htt_log_buf_t *htt_log = &htt_logger_handle->log_info. \
  557. htt_##func_base##_buf_info; \
  558. ret = kstrtoint(buf, 0, &k); \
  559. if ((ret != 0) || (k != 0)) { \
  560. return QDF_STATUS_E_PERM; \
  561. } \
  562. qdf_spin_lock(&htt_logger_handle->log_info.htt_record_lock); \
  563. qdf_mem_zero(htt_log->buf, (htt_ring_size) * \
  564. sizeof(struct htt_record_type)); \
  565. htt_log->length = 0; \
  566. htt_log->buf_tail_idx = 0; \
  567. qdf_spin_unlock(&htt_logger_handle->log_info.htt_record_lock); \
  568. return QDF_STATUS_SUCCESS ; \
  569. }
  570. GENERATE_DEBUG_WRITE_FUNCS(command_log, HTT_EVENT_DEBUG_MAX_ENTRY,
  571. htt_command_debug);
  572. GENERATE_DEBUG_WRITE_FUNCS(event_log, HTT_EVENT_DEBUG_MAX_ENTRY,
  573. htt_event_debug);
  574. GENERATE_DEBUG_WRITE_FUNCS(wbm_event_log, HTT_EVENT_DEBUG_MAX_ENTRY,
  575. htt_wbm_event_debug);
  576. /**
  577. * debug_htt_enable_write() - debugfs functions to enable/disable
  578. * htt logging feature.
  579. *
  580. * @priv: file handler to access htt_logger_handle
  581. * @buf: received data buffer
  582. * @len: length of received buffer
  583. *
  584. * Return: QDF_STATUS
  585. */
  586. static QDF_STATUS debug_htt_enable_write(void *priv, const char *buf,
  587. qdf_size_t len)
  588. {
  589. struct htt_logger *htt_logger_handle = (struct htt_logger *)priv;
  590. int k, ret;
  591. ret = kstrtoint(buf, 0, &k);
  592. if ((ret != 1) || ((k != 0) && (k != 1)))
  593. return QDF_STATUS_E_PERM;
  594. htt_logger_handle->log_info.htt_logging_enable = k;
  595. return QDF_STATUS_SUCCESS;
  596. }
  597. /**
  598. * debug_htt_cmd_disable_list_write() - Debugfs write for command
  599. * to be disabled for tracing
  600. * @priv: file handler to access htt_logger_handle
  601. * @buf: received data buffer
  602. * @len: length of received buffer
  603. *
  604. * Return: QDF_STATUS
  605. */
  606. static QDF_STATUS debug_htt_cmd_disable_list_write(void *priv,
  607. const char *buf,
  608. qdf_size_t len)
  609. {
  610. struct htt_logger *htt_logger_handle = (struct htt_logger *)priv;
  611. int ret;
  612. uint64_t k;
  613. ret = kstrtou64(buf, 0, &k);
  614. if ((ret != 0) || ((k < 0) || (k > 0xFFFFFFFF)))
  615. return QDF_STATUS_E_PERM;
  616. htt_logger_handle->log_info.htt_cmd_disable_list = k;
  617. return QDF_STATUS_SUCCESS;
  618. }
  619. /**
  620. * debug_htt_event_disable_list_write() - Debugfs write for event
  621. * to be disabled for tracing
  622. * @priv: file handler to access htt_logger_handle
  623. * @buf: received data buffer
  624. * @len: length of received buffer
  625. *
  626. * Return: QDF_STATUS
  627. */
  628. static QDF_STATUS debug_htt_event_disable_list_write(void *priv,
  629. const char *buf,
  630. qdf_size_t len)
  631. {
  632. struct htt_logger *htt_logger_handle = (struct htt_logger *)priv;
  633. int ret;
  634. uint64_t k;
  635. ret = kstrtou64(buf, 0, &k);
  636. if ((ret != 0) || ((k < 0) || (k > 0xFFFFFFFF)))
  637. return QDF_STATUS_E_PERM;
  638. htt_logger_handle->log_info.htt_event_disable_list = k;
  639. return QDF_STATUS_SUCCESS;
  640. }
  641. /**
  642. * debug_htt_wbm_event_disable_list_write() - Debugfs write for wbm event
  643. * to be disabled for tracing
  644. * @priv: file handler to access htt_logger_handle
  645. * @buf: received data buffer
  646. * @len: length of received buffer
  647. *
  648. * Return: QDF_STATUS
  649. */
  650. static QDF_STATUS debug_htt_wbm_event_disable_list_write(void *priv,
  651. const char *buf,
  652. qdf_size_t len)
  653. {
  654. struct htt_logger *htt_logger_handle = (struct htt_logger *)priv;
  655. int ret;
  656. uint64_t k;
  657. ret = kstrtou64(buf, 0, &k);
  658. if ((ret != 0) || ((k < 0) || (k > 0xFFFFFFFF)))
  659. return QDF_STATUS_E_PERM;
  660. htt_logger_handle->log_info.htt_wbm_event_disable_list = k;
  661. return QDF_STATUS_SUCCESS;
  662. }
  663. /**
  664. * debug_htt_log_size_write() - reserved.
  665. *
  666. * @priv: file handler to access htt_logger_handle
  667. * @buf: received data buffer
  668. * @len: length of received buffer
  669. *
  670. * Return: QDF_STATUS
  671. */
  672. static QDF_STATUS debug_htt_log_size_write(void *priv,
  673. const char *buf,
  674. qdf_size_t len)
  675. {
  676. return -EINVAL;
  677. }
  678. /* Structure to maintain debug information */
  679. struct htt_debugfs_info {
  680. const char *name;
  681. struct qdf_debugfs_fops *ops;
  682. };
  683. #define DEBUGFS_FOPS(func_base) { .name = #func_base, \
  684. .ops = &debug_##func_base##_ops }
  685. #define GENERATE_DEBUG_STRUCTS(func_base) \
  686. \
  687. static struct qdf_debugfs_fops debug_##func_base##_ops = { \
  688. .show = debug_##func_base##_show, \
  689. .write = debug_##func_base##_write, \
  690. .priv = NULL, \
  691. }
  692. GENERATE_DEBUG_STRUCTS(htt_command_log);
  693. GENERATE_DEBUG_STRUCTS(htt_event_log);
  694. GENERATE_DEBUG_STRUCTS(htt_wbm_event_log);
  695. GENERATE_DEBUG_STRUCTS(htt_enable);
  696. GENERATE_DEBUG_STRUCTS(htt_log_size);
  697. GENERATE_DEBUG_STRUCTS(htt_cmd_disable_list);
  698. GENERATE_DEBUG_STRUCTS(htt_event_disable_list);
  699. GENERATE_DEBUG_STRUCTS(htt_wbm_event_disable_list);
  700. struct htt_debugfs_info htt_debugfs_infos[NUM_HTT_DEBUG_INFOS] = {
  701. DEBUGFS_FOPS(htt_command_log),
  702. DEBUGFS_FOPS(htt_event_log),
  703. DEBUGFS_FOPS(htt_wbm_event_log),
  704. DEBUGFS_FOPS(htt_enable),
  705. DEBUGFS_FOPS(htt_log_size),
  706. DEBUGFS_FOPS(htt_cmd_disable_list),
  707. DEBUGFS_FOPS(htt_event_disable_list),
  708. DEBUGFS_FOPS(htt_wbm_event_disable_list),
  709. };
  710. /**
  711. * htt_log_buffer_free() - Free all dynamic allocated buffer memory for
  712. * event logging
  713. * @htt_logger_handle: HTT handle.
  714. *
  715. * Return: None
  716. */
  717. static inline void htt_log_buffer_free(struct htt_logger *htt_logger_handle)
  718. {
  719. struct htt_debug_log_info *log_info_p = &htt_logger_handle->log_info;
  720. /* first disable logging and then free buffer and release lock */
  721. log_info_p->htt_logging_enable = 0;
  722. /* Free allocated buffer */
  723. if (log_info_p->htt_command_log_buf_info.buf) {
  724. qdf_mem_free(log_info_p->htt_command_log_buf_info.buf);
  725. log_info_p->htt_command_log_buf_info.buf = NULL;
  726. }
  727. if (log_info_p->htt_event_log_buf_info.buf) {
  728. qdf_mem_free(log_info_p->htt_event_log_buf_info.buf);
  729. log_info_p->htt_event_log_buf_info.buf = NULL;
  730. }
  731. if (log_info_p->htt_wbm_event_log_buf_info.buf) {
  732. qdf_mem_free(log_info_p->htt_wbm_event_log_buf_info.buf);
  733. log_info_p->htt_wbm_event_log_buf_info.buf = NULL;
  734. }
  735. }
  736. /**
  737. * htt_log_buffer_alloc() - Allocate all dynamic allocated buffer memory for
  738. * event logging
  739. * @htt_logger_handle: HTT handle.
  740. *
  741. * Return: None
  742. */
  743. static QDF_STATUS htt_log_buffer_alloc(struct htt_logger *htt_logger_handle)
  744. {
  745. struct htt_log_buf_t *cmd_log_buf;
  746. struct htt_log_buf_t *event_log_buf;
  747. struct htt_log_buf_t *wbm_event_log_buf;
  748. cmd_log_buf =
  749. &htt_logger_handle->log_info.htt_command_log_buf_info;
  750. event_log_buf =
  751. &htt_logger_handle->log_info.htt_event_log_buf_info;
  752. wbm_event_log_buf =
  753. &htt_logger_handle->log_info.htt_wbm_event_log_buf_info;
  754. /* first disable logging and then free buffer and release lock */
  755. htt_logger_handle->log_info.htt_logging_enable = 0;
  756. /* Allocate data buffer */
  757. cmd_log_buf->buf = (struct htt_command_debug *)qdf_mem_malloc(
  758. HTT_EVENT_DEBUG_MAX_ENTRY *
  759. sizeof(struct htt_command_debug));
  760. if (!cmd_log_buf->buf) {
  761. HTT_LOGE("Memory allocation for HTT CMD log failed.");
  762. goto error_mem_fail;
  763. }
  764. event_log_buf->buf = (struct htt_event_debug *)qdf_mem_malloc(
  765. HTT_EVENT_DEBUG_MAX_ENTRY *
  766. sizeof(struct htt_event_debug));
  767. if (!event_log_buf->buf) {
  768. HTT_LOGE("Memory allocation for HTT EVENT log failed.");
  769. goto error_mem_fail;
  770. }
  771. wbm_event_log_buf->buf = (struct htt_wbm_event_debug *)qdf_mem_malloc(
  772. HTT_EVENT_DEBUG_MAX_ENTRY *
  773. sizeof(struct htt_wbm_event_debug));
  774. if (!wbm_event_log_buf->buf) {
  775. HTT_LOGE("Memory allocation for HTT WBM EVENT log failed.");
  776. goto error_mem_fail;
  777. }
  778. return QDF_STATUS_SUCCESS;
  779. error_mem_fail:
  780. htt_log_buffer_free(htt_logger_handle);
  781. return QDF_STATUS_E_NOMEM;
  782. }
  783. /**
  784. * htt_log_lock_free - Destroy lock
  785. */
  786. static inline void htt_log_lock_alloc(struct htt_logger *htt_logger_handle)
  787. {
  788. struct htt_debug_log_info *log_info_p = &htt_logger_handle->log_info;
  789. struct htt_log_buf_t *cmd_log_buf =
  790. &htt_logger_handle->log_info.htt_command_log_buf_info;
  791. struct htt_log_buf_t *event_log_buf =
  792. &htt_logger_handle->log_info.htt_event_log_buf_info;
  793. struct htt_log_buf_t *wbm_event_log_buf =
  794. &htt_logger_handle->log_info.htt_wbm_event_log_buf_info;
  795. /* Create lock for cmd/event/wbm */
  796. qdf_spinlock_create(&cmd_log_buf->record_lock);
  797. qdf_spinlock_create(&event_log_buf->record_lock);
  798. qdf_spinlock_create(&wbm_event_log_buf->record_lock);
  799. /* Create recording lock in read through debugfs */
  800. qdf_spinlock_create(&log_info_p->htt_record_lock);
  801. }
  802. /**
  803. * htt_log_lock_free - Destroy lock
  804. */
  805. static inline void htt_log_lock_free(struct htt_logger *htt_logger_handle)
  806. {
  807. struct htt_debug_log_info *log_info_p = &htt_logger_handle->log_info;
  808. struct htt_log_buf_t *cmd_log_buf =
  809. &htt_logger_handle->log_info.htt_command_log_buf_info;
  810. struct htt_log_buf_t *event_log_buf =
  811. &htt_logger_handle->log_info.htt_event_log_buf_info;
  812. struct htt_log_buf_t *wbm_event_log_buf =
  813. &htt_logger_handle->log_info.htt_wbm_event_log_buf_info;
  814. /* Destroy lock for cmd/event/wbm */
  815. qdf_spinlock_destroy(&cmd_log_buf->record_lock);
  816. qdf_spinlock_destroy(&event_log_buf->record_lock);
  817. qdf_spinlock_destroy(&wbm_event_log_buf->record_lock);
  818. /* Destroy recording lock in read through debugfs */
  819. qdf_spinlock_destroy(&log_info_p->htt_record_lock);
  820. }
  821. /**
  822. * htt_debugfs_remove() - Remove debugfs entry for htt logging.
  823. * @htt_logger_handle: htt handle
  824. * @dentry: qdf_debugfs directory entry
  825. * @id: Index to debug info data array
  826. *
  827. * Return: none
  828. */
  829. static void htt_debugfs_remove(struct htt_logger *htt_logger_handle)
  830. {
  831. int i;
  832. qdf_dentry_t dentry = htt_logger_handle->log_info.htt_log_debugfs_dir;
  833. if (dentry) {
  834. for (i = 0; i < NUM_HTT_DEBUG_INFOS; ++i) {
  835. if (htt_logger_handle->debugfs_de[i])
  836. htt_logger_handle->debugfs_de[i] = NULL;
  837. }
  838. }
  839. if (dentry)
  840. qdf_debugfs_remove_dir_recursive(dentry);
  841. }
  842. /**
  843. * htt_debugfs_init() - debugfs functions to create debugfs directory and to
  844. * create debugfs enteries.
  845. *
  846. * @ htt_logger_handle: htt logger handler
  847. *
  848. * Return: init status
  849. */
  850. static QDF_STATUS htt_debugfs_init(struct htt_logger *htt_logger_handle)
  851. {
  852. char buf[32];
  853. int i;
  854. snprintf(buf, sizeof(buf), "HTT_SOC_LOGGER");
  855. htt_logger_handle->log_info.htt_log_debugfs_dir =
  856. qdf_debugfs_create_dir(buf, NULL);
  857. if (!htt_logger_handle->log_info.htt_log_debugfs_dir) {
  858. HTT_LOGE("error while creating debugfs dir for %s", buf);
  859. return QDF_STATUS_E_FAILURE;
  860. }
  861. for (i = 0; i < NUM_HTT_DEBUG_INFOS; ++i) {
  862. htt_debugfs_infos[i].ops->priv = htt_logger_handle;
  863. htt_logger_handle->debugfs_de[i] = qdf_debugfs_create_file(
  864. htt_debugfs_infos[i].name, HTT_DBG_FILE_PERM,
  865. htt_logger_handle->log_info.htt_log_debugfs_dir,
  866. htt_debugfs_infos[i].ops);
  867. if (!htt_logger_handle->debugfs_de[i])
  868. goto out;
  869. }
  870. return QDF_STATUS_SUCCESS;
  871. out:
  872. HTT_LOGE("debug Entry creation failed[%s]!", htt_debugfs_infos[i].name);
  873. htt_debugfs_remove(htt_logger_handle);
  874. return QDF_STATUS_E_FAILURE;
  875. }
  876. /**
  877. * htt_interface_logging_init() - Initialize HTT tracer
  878. * @ htt_logger_handle: htt logger handler
  879. */
  880. void htt_interface_logging_init(struct htt_logger **phtt_logger_handle)
  881. {
  882. QDF_STATUS ret;
  883. struct htt_logger *htt_logger_handle;
  884. struct htt_log_buf_t *cmd_log_buf;
  885. struct htt_log_buf_t *event_log_buf;
  886. struct htt_log_buf_t *wbm_event_log_buf;
  887. uint64_t htt_disable_mask;
  888. *phtt_logger_handle = (struct htt_logger *)qdf_mem_malloc(
  889. sizeof(struct htt_logger));
  890. if (!*phtt_logger_handle) {
  891. HTT_LOGE("Memory allocation for HTT logger buffer failed.");
  892. return;
  893. }
  894. /* Allocate Buffer */
  895. if (QDF_STATUS_SUCCESS != htt_log_buffer_alloc(*phtt_logger_handle)) {
  896. qdf_mem_free(*phtt_logger_handle);
  897. *phtt_logger_handle = NULL;
  898. return;
  899. }
  900. htt_logger_handle = *phtt_logger_handle;
  901. cmd_log_buf =
  902. &htt_logger_handle->log_info.htt_command_log_buf_info;
  903. event_log_buf =
  904. &htt_logger_handle->log_info.htt_event_log_buf_info;
  905. wbm_event_log_buf =
  906. &htt_logger_handle->log_info.htt_wbm_event_log_buf_info;
  907. /* Initialize HTT Cmd/Event/WBM Event */
  908. log_buf_init(cmd_log_buf);
  909. log_buf_init(event_log_buf);
  910. log_buf_init(wbm_event_log_buf);
  911. /* Disable all command */
  912. disable_all_command(htt_logger_handle);
  913. /* Disable all event except:
  914. * HTT_T2H_MSG_TYPE_PEER_MAP, HTT_T2H_MSG_TYPE_PEER_UNMAP
  915. * HTT_T2H_MSG_TYPE_RX_ADDBA HTT_T2H_MSG_TYPE_RX_DELBA
  916. * HTT_T2H_MSG_TYPE_PEER_MAP_V2 HTT_T2H_MSG_TYPE_PEER_UNMAP_V2
  917. */
  918. disable_all_event(htt_logger_handle);
  919. enable_event(htt_logger_handle, HTT_T2H_MSG_TYPE_PEER_MAP_C);
  920. enable_event(htt_logger_handle, HTT_T2H_MSG_TYPE_PEER_UNMAP_C);
  921. enable_event(htt_logger_handle, HTT_T2H_MSG_TYPE_RX_ADDBA_C);
  922. enable_event(htt_logger_handle, HTT_T2H_MSG_TYPE_RX_DELBA_C);
  923. enable_event(htt_logger_handle, HTT_T2H_MSG_TYPE_PEER_MAP_V2_C);
  924. enable_event(htt_logger_handle, HTT_T2H_MSG_TYPE_PEER_UNMAP_V2_C);
  925. /* Disable success status*/
  926. disable_wbm_success_status(htt_logger_handle);
  927. /* Create lock for all event */
  928. htt_log_lock_alloc(htt_logger_handle);
  929. /* Enable HTT logging */
  930. enable_htt_logging(htt_logger_handle);
  931. ret = htt_debugfs_init(*phtt_logger_handle);
  932. if (QDF_STATUS_SUCCESS != ret)
  933. goto debugfs_init_failed;
  934. return;
  935. debugfs_init_failed:
  936. htt_log_buffer_free(*phtt_logger_handle);
  937. htt_log_lock_free(*phtt_logger_handle);
  938. (*phtt_logger_handle)->log_info.htt_logging_enable = 0;
  939. qdf_mem_free(*phtt_logger_handle);
  940. *phtt_logger_handle = NULL;
  941. }
  942. /**
  943. * htt_interface_logging_deinit() - Deinitialize HTT tracer
  944. * @ htt_logger_handle: htt logger handler
  945. */
  946. void htt_interface_logging_deinit(struct htt_logger *htt_logger_handle)
  947. {
  948. /**
  949. * This case will hit in deinit path
  950. * if htt_initialization failed
  951. */
  952. if (!htt_logger_handle)
  953. return;
  954. htt_debugfs_remove(htt_logger_handle);
  955. htt_log_buffer_free(htt_logger_handle);
  956. htt_log_lock_free(htt_logger_handle);
  957. qdf_mem_free(htt_logger_handle);
  958. }
  959. #ifdef HTT_STATS_DEBUGFS_SUPPORT
  960. void htt_stats_msg_receive(void *data, A_INT32 len);
  961. /* File permission for HTT stats debugfs entry */
  962. #define PDEV_HTT_STATS_DBGFS_FILE_PERM (QDF_FILE_USR_READ | \
  963. QDF_FILE_GRP_READ | QDF_FILE_OTH_READ)
  964. /* Delay in ms to get the HTT stats for debugfs entry */
  965. #define PDEV_HTT_STATS_DBGFS_WAIT_TIME 2000
  966. /* Char array size of parent directory of debugfs HTT stats */
  967. #define PDEV_HTT_STATS_DBGFS_DIR_SIZE 19
  968. /* Char array size of debugfs file for HTT stats */
  969. #define PDEV_HTT_STATS_DBGFS_FILE_SIZE 7
  970. /* dp_pdev_htt_stats_dbgfs_show() - Function to display HTT stats
  971. * @file: qdf debugfs file handler
  972. * @arg: pointer to HTT stats debugfs private object
  973. *
  974. * Return: QDF_STATUS
  975. */
  976. static inline
  977. QDF_STATUS
  978. dp_pdev_htt_stats_dbgfs_show(qdf_debugfs_file_t file, void *arg)
  979. {
  980. struct pdev_htt_stats_dbgfs_priv *priv = arg;
  981. struct dp_pdev *pdev = NULL;
  982. uint32_t config_param0 = 0;
  983. uint32_t config_param1 = 0;
  984. uint32_t config_param2 = 0;
  985. uint32_t config_param3 = 0;
  986. int cookie_val = 0;
  987. uint8_t mac_id = 0;
  988. QDF_STATUS ret = QDF_STATUS_SUCCESS;
  989. pdev = priv->pdev;
  990. pdev->dbgfs_cfg->m = file;
  991. qdf_mutex_acquire(&pdev->dbgfs_cfg->lock);
  992. dp_h2t_ext_stats_msg_send(pdev, priv->stats_id, config_param0,
  993. config_param1, config_param2, config_param3,
  994. cookie_val, DBG_STATS_COOKIE_HTT_DBGFS,
  995. mac_id);
  996. ret = qdf_wait_single_event(&pdev->dbgfs_cfg->htt_stats_dbgfs_event,
  997. PDEV_HTT_STATS_DBGFS_WAIT_TIME);
  998. if (ret == QDF_STATUS_E_TIMEOUT)
  999. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1000. "Event timeout: Failed to get response from FW");
  1001. qdf_mutex_release(&pdev->dbgfs_cfg->lock);
  1002. return ret;
  1003. }
  1004. /* dp_pdev_dbgfs_init() - Init debugfs of HTT stats to create
  1005. * debugfs directories and entries
  1006. * @pdev: DP pdev handle
  1007. *
  1008. * Return: QDF_STATUS
  1009. */
  1010. static inline
  1011. QDF_STATUS dp_pdev_dbgfs_init(struct dp_pdev *pdev)
  1012. {
  1013. char dir_name[PDEV_HTT_STATS_DBGFS_DIR_SIZE] = {0};
  1014. char file_name[PDEV_HTT_STATS_DBGFS_FILE_SIZE] = {0};
  1015. int idx;
  1016. qdf_snprintf(dir_name, sizeof(dir_name), "dp_wifistats_wifi%d",
  1017. pdev->pdev_id);
  1018. pdev->dbgfs_cfg->debugfs_entry[0] = qdf_debugfs_create_dir(dir_name,
  1019. NULL);
  1020. if (!pdev->dbgfs_cfg->debugfs_entry[0]) {
  1021. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1022. "Failed to create debugfs directory for HTT stats");
  1023. return QDF_STATUS_E_FAILURE;
  1024. }
  1025. for (idx = 1; idx < PDEV_HTT_STATS_DBGFS_SIZE - 1; idx++) {
  1026. qdf_snprintf(file_name, sizeof(file_name), "cmd%d", idx);
  1027. pdev->dbgfs_cfg->priv[idx - 1].pdev = pdev;
  1028. pdev->dbgfs_cfg->priv[idx - 1].stats_id = idx;
  1029. pdev->dbgfs_cfg->pdev_htt_stats_dbgfs_ops[idx - 1].show =
  1030. dp_pdev_htt_stats_dbgfs_show;
  1031. pdev->dbgfs_cfg->pdev_htt_stats_dbgfs_ops[idx - 1].write = NULL;
  1032. pdev->dbgfs_cfg->pdev_htt_stats_dbgfs_ops[idx - 1].priv =
  1033. &pdev->dbgfs_cfg->priv[idx - 1];
  1034. pdev->dbgfs_cfg->debugfs_entry[idx] =
  1035. qdf_debugfs_create_file_simplified(
  1036. file_name, PDEV_HTT_STATS_DBGFS_FILE_PERM,
  1037. pdev->dbgfs_cfg->debugfs_entry[0],
  1038. &pdev->dbgfs_cfg->pdev_htt_stats_dbgfs_ops[idx - 1]);
  1039. if (!pdev->dbgfs_cfg->debugfs_entry[idx]) {
  1040. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1041. "Failed to create htt stats dbgfs file for %d", idx);
  1042. return QDF_STATUS_E_FAILURE;
  1043. }
  1044. }
  1045. return QDF_STATUS_SUCCESS;
  1046. }
  1047. /* dp_pdev_htt_stats_dbgfs_init() - Function to allocate memory and initialize
  1048. * debugfs for HTT stats
  1049. * @pdev: dp pdev handle
  1050. *
  1051. * Return: QDF_STATUS
  1052. */
  1053. QDF_STATUS dp_pdev_htt_stats_dbgfs_init(struct dp_pdev *pdev)
  1054. {
  1055. pdev->dbgfs_cfg =
  1056. qdf_mem_malloc(sizeof(struct pdev_htt_stats_dbgfs_cfg));
  1057. if (!pdev->dbgfs_cfg) {
  1058. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1059. "%s: Memory allocation failed for pdev htt stats dbgfs cfg", __func__);
  1060. return QDF_STATUS_E_NOMEM;
  1061. }
  1062. qdf_mutex_create(&pdev->dbgfs_cfg->lock);
  1063. qdf_event_create(&pdev->dbgfs_cfg->htt_stats_dbgfs_event);
  1064. pdev->dbgfs_cfg->htt_stats_dbgfs_msg_process = htt_stats_msg_receive;
  1065. if (dp_pdev_dbgfs_init(pdev)) {
  1066. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1067. "%s: Failed to initialize for pdev htt stats dbgfs", __func__);
  1068. dp_pdev_htt_stats_dbgfs_deinit(pdev);
  1069. return QDF_STATUS_E_FAILURE;
  1070. }
  1071. return QDF_STATUS_SUCCESS;
  1072. }
  1073. /* dp_pdev_htt_stats_dbgfs_deinit() - Function to free memory and remove
  1074. * debugfs directory and entries for HTT stats
  1075. * @pdev: dp pdev handle
  1076. *
  1077. * Return: none
  1078. */
  1079. void dp_pdev_htt_stats_dbgfs_deinit(struct dp_pdev *pdev)
  1080. {
  1081. if (pdev->dbgfs_cfg) {
  1082. qdf_mutex_destroy(&pdev->dbgfs_cfg->lock);
  1083. qdf_event_destroy(&pdev->dbgfs_cfg->htt_stats_dbgfs_event);
  1084. pdev->dbgfs_cfg->htt_stats_dbgfs_msg_process = NULL;
  1085. if (pdev->dbgfs_cfg->debugfs_entry[0]) {
  1086. qdf_debugfs_remove_dir_recursive(
  1087. pdev->dbgfs_cfg->debugfs_entry[0]);
  1088. pdev->dbgfs_cfg->debugfs_entry[0] = NULL;
  1089. }
  1090. qdf_mem_free(pdev->dbgfs_cfg);
  1091. pdev->dbgfs_cfg = NULL;
  1092. }
  1093. }
  1094. #endif /* HTT_STATS_DEBUGFS_SUPPORT */