netif.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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. * Multiple transmit and receive queues:
  49. * If supported, the backend will write the key "multi-queue-max-queues" to
  50. * the directory for that vif, and set its value to the maximum supported
  51. * number of queues.
  52. * Frontends that are aware of this feature and wish to use it can write the
  53. * key "multi-queue-num-queues", set to the number they wish to use, which
  54. * must be greater than zero, and no more than the value reported by the backend
  55. * in "multi-queue-max-queues".
  56. *
  57. * Queues replicate the shared rings and event channels.
  58. * "feature-split-event-channels" may optionally be used when using
  59. * multiple queues, but is not mandatory.
  60. *
  61. * Each queue consists of one shared ring pair, i.e. there must be the same
  62. * number of tx and rx rings.
  63. *
  64. * For frontends requesting just one queue, the usual event-channel and
  65. * ring-ref keys are written as before, simplifying the backend processing
  66. * to avoid distinguishing between a frontend that doesn't understand the
  67. * multi-queue feature, and one that does, but requested only one queue.
  68. *
  69. * Frontends requesting two or more queues must not write the toplevel
  70. * event-channel (or event-channel-{tx,rx}) and {tx,rx}-ring-ref keys,
  71. * instead writing those keys under sub-keys having the name "queue-N" where
  72. * N is the integer ID of the queue for which those keys belong. Queues
  73. * are indexed from zero. For example, a frontend with two queues and split
  74. * event channels must write the following set of queue-related keys:
  75. *
  76. * /local/domain/1/device/vif/0/multi-queue-num-queues = "2"
  77. * /local/domain/1/device/vif/0/queue-0 = ""
  78. * /local/domain/1/device/vif/0/queue-0/tx-ring-ref = "<ring-ref-tx0>"
  79. * /local/domain/1/device/vif/0/queue-0/rx-ring-ref = "<ring-ref-rx0>"
  80. * /local/domain/1/device/vif/0/queue-0/event-channel-tx = "<evtchn-tx0>"
  81. * /local/domain/1/device/vif/0/queue-0/event-channel-rx = "<evtchn-rx0>"
  82. * /local/domain/1/device/vif/0/queue-1 = ""
  83. * /local/domain/1/device/vif/0/queue-1/tx-ring-ref = "<ring-ref-tx1>"
  84. * /local/domain/1/device/vif/0/queue-1/rx-ring-ref = "<ring-ref-rx1"
  85. * /local/domain/1/device/vif/0/queue-1/event-channel-tx = "<evtchn-tx1>"
  86. * /local/domain/1/device/vif/0/queue-1/event-channel-rx = "<evtchn-rx1>"
  87. *
  88. * If there is any inconsistency in the XenStore data, the backend may
  89. * choose not to connect any queues, instead treating the request as an
  90. * error. This includes scenarios where more (or fewer) queues were
  91. * requested than the frontend provided details for.
  92. *
  93. * Mapping of packets to queues is considered to be a function of the
  94. * transmitting system (backend or frontend) and is not negotiated
  95. * between the two. Guests are free to transmit packets on any queue
  96. * they choose, provided it has been set up correctly. Guests must be
  97. * prepared to receive packets on any queue they have requested be set up.
  98. */
  99. /*
  100. * "feature-no-csum-offload" should be used to turn IPv4 TCP/UDP checksum
  101. * offload off or on. If it is missing then the feature is assumed to be on.
  102. * "feature-ipv6-csum-offload" should be used to turn IPv6 TCP/UDP checksum
  103. * offload on or off. If it is missing then the feature is assumed to be off.
  104. */
  105. /*
  106. * "feature-gso-tcpv4" and "feature-gso-tcpv6" advertise the capability to
  107. * handle large TCP packets (in IPv4 or IPv6 form respectively). Neither
  108. * frontends nor backends are assumed to be capable unless the flags are
  109. * present.
  110. */
  111. /*
  112. * This is the 'wire' format for packets:
  113. * Request 1: xen_netif_tx_request -- XEN_NETTXF_* (any flags)
  114. * [Request 2: xen_netif_extra_info] (only if request 1 has XEN_NETTXF_extra_info)
  115. * [Request 3: xen_netif_extra_info] (only if request 2 has XEN_NETIF_EXTRA_MORE)
  116. * Request 4: xen_netif_tx_request -- XEN_NETTXF_more_data
  117. * Request 5: xen_netif_tx_request -- XEN_NETTXF_more_data
  118. * ...
  119. * Request N: xen_netif_tx_request -- 0
  120. */
  121. /* Protocol checksum field is blank in the packet (hardware offload)? */
  122. #define _XEN_NETTXF_csum_blank (0)
  123. #define XEN_NETTXF_csum_blank (1U<<_XEN_NETTXF_csum_blank)
  124. /* Packet data has been validated against protocol checksum. */
  125. #define _XEN_NETTXF_data_validated (1)
  126. #define XEN_NETTXF_data_validated (1U<<_XEN_NETTXF_data_validated)
  127. /* Packet continues in the next request descriptor. */
  128. #define _XEN_NETTXF_more_data (2)
  129. #define XEN_NETTXF_more_data (1U<<_XEN_NETTXF_more_data)
  130. /* Packet to be followed by extra descriptor(s). */
  131. #define _XEN_NETTXF_extra_info (3)
  132. #define XEN_NETTXF_extra_info (1U<<_XEN_NETTXF_extra_info)
  133. #define XEN_NETIF_MAX_TX_SIZE 0xFFFF
  134. struct xen_netif_tx_request {
  135. grant_ref_t gref; /* Reference to buffer page */
  136. uint16_t offset; /* Offset within buffer page */
  137. uint16_t flags; /* XEN_NETTXF_* */
  138. uint16_t id; /* Echoed in response message. */
  139. uint16_t size; /* Packet size in bytes. */
  140. };
  141. /* Types of xen_netif_extra_info descriptors. */
  142. #define XEN_NETIF_EXTRA_TYPE_NONE (0) /* Never used - invalid */
  143. #define XEN_NETIF_EXTRA_TYPE_GSO (1) /* u.gso */
  144. #define XEN_NETIF_EXTRA_TYPE_MCAST_ADD (2) /* u.mcast */
  145. #define XEN_NETIF_EXTRA_TYPE_MCAST_DEL (3) /* u.mcast */
  146. #define XEN_NETIF_EXTRA_TYPE_MAX (4)
  147. /* xen_netif_extra_info flags. */
  148. #define _XEN_NETIF_EXTRA_FLAG_MORE (0)
  149. #define XEN_NETIF_EXTRA_FLAG_MORE (1U<<_XEN_NETIF_EXTRA_FLAG_MORE)
  150. /* GSO types */
  151. #define XEN_NETIF_GSO_TYPE_NONE (0)
  152. #define XEN_NETIF_GSO_TYPE_TCPV4 (1)
  153. #define XEN_NETIF_GSO_TYPE_TCPV6 (2)
  154. /*
  155. * This structure needs to fit within both netif_tx_request and
  156. * netif_rx_response for compatibility.
  157. */
  158. struct xen_netif_extra_info {
  159. uint8_t type; /* XEN_NETIF_EXTRA_TYPE_* */
  160. uint8_t flags; /* XEN_NETIF_EXTRA_FLAG_* */
  161. union {
  162. struct {
  163. /*
  164. * Maximum payload size of each segment. For
  165. * example, for TCP this is just the path MSS.
  166. */
  167. uint16_t size;
  168. /*
  169. * GSO type. This determines the protocol of
  170. * the packet and any extra features required
  171. * to segment the packet properly.
  172. */
  173. uint8_t type; /* XEN_NETIF_GSO_TYPE_* */
  174. /* Future expansion. */
  175. uint8_t pad;
  176. /*
  177. * GSO features. This specifies any extra GSO
  178. * features required to process this packet,
  179. * such as ECN support for TCPv4.
  180. */
  181. uint16_t features; /* XEN_NETIF_GSO_FEAT_* */
  182. } gso;
  183. struct {
  184. uint8_t addr[6]; /* Address to add/remove. */
  185. } mcast;
  186. uint16_t pad[3];
  187. } u;
  188. };
  189. struct xen_netif_tx_response {
  190. uint16_t id;
  191. int16_t status; /* XEN_NETIF_RSP_* */
  192. };
  193. struct xen_netif_rx_request {
  194. uint16_t id; /* Echoed in response message. */
  195. grant_ref_t gref; /* Reference to incoming granted frame */
  196. };
  197. /* Packet data has been validated against protocol checksum. */
  198. #define _XEN_NETRXF_data_validated (0)
  199. #define XEN_NETRXF_data_validated (1U<<_XEN_NETRXF_data_validated)
  200. /* Protocol checksum field is blank in the packet (hardware offload)? */
  201. #define _XEN_NETRXF_csum_blank (1)
  202. #define XEN_NETRXF_csum_blank (1U<<_XEN_NETRXF_csum_blank)
  203. /* Packet continues in the next request descriptor. */
  204. #define _XEN_NETRXF_more_data (2)
  205. #define XEN_NETRXF_more_data (1U<<_XEN_NETRXF_more_data)
  206. /* Packet to be followed by extra descriptor(s). */
  207. #define _XEN_NETRXF_extra_info (3)
  208. #define XEN_NETRXF_extra_info (1U<<_XEN_NETRXF_extra_info)
  209. /* GSO Prefix descriptor. */
  210. #define _XEN_NETRXF_gso_prefix (4)
  211. #define XEN_NETRXF_gso_prefix (1U<<_XEN_NETRXF_gso_prefix)
  212. struct xen_netif_rx_response {
  213. uint16_t id;
  214. uint16_t offset; /* Offset in page of start of received packet */
  215. uint16_t flags; /* XEN_NETRXF_* */
  216. int16_t status; /* -ve: BLKIF_RSP_* ; +ve: Rx'ed pkt size. */
  217. };
  218. /*
  219. * Generate netif ring structures and types.
  220. */
  221. DEFINE_RING_TYPES(xen_netif_tx,
  222. struct xen_netif_tx_request,
  223. struct xen_netif_tx_response);
  224. DEFINE_RING_TYPES(xen_netif_rx,
  225. struct xen_netif_rx_request,
  226. struct xen_netif_rx_response);
  227. #define XEN_NETIF_RSP_DROPPED -2
  228. #define XEN_NETIF_RSP_ERROR -1
  229. #define XEN_NETIF_RSP_OKAY 0
  230. /* No response: used for auxiliary requests (e.g., xen_netif_extra_info). */
  231. #define XEN_NETIF_RSP_NULL 1
  232. #endif