RE: xhci data toggle out of sync

From: Mahesh Vardhamanaiah <maheshmv_at_juniper.net>
Date: Tue, 19 Apr 2022 11:36:07 UTC
Hi HPS,

Please find the diff below for the error prints.


[maheshmv@svl-bsdx-02 /b/maheshmv/usb_issue/src]$ git diff sys/dev/usb/controller/xhci.c
diff --git a/sys/dev/usb/controller/xhci.c b/sys/dev/usb/controller/xhci.c
index 70a73dcc94c..fa7c1062ada 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,25 @@ 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
+
+       device_printf(sc->sc_bus.parent, "MMV endpoint %u state %x\n", epno, xhci_get_endpoint_state(udev, epno));
+       err = xhci_cmd_stop_ep(sc, 0, epno, index);
+       if (err !=0)
+               device_printf(sc->sc_bus.parent, "MMV Could not stop endpoint %u err %x\n", epno, err);
+
+       err = xhci_cmd_reset_ep(sc, 0, epno, index);
+       if (err !=0)
+               device_printf(sc->sc_bus.parent, "MMV Could not reset endpoint %u err %x\n", epno, err);

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


Thanks,
Mahesh



Juniper Business Use Only

-----Original Message-----
From: Hans Petter Selasky <hps@selasky.org> 
Sent: Tuesday, April 19, 2022 5:03 PM
To: Kamal Prasad <krprasad@juniper.net>; 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>; 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]


On 4/19/22 12:59, Kamal Prasad wrote:
> Hi Peter,
>
>>>      Which is not a valid return code from xhci_do_command(). Can you check
>      where this value comes from?
>
> This is coming from this location in xhci_configure_endpoint() which in turn is called by xhci_configure_endpoint_by_xfer():-
> ---
>       epno = XHCI_EPNO2EPID(epno);
>
>          if (epno == 0)
>                  return (USB_ERR_NO_PIPE);               /* invalid */
> ---

Hi Kamal,

I'm asking about the value after "err" in these prints:

 >      > xhci0: MMV Could not stop endpoint 3 err 12
 >      > xhci0: MMV Could not reset endpoint 3 err 12

  3875
  3876         err = xhci_cmd_stop_ep(sc, 0, epno, index);
  3877
  3878         if (err != 0)
  3879                 DPRINTF("Could not stop endpoint %u\n", epno);
  3880
  3881         err = xhci_cmd_reset_ep(sc, 0, epno, index);
  3882
  3883         if (err != 0)
  3884                 DPRINTF("Could not reset endpoint %u\n", epno);
  3885

--HPS