1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
|
/* Copyright (c) 2015, 2018, The Linux Foundation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
* only version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include <asm/arch_timer.h>
#include <linux/err.h>
#include <linux/module.h>
#include <linux/types.h>
#include <soc/qcom/tracer_pkt.h>
#define CREATE_TRACE_POINTS
#include "tracer_pkt_private.h"
static unsigned qdss_tracing;
module_param_named(qdss_tracing_enable, qdss_tracing,
uint, S_IRUGO | S_IWUSR | S_IWGRP);
#define TRACER_PKT_VERSION 1
#define MAX_CC_WLEN 3
#define HEX_DUMP_HDR "Tracer Packet:"
/**
* struct tracer_pkt_hdr - data structure defiining the tracer packet header
* @version: Tracer Packet version.
* @reserved: Reserved fields in the tracer packet.
* @id_valid: Indicates the presence of a subsytem & transport ID.
* @qdss_tracing: Enable the event logging to QDSS.
* @ccl: Client cookie/private information length in words.
* @pkt_len: Length of the tracer packet in words.
* @pkt_offset: Offset into the packet to log events, in words.
* @clnt_event_cfg: Client-specific event configuration bit mask.
* @glink_event_cfg: G-Link-specific event configuration bit mask.
* @base_ts: Base timestamp when the tracer packet is initialized.
* @cc: Client cookie/private information.
*/
struct tracer_pkt_hdr {
uint16_t version:4;
uint16_t reserved:8;
uint16_t id_valid:1;
uint16_t qdss_tracing:1;
uint16_t ccl:2;
uint16_t pkt_len;
uint16_t pkt_offset;
uint16_t clnt_event_cfg;
uint32_t glink_event_cfg;
u64 base_ts;
uint32_t cc[MAX_CC_WLEN];
} __attribute__((__packed__));
/**
* struct tracer_pkt_event - data structure defining the tracer packet event
* @event_id: Event ID.
* @event_ts: Timestamp at which the event occured.
*/
struct tracer_pkt_event {
uint32_t event_id;
uint32_t event_ts;
};
/**
* tracer_pkt_init() - initialize the tracer packet
* @data: Pointer to the buffer to be initialized with a tracer
* packet.
* @data_len: Length of the buffer.
* @client_event_cfg: Client-specific event configuration mask.
* @glink_event_cfg: G-Link-specific event configuration mask.
* @pkt_priv: Private/Cookie information to be added to the tracer
* packet.
* @pkt_priv_len: Length of the private data.
*
* This function is used to initialize a buffer with the tracer packet header.
* The tracer packet header includes the data as passed by the elements in the
* parameters.
*
* Return: 0 on success, standard Linux error codes on failure.
*/
int tracer_pkt_init(void *data, size_t data_len,
uint16_t client_event_cfg, uint32_t glink_event_cfg,
void *pkt_priv, size_t pkt_priv_len)
{
struct tracer_pkt_hdr *pkt_hdr;
if (!data || !data_len)
return -EINVAL;
if (!IS_ALIGNED(data_len, sizeof(uint32_t)))
return -EINVAL;
if (data_len < sizeof(*pkt_hdr))
return -ETOOSMALL;
pkt_hdr = (struct tracer_pkt_hdr *)data;
pkt_hdr->version = TRACER_PKT_VERSION;
pkt_hdr->reserved = 0;
pkt_hdr->id_valid = 0;
pkt_hdr->qdss_tracing = qdss_tracing ? true : false;
if (pkt_priv_len >= MAX_CC_WLEN * sizeof(uint32_t))
pkt_hdr->ccl = MAX_CC_WLEN;
else
pkt_hdr->ccl = pkt_priv_len/sizeof(uint32_t) +
(pkt_priv_len & (sizeof(uint32_t) - 1) ? 1 : 0);
pkt_hdr->pkt_len = data_len / sizeof(uint32_t);
pkt_hdr->pkt_offset = sizeof(*pkt_hdr) / sizeof(uint32_t);
pkt_hdr->clnt_event_cfg = client_event_cfg;
pkt_hdr->glink_event_cfg = glink_event_cfg;
pkt_hdr->base_ts = arch_counter_get_cntvct();
memcpy(pkt_hdr->cc, pkt_priv, pkt_hdr->ccl * sizeof(uint32_t));
return 0;
}
EXPORT_SYMBOL(tracer_pkt_init);
/**
* tracer_pkt_set_event_cfg() - set the event configuration mask in the tracer
* packet
* @data: Pointer to the buffer to be initialized with event
* configuration mask.
* @client_event_cfg: Client-specific event configuration mask.
* @glink_event_cfg: G-Link-specific event configuration mask.
*
* This function is used to initialize a buffer with the event configuration
* mask as passed by the elements in the parameters.
*
* Return: 0 on success, standard Linux error codes on failure.
*/
int tracer_pkt_set_event_cfg(void *data, uint16_t client_event_cfg,
uint32_t glink_event_cfg)
{
struct tracer_pkt_hdr *pkt_hdr;
if (!data)
return -EINVAL;
pkt_hdr = (struct tracer_pkt_hdr *)data;
if (unlikely(pkt_hdr->version != TRACER_PKT_VERSION))
return -EINVAL;
pkt_hdr->clnt_event_cfg = client_event_cfg;
pkt_hdr->glink_event_cfg = glink_event_cfg;
return 0;
}
EXPORT_SYMBOL(tracer_pkt_set_event_cfg);
/**
* tracer_pkt_log_event() - log an event specific to the tracer packet
* @data: Pointer to the buffer containing tracer packet.
* @event_id: Event ID to be logged.
*
* This function is used to log an event specific to the tracer packet.
* The event is logged either into the tracer packet itself or a different
* tracing mechanism as configured.
*
* Return: 0 on success, standard Linux error codes on failure.
*/
int tracer_pkt_log_event(void *data, uint32_t event_id)
{
struct tracer_pkt_hdr *pkt_hdr;
struct tracer_pkt_event event;
if (!data)
return -EINVAL;
pkt_hdr = (struct tracer_pkt_hdr *)data;
if (unlikely(pkt_hdr->version != TRACER_PKT_VERSION))
return -EINVAL;
if (qdss_tracing) {
trace_tracer_pkt_event(event_id, pkt_hdr->cc);
return 0;
}
if (unlikely((pkt_hdr->pkt_len - pkt_hdr->pkt_offset) *
sizeof(uint32_t) < sizeof(event)))
return -ETOOSMALL;
event.event_id = event_id;
event.event_ts = (uint32_t)arch_counter_get_cntvct();
memcpy(data + (pkt_hdr->pkt_offset * sizeof(uint32_t)),
&event, sizeof(event));
pkt_hdr->pkt_offset += sizeof(event)/sizeof(uint32_t);
return 0;
}
EXPORT_SYMBOL(tracer_pkt_log_event);
/**
* tracer_pkt_calc_hex_dump_size() - calculate the hex dump size of a tracer
* packet
* @data: Pointer to the buffer containing tracer packet.
* @data_len: Length of the tracer packet buffer.
*
* This function is used to calculate the length of the buffer required to
* hold the hex dump of the tracer packet.
*
* Return: 0 on success, standard Linux error codes on failure.
*/
size_t tracer_pkt_calc_hex_dump_size(void *data, size_t data_len)
{
size_t hex_dump_size;
struct tracer_pkt_hdr *pkt_hdr;
if (!data || data_len <= 0)
return -EINVAL;
pkt_hdr = (struct tracer_pkt_hdr *)data;
if (unlikely(pkt_hdr->version != TRACER_PKT_VERSION))
return -EINVAL;
/*
* Hex Dump Prefix + newline
* 0x<first_word> + newline
* ...
* 0x<last_word> + newline + null-termination character.
*/
hex_dump_size = strlen(HEX_DUMP_HDR) + 1 + (pkt_hdr->pkt_len * 11) + 1;
return hex_dump_size;
}
EXPORT_SYMBOL(tracer_pkt_calc_hex_dump_size);
/**
* tracer_pkt_hex_dump() - hex dump the tracer packet into a buffer
* @buf: Buffer to contain the hex dump of the tracer packet.
* @buf_len: Length of the hex dump buffer.
* @data: Buffer containing the tracer packet.
* @data_len: Length of the buffer containing the tracer packet.
*
* This function is used to dump the contents of the tracer packet into
* a buffer in a specific hexadecimal format. The hex dump buffer can then
* be dumped through debugfs.
*
* Return: 0 on success, standard Linux error codes on failure.
*/
int tracer_pkt_hex_dump(void *buf, size_t buf_len, void *data, size_t data_len)
{
int i, j = 0;
char *dst = (char *)buf;
if (!buf || buf_len <= 0 || !data || data_len <= 0)
return -EINVAL;
if (buf_len < tracer_pkt_calc_hex_dump_size(data, data_len))
return -EINVAL;
j = scnprintf(dst, buf_len, "%s\n", HEX_DUMP_HDR);
for (i = 0; i < data_len/sizeof(uint32_t); i++)
j += scnprintf(dst + j, buf_len - j, "0x%08x\n",
*((uint32_t *)data + i));
dst[j] = '\0';
return 0;
}
EXPORT_SYMBOL(tracer_pkt_hex_dump);
|