Lines Matching +full:hird +full:- +full:threshold
1 // SPDX-License-Identifier: GPL-2.0+
2 /* Faraday FOTG210 EHCI-like driver
6 * Author: Yuan-Hsin Chen <yhchen@faraday-tech.com>
7 * Feng-Hsin Chiang <john453@faraday-tech.com>
8 * Po-Yu Chuang <ratbert.chuang@gmail.com>
10 * Most of code borrowed from the Linux-3.7 EHCI driver
29 #include <linux/dma-mapping.h>
49 #define FOTG210_TUNE_CERR 3 /* 0-3 qtd retries; 0 == don't stop */
52 #define FOTG210_TUNE_MULT_HS 1 /* 1-3 transactions/uframe; 4.10.3 */
60 #define FOTG210_TUNE_FLS 1 /* (medium) 512-frame schedule */
65 MODULE_PARM_DESC(log2_irq_thresh, "log2 IRQ latency, 1-64 microframes");
70 MODULE_PARM_DESC(park, "park setting; 1-3 back-to-back async packets");
73 static unsigned int hird;
74 module_param(hird, int, S_IRUGO);
75 MODULE_PARM_DESC(hird, "host initiated resume duration, +1 for each 75us");
79 #include "fotg210-hcd.h"
82 dev_dbg(fotg210_to_hcd(fotg210)->self.controller, fmt, ## args)
84 dev_err(fotg210_to_hcd(fotg210)->self.controller, fmt, ## args)
86 dev_info(fotg210_to_hcd(fotg210)->self.controller, fmt, ## args)
88 dev_warn(fotg210_to_hcd(fotg210)->self.controller, fmt, ## args)
91 * parameters) see EHCI spec, Table 2-4 for each value
95 u32 params = fotg210_readl(fotg210, &fotg210->caps->hcs_params);
102 * parameters) see EHCI Spec, Table 2-5 for each value
106 u32 params = fotg210_readl(fotg210, &fotg210->caps->hcc_params);
118 hc32_to_cpup(fotg210, &qtd->hw_next),
119 hc32_to_cpup(fotg210, &qtd->hw_alt_next),
120 hc32_to_cpup(fotg210, &qtd->hw_token),
121 hc32_to_cpup(fotg210, &qtd->hw_buf[0]));
122 if (qtd->hw_buf[1])
124 hc32_to_cpup(fotg210, &qtd->hw_buf[1]),
125 hc32_to_cpup(fotg210, &qtd->hw_buf[2]),
126 hc32_to_cpup(fotg210, &qtd->hw_buf[3]),
127 hc32_to_cpup(fotg210, &qtd->hw_buf[4]));
133 struct fotg210_qh_hw *hw = qh->hw;
136 hw->hw_next, hw->hw_info1, hw->hw_info2,
137 hw->hw_current);
139 dbg_qtd("overlay", fotg210, (struct fotg210_qtd *) &hw->hw_qtd_next);
146 itd->frame, itd, hc32_to_cpu(fotg210, itd->hw_next),
147 itd->urb);
151 hc32_to_cpu(fotg210, itd->hw_transaction[0]),
152 hc32_to_cpu(fotg210, itd->hw_transaction[1]),
153 hc32_to_cpu(fotg210, itd->hw_transaction[2]),
154 hc32_to_cpu(fotg210, itd->hw_transaction[3]),
155 hc32_to_cpu(fotg210, itd->hw_transaction[4]),
156 hc32_to_cpu(fotg210, itd->hw_transaction[5]),
157 hc32_to_cpu(fotg210, itd->hw_transaction[6]),
158 hc32_to_cpu(fotg210, itd->hw_transaction[7]));
162 hc32_to_cpu(fotg210, itd->hw_bufp[0]),
163 hc32_to_cpu(fotg210, itd->hw_bufp[1]),
164 hc32_to_cpu(fotg210, itd->hw_bufp[2]),
165 hc32_to_cpu(fotg210, itd->hw_bufp[3]),
166 hc32_to_cpu(fotg210, itd->hw_bufp[4]),
167 hc32_to_cpu(fotg210, itd->hw_bufp[5]),
168 hc32_to_cpu(fotg210, itd->hw_bufp[6]));
171 itd->index[0], itd->index[1], itd->index[2],
172 itd->index[3], itd->index[4], itd->index[5],
173 itd->index[6], itd->index[7]);
346 return '-';
364 struct fotg210_qh_hw *hw = qh->hw;
366 if (hw->hw_qtd_next == list_end) /* NEC does this */
369 mark = token_mark(fotg210, hw->hw_token);
371 if ((hw->hw_alt_next & QTD_MASK(fotg210)) ==
372 fotg210->async->hw->hw_alt_next)
374 else if (hw->hw_alt_next == list_end)
378 scratch = hc32_to_cpup(fotg210, &hw->hw_info1);
379 hw_curr = (mark == '*') ? hc32_to_cpup(fotg210, &hw->hw_current) : 0;
385 scratch, hc32_to_cpup(fotg210, &hw->hw_info2),
386 hc32_to_cpup(fotg210, &hw->hw_token), mark,
387 (cpu_to_hc32(fotg210, QTD_TOGGLE) & hw->hw_token)
389 (hc32_to_cpup(fotg210, &hw->hw_alt_next) >> 1) & 0x0f);
390 size -= temp;
394 list_for_each_entry(td, &qh->qtd_list, qtd_list) {
395 scratch = hc32_to_cpup(fotg210, &td->hw_token);
397 if (hw_curr == td->qtd_dma)
399 else if (hw->hw_qtd_next == cpu_to_hc32(fotg210, td->qtd_dma))
402 if (td->hw_alt_next == fotg210->async->hw->hw_alt_next)
404 else if (td->hw_alt_next != list_end)
426 td->urb);
427 size -= temp;
433 size -= temp;
449 hcd = bus_to_hcd(buf->bus);
451 next = buf->output_buf;
452 size = buf->alloc_size;
457 * usually empty except for long-term bulk reads, or head.
460 spin_lock_irqsave(&fotg210->lock, flags);
461 for (qh = fotg210->async->qh_next.qh; size > 0 && qh;
462 qh = qh->qh_next.qh)
464 if (fotg210->async_unlink && size > 0) {
466 size -= temp;
469 for (qh = fotg210->async_unlink; size > 0 && qh;
470 qh = qh->unlink_next)
473 spin_unlock_irqrestore(&fotg210->lock, flags);
475 return strlen(buf->output_buf);
482 u32 scratch = hc32_to_cpup(fotg210, &hw->hw_info1);
488 list_for_each_entry(qtd, &qh->qtd_list, qtd_list) {
490 switch ((hc32_to_cpu(fotg210, qtd->hw_token) >> 8) & 0x03) {
502 (scratch >> 8) & 0x000f, type, qh->usecs,
503 qh->c_usecs, temp, (scratch >> 16) & 0x7ff);
524 hcd = bus_to_hcd(buf->bus);
526 next = buf->output_buf;
527 size = buf->alloc_size;
529 temp = scnprintf(next, size, "size = %d\n", fotg210->periodic_size);
530 size -= temp;
536 spin_lock_irqsave(&fotg210->lock, flags);
537 for (i = 0; i < fotg210->periodic_size; i++) {
538 p = fotg210->pshadow[i];
542 tag = Q_NEXT_TYPE(fotg210, fotg210->periodic[i]);
545 size -= temp;
553 hw = p.qh->hw;
554 temp = scnprintf(next, size, " qh%d-%04x/%p",
555 p.qh->period,
557 &hw->hw_info2)
561 size -= temp;
567 if (p.qh->qh_next.ptr) {
570 size -= temp;
585 tag = Q_NEXT_TYPE(fotg210, hw->hw_next);
586 p = p.qh->qh_next;
590 " fstn-%8x/%p",
591 p.fstn->hw_prev, p.fstn);
592 tag = Q_NEXT_TYPE(fotg210, p.fstn->hw_next);
593 p = p.fstn->fstn_next;
598 tag = Q_NEXT_TYPE(fotg210, p.itd->hw_next);
599 p = p.itd->itd_next;
602 size -= temp;
607 size -= temp;
610 spin_unlock_irqrestore(&fotg210->lock, flags);
613 return buf->alloc_size - size;
619 switch (fotg210->rh_state) {
642 hcd = bus_to_hcd(buf->bus);
644 next = buf->output_buf;
645 size = buf->alloc_size;
647 spin_lock_irqsave(&fotg210->lock, flags);
654 hcd->self.controller->bus->name,
655 dev_name(hcd->self.controller),
656 hcd->product_desc);
662 &fotg210->caps->hc_capbase));
667 hcd->self.controller->bus->name,
668 dev_name(hcd->self.controller),
669 hcd->product_desc,
671 size -= temp;
675 i = fotg210_readl(fotg210, &fotg210->caps->hcs_params);
677 size -= temp;
680 i = fotg210_readl(fotg210, &fotg210->caps->hcc_params);
682 size -= temp;
687 fotg210_readl(fotg210, &fotg210->regs->status));
689 size -= temp;
693 fotg210_readl(fotg210, &fotg210->regs->command));
695 size -= temp;
699 fotg210_readl(fotg210, &fotg210->regs->intr_enable));
701 size -= temp;
706 size -= temp;
709 if (fotg210->async_unlink) {
711 fotg210->async_unlink);
712 size -= temp;
719 fotg210->stats.normal, fotg210->stats.error,
720 fotg210->stats.iaa, fotg210->stats.lost_iaa);
721 size -= temp;
725 fotg210->stats.complete, fotg210->stats.unlink);
726 size -= temp;
731 spin_unlock_irqrestore(&fotg210->lock, flags);
733 return buf->alloc_size - size;
744 buf->bus = bus;
745 buf->fill_func = fill_func;
746 mutex_init(&buf->mutex);
747 buf->alloc_size = PAGE_SIZE;
757 if (!buf->output_buf)
758 buf->output_buf = vmalloc(buf->alloc_size);
760 if (!buf->output_buf) {
761 ret = -ENOMEM;
765 ret = buf->fill_func(buf);
768 buf->count = ret;
779 struct debug_buffer *buf = file->private_data;
782 mutex_lock(&buf->mutex);
783 if (buf->count == 0) {
786 mutex_unlock(&buf->mutex);
790 mutex_unlock(&buf->mutex);
793 buf->output_buf, buf->count);
802 struct debug_buffer *buf = file->private_data;
805 vfree(buf->output_buf);
813 file->private_data = alloc_buffer(inode->i_private, fill_async_buffer);
815 return file->private_data ? 0 : -ENOMEM;
822 buf = alloc_buffer(inode->i_private, fill_periodic_buffer);
824 return -ENOMEM;
826 buf->alloc_size = (sizeof(void *) == 4 ? 6 : 8)*PAGE_SIZE;
827 file->private_data = buf;
833 file->private_data = alloc_buffer(inode->i_private,
836 return file->private_data ? 0 : -ENOMEM;
841 struct usb_bus *bus = &fotg210_to_hcd(fotg210)->self;
844 root = debugfs_create_dir(bus->bus_name, fotg210_debug_root);
855 struct usb_bus *bus = &fotg210_to_hcd(fotg210)->self;
857 debugfs_lookup_and_remove(bus->bus_name, fotg210_debug_root);
860 /* handshake - spin reading hc until handshake completes or fails
870 * hardware flakeout), or the register reads as all-ones (hardware removed).
886 return -ENODEV;
898 spin_lock_irq(&fotg210->lock);
901 fotg210_writel(fotg210, 0, &fotg210->regs->intr_enable);
904 * This routine gets called during probe before fotg210->command
907 fotg210->command &= ~CMD_RUN;
908 temp = fotg210_readl(fotg210, &fotg210->regs->command);
910 fotg210_writel(fotg210, temp, &fotg210->regs->command);
912 spin_unlock_irq(&fotg210->lock);
913 synchronize_irq(fotg210_to_hcd(fotg210)->irq);
915 return handshake(fotg210, &fotg210->regs->status,
919 /* Reset a non-running (STS_HALT == 1) controller.
925 u32 command = fotg210_readl(fotg210, &fotg210->regs->command);
930 if (fotg210->debug && !dbgp_reset_prep(fotg210_to_hcd(fotg210)))
931 fotg210->debug = NULL;
935 fotg210_writel(fotg210, command, &fotg210->regs->command);
936 fotg210->rh_state = FOTG210_RH_HALTED;
937 fotg210->next_statechange = jiffies;
938 retval = handshake(fotg210, &fotg210->regs->command,
944 if (fotg210->debug)
947 fotg210->port_c_suspend = fotg210->suspended_ports =
948 fotg210->resuming_ports = 0;
959 if (fotg210->rh_state != FOTG210_RH_RUNNING)
963 temp = (fotg210->command << 10) & (STS_ASS | STS_PSS);
964 handshake(fotg210, &fotg210->regs->status, STS_ASS | STS_PSS, temp,
968 spin_lock_irq(&fotg210->lock);
969 fotg210->command &= ~(CMD_ASE | CMD_PSE);
970 fotg210_writel(fotg210, fotg210->command, &fotg210->regs->command);
971 spin_unlock_irq(&fotg210->lock);
974 handshake(fotg210, &fotg210->regs->status, STS_ASS | STS_PSS, 0,
988 fotg210->command |= bit;
989 fotg210_writel(fotg210, fotg210->command, &fotg210->regs->command);
992 fotg210_readl(fotg210, &fotg210->regs->command);
998 fotg210->command &= ~bit;
999 fotg210_writel(fotg210, fotg210->command, &fotg210->regs->command);
1002 fotg210_readl(fotg210, &fotg210->regs->command);
1007 * Lots of different events are triggered from fotg210->hrtimer. Whenever
1011 * fotg210->enabled_hrtimer_events, and they are numbered in order of
1015 * we keep track only of the lowest-numbered pending event, in
1016 * fotg210->next_hrtimer_event. Whenever fotg210->hrtimer gets restarted, its
1021 * matter, because none of the events are especially time-critical. The
1048 ktime_t *timeout = &fotg210->hr_timeouts[event];
1052 fotg210->enabled_hrtimer_events |= (1 << event);
1054 /* Track only the lowest-numbered pending event */
1055 if (event < fotg210->next_hrtimer_event) {
1056 fotg210->next_hrtimer_event = event;
1057 hrtimer_start_range_ns(&fotg210->hrtimer, *timeout,
1069 if (fotg210->rh_state != FOTG210_RH_RUNNING)
1072 want = (fotg210->command & CMD_ASE) ? STS_ASS : 0;
1073 actual = fotg210_readl(fotg210, &fotg210->regs->status) & STS_ASS;
1078 if (fotg210->ASS_poll_count++ < 20) {
1086 fotg210->ASS_poll_count = 0;
1088 /* The status is up-to-date; restart or stop the schedule as needed */
1090 if (fotg210->async_count > 0)
1094 if (fotg210->async_count == 0) {
1117 if (fotg210->rh_state != FOTG210_RH_RUNNING)
1120 want = (fotg210->command & CMD_PSE) ? STS_PSS : 0;
1121 actual = fotg210_readl(fotg210, &fotg210->regs->status) & STS_PSS;
1126 if (fotg210->PSS_poll_count++ < 20) {
1134 fotg210->PSS_poll_count = 0;
1136 /* The status is up-to-date; restart or stop the schedule as needed */
1138 if (fotg210->periodic_count > 0)
1142 if (fotg210->periodic_count == 0) {
1162 if (!(fotg210_readl(fotg210, &fotg210->regs->status) & STS_HALT)) {
1165 if (fotg210->died_poll_count++ < 5) {
1175 fotg210->rh_state = FOTG210_RH_HALTED;
1176 fotg210_writel(fotg210, 0, &fotg210->regs->intr_enable);
1187 bool stopped = (fotg210->rh_state < FOTG210_RH_RUNNING);
1196 fotg210->intr_unlinking = true;
1197 while (fotg210->intr_unlink) {
1198 struct fotg210_qh *qh = fotg210->intr_unlink;
1200 if (!stopped && qh->unlink_cycle == fotg210->intr_unlink_cycle)
1202 fotg210->intr_unlink = qh->unlink_next;
1203 qh->unlink_next = NULL;
1208 if (fotg210->intr_unlink) {
1211 ++fotg210->intr_unlink_cycle;
1213 fotg210->intr_unlinking = false;
1217 /* Start another free-iTDs/siTDs cycle */
1220 if (!(fotg210->enabled_hrtimer_events &
1222 fotg210->last_itd_to_free = list_entry(
1223 fotg210->cached_itd_list.prev,
1234 if (fotg210->rh_state < FOTG210_RH_RUNNING)
1235 fotg210->last_itd_to_free = NULL;
1237 list_for_each_entry_safe(itd, n, &fotg210->cached_itd_list, itd_list) {
1238 list_del(&itd->itd_list);
1239 dma_pool_free(fotg210->itd_pool, itd, itd->itd_dma);
1240 if (itd == fotg210->last_itd_to_free)
1244 if (!list_empty(&fotg210->cached_itd_list))
1252 if (fotg210->rh_state != FOTG210_RH_RUNNING)
1261 if (fotg210->async_iaa) {
1270 cmd = fotg210_readl(fotg210, &fotg210->regs->command);
1276 * - VIA seems to set IAA without triggering the IRQ;
1277 * - IAAD potentially cleared without setting IAA.
1279 status = fotg210_readl(fotg210, &fotg210->regs->status);
1281 INCR(fotg210->stats.lost_iaa);
1283 &fotg210->regs->status);
1297 if (fotg210->rh_state != FOTG210_RH_RUNNING ||
1298 (fotg210->enabled_hrtimer_events &
1306 if (fotg210->isoc_count > 0 || (fotg210->need_io_watchdog &&
1307 fotg210->async_count + fotg210->intr_count > 0))
1339 spin_lock_irqsave(&fotg210->lock, flags);
1341 events = fotg210->enabled_hrtimer_events;
1342 fotg210->enabled_hrtimer_events = 0;
1343 fotg210->next_hrtimer_event = FOTG210_HRTIMER_NO_EVENT;
1347 * the event; otherwise re-enable it.
1351 if (ktime_compare(now, fotg210->hr_timeouts[e]) >= 0)
1357 spin_unlock_irqrestore(&fotg210->lock, flags);
1370 /* if reset finished and it's still not enabled -- handoff */
1393 /* init status to no-changes */
1396 /* Inform the core about resumes-in-progress by returning
1397 * a non-zero value even if there are no status changes.
1399 status = fotg210->resuming_ports;
1407 spin_lock_irqsave(&fotg210->lock, flags);
1409 temp = fotg210_readl(fotg210, &fotg210->regs->port_status);
1414 * high-speed device is switched over to the companion
1418 if ((temp & mask) != 0 || test_bit(0, &fotg210->port_c_suspend) ||
1419 (fotg210->reset_done[0] &&
1420 time_after_eq(jiffies, fotg210->reset_done[0]))) {
1425 spin_unlock_irqrestore(&fotg210->lock, flags);
1432 int ports = HCS_N_PORTS(fotg210->hcs_params);
1435 desc->bDescriptorType = USB_DT_HUB;
1436 desc->bPwrOn2PwrGood = 10; /* fotg210 1.0, 2.3.9 says 20ms max */
1437 desc->bHubContrCurrent = 0;
1439 desc->bNbrPorts = ports;
1441 desc->bDescLength = 7 + 2 * temp;
1444 memset(&desc->u.hs.DeviceRemovable[0], 0, temp);
1445 memset(&desc->u.hs.DeviceRemovable[temp], 0xff, temp);
1447 temp = HUB_CHAR_INDV_PORT_OCPM; /* per-port overcurrent reporting */
1449 desc->wHubCharacteristics = cpu_to_le16(temp);
1456 int ports = HCS_N_PORTS(fotg210->hcs_params);
1457 u32 __iomem *status_reg = &fotg210->regs->port_status;
1470 spin_lock_irqsave(&fotg210->lock, flags);
1476 /* no hub-wide feature/status flags */
1485 wIndex--;
1492 * the port-change status bits (especially
1513 fotg210->reset_done[wIndex] = jiffies
1517 clear_bit(wIndex, &fotg210->port_c_suspend);
1524 &fotg210->regs->otgisr);
1532 fotg210_readl(fotg210, &fotg210->regs->command);
1539 /* no hub-wide feature/status flags */
1546 wIndex--;
1556 temp1 = fotg210_readl(fotg210, &fotg210->regs->otgisr);
1564 if (!fotg210->reset_done[wIndex]) {
1566 fotg210->reset_done[wIndex] = jiffies
1569 mod_timer(&fotg210_to_hcd(fotg210)->rh_timer,
1570 fotg210->reset_done[wIndex]);
1575 fotg210->reset_done[wIndex])) {
1576 clear_bit(wIndex, &fotg210->suspended_ports);
1577 set_bit(wIndex, &fotg210->port_c_suspend);
1578 fotg210->reset_done[wIndex] = 0;
1585 clear_bit(wIndex, &fotg210->resuming_ports);
1600 fotg210->reset_done[wIndex])) {
1602 fotg210->reset_done[wIndex] = 0;
1603 clear_bit(wIndex, &fotg210->resuming_ports);
1625 fotg210->command |= CMD_RUN;
1626 fotg210_writel(fotg210, fotg210->command, &fotg210->regs->command);
1630 fotg210->reset_done[wIndex] = 0;
1631 clear_bit(wIndex, &fotg210->resuming_ports);
1636 test_bit(wIndex, &fotg210->companion_ports)) {
1639 fotg210_dbg(fotg210, "port %d --> companion\n",
1660 } else if (test_bit(wIndex, &fotg210->suspended_ports)) {
1661 clear_bit(wIndex, &fotg210->suspended_ports);
1662 clear_bit(wIndex, &fotg210->resuming_ports);
1663 fotg210->reset_done[wIndex] = 0;
1665 set_bit(wIndex, &fotg210->port_c_suspend);
1668 temp1 = fotg210_readl(fotg210, &fotg210->regs->otgisr);
1673 if (test_bit(wIndex, &fotg210->port_c_suspend))
1684 /* no hub-wide feature/status flags */
1696 wIndex--;
1711 set_bit(wIndex, &fotg210->suspended_ports);
1728 fotg210->reset_done[wIndex] = jiffies
1737 * about the EHCI-specific stuff.
1742 spin_unlock_irqrestore(&fotg210->lock, flags);
1744 spin_lock_irqsave(&fotg210->lock, flags);
1753 spin_unlock_irqrestore(&fotg210->lock, flags);
1755 spin_lock_irqsave(&fotg210->lock, flags);
1765 fotg210_readl(fotg210, &fotg210->regs->command);
1771 retval = -EPIPE;
1773 spin_unlock_irqrestore(&fotg210->lock, flags);
1790 * - data used only by the HCD ... kmalloc is fine
1791 * - async and periodic schedules, shared by HC and HCD ... these
1793 * - driver buffers, read/written by HC ... single shot DMA mapped
1804 qtd->qtd_dma = dma;
1805 qtd->hw_token = cpu_to_hc32(fotg210, QTD_STS_HALT);
1806 qtd->hw_next = FOTG210_LIST_END(fotg210);
1807 qtd->hw_alt_next = FOTG210_LIST_END(fotg210);
1808 INIT_LIST_HEAD(&qtd->qtd_list);
1817 qtd = dma_pool_alloc(fotg210->qtd_pool, flags, &dma);
1827 dma_pool_free(fotg210->qtd_pool, qtd, qtd->qtd_dma);
1834 if (!list_empty(&qh->qtd_list) || qh->qh_next.ptr) {
1838 if (qh->dummy)
1839 fotg210_qtd_free(fotg210, qh->dummy);
1840 dma_pool_free(fotg210->qh_pool, qh->hw, qh->qh_dma);
1853 qh->hw = (struct fotg210_qh_hw *)
1854 dma_pool_zalloc(fotg210->qh_pool, flags, &dma);
1855 if (!qh->hw)
1857 qh->qh_dma = dma;
1858 INIT_LIST_HEAD(&qh->qtd_list);
1861 qh->dummy = fotg210_qtd_alloc(fotg210, flags);
1862 if (qh->dummy == NULL) {
1869 dma_pool_free(fotg210->qh_pool, qh->hw, qh->qh_dma);
1882 if (fotg210->async)
1883 qh_destroy(fotg210, fotg210->async);
1884 fotg210->async = NULL;
1886 if (fotg210->dummy)
1887 qh_destroy(fotg210, fotg210->dummy);
1888 fotg210->dummy = NULL;
1891 dma_pool_destroy(fotg210->qtd_pool);
1892 fotg210->qtd_pool = NULL;
1894 dma_pool_destroy(fotg210->qh_pool);
1895 fotg210->qh_pool = NULL;
1897 dma_pool_destroy(fotg210->itd_pool);
1898 fotg210->itd_pool = NULL;
1900 if (fotg210->periodic)
1901 dma_free_coherent(fotg210_to_hcd(fotg210)->self.controller,
1902 fotg210->periodic_size * sizeof(u32),
1903 fotg210->periodic, fotg210->periodic_dma);
1904 fotg210->periodic = NULL;
1907 kfree(fotg210->pshadow);
1908 fotg210->pshadow = NULL;
1917 fotg210->qtd_pool = dma_pool_create("fotg210_qtd",
1918 fotg210_to_hcd(fotg210)->self.controller,
1922 if (!fotg210->qtd_pool)
1926 fotg210->qh_pool = dma_pool_create("fotg210_qh",
1927 fotg210_to_hcd(fotg210)->self.controller,
1931 if (!fotg210->qh_pool)
1934 fotg210->async = fotg210_qh_alloc(fotg210, flags);
1935 if (!fotg210->async)
1939 fotg210->itd_pool = dma_pool_create("fotg210_itd",
1940 fotg210_to_hcd(fotg210)->self.controller,
1944 if (!fotg210->itd_pool)
1948 fotg210->periodic =
1949 dma_alloc_coherent(fotg210_to_hcd(fotg210)->self.controller,
1950 fotg210->periodic_size * sizeof(__le32),
1951 &fotg210->periodic_dma, 0);
1952 if (fotg210->periodic == NULL)
1955 for (i = 0; i < fotg210->periodic_size; i++)
1956 fotg210->periodic[i] = FOTG210_LIST_END(fotg210);
1959 fotg210->pshadow = kcalloc(fotg210->periodic_size, sizeof(void *),
1961 if (fotg210->pshadow != NULL)
1967 return -ENOMEM;
1972 * entries describing USB transactions, max 16-20kB/entry (with 4kB-aligned
1978 * an ongoing challenge. That's in "ehci-sched.c".
1994 qtd->hw_buf[0] = cpu_to_hc32(fotg210, (u32)addr);
1995 qtd->hw_buf_hi[0] = cpu_to_hc32(fotg210, (u32)(addr >> 32));
1996 count = 0x1000 - (buf & 0x0fff); /* rest of that page */
2003 /* per-qtd limit: from 16K to 20K (best alignment) */
2006 qtd->hw_buf[i] = cpu_to_hc32(fotg210, (u32)addr);
2007 qtd->hw_buf_hi[i] = cpu_to_hc32(fotg210,
2018 count -= (count % maxpacket);
2020 qtd->hw_token = cpu_to_hc32(fotg210, (count << 16) | token);
2021 qtd->length = count;
2029 struct fotg210_qh_hw *hw = qh->hw;
2032 BUG_ON(qh->qh_state != QH_STATE_IDLE);
2034 hw->hw_qtd_next = QTD_NEXT(fotg210, qtd->qtd_dma);
2035 hw->hw_alt_next = FOTG210_LIST_END(fotg210);
2039 * and set the pseudo-toggle in udev. Only usb_clear_halt() will
2042 if (!(hw->hw_info1 & cpu_to_hc32(fotg210, QH_TOGGLE_CTL))) {
2045 is_out = qh->is_out;
2046 epnum = (hc32_to_cpup(fotg210, &hw->hw_info1) >> 8) & 0x0f;
2047 if (unlikely(!usb_gettoggle(qh->dev, epnum, is_out))) {
2048 hw->hw_token &= ~cpu_to_hc32(fotg210, QTD_TOGGLE);
2049 usb_settoggle(qh->dev, epnum, is_out, 1);
2053 hw->hw_token &= cpu_to_hc32(fotg210, QTD_TOGGLE | QTD_STS_PING);
2057 * overlay, so qh->hw_token wrongly becomes inactive/halted), only fault
2064 if (list_empty(&qh->qtd_list))
2065 qtd = qh->dummy;
2067 qtd = list_entry(qh->qtd_list.next,
2076 if (cpu_to_hc32(fotg210, qtd->qtd_dma) == qh->hw->hw_current) {
2077 qh->hw->hw_qtd_next = qtd->hw_next;
2092 struct fotg210_qh *qh = ep->hcpriv;
2095 spin_lock_irqsave(&fotg210->lock, flags);
2096 qh->clearing_tt = 0;
2097 if (qh->qh_state == QH_STATE_IDLE && !list_empty(&qh->qtd_list)
2098 && fotg210->rh_state == FOTG210_RH_RUNNING)
2100 spin_unlock_irqrestore(&fotg210->lock, flags);
2113 if (urb->dev->tt && !usb_pipeint(urb->pipe) && !qh->clearing_tt) {
2114 struct usb_device *tt = urb->dev->tt->hub;
2116 dev_dbg(&tt->dev,
2118 urb->dev->ttport, urb->dev->devnum,
2119 usb_pipeendpoint(urb->pipe), token);
2121 if (urb->dev->tt->hub !=
2122 fotg210_to_hcd(fotg210)->self.root_hub) {
2124 qh->clearing_tt = 1;
2132 int status = -EINPROGRESS;
2136 urb->actual_length += length - QTD_LENGTH(token);
2139 if (unlikely(urb->unlinked))
2144 status = -EREMOTEIO;
2150 status = -EOVERFLOW;
2151 /* CERR nonzero + halt --> stall */
2153 status = -EPIPE;
2160 /* fs/ls interrupt xfer missed the complete-split */
2161 status = -EPROTO;
2164 ? -ENOSR /* hc couldn't read data */
2165 : -ECOMM; /* hc couldn't write data */
2169 urb->dev->devpath,
2170 usb_pipeendpoint(urb->pipe),
2171 usb_pipein(urb->pipe) ? "in" : "out");
2172 status = -EPROTO;
2174 status = -EPROTO;
2178 "dev%d ep%d%s qtd token %08x --> status %d\n",
2179 usb_pipedevice(urb->pipe),
2180 usb_pipeendpoint(urb->pipe),
2181 usb_pipein(urb->pipe) ? "in" : "out",
2190 __releases(fotg210->lock)
2191 __acquires(fotg210->lock)
2193 if (likely(urb->hcpriv != NULL)) {
2194 struct fotg210_qh *qh = (struct fotg210_qh *) urb->hcpriv;
2196 /* S-mask in a QH means it's an interrupt urb */
2197 if ((qh->hw->hw_info2 & cpu_to_hc32(fotg210, QH_SMASK)) != 0) {
2199 /* ... update hc-wide periodic stats (for usbfs) */
2200 fotg210_to_hcd(fotg210)->self.bandwidth_int_reqs--;
2204 if (unlikely(urb->unlinked)) {
2205 INCR(fotg210->stats.unlink);
2207 /* report non-error and short read status as zero */
2208 if (status == -EINPROGRESS || status == -EREMOTEIO)
2210 INCR(fotg210->stats.complete);
2216 __func__, urb->dev->devpath, urb,
2217 usb_pipeendpoint(urb->pipe),
2218 usb_pipein(urb->pipe) ? "in" : "out",
2220 urb->actual_length, urb->transfer_buffer_length);
2225 spin_unlock(&fotg210->lock);
2227 spin_lock(&fotg210->lock);
2233 * Chases up to qh->hw_current. Returns number of completions called,
2239 struct fotg210_qtd *last, *end = qh->dummy;
2245 struct fotg210_qh_hw *hw = qh->hw;
2247 if (unlikely(list_empty(&qh->qtd_list)))
2256 * It's a bug for qh->qh_state to be anything other than
2260 state = qh->qh_state;
2261 qh->qh_state = QH_STATE_COMPLETING;
2266 last_status = -EINPROGRESS;
2267 qh->needs_rescan = 0;
2269 /* remove de-activated QTDs from front of queue.
2274 list_for_each_entry_safe(qtd, tmp, &qh->qtd_list, qtd_list) {
2278 urb = qtd->urb;
2282 if (likely(last->urb != urb)) {
2283 fotg210_urb_done(fotg210, last->urb,
2286 last_status = -EINPROGRESS;
2298 token = hc32_to_cpu(fotg210, qtd->hw_token);
2300 /* always clean up qtds the hc de-activated */
2304 /* Report Data Buffer Error: non-fatal but useful */
2308 urb, usb_endpoint_num(&urb->ep->desc),
2309 usb_endpoint_dir_in(&urb->ep->desc)
2311 urb->transfer_buffer_length, qtd, qh);
2323 ++qh->xacterrs < QH_XACTERR_MAX &&
2324 !urb->unlinked) {
2327 qtd->length - QTD_LENGTH(token),
2328 qtd->length,
2329 qh->xacterrs);
2339 qtd->hw_token = cpu_to_hc32(fotg210,
2342 hw->hw_token = cpu_to_hc32(fotg210,
2353 * most other single-qtd reads ... the queue stops if
2358 !(qtd->hw_alt_next &
2365 && fotg210->rh_state >= FOTG210_RH_RUNNING)) {
2373 if (fotg210->rh_state < FOTG210_RH_RUNNING)
2374 last_status = -ESHUTDOWN;
2379 else if (last_status == -EINPROGRESS && !urb->unlinked)
2384 cpu_to_hc32(fotg210, qtd->qtd_dma)
2385 == hw->hw_current) {
2386 token = hc32_to_cpu(fotg210, hw->hw_token);
2404 if (last_status == -EINPROGRESS) {
2406 qtd->length, token);
2407 if (last_status == -EREMOTEIO &&
2408 (qtd->hw_alt_next &
2410 last_status = -EINPROGRESS;
2412 /* As part of low/full-speed endpoint-halt processing
2415 if (unlikely(last_status != -EINPROGRESS &&
2416 last_status != -EREMOTEIO)) {
2421 * state (if you believe Figures 11-48 - 11-51
2426 if (last_status != -EPIPE)
2435 if (stopped && qtd->qtd_list.prev != &qh->qtd_list) {
2436 last = list_entry(qtd->qtd_list.prev,
2438 last->hw_next = qtd->hw_next;
2442 list_del(&qtd->qtd_list);
2446 qh->xacterrs = 0;
2451 fotg210_urb_done(fotg210, last->urb, last_status);
2457 if (unlikely(qh->needs_rescan)) {
2463 * Our caller will start an unlink if qh->needs_rescan is
2468 qh->needs_rescan = 0;
2472 qh->qh_state = state;
2478 if (stopped != 0 || hw->hw_qtd_next == FOTG210_LIST_END(fotg210)) {
2486 * - HC reads first part of QH;
2487 * - CPU updates that first part and the token;
2488 * - HC reads rest of that QH, including token
2497 qh->needs_rescan = 1;
2515 list_del(&qtd->qtd_list);
2539 list_add_tail(&qtd->qtd_list, head);
2540 qtd->urb = urb;
2546 len = urb->transfer_buffer_length;
2547 is_input = usb_pipein(urb->pipe);
2548 if (usb_pipecontrol(urb->pipe)) {
2550 qtd_fill(fotg210, qtd, urb->setup_dma,
2560 qtd->urb = urb;
2561 qtd_prev->hw_next = QTD_NEXT(fotg210, qtd->qtd_dma);
2562 list_add_tail(&qtd->qtd_list, head);
2572 i = urb->num_mapped_sgs;
2574 sg = urb->sg;
2577 /* urb->transfer_buffer_length may be smaller than the
2583 buf = urb->transfer_dma;
2591 maxpacket = usb_maxpacket(urb->dev, urb->pipe);
2603 this_sg_len -= this_qtd_len;
2604 len -= this_qtd_len;
2613 qtd->hw_alt_next = fotg210->async->hw->hw_alt_next;
2616 if ((maxpacket & (this_qtd_len + (maxpacket - 1))) == 0)
2620 if (--i <= 0 || len <= 0)
2631 qtd->urb = urb;
2632 qtd_prev->hw_next = QTD_NEXT(fotg210, qtd->qtd_dma);
2633 list_add_tail(&qtd->qtd_list, head);
2641 if (likely((urb->transfer_flags & URB_SHORT_NOT_OK) == 0 ||
2642 usb_pipecontrol(urb->pipe)))
2643 qtd->hw_alt_next = FOTG210_LIST_END(fotg210);
2650 if (likely(urb->transfer_buffer_length != 0)) {
2653 if (usb_pipecontrol(urb->pipe)) {
2655 token ^= 0x0100; /* "in" <--> "out" */
2657 } else if (usb_pipeout(urb->pipe)
2658 && (urb->transfer_flags & URB_ZERO_PACKET)
2659 && !(urb->transfer_buffer_length % maxpacket)) {
2667 qtd->urb = urb;
2668 qtd_prev->hw_next = QTD_NEXT(fotg210, qtd->qtd_dma);
2669 list_add_tail(&qtd->qtd_list, head);
2677 if (likely(!(urb->transfer_flags & URB_NO_INTERRUPT)))
2678 qtd->hw_token |= cpu_to_hc32(fotg210, QTD_IOC);
2698 * just one microframe in the s-mask. For split interrupt transactions
2699 * there are additional complications: c-mask, maybe FSTNs.
2710 struct usb_tt *tt = urb->dev->tt;
2719 info1 |= usb_pipeendpoint(urb->pipe) << 8;
2720 info1 |= usb_pipedevice(urb->pipe) << 0;
2722 is_input = usb_pipein(urb->pipe);
2723 type = usb_pipetype(urb->pipe);
2724 ep = usb_pipe_endpoint(urb->dev, urb->pipe);
2725 maxp = usb_endpoint_maxp(&ep->desc);
2726 mult = usb_endpoint_maxp_mult(&ep->desc);
2737 * - allowing for high bandwidth, how many nsec/uframe are used?
2738 * - split transactions need a second CSPLIT uframe; same question
2739 * - splits also need a schedule gap (for full/low speed I/O)
2740 * - qh has a polling interval
2745 qh->usecs = NS_TO_US(usb_calc_bus_time(USB_SPEED_HIGH,
2747 qh->start = NO_FRAME;
2749 if (urb->dev->speed == USB_SPEED_HIGH) {
2750 qh->c_usecs = 0;
2751 qh->gap_uf = 0;
2753 qh->period = urb->interval >> 3;
2754 if (qh->period == 0 && urb->interval != 1) {
2759 urb->interval = 1;
2760 } else if (qh->period > fotg210->periodic_size) {
2761 qh->period = fotg210->periodic_size;
2762 urb->interval = qh->period << 3;
2768 qh->gap_uf = 1 + usb_calc_bus_time(urb->dev->speed,
2773 qh->c_usecs = qh->usecs + HS_USECS(0);
2774 qh->usecs = HS_USECS(1);
2776 qh->usecs += HS_USECS(1);
2777 qh->c_usecs = HS_USECS(0);
2780 think_time = tt ? tt->think_time : 0;
2781 qh->tt_usecs = NS_TO_US(think_time +
2782 usb_calc_bus_time(urb->dev->speed,
2784 qh->period = urb->interval;
2785 if (qh->period > fotg210->periodic_size) {
2786 qh->period = fotg210->periodic_size;
2787 urb->interval = qh->period;
2793 qh->dev = urb->dev;
2796 switch (urb->dev->speed) {
2814 * port number in the queue head was 0..N-1 instead of 1..N.
2817 info2 |= (urb->dev->ttport-1) << 23;
2819 info2 |= urb->dev->ttport << 23;
2824 if (tt && tt->hub != fotg210_to_hcd(fotg210)->self.root_hub)
2825 info2 |= tt->hub->devnum << 16;
2827 /* NOTE: if (PIPE_INTERRUPT) { scheduler sets c-mask } */
2854 fotg210_dbg(fotg210, "bogus dev %p speed %d\n", urb->dev,
2855 urb->dev->speed);
2861 /* NOTE: if (PIPE_INTERRUPT) { scheduler sets s-mask } */
2864 qh->qh_state = QH_STATE_IDLE;
2865 hw = qh->hw;
2866 hw->hw_info1 = cpu_to_hc32(fotg210, info1);
2867 hw->hw_info2 = cpu_to_hc32(fotg210, info2);
2868 qh->is_out = !is_input;
2869 usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), !is_input, 1);
2876 if (fotg210->async_count++)
2880 fotg210->enabled_hrtimer_events &= ~BIT(FOTG210_HRTIMER_DISABLE_ASYNC);
2889 if (--fotg210->async_count)
2893 WARN_ON(fotg210->async->qh_next.qh || fotg210->async_unlink);
2903 __hc32 dma = QH_NEXT(fotg210, qh->qh_dma);
2906 /* Don't link a QH if there's a Clear-TT-Buffer pending */
2907 if (unlikely(qh->clearing_tt))
2910 WARN_ON(qh->qh_state != QH_STATE_IDLE);
2916 head = fotg210->async;
2917 qh->qh_next = head->qh_next;
2918 qh->hw->hw_next = head->hw->hw_next;
2921 head->qh_next.qh = qh;
2922 head->hw->hw_next = dma;
2924 qh->xacterrs = 0;
2925 qh->qh_state = QH_STATE_LINKED;
2945 /* can't sleep here, we have fotg210->lock... */
2955 qtd = list_entry(qtd_list->next, struct fotg210_qtd,
2961 if (usb_pipedevice(urb->pipe) == 0)
2962 qh->hw->hw_info1 &= ~qh_addr_mask;
2978 token = qtd->hw_token;
2979 qtd->hw_token = HALT_BIT(fotg210);
2981 dummy = qh->dummy;
2983 dma = dummy->qtd_dma;
2985 dummy->qtd_dma = dma;
2987 list_del(&qtd->qtd_list);
2988 list_add(&dummy->qtd_list, qtd_list);
2989 list_splice_tail(qtd_list, &qh->qtd_list);
2991 fotg210_qtd_init(fotg210, qtd, qtd->qtd_dma);
2992 qh->dummy = qtd;
2995 dma = qtd->qtd_dma;
2996 qtd = list_entry(qh->qtd_list.prev,
2998 qtd->hw_next = QTD_NEXT(fotg210, dma);
3002 dummy->hw_token = token;
3004 urb->hcpriv = qh;
3018 epnum = urb->ep->desc.bEndpointAddress;
3024 qtd = list_entry(qtd_list->next, struct fotg210_qtd, qtd_list);
3027 __func__, urb->dev->devpath, urb,
3030 urb->transfer_buffer_length,
3031 qtd, urb->ep->hcpriv);
3035 spin_lock_irqsave(&fotg210->lock, flags);
3037 rc = -ESHUTDOWN;
3044 qh = qh_append_tds(fotg210, urb, qtd_list, epnum, &urb->ep->hcpriv);
3047 rc = -ENOMEM;
3054 if (likely(qh->qh_state == QH_STATE_IDLE))
3057 spin_unlock_irqrestore(&fotg210->lock, flags);
3069 qh->qh_state = QH_STATE_UNLINK;
3070 if (fotg210->async_unlink)
3071 fotg210->async_unlink_last->unlink_next = qh;
3073 fotg210->async_unlink = qh;
3074 fotg210->async_unlink_last = qh;
3077 prev = fotg210->async;
3078 while (prev->qh_next.qh != qh)
3079 prev = prev->qh_next.qh;
3081 prev->hw->hw_next = qh->hw->hw_next;
3082 prev->qh_next = qh->qh_next;
3083 if (fotg210->qh_scan_next == qh)
3084 fotg210->qh_scan_next = qh->qh_next.qh;
3093 if (fotg210->async_iaa || fotg210->async_unlinking)
3097 fotg210->async_iaa = fotg210->async_unlink;
3098 fotg210->async_unlink = NULL;
3101 if (unlikely(fotg210->rh_state < FOTG210_RH_RUNNING)) {
3106 } else if (likely(fotg210->rh_state == FOTG210_RH_RUNNING)) {
3110 fotg210_writel(fotg210, fotg210->command | CMD_IAAD,
3111 &fotg210->regs->command);
3112 fotg210_readl(fotg210, &fotg210->regs->command);
3126 fotg210->async_unlinking = true;
3127 while (fotg210->async_iaa) {
3128 qh = fotg210->async_iaa;
3129 fotg210->async_iaa = qh->unlink_next;
3130 qh->unlink_next = NULL;
3132 qh->qh_state = QH_STATE_IDLE;
3133 qh->qh_next.qh = NULL;
3136 if (!list_empty(&qh->qtd_list) &&
3137 fotg210->rh_state == FOTG210_RH_RUNNING)
3141 fotg210->async_unlinking = false;
3144 if (fotg210->async_unlink) {
3146 if (unlikely(fotg210->rh_state < FOTG210_RH_RUNNING))
3154 bool stopped = (fotg210->rh_state < FOTG210_RH_RUNNING);
3158 next = fotg210->async->qh_next.qh;
3161 next = qh->qh_next.qh;
3163 if (list_empty(&qh->qtd_list) &&
3164 qh->qh_state == QH_STATE_LINKED) {
3165 if (!stopped && qh->unlink_cycle ==
3166 fotg210->async_unlink_cycle)
3174 if (fotg210->async_unlink)
3181 ++fotg210->async_unlink_cycle;
3186 /* caller must own fotg210->lock */
3196 if (qh->qh_state != QH_STATE_LINKED) {
3197 if (qh->qh_state == QH_STATE_COMPLETING)
3198 qh->needs_rescan = 1;
3211 fotg210->qh_scan_next = fotg210->async->qh_next.qh;
3212 while (fotg210->qh_scan_next) {
3213 qh = fotg210->qh_scan_next;
3214 fotg210->qh_scan_next = qh->qh_next.qh;
3217 if (!list_empty(&qh->qtd_list)) {
3222 * drops the lock. That's why fotg210->qh_scan_next
3224 * gets unlinked then fotg210->qh_scan_next is adjusted
3228 if (qh->needs_rescan) {
3230 } else if (list_empty(&qh->qtd_list)
3231 && qh->qh_state == QH_STATE_LINKED) {
3232 qh->unlink_cycle = fotg210->async_unlink_cycle;
3241 * as HCD schedule-scanning costs. Delay for any qh
3242 * we just scanned, there's a not-unusual case that it
3245 if (check_unlinks_later && fotg210->rh_state == FOTG210_RH_RUNNING &&
3246 !(fotg210->enabled_hrtimer_events &
3250 ++fotg210->async_unlink_cycle;
3262 * pre-calculated schedule data to make appending to the queue be quick.
3266 /* periodic_next_shadow - return "next" pointer on shadow list
3275 return &periodic->qh->qh_next;
3277 return &periodic->fstn->fstn_next;
3279 return &periodic->itd->itd_next;
3289 return &periodic->qh->hw->hw_next;
3292 return periodic->hw_next;
3296 /* caller must hold fotg210->lock */
3300 union fotg210_shadow *prev_p = &fotg210->pshadow[frame];
3301 __hc32 *hw_p = &fotg210->periodic[frame];
3330 __hc32 *hw_p = &fotg210->periodic[frame];
3331 union fotg210_shadow *q = &fotg210->pshadow[frame];
3335 while (q->ptr) {
3338 hw = q->qh->hw;
3339 /* is it in the S-mask? */
3340 if (hw->hw_info2 & cpu_to_hc32(fotg210, 1 << uframe))
3341 usecs += q->qh->usecs;
3342 /* ... or C-mask? */
3343 if (hw->hw_info2 & cpu_to_hc32(fotg210,
3345 usecs += q->qh->c_usecs;
3346 hw_p = &hw->hw_next;
3347 q = &q->qh->qh_next;
3354 if (q->fstn->hw_prev != FOTG210_LIST_END(fotg210))
3357 hw_p = &q->fstn->hw_next;
3358 q = &q->fstn->fstn_next;
3361 if (q->itd->hw_transaction[uframe])
3362 usecs += q->itd->stream->usecs;
3363 hw_p = &q->itd->hw_next;
3364 q = &q->itd->itd_next;
3368 if (usecs > fotg210->uframe_periodic_max)
3376 if (!dev1->tt || !dev2->tt)
3378 if (dev1->tt != dev2->tt)
3380 if (dev1->tt->multi)
3381 return dev1->ttport == dev2->ttport;
3400 for (; frame < fotg210->periodic_size; frame += period) {
3405 here = fotg210->pshadow[frame];
3406 type = Q_NEXT_TYPE(fotg210, fotg210->periodic[frame]);
3410 type = Q_NEXT_TYPE(fotg210, here.itd->hw_next);
3411 here = here.itd->itd_next;
3414 hw = here.qh->hw;
3415 if (same_tt(dev, here.qh->dev)) {
3419 hw->hw_info2);
3425 type = Q_NEXT_TYPE(fotg210, hw->hw_next);
3426 here = here.qh->qh_next;
3446 if (fotg210->periodic_count++)
3450 fotg210->enabled_hrtimer_events &=
3460 if (--fotg210->periodic_count)
3476 unsigned period = qh->period;
3478 dev_dbg(&qh->dev->dev,
3479 "link qh%d-%04x/%p start %d [%d/%d us]\n", period,
3480 hc32_to_cpup(fotg210, &qh->hw->hw_info2) &
3481 (QH_CMASK | QH_SMASK), qh, qh->start, qh->usecs,
3482 qh->c_usecs);
3488 for (i = qh->start; i < fotg210->periodic_size; i += period) {
3489 union fotg210_shadow *prev = &fotg210->pshadow[i];
3490 __hc32 *hw_p = &fotg210->periodic[i];
3504 /* sorting each branch by period (slow-->fast)
3508 if (qh->period > here.qh->period)
3510 prev = &here.qh->qh_next;
3511 hw_p = &here.qh->hw->hw_next;
3516 qh->qh_next = here;
3518 qh->hw->hw_next = *hw_p;
3520 prev->qh = qh;
3521 *hw_p = QH_NEXT(fotg210, qh->qh_dma);
3524 qh->qh_state = QH_STATE_LINKED;
3525 qh->xacterrs = 0;
3527 /* update per-qh bandwidth for usbfs */
3528 fotg210_to_hcd(fotg210)->self.bandwidth_allocated += qh->period
3529 ? ((qh->usecs + qh->c_usecs) / qh->period)
3530 : (qh->usecs * 8);
3532 list_add(&qh->intr_node, &fotg210->intr_qh_list);
3535 ++fotg210->intr_count;
3546 * If qh is for a low/full-speed device, simply unlinking it
3561 period = qh->period;
3565 for (i = qh->start; i < fotg210->periodic_size; i += period)
3568 /* update per-qh bandwidth for usbfs */
3569 fotg210_to_hcd(fotg210)->self.bandwidth_allocated -= qh->period
3570 ? ((qh->usecs + qh->c_usecs) / qh->period)
3571 : (qh->usecs * 8);
3573 dev_dbg(&qh->dev->dev,
3574 "unlink qh%d-%04x/%p start %d [%d/%d us]\n",
3575 qh->period, hc32_to_cpup(fotg210, &qh->hw->hw_info2) &
3576 (QH_CMASK | QH_SMASK), qh, qh->start, qh->usecs,
3577 qh->c_usecs);
3579 /* qh->qh_next still "live" to HC */
3580 qh->qh_state = QH_STATE_UNLINK;
3581 qh->qh_next.ptr = NULL;
3583 if (fotg210->qh_scan_next == qh)
3584 fotg210->qh_scan_next = list_entry(qh->intr_node.next,
3586 list_del(&qh->intr_node);
3596 if (qh->qh_state != QH_STATE_LINKED) {
3597 if (qh->qh_state == QH_STATE_COMPLETING)
3598 qh->needs_rescan = 1;
3612 qh->unlink_cycle = fotg210->intr_unlink_cycle;
3615 if (fotg210->intr_unlink)
3616 fotg210->intr_unlink_last->unlink_next = qh;
3618 fotg210->intr_unlink = qh;
3619 fotg210->intr_unlink_last = qh;
3621 if (fotg210->intr_unlinking)
3623 else if (fotg210->rh_state < FOTG210_RH_RUNNING)
3625 else if (fotg210->intr_unlink == qh) {
3628 ++fotg210->intr_unlink_cycle;
3634 struct fotg210_qh_hw *hw = qh->hw;
3637 qh->qh_state = QH_STATE_IDLE;
3638 hw->hw_next = FOTG210_LIST_END(fotg210);
3643 if (!list_empty(&qh->qtd_list) &&
3644 fotg210->rh_state == FOTG210_RH_RUNNING) {
3651 * FIXME kill the now-dysfunctional queued urbs
3659 --fotg210->intr_count;
3675 usecs = fotg210->uframe_periodic_max - usecs;
3688 } while ((frame += 1) < fotg210->periodic_size);
3696 } while ((frame += period) < fotg210->periodic_size);
3706 int retval = -ENOSPC;
3709 if (qh->c_usecs && uframe >= 6) /* FSTN territory? */
3712 if (!check_period(fotg210, frame, uframe, qh->period, qh->usecs))
3714 if (!qh->c_usecs) {
3727 mask = 0x03 << (uframe + qh->gap_uf);
3731 if (tt_no_collision(fotg210, qh->period, qh->dev, frame, mask)) {
3732 if (!check_period(fotg210, frame, uframe + qh->gap_uf + 1,
3733 qh->period, qh->c_usecs))
3735 if (!check_period(fotg210, frame, uframe + qh->gap_uf,
3736 qh->period, qh->c_usecs))
3745 * or when the previous schedule slot can't be re-used.
3752 unsigned frame; /* 0..(qh->period - 1), or NO_FRAME */
3753 struct fotg210_qh_hw *hw = qh->hw;
3756 hw->hw_next = FOTG210_LIST_END(fotg210);
3757 frame = qh->start;
3760 if (frame < qh->period) {
3761 uframe = ffs(hc32_to_cpup(fotg210, &hw->hw_info2) & QH_SMASK);
3762 status = check_intr_schedule(fotg210, frame, --uframe,
3767 status = -ENOSPC;
3775 if (qh->period) {
3778 for (i = qh->period; status && i > 0; --i) {
3779 frame = ++fotg210->random_frame % qh->period;
3789 /* qh->period == 0 means every uframe */
3797 qh->start = frame;
3799 /* reset S-frame and (maybe) C-frame masks */
3800 hw->hw_info2 &= cpu_to_hc32(fotg210, ~(QH_CMASK | QH_SMASK));
3801 hw->hw_info2 |= qh->period
3804 hw->hw_info2 |= c_mask;
3824 epnum = urb->ep->desc.bEndpointAddress;
3826 spin_lock_irqsave(&fotg210->lock, flags);
3829 status = -ESHUTDOWN;
3838 qh = qh_append_tds(fotg210, urb, &empty, epnum, &urb->ep->hcpriv);
3840 status = -ENOMEM;
3843 if (qh->qh_state == QH_STATE_IDLE) {
3850 qh = qh_append_tds(fotg210, urb, qtd_list, epnum, &urb->ep->hcpriv);
3854 fotg210_to_hcd(fotg210)->self.bandwidth_int_reqs++;
3860 spin_unlock_irqrestore(&fotg210->lock, flags);
3871 list_for_each_entry_safe(qh, fotg210->qh_scan_next,
3872 &fotg210->intr_qh_list, intr_node) {
3875 if (!list_empty(&qh->qtd_list)) {
3880 * drops the lock. That's why fotg210->qh_scan_next
3882 * gets unlinked then fotg210->qh_scan_next is adjusted
3886 if (unlikely(qh->needs_rescan ||
3887 (list_empty(&qh->qtd_list) &&
3888 qh->qh_state == QH_STATE_LINKED)))
3904 INIT_LIST_HEAD(&stream->td_list);
3905 INIT_LIST_HEAD(&stream->free_list);
3906 stream->next_uframe = -1;
3929 maxp = usb_endpoint_maxp(&ep->desc);
3935 multi = usb_endpoint_maxp_mult(&ep->desc);
3939 stream->buf0 = cpu_to_hc32(fotg210, (epnum << 8) | dev->devnum);
3940 stream->buf1 = cpu_to_hc32(fotg210, buf1);
3941 stream->buf2 = cpu_to_hc32(fotg210, multi);
3946 if (dev->speed == USB_SPEED_FULL) {
3948 stream->usecs = NS_TO_US(usb_calc_bus_time(dev->speed,
3950 stream->usecs /= 8;
3952 stream->highspeed = 1;
3953 stream->usecs = HS_USECS_ISO(maxp);
3955 bandwidth = stream->usecs * 8;
3958 stream->bandwidth = bandwidth;
3959 stream->udev = dev;
3960 stream->bEndpointAddress = is_input | epnum;
3961 stream->interval = interval;
3962 stream->maxp = maxp;
3973 epnum = usb_pipeendpoint(urb->pipe);
3974 if (usb_pipein(urb->pipe))
3975 ep = urb->dev->ep_in[epnum];
3977 ep = urb->dev->ep_out[epnum];
3979 spin_lock_irqsave(&fotg210->lock, flags);
3980 stream = ep->hcpriv;
3985 ep->hcpriv = stream;
3986 stream->ep = ep;
3987 iso_stream_init(fotg210, stream, urb->dev, urb->pipe,
3988 urb->interval);
3991 /* if dev->ep[epnum] is a QH, hw is set */
3992 } else if (unlikely(stream->hw != NULL)) {
3994 urb->dev->devpath, epnum,
3995 usb_pipein(urb->pipe) ? "in" : "out");
3999 spin_unlock_irqrestore(&fotg210->lock, flags);
4003 /* fotg210_iso_sched ops can be ITD-only or SITD-only */
4012 INIT_LIST_HEAD(&iso_sched->td_list);
4022 dma_addr_t dma = urb->transfer_dma;
4025 iso_sched->span = urb->number_of_packets * stream->interval;
4027 /* figure out per-uframe itd fields that we'll need later
4030 for (i = 0; i < urb->number_of_packets; i++) {
4031 struct fotg210_iso_packet *uframe = &iso_sched->packet[i];
4036 length = urb->iso_frame_desc[i].length;
4037 buf = dma + urb->iso_frame_desc[i].offset;
4041 if (unlikely(((i + 1) == urb->number_of_packets))
4042 && !(urb->transfer_flags & URB_NO_INTERRUPT))
4045 uframe->transaction = cpu_to_hc32(fotg210, trans);
4048 uframe->bufp = (buf & ~(u64)0x0fff);
4050 if (unlikely((uframe->bufp != (buf & ~(u64)0x0fff))))
4051 uframe->cross = 1;
4060 /* caller must hold fotg210->lock!*/
4061 list_splice(&iso_sched->td_list, &stream->free_list);
4075 sched = iso_sched_alloc(urb->number_of_packets, mem_flags);
4077 return -ENOMEM;
4081 if (urb->interval < 8)
4082 num_itds = 1 + (sched->span + 7) / 8;
4084 num_itds = urb->number_of_packets;
4087 spin_lock_irqsave(&fotg210->lock, flags);
4094 if (likely(!list_empty(&stream->free_list))) {
4095 itd = list_first_entry(&stream->free_list,
4097 if (itd->frame == fotg210->now_frame)
4099 list_del(&itd->itd_list);
4100 itd_dma = itd->itd_dma;
4103 spin_unlock_irqrestore(&fotg210->lock, flags);
4104 itd = dma_pool_alloc(fotg210->itd_pool, mem_flags,
4106 spin_lock_irqsave(&fotg210->lock, flags);
4109 spin_unlock_irqrestore(&fotg210->lock, flags);
4110 return -ENOMEM;
4115 itd->itd_dma = itd_dma;
4116 list_add(&itd->itd_list, &sched->td_list);
4118 spin_unlock_irqrestore(&fotg210->lock, flags);
4121 urb->hcpriv = sched;
4122 urb->error_count = 0;
4133 > (fotg210->uframe_periodic_max - usecs))
4136 /* we know urb->interval is 2^N uframes */
4144 * "as small as possible" to be cache-friendlier.) That limits the size
4147 * by the per-urb URB_NO_INTERRUPT hint, the log2_irq_thresh module parameter,
4159 unsigned mod = fotg210->periodic_size << 3;
4160 struct fotg210_iso_sched *sched = urb->hcpriv;
4162 period = urb->interval;
4163 span = sched->span;
4165 if (span > mod - SCHEDULE_SLOP) {
4167 status = -EFBIG;
4171 now = fotg210_read_frame_index(fotg210) & (mod - 1);
4178 if (likely(!list_empty(&stream->td_list))) {
4182 * isochronous scheduling threshold. For full speed devices
4183 * and Intel PCI-based controllers, don't (work around for
4186 if (!stream->highspeed && fotg210->fs_i_thresh)
4187 next = now + fotg210->i_thresh;
4192 * We decide based on the time of the last currently-scheduled
4195 excess = (stream->next_uframe - period - next) & (mod - 1);
4196 if (excess >= mod - 2 * SCHEDULE_SLOP)
4197 start = next + excess - mod + period *
4198 DIV_ROUND_UP(mod - excess, period);
4201 if (start - now >= mod) {
4203 urb, start - now - period, period,
4205 status = -EFBIG;
4211 * this is bigger than fotg210->i_thresh allows; scheduling itself
4224 * Early uframes are more precious because full-speed
4231 start--;
4234 stream->usecs, period))
4242 status = -ENOSPC;
4248 if (unlikely(start - now + span - period >=
4249 mod - 2 * SCHEDULE_SLOP)) {
4251 urb, start - now, span - period,
4252 mod - 2 * SCHEDULE_SLOP);
4253 status = -EFBIG;
4257 stream->next_uframe = start & (mod - 1);
4260 urb->start_frame = stream->next_uframe;
4261 if (!stream->highspeed)
4262 urb->start_frame >>= 3;
4265 if (fotg210->isoc_count == 0)
4266 fotg210->next_frame = now >> 3;
4271 urb->hcpriv = NULL;
4281 itd->hw_next = FOTG210_LIST_END(fotg210);
4282 itd->hw_bufp[0] = stream->buf0;
4283 itd->hw_bufp[1] = stream->buf1;
4284 itd->hw_bufp[2] = stream->buf2;
4287 itd->index[i] = -1;
4296 struct fotg210_iso_packet *uf = &iso_sched->packet[index];
4297 unsigned pg = itd->pg;
4300 itd->index[uframe] = index;
4302 itd->hw_transaction[uframe] = uf->transaction;
4303 itd->hw_transaction[uframe] |= cpu_to_hc32(fotg210, pg << 12);
4304 itd->hw_bufp[pg] |= cpu_to_hc32(fotg210, uf->bufp & ~(u32)0);
4305 itd->hw_bufp_hi[pg] |= cpu_to_hc32(fotg210, (u32)(uf->bufp >> 32));
4308 if (unlikely(uf->cross)) {
4309 u64 bufp = uf->bufp + 4096;
4311 itd->pg = ++pg;
4312 itd->hw_bufp[pg] |= cpu_to_hc32(fotg210, bufp & ~(u32)0);
4313 itd->hw_bufp_hi[pg] |= cpu_to_hc32(fotg210, (u32)(bufp >> 32));
4320 union fotg210_shadow *prev = &fotg210->pshadow[frame];
4321 __hc32 *hw_p = &fotg210->periodic[frame];
4335 itd->itd_next = here;
4336 itd->hw_next = *hw_p;
4337 prev->itd = itd;
4338 itd->frame = frame;
4340 *hw_p = cpu_to_hc32(fotg210, itd->itd_dma | Q_TYPE_ITD);
4349 struct fotg210_iso_sched *iso_sched = urb->hcpriv;
4352 next_uframe = stream->next_uframe & (mod - 1);
4354 if (unlikely(list_empty(&stream->td_list))) {
4355 fotg210_to_hcd(fotg210)->self.bandwidth_allocated
4356 += stream->bandwidth;
4358 "schedule devp %s ep%d%s-iso period %d start %d.%d\n",
4359 urb->dev->devpath, stream->bEndpointAddress & 0x0f,
4360 (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out",
4361 urb->interval,
4366 for (packet = 0, itd = NULL; packet < urb->number_of_packets;) {
4372 itd = list_entry(iso_sched->td_list.next,
4374 list_move_tail(&itd->itd_list, &stream->td_list);
4375 itd->stream = stream;
4376 itd->urb = urb;
4385 next_uframe += stream->interval;
4386 next_uframe &= mod - 1;
4391 || packet == urb->number_of_packets) {
4392 itd_link(fotg210, frame & (fotg210->periodic_size - 1),
4397 stream->next_uframe = next_uframe;
4401 urb->hcpriv = NULL;
4403 ++fotg210->isoc_count;
4422 struct urb *urb = itd->urb;
4426 int urb_index = -1;
4427 struct fotg210_iso_stream *stream = itd->stream;
4433 if (likely(itd->index[uframe] == -1))
4435 urb_index = itd->index[uframe];
4436 desc = &urb->iso_frame_desc[urb_index];
4438 t = hc32_to_cpup(fotg210, &itd->hw_transaction[uframe]);
4439 itd->hw_transaction[uframe] = 0;
4443 urb->error_count++;
4445 desc->status = usb_pipein(urb->pipe)
4446 ? -ENOSR /* hc couldn't read */
4447 : -ECOMM; /* hc couldn't write */
4449 desc->status = -EOVERFLOW;
4451 desc->status = -EPROTO;
4455 desc->actual_length = FOTG210_ITD_LENGTH(t);
4456 urb->actual_length += desc->actual_length;
4459 desc->status = 0;
4460 desc->actual_length = FOTG210_ITD_LENGTH(t);
4461 urb->actual_length += desc->actual_length;
4464 desc->status = -EXDEV;
4469 if (likely((urb_index + 1) != urb->number_of_packets))
4473 * list_for_each_entry (itd, &stream->td_list, itd_list)
4474 * BUG_ON (itd->urb == urb);
4478 dev = urb->dev;
4483 --fotg210->isoc_count;
4486 if (unlikely(list_is_singular(&stream->td_list))) {
4487 fotg210_to_hcd(fotg210)->self.bandwidth_allocated
4488 -= stream->bandwidth;
4490 "deschedule devp %s ep%d%s-iso\n",
4491 dev->devpath, stream->bEndpointAddress & 0x0f,
4492 (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out");
4496 itd->urb = NULL;
4499 list_move_tail(&itd->itd_list, &stream->free_list);
4502 if (list_empty(&stream->td_list)) {
4503 list_splice_tail_init(&stream->free_list,
4504 &fotg210->cached_itd_list);
4514 int status = -EINVAL;
4522 return -ENOMEM;
4524 if (unlikely(urb->interval != stream->interval &&
4527 fotg210_dbg(fotg210, "can't change iso interval %d --> %d\n",
4528 stream->interval, urb->interval);
4535 __func__, urb->dev->devpath, urb,
4536 usb_pipeendpoint(urb->pipe),
4537 usb_pipein(urb->pipe) ? "in" : "out",
4538 urb->transfer_buffer_length,
4539 urb->number_of_packets, urb->interval,
4551 spin_lock_irqsave(&fotg210->lock, flags);
4553 status = -ESHUTDOWN;
4561 itd_link_urb(fotg210, urb, fotg210->periodic_size << 3, stream);
4565 spin_unlock_irqrestore(&fotg210->lock, flags);
4579 q_p = &fotg210->pshadow[frame];
4580 hw_p = &fotg210->periodic[frame];
4581 q.ptr = q_p->ptr;
4596 if (q.itd->hw_transaction[uf] &
4601 q_p = &q.itd->itd_next;
4602 hw_p = &q.itd->hw_next;
4604 q.itd->hw_next);
4615 *q_p = q.itd->itd_next;
4616 *hw_p = q.itd->hw_next;
4617 type = Q_NEXT_TYPE(fotg210, q.itd->hw_next);
4634 if (unlikely(modified && fotg210->isoc_count > 0))
4635 return -EINVAL;
4643 unsigned fmask = fotg210->periodic_size - 1;
4649 * Touches as few pages as possible: cache-friendly.
4651 if (fotg210->rh_state >= FOTG210_RH_RUNNING) {
4656 now_frame = (fotg210->next_frame - 1) & fmask;
4659 fotg210->now_frame = now_frame;
4661 frame = fotg210->next_frame;
4673 fotg210->next_frame = now_frame;
4684 return sysfs_emit(buf, "%d\n", fotg210->uframe_periodic_max);
4706 return -EINVAL;
4709 ret = -EINVAL;
4715 spin_lock_irqsave(&fotg210->lock, flags);
4722 if (uframe_periodic_max < fotg210->uframe_periodic_max) {
4725 for (frame = 0; frame < fotg210->periodic_size; ++frame)
4746 fotg210_warn(fotg210, "max periodic bandwidth set is non-standard\n");
4748 fotg210->uframe_periodic_max = uframe_periodic_max;
4752 spin_unlock_irqrestore(&fotg210->lock, flags);
4760 struct device *controller = fotg210_to_hcd(fotg210)->self.controller;
4767 struct device *controller = fotg210_to_hcd(fotg210)->self.controller;
4777 u32 __iomem *status_reg = &fotg210->regs->port_status;
4789 spin_lock_irq(&fotg210->lock);
4790 fotg210->rh_state = FOTG210_RH_HALTED;
4792 spin_unlock_irq(&fotg210->lock);
4803 spin_lock_irq(&fotg210->lock);
4804 fotg210->shutdown = true;
4805 fotg210->rh_state = FOTG210_RH_STOPPING;
4806 fotg210->enabled_hrtimer_events = 0;
4807 spin_unlock_irq(&fotg210->lock);
4811 hrtimer_cancel(&fotg210->hrtimer);
4815 * it calls driver completion functions, after dropping fotg210->lock.
4819 /* another CPU may drop fotg210->lock during a schedule scan while
4821 * attempts at re-entrant schedule scanning.
4823 if (fotg210->scanning) {
4824 fotg210->need_rescan = true;
4827 fotg210->scanning = true;
4830 fotg210->need_rescan = false;
4831 if (fotg210->async_count)
4833 if (fotg210->intr_count > 0)
4835 if (fotg210->isoc_count > 0)
4837 if (fotg210->need_rescan)
4839 fotg210->scanning = false;
4858 spin_lock_irq(&fotg210->lock);
4859 fotg210->enabled_hrtimer_events = 0;
4860 spin_unlock_irq(&fotg210->lock);
4866 hrtimer_cancel(&fotg210->hrtimer);
4871 spin_lock_irq(&fotg210->lock);
4873 spin_unlock_irq(&fotg210->lock);
4878 fotg210->stats.normal, fotg210->stats.error,
4879 fotg210->stats.iaa, fotg210->stats.lost_iaa);
4881 fotg210->stats.complete, fotg210->stats.unlink);
4885 fotg210_readl(fotg210, &fotg210->regs->status));
4888 /* one-time init, only for memory state */
4897 spin_lock_init(&fotg210->lock);
4902 fotg210->need_io_watchdog = 1;
4904 hrtimer_setup(&fotg210->hrtimer, fotg210_hrtimer_func, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
4905 fotg210->next_hrtimer_event = FOTG210_HRTIMER_NO_EVENT;
4907 hcc_params = fotg210_readl(fotg210, &fotg210->caps->hcc_params);
4913 fotg210->uframe_periodic_max = 100;
4919 fotg210->periodic_size = DEFAULT_I_TDPS;
4920 INIT_LIST_HEAD(&fotg210->intr_qh_list);
4921 INIT_LIST_HEAD(&fotg210->cached_itd_list);
4927 fotg210->periodic_size = 1024;
4930 fotg210->periodic_size = 512;
4933 fotg210->periodic_size = 256;
4944 fotg210->i_thresh = 2;
4953 fotg210->async->qh_next.qh = NULL;
4954 hw = fotg210->async->hw;
4955 hw->hw_next = QH_NEXT(fotg210, fotg210->async->qh_dma);
4956 hw->hw_info1 = cpu_to_hc32(fotg210, QH_HEAD);
4957 hw->hw_token = cpu_to_hc32(fotg210, QTD_STS_HALT);
4958 hw->hw_qtd_next = FOTG210_LIST_END(fotg210);
4959 fotg210->async->qh_state = QH_STATE_LINKED;
4960 hw->hw_alt_next = QTD_NEXT(fotg210, fotg210->async->dummy->qtd_dma);
4986 fotg210->command = temp;
4988 /* Accept arbitrarily long scatter-gather lists */
4989 if (!hcd->localmem_pool)
4990 hcd->self.sg_tablesize = ~0;
5000 hcd->uses_new_polling = 1;
5004 fotg210_writel(fotg210, fotg210->periodic_dma,
5005 &fotg210->regs->frame_list);
5006 fotg210_writel(fotg210, (u32)fotg210->async->qh_dma,
5007 &fotg210->regs->async_next);
5010 * hcc_params controls whether fotg210->regs->segment must (!!!)
5016 * NOTE: the dma mask is visible through dev->dma_mask, so
5021 fotg210_readl(fotg210, &fotg210->caps->hcc_params);
5027 fotg210->command &= ~(CMD_IAAD|CMD_PSE|CMD_ASE|CMD_RESET);
5028 fotg210->command |= CMD_RUN;
5029 fotg210_writel(fotg210, fotg210->command, &fotg210->regs->command);
5030 dbg_cmd(fotg210, "init", fotg210->command);
5041 * could cause trouble. Write-locking ehci_cf_port_reset_rwsem
5047 fotg210->rh_state = FOTG210_RH_RUNNING;
5049 fotg210_readl(fotg210, &fotg210->regs->command);
5052 fotg210->last_periodic_enable = ktime_get_real();
5055 fotg210_readl(fotg210, &fotg210->caps->hc_capbase));
5058 ((fotg210->sbrn & 0xf0) >> 4), (fotg210->sbrn & 0x0f),
5062 &fotg210->regs->intr_enable); /* Turn On Interrupts */
5064 /* GRR this is run-once init(), being done every time the HC starts.
5079 fotg210->regs = (void __iomem *)fotg210->caps +
5081 fotg210_readl(fotg210, &fotg210->caps->hc_capbase));
5086 fotg210->hcs_params = fotg210_readl(fotg210,
5087 &fotg210->caps->hcs_params);
5089 fotg210->sbrn = HCD_USB2;
5111 spin_lock(&fotg210->lock);
5113 status = fotg210_readl(fotg210, &fotg210->regs->status);
5129 unlikely(fotg210->rh_state == FOTG210_RH_HALTED)) {
5130 spin_unlock(&fotg210->lock);
5135 fotg210_writel(fotg210, masked_status, &fotg210->regs->status);
5136 cmd = fotg210_readl(fotg210, &fotg210->regs->command);
5147 INCR(fotg210->stats.normal);
5149 INCR(fotg210->stats.error);
5157 fotg210->enabled_hrtimer_events &=
5167 if (fotg210->next_hrtimer_event == FOTG210_HRTIMER_IAA_WATCHDOG)
5168 ++fotg210->next_hrtimer_event;
5173 if (fotg210->async_iaa) {
5174 INCR(fotg210->stats.iaa);
5183 u32 __iomem *status_reg = &fotg210->regs->port_status;
5189 if (fotg210->rh_state == FOTG210_RH_SUSPENDED)
5194 if (test_bit(0, &fotg210->suspended_ports) &&
5198 fotg210->reset_done[0] == 0) {
5205 fotg210->reset_done[0] = jiffies + msecs_to_jiffies(25);
5206 set_bit(0, &fotg210->resuming_ports);
5208 mod_timer(&hcd->rh_timer, fotg210->reset_done[0]);
5221 fotg210->shutdown = true;
5222 fotg210->rh_state = FOTG210_RH_STOPPING;
5223 fotg210->command &= ~(CMD_RUN | CMD_ASE | CMD_PSE);
5224 fotg210_writel(fotg210, fotg210->command,
5225 &fotg210->regs->command);
5226 fotg210_writel(fotg210, 0, &fotg210->regs->intr_enable);
5235 spin_unlock(&fotg210->lock);
5241 /* non-error returns are a promise to giveback() the urb later
5247 * hcd-specific init for hcpriv hasn't been done yet
5260 switch (usb_pipetype(urb->pipe)) {
5263 * in multi-TD control transfers. Even 1KB is rare anyway.
5265 if (urb->transfer_buffer_length > (16 * 1024))
5266 return -EMSGSIZE;
5271 return -ENOMEM;
5276 return -ENOMEM;
5295 spin_lock_irqsave(&fotg210->lock, flags);
5300 switch (usb_pipetype(urb->pipe)) {
5304 qh = (struct fotg210_qh *) urb->hcpriv;
5307 switch (qh->qh_state) {
5317 /* QH might be waiting for a Clear-TT-Buffer */
5324 qh = (struct fotg210_qh *) urb->hcpriv;
5327 switch (qh->qh_state) {
5337 qh, qh->qh_state);
5350 spin_unlock_irqrestore(&fotg210->lock, flags);
5367 spin_lock_irqsave(&fotg210->lock, flags);
5368 qh = ep->hcpriv;
5375 if (qh->hw == NULL) {
5376 struct fotg210_iso_stream *stream = ep->hcpriv;
5378 if (!list_empty(&stream->td_list))
5381 /* BUG_ON(!list_empty(&stream->free_list)); */
5386 if (fotg210->rh_state < FOTG210_RH_RUNNING)
5387 qh->qh_state = QH_STATE_IDLE;
5388 switch (qh->qh_state) {
5391 for (tmp = fotg210->async->qh_next.qh;
5393 tmp = tmp->qh_next.qh)
5395 /* periodic qh self-unlinks on empty, and a COMPLETING qh
5404 spin_unlock_irqrestore(&fotg210->lock, flags);
5408 if (qh->clearing_tt)
5410 if (list_empty(&qh->qtd_list)) {
5420 qh, ep->desc.bEndpointAddress, qh->qh_state,
5421 list_empty(&qh->qtd_list) ? "" : "(has tds)");
5425 ep->hcpriv = NULL;
5426 spin_unlock_irqrestore(&fotg210->lock, flags);
5434 int eptype = usb_endpoint_type(&ep->desc);
5435 int epnum = usb_endpoint_num(&ep->desc);
5436 int is_out = usb_endpoint_dir_out(&ep->desc);
5442 spin_lock_irqsave(&fotg210->lock, flags);
5443 qh = ep->hcpriv;
5451 usb_settoggle(qh->dev, epnum, is_out, 0);
5452 if (!list_empty(&qh->qtd_list)) {
5454 } else if (qh->qh_state == QH_STATE_LINKED ||
5455 qh->qh_state == QH_STATE_COMPLETING) {
5459 * re-linking will call qh_refresh().
5467 spin_unlock_irqrestore(&fotg210->lock, flags);
5475 fotg210->periodic_size;
5535 &fotg210->regs->gmir);
5537 value = ioread32(&fotg210->regs->otgcsr);
5540 iowrite32(value, &fotg210->regs->otgcsr);
5544 * fotg210_hcd_probe - initialize faraday FOTG210 HCDs
5552 struct device *dev = &pdev->dev;
5559 return -ENODEV;
5561 pdev->dev.power.power_state = PMSG_ON;
5570 retval = dev_err_probe(dev, -ENOMEM, "failed to create hcd\n");
5574 hcd->has_tt = 1;
5576 hcd->regs = fotg->base;
5578 hcd->rsrc_start = fotg->res->start;
5579 hcd->rsrc_len = resource_size(fotg->res);
5583 fotg210->fotg = fotg;
5584 fotg210->caps = hcd->regs;
5597 device_wakeup_enable(hcd->self.controller);
5609 * fotg210_hcd_remove - shutdown processing for EHCI HCDs
5626 return -ENODEV;