Changeset 8033f89 in mainline
- Timestamp:
- 2018-01-23T12:41:22Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e7e1fd3
- Parents:
- e546142
- Location:
- uspace/drv/bus/usb/xhci
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/xhci/commands.c
re546142 r8033f89 244 244 cr_set_state(cr, XHCI_CR_STATE_CLOSED); 245 245 246 /* Some systems, inc. QEMU, need whole 64-bit qword to be written */ 246 247 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 write248 XHCI_REG_SET(hc->op_regs, XHCI_OP_CRCR_HI, 0); 248 249 249 250 while (XHCI_REG_RD(hc->op_regs, XHCI_OP_CRR)) … … 259 260 static void abort_command_ring(xhci_hc_t *hc) 260 261 { 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); 263 265 } 264 266 … … 370 372 command->slot_id = TRB_GET_SLOT(*trb); 371 373 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))); 373 376 374 377 if (code != XHCI_TRBC_SUCCESS) { … … 412 415 413 416 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); 415 419 416 420 return enqueue_command(hc, cmd); … … 683 687 while (!cmd->_header.completed) { 684 688 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); 686 691 687 692 /* The waiting timed out. Current command (not necessarily -
uspace/drv/bus/usb/xhci/debug.c
re546142 r8033f89 264 264 void xhci_dump_trb(const xhci_trb_t *trb) 265 265 { 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); 267 269 } 268 270 … … 330 332 unsigned psic = XHCI_REG_RD(ec, XHCI_EC_SP_PSIC); 331 333 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, 333 336 XHCI_REG_RD(ec, XHCI_EC_SP_MAJOR), 334 337 XHCI_REG_RD(ec, XHCI_EC_SP_MINOR), -
uspace/drv/bus/usb/xhci/device.c
re546142 r8033f89 56 56 #include "device.h" 57 57 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 */ 59 62 static const usb_endpoint_descriptors_t ep0_initial_desc = { 60 63 .endpoint.max_packet_size = CTRL_PIPE_MIN_PACKET_SIZE, … … 87 90 dev->base.endpoints[0] = ep0_base; 88 91 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)); 90 94 ep0_base->max_packet_size = hc_get_ep0_initial_mps(dev->base.speed); 91 95 … … 117 121 118 122 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))) 120 125 return err; 121 126 … … 160 165 } 161 166 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); 163 169 return EOK; 164 170 } … … 197 203 198 204 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)); 200 207 return err; 201 208 } … … 208 215 209 216 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)); 211 219 goto err_address; 212 220 } … … 215 223 216 224 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)); 218 227 goto err_address; 219 228 } 220 229 221 230 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)); 224 234 225 235 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)); 227 238 goto err_address; 228 239 } … … 253 264 const uint32_t slot_id = xhci_dev->slot_id; 254 265 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)); 257 268 } 258 269 … … 277 288 /* Transition the device from the Addressed to the Configured state. */ 278 289 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)); 280 292 return err; 281 293 } … … 302 314 /* Issue one HC command to simultaneously drop all endpoints except zero. */ 303 315 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)); 306 318 } 307 319 } … … 339 351 } 340 352 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 */ 342 358 XHCI_SLOT_CTX_ENTRIES_SET(*ctx, 31); 343 359 } -
uspace/drv/bus/usb/xhci/endpoint.c
re546142 r8033f89 58 58 * @return Error code. 59 59 */ 60 static int xhci_endpoint_init(xhci_endpoint_t *xhci_ep, device_t *dev, const usb_endpoint_descriptors_t *desc) 60 static int xhci_endpoint_init(xhci_endpoint_t *xhci_ep, device_t *dev, 61 const usb_endpoint_descriptors_t *desc) 61 62 { 62 63 int rc; … … 79 80 xhci_ep->mult = 1; 80 81 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 82 84 * packets per service interval is determined from max_burst and mult. 83 85 */ … … 93 95 * others have 2-based log of it. 94 96 */ 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) { 96 99 xhci_ep->interval = 1 << (xhci_ep->interval - 1); 97 100 } … … 119 122 * Bus callback. 120 123 */ 121 endpoint_t *xhci_endpoint_create(device_t *dev, const usb_endpoint_descriptors_t *desc) 124 endpoint_t *xhci_endpoint_create(device_t *dev, 125 const usb_endpoint_descriptors_t *desc) 122 126 { 123 127 const usb_transfer_type_t type = USB_ED_GET_TRANSFER_TYPE(desc->endpoint); … … 193 197 const int err = hc_stop_endpoint(xhci_ep); 194 198 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)); 197 202 } 198 203 … … 233 238 234 239 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)); 236 242 } 237 243 } else { … … 271 277 } 272 278 273 /** Allocate transfer data structures for XHCI endpoint not using streams. 279 /** 280 * Allocate transfer data structures for XHCI endpoint not using streams. 274 281 * @param[in] xhci_ep XHCI endpoint to allocate data structures for. 275 282 * … … 279 286 { 280 287 /* 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)); 282 290 283 291 xhci_ep->primary_stream_data_array = NULL; … … 299 307 } 300 308 301 /** Free transfer data structures for XHCI endpoint. 309 /** 310 * Free transfer data structures for XHCI endpoint. 302 311 * @param[in] xhci_ep XHCI endpoint to free data structures for. 303 312 */ … … 307 316 xhci_stream_free_ds(xhci_ep); 308 317 } 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)); 310 320 xhci_trb_ring_fini(&xhci_ep->ring); 311 321 } … … 329 339 } 330 340 331 /** Configure endpoint context of a control endpoint. 341 /** 342 * Configure endpoint context of a control endpoint. 332 343 * @param[in] ep XHCI control endpoint. 333 344 * @param[in] ctx Endpoint context to configure. … … 344 355 } 345 356 346 /** Configure endpoint context of a bulk endpoint. 357 /** 358 * Configure endpoint context of a bulk endpoint. 347 359 * @param[in] ep XHCI bulk endpoint. 348 360 * @param[in] ctx Endpoint context to configure. … … 360 372 } 361 373 362 /** Configure endpoint context of a isochronous endpoint. 374 /** 375 * Configure endpoint context of a isochronous endpoint. 363 376 * @param[in] ep XHCI isochronous endpoint. 364 377 * @param[in] ctx Endpoint context to configure. … … 379 392 } 380 393 381 /** Configure endpoint context of a interrupt endpoint. 394 /** 395 * Configure endpoint context of a interrupt endpoint. 382 396 * @param[in] ep XHCI interrupt endpoint. 383 397 * @param[in] ctx Endpoint context to configure. … … 399 413 typedef void (*setup_ep_ctx_helper)(xhci_endpoint_t *, xhci_ep_ctx_t *); 400 414 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 */ 402 419 static const setup_ep_ctx_helper setup_ep_ctx_helpers[] = { 403 420 [USB_TRANSFER_CONTROL] = setup_control_ep_ctx, -
uspace/drv/bus/usb/xhci/hc.c
re546142 r8033f89 139 139 140 140 /* 141 * Speed is not implied, but using one of default PSIV. This is142 * not clearly stated in xHCI spec. There is a clear intention143 * to allow xHCI to specify its own speed parameters, but144 * throughout the document, they used fixed values for e.g.145 * High-speed (3), without stating the controller shall have146 * implied default speeds - and for instance Intel controllers147 * do not. So let's check if the values match and if so, accept148 * 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. 149 149 * 150 150 * The main reason we need this is the usb_speed to have … … 157 157 && default_psiv_to_port_speed[psiv].tx_bps == bps) { 158 158 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); 160 161 continue; 161 162 } … … 171 172 if (sim == XHCI_PSI_PLT_SYMM || sim == XHCI_PSI_PLT_TX) { 172 173 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); 174 177 } 175 178 } … … 395 398 memcpy(code->cmds, irq_commands, sizeof(irq_commands)); 396 399 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 399 407 code->cmds[0].addr = intr0_iman; 400 408 code->cmds[1].value = host2xhci(32, 1); … … 447 455 448 456 /* 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))) 450 459 return ETIMEOUT; 451 460 … … 533 542 struct timeval tv; 534 543 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); 536 546 hc->wrap_time = ((uint64_t) tv.tv_sec) * 1000000 + ((uint64_t) tv.tv_usec); 537 547 ++hc->wrap_count; … … 596 606 fibril_mutex_lock(&hc->event_fibril_completion.guard); 597 607 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); 599 610 fibril_mutex_unlock(&hc->event_fibril_completion.guard); 600 611 … … 612 623 * IPC notification will create new event handling fibril for us. 613 624 */ 614 static void hc_run_event_ring(xhci_hc_t *hc, xhci_event_ring_t *event_ring, xhci_interrupter_regs_t *intr) 625 static void hc_run_event_ring(xhci_hc_t *hc, xhci_event_ring_t *event_ring, 626 xhci_interrupter_regs_t *intr) 615 627 { 616 628 int err; … … 666 678 667 679 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!"); 669 682 status &= ~XHCI_REG_MASK(XHCI_OP_SRE); 670 683 } … … 674 687 675 688 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); 677 691 } 678 692 } … … 688 702 fibril_mutex_lock(&hc->event_fibril_completion.guard); 689 703 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); 691 706 fibril_mutex_unlock(&hc->event_fibril_completion.guard); 692 707 xhci_sw_ring_fini(&hc->sw_ring); … … 830 845 * we have to rely on reverse mapping on others. */ 831 846 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)); 833 849 return EINVAL; 834 850 } … … 850 866 851 867 /* 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 ))) 853 872 return err; 854 873 … … 875 894 return err; 876 895 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 ); 878 900 } 879 901 … … 888 910 889 911 /* 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 ); 891 916 } 892 917 … … 917 942 xhci_setup_endpoint_context(ep, ep_ctx); 918 943 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 ); 920 948 } 921 949 … … 941 969 XHCI_INPUT_CTRL_CTX_DROP_SET(*XHCI_GET_CTRL_CTX(ictx, hc), dci); 942 970 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 ); 944 975 } 945 976 … … 971 1002 xhci_setup_endpoint_context(ep, ep_ctx); 972 1003 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 ); 974 1008 } 975 1009 … … 985 1019 const unsigned dci = endpoint_dci(ep); 986 1020 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 ); 988 1025 } 989 1026 … … 999 1036 const unsigned dci = endpoint_dci(ep); 1000 1037 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 ); 1002 1042 } 1003 1043 … … 1018 1058 xhci_hc_t * const hc = bus_to_hc(endpoint_get_bus(&ep->base)); 1019 1059 return xhci_cmd_sync_inline(hc, SET_TR_DEQUEUE_POINTER, 1020 1021 1022 1023 1024 1060 .slot_id = dev->slot_id, 1061 .endpoint_id = dci, 1062 .stream_id = stream_id, 1063 .dequeue_ptr = addr, 1064 ); 1025 1065 } 1026 1066 -
uspace/drv/bus/usb/xhci/hw_struct/common.h
re546142 r8033f89 59 59 typedef volatile uint64_t xhci_qword_t __attribute__((aligned(8))); 60 60 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))) 63 65 64 66 /** … … 67 69 * Not thread-safe, proper synchronization over this dword must be assured. 68 70 */ 69 static inline void xhci_dword_set_bits(xhci_dword_t *storage, uint32_t value, unsigned hi, unsigned lo) 71 static inline void xhci_dword_set_bits(xhci_dword_t *storage, uint32_t value, 72 unsigned hi, unsigned lo) 70 73 { 71 74 const uint32_t mask = host2xhci(32, BIT_RANGE(uint32_t, hi, lo)); … … 82 85 } 83 86 84 static inline void xhci_qword_set_bits(xhci_qword_t *storage, uint64_t value, unsigned hi, unsigned lo) 87 static inline void xhci_qword_set_bits(xhci_qword_t *storage, uint64_t value, 88 unsigned hi, unsigned lo) 85 89 { 86 90 const uint64_t mask = host2xhci(64, BIT_RANGE(uint64_t, hi, lo)); … … 89 93 } 90 94 91 static inline int xhci_reg_wait(xhci_dword_t *reg, uint32_t mask, uint32_t expected) 95 static inline int xhci_reg_wait(xhci_dword_t *reg, uint32_t mask, 96 uint32_t expected) 92 97 { 93 98 mask = host2xhci(32, mask); -
uspace/drv/bus/usb/xhci/hw_struct/regs.h
re546142 r8033f89 84 84 * Field handling is the easiest. Just do it with whole field. 85 85 */ 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); 90 94 #define XHCI_REG_MASK_FIELD(size) (~((uint##size##_t) 0)) 91 95 #define XHCI_REG_SHIFT_FIELD(size) (0) … … 94 98 * Flags are just trivial case of ranges. 95 99 */ 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)) 100 108 #define XHCI_REG_MASK_FLAG(size, offset) BIT_V(uint##size##_t, offset) 101 109 #define XHCI_REG_SHIFT_FLAG(size, offset) (offset) … … 108 116 109 117 #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))), \ 111 120 host2xhci(size, BIT_RANGE(uint##size##_t, (hi), (lo))), \ 112 121 XHCI_PIO_CHANGE_UDELAY); 113 122 114 123 #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))), \ 116 126 XHCI_PIO_CHANGE_UDELAY); 117 127 118 128 #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))), \ 120 131 XHCI_PIO_CHANGE_UDELAY); 121 132 … … 409 420 #define XHCI_OP_CA crcr_lo, 32, FLAG, 2 410 421 #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 */ 413 426 #define XHCI_OP_CRCR_LO crcr_lo, 32, FIELD 414 427 #define XHCI_OP_CRCR_HI crcr_hi, 32, FIELD … … 466 479 #define XHCI_INTR_ERDP_ESI erdp_lo, 32, RANGE, 2, 0 467 480 #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).469 481 #define XHCI_INTR_ERDP_LO erdp_lo, 32, FIELD 470 482 #define XHCI_INTR_ERDP_HI erdp_hi, 32, FIELD … … 532 544 } xhci_extcap_t; 533 545 534 #define XHCI_EC_CAP_ID 535 #define XHCI_EC_SIZE 546 #define XHCI_EC_CAP_ID header, 32, RANGE, 7, 0 547 #define XHCI_EC_SIZE header, 32, RANGE, 15, 8 536 548 537 549 /* Supported protocol */ 538 #define XHCI_EC_SP_MINOR 539 #define XHCI_EC_SP_MAJOR 540 #define XHCI_EC_SP_NAME 541 #define XHCI_EC_SP_CP_OFF 542 #define XHCI_EC_SP_CP_COUNT 543 #define XHCI_EC_SP_PSIC 544 #define XHCI_EC_SP_SLOT_TYPE 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 545 557 546 558 typedef union { … … 582 594 ioport8_t sem_os; 583 595 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; 585 598 } xhci_legsup_t; 586 599 … … 588 601 #define XHCI_LEGSUP_SEM_OS sem_os, 8, FLAG, 0 589 602 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 592 606 593 607 #endif -
uspace/drv/bus/usb/xhci/hw_struct/trb.h
re546142 r8033f89 208 208 } xhci_erst_entry_t; 209 209 210 static inline void xhci_fill_erst_entry(xhci_erst_entry_t *entry, uintptr_t phys, int segments) 210 static inline void xhci_fill_erst_entry(xhci_erst_entry_t *entry, 211 uintptr_t phys, int segments) 211 212 { 212 213 xhci_qword_set(&entry->rs_base_ptr, phys); -
uspace/drv/bus/usb/xhci/isoch.c
re546142 r8033f89 81 81 fibril_timer_clear_locked(isoch->feeding_timer); 82 82 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)); 84 85 } 85 86 … … 110 111 static void timer_schedule_reset(xhci_endpoint_t *ep) { 111 112 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; 113 115 114 116 fibril_timer_clear_locked(isoch->reset_timer); … … 213 215 const uint32_t reg_mfindex = XHCI_REG_RD(hc->rt_regs, XHCI_RT_MFINDEX); 214 216 /* 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). 217 220 */ 218 221 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) { 220 224 ++epoch; 221 225 } … … 230 234 const xhci_hc_t *hc = bus->hc; 231 235 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 */ 233 240 const uint64_t delay = min(isoch->buffer_count * ep->interval, 10 * 8); 234 241 it->mfindex = get_current_microframe(hc) + 1 + delay + hc->ist; … … 262 269 * uframes it's off. 263 270 */ 264 static inline void window_decide(window_decision_t *res, xhci_hc_t *hc, uint64_t mfindex) 271 static inline void window_decide(window_decision_t *res, xhci_hc_t *hc, 272 uint64_t mfindex) 265 273 { 266 274 const uint64_t current_mf = get_current_microframe(hc); … … 333 341 334 342 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); 338 349 it->state = ISOCH_COMPLETE; 339 350 it->error = EOK; … … 348 359 if (fed) { 349 360 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 */ 351 365 timer_schedule_reset(ep); 352 366 } … … 405 419 406 420 case WINDOW_TOO_LATE: 407 usb_log_debug("[isoch] missed feeding buffer %lu at 0x%llx by %llu uframes",408 421 usb_log_debug("[isoch] missed feeding buffer %lu at 0x%llx by" 422 "%llu uframes", it - isoch->transfers, it->mfindex, wd.offset); 409 423 /* Missed the opportunity to schedule. Schedule ASAP. */ 410 424 it->mfindex += wd.offset; … … 435 449 if (fed) { 436 450 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 */ 438 455 timer_schedule_reset(ep); 439 456 } … … 502 519 calc_next_mfindex(ep, it); 503 520 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); 505 523 506 524 /* Prepare the transfer. */ … … 543 561 isoch_feed_in(ep); 544 562 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); 546 565 fibril_condvar_wait(&isoch->avail, &isoch->guard); 547 566 … … 568 587 } 569 588 570 void isoch_handle_transfer_event(xhci_hc_t *hc, xhci_endpoint_t *ep, xhci_trb_t *trb) 589 void isoch_handle_transfer_event(xhci_hc_t *hc, xhci_endpoint_t *ep, 590 xhci_trb_t *trb) 571 591 { 572 592 assert(ep->base.transfer_type == USB_TRANSFER_ISOCHRONOUS); … … 581 601 case XHCI_TRBC_RING_OVERRUN: 582 602 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 */ 585 608 usb_log_warning("Ring over/underrun."); 586 609 isoch_reset_no_timer(ep); -
uspace/drv/bus/usb/xhci/rh.c
re546142 r8033f89 155 155 return ENOENT; 156 156 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); 158 159 const usb_speed_t speed = port->rh->hc->speeds[psiv].usb_speed; 159 160 … … 171 172 port->device->rh_port = dev->port; 172 173 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); 174 176 175 177 if ((err = bus_device_enumerate(dev))) { … … 229 231 * standard mechanisms of register handling fails here. 230 232 */ 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); 232 235 233 236 const bool connected = !!(status & XHCI_REG_MASK(XHCI_PORT_CCS)); … … 264 267 } 265 268 266 void xhci_rh_set_ports_protocol(xhci_rh_t *rh, unsigned offset, unsigned count, unsigned major) 269 void xhci_rh_set_ports_protocol(xhci_rh_t *rh, 270 unsigned offset, unsigned count, unsigned major) 267 271 { 268 272 for (unsigned i = offset; i < offset + count; i++) … … 285 289 * such ports. 286 290 */ 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) 288 293 usb_port_connected(&port->base, &rh_enumerate_device); 289 294 } -
uspace/drv/bus/usb/xhci/streams.c
re546142 r8033f89 39 39 #include "streams.h" 40 40 41 /** Finds stream data with given stream ID if it exists. 41 /** 42 * Finds stream data with given stream ID if it exists. 42 43 * Note that streams with ID 0, 65534 and 65535 are reserved. 43 44 * Splits the ID into primary and secondary context ID and searches the structures. … … 52 53 53 54 /* 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); 56 59 57 60 if (primary_stream_id >= ep->primary_stream_data_size) { … … 59 62 } 60 63 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]; 62 66 if (secondary_stream_id != 0 && !primary_data->secondary_size) { 63 67 return NULL; … … 76 80 } 77 81 78 /** Initializes primary stream data structures in endpoint. 82 /** 83 * Initializes primary stream data structures in endpoint. 79 84 * @param[in] xhci_ep Used XHCI bulk endpoint. 80 85 * @param[in] count Amount of primary streams. … … 82 87 static int initialize_primary_structures(xhci_endpoint_t *xhci_ep, unsigned count) 83 88 { 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)))) { 88 94 return ENOMEM; 89 95 } … … 101 107 } 102 108 103 /**104 *105 */106 109 static void clear_primary_structures(xhci_endpoint_t *xhci_ep) 107 110 { 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)); 109 113 110 114 dma_buffer_free(&xhci_ep->primary_stream_ctx_dma); … … 133 137 void xhci_stream_free_ds(xhci_endpoint_t *xhci_ep) 134 138 { 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)); 136 141 137 142 for (size_t index = 0; index < xhci_ep->primary_stream_data_size; ++index) { … … 141 146 } 142 147 143 /** Initialize a single primary stream structure with given index. 148 /** 149 * Initialize a single primary stream structure with given index. 144 150 * @param[in] hc Host controller of the endpoint. 145 151 * @param[in] xhci_ep XHCI bulk endpoint to use. 146 152 * @param[in] index index of the initialized stream structure. 147 153 */ 148 static int initialize_primary_stream(xhci_hc_t *hc, xhci_endpoint_t *xhci_ep, unsigned index) { 154 static int initialize_primary_stream(xhci_hc_t *hc, xhci_endpoint_t *xhci_ep, 155 unsigned index) 156 { 149 157 xhci_stream_ctx_t *ctx = &xhci_ep->primary_stream_ctx_array[index]; 150 158 xhci_stream_data_t *data = &xhci_ep->primary_stream_data_array[index]; … … 165 173 } 166 174 167 /** Initialize primary streams of XHCI bulk endpoint. 175 /** 176 * Initialize primary streams of XHCI bulk endpoint. 168 177 * @param[in] hc Host controller of the endpoint. 169 178 * @param[in] xhci_ep XHCI bulk endpoint to use. … … 189 198 } 190 199 191 /** Initialize secondary streams of XHCI bulk endpoint. 200 /** 201 * Initialize secondary streams of XHCI bulk endpoint. 192 202 * @param[in] hc Host controller of the endpoint. 193 203 * @param[in] xhci_epi XHCI bulk endpoint to use. … … 195 205 * @param[in] count Number of secondary streams to initialize. 196 206 */ 197 static int initialize_secondary_streams(xhci_hc_t *hc, xhci_endpoint_t *xhci_ep, unsigned idx, unsigned count) 207 static int initialize_secondary_streams(xhci_hc_t *hc, xhci_endpoint_t *xhci_ep, 208 unsigned idx, unsigned count) 198 209 { 199 210 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 */ 201 215 return initialize_primary_stream(hc, xhci_ep, idx); 202 216 } 203 217 204 218 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."); 206 221 return EINVAL; 207 222 } … … 217 232 } 218 233 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)))) { 220 236 free(data->secondary_data); 221 237 return ENOMEM; … … 251 267 } 252 268 253 /** Configure XHCI bulk endpoint's stream context. 269 /** 270 * Configure XHCI bulk endpoint's stream context. 254 271 * @param[in] xhci_ep Associated XHCI bulk endpoint. 255 272 * @param[in] ctx Endpoint context to configure. … … 257 274 * @param[in] lsa Specifies if the stream IDs point to primary stream array. 258 275 */ 259 static void setup_stream_context(xhci_endpoint_t *xhci_ep, xhci_ep_ctx_t *ctx, unsigned pstreams, unsigned lsa) 276 static void setup_stream_context(xhci_endpoint_t *xhci_ep, xhci_ep_ctx_t *ctx, 277 unsigned pstreams, unsigned lsa) 260 278 { 261 279 XHCI_EP_TYPE_SET(*ctx, xhci_endpoint_type(xhci_ep)); … … 269 287 } 270 288 271 /** Verifies if all the common preconditions are satisfied. 289 /** 290 * Verifies if all the common preconditions are satisfied. 272 291 * @param[in] hc Host controller of the endpoint. 273 292 * @param[in] dev Used device. … … 285 304 286 305 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)); 288 308 return EINVAL; 289 309 } … … 294 314 } 295 315 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 */ 297 320 uint8_t max_psa_size = 1 << (XHCI_REG_RD(hc->cap_regs, XHCI_CAP_MAX_PSA_SIZE) + 1); 298 321 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); 300 324 return EINVAL; 301 325 } … … 315 339 } 316 340 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. 318 343 * @param[in] hc Host controller of the endpoint. 319 344 * @param[in] dev Used device. 320 345 * @param[in] xhci_ep Associated XHCI bulk endpoint. 321 346 */ 322 int xhci_endpoint_remove_streams(xhci_hc_t *hc, xhci_device_t *dev, xhci_endpoint_t *xhci_ep) 347 int xhci_endpoint_remove_streams(xhci_hc_t *hc, xhci_device_t *dev, 348 xhci_endpoint_t *xhci_ep) 323 349 { 324 350 if (!xhci_ep->primary_stream_data_size) { … … 340 366 } 341 367 342 /** Initialize, setup and register primary streams. 368 /** 369 * Initialize, setup and register primary streams. 343 370 * @param[in] hc Host controller of the endpoint. 344 371 * @param[in] dev Used device. … … 374 401 375 402 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 */ 377 407 const size_t pstreams = fnzb32(count) - 1; 378 408 setup_stream_context(xhci_ep, &ep_ctx, pstreams, 1); … … 381 411 } 382 412 383 /** Initialize, setup and register secondary streams. 413 /** 414 * Initialize, setup and register secondary streams. 384 415 * @param[in] hc Host controller of the endpoint. 385 416 * @param[in] dev Used device. 386 417 * @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 sizeis 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. 390 421 * @param[in] count Amount of primary streams requested. 391 422 */ -
uspace/drv/bus/usb/xhci/transfers.c
re546142 r8033f89 151 151 TRB_CTRL_SET_IDT(*trb_setup, 1); 152 152 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)); 154 155 155 156 /* Data stage */ … … 178 179 xhci_trb_clean(trb_status); 179 180 180 // FIXME: Evaluate next TRB? 4.12.3181 // TRB_CTRL_SET_ENT(*trb_status, 1);182 183 181 TRB_CTRL_SET_IOC(*trb_status, 1); 184 182 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)); 186 185 187 186 // Issue a Configure Endpoint command, if needed. … … 192 191 } 193 192 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); 195 195 } 196 196 … … 303 303 /* We are received transfer pointer instead - work with that */ 304 304 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); 306 307 batch = &transfer->batch; 307 308 … … 453 454 * the Reset Endpoint command. 454 455 */ 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) { 456 458 const usb_device_request_setup_packet_t *request = &batch->setup.packet; 457 459 if (request->request == USB_DEVREQ_CLEAR_FEATURE … … 460 462 const uint16_t index = uint16_usb2host(request->index); 461 463 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; 463 467 endpoint_t *halted_ep = bus_find_endpoint(&xhci_dev->base, ep_num, dir); 464 468 if (halted_ep) { 465 469 /* 466 * TODO: Find out how to come up with stream_id. It 467 * might bepossible 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. 468 472 */ 469 473 xhci_endpoint_clear_halt(xhci_endpoint_get(halted_ep), 0); 470 474 endpoint_del_ref(halted_ep); 471 475 } 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)); 473 479 } 474 480 } … … 487 493 488 494 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;492 495 fibril_mutex_unlock(&ep->guard); 493 496 return EOK; -
uspace/drv/bus/usb/xhci/trb_ring.c
re546142 r8033f89 156 156 157 157 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); 159 160 trb_segment_free(segment); 160 161 } … … 171 172 static void trb_ring_resolve_link(xhci_trb_ring_t *ring) 172 173 { 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); 174 176 if (!next_segment) 175 177 next_segment = list_first(&ring->segments); 176 178 assert(next_segment); 177 179 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); 179 182 ring->enqueue_trb = segment_begin(ring->enqueue_segment); 180 183 } … … 206 209 * The copied TRBs must be contiguous in memory, and must not contain Link TRBs. 207 210 * 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. 209 213 * 210 214 * @param first_trb the first TRB … … 405 409 /* Wrapping around segment boundary */ 406 410 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); 408 413 409 414 /* Wrapping around table boundary */ … … 413 418 } 414 419 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); 416 422 ring->dequeue_trb = segment_begin(ring->dequeue_segment); 417 423 }
Note:
See TracChangeset
for help on using the changeset viewer.