Changeset 91ca111 in mainline for uspace/drv/bus/usb/xhci/debug.c


Ignore:
Timestamp:
2017-06-23T11:18:50Z (7 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
51b2693
Parents:
e4d7363
Message:

xhci: extended capability handling

Currently, only detection of legacy support and parsing of protocol speeds is
implemented.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/xhci/debug.c

    re4d7363 r91ca111  
    3535
    3636#include <inttypes.h>
     37#include <byteorder.h>
    3738#include <usb/debug.h>
    3839
     
    6061 * Dumps all capability registers.
    6162 */
    62 void xhci_dump_cap_regs(xhci_cap_regs_t *cap)
     63void xhci_dump_cap_regs(const xhci_cap_regs_t *cap)
    6364{
    6465        usb_log_debug2("Capabilities:");
     
    99100}
    100101
    101 void xhci_dump_port(xhci_port_regs_t *port)
     102void xhci_dump_port(const xhci_port_regs_t *port)
    102103{
    103104        DUMP_REG(port, XHCI_PORT_CCS);
     
    124125}
    125126
    126 void xhci_dump_state(xhci_hc_t *hc)
     127void xhci_dump_state(const xhci_hc_t *hc)
    127128{
    128129        usb_log_debug2("Operational registers:");
     
    171172}
    172173
    173 void xhci_dump_ports(xhci_hc_t *hc)
     174void xhci_dump_ports(const xhci_hc_t *hc)
    174175{
    175176        const size_t num_ports = XHCI_REG_RD(hc->cap_regs, XHCI_CAP_MAX_PORTS);
     
    230231}
    231232
    232 void xhci_dump_trb(xhci_trb_t *trb)
     233void xhci_dump_trb(const xhci_trb_t *trb)
    233234{
    234235        usb_log_debug2("TRB(%p): type %s, cycle %u", trb, xhci_trb_str_type(TRB_TYPE(*trb)), TRB_CYCLE(*trb));
     236}
     237
     238static const char *ec_ids [] = {
     239        [0] = "<empty>",
     240#define EC(t) [XHCI_EC_##t] = #t
     241        EC(USB_LEGACY),
     242        EC(SUPPORTED_PROTOCOL),
     243        EC(EXTENDED_POWER_MANAGEMENT),
     244        EC(IOV),
     245        EC(MSI),
     246        EC(LOCALMEM),
     247        EC(DEBUG),
     248        EC(MSIX),
     249#undef EC
     250        [XHCI_EC_MAX] = NULL
     251};
     252
     253const char *xhci_ec_str_id(unsigned id)
     254{
     255        static char buf [20];
     256
     257        if (id < XHCI_EC_MAX && ec_ids[id] != NULL)
     258                return ec_ids[id];
     259
     260        snprintf(buf, sizeof(buf), "<unknown (%u)>", id);
     261        return buf;
     262}
     263
     264static void xhci_dump_psi(const xhci_psi_t *psi)
     265{
     266        static const char speed_exp [] = " KMG";
     267        static const char *psi_types [] = { "", " rsvd", " RX", " TX" };
     268       
     269        usb_log_debug("Speed %u%s: %5u %cb/s, %s",
     270            XHCI_REG_RD(psi, XHCI_PSI_PSIV),
     271            psi_types[XHCI_REG_RD(psi, XHCI_PSI_PLT)],
     272            XHCI_REG_RD(psi, XHCI_PSI_PSIM),
     273            speed_exp[XHCI_REG_RD(psi, XHCI_PSI_PSIE)],
     274            XHCI_REG_RD(psi, XHCI_PSI_PFD) ? "full-duplex" : "");
     275}
     276
     277void xhci_dump_extcap(const xhci_extcap_t *ec)
     278{
     279        xhci_sp_name_t name;
     280        unsigned ports_from, ports_to;
     281
     282        unsigned id = XHCI_REG_RD(ec, XHCI_EC_CAP_ID);
     283        usb_log_debug("Extended capability %s", xhci_ec_str_id(id));
     284
     285        switch (id) {
     286                case XHCI_EC_SUPPORTED_PROTOCOL:
     287                        name.packed = host2uint32_t_le(XHCI_REG_RD(ec, XHCI_EC_SP_NAME));
     288                        ports_from = XHCI_REG_RD(ec, XHCI_EC_SP_CP_OFF);
     289                        ports_to = ports_from + XHCI_REG_RD(ec, XHCI_EC_SP_CP_OFF) - 1;
     290                        usb_log_debug("\tProtocol %4s%u.%u, ports %u-%u", name.str,
     291                            XHCI_REG_RD(ec, XHCI_EC_SP_MAJOR),
     292                            XHCI_REG_RD(ec, XHCI_EC_SP_MINOR),
     293                            ports_from, ports_to);
     294
     295                        unsigned psic = XHCI_REG_RD(ec, XHCI_EC_SP_PSIC);
     296                        for (unsigned i = 0; i < psic; i++)
     297                                xhci_dump_psi(xhci_extcap_psi(ec, i));
     298                        break;
     299        }
    235300}
    236301
Note: See TracChangeset for help on using the changeset viewer.