X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=drivers%2Fusb%2Fserial%2Fsafe_serial.c;h=f0215f850d2d3eea98faf2b6569075f596aec3cd;hb=43bc926fffd92024b46cafaf7350d669ba9ca884;hp=a55c631c19981dbf95a5912bfa92377cf40a8152;hpb=5273a3df6485dc2ad6aa7ddd441b9a21970f003b;p=linux-2.6.git diff --git a/drivers/usb/serial/safe_serial.c b/drivers/usb/serial/safe_serial.c index a55c631c1..f0215f850 100644 --- a/drivers/usb/serial/safe_serial.c +++ b/drivers/usb/serial/safe_serial.c @@ -72,18 +72,14 @@ #include #include #include +#include "usb-serial.h" -#ifndef CONFIG_USB_SERIAL_DEBUG -#define CONFIG_USB_SERIAL_DEBUG 0 -#endif #ifndef CONFIG_USB_SAFE_PADDED #define CONFIG_USB_SAFE_PADDED 0 #endif -static int debug = CONFIG_USB_SERIAL_DEBUG; -#include "usb-serial.h" // must follow the declaration of debug - +static int debug; static int safe = 1; static int padded = CONFIG_USB_SAFE_PADDED; @@ -96,25 +92,26 @@ MODULE_DESCRIPTION (DRIVER_DESC); MODULE_LICENSE("GPL"); #if defined(CONFIG_USBD_SAFE_SERIAL_VENDOR) && !defined(CONFIG_USBD_SAFE_SERIAL_PRODUCT) -#abort "SAFE_SERIAL_VENDOR defined without SAFE_SERIAL_PRODUCT" +#error "SAFE_SERIAL_VENDOR defined without SAFE_SERIAL_PRODUCT" #endif #if ! defined(CONFIG_USBD_SAFE_SERIAL_VENDOR) static __u16 vendor; // no default static __u16 product; // no default -MODULE_PARM (vendor, "i"); -MODULE_PARM (product, "i"); -MODULE_PARM_DESC (vendor, "User specified USB idVendor (required)"); -MODULE_PARM_DESC (product, "User specified USB idProduct (required)"); +module_param(vendor, ushort, 0); +MODULE_PARM_DESC(vendor, "User specified USB idVendor (required)"); +module_param(product, ushort, 0); +MODULE_PARM_DESC(product, "User specified USB idProduct (required)"); #endif -MODULE_PARM (debug, "i"); -MODULE_PARM (safe, "i"); -MODULE_PARM (padded, "i"); +module_param(debug, bool, S_IRUGO | S_IWUSR); +MODULE_PARM_DESC(debug, "Debug enabled or not"); + +module_param(safe, bool, 0); +MODULE_PARM_DESC(safe, "Turn Safe Encapsulation On/Off"); -MODULE_PARM_DESC (debug, "Debug enabled or not"); -MODULE_PARM_DESC (safe, "Turn Safe Encapsulation On/Off"); -MODULE_PARM_DESC (padded, "Pad to full wMaxPacketSize On/Off"); +module_param(padded, bool, 0); +MODULE_PARM_DESC(padded, "Pad to full wMaxPacketSize On/Off"); #define CDC_DEVICE_CLASS 0x02 @@ -163,14 +160,14 @@ static struct usb_device_id id_table[] = { MODULE_DEVICE_TABLE (usb, id_table); static struct usb_driver safe_driver = { - .owner = THIS_MODULE, .name = "safe_serial", .probe = usb_serial_probe, .disconnect = usb_serial_disconnect, .id_table = id_table, + .no_dynamic_id = 1, }; -static __u16 crc10_table[256] = { +static const __u16 crc10_table[256] = { 0x000, 0x233, 0x255, 0x066, 0x299, 0x0aa, 0x0cc, 0x2ff, 0x301, 0x132, 0x154, 0x367, 0x198, 0x3ab, 0x3cd, 0x1fe, 0x031, 0x202, 0x264, 0x057, 0x2a8, 0x09b, 0x0fd, 0x2ce, 0x330, 0x103, 0x165, 0x356, 0x1a9, 0x39a, 0x3fc, 0x1cf, 0x062, 0x251, 0x237, 0x004, 0x2fb, 0x0c8, 0x0ae, 0x29d, 0x363, 0x150, 0x136, 0x305, 0x1fa, 0x3c9, 0x3af, 0x19c, @@ -211,7 +208,6 @@ static __u16 __inline__ fcs_compute10 (unsigned char *sp, int len, __u16 fcs) static void safe_read_bulk_callback (struct urb *urb, struct pt_regs *regs) { struct usb_serial_port *port = (struct usb_serial_port *) urb->context; - struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); unsigned char *data = urb->transfer_buffer; unsigned char length = urb->actual_length; int i; @@ -219,11 +215,6 @@ static void safe_read_bulk_callback (struct urb *urb, struct pt_regs *regs) dbg ("%s", __FUNCTION__); - if (!serial) { - dbg ("%s - bad serial pointer, exiting", __FUNCTION__); - return; - } - if (urb->status) { dbg ("%s - nonzero read bulk status received: %d", __FUNCTION__, urb->status); return; @@ -272,8 +263,8 @@ static void safe_read_bulk_callback (struct urb *urb, struct pt_regs *regs) } /* Continue trying to always read */ - usb_fill_bulk_urb (urb, serial->dev, - usb_rcvbulkpipe (serial->dev, port->bulk_in_endpointAddress), + usb_fill_bulk_urb (urb, port->serial->dev, + usb_rcvbulkpipe (port->serial->dev, port->bulk_in_endpointAddress), urb->transfer_buffer, urb->transfer_buffer_length, safe_read_bulk_callback, port); @@ -282,9 +273,8 @@ static void safe_read_bulk_callback (struct urb *urb, struct pt_regs *regs) } } -static int safe_write (struct usb_serial_port *port, int from_user, const unsigned char *buf, int count) +static int safe_write (struct usb_serial_port *port, const unsigned char *buf, int count) { - struct usb_serial *serial = port->serial; unsigned char *data; int result; int i; @@ -309,10 +299,14 @@ static int safe_write (struct usb_serial_port *port, int from_user, const unsign dbg ("%s - write request of 0 bytes", __FUNCTION__); return (0); } - if (port->write_urb->status == -EINPROGRESS) { - dbg ("%s - already writing", __FUNCTION__); - return (0); + spin_lock(&port->lock); + if (port->write_urb_busy) { + spin_unlock(&port->lock); + dbg("%s - already writing", __FUNCTION__); + return 0; } + port->write_urb_busy = 1; + spin_unlock(&port->lock); packet_length = port->bulk_out_size; // get max packetsize @@ -324,12 +318,7 @@ static int safe_write (struct usb_serial_port *port, int from_user, const unsign data = port->write_urb->transfer_buffer; memset (data, '0', packet_length); - if (from_user) { - if (copy_from_user (data, buf, count)) - return -EFAULT; - } else { - memcpy (data, buf, count); - } + memcpy (data, buf, count); if (safe) { __u16 fcs; @@ -353,7 +342,7 @@ static int safe_write (struct usb_serial_port *port, int from_user, const unsign port->write_urb->transfer_buffer_length = count; } - usb_serial_debug_data (__FILE__, __FUNCTION__, count, port->write_urb->transfer_buffer); + usb_serial_debug_data(debug, &port->dev, __FUNCTION__, count, port->write_urb->transfer_buffer); #ifdef ECHO_TX { int i; @@ -367,8 +356,9 @@ static int safe_write (struct usb_serial_port *port, int from_user, const unsign printk ("\n"); } #endif - port->write_urb->dev = serial->dev; + port->write_urb->dev = port->serial->dev; if ((result = usb_submit_urb (port->write_urb, GFP_KERNEL))) { + port->write_urb_busy = 0; err ("%s - failed submitting write urb, error %d", __FUNCTION__, result); return 0; } @@ -383,7 +373,7 @@ static int safe_write_room (struct usb_serial_port *port) dbg ("%s", __FUNCTION__); - if (port->write_urb->status != -EINPROGRESS) + if (port->write_urb_busy) room = port->bulk_out_size - (safe ? 2 : 0); if (room) { @@ -395,7 +385,7 @@ static int safe_write_room (struct usb_serial_port *port) static int safe_startup (struct usb_serial *serial) { - switch (serial->interface->altsetting->desc.bInterfaceProtocol) { + switch (serial->interface->cur_altsetting->desc.bInterfaceProtocol) { case LINEO_SAFESERIAL_CRC: break; case LINEO_SAFESERIAL_CRC_PADDED: @@ -407,9 +397,11 @@ static int safe_startup (struct usb_serial *serial) return 0; } -static struct usb_serial_device_type safe_device = { - .owner = THIS_MODULE, - .name = "Safe", +static struct usb_serial_driver safe_device = { + .driver = { + .owner = THIS_MODULE, + .name = "safe_serial", + }, .id_table = id_table, .num_interrupt_in = NUM_DONT_CARE, .num_bulk_in = NUM_DONT_CARE, @@ -433,7 +425,7 @@ static int __init safe_init (void) if (vendor || product) { info ("vendor: %x product: %x\n", vendor, product); - for (i = 0; i < (sizeof (id_table) / sizeof (struct usb_device_id)); i++) { + for (i = 0; i < ARRAY_SIZE(id_table); i++) { if (!id_table[i].idVendor && !id_table[i].idProduct) { id_table[i].idVendor = vendor; id_table[i].idProduct = product;