RE: xhci data toggle out of sync

From: Mahesh Vardhamanaiah <maheshmv_at_juniper.net>
Date: Tue, 19 Apr 2022 08:40:37 UTC
Hi Hans Petter Selasky,
After revert also same issue. I do see lot of reset/stop failures on end point before I see the read errors.
Diff.
diff --git a/sys/dev/usb/controller/xhci.c b/sys/dev/usb/controller/xhci.c
index 70a73dcc94c..48c8fef69e7 100644
--- a/sys/dev/usb/controller/xhci.c
+++ b/sys/dev/usb/controller/xhci.c
@@ -3895,6 +3895,7 @@ xhci_configure_reset_endpoint(struct usb_xfer *xfer)
         * Get the endpoint into the stopped state according to the
         * endpoint context state diagram in the XHCI specification:
         */
+#if 0
        switch (xhci_get_endpoint_state(udev, epno)) {
        case XHCI_EPCTX_0_EPSTATE_DISABLED:
                 break;
@@ -3909,8 +3910,24 @@ xhci_configure_reset_endpoint(struct usb_xfer *xfer)
                err = xhci_cmd_stop_ep(sc, 0, epno, index);
                if (err != 0)
                        DPRINTF("Could not stop endpoint %u\n", epno);
+               /*
+                * Need to reset the data toggle, because stop
+                * endpoint doesn't do that:
+                */
+               err = xhci_cmd_reset_ep(sc, 0, epno, index);
+               if (err != 0)
+                       DPRINTF("Mahesh Could not reset endpoint %u\n", epno);
                break;
        }
+#endif
+
+       err = xhci_cmd_stop_ep(sc, 0, epno, index);
+       if (err !=0)
+               device_printf(sc->sc_bus.parent, "MMV Could not stop endpoint %u\n", epno);
+
+       err = xhci_cmd_reset_ep(sc, 0, epno, index);
+       if (err !=0)
+               device_printf(sc->sc_bus.parent, "MMV Could not reset endpoint %u\n", epno);

        err = xhci_cmd_set_tr_dequeue_ptr(sc,
            (pepext->physaddr + (stream_id * sizeof(struct xhci_trb)


Errors:

Tue Apr 19 14:02xhci0: MMV Could not stop endpoint 3
xhci0: MMV Could not stop endpoint 3
xhci0: MMV Could not reset endpoint 3
xhci0: MMV Could not stop endpoint 3
xhci0: MMV Could not stop endpoint 3
xhci0: MMV Could not reset endpoint 3

FreeBSD/arm (Amnesiac) (ttyu0)

login: xhci0: MMV Could not stop endpoint 3
xhci0: MMV Could not stop endpoint 3
xhci0: MMV Could not reset endpoint 3
xhci0: MMV Could not stop endpoint 3
xhci0: MMV Could not stop endpoint 3
xhci0: MMV Could not reset endpoint 3
xhci0: MMV Could not stop endpoint 3

(da0:umass-sim0:0:0:0): READ(10). CDB: 28 00 00 b1 51 28 00 00 80 00
(da0:umass-sim0:0:0:0): CAM status: CCB request completed with an error
(da0:umass-sim0:0:0:0): Retrying command, 3 more tries remain


xhci0: MMV Could not reset endpoint 2
xhci0: MMV Could not stop endpoint 3
xhci0: MMV Could not reset endpoint 3
xhci0: MMV Could not stop endpoint 3
xhci0: MMV Could not stop endpoint 3
xhci0: MMV Could not reset endpoint 3


root@:RE:0% usbconfig dump_all_desc
ugen0.1: <Marvell XHCI root HUB> at usbus0, cfg=0 md=HOST spd=SUPER (5.0Gbps) pwr=SAVE (0mA)

  bLength = 0x0012
  bDescriptorType = 0x0001
  bcdUSB = 0x0300
  bDeviceClass = 0x0009  <HUB>
  bDeviceSubClass = 0x0000
  bDeviceProtocol = 0x0003
  bMaxPacketSize0 = 0x0009
  idVendor = 0x0000
  idProduct = 0x0000
  bcdDevice = 0x0100
  iManufacturer = 0x0001  <Marvell>
  iProduct = 0x0002  <XHCI root HUB>
  iSerialNumber = 0x0000  <no string>
  bNumConfigurations = 0x0001

 Configuration index 0

    bLength = 0x0009
    bDescriptorType = 0x0002
    wTotalLength = 0x001f
    bNumInterfaces = 0x0001
    bConfigurationValue = 0x0001
    iConfiguration = 0x0000  <no string>
    bmAttributes = 0x0040
    bMaxPower = 0x0000

    Interface 0
      bLength = 0x0009
      bDescriptorType = 0x0004
      bInterfaceNumber = 0x0000
      bAlternateSetting = 0x0000
      bNumEndpoints = 0x0001
      bInterfaceClass = 0x0009  <HUB>
      bInterfaceSubClass = 0x0000
      bInterfaceProtocol = 0x0000
      iInterface = 0x0000  <no string>

     Endpoint 0
        bLength = 0x0007
        bDescriptorType = 0x0005
        bEndpointAddress = 0x0081  <IN>
        bmAttributes = 0x0003  <INTERRUPT>
        wMaxPacketSize = 0x0002
        bInterval = 0x00ff
        bRefresh = 0x0000
        bSynchAddress = 0x0000

      Additional Descriptor

      bLength = 0x06
      bDescriptorType = 0x30
      bDescriptorSubType = 0x00
       RAW dump:
       0x00 | 0x06, 0x30, 0x00, 0x00, 0x00, 0x00




ugen0.2: <vendor 0x05e3 USB2.0 Hub> at usbus0, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=SAVE (100mA)

  bLength = 0x0012
  bDescriptorType = 0x0001
  bcdUSB = 0x0200
  bDeviceClass = 0x0009  <HUB>
  bDeviceSubClass = 0x0000
  bDeviceProtocol = 0x0001
  bMaxPacketSize0 = 0x0040
  idVendor = 0x05e3
  idProduct = 0x0608
  bcdDevice = 0x6070
  iManufacturer = 0x0000  <no string>
  iProduct = 0x0001  <USB2.0 Hub>
  iSerialNumber = 0x0000  <no string>
  bNumConfigurations = 0x0001

 Configuration index 0

    bLength = 0x0009
    bDescriptorType = 0x0002
    wTotalLength = 0x0019
    bNumInterfaces = 0x0001
    bConfigurationValue = 0x0001
    iConfiguration = 0x0000  <no string>
    bmAttributes = 0x00e0
    bMaxPower = 0x0032

    Interface 0
      bLength = 0x0009
      bDescriptorType = 0x0004
      bInterfaceNumber = 0x0000
      bAlternateSetting = 0x0000
      bNumEndpoints = 0x0001
      bInterfaceClass = 0x0009  <HUB>
      bInterfaceSubClass = 0x0000
      bInterfaceProtocol = 0x0000
      iInterface = 0x0000  <no string>

     Endpoint 0
        bLength = 0x0007
        bDescriptorType = 0x0005
        bEndpointAddress = 0x0081  <IN>
        bmAttributes = 0x0003  <INTERRUPT>
        wMaxPacketSize = 0x0001
        bInterval = 0x000c
        bRefresh = 0x0000
        bSynchAddress = 0x0000



ugen0.3: <Virtium VTDU31XC008G-A901> at usbus0, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=ON (100mA)

  bLength = 0x0012
  bDescriptorType = 0x0001
  bcdUSB = 0x0200
  bDeviceClass = 0x0000  <Probed by interface class>
  bDeviceSubClass = 0x0000
  bDeviceProtocol = 0x0000
  bMaxPacketSize0 = 0x0040
  idVendor = 0x2aaa
  idProduct = 0x0100
  bcdDevice = 0x0100
  iManufacturer = 0x0001  <Virtium>
  iProduct = 0x0003  <VTDU31XC008G-A901>
  iSerialNumber = 0x0002  <P1T66005607903260063>
  bNumConfigurations = 0x0001

 Configuration index 0

    bLength = 0x0009
    bDescriptorType = 0x0002
    wTotalLength = 0x0020
    bNumInterfaces = 0x0001
    bConfigurationValue = 0x0001
    iConfiguration = 0x0000  <no string>
    bmAttributes = 0x0080
    bMaxPower = 0x0032

    Interface 0
      bLength = 0x0009
      bDescriptorType = 0x0004
      bInterfaceNumber = 0x0000
      bAlternateSetting = 0x0000
      bNumEndpoints = 0x0002
      bInterfaceClass = 0x0008  <Mass storage>
      bInterfaceSubClass = 0x0006
      bInterfaceProtocol = 0x0050
      iInterface = 0x0000  <no string>

     Endpoint 0
        bLength = 0x0007
        bDescriptorType = 0x0005
        bEndpointAddress = 0x0081  <IN>
        bmAttributes = 0x0002  <BULK>
        wMaxPacketSize = 0x0200
        bInterval = 0x0000
        bRefresh = 0x0000
        bSynchAddress = 0x0000

     Endpoint 1
        bLength = 0x0007
        bDescriptorType = 0x0005
        bEndpointAddress = 0x0001  <OUT>
        bmAttributes = 0x0002  <BULK>
        wMaxPacketSize = 0x0200
        bInterval = 0x0000
        bRefresh = 0x0000
        bSynchAddress = 0x0000



==

Thanks,
Mahesh


Juniper Business Use Only

-----Original Message-----
From: Hans Petter Selasky <hps@selasky.org> 
Sent: Tuesday, April 19, 2022 12:33 PM
To: Mahesh Vardhamanaiah <maheshmv@juniper.net>; freebsd-usb@freebsd.org
Cc: Steve Kiernan <stevek@juniper.net>; Justin Hibbits <jhibbits@juniper.net>; Kumara N Babu <bkumara@juniper.net>; Kamal Prasad <krprasad@juniper.net>; Kristof Provost <kp@FreeBSD.org>; Bjoern A. Zeeb <bz@FreeBSD.org>
Subject: Re: xhci data toggle out of sync

[External Email. Be cautious of content]


Hi Mahesh,

What happens if you revert SVN r365239?

--HPS