blob: 4b0be93dac6f72f6a681c2db1b3b1af5462926c9 [file] [log] [blame]
Paul Zimmermandc4c76e2013-03-11 17:48:00 -07001/*
2 * hcd_ddma.c - DesignWare HS OTG Controller descriptor DMA routines
3 *
4 * Copyright (C) 2004-2013 Synopsys, Inc.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer,
11 * without modification.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The names of the above-listed copyright holders may not be used
16 * to endorse or promote products derived from this software without
17 * specific prior written permission.
18 *
19 * ALTERNATIVELY, this software may be distributed under the terms of the
20 * GNU General Public License ("GPL") as published by the Free Software
21 * Foundation; either version 2 of the License, or (at your option) any
22 * later version.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
25 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
26 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
28 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 */
36
37/*
38 * This file contains the Descriptor DMA implementation for Host mode
39 */
40#include <linux/kernel.h>
41#include <linux/module.h>
42#include <linux/spinlock.h>
43#include <linux/interrupt.h>
44#include <linux/dma-mapping.h>
45#include <linux/io.h>
46#include <linux/slab.h>
47#include <linux/usb.h>
48
49#include <linux/usb/hcd.h>
50#include <linux/usb/ch11.h>
51
52#include "core.h"
53#include "hcd.h"
54
55static u16 dwc2_frame_list_idx(u16 frame)
56{
57 return frame & (FRLISTEN_64_SIZE - 1);
58}
59
60static u16 dwc2_desclist_idx_inc(u16 idx, u16 inc, u8 speed)
61{
62 return (idx + inc) &
63 ((speed == USB_SPEED_HIGH ? MAX_DMA_DESC_NUM_HS_ISOC :
64 MAX_DMA_DESC_NUM_GENERIC) - 1);
65}
66
67static u16 dwc2_desclist_idx_dec(u16 idx, u16 inc, u8 speed)
68{
69 return (idx - inc) &
70 ((speed == USB_SPEED_HIGH ? MAX_DMA_DESC_NUM_HS_ISOC :
71 MAX_DMA_DESC_NUM_GENERIC) - 1);
72}
73
74static u16 dwc2_max_desc_num(struct dwc2_qh *qh)
75{
76 return (qh->ep_type == USB_ENDPOINT_XFER_ISOC &&
77 qh->dev_speed == USB_SPEED_HIGH) ?
78 MAX_DMA_DESC_NUM_HS_ISOC : MAX_DMA_DESC_NUM_GENERIC;
79}
80
81static u16 dwc2_frame_incr_val(struct dwc2_qh *qh)
82{
83 return qh->dev_speed == USB_SPEED_HIGH ?
84 (qh->interval + 8 - 1) / 8 : qh->interval;
85}
86
87static int dwc2_desc_list_alloc(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh,
88 gfp_t flags)
89{
90 qh->desc_list = dma_alloc_coherent(hsotg->dev,
91 sizeof(struct dwc2_hcd_dma_desc) *
92 dwc2_max_desc_num(qh), &qh->desc_list_dma,
93 flags);
94
95 if (!qh->desc_list)
96 return -ENOMEM;
97
98 memset(qh->desc_list, 0,
99 sizeof(struct dwc2_hcd_dma_desc) * dwc2_max_desc_num(qh));
100
101 qh->n_bytes = kzalloc(sizeof(u32) * dwc2_max_desc_num(qh), flags);
102 if (!qh->n_bytes) {
103 dma_free_coherent(hsotg->dev, sizeof(struct dwc2_hcd_dma_desc)
104 * dwc2_max_desc_num(qh), qh->desc_list,
105 qh->desc_list_dma);
106 qh->desc_list = NULL;
107 return -ENOMEM;
108 }
109
110 return 0;
111}
112
113static void dwc2_desc_list_free(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh)
114{
115 if (qh->desc_list) {
116 dma_free_coherent(hsotg->dev, sizeof(struct dwc2_hcd_dma_desc)
117 * dwc2_max_desc_num(qh), qh->desc_list,
118 qh->desc_list_dma);
119 qh->desc_list = NULL;
120 }
121
122 kfree(qh->n_bytes);
123 qh->n_bytes = NULL;
124}
125
126static int dwc2_frame_list_alloc(struct dwc2_hsotg *hsotg, gfp_t mem_flags)
127{
128 if (hsotg->frame_list)
129 return 0;
130
131 hsotg->frame_list = dma_alloc_coherent(hsotg->dev,
132 4 * FRLISTEN_64_SIZE,
133 &hsotg->frame_list_dma,
134 mem_flags);
135 if (!hsotg->frame_list)
136 return -ENOMEM;
137
138 memset(hsotg->frame_list, 0, 4 * FRLISTEN_64_SIZE);
139 return 0;
140}
141
142static void dwc2_frame_list_free(struct dwc2_hsotg *hsotg)
143{
144 u32 *frame_list;
145 dma_addr_t frame_list_dma;
146 unsigned long flags;
147
148 spin_lock_irqsave(&hsotg->lock, flags);
149
150 if (!hsotg->frame_list) {
151 spin_unlock_irqrestore(&hsotg->lock, flags);
152 return;
153 }
154
155 frame_list = hsotg->frame_list;
156 frame_list_dma = hsotg->frame_list_dma;
157 hsotg->frame_list = NULL;
158
159 spin_unlock_irqrestore(&hsotg->lock, flags);
160
161 dma_free_coherent(hsotg->dev, 4 * FRLISTEN_64_SIZE, frame_list,
162 frame_list_dma);
163}
164
165static void dwc2_per_sched_enable(struct dwc2_hsotg *hsotg, u32 fr_list_en)
166{
167 u32 hcfg;
168 unsigned long flags;
169
170 spin_lock_irqsave(&hsotg->lock, flags);
171
Antti Seppälä95c8bc32015-08-20 21:41:07 +0300172 hcfg = dwc2_readl(hsotg->regs + HCFG);
Paul Zimmermandc4c76e2013-03-11 17:48:00 -0700173 if (hcfg & HCFG_PERSCHEDENA) {
174 /* already enabled */
175 spin_unlock_irqrestore(&hsotg->lock, flags);
176 return;
177 }
178
Antti Seppälä95c8bc32015-08-20 21:41:07 +0300179 dwc2_writel(hsotg->frame_list_dma, hsotg->regs + HFLBADDR);
Paul Zimmermandc4c76e2013-03-11 17:48:00 -0700180
181 hcfg &= ~HCFG_FRLISTEN_MASK;
182 hcfg |= fr_list_en | HCFG_PERSCHEDENA;
183 dev_vdbg(hsotg->dev, "Enabling Periodic schedule\n");
Antti Seppälä95c8bc32015-08-20 21:41:07 +0300184 dwc2_writel(hcfg, hsotg->regs + HCFG);
Paul Zimmermandc4c76e2013-03-11 17:48:00 -0700185
186 spin_unlock_irqrestore(&hsotg->lock, flags);
187}
188
189static void dwc2_per_sched_disable(struct dwc2_hsotg *hsotg)
190{
191 u32 hcfg;
192 unsigned long flags;
193
194 spin_lock_irqsave(&hsotg->lock, flags);
195
Antti Seppälä95c8bc32015-08-20 21:41:07 +0300196 hcfg = dwc2_readl(hsotg->regs + HCFG);
Paul Zimmermandc4c76e2013-03-11 17:48:00 -0700197 if (!(hcfg & HCFG_PERSCHEDENA)) {
198 /* already disabled */
199 spin_unlock_irqrestore(&hsotg->lock, flags);
200 return;
201 }
202
203 hcfg &= ~HCFG_PERSCHEDENA;
204 dev_vdbg(hsotg->dev, "Disabling Periodic schedule\n");
Antti Seppälä95c8bc32015-08-20 21:41:07 +0300205 dwc2_writel(hcfg, hsotg->regs + HCFG);
Paul Zimmermandc4c76e2013-03-11 17:48:00 -0700206
207 spin_unlock_irqrestore(&hsotg->lock, flags);
208}
209
210/*
211 * Activates/Deactivates FrameList entries for the channel based on endpoint
212 * servicing period
213 */
214static void dwc2_update_frame_list(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh,
215 int enable)
216{
217 struct dwc2_host_chan *chan;
218 u16 i, j, inc;
219
Paul Zimmermanddf58462013-04-22 14:00:16 -0700220 if (!hsotg) {
Paul Zimmermande9169a2013-04-22 14:00:17 -0700221 pr_err("hsotg = %p\n", hsotg);
Paul Zimmermanddf58462013-04-22 14:00:16 -0700222 return;
223 }
224
Paul Zimmermandc4c76e2013-03-11 17:48:00 -0700225 if (!qh->channel) {
Paul Zimmermande9169a2013-04-22 14:00:17 -0700226 dev_err(hsotg->dev, "qh->channel = %p\n", qh->channel);
Paul Zimmermandc4c76e2013-03-11 17:48:00 -0700227 return;
228 }
229
Paul Zimmermandc4c76e2013-03-11 17:48:00 -0700230 if (!hsotg->frame_list) {
Paul Zimmermande9169a2013-04-22 14:00:17 -0700231 dev_err(hsotg->dev, "hsotg->frame_list = %p\n",
Paul Zimmermandc4c76e2013-03-11 17:48:00 -0700232 hsotg->frame_list);
233 return;
234 }
235
236 chan = qh->channel;
237 inc = dwc2_frame_incr_val(qh);
238 if (qh->ep_type == USB_ENDPOINT_XFER_ISOC)
239 i = dwc2_frame_list_idx(qh->sched_frame);
240 else
241 i = 0;
242
243 j = i;
244 do {
245 if (enable)
246 hsotg->frame_list[j] |= 1 << chan->hc_num;
247 else
248 hsotg->frame_list[j] &= ~(1 << chan->hc_num);
249 j = (j + inc) & (FRLISTEN_64_SIZE - 1);
250 } while (j != i);
251
252 if (!enable)
253 return;
254
255 chan->schinfo = 0;
256 if (chan->speed == USB_SPEED_HIGH && qh->interval) {
257 j = 1;
258 /* TODO - check this */
259 inc = (8 + qh->interval - 1) / qh->interval;
260 for (i = 0; i < inc; i++) {
261 chan->schinfo |= j;
262 j = j << qh->interval;
263 }
264 } else {
265 chan->schinfo = 0xff;
266 }
267}
268
269static void dwc2_release_channel_ddma(struct dwc2_hsotg *hsotg,
270 struct dwc2_qh *qh)
271{
272 struct dwc2_host_chan *chan = qh->channel;
273
Dom Cobley20f2eb92013-09-23 14:23:34 -0700274 if (dwc2_qh_is_non_per(qh)) {
275 if (hsotg->core_params->uframe_sched > 0)
276 hsotg->available_host_channels++;
277 else
278 hsotg->non_periodic_channels--;
279 } else {
Paul Zimmermandc4c76e2013-03-11 17:48:00 -0700280 dwc2_update_frame_list(hsotg, qh, 0);
Dom Cobley20f2eb92013-09-23 14:23:34 -0700281 }
Paul Zimmermandc4c76e2013-03-11 17:48:00 -0700282
283 /*
284 * The condition is added to prevent double cleanup try in case of
285 * device disconnect. See channel cleanup in dwc2_hcd_disconnect().
286 */
287 if (chan->qh) {
288 if (!list_empty(&chan->hc_list_entry))
289 list_del(&chan->hc_list_entry);
290 dwc2_hc_cleanup(hsotg, chan);
291 list_add_tail(&chan->hc_list_entry, &hsotg->free_hc_list);
292 chan->qh = NULL;
293 }
294
295 qh->channel = NULL;
296 qh->ntd = 0;
297
298 if (qh->desc_list)
299 memset(qh->desc_list, 0, sizeof(struct dwc2_hcd_dma_desc) *
300 dwc2_max_desc_num(qh));
301}
302
303/**
304 * dwc2_hcd_qh_init_ddma() - Initializes a QH structure's Descriptor DMA
305 * related members
306 *
307 * @hsotg: The HCD state structure for the DWC OTG controller
308 * @qh: The QH to init
309 *
310 * Return: 0 if successful, negative error code otherwise
311 *
312 * Allocates memory for the descriptor list. For the first periodic QH,
313 * allocates memory for the FrameList and enables periodic scheduling.
314 */
315int dwc2_hcd_qh_init_ddma(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh,
316 gfp_t mem_flags)
317{
318 int retval;
319
320 if (qh->do_split) {
321 dev_err(hsotg->dev,
322 "SPLIT Transfers are not supported in Descriptor DMA mode.\n");
323 retval = -EINVAL;
324 goto err0;
325 }
326
327 retval = dwc2_desc_list_alloc(hsotg, qh, mem_flags);
328 if (retval)
329 goto err0;
330
331 if (qh->ep_type == USB_ENDPOINT_XFER_ISOC ||
332 qh->ep_type == USB_ENDPOINT_XFER_INT) {
333 if (!hsotg->frame_list) {
334 retval = dwc2_frame_list_alloc(hsotg, mem_flags);
335 if (retval)
336 goto err1;
337 /* Enable periodic schedule on first periodic QH */
338 dwc2_per_sched_enable(hsotg, HCFG_FRLISTEN_64);
339 }
340 }
341
342 qh->ntd = 0;
343 return 0;
344
345err1:
346 dwc2_desc_list_free(hsotg, qh);
347err0:
348 return retval;
349}
350
351/**
352 * dwc2_hcd_qh_free_ddma() - Frees a QH structure's Descriptor DMA related
353 * members
354 *
355 * @hsotg: The HCD state structure for the DWC OTG controller
356 * @qh: The QH to free
357 *
358 * Frees descriptor list memory associated with the QH. If QH is periodic and
359 * the last, frees FrameList memory and disables periodic scheduling.
360 */
361void dwc2_hcd_qh_free_ddma(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh)
362{
363 dwc2_desc_list_free(hsotg, qh);
364
365 /*
366 * Channel still assigned due to some reasons.
367 * Seen on Isoc URB dequeue. Channel halted but no subsequent
368 * ChHalted interrupt to release the channel. Afterwards
369 * when it comes here from endpoint disable routine
370 * channel remains assigned.
371 */
372 if (qh->channel)
373 dwc2_release_channel_ddma(hsotg, qh);
374
375 if ((qh->ep_type == USB_ENDPOINT_XFER_ISOC ||
376 qh->ep_type == USB_ENDPOINT_XFER_INT) &&
Dom Cobley20f2eb92013-09-23 14:23:34 -0700377 (hsotg->core_params->uframe_sched > 0 ||
378 !hsotg->periodic_channels) && hsotg->frame_list) {
Paul Zimmermandc4c76e2013-03-11 17:48:00 -0700379 dwc2_per_sched_disable(hsotg);
380 dwc2_frame_list_free(hsotg);
381 }
382}
383
384static u8 dwc2_frame_to_desc_idx(struct dwc2_qh *qh, u16 frame_idx)
385{
386 if (qh->dev_speed == USB_SPEED_HIGH)
387 /* Descriptor set (8 descriptors) index which is 8-aligned */
388 return (frame_idx & ((MAX_DMA_DESC_NUM_HS_ISOC / 8) - 1)) * 8;
389 else
390 return frame_idx & (MAX_DMA_DESC_NUM_GENERIC - 1);
391}
392
393/*
394 * Determine starting frame for Isochronous transfer.
395 * Few frames skipped to prevent race condition with HC.
396 */
397static u16 dwc2_calc_starting_frame(struct dwc2_hsotg *hsotg,
398 struct dwc2_qh *qh, u16 *skip_frames)
399{
400 u16 frame;
401
402 hsotg->frame_number = dwc2_hcd_get_frame_number(hsotg);
403
404 /* sched_frame is always frame number (not uFrame) both in FS and HS! */
405
406 /*
407 * skip_frames is used to limit activated descriptors number
408 * to avoid the situation when HC services the last activated
409 * descriptor firstly.
410 * Example for FS:
411 * Current frame is 1, scheduled frame is 3. Since HC always fetches
412 * the descriptor corresponding to curr_frame+1, the descriptor
413 * corresponding to frame 2 will be fetched. If the number of
414 * descriptors is max=64 (or greather) the list will be fully programmed
415 * with Active descriptors and it is possible case (rare) that the
416 * latest descriptor(considering rollback) corresponding to frame 2 will
417 * be serviced first. HS case is more probable because, in fact, up to
418 * 11 uframes (16 in the code) may be skipped.
419 */
420 if (qh->dev_speed == USB_SPEED_HIGH) {
421 /*
422 * Consider uframe counter also, to start xfer asap. If half of
423 * the frame elapsed skip 2 frames otherwise just 1 frame.
424 * Starting descriptor index must be 8-aligned, so if the
425 * current frame is near to complete the next one is skipped as
426 * well.
427 */
428 if (dwc2_micro_frame_num(hsotg->frame_number) >= 5) {
429 *skip_frames = 2 * 8;
430 frame = dwc2_frame_num_inc(hsotg->frame_number,
431 *skip_frames);
432 } else {
433 *skip_frames = 1 * 8;
434 frame = dwc2_frame_num_inc(hsotg->frame_number,
435 *skip_frames);
436 }
437
438 frame = dwc2_full_frame_num(frame);
439 } else {
440 /*
441 * Two frames are skipped for FS - the current and the next.
442 * But for descriptor programming, 1 frame (descriptor) is
443 * enough, see example above.
444 */
445 *skip_frames = 1;
446 frame = dwc2_frame_num_inc(hsotg->frame_number, 2);
447 }
448
449 return frame;
450}
451
452/*
453 * Calculate initial descriptor index for isochronous transfer based on
454 * scheduled frame
455 */
456static u16 dwc2_recalc_initial_desc_idx(struct dwc2_hsotg *hsotg,
457 struct dwc2_qh *qh)
458{
459 u16 frame, fr_idx, fr_idx_tmp, skip_frames;
460
461 /*
462 * With current ISOC processing algorithm the channel is being released
463 * when no more QTDs in the list (qh->ntd == 0). Thus this function is
464 * called only when qh->ntd == 0 and qh->channel == 0.
465 *
466 * So qh->channel != NULL branch is not used and just not removed from
467 * the source file. It is required for another possible approach which
468 * is, do not disable and release the channel when ISOC session
469 * completed, just move QH to inactive schedule until new QTD arrives.
470 * On new QTD, the QH moved back to 'ready' schedule, starting frame and
471 * therefore starting desc_index are recalculated. In this case channel
472 * is released only on ep_disable.
473 */
474
475 /*
476 * Calculate starting descriptor index. For INTERRUPT endpoint it is
477 * always 0.
478 */
479 if (qh->channel) {
480 frame = dwc2_calc_starting_frame(hsotg, qh, &skip_frames);
481 /*
482 * Calculate initial descriptor index based on FrameList current
483 * bitmap and servicing period
484 */
485 fr_idx_tmp = dwc2_frame_list_idx(frame);
486 fr_idx = (FRLISTEN_64_SIZE +
487 dwc2_frame_list_idx(qh->sched_frame) - fr_idx_tmp)
488 % dwc2_frame_incr_val(qh);
489 fr_idx = (fr_idx + fr_idx_tmp) % FRLISTEN_64_SIZE;
490 } else {
491 qh->sched_frame = dwc2_calc_starting_frame(hsotg, qh,
492 &skip_frames);
493 fr_idx = dwc2_frame_list_idx(qh->sched_frame);
494 }
495
496 qh->td_first = qh->td_last = dwc2_frame_to_desc_idx(qh, fr_idx);
497
498 return skip_frames;
499}
500
501#define ISOC_URB_GIVEBACK_ASAP
502
503#define MAX_ISOC_XFER_SIZE_FS 1023
504#define MAX_ISOC_XFER_SIZE_HS 3072
505#define DESCNUM_THRESHOLD 4
506
507static void dwc2_fill_host_isoc_dma_desc(struct dwc2_hsotg *hsotg,
508 struct dwc2_qtd *qtd,
509 struct dwc2_qh *qh, u32 max_xfer_size,
510 u16 idx)
511{
512 struct dwc2_hcd_dma_desc *dma_desc = &qh->desc_list[idx];
513 struct dwc2_hcd_iso_packet_desc *frame_desc;
514
515 memset(dma_desc, 0, sizeof(*dma_desc));
516 frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index_last];
517
518 if (frame_desc->length > max_xfer_size)
519 qh->n_bytes[idx] = max_xfer_size;
520 else
521 qh->n_bytes[idx] = frame_desc->length;
522
523 dma_desc->buf = (u32)(qtd->urb->dma + frame_desc->offset);
524 dma_desc->status = qh->n_bytes[idx] << HOST_DMA_ISOC_NBYTES_SHIFT &
525 HOST_DMA_ISOC_NBYTES_MASK;
526
Gregory Herrero3ac38d22015-11-05 09:41:37 +0100527 qh->ntd++;
528 qtd->isoc_frame_index_last++;
529
Paul Zimmermandc4c76e2013-03-11 17:48:00 -0700530#ifdef ISOC_URB_GIVEBACK_ASAP
531 /* Set IOC for each descriptor corresponding to last frame of URB */
532 if (qtd->isoc_frame_index_last == qtd->urb->packet_count)
533 dma_desc->status |= HOST_DMA_IOC;
534#endif
535
Paul Zimmermandc4c76e2013-03-11 17:48:00 -0700536}
537
538static void dwc2_init_isoc_dma_desc(struct dwc2_hsotg *hsotg,
539 struct dwc2_qh *qh, u16 skip_frames)
540{
541 struct dwc2_qtd *qtd;
542 u32 max_xfer_size;
543 u16 idx, inc, n_desc, ntd_max = 0;
544
545 idx = qh->td_last;
546 inc = qh->interval;
547 n_desc = 0;
548
549 if (qh->interval) {
550 ntd_max = (dwc2_max_desc_num(qh) + qh->interval - 1) /
551 qh->interval;
552 if (skip_frames && !qh->channel)
553 ntd_max -= skip_frames / qh->interval;
554 }
555
556 max_xfer_size = qh->dev_speed == USB_SPEED_HIGH ?
557 MAX_ISOC_XFER_SIZE_HS : MAX_ISOC_XFER_SIZE_FS;
558
559 list_for_each_entry(qtd, &qh->qtd_list, qtd_list_entry) {
560 while (qh->ntd < ntd_max && qtd->isoc_frame_index_last <
561 qtd->urb->packet_count) {
562 if (n_desc > 1)
563 qh->desc_list[n_desc - 1].status |= HOST_DMA_A;
564 dwc2_fill_host_isoc_dma_desc(hsotg, qtd, qh,
565 max_xfer_size, idx);
566 idx = dwc2_desclist_idx_inc(idx, inc, qh->dev_speed);
567 n_desc++;
568 }
569 qtd->in_process = 1;
570 }
571
572 qh->td_last = idx;
573
574#ifdef ISOC_URB_GIVEBACK_ASAP
575 /* Set IOC for last descriptor if descriptor list is full */
576 if (qh->ntd == ntd_max) {
577 idx = dwc2_desclist_idx_dec(qh->td_last, inc, qh->dev_speed);
578 qh->desc_list[idx].status |= HOST_DMA_IOC;
579 }
580#else
581 /*
582 * Set IOC bit only for one descriptor. Always try to be ahead of HW
583 * processing, i.e. on IOC generation driver activates next descriptor
584 * but core continues to process descriptors following the one with IOC
585 * set.
586 */
587
588 if (n_desc > DESCNUM_THRESHOLD)
589 /*
590 * Move IOC "up". Required even if there is only one QTD
591 * in the list, because QTDs might continue to be queued,
592 * but during the activation it was only one queued.
593 * Actually more than one QTD might be in the list if this
594 * function called from XferCompletion - QTDs was queued during
595 * HW processing of the previous descriptor chunk.
596 */
597 idx = dwc2_desclist_idx_dec(idx, inc * ((qh->ntd + 1) / 2),
598 qh->dev_speed);
599 else
600 /*
601 * Set the IOC for the latest descriptor if either number of
602 * descriptors is not greater than threshold or no more new
603 * descriptors activated
604 */
605 idx = dwc2_desclist_idx_dec(qh->td_last, inc, qh->dev_speed);
606
607 qh->desc_list[idx].status |= HOST_DMA_IOC;
608#endif
609
610 if (n_desc) {
611 qh->desc_list[n_desc - 1].status |= HOST_DMA_A;
612 if (n_desc > 1)
613 qh->desc_list[0].status |= HOST_DMA_A;
614 }
615}
616
617static void dwc2_fill_host_dma_desc(struct dwc2_hsotg *hsotg,
618 struct dwc2_host_chan *chan,
619 struct dwc2_qtd *qtd, struct dwc2_qh *qh,
620 int n_desc)
621{
622 struct dwc2_hcd_dma_desc *dma_desc = &qh->desc_list[n_desc];
623 int len = chan->xfer_len;
624
Paul Zimmerman0b851be2013-11-25 13:42:45 -0800625 if (len > MAX_DMA_DESC_SIZE - (chan->max_packet - 1))
626 len = MAX_DMA_DESC_SIZE - (chan->max_packet - 1);
Paul Zimmermandc4c76e2013-03-11 17:48:00 -0700627
628 if (chan->ep_is_in) {
629 int num_packets;
630
631 if (len > 0 && chan->max_packet)
632 num_packets = (len + chan->max_packet - 1)
633 / chan->max_packet;
634 else
635 /* Need 1 packet for transfer length of 0 */
636 num_packets = 1;
637
638 /* Always program an integral # of packets for IN transfers */
639 len = num_packets * chan->max_packet;
640 }
641
642 dma_desc->status = len << HOST_DMA_NBYTES_SHIFT & HOST_DMA_NBYTES_MASK;
643 qh->n_bytes[n_desc] = len;
644
645 if (qh->ep_type == USB_ENDPOINT_XFER_CONTROL &&
646 qtd->control_phase == DWC2_CONTROL_SETUP)
647 dma_desc->status |= HOST_DMA_SUP;
648
649 dma_desc->buf = (u32)chan->xfer_dma;
650
651 /*
652 * Last (or only) descriptor of IN transfer with actual size less
653 * than MaxPacket
654 */
655 if (len > chan->xfer_len) {
656 chan->xfer_len = 0;
657 } else {
658 chan->xfer_dma += len;
659 chan->xfer_len -= len;
660 }
661}
662
663static void dwc2_init_non_isoc_dma_desc(struct dwc2_hsotg *hsotg,
664 struct dwc2_qh *qh)
665{
666 struct dwc2_qtd *qtd;
667 struct dwc2_host_chan *chan = qh->channel;
668 int n_desc = 0;
669
670 dev_vdbg(hsotg->dev, "%s(): qh=%p dma=%08lx len=%d\n", __func__, qh,
671 (unsigned long)chan->xfer_dma, chan->xfer_len);
672
673 /*
674 * Start with chan->xfer_dma initialized in assign_and_init_hc(), then
675 * if SG transfer consists of multiple URBs, this pointer is re-assigned
676 * to the buffer of the currently processed QTD. For non-SG request
677 * there is always one QTD active.
678 */
679
680 list_for_each_entry(qtd, &qh->qtd_list, qtd_list_entry) {
681 dev_vdbg(hsotg->dev, "qtd=%p\n", qtd);
682
683 if (n_desc) {
684 /* SG request - more than 1 QTD */
685 chan->xfer_dma = qtd->urb->dma +
686 qtd->urb->actual_length;
687 chan->xfer_len = qtd->urb->length -
688 qtd->urb->actual_length;
689 dev_vdbg(hsotg->dev, "buf=%08lx len=%d\n",
690 (unsigned long)chan->xfer_dma, chan->xfer_len);
691 }
692
693 qtd->n_desc = 0;
694 do {
695 if (n_desc > 1) {
696 qh->desc_list[n_desc - 1].status |= HOST_DMA_A;
697 dev_vdbg(hsotg->dev,
698 "set A bit in desc %d (%p)\n",
699 n_desc - 1,
700 &qh->desc_list[n_desc - 1]);
701 }
702 dwc2_fill_host_dma_desc(hsotg, chan, qtd, qh, n_desc);
703 dev_vdbg(hsotg->dev,
704 "desc %d (%p) buf=%08x status=%08x\n",
705 n_desc, &qh->desc_list[n_desc],
706 qh->desc_list[n_desc].buf,
707 qh->desc_list[n_desc].status);
708 qtd->n_desc++;
709 n_desc++;
710 } while (chan->xfer_len > 0 &&
711 n_desc != MAX_DMA_DESC_NUM_GENERIC);
712
713 dev_vdbg(hsotg->dev, "n_desc=%d\n", n_desc);
714 qtd->in_process = 1;
715 if (qh->ep_type == USB_ENDPOINT_XFER_CONTROL)
716 break;
717 if (n_desc == MAX_DMA_DESC_NUM_GENERIC)
718 break;
719 }
720
721 if (n_desc) {
722 qh->desc_list[n_desc - 1].status |=
723 HOST_DMA_IOC | HOST_DMA_EOL | HOST_DMA_A;
724 dev_vdbg(hsotg->dev, "set IOC/EOL/A bits in desc %d (%p)\n",
725 n_desc - 1, &qh->desc_list[n_desc - 1]);
726 if (n_desc > 1) {
727 qh->desc_list[0].status |= HOST_DMA_A;
728 dev_vdbg(hsotg->dev, "set A bit in desc 0 (%p)\n",
729 &qh->desc_list[0]);
730 }
731 chan->ntd = n_desc;
732 }
733}
734
735/**
736 * dwc2_hcd_start_xfer_ddma() - Starts a transfer in Descriptor DMA mode
737 *
738 * @hsotg: The HCD state structure for the DWC OTG controller
739 * @qh: The QH to init
740 *
741 * Return: 0 if successful, negative error code otherwise
742 *
743 * For Control and Bulk endpoints, initializes descriptor list and starts the
744 * transfer. For Interrupt and Isochronous endpoints, initializes descriptor
745 * list then updates FrameList, marking appropriate entries as active.
746 *
747 * For Isochronous endpoints the starting descriptor index is calculated based
748 * on the scheduled frame, but only on the first transfer descriptor within a
749 * session. Then the transfer is started via enabling the channel.
750 *
751 * For Isochronous endpoints the channel is not halted on XferComplete
752 * interrupt so remains assigned to the endpoint(QH) until session is done.
753 */
754void dwc2_hcd_start_xfer_ddma(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh)
755{
756 /* Channel is already assigned */
757 struct dwc2_host_chan *chan = qh->channel;
758 u16 skip_frames = 0;
759
760 switch (chan->ep_type) {
761 case USB_ENDPOINT_XFER_CONTROL:
762 case USB_ENDPOINT_XFER_BULK:
763 dwc2_init_non_isoc_dma_desc(hsotg, qh);
764 dwc2_hc_start_transfer_ddma(hsotg, chan);
765 break;
766 case USB_ENDPOINT_XFER_INT:
767 dwc2_init_non_isoc_dma_desc(hsotg, qh);
768 dwc2_update_frame_list(hsotg, qh, 1);
769 dwc2_hc_start_transfer_ddma(hsotg, chan);
770 break;
771 case USB_ENDPOINT_XFER_ISOC:
772 if (!qh->ntd)
773 skip_frames = dwc2_recalc_initial_desc_idx(hsotg, qh);
774 dwc2_init_isoc_dma_desc(hsotg, qh, skip_frames);
775
776 if (!chan->xfer_started) {
777 dwc2_update_frame_list(hsotg, qh, 1);
778
779 /*
780 * Always set to max, instead of actual size. Otherwise
781 * ntd will be changed with channel being enabled. Not
782 * recommended.
783 */
784 chan->ntd = dwc2_max_desc_num(qh);
785
786 /* Enable channel only once for ISOC */
787 dwc2_hc_start_transfer_ddma(hsotg, chan);
788 }
789
790 break;
791 default:
792 break;
793 }
794}
795
796#define DWC2_CMPL_DONE 1
797#define DWC2_CMPL_STOP 2
798
799static int dwc2_cmpl_host_isoc_dma_desc(struct dwc2_hsotg *hsotg,
800 struct dwc2_host_chan *chan,
801 struct dwc2_qtd *qtd,
802 struct dwc2_qh *qh, u16 idx)
803{
804 struct dwc2_hcd_dma_desc *dma_desc = &qh->desc_list[idx];
805 struct dwc2_hcd_iso_packet_desc *frame_desc;
806 u16 remain = 0;
807 int rc = 0;
808
Paul Zimmerman0d012b92013-07-13 14:53:48 -0700809 if (!qtd->urb)
810 return -EINVAL;
811
Paul Zimmermandc4c76e2013-03-11 17:48:00 -0700812 frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index_last];
813 dma_desc->buf = (u32)(qtd->urb->dma + frame_desc->offset);
814 if (chan->ep_is_in)
Matthijs Kooijmand6ec53e2013-08-30 18:45:15 +0200815 remain = (dma_desc->status & HOST_DMA_ISOC_NBYTES_MASK) >>
816 HOST_DMA_ISOC_NBYTES_SHIFT;
Paul Zimmermandc4c76e2013-03-11 17:48:00 -0700817
818 if ((dma_desc->status & HOST_DMA_STS_MASK) == HOST_DMA_STS_PKTERR) {
819 /*
820 * XactError, or unable to complete all the transactions
821 * in the scheduled micro-frame/frame, both indicated by
822 * HOST_DMA_STS_PKTERR
823 */
824 qtd->urb->error_count++;
825 frame_desc->actual_length = qh->n_bytes[idx] - remain;
826 frame_desc->status = -EPROTO;
827 } else {
828 /* Success */
829 frame_desc->actual_length = qh->n_bytes[idx] - remain;
830 frame_desc->status = 0;
831 }
832
833 if (++qtd->isoc_frame_index == qtd->urb->packet_count) {
834 /*
835 * urb->status is not used for isoc transfers here. The
836 * individual frame_desc status are used instead.
837 */
Paul Zimmerman0d012b92013-07-13 14:53:48 -0700838 dwc2_host_complete(hsotg, qtd, 0);
Paul Zimmermandc4c76e2013-03-11 17:48:00 -0700839 dwc2_hcd_qtd_unlink_and_free(hsotg, qtd, qh);
840
841 /*
842 * This check is necessary because urb_dequeue can be called
843 * from urb complete callback (sound driver for example). All
844 * pending URBs are dequeued there, so no need for further
845 * processing.
846 */
847 if (chan->halt_status == DWC2_HC_XFER_URB_DEQUEUE)
848 return -1;
849 rc = DWC2_CMPL_DONE;
850 }
851
852 qh->ntd--;
853
854 /* Stop if IOC requested descriptor reached */
855 if (dma_desc->status & HOST_DMA_IOC)
856 rc = DWC2_CMPL_STOP;
857
858 return rc;
859}
860
861static void dwc2_complete_isoc_xfer_ddma(struct dwc2_hsotg *hsotg,
862 struct dwc2_host_chan *chan,
863 enum dwc2_halt_status halt_status)
864{
865 struct dwc2_hcd_iso_packet_desc *frame_desc;
866 struct dwc2_qtd *qtd, *qtd_tmp;
867 struct dwc2_qh *qh;
868 u16 idx;
869 int rc;
870
871 qh = chan->qh;
872 idx = qh->td_first;
873
874 if (chan->halt_status == DWC2_HC_XFER_URB_DEQUEUE) {
875 list_for_each_entry(qtd, &qh->qtd_list, qtd_list_entry)
876 qtd->in_process = 0;
877 return;
878 }
879
880 if (halt_status == DWC2_HC_XFER_AHB_ERR ||
881 halt_status == DWC2_HC_XFER_BABBLE_ERR) {
882 /*
883 * Channel is halted in these error cases, considered as serious
884 * issues.
885 * Complete all URBs marking all frames as failed, irrespective
886 * whether some of the descriptors (frames) succeeded or not.
887 * Pass error code to completion routine as well, to update
888 * urb->status, some of class drivers might use it to stop
889 * queing transfer requests.
890 */
891 int err = halt_status == DWC2_HC_XFER_AHB_ERR ?
892 -EIO : -EOVERFLOW;
893
894 list_for_each_entry_safe(qtd, qtd_tmp, &qh->qtd_list,
895 qtd_list_entry) {
Paul Zimmerman0d012b92013-07-13 14:53:48 -0700896 if (qtd->urb) {
897 for (idx = 0; idx < qtd->urb->packet_count;
898 idx++) {
899 frame_desc = &qtd->urb->iso_descs[idx];
900 frame_desc->status = err;
901 }
902
903 dwc2_host_complete(hsotg, qtd, err);
Paul Zimmermandc4c76e2013-03-11 17:48:00 -0700904 }
905
Paul Zimmermandc4c76e2013-03-11 17:48:00 -0700906 dwc2_hcd_qtd_unlink_and_free(hsotg, qtd, qh);
907 }
908
909 return;
910 }
911
912 list_for_each_entry_safe(qtd, qtd_tmp, &qh->qtd_list, qtd_list_entry) {
913 if (!qtd->in_process)
914 break;
915 do {
916 rc = dwc2_cmpl_host_isoc_dma_desc(hsotg, chan, qtd, qh,
917 idx);
918 if (rc < 0)
919 return;
920 idx = dwc2_desclist_idx_inc(idx, qh->interval,
921 chan->speed);
922 if (rc == DWC2_CMPL_STOP)
923 goto stop_scan;
924 if (rc == DWC2_CMPL_DONE)
925 break;
926 } while (idx != qh->td_first);
927 }
928
929stop_scan:
930 qh->td_first = idx;
931}
932
933static int dwc2_update_non_isoc_urb_state_ddma(struct dwc2_hsotg *hsotg,
934 struct dwc2_host_chan *chan,
935 struct dwc2_qtd *qtd,
936 struct dwc2_hcd_dma_desc *dma_desc,
937 enum dwc2_halt_status halt_status,
938 u32 n_bytes, int *xfer_done)
939{
940 struct dwc2_hcd_urb *urb = qtd->urb;
941 u16 remain = 0;
942
943 if (chan->ep_is_in)
Matthijs Kooijmand6ec53e2013-08-30 18:45:15 +0200944 remain = (dma_desc->status & HOST_DMA_NBYTES_MASK) >>
945 HOST_DMA_NBYTES_SHIFT;
Paul Zimmermandc4c76e2013-03-11 17:48:00 -0700946
947 dev_vdbg(hsotg->dev, "remain=%d dwc2_urb=%p\n", remain, urb);
948
949 if (halt_status == DWC2_HC_XFER_AHB_ERR) {
950 dev_err(hsotg->dev, "EIO\n");
951 urb->status = -EIO;
952 return 1;
953 }
954
955 if ((dma_desc->status & HOST_DMA_STS_MASK) == HOST_DMA_STS_PKTERR) {
956 switch (halt_status) {
957 case DWC2_HC_XFER_STALL:
958 dev_vdbg(hsotg->dev, "Stall\n");
959 urb->status = -EPIPE;
960 break;
961 case DWC2_HC_XFER_BABBLE_ERR:
962 dev_err(hsotg->dev, "Babble\n");
963 urb->status = -EOVERFLOW;
964 break;
965 case DWC2_HC_XFER_XACT_ERR:
966 dev_err(hsotg->dev, "XactErr\n");
967 urb->status = -EPROTO;
968 break;
969 default:
970 dev_err(hsotg->dev,
971 "%s: Unhandled descriptor error status (%d)\n",
972 __func__, halt_status);
973 break;
974 }
975 return 1;
976 }
977
978 if (dma_desc->status & HOST_DMA_A) {
979 dev_vdbg(hsotg->dev,
980 "Active descriptor encountered on channel %d\n",
981 chan->hc_num);
982 return 0;
983 }
984
985 if (chan->ep_type == USB_ENDPOINT_XFER_CONTROL) {
986 if (qtd->control_phase == DWC2_CONTROL_DATA) {
987 urb->actual_length += n_bytes - remain;
988 if (remain || urb->actual_length >= urb->length) {
989 /*
990 * For Control Data stage do not set urb->status
991 * to 0, to prevent URB callback. Set it when
992 * Status phase is done. See below.
993 */
994 *xfer_done = 1;
995 }
996 } else if (qtd->control_phase == DWC2_CONTROL_STATUS) {
997 urb->status = 0;
998 *xfer_done = 1;
999 }
1000 /* No handling for SETUP stage */
1001 } else {
1002 /* BULK and INTR */
1003 urb->actual_length += n_bytes - remain;
1004 dev_vdbg(hsotg->dev, "length=%d actual=%d\n", urb->length,
1005 urb->actual_length);
1006 if (remain || urb->actual_length >= urb->length) {
1007 urb->status = 0;
1008 *xfer_done = 1;
1009 }
1010 }
1011
1012 return 0;
1013}
1014
1015static int dwc2_process_non_isoc_desc(struct dwc2_hsotg *hsotg,
1016 struct dwc2_host_chan *chan,
1017 int chnum, struct dwc2_qtd *qtd,
1018 int desc_num,
1019 enum dwc2_halt_status halt_status,
1020 int *xfer_done)
1021{
1022 struct dwc2_qh *qh = chan->qh;
1023 struct dwc2_hcd_urb *urb = qtd->urb;
1024 struct dwc2_hcd_dma_desc *dma_desc;
1025 u32 n_bytes;
1026 int failed;
1027
1028 dev_vdbg(hsotg->dev, "%s()\n", __func__);
1029
Paul Zimmerman0d012b92013-07-13 14:53:48 -07001030 if (!urb)
1031 return -EINVAL;
1032
Paul Zimmermandc4c76e2013-03-11 17:48:00 -07001033 dma_desc = &qh->desc_list[desc_num];
1034 n_bytes = qh->n_bytes[desc_num];
1035 dev_vdbg(hsotg->dev,
1036 "qtd=%p dwc2_urb=%p desc_num=%d desc=%p n_bytes=%d\n",
1037 qtd, urb, desc_num, dma_desc, n_bytes);
1038 failed = dwc2_update_non_isoc_urb_state_ddma(hsotg, chan, qtd, dma_desc,
1039 halt_status, n_bytes,
1040 xfer_done);
1041 if (failed || (*xfer_done && urb->status != -EINPROGRESS)) {
Paul Zimmerman0d012b92013-07-13 14:53:48 -07001042 dwc2_host_complete(hsotg, qtd, urb->status);
Paul Zimmermandc4c76e2013-03-11 17:48:00 -07001043 dwc2_hcd_qtd_unlink_and_free(hsotg, qtd, qh);
1044 dev_vdbg(hsotg->dev, "failed=%1x xfer_done=%1x status=%08x\n",
1045 failed, *xfer_done, urb->status);
1046 return failed;
1047 }
1048
1049 if (qh->ep_type == USB_ENDPOINT_XFER_CONTROL) {
1050 switch (qtd->control_phase) {
1051 case DWC2_CONTROL_SETUP:
1052 if (urb->length > 0)
1053 qtd->control_phase = DWC2_CONTROL_DATA;
1054 else
1055 qtd->control_phase = DWC2_CONTROL_STATUS;
1056 dev_vdbg(hsotg->dev,
1057 " Control setup transaction done\n");
1058 break;
1059 case DWC2_CONTROL_DATA:
1060 if (*xfer_done) {
1061 qtd->control_phase = DWC2_CONTROL_STATUS;
1062 dev_vdbg(hsotg->dev,
1063 " Control data transfer done\n");
1064 } else if (desc_num + 1 == qtd->n_desc) {
1065 /*
1066 * Last descriptor for Control data stage which
1067 * is not completed yet
1068 */
1069 dwc2_hcd_save_data_toggle(hsotg, chan, chnum,
1070 qtd);
1071 }
1072 break;
1073 default:
1074 break;
1075 }
1076 }
1077
1078 return 0;
1079}
1080
1081static void dwc2_complete_non_isoc_xfer_ddma(struct dwc2_hsotg *hsotg,
1082 struct dwc2_host_chan *chan,
1083 int chnum,
1084 enum dwc2_halt_status halt_status)
1085{
1086 struct list_head *qtd_item, *qtd_tmp;
1087 struct dwc2_qh *qh = chan->qh;
1088 struct dwc2_qtd *qtd = NULL;
1089 int xfer_done;
1090 int desc_num = 0;
1091
1092 if (chan->halt_status == DWC2_HC_XFER_URB_DEQUEUE) {
1093 list_for_each_entry(qtd, &qh->qtd_list, qtd_list_entry)
1094 qtd->in_process = 0;
1095 return;
1096 }
1097
1098 list_for_each_safe(qtd_item, qtd_tmp, &qh->qtd_list) {
1099 int i;
1100
1101 qtd = list_entry(qtd_item, struct dwc2_qtd, qtd_list_entry);
1102 xfer_done = 0;
1103
1104 for (i = 0; i < qtd->n_desc; i++) {
1105 if (dwc2_process_non_isoc_desc(hsotg, chan, chnum, qtd,
1106 desc_num, halt_status,
Paul Zimmermanfbd1cd22013-11-22 16:43:46 -08001107 &xfer_done)) {
1108 qtd = NULL;
Paul Zimmermandc4c76e2013-03-11 17:48:00 -07001109 break;
Paul Zimmermanfbd1cd22013-11-22 16:43:46 -08001110 }
Paul Zimmermandc4c76e2013-03-11 17:48:00 -07001111 desc_num++;
1112 }
1113 }
1114
1115 if (qh->ep_type != USB_ENDPOINT_XFER_CONTROL) {
1116 /*
1117 * Resetting the data toggle for bulk and interrupt endpoints
1118 * in case of stall. See handle_hc_stall_intr().
1119 */
1120 if (halt_status == DWC2_HC_XFER_STALL)
1121 qh->data_toggle = DWC2_HC_PID_DATA0;
1122 else if (qtd)
1123 dwc2_hcd_save_data_toggle(hsotg, chan, chnum, qtd);
1124 }
1125
1126 if (halt_status == DWC2_HC_XFER_COMPLETE) {
1127 if (chan->hcint & HCINTMSK_NYET) {
1128 /*
1129 * Got a NYET on the last transaction of the transfer.
1130 * It means that the endpoint should be in the PING
1131 * state at the beginning of the next transfer.
1132 */
1133 qh->ping_state = 1;
1134 }
1135 }
1136}
1137
1138/**
1139 * dwc2_hcd_complete_xfer_ddma() - Scans the descriptor list, updates URB's
1140 * status and calls completion routine for the URB if it's done. Called from
1141 * interrupt handlers.
1142 *
1143 * @hsotg: The HCD state structure for the DWC OTG controller
1144 * @chan: Host channel the transfer is completed on
1145 * @chnum: Index of Host channel registers
1146 * @halt_status: Reason the channel is being halted or just XferComplete
1147 * for isochronous transfers
1148 *
1149 * Releases the channel to be used by other transfers.
1150 * In case of Isochronous endpoint the channel is not halted until the end of
1151 * the session, i.e. QTD list is empty.
1152 * If periodic channel released the FrameList is updated accordingly.
1153 * Calls transaction selection routines to activate pending transfers.
1154 */
1155void dwc2_hcd_complete_xfer_ddma(struct dwc2_hsotg *hsotg,
1156 struct dwc2_host_chan *chan, int chnum,
1157 enum dwc2_halt_status halt_status)
1158{
1159 struct dwc2_qh *qh = chan->qh;
1160 int continue_isoc_xfer = 0;
1161 enum dwc2_transaction_type tr_type;
1162
1163 if (chan->ep_type == USB_ENDPOINT_XFER_ISOC) {
1164 dwc2_complete_isoc_xfer_ddma(hsotg, chan, halt_status);
1165
1166 /* Release the channel if halted or session completed */
1167 if (halt_status != DWC2_HC_XFER_COMPLETE ||
1168 list_empty(&qh->qtd_list)) {
1169 /* Halt the channel if session completed */
1170 if (halt_status == DWC2_HC_XFER_COMPLETE)
1171 dwc2_hc_halt(hsotg, chan, halt_status);
1172 dwc2_release_channel_ddma(hsotg, qh);
1173 dwc2_hcd_qh_unlink(hsotg, qh);
1174 } else {
1175 /* Keep in assigned schedule to continue transfer */
1176 list_move(&qh->qh_list_entry,
1177 &hsotg->periodic_sched_assigned);
1178 continue_isoc_xfer = 1;
1179 }
1180 /*
1181 * Todo: Consider the case when period exceeds FrameList size.
1182 * Frame Rollover interrupt should be used.
1183 */
1184 } else {
1185 /*
1186 * Scan descriptor list to complete the URB(s), then release
1187 * the channel
1188 */
1189 dwc2_complete_non_isoc_xfer_ddma(hsotg, chan, chnum,
1190 halt_status);
1191 dwc2_release_channel_ddma(hsotg, qh);
1192 dwc2_hcd_qh_unlink(hsotg, qh);
1193
1194 if (!list_empty(&qh->qtd_list)) {
1195 /*
1196 * Add back to inactive non-periodic schedule on normal
1197 * completion
1198 */
1199 dwc2_hcd_qh_add(hsotg, qh);
1200 }
1201 }
1202
1203 tr_type = dwc2_hcd_select_transactions(hsotg);
1204 if (tr_type != DWC2_TRANSACTION_NONE || continue_isoc_xfer) {
1205 if (continue_isoc_xfer) {
1206 if (tr_type == DWC2_TRANSACTION_NONE)
1207 tr_type = DWC2_TRANSACTION_PERIODIC;
1208 else if (tr_type == DWC2_TRANSACTION_NON_PERIODIC)
1209 tr_type = DWC2_TRANSACTION_ALL;
1210 }
1211 dwc2_hcd_queue_transactions(hsotg, tr_type);
1212 }
1213}