Lines Matching +full:multi +full:- +full:tt

1 // SPDX-License-Identifier: GPL-2.0
20 #include <linux/dma-mapping.h>
23 #include "xhci-trace.h"
24 #include "xhci-debugfs.h"
25 #include "xhci-dbgcap.h"
43 struct xhci_segment *seg = ring->first_seg; in td_on_ring()
45 if (!td || !td->start_seg) in td_on_ring()
48 if (seg == td->start_seg) in td_on_ring()
50 seg = seg->next; in td_on_ring()
51 } while (seg && seg != ring->first_seg); in td_on_ring()
57 * xhci_handshake - spin reading hc until handshake completes or fails
67 * hardware flakeout), or the register reads as all-ones (hardware removed).
79 return -ENODEV; in xhci_handshake()
94 halted = readl(&xhci->op_regs->status) & STS_HALT; in xhci_quiesce()
98 cmd = readl(&xhci->op_regs->command); in xhci_quiesce()
100 writel(cmd, &xhci->op_regs->command); in xhci_quiesce()
118 ret = xhci_handshake(&xhci->op_regs->status, in xhci_halt()
125 xhci->xhc_state |= XHCI_STATE_HALTED; in xhci_halt()
126 xhci->cmd_ring_state = CMD_RING_STATE_STOPPED; in xhci_halt()
139 temp = readl(&xhci->op_regs->command); in xhci_start()
143 writel(temp, &xhci->op_regs->command); in xhci_start()
149 ret = xhci_handshake(&xhci->op_regs->status, in xhci_start()
151 if (ret == -ETIMEDOUT) in xhci_start()
157 xhci->xhc_state = 0; in xhci_start()
158 xhci->run_graceperiod = jiffies + msecs_to_jiffies(500); in xhci_start()
177 state = readl(&xhci->op_regs->status); in xhci_reset()
181 return -ENODEV; in xhci_reset()
190 command = readl(&xhci->op_regs->command); in xhci_reset()
192 writel(command, &xhci->op_regs->command); in xhci_reset()
201 if (xhci->quirks & XHCI_INTEL_HOST) in xhci_reset()
204 ret = xhci_handshake(&xhci->op_regs->command, CMD_RESET, 0, timeout_us); in xhci_reset()
208 if (xhci->quirks & XHCI_ASMEDIA_MODIFY_FLOWCONTROL) in xhci_reset()
209 usb_asmedia_modifyflowcontrol(to_pci_dev(xhci_to_hcd(xhci)->self.controller)); in xhci_reset()
217 ret = xhci_handshake(&xhci->op_regs->status, STS_CNR, 0, timeout_us); in xhci_reset()
219 xhci->usb2_rhub.bus_state.port_c_suspend = 0; in xhci_reset()
220 xhci->usb2_rhub.bus_state.suspended_ports = 0; in xhci_reset()
221 xhci->usb2_rhub.bus_state.resuming_ports = 0; in xhci_reset()
222 xhci->usb3_rhub.bus_state.port_c_suspend = 0; in xhci_reset()
223 xhci->usb3_rhub.bus_state.suspended_ports = 0; in xhci_reset()
224 xhci->usb3_rhub.bus_state.resuming_ports = 0; in xhci_reset()
231 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_zero_64b_regs()
252 if (!(xhci->quirks & XHCI_ZERO_64B_REGS) || !domain || in xhci_zero_64b_regs()
253 domain->type == IOMMU_DOMAIN_IDENTITY) in xhci_zero_64b_regs()
259 val = readl(&xhci->op_regs->command); in xhci_zero_64b_regs()
261 writel(val, &xhci->op_regs->command); in xhci_zero_64b_regs()
264 val = readl(&xhci->op_regs->status); in xhci_zero_64b_regs()
266 writel(val, &xhci->op_regs->status); in xhci_zero_64b_regs()
269 val = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr); in xhci_zero_64b_regs()
271 xhci_write_64(xhci, 0, &xhci->op_regs->dcbaa_ptr); in xhci_zero_64b_regs()
272 val = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); in xhci_zero_64b_regs()
274 xhci_write_64(xhci, 0, &xhci->op_regs->cmd_ring); in xhci_zero_64b_regs()
276 intrs = min_t(u32, HCS_MAX_INTRS(xhci->hcs_params1), in xhci_zero_64b_regs()
277 ARRAY_SIZE(xhci->run_regs->ir_set)); in xhci_zero_64b_regs()
282 ir = &xhci->run_regs->ir_set[i]; in xhci_zero_64b_regs()
283 val = xhci_read_64(xhci, &ir->erst_base); in xhci_zero_64b_regs()
285 xhci_write_64(xhci, 0, &ir->erst_base); in xhci_zero_64b_regs()
286 val= xhci_read_64(xhci, &ir->erst_dequeue); in xhci_zero_64b_regs()
288 xhci_write_64(xhci, 0, &ir->erst_dequeue); in xhci_zero_64b_regs()
292 err = xhci_handshake(&xhci->op_regs->status, in xhci_zero_64b_regs()
303 if (!ir || !ir->ir_set) in xhci_enable_interrupter()
304 return -EINVAL; in xhci_enable_interrupter()
306 iman = readl(&ir->ir_set->irq_pending); in xhci_enable_interrupter()
307 writel(ER_IRQ_ENABLE(iman), &ir->ir_set->irq_pending); in xhci_enable_interrupter()
316 if (!ir || !ir->ir_set) in xhci_disable_interrupter()
317 return -EINVAL; in xhci_disable_interrupter()
319 iman = readl(&ir->ir_set->irq_pending); in xhci_disable_interrupter()
320 writel(ER_IRQ_DISABLE(iman), &ir->ir_set->irq_pending); in xhci_disable_interrupter()
334 rhub = &xhci->usb3_rhub; in compliance_mode_recovery()
335 hcd = rhub->hcd; in compliance_mode_recovery()
340 for (i = 0; i < rhub->num_ports; i++) { in compliance_mode_recovery()
341 temp = readl(rhub->ports[i]->addr); in compliance_mode_recovery()
348 "Compliance mode detected->port %d", in compliance_mode_recovery()
353 if (hcd->state == HC_STATE_SUSPENDED) in compliance_mode_recovery()
360 if (xhci->port_status_u0 != ((1 << rhub->num_ports) - 1)) in compliance_mode_recovery()
361 mod_timer(&xhci->comp_mode_recovery_timer, in compliance_mode_recovery()
366 * Quirk to work around issue generated by the SN65LVPE502CP USB3.0 re-driver
377 xhci->port_status_u0 = 0; in compliance_mode_recovery_timer_init()
378 timer_setup(&xhci->comp_mode_recovery_timer, compliance_mode_recovery, in compliance_mode_recovery_timer_init()
380 xhci->comp_mode_recovery_timer.expires = jiffies + in compliance_mode_recovery_timer_init()
383 add_timer(&xhci->comp_mode_recovery_timer); in compliance_mode_recovery_timer_init()
390 * USB3.0 re-driver and that need the Compliance Mode Quirk.
392 * Vendor: Hewlett-Packard -> System Models: Z420, Z620 and Z820
403 if (!(strstr(dmi_sys_vendor, "Hewlett-Packard"))) in xhci_compliance_mode_recovery_timer_quirk_check()
417 return (xhci->port_status_u0 == ((1 << xhci->usb3_rhub.num_ports) - 1)); in xhci_all_ports_seen_u0()
422 * Initialize memory for HCD and xHC (one-time init).
434 spin_lock_init(&xhci->lock); in xhci_init()
435 if (xhci->hci_version == 0x95 && link_quirk) { in xhci_init()
438 xhci->quirks |= XHCI_LINK_TRB_QUIRK; in xhci_init()
448 xhci->quirks |= XHCI_COMP_MODE_QUIRK; in xhci_init()
455 /*-------------------------------------------------------------------------*/
459 struct xhci_interrupter *ir = xhci->interrupter; in xhci_run_finished()
467 spin_lock_irqsave(&xhci->lock, flags); in xhci_run_finished()
470 temp = readl(&xhci->op_regs->command); in xhci_run_finished()
472 writel(temp, &xhci->op_regs->command); in xhci_run_finished()
479 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_run_finished()
480 return -ENODEV; in xhci_run_finished()
483 xhci->cmd_ring_state = CMD_RING_STATE_RUNNING; in xhci_run_finished()
485 if (xhci->quirks & XHCI_NEC_HOST) in xhci_run_finished()
488 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_run_finished()
503 * Setup MSI-X vectors and enable interrupts.
511 struct xhci_interrupter *ir = xhci->interrupter; in xhci_run()
516 hcd->uses_new_polling = 1; in xhci_run()
522 temp_64 = xhci_read_64(xhci, &ir->ir_set->erst_dequeue); in xhci_run()
529 temp = readl(&ir->ir_set->irq_control); in xhci_run()
531 temp |= (xhci->imod_interval / 250) & ER_IRQ_INTERVAL_MASK; in xhci_run()
532 writel(temp, &ir->ir_set->irq_control); in xhci_run()
534 if (xhci->quirks & XHCI_NEC_HOST) { in xhci_run()
539 return -ENOMEM; in xhci_run()
556 set_bit(HCD_FLAG_DEFER_RH_REGISTER, &hcd->flags); in xhci_run()
575 struct xhci_interrupter *ir = xhci->interrupter; in xhci_stop()
577 mutex_lock(&xhci->mutex); in xhci_stop()
581 mutex_unlock(&xhci->mutex); in xhci_stop()
587 spin_lock_irq(&xhci->lock); in xhci_stop()
588 xhci->xhc_state |= XHCI_STATE_HALTED; in xhci_stop()
589 xhci->cmd_ring_state = CMD_RING_STATE_STOPPED; in xhci_stop()
592 spin_unlock_irq(&xhci->lock); in xhci_stop()
595 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && in xhci_stop()
597 del_timer_sync(&xhci->comp_mode_recovery_timer); in xhci_stop()
603 if (xhci->quirks & XHCI_AMD_PLL_FIX) in xhci_stop()
608 temp = readl(&xhci->op_regs->status); in xhci_stop()
609 writel((temp & ~0x1fff) | STS_EINT, &xhci->op_regs->status); in xhci_stop()
616 "xhci_stop completed - status = %x", in xhci_stop()
617 readl(&xhci->op_regs->status)); in xhci_stop()
618 mutex_unlock(&xhci->mutex); in xhci_stop()
623 * Shutdown HC (not bus-specific)
635 if (xhci->quirks & XHCI_SPURIOUS_REBOOT) in xhci_shutdown()
636 usb_disable_xhci_ports(to_pci_dev(hcd->self.sysdev)); in xhci_shutdown()
640 __func__, hcd->self.busnum); in xhci_shutdown()
641 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); in xhci_shutdown()
642 del_timer_sync(&hcd->rh_timer); in xhci_shutdown()
644 if (xhci->shared_hcd) { in xhci_shutdown()
645 clear_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags); in xhci_shutdown()
646 del_timer_sync(&xhci->shared_hcd->rh_timer); in xhci_shutdown()
649 spin_lock_irq(&xhci->lock); in xhci_shutdown()
654 * firmware delay in ADL-P PCH if port are left in U3 at shutdown in xhci_shutdown()
656 if (xhci->quirks & XHCI_SPURIOUS_WAKEUP || in xhci_shutdown()
657 xhci->quirks & XHCI_RESET_TO_DEFAULT) in xhci_shutdown()
660 spin_unlock_irq(&xhci->lock); in xhci_shutdown()
663 "xhci_shutdown completed - status = %x", in xhci_shutdown()
664 readl(&xhci->op_regs->status)); in xhci_shutdown()
671 struct xhci_interrupter *ir = xhci->interrupter; in xhci_save_registers()
673 xhci->s3.command = readl(&xhci->op_regs->command); in xhci_save_registers()
674 xhci->s3.dev_nt = readl(&xhci->op_regs->dev_notification); in xhci_save_registers()
675 xhci->s3.dcbaa_ptr = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr); in xhci_save_registers()
676 xhci->s3.config_reg = readl(&xhci->op_regs->config_reg); in xhci_save_registers()
681 ir->s3_erst_size = readl(&ir->ir_set->erst_size); in xhci_save_registers()
682 ir->s3_erst_base = xhci_read_64(xhci, &ir->ir_set->erst_base); in xhci_save_registers()
683 ir->s3_erst_dequeue = xhci_read_64(xhci, &ir->ir_set->erst_dequeue); in xhci_save_registers()
684 ir->s3_irq_pending = readl(&ir->ir_set->irq_pending); in xhci_save_registers()
685 ir->s3_irq_control = readl(&ir->ir_set->irq_control); in xhci_save_registers()
690 struct xhci_interrupter *ir = xhci->interrupter; in xhci_restore_registers()
692 writel(xhci->s3.command, &xhci->op_regs->command); in xhci_restore_registers()
693 writel(xhci->s3.dev_nt, &xhci->op_regs->dev_notification); in xhci_restore_registers()
694 xhci_write_64(xhci, xhci->s3.dcbaa_ptr, &xhci->op_regs->dcbaa_ptr); in xhci_restore_registers()
695 writel(xhci->s3.config_reg, &xhci->op_regs->config_reg); in xhci_restore_registers()
696 writel(ir->s3_erst_size, &ir->ir_set->erst_size); in xhci_restore_registers()
697 xhci_write_64(xhci, ir->s3_erst_base, &ir->ir_set->erst_base); in xhci_restore_registers()
698 xhci_write_64(xhci, ir->s3_erst_dequeue, &ir->ir_set->erst_dequeue); in xhci_restore_registers()
699 writel(ir->s3_irq_pending, &ir->ir_set->irq_pending); in xhci_restore_registers()
700 writel(ir->s3_irq_control, &ir->ir_set->irq_control); in xhci_restore_registers()
708 val_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); in xhci_set_cmd_ring_deq()
710 (xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg, in xhci_set_cmd_ring_deq()
711 xhci->cmd_ring->dequeue) & in xhci_set_cmd_ring_deq()
713 xhci->cmd_ring->cycle_state; in xhci_set_cmd_ring_deq()
717 xhci_write_64(xhci, val_64, &xhci->op_regs->cmd_ring); in xhci_set_cmd_ring_deq()
724 * need to re-program it on resume. Unfortunately, the pointer must be 64-byte
727 * middle of the ring (TRBs are 16-byte aligned).
734 ring = xhci->cmd_ring; in xhci_clear_command_ring()
735 seg = ring->deq_seg; in xhci_clear_command_ring()
737 memset(seg->trbs, 0, in xhci_clear_command_ring()
738 sizeof(union xhci_trb) * (TRBS_PER_SEGMENT - 1)); in xhci_clear_command_ring()
739 seg->trbs[TRBS_PER_SEGMENT - 1].link.control &= in xhci_clear_command_ring()
741 seg = seg->next; in xhci_clear_command_ring()
742 } while (seg != ring->deq_seg); in xhci_clear_command_ring()
745 ring->deq_seg = ring->first_seg; in xhci_clear_command_ring()
746 ring->dequeue = ring->first_seg->trbs; in xhci_clear_command_ring()
747 ring->enq_seg = ring->deq_seg; in xhci_clear_command_ring()
748 ring->enqueue = ring->dequeue; in xhci_clear_command_ring()
750 ring->num_trbs_free = ring->num_segs * (TRBS_PER_SEGMENT - 1) - 1; in xhci_clear_command_ring()
755 ring->cycle_state = 1; in xhci_clear_command_ring()
759 * Yes, this will need to be re-written after resume, but we're paranoid in xhci_clear_command_ring()
784 spin_lock_irqsave(&xhci->lock, flags); in xhci_disable_hub_port_wake()
786 for (i = 0; i < rhub->num_ports; i++) { in xhci_disable_hub_port_wake()
787 portsc = readl(rhub->ports[i]->addr); in xhci_disable_hub_port_wake()
800 writel(t2, rhub->ports[i]->addr); in xhci_disable_hub_port_wake()
801 xhci_dbg(xhci, "config port %d-%d wake bits, portsc: 0x%x, write: 0x%x\n", in xhci_disable_hub_port_wake()
802 rhub->hcd->self.busnum, i + 1, portsc, t2); in xhci_disable_hub_port_wake()
805 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_disable_hub_port_wake()
815 status = readl(&xhci->op_regs->status); in xhci_pending_portevent()
824 port_index = xhci->usb2_rhub.num_ports; in xhci_pending_portevent()
825 ports = xhci->usb2_rhub.ports; in xhci_pending_portevent()
826 while (port_index--) { in xhci_pending_portevent()
827 portsc = readl(ports[port_index]->addr); in xhci_pending_portevent()
832 port_index = xhci->usb3_rhub.num_ports; in xhci_pending_portevent()
833 ports = xhci->usb3_rhub.ports; in xhci_pending_portevent()
834 while (port_index--) { in xhci_pending_portevent()
835 portsc = readl(ports[port_index]->addr); in xhci_pending_portevent()
844 * Stop HC (not bus-specific)
857 if (!hcd->state) in xhci_suspend()
860 if (hcd->state != HC_STATE_SUSPENDED || in xhci_suspend()
861 (xhci->shared_hcd && xhci->shared_hcd->state != HC_STATE_SUSPENDED)) in xhci_suspend()
862 return -EINVAL; in xhci_suspend()
865 xhci_disable_hub_port_wake(xhci, &xhci->usb3_rhub, do_wakeup); in xhci_suspend()
866 xhci_disable_hub_port_wake(xhci, &xhci->usb2_rhub, do_wakeup); in xhci_suspend()
875 __func__, hcd->self.busnum); in xhci_suspend()
876 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); in xhci_suspend()
877 del_timer_sync(&hcd->rh_timer); in xhci_suspend()
878 if (xhci->shared_hcd) { in xhci_suspend()
879 clear_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags); in xhci_suspend()
880 del_timer_sync(&xhci->shared_hcd->rh_timer); in xhci_suspend()
883 if (xhci->quirks & XHCI_SUSPEND_DELAY) in xhci_suspend()
886 spin_lock_irq(&xhci->lock); in xhci_suspend()
887 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); in xhci_suspend()
888 if (xhci->shared_hcd) in xhci_suspend()
889 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &xhci->shared_hcd->flags); in xhci_suspend()
894 command = readl(&xhci->op_regs->command); in xhci_suspend()
896 writel(command, &xhci->op_regs->command); in xhci_suspend()
899 delay *= (xhci->quirks & XHCI_SLOW_SUSPEND) ? 10 : 1; in xhci_suspend()
901 if (xhci_handshake(&xhci->op_regs->status, in xhci_suspend()
904 spin_unlock_irq(&xhci->lock); in xhci_suspend()
905 return -ETIMEDOUT; in xhci_suspend()
913 command = readl(&xhci->op_regs->command); in xhci_suspend()
915 writel(command, &xhci->op_regs->command); in xhci_suspend()
916 xhci->broken_suspend = 0; in xhci_suspend()
917 if (xhci_handshake(&xhci->op_regs->status, in xhci_suspend()
928 res = readl(&xhci->op_regs->status); in xhci_suspend()
929 if ((xhci->quirks & XHCI_SNPS_BROKEN_SUSPEND) && in xhci_suspend()
932 xhci->broken_suspend = 1; in xhci_suspend()
935 spin_unlock_irq(&xhci->lock); in xhci_suspend()
936 return -ETIMEDOUT; in xhci_suspend()
939 spin_unlock_irq(&xhci->lock); in xhci_suspend()
945 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && in xhci_suspend()
947 del_timer_sync(&xhci->comp_mode_recovery_timer); in xhci_suspend()
958 * start xHC (not bus-specific)
973 if (!hcd->state) in xhci_resume()
980 if (time_before(jiffies, xhci->usb2_rhub.bus_state.next_statechange) || in xhci_resume()
981 time_before(jiffies, xhci->usb3_rhub.bus_state.next_statechange)) in xhci_resume()
984 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); in xhci_resume()
985 if (xhci->shared_hcd) in xhci_resume()
986 set_bit(HCD_FLAG_HW_ACCESSIBLE, &xhci->shared_hcd->flags); in xhci_resume()
988 spin_lock_irq(&xhci->lock); in xhci_resume()
990 if (hibernated || xhci->quirks & XHCI_RESET_ON_RESUME || xhci->broken_suspend) in xhci_resume()
998 retval = xhci_handshake(&xhci->op_regs->status, in xhci_resume()
1003 spin_unlock_irq(&xhci->lock); in xhci_resume()
1012 command = readl(&xhci->op_regs->command); in xhci_resume()
1014 writel(command, &xhci->op_regs->command); in xhci_resume()
1020 if (xhci_handshake(&xhci->op_regs->status, in xhci_resume()
1023 spin_unlock_irq(&xhci->lock); in xhci_resume()
1024 return -ETIMEDOUT; in xhci_resume()
1028 temp = readl(&xhci->op_regs->status); in xhci_resume()
1030 /* re-initialize the HC on Restore Error, or Host Controller Error */ in xhci_resume()
1032 !(xhci->xhc_state & XHCI_STATE_REMOVING)) { in xhci_resume()
1034 if (!xhci->broken_suspend) in xhci_resume()
1039 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && in xhci_resume()
1041 del_timer_sync(&xhci->comp_mode_recovery_timer); in xhci_resume()
1047 usb_root_hub_lost_power(xhci->main_hcd->self.root_hub); in xhci_resume()
1048 if (xhci->shared_hcd) in xhci_resume()
1049 usb_root_hub_lost_power(xhci->shared_hcd->self.root_hub); in xhci_resume()
1055 spin_unlock_irq(&xhci->lock); in xhci_resume()
1060 temp = readl(&xhci->op_regs->status); in xhci_resume()
1061 writel((temp & ~0x1fff) | STS_EINT, &xhci->op_regs->status); in xhci_resume()
1062 xhci_disable_interrupter(xhci->interrupter); in xhci_resume()
1067 xhci_dbg(xhci, "xhci_stop completed - status = %x\n", in xhci_resume()
1068 readl(&xhci->op_regs->status)); in xhci_resume()
1082 if (!retval && xhci->shared_hcd) { in xhci_resume()
1084 retval = xhci_run(xhci->shared_hcd); in xhci_resume()
1087 hcd->state = HC_STATE_SUSPENDED; in xhci_resume()
1088 if (xhci->shared_hcd) in xhci_resume()
1089 xhci->shared_hcd->state = HC_STATE_SUSPENDED; in xhci_resume()
1094 command = readl(&xhci->op_regs->command); in xhci_resume()
1096 writel(command, &xhci->op_regs->command); in xhci_resume()
1097 xhci_handshake(&xhci->op_regs->status, STS_HALT, in xhci_resume()
1109 spin_unlock_irq(&xhci->lock); in xhci_resume()
1127 if (xhci->shared_hcd) in xhci_resume()
1128 usb_hcd_resume_root_hub(xhci->shared_hcd); in xhci_resume()
1134 * be re-initialized Always after a system resume. Ports are subject in xhci_resume()
1138 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && !comp_timer_running) in xhci_resume()
1141 if (xhci->quirks & XHCI_ASMEDIA_MODIFY_FLOWCONTROL) in xhci_resume()
1142 usb_asmedia_modifyflowcontrol(to_pci_dev(hcd->self.controller)); in xhci_resume()
1144 /* Re-enable port polling. */ in xhci_resume()
1146 __func__, hcd->self.busnum); in xhci_resume()
1147 if (xhci->shared_hcd) { in xhci_resume()
1148 set_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags); in xhci_resume()
1149 usb_hcd_poll_rh_status(xhci->shared_hcd); in xhci_resume()
1151 set_bit(HCD_FLAG_POLL_RH, &hcd->flags); in xhci_resume()
1159 /*-------------------------------------------------------------------------*/
1169 buf_len = urb->transfer_buffer_length; in xhci_map_temp_buffer()
1172 dev_to_node(hcd->self.sysdev)); in xhci_map_temp_buffer()
1175 sg_pcopy_to_buffer(urb->sg, urb->num_sgs, in xhci_map_temp_buffer()
1178 urb->transfer_buffer = temp; in xhci_map_temp_buffer()
1179 urb->transfer_dma = dma_map_single(hcd->self.sysdev, in xhci_map_temp_buffer()
1180 urb->transfer_buffer, in xhci_map_temp_buffer()
1181 urb->transfer_buffer_length, in xhci_map_temp_buffer()
1184 if (dma_mapping_error(hcd->self.sysdev, in xhci_map_temp_buffer()
1185 urb->transfer_dma)) { in xhci_map_temp_buffer()
1186 ret = -EAGAIN; in xhci_map_temp_buffer()
1189 urb->transfer_flags |= URB_DMA_MAP_SINGLE; in xhci_map_temp_buffer()
1206 tail_sg = urb->sg; in xhci_urb_temp_buffer_required()
1207 max_pkt = usb_endpoint_maxp(&urb->ep->desc); in xhci_urb_temp_buffer_required()
1209 if (!urb->num_sgs) in xhci_urb_temp_buffer_required()
1212 if (urb->dev->speed >= USB_SPEED_SUPER) in xhci_urb_temp_buffer_required()
1217 if (urb->transfer_buffer_length != 0 && in xhci_urb_temp_buffer_required()
1218 !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)) { in xhci_urb_temp_buffer_required()
1219 for_each_sg(urb->sg, sg, urb->num_sgs, i) { in xhci_urb_temp_buffer_required()
1220 len = len + sg->length; in xhci_urb_temp_buffer_required()
1221 if (i > trb_size - 2) { in xhci_urb_temp_buffer_required()
1222 len = len - tail_sg->length; in xhci_urb_temp_buffer_required()
1243 buf_len = urb->transfer_buffer_length; in xhci_unmap_temp_buf()
1246 (urb->transfer_flags & URB_DMA_MAP_SINGLE)) in xhci_unmap_temp_buf()
1247 dma_unmap_single(hcd->self.sysdev, in xhci_unmap_temp_buf()
1248 urb->transfer_dma, in xhci_unmap_temp_buf()
1249 urb->transfer_buffer_length, in xhci_unmap_temp_buf()
1253 len = sg_pcopy_from_buffer(urb->sg, urb->num_sgs, in xhci_unmap_temp_buf()
1254 urb->transfer_buffer, in xhci_unmap_temp_buf()
1260 urb->actual_length = len; in xhci_unmap_temp_buf()
1263 urb->transfer_flags &= ~URB_DMA_MAP_SINGLE; in xhci_unmap_temp_buf()
1264 kfree(urb->transfer_buffer); in xhci_unmap_temp_buf()
1265 urb->transfer_buffer = NULL; in xhci_unmap_temp_buf()
1284 if (xhci->quirks & XHCI_SG_TRB_CACHE_SIZE_QUIRK) { in xhci_map_urb_for_dma()
1298 if (urb->num_sgs && (urb->transfer_flags & URB_DMA_MAP_SINGLE)) in xhci_unmap_urb_for_dma()
1301 if ((xhci->quirks & XHCI_SG_TRB_CACHE_SIZE_QUIRK) && unmap_temp_buf) in xhci_unmap_urb_for_dma()
1308 * xhci_get_endpoint_index - Used for passing endpoint bitmasks between the core and
1312 * Index = (epnum * 2) + direction - 1,
1315 * index = (epnum * 2) + direction - 1 = (epnum * 2) + 1 - 1 = (epnum * 2)
1324 (usb_endpoint_dir_in(desc) ? 1 : 0) - 1; in xhci_get_endpoint_index()
1356 return fls(added_ctxs) - 1; in xhci_last_valid_endpoint()
1360 * returns 0 this is a root hub; returns -EINVAL for NULL pointers.
1370 return -EINVAL; in xhci_check_args()
1372 if (!udev->parent) { in xhci_check_args()
1379 if (!udev->slot_id || !xhci->devs[udev->slot_id]) { in xhci_check_args()
1382 return -EINVAL; in xhci_check_args()
1385 virt_dev = xhci->devs[udev->slot_id]; in xhci_check_args()
1386 if (virt_dev->udev != udev) { in xhci_check_args()
1389 return -EINVAL; in xhci_check_args()
1393 if (xhci->xhc_state & XHCI_STATE_HALTED) in xhci_check_args()
1394 return -ENODEV; in xhci_check_args()
1420 out_ctx = xhci->devs[slot_id]->out_ctx; in xhci_check_maxpacket()
1422 hw_max_packet_size = MAX_PACKET_DECODED(le32_to_cpu(ep_ctx->ep_info2)); in xhci_check_maxpacket()
1423 max_packet_size = usb_endpoint_maxp(&urb->dev->ep0.desc); in xhci_check_maxpacket()
1437 /* FIXME: This won't work if a non-default control endpoint in xhci_check_maxpacket()
1443 return -ENOMEM; in xhci_check_maxpacket()
1445 command->in_ctx = xhci->devs[slot_id]->in_ctx; in xhci_check_maxpacket()
1446 ctrl_ctx = xhci_get_input_control_ctx(command->in_ctx); in xhci_check_maxpacket()
1450 ret = -ENOMEM; in xhci_check_maxpacket()
1454 xhci_endpoint_copy(xhci, xhci->devs[slot_id]->in_ctx, in xhci_check_maxpacket()
1455 xhci->devs[slot_id]->out_ctx, ep_index); in xhci_check_maxpacket()
1457 ep_ctx = xhci_get_ep_ctx(xhci, command->in_ctx, ep_index); in xhci_check_maxpacket()
1458 ep_ctx->ep_info &= cpu_to_le32(~EP_STATE_MASK);/* must clear */ in xhci_check_maxpacket()
1459 ep_ctx->ep_info2 &= cpu_to_le32(~MAX_PACKET_MASK); in xhci_check_maxpacket()
1460 ep_ctx->ep_info2 |= cpu_to_le32(MAX_PACKET(max_packet_size)); in xhci_check_maxpacket()
1462 ctrl_ctx->add_flags = cpu_to_le32(EP0_FLAG); in xhci_check_maxpacket()
1463 ctrl_ctx->drop_flags = 0; in xhci_check_maxpacket()
1465 ret = xhci_configure_endpoint(xhci, urb->dev, command, in xhci_check_maxpacket()
1471 ctrl_ctx->add_flags = cpu_to_le32(SLOT_FLAG); in xhci_check_maxpacket()
1473 kfree(command->completion); in xhci_check_maxpacket()
1480 * non-error returns are a promise to giveback() the urb later
1494 return -EINVAL; in xhci_urb_enqueue()
1495 ret = xhci_check_args(hcd, urb->dev, urb->ep, in xhci_urb_enqueue()
1498 return ret ? ret : -EINVAL; in xhci_urb_enqueue()
1500 slot_id = urb->dev->slot_id; in xhci_urb_enqueue()
1501 ep_index = xhci_get_endpoint_index(&urb->ep->desc); in xhci_urb_enqueue()
1502 ep_state = &xhci->devs[slot_id]->eps[ep_index].ep_state; in xhci_urb_enqueue()
1505 return -ESHUTDOWN; in xhci_urb_enqueue()
1507 if (xhci->devs[slot_id]->flags & VDEV_PORT_ERROR) { in xhci_urb_enqueue()
1509 return -ENODEV; in xhci_urb_enqueue()
1512 if (usb_endpoint_xfer_isoc(&urb->ep->desc)) in xhci_urb_enqueue()
1513 num_tds = urb->number_of_packets; in xhci_urb_enqueue()
1514 else if (usb_endpoint_is_bulk_out(&urb->ep->desc) && in xhci_urb_enqueue()
1515 urb->transfer_buffer_length > 0 && in xhci_urb_enqueue()
1516 urb->transfer_flags & URB_ZERO_PACKET && in xhci_urb_enqueue()
1517 !(urb->transfer_buffer_length % usb_endpoint_maxp(&urb->ep->desc))) in xhci_urb_enqueue()
1524 return -ENOMEM; in xhci_urb_enqueue()
1526 urb_priv->num_tds = num_tds; in xhci_urb_enqueue()
1527 urb_priv->num_tds_done = 0; in xhci_urb_enqueue()
1528 urb->hcpriv = urb_priv; in xhci_urb_enqueue()
1532 if (usb_endpoint_xfer_control(&urb->ep->desc)) { in xhci_urb_enqueue()
1536 if (urb->dev->speed == USB_SPEED_FULL) { in xhci_urb_enqueue()
1541 urb->hcpriv = NULL; in xhci_urb_enqueue()
1547 spin_lock_irqsave(&xhci->lock, flags); in xhci_urb_enqueue()
1549 if (xhci->xhc_state & XHCI_STATE_DYING) { in xhci_urb_enqueue()
1550 xhci_dbg(xhci, "Ep 0x%x: URB %p submitted for non-responsive xHCI host.\n", in xhci_urb_enqueue()
1551 urb->ep->desc.bEndpointAddress, urb); in xhci_urb_enqueue()
1552 ret = -ESHUTDOWN; in xhci_urb_enqueue()
1558 ret = -EINVAL; in xhci_urb_enqueue()
1563 ret = -EINVAL; in xhci_urb_enqueue()
1567 switch (usb_endpoint_type(&urb->ep->desc)) { in xhci_urb_enqueue()
1589 urb->hcpriv = NULL; in xhci_urb_enqueue()
1591 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_urb_enqueue()
1611 * series of 1-TRB transfer no-op TDs. (No-ops shouldn't be chained.) The
1641 spin_lock_irqsave(&xhci->lock, flags); in xhci_urb_dequeue()
1651 vdev = xhci->devs[urb->dev->slot_id]; in xhci_urb_dequeue()
1652 urb_priv = urb->hcpriv; in xhci_urb_dequeue()
1656 ep_index = xhci_get_endpoint_index(&urb->ep->desc); in xhci_urb_dequeue()
1657 ep = &vdev->eps[ep_index]; in xhci_urb_dequeue()
1663 temp = readl(&xhci->op_regs->status); in xhci_urb_dequeue()
1664 if (temp == ~(u32)0 || xhci->xhc_state & XHCI_STATE_DYING) { in xhci_urb_dequeue()
1670 * check ring is not re-allocated since URB was enqueued. If it is, then in xhci_urb_dequeue()
1674 if (!td_on_ring(&urb_priv->td[0], ep_ring)) { in xhci_urb_dequeue()
1676 for (i = urb_priv->num_tds_done; i < urb_priv->num_tds; i++) { in xhci_urb_dequeue()
1677 td = &urb_priv->td[i]; in xhci_urb_dequeue()
1678 if (!list_empty(&td->cancelled_td_list)) in xhci_urb_dequeue()
1679 list_del_init(&td->cancelled_td_list); in xhci_urb_dequeue()
1684 if (xhci->xhc_state & XHCI_STATE_HALTED) { in xhci_urb_dequeue()
1687 for (i = urb_priv->num_tds_done; in xhci_urb_dequeue()
1688 i < urb_priv->num_tds; in xhci_urb_dequeue()
1690 td = &urb_priv->td[i]; in xhci_urb_dequeue()
1691 if (!list_empty(&td->td_list)) in xhci_urb_dequeue()
1692 list_del_init(&td->td_list); in xhci_urb_dequeue()
1693 if (!list_empty(&td->cancelled_td_list)) in xhci_urb_dequeue()
1694 list_del_init(&td->cancelled_td_list); in xhci_urb_dequeue()
1699 i = urb_priv->num_tds_done; in xhci_urb_dequeue()
1700 if (i < urb_priv->num_tds) in xhci_urb_dequeue()
1704 urb, urb->dev->devpath, in xhci_urb_dequeue()
1705 urb->ep->desc.bEndpointAddress, in xhci_urb_dequeue()
1707 urb_priv->td[i].start_seg, in xhci_urb_dequeue()
1708 urb_priv->td[i].first_trb)); in xhci_urb_dequeue()
1710 for (; i < urb_priv->num_tds; i++) { in xhci_urb_dequeue()
1711 td = &urb_priv->td[i]; in xhci_urb_dequeue()
1713 if (list_empty(&td->cancelled_td_list)) { in xhci_urb_dequeue()
1714 td->cancel_status = TD_DIRTY; in xhci_urb_dequeue()
1715 list_add_tail(&td->cancelled_td_list, in xhci_urb_dequeue()
1716 &ep->cancelled_td_list); in xhci_urb_dequeue()
1723 if (!(ep->ep_state & EP_STOP_CMD_PENDING)) { in xhci_urb_dequeue()
1726 ret = -ENOMEM; in xhci_urb_dequeue()
1729 ep->ep_state |= EP_STOP_CMD_PENDING; in xhci_urb_dequeue()
1730 xhci_queue_stop_endpoint(xhci, command, urb->dev->slot_id, in xhci_urb_dequeue()
1735 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_urb_dequeue()
1742 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_urb_dequeue()
1743 usb_hcd_giveback_urb(hcd, urb, -ESHUTDOWN); in xhci_urb_dequeue()
1758 * the xhci->devs[slot_id] structure.
1776 if (xhci->xhc_state & XHCI_STATE_DYING) in xhci_drop_endpoint()
1777 return -ENODEV; in xhci_drop_endpoint()
1780 drop_flag = xhci_get_endpoint_flag(&ep->desc); in xhci_drop_endpoint()
1782 xhci_dbg(xhci, "xHCI %s - can't drop slot or ep 0 %#x\n", in xhci_drop_endpoint()
1787 in_ctx = xhci->devs[udev->slot_id]->in_ctx; in xhci_drop_endpoint()
1788 out_ctx = xhci->devs[udev->slot_id]->out_ctx; in xhci_drop_endpoint()
1796 ep_index = xhci_get_endpoint_index(&ep->desc); in xhci_drop_endpoint()
1802 le32_to_cpu(ctrl_ctx->drop_flags) & in xhci_drop_endpoint()
1803 xhci_get_endpoint_flag(&ep->desc)) { in xhci_drop_endpoint()
1805 if (xhci->devs[udev->slot_id]->eps[ep_index].ring != NULL) in xhci_drop_endpoint()
1811 ctrl_ctx->drop_flags |= cpu_to_le32(drop_flag); in xhci_drop_endpoint()
1812 new_drop_flags = le32_to_cpu(ctrl_ctx->drop_flags); in xhci_drop_endpoint()
1814 ctrl_ctx->add_flags &= cpu_to_le32(~drop_flag); in xhci_drop_endpoint()
1815 new_add_flags = le32_to_cpu(ctrl_ctx->add_flags); in xhci_drop_endpoint()
1817 xhci_debugfs_remove_endpoint(xhci, xhci->devs[udev->slot_id], ep_index); in xhci_drop_endpoint()
1819 xhci_endpoint_zero(xhci, xhci->devs[udev->slot_id], ep); in xhci_drop_endpoint()
1822 (unsigned int) ep->desc.bEndpointAddress, in xhci_drop_endpoint()
1823 udev->slot_id, in xhci_drop_endpoint()
1841 * for mutual exclusion to protect the xhci->devs[slot_id] structure.
1859 ep->hcpriv = NULL; in xhci_add_endpoint()
1863 if (xhci->xhc_state & XHCI_STATE_DYING) in xhci_add_endpoint()
1864 return -ENODEV; in xhci_add_endpoint()
1866 added_ctxs = xhci_get_endpoint_flag(&ep->desc); in xhci_add_endpoint()
1872 xhci_dbg(xhci, "xHCI %s - can't add slot or ep 0 %#x\n", in xhci_add_endpoint()
1877 virt_dev = xhci->devs[udev->slot_id]; in xhci_add_endpoint()
1878 in_ctx = virt_dev->in_ctx; in xhci_add_endpoint()
1886 ep_index = xhci_get_endpoint_index(&ep->desc); in xhci_add_endpoint()
1890 if (virt_dev->eps[ep_index].ring && in xhci_add_endpoint()
1891 !(le32_to_cpu(ctrl_ctx->drop_flags) & added_ctxs)) { in xhci_add_endpoint()
1894 (unsigned int) ep->desc.bEndpointAddress); in xhci_add_endpoint()
1895 return -EINVAL; in xhci_add_endpoint()
1901 if (le32_to_cpu(ctrl_ctx->add_flags) & added_ctxs) { in xhci_add_endpoint()
1913 dev_dbg(&udev->dev, "%s - could not initialize ep %#x\n", in xhci_add_endpoint()
1914 __func__, ep->desc.bEndpointAddress); in xhci_add_endpoint()
1915 return -ENOMEM; in xhci_add_endpoint()
1918 ctrl_ctx->add_flags |= cpu_to_le32(added_ctxs); in xhci_add_endpoint()
1919 new_add_flags = le32_to_cpu(ctrl_ctx->add_flags); in xhci_add_endpoint()
1923 * this re-adds a new state for the endpoint from the new endpoint in xhci_add_endpoint()
1924 * descriptors. We must drop and re-add this endpoint, so we leave the in xhci_add_endpoint()
1927 new_drop_flags = le32_to_cpu(ctrl_ctx->drop_flags); in xhci_add_endpoint()
1930 ep->hcpriv = udev; in xhci_add_endpoint()
1932 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index); in xhci_add_endpoint()
1936 (unsigned int) ep->desc.bEndpointAddress, in xhci_add_endpoint()
1937 udev->slot_id, in xhci_add_endpoint()
1951 ctrl_ctx = xhci_get_input_control_ctx(virt_dev->in_ctx); in xhci_zero_in_ctx()
1963 ctrl_ctx->drop_flags = 0; in xhci_zero_in_ctx()
1964 ctrl_ctx->add_flags = 0; in xhci_zero_in_ctx()
1965 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); in xhci_zero_in_ctx()
1966 slot_ctx->dev_info &= cpu_to_le32(~LAST_CTX_MASK); in xhci_zero_in_ctx()
1968 slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(1)); in xhci_zero_in_ctx()
1970 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, i); in xhci_zero_in_ctx()
1971 ep_ctx->ep_info = 0; in xhci_zero_in_ctx()
1972 ep_ctx->ep_info2 = 0; in xhci_zero_in_ctx()
1973 ep_ctx->deq = 0; in xhci_zero_in_ctx()
1974 ep_ctx->tx_info = 0; in xhci_zero_in_ctx()
1987 ret = -ETIME; in xhci_configure_endpoint_result()
1990 dev_warn(&udev->dev, in xhci_configure_endpoint_result()
1992 ret = -ENOMEM; in xhci_configure_endpoint_result()
1997 dev_warn(&udev->dev, in xhci_configure_endpoint_result()
1999 ret = -ENOSPC; in xhci_configure_endpoint_result()
2004 dev_warn(&udev->dev, "ERROR: Endpoint drop flag = 0, " in xhci_configure_endpoint_result()
2007 ret = -EINVAL; in xhci_configure_endpoint_result()
2010 dev_warn(&udev->dev, in xhci_configure_endpoint_result()
2012 ret = -ENODEV; in xhci_configure_endpoint_result()
2022 ret = -EINVAL; in xhci_configure_endpoint_result()
2037 ret = -ETIME; in xhci_evaluate_context_result()
2040 dev_warn(&udev->dev, in xhci_evaluate_context_result()
2042 ret = -EINVAL; in xhci_evaluate_context_result()
2045 dev_warn(&udev->dev, in xhci_evaluate_context_result()
2047 ret = -EINVAL; in xhci_evaluate_context_result()
2050 dev_warn(&udev->dev, in xhci_evaluate_context_result()
2052 ret = -EINVAL; in xhci_evaluate_context_result()
2055 dev_warn(&udev->dev, in xhci_evaluate_context_result()
2057 ret = -ENODEV; in xhci_evaluate_context_result()
2061 dev_warn(&udev->dev, "WARN: Max Exit Latency too large\n"); in xhci_evaluate_context_result()
2062 ret = -EINVAL; in xhci_evaluate_context_result()
2072 ret = -EINVAL; in xhci_evaluate_context_result()
2088 valid_add_flags = le32_to_cpu(ctrl_ctx->add_flags) >> 2; in xhci_count_num_new_endpoints()
2089 valid_drop_flags = le32_to_cpu(ctrl_ctx->drop_flags) >> 2; in xhci_count_num_new_endpoints()
2095 return hweight32(valid_add_flags) - in xhci_count_num_new_endpoints()
2105 valid_add_flags = le32_to_cpu(ctrl_ctx->add_flags) >> 2; in xhci_count_num_dropped_endpoints()
2106 valid_drop_flags = le32_to_cpu(ctrl_ctx->drop_flags) >> 2; in xhci_count_num_dropped_endpoints()
2108 return hweight32(valid_drop_flags) - in xhci_count_num_dropped_endpoints()
2118 * - the first configure endpoint command drops more endpoints than it adds
2119 * - a second configure endpoint command that adds more endpoints is queued
2120 * - the first configure endpoint command fails, so the config is unchanged
2121 * - the second command may succeed, even though there isn't enough resources
2123 * Must be called with xhci->lock held.
2131 if (xhci->num_active_eps + added_eps > xhci->limit_active_eps) { in xhci_reserve_host_resources()
2135 xhci->num_active_eps, added_eps, in xhci_reserve_host_resources()
2136 xhci->limit_active_eps); in xhci_reserve_host_resources()
2137 return -ENOMEM; in xhci_reserve_host_resources()
2139 xhci->num_active_eps += added_eps; in xhci_reserve_host_resources()
2142 xhci->num_active_eps); in xhci_reserve_host_resources()
2150 * Must be called with xhci->lock held.
2158 xhci->num_active_eps -= num_failed_eps; in xhci_free_host_resources()
2162 xhci->num_active_eps); in xhci_free_host_resources()
2169 * Must be called with xhci->lock held.
2177 xhci->num_active_eps -= num_dropped_eps; in xhci_finish_resource_reservation()
2182 xhci->num_active_eps); in xhci_finish_resource_reservation()
2187 switch (udev->speed) { in xhci_get_block_size()
2206 if (interval_bw->overhead[LS_OVERHEAD_TYPE]) in xhci_get_largest_overhead()
2208 if (interval_bw->overhead[FS_OVERHEAD_TYPE]) in xhci_get_largest_overhead()
2214 * make sure (if we are activating a new TT) that the HS bus has enough
2215 * bandwidth for this new TT.
2224 /* Find the bandwidth table for the root port this TT is attached to. */ in xhci_check_tt_bw_table()
2225 bw_table = &xhci->rh_bw[virt_dev->real_port - 1].bw_table; in xhci_check_tt_bw_table()
2226 tt_info = virt_dev->tt_info; in xhci_check_tt_bw_table()
2227 /* If this TT already had active endpoints, the bandwidth for this TT in xhci_check_tt_bw_table()
2229 * making the TT enactive) will only decrease the bandwidth used. in xhci_check_tt_bw_table()
2233 if (old_active_eps == 0 && tt_info->active_eps != 0) { in xhci_check_tt_bw_table()
2234 if (bw_table->bw_used + TT_HS_OVERHEAD > HS_BW_LIMIT) in xhci_check_tt_bw_table()
2235 return -ENOMEM; in xhci_check_tt_bw_table()
2253 if (virt_dev->bw_table->ss_bw_in > (SS_BW_LIMIT_IN - bw_reserved)) in xhci_check_ss_bw()
2254 return -ENOMEM; in xhci_check_ss_bw()
2257 if (virt_dev->bw_table->ss_bw_out > (SS_BW_LIMIT_OUT - bw_reserved)) in xhci_check_ss_bw()
2258 return -ENOMEM; in xhci_check_ss_bw()
2264 * This algorithm is a very conservative estimate of the worst-case scheduling
2272 * over-estimate.
2319 if (virt_dev->udev->speed >= USB_SPEED_SUPER) in xhci_check_bw_table()
2322 if (virt_dev->udev->speed == USB_SPEED_HIGH) { in xhci_check_bw_table()
2331 bw_table = virt_dev->bw_table; in xhci_check_bw_table()
2335 block_size = xhci_get_block_size(virt_dev->udev); in xhci_check_bw_table()
2338 * that the HS bus has enough bandwidth if we are activing a new TT. in xhci_check_bw_table()
2340 if (virt_dev->tt_info) { in xhci_check_bw_table()
2343 virt_dev->real_port); in xhci_check_bw_table()
2346 "newly activated TT.\n"); in xhci_check_bw_table()
2347 return -ENOMEM; in xhci_check_bw_table()
2350 "Recalculating BW for TT slot %u port %u", in xhci_check_bw_table()
2351 virt_dev->tt_info->slot_id, in xhci_check_bw_table()
2352 virt_dev->tt_info->ttport); in xhci_check_bw_table()
2356 virt_dev->real_port); in xhci_check_bw_table()
2362 bw_used = DIV_ROUND_UP(bw_table->interval0_esit_payload, block_size) + in xhci_check_bw_table()
2363 bw_table->interval_bw[0].num_packets * in xhci_check_bw_table()
2364 xhci_get_largest_overhead(&bw_table->interval_bw[0]); in xhci_check_bw_table()
2377 bw_table->interval_bw[i].num_packets; in xhci_check_bw_table()
2382 if (list_empty(&bw_table->interval_bw[i].endpoints)) in xhci_check_bw_table()
2388 ep_entry = bw_table->interval_bw[i].endpoints.next; in xhci_check_bw_table()
2393 virt_ep->bw_info.max_packet_size, in xhci_check_bw_table()
2401 &bw_table->interval_bw[i]); in xhci_check_bw_table()
2440 return -ENOMEM; in xhci_check_bw_table()
2444 * Ok, we know we have some packets left over after even-handedly in xhci_check_bw_table()
2446 * fit into, so we over-schedule and say they will be scheduled every in xhci_check_bw_table()
2452 if (!virt_dev->tt_info && virt_dev->udev->speed == USB_SPEED_HIGH) { in xhci_check_bw_table()
2453 unsigned int port_index = virt_dev->real_port - 1; in xhci_check_bw_table()
2460 xhci->rh_bw[port_index].num_active_tts; in xhci_check_bw_table()
2467 (max_bandwidth - bw_used - bw_reserved) * 100 / in xhci_check_bw_table()
2474 return -ENOMEM; in xhci_check_bw_table()
2477 bw_table->bw_used = bw_used; in xhci_check_bw_table()
2495 unsigned int mps = DIV_ROUND_UP(ep_bw->max_packet_size, SS_BLOCK); in xhci_get_ss_bw_consumed()
2497 if (ep_bw->ep_interval == 0) in xhci_get_ss_bw_consumed()
2499 (ep_bw->mult * ep_bw->num_packets * in xhci_get_ss_bw_consumed()
2501 return DIV_ROUND_UP(ep_bw->mult * ep_bw->num_packets * in xhci_get_ss_bw_consumed()
2503 1 << ep_bw->ep_interval); in xhci_get_ss_bw_consumed()
2517 if (xhci_is_async_ep(ep_bw->type)) in xhci_drop_ep_from_interval_table()
2520 if (udev->speed >= USB_SPEED_SUPER) { in xhci_drop_ep_from_interval_table()
2521 if (xhci_is_sync_in_ep(ep_bw->type)) in xhci_drop_ep_from_interval_table()
2522 xhci->devs[udev->slot_id]->bw_table->ss_bw_in -= in xhci_drop_ep_from_interval_table()
2525 xhci->devs[udev->slot_id]->bw_table->ss_bw_out -= in xhci_drop_ep_from_interval_table()
2533 if (list_empty(&virt_ep->bw_endpoint_list)) in xhci_drop_ep_from_interval_table()
2538 if (udev->speed == USB_SPEED_HIGH) in xhci_drop_ep_from_interval_table()
2539 normalized_interval = ep_bw->ep_interval; in xhci_drop_ep_from_interval_table()
2541 normalized_interval = ep_bw->ep_interval - 3; in xhci_drop_ep_from_interval_table()
2544 bw_table->interval0_esit_payload -= ep_bw->max_esit_payload; in xhci_drop_ep_from_interval_table()
2545 interval_bw = &bw_table->interval_bw[normalized_interval]; in xhci_drop_ep_from_interval_table()
2546 interval_bw->num_packets -= ep_bw->num_packets; in xhci_drop_ep_from_interval_table()
2547 switch (udev->speed) { in xhci_drop_ep_from_interval_table()
2549 interval_bw->overhead[LS_OVERHEAD_TYPE] -= 1; in xhci_drop_ep_from_interval_table()
2552 interval_bw->overhead[FS_OVERHEAD_TYPE] -= 1; in xhci_drop_ep_from_interval_table()
2555 interval_bw->overhead[HS_OVERHEAD_TYPE] -= 1; in xhci_drop_ep_from_interval_table()
2564 tt_info->active_eps -= 1; in xhci_drop_ep_from_interval_table()
2565 list_del_init(&virt_ep->bw_endpoint_list); in xhci_drop_ep_from_interval_table()
2579 if (xhci_is_async_ep(ep_bw->type)) in xhci_add_ep_to_interval_table()
2582 if (udev->speed == USB_SPEED_SUPER) { in xhci_add_ep_to_interval_table()
2583 if (xhci_is_sync_in_ep(ep_bw->type)) in xhci_add_ep_to_interval_table()
2584 xhci->devs[udev->slot_id]->bw_table->ss_bw_in += in xhci_add_ep_to_interval_table()
2587 xhci->devs[udev->slot_id]->bw_table->ss_bw_out += in xhci_add_ep_to_interval_table()
2595 if (udev->speed == USB_SPEED_HIGH) in xhci_add_ep_to_interval_table()
2596 normalized_interval = ep_bw->ep_interval; in xhci_add_ep_to_interval_table()
2598 normalized_interval = ep_bw->ep_interval - 3; in xhci_add_ep_to_interval_table()
2601 bw_table->interval0_esit_payload += ep_bw->max_esit_payload; in xhci_add_ep_to_interval_table()
2602 interval_bw = &bw_table->interval_bw[normalized_interval]; in xhci_add_ep_to_interval_table()
2603 interval_bw->num_packets += ep_bw->num_packets; in xhci_add_ep_to_interval_table()
2604 switch (udev->speed) { in xhci_add_ep_to_interval_table()
2606 interval_bw->overhead[LS_OVERHEAD_TYPE] += 1; in xhci_add_ep_to_interval_table()
2609 interval_bw->overhead[FS_OVERHEAD_TYPE] += 1; in xhci_add_ep_to_interval_table()
2612 interval_bw->overhead[HS_OVERHEAD_TYPE] += 1; in xhci_add_ep_to_interval_table()
2622 tt_info->active_eps += 1; in xhci_add_ep_to_interval_table()
2624 list_for_each_entry(smaller_ep, &interval_bw->endpoints, in xhci_add_ep_to_interval_table()
2626 if (ep_bw->max_packet_size >= in xhci_add_ep_to_interval_table()
2627 smaller_ep->bw_info.max_packet_size) { in xhci_add_ep_to_interval_table()
2629 list_add_tail(&virt_ep->bw_endpoint_list, in xhci_add_ep_to_interval_table()
2630 &smaller_ep->bw_endpoint_list); in xhci_add_ep_to_interval_table()
2635 list_add_tail(&virt_ep->bw_endpoint_list, in xhci_add_ep_to_interval_table()
2636 &interval_bw->endpoints); in xhci_add_ep_to_interval_table()
2644 if (!virt_dev->tt_info) in xhci_update_tt_active_eps()
2647 rh_bw_info = &xhci->rh_bw[virt_dev->real_port - 1]; in xhci_update_tt_active_eps()
2649 virt_dev->tt_info->active_eps != 0) { in xhci_update_tt_active_eps()
2650 rh_bw_info->num_active_tts += 1; in xhci_update_tt_active_eps()
2651 rh_bw_info->bw_table.bw_used += TT_HS_OVERHEAD; in xhci_update_tt_active_eps()
2653 virt_dev->tt_info->active_eps == 0) { in xhci_update_tt_active_eps()
2654 rh_bw_info->num_active_tts -= 1; in xhci_update_tt_active_eps()
2655 rh_bw_info->bw_table.bw_used -= TT_HS_OVERHEAD; in xhci_update_tt_active_eps()
2668 if (virt_dev->tt_info) in xhci_reserve_bandwidth()
2669 old_active_eps = virt_dev->tt_info->active_eps; in xhci_reserve_bandwidth()
2675 return -ENOMEM; in xhci_reserve_bandwidth()
2683 memcpy(&ep_bw_info[i], &virt_dev->eps[i].bw_info, in xhci_reserve_bandwidth()
2690 &virt_dev->eps[i].bw_info, in xhci_reserve_bandwidth()
2691 virt_dev->bw_table, in xhci_reserve_bandwidth()
2692 virt_dev->udev, in xhci_reserve_bandwidth()
2693 &virt_dev->eps[i], in xhci_reserve_bandwidth()
2694 virt_dev->tt_info); in xhci_reserve_bandwidth()
2697 xhci_update_bw_info(xhci, virt_dev->in_ctx, ctrl_ctx, virt_dev); in xhci_reserve_bandwidth()
2702 &virt_dev->eps[i].bw_info, in xhci_reserve_bandwidth()
2703 virt_dev->bw_table, in xhci_reserve_bandwidth()
2704 virt_dev->udev, in xhci_reserve_bandwidth()
2705 &virt_dev->eps[i], in xhci_reserve_bandwidth()
2706 virt_dev->tt_info); in xhci_reserve_bandwidth()
2727 &virt_dev->eps[i].bw_info, in xhci_reserve_bandwidth()
2728 virt_dev->bw_table, in xhci_reserve_bandwidth()
2729 virt_dev->udev, in xhci_reserve_bandwidth()
2730 &virt_dev->eps[i], in xhci_reserve_bandwidth()
2731 virt_dev->tt_info); in xhci_reserve_bandwidth()
2734 memcpy(&virt_dev->eps[i].bw_info, &ep_bw_info[i], in xhci_reserve_bandwidth()
2739 &virt_dev->eps[i].bw_info, in xhci_reserve_bandwidth()
2740 virt_dev->bw_table, in xhci_reserve_bandwidth()
2741 virt_dev->udev, in xhci_reserve_bandwidth()
2742 &virt_dev->eps[i], in xhci_reserve_bandwidth()
2743 virt_dev->tt_info); in xhci_reserve_bandwidth()
2745 return -ENOMEM; in xhci_reserve_bandwidth()
2764 return -EINVAL; in xhci_configure_endpoint()
2766 spin_lock_irqsave(&xhci->lock, flags); in xhci_configure_endpoint()
2768 if (xhci->xhc_state & XHCI_STATE_DYING) { in xhci_configure_endpoint()
2769 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2770 return -ESHUTDOWN; in xhci_configure_endpoint()
2773 virt_dev = xhci->devs[udev->slot_id]; in xhci_configure_endpoint()
2775 ctrl_ctx = xhci_get_input_control_ctx(command->in_ctx); in xhci_configure_endpoint()
2777 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2780 return -ENOMEM; in xhci_configure_endpoint()
2783 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK) && in xhci_configure_endpoint()
2785 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2788 xhci->num_active_eps); in xhci_configure_endpoint()
2789 return -ENOMEM; in xhci_configure_endpoint()
2791 if ((xhci->quirks & XHCI_SW_BW_CHECKING) && in xhci_configure_endpoint()
2792 xhci_reserve_bandwidth(xhci, virt_dev, command->in_ctx)) { in xhci_configure_endpoint()
2793 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) in xhci_configure_endpoint()
2795 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2797 return -ENOMEM; in xhci_configure_endpoint()
2800 slot_ctx = xhci_get_slot_ctx(xhci, command->in_ctx); in xhci_configure_endpoint()
2807 command->in_ctx->dma, in xhci_configure_endpoint()
2808 udev->slot_id, must_succeed); in xhci_configure_endpoint()
2811 command->in_ctx->dma, in xhci_configure_endpoint()
2812 udev->slot_id, must_succeed); in xhci_configure_endpoint()
2814 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) in xhci_configure_endpoint()
2816 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2819 return -ENOMEM; in xhci_configure_endpoint()
2822 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2825 wait_for_completion(command->completion); in xhci_configure_endpoint()
2829 &command->status); in xhci_configure_endpoint()
2832 &command->status); in xhci_configure_endpoint()
2834 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) { in xhci_configure_endpoint()
2835 spin_lock_irqsave(&xhci->lock, flags); in xhci_configure_endpoint()
2843 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2851 struct xhci_virt_ep *ep = &vdev->eps[i]; in xhci_check_bw_drop_ep_streams()
2853 if (ep->ep_state & EP_HAS_STREAMS) { in xhci_check_bw_drop_ep_streams()
2856 xhci_free_stream_info(xhci, ep->stream_info); in xhci_check_bw_drop_ep_streams()
2857 ep->stream_info = NULL; in xhci_check_bw_drop_ep_streams()
2858 ep->ep_state &= ~EP_HAS_STREAMS; in xhci_check_bw_drop_ep_streams()
2869 * else should be touching the xhci->devs[slot_id] structure, so we
2870 * don't need to take the xhci->lock for manipulating that.
2886 if ((xhci->xhc_state & XHCI_STATE_DYING) || in xhci_check_bandwidth()
2887 (xhci->xhc_state & XHCI_STATE_REMOVING)) in xhci_check_bandwidth()
2888 return -ENODEV; in xhci_check_bandwidth()
2891 virt_dev = xhci->devs[udev->slot_id]; in xhci_check_bandwidth()
2895 return -ENOMEM; in xhci_check_bandwidth()
2897 command->in_ctx = virt_dev->in_ctx; in xhci_check_bandwidth()
2899 /* See section 4.6.6 - A0 = 1; A1 = D0 = D1 = 0 */ in xhci_check_bandwidth()
2900 ctrl_ctx = xhci_get_input_control_ctx(command->in_ctx); in xhci_check_bandwidth()
2904 ret = -ENOMEM; in xhci_check_bandwidth()
2907 ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG); in xhci_check_bandwidth()
2908 ctrl_ctx->add_flags &= cpu_to_le32(~EP0_FLAG); in xhci_check_bandwidth()
2909 ctrl_ctx->drop_flags &= cpu_to_le32(~(SLOT_FLAG | EP0_FLAG)); in xhci_check_bandwidth()
2912 if (ctrl_ctx->add_flags == cpu_to_le32(SLOT_FLAG) && in xhci_check_bandwidth()
2913 ctrl_ctx->drop_flags == 0) { in xhci_check_bandwidth()
2918 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); in xhci_check_bandwidth()
2919 for (i = 31; i >= 1; i--) { in xhci_check_bandwidth()
2922 if ((virt_dev->eps[i-1].ring && !(ctrl_ctx->drop_flags & le32)) in xhci_check_bandwidth()
2923 || (ctrl_ctx->add_flags & le32) || i == 1) { in xhci_check_bandwidth()
2924 slot_ctx->dev_info &= cpu_to_le32(~LAST_CTX_MASK); in xhci_check_bandwidth()
2925 slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(i)); in xhci_check_bandwidth()
2938 if ((le32_to_cpu(ctrl_ctx->drop_flags) & (1 << (i + 1))) && in xhci_check_bandwidth()
2939 !(le32_to_cpu(ctrl_ctx->add_flags) & (1 << (i + 1)))) { in xhci_check_bandwidth()
2950 if (!virt_dev->eps[i].new_ring) in xhci_check_bandwidth()
2955 if (virt_dev->eps[i].ring) { in xhci_check_bandwidth()
2959 virt_dev->eps[i].ring = virt_dev->eps[i].new_ring; in xhci_check_bandwidth()
2960 virt_dev->eps[i].new_ring = NULL; in xhci_check_bandwidth()
2964 kfree(command->completion); in xhci_check_bandwidth()
2983 virt_dev = xhci->devs[udev->slot_id]; in xhci_reset_bandwidth()
2986 if (virt_dev->eps[i].new_ring) { in xhci_reset_bandwidth()
2988 xhci_ring_free(xhci, virt_dev->eps[i].new_ring); in xhci_reset_bandwidth()
2989 virt_dev->eps[i].new_ring = NULL; in xhci_reset_bandwidth()
3002 ctrl_ctx->add_flags = cpu_to_le32(add_flags); in xhci_setup_input_ctx_for_config_ep()
3003 ctrl_ctx->drop_flags = cpu_to_le32(drop_flags); in xhci_setup_input_ctx_for_config_ep()
3005 ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG); in xhci_setup_input_ctx_for_config_ep()
3020 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_disable()
3022 udev = (struct usb_device *)host_ep->hcpriv; in xhci_endpoint_disable()
3023 if (!udev || !udev->slot_id) in xhci_endpoint_disable()
3026 vdev = xhci->devs[udev->slot_id]; in xhci_endpoint_disable()
3030 ep_index = xhci_get_endpoint_index(&host_ep->desc); in xhci_endpoint_disable()
3031 ep = &vdev->eps[ep_index]; in xhci_endpoint_disable()
3033 /* wait for hub_tt_work to finish clearing hub TT */ in xhci_endpoint_disable()
3034 if (ep->ep_state & EP_CLEARING_TT) { in xhci_endpoint_disable()
3035 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_disable()
3040 if (ep->ep_state) in xhci_endpoint_disable()
3042 ep->ep_state); in xhci_endpoint_disable()
3044 host_ep->hcpriv = NULL; in xhci_endpoint_disable()
3045 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_disable()
3075 if (!host_ep->hcpriv) in xhci_endpoint_reset()
3077 udev = (struct usb_device *) host_ep->hcpriv; in xhci_endpoint_reset()
3078 vdev = xhci->devs[udev->slot_id]; in xhci_endpoint_reset()
3081 * vdev may be lost due to xHC restore error and re-initialization in xhci_endpoint_reset()
3085 if (!udev->slot_id || !vdev) in xhci_endpoint_reset()
3087 ep_index = xhci_get_endpoint_index(&host_ep->desc); in xhci_endpoint_reset()
3088 ep = &vdev->eps[ep_index]; in xhci_endpoint_reset()
3091 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_reset()
3092 if (ep->ep_state & EP_HARD_CLEAR_TOGGLE) { in xhci_endpoint_reset()
3093 ep->ep_state &= ~EP_HARD_CLEAR_TOGGLE; in xhci_endpoint_reset()
3094 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3097 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3098 /* Only interrupt and bulk ep's use data toggle, USB2 spec 5.5.4-> */ in xhci_endpoint_reset()
3099 if (usb_endpoint_xfer_control(&host_ep->desc) || in xhci_endpoint_reset()
3100 usb_endpoint_xfer_isoc(&host_ep->desc)) in xhci_endpoint_reset()
3103 ep_flag = xhci_get_endpoint_flag(&host_ep->desc); in xhci_endpoint_reset()
3116 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_reset()
3119 ep->ep_state |= EP_SOFT_CLEAR_TOGGLE; in xhci_endpoint_reset()
3127 if (!list_empty(&ep->ring->td_list)) { in xhci_endpoint_reset()
3128 dev_err(&udev->dev, "EP not empty, refuse reset\n"); in xhci_endpoint_reset()
3129 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3134 err = xhci_queue_stop_endpoint(xhci, stop_cmd, udev->slot_id, in xhci_endpoint_reset()
3137 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3145 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3147 wait_for_completion(stop_cmd->completion); in xhci_endpoint_reset()
3149 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_reset()
3152 ctrl_ctx = xhci_get_input_control_ctx(cfg_cmd->in_ctx); in xhci_endpoint_reset()
3154 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3161 xhci_setup_input_ctx_for_config_ep(xhci, cfg_cmd->in_ctx, vdev->out_ctx, in xhci_endpoint_reset()
3163 xhci_endpoint_copy(xhci, cfg_cmd->in_ctx, vdev->out_ctx, ep_index); in xhci_endpoint_reset()
3165 err = xhci_queue_configure_endpoint(xhci, cfg_cmd, cfg_cmd->in_ctx->dma, in xhci_endpoint_reset()
3166 udev->slot_id, false); in xhci_endpoint_reset()
3168 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3176 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3178 wait_for_completion(cfg_cmd->completion); in xhci_endpoint_reset()
3183 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_reset()
3184 if (ep->ep_state & EP_SOFT_CLEAR_TOGGLE) in xhci_endpoint_reset()
3185 ep->ep_state &= ~EP_SOFT_CLEAR_TOGGLE; in xhci_endpoint_reset()
3186 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3198 return -EINVAL; in xhci_check_streams_endpoint()
3201 return ret ? ret : -EINVAL; in xhci_check_streams_endpoint()
3202 if (usb_ss_max_streams(&ep->ss_ep_comp) == 0) { in xhci_check_streams_endpoint()
3205 ep->desc.bEndpointAddress); in xhci_check_streams_endpoint()
3206 return -EINVAL; in xhci_check_streams_endpoint()
3209 ep_index = xhci_get_endpoint_index(&ep->desc); in xhci_check_streams_endpoint()
3210 ep_state = xhci->devs[slot_id]->eps[ep_index].ep_state; in xhci_check_streams_endpoint()
3215 ep->desc.bEndpointAddress); in xhci_check_streams_endpoint()
3218 return -EINVAL; in xhci_check_streams_endpoint()
3220 if (!list_empty(&xhci->devs[slot_id]->eps[ep_index].ring->td_list)) { in xhci_check_streams_endpoint()
3223 ep->desc.bEndpointAddress); in xhci_check_streams_endpoint()
3224 return -EINVAL; in xhci_check_streams_endpoint()
3242 max_streams = HCC_MAX_PSA(xhci->hcc_params); in xhci_calculate_streams_entries()
3267 eps[i], udev->slot_id); in xhci_calculate_streams_and_bitmask()
3271 max_streams = usb_ss_max_streams(&eps[i]->ss_ep_comp); in xhci_calculate_streams_and_bitmask()
3272 if (max_streams < (*num_streams - 1)) { in xhci_calculate_streams_and_bitmask()
3274 eps[i]->desc.bEndpointAddress, in xhci_calculate_streams_and_bitmask()
3279 endpoint_flag = xhci_get_endpoint_flag(&eps[i]->desc); in xhci_calculate_streams_and_bitmask()
3281 return -EINVAL; in xhci_calculate_streams_and_bitmask()
3297 slot_id = udev->slot_id; in xhci_calculate_no_streams_bitmask()
3298 if (!xhci->devs[slot_id]) in xhci_calculate_no_streams_bitmask()
3302 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_calculate_no_streams_bitmask()
3303 ep_state = xhci->devs[slot_id]->eps[ep_index].ep_state; in xhci_calculate_no_streams_bitmask()
3309 eps[i]->desc.bEndpointAddress); in xhci_calculate_no_streams_bitmask()
3318 eps[i]->desc.bEndpointAddress); in xhci_calculate_no_streams_bitmask()
3320 "with non-streams endpoint\n"); in xhci_calculate_no_streams_bitmask()
3323 changed_ep_bitmask |= xhci_get_endpoint_flag(&eps[i]->desc); in xhci_calculate_no_streams_bitmask()
3360 return -EINVAL; in xhci_alloc_streams()
3371 if ((xhci->quirks & XHCI_BROKEN_STREAMS) || in xhci_alloc_streams()
3372 HCC_MAX_PSA(xhci->hcc_params) < 4) { in xhci_alloc_streams()
3374 return -ENOSYS; in xhci_alloc_streams()
3379 return -ENOMEM; in xhci_alloc_streams()
3381 ctrl_ctx = xhci_get_input_control_ctx(config_cmd->in_ctx); in xhci_alloc_streams()
3386 return -ENOMEM; in xhci_alloc_streams()
3393 spin_lock_irqsave(&xhci->lock, flags); in xhci_alloc_streams()
3398 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_streams()
3405 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_streams()
3406 return -EINVAL; in xhci_alloc_streams()
3408 vdev = xhci->devs[udev->slot_id]; in xhci_alloc_streams()
3413 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_alloc_streams()
3414 vdev->eps[ep_index].ep_state |= EP_GETTING_STREAMS; in xhci_alloc_streams()
3416 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_streams()
3427 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_alloc_streams()
3428 max_packet = usb_endpoint_maxp(&eps[i]->desc); in xhci_alloc_streams()
3429 vdev->eps[ep_index].stream_info = xhci_alloc_stream_info(xhci, in xhci_alloc_streams()
3433 if (!vdev->eps[ep_index].stream_info) in xhci_alloc_streams()
3444 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_alloc_streams()
3445 ep_ctx = xhci_get_ep_ctx(xhci, config_cmd->in_ctx, ep_index); in xhci_alloc_streams()
3447 xhci_endpoint_copy(xhci, config_cmd->in_ctx, in xhci_alloc_streams()
3448 vdev->out_ctx, ep_index); in xhci_alloc_streams()
3450 vdev->eps[ep_index].stream_info); in xhci_alloc_streams()
3455 xhci_setup_input_ctx_for_config_ep(xhci, config_cmd->in_ctx, in xhci_alloc_streams()
3456 vdev->out_ctx, ctrl_ctx, in xhci_alloc_streams()
3470 spin_lock_irqsave(&xhci->lock, flags); in xhci_alloc_streams()
3472 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_alloc_streams()
3473 vdev->eps[ep_index].ep_state &= ~EP_GETTING_STREAMS; in xhci_alloc_streams()
3475 udev->slot_id, ep_index); in xhci_alloc_streams()
3476 vdev->eps[ep_index].ep_state |= EP_HAS_STREAMS; in xhci_alloc_streams()
3479 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_streams()
3482 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_alloc_streams()
3486 return num_streams - 1; in xhci_alloc_streams()
3491 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_alloc_streams()
3492 xhci_free_stream_info(xhci, vdev->eps[ep_index].stream_info); in xhci_alloc_streams()
3493 vdev->eps[ep_index].stream_info = NULL; in xhci_alloc_streams()
3497 vdev->eps[ep_index].ep_state &= ~EP_GETTING_STREAMS; in xhci_alloc_streams()
3498 vdev->eps[ep_index].ep_state &= ~EP_HAS_STREAMS; in xhci_alloc_streams()
3502 return -ENOMEM; in xhci_alloc_streams()
3525 vdev = xhci->devs[udev->slot_id]; in xhci_free_streams()
3528 spin_lock_irqsave(&xhci->lock, flags); in xhci_free_streams()
3532 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_streams()
3533 return -EINVAL; in xhci_free_streams()
3540 ep_index = xhci_get_endpoint_index(&eps[0]->desc); in xhci_free_streams()
3541 command = vdev->eps[ep_index].stream_info->free_streams_command; in xhci_free_streams()
3542 ctrl_ctx = xhci_get_input_control_ctx(command->in_ctx); in xhci_free_streams()
3544 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_streams()
3547 return -EINVAL; in xhci_free_streams()
3553 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_free_streams()
3554 ep_ctx = xhci_get_ep_ctx(xhci, command->in_ctx, ep_index); in xhci_free_streams()
3555 xhci->devs[udev->slot_id]->eps[ep_index].ep_state |= in xhci_free_streams()
3558 xhci_endpoint_copy(xhci, command->in_ctx, in xhci_free_streams()
3559 vdev->out_ctx, ep_index); in xhci_free_streams()
3561 &vdev->eps[ep_index]); in xhci_free_streams()
3563 xhci_setup_input_ctx_for_config_ep(xhci, command->in_ctx, in xhci_free_streams()
3564 vdev->out_ctx, ctrl_ctx, in xhci_free_streams()
3566 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_streams()
3580 spin_lock_irqsave(&xhci->lock, flags); in xhci_free_streams()
3582 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_free_streams()
3583 xhci_free_stream_info(xhci, vdev->eps[ep_index].stream_info); in xhci_free_streams()
3584 vdev->eps[ep_index].stream_info = NULL; in xhci_free_streams()
3588 vdev->eps[ep_index].ep_state &= ~EP_GETTING_NO_STREAMS; in xhci_free_streams()
3589 vdev->eps[ep_index].ep_state &= ~EP_HAS_STREAMS; in xhci_free_streams()
3591 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_streams()
3601 * Must be called with xhci->lock held.
3611 if (virt_dev->eps[i].ring) { in xhci_free_device_endpoint_resources()
3616 xhci->num_active_eps -= num_dropped_eps; in xhci_free_device_endpoint_resources()
3622 xhci->num_active_eps); in xhci_free_device_endpoint_resources()
3629 * xhci_address_device(), and then re-set up the configuration. If this is
3631 * settings will be re-installed through the normal bandwidth allocation
3640 * re-initialization during S3/S4. In this case, call xhci_alloc_dev() to
3641 * re-allocate the device.
3659 slot_id = udev->slot_id; in xhci_discover_or_reset_device()
3660 virt_dev = xhci->devs[slot_id]; in xhci_discover_or_reset_device()
3663 "not exist. Re-allocate the device\n", slot_id); in xhci_discover_or_reset_device()
3668 return -EINVAL; in xhci_discover_or_reset_device()
3671 if (virt_dev->tt_info) in xhci_discover_or_reset_device()
3672 old_active_eps = virt_dev->tt_info->active_eps; in xhci_discover_or_reset_device()
3674 if (virt_dev->udev != udev) { in xhci_discover_or_reset_device()
3677 * Re-allocate the device. in xhci_discover_or_reset_device()
3680 "not match the udev. Re-allocate the device\n", in xhci_discover_or_reset_device()
3686 return -EINVAL; in xhci_discover_or_reset_device()
3690 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); in xhci_discover_or_reset_device()
3691 if (GET_SLOT_STATE(le32_to_cpu(slot_ctx->dev_state)) == in xhci_discover_or_reset_device()
3707 return -ENOMEM; in xhci_discover_or_reset_device()
3711 spin_lock_irqsave(&xhci->lock, flags); in xhci_discover_or_reset_device()
3716 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_discover_or_reset_device()
3720 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_discover_or_reset_device()
3723 wait_for_completion(reset_device_cmd->completion); in xhci_discover_or_reset_device()
3729 ret = reset_device_cmd->status; in xhci_discover_or_reset_device()
3734 ret = -ETIME; in xhci_discover_or_reset_device()
3740 xhci_get_slot_state(xhci, virt_dev->out_ctx)); in xhci_discover_or_reset_device()
3753 ret = -EINVAL; in xhci_discover_or_reset_device()
3758 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) { in xhci_discover_or_reset_device()
3759 spin_lock_irqsave(&xhci->lock, flags); in xhci_discover_or_reset_device()
3762 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_discover_or_reset_device()
3767 struct xhci_virt_ep *ep = &virt_dev->eps[i]; in xhci_discover_or_reset_device()
3769 if (ep->ep_state & EP_HAS_STREAMS) { in xhci_discover_or_reset_device()
3772 xhci_free_stream_info(xhci, ep->stream_info); in xhci_discover_or_reset_device()
3773 ep->stream_info = NULL; in xhci_discover_or_reset_device()
3774 ep->ep_state &= ~EP_HAS_STREAMS; in xhci_discover_or_reset_device()
3777 if (ep->ring) { in xhci_discover_or_reset_device()
3781 if (!list_empty(&virt_dev->eps[i].bw_endpoint_list)) in xhci_discover_or_reset_device()
3783 &virt_dev->eps[i].bw_info, in xhci_discover_or_reset_device()
3784 virt_dev->bw_table, in xhci_discover_or_reset_device()
3786 &virt_dev->eps[i], in xhci_discover_or_reset_device()
3787 virt_dev->tt_info); in xhci_discover_or_reset_device()
3788 xhci_clear_endpoint_bw_info(&virt_dev->eps[i].bw_info); in xhci_discover_or_reset_device()
3792 virt_dev->flags = 0; in xhci_discover_or_reset_device()
3818 if (xhci->quirks & XHCI_RESET_ON_RESUME) in xhci_free_dev()
3819 pm_runtime_put_noidle(hcd->self.controller); in xhci_free_dev()
3825 if (ret <= 0 && ret != -ENODEV) in xhci_free_dev()
3828 virt_dev = xhci->devs[udev->slot_id]; in xhci_free_dev()
3829 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); in xhci_free_dev()
3834 virt_dev->eps[i].ep_state &= ~EP_STOP_CMD_PENDING; in xhci_free_dev()
3835 virt_dev->udev = NULL; in xhci_free_dev()
3836 xhci_disable_slot(xhci, udev->slot_id); in xhci_free_dev()
3838 spin_lock_irqsave(&xhci->lock, flags); in xhci_free_dev()
3839 xhci_free_virt_device(xhci, udev->slot_id); in xhci_free_dev()
3840 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_dev()
3853 return -ENOMEM; in xhci_disable_slot()
3857 spin_lock_irqsave(&xhci->lock, flags); in xhci_disable_slot()
3859 state = readl(&xhci->op_regs->status); in xhci_disable_slot()
3860 if (state == 0xffffffff || (xhci->xhc_state & XHCI_STATE_DYING) || in xhci_disable_slot()
3861 (xhci->xhc_state & XHCI_STATE_HALTED)) { in xhci_disable_slot()
3862 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_disable_slot()
3864 return -ENODEV; in xhci_disable_slot()
3870 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_disable_slot()
3875 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_disable_slot()
3877 wait_for_completion(command->completion); in xhci_disable_slot()
3879 if (command->status != COMP_SUCCESS) in xhci_disable_slot()
3881 slot_id, command->status); in xhci_disable_slot()
3892 * Must be called with xhci->lock held.
3896 if (xhci->num_active_eps + 1 > xhci->limit_active_eps) { in xhci_reserve_host_control_ep_resources()
3900 xhci->num_active_eps, xhci->limit_active_eps); in xhci_reserve_host_control_ep_resources()
3901 return -ENOMEM; in xhci_reserve_host_control_ep_resources()
3903 xhci->num_active_eps += 1; in xhci_reserve_host_control_ep_resources()
3906 xhci->num_active_eps); in xhci_reserve_host_control_ep_resources()
3928 spin_lock_irqsave(&xhci->lock, flags); in xhci_alloc_dev()
3931 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_dev()
3937 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_dev()
3939 wait_for_completion(command->completion); in xhci_alloc_dev()
3940 slot_id = command->slot_id; in xhci_alloc_dev()
3942 if (!slot_id || command->status != COMP_SUCCESS) { in xhci_alloc_dev()
3944 xhci_trb_comp_code_string(command->status)); in xhci_alloc_dev()
3947 readl(&xhci->cap_regs->hcs_params1))); in xhci_alloc_dev()
3954 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) { in xhci_alloc_dev()
3955 spin_lock_irqsave(&xhci->lock, flags); in xhci_alloc_dev()
3958 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_dev()
3961 xhci->num_active_eps); in xhci_alloc_dev()
3964 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_dev()
3974 vdev = xhci->devs[slot_id]; in xhci_alloc_dev()
3975 slot_ctx = xhci_get_slot_ctx(xhci, vdev->out_ctx); in xhci_alloc_dev()
3978 udev->slot_id = slot_id; in xhci_alloc_dev()
3986 if (xhci->quirks & XHCI_RESET_ON_RESUME) in xhci_alloc_dev()
3987 pm_runtime_get_noresume(hcd->self.controller); in xhci_alloc_dev()
3994 xhci_disable_slot(xhci, udev->slot_id); in xhci_alloc_dev()
3995 xhci_free_virt_device(xhci, udev->slot_id); in xhci_alloc_dev()
4017 mutex_lock(&xhci->mutex); in xhci_setup_device()
4019 if (xhci->xhc_state) { /* dying, removing or halted */ in xhci_setup_device()
4020 ret = -ESHUTDOWN; in xhci_setup_device()
4024 if (!udev->slot_id) { in xhci_setup_device()
4026 "Bad Slot ID %d", udev->slot_id); in xhci_setup_device()
4027 ret = -EINVAL; in xhci_setup_device()
4031 virt_dev = xhci->devs[udev->slot_id]; in xhci_setup_device()
4036 * a zero-dereference was observed once due to virt_dev = 0. in xhci_setup_device()
4040 udev->slot_id); in xhci_setup_device()
4041 ret = -EINVAL; in xhci_setup_device()
4044 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); in xhci_setup_device()
4048 if (GET_SLOT_STATE(le32_to_cpu(slot_ctx->dev_state)) == in xhci_setup_device()
4057 ret = -ENOMEM; in xhci_setup_device()
4061 command->in_ctx = virt_dev->in_ctx; in xhci_setup_device()
4063 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); in xhci_setup_device()
4064 ctrl_ctx = xhci_get_input_control_ctx(virt_dev->in_ctx); in xhci_setup_device()
4068 ret = -EINVAL; in xhci_setup_device()
4072 * If this is the first Set Address since device plug-in or in xhci_setup_device()
4076 if (!slot_ctx->dev_info) in xhci_setup_device()
4081 ctrl_ctx->add_flags = cpu_to_le32(SLOT_FLAG | EP0_FLAG); in xhci_setup_device()
4082 ctrl_ctx->drop_flags = 0; in xhci_setup_device()
4084 trace_xhci_address_ctx(xhci, virt_dev->in_ctx, in xhci_setup_device()
4085 le32_to_cpu(slot_ctx->dev_info) >> 27); in xhci_setup_device()
4088 spin_lock_irqsave(&xhci->lock, flags); in xhci_setup_device()
4090 ret = xhci_queue_address_device(xhci, command, virt_dev->in_ctx->dma, in xhci_setup_device()
4091 udev->slot_id, setup); in xhci_setup_device()
4093 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_setup_device()
4099 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_setup_device()
4102 wait_for_completion(command->completion); in xhci_setup_device()
4108 switch (command->status) { in xhci_setup_device()
4112 ret = -ETIME; in xhci_setup_device()
4117 act, udev->slot_id); in xhci_setup_device()
4118 ret = -EINVAL; in xhci_setup_device()
4121 dev_warn(&udev->dev, "Device not responding to setup %s.\n", act); in xhci_setup_device()
4123 mutex_unlock(&xhci->mutex); in xhci_setup_device()
4124 ret = xhci_disable_slot(xhci, udev->slot_id); in xhci_setup_device()
4125 xhci_free_virt_device(xhci, udev->slot_id); in xhci_setup_device()
4128 kfree(command->completion); in xhci_setup_device()
4130 return -EPROTO; in xhci_setup_device()
4132 dev_warn(&udev->dev, in xhci_setup_device()
4134 ret = -ENODEV; in xhci_setup_device()
4143 act, command->status); in xhci_setup_device()
4144 trace_xhci_address_ctx(xhci, virt_dev->out_ctx, 1); in xhci_setup_device()
4145 ret = -EINVAL; in xhci_setup_device()
4150 temp_64 = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr); in xhci_setup_device()
4155 udev->slot_id, in xhci_setup_device()
4156 &xhci->dcbaa->dev_context_ptrs[udev->slot_id], in xhci_setup_device()
4158 le64_to_cpu(xhci->dcbaa->dev_context_ptrs[udev->slot_id])); in xhci_setup_device()
4161 (unsigned long long)virt_dev->out_ctx->dma); in xhci_setup_device()
4162 trace_xhci_address_ctx(xhci, virt_dev->in_ctx, in xhci_setup_device()
4163 le32_to_cpu(slot_ctx->dev_info) >> 27); in xhci_setup_device()
4168 trace_xhci_address_ctx(xhci, virt_dev->out_ctx, in xhci_setup_device()
4169 le32_to_cpu(slot_ctx->dev_info) >> 27); in xhci_setup_device()
4171 ctrl_ctx->add_flags = 0; in xhci_setup_device()
4172 ctrl_ctx->drop_flags = 0; in xhci_setup_device()
4173 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); in xhci_setup_device()
4174 udev->devaddr = (u8)(le32_to_cpu(slot_ctx->dev_state) & DEV_ADDR_MASK); in xhci_setup_device()
4178 le32_to_cpu(slot_ctx->dev_state) & DEV_ADDR_MASK); in xhci_setup_device()
4180 mutex_unlock(&xhci->mutex); in xhci_setup_device()
4182 kfree(command->completion); in xhci_setup_device()
4209 return rhub->ports[port1 - 1]->hw_portnum + 1; in xhci_find_raw_port_number()
4228 return -ENOMEM; in xhci_change_max_exit_latency()
4230 spin_lock_irqsave(&xhci->lock, flags); in xhci_change_max_exit_latency()
4232 virt_dev = xhci->devs[udev->slot_id]; in xhci_change_max_exit_latency()
4236 * xHC was re-initialized. Exit latency will be set later after in xhci_change_max_exit_latency()
4237 * hub_port_finish_reset() is done and xhci->devs[] are re-allocated in xhci_change_max_exit_latency()
4240 if (!virt_dev || max_exit_latency == virt_dev->current_mel) { in xhci_change_max_exit_latency()
4241 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_change_max_exit_latency()
4247 ctrl_ctx = xhci_get_input_control_ctx(command->in_ctx); in xhci_change_max_exit_latency()
4249 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_change_max_exit_latency()
4253 return -ENOMEM; in xhci_change_max_exit_latency()
4256 xhci_slot_copy(xhci, command->in_ctx, virt_dev->out_ctx); in xhci_change_max_exit_latency()
4257 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_change_max_exit_latency()
4259 ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG); in xhci_change_max_exit_latency()
4260 slot_ctx = xhci_get_slot_ctx(xhci, command->in_ctx); in xhci_change_max_exit_latency()
4261 slot_ctx->dev_info2 &= cpu_to_le32(~((u32) MAX_EXIT)); in xhci_change_max_exit_latency()
4262 slot_ctx->dev_info2 |= cpu_to_le32(max_exit_latency); in xhci_change_max_exit_latency()
4263 slot_ctx->dev_state = 0; in xhci_change_max_exit_latency()
4273 spin_lock_irqsave(&xhci->lock, flags); in xhci_change_max_exit_latency()
4274 virt_dev->current_mel = max_exit_latency; in xhci_change_max_exit_latency()
4275 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_change_max_exit_latency()
4297 u2del = HCS_U2_LATENCY(xhci->hcs_params3); in xhci_calculate_hird_besl()
4298 field = le32_to_cpu(udev->bos->ext_cap->bmAttributes); in xhci_calculate_hird_besl()
4314 besl_host = (u2del - 51) / 75 + 1; in xhci_calculate_hird_besl()
4332 field = le32_to_cpu(udev->bos->ext_cap->bmAttributes); in xhci_calculate_usb2_hw_lpm_params()
4335 l1 = udev->l1_params.timeout / 256; in xhci_calculate_usb2_hw_lpm_params()
4358 if (xhci->quirks & XHCI_HW_LPM_DISABLE) in xhci_set_usb2_hardware_lpm()
4359 return -EPERM; in xhci_set_usb2_hardware_lpm()
4361 if (hcd->speed >= HCD_USB3 || !xhci->hw_lpm_support || in xhci_set_usb2_hardware_lpm()
4362 !udev->lpm_capable) in xhci_set_usb2_hardware_lpm()
4363 return -EPERM; in xhci_set_usb2_hardware_lpm()
4365 if (!udev->parent || udev->parent->parent || in xhci_set_usb2_hardware_lpm()
4366 udev->descriptor.bDeviceClass == USB_CLASS_HUB) in xhci_set_usb2_hardware_lpm()
4367 return -EPERM; in xhci_set_usb2_hardware_lpm()
4369 if (udev->usb2_hw_lpm_capable != 1) in xhci_set_usb2_hardware_lpm()
4370 return -EPERM; in xhci_set_usb2_hardware_lpm()
4372 spin_lock_irqsave(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4374 ports = xhci->usb2_rhub.ports; in xhci_set_usb2_hardware_lpm()
4375 port_num = udev->portnum - 1; in xhci_set_usb2_hardware_lpm()
4376 pm_addr = ports[port_num]->addr + PORTPMSC; in xhci_set_usb2_hardware_lpm()
4378 hlpm_addr = ports[port_num]->addr + PORTHLPMC; in xhci_set_usb2_hardware_lpm()
4385 if (udev->usb2_hw_lpm_besl_capable) { in xhci_set_usb2_hardware_lpm()
4390 field = le32_to_cpu(udev->bos->ext_cap->bmAttributes); in xhci_set_usb2_hardware_lpm()
4395 hird = udev->l1_params.besl; in xhci_set_usb2_hardware_lpm()
4398 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4404 spin_lock_irqsave(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4415 pm_val |= PORT_HIRD(hird) | PORT_RWE | PORT_L1DS(udev->slot_id); in xhci_set_usb2_hardware_lpm()
4427 if (udev->usb2_hw_lpm_besl_capable) { in xhci_set_usb2_hardware_lpm()
4428 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4430 readl_poll_timeout(ports[port_num]->addr, pm_val, in xhci_set_usb2_hardware_lpm()
4437 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4451 for (i = 0; i < xhci->num_ext_caps; i++) { in xhci_check_usb2_port_capability()
4452 if (xhci->ext_caps[i] & capability) { in xhci_check_usb2_port_capability()
4454 port_offset = XHCI_EXT_PORT_OFF(xhci->ext_caps[i]) - 1; in xhci_check_usb2_port_capability()
4455 port_count = XHCI_EXT_PORT_COUNT(xhci->ext_caps[i]); in xhci_check_usb2_port_capability()
4467 int portnum = udev->portnum - 1; in xhci_update_device()
4469 if (hcd->speed >= HCD_USB3 || !udev->lpm_capable) in xhci_update_device()
4472 /* we only support lpm for non-hub device connected to root hub yet */ in xhci_update_device()
4473 if (!udev->parent || udev->parent->parent || in xhci_update_device()
4474 udev->descriptor.bDeviceClass == USB_CLASS_HUB) in xhci_update_device()
4477 if (xhci->hw_lpm_support == 1 && in xhci_update_device()
4480 udev->usb2_hw_lpm_capable = 1; in xhci_update_device()
4481 udev->l1_params.timeout = XHCI_L1_TIMEOUT; in xhci_update_device()
4482 udev->l1_params.besl = XHCI_DEFAULT_BESL; in xhci_update_device()
4485 udev->usb2_hw_lpm_besl_capable = 1; in xhci_update_device()
4491 /*---------------------- USB 3.0 Link PM functions ------------------------*/
4493 /* Service interval in nanoseconds = 2^(bInterval - 1) * 125us * 1000ns / 1us */
4497 return (1ULL << (desc->bInterval - 1)) * 125 * 1000; in xhci_service_interval_to_ns()
4511 sel = DIV_ROUND_UP(udev->u1_params.sel, 1000); in xhci_get_timeout_no_hub_lpm()
4512 pel = DIV_ROUND_UP(udev->u1_params.pel, 1000); in xhci_get_timeout_no_hub_lpm()
4517 sel = DIV_ROUND_UP(udev->u2_params.sel, 1000); in xhci_get_timeout_no_hub_lpm()
4518 pel = DIV_ROUND_UP(udev->u2_params.pel, 1000); in xhci_get_timeout_no_hub_lpm()
4523 dev_warn(&udev->dev, "%s: Can't get timeout for non-U1 or U2 state.\n", in xhci_get_timeout_no_hub_lpm()
4532 dev_dbg(&udev->dev, "Device-initiated %s disabled " in xhci_get_timeout_no_hub_lpm()
4536 dev_dbg(&udev->dev, "Device-initiated %s disabled " in xhci_get_timeout_no_hub_lpm()
4543 * - For control endpoints, U1 system exit latency (SEL) * 3
4544 * - For bulk endpoints, U1 SEL * 5
4545 * - For interrupt endpoints:
4546 * - Notification EPs, U1 SEL * 3
4547 * - Periodic EPs, max(105% of bInterval, U1 SEL * 2)
4548 * - For isochronous endpoints, max(105% of bInterval, U1 SEL * 2)
4561 timeout_ns = udev->u1_params.sel * 3; in xhci_calculate_intel_u1_timeout()
4564 timeout_ns = udev->u1_params.sel * 5; in xhci_calculate_intel_u1_timeout()
4569 timeout_ns = udev->u1_params.sel * 3; in xhci_calculate_intel_u1_timeout()
4577 if (timeout_ns < udev->u1_params.sel * 2) in xhci_calculate_intel_u1_timeout()
4578 timeout_ns = udev->u1_params.sel * 2; in xhci_calculate_intel_u1_timeout()
4587 /* Returns the hub-encoded U1 timeout value. */
4596 if (xhci_service_interval_to_ns(desc) <= udev->u1_params.mel) { in xhci_calculate_u1_timeout()
4597 dev_dbg(&udev->dev, "Disable U1, ESIT shorter than exit latency\n"); in xhci_calculate_u1_timeout()
4602 if (xhci->quirks & (XHCI_INTEL_HOST | XHCI_ZHAOXIN_HOST)) in xhci_calculate_u1_timeout()
4605 timeout_ns = udev->u1_params.sel; in xhci_calculate_u1_timeout()
4616 * USB 3.0 hub, we have to disable hub-initiated U1. in xhci_calculate_u1_timeout()
4620 dev_dbg(&udev->dev, "Hub-initiated U1 disabled " in xhci_calculate_u1_timeout()
4626 * - 10 ms (to avoid the bandwidth impact on the scheduler)
4627 * - largest bInterval of any active periodic endpoint (to avoid going
4629 * - the U2 Exit Latency of the device
4644 u2_del_ns = le16_to_cpu(udev->bos->ss_cap->bU2DevExitLat) * 1000ULL; in xhci_calculate_intel_u2_timeout()
4651 /* Returns the hub-encoded U2 timeout value. */
4660 if (xhci_service_interval_to_ns(desc) <= udev->u2_params.mel) { in xhci_calculate_u2_timeout()
4661 dev_dbg(&udev->dev, "Disable U2, ESIT shorter than exit latency\n"); in xhci_calculate_u2_timeout()
4666 if (xhci->quirks & (XHCI_INTEL_HOST | XHCI_ZHAOXIN_HOST)) in xhci_calculate_u2_timeout()
4669 timeout_ns = udev->u2_params.sel; in xhci_calculate_u2_timeout()
4674 * USB 3.0 hub, we have to disable hub-initiated U2. in xhci_calculate_u2_timeout()
4678 dev_dbg(&udev->dev, "Hub-initiated U2 disabled " in xhci_calculate_u2_timeout()
4708 /* If we found we can't enable hub-initiated LPM, and in xhci_update_timeout_for_endpoint()
4710 * device-initiated LPM as well, then we will disable LPM in xhci_update_timeout_for_endpoint()
4715 return -E2BIG; in xhci_update_timeout_for_endpoint()
4730 for (j = 0; j < alt->desc.bNumEndpoints; j++) { in xhci_update_timeout_for_interface()
4732 &alt->endpoint[j].desc, state, timeout)) in xhci_update_timeout_for_interface()
4733 return -E2BIG; in xhci_update_timeout_for_interface()
4742 struct usb_device *parent = udev->parent; in xhci_check_tier_policy()
4746 parent = parent->parent; in xhci_check_tier_policy()
4750 if (xhci->quirks & XHCI_INTEL_HOST && tier > 3) in xhci_check_tier_policy()
4752 if (xhci->quirks & XHCI_ZHAOXIN_HOST && tier > 2) in xhci_check_tier_policy()
4757 dev_dbg(&udev->dev, "Tier policy prevents U1/U2 LPM states for devices at tier %d\n", in xhci_check_tier_policy()
4759 return -E2BIG; in xhci_check_tier_policy()
4763 * If the tier check or timeout setting functions return with a non-zero exit
4781 dev_warn(&udev->dev, "Can't enable unknown link state %i\n", in xhci_calculate_lpm_timeout()
4789 if (xhci_update_timeout_for_endpoint(xhci, udev, &udev->ep0.desc, in xhci_calculate_lpm_timeout()
4793 config = udev->actconfig; in xhci_calculate_lpm_timeout()
4797 for (i = 0; i < config->desc.bNumInterfaces; i++) { in xhci_calculate_lpm_timeout()
4799 struct usb_interface *intf = config->interface[i]; in xhci_calculate_lpm_timeout()
4804 /* Check if any currently bound drivers want hub-initiated LPM in xhci_calculate_lpm_timeout()
4807 if (intf->dev.driver) { in xhci_calculate_lpm_timeout()
4808 driver = to_usb_driver(intf->dev.driver); in xhci_calculate_lpm_timeout()
4809 if (driver && driver->disable_hub_initiated_lpm) { in xhci_calculate_lpm_timeout()
4810 dev_dbg(&udev->dev, "Hub-initiated %s disabled at request of driver %s\n", in xhci_calculate_lpm_timeout()
4811 state_name, driver->name); in xhci_calculate_lpm_timeout()
4820 if (!intf->cur_altsetting) in xhci_calculate_lpm_timeout()
4824 intf->cur_altsetting, in xhci_calculate_lpm_timeout()
4856 if ((udev->u1_params.timeout != USB3_LPM_DISABLED && !disabling_u1) || in calculate_max_exit_latency()
4858 u1_mel_us = DIV_ROUND_UP(udev->u1_params.mel, 1000); in calculate_max_exit_latency()
4859 if ((udev->u2_params.timeout != USB3_LPM_DISABLED && !disabling_u2) || in calculate_max_exit_latency()
4861 u2_mel_us = DIV_ROUND_UP(udev->u2_params.mel, 1000); in calculate_max_exit_latency()
4867 dev_warn(&udev->dev, "Link PM max exit latency of %lluus " in calculate_max_exit_latency()
4869 return -E2BIG; in calculate_max_exit_latency()
4874 /* Returns the USB3 hub-encoded value for the U1/U2 timeout. */
4885 /* The LPM timeout values are pretty host-controller specific, so don't in xhci_enable_usb3_lpm_timeout()
4886 * enable hub-initiated timeouts unless the vendor has provided in xhci_enable_usb3_lpm_timeout()
4889 if (!xhci || !(xhci->quirks & XHCI_LPM_SUPPORT) || in xhci_enable_usb3_lpm_timeout()
4890 !xhci->devs[udev->slot_id]) in xhci_enable_usb3_lpm_timeout()
4897 if (udev->parent && !udev->parent->parent) { in xhci_enable_usb3_lpm_timeout()
4898 port = xhci->usb3_rhub.ports[udev->portnum - 1]; in xhci_enable_usb3_lpm_timeout()
4899 if (port->lpm_incapable) in xhci_enable_usb3_lpm_timeout()
4924 if (!xhci || !(xhci->quirks & XHCI_LPM_SUPPORT) || in xhci_disable_usb3_lpm_timeout()
4925 !xhci->devs[udev->slot_id]) in xhci_disable_usb3_lpm_timeout()
4957 /*-------------------------------------------------------------------------*/
4963 struct usb_tt *tt, gfp_t mem_flags) in xhci_update_hub_device() argument
4975 if (!hdev->parent) in xhci_update_hub_device()
4978 vdev = xhci->devs[hdev->slot_id]; in xhci_update_hub_device()
4981 return -EINVAL; in xhci_update_hub_device()
4986 return -ENOMEM; in xhci_update_hub_device()
4988 ctrl_ctx = xhci_get_input_control_ctx(config_cmd->in_ctx); in xhci_update_hub_device()
4993 return -ENOMEM; in xhci_update_hub_device()
4996 spin_lock_irqsave(&xhci->lock, flags); in xhci_update_hub_device()
4997 if (hdev->speed == USB_SPEED_HIGH && in xhci_update_hub_device()
4998 xhci_alloc_tt_info(xhci, vdev, hdev, tt, GFP_ATOMIC)) { in xhci_update_hub_device()
4999 xhci_dbg(xhci, "Could not allocate xHCI TT structure.\n"); in xhci_update_hub_device()
5001 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_update_hub_device()
5002 return -ENOMEM; in xhci_update_hub_device()
5005 xhci_slot_copy(xhci, config_cmd->in_ctx, vdev->out_ctx); in xhci_update_hub_device()
5006 ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG); in xhci_update_hub_device()
5007 slot_ctx = xhci_get_slot_ctx(xhci, config_cmd->in_ctx); in xhci_update_hub_device()
5008 slot_ctx->dev_info |= cpu_to_le32(DEV_HUB); in xhci_update_hub_device()
5014 if (tt->multi) in xhci_update_hub_device()
5015 slot_ctx->dev_info |= cpu_to_le32(DEV_MTT); in xhci_update_hub_device()
5016 else if (hdev->speed == USB_SPEED_FULL) in xhci_update_hub_device()
5017 slot_ctx->dev_info &= cpu_to_le32(~DEV_MTT); in xhci_update_hub_device()
5019 if (xhci->hci_version > 0x95) { in xhci_update_hub_device()
5021 "TT think time and number of ports\n", in xhci_update_hub_device()
5022 (unsigned int) xhci->hci_version); in xhci_update_hub_device()
5023 slot_ctx->dev_info2 |= cpu_to_le32(XHCI_MAX_PORTS(hdev->maxchild)); in xhci_update_hub_device()
5024 /* Set TT think time - convert from ns to FS bit times. in xhci_update_hub_device()
5029 * High-spped hub. in xhci_update_hub_device()
5031 think_time = tt->think_time; in xhci_update_hub_device()
5033 think_time = (think_time / 666) - 1; in xhci_update_hub_device()
5034 if (xhci->hci_version < 0x100 || hdev->speed == USB_SPEED_HIGH) in xhci_update_hub_device()
5035 slot_ctx->tt_info |= in xhci_update_hub_device()
5039 "TT think time or number of ports\n", in xhci_update_hub_device()
5040 (unsigned int) xhci->hci_version); in xhci_update_hub_device()
5042 slot_ctx->dev_state = 0; in xhci_update_hub_device()
5043 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_update_hub_device()
5046 (xhci->hci_version > 0x95) ? in xhci_update_hub_device()
5052 if (xhci->hci_version > 0x95) in xhci_update_hub_device()
5068 return readl(&xhci->run_regs->microframe_index) >> 3; in xhci_get_frame()
5073 xhci->usb2_rhub.hcd = hcd; in xhci_hcd_init_usb2_data()
5074 hcd->speed = HCD_USB2; in xhci_hcd_init_usb2_data()
5075 hcd->self.root_hub->speed = USB_SPEED_HIGH; in xhci_hcd_init_usb2_data()
5077 * USB 2.0 roothub under xHCI has an integrated TT, in xhci_hcd_init_usb2_data()
5081 hcd->has_tt = 1; in xhci_hcd_init_usb2_data()
5091 * is a two digit BCD containig minor and sub-minor numbers. in xhci_hcd_init_usb3_data()
5097 if (xhci->usb3_rhub.min_rev == 0x1) in xhci_hcd_init_usb3_data()
5100 minor_rev = xhci->usb3_rhub.min_rev / 0x10; in xhci_hcd_init_usb3_data()
5104 hcd->speed = HCD_USB32; in xhci_hcd_init_usb3_data()
5105 hcd->self.root_hub->speed = USB_SPEED_SUPER_PLUS; in xhci_hcd_init_usb3_data()
5106 hcd->self.root_hub->rx_lanes = 2; in xhci_hcd_init_usb3_data()
5107 hcd->self.root_hub->tx_lanes = 2; in xhci_hcd_init_usb3_data()
5108 hcd->self.root_hub->ssp_rate = USB_SSP_GEN_2x2; in xhci_hcd_init_usb3_data()
5111 hcd->speed = HCD_USB31; in xhci_hcd_init_usb3_data()
5112 hcd->self.root_hub->speed = USB_SPEED_SUPER_PLUS; in xhci_hcd_init_usb3_data()
5113 hcd->self.root_hub->ssp_rate = USB_SSP_GEN_2x1; in xhci_hcd_init_usb3_data()
5119 xhci->usb3_rhub.hcd = hcd; in xhci_hcd_init_usb3_data()
5129 struct device *dev = hcd->self.sysdev; in xhci_gen_setup()
5132 /* Accept arbitrarily long scatter-gather lists */ in xhci_gen_setup()
5133 hcd->self.sg_tablesize = ~0; in xhci_gen_setup()
5136 hcd->self.no_sg_constraint = 1; in xhci_gen_setup()
5139 hcd->self.no_stop_on_short = 1; in xhci_gen_setup()
5148 mutex_init(&xhci->mutex); in xhci_gen_setup()
5149 xhci->main_hcd = hcd; in xhci_gen_setup()
5150 xhci->cap_regs = hcd->regs; in xhci_gen_setup()
5151 xhci->op_regs = hcd->regs + in xhci_gen_setup()
5152 HC_LENGTH(readl(&xhci->cap_regs->hc_capbase)); in xhci_gen_setup()
5153 xhci->run_regs = hcd->regs + in xhci_gen_setup()
5154 (readl(&xhci->cap_regs->run_regs_off) & RTSOFF_MASK); in xhci_gen_setup()
5155 /* Cache read-only capability registers */ in xhci_gen_setup()
5156 xhci->hcs_params1 = readl(&xhci->cap_regs->hcs_params1); in xhci_gen_setup()
5157 xhci->hcs_params2 = readl(&xhci->cap_regs->hcs_params2); in xhci_gen_setup()
5158 xhci->hcs_params3 = readl(&xhci->cap_regs->hcs_params3); in xhci_gen_setup()
5159 xhci->hci_version = HC_VERSION(readl(&xhci->cap_regs->hc_capbase)); in xhci_gen_setup()
5160 xhci->hcc_params = readl(&xhci->cap_regs->hcc_params); in xhci_gen_setup()
5161 if (xhci->hci_version > 0x100) in xhci_gen_setup()
5162 xhci->hcc_params2 = readl(&xhci->cap_regs->hcc_params2); in xhci_gen_setup()
5164 /* xhci-plat or xhci-pci might have set max_interrupters already */ in xhci_gen_setup()
5165 if ((!xhci->max_interrupters) || in xhci_gen_setup()
5166 xhci->max_interrupters > HCS_MAX_INTRS(xhci->hcs_params1)) in xhci_gen_setup()
5167 xhci->max_interrupters = HCS_MAX_INTRS(xhci->hcs_params1); in xhci_gen_setup()
5169 xhci->quirks |= quirks; in xhci_gen_setup()
5178 if (xhci->hci_version > 0x96) in xhci_gen_setup()
5179 xhci->quirks |= XHCI_SPURIOUS_SUCCESS; in xhci_gen_setup()
5196 * On some xHCI controllers (e.g. R-Car SoCs), the AC64 bit (bit 0) in xhci_gen_setup()
5197 * of HCCPARAMS1 is set to 1. However, the xHCs don't support 64-bit in xhci_gen_setup()
5199 * bit of xhci->hcc_params to call dma_set_coherent_mask(dev, in xhci_gen_setup()
5202 if (xhci->quirks & XHCI_NO_64BIT_SUPPORT) in xhci_gen_setup()
5203 xhci->hcc_params &= ~BIT(0); in xhci_gen_setup()
5205 /* Set dma_mask and coherent_dma_mask to 64-bits, in xhci_gen_setup()
5206 * if xHC supports 64-bit addressing */ in xhci_gen_setup()
5207 if (HCC_64BIT_ADDR(xhci->hcc_params) && in xhci_gen_setup()
5209 xhci_dbg(xhci, "Enabling 64-bit DMA addresses.\n"); in xhci_gen_setup()
5213 * This is to avoid error in cases where a 32-bit USB in xhci_gen_setup()
5214 * controller is used on a 64-bit capable system. in xhci_gen_setup()
5219 xhci_dbg(xhci, "Enabling 32-bit DMA addresses.\n"); in xhci_gen_setup()
5236 xhci->hcc_params, xhci->hci_version, xhci->quirks); in xhci_gen_setup()
5253 spin_lock_irqsave(&xhci->lock, flags); in xhci_clear_tt_buffer_complete()
5254 udev = (struct usb_device *)ep->hcpriv; in xhci_clear_tt_buffer_complete()
5255 slot_id = udev->slot_id; in xhci_clear_tt_buffer_complete()
5256 ep_index = xhci_get_endpoint_index(&ep->desc); in xhci_clear_tt_buffer_complete()
5258 xhci->devs[slot_id]->eps[ep_index].ep_state &= ~EP_CLEARING_TT; in xhci_clear_tt_buffer_complete()
5260 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_clear_tt_buffer_complete()
5264 .description = "xhci-hcd",
5339 drv->hcd_priv_size += over->extra_priv_size; in xhci_init_driver()
5340 if (over->reset) in xhci_init_driver()
5341 drv->reset = over->reset; in xhci_init_driver()
5342 if (over->start) in xhci_init_driver()
5343 drv->start = over->start; in xhci_init_driver()
5344 if (over->add_endpoint) in xhci_init_driver()
5345 drv->add_endpoint = over->add_endpoint; in xhci_init_driver()
5346 if (over->drop_endpoint) in xhci_init_driver()
5347 drv->drop_endpoint = over->drop_endpoint; in xhci_init_driver()
5348 if (over->check_bandwidth) in xhci_init_driver()
5349 drv->check_bandwidth = over->check_bandwidth; in xhci_init_driver()
5350 if (over->reset_bandwidth) in xhci_init_driver()
5351 drv->reset_bandwidth = over->reset_bandwidth; in xhci_init_driver()
5352 if (over->update_hub_device) in xhci_init_driver()
5353 drv->update_hub_device = over->update_hub_device; in xhci_init_driver()
5354 if (over->hub_control) in xhci_init_driver()
5355 drv->hub_control = over->hub_control; in xhci_init_driver()
5385 return -ENODEV; in xhci_hcd_init()