vmci_transport.h 3.9 KB

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