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