Lines Matching +full:oc +full:- +full:delay +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.
14 #include <linux/delay.h>
26 #include <linux/dma-mapping.h>
83 #define EHCI_TUNE_CERR 3 /* 0-3 qtd retries; 0 == don't stop */
86 #define EHCI_TUNE_MULT_HS 1 /* 1-3 transactions/uframe; 4.10.3 */
102 u32 hcs_params; /* HCSPARAMS - offset 0x4 */
111 u32 hcc_params; /* HCCPARAMS - offset 0x8 */
117 #define HCC_64BIT_ADDR(p) ((p)&(1)) /* true: can use 64-bit addr */
118 u8 portroute[8]; /* nibbles for routing - offset 0xC */
205 * See Fig 3-6 "Queue Element Transfer Descriptor Block Diagram".
231 /* the rest is HCD-private */
244 /* mask NakCnt+T in qh->hw_alt_next */
249 /* Type tag from {qh, itd, sitd, fstn}->hw_next */
278 * See Fig 3-7 "Queue Head Structure Layout".
294 __le32 hw_current; /* qtd list - see EHCI 3.6.4 */
303 /* the rest is HCD-private */
345 /* 2 host controllers are enabled - total size <= 28 kbytes */
445 #define EHCI_SHRINK_JIFFIES (HZ/200) /* async qh unlink delay */
459 dev_dbg(oxu_to_hcd(oxu)->self.controller , fmt , ## args)
461 dev_err(oxu_to_hcd(oxu)->self.controller , fmt , ## args)
463 dev_info(oxu_to_hcd(oxu)->self.controller , fmt , ## args)
476 return (struct oxu_hcd *) (hcd->hcd_priv); in hcd_to_oxu()
579 (status & PORT_OC) ? " OC" : "", in dbg_port_buf()
633 MODULE_PARM_DESC(log2_irq_thresh, "log2 IRQ latency, 1-64 microframes");
638 MODULE_PARM_DESC(park, "park setting; 1-3 back-to-back async packets");
669 clear_bit(action, &oxu->actions); in timer_action_done()
675 if (!test_and_set_bit(action, &oxu->actions)) { in timer_action()
700 && t > oxu->watchdog.expires in timer_action()
701 && timer_pending(&oxu->watchdog)) in timer_action()
703 mod_timer(&oxu->watchdog, t); in timer_action()
708 * handshake - spin reading hc until handshake completes or fails
718 * hardware flakeout), or the register reads as all-ones (hardware removed).
735 return -ENODEV; in handshake()
743 u32 temp = readl(&oxu->regs->status); in ehci_halt()
746 writel(0, &oxu->regs->intr_enable); in ehci_halt()
751 temp = readl(&oxu->regs->command); in ehci_halt()
753 writel(temp, &oxu->regs->command); in ehci_halt()
754 return handshake(oxu, &oxu->regs->status, in ehci_halt()
764 reg_ptr = (u32 __iomem *)(((u8 __iomem *)oxu->regs) + 0x68); in tdi_reset()
770 /* Reset a non-running (STS_HALT == 1) controller */
774 u32 command = readl(&oxu->regs->command); in ehci_reset()
778 writel(command, &oxu->regs->command); in ehci_reset()
779 oxu_to_hcd(oxu)->state = HC_STATE_HALT; in ehci_reset()
780 oxu->next_statechange = jiffies; in ehci_reset()
781 retval = handshake(oxu, &oxu->regs->command, in ehci_reset()
798 BUG_ON(!HC_IS_RUNNING(oxu_to_hcd(oxu)->state)); in ehci_quiesce()
802 temp = readl(&oxu->regs->command) << 10; in ehci_quiesce()
804 if (handshake(oxu, &oxu->regs->status, STS_ASS | STS_PSS, in ehci_quiesce()
806 oxu_to_hcd(oxu)->state = HC_STATE_HALT; in ehci_quiesce()
811 temp = readl(&oxu->regs->command); in ehci_quiesce()
813 writel(temp, &oxu->regs->command); in ehci_quiesce()
816 if (handshake(oxu, &oxu->regs->status, STS_ASS | STS_PSS, in ehci_quiesce()
818 oxu_to_hcd(oxu)->state = HC_STATE_HALT; in ehci_quiesce()
827 oxu->reset_done[index] = 0; in check_reset_complete()
831 /* if reset finished and it's still not enabled -- handoff */ in check_reset_complete()
845 int ports = HCS_N_PORTS(oxu->hcs_params); in ehci_hub_descriptor()
848 desc->bDescriptorType = USB_DT_HUB; in ehci_hub_descriptor()
849 desc->bPwrOn2PwrGood = 10; /* oxu 1.0, 2.3.9 says 20ms max */ in ehci_hub_descriptor()
850 desc->bHubContrCurrent = 0; in ehci_hub_descriptor()
852 desc->bNbrPorts = ports; in ehci_hub_descriptor()
854 desc->bDescLength = 7 + 2 * temp; in ehci_hub_descriptor()
857 memset(&desc->u.hs.DeviceRemovable[0], 0, temp); in ehci_hub_descriptor()
858 memset(&desc->u.hs.DeviceRemovable[temp], 0xff, temp); in ehci_hub_descriptor()
860 temp = HUB_CHAR_INDV_PORT_OCPM; /* per-port overcurrent reporting */ in ehci_hub_descriptor()
861 if (HCS_PPC(oxu->hcs_params)) in ehci_hub_descriptor()
862 temp |= HUB_CHAR_INDV_PORT_LPSM; /* per-port power control */ in ehci_hub_descriptor()
865 desc->wHubCharacteristics = (__force __u16)cpu_to_le16(temp); in ehci_hub_descriptor()
869 /* Allocate an OXU210HP on-chip memory data buffer
871 * An on-chip memory data buffer is required for each OXU210HP USB transfer.
872 * Each transfer descriptor has one or more on-chip memory data buffers.
880 * len=0. This is a waste of on-chip memory and should be fix. Then this
892 return -ENOMEM; in oxu_buf_alloc()
895 spin_lock(&oxu->mem_lock); in oxu_buf_alloc()
898 n_blocks = (len + BUFFER_SIZE - 1) / BUFFER_SIZE; in oxu_buf_alloc()
906 i += max_t(int, a_blocks, oxu->db_used[i])) { in oxu_buf_alloc()
910 if (oxu->db_used[i + j]) in oxu_buf_alloc()
917 qtd->buffer = (void *) &oxu->mem->db_pool[i]; in oxu_buf_alloc()
918 qtd->buffer_dma = virt_to_phys(qtd->buffer); in oxu_buf_alloc()
920 qtd->qtd_buffer_len = BUFFER_SIZE * a_blocks; in oxu_buf_alloc()
921 oxu->db_used[i] = a_blocks; in oxu_buf_alloc()
923 spin_unlock(&oxu->mem_lock); in oxu_buf_alloc()
930 spin_unlock(&oxu->mem_lock); in oxu_buf_alloc()
932 return -ENOMEM; in oxu_buf_alloc()
939 spin_lock(&oxu->mem_lock); in oxu_buf_free()
941 index = (qtd->buffer - (void *) &oxu->mem->db_pool[0]) in oxu_buf_free()
943 oxu->db_used[index] = 0; in oxu_buf_free()
944 qtd->qtd_buffer_len = 0; in oxu_buf_free()
945 qtd->buffer_dma = 0; in oxu_buf_free()
946 qtd->buffer = NULL; in oxu_buf_free()
948 spin_unlock(&oxu->mem_lock); in oxu_buf_free()
954 qtd->qtd_dma = dma; in ehci_qtd_init()
955 qtd->hw_token = cpu_to_le32(QTD_STS_HALT); in ehci_qtd_init()
956 qtd->hw_next = EHCI_LIST_END; in ehci_qtd_init()
957 qtd->hw_alt_next = EHCI_LIST_END; in ehci_qtd_init()
958 INIT_LIST_HEAD(&qtd->qtd_list); in ehci_qtd_init()
965 if (qtd->buffer) in oxu_qtd_free()
968 spin_lock(&oxu->mem_lock); in oxu_qtd_free()
970 index = qtd - &oxu->mem->qtd_pool[0]; in oxu_qtd_free()
971 oxu->qtd_used[index] = 0; in oxu_qtd_free()
973 spin_unlock(&oxu->mem_lock); in oxu_qtd_free()
981 spin_lock(&oxu->mem_lock); in ehci_qtd_alloc()
984 if (!oxu->qtd_used[i]) in ehci_qtd_alloc()
988 qtd = (struct ehci_qtd *) &oxu->mem->qtd_pool[i]; in ehci_qtd_alloc()
991 qtd->hw_token = cpu_to_le32(QTD_STS_HALT); in ehci_qtd_alloc()
992 qtd->hw_next = EHCI_LIST_END; in ehci_qtd_alloc()
993 qtd->hw_alt_next = EHCI_LIST_END; in ehci_qtd_alloc()
994 INIT_LIST_HEAD(&qtd->qtd_list); in ehci_qtd_alloc()
996 qtd->qtd_dma = virt_to_phys(qtd); in ehci_qtd_alloc()
998 oxu->qtd_used[i] = 1; in ehci_qtd_alloc()
1001 spin_unlock(&oxu->mem_lock); in ehci_qtd_alloc()
1010 spin_lock(&oxu->mem_lock); in oxu_qh_free()
1012 index = qh - &oxu->mem->qh_pool[0]; in oxu_qh_free()
1013 oxu->qh_used[index] = 0; in oxu_qh_free()
1015 spin_unlock(&oxu->mem_lock); in oxu_qh_free()
1021 struct oxu_hcd *oxu = qh->oxu; in qh_destroy()
1024 if (!list_empty(&qh->qtd_list) || qh->qh_next.ptr) { in qh_destroy()
1028 if (qh->dummy) in qh_destroy()
1029 oxu_qtd_free(oxu, qh->dummy); in qh_destroy()
1038 spin_lock(&oxu->mem_lock); in oxu_qh_alloc()
1041 if (!oxu->qh_used[i]) in oxu_qh_alloc()
1045 qh = (struct ehci_qh *) &oxu->mem->qh_pool[i]; in oxu_qh_alloc()
1048 kref_init(&qh->kref); in oxu_qh_alloc()
1049 qh->oxu = oxu; in oxu_qh_alloc()
1050 qh->qh_dma = virt_to_phys(qh); in oxu_qh_alloc()
1051 INIT_LIST_HEAD(&qh->qtd_list); in oxu_qh_alloc()
1054 qh->dummy = ehci_qtd_alloc(oxu); in oxu_qh_alloc()
1055 if (qh->dummy == NULL) { in oxu_qh_alloc()
1057 oxu->qh_used[i] = 0; in oxu_qh_alloc()
1062 oxu->qh_used[i] = 1; in oxu_qh_alloc()
1065 spin_unlock(&oxu->mem_lock); in oxu_qh_alloc()
1073 kref_get(&qh->kref); in qh_get()
1079 kref_put(&qh->kref, qh_destroy); in qh_put()
1086 spin_lock(&oxu->mem_lock); in oxu_murb_free()
1088 index = murb - &oxu->murb_pool[0]; in oxu_murb_free()
1089 oxu->murb_used[index] = 0; in oxu_murb_free()
1091 spin_unlock(&oxu->mem_lock); in oxu_murb_free()
1100 spin_lock(&oxu->mem_lock); in oxu_murb_alloc()
1103 if (!oxu->murb_used[i]) in oxu_murb_alloc()
1107 murb = &(oxu->murb_pool)[i]; in oxu_murb_alloc()
1109 oxu->murb_used[i] = 1; in oxu_murb_alloc()
1112 spin_unlock(&oxu->mem_lock); in oxu_murb_alloc()
1123 kfree(oxu->murb_pool); in ehci_mem_cleanup()
1124 oxu->murb_pool = NULL; in ehci_mem_cleanup()
1126 if (oxu->async) in ehci_mem_cleanup()
1127 qh_put(oxu->async); in ehci_mem_cleanup()
1128 oxu->async = NULL; in ehci_mem_cleanup()
1130 del_timer(&oxu->urb_timer); in ehci_mem_cleanup()
1132 oxu->periodic = NULL; in ehci_mem_cleanup()
1135 kfree(oxu->pshadow); in ehci_mem_cleanup()
1136 oxu->pshadow = NULL; in ehci_mem_cleanup()
1145 for (i = 0; i < oxu->periodic_size; i++) in ehci_mem_init()
1146 oxu->mem->frame_list[i] = EHCI_LIST_END; in ehci_mem_init()
1148 oxu->qh_used[i] = 0; in ehci_mem_init()
1150 oxu->qtd_used[i] = 0; in ehci_mem_init()
1152 oxu->murb_pool = kcalloc(MURB_NUM, sizeof(struct oxu_murb), flags); in ehci_mem_init()
1153 if (!oxu->murb_pool) in ehci_mem_init()
1157 oxu->murb_used[i] = 0; in ehci_mem_init()
1159 oxu->async = oxu_qh_alloc(oxu); in ehci_mem_init()
1160 if (!oxu->async) in ehci_mem_init()
1163 oxu->periodic = (__le32 *) &oxu->mem->frame_list; in ehci_mem_init()
1164 oxu->periodic_dma = virt_to_phys(oxu->periodic); in ehci_mem_init()
1166 for (i = 0; i < oxu->periodic_size; i++) in ehci_mem_init()
1167 oxu->periodic[i] = EHCI_LIST_END; in ehci_mem_init()
1170 oxu->pshadow = kcalloc(oxu->periodic_size, sizeof(void *), flags); in ehci_mem_init()
1171 if (oxu->pshadow != NULL) in ehci_mem_init()
1177 return -ENOMEM; in ehci_mem_init()
1189 qtd->hw_buf[0] = cpu_to_le32((u32)addr); in qtd_fill()
1190 qtd->hw_buf_hi[0] = cpu_to_le32((u32)(addr >> 32)); in qtd_fill()
1191 count = 0x1000 - (buf & 0x0fff); /* rest of that page */ in qtd_fill()
1198 /* per-qtd limit: from 16K to 20K (best alignment) */ in qtd_fill()
1201 qtd->hw_buf[i] = cpu_to_le32((u32)addr); in qtd_fill()
1202 qtd->hw_buf_hi[i] = cpu_to_le32((u32)(addr >> 32)); in qtd_fill()
1212 count -= (count % maxpacket); in qtd_fill()
1214 qtd->hw_token = cpu_to_le32((count << 16) | token); in qtd_fill()
1215 qtd->length = count; in qtd_fill()
1224 BUG_ON(qh->qh_state != QH_STATE_IDLE); in qh_update()
1226 qh->hw_qtd_next = QTD_NEXT(qtd->qtd_dma); in qh_update()
1227 qh->hw_alt_next = EHCI_LIST_END; in qh_update()
1231 * and set the pseudo-toggle in udev. Only usb_clear_halt() will in qh_update()
1234 if (!(qh->hw_info1 & cpu_to_le32(1 << 14))) { in qh_update()
1237 is_out = !(qtd->hw_token & cpu_to_le32(1 << 8)); in qh_update()
1238 epnum = (le32_to_cpup(&qh->hw_info1) >> 8) & 0x0f; in qh_update()
1239 if (unlikely(!usb_gettoggle(qh->dev, epnum, is_out))) { in qh_update()
1240 qh->hw_token &= ~cpu_to_le32(QTD_TOGGLE); in qh_update()
1241 usb_settoggle(qh->dev, epnum, is_out, 1); in qh_update()
1247 qh->hw_token &= cpu_to_le32(QTD_TOGGLE | QTD_STS_PING); in qh_update()
1251 * overlay, so qh->hw_token wrongly becomes inactive/halted), only fault
1258 if (list_empty(&qh->qtd_list)) in qh_refresh()
1259 qtd = qh->dummy; in qh_refresh()
1261 qtd = list_entry(qh->qtd_list.next, in qh_refresh()
1264 if (cpu_to_le32(qtd->qtd_dma) == qh->hw_current) in qh_refresh()
1277 urb->actual_length += length - QTD_LENGTH(token); in qtd_copy_status()
1280 if (unlikely(urb->status != -EINPROGRESS)) in qtd_copy_status()
1285 urb->status = -EREMOTEIO; in qtd_copy_status()
1291 urb->status = -EOVERFLOW; in qtd_copy_status()
1293 /* fs/ls interrupt xfer missed the complete-split */ in qtd_copy_status()
1294 urb->status = -EPROTO; in qtd_copy_status()
1296 urb->status = (QTD_PID(token) == 1) /* IN ? */ in qtd_copy_status()
1297 ? -ENOSR /* hc couldn't read data */ in qtd_copy_status()
1298 : -ECOMM; /* hc couldn't write data */ in qtd_copy_status()
1302 urb->status = -EPIPE; in qtd_copy_status()
1305 urb->dev->devpath, in qtd_copy_status()
1306 usb_pipeendpoint(urb->pipe), in qtd_copy_status()
1307 usb_pipein(urb->pipe) ? "in" : "out"); in qtd_copy_status()
1308 urb->status = -EPROTO; in qtd_copy_status()
1310 /* CERR nonzero + no errors + halt --> stall */ in qtd_copy_status()
1312 urb->status = -EPIPE; in qtd_copy_status()
1314 urb->status = -EPROTO; in qtd_copy_status()
1316 oxu_vdbg(oxu, "dev%d ep%d%s qtd token %08x --> status %d\n", in qtd_copy_status()
1317 usb_pipedevice(urb->pipe), in qtd_copy_status()
1318 usb_pipeendpoint(urb->pipe), in qtd_copy_status()
1319 usb_pipein(urb->pipe) ? "in" : "out", in qtd_copy_status()
1320 token, urb->status); in qtd_copy_status()
1325 __releases(oxu->lock) in ehci_urb_done()
1326 __acquires(oxu->lock) in ehci_urb_done()
1328 if (likely(urb->hcpriv != NULL)) { in ehci_urb_done()
1329 struct ehci_qh *qh = (struct ehci_qh *) urb->hcpriv; in ehci_urb_done()
1331 /* S-mask in a QH means it's an interrupt urb */ in ehci_urb_done()
1332 if ((qh->hw_info2 & cpu_to_le32(QH_SMASK)) != 0) { in ehci_urb_done()
1334 /* ... update hc-wide periodic stats (for usbfs) */ in ehci_urb_done()
1335 oxu_to_hcd(oxu)->self.bandwidth_int_reqs--; in ehci_urb_done()
1340 urb->hcpriv = NULL; in ehci_urb_done()
1341 switch (urb->status) { in ehci_urb_done()
1342 case -EINPROGRESS: /* success */ in ehci_urb_done()
1343 urb->status = 0; in ehci_urb_done()
1347 case -EREMOTEIO: /* fault or normal */ in ehci_urb_done()
1348 if (!(urb->transfer_flags & URB_SHORT_NOT_OK)) in ehci_urb_done()
1349 urb->status = 0; in ehci_urb_done()
1351 case -ECONNRESET: /* canceled */ in ehci_urb_done()
1352 case -ENOENT: in ehci_urb_done()
1358 __func__, urb->dev->devpath, urb, in ehci_urb_done()
1359 usb_pipeendpoint(urb->pipe), in ehci_urb_done()
1360 usb_pipein(urb->pipe) ? "in" : "out", in ehci_urb_done()
1361 urb->status, in ehci_urb_done()
1362 urb->actual_length, urb->transfer_buffer_length); in ehci_urb_done()
1366 spin_unlock(&oxu->lock); in ehci_urb_done()
1367 usb_hcd_giveback_urb(oxu_to_hcd(oxu), urb, urb->status); in ehci_urb_done()
1368 spin_lock(&oxu->lock); in ehci_urb_done()
1380 * Chases up to qh->hw_current. Returns number of completions called,
1385 struct ehci_qtd *last = NULL, *end = qh->dummy; in qh_completions()
1393 if (unlikely(list_empty(&qh->qtd_list))) in qh_completions()
1402 state = qh->qh_state; in qh_completions()
1403 qh->qh_state = QH_STATE_COMPLETING; in qh_completions()
1406 /* remove de-activated QTDs from front of queue. in qh_completions()
1411 list_for_each_entry_safe(qtd, tmp, &qh->qtd_list, qtd_list) { in qh_completions()
1415 urb = qtd->urb; in qh_completions()
1419 if (likely(last->urb != urb)) { in qh_completions()
1420 if (last->urb->complete == NULL) { in qh_completions()
1421 murb = (struct oxu_murb *) last->urb; in qh_completions()
1422 last->urb = murb->main; in qh_completions()
1423 if (murb->last) { in qh_completions()
1424 ehci_urb_done(oxu, last->urb); in qh_completions()
1429 ehci_urb_done(oxu, last->urb); in qh_completions()
1443 token = le32_to_cpu(qtd->hw_token); in qh_completions()
1445 /* always clean up qtds the hc de-activated */ in qh_completions()
1455 !(qtd->hw_alt_next & EHCI_LIST_END)) { in qh_completions()
1462 HC_IS_RUNNING(oxu_to_hcd(oxu)->state))) { in qh_completions()
1468 if (unlikely(!HC_IS_RUNNING(oxu_to_hcd(oxu)->state))) in qh_completions()
1469 urb->status = -ESHUTDOWN; in qh_completions()
1475 if (likely(urb->status == -EINPROGRESS)) in qh_completions()
1487 && cpu_to_le32(qtd->qtd_dma) in qh_completions()
1488 == qh->hw_current) in qh_completions()
1489 token = le32_to_cpu(qh->hw_token); in qh_completions()
1495 if ((HALT_BIT & qh->hw_token) == 0) { in qh_completions()
1497 qh->hw_token |= HALT_BIT; in qh_completions()
1503 qtd_copy_status(oxu, urb->complete ? in qh_completions()
1504 urb : ((struct oxu_murb *) urb)->main, in qh_completions()
1505 qtd->length, token); in qh_completions()
1506 if ((usb_pipein(qtd->urb->pipe)) && in qh_completions()
1507 (NULL != qtd->transfer_buffer)) in qh_completions()
1508 memcpy(qtd->transfer_buffer, qtd->buffer, qtd->length); in qh_completions()
1509 do_status = (urb->status == -EREMOTEIO) in qh_completions()
1510 && usb_pipecontrol(urb->pipe); in qh_completions()
1512 if (stopped && qtd->qtd_list.prev != &qh->qtd_list) { in qh_completions()
1513 last = list_entry(qtd->qtd_list.prev, in qh_completions()
1515 last->hw_next = qtd->hw_next; in qh_completions()
1517 list_del(&qtd->qtd_list); in qh_completions()
1523 if (last->urb->complete == NULL) { in qh_completions()
1524 murb = (struct oxu_murb *) last->urb; in qh_completions()
1525 last->urb = murb->main; in qh_completions()
1526 if (murb->last) { in qh_completions()
1527 ehci_urb_done(oxu, last->urb); in qh_completions()
1532 ehci_urb_done(oxu, last->urb); in qh_completions()
1539 qh->qh_state = state; in qh_completions()
1545 if (stopped != 0 || qh->hw_qtd_next == EHCI_LIST_END) { in qh_completions()
1555 & qh->hw_info2) != 0) { in qh_completions()
1582 list_del(&qtd->qtd_list); in qtd_list_free()
1608 list_add_tail(&qtd->qtd_list, head); in qh_urb_transaction()
1609 qtd->urb = urb; in qh_urb_transaction()
1615 len = urb->transfer_buffer_length; in qh_urb_transaction()
1616 is_input = usb_pipein(urb->pipe); in qh_urb_transaction()
1617 if (!urb->transfer_buffer && urb->transfer_buffer_length && is_input) in qh_urb_transaction()
1618 urb->transfer_buffer = phys_to_virt(urb->transfer_dma); in qh_urb_transaction()
1620 if (usb_pipecontrol(urb->pipe)) { in qh_urb_transaction()
1626 qtd_fill(qtd, qtd->buffer_dma, sizeof(struct usb_ctrlrequest), in qh_urb_transaction()
1628 memcpy(qtd->buffer, qtd->urb->setup_packet, in qh_urb_transaction()
1637 qtd->urb = urb; in qh_urb_transaction()
1638 qtd_prev->hw_next = QTD_NEXT(qtd->qtd_dma); in qh_urb_transaction()
1639 list_add_tail(&qtd->qtd_list, head); in qh_urb_transaction()
1654 buf = qtd->buffer_dma; in qh_urb_transaction()
1655 transfer_buf = urb->transfer_buffer; in qh_urb_transaction()
1658 memcpy(qtd->buffer, qtd->urb->transfer_buffer, len); in qh_urb_transaction()
1664 maxpacket = usb_maxpacket(urb->dev, urb->pipe); in qh_urb_transaction()
1675 qtd->transfer_buffer = transfer_buf; in qh_urb_transaction()
1676 len -= this_qtd_len; in qh_urb_transaction()
1680 qtd->hw_alt_next = oxu->async->hw_alt_next; in qh_urb_transaction()
1683 if ((maxpacket & (this_qtd_len + (maxpacket - 1))) == 0) in qh_urb_transaction()
1698 qtd->urb = urb; in qh_urb_transaction()
1699 qtd_prev->hw_next = QTD_NEXT(qtd->qtd_dma); in qh_urb_transaction()
1700 list_add_tail(&qtd->qtd_list, head); in qh_urb_transaction()
1706 if (likely((urb->transfer_flags & URB_SHORT_NOT_OK) == 0 in qh_urb_transaction()
1707 || usb_pipecontrol(urb->pipe))) in qh_urb_transaction()
1708 qtd->hw_alt_next = EHCI_LIST_END; in qh_urb_transaction()
1714 if (likely(urb->transfer_buffer_length != 0)) { in qh_urb_transaction()
1717 if (usb_pipecontrol(urb->pipe)) { in qh_urb_transaction()
1719 token ^= 0x0100; /* "in" <--> "out" */ in qh_urb_transaction()
1721 } else if (usb_pipebulk(urb->pipe) in qh_urb_transaction()
1722 && (urb->transfer_flags & URB_ZERO_PACKET) in qh_urb_transaction()
1723 && !(urb->transfer_buffer_length % maxpacket)) { in qh_urb_transaction()
1731 qtd->urb = urb; in qh_urb_transaction()
1732 qtd_prev->hw_next = QTD_NEXT(qtd->qtd_dma); in qh_urb_transaction()
1733 list_add_tail(&qtd->qtd_list, head); in qh_urb_transaction()
1741 qtd->hw_token |= cpu_to_le32(QTD_IOC); in qh_urb_transaction()
1753 * just one microframe in the s-mask. For split interrupt transactions
1754 * there are additional complications: c-mask, maybe FSTNs.
1770 info1 |= usb_pipeendpoint(urb->pipe) << 8; in qh_make()
1771 info1 |= usb_pipedevice(urb->pipe) << 0; in qh_make()
1773 is_input = usb_pipein(urb->pipe); in qh_make()
1774 type = usb_pipetype(urb->pipe); in qh_make()
1775 maxp = usb_maxpacket(urb->dev, urb->pipe); in qh_make()
1778 * - allowing for high bandwidth, how many nsec/uframe are used? in qh_make()
1779 * - split transactions need a second CSPLIT uframe; same question in qh_make()
1780 * - splits also need a schedule gap (for full/low speed I/O) in qh_make()
1781 * - qh has a polling interval in qh_make()
1786 qh->usecs = NS_TO_US(usb_calc_bus_time(USB_SPEED_HIGH, in qh_make()
1789 qh->start = NO_FRAME; in qh_make()
1791 if (urb->dev->speed == USB_SPEED_HIGH) { in qh_make()
1792 qh->c_usecs = 0; in qh_make()
1793 qh->gap_uf = 0; in qh_make()
1795 qh->period = urb->interval >> 3; in qh_make()
1796 if (qh->period == 0 && urb->interval != 1) { in qh_make()
1802 urb->interval); in qh_make()
1806 struct usb_tt *tt = urb->dev->tt; in qh_make()
1810 qh->gap_uf = 1 + usb_calc_bus_time(urb->dev->speed, in qh_make()
1815 qh->c_usecs = qh->usecs + HS_USECS(0); in qh_make()
1816 qh->usecs = HS_USECS(1); in qh_make()
1818 qh->usecs += HS_USECS(1); in qh_make()
1819 qh->c_usecs = HS_USECS(0); in qh_make()
1822 think_time = tt ? tt->think_time : 0; in qh_make()
1823 qh->tt_usecs = NS_TO_US(think_time + in qh_make()
1824 usb_calc_bus_time(urb->dev->speed, in qh_make()
1826 qh->period = urb->interval; in qh_make()
1831 qh->dev = urb->dev; in qh_make()
1834 switch (urb->dev->speed) { in qh_make()
1850 info2 |= urb->dev->ttport << 23; in qh_make()
1852 /* NOTE: if (PIPE_INTERRUPT) { scheduler sets c-mask } */ in qh_make()
1873 oxu_dbg(oxu, "bogus dev %p speed %d\n", urb->dev, urb->dev->speed); in qh_make()
1879 /* NOTE: if (PIPE_INTERRUPT) { scheduler sets s-mask } */ in qh_make()
1882 qh->qh_state = QH_STATE_IDLE; in qh_make()
1883 qh->hw_info1 = cpu_to_le32(info1); in qh_make()
1884 qh->hw_info2 = cpu_to_le32(info2); in qh_make()
1885 usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), !is_input, 1); in qh_make()
1894 __le32 dma = QH_NEXT(qh->qh_dma); in qh_link_async()
1898 head = oxu->async; in qh_link_async()
1900 if (!head->qh_next.qh) { in qh_link_async()
1901 u32 cmd = readl(&oxu->regs->command); in qh_link_async()
1905 (void)handshake(oxu, &oxu->regs->status, in qh_link_async()
1908 writel(cmd, &oxu->regs->command); in qh_link_async()
1909 oxu_to_hcd(oxu)->state = HC_STATE_RUNNING; in qh_link_async()
1915 if (qh->qh_state == QH_STATE_IDLE) in qh_link_async()
1919 qh->qh_next = head->qh_next; in qh_link_async()
1920 qh->hw_next = head->hw_next; in qh_link_async()
1923 head->qh_next.qh = qh; in qh_link_async()
1924 head->hw_next = dma; in qh_link_async()
1926 qh->qh_state = QH_STATE_LINKED; in qh_link_async()
1946 /* can't sleep here, we have oxu->lock... */ in qh_append_tds()
1956 qtd = list_entry(qtd_list->next, struct ehci_qtd, in qh_append_tds()
1963 if (usb_pipedevice(urb->pipe) == 0) in qh_append_tds()
1964 qh->hw_info1 &= ~QH_ADDR_MASK; in qh_append_tds()
1980 token = qtd->hw_token; in qh_append_tds()
1981 qtd->hw_token = HALT_BIT; in qh_append_tds()
1983 dummy = qh->dummy; in qh_append_tds()
1985 dma = dummy->qtd_dma; in qh_append_tds()
1987 dummy->qtd_dma = dma; in qh_append_tds()
1989 list_del(&qtd->qtd_list); in qh_append_tds()
1990 list_add(&dummy->qtd_list, qtd_list); in qh_append_tds()
1991 list_splice(qtd_list, qh->qtd_list.prev); in qh_append_tds()
1993 ehci_qtd_init(qtd, qtd->qtd_dma); in qh_append_tds()
1994 qh->dummy = qtd; in qh_append_tds()
1997 dma = qtd->qtd_dma; in qh_append_tds()
1998 qtd = list_entry(qh->qtd_list.prev, in qh_append_tds()
2000 qtd->hw_next = QTD_NEXT(dma); in qh_append_tds()
2003 dummy->hw_token = (token & ~(0x80)); in qh_append_tds()
2005 dummy->hw_token = token; in qh_append_tds()
2007 urb->hcpriv = qh_get(qh); in qh_append_tds()
2016 int epnum = urb->ep->desc.bEndpointAddress; in submit_async()
2023 qtd = list_entry(qtd_list->next, struct ehci_qtd, qtd_list); in submit_async()
2026 __func__, urb->dev->devpath, urb, in submit_async()
2028 urb->transfer_buffer_length, in submit_async()
2029 qtd, urb->ep->hcpriv); in submit_async()
2032 spin_lock_irqsave(&oxu->lock, flags); in submit_async()
2034 rc = -ESHUTDOWN; in submit_async()
2038 qh = qh_append_tds(oxu, urb, qtd_list, epnum, &urb->ep->hcpriv); in submit_async()
2040 rc = -ENOMEM; in submit_async()
2047 if (likely(qh->qh_state == QH_STATE_IDLE)) in submit_async()
2050 spin_unlock_irqrestore(&oxu->lock, flags); in submit_async()
2060 struct ehci_qh *qh = oxu->reclaim; in end_unlink_async()
2065 qh->qh_state = QH_STATE_IDLE; in end_unlink_async()
2066 qh->qh_next.qh = NULL; in end_unlink_async()
2070 next = qh->reclaim; in end_unlink_async()
2071 oxu->reclaim = next; in end_unlink_async()
2072 oxu->reclaim_ready = 0; in end_unlink_async()
2073 qh->reclaim = NULL; in end_unlink_async()
2077 if (!list_empty(&qh->qtd_list) in end_unlink_async()
2078 && HC_IS_RUNNING(oxu_to_hcd(oxu)->state)) in end_unlink_async()
2086 if (HC_IS_RUNNING(oxu_to_hcd(oxu)->state) in end_unlink_async()
2087 && oxu->async->qh_next.qh == NULL) in end_unlink_async()
2092 oxu->reclaim = NULL; in end_unlink_async()
2098 /* caller must own oxu->lock */
2102 int cmd = readl(&oxu->regs->command); in start_unlink_async()
2106 assert_spin_locked(&oxu->lock); in start_unlink_async()
2107 BUG_ON(oxu->reclaim || (qh->qh_state != QH_STATE_LINKED in start_unlink_async()
2108 && qh->qh_state != QH_STATE_UNLINK_WAIT)); in start_unlink_async()
2112 if (unlikely(qh == oxu->async)) { in start_unlink_async()
2114 if (oxu_to_hcd(oxu)->state != HC_STATE_HALT in start_unlink_async()
2115 && !oxu->reclaim) { in start_unlink_async()
2117 writel(cmd & ~CMD_ASE, &oxu->regs->command); in start_unlink_async()
2125 qh->qh_state = QH_STATE_UNLINK; in start_unlink_async()
2126 oxu->reclaim = qh = qh_get(qh); in start_unlink_async()
2128 prev = oxu->async; in start_unlink_async()
2129 while (prev->qh_next.qh != qh) in start_unlink_async()
2130 prev = prev->qh_next.qh; in start_unlink_async()
2132 prev->hw_next = qh->hw_next; in start_unlink_async()
2133 prev->qh_next = qh->qh_next; in start_unlink_async()
2136 if (unlikely(oxu_to_hcd(oxu)->state == HC_STATE_HALT)) { in start_unlink_async()
2137 /* if (unlikely(qh->reclaim != 0)) in start_unlink_async()
2144 oxu->reclaim_ready = 0; in start_unlink_async()
2146 writel(cmd, &oxu->regs->command); in start_unlink_async()
2147 (void) readl(&oxu->regs->command); in start_unlink_async()
2156 if (!++(oxu->stamp)) in scan_async()
2157 oxu->stamp++; in scan_async()
2160 qh = oxu->async->qh_next.qh; in scan_async()
2164 if (!list_empty(&qh->qtd_list) in scan_async()
2165 && qh->stamp != oxu->stamp) { in scan_async()
2174 qh->stamp = oxu->stamp; in scan_async()
2182 * as HCD schedule-scanning costs. delay for any qh in scan_async()
2183 * we just scanned, there's a not-unusual case that it in scan_async()
2185 * (plus, avoids some kind of re-activation race.) in scan_async()
2187 if (list_empty(&qh->qtd_list)) { in scan_async()
2188 if (qh->stamp == oxu->stamp) in scan_async()
2190 else if (!oxu->reclaim in scan_async()
2191 && qh->qh_state == QH_STATE_LINKED) in scan_async()
2195 qh = qh->qh_next.qh; in scan_async()
2203 * periodic_next_shadow - return "next" pointer on shadow list
2213 return &periodic->qh->qh_next; in periodic_next_shadow()
2217 /* caller must hold oxu->lock */
2220 union ehci_shadow *prev_p = &oxu->pshadow[frame]; in periodic_unlink()
2221 __le32 *hw_p = &oxu->periodic[frame]; in periodic_unlink()
2245 __le32 *hw_p = &oxu->periodic[frame]; in periodic_usecs()
2246 union ehci_shadow *q = &oxu->pshadow[frame]; in periodic_usecs()
2249 while (q->ptr) { in periodic_usecs()
2253 /* is it in the S-mask? */ in periodic_usecs()
2254 if (q->qh->hw_info2 & cpu_to_le32(1 << uframe)) in periodic_usecs()
2255 usecs += q->qh->usecs; in periodic_usecs()
2256 /* ... or C-mask? */ in periodic_usecs()
2257 if (q->qh->hw_info2 & cpu_to_le32(1 << (8 + uframe))) in periodic_usecs()
2258 usecs += q->qh->c_usecs; in periodic_usecs()
2259 hw_p = &q->qh->hw_next; in periodic_usecs()
2260 q = &q->qh->qh_next; in periodic_usecs()
2280 status = handshake(oxu, &oxu->regs->status, STS_PSS, 0, 9 * 125); in enable_periodic()
2282 oxu_to_hcd(oxu)->state = HC_STATE_HALT; in enable_periodic()
2287 cmd = readl(&oxu->regs->command) | CMD_PSE; in enable_periodic()
2288 writel(cmd, &oxu->regs->command); in enable_periodic()
2290 oxu_to_hcd(oxu)->state = HC_STATE_RUNNING; in enable_periodic()
2293 oxu->next_uframe = readl(&oxu->regs->frame_index) in enable_periodic()
2294 % (oxu->periodic_size << 3); in enable_periodic()
2306 status = handshake(oxu, &oxu->regs->status, STS_PSS, STS_PSS, 9 * 125); in disable_periodic()
2308 oxu_to_hcd(oxu)->state = HC_STATE_HALT; in disable_periodic()
2313 cmd = readl(&oxu->regs->command) & ~CMD_PSE; in disable_periodic()
2314 writel(cmd, &oxu->regs->command); in disable_periodic()
2317 oxu->next_uframe = -1; in disable_periodic()
2330 unsigned period = qh->period; in qh_link_periodic()
2332 dev_dbg(&qh->dev->dev, in qh_link_periodic()
2333 "link qh%d-%04x/%p start %d [%d/%d us]\n", in qh_link_periodic()
2334 period, le32_to_cpup(&qh->hw_info2) & (QH_CMASK | QH_SMASK), in qh_link_periodic()
2335 qh, qh->start, qh->usecs, qh->c_usecs); in qh_link_periodic()
2341 for (i = qh->start; i < oxu->periodic_size; i += period) { in qh_link_periodic()
2342 union ehci_shadow *prev = &oxu->pshadow[i]; in qh_link_periodic()
2343 __le32 *hw_p = &oxu->periodic[i]; in qh_link_periodic()
2353 hw_p = &here.qh->hw_next; in qh_link_periodic()
2357 /* sorting each branch by period (slow-->fast) in qh_link_periodic()
2361 if (qh->period > here.qh->period) in qh_link_periodic()
2363 prev = &here.qh->qh_next; in qh_link_periodic()
2364 hw_p = &here.qh->hw_next; in qh_link_periodic()
2369 qh->qh_next = here; in qh_link_periodic()
2371 qh->hw_next = *hw_p; in qh_link_periodic()
2373 prev->qh = qh; in qh_link_periodic()
2374 *hw_p = QH_NEXT(qh->qh_dma); in qh_link_periodic()
2377 qh->qh_state = QH_STATE_LINKED; in qh_link_periodic()
2380 /* update per-qh bandwidth for usbfs */ in qh_link_periodic()
2381 oxu_to_hcd(oxu)->self.bandwidth_allocated += qh->period in qh_link_periodic()
2382 ? ((qh->usecs + qh->c_usecs) / qh->period) in qh_link_periodic()
2383 : (qh->usecs * 8); in qh_link_periodic()
2386 if (!oxu->periodic_sched++) in qh_link_periodic()
2402 * qh->hw_info1 |= cpu_to_le32(1 << 7 "ignore"); in qh_unlink_periodic()
2406 period = qh->period; in qh_unlink_periodic()
2410 for (i = qh->start; i < oxu->periodic_size; i += period) in qh_unlink_periodic()
2413 /* update per-qh bandwidth for usbfs */ in qh_unlink_periodic()
2414 oxu_to_hcd(oxu)->self.bandwidth_allocated -= qh->period in qh_unlink_periodic()
2415 ? ((qh->usecs + qh->c_usecs) / qh->period) in qh_unlink_periodic()
2416 : (qh->usecs * 8); in qh_unlink_periodic()
2418 dev_dbg(&qh->dev->dev, in qh_unlink_periodic()
2419 "unlink qh%d-%04x/%p start %d [%d/%d us]\n", in qh_unlink_periodic()
2420 qh->period, in qh_unlink_periodic()
2421 le32_to_cpup(&qh->hw_info2) & (QH_CMASK | QH_SMASK), in qh_unlink_periodic()
2422 qh, qh->start, qh->usecs, qh->c_usecs); in qh_unlink_periodic()
2424 /* qh->qh_next still "live" to HC */ in qh_unlink_periodic()
2425 qh->qh_state = QH_STATE_UNLINK; in qh_unlink_periodic()
2426 qh->qh_next.ptr = NULL; in qh_unlink_periodic()
2430 oxu->periodic_sched--; in qh_unlink_periodic()
2431 if (!oxu->periodic_sched) in qh_unlink_periodic()
2441 /* simple/paranoid: always delay, expecting the HC needs to read in intr_deschedule()
2442 * qh->hw_next or finish a writeback after SPLIT/CSPLIT ... and in intr_deschedule()
2446 if (list_empty(&qh->qtd_list) in intr_deschedule()
2447 || (cpu_to_le32(QH_CMASK) & qh->hw_info2) != 0) in intr_deschedule()
2453 qh->qh_state = QH_STATE_IDLE; in intr_deschedule()
2454 qh->hw_next = EHCI_LIST_END; in intr_deschedule()
2474 usecs = 100 - usecs; in check_period()
2486 } while ((frame += 1) < oxu->periodic_size); in check_period()
2494 } while ((frame += period) < oxu->periodic_size); in check_period()
2504 int retval = -ENOSPC; in check_intr_schedule()
2506 if (qh->c_usecs && uframe >= 6) /* FSTN territory? */ in check_intr_schedule()
2509 if (!check_period(oxu, frame, uframe, qh->period, qh->usecs)) in check_intr_schedule()
2511 if (!qh->c_usecs) { in check_intr_schedule()
2522 * or when the previous schedule slot can't be re-used.
2529 unsigned frame; /* 0..(qh->period - 1), or NO_FRAME */ in qh_schedule()
2532 qh->hw_next = EHCI_LIST_END; in qh_schedule()
2533 frame = qh->start; in qh_schedule()
2536 if (frame < qh->period) { in qh_schedule()
2537 uframe = ffs(le32_to_cpup(&qh->hw_info2) & QH_SMASK); in qh_schedule()
2538 status = check_intr_schedule(oxu, frame, --uframe, in qh_schedule()
2543 status = -ENOSPC; in qh_schedule()
2551 if (qh->period) { in qh_schedule()
2552 frame = qh->period - 1; in qh_schedule()
2561 } while (status && frame--); in qh_schedule()
2563 /* qh->period == 0 means every uframe */ in qh_schedule()
2570 qh->start = frame; in qh_schedule()
2572 /* reset S-frame and (maybe) C-frame masks */ in qh_schedule()
2573 qh->hw_info2 &= cpu_to_le32(~(QH_CMASK | QH_SMASK)); in qh_schedule()
2574 qh->hw_info2 |= qh->period in qh_schedule()
2577 qh->hw_info2 |= c_mask; in qh_schedule()
2597 epnum = urb->ep->desc.bEndpointAddress; in intr_submit()
2599 spin_lock_irqsave(&oxu->lock, flags); in intr_submit()
2602 status = -ESHUTDOWN; in intr_submit()
2608 qh = qh_append_tds(oxu, urb, &empty, epnum, &urb->ep->hcpriv); in intr_submit()
2610 status = -ENOMEM; in intr_submit()
2613 if (qh->qh_state == QH_STATE_IDLE) { in intr_submit()
2620 qh = qh_append_tds(oxu, urb, qtd_list, epnum, &urb->ep->hcpriv); in intr_submit()
2624 oxu_to_hcd(oxu)->self.bandwidth_int_reqs++; in intr_submit()
2627 spin_unlock_irqrestore(&oxu->lock, flags); in intr_submit()
2638 return -ENOSYS; in itd_submit()
2645 return -ENOSYS; in sitd_submit()
2653 mod = oxu->periodic_size << 3; in scan_periodic()
2658 * Touches as few pages as possible: cache-friendly. in scan_periodic()
2660 now_uframe = oxu->next_uframe; in scan_periodic()
2661 if (HC_IS_RUNNING(oxu_to_hcd(oxu)->state)) in scan_periodic()
2662 clock = readl(&oxu->regs->frame_index); in scan_periodic()
2664 clock = now_uframe + mod - 1; in scan_periodic()
2680 q_p = &oxu->pshadow[frame]; in scan_periodic()
2681 hw_p = &oxu->periodic[frame]; in scan_periodic()
2682 q.ptr = q_p->ptr; in scan_periodic()
2693 type = Q_NEXT_TYPE(q.qh->hw_next); in scan_periodic()
2694 q = q.qh->qh_next; in scan_periodic()
2696 if (unlikely(list_empty(&temp.qh->qtd_list))) in scan_periodic()
2720 /* FIXME: likewise assumes HC doesn't halt mid-scan */ in scan_periodic()
2725 if (!HC_IS_RUNNING(oxu_to_hcd(oxu)->state)) in scan_periodic()
2727 oxu->next_uframe = now_uframe; in scan_periodic()
2728 now = readl(&oxu->regs->frame_index) % mod; in scan_periodic()
2747 int port = HCS_N_PORTS(oxu->hcs_params); in ehci_turn_off_all_ports()
2749 while (port--) in ehci_turn_off_all_ports()
2750 writel(PORT_RWC_BITS, &oxu->regs->port_status[port]); in ehci_turn_off_all_ports()
2757 if (!HCS_PPC(oxu->hcs_params)) in ehci_port_power()
2761 for (port = HCS_N_PORTS(oxu->hcs_params); port > 0; ) { in ehci_port_power()
2764 USB_PORT_FEAT_POWER, port--, NULL, 0); in ehci_port_power()
2767 USB_PORT_FEAT_POWER, port--, NULL, 0); in ehci_port_power()
2774 * It calls driver completion functions, after dropping oxu->lock.
2779 if (oxu->reclaim_ready) in ehci_work()
2782 /* another CPU may drop oxu->lock during a schedule scan while in ehci_work()
2784 * attempts at re-entrant schedule scanning. in ehci_work()
2786 if (oxu->scanning) in ehci_work()
2788 oxu->scanning = 1; in ehci_work()
2790 if (oxu->next_uframe != -1) in ehci_work()
2792 oxu->scanning = 0; in ehci_work()
2795 * misplace IRQs, and should let us run completely without IRQs. in ehci_work()
2798 if (HC_IS_RUNNING(oxu_to_hcd(oxu)->state) && in ehci_work()
2799 (oxu->async->qh_next.ptr != NULL || in ehci_work()
2800 oxu->periodic_sched != 0)) in ehci_work()
2807 if (qh->qh_state == QH_STATE_LINKED in unlink_async()
2808 && oxu->reclaim in unlink_async()
2809 && HC_IS_RUNNING(oxu_to_hcd(oxu)->state)) { in unlink_async()
2812 for (last = oxu->reclaim; in unlink_async()
2813 last->reclaim; in unlink_async()
2814 last = last->reclaim) in unlink_async()
2816 qh->qh_state = QH_STATE_UNLINK_WAIT; in unlink_async()
2817 last->reclaim = qh; in unlink_async()
2820 } else if (!HC_IS_RUNNING(oxu_to_hcd(oxu)->state) && oxu->reclaim) in unlink_async()
2824 if (qh->qh_state == QH_STATE_LINKED) in unlink_async()
2838 spin_lock(&oxu->lock); in oxu210_hcd_irq()
2840 status = readl(&oxu->regs->status); in oxu210_hcd_irq()
2850 if (!status || unlikely(hcd->state == HC_STATE_HALT)) { in oxu210_hcd_irq()
2851 spin_unlock(&oxu->lock); in oxu210_hcd_irq()
2856 writel(status, &oxu->regs->status); in oxu210_hcd_irq()
2857 readl(&oxu->regs->command); /* unblock posted write */ in oxu210_hcd_irq()
2873 oxu->reclaim_ready = 1; in oxu210_hcd_irq()
2879 unsigned i = HCS_N_PORTS(oxu->hcs_params); in oxu210_hcd_irq()
2883 if (!(readl(&oxu->regs->command) & CMD_RUN)) in oxu210_hcd_irq()
2886 while (i--) { in oxu210_hcd_irq()
2887 int pstatus = readl(&oxu->regs->port_status[i]); in oxu210_hcd_irq()
2892 || oxu->reset_done[i] != 0) in oxu210_hcd_irq()
2899 oxu->reset_done[i] = jiffies + in oxu210_hcd_irq()
2902 mod_timer(&hcd->rh_timer, oxu->reset_done[i]); in oxu210_hcd_irq()
2909 status = readl(&oxu->regs->status); in oxu210_hcd_irq()
2910 dbg_cmd(oxu, "fatal", readl(&oxu->regs->command)); in oxu210_hcd_irq()
2916 writel(0, &oxu->regs->configured_flag); in oxu210_hcd_irq()
2927 spin_unlock(&oxu->lock); in oxu210_hcd_irq()
2938 u32 status = oxu_readl(hcd->regs, OXU_CHIPIRQSTATUS); in oxu_irq()
2939 u32 enable = oxu_readl(hcd->regs, OXU_CHIPIRQEN_SET); in oxu_irq()
2942 oxu_writel(hcd->regs, OXU_CHIPIRQEN_CLR, enable); in oxu_irq()
2944 if ((oxu->is_otg && (status & OXU_USBOTGI)) || in oxu_irq()
2945 (!oxu->is_otg && (status & OXU_USBSPHI))) in oxu_irq()
2951 oxu_writel(hcd->regs, OXU_CHIPIRQEN_SET, enable); in oxu_irq()
2961 spin_lock_irqsave(&oxu->lock, flags); in oxu_watchdog()
2964 if (oxu->reclaim) { in oxu_watchdog()
2965 u32 status = readl(&oxu->regs->status); in oxu_watchdog()
2968 writel(STS_IAA, &oxu->regs->status); in oxu_watchdog()
2969 oxu->reclaim_ready = 1; in oxu_watchdog()
2974 if (test_bit(TIMER_ASYNC_OFF, &oxu->actions)) in oxu_watchdog()
2975 start_unlink_async(oxu, oxu->async); in oxu_watchdog()
2980 spin_unlock_irqrestore(&oxu->lock, flags); in oxu_watchdog()
2983 /* One-time init, only for memory state.
2992 spin_lock_init(&oxu->lock); in oxu_hcd_init()
2994 timer_setup(&oxu->watchdog, oxu_watchdog, 0); in oxu_hcd_init()
3000 oxu->periodic_size = DEFAULT_I_TDPS; in oxu_hcd_init()
3006 hcc_params = readl(&oxu->caps->hcc_params); in oxu_hcd_init()
3008 oxu->i_thresh = 8; in oxu_hcd_init()
3010 oxu->i_thresh = 2 + HCC_ISOC_THRES(hcc_params); in oxu_hcd_init()
3012 oxu->reclaim = NULL; in oxu_hcd_init()
3013 oxu->reclaim_ready = 0; in oxu_hcd_init()
3014 oxu->next_uframe = -1; in oxu_hcd_init()
3023 oxu->async->qh_next.qh = NULL; in oxu_hcd_init()
3024 oxu->async->hw_next = QH_NEXT(oxu->async->qh_dma); in oxu_hcd_init()
3025 oxu->async->hw_info1 = cpu_to_le32(QH_HEAD); in oxu_hcd_init()
3026 oxu->async->hw_token = cpu_to_le32(QTD_STS_HALT); in oxu_hcd_init()
3027 oxu->async->hw_qtd_next = EHCI_LIST_END; in oxu_hcd_init()
3028 oxu->async->qh_state = QH_STATE_LINKED; in oxu_hcd_init()
3029 oxu->async->hw_alt_next = QTD_NEXT(oxu->async->dummy->qtd_dma); in oxu_hcd_init()
3055 oxu->command = temp; in oxu_hcd_init()
3066 spin_lock_init(&oxu->mem_lock); in oxu_reset()
3067 INIT_LIST_HEAD(&oxu->urb_list); in oxu_reset()
3068 oxu->urb_len = 0; in oxu_reset()
3070 if (oxu->is_otg) { in oxu_reset()
3071 oxu->caps = hcd->regs + OXU_OTG_CAP_OFFSET; in oxu_reset()
3072 oxu->regs = hcd->regs + OXU_OTG_CAP_OFFSET + \ in oxu_reset()
3073 HC_LENGTH(readl(&oxu->caps->hc_capbase)); in oxu_reset()
3075 oxu->mem = hcd->regs + OXU_SPH_MEM; in oxu_reset()
3077 oxu->caps = hcd->regs + OXU_SPH_CAP_OFFSET; in oxu_reset()
3078 oxu->regs = hcd->regs + OXU_SPH_CAP_OFFSET + \ in oxu_reset()
3079 HC_LENGTH(readl(&oxu->caps->hc_capbase)); in oxu_reset()
3081 oxu->mem = hcd->regs + OXU_OTG_MEM; in oxu_reset()
3084 oxu->hcs_params = readl(&oxu->caps->hcs_params); in oxu_reset()
3085 oxu->sbrn = 0x20; in oxu_reset()
3096 hcd->uses_new_polling = 1; in oxu_run()
3104 writel(oxu->periodic_dma, &oxu->regs->frame_list); in oxu_run()
3105 writel((u32) oxu->async->qh_dma, &oxu->regs->async_next); in oxu_run()
3107 /* hcc_params controls whether oxu->regs->segment must (!!!) in oxu_run()
3113 * NOTE: the dma mask is visible through dev->dma_mask, so in oxu_run()
3118 hcc_params = readl(&oxu->caps->hcc_params); in oxu_run()
3120 writel(0, &oxu->regs->segment); in oxu_run()
3122 oxu->command &= ~(CMD_LRESET | CMD_IAAD | CMD_PSE | in oxu_run()
3124 oxu->command |= CMD_RUN; in oxu_run()
3125 writel(oxu->command, &oxu->regs->command); in oxu_run()
3126 dbg_cmd(oxu, "init", oxu->command); in oxu_run()
3134 hcd->state = HC_STATE_RUNNING; in oxu_run()
3135 writel(FLAG_CF, &oxu->regs->configured_flag); in oxu_run()
3136 readl(&oxu->regs->command); /* unblock posted writes */ in oxu_run()
3138 temp = HC_VERSION(readl(&oxu->caps->hc_capbase)); in oxu_run()
3139 oxu_info(oxu, "USB %x.%x started, quasi-EHCI %x.%02x, driver %s%s\n", in oxu_run()
3140 ((oxu->sbrn & 0xf0)>>4), (oxu->sbrn & 0x0f), in oxu_run()
3144 writel(INTR_MASK, &oxu->regs->intr_enable); /* Turn On Interrupts */ in oxu_run()
3157 del_timer_sync(&oxu->watchdog); in oxu_stop()
3159 spin_lock_irq(&oxu->lock); in oxu_stop()
3160 if (HC_IS_RUNNING(hcd->state)) in oxu_stop()
3164 writel(0, &oxu->regs->intr_enable); in oxu_stop()
3165 spin_unlock_irq(&oxu->lock); in oxu_stop()
3168 writel(0, &oxu->regs->configured_flag); in oxu_stop()
3171 spin_lock_irq(&oxu->lock); in oxu_stop()
3172 if (oxu->async) in oxu_stop()
3174 spin_unlock_irq(&oxu->lock); in oxu_stop()
3177 dbg_status(oxu, "oxu_stop completed", readl(&oxu->regs->status)); in oxu_stop()
3192 writel(0, &oxu->regs->configured_flag); in oxu_shutdown()
3195 readl(&oxu->regs->configured_flag); in oxu_shutdown()
3198 /* Non-error returns are a promise to giveback() the urb later
3204 * hcd-specific init for hcpriv hasn't been done yet
3217 switch (usb_pipetype(urb->pipe)) { in __oxu_urb_enqueue()
3222 return -ENOMEM; in __oxu_urb_enqueue()
3227 return -ENOMEM; in __oxu_urb_enqueue()
3231 if (urb->dev->speed == USB_SPEED_HIGH) in __oxu_urb_enqueue()
3251 if (!usb_pipebulk(urb->pipe)) in oxu_urb_enqueue()
3255 transfer_buffer = urb->transfer_buffer; in oxu_urb_enqueue()
3257 num = urb->transfer_buffer_length / 4096; in oxu_urb_enqueue()
3258 rem = urb->transfer_buffer_length % 4096; in oxu_urb_enqueue()
3268 for (i = 0; i < num - 1; i++) { in oxu_urb_enqueue()
3280 murb->transfer_buffer_length = 4096; in oxu_urb_enqueue()
3281 murb->transfer_buffer = transfer_buffer + i * 4096; in oxu_urb_enqueue()
3284 murb->complete = NULL; in oxu_urb_enqueue()
3286 ((struct oxu_murb *) murb)->main = urb; in oxu_urb_enqueue()
3287 ((struct oxu_murb *) murb)->last = 0; in oxu_urb_enqueue()
3311 murb->transfer_buffer_length = rem > 0 ? rem : 4096; in oxu_urb_enqueue()
3312 murb->transfer_buffer = transfer_buffer + (num - 1) * 4096; in oxu_urb_enqueue()
3315 murb->complete = NULL; in oxu_urb_enqueue()
3317 ((struct oxu_murb *) murb)->main = urb; in oxu_urb_enqueue()
3318 ((struct oxu_murb *) murb)->last = 1; in oxu_urb_enqueue()
3338 spin_lock_irqsave(&oxu->lock, flags); in oxu_urb_dequeue()
3339 switch (usb_pipetype(urb->pipe)) { in oxu_urb_dequeue()
3343 qh = (struct ehci_qh *) urb->hcpriv; in oxu_urb_dequeue()
3350 qh = (struct ehci_qh *) urb->hcpriv; in oxu_urb_dequeue()
3353 switch (qh->qh_state) { in oxu_urb_dequeue()
3362 qh, qh->qh_state); in oxu_urb_dequeue()
3367 if (!list_empty(&qh->qtd_list) in oxu_urb_dequeue()
3368 && HC_IS_RUNNING(hcd->state)) { in oxu_urb_dequeue()
3372 spin_unlock_irqrestore(&oxu->lock, flags); in oxu_urb_dequeue()
3378 dev_err(hcd->self.controller, in oxu_urb_dequeue()
3387 spin_unlock_irqrestore(&oxu->lock, flags); in oxu_urb_dequeue()
3403 spin_lock_irqsave(&oxu->lock, flags); in oxu_endpoint_disable()
3404 qh = ep->hcpriv; in oxu_endpoint_disable()
3411 if (qh->hw_info1 == 0) { in oxu_endpoint_disable()
3412 oxu_vdbg(oxu, "iso delay\n"); in oxu_endpoint_disable()
3416 if (!HC_IS_RUNNING(hcd->state)) in oxu_endpoint_disable()
3417 qh->qh_state = QH_STATE_IDLE; in oxu_endpoint_disable()
3418 switch (qh->qh_state) { in oxu_endpoint_disable()
3420 for (tmp = oxu->async->qh_next.qh; in oxu_endpoint_disable()
3422 tmp = tmp->qh_next.qh) in oxu_endpoint_disable()
3424 /* periodic qh self-unlinks on empty */ in oxu_endpoint_disable()
3431 spin_unlock_irqrestore(&oxu->lock, flags); in oxu_endpoint_disable()
3435 if (list_empty(&qh->qtd_list)) { in oxu_endpoint_disable()
3446 qh, ep->desc.bEndpointAddress, qh->qh_state, in oxu_endpoint_disable()
3447 list_empty(&qh->qtd_list) ? "" : "(has tds)"); in oxu_endpoint_disable()
3450 ep->hcpriv = NULL; in oxu_endpoint_disable()
3452 spin_unlock_irqrestore(&oxu->lock, flags); in oxu_endpoint_disable()
3459 return (readl(&oxu->regs->frame_index) >> 3) % in oxu_get_frame()
3460 oxu->periodic_size; in oxu_get_frame()
3472 if (!HC_IS_RUNNING(hcd->state)) in oxu_hub_status_data()
3475 /* init status to no-changes */ in oxu_hub_status_data()
3477 ports = HCS_N_PORTS(oxu->hcs_params); in oxu_hub_status_data()
3487 * PORT_POWER; that's surprising, but maybe within-spec. in oxu_hub_status_data()
3497 spin_lock_irqsave(&oxu->lock, flags); in oxu_hub_status_data()
3499 temp = readl(&oxu->regs->port_status[i]); in oxu_hub_status_data()
3504 * high-speed device is switched over to the companion in oxu_hub_status_data()
3509 oxu->reset_done[i] = 0; in oxu_hub_status_data()
3511 time_after_eq(jiffies, oxu->reset_done[i]))) { in oxu_hub_status_data()
3515 buf[1] |= 1 << (i - 7); in oxu_hub_status_data()
3520 spin_unlock_irqrestore(&oxu->lock, flags); in oxu_hub_status_data()
3544 int ports = HCS_N_PORTS(oxu->hcs_params); in oxu_hub_control()
3545 u32 __iomem *status_reg = &oxu->regs->port_status[wIndex - 1]; in oxu_hub_control()
3558 spin_lock_irqsave(&oxu->lock, flags); in oxu_hub_control()
3564 /* no hub-wide feature/status flags */ in oxu_hub_control()
3573 wIndex--; in oxu_hub_control()
3579 * the port-change status bits (especially in oxu_hub_control()
3599 oxu->reset_done[wIndex] = jiffies in oxu_hub_control()
3604 /* we auto-clear this feature */ in oxu_hub_control()
3607 if (HCS_PPC(oxu->hcs_params)) in oxu_hub_control()
3623 readl(&oxu->regs->command); /* unblock posted write */ in oxu_hub_control()
3630 /* no hub-wide feature/status flags */ in oxu_hub_control()
3636 wIndex--; in oxu_hub_control()
3652 if (!oxu->reset_done[wIndex]) { in oxu_hub_control()
3654 oxu->reset_done[wIndex] = jiffies in oxu_hub_control()
3657 mod_timer(&oxu_to_hcd(oxu)->rh_timer, in oxu_hub_control()
3658 oxu->reset_done[wIndex]); in oxu_hub_control()
3663 oxu->reset_done[wIndex])) { in oxu_hub_control()
3665 oxu->reset_done[wIndex] = 0; in oxu_hub_control()
3686 oxu->reset_done[wIndex])) { in oxu_hub_control()
3688 oxu->reset_done[wIndex] = 0; in oxu_hub_control()
3711 test_bit(wIndex, &oxu->companion_ports)) { in oxu_hub_control()
3715 oxu_dbg(oxu, "port %d --> companion\n", wIndex + 1); in oxu_hub_control()
3751 /* no hub-wide feature/status flags */ in oxu_hub_control()
3762 wIndex--; in oxu_hub_control()
3773 if (device_may_wakeup(&hcd->self.root_hub->dev)) in oxu_hub_control()
3778 if (HCS_PPC(oxu->hcs_params)) in oxu_hub_control()
3796 oxu->reset_done[wIndex] = jiffies in oxu_hub_control()
3805 * about the EHCI-specific stuff. in oxu_hub_control()
3819 readl(&oxu->regs->command); /* unblock posted writes */ in oxu_hub_control()
3825 retval = -EPIPE; in oxu_hub_control()
3827 spin_unlock_irqrestore(&oxu->lock, flags); in oxu_hub_control()
3841 if (time_before(jiffies, oxu->next_statechange)) in oxu_bus_suspend()
3844 port = HCS_N_PORTS(oxu->hcs_params); in oxu_bus_suspend()
3845 spin_lock_irq(&oxu->lock); in oxu_bus_suspend()
3848 if (HC_IS_RUNNING(hcd->state)) { in oxu_bus_suspend()
3850 hcd->state = HC_STATE_QUIESCING; in oxu_bus_suspend()
3852 oxu->command = readl(&oxu->regs->command); in oxu_bus_suspend()
3853 if (oxu->reclaim) in oxu_bus_suspend()
3854 oxu->reclaim_ready = 1; in oxu_bus_suspend()
3858 * any notion of "global" or bus-wide suspend. The driver has in oxu_bus_suspend()
3862 oxu->bus_suspended = 0; in oxu_bus_suspend()
3863 while (port--) { in oxu_bus_suspend()
3864 u32 __iomem *reg = &oxu->regs->port_status[port]; in oxu_bus_suspend()
3872 set_bit(port, &oxu->bus_suspended); in oxu_bus_suspend()
3876 if (device_may_wakeup(&hcd->self.root_hub->dev)) in oxu_bus_suspend()
3882 oxu_vdbg(oxu, "port %d, %08x -> %08x\n", in oxu_bus_suspend()
3888 spin_unlock_irq(&oxu->lock); in oxu_bus_suspend()
3889 /* turn off now-idle HC */ in oxu_bus_suspend()
3890 del_timer_sync(&oxu->watchdog); in oxu_bus_suspend()
3891 spin_lock_irq(&oxu->lock); in oxu_bus_suspend()
3893 hcd->state = HC_STATE_SUSPENDED; in oxu_bus_suspend()
3897 if (!device_may_wakeup(&hcd->self.root_hub->dev)) in oxu_bus_suspend()
3899 writel(mask, &oxu->regs->intr_enable); in oxu_bus_suspend()
3900 readl(&oxu->regs->intr_enable); in oxu_bus_suspend()
3902 oxu->next_statechange = jiffies + msecs_to_jiffies(10); in oxu_bus_suspend()
3903 spin_unlock_irq(&oxu->lock); in oxu_bus_suspend()
3914 if (time_before(jiffies, oxu->next_statechange)) in oxu_bus_resume()
3916 spin_lock_irq(&oxu->lock); in oxu_bus_resume()
3920 * could instead be restoring a swsusp snapshot -- so that BIOS was in oxu_bus_resume()
3924 temp = readl(&oxu->regs->intr_enable); in oxu_bus_resume()
3928 * IRQs right away, so delay them until we're ready. in oxu_bus_resume()
3930 writel(0, &oxu->regs->intr_enable); in oxu_bus_resume()
3932 /* re-init operational registers */ in oxu_bus_resume()
3933 writel(0, &oxu->regs->segment); in oxu_bus_resume()
3934 writel(oxu->periodic_dma, &oxu->regs->frame_list); in oxu_bus_resume()
3935 writel((u32) oxu->async->qh_dma, &oxu->regs->async_next); in oxu_bus_resume()
3938 writel(oxu->command, &oxu->regs->command); in oxu_bus_resume()
3940 /* Some controller/firmware combinations need a delay during which in oxu_bus_resume()
3945 i = HCS_N_PORTS(oxu->hcs_params); in oxu_bus_resume()
3946 while (i--) { in oxu_bus_resume()
3947 temp = readl(&oxu->regs->port_status[i]); in oxu_bus_resume()
3950 if (test_bit(i, &oxu->bus_suspended) && (temp & PORT_SUSPEND)) { in oxu_bus_resume()
3951 oxu->reset_done[i] = jiffies + msecs_to_jiffies(20); in oxu_bus_resume()
3954 writel(temp, &oxu->regs->port_status[i]); in oxu_bus_resume()
3956 i = HCS_N_PORTS(oxu->hcs_params); in oxu_bus_resume()
3958 while (i--) { in oxu_bus_resume()
3959 temp = readl(&oxu->regs->port_status[i]); in oxu_bus_resume()
3960 if (test_bit(i, &oxu->bus_suspended) && (temp & PORT_SUSPEND)) { in oxu_bus_resume()
3962 writel(temp, &oxu->regs->port_status[i]); in oxu_bus_resume()
3966 (void) readl(&oxu->regs->command); in oxu_bus_resume()
3968 /* maybe re-activate the schedule(s) */ in oxu_bus_resume()
3970 if (oxu->async->qh_next.qh) in oxu_bus_resume()
3972 if (oxu->periodic_sched) in oxu_bus_resume()
3975 oxu->command |= temp; in oxu_bus_resume()
3976 writel(oxu->command, &oxu->regs->command); in oxu_bus_resume()
3979 oxu->next_statechange = jiffies + msecs_to_jiffies(5); in oxu_bus_resume()
3980 hcd->state = HC_STATE_RUNNING; in oxu_bus_resume()
3982 /* Now we can safely re-enable irqs */ in oxu_bus_resume()
3983 writel(INTR_MASK, &oxu->regs->intr_enable); in oxu_bus_resume()
3985 spin_unlock_irq(&oxu->lock); in oxu_bus_resume()
4082 "128-pin LQFP", in oxu_verify_id()
4083 "84-pin TFBGA", in oxu_verify_id()
4089 dev_info(&pdev->dev, "device ID %x\n", id); in oxu_verify_id()
4091 return -1; in oxu_verify_id()
4093 dev_info(&pdev->dev, "found device %x %s (%04x:%04x)\n", in oxu_verify_id()
4107 struct device *dev = &pdev->dev; in oxu_create()
4121 return ERR_PTR(-ENOMEM); in oxu_create()
4123 hcd->rsrc_start = memstart; in oxu_create()
4124 hcd->rsrc_len = memlen; in oxu_create()
4125 hcd->regs = base; in oxu_create()
4126 hcd->irq = irq; in oxu_create()
4127 hcd->state = HC_STATE_HALT; in oxu_create()
4130 oxu->is_otg = otg; in oxu_create()
4138 device_wakeup_enable(hcd->self.controller); in oxu_create()
4155 dev_err(&pdev->dev, "no devices found!\n"); in oxu_init()
4156 return -ENODEV; in oxu_init()
4162 dev_err(&pdev->dev, "cannot create OTG controller!\n"); in oxu_init()
4166 info->hcd[0] = hcd; in oxu_init()
4171 dev_err(&pdev->dev, "cannot create SPH controller!\n"); in oxu_init()
4175 info->hcd[1] = hcd; in oxu_init()
4183 usb_remove_hcd(info->hcd[0]); in oxu_init()
4184 usb_put_hcd(info->hcd[0]); in oxu_init()
4199 return -ENODEV; in oxu_drv_probe()
4207 dev_dbg(&pdev->dev, "IRQ resource %d\n", irq); in oxu_drv_probe()
4214 memstart = res->start; in oxu_drv_probe()
4219 dev_err(&pdev->dev, "error setting irq type\n"); in oxu_drv_probe()
4220 ret = -EFAULT; in oxu_drv_probe()
4227 info = devm_kzalloc(&pdev->dev, sizeof(struct oxu_info), GFP_KERNEL); in oxu_drv_probe()
4229 ret = -EFAULT; in oxu_drv_probe()
4236 dev_dbg(&pdev->dev, "cannot init USB devices\n"); in oxu_drv_probe()
4240 dev_info(&pdev->dev, "devices enabled and running\n"); in oxu_drv_probe()
4246 dev_err(&pdev->dev, "init %s fail, %d\n", dev_name(&pdev->dev), ret); in oxu_drv_probe()
4260 oxu_remove(pdev, info->hcd[0]); in oxu_drv_remove()
4261 oxu_remove(pdev, info->hcd[1]); in oxu_drv_remove()
4298 .name = "oxu210hp-hcd",
4305 MODULE_DESCRIPTION("Oxford OXU210HP HCD driver - ver. " DRIVER_VERSION);