blob: 5e766ebe77f6d576f807718c1d06feb9efc37ddb [file] [log] [blame]
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -07001/******************************************************************************
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
David Howellsa1ce3922012-10-02 18:01:25 +010012#include <xen/interface/io/ring.h>
13#include <xen/interface/grant_table.h>
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -070014
15/*
Wei Liu2810e5b2013-04-22 02:20:42 +000016 * 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/*
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -070034 * 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
Wei Liua5560a62013-05-22 06:34:47 +000041 /*
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
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -070053/*
Paul Durrant146c8a72013-10-16 17:50:28 +010054 * "feature-no-csum-offload" should be used to turn IPv4 TCP/UDP checksum
55 * offload off or on. If it is missing then the feature is assumed to be on.
56 * "feature-ipv6-csum-offload" should be used to turn IPv6 TCP/UDP checksum
57 * offload on or off. If it is missing then the feature is assumed to be off.
58 */
59
60/*
Paul Durranta9468582013-10-16 17:50:31 +010061 * "feature-gso-tcpv4" and "feature-gso-tcpv6" advertise the capability to
62 * handle large TCP packets (in IPv4 or IPv6 form respectively). Neither
63 * frontends nor backends are assumed to be capable unless the flags are
64 * present.
65 */
66
67/*
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -070068 * This is the 'wire' format for packets:
Ian Campbellf942dc22011-03-15 00:06:18 +000069 * Request 1: xen_netif_tx_request -- XEN_NETTXF_* (any flags)
70 * [Request 2: xen_netif_extra_info] (only if request 1 has XEN_NETTXF_extra_info)
71 * [Request 3: xen_netif_extra_info] (only if request 2 has XEN_NETIF_EXTRA_MORE)
72 * Request 4: xen_netif_tx_request -- XEN_NETTXF_more_data
73 * Request 5: xen_netif_tx_request -- XEN_NETTXF_more_data
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -070074 * ...
Ian Campbellf942dc22011-03-15 00:06:18 +000075 * Request N: xen_netif_tx_request -- 0
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -070076 */
77
78/* Protocol checksum field is blank in the packet (hardware offload)? */
Ian Campbellf942dc22011-03-15 00:06:18 +000079#define _XEN_NETTXF_csum_blank (0)
80#define XEN_NETTXF_csum_blank (1U<<_XEN_NETTXF_csum_blank)
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -070081
82/* Packet data has been validated against protocol checksum. */
Ian Campbellf942dc22011-03-15 00:06:18 +000083#define _XEN_NETTXF_data_validated (1)
84#define XEN_NETTXF_data_validated (1U<<_XEN_NETTXF_data_validated)
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -070085
86/* Packet continues in the next request descriptor. */
Ian Campbellf942dc22011-03-15 00:06:18 +000087#define _XEN_NETTXF_more_data (2)
88#define XEN_NETTXF_more_data (1U<<_XEN_NETTXF_more_data)
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -070089
90/* Packet to be followed by extra descriptor(s). */
Ian Campbellf942dc22011-03-15 00:06:18 +000091#define _XEN_NETTXF_extra_info (3)
92#define XEN_NETTXF_extra_info (1U<<_XEN_NETTXF_extra_info)
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -070093
Wei Liu9ecd1a72013-04-22 02:20:41 +000094#define XEN_NETIF_MAX_TX_SIZE 0xFFFF
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -070095struct xen_netif_tx_request {
96 grant_ref_t gref; /* Reference to buffer page */
97 uint16_t offset; /* Offset within buffer page */
Ian Campbellf942dc22011-03-15 00:06:18 +000098 uint16_t flags; /* XEN_NETTXF_* */
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -070099 uint16_t id; /* Echoed in response message. */
100 uint16_t size; /* Packet size in bytes. */
101};
102
Ian Campbellf942dc22011-03-15 00:06:18 +0000103/* Types of xen_netif_extra_info descriptors. */
104#define XEN_NETIF_EXTRA_TYPE_NONE (0) /* Never used - invalid */
105#define XEN_NETIF_EXTRA_TYPE_GSO (1) /* u.gso */
106#define XEN_NETIF_EXTRA_TYPE_MAX (2)
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -0700107
Ian Campbellf942dc22011-03-15 00:06:18 +0000108/* xen_netif_extra_info flags. */
109#define _XEN_NETIF_EXTRA_FLAG_MORE (0)
110#define XEN_NETIF_EXTRA_FLAG_MORE (1U<<_XEN_NETIF_EXTRA_FLAG_MORE)
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -0700111
Paul Durranta9468582013-10-16 17:50:31 +0100112/* GSO types */
Ian Campbellf942dc22011-03-15 00:06:18 +0000113#define XEN_NETIF_GSO_TYPE_TCPV4 (1)
Paul Durranta9468582013-10-16 17:50:31 +0100114#define XEN_NETIF_GSO_TYPE_TCPV6 (2)
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -0700115
116/*
117 * This structure needs to fit within both netif_tx_request and
118 * netif_rx_response for compatibility.
119 */
120struct xen_netif_extra_info {
121 uint8_t type; /* XEN_NETIF_EXTRA_TYPE_* */
122 uint8_t flags; /* XEN_NETIF_EXTRA_FLAG_* */
123
124 union {
125 struct {
126 /*
127 * Maximum payload size of each segment. For
128 * example, for TCP this is just the path MSS.
129 */
130 uint16_t size;
131
132 /*
133 * GSO type. This determines the protocol of
134 * the packet and any extra features required
135 * to segment the packet properly.
136 */
137 uint8_t type; /* XEN_NETIF_GSO_TYPE_* */
138
139 /* Future expansion. */
140 uint8_t pad;
141
142 /*
143 * GSO features. This specifies any extra GSO
144 * features required to process this packet,
145 * such as ECN support for TCPv4.
146 */
147 uint16_t features; /* XEN_NETIF_GSO_FEAT_* */
148 } gso;
149
150 uint16_t pad[3];
151 } u;
152};
153
154struct xen_netif_tx_response {
155 uint16_t id;
Ian Campbellf942dc22011-03-15 00:06:18 +0000156 int16_t status; /* XEN_NETIF_RSP_* */
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -0700157};
158
159struct xen_netif_rx_request {
160 uint16_t id; /* Echoed in response message. */
161 grant_ref_t gref; /* Reference to incoming granted frame */
162};
163
164/* Packet data has been validated against protocol checksum. */
Ian Campbellf942dc22011-03-15 00:06:18 +0000165#define _XEN_NETRXF_data_validated (0)
166#define XEN_NETRXF_data_validated (1U<<_XEN_NETRXF_data_validated)
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -0700167
168/* Protocol checksum field is blank in the packet (hardware offload)? */
Ian Campbellf942dc22011-03-15 00:06:18 +0000169#define _XEN_NETRXF_csum_blank (1)
170#define XEN_NETRXF_csum_blank (1U<<_XEN_NETRXF_csum_blank)
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -0700171
172/* Packet continues in the next request descriptor. */
Ian Campbellf942dc22011-03-15 00:06:18 +0000173#define _XEN_NETRXF_more_data (2)
174#define XEN_NETRXF_more_data (1U<<_XEN_NETRXF_more_data)
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -0700175
176/* Packet to be followed by extra descriptor(s). */
Ian Campbellf942dc22011-03-15 00:06:18 +0000177#define _XEN_NETRXF_extra_info (3)
178#define XEN_NETRXF_extra_info (1U<<_XEN_NETRXF_extra_info)
179
180/* GSO Prefix descriptor. */
181#define _XEN_NETRXF_gso_prefix (4)
182#define XEN_NETRXF_gso_prefix (1U<<_XEN_NETRXF_gso_prefix)
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -0700183
184struct xen_netif_rx_response {
185 uint16_t id;
186 uint16_t offset; /* Offset in page of start of received packet */
Ian Campbellf942dc22011-03-15 00:06:18 +0000187 uint16_t flags; /* XEN_NETRXF_* */
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -0700188 int16_t status; /* -ve: BLKIF_RSP_* ; +ve: Rx'ed pkt size. */
189};
190
191/*
192 * Generate netif ring structures and types.
193 */
194
195DEFINE_RING_TYPES(xen_netif_tx,
196 struct xen_netif_tx_request,
197 struct xen_netif_tx_response);
198DEFINE_RING_TYPES(xen_netif_rx,
199 struct xen_netif_rx_request,
200 struct xen_netif_rx_response);
201
Ian Campbellf942dc22011-03-15 00:06:18 +0000202#define XEN_NETIF_RSP_DROPPED -2
203#define XEN_NETIF_RSP_ERROR -1
204#define XEN_NETIF_RSP_OKAY 0
205/* No response: used for auxiliary requests (e.g., xen_netif_extra_info). */
206#define XEN_NETIF_RSP_NULL 1
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -0700207
208#endif