15084Sjohnlev /****************************************************************************** 25084Sjohnlev * netif.h 35084Sjohnlev * 45084Sjohnlev * Unified network-device I/O interface for Xen guest OSes. 55084Sjohnlev * 65084Sjohnlev * Permission is hereby granted, free of charge, to any person obtaining a copy 75084Sjohnlev * of this software and associated documentation files (the "Software"), to 85084Sjohnlev * deal in the Software without restriction, including without limitation the 95084Sjohnlev * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 105084Sjohnlev * sell copies of the Software, and to permit persons to whom the Software is 115084Sjohnlev * furnished to do so, subject to the following conditions: 125084Sjohnlev * 135084Sjohnlev * The above copyright notice and this permission notice shall be included in 145084Sjohnlev * all copies or substantial portions of the Software. 155084Sjohnlev * 165084Sjohnlev * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 175084Sjohnlev * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 185084Sjohnlev * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 195084Sjohnlev * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 205084Sjohnlev * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 215084Sjohnlev * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 225084Sjohnlev * DEALINGS IN THE SOFTWARE. 235084Sjohnlev * 245084Sjohnlev * Copyright (c) 2003-2004, Keir Fraser 255084Sjohnlev */ 265084Sjohnlev 275084Sjohnlev #ifndef __XEN_PUBLIC_IO_NETIF_H__ 285084Sjohnlev #define __XEN_PUBLIC_IO_NETIF_H__ 295084Sjohnlev 305084Sjohnlev #include "ring.h" 315084Sjohnlev #include "../grant_table.h" 325084Sjohnlev 335084Sjohnlev /* 345084Sjohnlev * Notifications after enqueuing any type of message should be conditional on 355084Sjohnlev * the appropriate req_event or rsp_event field in the shared ring. 365084Sjohnlev * If the client sends notification for rx requests then it should specify 375084Sjohnlev * feature 'feature-rx-notify' via xenbus. Otherwise the backend will assume 385084Sjohnlev * that it cannot safely queue packets (as it may not be kicked to send them). 395084Sjohnlev */ 405084Sjohnlev 415084Sjohnlev /* 425084Sjohnlev * This is the 'wire' format for packets: 435084Sjohnlev * Request 1: netif_tx_request -- NETTXF_* (any flags) 445084Sjohnlev * [Request 2: netif_tx_extra] (only if request 1 has NETTXF_extra_info) 455084Sjohnlev * [Request 3: netif_tx_extra] (only if request 2 has XEN_NETIF_EXTRA_MORE) 465084Sjohnlev * Request 4: netif_tx_request -- NETTXF_more_data 475084Sjohnlev * Request 5: netif_tx_request -- NETTXF_more_data 485084Sjohnlev * ... 495084Sjohnlev * Request N: netif_tx_request -- 0 505084Sjohnlev */ 515084Sjohnlev 525084Sjohnlev /* Protocol checksum field is blank in the packet (hardware offload)? */ 535084Sjohnlev #define _NETTXF_csum_blank (0) 545084Sjohnlev #define NETTXF_csum_blank (1U<<_NETTXF_csum_blank) 555084Sjohnlev 565084Sjohnlev /* Packet data has been validated against protocol checksum. */ 575084Sjohnlev #define _NETTXF_data_validated (1) 585084Sjohnlev #define NETTXF_data_validated (1U<<_NETTXF_data_validated) 595084Sjohnlev 605084Sjohnlev /* Packet continues in the next request descriptor. */ 615084Sjohnlev #define _NETTXF_more_data (2) 625084Sjohnlev #define NETTXF_more_data (1U<<_NETTXF_more_data) 635084Sjohnlev 645084Sjohnlev /* Packet to be followed by extra descriptor(s). */ 655084Sjohnlev #define _NETTXF_extra_info (3) 665084Sjohnlev #define NETTXF_extra_info (1U<<_NETTXF_extra_info) 675084Sjohnlev 685084Sjohnlev struct netif_tx_request { 695084Sjohnlev grant_ref_t gref; /* Reference to buffer page */ 705084Sjohnlev uint16_t offset; /* Offset within buffer page */ 715084Sjohnlev uint16_t flags; /* NETTXF_* */ 725084Sjohnlev uint16_t id; /* Echoed in response message. */ 735084Sjohnlev uint16_t size; /* Packet size in bytes. */ 745084Sjohnlev }; 755084Sjohnlev typedef struct netif_tx_request netif_tx_request_t; 765084Sjohnlev 775084Sjohnlev /* Types of netif_extra_info descriptors. */ 78*10175SStuart.Maybee@Sun.COM #define XEN_NETIF_EXTRA_TYPE_NONE (0) /* Never used - invalid */ 79*10175SStuart.Maybee@Sun.COM #define XEN_NETIF_EXTRA_TYPE_GSO (1) /* u.gso */ 80*10175SStuart.Maybee@Sun.COM #define XEN_NETIF_EXTRA_TYPE_MCAST_ADD (2) /* u.mcast */ 81*10175SStuart.Maybee@Sun.COM #define XEN_NETIF_EXTRA_TYPE_MCAST_DEL (3) /* u.mcast */ 82*10175SStuart.Maybee@Sun.COM #define XEN_NETIF_EXTRA_TYPE_MAX (4) 835084Sjohnlev 845084Sjohnlev /* netif_extra_info flags. */ 855084Sjohnlev #define _XEN_NETIF_EXTRA_FLAG_MORE (0) 865084Sjohnlev #define XEN_NETIF_EXTRA_FLAG_MORE (1U<<_XEN_NETIF_EXTRA_FLAG_MORE) 875084Sjohnlev 885084Sjohnlev /* GSO types - only TCPv4 currently supported. */ 895084Sjohnlev #define XEN_NETIF_GSO_TYPE_TCPV4 (1) 905084Sjohnlev 915084Sjohnlev /* 925084Sjohnlev * This structure needs to fit within both netif_tx_request and 935084Sjohnlev * netif_rx_response for compatibility. 945084Sjohnlev */ 955084Sjohnlev struct netif_extra_info { 965084Sjohnlev uint8_t type; /* XEN_NETIF_EXTRA_TYPE_* */ 975084Sjohnlev uint8_t flags; /* XEN_NETIF_EXTRA_FLAG_* */ 985084Sjohnlev 995084Sjohnlev union { 100*10175SStuart.Maybee@Sun.COM /* 101*10175SStuart.Maybee@Sun.COM * XEN_NETIF_EXTRA_TYPE_GSO: 102*10175SStuart.Maybee@Sun.COM */ 1035084Sjohnlev struct { 1045084Sjohnlev /* 1055084Sjohnlev * Maximum payload size of each segment. For example, for TCP this 1065084Sjohnlev * is just the path MSS. 1075084Sjohnlev */ 1085084Sjohnlev uint16_t size; 1095084Sjohnlev 1105084Sjohnlev /* 1115084Sjohnlev * GSO type. This determines the protocol of the packet and any 1125084Sjohnlev * extra features required to segment the packet properly. 1135084Sjohnlev */ 1145084Sjohnlev uint8_t type; /* XEN_NETIF_GSO_TYPE_* */ 1155084Sjohnlev 1165084Sjohnlev /* Future expansion. */ 1175084Sjohnlev uint8_t pad; 1185084Sjohnlev 1195084Sjohnlev /* 1205084Sjohnlev * GSO features. This specifies any extra GSO features required 1215084Sjohnlev * to process this packet, such as ECN support for TCPv4. 1225084Sjohnlev */ 1235084Sjohnlev uint16_t features; /* XEN_NETIF_GSO_FEAT_* */ 1245084Sjohnlev } gso; 1255084Sjohnlev 126*10175SStuart.Maybee@Sun.COM /* 127*10175SStuart.Maybee@Sun.COM * XEN_NETIF_EXTRA_TYPE_MCAST_{ADD,DEL}: 128*10175SStuart.Maybee@Sun.COM * Backend advertises availability via 'feature-multicast-control' 129*10175SStuart.Maybee@Sun.COM * xenbus node containing value '1'. 130*10175SStuart.Maybee@Sun.COM * Frontend requests this feature by advertising 131*10175SStuart.Maybee@Sun.COM * 'request-multicast-control' xenbus node containing value '1'. 132*10175SStuart.Maybee@Sun.COM * If multicast control is requested then multicast flooding is 133*10175SStuart.Maybee@Sun.COM * disabled and the frontend must explicitly register its interest 134*10175SStuart.Maybee@Sun.COM * in multicast groups using dummy transmit requests containing 135*10175SStuart.Maybee@Sun.COM * MCAST_{ADD,DEL} extra-info fragments. 136*10175SStuart.Maybee@Sun.COM */ 137*10175SStuart.Maybee@Sun.COM struct { 138*10175SStuart.Maybee@Sun.COM uint8_t addr[6]; /* Address to add/remove. */ 139*10175SStuart.Maybee@Sun.COM } mcast; 140*10175SStuart.Maybee@Sun.COM 1415084Sjohnlev uint16_t pad[3]; 1425084Sjohnlev } u; 1435084Sjohnlev }; 144*10175SStuart.Maybee@Sun.COM typedef struct netif_extra_info netif_extra_info_t; 1455084Sjohnlev 1465084Sjohnlev struct netif_tx_response { 1475084Sjohnlev uint16_t id; 1485084Sjohnlev int16_t status; /* NETIF_RSP_* */ 1495084Sjohnlev }; 1505084Sjohnlev typedef struct netif_tx_response netif_tx_response_t; 1515084Sjohnlev 1525084Sjohnlev struct netif_rx_request { 1535084Sjohnlev uint16_t id; /* Echoed in response message. */ 1545084Sjohnlev grant_ref_t gref; /* Reference to incoming granted frame */ 1555084Sjohnlev }; 1565084Sjohnlev typedef struct netif_rx_request netif_rx_request_t; 1575084Sjohnlev 1585084Sjohnlev /* Packet data has been validated against protocol checksum. */ 1595084Sjohnlev #define _NETRXF_data_validated (0) 1605084Sjohnlev #define NETRXF_data_validated (1U<<_NETRXF_data_validated) 1615084Sjohnlev 1625084Sjohnlev /* Protocol checksum field is blank in the packet (hardware offload)? */ 1635084Sjohnlev #define _NETRXF_csum_blank (1) 1645084Sjohnlev #define NETRXF_csum_blank (1U<<_NETRXF_csum_blank) 1655084Sjohnlev 1665084Sjohnlev /* Packet continues in the next request descriptor. */ 1675084Sjohnlev #define _NETRXF_more_data (2) 1685084Sjohnlev #define NETRXF_more_data (1U<<_NETRXF_more_data) 1695084Sjohnlev 1705084Sjohnlev /* Packet to be followed by extra descriptor(s). */ 1715084Sjohnlev #define _NETRXF_extra_info (3) 1725084Sjohnlev #define NETRXF_extra_info (1U<<_NETRXF_extra_info) 1735084Sjohnlev 1745084Sjohnlev struct netif_rx_response { 1755084Sjohnlev uint16_t id; 1765084Sjohnlev uint16_t offset; /* Offset in page of start of received packet */ 1775084Sjohnlev uint16_t flags; /* NETRXF_* */ 1785084Sjohnlev int16_t status; /* -ve: BLKIF_RSP_* ; +ve: Rx'ed pkt size. */ 1795084Sjohnlev }; 1805084Sjohnlev typedef struct netif_rx_response netif_rx_response_t; 1815084Sjohnlev 1825084Sjohnlev /* 1835084Sjohnlev * Generate netif ring structures and types. 1845084Sjohnlev */ 1855084Sjohnlev 1865084Sjohnlev DEFINE_RING_TYPES(netif_tx, struct netif_tx_request, struct netif_tx_response); 1875084Sjohnlev DEFINE_RING_TYPES(netif_rx, struct netif_rx_request, struct netif_rx_response); 1885084Sjohnlev 1895084Sjohnlev #define NETIF_RSP_DROPPED -2 1905084Sjohnlev #define NETIF_RSP_ERROR -1 1915084Sjohnlev #define NETIF_RSP_OKAY 0 1925084Sjohnlev /* No response: used for auxiliary requests (e.g., netif_tx_extra). */ 1935084Sjohnlev #define NETIF_RSP_NULL 1 1945084Sjohnlev 1955084Sjohnlev #endif 1965084Sjohnlev 1975084Sjohnlev /* 1985084Sjohnlev * Local variables: 1995084Sjohnlev * mode: C 2005084Sjohnlev * c-set-style: "BSD" 2015084Sjohnlev * c-basic-offset: 4 2025084Sjohnlev * tab-width: 4 2035084Sjohnlev * indent-tabs-mode: nil 2045084Sjohnlev * End: 2055084Sjohnlev */ 206