Lines Matching refs:qh
45 static u16 dwc2_max_desc_num(struct dwc2_qh *qh)
47 return (qh->ep_type == USB_ENDPOINT_XFER_ISOC &&
48 qh->dev_speed == USB_SPEED_HIGH) ?
52 static u16 dwc2_frame_incr_val(struct dwc2_qh *qh)
54 return qh->dev_speed == USB_SPEED_HIGH ?
55 (qh->host_interval + 8 - 1) / 8 : qh->host_interval;
58 static int dwc2_desc_list_alloc(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh,
63 if (qh->ep_type == USB_ENDPOINT_XFER_ISOC &&
64 qh->dev_speed == USB_SPEED_HIGH)
69 qh->desc_list_sz = sizeof(struct dwc2_dma_desc) *
70 dwc2_max_desc_num(qh);
72 qh->desc_list = kmem_cache_zalloc(desc_cache, flags | GFP_DMA);
73 if (!qh->desc_list)
76 qh->desc_list_dma = dma_map_single(hsotg->dev, qh->desc_list,
77 qh->desc_list_sz,
80 qh->n_bytes = kcalloc(dwc2_max_desc_num(qh), sizeof(u32), flags);
81 if (!qh->n_bytes) {
82 dma_unmap_single(hsotg->dev, qh->desc_list_dma,
83 qh->desc_list_sz,
85 kmem_cache_free(desc_cache, qh->desc_list);
86 qh->desc_list = NULL;
93 static void dwc2_desc_list_free(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh)
97 if (qh->ep_type == USB_ENDPOINT_XFER_ISOC &&
98 qh->dev_speed == USB_SPEED_HIGH)
103 if (qh->desc_list) {
104 dma_unmap_single(hsotg->dev, qh->desc_list_dma,
105 qh->desc_list_sz, DMA_FROM_DEVICE);
106 kmem_cache_free(desc_cache, qh->desc_list);
107 qh->desc_list = NULL;
110 kfree(qh->n_bytes);
111 qh->n_bytes = NULL;
200 static void dwc2_update_frame_list(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh,
211 if (!qh->channel) {
212 dev_err(hsotg->dev, "qh->channel = %p\n", qh->channel);
222 chan = qh->channel;
223 inc = dwc2_frame_incr_val(qh);
224 if (qh->ep_type == USB_ENDPOINT_XFER_ISOC)
225 i = dwc2_frame_list_idx(qh->next_active_frame);
251 if (chan->speed == USB_SPEED_HIGH && qh->host_interval) {
254 inc = (8 + qh->host_interval - 1) / qh->host_interval;
257 j = j << qh->host_interval;
265 struct dwc2_qh *qh)
267 struct dwc2_host_chan *chan = qh->channel;
269 if (dwc2_qh_is_non_per(qh)) {
275 dwc2_update_frame_list(hsotg, qh, 0);
283 if (chan->qh) {
288 chan->qh = NULL;
291 qh->channel = NULL;
292 qh->ntd = 0;
294 if (qh->desc_list)
295 memset(qh->desc_list, 0, sizeof(struct dwc2_dma_desc) *
296 dwc2_max_desc_num(qh));
304 * @qh: The QH to init
312 int dwc2_hcd_qh_init_ddma(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh,
317 if (qh->do_split) {
324 retval = dwc2_desc_list_alloc(hsotg, qh, mem_flags);
328 if (qh->ep_type == USB_ENDPOINT_XFER_ISOC ||
329 qh->ep_type == USB_ENDPOINT_XFER_INT) {
339 qh->ntd = 0;
343 dwc2_desc_list_free(hsotg, qh);
353 * @qh: The QH to free
358 void dwc2_hcd_qh_free_ddma(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh)
362 dwc2_desc_list_free(hsotg, qh);
372 if (qh->channel)
373 dwc2_release_channel_ddma(hsotg, qh);
376 if ((qh->ep_type == USB_ENDPOINT_XFER_ISOC ||
377 qh->ep_type == USB_ENDPOINT_XFER_INT) &&
385 static u8 dwc2_frame_to_desc_idx(struct dwc2_qh *qh, u16 frame_idx)
387 if (qh->dev_speed == USB_SPEED_HIGH)
399 struct dwc2_qh *qh, u16 *skip_frames)
424 if (qh->dev_speed == USB_SPEED_HIGH) {
461 struct dwc2_qh *qh)
467 * when no more QTDs in the list (qh->ntd == 0). Thus this function is
468 * called only when qh->ntd == 0 and qh->channel == 0.
470 * So qh->channel != NULL branch is not used and just not removed from
483 if (qh->channel) {
484 frame = dwc2_calc_starting_frame(hsotg, qh, &skip_frames);
491 dwc2_frame_list_idx(qh->next_active_frame) -
492 fr_idx_tmp) % dwc2_frame_incr_val(qh);
495 qh->next_active_frame = dwc2_calc_starting_frame(hsotg, qh,
497 fr_idx = dwc2_frame_list_idx(qh->next_active_frame);
500 qh->td_first = qh->td_last = dwc2_frame_to_desc_idx(qh, fr_idx);
513 struct dwc2_qh *qh, u32 max_xfer_size,
516 struct dwc2_dma_desc *dma_desc = &qh->desc_list[idx];
523 qh->n_bytes[idx] = max_xfer_size;
525 qh->n_bytes[idx] = frame_desc->length;
528 dma_desc->status = qh->n_bytes[idx] << HOST_DMA_ISOC_NBYTES_SHIFT &
534 qh->ntd++;
544 qh->desc_list_dma +
551 struct dwc2_qh *qh, u16 skip_frames)
559 idx = qh->td_last;
560 inc = qh->host_interval;
563 next_idx = dwc2_desclist_idx_inc(qh->td_last, inc, qh->dev_speed);
568 * qh->td_last to current frame number + 1.
576 qh->td_last = dwc2_desclist_idx_inc(cur_idx, inc,
577 qh->dev_speed);
578 idx = qh->td_last;
582 if (qh->host_interval) {
583 ntd_max = (dwc2_max_desc_num(qh) + qh->host_interval - 1) /
584 qh->host_interval;
585 if (skip_frames && !qh->channel)
586 ntd_max -= skip_frames / qh->host_interval;
589 max_xfer_size = qh->dev_speed == USB_SPEED_HIGH ?
592 list_for_each_entry(qtd, &qh->qtd_list, qtd_list_entry) {
599 while (qh->ntd < ntd_max && qtd->isoc_frame_index_last <
601 dwc2_fill_host_isoc_dma_desc(hsotg, qtd, qh,
603 idx = dwc2_desclist_idx_inc(idx, inc, qh->dev_speed);
610 qh->td_last = idx;
614 if (qh->ntd == ntd_max) {
615 idx = dwc2_desclist_idx_dec(qh->td_last, inc, qh->dev_speed);
616 qh->desc_list[idx].status |= HOST_DMA_IOC;
618 qh->desc_list_dma + (idx *
640 idx = dwc2_desclist_idx_dec(idx, inc * ((qh->ntd + 1) / 2),
641 qh->dev_speed);
648 idx = dwc2_desclist_idx_dec(qh->td_last, inc, qh->dev_speed);
650 qh->desc_list[idx].status |= HOST_DMA_IOC;
652 qh->desc_list_dma +
661 struct dwc2_qtd *qtd, struct dwc2_qh *qh,
664 struct dwc2_dma_desc *dma_desc = &qh->desc_list[n_desc];
685 qh->n_bytes[n_desc] = len;
687 if (qh->ep_type == USB_ENDPOINT_XFER_CONTROL &&
694 qh->desc_list_dma +
712 struct dwc2_qh *qh)
715 struct dwc2_host_chan *chan = qh->channel;
718 dev_vdbg(hsotg->dev, "%s(): qh=%p dma=%08lx len=%d\n", __func__, qh,
728 list_for_each_entry(qtd, &qh->qtd_list, qtd_list_entry) {
744 qh->desc_list[n_desc - 1].status |= HOST_DMA_A;
748 &qh->desc_list[n_desc - 1]);
750 qh->desc_list_dma +
756 dwc2_fill_host_dma_desc(hsotg, chan, qtd, qh, n_desc);
759 n_desc, &qh->desc_list[n_desc],
760 qh->desc_list[n_desc].buf,
761 qh->desc_list[n_desc].status);
769 if (qh->ep_type == USB_ENDPOINT_XFER_CONTROL)
776 qh->desc_list[n_desc - 1].status |=
779 n_desc - 1, &qh->desc_list[n_desc - 1]);
781 qh->desc_list_dma + (n_desc - 1) *
786 qh->desc_list[0].status |= HOST_DMA_A;
788 &qh->desc_list[0]);
790 qh->desc_list_dma,
802 * @qh: The QH to init
817 void dwc2_hcd_start_xfer_ddma(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh)
820 struct dwc2_host_chan *chan = qh->channel;
826 dwc2_init_non_isoc_dma_desc(hsotg, qh);
830 dwc2_init_non_isoc_dma_desc(hsotg, qh);
831 dwc2_update_frame_list(hsotg, qh, 1);
835 if (!qh->ntd)
836 skip_frames = dwc2_recalc_initial_desc_idx(hsotg, qh);
837 dwc2_init_isoc_dma_desc(hsotg, qh, skip_frames);
840 dwc2_update_frame_list(hsotg, qh, 1);
847 chan->ntd = dwc2_max_desc_num(qh);
865 struct dwc2_qh *qh, u16 idx)
875 dma_sync_single_for_cpu(hsotg->dev, qh->desc_list_dma + (idx *
880 dma_desc = &qh->desc_list[idx];
895 frame_desc->actual_length = qh->n_bytes[idx] - remain;
899 frame_desc->actual_length = qh->n_bytes[idx] - remain;
909 dwc2_hcd_qtd_unlink_and_free(hsotg, qtd, qh);
922 qh->ntd--;
937 struct dwc2_qh *qh;
941 qh = chan->qh;
942 idx = qh->td_first;
945 list_for_each_entry(qtd, &qh->qtd_list, qtd_list_entry)
964 list_for_each_entry_safe(qtd, qtd_tmp, &qh->qtd_list,
976 dwc2_hcd_qtd_unlink_and_free(hsotg, qtd, qh);
982 list_for_each_entry_safe(qtd, qtd_tmp, &qh->qtd_list, qtd_list_entry) {
1002 rc = dwc2_cmpl_host_isoc_dma_desc(hsotg, chan, qtd, qh,
1006 idx = dwc2_desclist_idx_inc(idx, qh->host_interval,
1016 if (qh->host_interval >= 32)
1019 qh->td_first = idx;
1021 qtd_next = list_first_entry(&qh->qtd_list,
1030 } while (idx != qh->td_first);
1034 qh->td_first = idx;
1126 struct dwc2_qh *qh = chan->qh;
1138 qh->desc_list_dma + (desc_num *
1143 dma_desc = &qh->desc_list[desc_num];
1144 n_bytes = qh->n_bytes[desc_num];
1153 dwc2_hcd_qtd_unlink_and_free(hsotg, qtd, qh);
1159 if (qh->ep_type == USB_ENDPOINT_XFER_CONTROL) {
1197 struct dwc2_qh *qh = chan->qh;
1203 list_for_each_entry(qtd, &qh->qtd_list, qtd_list_entry)
1208 list_for_each_safe(qtd_item, qtd_tmp, &qh->qtd_list) {
1229 if (qh->ep_type != USB_ENDPOINT_XFER_CONTROL) {
1235 qh->data_toggle = DWC2_HC_PID_DATA0;
1247 qh->ping_state = 1;
1273 struct dwc2_qh *qh = chan->qh;
1282 list_empty(&qh->qtd_list)) {
1290 &qh->qtd_list,
1295 qtd, qh);
1301 dwc2_release_channel_ddma(hsotg, qh);
1302 dwc2_hcd_qh_unlink(hsotg, qh);
1305 list_move_tail(&qh->qh_list_entry,
1325 dwc2_release_channel_ddma(hsotg, qh);
1326 dwc2_hcd_qh_unlink(hsotg, qh);
1328 if (!list_empty(&qh->qtd_list)) {
1333 dwc2_hcd_qh_add(hsotg, qh);