# EVDO PCMCIA cards usb-serial.c patch resolves timeouts

## nick-oshean

If you are experiencing timeouts and dropouts with your PCMCIA EVDO card it is probably due to:

http://www.junxion.com/opensource/linux_highspeed_usbserial.html

This page has a patch that will not work against the current Gentoo-Sources 2.6.x usb-serial.c file, so attachted is an updated patch file that will work.

Edit:This patch works and has been tested with 2.6.15-gentoo-r1. 

```

--- usb-serial.c.orig   2006-01-28 21:18:31.000000000 -0500

+++ usb-serial.c        2006-01-28 21:22:24.000000000 -0500

@@ -55,6 +55,7 @@

    drivers depend on it.

 */

 

+static ushort maxSize = 0;

 static int debug;

 static struct usb_serial *serial_table[SERIAL_TTY_MINORS];     /* initially all NULL */

 static LIST_HEAD(usb_serial_driver_list);

@@ -755,7 +756,7 @@

                        dev_err(&interface->dev, "No free urbs available\n");

                        goto probe_error;

                }

-               buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);

+               buffer_size = (endpoint->wMaxPacketSize > maxSize)?endpoint->wMaxPacketSize:maxSize;

                port->bulk_in_size = buffer_size;

                port->bulk_in_endpointAddress = endpoint->bEndpointAddress;

                port->bulk_in_buffer = kmalloc (buffer_size, GFP_KERNEL);

@@ -1130,3 +1131,5 @@

 

 module_param(debug, bool, S_IRUGO | S_IWUSR);

 MODULE_PARM_DESC(debug, "Debug enabled or not");

+module_param(maxSize, ushort,0);

+MODULE_PARM_DESC(maxSize,"User specified USB endpoint size");

```

This add's a maxSize parameter.

So for my Kyocera KPC650 I use:

usbserial vendor=0x0c88 product=0x17da maxSize=2048

Replace vendor= and product= with your card's info.

Hope it helps!

----------

## steevdave

I couldn't get this to apply cleanly with recent kernels, so I have updated it - this applies against 2.6.14 and 2.6.15 (vanilla on .15) for me.  The updated patch can be found at http://dev.gentoo.org/~steev/files/patches/gentoo-usb-serial-maxSize.patch

----------

## nick-oshean

The above patch will not patch cleanly against 2.6.15-gentoo-r1. It can easily be modified to do so, I will post an updated patch and edit my inital post when I have more time.

Edit:My inital post has been edited with an updated patch that patches cleanly against 2.6.15-gentoo-r1.

----------

## BrianW

I was unable to get the patch in the first post to patch cleanly. It was failing on the middle hunk. It seems that the above patch has one indentation too many for the middle hunk. Here is what worked for me:

```

--- usb-serial.c.orig   2006-03-12 21:25:43.000000000 -0800

+++ usb-serial.c        2006-03-12 23:32:20.000000000 -0800

@@ -55,6 +55,7 @@

    drivers depend on it.

 */

+static ushort maxSize = 0;

 static int debug;

 static struct usb_serial *serial_table[SERIAL_TTY_MINORS];     /* initially all NULL */

 static LIST_HEAD(usb_serial_driver_list);

@@ -755,7 +756,7 @@

                        dev_err(&interface->dev, "No free urbs available\n");

                        goto probe_error;

                }

-               buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);

+               buffer_size = (endpoint->wMaxPacketSize > maxSize)?endpoint->wMaxPacketSize:maxSize;

                port->bulk_in_size = buffer_size;

                port->bulk_in_endpointAddress = endpoint->bEndpointAddress;

                port->bulk_in_buffer = kmalloc (buffer_size, GFP_KERNEL);

@@ -1130,3 +1131,5 @@

 module_param(debug, bool, S_IRUGO | S_IWUSR);

 MODULE_PARM_DESC(debug, "Debug enabled or not");

+module_param(maxSize, ushort,0);

+MODULE_PARM_DESC(maxSize,"User specified USB endpoint size");

```

Hope it helps, and thank you steev-laptop  :Smile: 

BrianW

----------

## xvalentinex

Hello, I was wondering if anyone could help me with compiling this.  The command to compile from junction seems to fail.  I am actually doing this on my laptop which runs Ubuntu, but don't fret I use gentoo on my Home Desktop   :Laughing:  .  The patch didn't work, but it's simple enough that I went in and edited it by hand.

 RESOLVED: Running 'make modules' from /usr/src/linux was my fix, but probably only worked because I had custom vanilla kernel.  It would still be nice to know if one module could be compiled vs. make modules which compiles everyone.

Any help would be greatly appreciated.

Thanks

Here are the logs:

```
gcc -D__KERNEL__ -I/usr/src/linux-2.6.17-emission8/include -Wall -Wstrict-prototypes -Wno-trigraphs -02 -fno-strict-aliasing -fno-common -fomit-frame-pointer -pipe -mpreferred-stack-boundary=2 -march=i386 -DMODULE -nostdinc -iwithprefix include -DKBUILD_BASENAME=usbserial-maxsize -DEXPORT_SYMTAB -c usb-serial.c

gcc: unrecognized option '-02'

In file included from /usr/src/linux-2.6.17-emission8/include/linux/rwsem.h:27,

                 from /usr/src/linux-2.6.17-emission8/include/linux/notifier.h:14,

                 from /usr/src/linux-2.6.17-emission8/include/linux/memory_hotplug.h:7,

                 from /usr/src/linux-2.6.17-emission8/include/linux/mmzone.h:333,

                 from /usr/src/linux-2.6.17-emission8/include/linux/gfp.h:4,

                 from /usr/src/linux-2.6.17-emission8/include/linux/slab.h:15,

                 from usb-serial.c:23:

/usr/src/linux-2.6.17-emission8/include/asm/rwsem.h: In function __down_read:

/usr/src/linux-2.6.17-emission8/include/asm/rwsem.h:105: error: syntax error before usbserial

/usr/src/linux-2.6.17-emission8/include/asm/rwsem.h: In function __down_write:

/usr/src/linux-2.6.17-emission8/include/asm/rwsem.h:157: error: syntax error before usbserial

/usr/src/linux-2.6.17-emission8/include/asm/rwsem.h: In function __up_read:

/usr/src/linux-2.6.17-emission8/include/asm/rwsem.h:194: error: syntax error before usbserial

/usr/src/linux-2.6.17-emission8/include/asm/rwsem.h:188: warning: unused variable tmp

/usr/src/linux-2.6.17-emission8/include/asm/rwsem.h: In function __up_write:

/usr/src/linux-2.6.17-emission8/include/asm/rwsem.h:220: error: syntax error before usbserial

/usr/src/linux-2.6.17-emission8/include/asm/rwsem.h: In function __downgrade_write:

/usr/src/linux-2.6.17-emission8/include/asm/rwsem.h:245: error: syntax error before usbserial

In file included from /usr/src/linux-2.6.17-emission8/include/linux/sched.h:20,

                 from /usr/src/linux-2.6.17-emission8/include/linux/radix-tree.h:23,

                 from /usr/src/linux-2.6.17-emission8/include/linux/fs.h:231,

                 from /usr/src/linux-2.6.17-emission8/include/linux/tty.h:20,

                 from usb-serial.c:24:

/usr/src/linux-2.6.17-emission8/include/asm/semaphore.h: In function down:

/usr/src/linux-2.6.17-emission8/include/asm/semaphore.h:105: error: syntax error before usbserial

/usr/src/linux-2.6.17-emission8/include/asm/semaphore.h: In function down_interruptible:

/usr/src/linux-2.6.17-emission8/include/asm/semaphore.h:130: error: syntax error before usbserial

/usr/src/linux-2.6.17-emission8/include/asm/semaphore.h: In function down_trylock:

/usr/src/linux-2.6.17-emission8/include/asm/semaphore.h:155: error: syntax error before usbserial

/usr/src/linux-2.6.17-emission8/include/asm/semaphore.h: In function up:

/usr/src/linux-2.6.17-emission8/include/asm/semaphore.h:179: error: syntax error before usbserial

In file included from /usr/src/linux-2.6.17-emission8/include/linux/irq.h:22,

                 from /usr/src/linux-2.6.17-emission8/include/asm/hardirq.h:6,

                 from /usr/src/linux-2.6.17-emission8/include/linux/hardirq.h:7,

                 from /usr/src/linux-2.6.17-emission8/include/linux/interrupt.h:11,

                 from /usr/src/linux-2.6.17-emission8/include/linux/usb.h:16,

                 from usb-serial.c:34:

/usr/src/linux-2.6.17-emission8/include/asm/irq.h:16:25: error: irq_vectors.h: No such file or directory

In file included from /usr/src/linux-2.6.17-emission8/include/asm/hardirq.h:6,

                 from /usr/src/linux-2.6.17-emission8/include/linux/hardirq.h:7,

                 from /usr/src/linux-2.6.17-emission8/include/linux/interrupt.h:11,

                 from /usr/src/linux-2.6.17-emission8/include/linux/usb.h:16,

                 from usb-serial.c:34:

/usr/src/linux-2.6.17-emission8/include/linux/irq.h: At top level:

/usr/src/linux-2.6.17-emission8/include/linux/irq.h:85: error: NR_IRQS undeclared here (not in a function)

In file included from /usr/src/linux-2.6.17-emission8/include/linux/irq.h:94,

                 from /usr/src/linux-2.6.17-emission8/include/asm/hardirq.h:6,

                 from /usr/src/linux-2.6.17-emission8/include/linux/hardirq.h:7,

                 from /usr/src/linux-2.6.17-emission8/include/linux/interrupt.h:11,

                 from /usr/src/linux-2.6.17-emission8/include/linux/usb.h:16,

                 from usb-serial.c:34:

/usr/src/linux-2.6.17-emission8/include/asm/hw_irq.h:30: error: NR_IRQ_VECTORS undeclared here (not in a function)

usb-serial.c: In function usb_serial_probe:

usb-serial.c:764: warning: pointer targets in passing argument 3 of get_free_serial differ in signedness

```

----------

## sharmay

For 2.6.19-suspend2-r3 kernel tree:

```

--- drivers/usb/serial/usb-serial.c.orig        2007-03-18 11:31:20.364525684 -0700

+++ drivers/usb/serial/usb-serial.c     2007-03-18 11:33:51.032540333 -0700

@@ -57,6 +57,7 @@

    drivers depend on it.

 */

 

+static ushort maxSize = 0;

 static int debug;

 static struct usb_serial *serial_table[SERIAL_TTY_MINORS];     /* initially all NULL */

 static LIST_HEAD(usb_serial_driver_list);

@@ -812,7 +813,7 @@

                        dev_err(&interface->dev, "No free urbs available\n");

                        goto probe_error;

                }

-               buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);

+               buffer_size = (endpoint->wMaxPacketSize > maxSize)?endpoint->wMaxPacketSize:maxSize;

                port->bulk_in_size = buffer_size;

                port->bulk_in_endpointAddress = endpoint->bEndpointAddress;

                port->bulk_in_buffer = kmalloc (buffer_size, GFP_KERNEL);

@@ -1190,3 +1191,5 @@

 

 module_param(debug, bool, S_IRUGO | S_IWUSR);

 MODULE_PARM_DESC(debug, "Debug enabled or not");

+module_param(maxSize, ushort,0);

+MODULE_PARM_DESC(maxSize,"User specified USB endpoint size");

```

How to apply:

save above code to /usr/src/usb-serial.patch

cd  /usr/src/linux-`uname -r`

patch -p0 < /usr/src/usb-serial.patch

----------

## Megaqwerty

I have noticed a few different patches here, specifically for different kernel versions. I was wondering how you know which values to change to make this patch compatible with newer or older kernel versions, I'd love to be able to do it myself as well.

Thanks in advance,

Megaqwerty

----------

## b0fh_

 *Megaqwerty wrote:*   

> I have noticed a few different patches here, specifically for different kernel versions. I was wondering how you know which values to change to make this patch compatible with newer or older kernel versions, I'd love to be able to do it myself as well.
> 
> Thanks in advance,
> 
> Megaqwerty

 

1) backup the file as usb-serial.bak

2) patch usb-serial by hand (not that hard, add 3 lines and change other)

3) diff -u usb-serial.c.bak usb-serial.c

For kernel 2.6.16-gentoo-r13 I get this:

```

[Cate(root)]ok:diff  -u usb-serial.c.bak usb-serial.c

--- usb-serial.c.bak    2007-03-21 20:04:33.000000000 -0300

+++ usb-serial.c        2007-03-21 22:09:58.000000000 -0300

@@ -56,6 +56,7 @@

    drivers depend on it.

 */

+static ushort maxSize = 0;

 static int debug;

 static struct usb_serial *serial_table[SERIAL_TTY_MINORS];     /* initially all NULL */

 static LIST_HEAD(usb_serial_driver_list);

@@ -799,7 +800,7 @@

                        dev_err(&interface->dev, "No free urbs available\n");

                        goto probe_error;

                }

-               buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);

+               buffer_size = (endpoint->wMaxPacketSize > maxSize)?endpoint->wMaxPacketSize:maxSize;

                port->bulk_in_size = buffer_size;

                port->bulk_in_endpointAddress = endpoint->bEndpointAddress;

                port->bulk_in_buffer = kmalloc (buffer_size, GFP_KERNEL);

@@ -1174,3 +1175,5 @@

 module_param(debug, bool, S_IRUGO | S_IWUSR);

 MODULE_PARM_DESC(debug, "Debug enabled or not");

+module_param(maxSize, ushort,0);

+MODULE_PARM_DESC(maxSize,"User specified USB endpoint size");

```

cheers

----------

## Megaqwerty

 *Quote:*   

> 
> 
> 1) backup the file as usb-serial.bak
> 
> 2) patch usb-serial by hand (not that hard, add 3 lines and change other)
> ...

 

So from the existing patch we saw, where did you find out what 3 lines need to be added, and what line had to be changed?

I don't remember seeing them on the site it was originally posted on, so...is it in the patch itself?

Thanks again,

Megaqwerty

----------

## b0fh_

check the lines in the the patch that begin with '+' and '-'.

for example, if you see a line with only a '+', like this ones:

+module_param(maxSize, ushort,0);

+MODULE_PARM_DESC(maxSize,"User specified USB endpoint size");

they have to be added to the source file. where, you may ask... easy, just below the line

MODULE_PARM_DESC(debug, "Debug enabled or not");

as the patch itself implies   :Cool: 

when you see something like this:

-buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); 

+buffer_size = (endpoint->wMaxPacketSize > maxSize)?endpoint->wMaxPacketSize:maxSize; 

it pretty much means the first line is replaced by the second;

you can also have just a '-', in that case the line has to be deleted.

those things between @@ ... @@ are references to line numbers, but I don't generally care for them because if they were right for the source i'm patching, I would not need to patch by hand   :Cool: . When doing that, I get the location mostly by context.

cheers

----------

## Megaqwerty

Sweet. 

Thanks, patches no longer look as menacing   :Wink: . 

-Megaqwerty

----------

