• Home
  • Raw
  • Download

Lines Matching refs:port

172 struct port {  struct
242 static struct port *find_port_by_vtermno(u32 vtermno) in find_port_by_vtermno() argument
244 struct port *port; in find_port_by_vtermno() local
251 port = container_of(cons, struct port, cons); in find_port_by_vtermno()
255 port = NULL; in find_port_by_vtermno()
258 return port; in find_port_by_vtermno()
261 static struct port *find_port_by_devt_in_portdev(struct ports_device *portdev, in find_port_by_devt_in_portdev()
264 struct port *port; in find_port_by_devt_in_portdev() local
268 list_for_each_entry(port, &portdev->ports, list) { in find_port_by_devt_in_portdev()
269 if (port->cdev->dev == dev) { in find_port_by_devt_in_portdev()
270 kref_get(&port->kref); in find_port_by_devt_in_portdev()
274 port = NULL; in find_port_by_devt_in_portdev()
278 return port; in find_port_by_devt_in_portdev()
281 static struct port *find_port_by_devt(dev_t dev) in find_port_by_devt()
284 struct port *port; in find_port_by_devt() local
289 port = find_port_by_devt_in_portdev(portdev, dev); in find_port_by_devt()
290 if (port) in find_port_by_devt()
293 port = NULL; in find_port_by_devt()
296 return port; in find_port_by_devt()
299 static struct port *find_port_by_id(struct ports_device *portdev, u32 id) in find_port_by_id()
301 struct port *port; in find_port_by_id() local
305 list_for_each_entry(port, &portdev->ports, list) in find_port_by_id()
306 if (port->id == id) in find_port_by_id()
308 port = NULL; in find_port_by_id()
312 return port; in find_port_by_id()
315 static struct port *find_port_by_vq(struct ports_device *portdev, in find_port_by_vq()
318 struct port *port; in find_port_by_vq() local
322 list_for_each_entry(port, &portdev->ports, list) in find_port_by_vq()
323 if (port->in_vq == vq || port->out_vq == vq) in find_port_by_vq()
325 port = NULL; in find_port_by_vq()
328 return port; in find_port_by_vq()
331 static bool is_console_port(struct port *port) in is_console_port() argument
333 if (port->cons.hvc) in is_console_port()
468 static struct port_buffer *get_inbuf(struct port *port) in get_inbuf() argument
473 if (port->inbuf) in get_inbuf()
474 return port->inbuf; in get_inbuf()
476 buf = virtqueue_get_buf(port->in_vq, &len); in get_inbuf()
480 port->stats.bytes_received += len; in get_inbuf()
506 static void discard_port_data(struct port *port) in discard_port_data() argument
511 if (!port->portdev) { in discard_port_data()
515 buf = get_inbuf(port); in discard_port_data()
519 port->stats.bytes_discarded += buf->len - buf->offset; in discard_port_data()
520 if (add_inbuf(port->in_vq, buf) < 0) { in discard_port_data()
524 port->inbuf = NULL; in discard_port_data()
525 buf = get_inbuf(port); in discard_port_data()
528 dev_warn(port->dev, "Errors adding %d buffers back to vq\n", in discard_port_data()
532 static bool port_has_data(struct port *port) in port_has_data() argument
538 spin_lock_irqsave(&port->inbuf_lock, flags); in port_has_data()
539 port->inbuf = get_inbuf(port); in port_has_data()
540 if (port->inbuf) in port_has_data()
543 spin_unlock_irqrestore(&port->inbuf_lock, flags); in port_has_data()
578 static ssize_t send_control_msg(struct port *port, unsigned int event, in send_control_msg() argument
582 if (port->portdev) in send_control_msg()
583 return __send_control_msg(port->portdev, port->id, event, value); in send_control_msg()
589 static void reclaim_consumed_buffers(struct port *port) in reclaim_consumed_buffers() argument
594 if (!port->portdev) { in reclaim_consumed_buffers()
598 while ((buf = virtqueue_get_buf(port->out_vq, &len))) { in reclaim_consumed_buffers()
600 port->outvq_full = false; in reclaim_consumed_buffers()
604 static ssize_t __send_to_port(struct port *port, struct scatterlist *sg, in __send_to_port() argument
613 out_vq = port->out_vq; in __send_to_port()
615 spin_lock_irqsave(&port->outvq_lock, flags); in __send_to_port()
617 reclaim_consumed_buffers(port); in __send_to_port()
630 port->outvq_full = true; in __send_to_port()
648 spin_unlock_irqrestore(&port->outvq_lock, flags); in __send_to_port()
650 port->stats.bytes_sent += in_count; in __send_to_port()
662 static ssize_t fill_readbuf(struct port *port, char __user *out_buf, in fill_readbuf() argument
668 if (!out_count || !port_has_data(port)) in fill_readbuf()
671 buf = port->inbuf; in fill_readbuf()
692 spin_lock_irqsave(&port->inbuf_lock, flags); in fill_readbuf()
693 port->inbuf = NULL; in fill_readbuf()
695 if (add_inbuf(port->in_vq, buf) < 0) in fill_readbuf()
696 dev_warn(port->dev, "failed add_buf\n"); in fill_readbuf()
698 spin_unlock_irqrestore(&port->inbuf_lock, flags); in fill_readbuf()
705 static bool will_read_block(struct port *port) in will_read_block() argument
707 if (!port->guest_connected) { in will_read_block()
711 return !port_has_data(port) && port->host_connected; in will_read_block()
714 static bool will_write_block(struct port *port) in will_write_block() argument
718 if (!port->guest_connected) { in will_write_block()
722 if (!port->host_connected) in will_write_block()
725 spin_lock_irq(&port->outvq_lock); in will_write_block()
730 reclaim_consumed_buffers(port); in will_write_block()
731 ret = port->outvq_full; in will_write_block()
732 spin_unlock_irq(&port->outvq_lock); in will_write_block()
740 struct port *port; in port_fops_read() local
743 port = filp->private_data; in port_fops_read()
746 if (!port->guest_connected) in port_fops_read()
749 if (!port_has_data(port)) { in port_fops_read()
755 if (!port->host_connected) in port_fops_read()
760 ret = wait_event_freezable(port->waitqueue, in port_fops_read()
761 !will_read_block(port)); in port_fops_read()
766 if (!port->guest_connected) in port_fops_read()
778 if (!port_has_data(port) && !port->host_connected) in port_fops_read()
781 return fill_readbuf(port, ubuf, count, true); in port_fops_read()
784 static int wait_port_writable(struct port *port, bool nonblock) in wait_port_writable() argument
788 if (will_write_block(port)) { in wait_port_writable()
792 ret = wait_event_freezable(port->waitqueue, in wait_port_writable()
793 !will_write_block(port)); in wait_port_writable()
798 if (!port->guest_connected) in wait_port_writable()
807 struct port *port; in port_fops_write() local
817 port = filp->private_data; in port_fops_write()
821 ret = wait_port_writable(port, nonblock); in port_fops_write()
827 buf = alloc_buf(port->portdev->vdev, count, 0); in port_fops_write()
846 ret = __send_to_port(port, sg, 1, count, buf, nonblock); in port_fops_write()
912 struct port *port = filp->private_data; in port_fops_splice_write() local
930 if (is_rproc_serial(port->out_vq->vdev)) in port_fops_splice_write()
938 ret = wait_port_writable(port, filp->f_flags & O_NONBLOCK); in port_fops_splice_write()
943 buf = alloc_buf(port->portdev->vdev, 0, occupancy); in port_fops_splice_write()
958 ret = __send_to_port(port, buf->sg, sgl.n, sgl.len, buf, true); in port_fops_splice_write()
971 struct port *port; in port_fops_poll() local
974 port = filp->private_data; in port_fops_poll()
975 poll_wait(filp, &port->waitqueue, wait); in port_fops_poll()
977 if (!port->guest_connected) { in port_fops_poll()
982 if (!will_read_block(port)) in port_fops_poll()
984 if (!will_write_block(port)) in port_fops_poll()
986 if (!port->host_connected) in port_fops_poll()
996 struct port *port; in port_fops_release() local
998 port = filp->private_data; in port_fops_release()
1001 send_control_msg(port, VIRTIO_CONSOLE_PORT_OPEN, 0); in port_fops_release()
1003 spin_lock_irq(&port->inbuf_lock); in port_fops_release()
1004 port->guest_connected = false; in port_fops_release()
1006 discard_port_data(port); in port_fops_release()
1008 spin_unlock_irq(&port->inbuf_lock); in port_fops_release()
1010 spin_lock_irq(&port->outvq_lock); in port_fops_release()
1011 reclaim_consumed_buffers(port); in port_fops_release()
1012 spin_unlock_irq(&port->outvq_lock); in port_fops_release()
1023 kref_put(&port->kref, remove_port); in port_fops_release()
1031 struct port *port; in port_fops_open() local
1035 port = find_port_by_devt(cdev->dev); in port_fops_open()
1036 if (!port) { in port_fops_open()
1040 filp->private_data = port; in port_fops_open()
1046 if (is_console_port(port)) { in port_fops_open()
1052 spin_lock_irq(&port->inbuf_lock); in port_fops_open()
1053 if (port->guest_connected) { in port_fops_open()
1054 spin_unlock_irq(&port->inbuf_lock); in port_fops_open()
1059 port->guest_connected = true; in port_fops_open()
1060 spin_unlock_irq(&port->inbuf_lock); in port_fops_open()
1062 spin_lock_irq(&port->outvq_lock); in port_fops_open()
1068 reclaim_consumed_buffers(port); in port_fops_open()
1069 spin_unlock_irq(&port->outvq_lock); in port_fops_open()
1078 kref_put(&port->kref, remove_port); in port_fops_open()
1084 struct port *port; in port_fops_fasync() local
1086 port = filp->private_data; in port_fops_fasync()
1087 return fasync_helper(fd, filp, mode, &port->async_queue); in port_fops_fasync()
1118 struct port *port; in put_chars() local
1126 port = find_port_by_vtermno(vtermno); in put_chars()
1127 if (!port) in put_chars()
1135 ret = __send_to_port(port, sg, 1, count, data, false); in put_chars()
1149 struct port *port; in get_chars() local
1155 port = find_port_by_vtermno(vtermno); in get_chars()
1156 if (!port) in get_chars()
1160 BUG_ON(!port->in_vq); in get_chars()
1162 return fill_readbuf(port, (__force char __user *)buf, count, false); in get_chars()
1165 static void resize_console(struct port *port) in resize_console() argument
1170 if (!port || !is_console_port(port)) in resize_console()
1173 vdev = port->portdev->vdev; in resize_console()
1178 hvc_resize(port->cons.hvc, port->cons.ws); in resize_console()
1184 struct port *port; in notifier_add_vio() local
1186 port = find_port_by_vtermno(hp->vtermno); in notifier_add_vio()
1187 if (!port) in notifier_add_vio()
1191 resize_console(port); in notifier_add_vio()
1225 static int init_port_console(struct port *port) in init_port_console() argument
1246 port->cons.vtermno = pdrvdata.next_vtermno; in init_port_console()
1248 port->cons.hvc = hvc_alloc(port->cons.vtermno, 0, &hv_ops, PAGE_SIZE); in init_port_console()
1249 if (IS_ERR(port->cons.hvc)) { in init_port_console()
1250 ret = PTR_ERR(port->cons.hvc); in init_port_console()
1251 dev_err(port->dev, in init_port_console()
1253 port->cons.hvc = NULL; in init_port_console()
1258 list_add_tail(&port->cons.list, &pdrvdata.consoles); in init_port_console()
1260 port->guest_connected = true; in init_port_console()
1270 send_control_msg(port, VIRTIO_CONSOLE_PORT_OPEN, 1); in init_port_console()
1278 struct port *port; in show_port_name() local
1280 port = dev_get_drvdata(dev); in show_port_name()
1282 return sprintf(buffer, "%s\n", port->name); in show_port_name()
1299 struct port *port = s->private; in port_debugfs_show() local
1301 seq_printf(s, "name: %s\n", port->name ? port->name : ""); in port_debugfs_show()
1302 seq_printf(s, "guest_connected: %d\n", port->guest_connected); in port_debugfs_show()
1303 seq_printf(s, "host_connected: %d\n", port->host_connected); in port_debugfs_show()
1304 seq_printf(s, "outvq_full: %d\n", port->outvq_full); in port_debugfs_show()
1305 seq_printf(s, "bytes_sent: %lu\n", port->stats.bytes_sent); in port_debugfs_show()
1306 seq_printf(s, "bytes_received: %lu\n", port->stats.bytes_received); in port_debugfs_show()
1307 seq_printf(s, "bytes_discarded: %lu\n", port->stats.bytes_discarded); in port_debugfs_show()
1309 is_console_port(port) ? "yes" : "no"); in port_debugfs_show()
1310 seq_printf(s, "console_vtermno: %u\n", port->cons.vtermno); in port_debugfs_show()
1317 static void set_console_size(struct port *port, u16 rows, u16 cols) in set_console_size() argument
1319 if (!port || !is_console_port(port)) in set_console_size()
1322 port->cons.ws.ws_row = rows; in set_console_size()
1323 port->cons.ws.ws_col = cols; in set_console_size()
1352 static void send_sigio_to_port(struct port *port) in send_sigio_to_port() argument
1354 if (port->async_queue && port->guest_connected) in send_sigio_to_port()
1355 kill_fasync(&port->async_queue, SIGIO, POLL_OUT); in send_sigio_to_port()
1361 struct port *port; in add_port() local
1365 port = kmalloc(sizeof(*port), GFP_KERNEL); in add_port()
1366 if (!port) { in add_port()
1370 kref_init(&port->kref); in add_port()
1372 port->portdev = portdev; in add_port()
1373 port->id = id; in add_port()
1375 port->name = NULL; in add_port()
1376 port->inbuf = NULL; in add_port()
1377 port->cons.hvc = NULL; in add_port()
1378 port->async_queue = NULL; in add_port()
1380 port->cons.ws.ws_row = port->cons.ws.ws_col = 0; in add_port()
1381 port->cons.vtermno = 0; in add_port()
1383 port->host_connected = port->guest_connected = false; in add_port()
1384 port->stats = (struct port_stats) { 0 }; in add_port()
1386 port->outvq_full = false; in add_port()
1388 port->in_vq = portdev->in_vqs[port->id]; in add_port()
1389 port->out_vq = portdev->out_vqs[port->id]; in add_port()
1391 port->cdev = cdev_alloc(); in add_port()
1392 if (!port->cdev) { in add_port()
1393 dev_err(&port->portdev->vdev->dev, "Error allocating cdev\n"); in add_port()
1397 port->cdev->ops = &port_fops; in add_port()
1400 err = cdev_add(port->cdev, devt, 1); in add_port()
1402 dev_err(&port->portdev->vdev->dev, in add_port()
1406 port->dev = device_create(pdrvdata.class, &port->portdev->vdev->dev, in add_port()
1407 devt, port, "vport%up%u", in add_port()
1408 port->portdev->vdev->index, id); in add_port()
1409 if (IS_ERR(port->dev)) { in add_port()
1410 err = PTR_ERR(port->dev); in add_port()
1411 dev_err(&port->portdev->vdev->dev, in add_port()
1417 spin_lock_init(&port->inbuf_lock); in add_port()
1418 spin_lock_init(&port->outvq_lock); in add_port()
1419 init_waitqueue_head(&port->waitqueue); in add_port()
1425 err = fill_queue(port->in_vq, &port->inbuf_lock); in add_port()
1427 dev_err(port->dev, "Error allocating inbufs\n"); in add_port()
1431 if (is_rproc_serial(port->portdev->vdev)) in add_port()
1437 port->host_connected = true; in add_port()
1438 else if (!use_multiport(port->portdev)) { in add_port()
1443 err = init_port_console(port); in add_port()
1449 list_add_tail(&port->list, &port->portdev->ports); in add_port()
1457 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, in add_port()
1475 device_destroy(pdrvdata.class, port->dev->devt); in add_port()
1477 cdev_del(port->cdev); in add_port()
1479 kfree(port); in add_port()
1489 struct port *port; in remove_port() local
1491 port = container_of(kref, struct port, kref); in remove_port()
1493 kfree(port); in remove_port()
1496 static void remove_port_data(struct port *port) in remove_port_data() argument
1498 spin_lock_irq(&port->inbuf_lock); in remove_port_data()
1500 discard_port_data(port); in remove_port_data()
1501 spin_unlock_irq(&port->inbuf_lock); in remove_port_data()
1503 spin_lock_irq(&port->outvq_lock); in remove_port_data()
1504 reclaim_consumed_buffers(port); in remove_port_data()
1505 spin_unlock_irq(&port->outvq_lock); in remove_port_data()
1513 static void unplug_port(struct port *port) in unplug_port() argument
1515 spin_lock_irq(&port->portdev->ports_lock); in unplug_port()
1516 list_del(&port->list); in unplug_port()
1517 spin_unlock_irq(&port->portdev->ports_lock); in unplug_port()
1519 spin_lock_irq(&port->inbuf_lock); in unplug_port()
1520 if (port->guest_connected) { in unplug_port()
1522 send_sigio_to_port(port); in unplug_port()
1525 port->guest_connected = false; in unplug_port()
1526 port->host_connected = false; in unplug_port()
1528 wake_up_interruptible(&port->waitqueue); in unplug_port()
1530 spin_unlock_irq(&port->inbuf_lock); in unplug_port()
1532 if (is_console_port(port)) { in unplug_port()
1534 list_del(&port->cons.list); in unplug_port()
1536 hvc_remove(port->cons.hvc); in unplug_port()
1539 remove_port_data(port); in unplug_port()
1546 port->portdev = NULL; in unplug_port()
1548 sysfs_remove_group(&port->dev->kobj, &port_attribute_group); in unplug_port()
1549 device_destroy(pdrvdata.class, port->dev->devt); in unplug_port()
1550 cdev_del(port->cdev); in unplug_port()
1552 debugfs_remove(port->debugfs_file); in unplug_port()
1553 kfree(port->name); in unplug_port()
1560 kref_put(&port->kref, remove_port); in unplug_port()
1569 struct port *port; in handle_control_message() local
1575 port = find_port_by_id(portdev, virtio32_to_cpu(vdev, cpkt->id)); in handle_control_message()
1576 if (!port && in handle_control_message()
1586 if (port) { in handle_control_message()
1588 "Port %u already added\n", port->id); in handle_control_message()
1589 send_control_msg(port, VIRTIO_CONSOLE_PORT_READY, 1); in handle_control_message()
1603 unplug_port(port); in handle_control_message()
1608 if (is_console_port(port)) in handle_control_message()
1611 init_port_console(port); in handle_control_message()
1624 if (!is_console_port(port)) in handle_control_message()
1629 set_console_size(port, size.rows, size.cols); in handle_control_message()
1631 port->cons.hvc->irq_requested = 1; in handle_control_message()
1632 resize_console(port); in handle_control_message()
1636 port->host_connected = virtio16_to_cpu(vdev, cpkt->value); in handle_control_message()
1637 wake_up_interruptible(&port->waitqueue); in handle_control_message()
1643 spin_lock_irq(&port->outvq_lock); in handle_control_message()
1644 reclaim_consumed_buffers(port); in handle_control_message()
1645 spin_unlock_irq(&port->outvq_lock); in handle_control_message()
1651 spin_lock_irq(&port->inbuf_lock); in handle_control_message()
1652 send_sigio_to_port(port); in handle_control_message()
1653 spin_unlock_irq(&port->inbuf_lock); in handle_control_message()
1660 if (port->name) in handle_control_message()
1669 port->name = kmalloc(name_size, GFP_KERNEL); in handle_control_message()
1670 if (!port->name) { in handle_control_message()
1671 dev_err(port->dev, in handle_control_message()
1675 strncpy(port->name, buf->buf + buf->offset + sizeof(*cpkt), in handle_control_message()
1677 port->name[name_size - 1] = 0; in handle_control_message()
1683 err = sysfs_create_group(&port->dev->kobj, in handle_control_message()
1686 dev_err(port->dev, in handle_control_message()
1695 kobject_uevent(&port->dev->kobj, KOBJ_CHANGE); in handle_control_message()
1741 struct port *port; in out_intr() local
1743 port = find_port_by_vq(vq->vdev->priv, vq); in out_intr()
1744 if (!port) { in out_intr()
1749 wake_up_interruptible(&port->waitqueue); in out_intr()
1754 struct port *port; in in_intr() local
1757 port = find_port_by_vq(vq->vdev->priv, vq); in in_intr()
1758 if (!port) { in in_intr()
1763 spin_lock_irqsave(&port->inbuf_lock, flags); in in_intr()
1764 port->inbuf = get_inbuf(port); in in_intr()
1783 if (!port->guest_connected && !is_rproc_serial(port->portdev->vdev)) in in_intr()
1784 discard_port_data(port); in in_intr()
1787 send_sigio_to_port(port); in in_intr()
1789 spin_unlock_irqrestore(&port->inbuf_lock, flags); in in_intr()
1791 wake_up_interruptible(&port->waitqueue); in in_intr()
1793 if (is_console_port(port) && hvc_poll(port->cons.hvc)) in in_intr()
1822 struct port *port; in config_work_handler() local
1829 port = find_port_by_id(portdev, 0); in config_work_handler()
1830 set_console_size(port, rows, cols); in config_work_handler()
1839 resize_console(port); in config_work_handler()
1954 struct port *port, *port2; in virtcons_remove() local
1977 list_for_each_entry_safe(port, port2, &portdev->ports, list) in virtcons_remove()
1978 unplug_port(port); in virtcons_remove()
2148 struct port *port; in virtcons_freeze() local
2165 list_for_each_entry(port, &portdev->ports, list) { in virtcons_freeze()
2166 virtqueue_disable_cb(port->in_vq); in virtcons_freeze()
2167 virtqueue_disable_cb(port->out_vq); in virtcons_freeze()
2172 port->host_connected = false; in virtcons_freeze()
2173 remove_port_data(port); in virtcons_freeze()
2183 struct port *port; in virtcons_restore() local
2197 list_for_each_entry(port, &portdev->ports, list) { in virtcons_restore()
2198 port->in_vq = portdev->in_vqs[port->id]; in virtcons_restore()
2199 port->out_vq = portdev->out_vqs[port->id]; in virtcons_restore()
2201 fill_queue(port->in_vq, &port->inbuf_lock); in virtcons_restore()
2204 send_control_msg(port, VIRTIO_CONSOLE_PORT_READY, 1); in virtcons_restore()
2210 if (port->guest_connected) in virtcons_restore()
2211 send_control_msg(port, VIRTIO_CONSOLE_PORT_OPEN, 1); in virtcons_restore()