diff options
Diffstat (limited to 'drivers/usb/serial/generic.c')
-rw-r--r-- | drivers/usb/serial/generic.c | 150 |
1 files changed, 22 insertions, 128 deletions
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c index 3ae17840175c..fcd30b841559 100644 --- a/drivers/usb/serial/generic.c +++ b/drivers/usb/serial/generic.c | |||
@@ -26,8 +26,6 @@ | |||
26 | 26 | ||
27 | static int debug; | 27 | static int debug; |
28 | 28 | ||
29 | #define MAX_TX_URBS 40 | ||
30 | |||
31 | #ifdef CONFIG_USB_SERIAL_GENERIC | 29 | #ifdef CONFIG_USB_SERIAL_GENERIC |
32 | 30 | ||
33 | static int generic_probe(struct usb_interface *interface, | 31 | static int generic_probe(struct usb_interface *interface, |
@@ -172,90 +170,9 @@ void usb_serial_generic_close(struct usb_serial_port *port) | |||
172 | EXPORT_SYMBOL_GPL(usb_serial_generic_close); | 170 | EXPORT_SYMBOL_GPL(usb_serial_generic_close); |
173 | 171 | ||
174 | int usb_serial_generic_prepare_write_buffer(struct usb_serial_port *port, | 172 | int usb_serial_generic_prepare_write_buffer(struct usb_serial_port *port, |
175 | void **dest, size_t size, const void *src, size_t count) | 173 | void *dest, size_t size) |
176 | { | 174 | { |
177 | if (!*dest) { | 175 | return kfifo_out_locked(&port->write_fifo, dest, size, &port->lock); |
178 | size = count; | ||
179 | *dest = kmalloc(count, GFP_ATOMIC); | ||
180 | if (!*dest) { | ||
181 | dev_err(&port->dev, "%s - could not allocate buffer\n", | ||
182 | __func__); | ||
183 | return -ENOMEM; | ||
184 | } | ||
185 | } | ||
186 | if (src) { | ||
187 | count = size; | ||
188 | memcpy(*dest, src, size); | ||
189 | } else { | ||
190 | count = kfifo_out_locked(&port->write_fifo, *dest, size, | ||
191 | &port->lock); | ||
192 | } | ||
193 | return count; | ||
194 | } | ||
195 | EXPORT_SYMBOL_GPL(usb_serial_generic_prepare_write_buffer); | ||
196 | |||
197 | static int usb_serial_multi_urb_write(struct tty_struct *tty, | ||
198 | struct usb_serial_port *port, const unsigned char *buf, int count) | ||
199 | { | ||
200 | unsigned long flags; | ||
201 | struct urb *urb; | ||
202 | void *buffer; | ||
203 | int status; | ||
204 | |||
205 | spin_lock_irqsave(&port->lock, flags); | ||
206 | if (port->tx_urbs == MAX_TX_URBS) { | ||
207 | spin_unlock_irqrestore(&port->lock, flags); | ||
208 | dbg("%s - write limit hit", __func__); | ||
209 | return 0; | ||
210 | } | ||
211 | port->tx_urbs++; | ||
212 | spin_unlock_irqrestore(&port->lock, flags); | ||
213 | |||
214 | urb = usb_alloc_urb(0, GFP_ATOMIC); | ||
215 | if (!urb) { | ||
216 | dev_err(&port->dev, "%s - no free urbs available\n", __func__); | ||
217 | status = -ENOMEM; | ||
218 | goto err_urb; | ||
219 | } | ||
220 | |||
221 | buffer = NULL; | ||
222 | count = min_t(int, count, PAGE_SIZE); | ||
223 | count = port->serial->type->prepare_write_buffer(port, &buffer, 0, | ||
224 | buf, count); | ||
225 | if (count < 0) { | ||
226 | status = count; | ||
227 | goto err_buf; | ||
228 | } | ||
229 | usb_serial_debug_data(debug, &port->dev, __func__, count, buffer); | ||
230 | usb_fill_bulk_urb(urb, port->serial->dev, | ||
231 | usb_sndbulkpipe(port->serial->dev, | ||
232 | port->bulk_out_endpointAddress), | ||
233 | buffer, count, | ||
234 | port->serial->type->write_bulk_callback, port); | ||
235 | |||
236 | status = usb_submit_urb(urb, GFP_ATOMIC); | ||
237 | if (status) { | ||
238 | dev_err(&port->dev, "%s - error submitting urb: %d\n", | ||
239 | __func__, status); | ||
240 | goto err; | ||
241 | } | ||
242 | spin_lock_irqsave(&port->lock, flags); | ||
243 | port->tx_bytes += urb->transfer_buffer_length; | ||
244 | spin_unlock_irqrestore(&port->lock, flags); | ||
245 | |||
246 | usb_free_urb(urb); | ||
247 | |||
248 | return count; | ||
249 | err: | ||
250 | kfree(buffer); | ||
251 | err_buf: | ||
252 | usb_free_urb(urb); | ||
253 | err_urb: | ||
254 | spin_lock_irqsave(&port->lock, flags); | ||
255 | port->tx_urbs--; | ||
256 | spin_unlock_irqrestore(&port->lock, flags); | ||
257 | |||
258 | return status; | ||
259 | } | 176 | } |
260 | 177 | ||
261 | /** | 178 | /** |
@@ -286,8 +203,8 @@ retry: | |||
286 | 203 | ||
287 | urb = port->write_urbs[i]; | 204 | urb = port->write_urbs[i]; |
288 | count = port->serial->type->prepare_write_buffer(port, | 205 | count = port->serial->type->prepare_write_buffer(port, |
289 | &urb->transfer_buffer, | 206 | urb->transfer_buffer, |
290 | port->bulk_out_size, NULL, 0); | 207 | port->bulk_out_size); |
291 | urb->transfer_buffer_length = count; | 208 | urb->transfer_buffer_length = count; |
292 | usb_serial_debug_data(debug, &port->dev, __func__, count, | 209 | usb_serial_debug_data(debug, &port->dev, __func__, count, |
293 | urb->transfer_buffer); | 210 | urb->transfer_buffer); |
@@ -328,7 +245,6 @@ retry: | |||
328 | int usb_serial_generic_write(struct tty_struct *tty, | 245 | int usb_serial_generic_write(struct tty_struct *tty, |
329 | struct usb_serial_port *port, const unsigned char *buf, int count) | 246 | struct usb_serial_port *port, const unsigned char *buf, int count) |
330 | { | 247 | { |
331 | struct usb_serial *serial = port->serial; | ||
332 | int result; | 248 | int result; |
333 | 249 | ||
334 | dbg("%s - port %d", __func__, port->number); | 250 | dbg("%s - port %d", __func__, port->number); |
@@ -340,23 +256,18 @@ int usb_serial_generic_write(struct tty_struct *tty, | |||
340 | if (!count) | 256 | if (!count) |
341 | return 0; | 257 | return 0; |
342 | 258 | ||
343 | if (serial->type->multi_urb_write) | ||
344 | return usb_serial_multi_urb_write(tty, port, buf, count); | ||
345 | |||
346 | count = kfifo_in_locked(&port->write_fifo, buf, count, &port->lock); | 259 | count = kfifo_in_locked(&port->write_fifo, buf, count, &port->lock); |
347 | result = usb_serial_generic_write_start(port); | 260 | result = usb_serial_generic_write_start(port); |
261 | if (result) | ||
262 | return result; | ||
348 | 263 | ||
349 | if (result >= 0) | 264 | return count; |
350 | result = count; | ||
351 | |||
352 | return result; | ||
353 | } | 265 | } |
354 | EXPORT_SYMBOL_GPL(usb_serial_generic_write); | 266 | EXPORT_SYMBOL_GPL(usb_serial_generic_write); |
355 | 267 | ||
356 | int usb_serial_generic_write_room(struct tty_struct *tty) | 268 | int usb_serial_generic_write_room(struct tty_struct *tty) |
357 | { | 269 | { |
358 | struct usb_serial_port *port = tty->driver_data; | 270 | struct usb_serial_port *port = tty->driver_data; |
359 | struct usb_serial *serial = port->serial; | ||
360 | unsigned long flags; | 271 | unsigned long flags; |
361 | int room; | 272 | int room; |
362 | 273 | ||
@@ -366,10 +277,7 @@ int usb_serial_generic_write_room(struct tty_struct *tty) | |||
366 | return 0; | 277 | return 0; |
367 | 278 | ||
368 | spin_lock_irqsave(&port->lock, flags); | 279 | spin_lock_irqsave(&port->lock, flags); |
369 | if (serial->type->multi_urb_write) | 280 | room = kfifo_avail(&port->write_fifo); |
370 | room = (MAX_TX_URBS - port->tx_urbs) * PAGE_SIZE; | ||
371 | else | ||
372 | room = kfifo_avail(&port->write_fifo); | ||
373 | spin_unlock_irqrestore(&port->lock, flags); | 281 | spin_unlock_irqrestore(&port->lock, flags); |
374 | 282 | ||
375 | dbg("%s - returns %d", __func__, room); | 283 | dbg("%s - returns %d", __func__, room); |
@@ -379,7 +287,6 @@ int usb_serial_generic_write_room(struct tty_struct *tty) | |||
379 | int usb_serial_generic_chars_in_buffer(struct tty_struct *tty) | 287 | int usb_serial_generic_chars_in_buffer(struct tty_struct *tty) |
380 | { | 288 | { |
381 | struct usb_serial_port *port = tty->driver_data; | 289 | struct usb_serial_port *port = tty->driver_data; |
382 | struct usb_serial *serial = port->serial; | ||
383 | unsigned long flags; | 290 | unsigned long flags; |
384 | int chars; | 291 | int chars; |
385 | 292 | ||
@@ -389,10 +296,7 @@ int usb_serial_generic_chars_in_buffer(struct tty_struct *tty) | |||
389 | return 0; | 296 | return 0; |
390 | 297 | ||
391 | spin_lock_irqsave(&port->lock, flags); | 298 | spin_lock_irqsave(&port->lock, flags); |
392 | if (serial->type->multi_urb_write) | 299 | chars = kfifo_len(&port->write_fifo) + port->tx_bytes; |
393 | chars = port->tx_bytes; | ||
394 | else | ||
395 | chars = kfifo_len(&port->write_fifo) + port->tx_bytes; | ||
396 | spin_unlock_irqrestore(&port->lock, flags); | 300 | spin_unlock_irqrestore(&port->lock, flags); |
397 | 301 | ||
398 | dbg("%s - returns %d", __func__, chars); | 302 | dbg("%s - returns %d", __func__, chars); |
@@ -479,35 +383,25 @@ void usb_serial_generic_write_bulk_callback(struct urb *urb) | |||
479 | 383 | ||
480 | dbg("%s - port %d", __func__, port->number); | 384 | dbg("%s - port %d", __func__, port->number); |
481 | 385 | ||
482 | if (port->serial->type->multi_urb_write) { | 386 | for (i = 0; i < ARRAY_SIZE(port->write_urbs); ++i) |
483 | kfree(urb->transfer_buffer); | 387 | if (port->write_urbs[i] == urb) |
388 | break; | ||
484 | 389 | ||
485 | spin_lock_irqsave(&port->lock, flags); | 390 | spin_lock_irqsave(&port->lock, flags); |
486 | port->tx_bytes -= urb->transfer_buffer_length; | 391 | port->tx_bytes -= urb->transfer_buffer_length; |
487 | port->tx_urbs--; | 392 | set_bit(i, &port->write_urbs_free); |
488 | spin_unlock_irqrestore(&port->lock, flags); | 393 | spin_unlock_irqrestore(&port->lock, flags); |
489 | } else { | 394 | |
490 | for (i = 0; i < ARRAY_SIZE(port->write_urbs); ++i) | 395 | if (status) { |
491 | if (port->write_urbs[i] == urb) | 396 | dbg("%s - non-zero urb status: %d", __func__, status); |
492 | break; | ||
493 | 397 | ||
494 | spin_lock_irqsave(&port->lock, flags); | 398 | spin_lock_irqsave(&port->lock, flags); |
495 | port->tx_bytes -= urb->transfer_buffer_length; | 399 | kfifo_reset_out(&port->write_fifo); |
496 | set_bit(i, &port->write_urbs_free); | ||
497 | spin_unlock_irqrestore(&port->lock, flags); | 400 | spin_unlock_irqrestore(&port->lock, flags); |
498 | 401 | } else { | |
499 | if (status) { | 402 | usb_serial_generic_write_start(port); |
500 | spin_lock_irqsave(&port->lock, flags); | ||
501 | kfifo_reset_out(&port->write_fifo); | ||
502 | spin_unlock_irqrestore(&port->lock, flags); | ||
503 | } else { | ||
504 | usb_serial_generic_write_start(port); | ||
505 | } | ||
506 | } | 403 | } |
507 | 404 | ||
508 | if (status) | ||
509 | dbg("%s - non-zero urb status: %d", __func__, status); | ||
510 | |||
511 | usb_serial_port_softint(port); | 405 | usb_serial_port_softint(port); |
512 | } | 406 | } |
513 | EXPORT_SYMBOL_GPL(usb_serial_generic_write_bulk_callback); | 407 | EXPORT_SYMBOL_GPL(usb_serial_generic_write_bulk_callback); |