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>
35 * dwc2_periodic_channel_available() - Checks that a channel is available for a
47 * non-periodic transactions in dwc2_periodic_channel_available()
52 num_channels = hsotg->params.host_channels; in dwc2_periodic_channel_available()
53 if ((hsotg->periodic_channels + hsotg->non_periodic_channels < in dwc2_periodic_channel_available()
54 num_channels) && (hsotg->periodic_channels < num_channels - 1)) { in dwc2_periodic_channel_available()
57 dev_dbg(hsotg->dev, in dwc2_periodic_channel_available()
58 "%s: Total channels: %d, Periodic: %d, Non-periodic: %d\n", in dwc2_periodic_channel_available()
60 hsotg->periodic_channels, hsotg->non_periodic_channels); in dwc2_periodic_channel_available()
61 status = -ENOSPC; in dwc2_periodic_channel_available()
68 * dwc2_check_periodic_bandwidth() - Checks that there is sufficient bandwidth
77 * periodic schedule may occur in the same (micro)frame
87 if (qh->dev_speed == USB_SPEED_HIGH || qh->do_split) { in dwc2_check_periodic_bandwidth()
92 max_claimed_usecs = 100 - qh->host_us; in dwc2_check_periodic_bandwidth()
95 * Full speed mode in dwc2_check_periodic_bandwidth()
98 max_claimed_usecs = 900 - qh->host_us; in dwc2_check_periodic_bandwidth()
101 if (hsotg->periodic_usecs > max_claimed_usecs) { in dwc2_check_periodic_bandwidth()
102 dev_err(hsotg->dev, in dwc2_check_periodic_bandwidth()
104 __func__, hsotg->periodic_usecs, qh->host_us); in dwc2_check_periodic_bandwidth()
105 status = -ENOSPC; in dwc2_check_periodic_bandwidth()
112 * pmap_schedule() - Schedule time in a periodic bitmap (pmap).
134 * want the same resource. The resource is divided into fixed-sized periods
140 * but does mean that we need to handle things specially (and non-ideally) if
145 * - If interval is 1, we need to take up space in each of the 8
147 * - If interval is 2, we need to take up space in half of the
149 * - If interval is 3, we actually need to fall back to interval 1.
153 * 0, 3, and 6. Since we could be in any frame we need to reserve
157 * - If interval is 4, easy.
158 * - If interval is 5, we again need interval 1. The schedule will be
160 * - If interval is 6, we need interval 2. 0, 6, 4, 2.
161 * - If interval is 7, we need interval 1.
162 * - If interval is 8, we need interval 8.
167 * Note that at the moment this function tends to front-pack the schedule.
168 * In some cases that's really non-ideal (it's hard to schedule things that
199 * Returns either -ENOSPC or a >= 0 start bit which should be passed to the
200 * unschedule routine. The map bitmap will be updated on a non-error result.
212 return -ENOSPC; in pmap_schedule()
222 return -ENOSPC; in pmap_schedule()
279 start = ith_start - interval_bits * i; in pmap_schedule()
289 return -ENOSPC; in pmap_schedule()
301 * pmap_unschedule() - Undo work done by pmap_schedule()
332 * dwc2_get_ls_map() - Get the map used for the given qh
338 * running the host straight in low speed / full speed mode it appears as if
340 * add logic here to get a map out of "hsotg" if !qh->do_split.
350 if (WARN_ON(!qh->dwc_tt)) in dwc2_get_ls_map()
354 map = qh->dwc_tt->periodic_bitmaps; in dwc2_get_ls_map()
355 if (qh->dwc_tt->usb_tt->multi) in dwc2_get_ls_map()
356 map += DWC2_ELEMENTS_PER_LS_BITMAP * (qh->ttport - 1); in dwc2_get_ls_map()
363 * cat_printf() - A printf() + strcat() helper
388 (*buf)[*size - 1] = '\0'; in cat_printf()
393 *size -= i; in cat_printf()
398 * pmap_print() - Print the given periodic map
435 start = i - period_start; in pmap_print()
451 cat_printf(&buf, &buf_size, "%d %s -%3d %s", start, in pmap_print()
452 units, start + count - 1, units); in pmap_print()
467 * dwc2_qh_print() - Helper function for dwc2_qh_schedule_print()
476 dwc2_sch_dbg(print_data->hsotg, "QH=%p ...%s\n", print_data->qh, str); in dwc2_qh_print()
480 * dwc2_qh_schedule_print() - Print the periodic schedule
497 if (qh->schedule_low_speed) { in dwc2_qh_schedule_print()
501 qh, qh->device_us, in dwc2_qh_schedule_print()
502 DWC2_ROUND_US_TO_SLICE(qh->device_us), in dwc2_qh_schedule_print()
503 DWC2_US_PER_SLICE * qh->ls_start_schedule_slice); in dwc2_qh_schedule_print()
507 "QH=%p Whole low/full speed map %p now:\n", in dwc2_qh_schedule_print()
510 DWC2_LS_SCHEDULE_FRAMES, "Frame ", "slices", in dwc2_qh_schedule_print()
515 for (i = 0; i < qh->num_hs_transfers; i++) { in dwc2_qh_schedule_print()
516 struct dwc2_hs_transfer_time *trans_time = qh->hs_transfers + i; in dwc2_qh_schedule_print()
517 int uframe = trans_time->start_schedule_us / in dwc2_qh_schedule_print()
519 int rel_us = trans_time->start_schedule_us % in dwc2_qh_schedule_print()
524 qh, i, trans_time->duration_us, uframe, rel_us); in dwc2_qh_schedule_print()
526 if (qh->num_hs_transfers) { in dwc2_qh_schedule_print()
528 pmap_print(hsotg->hs_periodic_bitmap, in dwc2_qh_schedule_print()
540 * dwc2_ls_pmap_schedule() - Schedule a low speed QH
557 int slices = DIV_ROUND_UP(qh->device_us, DWC2_US_PER_SLICE); in dwc2_ls_pmap_schedule()
562 return -EINVAL; in dwc2_ls_pmap_schedule()
578 qh->device_interval, search_slice, false); in dwc2_ls_pmap_schedule()
583 qh->ls_start_schedule_slice = slice; in dwc2_ls_pmap_schedule()
588 * dwc2_ls_pmap_unschedule() - Undo work done by dwc2_ls_pmap_schedule()
596 int slices = DIV_ROUND_UP(qh->device_us, DWC2_US_PER_SLICE); in dwc2_ls_pmap_unschedule()
604 DWC2_LS_SCHEDULE_FRAMES, slices, qh->device_interval, in dwc2_ls_pmap_unschedule()
605 qh->ls_start_schedule_slice); in dwc2_ls_pmap_unschedule()
609 * dwc2_hs_pmap_schedule - Schedule in the main high speed schedule
613 * We'll start looking in qh->hs_transfers[index].start_schedule_us. We'll
623 * @index: The index into qh->hs_transfers that we're working with.
631 struct dwc2_hs_transfer_time *trans_time = qh->hs_transfers + index; in dwc2_hs_pmap_schedule()
634 us = pmap_schedule(hsotg->hs_periodic_bitmap, in dwc2_hs_pmap_schedule()
636 DWC2_HS_SCHEDULE_UFRAMES, trans_time->duration_us, in dwc2_hs_pmap_schedule()
637 qh->host_interval, trans_time->start_schedule_us, in dwc2_hs_pmap_schedule()
643 trans_time->start_schedule_us = us; in dwc2_hs_pmap_schedule()
648 * dwc2_hs_pmap_unschedule() - Undo work done by dwc2_hs_pmap_schedule()
657 struct dwc2_hs_transfer_time *trans_time = qh->hs_transfers + index; in dwc2_hs_pmap_unschedule()
659 pmap_unschedule(hsotg->hs_periodic_bitmap, in dwc2_hs_pmap_unschedule()
661 DWC2_HS_SCHEDULE_UFRAMES, trans_time->duration_us, in dwc2_hs_pmap_unschedule()
662 qh->host_interval, trans_time->start_schedule_us); in dwc2_hs_pmap_unschedule()
666 * dwc2_uframe_schedule_split - Schedule a QH for a periodic split xfer.
673 * device is in low or full speed mode (and behind a hub).
681 int bytecount = qh->maxp_mult * qh->maxp; in dwc2_uframe_schedule_split()
690 host_interval_in_sched = gcd(qh->host_interval, in dwc2_uframe_schedule_split()
700 * Note that this will tend to front-load the high speed schedule. in dwc2_uframe_schedule_split()
718 if (qh->schedule_low_speed) { in dwc2_uframe_schedule_split()
735 * This will give us a number 0 - 7 if in dwc2_uframe_schedule_split()
736 * DWC2_LS_SCHEDULE_FRAMES == 1, or 0 - 15 if == 2, or ... in dwc2_uframe_schedule_split()
738 start_s_uframe = qh->ls_start_schedule_slice / in dwc2_uframe_schedule_split()
741 /* Get a number that's always 0 - 7 */ in dwc2_uframe_schedule_split()
747 * Move on to the next full frame (assuming there is one). in dwc2_uframe_schedule_split()
753 if (qh->schedule_low_speed) in dwc2_uframe_schedule_split()
756 (qh->ls_start_schedule_slice / in dwc2_uframe_schedule_split()
764 * - start split (frame -1) in dwc2_uframe_schedule_split()
765 * - complete split w/ data (frame +1) in dwc2_uframe_schedule_split()
766 * - complete split w/ data (frame +2) in dwc2_uframe_schedule_split()
767 * - ... in dwc2_uframe_schedule_split()
768 * - complete split w/ data (frame +num_data_packets) in dwc2_uframe_schedule_split()
769 * - complete split w/ data (frame +num_data_packets+1) in dwc2_uframe_schedule_split()
770 * - complete split w/ data (frame +num_data_packets+2, max 8) in dwc2_uframe_schedule_split()
771 * ...though if frame was "0" then max is 7... in dwc2_uframe_schedule_split()
774 * - start split w/ data (frame -1) in dwc2_uframe_schedule_split()
775 * - start split w/ data (frame +0) in dwc2_uframe_schedule_split()
776 * - ... in dwc2_uframe_schedule_split()
777 * - start split w/ data (frame +num_data_packets-2) in dwc2_uframe_schedule_split()
780 * - start split (frame -1) in dwc2_uframe_schedule_split()
781 * - complete split w/ data (frame +1) in dwc2_uframe_schedule_split()
782 * - complete split w/ data (frame +2) in dwc2_uframe_schedule_split()
783 * - complete split w/ data (frame +3, max 8) in dwc2_uframe_schedule_split()
786 * - start split w/ data (frame -1) in dwc2_uframe_schedule_split()
787 * - complete split (frame +1) in dwc2_uframe_schedule_split()
788 * - complete split (frame +2) in dwc2_uframe_schedule_split()
789 * - complete split (frame +3, max 8) in dwc2_uframe_schedule_split()
794 host_interval_in_sched - 1) % in dwc2_uframe_schedule_split()
796 if (qh->ep_type == USB_ENDPOINT_XFER_ISOC && !qh->ep_is_in) in dwc2_uframe_schedule_split()
802 first_data_bytes = 188 - in dwc2_uframe_schedule_split()
803 DIV_ROUND_UP(188 * (qh->ls_start_schedule_slice % in dwc2_uframe_schedule_split()
808 other_data_bytes = bytecount - first_data_bytes; in dwc2_uframe_schedule_split()
814 * - INT transfers never get split in two. in dwc2_uframe_schedule_split()
815 * - ISOC transfers can always transfer 188 bytes the first in dwc2_uframe_schedule_split()
825 if (!qh->ep_is_in && in dwc2_uframe_schedule_split()
830 if (qh->schedule_low_speed) in dwc2_uframe_schedule_split()
838 qh->num_hs_transfers = 1 + DIV_ROUND_UP(other_data_bytes, 188); in dwc2_uframe_schedule_split()
845 if (qh->ep_type == USB_ENDPOINT_XFER_INT) { in dwc2_uframe_schedule_split()
847 qh->num_hs_transfers += 2; in dwc2_uframe_schedule_split()
849 qh->num_hs_transfers += 3; in dwc2_uframe_schedule_split()
851 if (qh->ep_is_in) { in dwc2_uframe_schedule_split()
854 * Allocate full data bytes for all data. in dwc2_uframe_schedule_split()
870 if (qh->ep_is_in) { in dwc2_uframe_schedule_split()
874 qh->num_hs_transfers++; in dwc2_uframe_schedule_split()
877 last = rel_uframe + qh->num_hs_transfers + 1; in dwc2_uframe_schedule_split()
881 qh->num_hs_transfers += 2; in dwc2_uframe_schedule_split()
883 qh->num_hs_transfers += 1; in dwc2_uframe_schedule_split()
887 qh->num_hs_transfers--; in dwc2_uframe_schedule_split()
903 qh->hs_transfers[0].duration_us = HS_USECS_ISO(first_count); in dwc2_uframe_schedule_split()
904 for (i = 1; i < qh->num_hs_transfers - 1; i++) in dwc2_uframe_schedule_split()
905 qh->hs_transfers[i].duration_us = in dwc2_uframe_schedule_split()
907 if (qh->num_hs_transfers > 1) in dwc2_uframe_schedule_split()
908 qh->hs_transfers[qh->num_hs_transfers - 1].duration_us = in dwc2_uframe_schedule_split()
916 qh->hs_transfers[0].start_schedule_us = in dwc2_uframe_schedule_split()
918 for (i = 1; i < qh->num_hs_transfers; i++) in dwc2_uframe_schedule_split()
919 qh->hs_transfers[i].start_schedule_us = in dwc2_uframe_schedule_split()
920 ((second_s_uframe + i - 1) % in dwc2_uframe_schedule_split()
925 for (i = 0; i < qh->num_hs_transfers; i++) { in dwc2_uframe_schedule_split()
932 if (i == qh->num_hs_transfers) in dwc2_uframe_schedule_split()
935 for (; i >= 0; i--) in dwc2_uframe_schedule_split()
938 if (qh->schedule_low_speed) in dwc2_uframe_schedule_split()
946 return -ENOSPC; in dwc2_uframe_schedule_split()
952 * dwc2_uframe_schedule_hs - Schedule a QH for a periodic high speed xfer.
962 /* In non-split host and device time are the same */ in dwc2_uframe_schedule_hs()
963 WARN_ON(qh->host_us != qh->device_us); in dwc2_uframe_schedule_hs()
964 WARN_ON(qh->host_interval != qh->device_interval); in dwc2_uframe_schedule_hs()
965 WARN_ON(qh->num_hs_transfers != 1); in dwc2_uframe_schedule_hs()
968 qh->hs_transfers[0].start_schedule_us = 0; in dwc2_uframe_schedule_hs()
969 qh->hs_transfers[0].duration_us = qh->host_us; in dwc2_uframe_schedule_hs()
975 * dwc2_uframe_schedule_ls - Schedule a QH for a periodic low/full speed xfer.
985 /* In non-split host and device time are the same */ in dwc2_uframe_schedule_ls()
986 WARN_ON(qh->host_us != qh->device_us); in dwc2_uframe_schedule_ls()
987 WARN_ON(qh->host_interval != qh->device_interval); in dwc2_uframe_schedule_ls()
988 WARN_ON(!qh->schedule_low_speed); in dwc2_uframe_schedule_ls()
995 * dwc2_uframe_schedule - Schedule a QH for a periodic xfer.
997 * Calls one of the 3 sub-function depending on what type of transfer this QH
1007 if (qh->dev_speed == USB_SPEED_HIGH) in dwc2_uframe_schedule()
1009 else if (!qh->do_split) in dwc2_uframe_schedule()
1023 * dwc2_uframe_unschedule - Undoes dwc2_uframe_schedule().
1032 for (i = 0; i < qh->num_hs_transfers; i++) in dwc2_uframe_unschedule()
1035 if (qh->schedule_low_speed) in dwc2_uframe_unschedule()
1042 * dwc2_pick_first_frame() - Choose 1st frame for qh that's already scheduled
1049 * running. It just picks the next frame that we can fit into without any
1065 * Use the real frame number rather than the cached value as of the in dwc2_pick_first_frame()
1071 * We wouldn't want to start any earlier than the next frame just in in dwc2_pick_first_frame()
1072 * case the frame number ticks as we're doing this calculation. in dwc2_pick_first_frame()
1082 if (!hsotg->params.uframe_sched) { in dwc2_pick_first_frame()
1083 if (qh->do_split) in dwc2_pick_first_frame()
1089 if (qh->dev_speed == USB_SPEED_HIGH || qh->do_split) { in dwc2_pick_first_frame()
1093 * the first frame should be based on when the first scheduled in dwc2_pick_first_frame()
1096 WARN_ON(qh->num_hs_transfers < 1); in dwc2_pick_first_frame()
1098 relative_frame = qh->hs_transfers[0].start_schedule_us / in dwc2_pick_first_frame()
1102 interval = gcd(qh->host_interval, DWC2_HS_SCHEDULE_UFRAMES); in dwc2_pick_first_frame()
1106 * Low or full speed directly on dwc2. Just about the same in dwc2_pick_first_frame()
1112 relative_frame = qh->ls_start_schedule_slice / in dwc2_pick_first_frame()
1114 interval = gcd(qh->host_interval, DWC2_LS_SCHEDULE_FRAMES); in dwc2_pick_first_frame()
1117 /* Scheduler messed up if frame is past interval */ in dwc2_pick_first_frame()
1131 * Actually choose to start at the frame number we've been in dwc2_pick_first_frame()
1138 * We actually need 1 frame before since the next_active_frame is in dwc2_pick_first_frame()
1139 * the frame number we'll be put on the ready list and we won't be on in dwc2_pick_first_frame()
1140 * the bus until 1 frame later. in dwc2_pick_first_frame()
1153 qh->next_active_frame = next_active_frame; in dwc2_pick_first_frame()
1154 qh->start_active_frame = next_active_frame; in dwc2_pick_first_frame()
1157 qh, frame_number, qh->next_active_frame); in dwc2_pick_first_frame()
1161 * dwc2_do_reserve() - Make a periodic reservation
1175 if (hsotg->params.uframe_sched) { in dwc2_do_reserve()
1180 dev_info(hsotg->dev, in dwc2_do_reserve()
1190 dev_dbg(hsotg->dev, in dwc2_do_reserve()
1196 if (!hsotg->params.uframe_sched) in dwc2_do_reserve()
1198 hsotg->periodic_channels++; in dwc2_do_reserve()
1200 /* Update claimed usecs per (micro)frame */ in dwc2_do_reserve()
1201 hsotg->periodic_usecs += qh->host_us; in dwc2_do_reserve()
1209 * dwc2_do_unreserve() - Actually release the periodic reservation
1219 assert_spin_locked(&hsotg->lock); in dwc2_do_unreserve()
1221 WARN_ON(!qh->unreserve_pending); in dwc2_do_unreserve()
1223 /* No more unreserve pending--we're doing it */ in dwc2_do_unreserve()
1224 qh->unreserve_pending = false; in dwc2_do_unreserve()
1226 if (WARN_ON(!list_empty(&qh->qh_list_entry))) in dwc2_do_unreserve()
1227 list_del_init(&qh->qh_list_entry); in dwc2_do_unreserve()
1229 /* Update claimed usecs per (micro)frame */ in dwc2_do_unreserve()
1230 hsotg->periodic_usecs -= qh->host_us; in dwc2_do_unreserve()
1232 if (hsotg->params.uframe_sched) { in dwc2_do_unreserve()
1236 hsotg->periodic_channels--; in dwc2_do_unreserve()
1241 * dwc2_unreserve_timer_fn() - Timer function to release periodic reservation
1255 struct dwc2_hsotg *hsotg = qh->hsotg; in dwc2_unreserve_timer_fn()
1261 * - We started executing but didn't get the lock yet. in dwc2_unreserve_timer_fn()
1262 * - A new reservation came in, but cancel didn't take effect in dwc2_unreserve_timer_fn()
1264 * - The timer has been kicked again. in dwc2_unreserve_timer_fn()
1267 while (!spin_trylock_irqsave(&hsotg->lock, flags)) { in dwc2_unreserve_timer_fn()
1268 if (timer_pending(&qh->unreserve_timer)) in dwc2_unreserve_timer_fn()
1274 * - We started executing but didn't get the lock yet. in dwc2_unreserve_timer_fn()
1275 * - A new reservation came in, but cancel didn't take effect in dwc2_unreserve_timer_fn()
1282 if (qh->unreserve_pending) in dwc2_unreserve_timer_fn()
1285 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_unreserve_timer_fn()
1289 * dwc2_check_max_xfer_size() - Checks that the max transfer size allowed in a
1291 * (micro)frame for a periodic transfer
1305 max_xfer_size = qh->maxp * qh->maxp_mult; in dwc2_check_max_xfer_size()
1306 max_channel_xfer_size = hsotg->params.max_transfer_size; in dwc2_check_max_xfer_size()
1309 dev_err(hsotg->dev, in dwc2_check_max_xfer_size()
1312 status = -ENOSPC; in dwc2_check_max_xfer_size()
1319 * dwc2_schedule_periodic() - Schedules an interrupt or isochronous transfer in
1334 dev_dbg(hsotg->dev, in dwc2_schedule_periodic()
1341 if (del_timer(&qh->unreserve_timer)) in dwc2_schedule_periodic()
1342 WARN_ON(!qh->unreserve_pending); in dwc2_schedule_periodic()
1351 if (!qh->unreserve_pending) { in dwc2_schedule_periodic()
1362 if (dwc2_frame_num_le(qh->next_active_frame, in dwc2_schedule_periodic()
1363 hsotg->frame_number)) in dwc2_schedule_periodic()
1367 qh->unreserve_pending = 0; in dwc2_schedule_periodic()
1369 if (hsotg->params.dma_desc_enable) in dwc2_schedule_periodic()
1371 list_add_tail(&qh->qh_list_entry, &hsotg->periodic_sched_ready); in dwc2_schedule_periodic()
1374 list_add_tail(&qh->qh_list_entry, in dwc2_schedule_periodic()
1375 &hsotg->periodic_sched_inactive); in dwc2_schedule_periodic()
1381 * dwc2_deschedule_periodic() - Removes an interrupt or isochronous transfer
1392 assert_spin_locked(&hsotg->lock); in dwc2_deschedule_periodic()
1396 * - Unreserve worker might be sitting there waiting to grab the lock. in dwc2_deschedule_periodic()
1399 * - Unreserve worker might not be scheduled. in dwc2_deschedule_periodic()
1409 did_modify = mod_timer(&qh->unreserve_timer, in dwc2_deschedule_periodic()
1412 qh->unreserve_pending = 1; in dwc2_deschedule_periodic()
1414 list_del_init(&qh->qh_list_entry); in dwc2_deschedule_periodic()
1418 * dwc2_wait_timer_fn() - Timer function to re-queue after waiting
1443 struct dwc2_hsotg *hsotg = qh->hsotg; in dwc2_wait_timer_fn()
1446 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_wait_timer_fn()
1452 if (!qh->wait_timer_cancel) { in dwc2_wait_timer_fn()
1455 qh->want_wait = false; in dwc2_wait_timer_fn()
1457 list_move(&qh->qh_list_entry, in dwc2_wait_timer_fn()
1458 &hsotg->non_periodic_sched_inactive); in dwc2_wait_timer_fn()
1465 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_wait_timer_fn()
1470 * dwc2_qh_init() - Initializes a QH structure
1481 int dev_speed = dwc2_host_get_speed(hsotg, urb->priv); in dwc2_qh_init()
1482 u8 ep_type = dwc2_hcd_get_pipe_type(&urb->pipe_info); in dwc2_qh_init()
1483 bool ep_is_in = !!dwc2_hcd_is_pipe_in(&urb->pipe_info); in dwc2_qh_init()
1490 int maxp = dwc2_hcd_get_maxp(&urb->pipe_info); in dwc2_qh_init()
1491 int maxp_mult = dwc2_hcd_get_maxp_mult(&urb->pipe_info); in dwc2_qh_init()
1496 qh->hsotg = hsotg; in dwc2_qh_init()
1497 timer_setup(&qh->unreserve_timer, dwc2_unreserve_timer_fn, 0); in dwc2_qh_init()
1498 hrtimer_init(&qh->wait_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); in dwc2_qh_init()
1499 qh->wait_timer.function = &dwc2_wait_timer_fn; in dwc2_qh_init()
1500 qh->ep_type = ep_type; in dwc2_qh_init()
1501 qh->ep_is_in = ep_is_in; in dwc2_qh_init()
1503 qh->data_toggle = DWC2_HC_PID_DATA0; in dwc2_qh_init()
1504 qh->maxp = maxp; in dwc2_qh_init()
1505 qh->maxp_mult = maxp_mult; in dwc2_qh_init()
1506 INIT_LIST_HEAD(&qh->qtd_list); in dwc2_qh_init()
1507 INIT_LIST_HEAD(&qh->qh_list_entry); in dwc2_qh_init()
1509 qh->do_split = do_split; in dwc2_qh_init()
1510 qh->dev_speed = dev_speed; in dwc2_qh_init()
1515 struct dwc2_tt *dwc_tt = dwc2_host_get_tt_info(hsotg, urb->priv, in dwc2_qh_init()
1517 &qh->ttport); in dwc2_qh_init()
1520 qh->dwc_tt = dwc_tt; in dwc2_qh_init()
1522 qh->host_us = NS_TO_US(usb_calc_bus_time(host_speed, ep_is_in, in dwc2_qh_init()
1528 device_ns += dwc_tt->usb_tt->think_time; in dwc2_qh_init()
1529 qh->device_us = NS_TO_US(device_ns); in dwc2_qh_init()
1531 qh->device_interval = urb->interval; in dwc2_qh_init()
1532 qh->host_interval = urb->interval * (do_split ? 8 : 1); in dwc2_qh_init()
1536 * full speed OR if we've got a "TT" to deal with to access this in dwc2_qh_init()
1539 qh->schedule_low_speed = prtspd != HPRT0_SPD_HIGH_SPEED || in dwc2_qh_init()
1544 qh->num_hs_transfers = -1; in dwc2_qh_init()
1546 qh->num_hs_transfers = 1; in dwc2_qh_init()
1548 qh->num_hs_transfers = 0; in dwc2_qh_init()
1559 speed = "full"; in dwc2_qh_init()
1569 switch (qh->ep_type) { in dwc2_qh_init()
1590 dwc2_hcd_get_dev_addr(&urb->pipe_info), in dwc2_qh_init()
1591 dwc2_hcd_get_ep_num(&urb->pipe_info), in dwc2_qh_init()
1596 qh, qh->host_us, qh->device_us); in dwc2_qh_init()
1598 qh, qh->host_interval, qh->device_interval); in dwc2_qh_init()
1599 if (qh->schedule_low_speed) in dwc2_qh_init()
1606 * dwc2_hcd_qh_create() - Allocates and initializes a QH
1621 if (!urb->priv) in dwc2_hcd_qh_create()
1631 if (hsotg->params.dma_desc_enable && in dwc2_hcd_qh_create()
1641 * dwc2_hcd_qh_free() - Frees the QH
1654 if (del_timer_sync(&qh->unreserve_timer)) { in dwc2_hcd_qh_free()
1657 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_hcd_qh_free()
1659 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_hcd_qh_free()
1669 hrtimer_cancel(&qh->wait_timer); in dwc2_hcd_qh_free()
1671 dwc2_host_put_tt_info(hsotg, qh->dwc_tt); in dwc2_hcd_qh_free()
1673 if (qh->desc_list) in dwc2_hcd_qh_free()
1675 else if (hsotg->unaligned_cache && qh->dw_align_buf) in dwc2_hcd_qh_free()
1676 kmem_cache_free(hsotg->unaligned_cache, qh->dw_align_buf); in dwc2_hcd_qh_free()
1682 * dwc2_hcd_qh_add() - Adds a QH to either the non periodic or periodic
1698 dev_vdbg(hsotg->dev, "%s()\n", __func__); in dwc2_hcd_qh_add()
1700 if (!list_empty(&qh->qh_list_entry)) in dwc2_hcd_qh_add()
1707 qh->start_active_frame = hsotg->frame_number; in dwc2_hcd_qh_add()
1708 qh->next_active_frame = qh->start_active_frame; in dwc2_hcd_qh_add()
1710 if (qh->want_wait) { in dwc2_hcd_qh_add()
1711 list_add_tail(&qh->qh_list_entry, in dwc2_hcd_qh_add()
1712 &hsotg->non_periodic_sched_waiting); in dwc2_hcd_qh_add()
1713 qh->wait_timer_cancel = false; in dwc2_hcd_qh_add()
1715 hrtimer_start(&qh->wait_timer, delay, HRTIMER_MODE_REL); in dwc2_hcd_qh_add()
1717 list_add_tail(&qh->qh_list_entry, in dwc2_hcd_qh_add()
1718 &hsotg->non_periodic_sched_inactive); in dwc2_hcd_qh_add()
1726 if (!hsotg->periodic_qh_count) { in dwc2_hcd_qh_add()
1731 hsotg->periodic_qh_count++; in dwc2_hcd_qh_add()
1737 * dwc2_hcd_qh_unlink() - Removes a QH from either the non-periodic or periodic
1747 dev_vdbg(hsotg->dev, "%s()\n", __func__); in dwc2_hcd_qh_unlink()
1750 qh->wait_timer_cancel = true; in dwc2_hcd_qh_unlink()
1752 if (list_empty(&qh->qh_list_entry)) in dwc2_hcd_qh_unlink()
1757 if (hsotg->non_periodic_qh_ptr == &qh->qh_list_entry) in dwc2_hcd_qh_unlink()
1758 hsotg->non_periodic_qh_ptr = in dwc2_hcd_qh_unlink()
1759 hsotg->non_periodic_qh_ptr->next; in dwc2_hcd_qh_unlink()
1760 list_del_init(&qh->qh_list_entry); in dwc2_hcd_qh_unlink()
1765 hsotg->periodic_qh_count--; in dwc2_hcd_qh_unlink()
1766 if (!hsotg->periodic_qh_count && in dwc2_hcd_qh_unlink()
1767 !hsotg->params.dma_desc_enable) { in dwc2_hcd_qh_unlink()
1775 * dwc2_next_for_periodic_split() - Set next_active_frame midway thru a split.
1780 * Periodic splits are single low/full speed transfers that we end up splitting
1781 * up into several high speed transfers. They always fit into one full (1 ms)
1782 * frame but might be split over several microframes (125 us each). We to put
1783 * each of the parts on a very specific high speed frame.
1789 * @frame_number: The current frame number.
1796 u16 old_frame = qh->next_active_frame; in dwc2_next_for_periodic_split()
1807 if (old_frame == qh->start_active_frame && in dwc2_next_for_periodic_split()
1808 !(qh->ep_type == USB_ENDPOINT_XFER_ISOC && !qh->ep_is_in)) in dwc2_next_for_periodic_split()
1813 qh->next_active_frame = dwc2_frame_num_inc(old_frame, incr); in dwc2_next_for_periodic_split()
1816 * Note that it's OK for frame_number to be 1 frame past in dwc2_next_for_periodic_split()
1818 * be 1 frame _before_ when we want to be scheduled. If we're 1 frame in dwc2_next_for_periodic_split()
1821 * It's _not_ OK, however, if we're more than one frame past. in dwc2_next_for_periodic_split()
1823 if (dwc2_frame_num_gt(prev_frame_number, qh->next_active_frame)) { in dwc2_next_for_periodic_split()
1829 qh->next_active_frame); in dwc2_next_for_periodic_split()
1830 qh->next_active_frame = frame_number; in dwc2_next_for_periodic_split()
1837 * dwc2_next_periodic_start() - Set next_active_frame for next transfer start
1852 * @frame_number: The current frame number.
1860 u16 interval = qh->host_interval; in dwc2_next_periodic_start()
1863 qh->start_active_frame = dwc2_frame_num_inc(qh->start_active_frame, in dwc2_next_periodic_start()
1869 * frame counter only goes to 0x3fff. It's terribly unlikely that we in dwc2_next_periodic_start()
1881 * - We compare against prev_frame_number since start_active_frame in dwc2_next_periodic_start()
1882 * and next_active_frame are always 1 frame before we want things in dwc2_next_periodic_start()
1884 * current frame number. in dwc2_next_periodic_start()
1885 * - It's possible for start_active_frame (now incremented) to be in dwc2_next_periodic_start()
1890 * another transfer for the same frame. My test webcam doesn't seem in dwc2_next_periodic_start()
1892 * we do two transfers in the same frame. in dwc2_next_periodic_start()
1893 * - Some misses are expected. Specifically, in order to work in dwc2_next_periodic_start()
1903 if (qh->start_active_frame == qh->next_active_frame || in dwc2_next_periodic_start()
1904 dwc2_frame_num_gt(prev_frame_number, qh->start_active_frame)) { in dwc2_next_periodic_start()
1905 u16 ideal_start = qh->start_active_frame; in dwc2_next_periodic_start()
1912 if (qh->do_split || qh->dev_speed == USB_SPEED_HIGH) in dwc2_next_periodic_start()
1919 qh->start_active_frame = dwc2_frame_num_inc( in dwc2_next_periodic_start()
1920 qh->start_active_frame, interval); in dwc2_next_periodic_start()
1922 qh->start_active_frame)); in dwc2_next_periodic_start()
1924 missed = dwc2_frame_num_dec(qh->start_active_frame, in dwc2_next_periodic_start()
1929 qh->next_active_frame = qh->start_active_frame; in dwc2_next_periodic_start()
1935 * Deactivates a QH. For non-periodic QHs, removes the QH from the active
1936 * non-periodic schedule. The QH is added to the inactive non-periodic
1942 * scheduled frame is calculated. The QH is placed in the ready schedule if
1943 * the scheduled frame has been reached already. Otherwise it's placed in the
1950 u16 old_frame = qh->next_active_frame; in dwc2_hcd_qh_deactivate()
1955 dev_vdbg(hsotg->dev, "%s()\n", __func__); in dwc2_hcd_qh_deactivate()
1959 if (!list_empty(&qh->qtd_list)) in dwc2_hcd_qh_deactivate()
1960 /* Add back to inactive/waiting non-periodic schedule */ in dwc2_hcd_qh_deactivate()
1966 * Use the real frame number rather than the cached value as of the in dwc2_hcd_qh_deactivate()
1969 * interrupt for this frame. in dwc2_hcd_qh_deactivate()
1981 qh->next_active_frame, in dwc2_hcd_qh_deactivate()
1982 dwc2_frame_num_dec(qh->next_active_frame, old_frame), in dwc2_hcd_qh_deactivate()
1985 if (list_empty(&qh->qtd_list)) { in dwc2_hcd_qh_deactivate()
1997 if (dwc2_frame_num_le(qh->next_active_frame, hsotg->frame_number)) in dwc2_hcd_qh_deactivate()
1998 list_move_tail(&qh->qh_list_entry, in dwc2_hcd_qh_deactivate()
1999 &hsotg->periodic_sched_ready); in dwc2_hcd_qh_deactivate()
2001 list_move_tail(&qh->qh_list_entry, in dwc2_hcd_qh_deactivate()
2002 &hsotg->periodic_sched_inactive); in dwc2_hcd_qh_deactivate()
2006 * dwc2_hcd_qtd_init() - Initializes a QTD structure
2013 qtd->urb = urb; in dwc2_hcd_qtd_init()
2014 if (dwc2_hcd_get_pipe_type(&urb->pipe_info) == in dwc2_hcd_qtd_init()
2021 qtd->data_toggle = DWC2_HC_PID_DATA1; in dwc2_hcd_qtd_init()
2022 qtd->control_phase = DWC2_CONTROL_SETUP; in dwc2_hcd_qtd_init()
2026 qtd->complete_split = 0; in dwc2_hcd_qtd_init()
2027 qtd->isoc_split_pos = DWC2_HCSPLT_XACTPOS_ALL; in dwc2_hcd_qtd_init()
2028 qtd->isoc_split_offset = 0; in dwc2_hcd_qtd_init()
2029 qtd->in_process = 0; in dwc2_hcd_qtd_init()
2032 urb->qtd = qtd; in dwc2_hcd_qtd_init()
2036 * dwc2_hcd_qtd_add() - Adds a QTD to the QTD-list of a QH
2054 dev_err(hsotg->dev, "%s: Invalid QH\n", __func__); in dwc2_hcd_qtd_add()
2055 retval = -EINVAL; in dwc2_hcd_qtd_add()
2063 qtd->qh = qh; in dwc2_hcd_qtd_add()
2064 list_add_tail(&qtd->qtd_list_entry, &qh->qtd_list); in dwc2_hcd_qtd_add()