Changeset 60af4cdb in mainline


Ignore:
Timestamp:
2017-10-19T14:01:18Z (7 years ago)
Author:
Michal Staruch <salmelu@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0f6b50f
Parents:
95c675b
Message:

Added get port bandwidth command

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

Legend:

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

    r95c675b r60af4cdb  
    5050#define TRB_SET_SUSP(trb, susp) (trb).control |= host2xhci(32, ((susp) & 0x1) << 23)
    5151#define TRB_SET_SLOT(trb, slot) (trb).control |= host2xhci(32, (slot) << 24)
     52#define TRB_SET_DEV_SPEED(trb, speed)   (trb).control |= host2xhci(32, (speed & 0xF) << 16)
    5253
    5354/**
     
    418419}
    419420
     421int xhci_get_port_bandwidth_command(xhci_hc_t *hc, xhci_cmd_t *cmd,
     422        xhci_port_bandwidth_ctx_t *ctx, uint8_t device_speed)
     423{
     424        assert(hc);
     425        assert(cmd);
     426
     427        xhci_trb_clean(&cmd->trb);
     428
     429        uint64_t phys_addr = (uint64_t) addr_to_phys(ctx);
     430        TRB_SET_ICTX(cmd->trb, phys_addr);
     431
     432        TRB_SET_TYPE(cmd->trb, XHCI_TRB_TYPE_GET_PORT_BANDWIDTH_CMD);
     433        TRB_SET_SLOT(cmd->trb, cmd->slot_id);
     434        TRB_SET_DEV_SPEED(cmd->trb, device_speed);
     435
     436        return enqueue_command(hc, cmd, 0, 0);
     437}
     438
    420439int xhci_handle_command_completion(xhci_hc_t *hc, xhci_trb_t *trb)
    421440{
  • uspace/drv/bus/usb/xhci/commands.h

    r95c675b r60af4cdb  
    4444typedef struct xhci_hc xhci_hc_t;
    4545typedef struct xhci_input_ctx xhci_input_ctx_t;
     46typedef struct xhci_port_bandwidth_ctx xhci_port_bandwidth_ctx_t;
    4647
    4748typedef struct xhci_command {
     
    8788// TODO: Negotiate bandwidth (optional normative, section 4.6.13).
    8889// TODO: Set latency tolerance value (optional normative, section 4.6.14).
     90int xhci_get_port_bandwidth_command(xhci_hc_t *, xhci_cmd_t *, xhci_port_bandwidth_ctx_t *, uint8_t);
    8991// TODO: Get port bandwidth (mandatory, but needs root hub implementation, section 4.6.15).
    9092// TODO: Force header (mandatory, but needs root hub implementation, section 4.6.16).
  • uspace/drv/bus/usb/xhci/hw_struct/context.h

    r95c675b r60af4cdb  
    192192} __attribute__((packed)) xhci_input_ctx_t;
    193193
     194/**
     195 * Port bandwidth context: section 6.2.6
     196 * The number of ports depends on the amount of ports available to the hub.
     197 */
     198typedef struct xhci_port_bandwidth_ctx {
     199        uint8_t reserved;
     200        uint8_t ports [];
     201} __attribute__((packed)) xhci_port_bandwidth_ctx_t;
     202
    194203#endif
  • uspace/drv/bus/usb/xhci/rh.c

    r95c675b r60af4cdb  
    382382}
    383383
     384static inline int get_hub_available_bandwidth(xhci_device_t* dev, uint8_t speed, xhci_port_bandwidth_ctx_t *ctx) {
     385        // TODO: find a correct place for this function + API
     386        // We need speed, because a root hub device has both USB 2 and USB 3 speeds
     387        // and the command can query only one of them
     388        // ctx is an out parameter as of now
     389        assert(dev);
     390
     391        ctx = malloc(sizeof(xhci_port_bandwidth_ctx_t));
     392        if(!ctx)
     393                return ENOMEM;
     394
     395        xhci_cmd_t cmd;
     396        xhci_cmd_init(&cmd);
     397
     398        xhci_get_port_bandwidth_command(dev->hc, &cmd, ctx, speed);
     399
     400        int err = xhci_cmd_wait(&cmd, 100000);
     401        if(err != EOK) {
     402                free(ctx);
     403                ctx = NULL;
     404        }
     405
     406        return EOK;
     407}
     408
    384409const xhci_port_speed_t *xhci_rh_get_port_speed(xhci_rh_t *rh, uint8_t port)
    385410{
Note: See TracChangeset for help on using the changeset viewer.