Lines Matching +full:additional +full:- +full:devs
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)
974 if (!hcd->state) in xhci_resume()
981 if (time_before(jiffies, xhci->usb2_rhub.bus_state.next_statechange) || in xhci_resume()
982 time_before(jiffies, xhci->usb3_rhub.bus_state.next_statechange)) in xhci_resume()
985 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); in xhci_resume()
986 if (xhci->shared_hcd) in xhci_resume()
987 set_bit(HCD_FLAG_HW_ACCESSIBLE, &xhci->shared_hcd->flags); in xhci_resume()
989 spin_lock_irq(&xhci->lock); in xhci_resume()
991 if (hibernated || xhci->quirks & XHCI_RESET_ON_RESUME || xhci->broken_suspend) in xhci_resume()
999 retval = xhci_handshake(&xhci->op_regs->status, in xhci_resume()
1004 spin_unlock_irq(&xhci->lock); in xhci_resume()
1013 command = readl(&xhci->op_regs->command); in xhci_resume()
1015 writel(command, &xhci->op_regs->command); in xhci_resume()
1021 if (xhci_handshake(&xhci->op_regs->status, in xhci_resume()
1024 spin_unlock_irq(&xhci->lock); in xhci_resume()
1025 return -ETIMEDOUT; in xhci_resume()
1029 temp = readl(&xhci->op_regs->status); in xhci_resume()
1031 /* re-initialize the HC on Restore Error, or Host Controller Error */ in xhci_resume()
1033 !(xhci->xhc_state & XHCI_STATE_REMOVING)) { in xhci_resume()
1035 if (!xhci->broken_suspend) in xhci_resume()
1040 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && in xhci_resume()
1042 del_timer_sync(&xhci->comp_mode_recovery_timer); in xhci_resume()
1048 usb_root_hub_lost_power(xhci->main_hcd->self.root_hub); in xhci_resume()
1049 if (xhci->shared_hcd) in xhci_resume()
1050 usb_root_hub_lost_power(xhci->shared_hcd->self.root_hub); in xhci_resume()
1056 spin_unlock_irq(&xhci->lock); in xhci_resume()
1061 temp = readl(&xhci->op_regs->status); in xhci_resume()
1062 writel((temp & ~0x1fff) | STS_EINT, &xhci->op_regs->status); in xhci_resume()
1063 xhci_disable_interrupter(xhci->interrupter); in xhci_resume()
1068 xhci_dbg(xhci, "xhci_stop completed - status = %x\n", in xhci_resume()
1069 readl(&xhci->op_regs->status)); in xhci_resume()
1083 if (!retval && xhci->shared_hcd) { in xhci_resume()
1085 retval = xhci_run(xhci->shared_hcd); in xhci_resume()
1088 hcd->state = HC_STATE_SUSPENDED; in xhci_resume()
1089 if (xhci->shared_hcd) in xhci_resume()
1090 xhci->shared_hcd->state = HC_STATE_SUSPENDED; in xhci_resume()
1095 command = readl(&xhci->op_regs->command); in xhci_resume()
1097 writel(command, &xhci->op_regs->command); in xhci_resume()
1098 xhci_handshake(&xhci->op_regs->status, STS_HALT, in xhci_resume()
1110 spin_unlock_irq(&xhci->lock); in xhci_resume()
1122 if (xhci->usb3_rhub.bus_state.suspended_ports || in xhci_resume()
1123 xhci->usb3_rhub.bus_state.bus_suspended) in xhci_resume()
1135 if (xhci->shared_hcd) in xhci_resume()
1136 usb_hcd_resume_root_hub(xhci->shared_hcd); in xhci_resume()
1142 * be re-initialized Always after a system resume. Ports are subject in xhci_resume()
1146 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && !comp_timer_running) in xhci_resume()
1149 if (xhci->quirks & XHCI_ASMEDIA_MODIFY_FLOWCONTROL) in xhci_resume()
1150 usb_asmedia_modifyflowcontrol(to_pci_dev(hcd->self.controller)); in xhci_resume()
1152 /* Re-enable port polling. */ in xhci_resume()
1154 __func__, hcd->self.busnum); in xhci_resume()
1155 if (xhci->shared_hcd) { in xhci_resume()
1156 set_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags); in xhci_resume()
1157 usb_hcd_poll_rh_status(xhci->shared_hcd); in xhci_resume()
1159 set_bit(HCD_FLAG_POLL_RH, &hcd->flags); in xhci_resume()
1167 /*-------------------------------------------------------------------------*/
1177 buf_len = urb->transfer_buffer_length; in xhci_map_temp_buffer()
1180 dev_to_node(hcd->self.sysdev)); in xhci_map_temp_buffer()
1183 sg_pcopy_to_buffer(urb->sg, urb->num_sgs, in xhci_map_temp_buffer()
1186 urb->transfer_buffer = temp; in xhci_map_temp_buffer()
1187 urb->transfer_dma = dma_map_single(hcd->self.sysdev, in xhci_map_temp_buffer()
1188 urb->transfer_buffer, in xhci_map_temp_buffer()
1189 urb->transfer_buffer_length, in xhci_map_temp_buffer()
1192 if (dma_mapping_error(hcd->self.sysdev, in xhci_map_temp_buffer()
1193 urb->transfer_dma)) { in xhci_map_temp_buffer()
1194 ret = -EAGAIN; in xhci_map_temp_buffer()
1197 urb->transfer_flags |= URB_DMA_MAP_SINGLE; in xhci_map_temp_buffer()
1214 tail_sg = urb->sg; in xhci_urb_temp_buffer_required()
1215 max_pkt = usb_endpoint_maxp(&urb->ep->desc); in xhci_urb_temp_buffer_required()
1217 if (!urb->num_sgs) in xhci_urb_temp_buffer_required()
1220 if (urb->dev->speed >= USB_SPEED_SUPER) in xhci_urb_temp_buffer_required()
1225 if (urb->transfer_buffer_length != 0 && in xhci_urb_temp_buffer_required()
1226 !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)) { in xhci_urb_temp_buffer_required()
1227 for_each_sg(urb->sg, sg, urb->num_sgs, i) { in xhci_urb_temp_buffer_required()
1228 len = len + sg->length; in xhci_urb_temp_buffer_required()
1229 if (i > trb_size - 2) { in xhci_urb_temp_buffer_required()
1230 len = len - tail_sg->length; in xhci_urb_temp_buffer_required()
1251 buf_len = urb->transfer_buffer_length; in xhci_unmap_temp_buf()
1254 (urb->transfer_flags & URB_DMA_MAP_SINGLE)) in xhci_unmap_temp_buf()
1255 dma_unmap_single(hcd->self.sysdev, in xhci_unmap_temp_buf()
1256 urb->transfer_dma, in xhci_unmap_temp_buf()
1257 urb->transfer_buffer_length, in xhci_unmap_temp_buf()
1261 len = sg_pcopy_from_buffer(urb->sg, urb->num_sgs, in xhci_unmap_temp_buf()
1262 urb->transfer_buffer, in xhci_unmap_temp_buf()
1268 urb->actual_length = len; in xhci_unmap_temp_buf()
1271 urb->transfer_flags &= ~URB_DMA_MAP_SINGLE; in xhci_unmap_temp_buf()
1272 kfree(urb->transfer_buffer); in xhci_unmap_temp_buf()
1273 urb->transfer_buffer = NULL; in xhci_unmap_temp_buf()
1292 if (xhci->quirks & XHCI_SG_TRB_CACHE_SIZE_QUIRK) { in xhci_map_urb_for_dma()
1306 if (urb->num_sgs && (urb->transfer_flags & URB_DMA_MAP_SINGLE)) in xhci_unmap_urb_for_dma()
1309 if ((xhci->quirks & XHCI_SG_TRB_CACHE_SIZE_QUIRK) && unmap_temp_buf) in xhci_unmap_urb_for_dma()
1316 * xhci_get_endpoint_index - Used for passing endpoint bitmasks between the core and
1320 * Index = (epnum * 2) + direction - 1,
1323 * index = (epnum * 2) + direction - 1 = (epnum * 2) + 1 - 1 = (epnum * 2)
1332 (usb_endpoint_dir_in(desc) ? 1 : 0) - 1; in xhci_get_endpoint_index()
1364 return fls(added_ctxs) - 1; in xhci_last_valid_endpoint()
1368 * returns 0 this is a root hub; returns -EINVAL for NULL pointers.
1378 return -EINVAL; in xhci_check_args()
1380 if (!udev->parent) { in xhci_check_args()
1387 if (!udev->slot_id || !xhci->devs[udev->slot_id]) { in xhci_check_args()
1390 return -EINVAL; in xhci_check_args()
1393 virt_dev = xhci->devs[udev->slot_id]; in xhci_check_args()
1394 if (virt_dev->udev != udev) { in xhci_check_args()
1397 return -EINVAL; in xhci_check_args()
1401 if (xhci->xhc_state & XHCI_STATE_HALTED) in xhci_check_args()
1402 return -ENODEV; in xhci_check_args()
1428 out_ctx = xhci->devs[slot_id]->out_ctx; in xhci_check_maxpacket()
1430 hw_max_packet_size = MAX_PACKET_DECODED(le32_to_cpu(ep_ctx->ep_info2)); in xhci_check_maxpacket()
1431 max_packet_size = usb_endpoint_maxp(&urb->dev->ep0.desc); in xhci_check_maxpacket()
1445 /* FIXME: This won't work if a non-default control endpoint in xhci_check_maxpacket()
1451 return -ENOMEM; in xhci_check_maxpacket()
1453 command->in_ctx = xhci->devs[slot_id]->in_ctx; in xhci_check_maxpacket()
1454 ctrl_ctx = xhci_get_input_control_ctx(command->in_ctx); in xhci_check_maxpacket()
1458 ret = -ENOMEM; in xhci_check_maxpacket()
1462 xhci_endpoint_copy(xhci, xhci->devs[slot_id]->in_ctx, in xhci_check_maxpacket()
1463 xhci->devs[slot_id]->out_ctx, ep_index); in xhci_check_maxpacket()
1465 ep_ctx = xhci_get_ep_ctx(xhci, command->in_ctx, ep_index); in xhci_check_maxpacket()
1466 ep_ctx->ep_info &= cpu_to_le32(~EP_STATE_MASK);/* must clear */ in xhci_check_maxpacket()
1467 ep_ctx->ep_info2 &= cpu_to_le32(~MAX_PACKET_MASK); in xhci_check_maxpacket()
1468 ep_ctx->ep_info2 |= cpu_to_le32(MAX_PACKET(max_packet_size)); in xhci_check_maxpacket()
1470 ctrl_ctx->add_flags = cpu_to_le32(EP0_FLAG); in xhci_check_maxpacket()
1471 ctrl_ctx->drop_flags = 0; in xhci_check_maxpacket()
1473 ret = xhci_configure_endpoint(xhci, urb->dev, command, in xhci_check_maxpacket()
1479 ctrl_ctx->add_flags = cpu_to_le32(SLOT_FLAG); in xhci_check_maxpacket()
1481 kfree(command->completion); in xhci_check_maxpacket()
1488 * non-error returns are a promise to giveback() the urb later
1502 return -EINVAL; in xhci_urb_enqueue()
1503 ret = xhci_check_args(hcd, urb->dev, urb->ep, in xhci_urb_enqueue()
1506 return ret ? ret : -EINVAL; in xhci_urb_enqueue()
1508 slot_id = urb->dev->slot_id; in xhci_urb_enqueue()
1509 ep_index = xhci_get_endpoint_index(&urb->ep->desc); in xhci_urb_enqueue()
1510 ep_state = &xhci->devs[slot_id]->eps[ep_index].ep_state; in xhci_urb_enqueue()
1513 return -ESHUTDOWN; in xhci_urb_enqueue()
1515 if (xhci->devs[slot_id]->flags & VDEV_PORT_ERROR) { in xhci_urb_enqueue()
1517 return -ENODEV; in xhci_urb_enqueue()
1520 if (usb_endpoint_xfer_isoc(&urb->ep->desc)) in xhci_urb_enqueue()
1521 num_tds = urb->number_of_packets; in xhci_urb_enqueue()
1522 else if (usb_endpoint_is_bulk_out(&urb->ep->desc) && in xhci_urb_enqueue()
1523 urb->transfer_buffer_length > 0 && in xhci_urb_enqueue()
1524 urb->transfer_flags & URB_ZERO_PACKET && in xhci_urb_enqueue()
1525 !(urb->transfer_buffer_length % usb_endpoint_maxp(&urb->ep->desc))) in xhci_urb_enqueue()
1532 return -ENOMEM; in xhci_urb_enqueue()
1534 urb_priv->num_tds = num_tds; in xhci_urb_enqueue()
1535 urb_priv->num_tds_done = 0; in xhci_urb_enqueue()
1536 urb->hcpriv = urb_priv; in xhci_urb_enqueue()
1540 if (usb_endpoint_xfer_control(&urb->ep->desc)) { in xhci_urb_enqueue()
1544 if (urb->dev->speed == USB_SPEED_FULL) { in xhci_urb_enqueue()
1549 urb->hcpriv = NULL; in xhci_urb_enqueue()
1555 spin_lock_irqsave(&xhci->lock, flags); in xhci_urb_enqueue()
1557 if (xhci->xhc_state & XHCI_STATE_DYING) { in xhci_urb_enqueue()
1558 xhci_dbg(xhci, "Ep 0x%x: URB %p submitted for non-responsive xHCI host.\n", in xhci_urb_enqueue()
1559 urb->ep->desc.bEndpointAddress, urb); in xhci_urb_enqueue()
1560 ret = -ESHUTDOWN; in xhci_urb_enqueue()
1566 ret = -EINVAL; in xhci_urb_enqueue()
1571 ret = -EINVAL; in xhci_urb_enqueue()
1575 switch (usb_endpoint_type(&urb->ep->desc)) { in xhci_urb_enqueue()
1597 urb->hcpriv = NULL; in xhci_urb_enqueue()
1599 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_urb_enqueue()
1619 * series of 1-TRB transfer no-op TDs. (No-ops shouldn't be chained.) The
1649 spin_lock_irqsave(&xhci->lock, flags); in xhci_urb_dequeue()
1659 vdev = xhci->devs[urb->dev->slot_id]; in xhci_urb_dequeue()
1660 urb_priv = urb->hcpriv; in xhci_urb_dequeue()
1664 ep_index = xhci_get_endpoint_index(&urb->ep->desc); in xhci_urb_dequeue()
1665 ep = &vdev->eps[ep_index]; in xhci_urb_dequeue()
1671 temp = readl(&xhci->op_regs->status); in xhci_urb_dequeue()
1672 if (temp == ~(u32)0 || xhci->xhc_state & XHCI_STATE_DYING) { in xhci_urb_dequeue()
1678 * check ring is not re-allocated since URB was enqueued. If it is, then in xhci_urb_dequeue()
1682 if (!td_on_ring(&urb_priv->td[0], ep_ring)) { in xhci_urb_dequeue()
1684 for (i = urb_priv->num_tds_done; i < urb_priv->num_tds; i++) { in xhci_urb_dequeue()
1685 td = &urb_priv->td[i]; in xhci_urb_dequeue()
1686 if (!list_empty(&td->cancelled_td_list)) in xhci_urb_dequeue()
1687 list_del_init(&td->cancelled_td_list); in xhci_urb_dequeue()
1692 if (xhci->xhc_state & XHCI_STATE_HALTED) { in xhci_urb_dequeue()
1695 for (i = urb_priv->num_tds_done; in xhci_urb_dequeue()
1696 i < urb_priv->num_tds; in xhci_urb_dequeue()
1698 td = &urb_priv->td[i]; in xhci_urb_dequeue()
1699 if (!list_empty(&td->td_list)) in xhci_urb_dequeue()
1700 list_del_init(&td->td_list); in xhci_urb_dequeue()
1701 if (!list_empty(&td->cancelled_td_list)) in xhci_urb_dequeue()
1702 list_del_init(&td->cancelled_td_list); in xhci_urb_dequeue()
1707 i = urb_priv->num_tds_done; in xhci_urb_dequeue()
1708 if (i < urb_priv->num_tds) in xhci_urb_dequeue()
1712 urb, urb->dev->devpath, in xhci_urb_dequeue()
1713 urb->ep->desc.bEndpointAddress, in xhci_urb_dequeue()
1715 urb_priv->td[i].start_seg, in xhci_urb_dequeue()
1716 urb_priv->td[i].first_trb)); in xhci_urb_dequeue()
1718 for (; i < urb_priv->num_tds; i++) { in xhci_urb_dequeue()
1719 td = &urb_priv->td[i]; in xhci_urb_dequeue()
1721 if (list_empty(&td->cancelled_td_list)) { in xhci_urb_dequeue()
1722 td->cancel_status = TD_DIRTY; in xhci_urb_dequeue()
1723 list_add_tail(&td->cancelled_td_list, in xhci_urb_dequeue()
1724 &ep->cancelled_td_list); in xhci_urb_dequeue()
1731 if (!(ep->ep_state & EP_STOP_CMD_PENDING)) { in xhci_urb_dequeue()
1734 ret = -ENOMEM; in xhci_urb_dequeue()
1737 ep->ep_state |= EP_STOP_CMD_PENDING; in xhci_urb_dequeue()
1738 xhci_queue_stop_endpoint(xhci, command, urb->dev->slot_id, in xhci_urb_dequeue()
1743 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_urb_dequeue()
1750 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_urb_dequeue()
1751 usb_hcd_giveback_urb(hcd, urb, -ESHUTDOWN); in xhci_urb_dequeue()
1766 * the xhci->devs[slot_id] structure.
1784 if (xhci->xhc_state & XHCI_STATE_DYING) in xhci_drop_endpoint()
1785 return -ENODEV; in xhci_drop_endpoint()
1788 drop_flag = xhci_get_endpoint_flag(&ep->desc); in xhci_drop_endpoint()
1790 xhci_dbg(xhci, "xHCI %s - can't drop slot or ep 0 %#x\n", in xhci_drop_endpoint()
1795 in_ctx = xhci->devs[udev->slot_id]->in_ctx; in xhci_drop_endpoint()
1796 out_ctx = xhci->devs[udev->slot_id]->out_ctx; in xhci_drop_endpoint()
1804 ep_index = xhci_get_endpoint_index(&ep->desc); in xhci_drop_endpoint()
1810 le32_to_cpu(ctrl_ctx->drop_flags) & in xhci_drop_endpoint()
1811 xhci_get_endpoint_flag(&ep->desc)) { in xhci_drop_endpoint()
1813 if (xhci->devs[udev->slot_id]->eps[ep_index].ring != NULL) in xhci_drop_endpoint()
1819 ctrl_ctx->drop_flags |= cpu_to_le32(drop_flag); in xhci_drop_endpoint()
1820 new_drop_flags = le32_to_cpu(ctrl_ctx->drop_flags); in xhci_drop_endpoint()
1822 ctrl_ctx->add_flags &= cpu_to_le32(~drop_flag); in xhci_drop_endpoint()
1823 new_add_flags = le32_to_cpu(ctrl_ctx->add_flags); in xhci_drop_endpoint()
1825 xhci_debugfs_remove_endpoint(xhci, xhci->devs[udev->slot_id], ep_index); in xhci_drop_endpoint()
1827 xhci_endpoint_zero(xhci, xhci->devs[udev->slot_id], ep); in xhci_drop_endpoint()
1830 (unsigned int) ep->desc.bEndpointAddress, in xhci_drop_endpoint()
1831 udev->slot_id, in xhci_drop_endpoint()
1849 * for mutual exclusion to protect the xhci->devs[slot_id] structure.
1867 ep->hcpriv = NULL; in xhci_add_endpoint()
1871 if (xhci->xhc_state & XHCI_STATE_DYING) in xhci_add_endpoint()
1872 return -ENODEV; in xhci_add_endpoint()
1874 added_ctxs = xhci_get_endpoint_flag(&ep->desc); in xhci_add_endpoint()
1880 xhci_dbg(xhci, "xHCI %s - can't add slot or ep 0 %#x\n", in xhci_add_endpoint()
1885 virt_dev = xhci->devs[udev->slot_id]; in xhci_add_endpoint()
1886 in_ctx = virt_dev->in_ctx; in xhci_add_endpoint()
1894 ep_index = xhci_get_endpoint_index(&ep->desc); in xhci_add_endpoint()
1898 if (virt_dev->eps[ep_index].ring && in xhci_add_endpoint()
1899 !(le32_to_cpu(ctrl_ctx->drop_flags) & added_ctxs)) { in xhci_add_endpoint()
1902 (unsigned int) ep->desc.bEndpointAddress); in xhci_add_endpoint()
1903 return -EINVAL; in xhci_add_endpoint()
1909 if (le32_to_cpu(ctrl_ctx->add_flags) & added_ctxs) { in xhci_add_endpoint()
1921 dev_dbg(&udev->dev, "%s - could not initialize ep %#x\n", in xhci_add_endpoint()
1922 __func__, ep->desc.bEndpointAddress); in xhci_add_endpoint()
1923 return -ENOMEM; in xhci_add_endpoint()
1926 ctrl_ctx->add_flags |= cpu_to_le32(added_ctxs); in xhci_add_endpoint()
1927 new_add_flags = le32_to_cpu(ctrl_ctx->add_flags); in xhci_add_endpoint()
1931 * this re-adds a new state for the endpoint from the new endpoint in xhci_add_endpoint()
1932 * descriptors. We must drop and re-add this endpoint, so we leave the in xhci_add_endpoint()
1935 new_drop_flags = le32_to_cpu(ctrl_ctx->drop_flags); in xhci_add_endpoint()
1938 ep->hcpriv = udev; in xhci_add_endpoint()
1940 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index); in xhci_add_endpoint()
1944 (unsigned int) ep->desc.bEndpointAddress, in xhci_add_endpoint()
1945 udev->slot_id, in xhci_add_endpoint()
1959 ctrl_ctx = xhci_get_input_control_ctx(virt_dev->in_ctx); in xhci_zero_in_ctx()
1971 ctrl_ctx->drop_flags = 0; in xhci_zero_in_ctx()
1972 ctrl_ctx->add_flags = 0; in xhci_zero_in_ctx()
1973 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); in xhci_zero_in_ctx()
1974 slot_ctx->dev_info &= cpu_to_le32(~LAST_CTX_MASK); in xhci_zero_in_ctx()
1976 slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(1)); in xhci_zero_in_ctx()
1978 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, i); in xhci_zero_in_ctx()
1979 ep_ctx->ep_info = 0; in xhci_zero_in_ctx()
1980 ep_ctx->ep_info2 = 0; in xhci_zero_in_ctx()
1981 ep_ctx->deq = 0; in xhci_zero_in_ctx()
1982 ep_ctx->tx_info = 0; in xhci_zero_in_ctx()
1995 ret = -ETIME; in xhci_configure_endpoint_result()
1998 dev_warn(&udev->dev, in xhci_configure_endpoint_result()
2000 ret = -ENOMEM; in xhci_configure_endpoint_result()
2005 dev_warn(&udev->dev, in xhci_configure_endpoint_result()
2007 ret = -ENOSPC; in xhci_configure_endpoint_result()
2012 dev_warn(&udev->dev, "ERROR: Endpoint drop flag = 0, " in xhci_configure_endpoint_result()
2015 ret = -EINVAL; in xhci_configure_endpoint_result()
2018 dev_warn(&udev->dev, in xhci_configure_endpoint_result()
2020 ret = -ENODEV; in xhci_configure_endpoint_result()
2030 ret = -EINVAL; in xhci_configure_endpoint_result()
2045 ret = -ETIME; in xhci_evaluate_context_result()
2048 dev_warn(&udev->dev, in xhci_evaluate_context_result()
2050 ret = -EINVAL; in xhci_evaluate_context_result()
2053 dev_warn(&udev->dev, in xhci_evaluate_context_result()
2055 ret = -EINVAL; in xhci_evaluate_context_result()
2058 dev_warn(&udev->dev, in xhci_evaluate_context_result()
2060 ret = -EINVAL; in xhci_evaluate_context_result()
2063 dev_warn(&udev->dev, in xhci_evaluate_context_result()
2065 ret = -ENODEV; in xhci_evaluate_context_result()
2069 dev_warn(&udev->dev, "WARN: Max Exit Latency too large\n"); in xhci_evaluate_context_result()
2070 ret = -EINVAL; in xhci_evaluate_context_result()
2080 ret = -EINVAL; in xhci_evaluate_context_result()
2096 valid_add_flags = le32_to_cpu(ctrl_ctx->add_flags) >> 2; in xhci_count_num_new_endpoints()
2097 valid_drop_flags = le32_to_cpu(ctrl_ctx->drop_flags) >> 2; in xhci_count_num_new_endpoints()
2103 return hweight32(valid_add_flags) - in xhci_count_num_new_endpoints()
2113 valid_add_flags = le32_to_cpu(ctrl_ctx->add_flags) >> 2; in xhci_count_num_dropped_endpoints()
2114 valid_drop_flags = le32_to_cpu(ctrl_ctx->drop_flags) >> 2; in xhci_count_num_dropped_endpoints()
2116 return hweight32(valid_drop_flags) - in xhci_count_num_dropped_endpoints()
2126 * - the first configure endpoint command drops more endpoints than it adds
2127 * - a second configure endpoint command that adds more endpoints is queued
2128 * - the first configure endpoint command fails, so the config is unchanged
2129 * - the second command may succeed, even though there isn't enough resources
2131 * Must be called with xhci->lock held.
2139 if (xhci->num_active_eps + added_eps > xhci->limit_active_eps) { in xhci_reserve_host_resources()
2143 xhci->num_active_eps, added_eps, in xhci_reserve_host_resources()
2144 xhci->limit_active_eps); in xhci_reserve_host_resources()
2145 return -ENOMEM; in xhci_reserve_host_resources()
2147 xhci->num_active_eps += added_eps; in xhci_reserve_host_resources()
2150 xhci->num_active_eps); in xhci_reserve_host_resources()
2158 * Must be called with xhci->lock held.
2166 xhci->num_active_eps -= num_failed_eps; in xhci_free_host_resources()
2170 xhci->num_active_eps); in xhci_free_host_resources()
2177 * Must be called with xhci->lock held.
2185 xhci->num_active_eps -= num_dropped_eps; in xhci_finish_resource_reservation()
2190 xhci->num_active_eps); in xhci_finish_resource_reservation()
2195 switch (udev->speed) { in xhci_get_block_size()
2214 if (interval_bw->overhead[LS_OVERHEAD_TYPE]) in xhci_get_largest_overhead()
2216 if (interval_bw->overhead[FS_OVERHEAD_TYPE]) in xhci_get_largest_overhead()
2233 bw_table = &xhci->rh_bw[virt_dev->real_port - 1].bw_table; in xhci_check_tt_bw_table()
2234 tt_info = virt_dev->tt_info; in xhci_check_tt_bw_table()
2241 if (old_active_eps == 0 && tt_info->active_eps != 0) { in xhci_check_tt_bw_table()
2242 if (bw_table->bw_used + TT_HS_OVERHEAD > HS_BW_LIMIT) in xhci_check_tt_bw_table()
2243 return -ENOMEM; in xhci_check_tt_bw_table()
2261 if (virt_dev->bw_table->ss_bw_in > (SS_BW_LIMIT_IN - bw_reserved)) in xhci_check_ss_bw()
2262 return -ENOMEM; in xhci_check_ss_bw()
2265 if (virt_dev->bw_table->ss_bw_out > (SS_BW_LIMIT_OUT - bw_reserved)) in xhci_check_ss_bw()
2266 return -ENOMEM; in xhci_check_ss_bw()
2272 * This algorithm is a very conservative estimate of the worst-case scheduling
2280 * over-estimate.
2327 if (virt_dev->udev->speed >= USB_SPEED_SUPER) in xhci_check_bw_table()
2330 if (virt_dev->udev->speed == USB_SPEED_HIGH) { in xhci_check_bw_table()
2339 bw_table = virt_dev->bw_table; in xhci_check_bw_table()
2343 block_size = xhci_get_block_size(virt_dev->udev); in xhci_check_bw_table()
2348 if (virt_dev->tt_info) { in xhci_check_bw_table()
2351 virt_dev->real_port); in xhci_check_bw_table()
2355 return -ENOMEM; in xhci_check_bw_table()
2359 virt_dev->tt_info->slot_id, in xhci_check_bw_table()
2360 virt_dev->tt_info->ttport); in xhci_check_bw_table()
2364 virt_dev->real_port); in xhci_check_bw_table()
2370 bw_used = DIV_ROUND_UP(bw_table->interval0_esit_payload, block_size) + in xhci_check_bw_table()
2371 bw_table->interval_bw[0].num_packets * in xhci_check_bw_table()
2372 xhci_get_largest_overhead(&bw_table->interval_bw[0]); in xhci_check_bw_table()
2385 bw_table->interval_bw[i].num_packets; in xhci_check_bw_table()
2390 if (list_empty(&bw_table->interval_bw[i].endpoints)) in xhci_check_bw_table()
2396 ep_entry = bw_table->interval_bw[i].endpoints.next; in xhci_check_bw_table()
2401 virt_ep->bw_info.max_packet_size, in xhci_check_bw_table()
2409 &bw_table->interval_bw[i]); in xhci_check_bw_table()
2448 return -ENOMEM; in xhci_check_bw_table()
2452 * Ok, we know we have some packets left over after even-handedly in xhci_check_bw_table()
2454 * fit into, so we over-schedule and say they will be scheduled every in xhci_check_bw_table()
2460 if (!virt_dev->tt_info && virt_dev->udev->speed == USB_SPEED_HIGH) { in xhci_check_bw_table()
2461 unsigned int port_index = virt_dev->real_port - 1; in xhci_check_bw_table()
2468 xhci->rh_bw[port_index].num_active_tts; in xhci_check_bw_table()
2475 (max_bandwidth - bw_used - bw_reserved) * 100 / in xhci_check_bw_table()
2482 return -ENOMEM; in xhci_check_bw_table()
2485 bw_table->bw_used = bw_used; in xhci_check_bw_table()
2503 unsigned int mps = DIV_ROUND_UP(ep_bw->max_packet_size, SS_BLOCK); in xhci_get_ss_bw_consumed()
2505 if (ep_bw->ep_interval == 0) in xhci_get_ss_bw_consumed()
2507 (ep_bw->mult * ep_bw->num_packets * in xhci_get_ss_bw_consumed()
2509 return DIV_ROUND_UP(ep_bw->mult * ep_bw->num_packets * in xhci_get_ss_bw_consumed()
2511 1 << ep_bw->ep_interval); in xhci_get_ss_bw_consumed()
2525 if (xhci_is_async_ep(ep_bw->type)) in xhci_drop_ep_from_interval_table()
2528 if (udev->speed >= USB_SPEED_SUPER) { in xhci_drop_ep_from_interval_table()
2529 if (xhci_is_sync_in_ep(ep_bw->type)) in xhci_drop_ep_from_interval_table()
2530 xhci->devs[udev->slot_id]->bw_table->ss_bw_in -= in xhci_drop_ep_from_interval_table()
2533 xhci->devs[udev->slot_id]->bw_table->ss_bw_out -= in xhci_drop_ep_from_interval_table()
2541 if (list_empty(&virt_ep->bw_endpoint_list)) in xhci_drop_ep_from_interval_table()
2546 if (udev->speed == USB_SPEED_HIGH) in xhci_drop_ep_from_interval_table()
2547 normalized_interval = ep_bw->ep_interval; in xhci_drop_ep_from_interval_table()
2549 normalized_interval = ep_bw->ep_interval - 3; in xhci_drop_ep_from_interval_table()
2552 bw_table->interval0_esit_payload -= ep_bw->max_esit_payload; in xhci_drop_ep_from_interval_table()
2553 interval_bw = &bw_table->interval_bw[normalized_interval]; in xhci_drop_ep_from_interval_table()
2554 interval_bw->num_packets -= ep_bw->num_packets; in xhci_drop_ep_from_interval_table()
2555 switch (udev->speed) { in xhci_drop_ep_from_interval_table()
2557 interval_bw->overhead[LS_OVERHEAD_TYPE] -= 1; in xhci_drop_ep_from_interval_table()
2560 interval_bw->overhead[FS_OVERHEAD_TYPE] -= 1; in xhci_drop_ep_from_interval_table()
2563 interval_bw->overhead[HS_OVERHEAD_TYPE] -= 1; in xhci_drop_ep_from_interval_table()
2572 tt_info->active_eps -= 1; in xhci_drop_ep_from_interval_table()
2573 list_del_init(&virt_ep->bw_endpoint_list); in xhci_drop_ep_from_interval_table()
2587 if (xhci_is_async_ep(ep_bw->type)) in xhci_add_ep_to_interval_table()
2590 if (udev->speed == USB_SPEED_SUPER) { in xhci_add_ep_to_interval_table()
2591 if (xhci_is_sync_in_ep(ep_bw->type)) in xhci_add_ep_to_interval_table()
2592 xhci->devs[udev->slot_id]->bw_table->ss_bw_in += in xhci_add_ep_to_interval_table()
2595 xhci->devs[udev->slot_id]->bw_table->ss_bw_out += in xhci_add_ep_to_interval_table()
2603 if (udev->speed == USB_SPEED_HIGH) in xhci_add_ep_to_interval_table()
2604 normalized_interval = ep_bw->ep_interval; in xhci_add_ep_to_interval_table()
2606 normalized_interval = ep_bw->ep_interval - 3; in xhci_add_ep_to_interval_table()
2609 bw_table->interval0_esit_payload += ep_bw->max_esit_payload; in xhci_add_ep_to_interval_table()
2610 interval_bw = &bw_table->interval_bw[normalized_interval]; in xhci_add_ep_to_interval_table()
2611 interval_bw->num_packets += ep_bw->num_packets; in xhci_add_ep_to_interval_table()
2612 switch (udev->speed) { in xhci_add_ep_to_interval_table()
2614 interval_bw->overhead[LS_OVERHEAD_TYPE] += 1; in xhci_add_ep_to_interval_table()
2617 interval_bw->overhead[FS_OVERHEAD_TYPE] += 1; in xhci_add_ep_to_interval_table()
2620 interval_bw->overhead[HS_OVERHEAD_TYPE] += 1; in xhci_add_ep_to_interval_table()
2630 tt_info->active_eps += 1; in xhci_add_ep_to_interval_table()
2632 list_for_each_entry(smaller_ep, &interval_bw->endpoints, in xhci_add_ep_to_interval_table()
2634 if (ep_bw->max_packet_size >= in xhci_add_ep_to_interval_table()
2635 smaller_ep->bw_info.max_packet_size) { in xhci_add_ep_to_interval_table()
2637 list_add_tail(&virt_ep->bw_endpoint_list, in xhci_add_ep_to_interval_table()
2638 &smaller_ep->bw_endpoint_list); in xhci_add_ep_to_interval_table()
2643 list_add_tail(&virt_ep->bw_endpoint_list, in xhci_add_ep_to_interval_table()
2644 &interval_bw->endpoints); in xhci_add_ep_to_interval_table()
2652 if (!virt_dev->tt_info) in xhci_update_tt_active_eps()
2655 rh_bw_info = &xhci->rh_bw[virt_dev->real_port - 1]; in xhci_update_tt_active_eps()
2657 virt_dev->tt_info->active_eps != 0) { in xhci_update_tt_active_eps()
2658 rh_bw_info->num_active_tts += 1; in xhci_update_tt_active_eps()
2659 rh_bw_info->bw_table.bw_used += TT_HS_OVERHEAD; in xhci_update_tt_active_eps()
2661 virt_dev->tt_info->active_eps == 0) { in xhci_update_tt_active_eps()
2662 rh_bw_info->num_active_tts -= 1; in xhci_update_tt_active_eps()
2663 rh_bw_info->bw_table.bw_used -= TT_HS_OVERHEAD; in xhci_update_tt_active_eps()
2676 if (virt_dev->tt_info) in xhci_reserve_bandwidth()
2677 old_active_eps = virt_dev->tt_info->active_eps; in xhci_reserve_bandwidth()
2683 return -ENOMEM; in xhci_reserve_bandwidth()
2691 memcpy(&ep_bw_info[i], &virt_dev->eps[i].bw_info, in xhci_reserve_bandwidth()
2698 &virt_dev->eps[i].bw_info, in xhci_reserve_bandwidth()
2699 virt_dev->bw_table, in xhci_reserve_bandwidth()
2700 virt_dev->udev, in xhci_reserve_bandwidth()
2701 &virt_dev->eps[i], in xhci_reserve_bandwidth()
2702 virt_dev->tt_info); in xhci_reserve_bandwidth()
2705 xhci_update_bw_info(xhci, virt_dev->in_ctx, ctrl_ctx, virt_dev); in xhci_reserve_bandwidth()
2710 &virt_dev->eps[i].bw_info, in xhci_reserve_bandwidth()
2711 virt_dev->bw_table, in xhci_reserve_bandwidth()
2712 virt_dev->udev, in xhci_reserve_bandwidth()
2713 &virt_dev->eps[i], in xhci_reserve_bandwidth()
2714 virt_dev->tt_info); in xhci_reserve_bandwidth()
2735 &virt_dev->eps[i].bw_info, in xhci_reserve_bandwidth()
2736 virt_dev->bw_table, in xhci_reserve_bandwidth()
2737 virt_dev->udev, in xhci_reserve_bandwidth()
2738 &virt_dev->eps[i], in xhci_reserve_bandwidth()
2739 virt_dev->tt_info); in xhci_reserve_bandwidth()
2742 memcpy(&virt_dev->eps[i].bw_info, &ep_bw_info[i], in xhci_reserve_bandwidth()
2747 &virt_dev->eps[i].bw_info, in xhci_reserve_bandwidth()
2748 virt_dev->bw_table, in xhci_reserve_bandwidth()
2749 virt_dev->udev, in xhci_reserve_bandwidth()
2750 &virt_dev->eps[i], in xhci_reserve_bandwidth()
2751 virt_dev->tt_info); in xhci_reserve_bandwidth()
2753 return -ENOMEM; in xhci_reserve_bandwidth()
2772 return -EINVAL; in xhci_configure_endpoint()
2774 spin_lock_irqsave(&xhci->lock, flags); in xhci_configure_endpoint()
2776 if (xhci->xhc_state & XHCI_STATE_DYING) { in xhci_configure_endpoint()
2777 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2778 return -ESHUTDOWN; in xhci_configure_endpoint()
2781 virt_dev = xhci->devs[udev->slot_id]; in xhci_configure_endpoint()
2783 ctrl_ctx = xhci_get_input_control_ctx(command->in_ctx); in xhci_configure_endpoint()
2785 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2788 return -ENOMEM; in xhci_configure_endpoint()
2791 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK) && in xhci_configure_endpoint()
2793 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2796 xhci->num_active_eps); in xhci_configure_endpoint()
2797 return -ENOMEM; in xhci_configure_endpoint()
2799 if ((xhci->quirks & XHCI_SW_BW_CHECKING) && in xhci_configure_endpoint()
2800 xhci_reserve_bandwidth(xhci, virt_dev, command->in_ctx)) { in xhci_configure_endpoint()
2801 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) in xhci_configure_endpoint()
2803 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2805 return -ENOMEM; in xhci_configure_endpoint()
2808 slot_ctx = xhci_get_slot_ctx(xhci, command->in_ctx); in xhci_configure_endpoint()
2815 command->in_ctx->dma, in xhci_configure_endpoint()
2816 udev->slot_id, must_succeed); in xhci_configure_endpoint()
2819 command->in_ctx->dma, in xhci_configure_endpoint()
2820 udev->slot_id, must_succeed); in xhci_configure_endpoint()
2822 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) in xhci_configure_endpoint()
2824 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2827 return -ENOMEM; in xhci_configure_endpoint()
2830 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2833 wait_for_completion(command->completion); in xhci_configure_endpoint()
2837 &command->status); in xhci_configure_endpoint()
2840 &command->status); in xhci_configure_endpoint()
2842 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) { in xhci_configure_endpoint()
2843 spin_lock_irqsave(&xhci->lock, flags); in xhci_configure_endpoint()
2851 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2859 struct xhci_virt_ep *ep = &vdev->eps[i]; in xhci_check_bw_drop_ep_streams()
2861 if (ep->ep_state & EP_HAS_STREAMS) { in xhci_check_bw_drop_ep_streams()
2864 xhci_free_stream_info(xhci, ep->stream_info); in xhci_check_bw_drop_ep_streams()
2865 ep->stream_info = NULL; in xhci_check_bw_drop_ep_streams()
2866 ep->ep_state &= ~EP_HAS_STREAMS; in xhci_check_bw_drop_ep_streams()
2877 * else should be touching the xhci->devs[slot_id] structure, so we
2878 * don't need to take the xhci->lock for manipulating that.
2894 if ((xhci->xhc_state & XHCI_STATE_DYING) || in xhci_check_bandwidth()
2895 (xhci->xhc_state & XHCI_STATE_REMOVING)) in xhci_check_bandwidth()
2896 return -ENODEV; in xhci_check_bandwidth()
2899 virt_dev = xhci->devs[udev->slot_id]; in xhci_check_bandwidth()
2903 return -ENOMEM; in xhci_check_bandwidth()
2905 command->in_ctx = virt_dev->in_ctx; in xhci_check_bandwidth()
2907 /* See section 4.6.6 - A0 = 1; A1 = D0 = D1 = 0 */ in xhci_check_bandwidth()
2908 ctrl_ctx = xhci_get_input_control_ctx(command->in_ctx); in xhci_check_bandwidth()
2912 ret = -ENOMEM; in xhci_check_bandwidth()
2915 ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG); in xhci_check_bandwidth()
2916 ctrl_ctx->add_flags &= cpu_to_le32(~EP0_FLAG); in xhci_check_bandwidth()
2917 ctrl_ctx->drop_flags &= cpu_to_le32(~(SLOT_FLAG | EP0_FLAG)); in xhci_check_bandwidth()
2920 if (ctrl_ctx->add_flags == cpu_to_le32(SLOT_FLAG) && in xhci_check_bandwidth()
2921 ctrl_ctx->drop_flags == 0) { in xhci_check_bandwidth()
2926 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); in xhci_check_bandwidth()
2927 for (i = 31; i >= 1; i--) { in xhci_check_bandwidth()
2930 if ((virt_dev->eps[i-1].ring && !(ctrl_ctx->drop_flags & le32)) in xhci_check_bandwidth()
2931 || (ctrl_ctx->add_flags & le32) || i == 1) { in xhci_check_bandwidth()
2932 slot_ctx->dev_info &= cpu_to_le32(~LAST_CTX_MASK); in xhci_check_bandwidth()
2933 slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(i)); in xhci_check_bandwidth()
2946 if ((le32_to_cpu(ctrl_ctx->drop_flags) & (1 << (i + 1))) && in xhci_check_bandwidth()
2947 !(le32_to_cpu(ctrl_ctx->add_flags) & (1 << (i + 1)))) { in xhci_check_bandwidth()
2958 if (!virt_dev->eps[i].new_ring) in xhci_check_bandwidth()
2963 if (virt_dev->eps[i].ring) { in xhci_check_bandwidth()
2967 virt_dev->eps[i].ring = virt_dev->eps[i].new_ring; in xhci_check_bandwidth()
2968 virt_dev->eps[i].new_ring = NULL; in xhci_check_bandwidth()
2972 kfree(command->completion); in xhci_check_bandwidth()
2991 virt_dev = xhci->devs[udev->slot_id]; in xhci_reset_bandwidth()
2994 if (virt_dev->eps[i].new_ring) { in xhci_reset_bandwidth()
2996 xhci_ring_free(xhci, virt_dev->eps[i].new_ring); in xhci_reset_bandwidth()
2997 virt_dev->eps[i].new_ring = NULL; in xhci_reset_bandwidth()
3010 ctrl_ctx->add_flags = cpu_to_le32(add_flags); in xhci_setup_input_ctx_for_config_ep()
3011 ctrl_ctx->drop_flags = cpu_to_le32(drop_flags); in xhci_setup_input_ctx_for_config_ep()
3013 ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG); in xhci_setup_input_ctx_for_config_ep()
3028 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_disable()
3030 udev = (struct usb_device *)host_ep->hcpriv; in xhci_endpoint_disable()
3031 if (!udev || !udev->slot_id) in xhci_endpoint_disable()
3034 vdev = xhci->devs[udev->slot_id]; in xhci_endpoint_disable()
3038 ep_index = xhci_get_endpoint_index(&host_ep->desc); in xhci_endpoint_disable()
3039 ep = &vdev->eps[ep_index]; in xhci_endpoint_disable()
3042 if (ep->ep_state & EP_CLEARING_TT) { in xhci_endpoint_disable()
3043 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_disable()
3048 if (ep->ep_state) in xhci_endpoint_disable()
3050 ep->ep_state); in xhci_endpoint_disable()
3052 host_ep->hcpriv = NULL; in xhci_endpoint_disable()
3053 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_disable()
3065 * endpoint. Refer to the additional note in xhci spcification section 4.6.8.
3083 if (!host_ep->hcpriv) in xhci_endpoint_reset()
3085 udev = (struct usb_device *) host_ep->hcpriv; in xhci_endpoint_reset()
3086 vdev = xhci->devs[udev->slot_id]; in xhci_endpoint_reset()
3089 * vdev may be lost due to xHC restore error and re-initialization in xhci_endpoint_reset()
3093 if (!udev->slot_id || !vdev) in xhci_endpoint_reset()
3095 ep_index = xhci_get_endpoint_index(&host_ep->desc); in xhci_endpoint_reset()
3096 ep = &vdev->eps[ep_index]; in xhci_endpoint_reset()
3099 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_reset()
3100 if (ep->ep_state & EP_HARD_CLEAR_TOGGLE) { in xhci_endpoint_reset()
3101 ep->ep_state &= ~EP_HARD_CLEAR_TOGGLE; in xhci_endpoint_reset()
3102 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3105 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3106 /* Only interrupt and bulk ep's use data toggle, USB2 spec 5.5.4-> */ in xhci_endpoint_reset()
3107 if (usb_endpoint_xfer_control(&host_ep->desc) || in xhci_endpoint_reset()
3108 usb_endpoint_xfer_isoc(&host_ep->desc)) in xhci_endpoint_reset()
3111 ep_flag = xhci_get_endpoint_flag(&host_ep->desc); in xhci_endpoint_reset()
3124 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_reset()
3127 ep->ep_state |= EP_SOFT_CLEAR_TOGGLE; in xhci_endpoint_reset()
3135 if (!list_empty(&ep->ring->td_list)) { in xhci_endpoint_reset()
3136 dev_err(&udev->dev, "EP not empty, refuse reset\n"); in xhci_endpoint_reset()
3137 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3142 err = xhci_queue_stop_endpoint(xhci, stop_cmd, udev->slot_id, in xhci_endpoint_reset()
3145 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3153 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3155 wait_for_completion(stop_cmd->completion); in xhci_endpoint_reset()
3157 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_reset()
3160 ctrl_ctx = xhci_get_input_control_ctx(cfg_cmd->in_ctx); in xhci_endpoint_reset()
3162 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3169 xhci_setup_input_ctx_for_config_ep(xhci, cfg_cmd->in_ctx, vdev->out_ctx, in xhci_endpoint_reset()
3171 xhci_endpoint_copy(xhci, cfg_cmd->in_ctx, vdev->out_ctx, ep_index); in xhci_endpoint_reset()
3173 err = xhci_queue_configure_endpoint(xhci, cfg_cmd, cfg_cmd->in_ctx->dma, in xhci_endpoint_reset()
3174 udev->slot_id, false); in xhci_endpoint_reset()
3176 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3184 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3186 wait_for_completion(cfg_cmd->completion); in xhci_endpoint_reset()
3191 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_reset()
3192 if (ep->ep_state & EP_SOFT_CLEAR_TOGGLE) in xhci_endpoint_reset()
3193 ep->ep_state &= ~EP_SOFT_CLEAR_TOGGLE; in xhci_endpoint_reset()
3194 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3206 return -EINVAL; in xhci_check_streams_endpoint()
3209 return ret ? ret : -EINVAL; in xhci_check_streams_endpoint()
3210 if (usb_ss_max_streams(&ep->ss_ep_comp) == 0) { in xhci_check_streams_endpoint()
3213 ep->desc.bEndpointAddress); in xhci_check_streams_endpoint()
3214 return -EINVAL; in xhci_check_streams_endpoint()
3217 ep_index = xhci_get_endpoint_index(&ep->desc); in xhci_check_streams_endpoint()
3218 ep_state = xhci->devs[slot_id]->eps[ep_index].ep_state; in xhci_check_streams_endpoint()
3223 ep->desc.bEndpointAddress); in xhci_check_streams_endpoint()
3226 return -EINVAL; in xhci_check_streams_endpoint()
3228 if (!list_empty(&xhci->devs[slot_id]->eps[ep_index].ring->td_list)) { in xhci_check_streams_endpoint()
3231 ep->desc.bEndpointAddress); in xhci_check_streams_endpoint()
3232 return -EINVAL; in xhci_check_streams_endpoint()
3250 max_streams = HCC_MAX_PSA(xhci->hcc_params); in xhci_calculate_streams_entries()
3275 eps[i], udev->slot_id); in xhci_calculate_streams_and_bitmask()
3279 max_streams = usb_ss_max_streams(&eps[i]->ss_ep_comp); in xhci_calculate_streams_and_bitmask()
3280 if (max_streams < (*num_streams - 1)) { in xhci_calculate_streams_and_bitmask()
3282 eps[i]->desc.bEndpointAddress, in xhci_calculate_streams_and_bitmask()
3287 endpoint_flag = xhci_get_endpoint_flag(&eps[i]->desc); in xhci_calculate_streams_and_bitmask()
3289 return -EINVAL; in xhci_calculate_streams_and_bitmask()
3305 slot_id = udev->slot_id; in xhci_calculate_no_streams_bitmask()
3306 if (!xhci->devs[slot_id]) in xhci_calculate_no_streams_bitmask()
3310 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_calculate_no_streams_bitmask()
3311 ep_state = xhci->devs[slot_id]->eps[ep_index].ep_state; in xhci_calculate_no_streams_bitmask()
3317 eps[i]->desc.bEndpointAddress); in xhci_calculate_no_streams_bitmask()
3326 eps[i]->desc.bEndpointAddress); in xhci_calculate_no_streams_bitmask()
3328 "with non-streams endpoint\n"); in xhci_calculate_no_streams_bitmask()
3331 changed_ep_bitmask |= xhci_get_endpoint_flag(&eps[i]->desc); in xhci_calculate_no_streams_bitmask()
3368 return -EINVAL; in xhci_alloc_streams()
3379 if ((xhci->quirks & XHCI_BROKEN_STREAMS) || in xhci_alloc_streams()
3380 HCC_MAX_PSA(xhci->hcc_params) < 4) { in xhci_alloc_streams()
3382 return -ENOSYS; in xhci_alloc_streams()
3387 return -ENOMEM; in xhci_alloc_streams()
3389 ctrl_ctx = xhci_get_input_control_ctx(config_cmd->in_ctx); in xhci_alloc_streams()
3394 return -ENOMEM; in xhci_alloc_streams()
3401 spin_lock_irqsave(&xhci->lock, flags); in xhci_alloc_streams()
3406 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_streams()
3413 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_streams()
3414 return -EINVAL; in xhci_alloc_streams()
3416 vdev = xhci->devs[udev->slot_id]; in xhci_alloc_streams()
3421 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_alloc_streams()
3422 vdev->eps[ep_index].ep_state |= EP_GETTING_STREAMS; in xhci_alloc_streams()
3424 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_streams()
3435 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_alloc_streams()
3436 max_packet = usb_endpoint_maxp(&eps[i]->desc); in xhci_alloc_streams()
3437 vdev->eps[ep_index].stream_info = xhci_alloc_stream_info(xhci, in xhci_alloc_streams()
3441 if (!vdev->eps[ep_index].stream_info) in xhci_alloc_streams()
3452 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_alloc_streams()
3453 ep_ctx = xhci_get_ep_ctx(xhci, config_cmd->in_ctx, ep_index); in xhci_alloc_streams()
3455 xhci_endpoint_copy(xhci, config_cmd->in_ctx, in xhci_alloc_streams()
3456 vdev->out_ctx, ep_index); in xhci_alloc_streams()
3458 vdev->eps[ep_index].stream_info); in xhci_alloc_streams()
3463 xhci_setup_input_ctx_for_config_ep(xhci, config_cmd->in_ctx, in xhci_alloc_streams()
3464 vdev->out_ctx, ctrl_ctx, in xhci_alloc_streams()
3478 spin_lock_irqsave(&xhci->lock, flags); in xhci_alloc_streams()
3480 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_alloc_streams()
3481 vdev->eps[ep_index].ep_state &= ~EP_GETTING_STREAMS; in xhci_alloc_streams()
3483 udev->slot_id, ep_index); in xhci_alloc_streams()
3484 vdev->eps[ep_index].ep_state |= EP_HAS_STREAMS; in xhci_alloc_streams()
3487 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_streams()
3490 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_alloc_streams()
3494 return num_streams - 1; in xhci_alloc_streams()
3499 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_alloc_streams()
3500 xhci_free_stream_info(xhci, vdev->eps[ep_index].stream_info); in xhci_alloc_streams()
3501 vdev->eps[ep_index].stream_info = NULL; in xhci_alloc_streams()
3505 vdev->eps[ep_index].ep_state &= ~EP_GETTING_STREAMS; in xhci_alloc_streams()
3506 vdev->eps[ep_index].ep_state &= ~EP_HAS_STREAMS; in xhci_alloc_streams()
3510 return -ENOMEM; in xhci_alloc_streams()
3533 vdev = xhci->devs[udev->slot_id]; in xhci_free_streams()
3536 spin_lock_irqsave(&xhci->lock, flags); in xhci_free_streams()
3540 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_streams()
3541 return -EINVAL; in xhci_free_streams()
3548 ep_index = xhci_get_endpoint_index(&eps[0]->desc); in xhci_free_streams()
3549 command = vdev->eps[ep_index].stream_info->free_streams_command; in xhci_free_streams()
3550 ctrl_ctx = xhci_get_input_control_ctx(command->in_ctx); in xhci_free_streams()
3552 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_streams()
3555 return -EINVAL; in xhci_free_streams()
3561 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_free_streams()
3562 ep_ctx = xhci_get_ep_ctx(xhci, command->in_ctx, ep_index); in xhci_free_streams()
3563 xhci->devs[udev->slot_id]->eps[ep_index].ep_state |= in xhci_free_streams()
3566 xhci_endpoint_copy(xhci, command->in_ctx, in xhci_free_streams()
3567 vdev->out_ctx, ep_index); in xhci_free_streams()
3569 &vdev->eps[ep_index]); in xhci_free_streams()
3571 xhci_setup_input_ctx_for_config_ep(xhci, command->in_ctx, in xhci_free_streams()
3572 vdev->out_ctx, ctrl_ctx, in xhci_free_streams()
3574 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_streams()
3588 spin_lock_irqsave(&xhci->lock, flags); in xhci_free_streams()
3590 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_free_streams()
3591 xhci_free_stream_info(xhci, vdev->eps[ep_index].stream_info); in xhci_free_streams()
3592 vdev->eps[ep_index].stream_info = NULL; in xhci_free_streams()
3596 vdev->eps[ep_index].ep_state &= ~EP_GETTING_NO_STREAMS; in xhci_free_streams()
3597 vdev->eps[ep_index].ep_state &= ~EP_HAS_STREAMS; in xhci_free_streams()
3599 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_streams()
3609 * Must be called with xhci->lock held.
3619 if (virt_dev->eps[i].ring) { in xhci_free_device_endpoint_resources()
3624 xhci->num_active_eps -= num_dropped_eps; in xhci_free_device_endpoint_resources()
3630 xhci->num_active_eps); in xhci_free_device_endpoint_resources()
3637 * xhci_address_device(), and then re-set up the configuration. If this is
3639 * settings will be re-installed through the normal bandwidth allocation
3648 * re-initialization during S3/S4. In this case, call xhci_alloc_dev() to
3649 * re-allocate the device.
3667 slot_id = udev->slot_id; in xhci_discover_or_reset_device()
3668 virt_dev = xhci->devs[slot_id]; in xhci_discover_or_reset_device()
3671 "not exist. Re-allocate the device\n", slot_id); in xhci_discover_or_reset_device()
3676 return -EINVAL; in xhci_discover_or_reset_device()
3679 if (virt_dev->tt_info) in xhci_discover_or_reset_device()
3680 old_active_eps = virt_dev->tt_info->active_eps; in xhci_discover_or_reset_device()
3682 if (virt_dev->udev != udev) { in xhci_discover_or_reset_device()
3685 * Re-allocate the device. in xhci_discover_or_reset_device()
3688 "not match the udev. Re-allocate the device\n", in xhci_discover_or_reset_device()
3694 return -EINVAL; in xhci_discover_or_reset_device()
3698 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); in xhci_discover_or_reset_device()
3699 if (GET_SLOT_STATE(le32_to_cpu(slot_ctx->dev_state)) == in xhci_discover_or_reset_device()
3715 return -ENOMEM; in xhci_discover_or_reset_device()
3719 spin_lock_irqsave(&xhci->lock, flags); in xhci_discover_or_reset_device()
3724 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_discover_or_reset_device()
3728 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_discover_or_reset_device()
3731 wait_for_completion(reset_device_cmd->completion); in xhci_discover_or_reset_device()
3737 ret = reset_device_cmd->status; in xhci_discover_or_reset_device()
3742 ret = -ETIME; in xhci_discover_or_reset_device()
3748 xhci_get_slot_state(xhci, virt_dev->out_ctx)); in xhci_discover_or_reset_device()
3761 ret = -EINVAL; in xhci_discover_or_reset_device()
3766 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) { in xhci_discover_or_reset_device()
3767 spin_lock_irqsave(&xhci->lock, flags); in xhci_discover_or_reset_device()
3770 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_discover_or_reset_device()
3775 struct xhci_virt_ep *ep = &virt_dev->eps[i]; in xhci_discover_or_reset_device()
3777 if (ep->ep_state & EP_HAS_STREAMS) { in xhci_discover_or_reset_device()
3780 xhci_free_stream_info(xhci, ep->stream_info); in xhci_discover_or_reset_device()
3781 ep->stream_info = NULL; in xhci_discover_or_reset_device()
3782 ep->ep_state &= ~EP_HAS_STREAMS; in xhci_discover_or_reset_device()
3785 if (ep->ring) { in xhci_discover_or_reset_device()
3789 if (!list_empty(&virt_dev->eps[i].bw_endpoint_list)) in xhci_discover_or_reset_device()
3791 &virt_dev->eps[i].bw_info, in xhci_discover_or_reset_device()
3792 virt_dev->bw_table, in xhci_discover_or_reset_device()
3794 &virt_dev->eps[i], in xhci_discover_or_reset_device()
3795 virt_dev->tt_info); in xhci_discover_or_reset_device()
3796 xhci_clear_endpoint_bw_info(&virt_dev->eps[i].bw_info); in xhci_discover_or_reset_device()
3800 virt_dev->flags = 0; in xhci_discover_or_reset_device()
3826 if (xhci->quirks & XHCI_RESET_ON_RESUME) in xhci_free_dev()
3827 pm_runtime_put_noidle(hcd->self.controller); in xhci_free_dev()
3833 if (ret <= 0 && ret != -ENODEV) in xhci_free_dev()
3836 virt_dev = xhci->devs[udev->slot_id]; in xhci_free_dev()
3837 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); in xhci_free_dev()
3842 virt_dev->eps[i].ep_state &= ~EP_STOP_CMD_PENDING; in xhci_free_dev()
3843 virt_dev->udev = NULL; in xhci_free_dev()
3844 xhci_disable_slot(xhci, udev->slot_id); in xhci_free_dev()
3846 spin_lock_irqsave(&xhci->lock, flags); in xhci_free_dev()
3847 xhci_free_virt_device(xhci, udev->slot_id); in xhci_free_dev()
3848 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_dev()
3861 return -ENOMEM; in xhci_disable_slot()
3865 spin_lock_irqsave(&xhci->lock, flags); in xhci_disable_slot()
3867 state = readl(&xhci->op_regs->status); in xhci_disable_slot()
3868 if (state == 0xffffffff || (xhci->xhc_state & XHCI_STATE_DYING) || in xhci_disable_slot()
3869 (xhci->xhc_state & XHCI_STATE_HALTED)) { in xhci_disable_slot()
3870 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_disable_slot()
3872 return -ENODEV; in xhci_disable_slot()
3878 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_disable_slot()
3883 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_disable_slot()
3885 wait_for_completion(command->completion); in xhci_disable_slot()
3887 if (command->status != COMP_SUCCESS) in xhci_disable_slot()
3889 slot_id, command->status); in xhci_disable_slot()
3900 * Must be called with xhci->lock held.
3904 if (xhci->num_active_eps + 1 > xhci->limit_active_eps) { in xhci_reserve_host_control_ep_resources()
3908 xhci->num_active_eps, xhci->limit_active_eps); in xhci_reserve_host_control_ep_resources()
3909 return -ENOMEM; in xhci_reserve_host_control_ep_resources()
3911 xhci->num_active_eps += 1; in xhci_reserve_host_control_ep_resources()
3914 xhci->num_active_eps); in xhci_reserve_host_control_ep_resources()
3936 spin_lock_irqsave(&xhci->lock, flags); in xhci_alloc_dev()
3939 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_dev()
3945 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_dev()
3947 wait_for_completion(command->completion); in xhci_alloc_dev()
3948 slot_id = command->slot_id; in xhci_alloc_dev()
3950 if (!slot_id || command->status != COMP_SUCCESS) { in xhci_alloc_dev()
3952 xhci_trb_comp_code_string(command->status)); in xhci_alloc_dev()
3955 readl(&xhci->cap_regs->hcs_params1))); in xhci_alloc_dev()
3962 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) { in xhci_alloc_dev()
3963 spin_lock_irqsave(&xhci->lock, flags); in xhci_alloc_dev()
3966 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_dev()
3969 xhci->num_active_eps); in xhci_alloc_dev()
3972 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_dev()
3982 vdev = xhci->devs[slot_id]; in xhci_alloc_dev()
3983 slot_ctx = xhci_get_slot_ctx(xhci, vdev->out_ctx); in xhci_alloc_dev()
3986 udev->slot_id = slot_id; in xhci_alloc_dev()
3994 if (xhci->quirks & XHCI_RESET_ON_RESUME) in xhci_alloc_dev()
3995 pm_runtime_get_noresume(hcd->self.controller); in xhci_alloc_dev()
4002 xhci_disable_slot(xhci, udev->slot_id); in xhci_alloc_dev()
4003 xhci_free_virt_device(xhci, udev->slot_id); in xhci_alloc_dev()
4025 mutex_lock(&xhci->mutex); in xhci_setup_device()
4027 if (xhci->xhc_state) { /* dying, removing or halted */ in xhci_setup_device()
4028 ret = -ESHUTDOWN; in xhci_setup_device()
4032 if (!udev->slot_id) { in xhci_setup_device()
4034 "Bad Slot ID %d", udev->slot_id); in xhci_setup_device()
4035 ret = -EINVAL; in xhci_setup_device()
4039 virt_dev = xhci->devs[udev->slot_id]; in xhci_setup_device()
4044 * a zero-dereference was observed once due to virt_dev = 0. in xhci_setup_device()
4048 udev->slot_id); in xhci_setup_device()
4049 ret = -EINVAL; in xhci_setup_device()
4052 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); in xhci_setup_device()
4056 if (GET_SLOT_STATE(le32_to_cpu(slot_ctx->dev_state)) == in xhci_setup_device()
4065 ret = -ENOMEM; in xhci_setup_device()
4069 command->in_ctx = virt_dev->in_ctx; in xhci_setup_device()
4071 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); in xhci_setup_device()
4072 ctrl_ctx = xhci_get_input_control_ctx(virt_dev->in_ctx); in xhci_setup_device()
4076 ret = -EINVAL; in xhci_setup_device()
4080 * If this is the first Set Address since device plug-in or in xhci_setup_device()
4084 if (!slot_ctx->dev_info) in xhci_setup_device()
4089 ctrl_ctx->add_flags = cpu_to_le32(SLOT_FLAG | EP0_FLAG); in xhci_setup_device()
4090 ctrl_ctx->drop_flags = 0; in xhci_setup_device()
4092 trace_xhci_address_ctx(xhci, virt_dev->in_ctx, in xhci_setup_device()
4093 le32_to_cpu(slot_ctx->dev_info) >> 27); in xhci_setup_device()
4096 spin_lock_irqsave(&xhci->lock, flags); in xhci_setup_device()
4098 ret = xhci_queue_address_device(xhci, command, virt_dev->in_ctx->dma, in xhci_setup_device()
4099 udev->slot_id, setup); in xhci_setup_device()
4101 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_setup_device()
4107 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_setup_device()
4110 wait_for_completion(command->completion); in xhci_setup_device()
4116 switch (command->status) { in xhci_setup_device()
4120 ret = -ETIME; in xhci_setup_device()
4125 act, udev->slot_id); in xhci_setup_device()
4126 ret = -EINVAL; in xhci_setup_device()
4129 dev_warn(&udev->dev, "Device not responding to setup %s.\n", act); in xhci_setup_device()
4131 mutex_unlock(&xhci->mutex); in xhci_setup_device()
4132 ret = xhci_disable_slot(xhci, udev->slot_id); in xhci_setup_device()
4133 xhci_free_virt_device(xhci, udev->slot_id); in xhci_setup_device()
4136 kfree(command->completion); in xhci_setup_device()
4138 return -EPROTO; in xhci_setup_device()
4140 dev_warn(&udev->dev, in xhci_setup_device()
4142 ret = -ENODEV; in xhci_setup_device()
4151 act, command->status); in xhci_setup_device()
4152 trace_xhci_address_ctx(xhci, virt_dev->out_ctx, 1); in xhci_setup_device()
4153 ret = -EINVAL; in xhci_setup_device()
4158 temp_64 = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr); in xhci_setup_device()
4163 udev->slot_id, in xhci_setup_device()
4164 &xhci->dcbaa->dev_context_ptrs[udev->slot_id], in xhci_setup_device()
4166 le64_to_cpu(xhci->dcbaa->dev_context_ptrs[udev->slot_id])); in xhci_setup_device()
4169 (unsigned long long)virt_dev->out_ctx->dma); in xhci_setup_device()
4170 trace_xhci_address_ctx(xhci, virt_dev->in_ctx, in xhci_setup_device()
4171 le32_to_cpu(slot_ctx->dev_info) >> 27); in xhci_setup_device()
4176 trace_xhci_address_ctx(xhci, virt_dev->out_ctx, in xhci_setup_device()
4177 le32_to_cpu(slot_ctx->dev_info) >> 27); in xhci_setup_device()
4179 ctrl_ctx->add_flags = 0; in xhci_setup_device()
4180 ctrl_ctx->drop_flags = 0; in xhci_setup_device()
4181 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); in xhci_setup_device()
4182 udev->devaddr = (u8)(le32_to_cpu(slot_ctx->dev_state) & DEV_ADDR_MASK); in xhci_setup_device()
4186 le32_to_cpu(slot_ctx->dev_state) & DEV_ADDR_MASK); in xhci_setup_device()
4188 mutex_unlock(&xhci->mutex); in xhci_setup_device()
4190 kfree(command->completion); in xhci_setup_device()
4217 return rhub->ports[port1 - 1]->hw_portnum + 1; in xhci_find_raw_port_number()
4236 return -ENOMEM; in xhci_change_max_exit_latency()
4238 spin_lock_irqsave(&xhci->lock, flags); in xhci_change_max_exit_latency()
4240 virt_dev = xhci->devs[udev->slot_id]; in xhci_change_max_exit_latency()
4244 * xHC was re-initialized. Exit latency will be set later after in xhci_change_max_exit_latency()
4245 * hub_port_finish_reset() is done and xhci->devs[] are re-allocated in xhci_change_max_exit_latency()
4248 if (!virt_dev || max_exit_latency == virt_dev->current_mel) { in xhci_change_max_exit_latency()
4249 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_change_max_exit_latency()
4255 ctrl_ctx = xhci_get_input_control_ctx(command->in_ctx); in xhci_change_max_exit_latency()
4257 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_change_max_exit_latency()
4261 return -ENOMEM; in xhci_change_max_exit_latency()
4264 xhci_slot_copy(xhci, command->in_ctx, virt_dev->out_ctx); in xhci_change_max_exit_latency()
4265 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_change_max_exit_latency()
4267 ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG); in xhci_change_max_exit_latency()
4268 slot_ctx = xhci_get_slot_ctx(xhci, command->in_ctx); in xhci_change_max_exit_latency()
4269 slot_ctx->dev_info2 &= cpu_to_le32(~((u32) MAX_EXIT)); in xhci_change_max_exit_latency()
4270 slot_ctx->dev_info2 |= cpu_to_le32(max_exit_latency); in xhci_change_max_exit_latency()
4271 slot_ctx->dev_state = 0; in xhci_change_max_exit_latency()
4281 spin_lock_irqsave(&xhci->lock, flags); in xhci_change_max_exit_latency()
4282 virt_dev->current_mel = max_exit_latency; in xhci_change_max_exit_latency()
4283 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_change_max_exit_latency()
4305 u2del = HCS_U2_LATENCY(xhci->hcs_params3); in xhci_calculate_hird_besl()
4306 field = le32_to_cpu(udev->bos->ext_cap->bmAttributes); in xhci_calculate_hird_besl()
4322 besl_host = (u2del - 51) / 75 + 1; in xhci_calculate_hird_besl()
4340 field = le32_to_cpu(udev->bos->ext_cap->bmAttributes); in xhci_calculate_usb2_hw_lpm_params()
4343 l1 = udev->l1_params.timeout / 256; in xhci_calculate_usb2_hw_lpm_params()
4366 if (xhci->quirks & XHCI_HW_LPM_DISABLE) in xhci_set_usb2_hardware_lpm()
4367 return -EPERM; in xhci_set_usb2_hardware_lpm()
4369 if (hcd->speed >= HCD_USB3 || !xhci->hw_lpm_support || in xhci_set_usb2_hardware_lpm()
4370 !udev->lpm_capable) in xhci_set_usb2_hardware_lpm()
4371 return -EPERM; in xhci_set_usb2_hardware_lpm()
4373 if (!udev->parent || udev->parent->parent || in xhci_set_usb2_hardware_lpm()
4374 udev->descriptor.bDeviceClass == USB_CLASS_HUB) in xhci_set_usb2_hardware_lpm()
4375 return -EPERM; in xhci_set_usb2_hardware_lpm()
4377 if (udev->usb2_hw_lpm_capable != 1) in xhci_set_usb2_hardware_lpm()
4378 return -EPERM; in xhci_set_usb2_hardware_lpm()
4380 spin_lock_irqsave(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4382 ports = xhci->usb2_rhub.ports; in xhci_set_usb2_hardware_lpm()
4383 port_num = udev->portnum - 1; in xhci_set_usb2_hardware_lpm()
4384 pm_addr = ports[port_num]->addr + PORTPMSC; in xhci_set_usb2_hardware_lpm()
4386 hlpm_addr = ports[port_num]->addr + PORTHLPMC; in xhci_set_usb2_hardware_lpm()
4393 if (udev->usb2_hw_lpm_besl_capable) { in xhci_set_usb2_hardware_lpm()
4398 field = le32_to_cpu(udev->bos->ext_cap->bmAttributes); in xhci_set_usb2_hardware_lpm()
4403 hird = udev->l1_params.besl; in xhci_set_usb2_hardware_lpm()
4406 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4412 spin_lock_irqsave(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4423 pm_val |= PORT_HIRD(hird) | PORT_RWE | PORT_L1DS(udev->slot_id); in xhci_set_usb2_hardware_lpm()
4435 if (udev->usb2_hw_lpm_besl_capable) { in xhci_set_usb2_hardware_lpm()
4436 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4438 readl_poll_timeout(ports[port_num]->addr, pm_val, in xhci_set_usb2_hardware_lpm()
4445 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4459 for (i = 0; i < xhci->num_ext_caps; i++) { in xhci_check_usb2_port_capability()
4460 if (xhci->ext_caps[i] & capability) { in xhci_check_usb2_port_capability()
4462 port_offset = XHCI_EXT_PORT_OFF(xhci->ext_caps[i]) - 1; in xhci_check_usb2_port_capability()
4463 port_count = XHCI_EXT_PORT_COUNT(xhci->ext_caps[i]); in xhci_check_usb2_port_capability()
4475 int portnum = udev->portnum - 1; in xhci_update_device()
4477 if (hcd->speed >= HCD_USB3 || !udev->lpm_capable) in xhci_update_device()
4480 /* we only support lpm for non-hub device connected to root hub yet */ in xhci_update_device()
4481 if (!udev->parent || udev->parent->parent || in xhci_update_device()
4482 udev->descriptor.bDeviceClass == USB_CLASS_HUB) in xhci_update_device()
4485 if (xhci->hw_lpm_support == 1 && in xhci_update_device()
4488 udev->usb2_hw_lpm_capable = 1; in xhci_update_device()
4489 udev->l1_params.timeout = XHCI_L1_TIMEOUT; in xhci_update_device()
4490 udev->l1_params.besl = XHCI_DEFAULT_BESL; in xhci_update_device()
4493 udev->usb2_hw_lpm_besl_capable = 1; in xhci_update_device()
4499 /*---------------------- USB 3.0 Link PM functions ------------------------*/
4501 /* Service interval in nanoseconds = 2^(bInterval - 1) * 125us * 1000ns / 1us */
4505 return (1ULL << (desc->bInterval - 1)) * 125 * 1000; in xhci_service_interval_to_ns()
4519 sel = DIV_ROUND_UP(udev->u1_params.sel, 1000); in xhci_get_timeout_no_hub_lpm()
4520 pel = DIV_ROUND_UP(udev->u1_params.pel, 1000); in xhci_get_timeout_no_hub_lpm()
4525 sel = DIV_ROUND_UP(udev->u2_params.sel, 1000); in xhci_get_timeout_no_hub_lpm()
4526 pel = DIV_ROUND_UP(udev->u2_params.pel, 1000); in xhci_get_timeout_no_hub_lpm()
4531 dev_warn(&udev->dev, "%s: Can't get timeout for non-U1 or U2 state.\n", in xhci_get_timeout_no_hub_lpm()
4540 dev_dbg(&udev->dev, "Device-initiated %s disabled " in xhci_get_timeout_no_hub_lpm()
4544 dev_dbg(&udev->dev, "Device-initiated %s disabled " in xhci_get_timeout_no_hub_lpm()
4551 * - For control endpoints, U1 system exit latency (SEL) * 3
4552 * - For bulk endpoints, U1 SEL * 5
4553 * - For interrupt endpoints:
4554 * - Notification EPs, U1 SEL * 3
4555 * - Periodic EPs, max(105% of bInterval, U1 SEL * 2)
4556 * - For isochronous endpoints, max(105% of bInterval, U1 SEL * 2)
4569 timeout_ns = udev->u1_params.sel * 3; in xhci_calculate_intel_u1_timeout()
4572 timeout_ns = udev->u1_params.sel * 5; in xhci_calculate_intel_u1_timeout()
4577 timeout_ns = udev->u1_params.sel * 3; in xhci_calculate_intel_u1_timeout()
4585 if (timeout_ns < udev->u1_params.sel * 2) in xhci_calculate_intel_u1_timeout()
4586 timeout_ns = udev->u1_params.sel * 2; in xhci_calculate_intel_u1_timeout()
4595 /* Returns the hub-encoded U1 timeout value. */
4604 if (xhci_service_interval_to_ns(desc) <= udev->u1_params.mel) { in xhci_calculate_u1_timeout()
4605 dev_dbg(&udev->dev, "Disable U1, ESIT shorter than exit latency\n"); in xhci_calculate_u1_timeout()
4610 if (xhci->quirks & (XHCI_INTEL_HOST | XHCI_ZHAOXIN_HOST)) in xhci_calculate_u1_timeout()
4613 timeout_ns = udev->u1_params.sel; in xhci_calculate_u1_timeout()
4624 * USB 3.0 hub, we have to disable hub-initiated U1. in xhci_calculate_u1_timeout()
4628 dev_dbg(&udev->dev, "Hub-initiated U1 disabled " in xhci_calculate_u1_timeout()
4634 * - 10 ms (to avoid the bandwidth impact on the scheduler)
4635 * - largest bInterval of any active periodic endpoint (to avoid going
4637 * - the U2 Exit Latency of the device
4652 u2_del_ns = le16_to_cpu(udev->bos->ss_cap->bU2DevExitLat) * 1000ULL; in xhci_calculate_intel_u2_timeout()
4659 /* Returns the hub-encoded U2 timeout value. */
4668 if (xhci_service_interval_to_ns(desc) <= udev->u2_params.mel) { in xhci_calculate_u2_timeout()
4669 dev_dbg(&udev->dev, "Disable U2, ESIT shorter than exit latency\n"); in xhci_calculate_u2_timeout()
4674 if (xhci->quirks & (XHCI_INTEL_HOST | XHCI_ZHAOXIN_HOST)) in xhci_calculate_u2_timeout()
4677 timeout_ns = udev->u2_params.sel; in xhci_calculate_u2_timeout()
4682 * USB 3.0 hub, we have to disable hub-initiated U2. in xhci_calculate_u2_timeout()
4686 dev_dbg(&udev->dev, "Hub-initiated U2 disabled " in xhci_calculate_u2_timeout()
4716 /* If we found we can't enable hub-initiated LPM, and in xhci_update_timeout_for_endpoint()
4718 * device-initiated LPM as well, then we will disable LPM in xhci_update_timeout_for_endpoint()
4723 return -E2BIG; in xhci_update_timeout_for_endpoint()
4738 for (j = 0; j < alt->desc.bNumEndpoints; j++) { in xhci_update_timeout_for_interface()
4740 &alt->endpoint[j].desc, state, timeout)) in xhci_update_timeout_for_interface()
4741 return -E2BIG; in xhci_update_timeout_for_interface()
4750 struct usb_device *parent = udev->parent; in xhci_check_tier_policy()
4754 parent = parent->parent; in xhci_check_tier_policy()
4758 if (xhci->quirks & XHCI_INTEL_HOST && tier > 3) in xhci_check_tier_policy()
4760 if (xhci->quirks & XHCI_ZHAOXIN_HOST && tier > 2) in xhci_check_tier_policy()
4765 dev_dbg(&udev->dev, "Tier policy prevents U1/U2 LPM states for devices at tier %d\n", in xhci_check_tier_policy()
4767 return -E2BIG; in xhci_check_tier_policy()
4771 * If the tier check or timeout setting functions return with a non-zero exit
4789 dev_warn(&udev->dev, "Can't enable unknown link state %i\n", in xhci_calculate_lpm_timeout()
4797 if (xhci_update_timeout_for_endpoint(xhci, udev, &udev->ep0.desc, in xhci_calculate_lpm_timeout()
4801 config = udev->actconfig; in xhci_calculate_lpm_timeout()
4805 for (i = 0; i < config->desc.bNumInterfaces; i++) { in xhci_calculate_lpm_timeout()
4807 struct usb_interface *intf = config->interface[i]; in xhci_calculate_lpm_timeout()
4812 /* Check if any currently bound drivers want hub-initiated LPM in xhci_calculate_lpm_timeout()
4815 if (intf->dev.driver) { in xhci_calculate_lpm_timeout()
4816 driver = to_usb_driver(intf->dev.driver); in xhci_calculate_lpm_timeout()
4817 if (driver && driver->disable_hub_initiated_lpm) { in xhci_calculate_lpm_timeout()
4818 dev_dbg(&udev->dev, "Hub-initiated %s disabled at request of driver %s\n", in xhci_calculate_lpm_timeout()
4819 state_name, driver->name); in xhci_calculate_lpm_timeout()
4828 if (!intf->cur_altsetting) in xhci_calculate_lpm_timeout()
4832 intf->cur_altsetting, in xhci_calculate_lpm_timeout()
4864 if ((udev->u1_params.timeout != USB3_LPM_DISABLED && !disabling_u1) || in calculate_max_exit_latency()
4866 u1_mel_us = DIV_ROUND_UP(udev->u1_params.mel, 1000); in calculate_max_exit_latency()
4867 if ((udev->u2_params.timeout != USB3_LPM_DISABLED && !disabling_u2) || in calculate_max_exit_latency()
4869 u2_mel_us = DIV_ROUND_UP(udev->u2_params.mel, 1000); in calculate_max_exit_latency()
4875 dev_warn(&udev->dev, "Link PM max exit latency of %lluus " in calculate_max_exit_latency()
4877 return -E2BIG; in calculate_max_exit_latency()
4882 /* Returns the USB3 hub-encoded value for the U1/U2 timeout. */
4893 /* The LPM timeout values are pretty host-controller specific, so don't in xhci_enable_usb3_lpm_timeout()
4894 * enable hub-initiated timeouts unless the vendor has provided in xhci_enable_usb3_lpm_timeout()
4897 if (!xhci || !(xhci->quirks & XHCI_LPM_SUPPORT) || in xhci_enable_usb3_lpm_timeout()
4898 !xhci->devs[udev->slot_id]) in xhci_enable_usb3_lpm_timeout()
4905 if (udev->parent && !udev->parent->parent) { in xhci_enable_usb3_lpm_timeout()
4906 port = xhci->usb3_rhub.ports[udev->portnum - 1]; in xhci_enable_usb3_lpm_timeout()
4907 if (port->lpm_incapable) in xhci_enable_usb3_lpm_timeout()
4932 if (!xhci || !(xhci->quirks & XHCI_LPM_SUPPORT) || in xhci_disable_usb3_lpm_timeout()
4933 !xhci->devs[udev->slot_id]) in xhci_disable_usb3_lpm_timeout()
4965 /*-------------------------------------------------------------------------*/
4983 if (!hdev->parent) in xhci_update_hub_device()
4986 vdev = xhci->devs[hdev->slot_id]; in xhci_update_hub_device()
4989 return -EINVAL; in xhci_update_hub_device()
4994 return -ENOMEM; in xhci_update_hub_device()
4996 ctrl_ctx = xhci_get_input_control_ctx(config_cmd->in_ctx); in xhci_update_hub_device()
5001 return -ENOMEM; in xhci_update_hub_device()
5004 spin_lock_irqsave(&xhci->lock, flags); in xhci_update_hub_device()
5005 if (hdev->speed == USB_SPEED_HIGH && in xhci_update_hub_device()
5009 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_update_hub_device()
5010 return -ENOMEM; in xhci_update_hub_device()
5013 xhci_slot_copy(xhci, config_cmd->in_ctx, vdev->out_ctx); in xhci_update_hub_device()
5014 ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG); in xhci_update_hub_device()
5015 slot_ctx = xhci_get_slot_ctx(xhci, config_cmd->in_ctx); in xhci_update_hub_device()
5016 slot_ctx->dev_info |= cpu_to_le32(DEV_HUB); in xhci_update_hub_device()
5022 if (tt->multi) in xhci_update_hub_device()
5023 slot_ctx->dev_info |= cpu_to_le32(DEV_MTT); in xhci_update_hub_device()
5024 else if (hdev->speed == USB_SPEED_FULL) in xhci_update_hub_device()
5025 slot_ctx->dev_info &= cpu_to_le32(~DEV_MTT); in xhci_update_hub_device()
5027 if (xhci->hci_version > 0x95) { in xhci_update_hub_device()
5030 (unsigned int) xhci->hci_version); in xhci_update_hub_device()
5031 slot_ctx->dev_info2 |= cpu_to_le32(XHCI_MAX_PORTS(hdev->maxchild)); in xhci_update_hub_device()
5032 /* Set TT think time - convert from ns to FS bit times. in xhci_update_hub_device()
5037 * High-spped hub. in xhci_update_hub_device()
5039 think_time = tt->think_time; in xhci_update_hub_device()
5041 think_time = (think_time / 666) - 1; in xhci_update_hub_device()
5042 if (xhci->hci_version < 0x100 || hdev->speed == USB_SPEED_HIGH) in xhci_update_hub_device()
5043 slot_ctx->tt_info |= in xhci_update_hub_device()
5048 (unsigned int) xhci->hci_version); in xhci_update_hub_device()
5050 slot_ctx->dev_state = 0; in xhci_update_hub_device()
5051 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_update_hub_device()
5054 (xhci->hci_version > 0x95) ? in xhci_update_hub_device()
5060 if (xhci->hci_version > 0x95) in xhci_update_hub_device()
5076 return readl(&xhci->run_regs->microframe_index) >> 3; in xhci_get_frame()
5081 xhci->usb2_rhub.hcd = hcd; in xhci_hcd_init_usb2_data()
5082 hcd->speed = HCD_USB2; in xhci_hcd_init_usb2_data()
5083 hcd->self.root_hub->speed = USB_SPEED_HIGH; in xhci_hcd_init_usb2_data()
5089 hcd->has_tt = 1; in xhci_hcd_init_usb2_data()
5099 * is a two digit BCD containig minor and sub-minor numbers. in xhci_hcd_init_usb3_data()
5105 if (xhci->usb3_rhub.min_rev == 0x1) in xhci_hcd_init_usb3_data()
5108 minor_rev = xhci->usb3_rhub.min_rev / 0x10; in xhci_hcd_init_usb3_data()
5112 hcd->speed = HCD_USB32; in xhci_hcd_init_usb3_data()
5113 hcd->self.root_hub->speed = USB_SPEED_SUPER_PLUS; in xhci_hcd_init_usb3_data()
5114 hcd->self.root_hub->rx_lanes = 2; in xhci_hcd_init_usb3_data()
5115 hcd->self.root_hub->tx_lanes = 2; in xhci_hcd_init_usb3_data()
5116 hcd->self.root_hub->ssp_rate = USB_SSP_GEN_2x2; in xhci_hcd_init_usb3_data()
5119 hcd->speed = HCD_USB31; in xhci_hcd_init_usb3_data()
5120 hcd->self.root_hub->speed = USB_SPEED_SUPER_PLUS; in xhci_hcd_init_usb3_data()
5121 hcd->self.root_hub->ssp_rate = USB_SSP_GEN_2x1; in xhci_hcd_init_usb3_data()
5127 xhci->usb3_rhub.hcd = hcd; in xhci_hcd_init_usb3_data()
5137 struct device *dev = hcd->self.sysdev; in xhci_gen_setup()
5140 /* Accept arbitrarily long scatter-gather lists */ in xhci_gen_setup()
5141 hcd->self.sg_tablesize = ~0; in xhci_gen_setup()
5144 hcd->self.no_sg_constraint = 1; in xhci_gen_setup()
5147 hcd->self.no_stop_on_short = 1; in xhci_gen_setup()
5156 mutex_init(&xhci->mutex); in xhci_gen_setup()
5157 xhci->main_hcd = hcd; in xhci_gen_setup()
5158 xhci->cap_regs = hcd->regs; in xhci_gen_setup()
5159 xhci->op_regs = hcd->regs + in xhci_gen_setup()
5160 HC_LENGTH(readl(&xhci->cap_regs->hc_capbase)); in xhci_gen_setup()
5161 xhci->run_regs = hcd->regs + in xhci_gen_setup()
5162 (readl(&xhci->cap_regs->run_regs_off) & RTSOFF_MASK); in xhci_gen_setup()
5163 /* Cache read-only capability registers */ in xhci_gen_setup()
5164 xhci->hcs_params1 = readl(&xhci->cap_regs->hcs_params1); in xhci_gen_setup()
5165 xhci->hcs_params2 = readl(&xhci->cap_regs->hcs_params2); in xhci_gen_setup()
5166 xhci->hcs_params3 = readl(&xhci->cap_regs->hcs_params3); in xhci_gen_setup()
5167 xhci->hci_version = HC_VERSION(readl(&xhci->cap_regs->hc_capbase)); in xhci_gen_setup()
5168 xhci->hcc_params = readl(&xhci->cap_regs->hcc_params); in xhci_gen_setup()
5169 if (xhci->hci_version > 0x100) in xhci_gen_setup()
5170 xhci->hcc_params2 = readl(&xhci->cap_regs->hcc_params2); in xhci_gen_setup()
5172 /* xhci-plat or xhci-pci might have set max_interrupters already */ in xhci_gen_setup()
5173 if ((!xhci->max_interrupters) || in xhci_gen_setup()
5174 xhci->max_interrupters > HCS_MAX_INTRS(xhci->hcs_params1)) in xhci_gen_setup()
5175 xhci->max_interrupters = HCS_MAX_INTRS(xhci->hcs_params1); in xhci_gen_setup()
5177 xhci->quirks |= quirks; in xhci_gen_setup()
5186 if (xhci->hci_version > 0x96) in xhci_gen_setup()
5187 xhci->quirks |= XHCI_SPURIOUS_SUCCESS; in xhci_gen_setup()
5204 * On some xHCI controllers (e.g. R-Car SoCs), the AC64 bit (bit 0) in xhci_gen_setup()
5205 * of HCCPARAMS1 is set to 1. However, the xHCs don't support 64-bit in xhci_gen_setup()
5207 * bit of xhci->hcc_params to call dma_set_coherent_mask(dev, in xhci_gen_setup()
5210 if (xhci->quirks & XHCI_NO_64BIT_SUPPORT) in xhci_gen_setup()
5211 xhci->hcc_params &= ~BIT(0); in xhci_gen_setup()
5213 /* Set dma_mask and coherent_dma_mask to 64-bits, in xhci_gen_setup()
5214 * if xHC supports 64-bit addressing */ in xhci_gen_setup()
5215 if (HCC_64BIT_ADDR(xhci->hcc_params) && in xhci_gen_setup()
5217 xhci_dbg(xhci, "Enabling 64-bit DMA addresses.\n"); in xhci_gen_setup()
5221 * This is to avoid error in cases where a 32-bit USB in xhci_gen_setup()
5222 * controller is used on a 64-bit capable system. in xhci_gen_setup()
5227 xhci_dbg(xhci, "Enabling 32-bit DMA addresses.\n"); in xhci_gen_setup()
5244 xhci->hcc_params, xhci->hci_version, xhci->quirks); in xhci_gen_setup()
5261 spin_lock_irqsave(&xhci->lock, flags); in xhci_clear_tt_buffer_complete()
5262 udev = (struct usb_device *)ep->hcpriv; in xhci_clear_tt_buffer_complete()
5263 slot_id = udev->slot_id; in xhci_clear_tt_buffer_complete()
5264 ep_index = xhci_get_endpoint_index(&ep->desc); in xhci_clear_tt_buffer_complete()
5266 xhci->devs[slot_id]->eps[ep_index].ep_state &= ~EP_CLEARING_TT; in xhci_clear_tt_buffer_complete()
5268 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_clear_tt_buffer_complete()
5272 .description = "xhci-hcd",
5347 drv->hcd_priv_size += over->extra_priv_size; in xhci_init_driver()
5348 if (over->reset) in xhci_init_driver()
5349 drv->reset = over->reset; in xhci_init_driver()
5350 if (over->start) in xhci_init_driver()
5351 drv->start = over->start; in xhci_init_driver()
5352 if (over->add_endpoint) in xhci_init_driver()
5353 drv->add_endpoint = over->add_endpoint; in xhci_init_driver()
5354 if (over->drop_endpoint) in xhci_init_driver()
5355 drv->drop_endpoint = over->drop_endpoint; in xhci_init_driver()
5356 if (over->check_bandwidth) in xhci_init_driver()
5357 drv->check_bandwidth = over->check_bandwidth; in xhci_init_driver()
5358 if (over->reset_bandwidth) in xhci_init_driver()
5359 drv->reset_bandwidth = over->reset_bandwidth; in xhci_init_driver()
5360 if (over->update_hub_device) in xhci_init_driver()
5361 drv->update_hub_device = over->update_hub_device; in xhci_init_driver()
5362 if (over->hub_control) in xhci_init_driver()
5363 drv->hub_control = over->hub_control; in xhci_init_driver()
5393 return -ENODEV; in xhci_hcd_init()