Lines Matching refs:qh
45 static u16 dwc2_max_desc_num(struct dwc2_qh *qh) in dwc2_max_desc_num() argument
47 return (qh->ep_type == USB_ENDPOINT_XFER_ISOC && in dwc2_max_desc_num()
48 qh->dev_speed == USB_SPEED_HIGH) ? in dwc2_max_desc_num()
52 static u16 dwc2_frame_incr_val(struct dwc2_qh *qh) in dwc2_frame_incr_val() argument
54 return qh->dev_speed == USB_SPEED_HIGH ? in dwc2_frame_incr_val()
55 (qh->host_interval + 8 - 1) / 8 : qh->host_interval; in dwc2_frame_incr_val()
58 static int dwc2_desc_list_alloc(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh, in dwc2_desc_list_alloc() argument
63 if (qh->ep_type == USB_ENDPOINT_XFER_ISOC && in dwc2_desc_list_alloc()
64 qh->dev_speed == USB_SPEED_HIGH) in dwc2_desc_list_alloc()
69 qh->desc_list_sz = sizeof(struct dwc2_dma_desc) * in dwc2_desc_list_alloc()
70 dwc2_max_desc_num(qh); in dwc2_desc_list_alloc()
72 qh->desc_list = kmem_cache_zalloc(desc_cache, flags | GFP_DMA); in dwc2_desc_list_alloc()
73 if (!qh->desc_list) in dwc2_desc_list_alloc()
76 qh->desc_list_dma = dma_map_single(hsotg->dev, qh->desc_list, in dwc2_desc_list_alloc()
77 qh->desc_list_sz, in dwc2_desc_list_alloc()
80 qh->n_bytes = kcalloc(dwc2_max_desc_num(qh), sizeof(u32), flags); in dwc2_desc_list_alloc()
81 if (!qh->n_bytes) { in dwc2_desc_list_alloc()
82 dma_unmap_single(hsotg->dev, qh->desc_list_dma, in dwc2_desc_list_alloc()
83 qh->desc_list_sz, in dwc2_desc_list_alloc()
85 kmem_cache_free(desc_cache, qh->desc_list); in dwc2_desc_list_alloc()
86 qh->desc_list = NULL; in dwc2_desc_list_alloc()
93 static void dwc2_desc_list_free(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) in dwc2_desc_list_free() argument
97 if (qh->ep_type == USB_ENDPOINT_XFER_ISOC && in dwc2_desc_list_free()
98 qh->dev_speed == USB_SPEED_HIGH) in dwc2_desc_list_free()
103 if (qh->desc_list) { in dwc2_desc_list_free()
104 dma_unmap_single(hsotg->dev, qh->desc_list_dma, in dwc2_desc_list_free()
105 qh->desc_list_sz, DMA_FROM_DEVICE); in dwc2_desc_list_free()
106 kmem_cache_free(desc_cache, qh->desc_list); in dwc2_desc_list_free()
107 qh->desc_list = NULL; in dwc2_desc_list_free()
110 kfree(qh->n_bytes); in dwc2_desc_list_free()
111 qh->n_bytes = NULL; in dwc2_desc_list_free()
200 static void dwc2_update_frame_list(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh, in dwc2_update_frame_list() argument
211 if (!qh->channel) { in dwc2_update_frame_list()
212 dev_err(hsotg->dev, "qh->channel = %p\n", qh->channel); in dwc2_update_frame_list()
222 chan = qh->channel; in dwc2_update_frame_list()
223 inc = dwc2_frame_incr_val(qh); in dwc2_update_frame_list()
224 if (qh->ep_type == USB_ENDPOINT_XFER_ISOC) in dwc2_update_frame_list()
225 i = dwc2_frame_list_idx(qh->next_active_frame); in dwc2_update_frame_list()
251 if (chan->speed == USB_SPEED_HIGH && qh->host_interval) { in dwc2_update_frame_list()
254 inc = (8 + qh->host_interval - 1) / qh->host_interval; in dwc2_update_frame_list()
257 j = j << qh->host_interval; in dwc2_update_frame_list()
265 struct dwc2_qh *qh) in dwc2_release_channel_ddma() argument
267 struct dwc2_host_chan *chan = qh->channel; in dwc2_release_channel_ddma()
269 if (dwc2_qh_is_non_per(qh)) { in dwc2_release_channel_ddma()
275 dwc2_update_frame_list(hsotg, qh, 0); in dwc2_release_channel_ddma()
283 if (chan->qh) { in dwc2_release_channel_ddma()
288 chan->qh = NULL; in dwc2_release_channel_ddma()
291 qh->channel = NULL; in dwc2_release_channel_ddma()
292 qh->ntd = 0; in dwc2_release_channel_ddma()
294 if (qh->desc_list) in dwc2_release_channel_ddma()
295 memset(qh->desc_list, 0, sizeof(struct dwc2_dma_desc) * in dwc2_release_channel_ddma()
296 dwc2_max_desc_num(qh)); in dwc2_release_channel_ddma()
312 int dwc2_hcd_qh_init_ddma(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh, in dwc2_hcd_qh_init_ddma() argument
317 if (qh->do_split) { in dwc2_hcd_qh_init_ddma()
324 retval = dwc2_desc_list_alloc(hsotg, qh, mem_flags); in dwc2_hcd_qh_init_ddma()
328 if (qh->ep_type == USB_ENDPOINT_XFER_ISOC || in dwc2_hcd_qh_init_ddma()
329 qh->ep_type == USB_ENDPOINT_XFER_INT) { in dwc2_hcd_qh_init_ddma()
339 qh->ntd = 0; in dwc2_hcd_qh_init_ddma()
343 dwc2_desc_list_free(hsotg, qh); in dwc2_hcd_qh_init_ddma()
358 void dwc2_hcd_qh_free_ddma(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) in dwc2_hcd_qh_free_ddma() argument
362 dwc2_desc_list_free(hsotg, qh); in dwc2_hcd_qh_free_ddma()
372 if (qh->channel) in dwc2_hcd_qh_free_ddma()
373 dwc2_release_channel_ddma(hsotg, qh); in dwc2_hcd_qh_free_ddma()
376 if ((qh->ep_type == USB_ENDPOINT_XFER_ISOC || in dwc2_hcd_qh_free_ddma()
377 qh->ep_type == USB_ENDPOINT_XFER_INT) && in dwc2_hcd_qh_free_ddma()
385 static u8 dwc2_frame_to_desc_idx(struct dwc2_qh *qh, u16 frame_idx) in dwc2_frame_to_desc_idx() argument
387 if (qh->dev_speed == USB_SPEED_HIGH) in dwc2_frame_to_desc_idx()
399 struct dwc2_qh *qh, u16 *skip_frames) in dwc2_calc_starting_frame() argument
424 if (qh->dev_speed == USB_SPEED_HIGH) { in dwc2_calc_starting_frame()
461 struct dwc2_qh *qh) in dwc2_recalc_initial_desc_idx() argument
483 if (qh->channel) { in dwc2_recalc_initial_desc_idx()
484 frame = dwc2_calc_starting_frame(hsotg, qh, &skip_frames); in dwc2_recalc_initial_desc_idx()
491 dwc2_frame_list_idx(qh->next_active_frame) - in dwc2_recalc_initial_desc_idx()
492 fr_idx_tmp) % dwc2_frame_incr_val(qh); in dwc2_recalc_initial_desc_idx()
495 qh->next_active_frame = dwc2_calc_starting_frame(hsotg, qh, in dwc2_recalc_initial_desc_idx()
497 fr_idx = dwc2_frame_list_idx(qh->next_active_frame); in dwc2_recalc_initial_desc_idx()
500 qh->td_first = qh->td_last = dwc2_frame_to_desc_idx(qh, fr_idx); in dwc2_recalc_initial_desc_idx()
513 struct dwc2_qh *qh, u32 max_xfer_size, in dwc2_fill_host_isoc_dma_desc() argument
516 struct dwc2_dma_desc *dma_desc = &qh->desc_list[idx]; in dwc2_fill_host_isoc_dma_desc()
523 qh->n_bytes[idx] = max_xfer_size; in dwc2_fill_host_isoc_dma_desc()
525 qh->n_bytes[idx] = frame_desc->length; in dwc2_fill_host_isoc_dma_desc()
528 dma_desc->status = qh->n_bytes[idx] << HOST_DMA_ISOC_NBYTES_SHIFT & in dwc2_fill_host_isoc_dma_desc()
534 qh->ntd++; in dwc2_fill_host_isoc_dma_desc()
544 qh->desc_list_dma + in dwc2_fill_host_isoc_dma_desc()
551 struct dwc2_qh *qh, u16 skip_frames) in dwc2_init_isoc_dma_desc() argument
559 idx = qh->td_last; in dwc2_init_isoc_dma_desc()
560 inc = qh->host_interval; in dwc2_init_isoc_dma_desc()
563 next_idx = dwc2_desclist_idx_inc(qh->td_last, inc, qh->dev_speed); in dwc2_init_isoc_dma_desc()
576 qh->td_last = dwc2_desclist_idx_inc(cur_idx, inc, in dwc2_init_isoc_dma_desc()
577 qh->dev_speed); in dwc2_init_isoc_dma_desc()
578 idx = qh->td_last; in dwc2_init_isoc_dma_desc()
582 if (qh->host_interval) { in dwc2_init_isoc_dma_desc()
583 ntd_max = (dwc2_max_desc_num(qh) + qh->host_interval - 1) / in dwc2_init_isoc_dma_desc()
584 qh->host_interval; in dwc2_init_isoc_dma_desc()
585 if (skip_frames && !qh->channel) in dwc2_init_isoc_dma_desc()
586 ntd_max -= skip_frames / qh->host_interval; in dwc2_init_isoc_dma_desc()
589 max_xfer_size = qh->dev_speed == USB_SPEED_HIGH ? in dwc2_init_isoc_dma_desc()
592 list_for_each_entry(qtd, &qh->qtd_list, qtd_list_entry) { in dwc2_init_isoc_dma_desc()
599 while (qh->ntd < ntd_max && qtd->isoc_frame_index_last < in dwc2_init_isoc_dma_desc()
601 dwc2_fill_host_isoc_dma_desc(hsotg, qtd, qh, in dwc2_init_isoc_dma_desc()
603 idx = dwc2_desclist_idx_inc(idx, inc, qh->dev_speed); in dwc2_init_isoc_dma_desc()
610 qh->td_last = idx; in dwc2_init_isoc_dma_desc()
614 if (qh->ntd == ntd_max) { in dwc2_init_isoc_dma_desc()
615 idx = dwc2_desclist_idx_dec(qh->td_last, inc, qh->dev_speed); in dwc2_init_isoc_dma_desc()
616 qh->desc_list[idx].status |= HOST_DMA_IOC; in dwc2_init_isoc_dma_desc()
618 qh->desc_list_dma + (idx * in dwc2_init_isoc_dma_desc()
640 idx = dwc2_desclist_idx_dec(idx, inc * ((qh->ntd + 1) / 2), in dwc2_init_isoc_dma_desc()
641 qh->dev_speed); in dwc2_init_isoc_dma_desc()
648 idx = dwc2_desclist_idx_dec(qh->td_last, inc, qh->dev_speed); in dwc2_init_isoc_dma_desc()
650 qh->desc_list[idx].status |= HOST_DMA_IOC; in dwc2_init_isoc_dma_desc()
652 qh->desc_list_dma + in dwc2_init_isoc_dma_desc()
661 struct dwc2_qtd *qtd, struct dwc2_qh *qh, in dwc2_fill_host_dma_desc() argument
664 struct dwc2_dma_desc *dma_desc = &qh->desc_list[n_desc]; in dwc2_fill_host_dma_desc()
685 qh->n_bytes[n_desc] = len; in dwc2_fill_host_dma_desc()
687 if (qh->ep_type == USB_ENDPOINT_XFER_CONTROL && in dwc2_fill_host_dma_desc()
694 qh->desc_list_dma + in dwc2_fill_host_dma_desc()
712 struct dwc2_qh *qh) in dwc2_init_non_isoc_dma_desc() argument
715 struct dwc2_host_chan *chan = qh->channel; in dwc2_init_non_isoc_dma_desc()
718 dev_vdbg(hsotg->dev, "%s(): qh=%p dma=%08lx len=%d\n", __func__, qh, in dwc2_init_non_isoc_dma_desc()
728 list_for_each_entry(qtd, &qh->qtd_list, qtd_list_entry) { in dwc2_init_non_isoc_dma_desc()
744 qh->desc_list[n_desc - 1].status |= HOST_DMA_A; in dwc2_init_non_isoc_dma_desc()
748 &qh->desc_list[n_desc - 1]); in dwc2_init_non_isoc_dma_desc()
750 qh->desc_list_dma + in dwc2_init_non_isoc_dma_desc()
756 dwc2_fill_host_dma_desc(hsotg, chan, qtd, qh, n_desc); in dwc2_init_non_isoc_dma_desc()
759 n_desc, &qh->desc_list[n_desc], in dwc2_init_non_isoc_dma_desc()
760 qh->desc_list[n_desc].buf, in dwc2_init_non_isoc_dma_desc()
761 qh->desc_list[n_desc].status); in dwc2_init_non_isoc_dma_desc()
769 if (qh->ep_type == USB_ENDPOINT_XFER_CONTROL) in dwc2_init_non_isoc_dma_desc()
776 qh->desc_list[n_desc - 1].status |= in dwc2_init_non_isoc_dma_desc()
779 n_desc - 1, &qh->desc_list[n_desc - 1]); in dwc2_init_non_isoc_dma_desc()
781 qh->desc_list_dma + (n_desc - 1) * in dwc2_init_non_isoc_dma_desc()
786 qh->desc_list[0].status |= HOST_DMA_A; in dwc2_init_non_isoc_dma_desc()
788 &qh->desc_list[0]); in dwc2_init_non_isoc_dma_desc()
790 qh->desc_list_dma, in dwc2_init_non_isoc_dma_desc()
817 void dwc2_hcd_start_xfer_ddma(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) in dwc2_hcd_start_xfer_ddma() argument
820 struct dwc2_host_chan *chan = qh->channel; in dwc2_hcd_start_xfer_ddma()
826 dwc2_init_non_isoc_dma_desc(hsotg, qh); in dwc2_hcd_start_xfer_ddma()
830 dwc2_init_non_isoc_dma_desc(hsotg, qh); in dwc2_hcd_start_xfer_ddma()
831 dwc2_update_frame_list(hsotg, qh, 1); in dwc2_hcd_start_xfer_ddma()
835 if (!qh->ntd) in dwc2_hcd_start_xfer_ddma()
836 skip_frames = dwc2_recalc_initial_desc_idx(hsotg, qh); in dwc2_hcd_start_xfer_ddma()
837 dwc2_init_isoc_dma_desc(hsotg, qh, skip_frames); in dwc2_hcd_start_xfer_ddma()
840 dwc2_update_frame_list(hsotg, qh, 1); in dwc2_hcd_start_xfer_ddma()
847 chan->ntd = dwc2_max_desc_num(qh); in dwc2_hcd_start_xfer_ddma()
865 struct dwc2_qh *qh, u16 idx) in dwc2_cmpl_host_isoc_dma_desc() argument
879 dma_sync_single_for_cpu(hsotg->dev, qh->desc_list_dma + (idx * in dwc2_cmpl_host_isoc_dma_desc()
884 dma_desc = &qh->desc_list[idx]; in dwc2_cmpl_host_isoc_dma_desc()
902 frame_desc->actual_length = qh->n_bytes[idx] - remain; in dwc2_cmpl_host_isoc_dma_desc()
906 frame_desc->actual_length = qh->n_bytes[idx] - remain; in dwc2_cmpl_host_isoc_dma_desc()
916 dwc2_hcd_qtd_unlink_and_free(hsotg, qtd, qh); in dwc2_cmpl_host_isoc_dma_desc()
929 qh->ntd--; in dwc2_cmpl_host_isoc_dma_desc()
944 struct dwc2_qh *qh; in dwc2_complete_isoc_xfer_ddma() local
948 qh = chan->qh; in dwc2_complete_isoc_xfer_ddma()
949 idx = qh->td_first; in dwc2_complete_isoc_xfer_ddma()
952 list_for_each_entry(qtd, &qh->qtd_list, qtd_list_entry) in dwc2_complete_isoc_xfer_ddma()
971 list_for_each_entry_safe(qtd, qtd_tmp, &qh->qtd_list, in dwc2_complete_isoc_xfer_ddma()
983 dwc2_hcd_qtd_unlink_and_free(hsotg, qtd, qh); in dwc2_complete_isoc_xfer_ddma()
989 list_for_each_entry_safe(qtd, qtd_tmp, &qh->qtd_list, qtd_list_entry) { in dwc2_complete_isoc_xfer_ddma()
1009 rc = dwc2_cmpl_host_isoc_dma_desc(hsotg, chan, qtd, qh, in dwc2_complete_isoc_xfer_ddma()
1013 idx = dwc2_desclist_idx_inc(idx, qh->host_interval, in dwc2_complete_isoc_xfer_ddma()
1023 if (qh->host_interval >= 32) in dwc2_complete_isoc_xfer_ddma()
1026 qh->td_first = idx; in dwc2_complete_isoc_xfer_ddma()
1028 qtd_next = list_first_entry(&qh->qtd_list, in dwc2_complete_isoc_xfer_ddma()
1037 } while (idx != qh->td_first); in dwc2_complete_isoc_xfer_ddma()
1041 qh->td_first = idx; in dwc2_complete_isoc_xfer_ddma()
1133 struct dwc2_qh *qh = chan->qh; in dwc2_process_non_isoc_desc() local
1145 qh->desc_list_dma + (desc_num * in dwc2_process_non_isoc_desc()
1150 dma_desc = &qh->desc_list[desc_num]; in dwc2_process_non_isoc_desc()
1151 n_bytes = qh->n_bytes[desc_num]; in dwc2_process_non_isoc_desc()
1160 dwc2_hcd_qtd_unlink_and_free(hsotg, qtd, qh); in dwc2_process_non_isoc_desc()
1166 if (qh->ep_type == USB_ENDPOINT_XFER_CONTROL) { in dwc2_process_non_isoc_desc()
1204 struct dwc2_qh *qh = chan->qh; in dwc2_complete_non_isoc_xfer_ddma() local
1210 list_for_each_entry(qtd, &qh->qtd_list, qtd_list_entry) in dwc2_complete_non_isoc_xfer_ddma()
1215 list_for_each_safe(qtd_item, qtd_tmp, &qh->qtd_list) { in dwc2_complete_non_isoc_xfer_ddma()
1236 if (qh->ep_type != USB_ENDPOINT_XFER_CONTROL) { in dwc2_complete_non_isoc_xfer_ddma()
1242 qh->data_toggle = DWC2_HC_PID_DATA0; in dwc2_complete_non_isoc_xfer_ddma()
1254 qh->ping_state = 1; in dwc2_complete_non_isoc_xfer_ddma()
1280 struct dwc2_qh *qh = chan->qh; in dwc2_hcd_complete_xfer_ddma() local
1289 list_empty(&qh->qtd_list)) { in dwc2_hcd_complete_xfer_ddma()
1297 &qh->qtd_list, in dwc2_hcd_complete_xfer_ddma()
1302 qtd, qh); in dwc2_hcd_complete_xfer_ddma()
1308 dwc2_release_channel_ddma(hsotg, qh); in dwc2_hcd_complete_xfer_ddma()
1309 dwc2_hcd_qh_unlink(hsotg, qh); in dwc2_hcd_complete_xfer_ddma()
1312 list_move_tail(&qh->qh_list_entry, in dwc2_hcd_complete_xfer_ddma()
1332 dwc2_release_channel_ddma(hsotg, qh); in dwc2_hcd_complete_xfer_ddma()
1333 dwc2_hcd_qh_unlink(hsotg, qh); in dwc2_hcd_complete_xfer_ddma()
1335 if (!list_empty(&qh->qtd_list)) { in dwc2_hcd_complete_xfer_ddma()
1340 dwc2_hcd_qh_add(hsotg, qh); in dwc2_hcd_complete_xfer_ddma()