netif.h revision 183375
190075Sobrien/******************************************************************************
290075Sobrien * netif.h
390075Sobrien *
490075Sobrien * Unified network-device I/O interface for Xen guest OSes.
590075Sobrien *
690075Sobrien * Permission is hereby granted, free of charge, to any person obtaining a copy
790075Sobrien * of this software and associated documentation files (the "Software"), to
890075Sobrien * deal in the Software without restriction, including without limitation the
990075Sobrien * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
1090075Sobrien * sell copies of the Software, and to permit persons to whom the Software is
1190075Sobrien * furnished to do so, subject to the following conditions:
1290075Sobrien *
1390075Sobrien * The above copyright notice and this permission notice shall be included in
1490075Sobrien * all copies or substantial portions of the Software.
1590075Sobrien *
1690075Sobrien * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1790075Sobrien * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1890075Sobrien * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1990075Sobrien * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2090075Sobrien * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2190075Sobrien * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2290075Sobrien * DEALINGS IN THE SOFTWARE.
2390075Sobrien *
2490075Sobrien * Copyright (c) 2003-2004, Keir Fraser
2590075Sobrien */
26169689Skan
27169689Skan#ifndef __XEN_PUBLIC_IO_NETIF_H__
2890075Sobrien#define __XEN_PUBLIC_IO_NETIF_H__
2990075Sobrien
3090075Sobrien#include "ring.h"
3190075Sobrien#include "../grant_table.h"
3290075Sobrien
3390075Sobrien/*
3490075Sobrien * Notifications after enqueuing any type of message should be conditional on
3590075Sobrien * the appropriate req_event or rsp_event field in the shared ring.
3690075Sobrien * If the client sends notification for rx requests then it should specify
3790075Sobrien * feature 'feature-rx-notify' via xenbus. Otherwise the backend will assume
3890075Sobrien * that it cannot safely queue packets (as it may not be kicked to send them).
3990075Sobrien */
4090075Sobrien
4190075Sobrien/*
42132718Skan * This is the 'wire' format for packets:
4390075Sobrien *  Request 1: netif_tx_request -- NETTXF_* (any flags)
4490075Sobrien * [Request 2: netif_tx_extra]  (only if request 1 has NETTXF_extra_info)
4590075Sobrien * [Request 3: netif_tx_extra]  (only if request 2 has XEN_NETIF_EXTRA_MORE)
4690075Sobrien *  Request 4: netif_tx_request -- NETTXF_more_data
47169689Skan *  Request 5: netif_tx_request -- NETTXF_more_data
4890075Sobrien *  ...
4990075Sobrien *  Request N: netif_tx_request -- 0
5090075Sobrien */
5190075Sobrien
5290075Sobrien/* Protocol checksum field is blank in the packet (hardware offload)? */
5390075Sobrien#define _NETTXF_csum_blank     (0)
5490075Sobrien#define  NETTXF_csum_blank     (1U<<_NETTXF_csum_blank)
5590075Sobrien
5690075Sobrien/* Packet data has been validated against protocol checksum. */
5790075Sobrien#define _NETTXF_data_validated (1)
5890075Sobrien#define  NETTXF_data_validated (1U<<_NETTXF_data_validated)
5990075Sobrien
6090075Sobrien/* Packet continues in the next request descriptor. */
6190075Sobrien#define _NETTXF_more_data      (2)
6290075Sobrien#define  NETTXF_more_data      (1U<<_NETTXF_more_data)
6390075Sobrien
6490075Sobrien/* Packet to be followed by extra descriptor(s). */
6590075Sobrien#define _NETTXF_extra_info     (3)
6690075Sobrien#define  NETTXF_extra_info     (1U<<_NETTXF_extra_info)
6790075Sobrien
6890075Sobrienstruct netif_tx_request {
6990075Sobrien    grant_ref_t gref;      /* Reference to buffer page */
70169689Skan    uint16_t offset;       /* Offset within buffer page */
7190075Sobrien    uint16_t flags;        /* NETTXF_* */
7290075Sobrien    uint16_t id;           /* Echoed in response message. */
7390075Sobrien    uint16_t size;         /* Packet size in bytes.       */
7490075Sobrien};
7590075Sobrientypedef struct netif_tx_request netif_tx_request_t;
7690075Sobrien
7790075Sobrien/* Types of netif_extra_info descriptors. */
7890075Sobrien#define XEN_NETIF_EXTRA_TYPE_NONE      (0)  /* Never used - invalid */
7990075Sobrien#define XEN_NETIF_EXTRA_TYPE_GSO       (1)  /* u.gso */
8090075Sobrien#define XEN_NETIF_EXTRA_TYPE_MCAST_ADD (2)  /* u.mcast */
8190075Sobrien#define XEN_NETIF_EXTRA_TYPE_MCAST_DEL (3)  /* u.mcast */
8290075Sobrien#define XEN_NETIF_EXTRA_TYPE_MAX       (4)
8390075Sobrien
8490075Sobrien/* netif_extra_info flags. */
8590075Sobrien#define _XEN_NETIF_EXTRA_FLAG_MORE (0)
8690075Sobrien#define XEN_NETIF_EXTRA_FLAG_MORE  (1U<<_XEN_NETIF_EXTRA_FLAG_MORE)
8790075Sobrien
8890075Sobrien/* GSO types - only TCPv4 currently supported. */
8990075Sobrien#define XEN_NETIF_GSO_TYPE_TCPV4        (1)
9090075Sobrien
9190075Sobrien/*
9290075Sobrien * This structure needs to fit within both netif_tx_request and
9390075Sobrien * netif_rx_response for compatibility.
9490075Sobrien */
9590075Sobrienstruct netif_extra_info {
9690075Sobrien    uint8_t type;  /* XEN_NETIF_EXTRA_TYPE_* */
9790075Sobrien    uint8_t flags; /* XEN_NETIF_EXTRA_FLAG_* */
9890075Sobrien
9990075Sobrien    union {
10090075Sobrien        /*
10190075Sobrien         * XEN_NETIF_EXTRA_TYPE_GSO:
10290075Sobrien         */
10390075Sobrien        struct {
10490075Sobrien            /*
10590075Sobrien             * Maximum payload size of each segment. For example, for TCP this
10690075Sobrien             * is just the path MSS.
10790075Sobrien             */
108169689Skan            uint16_t size;
109169689Skan
110169689Skan            /*
111169689Skan             * GSO type. This determines the protocol of the packet and any
112169689Skan             * extra features required to segment the packet properly.
113169689Skan             */
11490075Sobrien            uint8_t type; /* XEN_NETIF_GSO_TYPE_* */
11590075Sobrien
11690075Sobrien            /* Future expansion. */
117132718Skan            uint8_t pad;
118
119            /*
120             * GSO features. This specifies any extra GSO features required
121             * to process this packet, such as ECN support for TCPv4.
122             */
123            uint16_t features; /* XEN_NETIF_GSO_FEAT_* */
124        } gso;
125
126        /*
127         * XEN_NETIF_EXTRA_TYPE_MCAST_{ADD,DEL}:
128         * Backend advertises availability via 'feature-multicast-control'
129         * xenbus node containing value '1'.
130         * Frontend requests this feature by advertising
131         * 'request-multicast-control' xenbus node containing value '1'.
132         * If multicast control is requested then multicast flooding is
133         * disabled and the frontend must explicitly register its interest
134         * in multicast groups using dummy transmit requests containing
135         * MCAST_{ADD,DEL} extra-info fragments.
136         */
137        struct {
138            uint8_t addr[6]; /* Address to add/remove. */
139        } mcast;
140
141        uint16_t pad[3];
142    } u;
143};
144typedef struct netif_extra_info netif_extra_info_t;
145
146struct netif_tx_response {
147    uint16_t id;
148    int16_t  status;       /* NETIF_RSP_* */
149};
150typedef struct netif_tx_response netif_tx_response_t;
151
152struct netif_rx_request {
153    uint16_t    id;        /* Echoed in response message.        */
154    grant_ref_t gref;      /* Reference to incoming granted frame */
155};
156typedef struct netif_rx_request netif_rx_request_t;
157
158/* Packet data has been validated against protocol checksum. */
159#define _NETRXF_data_validated (0)
160#define  NETRXF_data_validated (1U<<_NETRXF_data_validated)
161
162/* Protocol checksum field is blank in the packet (hardware offload)? */
163#define _NETRXF_csum_blank     (1)
164#define  NETRXF_csum_blank     (1U<<_NETRXF_csum_blank)
165
166/* Packet continues in the next request descriptor. */
167#define _NETRXF_more_data      (2)
168#define  NETRXF_more_data      (1U<<_NETRXF_more_data)
169
170/* Packet to be followed by extra descriptor(s). */
171#define _NETRXF_extra_info     (3)
172#define  NETRXF_extra_info     (1U<<_NETRXF_extra_info)
173
174struct netif_rx_response {
175    uint16_t id;
176    uint16_t offset;       /* Offset in page of start of received packet  */
177    uint16_t flags;        /* NETRXF_* */
178    int16_t  status;       /* -ve: BLKIF_RSP_* ; +ve: Rx'ed pkt size. */
179};
180typedef struct netif_rx_response netif_rx_response_t;
181
182/*
183 * Generate netif ring structures and types.
184 */
185
186DEFINE_RING_TYPES(netif_tx, struct netif_tx_request, struct netif_tx_response);
187DEFINE_RING_TYPES(netif_rx, struct netif_rx_request, struct netif_rx_response);
188
189#define NETIF_RSP_DROPPED         -2
190#define NETIF_RSP_ERROR           -1
191#define NETIF_RSP_OKAY             0
192/* No response: used for auxiliary requests (e.g., netif_tx_extra). */
193#define NETIF_RSP_NULL             1
194
195#endif
196
197/*
198 * Local variables:
199 * mode: C
200 * c-set-style: "BSD"
201 * c-basic-offset: 4
202 * tab-width: 4
203 * indent-tabs-mode: nil
204 * End:
205 */
206