Lines Matching refs:qh

75 static u16 dwc2_max_desc_num(struct dwc2_qh *qh)
77 return (qh->ep_type == USB_ENDPOINT_XFER_ISOC &&
78 qh->dev_speed == USB_SPEED_HIGH) ?
82 static u16 dwc2_frame_incr_val(struct dwc2_qh *qh)
84 return qh->dev_speed == USB_SPEED_HIGH ?
85 (qh->host_interval + 8 - 1) / 8 : qh->host_interval;
88 static int dwc2_desc_list_alloc(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh,
93 if (qh->ep_type == USB_ENDPOINT_XFER_ISOC &&
94 qh->dev_speed == USB_SPEED_HIGH)
99 qh->desc_list_sz = sizeof(struct dwc2_dma_desc) *
100 dwc2_max_desc_num(qh);
102 qh->desc_list = kmem_cache_zalloc(desc_cache, flags | GFP_DMA);
103 if (!qh->desc_list)
106 qh->desc_list_dma = dma_map_single(hsotg->dev, qh->desc_list,
107 qh->desc_list_sz,
110 qh->n_bytes = kcalloc(dwc2_max_desc_num(qh), sizeof(u32), flags);
111 if (!qh->n_bytes) {
112 dma_unmap_single(hsotg->dev, qh->desc_list_dma,
113 qh->desc_list_sz,
115 kmem_cache_free(desc_cache, qh->desc_list);
116 qh->desc_list = NULL;
123 static void dwc2_desc_list_free(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh)
127 if (qh->ep_type == USB_ENDPOINT_XFER_ISOC &&
128 qh->dev_speed == USB_SPEED_HIGH)
133 if (qh->desc_list) {
134 dma_unmap_single(hsotg->dev, qh->desc_list_dma,
135 qh->desc_list_sz, DMA_FROM_DEVICE);
136 kmem_cache_free(desc_cache, qh->desc_list);
137 qh->desc_list = NULL;
140 kfree(qh->n_bytes);
141 qh->n_bytes = NULL;
230 static void dwc2_update_frame_list(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh,
241 if (!qh->channel) {
242 dev_err(hsotg->dev, "qh->channel = %p\n", qh->channel);
252 chan = qh->channel;
253 inc = dwc2_frame_incr_val(qh);
254 if (qh->ep_type == USB_ENDPOINT_XFER_ISOC)
255 i = dwc2_frame_list_idx(qh->next_active_frame);
281 if (chan->speed == USB_SPEED_HIGH && qh->host_interval) {
284 inc = (8 + qh->host_interval - 1) / qh->host_interval;
287 j = j << qh->host_interval;
295 struct dwc2_qh *qh)
297 struct dwc2_host_chan *chan = qh->channel;
299 if (dwc2_qh_is_non_per(qh)) {
305 dwc2_update_frame_list(hsotg, qh, 0);
313 if (chan->qh) {
318 chan->qh = NULL;
321 qh->channel = NULL;
322 qh->ntd = 0;
324 if (qh->desc_list)
325 memset(qh->desc_list, 0, sizeof(struct dwc2_dma_desc) *
326 dwc2_max_desc_num(qh));
334 * @qh: The QH to init
342 int dwc2_hcd_qh_init_ddma(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh,
347 if (qh->do_split) {
354 retval = dwc2_desc_list_alloc(hsotg, qh, mem_flags);
358 if (qh->ep_type == USB_ENDPOINT_XFER_ISOC ||
359 qh->ep_type == USB_ENDPOINT_XFER_INT) {
369 qh->ntd = 0;
373 dwc2_desc_list_free(hsotg, qh);
383 * @qh: The QH to free
388 void dwc2_hcd_qh_free_ddma(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh)
392 dwc2_desc_list_free(hsotg, qh);
402 if (qh->channel)
403 dwc2_release_channel_ddma(hsotg, qh);
406 if ((qh->ep_type == USB_ENDPOINT_XFER_ISOC ||
407 qh->ep_type == USB_ENDPOINT_XFER_INT) &&
415 static u8 dwc2_frame_to_desc_idx(struct dwc2_qh *qh, u16 frame_idx)
417 if (qh->dev_speed == USB_SPEED_HIGH)
429 struct dwc2_qh *qh, u16 *skip_frames)
454 if (qh->dev_speed == USB_SPEED_HIGH) {
491 struct dwc2_qh *qh)
497 * when no more QTDs in the list (qh->ntd == 0). Thus this function is
498 * called only when qh->ntd == 0 and qh->channel == 0.
500 * So qh->channel != NULL branch is not used and just not removed from
513 if (qh->channel) {
514 frame = dwc2_calc_starting_frame(hsotg, qh, &skip_frames);
521 dwc2_frame_list_idx(qh->next_active_frame) -
522 fr_idx_tmp) % dwc2_frame_incr_val(qh);
525 qh->next_active_frame = dwc2_calc_starting_frame(hsotg, qh,
527 fr_idx = dwc2_frame_list_idx(qh->next_active_frame);
530 qh->td_first = qh->td_last = dwc2_frame_to_desc_idx(qh, fr_idx);
543 struct dwc2_qh *qh, u32 max_xfer_size,
546 struct dwc2_dma_desc *dma_desc = &qh->desc_list[idx];
553 qh->n_bytes[idx] = max_xfer_size;
555 qh->n_bytes[idx] = frame_desc->length;
558 dma_desc->status = qh->n_bytes[idx] << HOST_DMA_ISOC_NBYTES_SHIFT &
564 qh->ntd++;
574 qh->desc_list_dma +
581 struct dwc2_qh *qh, u16 skip_frames)
589 idx = qh->td_last;
590 inc = qh->host_interval;
593 next_idx = dwc2_desclist_idx_inc(qh->td_last, inc, qh->dev_speed);
598 * qh->td_last to current frame number + 1.
606 qh->td_last = dwc2_desclist_idx_inc(cur_idx, inc,
607 qh->dev_speed);
608 idx = qh->td_last;
612 if (qh->host_interval) {
613 ntd_max = (dwc2_max_desc_num(qh) + qh->host_interval - 1) /
614 qh->host_interval;
615 if (skip_frames && !qh->channel)
616 ntd_max -= skip_frames / qh->host_interval;
619 max_xfer_size = qh->dev_speed == USB_SPEED_HIGH ?
622 list_for_each_entry(qtd, &qh->qtd_list, qtd_list_entry) {
629 while (qh->ntd < ntd_max && qtd->isoc_frame_index_last <
631 dwc2_fill_host_isoc_dma_desc(hsotg, qtd, qh,
633 idx = dwc2_desclist_idx_inc(idx, inc, qh->dev_speed);
640 qh->td_last = idx;
644 if (qh->ntd == ntd_max) {
645 idx = dwc2_desclist_idx_dec(qh->td_last, inc, qh->dev_speed);
646 qh->desc_list[idx].status |= HOST_DMA_IOC;
648 qh->desc_list_dma + (idx *
670 idx = dwc2_desclist_idx_dec(idx, inc * ((qh->ntd + 1) / 2),
671 qh->dev_speed);
678 idx = dwc2_desclist_idx_dec(qh->td_last, inc, qh->dev_speed);
680 qh->desc_list[idx].status |= HOST_DMA_IOC;
682 qh->desc_list_dma +
691 struct dwc2_qtd *qtd, struct dwc2_qh *qh,
694 struct dwc2_dma_desc *dma_desc = &qh->desc_list[n_desc];
715 qh->n_bytes[n_desc] = len;
717 if (qh->ep_type == USB_ENDPOINT_XFER_CONTROL &&
724 qh->desc_list_dma +
742 struct dwc2_qh *qh)
745 struct dwc2_host_chan *chan = qh->channel;
748 dev_vdbg(hsotg->dev, "%s(): qh=%p dma=%08lx len=%d\n", __func__, qh,
758 list_for_each_entry(qtd, &qh->qtd_list, qtd_list_entry) {
774 qh->desc_list[n_desc - 1].status |= HOST_DMA_A;
778 &qh->desc_list[n_desc - 1]);
780 qh->desc_list_dma +
786 dwc2_fill_host_dma_desc(hsotg, chan, qtd, qh, n_desc);
789 n_desc, &qh->desc_list[n_desc],
790 qh->desc_list[n_desc].buf,
791 qh->desc_list[n_desc].status);
799 if (qh->ep_type == USB_ENDPOINT_XFER_CONTROL)
806 qh->desc_list[n_desc - 1].status |=
809 n_desc - 1, &qh->desc_list[n_desc - 1]);
811 qh->desc_list_dma + (n_desc - 1) *
816 qh->desc_list[0].status |= HOST_DMA_A;
818 &qh->desc_list[0]);
820 qh->desc_list_dma,
832 * @qh: The QH to init
847 void dwc2_hcd_start_xfer_ddma(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh)
850 struct dwc2_host_chan *chan = qh->channel;
856 dwc2_init_non_isoc_dma_desc(hsotg, qh);
860 dwc2_init_non_isoc_dma_desc(hsotg, qh);
861 dwc2_update_frame_list(hsotg, qh, 1);
865 if (!qh->ntd)
866 skip_frames = dwc2_recalc_initial_desc_idx(hsotg, qh);
867 dwc2_init_isoc_dma_desc(hsotg, qh, skip_frames);
870 dwc2_update_frame_list(hsotg, qh, 1);
877 chan->ntd = dwc2_max_desc_num(qh);
895 struct dwc2_qh *qh, u16 idx)
905 dma_sync_single_for_cpu(hsotg->dev, qh->desc_list_dma + (idx *
910 dma_desc = &qh->desc_list[idx];
925 frame_desc->actual_length = qh->n_bytes[idx] - remain;
929 frame_desc->actual_length = qh->n_bytes[idx] - remain;
939 dwc2_hcd_qtd_unlink_and_free(hsotg, qtd, qh);
952 qh->ntd--;
967 struct dwc2_qh *qh;
971 qh = chan->qh;
972 idx = qh->td_first;
975 list_for_each_entry(qtd, &qh->qtd_list, qtd_list_entry)
994 list_for_each_entry_safe(qtd, qtd_tmp, &qh->qtd_list,
1006 dwc2_hcd_qtd_unlink_and_free(hsotg, qtd, qh);
1012 list_for_each_entry_safe(qtd, qtd_tmp, &qh->qtd_list, qtd_list_entry) {
1032 rc = dwc2_cmpl_host_isoc_dma_desc(hsotg, chan, qtd, qh,
1036 idx = dwc2_desclist_idx_inc(idx, qh->host_interval,
1046 if (qh->host_interval >= 32)
1049 qh->td_first = idx;
1051 qtd_next = list_first_entry(&qh->qtd_list,
1060 } while (idx != qh->td_first);
1064 qh->td_first = idx;
1156 struct dwc2_qh *qh = chan->qh;
1168 qh->desc_list_dma + (desc_num *
1173 dma_desc = &qh->desc_list[desc_num];
1174 n_bytes = qh->n_bytes[desc_num];
1183 dwc2_hcd_qtd_unlink_and_free(hsotg, qtd, qh);
1189 if (qh->ep_type == USB_ENDPOINT_XFER_CONTROL) {
1227 struct dwc2_qh *qh = chan->qh;
1233 list_for_each_entry(qtd, &qh->qtd_list, qtd_list_entry)
1238 list_for_each_safe(qtd_item, qtd_tmp, &qh->qtd_list) {
1259 if (qh->ep_type != USB_ENDPOINT_XFER_CONTROL) {
1265 qh->data_toggle = DWC2_HC_PID_DATA0;
1277 qh->ping_state = 1;
1303 struct dwc2_qh *qh = chan->qh;
1312 list_empty(&qh->qtd_list)) {
1320 &qh->qtd_list,
1325 qtd, qh);
1331 dwc2_release_channel_ddma(hsotg, qh);
1332 dwc2_hcd_qh_unlink(hsotg, qh);
1335 list_move_tail(&qh->qh_list_entry,
1355 dwc2_release_channel_ddma(hsotg, qh);
1356 dwc2_hcd_qh_unlink(hsotg, qh);
1358 if (!list_empty(&qh->qtd_list)) {
1363 dwc2_hcd_qh_add(hsotg, qh);