netif.h 34 KB

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