| .. | .. |
|---|
| 106 | 106 | int usb_serial_generic_open(struct tty_struct *tty, struct usb_serial_port *port) |
|---|
| 107 | 107 | { |
|---|
| 108 | 108 | int result = 0; |
|---|
| 109 | | - unsigned long flags; |
|---|
| 110 | 109 | |
|---|
| 111 | | - spin_lock_irqsave(&port->lock, flags); |
|---|
| 112 | | - port->throttled = 0; |
|---|
| 113 | | - port->throttle_req = 0; |
|---|
| 114 | | - spin_unlock_irqrestore(&port->lock, flags); |
|---|
| 110 | + clear_bit(USB_SERIAL_THROTTLED, &port->flags); |
|---|
| 115 | 111 | |
|---|
| 116 | 112 | if (port->bulk_in_size) |
|---|
| 117 | 113 | result = usb_serial_generic_submit_read_urbs(port, GFP_KERNEL); |
|---|
| .. | .. |
|---|
| 349 | 345 | void usb_serial_generic_process_read_urb(struct urb *urb) |
|---|
| 350 | 346 | { |
|---|
| 351 | 347 | struct usb_serial_port *port = urb->context; |
|---|
| 352 | | - char *ch = (char *)urb->transfer_buffer; |
|---|
| 348 | + char *ch = urb->transfer_buffer; |
|---|
| 353 | 349 | int i; |
|---|
| 354 | 350 | |
|---|
| 355 | 351 | if (!urb->actual_length) |
|---|
| .. | .. |
|---|
| 359 | 355 | * stuff like 3G modems, so shortcircuit it in the 99.9999999% of |
|---|
| 360 | 356 | * cases where the USB serial is not a console anyway. |
|---|
| 361 | 357 | */ |
|---|
| 362 | | - if (!port->port.console || !port->sysrq) { |
|---|
| 363 | | - tty_insert_flip_string(&port->port, ch, urb->actual_length); |
|---|
| 364 | | - } else { |
|---|
| 358 | + if (port->sysrq) { |
|---|
| 365 | 359 | for (i = 0; i < urb->actual_length; i++, ch++) { |
|---|
| 366 | 360 | if (!usb_serial_handle_sysrq_char(port, *ch)) |
|---|
| 367 | 361 | tty_insert_flip_char(&port->port, *ch, TTY_NORMAL); |
|---|
| 368 | 362 | } |
|---|
| 363 | + } else { |
|---|
| 364 | + tty_insert_flip_string(&port->port, ch, urb->actual_length); |
|---|
| 369 | 365 | } |
|---|
| 370 | 366 | tty_flip_buffer_push(&port->port); |
|---|
| 371 | 367 | } |
|---|
| .. | .. |
|---|
| 375 | 371 | { |
|---|
| 376 | 372 | struct usb_serial_port *port = urb->context; |
|---|
| 377 | 373 | unsigned char *data = urb->transfer_buffer; |
|---|
| 378 | | - unsigned long flags; |
|---|
| 379 | 374 | bool stopped = false; |
|---|
| 380 | 375 | int status = urb->status; |
|---|
| 381 | 376 | int i; |
|---|
| .. | .. |
|---|
| 422 | 417 | /* |
|---|
| 423 | 418 | * Make sure URB is marked as free before checking the throttled flag |
|---|
| 424 | 419 | * to avoid racing with unthrottle() on another CPU. Matches the |
|---|
| 425 | | - * smp_mb() in unthrottle(). |
|---|
| 420 | + * smp_mb__after_atomic() in unthrottle(). |
|---|
| 426 | 421 | */ |
|---|
| 427 | 422 | smp_mb__after_atomic(); |
|---|
| 428 | 423 | |
|---|
| 429 | 424 | if (stopped) |
|---|
| 430 | 425 | return; |
|---|
| 431 | 426 | |
|---|
| 432 | | - /* Throttle the device if requested by tty */ |
|---|
| 433 | | - spin_lock_irqsave(&port->lock, flags); |
|---|
| 434 | | - port->throttled = port->throttle_req; |
|---|
| 435 | | - if (!port->throttled) { |
|---|
| 436 | | - spin_unlock_irqrestore(&port->lock, flags); |
|---|
| 437 | | - usb_serial_generic_submit_read_urb(port, i, GFP_ATOMIC); |
|---|
| 438 | | - } else { |
|---|
| 439 | | - spin_unlock_irqrestore(&port->lock, flags); |
|---|
| 440 | | - } |
|---|
| 427 | + if (test_bit(USB_SERIAL_THROTTLED, &port->flags)) |
|---|
| 428 | + return; |
|---|
| 429 | + |
|---|
| 430 | + usb_serial_generic_submit_read_urb(port, i, GFP_ATOMIC); |
|---|
| 441 | 431 | } |
|---|
| 442 | 432 | EXPORT_SYMBOL_GPL(usb_serial_generic_read_bulk_callback); |
|---|
| 443 | 433 | |
|---|
| .. | .. |
|---|
| 473 | 463 | default: |
|---|
| 474 | 464 | dev_err_console(port, "%s - nonzero urb status: %d\n", |
|---|
| 475 | 465 | __func__, status); |
|---|
| 476 | | - goto resubmit; |
|---|
| 466 | + break; |
|---|
| 477 | 467 | } |
|---|
| 478 | 468 | |
|---|
| 479 | | -resubmit: |
|---|
| 480 | 469 | usb_serial_generic_write_start(port, GFP_ATOMIC); |
|---|
| 481 | 470 | usb_serial_port_softint(port); |
|---|
| 482 | 471 | } |
|---|
| .. | .. |
|---|
| 485 | 474 | void usb_serial_generic_throttle(struct tty_struct *tty) |
|---|
| 486 | 475 | { |
|---|
| 487 | 476 | struct usb_serial_port *port = tty->driver_data; |
|---|
| 488 | | - unsigned long flags; |
|---|
| 489 | 477 | |
|---|
| 490 | | - spin_lock_irqsave(&port->lock, flags); |
|---|
| 491 | | - port->throttle_req = 1; |
|---|
| 492 | | - spin_unlock_irqrestore(&port->lock, flags); |
|---|
| 478 | + set_bit(USB_SERIAL_THROTTLED, &port->flags); |
|---|
| 493 | 479 | } |
|---|
| 494 | 480 | EXPORT_SYMBOL_GPL(usb_serial_generic_throttle); |
|---|
| 495 | 481 | |
|---|
| 496 | 482 | void usb_serial_generic_unthrottle(struct tty_struct *tty) |
|---|
| 497 | 483 | { |
|---|
| 498 | 484 | struct usb_serial_port *port = tty->driver_data; |
|---|
| 499 | | - int was_throttled; |
|---|
| 500 | 485 | |
|---|
| 501 | | - spin_lock_irq(&port->lock); |
|---|
| 502 | | - was_throttled = port->throttled; |
|---|
| 503 | | - port->throttled = port->throttle_req = 0; |
|---|
| 504 | | - spin_unlock_irq(&port->lock); |
|---|
| 486 | + clear_bit(USB_SERIAL_THROTTLED, &port->flags); |
|---|
| 505 | 487 | |
|---|
| 506 | 488 | /* |
|---|
| 507 | 489 | * Matches the smp_mb__after_atomic() in |
|---|
| 508 | 490 | * usb_serial_generic_read_bulk_callback(). |
|---|
| 509 | 491 | */ |
|---|
| 510 | | - smp_mb(); |
|---|
| 492 | + smp_mb__after_atomic(); |
|---|
| 511 | 493 | |
|---|
| 512 | | - if (was_throttled) |
|---|
| 513 | | - usb_serial_generic_submit_read_urbs(port, GFP_KERNEL); |
|---|
| 494 | + usb_serial_generic_submit_read_urbs(port, GFP_KERNEL); |
|---|
| 514 | 495 | } |
|---|
| 515 | 496 | EXPORT_SYMBOL_GPL(usb_serial_generic_unthrottle); |
|---|
| 516 | 497 | |
|---|
| .. | .. |
|---|
| 590 | 571 | } |
|---|
| 591 | 572 | EXPORT_SYMBOL_GPL(usb_serial_generic_get_icount); |
|---|
| 592 | 573 | |
|---|
| 593 | | -#ifdef CONFIG_MAGIC_SYSRQ |
|---|
| 574 | +#if defined(CONFIG_USB_SERIAL_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) |
|---|
| 594 | 575 | int usb_serial_handle_sysrq_char(struct usb_serial_port *port, unsigned int ch) |
|---|
| 595 | 576 | { |
|---|
| 596 | | - if (port->sysrq && port->port.console) { |
|---|
| 577 | + if (port->sysrq) { |
|---|
| 597 | 578 | if (ch && time_before(jiffies, port->sysrq)) { |
|---|
| 598 | 579 | handle_sysrq(ch); |
|---|
| 599 | 580 | port->sysrq = 0; |
|---|
| .. | .. |
|---|
| 603 | 584 | } |
|---|
| 604 | 585 | return 0; |
|---|
| 605 | 586 | } |
|---|
| 606 | | -#else |
|---|
| 607 | | -int usb_serial_handle_sysrq_char(struct usb_serial_port *port, unsigned int ch) |
|---|
| 608 | | -{ |
|---|
| 609 | | - return 0; |
|---|
| 610 | | -} |
|---|
| 611 | | -#endif |
|---|
| 612 | 587 | EXPORT_SYMBOL_GPL(usb_serial_handle_sysrq_char); |
|---|
| 613 | 588 | |
|---|
| 614 | 589 | int usb_serial_handle_break(struct usb_serial_port *port) |
|---|
| 615 | 590 | { |
|---|
| 591 | + if (!port->port.console) |
|---|
| 592 | + return 0; |
|---|
| 593 | + |
|---|
| 616 | 594 | if (!port->sysrq) { |
|---|
| 617 | 595 | port->sysrq = jiffies + HZ*5; |
|---|
| 618 | 596 | return 1; |
|---|
| .. | .. |
|---|
| 621 | 599 | return 0; |
|---|
| 622 | 600 | } |
|---|
| 623 | 601 | EXPORT_SYMBOL_GPL(usb_serial_handle_break); |
|---|
| 602 | +#endif |
|---|
| 624 | 603 | |
|---|
| 625 | 604 | /** |
|---|
| 626 | 605 | * usb_serial_handle_dcd_change - handle a change of carrier detect state |
|---|
| .. | .. |
|---|
| 628 | 607 | * @tty: tty for the port |
|---|
| 629 | 608 | * @status: new carrier detect status, nonzero if active |
|---|
| 630 | 609 | */ |
|---|
| 631 | | -void usb_serial_handle_dcd_change(struct usb_serial_port *usb_port, |
|---|
| 610 | +void usb_serial_handle_dcd_change(struct usb_serial_port *port, |
|---|
| 632 | 611 | struct tty_struct *tty, unsigned int status) |
|---|
| 633 | 612 | { |
|---|
| 634 | | - struct tty_port *port = &usb_port->port; |
|---|
| 635 | | - |
|---|
| 636 | | - dev_dbg(&usb_port->dev, "%s - status %d\n", __func__, status); |
|---|
| 613 | + dev_dbg(&port->dev, "%s - status %d\n", __func__, status); |
|---|
| 637 | 614 | |
|---|
| 638 | 615 | if (tty) { |
|---|
| 639 | 616 | struct tty_ldisc *ld = tty_ldisc_ref(tty); |
|---|
| .. | .. |
|---|
| 646 | 623 | } |
|---|
| 647 | 624 | |
|---|
| 648 | 625 | if (status) |
|---|
| 649 | | - wake_up_interruptible(&port->open_wait); |
|---|
| 626 | + wake_up_interruptible(&port->port.open_wait); |
|---|
| 650 | 627 | else if (tty && !C_CLOCAL(tty)) |
|---|
| 651 | 628 | tty_hangup(tty); |
|---|
| 652 | 629 | } |
|---|