Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * USB Serial Converter Generic functions |
| 3 | * |
| 4 | * Copyright (C) 1999 - 2002 Greg Kroah-Hartman (greg@kroah.com) |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License version |
| 8 | * 2 as published by the Free Software Foundation. |
| 9 | * |
| 10 | */ |
| 11 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/kernel.h> |
| 13 | #include <linux/errno.h> |
| 14 | #include <linux/slab.h> |
Randy Dunlap | 7f0ae3a | 2010-03-25 11:29:16 -0700 | [diff] [blame] | 15 | #include <linux/sysrq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/tty.h> |
| 17 | #include <linux/tty_flip.h> |
| 18 | #include <linux/module.h> |
| 19 | #include <linux/moduleparam.h> |
| 20 | #include <linux/usb.h> |
Greg Kroah-Hartman | a969888 | 2006-07-11 21:22:58 -0700 | [diff] [blame] | 21 | #include <linux/usb/serial.h> |
Alan Cox | ae64387 | 2008-07-22 11:11:55 +0100 | [diff] [blame] | 22 | #include <linux/uaccess.h> |
David VomLehn | 8e8dce0 | 2009-08-28 12:54:27 -0700 | [diff] [blame] | 23 | #include <linux/kfifo.h> |
Alan Stern | 1f87158 | 2010-02-17 10:05:47 -0500 | [diff] [blame] | 24 | #include <linux/serial.h> |
Johannes Hölzl | d9b1b78 | 2006-12-17 21:50:24 +0100 | [diff] [blame] | 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | static int debug; |
| 27 | |
Johan Hovold | 25d514c | 2010-03-17 23:06:07 +0100 | [diff] [blame] | 28 | #define MAX_TX_URBS 40 |
| 29 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #ifdef CONFIG_USB_SERIAL_GENERIC |
David Brownell | b46d60f | 2007-03-23 12:51:55 -0700 | [diff] [blame] | 31 | |
| 32 | static int generic_probe(struct usb_interface *interface, |
| 33 | const struct usb_device_id *id); |
| 34 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | static __u16 vendor = 0x05f9; |
| 36 | static __u16 product = 0xffff; |
| 37 | |
| 38 | module_param(vendor, ushort, 0); |
| 39 | MODULE_PARM_DESC(vendor, "User specified USB idVendor"); |
| 40 | |
| 41 | module_param(product, ushort, 0); |
| 42 | MODULE_PARM_DESC(product, "User specified USB idProduct"); |
| 43 | |
| 44 | static struct usb_device_id generic_device_ids[2]; /* Initially all zeroes. */ |
| 45 | |
Johannes Hölzl | d9b1b78 | 2006-12-17 21:50:24 +0100 | [diff] [blame] | 46 | /* we want to look at all devices, as the vendor/product id can change |
| 47 | * depending on the command line argument */ |
Németh Márton | 7d40d7e | 2010-01-10 15:34:24 +0100 | [diff] [blame] | 48 | static const struct usb_device_id generic_serial_ids[] = { |
Johannes Hölzl | d9b1b78 | 2006-12-17 21:50:24 +0100 | [diff] [blame] | 49 | {.driver_info = 42}, |
| 50 | {} |
| 51 | }; |
| 52 | |
| 53 | static struct usb_driver generic_driver = { |
| 54 | .name = "usbserial_generic", |
| 55 | .probe = generic_probe, |
| 56 | .disconnect = usb_serial_disconnect, |
| 57 | .id_table = generic_serial_ids, |
| 58 | .no_dynamic_id = 1, |
| 59 | }; |
| 60 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | /* All of the device info needed for the Generic Serial Converter */ |
Greg Kroah-Hartman | ea65370 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 62 | struct usb_serial_driver usb_serial_generic_device = { |
Greg Kroah-Hartman | 18fcac3 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 63 | .driver = { |
| 64 | .owner = THIS_MODULE, |
Greg Kroah-Hartman | 269bda1 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 65 | .name = "generic", |
Greg Kroah-Hartman | 18fcac3 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 66 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | .id_table = generic_device_ids, |
Johannes Hölzl | d9b1b78 | 2006-12-17 21:50:24 +0100 | [diff] [blame] | 68 | .usb_driver = &generic_driver, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | .num_ports = 1, |
Alan Stern | f9c99bb | 2009-06-02 11:53:55 -0400 | [diff] [blame] | 70 | .disconnect = usb_serial_generic_disconnect, |
| 71 | .release = usb_serial_generic_release, |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 72 | .throttle = usb_serial_generic_throttle, |
| 73 | .unthrottle = usb_serial_generic_unthrottle, |
Oliver Neukum | ec22559 | 2007-04-27 20:54:57 +0200 | [diff] [blame] | 74 | .resume = usb_serial_generic_resume, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | }; |
| 76 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | static int generic_probe(struct usb_interface *interface, |
| 78 | const struct usb_device_id *id) |
| 79 | { |
| 80 | const struct usb_device_id *id_pattern; |
| 81 | |
| 82 | id_pattern = usb_match_id(interface, generic_device_ids); |
| 83 | if (id_pattern != NULL) |
| 84 | return usb_serial_probe(interface, id); |
| 85 | return -ENODEV; |
| 86 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | #endif |
| 88 | |
Alan Cox | ae64387 | 2008-07-22 11:11:55 +0100 | [diff] [blame] | 89 | int usb_serial_generic_register(int _debug) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | { |
| 91 | int retval = 0; |
| 92 | |
| 93 | debug = _debug; |
| 94 | #ifdef CONFIG_USB_SERIAL_GENERIC |
| 95 | generic_device_ids[0].idVendor = vendor; |
| 96 | generic_device_ids[0].idProduct = product; |
Alan Cox | ae64387 | 2008-07-22 11:11:55 +0100 | [diff] [blame] | 97 | generic_device_ids[0].match_flags = |
| 98 | USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
| 100 | /* register our generic driver with ourselves */ |
Alan Cox | ae64387 | 2008-07-22 11:11:55 +0100 | [diff] [blame] | 101 | retval = usb_serial_register(&usb_serial_generic_device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | if (retval) |
| 103 | goto exit; |
| 104 | retval = usb_register(&generic_driver); |
| 105 | if (retval) |
| 106 | usb_serial_deregister(&usb_serial_generic_device); |
| 107 | exit: |
| 108 | #endif |
| 109 | return retval; |
| 110 | } |
| 111 | |
Alan Cox | ae64387 | 2008-07-22 11:11:55 +0100 | [diff] [blame] | 112 | void usb_serial_generic_deregister(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | { |
| 114 | #ifdef CONFIG_USB_SERIAL_GENERIC |
| 115 | /* remove our generic driver */ |
| 116 | usb_deregister(&generic_driver); |
Alan Cox | ae64387 | 2008-07-22 11:11:55 +0100 | [diff] [blame] | 117 | usb_serial_deregister(&usb_serial_generic_device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | #endif |
| 119 | } |
| 120 | |
Alan Cox | a509a7e | 2009-09-19 13:13:26 -0700 | [diff] [blame] | 121 | int usb_serial_generic_open(struct tty_struct *tty, struct usb_serial_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | int result = 0; |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 124 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 126 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 128 | /* clear the throttle flags */ |
| 129 | spin_lock_irqsave(&port->lock, flags); |
| 130 | port->throttled = 0; |
| 131 | port->throttle_req = 0; |
| 132 | spin_unlock_irqrestore(&port->lock, flags); |
| 133 | |
| 134 | /* if we have a bulk endpoint, start reading from it */ |
Johan Hovold | 41bd72f | 2010-03-17 23:05:53 +0100 | [diff] [blame] | 135 | if (port->bulk_in_size) |
| 136 | result = usb_serial_generic_submit_read_urb(port, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
| 138 | return result; |
| 139 | } |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 140 | EXPORT_SYMBOL_GPL(usb_serial_generic_open); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 142 | static void generic_cleanup(struct usb_serial_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | { |
| 144 | struct usb_serial *serial = port->serial; |
Johan Hovold | ec3ee50 | 2010-03-17 23:00:44 +0100 | [diff] [blame] | 145 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 147 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | |
| 149 | if (serial->dev) { |
Johan Hovold | eb8878a | 2010-02-27 16:24:49 +0100 | [diff] [blame] | 150 | /* shutdown any bulk transfers that might be going on */ |
Johan Hovold | ec3ee50 | 2010-03-17 23:00:44 +0100 | [diff] [blame] | 151 | if (port->bulk_out_size) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | usb_kill_urb(port->write_urb); |
Johan Hovold | ec3ee50 | 2010-03-17 23:00:44 +0100 | [diff] [blame] | 153 | |
| 154 | spin_lock_irqsave(&port->lock, flags); |
| 155 | kfifo_reset_out(&port->write_fifo); |
| 156 | spin_unlock_irqrestore(&port->lock, flags); |
| 157 | } |
Johan Hovold | eb8878a | 2010-02-27 16:24:49 +0100 | [diff] [blame] | 158 | if (port->bulk_in_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | usb_kill_urb(port->read_urb); |
| 160 | } |
| 161 | } |
| 162 | |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 163 | void usb_serial_generic_close(struct usb_serial_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 165 | dbg("%s - port %d", __func__, port->number); |
Alan Cox | ae64387 | 2008-07-22 11:11:55 +0100 | [diff] [blame] | 166 | generic_cleanup(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | } |
Johan Hovold | f26788d | 2010-03-17 23:00:45 +0100 | [diff] [blame] | 168 | EXPORT_SYMBOL_GPL(usb_serial_generic_close); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | |
Johan Hovold | eaa3bcb | 2010-03-17 23:06:08 +0100 | [diff] [blame^] | 170 | int usb_serial_generic_prepare_write_buffer(struct usb_serial_port *port, |
| 171 | void **dest, size_t size, const void *src, size_t count) |
| 172 | { |
| 173 | if (!*dest) { |
| 174 | size = count; |
| 175 | *dest = kmalloc(count, GFP_ATOMIC); |
| 176 | if (!*dest) { |
| 177 | dev_err(&port->dev, "%s - could not allocate buffer\n", |
| 178 | __func__); |
| 179 | return -ENOMEM; |
| 180 | } |
| 181 | } |
| 182 | if (src) { |
| 183 | count = size; |
| 184 | memcpy(*dest, src, size); |
| 185 | } else { |
| 186 | count = kfifo_out_locked(&port->write_fifo, *dest, size, |
| 187 | &port->lock); |
| 188 | } |
| 189 | return count; |
| 190 | } |
| 191 | EXPORT_SYMBOL_GPL(usb_serial_generic_prepare_write_buffer); |
| 192 | |
Jason Wessel | 715b1dc | 2009-05-11 15:24:07 -0500 | [diff] [blame] | 193 | static int usb_serial_multi_urb_write(struct tty_struct *tty, |
| 194 | struct usb_serial_port *port, const unsigned char *buf, int count) |
| 195 | { |
| 196 | unsigned long flags; |
| 197 | struct urb *urb; |
Johan Hovold | eaa3bcb | 2010-03-17 23:06:08 +0100 | [diff] [blame^] | 198 | void *buffer; |
Jason Wessel | 715b1dc | 2009-05-11 15:24:07 -0500 | [diff] [blame] | 199 | int status; |
Jason Wessel | 715b1dc | 2009-05-11 15:24:07 -0500 | [diff] [blame] | 200 | |
Johan Hovold | 25d514c | 2010-03-17 23:06:07 +0100 | [diff] [blame] | 201 | spin_lock_irqsave(&port->lock, flags); |
| 202 | if (port->tx_urbs == MAX_TX_URBS) { |
Jason Wessel | 715b1dc | 2009-05-11 15:24:07 -0500 | [diff] [blame] | 203 | spin_unlock_irqrestore(&port->lock, flags); |
Johan Hovold | 25d514c | 2010-03-17 23:06:07 +0100 | [diff] [blame] | 204 | dbg("%s - write limit hit", __func__); |
| 205 | return 0; |
| 206 | } |
| 207 | port->tx_urbs++; |
| 208 | spin_unlock_irqrestore(&port->lock, flags); |
Jason Wessel | 715b1dc | 2009-05-11 15:24:07 -0500 | [diff] [blame] | 209 | |
Johan Hovold | 25d514c | 2010-03-17 23:06:07 +0100 | [diff] [blame] | 210 | urb = usb_alloc_urb(0, GFP_ATOMIC); |
| 211 | if (!urb) { |
| 212 | dev_err(&port->dev, "%s - no free urbs available\n", __func__); |
| 213 | status = -ENOMEM; |
| 214 | goto err_urb; |
| 215 | } |
Jason Wessel | 715b1dc | 2009-05-11 15:24:07 -0500 | [diff] [blame] | 216 | |
Johan Hovold | eaa3bcb | 2010-03-17 23:06:08 +0100 | [diff] [blame^] | 217 | buffer = NULL; |
Johan Hovold | 25d514c | 2010-03-17 23:06:07 +0100 | [diff] [blame] | 218 | count = min_t(int, count, PAGE_SIZE); |
Johan Hovold | eaa3bcb | 2010-03-17 23:06:08 +0100 | [diff] [blame^] | 219 | count = port->serial->type->prepare_write_buffer(port, &buffer, 0, |
| 220 | buf, count); |
| 221 | if (count < 0) { |
| 222 | status = count; |
Johan Hovold | 25d514c | 2010-03-17 23:06:07 +0100 | [diff] [blame] | 223 | goto err_buf; |
| 224 | } |
Johan Hovold | 25d514c | 2010-03-17 23:06:07 +0100 | [diff] [blame] | 225 | usb_serial_debug_data(debug, &port->dev, __func__, count, buffer); |
| 226 | usb_fill_bulk_urb(urb, port->serial->dev, |
Jason Wessel | 715b1dc | 2009-05-11 15:24:07 -0500 | [diff] [blame] | 227 | usb_sndbulkpipe(port->serial->dev, |
| 228 | port->bulk_out_endpointAddress), |
Johan Hovold | 25d514c | 2010-03-17 23:06:07 +0100 | [diff] [blame] | 229 | buffer, count, |
Johan Hovold | 40f92f0 | 2010-03-17 23:06:06 +0100 | [diff] [blame] | 230 | port->serial->type->write_bulk_callback, port); |
Jason Wessel | 715b1dc | 2009-05-11 15:24:07 -0500 | [diff] [blame] | 231 | |
Johan Hovold | 25d514c | 2010-03-17 23:06:07 +0100 | [diff] [blame] | 232 | status = usb_submit_urb(urb, GFP_ATOMIC); |
| 233 | if (status) { |
| 234 | dev_err(&port->dev, "%s - error submitting urb: %d\n", |
Jason Wessel | 715b1dc | 2009-05-11 15:24:07 -0500 | [diff] [blame] | 235 | __func__, status); |
Johan Hovold | 25d514c | 2010-03-17 23:06:07 +0100 | [diff] [blame] | 236 | goto err; |
Jason Wessel | 715b1dc | 2009-05-11 15:24:07 -0500 | [diff] [blame] | 237 | } |
Jason Wessel | 715b1dc | 2009-05-11 15:24:07 -0500 | [diff] [blame] | 238 | spin_lock_irqsave(&port->lock, flags); |
Johan Hovold | 25d514c | 2010-03-17 23:06:07 +0100 | [diff] [blame] | 239 | port->tx_bytes += urb->transfer_buffer_length; |
Jason Wessel | 715b1dc | 2009-05-11 15:24:07 -0500 | [diff] [blame] | 240 | spin_unlock_irqrestore(&port->lock, flags); |
Johan Hovold | 25d514c | 2010-03-17 23:06:07 +0100 | [diff] [blame] | 241 | |
| 242 | usb_free_urb(urb); |
| 243 | |
| 244 | return count; |
| 245 | err: |
| 246 | kfree(buffer); |
| 247 | err_buf: |
| 248 | usb_free_urb(urb); |
| 249 | err_urb: |
| 250 | spin_lock_irqsave(&port->lock, flags); |
| 251 | port->tx_urbs--; |
| 252 | spin_unlock_irqrestore(&port->lock, flags); |
| 253 | |
| 254 | return status; |
Jason Wessel | 715b1dc | 2009-05-11 15:24:07 -0500 | [diff] [blame] | 255 | } |
| 256 | |
David VomLehn | 8e8dce0 | 2009-08-28 12:54:27 -0700 | [diff] [blame] | 257 | /** |
| 258 | * usb_serial_generic_write_start - kick off an URB write |
| 259 | * @port: Pointer to the &struct usb_serial_port data |
| 260 | * |
| 261 | * Returns the number of bytes queued on success. This will be zero if there |
| 262 | * was nothing to send. Otherwise, it returns a negative errno value |
| 263 | */ |
| 264 | static int usb_serial_generic_write_start(struct usb_serial_port *port) |
| 265 | { |
David VomLehn | 8e8dce0 | 2009-08-28 12:54:27 -0700 | [diff] [blame] | 266 | int result; |
| 267 | int count; |
| 268 | unsigned long flags; |
David VomLehn | 8e8dce0 | 2009-08-28 12:54:27 -0700 | [diff] [blame] | 269 | |
David VomLehn | 8e8dce0 | 2009-08-28 12:54:27 -0700 | [diff] [blame] | 270 | spin_lock_irqsave(&port->lock, flags); |
Johan Hovold | 50a5f70 | 2010-03-17 23:06:02 +0100 | [diff] [blame] | 271 | if (port->write_urb_busy || !kfifo_len(&port->write_fifo)) { |
| 272 | spin_unlock_irqrestore(&port->lock, flags); |
David VomLehn | 8e8dce0 | 2009-08-28 12:54:27 -0700 | [diff] [blame] | 273 | return 0; |
Johan Hovold | 50a5f70 | 2010-03-17 23:06:02 +0100 | [diff] [blame] | 274 | } |
| 275 | port->write_urb_busy = 1; |
| 276 | spin_unlock_irqrestore(&port->lock, flags); |
David VomLehn | 8e8dce0 | 2009-08-28 12:54:27 -0700 | [diff] [blame] | 277 | |
Johan Hovold | eaa3bcb | 2010-03-17 23:06:08 +0100 | [diff] [blame^] | 278 | count = port->serial->type->prepare_write_buffer(port, |
| 279 | &port->write_urb->transfer_buffer, |
| 280 | port->bulk_out_size, NULL, 0); |
| 281 | usb_serial_debug_data(debug, &port->dev, __func__, |
| 282 | count, port->write_urb->transfer_buffer); |
Johan Hovold | 056afc0 | 2010-03-17 23:05:54 +0100 | [diff] [blame] | 283 | port->write_urb->transfer_buffer_length = count; |
David VomLehn | 8e8dce0 | 2009-08-28 12:54:27 -0700 | [diff] [blame] | 284 | |
| 285 | /* send the data out the bulk port */ |
| 286 | result = usb_submit_urb(port->write_urb, GFP_ATOMIC); |
| 287 | if (result) { |
Johan Hovold | 1a1405e | 2010-03-17 23:06:01 +0100 | [diff] [blame] | 288 | dev_err(&port->dev, "%s - error submitting urb: %d\n", |
David VomLehn | 8e8dce0 | 2009-08-28 12:54:27 -0700 | [diff] [blame] | 289 | __func__, result); |
| 290 | /* don't have to grab the lock here, as we will |
| 291 | retry if != 0 */ |
| 292 | port->write_urb_busy = 0; |
Johan Hovold | 30af7fb | 2010-03-17 23:00:42 +0100 | [diff] [blame] | 293 | return result; |
| 294 | } |
David VomLehn | 8e8dce0 | 2009-08-28 12:54:27 -0700 | [diff] [blame] | 295 | |
Johan Hovold | 30af7fb | 2010-03-17 23:00:42 +0100 | [diff] [blame] | 296 | spin_lock_irqsave(&port->lock, flags); |
Johan Hovold | 25d514c | 2010-03-17 23:06:07 +0100 | [diff] [blame] | 297 | port->tx_bytes += count; |
Johan Hovold | 30af7fb | 2010-03-17 23:00:42 +0100 | [diff] [blame] | 298 | spin_unlock_irqrestore(&port->lock, flags); |
| 299 | |
| 300 | return count; |
David VomLehn | 8e8dce0 | 2009-08-28 12:54:27 -0700 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | /** |
| 304 | * usb_serial_generic_write - generic write function for serial USB devices |
| 305 | * @tty: Pointer to &struct tty_struct for the device |
| 306 | * @port: Pointer to the &usb_serial_port structure for the device |
| 307 | * @buf: Pointer to the data to write |
| 308 | * @count: Number of bytes to write |
| 309 | * |
| 310 | * Returns the number of characters actually written, which may be anything |
| 311 | * from zero to @count. If an error occurs, it returns the negative errno |
| 312 | * value. |
| 313 | */ |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 314 | int usb_serial_generic_write(struct tty_struct *tty, |
| 315 | struct usb_serial_port *port, const unsigned char *buf, int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | { |
| 317 | struct usb_serial *serial = port->serial; |
| 318 | int result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 320 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | |
Johan Hovold | eb8878a | 2010-02-27 16:24:49 +0100 | [diff] [blame] | 322 | /* only do something if we have a bulk out endpoint */ |
| 323 | if (!port->bulk_out_size) |
| 324 | return -ENODEV; |
| 325 | |
Johan Hovold | 1a1405e | 2010-03-17 23:06:01 +0100 | [diff] [blame] | 326 | if (!count) |
Alan Cox | ae64387 | 2008-07-22 11:11:55 +0100 | [diff] [blame] | 327 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | |
Johan Hovold | 25d514c | 2010-03-17 23:06:07 +0100 | [diff] [blame] | 329 | if (serial->type->multi_urb_write) |
| 330 | return usb_serial_multi_urb_write(tty, port, buf, count); |
Jason Wessel | 715b1dc | 2009-05-11 15:24:07 -0500 | [diff] [blame] | 331 | |
Stefani Seibold | 119eecc | 2009-12-23 09:10:48 +0100 | [diff] [blame] | 332 | count = kfifo_in_locked(&port->write_fifo, buf, count, &port->lock); |
David VomLehn | 8e8dce0 | 2009-08-28 12:54:27 -0700 | [diff] [blame] | 333 | result = usb_serial_generic_write_start(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | |
David VomLehn | 8e8dce0 | 2009-08-28 12:54:27 -0700 | [diff] [blame] | 335 | if (result >= 0) |
| 336 | result = count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | |
David VomLehn | 8e8dce0 | 2009-08-28 12:54:27 -0700 | [diff] [blame] | 338 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | } |
Jason Wessel | 98fcb5f | 2009-05-11 15:24:09 -0500 | [diff] [blame] | 340 | EXPORT_SYMBOL_GPL(usb_serial_generic_write); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | |
Alan Cox | ae64387 | 2008-07-22 11:11:55 +0100 | [diff] [blame] | 342 | int usb_serial_generic_write_room(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 344 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | struct usb_serial *serial = port->serial; |
Jason Wessel | 715b1dc | 2009-05-11 15:24:07 -0500 | [diff] [blame] | 346 | unsigned long flags; |
Johan Hovold | 25d514c | 2010-03-17 23:06:07 +0100 | [diff] [blame] | 347 | int room; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 349 | dbg("%s - port %d", __func__, port->number); |
Johan Hovold | eb8878a | 2010-02-27 16:24:49 +0100 | [diff] [blame] | 350 | |
| 351 | if (!port->bulk_out_size) |
| 352 | return 0; |
| 353 | |
Jason Wessel | 715b1dc | 2009-05-11 15:24:07 -0500 | [diff] [blame] | 354 | spin_lock_irqsave(&port->lock, flags); |
Johan Hovold | 25d514c | 2010-03-17 23:06:07 +0100 | [diff] [blame] | 355 | if (serial->type->multi_urb_write) |
| 356 | room = (MAX_TX_URBS - port->tx_urbs) * PAGE_SIZE; |
| 357 | else |
Stefani Seibold | 119eecc | 2009-12-23 09:10:48 +0100 | [diff] [blame] | 358 | room = kfifo_avail(&port->write_fifo); |
Jason Wessel | 715b1dc | 2009-05-11 15:24:07 -0500 | [diff] [blame] | 359 | spin_unlock_irqrestore(&port->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 361 | dbg("%s - returns %d", __func__, room); |
Alan Cox | a5b6f60 | 2008-04-08 17:16:06 +0100 | [diff] [blame] | 362 | return room; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | } |
| 364 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 365 | int usb_serial_generic_chars_in_buffer(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 367 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | struct usb_serial *serial = port->serial; |
Jason Wessel | 715b1dc | 2009-05-11 15:24:07 -0500 | [diff] [blame] | 369 | unsigned long flags; |
Johan Hovold | eb8878a | 2010-02-27 16:24:49 +0100 | [diff] [blame] | 370 | int chars; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 372 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | |
Johan Hovold | eb8878a | 2010-02-27 16:24:49 +0100 | [diff] [blame] | 374 | if (!port->bulk_out_size) |
| 375 | return 0; |
| 376 | |
Stefani Seibold | 25719e6b | 2010-01-05 14:30:31 +0100 | [diff] [blame] | 377 | spin_lock_irqsave(&port->lock, flags); |
Johan Hovold | 25d514c | 2010-03-17 23:06:07 +0100 | [diff] [blame] | 378 | if (serial->type->multi_urb_write) |
| 379 | chars = port->tx_bytes; |
Johan Hovold | eb8878a | 2010-02-27 16:24:49 +0100 | [diff] [blame] | 380 | else |
Johan Hovold | 25d514c | 2010-03-17 23:06:07 +0100 | [diff] [blame] | 381 | chars = kfifo_len(&port->write_fifo) + port->tx_bytes; |
Stefani Seibold | 25719e6b | 2010-01-05 14:30:31 +0100 | [diff] [blame] | 382 | spin_unlock_irqrestore(&port->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 384 | dbg("%s - returns %d", __func__, chars); |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 385 | return chars; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | } |
| 387 | |
Johan Hovold | 41bd72f | 2010-03-17 23:05:53 +0100 | [diff] [blame] | 388 | int usb_serial_generic_submit_read_urb(struct usb_serial_port *port, |
| 389 | gfp_t mem_flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | int result; |
| 392 | |
Johan Hovold | 056afc0 | 2010-03-17 23:05:54 +0100 | [diff] [blame] | 393 | result = usb_submit_urb(port->read_urb, mem_flags); |
Johan Hovold | 0ae1474 | 2010-02-27 14:05:46 +0100 | [diff] [blame] | 394 | if (result && result != -EPERM) { |
Johan Hovold | 1a1405e | 2010-03-17 23:06:01 +0100 | [diff] [blame] | 395 | dev_err(&port->dev, "%s - error submitting urb: %d\n", |
Alan Cox | ae64387 | 2008-07-22 11:11:55 +0100 | [diff] [blame] | 396 | __func__, result); |
Johan Hovold | 0ae1474 | 2010-02-27 14:05:46 +0100 | [diff] [blame] | 397 | } |
Johan Hovold | 41bd72f | 2010-03-17 23:05:53 +0100 | [diff] [blame] | 398 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | } |
Johan Hovold | 41bd72f | 2010-03-17 23:05:53 +0100 | [diff] [blame] | 400 | EXPORT_SYMBOL_GPL(usb_serial_generic_submit_read_urb); |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 401 | |
Johan Hovold | 2315432 | 2010-03-17 23:05:57 +0100 | [diff] [blame] | 402 | void usb_serial_generic_process_read_urb(struct urb *urb) |
Oliver Neukum | 1abdeeb | 2007-05-07 12:09:33 +0200 | [diff] [blame] | 403 | { |
Johan Hovold | 0f3d5ba | 2010-03-17 23:05:56 +0100 | [diff] [blame] | 404 | struct usb_serial_port *port = urb->context; |
| 405 | struct tty_struct *tty; |
Jason Wessel | 98fcb5f | 2009-05-11 15:24:09 -0500 | [diff] [blame] | 406 | char *ch = (char *)urb->transfer_buffer; |
| 407 | int i; |
| 408 | |
Johan Hovold | 0f3d5ba | 2010-03-17 23:05:56 +0100 | [diff] [blame] | 409 | tty = tty_port_tty_get(&port->port); |
Jason Wessel | 98fcb5f | 2009-05-11 15:24:09 -0500 | [diff] [blame] | 410 | if (!tty) |
Johan Hovold | 0f3d5ba | 2010-03-17 23:05:56 +0100 | [diff] [blame] | 411 | return; |
Oliver Neukum | 1abdeeb | 2007-05-07 12:09:33 +0200 | [diff] [blame] | 412 | |
Alan Cox | 4cd1de0 | 2009-07-09 13:35:52 +0100 | [diff] [blame] | 413 | /* The per character mucking around with sysrq path it too slow for |
| 414 | stuff like 3G modems, so shortcircuit it in the 99.9999999% of cases |
| 415 | where the USB serial is not a console anyway */ |
Jason Wessel | bd5afa9 | 2010-03-08 21:50:12 -0600 | [diff] [blame] | 416 | if (!port->port.console || !port->sysrq) |
Alan Cox | 4cd1de0 | 2009-07-09 13:35:52 +0100 | [diff] [blame] | 417 | tty_insert_flip_string(tty, ch, urb->actual_length); |
| 418 | else { |
Alan Cox | 4cd1de0 | 2009-07-09 13:35:52 +0100 | [diff] [blame] | 419 | for (i = 0; i < urb->actual_length; i++, ch++) { |
Alan Cox | 24a15a6 | 2009-07-09 13:36:22 +0100 | [diff] [blame] | 420 | if (!usb_serial_handle_sysrq_char(tty, port, *ch)) |
Alan Cox | 4cd1de0 | 2009-07-09 13:35:52 +0100 | [diff] [blame] | 421 | tty_insert_flip_char(tty, *ch, TTY_NORMAL); |
| 422 | } |
Oliver Neukum | 1abdeeb | 2007-05-07 12:09:33 +0200 | [diff] [blame] | 423 | } |
Jason Wessel | 98fcb5f | 2009-05-11 15:24:09 -0500 | [diff] [blame] | 424 | tty_flip_buffer_push(tty); |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 425 | tty_kref_put(tty); |
Oliver Neukum | 1abdeeb | 2007-05-07 12:09:33 +0200 | [diff] [blame] | 426 | } |
Johan Hovold | 2315432 | 2010-03-17 23:05:57 +0100 | [diff] [blame] | 427 | EXPORT_SYMBOL_GPL(usb_serial_generic_process_read_urb); |
Oliver Neukum | 1abdeeb | 2007-05-07 12:09:33 +0200 | [diff] [blame] | 428 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 429 | void usb_serial_generic_read_bulk_callback(struct urb *urb) |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 430 | { |
Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 431 | struct usb_serial_port *port = urb->context; |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 432 | unsigned char *data = urb->transfer_buffer; |
Greg Kroah-Hartman | fbd27225 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 433 | int status = urb->status; |
Borislav Petkov | bfaeafc | 2007-10-28 13:24:16 +0100 | [diff] [blame] | 434 | unsigned long flags; |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 435 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 436 | dbg("%s - port %d", __func__, port->number); |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 437 | |
Greg Kroah-Hartman | fbd27225 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 438 | if (unlikely(status != 0)) { |
| 439 | dbg("%s - nonzero read bulk status received: %d", |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 440 | __func__, status); |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 441 | return; |
| 442 | } |
| 443 | |
Alan Cox | ae64387 | 2008-07-22 11:11:55 +0100 | [diff] [blame] | 444 | usb_serial_debug_data(debug, &port->dev, __func__, |
| 445 | urb->actual_length, data); |
Johan Hovold | 2315432 | 2010-03-17 23:05:57 +0100 | [diff] [blame] | 446 | port->serial->type->process_read_urb(urb); |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 447 | |
| 448 | /* Throttle the device if requested by tty */ |
Borislav Petkov | bfaeafc | 2007-10-28 13:24:16 +0100 | [diff] [blame] | 449 | spin_lock_irqsave(&port->lock, flags); |
Alan Cox | ae64387 | 2008-07-22 11:11:55 +0100 | [diff] [blame] | 450 | port->throttled = port->throttle_req; |
| 451 | if (!port->throttled) { |
Pete Zaitcev | b507cc9 | 2008-03-04 23:28:42 -0800 | [diff] [blame] | 452 | spin_unlock_irqrestore(&port->lock, flags); |
Johan Hovold | 0f3d5ba | 2010-03-17 23:05:56 +0100 | [diff] [blame] | 453 | usb_serial_generic_submit_read_urb(port, GFP_ATOMIC); |
Alan Cox | ae64387 | 2008-07-22 11:11:55 +0100 | [diff] [blame] | 454 | } else |
Pete Zaitcev | b507cc9 | 2008-03-04 23:28:42 -0800 | [diff] [blame] | 455 | spin_unlock_irqrestore(&port->lock, flags); |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 456 | } |
Luiz Fernando N. Capitulino | 166ffcc | 2006-07-11 14:19:25 -0300 | [diff] [blame] | 457 | EXPORT_SYMBOL_GPL(usb_serial_generic_read_bulk_callback); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 459 | void usb_serial_generic_write_bulk_callback(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | { |
Jason Wessel | 715b1dc | 2009-05-11 15:24:07 -0500 | [diff] [blame] | 461 | unsigned long flags; |
Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 462 | struct usb_serial_port *port = urb->context; |
Greg Kroah-Hartman | fbd27225 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 463 | int status = urb->status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 465 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | |
Johan Hovold | 25d514c | 2010-03-17 23:06:07 +0100 | [diff] [blame] | 467 | if (port->serial->type->multi_urb_write) { |
Johan Hovold | 2591530 | 2010-01-06 15:48:42 -0800 | [diff] [blame] | 468 | kfree(urb->transfer_buffer); |
| 469 | |
Jason Wessel | 715b1dc | 2009-05-11 15:24:07 -0500 | [diff] [blame] | 470 | spin_lock_irqsave(&port->lock, flags); |
Johan Hovold | 25d514c | 2010-03-17 23:06:07 +0100 | [diff] [blame] | 471 | port->tx_bytes -= urb->transfer_buffer_length; |
| 472 | port->tx_urbs--; |
Jason Wessel | 715b1dc | 2009-05-11 15:24:07 -0500 | [diff] [blame] | 473 | spin_unlock_irqrestore(&port->lock, flags); |
| 474 | } else { |
Johan Hovold | 30af7fb | 2010-03-17 23:00:42 +0100 | [diff] [blame] | 475 | spin_lock_irqsave(&port->lock, flags); |
Johan Hovold | 25d514c | 2010-03-17 23:06:07 +0100 | [diff] [blame] | 476 | port->tx_bytes -= urb->transfer_buffer_length; |
Jason Wessel | 715b1dc | 2009-05-11 15:24:07 -0500 | [diff] [blame] | 477 | port->write_urb_busy = 0; |
Johan Hovold | 30af7fb | 2010-03-17 23:00:42 +0100 | [diff] [blame] | 478 | spin_unlock_irqrestore(&port->lock, flags); |
David VomLehn | 8e8dce0 | 2009-08-28 12:54:27 -0700 | [diff] [blame] | 479 | |
Johan Hovold | 50dbb85 | 2010-03-17 23:00:43 +0100 | [diff] [blame] | 480 | if (status) { |
| 481 | spin_lock_irqsave(&port->lock, flags); |
Stefani Seibold | 119eecc | 2009-12-23 09:10:48 +0100 | [diff] [blame] | 482 | kfifo_reset_out(&port->write_fifo); |
Johan Hovold | 50dbb85 | 2010-03-17 23:00:43 +0100 | [diff] [blame] | 483 | spin_unlock_irqrestore(&port->lock, flags); |
| 484 | } else { |
David VomLehn | 8e8dce0 | 2009-08-28 12:54:27 -0700 | [diff] [blame] | 485 | usb_serial_generic_write_start(port); |
Johan Hovold | 50dbb85 | 2010-03-17 23:00:43 +0100 | [diff] [blame] | 486 | } |
Jason Wessel | 715b1dc | 2009-05-11 15:24:07 -0500 | [diff] [blame] | 487 | } |
| 488 | |
Johan Hovold | 6313620 | 2010-02-27 14:06:07 +0100 | [diff] [blame] | 489 | if (status) |
| 490 | dbg("%s - non-zero urb status: %d", __func__, status); |
| 491 | |
Pete Zaitcev | cf2c748 | 2006-05-22 21:58:49 -0700 | [diff] [blame] | 492 | usb_serial_port_softint(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | } |
Greg Kroah-Hartman | bb83398 | 2005-11-17 09:48:18 -0800 | [diff] [blame] | 494 | EXPORT_SYMBOL_GPL(usb_serial_generic_write_bulk_callback); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 496 | void usb_serial_generic_throttle(struct tty_struct *tty) |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 497 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 498 | struct usb_serial_port *port = tty->driver_data; |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 499 | unsigned long flags; |
| 500 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 501 | dbg("%s - port %d", __func__, port->number); |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 502 | |
| 503 | /* Set the throttle request flag. It will be picked up |
| 504 | * by usb_serial_generic_read_bulk_callback(). */ |
| 505 | spin_lock_irqsave(&port->lock, flags); |
| 506 | port->throttle_req = 1; |
| 507 | spin_unlock_irqrestore(&port->lock, flags); |
| 508 | } |
Johan Hovold | f1e949a | 2010-03-17 23:05:59 +0100 | [diff] [blame] | 509 | EXPORT_SYMBOL_GPL(usb_serial_generic_throttle); |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 510 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 511 | void usb_serial_generic_unthrottle(struct tty_struct *tty) |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 512 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 513 | struct usb_serial_port *port = tty->driver_data; |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 514 | int was_throttled; |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 515 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 516 | dbg("%s - port %d", __func__, port->number); |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 517 | |
| 518 | /* Clear the throttle flags */ |
Johan Hovold | 0f3d5ba | 2010-03-17 23:05:56 +0100 | [diff] [blame] | 519 | spin_lock_irq(&port->lock); |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 520 | was_throttled = port->throttled; |
| 521 | port->throttled = port->throttle_req = 0; |
Johan Hovold | 0f3d5ba | 2010-03-17 23:05:56 +0100 | [diff] [blame] | 522 | spin_unlock_irq(&port->lock); |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 523 | |
Johan Hovold | 0f3d5ba | 2010-03-17 23:05:56 +0100 | [diff] [blame] | 524 | if (was_throttled) |
| 525 | usb_serial_generic_submit_read_urb(port, GFP_KERNEL); |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 526 | } |
Johan Hovold | f1e949a | 2010-03-17 23:05:59 +0100 | [diff] [blame] | 527 | EXPORT_SYMBOL_GPL(usb_serial_generic_unthrottle); |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 528 | |
Randy Dunlap | 7f0ae3a | 2010-03-25 11:29:16 -0700 | [diff] [blame] | 529 | #ifdef CONFIG_MAGIC_SYSRQ |
Alan Cox | 24a15a6 | 2009-07-09 13:36:22 +0100 | [diff] [blame] | 530 | int usb_serial_handle_sysrq_char(struct tty_struct *tty, |
| 531 | struct usb_serial_port *port, unsigned int ch) |
Jason Wessel | 98fcb5f | 2009-05-11 15:24:09 -0500 | [diff] [blame] | 532 | { |
Jason Wessel | bd5afa9 | 2010-03-08 21:50:12 -0600 | [diff] [blame] | 533 | if (port->sysrq && port->port.console) { |
Jason Wessel | 98fcb5f | 2009-05-11 15:24:09 -0500 | [diff] [blame] | 534 | if (ch && time_before(jiffies, port->sysrq)) { |
Alan Cox | 24a15a6 | 2009-07-09 13:36:22 +0100 | [diff] [blame] | 535 | handle_sysrq(ch, tty); |
Jason Wessel | 98fcb5f | 2009-05-11 15:24:09 -0500 | [diff] [blame] | 536 | port->sysrq = 0; |
| 537 | return 1; |
| 538 | } |
| 539 | port->sysrq = 0; |
| 540 | } |
| 541 | return 0; |
| 542 | } |
Randy Dunlap | 7f0ae3a | 2010-03-25 11:29:16 -0700 | [diff] [blame] | 543 | #else |
| 544 | int usb_serial_handle_sysrq_char(struct tty_struct *tty, |
| 545 | struct usb_serial_port *port, unsigned int ch) |
| 546 | { |
| 547 | return 0; |
| 548 | } |
| 549 | #endif |
Jason Wessel | 98fcb5f | 2009-05-11 15:24:09 -0500 | [diff] [blame] | 550 | EXPORT_SYMBOL_GPL(usb_serial_handle_sysrq_char); |
| 551 | |
| 552 | int usb_serial_handle_break(struct usb_serial_port *port) |
| 553 | { |
| 554 | if (!port->sysrq) { |
| 555 | port->sysrq = jiffies + HZ*5; |
| 556 | return 1; |
| 557 | } |
| 558 | port->sysrq = 0; |
| 559 | return 0; |
| 560 | } |
| 561 | EXPORT_SYMBOL_GPL(usb_serial_handle_break); |
| 562 | |
David VomLehn | 8e8dce0 | 2009-08-28 12:54:27 -0700 | [diff] [blame] | 563 | int usb_serial_generic_resume(struct usb_serial *serial) |
| 564 | { |
| 565 | struct usb_serial_port *port; |
| 566 | int i, c = 0, r; |
| 567 | |
| 568 | for (i = 0; i < serial->num_ports; i++) { |
| 569 | port = serial->port[i]; |
Alan Stern | 1f87158 | 2010-02-17 10:05:47 -0500 | [diff] [blame] | 570 | if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) |
David VomLehn | 8e8dce0 | 2009-08-28 12:54:27 -0700 | [diff] [blame] | 571 | continue; |
| 572 | |
| 573 | if (port->read_urb) { |
| 574 | r = usb_submit_urb(port->read_urb, GFP_NOIO); |
| 575 | if (r < 0) |
| 576 | c++; |
| 577 | } |
| 578 | |
| 579 | if (port->write_urb) { |
| 580 | r = usb_serial_generic_write_start(port); |
| 581 | if (r < 0) |
| 582 | c++; |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | return c ? -EIO : 0; |
| 587 | } |
| 588 | EXPORT_SYMBOL_GPL(usb_serial_generic_resume); |
| 589 | |
Alan Stern | f9c99bb | 2009-06-02 11:53:55 -0400 | [diff] [blame] | 590 | void usb_serial_generic_disconnect(struct usb_serial *serial) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | { |
| 592 | int i; |
| 593 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 594 | dbg("%s", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | |
| 596 | /* stop reads and writes on all ports */ |
Alan Cox | ae64387 | 2008-07-22 11:11:55 +0100 | [diff] [blame] | 597 | for (i = 0; i < serial->num_ports; ++i) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | generic_cleanup(serial->port[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | } |
| 600 | |
Alan Stern | f9c99bb | 2009-06-02 11:53:55 -0400 | [diff] [blame] | 601 | void usb_serial_generic_release(struct usb_serial *serial) |
| 602 | { |
| 603 | dbg("%s", __func__); |
| 604 | } |