This source file includes following definitions.
- dwc2_hsotg_to_hcd
- disable_hc_int
- dwc2_read_hprt0
- dwc2_hcd_get_ep_num
- dwc2_hcd_get_pipe_type
- dwc2_hcd_get_maxp
- dwc2_hcd_get_maxp_mult
- dwc2_hcd_get_dev_addr
- dwc2_hcd_is_pipe_isoc
- dwc2_hcd_is_pipe_int
- dwc2_hcd_is_pipe_bulk
- dwc2_hcd_is_pipe_control
- dwc2_hcd_is_pipe_in
- dwc2_hcd_is_pipe_out
- dwc2_hcd_qtd_unlink_and_free
- dbg_hc
- dbg_qh
- dbg_urb
- dbg_perio
- dbg_hc
- dbg_qh
- dbg_urb
- dbg_perio
- dwc2_frame_idx_num_gt
- dwc2_frame_num_le
- dwc2_frame_num_gt
- dwc2_frame_num_inc
- dwc2_frame_num_dec
- dwc2_full_frame_num
- dwc2_micro_frame_num
- dwc2_read_core_intr
- dwc2_hcd_urb_get_status
- dwc2_hcd_urb_get_actual_length
- dwc2_hcd_urb_get_error_count
- dwc2_hcd_urb_set_iso_desc_params
- dwc2_hcd_urb_get_iso_desc_status
- dwc2_hcd_urb_get_iso_desc_actual_length
- dwc2_hcd_is_bandwidth_allocated
- dwc2_hcd_get_ep_bandwidth
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 #ifndef __DWC2_HCD_H__
38 #define __DWC2_HCD_H__
39
40
41
42
43
44
45
46
47
48
49
50 struct dwc2_qh;
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118 struct dwc2_host_chan {
119 u8 hc_num;
120
121 unsigned dev_addr:7;
122 unsigned ep_num:4;
123 unsigned ep_is_in:1;
124 unsigned speed:4;
125 unsigned ep_type:2;
126 unsigned max_packet:11;
127 unsigned data_pid_start:2;
128 #define DWC2_HC_PID_DATA0 TSIZ_SC_MC_PID_DATA0
129 #define DWC2_HC_PID_DATA2 TSIZ_SC_MC_PID_DATA2
130 #define DWC2_HC_PID_DATA1 TSIZ_SC_MC_PID_DATA1
131 #define DWC2_HC_PID_MDATA TSIZ_SC_MC_PID_MDATA
132 #define DWC2_HC_PID_SETUP TSIZ_SC_MC_PID_SETUP
133
134 unsigned multi_count:2;
135
136 u8 *xfer_buf;
137 dma_addr_t xfer_dma;
138 dma_addr_t align_buf;
139 u32 xfer_len;
140 u32 xfer_count;
141 u16 start_pkt_count;
142 u8 xfer_started;
143 u8 do_ping;
144 u8 error_state;
145 u8 halt_on_queue;
146 u8 halt_pending;
147 u8 do_split;
148 u8 complete_split;
149 u8 hub_addr;
150 u8 hub_port;
151 u8 xact_pos;
152 #define DWC2_HCSPLT_XACTPOS_MID HCSPLT_XACTPOS_MID
153 #define DWC2_HCSPLT_XACTPOS_END HCSPLT_XACTPOS_END
154 #define DWC2_HCSPLT_XACTPOS_BEGIN HCSPLT_XACTPOS_BEGIN
155 #define DWC2_HCSPLT_XACTPOS_ALL HCSPLT_XACTPOS_ALL
156
157 u8 requests;
158 u8 schinfo;
159 u16 ntd;
160 enum dwc2_halt_status halt_status;
161 u32 hcint;
162 struct dwc2_qh *qh;
163 struct list_head hc_list_entry;
164 dma_addr_t desc_list_addr;
165 u32 desc_list_sz;
166 struct list_head split_order_list_entry;
167 };
168
169 struct dwc2_hcd_pipe_info {
170 u8 dev_addr;
171 u8 ep_num;
172 u8 pipe_type;
173 u8 pipe_dir;
174 u16 maxp;
175 u16 maxp_mult;
176 };
177
178 struct dwc2_hcd_iso_packet_desc {
179 u32 offset;
180 u32 length;
181 u32 actual_length;
182 u32 status;
183 };
184
185 struct dwc2_qtd;
186
187 struct dwc2_hcd_urb {
188 void *priv;
189 struct dwc2_qtd *qtd;
190 void *buf;
191 dma_addr_t dma;
192 void *setup_packet;
193 dma_addr_t setup_dma;
194 u32 length;
195 u32 actual_length;
196 u32 status;
197 u32 error_count;
198 u32 packet_count;
199 u32 flags;
200 u16 interval;
201 struct dwc2_hcd_pipe_info pipe_info;
202 struct dwc2_hcd_iso_packet_desc iso_descs[0];
203 };
204
205
206 enum dwc2_control_phase {
207 DWC2_CONTROL_SETUP,
208 DWC2_CONTROL_DATA,
209 DWC2_CONTROL_STATUS,
210 };
211
212
213 enum dwc2_transaction_type {
214 DWC2_TRANSACTION_NONE,
215 DWC2_TRANSACTION_PERIODIC,
216 DWC2_TRANSACTION_NON_PERIODIC,
217 DWC2_TRANSACTION_ALL,
218 };
219
220
221 #define DWC2_ELEMENTS_PER_LS_BITMAP DIV_ROUND_UP(DWC2_LS_SCHEDULE_SLICES, \
222 BITS_PER_LONG)
223
224
225
226
227
228
229
230
231
232
233
234
235 struct dwc2_tt {
236 int refcount;
237 struct usb_tt *usb_tt;
238 unsigned long periodic_bitmaps[];
239 };
240
241
242
243
244
245
246
247
248
249
250
251
252 struct dwc2_hs_transfer_time {
253 u32 start_schedule_us;
254 u16 duration_us;
255 };
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340 struct dwc2_qh {
341 struct dwc2_hsotg *hsotg;
342 u8 ep_type;
343 u8 ep_is_in;
344 u16 maxp;
345 u16 maxp_mult;
346 u8 dev_speed;
347 u8 data_toggle;
348 u8 ping_state;
349 u8 do_split;
350 u8 td_first;
351 u8 td_last;
352 u16 host_us;
353 u16 device_us;
354 u16 host_interval;
355 u16 device_interval;
356 u16 next_active_frame;
357 u16 start_active_frame;
358 s16 num_hs_transfers;
359 struct dwc2_hs_transfer_time hs_transfers[DWC2_HS_SCHEDULE_UFRAMES];
360 u32 ls_start_schedule_slice;
361 u16 ntd;
362 u8 *dw_align_buf;
363 dma_addr_t dw_align_buf_dma;
364 struct list_head qtd_list;
365 struct dwc2_host_chan *channel;
366 struct list_head qh_list_entry;
367 struct dwc2_dma_desc *desc_list;
368 dma_addr_t desc_list_dma;
369 u32 desc_list_sz;
370 u32 *n_bytes;
371 struct timer_list unreserve_timer;
372 struct hrtimer wait_timer;
373 struct dwc2_tt *dwc_tt;
374 int ttport;
375 unsigned tt_buffer_dirty:1;
376 unsigned unreserve_pending:1;
377 unsigned schedule_low_speed:1;
378 unsigned want_wait:1;
379 unsigned wait_timer_cancel:1;
380 };
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431 struct dwc2_qtd {
432 enum dwc2_control_phase control_phase;
433 u8 in_process;
434 u8 data_toggle;
435 u8 complete_split;
436 u8 isoc_split_pos;
437 u16 isoc_frame_index;
438 u16 isoc_split_offset;
439 u16 isoc_td_last;
440 u16 isoc_td_first;
441 u32 ssplit_out_xfer_count;
442 u8 error_count;
443 u8 n_desc;
444 u16 isoc_frame_index_last;
445 u16 num_naks;
446 struct dwc2_hcd_urb *urb;
447 struct dwc2_qh *qh;
448 struct list_head qtd_list_entry;
449 };
450
451 #ifdef DEBUG
452 struct hc_xfer_info {
453 struct dwc2_hsotg *hsotg;
454 struct dwc2_host_chan *chan;
455 };
456 #endif
457
458 u32 dwc2_calc_frame_interval(struct dwc2_hsotg *hsotg);
459
460
461 static inline struct usb_hcd *dwc2_hsotg_to_hcd(struct dwc2_hsotg *hsotg)
462 {
463 return (struct usb_hcd *)hsotg->priv;
464 }
465
466
467
468
469
470
471
472
473 static inline void disable_hc_int(struct dwc2_hsotg *hsotg, int chnum, u32 intr)
474 {
475 u32 mask = dwc2_readl(hsotg, HCINTMSK(chnum));
476
477 mask &= ~intr;
478 dwc2_writel(hsotg, mask, HCINTMSK(chnum));
479 }
480
481 void dwc2_hc_cleanup(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan);
482 void dwc2_hc_halt(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan,
483 enum dwc2_halt_status halt_status);
484 void dwc2_hc_start_transfer_ddma(struct dwc2_hsotg *hsotg,
485 struct dwc2_host_chan *chan);
486
487
488
489
490
491 static inline u32 dwc2_read_hprt0(struct dwc2_hsotg *hsotg)
492 {
493 u32 hprt0 = dwc2_readl(hsotg, HPRT0);
494
495 hprt0 &= ~(HPRT0_ENA | HPRT0_CONNDET | HPRT0_ENACHG | HPRT0_OVRCURRCHG);
496 return hprt0;
497 }
498
499 static inline u8 dwc2_hcd_get_ep_num(struct dwc2_hcd_pipe_info *pipe)
500 {
501 return pipe->ep_num;
502 }
503
504 static inline u8 dwc2_hcd_get_pipe_type(struct dwc2_hcd_pipe_info *pipe)
505 {
506 return pipe->pipe_type;
507 }
508
509 static inline u16 dwc2_hcd_get_maxp(struct dwc2_hcd_pipe_info *pipe)
510 {
511 return pipe->maxp;
512 }
513
514 static inline u16 dwc2_hcd_get_maxp_mult(struct dwc2_hcd_pipe_info *pipe)
515 {
516 return pipe->maxp_mult;
517 }
518
519 static inline u8 dwc2_hcd_get_dev_addr(struct dwc2_hcd_pipe_info *pipe)
520 {
521 return pipe->dev_addr;
522 }
523
524 static inline u8 dwc2_hcd_is_pipe_isoc(struct dwc2_hcd_pipe_info *pipe)
525 {
526 return pipe->pipe_type == USB_ENDPOINT_XFER_ISOC;
527 }
528
529 static inline u8 dwc2_hcd_is_pipe_int(struct dwc2_hcd_pipe_info *pipe)
530 {
531 return pipe->pipe_type == USB_ENDPOINT_XFER_INT;
532 }
533
534 static inline u8 dwc2_hcd_is_pipe_bulk(struct dwc2_hcd_pipe_info *pipe)
535 {
536 return pipe->pipe_type == USB_ENDPOINT_XFER_BULK;
537 }
538
539 static inline u8 dwc2_hcd_is_pipe_control(struct dwc2_hcd_pipe_info *pipe)
540 {
541 return pipe->pipe_type == USB_ENDPOINT_XFER_CONTROL;
542 }
543
544 static inline u8 dwc2_hcd_is_pipe_in(struct dwc2_hcd_pipe_info *pipe)
545 {
546 return pipe->pipe_dir == USB_DIR_IN;
547 }
548
549 static inline u8 dwc2_hcd_is_pipe_out(struct dwc2_hcd_pipe_info *pipe)
550 {
551 return !dwc2_hcd_is_pipe_in(pipe);
552 }
553
554 int dwc2_hcd_init(struct dwc2_hsotg *hsotg);
555 void dwc2_hcd_remove(struct dwc2_hsotg *hsotg);
556
557
558 enum dwc2_transaction_type dwc2_hcd_select_transactions(
559 struct dwc2_hsotg *hsotg);
560 void dwc2_hcd_queue_transactions(struct dwc2_hsotg *hsotg,
561 enum dwc2_transaction_type tr_type);
562
563
564
565 struct dwc2_qh *dwc2_hcd_qh_create(struct dwc2_hsotg *hsotg,
566 struct dwc2_hcd_urb *urb,
567 gfp_t mem_flags);
568 void dwc2_hcd_qh_free(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh);
569 int dwc2_hcd_qh_add(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh);
570 void dwc2_hcd_qh_unlink(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh);
571 void dwc2_hcd_qh_deactivate(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh,
572 int sched_csplit);
573
574 void dwc2_hcd_qtd_init(struct dwc2_qtd *qtd, struct dwc2_hcd_urb *urb);
575 int dwc2_hcd_qtd_add(struct dwc2_hsotg *hsotg, struct dwc2_qtd *qtd,
576 struct dwc2_qh *qh);
577
578
579 static inline void dwc2_hcd_qtd_unlink_and_free(struct dwc2_hsotg *hsotg,
580 struct dwc2_qtd *qtd,
581 struct dwc2_qh *qh)
582 {
583 list_del(&qtd->qtd_list_entry);
584 kfree(qtd);
585 }
586
587
588 void dwc2_hcd_start_xfer_ddma(struct dwc2_hsotg *hsotg,
589 struct dwc2_qh *qh);
590 void dwc2_hcd_complete_xfer_ddma(struct dwc2_hsotg *hsotg,
591 struct dwc2_host_chan *chan, int chnum,
592 enum dwc2_halt_status halt_status);
593
594 int dwc2_hcd_qh_init_ddma(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh,
595 gfp_t mem_flags);
596 void dwc2_hcd_qh_free_ddma(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh);
597
598
599 #define dwc2_qh_is_non_per(_qh_ptr_) \
600 ((_qh_ptr_)->ep_type == USB_ENDPOINT_XFER_BULK || \
601 (_qh_ptr_)->ep_type == USB_ENDPOINT_XFER_CONTROL)
602
603 #ifdef CONFIG_USB_DWC2_DEBUG_PERIODIC
604 static inline bool dbg_hc(struct dwc2_host_chan *hc) { return true; }
605 static inline bool dbg_qh(struct dwc2_qh *qh) { return true; }
606 static inline bool dbg_urb(struct urb *urb) { return true; }
607 static inline bool dbg_perio(void) { return true; }
608 #else
609 static inline bool dbg_hc(struct dwc2_host_chan *hc)
610 {
611 return hc->ep_type == USB_ENDPOINT_XFER_BULK ||
612 hc->ep_type == USB_ENDPOINT_XFER_CONTROL;
613 }
614
615 static inline bool dbg_qh(struct dwc2_qh *qh)
616 {
617 return qh->ep_type == USB_ENDPOINT_XFER_BULK ||
618 qh->ep_type == USB_ENDPOINT_XFER_CONTROL;
619 }
620
621 static inline bool dbg_urb(struct urb *urb)
622 {
623 return usb_pipetype(urb->pipe) == PIPE_BULK ||
624 usb_pipetype(urb->pipe) == PIPE_CONTROL;
625 }
626
627 static inline bool dbg_perio(void) { return false; }
628 #endif
629
630
631
632
633
634
635 static inline bool dwc2_frame_idx_num_gt(u16 fr_idx1, u16 fr_idx2)
636 {
637 u16 diff = fr_idx1 - fr_idx2;
638 u16 sign = diff & (FRLISTEN_64_SIZE >> 1);
639
640 return diff && !sign;
641 }
642
643
644
645
646
647
648 static inline int dwc2_frame_num_le(u16 frame1, u16 frame2)
649 {
650 return ((frame2 - frame1) & HFNUM_MAX_FRNUM) <= (HFNUM_MAX_FRNUM >> 1);
651 }
652
653
654
655
656
657
658 static inline int dwc2_frame_num_gt(u16 frame1, u16 frame2)
659 {
660 return (frame1 != frame2) &&
661 ((frame1 - frame2) & HFNUM_MAX_FRNUM) < (HFNUM_MAX_FRNUM >> 1);
662 }
663
664
665
666
667
668 static inline u16 dwc2_frame_num_inc(u16 frame, u16 inc)
669 {
670 return (frame + inc) & HFNUM_MAX_FRNUM;
671 }
672
673 static inline u16 dwc2_frame_num_dec(u16 frame, u16 dec)
674 {
675 return (frame + HFNUM_MAX_FRNUM + 1 - dec) & HFNUM_MAX_FRNUM;
676 }
677
678 static inline u16 dwc2_full_frame_num(u16 frame)
679 {
680 return (frame & HFNUM_MAX_FRNUM) >> 3;
681 }
682
683 static inline u16 dwc2_micro_frame_num(u16 frame)
684 {
685 return frame & 0x7;
686 }
687
688
689
690
691
692 static inline u32 dwc2_read_core_intr(struct dwc2_hsotg *hsotg)
693 {
694 return dwc2_readl(hsotg, GINTSTS) &
695 dwc2_readl(hsotg, GINTMSK);
696 }
697
698 static inline u32 dwc2_hcd_urb_get_status(struct dwc2_hcd_urb *dwc2_urb)
699 {
700 return dwc2_urb->status;
701 }
702
703 static inline u32 dwc2_hcd_urb_get_actual_length(
704 struct dwc2_hcd_urb *dwc2_urb)
705 {
706 return dwc2_urb->actual_length;
707 }
708
709 static inline u32 dwc2_hcd_urb_get_error_count(struct dwc2_hcd_urb *dwc2_urb)
710 {
711 return dwc2_urb->error_count;
712 }
713
714 static inline void dwc2_hcd_urb_set_iso_desc_params(
715 struct dwc2_hcd_urb *dwc2_urb, int desc_num, u32 offset,
716 u32 length)
717 {
718 dwc2_urb->iso_descs[desc_num].offset = offset;
719 dwc2_urb->iso_descs[desc_num].length = length;
720 }
721
722 static inline u32 dwc2_hcd_urb_get_iso_desc_status(
723 struct dwc2_hcd_urb *dwc2_urb, int desc_num)
724 {
725 return dwc2_urb->iso_descs[desc_num].status;
726 }
727
728 static inline u32 dwc2_hcd_urb_get_iso_desc_actual_length(
729 struct dwc2_hcd_urb *dwc2_urb, int desc_num)
730 {
731 return dwc2_urb->iso_descs[desc_num].actual_length;
732 }
733
734 static inline int dwc2_hcd_is_bandwidth_allocated(struct dwc2_hsotg *hsotg,
735 struct usb_host_endpoint *ep)
736 {
737 struct dwc2_qh *qh = ep->hcpriv;
738
739 if (qh && !list_empty(&qh->qh_list_entry))
740 return 1;
741
742 return 0;
743 }
744
745 static inline u16 dwc2_hcd_get_ep_bandwidth(struct dwc2_hsotg *hsotg,
746 struct usb_host_endpoint *ep)
747 {
748 struct dwc2_qh *qh = ep->hcpriv;
749
750 if (!qh) {
751 WARN_ON(1);
752 return 0;
753 }
754
755 return qh->host_us;
756 }
757
758 void dwc2_hcd_save_data_toggle(struct dwc2_hsotg *hsotg,
759 struct dwc2_host_chan *chan, int chnum,
760 struct dwc2_qtd *qtd);
761
762
763
764
765
766
767
768
769
770
771
772 irqreturn_t dwc2_handle_hcd_intr(struct dwc2_hsotg *hsotg);
773
774
775
776
777
778
779 void dwc2_hcd_stop(struct dwc2_hsotg *hsotg);
780
781
782
783
784
785
786
787 int dwc2_hcd_is_b_host(struct dwc2_hsotg *hsotg);
788
789
790
791
792
793
794
795
796
797 void dwc2_hcd_dump_state(struct dwc2_hsotg *hsotg);
798
799
800
801
802 #define URB_GIVEBACK_ASAP 0x1
803 #define URB_SEND_ZERO_PACKET 0x2
804
805
806 struct dwc2_tt *dwc2_host_get_tt_info(struct dwc2_hsotg *hsotg,
807 void *context, gfp_t mem_flags,
808 int *ttport);
809
810 void dwc2_host_put_tt_info(struct dwc2_hsotg *hsotg,
811 struct dwc2_tt *dwc_tt);
812 int dwc2_host_get_speed(struct dwc2_hsotg *hsotg, void *context);
813 void dwc2_host_complete(struct dwc2_hsotg *hsotg, struct dwc2_qtd *qtd,
814 int status);
815
816 #endif