Changeset 370a1c8 in mainline


Ignore:
Timestamp:
2017-10-02T16:10:28Z (7 years ago)
Author:
Michal Staruch <salmelu@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
04df063
Parents:
4688350b
Message:

Extcap fix, not correctly determine if port is USB 2/3

Location:
uspace/drv/bus/usb/xhci
Files:
6 edited

Legend:

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

    r4688350b r370a1c8  
    287287                        name.packed = host2uint32_t_le(XHCI_REG_RD(ec, XHCI_EC_SP_NAME));
    288288                        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;
     289                        ports_to = ports_from + XHCI_REG_RD(ec, XHCI_EC_SP_CP_COUNT) - 1;
    290290                        usb_log_debug("\tProtocol %4s%u.%u, ports %u-%u", name.str,
    291291                            XHCI_REG_RD(ec, XHCI_EC_SP_MAJOR),
  • uspace/drv/bus/usb/xhci/endpoint.h

    r4688350b r370a1c8  
    4343#include <usb/host/hcd.h>
    4444
     45enum {
     46        EP_TYPE_INVALID = 0,
     47        EP_TYPE_ISOCH_OUT = 1,
     48        EP_TYPE_BULK_OUT = 2,
     49        EP_TYPE_INTERRUPT_OUT = 3,
     50        EP_TYPE_CONTROL = 4,
     51        EP_TYPE_ISOCH_IN = 5,
     52        EP_TYPE_BULK_IN = 6,
     53        EP_TYPE_INTERRUPT_IN = 7
     54};
     55
    4556/** Connector structure linking endpoint context to the endpoint. */
    4657typedef struct xhci_endpoint {
  • uspace/drv/bus/usb/xhci/hc.c

    r4688350b r370a1c8  
    8383                                 * == 0.
    8484                                 */
     85
     86                                unsigned ports_from = XHCI_REG_RD(ec, XHCI_EC_SP_CP_OFF);
     87                                unsigned ports_to = ports_from
     88                                        + XHCI_REG_RD(ec, XHCI_EC_SP_CP_COUNT) - 1;
     89
    8590                                if (major == 2) {
    8691                                        hc->speeds[1] = ps_default_full;
    8792                                        hc->speeds[2] = ps_default_low;
    8893                                        hc->speeds[3] = ps_default_high;
     94                                        hc->rh.usb2_port_start = ports_from;
     95                                        hc->rh.usb2_port_end = ports_to;
    8996                                } else if (major == 3) {
    9097                                        hc->speeds[4] = ps_default_super;
     98                                        hc->rh.usb3_port_start = ports_from;
     99                                        hc->rh.usb3_port_end = ports_to;
    91100                                } else {
    92101                                        return EINVAL;
  • uspace/drv/bus/usb/xhci/hw_struct/context.h

    r4688350b r370a1c8  
    109109#define XHCI_SLOT_CTX_ENTRIES_SET(ctx, val) \
    110110    xhci_dword_set_bits(&(ctx).data[0], val, 31, 27)
     111#define XHCI_SLOT_ROUTE_STRING_SET(ctx, val) \
     112        xhci_dword_set_bits(&(ctx).data[0], (val & 0xFFFFF), 19, 0)
    111113
    112114#define XHCI_SLOT_ROUTE_STRING(ctx)     XHCI_DWORD_EXTRACT((ctx).data[0], 19,  0)
  • uspace/drv/bus/usb/xhci/rh.c

    r4688350b r370a1c8  
    4040#include "debug.h"
    4141#include "commands.h"
     42#include "endpoint.h"
    4243#include "hc.h"
    4344#include "hw_struct/trb.h"
     
    5859// TODO: Check device deallocation, we free device_ctx in hc.c, not
    5960//       sure about the other structs.
    60 static int alloc_dev(xhci_hc_t *hc, uint8_t port)
     61static int alloc_dev(xhci_hc_t *hc, uint8_t port, uint32_t route_str)
    6162{
    6263        int err;
     
    6768
    6869        xhci_send_enable_slot_command(hc, cmd);
    69         if ((err = xhci_wait_for_command(cmd, 100000)) != EOK)
     70        if ((err = xhci_wait_for_command(cmd, 100000)) != EOK) {
     71                usb_log_error("Failed to enable a slot for the device.");
    7072                goto err_command;
     73        }
    7174
    7275        uint32_t slot_id = cmd->slot_id;
     
    9194        XHCI_SLOT_ROOT_HUB_PORT_SET(ictx->slot_ctx, port);
    9295        XHCI_SLOT_CTX_ENTRIES_SET(ictx->slot_ctx, 1);
    93 
    94         // TODO: where do we save this? the ring should be associated with device structure somewhere
     96        XHCI_SLOT_ROUTE_STRING_SET(ictx->slot_ctx, route_str);
     97
    9598        xhci_trb_ring_t *ep_ring = malloc32(sizeof(xhci_trb_ring_t));
    9699        if (!ep_ring) {
     
    103106                goto err_ring;
    104107
    105         xhci_port_regs_t *regs = &hc->op_regs->portrs[port - 1];
    106         uint8_t port_speed_id = XHCI_REG_RD(regs, XHCI_PORT_PS);
    107 
    108         XHCI_EP_TYPE_SET(ictx->endpoint_ctx[0], 4);
     108        XHCI_EP_TYPE_SET(ictx->endpoint_ctx[0], EP_TYPE_CONTROL);
     109        // TODO: must be changed with a command after USB descriptor is read
     110        // See 4.6.5 in XHCI specification, first note
    109111        XHCI_EP_MAX_PACKET_SIZE_SET(ictx->endpoint_ctx[0],
    110             hc->speeds[port_speed_id].tx_bps);
     112            xhci_is_usb3_port(&hc->rh, port) ? 512 : 8);
    111113        XHCI_EP_MAX_BURST_SIZE_SET(ictx->endpoint_ctx[0], 0);
     114        /* FIXME physical pointer? */
    112115        XHCI_EP_TR_DPTR_SET(ictx->endpoint_ctx[0], ep_ring->dequeue);
    113116        XHCI_EP_DCS_SET(ictx->endpoint_ctx[0], 1);
     
    139142        ictx = NULL;
    140143
    141         // TODO: Issue configure endpoint commands (sec 4.3.5).
     144        // TODO: Issue configure endpoint commands (sec 4.3.5).
    142145
    143146        return EOK;
     
    171174        uint8_t link_state = XHCI_REG_RD(regs, XHCI_PORT_PLS);
    172175        // FIXME: do we have a better way to detect if this is usb2 or usb3 device?
    173         if (link_state == 0) {
    174                 /* USB3 is automatically advanced to enabled. */
    175                 uint8_t port_speed = XHCI_REG_RD(regs, XHCI_PORT_PS);
    176                 usb_log_debug2("Detected new device on port %u, port speed id %u.", port_id, port_speed);
    177 
    178                 alloc_dev(hc, port_id);
    179         } else if (link_state == 5) {
    180                 /* USB 3 failed to enable. */
    181                 usb_log_debug("USB 3 port couldn't be enabled.");
    182         } else if (link_state == 7) {
     176        if (xhci_is_usb3_port(&hc->rh, port_id)) {
     177                if(link_state == 0) {
     178                        /* USB3 is automatically advanced to enabled. */
     179                        uint8_t port_speed = XHCI_REG_RD(regs, XHCI_PORT_PS);
     180                        usb_log_debug("Detected new device on port %u, port speed id %u.", port_id, port_speed);
     181
     182                        alloc_dev(hc, port_id, 0);
     183                }
     184                else if (link_state == 5) {
     185                        /* USB 3 failed to enable. */
     186                        usb_log_error("USB 3 port couldn't be enabled.");
     187                }
     188                else {
     189                        usb_log_error("USB 3 port is in invalid state %u.", link_state);
     190                }
     191        }
     192        else {
    183193                usb_log_debug("USB 2 device attached, issuing reset.");
    184194                xhci_reset_hub_port(hc, port_id);
     195                /*
     196                        FIXME: we need to wait for the event triggered by the reset
     197                        and then alloc_dev()... can't it be done directly instead of
     198                        going around?
     199                */
    185200        }
    186201
     
    201216                uint8_t port_speed = XHCI_REG_RD(regs, XHCI_PORT_PS);
    202217                usb_log_debug2("Detected port reset on port %u, port speed id %u.", port_id, port_speed);
    203                 alloc_dev(hc, port_id);
     218                /** FIXME: only if that port is not yet initialized */
     219                alloc_dev(hc, port_id, 0);
    204220        }
    205221
  • uspace/drv/bus/usb/xhci/rh.h

    r4688350b r370a1c8  
    5555        /** Interrupt transfer waiting for an actual interrupt to occur */
    5656        usb_transfer_batch_t *unfinished_interrupt_transfer;
     57
     58        uint8_t usb2_port_start;
     59        uint8_t usb2_port_end;
     60        uint8_t usb3_port_start;
     61        uint8_t usb3_port_end;
    5762} xhci_rh_t;
    5863
     
    7782}
    7883
     84static inline bool xhci_is_usb3_port(xhci_rh_t* rh, uint8_t port) {
     85        return port >= rh->usb3_port_start && port <= rh->usb3_port_end;
     86}
     87
    7988#endif
    8089
Note: See TracChangeset for help on using the changeset viewer.