From ced9eee1229db3bbe683ae17e0a91a8642382a39 Mon Sep 17 00:00:00 2001 From: Douglas Anderson Date: Thu, 28 Jan 2016 18:20:04 -0800 Subject: [PATCH] usb: dwc2: host: Rename some fields in struct dwc2_qh This no-op change just does some renames to simplify a future patch. 1. The "interval" field is renamed to "host_interval" to make it more obvious that this interval may be 8 times the interval that the device sees (if we're doing split transactions). A future patch will also add the "device_interval" field. 2. The "usecs" field is renamed to "host_us" again to make it more obvious that this is the time for the transaction as seen by the host. For split transactions the device may see a much longer transaction time. A future patch will also add "device_us". 3. The "sched_frame" field is renamed to "next_active_frame". The name "sched_frame" kept confusing me because it felt like something more permament (the QH's reservation or something). The name "next_active_frame" makes it more obvious that this field is constantly changing. Acked-by: John Youn Signed-off-by: Douglas Anderson Tested-by: Heiko Stuebner Tested-by: Stefan Wahren Signed-off-by: Felipe Balbi --- drivers/usb/dwc2/hcd.h | 20 ++++--- drivers/usb/dwc2/hcd_ddma.c | 37 ++++++------ drivers/usb/dwc2/hcd_intr.c | 10 ++-- drivers/usb/dwc2/hcd_queue.c | 107 ++++++++++++++++++----------------- 4 files changed, 92 insertions(+), 82 deletions(-) diff --git a/drivers/usb/dwc2/hcd.h b/drivers/usb/dwc2/hcd.h index 79473ea35bd6..10c35585a2bd 100644 --- a/drivers/usb/dwc2/hcd.h +++ b/drivers/usb/dwc2/hcd.h @@ -236,10 +236,14 @@ enum dwc2_transaction_type { * @do_split: Full/low speed endpoint on high-speed hub requires split * @td_first: Index of first activated isochronous transfer descriptor * @td_last: Index of last activated isochronous transfer descriptor - * @usecs: Bandwidth in microseconds per (micro)frame - * @interval: Interval between transfers in (micro)frames - * @sched_frame: (Micro)frame to initialize a periodic transfer. - * The transfer executes in the following (micro)frame. + * @host_us: Bandwidth in microseconds per transfer as seen by host + * @host_interval: Interval between transfers as seen by the host. If + * the host is high speed and the device is low speed this + * will be 8 times device interval. + * @next_active_frame: (Micro)frame before we next need to put something on + * the bus. We'll move the qh to active here. If the + * host is in high speed mode this will be a uframe. If + * the host is in low speed mode this will be a full frame. * @frame_usecs: Internal variable used by the microframe scheduler * @start_split_frame: (Micro)frame at which last start split was initialized * @ntd: Actual number of transfer descriptors in a list @@ -272,9 +276,9 @@ struct dwc2_qh { u8 do_split; u8 td_first; u8 td_last; - u16 usecs; - u16 interval; - u16 sched_frame; + u16 host_us; + u16 host_interval; + u16 next_active_frame; u16 frame_usecs[8]; u16 start_split_frame; u16 ntd; @@ -651,7 +655,7 @@ static inline u16 dwc2_hcd_get_ep_bandwidth(struct dwc2_hsotg *hsotg, return 0; } - return qh->usecs; + return qh->host_us; } extern void dwc2_hcd_save_data_toggle(struct dwc2_hsotg *hsotg, diff --git a/drivers/usb/dwc2/hcd_ddma.c b/drivers/usb/dwc2/hcd_ddma.c index faca7aaec1a5..2ff517a0210f 100644 --- a/drivers/usb/dwc2/hcd_ddma.c +++ b/drivers/usb/dwc2/hcd_ddma.c @@ -81,7 +81,7 @@ static u16 dwc2_max_desc_num(struct dwc2_qh *qh) static u16 dwc2_frame_incr_val(struct dwc2_qh *qh) { return qh->dev_speed == USB_SPEED_HIGH ? - (qh->interval + 8 - 1) / 8 : qh->interval; + (qh->host_interval + 8 - 1) / 8 : qh->host_interval; } static int dwc2_desc_list_alloc(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh, @@ -252,7 +252,7 @@ static void dwc2_update_frame_list(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh, chan = qh->channel; inc = dwc2_frame_incr_val(qh); if (qh->ep_type == USB_ENDPOINT_XFER_ISOC) - i = dwc2_frame_list_idx(qh->sched_frame); + i = dwc2_frame_list_idx(qh->next_active_frame); else i = 0; @@ -278,13 +278,13 @@ static void dwc2_update_frame_list(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh, return; chan->schinfo = 0; - if (chan->speed == USB_SPEED_HIGH && qh->interval) { + if (chan->speed == USB_SPEED_HIGH && qh->host_interval) { j = 1; /* TODO - check this */ - inc = (8 + qh->interval - 1) / qh->interval; + inc = (8 + qh->host_interval - 1) / qh->host_interval; for (i = 0; i < inc; i++) { chan->schinfo |= j; - j = j << qh->interval; + j = j << qh->host_interval; } } else { chan->schinfo = 0xff; @@ -431,7 +431,10 @@ static u16 dwc2_calc_starting_frame(struct dwc2_hsotg *hsotg, hsotg->frame_number = dwc2_hcd_get_frame_number(hsotg); - /* sched_frame is always frame number (not uFrame) both in FS and HS! */ + /* + * next_active_frame is always frame number (not uFrame) both in FS + * and HS! + */ /* * skip_frames is used to limit activated descriptors number @@ -514,13 +517,13 @@ static u16 dwc2_recalc_initial_desc_idx(struct dwc2_hsotg *hsotg, */ fr_idx_tmp = dwc2_frame_list_idx(frame); fr_idx = (FRLISTEN_64_SIZE + - dwc2_frame_list_idx(qh->sched_frame) - fr_idx_tmp) - % dwc2_frame_incr_val(qh); + dwc2_frame_list_idx(qh->next_active_frame) - + fr_idx_tmp) % dwc2_frame_incr_val(qh); fr_idx = (fr_idx + fr_idx_tmp) % FRLISTEN_64_SIZE; } else { - qh->sched_frame = dwc2_calc_starting_frame(hsotg, qh, + qh->next_active_frame = dwc2_calc_starting_frame(hsotg, qh, &skip_frames); - fr_idx = dwc2_frame_list_idx(qh->sched_frame); + fr_idx = dwc2_frame_list_idx(qh->next_active_frame); } qh->td_first = qh->td_last = dwc2_frame_to_desc_idx(qh, fr_idx); @@ -583,7 +586,7 @@ static void dwc2_init_isoc_dma_desc(struct dwc2_hsotg *hsotg, u16 next_idx; idx = qh->td_last; - inc = qh->interval; + inc = qh->host_interval; hsotg->frame_number = dwc2_hcd_get_frame_number(hsotg); cur_idx = dwc2_frame_list_idx(hsotg->frame_number); next_idx = dwc2_desclist_idx_inc(qh->td_last, inc, qh->dev_speed); @@ -605,11 +608,11 @@ static void dwc2_init_isoc_dma_desc(struct dwc2_hsotg *hsotg, } } - if (qh->interval) { - ntd_max = (dwc2_max_desc_num(qh) + qh->interval - 1) / - qh->interval; + if (qh->host_interval) { + ntd_max = (dwc2_max_desc_num(qh) + qh->host_interval - 1) / + qh->host_interval; if (skip_frames && !qh->channel) - ntd_max -= skip_frames / qh->interval; + ntd_max -= skip_frames / qh->host_interval; } max_xfer_size = qh->dev_speed == USB_SPEED_HIGH ? @@ -1029,7 +1032,7 @@ static void dwc2_complete_isoc_xfer_ddma(struct dwc2_hsotg *hsotg, idx); if (rc < 0) return; - idx = dwc2_desclist_idx_inc(idx, qh->interval, + idx = dwc2_desclist_idx_inc(idx, qh->host_interval, chan->speed); if (!rc) continue; @@ -1039,7 +1042,7 @@ static void dwc2_complete_isoc_xfer_ddma(struct dwc2_hsotg *hsotg, /* rc == DWC2_CMPL_STOP */ - if (qh->interval >= 32) + if (qh->host_interval >= 32) goto stop_scan; qh->td_first = idx; diff --git a/drivers/usb/dwc2/hcd_intr.c b/drivers/usb/dwc2/hcd_intr.c index 3d686540d250..97aa6ca3a12e 100644 --- a/drivers/usb/dwc2/hcd_intr.c +++ b/drivers/usb/dwc2/hcd_intr.c @@ -148,9 +148,11 @@ static void dwc2_sof_intr(struct dwc2_hsotg *hsotg) while (qh_entry != &hsotg->periodic_sched_inactive) { qh = list_entry(qh_entry, struct dwc2_qh, qh_list_entry); qh_entry = qh_entry->next; - if (dwc2_frame_num_le(qh->sched_frame, hsotg->frame_number)) { - dwc2_sch_vdbg(hsotg, "QH=%p ready fn=%04x, sch=%04x\n", - qh, hsotg->frame_number, qh->sched_frame); + if (dwc2_frame_num_le(qh->next_active_frame, + hsotg->frame_number)) { + dwc2_sch_vdbg(hsotg, "QH=%p ready fn=%04x, nxt=%04x\n", + qh, hsotg->frame_number, + qh->next_active_frame); /* * Move QH to the ready list to be executed next @@ -1368,7 +1370,7 @@ static void dwc2_hc_nyet_intr(struct dwc2_hsotg *hsotg, int frnum = dwc2_hcd_get_frame_number(hsotg); if (dwc2_full_frame_num(frnum) != - dwc2_full_frame_num(chan->qh->sched_frame)) { + dwc2_full_frame_num(chan->qh->next_active_frame)) { /* * No longer in the same full speed frame. * Treat this as a transaction error. diff --git a/drivers/usb/dwc2/hcd_queue.c b/drivers/usb/dwc2/hcd_queue.c index b9e4867e1afd..39f4de6279f8 100644 --- a/drivers/usb/dwc2/hcd_queue.c +++ b/drivers/usb/dwc2/hcd_queue.c @@ -78,7 +78,7 @@ static void dwc2_do_unreserve(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) list_del_init(&qh->qh_list_entry); /* Update claimed usecs per (micro)frame */ - hsotg->periodic_usecs -= qh->usecs; + hsotg->periodic_usecs -= qh->host_us; if (hsotg->core_params->uframe_sched > 0) { int i; @@ -193,40 +193,40 @@ static void dwc2_qh_init(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh, int bytecount = dwc2_hb_mult(qh->maxp) * dwc2_max_packet(qh->maxp); - qh->usecs = NS_TO_US(usb_calc_bus_time(qh->do_split ? - USB_SPEED_HIGH : dev_speed, qh->ep_is_in, - qh->ep_type == USB_ENDPOINT_XFER_ISOC, - bytecount)); + qh->host_us = NS_TO_US(usb_calc_bus_time(qh->do_split ? + USB_SPEED_HIGH : dev_speed, qh->ep_is_in, + qh->ep_type == USB_ENDPOINT_XFER_ISOC, + bytecount)); /* Ensure frame_number corresponds to the reality */ hsotg->frame_number = dwc2_hcd_get_frame_number(hsotg); /* Start in a slightly future (micro)frame */ - qh->sched_frame = dwc2_frame_num_inc(hsotg->frame_number, + qh->next_active_frame = dwc2_frame_num_inc(hsotg->frame_number, SCHEDULE_SLOP); - qh->interval = urb->interval; - dwc2_sch_dbg(hsotg, "QH=%p init sch=%04x, fn=%04x, int=%#x\n", - qh, qh->sched_frame, hsotg->frame_number, - qh->interval); + qh->host_interval = urb->interval; + dwc2_sch_dbg(hsotg, "QH=%p init nxt=%04x, fn=%04x, int=%#x\n", + qh, qh->next_active_frame, hsotg->frame_number, + qh->host_interval); #if 0 /* Increase interrupt polling rate for debugging */ if (qh->ep_type == USB_ENDPOINT_XFER_INT) - qh->interval = 8; + qh->host_interval = 8; #endif hprt = dwc2_readl(hsotg->regs + HPRT0); prtspd = (hprt & HPRT0_SPD_MASK) >> HPRT0_SPD_SHIFT; if (prtspd == HPRT0_SPD_HIGH_SPEED && (dev_speed == USB_SPEED_LOW || dev_speed == USB_SPEED_FULL)) { - qh->interval *= 8; - qh->sched_frame |= 0x7; - qh->start_split_frame = qh->sched_frame; + qh->host_interval *= 8; + qh->next_active_frame |= 0x7; + qh->start_split_frame = qh->next_active_frame; dwc2_sch_dbg(hsotg, - "QH=%p init*8 sch=%04x, fn=%04x, int=%#x\n", - qh, qh->sched_frame, hsotg->frame_number, - qh->interval); + "QH=%p init*8 nxt=%04x, fn=%04x, int=%#x\n", + qh, qh->next_active_frame, + hsotg->frame_number, qh->host_interval); } - dev_dbg(hsotg->dev, "interval=%d\n", qh->interval); + dev_dbg(hsotg->dev, "interval=%d\n", qh->host_interval); } dev_vdbg(hsotg->dev, "DWC OTG HCD QH Initialized\n"); @@ -277,9 +277,9 @@ static void dwc2_qh_init(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh, if (qh->ep_type == USB_ENDPOINT_XFER_INT) { dev_vdbg(hsotg->dev, "DWC OTG HCD QH - usecs = %d\n", - qh->usecs); + qh->host_us); dev_vdbg(hsotg->dev, "DWC OTG HCD QH - interval = %d\n", - qh->interval); + qh->host_interval); } } @@ -404,19 +404,19 @@ static int dwc2_check_periodic_bandwidth(struct dwc2_hsotg *hsotg, * High speed mode * Max periodic usecs is 80% x 125 usec = 100 usec */ - max_claimed_usecs = 100 - qh->usecs; + max_claimed_usecs = 100 - qh->host_us; } else { /* * Full speed mode * Max periodic usecs is 90% x 1000 usec = 900 usec */ - max_claimed_usecs = 900 - qh->usecs; + max_claimed_usecs = 900 - qh->host_us; } if (hsotg->periodic_usecs > max_claimed_usecs) { dev_err(hsotg->dev, "%s: already claimed usecs %d, required usecs %d\n", - __func__, hsotg->periodic_usecs, qh->usecs); + __func__, hsotg->periodic_usecs, qh->host_us); status = -ENOSPC; } @@ -443,7 +443,7 @@ void dwc2_hcd_init_usecs(struct dwc2_hsotg *hsotg) static int dwc2_find_single_uframe(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) { - unsigned short utime = qh->usecs; + unsigned short utime = qh->host_us; int i; for (i = 0; i < 8; i++) { @@ -462,7 +462,7 @@ static int dwc2_find_single_uframe(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) */ static int dwc2_find_multi_uframe(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) { - unsigned short utime = qh->usecs; + unsigned short utime = qh->host_us; unsigned short xtime; int t_left; int i; @@ -608,11 +608,11 @@ static int dwc2_schedule_periodic(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) /* Set the new frame up */ if (frame >= 0) { - qh->sched_frame &= ~0x7; - qh->sched_frame |= (frame & 7); + qh->next_active_frame &= ~0x7; + qh->next_active_frame |= (frame & 7); dwc2_sch_dbg(hsotg, - "QH=%p sched_p sch=%04x, uf=%d\n", - qh, qh->sched_frame, frame); + "QH=%p sched_p nxt=%04x, uf=%d\n", + qh, qh->next_active_frame, frame); } if (status > 0) @@ -641,7 +641,7 @@ static int dwc2_schedule_periodic(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) hsotg->periodic_channels++; /* Update claimed usecs per (micro)frame */ - hsotg->periodic_usecs += qh->usecs; + hsotg->periodic_usecs += qh->host_us; } qh->unreserve_pending = 0; @@ -716,7 +716,7 @@ int dwc2_hcd_qh_add(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) /* QH already in a schedule */ return 0; - if (!dwc2_frame_num_le(qh->sched_frame, hsotg->frame_number) && + if (!dwc2_frame_num_le(qh->next_active_frame, hsotg->frame_number) && !hsotg->frame_number) { u16 new_frame; @@ -725,9 +725,9 @@ int dwc2_hcd_qh_add(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) new_frame = dwc2_frame_num_inc(hsotg->frame_number, SCHEDULE_SLOP); - dwc2_sch_vdbg(hsotg, "QH=%p reset sch=%04x=>%04x\n", - qh, qh->sched_frame, new_frame); - qh->sched_frame = new_frame; + dwc2_sch_vdbg(hsotg, "QH=%p reset nxt=%04x=>%04x\n", + qh, qh->next_active_frame, new_frame); + qh->next_active_frame = new_frame; } /* Add the new QH to the appropriate schedule */ @@ -793,10 +793,10 @@ static void dwc2_sched_periodic_split(struct dwc2_hsotg *hsotg, int sched_next_periodic_split) { u16 incr; - u16 old_frame = qh->sched_frame; + u16 old_frame = qh->next_active_frame; if (sched_next_periodic_split) { - qh->sched_frame = frame_number; + qh->next_active_frame = frame_number; incr = dwc2_frame_num_inc(qh->start_split_frame, 1); if (dwc2_frame_num_le(frame_number, incr)) { /* @@ -807,23 +807,24 @@ static void dwc2_sched_periodic_split(struct dwc2_hsotg *hsotg, */ if (qh->ep_type != USB_ENDPOINT_XFER_ISOC || qh->ep_is_in != 0) { - qh->sched_frame = - dwc2_frame_num_inc(qh->sched_frame, 1); + qh->next_active_frame = dwc2_frame_num_inc( + qh->next_active_frame, 1); } } } else { - qh->sched_frame = dwc2_frame_num_inc(qh->start_split_frame, - qh->interval); - if (dwc2_frame_num_le(qh->sched_frame, frame_number)) - qh->sched_frame = frame_number; - qh->sched_frame |= 0x7; - qh->start_split_frame = qh->sched_frame; + qh->next_active_frame = + dwc2_frame_num_inc(qh->start_split_frame, + qh->host_interval); + if (dwc2_frame_num_le(qh->next_active_frame, frame_number)) + qh->next_active_frame = frame_number; + qh->next_active_frame |= 0x7; + qh->start_split_frame = qh->next_active_frame; } - dwc2_sch_vdbg(hsotg, "QH=%p next(%d) fn=%04x, sch=%04x=>%04x (%+d)\n", + dwc2_sch_vdbg(hsotg, "QH=%p next(%d) fn=%04x, nxt=%04x=>%04x (%+d)\n", qh, sched_next_periodic_split, frame_number, old_frame, - qh->sched_frame, - dwc2_frame_num_dec(qh->sched_frame, old_frame)); + qh->next_active_frame, + dwc2_frame_num_dec(qh->next_active_frame, old_frame)); } /* @@ -861,10 +862,10 @@ void dwc2_hcd_qh_deactivate(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh, dwc2_sched_periodic_split(hsotg, qh, frame_number, sched_next_periodic_split); } else { - qh->sched_frame = dwc2_frame_num_inc(qh->sched_frame, - qh->interval); - if (dwc2_frame_num_le(qh->sched_frame, frame_number)) - qh->sched_frame = frame_number; + qh->next_active_frame = dwc2_frame_num_inc( + qh->next_active_frame, qh->host_interval); + if (dwc2_frame_num_le(qh->next_active_frame, frame_number)) + qh->next_active_frame = frame_number; } if (list_empty(&qh->qtd_list)) { @@ -876,9 +877,9 @@ void dwc2_hcd_qh_deactivate(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh, * appropriate queue */ if ((hsotg->core_params->uframe_sched > 0 && - dwc2_frame_num_le(qh->sched_frame, frame_number)) || + dwc2_frame_num_le(qh->next_active_frame, frame_number)) || (hsotg->core_params->uframe_sched <= 0 && - qh->sched_frame == frame_number)) + qh->next_active_frame == frame_number)) list_move_tail(&qh->qh_list_entry, &hsotg->periodic_sched_ready); else -- 2.39.5