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 */
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 */
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()
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()
1370 case -EREMOTEIO: /* fault or normal */ in ehci_urb_done()
1371 if (!(urb->transfer_flags & URB_SHORT_NOT_OK)) in ehci_urb_done()
1372 urb->status = 0; in ehci_urb_done()
1374 case -ECONNRESET: /* canceled */ in ehci_urb_done()
1375 case -ENOENT: in ehci_urb_done()
1381 __func__, urb->dev->devpath, urb, in ehci_urb_done()
1382 usb_pipeendpoint(urb->pipe), in ehci_urb_done()
1383 usb_pipein(urb->pipe) ? "in" : "out", in ehci_urb_done()
1384 urb->status, in ehci_urb_done()
1385 urb->actual_length, urb->transfer_buffer_length); in ehci_urb_done()
1389 spin_unlock(&oxu->lock); in ehci_urb_done()
1390 usb_hcd_giveback_urb(oxu_to_hcd(oxu), urb, urb->status); in ehci_urb_done()
1391 spin_lock(&oxu->lock); in ehci_urb_done()
1403 * Chases up to qh->hw_current. Returns number of completions called,
1408 struct ehci_qtd *last = NULL, *end = qh->dummy; in qh_completions()
1416 if (unlikely(list_empty(&qh->qtd_list))) in qh_completions()
1425 state = qh->qh_state; in qh_completions()
1426 qh->qh_state = QH_STATE_COMPLETING; in qh_completions()
1429 /* remove de-activated QTDs from front of queue. in qh_completions()
1434 list_for_each_entry_safe(qtd, tmp, &qh->qtd_list, qtd_list) { in qh_completions()
1438 urb = qtd->urb; in qh_completions()
1442 if (likely(last->urb != urb)) { in qh_completions()
1443 if (last->urb->complete == NULL) { in qh_completions()
1444 murb = (struct oxu_murb *) last->urb; in qh_completions()
1445 last->urb = murb->main; in qh_completions()
1446 if (murb->last) { in qh_completions()
1447 ehci_urb_done(oxu, last->urb); in qh_completions()
1452 ehci_urb_done(oxu, last->urb); in qh_completions()
1466 token = le32_to_cpu(qtd->hw_token); in qh_completions()
1468 /* always clean up qtds the hc de-activated */ in qh_completions()
1478 !(qtd->hw_alt_next & EHCI_LIST_END)) { in qh_completions()
1485 HC_IS_RUNNING(oxu_to_hcd(oxu)->state))) { in qh_completions()
1491 if (unlikely(!HC_IS_RUNNING(oxu_to_hcd(oxu)->state))) in qh_completions()
1492 urb->status = -ESHUTDOWN; in qh_completions()
1498 if (likely(urb->status == -EINPROGRESS)) in qh_completions()
1510 && cpu_to_le32(qtd->qtd_dma) in qh_completions()
1511 == qh->hw_current) in qh_completions()
1512 token = le32_to_cpu(qh->hw_token); in qh_completions()
1518 if ((HALT_BIT & qh->hw_token) == 0) { in qh_completions()
1520 qh->hw_token |= HALT_BIT; in qh_completions()
1526 qtd_copy_status(oxu, urb->complete ? in qh_completions()
1527 urb : ((struct oxu_murb *) urb)->main, in qh_completions()
1528 qtd->length, token); in qh_completions()
1529 if ((usb_pipein(qtd->urb->pipe)) && in qh_completions()
1530 (NULL != qtd->transfer_buffer)) in qh_completions()
1531 memcpy(qtd->transfer_buffer, qtd->buffer, qtd->length); in qh_completions()
1532 do_status = (urb->status == -EREMOTEIO) in qh_completions()
1533 && usb_pipecontrol(urb->pipe); in qh_completions()
1535 if (stopped && qtd->qtd_list.prev != &qh->qtd_list) { in qh_completions()
1536 last = list_entry(qtd->qtd_list.prev, in qh_completions()
1538 last->hw_next = qtd->hw_next; in qh_completions()
1540 list_del(&qtd->qtd_list); in qh_completions()
1546 if (last->urb->complete == NULL) { in qh_completions()
1547 murb = (struct oxu_murb *) last->urb; in qh_completions()
1548 last->urb = murb->main; in qh_completions()
1549 if (murb->last) { in qh_completions()
1550 ehci_urb_done(oxu, last->urb); in qh_completions()
1555 ehci_urb_done(oxu, last->urb); in qh_completions()
1562 qh->qh_state = state; in qh_completions()
1568 if (stopped != 0 || qh->hw_qtd_next == EHCI_LIST_END) { in qh_completions()
1578 & qh->hw_info2) != 0) { in qh_completions()
1605 list_del(&qtd->qtd_list); in qtd_list_free()
1631 list_add_tail(&qtd->qtd_list, head); in qh_urb_transaction()
1632 qtd->urb = urb; in qh_urb_transaction()
1638 len = urb->transfer_buffer_length; in qh_urb_transaction()
1639 is_input = usb_pipein(urb->pipe); in qh_urb_transaction()
1640 if (!urb->transfer_buffer && urb->transfer_buffer_length && is_input) in qh_urb_transaction()
1641 urb->transfer_buffer = phys_to_virt(urb->transfer_dma); in qh_urb_transaction()
1643 if (usb_pipecontrol(urb->pipe)) { in qh_urb_transaction()
1649 qtd_fill(qtd, qtd->buffer_dma, sizeof(struct usb_ctrlrequest), in qh_urb_transaction()
1651 memcpy(qtd->buffer, qtd->urb->setup_packet, in qh_urb_transaction()
1660 qtd->urb = urb; in qh_urb_transaction()
1661 qtd_prev->hw_next = QTD_NEXT(qtd->qtd_dma); in qh_urb_transaction()
1662 list_add_tail(&qtd->qtd_list, head); in qh_urb_transaction()
1677 buf = qtd->buffer_dma; in qh_urb_transaction()
1678 transfer_buf = urb->transfer_buffer; in qh_urb_transaction()
1681 memcpy(qtd->buffer, qtd->urb->transfer_buffer, len); in qh_urb_transaction()
1687 maxpacket = max_packet(usb_maxpacket(urb->dev, urb->pipe, !is_input)); in qh_urb_transaction()
1698 qtd->transfer_buffer = transfer_buf; in qh_urb_transaction()
1699 len -= this_qtd_len; in qh_urb_transaction()
1703 qtd->hw_alt_next = oxu->async->hw_alt_next; in qh_urb_transaction()
1706 if ((maxpacket & (this_qtd_len + (maxpacket - 1))) == 0) in qh_urb_transaction()
1721 qtd->urb = urb; in qh_urb_transaction()
1722 qtd_prev->hw_next = QTD_NEXT(qtd->qtd_dma); in qh_urb_transaction()
1723 list_add_tail(&qtd->qtd_list, head); in qh_urb_transaction()
1729 if (likely((urb->transfer_flags & URB_SHORT_NOT_OK) == 0 in qh_urb_transaction()
1730 || usb_pipecontrol(urb->pipe))) in qh_urb_transaction()
1731 qtd->hw_alt_next = EHCI_LIST_END; in qh_urb_transaction()
1737 if (likely(urb->transfer_buffer_length != 0)) { in qh_urb_transaction()
1740 if (usb_pipecontrol(urb->pipe)) { in qh_urb_transaction()
1742 token ^= 0x0100; /* "in" <--> "out" */ in qh_urb_transaction()
1744 } else if (usb_pipebulk(urb->pipe) in qh_urb_transaction()
1745 && (urb->transfer_flags & URB_ZERO_PACKET) in qh_urb_transaction()
1746 && !(urb->transfer_buffer_length % maxpacket)) { in qh_urb_transaction()
1754 qtd->urb = urb; in qh_urb_transaction()
1755 qtd_prev->hw_next = QTD_NEXT(qtd->qtd_dma); in qh_urb_transaction()
1756 list_add_tail(&qtd->qtd_list, head); in qh_urb_transaction()
1764 qtd->hw_token |= cpu_to_le32(QTD_IOC); in qh_urb_transaction()
1776 * just one microframe in the s-mask. For split interrupt transactions
1777 * there are additional complications: c-mask, maybe FSTNs.
1793 info1 |= usb_pipeendpoint(urb->pipe) << 8; in qh_make()
1794 info1 |= usb_pipedevice(urb->pipe) << 0; in qh_make()
1796 is_input = usb_pipein(urb->pipe); in qh_make()
1797 type = usb_pipetype(urb->pipe); in qh_make()
1798 maxp = usb_maxpacket(urb->dev, urb->pipe, !is_input); in qh_make()
1801 * - allowing for high bandwidth, how many nsec/uframe are used? in qh_make()
1802 * - split transactions need a second CSPLIT uframe; same question in qh_make()
1803 * - splits also need a schedule gap (for full/low speed I/O) in qh_make()
1804 * - qh has a polling interval in qh_make()
1809 qh->usecs = NS_TO_US(usb_calc_bus_time(USB_SPEED_HIGH, in qh_make()
1812 qh->start = NO_FRAME; in qh_make()
1814 if (urb->dev->speed == USB_SPEED_HIGH) { in qh_make()
1815 qh->c_usecs = 0; in qh_make()
1816 qh->gap_uf = 0; in qh_make()
1818 qh->period = urb->interval >> 3; in qh_make()
1819 if (qh->period == 0 && urb->interval != 1) { in qh_make()
1825 urb->interval); in qh_make()
1829 struct usb_tt *tt = urb->dev->tt; in qh_make()
1833 qh->gap_uf = 1 + usb_calc_bus_time(urb->dev->speed, in qh_make()
1838 qh->c_usecs = qh->usecs + HS_USECS(0); in qh_make()
1839 qh->usecs = HS_USECS(1); in qh_make()
1841 qh->usecs += HS_USECS(1); in qh_make()
1842 qh->c_usecs = HS_USECS(0); in qh_make()
1845 think_time = tt ? tt->think_time : 0; in qh_make()
1846 qh->tt_usecs = NS_TO_US(think_time + in qh_make()
1847 usb_calc_bus_time(urb->dev->speed, in qh_make()
1849 qh->period = urb->interval; in qh_make()
1854 qh->dev = urb->dev; in qh_make()
1857 switch (urb->dev->speed) { in qh_make()
1873 info2 |= urb->dev->ttport << 23; in qh_make()
1875 /* NOTE: if (PIPE_INTERRUPT) { scheduler sets c-mask } */ in qh_make()
1896 oxu_dbg(oxu, "bogus dev %p speed %d\n", urb->dev, urb->dev->speed); in qh_make()
1902 /* NOTE: if (PIPE_INTERRUPT) { scheduler sets s-mask } */ in qh_make()
1905 qh->qh_state = QH_STATE_IDLE; in qh_make()
1906 qh->hw_info1 = cpu_to_le32(info1); in qh_make()
1907 qh->hw_info2 = cpu_to_le32(info2); in qh_make()
1908 usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), !is_input, 1); in qh_make()
1917 __le32 dma = QH_NEXT(qh->qh_dma); in qh_link_async()
1921 head = oxu->async; in qh_link_async()
1923 if (!head->qh_next.qh) { in qh_link_async()
1924 u32 cmd = readl(&oxu->regs->command); in qh_link_async()
1928 (void)handshake(oxu, &oxu->regs->status, in qh_link_async()
1931 writel(cmd, &oxu->regs->command); in qh_link_async()
1932 oxu_to_hcd(oxu)->state = HC_STATE_RUNNING; in qh_link_async()
1938 if (qh->qh_state == QH_STATE_IDLE) in qh_link_async()
1942 qh->qh_next = head->qh_next; in qh_link_async()
1943 qh->hw_next = head->hw_next; in qh_link_async()
1946 head->qh_next.qh = qh; in qh_link_async()
1947 head->hw_next = dma; in qh_link_async()
1949 qh->qh_state = QH_STATE_LINKED; in qh_link_async()
1969 /* can't sleep here, we have oxu->lock... */ in qh_append_tds()
1979 qtd = list_entry(qtd_list->next, struct ehci_qtd, in qh_append_tds()
1986 if (usb_pipedevice(urb->pipe) == 0) in qh_append_tds()
1987 qh->hw_info1 &= ~QH_ADDR_MASK; in qh_append_tds()
2003 token = qtd->hw_token; in qh_append_tds()
2004 qtd->hw_token = HALT_BIT; in qh_append_tds()
2006 dummy = qh->dummy; in qh_append_tds()
2008 dma = dummy->qtd_dma; in qh_append_tds()
2010 dummy->qtd_dma = dma; in qh_append_tds()
2012 list_del(&qtd->qtd_list); in qh_append_tds()
2013 list_add(&dummy->qtd_list, qtd_list); in qh_append_tds()
2014 list_splice(qtd_list, qh->qtd_list.prev); in qh_append_tds()
2016 ehci_qtd_init(qtd, qtd->qtd_dma); in qh_append_tds()
2017 qh->dummy = qtd; in qh_append_tds()
2020 dma = qtd->qtd_dma; in qh_append_tds()
2021 qtd = list_entry(qh->qtd_list.prev, in qh_append_tds()
2023 qtd->hw_next = QTD_NEXT(dma); in qh_append_tds()
2026 dummy->hw_token = (token & ~(0x80)); in qh_append_tds()
2028 dummy->hw_token = token; in qh_append_tds()
2030 urb->hcpriv = qh_get(qh); in qh_append_tds()
2039 int epnum = urb->ep->desc.bEndpointAddress; in submit_async()
2046 qtd = list_entry(qtd_list->next, struct ehci_qtd, qtd_list); in submit_async()
2049 __func__, urb->dev->devpath, urb, in submit_async()
2051 urb->transfer_buffer_length, in submit_async()
2052 qtd, urb->ep->hcpriv); in submit_async()
2055 spin_lock_irqsave(&oxu->lock, flags); in submit_async()
2057 rc = -ESHUTDOWN; in submit_async()
2061 qh = qh_append_tds(oxu, urb, qtd_list, epnum, &urb->ep->hcpriv); in submit_async()
2063 rc = -ENOMEM; in submit_async()
2070 if (likely(qh->qh_state == QH_STATE_IDLE)) in submit_async()
2073 spin_unlock_irqrestore(&oxu->lock, flags); in submit_async()
2083 struct ehci_qh *qh = oxu->reclaim; in end_unlink_async()
2088 qh->qh_state = QH_STATE_IDLE; in end_unlink_async()
2089 qh->qh_next.qh = NULL; in end_unlink_async()
2093 next = qh->reclaim; in end_unlink_async()
2094 oxu->reclaim = next; in end_unlink_async()
2095 oxu->reclaim_ready = 0; in end_unlink_async()
2096 qh->reclaim = NULL; in end_unlink_async()
2100 if (!list_empty(&qh->qtd_list) in end_unlink_async()
2101 && HC_IS_RUNNING(oxu_to_hcd(oxu)->state)) in end_unlink_async()
2109 if (HC_IS_RUNNING(oxu_to_hcd(oxu)->state) in end_unlink_async()
2110 && oxu->async->qh_next.qh == NULL) in end_unlink_async()
2115 oxu->reclaim = NULL; in end_unlink_async()
2121 /* caller must own oxu->lock */
2125 int cmd = readl(&oxu->regs->command); in start_unlink_async()
2129 assert_spin_locked(&oxu->lock); in start_unlink_async()
2130 BUG_ON(oxu->reclaim || (qh->qh_state != QH_STATE_LINKED in start_unlink_async()
2131 && qh->qh_state != QH_STATE_UNLINK_WAIT)); in start_unlink_async()
2135 if (unlikely(qh == oxu->async)) { in start_unlink_async()
2137 if (oxu_to_hcd(oxu)->state != HC_STATE_HALT in start_unlink_async()
2138 && !oxu->reclaim) { in start_unlink_async()
2140 writel(cmd & ~CMD_ASE, &oxu->regs->command); in start_unlink_async()
2148 qh->qh_state = QH_STATE_UNLINK; in start_unlink_async()
2149 oxu->reclaim = qh = qh_get(qh); in start_unlink_async()
2151 prev = oxu->async; in start_unlink_async()
2152 while (prev->qh_next.qh != qh) in start_unlink_async()
2153 prev = prev->qh_next.qh; in start_unlink_async()
2155 prev->hw_next = qh->hw_next; in start_unlink_async()
2156 prev->qh_next = qh->qh_next; in start_unlink_async()
2159 if (unlikely(oxu_to_hcd(oxu)->state == HC_STATE_HALT)) { in start_unlink_async()
2160 /* if (unlikely(qh->reclaim != 0)) in start_unlink_async()
2167 oxu->reclaim_ready = 0; in start_unlink_async()
2169 writel(cmd, &oxu->regs->command); in start_unlink_async()
2170 (void) readl(&oxu->regs->command); in start_unlink_async()
2179 if (!++(oxu->stamp)) in scan_async()
2180 oxu->stamp++; in scan_async()
2183 qh = oxu->async->qh_next.qh; in scan_async()
2187 if (!list_empty(&qh->qtd_list) in scan_async()
2188 && qh->stamp != oxu->stamp) { in scan_async()
2197 qh->stamp = oxu->stamp; in scan_async()
2205 * as HCD schedule-scanning costs. delay for any qh in scan_async()
2206 * we just scanned, there's a not-unusual case that it in scan_async()
2208 * (plus, avoids some kind of re-activation race.) in scan_async()
2210 if (list_empty(&qh->qtd_list)) { in scan_async()
2211 if (qh->stamp == oxu->stamp) in scan_async()
2213 else if (!oxu->reclaim in scan_async()
2214 && qh->qh_state == QH_STATE_LINKED) in scan_async()
2218 qh = qh->qh_next.qh; in scan_async()
2226 * periodic_next_shadow - return "next" pointer on shadow list
2236 return &periodic->qh->qh_next; in periodic_next_shadow()
2240 /* caller must hold oxu->lock */
2243 union ehci_shadow *prev_p = &oxu->pshadow[frame]; in periodic_unlink()
2244 __le32 *hw_p = &oxu->periodic[frame]; in periodic_unlink()
2268 __le32 *hw_p = &oxu->periodic[frame]; in periodic_usecs()
2269 union ehci_shadow *q = &oxu->pshadow[frame]; in periodic_usecs()
2272 while (q->ptr) { in periodic_usecs()
2276 /* is it in the S-mask? */ in periodic_usecs()
2277 if (q->qh->hw_info2 & cpu_to_le32(1 << uframe)) in periodic_usecs()
2278 usecs += q->qh->usecs; in periodic_usecs()
2279 /* ... or C-mask? */ in periodic_usecs()
2280 if (q->qh->hw_info2 & cpu_to_le32(1 << (8 + uframe))) in periodic_usecs()
2281 usecs += q->qh->c_usecs; in periodic_usecs()
2282 hw_p = &q->qh->hw_next; in periodic_usecs()
2283 q = &q->qh->qh_next; in periodic_usecs()
2289 oxu_err(oxu, "uframe %d sched overrun: %d usecs\n", in periodic_usecs()
2303 status = handshake(oxu, &oxu->regs->status, STS_PSS, 0, 9 * 125); in enable_periodic()
2305 oxu_to_hcd(oxu)->state = HC_STATE_HALT; in enable_periodic()
2310 cmd = readl(&oxu->regs->command) | CMD_PSE; in enable_periodic()
2311 writel(cmd, &oxu->regs->command); in enable_periodic()
2313 oxu_to_hcd(oxu)->state = HC_STATE_RUNNING; in enable_periodic()
2316 oxu->next_uframe = readl(&oxu->regs->frame_index) in enable_periodic()
2317 % (oxu->periodic_size << 3); in enable_periodic()
2329 status = handshake(oxu, &oxu->regs->status, STS_PSS, STS_PSS, 9 * 125); in disable_periodic()
2331 oxu_to_hcd(oxu)->state = HC_STATE_HALT; in disable_periodic()
2336 cmd = readl(&oxu->regs->command) & ~CMD_PSE; in disable_periodic()
2337 writel(cmd, &oxu->regs->command); in disable_periodic()
2340 oxu->next_uframe = -1; in disable_periodic()
2353 unsigned period = qh->period; in qh_link_periodic()
2355 dev_dbg(&qh->dev->dev, in qh_link_periodic()
2356 "link qh%d-%04x/%p start %d [%d/%d us]\n", in qh_link_periodic()
2357 period, le32_to_cpup(&qh->hw_info2) & (QH_CMASK | QH_SMASK), in qh_link_periodic()
2358 qh, qh->start, qh->usecs, qh->c_usecs); in qh_link_periodic()
2364 for (i = qh->start; i < oxu->periodic_size; i += period) { in qh_link_periodic()
2365 union ehci_shadow *prev = &oxu->pshadow[i]; in qh_link_periodic()
2366 __le32 *hw_p = &oxu->periodic[i]; in qh_link_periodic()
2376 hw_p = &here.qh->hw_next; in qh_link_periodic()
2380 /* sorting each branch by period (slow-->fast) in qh_link_periodic()
2384 if (qh->period > here.qh->period) in qh_link_periodic()
2386 prev = &here.qh->qh_next; in qh_link_periodic()
2387 hw_p = &here.qh->hw_next; in qh_link_periodic()
2392 qh->qh_next = here; in qh_link_periodic()
2394 qh->hw_next = *hw_p; in qh_link_periodic()
2396 prev->qh = qh; in qh_link_periodic()
2397 *hw_p = QH_NEXT(qh->qh_dma); in qh_link_periodic()
2400 qh->qh_state = QH_STATE_LINKED; in qh_link_periodic()
2403 /* update per-qh bandwidth for usbfs */ in qh_link_periodic()
2404 oxu_to_hcd(oxu)->self.bandwidth_allocated += qh->period in qh_link_periodic()
2405 ? ((qh->usecs + qh->c_usecs) / qh->period) in qh_link_periodic()
2406 : (qh->usecs * 8); in qh_link_periodic()
2409 if (!oxu->periodic_sched++) in qh_link_periodic()
2425 * qh->hw_info1 |= cpu_to_le32(1 << 7 "ignore"); in qh_unlink_periodic()
2429 period = qh->period; in qh_unlink_periodic()
2433 for (i = qh->start; i < oxu->periodic_size; i += period) in qh_unlink_periodic()
2436 /* update per-qh bandwidth for usbfs */ in qh_unlink_periodic()
2437 oxu_to_hcd(oxu)->self.bandwidth_allocated -= qh->period in qh_unlink_periodic()
2438 ? ((qh->usecs + qh->c_usecs) / qh->period) in qh_unlink_periodic()
2439 : (qh->usecs * 8); in qh_unlink_periodic()
2441 dev_dbg(&qh->dev->dev, in qh_unlink_periodic()
2442 "unlink qh%d-%04x/%p start %d [%d/%d us]\n", in qh_unlink_periodic()
2443 qh->period, in qh_unlink_periodic()
2444 le32_to_cpup(&qh->hw_info2) & (QH_CMASK | QH_SMASK), in qh_unlink_periodic()
2445 qh, qh->start, qh->usecs, qh->c_usecs); in qh_unlink_periodic()
2447 /* qh->qh_next still "live" to HC */ in qh_unlink_periodic()
2448 qh->qh_state = QH_STATE_UNLINK; in qh_unlink_periodic()
2449 qh->qh_next.ptr = NULL; in qh_unlink_periodic()
2453 oxu->periodic_sched--; in qh_unlink_periodic()
2454 if (!oxu->periodic_sched) in qh_unlink_periodic()
2465 * qh->hw_next or finish a writeback after SPLIT/CSPLIT ... and in intr_deschedule()
2469 if (list_empty(&qh->qtd_list) in intr_deschedule()
2470 || (cpu_to_le32(QH_CMASK) & qh->hw_info2) != 0) in intr_deschedule()
2476 qh->qh_state = QH_STATE_IDLE; in intr_deschedule()
2477 qh->hw_next = EHCI_LIST_END; in intr_deschedule()
2497 usecs = 100 - usecs; in check_period()
2509 } while ((frame += 1) < oxu->periodic_size); in check_period()
2517 } while ((frame += period) < oxu->periodic_size); in check_period()
2527 int retval = -ENOSPC; in check_intr_schedule()
2529 if (qh->c_usecs && uframe >= 6) /* FSTN territory? */ in check_intr_schedule()
2532 if (!check_period(oxu, frame, uframe, qh->period, qh->usecs)) in check_intr_schedule()
2534 if (!qh->c_usecs) { in check_intr_schedule()
2545 * or when the previous schedule slot can't be re-used.
2552 unsigned frame; /* 0..(qh->period - 1), or NO_FRAME */ in qh_schedule()
2555 qh->hw_next = EHCI_LIST_END; in qh_schedule()
2556 frame = qh->start; in qh_schedule()
2559 if (frame < qh->period) { in qh_schedule()
2560 uframe = ffs(le32_to_cpup(&qh->hw_info2) & QH_SMASK); in qh_schedule()
2561 status = check_intr_schedule(oxu, frame, --uframe, in qh_schedule()
2566 status = -ENOSPC; in qh_schedule()
2574 if (qh->period) { in qh_schedule()
2575 frame = qh->period - 1; in qh_schedule()
2584 } while (status && frame--); in qh_schedule()
2586 /* qh->period == 0 means every uframe */ in qh_schedule()
2593 qh->start = frame; in qh_schedule()
2595 /* reset S-frame and (maybe) C-frame masks */ in qh_schedule()
2596 qh->hw_info2 &= cpu_to_le32(~(QH_CMASK | QH_SMASK)); in qh_schedule()
2597 qh->hw_info2 |= qh->period in qh_schedule()
2600 qh->hw_info2 |= c_mask; in qh_schedule()
2620 epnum = urb->ep->desc.bEndpointAddress; in intr_submit()
2622 spin_lock_irqsave(&oxu->lock, flags); in intr_submit()
2625 status = -ESHUTDOWN; in intr_submit()
2631 qh = qh_append_tds(oxu, urb, &empty, epnum, &urb->ep->hcpriv); in intr_submit()
2633 status = -ENOMEM; in intr_submit()
2636 if (qh->qh_state == QH_STATE_IDLE) { in intr_submit()
2643 qh = qh_append_tds(oxu, urb, qtd_list, epnum, &urb->ep->hcpriv); in intr_submit()
2647 oxu_to_hcd(oxu)->self.bandwidth_int_reqs++; in intr_submit()
2650 spin_unlock_irqrestore(&oxu->lock, flags); in intr_submit()
2661 return -ENOSYS; in itd_submit()
2668 return -ENOSYS; in sitd_submit()
2676 mod = oxu->periodic_size << 3; in scan_periodic()
2681 * Touches as few pages as possible: cache-friendly. in scan_periodic()
2683 now_uframe = oxu->next_uframe; in scan_periodic()
2684 if (HC_IS_RUNNING(oxu_to_hcd(oxu)->state)) in scan_periodic()
2685 clock = readl(&oxu->regs->frame_index); in scan_periodic()
2687 clock = now_uframe + mod - 1; in scan_periodic()
2703 q_p = &oxu->pshadow[frame]; in scan_periodic()
2704 hw_p = &oxu->periodic[frame]; in scan_periodic()
2705 q.ptr = q_p->ptr; in scan_periodic()
2716 type = Q_NEXT_TYPE(q.qh->hw_next); in scan_periodic()
2717 q = q.qh->qh_next; in scan_periodic()
2719 if (unlikely(list_empty(&temp.qh->qtd_list))) in scan_periodic()
2743 /* FIXME: likewise assumes HC doesn't halt mid-scan */ in scan_periodic()
2748 if (!HC_IS_RUNNING(oxu_to_hcd(oxu)->state)) in scan_periodic()
2750 oxu->next_uframe = now_uframe; in scan_periodic()
2751 now = readl(&oxu->regs->frame_index) % mod; in scan_periodic()
2770 int port = HCS_N_PORTS(oxu->hcs_params); in ehci_turn_off_all_ports()
2772 while (port--) in ehci_turn_off_all_ports()
2773 writel(PORT_RWC_BITS, &oxu->regs->port_status[port]); in ehci_turn_off_all_ports()
2780 if (!HCS_PPC(oxu->hcs_params)) in ehci_port_power()
2784 for (port = HCS_N_PORTS(oxu->hcs_params); port > 0; ) { in ehci_port_power()
2787 USB_PORT_FEAT_POWER, port--, NULL, 0); in ehci_port_power()
2790 USB_PORT_FEAT_POWER, port--, NULL, 0); in ehci_port_power()
2797 * It calls driver completion functions, after dropping oxu->lock.
2802 if (oxu->reclaim_ready) in ehci_work()
2805 /* another CPU may drop oxu->lock during a schedule scan while in ehci_work()
2807 * attempts at re-entrant schedule scanning. in ehci_work()
2809 if (oxu->scanning) in ehci_work()
2811 oxu->scanning = 1; in ehci_work()
2813 if (oxu->next_uframe != -1) in ehci_work()
2815 oxu->scanning = 0; in ehci_work()
2821 if (HC_IS_RUNNING(oxu_to_hcd(oxu)->state) && in ehci_work()
2822 (oxu->async->qh_next.ptr != NULL || in ehci_work()
2823 oxu->periodic_sched != 0)) in ehci_work()
2830 if (qh->qh_state == QH_STATE_LINKED in unlink_async()
2831 && oxu->reclaim in unlink_async()
2832 && HC_IS_RUNNING(oxu_to_hcd(oxu)->state)) { in unlink_async()
2835 for (last = oxu->reclaim; in unlink_async()
2836 last->reclaim; in unlink_async()
2837 last = last->reclaim) in unlink_async()
2839 qh->qh_state = QH_STATE_UNLINK_WAIT; in unlink_async()
2840 last->reclaim = qh; in unlink_async()
2843 } else if (!HC_IS_RUNNING(oxu_to_hcd(oxu)->state) && oxu->reclaim) in unlink_async()
2847 if (qh->qh_state == QH_STATE_LINKED) in unlink_async()
2861 spin_lock(&oxu->lock); in oxu210_hcd_irq()
2863 status = readl(&oxu->regs->status); in oxu210_hcd_irq()
2873 if (!status || unlikely(hcd->state == HC_STATE_HALT)) { in oxu210_hcd_irq()
2874 spin_unlock(&oxu->lock); in oxu210_hcd_irq()
2879 writel(status, &oxu->regs->status); in oxu210_hcd_irq()
2880 readl(&oxu->regs->command); /* unblock posted write */ in oxu210_hcd_irq()
2896 oxu->reclaim_ready = 1; in oxu210_hcd_irq()
2902 unsigned i = HCS_N_PORTS(oxu->hcs_params); in oxu210_hcd_irq()
2906 if (!(readl(&oxu->regs->command) & CMD_RUN)) in oxu210_hcd_irq()
2909 while (i--) { in oxu210_hcd_irq()
2910 int pstatus = readl(&oxu->regs->port_status[i]); in oxu210_hcd_irq()
2915 || oxu->reset_done[i] != 0) in oxu210_hcd_irq()
2922 oxu->reset_done[i] = jiffies + in oxu210_hcd_irq()
2925 mod_timer(&hcd->rh_timer, oxu->reset_done[i]); in oxu210_hcd_irq()
2932 status = readl(&oxu->regs->status); in oxu210_hcd_irq()
2933 dbg_cmd(oxu, "fatal", readl(&oxu->regs->command)); in oxu210_hcd_irq()
2939 writel(0, &oxu->regs->configured_flag); in oxu210_hcd_irq()
2950 spin_unlock(&oxu->lock); in oxu210_hcd_irq()
2961 u32 status = oxu_readl(hcd->regs, OXU_CHIPIRQSTATUS); in oxu_irq()
2962 u32 enable = oxu_readl(hcd->regs, OXU_CHIPIRQEN_SET); in oxu_irq()
2965 oxu_writel(hcd->regs, OXU_CHIPIRQEN_CLR, enable); in oxu_irq()
2967 if ((oxu->is_otg && (status & OXU_USBOTGI)) || in oxu_irq()
2968 (!oxu->is_otg && (status & OXU_USBSPHI))) in oxu_irq()
2974 oxu_writel(hcd->regs, OXU_CHIPIRQEN_SET, enable); in oxu_irq()
2984 spin_lock_irqsave(&oxu->lock, flags); in oxu_watchdog()
2987 if (oxu->reclaim) { in oxu_watchdog()
2988 u32 status = readl(&oxu->regs->status); in oxu_watchdog()
2991 writel(STS_IAA, &oxu->regs->status); in oxu_watchdog()
2992 oxu->reclaim_ready = 1; in oxu_watchdog()
2997 if (test_bit(TIMER_ASYNC_OFF, &oxu->actions)) in oxu_watchdog()
2998 start_unlink_async(oxu, oxu->async); in oxu_watchdog()
3003 spin_unlock_irqrestore(&oxu->lock, flags); in oxu_watchdog()
3006 /* One-time init, only for memory state.
3015 spin_lock_init(&oxu->lock); in oxu_hcd_init()
3017 timer_setup(&oxu->watchdog, oxu_watchdog, 0); in oxu_hcd_init()
3023 oxu->periodic_size = DEFAULT_I_TDPS; in oxu_hcd_init()
3029 hcc_params = readl(&oxu->caps->hcc_params); in oxu_hcd_init()
3031 oxu->i_thresh = 8; in oxu_hcd_init()
3033 oxu->i_thresh = 2 + HCC_ISOC_THRES(hcc_params); in oxu_hcd_init()
3035 oxu->reclaim = NULL; in oxu_hcd_init()
3036 oxu->reclaim_ready = 0; in oxu_hcd_init()
3037 oxu->next_uframe = -1; in oxu_hcd_init()
3046 oxu->async->qh_next.qh = NULL; in oxu_hcd_init()
3047 oxu->async->hw_next = QH_NEXT(oxu->async->qh_dma); in oxu_hcd_init()
3048 oxu->async->hw_info1 = cpu_to_le32(QH_HEAD); in oxu_hcd_init()
3049 oxu->async->hw_token = cpu_to_le32(QTD_STS_HALT); in oxu_hcd_init()
3050 oxu->async->hw_qtd_next = EHCI_LIST_END; in oxu_hcd_init()
3051 oxu->async->qh_state = QH_STATE_LINKED; in oxu_hcd_init()
3052 oxu->async->hw_alt_next = QTD_NEXT(oxu->async->dummy->qtd_dma); in oxu_hcd_init()
3078 oxu->command = temp; in oxu_hcd_init()
3089 spin_lock_init(&oxu->mem_lock); in oxu_reset()
3090 INIT_LIST_HEAD(&oxu->urb_list); in oxu_reset()
3091 oxu->urb_len = 0; in oxu_reset()
3093 if (oxu->is_otg) { in oxu_reset()
3094 oxu->caps = hcd->regs + OXU_OTG_CAP_OFFSET; in oxu_reset()
3095 oxu->regs = hcd->regs + OXU_OTG_CAP_OFFSET + \ in oxu_reset()
3096 HC_LENGTH(readl(&oxu->caps->hc_capbase)); in oxu_reset()
3098 oxu->mem = hcd->regs + OXU_SPH_MEM; in oxu_reset()
3100 oxu->caps = hcd->regs + OXU_SPH_CAP_OFFSET; in oxu_reset()
3101 oxu->regs = hcd->regs + OXU_SPH_CAP_OFFSET + \ in oxu_reset()
3102 HC_LENGTH(readl(&oxu->caps->hc_capbase)); in oxu_reset()
3104 oxu->mem = hcd->regs + OXU_OTG_MEM; in oxu_reset()
3107 oxu->hcs_params = readl(&oxu->caps->hcs_params); in oxu_reset()
3108 oxu->sbrn = 0x20; in oxu_reset()
3119 hcd->uses_new_polling = 1; in oxu_run()
3127 writel(oxu->periodic_dma, &oxu->regs->frame_list); in oxu_run()
3128 writel((u32) oxu->async->qh_dma, &oxu->regs->async_next); in oxu_run()
3130 /* hcc_params controls whether oxu->regs->segment must (!!!) in oxu_run()
3136 * NOTE: the dma mask is visible through dev->dma_mask, so in oxu_run()
3141 hcc_params = readl(&oxu->caps->hcc_params); in oxu_run()
3143 writel(0, &oxu->regs->segment); in oxu_run()
3145 oxu->command &= ~(CMD_LRESET | CMD_IAAD | CMD_PSE | in oxu_run()
3147 oxu->command |= CMD_RUN; in oxu_run()
3148 writel(oxu->command, &oxu->regs->command); in oxu_run()
3149 dbg_cmd(oxu, "init", oxu->command); in oxu_run()
3157 hcd->state = HC_STATE_RUNNING; in oxu_run()
3158 writel(FLAG_CF, &oxu->regs->configured_flag); in oxu_run()
3159 readl(&oxu->regs->command); /* unblock posted writes */ in oxu_run()
3161 temp = HC_VERSION(readl(&oxu->caps->hc_capbase)); in oxu_run()
3162 oxu_info(oxu, "USB %x.%x started, quasi-EHCI %x.%02x, driver %s%s\n", in oxu_run()
3163 ((oxu->sbrn & 0xf0)>>4), (oxu->sbrn & 0x0f), in oxu_run()
3167 writel(INTR_MASK, &oxu->regs->intr_enable); /* Turn On Interrupts */ in oxu_run()
3180 del_timer_sync(&oxu->watchdog); in oxu_stop()
3182 spin_lock_irq(&oxu->lock); in oxu_stop()
3183 if (HC_IS_RUNNING(hcd->state)) in oxu_stop()
3187 writel(0, &oxu->regs->intr_enable); in oxu_stop()
3188 spin_unlock_irq(&oxu->lock); in oxu_stop()
3191 writel(0, &oxu->regs->configured_flag); in oxu_stop()
3194 spin_lock_irq(&oxu->lock); in oxu_stop()
3195 if (oxu->async) in oxu_stop()
3197 spin_unlock_irq(&oxu->lock); in oxu_stop()
3200 dbg_status(oxu, "oxu_stop completed", readl(&oxu->regs->status)); in oxu_stop()
3215 writel(0, &oxu->regs->configured_flag); in oxu_shutdown()
3218 readl(&oxu->regs->configured_flag); in oxu_shutdown()
3221 /* Non-error returns are a promise to giveback() the urb later
3227 * hcd-specific init for hcpriv hasn't been done yet
3240 switch (usb_pipetype(urb->pipe)) { in __oxu_urb_enqueue()
3245 return -ENOMEM; in __oxu_urb_enqueue()
3250 return -ENOMEM; in __oxu_urb_enqueue()
3254 if (urb->dev->speed == USB_SPEED_HIGH) in __oxu_urb_enqueue()
3274 if (!usb_pipebulk(urb->pipe)) in oxu_urb_enqueue()
3278 transfer_buffer = urb->transfer_buffer; in oxu_urb_enqueue()
3280 num = urb->transfer_buffer_length / 4096; in oxu_urb_enqueue()
3281 rem = urb->transfer_buffer_length % 4096; in oxu_urb_enqueue()
3291 for (i = 0; i < num - 1; i++) { in oxu_urb_enqueue()
3303 murb->transfer_buffer_length = 4096; in oxu_urb_enqueue()
3304 murb->transfer_buffer = transfer_buffer + i * 4096; in oxu_urb_enqueue()
3307 murb->complete = NULL; in oxu_urb_enqueue()
3309 ((struct oxu_murb *) murb)->main = urb; in oxu_urb_enqueue()
3310 ((struct oxu_murb *) murb)->last = 0; in oxu_urb_enqueue()
3334 murb->transfer_buffer_length = rem > 0 ? rem : 4096; in oxu_urb_enqueue()
3335 murb->transfer_buffer = transfer_buffer + (num - 1) * 4096; in oxu_urb_enqueue()
3338 murb->complete = NULL; in oxu_urb_enqueue()
3340 ((struct oxu_murb *) murb)->main = urb; in oxu_urb_enqueue()
3341 ((struct oxu_murb *) murb)->last = 1; in oxu_urb_enqueue()
3361 spin_lock_irqsave(&oxu->lock, flags); in oxu_urb_dequeue()
3362 switch (usb_pipetype(urb->pipe)) { in oxu_urb_dequeue()
3366 qh = (struct ehci_qh *) urb->hcpriv; in oxu_urb_dequeue()
3373 qh = (struct ehci_qh *) urb->hcpriv; in oxu_urb_dequeue()
3376 switch (qh->qh_state) { in oxu_urb_dequeue()
3385 qh, qh->qh_state); in oxu_urb_dequeue()
3390 if (!list_empty(&qh->qtd_list) in oxu_urb_dequeue()
3391 && HC_IS_RUNNING(hcd->state)) { in oxu_urb_dequeue()
3395 spin_unlock_irqrestore(&oxu->lock, flags); in oxu_urb_dequeue()
3401 dev_err(hcd->self.controller, in oxu_urb_dequeue()
3410 spin_unlock_irqrestore(&oxu->lock, flags); in oxu_urb_dequeue()
3426 spin_lock_irqsave(&oxu->lock, flags); in oxu_endpoint_disable()
3427 qh = ep->hcpriv; in oxu_endpoint_disable()
3434 if (qh->hw_info1 == 0) { in oxu_endpoint_disable()
3439 if (!HC_IS_RUNNING(hcd->state)) in oxu_endpoint_disable()
3440 qh->qh_state = QH_STATE_IDLE; in oxu_endpoint_disable()
3441 switch (qh->qh_state) { in oxu_endpoint_disable()
3443 for (tmp = oxu->async->qh_next.qh; in oxu_endpoint_disable()
3445 tmp = tmp->qh_next.qh) in oxu_endpoint_disable()
3447 /* periodic qh self-unlinks on empty */ in oxu_endpoint_disable()
3454 spin_unlock_irqrestore(&oxu->lock, flags); in oxu_endpoint_disable()
3458 if (list_empty(&qh->qtd_list)) { in oxu_endpoint_disable()
3469 qh, ep->desc.bEndpointAddress, qh->qh_state, in oxu_endpoint_disable()
3470 list_empty(&qh->qtd_list) ? "" : "(has tds)"); in oxu_endpoint_disable()
3473 ep->hcpriv = NULL; in oxu_endpoint_disable()
3475 spin_unlock_irqrestore(&oxu->lock, flags); in oxu_endpoint_disable()
3482 return (readl(&oxu->regs->frame_index) >> 3) % in oxu_get_frame()
3483 oxu->periodic_size; in oxu_get_frame()
3495 if (!HC_IS_RUNNING(hcd->state)) in oxu_hub_status_data()
3498 /* init status to no-changes */ in oxu_hub_status_data()
3500 ports = HCS_N_PORTS(oxu->hcs_params); in oxu_hub_status_data()
3510 * PORT_POWER; that's surprising, but maybe within-spec. in oxu_hub_status_data()
3520 spin_lock_irqsave(&oxu->lock, flags); in oxu_hub_status_data()
3522 temp = readl(&oxu->regs->port_status[i]); in oxu_hub_status_data()
3527 * high-speed device is switched over to the companion in oxu_hub_status_data()
3532 oxu->reset_done[i] = 0; in oxu_hub_status_data()
3534 time_after_eq(jiffies, oxu->reset_done[i]))) { in oxu_hub_status_data()
3538 buf[1] |= 1 << (i - 7); in oxu_hub_status_data()
3543 spin_unlock_irqrestore(&oxu->lock, flags); in oxu_hub_status_data()
3567 int ports = HCS_N_PORTS(oxu->hcs_params); in oxu_hub_control()
3568 u32 __iomem *status_reg = &oxu->regs->port_status[wIndex - 1]; in oxu_hub_control()
3581 spin_lock_irqsave(&oxu->lock, flags); in oxu_hub_control()
3587 /* no hub-wide feature/status flags */ in oxu_hub_control()
3596 wIndex--; in oxu_hub_control()
3602 * the port-change status bits (especially in oxu_hub_control()
3622 oxu->reset_done[wIndex] = jiffies in oxu_hub_control()
3627 /* we auto-clear this feature */ in oxu_hub_control()
3630 if (HCS_PPC(oxu->hcs_params)) in oxu_hub_control()
3646 readl(&oxu->regs->command); /* unblock posted write */ in oxu_hub_control()
3653 /* no hub-wide feature/status flags */ in oxu_hub_control()
3659 wIndex--; in oxu_hub_control()
3675 if (!oxu->reset_done[wIndex]) { in oxu_hub_control()
3677 oxu->reset_done[wIndex] = jiffies in oxu_hub_control()
3680 mod_timer(&oxu_to_hcd(oxu)->rh_timer, in oxu_hub_control()
3681 oxu->reset_done[wIndex]); in oxu_hub_control()
3686 oxu->reset_done[wIndex])) { in oxu_hub_control()
3688 oxu->reset_done[wIndex] = 0; in oxu_hub_control()
3709 oxu->reset_done[wIndex])) { in oxu_hub_control()
3711 oxu->reset_done[wIndex] = 0; in oxu_hub_control()
3734 test_bit(wIndex, &oxu->companion_ports)) { in oxu_hub_control()
3738 oxu_dbg(oxu, "port %d --> companion\n", wIndex + 1); in oxu_hub_control()
3774 /* no hub-wide feature/status flags */ in oxu_hub_control()
3785 wIndex--; in oxu_hub_control()
3796 if (device_may_wakeup(&hcd->self.root_hub->dev)) in oxu_hub_control()
3801 if (HCS_PPC(oxu->hcs_params)) in oxu_hub_control()
3817 * usb 2.0 spec says 50 ms resets on root in oxu_hub_control()
3819 oxu->reset_done[wIndex] = jiffies in oxu_hub_control()
3828 * about the EHCI-specific stuff. in oxu_hub_control()
3842 readl(&oxu->regs->command); /* unblock posted writes */ in oxu_hub_control()
3848 retval = -EPIPE; in oxu_hub_control()
3850 spin_unlock_irqrestore(&oxu->lock, flags); in oxu_hub_control()
3864 if (time_before(jiffies, oxu->next_statechange)) in oxu_bus_suspend()
3867 port = HCS_N_PORTS(oxu->hcs_params); in oxu_bus_suspend()
3868 spin_lock_irq(&oxu->lock); in oxu_bus_suspend()
3871 if (HC_IS_RUNNING(hcd->state)) { in oxu_bus_suspend()
3873 hcd->state = HC_STATE_QUIESCING; in oxu_bus_suspend()
3875 oxu->command = readl(&oxu->regs->command); in oxu_bus_suspend()
3876 if (oxu->reclaim) in oxu_bus_suspend()
3877 oxu->reclaim_ready = 1; in oxu_bus_suspend()
3881 * any notion of "global" or bus-wide suspend. The driver has in oxu_bus_suspend()
3885 oxu->bus_suspended = 0; in oxu_bus_suspend()
3886 while (port--) { in oxu_bus_suspend()
3887 u32 __iomem *reg = &oxu->regs->port_status[port]; in oxu_bus_suspend()
3895 set_bit(port, &oxu->bus_suspended); in oxu_bus_suspend()
3899 if (device_may_wakeup(&hcd->self.root_hub->dev)) in oxu_bus_suspend()
3905 oxu_vdbg(oxu, "port %d, %08x -> %08x\n", in oxu_bus_suspend()
3911 /* turn off now-idle HC */ in oxu_bus_suspend()
3912 del_timer_sync(&oxu->watchdog); in oxu_bus_suspend()
3914 hcd->state = HC_STATE_SUSPENDED; in oxu_bus_suspend()
3918 if (!device_may_wakeup(&hcd->self.root_hub->dev)) in oxu_bus_suspend()
3920 writel(mask, &oxu->regs->intr_enable); in oxu_bus_suspend()
3921 readl(&oxu->regs->intr_enable); in oxu_bus_suspend()
3923 oxu->next_statechange = jiffies + msecs_to_jiffies(10); in oxu_bus_suspend()
3924 spin_unlock_irq(&oxu->lock); in oxu_bus_suspend()
3935 if (time_before(jiffies, oxu->next_statechange)) in oxu_bus_resume()
3937 spin_lock_irq(&oxu->lock); in oxu_bus_resume()
3941 * could instead be restoring a swsusp snapshot -- so that BIOS was in oxu_bus_resume()
3945 temp = readl(&oxu->regs->intr_enable); in oxu_bus_resume()
3951 writel(0, &oxu->regs->intr_enable); in oxu_bus_resume()
3953 /* re-init operational registers */ in oxu_bus_resume()
3954 writel(0, &oxu->regs->segment); in oxu_bus_resume()
3955 writel(oxu->periodic_dma, &oxu->regs->frame_list); in oxu_bus_resume()
3956 writel((u32) oxu->async->qh_dma, &oxu->regs->async_next); in oxu_bus_resume()
3959 writel(oxu->command, &oxu->regs->command); in oxu_bus_resume()
3966 i = HCS_N_PORTS(oxu->hcs_params); in oxu_bus_resume()
3967 while (i--) { in oxu_bus_resume()
3968 temp = readl(&oxu->regs->port_status[i]); in oxu_bus_resume()
3971 if (test_bit(i, &oxu->bus_suspended) && (temp & PORT_SUSPEND)) { in oxu_bus_resume()
3972 oxu->reset_done[i] = jiffies + msecs_to_jiffies(20); in oxu_bus_resume()
3975 writel(temp, &oxu->regs->port_status[i]); in oxu_bus_resume()
3977 i = HCS_N_PORTS(oxu->hcs_params); in oxu_bus_resume()
3979 while (i--) { in oxu_bus_resume()
3980 temp = readl(&oxu->regs->port_status[i]); in oxu_bus_resume()
3981 if (test_bit(i, &oxu->bus_suspended) && (temp & PORT_SUSPEND)) { in oxu_bus_resume()
3983 writel(temp, &oxu->regs->port_status[i]); in oxu_bus_resume()
3987 (void) readl(&oxu->regs->command); in oxu_bus_resume()
3989 /* maybe re-activate the schedule(s) */ in oxu_bus_resume()
3991 if (oxu->async->qh_next.qh) in oxu_bus_resume()
3993 if (oxu->periodic_sched) in oxu_bus_resume()
3996 oxu->command |= temp; in oxu_bus_resume()
3997 writel(oxu->command, &oxu->regs->command); in oxu_bus_resume()
4000 oxu->next_statechange = jiffies + msecs_to_jiffies(5); in oxu_bus_resume()
4001 hcd->state = HC_STATE_RUNNING; in oxu_bus_resume()
4003 /* Now we can safely re-enable irqs */ in oxu_bus_resume()
4004 writel(INTR_MASK, &oxu->regs->intr_enable); in oxu_bus_resume()
4006 spin_unlock_irq(&oxu->lock); in oxu_bus_resume()
4103 "128-pin LQFP", in oxu_verify_id()
4104 "84-pin TFBGA", in oxu_verify_id()
4110 dev_info(&pdev->dev, "device ID %x\n", id); in oxu_verify_id()
4112 return -1; in oxu_verify_id()
4114 dev_info(&pdev->dev, "found device %x %s (%04x:%04x)\n", in oxu_verify_id()
4128 struct device *dev = &pdev->dev; in oxu_create()
4142 return ERR_PTR(-ENOMEM); in oxu_create()
4144 hcd->rsrc_start = memstart; in oxu_create()
4145 hcd->rsrc_len = memlen; in oxu_create()
4146 hcd->regs = base; in oxu_create()
4147 hcd->irq = irq; in oxu_create()
4148 hcd->state = HC_STATE_HALT; in oxu_create()
4151 oxu->is_otg = otg; in oxu_create()
4157 device_wakeup_enable(hcd->self.controller); in oxu_create()
4174 dev_err(&pdev->dev, "no devices found!\n"); in oxu_init()
4175 return -ENODEV; in oxu_init()
4181 dev_err(&pdev->dev, "cannot create OTG controller!\n"); in oxu_init()
4185 info->hcd[0] = hcd; in oxu_init()
4190 dev_err(&pdev->dev, "cannot create SPH controller!\n"); in oxu_init()
4194 info->hcd[1] = hcd; in oxu_init()
4202 usb_remove_hcd(info->hcd[0]); in oxu_init()
4203 usb_put_hcd(info->hcd[0]); in oxu_init()
4218 return -ENODEV; in oxu_drv_probe()
4225 dev_err(&pdev->dev, in oxu_drv_probe()
4226 "no IRQ! Check %s setup!\n", dev_name(&pdev->dev)); in oxu_drv_probe()
4227 return -ENODEV; in oxu_drv_probe()
4229 irq = res->start; in oxu_drv_probe()
4230 dev_dbg(&pdev->dev, "IRQ resource %d\n", irq); in oxu_drv_probe()
4233 base = devm_ioremap_resource(&pdev->dev, res); 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()
4324 .name = "oxu210hp-hcd",
4331 MODULE_DESCRIPTION("Oxford OXU210HP HCD driver - ver. " DRIVER_VERSION);