blob: cb94668f6e9ff60c75f8d7ed4b380b2b064239c0 [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
12#include "ring.h"
13#include "../grant_table.h"
14
15/*
16 * Notifications after enqueuing any type of message should be conditional on
17 * the appropriate req_event or rsp_event field in the shared ring.
18 * If the client sends notification for rx requests then it should specify
19 * feature 'feature-rx-notify' via xenbus. Otherwise the backend will assume
20 * that it cannot safely queue packets (as it may not be kicked to send them).
21 */
22
23/*
24 * This is the 'wire' format for packets:
Ian Campbellf942dc22011-03-15 00:06:18 +000025 * Request 1: xen_netif_tx_request -- XEN_NETTXF_* (any flags)
26 * [Request 2: xen_netif_extra_info] (only if request 1 has XEN_NETTXF_extra_info)
27 * [Request 3: xen_netif_extra_info] (only if request 2 has XEN_NETIF_EXTRA_MORE)
28 * Request 4: xen_netif_tx_request -- XEN_NETTXF_more_data
29 * Request 5: xen_netif_tx_request -- XEN_NETTXF_more_data
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -070030 * ...
Ian Campbellf942dc22011-03-15 00:06:18 +000031 * Request N: xen_netif_tx_request -- 0
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -070032 */
33
34/* Protocol checksum field is blank in the packet (hardware offload)? */
Ian Campbellf942dc22011-03-15 00:06:18 +000035#define _XEN_NETTXF_csum_blank (0)
36#define XEN_NETTXF_csum_blank (1U<<_XEN_NETTXF_csum_blank)
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -070037
38/* Packet data has been validated against protocol checksum. */
Ian Campbellf942dc22011-03-15 00:06:18 +000039#define _XEN_NETTXF_data_validated (1)
40#define XEN_NETTXF_data_validated (1U<<_XEN_NETTXF_data_validated)
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -070041
42/* Packet continues in the next request descriptor. */
Ian Campbellf942dc22011-03-15 00:06:18 +000043#define _XEN_NETTXF_more_data (2)
44#define XEN_NETTXF_more_data (1U<<_XEN_NETTXF_more_data)
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -070045
46/* Packet to be followed by extra descriptor(s). */
Ian Campbellf942dc22011-03-15 00:06:18 +000047#define _XEN_NETTXF_extra_info (3)
48#define XEN_NETTXF_extra_info (1U<<_XEN_NETTXF_extra_info)
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -070049
50struct xen_netif_tx_request {
51 grant_ref_t gref; /* Reference to buffer page */
52 uint16_t offset; /* Offset within buffer page */
Ian Campbellf942dc22011-03-15 00:06:18 +000053 uint16_t flags; /* XEN_NETTXF_* */
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -070054 uint16_t id; /* Echoed in response message. */
55 uint16_t size; /* Packet size in bytes. */
56};
57
Ian Campbellf942dc22011-03-15 00:06:18 +000058/* Types of xen_netif_extra_info descriptors. */
59#define XEN_NETIF_EXTRA_TYPE_NONE (0) /* Never used - invalid */
60#define XEN_NETIF_EXTRA_TYPE_GSO (1) /* u.gso */
61#define XEN_NETIF_EXTRA_TYPE_MAX (2)
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -070062
Ian Campbellf942dc22011-03-15 00:06:18 +000063/* xen_netif_extra_info flags. */
64#define _XEN_NETIF_EXTRA_FLAG_MORE (0)
65#define XEN_NETIF_EXTRA_FLAG_MORE (1U<<_XEN_NETIF_EXTRA_FLAG_MORE)
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -070066
67/* GSO types - only TCPv4 currently supported. */
Ian Campbellf942dc22011-03-15 00:06:18 +000068#define XEN_NETIF_GSO_TYPE_TCPV4 (1)
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -070069
70/*
71 * This structure needs to fit within both netif_tx_request and
72 * netif_rx_response for compatibility.
73 */
74struct xen_netif_extra_info {
75 uint8_t type; /* XEN_NETIF_EXTRA_TYPE_* */
76 uint8_t flags; /* XEN_NETIF_EXTRA_FLAG_* */
77
78 union {
79 struct {
80 /*
81 * Maximum payload size of each segment. For
82 * example, for TCP this is just the path MSS.
83 */
84 uint16_t size;
85
86 /*
87 * GSO type. This determines the protocol of
88 * the packet and any extra features required
89 * to segment the packet properly.
90 */
91 uint8_t type; /* XEN_NETIF_GSO_TYPE_* */
92
93 /* Future expansion. */
94 uint8_t pad;
95
96 /*
97 * GSO features. This specifies any extra GSO
98 * features required to process this packet,
99 * such as ECN support for TCPv4.
100 */
101 uint16_t features; /* XEN_NETIF_GSO_FEAT_* */
102 } gso;
103
104 uint16_t pad[3];
105 } u;
106};
107
108struct xen_netif_tx_response {
109 uint16_t id;
Ian Campbellf942dc22011-03-15 00:06:18 +0000110 int16_t status; /* XEN_NETIF_RSP_* */
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -0700111};
112
113struct xen_netif_rx_request {
114 uint16_t id; /* Echoed in response message. */
115 grant_ref_t gref; /* Reference to incoming granted frame */
116};
117
118/* Packet data has been validated against protocol checksum. */
Ian Campbellf942dc22011-03-15 00:06:18 +0000119#define _XEN_NETRXF_data_validated (0)
120#define XEN_NETRXF_data_validated (1U<<_XEN_NETRXF_data_validated)
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -0700121
122/* Protocol checksum field is blank in the packet (hardware offload)? */
Ian Campbellf942dc22011-03-15 00:06:18 +0000123#define _XEN_NETRXF_csum_blank (1)
124#define XEN_NETRXF_csum_blank (1U<<_XEN_NETRXF_csum_blank)
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -0700125
126/* Packet continues in the next request descriptor. */
Ian Campbellf942dc22011-03-15 00:06:18 +0000127#define _XEN_NETRXF_more_data (2)
128#define XEN_NETRXF_more_data (1U<<_XEN_NETRXF_more_data)
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -0700129
130/* Packet to be followed by extra descriptor(s). */
Ian Campbellf942dc22011-03-15 00:06:18 +0000131#define _XEN_NETRXF_extra_info (3)
132#define XEN_NETRXF_extra_info (1U<<_XEN_NETRXF_extra_info)
133
134/* GSO Prefix descriptor. */
135#define _XEN_NETRXF_gso_prefix (4)
136#define XEN_NETRXF_gso_prefix (1U<<_XEN_NETRXF_gso_prefix)
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -0700137
138struct xen_netif_rx_response {
139 uint16_t id;
140 uint16_t offset; /* Offset in page of start of received packet */
Ian Campbellf942dc22011-03-15 00:06:18 +0000141 uint16_t flags; /* XEN_NETRXF_* */
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -0700142 int16_t status; /* -ve: BLKIF_RSP_* ; +ve: Rx'ed pkt size. */
143};
144
145/*
146 * Generate netif ring structures and types.
147 */
148
149DEFINE_RING_TYPES(xen_netif_tx,
150 struct xen_netif_tx_request,
151 struct xen_netif_tx_response);
152DEFINE_RING_TYPES(xen_netif_rx,
153 struct xen_netif_rx_request,
154 struct xen_netif_rx_response);
155
Ian Campbellf942dc22011-03-15 00:06:18 +0000156#define XEN_NETIF_RSP_DROPPED -2
157#define XEN_NETIF_RSP_ERROR -1
158#define XEN_NETIF_RSP_OKAY 0
159/* No response: used for auxiliary requests (e.g., xen_netif_extra_info). */
160#define XEN_NETIF_RSP_NULL 1
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -0700161
162#endif