Lines Matching refs:port

104 	struct tty_port		port;  member
138 struct gs_port *port; member
209 gs_send_packet(struct gs_port *port, char *packet, unsigned size) in gs_send_packet() argument
213 len = kfifo_len(&port->port_write_buf); in gs_send_packet()
217 size = kfifo_out(&port->port_write_buf, packet, size); in gs_send_packet()
232 static int gs_start_tx(struct gs_port *port) in gs_start_tx() argument
238 struct list_head *pool = &port->write_pool; in gs_start_tx()
243 if (!port->port_usb) in gs_start_tx()
246 in = port->port_usb->in; in gs_start_tx()
248 while (!port->write_busy && !list_empty(pool)) { in gs_start_tx()
252 if (port->write_started >= QUEUE_SIZE) in gs_start_tx()
256 len = gs_send_packet(port, req->buf, in->maxpacket); in gs_start_tx()
258 wake_up_interruptible(&port->drain_wait); in gs_start_tx()
262 port->icount.tx += len; in gs_start_tx()
266 req->zero = kfifo_is_empty(&port->port_write_buf); in gs_start_tx()
268 pr_vdebug("ttyGS%d: tx len=%d, %3ph ...\n", port->port_num, len, req->buf); in gs_start_tx()
277 port->write_busy = true; in gs_start_tx()
278 spin_unlock(&port->port_lock); in gs_start_tx()
280 spin_lock(&port->port_lock); in gs_start_tx()
281 port->write_busy = false; in gs_start_tx()
290 port->write_started++; in gs_start_tx()
293 if (!port->port_usb) in gs_start_tx()
297 if (do_tty_wake && port->port.tty) in gs_start_tx()
298 tty_wakeup(port->port.tty); in gs_start_tx()
305 static unsigned gs_start_rx(struct gs_port *port) in gs_start_rx() argument
311 struct list_head *pool = &port->read_pool; in gs_start_rx()
312 struct usb_ep *out = port->port_usb->out; in gs_start_rx()
320 tty = port->port.tty; in gs_start_rx()
324 if (port->read_started >= QUEUE_SIZE) in gs_start_rx()
334 spin_unlock(&port->port_lock); in gs_start_rx()
336 spin_lock(&port->port_lock); in gs_start_rx()
344 port->read_started++; in gs_start_rx()
347 if (!port->port_usb) in gs_start_rx()
350 return port->read_started; in gs_start_rx()
366 struct gs_port *port = container_of(w, struct gs_port, push); in gs_rx_push() local
368 struct list_head *queue = &port->read_queue; in gs_rx_push()
373 spin_lock_irq(&port->port_lock); in gs_rx_push()
374 tty = port->port.tty; in gs_rx_push()
387 pr_vdebug("ttyGS%d: shutdown\n", port->port_num); in gs_rx_push()
393 port->port_num, req->status); in gs_rx_push()
408 n = port->n_read; in gs_rx_push()
414 port->icount.rx += size; in gs_rx_push()
415 count = tty_insert_flip_string(&port->port, packet, in gs_rx_push()
421 port->n_read += count; in gs_rx_push()
423 port->port_num, count, req->actual); in gs_rx_push()
426 port->n_read = 0; in gs_rx_push()
429 list_move(&req->list, &port->read_pool); in gs_rx_push()
430 port->read_started--; in gs_rx_push()
437 tty_flip_buffer_push(&port->port); in gs_rx_push()
448 schedule_delayed_work(&port->push, 1); in gs_rx_push()
451 if (!disconnect && port->port_usb) in gs_rx_push()
452 gs_start_rx(port); in gs_rx_push()
454 spin_unlock_irq(&port->port_lock); in gs_rx_push()
459 struct gs_port *port = ep->driver_data; in gs_read_complete() local
462 spin_lock(&port->port_lock); in gs_read_complete()
463 list_add_tail(&req->list, &port->read_queue); in gs_read_complete()
464 schedule_delayed_work(&port->push, 0); in gs_read_complete()
465 spin_unlock(&port->port_lock); in gs_read_complete()
470 struct gs_port *port = ep->driver_data; in gs_write_complete() local
472 spin_lock(&port->port_lock); in gs_write_complete()
473 list_add(&req->list, &port->write_pool); in gs_write_complete()
474 port->write_started--; in gs_write_complete()
484 gs_start_tx(port); in gs_write_complete()
493 spin_unlock(&port->port_lock); in gs_write_complete()
543 static int gs_start_io(struct gs_port *port) in gs_start_io() argument
545 struct list_head *head = &port->read_pool; in gs_start_io()
550 if (!port->port_usb || !port->port.tty) in gs_start_io()
559 ep = port->port_usb->out; in gs_start_io()
561 &port->read_allocated); in gs_start_io()
565 status = gs_alloc_requests(port->port_usb->in, &port->write_pool, in gs_start_io()
566 gs_write_complete, &port->write_allocated); in gs_start_io()
568 gs_free_requests(ep, head, &port->read_allocated); in gs_start_io()
573 port->n_read = 0; in gs_start_io()
574 started = gs_start_rx(port); in gs_start_io()
577 gs_start_tx(port); in gs_start_io()
580 tty_wakeup(port->port.tty); in gs_start_io()
582 gs_free_requests(ep, head, &port->read_allocated); in gs_start_io()
583 gs_free_requests(port->port_usb->in, &port->write_pool, in gs_start_io()
584 &port->write_allocated); in gs_start_io()
603 struct gs_port *port; in gs_open() local
607 port = ports[port_num].port; in gs_open()
608 if (!port) { in gs_open()
613 spin_lock_irq(&port->port_lock); in gs_open()
616 if (!kfifo_initialized(&port->port_write_buf)) { in gs_open()
618 spin_unlock_irq(&port->port_lock); in gs_open()
625 status = kfifo_alloc(&port->port_write_buf, in gs_open()
633 spin_lock_irq(&port->port_lock); in gs_open()
637 if (port->port.count++) in gs_open()
640 tty->driver_data = port; in gs_open()
641 port->port.tty = tty; in gs_open()
644 if (port->port_usb) { in gs_open()
646 if (!port->suspended) { in gs_open()
647 struct gserial *gser = port->port_usb; in gs_open()
649 pr_debug("gs_open: start ttyGS%d\n", port->port_num); in gs_open()
650 gs_start_io(port); in gs_open()
655 pr_debug("delay start of ttyGS%d\n", port->port_num); in gs_open()
656 port->start_delayed = true; in gs_open()
660 pr_debug("gs_open: ttyGS%d (%p,%p)\n", port->port_num, tty, file); in gs_open()
663 spin_unlock_irq(&port->port_lock); in gs_open()
676 p->port.count > 1; in gs_close_flush_done()
684 struct gs_port *port = tty->driver_data; in gs_close() local
687 spin_lock_irq(&port->port_lock); in gs_close()
689 if (port->port.count != 1) { in gs_close()
691 if (port->port.count == 0) in gs_close()
694 --port->port.count; in gs_close()
698 pr_debug("gs_close: ttyGS%d (%p,%p) ...\n", port->port_num, tty, file); in gs_close()
700 gser = port->port_usb; in gs_close()
701 if (gser && !port->suspended && gser->disconnect) in gs_close()
707 if (kfifo_len(&port->port_write_buf) > 0 && gser) { in gs_close()
708 spin_unlock_irq(&port->port_lock); in gs_close()
709 wait_event_interruptible_timeout(port->drain_wait, in gs_close()
710 gs_close_flush_done(port), in gs_close()
712 spin_lock_irq(&port->port_lock); in gs_close()
714 if (port->port.count != 1) in gs_close()
717 gser = port->port_usb; in gs_close()
725 kfifo_free(&port->port_write_buf); in gs_close()
727 kfifo_reset(&port->port_write_buf); in gs_close()
729 port->start_delayed = false; in gs_close()
730 port->port.count = 0; in gs_close()
731 port->port.tty = NULL; in gs_close()
734 port->port_num, tty, file); in gs_close()
736 wake_up(&port->close_wait); in gs_close()
738 spin_unlock_irq(&port->port_lock); in gs_close()
743 struct gs_port *port = tty->driver_data; in gs_write() local
747 port->port_num, tty, count); in gs_write()
749 spin_lock_irqsave(&port->port_lock, flags); in gs_write()
751 count = kfifo_in(&port->port_write_buf, buf, count); in gs_write()
753 if (port->port_usb) in gs_write()
754 gs_start_tx(port); in gs_write()
755 spin_unlock_irqrestore(&port->port_lock, flags); in gs_write()
762 struct gs_port *port = tty->driver_data; in gs_put_char() local
767 port->port_num, tty, ch, __builtin_return_address(0)); in gs_put_char()
769 spin_lock_irqsave(&port->port_lock, flags); in gs_put_char()
770 status = kfifo_put(&port->port_write_buf, ch); in gs_put_char()
771 spin_unlock_irqrestore(&port->port_lock, flags); in gs_put_char()
778 struct gs_port *port = tty->driver_data; in gs_flush_chars() local
781 pr_vdebug("gs_flush_chars: (%d,%p)\n", port->port_num, tty); in gs_flush_chars()
783 spin_lock_irqsave(&port->port_lock, flags); in gs_flush_chars()
784 if (port->port_usb) in gs_flush_chars()
785 gs_start_tx(port); in gs_flush_chars()
786 spin_unlock_irqrestore(&port->port_lock, flags); in gs_flush_chars()
791 struct gs_port *port = tty->driver_data; in gs_write_room() local
795 spin_lock_irqsave(&port->port_lock, flags); in gs_write_room()
796 if (port->port_usb) in gs_write_room()
797 room = kfifo_avail(&port->port_write_buf); in gs_write_room()
798 spin_unlock_irqrestore(&port->port_lock, flags); in gs_write_room()
801 port->port_num, tty, room); in gs_write_room()
808 struct gs_port *port = tty->driver_data; in gs_chars_in_buffer() local
812 spin_lock_irqsave(&port->port_lock, flags); in gs_chars_in_buffer()
813 chars = kfifo_len(&port->port_write_buf); in gs_chars_in_buffer()
814 spin_unlock_irqrestore(&port->port_lock, flags); in gs_chars_in_buffer()
817 port->port_num, tty, chars); in gs_chars_in_buffer()
825 struct gs_port *port = tty->driver_data; in gs_unthrottle() local
828 spin_lock_irqsave(&port->port_lock, flags); in gs_unthrottle()
829 if (port->port_usb) { in gs_unthrottle()
834 pr_vdebug("ttyGS%d: unthrottle\n", port->port_num); in gs_unthrottle()
835 schedule_delayed_work(&port->push, 0); in gs_unthrottle()
837 spin_unlock_irqrestore(&port->port_lock, flags); in gs_unthrottle()
842 struct gs_port *port = tty->driver_data; in gs_break_ctl() local
847 port->port_num, duration); in gs_break_ctl()
849 spin_lock_irq(&port->port_lock); in gs_break_ctl()
850 gser = port->port_usb; in gs_break_ctl()
853 spin_unlock_irq(&port->port_lock); in gs_break_ctl()
861 struct gs_port *port = tty->driver_data; in gs_get_icount() local
865 spin_lock_irqsave(&port->port_lock, flags); in gs_get_icount()
866 cnow = port->icount; in gs_get_icount()
867 spin_unlock_irqrestore(&port->port_lock, flags); in gs_get_icount()
988 static int gs_console_connect(struct gs_port *port) in gs_console_connect() argument
990 struct gs_console *cons = port->console; in gs_console_connect()
997 ep = port->port_usb->in; in gs_console_connect()
1010 pr_debug("ttyGS%d: console connected!\n", port->port_num); in gs_console_connect()
1017 static void gs_console_disconnect(struct gs_port *port) in gs_console_disconnect() argument
1019 struct gs_console *cons = port->console; in gs_console_disconnect()
1041 static int gs_console_init(struct gs_port *port) in gs_console_init() argument
1046 if (port->console) in gs_console_init()
1049 cons = kzalloc(sizeof(*port->console), GFP_KERNEL); in gs_console_init()
1057 cons->console.index = port->port_num; in gs_console_init()
1064 pr_err("ttyGS%d: allocate console buffer failed\n", port->port_num); in gs_console_init()
1069 port->console = cons; in gs_console_init()
1072 spin_lock_irq(&port->port_lock); in gs_console_init()
1073 if (port->port_usb) in gs_console_init()
1074 gs_console_connect(port); in gs_console_init()
1075 spin_unlock_irq(&port->port_lock); in gs_console_init()
1080 static void gs_console_exit(struct gs_port *port) in gs_console_exit() argument
1082 struct gs_console *cons = port->console; in gs_console_exit()
1089 spin_lock_irq(&port->port_lock); in gs_console_exit()
1091 gs_console_disconnect(port); in gs_console_exit()
1092 spin_unlock_irq(&port->port_lock); in gs_console_exit()
1097 port->console = NULL; in gs_console_exit()
1102 struct gs_port *port; in gserial_set_console() local
1111 port = ports[port_num].port; in gserial_set_console()
1113 if (WARN_ON(port == NULL)) { in gserial_set_console()
1119 ret = gs_console_init(port); in gserial_set_console()
1121 gs_console_exit(port); in gserial_set_console()
1131 struct gs_port *port; in gserial_get_console() local
1135 port = ports[port_num].port; in gserial_get_console()
1137 if (WARN_ON(port == NULL)) in gserial_get_console()
1140 ret = sprintf(page, "%u\n", !!port->console); in gserial_get_console()
1150 static int gs_console_connect(struct gs_port *port) in gs_console_connect() argument
1155 static void gs_console_disconnect(struct gs_port *port) in gs_console_disconnect() argument
1159 static int gs_console_init(struct gs_port *port) in gs_console_init() argument
1164 static void gs_console_exit(struct gs_port *port) in gs_console_exit() argument
1173 struct gs_port *port; in gs_port_alloc() local
1177 if (ports[port_num].port) { in gs_port_alloc()
1182 port = kzalloc(sizeof(struct gs_port), GFP_KERNEL); in gs_port_alloc()
1183 if (port == NULL) { in gs_port_alloc()
1188 tty_port_init(&port->port); in gs_port_alloc()
1189 spin_lock_init(&port->port_lock); in gs_port_alloc()
1190 init_waitqueue_head(&port->drain_wait); in gs_port_alloc()
1191 init_waitqueue_head(&port->close_wait); in gs_port_alloc()
1193 INIT_DELAYED_WORK(&port->push, gs_rx_push); in gs_port_alloc()
1195 INIT_LIST_HEAD(&port->read_pool); in gs_port_alloc()
1196 INIT_LIST_HEAD(&port->read_queue); in gs_port_alloc()
1197 INIT_LIST_HEAD(&port->write_pool); in gs_port_alloc()
1199 port->port_num = port_num; in gs_port_alloc()
1200 port->port_line_coding = *coding; in gs_port_alloc()
1202 ports[port_num].port = port; in gs_port_alloc()
1208 static int gs_closed(struct gs_port *port) in gs_closed() argument
1212 spin_lock_irq(&port->port_lock); in gs_closed()
1213 cond = port->port.count == 0; in gs_closed()
1214 spin_unlock_irq(&port->port_lock); in gs_closed()
1219 static void gserial_free_port(struct gs_port *port) in gserial_free_port() argument
1221 cancel_delayed_work_sync(&port->push); in gserial_free_port()
1223 wait_event(port->close_wait, gs_closed(port)); in gserial_free_port()
1224 WARN_ON(port->port_usb != NULL); in gserial_free_port()
1225 tty_port_destroy(&port->port); in gserial_free_port()
1226 kfree(port); in gserial_free_port()
1231 struct gs_port *port; in gserial_free_line() local
1234 if (!ports[port_num].port) { in gserial_free_line()
1238 port = ports[port_num].port; in gserial_free_line()
1239 gs_console_exit(port); in gserial_free_line()
1240 ports[port_num].port = NULL; in gserial_free_line()
1243 gserial_free_port(port); in gserial_free_line()
1251 struct gs_port *port; in gserial_alloc_line_no_console() local
1274 port = ports[port_num].port; in gserial_alloc_line_no_console()
1275 tty_dev = tty_port_register_device(&port->port, in gserial_alloc_line_no_console()
1283 ports[port_num].port = NULL; in gserial_alloc_line_no_console()
1285 gserial_free_port(port); in gserial_alloc_line_no_console()
1299 gs_console_init(ports[*line_num].port); in gserial_alloc_line()
1328 struct gs_port *port; in gserial_connect() local
1335 port = ports[port_num].port; in gserial_connect()
1336 if (!port) { in gserial_connect()
1340 if (port->port_usb) { in gserial_connect()
1349 gser->in->driver_data = port; in gserial_connect()
1354 gser->out->driver_data = port; in gserial_connect()
1357 spin_lock_irqsave(&port->port_lock, flags); in gserial_connect()
1358 gser->ioport = port; in gserial_connect()
1359 port->port_usb = gser; in gserial_connect()
1364 gser->port_line_coding = port->port_line_coding; in gserial_connect()
1371 if (port->port.count) { in gserial_connect()
1372 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num); in gserial_connect()
1373 gs_start_io(port); in gserial_connect()
1381 status = gs_console_connect(port); in gserial_connect()
1382 spin_unlock_irqrestore(&port->port_lock, flags); in gserial_connect()
1404 struct gs_port *port = gser->ioport; in gserial_disconnect() local
1407 if (!port) in gserial_disconnect()
1413 spin_lock(&port->port_lock); in gserial_disconnect()
1415 gs_console_disconnect(port); in gserial_disconnect()
1418 port->port_line_coding = gser->port_line_coding; in gserial_disconnect()
1420 port->port_usb = NULL; in gserial_disconnect()
1422 if (port->port.count > 0) { in gserial_disconnect()
1423 wake_up_interruptible(&port->drain_wait); in gserial_disconnect()
1424 if (port->port.tty) in gserial_disconnect()
1425 tty_hangup(port->port.tty); in gserial_disconnect()
1427 port->suspended = false; in gserial_disconnect()
1428 spin_unlock(&port->port_lock); in gserial_disconnect()
1436 spin_lock_irqsave(&port->port_lock, flags); in gserial_disconnect()
1437 if (port->port.count == 0) in gserial_disconnect()
1438 kfifo_free(&port->port_write_buf); in gserial_disconnect()
1439 gs_free_requests(gser->out, &port->read_pool, NULL); in gserial_disconnect()
1440 gs_free_requests(gser->out, &port->read_queue, NULL); in gserial_disconnect()
1441 gs_free_requests(gser->in, &port->write_pool, NULL); in gserial_disconnect()
1443 port->read_allocated = port->read_started = in gserial_disconnect()
1444 port->write_allocated = port->write_started = 0; in gserial_disconnect()
1446 spin_unlock_irqrestore(&port->port_lock, flags); in gserial_disconnect()
1452 struct gs_port *port; in gserial_suspend() local
1456 port = gser->ioport; in gserial_suspend()
1458 if (!port) { in gserial_suspend()
1463 spin_lock(&port->port_lock); in gserial_suspend()
1465 port->suspended = true; in gserial_suspend()
1466 port->start_delayed = true; in gserial_suspend()
1467 spin_unlock_irqrestore(&port->port_lock, flags); in gserial_suspend()
1473 struct gs_port *port; in gserial_resume() local
1477 port = gser->ioport; in gserial_resume()
1479 if (!port) { in gserial_resume()
1484 spin_lock(&port->port_lock); in gserial_resume()
1486 port->suspended = false; in gserial_resume()
1487 if (!port->start_delayed) { in gserial_resume()
1488 spin_unlock_irqrestore(&port->port_lock, flags); in gserial_resume()
1492 pr_debug("delayed start ttyGS%d\n", port->port_num); in gserial_resume()
1493 gs_start_io(port); in gserial_resume()
1496 port->start_delayed = false; in gserial_resume()
1497 spin_unlock_irqrestore(&port->port_lock, flags); in gserial_resume()