1/* $NetBSD: netif.h,v 1.6 2011/12/07 15:04:18 cegger Exp $ */
2/******************************************************************************
3 * netif.h
4 *
5 * Unified network-device I/O interface for Xen guest OSes.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to
9 * deal in the Software without restriction, including without limitation the
10 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
11 * sell copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
24 *
25 * Copyright (c) 2003-2004, Keir Fraser
26 */
27
28#ifndef __XEN_PUBLIC_IO_NETIF_H__
29#define __XEN_PUBLIC_IO_NETIF_H__
30
31#include "ring.h"
32#include "../grant_table.h"
33
34/*
35 * Notifications after enqueuing any type of message should be conditional on
36 * the appropriate req_event or rsp_event field in the shared ring.
37 * If the client sends notification for rx requests then it should specify
38 * feature 'feature-rx-notify' via xenbus. Otherwise the backend will assume
39 * that it cannot safely queue packets (as it may not be kicked to send them).
40 */
41
42/*
43 * This is the 'wire' format for packets:
44 * Request 1: netif_tx_request -- NETTXF_* (any flags)
45 * [Request 2: netif_tx_extra] (only if request 1 has NETTXF_extra_info)
46 * [Request 3: netif_tx_extra] (only if request 2 has XEN_NETIF_EXTRA_MORE)
47 * Request 4: netif_tx_request -- NETTXF_more_data
48 * Request 5: netif_tx_request -- NETTXF_more_data
49 * ...
50 * Request N: netif_tx_request -- 0
51 */
52
53/* Protocol checksum field is blank in the packet (hardware offload)? */
54#define _NETTXF_csum_blank (0)
55#define NETTXF_csum_blank (1U<<_NETTXF_csum_blank)
56
57/* Packet data has been validated against protocol checksum. */
58#define _NETTXF_data_validated (1)
59#define NETTXF_data_validated (1U<<_NETTXF_data_validated)
60
61/* Packet continues in the next request descriptor. */
62#define _NETTXF_more_data (2)
63#define NETTXF_more_data (1U<<_NETTXF_more_data)
64
65/* Packet to be followed by extra descriptor(s). */
66#define _NETTXF_extra_info (3)
67#define NETTXF_extra_info (1U<<_NETTXF_extra_info)
68
69struct netif_tx_request {
70 grant_ref_t gref; /* Reference to buffer page */
71 uint16_t offset; /* Offset within buffer page */
72 uint16_t flags; /* NETTXF_* */
73 uint16_t id; /* Echoed in response message. */
74 uint16_t size; /* Packet size in bytes. */
75};
76typedef struct netif_tx_request netif_tx_request_t;
77
78/* Types of netif_extra_info descriptors. */
79#define XEN_NETIF_EXTRA_TYPE_NONE (0) /* Never used - invalid */
80#define XEN_NETIF_EXTRA_TYPE_GSO (1) /* u.gso */
81#define XEN_NETIF_EXTRA_TYPE_MCAST_ADD (2) /* u.mcast */
82#define XEN_NETIF_EXTRA_TYPE_MCAST_DEL (3) /* u.mcast */
83#define XEN_NETIF_EXTRA_TYPE_MAX (4)
84
85/* netif_extra_info flags. */
86#define _XEN_NETIF_EXTRA_FLAG_MORE (0)
87#define XEN_NETIF_EXTRA_FLAG_MORE (1U<<_XEN_NETIF_EXTRA_FLAG_MORE)
88
89/* GSO types - only TCPv4 currently supported. */
90#define XEN_NETIF_GSO_TYPE_TCPV4 (1)
91
92/*
93 * This structure needs to fit within both netif_tx_request and
94 * netif_rx_response for compatibility.
95 */
96struct netif_extra_info {
97 uint8_t type; /* XEN_NETIF_EXTRA_TYPE_* */
98 uint8_t flags; /* XEN_NETIF_EXTRA_FLAG_* */
99
100 union {
101 /*
102 * XEN_NETIF_EXTRA_TYPE_GSO:
103 */
104 struct {
105 /*
106 * Maximum payload size of each segment. For example, for TCP this
107 * is just the path MSS.
108 */
109 uint16_t size;
110
111 /*
112 * GSO type. This determines the protocol of the packet and any
113 * extra features required 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 features required
122 * to process this packet, such as ECN support for TCPv4.
123 */
124 uint16_t features; /* XEN_NETIF_GSO_FEAT_* */
125 } gso;
126
127 /*
128 * XEN_NETIF_EXTRA_TYPE_MCAST_{ADD,DEL}:
129 * Backend advertises availability via 'feature-multicast-control'
130 * xenbus node containing value '1'.
131 * Frontend requests this feature by advertising
132 * 'request-multicast-control' xenbus node containing value '1'.
133 * If multicast control is requested then multicast flooding is
134 * disabled and the frontend must explicitly register its interest
135 * in multicast groups using dummy transmit requests containing
136 * MCAST_{ADD,DEL} extra-info fragments.
137 */
138 struct {
139 uint8_t addr[6]; /* Address to add/remove. */
140 } mcast;
141
142 uint16_t pad[3];
143 } u;
144};
145typedef struct netif_extra_info netif_extra_info_t;
146
147struct netif_tx_response {
148 uint16_t id;
149 int16_t status; /* NETIF_RSP_* */
150};
151typedef struct netif_tx_response netif_tx_response_t;
152
153struct netif_rx_request {
154 uint16_t id; /* Echoed in response message. */
155 grant_ref_t gref; /* Reference to incoming granted frame */
156};
157typedef struct netif_rx_request netif_rx_request_t;
158
159/* Packet data has been validated against protocol checksum. */
160#define _NETRXF_data_validated (0)
161#define NETRXF_data_validated (1U<<_NETRXF_data_validated)
162
163/* Protocol checksum field is blank in the packet (hardware offload)? */
164#define _NETRXF_csum_blank (1)
165#define NETRXF_csum_blank (1U<<_NETRXF_csum_blank)
166
167/* Packet continues in the next request descriptor. */
168#define _NETRXF_more_data (2)
169#define NETRXF_more_data (1U<<_NETRXF_more_data)
170
171/* Packet to be followed by extra descriptor(s). */
172#define _NETRXF_extra_info (3)
173#define NETRXF_extra_info (1U<<_NETRXF_extra_info)
174
175struct netif_rx_response {
176 uint16_t id;
177 uint16_t offset; /* Offset in page of start of received packet */
178 uint16_t flags; /* NETRXF_* */
179 int16_t status; /* -ve: BLKIF_RSP_* ; +ve: Rx'ed pkt size. */
180};
181typedef struct netif_rx_response netif_rx_response_t;
182
183/*
184 * Generate netif ring structures and types.
185 */
186
187DEFINE_RING_TYPES(netif_tx, struct netif_tx_request, struct netif_tx_response);
188DEFINE_RING_TYPES(netif_rx, struct netif_rx_request, struct netif_rx_response);
189
190#define NETIF_RSP_DROPPED -2
191#define NETIF_RSP_ERROR -1
192#define NETIF_RSP_OKAY 0
193/* No response: used for auxiliary requests (e.g., netif_tx_extra). */
194#define NETIF_RSP_NULL 1
195
196#endif
197
198/*
199 * Local variables:
200 * mode: C
201 * c-set-style: "BSD"
202 * c-basic-offset: 4
203 * tab-width: 4
204 * indent-tabs-mode: nil
205 * End:
206 */
207