Changeset 8033f89 in mainline


Ignore:
Timestamp:
2018-01-23T12:41:22Z (6 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e7e1fd3
Parents:
e546142
Message:

xhci: cstyle

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

Legend:

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

    re546142 r8033f89  
    244244        cr_set_state(cr, XHCI_CR_STATE_CLOSED);
    245245
     246        /* Some systems, inc. QEMU, need whole 64-bit qword to be written */
    246247        XHCI_REG_SET(hc->op_regs, XHCI_OP_CS, 1);
    247         XHCI_REG_SET(hc->op_regs, XHCI_OP_CRCR_HI, 0); // Some systems (incl. QEMU) require 64-bit write
     248        XHCI_REG_SET(hc->op_regs, XHCI_OP_CRCR_HI, 0);
    248249
    249250        while (XHCI_REG_RD(hc->op_regs, XHCI_OP_CRR))
     
    259260static void abort_command_ring(xhci_hc_t *hc)
    260261{
    261         XHCI_REG_WR(hc->op_regs, XHCI_OP_CA, 1);
    262         XHCI_REG_SET(hc->op_regs, XHCI_OP_CRCR_HI, 0); // Some systems (incl. QEMU) require 64-bit write
     262        /* Some systems, inc. QEMU, need whole 64-bit qword to be written */
     263        XHCI_REG_SET(hc->op_regs, XHCI_OP_CA, 1);
     264        XHCI_REG_SET(hc->op_regs, XHCI_OP_CRCR_HI, 0);
    263265}
    264266
     
    370372        command->slot_id = TRB_GET_SLOT(*trb);
    371373
    372         usb_log_debug("Completed command %s", xhci_trb_str_type(TRB_TYPE(command->_header.trb)));
     374        usb_log_debug("Completed command %s",
     375            xhci_trb_str_type(TRB_TYPE(command->_header.trb)));
    373376
    374377        if (code != XHCI_TRBC_SUCCESS) {
     
    412415
    413416        TRB_SET_TYPE(cmd->_header.trb, XHCI_TRB_TYPE_ENABLE_SLOT_CMD);
    414         cmd->_header.trb.control |= host2xhci(32, XHCI_REG_RD(hc->xecp, XHCI_EC_SP_SLOT_TYPE) << 16);
     417        cmd->_header.trb.control |=
     418            host2xhci(32, XHCI_REG_RD(hc->xecp, XHCI_EC_SP_SLOT_TYPE) << 16);
    415419
    416420        return enqueue_command(hc, cmd);
     
    683687        while (!cmd->_header.completed) {
    684688
    685                 rv = fibril_condvar_wait_timeout(&cmd->_header.completed_cv, &cmd->_header.completed_mtx, XHCI_COMMAND_TIMEOUT);
     689                rv = fibril_condvar_wait_timeout(&cmd->_header.completed_cv,
     690                    &cmd->_header.completed_mtx, XHCI_COMMAND_TIMEOUT);
    686691
    687692                /* The waiting timed out. Current command (not necessarily
  • uspace/drv/bus/usb/xhci/debug.c

    re546142 r8033f89  
    264264void xhci_dump_trb(const xhci_trb_t *trb)
    265265{
    266         usb_log_debug("TRB(%p): type %s, cycle %u, status 0x%#08" PRIx32 ", parameter 0x%#016" PRIx64, trb, xhci_trb_str_type(TRB_TYPE(*trb)), TRB_CYCLE(*trb), trb->status, trb->parameter);
     266        usb_log_debug("TRB(%p): type %s, cycle %u, status 0x%#08" PRIx32 ", "
     267            "parameter 0x%#016" PRIx64, trb, xhci_trb_str_type(TRB_TYPE(*trb)),
     268            TRB_CYCLE(*trb), trb->status, trb->parameter);
    267269}
    268270
     
    330332                        unsigned psic = XHCI_REG_RD(ec, XHCI_EC_SP_PSIC);
    331333
    332                         usb_log_debug("\tProtocol %.4s%u.%u, ports %u-%u, %u protocol speeds", name.str,
     334                        usb_log_debug("\tProtocol %.4s%u.%u, ports %u-%u, "
     335                            "%u protocol speeds", name.str,
    333336                            XHCI_REG_RD(ec, XHCI_EC_SP_MAJOR),
    334337                            XHCI_REG_RD(ec, XHCI_EC_SP_MINOR),
  • uspace/drv/bus/usb/xhci/device.c

    re546142 r8033f89  
    5656#include "device.h"
    5757
    58 /** Initial descriptor used for control endpoint 0 before more configuration is retrieved. */
     58/**
     59 * Initial descriptor used for control endpoint 0,
     60 * before more configuration is retrieved.
     61 */
    5962static const usb_endpoint_descriptors_t ep0_initial_desc = {
    6063        .endpoint.max_packet_size = CTRL_PIPE_MIN_PACKET_SIZE,
     
    8790        dev->base.endpoints[0] = ep0_base;
    8891
    89         usb_log_debug("Looking up new device initial MPS: %s", usb_str_speed(dev->base.speed));
     92        usb_log_debug("Looking up new device initial MPS: %s",
     93            usb_str_speed(dev->base.speed));
    9094        ep0_base->max_packet_size = hc_get_ep0_initial_mps(dev->base.speed);
    9195
     
    117121
    118122        uint16_t max_packet_size;
    119         if ((err = hc_get_ep0_max_packet_size(&max_packet_size, (bus_t *) &hc->bus, &dev->base)))
     123        if ((err = hc_get_ep0_max_packet_size(&max_packet_size,
     124            (bus_t *) &hc->bus, &dev->base)))
    120125                return err;
    121126
     
    160165        }
    161166
    162         usb_log_debug("Device(%u): recognised USB hub with %u ports", dev->base.address, dev->num_ports);
     167        usb_log_debug("Device(%u): recognised USB hub with %u ports",
     168            dev->base.address, dev->num_ports);
    163169        return EOK;
    164170}
     
    197203
    198204        if (err) {
    199                 usb_log_error("Failed to setup address of the new device: %s", str_error(err));
     205                usb_log_error("Failed to setup address of the new device: %s",
     206                    str_error(err));
    200207                return err;
    201208        }
     
    208215
    209216        if ((err = setup_ep0_packet_size(bus->hc, xhci_dev))) {
    210                 usb_log_error("Failed to setup control endpoint of the new device: %s", str_error(err));
     217                usb_log_error("Failed to setup control endpoint "
     218                    "of the new device: %s", str_error(err));
    211219                goto err_address;
    212220        }
     
    215223
    216224        if ((err = hc_get_device_desc(dev, &desc))) {
    217                 usb_log_error("Device(%d): failed to get devices descriptor: %s", dev->address, str_error(err));
     225                usb_log_error("Device(%d): failed to get device "
     226                   "descriptor: %s", dev->address, str_error(err));
    218227                goto err_address;
    219228        }
    220229
    221230        if ((err = setup_hub(xhci_dev, &desc)))
    222                 usb_log_warning("Device(%d): failed to setup hub characteristics: %s. "
    223                     " Continuing anyway.", dev->address, str_error(err));
     231                usb_log_warning("Device(%d): failed to setup hub "
     232                    "characteristics: %s.  Continuing anyway.",
     233                    dev->address, str_error(err));
    224234
    225235        if ((err = hcd_ddf_setup_match_ids(dev, &desc))) {
    226                 usb_log_error("Device(%d): failed to setup match IDs: %s", dev->address, str_error(err));
     236                usb_log_error("Device(%d): failed to setup match IDs: %s",
     237                    dev->address, str_error(err));
    227238                goto err_address;
    228239        }
     
    253264        const uint32_t slot_id = xhci_dev->slot_id;
    254265        if ((err = hc_disable_slot(xhci_dev))) {
    255                 usb_log_warning("Failed to disable slot of device " XHCI_DEV_FMT ": %s",
    256                     XHCI_DEV_ARGS(*xhci_dev), str_error(err));
     266                usb_log_warning("Failed to disable slot of device " XHCI_DEV_FMT
     267                    ": %s", XHCI_DEV_ARGS(*xhci_dev), str_error(err));
    257268        }
    258269
     
    277288        /* Transition the device from the Addressed to the Configured state. */
    278289        if ((err = hc_configure_device(dev))) {
    279                 usb_log_warning("Failed to configure device " XHCI_DEV_FMT ".", XHCI_DEV_ARGS(*dev));
     290                usb_log_warning("Failed to configure device " XHCI_DEV_FMT ".",
     291                    XHCI_DEV_ARGS(*dev));
    280292                return err;
    281293        }
     
    302314        /* Issue one HC command to simultaneously drop all endpoints except zero. */
    303315        if ((err = hc_deconfigure_device(dev))) {
    304                 usb_log_warning("Failed to deconfigure device " XHCI_DEV_FMT ".",
    305                     XHCI_DEV_ARGS(*dev));
     316                usb_log_warning("Failed to deconfigure device "
     317                    XHCI_DEV_FMT ".", XHCI_DEV_ARGS(*dev));
    306318        }
    307319}
     
    339351        }
    340352
    341         // As we always allocate space for whole input context, we can set this to maximum
     353        /*
     354         * As we always allocate space for whole input context, we can set this
     355         * to maximum. The only exception being Address Device command, which
     356         * explicitly requires this to be se to 1.
     357         */
    342358        XHCI_SLOT_CTX_ENTRIES_SET(*ctx, 31);
    343359}
  • uspace/drv/bus/usb/xhci/endpoint.c

    re546142 r8033f89  
    5858 * @return Error code.
    5959 */
    60 static int xhci_endpoint_init(xhci_endpoint_t *xhci_ep, device_t *dev, const usb_endpoint_descriptors_t *desc)
     60static int xhci_endpoint_init(xhci_endpoint_t *xhci_ep, device_t *dev,
     61    const usb_endpoint_descriptors_t *desc)
    6162{
    6263        int rc;
     
    7980                xhci_ep->mult = 1;
    8081
    81         /* In USB 3, the semantics of wMaxPacketSize changed. Now the number of
     82        /*
     83         * In USB 3, the semantics of wMaxPacketSize changed. Now the number of
    8284         * packets per service interval is determined from max_burst and mult.
    8385         */
     
    9395         * others have 2-based log of it.
    9496         */
    95         if (dev->speed >= USB_SPEED_HIGH || ep->transfer_type != USB_TRANSFER_INTERRUPT) {
     97        if (dev->speed >= USB_SPEED_HIGH
     98            || ep->transfer_type != USB_TRANSFER_INTERRUPT) {
    9699                xhci_ep->interval = 1 << (xhci_ep->interval - 1);
    97100        }
     
    119122 * Bus callback.
    120123 */
    121 endpoint_t *xhci_endpoint_create(device_t *dev, const usb_endpoint_descriptors_t *desc)
     124endpoint_t *xhci_endpoint_create(device_t *dev,
     125    const usb_endpoint_descriptors_t *desc)
    122126{
    123127        const usb_transfer_type_t type = USB_ED_GET_TRANSFER_TYPE(desc->endpoint);
     
    193197                        const int err = hc_stop_endpoint(xhci_ep);
    194198                        if (err) {
    195                                 usb_log_warning("Failed to stop endpoint %u of device " XHCI_DEV_FMT ": %s",
    196                                     ep->endpoint, XHCI_DEV_ARGS(*dev), str_error(err));
     199                                usb_log_warning("Failed to stop endpoint %u of device "
     200                                    XHCI_DEV_FMT ": %s", ep->endpoint, XHCI_DEV_ARGS(*dev),
     201                                    str_error(err));
    197202                        }
    198203
     
    233238
    234239                if ((err = hc_drop_endpoint(ep))) {
    235                         usb_log_error("Failed to drop endpoint " XHCI_EP_FMT ": %s", XHCI_EP_ARGS(*ep), str_error(err));
     240                        usb_log_error("Failed to drop endpoint " XHCI_EP_FMT ": %s",
     241                            XHCI_EP_ARGS(*ep), str_error(err));
    236242                }
    237243        } else {
     
    271277}
    272278
    273 /** Allocate transfer data structures for XHCI endpoint not using streams.
     279/**
     280 * Allocate transfer data structures for XHCI endpoint not using streams.
    274281 * @param[in] xhci_ep XHCI endpoint to allocate data structures for.
    275282 *
     
    279286{
    280287        /* Can't use XHCI_EP_FMT because the endpoint may not have device. */
    281         usb_log_debug("Allocating main transfer ring for endpoint " XHCI_EP_FMT, XHCI_EP_ARGS(*xhci_ep));
     288        usb_log_debug("Allocating main transfer ring for endpoint " XHCI_EP_FMT,
     289            XHCI_EP_ARGS(*xhci_ep));
    282290
    283291        xhci_ep->primary_stream_data_array = NULL;
     
    299307}
    300308
    301 /** Free transfer data structures for XHCI endpoint.
     309/**
     310 * Free transfer data structures for XHCI endpoint.
    302311 * @param[in] xhci_ep XHCI endpoint to free data structures for.
    303312 */
     
    307316                xhci_stream_free_ds(xhci_ep);
    308317        } else {
    309                 usb_log_debug("Freeing main transfer ring of endpoint " XHCI_EP_FMT, XHCI_EP_ARGS(*xhci_ep));
     318                usb_log_debug("Freeing main transfer ring of endpoint " XHCI_EP_FMT,
     319                    XHCI_EP_ARGS(*xhci_ep));
    310320                xhci_trb_ring_fini(&xhci_ep->ring);
    311321        }
     
    329339}
    330340
    331 /** Configure endpoint context of a control endpoint.
     341/**
     342 * Configure endpoint context of a control endpoint.
    332343 * @param[in] ep XHCI control endpoint.
    333344 * @param[in] ctx Endpoint context to configure.
     
    344355}
    345356
    346 /** Configure endpoint context of a bulk endpoint.
     357/**
     358 * Configure endpoint context of a bulk endpoint.
    347359 * @param[in] ep XHCI bulk endpoint.
    348360 * @param[in] ctx Endpoint context to configure.
     
    360372}
    361373
    362 /** Configure endpoint context of a isochronous endpoint.
     374/**
     375 * Configure endpoint context of a isochronous endpoint.
    363376 * @param[in] ep XHCI isochronous endpoint.
    364377 * @param[in] ctx Endpoint context to configure.
     
    379392}
    380393
    381 /** Configure endpoint context of a interrupt endpoint.
     394/**
     395 * Configure endpoint context of a interrupt endpoint.
    382396 * @param[in] ep XHCI interrupt endpoint.
    383397 * @param[in] ctx Endpoint context to configure.
     
    399413typedef void (*setup_ep_ctx_helper)(xhci_endpoint_t *, xhci_ep_ctx_t *);
    400414
    401 /** Static array, which maps USB endpoint types to their respective endpoint context configuration functions. */
     415/**
     416 * Static array, which maps USB endpoint types to their respective endpoint
     417 * context configuration functions.
     418 */
    402419static const setup_ep_ctx_helper setup_ep_ctx_helpers[] = {
    403420        [USB_TRANSFER_CONTROL] = setup_control_ep_ctx,
  • uspace/drv/bus/usb/xhci/hc.c

    re546142 r8033f89  
    139139
    140140                                        /*
    141                                          * Speed is not implied, but using one of default PSIV. This is
    142                                          * not clearly stated in xHCI spec. There is a clear intention
    143                                          * to allow xHCI to specify its own speed parameters, but
    144                                          * throughout the document, they used fixed values for e.g.
    145                                          * High-speed (3), without stating the controller shall have
    146                                          * implied default speeds - and for instance Intel controllers
    147                                          * do not. So let's check if the values match and if so, accept
    148                                          * the implied USB speed too.
     141                                         * Speed is not implied, but using one of default PSIV. This
     142                                         * is not clearly stated in xHCI spec. There is a clear
     143                                         * intention to allow xHCI to specify its own speed
     144                                         * parameters, but throughout the document, they used fixed
     145                                         * values for e.g. High-speed (3), without stating the
     146                                         * controller shall have implied default speeds - and for
     147                                         * instance Intel controllers do not. So let's check if the
     148                                         * values match and if so, accept the implied USB speed too.
    149149                                         *
    150150                                         * The main reason we need this is the usb_speed to have
     
    157157                                           && default_psiv_to_port_speed[psiv].tx_bps == bps) {
    158158                                                speeds[psiv] = default_psiv_to_port_speed[psiv];
    159                                                 usb_log_debug("Assumed default %s speed of USB %u.", usb_str_speed(speeds[psiv].usb_speed), major);
     159                                                usb_log_debug("Assumed default %s speed of USB %u.",
     160                                                        usb_str_speed(speeds[psiv].usb_speed), major);
    160161                                                continue;
    161162                                        }
     
    171172                                        if (sim == XHCI_PSI_PLT_SYMM || sim == XHCI_PSI_PLT_TX) {
    172173                                                speeds[psiv].tx_bps = bps;
    173                                                 usb_log_debug("Speed %u set up for bps %" PRIu64 " / %" PRIu64 ".", psiv, speeds[psiv].rx_bps, speeds[psiv].tx_bps);
     174                                                usb_log_debug("Speed %u set up for bps %" PRIu64
     175                                                        " / %" PRIu64 ".", psiv, speeds[psiv].rx_bps,
     176                                                        speeds[psiv].tx_bps);
    174177                                        }
    175178                                }
     
    395398        memcpy(code->cmds, irq_commands, sizeof(irq_commands));
    396399
    397         void *intr0_iman = RNGABSPTR(hc->mmio_range) + XHCI_REG_RD(hc->cap_regs, XHCI_CAP_RTSOFF) + offsetof(xhci_rt_regs_t, ir[0]);
    398         void *usbsts = RNGABSPTR(hc->mmio_range) + XHCI_REG_RD(hc->cap_regs, XHCI_CAP_LENGTH) + offsetof(xhci_op_regs_t, usbsts);
     400        void *intr0_iman = RNGABSPTR(hc->mmio_range)
     401            + XHCI_REG_RD(hc->cap_regs, XHCI_CAP_RTSOFF)
     402            + offsetof(xhci_rt_regs_t, ir[0]);
     403        void *usbsts = RNGABSPTR(hc->mmio_range)
     404            + XHCI_REG_RD(hc->cap_regs, XHCI_CAP_LENGTH)
     405            + offsetof(xhci_op_regs_t, usbsts);
     406
    399407        code->cmds[0].addr = intr0_iman;
    400408        code->cmds[1].value = host2xhci(32, 1);
     
    447455
    448456        /* Wait until the HC is halted - it shall take at most 16 ms */
    449         if (xhci_reg_wait(&hc->op_regs->usbsts, XHCI_REG_MASK(XHCI_OP_HCH), XHCI_REG_MASK(XHCI_OP_HCH)))
     457        if (xhci_reg_wait(&hc->op_regs->usbsts, XHCI_REG_MASK(XHCI_OP_HCH),
     458            XHCI_REG_MASK(XHCI_OP_HCH)))
    450459                return ETIMEOUT;
    451460
     
    533542        struct timeval tv;
    534543        getuptime(&tv);
    535         usb_log_debug("Microframe index wrapped (@%lu.%li, %"PRIu64" total).", tv.tv_sec, tv.tv_usec, hc->wrap_count);
     544        usb_log_debug("Microframe index wrapped (@%lu.%li, %"PRIu64" total).",
     545            tv.tv_sec, tv.tv_usec, hc->wrap_count);
    536546        hc->wrap_time = ((uint64_t) tv.tv_sec) * 1000000 + ((uint64_t) tv.tv_usec);
    537547        ++hc->wrap_count;
     
    596606        fibril_mutex_lock(&hc->event_fibril_completion.guard);
    597607        hc->event_fibril_completion.active = false;
    598         fibril_condvar_wait(&hc->event_fibril_completion.cv, &hc->event_fibril_completion.guard);
     608        fibril_condvar_wait(&hc->event_fibril_completion.cv,
     609            &hc->event_fibril_completion.guard);
    599610        fibril_mutex_unlock(&hc->event_fibril_completion.guard);
    600611
     
    612623 * IPC notification will create new event handling fibril for us.
    613624 */
    614 static void hc_run_event_ring(xhci_hc_t *hc, xhci_event_ring_t *event_ring, xhci_interrupter_regs_t *intr)
     625static void hc_run_event_ring(xhci_hc_t *hc, xhci_event_ring_t *event_ring,
     626    xhci_interrupter_regs_t *intr)
    615627{
    616628        int err;
     
    666678
    667679        if (status & XHCI_REG_MASK(XHCI_OP_SRE)) {
    668                 usb_log_error("Save/Restore error occured. WTF, S/R mechanism not implemented!");
     680                usb_log_error("Save/Restore error occured. WTF, "
     681                    "S/R mechanism not implemented!");
    669682                status &= ~XHCI_REG_MASK(XHCI_OP_SRE);
    670683        }
     
    674687
    675688        if (status) {
    676                 usb_log_error("Non-zero status after interrupt handling (%08x) - missing something?", status);
     689                usb_log_error("Non-zero status after interrupt handling (%08x) "
     690                        " - missing something?", status);
    677691        }
    678692}
     
    688702        fibril_mutex_lock(&hc->event_fibril_completion.guard);
    689703        while (hc->event_fibril_completion.active)
    690                 fibril_condvar_wait(&hc->event_fibril_completion.cv, &hc->event_fibril_completion.guard);
     704                fibril_condvar_wait(&hc->event_fibril_completion.cv,
     705                    &hc->event_fibril_completion.guard);
    691706        fibril_mutex_unlock(&hc->event_fibril_completion.guard);
    692707        xhci_sw_ring_fini(&hc->sw_ring);
     
    830845         * we have to rely on reverse mapping on others. */
    831846        if (!usb_speed_to_psiv[dev->base.speed]) {
    832                 usb_log_error("Device reported an USB speed (%s) that cannot be mapped to HC port speed.", usb_str_speed(dev->base.speed));
     847                usb_log_error("Device reported an USB speed (%s) that cannot be mapped "
     848                    "to HC port speed.", usb_str_speed(dev->base.speed));
    833849                return EINVAL;
    834850        }
     
    850866
    851867        /* Issue Address Device command. */
    852         if ((err = xhci_cmd_sync_inline(hc, ADDRESS_DEVICE, .slot_id = dev->slot_id, .input_ctx = ictx_dma_buf)))
     868        if ((err = xhci_cmd_sync_inline(hc, ADDRESS_DEVICE,
     869                .slot_id = dev->slot_id,
     870                .input_ctx = ictx_dma_buf
     871            )))
    853872                return err;
    854873
     
    875894                return err;
    876895
    877         return xhci_cmd_sync_inline(hc, CONFIGURE_ENDPOINT, .slot_id = dev->slot_id, .input_ctx = ictx_dma_buf);
     896        return xhci_cmd_sync_inline(hc, CONFIGURE_ENDPOINT,
     897                .slot_id = dev->slot_id,
     898                .input_ctx = ictx_dma_buf
     899        );
    878900}
    879901
     
    888910
    889911        /* Issue configure endpoint command (sec 4.3.5) with the DC flag. */
    890         return xhci_cmd_sync_inline(hc, CONFIGURE_ENDPOINT, .slot_id = dev->slot_id, .deconfigure = true);
     912        return xhci_cmd_sync_inline(hc, CONFIGURE_ENDPOINT,
     913                .slot_id = dev->slot_id,
     914                .deconfigure = true
     915        );
    891916}
    892917
     
    917942        xhci_setup_endpoint_context(ep, ep_ctx);
    918943
    919         return xhci_cmd_sync_inline(hc, CONFIGURE_ENDPOINT, .slot_id = dev->slot_id, .input_ctx = ictx_dma_buf);
     944        return xhci_cmd_sync_inline(hc, CONFIGURE_ENDPOINT,
     945                .slot_id = dev->slot_id,
     946                .input_ctx = ictx_dma_buf
     947        );
    920948}
    921949
     
    941969        XHCI_INPUT_CTRL_CTX_DROP_SET(*XHCI_GET_CTRL_CTX(ictx, hc), dci);
    942970
    943         return xhci_cmd_sync_inline(hc, CONFIGURE_ENDPOINT, .slot_id = dev->slot_id, .input_ctx = ictx_dma_buf);
     971        return xhci_cmd_sync_inline(hc, CONFIGURE_ENDPOINT,
     972                .slot_id = dev->slot_id,
     973                .input_ctx = ictx_dma_buf
     974        );
    944975}
    945976
     
    9711002        xhci_setup_endpoint_context(ep, ep_ctx);
    9721003
    973         return xhci_cmd_sync_inline(hc, EVALUATE_CONTEXT, .slot_id = dev->slot_id, .input_ctx = ictx_dma_buf);
     1004        return xhci_cmd_sync_inline(hc, EVALUATE_CONTEXT,
     1005                .slot_id = dev->slot_id,
     1006                .input_ctx = ictx_dma_buf
     1007        );
    9741008}
    9751009
     
    9851019        const unsigned dci = endpoint_dci(ep);
    9861020        xhci_hc_t * const hc = bus_to_hc(dev->base.bus);
    987         return xhci_cmd_sync_inline(hc, STOP_ENDPOINT, .slot_id = dev->slot_id, .endpoint_id = dci);
     1021        return xhci_cmd_sync_inline(hc, STOP_ENDPOINT,
     1022                .slot_id = dev->slot_id,
     1023                .endpoint_id = dci
     1024        );
    9881025}
    9891026
     
    9991036        const unsigned dci = endpoint_dci(ep);
    10001037        xhci_hc_t * const hc = bus_to_hc(dev->base.bus);
    1001         return xhci_cmd_sync_inline(hc, RESET_ENDPOINT, .slot_id = dev->slot_id, .endpoint_id = dci);
     1038        return xhci_cmd_sync_inline(hc, RESET_ENDPOINT,
     1039                .slot_id = dev->slot_id,
     1040                .endpoint_id = dci
     1041        );
    10021042}
    10031043
     
    10181058        xhci_hc_t * const hc = bus_to_hc(endpoint_get_bus(&ep->base));
    10191059        return xhci_cmd_sync_inline(hc, SET_TR_DEQUEUE_POINTER,
    1020                             .slot_id = dev->slot_id,
    1021                             .endpoint_id = dci,
    1022                             .stream_id = stream_id,
    1023                             .dequeue_ptr = addr,
    1024                         );
     1060                .slot_id = dev->slot_id,
     1061                .endpoint_id = dci,
     1062                .stream_id = stream_id,
     1063                .dequeue_ptr = addr,
     1064        );
    10251065}
    10261066
  • uspace/drv/bus/usb/xhci/hw_struct/common.h

    re546142 r8033f89  
    5959typedef volatile uint64_t xhci_qword_t __attribute__((aligned(8)));
    6060
    61 #define XHCI_DWORD_EXTRACT(field, hi, lo) (BIT_RANGE_EXTRACT(uint32_t, hi, lo, xhci2host(32, field)))
    62 #define XHCI_QWORD_EXTRACT(field, hi, lo) (BIT_RANGE_EXTRACT(uint64_t, hi, lo, xhci2host(64, field)))
     61#define XHCI_DWORD_EXTRACT(field, hi, lo) \
     62        (BIT_RANGE_EXTRACT(uint32_t, hi, lo, xhci2host(32, field)))
     63#define XHCI_QWORD_EXTRACT(field, hi, lo) \
     64        (BIT_RANGE_EXTRACT(uint64_t, hi, lo, xhci2host(64, field)))
    6365
    6466/**
     
    6769 * Not thread-safe, proper synchronization over this dword must be assured.
    6870 */
    69 static inline void xhci_dword_set_bits(xhci_dword_t *storage, uint32_t value, unsigned hi, unsigned lo)
     71static inline void xhci_dword_set_bits(xhci_dword_t *storage, uint32_t value,
     72        unsigned hi, unsigned lo)
    7073{
    7174        const uint32_t mask = host2xhci(32, BIT_RANGE(uint32_t, hi, lo));
     
    8285}
    8386
    84 static inline void xhci_qword_set_bits(xhci_qword_t *storage, uint64_t value, unsigned hi, unsigned lo)
     87static inline void xhci_qword_set_bits(xhci_qword_t *storage, uint64_t value,
     88        unsigned hi, unsigned lo)
    8589{
    8690        const uint64_t mask = host2xhci(64, BIT_RANGE(uint64_t, hi, lo));
     
    8993}
    9094
    91 static inline int xhci_reg_wait(xhci_dword_t *reg, uint32_t mask, uint32_t expected)
     95static inline int xhci_reg_wait(xhci_dword_t *reg, uint32_t mask,
     96        uint32_t expected)
    9297{
    9398        mask = host2xhci(32, mask);
  • uspace/drv/bus/usb/xhci/hw_struct/regs.h

    re546142 r8033f89  
    8484 * Field handling is the easiest. Just do it with whole field.
    8585 */
    86 #define XHCI_REG_RD_FIELD(ptr, size)         xhci2host(size, pio_read_##size((ptr)))
    87 #define XHCI_REG_WR_FIELD(ptr, value, size)  pio_write_##size((ptr), host2xhci(size, value))
    88 #define XHCI_REG_SET_FIELD(ptr, value, size) pio_set_##size((ptr), host2xhci(size, value), XHCI_PIO_CHANGE_UDELAY);
    89 #define XHCI_REG_CLR_FIELD(ptr, value, size) pio_clear_##size((ptr), host2xhci(size, value), XHCI_PIO_CHANGE_UDELAY);
     86#define XHCI_REG_RD_FIELD(ptr, size) \
     87        xhci2host(size, pio_read_##size((ptr)))
     88#define XHCI_REG_WR_FIELD(ptr, value, size) \
     89        pio_write_##size((ptr), host2xhci(size, value))
     90#define XHCI_REG_SET_FIELD(ptr, value, size) \
     91        pio_set_##size((ptr), host2xhci(size, value), XHCI_PIO_CHANGE_UDELAY);
     92#define XHCI_REG_CLR_FIELD(ptr, value, size) \
     93        pio_clear_##size((ptr), host2xhci(size, value), XHCI_PIO_CHANGE_UDELAY);
    9094#define XHCI_REG_MASK_FIELD(size)            (~((uint##size##_t) 0))
    9195#define XHCI_REG_SHIFT_FIELD(size)           (0)
     
    9498 * Flags are just trivial case of ranges.
    9599 */
    96 #define XHCI_REG_RD_FLAG(ptr, size, offset)         XHCI_REG_RD_RANGE((ptr), size, (offset), (offset))
    97 #define XHCI_REG_WR_FLAG(ptr, value, size, offset)  XHCI_REG_WR_RANGE((ptr), (value), size, (offset), (offset))
    98 #define XHCI_REG_SET_FLAG(ptr, value, size, offset) XHCI_REG_SET_RANGE((ptr), (value), size, (offset), (offset))
    99 #define XHCI_REG_CLR_FLAG(ptr, value, size, offset) XHCI_REG_CLR_RANGE((ptr), (value), size, (offset), (offset))
     100#define XHCI_REG_RD_FLAG(ptr, size, offset) \
     101        XHCI_REG_RD_RANGE((ptr), size, (offset), (offset))
     102#define XHCI_REG_WR_FLAG(ptr, value, size, offset) \
     103        XHCI_REG_WR_RANGE((ptr), (value), size, (offset), (offset))
     104#define XHCI_REG_SET_FLAG(ptr, value, size, offset) \
     105        XHCI_REG_SET_RANGE((ptr), (value), size, (offset), (offset))
     106#define XHCI_REG_CLR_FLAG(ptr, value, size, offset) \
     107        XHCI_REG_CLR_RANGE((ptr), (value), size, (offset), (offset))
    100108#define XHCI_REG_MASK_FLAG(size, offset)            BIT_V(uint##size##_t, offset)
    101109#define XHCI_REG_SHIFT_FLAG(size, offset)           (offset)
     
    108116
    109117#define XHCI_REG_WR_RANGE(ptr, value, size, hi, lo) \
    110         pio_change_##size((ptr), host2xhci(size, BIT_RANGE_INSERT(uint##size##_t, (hi), (lo), (value))), \
     118        pio_change_##size((ptr), host2xhci(size, BIT_RANGE_INSERT(uint##size##_t, \
     119                        (hi), (lo), (value))), \
    111120                host2xhci(size, BIT_RANGE(uint##size##_t, (hi), (lo))), \
    112121                XHCI_PIO_CHANGE_UDELAY);
    113122
    114123#define XHCI_REG_SET_RANGE(ptr, value, size, hi, lo) \
    115         pio_set_##size((ptr), host2xhci(size, BIT_RANGE_INSERT(uint##size##_t, (hi), (lo), (value))), \
     124        pio_set_##size((ptr), host2xhci(size, BIT_RANGE_INSERT(uint##size##_t, \
     125                        (hi), (lo), (value))), \
    116126                XHCI_PIO_CHANGE_UDELAY);
    117127
    118128#define XHCI_REG_CLR_RANGE(ptr, value, size, hi, lo) \
    119         pio_clear_##size((ptr), host2xhci(size, BIT_RANGE_INSERT(uint##size##_t, (hi), (lo), (value))), \
     129        pio_clear_##size((ptr), host2xhci(size, BIT_RANGE_INSERT(uint##size##_t, \
     130                        (hi), (lo), (value))), \
    120131                XHCI_PIO_CHANGE_UDELAY);
    121132
     
    409420#define XHCI_OP_CA             crcr_lo, 32,  FLAG, 2
    410421#define XHCI_OP_CRR            crcr_lo, 32,  FLAG, 3
    411 /* This shall be RANGE, 6, 0, but the value containing CR pointer and RCS flag
    412  * must be written at once. */
     422/*
     423 * This shall be RANGE, 6, 0, but the value containing CR pointer and RCS flag
     424 * must be written at once.
     425 */
    413426#define XHCI_OP_CRCR_LO        crcr_lo, 32, FIELD
    414427#define XHCI_OP_CRCR_HI        crcr_hi, 32, FIELD
     
    466479#define XHCI_INTR_ERDP_ESI     erdp_lo, 32, RANGE,  2, 0
    467480#define XHCI_INTR_ERDP_EHB     erdp_lo, 32,  FLAG,  3
    468 // TODO: ERDP_LO is supposed to be RANGE 31, 4 (section 5.5.2.3.3).
    469481#define XHCI_INTR_ERDP_LO      erdp_lo, 32, FIELD
    470482#define XHCI_INTR_ERDP_HI      erdp_hi, 32, FIELD
     
    532544} xhci_extcap_t;
    533545
    534 #define XHCI_EC_CAP_ID                           header, 32, RANGE,  7,  0
    535 #define XHCI_EC_SIZE                             header, 32, RANGE, 15,  8
     546#define XHCI_EC_CAP_ID                  header, 32, RANGE,  7,  0
     547#define XHCI_EC_SIZE                    header, 32, RANGE, 15,  8
    536548
    537549/* Supported protocol */
    538 #define XHCI_EC_SP_MINOR                         header, 32, RANGE, 23, 16
    539 #define XHCI_EC_SP_MAJOR                         header, 32, RANGE, 31, 24
    540 #define XHCI_EC_SP_NAME                 cap_specific[0], 32, FIELD
    541 #define XHCI_EC_SP_CP_OFF               cap_specific[1], 32, RANGE,  7,  0
    542 #define XHCI_EC_SP_CP_COUNT             cap_specific[1], 32, RANGE, 15,  8
    543 #define XHCI_EC_SP_PSIC                 cap_specific[1], 32, RANGE, 31, 28
    544 #define XHCI_EC_SP_SLOT_TYPE            cap_specific[2], 32, RANGE,  4,  0
     550#define XHCI_EC_SP_MINOR                header, 32, RANGE, 23, 16
     551#define XHCI_EC_SP_MAJOR                header, 32, RANGE, 31, 24
     552#define XHCI_EC_SP_NAME        cap_specific[0], 32, FIELD
     553#define XHCI_EC_SP_CP_OFF      cap_specific[1], 32, RANGE,  7,  0
     554#define XHCI_EC_SP_CP_COUNT    cap_specific[1], 32, RANGE, 15,  8
     555#define XHCI_EC_SP_PSIC        cap_specific[1], 32, RANGE, 31, 28
     556#define XHCI_EC_SP_SLOT_TYPE   cap_specific[2], 32, RANGE,  4,  0
    545557
    546558typedef union {
     
    582594        ioport8_t sem_os;
    583595
    584         xhci_dword_t usblegctlsts;      /**< USB Legacy Support Control/Status - RW for BIOS, RO for OS */
     596        /** USB Legacy Support Control/Status - RW for BIOS, RO for OS */
     597        xhci_dword_t usblegctlsts;
    585598} xhci_legsup_t;
    586599
     
    588601#define XHCI_LEGSUP_SEM_OS      sem_os, 8, FLAG, 0
    589602
    590 #define XHCI_LEGSUP_POLLING_DELAY_1MS   1000
    591 #define XHCI_LEGSUP_BIOS_TIMEOUT_US     1000000 /* 4.22.1 BIOS may take up to 1 second to release the device */
     603/* 4.22.1 BIOS may take up to 1 second to release the device */
     604#define XHCI_LEGSUP_BIOS_TIMEOUT_US   1000000
     605#define XHCI_LEGSUP_POLLING_DELAY_1MS    1000
    592606
    593607#endif
  • uspace/drv/bus/usb/xhci/hw_struct/trb.h

    re546142 r8033f89  
    208208} xhci_erst_entry_t;
    209209
    210 static inline void xhci_fill_erst_entry(xhci_erst_entry_t *entry, uintptr_t phys, int segments)
     210static inline void xhci_fill_erst_entry(xhci_erst_entry_t *entry,
     211    uintptr_t phys, int segments)
    211212{
    212213        xhci_qword_set(&entry->rs_base_ptr, phys);
  • uspace/drv/bus/usb/xhci/isoch.c

    re546142 r8033f89  
    8181        fibril_timer_clear_locked(isoch->feeding_timer);
    8282        isoch->last_mf = -1U;
    83         usb_log_info("[isoch] Endpoint" XHCI_EP_FMT ": Data flow reset.", XHCI_EP_ARGS(*ep));
     83        usb_log_info("[isoch] Endpoint" XHCI_EP_FMT ": Data flow reset.",
     84            XHCI_EP_ARGS(*ep));
    8485}
    8586
     
    110111static void timer_schedule_reset(xhci_endpoint_t *ep) {
    111112        xhci_isoch_t * const isoch = ep->isoch;
    112         const suseconds_t delay = isoch->buffer_count * ep->interval * 125 + RESET_TIMER_DELAY;
     113        const suseconds_t delay = isoch->buffer_count * ep->interval * 125
     114            + RESET_TIMER_DELAY;
    113115
    114116        fibril_timer_clear_locked(isoch->reset_timer);
     
    213215        const uint32_t reg_mfindex = XHCI_REG_RD(hc->rt_regs, XHCI_RT_MFINDEX);
    214216        /*
    215          * If the mfindex is low and the time passed since last mfindex wrap
    216          * is too high, we have entered the new epoch already (and haven't received event yet).
     217         * If the mfindex is low and the time passed since last mfindex wrap is too
     218         * high, we have entered the new epoch already (and haven't received event
     219         * yet).
    217220         */
    218221        uint64_t epoch = hc->wrap_count;
    219         if (reg_mfindex < EPOCH_LOW_MFINDEX && get_system_time() - hc->wrap_time > EPOCH_DELAY) {
     222        if (reg_mfindex < EPOCH_LOW_MFINDEX
     223            && get_system_time() - hc->wrap_time > EPOCH_DELAY) {
    220224                ++epoch;
    221225        }
     
    230234                const xhci_hc_t *hc = bus->hc;
    231235
    232                 /* Delay the first frame by some time to fill the buffer, but at most 10 miliseconds. */
     236                /*
     237                 * Delay the first frame by some time to fill the buffer, but at most 10
     238                 * miliseconds.
     239                 */
    233240                const uint64_t delay = min(isoch->buffer_count * ep->interval, 10 * 8);
    234241                it->mfindex = get_current_microframe(hc) + 1 + delay + hc->ist;
     
    262269 * uframes it's off.
    263270 */
    264 static inline void window_decide(window_decision_t *res, xhci_hc_t *hc, uint64_t mfindex)
     271static inline void window_decide(window_decision_t *res, xhci_hc_t *hc,
     272    uint64_t mfindex)
    265273{
    266274        const uint64_t current_mf = get_current_microframe(hc);
     
    333341
    334342                case WINDOW_TOO_LATE:
    335                         /* Missed the opportunity to schedule. Just mark this transfer as skipped. */
    336                         usb_log_debug("[isoch] missed feeding buffer %lu at 0x%llx by %llu uframes",
    337                             it - isoch->transfers, it->mfindex, wd.offset);
     343                        /*
     344                         * Missed the opportunity to schedule. Just mark this transfer as
     345                         * skipped.
     346                         */
     347                        usb_log_debug("[isoch] missed feeding buffer %lu at 0x%llx by "
     348                                "%llu uframes", it - isoch->transfers, it->mfindex, wd.offset);
    338349                        it->state = ISOCH_COMPLETE;
    339350                        it->error = EOK;
     
    348359        if (fed) {
    349360                hc_ring_ep_doorbell(ep, 0);
    350                 /* The ring may be dead. If no event happens until the delay, reset the endpoint. */
     361                /*
     362                 * The ring may be dead. If no event happens until the delay, reset the
     363                 * endpoint.
     364                 */
    351365                timer_schedule_reset(ep);
    352366        }
     
    405419
    406420                case WINDOW_TOO_LATE:
    407                         usb_log_debug("[isoch] missed feeding buffer %lu at 0x%llx by %llu uframes",
    408                             it - isoch->transfers, it->mfindex, wd.offset);
     421                        usb_log_debug("[isoch] missed feeding buffer %lu at 0x%llx by"
     422                                "%llu uframes", it - isoch->transfers, it->mfindex, wd.offset);
    409423                        /* Missed the opportunity to schedule. Schedule ASAP. */
    410424                        it->mfindex += wd.offset;
     
    435449        if (fed) {
    436450                hc_ring_ep_doorbell(ep, 0);
    437                 /* The ring may be dead. If no event happens until the delay, reset the endpoint. */
     451                /*
     452                 * The ring may be dead. If no event happens until the delay, reset the
     453                 * endpoint.
     454                 */
    438455                timer_schedule_reset(ep);
    439456        }
     
    502519        calc_next_mfindex(ep, it);
    503520        isoch->last_mf = it->mfindex;
    504         usb_log_debug("[isoch] buffer %zu will be on schedule at 0x%llx", it - isoch->transfers, it->mfindex);
     521        usb_log_debug("[isoch] buffer %zu will be on schedule at 0x%llx",
     522            it - isoch->transfers, it->mfindex);
    505523
    506524        /* Prepare the transfer. */
     
    543561                isoch_feed_in(ep);
    544562
    545                 usb_log_debug("[isoch] waiting for buffer %zu to be completed", it - isoch->transfers);
     563                usb_log_debug("[isoch] waiting for buffer %zu to be completed",
     564                    it - isoch->transfers);
    546565                fibril_condvar_wait(&isoch->avail, &isoch->guard);
    547566
     
    568587}
    569588
    570 void isoch_handle_transfer_event(xhci_hc_t *hc, xhci_endpoint_t *ep, xhci_trb_t *trb)
     589void isoch_handle_transfer_event(xhci_hc_t *hc, xhci_endpoint_t *ep,
     590    xhci_trb_t *trb)
    571591{
    572592        assert(ep->base.transfer_type == USB_TRANSFER_ISOCHRONOUS);
     
    581601                case XHCI_TRBC_RING_OVERRUN:
    582602                case XHCI_TRBC_RING_UNDERRUN:
    583                         /* For OUT, there was nothing to process */
    584                         /* For IN, the buffer has overfilled, we empty the buffers and readd TRBs */
     603                        /*
     604                         * For OUT, there was nothing to process.
     605                         * For IN, the buffer has overfilled.
     606                         * In either case, reset the ring.
     607                         */
    585608                        usb_log_warning("Ring over/underrun.");
    586609                        isoch_reset_no_timer(ep);
  • uspace/drv/bus/usb/xhci/rh.c

    re546142 r8033f89  
    155155                return ENOENT;
    156156
    157         unsigned psiv = (status & XHCI_REG_MASK(XHCI_PORT_PS)) >> XHCI_REG_SHIFT(XHCI_PORT_PS);
     157        unsigned psiv = (status & XHCI_REG_MASK(XHCI_PORT_PS))
     158            >> XHCI_REG_SHIFT(XHCI_PORT_PS);
    158159        const usb_speed_t speed = port->rh->hc->speeds[psiv].usb_speed;
    159160
     
    171172        port->device->rh_port = dev->port;
    172173
    173         usb_log_debug("Enumerating new %s-speed device on port %u.", usb_str_speed(dev->speed), dev->port);
     174        usb_log_debug("Enumerating new %s-speed device on port %u.",
     175            usb_str_speed(dev->speed), dev->port);
    174176
    175177        if ((err = bus_device_enumerate(dev))) {
     
    229231                 * standard mechanisms of register handling fails here.
    230232                 */
    231                 XHCI_REG_WR_FIELD(&port->regs->portsc, status & ~XHCI_REG_MASK(XHCI_PORT_PED), 32);
     233                XHCI_REG_WR_FIELD(&port->regs->portsc,
     234                    status & ~XHCI_REG_MASK(XHCI_PORT_PED), 32);
    232235
    233236                const bool connected = !!(status & XHCI_REG_MASK(XHCI_PORT_CCS));
     
    264267}
    265268
    266 void xhci_rh_set_ports_protocol(xhci_rh_t *rh, unsigned offset, unsigned count, unsigned major)
     269void xhci_rh_set_ports_protocol(xhci_rh_t *rh,
     270    unsigned offset, unsigned count, unsigned major)
    267271{
    268272        for (unsigned i = offset; i < offset + count; i++)
     
    285289                 * such ports.
    286290                 */
    287                 if (XHCI_REG_RD(port->regs, XHCI_PORT_CCS) && port->base.state == PORT_DISABLED)
     291                if (XHCI_REG_RD(port->regs, XHCI_PORT_CCS)
     292                    && port->base.state == PORT_DISABLED)
    288293                        usb_port_connected(&port->base, &rh_enumerate_device);
    289294        }
  • uspace/drv/bus/usb/xhci/streams.c

    re546142 r8033f89  
    3939#include "streams.h"
    4040
    41 /** Finds stream data with given stream ID if it exists.
     41/**
     42 * Finds stream data with given stream ID if it exists.
    4243 * Note that streams with ID 0, 65534 and 65535 are reserved.
    4344 * Splits the ID into primary and secondary context ID and searches the structures.
     
    5253
    5354        /* See 4.12.2.1 for the calculation of the IDs and dividing the stream_id */
    54         uint32_t primary_stream_id = (uint32_t) (stream_id & (ep->primary_stream_data_size - 1));
    55         uint32_t secondary_stream_id = (uint32_t) ((stream_id / ep->primary_stream_data_size) & 0xFF);
     55        uint32_t primary_stream_id =
     56            (uint32_t) (stream_id & (ep->primary_stream_data_size - 1));
     57        uint32_t secondary_stream_id =
     58            (uint32_t) ((stream_id / ep->primary_stream_data_size) & 0xFF);
    5659
    5760        if (primary_stream_id >= ep->primary_stream_data_size) {
     
    5962        }
    6063
    61         xhci_stream_data_t *primary_data = &ep->primary_stream_data_array[primary_stream_id];
     64        xhci_stream_data_t *primary_data =
     65            &ep->primary_stream_data_array[primary_stream_id];
    6266        if (secondary_stream_id != 0 && !primary_data->secondary_size) {
    6367                return NULL;
     
    7680}
    7781
    78 /** Initializes primary stream data structures in endpoint.
     82/**
     83 * Initializes primary stream data structures in endpoint.
    7984 * @param[in] xhci_ep Used XHCI bulk endpoint.
    8085 * @param[in] count Amount of primary streams.
     
    8287static int initialize_primary_structures(xhci_endpoint_t *xhci_ep, unsigned count)
    8388{
    84         usb_log_debug("Allocating primary stream context array of size %u for endpoint " XHCI_EP_FMT,
    85                 count, XHCI_EP_ARGS(*xhci_ep));
    86 
    87         if ((dma_buffer_alloc(&xhci_ep->primary_stream_ctx_dma, count * sizeof(xhci_stream_ctx_t)))) {
     89        usb_log_debug("Allocating primary stream context array of size %u "
     90                "for endpoint " XHCI_EP_FMT, count, XHCI_EP_ARGS(*xhci_ep));
     91
     92        if ((dma_buffer_alloc(&xhci_ep->primary_stream_ctx_dma,
     93                count * sizeof(xhci_stream_ctx_t)))) {
    8894                return ENOMEM;
    8995        }
     
    101107}
    102108
    103 /**
    104  *
    105  */
    106109static void clear_primary_structures(xhci_endpoint_t *xhci_ep)
    107110{
    108         usb_log_debug("Deallocating primary stream structures for endpoint " XHCI_EP_FMT, XHCI_EP_ARGS(*xhci_ep));
     111        usb_log_debug("Deallocating primary stream structures for "
     112                "endpoint " XHCI_EP_FMT, XHCI_EP_ARGS(*xhci_ep));
    109113
    110114        dma_buffer_free(&xhci_ep->primary_stream_ctx_dma);
     
    133137void xhci_stream_free_ds(xhci_endpoint_t *xhci_ep)
    134138{
    135         usb_log_debug("Freeing stream rings and context arrays of endpoint " XHCI_EP_FMT, XHCI_EP_ARGS(*xhci_ep));
     139        usb_log_debug("Freeing stream rings and context arrays of endpoint "
     140                XHCI_EP_FMT, XHCI_EP_ARGS(*xhci_ep));
    136141
    137142        for (size_t index = 0; index < xhci_ep->primary_stream_data_size; ++index) {
     
    141146}
    142147
    143 /** Initialize a single primary stream structure with given index.
     148/**
     149 * Initialize a single primary stream structure with given index.
    144150 * @param[in] hc Host controller of the endpoint.
    145151 * @param[in] xhci_ep XHCI bulk endpoint to use.
    146152 * @param[in] index index of the initialized stream structure.
    147153 */
    148 static int initialize_primary_stream(xhci_hc_t *hc, xhci_endpoint_t *xhci_ep, unsigned index) {
     154static int initialize_primary_stream(xhci_hc_t *hc, xhci_endpoint_t *xhci_ep,
     155    unsigned index)
     156{
    149157        xhci_stream_ctx_t *ctx = &xhci_ep->primary_stream_ctx_array[index];
    150158        xhci_stream_data_t *data = &xhci_ep->primary_stream_data_array[index];
     
    165173}
    166174
    167 /** Initialize primary streams of XHCI bulk endpoint.
     175/**
     176 * Initialize primary streams of XHCI bulk endpoint.
    168177 * @param[in] hc Host controller of the endpoint.
    169178 * @param[in] xhci_ep XHCI bulk endpoint to use.
     
    189198}
    190199
    191 /** Initialize secondary streams of XHCI bulk endpoint.
     200/**
     201 * Initialize secondary streams of XHCI bulk endpoint.
    192202 * @param[in] hc Host controller of the endpoint.
    193203 * @param[in] xhci_epi XHCI bulk endpoint to use.
     
    195205 * @param[in] count Number of secondary streams to initialize.
    196206 */
    197 static int initialize_secondary_streams(xhci_hc_t *hc, xhci_endpoint_t *xhci_ep, unsigned idx, unsigned count)
     207static int initialize_secondary_streams(xhci_hc_t *hc, xhci_endpoint_t *xhci_ep,
     208    unsigned idx, unsigned count)
    198209{
    199210        if (count == 0) {
    200                 /* The primary stream context can still point to a single ring, not a secondary. */
     211                /*
     212                 * The primary stream context can still point to a single ring, not
     213                 * a secondary.
     214                 */
    201215                return initialize_primary_stream(hc, xhci_ep, idx);
    202216        }
    203217
    204218        if ((count & (count - 1)) != 0 || count < 8 || count > 256) {
    205                 usb_log_error("The secondary stream array size must be a power of 2 between 8 and 256.");
     219                usb_log_error("The secondary stream array size must be a power of 2 "
     220                        "between 8 and 256.");
    206221                return EINVAL;
    207222        }
     
    217232        }
    218233
    219         if ((dma_buffer_alloc(&data->secondary_stream_ctx_dma, count * sizeof(xhci_stream_ctx_t)))) {
     234        if ((dma_buffer_alloc(&data->secondary_stream_ctx_dma,
     235                count * sizeof(xhci_stream_ctx_t)))) {
    220236                free(data->secondary_data);
    221237                return ENOMEM;
     
    251267}
    252268
    253 /** Configure XHCI bulk endpoint's stream context.
     269/**
     270 * Configure XHCI bulk endpoint's stream context.
    254271 * @param[in] xhci_ep Associated XHCI bulk endpoint.
    255272 * @param[in] ctx Endpoint context to configure.
     
    257274 * @param[in] lsa Specifies if the stream IDs point to primary stream array.
    258275 */
    259 static void setup_stream_context(xhci_endpoint_t *xhci_ep, xhci_ep_ctx_t *ctx, unsigned pstreams, unsigned lsa)
     276static void setup_stream_context(xhci_endpoint_t *xhci_ep, xhci_ep_ctx_t *ctx,
     277    unsigned pstreams, unsigned lsa)
    260278{
    261279        XHCI_EP_TYPE_SET(*ctx, xhci_endpoint_type(xhci_ep));
     
    269287}
    270288
    271 /** Verifies if all the common preconditions are satisfied.
     289/**
     290 * Verifies if all the common preconditions are satisfied.
    272291 * @param[in] hc Host controller of the endpoint.
    273292 * @param[in] dev Used device.
     
    285304
    286305        if (xhci_ep->max_streams <= 1) {
    287                 usb_log_error("Streams are not supported by endpoint " XHCI_EP_FMT, XHCI_EP_ARGS(*xhci_ep));
     306                usb_log_error("Streams are not supported by endpoint "
     307                    XHCI_EP_FMT, XHCI_EP_ARGS(*xhci_ep));
    288308                return EINVAL;
    289309        }
     
    294314        }
    295315
    296         /* The maximum amount of primary streams is 2 ^ (MaxPSA + 1) (See table 26 of XHCI specification) */
     316        /*
     317         * The maximum amount of primary streams is 2 ^ (MaxPSA + 1)
     318         * See table 26 of XHCI specification.
     319         */
    297320        uint8_t max_psa_size = 1 << (XHCI_REG_RD(hc->cap_regs, XHCI_CAP_MAX_PSA_SIZE) + 1);
    298321        if (count > max_psa_size) {
    299                 usb_log_error("Host controller only supports %u primary streams.", max_psa_size);
     322                usb_log_error("Host controller only supports "
     323                        "%u primary streams.", max_psa_size);
    300324                return EINVAL;
    301325        }
     
    315339}
    316340
    317 /** Cancels streams and reconfigures endpoint back to single ring no stream endpoint.
     341/**
     342 * Cancels streams and reconfigures endpoint back to single ring no stream endpoint.
    318343 * @param[in] hc Host controller of the endpoint.
    319344 * @param[in] dev Used device.
    320345 * @param[in] xhci_ep Associated XHCI bulk endpoint.
    321346 */
    322 int xhci_endpoint_remove_streams(xhci_hc_t *hc, xhci_device_t *dev, xhci_endpoint_t *xhci_ep)
     347int xhci_endpoint_remove_streams(xhci_hc_t *hc, xhci_device_t *dev,
     348    xhci_endpoint_t *xhci_ep)
    323349{
    324350        if (!xhci_ep->primary_stream_data_size) {
     
    340366}
    341367
    342 /** Initialize, setup and register primary streams.
     368/**
     369 * Initialize, setup and register primary streams.
    343370 * @param[in] hc Host controller of the endpoint.
    344371 * @param[in] dev Used device.
     
    374401
    375402        xhci_ep_ctx_t ep_ctx;
    376         /* Allowed values are 1-15, where 2 ^ pstreams is the actual amount of streams. */
     403        /*
     404         * Allowed values are 1-15, where 2 ^ pstreams is the actual amount of
     405         * streams.
     406         */
    377407        const size_t pstreams = fnzb32(count) - 1;
    378408        setup_stream_context(xhci_ep, &ep_ctx, pstreams, 1);
     
    381411}
    382412
    383 /** Initialize, setup and register secondary streams.
     413/**
     414 * Initialize, setup and register secondary streams.
    384415 * @param[in] hc Host controller of the endpoint.
    385416 * @param[in] dev Used device.
    386417 * @param[in] xhci_ep Associated XHCI bulk endpoint.
    387  * @param[in] sizes Amount of secondary streams in each primary stream.
    388                                         This array should have exactly count elements.
    389                                         If the size is 0, then a primary ring is created with that index.
     418 * @param[in] sizes Amount of secondary streams in each of the primary streams.
     419 *                  This array should have exactly count elements. If the size
     420 *                  is 0, then a primary ring is created with that index.
    390421 * @param[in] count Amount of primary streams requested.
    391422 */
  • uspace/drv/bus/usb/xhci/transfers.c

    re546142 r8033f89  
    151151        TRB_CTRL_SET_IDT(*trb_setup, 1);
    152152        TRB_CTRL_SET_TRB_TYPE(*trb_setup, XHCI_TRB_TYPE_SETUP_STAGE);
    153         TRB_CTRL_SET_TRT(*trb_setup, get_transfer_type(trb_setup, setup->request_type, setup->length));
     153        TRB_CTRL_SET_TRT(*trb_setup,
     154            get_transfer_type(trb_setup, setup->request_type, setup->length));
    154155
    155156        /* Data stage */
     
    178179        xhci_trb_clean(trb_status);
    179180
    180         // FIXME: Evaluate next TRB? 4.12.3
    181         // TRB_CTRL_SET_ENT(*trb_status, 1);
    182 
    183181        TRB_CTRL_SET_IOC(*trb_status, 1);
    184182        TRB_CTRL_SET_TRB_TYPE(*trb_status, XHCI_TRB_TYPE_STATUS_STAGE);
    185         TRB_CTRL_SET_DIR(*trb_status, get_status_direction_flag(trb_setup, setup->request_type, setup->length));
     183        TRB_CTRL_SET_DIR(*trb_status, get_status_direction_flag(trb_setup,
     184            setup->request_type, setup->length));
    186185
    187186        // Issue a Configure Endpoint command, if needed.
     
    192191        }
    193192
    194         return xhci_trb_ring_enqueue_multiple(get_ring(transfer), trbs, trbs_used, &transfer->interrupt_trb_phys);
     193        return xhci_trb_ring_enqueue_multiple(get_ring(transfer), trbs,
     194            trbs_used, &transfer->interrupt_trb_phys);
    195195}
    196196
     
    303303                /* We are received transfer pointer instead - work with that */
    304304                transfer = (xhci_transfer_t *) addr;
    305                 xhci_trb_ring_update_dequeue(get_ring(transfer), transfer->interrupt_trb_phys);
     305                xhci_trb_ring_update_dequeue(get_ring(transfer),
     306                    transfer->interrupt_trb_phys);
    306307                batch = &transfer->batch;
    307308
     
    453454         * the Reset Endpoint command.
    454455         */
    455         if (batch->ep->transfer_type == USB_TRANSFER_CONTROL && batch->dir == USB_DIRECTION_OUT) {
     456        if (batch->ep->transfer_type == USB_TRANSFER_CONTROL
     457            && batch->dir == USB_DIRECTION_OUT) {
    456458                const usb_device_request_setup_packet_t *request = &batch->setup.packet;
    457459                if (request->request == USB_DEVREQ_CLEAR_FEATURE
     
    460462                        const uint16_t index = uint16_usb2host(request->index);
    461463                        const usb_endpoint_t ep_num = index & 0xf;
    462                         const usb_direction_t dir = (index >> 7) ? USB_DIRECTION_IN : USB_DIRECTION_OUT;
     464                        const usb_direction_t dir = (index >> 7)
     465                            ? USB_DIRECTION_IN
     466                            : USB_DIRECTION_OUT;
    463467                        endpoint_t *halted_ep = bus_find_endpoint(&xhci_dev->base, ep_num, dir);
    464468                        if (halted_ep) {
    465469                                /*
    466                                  * TODO: Find out how to come up with stream_id. It
    467                                  * might be possible that we have to clear all of them.
     470                                 * TODO: Find out how to come up with stream_id. It might be
     471                                 * possible that we have to clear all of them.
    468472                                 */
    469473                                xhci_endpoint_clear_halt(xhci_endpoint_get(halted_ep), 0);
    470474                                endpoint_del_ref(halted_ep);
    471475                        } else {
    472                                 usb_log_warning("Device(%u): Resetting unregistered endpoint %u %s.", xhci_dev->base.address, ep_num, usb_str_direction(dir));
     476                                usb_log_warning("Device(%u): Resetting unregistered endpoint"
     477                                        " %u %s.", xhci_dev->base.address, ep_num,
     478                                        usb_str_direction(dir));
    473479                        }
    474480                }
     
    487493
    488494        hc_ring_ep_doorbell(xhci_ep, batch->target.stream);
    489 
    490         /* After the critical section, the transfer can already be finished or aborted. */
    491         transfer = NULL; batch = NULL;
    492495        fibril_mutex_unlock(&ep->guard);
    493496        return EOK;
  • uspace/drv/bus/usb/xhci/trb_ring.c

    re546142 r8033f89  
    156156
    157157        list_foreach_safe(ring->segments, cur, next) {
    158                 trb_segment_t *segment = list_get_instance(cur, trb_segment_t, segments_link);
     158                trb_segment_t *segment =
     159                    list_get_instance(cur, trb_segment_t, segments_link);
    159160                trb_segment_free(segment);
    160161        }
     
    171172static void trb_ring_resolve_link(xhci_trb_ring_t *ring)
    172173{
    173         link_t *next_segment = list_next(&ring->enqueue_segment->segments_link, &ring->segments);
     174        link_t *next_segment =
     175            list_next(&ring->enqueue_segment->segments_link, &ring->segments);
    174176        if (!next_segment)
    175177                next_segment = list_first(&ring->segments);
    176178        assert(next_segment);
    177179
    178         ring->enqueue_segment = list_get_instance(next_segment, trb_segment_t, segments_link);
     180        ring->enqueue_segment =
     181            list_get_instance(next_segment, trb_segment_t, segments_link);
    179182        ring->enqueue_trb = segment_begin(ring->enqueue_segment);
    180183}
     
    206209 * The copied TRBs must be contiguous in memory, and must not contain Link TRBs.
    207210 *
    208  * We cannot avoid the copying, because the TRB in ring should be updated atomically.
     211 * We cannot avoid the copying, because the TRB in ring should be updated
     212 * atomically.
    209213 *
    210214 * @param first_trb the first TRB
     
    405409        /* Wrapping around segment boundary */
    406410        if (index >= SEGMENT_TRB_COUNT) {
    407                 link_t *next_segment = list_next(&ring->dequeue_segment->segments_link, &ring->segments);
     411                link_t *next_segment =
     412                    list_next(&ring->dequeue_segment->segments_link, &ring->segments);
    408413
    409414                /* Wrapping around table boundary */
     
    413418                }
    414419
    415                 ring->dequeue_segment = list_get_instance(next_segment, trb_segment_t, segments_link);
     420                ring->dequeue_segment =
     421                    list_get_instance(next_segment, trb_segment_t, segments_link);
    416422                ring->dequeue_trb = segment_begin(ring->dequeue_segment);
    417423        }
Note: See TracChangeset for help on using the changeset viewer.