47 size_t len,
int token,
int maxpacket)
55 count = 0x1000 - (buf & 0x0fff);
63 for (i = 1; count < len && i < 5; i++) {
69 if ((count + 0x1000) < len)
77 count -= (count % maxpacket);
104 unsigned is_out, epnum;
107 epnum = (hc32_to_cpup(ehci, &hw->
hw_info1) >> 8) & 0x0f;
108 if (
unlikely (!usb_gettoggle (qh->
dev, epnum, is_out))) {
110 usb_settoggle (qh->
dev, epnum, is_out, 1);
145 qh_update (ehci, qh, qtd);
152 static void ehci_clear_tt_buffer_complete(
struct usb_hcd *hcd,
153 struct usb_host_endpoint *ep)
155 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
156 struct ehci_qh *qh = ep->hcpriv;
163 qh_link_async(ehci, qh);
164 spin_unlock_irqrestore(&ehci->
lock, flags);
167 static void ehci_clear_tt_buffer(
struct ehci_hcd *ehci,
struct ehci_qh *qh,
177 if (urb->dev->tt && !usb_pipeint(urb->pipe) && !qh->
clearing_tt) {
179 struct usb_device *
tt = urb->dev->tt->hub;
181 "clear tt buffer port %d, a%d ep%d t%08x\n",
182 urb->dev->ttport, urb->dev->devnum,
183 usb_pipeendpoint(urb->pipe), token);
186 || urb->dev->tt->hub !=
187 ehci_to_hcd(ehci)->
self.root_hub) {
199 static int qtd_copy_status (
210 urb->actual_length += length -
QTD_LENGTH (token);
237 status = (
QTD_PID (token) == 1)
242 ehci_dbg(ehci,
"devpath %s ep%d%s 3strikes\n",
244 usb_pipeendpoint(urb->pipe),
245 usb_pipein(urb->pipe) ?
"in" :
"out");
252 "dev%d ep%d%s qtd token %08x --> status %d\n",
253 usb_pipedevice (urb->pipe),
254 usb_pipeendpoint (urb->pipe),
255 usb_pipein (urb->pipe) ?
"in" :
"out",
263 ehci_urb_done(
struct ehci_hcd *ehci,
struct urb *urb,
int status)
267 if (usb_pipetype(urb->pipe) == PIPE_INTERRUPT) {
269 ehci_to_hcd(ehci)->self.bandwidth_int_reqs--;
273 COUNT(ehci->stats.unlink);
278 COUNT(ehci->stats.complete);
281 #ifdef EHCI_URB_TRACE
283 "%s %s urb %p ep%d%s status %d len %d/%d\n",
284 __func__, urb->dev->devpath, urb,
285 usb_pipeendpoint (urb->pipe),
286 usb_pipein (urb->pipe) ?
"in" :
"out",
288 urb->actual_length, urb->transfer_buffer_length);
293 spin_unlock (&ehci->
lock);
295 spin_lock (&ehci->
lock);
354 ehci_urb_done(ehci, last->
urb, last_status);
358 ehci_qtd_free (ehci, last);
375 if (token & QTD_STS_DBE)
377 "detected DataBufferErr for urb %p ep%d%s len %d, qtd %p [qh %p]\n",
379 usb_endpoint_num(&urb->ep->desc),
380 usb_endpoint_dir_in(&urb->ep->desc) ?
"in" :
"out",
381 urb->transfer_buffer_length,
388 if ((token & QTD_STS_HALT) != 0) {
393 if ((token & QTD_STS_XACT) &&
398 "detected XactErr len %zu/%zu retry %d\n",
406 token &= ~QTD_STS_HALT;
407 token |= QTD_STS_ACTIVE |
434 }
else if (
likely (!stopped
449 else if (last_status == -
EINPROGRESS && !urb->unlinked)
462 ehci_clear_tt_buffer(ehci, qh, urb, token);
474 last_status = qtd_copy_status(ehci, urb,
495 if (last_status != -
EPIPE)
496 ehci_clear_tt_buffer(ehci, qh, urb,
520 ehci_urb_done(ehci, last->
urb, last_status);
522 ehci_qtd_free (ehci, last);
550 qh_refresh(ehci, qh);
578 #define hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))
580 #define max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff)
586 static void qtd_list_free (
598 ehci_qtd_free (ehci, qtd);
614 int len, this_sg_len, maxpacket;
623 qtd = ehci_qtd_alloc (ehci, flags);
633 len = urb->transfer_buffer_length;
634 is_input = usb_pipein (urb->pipe);
635 if (usb_pipecontrol (urb->pipe)) {
637 qtd_fill(ehci, qtd, urb->setup_dma,
639 token | (2 << 8), 8);
644 qtd = ehci_qtd_alloc (ehci, flags);
659 i = urb->num_mapped_sgs;
660 if (len > 0 && i > 0) {
670 buf = urb->transfer_dma;
678 maxpacket =
max_packet(usb_maxpacket(urb->dev, urb->pipe, !is_input));
688 this_qtd_len = qtd_fill(ehci, qtd, buf, this_sg_len, token,
690 this_sg_len -= this_qtd_len;
703 if ((maxpacket & (this_qtd_len + (maxpacket - 1))) == 0)
706 if (
likely(this_sg_len <= 0)) {
707 if (--i <= 0 || len <= 0)
715 qtd = ehci_qtd_alloc (ehci, flags);
728 if (
likely ((urb->transfer_flags & URB_SHORT_NOT_OK) == 0
729 || usb_pipecontrol (urb->pipe)))
737 if (
likely (urb->transfer_buffer_length != 0)) {
740 if (usb_pipecontrol (urb->pipe)) {
744 }
else if (usb_pipeout(urb->pipe)
745 && (urb->transfer_flags & URB_ZERO_PACKET)
746 && !(urb->transfer_buffer_length % maxpacket)) {
751 qtd = ehci_qtd_alloc (ehci, flags);
759 qtd_fill(ehci, qtd, 0, 0, token, 0);
764 if (
likely (!(urb->transfer_flags & URB_NO_INTERRUPT)))
769 qtd_list_free (ehci, urb, head);
796 struct ehci_qh *qh = ehci_qh_alloc (ehci, flags);
800 struct usb_tt *tt = urb->dev->tt;
809 info1 |= usb_pipeendpoint (urb->pipe) << 8;
810 info1 |= usb_pipedevice (urb->pipe) << 0;
812 is_input = usb_pipein (urb->pipe);
813 type = usb_pipetype (urb->pipe);
814 maxp = usb_maxpacket (urb->dev, urb->pipe, !is_input);
832 if (type == PIPE_INTERRUPT) {
842 qh->
period = urb->interval >> 3;
843 if (qh->
period == 0 && urb->interval != 1) {
851 urb->interval = qh->
period << 3;
858 is_input, 0, maxp) / (125 * 1000);
863 qh->
usecs = HS_USECS (1);
865 qh->
usecs += HS_USECS (1);
869 think_time = tt ? tt->think_time : 0;
870 qh->
tt_usecs = NS_TO_US (think_time +
873 qh->
period = urb->interval;
876 urb->interval = qh->
period;
885 switch (urb->dev->speed) {
892 if (type != PIPE_INTERRUPT)
894 if (type == PIPE_CONTROL) {
906 info2 |= (urb->dev->ttport-1) << 23;
908 info2 |= urb->dev->ttport << 23;
913 if (tt && tt->hub != ehci_to_hcd(ehci)->self.root_hub)
914 info2 |= tt->hub->devnum << 16;
922 if (type == PIPE_CONTROL) {
927 }
else if (type == PIPE_BULK) {
943 ehci_dbg(ehci,
"bogus dev %p speed %d\n", urb->dev,
946 qh_destroy(ehci, qh);
958 usb_settoggle (urb->dev, usb_pipeendpoint (urb->pipe), !is_input, 1);
959 qh_refresh (ehci, qh);
965 static void enable_async(
struct ehci_hcd *ehci)
975 turn_on_io_watchdog(ehci);
978 static void disable_async(
struct ehci_hcd *ehci)
1004 qh_refresh(ehci, qh);
1009 qh->
hw->hw_next = head->
hw->hw_next;
1013 head->
hw->hw_next =
dma;
1030 static struct ehci_qh *qh_append_tds (
1050 if (
unlikely (list_empty (qtd_list)))
1060 if (usb_pipedevice (urb->pipe) == 0)
1061 qh->
hw->hw_info1 &= ~qh_addr_mask;
1087 list_add (&dummy->
qtd_list, qtd_list);
1088 list_splice_tail(qtd_list, &qh->
qtd_list);
1090 ehci_qtd_init(ehci, qtd, qtd->
qtd_dma);
1119 unsigned long flags;
1123 epnum = urb->ep->desc.bEndpointAddress;
1125 #ifdef EHCI_URB_TRACE
1130 "%s %s urb %p ep%d%s len %d, qtd %p [qh %p]\n",
1131 __func__, urb->dev->devpath, urb,
1132 epnum & 0x0f, (epnum &
USB_DIR_IN) ?
"in" :
"out",
1133 urb->transfer_buffer_length,
1134 qtd, urb->ep->hcpriv);
1139 if (
unlikely(!HCD_HW_ACCESSIBLE(ehci_to_hcd(ehci)))) {
1147 qh = qh_append_tds(ehci, urb, qtd_list, epnum, &urb->ep->hcpriv);
1158 qh_link_async(ehci, qh);
1160 spin_unlock_irqrestore (&ehci->
lock, flags);
1162 qtd_list_free (ehci, urb, qtd_list);
1168 static void single_unlink_async(
struct ehci_hcd *ehci,
struct ehci_qh *qh)
1185 prev->
hw->hw_next = qh->
hw->hw_next;
1191 static void start_iaa_cycle(
struct ehci_hcd *ehci,
bool nested)
1207 end_unlink_async(ehci);
1215 &ehci->
regs->command);
1216 ehci_readl(ehci, &ehci->
regs->command);
1223 static void end_unlink_async(
struct ehci_hcd *ehci)
1228 ehci_writel(ehci, (
u32) ehci->
async->qh_dma,
1229 &ehci->
regs->async_next);
1242 qh_completions(ehci, qh);
1245 qh_link_async(ehci, qh);
1246 disable_async(ehci);
1252 start_iaa_cycle(ehci,
true);
1258 static void unlink_empty_async(
struct ehci_hcd *ehci)
1262 bool check_unlinks_later =
false;
1265 next = ehci->
async->qh_next.qh;
1274 check_unlinks_later =
true;
1276 single_unlink_async(ehci, qh);
1282 start_iaa_cycle(ehci,
false);
1285 if (check_unlinks_later) {
1294 static void start_unlink_async(
struct ehci_hcd *ehci,
struct ehci_qh *qh)
1307 single_unlink_async(ehci, qh);
1308 start_iaa_cycle(ehci,
false);
1313 static void scan_async (
struct ehci_hcd *ehci)
1316 bool check_unlinks_later =
false;
1334 temp = qh_completions(ehci, qh);
1336 start_unlink_async(ehci, qh);
1337 }
else if (list_empty(&qh->
qtd_list)
1340 check_unlinks_later =
true;
1341 }
else if (temp != 0)