Lines Matching refs:port
86 struct gs_port *port; member
100 struct tty_port port; member
129 struct gs_port *port; member
200 gs_send_packet(struct gs_port *port, char *packet, unsigned size) in gs_send_packet() argument
204 len = kfifo_len(&port->port_write_buf); in gs_send_packet()
208 size = kfifo_out(&port->port_write_buf, packet, size); in gs_send_packet()
223 static int gs_start_tx(struct gs_port *port) in gs_start_tx() argument
229 struct list_head *pool = &port->write_pool; in gs_start_tx()
234 if (!port->port_usb) in gs_start_tx()
237 in = port->port_usb->in; in gs_start_tx()
239 while (!port->write_busy && !list_empty(pool)) { in gs_start_tx()
243 if (port->write_started >= QUEUE_SIZE) in gs_start_tx()
247 len = gs_send_packet(port, req->buf, in->maxpacket); in gs_start_tx()
249 wake_up_interruptible(&port->drain_wait); in gs_start_tx()
256 req->zero = kfifo_is_empty(&port->port_write_buf); in gs_start_tx()
259 port->port_num, len, *((u8 *)req->buf), in gs_start_tx()
269 port->write_busy = true; in gs_start_tx()
270 spin_unlock(&port->port_lock); in gs_start_tx()
272 spin_lock(&port->port_lock); in gs_start_tx()
273 port->write_busy = false; in gs_start_tx()
282 port->write_started++; in gs_start_tx()
285 if (!port->port_usb) in gs_start_tx()
289 if (do_tty_wake && port->port.tty) in gs_start_tx()
290 tty_wakeup(port->port.tty); in gs_start_tx()
297 static unsigned gs_start_rx(struct gs_port *port) in gs_start_rx() argument
303 struct list_head *pool = &port->read_pool; in gs_start_rx()
304 struct usb_ep *out = port->port_usb->out; in gs_start_rx()
312 tty = port->port.tty; in gs_start_rx()
316 if (port->read_started >= QUEUE_SIZE) in gs_start_rx()
326 spin_unlock(&port->port_lock); in gs_start_rx()
328 spin_lock(&port->port_lock); in gs_start_rx()
336 port->read_started++; in gs_start_rx()
339 if (!port->port_usb) in gs_start_rx()
342 return port->read_started; in gs_start_rx()
357 struct gs_port *port = (void *)_port; in gs_rx_push() local
359 struct list_head *queue = &port->read_queue; in gs_rx_push()
364 spin_lock_irq(&port->port_lock); in gs_rx_push()
365 tty = port->port.tty; in gs_rx_push()
378 pr_vdebug("ttyGS%d: shutdown\n", port->port_num); in gs_rx_push()
384 port->port_num, req->status); in gs_rx_push()
399 n = port->n_read; in gs_rx_push()
405 count = tty_insert_flip_string(&port->port, packet, in gs_rx_push()
411 port->n_read += count; in gs_rx_push()
413 port->port_num, count, req->actual); in gs_rx_push()
416 port->n_read = 0; in gs_rx_push()
419 list_move(&req->list, &port->read_pool); in gs_rx_push()
420 port->read_started--; in gs_rx_push()
427 tty_flip_buffer_push(&port->port); in gs_rx_push()
441 tasklet_schedule(&port->push); in gs_rx_push()
444 port->port_num); in gs_rx_push()
449 if (!disconnect && port->port_usb) in gs_rx_push()
450 gs_start_rx(port); in gs_rx_push()
452 spin_unlock_irq(&port->port_lock); in gs_rx_push()
457 struct gs_port *port = ep->driver_data; in gs_read_complete() local
460 spin_lock(&port->port_lock); in gs_read_complete()
461 list_add_tail(&req->list, &port->read_queue); in gs_read_complete()
462 tasklet_schedule(&port->push); in gs_read_complete()
463 spin_unlock(&port->port_lock); in gs_read_complete()
468 struct gs_port *port = ep->driver_data; in gs_write_complete() local
470 spin_lock(&port->port_lock); in gs_write_complete()
471 list_add(&req->list, &port->write_pool); in gs_write_complete()
472 port->write_started--; in gs_write_complete()
482 gs_start_tx(port); in gs_write_complete()
491 spin_unlock(&port->port_lock); in gs_write_complete()
541 static int gs_start_io(struct gs_port *port) in gs_start_io() argument
543 struct list_head *head = &port->read_pool; in gs_start_io()
544 struct usb_ep *ep = port->port_usb->out; in gs_start_io()
555 &port->read_allocated); in gs_start_io()
559 status = gs_alloc_requests(port->port_usb->in, &port->write_pool, in gs_start_io()
560 gs_write_complete, &port->write_allocated); in gs_start_io()
562 gs_free_requests(ep, head, &port->read_allocated); in gs_start_io()
567 port->n_read = 0; in gs_start_io()
568 started = gs_start_rx(port); in gs_start_io()
572 tty_wakeup(port->port.tty); in gs_start_io()
574 gs_free_requests(ep, head, &port->read_allocated); in gs_start_io()
575 gs_free_requests(port->port_usb->in, &port->write_pool, in gs_start_io()
576 &port->write_allocated); in gs_start_io()
595 struct gs_port *port; in gs_open() local
600 port = ports[port_num].port; in gs_open()
601 if (!port) in gs_open()
604 spin_lock_irq(&port->port_lock); in gs_open()
607 if (port->port.count) { in gs_open()
609 port->port.count++; in gs_open()
612 } else if (port->openclose) { in gs_open()
618 port->openclose = true; in gs_open()
620 spin_unlock_irq(&port->port_lock); in gs_open()
642 spin_lock_irq(&port->port_lock); in gs_open()
645 if (!kfifo_initialized(&port->port_write_buf)) { in gs_open()
647 spin_unlock_irq(&port->port_lock); in gs_open()
648 status = kfifo_alloc(&port->port_write_buf, in gs_open()
650 spin_lock_irq(&port->port_lock); in gs_open()
654 port->port_num, tty, file); in gs_open()
655 port->openclose = false; in gs_open()
666 tty->driver_data = port; in gs_open()
667 port->port.tty = tty; in gs_open()
669 port->port.count = 1; in gs_open()
670 port->openclose = false; in gs_open()
673 if (port->port_usb) { in gs_open()
674 struct gserial *gser = port->port_usb; in gs_open()
676 pr_debug("gs_open: start ttyGS%d\n", port->port_num); in gs_open()
677 gs_start_io(port); in gs_open()
683 pr_debug("gs_open: ttyGS%d (%p,%p)\n", port->port_num, tty, file); in gs_open()
688 spin_unlock_irq(&port->port_lock); in gs_open()
706 struct gs_port *port = tty->driver_data; in gs_close() local
709 spin_lock_irq(&port->port_lock); in gs_close()
711 if (port->port.count != 1) { in gs_close()
712 if (port->port.count == 0) in gs_close()
715 --port->port.count; in gs_close()
719 pr_debug("gs_close: ttyGS%d (%p,%p) ...\n", port->port_num, tty, file); in gs_close()
724 port->openclose = true; in gs_close()
725 port->port.count = 0; in gs_close()
727 gser = port->port_usb; in gs_close()
734 if (kfifo_len(&port->port_write_buf) > 0 && gser) { in gs_close()
735 spin_unlock_irq(&port->port_lock); in gs_close()
736 wait_event_interruptible_timeout(port->drain_wait, in gs_close()
737 gs_writes_finished(port), in gs_close()
739 spin_lock_irq(&port->port_lock); in gs_close()
740 gser = port->port_usb; in gs_close()
748 kfifo_free(&port->port_write_buf); in gs_close()
750 kfifo_reset(&port->port_write_buf); in gs_close()
752 port->port.tty = NULL; in gs_close()
754 port->openclose = false; in gs_close()
757 port->port_num, tty, file); in gs_close()
759 wake_up(&port->close_wait); in gs_close()
761 spin_unlock_irq(&port->port_lock); in gs_close()
766 struct gs_port *port = tty->driver_data; in gs_write() local
770 port->port_num, tty, count); in gs_write()
772 spin_lock_irqsave(&port->port_lock, flags); in gs_write()
774 count = kfifo_in(&port->port_write_buf, buf, count); in gs_write()
776 if (port->port_usb) in gs_write()
777 gs_start_tx(port); in gs_write()
778 spin_unlock_irqrestore(&port->port_lock, flags); in gs_write()
785 struct gs_port *port = tty->driver_data; in gs_put_char() local
790 port->port_num, tty, ch, __builtin_return_address(0)); in gs_put_char()
792 spin_lock_irqsave(&port->port_lock, flags); in gs_put_char()
793 status = kfifo_put(&port->port_write_buf, ch); in gs_put_char()
794 spin_unlock_irqrestore(&port->port_lock, flags); in gs_put_char()
801 struct gs_port *port = tty->driver_data; in gs_flush_chars() local
804 pr_vdebug("gs_flush_chars: (%d,%p)\n", port->port_num, tty); in gs_flush_chars()
806 spin_lock_irqsave(&port->port_lock, flags); in gs_flush_chars()
807 if (port->port_usb) in gs_flush_chars()
808 gs_start_tx(port); in gs_flush_chars()
809 spin_unlock_irqrestore(&port->port_lock, flags); in gs_flush_chars()
814 struct gs_port *port = tty->driver_data; in gs_write_room() local
818 spin_lock_irqsave(&port->port_lock, flags); in gs_write_room()
819 if (port->port_usb) in gs_write_room()
820 room = kfifo_avail(&port->port_write_buf); in gs_write_room()
821 spin_unlock_irqrestore(&port->port_lock, flags); in gs_write_room()
824 port->port_num, tty, room); in gs_write_room()
831 struct gs_port *port = tty->driver_data; in gs_chars_in_buffer() local
835 spin_lock_irqsave(&port->port_lock, flags); in gs_chars_in_buffer()
836 chars = kfifo_len(&port->port_write_buf); in gs_chars_in_buffer()
837 spin_unlock_irqrestore(&port->port_lock, flags); in gs_chars_in_buffer()
840 port->port_num, tty, chars); in gs_chars_in_buffer()
848 struct gs_port *port = tty->driver_data; in gs_unthrottle() local
851 spin_lock_irqsave(&port->port_lock, flags); in gs_unthrottle()
852 if (port->port_usb) { in gs_unthrottle()
857 tasklet_schedule(&port->push); in gs_unthrottle()
858 pr_vdebug("ttyGS%d: unthrottle\n", port->port_num); in gs_unthrottle()
860 spin_unlock_irqrestore(&port->port_lock, flags); in gs_unthrottle()
865 struct gs_port *port = tty->driver_data; in gs_break_ctl() local
870 port->port_num, duration); in gs_break_ctl()
872 spin_lock_irq(&port->port_lock); in gs_break_ctl()
873 gser = port->port_usb; in gs_break_ctl()
876 spin_unlock_irq(&port->port_lock); in gs_break_ctl()
953 struct gs_port *port; in gs_console_connect() local
962 port = ports[port_num].port; in gs_console_connect()
963 ep = port->port_usb->in; in gs_console_connect()
971 info->port = port; in gs_console_connect()
991 struct gs_port *port; in gs_console_thread() local
997 port = info->port; in gs_console_thread()
999 if (!port || !port->port_usb in gs_console_thread()
1000 || !port->port_usb->in || !info->console_req) in gs_console_thread()
1004 ep = port->port_usb->in; in gs_console_thread()
1046 info->port = NULL; in gs_console_setup()
1142 struct gs_port *port; in gs_port_alloc() local
1146 if (ports[port_num].port) { in gs_port_alloc()
1151 port = kzalloc(sizeof(struct gs_port), GFP_KERNEL); in gs_port_alloc()
1152 if (port == NULL) { in gs_port_alloc()
1157 tty_port_init(&port->port); in gs_port_alloc()
1158 spin_lock_init(&port->port_lock); in gs_port_alloc()
1159 init_waitqueue_head(&port->drain_wait); in gs_port_alloc()
1160 init_waitqueue_head(&port->close_wait); in gs_port_alloc()
1162 tasklet_init(&port->push, gs_rx_push, (unsigned long) port); in gs_port_alloc()
1164 INIT_LIST_HEAD(&port->read_pool); in gs_port_alloc()
1165 INIT_LIST_HEAD(&port->read_queue); in gs_port_alloc()
1166 INIT_LIST_HEAD(&port->write_pool); in gs_port_alloc()
1168 port->port_num = port_num; in gs_port_alloc()
1169 port->port_line_coding = *coding; in gs_port_alloc()
1171 ports[port_num].port = port; in gs_port_alloc()
1177 static int gs_closed(struct gs_port *port) in gs_closed() argument
1181 spin_lock_irq(&port->port_lock); in gs_closed()
1182 cond = (port->port.count == 0) && !port->openclose; in gs_closed()
1183 spin_unlock_irq(&port->port_lock); in gs_closed()
1187 static void gserial_free_port(struct gs_port *port) in gserial_free_port() argument
1189 tasklet_kill(&port->push); in gserial_free_port()
1191 wait_event(port->close_wait, gs_closed(port)); in gserial_free_port()
1192 WARN_ON(port->port_usb != NULL); in gserial_free_port()
1193 tty_port_destroy(&port->port); in gserial_free_port()
1194 kfree(port); in gserial_free_port()
1199 struct gs_port *port; in gserial_free_line() local
1202 if (WARN_ON(!ports[port_num].port)) { in gserial_free_line()
1206 port = ports[port_num].port; in gserial_free_line()
1207 ports[port_num].port = NULL; in gserial_free_line()
1210 gserial_free_port(port); in gserial_free_line()
1241 tty_dev = tty_port_register_device(&ports[port_num].port->port, in gserial_alloc_line()
1244 struct gs_port *port; in gserial_alloc_line() local
1249 port = ports[port_num].port; in gserial_alloc_line()
1250 ports[port_num].port = NULL; in gserial_alloc_line()
1251 gserial_free_port(port); in gserial_alloc_line()
1284 struct gs_port *port; in gserial_connect() local
1291 port = ports[port_num].port; in gserial_connect()
1292 if (!port) { in gserial_connect()
1296 if (port->port_usb) { in gserial_connect()
1305 gser->in->driver_data = port; in gserial_connect()
1310 gser->out->driver_data = port; in gserial_connect()
1313 spin_lock_irqsave(&port->port_lock, flags); in gserial_connect()
1314 gser->ioport = port; in gserial_connect()
1315 port->port_usb = gser; in gserial_connect()
1320 gser->port_line_coding = port->port_line_coding; in gserial_connect()
1327 if (port->port.count) { in gserial_connect()
1328 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num); in gserial_connect()
1329 gs_start_io(port); in gserial_connect()
1338 spin_unlock_irqrestore(&port->port_lock, flags); in gserial_connect()
1360 struct gs_port *port = gser->ioport; in gserial_disconnect() local
1363 if (!port) in gserial_disconnect()
1367 spin_lock_irqsave(&port->port_lock, flags); in gserial_disconnect()
1370 port->port_line_coding = gser->port_line_coding; in gserial_disconnect()
1372 port->port_usb = NULL; in gserial_disconnect()
1374 if (port->port.count > 0 || port->openclose) { in gserial_disconnect()
1375 wake_up_interruptible(&port->drain_wait); in gserial_disconnect()
1376 if (port->port.tty) in gserial_disconnect()
1377 tty_hangup(port->port.tty); in gserial_disconnect()
1379 spin_unlock_irqrestore(&port->port_lock, flags); in gserial_disconnect()
1386 spin_lock_irqsave(&port->port_lock, flags); in gserial_disconnect()
1387 if (port->port.count == 0 && !port->openclose) in gserial_disconnect()
1388 kfifo_free(&port->port_write_buf); in gserial_disconnect()
1389 gs_free_requests(gser->out, &port->read_pool, NULL); in gserial_disconnect()
1390 gs_free_requests(gser->out, &port->read_queue, NULL); in gserial_disconnect()
1391 gs_free_requests(gser->in, &port->write_pool, NULL); in gserial_disconnect()
1393 port->read_allocated = port->read_started = in gserial_disconnect()
1394 port->write_allocated = port->write_started = 0; in gserial_disconnect()
1397 spin_unlock_irqrestore(&port->port_lock, flags); in gserial_disconnect()