netif.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /******************************************************************************
  2. * netif.h
  3. *
  4. * Unified network-device I/O interface for Xen guest OSes.
  5. *
  6. * Copyright (c) 2003-2004, Keir Fraser
  7. */
  8. #ifndef __XEN_PUBLIC_IO_NETIF_H__
  9. #define __XEN_PUBLIC_IO_NETIF_H__
  10. #include <xen/interface/io/ring.h>
  11. #include <xen/interface/grant_table.h>
  12. /*
  13. * Older implementation of Xen network frontend / backend has an
  14. * implicit dependency on the MAX_SKB_FRAGS as the maximum number of
  15. * ring slots a skb can use. Netfront / netback may not work as
  16. * expected when frontend and backend have different MAX_SKB_FRAGS.
  17. *
  18. * A better approach is to add mechanism for netfront / netback to
  19. * negotiate this value. However we cannot fix all possible
  20. * frontends, so we need to define a value which states the minimum
  21. * slots backend must support.
  22. *
  23. * The minimum value derives from older Linux kernel's MAX_SKB_FRAGS
  24. * (18), which is proved to work with most frontends. Any new backend
  25. * which doesn't negotiate with frontend should expect frontend to
  26. * send a valid packet using slots up to this value.
  27. */
  28. #define XEN_NETIF_NR_SLOTS_MIN 18
  29. /*
  30. * Notifications after enqueuing any type of message should be conditional on
  31. * the appropriate req_event or rsp_event field in the shared ring.
  32. * If the client sends notification for rx requests then it should specify
  33. * feature 'feature-rx-notify' via xenbus. Otherwise the backend will assume
  34. * that it cannot safely queue packets (as it may not be kicked to send them).
  35. */
  36. /*
  37. * "feature-split-event-channels" is introduced to separate guest TX
  38. * and RX notificaion. Backend either doesn't support this feature or
  39. * advertise it via xenstore as 0 (disabled) or 1 (enabled).
  40. *
  41. * To make use of this feature, frontend should allocate two event
  42. * channels for TX and RX, advertise them to backend as
  43. * "event-channel-tx" and "event-channel-rx" respectively. If frontend
  44. * doesn't want to use this feature, it just writes "event-channel"
  45. * node as before.
  46. */
  47. /*
  48. * "feature-no-csum-offload" should be used to turn IPv4 TCP/UDP checksum
  49. * offload off or on. If it is missing then the feature is assumed to be on.
  50. * "feature-ipv6-csum-offload" should be used to turn IPv6 TCP/UDP checksum
  51. * offload on or off. If it is missing then the feature is assumed to be off.
  52. */
  53. /*
  54. * "feature-gso-tcpv4" and "feature-gso-tcpv6" advertise the capability to
  55. * handle large TCP packets (in IPv4 or IPv6 form respectively). Neither
  56. * frontends nor backends are assumed to be capable unless the flags are
  57. * present.
  58. */
  59. /*
  60. * This is the 'wire' format for packets:
  61. * Request 1: xen_netif_tx_request -- XEN_NETTXF_* (any flags)
  62. * [Request 2: xen_netif_extra_info] (only if request 1 has XEN_NETTXF_extra_info)
  63. * [Request 3: xen_netif_extra_info] (only if request 2 has XEN_NETIF_EXTRA_MORE)
  64. * Request 4: xen_netif_tx_request -- XEN_NETTXF_more_data
  65. * Request 5: xen_netif_tx_request -- XEN_NETTXF_more_data
  66. * ...
  67. * Request N: xen_netif_tx_request -- 0
  68. */
  69. /* Protocol checksum field is blank in the packet (hardware offload)? */
  70. #define _XEN_NETTXF_csum_blank (0)
  71. #define XEN_NETTXF_csum_blank (1U<<_XEN_NETTXF_csum_blank)
  72. /* Packet data has been validated against protocol checksum. */
  73. #define _XEN_NETTXF_data_validated (1)
  74. #define XEN_NETTXF_data_validated (1U<<_XEN_NETTXF_data_validated)
  75. /* Packet continues in the next request descriptor. */
  76. #define _XEN_NETTXF_more_data (2)
  77. #define XEN_NETTXF_more_data (1U<<_XEN_NETTXF_more_data)
  78. /* Packet to be followed by extra descriptor(s). */
  79. #define _XEN_NETTXF_extra_info (3)
  80. #define XEN_NETTXF_extra_info (1U<<_XEN_NETTXF_extra_info)
  81. #define XEN_NETIF_MAX_TX_SIZE 0xFFFF
  82. struct xen_netif_tx_request {
  83. grant_ref_t gref; /* Reference to buffer page */
  84. uint16_t offset; /* Offset within buffer page */
  85. uint16_t flags; /* XEN_NETTXF_* */
  86. uint16_t id; /* Echoed in response message. */
  87. uint16_t size; /* Packet size in bytes. */
  88. };
  89. /* Types of xen_netif_extra_info descriptors. */
  90. #define XEN_NETIF_EXTRA_TYPE_NONE (0) /* Never used - invalid */
  91. #define XEN_NETIF_EXTRA_TYPE_GSO (1) /* u.gso */
  92. #define XEN_NETIF_EXTRA_TYPE_MAX (2)
  93. /* xen_netif_extra_info flags. */
  94. #define _XEN_NETIF_EXTRA_FLAG_MORE (0)
  95. #define XEN_NETIF_EXTRA_FLAG_MORE (1U<<_XEN_NETIF_EXTRA_FLAG_MORE)
  96. /* GSO types */
  97. #define XEN_NETIF_GSO_TYPE_NONE (0)
  98. #define XEN_NETIF_GSO_TYPE_TCPV4 (1)
  99. #define XEN_NETIF_GSO_TYPE_TCPV6 (2)
  100. /*
  101. * This structure needs to fit within both netif_tx_request and
  102. * netif_rx_response for compatibility.
  103. */
  104. struct xen_netif_extra_info {
  105. uint8_t type; /* XEN_NETIF_EXTRA_TYPE_* */
  106. uint8_t flags; /* XEN_NETIF_EXTRA_FLAG_* */
  107. union {
  108. struct {
  109. /*
  110. * Maximum payload size of each segment. For
  111. * example, for TCP this is just the path MSS.
  112. */
  113. uint16_t size;
  114. /*
  115. * GSO type. This determines the protocol of
  116. * the packet and any extra features required
  117. * to segment the packet properly.
  118. */
  119. uint8_t type; /* XEN_NETIF_GSO_TYPE_* */
  120. /* Future expansion. */
  121. uint8_t pad;
  122. /*
  123. * GSO features. This specifies any extra GSO
  124. * features required to process this packet,
  125. * such as ECN support for TCPv4.
  126. */
  127. uint16_t features; /* XEN_NETIF_GSO_FEAT_* */
  128. } gso;
  129. uint16_t pad[3];
  130. } u;
  131. };
  132. struct xen_netif_tx_response {
  133. uint16_t id;
  134. int16_t status; /* XEN_NETIF_RSP_* */
  135. };
  136. struct xen_netif_rx_request {
  137. uint16_t id; /* Echoed in response message. */
  138. grant_ref_t gref; /* Reference to incoming granted frame */
  139. };
  140. /* Packet data has been validated against protocol checksum. */
  141. #define _XEN_NETRXF_data_validated (0)
  142. #define XEN_NETRXF_data_validated (1U<<_XEN_NETRXF_data_validated)
  143. /* Protocol checksum field is blank in the packet (hardware offload)? */
  144. #define _XEN_NETRXF_csum_blank (1)
  145. #define XEN_NETRXF_csum_blank (1U<<_XEN_NETRXF_csum_blank)
  146. /* Packet continues in the next request descriptor. */
  147. #define _XEN_NETRXF_more_data (2)
  148. #define XEN_NETRXF_more_data (1U<<_XEN_NETRXF_more_data)
  149. /* Packet to be followed by extra descriptor(s). */
  150. #define _XEN_NETRXF_extra_info (3)
  151. #define XEN_NETRXF_extra_info (1U<<_XEN_NETRXF_extra_info)
  152. /* GSO Prefix descriptor. */
  153. #define _XEN_NETRXF_gso_prefix (4)
  154. #define XEN_NETRXF_gso_prefix (1U<<_XEN_NETRXF_gso_prefix)
  155. struct xen_netif_rx_response {
  156. uint16_t id;
  157. uint16_t offset; /* Offset in page of start of received packet */
  158. uint16_t flags; /* XEN_NETRXF_* */
  159. int16_t status; /* -ve: BLKIF_RSP_* ; +ve: Rx'ed pkt size. */
  160. };
  161. /*
  162. * Generate netif ring structures and types.
  163. */
  164. DEFINE_RING_TYPES(xen_netif_tx,
  165. struct xen_netif_tx_request,
  166. struct xen_netif_tx_response);
  167. DEFINE_RING_TYPES(xen_netif_rx,
  168. struct xen_netif_rx_request,
  169. struct xen_netif_rx_response);
  170. #define XEN_NETIF_RSP_DROPPED -2
  171. #define XEN_NETIF_RSP_ERROR -1
  172. #define XEN_NETIF_RSP_OKAY 0
  173. /* No response: used for auxiliary requests (e.g., xen_netif_extra_info). */
  174. #define XEN_NETIF_RSP_NULL 1
  175. #endif