Lines Matching +full:throttle +full:- +full:period +full:- +full:us
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 */
229 * See Fig 3-6 "Queue Element Transfer Descriptor Block Diagram".
255 /* the rest is HCD-private */
268 /* mask NakCnt+T in qh->hw_alt_next */
273 /* Type tag from {qh, itd, sitd, fstn}->hw_next */
302 * See Fig 3-7 "Queue Head Structure Layout".
318 __le32 hw_current; /* qtd list - see EHCI 3.6.4 */
327 /* the rest is HCD-private */
350 unsigned short period; /* polling interval */ member
369 /* 2 host controllers are enabled - total size <= 28 kbytes */
483 dev_dbg(oxu_to_hcd(oxu)->self.controller , fmt , ## args)
485 dev_err(oxu_to_hcd(oxu)->self.controller , fmt , ## args)
487 dev_info(oxu_to_hcd(oxu)->self.controller , fmt , ## args)
500 return (struct oxu_hcd *) (hcd->hcd_priv); in hcd_to_oxu()
557 "%s%scommand %06x %s=%d ithresh=%d%s%s%s%s period=%s%s %s", in dbg_command_buf()
657 MODULE_PARM_DESC(log2_irq_thresh, "log2 IRQ latency, 1-64 microframes");
662 MODULE_PARM_DESC(park, "park setting; 1-3 back-to-back async packets");
693 clear_bit(action, &oxu->actions); in timer_action_done()
699 if (!test_and_set_bit(action, &oxu->actions)) { in timer_action()
724 && t > oxu->watchdog.expires in timer_action()
725 && timer_pending(&oxu->watchdog)) in timer_action()
727 mod_timer(&oxu->watchdog, t); in timer_action()
732 * handshake - spin reading hc until handshake completes or fails
742 * hardware flakeout), or the register reads as all-ones (hardware removed).
759 return -ENODEV; in handshake()
767 u32 temp = readl(&oxu->regs->status); in ehci_halt()
770 writel(0, &oxu->regs->intr_enable); in ehci_halt()
775 temp = readl(&oxu->regs->command); in ehci_halt()
777 writel(temp, &oxu->regs->command); in ehci_halt()
778 return handshake(oxu, &oxu->regs->status, in ehci_halt()
788 reg_ptr = (u32 __iomem *)(((u8 __iomem *)oxu->regs) + 0x68); in tdi_reset()
794 /* Reset a non-running (STS_HALT == 1) controller */
798 u32 command = readl(&oxu->regs->command); in ehci_reset()
802 writel(command, &oxu->regs->command); in ehci_reset()
803 oxu_to_hcd(oxu)->state = HC_STATE_HALT; in ehci_reset()
804 oxu->next_statechange = jiffies; in ehci_reset()
805 retval = handshake(oxu, &oxu->regs->command, in ehci_reset()
822 BUG_ON(!HC_IS_RUNNING(oxu_to_hcd(oxu)->state)); in ehci_quiesce()
826 temp = readl(&oxu->regs->command) << 10; in ehci_quiesce()
828 if (handshake(oxu, &oxu->regs->status, STS_ASS | STS_PSS, in ehci_quiesce()
830 oxu_to_hcd(oxu)->state = HC_STATE_HALT; in ehci_quiesce()
835 temp = readl(&oxu->regs->command); in ehci_quiesce()
837 writel(temp, &oxu->regs->command); in ehci_quiesce()
840 if (handshake(oxu, &oxu->regs->status, STS_ASS | STS_PSS, in ehci_quiesce()
842 oxu_to_hcd(oxu)->state = HC_STATE_HALT; in ehci_quiesce()
851 oxu->reset_done[index] = 0; in check_reset_complete()
855 /* if reset finished and it's still not enabled -- handoff */ in check_reset_complete()
869 int ports = HCS_N_PORTS(oxu->hcs_params); in ehci_hub_descriptor()
872 desc->bDescriptorType = USB_DT_HUB; in ehci_hub_descriptor()
873 desc->bPwrOn2PwrGood = 10; /* oxu 1.0, 2.3.9 says 20ms max */ in ehci_hub_descriptor()
874 desc->bHubContrCurrent = 0; in ehci_hub_descriptor()
876 desc->bNbrPorts = ports; in ehci_hub_descriptor()
878 desc->bDescLength = 7 + 2 * temp; in ehci_hub_descriptor()
881 memset(&desc->u.hs.DeviceRemovable[0], 0, temp); in ehci_hub_descriptor()
882 memset(&desc->u.hs.DeviceRemovable[temp], 0xff, temp); in ehci_hub_descriptor()
884 temp = HUB_CHAR_INDV_PORT_OCPM; /* per-port overcurrent reporting */ in ehci_hub_descriptor()
885 if (HCS_PPC(oxu->hcs_params)) in ehci_hub_descriptor()
886 temp |= HUB_CHAR_INDV_PORT_LPSM; /* per-port power control */ in ehci_hub_descriptor()
889 desc->wHubCharacteristics = (__force __u16)cpu_to_le16(temp); in ehci_hub_descriptor()
893 /* Allocate an OXU210HP on-chip memory data buffer
895 * An on-chip memory data buffer is required for each OXU210HP USB transfer.
896 * Each transfer descriptor has one or more on-chip memory data buffers.
904 * len=0. This is a waste of on-chip memory and should be fix. Then this
916 return -ENOMEM; in oxu_buf_alloc()
919 spin_lock(&oxu->mem_lock); in oxu_buf_alloc()
922 n_blocks = (len + BUFFER_SIZE - 1) / BUFFER_SIZE; in oxu_buf_alloc()
930 i += max(a_blocks, (int)oxu->db_used[i])) { in oxu_buf_alloc()
934 if (oxu->db_used[i + j]) in oxu_buf_alloc()
941 qtd->buffer = (void *) &oxu->mem->db_pool[i]; in oxu_buf_alloc()
942 qtd->buffer_dma = virt_to_phys(qtd->buffer); in oxu_buf_alloc()
944 qtd->qtd_buffer_len = BUFFER_SIZE * a_blocks; in oxu_buf_alloc()
945 oxu->db_used[i] = a_blocks; in oxu_buf_alloc()
947 spin_unlock(&oxu->mem_lock); in oxu_buf_alloc()
954 spin_unlock(&oxu->mem_lock); in oxu_buf_alloc()
956 return -ENOMEM; in oxu_buf_alloc()
963 spin_lock(&oxu->mem_lock); in oxu_buf_free()
965 index = (qtd->buffer - (void *) &oxu->mem->db_pool[0]) in oxu_buf_free()
967 oxu->db_used[index] = 0; in oxu_buf_free()
968 qtd->qtd_buffer_len = 0; in oxu_buf_free()
969 qtd->buffer_dma = 0; in oxu_buf_free()
970 qtd->buffer = NULL; in oxu_buf_free()
972 spin_unlock(&oxu->mem_lock); in oxu_buf_free()
978 qtd->qtd_dma = dma; in ehci_qtd_init()
979 qtd->hw_token = cpu_to_le32(QTD_STS_HALT); in ehci_qtd_init()
980 qtd->hw_next = EHCI_LIST_END; in ehci_qtd_init()
981 qtd->hw_alt_next = EHCI_LIST_END; in ehci_qtd_init()
982 INIT_LIST_HEAD(&qtd->qtd_list); in ehci_qtd_init()
989 if (qtd->buffer) in oxu_qtd_free()
992 spin_lock(&oxu->mem_lock); in oxu_qtd_free()
994 index = qtd - &oxu->mem->qtd_pool[0]; in oxu_qtd_free()
995 oxu->qtd_used[index] = 0; in oxu_qtd_free()
997 spin_unlock(&oxu->mem_lock); in oxu_qtd_free()
1005 spin_lock(&oxu->mem_lock); in ehci_qtd_alloc()
1008 if (!oxu->qtd_used[i]) in ehci_qtd_alloc()
1012 qtd = (struct ehci_qtd *) &oxu->mem->qtd_pool[i]; in ehci_qtd_alloc()
1015 qtd->hw_token = cpu_to_le32(QTD_STS_HALT); in ehci_qtd_alloc()
1016 qtd->hw_next = EHCI_LIST_END; in ehci_qtd_alloc()
1017 qtd->hw_alt_next = EHCI_LIST_END; in ehci_qtd_alloc()
1018 INIT_LIST_HEAD(&qtd->qtd_list); in ehci_qtd_alloc()
1020 qtd->qtd_dma = virt_to_phys(qtd); in ehci_qtd_alloc()
1022 oxu->qtd_used[i] = 1; in ehci_qtd_alloc()
1025 spin_unlock(&oxu->mem_lock); in ehci_qtd_alloc()
1034 spin_lock(&oxu->mem_lock); in oxu_qh_free()
1036 index = qh - &oxu->mem->qh_pool[0]; in oxu_qh_free()
1037 oxu->qh_used[index] = 0; in oxu_qh_free()
1039 spin_unlock(&oxu->mem_lock); in oxu_qh_free()
1045 struct oxu_hcd *oxu = qh->oxu; in qh_destroy()
1048 if (!list_empty(&qh->qtd_list) || qh->qh_next.ptr) { in qh_destroy()
1052 if (qh->dummy) in qh_destroy()
1053 oxu_qtd_free(oxu, qh->dummy); in qh_destroy()
1062 spin_lock(&oxu->mem_lock); in oxu_qh_alloc()
1065 if (!oxu->qh_used[i]) in oxu_qh_alloc()
1069 qh = (struct ehci_qh *) &oxu->mem->qh_pool[i]; in oxu_qh_alloc()
1072 kref_init(&qh->kref); in oxu_qh_alloc()
1073 qh->oxu = oxu; in oxu_qh_alloc()
1074 qh->qh_dma = virt_to_phys(qh); in oxu_qh_alloc()
1075 INIT_LIST_HEAD(&qh->qtd_list); in oxu_qh_alloc()
1078 qh->dummy = ehci_qtd_alloc(oxu); in oxu_qh_alloc()
1079 if (qh->dummy == NULL) { in oxu_qh_alloc()
1081 oxu->qh_used[i] = 0; in oxu_qh_alloc()
1086 oxu->qh_used[i] = 1; in oxu_qh_alloc()
1089 spin_unlock(&oxu->mem_lock); in oxu_qh_alloc()
1097 kref_get(&qh->kref); in qh_get()
1103 kref_put(&qh->kref, qh_destroy); in qh_put()
1110 spin_lock(&oxu->mem_lock); in oxu_murb_free()
1112 index = murb - &oxu->murb_pool[0]; in oxu_murb_free()
1113 oxu->murb_used[index] = 0; in oxu_murb_free()
1115 spin_unlock(&oxu->mem_lock); in oxu_murb_free()
1124 spin_lock(&oxu->mem_lock); in oxu_murb_alloc()
1127 if (!oxu->murb_used[i]) in oxu_murb_alloc()
1131 murb = &(oxu->murb_pool)[i]; in oxu_murb_alloc()
1133 oxu->murb_used[i] = 1; in oxu_murb_alloc()
1136 spin_unlock(&oxu->mem_lock); in oxu_murb_alloc()
1147 kfree(oxu->murb_pool); in ehci_mem_cleanup()
1148 oxu->murb_pool = NULL; in ehci_mem_cleanup()
1150 if (oxu->async) in ehci_mem_cleanup()
1151 qh_put(oxu->async); in ehci_mem_cleanup()
1152 oxu->async = NULL; in ehci_mem_cleanup()
1154 del_timer(&oxu->urb_timer); in ehci_mem_cleanup()
1156 oxu->periodic = NULL; in ehci_mem_cleanup()
1159 kfree(oxu->pshadow); in ehci_mem_cleanup()
1160 oxu->pshadow = NULL; in ehci_mem_cleanup()
1169 for (i = 0; i < oxu->periodic_size; i++) in ehci_mem_init()
1170 oxu->mem->frame_list[i] = EHCI_LIST_END; in ehci_mem_init()
1172 oxu->qh_used[i] = 0; in ehci_mem_init()
1174 oxu->qtd_used[i] = 0; in ehci_mem_init()
1176 oxu->murb_pool = kcalloc(MURB_NUM, sizeof(struct oxu_murb), flags); in ehci_mem_init()
1177 if (!oxu->murb_pool) in ehci_mem_init()
1181 oxu->murb_used[i] = 0; in ehci_mem_init()
1183 oxu->async = oxu_qh_alloc(oxu); in ehci_mem_init()
1184 if (!oxu->async) in ehci_mem_init()
1187 oxu->periodic = (__le32 *) &oxu->mem->frame_list; in ehci_mem_init()
1188 oxu->periodic_dma = virt_to_phys(oxu->periodic); in ehci_mem_init()
1190 for (i = 0; i < oxu->periodic_size; i++) in ehci_mem_init()
1191 oxu->periodic[i] = EHCI_LIST_END; in ehci_mem_init()
1194 oxu->pshadow = kcalloc(oxu->periodic_size, sizeof(void *), flags); in ehci_mem_init()
1195 if (oxu->pshadow != NULL) in ehci_mem_init()
1201 return -ENOMEM; in ehci_mem_init()
1213 qtd->hw_buf[0] = cpu_to_le32((u32)addr); in qtd_fill()
1214 qtd->hw_buf_hi[0] = cpu_to_le32((u32)(addr >> 32)); in qtd_fill()
1215 count = 0x1000 - (buf & 0x0fff); /* rest of that page */ in qtd_fill()
1222 /* per-qtd limit: from 16K to 20K (best alignment) */ in qtd_fill()
1225 qtd->hw_buf[i] = cpu_to_le32((u32)addr); in qtd_fill()
1226 qtd->hw_buf_hi[i] = cpu_to_le32((u32)(addr >> 32)); in qtd_fill()
1236 count -= (count % maxpacket); in qtd_fill()
1238 qtd->hw_token = cpu_to_le32((count << 16) | token); in qtd_fill()
1239 qtd->length = count; in qtd_fill()
1248 BUG_ON(qh->qh_state != QH_STATE_IDLE); in qh_update()
1250 qh->hw_qtd_next = QTD_NEXT(qtd->qtd_dma); in qh_update()
1251 qh->hw_alt_next = EHCI_LIST_END; in qh_update()
1255 * and set the pseudo-toggle in udev. Only usb_clear_halt() will in qh_update()
1258 if (!(qh->hw_info1 & cpu_to_le32(1 << 14))) { in qh_update()
1261 is_out = !(qtd->hw_token & cpu_to_le32(1 << 8)); in qh_update()
1262 epnum = (le32_to_cpup(&qh->hw_info1) >> 8) & 0x0f; in qh_update()
1263 if (unlikely(!usb_gettoggle(qh->dev, epnum, is_out))) { in qh_update()
1264 qh->hw_token &= ~cpu_to_le32(QTD_TOGGLE); in qh_update()
1265 usb_settoggle(qh->dev, epnum, is_out, 1); in qh_update()
1271 qh->hw_token &= cpu_to_le32(QTD_TOGGLE | QTD_STS_PING); in qh_update()
1275 * overlay, so qh->hw_token wrongly becomes inactive/halted), only fault
1282 if (list_empty(&qh->qtd_list)) in qh_refresh()
1283 qtd = qh->dummy; in qh_refresh()
1285 qtd = list_entry(qh->qtd_list.next, in qh_refresh()
1288 if (cpu_to_le32(qtd->qtd_dma) == qh->hw_current) in qh_refresh()
1301 urb->actual_length += length - QTD_LENGTH(token); in qtd_copy_status()
1304 if (unlikely(urb->status != -EINPROGRESS)) in qtd_copy_status()
1309 urb->status = -EREMOTEIO; in qtd_copy_status()
1315 urb->status = -EOVERFLOW; in qtd_copy_status()
1317 /* fs/ls interrupt xfer missed the complete-split */ in qtd_copy_status()
1318 urb->status = -EPROTO; in qtd_copy_status()
1320 urb->status = (QTD_PID(token) == 1) /* IN ? */ in qtd_copy_status()
1321 ? -ENOSR /* hc couldn't read data */ in qtd_copy_status()
1322 : -ECOMM; /* hc couldn't write data */ in qtd_copy_status()
1326 urb->status = -EPIPE; in qtd_copy_status()
1329 urb->dev->devpath, in qtd_copy_status()
1330 usb_pipeendpoint(urb->pipe), in qtd_copy_status()
1331 usb_pipein(urb->pipe) ? "in" : "out"); in qtd_copy_status()
1332 urb->status = -EPROTO; in qtd_copy_status()
1334 /* CERR nonzero + no errors + halt --> stall */ in qtd_copy_status()
1336 urb->status = -EPIPE; in qtd_copy_status()
1338 urb->status = -EPROTO; in qtd_copy_status()
1340 oxu_vdbg(oxu, "dev%d ep%d%s qtd token %08x --> status %d\n", in qtd_copy_status()
1341 usb_pipedevice(urb->pipe), in qtd_copy_status()
1342 usb_pipeendpoint(urb->pipe), in qtd_copy_status()
1343 usb_pipein(urb->pipe) ? "in" : "out", in qtd_copy_status()
1344 token, urb->status); in qtd_copy_status()
1349 __releases(oxu->lock) in ehci_urb_done()
1350 __acquires(oxu->lock) in ehci_urb_done()
1352 if (likely(urb->hcpriv != NULL)) { in ehci_urb_done()
1353 struct ehci_qh *qh = (struct ehci_qh *) urb->hcpriv; in ehci_urb_done()
1355 /* S-mask in a QH means it's an interrupt urb */ in ehci_urb_done()
1356 if ((qh->hw_info2 & cpu_to_le32(QH_SMASK)) != 0) { in ehci_urb_done()
1358 /* ... update hc-wide periodic stats (for usbfs) */ in ehci_urb_done()
1359 oxu_to_hcd(oxu)->self.bandwidth_int_reqs--; in ehci_urb_done()
1364 urb->hcpriv = NULL; in ehci_urb_done()
1365 switch (urb->status) { in ehci_urb_done()
1366 case -EINPROGRESS: /* success */ in ehci_urb_done()
1367 urb->status = 0; in ehci_urb_done()
1371 case -EREMOTEIO: /* fault or normal */ in ehci_urb_done()
1372 if (!(urb->transfer_flags & URB_SHORT_NOT_OK)) in ehci_urb_done()
1373 urb->status = 0; in ehci_urb_done()
1375 case -ECONNRESET: /* canceled */ in ehci_urb_done()
1376 case -ENOENT: in ehci_urb_done()
1382 __func__, urb->dev->devpath, urb, in ehci_urb_done()
1383 usb_pipeendpoint(urb->pipe), in ehci_urb_done()
1384 usb_pipein(urb->pipe) ? "in" : "out", in ehci_urb_done()
1385 urb->status, in ehci_urb_done()
1386 urb->actual_length, urb->transfer_buffer_length); in ehci_urb_done()
1390 spin_unlock(&oxu->lock); in ehci_urb_done()
1391 usb_hcd_giveback_urb(oxu_to_hcd(oxu), urb, urb->status); in ehci_urb_done()
1392 spin_lock(&oxu->lock); in ehci_urb_done()
1404 * Chases up to qh->hw_current. Returns number of completions called,
1409 struct ehci_qtd *last = NULL, *end = qh->dummy; in qh_completions()
1417 if (unlikely(list_empty(&qh->qtd_list))) in qh_completions()
1426 state = qh->qh_state; in qh_completions()
1427 qh->qh_state = QH_STATE_COMPLETING; in qh_completions()
1430 /* remove de-activated QTDs from front of queue. in qh_completions()
1435 list_for_each_entry_safe(qtd, tmp, &qh->qtd_list, qtd_list) { in qh_completions()
1439 urb = qtd->urb; in qh_completions()
1443 if (likely(last->urb != urb)) { in qh_completions()
1444 if (last->urb->complete == NULL) { in qh_completions()
1445 murb = (struct oxu_murb *) last->urb; in qh_completions()
1446 last->urb = murb->main; in qh_completions()
1447 if (murb->last) { in qh_completions()
1448 ehci_urb_done(oxu, last->urb); in qh_completions()
1453 ehci_urb_done(oxu, last->urb); in qh_completions()
1467 token = le32_to_cpu(qtd->hw_token); in qh_completions()
1469 /* always clean up qtds the hc de-activated */ in qh_completions()
1479 !(qtd->hw_alt_next & EHCI_LIST_END)) { in qh_completions()
1486 HC_IS_RUNNING(oxu_to_hcd(oxu)->state))) { in qh_completions()
1492 if (unlikely(!HC_IS_RUNNING(oxu_to_hcd(oxu)->state))) in qh_completions()
1493 urb->status = -ESHUTDOWN; in qh_completions()
1499 if (likely(urb->status == -EINPROGRESS)) in qh_completions()
1511 && cpu_to_le32(qtd->qtd_dma) in qh_completions()
1512 == qh->hw_current) in qh_completions()
1513 token = le32_to_cpu(qh->hw_token); in qh_completions()
1519 if ((HALT_BIT & qh->hw_token) == 0) { in qh_completions()
1521 qh->hw_token |= HALT_BIT; in qh_completions()
1527 qtd_copy_status(oxu, urb->complete ? in qh_completions()
1528 urb : ((struct oxu_murb *) urb)->main, in qh_completions()
1529 qtd->length, token); in qh_completions()
1530 if ((usb_pipein(qtd->urb->pipe)) && in qh_completions()
1531 (NULL != qtd->transfer_buffer)) in qh_completions()
1532 memcpy(qtd->transfer_buffer, qtd->buffer, qtd->length); in qh_completions()
1533 do_status = (urb->status == -EREMOTEIO) in qh_completions()
1534 && usb_pipecontrol(urb->pipe); in qh_completions()
1536 if (stopped && qtd->qtd_list.prev != &qh->qtd_list) { in qh_completions()
1537 last = list_entry(qtd->qtd_list.prev, in qh_completions()
1539 last->hw_next = qtd->hw_next; in qh_completions()
1541 list_del(&qtd->qtd_list); in qh_completions()
1547 if (last->urb->complete == NULL) { in qh_completions()
1548 murb = (struct oxu_murb *) last->urb; in qh_completions()
1549 last->urb = murb->main; in qh_completions()
1550 if (murb->last) { in qh_completions()
1551 ehci_urb_done(oxu, last->urb); in qh_completions()
1556 ehci_urb_done(oxu, last->urb); in qh_completions()
1563 qh->qh_state = state; in qh_completions()
1569 if (stopped != 0 || qh->hw_qtd_next == EHCI_LIST_END) { in qh_completions()
1579 & qh->hw_info2) != 0) { in qh_completions()
1606 list_del(&qtd->qtd_list); in qtd_list_free()
1632 list_add_tail(&qtd->qtd_list, head); in qh_urb_transaction()
1633 qtd->urb = urb; in qh_urb_transaction()
1639 len = urb->transfer_buffer_length; in qh_urb_transaction()
1640 is_input = usb_pipein(urb->pipe); in qh_urb_transaction()
1641 if (!urb->transfer_buffer && urb->transfer_buffer_length && is_input) in qh_urb_transaction()
1642 urb->transfer_buffer = phys_to_virt(urb->transfer_dma); in qh_urb_transaction()
1644 if (usb_pipecontrol(urb->pipe)) { in qh_urb_transaction()
1650 qtd_fill(qtd, qtd->buffer_dma, sizeof(struct usb_ctrlrequest), in qh_urb_transaction()
1652 memcpy(qtd->buffer, qtd->urb->setup_packet, in qh_urb_transaction()
1661 qtd->urb = urb; in qh_urb_transaction()
1662 qtd_prev->hw_next = QTD_NEXT(qtd->qtd_dma); in qh_urb_transaction()
1663 list_add_tail(&qtd->qtd_list, head); in qh_urb_transaction()
1678 buf = qtd->buffer_dma; in qh_urb_transaction()
1679 transfer_buf = urb->transfer_buffer; in qh_urb_transaction()
1682 memcpy(qtd->buffer, qtd->urb->transfer_buffer, len); in qh_urb_transaction()
1688 maxpacket = usb_maxpacket(urb->dev, urb->pipe); in qh_urb_transaction()
1699 qtd->transfer_buffer = transfer_buf; in qh_urb_transaction()
1700 len -= this_qtd_len; in qh_urb_transaction()
1704 qtd->hw_alt_next = oxu->async->hw_alt_next; in qh_urb_transaction()
1707 if ((maxpacket & (this_qtd_len + (maxpacket - 1))) == 0) in qh_urb_transaction()
1722 qtd->urb = urb; in qh_urb_transaction()
1723 qtd_prev->hw_next = QTD_NEXT(qtd->qtd_dma); in qh_urb_transaction()
1724 list_add_tail(&qtd->qtd_list, head); in qh_urb_transaction()
1730 if (likely((urb->transfer_flags & URB_SHORT_NOT_OK) == 0 in qh_urb_transaction()
1731 || usb_pipecontrol(urb->pipe))) in qh_urb_transaction()
1732 qtd->hw_alt_next = EHCI_LIST_END; in qh_urb_transaction()
1738 if (likely(urb->transfer_buffer_length != 0)) { in qh_urb_transaction()
1741 if (usb_pipecontrol(urb->pipe)) { in qh_urb_transaction()
1743 token ^= 0x0100; /* "in" <--> "out" */ in qh_urb_transaction()
1745 } else if (usb_pipebulk(urb->pipe) in qh_urb_transaction()
1746 && (urb->transfer_flags & URB_ZERO_PACKET) in qh_urb_transaction()
1747 && !(urb->transfer_buffer_length % maxpacket)) { in qh_urb_transaction()
1755 qtd->urb = urb; in qh_urb_transaction()
1756 qtd_prev->hw_next = QTD_NEXT(qtd->qtd_dma); in qh_urb_transaction()
1757 list_add_tail(&qtd->qtd_list, head); in qh_urb_transaction()
1765 qtd->hw_token |= cpu_to_le32(QTD_IOC); in qh_urb_transaction()
1777 * just one microframe in the s-mask. For split interrupt transactions
1778 * there are additional complications: c-mask, maybe FSTNs.
1794 info1 |= usb_pipeendpoint(urb->pipe) << 8; in qh_make()
1795 info1 |= usb_pipedevice(urb->pipe) << 0; in qh_make()
1797 is_input = usb_pipein(urb->pipe); in qh_make()
1798 type = usb_pipetype(urb->pipe); in qh_make()
1799 maxp = usb_maxpacket(urb->dev, urb->pipe); in qh_make()
1802 * - allowing for high bandwidth, how many nsec/uframe are used? in qh_make()
1803 * - split transactions need a second CSPLIT uframe; same question in qh_make()
1804 * - splits also need a schedule gap (for full/low speed I/O) in qh_make()
1805 * - qh has a polling interval in qh_make()
1810 qh->usecs = NS_TO_US(usb_calc_bus_time(USB_SPEED_HIGH, in qh_make()
1813 qh->start = NO_FRAME; in qh_make()
1815 if (urb->dev->speed == USB_SPEED_HIGH) { in qh_make()
1816 qh->c_usecs = 0; in qh_make()
1817 qh->gap_uf = 0; in qh_make()
1819 qh->period = urb->interval >> 3; in qh_make()
1820 if (qh->period == 0 && urb->interval != 1) { in qh_make()
1825 oxu_dbg(oxu, "intr period %d uframes, NYET!\n", in qh_make()
1826 urb->interval); in qh_make()
1830 struct usb_tt *tt = urb->dev->tt; in qh_make()
1834 qh->gap_uf = 1 + usb_calc_bus_time(urb->dev->speed, in qh_make()
1839 qh->c_usecs = qh->usecs + HS_USECS(0); in qh_make()
1840 qh->usecs = HS_USECS(1); in qh_make()
1842 qh->usecs += HS_USECS(1); in qh_make()
1843 qh->c_usecs = HS_USECS(0); in qh_make()
1846 think_time = tt ? tt->think_time : 0; in qh_make()
1847 qh->tt_usecs = NS_TO_US(think_time + in qh_make()
1848 usb_calc_bus_time(urb->dev->speed, in qh_make()
1850 qh->period = urb->interval; in qh_make()
1855 qh->dev = urb->dev; in qh_make()
1858 switch (urb->dev->speed) { in qh_make()
1874 info2 |= urb->dev->ttport << 23; in qh_make()
1876 /* NOTE: if (PIPE_INTERRUPT) { scheduler sets c-mask } */ in qh_make()
1897 oxu_dbg(oxu, "bogus dev %p speed %d\n", urb->dev, urb->dev->speed); in qh_make()
1903 /* NOTE: if (PIPE_INTERRUPT) { scheduler sets s-mask } */ in qh_make()
1906 qh->qh_state = QH_STATE_IDLE; in qh_make()
1907 qh->hw_info1 = cpu_to_le32(info1); in qh_make()
1908 qh->hw_info2 = cpu_to_le32(info2); in qh_make()
1909 usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), !is_input, 1); in qh_make()
1918 __le32 dma = QH_NEXT(qh->qh_dma); in qh_link_async()
1922 head = oxu->async; in qh_link_async()
1924 if (!head->qh_next.qh) { in qh_link_async()
1925 u32 cmd = readl(&oxu->regs->command); in qh_link_async()
1929 (void)handshake(oxu, &oxu->regs->status, in qh_link_async()
1932 writel(cmd, &oxu->regs->command); in qh_link_async()
1933 oxu_to_hcd(oxu)->state = HC_STATE_RUNNING; in qh_link_async()
1939 if (qh->qh_state == QH_STATE_IDLE) in qh_link_async()
1943 qh->qh_next = head->qh_next; in qh_link_async()
1944 qh->hw_next = head->hw_next; in qh_link_async()
1947 head->qh_next.qh = qh; in qh_link_async()
1948 head->hw_next = dma; in qh_link_async()
1950 qh->qh_state = QH_STATE_LINKED; in qh_link_async()
1970 /* can't sleep here, we have oxu->lock... */ in qh_append_tds()
1980 qtd = list_entry(qtd_list->next, struct ehci_qtd, in qh_append_tds()
1987 if (usb_pipedevice(urb->pipe) == 0) in qh_append_tds()
1988 qh->hw_info1 &= ~QH_ADDR_MASK; in qh_append_tds()
2004 token = qtd->hw_token; in qh_append_tds()
2005 qtd->hw_token = HALT_BIT; in qh_append_tds()
2007 dummy = qh->dummy; in qh_append_tds()
2009 dma = dummy->qtd_dma; in qh_append_tds()
2011 dummy->qtd_dma = dma; in qh_append_tds()
2013 list_del(&qtd->qtd_list); in qh_append_tds()
2014 list_add(&dummy->qtd_list, qtd_list); in qh_append_tds()
2015 list_splice(qtd_list, qh->qtd_list.prev); in qh_append_tds()
2017 ehci_qtd_init(qtd, qtd->qtd_dma); in qh_append_tds()
2018 qh->dummy = qtd; in qh_append_tds()
2021 dma = qtd->qtd_dma; in qh_append_tds()
2022 qtd = list_entry(qh->qtd_list.prev, in qh_append_tds()
2024 qtd->hw_next = QTD_NEXT(dma); in qh_append_tds()
2027 dummy->hw_token = (token & ~(0x80)); in qh_append_tds()
2029 dummy->hw_token = token; in qh_append_tds()
2031 urb->hcpriv = qh_get(qh); in qh_append_tds()
2040 int epnum = urb->ep->desc.bEndpointAddress; in submit_async()
2047 qtd = list_entry(qtd_list->next, struct ehci_qtd, qtd_list); in submit_async()
2050 __func__, urb->dev->devpath, urb, in submit_async()
2052 urb->transfer_buffer_length, in submit_async()
2053 qtd, urb->ep->hcpriv); in submit_async()
2056 spin_lock_irqsave(&oxu->lock, flags); in submit_async()
2058 rc = -ESHUTDOWN; in submit_async()
2062 qh = qh_append_tds(oxu, urb, qtd_list, epnum, &urb->ep->hcpriv); in submit_async()
2064 rc = -ENOMEM; in submit_async()
2071 if (likely(qh->qh_state == QH_STATE_IDLE)) in submit_async()
2074 spin_unlock_irqrestore(&oxu->lock, flags); in submit_async()
2084 struct ehci_qh *qh = oxu->reclaim; in end_unlink_async()
2089 qh->qh_state = QH_STATE_IDLE; in end_unlink_async()
2090 qh->qh_next.qh = NULL; in end_unlink_async()
2094 next = qh->reclaim; in end_unlink_async()
2095 oxu->reclaim = next; in end_unlink_async()
2096 oxu->reclaim_ready = 0; in end_unlink_async()
2097 qh->reclaim = NULL; in end_unlink_async()
2101 if (!list_empty(&qh->qtd_list) in end_unlink_async()
2102 && HC_IS_RUNNING(oxu_to_hcd(oxu)->state)) in end_unlink_async()
2110 if (HC_IS_RUNNING(oxu_to_hcd(oxu)->state) in end_unlink_async()
2111 && oxu->async->qh_next.qh == NULL) in end_unlink_async()
2116 oxu->reclaim = NULL; in end_unlink_async()
2122 /* caller must own oxu->lock */
2126 int cmd = readl(&oxu->regs->command); in start_unlink_async()
2130 assert_spin_locked(&oxu->lock); in start_unlink_async()
2131 BUG_ON(oxu->reclaim || (qh->qh_state != QH_STATE_LINKED in start_unlink_async()
2132 && qh->qh_state != QH_STATE_UNLINK_WAIT)); in start_unlink_async()
2136 if (unlikely(qh == oxu->async)) { in start_unlink_async()
2138 if (oxu_to_hcd(oxu)->state != HC_STATE_HALT in start_unlink_async()
2139 && !oxu->reclaim) { in start_unlink_async()
2141 writel(cmd & ~CMD_ASE, &oxu->regs->command); in start_unlink_async()
2149 qh->qh_state = QH_STATE_UNLINK; in start_unlink_async()
2150 oxu->reclaim = qh = qh_get(qh); in start_unlink_async()
2152 prev = oxu->async; in start_unlink_async()
2153 while (prev->qh_next.qh != qh) in start_unlink_async()
2154 prev = prev->qh_next.qh; in start_unlink_async()
2156 prev->hw_next = qh->hw_next; in start_unlink_async()
2157 prev->qh_next = qh->qh_next; in start_unlink_async()
2160 if (unlikely(oxu_to_hcd(oxu)->state == HC_STATE_HALT)) { in start_unlink_async()
2161 /* if (unlikely(qh->reclaim != 0)) in start_unlink_async()
2168 oxu->reclaim_ready = 0; in start_unlink_async()
2170 writel(cmd, &oxu->regs->command); in start_unlink_async()
2171 (void) readl(&oxu->regs->command); in start_unlink_async()
2180 if (!++(oxu->stamp)) in scan_async()
2181 oxu->stamp++; in scan_async()
2184 qh = oxu->async->qh_next.qh; in scan_async()
2188 if (!list_empty(&qh->qtd_list) in scan_async()
2189 && qh->stamp != oxu->stamp) { in scan_async()
2198 qh->stamp = oxu->stamp; in scan_async()
2206 * as HCD schedule-scanning costs. delay for any qh in scan_async()
2207 * we just scanned, there's a not-unusual case that it in scan_async()
2209 * (plus, avoids some kind of re-activation race.) in scan_async()
2211 if (list_empty(&qh->qtd_list)) { in scan_async()
2212 if (qh->stamp == oxu->stamp) in scan_async()
2214 else if (!oxu->reclaim in scan_async()
2215 && qh->qh_state == QH_STATE_LINKED) in scan_async()
2219 qh = qh->qh_next.qh; in scan_async()
2227 * periodic_next_shadow - return "next" pointer on shadow list
2237 return &periodic->qh->qh_next; in periodic_next_shadow()
2241 /* caller must hold oxu->lock */
2244 union ehci_shadow *prev_p = &oxu->pshadow[frame]; in periodic_unlink()
2245 __le32 *hw_p = &oxu->periodic[frame]; in periodic_unlink()
2269 __le32 *hw_p = &oxu->periodic[frame]; in periodic_usecs()
2270 union ehci_shadow *q = &oxu->pshadow[frame]; in periodic_usecs()
2273 while (q->ptr) { in periodic_usecs()
2277 /* is it in the S-mask? */ in periodic_usecs()
2278 if (q->qh->hw_info2 & cpu_to_le32(1 << uframe)) in periodic_usecs()
2279 usecs += q->qh->usecs; in periodic_usecs()
2280 /* ... or C-mask? */ in periodic_usecs()
2281 if (q->qh->hw_info2 & cpu_to_le32(1 << (8 + uframe))) in periodic_usecs()
2282 usecs += q->qh->c_usecs; in periodic_usecs()
2283 hw_p = &q->qh->hw_next; in periodic_usecs()
2284 q = &q->qh->qh_next; in periodic_usecs()
2304 status = handshake(oxu, &oxu->regs->status, STS_PSS, 0, 9 * 125); in enable_periodic()
2306 oxu_to_hcd(oxu)->state = HC_STATE_HALT; in enable_periodic()
2311 cmd = readl(&oxu->regs->command) | CMD_PSE; in enable_periodic()
2312 writel(cmd, &oxu->regs->command); in enable_periodic()
2314 oxu_to_hcd(oxu)->state = HC_STATE_RUNNING; in enable_periodic()
2317 oxu->next_uframe = readl(&oxu->regs->frame_index) in enable_periodic()
2318 % (oxu->periodic_size << 3); in enable_periodic()
2330 status = handshake(oxu, &oxu->regs->status, STS_PSS, STS_PSS, 9 * 125); in disable_periodic()
2332 oxu_to_hcd(oxu)->state = HC_STATE_HALT; in disable_periodic()
2337 cmd = readl(&oxu->regs->command) & ~CMD_PSE; in disable_periodic()
2338 writel(cmd, &oxu->regs->command); in disable_periodic()
2341 oxu->next_uframe = -1; in disable_periodic()
2354 unsigned period = qh->period; in qh_link_periodic() local
2356 dev_dbg(&qh->dev->dev, in qh_link_periodic()
2357 "link qh%d-%04x/%p start %d [%d/%d us]\n", in qh_link_periodic()
2358 period, le32_to_cpup(&qh->hw_info2) & (QH_CMASK | QH_SMASK), in qh_link_periodic()
2359 qh, qh->start, qh->usecs, qh->c_usecs); in qh_link_periodic()
2362 if (period == 0) in qh_link_periodic()
2363 period = 1; in qh_link_periodic()
2365 for (i = qh->start; i < oxu->periodic_size; i += period) { in qh_link_periodic()
2366 union ehci_shadow *prev = &oxu->pshadow[i]; in qh_link_periodic()
2367 __le32 *hw_p = &oxu->periodic[i]; in qh_link_periodic()
2377 hw_p = &here.qh->hw_next; in qh_link_periodic()
2381 /* sorting each branch by period (slow-->fast) in qh_link_periodic()
2385 if (qh->period > here.qh->period) in qh_link_periodic()
2387 prev = &here.qh->qh_next; in qh_link_periodic()
2388 hw_p = &here.qh->hw_next; in qh_link_periodic()
2393 qh->qh_next = here; in qh_link_periodic()
2395 qh->hw_next = *hw_p; in qh_link_periodic()
2397 prev->qh = qh; in qh_link_periodic()
2398 *hw_p = QH_NEXT(qh->qh_dma); in qh_link_periodic()
2401 qh->qh_state = QH_STATE_LINKED; in qh_link_periodic()
2404 /* update per-qh bandwidth for usbfs */ in qh_link_periodic()
2405 oxu_to_hcd(oxu)->self.bandwidth_allocated += qh->period in qh_link_periodic()
2406 ? ((qh->usecs + qh->c_usecs) / qh->period) in qh_link_periodic()
2407 : (qh->usecs * 8); in qh_link_periodic()
2410 if (!oxu->periodic_sched++) in qh_link_periodic()
2419 unsigned period; in qh_unlink_periodic() local
2426 * qh->hw_info1 |= cpu_to_le32(1 << 7 "ignore"); in qh_unlink_periodic()
2430 period = qh->period; in qh_unlink_periodic()
2431 if (period == 0) in qh_unlink_periodic()
2432 period = 1; in qh_unlink_periodic()
2434 for (i = qh->start; i < oxu->periodic_size; i += period) in qh_unlink_periodic()
2437 /* update per-qh bandwidth for usbfs */ in qh_unlink_periodic()
2438 oxu_to_hcd(oxu)->self.bandwidth_allocated -= qh->period in qh_unlink_periodic()
2439 ? ((qh->usecs + qh->c_usecs) / qh->period) in qh_unlink_periodic()
2440 : (qh->usecs * 8); in qh_unlink_periodic()
2442 dev_dbg(&qh->dev->dev, in qh_unlink_periodic()
2443 "unlink qh%d-%04x/%p start %d [%d/%d us]\n", in qh_unlink_periodic()
2444 qh->period, in qh_unlink_periodic()
2445 le32_to_cpup(&qh->hw_info2) & (QH_CMASK | QH_SMASK), in qh_unlink_periodic()
2446 qh, qh->start, qh->usecs, qh->c_usecs); in qh_unlink_periodic()
2448 /* qh->qh_next still "live" to HC */ in qh_unlink_periodic()
2449 qh->qh_state = QH_STATE_UNLINK; in qh_unlink_periodic()
2450 qh->qh_next.ptr = NULL; in qh_unlink_periodic()
2454 oxu->periodic_sched--; in qh_unlink_periodic()
2455 if (!oxu->periodic_sched) in qh_unlink_periodic()
2466 * qh->hw_next or finish a writeback after SPLIT/CSPLIT ... and in intr_deschedule()
2470 if (list_empty(&qh->qtd_list) in intr_deschedule()
2471 || (cpu_to_le32(QH_CMASK) & qh->hw_info2) != 0) in intr_deschedule()
2477 qh->qh_state = QH_STATE_IDLE; in intr_deschedule()
2478 qh->hw_next = EHCI_LIST_END; in intr_deschedule()
2484 unsigned period, unsigned usecs) in check_period() argument
2498 usecs = 100 - usecs; in check_period()
2501 * for period 0, check _every_ microframe in the schedule. in check_period()
2503 if (unlikely(period == 0)) { in check_period()
2510 } while ((frame += 1) < oxu->periodic_size); in check_period()
2512 /* just check the specified uframe, at that period */ in check_period()
2518 } while ((frame += period) < oxu->periodic_size); in check_period()
2528 int retval = -ENOSPC; in check_intr_schedule()
2530 if (qh->c_usecs && uframe >= 6) /* FSTN territory? */ in check_intr_schedule()
2533 if (!check_period(oxu, frame, uframe, qh->period, qh->usecs)) in check_intr_schedule()
2535 if (!qh->c_usecs) { in check_intr_schedule()
2546 * or when the previous schedule slot can't be re-used.
2553 unsigned frame; /* 0..(qh->period - 1), or NO_FRAME */ in qh_schedule()
2556 qh->hw_next = EHCI_LIST_END; in qh_schedule()
2557 frame = qh->start; in qh_schedule()
2560 if (frame < qh->period) { in qh_schedule()
2561 uframe = ffs(le32_to_cpup(&qh->hw_info2) & QH_SMASK); in qh_schedule()
2562 status = check_intr_schedule(oxu, frame, --uframe, in qh_schedule()
2567 status = -ENOSPC; in qh_schedule()
2575 if (qh->period) { in qh_schedule()
2576 frame = qh->period - 1; in qh_schedule()
2585 } while (status && frame--); in qh_schedule()
2587 /* qh->period == 0 means every uframe */ in qh_schedule()
2594 qh->start = frame; in qh_schedule()
2596 /* reset S-frame and (maybe) C-frame masks */ in qh_schedule()
2597 qh->hw_info2 &= cpu_to_le32(~(QH_CMASK | QH_SMASK)); in qh_schedule()
2598 qh->hw_info2 |= qh->period in qh_schedule()
2601 qh->hw_info2 |= c_mask; in qh_schedule()
2621 epnum = urb->ep->desc.bEndpointAddress; in intr_submit()
2623 spin_lock_irqsave(&oxu->lock, flags); in intr_submit()
2626 status = -ESHUTDOWN; in intr_submit()
2632 qh = qh_append_tds(oxu, urb, &empty, epnum, &urb->ep->hcpriv); in intr_submit()
2634 status = -ENOMEM; in intr_submit()
2637 if (qh->qh_state == QH_STATE_IDLE) { in intr_submit()
2644 qh = qh_append_tds(oxu, urb, qtd_list, epnum, &urb->ep->hcpriv); in intr_submit()
2648 oxu_to_hcd(oxu)->self.bandwidth_int_reqs++; in intr_submit()
2651 spin_unlock_irqrestore(&oxu->lock, flags); in intr_submit()
2662 return -ENOSYS; in itd_submit()
2669 return -ENOSYS; in sitd_submit()
2677 mod = oxu->periodic_size << 3; in scan_periodic()
2682 * Touches as few pages as possible: cache-friendly. in scan_periodic()
2684 now_uframe = oxu->next_uframe; in scan_periodic()
2685 if (HC_IS_RUNNING(oxu_to_hcd(oxu)->state)) in scan_periodic()
2686 clock = readl(&oxu->regs->frame_index); in scan_periodic()
2688 clock = now_uframe + mod - 1; in scan_periodic()
2704 q_p = &oxu->pshadow[frame]; in scan_periodic()
2705 hw_p = &oxu->periodic[frame]; in scan_periodic()
2706 q.ptr = q_p->ptr; in scan_periodic()
2717 type = Q_NEXT_TYPE(q.qh->hw_next); in scan_periodic()
2718 q = q.qh->qh_next; in scan_periodic()
2720 if (unlikely(list_empty(&temp.qh->qtd_list))) in scan_periodic()
2744 /* FIXME: likewise assumes HC doesn't halt mid-scan */ in scan_periodic()
2749 if (!HC_IS_RUNNING(oxu_to_hcd(oxu)->state)) in scan_periodic()
2751 oxu->next_uframe = now_uframe; in scan_periodic()
2752 now = readl(&oxu->regs->frame_index) % mod; in scan_periodic()
2771 int port = HCS_N_PORTS(oxu->hcs_params); in ehci_turn_off_all_ports()
2773 while (port--) in ehci_turn_off_all_ports()
2774 writel(PORT_RWC_BITS, &oxu->regs->port_status[port]); in ehci_turn_off_all_ports()
2781 if (!HCS_PPC(oxu->hcs_params)) in ehci_port_power()
2785 for (port = HCS_N_PORTS(oxu->hcs_params); port > 0; ) { in ehci_port_power()
2788 USB_PORT_FEAT_POWER, port--, NULL, 0); in ehci_port_power()
2791 USB_PORT_FEAT_POWER, port--, NULL, 0); in ehci_port_power()
2798 * It calls driver completion functions, after dropping oxu->lock.
2803 if (oxu->reclaim_ready) in ehci_work()
2806 /* another CPU may drop oxu->lock during a schedule scan while in ehci_work()
2808 * attempts at re-entrant schedule scanning. in ehci_work()
2810 if (oxu->scanning) in ehci_work()
2812 oxu->scanning = 1; in ehci_work()
2814 if (oxu->next_uframe != -1) in ehci_work()
2816 oxu->scanning = 0; in ehci_work()
2819 * misplace IRQs, and should let us run completely without IRQs. in ehci_work()
2822 if (HC_IS_RUNNING(oxu_to_hcd(oxu)->state) && in ehci_work()
2823 (oxu->async->qh_next.ptr != NULL || in ehci_work()
2824 oxu->periodic_sched != 0)) in ehci_work()
2831 if (qh->qh_state == QH_STATE_LINKED in unlink_async()
2832 && oxu->reclaim in unlink_async()
2833 && HC_IS_RUNNING(oxu_to_hcd(oxu)->state)) { in unlink_async()
2836 for (last = oxu->reclaim; in unlink_async()
2837 last->reclaim; in unlink_async()
2838 last = last->reclaim) in unlink_async()
2840 qh->qh_state = QH_STATE_UNLINK_WAIT; in unlink_async()
2841 last->reclaim = qh; in unlink_async()
2844 } else if (!HC_IS_RUNNING(oxu_to_hcd(oxu)->state) && oxu->reclaim) in unlink_async()
2848 if (qh->qh_state == QH_STATE_LINKED) in unlink_async()
2862 spin_lock(&oxu->lock); in oxu210_hcd_irq()
2864 status = readl(&oxu->regs->status); in oxu210_hcd_irq()
2874 if (!status || unlikely(hcd->state == HC_STATE_HALT)) { in oxu210_hcd_irq()
2875 spin_unlock(&oxu->lock); in oxu210_hcd_irq()
2880 writel(status, &oxu->regs->status); in oxu210_hcd_irq()
2881 readl(&oxu->regs->command); /* unblock posted write */ in oxu210_hcd_irq()
2897 oxu->reclaim_ready = 1; in oxu210_hcd_irq()
2903 unsigned i = HCS_N_PORTS(oxu->hcs_params); in oxu210_hcd_irq()
2907 if (!(readl(&oxu->regs->command) & CMD_RUN)) in oxu210_hcd_irq()
2910 while (i--) { in oxu210_hcd_irq()
2911 int pstatus = readl(&oxu->regs->port_status[i]); in oxu210_hcd_irq()
2916 || oxu->reset_done[i] != 0) in oxu210_hcd_irq()
2923 oxu->reset_done[i] = jiffies + in oxu210_hcd_irq()
2926 mod_timer(&hcd->rh_timer, oxu->reset_done[i]); in oxu210_hcd_irq()
2933 status = readl(&oxu->regs->status); in oxu210_hcd_irq()
2934 dbg_cmd(oxu, "fatal", readl(&oxu->regs->command)); in oxu210_hcd_irq()
2940 writel(0, &oxu->regs->configured_flag); in oxu210_hcd_irq()
2951 spin_unlock(&oxu->lock); in oxu210_hcd_irq()
2962 u32 status = oxu_readl(hcd->regs, OXU_CHIPIRQSTATUS); in oxu_irq()
2963 u32 enable = oxu_readl(hcd->regs, OXU_CHIPIRQEN_SET); in oxu_irq()
2966 oxu_writel(hcd->regs, OXU_CHIPIRQEN_CLR, enable); in oxu_irq()
2968 if ((oxu->is_otg && (status & OXU_USBOTGI)) || in oxu_irq()
2969 (!oxu->is_otg && (status & OXU_USBSPHI))) in oxu_irq()
2975 oxu_writel(hcd->regs, OXU_CHIPIRQEN_SET, enable); in oxu_irq()
2985 spin_lock_irqsave(&oxu->lock, flags); in oxu_watchdog()
2988 if (oxu->reclaim) { in oxu_watchdog()
2989 u32 status = readl(&oxu->regs->status); in oxu_watchdog()
2992 writel(STS_IAA, &oxu->regs->status); in oxu_watchdog()
2993 oxu->reclaim_ready = 1; in oxu_watchdog()
2998 if (test_bit(TIMER_ASYNC_OFF, &oxu->actions)) in oxu_watchdog()
2999 start_unlink_async(oxu, oxu->async); in oxu_watchdog()
3004 spin_unlock_irqrestore(&oxu->lock, flags); in oxu_watchdog()
3007 /* One-time init, only for memory state.
3016 spin_lock_init(&oxu->lock); in oxu_hcd_init()
3018 timer_setup(&oxu->watchdog, oxu_watchdog, 0); in oxu_hcd_init()
3024 oxu->periodic_size = DEFAULT_I_TDPS; in oxu_hcd_init()
3030 hcc_params = readl(&oxu->caps->hcc_params); in oxu_hcd_init()
3032 oxu->i_thresh = 8; in oxu_hcd_init()
3034 oxu->i_thresh = 2 + HCC_ISOC_THRES(hcc_params); in oxu_hcd_init()
3036 oxu->reclaim = NULL; in oxu_hcd_init()
3037 oxu->reclaim_ready = 0; in oxu_hcd_init()
3038 oxu->next_uframe = -1; in oxu_hcd_init()
3047 oxu->async->qh_next.qh = NULL; in oxu_hcd_init()
3048 oxu->async->hw_next = QH_NEXT(oxu->async->qh_dma); in oxu_hcd_init()
3049 oxu->async->hw_info1 = cpu_to_le32(QH_HEAD); in oxu_hcd_init()
3050 oxu->async->hw_token = cpu_to_le32(QTD_STS_HALT); in oxu_hcd_init()
3051 oxu->async->hw_qtd_next = EHCI_LIST_END; in oxu_hcd_init()
3052 oxu->async->qh_state = QH_STATE_LINKED; in oxu_hcd_init()
3053 oxu->async->hw_alt_next = QTD_NEXT(oxu->async->dummy->qtd_dma); in oxu_hcd_init()
3079 oxu->command = temp; in oxu_hcd_init()
3090 spin_lock_init(&oxu->mem_lock); in oxu_reset()
3091 INIT_LIST_HEAD(&oxu->urb_list); in oxu_reset()
3092 oxu->urb_len = 0; in oxu_reset()
3094 if (oxu->is_otg) { in oxu_reset()
3095 oxu->caps = hcd->regs + OXU_OTG_CAP_OFFSET; in oxu_reset()
3096 oxu->regs = hcd->regs + OXU_OTG_CAP_OFFSET + \ in oxu_reset()
3097 HC_LENGTH(readl(&oxu->caps->hc_capbase)); in oxu_reset()
3099 oxu->mem = hcd->regs + OXU_SPH_MEM; in oxu_reset()
3101 oxu->caps = hcd->regs + OXU_SPH_CAP_OFFSET; in oxu_reset()
3102 oxu->regs = hcd->regs + OXU_SPH_CAP_OFFSET + \ in oxu_reset()
3103 HC_LENGTH(readl(&oxu->caps->hc_capbase)); in oxu_reset()
3105 oxu->mem = hcd->regs + OXU_OTG_MEM; in oxu_reset()
3108 oxu->hcs_params = readl(&oxu->caps->hcs_params); in oxu_reset()
3109 oxu->sbrn = 0x20; in oxu_reset()
3120 hcd->uses_new_polling = 1; in oxu_run()
3128 writel(oxu->periodic_dma, &oxu->regs->frame_list); in oxu_run()
3129 writel((u32) oxu->async->qh_dma, &oxu->regs->async_next); in oxu_run()
3131 /* hcc_params controls whether oxu->regs->segment must (!!!) in oxu_run()
3137 * NOTE: the dma mask is visible through dev->dma_mask, so in oxu_run()
3142 hcc_params = readl(&oxu->caps->hcc_params); in oxu_run()
3144 writel(0, &oxu->regs->segment); in oxu_run()
3146 oxu->command &= ~(CMD_LRESET | CMD_IAAD | CMD_PSE | in oxu_run()
3148 oxu->command |= CMD_RUN; in oxu_run()
3149 writel(oxu->command, &oxu->regs->command); in oxu_run()
3150 dbg_cmd(oxu, "init", oxu->command); in oxu_run()
3158 hcd->state = HC_STATE_RUNNING; in oxu_run()
3159 writel(FLAG_CF, &oxu->regs->configured_flag); in oxu_run()
3160 readl(&oxu->regs->command); /* unblock posted writes */ in oxu_run()
3162 temp = HC_VERSION(readl(&oxu->caps->hc_capbase)); in oxu_run()
3163 oxu_info(oxu, "USB %x.%x started, quasi-EHCI %x.%02x, driver %s%s\n", in oxu_run()
3164 ((oxu->sbrn & 0xf0)>>4), (oxu->sbrn & 0x0f), in oxu_run()
3168 writel(INTR_MASK, &oxu->regs->intr_enable); /* Turn On Interrupts */ in oxu_run()
3181 del_timer_sync(&oxu->watchdog); in oxu_stop()
3183 spin_lock_irq(&oxu->lock); in oxu_stop()
3184 if (HC_IS_RUNNING(hcd->state)) in oxu_stop()
3188 writel(0, &oxu->regs->intr_enable); in oxu_stop()
3189 spin_unlock_irq(&oxu->lock); in oxu_stop()
3192 writel(0, &oxu->regs->configured_flag); in oxu_stop()
3195 spin_lock_irq(&oxu->lock); in oxu_stop()
3196 if (oxu->async) in oxu_stop()
3198 spin_unlock_irq(&oxu->lock); in oxu_stop()
3201 dbg_status(oxu, "oxu_stop completed", readl(&oxu->regs->status)); in oxu_stop()
3216 writel(0, &oxu->regs->configured_flag); in oxu_shutdown()
3219 readl(&oxu->regs->configured_flag); in oxu_shutdown()
3222 /* Non-error returns are a promise to giveback() the urb later
3228 * hcd-specific init for hcpriv hasn't been done yet
3241 switch (usb_pipetype(urb->pipe)) { in __oxu_urb_enqueue()
3246 return -ENOMEM; in __oxu_urb_enqueue()
3251 return -ENOMEM; in __oxu_urb_enqueue()
3255 if (urb->dev->speed == USB_SPEED_HIGH) in __oxu_urb_enqueue()
3275 if (!usb_pipebulk(urb->pipe)) in oxu_urb_enqueue()
3279 transfer_buffer = urb->transfer_buffer; in oxu_urb_enqueue()
3281 num = urb->transfer_buffer_length / 4096; in oxu_urb_enqueue()
3282 rem = urb->transfer_buffer_length % 4096; in oxu_urb_enqueue()
3292 for (i = 0; i < num - 1; i++) { in oxu_urb_enqueue()
3304 murb->transfer_buffer_length = 4096; in oxu_urb_enqueue()
3305 murb->transfer_buffer = transfer_buffer + i * 4096; in oxu_urb_enqueue()
3308 murb->complete = NULL; in oxu_urb_enqueue()
3310 ((struct oxu_murb *) murb)->main = urb; in oxu_urb_enqueue()
3311 ((struct oxu_murb *) murb)->last = 0; in oxu_urb_enqueue()
3335 murb->transfer_buffer_length = rem > 0 ? rem : 4096; in oxu_urb_enqueue()
3336 murb->transfer_buffer = transfer_buffer + (num - 1) * 4096; in oxu_urb_enqueue()
3339 murb->complete = NULL; in oxu_urb_enqueue()
3341 ((struct oxu_murb *) murb)->main = urb; in oxu_urb_enqueue()
3342 ((struct oxu_murb *) murb)->last = 1; in oxu_urb_enqueue()
3362 spin_lock_irqsave(&oxu->lock, flags); in oxu_urb_dequeue()
3363 switch (usb_pipetype(urb->pipe)) { in oxu_urb_dequeue()
3367 qh = (struct ehci_qh *) urb->hcpriv; in oxu_urb_dequeue()
3374 qh = (struct ehci_qh *) urb->hcpriv; in oxu_urb_dequeue()
3377 switch (qh->qh_state) { in oxu_urb_dequeue()
3386 qh, qh->qh_state); in oxu_urb_dequeue()
3391 if (!list_empty(&qh->qtd_list) in oxu_urb_dequeue()
3392 && HC_IS_RUNNING(hcd->state)) { in oxu_urb_dequeue()
3396 spin_unlock_irqrestore(&oxu->lock, flags); in oxu_urb_dequeue()
3402 dev_err(hcd->self.controller, in oxu_urb_dequeue()
3411 spin_unlock_irqrestore(&oxu->lock, flags); in oxu_urb_dequeue()
3427 spin_lock_irqsave(&oxu->lock, flags); in oxu_endpoint_disable()
3428 qh = ep->hcpriv; in oxu_endpoint_disable()
3435 if (qh->hw_info1 == 0) { in oxu_endpoint_disable()
3440 if (!HC_IS_RUNNING(hcd->state)) in oxu_endpoint_disable()
3441 qh->qh_state = QH_STATE_IDLE; in oxu_endpoint_disable()
3442 switch (qh->qh_state) { in oxu_endpoint_disable()
3444 for (tmp = oxu->async->qh_next.qh; in oxu_endpoint_disable()
3446 tmp = tmp->qh_next.qh) in oxu_endpoint_disable()
3448 /* periodic qh self-unlinks on empty */ in oxu_endpoint_disable()
3455 spin_unlock_irqrestore(&oxu->lock, flags); in oxu_endpoint_disable()
3459 if (list_empty(&qh->qtd_list)) { in oxu_endpoint_disable()
3470 qh, ep->desc.bEndpointAddress, qh->qh_state, in oxu_endpoint_disable()
3471 list_empty(&qh->qtd_list) ? "" : "(has tds)"); in oxu_endpoint_disable()
3474 ep->hcpriv = NULL; in oxu_endpoint_disable()
3476 spin_unlock_irqrestore(&oxu->lock, flags); in oxu_endpoint_disable()
3483 return (readl(&oxu->regs->frame_index) >> 3) % in oxu_get_frame()
3484 oxu->periodic_size; in oxu_get_frame()
3496 if (!HC_IS_RUNNING(hcd->state)) in oxu_hub_status_data()
3499 /* init status to no-changes */ in oxu_hub_status_data()
3501 ports = HCS_N_PORTS(oxu->hcs_params); in oxu_hub_status_data()
3511 * PORT_POWER; that's surprising, but maybe within-spec. in oxu_hub_status_data()
3521 spin_lock_irqsave(&oxu->lock, flags); in oxu_hub_status_data()
3523 temp = readl(&oxu->regs->port_status[i]); in oxu_hub_status_data()
3528 * high-speed device is switched over to the companion in oxu_hub_status_data()
3533 oxu->reset_done[i] = 0; in oxu_hub_status_data()
3535 time_after_eq(jiffies, oxu->reset_done[i]))) { in oxu_hub_status_data()
3539 buf[1] |= 1 << (i - 7); in oxu_hub_status_data()
3544 spin_unlock_irqrestore(&oxu->lock, flags); in oxu_hub_status_data()
3568 int ports = HCS_N_PORTS(oxu->hcs_params); in oxu_hub_control()
3569 u32 __iomem *status_reg = &oxu->regs->port_status[wIndex - 1]; in oxu_hub_control()
3582 spin_lock_irqsave(&oxu->lock, flags); in oxu_hub_control()
3588 /* no hub-wide feature/status flags */ in oxu_hub_control()
3597 wIndex--; in oxu_hub_control()
3603 * the port-change status bits (especially in oxu_hub_control()
3623 oxu->reset_done[wIndex] = jiffies in oxu_hub_control()
3628 /* we auto-clear this feature */ in oxu_hub_control()
3631 if (HCS_PPC(oxu->hcs_params)) in oxu_hub_control()
3647 readl(&oxu->regs->command); /* unblock posted write */ in oxu_hub_control()
3654 /* no hub-wide feature/status flags */ in oxu_hub_control()
3660 wIndex--; in oxu_hub_control()
3676 if (!oxu->reset_done[wIndex]) { in oxu_hub_control()
3678 oxu->reset_done[wIndex] = jiffies in oxu_hub_control()
3681 mod_timer(&oxu_to_hcd(oxu)->rh_timer, in oxu_hub_control()
3682 oxu->reset_done[wIndex]); in oxu_hub_control()
3687 oxu->reset_done[wIndex])) { in oxu_hub_control()
3689 oxu->reset_done[wIndex] = 0; in oxu_hub_control()
3710 oxu->reset_done[wIndex])) { in oxu_hub_control()
3712 oxu->reset_done[wIndex] = 0; in oxu_hub_control()
3735 test_bit(wIndex, &oxu->companion_ports)) { in oxu_hub_control()
3739 oxu_dbg(oxu, "port %d --> companion\n", wIndex + 1); in oxu_hub_control()
3775 /* no hub-wide feature/status flags */ in oxu_hub_control()
3786 wIndex--; in oxu_hub_control()
3797 if (device_may_wakeup(&hcd->self.root_hub->dev)) in oxu_hub_control()
3802 if (HCS_PPC(oxu->hcs_params)) in oxu_hub_control()
3820 oxu->reset_done[wIndex] = jiffies in oxu_hub_control()
3829 * about the EHCI-specific stuff. in oxu_hub_control()
3843 readl(&oxu->regs->command); /* unblock posted writes */ in oxu_hub_control()
3849 retval = -EPIPE; in oxu_hub_control()
3851 spin_unlock_irqrestore(&oxu->lock, flags); in oxu_hub_control()
3865 if (time_before(jiffies, oxu->next_statechange)) in oxu_bus_suspend()
3868 port = HCS_N_PORTS(oxu->hcs_params); in oxu_bus_suspend()
3869 spin_lock_irq(&oxu->lock); in oxu_bus_suspend()
3872 if (HC_IS_RUNNING(hcd->state)) { in oxu_bus_suspend()
3874 hcd->state = HC_STATE_QUIESCING; in oxu_bus_suspend()
3876 oxu->command = readl(&oxu->regs->command); in oxu_bus_suspend()
3877 if (oxu->reclaim) in oxu_bus_suspend()
3878 oxu->reclaim_ready = 1; in oxu_bus_suspend()
3882 * any notion of "global" or bus-wide suspend. The driver has in oxu_bus_suspend()
3886 oxu->bus_suspended = 0; in oxu_bus_suspend()
3887 while (port--) { in oxu_bus_suspend()
3888 u32 __iomem *reg = &oxu->regs->port_status[port]; in oxu_bus_suspend()
3896 set_bit(port, &oxu->bus_suspended); in oxu_bus_suspend()
3900 if (device_may_wakeup(&hcd->self.root_hub->dev)) in oxu_bus_suspend()
3906 oxu_vdbg(oxu, "port %d, %08x -> %08x\n", in oxu_bus_suspend()
3912 spin_unlock_irq(&oxu->lock); in oxu_bus_suspend()
3913 /* turn off now-idle HC */ in oxu_bus_suspend()
3914 del_timer_sync(&oxu->watchdog); in oxu_bus_suspend()
3915 spin_lock_irq(&oxu->lock); in oxu_bus_suspend()
3917 hcd->state = HC_STATE_SUSPENDED; in oxu_bus_suspend()
3921 if (!device_may_wakeup(&hcd->self.root_hub->dev)) in oxu_bus_suspend()
3923 writel(mask, &oxu->regs->intr_enable); in oxu_bus_suspend()
3924 readl(&oxu->regs->intr_enable); in oxu_bus_suspend()
3926 oxu->next_statechange = jiffies + msecs_to_jiffies(10); in oxu_bus_suspend()
3927 spin_unlock_irq(&oxu->lock); in oxu_bus_suspend()
3938 if (time_before(jiffies, oxu->next_statechange)) in oxu_bus_resume()
3940 spin_lock_irq(&oxu->lock); in oxu_bus_resume()
3944 * could instead be restoring a swsusp snapshot -- so that BIOS was in oxu_bus_resume()
3948 temp = readl(&oxu->regs->intr_enable); in oxu_bus_resume()
3954 writel(0, &oxu->regs->intr_enable); in oxu_bus_resume()
3956 /* re-init operational registers */ in oxu_bus_resume()
3957 writel(0, &oxu->regs->segment); in oxu_bus_resume()
3958 writel(oxu->periodic_dma, &oxu->regs->frame_list); in oxu_bus_resume()
3959 writel((u32) oxu->async->qh_dma, &oxu->regs->async_next); in oxu_bus_resume()
3962 writel(oxu->command, &oxu->regs->command); in oxu_bus_resume()
3969 i = HCS_N_PORTS(oxu->hcs_params); in oxu_bus_resume()
3970 while (i--) { in oxu_bus_resume()
3971 temp = readl(&oxu->regs->port_status[i]); in oxu_bus_resume()
3974 if (test_bit(i, &oxu->bus_suspended) && (temp & PORT_SUSPEND)) { in oxu_bus_resume()
3975 oxu->reset_done[i] = jiffies + msecs_to_jiffies(20); in oxu_bus_resume()
3978 writel(temp, &oxu->regs->port_status[i]); in oxu_bus_resume()
3980 i = HCS_N_PORTS(oxu->hcs_params); in oxu_bus_resume()
3982 while (i--) { in oxu_bus_resume()
3983 temp = readl(&oxu->regs->port_status[i]); in oxu_bus_resume()
3984 if (test_bit(i, &oxu->bus_suspended) && (temp & PORT_SUSPEND)) { in oxu_bus_resume()
3986 writel(temp, &oxu->regs->port_status[i]); in oxu_bus_resume()
3990 (void) readl(&oxu->regs->command); in oxu_bus_resume()
3992 /* maybe re-activate the schedule(s) */ in oxu_bus_resume()
3994 if (oxu->async->qh_next.qh) in oxu_bus_resume()
3996 if (oxu->periodic_sched) in oxu_bus_resume()
3999 oxu->command |= temp; in oxu_bus_resume()
4000 writel(oxu->command, &oxu->regs->command); in oxu_bus_resume()
4003 oxu->next_statechange = jiffies + msecs_to_jiffies(5); in oxu_bus_resume()
4004 hcd->state = HC_STATE_RUNNING; in oxu_bus_resume()
4006 /* Now we can safely re-enable irqs */ in oxu_bus_resume()
4007 writel(INTR_MASK, &oxu->regs->intr_enable); in oxu_bus_resume()
4009 spin_unlock_irq(&oxu->lock); in oxu_bus_resume()
4106 "128-pin LQFP", in oxu_verify_id()
4107 "84-pin TFBGA", in oxu_verify_id()
4113 dev_info(&pdev->dev, "device ID %x\n", id); in oxu_verify_id()
4115 return -1; in oxu_verify_id()
4117 dev_info(&pdev->dev, "found device %x %s (%04x:%04x)\n", in oxu_verify_id()
4131 struct device *dev = &pdev->dev; in oxu_create()
4145 return ERR_PTR(-ENOMEM); in oxu_create()
4147 hcd->rsrc_start = memstart; in oxu_create()
4148 hcd->rsrc_len = memlen; in oxu_create()
4149 hcd->regs = base; in oxu_create()
4150 hcd->irq = irq; in oxu_create()
4151 hcd->state = HC_STATE_HALT; in oxu_create()
4154 oxu->is_otg = otg; in oxu_create()
4162 device_wakeup_enable(hcd->self.controller); in oxu_create()
4179 dev_err(&pdev->dev, "no devices found!\n"); in oxu_init()
4180 return -ENODEV; in oxu_init()
4186 dev_err(&pdev->dev, "cannot create OTG controller!\n"); in oxu_init()
4190 info->hcd[0] = hcd; in oxu_init()
4195 dev_err(&pdev->dev, "cannot create SPH controller!\n"); in oxu_init()
4199 info->hcd[1] = hcd; in oxu_init()
4207 usb_remove_hcd(info->hcd[0]); in oxu_init()
4208 usb_put_hcd(info->hcd[0]); in oxu_init()
4223 return -ENODEV; in oxu_drv_probe()
4231 dev_dbg(&pdev->dev, "IRQ resource %d\n", irq); in oxu_drv_probe()
4238 memstart = res->start; in oxu_drv_probe()
4243 dev_err(&pdev->dev, "error setting irq type\n"); in oxu_drv_probe()
4244 ret = -EFAULT; in oxu_drv_probe()
4251 info = devm_kzalloc(&pdev->dev, sizeof(struct oxu_info), GFP_KERNEL); in oxu_drv_probe()
4253 ret = -EFAULT; in oxu_drv_probe()
4260 dev_dbg(&pdev->dev, "cannot init USB devices\n"); in oxu_drv_probe()
4264 dev_info(&pdev->dev, "devices enabled and running\n"); in oxu_drv_probe()
4270 dev_err(&pdev->dev, "init %s fail, %d\n", dev_name(&pdev->dev), ret); in oxu_drv_probe()
4284 oxu_remove(pdev, info->hcd[0]); in oxu_drv_remove()
4285 oxu_remove(pdev, info->hcd[1]); in oxu_drv_remove()
4322 .name = "oxu210hp-hcd",
4329 MODULE_DESCRIPTION("Oxford OXU210HP HCD driver - ver. " DRIVER_VERSION);