Lines Matching +full:full +full:- +full:frame

1 // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
3 * hcd_queue.c - DesignWare HS OTG Controller host queuing routines
5 * Copyright (C) 2004-2013 Synopsys, Inc.
17 #include <linux/dma-mapping.h>
36 * dwc2_periodic_channel_available() - Checks that a channel is available for a
48 * non-periodic transactions in dwc2_periodic_channel_available()
53 num_channels = hsotg->params.host_channels; in dwc2_periodic_channel_available()
54 if ((hsotg->periodic_channels + hsotg->non_periodic_channels < in dwc2_periodic_channel_available()
55 num_channels) && (hsotg->periodic_channels < num_channels - 1)) { in dwc2_periodic_channel_available()
58 dev_dbg(hsotg->dev, in dwc2_periodic_channel_available()
59 "%s: Total channels: %d, Periodic: %d, Non-periodic: %d\n", in dwc2_periodic_channel_available()
61 hsotg->periodic_channels, hsotg->non_periodic_channels); in dwc2_periodic_channel_available()
62 status = -ENOSPC; in dwc2_periodic_channel_available()
69 * dwc2_check_periodic_bandwidth() - Checks that there is sufficient bandwidth
78 * periodic schedule may occur in the same (micro)frame
88 if (qh->dev_speed == USB_SPEED_HIGH || qh->do_split) { in dwc2_check_periodic_bandwidth()
93 max_claimed_usecs = 100 - qh->host_us; in dwc2_check_periodic_bandwidth()
96 * Full speed mode in dwc2_check_periodic_bandwidth()
99 max_claimed_usecs = 900 - qh->host_us; in dwc2_check_periodic_bandwidth()
102 if (hsotg->periodic_usecs > max_claimed_usecs) { in dwc2_check_periodic_bandwidth()
103 dev_err(hsotg->dev, in dwc2_check_periodic_bandwidth()
105 __func__, hsotg->periodic_usecs, qh->host_us); in dwc2_check_periodic_bandwidth()
106 status = -ENOSPC; in dwc2_check_periodic_bandwidth()
113 * pmap_schedule() - Schedule time in a periodic bitmap (pmap).
135 * want the same resource. The resource is divided into fixed-sized periods
141 * but does mean that we need to handle things specially (and non-ideally) if
146 * - If interval is 1, we need to take up space in each of the 8
148 * - If interval is 2, we need to take up space in half of the
150 * - If interval is 3, we actually need to fall back to interval 1.
154 * 0, 3, and 6. Since we could be in any frame we need to reserve
158 * - If interval is 4, easy.
159 * - If interval is 5, we again need interval 1. The schedule will be
161 * - If interval is 6, we need interval 2. 0, 6, 4, 2.
162 * - If interval is 7, we need interval 1.
163 * - If interval is 8, we need interval 8.
168 * Note that at the moment this function tends to front-pack the schedule.
169 * In some cases that's really non-ideal (it's hard to schedule things that
200 * Returns either -ENOSPC or a >= 0 start bit which should be passed to the
201 * unschedule routine. The map bitmap will be updated on a non-error result.
213 return -ENOSPC; in pmap_schedule()
223 return -ENOSPC; in pmap_schedule()
280 start = ith_start - interval_bits * i; in pmap_schedule()
290 return -ENOSPC; in pmap_schedule()
302 * pmap_unschedule() - Undo work done by pmap_schedule()
333 * dwc2_get_ls_map() - Get the map used for the given qh
339 * running the host straight in low speed / full speed mode it appears as if
341 * add logic here to get a map out of "hsotg" if !qh->do_split.
351 if (WARN_ON(!qh->dwc_tt)) in dwc2_get_ls_map()
355 map = qh->dwc_tt->periodic_bitmaps; in dwc2_get_ls_map()
356 if (qh->dwc_tt->usb_tt->multi) in dwc2_get_ls_map()
357 map += DWC2_ELEMENTS_PER_LS_BITMAP * (qh->ttport - 1); in dwc2_get_ls_map()
364 * pmap_print() - Print the given periodic map
399 start = i - period_start; in pmap_print()
415 seq_buf_printf(&buf, "%d %s -%3d %s", start, in pmap_print()
416 units, start + count - 1, units); in pmap_print()
431 * dwc2_qh_print() - Helper function for dwc2_qh_schedule_print()
440 dwc2_sch_dbg(print_data->hsotg, "QH=%p ...%s\n", print_data->qh, str); in dwc2_qh_print()
444 * dwc2_qh_schedule_print() - Print the periodic schedule
461 if (qh->schedule_low_speed) { in dwc2_qh_schedule_print()
465 qh, qh->device_us, in dwc2_qh_schedule_print()
466 DWC2_ROUND_US_TO_SLICE(qh->device_us), in dwc2_qh_schedule_print()
467 DWC2_US_PER_SLICE * qh->ls_start_schedule_slice); in dwc2_qh_schedule_print()
471 "QH=%p Whole low/full speed map %p now:\n", in dwc2_qh_schedule_print()
474 DWC2_LS_SCHEDULE_FRAMES, "Frame ", "slices", in dwc2_qh_schedule_print()
479 for (i = 0; i < qh->num_hs_transfers; i++) { in dwc2_qh_schedule_print()
480 struct dwc2_hs_transfer_time *trans_time = qh->hs_transfers + i; in dwc2_qh_schedule_print()
481 int uframe = trans_time->start_schedule_us / in dwc2_qh_schedule_print()
483 int rel_us = trans_time->start_schedule_us % in dwc2_qh_schedule_print()
488 qh, i, trans_time->duration_us, uframe, rel_us); in dwc2_qh_schedule_print()
490 if (qh->num_hs_transfers) { in dwc2_qh_schedule_print()
492 pmap_print(hsotg->hs_periodic_bitmap, in dwc2_qh_schedule_print()
504 * dwc2_ls_pmap_schedule() - Schedule a low speed QH
521 int slices = DIV_ROUND_UP(qh->device_us, DWC2_US_PER_SLICE); in dwc2_ls_pmap_schedule()
526 return -EINVAL; in dwc2_ls_pmap_schedule()
542 qh->device_interval, search_slice, false); in dwc2_ls_pmap_schedule()
547 qh->ls_start_schedule_slice = slice; in dwc2_ls_pmap_schedule()
552 * dwc2_ls_pmap_unschedule() - Undo work done by dwc2_ls_pmap_schedule()
560 int slices = DIV_ROUND_UP(qh->device_us, DWC2_US_PER_SLICE); in dwc2_ls_pmap_unschedule()
568 DWC2_LS_SCHEDULE_FRAMES, slices, qh->device_interval, in dwc2_ls_pmap_unschedule()
569 qh->ls_start_schedule_slice); in dwc2_ls_pmap_unschedule()
573 * dwc2_hs_pmap_schedule - Schedule in the main high speed schedule
577 * We'll start looking in qh->hs_transfers[index].start_schedule_us. We'll
587 * @index: The index into qh->hs_transfers that we're working with.
595 struct dwc2_hs_transfer_time *trans_time = qh->hs_transfers + index; in dwc2_hs_pmap_schedule()
598 us = pmap_schedule(hsotg->hs_periodic_bitmap, in dwc2_hs_pmap_schedule()
600 DWC2_HS_SCHEDULE_UFRAMES, trans_time->duration_us, in dwc2_hs_pmap_schedule()
601 qh->host_interval, trans_time->start_schedule_us, in dwc2_hs_pmap_schedule()
607 trans_time->start_schedule_us = us; in dwc2_hs_pmap_schedule()
612 * dwc2_hs_pmap_unschedule() - Undo work done by dwc2_hs_pmap_schedule()
621 struct dwc2_hs_transfer_time *trans_time = qh->hs_transfers + index; in dwc2_hs_pmap_unschedule()
623 pmap_unschedule(hsotg->hs_periodic_bitmap, in dwc2_hs_pmap_unschedule()
625 DWC2_HS_SCHEDULE_UFRAMES, trans_time->duration_us, in dwc2_hs_pmap_unschedule()
626 qh->host_interval, trans_time->start_schedule_us); in dwc2_hs_pmap_unschedule()
630 * dwc2_uframe_schedule_split - Schedule a QH for a periodic split xfer.
637 * device is in low or full speed mode (and behind a hub).
645 int bytecount = qh->maxp_mult * qh->maxp; in dwc2_uframe_schedule_split()
654 host_interval_in_sched = gcd(qh->host_interval, in dwc2_uframe_schedule_split()
664 * Note that this will tend to front-load the high speed schedule. in dwc2_uframe_schedule_split()
682 if (qh->schedule_low_speed) { in dwc2_uframe_schedule_split()
699 * This will give us a number 0 - 7 if in dwc2_uframe_schedule_split()
700 * DWC2_LS_SCHEDULE_FRAMES == 1, or 0 - 15 if == 2, or ... in dwc2_uframe_schedule_split()
702 start_s_uframe = qh->ls_start_schedule_slice / in dwc2_uframe_schedule_split()
705 /* Get a number that's always 0 - 7 */ in dwc2_uframe_schedule_split()
711 * Move on to the next full frame (assuming there is one). in dwc2_uframe_schedule_split()
717 if (qh->schedule_low_speed) in dwc2_uframe_schedule_split()
720 (qh->ls_start_schedule_slice / in dwc2_uframe_schedule_split()
728 * - start split (frame -1) in dwc2_uframe_schedule_split()
729 * - complete split w/ data (frame +1) in dwc2_uframe_schedule_split()
730 * - complete split w/ data (frame +2) in dwc2_uframe_schedule_split()
731 * - ... in dwc2_uframe_schedule_split()
732 * - complete split w/ data (frame +num_data_packets) in dwc2_uframe_schedule_split()
733 * - complete split w/ data (frame +num_data_packets+1) in dwc2_uframe_schedule_split()
734 * - complete split w/ data (frame +num_data_packets+2, max 8) in dwc2_uframe_schedule_split()
735 * ...though if frame was "0" then max is 7... in dwc2_uframe_schedule_split()
738 * - start split w/ data (frame -1) in dwc2_uframe_schedule_split()
739 * - start split w/ data (frame +0) in dwc2_uframe_schedule_split()
740 * - ... in dwc2_uframe_schedule_split()
741 * - start split w/ data (frame +num_data_packets-2) in dwc2_uframe_schedule_split()
744 * - start split (frame -1) in dwc2_uframe_schedule_split()
745 * - complete split w/ data (frame +1) in dwc2_uframe_schedule_split()
746 * - complete split w/ data (frame +2) in dwc2_uframe_schedule_split()
747 * - complete split w/ data (frame +3, max 8) in dwc2_uframe_schedule_split()
750 * - start split w/ data (frame -1) in dwc2_uframe_schedule_split()
751 * - complete split (frame +1) in dwc2_uframe_schedule_split()
752 * - complete split (frame +2) in dwc2_uframe_schedule_split()
753 * - complete split (frame +3, max 8) in dwc2_uframe_schedule_split()
758 host_interval_in_sched - 1) % in dwc2_uframe_schedule_split()
760 if (qh->ep_type == USB_ENDPOINT_XFER_ISOC && !qh->ep_is_in) in dwc2_uframe_schedule_split()
766 first_data_bytes = 188 - in dwc2_uframe_schedule_split()
767 DIV_ROUND_UP(188 * (qh->ls_start_schedule_slice % in dwc2_uframe_schedule_split()
772 other_data_bytes = bytecount - first_data_bytes; in dwc2_uframe_schedule_split()
778 * - INT transfers never get split in two. in dwc2_uframe_schedule_split()
779 * - ISOC transfers can always transfer 188 bytes the first in dwc2_uframe_schedule_split()
789 if (!qh->ep_is_in && in dwc2_uframe_schedule_split()
794 if (qh->schedule_low_speed) in dwc2_uframe_schedule_split()
802 qh->num_hs_transfers = 1 + DIV_ROUND_UP(other_data_bytes, 188); in dwc2_uframe_schedule_split()
809 if (qh->ep_type == USB_ENDPOINT_XFER_INT) { in dwc2_uframe_schedule_split()
811 qh->num_hs_transfers += 2; in dwc2_uframe_schedule_split()
813 qh->num_hs_transfers += 3; in dwc2_uframe_schedule_split()
815 if (qh->ep_is_in) { in dwc2_uframe_schedule_split()
818 * Allocate full data bytes for all data. in dwc2_uframe_schedule_split()
834 if (qh->ep_is_in) { in dwc2_uframe_schedule_split()
838 qh->num_hs_transfers++; in dwc2_uframe_schedule_split()
841 last = rel_uframe + qh->num_hs_transfers + 1; in dwc2_uframe_schedule_split()
845 qh->num_hs_transfers += 2; in dwc2_uframe_schedule_split()
847 qh->num_hs_transfers += 1; in dwc2_uframe_schedule_split()
851 qh->num_hs_transfers--; in dwc2_uframe_schedule_split()
867 qh->hs_transfers[0].duration_us = HS_USECS_ISO(first_count); in dwc2_uframe_schedule_split()
868 for (i = 1; i < qh->num_hs_transfers - 1; i++) in dwc2_uframe_schedule_split()
869 qh->hs_transfers[i].duration_us = in dwc2_uframe_schedule_split()
871 if (qh->num_hs_transfers > 1) in dwc2_uframe_schedule_split()
872 qh->hs_transfers[qh->num_hs_transfers - 1].duration_us = in dwc2_uframe_schedule_split()
880 qh->hs_transfers[0].start_schedule_us = in dwc2_uframe_schedule_split()
882 for (i = 1; i < qh->num_hs_transfers; i++) in dwc2_uframe_schedule_split()
883 qh->hs_transfers[i].start_schedule_us = in dwc2_uframe_schedule_split()
884 ((second_s_uframe + i - 1) % in dwc2_uframe_schedule_split()
889 for (i = 0; i < qh->num_hs_transfers; i++) { in dwc2_uframe_schedule_split()
896 if (i == qh->num_hs_transfers) in dwc2_uframe_schedule_split()
899 for (; i >= 0; i--) in dwc2_uframe_schedule_split()
902 if (qh->schedule_low_speed) in dwc2_uframe_schedule_split()
910 return -ENOSPC; in dwc2_uframe_schedule_split()
916 * dwc2_uframe_schedule_hs - Schedule a QH for a periodic high speed xfer.
926 /* In non-split host and device time are the same */ in dwc2_uframe_schedule_hs()
927 WARN_ON(qh->host_us != qh->device_us); in dwc2_uframe_schedule_hs()
928 WARN_ON(qh->host_interval != qh->device_interval); in dwc2_uframe_schedule_hs()
929 WARN_ON(qh->num_hs_transfers != 1); in dwc2_uframe_schedule_hs()
932 qh->hs_transfers[0].start_schedule_us = 0; in dwc2_uframe_schedule_hs()
933 qh->hs_transfers[0].duration_us = qh->host_us; in dwc2_uframe_schedule_hs()
939 * dwc2_uframe_schedule_ls - Schedule a QH for a periodic low/full speed xfer.
949 /* In non-split host and device time are the same */ in dwc2_uframe_schedule_ls()
950 WARN_ON(qh->host_us != qh->device_us); in dwc2_uframe_schedule_ls()
951 WARN_ON(qh->host_interval != qh->device_interval); in dwc2_uframe_schedule_ls()
952 WARN_ON(!qh->schedule_low_speed); in dwc2_uframe_schedule_ls()
959 * dwc2_uframe_schedule - Schedule a QH for a periodic xfer.
961 * Calls one of the 3 sub-function depending on what type of transfer this QH
971 if (qh->dev_speed == USB_SPEED_HIGH) in dwc2_uframe_schedule()
973 else if (!qh->do_split) in dwc2_uframe_schedule()
987 * dwc2_uframe_unschedule - Undoes dwc2_uframe_schedule().
996 for (i = 0; i < qh->num_hs_transfers; i++) in dwc2_uframe_unschedule()
999 if (qh->schedule_low_speed) in dwc2_uframe_unschedule()
1006 * dwc2_pick_first_frame() - Choose 1st frame for qh that's already scheduled
1013 * running. It just picks the next frame that we can fit into without any
1029 * Use the real frame number rather than the cached value as of the in dwc2_pick_first_frame()
1035 * We wouldn't want to start any earlier than the next frame just in in dwc2_pick_first_frame()
1036 * case the frame number ticks as we're doing this calculation. in dwc2_pick_first_frame()
1046 if (!hsotg->params.uframe_sched) { in dwc2_pick_first_frame()
1047 if (qh->do_split) in dwc2_pick_first_frame()
1053 if (qh->dev_speed == USB_SPEED_HIGH || qh->do_split) { in dwc2_pick_first_frame()
1057 * the first frame should be based on when the first scheduled in dwc2_pick_first_frame()
1060 WARN_ON(qh->num_hs_transfers < 1); in dwc2_pick_first_frame()
1062 relative_frame = qh->hs_transfers[0].start_schedule_us / in dwc2_pick_first_frame()
1066 interval = gcd(qh->host_interval, DWC2_HS_SCHEDULE_UFRAMES); in dwc2_pick_first_frame()
1070 * Low or full speed directly on dwc2. Just about the same in dwc2_pick_first_frame()
1076 relative_frame = qh->ls_start_schedule_slice / in dwc2_pick_first_frame()
1078 interval = gcd(qh->host_interval, DWC2_LS_SCHEDULE_FRAMES); in dwc2_pick_first_frame()
1081 /* Scheduler messed up if frame is past interval */ in dwc2_pick_first_frame()
1095 * Actually choose to start at the frame number we've been in dwc2_pick_first_frame()
1102 * We actually need 1 frame before since the next_active_frame is in dwc2_pick_first_frame()
1103 * the frame number we'll be put on the ready list and we won't be on in dwc2_pick_first_frame()
1104 * the bus until 1 frame later. in dwc2_pick_first_frame()
1117 qh->next_active_frame = next_active_frame; in dwc2_pick_first_frame()
1118 qh->start_active_frame = next_active_frame; in dwc2_pick_first_frame()
1121 qh, frame_number, qh->next_active_frame); in dwc2_pick_first_frame()
1125 * dwc2_do_reserve() - Make a periodic reservation
1139 if (hsotg->params.uframe_sched) { in dwc2_do_reserve()
1144 dev_info(hsotg->dev, in dwc2_do_reserve()
1154 dev_dbg(hsotg->dev, in dwc2_do_reserve()
1160 if (!hsotg->params.uframe_sched) in dwc2_do_reserve()
1162 hsotg->periodic_channels++; in dwc2_do_reserve()
1164 /* Update claimed usecs per (micro)frame */ in dwc2_do_reserve()
1165 hsotg->periodic_usecs += qh->host_us; in dwc2_do_reserve()
1173 * dwc2_do_unreserve() - Actually release the periodic reservation
1183 assert_spin_locked(&hsotg->lock); in dwc2_do_unreserve()
1185 WARN_ON(!qh->unreserve_pending); in dwc2_do_unreserve()
1187 /* No more unreserve pending--we're doing it */ in dwc2_do_unreserve()
1188 qh->unreserve_pending = false; in dwc2_do_unreserve()
1190 if (WARN_ON(!list_empty(&qh->qh_list_entry))) in dwc2_do_unreserve()
1191 list_del_init(&qh->qh_list_entry); in dwc2_do_unreserve()
1193 /* Update claimed usecs per (micro)frame */ in dwc2_do_unreserve()
1194 hsotg->periodic_usecs -= qh->host_us; in dwc2_do_unreserve()
1196 if (hsotg->params.uframe_sched) { in dwc2_do_unreserve()
1200 hsotg->periodic_channels--; in dwc2_do_unreserve()
1205 * dwc2_unreserve_timer_fn() - Timer function to release periodic reservation
1219 struct dwc2_hsotg *hsotg = qh->hsotg; in dwc2_unreserve_timer_fn()
1225 * - We started executing but didn't get the lock yet. in dwc2_unreserve_timer_fn()
1226 * - A new reservation came in, but cancel didn't take effect in dwc2_unreserve_timer_fn()
1228 * - The timer has been kicked again. in dwc2_unreserve_timer_fn()
1231 while (!spin_trylock_irqsave(&hsotg->lock, flags)) { in dwc2_unreserve_timer_fn()
1232 if (timer_pending(&qh->unreserve_timer)) in dwc2_unreserve_timer_fn()
1238 * - We started executing but didn't get the lock yet. in dwc2_unreserve_timer_fn()
1239 * - A new reservation came in, but cancel didn't take effect in dwc2_unreserve_timer_fn()
1246 if (qh->unreserve_pending) in dwc2_unreserve_timer_fn()
1249 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_unreserve_timer_fn()
1253 * dwc2_check_max_xfer_size() - Checks that the max transfer size allowed in a
1255 * (micro)frame for a periodic transfer
1269 max_xfer_size = qh->maxp * qh->maxp_mult; in dwc2_check_max_xfer_size()
1270 max_channel_xfer_size = hsotg->params.max_transfer_size; in dwc2_check_max_xfer_size()
1273 dev_err(hsotg->dev, in dwc2_check_max_xfer_size()
1276 status = -ENOSPC; in dwc2_check_max_xfer_size()
1283 * dwc2_schedule_periodic() - Schedules an interrupt or isochronous transfer in
1298 dev_dbg(hsotg->dev, in dwc2_schedule_periodic()
1305 if (del_timer(&qh->unreserve_timer)) in dwc2_schedule_periodic()
1306 WARN_ON(!qh->unreserve_pending); in dwc2_schedule_periodic()
1315 if (!qh->unreserve_pending) { in dwc2_schedule_periodic()
1326 if (dwc2_frame_num_le(qh->next_active_frame, in dwc2_schedule_periodic()
1327 hsotg->frame_number)) in dwc2_schedule_periodic()
1331 qh->unreserve_pending = 0; in dwc2_schedule_periodic()
1333 if (hsotg->params.dma_desc_enable) in dwc2_schedule_periodic()
1335 list_add_tail(&qh->qh_list_entry, &hsotg->periodic_sched_ready); in dwc2_schedule_periodic()
1338 list_add_tail(&qh->qh_list_entry, in dwc2_schedule_periodic()
1339 &hsotg->periodic_sched_inactive); in dwc2_schedule_periodic()
1345 * dwc2_deschedule_periodic() - Removes an interrupt or isochronous transfer
1356 assert_spin_locked(&hsotg->lock); in dwc2_deschedule_periodic()
1360 * - Unreserve worker might be sitting there waiting to grab the lock. in dwc2_deschedule_periodic()
1363 * - Unreserve worker might not be scheduled. in dwc2_deschedule_periodic()
1373 did_modify = mod_timer(&qh->unreserve_timer, in dwc2_deschedule_periodic()
1376 qh->unreserve_pending = 1; in dwc2_deschedule_periodic()
1378 list_del_init(&qh->qh_list_entry); in dwc2_deschedule_periodic()
1382 * dwc2_wait_timer_fn() - Timer function to re-queue after waiting
1407 struct dwc2_hsotg *hsotg = qh->hsotg; in dwc2_wait_timer_fn()
1410 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_wait_timer_fn()
1416 if (!qh->wait_timer_cancel) { in dwc2_wait_timer_fn()
1419 qh->want_wait = false; in dwc2_wait_timer_fn()
1421 list_move(&qh->qh_list_entry, in dwc2_wait_timer_fn()
1422 &hsotg->non_periodic_sched_inactive); in dwc2_wait_timer_fn()
1429 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_wait_timer_fn()
1434 * dwc2_qh_init() - Initializes a QH structure
1445 int dev_speed = dwc2_host_get_speed(hsotg, urb->priv); in dwc2_qh_init()
1446 u8 ep_type = dwc2_hcd_get_pipe_type(&urb->pipe_info); in dwc2_qh_init()
1447 bool ep_is_in = !!dwc2_hcd_is_pipe_in(&urb->pipe_info); in dwc2_qh_init()
1454 int maxp = dwc2_hcd_get_maxp(&urb->pipe_info); in dwc2_qh_init()
1455 int maxp_mult = dwc2_hcd_get_maxp_mult(&urb->pipe_info); in dwc2_qh_init()
1460 qh->hsotg = hsotg; in dwc2_qh_init()
1461 timer_setup(&qh->unreserve_timer, dwc2_unreserve_timer_fn, 0); in dwc2_qh_init()
1462 hrtimer_init(&qh->wait_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); in dwc2_qh_init()
1463 qh->wait_timer.function = &dwc2_wait_timer_fn; in dwc2_qh_init()
1464 qh->ep_type = ep_type; in dwc2_qh_init()
1465 qh->ep_is_in = ep_is_in; in dwc2_qh_init()
1467 qh->data_toggle = DWC2_HC_PID_DATA0; in dwc2_qh_init()
1468 qh->maxp = maxp; in dwc2_qh_init()
1469 qh->maxp_mult = maxp_mult; in dwc2_qh_init()
1470 INIT_LIST_HEAD(&qh->qtd_list); in dwc2_qh_init()
1471 INIT_LIST_HEAD(&qh->qh_list_entry); in dwc2_qh_init()
1473 qh->do_split = do_split; in dwc2_qh_init()
1474 qh->dev_speed = dev_speed; in dwc2_qh_init()
1479 struct dwc2_tt *dwc_tt = dwc2_host_get_tt_info(hsotg, urb->priv, in dwc2_qh_init()
1481 &qh->ttport); in dwc2_qh_init()
1484 qh->dwc_tt = dwc_tt; in dwc2_qh_init()
1486 qh->host_us = NS_TO_US(usb_calc_bus_time(host_speed, ep_is_in, in dwc2_qh_init()
1492 device_ns += dwc_tt->usb_tt->think_time; in dwc2_qh_init()
1493 qh->device_us = NS_TO_US(device_ns); in dwc2_qh_init()
1495 qh->device_interval = urb->interval; in dwc2_qh_init()
1496 qh->host_interval = urb->interval * (do_split ? 8 : 1); in dwc2_qh_init()
1500 * full speed OR if we've got a "TT" to deal with to access this in dwc2_qh_init()
1503 qh->schedule_low_speed = prtspd != HPRT0_SPD_HIGH_SPEED || in dwc2_qh_init()
1508 qh->num_hs_transfers = -1; in dwc2_qh_init()
1510 qh->num_hs_transfers = 1; in dwc2_qh_init()
1512 qh->num_hs_transfers = 0; in dwc2_qh_init()
1523 speed = "full"; in dwc2_qh_init()
1533 switch (qh->ep_type) { in dwc2_qh_init()
1554 dwc2_hcd_get_dev_addr(&urb->pipe_info), in dwc2_qh_init()
1555 dwc2_hcd_get_ep_num(&urb->pipe_info), in dwc2_qh_init()
1560 qh, qh->host_us, qh->device_us); in dwc2_qh_init()
1562 qh, qh->host_interval, qh->device_interval); in dwc2_qh_init()
1563 if (qh->schedule_low_speed) in dwc2_qh_init()
1570 * dwc2_hcd_qh_create() - Allocates and initializes a QH
1585 if (!urb->priv) in dwc2_hcd_qh_create()
1595 if (hsotg->params.dma_desc_enable && in dwc2_hcd_qh_create()
1605 * dwc2_hcd_qh_free() - Frees the QH
1618 if (del_timer_sync(&qh->unreserve_timer)) { in dwc2_hcd_qh_free()
1621 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_hcd_qh_free()
1623 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_hcd_qh_free()
1633 hrtimer_cancel(&qh->wait_timer); in dwc2_hcd_qh_free()
1635 dwc2_host_put_tt_info(hsotg, qh->dwc_tt); in dwc2_hcd_qh_free()
1637 if (qh->desc_list) in dwc2_hcd_qh_free()
1639 else if (hsotg->unaligned_cache && qh->dw_align_buf) in dwc2_hcd_qh_free()
1640 kmem_cache_free(hsotg->unaligned_cache, qh->dw_align_buf); in dwc2_hcd_qh_free()
1646 * dwc2_hcd_qh_add() - Adds a QH to either the non periodic or periodic
1662 dev_vdbg(hsotg->dev, "%s()\n", __func__); in dwc2_hcd_qh_add()
1664 if (!list_empty(&qh->qh_list_entry)) in dwc2_hcd_qh_add()
1671 qh->start_active_frame = hsotg->frame_number; in dwc2_hcd_qh_add()
1672 qh->next_active_frame = qh->start_active_frame; in dwc2_hcd_qh_add()
1674 if (qh->want_wait) { in dwc2_hcd_qh_add()
1675 list_add_tail(&qh->qh_list_entry, in dwc2_hcd_qh_add()
1676 &hsotg->non_periodic_sched_waiting); in dwc2_hcd_qh_add()
1677 qh->wait_timer_cancel = false; in dwc2_hcd_qh_add()
1679 hrtimer_start(&qh->wait_timer, delay, HRTIMER_MODE_REL); in dwc2_hcd_qh_add()
1681 list_add_tail(&qh->qh_list_entry, in dwc2_hcd_qh_add()
1682 &hsotg->non_periodic_sched_inactive); in dwc2_hcd_qh_add()
1690 if (!hsotg->periodic_qh_count) { in dwc2_hcd_qh_add()
1695 hsotg->periodic_qh_count++; in dwc2_hcd_qh_add()
1701 * dwc2_hcd_qh_unlink() - Removes a QH from either the non-periodic or periodic
1711 dev_vdbg(hsotg->dev, "%s()\n", __func__); in dwc2_hcd_qh_unlink()
1714 qh->wait_timer_cancel = true; in dwc2_hcd_qh_unlink()
1716 if (list_empty(&qh->qh_list_entry)) in dwc2_hcd_qh_unlink()
1721 if (hsotg->non_periodic_qh_ptr == &qh->qh_list_entry) in dwc2_hcd_qh_unlink()
1722 hsotg->non_periodic_qh_ptr = in dwc2_hcd_qh_unlink()
1723 hsotg->non_periodic_qh_ptr->next; in dwc2_hcd_qh_unlink()
1724 list_del_init(&qh->qh_list_entry); in dwc2_hcd_qh_unlink()
1729 hsotg->periodic_qh_count--; in dwc2_hcd_qh_unlink()
1730 if (!hsotg->periodic_qh_count && in dwc2_hcd_qh_unlink()
1731 !hsotg->params.dma_desc_enable) { in dwc2_hcd_qh_unlink()
1739 * dwc2_next_for_periodic_split() - Set next_active_frame midway thru a split.
1744 * Periodic splits are single low/full speed transfers that we end up splitting
1745 * up into several high speed transfers. They always fit into one full (1 ms)
1746 * frame but might be split over several microframes (125 us each). We to put
1747 * each of the parts on a very specific high speed frame.
1753 * @frame_number: The current frame number.
1760 u16 old_frame = qh->next_active_frame; in dwc2_next_for_periodic_split()
1771 if (old_frame == qh->start_active_frame && in dwc2_next_for_periodic_split()
1772 !(qh->ep_type == USB_ENDPOINT_XFER_ISOC && !qh->ep_is_in)) in dwc2_next_for_periodic_split()
1777 qh->next_active_frame = dwc2_frame_num_inc(old_frame, incr); in dwc2_next_for_periodic_split()
1780 * Note that it's OK for frame_number to be 1 frame past in dwc2_next_for_periodic_split()
1782 * be 1 frame _before_ when we want to be scheduled. If we're 1 frame in dwc2_next_for_periodic_split()
1785 * It's _not_ OK, however, if we're more than one frame past. in dwc2_next_for_periodic_split()
1787 if (dwc2_frame_num_gt(prev_frame_number, qh->next_active_frame)) { in dwc2_next_for_periodic_split()
1793 qh->next_active_frame); in dwc2_next_for_periodic_split()
1794 qh->next_active_frame = frame_number; in dwc2_next_for_periodic_split()
1801 * dwc2_next_periodic_start() - Set next_active_frame for next transfer start
1816 * @frame_number: The current frame number.
1824 u16 interval = qh->host_interval; in dwc2_next_periodic_start()
1827 qh->start_active_frame = dwc2_frame_num_inc(qh->start_active_frame, in dwc2_next_periodic_start()
1833 * frame counter only goes to 0x3fff. It's terribly unlikely that we in dwc2_next_periodic_start()
1845 * - We compare against prev_frame_number since start_active_frame in dwc2_next_periodic_start()
1846 * and next_active_frame are always 1 frame before we want things in dwc2_next_periodic_start()
1848 * current frame number. in dwc2_next_periodic_start()
1849 * - It's possible for start_active_frame (now incremented) to be in dwc2_next_periodic_start()
1854 * another transfer for the same frame. My test webcam doesn't seem in dwc2_next_periodic_start()
1856 * we do two transfers in the same frame. in dwc2_next_periodic_start()
1857 * - Some misses are expected. Specifically, in order to work in dwc2_next_periodic_start()
1867 if (qh->start_active_frame == qh->next_active_frame || in dwc2_next_periodic_start()
1868 dwc2_frame_num_gt(prev_frame_number, qh->start_active_frame)) { in dwc2_next_periodic_start()
1869 u16 ideal_start = qh->start_active_frame; in dwc2_next_periodic_start()
1876 if (qh->do_split || qh->dev_speed == USB_SPEED_HIGH) in dwc2_next_periodic_start()
1883 qh->start_active_frame = dwc2_frame_num_inc( in dwc2_next_periodic_start()
1884 qh->start_active_frame, interval); in dwc2_next_periodic_start()
1886 qh->start_active_frame)); in dwc2_next_periodic_start()
1888 missed = dwc2_frame_num_dec(qh->start_active_frame, in dwc2_next_periodic_start()
1893 qh->next_active_frame = qh->start_active_frame; in dwc2_next_periodic_start()
1899 * Deactivates a QH. For non-periodic QHs, removes the QH from the active
1900 * non-periodic schedule. The QH is added to the inactive non-periodic
1906 * scheduled frame is calculated. The QH is placed in the ready schedule if
1907 * the scheduled frame has been reached already. Otherwise it's placed in the
1914 u16 old_frame = qh->next_active_frame; in dwc2_hcd_qh_deactivate()
1919 dev_vdbg(hsotg->dev, "%s()\n", __func__); in dwc2_hcd_qh_deactivate()
1923 if (!list_empty(&qh->qtd_list)) in dwc2_hcd_qh_deactivate()
1924 /* Add back to inactive/waiting non-periodic schedule */ in dwc2_hcd_qh_deactivate()
1930 * Use the real frame number rather than the cached value as of the in dwc2_hcd_qh_deactivate()
1933 * interrupt for this frame. in dwc2_hcd_qh_deactivate()
1945 qh->next_active_frame, in dwc2_hcd_qh_deactivate()
1946 dwc2_frame_num_dec(qh->next_active_frame, old_frame), in dwc2_hcd_qh_deactivate()
1949 if (list_empty(&qh->qtd_list)) { in dwc2_hcd_qh_deactivate()
1961 if (dwc2_frame_num_le(qh->next_active_frame, hsotg->frame_number)) in dwc2_hcd_qh_deactivate()
1962 list_move_tail(&qh->qh_list_entry, in dwc2_hcd_qh_deactivate()
1963 &hsotg->periodic_sched_ready); in dwc2_hcd_qh_deactivate()
1965 list_move_tail(&qh->qh_list_entry, in dwc2_hcd_qh_deactivate()
1966 &hsotg->periodic_sched_inactive); in dwc2_hcd_qh_deactivate()
1970 * dwc2_hcd_qtd_init() - Initializes a QTD structure
1977 qtd->urb = urb; in dwc2_hcd_qtd_init()
1978 if (dwc2_hcd_get_pipe_type(&urb->pipe_info) == in dwc2_hcd_qtd_init()
1985 qtd->data_toggle = DWC2_HC_PID_DATA1; in dwc2_hcd_qtd_init()
1986 qtd->control_phase = DWC2_CONTROL_SETUP; in dwc2_hcd_qtd_init()
1990 qtd->complete_split = 0; in dwc2_hcd_qtd_init()
1991 qtd->isoc_split_pos = DWC2_HCSPLT_XACTPOS_ALL; in dwc2_hcd_qtd_init()
1992 qtd->isoc_split_offset = 0; in dwc2_hcd_qtd_init()
1993 qtd->in_process = 0; in dwc2_hcd_qtd_init()
1996 urb->qtd = qtd; in dwc2_hcd_qtd_init()
2000 * dwc2_hcd_qtd_add() - Adds a QTD to the QTD-list of a QH
2018 dev_err(hsotg->dev, "%s: Invalid QH\n", __func__); in dwc2_hcd_qtd_add()
2019 retval = -EINVAL; in dwc2_hcd_qtd_add()
2027 qtd->qh = qh; in dwc2_hcd_qtd_add()
2028 list_add_tail(&qtd->qtd_list_entry, &qh->qtd_list); in dwc2_hcd_qtd_add()