Lines Matching +full:max +full:- +full:burst +full:- +full:len
4 * Based on xHCI host controller driver in linux-kernel
14 * SPDX-License-Identifier: GPL-2.0+
49 2, /* bNrPorts -- runtime modified */
107 /* ss_wBytesPerInterval: 15 bits for max 15 ports */
122 for (dev = udev->dev; in xhci_get_ctrl()
124 dev = dev->parent) in xhci_get_ctrl()
128 return udev->controller; in xhci_get_ctrl()
150 return -ENODEV; in handshake()
154 usec--; in handshake()
158 return -ETIMEDOUT; in handshake()
173 temp = xhci_readl(&hcor->or_usbcmd); in xhci_start()
175 xhci_writel(&hcor->or_usbcmd, temp); in xhci_start()
181 ret = handshake(&hcor->or_usbsts, STS_HALT, 0, XHCI_MAX_HALT_USEC); in xhci_start()
193 * @return -EBUSY if XHCI Controller is not halted else status of handshake
203 state = xhci_readl(&hcor->or_usbsts) & STS_HALT; in xhci_reset()
205 cmd = xhci_readl(&hcor->or_usbcmd); in xhci_reset()
207 xhci_writel(&hcor->or_usbcmd, cmd); in xhci_reset()
210 ret = handshake(&hcor->or_usbsts, in xhci_reset()
215 return -EBUSY; in xhci_reset()
219 cmd = xhci_readl(&hcor->or_usbcmd); in xhci_reset()
221 xhci_writel(&hcor->or_usbcmd, cmd); in xhci_reset()
223 ret = handshake(&hcor->or_usbcmd, CMD_RESET, 0, XHCI_MAX_RESET_USEC); in xhci_reset()
231 return handshake(&hcor->or_usbsts, STS_CNR, 0, XHCI_MAX_RESET_USEC); in xhci_reset()
239 * Index = (epnum * 2) + direction - 1,
242 * index = (epnum * 2) + direction - 1 = (epnum * 2) + 1 - 1 = (epnum * 2)
254 index = (unsigned int)((usb_endpoint_num(desc) * 2) - in xhci_get_ep_index()
261 * Convert bInterval expressed in microframes (in 1-255 range) to exponent of
270 interval = fls(desc_interval) - 1; in xhci_microframes_to_exponent()
283 if (endpt_desc->bInterval == 0) in xhci_parse_microframe_interval()
286 return xhci_microframes_to_exponent(endpt_desc->bInterval, 0, 15); in xhci_parse_microframe_interval()
292 return xhci_microframes_to_exponent(endpt_desc->bInterval * 8, 3, 10); in xhci_parse_frame_interval()
296 * Convert interval expressed as 2^(bInterval - 1) == interval into
304 interval = clamp_val(endpt_desc->bInterval, 1, 16) - 1; in xhci_parse_exponent_interval()
305 if (interval != endpt_desc->bInterval - 1) in xhci_parse_exponent_interval()
306 debug("ep %#x - rounding interval to %d %sframes\n", in xhci_parse_exponent_interval()
307 endpt_desc->bEndpointAddress, 1 << interval, in xhci_parse_exponent_interval()
308 udev->speed == USB_SPEED_FULL ? "" : "micro"); in xhci_parse_exponent_interval()
310 if (udev->speed == USB_SPEED_FULL) { in xhci_parse_exponent_interval()
336 switch (udev->speed) { in xhci_get_endpoint_interval()
338 /* Max NAK rate */ in xhci_get_endpoint_interval()
345 /* Fall through - SS and HS isoc/int have same decoding */ in xhci_get_endpoint_interval()
384 * transaction opportunities per microframe", but that goes in the Max Burst
391 if (udev->speed < USB_SPEED_SUPER || in xhci_get_endpoint_mult()
395 return ss_ep_comp_desc->bmAttributes; in xhci_get_endpoint_mult()
402 /* Super speed and Plus have max burst in ep companion desc */ in xhci_get_endpoint_max_burst()
403 if (udev->speed >= USB_SPEED_SUPER) in xhci_get_endpoint_max_burst()
404 return ss_ep_comp_desc->bMaxBurst; in xhci_get_endpoint_max_burst()
406 if (udev->speed == USB_SPEED_HIGH && in xhci_get_endpoint_max_burst()
409 return usb_endpoint_maxp_mult(endpt_desc) - 1; in xhci_get_endpoint_max_burst()
416 * Basically, this is the maxpacket size, multiplied by the burst size
432 if (udev->speed >= USB_SPEED_SUPER) in xhci_get_max_esit_payload()
433 return le16_to_cpu(ss_ep_comp_desc->wBytesPerInterval); in xhci_get_max_esit_payload()
438 /* A 0 in max burst means 1 transfer per ESIT */ in xhci_get_max_esit_payload()
448 * @return 0 on success, -1 on failure
457 virt_dev = ctrl->devs[udev->slot_id]; in xhci_configure_endpoints()
458 in_ctx = virt_dev->in_ctx; in xhci_configure_endpoints()
460 xhci_flush_cache((uintptr_t)in_ctx->bytes, in_ctx->size); in xhci_configure_endpoints()
461 xhci_queue_command(ctrl, in_ctx->bytes, udev->slot_id, 0, in xhci_configure_endpoints()
464 BUG_ON(TRB_TO_SLOT_ID(le32_to_cpu(event->event_cmd.flags)) in xhci_configure_endpoints()
465 != udev->slot_id); in xhci_configure_endpoints()
467 switch (GET_COMP_CODE(le32_to_cpu(event->event_cmd.status))) { in xhci_configure_endpoints()
475 GET_COMP_CODE(le32_to_cpu(event->event_cmd.status))); in xhci_configure_endpoints()
476 return -EINVAL; in xhci_configure_endpoints()
506 int slot_id = udev->slot_id; in xhci_set_configuration()
507 struct xhci_virt_device *virt_dev = ctrl->devs[slot_id]; in xhci_set_configuration()
516 out_ctx = virt_dev->out_ctx; in xhci_set_configuration()
517 in_ctx = virt_dev->in_ctx; in xhci_set_configuration()
519 num_of_ep = udev->config.if_desc[0].no_of_ep; in xhci_set_configuration()
520 ifdesc = &udev->config.if_desc[0]; in xhci_set_configuration()
524 ctrl_ctx->add_flags = cpu_to_le32(SLOT_FLAG); in xhci_set_configuration()
525 ctrl_ctx->drop_flags = 0; in xhci_set_configuration()
529 ep_flag = xhci_get_ep_index(&ifdesc->ep_desc[cur_ep]); in xhci_set_configuration()
530 ctrl_ctx->add_flags |= cpu_to_le32(1 << (ep_flag + 1)); in xhci_set_configuration()
535 xhci_inval_cache((uintptr_t)out_ctx->bytes, out_ctx->size); in xhci_set_configuration()
540 slot_ctx->dev_info &= ~(cpu_to_le32(LAST_CTX_MASK)); in xhci_set_configuration()
541 slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(max_ep_flag + 1) | 0); in xhci_set_configuration()
550 endpt_desc = &ifdesc->ep_desc[cur_ep]; in xhci_set_configuration()
551 ss_ep_comp_desc = &ifdesc->ss_ep_comp_desc[cur_ep]; in xhci_set_configuration()
558 * size. For Isoc and Int, set it to max available. in xhci_set_configuration()
574 virt_dev->eps[ep_index].ring = xhci_ring_alloc(1, true); in xhci_set_configuration()
575 if (!virt_dev->eps[ep_index].ring) in xhci_set_configuration()
576 return -ENOMEM; in xhci_set_configuration()
579 dir = (((endpt_desc->bEndpointAddress) & (0x80)) >> 7); in xhci_set_configuration()
580 ep_type = (((endpt_desc->bmAttributes) & (0x3)) | (dir << 2)); in xhci_set_configuration()
582 ep_ctx[ep_index]->ep_info = in xhci_set_configuration()
586 ep_ctx[ep_index]->ep_info2 = in xhci_set_configuration()
588 ep_ctx[ep_index]->ep_info2 |= in xhci_set_configuration()
590 (get_unaligned(&endpt_desc->wMaxPacketSize))); in xhci_set_configuration()
595 ep_ctx[ep_index]->ep_info2 |= in xhci_set_configuration()
600 virt_dev->eps[ep_index].ring->enqueue; in xhci_set_configuration()
601 ep_ctx[ep_index]->deq = cpu_to_le64(trb_64 | in xhci_set_configuration()
602 virt_dev->eps[ep_index].ring->cycle_state); in xhci_set_configuration()
610 ep_ctx[ep_index]->tx_info = in xhci_set_configuration()
632 int slot_id = udev->slot_id; in xhci_address_device()
635 virt_dev = ctrl->devs[slot_id]; in xhci_address_device()
638 * This is the first Set Address since device plug-in in xhci_address_device()
641 debug("Setting up addressable devices %p\n", ctrl->dcbaa); in xhci_address_device()
644 ctrl_ctx = xhci_get_input_control_ctx(virt_dev->in_ctx); in xhci_address_device()
645 ctrl_ctx->add_flags = cpu_to_le32(SLOT_FLAG | EP0_FLAG); in xhci_address_device()
646 ctrl_ctx->drop_flags = 0; in xhci_address_device()
650 BUG_ON(TRB_TO_SLOT_ID(le32_to_cpu(event->event_cmd.flags)) != slot_id); in xhci_address_device()
652 switch (GET_COMP_CODE(le32_to_cpu(event->event_cmd.status))) { in xhci_address_device()
657 ret = -EINVAL; in xhci_address_device()
661 ret = -EPROTO; in xhci_address_device()
666 ret = -ENODEV; in xhci_address_device()
670 udev->status = 0; in xhci_address_device()
674 GET_COMP_CODE(le32_to_cpu(event->event_cmd.status))); in xhci_address_device()
675 ret = -EINVAL; in xhci_address_device()
688 xhci_inval_cache((uintptr_t)virt_dev->out_ctx->bytes, in xhci_address_device()
689 virt_dev->out_ctx->size); in xhci_address_device()
690 slot_ctx = xhci_get_slot_ctx(ctrl, virt_dev->out_ctx); in xhci_address_device()
693 le32_to_cpu(slot_ctx->dev_state) & DEV_ADDR_MASK); in xhci_address_device()
715 * If this device is root-hub, don't do any xHC related in _xhci_alloc_device()
718 if (ctrl->rootdev == 0) { in _xhci_alloc_device()
719 udev->speed = USB_SPEED_SUPER; in _xhci_alloc_device()
725 BUG_ON(GET_COMP_CODE(le32_to_cpu(event->event_cmd.status)) in _xhci_alloc_device()
728 udev->slot_id = TRB_TO_SLOT_ID(le32_to_cpu(event->event_cmd.flags)); in _xhci_alloc_device()
732 ret = xhci_alloc_virt_device(ctrl, udev->slot_id); in _xhci_alloc_device()
753 * Full speed devices may have a max packet size greater than 8 bytes, but the
755 * descriptor. If the usb_device's max packet size changes after that point,
764 unsigned int slot_id = udev->slot_id; in xhci_check_maxpacket()
774 out_ctx = ctrl->devs[slot_id]->out_ctx; in xhci_check_maxpacket()
775 xhci_inval_cache((uintptr_t)out_ctx->bytes, out_ctx->size); in xhci_check_maxpacket()
778 hw_max_packet_size = MAX_PACKET_DECODED(le32_to_cpu(ep_ctx->ep_info2)); in xhci_check_maxpacket()
779 max_packet_size = udev->epmaxpacketin[0]; in xhci_check_maxpacket()
781 debug("Max Packet Size for ep 0 changed.\n"); in xhci_check_maxpacket()
782 debug("Max packet size in usb_device = %d\n", max_packet_size); in xhci_check_maxpacket()
783 debug("Max packet size in xHCI HW = %d\n", hw_max_packet_size); in xhci_check_maxpacket()
787 xhci_endpoint_copy(ctrl, ctrl->devs[slot_id]->in_ctx, in xhci_check_maxpacket()
788 ctrl->devs[slot_id]->out_ctx, ep_index); in xhci_check_maxpacket()
789 in_ctx = ctrl->devs[slot_id]->in_ctx; in xhci_check_maxpacket()
791 ep_ctx->ep_info2 &= cpu_to_le32(~((0xffff & MAX_PACKET_MASK) in xhci_check_maxpacket()
793 ep_ctx->ep_info2 |= cpu_to_le32(MAX_PACKET(max_packet_size)); in xhci_check_maxpacket()
797 * FIXME: This won't work if a non-default control endpoint in xhci_check_maxpacket()
798 * changes max packet sizes. in xhci_check_maxpacket()
801 ctrl_ctx->add_flags = cpu_to_le32(EP0_FLAG); in xhci_check_maxpacket()
802 ctrl_ctx->drop_flags = 0; in xhci_check_maxpacket()
835 port_change_bit = "over-current"; in xhci_clear_port_change_bit()
870 /* Save read-only status and port state */ in xhci_port_state_to_neutral()
880 * @return returns 0 if successful else -1 on failure
888 int len, srclen; in xhci_submit_root() local
892 struct xhci_hccr *hccr = ctrl->hccr; in xhci_submit_root()
893 struct xhci_hcor *hcor = ctrl->hcor; in xhci_submit_root()
894 int max_ports = HCS_MAX_PORTS(xhci_readl(&hccr->cr_hcsparams1)); in xhci_submit_root()
896 if ((req->requesttype & USB_RT_PORT) && in xhci_submit_root()
897 le16_to_cpu(req->index) > max_ports) { in xhci_submit_root()
899 le16_to_cpu(req->index) - 1); in xhci_submit_root()
900 return -EINVAL; in xhci_submit_root()
904 (&hcor->portregs[le16_to_cpu(req->index) - 1].or_portsc); in xhci_submit_root()
907 typeReq = req->request | req->requesttype << 8; in xhci_submit_root()
911 switch (le16_to_cpu(req->value) >> 8) { in xhci_submit_root()
924 switch (le16_to_cpu(req->value) & 0xff) { in xhci_submit_root()
930 srcptr = "\16\3U\0-\0B\0o\0o\0t\0"; in xhci_submit_root()
941 le16_to_cpu(req->value)); in xhci_submit_root()
946 printf("unknown value %x\n", le16_to_cpu(req->value)); in xhci_submit_root()
951 switch (le16_to_cpu(req->value) >> 8) { in xhci_submit_root()
955 srcptr = &ctrl->hub; in xhci_submit_root()
959 printf("unknown value %x\n", le16_to_cpu(req->value)); in xhci_submit_root()
965 ctrl->rootdev = le16_to_cpu(req->value); in xhci_submit_root()
1033 switch (le16_to_cpu(req->value)) { in xhci_submit_root()
1047 printf("unknown feature %x\n", le16_to_cpu(req->value)); in xhci_submit_root()
1054 switch (le16_to_cpu(req->value)) { in xhci_submit_root()
1065 xhci_clear_port_change_bit((le16_to_cpu(req->value)), in xhci_submit_root()
1066 le16_to_cpu(req->index), in xhci_submit_root()
1070 printf("unknown feature %x\n", le16_to_cpu(req->value)); in xhci_submit_root()
1080 debug("scrlen = %d\n req->length = %d\n", in xhci_submit_root()
1081 srclen, le16_to_cpu(req->length)); in xhci_submit_root()
1083 len = min(srclen, (int)le16_to_cpu(req->length)); in xhci_submit_root()
1085 if (srcptr != NULL && len > 0) in xhci_submit_root()
1086 memcpy(buffer, srcptr, len); in xhci_submit_root()
1088 debug("Len is 0\n"); in xhci_submit_root()
1090 udev->act_len = len; in xhci_submit_root()
1091 udev->status = 0; in xhci_submit_root()
1096 udev->act_len = 0; in xhci_submit_root()
1097 udev->status = USB_ST_STALLED; in xhci_submit_root()
1099 return -ENODEV; in xhci_submit_root()
1117 printf("non-interrupt pipe (type=%lu)", usb_pipetype(pipe)); in _xhci_submit_int_msg()
1118 return -EINVAL; in _xhci_submit_int_msg()
1137 * @return returns 0 if successful else -1 on failure
1143 printf("non-bulk pipe (type=%lu)", usb_pipetype(pipe)); in _xhci_submit_bulk_msg()
1144 return -EINVAL; in _xhci_submit_bulk_msg()
1159 * @return returns 0 if successful else -1 on failure
1169 printf("non-control pipe (type=%lu)", usb_pipetype(pipe)); in _xhci_submit_control_msg()
1170 return -EINVAL; in _xhci_submit_control_msg()
1173 if (usb_pipedevice(pipe) == ctrl->rootdev) in _xhci_submit_control_msg()
1176 if (setup->request == USB_REQ_SET_ADDRESS && in _xhci_submit_control_msg()
1177 (setup->requesttype & USB_TYPE_MASK) == USB_TYPE_STANDARD) in _xhci_submit_control_msg()
1180 if (setup->request == USB_REQ_SET_CONFIGURATION && in _xhci_submit_control_msg()
1181 (setup->requesttype & USB_TYPE_MASK) == USB_TYPE_STANDARD) { in _xhci_submit_control_msg()
1200 hccr = ctrl->hccr; in xhci_lowlevel_init()
1201 hcor = ctrl->hcor; in xhci_lowlevel_init()
1204 * register with the max value of slots the HC can handle. in xhci_lowlevel_init()
1206 val = (xhci_readl(&hccr->cr_hcsparams1) & HCS_SLOTS_MASK); in xhci_lowlevel_init()
1207 val2 = xhci_readl(&hcor->or_config); in xhci_lowlevel_init()
1209 xhci_writel(&hcor->or_config, val); in xhci_lowlevel_init()
1213 return -ENOMEM; in xhci_lowlevel_init()
1215 reg = xhci_readl(&hccr->cr_hcsparams1); in xhci_lowlevel_init()
1221 reg = xhci_readl(&hccr->cr_hccparams); in xhci_lowlevel_init()
1231 memcpy(&ctrl->hub, &descriptor, sizeof(struct usb_hub_descriptor)); in xhci_lowlevel_init()
1235 return -ENODEV; in xhci_lowlevel_init()
1239 xhci_writel(&ctrl->ir_set->irq_control, 0x0); in xhci_lowlevel_init()
1240 xhci_writel(&ctrl->ir_set->irq_pending, 0x0); in xhci_lowlevel_init()
1242 reg = HC_VERSION(xhci_readl(&hccr->cr_capbase)); in xhci_lowlevel_init()
1252 xhci_reset(ctrl->hcor); in xhci_lowlevel_stop()
1255 temp = xhci_readl(&ctrl->hcor->or_usbsts); in xhci_lowlevel_stop()
1256 xhci_writel(&ctrl->hcor->or_usbsts, temp & ~STS_EINT); in xhci_lowlevel_stop()
1257 temp = xhci_readl(&ctrl->ir_set->irq_pending); in xhci_lowlevel_stop()
1258 xhci_writel(&ctrl->ir_set->irq_pending, ER_IRQ_DISABLE(temp)); in xhci_lowlevel_stop()
1269 if (hop->parent) in submit_control_msg()
1270 while (hop->parent->parent) in submit_control_msg()
1271 hop = hop->parent; in submit_control_msg()
1274 hop->portnr); in submit_control_msg()
1307 return -ENODEV; in usb_lowlevel_init()
1310 return -ENODEV; in usb_lowlevel_init()
1314 ctrl->hccr = hccr; in usb_lowlevel_init()
1315 ctrl->hcor = hcor; in usb_lowlevel_init()
1320 ctrl->hccr = NULL; in usb_lowlevel_init()
1321 ctrl->hcor = NULL; in usb_lowlevel_init()
1340 if (ctrl->hcor) { in usb_lowlevel_stop()
1360 debug("%s: dev='%s', udev=%p, udev->dev='%s', portnr=%d\n", __func__, in xhci_submit_control_msg()
1361 dev->name, udev, udev->dev->name, udev->portnr); in xhci_submit_control_msg()
1362 hub = udev->dev; in xhci_submit_control_msg()
1366 root_portnr = udev->portnr; in xhci_submit_control_msg()
1368 while (!usb_hub_is_root_hub(hub->parent)) in xhci_submit_control_msg()
1369 hub = hub->parent; in xhci_submit_control_msg()
1371 root_portnr = uhop->portnr; in xhci_submit_control_msg()
1377 if (hop->parent) in xhci_submit_control_msg()
1378 while (hop->parent->parent) in xhci_submit_control_msg()
1379 hop = hop->parent; in xhci_submit_control_msg()
1388 debug("%s: dev='%s', udev=%p\n", __func__, dev->name, udev); in xhci_submit_bulk_msg()
1396 debug("%s: dev='%s', udev=%p\n", __func__, dev->name, udev); in xhci_submit_int_msg()
1403 debug("%s: dev='%s', udev=%p\n", __func__, dev->name, udev); in xhci_alloc_device()
1410 struct usb_hub_device *hub = dev_get_uclass_priv(udev->dev); in xhci_update_hub_device()
1416 int slot_id = udev->slot_id; in xhci_update_hub_device()
1419 debug("%s: dev='%s', udev=%p\n", __func__, dev->name, udev); in xhci_update_hub_device()
1422 if (usb_hub_is_root_hub(udev->dev)) in xhci_update_hub_device()
1425 virt_dev = ctrl->devs[slot_id]; in xhci_update_hub_device()
1428 out_ctx = virt_dev->out_ctx; in xhci_update_hub_device()
1429 in_ctx = virt_dev->in_ctx; in xhci_update_hub_device()
1433 ctrl_ctx->add_flags = cpu_to_le32(SLOT_FLAG); in xhci_update_hub_device()
1434 ctrl_ctx->drop_flags = 0; in xhci_update_hub_device()
1436 xhci_inval_cache((uintptr_t)out_ctx->bytes, out_ctx->size); in xhci_update_hub_device()
1443 slot_ctx->dev_info |= cpu_to_le32(DEV_HUB); in xhci_update_hub_device()
1449 if (hub->tt.multi) in xhci_update_hub_device()
1450 slot_ctx->dev_info |= cpu_to_le32(DEV_MTT); in xhci_update_hub_device()
1451 else if (udev->speed == USB_SPEED_FULL) in xhci_update_hub_device()
1452 slot_ctx->dev_info &= cpu_to_le32(~DEV_MTT); in xhci_update_hub_device()
1453 slot_ctx->dev_info2 |= cpu_to_le32(XHCI_MAX_PORTS(udev->maxchild)); in xhci_update_hub_device()
1455 * Set TT think time - convert from ns to FS bit times. in xhci_update_hub_device()
1461 * This field shall be 0 if the device is not a high-spped hub. in xhci_update_hub_device()
1463 think_time = hub->tt.think_time; in xhci_update_hub_device()
1465 think_time = (think_time / 666) - 1; in xhci_update_hub_device()
1466 if (udev->speed == USB_SPEED_HIGH) in xhci_update_hub_device()
1467 slot_ctx->tt_info |= cpu_to_le32(TT_THINK_TIME(think_time)); in xhci_update_hub_device()
1468 slot_ctx->dev_state = 0; in xhci_update_hub_device()
1482 *size = (TRBS_PER_SEGMENT - 2) * TRB_MAX_BUFF_SIZE; in xhci_get_max_xfer_size()
1494 debug("%s: dev='%s', ctrl=%p, hccr=%p, hcor=%p\n", __func__, dev->name, in xhci_register()
1497 ctrl->dev = dev; in xhci_register()
1505 priv->desc_before_addr = false; in xhci_register()
1511 ctrl->hccr = hccr; in xhci_register()
1512 ctrl->hcor = hcor; in xhci_register()