netif.h 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091
  1. /* SPDX-License-Identifier: MIT */
  2. /******************************************************************************
  3. * 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_NETIF_H__
  10. #define __XEN_PUBLIC_IO_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. * The setting of "trusted" node to "0" in the frontend path signals that the
  138. * frontend should not trust the backend, and should deploy whatever measures
  139. * available to protect from a malicious backend on the other end.
  140. */
  141. /*
  142. * Control ring
  143. * ============
  144. *
  145. * Some features, such as hashing (detailed below), require a
  146. * significant amount of out-of-band data to be passed from frontend to
  147. * backend. Use of xenstore is not suitable for large quantities of data
  148. * because of quota limitations and so a dedicated 'control ring' is used.
  149. * The ability of the backend to use a control ring is advertised by
  150. * setting:
  151. *
  152. * /local/domain/X/backend/vif/<domid>/<vif>/feature-ctrl-ring = "1"
  153. *
  154. * The frontend provides a control ring to the backend by setting:
  155. *
  156. * /local/domain/<domid>/device/vif/<vif>/ctrl-ring-ref = <gref>
  157. * /local/domain/<domid>/device/vif/<vif>/event-channel-ctrl = <port>
  158. *
  159. * where <gref> is the grant reference of the shared page used to
  160. * implement the control ring and <port> is an event channel to be used
  161. * as a mailbox interrupt. These keys must be set before the frontend
  162. * moves into the connected state.
  163. *
  164. * The control ring uses a fixed request/response message size and is
  165. * balanced (i.e. one request to one response), so operationally it is much
  166. * the same as a transmit or receive ring.
  167. * Note that there is no requirement that responses are issued in the same
  168. * order as requests.
  169. */
  170. /*
  171. * Link state
  172. * ==========
  173. *
  174. * The backend can advertise its current link (carrier) state to the
  175. * frontend using the /local/domain/X/backend/vif/<domid>/<vif>/carrier
  176. * node. If this node is not present, then the frontend should assume that
  177. * the link is up (for compatibility with backends that do not implement
  178. * this feature). If this node is present, then a value of "0" should be
  179. * interpreted by the frontend as the link being down (no carrier) and a
  180. * value of "1" should be interpreted as the link being up (carrier
  181. * present).
  182. */
  183. /*
  184. * MTU
  185. * ===
  186. *
  187. * The toolstack may set a value of MTU for the frontend by setting the
  188. * /local/domain/<domid>/device/vif/<vif>/mtu node with the MTU value in
  189. * octets. If this node is absent the frontend should assume an MTU value
  190. * of 1500 octets. A frontend is also at liberty to ignore this value so
  191. * it is only suitable for informing the frontend that a packet payload
  192. * >1500 octets is permitted.
  193. */
  194. /*
  195. * Hash types
  196. * ==========
  197. *
  198. * For the purposes of the definitions below, 'Packet[]' is an array of
  199. * octets containing an IP packet without options, 'Array[X..Y]' means a
  200. * sub-array of 'Array' containing bytes X thru Y inclusive, and '+' is
  201. * used to indicate concatenation of arrays.
  202. */
  203. /*
  204. * A hash calculated over an IP version 4 header as follows:
  205. *
  206. * Buffer[0..8] = Packet[12..15] (source address) +
  207. * Packet[16..19] (destination address)
  208. *
  209. * Result = Hash(Buffer, 8)
  210. */
  211. #define _XEN_NETIF_CTRL_HASH_TYPE_IPV4 0
  212. #define XEN_NETIF_CTRL_HASH_TYPE_IPV4 \
  213. (1 << _XEN_NETIF_CTRL_HASH_TYPE_IPV4)
  214. /*
  215. * A hash calculated over an IP version 4 header and TCP header as
  216. * follows:
  217. *
  218. * Buffer[0..12] = Packet[12..15] (source address) +
  219. * Packet[16..19] (destination address) +
  220. * Packet[20..21] (source port) +
  221. * Packet[22..23] (destination port)
  222. *
  223. * Result = Hash(Buffer, 12)
  224. */
  225. #define _XEN_NETIF_CTRL_HASH_TYPE_IPV4_TCP 1
  226. #define XEN_NETIF_CTRL_HASH_TYPE_IPV4_TCP \
  227. (1 << _XEN_NETIF_CTRL_HASH_TYPE_IPV4_TCP)
  228. /*
  229. * A hash calculated over an IP version 6 header as follows:
  230. *
  231. * Buffer[0..32] = Packet[8..23] (source address ) +
  232. * Packet[24..39] (destination address)
  233. *
  234. * Result = Hash(Buffer, 32)
  235. */
  236. #define _XEN_NETIF_CTRL_HASH_TYPE_IPV6 2
  237. #define XEN_NETIF_CTRL_HASH_TYPE_IPV6 \
  238. (1 << _XEN_NETIF_CTRL_HASH_TYPE_IPV6)
  239. /*
  240. * A hash calculated over an IP version 6 header and TCP header as
  241. * follows:
  242. *
  243. * Buffer[0..36] = Packet[8..23] (source address) +
  244. * Packet[24..39] (destination address) +
  245. * Packet[40..41] (source port) +
  246. * Packet[42..43] (destination port)
  247. *
  248. * Result = Hash(Buffer, 36)
  249. */
  250. #define _XEN_NETIF_CTRL_HASH_TYPE_IPV6_TCP 3
  251. #define XEN_NETIF_CTRL_HASH_TYPE_IPV6_TCP \
  252. (1 << _XEN_NETIF_CTRL_HASH_TYPE_IPV6_TCP)
  253. /*
  254. * Hash algorithms
  255. * ===============
  256. */
  257. #define XEN_NETIF_CTRL_HASH_ALGORITHM_NONE 0
  258. /*
  259. * Toeplitz hash:
  260. */
  261. #define XEN_NETIF_CTRL_HASH_ALGORITHM_TOEPLITZ 1
  262. /*
  263. * This algorithm uses a 'key' as well as the data buffer itself.
  264. * (Buffer[] and Key[] are treated as shift-registers where the MSB of
  265. * Buffer/Key[0] is considered 'left-most' and the LSB of Buffer/Key[N-1]
  266. * is the 'right-most').
  267. *
  268. * Value = 0
  269. * For number of bits in Buffer[]
  270. * If (left-most bit of Buffer[] is 1)
  271. * Value ^= left-most 32 bits of Key[]
  272. * Key[] << 1
  273. * Buffer[] << 1
  274. *
  275. * The code below is provided for convenience where an operating system
  276. * does not already provide an implementation.
  277. */
  278. #ifdef XEN_NETIF_DEFINE_TOEPLITZ
  279. static uint32_t xen_netif_toeplitz_hash(const uint8_t *key,
  280. unsigned int keylen,
  281. const uint8_t *buf,
  282. unsigned int buflen)
  283. {
  284. unsigned int keyi, bufi;
  285. uint64_t prefix = 0;
  286. uint64_t hash = 0;
  287. /* Pre-load prefix with the first 8 bytes of the key */
  288. for (keyi = 0; keyi < 8; keyi++) {
  289. prefix <<= 8;
  290. prefix |= (keyi < keylen) ? key[keyi] : 0;
  291. }
  292. for (bufi = 0; bufi < buflen; bufi++) {
  293. uint8_t byte = buf[bufi];
  294. unsigned int bit;
  295. for (bit = 0; bit < 8; bit++) {
  296. if (byte & 0x80)
  297. hash ^= prefix;
  298. prefix <<= 1;
  299. byte <<=1;
  300. }
  301. /*
  302. * 'prefix' has now been left-shifted by 8, so
  303. * OR in the next byte.
  304. */
  305. prefix |= (keyi < keylen) ? key[keyi] : 0;
  306. keyi++;
  307. }
  308. /* The valid part of the hash is in the upper 32 bits. */
  309. return hash >> 32;
  310. }
  311. #endif /* XEN_NETIF_DEFINE_TOEPLITZ */
  312. /*
  313. * Control requests (struct xen_netif_ctrl_request)
  314. * ================================================
  315. *
  316. * All requests have the following format:
  317. *
  318. * 0 1 2 3 4 5 6 7 octet
  319. * +-----+-----+-----+-----+-----+-----+-----+-----+
  320. * | id | type | data[0] |
  321. * +-----+-----+-----+-----+-----+-----+-----+-----+
  322. * | data[1] | data[2] |
  323. * +-----+-----+-----+-----+-----------------------+
  324. *
  325. * id: the request identifier, echoed in response.
  326. * type: the type of request (see below)
  327. * data[]: any data associated with the request (determined by type)
  328. */
  329. struct xen_netif_ctrl_request {
  330. uint16_t id;
  331. uint16_t type;
  332. #define XEN_NETIF_CTRL_TYPE_INVALID 0
  333. #define XEN_NETIF_CTRL_TYPE_GET_HASH_FLAGS 1
  334. #define XEN_NETIF_CTRL_TYPE_SET_HASH_FLAGS 2
  335. #define XEN_NETIF_CTRL_TYPE_SET_HASH_KEY 3
  336. #define XEN_NETIF_CTRL_TYPE_GET_HASH_MAPPING_SIZE 4
  337. #define XEN_NETIF_CTRL_TYPE_SET_HASH_MAPPING_SIZE 5
  338. #define XEN_NETIF_CTRL_TYPE_SET_HASH_MAPPING 6
  339. #define XEN_NETIF_CTRL_TYPE_SET_HASH_ALGORITHM 7
  340. #define XEN_NETIF_CTRL_TYPE_GET_GREF_MAPPING_SIZE 8
  341. #define XEN_NETIF_CTRL_TYPE_ADD_GREF_MAPPING 9
  342. #define XEN_NETIF_CTRL_TYPE_DEL_GREF_MAPPING 10
  343. uint32_t data[3];
  344. };
  345. /*
  346. * Control responses (struct xen_netif_ctrl_response)
  347. * ==================================================
  348. *
  349. * All responses have the following format:
  350. *
  351. * 0 1 2 3 4 5 6 7 octet
  352. * +-----+-----+-----+-----+-----+-----+-----+-----+
  353. * | id | type | status |
  354. * +-----+-----+-----+-----+-----+-----+-----+-----+
  355. * | data |
  356. * +-----+-----+-----+-----+
  357. *
  358. * id: the corresponding request identifier
  359. * type: the type of the corresponding request
  360. * status: the status of request processing
  361. * data: any data associated with the response (determined by type and
  362. * status)
  363. */
  364. struct xen_netif_ctrl_response {
  365. uint16_t id;
  366. uint16_t type;
  367. uint32_t status;
  368. #define XEN_NETIF_CTRL_STATUS_SUCCESS 0
  369. #define XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED 1
  370. #define XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER 2
  371. #define XEN_NETIF_CTRL_STATUS_BUFFER_OVERFLOW 3
  372. uint32_t data;
  373. };
  374. /*
  375. * Static Grants (struct xen_netif_gref)
  376. * =====================================
  377. *
  378. * A frontend may provide a fixed set of grant references to be mapped on
  379. * the backend. The message of type XEN_NETIF_CTRL_TYPE_ADD_GREF_MAPPING
  380. * prior its usage in the command ring allows for creation of these mappings.
  381. * The backend will maintain a fixed amount of these mappings.
  382. *
  383. * XEN_NETIF_CTRL_TYPE_GET_GREF_MAPPING_SIZE lets a frontend query how many
  384. * of these mappings can be kept.
  385. *
  386. * Each entry in the XEN_NETIF_CTRL_TYPE_{ADD,DEL}_GREF_MAPPING input table has
  387. * the following format:
  388. *
  389. * 0 1 2 3 4 5 6 7 octet
  390. * +-----+-----+-----+-----+-----+-----+-----+-----+
  391. * | grant ref | flags | status |
  392. * +-----+-----+-----+-----+-----+-----+-----+-----+
  393. *
  394. * grant ref: grant reference (IN)
  395. * flags: flags describing the control operation (IN)
  396. * status: XEN_NETIF_CTRL_STATUS_* (OUT)
  397. *
  398. * 'status' is an output parameter which does not require to be set to zero
  399. * prior to its usage in the corresponding control messages.
  400. */
  401. struct xen_netif_gref {
  402. grant_ref_t ref;
  403. uint16_t flags;
  404. #define _XEN_NETIF_CTRLF_GREF_readonly 0
  405. #define XEN_NETIF_CTRLF_GREF_readonly (1U<<_XEN_NETIF_CTRLF_GREF_readonly)
  406. uint16_t status;
  407. };
  408. /*
  409. * Control messages
  410. * ================
  411. *
  412. * XEN_NETIF_CTRL_TYPE_SET_HASH_ALGORITHM
  413. * --------------------------------------
  414. *
  415. * This is sent by the frontend to set the desired hash algorithm.
  416. *
  417. * Request:
  418. *
  419. * type = XEN_NETIF_CTRL_TYPE_SET_HASH_ALGORITHM
  420. * data[0] = a XEN_NETIF_CTRL_HASH_ALGORITHM_* value
  421. * data[1] = 0
  422. * data[2] = 0
  423. *
  424. * Response:
  425. *
  426. * status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED - Operation not
  427. * supported
  428. * XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER - The algorithm is not
  429. * supported
  430. * XEN_NETIF_CTRL_STATUS_SUCCESS - Operation successful
  431. *
  432. * NOTE: Setting data[0] to XEN_NETIF_CTRL_HASH_ALGORITHM_NONE disables
  433. * hashing and the backend is free to choose how it steers packets
  434. * to queues (which is the default behaviour).
  435. *
  436. * XEN_NETIF_CTRL_TYPE_GET_HASH_FLAGS
  437. * ----------------------------------
  438. *
  439. * This is sent by the frontend to query the types of hash supported by
  440. * the backend.
  441. *
  442. * Request:
  443. *
  444. * type = XEN_NETIF_CTRL_TYPE_GET_HASH_FLAGS
  445. * data[0] = 0
  446. * data[1] = 0
  447. * data[2] = 0
  448. *
  449. * Response:
  450. *
  451. * status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED - Operation not supported
  452. * XEN_NETIF_CTRL_STATUS_SUCCESS - Operation successful
  453. * data = supported hash types (if operation was successful)
  454. *
  455. * NOTE: A valid hash algorithm must be selected before this operation can
  456. * succeed.
  457. *
  458. * XEN_NETIF_CTRL_TYPE_SET_HASH_FLAGS
  459. * ----------------------------------
  460. *
  461. * This is sent by the frontend to set the types of hash that the backend
  462. * should calculate. (See above for hash type definitions).
  463. * Note that the 'maximal' type of hash should always be chosen. For
  464. * example, if the frontend sets both IPV4 and IPV4_TCP hash types then
  465. * the latter hash type should be calculated for any TCP packet and the
  466. * former only calculated for non-TCP packets.
  467. *
  468. * Request:
  469. *
  470. * type = XEN_NETIF_CTRL_TYPE_SET_HASH_FLAGS
  471. * data[0] = bitwise OR of XEN_NETIF_CTRL_HASH_TYPE_* values
  472. * data[1] = 0
  473. * data[2] = 0
  474. *
  475. * Response:
  476. *
  477. * status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED - Operation not
  478. * supported
  479. * XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER - One or more flag
  480. * value is invalid or
  481. * unsupported
  482. * XEN_NETIF_CTRL_STATUS_SUCCESS - Operation successful
  483. * data = 0
  484. *
  485. * NOTE: A valid hash algorithm must be selected before this operation can
  486. * succeed.
  487. * Also, setting data[0] to zero disables hashing and the backend
  488. * is free to choose how it steers packets to queues.
  489. *
  490. * XEN_NETIF_CTRL_TYPE_SET_HASH_KEY
  491. * --------------------------------
  492. *
  493. * This is sent by the frontend to set the key of the hash if the algorithm
  494. * requires it. (See hash algorithms above).
  495. *
  496. * Request:
  497. *
  498. * type = XEN_NETIF_CTRL_TYPE_SET_HASH_KEY
  499. * data[0] = grant reference of page containing the key (assumed to
  500. * start at beginning of grant)
  501. * data[1] = size of key in octets
  502. * data[2] = 0
  503. *
  504. * Response:
  505. *
  506. * status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED - Operation not
  507. * supported
  508. * XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER - Key size is invalid
  509. * XEN_NETIF_CTRL_STATUS_BUFFER_OVERFLOW - Key size is larger
  510. * than the backend
  511. * supports
  512. * XEN_NETIF_CTRL_STATUS_SUCCESS - Operation successful
  513. * data = 0
  514. *
  515. * NOTE: Any key octets not specified are assumed to be zero (the key
  516. * is assumed to be empty by default) and specifying a new key
  517. * invalidates any previous key, hence specifying a key size of
  518. * zero will clear the key (which ensures that the calculated hash
  519. * will always be zero).
  520. * The maximum size of key is algorithm and backend specific, but
  521. * is also limited by the single grant reference.
  522. * The grant reference may be read-only and must remain valid until
  523. * the response has been processed.
  524. *
  525. * XEN_NETIF_CTRL_TYPE_GET_HASH_MAPPING_SIZE
  526. * -----------------------------------------
  527. *
  528. * This is sent by the frontend to query the maximum size of mapping
  529. * table supported by the backend. The size is specified in terms of
  530. * table entries.
  531. *
  532. * Request:
  533. *
  534. * type = XEN_NETIF_CTRL_TYPE_GET_HASH_MAPPING_SIZE
  535. * data[0] = 0
  536. * data[1] = 0
  537. * data[2] = 0
  538. *
  539. * Response:
  540. *
  541. * status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED - Operation not supported
  542. * XEN_NETIF_CTRL_STATUS_SUCCESS - Operation successful
  543. * data = maximum number of entries allowed in the mapping table
  544. * (if operation was successful) or zero if a mapping table is
  545. * not supported (i.e. hash mapping is done only by modular
  546. * arithmetic).
  547. *
  548. * XEN_NETIF_CTRL_TYPE_SET_HASH_MAPPING_SIZE
  549. * -------------------------------------
  550. *
  551. * This is sent by the frontend to set the actual size of the mapping
  552. * table to be used by the backend. The size is specified in terms of
  553. * table entries.
  554. * Any previous table is invalidated by this message and any new table
  555. * is assumed to be zero filled.
  556. *
  557. * Request:
  558. *
  559. * type = XEN_NETIF_CTRL_TYPE_SET_HASH_MAPPING_SIZE
  560. * data[0] = number of entries in mapping table
  561. * data[1] = 0
  562. * data[2] = 0
  563. *
  564. * Response:
  565. *
  566. * status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED - Operation not
  567. * supported
  568. * XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER - Table size is invalid
  569. * XEN_NETIF_CTRL_STATUS_SUCCESS - Operation successful
  570. * data = 0
  571. *
  572. * NOTE: Setting data[0] to 0 means that hash mapping should be done
  573. * using modular arithmetic.
  574. *
  575. * XEN_NETIF_CTRL_TYPE_SET_HASH_MAPPING
  576. * ------------------------------------
  577. *
  578. * This is sent by the frontend to set the content of the table mapping
  579. * hash value to queue number. The backend should calculate the hash from
  580. * the packet header, use it as an index into the table (modulo the size
  581. * of the table) and then steer the packet to the queue number found at
  582. * that index.
  583. *
  584. * Request:
  585. *
  586. * type = XEN_NETIF_CTRL_TYPE_SET_HASH_MAPPING
  587. * data[0] = grant reference of page containing the mapping (sub-)table
  588. * (assumed to start at beginning of grant)
  589. * data[1] = size of (sub-)table in entries
  590. * data[2] = offset, in entries, of sub-table within overall table
  591. *
  592. * Response:
  593. *
  594. * status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED - Operation not
  595. * supported
  596. * XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER - Table size or content
  597. * is invalid
  598. * XEN_NETIF_CTRL_STATUS_BUFFER_OVERFLOW - Table size is larger
  599. * than the backend
  600. * supports
  601. * XEN_NETIF_CTRL_STATUS_SUCCESS - Operation successful
  602. * data = 0
  603. *
  604. * NOTE: The overall table has the following format:
  605. *
  606. * 0 1 2 3 4 5 6 7 octet
  607. * +-----+-----+-----+-----+-----+-----+-----+-----+
  608. * | mapping[0] | mapping[1] |
  609. * +-----+-----+-----+-----+-----+-----+-----+-----+
  610. * | . |
  611. * | . |
  612. * | . |
  613. * +-----+-----+-----+-----+-----+-----+-----+-----+
  614. * | mapping[N-2] | mapping[N-1] |
  615. * +-----+-----+-----+-----+-----+-----+-----+-----+
  616. *
  617. * where N is specified by a XEN_NETIF_CTRL_TYPE_SET_HASH_MAPPING_SIZE
  618. * message and each mapping must specifies a queue between 0 and
  619. * "multi-queue-num-queues" (see above).
  620. * The backend may support a mapping table larger than can be
  621. * mapped by a single grant reference. Thus sub-tables within a
  622. * larger table can be individually set by sending multiple messages
  623. * with differing offset values. Specifying a new sub-table does not
  624. * invalidate any table data outside that range.
  625. * The grant reference may be read-only and must remain valid until
  626. * the response has been processed.
  627. *
  628. * XEN_NETIF_CTRL_TYPE_GET_GREF_MAPPING_SIZE
  629. * -----------------------------------------
  630. *
  631. * This is sent by the frontend to fetch the number of grefs that can be kept
  632. * mapped in the backend.
  633. *
  634. * Request:
  635. *
  636. * type = XEN_NETIF_CTRL_TYPE_GET_GREF_MAPPING_SIZE
  637. * data[0] = queue index (assumed 0 for single queue)
  638. * data[1] = 0
  639. * data[2] = 0
  640. *
  641. * Response:
  642. *
  643. * status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED - Operation not
  644. * supported
  645. * XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER - The queue index is
  646. * out of range
  647. * XEN_NETIF_CTRL_STATUS_SUCCESS - Operation successful
  648. * data = maximum number of entries allowed in the gref mapping table
  649. * (if operation was successful) or zero if it is not supported.
  650. *
  651. * XEN_NETIF_CTRL_TYPE_ADD_GREF_MAPPING
  652. * ------------------------------------
  653. *
  654. * This is sent by the frontend for backend to map a list of grant
  655. * references.
  656. *
  657. * Request:
  658. *
  659. * type = XEN_NETIF_CTRL_TYPE_ADD_GREF_MAPPING
  660. * data[0] = queue index
  661. * data[1] = grant reference of page containing the mapping list
  662. * (r/w and assumed to start at beginning of page)
  663. * data[2] = size of list in entries
  664. *
  665. * Response:
  666. *
  667. * status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED - Operation not
  668. * supported
  669. * XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER - Operation failed
  670. * XEN_NETIF_CTRL_STATUS_SUCCESS - Operation successful
  671. *
  672. * NOTE: Each entry in the input table has the format outlined
  673. * in struct xen_netif_gref.
  674. * Contrary to XEN_NETIF_CTRL_TYPE_DEL_GREF_MAPPING, the struct
  675. * xen_netif_gref 'status' field is not used and therefore the response
  676. * 'status' determines the success of this operation. In case of
  677. * failure none of grants mappings get added in the backend.
  678. *
  679. * XEN_NETIF_CTRL_TYPE_DEL_GREF_MAPPING
  680. * ------------------------------------
  681. *
  682. * This is sent by the frontend for backend to unmap a list of grant
  683. * references.
  684. *
  685. * Request:
  686. *
  687. * type = XEN_NETIF_CTRL_TYPE_DEL_GREF_MAPPING
  688. * data[0] = queue index
  689. * data[1] = grant reference of page containing the mapping list
  690. * (r/w and assumed to start at beginning of page)
  691. * data[2] = size of list in entries
  692. *
  693. * Response:
  694. *
  695. * status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED - Operation not
  696. * supported
  697. * XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER - Operation failed
  698. * XEN_NETIF_CTRL_STATUS_SUCCESS - Operation successful
  699. * data = number of entries that were unmapped
  700. *
  701. * NOTE: Each entry in the input table has the format outlined in struct
  702. * xen_netif_gref.
  703. * The struct xen_netif_gref 'status' field determines if the entry
  704. * was successfully removed.
  705. * The entries used are only the ones representing grant references that
  706. * were previously the subject of a XEN_NETIF_CTRL_TYPE_ADD_GREF_MAPPING
  707. * operation. Any other entries will have their status set to
  708. * XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER upon completion.
  709. */
  710. DEFINE_RING_TYPES(xen_netif_ctrl,
  711. struct xen_netif_ctrl_request,
  712. struct xen_netif_ctrl_response);
  713. /*
  714. * Guest transmit
  715. * ==============
  716. *
  717. * This is the 'wire' format for transmit (frontend -> backend) packets:
  718. *
  719. * Fragment 1: netif_tx_request_t - flags = NETTXF_*
  720. * size = total packet size
  721. * [Extra 1: netif_extra_info_t] - (only if fragment 1 flags include
  722. * NETTXF_extra_info)
  723. * ...
  724. * [Extra N: netif_extra_info_t] - (only if extra N-1 flags include
  725. * XEN_NETIF_EXTRA_MORE)
  726. * ...
  727. * Fragment N: netif_tx_request_t - (only if fragment N-1 flags include
  728. * NETTXF_more_data - flags on preceding
  729. * extras are not relevant here)
  730. * flags = 0
  731. * size = fragment size
  732. *
  733. * NOTE:
  734. *
  735. * This format slightly is different from that used for receive
  736. * (backend -> frontend) packets. Specifically, in a multi-fragment
  737. * packet the actual size of fragment 1 can only be determined by
  738. * subtracting the sizes of fragments 2..N from the total packet size.
  739. *
  740. * Ring slot size is 12 octets, however not all request/response
  741. * structs use the full size.
  742. *
  743. * tx request data (netif_tx_request_t)
  744. * ------------------------------------
  745. *
  746. * 0 1 2 3 4 5 6 7 octet
  747. * +-----+-----+-----+-----+-----+-----+-----+-----+
  748. * | grant ref | offset | flags |
  749. * +-----+-----+-----+-----+-----+-----+-----+-----+
  750. * | id | size |
  751. * +-----+-----+-----+-----+
  752. *
  753. * grant ref: Reference to buffer page.
  754. * offset: Offset within buffer page.
  755. * flags: NETTXF_*.
  756. * id: request identifier, echoed in response.
  757. * size: packet size in bytes.
  758. *
  759. * tx response (netif_tx_response_t)
  760. * ---------------------------------
  761. *
  762. * 0 1 2 3 4 5 6 7 octet
  763. * +-----+-----+-----+-----+-----+-----+-----+-----+
  764. * | id | status | unused |
  765. * +-----+-----+-----+-----+-----+-----+-----+-----+
  766. * | unused |
  767. * +-----+-----+-----+-----+
  768. *
  769. * id: reflects id in transmit request
  770. * status: NETIF_RSP_*
  771. *
  772. * Guest receive
  773. * =============
  774. *
  775. * This is the 'wire' format for receive (backend -> frontend) packets:
  776. *
  777. * Fragment 1: netif_rx_request_t - flags = NETRXF_*
  778. * size = fragment size
  779. * [Extra 1: netif_extra_info_t] - (only if fragment 1 flags include
  780. * NETRXF_extra_info)
  781. * ...
  782. * [Extra N: netif_extra_info_t] - (only if extra N-1 flags include
  783. * XEN_NETIF_EXTRA_MORE)
  784. * ...
  785. * Fragment N: netif_rx_request_t - (only if fragment N-1 flags include
  786. * NETRXF_more_data - flags on preceding
  787. * extras are not relevant here)
  788. * flags = 0
  789. * size = fragment size
  790. *
  791. * NOTE:
  792. *
  793. * This format slightly is different from that used for transmit
  794. * (frontend -> backend) packets. Specifically, in a multi-fragment
  795. * packet the size of the packet can only be determined by summing the
  796. * sizes of fragments 1..N.
  797. *
  798. * Ring slot size is 8 octets.
  799. *
  800. * rx request (netif_rx_request_t)
  801. * -------------------------------
  802. *
  803. * 0 1 2 3 4 5 6 7 octet
  804. * +-----+-----+-----+-----+-----+-----+-----+-----+
  805. * | id | pad | gref |
  806. * +-----+-----+-----+-----+-----+-----+-----+-----+
  807. *
  808. * id: request identifier, echoed in response.
  809. * gref: reference to incoming granted frame.
  810. *
  811. * rx response (netif_rx_response_t)
  812. * ---------------------------------
  813. *
  814. * 0 1 2 3 4 5 6 7 octet
  815. * +-----+-----+-----+-----+-----+-----+-----+-----+
  816. * | id | offset | flags | status |
  817. * +-----+-----+-----+-----+-----+-----+-----+-----+
  818. *
  819. * id: reflects id in receive request
  820. * offset: offset in page of start of received packet
  821. * flags: NETRXF_*
  822. * status: -ve: NETIF_RSP_*; +ve: Rx'ed pkt size.
  823. *
  824. * NOTE: Historically, to support GSO on the frontend receive side, Linux
  825. * netfront does not make use of the rx response id (because, as
  826. * described below, extra info structures overlay the id field).
  827. * Instead it assumes that responses always appear in the same ring
  828. * slot as their corresponding request. Thus, to maintain
  829. * compatibility, backends must make sure this is the case.
  830. *
  831. * Extra Info
  832. * ==========
  833. *
  834. * Can be present if initial request or response has NET{T,R}XF_extra_info,
  835. * or previous extra request has XEN_NETIF_EXTRA_MORE.
  836. *
  837. * The struct therefore needs to fit into either a tx or rx slot and
  838. * is therefore limited to 8 octets.
  839. *
  840. * NOTE: Because extra info data overlays the usual request/response
  841. * structures, there is no id information in the opposite direction.
  842. * So, if an extra info overlays an rx response the frontend can
  843. * assume that it is in the same ring slot as the request that was
  844. * consumed to make the slot available, and the backend must ensure
  845. * this assumption is true.
  846. *
  847. * extra info (netif_extra_info_t)
  848. * -------------------------------
  849. *
  850. * General format:
  851. *
  852. * 0 1 2 3 4 5 6 7 octet
  853. * +-----+-----+-----+-----+-----+-----+-----+-----+
  854. * |type |flags| type specific data |
  855. * +-----+-----+-----+-----+-----+-----+-----+-----+
  856. * | padding for tx |
  857. * +-----+-----+-----+-----+
  858. *
  859. * type: XEN_NETIF_EXTRA_TYPE_*
  860. * flags: XEN_NETIF_EXTRA_FLAG_*
  861. * padding for tx: present only in the tx case due to 8 octet limit
  862. * from rx case. Not shown in type specific entries
  863. * below.
  864. *
  865. * XEN_NETIF_EXTRA_TYPE_GSO:
  866. *
  867. * 0 1 2 3 4 5 6 7 octet
  868. * +-----+-----+-----+-----+-----+-----+-----+-----+
  869. * |type |flags| size |type | pad | features |
  870. * +-----+-----+-----+-----+-----+-----+-----+-----+
  871. *
  872. * type: Must be XEN_NETIF_EXTRA_TYPE_GSO
  873. * flags: XEN_NETIF_EXTRA_FLAG_*
  874. * size: Maximum payload size of each segment. For example,
  875. * for TCP this is just the path MSS.
  876. * type: XEN_NETIF_GSO_TYPE_*: This determines the protocol of
  877. * the packet and any extra features required to segment the
  878. * packet properly.
  879. * features: EN_NETIF_GSO_FEAT_*: This specifies any extra GSO
  880. * features required to process this packet, such as ECN
  881. * support for TCPv4.
  882. *
  883. * XEN_NETIF_EXTRA_TYPE_MCAST_{ADD,DEL}:
  884. *
  885. * 0 1 2 3 4 5 6 7 octet
  886. * +-----+-----+-----+-----+-----+-----+-----+-----+
  887. * |type |flags| addr |
  888. * +-----+-----+-----+-----+-----+-----+-----+-----+
  889. *
  890. * type: Must be XEN_NETIF_EXTRA_TYPE_MCAST_{ADD,DEL}
  891. * flags: XEN_NETIF_EXTRA_FLAG_*
  892. * addr: address to add/remove
  893. *
  894. * XEN_NETIF_EXTRA_TYPE_HASH:
  895. *
  896. * A backend that supports teoplitz hashing is assumed to accept
  897. * this type of extra info in transmit packets.
  898. * A frontend that enables hashing is assumed to accept
  899. * this type of extra info in receive packets.
  900. *
  901. * 0 1 2 3 4 5 6 7 octet
  902. * +-----+-----+-----+-----+-----+-----+-----+-----+
  903. * |type |flags|htype| alg |LSB ---- value ---- MSB|
  904. * +-----+-----+-----+-----+-----+-----+-----+-----+
  905. *
  906. * type: Must be XEN_NETIF_EXTRA_TYPE_HASH
  907. * flags: XEN_NETIF_EXTRA_FLAG_*
  908. * htype: Hash type (one of _XEN_NETIF_CTRL_HASH_TYPE_* - see above)
  909. * alg: The algorithm used to calculate the hash (one of
  910. * XEN_NETIF_CTRL_HASH_TYPE_ALGORITHM_* - see above)
  911. * value: Hash value
  912. */
  913. /* Protocol checksum field is blank in the packet (hardware offload)? */
  914. #define _NETTXF_csum_blank (0)
  915. #define NETTXF_csum_blank (1U<<_NETTXF_csum_blank)
  916. /* Packet data has been validated against protocol checksum. */
  917. #define _NETTXF_data_validated (1)
  918. #define NETTXF_data_validated (1U<<_NETTXF_data_validated)
  919. /* Packet continues in the next request descriptor. */
  920. #define _NETTXF_more_data (2)
  921. #define NETTXF_more_data (1U<<_NETTXF_more_data)
  922. /* Packet to be followed by extra descriptor(s). */
  923. #define _NETTXF_extra_info (3)
  924. #define NETTXF_extra_info (1U<<_NETTXF_extra_info)
  925. #define XEN_NETIF_MAX_TX_SIZE 0xFFFF
  926. struct netif_tx_request {
  927. grant_ref_t gref;
  928. uint16_t offset;
  929. uint16_t flags;
  930. uint16_t id;
  931. uint16_t size;
  932. };
  933. typedef struct netif_tx_request netif_tx_request_t;
  934. /* Types of netif_extra_info descriptors. */
  935. #define XEN_NETIF_EXTRA_TYPE_NONE (0) /* Never used - invalid */
  936. #define XEN_NETIF_EXTRA_TYPE_GSO (1) /* u.gso */
  937. #define XEN_NETIF_EXTRA_TYPE_MCAST_ADD (2) /* u.mcast */
  938. #define XEN_NETIF_EXTRA_TYPE_MCAST_DEL (3) /* u.mcast */
  939. #define XEN_NETIF_EXTRA_TYPE_HASH (4) /* u.hash */
  940. #define XEN_NETIF_EXTRA_TYPE_MAX (5)
  941. /* netif_extra_info_t flags. */
  942. #define _XEN_NETIF_EXTRA_FLAG_MORE (0)
  943. #define XEN_NETIF_EXTRA_FLAG_MORE (1U<<_XEN_NETIF_EXTRA_FLAG_MORE)
  944. /* GSO types */
  945. #define XEN_NETIF_GSO_TYPE_NONE (0)
  946. #define XEN_NETIF_GSO_TYPE_TCPV4 (1)
  947. #define XEN_NETIF_GSO_TYPE_TCPV6 (2)
  948. /*
  949. * This structure needs to fit within both netif_tx_request_t and
  950. * netif_rx_response_t for compatibility.
  951. */
  952. struct netif_extra_info {
  953. uint8_t type;
  954. uint8_t flags;
  955. union {
  956. struct {
  957. uint16_t size;
  958. uint8_t type;
  959. uint8_t pad;
  960. uint16_t features;
  961. } gso;
  962. struct {
  963. uint8_t addr[6];
  964. } mcast;
  965. struct {
  966. uint8_t type;
  967. uint8_t algorithm;
  968. uint8_t value[4];
  969. } hash;
  970. uint16_t pad[3];
  971. } u;
  972. };
  973. typedef struct netif_extra_info netif_extra_info_t;
  974. struct netif_tx_response {
  975. uint16_t id;
  976. int16_t status;
  977. };
  978. typedef struct netif_tx_response netif_tx_response_t;
  979. struct netif_rx_request {
  980. uint16_t id; /* Echoed in response message. */
  981. uint16_t pad;
  982. grant_ref_t gref;
  983. };
  984. typedef struct netif_rx_request netif_rx_request_t;
  985. /* Packet data has been validated against protocol checksum. */
  986. #define _NETRXF_data_validated (0)
  987. #define NETRXF_data_validated (1U<<_NETRXF_data_validated)
  988. /* Protocol checksum field is blank in the packet (hardware offload)? */
  989. #define _NETRXF_csum_blank (1)
  990. #define NETRXF_csum_blank (1U<<_NETRXF_csum_blank)
  991. /* Packet continues in the next request descriptor. */
  992. #define _NETRXF_more_data (2)
  993. #define NETRXF_more_data (1U<<_NETRXF_more_data)
  994. /* Packet to be followed by extra descriptor(s). */
  995. #define _NETRXF_extra_info (3)
  996. #define NETRXF_extra_info (1U<<_NETRXF_extra_info)
  997. /* Packet has GSO prefix. Deprecated but included for compatibility */
  998. #define _NETRXF_gso_prefix (4)
  999. #define NETRXF_gso_prefix (1U<<_NETRXF_gso_prefix)
  1000. struct netif_rx_response {
  1001. uint16_t id;
  1002. uint16_t offset;
  1003. uint16_t flags;
  1004. int16_t status;
  1005. };
  1006. typedef struct netif_rx_response netif_rx_response_t;
  1007. /*
  1008. * Generate netif ring structures and types.
  1009. */
  1010. DEFINE_RING_TYPES(netif_tx, struct netif_tx_request, struct netif_tx_response);
  1011. DEFINE_RING_TYPES(netif_rx, struct netif_rx_request, struct netif_rx_response);
  1012. #define NETIF_RSP_DROPPED -2
  1013. #define NETIF_RSP_ERROR -1
  1014. #define NETIF_RSP_OKAY 0
  1015. /* No response: used for auxiliary requests (e.g., netif_extra_info_t). */
  1016. #define NETIF_RSP_NULL 1
  1017. #endif
  1018. /*
  1019. * Local variables:
  1020. * mode: C
  1021. * c-file-style: "BSD"
  1022. * c-basic-offset: 4
  1023. * tab-width: 4
  1024. * indent-tabs-mode: nil
  1025. * End:
  1026. */