Lines Matching +full:overrun +full:- +full:throttle +full:- +full:ms

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