qdf_trace.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. /*
  2. * Copyright (c) 2014-2016 The Linux Foundation. All rights reserved.
  3. *
  4. * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
  5. *
  6. *
  7. * Permission to use, copy, modify, and/or distribute this software for
  8. * any purpose with or without fee is hereby granted, provided that the
  9. * above copyright notice and this permission notice appear in all
  10. * copies.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  13. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  14. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  15. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  16. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  17. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  18. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  19. * PERFORMANCE OF THIS SOFTWARE.
  20. */
  21. /*
  22. * This file was originally distributed by Qualcomm Atheros, Inc.
  23. * under proprietary terms before Copyright ownership was assigned
  24. * to the Linux Foundation.
  25. */
  26. #if !defined(__QDF_TRACE_H)
  27. #define __QDF_TRACE_H
  28. /**
  29. * DOC: qdf_trace
  30. * QCA driver framework trace APIs
  31. * Trace, logging, and debugging definitions and APIs
  32. */
  33. /* Include Files */
  34. #include <qdf_types.h> /* For QDF_MODULE_ID... */
  35. #include <stdarg.h> /* For va_list... */
  36. #include <qdf_status.h>
  37. #include <qdf_nbuf.h>
  38. #include <i_qdf_types.h>
  39. /* Type declarations */
  40. #define FL(x) "%s: %d: " x, __func__, __LINE__
  41. /**
  42. * typedef enum QDF_TRACE_LEVEL - Debug Trace level
  43. * @QDF_TRACE_LEVEL_NONE: no trace will be logged. This value is in place
  44. * for the qdf_trace_setlevel() to allow the user to turn off all traces
  45. * @QDF_TRACE_LEVEL_FATAL: enable trace for fatal Error
  46. * @QDF_TRACE_LEVEL_ERROR: enable trace for errors
  47. * @QDF_TRACE_LEVEL_WARN: enable trace for warnings
  48. * @QDF_TRACE_LEVEL_INFO: enable trace for information
  49. * @QDF_TRACE_LEVEL_INFO_HIGH: enable high level trace information
  50. * @QDF_TRACE_LEVEL_INFO_MED: enable middle level trace information
  51. * @QDF_TRACE_LEVEL_INFO_LOW: enable low level trace information
  52. * @QDF_TRACE_LEVEL_DEBUG: enable trace for debugging
  53. * @QDF_TRACE_LEVEL_ALL: enable all trace
  54. * @QDF_TRACE_LEVEL_MAX: enable max level trace
  55. */
  56. typedef enum {
  57. QDF_TRACE_LEVEL_NONE = 0,
  58. QDF_TRACE_LEVEL_FATAL,
  59. QDF_TRACE_LEVEL_ERROR,
  60. QDF_TRACE_LEVEL_WARN,
  61. QDF_TRACE_LEVEL_INFO,
  62. QDF_TRACE_LEVEL_INFO_HIGH,
  63. QDF_TRACE_LEVEL_INFO_MED,
  64. QDF_TRACE_LEVEL_INFO_LOW,
  65. QDF_TRACE_LEVEL_DEBUG,
  66. QDF_TRACE_LEVEL_ALL,
  67. QDF_TRACE_LEVEL_MAX
  68. } QDF_TRACE_LEVEL;
  69. /*
  70. * Log levels
  71. */
  72. #define QDF_DEBUG_FUNCTRACE 0x01
  73. #define QDF_DEBUG_LEVEL0 0x02
  74. #define QDF_DEBUG_LEVEL1 0x04
  75. #define QDF_DEBUG_LEVEL2 0x08
  76. #define QDF_DEBUG_LEVEL3 0x10
  77. #define QDF_DEBUG_ERROR 0x20
  78. #define QDF_DEBUG_CFG 0x40
  79. #ifdef CONFIG_MCL
  80. /* By default Data Path module will have all log levels enabled, except debug
  81. * log level. Debug level will be left up to the framework or user space modules
  82. * to be enabled when issue is detected
  83. */
  84. #define QDF_DATA_PATH_TRACE_LEVEL \
  85. ((1 << QDF_TRACE_LEVEL_FATAL) | (1 << QDF_TRACE_LEVEL_ERROR) | \
  86. (1 << QDF_TRACE_LEVEL_WARN) | (1 << QDF_TRACE_LEVEL_INFO) | \
  87. (1 << QDF_TRACE_LEVEL_INFO_HIGH) | (1 << QDF_TRACE_LEVEL_INFO_MED) | \
  88. (1 << QDF_TRACE_LEVEL_INFO_LOW))
  89. /* Preprocessor definitions and constants */
  90. #define ASSERT_BUFFER_SIZE (512)
  91. #define MAX_QDF_TRACE_RECORDS 4000
  92. #define INVALID_QDF_TRACE_ADDR 0xffffffff
  93. #define DEFAULT_QDF_TRACE_DUMP_COUNT 0
  94. #include <i_qdf_trace.h>
  95. #ifdef TRACE_RECORD
  96. #define MTRACE(p) p
  97. #define NO_SESSION 0xFF
  98. #else
  99. #define MTRACE(p) { }
  100. #endif
  101. /**
  102. * typedef struct qdf_trace_record_s - keep trace record
  103. * @time: timestamp
  104. * @module: module name
  105. * @code: hold record of code
  106. * @session: hold record of session
  107. * @data: hold data
  108. * @pid: hold pid of the process
  109. */
  110. typedef struct qdf_trace_record_s {
  111. uint64_t time;
  112. uint8_t module;
  113. uint8_t code;
  114. uint16_t session;
  115. uint32_t data;
  116. uint32_t pid;
  117. } qdf_trace_record_t, *tp_qdf_trace_record;
  118. /**
  119. * typedef struct s_qdf_trace_data - MTRACE logs are stored in ring buffer
  120. * @head: position of first record
  121. * @tail: position of last record
  122. * @num: count of total record
  123. * @num_since_last_dump: count from last dump
  124. * @enable: config for controlling the trace
  125. * @dump_count: Dump after number of records reach this number
  126. */
  127. typedef struct s_qdf_trace_data {
  128. uint32_t head;
  129. uint32_t tail;
  130. uint32_t num;
  131. uint16_t num_since_last_dump;
  132. uint8_t enable;
  133. uint16_t dump_count;
  134. } t_qdf_trace_data;
  135. #define CASE_RETURN_STRING(str) case ((str)): return (uint8_t *)(# str);
  136. /* DP Trace Implementation */
  137. #define DPTRACE(p) p
  138. #define MAX_QDF_DP_TRACE_RECORDS 4000
  139. #define QDF_DP_TRACE_RECORD_SIZE 16
  140. #define INVALID_QDF_DP_TRACE_ADDR 0xffffffff
  141. #define QDF_DP_TRACE_VERBOSITY_HIGH 3
  142. #define QDF_DP_TRACE_VERBOSITY_MEDIUM 2
  143. #define QDF_DP_TRACE_VERBOSITY_LOW 1
  144. #define QDF_DP_TRACE_VERBOSITY_DEFAULT 0
  145. /**
  146. * enum QDF_DP_TRACE_ID - Generic ID to identify various events in data path
  147. * @QDF_DP_TRACE_INVALID: Invalid ID
  148. * @QDF_DP_TRACE_DROP_PACKET_RECORD: Dropped packet stored with this id
  149. * @QDF_DP_TRACE_HDD_PACKET_PTR_RECORD: nbuf->data ptr of HDD
  150. * @QDF_DP_TRACE_HDD_PACKET_RECORD: nbuf->data stored with this id
  151. * @QDF_DP_TRACE_CE_PACKET_PTR_RECORD: nbuf->data ptr of CE
  152. * @QDF_DP_TRACE_CE_PACKET_RECORD: nbuf->data stored with this id
  153. * @QDF_DP_TRACE_TXRX_QUEUE_PACKET_PTR_RECORD: nbuf->data ptr of txrx queue
  154. * @QDF_DP_TRACE_TXRX_PACKET_PTR_RECORD: nbuf->data ptr of txrx
  155. * @QDF_DP_TRACE_HTT_PACKET_PTR_RECORD: nbuf->data ptr of htt
  156. * @QDF_DP_TRACE_HTC_PACKET_PTR_RECORD: nbuf->data ptr of htc
  157. * @QDF_DP_TRACE_HIF_PACKET_PTR_RECORD: nbuf->data ptr of hif
  158. * @QDF_DP_TRACE_HDD_TX_TIMEOUT: hdd tx timeout event
  159. * @QDF_DP_TRACE_HDD_SOFTAP_TX_TIMEOUT: hdd tx softap timeout event
  160. * @QDF_DP_TRACE_VDEV_PAUSE: vdev pause event
  161. * @QDF_DP_TRACE_VDEV_UNPAUSE: vdev unpause event
  162. */
  163. enum QDF_DP_TRACE_ID {
  164. QDF_DP_TRACE_INVALID = 0,
  165. QDF_DP_TRACE_DROP_PACKET_RECORD = 1,
  166. QDF_DP_TRACE_HDD_PACKET_PTR_RECORD = 2,
  167. QDF_DP_TRACE_HDD_PACKET_RECORD = 3,
  168. QDF_DP_TRACE_CE_PACKET_PTR_RECORD = 4,
  169. QDF_DP_TRACE_CE_PACKET_RECORD = 5,
  170. QDF_DP_TRACE_TXRX_QUEUE_PACKET_PTR_RECORD = 6,
  171. QDF_DP_TRACE_TXRX_PACKET_PTR_RECORD = 7,
  172. QDF_DP_TRACE_HTT_PACKET_PTR_RECORD = 8,
  173. QDF_DP_TRACE_HTC_PACKET_PTR_RECORD = 9,
  174. QDF_DP_TRACE_HIF_PACKET_PTR_RECORD = 10,
  175. QDF_DP_TRACE_HDD_TX_TIMEOUT = 11,
  176. QDF_DP_TRACE_HDD_SOFTAP_TX_TIMEOUT = 12,
  177. QDF_DP_TRACE_VDEV_PAUSE = 13,
  178. QDF_DP_TRACE_VDEV_UNPAUSE = 14,
  179. QDF_DP_TRACE_MAX
  180. };
  181. /**
  182. * struct qdf_dp_trace_record_s - Describes a record in DP trace
  183. * @time: time when it got stored
  184. * @code: Describes the particular event
  185. * @data: buffer to store data
  186. * @size: Length of the valid data stored in this record
  187. * @pid : process id which stored the data in this record
  188. */
  189. struct qdf_dp_trace_record_s {
  190. uint64_t time;
  191. uint8_t code;
  192. uint8_t data[QDF_DP_TRACE_RECORD_SIZE];
  193. uint8_t size;
  194. uint32_t pid;
  195. };
  196. /**
  197. * struct qdf_dp_trace_data - Parameters to configure/control DP trace
  198. * @head: Position of first record
  199. * @tail: Position of last record
  200. * @num: Current index
  201. * @proto_bitmap: defines which protocol to be traced
  202. * @no_of_record: defines every nth packet to be traced
  203. * @verbosity : defines verbosity level
  204. * @enable: enable/disable DP trace
  205. * @count: current packet number
  206. */
  207. struct s_qdf_dp_trace_data {
  208. uint32_t head;
  209. uint32_t tail;
  210. uint32_t num;
  211. uint8_t proto_bitmap;
  212. uint8_t no_of_record;
  213. uint8_t verbosity;
  214. bool enable;
  215. uint32_t count;
  216. };
  217. /* Function declarations and documenation */
  218. /**
  219. * qdf_trace_set_level() - Set the trace level for a particular module
  220. * @level : trace level
  221. *
  222. * Trace level is a member of the QDF_TRACE_LEVEL enumeration indicating
  223. * the severity of the condition causing the trace message to be issued.
  224. * More severe conditions are more likely to be logged.
  225. *
  226. * This is an external API that allows trace levels to be set for each module.
  227. *
  228. * Return: nothing
  229. */
  230. void qdf_trace_set_level(QDF_MODULE_ID module, QDF_TRACE_LEVEL level);
  231. /**
  232. * qdf_trace_get_level() - get the trace level
  233. * @level : trace level
  234. *
  235. * This is an external API that returns a bool value to signify if a
  236. * particular trace level is set for the specified module.
  237. * A member of the QDF_TRACE_LEVEL enumeration indicating the severity
  238. * of the condition causing the trace message to be issued.
  239. *
  240. * Note that individual trace levels are the only valid values
  241. * for this API. QDF_TRACE_LEVEL_NONE and QDF_TRACE_LEVEL_ALL
  242. * are not valid input and will return false
  243. *
  244. * Return:
  245. * false - the specified trace level for the specified module is OFF
  246. * true - the specified trace level for the specified module is ON
  247. */
  248. bool qdf_trace_get_level(QDF_MODULE_ID module, QDF_TRACE_LEVEL level);
  249. typedef void (*tp_qdf_trace_cb)(void *p_mac, tp_qdf_trace_record, uint16_t);
  250. void qdf_trace(uint8_t module, uint8_t code, uint16_t session, uint32_t data);
  251. void qdf_trace_register(QDF_MODULE_ID, tp_qdf_trace_cb);
  252. QDF_STATUS qdf_trace_spin_lock_init(void);
  253. void qdf_trace_init(void);
  254. void qdf_trace_enable(uint32_t, uint8_t enable);
  255. void qdf_trace_dump_all(void *, uint8_t, uint8_t, uint32_t, uint32_t);
  256. void qdf_dp_trace_spin_lock_init(void);
  257. void qdf_dp_trace_init(void);
  258. void qdf_dp_trace_set_value(uint8_t proto_bitmap, uint8_t no_of_records,
  259. uint8_t verbosity);
  260. void qdf_dp_trace_set_track(qdf_nbuf_t nbuf);
  261. void qdf_dp_trace(qdf_nbuf_t nbuf, enum QDF_DP_TRACE_ID code,
  262. uint8_t *data, uint8_t size);
  263. void qdf_dp_trace_dump_all(uint32_t count);
  264. typedef void (*tp_qdf_dp_trace_cb)(struct qdf_dp_trace_record_s* , uint16_t);
  265. void qdf_dp_display_record(struct qdf_dp_trace_record_s *record,
  266. uint16_t index);
  267. /**
  268. * qdf_trace_msg()- logging API
  269. * @module: Module identifier. A member of the QDF_MODULE_ID enumeration that
  270. * identifies the module issuing the trace message.
  271. * @level: Trace level. A member of the QDF_TRACE_LEVEL enumeration indicating
  272. * the severity of the condition causing the trace message to be issued.
  273. * More severe conditions are more likely to be logged.
  274. * @str_format: Format string. The message to be logged. This format string
  275. * contains printf-like replacement parameters, which follow this
  276. * parameter in the variable argument list.
  277. *
  278. * Users wishing to add tracing information to their code should use
  279. * QDF_TRACE. QDF_TRACE() will compile into a call to qdf_trace_msg() when
  280. * tracing is enabled.
  281. *
  282. * Return: nothing
  283. *
  284. */
  285. void __printf(3, 4) qdf_trace_msg(QDF_MODULE_ID module, QDF_TRACE_LEVEL level,
  286. char *str_format, ...);
  287. void qdf_trace_hex_dump(QDF_MODULE_ID module, QDF_TRACE_LEVEL level,
  288. void *data, int buf_len);
  289. void qdf_trace_display(void);
  290. void qdf_trace_set_value(QDF_MODULE_ID module, QDF_TRACE_LEVEL level,
  291. uint8_t on);
  292. void qdf_trace_set_module_trace_level(QDF_MODULE_ID module, uint32_t level);
  293. void __printf(3, 4) qdf_snprintf(char *str_buffer, unsigned int size,
  294. char *str_format, ...);
  295. #define QDF_SNPRINTF qdf_snprintf
  296. #endif /* CONFIG_MCL */
  297. #endif /* __QDF_TRACE_H */