Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * VMware vSockets Driver
0004  *
0005  * Copyright (C) 2013 VMware, Inc. All rights reserved.
0006  */
0007 
0008 #ifndef _VMCI_TRANSPORT_H_
0009 #define _VMCI_TRANSPORT_H_
0010 
0011 #include <linux/vmw_vmci_defs.h>
0012 #include <linux/vmw_vmci_api.h>
0013 
0014 #include <net/vsock_addr.h>
0015 #include <net/af_vsock.h>
0016 
0017 /* If the packet format changes in a release then this should change too. */
0018 #define VMCI_TRANSPORT_PACKET_VERSION 1
0019 
0020 /* The resource ID on which control packets are sent. */
0021 #define VMCI_TRANSPORT_PACKET_RID 1
0022 
0023 /* The resource ID on which control packets are sent to the hypervisor. */
0024 #define VMCI_TRANSPORT_HYPERVISOR_PACKET_RID 15
0025 
0026 #define VSOCK_PROTO_INVALID        0
0027 #define VSOCK_PROTO_PKT_ON_NOTIFY (1 << 0)
0028 #define VSOCK_PROTO_ALL_SUPPORTED (VSOCK_PROTO_PKT_ON_NOTIFY)
0029 
0030 #define vmci_trans(_vsk) ((struct vmci_transport *)((_vsk)->trans))
0031 
0032 enum vmci_transport_packet_type {
0033     VMCI_TRANSPORT_PACKET_TYPE_INVALID = 0,
0034     VMCI_TRANSPORT_PACKET_TYPE_REQUEST,
0035     VMCI_TRANSPORT_PACKET_TYPE_NEGOTIATE,
0036     VMCI_TRANSPORT_PACKET_TYPE_OFFER,
0037     VMCI_TRANSPORT_PACKET_TYPE_ATTACH,
0038     VMCI_TRANSPORT_PACKET_TYPE_WROTE,
0039     VMCI_TRANSPORT_PACKET_TYPE_READ,
0040     VMCI_TRANSPORT_PACKET_TYPE_RST,
0041     VMCI_TRANSPORT_PACKET_TYPE_SHUTDOWN,
0042     VMCI_TRANSPORT_PACKET_TYPE_WAITING_WRITE,
0043     VMCI_TRANSPORT_PACKET_TYPE_WAITING_READ,
0044     VMCI_TRANSPORT_PACKET_TYPE_REQUEST2,
0045     VMCI_TRANSPORT_PACKET_TYPE_NEGOTIATE2,
0046     VMCI_TRANSPORT_PACKET_TYPE_MAX
0047 };
0048 
0049 struct vmci_transport_waiting_info {
0050     u64 generation;
0051     u64 offset;
0052 };
0053 
0054 /* Control packet type for STREAM sockets.  DGRAMs have no control packets nor
0055  * special packet header for data packets, they are just raw VMCI DGRAM
0056  * messages.  For STREAMs, control packets are sent over the control channel
0057  * while data is written and read directly from queue pairs with no packet
0058  * format.
0059  */
0060 struct vmci_transport_packet {
0061     struct vmci_datagram dg;
0062     u8 version;
0063     u8 type;
0064     u16 proto;
0065     u32 src_port;
0066     u32 dst_port;
0067     u32 _reserved2;
0068     union {
0069         u64 size;
0070         u64 mode;
0071         struct vmci_handle handle;
0072         struct vmci_transport_waiting_info wait;
0073     } u;
0074 };
0075 
0076 struct vmci_transport_notify_pkt {
0077     u64 write_notify_window;
0078     u64 write_notify_min_window;
0079     bool peer_waiting_read;
0080     bool peer_waiting_write;
0081     bool peer_waiting_write_detected;
0082     bool sent_waiting_read;
0083     bool sent_waiting_write;
0084     struct vmci_transport_waiting_info peer_waiting_read_info;
0085     struct vmci_transport_waiting_info peer_waiting_write_info;
0086     u64 produce_q_generation;
0087     u64 consume_q_generation;
0088 };
0089 
0090 struct vmci_transport_notify_pkt_q_state {
0091     u64 write_notify_window;
0092     u64 write_notify_min_window;
0093     bool peer_waiting_write;
0094     bool peer_waiting_write_detected;
0095 };
0096 
0097 union vmci_transport_notify {
0098     struct vmci_transport_notify_pkt pkt;
0099     struct vmci_transport_notify_pkt_q_state pkt_q_state;
0100 };
0101 
0102 /* Our transport-specific data. */
0103 struct vmci_transport {
0104     /* For DGRAMs. */
0105     struct vmci_handle dg_handle;
0106     /* For STREAMs. */
0107     struct vmci_handle qp_handle;
0108     struct vmci_qp *qpair;
0109     u64 produce_size;
0110     u64 consume_size;
0111     u32 detach_sub_id;
0112     union vmci_transport_notify notify;
0113     const struct vmci_transport_notify_ops *notify_ops;
0114     struct list_head elem;
0115     struct sock *sk;
0116     spinlock_t lock; /* protects sk. */
0117 };
0118 
0119 int vmci_transport_register(void);
0120 void vmci_transport_unregister(void);
0121 
0122 int vmci_transport_send_wrote_bh(struct sockaddr_vm *dst,
0123                  struct sockaddr_vm *src);
0124 int vmci_transport_send_read_bh(struct sockaddr_vm *dst,
0125                 struct sockaddr_vm *src);
0126 int vmci_transport_send_wrote(struct sock *sk);
0127 int vmci_transport_send_read(struct sock *sk);
0128 int vmci_transport_send_waiting_write(struct sock *sk,
0129                       struct vmci_transport_waiting_info *wait);
0130 int vmci_transport_send_waiting_read(struct sock *sk,
0131                      struct vmci_transport_waiting_info *wait);
0132 
0133 #endif