netif.h revision 230587
11541Srgrimes/****************************************************************************** 21541Srgrimes * netif.h 31541Srgrimes * 41541Srgrimes * Unified network-device I/O interface for Xen guest OSes. 51541Srgrimes * 61541Srgrimes * Permission is hereby granted, free of charge, to any person obtaining a copy 71541Srgrimes * of this software and associated documentation files (the "Software"), to 81541Srgrimes * deal in the Software without restriction, including without limitation the 91541Srgrimes * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 101541Srgrimes * sell copies of the Software, and to permit persons to whom the Software is 111541Srgrimes * furnished to do so, subject to the following conditions: 121541Srgrimes * 131541Srgrimes * The above copyright notice and this permission notice shall be included in 141541Srgrimes * all copies or substantial portions of the Software. 151541Srgrimes * 161541Srgrimes * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 171541Srgrimes * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 181541Srgrimes * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 191541Srgrimes * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 201541Srgrimes * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 211541Srgrimes * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 221541Srgrimes * DEALINGS IN THE SOFTWARE. 231541Srgrimes * 241541Srgrimes * Copyright (c) 2003-2004, Keir Fraser 251541Srgrimes */ 261541Srgrimes 271541Srgrimes#ifndef __XEN_PUBLIC_IO_NETIF_H__ 281541Srgrimes#define __XEN_PUBLIC_IO_NETIF_H__ 291541Srgrimes 301541Srgrimes#include "ring.h" 311541Srgrimes#include "../grant_table.h" 321541Srgrimes 331541Srgrimes/* 341541Srgrimes * Notifications after enqueuing any type of message should be conditional on 351541Srgrimes * the appropriate req_event or rsp_event field in the shared ring. 361541Srgrimes * If the client sends notification for rx requests then it should specify 371541Srgrimes * feature 'feature-rx-notify' via xenbus. Otherwise the backend will assume 381541Srgrimes * that it cannot safely queue packets (as it may not be kicked to send them). 3935105Swosch */ 401541Srgrimes 411541Srgrimes/* 4213203Swollman * This is the 'wire' format for packets: 4313203Swollman * Request 1: netif_tx_request -- NETTXF_* (any flags) 441541Srgrimes * [Request 2: netif_tx_extra] (only if request 1 has NETTXF_extra_info) 452112Swollman * [Request 3: netif_tx_extra] (only if request 2 has XEN_NETIF_EXTRA_FLAG_MORE) 461541Srgrimes * Request 4: netif_tx_request -- NETTXF_more_data 471541Srgrimes * Request 5: netif_tx_request -- NETTXF_more_data 481541Srgrimes * ... 491541Srgrimes * Request N: netif_tx_request -- 0 501541Srgrimes */ 511541Srgrimes 521541Srgrimes/* Protocol checksum field is blank in the packet (hardware offload)? */ 531541Srgrimes#define _NETTXF_csum_blank (0) 541541Srgrimes#define NETTXF_csum_blank (1U<<_NETTXF_csum_blank) 551541Srgrimes 5632011Sbde/* Packet data has been validated against protocol checksum. */ 5732011Sbde#define _NETTXF_data_validated (1) 581541Srgrimes#define NETTXF_data_validated (1U<<_NETTXF_data_validated) 591541Srgrimes 601541Srgrimes/* Packet continues in the next request descriptor. */ 611541Srgrimes#define _NETTXF_more_data (2) 621541Srgrimes#define NETTXF_more_data (1U<<_NETTXF_more_data) 631541Srgrimes 641541Srgrimes/* Packet to be followed by extra descriptor(s). */ 651541Srgrimes#define _NETTXF_extra_info (3) 661541Srgrimes#define NETTXF_extra_info (1U<<_NETTXF_extra_info) 671541Srgrimes 681541Srgrimesstruct netif_tx_request { 691541Srgrimes grant_ref_t gref; /* Reference to buffer page */ 701541Srgrimes uint16_t offset; /* Offset within buffer page */ 711541Srgrimes uint16_t flags; /* NETTXF_* */ 721541Srgrimes uint16_t id; /* Echoed in response message. */ 731541Srgrimes uint16_t size; /* For the first request in a packet, the packet 741541Srgrimes size in bytes. For subsequent requests, the 751541Srgrimes size of that request's associated data in bytes*/ 761541Srgrimes}; 771541Srgrimestypedef struct netif_tx_request netif_tx_request_t; 781541Srgrimes 791541Srgrimes/* Types of netif_extra_info descriptors. */ 801541Srgrimes#define XEN_NETIF_EXTRA_TYPE_NONE (0) /* Never used - invalid */ 811541Srgrimes#define XEN_NETIF_EXTRA_TYPE_GSO (1) /* u.gso */ 821541Srgrimes#define XEN_NETIF_EXTRA_TYPE_MCAST_ADD (2) /* u.mcast */ 831541Srgrimes#define XEN_NETIF_EXTRA_TYPE_MCAST_DEL (3) /* u.mcast */ 841541Srgrimes#define XEN_NETIF_EXTRA_TYPE_MAX (4) 851541Srgrimes 861541Srgrimes/* netif_extra_info flags. */ 871541Srgrimes#define _XEN_NETIF_EXTRA_FLAG_MORE (0) 881541Srgrimes#define XEN_NETIF_EXTRA_FLAG_MORE (1U<<_XEN_NETIF_EXTRA_FLAG_MORE) 8922521Sdyson 901541Srgrimes/* GSO types - only TCPv4 currently supported. */ 911541Srgrimes#define XEN_NETIF_GSO_TYPE_TCPV4 (1) 921541Srgrimes 931541Srgrimes/* 941541Srgrimes * This structure needs to fit within both netif_tx_request and 951541Srgrimes * netif_rx_response for compatibility. 961541Srgrimes */ 971541Srgrimesstruct netif_extra_info { 981541Srgrimes uint8_t type; /* XEN_NETIF_EXTRA_TYPE_* */ 991541Srgrimes uint8_t flags; /* XEN_NETIF_EXTRA_FLAG_* */ 1001541Srgrimes 1011541Srgrimes union { 1021541Srgrimes /* 1031541Srgrimes * XEN_NETIF_EXTRA_TYPE_GSO: 1041541Srgrimes */ 1051541Srgrimes struct { 1061541Srgrimes /* 10729653Sdyson * Maximum payload size of each segment. For example, for TCP this 1081541Srgrimes * is just the path MSS. 1091541Srgrimes */ 1102142Sdg uint16_t size; 1111541Srgrimes 1121541Srgrimes /* 1132142Sdg * GSO type. This determines the protocol of the packet and any 11420069Sbde * extra features required to segment the packet properly. 11520069Sbde */ 11620069Sbde uint8_t type; /* XEN_NETIF_GSO_TYPE_* */ 11720069Sbde 11820069Sbde /* Future expansion. */ 11920069Sbde uint8_t pad; 12020069Sbde 1211541Srgrimes /* 12229653Sdyson * GSO features. This specifies any extra GSO features required 1231541Srgrimes * to process this packet, such as ECN support for TCPv4. 1241541Srgrimes */ 1251541Srgrimes uint16_t features; /* XEN_NETIF_GSO_FEAT_* */ 1261541Srgrimes } gso; 1271541Srgrimes 1281541Srgrimes /* 1291541Srgrimes * XEN_NETIF_EXTRA_TYPE_MCAST_{ADD,DEL}: 1301541Srgrimes * Backend advertises availability via 'feature-multicast-control' 1311541Srgrimes * xenbus node containing value '1'. 1321541Srgrimes * Frontend requests this feature by advertising 1331541Srgrimes * 'request-multicast-control' xenbus node containing value '1'. 1341541Srgrimes * If multicast control is requested then multicast flooding is 13533360Sdyson * disabled and the frontend must explicitly register its interest 13633360Sdyson * in multicast groups using dummy transmit requests containing 1371541Srgrimes * MCAST_{ADD,DEL} extra-info fragments. 1381541Srgrimes */ 1391541Srgrimes struct { 1401541Srgrimes uint8_t addr[6]; /* Address to add/remove. */ 1411541Srgrimes } mcast; 1421541Srgrimes 1431541Srgrimes uint16_t pad[3]; 1441541Srgrimes } u; 1451541Srgrimes}; 1461541Srgrimestypedef struct netif_extra_info netif_extra_info_t; 1471541Srgrimes 1481541Srgrimesstruct netif_tx_response { 1491541Srgrimes uint16_t id; 1501541Srgrimes int16_t status; /* NETIF_RSP_* */ 1511541Srgrimes}; 1521541Srgrimestypedef struct netif_tx_response netif_tx_response_t; 1531541Srgrimes 1541541Srgrimesstruct netif_rx_request { 1553148Sphk uint16_t id; /* Echoed in response message. */ 1563148Sphk grant_ref_t gref; /* Reference to incoming granted frame */ 15729653Sdyson}; 1581541Srgrimestypedef struct netif_rx_request netif_rx_request_t; 1591541Srgrimes 1601541Srgrimes/* Packet data has been validated against protocol checksum. */ 1611541Srgrimes#define _NETRXF_data_validated (0) 1621541Srgrimes#define NETRXF_data_validated (1U<<_NETRXF_data_validated) 1631541Srgrimes 1641541Srgrimes/* Protocol checksum field is blank in the packet (hardware offload)? */ 16529653Sdyson#define _NETRXF_csum_blank (1) 1661541Srgrimes#define NETRXF_csum_blank (1U<<_NETRXF_csum_blank) 1671541Srgrimes 16832286Sdyson/* Packet continues in the next request descriptor. */ 16932286Sdyson#define _NETRXF_more_data (2) 17032286Sdyson#define NETRXF_more_data (1U<<_NETRXF_more_data) 17132286Sdyson 17232286Sdyson/* Packet to be followed by extra descriptor(s). */ 17332286Sdyson#define _NETRXF_extra_info (3) 17432286Sdyson#define NETRXF_extra_info (1U<<_NETRXF_extra_info) 1751541Srgrimes 1761541Srgrimesstruct netif_rx_response { 1771541Srgrimes uint16_t id; 17822521Sdyson uint16_t offset; /* Offset in page of start of received packet */ 1791541Srgrimes uint16_t flags; /* NETRXF_* */ 1801541Srgrimes int16_t status; /* -ve: NETIF_RSP_* ; +ve: Rx'ed response size. */ 1811541Srgrimes}; 1821541Srgrimestypedef struct netif_rx_response netif_rx_response_t; 1831541Srgrimes 18429653Sdyson/* 1851541Srgrimes * Generate netif ring structures and types. 1861541Srgrimes */ 1871541Srgrimes 1881541SrgrimesDEFINE_RING_TYPES(netif_tx, struct netif_tx_request, struct netif_tx_response); 1891541SrgrimesDEFINE_RING_TYPES(netif_rx, struct netif_rx_request, struct netif_rx_response); 1901541Srgrimes 1911541Srgrimes#define NETIF_RSP_DROPPED -2 1921541Srgrimes#define NETIF_RSP_ERROR -1 1931541Srgrimes#define NETIF_RSP_OKAY 0 1941541Srgrimes/* No response: used for auxiliary requests (e.g., netif_tx_extra). */ 1951541Srgrimes#define NETIF_RSP_NULL 1 1963148Sphk 1973148Sphk#endif 1981541Srgrimes 19929653Sdyson/* 2001541Srgrimes * Local variables: 2011541Srgrimes * mode: C 2021541Srgrimes * c-set-style: "BSD" 2031541Srgrimes * c-basic-offset: 4 2041541Srgrimes * tab-width: 4 20529653Sdyson * indent-tabs-mode: nil 2061541Srgrimes * End: 2071541Srgrimes */ 2081541Srgrimes