2 * Freescale QUICC Engine USB Host Controller Driver
4 * Copyright (c) Freescale Semicondutor, Inc. 2006.
5 * Shlomi Gridish <gridish@freescale.com>
6 * Jerry Huang <Chang-Ming.Huang@freescale.com>
7 * Copyright (c) Logic Product Development, Inc. 2007
8 * Peter Barada <peterb@logicpd.com>
9 * Copyright (c) MontaVista Software, Inc. 2008.
10 * Anton Vorontsov <avorontsov@ru.mvista.com>
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
18 #include <linux/kernel.h>
19 #include <linux/types.h>
20 #include <linux/spinlock.h>
21 #include <linux/delay.h>
22 #include <linux/errno.h>
23 #include <linux/list.h>
24 #include <linux/interrupt.h>
26 #include <linux/usb.h>
28 #include <asm/fsl_gtm.h>
29 #include "../core/hcd.h"
32 static void recycle_frame(struct fhci_usb *usb, struct packet *pkt)
36 pkt->status = USB_TD_OK;
38 pkt->priv_data = NULL;
40 cq_put(usb->ep0->empty_frame_Q, pkt);
43 /* confirm submitted packet */
44 void fhci_transaction_confirm(struct fhci_usb *usb, struct packet *pkt)
47 struct packet *td_pkt;
52 td = fhci_remove_td_from_frame(usb->actual_frame);
55 td->status = pkt->status;
56 if (td->type == FHCI_TA_IN && td_pkt->info & PKT_DUMMY_PACKET) {
57 if ((td->data + td->actual_len) && trans_len)
58 memcpy(td->data + td->actual_len, pkt->data,
60 cq_put(usb->ep0->dummy_packets_Q, pkt->data);
63 recycle_frame(usb, pkt);
66 if (ed->mode == FHCI_TF_ISO) {
67 if (ed->td_list.next->next != &ed->td_list) {
69 list_entry(ed->td_list.next->next, struct td,
72 td_next->start_frame = usb->actual_frame->frame_num;
74 td->actual_len = trans_len;
76 } else if ((td->status & USB_TD_ERROR) &&
77 !(td->status & USB_TD_TX_ER_NAK)) {
79 * There was an error on the transaction (but not NAK).
80 * If it is fatal error (data underrun, stall, bad pid or 3
81 * errors exceeded), mark this TD as done.
83 if ((td->status & USB_TD_RX_DATA_UNDERUN) ||
84 (td->status & USB_TD_TX_ER_STALL) ||
85 (td->status & USB_TD_RX_ER_PID) ||
86 (++td->error_cnt >= 3)) {
87 ed->state = FHCI_ED_HALTED;
90 if (td->status & USB_TD_RX_DATA_UNDERUN) {
91 fhci_dbg(usb->fhci, "td err fu\n");
92 td->toggle = !td->toggle;
93 td->actual_len += trans_len;
95 fhci_dbg(usb->fhci, "td err f!u\n");
98 fhci_dbg(usb->fhci, "td err !f\n");
99 /* it is not a fatal error -retry this transaction */
102 td->status = USB_TD_OK;
104 } else if (td->status & USB_TD_TX_ER_NAK) {
105 /* there was a NAK response */
106 fhci_vdbg(usb->fhci, "td nack\n");
109 td->status = USB_TD_OK;
111 /* there was no error on transaction */
114 td->toggle = !td->toggle;
115 td->actual_len += trans_len;
117 if (td->len == td->actual_len)
122 fhci_move_td_from_ed_to_done_list(usb, ed);
126 * Flush all transmitted packets from BDs
127 * This routine is called when disabling the USB port to flush all
128 * transmissions that are allready scheduled in the BDs
130 void fhci_flush_all_transmissions(struct fhci_usb *usb)
135 mode = in_8(&usb->fhci->regs->usb_mod);
136 clrbits8(&usb->fhci->regs->usb_mod, USB_MODE_EN);
140 while ((td = fhci_peek_td_from_frame(usb->actual_frame)) != NULL) {
141 struct packet *pkt = td->pkt;
143 pkt->status = USB_TD_TX_ER_TIMEOUT;
144 fhci_transaction_confirm(usb, pkt);
147 usb->actual_frame->frame_status = FRAME_END_TRANSMISSION;
149 /* reset the event register */
150 out_be16(&usb->fhci->regs->usb_event, 0xffff);
151 /* enable the USB controller */
152 out_8(&usb->fhci->regs->usb_mod, mode | USB_MODE_EN);
156 * This function forms the packet and transmit the packet. This function
157 * will handle all endpoint type:ISO,interrupt,control and bulk
159 static int add_packet(struct fhci_usb *usb, struct ed *ed, struct td *td)
161 u32 fw_transaction_time, len = 0;
165 /* calcalate data address,len and toggle and then add the transaction */
166 if (td->toggle == USB_TD_TOGGLE_CARRY)
167 td->toggle = ed->toggle_carry;
172 if (td->type != FHCI_TA_IN)
177 len = min(td->len - td->actual_len, ed->max_pkt_size);
178 if (!((td->type == FHCI_TA_IN) &&
179 ((len + td->actual_len) == td->len)))
180 data = td->data + td->actual_len;
183 len = min(td->len, ed->max_pkt_size);
184 if (!((td->type == FHCI_TA_IN) &&
185 ((td->len + CRC_SIZE) >= ed->max_pkt_size)))
192 if (usb->port_status == FHCI_PORT_FULL)
193 fw_transaction_time = (((len + PROTOCOL_OVERHEAD) * 11) >> 4);
195 fw_transaction_time = ((len + PROTOCOL_OVERHEAD) * 6);
197 /* check if there's enough space in this frame to submit this TD */
198 if (usb->actual_frame->total_bytes + len + PROTOCOL_OVERHEAD >=
199 usb->max_bytes_per_frame) {
200 fhci_vdbg(usb->fhci, "not enough space in this frame: "
201 "%d %d %d\n", usb->actual_frame->total_bytes, len,
202 usb->max_bytes_per_frame);
206 /* check if there's enough time in this frame to submit this TD */
207 if (usb->actual_frame->frame_status != FRAME_IS_PREPARED &&
208 (usb->actual_frame->frame_status & FRAME_END_TRANSMISSION ||
209 (fw_transaction_time + usb->sw_transaction_time >=
210 1000 - fhci_get_sof_timer_count(usb)))) {
211 fhci_dbg(usb->fhci, "not enough time in this frame\n");
215 /* update frame object fields before transmitting */
216 pkt = cq_get(usb->ep0->empty_frame_Q);
218 fhci_dbg(usb->fhci, "there is no empty frame\n");
225 data = cq_get(usb->ep0->dummy_packets_Q);
227 pkt->info = PKT_DUMMY_PACKET;
231 pkt->status = USB_TD_OK;
232 /* update TD status field before transmitting */
233 td->status = USB_TD_INPROGRESS;
234 /* update actual frame time object with the actual transmission */
235 usb->actual_frame->total_bytes += (len + PROTOCOL_OVERHEAD);
236 fhci_add_td_to_frame(usb->actual_frame, td);
238 if (usb->port_status != FHCI_PORT_FULL &&
239 usb->port_status != FHCI_PORT_LOW) {
240 pkt->status = USB_TD_TX_ER_TIMEOUT;
242 fhci_transaction_confirm(usb, pkt);
243 } else if (fhci_host_transaction(usb, pkt, td->type, ed->dev_addr,
244 ed->ep_addr, ed->mode, ed->speed, td->toggle)) {
245 /* remove TD from actual frame */
246 list_del_init(&td->frame_lh);
247 td->status = USB_TD_OK;
248 if (pkt->info & PKT_DUMMY_PACKET)
249 cq_put(usb->ep0->dummy_packets_Q, pkt->data);
250 recycle_frame(usb, pkt);
251 usb->actual_frame->total_bytes -= (len + PROTOCOL_OVERHEAD);
252 fhci_err(usb->fhci, "host transaction failed\n");
259 static void move_head_to_tail(struct list_head *list)
261 struct list_head *node = list->next;
263 if (!list_empty(list)) {
265 list_add_tail(node, list);
270 * This function goes through the endpoint list and schedules the
271 * transactions within this list
273 static int scan_ed_list(struct fhci_usb *usb,
274 struct list_head *list, enum fhci_tf_mode list_type)
276 static const int frame_part[4] = {
277 [FHCI_TF_CTRL] = MAX_BYTES_PER_FRAME,
278 [FHCI_TF_ISO] = (MAX_BYTES_PER_FRAME *
279 MAX_PERIODIC_FRAME_USAGE) / 100,
280 [FHCI_TF_BULK] = MAX_BYTES_PER_FRAME,
281 [FHCI_TF_INTR] = (MAX_BYTES_PER_FRAME *
282 MAX_PERIODIC_FRAME_USAGE) / 100
287 u32 save_transaction_time = usb->sw_transaction_time;
289 list_for_each_entry(ed, list, node) {
292 if (!td || (td && td->status == USB_TD_INPROGRESS))
295 if (ed->state != FHCI_ED_OPER) {
296 if (ed->state == FHCI_ED_URB_DEL) {
297 td->status = USB_TD_OK;
298 fhci_move_td_from_ed_to_done_list(usb, ed);
299 ed->state = FHCI_ED_SKIP;
305 * if it isn't interrupt pipe or it is not iso pipe and the
306 * interval time passed
308 if ((list_type == FHCI_TF_INTR || list_type == FHCI_TF_ISO) &&
309 (((usb->actual_frame->frame_num -
310 td->start_frame) & 0x7ff) < td->interval))
313 if (add_packet(usb, ed, td) < 0)
316 /* update time stamps in the TD */
317 td->start_frame = usb->actual_frame->frame_num;
318 usb->sw_transaction_time += save_transaction_time;
320 if (usb->actual_frame->total_bytes >=
321 usb->max_bytes_per_frame) {
322 usb->actual_frame->frame_status =
323 FRAME_DATA_END_TRANSMISSION;
324 fhci_push_dummy_bd(usb->ep0);
329 if (usb->actual_frame->total_bytes >= frame_part[list_type])
333 /* be fair to each ED(move list head around) */
334 move_head_to_tail(list);
335 usb->sw_transaction_time = save_transaction_time;
340 static u32 rotate_frames(struct fhci_usb *usb)
342 struct fhci_hcd *fhci = usb->fhci;
344 if (!list_empty(&usb->actual_frame->tds_list)) {
345 if ((((in_be16(&fhci->pram->frame_num) & 0x07ff) -
346 usb->actual_frame->frame_num) & 0x7ff) > 5)
347 fhci_flush_actual_frame(usb);
352 usb->actual_frame->frame_status = FRAME_IS_PREPARED;
353 usb->actual_frame->frame_num = in_be16(&fhci->pram->frame_num) & 0x7ff;
354 usb->actual_frame->total_bytes = 0;
360 * This function schedule the USB transaction and will process the
361 * endpoint in the following order: iso, interrupt, control and bulk.
363 void fhci_schedule_transactions(struct fhci_usb *usb)
367 if (usb->actual_frame->frame_status & FRAME_END_TRANSMISSION)
368 if (rotate_frames(usb) != 0)
371 if (usb->actual_frame->frame_status & FRAME_END_TRANSMISSION)
374 if (usb->actual_frame->total_bytes == 0) {
376 * schedule the next available ISO transfer
377 *or next stage of the ISO transfer
379 scan_ed_list(usb, &usb->hc_list->iso_list, FHCI_TF_ISO);
382 * schedule the next available interrupt transfer or
383 * the next stage of the interrupt transfer
385 scan_ed_list(usb, &usb->hc_list->intr_list, FHCI_TF_INTR);
388 * schedule the next available control transfer
389 * or the next stage of the control transfer
391 left = scan_ed_list(usb, &usb->hc_list->ctrl_list,
396 * schedule the next available bulk transfer or the next stage of the
400 scan_ed_list(usb, &usb->hc_list->bulk_list, FHCI_TF_BULK);
403 /* Handles SOF interrupt */
404 static void sof_interrupt(struct fhci_hcd *fhci)
406 struct fhci_usb *usb = fhci->usb_lld;
408 if ((usb->port_status == FHCI_PORT_DISABLED) &&
409 (usb->vroot_hub->port.wPortStatus & USB_PORT_STAT_CONNECTION) &&
410 !(usb->vroot_hub->port.wPortChange & USB_PORT_STAT_C_CONNECTION)) {
411 if (usb->vroot_hub->port.wPortStatus & USB_PORT_STAT_LOW_SPEED)
412 usb->port_status = FHCI_PORT_LOW;
414 usb->port_status = FHCI_PORT_FULL;
416 usb->saved_msk &= ~USB_E_IDLE_MASK;
417 out_be16(&usb->fhci->regs->usb_mask, usb->saved_msk);
420 gtm_set_exact_timer16(fhci->timer, usb->max_frame_usage, false);
422 fhci_host_transmit_actual_frame(usb);
423 usb->actual_frame->frame_status = FRAME_IS_TRANSMITTED;
425 fhci_schedule_transactions(usb);
428 /* Handles device disconnected interrupt on port */
429 void fhci_device_disconnected_interrupt(struct fhci_hcd *fhci)
431 struct fhci_usb *usb = fhci->usb_lld;
433 fhci_dbg(fhci, "-> %s\n", __func__);
435 fhci_usb_disable_interrupt(usb);
436 clrbits8(&usb->fhci->regs->usb_mod, USB_MODE_LSS);
437 usb->port_status = FHCI_PORT_DISABLED;
439 fhci_stop_sof_timer(fhci);
441 /* Enable IDLE since we want to know if something comes along */
442 usb->saved_msk |= USB_E_IDLE_MASK;
443 out_be16(&usb->fhci->regs->usb_mask, usb->saved_msk);
445 usb->vroot_hub->port.wPortStatus &= ~USB_PORT_STAT_CONNECTION;
446 usb->vroot_hub->port.wPortChange |= USB_PORT_STAT_C_CONNECTION;
447 usb->max_bytes_per_frame = 0;
448 fhci_usb_enable_interrupt(usb);
450 fhci_dbg(fhci, "<- %s\n", __func__);
453 /* detect a new device connected on the USB port */
454 void fhci_device_connected_interrupt(struct fhci_hcd *fhci)
457 struct fhci_usb *usb = fhci->usb_lld;
461 fhci_dbg(fhci, "-> %s\n", __func__);
463 fhci_usb_disable_interrupt(usb);
464 state = fhci_ioports_check_bus_state(fhci);
466 /* low-speed device was connected to the USB port */
468 ret = qe_usb_clock_set(fhci->lowspeed_clk, USB_CLOCK >> 3);
470 fhci_warn(fhci, "Low-Speed device is not supported, "
475 usb->port_status = FHCI_PORT_LOW;
476 setbits8(&usb->fhci->regs->usb_mod, USB_MODE_LSS);
477 usb->vroot_hub->port.wPortStatus |=
478 (USB_PORT_STAT_LOW_SPEED |
479 USB_PORT_STAT_CONNECTION);
480 usb->vroot_hub->port.wPortChange |=
481 USB_PORT_STAT_C_CONNECTION;
482 usb->max_bytes_per_frame =
483 (MAX_BYTES_PER_FRAME >> 3) - 7;
484 fhci_port_enable(usb);
485 } else if (state == 2) {
486 ret = qe_usb_clock_set(fhci->fullspeed_clk, USB_CLOCK);
488 fhci_warn(fhci, "Full-Speed device is not supported, "
493 usb->port_status = FHCI_PORT_FULL;
494 clrbits8(&usb->fhci->regs->usb_mod, USB_MODE_LSS);
495 usb->vroot_hub->port.wPortStatus &=
496 ~USB_PORT_STAT_LOW_SPEED;
497 usb->vroot_hub->port.wPortStatus |=
498 USB_PORT_STAT_CONNECTION;
499 usb->vroot_hub->port.wPortChange |=
500 USB_PORT_STAT_C_CONNECTION;
501 usb->max_bytes_per_frame = (MAX_BYTES_PER_FRAME - 15);
502 fhci_port_enable(usb);
505 fhci_usb_enable_interrupt(usb);
506 fhci_dbg(fhci, "<- %s\n", __func__);
509 irqreturn_t fhci_frame_limit_timer_irq(int irq, void *_hcd)
511 struct usb_hcd *hcd = _hcd;
512 struct fhci_hcd *fhci = hcd_to_fhci(hcd);
513 struct fhci_usb *usb = fhci->usb_lld;
515 spin_lock(&fhci->lock);
517 gtm_set_exact_timer16(fhci->timer, 1000, false);
519 if (usb->actual_frame->frame_status == FRAME_IS_TRANSMITTED) {
520 usb->actual_frame->frame_status = FRAME_TIMER_END_TRANSMISSION;
521 fhci_push_dummy_bd(usb->ep0);
524 fhci_schedule_transactions(usb);
526 spin_unlock(&fhci->lock);
531 /* Cancel transmission on the USB endpoint */
532 static void abort_transmission(struct fhci_usb *usb)
534 fhci_dbg(usb->fhci, "-> %s\n", __func__);
535 /* issue stop Tx command */
536 qe_issue_cmd(QE_USB_STOP_TX, QE_CR_SUBBLOCK_USB, EP_ZERO, 0);
538 out_8(&usb->fhci->regs->usb_comm, USB_CMD_FLUSH_FIFO | EP_ZERO);
542 /* issue restart Tx command */
543 qe_issue_cmd(QE_USB_RESTART_TX, QE_CR_SUBBLOCK_USB, EP_ZERO, 0);
544 fhci_dbg(usb->fhci, "<- %s\n", __func__);
547 irqreturn_t fhci_irq(struct usb_hcd *hcd)
549 struct fhci_hcd *fhci = hcd_to_fhci(hcd);
550 struct fhci_usb *usb;
554 spin_lock_irqsave(&fhci->lock, flags);
558 usb_er |= in_be16(&usb->fhci->regs->usb_event) &
559 in_be16(&usb->fhci->regs->usb_mask);
561 /* clear event bits for next time */
562 out_be16(&usb->fhci->regs->usb_event, usb_er);
564 fhci_dbg_isr(fhci, usb_er);
566 if (usb_er & USB_E_RESET_MASK) {
567 if ((usb->port_status == FHCI_PORT_FULL) ||
568 (usb->port_status == FHCI_PORT_LOW)) {
569 fhci_device_disconnected_interrupt(fhci);
570 usb_er &= ~USB_E_IDLE_MASK;
571 } else if (usb->port_status == FHCI_PORT_WAITING) {
572 usb->port_status = FHCI_PORT_DISCONNECTING;
574 /* Turn on IDLE since we want to disconnect */
575 usb->saved_msk |= USB_E_IDLE_MASK;
576 out_be16(&usb->fhci->regs->usb_event,
578 } else if (usb->port_status == FHCI_PORT_DISABLED) {
579 if (fhci_ioports_check_bus_state(fhci) == 1 &&
580 usb->port_status != FHCI_PORT_LOW &&
581 usb->port_status != FHCI_PORT_FULL)
582 fhci_device_connected_interrupt(fhci);
584 usb_er &= ~USB_E_RESET_MASK;
587 if (usb_er & USB_E_MSF_MASK) {
588 abort_transmission(fhci->usb_lld);
589 usb_er &= ~USB_E_MSF_MASK;
592 if (usb_er & (USB_E_SOF_MASK | USB_E_SFT_MASK)) {
594 usb_er &= ~(USB_E_SOF_MASK | USB_E_SFT_MASK);
597 if (usb_er & USB_E_TXB_MASK) {
598 fhci_tx_conf_interrupt(fhci->usb_lld);
599 usb_er &= ~USB_E_TXB_MASK;
602 if (usb_er & USB_E_TXE1_MASK) {
603 fhci_tx_conf_interrupt(fhci->usb_lld);
604 usb_er &= ~USB_E_TXE1_MASK;
607 if (usb_er & USB_E_IDLE_MASK) {
608 if (usb->port_status == FHCI_PORT_DISABLED &&
609 usb->port_status != FHCI_PORT_LOW &&
610 usb->port_status != FHCI_PORT_FULL) {
611 usb_er &= ~USB_E_RESET_MASK;
612 fhci_device_connected_interrupt(fhci);
613 } else if (usb->port_status ==
614 FHCI_PORT_DISCONNECTING) {
615 /* XXX usb->port_status = FHCI_PORT_WAITING; */
617 usb->saved_msk &= ~USB_E_IDLE_MASK;
618 out_be16(&usb->fhci->regs->usb_mask,
621 fhci_dbg_isr(fhci, -1);
624 usb_er &= ~USB_E_IDLE_MASK;
627 spin_unlock_irqrestore(&fhci->lock, flags);
634 * Process normal completions(error or sucess) and clean the schedule.
636 * This is the main path for handing urbs back to drivers. The only other patth
637 * is process_del_list(),which unlinks URBs by scanning EDs,instead of scanning
638 * the (re-reversed) done list as this does.
640 static void process_done_list(unsigned long data)
645 struct urb_priv *urb_priv;
646 struct fhci_hcd *fhci = (struct fhci_hcd *)data;
648 disable_irq(fhci->timer->irq);
649 disable_irq(fhci_to_hcd(fhci)->irq);
650 spin_lock(&fhci->lock);
652 td = fhci_remove_td_from_done_list(fhci->hc_list);
655 urb_priv = urb->hcpriv;
658 /* update URB's length and status from TD */
659 fhci_done_td(urb, td);
663 * if all this urb's TDs are done, call complete()
664 * Interrupt transfers are the onley special case:
665 * they are reissued,until "deleted" by usb_unlink_urb
666 * (real work done in a SOF intr, by process_del_list)
668 if (urb_priv->tds_cnt == urb_priv->num_of_tds) {
669 fhci_urb_complete_free(fhci, urb);
670 } else if (urb_priv->state == URB_DEL &&
671 ed->state == FHCI_ED_SKIP) {
672 fhci_del_ed_list(fhci, ed);
673 ed->state = FHCI_ED_OPER;
674 } else if (ed->state == FHCI_ED_HALTED) {
675 urb_priv->state = URB_DEL;
676 ed->state = FHCI_ED_URB_DEL;
677 fhci_del_ed_list(fhci, ed);
678 ed->state = FHCI_ED_OPER;
681 td = fhci_remove_td_from_done_list(fhci->hc_list);
684 spin_unlock(&fhci->lock);
685 enable_irq(fhci->timer->irq);
686 enable_irq(fhci_to_hcd(fhci)->irq);
689 DECLARE_TASKLET(fhci_tasklet, process_done_list, 0);
691 /* transfer complted callback */
692 u32 fhci_transfer_confirm_callback(struct fhci_hcd *fhci)
694 if (!fhci->process_done_task->state)
695 tasklet_schedule(fhci->process_done_task);
700 * adds urb to the endpoint descriptor list
702 * fhci data structure for the Low level host controller
703 * ep USB Host endpoint data structure
704 * urb USB request block data structure
706 void fhci_queue_urb(struct fhci_hcd *fhci, struct urb *urb)
708 struct ed *ed = urb->ep->hcpriv;
709 struct urb_priv *urb_priv = urb->hcpriv;
710 u32 data_len = urb->transfer_buffer_length;
718 ed = fhci_get_empty_ed(fhci);
719 ed->dev_addr = usb_pipedevice(urb->pipe);
720 ed->ep_addr = usb_pipeendpoint(urb->pipe);
721 switch (usb_pipetype(urb->pipe)) {
723 ed->mode = FHCI_TF_CTRL;
726 ed->mode = FHCI_TF_BULK;
729 ed->mode = FHCI_TF_INTR;
731 case PIPE_ISOCHRONOUS:
732 ed->mode = FHCI_TF_ISO;
737 ed->speed = (urb->dev->speed == USB_SPEED_LOW) ?
738 FHCI_LOW_SPEED : FHCI_FULL_SPEED;
739 ed->max_pkt_size = usb_maxpacket(urb->dev,
740 urb->pipe, usb_pipeout(urb->pipe));
741 urb->ep->hcpriv = ed;
742 fhci_dbg(fhci, "new ep speed=%d max_pkt_size=%d\n",
743 ed->speed, ed->max_pkt_size);
746 /* for ISO transfer calculate start frame index */
747 if (ed->mode == FHCI_TF_ISO && urb->transfer_flags & URB_ISO_ASAP)
748 urb->start_frame = ed->td_head ? ed->last_iso + 1 :
752 * OHCI handles the DATA toggle itself,we just use the USB
755 if (usb_gettoggle(urb->dev, usb_pipeendpoint(urb->pipe),
756 usb_pipeout(urb->pipe)))
757 toggle = USB_TD_TOGGLE_CARRY;
759 toggle = USB_TD_TOGGLE_DATA0;
760 usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe),
761 usb_pipeout(urb->pipe), 1);
764 urb_priv->tds_cnt = 0;
767 data = urb->transfer_buffer;
773 if (urb->transfer_flags & URB_ZERO_PACKET &&
774 urb->transfer_buffer_length > 0 &&
775 ((urb->transfer_buffer_length %
776 usb_maxpacket(urb->dev, urb->pipe,
777 usb_pipeout(urb->pipe))) == 0))
778 urb_state = US_BULK0;
779 while (data_len > 4096) {
780 td = fhci_td_fill(fhci, urb, urb_priv, ed, cnt,
781 usb_pipeout(urb->pipe) ? FHCI_TA_OUT :
783 cnt ? USB_TD_TOGGLE_CARRY :
785 data, 4096, 0, 0, true);
791 td = fhci_td_fill(fhci, urb, urb_priv, ed, cnt,
792 usb_pipeout(urb->pipe) ? FHCI_TA_OUT : FHCI_TA_IN,
793 cnt ? USB_TD_TOGGLE_CARRY : toggle,
794 data, data_len, 0, 0, true);
797 if (urb->transfer_flags & URB_ZERO_PACKET &&
798 cnt < urb_priv->num_of_tds) {
799 td = fhci_td_fill(fhci, urb, urb_priv, ed, cnt,
800 usb_pipeout(urb->pipe) ? FHCI_TA_OUT :
802 USB_TD_TOGGLE_CARRY, NULL, 0, 0, 0, true);
807 urb->start_frame = get_frame_num(fhci) + 1;
808 td = fhci_td_fill(fhci, urb, urb_priv, ed, cnt++,
809 usb_pipeout(urb->pipe) ? FHCI_TA_OUT : FHCI_TA_IN,
810 USB_TD_TOGGLE_DATA0, data, data_len,
811 urb->interval, urb->start_frame, true);
814 ed->dev_addr = usb_pipedevice(urb->pipe);
815 ed->max_pkt_size = usb_maxpacket(urb->dev, urb->pipe,
816 usb_pipeout(urb->pipe));
817 td = fhci_td_fill(fhci, urb, urb_priv, ed, cnt++, FHCI_TA_SETUP,
818 USB_TD_TOGGLE_DATA0, urb->setup_packet, 8, 0, 0, true);
821 td = fhci_td_fill(fhci, urb, urb_priv, ed, cnt++,
822 usb_pipeout(urb->pipe) ? FHCI_TA_OUT :
824 USB_TD_TOGGLE_DATA1, data, data_len, 0, 0,
827 td = fhci_td_fill(fhci, urb, urb_priv, ed, cnt++,
828 usb_pipeout(urb->pipe) ? FHCI_TA_IN : FHCI_TA_OUT,
829 USB_TD_TOGGLE_DATA1, data, 0, 0, 0, true);
830 urb_state = US_CTRL_SETUP;
833 for (cnt = 0; cnt < urb->number_of_packets; cnt++) {
834 u16 frame = urb->start_frame;
837 * FIXME scheduling should handle frame counter
838 * roll-around ... exotic case (and OHCI has
839 * a 2^16 iso range, vs other HCs max of 2^10)
841 frame += cnt * urb->interval;
843 td = fhci_td_fill(fhci, urb, urb_priv, ed, cnt,
844 usb_pipeout(urb->pipe) ? FHCI_TA_OUT :
847 data + urb->iso_frame_desc[cnt].offset,
848 urb->iso_frame_desc[cnt].length,
849 urb->interval, frame, true);
857 * set the state of URB
858 * control pipe:3 states -- setup,data,status
859 * interrupt and bulk pipe:1 state -- data
862 urb->pipe |= urb_state & 0x1f;
864 urb_priv->state = URB_INPROGRESS;
867 ed->state = FHCI_ED_OPER;
870 list_add(&ed->node, &fhci->hc_list->ctrl_list);
873 list_add(&ed->node, &fhci->hc_list->bulk_list);
876 list_add(&ed->node, &fhci->hc_list->intr_list);
879 list_add(&ed->node, &fhci->hc_list->iso_list);
886 fhci_add_tds_to_ed(ed, urb_priv->tds, urb_priv->num_of_tds);