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