Lines Matching +full:overrun +full:- +full:throttle +full:- +full:ms
1 // SPDX-License-Identifier: GPL-2.0+
6 * This code is *strongly* based on EHCI-HCD code by David Brownell since
7 * the chip is a quasi-EHCI compatible.
25 #include <linux/dma-mapping.h>
82 #define EHCI_TUNE_CERR 3 /* 0-3 qtd retries; 0 == don't stop */
83 #define EHCI_TUNE_RL_HS 4 /* nak throttle; see 4.9 */
85 #define EHCI_TUNE_MULT_HS 1 /* 1-3 transactions/uframe; 4.10.3 */
101 u32 hcs_params; /* HCSPARAMS - offset 0x4 */
110 u32 hcc_params; /* HCCPARAMS - offset 0x8 */
116 #define HCC_64BIT_ADDR(p) ((p)&(1)) /* true: can use 64-bit addr */
117 u8 portroute[8]; /* nibbles for routing - offset 0xC */
204 * See Fig 3-6 "Queue Element Transfer Descriptor Block Diagram".
230 /* the rest is HCD-private */
243 /* mask NakCnt+T in qh->hw_alt_next */
248 /* Type tag from {qh, itd, sitd, fstn}->hw_next */
277 * See Fig 3-7 "Queue Head Structure Layout".
293 __le32 hw_current; /* qtd list - see EHCI 3.6.4 */
302 /* the rest is HCD-private */
344 /* 2 host controllers are enabled - total size <= 28 kbytes */
458 dev_dbg(oxu_to_hcd(oxu)->self.controller , fmt , ## args)
460 dev_err(oxu_to_hcd(oxu)->self.controller , fmt , ## args)
462 dev_info(oxu_to_hcd(oxu)->self.controller , fmt , ## args)
475 return (struct oxu_hcd *) (hcd->hcd_priv); in hcd_to_oxu()
632 MODULE_PARM_DESC(log2_irq_thresh, "log2 IRQ latency, 1-64 microframes");
637 MODULE_PARM_DESC(park, "park setting; 1-3 back-to-back async packets");
668 clear_bit(action, &oxu->actions); in timer_action_done()
674 if (!test_and_set_bit(action, &oxu->actions)) { in timer_action()
699 && t > oxu->watchdog.expires in timer_action()
700 && timer_pending(&oxu->watchdog)) in timer_action()
702 mod_timer(&oxu->watchdog, t); in timer_action()
707 * handshake - spin reading hc until handshake completes or fails
717 * hardware flakeout), or the register reads as all-ones (hardware removed).
734 return -ENODEV; in handshake()
742 u32 temp = readl(&oxu->regs->status); in ehci_halt()
745 writel(0, &oxu->regs->intr_enable); in ehci_halt()
750 temp = readl(&oxu->regs->command); in ehci_halt()
752 writel(temp, &oxu->regs->command); in ehci_halt()
753 return handshake(oxu, &oxu->regs->status, in ehci_halt()
763 reg_ptr = (u32 __iomem *)(((u8 __iomem *)oxu->regs) + 0x68); in tdi_reset()
769 /* Reset a non-running (STS_HALT == 1) controller */
773 u32 command = readl(&oxu->regs->command); in ehci_reset()
777 writel(command, &oxu->regs->command); in ehci_reset()
778 oxu_to_hcd(oxu)->state = HC_STATE_HALT; in ehci_reset()
779 oxu->next_statechange = jiffies; in ehci_reset()
780 retval = handshake(oxu, &oxu->regs->command, in ehci_reset()
797 BUG_ON(!HC_IS_RUNNING(oxu_to_hcd(oxu)->state)); in ehci_quiesce()
801 temp = readl(&oxu->regs->command) << 10; in ehci_quiesce()
803 if (handshake(oxu, &oxu->regs->status, STS_ASS | STS_PSS, in ehci_quiesce()
805 oxu_to_hcd(oxu)->state = HC_STATE_HALT; in ehci_quiesce()
810 temp = readl(&oxu->regs->command); in ehci_quiesce()
812 writel(temp, &oxu->regs->command); in ehci_quiesce()
815 if (handshake(oxu, &oxu->regs->status, STS_ASS | STS_PSS, in ehci_quiesce()
817 oxu_to_hcd(oxu)->state = HC_STATE_HALT; in ehci_quiesce()
826 oxu->reset_done[index] = 0; in check_reset_complete()
830 /* if reset finished and it's still not enabled -- handoff */ in check_reset_complete()
844 int ports = HCS_N_PORTS(oxu->hcs_params); in ehci_hub_descriptor()
847 desc->bDescriptorType = USB_DT_HUB; in ehci_hub_descriptor()
848 desc->bPwrOn2PwrGood = 10; /* oxu 1.0, 2.3.9 says 20ms max */ in ehci_hub_descriptor()
849 desc->bHubContrCurrent = 0; in ehci_hub_descriptor()
851 desc->bNbrPorts = ports; in ehci_hub_descriptor()
853 desc->bDescLength = 7 + 2 * temp; in ehci_hub_descriptor()
856 memset(&desc->u.hs.DeviceRemovable[0], 0, temp); in ehci_hub_descriptor()
857 memset(&desc->u.hs.DeviceRemovable[temp], 0xff, temp); in ehci_hub_descriptor()
859 temp = HUB_CHAR_INDV_PORT_OCPM; /* per-port overcurrent reporting */ in ehci_hub_descriptor()
860 if (HCS_PPC(oxu->hcs_params)) in ehci_hub_descriptor()
861 temp |= HUB_CHAR_INDV_PORT_LPSM; /* per-port power control */ in ehci_hub_descriptor()
864 desc->wHubCharacteristics = (__force __u16)cpu_to_le16(temp); in ehci_hub_descriptor()
868 /* Allocate an OXU210HP on-chip memory data buffer
870 * An on-chip memory data buffer is required for each OXU210HP USB transfer.
871 * Each transfer descriptor has one or more on-chip memory data buffers.
879 * len=0. This is a waste of on-chip memory and should be fix. Then this
891 return -ENOMEM; in oxu_buf_alloc()
894 spin_lock(&oxu->mem_lock); in oxu_buf_alloc()
897 n_blocks = (len + BUFFER_SIZE - 1) / BUFFER_SIZE; in oxu_buf_alloc()
905 i += max(a_blocks, (int)oxu->db_used[i])) { in oxu_buf_alloc()
909 if (oxu->db_used[i + j]) in oxu_buf_alloc()
916 qtd->buffer = (void *) &oxu->mem->db_pool[i]; in oxu_buf_alloc()
917 qtd->buffer_dma = virt_to_phys(qtd->buffer); in oxu_buf_alloc()
919 qtd->qtd_buffer_len = BUFFER_SIZE * a_blocks; in oxu_buf_alloc()
920 oxu->db_used[i] = a_blocks; in oxu_buf_alloc()
922 spin_unlock(&oxu->mem_lock); in oxu_buf_alloc()
929 spin_unlock(&oxu->mem_lock); in oxu_buf_alloc()
931 return -ENOMEM; in oxu_buf_alloc()
938 spin_lock(&oxu->mem_lock); in oxu_buf_free()
940 index = (qtd->buffer - (void *) &oxu->mem->db_pool[0]) in oxu_buf_free()
942 oxu->db_used[index] = 0; in oxu_buf_free()
943 qtd->qtd_buffer_len = 0; in oxu_buf_free()
944 qtd->buffer_dma = 0; in oxu_buf_free()
945 qtd->buffer = NULL; in oxu_buf_free()
947 spin_unlock(&oxu->mem_lock); in oxu_buf_free()
953 qtd->qtd_dma = dma; in ehci_qtd_init()
954 qtd->hw_token = cpu_to_le32(QTD_STS_HALT); in ehci_qtd_init()
955 qtd->hw_next = EHCI_LIST_END; in ehci_qtd_init()
956 qtd->hw_alt_next = EHCI_LIST_END; in ehci_qtd_init()
957 INIT_LIST_HEAD(&qtd->qtd_list); in ehci_qtd_init()
964 if (qtd->buffer) in oxu_qtd_free()
967 spin_lock(&oxu->mem_lock); in oxu_qtd_free()
969 index = qtd - &oxu->mem->qtd_pool[0]; in oxu_qtd_free()
970 oxu->qtd_used[index] = 0; in oxu_qtd_free()
972 spin_unlock(&oxu->mem_lock); in oxu_qtd_free()
980 spin_lock(&oxu->mem_lock); in ehci_qtd_alloc()
983 if (!oxu->qtd_used[i]) in ehci_qtd_alloc()
987 qtd = (struct ehci_qtd *) &oxu->mem->qtd_pool[i]; in ehci_qtd_alloc()
990 qtd->hw_token = cpu_to_le32(QTD_STS_HALT); in ehci_qtd_alloc()
991 qtd->hw_next = EHCI_LIST_END; in ehci_qtd_alloc()
992 qtd->hw_alt_next = EHCI_LIST_END; in ehci_qtd_alloc()
993 INIT_LIST_HEAD(&qtd->qtd_list); in ehci_qtd_alloc()
995 qtd->qtd_dma = virt_to_phys(qtd); in ehci_qtd_alloc()
997 oxu->qtd_used[i] = 1; in ehci_qtd_alloc()
1000 spin_unlock(&oxu->mem_lock); in ehci_qtd_alloc()
1009 spin_lock(&oxu->mem_lock); in oxu_qh_free()
1011 index = qh - &oxu->mem->qh_pool[0]; in oxu_qh_free()
1012 oxu->qh_used[index] = 0; in oxu_qh_free()
1014 spin_unlock(&oxu->mem_lock); in oxu_qh_free()
1020 struct oxu_hcd *oxu = qh->oxu; in qh_destroy()
1023 if (!list_empty(&qh->qtd_list) || qh->qh_next.ptr) { in qh_destroy()
1027 if (qh->dummy) in qh_destroy()
1028 oxu_qtd_free(oxu, qh->dummy); in qh_destroy()
1037 spin_lock(&oxu->mem_lock); in oxu_qh_alloc()
1040 if (!oxu->qh_used[i]) in oxu_qh_alloc()
1044 qh = (struct ehci_qh *) &oxu->mem->qh_pool[i]; in oxu_qh_alloc()
1047 kref_init(&qh->kref); in oxu_qh_alloc()
1048 qh->oxu = oxu; in oxu_qh_alloc()
1049 qh->qh_dma = virt_to_phys(qh); in oxu_qh_alloc()
1050 INIT_LIST_HEAD(&qh->qtd_list); in oxu_qh_alloc()
1053 qh->dummy = ehci_qtd_alloc(oxu); in oxu_qh_alloc()
1054 if (qh->dummy == NULL) { in oxu_qh_alloc()
1056 oxu->qh_used[i] = 0; in oxu_qh_alloc()
1061 oxu->qh_used[i] = 1; in oxu_qh_alloc()
1064 spin_unlock(&oxu->mem_lock); in oxu_qh_alloc()
1072 kref_get(&qh->kref); in qh_get()
1078 kref_put(&qh->kref, qh_destroy); in qh_put()
1085 spin_lock(&oxu->mem_lock); in oxu_murb_free()
1087 index = murb - &oxu->murb_pool[0]; in oxu_murb_free()
1088 oxu->murb_used[index] = 0; in oxu_murb_free()
1090 spin_unlock(&oxu->mem_lock); in oxu_murb_free()
1099 spin_lock(&oxu->mem_lock); in oxu_murb_alloc()
1102 if (!oxu->murb_used[i]) in oxu_murb_alloc()
1106 murb = &(oxu->murb_pool)[i]; in oxu_murb_alloc()
1108 oxu->murb_used[i] = 1; in oxu_murb_alloc()
1111 spin_unlock(&oxu->mem_lock); in oxu_murb_alloc()
1122 kfree(oxu->murb_pool); in ehci_mem_cleanup()
1123 oxu->murb_pool = NULL; in ehci_mem_cleanup()
1125 if (oxu->async) in ehci_mem_cleanup()
1126 qh_put(oxu->async); in ehci_mem_cleanup()
1127 oxu->async = NULL; in ehci_mem_cleanup()
1129 del_timer(&oxu->urb_timer); in ehci_mem_cleanup()
1131 oxu->periodic = NULL; in ehci_mem_cleanup()
1134 kfree(oxu->pshadow); in ehci_mem_cleanup()
1135 oxu->pshadow = NULL; in ehci_mem_cleanup()
1144 for (i = 0; i < oxu->periodic_size; i++) in ehci_mem_init()
1145 oxu->mem->frame_list[i] = EHCI_LIST_END; in ehci_mem_init()
1147 oxu->qh_used[i] = 0; in ehci_mem_init()
1149 oxu->qtd_used[i] = 0; in ehci_mem_init()
1151 oxu->murb_pool = kcalloc(MURB_NUM, sizeof(struct oxu_murb), flags); in ehci_mem_init()
1152 if (!oxu->murb_pool) in ehci_mem_init()
1156 oxu->murb_used[i] = 0; in ehci_mem_init()
1158 oxu->async = oxu_qh_alloc(oxu); in ehci_mem_init()
1159 if (!oxu->async) in ehci_mem_init()
1162 oxu->periodic = (__le32 *) &oxu->mem->frame_list; in ehci_mem_init()
1163 oxu->periodic_dma = virt_to_phys(oxu->periodic); in ehci_mem_init()
1165 for (i = 0; i < oxu->periodic_size; i++) in ehci_mem_init()
1166 oxu->periodic[i] = EHCI_LIST_END; in ehci_mem_init()
1169 oxu->pshadow = kcalloc(oxu->periodic_size, sizeof(void *), flags); in ehci_mem_init()
1170 if (oxu->pshadow != NULL) in ehci_mem_init()
1176 return -ENOMEM; in ehci_mem_init()
1188 qtd->hw_buf[0] = cpu_to_le32((u32)addr); in qtd_fill()
1189 qtd->hw_buf_hi[0] = cpu_to_le32((u32)(addr >> 32)); in qtd_fill()
1190 count = 0x1000 - (buf & 0x0fff); /* rest of that page */ in qtd_fill()
1197 /* per-qtd limit: from 16K to 20K (best alignment) */ in qtd_fill()
1200 qtd->hw_buf[i] = cpu_to_le32((u32)addr); in qtd_fill()
1201 qtd->hw_buf_hi[i] = cpu_to_le32((u32)(addr >> 32)); in qtd_fill()
1211 count -= (count % maxpacket); in qtd_fill()
1213 qtd->hw_token = cpu_to_le32((count << 16) | token); in qtd_fill()
1214 qtd->length = count; in qtd_fill()
1223 BUG_ON(qh->qh_state != QH_STATE_IDLE); in qh_update()
1225 qh->hw_qtd_next = QTD_NEXT(qtd->qtd_dma); in qh_update()
1226 qh->hw_alt_next = EHCI_LIST_END; in qh_update()
1230 * and set the pseudo-toggle in udev. Only usb_clear_halt() will in qh_update()
1233 if (!(qh->hw_info1 & cpu_to_le32(1 << 14))) { in qh_update()
1236 is_out = !(qtd->hw_token & cpu_to_le32(1 << 8)); in qh_update()
1237 epnum = (le32_to_cpup(&qh->hw_info1) >> 8) & 0x0f; in qh_update()
1238 if (unlikely(!usb_gettoggle(qh->dev, epnum, is_out))) { in qh_update()
1239 qh->hw_token &= ~cpu_to_le32(QTD_TOGGLE); in qh_update()
1240 usb_settoggle(qh->dev, epnum, is_out, 1); in qh_update()
1246 qh->hw_token &= cpu_to_le32(QTD_TOGGLE | QTD_STS_PING); in qh_update()
1250 * overlay, so qh->hw_token wrongly becomes inactive/halted), only fault
1257 if (list_empty(&qh->qtd_list)) in qh_refresh()
1258 qtd = qh->dummy; in qh_refresh()
1260 qtd = list_entry(qh->qtd_list.next, in qh_refresh()
1263 if (cpu_to_le32(qtd->qtd_dma) == qh->hw_current) in qh_refresh()
1276 urb->actual_length += length - QTD_LENGTH(token); in qtd_copy_status()
1279 if (unlikely(urb->status != -EINPROGRESS)) in qtd_copy_status()
1284 urb->status = -EREMOTEIO; in qtd_copy_status()
1290 urb->status = -EOVERFLOW; in qtd_copy_status()
1292 /* fs/ls interrupt xfer missed the complete-split */ in qtd_copy_status()
1293 urb->status = -EPROTO; in qtd_copy_status()
1295 urb->status = (QTD_PID(token) == 1) /* IN ? */ in qtd_copy_status()
1296 ? -ENOSR /* hc couldn't read data */ in qtd_copy_status()
1297 : -ECOMM; /* hc couldn't write data */ in qtd_copy_status()
1301 urb->status = -EPIPE; in qtd_copy_status()
1304 urb->dev->devpath, in qtd_copy_status()
1305 usb_pipeendpoint(urb->pipe), in qtd_copy_status()
1306 usb_pipein(urb->pipe) ? "in" : "out"); in qtd_copy_status()
1307 urb->status = -EPROTO; in qtd_copy_status()
1309 /* CERR nonzero + no errors + halt --> stall */ in qtd_copy_status()
1311 urb->status = -EPIPE; in qtd_copy_status()
1313 urb->status = -EPROTO; in qtd_copy_status()
1315 oxu_vdbg(oxu, "dev%d ep%d%s qtd token %08x --> status %d\n", in qtd_copy_status()
1316 usb_pipedevice(urb->pipe), in qtd_copy_status()
1317 usb_pipeendpoint(urb->pipe), in qtd_copy_status()
1318 usb_pipein(urb->pipe) ? "in" : "out", in qtd_copy_status()
1319 token, urb->status); in qtd_copy_status()
1324 __releases(oxu->lock) in ehci_urb_done()
1325 __acquires(oxu->lock) in ehci_urb_done()
1327 if (likely(urb->hcpriv != NULL)) { in ehci_urb_done()
1328 struct ehci_qh *qh = (struct ehci_qh *) urb->hcpriv; in ehci_urb_done()
1330 /* S-mask in a QH means it's an interrupt urb */ in ehci_urb_done()
1331 if ((qh->hw_info2 & cpu_to_le32(QH_SMASK)) != 0) { in ehci_urb_done()
1333 /* ... update hc-wide periodic stats (for usbfs) */ in ehci_urb_done()
1334 oxu_to_hcd(oxu)->self.bandwidth_int_reqs--; in ehci_urb_done()
1339 urb->hcpriv = NULL; in ehci_urb_done()
1340 switch (urb->status) { in ehci_urb_done()
1341 case -EINPROGRESS: /* success */ in ehci_urb_done()
1342 urb->status = 0; in ehci_urb_done()
1346 case -EREMOTEIO: /* fault or normal */ in ehci_urb_done()
1347 if (!(urb->transfer_flags & URB_SHORT_NOT_OK)) in ehci_urb_done()
1348 urb->status = 0; in ehci_urb_done()
1350 case -ECONNRESET: /* canceled */ in ehci_urb_done()
1351 case -ENOENT: in ehci_urb_done()
1357 __func__, urb->dev->devpath, urb, in ehci_urb_done()
1358 usb_pipeendpoint(urb->pipe), in ehci_urb_done()
1359 usb_pipein(urb->pipe) ? "in" : "out", in ehci_urb_done()
1360 urb->status, in ehci_urb_done()
1361 urb->actual_length, urb->transfer_buffer_length); in ehci_urb_done()
1365 spin_unlock(&oxu->lock); in ehci_urb_done()
1366 usb_hcd_giveback_urb(oxu_to_hcd(oxu), urb, urb->status); in ehci_urb_done()
1367 spin_lock(&oxu->lock); in ehci_urb_done()
1379 * Chases up to qh->hw_current. Returns number of completions called,
1384 struct ehci_qtd *last = NULL, *end = qh->dummy; in qh_completions()
1392 if (unlikely(list_empty(&qh->qtd_list))) in qh_completions()
1401 state = qh->qh_state; in qh_completions()
1402 qh->qh_state = QH_STATE_COMPLETING; in qh_completions()
1405 /* remove de-activated QTDs from front of queue. in qh_completions()
1410 list_for_each_entry_safe(qtd, tmp, &qh->qtd_list, qtd_list) { in qh_completions()
1414 urb = qtd->urb; in qh_completions()
1418 if (likely(last->urb != urb)) { in qh_completions()
1419 if (last->urb->complete == NULL) { in qh_completions()
1420 murb = (struct oxu_murb *) last->urb; in qh_completions()
1421 last->urb = murb->main; in qh_completions()
1422 if (murb->last) { in qh_completions()
1423 ehci_urb_done(oxu, last->urb); in qh_completions()
1428 ehci_urb_done(oxu, last->urb); in qh_completions()
1442 token = le32_to_cpu(qtd->hw_token); in qh_completions()
1444 /* always clean up qtds the hc de-activated */ in qh_completions()
1454 !(qtd->hw_alt_next & EHCI_LIST_END)) { in qh_completions()
1461 HC_IS_RUNNING(oxu_to_hcd(oxu)->state))) { in qh_completions()
1467 if (unlikely(!HC_IS_RUNNING(oxu_to_hcd(oxu)->state))) in qh_completions()
1468 urb->status = -ESHUTDOWN; in qh_completions()
1474 if (likely(urb->status == -EINPROGRESS)) in qh_completions()
1486 && cpu_to_le32(qtd->qtd_dma) in qh_completions()
1487 == qh->hw_current) in qh_completions()
1488 token = le32_to_cpu(qh->hw_token); in qh_completions()
1494 if ((HALT_BIT & qh->hw_token) == 0) { in qh_completions()
1496 qh->hw_token |= HALT_BIT; in qh_completions()
1502 qtd_copy_status(oxu, urb->complete ? in qh_completions()
1503 urb : ((struct oxu_murb *) urb)->main, in qh_completions()
1504 qtd->length, token); in qh_completions()
1505 if ((usb_pipein(qtd->urb->pipe)) && in qh_completions()
1506 (NULL != qtd->transfer_buffer)) in qh_completions()
1507 memcpy(qtd->transfer_buffer, qtd->buffer, qtd->length); in qh_completions()
1508 do_status = (urb->status == -EREMOTEIO) in qh_completions()
1509 && usb_pipecontrol(urb->pipe); in qh_completions()
1511 if (stopped && qtd->qtd_list.prev != &qh->qtd_list) { in qh_completions()
1512 last = list_entry(qtd->qtd_list.prev, in qh_completions()
1514 last->hw_next = qtd->hw_next; in qh_completions()
1516 list_del(&qtd->qtd_list); in qh_completions()
1522 if (last->urb->complete == NULL) { in qh_completions()
1523 murb = (struct oxu_murb *) last->urb; in qh_completions()
1524 last->urb = murb->main; in qh_completions()
1525 if (murb->last) { in qh_completions()
1526 ehci_urb_done(oxu, last->urb); in qh_completions()
1531 ehci_urb_done(oxu, last->urb); in qh_completions()
1538 qh->qh_state = state; in qh_completions()
1544 if (stopped != 0 || qh->hw_qtd_next == EHCI_LIST_END) { in qh_completions()
1554 & qh->hw_info2) != 0) { in qh_completions()
1581 list_del(&qtd->qtd_list); in qtd_list_free()
1607 list_add_tail(&qtd->qtd_list, head); in qh_urb_transaction()
1608 qtd->urb = urb; in qh_urb_transaction()
1614 len = urb->transfer_buffer_length; in qh_urb_transaction()
1615 is_input = usb_pipein(urb->pipe); in qh_urb_transaction()
1616 if (!urb->transfer_buffer && urb->transfer_buffer_length && is_input) in qh_urb_transaction()
1617 urb->transfer_buffer = phys_to_virt(urb->transfer_dma); in qh_urb_transaction()
1619 if (usb_pipecontrol(urb->pipe)) { in qh_urb_transaction()
1625 qtd_fill(qtd, qtd->buffer_dma, sizeof(struct usb_ctrlrequest), in qh_urb_transaction()
1627 memcpy(qtd->buffer, qtd->urb->setup_packet, in qh_urb_transaction()
1636 qtd->urb = urb; in qh_urb_transaction()
1637 qtd_prev->hw_next = QTD_NEXT(qtd->qtd_dma); in qh_urb_transaction()
1638 list_add_tail(&qtd->qtd_list, head); in qh_urb_transaction()
1653 buf = qtd->buffer_dma; in qh_urb_transaction()
1654 transfer_buf = urb->transfer_buffer; in qh_urb_transaction()
1657 memcpy(qtd->buffer, qtd->urb->transfer_buffer, len); in qh_urb_transaction()
1663 maxpacket = usb_maxpacket(urb->dev, urb->pipe); in qh_urb_transaction()
1674 qtd->transfer_buffer = transfer_buf; in qh_urb_transaction()
1675 len -= this_qtd_len; in qh_urb_transaction()
1679 qtd->hw_alt_next = oxu->async->hw_alt_next; in qh_urb_transaction()
1682 if ((maxpacket & (this_qtd_len + (maxpacket - 1))) == 0) in qh_urb_transaction()
1697 qtd->urb = urb; in qh_urb_transaction()
1698 qtd_prev->hw_next = QTD_NEXT(qtd->qtd_dma); in qh_urb_transaction()
1699 list_add_tail(&qtd->qtd_list, head); in qh_urb_transaction()
1705 if (likely((urb->transfer_flags & URB_SHORT_NOT_OK) == 0 in qh_urb_transaction()
1706 || usb_pipecontrol(urb->pipe))) in qh_urb_transaction()
1707 qtd->hw_alt_next = EHCI_LIST_END; in qh_urb_transaction()
1713 if (likely(urb->transfer_buffer_length != 0)) { in qh_urb_transaction()
1716 if (usb_pipecontrol(urb->pipe)) { in qh_urb_transaction()
1718 token ^= 0x0100; /* "in" <--> "out" */ in qh_urb_transaction()
1720 } else if (usb_pipebulk(urb->pipe) in qh_urb_transaction()
1721 && (urb->transfer_flags & URB_ZERO_PACKET) in qh_urb_transaction()
1722 && !(urb->transfer_buffer_length % maxpacket)) { in qh_urb_transaction()
1730 qtd->urb = urb; in qh_urb_transaction()
1731 qtd_prev->hw_next = QTD_NEXT(qtd->qtd_dma); in qh_urb_transaction()
1732 list_add_tail(&qtd->qtd_list, head); in qh_urb_transaction()
1740 qtd->hw_token |= cpu_to_le32(QTD_IOC); in qh_urb_transaction()
1752 * just one microframe in the s-mask. For split interrupt transactions
1753 * there are additional complications: c-mask, maybe FSTNs.
1769 info1 |= usb_pipeendpoint(urb->pipe) << 8; in qh_make()
1770 info1 |= usb_pipedevice(urb->pipe) << 0; in qh_make()
1772 is_input = usb_pipein(urb->pipe); in qh_make()
1773 type = usb_pipetype(urb->pipe); in qh_make()
1774 maxp = usb_maxpacket(urb->dev, urb->pipe); in qh_make()
1777 * - allowing for high bandwidth, how many nsec/uframe are used? in qh_make()
1778 * - split transactions need a second CSPLIT uframe; same question in qh_make()
1779 * - splits also need a schedule gap (for full/low speed I/O) in qh_make()
1780 * - qh has a polling interval in qh_make()
1785 qh->usecs = NS_TO_US(usb_calc_bus_time(USB_SPEED_HIGH, in qh_make()
1788 qh->start = NO_FRAME; in qh_make()
1790 if (urb->dev->speed == USB_SPEED_HIGH) { in qh_make()
1791 qh->c_usecs = 0; in qh_make()
1792 qh->gap_uf = 0; in qh_make()
1794 qh->period = urb->interval >> 3; in qh_make()
1795 if (qh->period == 0 && urb->interval != 1) { in qh_make()
1801 urb->interval); in qh_make()
1805 struct usb_tt *tt = urb->dev->tt; in qh_make()
1809 qh->gap_uf = 1 + usb_calc_bus_time(urb->dev->speed, in qh_make()
1814 qh->c_usecs = qh->usecs + HS_USECS(0); in qh_make()
1815 qh->usecs = HS_USECS(1); in qh_make()
1817 qh->usecs += HS_USECS(1); in qh_make()
1818 qh->c_usecs = HS_USECS(0); in qh_make()
1821 think_time = tt ? tt->think_time : 0; in qh_make()
1822 qh->tt_usecs = NS_TO_US(think_time + in qh_make()
1823 usb_calc_bus_time(urb->dev->speed, in qh_make()
1825 qh->period = urb->interval; in qh_make()
1830 qh->dev = urb->dev; in qh_make()
1833 switch (urb->dev->speed) { in qh_make()
1849 info2 |= urb->dev->ttport << 23; in qh_make()
1851 /* NOTE: if (PIPE_INTERRUPT) { scheduler sets c-mask } */ in qh_make()
1872 oxu_dbg(oxu, "bogus dev %p speed %d\n", urb->dev, urb->dev->speed); in qh_make()
1878 /* NOTE: if (PIPE_INTERRUPT) { scheduler sets s-mask } */ in qh_make()
1881 qh->qh_state = QH_STATE_IDLE; in qh_make()
1882 qh->hw_info1 = cpu_to_le32(info1); in qh_make()
1883 qh->hw_info2 = cpu_to_le32(info2); in qh_make()
1884 usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), !is_input, 1); in qh_make()
1893 __le32 dma = QH_NEXT(qh->qh_dma); in qh_link_async()
1897 head = oxu->async; in qh_link_async()
1899 if (!head->qh_next.qh) { in qh_link_async()
1900 u32 cmd = readl(&oxu->regs->command); in qh_link_async()
1904 (void)handshake(oxu, &oxu->regs->status, in qh_link_async()
1907 writel(cmd, &oxu->regs->command); in qh_link_async()
1908 oxu_to_hcd(oxu)->state = HC_STATE_RUNNING; in qh_link_async()
1914 if (qh->qh_state == QH_STATE_IDLE) in qh_link_async()
1918 qh->qh_next = head->qh_next; in qh_link_async()
1919 qh->hw_next = head->hw_next; in qh_link_async()
1922 head->qh_next.qh = qh; in qh_link_async()
1923 head->hw_next = dma; in qh_link_async()
1925 qh->qh_state = QH_STATE_LINKED; in qh_link_async()
1945 /* can't sleep here, we have oxu->lock... */ in qh_append_tds()
1955 qtd = list_entry(qtd_list->next, struct ehci_qtd, in qh_append_tds()
1962 if (usb_pipedevice(urb->pipe) == 0) in qh_append_tds()
1963 qh->hw_info1 &= ~QH_ADDR_MASK; in qh_append_tds()
1979 token = qtd->hw_token; in qh_append_tds()
1980 qtd->hw_token = HALT_BIT; in qh_append_tds()
1982 dummy = qh->dummy; in qh_append_tds()
1984 dma = dummy->qtd_dma; in qh_append_tds()
1986 dummy->qtd_dma = dma; in qh_append_tds()
1988 list_del(&qtd->qtd_list); in qh_append_tds()
1989 list_add(&dummy->qtd_list, qtd_list); in qh_append_tds()
1990 list_splice(qtd_list, qh->qtd_list.prev); in qh_append_tds()
1992 ehci_qtd_init(qtd, qtd->qtd_dma); in qh_append_tds()
1993 qh->dummy = qtd; in qh_append_tds()
1996 dma = qtd->qtd_dma; in qh_append_tds()
1997 qtd = list_entry(qh->qtd_list.prev, in qh_append_tds()
1999 qtd->hw_next = QTD_NEXT(dma); in qh_append_tds()
2002 dummy->hw_token = (token & ~(0x80)); in qh_append_tds()
2004 dummy->hw_token = token; in qh_append_tds()
2006 urb->hcpriv = qh_get(qh); in qh_append_tds()
2015 int epnum = urb->ep->desc.bEndpointAddress; in submit_async()
2022 qtd = list_entry(qtd_list->next, struct ehci_qtd, qtd_list); in submit_async()
2025 __func__, urb->dev->devpath, urb, in submit_async()
2027 urb->transfer_buffer_length, in submit_async()
2028 qtd, urb->ep->hcpriv); in submit_async()
2031 spin_lock_irqsave(&oxu->lock, flags); in submit_async()
2033 rc = -ESHUTDOWN; in submit_async()
2037 qh = qh_append_tds(oxu, urb, qtd_list, epnum, &urb->ep->hcpriv); in submit_async()
2039 rc = -ENOMEM; in submit_async()
2046 if (likely(qh->qh_state == QH_STATE_IDLE)) in submit_async()
2049 spin_unlock_irqrestore(&oxu->lock, flags); in submit_async()
2059 struct ehci_qh *qh = oxu->reclaim; in end_unlink_async()
2064 qh->qh_state = QH_STATE_IDLE; in end_unlink_async()
2065 qh->qh_next.qh = NULL; in end_unlink_async()
2069 next = qh->reclaim; in end_unlink_async()
2070 oxu->reclaim = next; in end_unlink_async()
2071 oxu->reclaim_ready = 0; in end_unlink_async()
2072 qh->reclaim = NULL; in end_unlink_async()
2076 if (!list_empty(&qh->qtd_list) in end_unlink_async()
2077 && HC_IS_RUNNING(oxu_to_hcd(oxu)->state)) in end_unlink_async()
2085 if (HC_IS_RUNNING(oxu_to_hcd(oxu)->state) in end_unlink_async()
2086 && oxu->async->qh_next.qh == NULL) in end_unlink_async()
2091 oxu->reclaim = NULL; in end_unlink_async()
2097 /* caller must own oxu->lock */
2101 int cmd = readl(&oxu->regs->command); in start_unlink_async()
2105 assert_spin_locked(&oxu->lock); in start_unlink_async()
2106 BUG_ON(oxu->reclaim || (qh->qh_state != QH_STATE_LINKED in start_unlink_async()
2107 && qh->qh_state != QH_STATE_UNLINK_WAIT)); in start_unlink_async()
2111 if (unlikely(qh == oxu->async)) { in start_unlink_async()
2113 if (oxu_to_hcd(oxu)->state != HC_STATE_HALT in start_unlink_async()
2114 && !oxu->reclaim) { in start_unlink_async()
2116 writel(cmd & ~CMD_ASE, &oxu->regs->command); in start_unlink_async()
2124 qh->qh_state = QH_STATE_UNLINK; in start_unlink_async()
2125 oxu->reclaim = qh = qh_get(qh); in start_unlink_async()
2127 prev = oxu->async; in start_unlink_async()
2128 while (prev->qh_next.qh != qh) in start_unlink_async()
2129 prev = prev->qh_next.qh; in start_unlink_async()
2131 prev->hw_next = qh->hw_next; in start_unlink_async()
2132 prev->qh_next = qh->qh_next; in start_unlink_async()
2135 if (unlikely(oxu_to_hcd(oxu)->state == HC_STATE_HALT)) { in start_unlink_async()
2136 /* if (unlikely(qh->reclaim != 0)) in start_unlink_async()
2143 oxu->reclaim_ready = 0; in start_unlink_async()
2145 writel(cmd, &oxu->regs->command); in start_unlink_async()
2146 (void) readl(&oxu->regs->command); in start_unlink_async()
2155 if (!++(oxu->stamp)) in scan_async()
2156 oxu->stamp++; in scan_async()
2159 qh = oxu->async->qh_next.qh; in scan_async()
2163 if (!list_empty(&qh->qtd_list) in scan_async()
2164 && qh->stamp != oxu->stamp) { in scan_async()
2173 qh->stamp = oxu->stamp; in scan_async()
2181 * as HCD schedule-scanning costs. delay for any qh in scan_async()
2182 * we just scanned, there's a not-unusual case that it in scan_async()
2184 * (plus, avoids some kind of re-activation race.) in scan_async()
2186 if (list_empty(&qh->qtd_list)) { in scan_async()
2187 if (qh->stamp == oxu->stamp) in scan_async()
2189 else if (!oxu->reclaim in scan_async()
2190 && qh->qh_state == QH_STATE_LINKED) in scan_async()
2194 qh = qh->qh_next.qh; in scan_async()
2202 * periodic_next_shadow - return "next" pointer on shadow list
2212 return &periodic->qh->qh_next; in periodic_next_shadow()
2216 /* caller must hold oxu->lock */
2219 union ehci_shadow *prev_p = &oxu->pshadow[frame]; in periodic_unlink()
2220 __le32 *hw_p = &oxu->periodic[frame]; in periodic_unlink()
2244 __le32 *hw_p = &oxu->periodic[frame]; in periodic_usecs()
2245 union ehci_shadow *q = &oxu->pshadow[frame]; in periodic_usecs()
2248 while (q->ptr) { in periodic_usecs()
2252 /* is it in the S-mask? */ in periodic_usecs()
2253 if (q->qh->hw_info2 & cpu_to_le32(1 << uframe)) in periodic_usecs()
2254 usecs += q->qh->usecs; in periodic_usecs()
2255 /* ... or C-mask? */ in periodic_usecs()
2256 if (q->qh->hw_info2 & cpu_to_le32(1 << (8 + uframe))) in periodic_usecs()
2257 usecs += q->qh->c_usecs; in periodic_usecs()
2258 hw_p = &q->qh->hw_next; in periodic_usecs()
2259 q = &q->qh->qh_next; in periodic_usecs()
2265 oxu_err(oxu, "uframe %d sched overrun: %d usecs\n", in periodic_usecs()
2279 status = handshake(oxu, &oxu->regs->status, STS_PSS, 0, 9 * 125); in enable_periodic()
2281 oxu_to_hcd(oxu)->state = HC_STATE_HALT; in enable_periodic()
2286 cmd = readl(&oxu->regs->command) | CMD_PSE; in enable_periodic()
2287 writel(cmd, &oxu->regs->command); in enable_periodic()
2289 oxu_to_hcd(oxu)->state = HC_STATE_RUNNING; in enable_periodic()
2292 oxu->next_uframe = readl(&oxu->regs->frame_index) in enable_periodic()
2293 % (oxu->periodic_size << 3); in enable_periodic()
2305 status = handshake(oxu, &oxu->regs->status, STS_PSS, STS_PSS, 9 * 125); in disable_periodic()
2307 oxu_to_hcd(oxu)->state = HC_STATE_HALT; in disable_periodic()
2312 cmd = readl(&oxu->regs->command) & ~CMD_PSE; in disable_periodic()
2313 writel(cmd, &oxu->regs->command); in disable_periodic()
2316 oxu->next_uframe = -1; in disable_periodic()
2329 unsigned period = qh->period; in qh_link_periodic()
2331 dev_dbg(&qh->dev->dev, in qh_link_periodic()
2332 "link qh%d-%04x/%p start %d [%d/%d us]\n", in qh_link_periodic()
2333 period, le32_to_cpup(&qh->hw_info2) & (QH_CMASK | QH_SMASK), in qh_link_periodic()
2334 qh, qh->start, qh->usecs, qh->c_usecs); in qh_link_periodic()
2340 for (i = qh->start; i < oxu->periodic_size; i += period) { in qh_link_periodic()
2341 union ehci_shadow *prev = &oxu->pshadow[i]; in qh_link_periodic()
2342 __le32 *hw_p = &oxu->periodic[i]; in qh_link_periodic()
2352 hw_p = &here.qh->hw_next; in qh_link_periodic()
2356 /* sorting each branch by period (slow-->fast) in qh_link_periodic()
2360 if (qh->period > here.qh->period) in qh_link_periodic()
2362 prev = &here.qh->qh_next; in qh_link_periodic()
2363 hw_p = &here.qh->hw_next; in qh_link_periodic()
2368 qh->qh_next = here; in qh_link_periodic()
2370 qh->hw_next = *hw_p; in qh_link_periodic()
2372 prev->qh = qh; in qh_link_periodic()
2373 *hw_p = QH_NEXT(qh->qh_dma); in qh_link_periodic()
2376 qh->qh_state = QH_STATE_LINKED; in qh_link_periodic()
2379 /* update per-qh bandwidth for usbfs */ in qh_link_periodic()
2380 oxu_to_hcd(oxu)->self.bandwidth_allocated += qh->period in qh_link_periodic()
2381 ? ((qh->usecs + qh->c_usecs) / qh->period) in qh_link_periodic()
2382 : (qh->usecs * 8); in qh_link_periodic()
2385 if (!oxu->periodic_sched++) in qh_link_periodic()
2401 * qh->hw_info1 |= cpu_to_le32(1 << 7 "ignore"); in qh_unlink_periodic()
2405 period = qh->period; in qh_unlink_periodic()
2409 for (i = qh->start; i < oxu->periodic_size; i += period) in qh_unlink_periodic()
2412 /* update per-qh bandwidth for usbfs */ in qh_unlink_periodic()
2413 oxu_to_hcd(oxu)->self.bandwidth_allocated -= qh->period in qh_unlink_periodic()
2414 ? ((qh->usecs + qh->c_usecs) / qh->period) in qh_unlink_periodic()
2415 : (qh->usecs * 8); in qh_unlink_periodic()
2417 dev_dbg(&qh->dev->dev, in qh_unlink_periodic()
2418 "unlink qh%d-%04x/%p start %d [%d/%d us]\n", in qh_unlink_periodic()
2419 qh->period, in qh_unlink_periodic()
2420 le32_to_cpup(&qh->hw_info2) & (QH_CMASK | QH_SMASK), in qh_unlink_periodic()
2421 qh, qh->start, qh->usecs, qh->c_usecs); in qh_unlink_periodic()
2423 /* qh->qh_next still "live" to HC */ in qh_unlink_periodic()
2424 qh->qh_state = QH_STATE_UNLINK; in qh_unlink_periodic()
2425 qh->qh_next.ptr = NULL; in qh_unlink_periodic()
2429 oxu->periodic_sched--; in qh_unlink_periodic()
2430 if (!oxu->periodic_sched) in qh_unlink_periodic()
2441 * qh->hw_next or finish a writeback after SPLIT/CSPLIT ... and in intr_deschedule()
2445 if (list_empty(&qh->qtd_list) in intr_deschedule()
2446 || (cpu_to_le32(QH_CMASK) & qh->hw_info2) != 0) in intr_deschedule()
2452 qh->qh_state = QH_STATE_IDLE; in intr_deschedule()
2453 qh->hw_next = EHCI_LIST_END; in intr_deschedule()
2473 usecs = 100 - usecs; in check_period()
2485 } while ((frame += 1) < oxu->periodic_size); in check_period()
2493 } while ((frame += period) < oxu->periodic_size); in check_period()
2503 int retval = -ENOSPC; in check_intr_schedule()
2505 if (qh->c_usecs && uframe >= 6) /* FSTN territory? */ in check_intr_schedule()
2508 if (!check_period(oxu, frame, uframe, qh->period, qh->usecs)) in check_intr_schedule()
2510 if (!qh->c_usecs) { in check_intr_schedule()
2521 * or when the previous schedule slot can't be re-used.
2528 unsigned frame; /* 0..(qh->period - 1), or NO_FRAME */ in qh_schedule()
2531 qh->hw_next = EHCI_LIST_END; in qh_schedule()
2532 frame = qh->start; in qh_schedule()
2535 if (frame < qh->period) { in qh_schedule()
2536 uframe = ffs(le32_to_cpup(&qh->hw_info2) & QH_SMASK); in qh_schedule()
2537 status = check_intr_schedule(oxu, frame, --uframe, in qh_schedule()
2542 status = -ENOSPC; in qh_schedule()
2550 if (qh->period) { in qh_schedule()
2551 frame = qh->period - 1; in qh_schedule()
2560 } while (status && frame--); in qh_schedule()
2562 /* qh->period == 0 means every uframe */ in qh_schedule()
2569 qh->start = frame; in qh_schedule()
2571 /* reset S-frame and (maybe) C-frame masks */ in qh_schedule()
2572 qh->hw_info2 &= cpu_to_le32(~(QH_CMASK | QH_SMASK)); in qh_schedule()
2573 qh->hw_info2 |= qh->period in qh_schedule()
2576 qh->hw_info2 |= c_mask; in qh_schedule()
2596 epnum = urb->ep->desc.bEndpointAddress; in intr_submit()
2598 spin_lock_irqsave(&oxu->lock, flags); in intr_submit()
2601 status = -ESHUTDOWN; in intr_submit()
2607 qh = qh_append_tds(oxu, urb, &empty, epnum, &urb->ep->hcpriv); in intr_submit()
2609 status = -ENOMEM; in intr_submit()
2612 if (qh->qh_state == QH_STATE_IDLE) { in intr_submit()
2619 qh = qh_append_tds(oxu, urb, qtd_list, epnum, &urb->ep->hcpriv); in intr_submit()
2623 oxu_to_hcd(oxu)->self.bandwidth_int_reqs++; in intr_submit()
2626 spin_unlock_irqrestore(&oxu->lock, flags); in intr_submit()
2637 return -ENOSYS; in itd_submit()
2644 return -ENOSYS; in sitd_submit()
2652 mod = oxu->periodic_size << 3; in scan_periodic()
2657 * Touches as few pages as possible: cache-friendly. in scan_periodic()
2659 now_uframe = oxu->next_uframe; in scan_periodic()
2660 if (HC_IS_RUNNING(oxu_to_hcd(oxu)->state)) in scan_periodic()
2661 clock = readl(&oxu->regs->frame_index); in scan_periodic()
2663 clock = now_uframe + mod - 1; in scan_periodic()
2679 q_p = &oxu->pshadow[frame]; in scan_periodic()
2680 hw_p = &oxu->periodic[frame]; in scan_periodic()
2681 q.ptr = q_p->ptr; in scan_periodic()
2692 type = Q_NEXT_TYPE(q.qh->hw_next); in scan_periodic()
2693 q = q.qh->qh_next; in scan_periodic()
2695 if (unlikely(list_empty(&temp.qh->qtd_list))) in scan_periodic()
2719 /* FIXME: likewise assumes HC doesn't halt mid-scan */ in scan_periodic()
2724 if (!HC_IS_RUNNING(oxu_to_hcd(oxu)->state)) in scan_periodic()
2726 oxu->next_uframe = now_uframe; in scan_periodic()
2727 now = readl(&oxu->regs->frame_index) % mod; in scan_periodic()
2746 int port = HCS_N_PORTS(oxu->hcs_params); in ehci_turn_off_all_ports()
2748 while (port--) in ehci_turn_off_all_ports()
2749 writel(PORT_RWC_BITS, &oxu->regs->port_status[port]); in ehci_turn_off_all_ports()
2756 if (!HCS_PPC(oxu->hcs_params)) in ehci_port_power()
2760 for (port = HCS_N_PORTS(oxu->hcs_params); port > 0; ) { in ehci_port_power()
2763 USB_PORT_FEAT_POWER, port--, NULL, 0); in ehci_port_power()
2766 USB_PORT_FEAT_POWER, port--, NULL, 0); in ehci_port_power()
2773 * It calls driver completion functions, after dropping oxu->lock.
2778 if (oxu->reclaim_ready) in ehci_work()
2781 /* another CPU may drop oxu->lock during a schedule scan while in ehci_work()
2783 * attempts at re-entrant schedule scanning. in ehci_work()
2785 if (oxu->scanning) in ehci_work()
2787 oxu->scanning = 1; in ehci_work()
2789 if (oxu->next_uframe != -1) in ehci_work()
2791 oxu->scanning = 0; in ehci_work()
2797 if (HC_IS_RUNNING(oxu_to_hcd(oxu)->state) && in ehci_work()
2798 (oxu->async->qh_next.ptr != NULL || in ehci_work()
2799 oxu->periodic_sched != 0)) in ehci_work()
2806 if (qh->qh_state == QH_STATE_LINKED in unlink_async()
2807 && oxu->reclaim in unlink_async()
2808 && HC_IS_RUNNING(oxu_to_hcd(oxu)->state)) { in unlink_async()
2811 for (last = oxu->reclaim; in unlink_async()
2812 last->reclaim; in unlink_async()
2813 last = last->reclaim) in unlink_async()
2815 qh->qh_state = QH_STATE_UNLINK_WAIT; in unlink_async()
2816 last->reclaim = qh; in unlink_async()
2819 } else if (!HC_IS_RUNNING(oxu_to_hcd(oxu)->state) && oxu->reclaim) in unlink_async()
2823 if (qh->qh_state == QH_STATE_LINKED) in unlink_async()
2837 spin_lock(&oxu->lock); in oxu210_hcd_irq()
2839 status = readl(&oxu->regs->status); in oxu210_hcd_irq()
2849 if (!status || unlikely(hcd->state == HC_STATE_HALT)) { in oxu210_hcd_irq()
2850 spin_unlock(&oxu->lock); in oxu210_hcd_irq()
2855 writel(status, &oxu->regs->status); in oxu210_hcd_irq()
2856 readl(&oxu->regs->command); /* unblock posted write */ in oxu210_hcd_irq()
2872 oxu->reclaim_ready = 1; in oxu210_hcd_irq()
2878 unsigned i = HCS_N_PORTS(oxu->hcs_params); in oxu210_hcd_irq()
2882 if (!(readl(&oxu->regs->command) & CMD_RUN)) in oxu210_hcd_irq()
2885 while (i--) { in oxu210_hcd_irq()
2886 int pstatus = readl(&oxu->regs->port_status[i]); in oxu210_hcd_irq()
2891 || oxu->reset_done[i] != 0) in oxu210_hcd_irq()
2898 oxu->reset_done[i] = jiffies + in oxu210_hcd_irq()
2901 mod_timer(&hcd->rh_timer, oxu->reset_done[i]); in oxu210_hcd_irq()
2908 status = readl(&oxu->regs->status); in oxu210_hcd_irq()
2909 dbg_cmd(oxu, "fatal", readl(&oxu->regs->command)); in oxu210_hcd_irq()
2915 writel(0, &oxu->regs->configured_flag); in oxu210_hcd_irq()
2926 spin_unlock(&oxu->lock); in oxu210_hcd_irq()
2937 u32 status = oxu_readl(hcd->regs, OXU_CHIPIRQSTATUS); in oxu_irq()
2938 u32 enable = oxu_readl(hcd->regs, OXU_CHIPIRQEN_SET); in oxu_irq()
2941 oxu_writel(hcd->regs, OXU_CHIPIRQEN_CLR, enable); in oxu_irq()
2943 if ((oxu->is_otg && (status & OXU_USBOTGI)) || in oxu_irq()
2944 (!oxu->is_otg && (status & OXU_USBSPHI))) in oxu_irq()
2950 oxu_writel(hcd->regs, OXU_CHIPIRQEN_SET, enable); in oxu_irq()
2960 spin_lock_irqsave(&oxu->lock, flags); in oxu_watchdog()
2963 if (oxu->reclaim) { in oxu_watchdog()
2964 u32 status = readl(&oxu->regs->status); in oxu_watchdog()
2967 writel(STS_IAA, &oxu->regs->status); in oxu_watchdog()
2968 oxu->reclaim_ready = 1; in oxu_watchdog()
2973 if (test_bit(TIMER_ASYNC_OFF, &oxu->actions)) in oxu_watchdog()
2974 start_unlink_async(oxu, oxu->async); in oxu_watchdog()
2979 spin_unlock_irqrestore(&oxu->lock, flags); in oxu_watchdog()
2982 /* One-time init, only for memory state.
2991 spin_lock_init(&oxu->lock); in oxu_hcd_init()
2993 timer_setup(&oxu->watchdog, oxu_watchdog, 0); in oxu_hcd_init()
2999 oxu->periodic_size = DEFAULT_I_TDPS; in oxu_hcd_init()
3005 hcc_params = readl(&oxu->caps->hcc_params); in oxu_hcd_init()
3007 oxu->i_thresh = 8; in oxu_hcd_init()
3009 oxu->i_thresh = 2 + HCC_ISOC_THRES(hcc_params); in oxu_hcd_init()
3011 oxu->reclaim = NULL; in oxu_hcd_init()
3012 oxu->reclaim_ready = 0; in oxu_hcd_init()
3013 oxu->next_uframe = -1; in oxu_hcd_init()
3022 oxu->async->qh_next.qh = NULL; in oxu_hcd_init()
3023 oxu->async->hw_next = QH_NEXT(oxu->async->qh_dma); in oxu_hcd_init()
3024 oxu->async->hw_info1 = cpu_to_le32(QH_HEAD); in oxu_hcd_init()
3025 oxu->async->hw_token = cpu_to_le32(QTD_STS_HALT); in oxu_hcd_init()
3026 oxu->async->hw_qtd_next = EHCI_LIST_END; in oxu_hcd_init()
3027 oxu->async->qh_state = QH_STATE_LINKED; in oxu_hcd_init()
3028 oxu->async->hw_alt_next = QTD_NEXT(oxu->async->dummy->qtd_dma); in oxu_hcd_init()
3054 oxu->command = temp; in oxu_hcd_init()
3065 spin_lock_init(&oxu->mem_lock); in oxu_reset()
3066 INIT_LIST_HEAD(&oxu->urb_list); in oxu_reset()
3067 oxu->urb_len = 0; in oxu_reset()
3069 if (oxu->is_otg) { in oxu_reset()
3070 oxu->caps = hcd->regs + OXU_OTG_CAP_OFFSET; in oxu_reset()
3071 oxu->regs = hcd->regs + OXU_OTG_CAP_OFFSET + \ in oxu_reset()
3072 HC_LENGTH(readl(&oxu->caps->hc_capbase)); in oxu_reset()
3074 oxu->mem = hcd->regs + OXU_SPH_MEM; in oxu_reset()
3076 oxu->caps = hcd->regs + OXU_SPH_CAP_OFFSET; in oxu_reset()
3077 oxu->regs = hcd->regs + OXU_SPH_CAP_OFFSET + \ in oxu_reset()
3078 HC_LENGTH(readl(&oxu->caps->hc_capbase)); in oxu_reset()
3080 oxu->mem = hcd->regs + OXU_OTG_MEM; in oxu_reset()
3083 oxu->hcs_params = readl(&oxu->caps->hcs_params); in oxu_reset()
3084 oxu->sbrn = 0x20; in oxu_reset()
3095 hcd->uses_new_polling = 1; in oxu_run()
3103 writel(oxu->periodic_dma, &oxu->regs->frame_list); in oxu_run()
3104 writel((u32) oxu->async->qh_dma, &oxu->regs->async_next); in oxu_run()
3106 /* hcc_params controls whether oxu->regs->segment must (!!!) in oxu_run()
3112 * NOTE: the dma mask is visible through dev->dma_mask, so in oxu_run()
3117 hcc_params = readl(&oxu->caps->hcc_params); in oxu_run()
3119 writel(0, &oxu->regs->segment); in oxu_run()
3121 oxu->command &= ~(CMD_LRESET | CMD_IAAD | CMD_PSE | in oxu_run()
3123 oxu->command |= CMD_RUN; in oxu_run()
3124 writel(oxu->command, &oxu->regs->command); in oxu_run()
3125 dbg_cmd(oxu, "init", oxu->command); in oxu_run()
3133 hcd->state = HC_STATE_RUNNING; in oxu_run()
3134 writel(FLAG_CF, &oxu->regs->configured_flag); in oxu_run()
3135 readl(&oxu->regs->command); /* unblock posted writes */ in oxu_run()
3137 temp = HC_VERSION(readl(&oxu->caps->hc_capbase)); in oxu_run()
3138 oxu_info(oxu, "USB %x.%x started, quasi-EHCI %x.%02x, driver %s%s\n", in oxu_run()
3139 ((oxu->sbrn & 0xf0)>>4), (oxu->sbrn & 0x0f), in oxu_run()
3143 writel(INTR_MASK, &oxu->regs->intr_enable); /* Turn On Interrupts */ in oxu_run()
3156 del_timer_sync(&oxu->watchdog); in oxu_stop()
3158 spin_lock_irq(&oxu->lock); in oxu_stop()
3159 if (HC_IS_RUNNING(hcd->state)) in oxu_stop()
3163 writel(0, &oxu->regs->intr_enable); in oxu_stop()
3164 spin_unlock_irq(&oxu->lock); in oxu_stop()
3167 writel(0, &oxu->regs->configured_flag); in oxu_stop()
3170 spin_lock_irq(&oxu->lock); in oxu_stop()
3171 if (oxu->async) in oxu_stop()
3173 spin_unlock_irq(&oxu->lock); in oxu_stop()
3176 dbg_status(oxu, "oxu_stop completed", readl(&oxu->regs->status)); in oxu_stop()
3191 writel(0, &oxu->regs->configured_flag); in oxu_shutdown()
3194 readl(&oxu->regs->configured_flag); in oxu_shutdown()
3197 /* Non-error returns are a promise to giveback() the urb later
3203 * hcd-specific init for hcpriv hasn't been done yet
3216 switch (usb_pipetype(urb->pipe)) { in __oxu_urb_enqueue()
3221 return -ENOMEM; in __oxu_urb_enqueue()
3226 return -ENOMEM; in __oxu_urb_enqueue()
3230 if (urb->dev->speed == USB_SPEED_HIGH) in __oxu_urb_enqueue()
3250 if (!usb_pipebulk(urb->pipe)) in oxu_urb_enqueue()
3254 transfer_buffer = urb->transfer_buffer; in oxu_urb_enqueue()
3256 num = urb->transfer_buffer_length / 4096; in oxu_urb_enqueue()
3257 rem = urb->transfer_buffer_length % 4096; in oxu_urb_enqueue()
3267 for (i = 0; i < num - 1; i++) { in oxu_urb_enqueue()
3279 murb->transfer_buffer_length = 4096; in oxu_urb_enqueue()
3280 murb->transfer_buffer = transfer_buffer + i * 4096; in oxu_urb_enqueue()
3283 murb->complete = NULL; in oxu_urb_enqueue()
3285 ((struct oxu_murb *) murb)->main = urb; in oxu_urb_enqueue()
3286 ((struct oxu_murb *) murb)->last = 0; in oxu_urb_enqueue()
3310 murb->transfer_buffer_length = rem > 0 ? rem : 4096; in oxu_urb_enqueue()
3311 murb->transfer_buffer = transfer_buffer + (num - 1) * 4096; in oxu_urb_enqueue()
3314 murb->complete = NULL; in oxu_urb_enqueue()
3316 ((struct oxu_murb *) murb)->main = urb; in oxu_urb_enqueue()
3317 ((struct oxu_murb *) murb)->last = 1; in oxu_urb_enqueue()
3337 spin_lock_irqsave(&oxu->lock, flags); in oxu_urb_dequeue()
3338 switch (usb_pipetype(urb->pipe)) { in oxu_urb_dequeue()
3342 qh = (struct ehci_qh *) urb->hcpriv; in oxu_urb_dequeue()
3349 qh = (struct ehci_qh *) urb->hcpriv; in oxu_urb_dequeue()
3352 switch (qh->qh_state) { in oxu_urb_dequeue()
3361 qh, qh->qh_state); in oxu_urb_dequeue()
3366 if (!list_empty(&qh->qtd_list) in oxu_urb_dequeue()
3367 && HC_IS_RUNNING(hcd->state)) { in oxu_urb_dequeue()
3371 spin_unlock_irqrestore(&oxu->lock, flags); in oxu_urb_dequeue()
3377 dev_err(hcd->self.controller, in oxu_urb_dequeue()
3386 spin_unlock_irqrestore(&oxu->lock, flags); in oxu_urb_dequeue()
3402 spin_lock_irqsave(&oxu->lock, flags); in oxu_endpoint_disable()
3403 qh = ep->hcpriv; in oxu_endpoint_disable()
3410 if (qh->hw_info1 == 0) { in oxu_endpoint_disable()
3415 if (!HC_IS_RUNNING(hcd->state)) in oxu_endpoint_disable()
3416 qh->qh_state = QH_STATE_IDLE; in oxu_endpoint_disable()
3417 switch (qh->qh_state) { in oxu_endpoint_disable()
3419 for (tmp = oxu->async->qh_next.qh; in oxu_endpoint_disable()
3421 tmp = tmp->qh_next.qh) in oxu_endpoint_disable()
3423 /* periodic qh self-unlinks on empty */ in oxu_endpoint_disable()
3430 spin_unlock_irqrestore(&oxu->lock, flags); in oxu_endpoint_disable()
3434 if (list_empty(&qh->qtd_list)) { in oxu_endpoint_disable()
3445 qh, ep->desc.bEndpointAddress, qh->qh_state, in oxu_endpoint_disable()
3446 list_empty(&qh->qtd_list) ? "" : "(has tds)"); in oxu_endpoint_disable()
3449 ep->hcpriv = NULL; in oxu_endpoint_disable()
3451 spin_unlock_irqrestore(&oxu->lock, flags); in oxu_endpoint_disable()
3458 return (readl(&oxu->regs->frame_index) >> 3) % in oxu_get_frame()
3459 oxu->periodic_size; in oxu_get_frame()
3471 if (!HC_IS_RUNNING(hcd->state)) in oxu_hub_status_data()
3474 /* init status to no-changes */ in oxu_hub_status_data()
3476 ports = HCS_N_PORTS(oxu->hcs_params); in oxu_hub_status_data()
3486 * PORT_POWER; that's surprising, but maybe within-spec. in oxu_hub_status_data()
3496 spin_lock_irqsave(&oxu->lock, flags); in oxu_hub_status_data()
3498 temp = readl(&oxu->regs->port_status[i]); in oxu_hub_status_data()
3503 * high-speed device is switched over to the companion in oxu_hub_status_data()
3508 oxu->reset_done[i] = 0; in oxu_hub_status_data()
3510 time_after_eq(jiffies, oxu->reset_done[i]))) { in oxu_hub_status_data()
3514 buf[1] |= 1 << (i - 7); in oxu_hub_status_data()
3519 spin_unlock_irqrestore(&oxu->lock, flags); in oxu_hub_status_data()
3543 int ports = HCS_N_PORTS(oxu->hcs_params); in oxu_hub_control()
3544 u32 __iomem *status_reg = &oxu->regs->port_status[wIndex - 1]; in oxu_hub_control()
3557 spin_lock_irqsave(&oxu->lock, flags); in oxu_hub_control()
3563 /* no hub-wide feature/status flags */ in oxu_hub_control()
3572 wIndex--; in oxu_hub_control()
3578 * the port-change status bits (especially in oxu_hub_control()
3598 oxu->reset_done[wIndex] = jiffies in oxu_hub_control()
3603 /* we auto-clear this feature */ in oxu_hub_control()
3606 if (HCS_PPC(oxu->hcs_params)) in oxu_hub_control()
3622 readl(&oxu->regs->command); /* unblock posted write */ in oxu_hub_control()
3629 /* no hub-wide feature/status flags */ in oxu_hub_control()
3635 wIndex--; in oxu_hub_control()
3651 if (!oxu->reset_done[wIndex]) { in oxu_hub_control()
3653 oxu->reset_done[wIndex] = jiffies in oxu_hub_control()
3656 mod_timer(&oxu_to_hcd(oxu)->rh_timer, in oxu_hub_control()
3657 oxu->reset_done[wIndex]); in oxu_hub_control()
3662 oxu->reset_done[wIndex])) { in oxu_hub_control()
3664 oxu->reset_done[wIndex] = 0; in oxu_hub_control()
3685 oxu->reset_done[wIndex])) { in oxu_hub_control()
3687 oxu->reset_done[wIndex] = 0; in oxu_hub_control()
3710 test_bit(wIndex, &oxu->companion_ports)) { in oxu_hub_control()
3714 oxu_dbg(oxu, "port %d --> companion\n", wIndex + 1); in oxu_hub_control()
3750 /* no hub-wide feature/status flags */ in oxu_hub_control()
3761 wIndex--; in oxu_hub_control()
3772 if (device_may_wakeup(&hcd->self.root_hub->dev)) in oxu_hub_control()
3777 if (HCS_PPC(oxu->hcs_params)) in oxu_hub_control()
3793 * usb 2.0 spec says 50 ms resets on root in oxu_hub_control()
3795 oxu->reset_done[wIndex] = jiffies in oxu_hub_control()
3804 * about the EHCI-specific stuff. in oxu_hub_control()
3818 readl(&oxu->regs->command); /* unblock posted writes */ in oxu_hub_control()
3824 retval = -EPIPE; in oxu_hub_control()
3826 spin_unlock_irqrestore(&oxu->lock, flags); in oxu_hub_control()
3840 if (time_before(jiffies, oxu->next_statechange)) in oxu_bus_suspend()
3843 port = HCS_N_PORTS(oxu->hcs_params); in oxu_bus_suspend()
3844 spin_lock_irq(&oxu->lock); in oxu_bus_suspend()
3847 if (HC_IS_RUNNING(hcd->state)) { in oxu_bus_suspend()
3849 hcd->state = HC_STATE_QUIESCING; in oxu_bus_suspend()
3851 oxu->command = readl(&oxu->regs->command); in oxu_bus_suspend()
3852 if (oxu->reclaim) in oxu_bus_suspend()
3853 oxu->reclaim_ready = 1; in oxu_bus_suspend()
3857 * any notion of "global" or bus-wide suspend. The driver has in oxu_bus_suspend()
3861 oxu->bus_suspended = 0; in oxu_bus_suspend()
3862 while (port--) { in oxu_bus_suspend()
3863 u32 __iomem *reg = &oxu->regs->port_status[port]; in oxu_bus_suspend()
3871 set_bit(port, &oxu->bus_suspended); in oxu_bus_suspend()
3875 if (device_may_wakeup(&hcd->self.root_hub->dev)) in oxu_bus_suspend()
3881 oxu_vdbg(oxu, "port %d, %08x -> %08x\n", in oxu_bus_suspend()
3887 spin_unlock_irq(&oxu->lock); in oxu_bus_suspend()
3888 /* turn off now-idle HC */ in oxu_bus_suspend()
3889 del_timer_sync(&oxu->watchdog); in oxu_bus_suspend()
3890 spin_lock_irq(&oxu->lock); in oxu_bus_suspend()
3892 hcd->state = HC_STATE_SUSPENDED; in oxu_bus_suspend()
3896 if (!device_may_wakeup(&hcd->self.root_hub->dev)) in oxu_bus_suspend()
3898 writel(mask, &oxu->regs->intr_enable); in oxu_bus_suspend()
3899 readl(&oxu->regs->intr_enable); in oxu_bus_suspend()
3901 oxu->next_statechange = jiffies + msecs_to_jiffies(10); in oxu_bus_suspend()
3902 spin_unlock_irq(&oxu->lock); in oxu_bus_suspend()
3913 if (time_before(jiffies, oxu->next_statechange)) in oxu_bus_resume()
3915 spin_lock_irq(&oxu->lock); in oxu_bus_resume()
3919 * could instead be restoring a swsusp snapshot -- so that BIOS was in oxu_bus_resume()
3923 temp = readl(&oxu->regs->intr_enable); in oxu_bus_resume()
3929 writel(0, &oxu->regs->intr_enable); in oxu_bus_resume()
3931 /* re-init operational registers */ in oxu_bus_resume()
3932 writel(0, &oxu->regs->segment); in oxu_bus_resume()
3933 writel(oxu->periodic_dma, &oxu->regs->frame_list); in oxu_bus_resume()
3934 writel((u32) oxu->async->qh_dma, &oxu->regs->async_next); in oxu_bus_resume()
3937 writel(oxu->command, &oxu->regs->command); in oxu_bus_resume()
3944 i = HCS_N_PORTS(oxu->hcs_params); in oxu_bus_resume()
3945 while (i--) { in oxu_bus_resume()
3946 temp = readl(&oxu->regs->port_status[i]); in oxu_bus_resume()
3949 if (test_bit(i, &oxu->bus_suspended) && (temp & PORT_SUSPEND)) { in oxu_bus_resume()
3950 oxu->reset_done[i] = jiffies + msecs_to_jiffies(20); in oxu_bus_resume()
3953 writel(temp, &oxu->regs->port_status[i]); in oxu_bus_resume()
3955 i = HCS_N_PORTS(oxu->hcs_params); in oxu_bus_resume()
3957 while (i--) { in oxu_bus_resume()
3958 temp = readl(&oxu->regs->port_status[i]); in oxu_bus_resume()
3959 if (test_bit(i, &oxu->bus_suspended) && (temp & PORT_SUSPEND)) { in oxu_bus_resume()
3961 writel(temp, &oxu->regs->port_status[i]); in oxu_bus_resume()
3965 (void) readl(&oxu->regs->command); in oxu_bus_resume()
3967 /* maybe re-activate the schedule(s) */ in oxu_bus_resume()
3969 if (oxu->async->qh_next.qh) in oxu_bus_resume()
3971 if (oxu->periodic_sched) in oxu_bus_resume()
3974 oxu->command |= temp; in oxu_bus_resume()
3975 writel(oxu->command, &oxu->regs->command); in oxu_bus_resume()
3978 oxu->next_statechange = jiffies + msecs_to_jiffies(5); in oxu_bus_resume()
3979 hcd->state = HC_STATE_RUNNING; in oxu_bus_resume()
3981 /* Now we can safely re-enable irqs */ in oxu_bus_resume()
3982 writel(INTR_MASK, &oxu->regs->intr_enable); in oxu_bus_resume()
3984 spin_unlock_irq(&oxu->lock); in oxu_bus_resume()
4081 "128-pin LQFP", in oxu_verify_id()
4082 "84-pin TFBGA", in oxu_verify_id()
4088 dev_info(&pdev->dev, "device ID %x\n", id); in oxu_verify_id()
4090 return -1; in oxu_verify_id()
4092 dev_info(&pdev->dev, "found device %x %s (%04x:%04x)\n", in oxu_verify_id()
4106 struct device *dev = &pdev->dev; in oxu_create()
4120 return ERR_PTR(-ENOMEM); in oxu_create()
4122 hcd->rsrc_start = memstart; in oxu_create()
4123 hcd->rsrc_len = memlen; in oxu_create()
4124 hcd->regs = base; in oxu_create()
4125 hcd->irq = irq; in oxu_create()
4126 hcd->state = HC_STATE_HALT; in oxu_create()
4129 oxu->is_otg = otg; in oxu_create()
4137 device_wakeup_enable(hcd->self.controller); in oxu_create()
4154 dev_err(&pdev->dev, "no devices found!\n"); in oxu_init()
4155 return -ENODEV; in oxu_init()
4161 dev_err(&pdev->dev, "cannot create OTG controller!\n"); in oxu_init()
4165 info->hcd[0] = hcd; in oxu_init()
4170 dev_err(&pdev->dev, "cannot create SPH controller!\n"); in oxu_init()
4174 info->hcd[1] = hcd; in oxu_init()
4182 usb_remove_hcd(info->hcd[0]); in oxu_init()
4183 usb_put_hcd(info->hcd[0]); in oxu_init()
4198 return -ENODEV; in oxu_drv_probe()
4206 dev_dbg(&pdev->dev, "IRQ resource %d\n", irq); in oxu_drv_probe()
4213 memstart = res->start; in oxu_drv_probe()
4218 dev_err(&pdev->dev, "error setting irq type\n"); in oxu_drv_probe()
4219 ret = -EFAULT; in oxu_drv_probe()
4226 info = devm_kzalloc(&pdev->dev, sizeof(struct oxu_info), GFP_KERNEL); in oxu_drv_probe()
4228 ret = -EFAULT; in oxu_drv_probe()
4235 dev_dbg(&pdev->dev, "cannot init USB devices\n"); in oxu_drv_probe()
4239 dev_info(&pdev->dev, "devices enabled and running\n"); in oxu_drv_probe()
4245 dev_err(&pdev->dev, "init %s fail, %d\n", dev_name(&pdev->dev), ret); in oxu_drv_probe()
4259 oxu_remove(pdev, info->hcd[0]); in oxu_drv_remove()
4260 oxu_remove(pdev, info->hcd[1]); in oxu_drv_remove()
4297 .name = "oxu210hp-hcd",
4304 MODULE_DESCRIPTION("Oxford OXU210HP HCD driver - ver. " DRIVER_VERSION);