netif.h revision 230879
198675Sdes/****************************************************************************** 298675Sdes * netif.h 398675Sdes * 498675Sdes * Unified network-device I/O interface for Xen guest OSes. 598675Sdes * 698675Sdes * Permission is hereby granted, free of charge, to any person obtaining a copy 798675Sdes * of this software and associated documentation files (the "Software"), to 898675Sdes * deal in the Software without restriction, including without limitation the 998675Sdes * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 1098675Sdes * sell copies of the Software, and to permit persons to whom the Software is 1198675Sdes * furnished to do so, subject to the following conditions: 1298675Sdes * 1398675Sdes * The above copyright notice and this permission notice shall be included in 1498675Sdes * all copies or substantial portions of the Software. 1598675Sdes * 1698675Sdes * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1798675Sdes * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1898675Sdes * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1998675Sdes * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 2098675Sdes * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 2198675Sdes * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 2298675Sdes * DEALINGS IN THE SOFTWARE. 2398675Sdes * 2498675Sdes * Copyright (c) 2003-2004, Keir Fraser 2598675Sdes */ 2698675Sdes 27106121Sdes#ifndef __XEN_PUBLIC_IO_NETIF_H__ 2898675Sdes#define __XEN_PUBLIC_IO_NETIF_H__ 2998937Sdes 3098675Sdes#include "ring.h" 3198937Sdes#include "../grant_table.h" 3298675Sdes 33106121Sdes/* 3498675Sdes * Notifications after enqueuing any type of message should be conditional on 3598675Sdes * the appropriate req_event or rsp_event field in the shared ring. 3698675Sdes * If the client sends notification for rx requests then it should specify 3798675Sdes * feature 'feature-rx-notify' via xenbus. Otherwise the backend will assume 3898675Sdes * that it cannot safely queue packets (as it may not be kicked to send them). 3998675Sdes */ 4098675Sdes 4198675Sdes/* 42106121Sdes * This is the 'wire' format for packets: 43106121Sdes * Request 1: netif_tx_request -- NETTXF_* (any flags) 44106121Sdes * [Request 2: netif_tx_extra] (only if request 1 has NETTXF_extra_info) 45106121Sdes * [Request 3: netif_tx_extra] (only if request 2 has XEN_NETIF_EXTRA_FLAG_MORE) 46106121Sdes * Request 4: netif_tx_request -- NETTXF_more_data 47106121Sdes * Request 5: netif_tx_request -- NETTXF_more_data 48106121Sdes * ... 49106121Sdes * Request N: netif_tx_request -- 0 5098675Sdes */ 5198675Sdes 5298675Sdes/* Protocol checksum field is blank in the packet (hardware offload)? */ 5398675Sdes#define _NETTXF_csum_blank (0) 5498675Sdes#define NETTXF_csum_blank (1U<<_NETTXF_csum_blank) 5598675Sdes 5698675Sdes/* Packet data has been validated against protocol checksum. */ 5798675Sdes#define _NETTXF_data_validated (1) 5898675Sdes#define NETTXF_data_validated (1U<<_NETTXF_data_validated) 5998675Sdes 6098675Sdes/* Packet continues in the next request descriptor. */ 6198675Sdes#define _NETTXF_more_data (2) 6298675Sdes#define NETTXF_more_data (1U<<_NETTXF_more_data) 6398675Sdes 6498675Sdes/* Packet to be followed by extra descriptor(s). */ 6598675Sdes#define _NETTXF_extra_info (3) 6698675Sdes#define NETTXF_extra_info (1U<<_NETTXF_extra_info) 6798675Sdes 6898675Sdesstruct netif_tx_request { 6998675Sdes grant_ref_t gref; /* Reference to buffer page */ 7098675Sdes uint16_t offset; /* Offset within buffer page */ 7198675Sdes uint16_t flags; /* NETTXF_* */ 7298675Sdes uint16_t id; /* Echoed in response message. */ 7398675Sdes uint16_t size; /* For the first request in a packet, the packet 7498675Sdes size in bytes. For subsequent requests, the 7598675Sdes size of that request's associated data in bytes*/ 7698675Sdes}; 7798675Sdestypedef struct netif_tx_request netif_tx_request_t; 7898675Sdes 7998675Sdes/* Types of netif_extra_info descriptors. */ 8098675Sdes#define XEN_NETIF_EXTRA_TYPE_NONE (0) /* Never used - invalid */ 8198675Sdes#define XEN_NETIF_EXTRA_TYPE_GSO (1) /* u.gso */ 8298675Sdes#define XEN_NETIF_EXTRA_TYPE_MCAST_ADD (2) /* u.mcast */ 8398675Sdes#define XEN_NETIF_EXTRA_TYPE_MCAST_DEL (3) /* u.mcast */ 8498675Sdes#define XEN_NETIF_EXTRA_TYPE_MAX (4) 8598675Sdes 8698675Sdes/* netif_extra_info flags. */ 8798675Sdes#define _XEN_NETIF_EXTRA_FLAG_MORE (0) 8898675Sdes#define XEN_NETIF_EXTRA_FLAG_MORE (1U<<_XEN_NETIF_EXTRA_FLAG_MORE) 8998675Sdes 9098675Sdes/* GSO types - only TCPv4 currently supported. */ 9198675Sdes#define XEN_NETIF_GSO_TYPE_TCPV4 (1) 9298675Sdes 9398675Sdes/* 9498675Sdes * This structure needs to fit within both netif_tx_request and 95106121Sdes * netif_rx_response for compatibility. 9698675Sdes */ 9798675Sdesstruct netif_extra_info { 9898675Sdes uint8_t type; /* XEN_NETIF_EXTRA_TYPE_* */ 9998675Sdes uint8_t flags; /* XEN_NETIF_EXTRA_FLAG_* */ 10098675Sdes 10198675Sdes union { 10298675Sdes /* 10398675Sdes * XEN_NETIF_EXTRA_TYPE_GSO: 10498675Sdes */ 10598675Sdes struct { 10698675Sdes /* 10798675Sdes * Maximum payload size of each segment. For example, for TCP this 10898675Sdes * is just the path MSS. 10998675Sdes */ 11098675Sdes uint16_t size; 11198675Sdes 11298675Sdes /* 11398675Sdes * GSO type. This determines the protocol of the packet and any 11498675Sdes * extra features required to segment the packet properly. 11598675Sdes */ 11698675Sdes uint8_t type; /* XEN_NETIF_GSO_TYPE_* */ 11798675Sdes 11898675Sdes /* Future expansion. */ 11998675Sdes uint8_t pad; 12098675Sdes 12198675Sdes /* 12298675Sdes * GSO features. This specifies any extra GSO features required 12398675Sdes * to process this packet, such as ECN support for TCPv4. 12498675Sdes */ 12598675Sdes uint16_t features; /* XEN_NETIF_GSO_FEAT_* */ 12698675Sdes } gso; 12798675Sdes 12898675Sdes /* 12998675Sdes * XEN_NETIF_EXTRA_TYPE_MCAST_{ADD,DEL}: 13098675Sdes * Backend advertises availability via 'feature-multicast-control' 13198675Sdes * xenbus node containing value '1'. 13298675Sdes * Frontend requests this feature by advertising 13398675Sdes * 'request-multicast-control' xenbus node containing value '1'. 13498675Sdes * If multicast control is requested then multicast flooding is 135106121Sdes * disabled and the frontend must explicitly register its interest 13698675Sdes * in multicast groups using dummy transmit requests containing 13798675Sdes * MCAST_{ADD,DEL} extra-info fragments. 13898675Sdes */ 13998937Sdes struct { 14099060Sdes uint8_t addr[6]; /* Address to add/remove. */ 14198937Sdes } mcast; 14298937Sdes 14398675Sdes uint16_t pad[3]; 14498675Sdes } u; 14598675Sdes}; 14698675Sdestypedef struct netif_extra_info netif_extra_info_t; 14798675Sdes 14898675Sdesstruct netif_tx_response { 14998675Sdes uint16_t id; 15098675Sdes int16_t status; /* NETIF_RSP_* */ 15198675Sdes}; 15298675Sdestypedef struct netif_tx_response netif_tx_response_t; 15398675Sdes 15498675Sdesstruct netif_rx_request { 15598675Sdes uint16_t id; /* Echoed in response message. */ 15698675Sdes grant_ref_t gref; /* Reference to incoming granted frame */ 15798675Sdes}; 15898675Sdestypedef struct netif_rx_request netif_rx_request_t; 15998675Sdes 16098675Sdes/* Packet data has been validated against protocol checksum. */ 16198675Sdes#define _NETRXF_data_validated (0) 16298675Sdes#define NETRXF_data_validated (1U<<_NETRXF_data_validated) 16398675Sdes 16498675Sdes/* Protocol checksum field is blank in the packet (hardware offload)? */ 16598675Sdes#define _NETRXF_csum_blank (1) 16698675Sdes#define NETRXF_csum_blank (1U<<_NETRXF_csum_blank) 16798675Sdes 16898675Sdes/* Packet continues in the next request descriptor. */ 16998675Sdes#define _NETRXF_more_data (2) 170106121Sdes#define NETRXF_more_data (1U<<_NETRXF_more_data) 171106121Sdes 17298675Sdes/* Packet to be followed by extra descriptor(s). */ 173106121Sdes#define _NETRXF_extra_info (3) 17498675Sdes#define NETRXF_extra_info (1U<<_NETRXF_extra_info) 17598675Sdes 17698675Sdes/* GSO Prefix descriptor. */ 17798675Sdes#define _NETRXF_gso_prefix (4) 17898675Sdes#define NETRXF_gso_prefix (1U<<_NETRXF_gso_prefix) 17998675Sdes 18098675Sdesstruct netif_rx_response { 18198675Sdes uint16_t id; 18298675Sdes uint16_t offset; /* Offset in page of start of received packet */ 18398675Sdes uint16_t flags; /* NETRXF_* */ 18498675Sdes int16_t status; /* -ve: NETIF_RSP_* ; +ve: Rx'ed response size. */ 18598675Sdes}; 18698675Sdestypedef struct netif_rx_response netif_rx_response_t; 18798675Sdes 18898675Sdes/* 18998675Sdes * Generate netif ring structures and types. 19098675Sdes */ 19198675Sdes 19298675SdesDEFINE_RING_TYPES(netif_tx, struct netif_tx_request, struct netif_tx_response); 19398675SdesDEFINE_RING_TYPES(netif_rx, struct netif_rx_request, struct netif_rx_response); 19498675Sdes 19598675Sdes#define NETIF_RSP_DROPPED -2 19698675Sdes#define NETIF_RSP_ERROR -1 19798675Sdes#define NETIF_RSP_OKAY 0 19898675Sdes/* No response: used for auxiliary requests (e.g., netif_tx_extra). */ 19998675Sdes#define NETIF_RSP_NULL 1 20098675Sdes 20198675Sdes#endif 20298675Sdes 20398675Sdes/* 20498675Sdes * Local variables: 20598675Sdes * mode: C 20698675Sdes * c-set-style: "BSD" 20798675Sdes * c-basic-offset: 4 20898675Sdes * tab-width: 4 20998675Sdes * indent-tabs-mode: nil 21098675Sdes * End: 21198675Sdes */ 21298675Sdes