Lines Matching +full:port +full:-

1 // SPDX-License-Identifier: GPL-2.0+
3 * u_serial.c - utilities for USB gadget "serial port"/TTY support
10 * Copyright (C) 1999 - 2002 Greg Kroah-Hartman (greg@kroah.com)
37 * "serial port" functionality through the USB gadget stack. Each such
38 * port is exposed through a /dev/ttyGS* node.
40 * After this module has been loaded, the individual TTY port can be requested
44 * host issues a config change event. Data can only flow when the port is
47 * A given TTY port can be made available in multiple configurations.
54 * Configurations may expose more than one TTY port. For example, if
65 * gserial <---> gs_port ... links will be null when the USB link is
68 * gserial->ioport == usb_ep->driver_data ... gs_port
69 * gs_port->port_usb ... gserial
71 * gs_port <---> tty_struct ... links will be null when the TTY file
73 * gserial->port_tty ... tty_struct
74 * tty_struct->driver_data ... gserial
85 /* Prevents race conditions while accessing gser->ioport */
99 * The port structure holds info for each port, one for each minor number
103 struct tty_port port; member
127 bool suspended; /* port suspended */
131 struct usb_cdc_line_coding port_line_coding; /* 8-N-1 etc */
136 struct gs_port *port; member
155 /*-------------------------------------------------------------------------*/
173 req->length = len; in gs_alloc_req()
174 req->buf = kmalloc(len, kmalloc_flags); in gs_alloc_req()
175 if (req->buf == NULL) { in gs_alloc_req()
192 kfree(req->buf); in gs_free_req()
207 gs_send_packet(struct gs_port *port, char *packet, unsigned size) in gs_send_packet() argument
211 len = kfifo_len(&port->port_write_buf); in gs_send_packet()
215 size = kfifo_out(&port->port_write_buf, packet, size); in gs_send_packet()
228 * Context: caller owns port_lock; port_usb is non-null.
230 static int gs_start_tx(struct gs_port *port) in gs_start_tx() argument
232 __releases(&port->port_lock) in gs_start_tx()
233 __acquires(&port->port_lock) in gs_start_tx()
236 struct list_head *pool = &port->write_pool; in gs_start_tx()
241 if (!port->port_usb) in gs_start_tx()
244 in = port->port_usb->in; in gs_start_tx()
246 while (!port->write_busy && !list_empty(pool)) { in gs_start_tx()
250 if (port->write_started >= QUEUE_SIZE) in gs_start_tx()
253 req = list_entry(pool->next, struct usb_request, list); in gs_start_tx()
254 len = gs_send_packet(port, req->buf, in->maxpacket); in gs_start_tx()
256 wake_up_interruptible(&port->drain_wait); in gs_start_tx()
261 req->length = len; in gs_start_tx()
262 list_del(&req->list); in gs_start_tx()
263 req->zero = kfifo_is_empty(&port->port_write_buf); in gs_start_tx()
265 pr_vdebug("ttyGS%d: tx len=%d, %3ph ...\n", port->port_num, len, req->buf); in gs_start_tx()
272 * the TTY closed (dev->ioport->port_tty is NULL). in gs_start_tx()
274 port->write_busy = true; in gs_start_tx()
275 spin_unlock(&port->port_lock); in gs_start_tx()
277 spin_lock(&port->port_lock); in gs_start_tx()
278 port->write_busy = false; in gs_start_tx()
282 __func__, "queue", in->name, status); in gs_start_tx()
283 list_add(&req->list, pool); in gs_start_tx()
287 port->write_started++; in gs_start_tx()
290 if (!port->port_usb) in gs_start_tx()
294 if (do_tty_wake && port->port.tty) in gs_start_tx()
295 tty_wakeup(port->port.tty); in gs_start_tx()
302 static unsigned gs_start_rx(struct gs_port *port) in gs_start_rx() argument
304 __releases(&port->port_lock) in gs_start_rx()
305 __acquires(&port->port_lock) in gs_start_rx()
308 struct list_head *pool = &port->read_pool; in gs_start_rx()
309 struct usb_ep *out = port->port_usb->out; in gs_start_rx()
317 tty = port->port.tty; in gs_start_rx()
321 if (port->read_started >= QUEUE_SIZE) in gs_start_rx()
324 req = list_entry(pool->next, struct usb_request, list); in gs_start_rx()
325 list_del(&req->list); in gs_start_rx()
326 req->length = out->maxpacket; in gs_start_rx()
331 spin_unlock(&port->port_lock); in gs_start_rx()
333 spin_lock(&port->port_lock); in gs_start_rx()
337 __func__, "queue", out->name, status); in gs_start_rx()
338 list_add(&req->list, pool); in gs_start_rx()
341 port->read_started++; in gs_start_rx()
344 if (!port->port_usb) in gs_start_rx()
347 return port->read_started; in gs_start_rx()
363 struct gs_port *port = container_of(w, struct gs_port, push); in gs_rx_push() local
365 struct list_head *queue = &port->read_queue; in gs_rx_push()
370 spin_lock_irq(&port->port_lock); in gs_rx_push()
371 tty = port->port.tty; in gs_rx_push()
381 switch (req->status) { in gs_rx_push()
382 case -ESHUTDOWN: in gs_rx_push()
384 pr_vdebug("ttyGS%d: shutdown\n", port->port_num); in gs_rx_push()
390 port->port_num, req->status); in gs_rx_push()
398 if (req->actual && tty) { in gs_rx_push()
399 char *packet = req->buf; in gs_rx_push()
400 unsigned size = req->actual; in gs_rx_push()
405 n = port->n_read; in gs_rx_push()
408 size -= n; in gs_rx_push()
411 count = tty_insert_flip_string(&port->port, packet, in gs_rx_push()
417 port->n_read += count; in gs_rx_push()
419 port->port_num, count, req->actual); in gs_rx_push()
422 port->n_read = 0; in gs_rx_push()
425 list_move(&req->list, &port->read_pool); in gs_rx_push()
426 port->read_started--; in gs_rx_push()
433 tty_flip_buffer_push(&port->port); in gs_rx_push()
440 * We may leave non-empty queue only when there is a tty, and in gs_rx_push()
444 schedule_delayed_work(&port->push, 1); in gs_rx_push()
447 if (!disconnect && port->port_usb) in gs_rx_push()
448 gs_start_rx(port); in gs_rx_push()
450 spin_unlock_irq(&port->port_lock); in gs_rx_push()
455 struct gs_port *port = ep->driver_data; in gs_read_complete() local
458 spin_lock(&port->port_lock); in gs_read_complete()
459 list_add_tail(&req->list, &port->read_queue); in gs_read_complete()
460 schedule_delayed_work(&port->push, 0); in gs_read_complete()
461 spin_unlock(&port->port_lock); in gs_read_complete()
466 struct gs_port *port = ep->driver_data; in gs_write_complete() local
468 spin_lock(&port->port_lock); in gs_write_complete()
469 list_add(&req->list, &port->write_pool); in gs_write_complete()
470 port->write_started--; in gs_write_complete()
472 switch (req->status) { in gs_write_complete()
476 __func__, ep->name, req->status); in gs_write_complete()
480 gs_start_tx(port); in gs_write_complete()
483 case -ESHUTDOWN: in gs_write_complete()
485 pr_vdebug("%s: %s shutdown\n", __func__, ep->name); in gs_write_complete()
489 spin_unlock(&port->port_lock); in gs_write_complete()
498 req = list_entry(head->next, struct usb_request, list); in gs_free_requests()
499 list_del(&req->list); in gs_free_requests()
502 (*allocated)--; in gs_free_requests()
512 int n = allocated ? QUEUE_SIZE - *allocated : QUEUE_SIZE; in gs_alloc_requests()
514 /* Pre-allocate up to QUEUE_SIZE transfers, but if we can't in gs_alloc_requests()
519 req = gs_alloc_req(ep, ep->maxpacket, GFP_ATOMIC); in gs_alloc_requests()
521 return list_empty(head) ? -ENOMEM : 0; in gs_alloc_requests()
522 req->complete = fn; in gs_alloc_requests()
523 list_add_tail(&req->list, head); in gs_alloc_requests()
531 * gs_start_io - start USB I/O streams
532 * @port: port to use
533 * Context: holding port_lock; port_tty and port_usb are non-null
536 * this port. If nothing is listening on the host side, we may
539 static int gs_start_io(struct gs_port *port) in gs_start_io() argument
541 struct list_head *head = &port->read_pool; in gs_start_io()
546 if (!port->port_usb || !port->port.tty) in gs_start_io()
547 return -EIO; in gs_start_io()
552 * configurations may use different endpoints with a given port; in gs_start_io()
555 ep = port->port_usb->out; in gs_start_io()
557 &port->read_allocated); in gs_start_io()
561 status = gs_alloc_requests(port->port_usb->in, &port->write_pool, in gs_start_io()
562 gs_write_complete, &port->write_allocated); in gs_start_io()
564 gs_free_requests(ep, head, &port->read_allocated); in gs_start_io()
569 port->n_read = 0; in gs_start_io()
570 started = gs_start_rx(port); in gs_start_io()
573 gs_start_tx(port); in gs_start_io()
576 tty_wakeup(port->port.tty); in gs_start_io()
579 if (port->port_usb) { in gs_start_io()
580 gs_free_requests(ep, head, &port->read_allocated); in gs_start_io()
581 gs_free_requests(port->port_usb->in, &port->write_pool, in gs_start_io()
582 &port->write_allocated); in gs_start_io()
584 status = -EIO; in gs_start_io()
590 /*-------------------------------------------------------------------------*/
601 int port_num = tty->index; in gs_open()
602 struct gs_port *port; in gs_open() local
606 port = ports[port_num].port; in gs_open()
607 if (!port) { in gs_open()
608 status = -ENODEV; in gs_open()
612 spin_lock_irq(&port->port_lock); in gs_open()
615 if (!kfifo_initialized(&port->port_write_buf)) { in gs_open()
617 spin_unlock_irq(&port->port_lock); in gs_open()
624 status = kfifo_alloc(&port->port_write_buf, in gs_open()
632 spin_lock_irq(&port->port_lock); in gs_open()
636 if (port->port.count++) in gs_open()
639 tty->driver_data = port; in gs_open()
640 port->port.tty = tty; in gs_open()
643 if (port->port_usb) { in gs_open()
644 /* if port is suspended, wait resume to start I/0 stream */ in gs_open()
645 if (!port->suspended) { in gs_open()
646 struct gserial *gser = port->port_usb; in gs_open()
648 pr_debug("gs_open: start ttyGS%d\n", port->port_num); in gs_open()
649 gs_start_io(port); in gs_open()
651 if (gser->connect) in gs_open()
652 gser->connect(gser); in gs_open()
654 pr_debug("delay start of ttyGS%d\n", port->port_num); in gs_open()
655 port->start_delayed = true; in gs_open()
659 pr_debug("gs_open: ttyGS%d (%p,%p)\n", port->port_num, tty, file); in gs_open()
662 spin_unlock_irq(&port->port_lock); in gs_open()
673 spin_lock_irq(&p->port_lock); in gs_close_flush_done()
674 cond = p->port_usb == NULL || !kfifo_len(&p->port_write_buf) || in gs_close_flush_done()
675 p->port.count > 1; in gs_close_flush_done()
676 spin_unlock_irq(&p->port_lock); in gs_close_flush_done()
683 struct gs_port *port = tty->driver_data; in gs_close() local
686 spin_lock_irq(&port->port_lock); in gs_close()
688 if (port->port.count != 1) { in gs_close()
690 if (port->port.count == 0) in gs_close()
693 --port->port.count; in gs_close()
697 pr_debug("gs_close: ttyGS%d (%p,%p) ...\n", port->port_num, tty, file); in gs_close()
699 gser = port->port_usb; in gs_close()
700 if (gser && !port->suspended && gser->disconnect) in gs_close()
701 gser->disconnect(gser); in gs_close()
706 if (kfifo_len(&port->port_write_buf) > 0 && gser) { in gs_close()
707 spin_unlock_irq(&port->port_lock); in gs_close()
708 wait_event_interruptible_timeout(port->drain_wait, in gs_close()
709 gs_close_flush_done(port), in gs_close()
711 spin_lock_irq(&port->port_lock); in gs_close()
713 if (port->port.count != 1) in gs_close()
716 gser = port->port_usb; in gs_close()
721 * let the push async work fire again until we're re-opened. in gs_close()
724 kfifo_free(&port->port_write_buf); in gs_close()
726 kfifo_reset(&port->port_write_buf); in gs_close()
728 port->start_delayed = false; in gs_close()
729 port->port.count = 0; in gs_close()
730 port->port.tty = NULL; in gs_close()
733 port->port_num, tty, file); in gs_close()
735 wake_up(&port->close_wait); in gs_close()
737 spin_unlock_irq(&port->port_lock); in gs_close()
742 struct gs_port *port = tty->driver_data; in gs_write() local
746 port->port_num, tty, count); in gs_write()
748 spin_lock_irqsave(&port->port_lock, flags); in gs_write()
750 count = kfifo_in(&port->port_write_buf, buf, count); in gs_write()
752 if (port->port_usb) in gs_write()
753 gs_start_tx(port); in gs_write()
754 spin_unlock_irqrestore(&port->port_lock, flags); in gs_write()
761 struct gs_port *port = tty->driver_data; in gs_put_char() local
766 port->port_num, tty, ch, __builtin_return_address(0)); in gs_put_char()
768 spin_lock_irqsave(&port->port_lock, flags); in gs_put_char()
769 status = kfifo_put(&port->port_write_buf, ch); in gs_put_char()
770 spin_unlock_irqrestore(&port->port_lock, flags); in gs_put_char()
777 struct gs_port *port = tty->driver_data; in gs_flush_chars() local
780 pr_vdebug("gs_flush_chars: (%d,%p)\n", port->port_num, tty); in gs_flush_chars()
782 spin_lock_irqsave(&port->port_lock, flags); in gs_flush_chars()
783 if (port->port_usb) in gs_flush_chars()
784 gs_start_tx(port); in gs_flush_chars()
785 spin_unlock_irqrestore(&port->port_lock, flags); in gs_flush_chars()
790 struct gs_port *port = tty->driver_data; in gs_write_room() local
794 spin_lock_irqsave(&port->port_lock, flags); in gs_write_room()
795 if (port->port_usb) in gs_write_room()
796 room = kfifo_avail(&port->port_write_buf); in gs_write_room()
797 spin_unlock_irqrestore(&port->port_lock, flags); in gs_write_room()
800 port->port_num, tty, room); in gs_write_room()
807 struct gs_port *port = tty->driver_data; in gs_chars_in_buffer() local
811 spin_lock_irqsave(&port->port_lock, flags); in gs_chars_in_buffer()
812 chars = kfifo_len(&port->port_write_buf); in gs_chars_in_buffer()
813 spin_unlock_irqrestore(&port->port_lock, flags); in gs_chars_in_buffer()
816 port->port_num, tty, chars); in gs_chars_in_buffer()
824 struct gs_port *port = tty->driver_data; in gs_unthrottle() local
827 spin_lock_irqsave(&port->port_lock, flags); in gs_unthrottle()
828 if (port->port_usb) { in gs_unthrottle()
833 pr_vdebug("ttyGS%d: unthrottle\n", port->port_num); in gs_unthrottle()
834 schedule_delayed_work(&port->push, 0); in gs_unthrottle()
836 spin_unlock_irqrestore(&port->port_lock, flags); in gs_unthrottle()
841 struct gs_port *port = tty->driver_data; in gs_break_ctl() local
846 port->port_num, duration); in gs_break_ctl()
848 spin_lock_irq(&port->port_lock); in gs_break_ctl()
849 gser = port->port_usb; in gs_break_ctl()
850 if (gser && gser->send_break) in gs_break_ctl()
851 status = gser->send_break(gser, duration); in gs_break_ctl()
852 spin_unlock_irq(&port->port_lock); in gs_break_ctl()
869 /*-------------------------------------------------------------------------*/
877 struct gs_console *cons = req->context; in gs_console_complete_out()
879 switch (req->status) { in gs_console_complete_out()
882 __func__, ep->name, req->status); in gs_console_complete_out()
886 spin_lock(&cons->lock); in gs_console_complete_out()
887 req->length = 0; in gs_console_complete_out()
888 schedule_work(&cons->work); in gs_console_complete_out()
889 spin_unlock(&cons->lock); in gs_console_complete_out()
891 case -ECONNRESET: in gs_console_complete_out()
892 case -ESHUTDOWN: in gs_console_complete_out()
894 pr_vdebug("%s: %s shutdown\n", __func__, ep->name); in gs_console_complete_out()
901 struct usb_request *req = cons->req; in __gs_console_push()
908 if (req->length) in __gs_console_push()
911 ep = cons->console.data; in __gs_console_push()
912 size = kfifo_out(&cons->buf, req->buf, ep->maxpacket); in __gs_console_push()
916 if (cons->missed && ep->maxpacket >= 64) { in __gs_console_push()
920 len = sprintf(buf, "\n[missed %zu bytes]\n", cons->missed); in __gs_console_push()
921 kfifo_in(&cons->buf, buf, len); in __gs_console_push()
922 cons->missed = 0; in __gs_console_push()
925 req->length = size; in __gs_console_push()
927 spin_unlock_irq(&cons->lock); in __gs_console_push()
929 req->length = 0; in __gs_console_push()
930 spin_lock_irq(&cons->lock); in __gs_console_push()
937 spin_lock_irq(&cons->lock); in gs_console_work()
941 spin_unlock_irq(&cons->lock); in gs_console_work()
951 spin_lock_irqsave(&cons->lock, flags); in gs_console_write()
953 n = kfifo_in(&cons->buf, buf, count); in gs_console_write()
955 cons->missed += count - n; in gs_console_write()
957 if (cons->req && !cons->req->length) in gs_console_write()
958 schedule_work(&cons->work); in gs_console_write()
960 spin_unlock_irqrestore(&cons->lock, flags); in gs_console_write()
965 *index = co->index; in gs_console_device()
969 static int gs_console_connect(struct gs_port *port) in gs_console_connect() argument
971 struct gs_console *cons = port->console; in gs_console_connect()
978 ep = port->port_usb->in; in gs_console_connect()
979 req = gs_alloc_req(ep, ep->maxpacket, GFP_ATOMIC); in gs_console_connect()
981 return -ENOMEM; in gs_console_connect()
982 req->complete = gs_console_complete_out; in gs_console_connect()
983 req->context = cons; in gs_console_connect()
984 req->length = 0; in gs_console_connect()
986 spin_lock(&cons->lock); in gs_console_connect()
987 cons->req = req; in gs_console_connect()
988 cons->console.data = ep; in gs_console_connect()
989 spin_unlock(&cons->lock); in gs_console_connect()
991 pr_debug("ttyGS%d: console connected!\n", port->port_num); in gs_console_connect()
993 schedule_work(&cons->work); in gs_console_connect()
998 static void gs_console_disconnect(struct gs_port *port) in gs_console_disconnect() argument
1000 struct gs_console *cons = port->console; in gs_console_disconnect()
1007 spin_lock(&cons->lock); in gs_console_disconnect()
1009 req = cons->req; in gs_console_disconnect()
1010 ep = cons->console.data; in gs_console_disconnect()
1011 cons->req = NULL; in gs_console_disconnect()
1013 spin_unlock(&cons->lock); in gs_console_disconnect()
1022 static int gs_console_init(struct gs_port *port) in gs_console_init() argument
1027 if (port->console) in gs_console_init()
1030 cons = kzalloc(sizeof(*port->console), GFP_KERNEL); in gs_console_init()
1032 return -ENOMEM; in gs_console_init()
1034 strcpy(cons->console.name, "ttyGS"); in gs_console_init()
1035 cons->console.write = gs_console_write; in gs_console_init()
1036 cons->console.device = gs_console_device; in gs_console_init()
1037 cons->console.flags = CON_PRINTBUFFER; in gs_console_init()
1038 cons->console.index = port->port_num; in gs_console_init()
1040 INIT_WORK(&cons->work, gs_console_work); in gs_console_init()
1041 spin_lock_init(&cons->lock); in gs_console_init()
1043 err = kfifo_alloc(&cons->buf, GS_CONSOLE_BUF_SIZE, GFP_KERNEL); in gs_console_init()
1045 pr_err("ttyGS%d: allocate console buffer failed\n", port->port_num); in gs_console_init()
1050 port->console = cons; in gs_console_init()
1051 register_console(&cons->console); in gs_console_init()
1053 spin_lock_irq(&port->port_lock); in gs_console_init()
1054 if (port->port_usb) in gs_console_init()
1055 gs_console_connect(port); in gs_console_init()
1056 spin_unlock_irq(&port->port_lock); in gs_console_init()
1061 static void gs_console_exit(struct gs_port *port) in gs_console_exit() argument
1063 struct gs_console *cons = port->console; in gs_console_exit()
1068 unregister_console(&cons->console); in gs_console_exit()
1070 spin_lock_irq(&port->port_lock); in gs_console_exit()
1071 if (cons->req) in gs_console_exit()
1072 gs_console_disconnect(port); in gs_console_exit()
1073 spin_unlock_irq(&port->port_lock); in gs_console_exit()
1075 cancel_work_sync(&cons->work); in gs_console_exit()
1076 kfifo_free(&cons->buf); in gs_console_exit()
1078 port->console = NULL; in gs_console_exit()
1083 struct gs_port *port; in gserial_set_console() local
1092 port = ports[port_num].port; in gserial_set_console()
1094 if (WARN_ON(port == NULL)) { in gserial_set_console()
1095 ret = -ENXIO; in gserial_set_console()
1100 ret = gs_console_init(port); in gserial_set_console()
1102 gs_console_exit(port); in gserial_set_console()
1112 struct gs_port *port; in gserial_get_console() local
1116 port = ports[port_num].port; in gserial_get_console()
1118 if (WARN_ON(port == NULL)) in gserial_get_console()
1119 ret = -ENXIO; in gserial_get_console()
1121 ret = sprintf(page, "%u\n", !!port->console); in gserial_get_console()
1131 static int gs_console_connect(struct gs_port *port) in gs_console_connect() argument
1136 static void gs_console_disconnect(struct gs_port *port) in gs_console_disconnect() argument
1140 static int gs_console_init(struct gs_port *port) in gs_console_init() argument
1142 return -ENOSYS; in gs_console_init()
1145 static void gs_console_exit(struct gs_port *port) in gs_console_exit() argument
1154 struct gs_port *port; in gs_port_alloc() local
1158 if (ports[port_num].port) { in gs_port_alloc()
1159 ret = -EBUSY; in gs_port_alloc()
1163 port = kzalloc(sizeof(struct gs_port), GFP_KERNEL); in gs_port_alloc()
1164 if (port == NULL) { in gs_port_alloc()
1165 ret = -ENOMEM; in gs_port_alloc()
1169 tty_port_init(&port->port); in gs_port_alloc()
1170 spin_lock_init(&port->port_lock); in gs_port_alloc()
1171 init_waitqueue_head(&port->drain_wait); in gs_port_alloc()
1172 init_waitqueue_head(&port->close_wait); in gs_port_alloc()
1174 INIT_DELAYED_WORK(&port->push, gs_rx_push); in gs_port_alloc()
1176 INIT_LIST_HEAD(&port->read_pool); in gs_port_alloc()
1177 INIT_LIST_HEAD(&port->read_queue); in gs_port_alloc()
1178 INIT_LIST_HEAD(&port->write_pool); in gs_port_alloc()
1180 port->port_num = port_num; in gs_port_alloc()
1181 port->port_line_coding = *coding; in gs_port_alloc()
1183 ports[port_num].port = port; in gs_port_alloc()
1189 static int gs_closed(struct gs_port *port) in gs_closed() argument
1193 spin_lock_irq(&port->port_lock); in gs_closed()
1194 cond = port->port.count == 0; in gs_closed()
1195 spin_unlock_irq(&port->port_lock); in gs_closed()
1200 static void gserial_free_port(struct gs_port *port) in gserial_free_port() argument
1202 cancel_delayed_work_sync(&port->push); in gserial_free_port()
1204 wait_event(port->close_wait, gs_closed(port)); in gserial_free_port()
1205 WARN_ON(port->port_usb != NULL); in gserial_free_port()
1206 tty_port_destroy(&port->port); in gserial_free_port()
1207 kfree(port); in gserial_free_port()
1212 struct gs_port *port; in gserial_free_line() local
1215 if (!ports[port_num].port) { in gserial_free_line()
1219 port = ports[port_num].port; in gserial_free_line()
1220 gs_console_exit(port); in gserial_free_line()
1221 ports[port_num].port = NULL; in gserial_free_line()
1224 gserial_free_port(port); in gserial_free_line()
1232 struct gs_port *port; in gserial_alloc_line_no_console() local
1244 if (ret == -EBUSY) in gserial_alloc_line_no_console()
1255 port = ports[port_num].port; in gserial_alloc_line_no_console()
1256 tty_dev = tty_port_register_device(&port->port, in gserial_alloc_line_no_console()
1259 pr_err("%s: failed to register tty for port %d, err %ld\n", in gserial_alloc_line_no_console()
1264 ports[port_num].port = NULL; in gserial_alloc_line_no_console()
1266 gserial_free_port(port); in gserial_alloc_line_no_console()
1280 gs_console_init(ports[*line_num].port); in gserial_alloc_line()
1287 * gserial_connect - notify TTY I/O glue that USB link is active
1289 * @port_num: which port is active
1300 * before calling this, as well as the appropriate (speed-specific)
1305 * On success, ep->driver_data will be overwritten.
1309 struct gs_port *port; in gserial_connect() local
1314 return -ENXIO; in gserial_connect()
1316 port = ports[port_num].port; in gserial_connect()
1317 if (!port) { in gserial_connect()
1319 return -EINVAL; in gserial_connect()
1321 if (port->port_usb) { in gserial_connect()
1323 return -EBUSY; in gserial_connect()
1327 status = usb_ep_enable(gser->in); in gserial_connect()
1330 gser->in->driver_data = port; in gserial_connect()
1332 status = usb_ep_enable(gser->out); in gserial_connect()
1335 gser->out->driver_data = port; in gserial_connect()
1338 spin_lock_irqsave(&port->port_lock, flags); in gserial_connect()
1339 gser->ioport = port; in gserial_connect()
1340 port->port_usb = gser; in gserial_connect()
1345 gser->port_line_coding = port->port_line_coding; in gserial_connect()
1352 if (port->port.count) { in gserial_connect()
1353 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num); in gserial_connect()
1354 gs_start_io(port); in gserial_connect()
1355 if (gser->connect) in gserial_connect()
1356 gser->connect(gser); in gserial_connect()
1358 if (gser->disconnect) in gserial_connect()
1359 gser->disconnect(gser); in gserial_connect()
1362 status = gs_console_connect(port); in gserial_connect()
1363 spin_unlock_irqrestore(&port->port_lock, flags); in gserial_connect()
1368 usb_ep_disable(gser->in); in gserial_connect()
1373 * gserial_disconnect - notify TTY I/O glue that USB link is inactive
1385 struct gs_port *port = gser->ioport; in gserial_disconnect() local
1388 if (!port) in gserial_disconnect()
1394 spin_lock(&port->port_lock); in gserial_disconnect()
1396 gs_console_disconnect(port); in gserial_disconnect()
1399 port->port_line_coding = gser->port_line_coding; in gserial_disconnect()
1402 usb_ep_disable(gser->out); in gserial_disconnect()
1403 usb_ep_disable(gser->in); in gserial_disconnect()
1405 port->port_usb = NULL; in gserial_disconnect()
1406 gser->ioport = NULL; in gserial_disconnect()
1407 if (port->port.count > 0) { in gserial_disconnect()
1408 wake_up_interruptible(&port->drain_wait); in gserial_disconnect()
1409 if (port->port.tty) in gserial_disconnect()
1410 tty_hangup(port->port.tty); in gserial_disconnect()
1412 port->suspended = false; in gserial_disconnect()
1413 spin_unlock(&port->port_lock); in gserial_disconnect()
1417 spin_lock_irqsave(&port->port_lock, flags); in gserial_disconnect()
1418 if (port->port.count == 0) in gserial_disconnect()
1419 kfifo_free(&port->port_write_buf); in gserial_disconnect()
1420 gs_free_requests(gser->out, &port->read_pool, NULL); in gserial_disconnect()
1421 gs_free_requests(gser->out, &port->read_queue, NULL); in gserial_disconnect()
1422 gs_free_requests(gser->in, &port->write_pool, NULL); in gserial_disconnect()
1424 port->read_allocated = port->read_started = in gserial_disconnect()
1425 port->write_allocated = port->write_started = 0; in gserial_disconnect()
1427 spin_unlock_irqrestore(&port->port_lock, flags); in gserial_disconnect()
1433 struct gs_port *port; in gserial_suspend() local
1437 port = gser->ioport; in gserial_suspend()
1439 if (!port) { in gserial_suspend()
1444 spin_lock(&port->port_lock); in gserial_suspend()
1446 port->suspended = true; in gserial_suspend()
1447 port->start_delayed = true; in gserial_suspend()
1448 spin_unlock_irqrestore(&port->port_lock, flags); in gserial_suspend()
1454 struct gs_port *port; in gserial_resume() local
1458 port = gser->ioport; in gserial_resume()
1460 if (!port) { in gserial_resume()
1465 spin_lock(&port->port_lock); in gserial_resume()
1467 port->suspended = false; in gserial_resume()
1468 if (!port->start_delayed) { in gserial_resume()
1469 spin_unlock_irqrestore(&port->port_lock, flags); in gserial_resume()
1473 pr_debug("delayed start ttyGS%d\n", port->port_num); in gserial_resume()
1474 gs_start_io(port); in gserial_resume()
1475 if (gser->connect) in gserial_resume()
1476 gser->connect(gser); in gserial_resume()
1477 port->start_delayed = false; in gserial_resume()
1478 spin_unlock_irqrestore(&port->port_lock, flags); in gserial_resume()
1493 driver->driver_name = "g_serial"; in userial_init()
1494 driver->name = "ttyGS"; in userial_init()
1497 driver->type = TTY_DRIVER_TYPE_SERIAL; in userial_init()
1498 driver->subtype = SERIAL_TYPE_NORMAL; in userial_init()
1499 driver->init_termios = tty_std_termios; in userial_init()
1501 /* 9600-8-N-1 ... matches defaults expected by "usbser.sys" on in userial_init()
1502 * MS-Windows. Otherwise, most of these flags shouldn't affect in userial_init()
1505 driver->init_termios.c_cflag = in userial_init()
1507 driver->init_termios.c_ispeed = 9600; in userial_init()
1508 driver->init_termios.c_ospeed = 9600; in userial_init()