vmci_transport.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. #ifndef _VMCI_TRANSPORT_H_
  16. #define _VMCI_TRANSPORT_H_
  17. #include <linux/vmw_vmci_defs.h>
  18. #include <linux/vmw_vmci_api.h>
  19. #include <net/vsock_addr.h>
  20. #include <net/af_vsock.h>
  21. /* If the packet format changes in a release then this should change too. */
  22. #define VMCI_TRANSPORT_PACKET_VERSION 1
  23. /* The resource ID on which control packets are sent. */
  24. #define VMCI_TRANSPORT_PACKET_RID 1
  25. /* The resource ID on which control packets are sent to the hypervisor. */
  26. #define VMCI_TRANSPORT_HYPERVISOR_PACKET_RID 15
  27. #define VSOCK_PROTO_INVALID 0
  28. #define VSOCK_PROTO_PKT_ON_NOTIFY (1 << 0)
  29. #define VSOCK_PROTO_ALL_SUPPORTED (VSOCK_PROTO_PKT_ON_NOTIFY)
  30. #define vmci_trans(_vsk) ((struct vmci_transport *)((_vsk)->trans))
  31. enum vmci_transport_packet_type {
  32. VMCI_TRANSPORT_PACKET_TYPE_INVALID = 0,
  33. VMCI_TRANSPORT_PACKET_TYPE_REQUEST,
  34. VMCI_TRANSPORT_PACKET_TYPE_NEGOTIATE,
  35. VMCI_TRANSPORT_PACKET_TYPE_OFFER,
  36. VMCI_TRANSPORT_PACKET_TYPE_ATTACH,
  37. VMCI_TRANSPORT_PACKET_TYPE_WROTE,
  38. VMCI_TRANSPORT_PACKET_TYPE_READ,
  39. VMCI_TRANSPORT_PACKET_TYPE_RST,
  40. VMCI_TRANSPORT_PACKET_TYPE_SHUTDOWN,
  41. VMCI_TRANSPORT_PACKET_TYPE_WAITING_WRITE,
  42. VMCI_TRANSPORT_PACKET_TYPE_WAITING_READ,
  43. VMCI_TRANSPORT_PACKET_TYPE_REQUEST2,
  44. VMCI_TRANSPORT_PACKET_TYPE_NEGOTIATE2,
  45. VMCI_TRANSPORT_PACKET_TYPE_MAX
  46. };
  47. struct vmci_transport_waiting_info {
  48. u64 generation;
  49. u64 offset;
  50. };
  51. /* Control packet type for STREAM sockets. DGRAMs have no control packets nor
  52. * special packet header for data packets, they are just raw VMCI DGRAM
  53. * messages. For STREAMs, control packets are sent over the control channel
  54. * while data is written and read directly from queue pairs with no packet
  55. * format.
  56. */
  57. struct vmci_transport_packet {
  58. struct vmci_datagram dg;
  59. u8 version;
  60. u8 type;
  61. u16 proto;
  62. u32 src_port;
  63. u32 dst_port;
  64. u32 _reserved2;
  65. union {
  66. u64 size;
  67. u64 mode;
  68. struct vmci_handle handle;
  69. struct vmci_transport_waiting_info wait;
  70. } u;
  71. };
  72. struct vmci_transport_notify_pkt {
  73. u64 write_notify_window;
  74. u64 write_notify_min_window;
  75. bool peer_waiting_read;
  76. bool peer_waiting_write;
  77. bool peer_waiting_write_detected;
  78. bool sent_waiting_read;
  79. bool sent_waiting_write;
  80. struct vmci_transport_waiting_info peer_waiting_read_info;
  81. struct vmci_transport_waiting_info peer_waiting_write_info;
  82. u64 produce_q_generation;
  83. u64 consume_q_generation;
  84. };
  85. struct vmci_transport_notify_pkt_q_state {
  86. u64 write_notify_window;
  87. u64 write_notify_min_window;
  88. bool peer_waiting_write;
  89. bool peer_waiting_write_detected;
  90. };
  91. union vmci_transport_notify {
  92. struct vmci_transport_notify_pkt pkt;
  93. struct vmci_transport_notify_pkt_q_state pkt_q_state;
  94. };
  95. /* Our transport-specific data. */
  96. struct vmci_transport {
  97. /* For DGRAMs. */
  98. struct vmci_handle dg_handle;
  99. /* For STREAMs. */
  100. struct vmci_handle qp_handle;
  101. struct vmci_qp *qpair;
  102. u64 produce_size;
  103. u64 consume_size;
  104. u64 queue_pair_size;
  105. u64 queue_pair_min_size;
  106. u64 queue_pair_max_size;
  107. u32 detach_sub_id;
  108. union vmci_transport_notify notify;
  109. struct vmci_transport_notify_ops *notify_ops;
  110. struct list_head elem;
  111. struct sock *sk;
  112. spinlock_t lock; /* protects sk. */
  113. };
  114. int vmci_transport_register(void);
  115. void vmci_transport_unregister(void);
  116. int vmci_transport_send_wrote_bh(struct sockaddr_vm *dst,
  117. struct sockaddr_vm *src);
  118. int vmci_transport_send_read_bh(struct sockaddr_vm *dst,
  119. struct sockaddr_vm *src);
  120. int vmci_transport_send_wrote(struct sock *sk);
  121. int vmci_transport_send_read(struct sock *sk);
  122. int vmci_transport_send_waiting_write(struct sock *sk,
  123. struct vmci_transport_waiting_info *wait);
  124. int vmci_transport_send_waiting_read(struct sock *sk,
  125. struct vmci_transport_waiting_info *wait);
  126. #endif