Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/******************************************************************************
2 * netif.h
3 *
4 * Unified network-device I/O interface for Xen guest OSes.
5 *
6 * Copyright (c) 2003-2004, Keir Fraser
7 */
8
9#ifndef __XEN_PUBLIC_IO_NETIF_H__
10#define __XEN_PUBLIC_IO_NETIF_H__
11
12#include <xen/interface/io/ring.h>
13#include <xen/interface/grant_table.h>
14
15/*
16 * Older implementation of Xen network frontend / backend has an
17 * implicit dependency on the MAX_SKB_FRAGS as the maximum number of
18 * ring slots a skb can use. Netfront / netback may not work as
19 * expected when frontend and backend have different MAX_SKB_FRAGS.
20 *
21 * A better approach is to add mechanism for netfront / netback to
22 * negotiate this value. However we cannot fix all possible
23 * frontends, so we need to define a value which states the minimum
24 * slots backend must support.
25 *
26 * The minimum value derives from older Linux kernel's MAX_SKB_FRAGS
27 * (18), which is proved to work with most frontends. Any new backend
28 * which doesn't negotiate with frontend should expect frontend to
29 * send a valid packet using slots up to this value.
30 */
31#define XEN_NETIF_NR_SLOTS_MIN 18
32
33/*
34 * Notifications after enqueuing any type of message should be conditional on
35 * the appropriate req_event or rsp_event field in the shared ring.
36 * If the client sends notification for rx requests then it should specify
37 * feature 'feature-rx-notify' via xenbus. Otherwise the backend will assume
38 * that it cannot safely queue packets (as it may not be kicked to send them).
39 */
40
41 /*
42 * "feature-split-event-channels" is introduced to separate guest TX
43 * and RX notificaion. Backend either doesn't support this feature or
44 * advertise it via xenstore as 0 (disabled) or 1 (enabled).
45 *
46 * To make use of this feature, frontend should allocate two event
47 * channels for TX and RX, advertise them to backend as
48 * "event-channel-tx" and "event-channel-rx" respectively. If frontend
49 * doesn't want to use this feature, it just writes "event-channel"
50 * node as before.
51 */
52
53/*
54 * Multiple transmit and receive queues:
55 * If supported, the backend will write the key "multi-queue-max-queues" to
56 * the directory for that vif, and set its value to the maximum supported
57 * number of queues.
58 * Frontends that are aware of this feature and wish to use it can write the
59 * key "multi-queue-num-queues", set to the number they wish to use, which
60 * must be greater than zero, and no more than the value reported by the backend
61 * in "multi-queue-max-queues".
62 *
63 * Queues replicate the shared rings and event channels.
64 * "feature-split-event-channels" may optionally be used when using
65 * multiple queues, but is not mandatory.
66 *
67 * Each queue consists of one shared ring pair, i.e. there must be the same
68 * number of tx and rx rings.
69 *
70 * For frontends requesting just one queue, the usual event-channel and
71 * ring-ref keys are written as before, simplifying the backend processing
72 * to avoid distinguishing between a frontend that doesn't understand the
73 * multi-queue feature, and one that does, but requested only one queue.
74 *
75 * Frontends requesting two or more queues must not write the toplevel
76 * event-channel (or event-channel-{tx,rx}) and {tx,rx}-ring-ref keys,
77 * instead writing those keys under sub-keys having the name "queue-N" where
78 * N is the integer ID of the queue for which those keys belong. Queues
79 * are indexed from zero. For example, a frontend with two queues and split
80 * event channels must write the following set of queue-related keys:
81 *
82 * /local/domain/1/device/vif/0/multi-queue-num-queues = "2"
83 * /local/domain/1/device/vif/0/queue-0 = ""
84 * /local/domain/1/device/vif/0/queue-0/tx-ring-ref = "<ring-ref-tx0>"
85 * /local/domain/1/device/vif/0/queue-0/rx-ring-ref = "<ring-ref-rx0>"
86 * /local/domain/1/device/vif/0/queue-0/event-channel-tx = "<evtchn-tx0>"
87 * /local/domain/1/device/vif/0/queue-0/event-channel-rx = "<evtchn-rx0>"
88 * /local/domain/1/device/vif/0/queue-1 = ""
89 * /local/domain/1/device/vif/0/queue-1/tx-ring-ref = "<ring-ref-tx1>"
90 * /local/domain/1/device/vif/0/queue-1/rx-ring-ref = "<ring-ref-rx1"
91 * /local/domain/1/device/vif/0/queue-1/event-channel-tx = "<evtchn-tx1>"
92 * /local/domain/1/device/vif/0/queue-1/event-channel-rx = "<evtchn-rx1>"
93 *
94 * If there is any inconsistency in the XenStore data, the backend may
95 * choose not to connect any queues, instead treating the request as an
96 * error. This includes scenarios where more (or fewer) queues were
97 * requested than the frontend provided details for.
98 *
99 * Mapping of packets to queues is considered to be a function of the
100 * transmitting system (backend or frontend) and is not negotiated
101 * between the two. Guests are free to transmit packets on any queue
102 * they choose, provided it has been set up correctly. Guests must be
103 * prepared to receive packets on any queue they have requested be set up.
104 */
105
106/*
107 * "feature-no-csum-offload" should be used to turn IPv4 TCP/UDP checksum
108 * offload off or on. If it is missing then the feature is assumed to be on.
109 * "feature-ipv6-csum-offload" should be used to turn IPv6 TCP/UDP checksum
110 * offload on or off. If it is missing then the feature is assumed to be off.
111 */
112
113/*
114 * "feature-gso-tcpv4" and "feature-gso-tcpv6" advertise the capability to
115 * handle large TCP packets (in IPv4 or IPv6 form respectively). Neither
116 * frontends nor backends are assumed to be capable unless the flags are
117 * present.
118 */
119
120/*
121 * This is the 'wire' format for packets:
122 * Request 1: xen_netif_tx_request -- XEN_NETTXF_* (any flags)
123 * [Request 2: xen_netif_extra_info] (only if request 1 has XEN_NETTXF_extra_info)
124 * [Request 3: xen_netif_extra_info] (only if request 2 has XEN_NETIF_EXTRA_MORE)
125 * Request 4: xen_netif_tx_request -- XEN_NETTXF_more_data
126 * Request 5: xen_netif_tx_request -- XEN_NETTXF_more_data
127 * ...
128 * Request N: xen_netif_tx_request -- 0
129 */
130
131/* Protocol checksum field is blank in the packet (hardware offload)? */
132#define _XEN_NETTXF_csum_blank (0)
133#define XEN_NETTXF_csum_blank (1U<<_XEN_NETTXF_csum_blank)
134
135/* Packet data has been validated against protocol checksum. */
136#define _XEN_NETTXF_data_validated (1)
137#define XEN_NETTXF_data_validated (1U<<_XEN_NETTXF_data_validated)
138
139/* Packet continues in the next request descriptor. */
140#define _XEN_NETTXF_more_data (2)
141#define XEN_NETTXF_more_data (1U<<_XEN_NETTXF_more_data)
142
143/* Packet to be followed by extra descriptor(s). */
144#define _XEN_NETTXF_extra_info (3)
145#define XEN_NETTXF_extra_info (1U<<_XEN_NETTXF_extra_info)
146
147#define XEN_NETIF_MAX_TX_SIZE 0xFFFF
148struct xen_netif_tx_request {
149 grant_ref_t gref; /* Reference to buffer page */
150 uint16_t offset; /* Offset within buffer page */
151 uint16_t flags; /* XEN_NETTXF_* */
152 uint16_t id; /* Echoed in response message. */
153 uint16_t size; /* Packet size in bytes. */
154};
155
156/* Types of xen_netif_extra_info descriptors. */
157#define XEN_NETIF_EXTRA_TYPE_NONE (0) /* Never used - invalid */
158#define XEN_NETIF_EXTRA_TYPE_GSO (1) /* u.gso */
159#define XEN_NETIF_EXTRA_TYPE_MCAST_ADD (2) /* u.mcast */
160#define XEN_NETIF_EXTRA_TYPE_MCAST_DEL (3) /* u.mcast */
161#define XEN_NETIF_EXTRA_TYPE_MAX (4)
162
163/* xen_netif_extra_info flags. */
164#define _XEN_NETIF_EXTRA_FLAG_MORE (0)
165#define XEN_NETIF_EXTRA_FLAG_MORE (1U<<_XEN_NETIF_EXTRA_FLAG_MORE)
166
167/* GSO types */
168#define XEN_NETIF_GSO_TYPE_NONE (0)
169#define XEN_NETIF_GSO_TYPE_TCPV4 (1)
170#define XEN_NETIF_GSO_TYPE_TCPV6 (2)
171
172/*
173 * This structure needs to fit within both netif_tx_request and
174 * netif_rx_response for compatibility.
175 */
176struct xen_netif_extra_info {
177 uint8_t type; /* XEN_NETIF_EXTRA_TYPE_* */
178 uint8_t flags; /* XEN_NETIF_EXTRA_FLAG_* */
179
180 union {
181 struct {
182 /*
183 * Maximum payload size of each segment. For
184 * example, for TCP this is just the path MSS.
185 */
186 uint16_t size;
187
188 /*
189 * GSO type. This determines the protocol of
190 * the packet and any extra features required
191 * to segment the packet properly.
192 */
193 uint8_t type; /* XEN_NETIF_GSO_TYPE_* */
194
195 /* Future expansion. */
196 uint8_t pad;
197
198 /*
199 * GSO features. This specifies any extra GSO
200 * features required to process this packet,
201 * such as ECN support for TCPv4.
202 */
203 uint16_t features; /* XEN_NETIF_GSO_FEAT_* */
204 } gso;
205
206 struct {
207 uint8_t addr[6]; /* Address to add/remove. */
208 } mcast;
209
210 uint16_t pad[3];
211 } u;
212};
213
214struct xen_netif_tx_response {
215 uint16_t id;
216 int16_t status; /* XEN_NETIF_RSP_* */
217};
218
219struct xen_netif_rx_request {
220 uint16_t id; /* Echoed in response message. */
221 grant_ref_t gref; /* Reference to incoming granted frame */
222};
223
224/* Packet data has been validated against protocol checksum. */
225#define _XEN_NETRXF_data_validated (0)
226#define XEN_NETRXF_data_validated (1U<<_XEN_NETRXF_data_validated)
227
228/* Protocol checksum field is blank in the packet (hardware offload)? */
229#define _XEN_NETRXF_csum_blank (1)
230#define XEN_NETRXF_csum_blank (1U<<_XEN_NETRXF_csum_blank)
231
232/* Packet continues in the next request descriptor. */
233#define _XEN_NETRXF_more_data (2)
234#define XEN_NETRXF_more_data (1U<<_XEN_NETRXF_more_data)
235
236/* Packet to be followed by extra descriptor(s). */
237#define _XEN_NETRXF_extra_info (3)
238#define XEN_NETRXF_extra_info (1U<<_XEN_NETRXF_extra_info)
239
240/* GSO Prefix descriptor. */
241#define _XEN_NETRXF_gso_prefix (4)
242#define XEN_NETRXF_gso_prefix (1U<<_XEN_NETRXF_gso_prefix)
243
244struct xen_netif_rx_response {
245 uint16_t id;
246 uint16_t offset; /* Offset in page of start of received packet */
247 uint16_t flags; /* XEN_NETRXF_* */
248 int16_t status; /* -ve: BLKIF_RSP_* ; +ve: Rx'ed pkt size. */
249};
250
251/*
252 * Generate netif ring structures and types.
253 */
254
255DEFINE_RING_TYPES(xen_netif_tx,
256 struct xen_netif_tx_request,
257 struct xen_netif_tx_response);
258DEFINE_RING_TYPES(xen_netif_rx,
259 struct xen_netif_rx_request,
260 struct xen_netif_rx_response);
261
262#define XEN_NETIF_RSP_DROPPED -2
263#define XEN_NETIF_RSP_ERROR -1
264#define XEN_NETIF_RSP_OKAY 0
265/* No response: used for auxiliary requests (e.g., xen_netif_extra_info). */
266#define XEN_NETIF_RSP_NULL 1
267
268#endif