Changeset 3bacee1 in mainline for uspace/drv/bus/usb/xhci


Ignore:
Timestamp:
2018-04-12T16:27:17Z (8 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3cf22f9
Parents:
76d0981d
git-author:
Jiri Svoboda <jiri@…> (2018-04-11 19:25:33)
git-committer:
Jiri Svoboda <jiri@…> (2018-04-12 16:27:17)
Message:

Make ccheck-fix again and commit more good files.

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

Legend:

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

    r76d0981d r3bacee1  
    159159        }
    160160
    161         return cmd_link
    162             ? list_get_instance(cmd_link, xhci_cmd_t, _header.link)
    163             : NULL;
     161        return cmd_link ?
     162            list_get_instance(cmd_link, xhci_cmd_t, _header.link) :
     163            NULL;
    164164}
    165165
  • uspace/drv/bus/usb/xhci/debug.c

    r76d0981d r3bacee1  
    382382}
    383383
    384 void xhci_dump_input_ctx(const xhci_hc_t * hc, const struct xhci_input_ctx *ictx)
     384void xhci_dump_input_ctx(const xhci_hc_t *hc, const struct xhci_input_ctx *ictx)
    385385{
    386386        xhci_device_ctx_t *device_ctx = XHCI_GET_DEVICE_CTX(ictx, hc);
     
    400400
    401401        for (uint8_t dci = 1; dci <= XHCI_EP_COUNT; dci++)
    402                 if (XHCI_INPUT_CTRL_CTX_DROP(*ctrl_ctx, dci)
    403                     || XHCI_INPUT_CTRL_CTX_ADD(*ctrl_ctx, dci)) {
     402                if (XHCI_INPUT_CTRL_CTX_DROP(*ctrl_ctx, dci) ||
     403                    XHCI_INPUT_CTRL_CTX_ADD(*ctrl_ctx, dci)) {
    404404                        usb_log_debug("Endpoint context DCI %u:", dci);
    405405                        xhci_ep_ctx_t *ep_ctx = XHCI_GET_EP_CTX(device_ctx, hc, dci);
  • uspace/drv/bus/usb/xhci/endpoint.c

    r76d0981d r3bacee1  
    5959 */
    6060static errno_t xhci_endpoint_init(xhci_endpoint_t *xhci_ep, device_t *dev,
    61         const usb_endpoint_descriptors_t *desc)
     61    const usb_endpoint_descriptors_t *desc)
    6262{
    6363        errno_t rc;
     
    8888        if (dev->speed >= USB_SPEED_SUPER) {
    8989                ep->packets_per_uframe = xhci_ep->max_burst * xhci_ep->mult;
    90                 if (ep->transfer_type == USB_TRANSFER_ISOCHRONOUS
    91                         || ep->transfer_type == USB_TRANSFER_INTERRUPT) {
     90                if (ep->transfer_type == USB_TRANSFER_ISOCHRONOUS ||
     91                    ep->transfer_type == USB_TRANSFER_INTERRUPT) {
    9292                        ep->max_transfer_size = ep->max_packet_size * ep->packets_per_uframe;
    9393                }
     
    100100         * others have 2-based log of it.
    101101         */
    102         if (dev->speed >= USB_SPEED_HIGH
    103             || ep->transfer_type != USB_TRANSFER_INTERRUPT) {
     102        if (dev->speed >= USB_SPEED_HIGH ||
     103            ep->transfer_type != USB_TRANSFER_INTERRUPT) {
    104104                xhci_ep->interval = 1 << (xhci_ep->interval - 1);
    105105        }
     
    141141 */
    142142endpoint_t *xhci_endpoint_create(device_t *dev,
    143         const usb_endpoint_descriptors_t *desc)
     143    const usb_endpoint_descriptors_t *desc)
    144144{
    145145        const usb_transfer_type_t type = USB_ED_GET_TRANSFER_TYPE(desc->endpoint);
    146146
    147         xhci_endpoint_t *ep = calloc(1, sizeof(xhci_endpoint_t)
    148                 + (type == USB_TRANSFER_ISOCHRONOUS) * sizeof(*ep->isoch));
     147        xhci_endpoint_t *ep = calloc(1, sizeof(xhci_endpoint_t) +
     148            (type == USB_TRANSFER_ISOCHRONOUS) * sizeof(*ep->isoch));
    149149        if (!ep)
    150150                return NULL;
     
    230230        }
    231231
    232         usb_transfer_batch_t * const batch = ep->active_batch;
     232        usb_transfer_batch_t *const batch = ep->active_batch;
    233233
    234234        const errno_t err = hc_stop_endpoint(xhci_ep);
     
    289289
    290290        case USB_TRANSFER_ISOCHRONOUS:
    291                 return in ? EP_TYPE_ISOCH_IN
    292                           : EP_TYPE_ISOCH_OUT;
     291                return in ? EP_TYPE_ISOCH_IN :
     292                    EP_TYPE_ISOCH_OUT;
    293293
    294294        case USB_TRANSFER_BULK:
    295                 return in ? EP_TYPE_BULK_IN
    296                           : EP_TYPE_BULK_OUT;
     295                return in ? EP_TYPE_BULK_IN :
     296                    EP_TYPE_BULK_OUT;
    297297
    298298        case USB_TRANSFER_INTERRUPT:
    299                 return in ? EP_TYPE_INTERRUPT_IN
    300                           : EP_TYPE_INTERRUPT_OUT;
     299                return in ? EP_TYPE_INTERRUPT_IN :
     300                    EP_TYPE_INTERRUPT_OUT;
    301301        }
    302302
  • uspace/drv/bus/usb/xhci/hc.c

    r76d0981d r3bacee1  
    8787        xhci_port_speed_t *speeds = hc->speeds;
    8888
    89         for (xhci_extcap_t *ec = hc->xecp; ec; ec = xhci_extcap_next(ec)) {
     89        for (xhci_extcap_t * ec = hc->xecp; ec; ec = xhci_extcap_next(ec)) {
    9090                xhci_dump_extcap(ec);
    9191                switch (XHCI_REG_RD(ec, XHCI_EC_CAP_ID)) {
     
    151151                                         * mapping also for devices connected to hubs.
    152152                                         */
    153                                         if (psiv < ARRAY_SIZE(default_psiv_to_port_speed)
    154                                            && default_psiv_to_port_speed[psiv].major == major
    155                                            && default_psiv_to_port_speed[psiv].minor == minor
    156                                            && default_psiv_to_port_speed[psiv].rx_bps == bps
    157                                            && default_psiv_to_port_speed[psiv].tx_bps == bps) {
     153                                        if (psiv < ARRAY_SIZE(default_psiv_to_port_speed) &&
     154                                            default_psiv_to_port_speed[psiv].major == major &&
     155                                            default_psiv_to_port_speed[psiv].minor == minor &&
     156                                            default_psiv_to_port_speed[psiv].rx_bps == bps &&
     157                                            default_psiv_to_port_speed[psiv].tx_bps == bps) {
    158158                                                speeds[psiv] = default_psiv_to_port_speed[psiv];
    159159                                                usb_log_debug("Assumed default %s speed of USB %u.",
    160                                                         usb_str_speed(speeds[psiv].usb_speed), major);
     160                                                    usb_str_speed(speeds[psiv].usb_speed), major);
    161161                                                continue;
    162162                                        }
     
    173173                                                speeds[psiv].tx_bps = bps;
    174174                                                usb_log_debug("Speed %u set up for bps %" PRIu64
    175                                                         " / %" PRIu64 ".", psiv, speeds[psiv].rx_bps,
    176                                                         speeds[psiv].tx_bps);
     175                                                    " / %" PRIu64 ".", psiv, speeds[psiv].rx_bps,
     176                                                    speeds[psiv].tx_bps);
    177177                                        }
    178178                                }
     
    384384        code->rangecount = 1;
    385385        code->ranges[0] = (irq_pio_range_t) {
    386             .base = RNGABS(hc->mmio_range),
    387             .size = RNGSZ(hc->mmio_range),
     386                .base = RNGABS(hc->mmio_range),
     387                .size = RNGSZ(hc->mmio_range),
    388388        };
    389389
     
    391391        memcpy(code->cmds, irq_commands, sizeof(irq_commands));
    392392
    393         void *intr0_iman = RNGABSPTR(hc->mmio_range)
    394             + XHCI_REG_RD(hc->cap_regs, XHCI_CAP_RTSOFF)
    395             + offsetof(xhci_rt_regs_t, ir[0]);
    396         void *usbsts = RNGABSPTR(hc->mmio_range)
    397             + XHCI_REG_RD(hc->cap_regs, XHCI_CAP_LENGTH)
    398             + offsetof(xhci_op_regs_t, usbsts);
     393        void *intr0_iman = RNGABSPTR(hc->mmio_range) +
     394            XHCI_REG_RD(hc->cap_regs, XHCI_CAP_RTSOFF) +
     395            offsetof(xhci_rt_regs_t, ir[0]);
     396        void *usbsts = RNGABSPTR(hc->mmio_range) +
     397            XHCI_REG_RD(hc->cap_regs, XHCI_CAP_LENGTH) +
     398            offsetof(xhci_op_regs_t, usbsts);
    399399
    400400        code->cmds[0].addr = intr0_iman;
     
    425425        for (int i = 0; i <= (XHCI_LEGSUP_BIOS_TIMEOUT_US / XHCI_LEGSUP_POLLING_DELAY_1MS); i++) {
    426426                usb_log_debug("LEGSUP: elapsed: %i ms, bios: %x, os: %x", i,
    427                         XHCI_REG_RD(hc->legsup, XHCI_LEGSUP_SEM_BIOS),
    428                         XHCI_REG_RD(hc->legsup, XHCI_LEGSUP_SEM_OS));
     427                    XHCI_REG_RD(hc->legsup, XHCI_LEGSUP_SEM_BIOS),
     428                    XHCI_REG_RD(hc->legsup, XHCI_LEGSUP_SEM_OS));
    429429                if (XHCI_REG_RD(hc->legsup, XHCI_LEGSUP_SEM_BIOS) == 0) {
    430430                        return XHCI_REG_RD(hc->legsup, XHCI_LEGSUP_SEM_OS) == 1 ? EOK : EIO;
     
    559559        const uint32_t usbsts = XHCI_REG_RD_FIELD(&hc->op_regs->usbsts, 32);
    560560
    561         return !(usbcmd & XHCI_REG_MASK(XHCI_OP_RS))
    562             ||  (usbsts & XHCI_REG_MASK(XHCI_OP_HCE))
    563             ||  (usbsts & XHCI_REG_MASK(XHCI_OP_HSE));
     561        return !(usbcmd & XHCI_REG_MASK(XHCI_OP_RS)) ||
     562            (usbsts & XHCI_REG_MASK(XHCI_OP_HCE)) ||
     563            (usbsts & XHCI_REG_MASK(XHCI_OP_HSE));
    564564}
    565565
     
    589589        struct timeval tv;
    590590        getuptime(&tv);
    591         usb_log_debug("Microframe index wrapped (@%lu.%li, %"PRIu64" total).",
     591        usb_log_debug("Microframe index wrapped (@%lu.%li, %" PRIu64 " total).",
    592592            tv.tv_sec, tv.tv_usec, hc->wrap_count);
    593593        hc->wrap_time = ((uint64_t) tv.tv_sec) * 1000000 + ((uint64_t) tv.tv_usec);
     
    634634        errno_t err;
    635635        xhci_trb_t trb;
    636         xhci_hc_t * const hc = arg;
     636        xhci_hc_t *const hc = arg;
    637637        assert(hc);
    638638
     
    654654 */
    655655static void hc_run_event_ring(xhci_hc_t *hc, xhci_event_ring_t *event_ring,
    656         xhci_interrupter_regs_t *intr)
     656    xhci_interrupter_regs_t *intr)
    657657{
    658658        errno_t err;
     
    720720        if (status) {
    721721                usb_log_error("Non-zero status after interrupt handling (%08x) "
    722                         " - missing something?", status);
     722                    " - missing something?", status);
    723723        }
    724724}
     
    766766{
    767767        return (2 * ep->base.endpoint) +
    768                 (ep->base.transfer_type == USB_TRANSFER_CONTROL
    769                  || ep->base.direction == USB_DIRECTION_IN);
     768            (ep->base.transfer_type == USB_TRANSFER_CONTROL ||
     769            ep->base.direction == USB_DIRECTION_IN);
    770770}
    771771
    772772void hc_ring_ep_doorbell(xhci_endpoint_t *ep, uint32_t stream_id)
    773773{
    774         xhci_device_t * const dev = xhci_ep_to_dev(ep);
    775         xhci_hc_t * const hc = bus_to_hc(dev->base.bus);
     774        xhci_device_t *const dev = xhci_ep_to_dev(ep);
     775        xhci_hc_t *const hc = bus_to_hc(dev->base.bus);
    776776        const uint8_t dci = endpoint_dci(ep);
    777777        const uint32_t target = (stream_id << 16) | (dci & 0x1ff);
     
    786786{
    787787        errno_t err;
    788         xhci_hc_t * const hc = bus_to_hc(dev->base.bus);
     788        xhci_hc_t *const hc = bus_to_hc(dev->base.bus);
    789789
    790790        /* Prepare memory for the context */
     
    821821{
    822822        errno_t err;
    823         xhci_hc_t * const hc = bus_to_hc(dev->base.bus);
     823        xhci_hc_t *const hc = bus_to_hc(dev->base.bus);
    824824        xhci_cmd_t cmd;
    825825
     
    846846static errno_t create_configure_ep_input_ctx(xhci_device_t *dev, dma_buffer_t *dma_buf)
    847847{
    848         const xhci_hc_t * hc = bus_to_hc(dev->base.bus);
     848        const xhci_hc_t *hc = bus_to_hc(dev->base.bus);
    849849        const errno_t err = dma_buffer_alloc(dma_buf, XHCI_INPUT_CTX_SIZE(hc));
    850850        if (err)
     
    870870{
    871871        errno_t err = ENOMEM;
    872         xhci_hc_t * const hc = bus_to_hc(dev->base.bus);
     872        xhci_hc_t *const hc = bus_to_hc(dev->base.bus);
    873873        xhci_endpoint_t *ep0 = xhci_endpoint_get(dev->base.endpoints[0]);
    874874
     
    920920errno_t hc_configure_device(xhci_device_t *dev)
    921921{
    922         xhci_hc_t * const hc = bus_to_hc(dev->base.bus);
     922        xhci_hc_t *const hc = bus_to_hc(dev->base.bus);
    923923        xhci_cmd_t cmd;
    924924
     
    945945errno_t hc_deconfigure_device(xhci_device_t *dev)
    946946{
    947         xhci_hc_t * const hc = bus_to_hc(dev->base.bus);
     947        xhci_hc_t *const hc = bus_to_hc(dev->base.bus);
    948948        xhci_cmd_t cmd;
    949949        errno_t err;
     
    972972errno_t hc_add_endpoint(xhci_endpoint_t *ep)
    973973{
    974         xhci_device_t * const dev = xhci_ep_to_dev(ep);
     974        xhci_device_t *const dev = xhci_ep_to_dev(ep);
    975975        const unsigned dci = endpoint_dci(ep);
    976976        xhci_cmd_t cmd;
     
    984984        xhci_input_ctx_t *ictx = ictx_dma_buf.virt;
    985985
    986         xhci_hc_t * const hc = bus_to_hc(dev->base.bus);
     986        xhci_hc_t *const hc = bus_to_hc(dev->base.bus);
    987987        XHCI_INPUT_CTRL_CTX_ADD_SET(*XHCI_GET_CTRL_CTX(ictx, hc), dci);
    988988
     
    10071007errno_t hc_drop_endpoint(xhci_endpoint_t *ep)
    10081008{
    1009         xhci_device_t * const dev = xhci_ep_to_dev(ep);
    1010         xhci_hc_t * const hc = bus_to_hc(dev->base.bus);
     1009        xhci_device_t *const dev = xhci_ep_to_dev(ep);
     1010        xhci_hc_t *const hc = bus_to_hc(dev->base.bus);
    10111011        const unsigned dci = endpoint_dci(ep);
    10121012        xhci_cmd_t cmd;
     
    10431043errno_t hc_update_endpoint(xhci_endpoint_t *ep)
    10441044{
    1045         xhci_device_t * const dev = xhci_ep_to_dev(ep);
     1045        xhci_device_t *const dev = xhci_ep_to_dev(ep);
    10461046        const unsigned dci = endpoint_dci(ep);
    10471047        xhci_cmd_t cmd;
    10481048
    10491049        dma_buffer_t ictx_dma_buf;
    1050         xhci_hc_t * const hc = bus_to_hc(dev->base.bus);
     1050        xhci_hc_t *const hc = bus_to_hc(dev->base.bus);
    10511051
    10521052        errno_t err = dma_buffer_alloc(&ictx_dma_buf, XHCI_INPUT_CTX_SIZE(hc));
     
    10781078errno_t hc_stop_endpoint(xhci_endpoint_t *ep)
    10791079{
    1080         xhci_device_t * const dev = xhci_ep_to_dev(ep);
     1080        xhci_device_t *const dev = xhci_ep_to_dev(ep);
    10811081        const unsigned dci = endpoint_dci(ep);
    1082         xhci_hc_t * const hc = bus_to_hc(dev->base.bus);
     1082        xhci_hc_t *const hc = bus_to_hc(dev->base.bus);
    10831083        xhci_cmd_t cmd;
    10841084        errno_t err;
     
    11041104errno_t hc_reset_endpoint(xhci_endpoint_t *ep)
    11051105{
    1106         xhci_device_t * const dev = xhci_ep_to_dev(ep);
     1106        xhci_device_t *const dev = xhci_ep_to_dev(ep);
    11071107        const unsigned dci = endpoint_dci(ep);
    1108         xhci_hc_t * const hc = bus_to_hc(dev->base.bus);
     1108        xhci_hc_t *const hc = bus_to_hc(dev->base.bus);
    11091109        xhci_cmd_t cmd;
    11101110        errno_t err;
     
    11261126errno_t hc_reset_ring(xhci_endpoint_t *ep, uint32_t stream_id)
    11271127{
    1128         xhci_device_t * const dev = xhci_ep_to_dev(ep);
     1128        xhci_device_t *const dev = xhci_ep_to_dev(ep);
    11291129        const unsigned dci = endpoint_dci(ep);
    11301130        uintptr_t addr;
     
    11351135        xhci_trb_ring_reset_dequeue_state(ring, &addr);
    11361136
    1137         xhci_hc_t * const hc = bus_to_hc(endpoint_get_bus(&ep->base));
     1137        xhci_hc_t *const hc = bus_to_hc(endpoint_get_bus(&ep->base));
    11381138
    11391139        xhci_cmd_init(&cmd, XHCI_CMD_SET_TR_DEQUEUE_POINTER);
  • uspace/drv/bus/usb/xhci/hw_struct/regs.h

    r76d0981d r3bacee1  
    235235#define XHCI_CAP_CIC          hccparams2, 32,  FLAG,  5
    236236
    237 static inline unsigned xhci_get_max_spbuf(xhci_cap_regs_t *cap_regs) {
    238         return XHCI_REG_RD(cap_regs, XHCI_CAP_MAX_SPBUF_HI) << 5
    239                 | XHCI_REG_RD(cap_regs, XHCI_CAP_MAX_SPBUF_LO);
     237static inline unsigned xhci_get_max_spbuf(xhci_cap_regs_t *cap_regs)
     238{
     239        return XHCI_REG_RD(cap_regs, XHCI_CAP_MAX_SPBUF_HI) << 5 |
     240            XHCI_REG_RD(cap_regs, XHCI_CAP_MAX_SPBUF_LO);
    240241}
    241242
  • uspace/drv/bus/usb/xhci/hw_struct/trb.h

    r76d0981d r3bacee1  
    166166
    167167        return chain_bit &&
    168             (type == XHCI_TRB_TYPE_NORMAL
    169             || type == XHCI_TRB_TYPE_DATA_STAGE
    170             || type == XHCI_TRB_TYPE_STATUS_STAGE
    171             || type == XHCI_TRB_TYPE_ISOCH);
     168            (type == XHCI_TRB_TYPE_NORMAL ||
     169            type == XHCI_TRB_TYPE_DATA_STAGE ||
     170            type == XHCI_TRB_TYPE_STATUS_STAGE ||
     171            type == XHCI_TRB_TYPE_ISOCH);
    172172}
    173173
  • uspace/drv/bus/usb/xhci/isoch.c

    r76d0981d r3bacee1  
    4949{
    5050        assert(ep->base.transfer_type == USB_TRANSFER_ISOCHRONOUS);
    51         xhci_isoch_t * const isoch = ep->isoch;
     51        xhci_isoch_t *const isoch = ep->isoch;
    5252
    5353        fibril_mutex_initialize(&isoch->guard);
     
    7070static void isoch_reset(xhci_endpoint_t *ep)
    7171{
    72         xhci_isoch_t * const isoch = ep->isoch;
     72        xhci_isoch_t *const isoch = ep->isoch;
    7373        assert(fibril_mutex_is_locked(&isoch->guard));
    7474
     
    8787static void isoch_reset_no_timer(xhci_endpoint_t *ep)
    8888{
    89         xhci_isoch_t * const isoch = ep->isoch;
     89        xhci_isoch_t *const isoch = ep->isoch;
    9090        assert(fibril_mutex_is_locked(&isoch->guard));
    9191        /*
     
    9797}
    9898
    99 static void isoch_reset_timer(void *ep) {
    100         xhci_isoch_t * const isoch = xhci_endpoint_get(ep)->isoch;
     99static void isoch_reset_timer(void *ep)
     100{
     101        xhci_isoch_t *const isoch = xhci_endpoint_get(ep)->isoch;
    101102        fibril_mutex_lock(&isoch->guard);
    102103        isoch_reset(ep);
     
    109110 */
    110111#define RESET_TIMER_DELAY 100000
    111 static void timer_schedule_reset(xhci_endpoint_t *ep) {
    112         xhci_isoch_t * const isoch = ep->isoch;
    113         const suseconds_t delay = isoch->buffer_count * ep->interval * 125
    114             + RESET_TIMER_DELAY;
     112static void timer_schedule_reset(xhci_endpoint_t *ep)
     113{
     114        xhci_isoch_t *const isoch = ep->isoch;
     115        const suseconds_t delay = isoch->buffer_count * ep->interval * 125 +
     116            RESET_TIMER_DELAY;
    115117
    116118        fibril_timer_clear_locked(isoch->reset_timer);
    117119        fibril_timer_set_locked(isoch->reset_timer, delay,
    118                 isoch_reset_timer, ep);
     120            isoch_reset_timer, ep);
    119121}
    120122
     
    122124{
    123125        assert(ep->base.transfer_type == USB_TRANSFER_ISOCHRONOUS);
    124         xhci_isoch_t * const isoch = ep->isoch;
     126        xhci_isoch_t *const isoch = ep->isoch;
    125127
    126128        if (isoch->feeding_timer) {
     
    141143 * Allocate isochronous buffers. Create the feeding timer.
    142144 */
    143 errno_t isoch_alloc_transfers(xhci_endpoint_t *ep) {
    144         assert(ep->base.transfer_type == USB_TRANSFER_ISOCHRONOUS);
    145         xhci_isoch_t * const isoch = ep->isoch;
     145errno_t isoch_alloc_transfers(xhci_endpoint_t *ep)
     146{
     147        assert(ep->base.transfer_type == USB_TRANSFER_ISOCHRONOUS);
     148        xhci_isoch_t *const isoch = ep->isoch;
    146149
    147150        isoch->feeding_timer = fibril_timer_create(&isoch->guard);
     
    151154
    152155        isoch->transfers = calloc(isoch->buffer_count, sizeof(xhci_isoch_transfer_t));
    153         if(!isoch->transfers)
     156        if (!isoch->transfers)
    154157                goto err;
    155158
     
    185188        size_t tdpc = it->size / 1024 + ((it->size % 1024) ? 1 : 0);
    186189        size_t tbc = tdpc / ep->max_burst;
    187         if (!tdpc % ep->max_burst) --tbc;
     190        if (!tdpc % ep->max_burst)
     191                --tbc;
    188192        size_t bsp = tdpc % ep->max_burst;
    189193        size_t tlbpc = (bsp ? bsp : ep->max_burst) - 1;
     
    220224         */
    221225        uint64_t epoch = hc->wrap_count;
    222         if (reg_mfindex < EPOCH_LOW_MFINDEX
    223             && get_system_time() - hc->wrap_time > EPOCH_DELAY) {
     226        if (reg_mfindex < EPOCH_LOW_MFINDEX &&
     227            get_system_time() - hc->wrap_time > EPOCH_DELAY) {
    224228                ++epoch;
    225229        }
     
    229233static inline void calc_next_mfindex(xhci_endpoint_t *ep, xhci_isoch_transfer_t *it)
    230234{
    231         xhci_isoch_t * const isoch = ep->isoch;
     235        xhci_isoch_t *const isoch = ep->isoch;
    232236        if (isoch->last_mf == -1U) {
    233237                const xhci_bus_t *bus = bus_to_xhci_bus(ep->base.device->bus);
     
    270274 */
    271275static inline void window_decide(window_decision_t *res, xhci_hc_t *hc,
    272         uint64_t mfindex)
     276    uint64_t mfindex)
    273277{
    274278        const uint64_t current_mf = get_current_microframe(hc);
     
    300304{
    301305        assert(ep->base.transfer_type == USB_TRANSFER_ISOCHRONOUS);
    302         xhci_isoch_t * const isoch = ep->isoch;
     306        xhci_isoch_t *const isoch = ep->isoch;
    303307        assert(fibril_mutex_is_locked(&isoch->guard));
    304308
     
    309313
    310314        while (isoch->transfers[isoch->hw_enqueue].state == ISOCH_FILLED) {
    311                 xhci_isoch_transfer_t * const it = &isoch->transfers[isoch->hw_enqueue];
     315                xhci_isoch_transfer_t *const it = &isoch->transfers[isoch->hw_enqueue];
    312316                suseconds_t delay;
    313317
     
    321325                        delay = wd.offset * 125;
    322326                        usb_log_debug("[isoch] delaying feeding buffer %zu for %ldus",
    323                                 it - isoch->transfers, delay);
     327                            it - isoch->transfers, delay);
    324328                        fibril_timer_set_locked(isoch->feeding_timer, delay,
    325329                            isoch_feed_out_timer, ep);
     
    346350                         */
    347351                        usb_log_debug("[isoch] missed feeding buffer %zu at 0x%llx by "
    348                                 "%llu uframes", it - isoch->transfers, it->mfindex, wd.offset);
     352                            "%llu uframes", it - isoch->transfers, it->mfindex, wd.offset);
    349353                        it->state = ISOCH_COMPLETE;
    350354                        it->error = EOK;
     
    370374static void isoch_feed_out_timer(void *ep)
    371375{
    372         xhci_isoch_t * const isoch = xhci_endpoint_get(ep)->isoch;
     376        xhci_isoch_t *const isoch = xhci_endpoint_get(ep)->isoch;
    373377        fibril_mutex_lock(&isoch->guard);
    374378        isoch_feed_out(ep);
     
    386390{
    387391        assert(ep->base.transfer_type == USB_TRANSFER_ISOCHRONOUS);
    388         xhci_isoch_t * const isoch = ep->isoch;
     392        xhci_isoch_t *const isoch = ep->isoch;
    389393        assert(fibril_mutex_is_locked(&isoch->guard));
    390394
     
    395399
    396400        while (isoch->transfers[isoch->enqueue].state <= ISOCH_FILLED) {
    397                 xhci_isoch_transfer_t * const it = &isoch->transfers[isoch->enqueue];
     401                xhci_isoch_transfer_t *const it = &isoch->transfers[isoch->enqueue];
    398402                suseconds_t delay;
    399403
     
    419423                case WINDOW_TOO_LATE:
    420424                        usb_log_debug("[isoch] missed feeding buffer %zu at 0x%llx by"
    421                                 "%llu uframes", it - isoch->transfers, it->mfindex, wd.offset);
     425                            "%llu uframes", it - isoch->transfers, it->mfindex, wd.offset);
    422426                        /* Missed the opportunity to schedule. Schedule ASAP. */
    423427                        it->mfindex += wd.offset;
     
    458462static void isoch_feed_in_timer(void *ep)
    459463{
    460         xhci_isoch_t * const isoch = xhci_endpoint_get(ep)->isoch;
     464        xhci_isoch_t *const isoch = xhci_endpoint_get(ep)->isoch;
    461465        fibril_mutex_lock(&isoch->guard);
    462466        isoch_feed_in(ep);
     
    477481        xhci_endpoint_t *ep = xhci_endpoint_get(transfer->batch.ep);
    478482        assert(ep->base.transfer_type == USB_TRANSFER_ISOCHRONOUS);
    479         xhci_isoch_t * const isoch = ep->isoch;
     483        xhci_isoch_t *const isoch = ep->isoch;
    480484
    481485        /* This shall be already checked by endpoint */
     
    541545        xhci_endpoint_t *ep = xhci_endpoint_get(transfer->batch.ep);
    542546        assert(ep->base.transfer_type == USB_TRANSFER_ISOCHRONOUS);
    543         xhci_isoch_t * const isoch = ep->isoch;
     547        xhci_isoch_t *const isoch = ep->isoch;
    544548
    545549        if (transfer->batch.size < ep->base.max_transfer_size) {
     
    585589
    586590void isoch_handle_transfer_event(xhci_hc_t *hc, xhci_endpoint_t *ep,
    587         xhci_trb_t *trb)
    588 {
    589         assert(ep->base.transfer_type == USB_TRANSFER_ISOCHRONOUS);
    590         xhci_isoch_t * const isoch = ep->isoch;
     591    xhci_trb_t *trb)
     592{
     593        assert(ep->base.transfer_type == USB_TRANSFER_ISOCHRONOUS);
     594        xhci_isoch_t *const isoch = ep->isoch;
    591595
    592596        fibril_mutex_lock(&ep->isoch->guard);
     
    632636                }
    633637
    634                 xhci_isoch_transfer_t * const it = &isoch->transfers[di];
     638                xhci_isoch_transfer_t *const it = &isoch->transfers[di];
    635639
    636640                if (it->state == ISOCH_FED && it->interrupt_trb_phys == trb->parameter) {
  • uspace/drv/bus/usb/xhci/rh.c

    r76d0981d r3bacee1  
    5454/* This mask only lists registers, which imply port change. */
    5555static const uint32_t port_events_mask =
    56         XHCI_REG_MASK(XHCI_PORT_CSC) |
    57         XHCI_REG_MASK(XHCI_PORT_PEC) |
    58         XHCI_REG_MASK(XHCI_PORT_WRC) |
    59         XHCI_REG_MASK(XHCI_PORT_OCC) |
    60         XHCI_REG_MASK(XHCI_PORT_PRC) |
    61         XHCI_REG_MASK(XHCI_PORT_PLC) |
    62         XHCI_REG_MASK(XHCI_PORT_CEC);
     56    XHCI_REG_MASK(XHCI_PORT_CSC) |
     57    XHCI_REG_MASK(XHCI_PORT_PEC) |
     58    XHCI_REG_MASK(XHCI_PORT_WRC) |
     59    XHCI_REG_MASK(XHCI_PORT_OCC) |
     60    XHCI_REG_MASK(XHCI_PORT_PRC) |
     61    XHCI_REG_MASK(XHCI_PORT_PLC) |
     62    XHCI_REG_MASK(XHCI_PORT_CEC);
    6363
    6464static const uint32_t port_reset_mask =
    65         XHCI_REG_MASK(XHCI_PORT_WRC) |
    66         XHCI_REG_MASK(XHCI_PORT_PRC);
     65    XHCI_REG_MASK(XHCI_PORT_WRC) |
     66    XHCI_REG_MASK(XHCI_PORT_PRC);
    6767
    6868typedef struct rh_port {
     
    167167                return ENOENT;
    168168
    169         unsigned psiv = (status & XHCI_REG_MASK(XHCI_PORT_PS))
    170             >> XHCI_REG_SHIFT(XHCI_PORT_PS);
     169        unsigned psiv = (status & XHCI_REG_MASK(XHCI_PORT_PS)) >>
     170            XHCI_REG_SHIFT(XHCI_PORT_PS);
    171171        const usb_speed_t speed = port->rh->hc->speeds[psiv].usb_speed;
    172172
     
    233233static void handle_port_change(xhci_rh_t *rh, uint8_t port_id)
    234234{
    235         rh_port_t * const port = &rh->ports[port_id - 1];
     235        rh_port_t *const port = &rh->ports[port_id - 1];
    236236
    237237        uint32_t status = XHCI_REG_RD_FIELD(&port->regs->portsc, 32);
     
    280280
    281281void xhci_rh_set_ports_protocol(xhci_rh_t *rh,
    282         unsigned offset, unsigned count, unsigned major)
     282    unsigned offset, unsigned count, unsigned major)
    283283{
    284284        for (unsigned i = offset; i < offset + count; i++)
     
    297297                handle_port_change(rh, i + 1);
    298298
    299                 rh_port_t * const port = &rh->ports[i];
     299                rh_port_t *const port = &rh->ports[i];
    300300
    301301                /*
     
    304304                 * such ports.
    305305                 */
    306                 if (XHCI_REG_RD(port->regs, XHCI_PORT_CCS)
    307                     && port->base.state == PORT_DISABLED)
     306                if (XHCI_REG_RD(port->regs, XHCI_PORT_CCS) &&
     307                    port->base.state == PORT_DISABLED)
    308308                        usb_port_connected(&port->base, &rh_enumerate_device);
    309309        }
     
    320320
    321321        for (uint8_t i = 0; i < rh->max_ports; ++i) {
    322                 rh_port_t * const port = &rh->ports[i];
     322                rh_port_t *const port = &rh->ports[i];
    323323                usb_port_disabled(&port->base, &rh_remove_device);
    324324                usb_port_fini(&port->base);
     
    328328static int rh_worker(void *arg)
    329329{
    330         xhci_rh_t * const rh = arg;
     330        xhci_rh_t *const rh = arg;
    331331
    332332        xhci_trb_t trb;
  • uspace/drv/bus/usb/xhci/streams.c

    r76d0981d r3bacee1  
    8888{
    8989        usb_log_debug("Allocating primary stream context array of size %u "
    90                 "for endpoint " XHCI_EP_FMT, count, XHCI_EP_ARGS(*xhci_ep));
     90            "for endpoint " XHCI_EP_FMT, count, XHCI_EP_ARGS(*xhci_ep));
    9191
    9292        if ((dma_buffer_alloc(&xhci_ep->primary_stream_ctx_dma,
    93                 count * sizeof(xhci_stream_ctx_t)))) {
     93            count * sizeof(xhci_stream_ctx_t)))) {
    9494                return ENOMEM;
    9595        }
     
    110110{
    111111        usb_log_debug("Deallocating primary stream structures for "
    112                 "endpoint " XHCI_EP_FMT, XHCI_EP_ARGS(*xhci_ep));
     112            "endpoint " XHCI_EP_FMT, XHCI_EP_ARGS(*xhci_ep));
    113113
    114114        dma_buffer_free(&xhci_ep->primary_stream_ctx_dma);
     
    138138{
    139139        usb_log_debug("Freeing stream rings and context arrays of endpoint "
    140                 XHCI_EP_FMT, XHCI_EP_ARGS(*xhci_ep));
     140            XHCI_EP_FMT, XHCI_EP_ARGS(*xhci_ep));
    141141
    142142        for (size_t index = 0; index < xhci_ep->primary_stream_data_size; ++index) {
     
    153153 */
    154154static errno_t initialize_primary_stream(xhci_hc_t *hc, xhci_endpoint_t *xhci_ep,
    155         unsigned index)
     155    unsigned index)
    156156{
    157157        xhci_stream_ctx_t *ctx = &xhci_ep->primary_stream_ctx_array[index];
     
    206206 */
    207207static errno_t initialize_secondary_streams(xhci_hc_t *hc, xhci_endpoint_t *xhci_ep,
    208         unsigned idx, unsigned count)
     208    unsigned idx, unsigned count)
    209209{
    210210        if (count == 0) {
     
    218218        if ((count & (count - 1)) != 0 || count < 8 || count > 256) {
    219219                usb_log_error("The secondary stream array size must be a power of 2 "
    220                         "between 8 and 256.");
     220                    "between 8 and 256.");
    221221                return EINVAL;
    222222        }
     
    233233
    234234        if ((dma_buffer_alloc(&data->secondary_stream_ctx_dma,
    235                 count * sizeof(xhci_stream_ctx_t)))) {
     235            count * sizeof(xhci_stream_ctx_t)))) {
    236236                free(data->secondary_data);
    237237                return ENOMEM;
     
    275275 */
    276276static void setup_stream_context(xhci_endpoint_t *xhci_ep, xhci_ep_ctx_t *ctx,
    277         unsigned pstreams, unsigned lsa)
     277    unsigned pstreams, unsigned lsa)
    278278{
    279279        XHCI_EP_TYPE_SET(*ctx, xhci_endpoint_type(xhci_ep));
     
    295295 */
    296296static errno_t verify_stream_conditions(xhci_hc_t *hc, xhci_device_t *dev,
    297         xhci_endpoint_t *xhci_ep, unsigned count)
    298 {
    299         if (xhci_ep->base.transfer_type != USB_TRANSFER_BULK
    300                 || dev->base.speed != USB_SPEED_SUPER) {
     297    xhci_endpoint_t *xhci_ep, unsigned count)
     298{
     299        if (xhci_ep->base.transfer_type != USB_TRANSFER_BULK ||
     300            dev->base.speed != USB_SPEED_SUPER) {
    301301                usb_log_error("Streams are only supported by superspeed bulk endpoints.");
    302302                return EINVAL;
     
    321321        if (count > max_psa_size) {
    322322                usb_log_error("Host controller only supports "
    323                         "%u primary streams.", max_psa_size);
     323                    "%u primary streams.", max_psa_size);
    324324                return EINVAL;
    325325        }
     
    327327        if (count > xhci_ep->max_streams) {
    328328                usb_log_error("Endpoint " XHCI_EP_FMT " supports only %" PRIu32 " streams.",
    329                         XHCI_EP_ARGS(*xhci_ep), xhci_ep->max_streams);
     329                    XHCI_EP_ARGS(*xhci_ep), xhci_ep->max_streams);
    330330                return EINVAL;
    331331        }
     
    346346 */
    347347errno_t xhci_endpoint_remove_streams(xhci_hc_t *hc, xhci_device_t *dev,
    348         xhci_endpoint_t *xhci_ep)
     348    xhci_endpoint_t *xhci_ep)
    349349{
    350350        if (!xhci_ep->primary_stream_data_size) {
     
    374374 */
    375375errno_t xhci_endpoint_request_primary_streams(xhci_hc_t *hc, xhci_device_t *dev,
    376         xhci_endpoint_t *xhci_ep, unsigned count)
     376    xhci_endpoint_t *xhci_ep, unsigned count)
    377377{
    378378        errno_t err = verify_stream_conditions(hc, dev, xhci_ep, count);
     
    422422 */
    423423errno_t xhci_endpoint_request_secondary_streams(xhci_hc_t *hc, xhci_device_t *dev,
    424         xhci_endpoint_t *xhci_ep, unsigned *sizes, unsigned count)
     424    xhci_endpoint_t *xhci_ep, unsigned *sizes, unsigned count)
    425425{
    426426        /* Check if HC supports secondary indexing */
     
    454454        if (max * count > xhci_ep->max_streams) {
    455455                usb_log_error("Endpoint " XHCI_EP_FMT " supports only %" PRIu32 " streams.",
    456                         XHCI_EP_ARGS(*xhci_ep), xhci_ep->max_streams);
     456                    XHCI_EP_ARGS(*xhci_ep), xhci_ep->max_streams);
    457457                return EINVAL;
    458458        }
  • uspace/drv/bus/usb/xhci/test/reg-ops.c

    r76d0981d r3bacee1  
    2323#define EQ(exp, act) PCUT_ASSERT_INT_EQUALS((exp), (act))
    2424
    25 PCUT_TEST(ops_8_field) {
     25PCUT_TEST(ops_8_field)
     26{
    2627        RESET;
    2728        EQ(0, XHCI_REG_RD(regs, REG_8_FIELD));
     
    4142}
    4243
    43 PCUT_TEST(ops_8_range) {
     44PCUT_TEST(ops_8_range)
     45{
    4446        RESET;
    4547        EQ(0, XHCI_REG_RD(regs, REG_8_RANGE));
     
    5860}
    5961
    60 PCUT_TEST(ops_8_flag) {
     62PCUT_TEST(ops_8_flag)
     63{
    6164        RESET;
    6265        EQ(0, XHCI_REG_RD(regs, REG_8_FLAG));
     
    7679}
    7780
    78 PCUT_TEST(ops_16_field) {
     81PCUT_TEST(ops_16_field)
     82{
    7983        RESET;
    8084        EQ(0, XHCI_REG_RD(regs, REG_16_FIELD));
     
    9397}
    9498
    95 PCUT_TEST(ops_16_range) {
     99PCUT_TEST(ops_16_range)
     100{
    96101        RESET;
    97102        EQ(0, XHCI_REG_RD(regs, REG_16_RANGE));
     
    110115}
    111116
    112 PCUT_TEST(ops_16_flag) {
     117PCUT_TEST(ops_16_flag)
     118{
    113119        RESET;
    114120        EQ(0, XHCI_REG_RD(regs, REG_16_FLAG));
     
    128134}
    129135
    130 PCUT_TEST(ops_32_field) {
     136PCUT_TEST(ops_32_field)
     137{
    131138        RESET;
    132139        EQ(0, XHCI_REG_RD(regs, REG_32_FIELD));
     
    145152}
    146153
    147 PCUT_TEST(ops_32_range) {
     154PCUT_TEST(ops_32_range)
     155{
    148156        RESET;
    149157        EQ(0, XHCI_REG_RD(regs, REG_32_RANGE));
     
    162170}
    163171
    164 PCUT_TEST(ops_32_flag) {
     172PCUT_TEST(ops_32_flag)
     173{
    165174        RESET;
    166175        EQ(0, XHCI_REG_RD(regs, REG_32_FLAG));
  • uspace/drv/bus/usb/xhci/transfers.c

    r76d0981d r3bacee1  
    5151 *  See Table 7 of xHCI specification.
    5252 */
    53 static inline stage_dir_flag_t get_status_direction_flag(xhci_trb_t* trb,
    54         uint8_t bmRequestType, uint16_t wLength)
     53static inline stage_dir_flag_t get_status_direction_flag(xhci_trb_t *trb,
     54    uint8_t bmRequestType, uint16_t wLength)
    5555{
    5656        /* See Table 7 of xHCI specification */
    57         return SETUP_REQUEST_TYPE_IS_DEVICE_TO_HOST(bmRequestType) && (wLength > 0)
    58                 ? STAGE_OUT
    59                 : STAGE_IN;
     57        return SETUP_REQUEST_TYPE_IS_DEVICE_TO_HOST(bmRequestType) && (wLength > 0) ?
     58            STAGE_OUT :
     59            STAGE_IN;
    6060}
    6161
     
    6969 *  See Table 8 of xHCI specification.
    7070 */
    71 static inline data_stage_type_t get_transfer_type(xhci_trb_t* trb, uint8_t
    72         bmRequestType, uint16_t wLength)
     71static inline data_stage_type_t get_transfer_type(xhci_trb_t *trb, uint8_t
     72    bmRequestType, uint16_t wLength)
    7373{
    7474        if (wLength == 0)
     
    7676
    7777        /* See Table 7 of xHCI specification */
    78         return SETUP_REQUEST_TYPE_IS_DEVICE_TO_HOST(bmRequestType)
    79                 ? DATA_STAGE_IN
    80                 : DATA_STAGE_NO;
     78        return SETUP_REQUEST_TYPE_IS_DEVICE_TO_HOST(bmRequestType) ?
     79            DATA_STAGE_IN :
     80            DATA_STAGE_NO;
    8181}
    8282
     
    8686
    8787        return request_type == USB_REQUEST_TYPE_STANDARD &&
    88                 (setup->request == USB_DEVREQ_SET_CONFIGURATION
    89                 || setup->request == USB_DEVREQ_SET_INTERFACE);
     88            (setup->request == USB_DEVREQ_SET_CONFIGURATION ||
     89            setup->request == USB_DEVREQ_SET_INTERFACE);
    9090}
    9191
     
    9595 * Bus callback.
    9696 */
    97 usb_transfer_batch_t * xhci_transfer_create(endpoint_t* ep)
     97usb_transfer_batch_t *xhci_transfer_create(endpoint_t *ep)
    9898{
    9999        xhci_transfer_t *transfer = calloc(1, sizeof(xhci_transfer_t));
     
    108108 * Destroy a xHCI transfer.
    109109 */
    110 void xhci_transfer_destroy(usb_transfer_batch_t* batch)
     110void xhci_transfer_destroy(usb_transfer_batch_t *batch)
    111111{
    112112        xhci_transfer_t *transfer = xhci_transfer_from_batch(batch);
     
    137137
    138138        const size_t chunk_mask = dma_policy_chunk_mask(ts->buf.policy);
    139         ts->chunk_size = (chunk_mask > MAX_CHUNK_SIZE + 1)
    140                 ? MAX_CHUNK_SIZE : (chunk_mask + 1);
     139        ts->chunk_size = (chunk_mask > MAX_CHUNK_SIZE + 1) ?
     140            MAX_CHUNK_SIZE : (chunk_mask + 1);
    141141
    142142        ts->remaining = transfer->batch.size;
     
    183183}
    184184
    185 static errno_t schedule_control(xhci_hc_t* hc, xhci_transfer_t* transfer)
     185static errno_t schedule_control(xhci_hc_t *hc, xhci_transfer_t *transfer)
    186186{
    187187        usb_transfer_batch_t *batch = &transfer->batch;
    188188        xhci_endpoint_t *xhci_ep = xhci_endpoint_get(transfer->batch.ep);
    189189
    190         usb_device_request_setup_packet_t* setup = &batch->setup.packet;
     190        usb_device_request_setup_packet_t *setup = &batch->setup.packet;
    191191
    192192        trb_splitter_t splitter;
     
    210210            get_transfer_type(trb_setup, setup->request_type, setup->length));
    211211
    212         stage_dir_flag_t stage_dir = (transfer->batch.dir == USB_DIRECTION_IN)
    213                                 ? STAGE_IN : STAGE_OUT;
     212        stage_dir_flag_t stage_dir = (transfer->batch.dir == USB_DIRECTION_IN) ?
     213            STAGE_IN : STAGE_OUT;
    214214
    215215        /* Data stage - first TRB is special */
     
    243243}
    244244
    245 static errno_t schedule_bulk_intr(xhci_hc_t* hc, xhci_transfer_t *transfer)
    246 {
    247         xhci_trb_ring_t * const ring = get_ring(transfer);
     245static errno_t schedule_bulk_intr(xhci_hc_t *hc, xhci_transfer_t *transfer)
     246{
     247        xhci_trb_ring_t *const ring = get_ring(transfer);
    248248        if (!ring)
    249249                return EINVAL;
     
    266266                /* Set the interrupt bit for last TRB */
    267267                TRB_CTRL_SET_IOC(trbs[trbs_used - 1], 1);
    268         }
    269         else {
     268        } else {
    270269                /* Clear the chain bit on the last TRB */
    271270                TRB_CTRL_SET_CHAIN(trbs[trbs_used - 1], 1);
     
    280279
    281280        return xhci_trb_ring_enqueue_multiple(ring, trbs, trbs_used,
    282                 &transfer->interrupt_trb_phys);
    283 }
    284 
    285 static int schedule_isochronous(xhci_transfer_t* transfer)
     281            &transfer->interrupt_trb_phys);
     282}
     283
     284static int schedule_isochronous(xhci_transfer_t *transfer)
    286285{
    287286        endpoint_t *ep = transfer->batch.ep;
    288287
    289         return ep->direction == USB_DIRECTION_OUT
    290                 ? isoch_schedule_out(transfer)
    291                 : isoch_schedule_in(transfer);
    292 }
    293 
    294 errno_t xhci_handle_transfer_event(xhci_hc_t* hc, xhci_trb_t* trb)
     288        return ep->direction == USB_DIRECTION_OUT ?
     289            isoch_schedule_out(transfer) :
     290            isoch_schedule_in(transfer);
     291}
     292
     293errno_t xhci_handle_transfer_event(xhci_hc_t *hc, xhci_trb_t *trb)
    295294{
    296295        uintptr_t addr = trb->parameter;
     
    327326                    transfer->interrupt_trb_phys);
    328327                batch = &transfer->batch;
    329         }
    330         else {
     328        } else {
    331329                xhci_trb_ring_update_dequeue(&ep->ring, addr);
    332330
     
    354352        const xhci_trb_completion_code_t completion_code = TRB_COMPLETION_CODE(*trb);
    355353        switch (completion_code) {
    356                 case XHCI_TRBC_SHORT_PACKET:
    357                 case XHCI_TRBC_SUCCESS:
    358                         batch->error = EOK;
    359                         batch->transferred_size = batch->size - TRB_TRANSFER_LENGTH(*trb);
    360                         break;
    361 
    362                 case XHCI_TRBC_DATA_BUFFER_ERROR:
    363                         usb_log_warning("Transfer ended with data buffer error.");
    364                         batch->error = EAGAIN;
    365                         batch->transferred_size = 0;
    366                         break;
    367 
    368                 case XHCI_TRBC_BABBLE_DETECTED_ERROR:
    369                         usb_log_warning("Babble detected during the transfer.");
    370                         batch->error = EAGAIN;
    371                         batch->transferred_size = 0;
    372                         break;
    373 
    374                 case XHCI_TRBC_USB_TRANSACTION_ERROR:
    375                         usb_log_warning("USB Transaction error.");
    376                         batch->error = EAGAIN;
    377                         batch->transferred_size = 0;
    378                         break;
    379 
    380                 case XHCI_TRBC_TRB_ERROR:
    381                         usb_log_error("Invalid transfer parameters.");
    382                         batch->error = EINVAL;
    383                         batch->transferred_size = 0;
    384                         break;
    385 
    386                 case XHCI_TRBC_STALL_ERROR:
    387                         usb_log_warning("Stall condition detected.");
    388                         batch->error = ESTALL;
    389                         batch->transferred_size = 0;
    390                         break;
    391 
    392                 case XHCI_TRBC_SPLIT_TRANSACTION_ERROR:
    393                         usb_log_error("Split transcation error detected.");
    394                         batch->error = EAGAIN;
    395                         batch->transferred_size = 0;
    396                         break;
    397 
    398                 default:
    399                         usb_log_warning("Transfer not successfull: %u", completion_code);
    400                         batch->error = EIO;
     354        case XHCI_TRBC_SHORT_PACKET:
     355        case XHCI_TRBC_SUCCESS:
     356                batch->error = EOK;
     357                batch->transferred_size = batch->size - TRB_TRANSFER_LENGTH(*trb);
     358                break;
     359
     360        case XHCI_TRBC_DATA_BUFFER_ERROR:
     361                usb_log_warning("Transfer ended with data buffer error.");
     362                batch->error = EAGAIN;
     363                batch->transferred_size = 0;
     364                break;
     365
     366        case XHCI_TRBC_BABBLE_DETECTED_ERROR:
     367                usb_log_warning("Babble detected during the transfer.");
     368                batch->error = EAGAIN;
     369                batch->transferred_size = 0;
     370                break;
     371
     372        case XHCI_TRBC_USB_TRANSACTION_ERROR:
     373                usb_log_warning("USB Transaction error.");
     374                batch->error = EAGAIN;
     375                batch->transferred_size = 0;
     376                break;
     377
     378        case XHCI_TRBC_TRB_ERROR:
     379                usb_log_error("Invalid transfer parameters.");
     380                batch->error = EINVAL;
     381                batch->transferred_size = 0;
     382                break;
     383
     384        case XHCI_TRBC_STALL_ERROR:
     385                usb_log_warning("Stall condition detected.");
     386                batch->error = ESTALL;
     387                batch->transferred_size = 0;
     388                break;
     389
     390        case XHCI_TRBC_SPLIT_TRANSACTION_ERROR:
     391                usb_log_error("Split transcation error detected.");
     392                batch->error = EAGAIN;
     393                batch->transferred_size = 0;
     394                break;
     395
     396        default:
     397                usb_log_warning("Transfer not successfull: %u", completion_code);
     398                batch->error = EIO;
    401399        }
    402400
     
    456454         * the Reset Endpoint command.
    457455         */
    458         if (batch->ep->transfer_type == USB_TRANSFER_CONTROL
    459             && batch->dir == USB_DIRECTION_OUT) {
     456        if (batch->ep->transfer_type == USB_TRANSFER_CONTROL &&
     457            batch->dir == USB_DIRECTION_OUT) {
    460458                const usb_device_request_setup_packet_t *request = &batch->setup.packet;
    461                 if (request->request == USB_DEVREQ_CLEAR_FEATURE
    462                     && request->request_type == USB_REQUEST_RECIPIENT_ENDPOINT
    463                     && request->value == USB_FEATURE_ENDPOINT_HALT) {
     459                if (request->request == USB_DEVREQ_CLEAR_FEATURE &&
     460                    request->request_type == USB_REQUEST_RECIPIENT_ENDPOINT &&
     461                    request->value == USB_FEATURE_ENDPOINT_HALT) {
    464462                        const uint16_t index = uint16_usb2host(request->index);
    465463                        const usb_endpoint_t ep_num = index & 0xf;
    466                         const usb_direction_t dir = (index >> 7)
    467                             ? USB_DIRECTION_IN
    468                             : USB_DIRECTION_OUT;
     464                        const usb_direction_t dir = (index >> 7) ?
     465                            USB_DIRECTION_IN :
     466                            USB_DIRECTION_OUT;
    469467                        endpoint_t *halted_ep = bus_find_endpoint(&xhci_dev->base, ep_num, dir);
    470468                        if (halted_ep) {
     
    488486                        } else {
    489487                                usb_log_warning("Device(%u): Resetting unregistered endpoint"
    490                                         " %u %s.", xhci_dev->base.address, ep_num,
    491                                         usb_str_direction(dir));
     488                                    " %u %s.", xhci_dev->base.address, ep_num,
     489                                    usb_str_direction(dir));
    492490                        }
    493491                }
  • uspace/drv/bus/usb/xhci/trb_ring.c

    r76d0981d r3bacee1  
    122122
    123123        list_initialize(&ring->segments);
    124         size_t segment_count = (initial_size + SEGMENT_TRB_USEFUL_COUNT - 1)
    125                 / SEGMENT_TRB_USEFUL_COUNT;
     124        size_t segment_count = (initial_size + SEGMENT_TRB_USEFUL_COUNT - 1) /
     125            SEGMENT_TRB_USEFUL_COUNT;
    126126
    127127        for (size_t i = 0; i < segment_count; ++i) {
     
    134134        }
    135135
    136         trb_segment_t * const segment = get_first_segment(&ring->segments);
     136        trb_segment_t *const segment = get_first_segment(&ring->segments);
    137137        xhci_trb_t *last = segment_end(segment) - 1;
    138138        xhci_trb_link_fill(last, segment->phys);
     
    198198static bool trb_generates_interrupt(xhci_trb_t *trb)
    199199{
    200         return TRB_TYPE(*trb) >= XHCI_TRB_TYPE_ENABLE_SLOT_CMD
    201                 || TRB_IOC(*trb);
     200        return TRB_TYPE(*trb) >= XHCI_TRB_TYPE_ENABLE_SLOT_CMD ||
     201            TRB_IOC(*trb);
    202202}
    203203
     
    220220 */
    221221errno_t xhci_trb_ring_enqueue_multiple(xhci_trb_ring_t *ring, xhci_trb_t *first_trb,
    222         size_t trbs, uintptr_t *phys)
     222    size_t trbs, uintptr_t *phys)
    223223{
    224224        errno_t err;
     
    230230        fibril_mutex_lock(&ring->guard);
    231231
    232         xhci_trb_t * const saved_enqueue_trb = ring->enqueue_trb;
    233         trb_segment_t * const saved_enqueue_segment = ring->enqueue_segment;
     232        xhci_trb_t *const saved_enqueue_trb = ring->enqueue_trb;
     233        trb_segment_t *const saved_enqueue_segment = ring->enqueue_segment;
    234234        if (phys)
    235235                *phys = (uintptr_t)NULL;
     
    365365{
    366366        list_foreach(ring->segments, segments_link, trb_segment_t, segment)
    367                 memset(segment->trb_storage, 0, sizeof(segment->trb_storage));
    368 
    369         trb_segment_t * const segment = get_first_segment(&ring->segments);
     367            memset(segment->trb_storage, 0, sizeof(segment->trb_storage));
     368
     369        trb_segment_t *const segment = get_first_segment(&ring->segments);
    370370        ring->dequeue_segment = segment;
    371371        ring->dequeue_trb = segment_begin(segment);
Note: See TracChangeset for help on using the changeset viewer.