You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

netif.h 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /******************************************************************************
  2. * netif.h
  3. *
  4. * Unified network-device I/O interface for Xen guest OSes.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to
  8. * deal in the Software without restriction, including without limitation the
  9. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  10. * sell copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  21. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  22. * DEALINGS IN THE SOFTWARE.
  23. *
  24. * Copyright (c) 2003-2004, Keir Fraser
  25. */
  26. #ifndef __XEN_PUBLIC_IO_NETIF_H__
  27. #define __XEN_PUBLIC_IO_NETIF_H__
  28. FILE_LICENCE ( MIT );
  29. #include "ring.h"
  30. #include "../grant_table.h"
  31. /*
  32. * Older implementation of Xen network frontend / backend has an
  33. * implicit dependency on the MAX_SKB_FRAGS as the maximum number of
  34. * ring slots a skb can use. Netfront / netback may not work as
  35. * expected when frontend and backend have different MAX_SKB_FRAGS.
  36. *
  37. * A better approach is to add mechanism for netfront / netback to
  38. * negotiate this value. However we cannot fix all possible
  39. * frontends, so we need to define a value which states the minimum
  40. * slots backend must support.
  41. *
  42. * The minimum value derives from older Linux kernel's MAX_SKB_FRAGS
  43. * (18), which is proved to work with most frontends. Any new backend
  44. * which doesn't negotiate with frontend should expect frontend to
  45. * send a valid packet using slots up to this value.
  46. */
  47. #define XEN_NETIF_NR_SLOTS_MIN 18
  48. /*
  49. * Notifications after enqueuing any type of message should be conditional on
  50. * the appropriate req_event or rsp_event field in the shared ring.
  51. * If the client sends notification for rx requests then it should specify
  52. * feature 'feature-rx-notify' via xenbus. Otherwise the backend will assume
  53. * that it cannot safely queue packets (as it may not be kicked to send them).
  54. */
  55. /*
  56. * "feature-split-event-channels" is introduced to separate guest TX
  57. * and RX notification. Backend either doesn't support this feature or
  58. * advertises it via xenstore as 0 (disabled) or 1 (enabled).
  59. *
  60. * To make use of this feature, frontend should allocate two event
  61. * channels for TX and RX, advertise them to backend as
  62. * "event-channel-tx" and "event-channel-rx" respectively. If frontend
  63. * doesn't want to use this feature, it just writes "event-channel"
  64. * node as before.
  65. */
  66. /*
  67. * Multiple transmit and receive queues:
  68. * If supported, the backend will write the key "multi-queue-max-queues" to
  69. * the directory for that vif, and set its value to the maximum supported
  70. * number of queues.
  71. * Frontends that are aware of this feature and wish to use it can write the
  72. * key "multi-queue-num-queues", set to the number they wish to use, which
  73. * must be greater than zero, and no more than the value reported by the backend
  74. * in "multi-queue-max-queues".
  75. *
  76. * Queues replicate the shared rings and event channels.
  77. * "feature-split-event-channels" may optionally be used when using
  78. * multiple queues, but is not mandatory.
  79. *
  80. * Each queue consists of one shared ring pair, i.e. there must be the same
  81. * number of tx and rx rings.
  82. *
  83. * For frontends requesting just one queue, the usual event-channel and
  84. * ring-ref keys are written as before, simplifying the backend processing
  85. * to avoid distinguishing between a frontend that doesn't understand the
  86. * multi-queue feature, and one that does, but requested only one queue.
  87. *
  88. * Frontends requesting two or more queues must not write the toplevel
  89. * event-channel (or event-channel-{tx,rx}) and {tx,rx}-ring-ref keys,
  90. * instead writing those keys under sub-keys having the name "queue-N" where
  91. * N is the integer ID of the queue for which those keys belong. Queues
  92. * are indexed from zero. For example, a frontend with two queues and split
  93. * event channels must write the following set of queue-related keys:
  94. *
  95. * /local/domain/1/device/vif/0/multi-queue-num-queues = "2"
  96. * /local/domain/1/device/vif/0/queue-0 = ""
  97. * /local/domain/1/device/vif/0/queue-0/tx-ring-ref = "<ring-ref-tx0>"
  98. * /local/domain/1/device/vif/0/queue-0/rx-ring-ref = "<ring-ref-rx0>"
  99. * /local/domain/1/device/vif/0/queue-0/event-channel-tx = "<evtchn-tx0>"
  100. * /local/domain/1/device/vif/0/queue-0/event-channel-rx = "<evtchn-rx0>"
  101. * /local/domain/1/device/vif/0/queue-1 = ""
  102. * /local/domain/1/device/vif/0/queue-1/tx-ring-ref = "<ring-ref-tx1>"
  103. * /local/domain/1/device/vif/0/queue-1/rx-ring-ref = "<ring-ref-rx1"
  104. * /local/domain/1/device/vif/0/queue-1/event-channel-tx = "<evtchn-tx1>"
  105. * /local/domain/1/device/vif/0/queue-1/event-channel-rx = "<evtchn-rx1>"
  106. *
  107. * If there is any inconsistency in the XenStore data, the backend may
  108. * choose not to connect any queues, instead treating the request as an
  109. * error. This includes scenarios where more (or fewer) queues were
  110. * requested than the frontend provided details for.
  111. *
  112. * Mapping of packets to queues is considered to be a function of the
  113. * transmitting system (backend or frontend) and is not negotiated
  114. * between the two. Guests are free to transmit packets on any queue
  115. * they choose, provided it has been set up correctly. Guests must be
  116. * prepared to receive packets on any queue they have requested be set up.
  117. */
  118. /*
  119. * "feature-no-csum-offload" should be used to turn IPv4 TCP/UDP checksum
  120. * offload off or on. If it is missing then the feature is assumed to be on.
  121. * "feature-ipv6-csum-offload" should be used to turn IPv6 TCP/UDP checksum
  122. * offload on or off. If it is missing then the feature is assumed to be off.
  123. */
  124. /*
  125. * "feature-gso-tcpv4" and "feature-gso-tcpv6" advertise the capability to
  126. * handle large TCP packets (in IPv4 or IPv6 form respectively). Neither
  127. * frontends nor backends are assumed to be capable unless the flags are
  128. * present.
  129. */
  130. /*
  131. * This is the 'wire' format for packets:
  132. * Request 1: netif_tx_request -- NETTXF_* (any flags)
  133. * [Request 2: netif_tx_extra] (only if request 1 has NETTXF_extra_info)
  134. * [Request 3: netif_tx_extra] (only if request 2 has XEN_NETIF_EXTRA_MORE)
  135. * Request 4: netif_tx_request -- NETTXF_more_data
  136. * Request 5: netif_tx_request -- NETTXF_more_data
  137. * ...
  138. * Request N: netif_tx_request -- 0
  139. */
  140. /* Protocol checksum field is blank in the packet (hardware offload)? */
  141. #define _NETTXF_csum_blank (0)
  142. #define NETTXF_csum_blank (1U<<_NETTXF_csum_blank)
  143. /* Packet data has been validated against protocol checksum. */
  144. #define _NETTXF_data_validated (1)
  145. #define NETTXF_data_validated (1U<<_NETTXF_data_validated)
  146. /* Packet continues in the next request descriptor. */
  147. #define _NETTXF_more_data (2)
  148. #define NETTXF_more_data (1U<<_NETTXF_more_data)
  149. /* Packet to be followed by extra descriptor(s). */
  150. #define _NETTXF_extra_info (3)
  151. #define NETTXF_extra_info (1U<<_NETTXF_extra_info)
  152. #define XEN_NETIF_MAX_TX_SIZE 0xFFFF
  153. struct netif_tx_request {
  154. grant_ref_t gref; /* Reference to buffer page */
  155. uint16_t offset; /* Offset within buffer page */
  156. uint16_t flags; /* NETTXF_* */
  157. uint16_t id; /* Echoed in response message. */
  158. uint16_t size; /* Packet size in bytes. */
  159. };
  160. typedef struct netif_tx_request netif_tx_request_t;
  161. /* Types of netif_extra_info descriptors. */
  162. #define XEN_NETIF_EXTRA_TYPE_NONE (0) /* Never used - invalid */
  163. #define XEN_NETIF_EXTRA_TYPE_GSO (1) /* u.gso */
  164. #define XEN_NETIF_EXTRA_TYPE_MCAST_ADD (2) /* u.mcast */
  165. #define XEN_NETIF_EXTRA_TYPE_MCAST_DEL (3) /* u.mcast */
  166. #define XEN_NETIF_EXTRA_TYPE_MAX (4)
  167. /* netif_extra_info flags. */
  168. #define _XEN_NETIF_EXTRA_FLAG_MORE (0)
  169. #define XEN_NETIF_EXTRA_FLAG_MORE (1U<<_XEN_NETIF_EXTRA_FLAG_MORE)
  170. /* GSO types */
  171. #define XEN_NETIF_GSO_TYPE_NONE (0)
  172. #define XEN_NETIF_GSO_TYPE_TCPV4 (1)
  173. #define XEN_NETIF_GSO_TYPE_TCPV6 (2)
  174. /*
  175. * This structure needs to fit within both netif_tx_request and
  176. * netif_rx_response for compatibility.
  177. */
  178. struct netif_extra_info {
  179. uint8_t type; /* XEN_NETIF_EXTRA_TYPE_* */
  180. uint8_t flags; /* XEN_NETIF_EXTRA_FLAG_* */
  181. union {
  182. /*
  183. * XEN_NETIF_EXTRA_TYPE_GSO:
  184. */
  185. struct {
  186. /*
  187. * Maximum payload size of each segment. For example, for TCP this
  188. * is just the path MSS.
  189. */
  190. uint16_t size;
  191. /*
  192. * GSO type. This determines the protocol of the packet and any
  193. * extra features required to segment the packet properly.
  194. */
  195. uint8_t type; /* XEN_NETIF_GSO_TYPE_* */
  196. /* Future expansion. */
  197. uint8_t pad;
  198. /*
  199. * GSO features. This specifies any extra GSO features required
  200. * to process this packet, such as ECN support for TCPv4.
  201. */
  202. uint16_t features; /* XEN_NETIF_GSO_FEAT_* */
  203. } gso;
  204. /*
  205. * XEN_NETIF_EXTRA_TYPE_MCAST_{ADD,DEL}:
  206. * Backend advertises availability via 'feature-multicast-control'
  207. * xenbus node containing value '1'.
  208. * Frontend requests this feature by advertising
  209. * 'request-multicast-control' xenbus node containing value '1'.
  210. * If multicast control is requested then multicast flooding is
  211. * disabled and the frontend must explicitly register its interest
  212. * in multicast groups using dummy transmit requests containing
  213. * MCAST_{ADD,DEL} extra-info fragments.
  214. */
  215. struct {
  216. uint8_t addr[6]; /* Address to add/remove. */
  217. } mcast;
  218. uint16_t pad[3];
  219. } u;
  220. };
  221. typedef struct netif_extra_info netif_extra_info_t;
  222. struct netif_tx_response {
  223. uint16_t id;
  224. int16_t status; /* NETIF_RSP_* */
  225. };
  226. typedef struct netif_tx_response netif_tx_response_t;
  227. struct netif_rx_request {
  228. uint16_t id; /* Echoed in response message. */
  229. grant_ref_t gref; /* Reference to incoming granted frame */
  230. };
  231. typedef struct netif_rx_request netif_rx_request_t;
  232. /* Packet data has been validated against protocol checksum. */
  233. #define _NETRXF_data_validated (0)
  234. #define NETRXF_data_validated (1U<<_NETRXF_data_validated)
  235. /* Protocol checksum field is blank in the packet (hardware offload)? */
  236. #define _NETRXF_csum_blank (1)
  237. #define NETRXF_csum_blank (1U<<_NETRXF_csum_blank)
  238. /* Packet continues in the next request descriptor. */
  239. #define _NETRXF_more_data (2)
  240. #define NETRXF_more_data (1U<<_NETRXF_more_data)
  241. /* Packet to be followed by extra descriptor(s). */
  242. #define _NETRXF_extra_info (3)
  243. #define NETRXF_extra_info (1U<<_NETRXF_extra_info)
  244. struct netif_rx_response {
  245. uint16_t id;
  246. uint16_t offset; /* Offset in page of start of received packet */
  247. uint16_t flags; /* NETRXF_* */
  248. int16_t status; /* -ve: NETIF_RSP_* ; +ve: Rx'ed pkt size. */
  249. };
  250. typedef struct netif_rx_response netif_rx_response_t;
  251. /*
  252. * Generate netif ring structures and types.
  253. */
  254. DEFINE_RING_TYPES(netif_tx, struct netif_tx_request, struct netif_tx_response);
  255. DEFINE_RING_TYPES(netif_rx, struct netif_rx_request, struct netif_rx_response);
  256. #define NETIF_RSP_DROPPED -2
  257. #define NETIF_RSP_ERROR -1
  258. #define NETIF_RSP_OKAY 0
  259. /* No response: used for auxiliary requests (e.g., netif_tx_extra). */
  260. #define NETIF_RSP_NULL 1
  261. #endif
  262. /*
  263. * Local variables:
  264. * mode: C
  265. * c-file-style: "BSD"
  266. * c-basic-offset: 4
  267. * tab-width: 4
  268. * indent-tabs-mode: nil
  269. * End:
  270. */