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>
42 #define DRIVER_AUTHOR "Yuan-Hsin Chen"
50 #define FOTG210_TUNE_CERR 3 /* 0-3 qtd retries; 0 == don't stop */
51 #define FOTG210_TUNE_RL_HS 4 /* nak throttle; see 4.9 */
53 #define FOTG210_TUNE_MULT_HS 1 /* 1-3 transactions/uframe; 4.10.3 */
57 * ms into the future (partly as a result of an old bug in the scheduling
61 #define FOTG210_TUNE_FLS 1 /* (medium) 512-frame schedule */
66 MODULE_PARM_DESC(log2_irq_thresh, "log2 IRQ latency, 1-64 microframes");
71 MODULE_PARM_DESC(park, "park setting; 1-3 back-to-back async packets");
83 dev_dbg(fotg210_to_hcd(fotg210)->self.controller, fmt, ## args)
85 dev_err(fotg210_to_hcd(fotg210)->self.controller, fmt, ## args)
87 dev_info(fotg210_to_hcd(fotg210)->self.controller, fmt, ## args)
89 dev_warn(fotg210_to_hcd(fotg210)->self.controller, fmt, ## args)
92 * parameters) see EHCI spec, Table 2-4 for each value
96 u32 params = fotg210_readl(fotg210, &fotg210->caps->hcs_params); in dbg_hcs_params()
103 * parameters) see EHCI Spec, Table 2-5 for each value
107 u32 params = fotg210_readl(fotg210, &fotg210->caps->hcc_params); in dbg_hcc_params()
119 hc32_to_cpup(fotg210, &qtd->hw_next), in dbg_qtd()
120 hc32_to_cpup(fotg210, &qtd->hw_alt_next), in dbg_qtd()
121 hc32_to_cpup(fotg210, &qtd->hw_token), in dbg_qtd()
122 hc32_to_cpup(fotg210, &qtd->hw_buf[0])); in dbg_qtd()
123 if (qtd->hw_buf[1]) in dbg_qtd()
125 hc32_to_cpup(fotg210, &qtd->hw_buf[1]), in dbg_qtd()
126 hc32_to_cpup(fotg210, &qtd->hw_buf[2]), in dbg_qtd()
127 hc32_to_cpup(fotg210, &qtd->hw_buf[3]), in dbg_qtd()
128 hc32_to_cpup(fotg210, &qtd->hw_buf[4])); in dbg_qtd()
134 struct fotg210_qh_hw *hw = qh->hw; in dbg_qh()
137 hw->hw_next, hw->hw_info1, hw->hw_info2, in dbg_qh()
138 hw->hw_current); in dbg_qh()
140 dbg_qtd("overlay", fotg210, (struct fotg210_qtd *) &hw->hw_qtd_next); in dbg_qh()
147 itd->frame, itd, hc32_to_cpu(fotg210, itd->hw_next), in dbg_itd()
148 itd->urb); in dbg_itd()
152 hc32_to_cpu(fotg210, itd->hw_transaction[0]), in dbg_itd()
153 hc32_to_cpu(fotg210, itd->hw_transaction[1]), in dbg_itd()
154 hc32_to_cpu(fotg210, itd->hw_transaction[2]), in dbg_itd()
155 hc32_to_cpu(fotg210, itd->hw_transaction[3]), in dbg_itd()
156 hc32_to_cpu(fotg210, itd->hw_transaction[4]), in dbg_itd()
157 hc32_to_cpu(fotg210, itd->hw_transaction[5]), in dbg_itd()
158 hc32_to_cpu(fotg210, itd->hw_transaction[6]), in dbg_itd()
159 hc32_to_cpu(fotg210, itd->hw_transaction[7])); in dbg_itd()
163 hc32_to_cpu(fotg210, itd->hw_bufp[0]), in dbg_itd()
164 hc32_to_cpu(fotg210, itd->hw_bufp[1]), in dbg_itd()
165 hc32_to_cpu(fotg210, itd->hw_bufp[2]), in dbg_itd()
166 hc32_to_cpu(fotg210, itd->hw_bufp[3]), in dbg_itd()
167 hc32_to_cpu(fotg210, itd->hw_bufp[4]), in dbg_itd()
168 hc32_to_cpu(fotg210, itd->hw_bufp[5]), in dbg_itd()
169 hc32_to_cpu(fotg210, itd->hw_bufp[6])); in dbg_itd()
172 itd->index[0], itd->index[1], itd->index[2], in dbg_itd()
173 itd->index[3], itd->index[4], itd->index[5], in dbg_itd()
174 itd->index[6], itd->index[7]); in dbg_itd()
347 return '-'; in token_mark()
365 struct fotg210_qh_hw *hw = qh->hw; in qh_lines()
367 if (hw->hw_qtd_next == list_end) /* NEC does this */ in qh_lines()
370 mark = token_mark(fotg210, hw->hw_token); in qh_lines()
372 if ((hw->hw_alt_next & QTD_MASK(fotg210)) == in qh_lines()
373 fotg210->async->hw->hw_alt_next) in qh_lines()
375 else if (hw->hw_alt_next == list_end) in qh_lines()
379 scratch = hc32_to_cpup(fotg210, &hw->hw_info1); in qh_lines()
380 hw_curr = (mark == '*') ? hc32_to_cpup(fotg210, &hw->hw_current) : 0; in qh_lines()
386 scratch, hc32_to_cpup(fotg210, &hw->hw_info2), in qh_lines()
387 hc32_to_cpup(fotg210, &hw->hw_token), mark, in qh_lines()
388 (cpu_to_hc32(fotg210, QTD_TOGGLE) & hw->hw_token) in qh_lines()
390 (hc32_to_cpup(fotg210, &hw->hw_alt_next) >> 1) & 0x0f); in qh_lines()
391 size -= temp; in qh_lines()
395 list_for_each_entry(td, &qh->qtd_list, qtd_list) { in qh_lines()
396 scratch = hc32_to_cpup(fotg210, &td->hw_token); in qh_lines()
398 if (hw_curr == td->qtd_dma) in qh_lines()
400 else if (hw->hw_qtd_next == cpu_to_hc32(fotg210, td->qtd_dma)) in qh_lines()
403 if (td->hw_alt_next == fotg210->async->hw->hw_alt_next) in qh_lines()
405 else if (td->hw_alt_next != list_end) in qh_lines()
427 td->urb); in qh_lines()
430 size -= temp; in qh_lines()
440 size -= temp; in qh_lines()
457 hcd = bus_to_hcd(buf->bus); in fill_async_buffer()
459 next = buf->output_buf; in fill_async_buffer()
460 size = buf->alloc_size; in fill_async_buffer()
465 * usually empty except for long-term bulk reads, or head. in fill_async_buffer()
468 spin_lock_irqsave(&fotg210->lock, flags); in fill_async_buffer()
469 for (qh = fotg210->async->qh_next.qh; size > 0 && qh; in fill_async_buffer()
470 qh = qh->qh_next.qh) in fill_async_buffer()
472 if (fotg210->async_unlink && size > 0) { in fill_async_buffer()
474 size -= temp; in fill_async_buffer()
477 for (qh = fotg210->async_unlink; size > 0 && qh; in fill_async_buffer()
478 qh = qh->unlink_next) in fill_async_buffer()
481 spin_unlock_irqrestore(&fotg210->lock, flags); in fill_async_buffer()
483 return strlen(buf->output_buf); in fill_async_buffer()
490 u32 scratch = hc32_to_cpup(fotg210, &hw->hw_info1); in output_buf_tds_dir()
496 list_for_each_entry(qtd, &qh->qtd_list, qtd_list) { in output_buf_tds_dir()
498 switch ((hc32_to_cpu(fotg210, qtd->hw_token) >> 8) & 0x03) { in output_buf_tds_dir()
510 (scratch >> 8) & 0x000f, type, qh->usecs, in output_buf_tds_dir()
511 qh->c_usecs, temp, (scratch >> 16) & 0x7ff); in output_buf_tds_dir()
532 hcd = bus_to_hcd(buf->bus); in fill_periodic_buffer()
534 next = buf->output_buf; in fill_periodic_buffer()
535 size = buf->alloc_size; in fill_periodic_buffer()
537 temp = scnprintf(next, size, "size = %d\n", fotg210->periodic_size); in fill_periodic_buffer()
538 size -= temp; in fill_periodic_buffer()
544 spin_lock_irqsave(&fotg210->lock, flags); in fill_periodic_buffer()
545 for (i = 0; i < fotg210->periodic_size; i++) { in fill_periodic_buffer()
546 p = fotg210->pshadow[i]; in fill_periodic_buffer()
550 tag = Q_NEXT_TYPE(fotg210, fotg210->periodic[i]); in fill_periodic_buffer()
553 size -= temp; in fill_periodic_buffer()
561 hw = p.qh->hw; in fill_periodic_buffer()
562 temp = scnprintf(next, size, " qh%d-%04x/%p", in fill_periodic_buffer()
563 p.qh->period, in fill_periodic_buffer()
565 &hw->hw_info2) in fill_periodic_buffer()
569 size -= temp; in fill_periodic_buffer()
575 if (p.qh->qh_next.ptr) { in fill_periodic_buffer()
578 size -= temp; in fill_periodic_buffer()
593 tag = Q_NEXT_TYPE(fotg210, hw->hw_next); in fill_periodic_buffer()
594 p = p.qh->qh_next; in fill_periodic_buffer()
598 " fstn-%8x/%p", in fill_periodic_buffer()
599 p.fstn->hw_prev, p.fstn); in fill_periodic_buffer()
600 tag = Q_NEXT_TYPE(fotg210, p.fstn->hw_next); in fill_periodic_buffer()
601 p = p.fstn->fstn_next; in fill_periodic_buffer()
606 tag = Q_NEXT_TYPE(fotg210, p.itd->hw_next); in fill_periodic_buffer()
607 p = p.itd->itd_next; in fill_periodic_buffer()
610 size -= temp; in fill_periodic_buffer()
615 size -= temp; in fill_periodic_buffer()
618 spin_unlock_irqrestore(&fotg210->lock, flags); in fill_periodic_buffer()
621 return buf->alloc_size - size; in fill_periodic_buffer()
627 switch (fotg210->rh_state) { in rh_state_string()
650 hcd = bus_to_hcd(buf->bus); in fill_registers_buffer()
652 next = buf->output_buf; in fill_registers_buffer()
653 size = buf->alloc_size; in fill_registers_buffer()
655 spin_lock_irqsave(&fotg210->lock, flags); in fill_registers_buffer()
662 hcd->self.controller->bus->name, in fill_registers_buffer()
663 dev_name(hcd->self.controller), in fill_registers_buffer()
664 hcd->product_desc); in fill_registers_buffer()
670 &fotg210->caps->hc_capbase)); in fill_registers_buffer()
675 hcd->self.controller->bus->name, in fill_registers_buffer()
676 dev_name(hcd->self.controller), in fill_registers_buffer()
677 hcd->product_desc, in fill_registers_buffer()
679 size -= temp; in fill_registers_buffer()
683 i = fotg210_readl(fotg210, &fotg210->caps->hcs_params); in fill_registers_buffer()
685 size -= temp; in fill_registers_buffer()
688 i = fotg210_readl(fotg210, &fotg210->caps->hcc_params); in fill_registers_buffer()
690 size -= temp; in fill_registers_buffer()
695 fotg210_readl(fotg210, &fotg210->regs->status)); in fill_registers_buffer()
697 size -= temp; in fill_registers_buffer()
701 fotg210_readl(fotg210, &fotg210->regs->command)); in fill_registers_buffer()
703 size -= temp; in fill_registers_buffer()
707 fotg210_readl(fotg210, &fotg210->regs->intr_enable)); in fill_registers_buffer()
709 size -= temp; in fill_registers_buffer()
714 size -= temp; in fill_registers_buffer()
717 if (fotg210->async_unlink) { in fill_registers_buffer()
719 fotg210->async_unlink); in fill_registers_buffer()
720 size -= temp; in fill_registers_buffer()
727 fotg210->stats.normal, fotg210->stats.error, in fill_registers_buffer()
728 fotg210->stats.iaa, fotg210->stats.lost_iaa); in fill_registers_buffer()
729 size -= temp; in fill_registers_buffer()
733 fotg210->stats.complete, fotg210->stats.unlink); in fill_registers_buffer()
734 size -= temp; in fill_registers_buffer()
739 spin_unlock_irqrestore(&fotg210->lock, flags); in fill_registers_buffer()
741 return buf->alloc_size - size; in fill_registers_buffer()
752 buf->bus = bus; in alloc_buffer()
753 buf->fill_func = fill_func; in alloc_buffer()
754 mutex_init(&buf->mutex); in alloc_buffer()
755 buf->alloc_size = PAGE_SIZE; in alloc_buffer()
765 if (!buf->output_buf) in fill_buffer()
766 buf->output_buf = vmalloc(buf->alloc_size); in fill_buffer()
768 if (!buf->output_buf) { in fill_buffer()
769 ret = -ENOMEM; in fill_buffer()
773 ret = buf->fill_func(buf); in fill_buffer()
776 buf->count = ret; in fill_buffer()
787 struct debug_buffer *buf = file->private_data; in debug_output()
790 mutex_lock(&buf->mutex); in debug_output()
791 if (buf->count == 0) { in debug_output()
794 mutex_unlock(&buf->mutex); in debug_output()
798 mutex_unlock(&buf->mutex); in debug_output()
801 buf->output_buf, buf->count); in debug_output()
810 struct debug_buffer *buf = file->private_data; in debug_close()
813 vfree(buf->output_buf); in debug_close()
821 file->private_data = alloc_buffer(inode->i_private, fill_async_buffer); in debug_async_open()
823 return file->private_data ? 0 : -ENOMEM; in debug_async_open()
830 buf = alloc_buffer(inode->i_private, fill_periodic_buffer); in debug_periodic_open()
832 return -ENOMEM; in debug_periodic_open()
834 buf->alloc_size = (sizeof(void *) == 4 ? 6 : 8)*PAGE_SIZE; in debug_periodic_open()
835 file->private_data = buf; in debug_periodic_open()
841 file->private_data = alloc_buffer(inode->i_private, in debug_registers_open()
844 return file->private_data ? 0 : -ENOMEM; in debug_registers_open()
849 struct usb_bus *bus = &fotg210_to_hcd(fotg210)->self; in create_debug_files()
852 root = debugfs_create_dir(bus->bus_name, fotg210_debug_root); in create_debug_files()
863 struct usb_bus *bus = &fotg210_to_hcd(fotg210)->self; in remove_debug_files()
865 debugfs_remove(debugfs_lookup(bus->bus_name, fotg210_debug_root)); in remove_debug_files()
868 /* handshake - spin reading hc until handshake completes or fails
878 * hardware flakeout), or the register reads as all-ones (hardware removed).
894 return -ENODEV; in handshake()
906 spin_lock_irq(&fotg210->lock); in fotg210_halt()
909 fotg210_writel(fotg210, 0, &fotg210->regs->intr_enable); in fotg210_halt()
912 * This routine gets called during probe before fotg210->command in fotg210_halt()
915 fotg210->command &= ~CMD_RUN; in fotg210_halt()
916 temp = fotg210_readl(fotg210, &fotg210->regs->command); in fotg210_halt()
918 fotg210_writel(fotg210, temp, &fotg210->regs->command); in fotg210_halt()
920 spin_unlock_irq(&fotg210->lock); in fotg210_halt()
921 synchronize_irq(fotg210_to_hcd(fotg210)->irq); in fotg210_halt()
923 return handshake(fotg210, &fotg210->regs->status, in fotg210_halt()
927 /* Reset a non-running (STS_HALT == 1) controller.
933 u32 command = fotg210_readl(fotg210, &fotg210->regs->command); in fotg210_reset()
938 if (fotg210->debug && !dbgp_reset_prep(fotg210_to_hcd(fotg210))) in fotg210_reset()
939 fotg210->debug = NULL; in fotg210_reset()
943 fotg210_writel(fotg210, command, &fotg210->regs->command); in fotg210_reset()
944 fotg210->rh_state = FOTG210_RH_HALTED; in fotg210_reset()
945 fotg210->next_statechange = jiffies; in fotg210_reset()
946 retval = handshake(fotg210, &fotg210->regs->command, in fotg210_reset()
952 if (fotg210->debug) in fotg210_reset()
955 fotg210->port_c_suspend = fotg210->suspended_ports = in fotg210_reset()
956 fotg210->resuming_ports = 0; in fotg210_reset()
967 if (fotg210->rh_state != FOTG210_RH_RUNNING) in fotg210_quiesce()
971 temp = (fotg210->command << 10) & (STS_ASS | STS_PSS); in fotg210_quiesce()
972 handshake(fotg210, &fotg210->regs->status, STS_ASS | STS_PSS, temp, in fotg210_quiesce()
976 spin_lock_irq(&fotg210->lock); in fotg210_quiesce()
977 fotg210->command &= ~(CMD_ASE | CMD_PSE); in fotg210_quiesce()
978 fotg210_writel(fotg210, fotg210->command, &fotg210->regs->command); in fotg210_quiesce()
979 spin_unlock_irq(&fotg210->lock); in fotg210_quiesce()
982 handshake(fotg210, &fotg210->regs->status, STS_ASS | STS_PSS, 0, in fotg210_quiesce()
996 fotg210->command |= bit; in fotg210_set_command_bit()
997 fotg210_writel(fotg210, fotg210->command, &fotg210->regs->command); in fotg210_set_command_bit()
1000 fotg210_readl(fotg210, &fotg210->regs->command); in fotg210_set_command_bit()
1006 fotg210->command &= ~bit; in fotg210_clear_command_bit()
1007 fotg210_writel(fotg210, fotg210->command, &fotg210->regs->command); in fotg210_clear_command_bit()
1010 fotg210_readl(fotg210, &fotg210->regs->command); in fotg210_clear_command_bit()
1015 * Lots of different events are triggered from fotg210->hrtimer. Whenever
1019 * fotg210->enabled_hrtimer_events, and they are numbered in order of
1020 * increasing delay values (ranging between 1 ms and 100 ms).
1023 * we keep track only of the lowest-numbered pending event, in
1024 * fotg210->next_hrtimer_event. Whenever fotg210->hrtimer gets restarted, its
1029 * matter, because none of the events are especially time-critical. The
1030 * ones that matter most all have a delay of 1 ms, so they will be
1031 * handled after 2 ms at most, which is okay. In addition to this, we
1032 * allow for an expiration range of 1 ms.
1056 ktime_t *timeout = &fotg210->hr_timeouts[event]; in fotg210_enable_event()
1060 fotg210->enabled_hrtimer_events |= (1 << event); in fotg210_enable_event()
1062 /* Track only the lowest-numbered pending event */ in fotg210_enable_event()
1063 if (event < fotg210->next_hrtimer_event) { in fotg210_enable_event()
1064 fotg210->next_hrtimer_event = event; in fotg210_enable_event()
1065 hrtimer_start_range_ns(&fotg210->hrtimer, *timeout, in fotg210_enable_event()
1077 if (fotg210->rh_state != FOTG210_RH_RUNNING) in fotg210_poll_ASS()
1080 want = (fotg210->command & CMD_ASE) ? STS_ASS : 0; in fotg210_poll_ASS()
1081 actual = fotg210_readl(fotg210, &fotg210->regs->status) & STS_ASS; in fotg210_poll_ASS()
1085 /* Poll again later, but give up after about 20 ms */ in fotg210_poll_ASS()
1086 if (fotg210->ASS_poll_count++ < 20) { in fotg210_poll_ASS()
1094 fotg210->ASS_poll_count = 0; in fotg210_poll_ASS()
1096 /* The status is up-to-date; restart or stop the schedule as needed */ in fotg210_poll_ASS()
1098 if (fotg210->async_count > 0) in fotg210_poll_ASS()
1102 if (fotg210->async_count == 0) { in fotg210_poll_ASS()
1125 if (fotg210->rh_state != FOTG210_RH_RUNNING) in fotg210_poll_PSS()
1128 want = (fotg210->command & CMD_PSE) ? STS_PSS : 0; in fotg210_poll_PSS()
1129 actual = fotg210_readl(fotg210, &fotg210->regs->status) & STS_PSS; in fotg210_poll_PSS()
1133 /* Poll again later, but give up after about 20 ms */ in fotg210_poll_PSS()
1134 if (fotg210->PSS_poll_count++ < 20) { in fotg210_poll_PSS()
1142 fotg210->PSS_poll_count = 0; in fotg210_poll_PSS()
1144 /* The status is up-to-date; restart or stop the schedule as needed */ in fotg210_poll_PSS()
1146 if (fotg210->periodic_count > 0) in fotg210_poll_PSS()
1150 if (fotg210->periodic_count == 0) { in fotg210_poll_PSS()
1170 if (!(fotg210_readl(fotg210, &fotg210->regs->status) & STS_HALT)) { in fotg210_handle_controller_death()
1173 if (fotg210->died_poll_count++ < 5) { in fotg210_handle_controller_death()
1183 fotg210->rh_state = FOTG210_RH_HALTED; in fotg210_handle_controller_death()
1184 fotg210_writel(fotg210, 0, &fotg210->regs->intr_enable); in fotg210_handle_controller_death()
1195 bool stopped = (fotg210->rh_state < FOTG210_RH_RUNNING); in fotg210_handle_intr_unlinks()
1204 fotg210->intr_unlinking = true; in fotg210_handle_intr_unlinks()
1205 while (fotg210->intr_unlink) { in fotg210_handle_intr_unlinks()
1206 struct fotg210_qh *qh = fotg210->intr_unlink; in fotg210_handle_intr_unlinks()
1208 if (!stopped && qh->unlink_cycle == fotg210->intr_unlink_cycle) in fotg210_handle_intr_unlinks()
1210 fotg210->intr_unlink = qh->unlink_next; in fotg210_handle_intr_unlinks()
1211 qh->unlink_next = NULL; in fotg210_handle_intr_unlinks()
1216 if (fotg210->intr_unlink) { in fotg210_handle_intr_unlinks()
1219 ++fotg210->intr_unlink_cycle; in fotg210_handle_intr_unlinks()
1221 fotg210->intr_unlinking = false; in fotg210_handle_intr_unlinks()
1225 /* Start another free-iTDs/siTDs cycle */
1228 if (!(fotg210->enabled_hrtimer_events & in start_free_itds()
1230 fotg210->last_itd_to_free = list_entry( in start_free_itds()
1231 fotg210->cached_itd_list.prev, in start_free_itds()
1242 if (fotg210->rh_state < FOTG210_RH_RUNNING) in end_free_itds()
1243 fotg210->last_itd_to_free = NULL; in end_free_itds()
1245 list_for_each_entry_safe(itd, n, &fotg210->cached_itd_list, itd_list) { in end_free_itds()
1246 list_del(&itd->itd_list); in end_free_itds()
1247 dma_pool_free(fotg210->itd_pool, itd, itd->itd_dma); in end_free_itds()
1248 if (itd == fotg210->last_itd_to_free) in end_free_itds()
1252 if (!list_empty(&fotg210->cached_itd_list)) in end_free_itds()
1260 if (fotg210->rh_state != FOTG210_RH_RUNNING) in fotg210_iaa_watchdog()
1269 if (fotg210->async_iaa) { in fotg210_iaa_watchdog()
1278 cmd = fotg210_readl(fotg210, &fotg210->regs->command); in fotg210_iaa_watchdog()
1284 * - VIA seems to set IAA without triggering the IRQ; in fotg210_iaa_watchdog()
1285 * - IAAD potentially cleared without setting IAA. in fotg210_iaa_watchdog()
1287 status = fotg210_readl(fotg210, &fotg210->regs->status); in fotg210_iaa_watchdog()
1289 INCR(fotg210->stats.lost_iaa); in fotg210_iaa_watchdog()
1291 &fotg210->regs->status); in fotg210_iaa_watchdog()
1305 if (fotg210->rh_state != FOTG210_RH_RUNNING || in turn_on_io_watchdog()
1306 (fotg210->enabled_hrtimer_events & in turn_on_io_watchdog()
1314 if (fotg210->isoc_count > 0 || (fotg210->need_io_watchdog && in turn_on_io_watchdog()
1315 fotg210->async_count + fotg210->intr_count > 0)) in turn_on_io_watchdog()
1347 spin_lock_irqsave(&fotg210->lock, flags); in fotg210_hrtimer_func()
1349 events = fotg210->enabled_hrtimer_events; in fotg210_hrtimer_func()
1350 fotg210->enabled_hrtimer_events = 0; in fotg210_hrtimer_func()
1351 fotg210->next_hrtimer_event = FOTG210_HRTIMER_NO_EVENT; in fotg210_hrtimer_func()
1355 * the event; otherwise re-enable it. in fotg210_hrtimer_func()
1359 if (ktime_compare(now, fotg210->hr_timeouts[e]) >= 0) in fotg210_hrtimer_func()
1365 spin_unlock_irqrestore(&fotg210->lock, flags); in fotg210_hrtimer_func()
1378 /* if reset finished and it's still not enabled -- handoff */ in check_reset_complete()
1401 /* init status to no-changes */ in fotg210_hub_status_data()
1404 /* Inform the core about resumes-in-progress by returning in fotg210_hub_status_data()
1405 * a non-zero value even if there are no status changes. in fotg210_hub_status_data()
1407 status = fotg210->resuming_ports; in fotg210_hub_status_data()
1415 spin_lock_irqsave(&fotg210->lock, flags); in fotg210_hub_status_data()
1417 temp = fotg210_readl(fotg210, &fotg210->regs->port_status); in fotg210_hub_status_data()
1422 * high-speed device is switched over to the companion in fotg210_hub_status_data()
1426 if ((temp & mask) != 0 || test_bit(0, &fotg210->port_c_suspend) || in fotg210_hub_status_data()
1427 (fotg210->reset_done[0] && in fotg210_hub_status_data()
1428 time_after_eq(jiffies, fotg210->reset_done[0]))) { in fotg210_hub_status_data()
1433 spin_unlock_irqrestore(&fotg210->lock, flags); in fotg210_hub_status_data()
1440 int ports = HCS_N_PORTS(fotg210->hcs_params); in fotg210_hub_descriptor()
1443 desc->bDescriptorType = USB_DT_HUB; in fotg210_hub_descriptor()
1444 desc->bPwrOn2PwrGood = 10; /* fotg210 1.0, 2.3.9 says 20ms max */ in fotg210_hub_descriptor()
1445 desc->bHubContrCurrent = 0; in fotg210_hub_descriptor()
1447 desc->bNbrPorts = ports; in fotg210_hub_descriptor()
1449 desc->bDescLength = 7 + 2 * temp; in fotg210_hub_descriptor()
1452 memset(&desc->u.hs.DeviceRemovable[0], 0, temp); in fotg210_hub_descriptor()
1453 memset(&desc->u.hs.DeviceRemovable[temp], 0xff, temp); in fotg210_hub_descriptor()
1455 temp = HUB_CHAR_INDV_PORT_OCPM; /* per-port overcurrent reporting */ in fotg210_hub_descriptor()
1457 desc->wHubCharacteristics = cpu_to_le16(temp); in fotg210_hub_descriptor()
1464 int ports = HCS_N_PORTS(fotg210->hcs_params); in fotg210_hub_control()
1465 u32 __iomem *status_reg = &fotg210->regs->port_status; in fotg210_hub_control()
1478 spin_lock_irqsave(&fotg210->lock, flags); in fotg210_hub_control()
1484 /* no hub-wide feature/status flags */ in fotg210_hub_control()
1493 wIndex--; in fotg210_hub_control()
1500 * the port-change status bits (especially in fotg210_hub_control()
1521 fotg210->reset_done[wIndex] = jiffies in fotg210_hub_control()
1525 clear_bit(wIndex, &fotg210->port_c_suspend); in fotg210_hub_control()
1532 &fotg210->regs->otgisr); in fotg210_hub_control()
1540 fotg210_readl(fotg210, &fotg210->regs->command); in fotg210_hub_control()
1547 /* no hub-wide feature/status flags */ in fotg210_hub_control()
1554 wIndex--; in fotg210_hub_control()
1564 temp1 = fotg210_readl(fotg210, &fotg210->regs->otgisr); in fotg210_hub_control()
1572 if (!fotg210->reset_done[wIndex]) { in fotg210_hub_control()
1574 fotg210->reset_done[wIndex] = jiffies in fotg210_hub_control()
1577 mod_timer(&fotg210_to_hcd(fotg210)->rh_timer, in fotg210_hub_control()
1578 fotg210->reset_done[wIndex]); in fotg210_hub_control()
1583 fotg210->reset_done[wIndex])) { in fotg210_hub_control()
1584 clear_bit(wIndex, &fotg210->suspended_ports); in fotg210_hub_control()
1585 set_bit(wIndex, &fotg210->port_c_suspend); in fotg210_hub_control()
1586 fotg210->reset_done[wIndex] = 0; in fotg210_hub_control()
1593 clear_bit(wIndex, &fotg210->resuming_ports); in fotg210_hub_control()
1595 PORT_RESUME, 0, 2000);/* 2ms */ in fotg210_hub_control()
1608 fotg210->reset_done[wIndex])) { in fotg210_hub_control()
1610 fotg210->reset_done[wIndex] = 0; in fotg210_hub_control()
1611 clear_bit(wIndex, &fotg210->resuming_ports); in fotg210_hub_control()
1633 fotg210->command |= CMD_RUN; in fotg210_hub_control()
1634 fotg210_writel(fotg210, fotg210->command, &fotg210->regs->command); in fotg210_hub_control()
1638 fotg210->reset_done[wIndex] = 0; in fotg210_hub_control()
1639 clear_bit(wIndex, &fotg210->resuming_ports); in fotg210_hub_control()
1644 test_bit(wIndex, &fotg210->companion_ports)) { in fotg210_hub_control()
1647 fotg210_dbg(fotg210, "port %d --> companion\n", in fotg210_hub_control()
1668 } else if (test_bit(wIndex, &fotg210->suspended_ports)) { in fotg210_hub_control()
1669 clear_bit(wIndex, &fotg210->suspended_ports); in fotg210_hub_control()
1670 clear_bit(wIndex, &fotg210->resuming_ports); in fotg210_hub_control()
1671 fotg210->reset_done[wIndex] = 0; in fotg210_hub_control()
1673 set_bit(wIndex, &fotg210->port_c_suspend); in fotg210_hub_control()
1676 temp1 = fotg210_readl(fotg210, &fotg210->regs->otgisr); in fotg210_hub_control()
1681 if (test_bit(wIndex, &fotg210->port_c_suspend)) in fotg210_hub_control()
1692 /* no hub-wide feature/status flags */ in fotg210_hub_control()
1704 wIndex--; in fotg210_hub_control()
1719 set_bit(wIndex, &fotg210->suspended_ports); in fotg210_hub_control()
1734 * usb 2.0 spec says 50 ms resets on root in fotg210_hub_control()
1736 fotg210->reset_done[wIndex] = jiffies in fotg210_hub_control()
1745 * about the EHCI-specific stuff. in fotg210_hub_control()
1750 spin_unlock_irqrestore(&fotg210->lock, flags); in fotg210_hub_control()
1752 spin_lock_irqsave(&fotg210->lock, flags); in fotg210_hub_control()
1761 spin_unlock_irqrestore(&fotg210->lock, flags); in fotg210_hub_control()
1763 spin_lock_irqsave(&fotg210->lock, flags); in fotg210_hub_control()
1773 fotg210_readl(fotg210, &fotg210->regs->command); in fotg210_hub_control()
1779 retval = -EPIPE; in fotg210_hub_control()
1781 spin_unlock_irqrestore(&fotg210->lock, flags); in fotg210_hub_control()
1798 * - data used only by the HCD ... kmalloc is fine
1799 * - async and periodic schedules, shared by HC and HCD ... these
1801 * - driver buffers, read/written by HC ... single shot DMA mapped
1812 qtd->qtd_dma = dma; in fotg210_qtd_init()
1813 qtd->hw_token = cpu_to_hc32(fotg210, QTD_STS_HALT); in fotg210_qtd_init()
1814 qtd->hw_next = FOTG210_LIST_END(fotg210); in fotg210_qtd_init()
1815 qtd->hw_alt_next = FOTG210_LIST_END(fotg210); in fotg210_qtd_init()
1816 INIT_LIST_HEAD(&qtd->qtd_list); in fotg210_qtd_init()
1825 qtd = dma_pool_alloc(fotg210->qtd_pool, flags, &dma); in fotg210_qtd_alloc()
1835 dma_pool_free(fotg210->qtd_pool, qtd, qtd->qtd_dma); in fotg210_qtd_free()
1842 if (!list_empty(&qh->qtd_list) || qh->qh_next.ptr) { in qh_destroy()
1846 if (qh->dummy) in qh_destroy()
1847 fotg210_qtd_free(fotg210, qh->dummy); in qh_destroy()
1848 dma_pool_free(fotg210->qh_pool, qh->hw, qh->qh_dma); in qh_destroy()
1861 qh->hw = (struct fotg210_qh_hw *) in fotg210_qh_alloc()
1862 dma_pool_alloc(fotg210->qh_pool, flags, &dma); in fotg210_qh_alloc()
1863 if (!qh->hw) in fotg210_qh_alloc()
1865 memset(qh->hw, 0, sizeof(*qh->hw)); in fotg210_qh_alloc()
1866 qh->qh_dma = dma; in fotg210_qh_alloc()
1867 INIT_LIST_HEAD(&qh->qtd_list); in fotg210_qh_alloc()
1870 qh->dummy = fotg210_qtd_alloc(fotg210, flags); in fotg210_qh_alloc()
1871 if (qh->dummy == NULL) { in fotg210_qh_alloc()
1878 dma_pool_free(fotg210->qh_pool, qh->hw, qh->qh_dma); in fotg210_qh_alloc()
1891 if (fotg210->async) in fotg210_mem_cleanup()
1892 qh_destroy(fotg210, fotg210->async); in fotg210_mem_cleanup()
1893 fotg210->async = NULL; in fotg210_mem_cleanup()
1895 if (fotg210->dummy) in fotg210_mem_cleanup()
1896 qh_destroy(fotg210, fotg210->dummy); in fotg210_mem_cleanup()
1897 fotg210->dummy = NULL; in fotg210_mem_cleanup()
1900 dma_pool_destroy(fotg210->qtd_pool); in fotg210_mem_cleanup()
1901 fotg210->qtd_pool = NULL; in fotg210_mem_cleanup()
1903 dma_pool_destroy(fotg210->qh_pool); in fotg210_mem_cleanup()
1904 fotg210->qh_pool = NULL; in fotg210_mem_cleanup()
1906 dma_pool_destroy(fotg210->itd_pool); in fotg210_mem_cleanup()
1907 fotg210->itd_pool = NULL; in fotg210_mem_cleanup()
1909 if (fotg210->periodic) in fotg210_mem_cleanup()
1910 dma_free_coherent(fotg210_to_hcd(fotg210)->self.controller, in fotg210_mem_cleanup()
1911 fotg210->periodic_size * sizeof(u32), in fotg210_mem_cleanup()
1912 fotg210->periodic, fotg210->periodic_dma); in fotg210_mem_cleanup()
1913 fotg210->periodic = NULL; in fotg210_mem_cleanup()
1916 kfree(fotg210->pshadow); in fotg210_mem_cleanup()
1917 fotg210->pshadow = NULL; in fotg210_mem_cleanup()
1926 fotg210->qtd_pool = dma_pool_create("fotg210_qtd", in fotg210_mem_init()
1927 fotg210_to_hcd(fotg210)->self.controller, in fotg210_mem_init()
1931 if (!fotg210->qtd_pool) in fotg210_mem_init()
1935 fotg210->qh_pool = dma_pool_create("fotg210_qh", in fotg210_mem_init()
1936 fotg210_to_hcd(fotg210)->self.controller, in fotg210_mem_init()
1940 if (!fotg210->qh_pool) in fotg210_mem_init()
1943 fotg210->async = fotg210_qh_alloc(fotg210, flags); in fotg210_mem_init()
1944 if (!fotg210->async) in fotg210_mem_init()
1948 fotg210->itd_pool = dma_pool_create("fotg210_itd", in fotg210_mem_init()
1949 fotg210_to_hcd(fotg210)->self.controller, in fotg210_mem_init()
1953 if (!fotg210->itd_pool) in fotg210_mem_init()
1957 fotg210->periodic = in fotg210_mem_init()
1958 dma_alloc_coherent(fotg210_to_hcd(fotg210)->self.controller, in fotg210_mem_init()
1959 fotg210->periodic_size * sizeof(__le32), in fotg210_mem_init()
1960 &fotg210->periodic_dma, 0); in fotg210_mem_init()
1961 if (fotg210->periodic == NULL) in fotg210_mem_init()
1964 for (i = 0; i < fotg210->periodic_size; i++) in fotg210_mem_init()
1965 fotg210->periodic[i] = FOTG210_LIST_END(fotg210); in fotg210_mem_init()
1968 fotg210->pshadow = kcalloc(fotg210->periodic_size, sizeof(void *), in fotg210_mem_init()
1970 if (fotg210->pshadow != NULL) in fotg210_mem_init()
1976 return -ENOMEM; in fotg210_mem_init()
1981 * entries describing USB transactions, max 16-20kB/entry (with 4kB-aligned
1987 * an ongoing challenge. That's in "ehci-sched.c".
2003 qtd->hw_buf[0] = cpu_to_hc32(fotg210, (u32)addr); in qtd_fill()
2004 qtd->hw_buf_hi[0] = cpu_to_hc32(fotg210, (u32)(addr >> 32)); in qtd_fill()
2005 count = 0x1000 - (buf & 0x0fff); /* rest of that page */ in qtd_fill()
2012 /* per-qtd limit: from 16K to 20K (best alignment) */ in qtd_fill()
2015 qtd->hw_buf[i] = cpu_to_hc32(fotg210, (u32)addr); in qtd_fill()
2016 qtd->hw_buf_hi[i] = cpu_to_hc32(fotg210, in qtd_fill()
2027 count -= (count % maxpacket); in qtd_fill()
2029 qtd->hw_token = cpu_to_hc32(fotg210, (count << 16) | token); in qtd_fill()
2030 qtd->length = count; in qtd_fill()
2038 struct fotg210_qh_hw *hw = qh->hw; in qh_update()
2041 BUG_ON(qh->qh_state != QH_STATE_IDLE); in qh_update()
2043 hw->hw_qtd_next = QTD_NEXT(fotg210, qtd->qtd_dma); in qh_update()
2044 hw->hw_alt_next = FOTG210_LIST_END(fotg210); in qh_update()
2048 * and set the pseudo-toggle in udev. Only usb_clear_halt() will in qh_update()
2051 if (!(hw->hw_info1 & cpu_to_hc32(fotg210, QH_TOGGLE_CTL))) { in qh_update()
2054 is_out = qh->is_out; in qh_update()
2055 epnum = (hc32_to_cpup(fotg210, &hw->hw_info1) >> 8) & 0x0f; in qh_update()
2056 if (unlikely(!usb_gettoggle(qh->dev, epnum, is_out))) { in qh_update()
2057 hw->hw_token &= ~cpu_to_hc32(fotg210, QTD_TOGGLE); in qh_update()
2058 usb_settoggle(qh->dev, epnum, is_out, 1); in qh_update()
2062 hw->hw_token &= cpu_to_hc32(fotg210, QTD_TOGGLE | QTD_STS_PING); in qh_update()
2066 * overlay, so qh->hw_token wrongly becomes inactive/halted), only fault
2073 if (list_empty(&qh->qtd_list)) in qh_refresh()
2074 qtd = qh->dummy; in qh_refresh()
2076 qtd = list_entry(qh->qtd_list.next, in qh_refresh()
2085 if (cpu_to_hc32(fotg210, qtd->qtd_dma) == qh->hw->hw_current) { in qh_refresh()
2086 qh->hw->hw_qtd_next = qtd->hw_next; in qh_refresh()
2101 struct fotg210_qh *qh = ep->hcpriv; in fotg210_clear_tt_buffer_complete()
2104 spin_lock_irqsave(&fotg210->lock, flags); in fotg210_clear_tt_buffer_complete()
2105 qh->clearing_tt = 0; in fotg210_clear_tt_buffer_complete()
2106 if (qh->qh_state == QH_STATE_IDLE && !list_empty(&qh->qtd_list) in fotg210_clear_tt_buffer_complete()
2107 && fotg210->rh_state == FOTG210_RH_RUNNING) in fotg210_clear_tt_buffer_complete()
2109 spin_unlock_irqrestore(&fotg210->lock, flags); in fotg210_clear_tt_buffer_complete()
2122 if (urb->dev->tt && !usb_pipeint(urb->pipe) && !qh->clearing_tt) { in fotg210_clear_tt_buffer()
2123 struct usb_device *tt = urb->dev->tt->hub; in fotg210_clear_tt_buffer()
2125 dev_dbg(&tt->dev, in fotg210_clear_tt_buffer()
2127 urb->dev->ttport, urb->dev->devnum, in fotg210_clear_tt_buffer()
2128 usb_pipeendpoint(urb->pipe), token); in fotg210_clear_tt_buffer()
2130 if (urb->dev->tt->hub != in fotg210_clear_tt_buffer()
2131 fotg210_to_hcd(fotg210)->self.root_hub) { in fotg210_clear_tt_buffer()
2133 qh->clearing_tt = 1; in fotg210_clear_tt_buffer()
2141 int status = -EINPROGRESS; in qtd_copy_status()
2145 urb->actual_length += length - QTD_LENGTH(token); in qtd_copy_status()
2148 if (unlikely(urb->unlinked)) in qtd_copy_status()
2153 status = -EREMOTEIO; in qtd_copy_status()
2159 status = -EOVERFLOW; in qtd_copy_status()
2160 /* CERR nonzero + halt --> stall */ in qtd_copy_status()
2162 status = -EPIPE; in qtd_copy_status()
2169 /* fs/ls interrupt xfer missed the complete-split */ in qtd_copy_status()
2170 status = -EPROTO; in qtd_copy_status()
2173 ? -ENOSR /* hc couldn't read data */ in qtd_copy_status()
2174 : -ECOMM; /* hc couldn't write data */ in qtd_copy_status()
2178 urb->dev->devpath, in qtd_copy_status()
2179 usb_pipeendpoint(urb->pipe), in qtd_copy_status()
2180 usb_pipein(urb->pipe) ? "in" : "out"); in qtd_copy_status()
2181 status = -EPROTO; in qtd_copy_status()
2183 status = -EPROTO; in qtd_copy_status()
2187 "dev%d ep%d%s qtd token %08x --> status %d\n", in qtd_copy_status()
2188 usb_pipedevice(urb->pipe), in qtd_copy_status()
2189 usb_pipeendpoint(urb->pipe), in qtd_copy_status()
2190 usb_pipein(urb->pipe) ? "in" : "out", in qtd_copy_status()
2199 __releases(fotg210->lock) in fotg210_urb_done()
2200 __acquires(fotg210->lock) in fotg210_urb_done()
2202 if (likely(urb->hcpriv != NULL)) { in fotg210_urb_done()
2203 struct fotg210_qh *qh = (struct fotg210_qh *) urb->hcpriv; in fotg210_urb_done()
2205 /* S-mask in a QH means it's an interrupt urb */ in fotg210_urb_done()
2206 if ((qh->hw->hw_info2 & cpu_to_hc32(fotg210, QH_SMASK)) != 0) { in fotg210_urb_done()
2208 /* ... update hc-wide periodic stats (for usbfs) */ in fotg210_urb_done()
2209 fotg210_to_hcd(fotg210)->self.bandwidth_int_reqs--; in fotg210_urb_done()
2213 if (unlikely(urb->unlinked)) { in fotg210_urb_done()
2214 INCR(fotg210->stats.unlink); in fotg210_urb_done()
2216 /* report non-error and short read status as zero */ in fotg210_urb_done()
2217 if (status == -EINPROGRESS || status == -EREMOTEIO) in fotg210_urb_done()
2219 INCR(fotg210->stats.complete); in fotg210_urb_done()
2225 __func__, urb->dev->devpath, urb, in fotg210_urb_done()
2226 usb_pipeendpoint(urb->pipe), in fotg210_urb_done()
2227 usb_pipein(urb->pipe) ? "in" : "out", in fotg210_urb_done()
2229 urb->actual_length, urb->transfer_buffer_length); in fotg210_urb_done()
2234 spin_unlock(&fotg210->lock); in fotg210_urb_done()
2236 spin_lock(&fotg210->lock); in fotg210_urb_done()
2242 * Chases up to qh->hw_current. Returns number of completions called,
2248 struct fotg210_qtd *last, *end = qh->dummy; in qh_completions()
2254 struct fotg210_qh_hw *hw = qh->hw; in qh_completions()
2256 if (unlikely(list_empty(&qh->qtd_list))) in qh_completions()
2265 * It's a bug for qh->qh_state to be anything other than in qh_completions()
2269 state = qh->qh_state; in qh_completions()
2270 qh->qh_state = QH_STATE_COMPLETING; in qh_completions()
2275 last_status = -EINPROGRESS; in qh_completions()
2276 qh->needs_rescan = 0; in qh_completions()
2278 /* remove de-activated QTDs from front of queue. in qh_completions()
2283 list_for_each_entry_safe(qtd, tmp, &qh->qtd_list, qtd_list) { in qh_completions()
2287 urb = qtd->urb; in qh_completions()
2291 if (likely(last->urb != urb)) { in qh_completions()
2292 fotg210_urb_done(fotg210, last->urb, in qh_completions()
2295 last_status = -EINPROGRESS; in qh_completions()
2307 token = hc32_to_cpu(fotg210, qtd->hw_token); in qh_completions()
2309 /* always clean up qtds the hc de-activated */ in qh_completions()
2313 /* Report Data Buffer Error: non-fatal but useful */ in qh_completions()
2317 urb, usb_endpoint_num(&urb->ep->desc), in qh_completions()
2318 usb_endpoint_dir_in(&urb->ep->desc) in qh_completions()
2320 urb->transfer_buffer_length, qtd, qh); in qh_completions()
2332 ++qh->xacterrs < QH_XACTERR_MAX && in qh_completions()
2333 !urb->unlinked) { in qh_completions()
2336 qtd->length - QTD_LENGTH(token), in qh_completions()
2337 qtd->length, in qh_completions()
2338 qh->xacterrs); in qh_completions()
2348 qtd->hw_token = cpu_to_hc32(fotg210, in qh_completions()
2351 hw->hw_token = cpu_to_hc32(fotg210, in qh_completions()
2362 * most other single-qtd reads ... the queue stops if in qh_completions()
2367 !(qtd->hw_alt_next & in qh_completions()
2374 && fotg210->rh_state >= FOTG210_RH_RUNNING)) { in qh_completions()
2382 if (fotg210->rh_state < FOTG210_RH_RUNNING) in qh_completions()
2383 last_status = -ESHUTDOWN; in qh_completions()
2388 else if (last_status == -EINPROGRESS && !urb->unlinked) in qh_completions()
2393 cpu_to_hc32(fotg210, qtd->qtd_dma) in qh_completions()
2394 == hw->hw_current) { in qh_completions()
2395 token = hc32_to_cpu(fotg210, hw->hw_token); in qh_completions()
2413 if (last_status == -EINPROGRESS) { in qh_completions()
2415 qtd->length, token); in qh_completions()
2416 if (last_status == -EREMOTEIO && in qh_completions()
2417 (qtd->hw_alt_next & in qh_completions()
2419 last_status = -EINPROGRESS; in qh_completions()
2421 /* As part of low/full-speed endpoint-halt processing in qh_completions()
2424 if (unlikely(last_status != -EINPROGRESS && in qh_completions()
2425 last_status != -EREMOTEIO)) { in qh_completions()
2430 * state (if you believe Figures 11-48 - 11-51 in qh_completions()
2435 if (last_status != -EPIPE) in qh_completions()
2444 if (stopped && qtd->qtd_list.prev != &qh->qtd_list) { in qh_completions()
2445 last = list_entry(qtd->qtd_list.prev, in qh_completions()
2447 last->hw_next = qtd->hw_next; in qh_completions()
2451 list_del(&qtd->qtd_list); in qh_completions()
2455 qh->xacterrs = 0; in qh_completions()
2460 fotg210_urb_done(fotg210, last->urb, last_status); in qh_completions()
2466 if (unlikely(qh->needs_rescan)) { in qh_completions()
2472 * Our caller will start an unlink if qh->needs_rescan is in qh_completions()
2477 qh->needs_rescan = 0; in qh_completions()
2481 qh->qh_state = state; in qh_completions()
2487 if (stopped != 0 || hw->hw_qtd_next == FOTG210_LIST_END(fotg210)) { in qh_completions()
2495 * - HC reads first part of QH; in qh_completions()
2496 * - CPU updates that first part and the token; in qh_completions()
2497 * - HC reads rest of that QH, including token in qh_completions()
2506 qh->needs_rescan = 1; in qh_completions()
2524 list_del(&qtd->qtd_list); in qtd_list_free()
2548 list_add_tail(&qtd->qtd_list, head); in qh_urb_transaction()
2549 qtd->urb = urb; in qh_urb_transaction()
2555 len = urb->transfer_buffer_length; in qh_urb_transaction()
2556 is_input = usb_pipein(urb->pipe); in qh_urb_transaction()
2557 if (usb_pipecontrol(urb->pipe)) { in qh_urb_transaction()
2559 qtd_fill(fotg210, qtd, urb->setup_dma, in qh_urb_transaction()
2569 qtd->urb = urb; in qh_urb_transaction()
2570 qtd_prev->hw_next = QTD_NEXT(fotg210, qtd->qtd_dma); in qh_urb_transaction()
2571 list_add_tail(&qtd->qtd_list, head); in qh_urb_transaction()
2581 i = urb->num_mapped_sgs; in qh_urb_transaction()
2583 sg = urb->sg; in qh_urb_transaction()
2586 /* urb->transfer_buffer_length may be smaller than the in qh_urb_transaction()
2592 buf = urb->transfer_dma; in qh_urb_transaction()
2600 maxpacket = usb_maxpacket(urb->dev, urb->pipe, !is_input); in qh_urb_transaction()
2612 this_sg_len -= this_qtd_len; in qh_urb_transaction()
2613 len -= this_qtd_len; in qh_urb_transaction()
2622 qtd->hw_alt_next = fotg210->async->hw->hw_alt_next; in qh_urb_transaction()
2625 if ((maxpacket & (this_qtd_len + (maxpacket - 1))) == 0) in qh_urb_transaction()
2629 if (--i <= 0 || len <= 0) in qh_urb_transaction()
2640 qtd->urb = urb; in qh_urb_transaction()
2641 qtd_prev->hw_next = QTD_NEXT(fotg210, qtd->qtd_dma); in qh_urb_transaction()
2642 list_add_tail(&qtd->qtd_list, head); in qh_urb_transaction()
2650 if (likely((urb->transfer_flags & URB_SHORT_NOT_OK) == 0 || in qh_urb_transaction()
2651 usb_pipecontrol(urb->pipe))) in qh_urb_transaction()
2652 qtd->hw_alt_next = FOTG210_LIST_END(fotg210); in qh_urb_transaction()
2659 if (likely(urb->transfer_buffer_length != 0)) { in qh_urb_transaction()
2662 if (usb_pipecontrol(urb->pipe)) { in qh_urb_transaction()
2664 token ^= 0x0100; /* "in" <--> "out" */ in qh_urb_transaction()
2666 } else if (usb_pipeout(urb->pipe) in qh_urb_transaction()
2667 && (urb->transfer_flags & URB_ZERO_PACKET) in qh_urb_transaction()
2668 && !(urb->transfer_buffer_length % maxpacket)) { in qh_urb_transaction()
2676 qtd->urb = urb; in qh_urb_transaction()
2677 qtd_prev->hw_next = QTD_NEXT(fotg210, qtd->qtd_dma); in qh_urb_transaction()
2678 list_add_tail(&qtd->qtd_list, head); in qh_urb_transaction()
2686 if (likely(!(urb->transfer_flags & URB_NO_INTERRUPT))) in qh_urb_transaction()
2687 qtd->hw_token |= cpu_to_hc32(fotg210, QTD_IOC); in qh_urb_transaction()
2707 * just one microframe in the s-mask. For split interrupt transactions
2708 * there are additional complications: c-mask, maybe FSTNs.
2719 struct usb_tt *tt = urb->dev->tt; in qh_make()
2728 info1 |= usb_pipeendpoint(urb->pipe) << 8; in qh_make()
2729 info1 |= usb_pipedevice(urb->pipe) << 0; in qh_make()
2731 is_input = usb_pipein(urb->pipe); in qh_make()
2732 type = usb_pipetype(urb->pipe); in qh_make()
2733 ep = usb_pipe_endpoint(urb->dev, urb->pipe); in qh_make()
2734 maxp = usb_endpoint_maxp(&ep->desc); in qh_make()
2735 mult = usb_endpoint_maxp_mult(&ep->desc); in qh_make()
2746 * - allowing for high bandwidth, how many nsec/uframe are used? in qh_make()
2747 * - split transactions need a second CSPLIT uframe; same question in qh_make()
2748 * - splits also need a schedule gap (for full/low speed I/O) in qh_make()
2749 * - qh has a polling interval in qh_make()
2754 qh->usecs = NS_TO_US(usb_calc_bus_time(USB_SPEED_HIGH, in qh_make()
2756 qh->start = NO_FRAME; in qh_make()
2758 if (urb->dev->speed == USB_SPEED_HIGH) { in qh_make()
2759 qh->c_usecs = 0; in qh_make()
2760 qh->gap_uf = 0; in qh_make()
2762 qh->period = urb->interval >> 3; in qh_make()
2763 if (qh->period == 0 && urb->interval != 1) { in qh_make()
2768 urb->interval = 1; in qh_make()
2769 } else if (qh->period > fotg210->periodic_size) { in qh_make()
2770 qh->period = fotg210->periodic_size; in qh_make()
2771 urb->interval = qh->period << 3; in qh_make()
2777 qh->gap_uf = 1 + usb_calc_bus_time(urb->dev->speed, in qh_make()
2782 qh->c_usecs = qh->usecs + HS_USECS(0); in qh_make()
2783 qh->usecs = HS_USECS(1); in qh_make()
2785 qh->usecs += HS_USECS(1); in qh_make()
2786 qh->c_usecs = HS_USECS(0); in qh_make()
2789 think_time = tt ? tt->think_time : 0; in qh_make()
2790 qh->tt_usecs = NS_TO_US(think_time + in qh_make()
2791 usb_calc_bus_time(urb->dev->speed, in qh_make()
2793 qh->period = urb->interval; in qh_make()
2794 if (qh->period > fotg210->periodic_size) { in qh_make()
2795 qh->period = fotg210->periodic_size; in qh_make()
2796 urb->interval = qh->period; in qh_make()
2802 qh->dev = urb->dev; in qh_make()
2805 switch (urb->dev->speed) { in qh_make()
2823 * port number in the queue head was 0..N-1 instead of 1..N. in qh_make()
2826 info2 |= (urb->dev->ttport-1) << 23; in qh_make()
2828 info2 |= urb->dev->ttport << 23; in qh_make()
2833 if (tt && tt->hub != fotg210_to_hcd(fotg210)->self.root_hub) in qh_make()
2834 info2 |= tt->hub->devnum << 16; in qh_make()
2836 /* NOTE: if (PIPE_INTERRUPT) { scheduler sets c-mask } */ in qh_make()
2863 fotg210_dbg(fotg210, "bogus dev %p speed %d\n", urb->dev, in qh_make()
2864 urb->dev->speed); in qh_make()
2870 /* NOTE: if (PIPE_INTERRUPT) { scheduler sets s-mask } */ in qh_make()
2873 qh->qh_state = QH_STATE_IDLE; in qh_make()
2874 hw = qh->hw; in qh_make()
2875 hw->hw_info1 = cpu_to_hc32(fotg210, info1); in qh_make()
2876 hw->hw_info2 = cpu_to_hc32(fotg210, info2); in qh_make()
2877 qh->is_out = !is_input; in qh_make()
2878 usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), !is_input, 1); in qh_make()
2885 if (fotg210->async_count++) in enable_async()
2889 fotg210->enabled_hrtimer_events &= ~BIT(FOTG210_HRTIMER_DISABLE_ASYNC); in enable_async()
2898 if (--fotg210->async_count) in disable_async()
2902 WARN_ON(fotg210->async->qh_next.qh || fotg210->async_unlink); in disable_async()
2912 __hc32 dma = QH_NEXT(fotg210, qh->qh_dma); in qh_link_async()
2915 /* Don't link a QH if there's a Clear-TT-Buffer pending */ in qh_link_async()
2916 if (unlikely(qh->clearing_tt)) in qh_link_async()
2919 WARN_ON(qh->qh_state != QH_STATE_IDLE); in qh_link_async()
2925 head = fotg210->async; in qh_link_async()
2926 qh->qh_next = head->qh_next; in qh_link_async()
2927 qh->hw->hw_next = head->hw->hw_next; in qh_link_async()
2930 head->qh_next.qh = qh; in qh_link_async()
2931 head->hw->hw_next = dma; in qh_link_async()
2933 qh->xacterrs = 0; in qh_link_async()
2934 qh->qh_state = QH_STATE_LINKED; in qh_link_async()
2954 /* can't sleep here, we have fotg210->lock... */ in qh_append_tds()
2964 qtd = list_entry(qtd_list->next, struct fotg210_qtd, in qh_append_tds()
2970 if (usb_pipedevice(urb->pipe) == 0) in qh_append_tds()
2971 qh->hw->hw_info1 &= ~qh_addr_mask; in qh_append_tds()
2987 token = qtd->hw_token; in qh_append_tds()
2988 qtd->hw_token = HALT_BIT(fotg210); in qh_append_tds()
2990 dummy = qh->dummy; in qh_append_tds()
2992 dma = dummy->qtd_dma; in qh_append_tds()
2994 dummy->qtd_dma = dma; in qh_append_tds()
2996 list_del(&qtd->qtd_list); in qh_append_tds()
2997 list_add(&dummy->qtd_list, qtd_list); in qh_append_tds()
2998 list_splice_tail(qtd_list, &qh->qtd_list); in qh_append_tds()
3000 fotg210_qtd_init(fotg210, qtd, qtd->qtd_dma); in qh_append_tds()
3001 qh->dummy = qtd; in qh_append_tds()
3004 dma = qtd->qtd_dma; in qh_append_tds()
3005 qtd = list_entry(qh->qtd_list.prev, in qh_append_tds()
3007 qtd->hw_next = QTD_NEXT(fotg210, dma); in qh_append_tds()
3011 dummy->hw_token = token; in qh_append_tds()
3013 urb->hcpriv = qh; in qh_append_tds()
3027 epnum = urb->ep->desc.bEndpointAddress; in submit_async()
3033 qtd = list_entry(qtd_list->next, struct fotg210_qtd, qtd_list); in submit_async()
3036 __func__, urb->dev->devpath, urb, in submit_async()
3039 urb->transfer_buffer_length, in submit_async()
3040 qtd, urb->ep->hcpriv); in submit_async()
3044 spin_lock_irqsave(&fotg210->lock, flags); in submit_async()
3046 rc = -ESHUTDOWN; in submit_async()
3053 qh = qh_append_tds(fotg210, urb, qtd_list, epnum, &urb->ep->hcpriv); in submit_async()
3056 rc = -ENOMEM; in submit_async()
3063 if (likely(qh->qh_state == QH_STATE_IDLE)) in submit_async()
3066 spin_unlock_irqrestore(&fotg210->lock, flags); in submit_async()
3078 qh->qh_state = QH_STATE_UNLINK; in single_unlink_async()
3079 if (fotg210->async_unlink) in single_unlink_async()
3080 fotg210->async_unlink_last->unlink_next = qh; in single_unlink_async()
3082 fotg210->async_unlink = qh; in single_unlink_async()
3083 fotg210->async_unlink_last = qh; in single_unlink_async()
3086 prev = fotg210->async; in single_unlink_async()
3087 while (prev->qh_next.qh != qh) in single_unlink_async()
3088 prev = prev->qh_next.qh; in single_unlink_async()
3090 prev->hw->hw_next = qh->hw->hw_next; in single_unlink_async()
3091 prev->qh_next = qh->qh_next; in single_unlink_async()
3092 if (fotg210->qh_scan_next == qh) in single_unlink_async()
3093 fotg210->qh_scan_next = qh->qh_next.qh; in single_unlink_async()
3102 if (fotg210->async_iaa || fotg210->async_unlinking) in start_iaa_cycle()
3106 fotg210->async_iaa = fotg210->async_unlink; in start_iaa_cycle()
3107 fotg210->async_unlink = NULL; in start_iaa_cycle()
3110 if (unlikely(fotg210->rh_state < FOTG210_RH_RUNNING)) { in start_iaa_cycle()
3115 } else if (likely(fotg210->rh_state == FOTG210_RH_RUNNING)) { in start_iaa_cycle()
3119 fotg210_writel(fotg210, fotg210->command | CMD_IAAD, in start_iaa_cycle()
3120 &fotg210->regs->command); in start_iaa_cycle()
3121 fotg210_readl(fotg210, &fotg210->regs->command); in start_iaa_cycle()
3135 fotg210->async_unlinking = true; in end_unlink_async()
3136 while (fotg210->async_iaa) { in end_unlink_async()
3137 qh = fotg210->async_iaa; in end_unlink_async()
3138 fotg210->async_iaa = qh->unlink_next; in end_unlink_async()
3139 qh->unlink_next = NULL; in end_unlink_async()
3141 qh->qh_state = QH_STATE_IDLE; in end_unlink_async()
3142 qh->qh_next.qh = NULL; in end_unlink_async()
3145 if (!list_empty(&qh->qtd_list) && in end_unlink_async()
3146 fotg210->rh_state == FOTG210_RH_RUNNING) in end_unlink_async()
3150 fotg210->async_unlinking = false; in end_unlink_async()
3153 if (fotg210->async_unlink) { in end_unlink_async()
3155 if (unlikely(fotg210->rh_state < FOTG210_RH_RUNNING)) in end_unlink_async()
3163 bool stopped = (fotg210->rh_state < FOTG210_RH_RUNNING); in unlink_empty_async()
3167 next = fotg210->async->qh_next.qh; in unlink_empty_async()
3170 next = qh->qh_next.qh; in unlink_empty_async()
3172 if (list_empty(&qh->qtd_list) && in unlink_empty_async()
3173 qh->qh_state == QH_STATE_LINKED) { in unlink_empty_async()
3174 if (!stopped && qh->unlink_cycle == in unlink_empty_async()
3175 fotg210->async_unlink_cycle) in unlink_empty_async()
3183 if (fotg210->async_unlink) in unlink_empty_async()
3190 ++fotg210->async_unlink_cycle; in unlink_empty_async()
3195 /* caller must own fotg210->lock */
3205 if (qh->qh_state != QH_STATE_LINKED) { in start_unlink_async()
3206 if (qh->qh_state == QH_STATE_COMPLETING) in start_unlink_async()
3207 qh->needs_rescan = 1; in start_unlink_async()
3220 fotg210->qh_scan_next = fotg210->async->qh_next.qh; in scan_async()
3221 while (fotg210->qh_scan_next) { in scan_async()
3222 qh = fotg210->qh_scan_next; in scan_async()
3223 fotg210->qh_scan_next = qh->qh_next.qh; in scan_async()
3226 if (!list_empty(&qh->qtd_list)) { in scan_async()
3231 * drops the lock. That's why fotg210->qh_scan_next in scan_async()
3233 * gets unlinked then fotg210->qh_scan_next is adjusted in scan_async()
3237 if (qh->needs_rescan) { in scan_async()
3239 } else if (list_empty(&qh->qtd_list) in scan_async()
3240 && qh->qh_state == QH_STATE_LINKED) { in scan_async()
3241 qh->unlink_cycle = fotg210->async_unlink_cycle; in scan_async()
3250 * as HCD schedule-scanning costs. Delay for any qh in scan_async()
3251 * we just scanned, there's a not-unusual case that it in scan_async()
3254 if (check_unlinks_later && fotg210->rh_state == FOTG210_RH_RUNNING && in scan_async()
3255 !(fotg210->enabled_hrtimer_events & in scan_async()
3259 ++fotg210->async_unlink_cycle; in scan_async()
3271 * pre-calculated schedule data to make appending to the queue be quick.
3275 /* periodic_next_shadow - return "next" pointer on shadow list
3284 return &periodic->qh->qh_next; in periodic_next_shadow()
3286 return &periodic->fstn->fstn_next; in periodic_next_shadow()
3288 return &periodic->itd->itd_next; in periodic_next_shadow()
3298 return &periodic->qh->hw->hw_next; in shadow_next_periodic()
3301 return periodic->hw_next; in shadow_next_periodic()
3305 /* caller must hold fotg210->lock */
3309 union fotg210_shadow *prev_p = &fotg210->pshadow[frame]; in periodic_unlink()
3310 __hc32 *hw_p = &fotg210->periodic[frame]; in periodic_unlink()
3339 __hc32 *hw_p = &fotg210->periodic[frame]; in periodic_usecs()
3340 union fotg210_shadow *q = &fotg210->pshadow[frame]; in periodic_usecs()
3344 while (q->ptr) { in periodic_usecs()
3347 hw = q->qh->hw; in periodic_usecs()
3348 /* is it in the S-mask? */ in periodic_usecs()
3349 if (hw->hw_info2 & cpu_to_hc32(fotg210, 1 << uframe)) in periodic_usecs()
3350 usecs += q->qh->usecs; in periodic_usecs()
3351 /* ... or C-mask? */ in periodic_usecs()
3352 if (hw->hw_info2 & cpu_to_hc32(fotg210, in periodic_usecs()
3354 usecs += q->qh->c_usecs; in periodic_usecs()
3355 hw_p = &hw->hw_next; in periodic_usecs()
3356 q = &q->qh->qh_next; in periodic_usecs()
3363 if (q->fstn->hw_prev != FOTG210_LIST_END(fotg210)) in periodic_usecs()
3366 hw_p = &q->fstn->hw_next; in periodic_usecs()
3367 q = &q->fstn->fstn_next; in periodic_usecs()
3370 if (q->itd->hw_transaction[uframe]) in periodic_usecs()
3371 usecs += q->itd->stream->usecs; in periodic_usecs()
3372 hw_p = &q->itd->hw_next; in periodic_usecs()
3373 q = &q->itd->itd_next; in periodic_usecs()
3377 if (usecs > fotg210->uframe_periodic_max) in periodic_usecs()
3378 fotg210_err(fotg210, "uframe %d sched overrun: %d usecs\n", in periodic_usecs()
3385 if (!dev1->tt || !dev2->tt) in same_tt()
3387 if (dev1->tt != dev2->tt) in same_tt()
3389 if (dev1->tt->multi) in same_tt()
3390 return dev1->ttport == dev2->ttport; in same_tt()
3409 for (; frame < fotg210->periodic_size; frame += period) { in tt_no_collision()
3414 here = fotg210->pshadow[frame]; in tt_no_collision()
3415 type = Q_NEXT_TYPE(fotg210, fotg210->periodic[frame]); in tt_no_collision()
3419 type = Q_NEXT_TYPE(fotg210, here.itd->hw_next); in tt_no_collision()
3420 here = here.itd->itd_next; in tt_no_collision()
3423 hw = here.qh->hw; in tt_no_collision()
3424 if (same_tt(dev, here.qh->dev)) { in tt_no_collision()
3428 hw->hw_info2); in tt_no_collision()
3434 type = Q_NEXT_TYPE(fotg210, hw->hw_next); in tt_no_collision()
3435 here = here.qh->qh_next; in tt_no_collision()
3455 if (fotg210->periodic_count++) in enable_periodic()
3459 fotg210->enabled_hrtimer_events &= in enable_periodic()
3469 if (--fotg210->periodic_count) in disable_periodic()
3485 unsigned period = qh->period; in qh_link_periodic()
3487 dev_dbg(&qh->dev->dev, in qh_link_periodic()
3488 "link qh%d-%04x/%p start %d [%d/%d us]\n", period, in qh_link_periodic()
3489 hc32_to_cpup(fotg210, &qh->hw->hw_info2) & in qh_link_periodic()
3490 (QH_CMASK | QH_SMASK), qh, qh->start, qh->usecs, in qh_link_periodic()
3491 qh->c_usecs); in qh_link_periodic()
3497 for (i = qh->start; i < fotg210->periodic_size; i += period) { in qh_link_periodic()
3498 union fotg210_shadow *prev = &fotg210->pshadow[i]; in qh_link_periodic()
3499 __hc32 *hw_p = &fotg210->periodic[i]; in qh_link_periodic()
3513 /* sorting each branch by period (slow-->fast) in qh_link_periodic()
3517 if (qh->period > here.qh->period) in qh_link_periodic()
3519 prev = &here.qh->qh_next; in qh_link_periodic()
3520 hw_p = &here.qh->hw->hw_next; in qh_link_periodic()
3525 qh->qh_next = here; in qh_link_periodic()
3527 qh->hw->hw_next = *hw_p; in qh_link_periodic()
3529 prev->qh = qh; in qh_link_periodic()
3530 *hw_p = QH_NEXT(fotg210, qh->qh_dma); in qh_link_periodic()
3533 qh->qh_state = QH_STATE_LINKED; in qh_link_periodic()
3534 qh->xacterrs = 0; in qh_link_periodic()
3536 /* update per-qh bandwidth for usbfs */ in qh_link_periodic()
3537 fotg210_to_hcd(fotg210)->self.bandwidth_allocated += qh->period in qh_link_periodic()
3538 ? ((qh->usecs + qh->c_usecs) / qh->period) in qh_link_periodic()
3539 : (qh->usecs * 8); in qh_link_periodic()
3541 list_add(&qh->intr_node, &fotg210->intr_qh_list); in qh_link_periodic()
3544 ++fotg210->intr_count; in qh_link_periodic()
3555 * If qh is for a low/full-speed device, simply unlinking it in qh_unlink_periodic()
3570 period = qh->period; in qh_unlink_periodic()
3574 for (i = qh->start; i < fotg210->periodic_size; i += period) in qh_unlink_periodic()
3577 /* update per-qh bandwidth for usbfs */ in qh_unlink_periodic()
3578 fotg210_to_hcd(fotg210)->self.bandwidth_allocated -= qh->period in qh_unlink_periodic()
3579 ? ((qh->usecs + qh->c_usecs) / qh->period) in qh_unlink_periodic()
3580 : (qh->usecs * 8); in qh_unlink_periodic()
3582 dev_dbg(&qh->dev->dev, in qh_unlink_periodic()
3583 "unlink qh%d-%04x/%p start %d [%d/%d us]\n", in qh_unlink_periodic()
3584 qh->period, hc32_to_cpup(fotg210, &qh->hw->hw_info2) & in qh_unlink_periodic()
3585 (QH_CMASK | QH_SMASK), qh, qh->start, qh->usecs, in qh_unlink_periodic()
3586 qh->c_usecs); in qh_unlink_periodic()
3588 /* qh->qh_next still "live" to HC */ in qh_unlink_periodic()
3589 qh->qh_state = QH_STATE_UNLINK; in qh_unlink_periodic()
3590 qh->qh_next.ptr = NULL; in qh_unlink_periodic()
3592 if (fotg210->qh_scan_next == qh) in qh_unlink_periodic()
3593 fotg210->qh_scan_next = list_entry(qh->intr_node.next, in qh_unlink_periodic()
3595 list_del(&qh->intr_node); in qh_unlink_periodic()
3605 if (qh->qh_state != QH_STATE_LINKED) { in start_unlink_intr()
3606 if (qh->qh_state == QH_STATE_COMPLETING) in start_unlink_intr()
3607 qh->needs_rescan = 1; in start_unlink_intr()
3621 qh->unlink_cycle = fotg210->intr_unlink_cycle; in start_unlink_intr()
3624 if (fotg210->intr_unlink) in start_unlink_intr()
3625 fotg210->intr_unlink_last->unlink_next = qh; in start_unlink_intr()
3627 fotg210->intr_unlink = qh; in start_unlink_intr()
3628 fotg210->intr_unlink_last = qh; in start_unlink_intr()
3630 if (fotg210->intr_unlinking) in start_unlink_intr()
3632 else if (fotg210->rh_state < FOTG210_RH_RUNNING) in start_unlink_intr()
3634 else if (fotg210->intr_unlink == qh) { in start_unlink_intr()
3637 ++fotg210->intr_unlink_cycle; in start_unlink_intr()
3643 struct fotg210_qh_hw *hw = qh->hw; in end_unlink_intr()
3646 qh->qh_state = QH_STATE_IDLE; in end_unlink_intr()
3647 hw->hw_next = FOTG210_LIST_END(fotg210); in end_unlink_intr()
3652 if (!list_empty(&qh->qtd_list) && in end_unlink_intr()
3653 fotg210->rh_state == FOTG210_RH_RUNNING) { in end_unlink_intr()
3660 * FIXME kill the now-dysfunctional queued urbs in end_unlink_intr()
3668 --fotg210->intr_count; in end_unlink_intr()
3684 usecs = fotg210->uframe_periodic_max - usecs; in check_period()
3697 } while ((frame += 1) < fotg210->periodic_size); in check_period()
3705 } while ((frame += period) < fotg210->periodic_size); in check_period()
3715 int retval = -ENOSPC; in check_intr_schedule()
3718 if (qh->c_usecs && uframe >= 6) /* FSTN territory? */ in check_intr_schedule()
3721 if (!check_period(fotg210, frame, uframe, qh->period, qh->usecs)) in check_intr_schedule()
3723 if (!qh->c_usecs) { in check_intr_schedule()
3736 mask = 0x03 << (uframe + qh->gap_uf); in check_intr_schedule()
3740 if (tt_no_collision(fotg210, qh->period, qh->dev, frame, mask)) { in check_intr_schedule()
3741 if (!check_period(fotg210, frame, uframe + qh->gap_uf + 1, in check_intr_schedule()
3742 qh->period, qh->c_usecs)) in check_intr_schedule()
3744 if (!check_period(fotg210, frame, uframe + qh->gap_uf, in check_intr_schedule()
3745 qh->period, qh->c_usecs)) in check_intr_schedule()
3754 * or when the previous schedule slot can't be re-used.
3761 unsigned frame; /* 0..(qh->period - 1), or NO_FRAME */ in qh_schedule()
3762 struct fotg210_qh_hw *hw = qh->hw; in qh_schedule()
3765 hw->hw_next = FOTG210_LIST_END(fotg210); in qh_schedule()
3766 frame = qh->start; in qh_schedule()
3769 if (frame < qh->period) { in qh_schedule()
3770 uframe = ffs(hc32_to_cpup(fotg210, &hw->hw_info2) & QH_SMASK); in qh_schedule()
3771 status = check_intr_schedule(fotg210, frame, --uframe, in qh_schedule()
3776 status = -ENOSPC; in qh_schedule()
3784 if (qh->period) { in qh_schedule()
3787 for (i = qh->period; status && i > 0; --i) { in qh_schedule()
3788 frame = ++fotg210->random_frame % qh->period; in qh_schedule()
3798 /* qh->period == 0 means every uframe */ in qh_schedule()
3806 qh->start = frame; in qh_schedule()
3808 /* reset S-frame and (maybe) C-frame masks */ in qh_schedule()
3809 hw->hw_info2 &= cpu_to_hc32(fotg210, ~(QH_CMASK | QH_SMASK)); in qh_schedule()
3810 hw->hw_info2 |= qh->period in qh_schedule()
3813 hw->hw_info2 |= c_mask; in qh_schedule()
3833 epnum = urb->ep->desc.bEndpointAddress; in intr_submit()
3835 spin_lock_irqsave(&fotg210->lock, flags); in intr_submit()
3838 status = -ESHUTDOWN; in intr_submit()
3847 qh = qh_append_tds(fotg210, urb, &empty, epnum, &urb->ep->hcpriv); in intr_submit()
3849 status = -ENOMEM; in intr_submit()
3852 if (qh->qh_state == QH_STATE_IDLE) { in intr_submit()
3859 qh = qh_append_tds(fotg210, urb, qtd_list, epnum, &urb->ep->hcpriv); in intr_submit()
3863 fotg210_to_hcd(fotg210)->self.bandwidth_int_reqs++; in intr_submit()
3869 spin_unlock_irqrestore(&fotg210->lock, flags); in intr_submit()
3880 list_for_each_entry_safe(qh, fotg210->qh_scan_next, in scan_intr()
3881 &fotg210->intr_qh_list, intr_node) { in scan_intr()
3884 if (!list_empty(&qh->qtd_list)) { in scan_intr()
3889 * drops the lock. That's why fotg210->qh_scan_next in scan_intr()
3891 * gets unlinked then fotg210->qh_scan_next is adjusted in scan_intr()
3895 if (unlikely(qh->needs_rescan || in scan_intr()
3896 (list_empty(&qh->qtd_list) && in scan_intr()
3897 qh->qh_state == QH_STATE_LINKED))) in scan_intr()
3913 INIT_LIST_HEAD(&stream->td_list); in iso_stream_alloc()
3914 INIT_LIST_HEAD(&stream->free_list); in iso_stream_alloc()
3915 stream->next_uframe = -1; in iso_stream_alloc()
3938 maxp = usb_endpoint_maxp(&ep->desc); in iso_stream_init()
3944 multi = usb_endpoint_maxp_mult(&ep->desc); in iso_stream_init()
3948 stream->buf0 = cpu_to_hc32(fotg210, (epnum << 8) | dev->devnum); in iso_stream_init()
3949 stream->buf1 = cpu_to_hc32(fotg210, buf1); in iso_stream_init()
3950 stream->buf2 = cpu_to_hc32(fotg210, multi); in iso_stream_init()
3955 if (dev->speed == USB_SPEED_FULL) { in iso_stream_init()
3957 stream->usecs = NS_TO_US(usb_calc_bus_time(dev->speed, in iso_stream_init()
3959 stream->usecs /= 8; in iso_stream_init()
3961 stream->highspeed = 1; in iso_stream_init()
3962 stream->usecs = HS_USECS_ISO(maxp); in iso_stream_init()
3964 bandwidth = stream->usecs * 8; in iso_stream_init()
3967 stream->bandwidth = bandwidth; in iso_stream_init()
3968 stream->udev = dev; in iso_stream_init()
3969 stream->bEndpointAddress = is_input | epnum; in iso_stream_init()
3970 stream->interval = interval; in iso_stream_init()
3971 stream->maxp = maxp; in iso_stream_init()
3982 epnum = usb_pipeendpoint(urb->pipe); in iso_stream_find()
3983 if (usb_pipein(urb->pipe)) in iso_stream_find()
3984 ep = urb->dev->ep_in[epnum]; in iso_stream_find()
3986 ep = urb->dev->ep_out[epnum]; in iso_stream_find()
3988 spin_lock_irqsave(&fotg210->lock, flags); in iso_stream_find()
3989 stream = ep->hcpriv; in iso_stream_find()
3994 ep->hcpriv = stream; in iso_stream_find()
3995 stream->ep = ep; in iso_stream_find()
3996 iso_stream_init(fotg210, stream, urb->dev, urb->pipe, in iso_stream_find()
3997 urb->interval); in iso_stream_find()
4000 /* if dev->ep[epnum] is a QH, hw is set */ in iso_stream_find()
4001 } else if (unlikely(stream->hw != NULL)) { in iso_stream_find()
4003 urb->dev->devpath, epnum, in iso_stream_find()
4004 usb_pipein(urb->pipe) ? "in" : "out"); in iso_stream_find()
4008 spin_unlock_irqrestore(&fotg210->lock, flags); in iso_stream_find()
4012 /* fotg210_iso_sched ops can be ITD-only or SITD-only */
4023 INIT_LIST_HEAD(&iso_sched->td_list); in iso_sched_alloc()
4033 dma_addr_t dma = urb->transfer_dma; in itd_sched_init()
4036 iso_sched->span = urb->number_of_packets * stream->interval; in itd_sched_init()
4038 /* figure out per-uframe itd fields that we'll need later in itd_sched_init()
4041 for (i = 0; i < urb->number_of_packets; i++) { in itd_sched_init()
4042 struct fotg210_iso_packet *uframe = &iso_sched->packet[i]; in itd_sched_init()
4047 length = urb->iso_frame_desc[i].length; in itd_sched_init()
4048 buf = dma + urb->iso_frame_desc[i].offset; in itd_sched_init()
4052 if (unlikely(((i + 1) == urb->number_of_packets)) in itd_sched_init()
4053 && !(urb->transfer_flags & URB_NO_INTERRUPT)) in itd_sched_init()
4056 uframe->transaction = cpu_to_hc32(fotg210, trans); in itd_sched_init()
4059 uframe->bufp = (buf & ~(u64)0x0fff); in itd_sched_init()
4061 if (unlikely((uframe->bufp != (buf & ~(u64)0x0fff)))) in itd_sched_init()
4062 uframe->cross = 1; in itd_sched_init()
4071 /* caller must hold fotg210->lock!*/ in iso_sched_free()
4072 list_splice(&iso_sched->td_list, &stream->free_list); in iso_sched_free()
4086 sched = iso_sched_alloc(urb->number_of_packets, mem_flags); in itd_urb_transaction()
4088 return -ENOMEM; in itd_urb_transaction()
4092 if (urb->interval < 8) in itd_urb_transaction()
4093 num_itds = 1 + (sched->span + 7) / 8; in itd_urb_transaction()
4095 num_itds = urb->number_of_packets; in itd_urb_transaction()
4098 spin_lock_irqsave(&fotg210->lock, flags); in itd_urb_transaction()
4105 if (likely(!list_empty(&stream->free_list))) { in itd_urb_transaction()
4106 itd = list_first_entry(&stream->free_list, in itd_urb_transaction()
4108 if (itd->frame == fotg210->now_frame) in itd_urb_transaction()
4110 list_del(&itd->itd_list); in itd_urb_transaction()
4111 itd_dma = itd->itd_dma; in itd_urb_transaction()
4114 spin_unlock_irqrestore(&fotg210->lock, flags); in itd_urb_transaction()
4115 itd = dma_pool_alloc(fotg210->itd_pool, mem_flags, in itd_urb_transaction()
4117 spin_lock_irqsave(&fotg210->lock, flags); in itd_urb_transaction()
4120 spin_unlock_irqrestore(&fotg210->lock, flags); in itd_urb_transaction()
4121 return -ENOMEM; in itd_urb_transaction()
4126 itd->itd_dma = itd_dma; in itd_urb_transaction()
4127 list_add(&itd->itd_list, &sched->td_list); in itd_urb_transaction()
4129 spin_unlock_irqrestore(&fotg210->lock, flags); in itd_urb_transaction()
4132 urb->hcpriv = sched; in itd_urb_transaction()
4133 urb->error_count = 0; in itd_urb_transaction()
4144 > (fotg210->uframe_periodic_max - usecs)) in itd_slot_ok()
4147 /* we know urb->interval is 2^N uframes */ in itd_slot_ok()
4155 * "as small as possible" to be cache-friendlier.) That limits the size
4158 * by the per-urb URB_NO_INTERRUPT hint, the log2_irq_thresh module parameter,
4170 unsigned mod = fotg210->periodic_size << 3; in iso_stream_schedule()
4171 struct fotg210_iso_sched *sched = urb->hcpriv; in iso_stream_schedule()
4173 period = urb->interval; in iso_stream_schedule()
4174 span = sched->span; in iso_stream_schedule()
4176 if (span > mod - SCHEDULE_SLOP) { in iso_stream_schedule()
4178 status = -EFBIG; in iso_stream_schedule()
4182 now = fotg210_read_frame_index(fotg210) & (mod - 1); in iso_stream_schedule()
4189 if (likely(!list_empty(&stream->td_list))) { in iso_stream_schedule()
4194 * and Intel PCI-based controllers, don't (work around for in iso_stream_schedule()
4197 if (!stream->highspeed && fotg210->fs_i_thresh) in iso_stream_schedule()
4198 next = now + fotg210->i_thresh; in iso_stream_schedule()
4203 * We decide based on the time of the last currently-scheduled in iso_stream_schedule()
4206 excess = (stream->next_uframe - period - next) & (mod - 1); in iso_stream_schedule()
4207 if (excess >= mod - 2 * SCHEDULE_SLOP) in iso_stream_schedule()
4208 start = next + excess - mod + period * in iso_stream_schedule()
4209 DIV_ROUND_UP(mod - excess, period); in iso_stream_schedule()
4212 if (start - now >= mod) { in iso_stream_schedule()
4214 urb, start - now - period, period, in iso_stream_schedule()
4216 status = -EFBIG; in iso_stream_schedule()
4222 * this is bigger than fotg210->i_thresh allows; scheduling itself in iso_stream_schedule()
4235 * Early uframes are more precious because full-speed in iso_stream_schedule()
4242 start--; in iso_stream_schedule()
4245 stream->usecs, period)) in iso_stream_schedule()
4253 status = -ENOSPC; in iso_stream_schedule()
4259 if (unlikely(start - now + span - period >= in iso_stream_schedule()
4260 mod - 2 * SCHEDULE_SLOP)) { in iso_stream_schedule()
4262 urb, start - now, span - period, in iso_stream_schedule()
4263 mod - 2 * SCHEDULE_SLOP); in iso_stream_schedule()
4264 status = -EFBIG; in iso_stream_schedule()
4268 stream->next_uframe = start & (mod - 1); in iso_stream_schedule()
4271 urb->start_frame = stream->next_uframe; in iso_stream_schedule()
4272 if (!stream->highspeed) in iso_stream_schedule()
4273 urb->start_frame >>= 3; in iso_stream_schedule()
4276 if (fotg210->isoc_count == 0) in iso_stream_schedule()
4277 fotg210->next_frame = now >> 3; in iso_stream_schedule()
4282 urb->hcpriv = NULL; in iso_stream_schedule()
4292 itd->hw_next = FOTG210_LIST_END(fotg210); in itd_init()
4293 itd->hw_bufp[0] = stream->buf0; in itd_init()
4294 itd->hw_bufp[1] = stream->buf1; in itd_init()
4295 itd->hw_bufp[2] = stream->buf2; in itd_init()
4298 itd->index[i] = -1; in itd_init()
4307 struct fotg210_iso_packet *uf = &iso_sched->packet[index]; in itd_patch()
4308 unsigned pg = itd->pg; in itd_patch()
4311 itd->index[uframe] = index; in itd_patch()
4313 itd->hw_transaction[uframe] = uf->transaction; in itd_patch()
4314 itd->hw_transaction[uframe] |= cpu_to_hc32(fotg210, pg << 12); in itd_patch()
4315 itd->hw_bufp[pg] |= cpu_to_hc32(fotg210, uf->bufp & ~(u32)0); in itd_patch()
4316 itd->hw_bufp_hi[pg] |= cpu_to_hc32(fotg210, (u32)(uf->bufp >> 32)); in itd_patch()
4319 if (unlikely(uf->cross)) { in itd_patch()
4320 u64 bufp = uf->bufp + 4096; in itd_patch()
4322 itd->pg = ++pg; in itd_patch()
4323 itd->hw_bufp[pg] |= cpu_to_hc32(fotg210, bufp & ~(u32)0); in itd_patch()
4324 itd->hw_bufp_hi[pg] |= cpu_to_hc32(fotg210, (u32)(bufp >> 32)); in itd_patch()
4331 union fotg210_shadow *prev = &fotg210->pshadow[frame]; in itd_link()
4332 __hc32 *hw_p = &fotg210->periodic[frame]; in itd_link()
4346 itd->itd_next = here; in itd_link()
4347 itd->hw_next = *hw_p; in itd_link()
4348 prev->itd = itd; in itd_link()
4349 itd->frame = frame; in itd_link()
4351 *hw_p = cpu_to_hc32(fotg210, itd->itd_dma | Q_TYPE_ITD); in itd_link()
4360 struct fotg210_iso_sched *iso_sched = urb->hcpriv; in itd_link_urb()
4363 next_uframe = stream->next_uframe & (mod - 1); in itd_link_urb()
4365 if (unlikely(list_empty(&stream->td_list))) { in itd_link_urb()
4366 fotg210_to_hcd(fotg210)->self.bandwidth_allocated in itd_link_urb()
4367 += stream->bandwidth; in itd_link_urb()
4369 "schedule devp %s ep%d%s-iso period %d start %d.%d\n", in itd_link_urb()
4370 urb->dev->devpath, stream->bEndpointAddress & 0x0f, in itd_link_urb()
4371 (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out", in itd_link_urb()
4372 urb->interval, in itd_link_urb()
4377 for (packet = 0, itd = NULL; packet < urb->number_of_packets;) { in itd_link_urb()
4383 itd = list_entry(iso_sched->td_list.next, in itd_link_urb()
4385 list_move_tail(&itd->itd_list, &stream->td_list); in itd_link_urb()
4386 itd->stream = stream; in itd_link_urb()
4387 itd->urb = urb; in itd_link_urb()
4396 next_uframe += stream->interval; in itd_link_urb()
4397 next_uframe &= mod - 1; in itd_link_urb()
4402 || packet == urb->number_of_packets) { in itd_link_urb()
4403 itd_link(fotg210, frame & (fotg210->periodic_size - 1), in itd_link_urb()
4408 stream->next_uframe = next_uframe; in itd_link_urb()
4412 urb->hcpriv = NULL; in itd_link_urb()
4414 ++fotg210->isoc_count; in itd_link_urb()
4433 struct urb *urb = itd->urb; in itd_complete()
4437 int urb_index = -1; in itd_complete()
4438 struct fotg210_iso_stream *stream = itd->stream; in itd_complete()
4444 if (likely(itd->index[uframe] == -1)) in itd_complete()
4446 urb_index = itd->index[uframe]; in itd_complete()
4447 desc = &urb->iso_frame_desc[urb_index]; in itd_complete()
4449 t = hc32_to_cpup(fotg210, &itd->hw_transaction[uframe]); in itd_complete()
4450 itd->hw_transaction[uframe] = 0; in itd_complete()
4454 urb->error_count++; in itd_complete()
4456 desc->status = usb_pipein(urb->pipe) in itd_complete()
4457 ? -ENOSR /* hc couldn't read */ in itd_complete()
4458 : -ECOMM; /* hc couldn't write */ in itd_complete()
4460 desc->status = -EOVERFLOW; in itd_complete()
4462 desc->status = -EPROTO; in itd_complete()
4466 desc->actual_length = FOTG210_ITD_LENGTH(t); in itd_complete()
4467 urb->actual_length += desc->actual_length; in itd_complete()
4470 desc->status = 0; in itd_complete()
4471 desc->actual_length = FOTG210_ITD_LENGTH(t); in itd_complete()
4472 urb->actual_length += desc->actual_length; in itd_complete()
4475 desc->status = -EXDEV; in itd_complete()
4480 if (likely((urb_index + 1) != urb->number_of_packets)) in itd_complete()
4484 * list_for_each_entry (itd, &stream->td_list, itd_list) in itd_complete()
4485 * BUG_ON (itd->urb == urb); in itd_complete()
4489 dev = urb->dev; in itd_complete()
4494 --fotg210->isoc_count; in itd_complete()
4497 if (unlikely(list_is_singular(&stream->td_list))) { in itd_complete()
4498 fotg210_to_hcd(fotg210)->self.bandwidth_allocated in itd_complete()
4499 -= stream->bandwidth; in itd_complete()
4501 "deschedule devp %s ep%d%s-iso\n", in itd_complete()
4502 dev->devpath, stream->bEndpointAddress & 0x0f, in itd_complete()
4503 (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out"); in itd_complete()
4507 itd->urb = NULL; in itd_complete()
4510 list_move_tail(&itd->itd_list, &stream->free_list); in itd_complete()
4513 if (list_empty(&stream->td_list)) { in itd_complete()
4514 list_splice_tail_init(&stream->free_list, in itd_complete()
4515 &fotg210->cached_itd_list); in itd_complete()
4525 int status = -EINVAL; in itd_submit()
4533 return -ENOMEM; in itd_submit()
4535 if (unlikely(urb->interval != stream->interval && in itd_submit()
4538 fotg210_dbg(fotg210, "can't change iso interval %d --> %d\n", in itd_submit()
4539 stream->interval, urb->interval); in itd_submit()
4546 __func__, urb->dev->devpath, urb, in itd_submit()
4547 usb_pipeendpoint(urb->pipe), in itd_submit()
4548 usb_pipein(urb->pipe) ? "in" : "out", in itd_submit()
4549 urb->transfer_buffer_length, in itd_submit()
4550 urb->number_of_packets, urb->interval, in itd_submit()
4562 spin_lock_irqsave(&fotg210->lock, flags); in itd_submit()
4564 status = -ESHUTDOWN; in itd_submit()
4572 itd_link_urb(fotg210, urb, fotg210->periodic_size << 3, stream); in itd_submit()
4576 spin_unlock_irqrestore(&fotg210->lock, flags); in itd_submit()
4590 q_p = &fotg210->pshadow[frame]; in scan_frame_queue()
4591 hw_p = &fotg210->periodic[frame]; in scan_frame_queue()
4592 q.ptr = q_p->ptr; in scan_frame_queue()
4607 if (q.itd->hw_transaction[uf] & in scan_frame_queue()
4612 q_p = &q.itd->itd_next; in scan_frame_queue()
4613 hw_p = &q.itd->hw_next; in scan_frame_queue()
4615 q.itd->hw_next); in scan_frame_queue()
4626 *q_p = q.itd->itd_next; in scan_frame_queue()
4627 *hw_p = q.itd->hw_next; in scan_frame_queue()
4628 type = Q_NEXT_TYPE(fotg210, q.itd->hw_next); in scan_frame_queue()
4645 if (unlikely(modified && fotg210->isoc_count > 0)) in scan_frame_queue()
4646 return -EINVAL; in scan_frame_queue()
4654 unsigned fmask = fotg210->periodic_size - 1; in scan_isoc()
4660 * Touches as few pages as possible: cache-friendly. in scan_isoc()
4662 if (fotg210->rh_state >= FOTG210_RH_RUNNING) { in scan_isoc()
4667 now_frame = (fotg210->next_frame - 1) & fmask; in scan_isoc()
4670 fotg210->now_frame = now_frame; in scan_isoc()
4672 frame = fotg210->next_frame; in scan_isoc()
4684 fotg210->next_frame = now_frame; in scan_isoc()
4696 n = scnprintf(buf, PAGE_SIZE, "%d\n", fotg210->uframe_periodic_max); in uframe_periodic_max_show()
4713 return -EINVAL; in uframe_periodic_max_store()
4718 return -EINVAL; in uframe_periodic_max_store()
4721 ret = -EINVAL; in uframe_periodic_max_store()
4727 spin_lock_irqsave(&fotg210->lock, flags); in uframe_periodic_max_store()
4734 if (uframe_periodic_max < fotg210->uframe_periodic_max) { in uframe_periodic_max_store()
4737 for (frame = 0; frame < fotg210->periodic_size; ++frame) in uframe_periodic_max_store()
4758 fotg210_warn(fotg210, "max periodic bandwidth set is non-standard\n"); in uframe_periodic_max_store()
4760 fotg210->uframe_periodic_max = uframe_periodic_max; in uframe_periodic_max_store()
4764 spin_unlock_irqrestore(&fotg210->lock, flags); in uframe_periodic_max_store()
4772 struct device *controller = fotg210_to_hcd(fotg210)->self.controller; in create_sysfs_files()
4779 struct device *controller = fotg210_to_hcd(fotg210)->self.controller; in remove_sysfs_files()
4789 u32 __iomem *status_reg = &fotg210->regs->port_status; in fotg210_turn_off_all_ports()
4801 spin_lock_irq(&fotg210->lock); in fotg210_silence_controller()
4802 fotg210->rh_state = FOTG210_RH_HALTED; in fotg210_silence_controller()
4804 spin_unlock_irq(&fotg210->lock); in fotg210_silence_controller()
4815 spin_lock_irq(&fotg210->lock); in fotg210_shutdown()
4816 fotg210->shutdown = true; in fotg210_shutdown()
4817 fotg210->rh_state = FOTG210_RH_STOPPING; in fotg210_shutdown()
4818 fotg210->enabled_hrtimer_events = 0; in fotg210_shutdown()
4819 spin_unlock_irq(&fotg210->lock); in fotg210_shutdown()
4823 hrtimer_cancel(&fotg210->hrtimer); in fotg210_shutdown()
4827 * it calls driver completion functions, after dropping fotg210->lock.
4831 /* another CPU may drop fotg210->lock during a schedule scan while in fotg210_work()
4833 * attempts at re-entrant schedule scanning. in fotg210_work()
4835 if (fotg210->scanning) { in fotg210_work()
4836 fotg210->need_rescan = true; in fotg210_work()
4839 fotg210->scanning = true; in fotg210_work()
4842 fotg210->need_rescan = false; in fotg210_work()
4843 if (fotg210->async_count) in fotg210_work()
4845 if (fotg210->intr_count > 0) in fotg210_work()
4847 if (fotg210->isoc_count > 0) in fotg210_work()
4849 if (fotg210->need_rescan) in fotg210_work()
4851 fotg210->scanning = false; in fotg210_work()
4870 spin_lock_irq(&fotg210->lock); in fotg210_stop()
4871 fotg210->enabled_hrtimer_events = 0; in fotg210_stop()
4872 spin_unlock_irq(&fotg210->lock); in fotg210_stop()
4878 hrtimer_cancel(&fotg210->hrtimer); in fotg210_stop()
4883 spin_lock_irq(&fotg210->lock); in fotg210_stop()
4885 spin_unlock_irq(&fotg210->lock); in fotg210_stop()
4890 fotg210->stats.normal, fotg210->stats.error, in fotg210_stop()
4891 fotg210->stats.iaa, fotg210->stats.lost_iaa); in fotg210_stop()
4893 fotg210->stats.complete, fotg210->stats.unlink); in fotg210_stop()
4897 fotg210_readl(fotg210, &fotg210->regs->status)); in fotg210_stop()
4900 /* one-time init, only for memory state */
4909 spin_lock_init(&fotg210->lock); in hcd_fotg210_init()
4914 fotg210->need_io_watchdog = 1; in hcd_fotg210_init()
4916 hrtimer_init(&fotg210->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); in hcd_fotg210_init()
4917 fotg210->hrtimer.function = fotg210_hrtimer_func; in hcd_fotg210_init()
4918 fotg210->next_hrtimer_event = FOTG210_HRTIMER_NO_EVENT; in hcd_fotg210_init()
4920 hcc_params = fotg210_readl(fotg210, &fotg210->caps->hcc_params); in hcd_fotg210_init()
4926 fotg210->uframe_periodic_max = 100; in hcd_fotg210_init()
4932 fotg210->periodic_size = DEFAULT_I_TDPS; in hcd_fotg210_init()
4933 INIT_LIST_HEAD(&fotg210->intr_qh_list); in hcd_fotg210_init()
4934 INIT_LIST_HEAD(&fotg210->cached_itd_list); in hcd_fotg210_init()
4940 fotg210->periodic_size = 1024; in hcd_fotg210_init()
4943 fotg210->periodic_size = 512; in hcd_fotg210_init()
4946 fotg210->periodic_size = 256; in hcd_fotg210_init()
4957 fotg210->i_thresh = 2; in hcd_fotg210_init()
4966 fotg210->async->qh_next.qh = NULL; in hcd_fotg210_init()
4967 hw = fotg210->async->hw; in hcd_fotg210_init()
4968 hw->hw_next = QH_NEXT(fotg210, fotg210->async->qh_dma); in hcd_fotg210_init()
4969 hw->hw_info1 = cpu_to_hc32(fotg210, QH_HEAD); in hcd_fotg210_init()
4970 hw->hw_token = cpu_to_hc32(fotg210, QTD_STS_HALT); in hcd_fotg210_init()
4971 hw->hw_qtd_next = FOTG210_LIST_END(fotg210); in hcd_fotg210_init()
4972 fotg210->async->qh_state = QH_STATE_LINKED; in hcd_fotg210_init()
4973 hw->hw_alt_next = QTD_NEXT(fotg210, fotg210->async->dummy->qtd_dma); in hcd_fotg210_init()
4999 fotg210->command = temp; in hcd_fotg210_init()
5001 /* Accept arbitrarily long scatter-gather lists */ in hcd_fotg210_init()
5002 if (!hcd->localmem_pool) in hcd_fotg210_init()
5003 hcd->self.sg_tablesize = ~0; in hcd_fotg210_init()
5013 hcd->uses_new_polling = 1; in fotg210_run()
5017 fotg210_writel(fotg210, fotg210->periodic_dma, in fotg210_run()
5018 &fotg210->regs->frame_list); in fotg210_run()
5019 fotg210_writel(fotg210, (u32)fotg210->async->qh_dma, in fotg210_run()
5020 &fotg210->regs->async_next); in fotg210_run()
5023 * hcc_params controls whether fotg210->regs->segment must (!!!) in fotg210_run()
5029 * NOTE: the dma mask is visible through dev->dma_mask, so in fotg210_run()
5034 fotg210_readl(fotg210, &fotg210->caps->hcc_params); in fotg210_run()
5040 fotg210->command &= ~(CMD_IAAD|CMD_PSE|CMD_ASE|CMD_RESET); in fotg210_run()
5041 fotg210->command |= CMD_RUN; in fotg210_run()
5042 fotg210_writel(fotg210, fotg210->command, &fotg210->regs->command); in fotg210_run()
5043 dbg_cmd(fotg210, "init", fotg210->command); in fotg210_run()
5054 * could cause trouble. Write-locking ehci_cf_port_reset_rwsem in fotg210_run()
5060 fotg210->rh_state = FOTG210_RH_RUNNING; in fotg210_run()
5062 fotg210_readl(fotg210, &fotg210->regs->command); in fotg210_run()
5065 fotg210->last_periodic_enable = ktime_get_real(); in fotg210_run()
5068 fotg210_readl(fotg210, &fotg210->caps->hc_capbase)); in fotg210_run()
5071 ((fotg210->sbrn & 0xf0) >> 4), (fotg210->sbrn & 0x0f), in fotg210_run()
5075 &fotg210->regs->intr_enable); /* Turn On Interrupts */ in fotg210_run()
5077 /* GRR this is run-once init(), being done every time the HC starts. in fotg210_run()
5092 fotg210->regs = (void __iomem *)fotg210->caps + in fotg210_setup()
5094 fotg210_readl(fotg210, &fotg210->caps->hc_capbase)); in fotg210_setup()
5099 fotg210->hcs_params = fotg210_readl(fotg210, in fotg210_setup()
5100 &fotg210->caps->hcs_params); in fotg210_setup()
5102 fotg210->sbrn = HCD_USB2; in fotg210_setup()
5124 spin_lock(&fotg210->lock); in fotg210_irq()
5126 status = fotg210_readl(fotg210, &fotg210->regs->status); in fotg210_irq()
5142 unlikely(fotg210->rh_state == FOTG210_RH_HALTED)) { in fotg210_irq()
5143 spin_unlock(&fotg210->lock); in fotg210_irq()
5148 fotg210_writel(fotg210, masked_status, &fotg210->regs->status); in fotg210_irq()
5149 cmd = fotg210_readl(fotg210, &fotg210->regs->command); in fotg210_irq()
5160 INCR(fotg210->stats.normal); in fotg210_irq()
5162 INCR(fotg210->stats.error); in fotg210_irq()
5170 fotg210->enabled_hrtimer_events &= in fotg210_irq()
5180 if (fotg210->next_hrtimer_event == FOTG210_HRTIMER_IAA_WATCHDOG) in fotg210_irq()
5181 ++fotg210->next_hrtimer_event; in fotg210_irq()
5186 if (fotg210->async_iaa) { in fotg210_irq()
5187 INCR(fotg210->stats.iaa); in fotg210_irq()
5196 u32 __iomem *status_reg = &fotg210->regs->port_status; in fotg210_irq()
5202 if (fotg210->rh_state == FOTG210_RH_SUSPENDED) in fotg210_irq()
5207 if (test_bit(0, &fotg210->suspended_ports) && in fotg210_irq()
5211 fotg210->reset_done[0] == 0) { in fotg210_irq()
5215 * stop that signaling. Use 5 ms extra for safety, in fotg210_irq()
5218 fotg210->reset_done[0] = jiffies + msecs_to_jiffies(25); in fotg210_irq()
5219 set_bit(0, &fotg210->resuming_ports); in fotg210_irq()
5221 mod_timer(&hcd->rh_timer, fotg210->reset_done[0]); in fotg210_irq()
5234 fotg210->shutdown = true; in fotg210_irq()
5235 fotg210->rh_state = FOTG210_RH_STOPPING; in fotg210_irq()
5236 fotg210->command &= ~(CMD_RUN | CMD_ASE | CMD_PSE); in fotg210_irq()
5237 fotg210_writel(fotg210, fotg210->command, in fotg210_irq()
5238 &fotg210->regs->command); in fotg210_irq()
5239 fotg210_writel(fotg210, 0, &fotg210->regs->intr_enable); in fotg210_irq()
5248 spin_unlock(&fotg210->lock); in fotg210_irq()
5254 /* non-error returns are a promise to giveback() the urb later
5260 * hcd-specific init for hcpriv hasn't been done yet
5273 switch (usb_pipetype(urb->pipe)) { in fotg210_urb_enqueue()
5276 * in multi-TD control transfers. Even 1KB is rare anyway. in fotg210_urb_enqueue()
5278 if (urb->transfer_buffer_length > (16 * 1024)) in fotg210_urb_enqueue()
5279 return -EMSGSIZE; in fotg210_urb_enqueue()
5284 return -ENOMEM; in fotg210_urb_enqueue()
5289 return -ENOMEM; in fotg210_urb_enqueue()
5308 spin_lock_irqsave(&fotg210->lock, flags); in fotg210_urb_dequeue()
5313 switch (usb_pipetype(urb->pipe)) { in fotg210_urb_dequeue()
5317 qh = (struct fotg210_qh *) urb->hcpriv; in fotg210_urb_dequeue()
5320 switch (qh->qh_state) { in fotg210_urb_dequeue()
5330 /* QH might be waiting for a Clear-TT-Buffer */ in fotg210_urb_dequeue()
5337 qh = (struct fotg210_qh *) urb->hcpriv; in fotg210_urb_dequeue()
5340 switch (qh->qh_state) { in fotg210_urb_dequeue()
5350 qh, qh->qh_state); in fotg210_urb_dequeue()
5363 spin_unlock_irqrestore(&fotg210->lock, flags); in fotg210_urb_dequeue()
5380 spin_lock_irqsave(&fotg210->lock, flags); in fotg210_endpoint_disable()
5381 qh = ep->hcpriv; in fotg210_endpoint_disable()
5388 if (qh->hw == NULL) { in fotg210_endpoint_disable()
5389 struct fotg210_iso_stream *stream = ep->hcpriv; in fotg210_endpoint_disable()
5391 if (!list_empty(&stream->td_list)) in fotg210_endpoint_disable()
5394 /* BUG_ON(!list_empty(&stream->free_list)); */ in fotg210_endpoint_disable()
5399 if (fotg210->rh_state < FOTG210_RH_RUNNING) in fotg210_endpoint_disable()
5400 qh->qh_state = QH_STATE_IDLE; in fotg210_endpoint_disable()
5401 switch (qh->qh_state) { in fotg210_endpoint_disable()
5404 for (tmp = fotg210->async->qh_next.qh; in fotg210_endpoint_disable()
5406 tmp = tmp->qh_next.qh) in fotg210_endpoint_disable()
5408 /* periodic qh self-unlinks on empty, and a COMPLETING qh in fotg210_endpoint_disable()
5417 spin_unlock_irqrestore(&fotg210->lock, flags); in fotg210_endpoint_disable()
5421 if (qh->clearing_tt) in fotg210_endpoint_disable()
5423 if (list_empty(&qh->qtd_list)) { in fotg210_endpoint_disable()
5433 qh, ep->desc.bEndpointAddress, qh->qh_state, in fotg210_endpoint_disable()
5434 list_empty(&qh->qtd_list) ? "" : "(has tds)"); in fotg210_endpoint_disable()
5438 ep->hcpriv = NULL; in fotg210_endpoint_disable()
5439 spin_unlock_irqrestore(&fotg210->lock, flags); in fotg210_endpoint_disable()
5447 int eptype = usb_endpoint_type(&ep->desc); in fotg210_endpoint_reset()
5448 int epnum = usb_endpoint_num(&ep->desc); in fotg210_endpoint_reset()
5449 int is_out = usb_endpoint_dir_out(&ep->desc); in fotg210_endpoint_reset()
5455 spin_lock_irqsave(&fotg210->lock, flags); in fotg210_endpoint_reset()
5456 qh = ep->hcpriv; in fotg210_endpoint_reset()
5464 usb_settoggle(qh->dev, epnum, is_out, 0); in fotg210_endpoint_reset()
5465 if (!list_empty(&qh->qtd_list)) { in fotg210_endpoint_reset()
5467 } else if (qh->qh_state == QH_STATE_LINKED || in fotg210_endpoint_reset()
5468 qh->qh_state == QH_STATE_COMPLETING) { in fotg210_endpoint_reset()
5472 * re-linking will call qh_refresh(). in fotg210_endpoint_reset()
5480 spin_unlock_irqrestore(&fotg210->lock, flags); in fotg210_endpoint_reset()
5488 fotg210->periodic_size; in fotg210_get_frame()
5551 &fotg210->regs->gmir); in fotg210_init()
5553 value = ioread32(&fotg210->regs->otgcsr); in fotg210_init()
5556 iowrite32(value, &fotg210->regs->otgcsr); in fotg210_init()
5560 * fotg210_hcd_probe - initialize faraday FOTG210 HCDs
5568 struct device *dev = &pdev->dev; in fotg210_hcd_probe()
5576 return -ENODEV; in fotg210_hcd_probe()
5578 pdev->dev.power.power_state = PMSG_ON; in fotg210_hcd_probe()
5584 return -ENODEV; in fotg210_hcd_probe()
5587 irq = res->start; in fotg210_hcd_probe()
5593 retval = -ENOMEM; in fotg210_hcd_probe()
5597 hcd->has_tt = 1; in fotg210_hcd_probe()
5600 hcd->regs = devm_ioremap_resource(&pdev->dev, res); in fotg210_hcd_probe()
5601 if (IS_ERR(hcd->regs)) { in fotg210_hcd_probe()
5602 retval = PTR_ERR(hcd->regs); in fotg210_hcd_probe()
5606 hcd->rsrc_start = res->start; in fotg210_hcd_probe()
5607 hcd->rsrc_len = resource_size(res); in fotg210_hcd_probe()
5611 fotg210->caps = hcd->regs; in fotg210_hcd_probe()
5614 fotg210->pclk = clk_get(dev, "PCLK"); in fotg210_hcd_probe()
5615 if (!IS_ERR(fotg210->pclk)) { in fotg210_hcd_probe()
5616 retval = clk_prepare_enable(fotg210->pclk); in fotg210_hcd_probe()
5621 } else if (PTR_ERR(fotg210->pclk) == -EPROBE_DEFER) { in fotg210_hcd_probe()
5626 retval = PTR_ERR(fotg210->pclk); in fotg210_hcd_probe()
5641 device_wakeup_enable(hcd->self.controller); in fotg210_hcd_probe()
5647 if (!IS_ERR(fotg210->pclk)) { in fotg210_hcd_probe()
5648 clk_disable_unprepare(fotg210->pclk); in fotg210_hcd_probe()
5649 clk_put(fotg210->pclk); in fotg210_hcd_probe()
5659 * fotg210_hcd_remove - shutdown processing for EHCI HCDs
5668 if (!IS_ERR(fotg210->pclk)) { in fotg210_hcd_remove()
5669 clk_disable_unprepare(fotg210->pclk); in fotg210_hcd_remove()
5670 clk_put(fotg210->pclk); in fotg210_hcd_remove()
5689 .name = "fotg210-hcd",
5701 return -ENODEV; in fotg210_hcd_init()