netif.h 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940
  1. /* SPDX-License-Identifier: MIT */
  2. /******************************************************************************
  3. * xen_netif.h
  4. *
  5. * Unified network-device I/O interface for Xen guest OSes.
  6. *
  7. * Copyright (c) 2003-2004, Keir Fraser
  8. */
  9. #ifndef __XEN_PUBLIC_IO_XEN_NETIF_H__
  10. #define __XEN_PUBLIC_IO_XEN_NETIF_H__
  11. #include "ring.h"
  12. #include "../grant_table.h"
  13. /*
  14. * Older implementation of Xen network frontend / backend has an
  15. * implicit dependency on the MAX_SKB_FRAGS as the maximum number of
  16. * ring slots a skb can use. Netfront / netback may not work as
  17. * expected when frontend and backend have different MAX_SKB_FRAGS.
  18. *
  19. * A better approach is to add mechanism for netfront / netback to
  20. * negotiate this value. However we cannot fix all possible
  21. * frontends, so we need to define a value which states the minimum
  22. * slots backend must support.
  23. *
  24. * The minimum value derives from older Linux kernel's MAX_SKB_FRAGS
  25. * (18), which is proved to work with most frontends. Any new backend
  26. * which doesn't negotiate with frontend should expect frontend to
  27. * send a valid packet using slots up to this value.
  28. */
  29. #define XEN_NETIF_NR_SLOTS_MIN 18
  30. /*
  31. * Notifications after enqueuing any type of message should be conditional on
  32. * the appropriate req_event or rsp_event field in the shared ring.
  33. * If the client sends notification for rx requests then it should specify
  34. * feature 'feature-rx-notify' via xenbus. Otherwise the backend will assume
  35. * that it cannot safely queue packets (as it may not be kicked to send them).
  36. */
  37. /*
  38. * "feature-split-event-channels" is introduced to separate guest TX
  39. * and RX notification. Backend either doesn't support this feature or
  40. * advertises it via xenstore as 0 (disabled) or 1 (enabled).
  41. *
  42. * To make use of this feature, frontend should allocate two event
  43. * channels for TX and RX, advertise them to backend as
  44. * "event-channel-tx" and "event-channel-rx" respectively. If frontend
  45. * doesn't want to use this feature, it just writes "event-channel"
  46. * node as before.
  47. */
  48. /*
  49. * Multiple transmit and receive queues:
  50. * If supported, the backend will write the key "multi-queue-max-queues" to
  51. * the directory for that vif, and set its value to the maximum supported
  52. * number of queues.
  53. * Frontends that are aware of this feature and wish to use it can write the
  54. * key "multi-queue-num-queues", set to the number they wish to use, which
  55. * must be greater than zero, and no more than the value reported by the backend
  56. * in "multi-queue-max-queues".
  57. *
  58. * Queues replicate the shared rings and event channels.
  59. * "feature-split-event-channels" may optionally be used when using
  60. * multiple queues, but is not mandatory.
  61. *
  62. * Each queue consists of one shared ring pair, i.e. there must be the same
  63. * number of tx and rx rings.
  64. *
  65. * For frontends requesting just one queue, the usual event-channel and
  66. * ring-ref keys are written as before, simplifying the backend processing
  67. * to avoid distinguishing between a frontend that doesn't understand the
  68. * multi-queue feature, and one that does, but requested only one queue.
  69. *
  70. * Frontends requesting two or more queues must not write the toplevel
  71. * event-channel (or event-channel-{tx,rx}) and {tx,rx}-ring-ref keys,
  72. * instead writing those keys under sub-keys having the name "queue-N" where
  73. * N is the integer ID of the queue for which those keys belong. Queues
  74. * are indexed from zero. For example, a frontend with two queues and split
  75. * event channels must write the following set of queue-related keys:
  76. *
  77. * /local/domain/1/device/vif/0/multi-queue-num-queues = "2"
  78. * /local/domain/1/device/vif/0/queue-0 = ""
  79. * /local/domain/1/device/vif/0/queue-0/tx-ring-ref = "<ring-ref-tx0>"
  80. * /local/domain/1/device/vif/0/queue-0/rx-ring-ref = "<ring-ref-rx0>"
  81. * /local/domain/1/device/vif/0/queue-0/event-channel-tx = "<evtchn-tx0>"
  82. * /local/domain/1/device/vif/0/queue-0/event-channel-rx = "<evtchn-rx0>"
  83. * /local/domain/1/device/vif/0/queue-1 = ""
  84. * /local/domain/1/device/vif/0/queue-1/tx-ring-ref = "<ring-ref-tx1>"
  85. * /local/domain/1/device/vif/0/queue-1/rx-ring-ref = "<ring-ref-rx1"
  86. * /local/domain/1/device/vif/0/queue-1/event-channel-tx = "<evtchn-tx1>"
  87. * /local/domain/1/device/vif/0/queue-1/event-channel-rx = "<evtchn-rx1>"
  88. *
  89. * If there is any inconsistency in the XenStore data, the backend may
  90. * choose not to connect any queues, instead treating the request as an
  91. * error. This includes scenarios where more (or fewer) queues were
  92. * requested than the frontend provided details for.
  93. *
  94. * Mapping of packets to queues is considered to be a function of the
  95. * transmitting system (backend or frontend) and is not negotiated
  96. * between the two. Guests are free to transmit packets on any queue
  97. * they choose, provided it has been set up correctly. Guests must be
  98. * prepared to receive packets on any queue they have requested be set up.
  99. */
  100. /*
  101. * "feature-no-csum-offload" should be used to turn IPv4 TCP/UDP checksum
  102. * offload off or on. If it is missing then the feature is assumed to be on.
  103. * "feature-ipv6-csum-offload" should be used to turn IPv6 TCP/UDP checksum
  104. * offload on or off. If it is missing then the feature is assumed to be off.
  105. */
  106. /*
  107. * "feature-gso-tcpv4" and "feature-gso-tcpv6" advertise the capability to
  108. * handle large TCP packets (in IPv4 or IPv6 form respectively). Neither
  109. * frontends nor backends are assumed to be capable unless the flags are
  110. * present.
  111. */
  112. /*
  113. * "feature-multicast-control" and "feature-dynamic-multicast-control"
  114. * advertise the capability to filter ethernet multicast packets in the
  115. * backend. If the frontend wishes to take advantage of this feature then
  116. * it may set "request-multicast-control". If the backend only advertises
  117. * "feature-multicast-control" then "request-multicast-control" must be set
  118. * before the frontend moves into the connected state. The backend will
  119. * sample the value on this state transition and any subsequent change in
  120. * value will have no effect. However, if the backend also advertises
  121. * "feature-dynamic-multicast-control" then "request-multicast-control"
  122. * may be set by the frontend at any time. In this case, the backend will
  123. * watch the value and re-sample on watch events.
  124. *
  125. * If the sampled value of "request-multicast-control" is set then the
  126. * backend transmit side should no longer flood multicast packets to the
  127. * frontend, it should instead drop any multicast packet that does not
  128. * match in a filter list.
  129. * The list is amended by the frontend by sending dummy transmit requests
  130. * containing XEN_NETIF_EXTRA_TYPE_MCAST_{ADD,DEL} extra-info fragments as
  131. * specified below.
  132. * Note that the filter list may be amended even if the sampled value of
  133. * "request-multicast-control" is not set, however the filter should only
  134. * be applied if it is set.
  135. */
  136. /*
  137. * "xdp-headroom" is used to request that extra space is added
  138. * for XDP processing. The value is measured in bytes and passed by
  139. * the frontend to be consistent between both ends.
  140. * If the value is greater than zero that means that
  141. * an RX response is going to be passed to an XDP program for processing.
  142. * XEN_NETIF_MAX_XDP_HEADROOM defines the maximum headroom offset in bytes
  143. *
  144. * "feature-xdp-headroom" is set to "1" by the netback side like other features
  145. * so a guest can check if an XDP program can be processed.
  146. */
  147. #define XEN_NETIF_MAX_XDP_HEADROOM 0x7FFF
  148. /*
  149. * Control ring
  150. * ============
  151. *
  152. * Some features, such as hashing (detailed below), require a
  153. * significant amount of out-of-band data to be passed from frontend to
  154. * backend. Use of xenstore is not suitable for large quantities of data
  155. * because of quota limitations and so a dedicated 'control ring' is used.
  156. * The ability of the backend to use a control ring is advertised by
  157. * setting:
  158. *
  159. * /local/domain/X/backend/<domid>/<vif>/feature-ctrl-ring = "1"
  160. *
  161. * The frontend provides a control ring to the backend by setting:
  162. *
  163. * /local/domain/<domid>/device/vif/<vif>/ctrl-ring-ref = <gref>
  164. * /local/domain/<domid>/device/vif/<vif>/event-channel-ctrl = <port>
  165. *
  166. * where <gref> is the grant reference of the shared page used to
  167. * implement the control ring and <port> is an event channel to be used
  168. * as a mailbox interrupt. These keys must be set before the frontend
  169. * moves into the connected state.
  170. *
  171. * The control ring uses a fixed request/response message size and is
  172. * balanced (i.e. one request to one response), so operationally it is much
  173. * the same as a transmit or receive ring.
  174. * Note that there is no requirement that responses are issued in the same
  175. * order as requests.
  176. */
  177. /*
  178. * Hash types
  179. * ==========
  180. *
  181. * For the purposes of the definitions below, 'Packet[]' is an array of
  182. * octets containing an IP packet without options, 'Array[X..Y]' means a
  183. * sub-array of 'Array' containing bytes X thru Y inclusive, and '+' is
  184. * used to indicate concatenation of arrays.
  185. */
  186. /*
  187. * A hash calculated over an IP version 4 header as follows:
  188. *
  189. * Buffer[0..8] = Packet[12..15] (source address) +
  190. * Packet[16..19] (destination address)
  191. *
  192. * Result = Hash(Buffer, 8)
  193. */
  194. #define _XEN_NETIF_CTRL_HASH_TYPE_IPV4 0
  195. #define XEN_NETIF_CTRL_HASH_TYPE_IPV4 \
  196. (1 << _XEN_NETIF_CTRL_HASH_TYPE_IPV4)
  197. /*
  198. * A hash calculated over an IP version 4 header and TCP header as
  199. * follows:
  200. *
  201. * Buffer[0..12] = Packet[12..15] (source address) +
  202. * Packet[16..19] (destination address) +
  203. * Packet[20..21] (source port) +
  204. * Packet[22..23] (destination port)
  205. *
  206. * Result = Hash(Buffer, 12)
  207. */
  208. #define _XEN_NETIF_CTRL_HASH_TYPE_IPV4_TCP 1
  209. #define XEN_NETIF_CTRL_HASH_TYPE_IPV4_TCP \
  210. (1 << _XEN_NETIF_CTRL_HASH_TYPE_IPV4_TCP)
  211. /*
  212. * A hash calculated over an IP version 6 header as follows:
  213. *
  214. * Buffer[0..32] = Packet[8..23] (source address ) +
  215. * Packet[24..39] (destination address)
  216. *
  217. * Result = Hash(Buffer, 32)
  218. */
  219. #define _XEN_NETIF_CTRL_HASH_TYPE_IPV6 2
  220. #define XEN_NETIF_CTRL_HASH_TYPE_IPV6 \
  221. (1 << _XEN_NETIF_CTRL_HASH_TYPE_IPV6)
  222. /*
  223. * A hash calculated over an IP version 6 header and TCP header as
  224. * follows:
  225. *
  226. * Buffer[0..36] = Packet[8..23] (source address) +
  227. * Packet[24..39] (destination address) +
  228. * Packet[40..41] (source port) +
  229. * Packet[42..43] (destination port)
  230. *
  231. * Result = Hash(Buffer, 36)
  232. */
  233. #define _XEN_NETIF_CTRL_HASH_TYPE_IPV6_TCP 3
  234. #define XEN_NETIF_CTRL_HASH_TYPE_IPV6_TCP \
  235. (1 << _XEN_NETIF_CTRL_HASH_TYPE_IPV6_TCP)
  236. /*
  237. * Hash algorithms
  238. * ===============
  239. */
  240. #define XEN_NETIF_CTRL_HASH_ALGORITHM_NONE 0
  241. /*
  242. * Toeplitz hash:
  243. */
  244. #define XEN_NETIF_CTRL_HASH_ALGORITHM_TOEPLITZ 1
  245. /*
  246. * This algorithm uses a 'key' as well as the data buffer itself.
  247. * (Buffer[] and Key[] are treated as shift-registers where the MSB of
  248. * Buffer/Key[0] is considered 'left-most' and the LSB of Buffer/Key[N-1]
  249. * is the 'right-most').
  250. *
  251. * Value = 0
  252. * For number of bits in Buffer[]
  253. * If (left-most bit of Buffer[] is 1)
  254. * Value ^= left-most 32 bits of Key[]
  255. * Key[] << 1
  256. * Buffer[] << 1
  257. *
  258. * The code below is provided for convenience where an operating system
  259. * does not already provide an implementation.
  260. */
  261. #ifdef XEN_NETIF_DEFINE_TOEPLITZ
  262. static uint32_t xen_netif_toeplitz_hash(const uint8_t *key,
  263. unsigned int keylen,
  264. const uint8_t *buf, unsigned int buflen)
  265. {
  266. unsigned int keyi, bufi;
  267. uint64_t prefix = 0;
  268. uint64_t hash = 0;
  269. /* Pre-load prefix with the first 8 bytes of the key */
  270. for (keyi = 0; keyi < 8; keyi++) {
  271. prefix <<= 8;
  272. prefix |= (keyi < keylen) ? key[keyi] : 0;
  273. }
  274. for (bufi = 0; bufi < buflen; bufi++) {
  275. uint8_t byte = buf[bufi];
  276. unsigned int bit;
  277. for (bit = 0; bit < 8; bit++) {
  278. if (byte & 0x80)
  279. hash ^= prefix;
  280. prefix <<= 1;
  281. byte <<= 1;
  282. }
  283. /*
  284. * 'prefix' has now been left-shifted by 8, so
  285. * OR in the next byte.
  286. */
  287. prefix |= (keyi < keylen) ? key[keyi] : 0;
  288. keyi++;
  289. }
  290. /* The valid part of the hash is in the upper 32 bits. */
  291. return hash >> 32;
  292. }
  293. #endif /* XEN_NETIF_DEFINE_TOEPLITZ */
  294. /*
  295. * Control requests (struct xen_netif_ctrl_request)
  296. * ================================================
  297. *
  298. * All requests have the following format:
  299. *
  300. * 0 1 2 3 4 5 6 7 octet
  301. * +-----+-----+-----+-----+-----+-----+-----+-----+
  302. * | id | type | data[0] |
  303. * +-----+-----+-----+-----+-----+-----+-----+-----+
  304. * | data[1] | data[2] |
  305. * +-----+-----+-----+-----+-----------------------+
  306. *
  307. * id: the request identifier, echoed in response.
  308. * type: the type of request (see below)
  309. * data[]: any data associated with the request (determined by type)
  310. */
  311. struct xen_netif_ctrl_request {
  312. uint16_t id;
  313. uint16_t type;
  314. #define XEN_NETIF_CTRL_TYPE_INVALID 0
  315. #define XEN_NETIF_CTRL_TYPE_GET_HASH_FLAGS 1
  316. #define XEN_NETIF_CTRL_TYPE_SET_HASH_FLAGS 2
  317. #define XEN_NETIF_CTRL_TYPE_SET_HASH_KEY 3
  318. #define XEN_NETIF_CTRL_TYPE_GET_HASH_MAPPING_SIZE 4
  319. #define XEN_NETIF_CTRL_TYPE_SET_HASH_MAPPING_SIZE 5
  320. #define XEN_NETIF_CTRL_TYPE_SET_HASH_MAPPING 6
  321. #define XEN_NETIF_CTRL_TYPE_SET_HASH_ALGORITHM 7
  322. uint32_t data[3];
  323. };
  324. /*
  325. * Control responses (struct xen_netif_ctrl_response)
  326. * ==================================================
  327. *
  328. * All responses have the following format:
  329. *
  330. * 0 1 2 3 4 5 6 7 octet
  331. * +-----+-----+-----+-----+-----+-----+-----+-----+
  332. * | id | type | status |
  333. * +-----+-----+-----+-----+-----+-----+-----+-----+
  334. * | data |
  335. * +-----+-----+-----+-----+
  336. *
  337. * id: the corresponding request identifier
  338. * type: the type of the corresponding request
  339. * status: the status of request processing
  340. * data: any data associated with the response (determined by type and
  341. * status)
  342. */
  343. struct xen_netif_ctrl_response {
  344. uint16_t id;
  345. uint16_t type;
  346. uint32_t status;
  347. #define XEN_NETIF_CTRL_STATUS_SUCCESS 0
  348. #define XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED 1
  349. #define XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER 2
  350. #define XEN_NETIF_CTRL_STATUS_BUFFER_OVERFLOW 3
  351. uint32_t data;
  352. };
  353. /*
  354. * Control messages
  355. * ================
  356. *
  357. * XEN_NETIF_CTRL_TYPE_SET_HASH_ALGORITHM
  358. * --------------------------------------
  359. *
  360. * This is sent by the frontend to set the desired hash algorithm.
  361. *
  362. * Request:
  363. *
  364. * type = XEN_NETIF_CTRL_TYPE_SET_HASH_ALGORITHM
  365. * data[0] = a XEN_NETIF_CTRL_HASH_ALGORITHM_* value
  366. * data[1] = 0
  367. * data[2] = 0
  368. *
  369. * Response:
  370. *
  371. * status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED - Operation not
  372. * supported
  373. * XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER - The algorithm is not
  374. * supported
  375. * XEN_NETIF_CTRL_STATUS_SUCCESS - Operation successful
  376. *
  377. * NOTE: Setting data[0] to XEN_NETIF_CTRL_HASH_ALGORITHM_NONE disables
  378. * hashing and the backend is free to choose how it steers packets
  379. * to queues (which is the default behaviour).
  380. *
  381. * XEN_NETIF_CTRL_TYPE_GET_HASH_FLAGS
  382. * ----------------------------------
  383. *
  384. * This is sent by the frontend to query the types of hash supported by
  385. * the backend.
  386. *
  387. * Request:
  388. *
  389. * type = XEN_NETIF_CTRL_TYPE_GET_HASH_FLAGS
  390. * data[0] = 0
  391. * data[1] = 0
  392. * data[2] = 0
  393. *
  394. * Response:
  395. *
  396. * status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED - Operation not supported
  397. * XEN_NETIF_CTRL_STATUS_SUCCESS - Operation successful
  398. * data = supported hash types (if operation was successful)
  399. *
  400. * NOTE: A valid hash algorithm must be selected before this operation can
  401. * succeed.
  402. *
  403. * XEN_NETIF_CTRL_TYPE_SET_HASH_FLAGS
  404. * ----------------------------------
  405. *
  406. * This is sent by the frontend to set the types of hash that the backend
  407. * should calculate. (See above for hash type definitions).
  408. * Note that the 'maximal' type of hash should always be chosen. For
  409. * example, if the frontend sets both IPV4 and IPV4_TCP hash types then
  410. * the latter hash type should be calculated for any TCP packet and the
  411. * former only calculated for non-TCP packets.
  412. *
  413. * Request:
  414. *
  415. * type = XEN_NETIF_CTRL_TYPE_SET_HASH_FLAGS
  416. * data[0] = bitwise OR of XEN_NETIF_CTRL_HASH_TYPE_* values
  417. * data[1] = 0
  418. * data[2] = 0
  419. *
  420. * Response:
  421. *
  422. * status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED - Operation not
  423. * supported
  424. * XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER - One or more flag
  425. * value is invalid or
  426. * unsupported
  427. * XEN_NETIF_CTRL_STATUS_SUCCESS - Operation successful
  428. * data = 0
  429. *
  430. * NOTE: A valid hash algorithm must be selected before this operation can
  431. * succeed.
  432. * Also, setting data[0] to zero disables hashing and the backend
  433. * is free to choose how it steers packets to queues.
  434. *
  435. * XEN_NETIF_CTRL_TYPE_SET_HASH_KEY
  436. * --------------------------------
  437. *
  438. * This is sent by the frontend to set the key of the hash if the algorithm
  439. * requires it. (See hash algorithms above).
  440. *
  441. * Request:
  442. *
  443. * type = XEN_NETIF_CTRL_TYPE_SET_HASH_KEY
  444. * data[0] = grant reference of page containing the key (assumed to
  445. * start at beginning of grant)
  446. * data[1] = size of key in octets
  447. * data[2] = 0
  448. *
  449. * Response:
  450. *
  451. * status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED - Operation not
  452. * supported
  453. * XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER - Key size is invalid
  454. * XEN_NETIF_CTRL_STATUS_BUFFER_OVERFLOW - Key size is larger
  455. * than the backend
  456. * supports
  457. * XEN_NETIF_CTRL_STATUS_SUCCESS - Operation successful
  458. * data = 0
  459. *
  460. * NOTE: Any key octets not specified are assumed to be zero (the key
  461. * is assumed to be empty by default) and specifying a new key
  462. * invalidates any previous key, hence specifying a key size of
  463. * zero will clear the key (which ensures that the calculated hash
  464. * will always be zero).
  465. * The maximum size of key is algorithm and backend specific, but
  466. * is also limited by the single grant reference.
  467. * The grant reference may be read-only and must remain valid until
  468. * the response has been processed.
  469. *
  470. * XEN_NETIF_CTRL_TYPE_GET_HASH_MAPPING_SIZE
  471. * -----------------------------------------
  472. *
  473. * This is sent by the frontend to query the maximum size of mapping
  474. * table supported by the backend. The size is specified in terms of
  475. * table entries.
  476. *
  477. * Request:
  478. *
  479. * type = XEN_NETIF_CTRL_TYPE_GET_HASH_MAPPING_SIZE
  480. * data[0] = 0
  481. * data[1] = 0
  482. * data[2] = 0
  483. *
  484. * Response:
  485. *
  486. * status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED - Operation not supported
  487. * XEN_NETIF_CTRL_STATUS_SUCCESS - Operation successful
  488. * data = maximum number of entries allowed in the mapping table
  489. * (if operation was successful) or zero if a mapping table is
  490. * not supported (i.e. hash mapping is done only by modular
  491. * arithmetic).
  492. *
  493. * XEN_NETIF_CTRL_TYPE_SET_HASH_MAPPING_SIZE
  494. * -------------------------------------
  495. *
  496. * This is sent by the frontend to set the actual size of the mapping
  497. * table to be used by the backend. The size is specified in terms of
  498. * table entries.
  499. * Any previous table is invalidated by this message and any new table
  500. * is assumed to be zero filled.
  501. *
  502. * Request:
  503. *
  504. * type = XEN_NETIF_CTRL_TYPE_SET_HASH_MAPPING_SIZE
  505. * data[0] = number of entries in mapping table
  506. * data[1] = 0
  507. * data[2] = 0
  508. *
  509. * Response:
  510. *
  511. * status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED - Operation not
  512. * supported
  513. * XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER - Table size is invalid
  514. * XEN_NETIF_CTRL_STATUS_SUCCESS - Operation successful
  515. * data = 0
  516. *
  517. * NOTE: Setting data[0] to 0 means that hash mapping should be done
  518. * using modular arithmetic.
  519. *
  520. * XEN_NETIF_CTRL_TYPE_SET_HASH_MAPPING
  521. * ------------------------------------
  522. *
  523. * This is sent by the frontend to set the content of the table mapping
  524. * hash value to queue number. The backend should calculate the hash from
  525. * the packet header, use it as an index into the table (modulo the size
  526. * of the table) and then steer the packet to the queue number found at
  527. * that index.
  528. *
  529. * Request:
  530. *
  531. * type = XEN_NETIF_CTRL_TYPE_SET_HASH_MAPPING
  532. * data[0] = grant reference of page containing the mapping (sub-)table
  533. * (assumed to start at beginning of grant)
  534. * data[1] = size of (sub-)table in entries
  535. * data[2] = offset, in entries, of sub-table within overall table
  536. *
  537. * Response:
  538. *
  539. * status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED - Operation not
  540. * supported
  541. * XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER - Table size or content
  542. * is invalid
  543. * XEN_NETIF_CTRL_STATUS_BUFFER_OVERFLOW - Table size is larger
  544. * than the backend
  545. * supports
  546. * XEN_NETIF_CTRL_STATUS_SUCCESS - Operation successful
  547. * data = 0
  548. *
  549. * NOTE: The overall table has the following format:
  550. *
  551. * 0 1 2 3 4 5 6 7 octet
  552. * +-----+-----+-----+-----+-----+-----+-----+-----+
  553. * | mapping[0] | mapping[1] |
  554. * +-----+-----+-----+-----+-----+-----+-----+-----+
  555. * | . |
  556. * | . |
  557. * | . |
  558. * +-----+-----+-----+-----+-----+-----+-----+-----+
  559. * | mapping[N-2] | mapping[N-1] |
  560. * +-----+-----+-----+-----+-----+-----+-----+-----+
  561. *
  562. * where N is specified by a XEN_NETIF_CTRL_TYPE_SET_HASH_MAPPING_SIZE
  563. * message and each mapping must specifies a queue between 0 and
  564. * "multi-queue-num-queues" (see above).
  565. * The backend may support a mapping table larger than can be
  566. * mapped by a single grant reference. Thus sub-tables within a
  567. * larger table can be individually set by sending multiple messages
  568. * with differing offset values. Specifying a new sub-table does not
  569. * invalidate any table data outside that range.
  570. * The grant reference may be read-only and must remain valid until
  571. * the response has been processed.
  572. */
  573. DEFINE_RING_TYPES(xen_netif_ctrl,
  574. struct xen_netif_ctrl_request,
  575. struct xen_netif_ctrl_response);
  576. /*
  577. * Guest transmit
  578. * ==============
  579. *
  580. * This is the 'wire' format for transmit (frontend -> backend) packets:
  581. *
  582. * Fragment 1: xen_netif_tx_request_t - flags = XEN_NETTXF_*
  583. * size = total packet size
  584. * [Extra 1: xen_netif_extra_info_t] - (only if fragment 1 flags include
  585. * XEN_NETTXF_extra_info)
  586. * ...
  587. * [Extra N: xen_netif_extra_info_t] - (only if extra N-1 flags include
  588. * XEN_NETIF_EXTRA_MORE)
  589. * ...
  590. * Fragment N: xen_netif_tx_request_t - (only if fragment N-1 flags include
  591. * XEN_NETTXF_more_data - flags on preceding
  592. * extras are not relevant here)
  593. * flags = 0
  594. * size = fragment size
  595. *
  596. * NOTE:
  597. *
  598. * This format slightly is different from that used for receive
  599. * (backend -> frontend) packets. Specifically, in a multi-fragment
  600. * packet the actual size of fragment 1 can only be determined by
  601. * subtracting the sizes of fragments 2..N from the total packet size.
  602. *
  603. * Ring slot size is 12 octets, however not all request/response
  604. * structs use the full size.
  605. *
  606. * tx request data (xen_netif_tx_request_t)
  607. * ------------------------------------
  608. *
  609. * 0 1 2 3 4 5 6 7 octet
  610. * +-----+-----+-----+-----+-----+-----+-----+-----+
  611. * | grant ref | offset | flags |
  612. * +-----+-----+-----+-----+-----+-----+-----+-----+
  613. * | id | size |
  614. * +-----+-----+-----+-----+
  615. *
  616. * grant ref: Reference to buffer page.
  617. * offset: Offset within buffer page.
  618. * flags: XEN_NETTXF_*.
  619. * id: request identifier, echoed in response.
  620. * size: packet size in bytes.
  621. *
  622. * tx response (xen_netif_tx_response_t)
  623. * ---------------------------------
  624. *
  625. * 0 1 2 3 4 5 6 7 octet
  626. * +-----+-----+-----+-----+-----+-----+-----+-----+
  627. * | id | status | unused |
  628. * +-----+-----+-----+-----+-----+-----+-----+-----+
  629. * | unused |
  630. * +-----+-----+-----+-----+
  631. *
  632. * id: reflects id in transmit request
  633. * status: XEN_NETIF_RSP_*
  634. *
  635. * Guest receive
  636. * =============
  637. *
  638. * This is the 'wire' format for receive (backend -> frontend) packets:
  639. *
  640. * Fragment 1: xen_netif_rx_request_t - flags = XEN_NETRXF_*
  641. * size = fragment size
  642. * [Extra 1: xen_netif_extra_info_t] - (only if fragment 1 flags include
  643. * XEN_NETRXF_extra_info)
  644. * ...
  645. * [Extra N: xen_netif_extra_info_t] - (only if extra N-1 flags include
  646. * XEN_NETIF_EXTRA_MORE)
  647. * ...
  648. * Fragment N: xen_netif_rx_request_t - (only if fragment N-1 flags include
  649. * XEN_NETRXF_more_data - flags on preceding
  650. * extras are not relevant here)
  651. * flags = 0
  652. * size = fragment size
  653. *
  654. * NOTE:
  655. *
  656. * This format slightly is different from that used for transmit
  657. * (frontend -> backend) packets. Specifically, in a multi-fragment
  658. * packet the size of the packet can only be determined by summing the
  659. * sizes of fragments 1..N.
  660. *
  661. * Ring slot size is 8 octets.
  662. *
  663. * rx request (xen_netif_rx_request_t)
  664. * -------------------------------
  665. *
  666. * 0 1 2 3 4 5 6 7 octet
  667. * +-----+-----+-----+-----+-----+-----+-----+-----+
  668. * | id | pad | gref |
  669. * +-----+-----+-----+-----+-----+-----+-----+-----+
  670. *
  671. * id: request identifier, echoed in response.
  672. * gref: reference to incoming granted frame.
  673. *
  674. * rx response (xen_netif_rx_response_t)
  675. * ---------------------------------
  676. *
  677. * 0 1 2 3 4 5 6 7 octet
  678. * +-----+-----+-----+-----+-----+-----+-----+-----+
  679. * | id | offset | flags | status |
  680. * +-----+-----+-----+-----+-----+-----+-----+-----+
  681. *
  682. * id: reflects id in receive request
  683. * offset: offset in page of start of received packet
  684. * flags: XEN_NETRXF_*
  685. * status: -ve: XEN_NETIF_RSP_*; +ve: Rx'ed pkt size.
  686. *
  687. * NOTE: Historically, to support GSO on the frontend receive side, Linux
  688. * netfront does not make use of the rx response id (because, as
  689. * described below, extra info structures overlay the id field).
  690. * Instead it assumes that responses always appear in the same ring
  691. * slot as their corresponding request. Thus, to maintain
  692. * compatibility, backends must make sure this is the case.
  693. *
  694. * Extra Info
  695. * ==========
  696. *
  697. * Can be present if initial request or response has NET{T,R}XF_extra_info,
  698. * or previous extra request has XEN_NETIF_EXTRA_MORE.
  699. *
  700. * The struct therefore needs to fit into either a tx or rx slot and
  701. * is therefore limited to 8 octets.
  702. *
  703. * NOTE: Because extra info data overlays the usual request/response
  704. * structures, there is no id information in the opposite direction.
  705. * So, if an extra info overlays an rx response the frontend can
  706. * assume that it is in the same ring slot as the request that was
  707. * consumed to make the slot available, and the backend must ensure
  708. * this assumption is true.
  709. *
  710. * extra info (xen_netif_extra_info_t)
  711. * -------------------------------
  712. *
  713. * General format:
  714. *
  715. * 0 1 2 3 4 5 6 7 octet
  716. * +-----+-----+-----+-----+-----+-----+-----+-----+
  717. * |type |flags| type specific data |
  718. * +-----+-----+-----+-----+-----+-----+-----+-----+
  719. * | padding for tx |
  720. * +-----+-----+-----+-----+
  721. *
  722. * type: XEN_NETIF_EXTRA_TYPE_*
  723. * flags: XEN_NETIF_EXTRA_FLAG_*
  724. * padding for tx: present only in the tx case due to 8 octet limit
  725. * from rx case. Not shown in type specific entries
  726. * below.
  727. *
  728. * XEN_NETIF_EXTRA_TYPE_GSO:
  729. *
  730. * 0 1 2 3 4 5 6 7 octet
  731. * +-----+-----+-----+-----+-----+-----+-----+-----+
  732. * |type |flags| size |type | pad | features |
  733. * +-----+-----+-----+-----+-----+-----+-----+-----+
  734. *
  735. * type: Must be XEN_NETIF_EXTRA_TYPE_GSO
  736. * flags: XEN_NETIF_EXTRA_FLAG_*
  737. * size: Maximum payload size of each segment. For example,
  738. * for TCP this is just the path MSS.
  739. * type: XEN_NETIF_GSO_TYPE_*: This determines the protocol of
  740. * the packet and any extra features required to segment the
  741. * packet properly.
  742. * features: EN_XEN_NETIF_GSO_FEAT_*: This specifies any extra GSO
  743. * features required to process this packet, such as ECN
  744. * support for TCPv4.
  745. *
  746. * XEN_NETIF_EXTRA_TYPE_MCAST_{ADD,DEL}:
  747. *
  748. * 0 1 2 3 4 5 6 7 octet
  749. * +-----+-----+-----+-----+-----+-----+-----+-----+
  750. * |type |flags| addr |
  751. * +-----+-----+-----+-----+-----+-----+-----+-----+
  752. *
  753. * type: Must be XEN_NETIF_EXTRA_TYPE_MCAST_{ADD,DEL}
  754. * flags: XEN_NETIF_EXTRA_FLAG_*
  755. * addr: address to add/remove
  756. *
  757. * XEN_NETIF_EXTRA_TYPE_HASH:
  758. *
  759. * A backend that supports teoplitz hashing is assumed to accept
  760. * this type of extra info in transmit packets.
  761. * A frontend that enables hashing is assumed to accept
  762. * this type of extra info in receive packets.
  763. *
  764. * 0 1 2 3 4 5 6 7 octet
  765. * +-----+-----+-----+-----+-----+-----+-----+-----+
  766. * |type |flags|htype| alg |LSB ---- value ---- MSB|
  767. * +-----+-----+-----+-----+-----+-----+-----+-----+
  768. *
  769. * type: Must be XEN_NETIF_EXTRA_TYPE_HASH
  770. * flags: XEN_NETIF_EXTRA_FLAG_*
  771. * htype: Hash type (one of _XEN_NETIF_CTRL_HASH_TYPE_* - see above)
  772. * alg: The algorithm used to calculate the hash (one of
  773. * XEN_NETIF_CTRL_HASH_TYPE_ALGORITHM_* - see above)
  774. * value: Hash value
  775. */
  776. /* Protocol checksum field is blank in the packet (hardware offload)? */
  777. #define _XEN_NETTXF_csum_blank (0)
  778. #define XEN_NETTXF_csum_blank (1U<<_XEN_NETTXF_csum_blank)
  779. /* Packet data has been validated against protocol checksum. */
  780. #define _XEN_NETTXF_data_validated (1)
  781. #define XEN_NETTXF_data_validated (1U<<_XEN_NETTXF_data_validated)
  782. /* Packet continues in the next request descriptor. */
  783. #define _XEN_NETTXF_more_data (2)
  784. #define XEN_NETTXF_more_data (1U<<_XEN_NETTXF_more_data)
  785. /* Packet to be followed by extra descriptor(s). */
  786. #define _XEN_NETTXF_extra_info (3)
  787. #define XEN_NETTXF_extra_info (1U<<_XEN_NETTXF_extra_info)
  788. #define XEN_NETIF_MAX_TX_SIZE 0xFFFF
  789. struct xen_netif_tx_request {
  790. grant_ref_t gref;
  791. uint16_t offset;
  792. uint16_t flags;
  793. uint16_t id;
  794. uint16_t size;
  795. };
  796. /* Types of xen_netif_extra_info descriptors. */
  797. #define XEN_NETIF_EXTRA_TYPE_NONE (0) /* Never used - invalid */
  798. #define XEN_NETIF_EXTRA_TYPE_GSO (1) /* u.gso */
  799. #define XEN_NETIF_EXTRA_TYPE_MCAST_ADD (2) /* u.mcast */
  800. #define XEN_NETIF_EXTRA_TYPE_MCAST_DEL (3) /* u.mcast */
  801. #define XEN_NETIF_EXTRA_TYPE_HASH (4) /* u.hash */
  802. #define XEN_NETIF_EXTRA_TYPE_XDP (5) /* u.xdp */
  803. #define XEN_NETIF_EXTRA_TYPE_MAX (6)
  804. /* xen_netif_extra_info_t flags. */
  805. #define _XEN_NETIF_EXTRA_FLAG_MORE (0)
  806. #define XEN_NETIF_EXTRA_FLAG_MORE (1U<<_XEN_NETIF_EXTRA_FLAG_MORE)
  807. /* GSO types */
  808. #define XEN_NETIF_GSO_TYPE_NONE (0)
  809. #define XEN_NETIF_GSO_TYPE_TCPV4 (1)
  810. #define XEN_NETIF_GSO_TYPE_TCPV6 (2)
  811. /*
  812. * This structure needs to fit within both xen_netif_tx_request_t and
  813. * xen_netif_rx_response_t for compatibility.
  814. */
  815. struct xen_netif_extra_info {
  816. uint8_t type;
  817. uint8_t flags;
  818. union {
  819. struct {
  820. uint16_t size;
  821. uint8_t type;
  822. uint8_t pad;
  823. uint16_t features;
  824. } gso;
  825. struct {
  826. uint8_t addr[6];
  827. } mcast;
  828. struct {
  829. uint8_t type;
  830. uint8_t algorithm;
  831. uint8_t value[4];
  832. } hash;
  833. struct {
  834. uint16_t headroom;
  835. uint16_t pad[2];
  836. } xdp;
  837. uint16_t pad[3];
  838. } u;
  839. };
  840. struct xen_netif_tx_response {
  841. uint16_t id;
  842. int16_t status;
  843. };
  844. struct xen_netif_rx_request {
  845. uint16_t id; /* Echoed in response message. */
  846. uint16_t pad;
  847. grant_ref_t gref;
  848. };
  849. /* Packet data has been validated against protocol checksum. */
  850. #define _XEN_NETRXF_data_validated (0)
  851. #define XEN_NETRXF_data_validated (1U<<_XEN_NETRXF_data_validated)
  852. /* Protocol checksum field is blank in the packet (hardware offload)? */
  853. #define _XEN_NETRXF_csum_blank (1)
  854. #define XEN_NETRXF_csum_blank (1U<<_XEN_NETRXF_csum_blank)
  855. /* Packet continues in the next request descriptor. */
  856. #define _XEN_NETRXF_more_data (2)
  857. #define XEN_NETRXF_more_data (1U<<_XEN_NETRXF_more_data)
  858. /* Packet to be followed by extra descriptor(s). */
  859. #define _XEN_NETRXF_extra_info (3)
  860. #define XEN_NETRXF_extra_info (1U<<_XEN_NETRXF_extra_info)
  861. /* Packet has GSO prefix. Deprecated but included for compatibility */
  862. #define _XEN_NETRXF_gso_prefix (4)
  863. #define XEN_NETRXF_gso_prefix (1U<<_XEN_NETRXF_gso_prefix)
  864. struct xen_netif_rx_response {
  865. uint16_t id;
  866. uint16_t offset;
  867. uint16_t flags;
  868. int16_t status;
  869. };
  870. /*
  871. * Generate xen_netif ring structures and types.
  872. */
  873. DEFINE_RING_TYPES(xen_netif_tx, struct xen_netif_tx_request,
  874. struct xen_netif_tx_response);
  875. DEFINE_RING_TYPES(xen_netif_rx, struct xen_netif_rx_request,
  876. struct xen_netif_rx_response);
  877. #define XEN_NETIF_RSP_DROPPED -2
  878. #define XEN_NETIF_RSP_ERROR -1
  879. #define XEN_NETIF_RSP_OKAY 0
  880. /* No response: used for auxiliary requests (e.g., xen_netif_extra_info_t). */
  881. #define XEN_NETIF_RSP_NULL 1
  882. #endif