@@ -76,23 +76,18 @@ static void ehci_qh_free(struct usbh_bus *bus, struct ehci_qh_hw *qh)
7676 }
7777}
7878
79- #ifdef CONFIG_USB_DCACHE_ENABLE
79+ #if CONFIG_USB_EHCI_QH_QTD_DCACHE_ENABLE
8080static inline void usb_ehci_qh_qtd_flush (struct ehci_qh_hw * qh )
8181{
8282 struct ehci_qtd_hw * qtd ;
8383
8484 qtd = EHCI_ADDR2QTD (qh -> first_qtd );
8585
8686 while (qtd ) {
87- usb_dcache_clean ((uintptr_t )& qtd -> hw , USB_ALIGN_UP (SIZEOF_EHCI_QTD , CONFIG_USB_EHCI_ALIGN_SIZE ));
88-
89- if (!qtd -> dir_in ) {
90- usb_dcache_clean (qtd -> bufaddr , USB_ALIGN_UP (qtd -> length , CONFIG_USB_ALIGN_SIZE ));
91- }
87+ usb_dcache_clean ((uintptr_t )& qtd -> hw , CONFIG_USB_EHCI_ALIGN_SIZE );
9288 qtd = EHCI_ADDR2QTD (qtd -> hw .next_qtd );
9389 }
94-
95- usb_dcache_clean ((uintptr_t )& qh -> hw , USB_ALIGN_UP (SIZEOF_EHCI_QH , CONFIG_USB_EHCI_ALIGN_SIZE ));
90+ usb_dcache_clean ((uintptr_t )& qh -> hw , CONFIG_USB_EHCI_ALIGN_SIZE );
9691}
9792#else
9893#define usb_ehci_qh_qtd_flush (qh )
@@ -103,9 +98,12 @@ static inline void ehci_qh_add_head(struct ehci_qh_hw *head, struct ehci_qh_hw *
10398 n -> hw .hlp = head -> hw .hlp ;
10499 usb_ehci_qh_qtd_flush (n );
105100
106- head -> hw . hlp = QH_HLP_QH ( n );
101+ usb_dcache_flush (( uintptr_t ) n -> urb -> transfer_buffer , USB_ALIGN_UP ( n -> urb -> transfer_buffer_length , CONFIG_USB_ALIGN_SIZE ) );
107102
108- usb_dcache_clean ((uintptr_t )& head -> hw , USB_ALIGN_UP (SIZEOF_EHCI_QH , CONFIG_USB_EHCI_ALIGN_SIZE ));
103+ head -> hw .hlp = QH_HLP_QH (n );
104+ #if CONFIG_USB_EHCI_QH_QTD_DCACHE_ENABLE
105+ usb_dcache_clean ((uintptr_t )& head -> hw , CONFIG_USB_EHCI_ALIGN_SIZE );
106+ #endif
109107}
110108
111109static inline void ehci_qh_remove (struct ehci_qh_hw * head , struct ehci_qh_hw * n )
@@ -118,7 +116,9 @@ static inline void ehci_qh_remove(struct ehci_qh_hw *head, struct ehci_qh_hw *n)
118116
119117 if (tmp ) {
120118 tmp -> hw .hlp = n -> hw .hlp ;
121- usb_dcache_clean ((uintptr_t )& tmp -> hw , USB_ALIGN_UP (SIZEOF_EHCI_QH , CONFIG_USB_EHCI_ALIGN_SIZE ));
119+ #if CONFIG_USB_EHCI_QH_QTD_DCACHE_ENABLE
120+ usb_dcache_clean ((uintptr_t )& tmp -> hw , CONFIG_USB_EHCI_ALIGN_SIZE );
121+ #endif
122122 }
123123}
124124
@@ -282,7 +282,6 @@ static void ehci_qtd_fill(struct ehci_qtd_hw *qtd, uint32_t bufaddr, size_t bufl
282282 qtd -> hw .token = token ;
283283
284284 ehci_qtd_bpl_fill (qtd , usb_phyaddr2ramaddr (bufaddr ), buflen );
285- qtd -> dir_in = ((token & QTD_TOKEN_PID_MASK ) == QTD_TOKEN_PID_IN ) ? true : false;
286285 qtd -> bufaddr = bufaddr ;
287286 qtd -> length = buflen ;
288287}
@@ -620,9 +619,6 @@ static void ehci_qh_scan_qtds(struct usbh_bus *bus, struct ehci_qh_hw *qhead, st
620619 qtd = EHCI_ADDR2QTD (qh -> first_qtd );
621620
622621 while (qtd ) {
623- if (qtd -> dir_in ) {
624- usb_dcache_invalidate (qtd -> bufaddr , USB_ALIGN_UP (qtd -> length - ((qtd -> hw .token & QTD_TOKEN_NBYTES_MASK ) >> QTD_TOKEN_NBYTES_SHIFT ), CONFIG_USB_ALIGN_SIZE ));
625- }
626622 qtd -> urb -> actual_length += (qtd -> length - ((qtd -> hw .token & QTD_TOKEN_NBYTES_MASK ) >> QTD_TOKEN_NBYTES_SHIFT ));
627623
628624 qh -> first_qtd = qtd -> hw .next_qtd ;
@@ -643,7 +639,9 @@ static void ehci_check_qh(struct usbh_bus *bus, struct ehci_qh_hw *qhead, struct
643639 }
644640
645641 while (qtd ) {
646- usb_dcache_invalidate ((uintptr_t )& qtd -> hw , USB_ALIGN_UP (SIZEOF_EHCI_QTD , CONFIG_USB_EHCI_ALIGN_SIZE ));
642+ #if CONFIG_USB_EHCI_QH_QTD_DCACHE_ENABLE
643+ usb_dcache_invalidate ((uintptr_t )& qtd -> hw , CONFIG_USB_EHCI_ALIGN_SIZE );
644+ #endif
647645 token = qtd -> hw .token ;
648646
649647 if (token & QTD_TOKEN_STATUS_ERRORS ) {
@@ -799,9 +797,11 @@ int usb_hc_init(struct usbh_bus *bus)
799797 g_framelist [bus -> hcd .hcd_id ][i ] = QH_HLP_QH (& g_periodic_qh_head [bus -> hcd .hcd_id ]);
800798 }
801799
802- usb_dcache_clean ((uintptr_t )& g_async_qh_head [bus -> hcd .hcd_id ].hw , USB_ALIGN_UP (SIZEOF_EHCI_QH , CONFIG_USB_EHCI_ALIGN_SIZE ));
803- usb_dcache_clean ((uintptr_t )& g_periodic_qh_head [bus -> hcd .hcd_id ].hw , USB_ALIGN_UP (SIZEOF_EHCI_QH , CONFIG_USB_EHCI_ALIGN_SIZE ));
800+ #if CONFIG_USB_EHCI_QH_QTD_DCACHE_ENABLE
801+ usb_dcache_clean ((uintptr_t )& g_async_qh_head [bus -> hcd .hcd_id ].hw , CONFIG_USB_EHCI_ALIGN_SIZE );
802+ usb_dcache_clean ((uintptr_t )& g_periodic_qh_head [bus -> hcd .hcd_id ].hw , CONFIG_USB_EHCI_ALIGN_SIZE );
804803 usb_dcache_clean ((uintptr_t )g_framelist [bus -> hcd .hcd_id ], sizeof (uint32_t ) * CONFIG_USB_EHCI_FRAME_LIST_SIZE );
804+ #endif
805805
806806 usb_hc_low_level_init (bus );
807807
0 commit comments