summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr/src/uts/common/Makefile.files3
-rw-r--r--usr/src/uts/common/Makefile.rules6
-rw-r--r--usr/src/uts/common/io/vsock/vsock_vio.c102
-rw-r--r--usr/src/uts/common/io/vsock/vsock_vio.h84
4 files changed, 194 insertions, 1 deletions
diff --git a/usr/src/uts/common/Makefile.files b/usr/src/uts/common/Makefile.files
index 4aa4a03310..4075f7952d 100644
--- a/usr/src/uts/common/Makefile.files
+++ b/usr/src/uts/common/Makefile.files
@@ -2133,6 +2133,9 @@ VIOBLK_OBJS = vioblk.o
# Virtio network driver
VIOIF_OBJS = vioif.o
+# Virtio transport for AF_VSOCK
+VSOCK_VIO_OBJS = vsock_vio.o
+
#
# kiconv modules
#
diff --git a/usr/src/uts/common/Makefile.rules b/usr/src/uts/common/Makefile.rules
index c103d6a591..9038019ab3 100644
--- a/usr/src/uts/common/Makefile.rules
+++ b/usr/src/uts/common/Makefile.rules
@@ -23,7 +23,7 @@
# Copyright (c) 1991, 2010, Oracle and/or its affiliates. All rights reserved.
# Copyright 2016 Garrett D'Amore <garrett@damore.org>
# Copyright 2013 Saso Kiselkov. All rights reserved.
-# Copyright 2020 Joyent, Inc.
+# Copyright 2021 Joyent, Inc.
# Copyright 2018 Nexenta Systems, Inc.
# Copyright (c) 2017 by Delphix. All rights reserved.
# Copyright 2020 Oxide Computer Company
@@ -1548,6 +1548,10 @@ $(OBJS_DIR)/%.o: $(UTSBASE)/common/io/vioif/%.c
$(COMPILE.c) -o $@ $<
$(CTFCONVERT_O)
+$(OBJS_DIR)/%.o: $(UTSBASE)/common/io/vsock/%.c
+ $(COMPILE.c) -o $@ $<
+ $(CTFCONVERT_O)
+
#
# krtld must refer to its own bzero/bcopy until the kernel is fully linked
#
diff --git a/usr/src/uts/common/io/vsock/vsock_vio.c b/usr/src/uts/common/io/vsock/vsock_vio.c
new file mode 100644
index 0000000000..be20e95677
--- /dev/null
+++ b/usr/src/uts/common/io/vsock/vsock_vio.c
@@ -0,0 +1,102 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2021 Joyent, Inc.
+ */
+
+/*
+ * AF_VSOCK VIRTIO TRANSPORT
+ */
+
+#include <sys/stropts.h>
+#include <sys/stream.h>
+#include <sys/strsubr.h>
+#include <sys/modctl.h>
+#include <sys/strsun.h>
+
+#include "virtio.h"
+#include "vsock.h"
+
+static struct cb_ops vsock_vio_cb_ops = {
+ .cb_rev CB_REV,
+ .cb_flags = D_MP | D_NEW,
+
+ .cb_open = nulldev,
+ .cb_close = nulldev,
+ .cb_strategy = nodev,
+ .cb_print = nodev,
+ .cb_dump = nodev,
+ .cb_read = nodev,
+ .cb_write = nodev,
+ .cb_ioctl = nodev,
+ .cb_devmap = nodev,
+ .cb_mmap = nodev,
+ .cb_segmap = nodev,
+ .cb_chpoll = nochpoll,
+ .cb_prop_op = ddi_prop_op,
+ .cb_str = NULL,
+ .cb_aread = nodev,
+ .cb_awrite = nodev,
+};
+
+statuc struct dev_ops vsock_vio_dev_ops = {
+ .devo_rev = DEVO_REV,
+ .devo_refcnt = 0,
+
+ .devo_attach = vsock_vio_attach,
+ .devo_detach = vsock_vio_detach,
+ .devo_quiesce = vsock_vio_quiesce,
+
+ .devo_cb_ops = &vsock_vio_cb_ops,
+
+ .devo_getinfo = NULL,
+ .devo_identify = nulldev,
+ .devo_probe = nulldev,
+ .devo_reset = nodev,
+ .devo_bus_ops = NULL,
+ .devo_power = NULL,
+};
+
+static struct modldrv vsock_vio_modldrv = {
+ .drv_modops = &mod_driverops,
+ .drv_linkinfo = "AF_VSOCK VIRTIO transport driver",
+ .drv_dev_ops = &vsock_vio_dev_ops,
+};
+
+static struct modlinkage vsock_vio_modlinkage = {
+ .ml_rev = MODREV_1,
+ .ml_linkage = { &vsock_vio_modldrv, NULL }
+};
+
+int
+_init(void)
+{
+ int rc;
+
+ rc = mod_install(&vsock_vio_modlinkage);
+ return (rc);
+}
+
+int
+_fini(void)
+{
+ int rc;
+
+ rc = mod_remove(&vsock_vio_modlinkage);
+ return (rc);
+}
+
+int
+_info(struct modinfo *modinfop)
+{
+ return (mod_info(&vsock_vio_modlinkage, modinfop));
+}
diff --git a/usr/src/uts/common/io/vsock/vsock_vio.h b/usr/src/uts/common/io/vsock/vsock_vio.h
new file mode 100644
index 0000000000..953d7dc1fa
--- /dev/null
+++ b/usr/src/uts/common/io/vsock/vsock_vio.h
@@ -0,0 +1,84 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2021 Joyent, Inc.
+ */
+
+#ifndef _VSOCK_VIO_H
+#define _VSOCK_VIO_H
+
+/*
+ * xxx
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * VIRTIO VSOCK CONFIGURATION REGISTERS
+ *
+ * These are offsets into the device-specific configuration space available
+ * through the virtio_dev_*() family of functions.
+ */
+#define VIRTO_VSOCK_CONFIG_CID 0x00 /* 16 R */
+
+/*
+ * VIRTIO VSOCK VIRTQUEUES
+ */
+#define VIRTIO_VSOCK_VIRTQ_RX 0
+#define VIRTIO_VSOCK_VIRTQ_TX 1
+#define VIRTIO_VOCK_VIRTQ_EVENT 2
+
+struct virtio_vsock_hdr {
+ uint64_t vvh_src_cid;
+ uint64_t vvh_dst_cid;
+ uint32_t vvh_src_port;
+ uint32_t vvh_dst_port;
+ uint32_t vvh_len;
+ uint16_t vvh_type;
+ uint16_t vvh_op;
+ uint32_t vvh_flags;
+ uint32_t vvh_buf_alloc;
+ uint32_t vvh_fwd_cnt;
+} __packed;
+
+#define VIRTIO_VSOCK_OP_INVALID 0
+
+#define VIRTIO_VSOCK_OP_REQUEST 1
+#define VIRTIO_VSOCK_OP_RESPONSE 2
+#define VIRTIO_VSOCK_OP_RST 3
+#define VIRTIO_VSOCK_OP_SHUTDOWN 4
+
+#define VIRTIO_VSOCK_OP_RW 5
+
+#define VIRTIO_VSOCK_OP_CREDIT_UPDATE 6
+#define VIRTIO_VSOCK_OP_CREDIT_REQUEST 7
+
+struct vsock_dev {
+ dev_info_t *vsd_dip;
+ virtio_t *vsd_virtio;
+
+ kmutex_t vsd_mutex;
+
+ virtio_queue_t *vsd_rx_vq;
+ virtio_queue_t *vsd_tx_vq;
+ virtio_queue_t *vsd_event_vq;
+
+ uint64_t vsd_cid;
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _VSOCK_H */