Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USB endpoint bufsz can prevent large i2c transfers #3

Open
azanegin opened this issue Nov 23, 2022 · 3 comments
Open

USB endpoint bufsz can prevent large i2c transfers #3

azanegin opened this issue Nov 23, 2022 · 3 comments

Comments

@azanegin
Copy link

azanegin commented Nov 23, 2022

If you getting EOVERFLOW out of nowhere - be aware of this line:

const size_t FTDI_IO_BUFFER_SIZE = 65536;

Most likely your FTDI device is using USB <= 2.0. Bulk endpoints of USB 2.0 devices is limited in size by 512 bytes (check your actual size). AFAIK on (older?) linux kernels, buffer size to use with usb_bulk_msg must not be larger than endpoint buffer.

JUST setting FTDI_IO_BUFFER_SIZE to endpoint size could cause other problems, plus you will lose speed at USB 3.0

I temporarily fixed it like this:

static int ftdi_mpsse_read(struct ftdi_usb *ftdi, u8 *data, size_t size, size_t *read)
{
        int actual_length;
        int ret;
        int sz_real = min(512, size);

        ret = usb_bulk_msg(
                ftdi->udev,
                usb_rcvbulkpipe(ftdi->udev, ftdi->ep_in),
                /* data = */data,
                /* len = */sz_real,
                /* actual_length = */&actual_length,
                ftdi->io_timeout
        );
        *read = actual_length;
        return ret;
}

It worked cuz caller functions take care of large buffers themselves.

@bm16ton
Copy link
Owner

bm16ton commented Nov 24, 2022 via email

@bm16ton
Copy link
Owner

bm16ton commented Nov 26, 2022

Hopefully ill have time to check this out tomorrow (fingers crossed) any chance you could describe the setup you used to get the error so i could recreate this? Unfortunatly the offending line etc was a copy and paiste error. Early in this drivers life i had written it without any header file or human readable defines, i copied and paisted them from another persons driver, that driver didnt work for my devices and was a usb low speed device, and i just missed it. So do usb2 devices somehow get more msg bandwidth on usb3 ports? I would not have guessed that. I was under the assumption that usb2 devices connected to usb3 ports simply get routed to regular usb2 bus. Thank you again and i always like to ha e test setups that i kknow break certain things so that could be very useful

@azanegin
Copy link
Author

azanegin commented Dec 2, 2022

[I2C device]------[I2C lines - FT232H(The Shikra) - USB2.0 port]----------<USB2.0 cable>----------[USB3.0 port on PC under Linux 5.19]

This is my setup, hope it helps. AFAIK the problem is with large reads from small endpoint, but I do not know USB stack that good to tell it right away - I just googled and tried to fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants