summaryrefslogtreecommitdiff
path: root/bsp/phytium/libraries/standalone/drivers/usb/fxhci/fxhci_debug.c
blob: 027a7f439061c1c5733b715346ad12cea1c7e35e (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
/*
 * Copyright : (C) 2022 Phytium Information Technology, Inc.
 * All Rights Reserved.
 *
 * This program is OPEN SOURCE software: you can redistribute it and/or modify it
 * under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
 * either version 1.0 of the License, or (at your option) any later version.
 *
 * 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 Phytium Public License for more details.
 *
 *
 * FilePath: fxhci_debug.c
 * Date: 2022-02-11 13:33:12
 * LastEditTime: 2022-02-18 09:12:15
 * Description:  This files is for implementation of XHCI debug utilities
 *
 * Modify History:
 *  Ver   Who        Date         Changes
 * ----- ------     --------    --------------------------------------
 * 1.0   Zhugengyu  2022/2/7    init commit
 */

#include <inttypes.h>
#include "fdebug.h"
#include "fxhci_private.h"

#define FUSB_DEBUG_TAG "FXHCI_DEBUG"
#define FUSB_ERROR(format, ...) FT_DEBUG_PRINT_E(FUSB_DEBUG_TAG, format, ##__VA_ARGS__)
#define FUSB_WARN(format, ...) FT_DEBUG_PRINT_W(FUSB_DEBUG_TAG, format, ##__VA_ARGS__)
#define FUSB_INFO(format, ...) FT_DEBUG_PRINT_I(FUSB_DEBUG_TAG, format, ##__VA_ARGS__)
#define FUSB_DEBUG(format, ...) FT_DEBUG_PRINT_D(FUSB_DEBUG_TAG, format, ##__VA_ARGS__)

void FXhciDumpSlotCtx(const FXhciSlotCtx *const sc)
{
    FUSB_INFO("Slot Context (@%p): ", sc);
    FUSB_INFO(" FIELD1\t0x%08x ", sc->f1);
    FUSB_INFO(" FIELD2\t0x%08x ", sc->f2);
    FUSB_INFO(" FIELD3\t0x%08x ", sc->f3);
    FUSB_INFO(" FIELD4\t0x%08x ", sc->f4);
    FXHCI_SC_DUMP(FUSB_INFO, ROUTE, sc);
    FXHCI_SC_DUMP(FUSB_INFO, SPEED1, sc);
    FXHCI_SC_DUMP(FUSB_INFO, MTT, sc);
    FXHCI_SC_DUMP(FUSB_INFO, HUB, sc);
    FXHCI_SC_DUMP(FUSB_INFO, CTXENT, sc);
    FXHCI_SC_DUMP(FUSB_INFO, RHPORT, sc);
    FXHCI_SC_DUMP(FUSB_INFO, NPORTS, sc);
    FXHCI_SC_DUMP(FUSB_INFO, TTID, sc);
    FXHCI_SC_DUMP(FUSB_INFO, TTPORT, sc);
    FXHCI_SC_DUMP(FUSB_INFO, TTT, sc);
    FXHCI_SC_DUMP(FUSB_INFO, UADDR, sc);
    FXHCI_SC_DUMP(FUSB_INFO, STATE, sc);
}

void FXhciDumpEpCtx(const FXhciEpCtx *const ec)
{
    FUSB_INFO("Endpoint Context (@%p): ", ec);
    FUSB_INFO(" FIELD1\t0x%08x ", ec->f1);
    FUSB_INFO(" FIELD2\t0x%08x ", ec->f2);
    FUSB_INFO(" TRDQ_L\t0x%08x ", ec->tr_dq_low);
    FUSB_INFO(" TRDQ_H\t0x%08x ", ec->tr_dq_high);
    FUSB_INFO(" FIELD5\t0x%08x ", ec->f5);
    FXHCI_EC_DUMP(FUSB_INFO, STATE, ec);
    FXHCI_EC_DUMP(FUSB_INFO, INTVAL, ec);
    FXHCI_EC_DUMP(FUSB_INFO, CERR, ec);
    FXHCI_EC_DUMP(FUSB_INFO, TYPE, ec);
    FXHCI_EC_DUMP(FUSB_INFO, MBS, ec);
    FXHCI_EC_DUMP(FUSB_INFO, MPS, ec);
    FXHCI_EC_DUMP(FUSB_INFO, DCS, ec);
    FXHCI_EC_DUMP(FUSB_INFO, AVRTRB, ec);
    FXHCI_EC_DUMP(FUSB_INFO, MXESIT, ec);
}

void FXhciDumpDevCtx(const FXhciDevCtx *const dc, const u32 ctx_mask)
{
    unsigned int i;

    if (ctx_mask & 1)
        FXhciDumpSlotCtx(dc->slot);

    for (i = 1; i <= FXHCI_SC_GET(CTXENT, dc->slot); ++i)
    {
        if (ctx_mask & (1 << i))
            FXhciDumpEpCtx(dc->ep[i]);
    }
}

void FXhciDumpInputCtx(const FXhciInputCtx *const ic)
{
    FUSB_INFO("Input Control  add: 0x%08x ", *ic->add);
    FUSB_INFO("Input Control drop: 0x%08x ", *ic->drop);
    FXhciDumpDevCtx(&ic->dev, *ic->add);
}

void FXhciDumpTransferTrb(const FXhciTrb *const cur)
{
    FUSB_INFO("Transfer TRB (@%p): ", cur);
    FUSB_INFO(" PTR_L\t0x%08x ", cur->ptr_low);
    FUSB_INFO(" PTR_H\t0x%08x ", cur->ptr_high);
    FUSB_INFO(" STATUS\t0x%08x ", cur->status);
    FUSB_INFO(" CNTRL\t0x%08x ", cur->control);
    FXHCI_TRB_DUMP(FUSB_INFO, TL, cur);
    FXHCI_TRB_DUMP(FUSB_INFO, TDS, cur);
    FXHCI_TRB_DUMP(FUSB_INFO, C, cur);
    FXHCI_TRB_DUMP(FUSB_INFO, ISP, cur);
    FXHCI_TRB_DUMP(FUSB_INFO, CH, cur);
    FXHCI_TRB_DUMP(FUSB_INFO, IOC, cur);
    FXHCI_TRB_DUMP(FUSB_INFO, IDT, cur);
    FXHCI_TRB_DUMP(FUSB_INFO, TT, cur);
    FXHCI_TRB_DUMP(FUSB_INFO, DIR, cur);
}

static const FXhciTrb *FXhciNextTrb(const FXhciTrb *const cur)
{
    if (FXHCI_TRB_GET(TT, cur) == FXHCI_TRB_LINK)
        return (!cur->ptr_low) ? NULL : (void *)(uintptr)(cur->ptr_low);
    else
        return cur + 1;
}

void FXhciDumpTransferTrbs(const FXhciTrb *const first, const FXhciTrb *const last)
{
    const FXhciTrb *cur;
    for (cur = first; cur; cur = FXhciNextTrb(cur))
    {
        FXhciDumpTransferTrb(cur);
        if (cur == last)
            break;
    }
}