.. | .. |
---|
16 | 16 | |
---|
17 | 17 | #include <linux/kernel.h> |
---|
18 | 18 | #include <linux/sched.h> |
---|
19 | | -#include <linux/interrupt.h> |
---|
20 | 19 | #include <linux/device.h> |
---|
21 | 20 | #include <linux/delay.h> |
---|
22 | 21 | #include <linux/tty.h> |
---|
.. | .. |
---|
26 | 25 | #include <linux/module.h> |
---|
27 | 26 | #include <linux/console.h> |
---|
28 | 27 | #include <linux/kthread.h> |
---|
| 28 | +#include <linux/workqueue.h> |
---|
29 | 29 | #include <linux/kfifo.h> |
---|
30 | 30 | |
---|
31 | 31 | #include "u_serial.h" |
---|
.. | .. |
---|
81 | 81 | #define WRITE_BUF_SIZE 8192 /* TX only */ |
---|
82 | 82 | #define GS_CONSOLE_BUF_SIZE 8192 |
---|
83 | 83 | |
---|
| 84 | +/* Prevents race conditions while accessing gser->ioport */ |
---|
| 85 | +static DEFINE_SPINLOCK(serial_port_lock); |
---|
| 86 | + |
---|
84 | 87 | /* console info */ |
---|
85 | | -struct gscons_info { |
---|
86 | | - struct gs_port *port; |
---|
87 | | - struct task_struct *console_thread; |
---|
88 | | - struct kfifo con_buf; |
---|
89 | | - /* protect the buf and busy flag */ |
---|
90 | | - spinlock_t con_lock; |
---|
91 | | - int req_busy; |
---|
92 | | - struct usb_request *console_req; |
---|
| 88 | +struct gs_console { |
---|
| 89 | + struct console console; |
---|
| 90 | + struct work_struct work; |
---|
| 91 | + spinlock_t lock; |
---|
| 92 | + struct usb_request *req; |
---|
| 93 | + struct kfifo buf; |
---|
| 94 | + size_t missed; |
---|
93 | 95 | }; |
---|
94 | 96 | |
---|
95 | 97 | /* |
---|
.. | .. |
---|
101 | 103 | spinlock_t port_lock; /* guard port_* access */ |
---|
102 | 104 | |
---|
103 | 105 | struct gserial *port_usb; |
---|
| 106 | +#ifdef CONFIG_U_SERIAL_CONSOLE |
---|
| 107 | + struct gs_console *console; |
---|
| 108 | +#endif |
---|
104 | 109 | |
---|
105 | | - bool openclose; /* open/close in progress */ |
---|
106 | 110 | u8 port_num; |
---|
107 | 111 | |
---|
108 | 112 | struct list_head read_pool; |
---|
.. | .. |
---|
110 | 114 | int read_allocated; |
---|
111 | 115 | struct list_head read_queue; |
---|
112 | 116 | unsigned n_read; |
---|
113 | | - struct tasklet_struct push; |
---|
| 117 | + struct delayed_work push; |
---|
114 | 118 | |
---|
115 | 119 | struct list_head write_pool; |
---|
116 | 120 | int write_started; |
---|
.. | .. |
---|
119 | 123 | wait_queue_head_t drain_wait; /* wait while writes drain */ |
---|
120 | 124 | bool write_busy; |
---|
121 | 125 | wait_queue_head_t close_wait; |
---|
| 126 | + bool suspended; /* port suspended */ |
---|
| 127 | + bool start_delayed; /* delay start when suspended */ |
---|
122 | 128 | |
---|
123 | 129 | /* REVISIT this state ... */ |
---|
124 | 130 | struct usb_cdc_line_coding port_line_coding; /* 8-N-1 etc */ |
---|
.. | .. |
---|
255 | 261 | list_del(&req->list); |
---|
256 | 262 | req->zero = kfifo_is_empty(&port->port_write_buf); |
---|
257 | 263 | |
---|
258 | | - pr_vdebug("ttyGS%d: tx len=%d, 0x%02x 0x%02x 0x%02x ...\n", |
---|
259 | | - port->port_num, len, *((u8 *)req->buf), |
---|
260 | | - *((u8 *)req->buf+1), *((u8 *)req->buf+2)); |
---|
| 264 | + pr_vdebug("ttyGS%d: tx len=%d, %3ph ...\n", port->port_num, len, req->buf); |
---|
261 | 265 | |
---|
262 | 266 | /* Drop lock while we call out of driver; completions |
---|
263 | 267 | * could be issued while we do so. Disconnection may |
---|
.. | .. |
---|
343 | 347 | } |
---|
344 | 348 | |
---|
345 | 349 | /* |
---|
346 | | - * RX tasklet takes data out of the RX queue and hands it up to the TTY |
---|
| 350 | + * RX work takes data out of the RX queue and hands it up to the TTY |
---|
347 | 351 | * layer until it refuses to take any more data (or is throttled back). |
---|
348 | 352 | * Then it issues reads for any further data. |
---|
349 | 353 | * |
---|
.. | .. |
---|
352 | 356 | * So QUEUE_SIZE packets plus however many the FIFO holds (usually two) |
---|
353 | 357 | * can be buffered before the TTY layer's buffers (currently 64 KB). |
---|
354 | 358 | */ |
---|
355 | | -static void gs_rx_push(unsigned long _port) |
---|
| 359 | +static void gs_rx_push(struct work_struct *work) |
---|
356 | 360 | { |
---|
357 | | - struct gs_port *port = (void *)_port; |
---|
| 361 | + struct delayed_work *w = to_delayed_work(work); |
---|
| 362 | + struct gs_port *port = container_of(w, struct gs_port, push); |
---|
358 | 363 | struct tty_struct *tty; |
---|
359 | 364 | struct list_head *queue = &port->read_queue; |
---|
360 | 365 | bool disconnect = false; |
---|
.. | .. |
---|
382 | 387 | /* presumably a transient fault */ |
---|
383 | 388 | pr_warn("ttyGS%d: unexpected RX status %d\n", |
---|
384 | 389 | port->port_num, req->status); |
---|
385 | | - /* FALLTHROUGH */ |
---|
| 390 | + fallthrough; |
---|
386 | 391 | case 0: |
---|
387 | 392 | /* normal completion */ |
---|
388 | 393 | break; |
---|
.. | .. |
---|
429 | 434 | |
---|
430 | 435 | /* We want our data queue to become empty ASAP, keeping data |
---|
431 | 436 | * in the tty and ldisc (not here). If we couldn't push any |
---|
432 | | - * this time around, there may be trouble unless there's an |
---|
433 | | - * implicit tty_unthrottle() call on its way... |
---|
| 437 | + * this time around, RX may be starved, so wait until next jiffy. |
---|
434 | 438 | * |
---|
435 | | - * REVISIT we should probably add a timer to keep the tasklet |
---|
436 | | - * from starving ... but it's not clear that case ever happens. |
---|
| 439 | + * We may leave non-empty queue only when there is a tty, and |
---|
| 440 | + * either it is throttled or there is no more room in flip buffer. |
---|
437 | 441 | */ |
---|
438 | | - if (!list_empty(queue) && tty) { |
---|
439 | | - if (!tty_throttled(tty)) { |
---|
440 | | - if (do_push) |
---|
441 | | - tasklet_schedule(&port->push); |
---|
442 | | - else |
---|
443 | | - pr_warn("ttyGS%d: RX not scheduled?\n", |
---|
444 | | - port->port_num); |
---|
445 | | - } |
---|
446 | | - } |
---|
| 442 | + if (!list_empty(queue) && !tty_throttled(tty)) |
---|
| 443 | + schedule_delayed_work(&port->push, 1); |
---|
447 | 444 | |
---|
448 | 445 | /* If we're still connected, refill the USB RX queue. */ |
---|
449 | 446 | if (!disconnect && port->port_usb) |
---|
.. | .. |
---|
459 | 456 | /* Queue all received data until the tty layer is ready for it. */ |
---|
460 | 457 | spin_lock(&port->port_lock); |
---|
461 | 458 | list_add_tail(&req->list, &port->read_queue); |
---|
462 | | - tasklet_schedule(&port->push); |
---|
| 459 | + schedule_delayed_work(&port->push, 0); |
---|
463 | 460 | spin_unlock(&port->port_lock); |
---|
464 | 461 | } |
---|
465 | 462 | |
---|
.. | .. |
---|
476 | 473 | /* presumably a transient fault */ |
---|
477 | 474 | pr_warn("%s: unexpected %s status %d\n", |
---|
478 | 475 | __func__, ep->name, req->status); |
---|
479 | | - /* FALL THROUGH */ |
---|
| 476 | + fallthrough; |
---|
480 | 477 | case 0: |
---|
481 | 478 | /* normal completion */ |
---|
482 | 479 | gs_start_tx(port); |
---|
.. | .. |
---|
531 | 528 | |
---|
532 | 529 | /** |
---|
533 | 530 | * gs_start_io - start USB I/O streams |
---|
534 | | - * @dev: encapsulates endpoints to use |
---|
| 531 | + * @port: port to use |
---|
535 | 532 | * Context: holding port_lock; port_tty and port_usb are non-null |
---|
536 | 533 | * |
---|
537 | 534 | * We only start I/O when something is connected to both sides of |
---|
.. | .. |
---|
595 | 592 | { |
---|
596 | 593 | int port_num = tty->index; |
---|
597 | 594 | struct gs_port *port; |
---|
598 | | - int status; |
---|
| 595 | + int status = 0; |
---|
599 | 596 | |
---|
600 | | - do { |
---|
601 | | - mutex_lock(&ports[port_num].lock); |
---|
602 | | - port = ports[port_num].port; |
---|
603 | | - if (!port) |
---|
604 | | - status = -ENODEV; |
---|
605 | | - else { |
---|
606 | | - spin_lock_irq(&port->port_lock); |
---|
| 597 | + mutex_lock(&ports[port_num].lock); |
---|
| 598 | + port = ports[port_num].port; |
---|
| 599 | + if (!port) { |
---|
| 600 | + status = -ENODEV; |
---|
| 601 | + goto out; |
---|
| 602 | + } |
---|
607 | 603 | |
---|
608 | | - /* already open? Great. */ |
---|
609 | | - if (port->port.count) { |
---|
610 | | - status = 0; |
---|
611 | | - port->port.count++; |
---|
612 | | - |
---|
613 | | - /* currently opening/closing? wait ... */ |
---|
614 | | - } else if (port->openclose) { |
---|
615 | | - status = -EBUSY; |
---|
616 | | - |
---|
617 | | - /* ... else we do the work */ |
---|
618 | | - } else { |
---|
619 | | - status = -EAGAIN; |
---|
620 | | - port->openclose = true; |
---|
621 | | - } |
---|
622 | | - spin_unlock_irq(&port->port_lock); |
---|
623 | | - } |
---|
624 | | - mutex_unlock(&ports[port_num].lock); |
---|
625 | | - |
---|
626 | | - switch (status) { |
---|
627 | | - default: |
---|
628 | | - /* fully handled */ |
---|
629 | | - return status; |
---|
630 | | - case -EAGAIN: |
---|
631 | | - /* must do the work */ |
---|
632 | | - break; |
---|
633 | | - case -EBUSY: |
---|
634 | | - /* wait for EAGAIN task to finish */ |
---|
635 | | - msleep(1); |
---|
636 | | - /* REVISIT could have a waitchannel here, if |
---|
637 | | - * concurrent open performance is important |
---|
638 | | - */ |
---|
639 | | - break; |
---|
640 | | - } |
---|
641 | | - } while (status != -EAGAIN); |
---|
642 | | - |
---|
643 | | - /* Do the "real open" */ |
---|
644 | 604 | spin_lock_irq(&port->port_lock); |
---|
645 | 605 | |
---|
646 | 606 | /* allocate circular buffer on first open */ |
---|
647 | 607 | if (!kfifo_initialized(&port->port_write_buf)) { |
---|
648 | 608 | |
---|
649 | 609 | spin_unlock_irq(&port->port_lock); |
---|
| 610 | + |
---|
| 611 | + /* |
---|
| 612 | + * portmaster's mutex still protects from simultaneous open(), |
---|
| 613 | + * and close() can't happen, yet. |
---|
| 614 | + */ |
---|
| 615 | + |
---|
650 | 616 | status = kfifo_alloc(&port->port_write_buf, |
---|
651 | 617 | WRITE_BUF_SIZE, GFP_KERNEL); |
---|
652 | | - spin_lock_irq(&port->port_lock); |
---|
653 | | - |
---|
654 | 618 | if (status) { |
---|
655 | 619 | pr_debug("gs_open: ttyGS%d (%p,%p) no buffer\n", |
---|
656 | | - port->port_num, tty, file); |
---|
657 | | - port->openclose = false; |
---|
658 | | - goto exit_unlock_port; |
---|
| 620 | + port_num, tty, file); |
---|
| 621 | + goto out; |
---|
659 | 622 | } |
---|
| 623 | + |
---|
| 624 | + spin_lock_irq(&port->port_lock); |
---|
660 | 625 | } |
---|
661 | 626 | |
---|
662 | | - /* REVISIT if REMOVED (ports[].port NULL), abort the open |
---|
663 | | - * to let rmmod work faster (but this way isn't wrong). |
---|
664 | | - */ |
---|
665 | | - |
---|
666 | | - /* REVISIT maybe wait for "carrier detect" */ |
---|
| 627 | + /* already open? Great. */ |
---|
| 628 | + if (port->port.count++) |
---|
| 629 | + goto exit_unlock_port; |
---|
667 | 630 | |
---|
668 | 631 | tty->driver_data = port; |
---|
669 | 632 | port->port.tty = tty; |
---|
670 | 633 | |
---|
671 | | - port->port.count = 1; |
---|
672 | | - port->openclose = false; |
---|
673 | | - |
---|
674 | 634 | /* if connected, start the I/O stream */ |
---|
675 | 635 | if (port->port_usb) { |
---|
676 | | - struct gserial *gser = port->port_usb; |
---|
| 636 | + /* if port is suspended, wait resume to start I/0 stream */ |
---|
| 637 | + if (!port->suspended) { |
---|
| 638 | + struct gserial *gser = port->port_usb; |
---|
677 | 639 | |
---|
678 | | - pr_debug("gs_open: start ttyGS%d\n", port->port_num); |
---|
679 | | - gs_start_io(port); |
---|
| 640 | + pr_debug("gs_open: start ttyGS%d\n", port->port_num); |
---|
| 641 | + gs_start_io(port); |
---|
680 | 642 | |
---|
681 | | - if (gser->connect) |
---|
682 | | - gser->connect(gser); |
---|
| 643 | + if (gser->connect) |
---|
| 644 | + gser->connect(gser); |
---|
| 645 | + } else { |
---|
| 646 | + pr_debug("delay start of ttyGS%d\n", port->port_num); |
---|
| 647 | + port->start_delayed = true; |
---|
| 648 | + } |
---|
683 | 649 | } |
---|
684 | 650 | |
---|
685 | 651 | pr_debug("gs_open: ttyGS%d (%p,%p)\n", port->port_num, tty, file); |
---|
686 | 652 | |
---|
687 | | - status = 0; |
---|
688 | | - |
---|
689 | 653 | exit_unlock_port: |
---|
690 | 654 | spin_unlock_irq(&port->port_lock); |
---|
| 655 | +out: |
---|
| 656 | + mutex_unlock(&ports[port_num].lock); |
---|
691 | 657 | return status; |
---|
692 | 658 | } |
---|
693 | 659 | |
---|
694 | | -static int gs_writes_finished(struct gs_port *p) |
---|
| 660 | +static int gs_close_flush_done(struct gs_port *p) |
---|
695 | 661 | { |
---|
696 | 662 | int cond; |
---|
697 | 663 | |
---|
698 | | - /* return true on disconnect or empty buffer */ |
---|
| 664 | + /* return true on disconnect or empty buffer or if raced with open() */ |
---|
699 | 665 | spin_lock_irq(&p->port_lock); |
---|
700 | | - cond = (p->port_usb == NULL) || !kfifo_len(&p->port_write_buf); |
---|
| 666 | + cond = p->port_usb == NULL || !kfifo_len(&p->port_write_buf) || |
---|
| 667 | + p->port.count > 1; |
---|
701 | 668 | spin_unlock_irq(&p->port_lock); |
---|
702 | 669 | |
---|
703 | 670 | return cond; |
---|
.. | .. |
---|
711 | 678 | spin_lock_irq(&port->port_lock); |
---|
712 | 679 | |
---|
713 | 680 | if (port->port.count != 1) { |
---|
| 681 | +raced_with_open: |
---|
714 | 682 | if (port->port.count == 0) |
---|
715 | 683 | WARN_ON(1); |
---|
716 | 684 | else |
---|
.. | .. |
---|
720 | 688 | |
---|
721 | 689 | pr_debug("gs_close: ttyGS%d (%p,%p) ...\n", port->port_num, tty, file); |
---|
722 | 690 | |
---|
723 | | - /* mark port as closing but in use; we can drop port lock |
---|
724 | | - * and sleep if necessary |
---|
725 | | - */ |
---|
726 | | - port->openclose = true; |
---|
727 | | - port->port.count = 0; |
---|
728 | | - |
---|
729 | 691 | gser = port->port_usb; |
---|
730 | | - if (gser && gser->disconnect) |
---|
| 692 | + if (gser && !port->suspended && gser->disconnect) |
---|
731 | 693 | gser->disconnect(gser); |
---|
732 | 694 | |
---|
733 | 695 | /* wait for circular write buffer to drain, disconnect, or at |
---|
.. | .. |
---|
736 | 698 | if (kfifo_len(&port->port_write_buf) > 0 && gser) { |
---|
737 | 699 | spin_unlock_irq(&port->port_lock); |
---|
738 | 700 | wait_event_interruptible_timeout(port->drain_wait, |
---|
739 | | - gs_writes_finished(port), |
---|
| 701 | + gs_close_flush_done(port), |
---|
740 | 702 | GS_CLOSE_TIMEOUT * HZ); |
---|
741 | 703 | spin_lock_irq(&port->port_lock); |
---|
| 704 | + |
---|
| 705 | + if (port->port.count != 1) |
---|
| 706 | + goto raced_with_open; |
---|
| 707 | + |
---|
742 | 708 | gser = port->port_usb; |
---|
743 | 709 | } |
---|
744 | 710 | |
---|
745 | 711 | /* Iff we're disconnected, there can be no I/O in flight so it's |
---|
746 | 712 | * ok to free the circular buffer; else just scrub it. And don't |
---|
747 | | - * let the push tasklet fire again until we're re-opened. |
---|
| 713 | + * let the push async work fire again until we're re-opened. |
---|
748 | 714 | */ |
---|
749 | 715 | if (gser == NULL) |
---|
750 | 716 | kfifo_free(&port->port_write_buf); |
---|
751 | 717 | else |
---|
752 | 718 | kfifo_reset(&port->port_write_buf); |
---|
753 | 719 | |
---|
| 720 | + port->start_delayed = false; |
---|
| 721 | + port->port.count = 0; |
---|
754 | 722 | port->port.tty = NULL; |
---|
755 | | - |
---|
756 | | - port->openclose = false; |
---|
757 | 723 | |
---|
758 | 724 | pr_debug("gs_close: ttyGS%d (%p,%p) done!\n", |
---|
759 | 725 | port->port_num, tty, file); |
---|
.. | .. |
---|
856 | 822 | * rts/cts, or other handshaking with the host, but if the |
---|
857 | 823 | * read queue backs up enough we'll be NAKing OUT packets. |
---|
858 | 824 | */ |
---|
859 | | - tasklet_schedule(&port->push); |
---|
860 | 825 | pr_vdebug("ttyGS%d: unthrottle\n", port->port_num); |
---|
| 826 | + schedule_delayed_work(&port->push, 0); |
---|
861 | 827 | } |
---|
862 | 828 | spin_unlock_irqrestore(&port->port_lock, flags); |
---|
863 | 829 | } |
---|
.. | .. |
---|
898 | 864 | |
---|
899 | 865 | #ifdef CONFIG_U_SERIAL_CONSOLE |
---|
900 | 866 | |
---|
901 | | -static struct gscons_info gscons_info; |
---|
902 | | -static struct console gserial_cons; |
---|
903 | | - |
---|
904 | | -static struct usb_request *gs_request_new(struct usb_ep *ep) |
---|
| 867 | +static void gs_console_complete_out(struct usb_ep *ep, struct usb_request *req) |
---|
905 | 868 | { |
---|
906 | | - struct usb_request *req = usb_ep_alloc_request(ep, GFP_ATOMIC); |
---|
907 | | - if (!req) |
---|
908 | | - return NULL; |
---|
909 | | - |
---|
910 | | - req->buf = kmalloc(ep->maxpacket, GFP_ATOMIC); |
---|
911 | | - if (!req->buf) { |
---|
912 | | - usb_ep_free_request(ep, req); |
---|
913 | | - return NULL; |
---|
914 | | - } |
---|
915 | | - |
---|
916 | | - return req; |
---|
917 | | -} |
---|
918 | | - |
---|
919 | | -static void gs_request_free(struct usb_request *req, struct usb_ep *ep) |
---|
920 | | -{ |
---|
921 | | - if (!req) |
---|
922 | | - return; |
---|
923 | | - |
---|
924 | | - kfree(req->buf); |
---|
925 | | - usb_ep_free_request(ep, req); |
---|
926 | | -} |
---|
927 | | - |
---|
928 | | -static void gs_complete_out(struct usb_ep *ep, struct usb_request *req) |
---|
929 | | -{ |
---|
930 | | - struct gscons_info *info = &gscons_info; |
---|
| 869 | + struct gs_console *cons = req->context; |
---|
931 | 870 | |
---|
932 | 871 | switch (req->status) { |
---|
933 | 872 | default: |
---|
934 | 873 | pr_warn("%s: unexpected %s status %d\n", |
---|
935 | 874 | __func__, ep->name, req->status); |
---|
936 | | - /* fall through */ |
---|
| 875 | + fallthrough; |
---|
937 | 876 | case 0: |
---|
938 | 877 | /* normal completion */ |
---|
939 | | - spin_lock(&info->con_lock); |
---|
940 | | - info->req_busy = 0; |
---|
941 | | - spin_unlock(&info->con_lock); |
---|
942 | | - |
---|
943 | | - wake_up_process(info->console_thread); |
---|
| 878 | + spin_lock(&cons->lock); |
---|
| 879 | + req->length = 0; |
---|
| 880 | + schedule_work(&cons->work); |
---|
| 881 | + spin_unlock(&cons->lock); |
---|
944 | 882 | break; |
---|
| 883 | + case -ECONNRESET: |
---|
945 | 884 | case -ESHUTDOWN: |
---|
946 | 885 | /* disconnect */ |
---|
947 | 886 | pr_vdebug("%s: %s shutdown\n", __func__, ep->name); |
---|
.. | .. |
---|
949 | 888 | } |
---|
950 | 889 | } |
---|
951 | 890 | |
---|
952 | | -static int gs_console_connect(int port_num) |
---|
| 891 | +static void __gs_console_push(struct gs_console *cons) |
---|
953 | 892 | { |
---|
954 | | - struct gscons_info *info = &gscons_info; |
---|
955 | | - struct gs_port *port; |
---|
| 893 | + struct usb_request *req = cons->req; |
---|
956 | 894 | struct usb_ep *ep; |
---|
| 895 | + size_t size; |
---|
957 | 896 | |
---|
958 | | - if (port_num != gserial_cons.index) { |
---|
959 | | - pr_err("%s: port num [%d] is not support console\n", |
---|
960 | | - __func__, port_num); |
---|
961 | | - return -ENXIO; |
---|
| 897 | + if (!req) |
---|
| 898 | + return; /* disconnected */ |
---|
| 899 | + |
---|
| 900 | + if (req->length) |
---|
| 901 | + return; /* busy */ |
---|
| 902 | + |
---|
| 903 | + ep = cons->console.data; |
---|
| 904 | + size = kfifo_out(&cons->buf, req->buf, ep->maxpacket); |
---|
| 905 | + if (!size) |
---|
| 906 | + return; |
---|
| 907 | + |
---|
| 908 | + if (cons->missed && ep->maxpacket >= 64) { |
---|
| 909 | + char buf[64]; |
---|
| 910 | + size_t len; |
---|
| 911 | + |
---|
| 912 | + len = sprintf(buf, "\n[missed %zu bytes]\n", cons->missed); |
---|
| 913 | + kfifo_in(&cons->buf, buf, len); |
---|
| 914 | + cons->missed = 0; |
---|
962 | 915 | } |
---|
963 | 916 | |
---|
964 | | - port = ports[port_num].port; |
---|
965 | | - ep = port->port_usb->in; |
---|
966 | | - if (!info->console_req) { |
---|
967 | | - info->console_req = gs_request_new(ep); |
---|
968 | | - if (!info->console_req) |
---|
969 | | - return -ENOMEM; |
---|
970 | | - info->console_req->complete = gs_complete_out; |
---|
971 | | - } |
---|
| 917 | + req->length = size; |
---|
972 | 918 | |
---|
973 | | - info->port = port; |
---|
974 | | - spin_lock(&info->con_lock); |
---|
975 | | - info->req_busy = 0; |
---|
976 | | - spin_unlock(&info->con_lock); |
---|
977 | | - pr_vdebug("port[%d] console connect!\n", port_num); |
---|
978 | | - return 0; |
---|
| 919 | + spin_unlock_irq(&cons->lock); |
---|
| 920 | + if (usb_ep_queue(ep, req, GFP_ATOMIC)) |
---|
| 921 | + req->length = 0; |
---|
| 922 | + spin_lock_irq(&cons->lock); |
---|
979 | 923 | } |
---|
980 | 924 | |
---|
981 | | -static void gs_console_disconnect(struct usb_ep *ep) |
---|
| 925 | +static void gs_console_work(struct work_struct *work) |
---|
982 | 926 | { |
---|
983 | | - struct gscons_info *info = &gscons_info; |
---|
984 | | - struct usb_request *req = info->console_req; |
---|
| 927 | + struct gs_console *cons = container_of(work, struct gs_console, work); |
---|
985 | 928 | |
---|
986 | | - gs_request_free(req, ep); |
---|
987 | | - info->console_req = NULL; |
---|
988 | | -} |
---|
| 929 | + spin_lock_irq(&cons->lock); |
---|
989 | 930 | |
---|
990 | | -static int gs_console_thread(void *data) |
---|
991 | | -{ |
---|
992 | | - struct gscons_info *info = &gscons_info; |
---|
993 | | - struct gs_port *port; |
---|
994 | | - struct usb_request *req; |
---|
995 | | - struct usb_ep *ep; |
---|
996 | | - int xfer, ret, count, size; |
---|
| 931 | + __gs_console_push(cons); |
---|
997 | 932 | |
---|
998 | | - do { |
---|
999 | | - port = info->port; |
---|
1000 | | - set_current_state(TASK_INTERRUPTIBLE); |
---|
1001 | | - if (!port || !port->port_usb |
---|
1002 | | - || !port->port_usb->in || !info->console_req) |
---|
1003 | | - goto sched; |
---|
1004 | | - |
---|
1005 | | - req = info->console_req; |
---|
1006 | | - ep = port->port_usb->in; |
---|
1007 | | - |
---|
1008 | | - spin_lock_irq(&info->con_lock); |
---|
1009 | | - count = kfifo_len(&info->con_buf); |
---|
1010 | | - size = ep->maxpacket; |
---|
1011 | | - |
---|
1012 | | - if (count > 0 && !info->req_busy) { |
---|
1013 | | - set_current_state(TASK_RUNNING); |
---|
1014 | | - if (count < size) |
---|
1015 | | - size = count; |
---|
1016 | | - |
---|
1017 | | - xfer = kfifo_out(&info->con_buf, req->buf, size); |
---|
1018 | | - req->length = xfer; |
---|
1019 | | - |
---|
1020 | | - spin_unlock(&info->con_lock); |
---|
1021 | | - ret = usb_ep_queue(ep, req, GFP_ATOMIC); |
---|
1022 | | - spin_lock(&info->con_lock); |
---|
1023 | | - if (ret < 0) |
---|
1024 | | - info->req_busy = 0; |
---|
1025 | | - else |
---|
1026 | | - info->req_busy = 1; |
---|
1027 | | - |
---|
1028 | | - spin_unlock_irq(&info->con_lock); |
---|
1029 | | - } else { |
---|
1030 | | - spin_unlock_irq(&info->con_lock); |
---|
1031 | | -sched: |
---|
1032 | | - if (kthread_should_stop()) { |
---|
1033 | | - set_current_state(TASK_RUNNING); |
---|
1034 | | - break; |
---|
1035 | | - } |
---|
1036 | | - schedule(); |
---|
1037 | | - } |
---|
1038 | | - } while (1); |
---|
1039 | | - |
---|
1040 | | - return 0; |
---|
1041 | | -} |
---|
1042 | | - |
---|
1043 | | -static int gs_console_setup(struct console *co, char *options) |
---|
1044 | | -{ |
---|
1045 | | - struct gscons_info *info = &gscons_info; |
---|
1046 | | - int status; |
---|
1047 | | - |
---|
1048 | | - info->port = NULL; |
---|
1049 | | - info->console_req = NULL; |
---|
1050 | | - info->req_busy = 0; |
---|
1051 | | - spin_lock_init(&info->con_lock); |
---|
1052 | | - |
---|
1053 | | - status = kfifo_alloc(&info->con_buf, GS_CONSOLE_BUF_SIZE, GFP_KERNEL); |
---|
1054 | | - if (status) { |
---|
1055 | | - pr_err("%s: allocate console buffer failed\n", __func__); |
---|
1056 | | - return status; |
---|
1057 | | - } |
---|
1058 | | - |
---|
1059 | | - info->console_thread = kthread_create(gs_console_thread, |
---|
1060 | | - co, "gs_console"); |
---|
1061 | | - if (IS_ERR(info->console_thread)) { |
---|
1062 | | - pr_err("%s: cannot create console thread\n", __func__); |
---|
1063 | | - kfifo_free(&info->con_buf); |
---|
1064 | | - return PTR_ERR(info->console_thread); |
---|
1065 | | - } |
---|
1066 | | - wake_up_process(info->console_thread); |
---|
1067 | | - |
---|
1068 | | - return 0; |
---|
| 933 | + spin_unlock_irq(&cons->lock); |
---|
1069 | 934 | } |
---|
1070 | 935 | |
---|
1071 | 936 | static void gs_console_write(struct console *co, |
---|
1072 | 937 | const char *buf, unsigned count) |
---|
1073 | 938 | { |
---|
1074 | | - struct gscons_info *info = &gscons_info; |
---|
| 939 | + struct gs_console *cons = container_of(co, struct gs_console, console); |
---|
1075 | 940 | unsigned long flags; |
---|
| 941 | + size_t n; |
---|
1076 | 942 | |
---|
1077 | | - spin_lock_irqsave(&info->con_lock, flags); |
---|
1078 | | - kfifo_in(&info->con_buf, buf, count); |
---|
1079 | | - spin_unlock_irqrestore(&info->con_lock, flags); |
---|
| 943 | + spin_lock_irqsave(&cons->lock, flags); |
---|
1080 | 944 | |
---|
1081 | | - wake_up_process(info->console_thread); |
---|
| 945 | + n = kfifo_in(&cons->buf, buf, count); |
---|
| 946 | + if (n < count) |
---|
| 947 | + cons->missed += count - n; |
---|
| 948 | + |
---|
| 949 | + if (cons->req && !cons->req->length) |
---|
| 950 | + schedule_work(&cons->work); |
---|
| 951 | + |
---|
| 952 | + spin_unlock_irqrestore(&cons->lock, flags); |
---|
1082 | 953 | } |
---|
1083 | 954 | |
---|
1084 | 955 | static struct tty_driver *gs_console_device(struct console *co, int *index) |
---|
1085 | 956 | { |
---|
1086 | | - struct tty_driver **p = (struct tty_driver **)co->data; |
---|
1087 | | - |
---|
1088 | | - if (!*p) |
---|
1089 | | - return NULL; |
---|
1090 | | - |
---|
1091 | 957 | *index = co->index; |
---|
1092 | | - return *p; |
---|
| 958 | + return gs_tty_driver; |
---|
1093 | 959 | } |
---|
1094 | 960 | |
---|
1095 | | -static struct console gserial_cons = { |
---|
1096 | | - .name = "ttyGS", |
---|
1097 | | - .write = gs_console_write, |
---|
1098 | | - .device = gs_console_device, |
---|
1099 | | - .setup = gs_console_setup, |
---|
1100 | | - .flags = CON_PRINTBUFFER, |
---|
1101 | | - .index = -1, |
---|
1102 | | - .data = &gs_tty_driver, |
---|
1103 | | -}; |
---|
1104 | | - |
---|
1105 | | -static void gserial_console_init(void) |
---|
| 961 | +static int gs_console_connect(struct gs_port *port) |
---|
1106 | 962 | { |
---|
1107 | | - register_console(&gserial_cons); |
---|
| 963 | + struct gs_console *cons = port->console; |
---|
| 964 | + struct usb_request *req; |
---|
| 965 | + struct usb_ep *ep; |
---|
| 966 | + |
---|
| 967 | + if (!cons) |
---|
| 968 | + return 0; |
---|
| 969 | + |
---|
| 970 | + ep = port->port_usb->in; |
---|
| 971 | + req = gs_alloc_req(ep, ep->maxpacket, GFP_ATOMIC); |
---|
| 972 | + if (!req) |
---|
| 973 | + return -ENOMEM; |
---|
| 974 | + req->complete = gs_console_complete_out; |
---|
| 975 | + req->context = cons; |
---|
| 976 | + req->length = 0; |
---|
| 977 | + |
---|
| 978 | + spin_lock(&cons->lock); |
---|
| 979 | + cons->req = req; |
---|
| 980 | + cons->console.data = ep; |
---|
| 981 | + spin_unlock(&cons->lock); |
---|
| 982 | + |
---|
| 983 | + pr_debug("ttyGS%d: console connected!\n", port->port_num); |
---|
| 984 | + |
---|
| 985 | + schedule_work(&cons->work); |
---|
| 986 | + |
---|
| 987 | + return 0; |
---|
1108 | 988 | } |
---|
1109 | 989 | |
---|
1110 | | -static void gserial_console_exit(void) |
---|
| 990 | +static void gs_console_disconnect(struct gs_port *port) |
---|
1111 | 991 | { |
---|
1112 | | - struct gscons_info *info = &gscons_info; |
---|
| 992 | + struct gs_console *cons = port->console; |
---|
| 993 | + struct usb_request *req; |
---|
| 994 | + struct usb_ep *ep; |
---|
1113 | 995 | |
---|
1114 | | - unregister_console(&gserial_cons); |
---|
1115 | | - if (!IS_ERR_OR_NULL(info->console_thread)) |
---|
1116 | | - kthread_stop(info->console_thread); |
---|
1117 | | - kfifo_free(&info->con_buf); |
---|
| 996 | + if (!cons) |
---|
| 997 | + return; |
---|
| 998 | + |
---|
| 999 | + spin_lock(&cons->lock); |
---|
| 1000 | + |
---|
| 1001 | + req = cons->req; |
---|
| 1002 | + ep = cons->console.data; |
---|
| 1003 | + cons->req = NULL; |
---|
| 1004 | + |
---|
| 1005 | + spin_unlock(&cons->lock); |
---|
| 1006 | + |
---|
| 1007 | + if (!req) |
---|
| 1008 | + return; |
---|
| 1009 | + |
---|
| 1010 | + usb_ep_dequeue(ep, req); |
---|
| 1011 | + gs_free_req(ep, req); |
---|
1118 | 1012 | } |
---|
| 1013 | + |
---|
| 1014 | +static int gs_console_init(struct gs_port *port) |
---|
| 1015 | +{ |
---|
| 1016 | + struct gs_console *cons; |
---|
| 1017 | + int err; |
---|
| 1018 | + |
---|
| 1019 | + if (port->console) |
---|
| 1020 | + return 0; |
---|
| 1021 | + |
---|
| 1022 | + cons = kzalloc(sizeof(*port->console), GFP_KERNEL); |
---|
| 1023 | + if (!cons) |
---|
| 1024 | + return -ENOMEM; |
---|
| 1025 | + |
---|
| 1026 | + strcpy(cons->console.name, "ttyGS"); |
---|
| 1027 | + cons->console.write = gs_console_write; |
---|
| 1028 | + cons->console.device = gs_console_device; |
---|
| 1029 | + cons->console.flags = CON_PRINTBUFFER; |
---|
| 1030 | + cons->console.index = port->port_num; |
---|
| 1031 | + |
---|
| 1032 | + INIT_WORK(&cons->work, gs_console_work); |
---|
| 1033 | + spin_lock_init(&cons->lock); |
---|
| 1034 | + |
---|
| 1035 | + err = kfifo_alloc(&cons->buf, GS_CONSOLE_BUF_SIZE, GFP_KERNEL); |
---|
| 1036 | + if (err) { |
---|
| 1037 | + pr_err("ttyGS%d: allocate console buffer failed\n", port->port_num); |
---|
| 1038 | + kfree(cons); |
---|
| 1039 | + return err; |
---|
| 1040 | + } |
---|
| 1041 | + |
---|
| 1042 | + port->console = cons; |
---|
| 1043 | + register_console(&cons->console); |
---|
| 1044 | + |
---|
| 1045 | + spin_lock_irq(&port->port_lock); |
---|
| 1046 | + if (port->port_usb) |
---|
| 1047 | + gs_console_connect(port); |
---|
| 1048 | + spin_unlock_irq(&port->port_lock); |
---|
| 1049 | + |
---|
| 1050 | + return 0; |
---|
| 1051 | +} |
---|
| 1052 | + |
---|
| 1053 | +static void gs_console_exit(struct gs_port *port) |
---|
| 1054 | +{ |
---|
| 1055 | + struct gs_console *cons = port->console; |
---|
| 1056 | + |
---|
| 1057 | + if (!cons) |
---|
| 1058 | + return; |
---|
| 1059 | + |
---|
| 1060 | + unregister_console(&cons->console); |
---|
| 1061 | + |
---|
| 1062 | + spin_lock_irq(&port->port_lock); |
---|
| 1063 | + if (cons->req) |
---|
| 1064 | + gs_console_disconnect(port); |
---|
| 1065 | + spin_unlock_irq(&port->port_lock); |
---|
| 1066 | + |
---|
| 1067 | + cancel_work_sync(&cons->work); |
---|
| 1068 | + kfifo_free(&cons->buf); |
---|
| 1069 | + kfree(cons); |
---|
| 1070 | + port->console = NULL; |
---|
| 1071 | +} |
---|
| 1072 | + |
---|
| 1073 | +ssize_t gserial_set_console(unsigned char port_num, const char *page, size_t count) |
---|
| 1074 | +{ |
---|
| 1075 | + struct gs_port *port; |
---|
| 1076 | + bool enable; |
---|
| 1077 | + int ret; |
---|
| 1078 | + |
---|
| 1079 | + ret = strtobool(page, &enable); |
---|
| 1080 | + if (ret) |
---|
| 1081 | + return ret; |
---|
| 1082 | + |
---|
| 1083 | + mutex_lock(&ports[port_num].lock); |
---|
| 1084 | + port = ports[port_num].port; |
---|
| 1085 | + |
---|
| 1086 | + if (WARN_ON(port == NULL)) { |
---|
| 1087 | + ret = -ENXIO; |
---|
| 1088 | + goto out; |
---|
| 1089 | + } |
---|
| 1090 | + |
---|
| 1091 | + if (enable) |
---|
| 1092 | + ret = gs_console_init(port); |
---|
| 1093 | + else |
---|
| 1094 | + gs_console_exit(port); |
---|
| 1095 | +out: |
---|
| 1096 | + mutex_unlock(&ports[port_num].lock); |
---|
| 1097 | + |
---|
| 1098 | + return ret < 0 ? ret : count; |
---|
| 1099 | +} |
---|
| 1100 | +EXPORT_SYMBOL_GPL(gserial_set_console); |
---|
| 1101 | + |
---|
| 1102 | +ssize_t gserial_get_console(unsigned char port_num, char *page) |
---|
| 1103 | +{ |
---|
| 1104 | + struct gs_port *port; |
---|
| 1105 | + ssize_t ret; |
---|
| 1106 | + |
---|
| 1107 | + mutex_lock(&ports[port_num].lock); |
---|
| 1108 | + port = ports[port_num].port; |
---|
| 1109 | + |
---|
| 1110 | + if (WARN_ON(port == NULL)) |
---|
| 1111 | + ret = -ENXIO; |
---|
| 1112 | + else |
---|
| 1113 | + ret = sprintf(page, "%u\n", !!port->console); |
---|
| 1114 | + |
---|
| 1115 | + mutex_unlock(&ports[port_num].lock); |
---|
| 1116 | + |
---|
| 1117 | + return ret; |
---|
| 1118 | +} |
---|
| 1119 | +EXPORT_SYMBOL_GPL(gserial_get_console); |
---|
1119 | 1120 | |
---|
1120 | 1121 | #else |
---|
1121 | 1122 | |
---|
1122 | | -static int gs_console_connect(int port_num) |
---|
| 1123 | +static int gs_console_connect(struct gs_port *port) |
---|
1123 | 1124 | { |
---|
1124 | 1125 | return 0; |
---|
1125 | 1126 | } |
---|
1126 | 1127 | |
---|
1127 | | -static void gs_console_disconnect(struct usb_ep *ep) |
---|
| 1128 | +static void gs_console_disconnect(struct gs_port *port) |
---|
1128 | 1129 | { |
---|
1129 | 1130 | } |
---|
1130 | 1131 | |
---|
1131 | | -static void gserial_console_init(void) |
---|
| 1132 | +static int gs_console_init(struct gs_port *port) |
---|
1132 | 1133 | { |
---|
| 1134 | + return -ENOSYS; |
---|
1133 | 1135 | } |
---|
1134 | 1136 | |
---|
1135 | | -static void gserial_console_exit(void) |
---|
| 1137 | +static void gs_console_exit(struct gs_port *port) |
---|
1136 | 1138 | { |
---|
1137 | 1139 | } |
---|
1138 | 1140 | |
---|
.. | .. |
---|
1161 | 1163 | init_waitqueue_head(&port->drain_wait); |
---|
1162 | 1164 | init_waitqueue_head(&port->close_wait); |
---|
1163 | 1165 | |
---|
1164 | | - tasklet_init(&port->push, gs_rx_push, (unsigned long) port); |
---|
| 1166 | + INIT_DELAYED_WORK(&port->push, gs_rx_push); |
---|
1165 | 1167 | |
---|
1166 | 1168 | INIT_LIST_HEAD(&port->read_pool); |
---|
1167 | 1169 | INIT_LIST_HEAD(&port->read_queue); |
---|
.. | .. |
---|
1181 | 1183 | int cond; |
---|
1182 | 1184 | |
---|
1183 | 1185 | spin_lock_irq(&port->port_lock); |
---|
1184 | | - cond = (port->port.count == 0) && !port->openclose; |
---|
| 1186 | + cond = port->port.count == 0; |
---|
1185 | 1187 | spin_unlock_irq(&port->port_lock); |
---|
| 1188 | + |
---|
1186 | 1189 | return cond; |
---|
1187 | 1190 | } |
---|
1188 | 1191 | |
---|
1189 | 1192 | static void gserial_free_port(struct gs_port *port) |
---|
1190 | 1193 | { |
---|
1191 | | - tasklet_kill(&port->push); |
---|
| 1194 | + cancel_delayed_work_sync(&port->push); |
---|
1192 | 1195 | /* wait for old opens to finish */ |
---|
1193 | 1196 | wait_event(port->close_wait, gs_closed(port)); |
---|
1194 | 1197 | WARN_ON(port->port_usb != NULL); |
---|
.. | .. |
---|
1206 | 1209 | return; |
---|
1207 | 1210 | } |
---|
1208 | 1211 | port = ports[port_num].port; |
---|
| 1212 | + gs_console_exit(port); |
---|
1209 | 1213 | ports[port_num].port = NULL; |
---|
1210 | 1214 | mutex_unlock(&ports[port_num].lock); |
---|
1211 | 1215 | |
---|
1212 | 1216 | gserial_free_port(port); |
---|
1213 | 1217 | tty_unregister_device(gs_tty_driver, port_num); |
---|
1214 | | - gserial_console_exit(); |
---|
1215 | 1218 | } |
---|
1216 | 1219 | EXPORT_SYMBOL_GPL(gserial_free_line); |
---|
1217 | 1220 | |
---|
1218 | | -int gserial_alloc_line(unsigned char *line_num) |
---|
| 1221 | +int gserial_alloc_line_no_console(unsigned char *line_num) |
---|
1219 | 1222 | { |
---|
1220 | 1223 | struct usb_cdc_line_coding coding; |
---|
| 1224 | + struct gs_port *port; |
---|
1221 | 1225 | struct device *tty_dev; |
---|
1222 | 1226 | int ret; |
---|
1223 | 1227 | int port_num; |
---|
.. | .. |
---|
1240 | 1244 | |
---|
1241 | 1245 | /* ... and sysfs class devices, so mdev/udev make /dev/ttyGS* */ |
---|
1242 | 1246 | |
---|
1243 | | - tty_dev = tty_port_register_device(&ports[port_num].port->port, |
---|
| 1247 | + port = ports[port_num].port; |
---|
| 1248 | + tty_dev = tty_port_register_device(&port->port, |
---|
1244 | 1249 | gs_tty_driver, port_num, NULL); |
---|
1245 | 1250 | if (IS_ERR(tty_dev)) { |
---|
1246 | | - struct gs_port *port; |
---|
1247 | 1251 | pr_err("%s: failed to register tty for port %d, err %ld\n", |
---|
1248 | 1252 | __func__, port_num, PTR_ERR(tty_dev)); |
---|
1249 | 1253 | |
---|
1250 | 1254 | ret = PTR_ERR(tty_dev); |
---|
1251 | 1255 | mutex_lock(&ports[port_num].lock); |
---|
1252 | | - port = ports[port_num].port; |
---|
1253 | 1256 | ports[port_num].port = NULL; |
---|
1254 | 1257 | mutex_unlock(&ports[port_num].lock); |
---|
1255 | 1258 | gserial_free_port(port); |
---|
1256 | 1259 | goto err; |
---|
1257 | 1260 | } |
---|
1258 | 1261 | *line_num = port_num; |
---|
1259 | | - gserial_console_init(); |
---|
1260 | 1262 | err: |
---|
| 1263 | + return ret; |
---|
| 1264 | +} |
---|
| 1265 | +EXPORT_SYMBOL_GPL(gserial_alloc_line_no_console); |
---|
| 1266 | + |
---|
| 1267 | +int gserial_alloc_line(unsigned char *line_num) |
---|
| 1268 | +{ |
---|
| 1269 | + int ret = gserial_alloc_line_no_console(line_num); |
---|
| 1270 | + |
---|
| 1271 | + if (!ret && !*line_num) |
---|
| 1272 | + gs_console_init(ports[*line_num].port); |
---|
| 1273 | + |
---|
1261 | 1274 | return ret; |
---|
1262 | 1275 | } |
---|
1263 | 1276 | EXPORT_SYMBOL_GPL(gserial_alloc_line); |
---|
.. | .. |
---|
1338 | 1351 | gser->disconnect(gser); |
---|
1339 | 1352 | } |
---|
1340 | 1353 | |
---|
1341 | | - status = gs_console_connect(port_num); |
---|
| 1354 | + status = gs_console_connect(port); |
---|
1342 | 1355 | spin_unlock_irqrestore(&port->port_lock, flags); |
---|
1343 | 1356 | |
---|
1344 | 1357 | return status; |
---|
.. | .. |
---|
1367 | 1380 | if (!port) |
---|
1368 | 1381 | return; |
---|
1369 | 1382 | |
---|
| 1383 | + spin_lock_irqsave(&serial_port_lock, flags); |
---|
| 1384 | + |
---|
1370 | 1385 | /* tell the TTY glue not to do I/O here any more */ |
---|
1371 | | - spin_lock_irqsave(&port->port_lock, flags); |
---|
| 1386 | + spin_lock(&port->port_lock); |
---|
| 1387 | + |
---|
| 1388 | + gs_console_disconnect(port); |
---|
1372 | 1389 | |
---|
1373 | 1390 | /* REVISIT as above: how best to track this? */ |
---|
1374 | 1391 | port->port_line_coding = gser->port_line_coding; |
---|
1375 | 1392 | |
---|
1376 | 1393 | port->port_usb = NULL; |
---|
1377 | 1394 | gser->ioport = NULL; |
---|
1378 | | - if (port->port.count > 0 || port->openclose) { |
---|
| 1395 | + if (port->port.count > 0) { |
---|
1379 | 1396 | wake_up_interruptible(&port->drain_wait); |
---|
1380 | 1397 | if (port->port.tty) |
---|
1381 | 1398 | tty_hangup(port->port.tty); |
---|
1382 | 1399 | } |
---|
1383 | | - spin_unlock_irqrestore(&port->port_lock, flags); |
---|
| 1400 | + port->suspended = false; |
---|
| 1401 | + spin_unlock(&port->port_lock); |
---|
| 1402 | + spin_unlock_irqrestore(&serial_port_lock, flags); |
---|
1384 | 1403 | |
---|
1385 | 1404 | /* disable endpoints, aborting down any active I/O */ |
---|
1386 | 1405 | usb_ep_disable(gser->out); |
---|
.. | .. |
---|
1388 | 1407 | |
---|
1389 | 1408 | /* finally, free any unused/unusable I/O buffers */ |
---|
1390 | 1409 | spin_lock_irqsave(&port->port_lock, flags); |
---|
1391 | | - if (port->port.count == 0 && !port->openclose) |
---|
| 1410 | + if (port->port.count == 0) |
---|
1392 | 1411 | kfifo_free(&port->port_write_buf); |
---|
1393 | 1412 | gs_free_requests(gser->out, &port->read_pool, NULL); |
---|
1394 | 1413 | gs_free_requests(gser->out, &port->read_queue, NULL); |
---|
.. | .. |
---|
1397 | 1416 | port->read_allocated = port->read_started = |
---|
1398 | 1417 | port->write_allocated = port->write_started = 0; |
---|
1399 | 1418 | |
---|
1400 | | - gs_console_disconnect(gser->in); |
---|
1401 | 1419 | spin_unlock_irqrestore(&port->port_lock, flags); |
---|
1402 | 1420 | } |
---|
1403 | 1421 | EXPORT_SYMBOL_GPL(gserial_disconnect); |
---|
1404 | 1422 | |
---|
| 1423 | +void gserial_suspend(struct gserial *gser) |
---|
| 1424 | +{ |
---|
| 1425 | + struct gs_port *port; |
---|
| 1426 | + unsigned long flags; |
---|
| 1427 | + |
---|
| 1428 | + spin_lock_irqsave(&serial_port_lock, flags); |
---|
| 1429 | + port = gser->ioport; |
---|
| 1430 | + |
---|
| 1431 | + if (!port) { |
---|
| 1432 | + spin_unlock_irqrestore(&serial_port_lock, flags); |
---|
| 1433 | + return; |
---|
| 1434 | + } |
---|
| 1435 | + |
---|
| 1436 | + spin_lock(&port->port_lock); |
---|
| 1437 | + spin_unlock(&serial_port_lock); |
---|
| 1438 | + port->suspended = true; |
---|
| 1439 | + spin_unlock_irqrestore(&port->port_lock, flags); |
---|
| 1440 | +} |
---|
| 1441 | +EXPORT_SYMBOL_GPL(gserial_suspend); |
---|
| 1442 | + |
---|
| 1443 | +void gserial_resume(struct gserial *gser) |
---|
| 1444 | +{ |
---|
| 1445 | + struct gs_port *port; |
---|
| 1446 | + unsigned long flags; |
---|
| 1447 | + |
---|
| 1448 | + spin_lock_irqsave(&serial_port_lock, flags); |
---|
| 1449 | + port = gser->ioport; |
---|
| 1450 | + |
---|
| 1451 | + if (!port) { |
---|
| 1452 | + spin_unlock_irqrestore(&serial_port_lock, flags); |
---|
| 1453 | + return; |
---|
| 1454 | + } |
---|
| 1455 | + |
---|
| 1456 | + spin_lock(&port->port_lock); |
---|
| 1457 | + spin_unlock(&serial_port_lock); |
---|
| 1458 | + port->suspended = false; |
---|
| 1459 | + if (!port->start_delayed) { |
---|
| 1460 | + spin_unlock_irqrestore(&port->port_lock, flags); |
---|
| 1461 | + return; |
---|
| 1462 | + } |
---|
| 1463 | + |
---|
| 1464 | + pr_debug("delayed start ttyGS%d\n", port->port_num); |
---|
| 1465 | + gs_start_io(port); |
---|
| 1466 | + if (gser->connect) |
---|
| 1467 | + gser->connect(gser); |
---|
| 1468 | + port->start_delayed = false; |
---|
| 1469 | + spin_unlock_irqrestore(&port->port_lock, flags); |
---|
| 1470 | +} |
---|
| 1471 | +EXPORT_SYMBOL_GPL(gserial_resume); |
---|
| 1472 | + |
---|
1405 | 1473 | static int userial_init(void) |
---|
1406 | 1474 | { |
---|
1407 | 1475 | unsigned i; |
---|