Lines Matching refs:port

173 struct port {  struct
243 static struct port *find_port_by_vtermno(u32 vtermno) in find_port_by_vtermno() argument
245 struct port *port; in find_port_by_vtermno() local
252 port = container_of(cons, struct port, cons); in find_port_by_vtermno()
256 port = NULL; in find_port_by_vtermno()
259 return port; in find_port_by_vtermno()
262 static struct port *find_port_by_devt_in_portdev(struct ports_device *portdev, in find_port_by_devt_in_portdev()
265 struct port *port; in find_port_by_devt_in_portdev() local
269 list_for_each_entry(port, &portdev->ports, list) { in find_port_by_devt_in_portdev()
270 if (port->cdev->dev == dev) { in find_port_by_devt_in_portdev()
271 kref_get(&port->kref); in find_port_by_devt_in_portdev()
275 port = NULL; in find_port_by_devt_in_portdev()
279 return port; in find_port_by_devt_in_portdev()
282 static struct port *find_port_by_devt(dev_t dev) in find_port_by_devt()
285 struct port *port; in find_port_by_devt() local
290 port = find_port_by_devt_in_portdev(portdev, dev); in find_port_by_devt()
291 if (port) in find_port_by_devt()
294 port = NULL; in find_port_by_devt()
297 return port; in find_port_by_devt()
300 static struct port *find_port_by_id(struct ports_device *portdev, u32 id) in find_port_by_id()
302 struct port *port; in find_port_by_id() local
306 list_for_each_entry(port, &portdev->ports, list) in find_port_by_id()
307 if (port->id == id) in find_port_by_id()
309 port = NULL; in find_port_by_id()
313 return port; in find_port_by_id()
316 static struct port *find_port_by_vq(struct ports_device *portdev, in find_port_by_vq()
319 struct port *port; in find_port_by_vq() local
323 list_for_each_entry(port, &portdev->ports, list) in find_port_by_vq()
324 if (port->in_vq == vq || port->out_vq == vq) in find_port_by_vq()
326 port = NULL; in find_port_by_vq()
329 return port; in find_port_by_vq()
332 static bool is_console_port(struct port *port) in is_console_port() argument
334 if (port->cons.hvc) in is_console_port()
469 static struct port_buffer *get_inbuf(struct port *port) in get_inbuf() argument
474 if (port->inbuf) in get_inbuf()
475 return port->inbuf; in get_inbuf()
477 buf = virtqueue_get_buf(port->in_vq, &len); in get_inbuf()
481 port->stats.bytes_received += len; in get_inbuf()
507 static void discard_port_data(struct port *port) in discard_port_data() argument
512 if (!port->portdev) { in discard_port_data()
516 buf = get_inbuf(port); in discard_port_data()
520 port->stats.bytes_discarded += buf->len - buf->offset; in discard_port_data()
521 if (add_inbuf(port->in_vq, buf) < 0) { in discard_port_data()
525 port->inbuf = NULL; in discard_port_data()
526 buf = get_inbuf(port); in discard_port_data()
529 dev_warn(port->dev, "Errors adding %d buffers back to vq\n", in discard_port_data()
533 static bool port_has_data(struct port *port) in port_has_data() argument
539 spin_lock_irqsave(&port->inbuf_lock, flags); in port_has_data()
540 port->inbuf = get_inbuf(port); in port_has_data()
541 if (port->inbuf) in port_has_data()
544 spin_unlock_irqrestore(&port->inbuf_lock, flags); in port_has_data()
579 static ssize_t send_control_msg(struct port *port, unsigned int event, in send_control_msg() argument
583 if (port->portdev) in send_control_msg()
584 return __send_control_msg(port->portdev, port->id, event, value); in send_control_msg()
590 static void reclaim_consumed_buffers(struct port *port) in reclaim_consumed_buffers() argument
595 if (!port->portdev) { in reclaim_consumed_buffers()
599 while ((buf = virtqueue_get_buf(port->out_vq, &len))) { in reclaim_consumed_buffers()
601 port->outvq_full = false; in reclaim_consumed_buffers()
605 static ssize_t __send_to_port(struct port *port, struct scatterlist *sg, in __send_to_port() argument
614 out_vq = port->out_vq; in __send_to_port()
616 spin_lock_irqsave(&port->outvq_lock, flags); in __send_to_port()
618 reclaim_consumed_buffers(port); in __send_to_port()
631 port->outvq_full = true; in __send_to_port()
649 spin_unlock_irqrestore(&port->outvq_lock, flags); in __send_to_port()
651 port->stats.bytes_sent += in_count; in __send_to_port()
663 static ssize_t fill_readbuf(struct port *port, char __user *out_buf, in fill_readbuf() argument
669 if (!out_count || !port_has_data(port)) in fill_readbuf()
672 buf = port->inbuf; in fill_readbuf()
693 spin_lock_irqsave(&port->inbuf_lock, flags); in fill_readbuf()
694 port->inbuf = NULL; in fill_readbuf()
696 if (add_inbuf(port->in_vq, buf) < 0) in fill_readbuf()
697 dev_warn(port->dev, "failed add_buf\n"); in fill_readbuf()
699 spin_unlock_irqrestore(&port->inbuf_lock, flags); in fill_readbuf()
706 static bool will_read_block(struct port *port) in will_read_block() argument
708 if (!port->guest_connected) { in will_read_block()
712 return !port_has_data(port) && port->host_connected; in will_read_block()
715 static bool will_write_block(struct port *port) in will_write_block() argument
719 if (!port->guest_connected) { in will_write_block()
723 if (!port->host_connected) in will_write_block()
726 spin_lock_irq(&port->outvq_lock); in will_write_block()
731 reclaim_consumed_buffers(port); in will_write_block()
732 ret = port->outvq_full; in will_write_block()
733 spin_unlock_irq(&port->outvq_lock); in will_write_block()
741 struct port *port; in port_fops_read() local
744 port = filp->private_data; in port_fops_read()
747 if (!port->guest_connected) in port_fops_read()
750 if (!port_has_data(port)) { in port_fops_read()
756 if (!port->host_connected) in port_fops_read()
761 ret = wait_event_freezable(port->waitqueue, in port_fops_read()
762 !will_read_block(port)); in port_fops_read()
767 if (!port->guest_connected) in port_fops_read()
779 if (!port_has_data(port) && !port->host_connected) in port_fops_read()
782 return fill_readbuf(port, ubuf, count, true); in port_fops_read()
785 static int wait_port_writable(struct port *port, bool nonblock) in wait_port_writable() argument
789 if (will_write_block(port)) { in wait_port_writable()
793 ret = wait_event_freezable(port->waitqueue, in wait_port_writable()
794 !will_write_block(port)); in wait_port_writable()
799 if (!port->guest_connected) in wait_port_writable()
808 struct port *port; in port_fops_write() local
818 port = filp->private_data; in port_fops_write()
822 ret = wait_port_writable(port, nonblock); in port_fops_write()
828 buf = alloc_buf(port->portdev->vdev, count, 0); in port_fops_write()
847 ret = __send_to_port(port, sg, 1, count, buf, nonblock); in port_fops_write()
913 struct port *port = filp->private_data; in port_fops_splice_write() local
931 if (is_rproc_serial(port->out_vq->vdev)) in port_fops_splice_write()
939 ret = wait_port_writable(port, filp->f_flags & O_NONBLOCK); in port_fops_splice_write()
944 buf = alloc_buf(port->portdev->vdev, 0, occupancy); in port_fops_splice_write()
959 ret = __send_to_port(port, buf->sg, sgl.n, sgl.len, buf, true); in port_fops_splice_write()
972 struct port *port; in port_fops_poll() local
975 port = filp->private_data; in port_fops_poll()
976 poll_wait(filp, &port->waitqueue, wait); in port_fops_poll()
978 if (!port->guest_connected) { in port_fops_poll()
983 if (!will_read_block(port)) in port_fops_poll()
985 if (!will_write_block(port)) in port_fops_poll()
987 if (!port->host_connected) in port_fops_poll()
997 struct port *port; in port_fops_release() local
999 port = filp->private_data; in port_fops_release()
1002 send_control_msg(port, VIRTIO_CONSOLE_PORT_OPEN, 0); in port_fops_release()
1004 spin_lock_irq(&port->inbuf_lock); in port_fops_release()
1005 port->guest_connected = false; in port_fops_release()
1007 discard_port_data(port); in port_fops_release()
1009 spin_unlock_irq(&port->inbuf_lock); in port_fops_release()
1011 spin_lock_irq(&port->outvq_lock); in port_fops_release()
1012 reclaim_consumed_buffers(port); in port_fops_release()
1013 spin_unlock_irq(&port->outvq_lock); in port_fops_release()
1024 kref_put(&port->kref, remove_port); in port_fops_release()
1032 struct port *port; in port_fops_open() local
1036 port = find_port_by_devt(cdev->dev); in port_fops_open()
1037 if (!port) { in port_fops_open()
1041 filp->private_data = port; in port_fops_open()
1047 if (is_console_port(port)) { in port_fops_open()
1053 spin_lock_irq(&port->inbuf_lock); in port_fops_open()
1054 if (port->guest_connected) { in port_fops_open()
1055 spin_unlock_irq(&port->inbuf_lock); in port_fops_open()
1060 port->guest_connected = true; in port_fops_open()
1061 spin_unlock_irq(&port->inbuf_lock); in port_fops_open()
1063 spin_lock_irq(&port->outvq_lock); in port_fops_open()
1069 reclaim_consumed_buffers(port); in port_fops_open()
1070 spin_unlock_irq(&port->outvq_lock); in port_fops_open()
1079 kref_put(&port->kref, remove_port); in port_fops_open()
1085 struct port *port; in port_fops_fasync() local
1087 port = filp->private_data; in port_fops_fasync()
1088 return fasync_helper(fd, filp, mode, &port->async_queue); in port_fops_fasync()
1119 struct port *port; in put_chars() local
1127 port = find_port_by_vtermno(vtermno); in put_chars()
1128 if (!port) in put_chars()
1136 ret = __send_to_port(port, sg, 1, count, data, false); in put_chars()
1150 struct port *port; in get_chars() local
1156 port = find_port_by_vtermno(vtermno); in get_chars()
1157 if (!port) in get_chars()
1161 BUG_ON(!port->in_vq); in get_chars()
1163 return fill_readbuf(port, (__force char __user *)buf, count, false); in get_chars()
1166 static void resize_console(struct port *port) in resize_console() argument
1171 if (!port || !is_console_port(port)) in resize_console()
1174 vdev = port->portdev->vdev; in resize_console()
1179 hvc_resize(port->cons.hvc, port->cons.ws); in resize_console()
1185 struct port *port; in notifier_add_vio() local
1187 port = find_port_by_vtermno(hp->vtermno); in notifier_add_vio()
1188 if (!port) in notifier_add_vio()
1192 resize_console(port); in notifier_add_vio()
1226 static int init_port_console(struct port *port) in init_port_console() argument
1247 port->cons.vtermno = pdrvdata.next_vtermno; in init_port_console()
1249 port->cons.hvc = hvc_alloc(port->cons.vtermno, 0, &hv_ops, PAGE_SIZE); in init_port_console()
1250 if (IS_ERR(port->cons.hvc)) { in init_port_console()
1251 ret = PTR_ERR(port->cons.hvc); in init_port_console()
1252 dev_err(port->dev, in init_port_console()
1254 port->cons.hvc = NULL; in init_port_console()
1259 list_add_tail(&port->cons.list, &pdrvdata.consoles); in init_port_console()
1261 port->guest_connected = true; in init_port_console()
1271 send_control_msg(port, VIRTIO_CONSOLE_PORT_OPEN, 1); in init_port_console()
1279 struct port *port; in show_port_name() local
1281 port = dev_get_drvdata(dev); in show_port_name()
1283 return sprintf(buffer, "%s\n", port->name); in show_port_name()
1300 struct port *port = s->private; in port_debugfs_show() local
1302 seq_printf(s, "name: %s\n", port->name ? port->name : ""); in port_debugfs_show()
1303 seq_printf(s, "guest_connected: %d\n", port->guest_connected); in port_debugfs_show()
1304 seq_printf(s, "host_connected: %d\n", port->host_connected); in port_debugfs_show()
1305 seq_printf(s, "outvq_full: %d\n", port->outvq_full); in port_debugfs_show()
1306 seq_printf(s, "bytes_sent: %lu\n", port->stats.bytes_sent); in port_debugfs_show()
1307 seq_printf(s, "bytes_received: %lu\n", port->stats.bytes_received); in port_debugfs_show()
1308 seq_printf(s, "bytes_discarded: %lu\n", port->stats.bytes_discarded); in port_debugfs_show()
1310 is_console_port(port) ? "yes" : "no"); in port_debugfs_show()
1311 seq_printf(s, "console_vtermno: %u\n", port->cons.vtermno); in port_debugfs_show()
1318 static void set_console_size(struct port *port, u16 rows, u16 cols) in set_console_size() argument
1320 if (!port || !is_console_port(port)) in set_console_size()
1323 port->cons.ws.ws_row = rows; in set_console_size()
1324 port->cons.ws.ws_col = cols; in set_console_size()
1353 static void send_sigio_to_port(struct port *port) in send_sigio_to_port() argument
1355 if (port->async_queue && port->guest_connected) in send_sigio_to_port()
1356 kill_fasync(&port->async_queue, SIGIO, POLL_OUT); in send_sigio_to_port()
1362 struct port *port; in add_port() local
1366 port = kmalloc(sizeof(*port), GFP_KERNEL); in add_port()
1367 if (!port) { in add_port()
1371 kref_init(&port->kref); in add_port()
1373 port->portdev = portdev; in add_port()
1374 port->id = id; in add_port()
1376 port->name = NULL; in add_port()
1377 port->inbuf = NULL; in add_port()
1378 port->cons.hvc = NULL; in add_port()
1379 port->async_queue = NULL; in add_port()
1381 port->cons.ws.ws_row = port->cons.ws.ws_col = 0; in add_port()
1382 port->cons.vtermno = 0; in add_port()
1384 port->host_connected = port->guest_connected = false; in add_port()
1385 port->stats = (struct port_stats) { 0 }; in add_port()
1387 port->outvq_full = false; in add_port()
1389 port->in_vq = portdev->in_vqs[port->id]; in add_port()
1390 port->out_vq = portdev->out_vqs[port->id]; in add_port()
1392 port->cdev = cdev_alloc(); in add_port()
1393 if (!port->cdev) { in add_port()
1394 dev_err(&port->portdev->vdev->dev, "Error allocating cdev\n"); in add_port()
1398 port->cdev->ops = &port_fops; in add_port()
1401 err = cdev_add(port->cdev, devt, 1); in add_port()
1403 dev_err(&port->portdev->vdev->dev, in add_port()
1407 port->dev = device_create(pdrvdata.class, &port->portdev->vdev->dev, in add_port()
1408 devt, port, "vport%up%u", in add_port()
1409 port->portdev->vdev->index, id); in add_port()
1410 if (IS_ERR(port->dev)) { in add_port()
1411 err = PTR_ERR(port->dev); in add_port()
1412 dev_err(&port->portdev->vdev->dev, in add_port()
1418 spin_lock_init(&port->inbuf_lock); in add_port()
1419 spin_lock_init(&port->outvq_lock); in add_port()
1420 init_waitqueue_head(&port->waitqueue); in add_port()
1426 err = fill_queue(port->in_vq, &port->inbuf_lock); in add_port()
1428 dev_err(port->dev, "Error allocating inbufs\n"); in add_port()
1432 if (is_rproc_serial(port->portdev->vdev)) in add_port()
1438 port->host_connected = true; in add_port()
1439 else if (!use_multiport(port->portdev)) { in add_port()
1444 err = init_port_console(port); in add_port()
1450 list_add_tail(&port->list, &port->portdev->ports); in add_port()
1458 send_control_msg(port, VIRTIO_CONSOLE_PORT_READY, 1); in add_port()
1465 port->portdev->vdev->index, id); in add_port()
1466 port->debugfs_file = debugfs_create_file(debugfs_name, 0444, in add_port()
1468 port, &port_debugfs_fops); in add_port()
1473 device_destroy(pdrvdata.class, port->dev->devt); in add_port()
1475 cdev_del(port->cdev); in add_port()
1477 kfree(port); in add_port()
1487 struct port *port; in remove_port() local
1489 port = container_of(kref, struct port, kref); in remove_port()
1491 kfree(port); in remove_port()
1494 static void remove_port_data(struct port *port) in remove_port_data() argument
1496 spin_lock_irq(&port->inbuf_lock); in remove_port_data()
1498 discard_port_data(port); in remove_port_data()
1499 spin_unlock_irq(&port->inbuf_lock); in remove_port_data()
1501 spin_lock_irq(&port->outvq_lock); in remove_port_data()
1502 reclaim_consumed_buffers(port); in remove_port_data()
1503 spin_unlock_irq(&port->outvq_lock); in remove_port_data()
1511 static void unplug_port(struct port *port) in unplug_port() argument
1513 spin_lock_irq(&port->portdev->ports_lock); in unplug_port()
1514 list_del(&port->list); in unplug_port()
1515 spin_unlock_irq(&port->portdev->ports_lock); in unplug_port()
1517 spin_lock_irq(&port->inbuf_lock); in unplug_port()
1518 if (port->guest_connected) { in unplug_port()
1520 send_sigio_to_port(port); in unplug_port()
1523 port->guest_connected = false; in unplug_port()
1524 port->host_connected = false; in unplug_port()
1526 wake_up_interruptible(&port->waitqueue); in unplug_port()
1528 spin_unlock_irq(&port->inbuf_lock); in unplug_port()
1530 if (is_console_port(port)) { in unplug_port()
1532 list_del(&port->cons.list); in unplug_port()
1534 hvc_remove(port->cons.hvc); in unplug_port()
1537 remove_port_data(port); in unplug_port()
1544 port->portdev = NULL; in unplug_port()
1546 sysfs_remove_group(&port->dev->kobj, &port_attribute_group); in unplug_port()
1547 device_destroy(pdrvdata.class, port->dev->devt); in unplug_port()
1548 cdev_del(port->cdev); in unplug_port()
1550 debugfs_remove(port->debugfs_file); in unplug_port()
1551 kfree(port->name); in unplug_port()
1558 kref_put(&port->kref, remove_port); in unplug_port()
1567 struct port *port; in handle_control_message() local
1573 port = find_port_by_id(portdev, virtio32_to_cpu(vdev, cpkt->id)); in handle_control_message()
1574 if (!port && in handle_control_message()
1584 if (port) { in handle_control_message()
1586 "Port %u already added\n", port->id); in handle_control_message()
1587 send_control_msg(port, VIRTIO_CONSOLE_PORT_READY, 1); in handle_control_message()
1601 unplug_port(port); in handle_control_message()
1606 if (is_console_port(port)) in handle_control_message()
1609 init_port_console(port); in handle_control_message()
1622 if (!is_console_port(port)) in handle_control_message()
1627 set_console_size(port, size.rows, size.cols); in handle_control_message()
1629 port->cons.hvc->irq_requested = 1; in handle_control_message()
1630 resize_console(port); in handle_control_message()
1634 port->host_connected = virtio16_to_cpu(vdev, cpkt->value); in handle_control_message()
1635 wake_up_interruptible(&port->waitqueue); in handle_control_message()
1641 spin_lock_irq(&port->outvq_lock); in handle_control_message()
1642 reclaim_consumed_buffers(port); in handle_control_message()
1643 spin_unlock_irq(&port->outvq_lock); in handle_control_message()
1649 spin_lock_irq(&port->inbuf_lock); in handle_control_message()
1650 send_sigio_to_port(port); in handle_control_message()
1651 spin_unlock_irq(&port->inbuf_lock); in handle_control_message()
1658 if (port->name) in handle_control_message()
1667 port->name = kmalloc(name_size, GFP_KERNEL); in handle_control_message()
1668 if (!port->name) { in handle_control_message()
1669 dev_err(port->dev, in handle_control_message()
1673 strncpy(port->name, buf->buf + buf->offset + sizeof(*cpkt), in handle_control_message()
1675 port->name[name_size - 1] = 0; in handle_control_message()
1681 err = sysfs_create_group(&port->dev->kobj, in handle_control_message()
1684 dev_err(port->dev, in handle_control_message()
1693 kobject_uevent(&port->dev->kobj, KOBJ_CHANGE); in handle_control_message()
1739 struct port *port; in out_intr() local
1741 port = find_port_by_vq(vq->vdev->priv, vq); in out_intr()
1742 if (!port) { in out_intr()
1747 wake_up_interruptible(&port->waitqueue); in out_intr()
1752 struct port *port; in in_intr() local
1755 port = find_port_by_vq(vq->vdev->priv, vq); in in_intr()
1756 if (!port) { in in_intr()
1761 spin_lock_irqsave(&port->inbuf_lock, flags); in in_intr()
1762 port->inbuf = get_inbuf(port); in in_intr()
1781 if (!port->guest_connected && !is_rproc_serial(port->portdev->vdev)) in in_intr()
1782 discard_port_data(port); in in_intr()
1785 send_sigio_to_port(port); in in_intr()
1787 spin_unlock_irqrestore(&port->inbuf_lock, flags); in in_intr()
1789 wake_up_interruptible(&port->waitqueue); in in_intr()
1791 if (is_console_port(port) && hvc_poll(port->cons.hvc)) in in_intr()
1820 struct port *port; in config_work_handler() local
1827 port = find_port_by_id(portdev, 0); in config_work_handler()
1828 set_console_size(port, rows, cols); in config_work_handler()
1837 resize_console(port); in config_work_handler()
1952 struct port *port, *port2; in virtcons_remove() local
1975 list_for_each_entry_safe(port, port2, &portdev->ports, list) in virtcons_remove()
1976 unplug_port(port); in virtcons_remove()
2154 struct port *port; in virtcons_freeze() local
2171 list_for_each_entry(port, &portdev->ports, list) { in virtcons_freeze()
2172 virtqueue_disable_cb(port->in_vq); in virtcons_freeze()
2173 virtqueue_disable_cb(port->out_vq); in virtcons_freeze()
2178 port->host_connected = false; in virtcons_freeze()
2179 remove_port_data(port); in virtcons_freeze()
2189 struct port *port; in virtcons_restore() local
2203 list_for_each_entry(port, &portdev->ports, list) { in virtcons_restore()
2204 port->in_vq = portdev->in_vqs[port->id]; in virtcons_restore()
2205 port->out_vq = portdev->out_vqs[port->id]; in virtcons_restore()
2207 fill_queue(port->in_vq, &port->inbuf_lock); in virtcons_restore()
2210 send_control_msg(port, VIRTIO_CONSOLE_PORT_READY, 1); in virtcons_restore()
2216 if (port->guest_connected) in virtcons_restore()
2217 send_control_msg(port, VIRTIO_CONSOLE_PORT_OPEN, 1); in virtcons_restore()