@@ -80,7 +80,7 @@ decode_ep(struct usb_host_endpoint *ep, enum usb_device_speed speed)
80
80
interval /= 1000 ;
81
81
}
82
82
83
- snprintf (buf , DBG_BUF_EN , "%s ep%d%s %s, mpkt:%d, interval:%d/%d%s\n " ,
83
+ snprintf (buf , DBG_BUF_EN , "%s ep%d%s %s, mpkt:%d, interval:%d/%d%s" ,
84
84
usb_speed_string (speed ), usb_endpoint_num (epd ),
85
85
usb_endpoint_dir_in (epd ) ? "in" : "out" ,
86
86
usb_ep_type_string (usb_endpoint_type (epd )),
@@ -129,6 +129,10 @@ get_bw_info(struct xhci_hcd_mtk *mtk, struct usb_device *udev,
129
129
int bw_index ;
130
130
131
131
virt_dev = xhci -> devs [udev -> slot_id ];
132
+ if (!virt_dev -> real_port ) {
133
+ WARN_ONCE (1 , "%s invalid real_port\n" , dev_name (& udev -> dev ));
134
+ return NULL ;
135
+ }
132
136
133
137
if (udev -> speed >= USB_SPEED_SUPER ) {
134
138
if (usb_endpoint_dir_out (& ep -> desc ))
@@ -236,14 +240,20 @@ static void drop_tt(struct usb_device *udev)
236
240
}
237
241
}
238
242
239
- static struct mu3h_sch_ep_info * create_sch_ep (struct usb_device * udev ,
240
- struct usb_host_endpoint * ep , struct xhci_ep_ctx * ep_ctx )
243
+ static struct mu3h_sch_ep_info *
244
+ create_sch_ep (struct xhci_hcd_mtk * mtk , struct usb_device * udev ,
245
+ struct usb_host_endpoint * ep , struct xhci_ep_ctx * ep_ctx )
241
246
{
242
247
struct mu3h_sch_ep_info * sch_ep ;
248
+ struct mu3h_sch_bw_info * bw_info ;
243
249
struct mu3h_sch_tt * tt = NULL ;
244
250
u32 len_bw_budget_table ;
245
251
size_t mem_size ;
246
252
253
+ bw_info = get_bw_info (mtk , udev , ep );
254
+ if (!bw_info )
255
+ return ERR_PTR (- ENODEV );
256
+
247
257
if (is_fs_or_ls (udev -> speed ))
248
258
len_bw_budget_table = TT_MICROFRAMES_MAX ;
249
259
else if ((udev -> speed >= USB_SPEED_SUPER )
@@ -266,11 +276,13 @@ static struct mu3h_sch_ep_info *create_sch_ep(struct usb_device *udev,
266
276
}
267
277
}
268
278
279
+ sch_ep -> bw_info = bw_info ;
269
280
sch_ep -> sch_tt = tt ;
270
281
sch_ep -> ep = ep ;
271
282
sch_ep -> speed = udev -> speed ;
272
283
INIT_LIST_HEAD (& sch_ep -> endpoint );
273
284
INIT_LIST_HEAD (& sch_ep -> tt_endpoint );
285
+ INIT_HLIST_NODE (& sch_ep -> hentry );
274
286
275
287
return sch_ep ;
276
288
}
@@ -578,9 +590,9 @@ static u32 get_esit_boundary(struct mu3h_sch_ep_info *sch_ep)
578
590
return boundary ;
579
591
}
580
592
581
- static int check_sch_bw (struct mu3h_sch_bw_info * sch_bw ,
582
- struct mu3h_sch_ep_info * sch_ep )
593
+ static int check_sch_bw (struct mu3h_sch_ep_info * sch_ep )
583
594
{
595
+ struct mu3h_sch_bw_info * sch_bw = sch_ep -> bw_info ;
584
596
const u32 esit_boundary = get_esit_boundary (sch_ep );
585
597
const u32 bw_boundary = get_bw_boundary (sch_ep -> speed );
586
598
u32 offset ;
@@ -627,23 +639,26 @@ static int check_sch_bw(struct mu3h_sch_bw_info *sch_bw,
627
639
return load_ep_bw (sch_bw , sch_ep , true);
628
640
}
629
641
630
- static void destroy_sch_ep (struct usb_device * udev ,
631
- struct mu3h_sch_bw_info * sch_bw , struct mu3h_sch_ep_info * sch_ep )
642
+ static void destroy_sch_ep (struct xhci_hcd_mtk * mtk , struct usb_device * udev ,
643
+ struct mu3h_sch_ep_info * sch_ep )
632
644
{
633
645
/* only release ep bw check passed by check_sch_bw() */
634
646
if (sch_ep -> allocated )
635
- load_ep_bw (sch_bw , sch_ep , false);
647
+ load_ep_bw (sch_ep -> bw_info , sch_ep , false);
636
648
637
649
if (sch_ep -> sch_tt )
638
650
drop_tt (udev );
639
651
640
652
list_del (& sch_ep -> endpoint );
653
+ hlist_del (& sch_ep -> hentry );
641
654
kfree (sch_ep );
642
655
}
643
656
644
- static bool need_bw_sch (struct usb_host_endpoint * ep ,
645
- enum usb_device_speed speed , int has_tt )
657
+ static bool need_bw_sch (struct usb_device * udev ,
658
+ struct usb_host_endpoint * ep )
646
659
{
660
+ bool has_tt = udev -> tt && udev -> tt -> hub -> parent ;
661
+
647
662
/* only for periodic endpoints */
648
663
if (usb_endpoint_xfer_control (& ep -> desc )
649
664
|| usb_endpoint_xfer_bulk (& ep -> desc ))
@@ -654,7 +669,7 @@ static bool need_bw_sch(struct usb_host_endpoint *ep,
654
669
* a TT are also ignored, root-hub will schedule them directly,
655
670
* but need set @bpkts field of endpoint context to 1.
656
671
*/
657
- if (is_fs_or_ls (speed ) && !has_tt )
672
+ if (is_fs_or_ls (udev -> speed ) && !has_tt )
658
673
return false;
659
674
660
675
/* skip endpoint with zero maxpkt */
@@ -669,7 +684,6 @@ int xhci_mtk_sch_init(struct xhci_hcd_mtk *mtk)
669
684
struct xhci_hcd * xhci = hcd_to_xhci (mtk -> hcd );
670
685
struct mu3h_sch_bw_info * sch_array ;
671
686
int num_usb_bus ;
672
- int i ;
673
687
674
688
/* ss IN and OUT are separated */
675
689
num_usb_bus = xhci -> usb3_rhub .num_ports * 2 + xhci -> usb2_rhub .num_ports ;
@@ -678,12 +692,10 @@ int xhci_mtk_sch_init(struct xhci_hcd_mtk *mtk)
678
692
if (sch_array == NULL )
679
693
return - ENOMEM ;
680
694
681
- for (i = 0 ; i < num_usb_bus ; i ++ )
682
- INIT_LIST_HEAD (& sch_array [i ].bw_ep_list );
683
-
684
695
mtk -> sch_array = sch_array ;
685
696
686
697
INIT_LIST_HEAD (& mtk -> bw_ep_chk_list );
698
+ hash_init (mtk -> sch_ep_hash );
687
699
688
700
return 0 ;
689
701
}
@@ -707,9 +719,7 @@ static int add_ep_quirk(struct usb_hcd *hcd, struct usb_device *udev,
707
719
ep_index = xhci_get_endpoint_index (& ep -> desc );
708
720
ep_ctx = xhci_get_ep_ctx (xhci , virt_dev -> in_ctx , ep_index );
709
721
710
- xhci_dbg (xhci , "%s %s\n" , __func__ , decode_ep (ep , udev -> speed ));
711
-
712
- if (!need_bw_sch (ep , udev -> speed , !!virt_dev -> tt_info )) {
722
+ if (!need_bw_sch (udev , ep )) {
713
723
/*
714
724
* set @bpkts to 1 if it is LS or FS periodic endpoint, and its
715
725
* device does not connected through an external HS hub
@@ -721,13 +731,16 @@ static int add_ep_quirk(struct usb_hcd *hcd, struct usb_device *udev,
721
731
return 0 ;
722
732
}
723
733
724
- sch_ep = create_sch_ep (udev , ep , ep_ctx );
734
+ xhci_dbg (xhci , "%s %s\n" , __func__ , decode_ep (ep , udev -> speed ));
735
+
736
+ sch_ep = create_sch_ep (mtk , udev , ep , ep_ctx );
725
737
if (IS_ERR_OR_NULL (sch_ep ))
726
738
return - ENOMEM ;
727
739
728
740
setup_sch_info (ep_ctx , sch_ep );
729
741
730
742
list_add_tail (& sch_ep -> endpoint , & mtk -> bw_ep_chk_list );
743
+ hash_add (mtk -> sch_ep_hash , & sch_ep -> hentry , (unsigned long )ep );
731
744
732
745
return 0 ;
733
746
}
@@ -737,22 +750,18 @@ static void drop_ep_quirk(struct usb_hcd *hcd, struct usb_device *udev,
737
750
{
738
751
struct xhci_hcd_mtk * mtk = hcd_to_mtk (hcd );
739
752
struct xhci_hcd * xhci = hcd_to_xhci (hcd );
740
- struct xhci_virt_device * virt_dev ;
741
- struct mu3h_sch_bw_info * sch_bw ;
742
- struct mu3h_sch_ep_info * sch_ep , * tmp ;
743
-
744
- virt_dev = xhci -> devs [udev -> slot_id ];
745
-
746
- xhci_dbg (xhci , "%s %s\n" , __func__ , decode_ep (ep , udev -> speed ));
753
+ struct mu3h_sch_ep_info * sch_ep ;
754
+ struct hlist_node * hn ;
747
755
748
- if (!need_bw_sch (ep , udev -> speed , !! virt_dev -> tt_info ))
756
+ if (!need_bw_sch (udev , ep ))
749
757
return ;
750
758
751
- sch_bw = get_bw_info ( mtk , udev , ep );
759
+ xhci_err ( xhci , "%s %s\n" , __func__ , decode_ep ( ep , udev -> speed ) );
752
760
753
- list_for_each_entry_safe (sch_ep , tmp , & sch_bw -> bw_ep_list , endpoint ) {
761
+ hash_for_each_possible_safe (mtk -> sch_ep_hash , sch_ep ,
762
+ hn , hentry , (unsigned long )ep ) {
754
763
if (sch_ep -> ep == ep ) {
755
- destroy_sch_ep (udev , sch_bw , sch_ep );
764
+ destroy_sch_ep (mtk , udev , sch_ep );
756
765
break ;
757
766
}
758
767
}
@@ -763,30 +772,22 @@ int xhci_mtk_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev)
763
772
struct xhci_hcd_mtk * mtk = hcd_to_mtk (hcd );
764
773
struct xhci_hcd * xhci = hcd_to_xhci (hcd );
765
774
struct xhci_virt_device * virt_dev = xhci -> devs [udev -> slot_id ];
766
- struct mu3h_sch_bw_info * sch_bw ;
767
- struct mu3h_sch_ep_info * sch_ep , * tmp ;
775
+ struct mu3h_sch_ep_info * sch_ep ;
768
776
int ret ;
769
777
770
778
xhci_dbg (xhci , "%s() udev %s\n" , __func__ , dev_name (& udev -> dev ));
771
779
772
780
list_for_each_entry (sch_ep , & mtk -> bw_ep_chk_list , endpoint ) {
773
- sch_bw = get_bw_info (mtk , udev , sch_ep -> ep );
781
+ struct xhci_ep_ctx * ep_ctx ;
782
+ struct usb_host_endpoint * ep = sch_ep -> ep ;
783
+ unsigned int ep_index = xhci_get_endpoint_index (& ep -> desc );
774
784
775
- ret = check_sch_bw (sch_bw , sch_ep );
785
+ ret = check_sch_bw (sch_ep );
776
786
if (ret ) {
777
787
xhci_err (xhci , "Not enough bandwidth! (%s)\n" ,
778
788
sch_error_string (- ret ));
779
789
return - ENOSPC ;
780
790
}
781
- }
782
-
783
- list_for_each_entry_safe (sch_ep , tmp , & mtk -> bw_ep_chk_list , endpoint ) {
784
- struct xhci_ep_ctx * ep_ctx ;
785
- struct usb_host_endpoint * ep = sch_ep -> ep ;
786
- unsigned int ep_index = xhci_get_endpoint_index (& ep -> desc );
787
-
788
- sch_bw = get_bw_info (mtk , udev , ep );
789
- list_move_tail (& sch_ep -> endpoint , & sch_bw -> bw_ep_list );
790
791
791
792
ep_ctx = xhci_get_ep_ctx (xhci , virt_dev -> in_ctx , ep_index );
792
793
ep_ctx -> reserved [0 ] = cpu_to_le32 (EP_BPKTS (sch_ep -> pkts )
@@ -800,22 +801,23 @@ int xhci_mtk_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev)
800
801
sch_ep -> offset , sch_ep -> repeat );
801
802
}
802
803
803
- return xhci_check_bandwidth (hcd , udev );
804
+ ret = xhci_check_bandwidth (hcd , udev );
805
+ if (!ret )
806
+ INIT_LIST_HEAD (& mtk -> bw_ep_chk_list );
807
+
808
+ return ret ;
804
809
}
805
810
806
811
void xhci_mtk_reset_bandwidth (struct usb_hcd * hcd , struct usb_device * udev )
807
812
{
808
813
struct xhci_hcd_mtk * mtk = hcd_to_mtk (hcd );
809
814
struct xhci_hcd * xhci = hcd_to_xhci (hcd );
810
- struct mu3h_sch_bw_info * sch_bw ;
811
815
struct mu3h_sch_ep_info * sch_ep , * tmp ;
812
816
813
817
xhci_dbg (xhci , "%s() udev %s\n" , __func__ , dev_name (& udev -> dev ));
814
818
815
- list_for_each_entry_safe (sch_ep , tmp , & mtk -> bw_ep_chk_list , endpoint ) {
816
- sch_bw = get_bw_info (mtk , udev , sch_ep -> ep );
817
- destroy_sch_ep (udev , sch_bw , sch_ep );
818
- }
819
+ list_for_each_entry_safe (sch_ep , tmp , & mtk -> bw_ep_chk_list , endpoint )
820
+ destroy_sch_ep (mtk , udev , sch_ep );
819
821
820
822
xhci_reset_bandwidth (hcd , udev );
821
823
}
0 commit comments