diff options
author | Jason Wessel <jason.wessel@windriver.com> | 2009-05-11 16:24:09 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2009-06-16 00:44:45 -0400 |
commit | 98fcb5f78165b8a3d93870ad7afd4d9ebbb8b43a (patch) | |
tree | ed64298e8b6bf47ba9c57db298e732429f7f669e /drivers/usb/serial/generic.c | |
parent | 87c1edd217a6742e48028db6664d7763de0449f6 (diff) |
USB: serial: usb_debug,usb_generic_serial: implement sysrq and serial break
The usb_debug driver was modified to implement serial break handling
by using a "magic" data packet comprised of the sequence:
0x00 0xff 0x01 0xfe 0x00 0xfe 0x01 0xff
When the tty layer requests a serial break the usb_debug driver sends
the magic packet. On the receiving side the magic packet is thrown
away or a sysrq is activated depending on what kernel .config options
have been set.
The generic serial driver was modified as well as the usb serial
headers to generically implement sysrq processing in the same way the
non usb uart based drivers implement the sysrq handling. This will
allow other usb serial devices to implement sysrq handling as desired.
The new usb serial functions are named similarly and implemented
similarly to the uart functions as follows:
usb_serial_handle_break <-> uart_handle_break
usb_serial_handle_sysrq_char <-> uart_handle_sysrq_char
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/serial/generic.c')
-rw-r--r-- | drivers/usb/serial/generic.c | 56 |
1 files changed, 44 insertions, 12 deletions
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c index c919686521ff..9fccc26235a2 100644 --- a/drivers/usb/serial/generic.c +++ b/drivers/usb/serial/generic.c | |||
@@ -339,6 +339,7 @@ int usb_serial_generic_write(struct tty_struct *tty, | |||
339 | /* no bulk out, so return 0 bytes written */ | 339 | /* no bulk out, so return 0 bytes written */ |
340 | return 0; | 340 | return 0; |
341 | } | 341 | } |
342 | EXPORT_SYMBOL_GPL(usb_serial_generic_write); | ||
342 | 343 | ||
343 | int usb_serial_generic_write_room(struct tty_struct *tty) | 344 | int usb_serial_generic_write_room(struct tty_struct *tty) |
344 | { | 345 | { |
@@ -351,7 +352,9 @@ int usb_serial_generic_write_room(struct tty_struct *tty) | |||
351 | spin_lock_irqsave(&port->lock, flags); | 352 | spin_lock_irqsave(&port->lock, flags); |
352 | if (serial->type->max_in_flight_urbs) { | 353 | if (serial->type->max_in_flight_urbs) { |
353 | if (port->urbs_in_flight < serial->type->max_in_flight_urbs) | 354 | if (port->urbs_in_flight < serial->type->max_in_flight_urbs) |
354 | room = port->bulk_out_size; | 355 | room = port->bulk_out_size * |
356 | (serial->type->max_in_flight_urbs - | ||
357 | port->urbs_in_flight); | ||
355 | } else if (serial->num_bulk_out && !(port->write_urb_busy)) { | 358 | } else if (serial->num_bulk_out && !(port->write_urb_busy)) { |
356 | room = port->bulk_out_size; | 359 | room = port->bulk_out_size; |
357 | } | 360 | } |
@@ -385,7 +388,8 @@ int usb_serial_generic_chars_in_buffer(struct tty_struct *tty) | |||
385 | } | 388 | } |
386 | 389 | ||
387 | 390 | ||
388 | static void resubmit_read_urb(struct usb_serial_port *port, gfp_t mem_flags) | 391 | void usb_serial_generic_resubmit_read_urb(struct usb_serial_port *port, |
392 | gfp_t mem_flags) | ||
389 | { | 393 | { |
390 | struct urb *urb = port->read_urb; | 394 | struct urb *urb = port->read_urb; |
391 | struct usb_serial *serial = port->serial; | 395 | struct usb_serial *serial = port->serial; |
@@ -406,25 +410,28 @@ static void resubmit_read_urb(struct usb_serial_port *port, gfp_t mem_flags) | |||
406 | "%s - failed resubmitting read urb, error %d\n", | 410 | "%s - failed resubmitting read urb, error %d\n", |
407 | __func__, result); | 411 | __func__, result); |
408 | } | 412 | } |
413 | EXPORT_SYMBOL_GPL(usb_serial_generic_resubmit_read_urb); | ||
409 | 414 | ||
410 | /* Push data to tty layer and resubmit the bulk read URB */ | 415 | /* Push data to tty layer and resubmit the bulk read URB */ |
411 | static void flush_and_resubmit_read_urb(struct usb_serial_port *port) | 416 | static void flush_and_resubmit_read_urb(struct usb_serial_port *port) |
412 | { | 417 | { |
413 | struct urb *urb = port->read_urb; | 418 | struct urb *urb = port->read_urb; |
414 | struct tty_struct *tty = tty_port_tty_get(&port->port); | 419 | struct tty_struct *tty = tty_port_tty_get(&port->port); |
415 | int room; | 420 | char *ch = (char *)urb->transfer_buffer; |
421 | int i; | ||
422 | |||
423 | if (!tty) | ||
424 | goto done; | ||
416 | 425 | ||
417 | /* Push data to tty */ | 426 | /* Push data to tty */ |
418 | if (tty && urb->actual_length) { | 427 | for (i = 0; i < urb->actual_length; i++, ch++) { |
419 | room = tty_buffer_request_room(tty, urb->actual_length); | 428 | if (!usb_serial_handle_sysrq_char(port, *ch)) |
420 | if (room) { | 429 | tty_insert_flip_char(tty, *ch, TTY_NORMAL); |
421 | tty_insert_flip_string(tty, urb->transfer_buffer, room); | ||
422 | tty_flip_buffer_push(tty); | ||
423 | } | ||
424 | } | 430 | } |
431 | tty_flip_buffer_push(tty); | ||
425 | tty_kref_put(tty); | 432 | tty_kref_put(tty); |
426 | 433 | done: | |
427 | resubmit_read_urb(port, GFP_ATOMIC); | 434 | usb_serial_generic_resubmit_read_urb(port, GFP_ATOMIC); |
428 | } | 435 | } |
429 | 436 | ||
430 | void usb_serial_generic_read_bulk_callback(struct urb *urb) | 437 | void usb_serial_generic_read_bulk_callback(struct urb *urb) |
@@ -515,10 +522,35 @@ void usb_serial_generic_unthrottle(struct tty_struct *tty) | |||
515 | 522 | ||
516 | if (was_throttled) { | 523 | if (was_throttled) { |
517 | /* Resume reading from device */ | 524 | /* Resume reading from device */ |
518 | resubmit_read_urb(port, GFP_KERNEL); | 525 | usb_serial_generic_resubmit_read_urb(port, GFP_KERNEL); |
519 | } | 526 | } |
520 | } | 527 | } |
521 | 528 | ||
529 | int usb_serial_handle_sysrq_char(struct usb_serial_port *port, unsigned int ch) | ||
530 | { | ||
531 | if (port->sysrq) { | ||
532 | if (ch && time_before(jiffies, port->sysrq)) { | ||
533 | handle_sysrq(ch, tty_port_tty_get(&port->port)); | ||
534 | port->sysrq = 0; | ||
535 | return 1; | ||
536 | } | ||
537 | port->sysrq = 0; | ||
538 | } | ||
539 | return 0; | ||
540 | } | ||
541 | EXPORT_SYMBOL_GPL(usb_serial_handle_sysrq_char); | ||
542 | |||
543 | int usb_serial_handle_break(struct usb_serial_port *port) | ||
544 | { | ||
545 | if (!port->sysrq) { | ||
546 | port->sysrq = jiffies + HZ*5; | ||
547 | return 1; | ||
548 | } | ||
549 | port->sysrq = 0; | ||
550 | return 0; | ||
551 | } | ||
552 | EXPORT_SYMBOL_GPL(usb_serial_handle_break); | ||
553 | |||
522 | void usb_serial_generic_shutdown(struct usb_serial *serial) | 554 | void usb_serial_generic_shutdown(struct usb_serial *serial) |
523 | { | 555 | { |
524 | int i; | 556 | int i; |