netif.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. * This is the 'wire' format for packets:
  55. * Request 1: xen_netif_tx_request -- XEN_NETTXF_* (any flags)
  56. * [Request 2: xen_netif_extra_info] (only if request 1 has XEN_NETTXF_extra_info)
  57. * [Request 3: xen_netif_extra_info] (only if request 2 has XEN_NETIF_EXTRA_MORE)
  58. * Request 4: xen_netif_tx_request -- XEN_NETTXF_more_data
  59. * Request 5: xen_netif_tx_request -- XEN_NETTXF_more_data
  60. * ...
  61. * Request N: xen_netif_tx_request -- 0
  62. */
  63. /* Protocol checksum field is blank in the packet (hardware offload)? */
  64. #define _XEN_NETTXF_csum_blank (0)
  65. #define XEN_NETTXF_csum_blank (1U<<_XEN_NETTXF_csum_blank)
  66. /* Packet data has been validated against protocol checksum. */
  67. #define _XEN_NETTXF_data_validated (1)
  68. #define XEN_NETTXF_data_validated (1U<<_XEN_NETTXF_data_validated)
  69. /* Packet continues in the next request descriptor. */
  70. #define _XEN_NETTXF_more_data (2)
  71. #define XEN_NETTXF_more_data (1U<<_XEN_NETTXF_more_data)
  72. /* Packet to be followed by extra descriptor(s). */
  73. #define _XEN_NETTXF_extra_info (3)
  74. #define XEN_NETTXF_extra_info (1U<<_XEN_NETTXF_extra_info)
  75. #define XEN_NETIF_MAX_TX_SIZE 0xFFFF
  76. struct xen_netif_tx_request {
  77. grant_ref_t gref; /* Reference to buffer page */
  78. uint16_t offset; /* Offset within buffer page */
  79. uint16_t flags; /* XEN_NETTXF_* */
  80. uint16_t id; /* Echoed in response message. */
  81. uint16_t size; /* Packet size in bytes. */
  82. };
  83. /* Types of xen_netif_extra_info descriptors. */
  84. #define XEN_NETIF_EXTRA_TYPE_NONE (0) /* Never used - invalid */
  85. #define XEN_NETIF_EXTRA_TYPE_GSO (1) /* u.gso */
  86. #define XEN_NETIF_EXTRA_TYPE_MAX (2)
  87. /* xen_netif_extra_info flags. */
  88. #define _XEN_NETIF_EXTRA_FLAG_MORE (0)
  89. #define XEN_NETIF_EXTRA_FLAG_MORE (1U<<_XEN_NETIF_EXTRA_FLAG_MORE)
  90. /* GSO types - only TCPv4 currently supported. */
  91. #define XEN_NETIF_GSO_TYPE_TCPV4 (1)
  92. /*
  93. * This structure needs to fit within both netif_tx_request and
  94. * netif_rx_response for compatibility.
  95. */
  96. struct xen_netif_extra_info {
  97. uint8_t type; /* XEN_NETIF_EXTRA_TYPE_* */
  98. uint8_t flags; /* XEN_NETIF_EXTRA_FLAG_* */
  99. union {
  100. struct {
  101. /*
  102. * Maximum payload size of each segment. For
  103. * example, for TCP this is just the path MSS.
  104. */
  105. uint16_t size;
  106. /*
  107. * GSO type. This determines the protocol of
  108. * the packet and any extra features required
  109. * to segment the packet properly.
  110. */
  111. uint8_t type; /* XEN_NETIF_GSO_TYPE_* */
  112. /* Future expansion. */
  113. uint8_t pad;
  114. /*
  115. * GSO features. This specifies any extra GSO
  116. * features required to process this packet,
  117. * such as ECN support for TCPv4.
  118. */
  119. uint16_t features; /* XEN_NETIF_GSO_FEAT_* */
  120. } gso;
  121. uint16_t pad[3];
  122. } u;
  123. };
  124. struct xen_netif_tx_response {
  125. uint16_t id;
  126. int16_t status; /* XEN_NETIF_RSP_* */
  127. };
  128. struct xen_netif_rx_request {
  129. uint16_t id; /* Echoed in response message. */
  130. grant_ref_t gref; /* Reference to incoming granted frame */
  131. };
  132. /* Packet data has been validated against protocol checksum. */
  133. #define _XEN_NETRXF_data_validated (0)
  134. #define XEN_NETRXF_data_validated (1U<<_XEN_NETRXF_data_validated)
  135. /* Protocol checksum field is blank in the packet (hardware offload)? */
  136. #define _XEN_NETRXF_csum_blank (1)
  137. #define XEN_NETRXF_csum_blank (1U<<_XEN_NETRXF_csum_blank)
  138. /* Packet continues in the next request descriptor. */
  139. #define _XEN_NETRXF_more_data (2)
  140. #define XEN_NETRXF_more_data (1U<<_XEN_NETRXF_more_data)
  141. /* Packet to be followed by extra descriptor(s). */
  142. #define _XEN_NETRXF_extra_info (3)
  143. #define XEN_NETRXF_extra_info (1U<<_XEN_NETRXF_extra_info)
  144. /* GSO Prefix descriptor. */
  145. #define _XEN_NETRXF_gso_prefix (4)
  146. #define XEN_NETRXF_gso_prefix (1U<<_XEN_NETRXF_gso_prefix)
  147. struct xen_netif_rx_response {
  148. uint16_t id;
  149. uint16_t offset; /* Offset in page of start of received packet */
  150. uint16_t flags; /* XEN_NETRXF_* */
  151. int16_t status; /* -ve: BLKIF_RSP_* ; +ve: Rx'ed pkt size. */
  152. };
  153. /*
  154. * Generate netif ring structures and types.
  155. */
  156. DEFINE_RING_TYPES(xen_netif_tx,
  157. struct xen_netif_tx_request,
  158. struct xen_netif_tx_response);
  159. DEFINE_RING_TYPES(xen_netif_rx,
  160. struct xen_netif_rx_request,
  161. struct xen_netif_rx_response);
  162. #define XEN_NETIF_RSP_DROPPED -2
  163. #define XEN_NETIF_RSP_ERROR -1
  164. #define XEN_NETIF_RSP_OKAY 0
  165. /* No response: used for auxiliary requests (e.g., xen_netif_extra_info). */
  166. #define XEN_NETIF_RSP_NULL 1
  167. #endif