blob: 4690748fc0d68e606f87fe756b204104fbf02f48 [file] [log] [blame]
Shad Ansari2f7f9be2017-06-07 13:34:53 -07001/*
2<:copyright-BRCM:2016:DUAL/GPL:standard
3
4 Broadcom Proprietary and Confidential.(c) 2016 Broadcom
5 All Rights Reserved
6
7Unless you and Broadcom execute a separate written software license
8agreement governing use of this software, this software is licensed
9to you under the terms of the GNU General Public License version 2
10(the "GPL"), available at http://www.broadcom.com/licenses/GPLv2.php,
11with the following added to such license:
12
13 As a special exception, the copyright holders of this software give
14 you permission to link this software with independent modules, and
15 to copy and distribute the resulting executable under terms of your
16 choice, provided that you also meet, for each linked independent
17 module, the terms and conditions of the license of that module.
18 An independent module is a module which is not derived from this
19 software. The special exception does not apply to any modifications
20 of the software.
21
22Not withstanding the above, under no circumstances may you combine
23this software in any way with any other Broadcom software provided
24under a license other than the GPL, without Broadcom's express prior
25written consent.
26
27:>
28 */
29
30#ifndef BCMTR_DEBUG_H_
31#define BCMTR_DEBUG_H_
32
33#include <bcm_config.h>
34#include <bcmolt_msg_pack.h>
35#include <bcmtr_header.h>
36#include <bcmolt_msg.h>
37#include <bcmcli.h>
38
39/* CLD stands for capture,log,debug */
40
41/** Capture, log, debug type */
42typedef enum
43{
44 BCMTR_CLD_NONE = 0, /**< Off */
45 BCMTR_CLD_CAPTURE = 0x01, /**< Message capture */
46 BCMTR_CLD_LOG = 0x02, /**< Message logging */
47 BCMTR_CLD_DUMP_HDR = 0x04, /**< Message header dump */
48 BCMTR_CLD_DUMP = 0x0C, /**< Message header and body dump */
49} bcmtr_cld_type;
50
51/** Event type */
52typedef enum
53{
54 BCMTR_CLD_EV_SEND, /**< Send message */
55 BCMTR_CLD_EV_RESEND, /**< Retransmit message */
56 BCMTR_CLD_EV_RECV, /**< Receive message */
57 BCMTR_CLD_EV_RECV_DISCARD, /**< Receive message discarded */
58 BCMTR_CLD_EV_TIMEOUT, /**< Request timed out waiting for response */
59} bcmtr_cld_event_type;
60
61/** Capture, log, debug filter */
62typedef struct
63{
64 bcmolt_mgt_group group; /**< Message group. Can be BCMOLT_MGT_GROUP_ANY */
65 bcmolt_obj_id object; /**< Object. Can be BCMOLT_OBJECT_ANY */
66 uint16_t subgroup; /**< Message subgroup. Can be BCMOLT_SUBGROUP_ANY */
67} bcmtr_cld_filter;
68
69/** Initialize transport capture,log, debug service
70 * \param[in] parent Parent CLI directory. Can be NULL
71 * \returns BCM_ERR_OK or error code
72 */
73bcmos_errno bcmtr_cld_init(bcmcli_session *session);
74
75/** Clean up transport capture, log, debug service
76 */
77void bcmtr_cld_exit(void);
78
79/** Set capture, log, debug for selected messages
80 * \param[in] device Device id
81 * \param[in] filter Message filter
82 * \param[in] cld_level Capture, log, debug level. Can be a combination of BCMTR_CLD_.. constants
83 * \returns BCM_ERR_OK or error code
84 */
85bcmos_errno bcmtr_cld_level_set(bcmolt_devid device, const bcmtr_cld_filter *filter, bcmtr_cld_type cld_level);
86
87/** Get capture, log, debug for selected message
88 * \param[in] device Device id
89 * \param[in] filter Message filter. Wildcards are not allowed.
90 * \param[out] cld_level Capture, log, debug level
91 * \returns BCM_ERR_OK or error code
92 */
93bcmos_errno bcmtr_cld_level_get(bcmolt_devid device, const bcmtr_cld_filter *filter, bcmtr_cld_type *cld_level);
94
95/*
96 * Message capture functions
97 */
98
99/**
100 * Message capture facility allows capturing messages between the host
101 * and OLT at real time. The recorded trace can be dumped in
102 * human readable format or "played back" in order to reproduce
103 * the configuration under test.
104 * @{
105 */
106
107/** Minimal trace buffer size (bytes) */
108#define BCMTR_CAPTURE_MIN_BUF_SIZE (16*1024)
109
110/** Capture buffer configuration parameters */
111typedef struct bcmtr_capture_parm
112{
113 uint32_t size; /**< Capture buffer size. Must be at least \ref BCMTR_CAPTURE_MIN_BUF_SIZE bytes */
114 void *ptr; /**< Optional capture buffer pointer. Allocated automatically if NULL */
115 bcmos_bool stop_on_full; /**< TRUE-stop recording when buffer is full. FALSE=circular buffer */
116 bcmos_bool activate; /**< Auto-activate capture immediately after init */
117} bcmtr_capture_parm;
118
119/** Capture info record */
120typedef struct bcmtr_capture_info
121{
122 uint32_t size; /**< Capture buffer size */
123 uint32_t used; /**< Used bytes */
124 uint32_t wa; /**< Number of times capture buffer wrapped around */
125 uint32_t msgs; /**< Number of complete messages stored in the capture buffer */
126 uint32_t lost; /**< Number of messages lost due to buffer overflow */
127} bcmtr_capture_info;
128
129/* Capture entry header
130 *
131 * Followed by msg_size bytes of message data
132 */
133typedef struct
134{
135 uint32_t msg_size; /**< Message size (bytes); MUST be the first member */
136 uint32_t event; /**< bcmtr_cld_event_type event */
137 uint32_t timestamp; /**< Message timestamp (us) */
138 /* Followed by message data padded to the nearest 4 bytes */
139} bcmtr_capture_entry;
140
141/** Initialize capture buffer
142 *
143 * This function must be called first.
144 * \param[in] olt Olt index
145 * \param[in] cfg Capture configuration parameters
146 * \return 0=success or error code
147 */
148bcmos_errno bcmtr_capture_init(bcmolt_devid olt, const bcmtr_capture_parm *parm);
149
150/** Destroy capture buffer
151 *
152 * Destroy buffer initialized by bcmtr_capture_Init().
153 * \param[in] olt Olt index
154 * Following this call all recording is lost.
155 */
156void bcmtr_capture_destroy(bcmolt_devid olt);
157
158/** Get capture recording info
159 *
160 * \param[in] olt Olt index
161 * \param[out] info Capture information
162 * \return 0=success or error code
163 */
164bcmos_errno bcmtr_capture_info_get(bcmolt_devid olt, bcmtr_capture_info *info);
165
166/** Get the number of readable bytes in the capture buffer
167 *
168 * \param[in] olt OLT index
169 * \param[out] size Number of readable bytes
170 */
171bcmos_errno bcmtr_capture_size_get(bcmolt_devid olt, uint32_t *size);
172
173/** Read portion of capture
174 *
175 * This function reads recorded data into a user buffer starting at the specified offset from the beginning of the
176 * capture up to the specified length. Applications can use this function in order to save capture into file or dump it.
177 *
178 * \param[in] olt OLT index
179 * \param[out] buf User buffer
180 * \param[in] offset Buffer offset to start read (bytes)
181 * \param[in/out] length in: Maximum number of bytes to read into the user buffer
182 * out: Remaining unused bytes in user buffer
183 * \return 0=success or error code
184 */
185bcmos_errno bcmtr_capture_read(bcmolt_devid olt, uint8_t *buf, uint32_t offset, uint32_t *length);
186
187/** Advance buffer to next capture entry
188 *
189 * Helper function used to scan buffer read by bcmtr_capture_read()
190 *
191 * \param[in/out] buf Capture buffer
192 * \param[out] hdr Capture entry header
193 * \param[out] msg Pointer to packed message
194 */
195bcmos_bool bcmtr_capture_entry_get_next(bcmolt_buf *buf, bcmtr_capture_entry *hdr, uint8_t **msg);
196
197/** Decode and dump capture recording
198 *
199 * This function interprets and dumps capture recording.
200 *
201 * \param[in] session CLI session
202 * \param[in] olt OLT index
203 * \param[out] nmsgs Number of messages dumped
204 * \return 0=success or error code
205 */
206bcmos_errno bcmtr_capture_dump(bcmcli_session *session, bcmolt_devid olt, uint32_t *nmsgs);
207
208/** (Re)start / Suspend capture recording
209 *
210 * \param[in] olt OLT index
211 * \param[in] start TRUE=start, FALSE=suspend
212 * \return 0=success or error code
213 */
214bcmos_errno bcmtr_capture_start_stop(bcmolt_devid olt, bcmos_bool start);
215
216/** Are we actively capturing?
217 *
218 * \param[in] olt OLT index
219 * \return TRUE=actively capturing, FALSE=NOT capturing
220 */
221bcmos_bool bcmtr_capture_is_active(bcmolt_devid olt);
222
223/** Convert entry to platform specific format
224 *
225 * \param[in/out] buf Capture buffer
226 * \param[out] entry Capture entry header
227 *
228 * \return TRUE if success, FALSE otherwise
229 */
230bcmos_bool bcmtr_capture_entry_unpack(bcmolt_buf *buf, bcmtr_capture_entry *entry);
231
232/*
233 * Internal functions - called from transport level
234 */
235
236/* Per-OLT, per-command combined trace,log,debug level */
237extern bcmtr_cld_type bcmtr_cld_active_level[BCMTR_MAX_OLTS][BCMOLT_GROUP_ID__NUM_OF];
238
239/* Notify message.
240 * Called by transport layer
241 */
242void bcmtr_cld_notify(bcmolt_devid device, const bcmtr_hdr *hdr,
243 bcmtr_cld_event_type ev, uint32_t ts, const uint8_t *packed, uint32_t packed_length,
244 bcmolt_msg *msg);
245
246/* Check if CLD is enabled for the message and record if yes
247 * Called by transport layer
248 */
249#define BCMTR_CLD_CHECK_NOTIFY(_device, _hdr, _ev, _ts, _packed, _packed_length, _msg) \
250 do {\
251 if (bcmtr_cld_active_level[_device][(_hdr)->msg_id]) \
252 { \
253 bcmtr_cld_notify(_device, _hdr, _ev, _ts, _packed, _packed_length, _msg); \
254 } \
255 } while (0)
256
257#endif /* BCMTR_DEBUG_H_ */