Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
[firefly-linux-kernel-4.4.55.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  * 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  * 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 #define XEN_NETIF_MAX_TX_SIZE 0xFFFF
69 struct xen_netif_tx_request {
70     grant_ref_t gref;      /* Reference to buffer page */
71     uint16_t offset;       /* Offset within buffer page */
72     uint16_t flags;        /* XEN_NETTXF_* */
73     uint16_t id;           /* Echoed in response message. */
74     uint16_t size;         /* Packet size in bytes.       */
75 };
76
77 /* Types of xen_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_MAX        (2)
81
82 /* xen_netif_extra_info flags. */
83 #define _XEN_NETIF_EXTRA_FLAG_MORE      (0)
84 #define  XEN_NETIF_EXTRA_FLAG_MORE      (1U<<_XEN_NETIF_EXTRA_FLAG_MORE)
85
86 /* GSO types - only TCPv4 currently supported. */
87 #define XEN_NETIF_GSO_TYPE_TCPV4        (1)
88
89 /*
90  * This structure needs to fit within both netif_tx_request and
91  * netif_rx_response for compatibility.
92  */
93 struct xen_netif_extra_info {
94         uint8_t type;  /* XEN_NETIF_EXTRA_TYPE_* */
95         uint8_t flags; /* XEN_NETIF_EXTRA_FLAG_* */
96
97         union {
98                 struct {
99                         /*
100                          * Maximum payload size of each segment. For
101                          * example, for TCP this is just the path MSS.
102                          */
103                         uint16_t size;
104
105                         /*
106                          * GSO type. This determines the protocol of
107                          * the packet and any extra features required
108                          * to segment the packet properly.
109                          */
110                         uint8_t type; /* XEN_NETIF_GSO_TYPE_* */
111
112                         /* Future expansion. */
113                         uint8_t pad;
114
115                         /*
116                          * GSO features. This specifies any extra GSO
117                          * features required to process this packet,
118                          * such as ECN support for TCPv4.
119                          */
120                         uint16_t features; /* XEN_NETIF_GSO_FEAT_* */
121                 } gso;
122
123                 uint16_t pad[3];
124         } u;
125 };
126
127 struct xen_netif_tx_response {
128         uint16_t id;
129         int16_t  status;       /* XEN_NETIF_RSP_* */
130 };
131
132 struct xen_netif_rx_request {
133         uint16_t    id;        /* Echoed in response message.        */
134         grant_ref_t gref;      /* Reference to incoming granted frame */
135 };
136
137 /* Packet data has been validated against protocol checksum. */
138 #define _XEN_NETRXF_data_validated      (0)
139 #define  XEN_NETRXF_data_validated      (1U<<_XEN_NETRXF_data_validated)
140
141 /* Protocol checksum field is blank in the packet (hardware offload)? */
142 #define _XEN_NETRXF_csum_blank          (1)
143 #define  XEN_NETRXF_csum_blank          (1U<<_XEN_NETRXF_csum_blank)
144
145 /* Packet continues in the next request descriptor. */
146 #define _XEN_NETRXF_more_data           (2)
147 #define  XEN_NETRXF_more_data           (1U<<_XEN_NETRXF_more_data)
148
149 /* Packet to be followed by extra descriptor(s). */
150 #define _XEN_NETRXF_extra_info          (3)
151 #define  XEN_NETRXF_extra_info          (1U<<_XEN_NETRXF_extra_info)
152
153 /* GSO Prefix descriptor. */
154 #define _XEN_NETRXF_gso_prefix          (4)
155 #define  XEN_NETRXF_gso_prefix          (1U<<_XEN_NETRXF_gso_prefix)
156
157 struct xen_netif_rx_response {
158     uint16_t id;
159     uint16_t offset;       /* Offset in page of start of received packet  */
160     uint16_t flags;        /* XEN_NETRXF_* */
161     int16_t  status;       /* -ve: BLKIF_RSP_* ; +ve: Rx'ed pkt size. */
162 };
163
164 /*
165  * Generate netif ring structures and types.
166  */
167
168 DEFINE_RING_TYPES(xen_netif_tx,
169                   struct xen_netif_tx_request,
170                   struct xen_netif_tx_response);
171 DEFINE_RING_TYPES(xen_netif_rx,
172                   struct xen_netif_rx_request,
173                   struct xen_netif_rx_response);
174
175 #define XEN_NETIF_RSP_DROPPED   -2
176 #define XEN_NETIF_RSP_ERROR     -1
177 #define XEN_NETIF_RSP_OKAY       0
178 /* No response: used for auxiliary requests (e.g., xen_netif_extra_info). */
179 #define XEN_NETIF_RSP_NULL       1
180
181 #endif