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