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

1 // SPDX-License-Identifier: GPL-2.0+
7 * Copyright (c) 2000-2004 by David Brownell
27 #include <linux/dma-mapping.h>
41 /*-------------------------------------------------------------------------*/
53 * test this driver on, and Cypress (including In-System Design) for
66 #define EHCI_TUNE_CERR 3 /* 0-3 qtd retries; 0 == don't stop */
69 #define EHCI_TUNE_MULT_HS 1 /* 1-3 transactions/uframe; 4.10.3 */
77 #define EHCI_TUNE_FLS 1 /* (medium) 512-frame schedule */
82 MODULE_PARM_DESC (log2_irq_thresh, "log2 IRQ latency, 1-64 microframes");
87 MODULE_PARM_DESC (park, "park setting; 1-3 back-to-back async packets");
96 /*-------------------------------------------------------------------------*/
99 #include "pci-quirks.h"
102 struct ehci_tt *tt);
108 * microframe number (the low-order 3 bits); if they are 0 then
109 * re-read the register to get the correct value.
115 uf = ehci_readl(ehci, &ehci->regs->frame_index); in ehci_moschip_read_frame_index()
117 uf = ehci_readl(ehci, &ehci->regs->frame_index); in ehci_moschip_read_frame_index()
123 if (ehci->frame_index_bug) in ehci_read_frame_index()
125 return ehci_readl(ehci, &ehci->regs->frame_index); in ehci_read_frame_index()
128 #include "ehci-dbg.c"
130 /*-------------------------------------------------------------------------*/
133 * ehci_handshake - spin reading hc until handshake completes or fails
143 * hardware flakeout), or the register reads as all-ones (hardware removed).
157 return -ENODEV; in ehci_handshake()
162 usec--; in ehci_handshake()
164 return -ETIMEDOUT; in ehci_handshake()
173 tmp = ehci_readl(ehci, &ehci->regs->usbmode); in tdi_in_host_mode()
185 spin_lock_irq(&ehci->lock); in ehci_halt()
188 ehci_writel(ehci, 0, &ehci->regs->intr_enable); in ehci_halt()
191 spin_unlock_irq(&ehci->lock); in ehci_halt()
196 * This routine gets called during probe before ehci->command in ehci_halt()
199 ehci->command &= ~CMD_RUN; in ehci_halt()
200 temp = ehci_readl(ehci, &ehci->regs->command); in ehci_halt()
202 ehci_writel(ehci, temp, &ehci->regs->command); in ehci_halt()
204 spin_unlock_irq(&ehci->lock); in ehci_halt()
205 synchronize_irq(ehci_to_hcd(ehci)->irq); in ehci_halt()
207 return ehci_handshake(ehci, &ehci->regs->status, in ehci_halt()
216 tmp = ehci_readl(ehci, &ehci->regs->usbmode); in tdi_reset()
224 ehci_writel(ehci, tmp, &ehci->regs->usbmode); in tdi_reset()
228 * Reset a non-running (STS_HALT == 1) controller.
234 u32 command = ehci_readl(ehci, &ehci->regs->command); in ehci_reset()
238 if (ehci->debug && !dbgp_reset_prep(ehci_to_hcd(ehci))) in ehci_reset()
239 ehci->debug = NULL; in ehci_reset()
243 ehci_writel(ehci, command, &ehci->regs->command); in ehci_reset()
244 ehci->rh_state = EHCI_RH_HALTED; in ehci_reset()
245 ehci->next_statechange = jiffies; in ehci_reset()
246 retval = ehci_handshake(ehci, &ehci->regs->command, in ehci_reset()
249 if (ehci->has_hostpc) { in ehci_reset()
251 &ehci->regs->usbmode_ex); in ehci_reset()
252 ehci_writel(ehci, TXFIFO_DEFAULT, &ehci->regs->txfill_tuning); in ehci_reset()
260 if (ehci->debug) in ehci_reset()
263 ehci->port_c_suspend = ehci->suspended_ports = in ehci_reset()
264 ehci->resuming_ports = 0; in ehci_reset()
277 if (ehci->rh_state != EHCI_RH_RUNNING) in ehci_quiesce()
281 temp = (ehci->command << 10) & (STS_ASS | STS_PSS); in ehci_quiesce()
282 ehci_handshake(ehci, &ehci->regs->status, STS_ASS | STS_PSS, temp, in ehci_quiesce()
286 spin_lock_irq(&ehci->lock); in ehci_quiesce()
287 ehci->command &= ~(CMD_ASE | CMD_PSE); in ehci_quiesce()
288 ehci_writel(ehci, ehci->command, &ehci->regs->command); in ehci_quiesce()
289 spin_unlock_irq(&ehci->lock); in ehci_quiesce()
292 ehci_handshake(ehci, &ehci->regs->status, STS_ASS | STS_PSS, 0, in ehci_quiesce()
296 /*-------------------------------------------------------------------------*/
306 #include "ehci-timer.c"
307 #include "ehci-hub.c"
308 #include "ehci-mem.c"
309 #include "ehci-q.c"
310 #include "ehci-sched.c"
311 #include "ehci-sysfs.c"
313 /*-------------------------------------------------------------------------*/
321 int port = HCS_N_PORTS(ehci->hcs_params); in ehci_turn_off_all_ports()
323 while (port--) { in ehci_turn_off_all_ports()
324 spin_unlock_irq(&ehci->lock); in ehci_turn_off_all_ports()
326 spin_lock_irq(&ehci->lock); in ehci_turn_off_all_ports()
328 &ehci->regs->port_status[port]); in ehci_turn_off_all_ports()
340 spin_lock_irq(&ehci->lock); in ehci_silence_controller()
341 ehci->rh_state = EHCI_RH_HALTED; in ehci_silence_controller()
345 ehci_writel(ehci, 0, &ehci->regs->configured_flag); in ehci_silence_controller()
348 ehci_readl(ehci, &ehci->regs->configured_flag); in ehci_silence_controller()
349 spin_unlock_irq(&ehci->lock); in ehci_silence_controller()
366 if (!ehci->sbrn) in ehci_shutdown()
369 spin_lock_irq(&ehci->lock); in ehci_shutdown()
370 ehci->shutdown = true; in ehci_shutdown()
371 ehci->rh_state = EHCI_RH_STOPPING; in ehci_shutdown()
372 ehci->enabled_hrtimer_events = 0; in ehci_shutdown()
373 spin_unlock_irq(&ehci->lock); in ehci_shutdown()
377 hrtimer_cancel(&ehci->hrtimer); in ehci_shutdown()
380 /*-------------------------------------------------------------------------*/
384 * it calls driver completion functions, after dropping ehci->lock.
388 /* another CPU may drop ehci->lock during a schedule scan while in ehci_work()
390 * attempts at re-entrant schedule scanning. in ehci_work()
392 if (ehci->scanning) { in ehci_work()
393 ehci->need_rescan = true; in ehci_work()
396 ehci->scanning = true; in ehci_work()
399 ehci->need_rescan = false; in ehci_work()
400 if (ehci->async_count) in ehci_work()
402 if (ehci->intr_count > 0) in ehci_work()
404 if (ehci->isoc_count > 0) in ehci_work()
406 if (ehci->need_rescan) in ehci_work()
408 ehci->scanning = false; in ehci_work()
428 spin_lock_irq(&ehci->lock); in ehci_stop()
429 ehci->enabled_hrtimer_events = 0; in ehci_stop()
430 spin_unlock_irq(&ehci->lock); in ehci_stop()
436 hrtimer_cancel(&ehci->hrtimer); in ehci_stop()
441 spin_lock_irq (&ehci->lock); in ehci_stop()
443 spin_unlock_irq (&ehci->lock); in ehci_stop()
446 if (ehci->amd_pll_fix == 1) in ehci_stop()
450 ehci_readl(ehci, &ehci->regs->status)); in ehci_stop()
453 /* one-time init, only for memory state */
462 spin_lock_init(&ehci->lock); in ehci_init()
467 ehci->need_io_watchdog = 1; in ehci_init()
469 hrtimer_init(&ehci->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); in ehci_init()
470 ehci->hrtimer.function = ehci_hrtimer_func; in ehci_init()
471 ehci->next_hrtimer_event = EHCI_HRTIMER_NO_EVENT; in ehci_init()
473 hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params); in ehci_init()
479 ehci->uframe_periodic_max = 100; in ehci_init()
485 ehci->periodic_size = DEFAULT_I_TDPS; in ehci_init()
486 INIT_LIST_HEAD(&ehci->async_unlink); in ehci_init()
487 INIT_LIST_HEAD(&ehci->async_idle); in ehci_init()
488 INIT_LIST_HEAD(&ehci->intr_unlink_wait); in ehci_init()
489 INIT_LIST_HEAD(&ehci->intr_unlink); in ehci_init()
490 INIT_LIST_HEAD(&ehci->intr_qh_list); in ehci_init()
491 INIT_LIST_HEAD(&ehci->cached_itd_list); in ehci_init()
492 INIT_LIST_HEAD(&ehci->cached_sitd_list); in ehci_init()
493 INIT_LIST_HEAD(&ehci->tt_list); in ehci_init()
498 case 0: ehci->periodic_size = 1024; break; in ehci_init()
499 case 1: ehci->periodic_size = 512; break; in ehci_init()
500 case 2: ehci->periodic_size = 256; break; in ehci_init()
509 ehci->i_thresh = 0; in ehci_init()
511 ehci->i_thresh = 2 + HCC_ISOC_THRES(hcc_params); in ehci_init()
520 ehci->async->qh_next.qh = NULL; in ehci_init()
521 hw = ehci->async->hw; in ehci_init()
522 hw->hw_next = QH_NEXT(ehci, ehci->async->qh_dma); in ehci_init()
523 hw->hw_info1 = cpu_to_hc32(ehci, QH_HEAD); in ehci_init()
525 hw->hw_info1 |= cpu_to_hc32(ehci, QH_INACTIVATE); in ehci_init()
527 hw->hw_token = cpu_to_hc32(ehci, QTD_STS_HALT); in ehci_init()
528 hw->hw_qtd_next = EHCI_LIST_END(ehci); in ehci_init()
529 ehci->async->qh_state = QH_STATE_LINKED; in ehci_init()
530 hw->hw_alt_next = QTD_NEXT(ehci, ehci->async->dummy->qtd_dma); in ehci_init()
537 ehci->has_ppcd = 1; in ehci_init()
538 ehci_dbg(ehci, "enable per-port change event\n"); in ehci_init()
561 ehci->command = temp; in ehci_init()
563 /* Accept arbitrarily long scatter-gather lists */ in ehci_init()
564 if (!hcd->localmem_pool) in ehci_init()
565 hcd->self.sg_tablesize = ~0; in ehci_init()
568 ehci->old_current = ~0; in ehci_init()
580 hcd->uses_new_polling = 1; in ehci_run()
584 ehci_writel(ehci, ehci->periodic_dma, &ehci->regs->frame_list); in ehci_run()
585 ehci_writel(ehci, (u32)ehci->async->qh_dma, &ehci->regs->async_next); in ehci_run()
588 * hcc_params controls whether ehci->regs->segment must (!!!) in ehci_run()
594 * NOTE: the dma mask is visible through dev->dma_mask, so in ehci_run()
599 hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params); in ehci_run()
601 ehci_writel(ehci, 0, &ehci->regs->segment); in ehci_run()
604 if (!dma_set_mask(hcd->self.controller, DMA_BIT_MASK(64))) in ehci_run()
612 ehci->command &= ~(CMD_LRESET|CMD_IAAD|CMD_PSE|CMD_ASE|CMD_RESET); in ehci_run()
613 ehci->command |= CMD_RUN; in ehci_run()
614 ehci_writel(ehci, ehci->command, &ehci->regs->command); in ehci_run()
615 dbg_cmd (ehci, "init", ehci->command); in ehci_run()
619 * are explicitly handed to companion controller(s), so no TT is in ehci_run()
626 * could cause trouble. Write-locking ehci_cf_port_reset_rwsem in ehci_run()
632 ehci->rh_state = EHCI_RH_RUNNING; in ehci_run()
633 ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag); in ehci_run()
636 ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */ in ehci_run()
642 if (ehci->is_aspeed) in ehci_run()
643 rc = ehci_handshake(ehci, &ehci->regs->command, CMD_RUN, in ehci_run()
646 rc = ehci_handshake(ehci, &ehci->regs->status, STS_HALT, in ehci_run()
653 ((ehci->sbrn & 0xf0)>>4), (ehci->sbrn & 0x0f), rc); in ehci_run()
657 ehci->last_periodic_enable = ktime_get_real(); in ehci_run()
659 temp = HC_VERSION(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase)); in ehci_run()
662 ((ehci->sbrn & 0xf0)>>4), (ehci->sbrn & 0x0f), in ehci_run()
664 (ignore_oc || ehci->spurious_oc) ? ", overcurrent ignored" : ""); in ehci_run()
667 &ehci->regs->intr_enable); /* Turn On Interrupts */ in ehci_run()
669 /* GRR this is run-once init(), being done every time the HC starts. in ehci_run()
684 ehci->regs = (void __iomem *)ehci->caps + in ehci_setup()
685 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase)); in ehci_setup()
690 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); in ehci_setup()
692 ehci->sbrn = HCD_USB2; in ehci_setup()
711 /*-------------------------------------------------------------------------*/
720 spin_lock(&ehci->lock); in ehci_irq()
723 current_status = ehci_readl(ehci, &ehci->regs->status); in ehci_irq()
740 if (!masked_status || unlikely(ehci->rh_state == EHCI_RH_HALTED)) { in ehci_irq()
741 spin_unlock(&ehci->lock); in ehci_irq()
746 ehci_writel(ehci, masked_status, &ehci->regs->status); in ehci_irq()
749 current_status = ehci_readl(ehci, &ehci->regs->status); in ehci_irq()
753 cmd = ehci_readl(ehci, &ehci->regs->command); in ehci_irq()
759 INCR(ehci->stats.normal); in ehci_irq()
762 if (ehci->has_ci_pec_bug) in ehci_irq()
764 INCR(ehci->stats.error); in ehci_irq()
773 ehci->enabled_hrtimer_events &= ~BIT(EHCI_HRTIMER_IAA_WATCHDOG); in ehci_irq()
782 if (ehci->next_hrtimer_event == EHCI_HRTIMER_IAA_WATCHDOG) in ehci_irq()
783 ++ehci->next_hrtimer_event; in ehci_irq()
788 if (ehci->iaa_in_progress) in ehci_irq()
789 INCR(ehci->stats.iaa); in ehci_irq()
795 unsigned i = HCS_N_PORTS (ehci->hcs_params); in ehci_irq()
802 if (ehci->rh_state == EHCI_RH_SUSPENDED) in ehci_irq()
805 /* get per-port change detect bits */ in ehci_irq()
806 if (ehci->has_ppcd) in ehci_irq()
809 while (i--) { in ehci_irq()
812 /* leverage per-port change bits feature */ in ehci_irq()
816 &ehci->regs->port_status[i]); in ehci_irq()
820 if (!(test_bit(i, &ehci->suspended_ports) && in ehci_irq()
824 ehci->reset_done[i] == 0)) in ehci_irq()
831 ehci->reset_done[i] = jiffies + in ehci_irq()
833 set_bit(i, &ehci->resuming_ports); in ehci_irq()
835 usb_hcd_start_port_resume(&hcd->self, i); in ehci_irq()
836 mod_timer(&hcd->rh_timer, ehci->reset_done[i]); in ehci_irq()
849 ehci->shutdown = true; in ehci_irq()
850 ehci->rh_state = EHCI_RH_STOPPING; in ehci_irq()
851 ehci->command &= ~(CMD_RUN | CMD_ASE | CMD_PSE); in ehci_irq()
852 ehci_writel(ehci, ehci->command, &ehci->regs->command); in ehci_irq()
853 ehci_writel(ehci, 0, &ehci->regs->intr_enable); in ehci_irq()
862 spin_unlock(&ehci->lock); in ehci_irq()
868 /*-------------------------------------------------------------------------*/
871 * non-error returns are a promise to giveback() the urb later
877 * hcd-specific init for hcpriv hasn't been done yet
892 switch (usb_pipetype (urb->pipe)) { in ehci_urb_enqueue()
895 * in multi-TD control transfers. Even 1KB is rare anyway. in ehci_urb_enqueue()
897 if (urb->transfer_buffer_length > (16 * 1024)) in ehci_urb_enqueue()
898 return -EMSGSIZE; in ehci_urb_enqueue()
903 return -ENOMEM; in ehci_urb_enqueue()
908 return -ENOMEM; in ehci_urb_enqueue()
912 if (urb->dev->speed == USB_SPEED_HIGH) in ehci_urb_enqueue()
930 spin_lock_irqsave (&ehci->lock, flags); in ehci_urb_dequeue()
935 if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) { in ehci_urb_dequeue()
942 qh = (struct ehci_qh *) urb->hcpriv; in ehci_urb_dequeue()
943 qh->unlink_reason |= QH_UNLINK_REQUESTED; in ehci_urb_dequeue()
944 switch (qh->qh_state) { in ehci_urb_dequeue()
946 if (usb_pipetype(urb->pipe) == PIPE_INTERRUPT) in ehci_urb_dequeue()
952 qh->dequeue_during_giveback = 1; in ehci_urb_dequeue()
959 /* QH might be waiting for a Clear-TT-Buffer */ in ehci_urb_dequeue()
965 spin_unlock_irqrestore (&ehci->lock, flags); in ehci_urb_dequeue()
969 /*-------------------------------------------------------------------------*/
984 spin_lock_irqsave (&ehci->lock, flags); in ehci_endpoint_disable()
985 qh = ep->hcpriv; in ehci_endpoint_disable()
992 if (qh->hw == NULL) { in ehci_endpoint_disable()
993 struct ehci_iso_stream *stream = ep->hcpriv; in ehci_endpoint_disable()
995 if (!list_empty(&stream->td_list)) in ehci_endpoint_disable()
998 /* BUG_ON(!list_empty(&stream->free_list)); */ in ehci_endpoint_disable()
999 reserve_release_iso_bandwidth(ehci, stream, -1); in ehci_endpoint_disable()
1004 qh->unlink_reason |= QH_UNLINK_REQUESTED; in ehci_endpoint_disable()
1005 switch (qh->qh_state) { in ehci_endpoint_disable()
1007 if (list_empty(&qh->qtd_list)) in ehci_endpoint_disable()
1008 qh->unlink_reason |= QH_UNLINK_QUEUE_EMPTY; in ehci_endpoint_disable()
1011 if (usb_endpoint_type(&ep->desc) != USB_ENDPOINT_XFER_INT) in ehci_endpoint_disable()
1020 spin_unlock_irqrestore (&ehci->lock, flags); in ehci_endpoint_disable()
1024 if (qh->clearing_tt) in ehci_endpoint_disable()
1026 if (list_empty (&qh->qtd_list)) { in ehci_endpoint_disable()
1027 if (qh->ps.bw_uperiod) in ehci_endpoint_disable()
1028 reserve_release_intr_bandwidth(ehci, qh, -1); in ehci_endpoint_disable()
1038 qh, ep->desc.bEndpointAddress, qh->qh_state, in ehci_endpoint_disable()
1039 list_empty (&qh->qtd_list) ? "" : "(has tds)"); in ehci_endpoint_disable()
1043 ep->hcpriv = NULL; in ehci_endpoint_disable()
1044 spin_unlock_irqrestore (&ehci->lock, flags); in ehci_endpoint_disable()
1052 int eptype = usb_endpoint_type(&ep->desc); in ehci_endpoint_reset()
1053 int epnum = usb_endpoint_num(&ep->desc); in ehci_endpoint_reset()
1054 int is_out = usb_endpoint_dir_out(&ep->desc); in ehci_endpoint_reset()
1060 spin_lock_irqsave(&ehci->lock, flags); in ehci_endpoint_reset()
1061 qh = ep->hcpriv; in ehci_endpoint_reset()
1069 if (!list_empty(&qh->qtd_list)) { in ehci_endpoint_reset()
1074 * re-linking will call qh_refresh(). in ehci_endpoint_reset()
1076 usb_settoggle(qh->ps.udev, epnum, is_out, 0); in ehci_endpoint_reset()
1077 qh->unlink_reason |= QH_UNLINK_REQUESTED; in ehci_endpoint_reset()
1084 spin_unlock_irqrestore(&ehci->lock, flags); in ehci_endpoint_reset()
1090 return (ehci_read_frame_index(ehci) >> 3) % ehci->periodic_size; in ehci_get_frame()
1093 /*-------------------------------------------------------------------------*/
1101 spin_lock_irq(&ehci->lock); in ehci_remove_device()
1103 spin_unlock_irq(&ehci->lock); in ehci_remove_device()
1106 /*-------------------------------------------------------------------------*/
1113 u32 __iomem *reg = &ehci->regs->port_status[4]; in ehci_zx_wakeup_clear()
1138 if (time_before(jiffies, ehci->next_statechange)) in ehci_suspend()
1148 spin_lock_irq(&ehci->lock); in ehci_suspend()
1149 ehci_writel(ehci, 0, &ehci->regs->intr_enable); in ehci_suspend()
1150 (void) ehci_readl(ehci, &ehci->regs->intr_enable); in ehci_suspend()
1152 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); in ehci_suspend()
1153 spin_unlock_irq(&ehci->lock); in ehci_suspend()
1155 synchronize_irq(hcd->irq); in ehci_suspend()
1160 return -EBUSY; in ehci_suspend()
1172 if (time_before(jiffies, ehci->next_statechange)) in ehci_resume()
1176 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); in ehci_resume()
1178 if (ehci->shutdown) in ehci_resume()
1181 if (ehci->zx_wakeup_clear_needed) in ehci_resume()
1189 if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF && in ehci_resume()
1195 spin_lock_irq(&ehci->lock); in ehci_resume()
1196 if (ehci->shutdown) in ehci_resume()
1199 if (!hcd->self.root_hub->do_remote_wakeup) in ehci_resume()
1201 ehci_writel(ehci, mask, &ehci->regs->intr_enable); in ehci_resume()
1202 ehci_readl(ehci, &ehci->regs->intr_enable); in ehci_resume()
1204 spin_unlock_irq(&ehci->lock); in ehci_resume()
1212 usb_root_hub_lost_power(hcd->self.root_hub); in ehci_resume()
1216 spin_lock_irq(&ehci->lock); in ehci_resume()
1217 if (ehci->shutdown) in ehci_resume()
1220 ehci_writel(ehci, ehci->command, &ehci->regs->command); in ehci_resume()
1221 ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag); in ehci_resume()
1222 ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */ in ehci_resume()
1224 ehci->rh_state = EHCI_RH_SUSPENDED; in ehci_resume()
1225 spin_unlock_irq(&ehci->lock); in ehci_resume()
1233 /*-------------------------------------------------------------------------*/
1301 drv->hcd_priv_size += over->extra_priv_size; in ehci_init_driver()
1302 if (over->reset) in ehci_init_driver()
1303 drv->reset = over->reset; in ehci_init_driver()
1304 if (over->port_power) in ehci_init_driver()
1305 drv->port_power = over->port_power; in ehci_init_driver()
1310 /*-------------------------------------------------------------------------*/
1317 #include "ehci-sh.c"
1321 #include "ehci-ps3.c"
1325 #include "ehci-ppc-of.c"
1329 #include "ehci-xilinx-of.c"
1333 #include "ehci-grlib.c"
1356 return -ENODEV; in ehci_hcd_init()