lambdaconcept / ft60x_driver

21 stars 11 forks source link

ft60x_int_callback - urb shutting down with status: -108 (linux 6.2.10) #4

Open ardje opened 1 year ago

ardje commented 1 year ago

Hi guys,

I am trying to get my usb2sniffer to work, but upon pluging in, I get this:

[462615.961437] FT60x i/f 0 now probed: (0403:601F)
[462615.961443] ID->bNumEndpoints: 02
[462615.961446] ID->bInterfaceClass: FF
[462615.961448] ED[0]->bEndpointAddress: 0x01
[462615.961451] ED[0]->bmAttributes: 0x02
[462615.961453] ED[0]->wMaxPacketSize: 0x0200 (512)
[462615.961456] ED[1]->bEndpointAddress: 0x81
[462615.961458] ED[1]->bmAttributes: 0x03
[462615.961459] ED[1]->wMaxPacketSize: 0x0040 (64)
[462615.961464] maxp = 64
[462615.962239] FT60x i/f 1 now probed: (0403:601F)
[462615.962245] ID->bNumEndpoints: 02
[462615.962247] ID->bInterfaceClass: FF
[462615.962249] ED[0]->bEndpointAddress: 0x02
[462615.962251] ED[0]->bmAttributes: 0x02
[462615.962253] ED[0]->wMaxPacketSize: 0x0200 (512)
[462615.962266] ED[1]->bEndpointAddress: 0x82
[462615.962268] ED[1]->bmAttributes: 0x02
[462615.962269] ED[1]->wMaxPacketSize: 0x0200 (512)
[462615.962414] ft60x 3-2:1.1: USB FT60x device now attached to ft60x-0
[462618.499149] ft60x_int_callback - urb shutting down with status: -108

And these are my changes:

ard@lenny:/mnt/source/ard/usb2sniffer/ft60x_driver$ git diff -u
diff --git a/ft60x.c b/ft60x.c
index 2e92cec..3d5036a 100644
--- a/ft60x.c
+++ b/ft60x.c
@@ -464,7 +464,7 @@ static int ft60x_send_cmd_read(struct usb_ft60x *dev, size_t count)
        dev->ft->ctrlreq.pipe = dev->bulk_in_endpointAddr;
        dev->ft->ctrlreq.cmd = 1;
        if (notif) {
-               dev->ft->ctrlreq.len = min(dev->bulk_in_size * 128, dev->len_to_read);
+               dev->ft->ctrlreq.len = min_t(size_t,dev->bulk_in_size * 128, dev->len_to_read);
        } else {
                dev->ft->ctrlreq.len = dev->bulk_in_size * 128;
        }
@@ -507,7 +507,7 @@ static int ft60x_do_read_io(struct usb_ft60x *dev, size_t count)
                                  usb_rcvbulkpipe(dev->udev,
                                                  dev->bulk_in_endpointAddr),
                                  dev->bulk_in_buffer,
-                                 min(dev->bulk_in_size * 128,
+                                 min_t(size_t,dev->bulk_in_size * 128,
                                      dev->len_to_read),
                                  ft60x_read_bulk_callback, dev);
        } else {
@@ -1061,7 +1061,9 @@ static int ft60x_alloc_ctrl_interface(struct usb_ft60x *dev,
                        /* get a handle to the interrupt data pipe */
                        pipe = usb_rcvintpipe(dev->udev,
                                              endpoint->bEndpointAddress);
-                       maxp = usb_maxpacket(dev->udev, pipe, usb_pipeout(pipe));
+                       //maxp = usb_maxpacket(dev->udev, pipe, usb_pipeout(pipe));
+                       maxp = usb_maxpacket(dev->udev, pipe);
+                       printk(KERN_INFO "maxp = %d\n", maxp);
                        usb_fill_int_urb(dev->int_in_urb, dev->udev, pipe,
                                         dev->int_in_buffer, maxp,
                                         ft60x_int_callback, dev,

As far as I know, these were just necessary janitory changes: usb_maxpacket had an argument that was obsolete. The maxp is still 64 for an INT message, so that looks ok. the min_t is a typed change.

I put it here as an issue because maybe someone else knows of more changes in the linux kernel, or my last few years not programming in C has made the obvious less obvious to me.

Anyway: I tried usbsniffer-qt and that seems not to get any data from the sniffer, and I suspect that's because the URB is shutdown, and hence all communication with the board has halted because we don't schedule any new interrupt polls. The USB shutdown happens on plugin. As far as I can tell, there are 2 interfaces being used.

Hmmm, I should be able to sniff what's going on with mere tcpdump...

For completeness: the usb device descriptor:

ard@lenny:~$ sudo lsusb -v -d 0403:601f
[sudo] password for ard:

Bus 003 Device 005: ID 0403:601f Future Technology Devices International, Ltd Myriad-RF LimeSDR-Mini
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.10
  bDeviceClass          239 Miscellaneous Device
  bDeviceSubClass         2
  bDeviceProtocol         1 Interface Association
  bMaxPacketSize0        64
  idVendor           0x0403 Future Technology Devices International, Ltd
  idProduct          0x601f Myriad-RF LimeSDR-Mini
  bcdDevice            0.00
  iManufacturer           1 FTDI
  iProduct                2 FTDI SuperSpeed-FIFO Bridge
  iSerial                 3 000000000001
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x003f
    bNumInterfaces          2
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0xe0
      Self Powered
      Remote Wakeup
    MaxPower               96mA
    Interface Association:
      bLength                 8
      bDescriptorType        11
      bFirstInterface         0
      bInterfaceCount         2
      bFunctionClass        255 Vendor Specific Class
      bFunctionSubClass     255 Vendor Specific Subclass
      bFunctionProtocol     255 Vendor Specific Protocol
      iFunction               0
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass    255 Vendor Specific Subclass
      bInterfaceProtocol    255 Vendor Specific Protocol
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x01  EP 1 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               9
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass    255 Vendor Specific Subclass
      bInterfaceProtocol    255 Vendor Specific Protocol
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0
Binary Object Store Descriptor:
  bLength                 5
  bDescriptorType        15
  wTotalLength       0x0016
  bNumDeviceCaps          2
  USB 2.0 Extension Device Capability:
    bLength                 7
    bDescriptorType        16
    bDevCapabilityType      2
    bmAttributes   0x00000006
      BESL Link Power Management (LPM) Supported
  SuperSpeed USB Device Capability:
    bLength                10
    bDescriptorType        16
    bDevCapabilityType      3
    bmAttributes         0x00
    wSpeedsSupported   0x000e
      Device can operate at Full Speed (12Mbps)
      Device can operate at High Speed (480Mbps)
      Device can operate at SuperSpeed (5Gbps)
    bFunctionalitySupport   2
      Lowest fully-functional device speed is High Speed (480Mbps)
    bU1DevExitLat          10 micro seconds
    bU2DevExitLat        2047 micro seconds
Device Status:     0x000d
  Self Powered
  Test Mode
ardje commented 1 year ago

Compiling it for an older 5.4.6 kernel on ARM gives me:

[  129.329495] usb 1-1: new high-speed USB device number 2 using exynos-ehci
[  129.491215] usb 1-1: New USB device found, idVendor=0403, idProduct=601f, bcdDevice= 0.00
[  129.497985] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[  129.505077] usb 1-1: Product: FTDI SuperSpeed-FIFO Bridge
[  129.510460] usb 1-1: Manufacturer: FTDI
[  129.514267] usb 1-1: SerialNumber: 000000000001
[  129.519504] FT60x i/f 0 now probed: (0403:601F)
[  129.523273] ID->bNumEndpoints: 02
[  129.526575] ID->bInterfaceClass: FF
[  129.530012] ED[0]->bEndpointAddress: 0x01
[  129.534002] ED[0]->bmAttributes: 0x02
[  129.537643] ED[0]->wMaxPacketSize: 0x0200 (512)
[  129.542152] ED[1]->bEndpointAddress: 0x81
[  129.546132] ED[1]->bmAttributes: 0x03
[  129.549804] ED[1]->wMaxPacketSize: 0x0040 (64)
[  129.554994] FT60x i/f 1 now probed: (0403:601F)
[  129.558719] ID->bNumEndpoints: 02
[  129.561989] ID->bInterfaceClass: FF
[  129.565407] ED[0]->bEndpointAddress: 0x02
[  129.569473] ED[0]->bmAttributes: 0x02
[  129.573033] ED[0]->wMaxPacketSize: 0x0200 (512)
[  129.577588] ED[1]->bEndpointAddress: 0x82
[  129.581599] ED[1]->bmAttributes: 0x02
[  129.585165] ED[1]->wMaxPacketSize: 0x0200 (512)
[  129.589940] ft60x 1-1:1.1: USB FT60x device now attached to ft60x-192

Which is nice, but it's a headless device. Also this is USB2. So this is tested:

  1. Odroid MC1 exynos5422 5.4.6 kernel on usb 2 slot: works (as in, urbs are recycled, not shutdown)
  2. Thinkpad T430 on usb 3 slot: does not work on ubuntu vanilla kernel 6.2, nor ubuntu distro kernel 5.16

I do need to test the usb2 slot, as the T430 is from 2012, so there might be bugs in the xhci, but for now I assume the kernel between 5.4 and 5.16 has changed in a way that makes this driver fail. (5.4 already complains about min types though)

ardje commented 1 year ago

Confirmed: on T430 also on 5.16 the URB is shut down.

ardje commented 1 year ago

Confirmed: on a T430, after setting up the configuration and the int urb, the kernel sends a port configuration change to the usb hub for that port after which the int urb is shut down. On another thinkpad with 5.10 there are no shutdown urbs, however the qt program still reports no data transfer.