1843e1988Sjohnlev /****************************************************************************** 2843e1988Sjohnlev * netif.h 3843e1988Sjohnlev * 4843e1988Sjohnlev * Unified network-device I/O interface for Xen guest OSes. 5843e1988Sjohnlev * 6843e1988Sjohnlev * Permission is hereby granted, free of charge, to any person obtaining a copy 7843e1988Sjohnlev * of this software and associated documentation files (the "Software"), to 8843e1988Sjohnlev * deal in the Software without restriction, including without limitation the 9843e1988Sjohnlev * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10843e1988Sjohnlev * sell copies of the Software, and to permit persons to whom the Software is 11843e1988Sjohnlev * furnished to do so, subject to the following conditions: 12843e1988Sjohnlev * 13843e1988Sjohnlev * The above copyright notice and this permission notice shall be included in 14843e1988Sjohnlev * all copies or substantial portions of the Software. 15843e1988Sjohnlev * 16843e1988Sjohnlev * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17843e1988Sjohnlev * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18843e1988Sjohnlev * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19843e1988Sjohnlev * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20843e1988Sjohnlev * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21843e1988Sjohnlev * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22843e1988Sjohnlev * DEALINGS IN THE SOFTWARE. 23843e1988Sjohnlev * 24843e1988Sjohnlev * Copyright (c) 2003-2004, Keir Fraser 25843e1988Sjohnlev */ 26843e1988Sjohnlev 27843e1988Sjohnlev #ifndef __XEN_PUBLIC_IO_NETIF_H__ 28843e1988Sjohnlev #define __XEN_PUBLIC_IO_NETIF_H__ 29843e1988Sjohnlev 30843e1988Sjohnlev #include "ring.h" 31843e1988Sjohnlev #include "../grant_table.h" 32843e1988Sjohnlev 33843e1988Sjohnlev /* 34843e1988Sjohnlev * Notifications after enqueuing any type of message should be conditional on 35843e1988Sjohnlev * the appropriate req_event or rsp_event field in the shared ring. 36843e1988Sjohnlev * If the client sends notification for rx requests then it should specify 37843e1988Sjohnlev * feature 'feature-rx-notify' via xenbus. Otherwise the backend will assume 38843e1988Sjohnlev * that it cannot safely queue packets (as it may not be kicked to send them). 39843e1988Sjohnlev */ 40843e1988Sjohnlev 41843e1988Sjohnlev /* 42843e1988Sjohnlev * This is the 'wire' format for packets: 43843e1988Sjohnlev * Request 1: netif_tx_request -- NETTXF_* (any flags) 44843e1988Sjohnlev * [Request 2: netif_tx_extra] (only if request 1 has NETTXF_extra_info) 45843e1988Sjohnlev * [Request 3: netif_tx_extra] (only if request 2 has XEN_NETIF_EXTRA_MORE) 46843e1988Sjohnlev * Request 4: netif_tx_request -- NETTXF_more_data 47843e1988Sjohnlev * Request 5: netif_tx_request -- NETTXF_more_data 48843e1988Sjohnlev * ... 49843e1988Sjohnlev * Request N: netif_tx_request -- 0 50843e1988Sjohnlev */ 51843e1988Sjohnlev 52843e1988Sjohnlev /* Protocol checksum field is blank in the packet (hardware offload)? */ 53843e1988Sjohnlev #define _NETTXF_csum_blank (0) 54843e1988Sjohnlev #define NETTXF_csum_blank (1U<<_NETTXF_csum_blank) 55843e1988Sjohnlev 56843e1988Sjohnlev /* Packet data has been validated against protocol checksum. */ 57843e1988Sjohnlev #define _NETTXF_data_validated (1) 58843e1988Sjohnlev #define NETTXF_data_validated (1U<<_NETTXF_data_validated) 59843e1988Sjohnlev 60843e1988Sjohnlev /* Packet continues in the next request descriptor. */ 61843e1988Sjohnlev #define _NETTXF_more_data (2) 62843e1988Sjohnlev #define NETTXF_more_data (1U<<_NETTXF_more_data) 63843e1988Sjohnlev 64843e1988Sjohnlev /* Packet to be followed by extra descriptor(s). */ 65843e1988Sjohnlev #define _NETTXF_extra_info (3) 66843e1988Sjohnlev #define NETTXF_extra_info (1U<<_NETTXF_extra_info) 67843e1988Sjohnlev 68843e1988Sjohnlev struct netif_tx_request { 69843e1988Sjohnlev grant_ref_t gref; /* Reference to buffer page */ 70843e1988Sjohnlev uint16_t offset; /* Offset within buffer page */ 71843e1988Sjohnlev uint16_t flags; /* NETTXF_* */ 72843e1988Sjohnlev uint16_t id; /* Echoed in response message. */ 73843e1988Sjohnlev uint16_t size; /* Packet size in bytes. */ 74843e1988Sjohnlev }; 75843e1988Sjohnlev typedef struct netif_tx_request netif_tx_request_t; 76843e1988Sjohnlev 77843e1988Sjohnlev /* Types of netif_extra_info descriptors. */ 78843e1988Sjohnlev #define XEN_NETIF_EXTRA_TYPE_NONE (0) /* Never used - invalid */ 79843e1988Sjohnlev #define XEN_NETIF_EXTRA_TYPE_GSO (1) /* u.gso */ 80*349b53ddSStuart Maybee #define XEN_NETIF_EXTRA_TYPE_MCAST_ADD (2) /* u.mcast */ 81*349b53ddSStuart Maybee #define XEN_NETIF_EXTRA_TYPE_MCAST_DEL (3) /* u.mcast */ 82*349b53ddSStuart Maybee #define XEN_NETIF_EXTRA_TYPE_MAX (4) 83843e1988Sjohnlev 84843e1988Sjohnlev /* netif_extra_info flags. */ 85843e1988Sjohnlev #define _XEN_NETIF_EXTRA_FLAG_MORE (0) 86843e1988Sjohnlev #define XEN_NETIF_EXTRA_FLAG_MORE (1U<<_XEN_NETIF_EXTRA_FLAG_MORE) 87843e1988Sjohnlev 88843e1988Sjohnlev /* GSO types - only TCPv4 currently supported. */ 89843e1988Sjohnlev #define XEN_NETIF_GSO_TYPE_TCPV4 (1) 90843e1988Sjohnlev 91843e1988Sjohnlev /* 92843e1988Sjohnlev * This structure needs to fit within both netif_tx_request and 93843e1988Sjohnlev * netif_rx_response for compatibility. 94843e1988Sjohnlev */ 95843e1988Sjohnlev struct netif_extra_info { 96843e1988Sjohnlev uint8_t type; /* XEN_NETIF_EXTRA_TYPE_* */ 97843e1988Sjohnlev uint8_t flags; /* XEN_NETIF_EXTRA_FLAG_* */ 98843e1988Sjohnlev 99843e1988Sjohnlev union { 100*349b53ddSStuart Maybee /* 101*349b53ddSStuart Maybee * XEN_NETIF_EXTRA_TYPE_GSO: 102*349b53ddSStuart Maybee */ 103843e1988Sjohnlev struct { 104843e1988Sjohnlev /* 105843e1988Sjohnlev * Maximum payload size of each segment. For example, for TCP this 106843e1988Sjohnlev * is just the path MSS. 107843e1988Sjohnlev */ 108843e1988Sjohnlev uint16_t size; 109843e1988Sjohnlev 110843e1988Sjohnlev /* 111843e1988Sjohnlev * GSO type. This determines the protocol of the packet and any 112843e1988Sjohnlev * extra features required to segment the packet properly. 113843e1988Sjohnlev */ 114843e1988Sjohnlev uint8_t type; /* XEN_NETIF_GSO_TYPE_* */ 115843e1988Sjohnlev 116843e1988Sjohnlev /* Future expansion. */ 117843e1988Sjohnlev uint8_t pad; 118843e1988Sjohnlev 119843e1988Sjohnlev /* 120843e1988Sjohnlev * GSO features. This specifies any extra GSO features required 121843e1988Sjohnlev * to process this packet, such as ECN support for TCPv4. 122843e1988Sjohnlev */ 123843e1988Sjohnlev uint16_t features; /* XEN_NETIF_GSO_FEAT_* */ 124843e1988Sjohnlev } gso; 125843e1988Sjohnlev 126*349b53ddSStuart Maybee /* 127*349b53ddSStuart Maybee * XEN_NETIF_EXTRA_TYPE_MCAST_{ADD,DEL}: 128*349b53ddSStuart Maybee * Backend advertises availability via 'feature-multicast-control' 129*349b53ddSStuart Maybee * xenbus node containing value '1'. 130*349b53ddSStuart Maybee * Frontend requests this feature by advertising 131*349b53ddSStuart Maybee * 'request-multicast-control' xenbus node containing value '1'. 132*349b53ddSStuart Maybee * If multicast control is requested then multicast flooding is 133*349b53ddSStuart Maybee * disabled and the frontend must explicitly register its interest 134*349b53ddSStuart Maybee * in multicast groups using dummy transmit requests containing 135*349b53ddSStuart Maybee * MCAST_{ADD,DEL} extra-info fragments. 136*349b53ddSStuart Maybee */ 137*349b53ddSStuart Maybee struct { 138*349b53ddSStuart Maybee uint8_t addr[6]; /* Address to add/remove. */ 139*349b53ddSStuart Maybee } mcast; 140*349b53ddSStuart Maybee 141843e1988Sjohnlev uint16_t pad[3]; 142843e1988Sjohnlev } u; 143843e1988Sjohnlev }; 144*349b53ddSStuart Maybee typedef struct netif_extra_info netif_extra_info_t; 145843e1988Sjohnlev 146843e1988Sjohnlev struct netif_tx_response { 147843e1988Sjohnlev uint16_t id; 148843e1988Sjohnlev int16_t status; /* NETIF_RSP_* */ 149843e1988Sjohnlev }; 150843e1988Sjohnlev typedef struct netif_tx_response netif_tx_response_t; 151843e1988Sjohnlev 152843e1988Sjohnlev struct netif_rx_request { 153843e1988Sjohnlev uint16_t id; /* Echoed in response message. */ 154843e1988Sjohnlev grant_ref_t gref; /* Reference to incoming granted frame */ 155843e1988Sjohnlev }; 156843e1988Sjohnlev typedef struct netif_rx_request netif_rx_request_t; 157843e1988Sjohnlev 158843e1988Sjohnlev /* Packet data has been validated against protocol checksum. */ 159843e1988Sjohnlev #define _NETRXF_data_validated (0) 160843e1988Sjohnlev #define NETRXF_data_validated (1U<<_NETRXF_data_validated) 161843e1988Sjohnlev 162843e1988Sjohnlev /* Protocol checksum field is blank in the packet (hardware offload)? */ 163843e1988Sjohnlev #define _NETRXF_csum_blank (1) 164843e1988Sjohnlev #define NETRXF_csum_blank (1U<<_NETRXF_csum_blank) 165843e1988Sjohnlev 166843e1988Sjohnlev /* Packet continues in the next request descriptor. */ 167843e1988Sjohnlev #define _NETRXF_more_data (2) 168843e1988Sjohnlev #define NETRXF_more_data (1U<<_NETRXF_more_data) 169843e1988Sjohnlev 170843e1988Sjohnlev /* Packet to be followed by extra descriptor(s). */ 171843e1988Sjohnlev #define _NETRXF_extra_info (3) 172843e1988Sjohnlev #define NETRXF_extra_info (1U<<_NETRXF_extra_info) 173843e1988Sjohnlev 174843e1988Sjohnlev struct netif_rx_response { 175843e1988Sjohnlev uint16_t id; 176843e1988Sjohnlev uint16_t offset; /* Offset in page of start of received packet */ 177843e1988Sjohnlev uint16_t flags; /* NETRXF_* */ 178843e1988Sjohnlev int16_t status; /* -ve: BLKIF_RSP_* ; +ve: Rx'ed pkt size. */ 179843e1988Sjohnlev }; 180843e1988Sjohnlev typedef struct netif_rx_response netif_rx_response_t; 181843e1988Sjohnlev 182843e1988Sjohnlev /* 183843e1988Sjohnlev * Generate netif ring structures and types. 184843e1988Sjohnlev */ 185843e1988Sjohnlev 186843e1988Sjohnlev DEFINE_RING_TYPES(netif_tx, struct netif_tx_request, struct netif_tx_response); 187843e1988Sjohnlev DEFINE_RING_TYPES(netif_rx, struct netif_rx_request, struct netif_rx_response); 188843e1988Sjohnlev 189843e1988Sjohnlev #define NETIF_RSP_DROPPED -2 190843e1988Sjohnlev #define NETIF_RSP_ERROR -1 191843e1988Sjohnlev #define NETIF_RSP_OKAY 0 192843e1988Sjohnlev /* No response: used for auxiliary requests (e.g., netif_tx_extra). */ 193843e1988Sjohnlev #define NETIF_RSP_NULL 1 194843e1988Sjohnlev 195843e1988Sjohnlev #endif 196843e1988Sjohnlev 197843e1988Sjohnlev /* 198843e1988Sjohnlev * Local variables: 199843e1988Sjohnlev * mode: C 200843e1988Sjohnlev * c-set-style: "BSD" 201843e1988Sjohnlev * c-basic-offset: 4 202843e1988Sjohnlev * tab-width: 4 203843e1988Sjohnlev * indent-tabs-mode: nil 204843e1988Sjohnlev * End: 205843e1988Sjohnlev */ 206