/******************************************************************************1* netif.h2*3* Unified network-device I/O interface for Xen guest OSes.4*5* Permission is hereby granted, free of charge, to any person obtaining a copy6* of this software and associated documentation files (the "Software"), to7* deal in the Software without restriction, including without limitation the8* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or9* sell copies of the Software, and to permit persons to whom the Software is10* furnished to do so, subject to the following conditions:11*12* The above copyright notice and this permission notice shall be included in13* all copies or substantial portions of the Software.14*15* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE18* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER19* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING20* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER21* DEALINGS IN THE SOFTWARE.22*23* Copyright (c) 2003-2004, Keir Fraser24*/2526#ifndef __XEN_PUBLIC_IO_NETIF_H__27#define __XEN_PUBLIC_IO_NETIF_H__2829#include "ring.h"30#include "../grant_table.h"3132/*33* Older implementation of Xen network frontend / backend has an34* implicit dependency on the MAX_SKB_FRAGS as the maximum number of35* ring slots a skb can use. Netfront / netback may not work as36* expected when frontend and backend have different MAX_SKB_FRAGS.37*38* A better approach is to add mechanism for netfront / netback to39* negotiate this value. However we cannot fix all possible40* frontends, so we need to define a value which states the minimum41* slots backend must support.42*43* The minimum value derives from older Linux kernel's MAX_SKB_FRAGS44* (18), which is proved to work with most frontends. Any new backend45* which doesn't negotiate with frontend should expect frontend to46* send a valid packet using slots up to this value.47*/48#define XEN_NETIF_NR_SLOTS_MIN 184950/*51* Notifications after enqueuing any type of message should be conditional on52* the appropriate req_event or rsp_event field in the shared ring.53* If the client sends notification for rx requests then it should specify54* feature 'feature-rx-notify' via xenbus. Otherwise the backend will assume55* that it cannot safely queue packets (as it may not be kicked to send them).56*/5758/*59* "feature-split-event-channels" is introduced to separate guest TX60* and RX notification. Backend either doesn't support this feature or61* advertises it via xenstore as 0 (disabled) or 1 (enabled).62*63* To make use of this feature, frontend should allocate two event64* channels for TX and RX, advertise them to backend as65* "event-channel-tx" and "event-channel-rx" respectively. If frontend66* doesn't want to use this feature, it just writes "event-channel"67* node as before.68*/6970/*71* Multiple transmit and receive queues:72* If supported, the backend will write the key "multi-queue-max-queues" to73* the directory for that vif, and set its value to the maximum supported74* number of queues.75* Frontends that are aware of this feature and wish to use it can write the76* key "multi-queue-num-queues", set to the number they wish to use, which77* must be greater than zero, and no more than the value reported by the backend78* in "multi-queue-max-queues".79*80* Queues replicate the shared rings and event channels.81* "feature-split-event-channels" may optionally be used when using82* multiple queues, but is not mandatory.83*84* Each queue consists of one shared ring pair, i.e. there must be the same85* number of tx and rx rings.86*87* For frontends requesting just one queue, the usual event-channel and88* ring-ref keys are written as before, simplifying the backend processing89* to avoid distinguishing between a frontend that doesn't understand the90* multi-queue feature, and one that does, but requested only one queue.91*92* Frontends requesting two or more queues must not write the toplevel93* event-channel (or event-channel-{tx,rx}) and {tx,rx}-ring-ref keys,94* instead writing those keys under sub-keys having the name "queue-N" where95* N is the integer ID of the queue for which those keys belong. Queues96* are indexed from zero. For example, a frontend with two queues and split97* event channels must write the following set of queue-related keys:98*99* /local/domain/1/device/vif/0/multi-queue-num-queues = "2"100* /local/domain/1/device/vif/0/queue-0 = ""101* /local/domain/1/device/vif/0/queue-0/tx-ring-ref = "<ring-ref-tx0>"102* /local/domain/1/device/vif/0/queue-0/rx-ring-ref = "<ring-ref-rx0>"103* /local/domain/1/device/vif/0/queue-0/event-channel-tx = "<evtchn-tx0>"104* /local/domain/1/device/vif/0/queue-0/event-channel-rx = "<evtchn-rx0>"105* /local/domain/1/device/vif/0/queue-1 = ""106* /local/domain/1/device/vif/0/queue-1/tx-ring-ref = "<ring-ref-tx1>"107* /local/domain/1/device/vif/0/queue-1/rx-ring-ref = "<ring-ref-rx1"108* /local/domain/1/device/vif/0/queue-1/event-channel-tx = "<evtchn-tx1>"109* /local/domain/1/device/vif/0/queue-1/event-channel-rx = "<evtchn-rx1>"110*111* If there is any inconsistency in the XenStore data, the backend may112* choose not to connect any queues, instead treating the request as an113* error. This includes scenarios where more (or fewer) queues were114* requested than the frontend provided details for.115*116* Mapping of packets to queues is considered to be a function of the117* transmitting system (backend or frontend) and is not negotiated118* between the two. Guests are free to transmit packets on any queue119* they choose, provided it has been set up correctly. Guests must be120* prepared to receive packets on any queue they have requested be set up.121*/122123/*124* "feature-no-csum-offload" should be used to turn IPv4 TCP/UDP checksum125* offload off or on. If it is missing then the feature is assumed to be on.126* "feature-ipv6-csum-offload" should be used to turn IPv6 TCP/UDP checksum127* offload on or off. If it is missing then the feature is assumed to be off.128*/129130/*131* "feature-gso-tcpv4" and "feature-gso-tcpv6" advertise the capability to132* handle large TCP packets (in IPv4 or IPv6 form respectively). Neither133* frontends nor backends are assumed to be capable unless the flags are134* present.135*/136137/*138* "feature-multicast-control" and "feature-dynamic-multicast-control"139* advertise the capability to filter ethernet multicast packets in the140* backend. If the frontend wishes to take advantage of this feature then141* it may set "request-multicast-control". If the backend only advertises142* "feature-multicast-control" then "request-multicast-control" must be set143* before the frontend moves into the connected state. The backend will144* sample the value on this state transition and any subsequent change in145* value will have no effect. However, if the backend also advertises146* "feature-dynamic-multicast-control" then "request-multicast-control"147* may be set by the frontend at any time. In this case, the backend will148* watch the value and re-sample on watch events.149*150* If the sampled value of "request-multicast-control" is set then the151* backend transmit side should no longer flood multicast packets to the152* frontend, it should instead drop any multicast packet that does not153* match in a filter list.154* The list is amended by the frontend by sending dummy transmit requests155* containing XEN_NETIF_EXTRA_TYPE_MCAST_{ADD,DEL} extra-info fragments as156* specified below.157* Note that the filter list may be amended even if the sampled value of158* "request-multicast-control" is not set, however the filter should only159* be applied if it is set.160*/161162/*163* Control ring164* ============165*166* Some features, such as hashing (detailed below), require a167* significant amount of out-of-band data to be passed from frontend to168* backend. Use of xenstore is not suitable for large quantities of data169* because of quota limitations and so a dedicated 'control ring' is used.170* The ability of the backend to use a control ring is advertised by171* setting:172*173* /local/domain/X/backend/vif/<domid>/<vif>/feature-ctrl-ring = "1"174*175* The frontend provides a control ring to the backend by setting:176*177* /local/domain/<domid>/device/vif/<vif>/ctrl-ring-ref = <gref>178* /local/domain/<domid>/device/vif/<vif>/event-channel-ctrl = <port>179*180* where <gref> is the grant reference of the shared page used to181* implement the control ring and <port> is an event channel to be used182* as a mailbox interrupt. These keys must be set before the frontend183* moves into the connected state.184*185* The control ring uses a fixed request/response message size and is186* balanced (i.e. one request to one response), so operationally it is much187* the same as a transmit or receive ring.188* Note that there is no requirement that responses are issued in the same189* order as requests.190*/191192/*193* Link state194* ==========195*196* The backend can advertise its current link (carrier) state to the197* frontend using the /local/domain/X/backend/vif/<domid>/<vif>/carrier198* node. If this node is not present, then the frontend should assume that199* the link is up (for compatibility with backends that do not implement200* this feature). If this node is present, then a value of "0" should be201* interpreted by the frontend as the link being down (no carrier) and a202* value of "1" should be interpreted as the link being up (carrier203* present).204*/205206/*207* MTU208* ===209*210* The toolstack may set a value of MTU for the frontend by setting the211* /local/domain/<domid>/device/vif/<vif>/mtu node with the MTU value in212* octets. If this node is absent the frontend should assume an MTU value213* of 1500 octets. A frontend is also at liberty to ignore this value so214* it is only suitable for informing the frontend that a packet payload215* >1500 octets is permitted.216*/217218/*219* Hash types220* ==========221*222* For the purposes of the definitions below, 'Packet[]' is an array of223* octets containing an IP packet without options, 'Array[X..Y]' means a224* sub-array of 'Array' containing bytes X thru Y inclusive, and '+' is225* used to indicate concatenation of arrays.226*/227228/*229* A hash calculated over an IP version 4 header as follows:230*231* Buffer[0..8] = Packet[12..15] (source address) +232* Packet[16..19] (destination address)233*234* Result = Hash(Buffer, 8)235*/236#define _XEN_NETIF_CTRL_HASH_TYPE_IPV4 0237#define XEN_NETIF_CTRL_HASH_TYPE_IPV4 \238(1 << _XEN_NETIF_CTRL_HASH_TYPE_IPV4)239240/*241* A hash calculated over an IP version 4 header and TCP header as242* follows:243*244* Buffer[0..12] = Packet[12..15] (source address) +245* Packet[16..19] (destination address) +246* Packet[20..21] (source port) +247* Packet[22..23] (destination port)248*249* Result = Hash(Buffer, 12)250*/251#define _XEN_NETIF_CTRL_HASH_TYPE_IPV4_TCP 1252#define XEN_NETIF_CTRL_HASH_TYPE_IPV4_TCP \253(1 << _XEN_NETIF_CTRL_HASH_TYPE_IPV4_TCP)254255/*256* A hash calculated over an IP version 6 header as follows:257*258* Buffer[0..32] = Packet[8..23] (source address ) +259* Packet[24..39] (destination address)260*261* Result = Hash(Buffer, 32)262*/263#define _XEN_NETIF_CTRL_HASH_TYPE_IPV6 2264#define XEN_NETIF_CTRL_HASH_TYPE_IPV6 \265(1 << _XEN_NETIF_CTRL_HASH_TYPE_IPV6)266267/*268* A hash calculated over an IP version 6 header and TCP header as269* follows:270*271* Buffer[0..36] = Packet[8..23] (source address) +272* Packet[24..39] (destination address) +273* Packet[40..41] (source port) +274* Packet[42..43] (destination port)275*276* Result = Hash(Buffer, 36)277*/278#define _XEN_NETIF_CTRL_HASH_TYPE_IPV6_TCP 3279#define XEN_NETIF_CTRL_HASH_TYPE_IPV6_TCP \280(1 << _XEN_NETIF_CTRL_HASH_TYPE_IPV6_TCP)281282/*283* Hash algorithms284* ===============285*/286287#define XEN_NETIF_CTRL_HASH_ALGORITHM_NONE 0288289/*290* Toeplitz hash:291*/292293#define XEN_NETIF_CTRL_HASH_ALGORITHM_TOEPLITZ 1294295/*296* This algorithm uses a 'key' as well as the data buffer itself.297* (Buffer[] and Key[] are treated as shift-registers where the MSB of298* Buffer/Key[0] is considered 'left-most' and the LSB of Buffer/Key[N-1]299* is the 'right-most').300*301* Value = 0302* For number of bits in Buffer[]303* If (left-most bit of Buffer[] is 1)304* Value ^= left-most 32 bits of Key[]305* Key[] << 1306* Buffer[] << 1307*308* The code below is provided for convenience where an operating system309* does not already provide an implementation.310*/311#ifdef XEN_NETIF_DEFINE_TOEPLITZ312static uint32_t xen_netif_toeplitz_hash(const uint8_t *key,313unsigned int keylen,314const uint8_t *buf,315unsigned int buflen)316{317unsigned int keyi, bufi;318uint64_t prefix = 0;319uint64_t hash = 0;320321/* Pre-load prefix with the first 8 bytes of the key */322for (keyi = 0; keyi < 8; keyi++) {323prefix <<= 8;324prefix |= (keyi < keylen) ? key[keyi] : 0;325}326327for (bufi = 0; bufi < buflen; bufi++) {328uint8_t byte = buf[bufi];329unsigned int bit;330331for (bit = 0; bit < 8; bit++) {332if (byte & 0x80)333hash ^= prefix;334prefix <<= 1;335byte <<=1;336}337338/*339* 'prefix' has now been left-shifted by 8, so340* OR in the next byte.341*/342prefix |= (keyi < keylen) ? key[keyi] : 0;343keyi++;344}345346/* The valid part of the hash is in the upper 32 bits. */347return hash >> 32;348}349#endif /* XEN_NETIF_DEFINE_TOEPLITZ */350351/*352* Control requests (struct xen_netif_ctrl_request)353* ================================================354*355* All requests have the following format:356*357* 0 1 2 3 4 5 6 7 octet358* +-----+-----+-----+-----+-----+-----+-----+-----+359* | id | type | data[0] |360* +-----+-----+-----+-----+-----+-----+-----+-----+361* | data[1] | data[2] |362* +-----+-----+-----+-----+-----------------------+363*364* id: the request identifier, echoed in response.365* type: the type of request (see below)366* data[]: any data associated with the request (determined by type)367*/368369struct xen_netif_ctrl_request {370uint16_t id;371uint16_t type;372373#define XEN_NETIF_CTRL_TYPE_INVALID 0374#define XEN_NETIF_CTRL_TYPE_GET_HASH_FLAGS 1375#define XEN_NETIF_CTRL_TYPE_SET_HASH_FLAGS 2376#define XEN_NETIF_CTRL_TYPE_SET_HASH_KEY 3377#define XEN_NETIF_CTRL_TYPE_GET_HASH_MAPPING_SIZE 4378#define XEN_NETIF_CTRL_TYPE_SET_HASH_MAPPING_SIZE 5379#define XEN_NETIF_CTRL_TYPE_SET_HASH_MAPPING 6380#define XEN_NETIF_CTRL_TYPE_SET_HASH_ALGORITHM 7381#define XEN_NETIF_CTRL_TYPE_GET_GREF_MAPPING_SIZE 8382#define XEN_NETIF_CTRL_TYPE_ADD_GREF_MAPPING 9383#define XEN_NETIF_CTRL_TYPE_DEL_GREF_MAPPING 10384385uint32_t data[3];386};387388/*389* Control responses (struct xen_netif_ctrl_response)390* ==================================================391*392* All responses have the following format:393*394* 0 1 2 3 4 5 6 7 octet395* +-----+-----+-----+-----+-----+-----+-----+-----+396* | id | type | status |397* +-----+-----+-----+-----+-----+-----+-----+-----+398* | data |399* +-----+-----+-----+-----+400*401* id: the corresponding request identifier402* type: the type of the corresponding request403* status: the status of request processing404* data: any data associated with the response (determined by type and405* status)406*/407408struct xen_netif_ctrl_response {409uint16_t id;410uint16_t type;411uint32_t status;412413#define XEN_NETIF_CTRL_STATUS_SUCCESS 0414#define XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED 1415#define XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER 2416#define XEN_NETIF_CTRL_STATUS_BUFFER_OVERFLOW 3417418uint32_t data;419};420421/*422* Static Grants (struct xen_netif_gref)423* =====================================424*425* A frontend may provide a fixed set of grant references to be mapped on426* the backend. The message of type XEN_NETIF_CTRL_TYPE_ADD_GREF_MAPPING427* prior its usage in the command ring allows for creation of these mappings.428* The backend will maintain a fixed amount of these mappings.429*430* XEN_NETIF_CTRL_TYPE_GET_GREF_MAPPING_SIZE lets a frontend query how many431* of these mappings can be kept.432*433* Each entry in the XEN_NETIF_CTRL_TYPE_{ADD,DEL}_GREF_MAPPING input table has434* the following format:435*436* 0 1 2 3 4 5 6 7 octet437* +-----+-----+-----+-----+-----+-----+-----+-----+438* | grant ref | flags | status |439* +-----+-----+-----+-----+-----+-----+-----+-----+440*441* grant ref: grant reference (IN)442* flags: flags describing the control operation (IN)443* status: XEN_NETIF_CTRL_STATUS_* (OUT)444*445* 'status' is an output parameter which does not require to be set to zero446* prior to its usage in the corresponding control messages.447*/448449struct xen_netif_gref {450grant_ref_t ref;451uint16_t flags;452453#define _XEN_NETIF_CTRLF_GREF_readonly 0454#define XEN_NETIF_CTRLF_GREF_readonly (1U<<_XEN_NETIF_CTRLF_GREF_readonly)455456uint16_t status;457};458459/*460* Control messages461* ================462*463* XEN_NETIF_CTRL_TYPE_SET_HASH_ALGORITHM464* --------------------------------------465*466* This is sent by the frontend to set the desired hash algorithm.467*468* Request:469*470* type = XEN_NETIF_CTRL_TYPE_SET_HASH_ALGORITHM471* data[0] = a XEN_NETIF_CTRL_HASH_ALGORITHM_* value472* data[1] = 0473* data[2] = 0474*475* Response:476*477* status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED - Operation not478* supported479* XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER - The algorithm is not480* supported481* XEN_NETIF_CTRL_STATUS_SUCCESS - Operation successful482*483* NOTE: Setting data[0] to XEN_NETIF_CTRL_HASH_ALGORITHM_NONE disables484* hashing and the backend is free to choose how it steers packets485* to queues (which is the default behaviour).486*487* XEN_NETIF_CTRL_TYPE_GET_HASH_FLAGS488* ----------------------------------489*490* This is sent by the frontend to query the types of hash supported by491* the backend.492*493* Request:494*495* type = XEN_NETIF_CTRL_TYPE_GET_HASH_FLAGS496* data[0] = 0497* data[1] = 0498* data[2] = 0499*500* Response:501*502* status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED - Operation not supported503* XEN_NETIF_CTRL_STATUS_SUCCESS - Operation successful504* data = supported hash types (if operation was successful)505*506* NOTE: A valid hash algorithm must be selected before this operation can507* succeed.508*509* XEN_NETIF_CTRL_TYPE_SET_HASH_FLAGS510* ----------------------------------511*512* This is sent by the frontend to set the types of hash that the backend513* should calculate. (See above for hash type definitions).514* Note that the 'maximal' type of hash should always be chosen. For515* example, if the frontend sets both IPV4 and IPV4_TCP hash types then516* the latter hash type should be calculated for any TCP packet and the517* former only calculated for non-TCP packets.518*519* Request:520*521* type = XEN_NETIF_CTRL_TYPE_SET_HASH_FLAGS522* data[0] = bitwise OR of XEN_NETIF_CTRL_HASH_TYPE_* values523* data[1] = 0524* data[2] = 0525*526* Response:527*528* status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED - Operation not529* supported530* XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER - One or more flag531* value is invalid or532* unsupported533* XEN_NETIF_CTRL_STATUS_SUCCESS - Operation successful534* data = 0535*536* NOTE: A valid hash algorithm must be selected before this operation can537* succeed.538* Also, setting data[0] to zero disables hashing and the backend539* is free to choose how it steers packets to queues.540*541* XEN_NETIF_CTRL_TYPE_SET_HASH_KEY542* --------------------------------543*544* This is sent by the frontend to set the key of the hash if the algorithm545* requires it. (See hash algorithms above).546*547* Request:548*549* type = XEN_NETIF_CTRL_TYPE_SET_HASH_KEY550* data[0] = grant reference of page containing the key (assumed to551* start at beginning of grant)552* data[1] = size of key in octets553* data[2] = 0554*555* Response:556*557* status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED - Operation not558* supported559* XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER - Key size is invalid560* XEN_NETIF_CTRL_STATUS_BUFFER_OVERFLOW - Key size is larger561* than the backend562* supports563* XEN_NETIF_CTRL_STATUS_SUCCESS - Operation successful564* data = 0565*566* NOTE: Any key octets not specified are assumed to be zero (the key567* is assumed to be empty by default) and specifying a new key568* invalidates any previous key, hence specifying a key size of569* zero will clear the key (which ensures that the calculated hash570* will always be zero).571* The maximum size of key is algorithm and backend specific, but572* is also limited by the single grant reference.573* The grant reference may be read-only and must remain valid until574* the response has been processed.575*576* XEN_NETIF_CTRL_TYPE_GET_HASH_MAPPING_SIZE577* -----------------------------------------578*579* This is sent by the frontend to query the maximum size of mapping580* table supported by the backend. The size is specified in terms of581* table entries.582*583* Request:584*585* type = XEN_NETIF_CTRL_TYPE_GET_HASH_MAPPING_SIZE586* data[0] = 0587* data[1] = 0588* data[2] = 0589*590* Response:591*592* status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED - Operation not supported593* XEN_NETIF_CTRL_STATUS_SUCCESS - Operation successful594* data = maximum number of entries allowed in the mapping table595* (if operation was successful) or zero if a mapping table is596* not supported (i.e. hash mapping is done only by modular597* arithmetic).598*599* XEN_NETIF_CTRL_TYPE_SET_HASH_MAPPING_SIZE600* -------------------------------------601*602* This is sent by the frontend to set the actual size of the mapping603* table to be used by the backend. The size is specified in terms of604* table entries.605* Any previous table is invalidated by this message and any new table606* is assumed to be zero filled.607*608* Request:609*610* type = XEN_NETIF_CTRL_TYPE_SET_HASH_MAPPING_SIZE611* data[0] = number of entries in mapping table612* data[1] = 0613* data[2] = 0614*615* Response:616*617* status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED - Operation not618* supported619* XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER - Table size is invalid620* XEN_NETIF_CTRL_STATUS_SUCCESS - Operation successful621* data = 0622*623* NOTE: Setting data[0] to 0 means that hash mapping should be done624* using modular arithmetic.625*626* XEN_NETIF_CTRL_TYPE_SET_HASH_MAPPING627* ------------------------------------628*629* This is sent by the frontend to set the content of the table mapping630* hash value to queue number. The backend should calculate the hash from631* the packet header, use it as an index into the table (modulo the size632* of the table) and then steer the packet to the queue number found at633* that index.634*635* Request:636*637* type = XEN_NETIF_CTRL_TYPE_SET_HASH_MAPPING638* data[0] = grant reference of page containing the mapping (sub-)table639* (assumed to start at beginning of grant)640* data[1] = size of (sub-)table in entries641* data[2] = offset, in entries, of sub-table within overall table642*643* Response:644*645* status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED - Operation not646* supported647* XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER - Table size or content648* is invalid649* XEN_NETIF_CTRL_STATUS_BUFFER_OVERFLOW - Table size is larger650* than the backend651* supports652* XEN_NETIF_CTRL_STATUS_SUCCESS - Operation successful653* data = 0654*655* NOTE: The overall table has the following format:656*657* 0 1 2 3 4 5 6 7 octet658* +-----+-----+-----+-----+-----+-----+-----+-----+659* | mapping[0] | mapping[1] |660* +-----+-----+-----+-----+-----+-----+-----+-----+661* | . |662* | . |663* | . |664* +-----+-----+-----+-----+-----+-----+-----+-----+665* | mapping[N-2] | mapping[N-1] |666* +-----+-----+-----+-----+-----+-----+-----+-----+667*668* where N is specified by a XEN_NETIF_CTRL_TYPE_SET_HASH_MAPPING_SIZE669* message and each mapping must specifies a queue between 0 and670* "multi-queue-num-queues" (see above).671* The backend may support a mapping table larger than can be672* mapped by a single grant reference. Thus sub-tables within a673* larger table can be individually set by sending multiple messages674* with differing offset values. Specifying a new sub-table does not675* invalidate any table data outside that range.676* The grant reference may be read-only and must remain valid until677* the response has been processed.678*679* XEN_NETIF_CTRL_TYPE_GET_GREF_MAPPING_SIZE680* -----------------------------------------681*682* This is sent by the frontend to fetch the number of grefs that can be kept683* mapped in the backend.684*685* Request:686*687* type = XEN_NETIF_CTRL_TYPE_GET_GREF_MAPPING_SIZE688* data[0] = queue index (assumed 0 for single queue)689* data[1] = 0690* data[2] = 0691*692* Response:693*694* status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED - Operation not695* supported696* XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER - The queue index is697* out of range698* XEN_NETIF_CTRL_STATUS_SUCCESS - Operation successful699* data = maximum number of entries allowed in the gref mapping table700* (if operation was successful) or zero if it is not supported.701*702* XEN_NETIF_CTRL_TYPE_ADD_GREF_MAPPING703* ------------------------------------704*705* This is sent by the frontend for backend to map a list of grant706* references.707*708* Request:709*710* type = XEN_NETIF_CTRL_TYPE_ADD_GREF_MAPPING711* data[0] = queue index712* data[1] = grant reference of page containing the mapping list713* (r/w and assumed to start at beginning of page)714* data[2] = size of list in entries715*716* Response:717*718* status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED - Operation not719* supported720* XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER - Operation failed721* XEN_NETIF_CTRL_STATUS_SUCCESS - Operation successful722*723* NOTE: Each entry in the input table has the format outlined724* in struct xen_netif_gref.725* Contrary to XEN_NETIF_CTRL_TYPE_DEL_GREF_MAPPING, the struct726* xen_netif_gref 'status' field is not used and therefore the response727* 'status' determines the success of this operation. In case of728* failure none of grants mappings get added in the backend.729*730* XEN_NETIF_CTRL_TYPE_DEL_GREF_MAPPING731* ------------------------------------732*733* This is sent by the frontend for backend to unmap a list of grant734* references.735*736* Request:737*738* type = XEN_NETIF_CTRL_TYPE_DEL_GREF_MAPPING739* data[0] = queue index740* data[1] = grant reference of page containing the mapping list741* (r/w and assumed to start at beginning of page)742* data[2] = size of list in entries743*744* Response:745*746* status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED - Operation not747* supported748* XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER - Operation failed749* XEN_NETIF_CTRL_STATUS_SUCCESS - Operation successful750* data = number of entries that were unmapped751*752* NOTE: Each entry in the input table has the format outlined in struct753* xen_netif_gref.754* The struct xen_netif_gref 'status' field determines if the entry755* was successfully removed.756* The entries used are only the ones representing grant references that757* were previously the subject of a XEN_NETIF_CTRL_TYPE_ADD_GREF_MAPPING758* operation. Any other entries will have their status set to759* XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER upon completion.760*/761762DEFINE_RING_TYPES(xen_netif_ctrl,763struct xen_netif_ctrl_request,764struct xen_netif_ctrl_response);765766/*767* Guest transmit768* ==============769*770* This is the 'wire' format for transmit (frontend -> backend) packets:771*772* Fragment 1: netif_tx_request_t - flags = NETTXF_*773* size = total packet size774* [Extra 1: netif_extra_info_t] - (only if fragment 1 flags include775* NETTXF_extra_info)776* ...777* [Extra N: netif_extra_info_t] - (only if extra N-1 flags include778* XEN_NETIF_EXTRA_MORE)779* ...780* Fragment N: netif_tx_request_t - (only if fragment N-1 flags include781* NETTXF_more_data - flags on preceding782* extras are not relevant here)783* flags = 0784* size = fragment size785*786* NOTE:787*788* This format slightly is different from that used for receive789* (backend -> frontend) packets. Specifically, in a multi-fragment790* packet the actual size of fragment 1 can only be determined by791* subtracting the sizes of fragments 2..N from the total packet size.792*793* Ring slot size is 12 octets, however not all request/response794* structs use the full size.795*796* tx request data (netif_tx_request_t)797* ------------------------------------798*799* 0 1 2 3 4 5 6 7 octet800* +-----+-----+-----+-----+-----+-----+-----+-----+801* | grant ref | offset | flags |802* +-----+-----+-----+-----+-----+-----+-----+-----+803* | id | size |804* +-----+-----+-----+-----+805*806* grant ref: Reference to buffer page.807* offset: Offset within buffer page.808* flags: NETTXF_*.809* id: request identifier, echoed in response.810* size: packet size in bytes.811*812* tx response (netif_tx_response_t)813* ---------------------------------814*815* 0 1 2 3 4 5 6 7 octet816* +-----+-----+-----+-----+-----+-----+-----+-----+817* | id | status | unused |818* +-----+-----+-----+-----+-----+-----+-----+-----+819* | unused |820* +-----+-----+-----+-----+821*822* id: reflects id in transmit request823* status: NETIF_RSP_*824*825* Guest receive826* =============827*828* This is the 'wire' format for receive (backend -> frontend) packets:829*830* Fragment 1: netif_rx_request_t - flags = NETRXF_*831* size = fragment size832* [Extra 1: netif_extra_info_t] - (only if fragment 1 flags include833* NETRXF_extra_info)834* ...835* [Extra N: netif_extra_info_t] - (only if extra N-1 flags include836* XEN_NETIF_EXTRA_MORE)837* ...838* Fragment N: netif_rx_request_t - (only if fragment N-1 flags include839* NETRXF_more_data - flags on preceding840* extras are not relevant here)841* flags = 0842* size = fragment size843*844* NOTE:845*846* This format slightly is different from that used for transmit847* (frontend -> backend) packets. Specifically, in a multi-fragment848* packet the size of the packet can only be determined by summing the849* sizes of fragments 1..N.850*851* Ring slot size is 8 octets.852*853* rx request (netif_rx_request_t)854* -------------------------------855*856* 0 1 2 3 4 5 6 7 octet857* +-----+-----+-----+-----+-----+-----+-----+-----+858* | id | pad | gref |859* +-----+-----+-----+-----+-----+-----+-----+-----+860*861* id: request identifier, echoed in response.862* gref: reference to incoming granted frame.863*864* rx response (netif_rx_response_t)865* ---------------------------------866*867* 0 1 2 3 4 5 6 7 octet868* +-----+-----+-----+-----+-----+-----+-----+-----+869* | id | offset | flags | status |870* +-----+-----+-----+-----+-----+-----+-----+-----+871*872* id: reflects id in receive request873* offset: offset in page of start of received packet874* flags: NETRXF_*875* status: -ve: NETIF_RSP_*; +ve: Rx'ed pkt size.876*877* NOTE: Historically, to support GSO on the frontend receive side, Linux878* netfront does not make use of the rx response id (because, as879* described below, extra info structures overlay the id field).880* Instead it assumes that responses always appear in the same ring881* slot as their corresponding request. Thus, to maintain882* compatibility, backends must make sure this is the case.883*884* Extra Info885* ==========886*887* Can be present if initial request or response has NET{T,R}XF_extra_info,888* or previous extra request has XEN_NETIF_EXTRA_MORE.889*890* The struct therefore needs to fit into either a tx or rx slot and891* is therefore limited to 8 octets.892*893* NOTE: Because extra info data overlays the usual request/response894* structures, there is no id information in the opposite direction.895* So, if an extra info overlays an rx response the frontend can896* assume that it is in the same ring slot as the request that was897* consumed to make the slot available, and the backend must ensure898* this assumption is true.899*900* extra info (netif_extra_info_t)901* -------------------------------902*903* General format:904*905* 0 1 2 3 4 5 6 7 octet906* +-----+-----+-----+-----+-----+-----+-----+-----+907* |type |flags| type specific data |908* +-----+-----+-----+-----+-----+-----+-----+-----+909* | padding for tx |910* +-----+-----+-----+-----+911*912* type: XEN_NETIF_EXTRA_TYPE_*913* flags: XEN_NETIF_EXTRA_FLAG_*914* padding for tx: present only in the tx case due to 8 octet limit915* from rx case. Not shown in type specific entries916* below.917*918* XEN_NETIF_EXTRA_TYPE_GSO:919*920* 0 1 2 3 4 5 6 7 octet921* +-----+-----+-----+-----+-----+-----+-----+-----+922* |type |flags| size |type | pad | features |923* +-----+-----+-----+-----+-----+-----+-----+-----+924*925* type: Must be XEN_NETIF_EXTRA_TYPE_GSO926* flags: XEN_NETIF_EXTRA_FLAG_*927* size: Maximum payload size of each segment. For example,928* for TCP this is just the path MSS.929* type: XEN_NETIF_GSO_TYPE_*: This determines the protocol of930* the packet and any extra features required to segment the931* packet properly.932* features: EN_NETIF_GSO_FEAT_*: This specifies any extra GSO933* features required to process this packet, such as ECN934* support for TCPv4.935*936* XEN_NETIF_EXTRA_TYPE_MCAST_{ADD,DEL}:937*938* 0 1 2 3 4 5 6 7 octet939* +-----+-----+-----+-----+-----+-----+-----+-----+940* |type |flags| addr |941* +-----+-----+-----+-----+-----+-----+-----+-----+942*943* type: Must be XEN_NETIF_EXTRA_TYPE_MCAST_{ADD,DEL}944* flags: XEN_NETIF_EXTRA_FLAG_*945* addr: address to add/remove946*947* XEN_NETIF_EXTRA_TYPE_HASH:948*949* A backend that supports teoplitz hashing is assumed to accept950* this type of extra info in transmit packets.951* A frontend that enables hashing is assumed to accept952* this type of extra info in receive packets.953*954* 0 1 2 3 4 5 6 7 octet955* +-----+-----+-----+-----+-----+-----+-----+-----+956* |type |flags|htype| alg |LSB ---- value ---- MSB|957* +-----+-----+-----+-----+-----+-----+-----+-----+958*959* type: Must be XEN_NETIF_EXTRA_TYPE_HASH960* flags: XEN_NETIF_EXTRA_FLAG_*961* htype: Hash type (one of _XEN_NETIF_CTRL_HASH_TYPE_* - see above)962* alg: The algorithm used to calculate the hash (one of963* XEN_NETIF_CTRL_HASH_TYPE_ALGORITHM_* - see above)964* value: Hash value965*/966967/* Protocol checksum field is blank in the packet (hardware offload)? */968#define _NETTXF_csum_blank (0)969#define NETTXF_csum_blank (1U<<_NETTXF_csum_blank)970971/* Packet data has been validated against protocol checksum. */972#define _NETTXF_data_validated (1)973#define NETTXF_data_validated (1U<<_NETTXF_data_validated)974975/* Packet continues in the next request descriptor. */976#define _NETTXF_more_data (2)977#define NETTXF_more_data (1U<<_NETTXF_more_data)978979/* Packet to be followed by extra descriptor(s). */980#define _NETTXF_extra_info (3)981#define NETTXF_extra_info (1U<<_NETTXF_extra_info)982983#define XEN_NETIF_MAX_TX_SIZE 0xFFFF984struct netif_tx_request {985grant_ref_t gref;986uint16_t offset;987uint16_t flags;988uint16_t id;989uint16_t size;990};991typedef struct netif_tx_request netif_tx_request_t;992993/* Types of netif_extra_info descriptors. */994#define XEN_NETIF_EXTRA_TYPE_NONE (0) /* Never used - invalid */995#define XEN_NETIF_EXTRA_TYPE_GSO (1) /* u.gso */996#define XEN_NETIF_EXTRA_TYPE_MCAST_ADD (2) /* u.mcast */997#define XEN_NETIF_EXTRA_TYPE_MCAST_DEL (3) /* u.mcast */998#define XEN_NETIF_EXTRA_TYPE_HASH (4) /* u.hash */999#define XEN_NETIF_EXTRA_TYPE_MAX (5)10001001/* netif_extra_info_t flags. */1002#define _XEN_NETIF_EXTRA_FLAG_MORE (0)1003#define XEN_NETIF_EXTRA_FLAG_MORE (1U<<_XEN_NETIF_EXTRA_FLAG_MORE)10041005/* GSO types */1006#define XEN_NETIF_GSO_TYPE_NONE (0)1007#define XEN_NETIF_GSO_TYPE_TCPV4 (1)1008#define XEN_NETIF_GSO_TYPE_TCPV6 (2)10091010/*1011* This structure needs to fit within both netif_tx_request_t and1012* netif_rx_response_t for compatibility.1013*/1014struct netif_extra_info {1015uint8_t type;1016uint8_t flags;1017union {1018struct {1019uint16_t size;1020uint8_t type;1021uint8_t pad;1022uint16_t features;1023} gso;1024struct {1025uint8_t addr[6];1026} mcast;1027struct {1028uint8_t type;1029uint8_t algorithm;1030uint8_t value[4];1031} hash;1032uint16_t pad[3];1033} u;1034};1035typedef struct netif_extra_info netif_extra_info_t;10361037struct netif_tx_response {1038uint16_t id;1039int16_t status;1040};1041typedef struct netif_tx_response netif_tx_response_t;10421043struct netif_rx_request {1044uint16_t id; /* Echoed in response message. */1045uint16_t pad;1046grant_ref_t gref;1047};1048typedef struct netif_rx_request netif_rx_request_t;10491050/* Packet data has been validated against protocol checksum. */1051#define _NETRXF_data_validated (0)1052#define NETRXF_data_validated (1U<<_NETRXF_data_validated)10531054/* Protocol checksum field is blank in the packet (hardware offload)? */1055#define _NETRXF_csum_blank (1)1056#define NETRXF_csum_blank (1U<<_NETRXF_csum_blank)10571058/* Packet continues in the next request descriptor. */1059#define _NETRXF_more_data (2)1060#define NETRXF_more_data (1U<<_NETRXF_more_data)10611062/* Packet to be followed by extra descriptor(s). */1063#define _NETRXF_extra_info (3)1064#define NETRXF_extra_info (1U<<_NETRXF_extra_info)10651066/* Packet has GSO prefix. Deprecated but included for compatibility */1067#define _NETRXF_gso_prefix (4)1068#define NETRXF_gso_prefix (1U<<_NETRXF_gso_prefix)10691070struct netif_rx_response {1071uint16_t id;1072uint16_t offset;1073uint16_t flags;1074int16_t status;1075};1076typedef struct netif_rx_response netif_rx_response_t;10771078/*1079* Generate netif ring structures and types.1080*/10811082DEFINE_RING_TYPES(netif_tx, struct netif_tx_request, struct netif_tx_response);1083DEFINE_RING_TYPES(netif_rx, struct netif_rx_request, struct netif_rx_response);10841085#define NETIF_RSP_DROPPED -21086#define NETIF_RSP_ERROR -11087#define NETIF_RSP_OKAY 01088/* No response: used for auxiliary requests (e.g., netif_extra_info_t). */1089#define NETIF_RSP_NULL 110901091#endif10921093/*1094* Local variables:1095* mode: C1096* c-file-style: "BSD"1097* c-basic-offset: 41098* tab-width: 41099* indent-tabs-mode: nil1100* End:1101*/110211031104