Skip to content

[Bug] [cherryusb] [EHCI] 未刷新SETUP包缓存,导致enumerate fail #11749

Description

@Memory-afk

RT-Thread Version

v5.2.2

Affected area

Device drivers

Hardware/BSP vendor

Nuvoton

Architecture

ARM / AArch64

Board and hardware details

N9H30

Develop Toolchain

GCC

Describe the bug

未刷新 SETUP 包缓存前

  • LOG

    [I/USB] EHCI HCIVERSION:0x0095
    [I/USB] EHCI HCSPARAMS:0x000012
    [I/USB] EHCI HCCPARAMS:0x0000
    [I/USB] EHCI ppc:1, n_ports:2, n_cc:0, n_pcc:0
    [I/USB] EHCI uses tt for ls/fs device
    [D/usbh_hub] Port change:0x04
    [D/usbh_hub] Port change:0x04
    [D/usbh_hub] Port 2 change
    [D/usbh_hub] port 2, status:0x101, change:0x01
    [D/usbh_hub] Port 2, status:0x101, change:0x00
    [D/usbh_hub] Port 2, status:0x101, change:0x00
    [D/usbh_hub] Port 2, status:0x101, change:0x00
    [D/usbh_hub] Port 2, status:0x101, change:0x00
    [D/usbh_hub] Port 2, status:0x101, change:0x00
    [D/usbh_hub] Port 2, status:0x503, change:0x02
    [I/usbh_hub] New high-speed device on Bus 0, Hub 1, Port 2 connected
    [D/usbh_core] Setup: bmRequestType 0x80, bRequest 0x06, wValue 0x0100, wIndex 0x0000, wLength 0x0008
    [D/usbh_core] Device rev=0200 cls=09 sub=00 proto=02 size=64
    [D/usbh_core] Setup: bmRequestType 0x00, bRequest 0x05, wValue 0x0002, wIndex 0x0000, wLength 0x0000
    [W/usbh_core] Control transfer failed, errorcode -9, retrying...
    [W/usbh_core] Control transfer failed, errorcode -9, retrying...
    [E/usbh_core] Failed to set devaddr,errorcode:-9
    [I/usbh_core] Device on Bus 0, Hub 1, Port 2 disconnected
    [E/usbh_hub] Port 2 enumerate fail

刷新 SETUP 包缓存后

  • CODE

    #if defined(CONFIG_USB_EHCI_DESC_DCACHE_ENABLE)
        // 刷新 SETUP 包缓存
        usb_dcache_flush((uintptr_t)urb->setup, 8);
    #endif
    
    
    int usbh_submit_urb(struct usbh_urb *urb)
    {
        struct ehci_qh_hw *qh = NULL;
        size_t flags;
        int ret = 0;
        struct usbh_hub *hub;
        struct usbh_hubport *hport;
        struct usbh_bus *bus;
    
        if (!urb || !urb->hport || !urb->ep || !urb->hport->bus) {
            return -USB_ERR_INVAL;
        }
    
    #ifdef CONFIG_USB_DCACHE_ENABLE
        USB_ASSERT_MSG(!((uintptr_t)urb->setup % CONFIG_USB_ALIGN_SIZE) &&
                           !((uintptr_t)urb->transfer_buffer % CONFIG_USB_ALIGN_SIZE),
                       "urb->setup or urb->transfer_buffer is not aligned %d", CONFIG_USB_ALIGN_SIZE);
    #endif
        bus = urb->hport->bus;
    
        /* find active hubport in roothub */
        hport = urb->hport;
        hub = urb->hport->parent;
        while (!hub->is_roothub) {
            hport = hub->parent;
            hub = hub->parent->parent;
        }
    
    #ifdef CONFIG_USB_EHCI_WITH_OHCI
        if (EHCI_HCOR->portsc[hport->port - 1] & EHCI_PORTSC_OWNER) {
            return ohci_submit_urb(urb);
        }
    #endif
    
        if (!urb->hport->connected || !(EHCI_HCOR->portsc[hport->port - 1] & EHCI_PORTSC_CCS)) {
            return -USB_ERR_NOTCONN;
        }
    
        if (urb->errorcode == -USB_ERR_BUSY) {
            return -USB_ERR_BUSY;
        }
    
        flags = usb_osal_enter_critical_section();
    
        urb->hcpriv = NULL;
        urb->errorcode = -USB_ERR_BUSY;
        urb->actual_length = 0;
    
    #if defined(CONFIG_USB_EHCI_DESC_DCACHE_ENABLE)
        // 刷新 SETUP 包缓存
        usb_dcache_flush((uintptr_t)urb->setup, 8);
    #endif
    
        usb_osal_leave_critical_section(flags);
    
        switch (USB_GET_ENDPOINT_TYPE(urb->ep->bmAttributes)) {
            case USB_ENDPOINT_TYPE_CONTROL:
                qh = ehci_control_urb_init(bus, urb, urb->setup, urb->transfer_buffer, urb->transfer_buffer_length);
                if (qh == NULL) {
                    return -USB_ERR_NOMEM;
                }
                break;
            case USB_ENDPOINT_TYPE_BULK:
                qh = ehci_bulk_urb_init(bus, urb, urb->transfer_buffer, urb->transfer_buffer_length);
                if (qh == NULL) {
                    return -USB_ERR_NOMEM;
                }
                break;
            case USB_ENDPOINT_TYPE_INTERRUPT:
                qh = ehci_intr_urb_init(bus, urb, urb->transfer_buffer, urb->transfer_buffer_length);
                if (qh == NULL) {
                    return -USB_ERR_NOMEM;
                }
                break;
            case USB_ENDPOINT_TYPE_ISOCHRONOUS:
    #ifdef CONFIG_USB_EHCI_ISO
                ret = ehci_iso_urb_init(bus, urb);
    #endif
                break;
            default:
                break;
        }
    
        if (urb->timeout > 0) {
            /* wait until timeout or sem give */
            ret = usb_osal_sem_take(qh->waitsem, urb->timeout);
            if (ret < 0) {
                goto errout_timeout;
            }
            urb->timeout = 0;
            ret = urb->errorcode;
            /* we can free qh when waitsem is done */
            ehci_qh_free(bus, qh);
        }
        return ret;
    errout_timeout:
        urb->timeout = 0;
        usbh_kill_urb(urb);
        return ret;
    }
    
  • LOG

    [I/USB] EHCI HCIVERSION:0x0095
    [I/USB] EHCI HCSPARAMS:0x000012
    [I/USB] EHCI HCCPARAMS:0x0000
    [I/USB] EHCI ppc:1, n_ports:2, n_cc:0, n_pcc:0
    [I/USB] EHCI uses tt for ls/fs device
    [D/usbh_hub] Port change:0x04
    [D/usbh_hub] Port change:0x04
    [D/usbh_hub] Port 2 change
    [D/usbh_hub] port 2, status:0x101, change:0x01
    [D/usbh_hub] Port 2, status:0x101, change:0x00
    [D/usbh_hub] Port 2, status:0x101, change:0x00
    [D/usbh_hub] Port 2, status:0x101, change:0x00
    [D/usbh_hub] Port 2, status:0x101, change:0x00
    [D/usbh_hub] Port 2, status:0x101, change:0x00
    [D/usbh_hub] Port 2, status:0x503, change:0x02
    [I/usbh_hub] New high-speed device on Bus 0, Hub 1, Port 2 connected
    [D/usbh_core] Setup: bmRequestType 0x80, bRequest 0x06, wValue 0x0100, wIndex 0x0000, wLength 0x0008
    [D/usbh_core] Device rev=0200 cls=09 sub=00 proto=02 size=64
    [D/usbh_core] Setup: bmRequestType 0x00, bRequest 0x05, wValue 0x0002, wIndex 0x0000, wLength 0x0000
    [D/usbh_core] Setup: bmRequestType 0x80, bRequest 0x06, wValue 0x0100, wIndex 0x0000, wLength 0x0012
    [I/usbh_core] New device found,idVendor:1a86,idProduct:8091,bcdDevice:1310
    [I/usbh_core] The device has 1 bNumConfigurations
    [D/usbh_core] The device selects config 0
    [D/usbh_core] Setup: bmRequestType 0x80, bRequest 0x06, wValue 0x0200, wIndex 0x0000, wLength 0x0009
    [D/usbh_core] Setup: bmRequestType 0x80, bRequest 0x06, wValue 0x0200, wIndex 0x0000, wLength 0x0029
    [I/usbh_core] The device has 1 interfaces
    [D/usbh_core] Setup: bmRequestType 0x00, bRequest 0x09, wValue 0x0001, wIndex 0x0000, wLength 0x0000
    [I/usbh_core] Enumeration success, start loading class driver
    [I/usbh_core] Loading hub class driver on interface 0
    [D/usbh_core] Setup: bmRequestType 0xa0, bRequest 0x06, wValue 0x2900, wIndex 0x0000, wLength 0x0009
    [D/usbh_hub] Hub Descriptor:
    [D/usbh_hub] bLength: 0x09
    [D/usbh_hub] bDescriptorType: 0x29
    [D/usbh_hub] bNbrPorts: 0x04
    [D/usbh_hub] wHubCharacteristics: 0x0020
    [D/usbh_hub] bPwrOn2PwrGood: 0x30
    [D/usbh_hub] bHubContrCurrent: 0x64
    [D/usbh_hub] DeviceRemovable: 0x00
    [D/usbh_hub] PortPwrCtrlMask: 0xff
    [I/usbh_hub] Ep=81 Attr=03 Mps=1 Interval=12 Mult=00
    [D/usbh_core] Setup: bmRequestType 0x23, bRequest 0x03, wValue 0x0008, wIndex 0x0001, wLength 0x0000
    [D/usbh_core] Setup: bmRequestType 0x23, bRequest 0x03, wValue 0x0008, wIndex 0x0002, wLength 0x0000
    [D/usbh_core] Setup: bmRequestType 0x23, bRequest 0x03, wValue 0x0008, wIndex 0x0003, wLength 0x0000
    [D/usbh_core] Setup: bmRequestType 0x23, bRequest 0x03, wValue 0x0008, wIndex 0x0004, wLength 0x0000
    [D/usbh_core] Setup: bmRequestType 0xa3, bRequest 0x00, wValue 0x0000, wIndex 0x0001, wLength 0x0004
    [D/usbh_hub] port 1, status:0x101, change:0x01
    [D/usbh_core] Setup: bmRequestType 0xa3, bRequest 0x00, wValue 0x0000, wIndex 0x0002, wLength 0x0004
    [D/usbh_hub] port 2, status:0x100, change:0x00
    [D/usbh_core] Setup: bmRequestType 0xa3, bRequest 0x00, wValue 0x0000, wIndex 0x0003, wLength 0x0004
    [D/usbh_hub] port 3, status:0x100, change:0x00
    [D/usbh_core] Setup: bmRequestType 0xa3, bRequest 0x00, wValue 0x0000, wIndex 0x0004, wLength 0x0004
    [D/usbh_hub] port 4, status:0x100, change:0x00
    [I/usbh_hub] Register HUB Class:/dev/hub2
    [D/usbh_hub] Port change:0x02
    [D/usbh_hub] Port 1 change
    [D/usbh_core] Setup: bmRequestType 0xa3, bRequest 0x00, wValue 0x0000, wIndex 0x0001, wLength 0x0004
    [D/usbh_hub] port 1, status:0x101, change:0x01
    [D/usbh_core] Setup: bmRequestType 0x23, bRequest 0x01, wValue 0x0010, wIndex 0x0001, wLength 0x0000
    [D/usbh_core] Setup: bmRequestType 0xa3, bRequest 0x00, wValue 0x0000, wIndex 0x0001, wLength 0x0004
    [D/usbh_hub] Port 1, status:0x101, change:0x00
    [D/usbh_core] Setup: bmRequestType 0xa3, bRequest 0x00, wValue 0x0000, wIndex 0x0001, wLength 0x0004
    [D/usbh_hub] Port 1, status:0x101, change:0x00
    [D/usbh_core] Setup: bmRequestType 0xa3, bRequest 0x00, wValue 0x0000, wIndex 0x0001, wLength 0x0004
    [D/usbh_hub] Port 1, status:0x101, change:0x00
    [D/usbh_core] Setup: bmRequestType 0xa3, bRequest 0x00, wValue 0x0000, wIndex 0x0001, wLength 0x0004
    [D/usbh_hub] Port 1, status:0x101, change:0x00
    [D/usbh_core] Setup: bmRequestType 0xa3, bRequest 0x00, wValue 0x0000, wIndex 0x0001, wLength 0x0004
    [D/usbh_hub] Port 1, status:0x101, change:0x00
    [D/usbh_core] Setup: bmRequestType 0x23, bRequest 0x03, wValue 0x0004, wIndex 0x0001, wLength 0x0000
    [D/usbh_core] Setup: bmRequestType 0xa3, bRequest 0x00, wValue 0x0000, wIndex 0x0001, wLength 0x0004
    [D/usbh_hub] Port 1, status:0x503, change:0x10
    [D/usbh_core] Setup: bmRequestType 0x23, bRequest 0x01, wValue 0x0014, wIndex 0x0001, wLength 0x0000
    [I/usbh_hub] New high-speed device on Bus 0, Hub 2, Port 1 connected
    [D/usbh_core] Setup: bmRequestType 0x80, bRequest 0x06, wValue 0x0100, wIndex 0x0000, wLength 0x0008
    [D/usbh_core] Device rev=0200 cls=00 sub=00 proto=00 size=64
    [D/usbh_core] Setup: bmRequestType 0x00, bRequest 0x05, wValue 0x0003, wIndex 0x0000, wLength 0x0000
    [D/usbh_core] Setup: bmRequestType 0x80, bRequest 0x06, wValue 0x0100, wIndex 0x0000, wLength 0x0012
    [I/usbh_core] New device found,idVendor:0951,idProduct:1665,bcdDevice:0110
    [I/usbh_core] The device has 1 bNumConfigurations
    [D/usbh_core] The device selects config 0
    [D/usbh_core] Setup: bmRequestType 0x80, bRequest 0x06, wValue 0x0200, wIndex 0x0000, wLength 0x0009
    [D/usbh_core] Setup: bmRequestType 0x80, bRequest 0x06, wValue 0x0200, wIndex 0x0000, wLength 0x0020
    [I/usbh_core] The device has 1 interfaces
    [D/usbh_core] Setup: bmRequestType 0x00, bRequest 0x09, wValue 0x0001, wIndex 0x0000, wLength 0x0000
    [I/usbh_core] Enumeration success, start loading class driver
    [I/usbh_core] Loading msc class driver on interface 0
    [D/usbh_core] Setup: bmRequestType 0xa1, bRequest 0xfe, wValue 0x0000, wIndex 0x0000, wLength 0x0001
    [I/usbh_msc] Get max LUN:1
    [I/usbh_msc] Ep=81 Attr=02 Mps=512 Interval=00 Mult=00
    [I/usbh_msc] Ep=02 Attr=02 Mps=512 Interval=00 Mult=00
    [I/usbh_msc] Register MSC Class:/dev/sda
    [D/usbh_hub] Port change:0x00
    [D/usbh_hub] Port change:0x00
    [D/usbh_hub] Port change:0x00
    [D/usbh_msc] CBW:
    [D/usbh_msc] signature: 0x43425355
    [D/usbh_msc] tag: 0x00000000
    [D/usbh_msc] datlen: 0x00000000
    [D/usbh_msc] flags: 0x00
    [D/usbh_msc] lun: 0x00
    [D/usbh_msc] cblen: 0x06
    [D/usbh_msc] CB:
    [D/usbh_msc] 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
    [D/usbh_msc] CSW:
    [D/usbh_msc] signature: 0x53425355
    [D/usbh_msc] tag: 0x00000000
    [D/usbh_msc] residue: 0x00000000
    [D/usbh_msc] status: 0x00
    [D/usbh_msc] CBW:
    [D/usbh_msc] signature: 0x43425355
    [D/usbh_msc] tag: 0x00000000
    [D/usbh_msc] datlen: 0x00000024
    [D/usbh_msc] flags: 0x80
    [D/usbh_msc] lun: 0x00
    [D/usbh_msc] cblen: 0x06
    [D/usbh_msc] CB:
    [D/usbh_msc] 0x12 0x00 0x00 0x00 0x24 0x00 0x00 0x00
    [D/usbh_msc] CSW:
    [D/usbh_msc] signature: 0x53425355
    [D/usbh_msc] tag: 0x00000000
    [D/usbh_msc] residue: 0x00000000
    [D/usbh_msc] status: 0x00
    [D/usbh_msc] CBW:
    [D/usbh_msc] signature: 0x43425355
    [D/usbh_msc] tag: 0x00000000
    [D/usbh_msc] datlen: 0x00000008
    [D/usbh_msc] flags: 0x80
    [D/usbh_msc] lun: 0x00
    [D/usbh_msc] cblen: 0x0a
    [D/usbh_msc] CB:
    [D/usbh_msc] 0x25 0x00 0x00 0x00 0x00 0x00 0x00 0x00
    [D/usbh_msc] 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
    [D/usbh_msc] CSW:
    [D/usbh_msc] signature: 0x53425355
    [D/usbh_msc] tag: 0x00000000
    [D/usbh_msc] residue: 0x00000000
    [D/usbh_msc] status: 0x00
    [I/usbh_msc] Capacity info:
    [I/usbh_msc] Block num:30277632,block size:512
    [D/usbh_msc] CBW:
    [D/usbh_msc] signature: 0x43425355
    [D/usbh_msc] tag: 0x00000000
    [D/usbh_msc] datlen: 0x00000200
    [D/usbh_msc] flags: 0x80
    [D/usbh_msc] lun: 0x00
    [D/usbh_msc] cblen: 0x0a
    [D/usbh_msc] CB:
    [D/usbh_msc] 0x28 0x00 0x00 0x00 0x00 0x00 0x00 0x00
    [D/usbh_msc] 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00
    [D/usbh_msc] CSW:
    [D/usbh_msc] signature: 0x53425355
    [D/usbh_msc] tag: 0x00000000
    [D/usbh_msc] residue: 0x00000000
    [D/usbh_msc] status: 0x00
    [D/usbh_msc] CBW:
    [D/usbh_msc] signature: 0x43425355
    [D/usbh_msc] tag: 0x00000000
    [D/usbh_msc] datlen: 0x00000200
    [D/usbh_msc] flags: 0x80
    [D/usbh_msc] lun: 0x00
    [D/usbh_msc] cblen: 0x0a
    [D/usbh_msc] CB:
    [D/usbh_msc] 0x28 0x00 0x00 0x00 0x1f 0x80 0x00 0x00
    [D/usbh_msc] 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00
    [D/usbh_msc] CSW:
    [D/usbh_msc] signature: 0x53425355
    [D/usbh_msc] tag: 0x00000000
    [D/usbh_msc] residue: 0x00000000
    [D/usbh_msc] status: 0x00
    [D/usbh_msc] CBW:
    [D/usbh_msc] signature: 0x43425355
    [D/usbh_msc] tag: 0x00000000
    [D/usbh_msc] datlen: 0x00000200
    [D/usbh_msc] flags: 0x80
    [D/usbh_msc] lun: 0x00
    [D/usbh_msc] cblen: 0x0a
    [D/usbh_msc] CB:
    [D/usbh_msc] 0x28 0x00 0x00 0x00 0x1f 0x81 0x00 0x00
    [D/usbh_msc] 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00
    [D/usbh_msc] CSW:
    [D/usbh_msc] signature: 0x53425355
    [D/usbh_msc] tag: 0x00000000
    [D/usbh_msc] residue: 0x00000000
    [D/usbh_msc] status: 0x00
    udisk: /dev/sda mount successfully

Other additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions