From 363533be4c124ba1d5c5f5976248bea4f8924a3a Mon Sep 17 00:00:00 2001 From: sakumisu <1203593632@qq.com> Date: Sun, 12 May 2024 13:03:33 +0800 Subject: [PATCH] update(class/vendor/net/usbh_rtl8152): update eth rx/tx size --- cherryusb_config_template.h | 11 +++++++++++ class/vendor/net/usbh_rtl8152.c | 22 +++++++++++++--------- demo/usb_host.c | 2 +- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/cherryusb_config_template.h b/cherryusb_config_template.h index 26725143..f0370fb9 100644 --- a/cherryusb_config_template.h +++ b/cherryusb_config_template.h @@ -168,6 +168,17 @@ #define CONFIG_USBHOST_CDC_NCM_ETH_MAX_TX_SIZE (2048) #endif +/* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size, + * you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow. + */ +#ifndef CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE +#define CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE (2048) +#endif +/* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */ +#ifndef CONFIG_USBHOST_RTL8152_ETH_MAX_TX_SIZE +#define CONFIG_USBHOST_RTL8152_ETH_MAX_TX_SIZE (2048) +#endif + #define CONFIG_USBHOST_BLUETOOTH_HCI_H4 // #define CONFIG_USBHOST_BLUETOOTH_HCI_LOG diff --git a/class/vendor/net/usbh_rtl8152.c b/class/vendor/net/usbh_rtl8152.c index bec8b9d9..7ff103cb 100644 --- a/class/vendor/net/usbh_rtl8152.c +++ b/class/vendor/net/usbh_rtl8152.c @@ -12,11 +12,15 @@ #define DEV_FORMAT "/dev/rtl8152" -#define CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SEGSZE (16 * 1024) -#define CONFIG_USBHOST_RTL8152_ETH_MAX_SEGSZE (2048) +#ifndef CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE +#define CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE (16*1024) +#endif +#ifndef CONFIG_USBHOST_RTL8152_ETH_MAX_TX_SIZE +#define CONFIG_USBHOST_RTL8152_ETH_MAX_TX_SIZE (2048) +#endif -static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_rtl8152_rx_buffer[CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SEGSZE]; -static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_rtl8152_tx_buffer[CONFIG_USBHOST_RTL8152_ETH_MAX_SEGSZE]; +static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_rtl8152_rx_buffer[CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE]; +static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_rtl8152_tx_buffer[CONFIG_USBHOST_RTL8152_ETH_MAX_TX_SIZE]; static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_rtl8152_inttx_buffer[2]; USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_rtl8152_buf[32]; @@ -2034,8 +2038,8 @@ static int usbh_rtl8152_connect(struct usbh_hubport *hport, uint8_t intf) rtl8152_class->rtl_ops.init(rtl8152_class); rtl8152_class->rtl_ops.up(rtl8152_class); - if (rtl8152_class->rx_buf_sz > CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SEGSZE) { - USB_LOG_ERR("rx_buf_sz is overflow, default is %d\r\n", CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SEGSZE); + if (rtl8152_class->rx_buf_sz > CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE) { + USB_LOG_ERR("rx_buf_sz is overflow, default is %d\r\n", CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE); return -USB_ERR_NOMEM; } @@ -2165,7 +2169,7 @@ find_class: g_rtl8152_rx_length = 0; while (1) { - usbh_bulk_urb_fill(&g_rtl8152_class.bulkin_urb, g_rtl8152_class.hport, g_rtl8152_class.bulkin, &g_rtl8152_rx_buffer[g_rtl8152_rx_length], USB_GET_MAXPACKETSIZE(g_rtl8152_class.bulkin->wMaxPacketSize), USB_OSAL_WAITING_FOREVER, NULL, NULL); + usbh_bulk_urb_fill(&g_rtl8152_class.bulkin_urb, g_rtl8152_class.hport, g_rtl8152_class.bulkin, &g_rtl8152_rx_buffer[g_rtl8152_rx_length], (CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE > (16 * 1024)) ? (16 * 1024) : CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE, USB_OSAL_WAITING_FOREVER, NULL, NULL); ret = usbh_submit_urb(&g_rtl8152_class.bulkin_urb); if (ret < 0) { goto find_class; @@ -2173,7 +2177,7 @@ find_class: g_rtl8152_rx_length += g_rtl8152_class.bulkin_urb.actual_length; - if (g_rtl8152_class.bulkin_urb.actual_length != USB_GET_MAXPACKETSIZE(g_rtl8152_class.bulkin->wMaxPacketSize)) { + if (g_rtl8152_rx_length % USB_GET_MAXPACKETSIZE(g_rtl8152_class.bulkin->wMaxPacketSize)) { data_offset = 0; USB_LOG_DBG("rxlen:%d\r\n", g_rtl8152_rx_length); @@ -2207,7 +2211,7 @@ find_class: } } } else { - if (g_rtl8152_rx_length > CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SEGSZE) { + if (g_rtl8152_rx_length > CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE) { USB_LOG_ERR("Rx packet is overflow\r\n"); g_rtl8152_rx_length = 0; } diff --git a/demo/usb_host.c b/demo/usb_host.c index 46fe751f..9bdd17ac 100644 --- a/demo/usb_host.c +++ b/demo/usb_host.c @@ -1018,7 +1018,7 @@ void usbh_rtl8152_run(struct usbh_rtl8152 *rtl8152_class) } } - usb_osal_thread_create("usbh_rtl8152_rx", 2048, 20, usbh_rtl8152_rx_thread, netif); + usb_osal_thread_create("usbh_rtl8152_rx", 2048, CONFIG_USBHOST_PSC_PRIO + 1, usbh_rtl8152_rx_thread, netif); #if LWIP_DHCP dhcp_start(netif); xTimerStart(dhcp_handle, 0);