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