- Update Xen patches to 3.3-rc5 and c/s 1157.
[linux-flexiantxendom0-3.2.10.git] / include / xen / interface / io / netif.h
1 /******************************************************************************
2  * netif.h
3  *
4  * Unified network-device I/O interface for Xen guest OSes.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  * DEALINGS IN THE SOFTWARE.
23  *
24  * Copyright (c) 2003-2004, Keir Fraser
25  */
26
27 #ifndef __XEN_PUBLIC_IO_NETIF_H__
28 #define __XEN_PUBLIC_IO_NETIF_H__
29
30 #include "ring.h"
31 #include "../grant_table.h"
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  * This is the 'wire' format for packets:
43  *  Request 1: xen_netif_tx_request  -- XEN_NETTXF_* (any flags)
44  * [Request 2: xen_netif_extra_info]    (only if request 1 has XEN_NETTXF_extra_info)
45  * [Request 3: xen_netif_extra_info]    (only if request 2 has XEN_NETIF_EXTRA_MORE)
46  *  Request 4: xen_netif_tx_request  -- XEN_NETTXF_more_data
47  *  Request 5: xen_netif_tx_request  -- XEN_NETTXF_more_data
48  *  ...
49  *  Request N: xen_netif_tx_request  -- 0
50  */
51
52 /* Protocol checksum field is blank in the packet (hardware offload)? */
53 #define _XEN_NETTXF_csum_blank          (0)
54 #define  XEN_NETTXF_csum_blank          (1U<<_XEN_NETTXF_csum_blank)
55
56 /* Packet data has been validated against protocol checksum. */
57 #define _XEN_NETTXF_data_validated      (1)
58 #define  XEN_NETTXF_data_validated      (1U<<_XEN_NETTXF_data_validated)
59
60 /* Packet continues in the next request descriptor. */
61 #define _XEN_NETTXF_more_data           (2)
62 #define  XEN_NETTXF_more_data           (1U<<_XEN_NETTXF_more_data)
63
64 /* Packet to be followed by extra descriptor(s). */
65 #define _XEN_NETTXF_extra_info          (3)
66 #define  XEN_NETTXF_extra_info          (1U<<_XEN_NETTXF_extra_info)
67
68 struct netif_tx_request {
69     grant_ref_t gref;      /* Reference to buffer page */
70     uint16_t offset;       /* Offset within buffer page */
71     uint16_t flags;        /* XEN_NETTXF_* */
72     uint16_t id;           /* Echoed in response message. */
73     uint16_t size;         /* Packet size in bytes.       */
74 };
75 typedef struct netif_tx_request netif_tx_request_t;
76
77 /* Types of netif_extra_info descriptors. */
78 #define XEN_NETIF_EXTRA_TYPE_NONE       (0)  /* Never used - invalid */
79 #define XEN_NETIF_EXTRA_TYPE_GSO        (1)  /* u.gso */
80 #define XEN_NETIF_EXTRA_TYPE_MCAST_ADD  (2)  /* u.mcast */
81 #define XEN_NETIF_EXTRA_TYPE_MCAST_DEL  (3)  /* u.mcast */
82 #define XEN_NETIF_EXTRA_TYPE_MAX        (4)
83
84 /* xen_netif_extra_info flags. */
85 #define _XEN_NETIF_EXTRA_FLAG_MORE      (0)
86 #define  XEN_NETIF_EXTRA_FLAG_MORE      (1U<<_XEN_NETIF_EXTRA_FLAG_MORE)
87
88 /* GSO types - only TCPv4 currently supported. */
89 #define XEN_NETIF_GSO_TYPE_TCPV4        (1)
90
91 /*
92  * This structure needs to fit within both netif_tx_request and
93  * netif_rx_response for compatibility.
94  */
95 struct netif_extra_info {
96         uint8_t type;  /* XEN_NETIF_EXTRA_TYPE_* */
97         uint8_t flags; /* XEN_NETIF_EXTRA_FLAG_* */
98
99         union {
100                 /*
101                  * XEN_NETIF_EXTRA_TYPE_GSO:
102                  */
103                 struct {
104                         /*
105                          * Maximum payload size of each segment. For
106                          * example, for TCP this is just the path MSS.
107                          */
108                         uint16_t size;
109
110                         /*
111                          * GSO type. This determines the protocol of
112                          * the packet and any extra features required
113                          * to segment the packet properly.
114                          */
115                         uint8_t type; /* XEN_NETIF_GSO_TYPE_* */
116
117                         /* Future expansion. */
118                         uint8_t pad;
119
120                         /*
121                          * GSO features. This specifies any extra GSO
122                          * features required to process this packet,
123                          * such as ECN support for TCPv4.
124                          */
125                         uint16_t features; /* XEN_NETIF_GSO_FEAT_* */
126                 } gso;
127
128                 /*
129                  * XEN_NETIF_EXTRA_TYPE_MCAST_{ADD,DEL}:
130                  * Backend advertises availability via
131                  * 'feature-multicast-control' xenbus node containing value
132                  * '1'.
133                  * Frontend requests this feature by advertising
134                  * 'request-multicast-control' xenbus node containing value
135                  * '1'. If multicast control is requested then multicast
136                  * flooding is disabled and the frontend must explicitly
137                  * register its interest in multicast groups using dummy
138                  * transmit requests containing MCAST_{ADD,DEL} extra-info
139                  * fragments.
140                  */
141                 struct {
142                         uint8_t addr[6]; /* Address to add/remove. */
143                 } mcast;
144
145                 uint16_t pad[3];
146         } u;
147 };
148 typedef struct netif_extra_info netif_extra_info_t;
149
150 struct netif_tx_response {
151         uint16_t id;
152         int16_t  status;       /* XEN_NETIF_RSP_* */
153 };
154 typedef struct netif_tx_response netif_tx_response_t;
155
156 struct netif_rx_request {
157         uint16_t    id;        /* Echoed in response message.        */
158         grant_ref_t gref;      /* Reference to incoming granted frame */
159 };
160 typedef struct netif_rx_request netif_rx_request_t;
161
162 /* Packet data has been validated against protocol checksum. */
163 #define _XEN_NETRXF_data_validated      (0)
164 #define  XEN_NETRXF_data_validated      (1U<<_XEN_NETRXF_data_validated)
165
166 /* Protocol checksum field is blank in the packet (hardware offload)? */
167 #define _XEN_NETRXF_csum_blank          (1)
168 #define  XEN_NETRXF_csum_blank          (1U<<_XEN_NETRXF_csum_blank)
169
170 /* Packet continues in the next request descriptor. */
171 #define _XEN_NETRXF_more_data           (2)
172 #define  XEN_NETRXF_more_data           (1U<<_XEN_NETRXF_more_data)
173
174 /* Packet to be followed by extra descriptor(s). */
175 #define _XEN_NETRXF_extra_info          (3)
176 #define  XEN_NETRXF_extra_info          (1U<<_XEN_NETRXF_extra_info)
177
178 /* GSO Prefix descriptor. */
179 #define _XEN_NETRXF_gso_prefix          (4)
180 #define  XEN_NETRXF_gso_prefix          (1U<<_XEN_NETRXF_gso_prefix)
181
182 struct netif_rx_response {
183     uint16_t id;
184     uint16_t offset;       /* Offset in page of start of received packet  */
185     uint16_t flags;        /* XEN_NETRXF_* */
186     int16_t  status;       /* -ve: BLKIF_RSP_* ; +ve: Rx'ed pkt size. */
187 };
188 typedef struct netif_rx_response netif_rx_response_t;
189
190 /*
191  * Generate netif ring structures and types.
192  */
193
194 #if defined(CONFIG_XEN) || defined(HAVE_XEN_PLATFORM_COMPAT_H)
195 DEFINE_RING_TYPES(netif_tx, struct netif_tx_request, struct netif_tx_response);
196 DEFINE_RING_TYPES(netif_rx, struct netif_rx_request, struct netif_rx_response);
197 #else
198 #define xen_netif_tx_request netif_tx_request
199 #define xen_netif_rx_request netif_rx_request
200 #define xen_netif_tx_response netif_tx_response
201 #define xen_netif_rx_response netif_rx_response
202 DEFINE_RING_TYPES(xen_netif_tx,
203                   struct xen_netif_tx_request,
204                   struct xen_netif_tx_response);
205 DEFINE_RING_TYPES(xen_netif_rx,
206                   struct xen_netif_rx_request,
207                   struct xen_netif_rx_response);
208 #define xen_netif_extra_info netif_extra_info
209 #endif
210
211 #define XEN_NETIF_RSP_DROPPED   -2
212 #define XEN_NETIF_RSP_ERROR     -1
213 #define XEN_NETIF_RSP_OKAY       0
214 /* No response: used for auxiliary requests (e.g., netif_tx_extra). */
215 #define XEN_NETIF_RSP_NULL       1
216
217 #endif