dhd_dbg_ring.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * DHD debug ring header file
  3. *
  4. * <<Broadcom-WL-IPTag/Open:>>
  5. *
  6. * Portions of this code are copyright (c) 2020 Cypress Semiconductor Corporation
  7. *
  8. * Copyright (C) 1999-2020, Broadcom Corporation
  9. *
  10. * Unless you and Broadcom execute a separate written software license
  11. * agreement governing use of this software, this software is licensed to you
  12. * under the terms of the GNU General Public License version 2 (the "GPL"),
  13. * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  14. * following added to such license:
  15. *
  16. * As a special exception, the copyright holders of this software give you
  17. * permission to link this software with independent modules, and to copy and
  18. * distribute the resulting executable under terms of your choice, provided that
  19. * you also meet, for each linked independent module, the terms and conditions of
  20. * the license of that module. An independent module is a module which is not
  21. * derived from this software. The special exception does not apply to any
  22. * modifications of the software.
  23. *
  24. * Notwithstanding the above, under no circumstances may you combine this
  25. * software in any way with any other Broadcom software provided under a license
  26. * other than the GPL, without Broadcom's express prior written consent.
  27. *
  28. * $Id: dhd_dbg_ring.h 717009 2019-06-06 20:41:11Z $
  29. */
  30. #ifndef __DHD_DBG_RING_H__
  31. #define __DHD_DBG_RING_H__
  32. #include <bcmutils.h>
  33. #define PACKED_STRUCT __attribute__ ((packed))
  34. #define DBGRING_NAME_MAX 32
  35. enum dbg_ring_state {
  36. RING_STOP = 0, /* ring is not initialized */
  37. RING_ACTIVE, /* ring is live and logging */
  38. RING_SUSPEND /* ring is initialized but not logging */
  39. };
  40. /* each entry in dbg ring has below header, to handle
  41. * variable length records in ring
  42. */
  43. typedef struct dhd_dbg_ring_entry {
  44. uint16 len; /* payload length excluding the header */
  45. uint8 flags;
  46. uint8 type; /* Per ring specific */
  47. uint64 timestamp; /* present if has_timestamp bit is set. */
  48. } PACKED_STRUCT dhd_dbg_ring_entry_t;
  49. struct ring_statistics {
  50. /* number of bytes that was written to the buffer by driver */
  51. uint32 written_bytes;
  52. /* number of bytes that was read from the buffer by user land */
  53. uint32 read_bytes;
  54. /* number of records that was written to the buffer by driver */
  55. uint32 written_records;
  56. };
  57. typedef struct dhd_dbg_ring_status {
  58. uint8 name[DBGRING_NAME_MAX];
  59. uint32 flags;
  60. int ring_id; /* unique integer representing the ring */
  61. /* total memory size allocated for the buffer */
  62. uint32 ring_buffer_byte_size;
  63. uint32 verbose_level;
  64. /* number of bytes that was written to the buffer by driver */
  65. uint32 written_bytes;
  66. /* number of bytes that was read from the buffer by user land */
  67. uint32 read_bytes;
  68. /* number of records that was read from the buffer by user land */
  69. uint32 written_records;
  70. } dhd_dbg_ring_status_t;
  71. typedef struct dhd_dbg_ring {
  72. int id; /* ring id */
  73. uint8 name[DBGRING_NAME_MAX]; /* name string */
  74. uint32 ring_size; /* numbers of item in ring */
  75. uint32 wp; /* write pointer */
  76. uint32 rp; /* read pointer */
  77. uint32 rp_tmp; /* tmp read pointer */
  78. uint32 log_level; /* log_level */
  79. uint32 threshold; /* threshold bytes */
  80. void * ring_buf; /* pointer of actually ring buffer */
  81. void * lock; /* lock for ring access */
  82. struct ring_statistics stat; /* statistics */
  83. enum dbg_ring_state state; /* ring state enum */
  84. bool tail_padded; /* writer does not have enough space */
  85. uint32 rem_len; /* number of bytes from wp_pad to end */
  86. bool sched_pull; /* schedule reader immediately */
  87. bool pull_inactive; /* pull contents from ring even if it is inactive */
  88. } dhd_dbg_ring_t;
  89. #define DBGRING_FLUSH_THRESHOLD(ring) (ring->ring_size / 3)
  90. #define RING_STAT_TO_STATUS(ring, status) \
  91. do { \
  92. strncpy(status.name, ring->name, \
  93. sizeof(status.name) - 1); \
  94. status.ring_id = ring->id; \
  95. status.ring_buffer_byte_size = ring->ring_size; \
  96. status.written_bytes = ring->stat.written_bytes; \
  97. status.written_records = ring->stat.written_records; \
  98. status.read_bytes = ring->stat.read_bytes; \
  99. status.verbose_level = ring->log_level; \
  100. } while (0)
  101. #define DBG_RING_ENTRY_SIZE (sizeof(dhd_dbg_ring_entry_t))
  102. #define ENTRY_LENGTH(hdr) ((hdr)->len + DBG_RING_ENTRY_SIZE)
  103. #define PAYLOAD_MAX_LEN 65535
  104. #define PAYLOAD_ECNTR_MAX_LEN 1648u
  105. #define PAYLOAD_RTT_MAX_LEN 1648u
  106. #define PENDING_LEN_MAX 0xFFFFFFFF
  107. #define DBG_RING_STATUS_SIZE (sizeof(dhd_dbg_ring_status_t))
  108. #define TXACTIVESZ(r, w, d) (((r) <= (w)) ? ((w) - (r)) : ((d) - (r) + (w)))
  109. #define DBG_RING_READ_AVAIL_SPACE(w, r, d) (((w) >= (r)) ? ((w) - (r)) : ((d) - (r)))
  110. #define DBG_RING_WRITE_SPACE_AVAIL_CONT(r, w, d) (((w) >= (r)) ? ((d) - (w)) : ((r) - (w)))
  111. #define DBG_RING_WRITE_SPACE_AVAIL(r, w, d) (d - (TXACTIVESZ(r, w, d)))
  112. #define DBG_RING_CHECK_WRITE_SPACE(r, w, d) \
  113. MIN(DBG_RING_WRITE_SPACE_AVAIL(r, w, d), DBG_RING_WRITE_SPACE_AVAIL_CONT(r, w, d))
  114. typedef void (*os_pullreq_t)(void *os_priv, const int ring_id);
  115. int dhd_dbg_ring_init(dhd_pub_t *dhdp, dhd_dbg_ring_t *ring, uint16 id, uint8 *name,
  116. uint32 ring_sz, void *allocd_buf, bool pull_inactive);
  117. void dhd_dbg_ring_deinit(dhd_pub_t *dhdp, dhd_dbg_ring_t *ring);
  118. int dhd_dbg_ring_push(dhd_dbg_ring_t *ring, dhd_dbg_ring_entry_t *hdr, void *data);
  119. int dhd_dbg_ring_pull(dhd_dbg_ring_t *ring, void *data, uint32 buf_len,
  120. bool strip_hdr);
  121. int dhd_dbg_ring_pull_single(dhd_dbg_ring_t *ring, void *data, uint32 buf_len,
  122. bool strip_header);
  123. uint32 dhd_dbg_ring_get_pending_len(dhd_dbg_ring_t *ring);
  124. void dhd_dbg_ring_sched_pull(dhd_dbg_ring_t *ring, uint32 pending_len,
  125. os_pullreq_t pull_fn, void *os_pvt, const int id);
  126. int dhd_dbg_ring_config(dhd_dbg_ring_t *ring, int log_level, uint32 threshold);
  127. void dhd_dbg_ring_start(dhd_dbg_ring_t *ring);
  128. #endif /* __DHD_DBG_RING_H__ */