summaryrefslogtreecommitdiff
path: root/cesar/mac/pbproc/src/trace.c
blob: 21a1e5edb4da248f8a8557f8120ed00fb63e1e2b (plain)
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
/* Cesar project {{{
 *
 * Copyright (C) 2007 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    mac/pbproc/src/trace.c
 * \brief   Define PBProc trace events.
 * \ingroup mac_pbproc
 */
#include "common/std.h"

#include <string.h>
#include <stdio.h>

#include "mac/pbproc/inc/context.h"
#include "inc/fc.h"

/**
 * Format a FC.
 * \see trace_format_t.
 */
static int
pbproc_trace_format_fc (char *text, uint text_size, const int *data,
                        uint size)
{
    static const char *mfs_cmd_str[] = { "INIT", "IN_SYNC", "RE_SYNC",
        "RELEASE", "NOP", "RES=5", "RES=6", "RES=7" };
    static const char *mfs_rsp_str[] = { "ACK", "NACK", "FAIL", "HOLD" };
    static const char *sackt[] = { "m", "mc", "nr", "u" };
    char mrtfl[sizeof ("bbf mrtfl=0xn ")];
    char mpdu_cnt[sizeof ("mpdu_cnt=n ")];
    char burst_cnt[sizeof ("burst_cnt=n ")];
    dbg_assert (size == 4);
#define FC_ACCESS_SNID(fc) \
    ((fc)->generic.access ? "A" : ""), ((fc)->generic.snid)
    int r;
    if (data[0] == -1)
        r = snprintf (text, text_size, "CRC ERROR");
    else
    {
        const pbproc_fc_t *fc = (const void *) data;
        switch (fc->generic.dt_av)
        {
        case PBPROC_FC_DT_BEACON:
            r = snprintf (text, text_size, "BEACON snid=%s%d bts=0x%08x"
                          " bto=%d,%d,%d,%d",
                          FC_ACCESS_SNID (fc), fc->beacon.bts_lsb24
                          | fc->beacon.bts_msb8 << 24, fc->beacon.bto0,
                          fc->beacon.bto1_lsb8 | fc->beacon.bto1_msb8 << 8,
                          fc->beacon.bto2, fc->beacon.bto3_lsb8
                          | fc->beacon.bto3_msb8 << 8);
            break;
        case PBPROC_FC_DT_SOF:
            dbg_check (snprintf (mrtfl, sizeof (mrtfl), "bbf mrtfl=0x%x ",
                                 fc->sof.mrtfl) < (int) sizeof (mrtfl));
            dbg_check (snprintf (mpdu_cnt, sizeof (mpdu_cnt), "mpdu_cnt=%d ",
                                 fc->sof.mpdu_cnt) < (int) sizeof (mpdu_cnt));
            dbg_check (snprintf (burst_cnt, sizeof (burst_cnt),
                                 "burst_cnt=%d ", fc->sof.burst_cnt)
                       < (int) sizeof (burst_cnt));
            r = snprintf (text, text_size,
                          "SOF snid=%s%d stei=0x%02x dtei=0x%02x lid=0x%02x"
                          " %s%s%s%s%s%seks=%d ppb=0x%02x ble=0x%02x"
                          " %snum_sym=%d tmi=%d fl_av=%d "
                          "%s%s%s%s%s%smfs=m%s,%s,m%s,%s sacki=0x%x",
                          FC_ACCESS_SNID (fc), fc->sof.stei, fc->sof.dtei,
                          fc->sof.lid,
                          fc->sof.mcf ? "mcf " : "",
                          fc->sof.mnbf ? "mnbf " : "",
                          fc->sof.cfs ? "cfs " : "",
                          fc->sof.bdf ? "bdf " : "",
                          fc->sof.hp10df ? "hp10df " : "",
                          fc->sof.hp11df ? "hp11df " : "",
                          fc->sof.eks, fc->sof.ppb, fc->sof.ble,
                          fc->sof.pbsz ? "pb136 " : "", fc->sof.num_sym,
                          fc->sof.tmi_av, fc->sof.fl_av,
                          fc->sof.mpdu_cnt ? mpdu_cnt : "",
                          fc->sof.burst_cnt ? burst_cnt : "",
                          fc->sof.bbf ? mrtfl : "",
                          fc->sof.dcppcf ? "dcppcf " : "",
                          fc->sof.rsr ? "rsr " : "",
                          fc->sof.clst ? "clst " : "",
                          mfs_cmd_str[fc->sof.mfs_cmd_mgmt],
                          mfs_cmd_str[fc->sof.mfs_cmd_data],
                          mfs_rsp_str[fc->sof.mfs_rsp_mgmt],
                          mfs_rsp_str[fc->sof.mfs_rsp_data],
                          fc->sof.bm_sacki);
            break;
        case PBPROC_FC_DT_SACK:
            r = snprintf (text, text_size,
                          "SACK snid=%s%d dtei=0x%02x %s%s%s%smfs=%s,m%s"
                          " sackt=%s,%s,%s,%s sacki=0x%08x,0x%08x,0x%02x",
                          FC_ACCESS_SNID (fc), fc->sack.dtei,
                          fc->sack.cfs ? "cfs " : "",
                          fc->sack.bdf ? "bdf " : "",
                          fc->sack.svn ? "svn=1 " : "",
                          fc->sack.rrtf ? "rrtf " : "",
                          mfs_rsp_str[fc->sack.mfs_rsp_data],
                          mfs_rsp_str[fc->sack.mfs_rsp_mgmt],
                          sackt[fc->sack.sackt3],
                          sackt[fc->sack.sackt2],
                          sackt[fc->sack.sackt1],
                          sackt[fc->sack.sackt0],
                          fc->sack.sacki[0], fc->sack.sacki[1],
                          fc->sack.sacki_last);
            break;
        case PBPROC_FC_DT_RTS_CTS:
            r = snprintf (text, text_size,
                          "%s snid=%s%d stei=0x%02x dtei=0x%02x lid=0x%02x"
                          " %s%s%s%s%s%s%sdur=%d",
                          fc->rts_cts.rtsf ? "RTS" : "CTS",
                          FC_ACCESS_SNID (fc), fc->rts_cts.stei,
                          fc->rts_cts.dtei, fc->rts_cts.lid,
                          fc->rts_cts.mcf ? "mcf " : "",
                          fc->rts_cts.mnbf ? "mnbf " : "",
                          fc->rts_cts.cfs ? "cfs " : "",
                          fc->rts_cts.bdf ? "bdf " : "",
                          fc->rts_cts.hp10df ? "hp10df " : "",
                          fc->rts_cts.hp11df ? "hp11df " : "",
                          fc->rts_cts.igf ? "igf " : "",
                          fc->rts_cts.dur);
            break;
        case PBPROC_FC_DT_SOUND:
            dbg_check (snprintf (mpdu_cnt, sizeof (mpdu_cnt), "mpdu_cnt=%d ",
                                 fc->sound.mpdu_cnt)
                       < (int) sizeof (mpdu_cnt));
            r = snprintf (text, text_size,
                          "SOUND snid=%s%d stei=0x%02x dtei=0x%02x lid=0x%02x"
                          " %s%s%s%s%sreq_tm=%d fl_av=%d %sppb=0x%02x"
                          " src=0x%02x",
                          FC_ACCESS_SNID (fc), fc->sound.stei, fc->sound.dtei,
                          fc->sound.lid,
                          fc->sound.cfs ? "cfs " : "",
                          fc->sound.pbsz ? "pb136 " : "",
                          fc->sound.bdf ? "bdf " : "",
                          fc->sound.saf ? "saf " : "",
                          fc->sound.scf ? "scf " : "",
                          fc->sound.req_tm, fc->sound.fl_av,
                          fc->sound.mpdu_cnt ? mpdu_cnt : "", fc->sound.ppb,
                          fc->sound.src);
            break;
        case PBPROC_FC_DT_RSOF:
            r = snprintf (text, text_size,
                          "RSOF snid=%s%d dtei=0x%02x"
                          " %s%s%s%smfs=m%s,%s,%s,m%s sackt=%s,%s,%s,%s"
                          " sacki=0x%08x,0x%04x fl_av=%d tmi=%d %snum_sym=%d",
                          FC_ACCESS_SNID (fc), fc->rsof.dtei,
                          fc->rsof.cfs ? "cfs " : "",
                          fc->rsof.bdf ? "bdf " : "",
                          fc->rsof.svn ? "svn=1 " : "",
                          fc->rsof.rrtf ? "rrtf " : "",
                          mfs_cmd_str[fc->rsof.mfs_cmd_mgmt],
                          mfs_cmd_str[fc->rsof.mfs_cmd_data],
                          mfs_rsp_str[fc->rsof.mfs_rsp_data],
                          mfs_rsp_str[fc->rsof.mfs_rsp_mgmt],
                          sackt[fc->rsof.sackt3],
                          sackt[fc->rsof.sackt2],
                          sackt[fc->rsof.sackt1],
                          sackt[fc->rsof.sackt0],
                          fc->rsof.sacki_lsb, fc->rsof.sacki_msb,
                          fc->rsof.rsof_fl_av <= 0x200 ? fc->rsof.rsof_fl_av
                          : fc->rsof.rsof_fl_av * 2 - 0x200, fc->rsof.tmi_av,
                          fc->rsof.pbsz ? "pb136 " : "",
                          fc->rsof.num_sym);
            break;
        default:
            r = snprintf (text, text_size, "UNKNOWN dt=%d snid=%s%d",
                          fc->generic.dt_av, FC_ACCESS_SNID (fc));
            break;
        }
    }
    return r >= (int) text_size ? -1 : r;
}

/**
 * Format a FSM state.
 * \see trace_format_t.
 */
static int
pbproc_trace_format_state (char *text, uint text_size, int data)
{
    const char *state_name = pbproc_fsm_state_name (data);
    uint state_name_len = strlen (state_name);
    if (state_name_len > text_size)
        return -1;
    else
    {
        memcpy (text, state_name, state_name_len);
        return state_name_len;
    }
}

/**
 * Format a PBDMA status.
 * \see trace_format_t.
 */
static int
pbproc_trace_format_pbdma_status (char *text, uint text_size, int data)
{
    char *t = text;
    uint s = 0;
    phy_pbdma_status_t status = PHY_PBDMA_STATUS (data);
    if (status.pb_null)
    {
        int r = snprintf (t, text_size - s, "N%u", status.null_pb_index);
        if (r >= (int) (text_size - s))
            return -1;
        s += r;
        t += r;
    }
    if (status.pb_crc_error)
    {
        s++;
        if (s > text_size) return -1;
        *t++ = '#';
    }
    if (status.pb_it)
    {
        s++;
        if (s > text_size) return -1;
        *t++ = 'I';
    }
    if (status.end_rx_pb)
    {
        s++;
        if (s > text_size) return -1;
        *t++ = 'R';
    }
    if (status.end_tx_pb)
    {
        s++;
        if (s > text_size) return -1;
        *t++ = 'T';
    }
    if (status.end_chandata)
    {
        s++;
        if (s > text_size) return -1;
        *t++ = 'C';
    }
    if (status.rx_header_load_error || status.ahb_response_error
        || status.chandata_type_forbidden || status.chandata_size_forbidden
        || status.pb_nb_total_null)
    {
        s++;
        if (s > text_size) return -1;
        *t++ = 'X';
    }
    return s;
}

void
pbproc_trace_init (pbproc_t *ctx)
{
    static trace_namespace_t namespace;
    static const trace_event_id_t event_ids[] =
    {
        TRACE_EVENT (PBPROC_TRACE_INIT, "init"),
        TRACE_EVENT (PBPROC_TRACE_UNINIT, "uninit"),
        TRACE_EVENT (PBPROC_TRACE_ACTIVATE, "activate %b", TIMESTAMP),
        TRACE_EVENT (PBPROC_TRACE_RX_SEG_REFILL, "rx seg refill %d"),
        TRACE_EVENT (PBPROC_TRACE_RX_CB, "rx cb pb_nb=%d"),
        TRACE_EVENT (PBPROC_TRACE_RX_BEACON_CB, "rx beacon cb"),
        TRACE_EVENT (PBPROC_TRACE_SPOC_COEFF_SET,
                     "spoc coeff set sync=%b rho_q30=%x"),
        TRACE_EVENT (PBPROC_TRACE_SPOC_UPDATE, "spoc update step=%d",
                     TIMESTAMP),
        TRACE_EVENT (PBPROC_TRACE_FSM_RX_FC, "fsm RX FC pre_date=%x %F",
                     TIMESTAMP),
        TRACE_EVENT (PBPROC_TRACE_FSM_ACCESS, "fsm ACCESS", TIMESTAMP),
        TRACE_EVENT (PBPROC_TRACE_FSM_ACCESS_CONF, "fsm ACCESS CONF",
                     TIMESTAMP),
        TRACE_EVENT (PBPROC_TRACE_FSM_PBDMA, "fsm PBDMA %P", TIMESTAMP),
        TRACE_EVENT (PBPROC_TRACE_FSM_DEFERRED, "fsm DEFERRED", TIMESTAMP),
        TRACE_EVENT (PBPROC_TRACE_FSM_CHANGE_STATE, "fsm change state %S"),
        TRACE_EVENT (PBPROC_TRACE_FSM_UNEXPECTED, "fsm unexpected"),
        TRACE_EVENT (PBPROC_TRACE_FTOP_AIFS, "ftop aifs"),
        TRACE_EVENT (PBPROC_TRACE_FTOP_PRP_LOST, "ftop prp lost"),
        TRACE_EVENT (PBPROC_TRACE_FTOP_TX, "ftop tx mfs=%x dtei=%d lid=%d "
                     "tx_date=%x flp_tck=%d pb_nb=%d"),
        TRACE_EVENT (PBPROC_TRACE_FTOP_TX_INVALID, "ftop tx invalid"),
        TRACE_EVENT (PBPROC_TRACE_FRDA_SACK_UNIFORM,
                     "frda sack uniform sacki=%d"),
        TRACE_EVENT (PBPROC_TRACE_FRDA_SACK_MIXED,
                     "frda sack mixed"),
        TRACE_EVENT (PBPROC_TRACE_FRDA_SACK_MIXED_COMPRESSED,
                     "frda sack mixed compressed"),
        TRACE_EVENT (PBPROC_TRACE_FTDA_TX_BURST, "ftda tx burst tx_date=%x "
                     "flp_tck=%d pb_nb=%d"),
        TRACE_EVENT (PBPROC_TRACE_PREP_MPDU_COMMIT, "commit return_nb=%d"),
    };
    dbg_assert (ctx);
    trace_namespace_init (&namespace, event_ids, COUNT (event_ids));
    trace_namespace_register_format_table (&namespace, 'F',
                                           pbproc_trace_format_fc, 4);
    trace_namespace_register_format (&namespace, 'S',
                                     pbproc_trace_format_state);
    trace_namespace_register_format (&namespace, 'P',
                                     pbproc_trace_format_pbdma_status);
    trace_buffer_add (&ctx->trace, "pbproc", 8, 4, true, &namespace);
}

void
pbproc_trace_uninit (pbproc_t *ctx)
{
    dbg_assert (ctx);
    trace_buffer_remove (&ctx->trace);
}