1 /* 2 * VMware vSockets Driver 3 * 4 * Copyright (C) 2013 VMware, Inc. All rights reserved. 5 * 6 * This program is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License as published by the Free 8 * Software Foundation version 2 and no later version. 9 * 10 * This program is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 * more details. 14 */ 15 16 #ifndef _VMCI_TRANSPORT_H_ 17 #define _VMCI_TRANSPORT_H_ 18 19 #include <linux/vmw_vmci_defs.h> 20 #include <linux/vmw_vmci_api.h> 21 22 #include "vsock_addr.h" 23 #include "af_vsock.h" 24 25 /* If the packet format changes in a release then this should change too. */ 26 #define VMCI_TRANSPORT_PACKET_VERSION 1 27 28 /* The resource ID on which control packets are sent. */ 29 #define VMCI_TRANSPORT_PACKET_RID 1 30 31 #define VSOCK_PROTO_INVALID 0 32 #define VSOCK_PROTO_PKT_ON_NOTIFY (1 << 0) 33 #define VSOCK_PROTO_ALL_SUPPORTED (VSOCK_PROTO_PKT_ON_NOTIFY) 34 35 #define vmci_trans(_vsk) ((struct vmci_transport *)((_vsk)->trans)) 36 37 enum vmci_transport_packet_type { 38 VMCI_TRANSPORT_PACKET_TYPE_INVALID = 0, 39 VMCI_TRANSPORT_PACKET_TYPE_REQUEST, 40 VMCI_TRANSPORT_PACKET_TYPE_NEGOTIATE, 41 VMCI_TRANSPORT_PACKET_TYPE_OFFER, 42 VMCI_TRANSPORT_PACKET_TYPE_ATTACH, 43 VMCI_TRANSPORT_PACKET_TYPE_WROTE, 44 VMCI_TRANSPORT_PACKET_TYPE_READ, 45 VMCI_TRANSPORT_PACKET_TYPE_RST, 46 VMCI_TRANSPORT_PACKET_TYPE_SHUTDOWN, 47 VMCI_TRANSPORT_PACKET_TYPE_WAITING_WRITE, 48 VMCI_TRANSPORT_PACKET_TYPE_WAITING_READ, 49 VMCI_TRANSPORT_PACKET_TYPE_REQUEST2, 50 VMCI_TRANSPORT_PACKET_TYPE_NEGOTIATE2, 51 VMCI_TRANSPORT_PACKET_TYPE_MAX 52 }; 53 54 struct vmci_transport_waiting_info { 55 u64 generation; 56 u64 offset; 57 }; 58 59 /* Control packet type for STREAM sockets. DGRAMs have no control packets nor 60 * special packet header for data packets, they are just raw VMCI DGRAM 61 * messages. For STREAMs, control packets are sent over the control channel 62 * while data is written and read directly from queue pairs with no packet 63 * format. 64 */ 65 struct vmci_transport_packet { 66 struct vmci_datagram dg; 67 u8 version; 68 u8 type; 69 u16 proto; 70 u32 src_port; 71 u32 dst_port; 72 u32 _reserved2; 73 union { 74 u64 size; 75 u64 mode; 76 struct vmci_handle handle; 77 struct vmci_transport_waiting_info wait; 78 } u; 79 }; 80 81 struct vmci_transport_notify_pkt { 82 u64 write_notify_window; 83 u64 write_notify_min_window; 84 bool peer_waiting_read; 85 bool peer_waiting_write; 86 bool peer_waiting_write_detected; 87 bool sent_waiting_read; 88 bool sent_waiting_write; 89 struct vmci_transport_waiting_info peer_waiting_read_info; 90 struct vmci_transport_waiting_info peer_waiting_write_info; 91 u64 produce_q_generation; 92 u64 consume_q_generation; 93 }; 94 95 struct vmci_transport_notify_pkt_q_state { 96 u64 write_notify_window; 97 u64 write_notify_min_window; 98 bool peer_waiting_write; 99 bool peer_waiting_write_detected; 100 }; 101 102 union vmci_transport_notify { 103 struct vmci_transport_notify_pkt pkt; 104 struct vmci_transport_notify_pkt_q_state pkt_q_state; 105 }; 106 107 /* Our transport-specific data. */ 108 struct vmci_transport { 109 /* For DGRAMs. */ 110 struct vmci_handle dg_handle; 111 /* For STREAMs. */ 112 struct vmci_handle qp_handle; 113 struct vmci_qp *qpair; 114 u64 produce_size; 115 u64 consume_size; 116 u64 queue_pair_size; 117 u64 queue_pair_min_size; 118 u64 queue_pair_max_size; 119 u32 attach_sub_id; 120 u32 detach_sub_id; 121 union vmci_transport_notify notify; 122 struct vmci_transport_notify_ops *notify_ops; 123 }; 124 125 int vmci_transport_register(void); 126 void vmci_transport_unregister(void); 127 128 int vmci_transport_send_wrote_bh(struct sockaddr_vm *dst, 129 struct sockaddr_vm *src); 130 int vmci_transport_send_read_bh(struct sockaddr_vm *dst, 131 struct sockaddr_vm *src); 132 int vmci_transport_send_wrote(struct sock *sk); 133 int vmci_transport_send_read(struct sock *sk); 134 int vmci_transport_send_waiting_write(struct sock *sk, 135 struct vmci_transport_waiting_info *wait); 136 int vmci_transport_send_waiting_read(struct sock *sk, 137 struct vmci_transport_waiting_info *wait); 138 139 #endif 140