Lines Matching defs:qh
73 * dwc2_qh_init() - Initializes a QH structure
76 * @qh: The QH to init
78 * the QH
81 static void dwc2_qh_init(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh,
88 /* Initialize QH */
89 qh->hsotg = hsotg;
90 /* XXX timer_setup(&qh->wait_timer, dwc2_wait_timer_fn, 0); */
91 callout_init(&qh->wait_timer, 0);
92 callout_setfunc(&qh->wait_timer, dwc2_wait_timer_fn, qh);
93 qh->ep_type = dwc2_hcd_get_pipe_type(&urb->pipe_info);
94 qh->ep_is_in = dwc2_hcd_is_pipe_in(&urb->pipe_info) ? 1 : 0;
96 qh->data_toggle = DWC2_HC_PID_DATA0;
97 qh->maxp = dwc2_hcd_get_mps(&urb->pipe_info);
98 INIT_LIST_HEAD(&qh->qtd_list);
99 INIT_LIST_HEAD(&qh->qh_list_entry);
105 qh->nak_frame = 0xffff;
110 "QH init: EP %d: TT found at hub addr %d, for port %d\n",
113 qh->do_split = 1;
116 if (qh->ep_type == USB_ENDPOINT_XFER_INT ||
117 qh->ep_type == USB_ENDPOINT_XFER_ISOC) {
123 dwc2_hb_mult(qh->maxp) * dwc2_max_packet(qh->maxp);
125 qh->usecs = dwc2_calc_bus_time(hsotg, qh->do_split ?
126 USB_SPEED_HIGH : dev_speed, qh->ep_is_in,
127 qh->ep_type == USB_ENDPOINT_XFER_ISOC,
133 qh->sched_frame = dwc2_frame_num_inc(hsotg->frame_number,
135 qh->interval = urb->interval;
138 if (qh->ep_type == USB_ENDPOINT_XFER_INT)
139 qh->interval = 8;
146 qh->interval *= 8;
147 qh->sched_frame |= 0x7;
148 qh->start_split_frame = qh->sched_frame;
150 dev_dbg(hsotg->dev, "interval=%d\n", qh->interval);
153 dev_vdbg(hsotg->dev, "DWC OTG HCD QH Initialized\n");
154 dev_vdbg(hsotg->dev, "DWC OTG HCD QH - qh = %p\n", qh);
155 dev_vdbg(hsotg->dev, "DWC OTG HCD QH - Device Address = %d\n",
157 dev_vdbg(hsotg->dev, "DWC OTG HCD QH - Endpoint %d, %s\n",
161 qh->dev_speed = dev_speed;
179 dev_vdbg(hsotg->dev, "DWC OTG HCD QH - Speed = %s\n", speed);
181 switch (qh->ep_type) {
199 dev_vdbg(hsotg->dev, "DWC OTG HCD QH - Type = %s\n", type);
202 if (qh->ep_type == USB_ENDPOINT_XFER_INT) {
203 dev_vdbg(hsotg->dev, "DWC OTG HCD QH - usecs = %d\n",
204 qh->usecs);
205 dev_vdbg(hsotg->dev, "DWC OTG HCD QH - interval = %d\n",
206 qh->interval);
211 * dwc2_hcd_qh_create() - Allocates and initializes a QH
215 * to initialize the QH
218 * Return: Pointer to the newly allocated QH, or NULL on error
225 struct dwc2_qh *qh;
231 qh = pool_cache_get(sc->sc_qhpool, PR_NOWAIT);
232 if (!qh)
235 memset(qh, 0, sizeof(*qh));
236 dwc2_qh_init(hsotg, qh, urb);
239 dwc2_hcd_qh_init_ddma(hsotg, qh, mem_flags) < 0) {
240 dwc2_hcd_qh_free(hsotg, qh);
244 return qh;
248 * dwc2_hcd_qh_free() - Frees the QH
251 * @qh: The QH to free
253 * QH should already be removed from the list. QTD list should already be empty
258 void dwc2_hcd_qh_free(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh)
269 /* XXX del_timer_sync(&qh->wait_timer); */
270 callout_destroy(&qh->wait_timer); /* XXX need to callout_halt() first? */
272 if (qh->desc_list) {
273 dwc2_hcd_qh_free_ddma(hsotg, qh);
274 } else if (qh->dw_align_buf) {
275 usb_freemem(&qh->dw_align_buf_usbdma);
276 qh->dw_align_buf_dma = (dma_addr_t)0;
279 pool_cache_put(sc->sc_qhpool, qh);
318 * for the specified QH in the periodic schedule
321 * @qh: QH containing periodic bandwidth required
329 struct dwc2_qh *qh)
336 if (qh->dev_speed == USB_SPEED_HIGH || qh->do_split) {
341 max_claimed_usecs = 100 - qh->usecs;
347 max_claimed_usecs = 900 - qh->usecs;
353 __func__, hsotg->periodic_usecs, qh->usecs);
363 * keep each qh use in qh->frame_usecs
364 * when surrendering the qh then donate the time back
378 static int dwc2_find_single_uframe(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh)
380 unsigned short utime = qh->usecs;
387 qh->frame_usecs[i] += utime;
397 static int dwc2_find_multi_uframe(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh)
399 unsigned short utime = qh->usecs;
430 qh->frame_usecs[k] +=
436 qh->frame_usecs[k] +=
453 static int dwc2_find_uframe(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh)
457 if (qh->dev_speed == USB_SPEED_HIGH) {
459 ret = dwc2_find_single_uframe(hsotg, qh);
465 ret = dwc2_find_multi_uframe(hsotg, qh);
476 * @qh: QH for a periodic endpoint
481 struct dwc2_qh *qh)
487 max_xfer_size = dwc2_max_packet(qh->maxp) * dwc2_hb_mult(qh->maxp);
505 * @qh: QH for the periodic transfer. The QH should already contain the
510 static int dwc2_schedule_periodic(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh)
517 status = dwc2_find_uframe(hsotg, qh);
525 qh->sched_frame &= ~0x7;
526 qh->sched_frame |= (frame & 7);
540 status = dwc2_check_periodic_bandwidth(hsotg, qh);
550 status = dwc2_check_max_xfer_size(hsotg, qh);
560 list_add_tail(&qh->qh_list_entry, &hsotg->periodic_sched_ready);
563 list_add_tail(&qh->qh_list_entry,
571 hsotg->periodic_usecs += qh->usecs;
581 * @qh: QH for the periodic transfer
584 struct dwc2_qh *qh)
588 list_del_init(&qh->qh_list_entry);
591 qh->usecs;
595 hsotg->frame_usecs[i] += qh->frame_usecs[i];
596 qh->frame_usecs[i] = 0;
621 * qh back to the "inactive" list, then queues transactions.
623 * @t: Pointer to wait_timer in a qh.
627 struct dwc2_qh *qh = arg;
628 struct dwc2_hsotg *hsotg = qh->hsotg;
637 if (!qh->wait_timer_cancel) {
640 qh->want_wait = false;
642 list_move(&qh->qh_list_entry,
654 * dwc2_hcd_qh_add() - Adds a QH to either the non periodic or periodic
655 * schedule if it is not already in the schedule. If the QH is already in
659 * @qh: The QH to add
663 int dwc2_hcd_qh_add(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh)
668 if (dbg_qh(qh))
671 if (!list_empty(&qh->qh_list_entry))
672 /* QH already in a schedule */
675 if (!dwc2_frame_num_le(qh->sched_frame, hsotg->frame_number) &&
679 qh->sched_frame = dwc2_frame_num_inc(hsotg->frame_number,
683 /* Add the new QH to the appropriate schedule */
684 if (dwc2_qh_is_non_per(qh)) {
685 if (qh->want_wait) {
686 list_add_tail(&qh->qh_list_entry,
688 qh->wait_timer_cancel = false;
689 /* XXX mod_timer(&qh->wait_timer,
691 callout_schedule(&qh->wait_timer,
694 list_add_tail(&qh->qh_list_entry,
700 status = dwc2_schedule_periodic(hsotg, qh);
714 * dwc2_hcd_qh_unlink() - Removes a QH from either the non-periodic or periodic
718 * @qh: QH to remove from schedule
720 void dwc2_hcd_qh_unlink(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh)
727 qh->wait_timer_cancel = true;
729 if (list_empty(&qh->qh_list_entry))
730 /* QH is not in a schedule */
733 if (dwc2_qh_is_non_per(qh)) {
734 if (hsotg->non_periodic_qh_ptr == &qh->qh_list_entry)
737 list_del_init(&qh->qh_list_entry);
741 dwc2_deschedule_periodic(hsotg, qh);
754 struct dwc2_qh *qh, u16 frame_number,
760 qh->sched_frame = frame_number;
761 incr = dwc2_frame_num_inc(qh->start_split_frame, 1);
769 if (qh->ep_type != USB_ENDPOINT_XFER_ISOC ||
770 qh->ep_is_in != 0) {
771 qh->sched_frame =
772 dwc2_frame_num_inc(qh->sched_frame, 1);
776 qh->sched_frame = dwc2_frame_num_inc(qh->start_split_frame,
777 qh->interval);
778 if (dwc2_frame_num_le(qh->sched_frame, frame_number))
779 qh->sched_frame = frame_number;
780 qh->sched_frame |= 0x7;
781 qh->start_split_frame = qh->sched_frame;
786 * Deactivates a QH. For non-periodic QHs, removes the QH from the active
787 * non-periodic schedule. The QH is added to the inactive non-periodic
788 * schedule if any QTDs are still attached to the QH.
790 * For periodic QHs, the QH is removed from the periodic queued schedule. If
791 * there are any QTDs still attached to the QH, the QH is added to either the
793 * scheduled frame is calculated. The QH is placed in the ready schedule if
795 * inactive schedule. If there are no QTDs attached to the QH, the QH is
798 void dwc2_hcd_qh_deactivate(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh,
803 if (dbg_qh(qh))
806 if (dwc2_qh_is_non_per(qh)) {
807 dwc2_hcd_qh_unlink(hsotg, qh);
808 if (!list_empty(&qh->qtd_list))
810 dwc2_hcd_qh_add(hsotg, qh);
816 if (qh->do_split) {
817 dwc2_sched_periodic_split(hsotg, qh, frame_number,
820 qh->sched_frame = dwc2_frame_num_inc(qh->sched_frame,
821 qh->interval);
822 if (dwc2_frame_num_le(qh->sched_frame, frame_number))
823 qh->sched_frame = frame_number;
826 if (list_empty(&qh->qtd_list)) {
827 dwc2_hcd_qh_unlink(hsotg, qh);
835 dwc2_frame_num_le(qh->sched_frame, frame_number)) ||
837 qh->sched_frame == frame_number))
838 list_move(&qh->qh_list_entry, &hsotg->periodic_sched_ready);
840 list_move(&qh->qh_list_entry, &hsotg->periodic_sched_inactive);
874 * dwc2_hcd_qtd_add() - Adds a QTD to the QTD-list of a QH
879 * @qh: Queue head to add qtd to
883 * If the QH to which the QTD is added is not currently scheduled, it is placed
887 struct dwc2_qh *qh)
893 if (unlikely(!qh)) {
894 dev_err(hsotg->dev, "%s: Invalid QH\n", __func__);
899 retval = dwc2_hcd_qh_add(hsotg, qh);
903 qtd->qh = qh;
904 list_add_tail(&qtd->qtd_list_entry, &qh->qtd_list);
913 struct dwc2_qh *qh)