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