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