Lines Matching defs:fotg210

41 #include "fotg210.h"
79 #include "fotg210-hcd.h"
81 #define fotg210_dbg(fotg210, fmt, args...) \
82 dev_dbg(fotg210_to_hcd(fotg210)->self.controller, fmt, ## args)
83 #define fotg210_err(fotg210, fmt, args...) \
84 dev_err(fotg210_to_hcd(fotg210)->self.controller, fmt, ## args)
85 #define fotg210_info(fotg210, fmt, args...) \
86 dev_info(fotg210_to_hcd(fotg210)->self.controller, fmt, ## args)
87 #define fotg210_warn(fotg210, fmt, args...) \
88 dev_warn(fotg210_to_hcd(fotg210)->self.controller, fmt, ## args)
93 static void dbg_hcs_params(struct fotg210_hcd *fotg210, char *label)
95 u32 params = fotg210_readl(fotg210, &fotg210->caps->hcs_params);
97 fotg210_dbg(fotg210, "%s hcs_params 0x%x ports=%d\n", label, params,
104 static void dbg_hcc_params(struct fotg210_hcd *fotg210, char *label)
106 u32 params = fotg210_readl(fotg210, &fotg210->caps->hcc_params);
108 fotg210_dbg(fotg210, "%s hcc_params %04x uframes %s%s\n", label,
115 dbg_qtd(const char *label, struct fotg210_hcd *fotg210, struct fotg210_qtd *qtd)
117 fotg210_dbg(fotg210, "%s td %p n%08x %08x t%08x p0=%08x\n", label, qtd,
118 hc32_to_cpup(fotg210, &qtd->hw_next),
119 hc32_to_cpup(fotg210, &qtd->hw_alt_next),
120 hc32_to_cpup(fotg210, &qtd->hw_token),
121 hc32_to_cpup(fotg210, &qtd->hw_buf[0]));
123 fotg210_dbg(fotg210, " p1=%08x p2=%08x p3=%08x p4=%08x\n",
124 hc32_to_cpup(fotg210, &qtd->hw_buf[1]),
125 hc32_to_cpup(fotg210, &qtd->hw_buf[2]),
126 hc32_to_cpup(fotg210, &qtd->hw_buf[3]),
127 hc32_to_cpup(fotg210, &qtd->hw_buf[4]));
131 dbg_qh(const char *label, struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
135 fotg210_dbg(fotg210, "%s qh %p n%08x info %x %x qtd %x\n", label, qh,
139 dbg_qtd("overlay", fotg210, (struct fotg210_qtd *) &hw->hw_qtd_next);
143 dbg_itd(const char *label, struct fotg210_hcd *fotg210, struct fotg210_itd *itd)
145 fotg210_dbg(fotg210, "%s[%d] itd %p, next %08x, urb %p\n", label,
146 itd->frame, itd, hc32_to_cpu(fotg210, itd->hw_next),
149 fotg210_dbg(fotg210,
151 hc32_to_cpu(fotg210, itd->hw_transaction[0]),
152 hc32_to_cpu(fotg210, itd->hw_transaction[1]),
153 hc32_to_cpu(fotg210, itd->hw_transaction[2]),
154 hc32_to_cpu(fotg210, itd->hw_transaction[3]),
155 hc32_to_cpu(fotg210, itd->hw_transaction[4]),
156 hc32_to_cpu(fotg210, itd->hw_transaction[5]),
157 hc32_to_cpu(fotg210, itd->hw_transaction[6]),
158 hc32_to_cpu(fotg210, itd->hw_transaction[7]));
160 fotg210_dbg(fotg210,
162 hc32_to_cpu(fotg210, itd->hw_bufp[0]),
163 hc32_to_cpu(fotg210, itd->hw_bufp[1]),
164 hc32_to_cpu(fotg210, itd->hw_bufp[2]),
165 hc32_to_cpu(fotg210, itd->hw_bufp[3]),
166 hc32_to_cpu(fotg210, itd->hw_bufp[4]),
167 hc32_to_cpu(fotg210, itd->hw_bufp[5]),
168 hc32_to_cpu(fotg210, itd->hw_bufp[6]));
170 fotg210_dbg(fotg210, " index: %d %d %d %d %d %d %d %d\n",
262 #define dbg_status(fotg210, label, status) { \
265 fotg210_dbg(fotg210, "%s\n", _buf); \
268 #define dbg_cmd(fotg210, label, command) { \
271 fotg210_dbg(fotg210, "%s\n", _buf); \
274 #define dbg_port(fotg210, label, port, status) { \
276 fotg210_dbg(fotg210, "%s\n", \
339 static inline char token_mark(struct fotg210_hcd *fotg210, __hc32 token)
341 __u32 v = hc32_to_cpu(fotg210, token);
353 static void qh_lines(struct fotg210_hcd *fotg210, struct fotg210_qh *qh,
363 __le32 list_end = FOTG210_LIST_END(fotg210);
369 mark = token_mark(fotg210, hw->hw_token);
371 if ((hw->hw_alt_next & QTD_MASK(fotg210)) ==
372 fotg210->async->hw->hw_alt_next)
378 scratch = hc32_to_cpup(fotg210, &hw->hw_info1);
379 hw_curr = (mark == '*') ? hc32_to_cpup(fotg210, &hw->hw_current) : 0;
385 scratch, hc32_to_cpup(fotg210, &hw->hw_info2),
386 hc32_to_cpup(fotg210, &hw->hw_token), mark,
387 (cpu_to_hc32(fotg210, QTD_TOGGLE) & hw->hw_token)
389 (hc32_to_cpup(fotg210, &hw->hw_alt_next) >> 1) & 0x0f);
395 scratch = hc32_to_cpup(fotg210, &td->hw_token);
399 else if (hw->hw_qtd_next == cpu_to_hc32(fotg210, td->qtd_dma))
402 if (td->hw_alt_next == fotg210->async->hw->hw_alt_next)
447 struct fotg210_hcd *fotg210;
454 fotg210 = hcd_to_fotg210(hcd);
464 spin_lock_irqsave(&fotg210->lock, flags);
465 for (qh = fotg210->async->qh_next.qh; size > 0 && qh;
467 qh_lines(fotg210, qh, &next, &size);
468 if (fotg210->async_unlink && size > 0) {
473 for (qh = fotg210->async_unlink; size > 0 && qh;
475 qh_lines(fotg210, qh, &next, &size);
477 spin_unlock_irqrestore(&fotg210->lock, flags);
483 static unsigned output_buf_tds_dir(char *buf, struct fotg210_hcd *fotg210,
486 u32 scratch = hc32_to_cpup(fotg210, &hw->hw_info1);
494 switch ((hc32_to_cpu(fotg210, qtd->hw_token) >> 8) & 0x03) {
514 struct fotg210_hcd *fotg210;
529 fotg210 = hcd_to_fotg210(hcd);
533 temp = scnprintf(next, size, "size = %d\n", fotg210->periodic_size);
540 spin_lock_irqsave(&fotg210->lock, flags);
541 for (i = 0; i < fotg210->periodic_size; i++) {
542 p = fotg210->pshadow[i];
546 tag = Q_NEXT_TYPE(fotg210, fotg210->periodic[i]);
555 switch (hc32_to_cpu(fotg210, tag)) {
560 hc32_to_cpup(fotg210,
582 fotg210, hw,
589 tag = Q_NEXT_TYPE(fotg210, hw->hw_next);
596 tag = Q_NEXT_TYPE(fotg210, p.fstn->hw_next);
602 tag = Q_NEXT_TYPE(fotg210, p.itd->hw_next);
614 spin_unlock_irqrestore(&fotg210->lock, flags);
621 static const char *rh_state_string(struct fotg210_hcd *fotg210)
623 switch (fotg210->rh_state) {
639 struct fotg210_hcd *fotg210;
647 fotg210 = hcd_to_fotg210(hcd);
651 spin_lock_irqsave(&fotg210->lock, flags);
665 i = HC_VERSION(fotg210, fotg210_readl(fotg210,
666 &fotg210->caps->hc_capbase));
674 i >> 8, i & 0x0ff, rh_state_string(fotg210));
679 i = fotg210_readl(fotg210, &fotg210->caps->hcs_params);
684 i = fotg210_readl(fotg210, &fotg210->caps->hcc_params);
691 fotg210_readl(fotg210, &fotg210->regs->status));
697 fotg210_readl(fotg210, &fotg210->regs->command));
703 fotg210_readl(fotg210, &fotg210->regs->intr_enable));
709 fotg210_read_frame_index(fotg210));
713 if (fotg210->async_unlink) {
715 fotg210->async_unlink);
723 fotg210->stats.normal, fotg210->stats.error,
724 fotg210->stats.iaa, fotg210->stats.lost_iaa);
729 fotg210->stats.complete, fotg210->stats.unlink);
735 spin_unlock_irqrestore(&fotg210->lock, flags);
843 static inline void create_debug_files(struct fotg210_hcd *fotg210)
845 struct usb_bus *bus = &fotg210_to_hcd(fotg210)->self;
857 static inline void remove_debug_files(struct fotg210_hcd *fotg210)
859 struct usb_bus *bus = &fotg210_to_hcd(fotg210)->self;
880 static int handshake(struct fotg210_hcd *fotg210, void __iomem *ptr,
898 static int fotg210_halt(struct fotg210_hcd *fotg210)
902 spin_lock_irq(&fotg210->lock);
905 fotg210_writel(fotg210, 0, &fotg210->regs->intr_enable);
908 * This routine gets called during probe before fotg210->command
911 fotg210->command &= ~CMD_RUN;
912 temp = fotg210_readl(fotg210, &fotg210->regs->command);
914 fotg210_writel(fotg210, temp, &fotg210->regs->command);
916 spin_unlock_irq(&fotg210->lock);
917 synchronize_irq(fotg210_to_hcd(fotg210)->irq);
919 return handshake(fotg210, &fotg210->regs->status,
926 static int fotg210_reset(struct fotg210_hcd *fotg210)
929 u32 command = fotg210_readl(fotg210, &fotg210->regs->command);
934 if (fotg210->debug && !dbgp_reset_prep(fotg210_to_hcd(fotg210)))
935 fotg210->debug = NULL;
938 dbg_cmd(fotg210, "reset", command);
939 fotg210_writel(fotg210, command, &fotg210->regs->command);
940 fotg210->rh_state = FOTG210_RH_HALTED;
941 fotg210->next_statechange = jiffies;
942 retval = handshake(fotg210, &fotg210->regs->command,
948 if (fotg210->debug)
949 dbgp_external_startup(fotg210_to_hcd(fotg210));
951 fotg210->port_c_suspend = fotg210->suspended_ports =
952 fotg210->resuming_ports = 0;
959 static void fotg210_quiesce(struct fotg210_hcd *fotg210)
963 if (fotg210->rh_state != FOTG210_RH_RUNNING)
967 temp = (fotg210->command << 10) & (STS_ASS | STS_PSS);
968 handshake(fotg210, &fotg210->regs->status, STS_ASS | STS_PSS, temp,
972 spin_lock_irq(&fotg210->lock);
973 fotg210->command &= ~(CMD_ASE | CMD_PSE);
974 fotg210_writel(fotg210, fotg210->command, &fotg210->regs->command);
975 spin_unlock_irq(&fotg210->lock);
978 handshake(fotg210, &fotg210->regs->status, STS_ASS | STS_PSS, 0,
982 static void end_unlink_async(struct fotg210_hcd *fotg210);
983 static void unlink_empty_async(struct fotg210_hcd *fotg210);
984 static void fotg210_work(struct fotg210_hcd *fotg210);
985 static void start_unlink_intr(struct fotg210_hcd *fotg210,
987 static void end_unlink_intr(struct fotg210_hcd *fotg210, struct fotg210_qh *qh);
990 static void fotg210_set_command_bit(struct fotg210_hcd *fotg210, u32 bit)
992 fotg210->command |= bit;
993 fotg210_writel(fotg210, fotg210->command, &fotg210->regs->command);
996 fotg210_readl(fotg210, &fotg210->regs->command);
1000 static void fotg210_clear_command_bit(struct fotg210_hcd *fotg210, u32 bit)
1002 fotg210->command &= ~bit;
1003 fotg210_writel(fotg210, fotg210->command, &fotg210->regs->command);
1006 fotg210_readl(fotg210, &fotg210->regs->command);
1011 * Lots of different events are triggered from fotg210->hrtimer. Whenever
1015 * fotg210->enabled_hrtimer_events, and they are numbered in order of
1020 * fotg210->next_hrtimer_event. Whenever fotg210->hrtimer gets restarted, its
1033 * the event types indexed by enum fotg210_hrtimer_event in fotg210.h.
1049 static void fotg210_enable_event(struct fotg210_hcd *fotg210, unsigned event,
1052 ktime_t *timeout = &fotg210->hr_timeouts[event];
1056 fotg210->enabled_hrtimer_events |= (1 << event);
1059 if (event < fotg210->next_hrtimer_event) {
1060 fotg210->next_hrtimer_event = event;
1061 hrtimer_start_range_ns(&fotg210->hrtimer, *timeout,
1068 static void fotg210_poll_ASS(struct fotg210_hcd *fotg210)
1073 if (fotg210->rh_state != FOTG210_RH_RUNNING)
1076 want = (fotg210->command & CMD_ASE) ? STS_ASS : 0;
1077 actual = fotg210_readl(fotg210, &fotg210->regs->status) & STS_ASS;
1082 if (fotg210->ASS_poll_count++ < 20) {
1083 fotg210_enable_event(fotg210, FOTG210_HRTIMER_POLL_ASS,
1087 fotg210_dbg(fotg210, "Waited too long for the async schedule status (%x/%x), giving up\n",
1090 fotg210->ASS_poll_count = 0;
1094 if (fotg210->async_count > 0)
1095 fotg210_set_command_bit(fotg210, CMD_ASE);
1098 if (fotg210->async_count == 0) {
1101 fotg210_enable_event(fotg210,
1109 static void fotg210_disable_ASE(struct fotg210_hcd *fotg210)
1111 fotg210_clear_command_bit(fotg210, CMD_ASE);
1116 static void fotg210_poll_PSS(struct fotg210_hcd *fotg210)
1121 if (fotg210->rh_state != FOTG210_RH_RUNNING)
1124 want = (fotg210->command & CMD_PSE) ? STS_PSS : 0;
1125 actual = fotg210_readl(fotg210, &fotg210->regs->status) & STS_PSS;
1130 if (fotg210->PSS_poll_count++ < 20) {
1131 fotg210_enable_event(fotg210, FOTG210_HRTIMER_POLL_PSS,
1135 fotg210_dbg(fotg210, "Waited too long for the periodic schedule status (%x/%x), giving up\n",
1138 fotg210->PSS_poll_count = 0;
1142 if (fotg210->periodic_count > 0)
1143 fotg210_set_command_bit(fotg210, CMD_PSE);
1146 if (fotg210->periodic_count == 0) {
1149 fotg210_enable_event(fotg210,
1157 static void fotg210_disable_PSE(struct fotg210_hcd *fotg210)
1159 fotg210_clear_command_bit(fotg210, CMD_PSE);
1164 static void fotg210_handle_controller_death(struct fotg210_hcd *fotg210)
1166 if (!(fotg210_readl(fotg210, &fotg210->regs->status) & STS_HALT)) {
1169 if (fotg210->died_poll_count++ < 5) {
1171 fotg210_enable_event(fotg210,
1175 fotg210_warn(fotg210, "Waited too long for the controller to stop, giving up\n");
1179 fotg210->rh_state = FOTG210_RH_HALTED;
1180 fotg210_writel(fotg210, 0, &fotg210->regs->intr_enable);
1181 fotg210_work(fotg210);
1182 end_unlink_async(fotg210);
1189 static void fotg210_handle_intr_unlinks(struct fotg210_hcd *fotg210)
1191 bool stopped = (fotg210->rh_state < FOTG210_RH_RUNNING);
1200 fotg210->intr_unlinking = true;
1201 while (fotg210->intr_unlink) {
1202 struct fotg210_qh *qh = fotg210->intr_unlink;
1204 if (!stopped && qh->unlink_cycle == fotg210->intr_unlink_cycle)
1206 fotg210->intr_unlink = qh->unlink_next;
1208 end_unlink_intr(fotg210, qh);
1212 if (fotg210->intr_unlink) {
1213 fotg210_enable_event(fotg210, FOTG210_HRTIMER_UNLINK_INTR,
1215 ++fotg210->intr_unlink_cycle;
1217 fotg210->intr_unlinking = false;
1222 static void start_free_itds(struct fotg210_hcd *fotg210)
1224 if (!(fotg210->enabled_hrtimer_events &
1226 fotg210->last_itd_to_free = list_entry(
1227 fotg210->cached_itd_list.prev,
1229 fotg210_enable_event(fotg210, FOTG210_HRTIMER_FREE_ITDS, true);
1234 static void end_free_itds(struct fotg210_hcd *fotg210)
1238 if (fotg210->rh_state < FOTG210_RH_RUNNING)
1239 fotg210->last_itd_to_free = NULL;
1241 list_for_each_entry_safe(itd, n, &fotg210->cached_itd_list, itd_list) {
1243 dma_pool_free(fotg210->itd_pool, itd, itd->itd_dma);
1244 if (itd == fotg210->last_itd_to_free)
1248 if (!list_empty(&fotg210->cached_itd_list))
1249 start_free_itds(fotg210);
1254 static void fotg210_iaa_watchdog(struct fotg210_hcd *fotg210)
1256 if (fotg210->rh_state != FOTG210_RH_RUNNING)
1265 if (fotg210->async_iaa) {
1274 cmd = fotg210_readl(fotg210, &fotg210->regs->command);
1283 status = fotg210_readl(fotg210, &fotg210->regs->status);
1285 INCR(fotg210->stats.lost_iaa);
1286 fotg210_writel(fotg210, STS_IAA,
1287 &fotg210->regs->status);
1290 fotg210_dbg(fotg210, "IAA watchdog: status %x cmd %x\n",
1292 end_unlink_async(fotg210);
1298 static void turn_on_io_watchdog(struct fotg210_hcd *fotg210)
1301 if (fotg210->rh_state != FOTG210_RH_RUNNING ||
1302 (fotg210->enabled_hrtimer_events &
1310 if (fotg210->isoc_count > 0 || (fotg210->need_io_watchdog &&
1311 fotg210->async_count + fotg210->intr_count > 0))
1312 fotg210_enable_event(fotg210, FOTG210_HRTIMER_IO_WATCHDOG,
1319 * enum fotg210_hrtimer_event in fotg210.h.
1336 struct fotg210_hcd *fotg210 =
1343 spin_lock_irqsave(&fotg210->lock, flags);
1345 events = fotg210->enabled_hrtimer_events;
1346 fotg210->enabled_hrtimer_events = 0;
1347 fotg210->next_hrtimer_event = FOTG210_HRTIMER_NO_EVENT;
1355 if (ktime_compare(now, fotg210->hr_timeouts[e]) >= 0)
1356 event_handlers[e](fotg210);
1358 fotg210_enable_event(fotg210, e, false);
1361 spin_unlock_irqrestore(&fotg210->lock, flags);
1368 static int check_reset_complete(struct fotg210_hcd *fotg210, int index,
1377 fotg210_dbg(fotg210, "Failed to enable port %d on root hub TT\n",
1380 fotg210_dbg(fotg210, "port %d reset complete, port enabled\n",
1391 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
1403 status = fotg210->resuming_ports;
1411 spin_lock_irqsave(&fotg210->lock, flags);
1413 temp = fotg210_readl(fotg210, &fotg210->regs->port_status);
1422 if ((temp & mask) != 0 || test_bit(0, &fotg210->port_c_suspend) ||
1423 (fotg210->reset_done[0] &&
1424 time_after_eq(jiffies, fotg210->reset_done[0]))) {
1429 spin_unlock_irqrestore(&fotg210->lock, flags);
1433 static void fotg210_hub_descriptor(struct fotg210_hcd *fotg210,
1436 int ports = HCS_N_PORTS(fotg210->hcs_params);
1440 desc->bPwrOn2PwrGood = 10; /* fotg210 1.0, 2.3.9 says 20ms max */
1459 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
1460 int ports = HCS_N_PORTS(fotg210->hcs_params);
1461 u32 __iomem *status_reg = &fotg210->regs->port_status;
1474 spin_lock_irqsave(&fotg210->lock, flags);
1490 temp = fotg210_readl(fotg210, status_reg);
1502 fotg210_writel(fotg210, temp & ~PORT_PE, status_reg);
1505 fotg210_writel(fotg210, temp | PORT_PEC, status_reg);
1516 fotg210_writel(fotg210, temp | PORT_RESUME, status_reg);
1517 fotg210->reset_done[wIndex] = jiffies
1521 clear_bit(wIndex, &fotg210->port_c_suspend);
1524 fotg210_writel(fotg210, temp | PORT_CSC, status_reg);
1527 fotg210_writel(fotg210, temp | OTGISR_OVC,
1528 &fotg210->regs->otgisr);
1536 fotg210_readl(fotg210, &fotg210->regs->command);
1539 fotg210_hub_descriptor(fotg210, (struct usb_hub_descriptor *)
1552 temp = fotg210_readl(fotg210, status_reg);
1560 temp1 = fotg210_readl(fotg210, &fotg210->regs->otgisr);
1568 if (!fotg210->reset_done[wIndex]) {
1570 fotg210->reset_done[wIndex] = jiffies
1573 mod_timer(&fotg210_to_hcd(fotg210)->rh_timer,
1574 fotg210->reset_done[wIndex]);
1579 fotg210->reset_done[wIndex])) {
1580 clear_bit(wIndex, &fotg210->suspended_ports);
1581 set_bit(wIndex, &fotg210->port_c_suspend);
1582 fotg210->reset_done[wIndex] = 0;
1585 temp = fotg210_readl(fotg210, status_reg);
1586 fotg210_writel(fotg210, temp &
1589 clear_bit(wIndex, &fotg210->resuming_ports);
1590 retval = handshake(fotg210, status_reg,
1593 fotg210_err(fotg210,
1604 fotg210->reset_done[wIndex])) {
1606 fotg210->reset_done[wIndex] = 0;
1607 clear_bit(wIndex, &fotg210->resuming_ports);
1610 fotg210_writel(fotg210,
1616 retval = handshake(fotg210, status_reg,
1619 fotg210_err(fotg210, "port %d reset error %d\n",
1625 temp = check_reset_complete(fotg210, wIndex, status_reg,
1626 fotg210_readl(fotg210, status_reg));
1629 fotg210->command |= CMD_RUN;
1630 fotg210_writel(fotg210, fotg210->command, &fotg210->regs->command);
1634 fotg210->reset_done[wIndex] = 0;
1635 clear_bit(wIndex, &fotg210->resuming_ports);
1640 test_bit(wIndex, &fotg210->companion_ports)) {
1642 fotg210_writel(fotg210, temp, status_reg);
1643 fotg210_dbg(fotg210, "port %d --> companion\n",
1645 temp = fotg210_readl(fotg210, status_reg);
1656 status |= fotg210_port_speed(fotg210, temp);
1664 } else if (test_bit(wIndex, &fotg210->suspended_ports)) {
1665 clear_bit(wIndex, &fotg210->suspended_ports);
1666 clear_bit(wIndex, &fotg210->resuming_ports);
1667 fotg210->reset_done[wIndex] = 0;
1669 set_bit(wIndex, &fotg210->port_c_suspend);
1672 temp1 = fotg210_readl(fotg210, &fotg210->regs->otgisr);
1677 if (test_bit(wIndex, &fotg210->port_c_suspend))
1681 dbg_port(fotg210, "GetStatus", wIndex + 1, temp);
1701 temp = fotg210_readl(fotg210, status_reg);
1713 fotg210_writel(fotg210, temp | PORT_SUSPEND,
1715 set_bit(wIndex, &fotg210->suspended_ports);
1724 fotg210_dbg(fotg210, "port %d reset\n", wIndex + 1);
1732 fotg210->reset_done[wIndex] = jiffies
1734 fotg210_writel(fotg210, temp, status_reg);
1746 spin_unlock_irqrestore(&fotg210->lock, flags);
1747 fotg210_quiesce(fotg210);
1748 spin_lock_irqsave(&fotg210->lock, flags);
1751 temp = fotg210_readl(fotg210, status_reg) &
1754 fotg210_writel(fotg210, temp | PORT_SUSPEND,
1757 spin_unlock_irqrestore(&fotg210->lock, flags);
1758 fotg210_halt(fotg210);
1759 spin_lock_irqsave(&fotg210->lock, flags);
1761 temp = fotg210_readl(fotg210, status_reg);
1763 fotg210_writel(fotg210, temp, status_reg);
1769 fotg210_readl(fotg210, &fotg210->regs->command);
1777 spin_unlock_irqrestore(&fotg210->lock, flags);
1804 static inline void fotg210_qtd_init(struct fotg210_hcd *fotg210,
1809 qtd->hw_token = cpu_to_hc32(fotg210, QTD_STS_HALT);
1810 qtd->hw_next = FOTG210_LIST_END(fotg210);
1811 qtd->hw_alt_next = FOTG210_LIST_END(fotg210);
1815 static struct fotg210_qtd *fotg210_qtd_alloc(struct fotg210_hcd *fotg210,
1821 qtd = dma_pool_alloc(fotg210->qtd_pool, flags, &dma);
1823 fotg210_qtd_init(fotg210, qtd, dma);
1828 static inline void fotg210_qtd_free(struct fotg210_hcd *fotg210,
1831 dma_pool_free(fotg210->qtd_pool, qtd, qtd->qtd_dma);
1835 static void qh_destroy(struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
1839 fotg210_dbg(fotg210, "unused qh not empty!\n");
1843 fotg210_qtd_free(fotg210, qh->dummy);
1844 dma_pool_free(fotg210->qh_pool, qh->hw, qh->qh_dma);
1848 static struct fotg210_qh *fotg210_qh_alloc(struct fotg210_hcd *fotg210,
1858 dma_pool_zalloc(fotg210->qh_pool, flags, &dma);
1865 qh->dummy = fotg210_qtd_alloc(fotg210, flags);
1867 fotg210_dbg(fotg210, "no dummy td\n");
1873 dma_pool_free(fotg210->qh_pool, qh->hw, qh->qh_dma);
1884 static void fotg210_mem_cleanup(struct fotg210_hcd *fotg210)
1886 if (fotg210->async)
1887 qh_destroy(fotg210, fotg210->async);
1888 fotg210->async = NULL;
1890 if (fotg210->dummy)
1891 qh_destroy(fotg210, fotg210->dummy);
1892 fotg210->dummy = NULL;
1895 dma_pool_destroy(fotg210->qtd_pool);
1896 fotg210->qtd_pool = NULL;
1898 dma_pool_destroy(fotg210->qh_pool);
1899 fotg210->qh_pool = NULL;
1901 dma_pool_destroy(fotg210->itd_pool);
1902 fotg210->itd_pool = NULL;
1904 if (fotg210->periodic)
1905 dma_free_coherent(fotg210_to_hcd(fotg210)->self.controller,
1906 fotg210->periodic_size * sizeof(u32),
1907 fotg210->periodic, fotg210->periodic_dma);
1908 fotg210->periodic = NULL;
1911 kfree(fotg210->pshadow);
1912 fotg210->pshadow = NULL;
1916 static int fotg210_mem_init(struct fotg210_hcd *fotg210, gfp_t flags)
1921 fotg210->qtd_pool = dma_pool_create("fotg210_qtd",
1922 fotg210_to_hcd(fotg210)->self.controller,
1926 if (!fotg210->qtd_pool)
1930 fotg210->qh_pool = dma_pool_create("fotg210_qh",
1931 fotg210_to_hcd(fotg210)->self.controller,
1935 if (!fotg210->qh_pool)
1938 fotg210->async = fotg210_qh_alloc(fotg210, flags);
1939 if (!fotg210->async)
1943 fotg210->itd_pool = dma_pool_create("fotg210_itd",
1944 fotg210_to_hcd(fotg210)->self.controller,
1948 if (!fotg210->itd_pool)
1952 fotg210->periodic =
1953 dma_alloc_coherent(fotg210_to_hcd(fotg210)->self.controller,
1954 fotg210->periodic_size * sizeof(__le32),
1955 &fotg210->periodic_dma, 0);
1956 if (fotg210->periodic == NULL)
1959 for (i = 0; i < fotg210->periodic_size; i++)
1960 fotg210->periodic[i] = FOTG210_LIST_END(fotg210);
1963 fotg210->pshadow = kcalloc(fotg210->periodic_size, sizeof(void *),
1965 if (fotg210->pshadow != NULL)
1969 fotg210_dbg(fotg210, "couldn't init memory\n");
1970 fotg210_mem_cleanup(fotg210);
1991 static int qtd_fill(struct fotg210_hcd *fotg210, struct fotg210_qtd *qtd,
1998 qtd->hw_buf[0] = cpu_to_hc32(fotg210, (u32)addr);
1999 qtd->hw_buf_hi[0] = cpu_to_hc32(fotg210, (u32)(addr >> 32));
2010 qtd->hw_buf[i] = cpu_to_hc32(fotg210, (u32)addr);
2011 qtd->hw_buf_hi[i] = cpu_to_hc32(fotg210,
2024 qtd->hw_token = cpu_to_hc32(fotg210, (count << 16) | token);
2030 static inline void qh_update(struct fotg210_hcd *fotg210,
2038 hw->hw_qtd_next = QTD_NEXT(fotg210, qtd->qtd_dma);
2039 hw->hw_alt_next = FOTG210_LIST_END(fotg210);
2046 if (!(hw->hw_info1 & cpu_to_hc32(fotg210, QH_TOGGLE_CTL))) {
2050 epnum = (hc32_to_cpup(fotg210, &hw->hw_info1) >> 8) & 0x0f;
2052 hw->hw_token &= ~cpu_to_hc32(fotg210, QTD_TOGGLE);
2057 hw->hw_token &= cpu_to_hc32(fotg210, QTD_TOGGLE | QTD_STS_PING);
2064 static void qh_refresh(struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
2080 if (cpu_to_hc32(fotg210, qtd->qtd_dma) == qh->hw->hw_current) {
2087 qh_update(fotg210, qh, qtd);
2090 static void qh_link_async(struct fotg210_hcd *fotg210, struct fotg210_qh *qh);
2095 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
2099 spin_lock_irqsave(&fotg210->lock, flags);
2102 && fotg210->rh_state == FOTG210_RH_RUNNING)
2103 qh_link_async(fotg210, qh);
2104 spin_unlock_irqrestore(&fotg210->lock, flags);
2107 static void fotg210_clear_tt_buffer(struct fotg210_hcd *fotg210,
2126 fotg210_to_hcd(fotg210)->self.root_hub) {
2133 static int qtd_copy_status(struct fotg210_hcd *fotg210, struct urb *urb,
2172 fotg210_dbg(fotg210, "devpath %s ep%d%s 3strikes\n",
2181 fotg210_dbg(fotg210,
2192 static void fotg210_urb_done(struct fotg210_hcd *fotg210, struct urb *urb,
2194 __releases(fotg210->lock)
2195 __acquires(fotg210->lock)
2201 if ((qh->hw->hw_info2 & cpu_to_hc32(fotg210, QH_SMASK)) != 0) {
2204 fotg210_to_hcd(fotg210)->self.bandwidth_int_reqs--;
2209 INCR(fotg210->stats.unlink);
2214 INCR(fotg210->stats.complete);
2218 fotg210_dbg(fotg210,
2228 usb_hcd_unlink_urb_from_ep(fotg210_to_hcd(fotg210), urb);
2229 spin_unlock(&fotg210->lock);
2230 usb_hcd_giveback_urb(fotg210_to_hcd(fotg210), urb, status);
2231 spin_lock(&fotg210->lock);
2234 static int qh_schedule(struct fotg210_hcd *fotg210, struct fotg210_qh *qh);
2240 static unsigned qh_completions(struct fotg210_hcd *fotg210,
2287 fotg210_urb_done(fotg210, last->urb,
2292 fotg210_qtd_free(fotg210, last);
2302 token = hc32_to_cpu(fotg210, qtd->hw_token);
2310 fotg210_dbg(fotg210,
2329 fotg210_dbg(fotg210,
2343 qtd->hw_token = cpu_to_hc32(fotg210,
2346 hw->hw_token = cpu_to_hc32(fotg210,
2363 FOTG210_LIST_END(fotg210))) {
2369 && fotg210->rh_state >= FOTG210_RH_RUNNING)) {
2377 if (fotg210->rh_state < FOTG210_RH_RUNNING)
2388 cpu_to_hc32(fotg210, qtd->qtd_dma)
2390 token = hc32_to_cpu(fotg210, hw->hw_token);
2396 fotg210_clear_tt_buffer(fotg210, qh, urb,
2409 last_status = qtd_copy_status(fotg210, urb,
2413 FOTG210_LIST_END(fotg210)))
2431 fotg210_clear_tt_buffer(fotg210, qh,
2455 fotg210_urb_done(fotg210, last->urb, last_status);
2457 fotg210_qtd_free(fotg210, last);
2482 if (stopped != 0 || hw->hw_qtd_next == FOTG210_LIST_END(fotg210)) {
2485 qh_refresh(fotg210, qh);
2513 static void qtd_list_free(struct fotg210_hcd *fotg210, struct urb *urb,
2520 fotg210_qtd_free(fotg210, qtd);
2526 static struct list_head *qh_urb_transaction(struct fotg210_hcd *fotg210,
2540 qtd = fotg210_qtd_alloc(fotg210, flags);
2554 qtd_fill(fotg210, qtd, urb->setup_dma,
2561 qtd = fotg210_qtd_alloc(fotg210, flags);
2565 qtd_prev->hw_next = QTD_NEXT(fotg210, qtd->qtd_dma);
2605 this_qtd_len = qtd_fill(fotg210, qtd, buf, this_sg_len, token,
2617 qtd->hw_alt_next = fotg210->async->hw->hw_alt_next;
2632 qtd = fotg210_qtd_alloc(fotg210, flags);
2636 qtd_prev->hw_next = QTD_NEXT(fotg210, qtd->qtd_dma);
2647 qtd->hw_alt_next = FOTG210_LIST_END(fotg210);
2668 qtd = fotg210_qtd_alloc(fotg210, flags);
2672 qtd_prev->hw_next = QTD_NEXT(fotg210, qtd->qtd_dma);
2676 qtd_fill(fotg210, qtd, 0, 0, token, 0);
2682 qtd->hw_token |= cpu_to_hc32(fotg210, QTD_IOC);
2686 qtd_list_free(fotg210, urb, head);
2705 static struct fotg210_qh *qh_make(struct fotg210_hcd *fotg210, struct urb *urb,
2708 struct fotg210_qh *qh = fotg210_qh_alloc(fotg210, flags);
2736 fotg210_dbg(fotg210, "bogus qh maxpacket %d\n", maxp);
2764 } else if (qh->period > fotg210->periodic_size) {
2765 qh->period = fotg210->periodic_size;
2789 if (qh->period > fotg210->periodic_size) {
2790 qh->period = fotg210->periodic_size;
2820 if (fotg210_has_fsl_portno_bug(fotg210))
2828 if (tt && tt->hub != fotg210_to_hcd(fotg210)->self.root_hub)
2858 fotg210_dbg(fotg210, "bogus dev %p speed %d\n", urb->dev,
2861 qh_destroy(fotg210, qh);
2870 hw->hw_info1 = cpu_to_hc32(fotg210, info1);
2871 hw->hw_info2 = cpu_to_hc32(fotg210, info2);
2874 qh_refresh(fotg210, qh);
2878 static void enable_async(struct fotg210_hcd *fotg210)
2880 if (fotg210->async_count++)
2884 fotg210->enabled_hrtimer_events &= ~BIT(FOTG210_HRTIMER_DISABLE_ASYNC);
2887 fotg210_poll_ASS(fotg210);
2888 turn_on_io_watchdog(fotg210);
2891 static void disable_async(struct fotg210_hcd *fotg210)
2893 if (--fotg210->async_count)
2897 WARN_ON(fotg210->async->qh_next.qh || fotg210->async_unlink);
2900 fotg210_poll_ASS(fotg210);
2905 static void qh_link_async(struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
2907 __hc32 dma = QH_NEXT(fotg210, qh->qh_dma);
2917 qh_refresh(fotg210, qh);
2920 head = fotg210->async;
2932 enable_async(fotg210);
2940 static struct fotg210_qh *qh_append_tds(struct fotg210_hcd *fotg210,
2945 __hc32 qh_addr_mask = cpu_to_hc32(fotg210, 0x7f);
2949 /* can't sleep here, we have fotg210->lock... */
2950 qh = qh_make(fotg210, urb, GFP_ATOMIC);
2983 qtd->hw_token = HALT_BIT(fotg210);
2995 fotg210_qtd_init(fotg210, qtd, qtd->qtd_dma);
3002 qtd->hw_next = QTD_NEXT(fotg210, dma);
3014 static int submit_async(struct fotg210_hcd *fotg210, struct urb *urb,
3029 fotg210_dbg(fotg210,
3039 spin_lock_irqsave(&fotg210->lock, flags);
3040 if (unlikely(!HCD_HW_ACCESSIBLE(fotg210_to_hcd(fotg210)))) {
3044 rc = usb_hcd_link_urb_to_ep(fotg210_to_hcd(fotg210), urb);
3048 qh = qh_append_tds(fotg210, urb, qtd_list, epnum, &urb->ep->hcpriv);
3050 usb_hcd_unlink_urb_from_ep(fotg210_to_hcd(fotg210), urb);
3059 qh_link_async(fotg210, qh);
3061 spin_unlock_irqrestore(&fotg210->lock, flags);
3063 qtd_list_free(fotg210, urb, qtd_list);
3067 static void single_unlink_async(struct fotg210_hcd *fotg210,
3074 if (fotg210->async_unlink)
3075 fotg210->async_unlink_last->unlink_next = qh;
3077 fotg210->async_unlink = qh;
3078 fotg210->async_unlink_last = qh;
3081 prev = fotg210->async;
3087 if (fotg210->qh_scan_next == qh)
3088 fotg210->qh_scan_next = qh->qh_next.qh;
3091 static void start_iaa_cycle(struct fotg210_hcd *fotg210, bool nested)
3097 if (fotg210->async_iaa || fotg210->async_unlinking)
3101 fotg210->async_iaa = fotg210->async_unlink;
3102 fotg210->async_unlink = NULL;
3105 if (unlikely(fotg210->rh_state < FOTG210_RH_RUNNING)) {
3107 end_unlink_async(fotg210);
3110 } else if (likely(fotg210->rh_state == FOTG210_RH_RUNNING)) {
3114 fotg210_writel(fotg210, fotg210->command | CMD_IAAD,
3115 &fotg210->regs->command);
3116 fotg210_readl(fotg210, &fotg210->regs->command);
3117 fotg210_enable_event(fotg210, FOTG210_HRTIMER_IAA_WATCHDOG,
3124 static void end_unlink_async(struct fotg210_hcd *fotg210)
3130 fotg210->async_unlinking = true;
3131 while (fotg210->async_iaa) {
3132 qh = fotg210->async_iaa;
3133 fotg210->async_iaa = qh->unlink_next;
3139 qh_completions(fotg210, qh);
3141 fotg210->rh_state == FOTG210_RH_RUNNING)
3142 qh_link_async(fotg210, qh);
3143 disable_async(fotg210);
3145 fotg210->async_unlinking = false;
3148 if (fotg210->async_unlink) {
3149 start_iaa_cycle(fotg210, true);
3150 if (unlikely(fotg210->rh_state < FOTG210_RH_RUNNING))
3155 static void unlink_empty_async(struct fotg210_hcd *fotg210)
3158 bool stopped = (fotg210->rh_state < FOTG210_RH_RUNNING);
3162 next = fotg210->async->qh_next.qh;
3170 fotg210->async_unlink_cycle)
3173 single_unlink_async(fotg210, qh);
3178 if (fotg210->async_unlink)
3179 start_iaa_cycle(fotg210, false);
3183 fotg210_enable_event(fotg210, FOTG210_HRTIMER_ASYNC_UNLINKS,
3185 ++fotg210->async_unlink_cycle;
3190 /* caller must own fotg210->lock */
3192 static void start_unlink_async(struct fotg210_hcd *fotg210,
3206 single_unlink_async(fotg210, qh);
3207 start_iaa_cycle(fotg210, false);
3210 static void scan_async(struct fotg210_hcd *fotg210)
3215 fotg210->qh_scan_next = fotg210->async->qh_next.qh;
3216 while (fotg210->qh_scan_next) {
3217 qh = fotg210->qh_scan_next;
3218 fotg210->qh_scan_next = qh->qh_next.qh;
3226 * drops the lock. That's why fotg210->qh_scan_next
3228 * gets unlinked then fotg210->qh_scan_next is adjusted
3231 temp = qh_completions(fotg210, qh);
3233 start_unlink_async(fotg210, qh);
3236 qh->unlink_cycle = fotg210->async_unlink_cycle;
3249 if (check_unlinks_later && fotg210->rh_state == FOTG210_RH_RUNNING &&
3250 !(fotg210->enabled_hrtimer_events &
3252 fotg210_enable_event(fotg210,
3254 ++fotg210->async_unlink_cycle;
3274 static union fotg210_shadow *periodic_next_shadow(struct fotg210_hcd *fotg210,
3277 switch (hc32_to_cpu(fotg210, tag)) {
3287 static __hc32 *shadow_next_periodic(struct fotg210_hcd *fotg210,
3290 switch (hc32_to_cpu(fotg210, tag)) {
3300 /* caller must hold fotg210->lock */
3301 static void periodic_unlink(struct fotg210_hcd *fotg210, unsigned frame,
3304 union fotg210_shadow *prev_p = &fotg210->pshadow[frame];
3305 __hc32 *hw_p = &fotg210->periodic[frame];
3310 prev_p = periodic_next_shadow(fotg210, prev_p,
3311 Q_NEXT_TYPE(fotg210, *hw_p));
3312 hw_p = shadow_next_periodic(fotg210, &here,
3313 Q_NEXT_TYPE(fotg210, *hw_p));
3323 *prev_p = *periodic_next_shadow(fotg210, &here,
3324 Q_NEXT_TYPE(fotg210, *hw_p));
3326 *hw_p = *shadow_next_periodic(fotg210, &here,
3327 Q_NEXT_TYPE(fotg210, *hw_p));
3331 static unsigned short periodic_usecs(struct fotg210_hcd *fotg210,
3334 __hc32 *hw_p = &fotg210->periodic[frame];
3335 union fotg210_shadow *q = &fotg210->pshadow[frame];
3340 switch (hc32_to_cpu(fotg210, Q_NEXT_TYPE(fotg210, *hw_p))) {
3344 if (hw->hw_info2 & cpu_to_hc32(fotg210, 1 << uframe))
3347 if (hw->hw_info2 & cpu_to_hc32(fotg210,
3358 if (q->fstn->hw_prev != FOTG210_LIST_END(fotg210))
3359 fotg210_dbg(fotg210, "ignoring FSTN cost ...\n");
3372 if (usecs > fotg210->uframe_periodic_max)
3373 fotg210_err(fotg210, "uframe %d sched overrun: %d usecs\n",
3394 static int tt_no_collision(struct fotg210_hcd *fotg210, unsigned period,
3404 for (; frame < fotg210->periodic_size; frame += period) {
3409 here = fotg210->pshadow[frame];
3410 type = Q_NEXT_TYPE(fotg210, fotg210->periodic[frame]);
3412 switch (hc32_to_cpu(fotg210, type)) {
3414 type = Q_NEXT_TYPE(fotg210, here.itd->hw_next);
3422 mask = hc32_to_cpu(fotg210,
3429 type = Q_NEXT_TYPE(fotg210, hw->hw_next);
3434 fotg210_dbg(fotg210,
3448 static void enable_periodic(struct fotg210_hcd *fotg210)
3450 if (fotg210->periodic_count++)
3454 fotg210->enabled_hrtimer_events &=
3458 fotg210_poll_PSS(fotg210);
3459 turn_on_io_watchdog(fotg210);
3462 static void disable_periodic(struct fotg210_hcd *fotg210)
3464 if (--fotg210->periodic_count)
3468 fotg210_poll_PSS(fotg210);
3475 * no FSTN support (yet; fotg210 0.96+)
3477 static void qh_link_periodic(struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
3484 hc32_to_cpup(fotg210, &qh->hw->hw_info2) &
3492 for (i = qh->start; i < fotg210->periodic_size; i += period) {
3493 union fotg210_shadow *prev = &fotg210->pshadow[i];
3494 __hc32 *hw_p = &fotg210->periodic[i];
3500 type = Q_NEXT_TYPE(fotg210, *hw_p);
3501 if (type == cpu_to_hc32(fotg210, Q_TYPE_QH))
3503 prev = periodic_next_shadow(fotg210, prev, type);
3504 hw_p = shadow_next_periodic(fotg210, &here, type);
3525 *hw_p = QH_NEXT(fotg210, qh->qh_dma);
3532 fotg210_to_hcd(fotg210)->self.bandwidth_allocated += qh->period
3536 list_add(&qh->intr_node, &fotg210->intr_qh_list);
3539 ++fotg210->intr_count;
3540 enable_periodic(fotg210);
3543 static void qh_unlink_periodic(struct fotg210_hcd *fotg210,
3569 for (i = qh->start; i < fotg210->periodic_size; i += period)
3570 periodic_unlink(fotg210, i, qh);
3573 fotg210_to_hcd(fotg210)->self.bandwidth_allocated -= qh->period
3579 qh->period, hc32_to_cpup(fotg210, &qh->hw->hw_info2) &
3587 if (fotg210->qh_scan_next == qh)
3588 fotg210->qh_scan_next = list_entry(qh->intr_node.next,
3593 static void start_unlink_intr(struct fotg210_hcd *fotg210,
3606 qh_unlink_periodic(fotg210, qh);
3616 qh->unlink_cycle = fotg210->intr_unlink_cycle;
3619 if (fotg210->intr_unlink)
3620 fotg210->intr_unlink_last->unlink_next = qh;
3622 fotg210->intr_unlink = qh;
3623 fotg210->intr_unlink_last = qh;
3625 if (fotg210->intr_unlinking)
3627 else if (fotg210->rh_state < FOTG210_RH_RUNNING)
3628 fotg210_handle_intr_unlinks(fotg210);
3629 else if (fotg210->intr_unlink == qh) {
3630 fotg210_enable_event(fotg210, FOTG210_HRTIMER_UNLINK_INTR,
3632 ++fotg210->intr_unlink_cycle;
3636 static void end_unlink_intr(struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
3642 hw->hw_next = FOTG210_LIST_END(fotg210);
3644 qh_completions(fotg210, qh);
3648 fotg210->rh_state == FOTG210_RH_RUNNING) {
3649 rc = qh_schedule(fotg210, qh);
3658 fotg210_err(fotg210, "can't reschedule qh %p, err %d\n",
3663 --fotg210->intr_count;
3664 disable_periodic(fotg210);
3667 static int check_period(struct fotg210_hcd *fotg210, unsigned frame,
3679 usecs = fotg210->uframe_periodic_max - usecs;
3687 claimed = periodic_usecs(fotg210, frame,
3692 } while ((frame += 1) < fotg210->periodic_size);
3697 claimed = periodic_usecs(fotg210, frame, uframe);
3700 } while ((frame += period) < fotg210->periodic_size);
3707 static int check_intr_schedule(struct fotg210_hcd *fotg210, unsigned frame,
3716 if (!check_period(fotg210, frame, uframe, qh->period, qh->usecs))
3732 *c_maskp = cpu_to_hc32(fotg210, mask << 8);
3735 if (tt_no_collision(fotg210, qh->period, qh->dev, frame, mask)) {
3736 if (!check_period(fotg210, frame, uframe + qh->gap_uf + 1,
3739 if (!check_period(fotg210, frame, uframe + qh->gap_uf,
3751 static int qh_schedule(struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
3759 qh_refresh(fotg210, qh);
3760 hw->hw_next = FOTG210_LIST_END(fotg210);
3765 uframe = ffs(hc32_to_cpup(fotg210, &hw->hw_info2) & QH_SMASK);
3766 status = check_intr_schedule(fotg210, frame, --uframe,
3783 frame = ++fotg210->random_frame % qh->period;
3785 status = check_intr_schedule(fotg210,
3796 status = check_intr_schedule(fotg210, 0, 0, qh,
3804 hw->hw_info2 &= cpu_to_hc32(fotg210, ~(QH_CMASK | QH_SMASK));
3806 ? cpu_to_hc32(fotg210, 1 << uframe)
3807 : cpu_to_hc32(fotg210, QH_SMASK);
3810 fotg210_dbg(fotg210, "reused qh %p schedule\n", qh);
3813 qh_link_periodic(fotg210, qh);
3818 static int intr_submit(struct fotg210_hcd *fotg210, struct urb *urb,
3830 spin_lock_irqsave(&fotg210->lock, flags);
3832 if (unlikely(!HCD_HW_ACCESSIBLE(fotg210_to_hcd(fotg210)))) {
3836 status = usb_hcd_link_urb_to_ep(fotg210_to_hcd(fotg210), urb);
3842 qh = qh_append_tds(fotg210, urb, &empty, epnum, &urb->ep->hcpriv);
3848 status = qh_schedule(fotg210, qh);
3854 qh = qh_append_tds(fotg210, urb, qtd_list, epnum, &urb->ep->hcpriv);
3858 fotg210_to_hcd(fotg210)->self.bandwidth_int_reqs++;
3862 usb_hcd_unlink_urb_from_ep(fotg210_to_hcd(fotg210), urb);
3864 spin_unlock_irqrestore(&fotg210->lock, flags);
3866 qtd_list_free(fotg210, urb, qtd_list);
3871 static void scan_intr(struct fotg210_hcd *fotg210)
3875 list_for_each_entry_safe(qh, fotg210->qh_scan_next,
3876 &fotg210->intr_qh_list, intr_node) {
3884 * drops the lock. That's why fotg210->qh_scan_next
3886 * gets unlinked then fotg210->qh_scan_next is adjusted
3889 temp = qh_completions(fotg210, qh);
3893 start_unlink_intr(fotg210, qh);
3915 static void iso_stream_init(struct fotg210_hcd *fotg210,
3943 stream->buf0 = cpu_to_hc32(fotg210, (epnum << 8) | dev->devnum);
3944 stream->buf1 = cpu_to_hc32(fotg210, buf1);
3945 stream->buf2 = cpu_to_hc32(fotg210, multi);
3969 static struct fotg210_iso_stream *iso_stream_find(struct fotg210_hcd *fotg210,
3983 spin_lock_irqsave(&fotg210->lock, flags);
3991 iso_stream_init(fotg210, stream, urb->dev, urb->pipe,
3997 fotg210_dbg(fotg210, "dev %s ep%d%s, not iso??\n",
4003 spin_unlock_irqrestore(&fotg210->lock, flags);
4021 static inline void itd_sched_init(struct fotg210_hcd *fotg210,
4049 uframe->transaction = cpu_to_hc32(fotg210, trans);
4064 /* caller must hold fotg210->lock!*/
4070 struct fotg210_hcd *fotg210, struct urb *urb, gfp_t mem_flags)
4083 itd_sched_init(fotg210, sched, stream, urb);
4091 spin_lock_irqsave(&fotg210->lock, flags);
4101 if (itd->frame == fotg210->now_frame)
4107 spin_unlock_irqrestore(&fotg210->lock, flags);
4108 itd = dma_pool_alloc(fotg210->itd_pool, mem_flags,
4110 spin_lock_irqsave(&fotg210->lock, flags);
4113 spin_unlock_irqrestore(&fotg210->lock, flags);
4122 spin_unlock_irqrestore(&fotg210->lock, flags);
4130 static inline int itd_slot_ok(struct fotg210_hcd *fotg210, u32 mod, u32 uframe,
4136 if (periodic_usecs(fotg210, uframe >> 3, uframe & 0x7)
4137 > (fotg210->uframe_periodic_max - usecs))
4150 * Also avoid queue depths of less than fotg210's worst irq latency (affected
4158 static int iso_stream_schedule(struct fotg210_hcd *fotg210, struct urb *urb,
4163 unsigned mod = fotg210->periodic_size << 3;
4170 fotg210_dbg(fotg210, "iso request %p too long\n", urb);
4175 now = fotg210_read_frame_index(fotg210) & (mod - 1);
4190 if (!stream->highspeed && fotg210->fs_i_thresh)
4191 next = now + fotg210->i_thresh;
4206 fotg210_dbg(fotg210, "request %p would overflow (%d+%d >= %d)\n",
4215 * this is bigger than fotg210->i_thresh allows; scheduling itself
4237 if (itd_slot_ok(fotg210, mod, start,
4244 fotg210_dbg(fotg210, "iso resched full %p (now %d max %d)\n",
4254 fotg210_dbg(fotg210, "request %p would overflow (%d+%d >= %d)\n",
4269 if (fotg210->isoc_count == 0)
4270 fotg210->next_frame = now >> 3;
4279 static inline void itd_init(struct fotg210_hcd *fotg210,
4285 itd->hw_next = FOTG210_LIST_END(fotg210);
4296 static inline void itd_patch(struct fotg210_hcd *fotg210,
4307 itd->hw_transaction[uframe] |= cpu_to_hc32(fotg210, pg << 12);
4308 itd->hw_bufp[pg] |= cpu_to_hc32(fotg210, uf->bufp & ~(u32)0);
4309 itd->hw_bufp_hi[pg] |= cpu_to_hc32(fotg210, (u32)(uf->bufp >> 32));
4316 itd->hw_bufp[pg] |= cpu_to_hc32(fotg210, bufp & ~(u32)0);
4317 itd->hw_bufp_hi[pg] |= cpu_to_hc32(fotg210, (u32)(bufp >> 32));
4321 static inline void itd_link(struct fotg210_hcd *fotg210, unsigned frame,
4324 union fotg210_shadow *prev = &fotg210->pshadow[frame];
4325 __hc32 *hw_p = &fotg210->periodic[frame];
4331 type = Q_NEXT_TYPE(fotg210, *hw_p);
4332 if (type == cpu_to_hc32(fotg210, Q_TYPE_QH))
4334 prev = periodic_next_shadow(fotg210, prev, type);
4335 hw_p = shadow_next_periodic(fotg210, &here, type);
4344 *hw_p = cpu_to_hc32(fotg210, itd->itd_dma | Q_TYPE_ITD);
4348 static void itd_link_urb(struct fotg210_hcd *fotg210, struct urb *urb,
4359 fotg210_to_hcd(fotg210)->self.bandwidth_allocated
4361 fotg210_dbg(fotg210,
4381 itd_init(fotg210, stream, itd);
4387 itd_patch(fotg210, itd, iso_sched, packet, uframe);
4396 itd_link(fotg210, frame & (fotg210->periodic_size - 1),
4407 ++fotg210->isoc_count;
4408 enable_periodic(fotg210);
4424 static bool itd_complete(struct fotg210_hcd *fotg210, struct fotg210_itd *itd)
4442 t = hc32_to_cpup(fotg210, &itd->hw_transaction[uframe]);
4483 fotg210_urb_done(fotg210, urb, 0);
4487 --fotg210->isoc_count;
4488 disable_periodic(fotg210);
4491 fotg210_to_hcd(fotg210)->self.bandwidth_allocated
4493 fotg210_dbg(fotg210,
4508 &fotg210->cached_itd_list);
4509 start_free_itds(fotg210);
4515 static int itd_submit(struct fotg210_hcd *fotg210, struct urb *urb,
4523 stream = iso_stream_find(fotg210, urb);
4525 fotg210_dbg(fotg210, "can't get iso stream\n");
4529 fotg210_port_speed(fotg210, 0) ==
4531 fotg210_dbg(fotg210, "can't change iso interval %d --> %d\n",
4537 fotg210_dbg(fotg210,
4548 status = itd_urb_transaction(stream, fotg210, urb, mem_flags);
4550 fotg210_dbg(fotg210, "can't init itds\n");
4555 spin_lock_irqsave(&fotg210->lock, flags);
4556 if (unlikely(!HCD_HW_ACCESSIBLE(fotg210_to_hcd(fotg210)))) {
4560 status = usb_hcd_link_urb_to_ep(fotg210_to_hcd(fotg210), urb);
4563 status = iso_stream_schedule(fotg210, urb, stream);
4565 itd_link_urb(fotg210, urb, fotg210->periodic_size << 3, stream);
4567 usb_hcd_unlink_urb_from_ep(fotg210_to_hcd(fotg210), urb);
4569 spin_unlock_irqrestore(&fotg210->lock, flags);
4574 static inline int scan_frame_queue(struct fotg210_hcd *fotg210, unsigned frame,
4583 q_p = &fotg210->pshadow[frame];
4584 hw_p = &fotg210->periodic[frame];
4586 type = Q_NEXT_TYPE(fotg210, *hw_p);
4590 switch (hc32_to_cpu(fotg210, type)) {
4601 ITD_ACTIVE(fotg210))
4607 type = Q_NEXT_TYPE(fotg210,
4621 type = Q_NEXT_TYPE(fotg210, q.itd->hw_next);
4623 modified = itd_complete(fotg210, q.itd);
4627 fotg210_dbg(fotg210, "corrupt type %d frame %d shadow %p\n",
4638 if (unlikely(modified && fotg210->isoc_count > 0))
4644 static void scan_isoc(struct fotg210_hcd *fotg210)
4647 unsigned fmask = fotg210->periodic_size - 1;
4655 if (fotg210->rh_state >= FOTG210_RH_RUNNING) {
4656 uf = fotg210_read_frame_index(fotg210);
4660 now_frame = (fotg210->next_frame - 1) & fmask;
4663 fotg210->now_frame = now_frame;
4665 frame = fotg210->next_frame;
4669 ret = scan_frame_queue(fotg210, frame,
4677 fotg210->next_frame = now_frame;
4685 struct fotg210_hcd *fotg210;
4687 fotg210 = hcd_to_fotg210(bus_to_hcd(dev_get_drvdata(dev)));
4688 return sysfs_emit(buf, "%d\n", fotg210->uframe_periodic_max);
4694 struct fotg210_hcd *fotg210;
4701 fotg210 = hcd_to_fotg210(bus_to_hcd(dev_get_drvdata(dev)));
4708 fotg210_info(fotg210, "rejecting invalid request for uframe_periodic_max=%u\n",
4719 spin_lock_irqsave(&fotg210->lock, flags);
4726 if (uframe_periodic_max < fotg210->uframe_periodic_max) {
4729 for (frame = 0; frame < fotg210->periodic_size; ++frame)
4732 periodic_usecs(fotg210, frame,
4736 fotg210_info(fotg210,
4745 fotg210_info(fotg210,
4750 fotg210_warn(fotg210, "max periodic bandwidth set is non-standard\n");
4752 fotg210->uframe_periodic_max = uframe_periodic_max;
4756 spin_unlock_irqrestore(&fotg210->lock, flags);
4762 static inline int create_sysfs_files(struct fotg210_hcd *fotg210)
4764 struct device *controller = fotg210_to_hcd(fotg210)->self.controller;
4769 static inline void remove_sysfs_files(struct fotg210_hcd *fotg210)
4771 struct device *controller = fotg210_to_hcd(fotg210)->self.controller;
4779 static void fotg210_turn_off_all_ports(struct fotg210_hcd *fotg210)
4781 u32 __iomem *status_reg = &fotg210->regs->port_status;
4783 fotg210_writel(fotg210, PORT_RWC_BITS, status_reg);
4789 static void fotg210_silence_controller(struct fotg210_hcd *fotg210)
4791 fotg210_halt(fotg210);
4793 spin_lock_irq(&fotg210->lock);
4794 fotg210->rh_state = FOTG210_RH_HALTED;
4795 fotg210_turn_off_all_ports(fotg210);
4796 spin_unlock_irq(&fotg210->lock);
4805 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
4807 spin_lock_irq(&fotg210->lock);
4808 fotg210->shutdown = true;
4809 fotg210->rh_state = FOTG210_RH_STOPPING;
4810 fotg210->enabled_hrtimer_events = 0;
4811 spin_unlock_irq(&fotg210->lock);
4813 fotg210_silence_controller(fotg210);
4815 hrtimer_cancel(&fotg210->hrtimer);
4819 * it calls driver completion functions, after dropping fotg210->lock.
4821 static void fotg210_work(struct fotg210_hcd *fotg210)
4823 /* another CPU may drop fotg210->lock during a schedule scan while
4827 if (fotg210->scanning) {
4828 fotg210->need_rescan = true;
4831 fotg210->scanning = true;
4834 fotg210->need_rescan = false;
4835 if (fotg210->async_count)
4836 scan_async(fotg210);
4837 if (fotg210->intr_count > 0)
4838 scan_intr(fotg210);
4839 if (fotg210->isoc_count > 0)
4840 scan_isoc(fotg210);
4841 if (fotg210->need_rescan)
4843 fotg210->scanning = false;
4849 turn_on_io_watchdog(fotg210);
4856 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
4858 fotg210_dbg(fotg210, "stop\n");
4862 spin_lock_irq(&fotg210->lock);
4863 fotg210->enabled_hrtimer_events = 0;
4864 spin_unlock_irq(&fotg210->lock);
4866 fotg210_quiesce(fotg210);
4867 fotg210_silence_controller(fotg210);
4868 fotg210_reset(fotg210);
4870 hrtimer_cancel(&fotg210->hrtimer);
4871 remove_sysfs_files(fotg210);
4872 remove_debug_files(fotg210);
4875 spin_lock_irq(&fotg210->lock);
4876 end_free_itds(fotg210);
4877 spin_unlock_irq(&fotg210->lock);
4878 fotg210_mem_cleanup(fotg210);
4881 fotg210_dbg(fotg210, "irq normal %ld err %ld iaa %ld (lost %ld)\n",
4882 fotg210->stats.normal, fotg210->stats.error,
4883 fotg210->stats.iaa, fotg210->stats.lost_iaa);
4884 fotg210_dbg(fotg210, "complete %ld unlink %ld\n",
4885 fotg210->stats.complete, fotg210->stats.unlink);
4888 dbg_status(fotg210, "fotg210_stop completed",
4889 fotg210_readl(fotg210, &fotg210->regs->status));
4895 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
4901 spin_lock_init(&fotg210->lock);
4906 fotg210->need_io_watchdog = 1;
4908 hrtimer_init(&fotg210->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
4909 fotg210->hrtimer.function = fotg210_hrtimer_func;
4910 fotg210->next_hrtimer_event = FOTG210_HRTIMER_NO_EVENT;
4912 hcc_params = fotg210_readl(fotg210, &fotg210->caps->hcc_params);
4918 fotg210->uframe_periodic_max = 100;
4924 fotg210->periodic_size = DEFAULT_I_TDPS;
4925 INIT_LIST_HEAD(&fotg210->intr_qh_list);
4926 INIT_LIST_HEAD(&fotg210->cached_itd_list);
4932 fotg210->periodic_size = 1024;
4935 fotg210->periodic_size = 512;
4938 fotg210->periodic_size = 256;
4944 retval = fotg210_mem_init(fotg210, GFP_KERNEL);
4949 fotg210->i_thresh = 2;
4958 fotg210->async->qh_next.qh = NULL;
4959 hw = fotg210->async->hw;
4960 hw->hw_next = QH_NEXT(fotg210, fotg210->async->qh_dma);
4961 hw->hw_info1 = cpu_to_hc32(fotg210, QH_HEAD);
4962 hw->hw_token = cpu_to_hc32(fotg210, QTD_STS_HALT);
4963 hw->hw_qtd_next = FOTG210_LIST_END(fotg210);
4964 fotg210->async->qh_state = QH_STATE_LINKED;
4965 hw->hw_alt_next = QTD_NEXT(fotg210, fotg210->async->dummy->qtd_dma);
4984 fotg210_dbg(fotg210, "park %d\n", park);
4991 fotg210->command = temp;
5002 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
5009 fotg210_writel(fotg210, fotg210->periodic_dma,
5010 &fotg210->regs->frame_list);
5011 fotg210_writel(fotg210, (u32)fotg210->async->qh_dma,
5012 &fotg210->regs->async_next);
5015 * hcc_params controls whether fotg210->regs->segment must (!!!)
5026 fotg210_readl(fotg210, &fotg210->caps->hcc_params);
5032 fotg210->command &= ~(CMD_IAAD|CMD_PSE|CMD_ASE|CMD_RESET);
5033 fotg210->command |= CMD_RUN;
5034 fotg210_writel(fotg210, fotg210->command, &fotg210->regs->command);
5035 dbg_cmd(fotg210, "init", fotg210->command);
5052 fotg210->rh_state = FOTG210_RH_RUNNING;
5054 fotg210_readl(fotg210, &fotg210->regs->command);
5057 fotg210->last_periodic_enable = ktime_get_real();
5059 temp = HC_VERSION(fotg210,
5060 fotg210_readl(fotg210, &fotg210->caps->hc_capbase));
5061 fotg210_info(fotg210,
5063 ((fotg210->sbrn & 0xf0) >> 4), (fotg210->sbrn & 0x0f),
5066 fotg210_writel(fotg210, INTR_MASK,
5067 &fotg210->regs->intr_enable); /* Turn On Interrupts */
5073 create_debug_files(fotg210);
5074 create_sysfs_files(fotg210);
5081 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
5084 fotg210->regs = (void __iomem *)fotg210->caps +
5085 HC_LENGTH(fotg210,
5086 fotg210_readl(fotg210, &fotg210->caps->hc_capbase));
5087 dbg_hcs_params(fotg210, "reset");
5088 dbg_hcc_params(fotg210, "reset");
5091 fotg210->hcs_params = fotg210_readl(fotg210,
5092 &fotg210->caps->hcs_params);
5094 fotg210->sbrn = HCD_USB2;
5101 retval = fotg210_halt(fotg210);
5105 fotg210_reset(fotg210);
5112 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
5116 spin_lock(&fotg210->lock);
5118 status = fotg210_readl(fotg210, &fotg210->regs->status);
5122 fotg210_dbg(fotg210, "device removed\n");
5134 unlikely(fotg210->rh_state == FOTG210_RH_HALTED)) {
5135 spin_unlock(&fotg210->lock);
5140 fotg210_writel(fotg210, masked_status, &fotg210->regs->status);
5141 cmd = fotg210_readl(fotg210, &fotg210->regs->command);
5145 dbg_status(fotg210, "irq", status);
5152 INCR(fotg210->stats.normal);
5154 INCR(fotg210->stats.error);
5162 fotg210->enabled_hrtimer_events &=
5172 if (fotg210->next_hrtimer_event == FOTG210_HRTIMER_IAA_WATCHDOG)
5173 ++fotg210->next_hrtimer_event;
5177 fotg210_dbg(fotg210, "IAA with IAAD still set?\n");
5178 if (fotg210->async_iaa) {
5179 INCR(fotg210->stats.iaa);
5180 end_unlink_async(fotg210);
5182 fotg210_dbg(fotg210, "IAA with nothing unlinked?\n");
5188 u32 __iomem *status_reg = &fotg210->regs->port_status;
5194 if (fotg210->rh_state == FOTG210_RH_SUSPENDED)
5197 pstatus = fotg210_readl(fotg210, status_reg);
5199 if (test_bit(0, &fotg210->suspended_ports) &&
5203 fotg210->reset_done[0] == 0) {
5210 fotg210->reset_done[0] = jiffies + msecs_to_jiffies(25);
5211 set_bit(0, &fotg210->resuming_ports);
5212 fotg210_dbg(fotg210, "port 1 remote wakeup\n");
5213 mod_timer(&hcd->rh_timer, fotg210->reset_done[0]);
5219 fotg210_err(fotg210, "fatal error\n");
5220 dbg_cmd(fotg210, "fatal", cmd);
5221 dbg_status(fotg210, "fatal", status);
5226 fotg210->shutdown = true;
5227 fotg210->rh_state = FOTG210_RH_STOPPING;
5228 fotg210->command &= ~(CMD_RUN | CMD_ASE | CMD_PSE);
5229 fotg210_writel(fotg210, fotg210->command,
5230 &fotg210->regs->command);
5231 fotg210_writel(fotg210, 0, &fotg210->regs->intr_enable);
5232 fotg210_handle_controller_death(fotg210);
5239 fotg210_work(fotg210);
5240 spin_unlock(&fotg210->lock);
5260 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
5275 if (!qh_urb_transaction(fotg210, urb, &qtd_list, mem_flags))
5277 return submit_async(fotg210, urb, &qtd_list, mem_flags);
5280 if (!qh_urb_transaction(fotg210, urb, &qtd_list, mem_flags))
5282 return intr_submit(fotg210, urb, &qtd_list, mem_flags);
5285 return itd_submit(fotg210, urb, mem_flags);
5295 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
5300 spin_lock_irqsave(&fotg210->lock, flags);
5315 start_unlink_async(fotg210, qh);
5323 qh_completions(fotg210, qh);
5335 start_unlink_intr(fotg210, qh);
5338 qh_completions(fotg210, qh);
5341 fotg210_dbg(fotg210, "bogus qh %p state %d\n",
5355 spin_unlock_irqrestore(&fotg210->lock, flags);
5364 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
5372 spin_lock_irqsave(&fotg210->lock, flags);
5391 if (fotg210->rh_state < FOTG210_RH_RUNNING)
5396 for (tmp = fotg210->async->qh_next.qh;
5404 start_unlink_async(fotg210, qh);
5409 spin_unlock_irqrestore(&fotg210->lock, flags);
5416 qh_destroy(fotg210, qh);
5424 fotg210_err(fotg210, "qh %p (#%02x) state %d%s\n",
5431 spin_unlock_irqrestore(&fotg210->lock, flags);
5437 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
5447 spin_lock_irqsave(&fotg210->lock, flags);
5467 start_unlink_async(fotg210, qh);
5469 start_unlink_intr(fotg210, qh);
5472 spin_unlock_irqrestore(&fotg210->lock, flags);
5477 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
5479 return (fotg210_read_frame_index(fotg210) >> 3) %
5480 fotg210->periodic_size;
5486 * give the fotg210 driver exclusive access to those.
5535 static void fotg210_init(struct fotg210_hcd *fotg210)
5540 &fotg210->regs->gmir);
5542 value = ioread32(&fotg210->regs->otgcsr);
5545 iowrite32(value, &fotg210->regs->otgcsr);
5555 int fotg210_hcd_probe(struct platform_device *pdev, struct fotg210 *fotg)
5561 struct fotg210_hcd *fotg210;
5586 fotg210 = hcd_to_fotg210(hcd);
5588 fotg210->fotg = fotg;
5589 fotg210->caps = hcd->regs;
5595 fotg210_init(fotg210);
5643 fotg210_debug_root = debugfs_create_dir("fotg210", usb_debug_root);