/* SPDX-License-Identifier: MIT */1/******************************************************************************2* xen_netif.h3*4* Unified network-device I/O interface for Xen guest OSes.5*6* Copyright (c) 2003-2004, Keir Fraser7*/89#ifndef __XEN_PUBLIC_IO_XEN_NETIF_H__10#define __XEN_PUBLIC_IO_XEN_NETIF_H__1112#include "ring.h"13#include "../grant_table.h"1415/*16* Older implementation of Xen network frontend / backend has an17* implicit dependency on the MAX_SKB_FRAGS as the maximum number of18* ring slots a skb can use. Netfront / netback may not work as19* expected when frontend and backend have different MAX_SKB_FRAGS.20*21* A better approach is to add mechanism for netfront / netback to22* negotiate this value. However we cannot fix all possible23* frontends, so we need to define a value which states the minimum24* slots backend must support.25*26* The minimum value derives from older Linux kernel's MAX_SKB_FRAGS27* (18), which is proved to work with most frontends. Any new backend28* which doesn't negotiate with frontend should expect frontend to29* send a valid packet using slots up to this value.30*/31#define XEN_NETIF_NR_SLOTS_MIN 183233/*34* Notifications after enqueuing any type of message should be conditional on35* the appropriate req_event or rsp_event field in the shared ring.36* If the client sends notification for rx requests then it should specify37* feature 'feature-rx-notify' via xenbus. Otherwise the backend will assume38* that it cannot safely queue packets (as it may not be kicked to send them).39*/4041/*42* "feature-split-event-channels" is introduced to separate guest TX43* and RX notification. Backend either doesn't support this feature or44* advertises it via xenstore as 0 (disabled) or 1 (enabled).45*46* To make use of this feature, frontend should allocate two event47* channels for TX and RX, advertise them to backend as48* "event-channel-tx" and "event-channel-rx" respectively. If frontend49* doesn't want to use this feature, it just writes "event-channel"50* node as before.51*/5253/*54* Multiple transmit and receive queues:55* If supported, the backend will write the key "multi-queue-max-queues" to56* the directory for that vif, and set its value to the maximum supported57* number of queues.58* Frontends that are aware of this feature and wish to use it can write the59* key "multi-queue-num-queues", set to the number they wish to use, which60* must be greater than zero, and no more than the value reported by the backend61* in "multi-queue-max-queues".62*63* Queues replicate the shared rings and event channels.64* "feature-split-event-channels" may optionally be used when using65* multiple queues, but is not mandatory.66*67* Each queue consists of one shared ring pair, i.e. there must be the same68* number of tx and rx rings.69*70* For frontends requesting just one queue, the usual event-channel and71* ring-ref keys are written as before, simplifying the backend processing72* to avoid distinguishing between a frontend that doesn't understand the73* multi-queue feature, and one that does, but requested only one queue.74*75* Frontends requesting two or more queues must not write the toplevel76* event-channel (or event-channel-{tx,rx}) and {tx,rx}-ring-ref keys,77* instead writing those keys under sub-keys having the name "queue-N" where78* N is the integer ID of the queue for which those keys belong. Queues79* are indexed from zero. For example, a frontend with two queues and split80* event channels must write the following set of queue-related keys:81*82* /local/domain/1/device/vif/0/multi-queue-num-queues = "2"83* /local/domain/1/device/vif/0/queue-0 = ""84* /local/domain/1/device/vif/0/queue-0/tx-ring-ref = "<ring-ref-tx0>"85* /local/domain/1/device/vif/0/queue-0/rx-ring-ref = "<ring-ref-rx0>"86* /local/domain/1/device/vif/0/queue-0/event-channel-tx = "<evtchn-tx0>"87* /local/domain/1/device/vif/0/queue-0/event-channel-rx = "<evtchn-rx0>"88* /local/domain/1/device/vif/0/queue-1 = ""89* /local/domain/1/device/vif/0/queue-1/tx-ring-ref = "<ring-ref-tx1>"90* /local/domain/1/device/vif/0/queue-1/rx-ring-ref = "<ring-ref-rx1"91* /local/domain/1/device/vif/0/queue-1/event-channel-tx = "<evtchn-tx1>"92* /local/domain/1/device/vif/0/queue-1/event-channel-rx = "<evtchn-rx1>"93*94* If there is any inconsistency in the XenStore data, the backend may95* choose not to connect any queues, instead treating the request as an96* error. This includes scenarios where more (or fewer) queues were97* requested than the frontend provided details for.98*99* Mapping of packets to queues is considered to be a function of the100* transmitting system (backend or frontend) and is not negotiated101* between the two. Guests are free to transmit packets on any queue102* they choose, provided it has been set up correctly. Guests must be103* prepared to receive packets on any queue they have requested be set up.104*/105106/*107* "feature-no-csum-offload" should be used to turn IPv4 TCP/UDP checksum108* offload off or on. If it is missing then the feature is assumed to be on.109* "feature-ipv6-csum-offload" should be used to turn IPv6 TCP/UDP checksum110* offload on or off. If it is missing then the feature is assumed to be off.111*/112113/*114* "feature-gso-tcpv4" and "feature-gso-tcpv6" advertise the capability to115* handle large TCP packets (in IPv4 or IPv6 form respectively). Neither116* frontends nor backends are assumed to be capable unless the flags are117* present.118*/119120/*121* "feature-multicast-control" and "feature-dynamic-multicast-control"122* advertise the capability to filter ethernet multicast packets in the123* backend. If the frontend wishes to take advantage of this feature then124* it may set "request-multicast-control". If the backend only advertises125* "feature-multicast-control" then "request-multicast-control" must be set126* before the frontend moves into the connected state. The backend will127* sample the value on this state transition and any subsequent change in128* value will have no effect. However, if the backend also advertises129* "feature-dynamic-multicast-control" then "request-multicast-control"130* may be set by the frontend at any time. In this case, the backend will131* watch the value and re-sample on watch events.132*133* If the sampled value of "request-multicast-control" is set then the134* backend transmit side should no longer flood multicast packets to the135* frontend, it should instead drop any multicast packet that does not136* match in a filter list.137* The list is amended by the frontend by sending dummy transmit requests138* containing XEN_NETIF_EXTRA_TYPE_MCAST_{ADD,DEL} extra-info fragments as139* specified below.140* Note that the filter list may be amended even if the sampled value of141* "request-multicast-control" is not set, however the filter should only142* be applied if it is set.143*/144145/*146* "xdp-headroom" is used to request that extra space is added147* for XDP processing. The value is measured in bytes and passed by148* the frontend to be consistent between both ends.149* If the value is greater than zero that means that150* an RX response is going to be passed to an XDP program for processing.151* XEN_NETIF_MAX_XDP_HEADROOM defines the maximum headroom offset in bytes152*153* "feature-xdp-headroom" is set to "1" by the netback side like other features154* so a guest can check if an XDP program can be processed.155*/156#define XEN_NETIF_MAX_XDP_HEADROOM 0x7FFF157158/*159* Control ring160* ============161*162* Some features, such as hashing (detailed below), require a163* significant amount of out-of-band data to be passed from frontend to164* backend. Use of xenstore is not suitable for large quantities of data165* because of quota limitations and so a dedicated 'control ring' is used.166* The ability of the backend to use a control ring is advertised by167* setting:168*169* /local/domain/X/backend/<domid>/<vif>/feature-ctrl-ring = "1"170*171* The frontend provides a control ring to the backend by setting:172*173* /local/domain/<domid>/device/vif/<vif>/ctrl-ring-ref = <gref>174* /local/domain/<domid>/device/vif/<vif>/event-channel-ctrl = <port>175*176* where <gref> is the grant reference of the shared page used to177* implement the control ring and <port> is an event channel to be used178* as a mailbox interrupt. These keys must be set before the frontend179* moves into the connected state.180*181* The control ring uses a fixed request/response message size and is182* balanced (i.e. one request to one response), so operationally it is much183* the same as a transmit or receive ring.184* Note that there is no requirement that responses are issued in the same185* order as requests.186*/187188/*189* Hash types190* ==========191*192* For the purposes of the definitions below, 'Packet[]' is an array of193* octets containing an IP packet without options, 'Array[X..Y]' means a194* sub-array of 'Array' containing bytes X thru Y inclusive, and '+' is195* used to indicate concatenation of arrays.196*/197198/*199* A hash calculated over an IP version 4 header as follows:200*201* Buffer[0..8] = Packet[12..15] (source address) +202* Packet[16..19] (destination address)203*204* Result = Hash(Buffer, 8)205*/206#define _XEN_NETIF_CTRL_HASH_TYPE_IPV4 0207#define XEN_NETIF_CTRL_HASH_TYPE_IPV4 \208(1 << _XEN_NETIF_CTRL_HASH_TYPE_IPV4)209210/*211* A hash calculated over an IP version 4 header and TCP header as212* follows:213*214* Buffer[0..12] = Packet[12..15] (source address) +215* Packet[16..19] (destination address) +216* Packet[20..21] (source port) +217* Packet[22..23] (destination port)218*219* Result = Hash(Buffer, 12)220*/221#define _XEN_NETIF_CTRL_HASH_TYPE_IPV4_TCP 1222#define XEN_NETIF_CTRL_HASH_TYPE_IPV4_TCP \223(1 << _XEN_NETIF_CTRL_HASH_TYPE_IPV4_TCP)224225/*226* A hash calculated over an IP version 6 header as follows:227*228* Buffer[0..32] = Packet[8..23] (source address ) +229* Packet[24..39] (destination address)230*231* Result = Hash(Buffer, 32)232*/233#define _XEN_NETIF_CTRL_HASH_TYPE_IPV6 2234#define XEN_NETIF_CTRL_HASH_TYPE_IPV6 \235(1 << _XEN_NETIF_CTRL_HASH_TYPE_IPV6)236237/*238* A hash calculated over an IP version 6 header and TCP header as239* follows:240*241* Buffer[0..36] = Packet[8..23] (source address) +242* Packet[24..39] (destination address) +243* Packet[40..41] (source port) +244* Packet[42..43] (destination port)245*246* Result = Hash(Buffer, 36)247*/248#define _XEN_NETIF_CTRL_HASH_TYPE_IPV6_TCP 3249#define XEN_NETIF_CTRL_HASH_TYPE_IPV6_TCP \250(1 << _XEN_NETIF_CTRL_HASH_TYPE_IPV6_TCP)251252/*253* Hash algorithms254* ===============255*/256257#define XEN_NETIF_CTRL_HASH_ALGORITHM_NONE 0258259/*260* Toeplitz hash:261*/262263#define XEN_NETIF_CTRL_HASH_ALGORITHM_TOEPLITZ 1264265/*266* This algorithm uses a 'key' as well as the data buffer itself.267* (Buffer[] and Key[] are treated as shift-registers where the MSB of268* Buffer/Key[0] is considered 'left-most' and the LSB of Buffer/Key[N-1]269* is the 'right-most').270*271* Value = 0272* For number of bits in Buffer[]273* If (left-most bit of Buffer[] is 1)274* Value ^= left-most 32 bits of Key[]275* Key[] << 1276* Buffer[] << 1277*278* The code below is provided for convenience where an operating system279* does not already provide an implementation.280*/281#ifdef XEN_NETIF_DEFINE_TOEPLITZ282static uint32_t xen_netif_toeplitz_hash(const uint8_t *key,283unsigned int keylen,284const uint8_t *buf, unsigned int buflen)285{286unsigned int keyi, bufi;287uint64_t prefix = 0;288uint64_t hash = 0;289290/* Pre-load prefix with the first 8 bytes of the key */291for (keyi = 0; keyi < 8; keyi++) {292prefix <<= 8;293prefix |= (keyi < keylen) ? key[keyi] : 0;294}295296for (bufi = 0; bufi < buflen; bufi++) {297uint8_t byte = buf[bufi];298unsigned int bit;299300for (bit = 0; bit < 8; bit++) {301if (byte & 0x80)302hash ^= prefix;303prefix <<= 1;304byte <<= 1;305}306307/*308* 'prefix' has now been left-shifted by 8, so309* OR in the next byte.310*/311prefix |= (keyi < keylen) ? key[keyi] : 0;312keyi++;313}314315/* The valid part of the hash is in the upper 32 bits. */316return hash >> 32;317}318#endif /* XEN_NETIF_DEFINE_TOEPLITZ */319320/*321* Control requests (struct xen_netif_ctrl_request)322* ================================================323*324* All requests have the following format:325*326* 0 1 2 3 4 5 6 7 octet327* +-----+-----+-----+-----+-----+-----+-----+-----+328* | id | type | data[0] |329* +-----+-----+-----+-----+-----+-----+-----+-----+330* | data[1] | data[2] |331* +-----+-----+-----+-----+-----------------------+332*333* id: the request identifier, echoed in response.334* type: the type of request (see below)335* data[]: any data associated with the request (determined by type)336*/337338struct xen_netif_ctrl_request {339uint16_t id;340uint16_t type;341342#define XEN_NETIF_CTRL_TYPE_INVALID 0343#define XEN_NETIF_CTRL_TYPE_GET_HASH_FLAGS 1344#define XEN_NETIF_CTRL_TYPE_SET_HASH_FLAGS 2345#define XEN_NETIF_CTRL_TYPE_SET_HASH_KEY 3346#define XEN_NETIF_CTRL_TYPE_GET_HASH_MAPPING_SIZE 4347#define XEN_NETIF_CTRL_TYPE_SET_HASH_MAPPING_SIZE 5348#define XEN_NETIF_CTRL_TYPE_SET_HASH_MAPPING 6349#define XEN_NETIF_CTRL_TYPE_SET_HASH_ALGORITHM 7350351uint32_t data[3];352};353354/*355* Control responses (struct xen_netif_ctrl_response)356* ==================================================357*358* All responses have the following format:359*360* 0 1 2 3 4 5 6 7 octet361* +-----+-----+-----+-----+-----+-----+-----+-----+362* | id | type | status |363* +-----+-----+-----+-----+-----+-----+-----+-----+364* | data |365* +-----+-----+-----+-----+366*367* id: the corresponding request identifier368* type: the type of the corresponding request369* status: the status of request processing370* data: any data associated with the response (determined by type and371* status)372*/373374struct xen_netif_ctrl_response {375uint16_t id;376uint16_t type;377uint32_t status;378379#define XEN_NETIF_CTRL_STATUS_SUCCESS 0380#define XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED 1381#define XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER 2382#define XEN_NETIF_CTRL_STATUS_BUFFER_OVERFLOW 3383384uint32_t data;385};386387/*388* Control messages389* ================390*391* XEN_NETIF_CTRL_TYPE_SET_HASH_ALGORITHM392* --------------------------------------393*394* This is sent by the frontend to set the desired hash algorithm.395*396* Request:397*398* type = XEN_NETIF_CTRL_TYPE_SET_HASH_ALGORITHM399* data[0] = a XEN_NETIF_CTRL_HASH_ALGORITHM_* value400* data[1] = 0401* data[2] = 0402*403* Response:404*405* status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED - Operation not406* supported407* XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER - The algorithm is not408* supported409* XEN_NETIF_CTRL_STATUS_SUCCESS - Operation successful410*411* NOTE: Setting data[0] to XEN_NETIF_CTRL_HASH_ALGORITHM_NONE disables412* hashing and the backend is free to choose how it steers packets413* to queues (which is the default behaviour).414*415* XEN_NETIF_CTRL_TYPE_GET_HASH_FLAGS416* ----------------------------------417*418* This is sent by the frontend to query the types of hash supported by419* the backend.420*421* Request:422*423* type = XEN_NETIF_CTRL_TYPE_GET_HASH_FLAGS424* data[0] = 0425* data[1] = 0426* data[2] = 0427*428* Response:429*430* status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED - Operation not supported431* XEN_NETIF_CTRL_STATUS_SUCCESS - Operation successful432* data = supported hash types (if operation was successful)433*434* NOTE: A valid hash algorithm must be selected before this operation can435* succeed.436*437* XEN_NETIF_CTRL_TYPE_SET_HASH_FLAGS438* ----------------------------------439*440* This is sent by the frontend to set the types of hash that the backend441* should calculate. (See above for hash type definitions).442* Note that the 'maximal' type of hash should always be chosen. For443* example, if the frontend sets both IPV4 and IPV4_TCP hash types then444* the latter hash type should be calculated for any TCP packet and the445* former only calculated for non-TCP packets.446*447* Request:448*449* type = XEN_NETIF_CTRL_TYPE_SET_HASH_FLAGS450* data[0] = bitwise OR of XEN_NETIF_CTRL_HASH_TYPE_* values451* data[1] = 0452* data[2] = 0453*454* Response:455*456* status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED - Operation not457* supported458* XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER - One or more flag459* value is invalid or460* unsupported461* XEN_NETIF_CTRL_STATUS_SUCCESS - Operation successful462* data = 0463*464* NOTE: A valid hash algorithm must be selected before this operation can465* succeed.466* Also, setting data[0] to zero disables hashing and the backend467* is free to choose how it steers packets to queues.468*469* XEN_NETIF_CTRL_TYPE_SET_HASH_KEY470* --------------------------------471*472* This is sent by the frontend to set the key of the hash if the algorithm473* requires it. (See hash algorithms above).474*475* Request:476*477* type = XEN_NETIF_CTRL_TYPE_SET_HASH_KEY478* data[0] = grant reference of page containing the key (assumed to479* start at beginning of grant)480* data[1] = size of key in octets481* data[2] = 0482*483* Response:484*485* status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED - Operation not486* supported487* XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER - Key size is invalid488* XEN_NETIF_CTRL_STATUS_BUFFER_OVERFLOW - Key size is larger489* than the backend490* supports491* XEN_NETIF_CTRL_STATUS_SUCCESS - Operation successful492* data = 0493*494* NOTE: Any key octets not specified are assumed to be zero (the key495* is assumed to be empty by default) and specifying a new key496* invalidates any previous key, hence specifying a key size of497* zero will clear the key (which ensures that the calculated hash498* will always be zero).499* The maximum size of key is algorithm and backend specific, but500* is also limited by the single grant reference.501* The grant reference may be read-only and must remain valid until502* the response has been processed.503*504* XEN_NETIF_CTRL_TYPE_GET_HASH_MAPPING_SIZE505* -----------------------------------------506*507* This is sent by the frontend to query the maximum size of mapping508* table supported by the backend. The size is specified in terms of509* table entries.510*511* Request:512*513* type = XEN_NETIF_CTRL_TYPE_GET_HASH_MAPPING_SIZE514* data[0] = 0515* data[1] = 0516* data[2] = 0517*518* Response:519*520* status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED - Operation not supported521* XEN_NETIF_CTRL_STATUS_SUCCESS - Operation successful522* data = maximum number of entries allowed in the mapping table523* (if operation was successful) or zero if a mapping table is524* not supported (i.e. hash mapping is done only by modular525* arithmetic).526*527* XEN_NETIF_CTRL_TYPE_SET_HASH_MAPPING_SIZE528* -------------------------------------529*530* This is sent by the frontend to set the actual size of the mapping531* table to be used by the backend. The size is specified in terms of532* table entries.533* Any previous table is invalidated by this message and any new table534* is assumed to be zero filled.535*536* Request:537*538* type = XEN_NETIF_CTRL_TYPE_SET_HASH_MAPPING_SIZE539* data[0] = number of entries in mapping table540* data[1] = 0541* data[2] = 0542*543* Response:544*545* status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED - Operation not546* supported547* XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER - Table size is invalid548* XEN_NETIF_CTRL_STATUS_SUCCESS - Operation successful549* data = 0550*551* NOTE: Setting data[0] to 0 means that hash mapping should be done552* using modular arithmetic.553*554* XEN_NETIF_CTRL_TYPE_SET_HASH_MAPPING555* ------------------------------------556*557* This is sent by the frontend to set the content of the table mapping558* hash value to queue number. The backend should calculate the hash from559* the packet header, use it as an index into the table (modulo the size560* of the table) and then steer the packet to the queue number found at561* that index.562*563* Request:564*565* type = XEN_NETIF_CTRL_TYPE_SET_HASH_MAPPING566* data[0] = grant reference of page containing the mapping (sub-)table567* (assumed to start at beginning of grant)568* data[1] = size of (sub-)table in entries569* data[2] = offset, in entries, of sub-table within overall table570*571* Response:572*573* status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED - Operation not574* supported575* XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER - Table size or content576* is invalid577* XEN_NETIF_CTRL_STATUS_BUFFER_OVERFLOW - Table size is larger578* than the backend579* supports580* XEN_NETIF_CTRL_STATUS_SUCCESS - Operation successful581* data = 0582*583* NOTE: The overall table has the following format:584*585* 0 1 2 3 4 5 6 7 octet586* +-----+-----+-----+-----+-----+-----+-----+-----+587* | mapping[0] | mapping[1] |588* +-----+-----+-----+-----+-----+-----+-----+-----+589* | . |590* | . |591* | . |592* +-----+-----+-----+-----+-----+-----+-----+-----+593* | mapping[N-2] | mapping[N-1] |594* +-----+-----+-----+-----+-----+-----+-----+-----+595*596* where N is specified by a XEN_NETIF_CTRL_TYPE_SET_HASH_MAPPING_SIZE597* message and each mapping must specifies a queue between 0 and598* "multi-queue-num-queues" (see above).599* The backend may support a mapping table larger than can be600* mapped by a single grant reference. Thus sub-tables within a601* larger table can be individually set by sending multiple messages602* with differing offset values. Specifying a new sub-table does not603* invalidate any table data outside that range.604* The grant reference may be read-only and must remain valid until605* the response has been processed.606*/607608DEFINE_RING_TYPES(xen_netif_ctrl,609struct xen_netif_ctrl_request,610struct xen_netif_ctrl_response);611612/*613* Guest transmit614* ==============615*616* This is the 'wire' format for transmit (frontend -> backend) packets:617*618* Fragment 1: xen_netif_tx_request_t - flags = XEN_NETTXF_*619* size = total packet size620* [Extra 1: xen_netif_extra_info_t] - (only if fragment 1 flags include621* XEN_NETTXF_extra_info)622* ...623* [Extra N: xen_netif_extra_info_t] - (only if extra N-1 flags include624* XEN_NETIF_EXTRA_MORE)625* ...626* Fragment N: xen_netif_tx_request_t - (only if fragment N-1 flags include627* XEN_NETTXF_more_data - flags on preceding628* extras are not relevant here)629* flags = 0630* size = fragment size631*632* NOTE:633*634* This format slightly is different from that used for receive635* (backend -> frontend) packets. Specifically, in a multi-fragment636* packet the actual size of fragment 1 can only be determined by637* subtracting the sizes of fragments 2..N from the total packet size.638*639* Ring slot size is 12 octets, however not all request/response640* structs use the full size.641*642* tx request data (xen_netif_tx_request_t)643* ------------------------------------644*645* 0 1 2 3 4 5 6 7 octet646* +-----+-----+-----+-----+-----+-----+-----+-----+647* | grant ref | offset | flags |648* +-----+-----+-----+-----+-----+-----+-----+-----+649* | id | size |650* +-----+-----+-----+-----+651*652* grant ref: Reference to buffer page.653* offset: Offset within buffer page.654* flags: XEN_NETTXF_*.655* id: request identifier, echoed in response.656* size: packet size in bytes.657*658* tx response (xen_netif_tx_response_t)659* ---------------------------------660*661* 0 1 2 3 4 5 6 7 octet662* +-----+-----+-----+-----+-----+-----+-----+-----+663* | id | status | unused |664* +-----+-----+-----+-----+-----+-----+-----+-----+665* | unused |666* +-----+-----+-----+-----+667*668* id: reflects id in transmit request669* status: XEN_NETIF_RSP_*670*671* Guest receive672* =============673*674* This is the 'wire' format for receive (backend -> frontend) packets:675*676* Fragment 1: xen_netif_rx_request_t - flags = XEN_NETRXF_*677* size = fragment size678* [Extra 1: xen_netif_extra_info_t] - (only if fragment 1 flags include679* XEN_NETRXF_extra_info)680* ...681* [Extra N: xen_netif_extra_info_t] - (only if extra N-1 flags include682* XEN_NETIF_EXTRA_MORE)683* ...684* Fragment N: xen_netif_rx_request_t - (only if fragment N-1 flags include685* XEN_NETRXF_more_data - flags on preceding686* extras are not relevant here)687* flags = 0688* size = fragment size689*690* NOTE:691*692* This format slightly is different from that used for transmit693* (frontend -> backend) packets. Specifically, in a multi-fragment694* packet the size of the packet can only be determined by summing the695* sizes of fragments 1..N.696*697* Ring slot size is 8 octets.698*699* rx request (xen_netif_rx_request_t)700* -------------------------------701*702* 0 1 2 3 4 5 6 7 octet703* +-----+-----+-----+-----+-----+-----+-----+-----+704* | id | pad | gref |705* +-----+-----+-----+-----+-----+-----+-----+-----+706*707* id: request identifier, echoed in response.708* gref: reference to incoming granted frame.709*710* rx response (xen_netif_rx_response_t)711* ---------------------------------712*713* 0 1 2 3 4 5 6 7 octet714* +-----+-----+-----+-----+-----+-----+-----+-----+715* | id | offset | flags | status |716* +-----+-----+-----+-----+-----+-----+-----+-----+717*718* id: reflects id in receive request719* offset: offset in page of start of received packet720* flags: XEN_NETRXF_*721* status: -ve: XEN_NETIF_RSP_*; +ve: Rx'ed pkt size.722*723* NOTE: Historically, to support GSO on the frontend receive side, Linux724* netfront does not make use of the rx response id (because, as725* described below, extra info structures overlay the id field).726* Instead it assumes that responses always appear in the same ring727* slot as their corresponding request. Thus, to maintain728* compatibility, backends must make sure this is the case.729*730* Extra Info731* ==========732*733* Can be present if initial request or response has NET{T,R}XF_extra_info,734* or previous extra request has XEN_NETIF_EXTRA_MORE.735*736* The struct therefore needs to fit into either a tx or rx slot and737* is therefore limited to 8 octets.738*739* NOTE: Because extra info data overlays the usual request/response740* structures, there is no id information in the opposite direction.741* So, if an extra info overlays an rx response the frontend can742* assume that it is in the same ring slot as the request that was743* consumed to make the slot available, and the backend must ensure744* this assumption is true.745*746* extra info (xen_netif_extra_info_t)747* -------------------------------748*749* General format:750*751* 0 1 2 3 4 5 6 7 octet752* +-----+-----+-----+-----+-----+-----+-----+-----+753* |type |flags| type specific data |754* +-----+-----+-----+-----+-----+-----+-----+-----+755* | padding for tx |756* +-----+-----+-----+-----+757*758* type: XEN_NETIF_EXTRA_TYPE_*759* flags: XEN_NETIF_EXTRA_FLAG_*760* padding for tx: present only in the tx case due to 8 octet limit761* from rx case. Not shown in type specific entries762* below.763*764* XEN_NETIF_EXTRA_TYPE_GSO:765*766* 0 1 2 3 4 5 6 7 octet767* +-----+-----+-----+-----+-----+-----+-----+-----+768* |type |flags| size |type | pad | features |769* +-----+-----+-----+-----+-----+-----+-----+-----+770*771* type: Must be XEN_NETIF_EXTRA_TYPE_GSO772* flags: XEN_NETIF_EXTRA_FLAG_*773* size: Maximum payload size of each segment. For example,774* for TCP this is just the path MSS.775* type: XEN_NETIF_GSO_TYPE_*: This determines the protocol of776* the packet and any extra features required to segment the777* packet properly.778* features: EN_XEN_NETIF_GSO_FEAT_*: This specifies any extra GSO779* features required to process this packet, such as ECN780* support for TCPv4.781*782* XEN_NETIF_EXTRA_TYPE_MCAST_{ADD,DEL}:783*784* 0 1 2 3 4 5 6 7 octet785* +-----+-----+-----+-----+-----+-----+-----+-----+786* |type |flags| addr |787* +-----+-----+-----+-----+-----+-----+-----+-----+788*789* type: Must be XEN_NETIF_EXTRA_TYPE_MCAST_{ADD,DEL}790* flags: XEN_NETIF_EXTRA_FLAG_*791* addr: address to add/remove792*793* XEN_NETIF_EXTRA_TYPE_HASH:794*795* A backend that supports teoplitz hashing is assumed to accept796* this type of extra info in transmit packets.797* A frontend that enables hashing is assumed to accept798* this type of extra info in receive packets.799*800* 0 1 2 3 4 5 6 7 octet801* +-----+-----+-----+-----+-----+-----+-----+-----+802* |type |flags|htype| alg |LSB ---- value ---- MSB|803* +-----+-----+-----+-----+-----+-----+-----+-----+804*805* type: Must be XEN_NETIF_EXTRA_TYPE_HASH806* flags: XEN_NETIF_EXTRA_FLAG_*807* htype: Hash type (one of _XEN_NETIF_CTRL_HASH_TYPE_* - see above)808* alg: The algorithm used to calculate the hash (one of809* XEN_NETIF_CTRL_HASH_TYPE_ALGORITHM_* - see above)810* value: Hash value811*/812813/* Protocol checksum field is blank in the packet (hardware offload)? */814#define _XEN_NETTXF_csum_blank (0)815#define XEN_NETTXF_csum_blank (1U<<_XEN_NETTXF_csum_blank)816817/* Packet data has been validated against protocol checksum. */818#define _XEN_NETTXF_data_validated (1)819#define XEN_NETTXF_data_validated (1U<<_XEN_NETTXF_data_validated)820821/* Packet continues in the next request descriptor. */822#define _XEN_NETTXF_more_data (2)823#define XEN_NETTXF_more_data (1U<<_XEN_NETTXF_more_data)824825/* Packet to be followed by extra descriptor(s). */826#define _XEN_NETTXF_extra_info (3)827#define XEN_NETTXF_extra_info (1U<<_XEN_NETTXF_extra_info)828829#define XEN_NETIF_MAX_TX_SIZE 0xFFFF830struct xen_netif_tx_request {831grant_ref_t gref;832uint16_t offset;833uint16_t flags;834uint16_t id;835uint16_t size;836};837838/* Types of xen_netif_extra_info descriptors. */839#define XEN_NETIF_EXTRA_TYPE_NONE (0) /* Never used - invalid */840#define XEN_NETIF_EXTRA_TYPE_GSO (1) /* u.gso */841#define XEN_NETIF_EXTRA_TYPE_MCAST_ADD (2) /* u.mcast */842#define XEN_NETIF_EXTRA_TYPE_MCAST_DEL (3) /* u.mcast */843#define XEN_NETIF_EXTRA_TYPE_HASH (4) /* u.hash */844#define XEN_NETIF_EXTRA_TYPE_XDP (5) /* u.xdp */845#define XEN_NETIF_EXTRA_TYPE_MAX (6)846847/* xen_netif_extra_info_t flags. */848#define _XEN_NETIF_EXTRA_FLAG_MORE (0)849#define XEN_NETIF_EXTRA_FLAG_MORE (1U<<_XEN_NETIF_EXTRA_FLAG_MORE)850851/* GSO types */852#define XEN_NETIF_GSO_TYPE_NONE (0)853#define XEN_NETIF_GSO_TYPE_TCPV4 (1)854#define XEN_NETIF_GSO_TYPE_TCPV6 (2)855856/*857* This structure needs to fit within both xen_netif_tx_request_t and858* xen_netif_rx_response_t for compatibility.859*/860struct xen_netif_extra_info {861uint8_t type;862uint8_t flags;863union {864struct {865uint16_t size;866uint8_t type;867uint8_t pad;868uint16_t features;869} gso;870struct {871uint8_t addr[6];872} mcast;873struct {874uint8_t type;875uint8_t algorithm;876uint8_t value[4];877} hash;878struct {879uint16_t headroom;880uint16_t pad[2];881} xdp;882uint16_t pad[3];883} u;884};885886struct xen_netif_tx_response {887uint16_t id;888int16_t status;889};890891struct xen_netif_rx_request {892uint16_t id; /* Echoed in response message. */893uint16_t pad;894grant_ref_t gref;895};896897/* Packet data has been validated against protocol checksum. */898#define _XEN_NETRXF_data_validated (0)899#define XEN_NETRXF_data_validated (1U<<_XEN_NETRXF_data_validated)900901/* Protocol checksum field is blank in the packet (hardware offload)? */902#define _XEN_NETRXF_csum_blank (1)903#define XEN_NETRXF_csum_blank (1U<<_XEN_NETRXF_csum_blank)904905/* Packet continues in the next request descriptor. */906#define _XEN_NETRXF_more_data (2)907#define XEN_NETRXF_more_data (1U<<_XEN_NETRXF_more_data)908909/* Packet to be followed by extra descriptor(s). */910#define _XEN_NETRXF_extra_info (3)911#define XEN_NETRXF_extra_info (1U<<_XEN_NETRXF_extra_info)912913/* Packet has GSO prefix. Deprecated but included for compatibility */914#define _XEN_NETRXF_gso_prefix (4)915#define XEN_NETRXF_gso_prefix (1U<<_XEN_NETRXF_gso_prefix)916917struct xen_netif_rx_response {918uint16_t id;919uint16_t offset;920uint16_t flags;921int16_t status;922};923924/*925* Generate xen_netif ring structures and types.926*/927928DEFINE_RING_TYPES(xen_netif_tx, struct xen_netif_tx_request,929struct xen_netif_tx_response);930DEFINE_RING_TYPES(xen_netif_rx, struct xen_netif_rx_request,931struct xen_netif_rx_response);932933#define XEN_NETIF_RSP_DROPPED -2934#define XEN_NETIF_RSP_ERROR -1935#define XEN_NETIF_RSP_OKAY 0936/* No response: used for auxiliary requests (e.g., xen_netif_extra_info_t). */937#define XEN_NETIF_RSP_NULL 1938939#endif940941942