Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: MIT */
0002 /******************************************************************************
0003  * xen_netif.h
0004  *
0005  * Unified network-device I/O interface for Xen guest OSes.
0006  *
0007  * Copyright (c) 2003-2004, Keir Fraser
0008  */
0009 
0010 #ifndef __XEN_PUBLIC_IO_XEN_NETIF_H__
0011 #define __XEN_PUBLIC_IO_XEN_NETIF_H__
0012 
0013 #include "ring.h"
0014 #include "../grant_table.h"
0015 
0016 /*
0017  * Older implementation of Xen network frontend / backend has an
0018  * implicit dependency on the MAX_SKB_FRAGS as the maximum number of
0019  * ring slots a skb can use. Netfront / netback may not work as
0020  * expected when frontend and backend have different MAX_SKB_FRAGS.
0021  *
0022  * A better approach is to add mechanism for netfront / netback to
0023  * negotiate this value. However we cannot fix all possible
0024  * frontends, so we need to define a value which states the minimum
0025  * slots backend must support.
0026  *
0027  * The minimum value derives from older Linux kernel's MAX_SKB_FRAGS
0028  * (18), which is proved to work with most frontends. Any new backend
0029  * which doesn't negotiate with frontend should expect frontend to
0030  * send a valid packet using slots up to this value.
0031  */
0032 #define XEN_NETIF_NR_SLOTS_MIN 18
0033 
0034 /*
0035  * Notifications after enqueuing any type of message should be conditional on
0036  * the appropriate req_event or rsp_event field in the shared ring.
0037  * If the client sends notification for rx requests then it should specify
0038  * feature 'feature-rx-notify' via xenbus. Otherwise the backend will assume
0039  * that it cannot safely queue packets (as it may not be kicked to send them).
0040  */
0041 
0042 /*
0043  * "feature-split-event-channels" is introduced to separate guest TX
0044  * and RX notification. Backend either doesn't support this feature or
0045  * advertises it via xenstore as 0 (disabled) or 1 (enabled).
0046  *
0047  * To make use of this feature, frontend should allocate two event
0048  * channels for TX and RX, advertise them to backend as
0049  * "event-channel-tx" and "event-channel-rx" respectively. If frontend
0050  * doesn't want to use this feature, it just writes "event-channel"
0051  * node as before.
0052  */
0053 
0054 /*
0055  * Multiple transmit and receive queues:
0056  * If supported, the backend will write the key "multi-queue-max-queues" to
0057  * the directory for that vif, and set its value to the maximum supported
0058  * number of queues.
0059  * Frontends that are aware of this feature and wish to use it can write the
0060  * key "multi-queue-num-queues", set to the number they wish to use, which
0061  * must be greater than zero, and no more than the value reported by the backend
0062  * in "multi-queue-max-queues".
0063  *
0064  * Queues replicate the shared rings and event channels.
0065  * "feature-split-event-channels" may optionally be used when using
0066  * multiple queues, but is not mandatory.
0067  *
0068  * Each queue consists of one shared ring pair, i.e. there must be the same
0069  * number of tx and rx rings.
0070  *
0071  * For frontends requesting just one queue, the usual event-channel and
0072  * ring-ref keys are written as before, simplifying the backend processing
0073  * to avoid distinguishing between a frontend that doesn't understand the
0074  * multi-queue feature, and one that does, but requested only one queue.
0075  *
0076  * Frontends requesting two or more queues must not write the toplevel
0077  * event-channel (or event-channel-{tx,rx}) and {tx,rx}-ring-ref keys,
0078  * instead writing those keys under sub-keys having the name "queue-N" where
0079  * N is the integer ID of the queue for which those keys belong. Queues
0080  * are indexed from zero. For example, a frontend with two queues and split
0081  * event channels must write the following set of queue-related keys:
0082  *
0083  * /local/domain/1/device/vif/0/multi-queue-num-queues = "2"
0084  * /local/domain/1/device/vif/0/queue-0 = ""
0085  * /local/domain/1/device/vif/0/queue-0/tx-ring-ref = "<ring-ref-tx0>"
0086  * /local/domain/1/device/vif/0/queue-0/rx-ring-ref = "<ring-ref-rx0>"
0087  * /local/domain/1/device/vif/0/queue-0/event-channel-tx = "<evtchn-tx0>"
0088  * /local/domain/1/device/vif/0/queue-0/event-channel-rx = "<evtchn-rx0>"
0089  * /local/domain/1/device/vif/0/queue-1 = ""
0090  * /local/domain/1/device/vif/0/queue-1/tx-ring-ref = "<ring-ref-tx1>"
0091  * /local/domain/1/device/vif/0/queue-1/rx-ring-ref = "<ring-ref-rx1"
0092  * /local/domain/1/device/vif/0/queue-1/event-channel-tx = "<evtchn-tx1>"
0093  * /local/domain/1/device/vif/0/queue-1/event-channel-rx = "<evtchn-rx1>"
0094  *
0095  * If there is any inconsistency in the XenStore data, the backend may
0096  * choose not to connect any queues, instead treating the request as an
0097  * error. This includes scenarios where more (or fewer) queues were
0098  * requested than the frontend provided details for.
0099  *
0100  * Mapping of packets to queues is considered to be a function of the
0101  * transmitting system (backend or frontend) and is not negotiated
0102  * between the two. Guests are free to transmit packets on any queue
0103  * they choose, provided it has been set up correctly. Guests must be
0104  * prepared to receive packets on any queue they have requested be set up.
0105  */
0106 
0107 /*
0108  * "feature-no-csum-offload" should be used to turn IPv4 TCP/UDP checksum
0109  * offload off or on. If it is missing then the feature is assumed to be on.
0110  * "feature-ipv6-csum-offload" should be used to turn IPv6 TCP/UDP checksum
0111  * offload on or off. If it is missing then the feature is assumed to be off.
0112  */
0113 
0114 /*
0115  * "feature-gso-tcpv4" and "feature-gso-tcpv6" advertise the capability to
0116  * handle large TCP packets (in IPv4 or IPv6 form respectively). Neither
0117  * frontends nor backends are assumed to be capable unless the flags are
0118  * present.
0119  */
0120 
0121 /*
0122  * "feature-multicast-control" and "feature-dynamic-multicast-control"
0123  * advertise the capability to filter ethernet multicast packets in the
0124  * backend. If the frontend wishes to take advantage of this feature then
0125  * it may set "request-multicast-control". If the backend only advertises
0126  * "feature-multicast-control" then "request-multicast-control" must be set
0127  * before the frontend moves into the connected state. The backend will
0128  * sample the value on this state transition and any subsequent change in
0129  * value will have no effect. However, if the backend also advertises
0130  * "feature-dynamic-multicast-control" then "request-multicast-control"
0131  * may be set by the frontend at any time. In this case, the backend will
0132  * watch the value and re-sample on watch events.
0133  *
0134  * If the sampled value of "request-multicast-control" is set then the
0135  * backend transmit side should no longer flood multicast packets to the
0136  * frontend, it should instead drop any multicast packet that does not
0137  * match in a filter list.
0138  * The list is amended by the frontend by sending dummy transmit requests
0139  * containing XEN_NETIF_EXTRA_TYPE_MCAST_{ADD,DEL} extra-info fragments as
0140  * specified below.
0141  * Note that the filter list may be amended even if the sampled value of
0142  * "request-multicast-control" is not set, however the filter should only
0143  * be applied if it is set.
0144  */
0145 
0146 /*
0147  * "xdp-headroom" is used to request that extra space is added
0148  * for XDP processing.  The value is measured in bytes and passed by
0149  * the frontend to be consistent between both ends.
0150  * If the value is greater than zero that means that
0151  * an RX response is going to be passed to an XDP program for processing.
0152  * XEN_NETIF_MAX_XDP_HEADROOM defines the maximum headroom offset in bytes
0153  *
0154  * "feature-xdp-headroom" is set to "1" by the netback side like other features
0155  * so a guest can check if an XDP program can be processed.
0156  */
0157 #define XEN_NETIF_MAX_XDP_HEADROOM 0x7FFF
0158 
0159 /*
0160  * Control ring
0161  * ============
0162  *
0163  * Some features, such as hashing (detailed below), require a
0164  * significant amount of out-of-band data to be passed from frontend to
0165  * backend. Use of xenstore is not suitable for large quantities of data
0166  * because of quota limitations and so a dedicated 'control ring' is used.
0167  * The ability of the backend to use a control ring is advertised by
0168  * setting:
0169  *
0170  * /local/domain/X/backend/<domid>/<vif>/feature-ctrl-ring = "1"
0171  *
0172  * The frontend provides a control ring to the backend by setting:
0173  *
0174  * /local/domain/<domid>/device/vif/<vif>/ctrl-ring-ref = <gref>
0175  * /local/domain/<domid>/device/vif/<vif>/event-channel-ctrl = <port>
0176  *
0177  * where <gref> is the grant reference of the shared page used to
0178  * implement the control ring and <port> is an event channel to be used
0179  * as a mailbox interrupt. These keys must be set before the frontend
0180  * moves into the connected state.
0181  *
0182  * The control ring uses a fixed request/response message size and is
0183  * balanced (i.e. one request to one response), so operationally it is much
0184  * the same as a transmit or receive ring.
0185  * Note that there is no requirement that responses are issued in the same
0186  * order as requests.
0187  */
0188 
0189 /*
0190  * Hash types
0191  * ==========
0192  *
0193  * For the purposes of the definitions below, 'Packet[]' is an array of
0194  * octets containing an IP packet without options, 'Array[X..Y]' means a
0195  * sub-array of 'Array' containing bytes X thru Y inclusive, and '+' is
0196  * used to indicate concatenation of arrays.
0197  */
0198 
0199 /*
0200  * A hash calculated over an IP version 4 header as follows:
0201  *
0202  * Buffer[0..8] = Packet[12..15] (source address) +
0203  *                Packet[16..19] (destination address)
0204  *
0205  * Result = Hash(Buffer, 8)
0206  */
0207 #define _XEN_NETIF_CTRL_HASH_TYPE_IPV4 0
0208 #define XEN_NETIF_CTRL_HASH_TYPE_IPV4 \
0209     (1 << _XEN_NETIF_CTRL_HASH_TYPE_IPV4)
0210 
0211 /*
0212  * A hash calculated over an IP version 4 header and TCP header as
0213  * follows:
0214  *
0215  * Buffer[0..12] = Packet[12..15] (source address) +
0216  *                 Packet[16..19] (destination address) +
0217  *                 Packet[20..21] (source port) +
0218  *                 Packet[22..23] (destination port)
0219  *
0220  * Result = Hash(Buffer, 12)
0221  */
0222 #define _XEN_NETIF_CTRL_HASH_TYPE_IPV4_TCP 1
0223 #define XEN_NETIF_CTRL_HASH_TYPE_IPV4_TCP \
0224     (1 << _XEN_NETIF_CTRL_HASH_TYPE_IPV4_TCP)
0225 
0226 /*
0227  * A hash calculated over an IP version 6 header as follows:
0228  *
0229  * Buffer[0..32] = Packet[8..23]  (source address ) +
0230  *                 Packet[24..39] (destination address)
0231  *
0232  * Result = Hash(Buffer, 32)
0233  */
0234 #define _XEN_NETIF_CTRL_HASH_TYPE_IPV6 2
0235 #define XEN_NETIF_CTRL_HASH_TYPE_IPV6 \
0236     (1 << _XEN_NETIF_CTRL_HASH_TYPE_IPV6)
0237 
0238 /*
0239  * A hash calculated over an IP version 6 header and TCP header as
0240  * follows:
0241  *
0242  * Buffer[0..36] = Packet[8..23]  (source address) +
0243  *                 Packet[24..39] (destination address) +
0244  *                 Packet[40..41] (source port) +
0245  *                 Packet[42..43] (destination port)
0246  *
0247  * Result = Hash(Buffer, 36)
0248  */
0249 #define _XEN_NETIF_CTRL_HASH_TYPE_IPV6_TCP 3
0250 #define XEN_NETIF_CTRL_HASH_TYPE_IPV6_TCP \
0251     (1 << _XEN_NETIF_CTRL_HASH_TYPE_IPV6_TCP)
0252 
0253 /*
0254  * Hash algorithms
0255  * ===============
0256  */
0257 
0258 #define XEN_NETIF_CTRL_HASH_ALGORITHM_NONE 0
0259 
0260 /*
0261  * Toeplitz hash:
0262  */
0263 
0264 #define XEN_NETIF_CTRL_HASH_ALGORITHM_TOEPLITZ 1
0265 
0266 /*
0267  * This algorithm uses a 'key' as well as the data buffer itself.
0268  * (Buffer[] and Key[] are treated as shift-registers where the MSB of
0269  * Buffer/Key[0] is considered 'left-most' and the LSB of Buffer/Key[N-1]
0270  * is the 'right-most').
0271  *
0272  * Value = 0
0273  * For number of bits in Buffer[]
0274  *    If (left-most bit of Buffer[] is 1)
0275  *        Value ^= left-most 32 bits of Key[]
0276  *    Key[] << 1
0277  *    Buffer[] << 1
0278  *
0279  * The code below is provided for convenience where an operating system
0280  * does not already provide an implementation.
0281  */
0282 #ifdef XEN_NETIF_DEFINE_TOEPLITZ
0283 static uint32_t xen_netif_toeplitz_hash(const uint8_t *key,
0284                     unsigned int keylen,
0285                     const uint8_t *buf, unsigned int buflen)
0286 {
0287     unsigned int keyi, bufi;
0288     uint64_t prefix = 0;
0289     uint64_t hash = 0;
0290 
0291     /* Pre-load prefix with the first 8 bytes of the key */
0292     for (keyi = 0; keyi < 8; keyi++) {
0293         prefix <<= 8;
0294         prefix |= (keyi < keylen) ? key[keyi] : 0;
0295     }
0296 
0297     for (bufi = 0; bufi < buflen; bufi++) {
0298         uint8_t byte = buf[bufi];
0299         unsigned int bit;
0300 
0301         for (bit = 0; bit < 8; bit++) {
0302             if (byte & 0x80)
0303                 hash ^= prefix;
0304             prefix <<= 1;
0305             byte <<= 1;
0306         }
0307 
0308         /*
0309          * 'prefix' has now been left-shifted by 8, so
0310          * OR in the next byte.
0311          */
0312         prefix |= (keyi < keylen) ? key[keyi] : 0;
0313         keyi++;
0314     }
0315 
0316     /* The valid part of the hash is in the upper 32 bits. */
0317     return hash >> 32;
0318 }
0319 #endif              /* XEN_NETIF_DEFINE_TOEPLITZ */
0320 
0321 /*
0322  * Control requests (struct xen_netif_ctrl_request)
0323  * ================================================
0324  *
0325  * All requests have the following format:
0326  *
0327  *    0     1     2     3     4     5     6     7  octet
0328  * +-----+-----+-----+-----+-----+-----+-----+-----+
0329  * |    id     |   type    |         data[0]       |
0330  * +-----+-----+-----+-----+-----+-----+-----+-----+
0331  * |         data[1]       |         data[2]       |
0332  * +-----+-----+-----+-----+-----------------------+
0333  *
0334  * id: the request identifier, echoed in response.
0335  * type: the type of request (see below)
0336  * data[]: any data associated with the request (determined by type)
0337  */
0338 
0339 struct xen_netif_ctrl_request {
0340     uint16_t id;
0341     uint16_t type;
0342 
0343 #define XEN_NETIF_CTRL_TYPE_INVALID               0
0344 #define XEN_NETIF_CTRL_TYPE_GET_HASH_FLAGS        1
0345 #define XEN_NETIF_CTRL_TYPE_SET_HASH_FLAGS        2
0346 #define XEN_NETIF_CTRL_TYPE_SET_HASH_KEY          3
0347 #define XEN_NETIF_CTRL_TYPE_GET_HASH_MAPPING_SIZE 4
0348 #define XEN_NETIF_CTRL_TYPE_SET_HASH_MAPPING_SIZE 5
0349 #define XEN_NETIF_CTRL_TYPE_SET_HASH_MAPPING      6
0350 #define XEN_NETIF_CTRL_TYPE_SET_HASH_ALGORITHM    7
0351 
0352     uint32_t data[3];
0353 };
0354 
0355 /*
0356  * Control responses (struct xen_netif_ctrl_response)
0357  * ==================================================
0358  *
0359  * All responses have the following format:
0360  *
0361  *    0     1     2     3     4     5     6     7  octet
0362  * +-----+-----+-----+-----+-----+-----+-----+-----+
0363  * |    id     |   type    |         status        |
0364  * +-----+-----+-----+-----+-----+-----+-----+-----+
0365  * |         data          |
0366  * +-----+-----+-----+-----+
0367  *
0368  * id: the corresponding request identifier
0369  * type: the type of the corresponding request
0370  * status: the status of request processing
0371  * data: any data associated with the response (determined by type and
0372  *       status)
0373  */
0374 
0375 struct xen_netif_ctrl_response {
0376     uint16_t id;
0377     uint16_t type;
0378     uint32_t status;
0379 
0380 #define XEN_NETIF_CTRL_STATUS_SUCCESS           0
0381 #define XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED     1
0382 #define XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER 2
0383 #define XEN_NETIF_CTRL_STATUS_BUFFER_OVERFLOW   3
0384 
0385     uint32_t data;
0386 };
0387 
0388 /*
0389  * Control messages
0390  * ================
0391  *
0392  * XEN_NETIF_CTRL_TYPE_SET_HASH_ALGORITHM
0393  * --------------------------------------
0394  *
0395  * This is sent by the frontend to set the desired hash algorithm.
0396  *
0397  * Request:
0398  *
0399  *  type    = XEN_NETIF_CTRL_TYPE_SET_HASH_ALGORITHM
0400  *  data[0] = a XEN_NETIF_CTRL_HASH_ALGORITHM_* value
0401  *  data[1] = 0
0402  *  data[2] = 0
0403  *
0404  * Response:
0405  *
0406  *  status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED     - Operation not
0407  *                                                     supported
0408  *           XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER - The algorithm is not
0409  *                                                     supported
0410  *           XEN_NETIF_CTRL_STATUS_SUCCESS           - Operation successful
0411  *
0412  * NOTE: Setting data[0] to XEN_NETIF_CTRL_HASH_ALGORITHM_NONE disables
0413  *       hashing and the backend is free to choose how it steers packets
0414  *       to queues (which is the default behaviour).
0415  *
0416  * XEN_NETIF_CTRL_TYPE_GET_HASH_FLAGS
0417  * ----------------------------------
0418  *
0419  * This is sent by the frontend to query the types of hash supported by
0420  * the backend.
0421  *
0422  * Request:
0423  *
0424  *  type    = XEN_NETIF_CTRL_TYPE_GET_HASH_FLAGS
0425  *  data[0] = 0
0426  *  data[1] = 0
0427  *  data[2] = 0
0428  *
0429  * Response:
0430  *
0431  *  status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED - Operation not supported
0432  *           XEN_NETIF_CTRL_STATUS_SUCCESS       - Operation successful
0433  *  data   = supported hash types (if operation was successful)
0434  *
0435  * NOTE: A valid hash algorithm must be selected before this operation can
0436  *       succeed.
0437  *
0438  * XEN_NETIF_CTRL_TYPE_SET_HASH_FLAGS
0439  * ----------------------------------
0440  *
0441  * This is sent by the frontend to set the types of hash that the backend
0442  * should calculate. (See above for hash type definitions).
0443  * Note that the 'maximal' type of hash should always be chosen. For
0444  * example, if the frontend sets both IPV4 and IPV4_TCP hash types then
0445  * the latter hash type should be calculated for any TCP packet and the
0446  * former only calculated for non-TCP packets.
0447  *
0448  * Request:
0449  *
0450  *  type    = XEN_NETIF_CTRL_TYPE_SET_HASH_FLAGS
0451  *  data[0] = bitwise OR of XEN_NETIF_CTRL_HASH_TYPE_* values
0452  *  data[1] = 0
0453  *  data[2] = 0
0454  *
0455  * Response:
0456  *
0457  *  status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED     - Operation not
0458  *                                                     supported
0459  *           XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER - One or more flag
0460  *                                                     value is invalid or
0461  *                                                     unsupported
0462  *           XEN_NETIF_CTRL_STATUS_SUCCESS           - Operation successful
0463  *  data   = 0
0464  *
0465  * NOTE: A valid hash algorithm must be selected before this operation can
0466  *       succeed.
0467  *       Also, setting data[0] to zero disables hashing and the backend
0468  *       is free to choose how it steers packets to queues.
0469  *
0470  * XEN_NETIF_CTRL_TYPE_SET_HASH_KEY
0471  * --------------------------------
0472  *
0473  * This is sent by the frontend to set the key of the hash if the algorithm
0474  * requires it. (See hash algorithms above).
0475  *
0476  * Request:
0477  *
0478  *  type    = XEN_NETIF_CTRL_TYPE_SET_HASH_KEY
0479  *  data[0] = grant reference of page containing the key (assumed to
0480  *            start at beginning of grant)
0481  *  data[1] = size of key in octets
0482  *  data[2] = 0
0483  *
0484  * Response:
0485  *
0486  *  status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED     - Operation not
0487  *                                                     supported
0488  *           XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER - Key size is invalid
0489  *           XEN_NETIF_CTRL_STATUS_BUFFER_OVERFLOW   - Key size is larger
0490  *                                                     than the backend
0491  *                                                     supports
0492  *           XEN_NETIF_CTRL_STATUS_SUCCESS           - Operation successful
0493  *  data   = 0
0494  *
0495  * NOTE: Any key octets not specified are assumed to be zero (the key
0496  *       is assumed to be empty by default) and specifying a new key
0497  *       invalidates any previous key, hence specifying a key size of
0498  *       zero will clear the key (which ensures that the calculated hash
0499  *       will always be zero).
0500  *       The maximum size of key is algorithm and backend specific, but
0501  *       is also limited by the single grant reference.
0502  *       The grant reference may be read-only and must remain valid until
0503  *       the response has been processed.
0504  *
0505  * XEN_NETIF_CTRL_TYPE_GET_HASH_MAPPING_SIZE
0506  * -----------------------------------------
0507  *
0508  * This is sent by the frontend to query the maximum size of mapping
0509  * table supported by the backend. The size is specified in terms of
0510  * table entries.
0511  *
0512  * Request:
0513  *
0514  *  type    = XEN_NETIF_CTRL_TYPE_GET_HASH_MAPPING_SIZE
0515  *  data[0] = 0
0516  *  data[1] = 0
0517  *  data[2] = 0
0518  *
0519  * Response:
0520  *
0521  *  status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED - Operation not supported
0522  *           XEN_NETIF_CTRL_STATUS_SUCCESS       - Operation successful
0523  *  data   = maximum number of entries allowed in the mapping table
0524  *           (if operation was successful) or zero if a mapping table is
0525  *           not supported (i.e. hash mapping is done only by modular
0526  *           arithmetic).
0527  *
0528  * XEN_NETIF_CTRL_TYPE_SET_HASH_MAPPING_SIZE
0529  * -------------------------------------
0530  *
0531  * This is sent by the frontend to set the actual size of the mapping
0532  * table to be used by the backend. The size is specified in terms of
0533  * table entries.
0534  * Any previous table is invalidated by this message and any new table
0535  * is assumed to be zero filled.
0536  *
0537  * Request:
0538  *
0539  *  type    = XEN_NETIF_CTRL_TYPE_SET_HASH_MAPPING_SIZE
0540  *  data[0] = number of entries in mapping table
0541  *  data[1] = 0
0542  *  data[2] = 0
0543  *
0544  * Response:
0545  *
0546  *  status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED     - Operation not
0547  *                                                     supported
0548  *           XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER - Table size is invalid
0549  *           XEN_NETIF_CTRL_STATUS_SUCCESS           - Operation successful
0550  *  data   = 0
0551  *
0552  * NOTE: Setting data[0] to 0 means that hash mapping should be done
0553  *       using modular arithmetic.
0554  *
0555  * XEN_NETIF_CTRL_TYPE_SET_HASH_MAPPING
0556  * ------------------------------------
0557  *
0558  * This is sent by the frontend to set the content of the table mapping
0559  * hash value to queue number. The backend should calculate the hash from
0560  * the packet header, use it as an index into the table (modulo the size
0561  * of the table) and then steer the packet to the queue number found at
0562  * that index.
0563  *
0564  * Request:
0565  *
0566  *  type    = XEN_NETIF_CTRL_TYPE_SET_HASH_MAPPING
0567  *  data[0] = grant reference of page containing the mapping (sub-)table
0568  *            (assumed to start at beginning of grant)
0569  *  data[1] = size of (sub-)table in entries
0570  *  data[2] = offset, in entries, of sub-table within overall table
0571  *
0572  * Response:
0573  *
0574  *  status = XEN_NETIF_CTRL_STATUS_NOT_SUPPORTED     - Operation not
0575  *                                                     supported
0576  *           XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER - Table size or content
0577  *                                                     is invalid
0578  *           XEN_NETIF_CTRL_STATUS_BUFFER_OVERFLOW   - Table size is larger
0579  *                                                     than the backend
0580  *                                                     supports
0581  *           XEN_NETIF_CTRL_STATUS_SUCCESS           - Operation successful
0582  *  data   = 0
0583  *
0584  * NOTE: The overall table has the following format:
0585  *
0586  *          0     1     2     3     4     5     6     7  octet
0587  *       +-----+-----+-----+-----+-----+-----+-----+-----+
0588  *       |       mapping[0]      |       mapping[1]      |
0589  *       +-----+-----+-----+-----+-----+-----+-----+-----+
0590  *       |                       .                       |
0591  *       |                       .                       |
0592  *       |                       .                       |
0593  *       +-----+-----+-----+-----+-----+-----+-----+-----+
0594  *       |      mapping[N-2]     |      mapping[N-1]     |
0595  *       +-----+-----+-----+-----+-----+-----+-----+-----+
0596  *
0597  *       where N is specified by a XEN_NETIF_CTRL_TYPE_SET_HASH_MAPPING_SIZE
0598  *       message and each  mapping must specifies a queue between 0 and
0599  *       "multi-queue-num-queues" (see above).
0600  *       The backend may support a mapping table larger than can be
0601  *       mapped by a single grant reference. Thus sub-tables within a
0602  *       larger table can be individually set by sending multiple messages
0603  *       with differing offset values. Specifying a new sub-table does not
0604  *       invalidate any table data outside that range.
0605  *       The grant reference may be read-only and must remain valid until
0606  *       the response has been processed.
0607  */
0608 
0609 DEFINE_RING_TYPES(xen_netif_ctrl,
0610           struct xen_netif_ctrl_request,
0611           struct xen_netif_ctrl_response);
0612 
0613 /*
0614  * Guest transmit
0615  * ==============
0616  *
0617  * This is the 'wire' format for transmit (frontend -> backend) packets:
0618  *
0619  *  Fragment 1: xen_netif_tx_request_t  - flags = XEN_NETTXF_*
0620  *                                    size = total packet size
0621  * [Extra 1: xen_netif_extra_info_t]    - (only if fragment 1 flags include
0622  *                                     XEN_NETTXF_extra_info)
0623  *  ...
0624  * [Extra N: xen_netif_extra_info_t]    - (only if extra N-1 flags include
0625  *                                     XEN_NETIF_EXTRA_MORE)
0626  *  ...
0627  *  Fragment N: xen_netif_tx_request_t  - (only if fragment N-1 flags include
0628  *                                     XEN_NETTXF_more_data - flags on preceding
0629  *                                     extras are not relevant here)
0630  *                                    flags = 0
0631  *                                    size = fragment size
0632  *
0633  * NOTE:
0634  *
0635  * This format slightly is different from that used for receive
0636  * (backend -> frontend) packets. Specifically, in a multi-fragment
0637  * packet the actual size of fragment 1 can only be determined by
0638  * subtracting the sizes of fragments 2..N from the total packet size.
0639  *
0640  * Ring slot size is 12 octets, however not all request/response
0641  * structs use the full size.
0642  *
0643  * tx request data (xen_netif_tx_request_t)
0644  * ------------------------------------
0645  *
0646  *    0     1     2     3     4     5     6     7  octet
0647  * +-----+-----+-----+-----+-----+-----+-----+-----+
0648  * | grant ref             | offset    | flags     |
0649  * +-----+-----+-----+-----+-----+-----+-----+-----+
0650  * | id        | size      |
0651  * +-----+-----+-----+-----+
0652  *
0653  * grant ref: Reference to buffer page.
0654  * offset: Offset within buffer page.
0655  * flags: XEN_NETTXF_*.
0656  * id: request identifier, echoed in response.
0657  * size: packet size in bytes.
0658  *
0659  * tx response (xen_netif_tx_response_t)
0660  * ---------------------------------
0661  *
0662  *    0     1     2     3     4     5     6     7  octet
0663  * +-----+-----+-----+-----+-----+-----+-----+-----+
0664  * | id        | status    | unused                |
0665  * +-----+-----+-----+-----+-----+-----+-----+-----+
0666  * | unused                |
0667  * +-----+-----+-----+-----+
0668  *
0669  * id: reflects id in transmit request
0670  * status: XEN_NETIF_RSP_*
0671  *
0672  * Guest receive
0673  * =============
0674  *
0675  * This is the 'wire' format for receive (backend -> frontend) packets:
0676  *
0677  *  Fragment 1: xen_netif_rx_request_t  - flags = XEN_NETRXF_*
0678  *                                    size = fragment size
0679  * [Extra 1: xen_netif_extra_info_t]    - (only if fragment 1 flags include
0680  *                                     XEN_NETRXF_extra_info)
0681  *  ...
0682  * [Extra N: xen_netif_extra_info_t]    - (only if extra N-1 flags include
0683  *                                     XEN_NETIF_EXTRA_MORE)
0684  *  ...
0685  *  Fragment N: xen_netif_rx_request_t  - (only if fragment N-1 flags include
0686  *                                     XEN_NETRXF_more_data - flags on preceding
0687  *                                     extras are not relevant here)
0688  *                                    flags = 0
0689  *                                    size = fragment size
0690  *
0691  * NOTE:
0692  *
0693  * This format slightly is different from that used for transmit
0694  * (frontend -> backend) packets. Specifically, in a multi-fragment
0695  * packet the size of the packet can only be determined by summing the
0696  * sizes of fragments 1..N.
0697  *
0698  * Ring slot size is 8 octets.
0699  *
0700  * rx request (xen_netif_rx_request_t)
0701  * -------------------------------
0702  *
0703  *    0     1     2     3     4     5     6     7  octet
0704  * +-----+-----+-----+-----+-----+-----+-----+-----+
0705  * | id        | pad       | gref                  |
0706  * +-----+-----+-----+-----+-----+-----+-----+-----+
0707  *
0708  * id: request identifier, echoed in response.
0709  * gref: reference to incoming granted frame.
0710  *
0711  * rx response (xen_netif_rx_response_t)
0712  * ---------------------------------
0713  *
0714  *    0     1     2     3     4     5     6     7  octet
0715  * +-----+-----+-----+-----+-----+-----+-----+-----+
0716  * | id        | offset    | flags     | status    |
0717  * +-----+-----+-----+-----+-----+-----+-----+-----+
0718  *
0719  * id: reflects id in receive request
0720  * offset: offset in page of start of received packet
0721  * flags: XEN_NETRXF_*
0722  * status: -ve: XEN_NETIF_RSP_*; +ve: Rx'ed pkt size.
0723  *
0724  * NOTE: Historically, to support GSO on the frontend receive side, Linux
0725  *       netfront does not make use of the rx response id (because, as
0726  *       described below, extra info structures overlay the id field).
0727  *       Instead it assumes that responses always appear in the same ring
0728  *       slot as their corresponding request. Thus, to maintain
0729  *       compatibility, backends must make sure this is the case.
0730  *
0731  * Extra Info
0732  * ==========
0733  *
0734  * Can be present if initial request or response has NET{T,R}XF_extra_info,
0735  * or previous extra request has XEN_NETIF_EXTRA_MORE.
0736  *
0737  * The struct therefore needs to fit into either a tx or rx slot and
0738  * is therefore limited to 8 octets.
0739  *
0740  * NOTE: Because extra info data overlays the usual request/response
0741  *       structures, there is no id information in the opposite direction.
0742  *       So, if an extra info overlays an rx response the frontend can
0743  *       assume that it is in the same ring slot as the request that was
0744  *       consumed to make the slot available, and the backend must ensure
0745  *       this assumption is true.
0746  *
0747  * extra info (xen_netif_extra_info_t)
0748  * -------------------------------
0749  *
0750  * General format:
0751  *
0752  *    0     1     2     3     4     5     6     7  octet
0753  * +-----+-----+-----+-----+-----+-----+-----+-----+
0754  * |type |flags| type specific data                |
0755  * +-----+-----+-----+-----+-----+-----+-----+-----+
0756  * | padding for tx        |
0757  * +-----+-----+-----+-----+
0758  *
0759  * type: XEN_NETIF_EXTRA_TYPE_*
0760  * flags: XEN_NETIF_EXTRA_FLAG_*
0761  * padding for tx: present only in the tx case due to 8 octet limit
0762  *                 from rx case. Not shown in type specific entries
0763  *                 below.
0764  *
0765  * XEN_NETIF_EXTRA_TYPE_GSO:
0766  *
0767  *    0     1     2     3     4     5     6     7  octet
0768  * +-----+-----+-----+-----+-----+-----+-----+-----+
0769  * |type |flags| size      |type | pad | features  |
0770  * +-----+-----+-----+-----+-----+-----+-----+-----+
0771  *
0772  * type: Must be XEN_NETIF_EXTRA_TYPE_GSO
0773  * flags: XEN_NETIF_EXTRA_FLAG_*
0774  * size: Maximum payload size of each segment. For example,
0775  *       for TCP this is just the path MSS.
0776  * type: XEN_NETIF_GSO_TYPE_*: This determines the protocol of
0777  *       the packet and any extra features required to segment the
0778  *       packet properly.
0779  * features: EN_XEN_NETIF_GSO_FEAT_*: This specifies any extra GSO
0780  *           features required to process this packet, such as ECN
0781  *           support for TCPv4.
0782  *
0783  * XEN_NETIF_EXTRA_TYPE_MCAST_{ADD,DEL}:
0784  *
0785  *    0     1     2     3     4     5     6     7  octet
0786  * +-----+-----+-----+-----+-----+-----+-----+-----+
0787  * |type |flags| addr                              |
0788  * +-----+-----+-----+-----+-----+-----+-----+-----+
0789  *
0790  * type: Must be XEN_NETIF_EXTRA_TYPE_MCAST_{ADD,DEL}
0791  * flags: XEN_NETIF_EXTRA_FLAG_*
0792  * addr: address to add/remove
0793  *
0794  * XEN_NETIF_EXTRA_TYPE_HASH:
0795  *
0796  * A backend that supports teoplitz hashing is assumed to accept
0797  * this type of extra info in transmit packets.
0798  * A frontend that enables hashing is assumed to accept
0799  * this type of extra info in receive packets.
0800  *
0801  *    0     1     2     3     4     5     6     7  octet
0802  * +-----+-----+-----+-----+-----+-----+-----+-----+
0803  * |type |flags|htype| alg |LSB ---- value ---- MSB|
0804  * +-----+-----+-----+-----+-----+-----+-----+-----+
0805  *
0806  * type: Must be XEN_NETIF_EXTRA_TYPE_HASH
0807  * flags: XEN_NETIF_EXTRA_FLAG_*
0808  * htype: Hash type (one of _XEN_NETIF_CTRL_HASH_TYPE_* - see above)
0809  * alg: The algorithm used to calculate the hash (one of
0810  *      XEN_NETIF_CTRL_HASH_TYPE_ALGORITHM_* - see above)
0811  * value: Hash value
0812  */
0813 
0814 /* Protocol checksum field is blank in the packet (hardware offload)? */
0815 #define _XEN_NETTXF_csum_blank     (0)
0816 #define  XEN_NETTXF_csum_blank     (1U<<_XEN_NETTXF_csum_blank)
0817 
0818 /* Packet data has been validated against protocol checksum. */
0819 #define _XEN_NETTXF_data_validated (1)
0820 #define  XEN_NETTXF_data_validated (1U<<_XEN_NETTXF_data_validated)
0821 
0822 /* Packet continues in the next request descriptor. */
0823 #define _XEN_NETTXF_more_data      (2)
0824 #define  XEN_NETTXF_more_data      (1U<<_XEN_NETTXF_more_data)
0825 
0826 /* Packet to be followed by extra descriptor(s). */
0827 #define _XEN_NETTXF_extra_info     (3)
0828 #define  XEN_NETTXF_extra_info     (1U<<_XEN_NETTXF_extra_info)
0829 
0830 #define XEN_NETIF_MAX_TX_SIZE 0xFFFF
0831 struct xen_netif_tx_request {
0832     grant_ref_t gref;
0833     uint16_t offset;
0834     uint16_t flags;
0835     uint16_t id;
0836     uint16_t size;
0837 };
0838 
0839 /* Types of xen_netif_extra_info descriptors. */
0840 #define XEN_NETIF_EXTRA_TYPE_NONE      (0)  /* Never used - invalid */
0841 #define XEN_NETIF_EXTRA_TYPE_GSO       (1)  /* u.gso */
0842 #define XEN_NETIF_EXTRA_TYPE_MCAST_ADD (2)  /* u.mcast */
0843 #define XEN_NETIF_EXTRA_TYPE_MCAST_DEL (3)  /* u.mcast */
0844 #define XEN_NETIF_EXTRA_TYPE_HASH      (4)  /* u.hash */
0845 #define XEN_NETIF_EXTRA_TYPE_XDP       (5)  /* u.xdp */
0846 #define XEN_NETIF_EXTRA_TYPE_MAX       (6)
0847 
0848 /* xen_netif_extra_info_t flags. */
0849 #define _XEN_NETIF_EXTRA_FLAG_MORE (0)
0850 #define XEN_NETIF_EXTRA_FLAG_MORE  (1U<<_XEN_NETIF_EXTRA_FLAG_MORE)
0851 
0852 /* GSO types */
0853 #define XEN_NETIF_GSO_TYPE_NONE         (0)
0854 #define XEN_NETIF_GSO_TYPE_TCPV4        (1)
0855 #define XEN_NETIF_GSO_TYPE_TCPV6        (2)
0856 
0857 /*
0858  * This structure needs to fit within both xen_netif_tx_request_t and
0859  * xen_netif_rx_response_t for compatibility.
0860  */
0861 struct xen_netif_extra_info {
0862     uint8_t type;
0863     uint8_t flags;
0864     union {
0865         struct {
0866             uint16_t size;
0867             uint8_t type;
0868             uint8_t pad;
0869             uint16_t features;
0870         } gso;
0871         struct {
0872             uint8_t addr[6];
0873         } mcast;
0874         struct {
0875             uint8_t type;
0876             uint8_t algorithm;
0877             uint8_t value[4];
0878         } hash;
0879         struct {
0880             uint16_t headroom;
0881             uint16_t pad[2];
0882         } xdp;
0883         uint16_t pad[3];
0884     } u;
0885 };
0886 
0887 struct xen_netif_tx_response {
0888     uint16_t id;
0889     int16_t status;
0890 };
0891 
0892 struct xen_netif_rx_request {
0893     uint16_t id;        /* Echoed in response message.        */
0894     uint16_t pad;
0895     grant_ref_t gref;
0896 };
0897 
0898 /* Packet data has been validated against protocol checksum. */
0899 #define _XEN_NETRXF_data_validated (0)
0900 #define  XEN_NETRXF_data_validated (1U<<_XEN_NETRXF_data_validated)
0901 
0902 /* Protocol checksum field is blank in the packet (hardware offload)? */
0903 #define _XEN_NETRXF_csum_blank     (1)
0904 #define  XEN_NETRXF_csum_blank     (1U<<_XEN_NETRXF_csum_blank)
0905 
0906 /* Packet continues in the next request descriptor. */
0907 #define _XEN_NETRXF_more_data      (2)
0908 #define  XEN_NETRXF_more_data      (1U<<_XEN_NETRXF_more_data)
0909 
0910 /* Packet to be followed by extra descriptor(s). */
0911 #define _XEN_NETRXF_extra_info     (3)
0912 #define  XEN_NETRXF_extra_info     (1U<<_XEN_NETRXF_extra_info)
0913 
0914 /* Packet has GSO prefix. Deprecated but included for compatibility */
0915 #define _XEN_NETRXF_gso_prefix     (4)
0916 #define  XEN_NETRXF_gso_prefix     (1U<<_XEN_NETRXF_gso_prefix)
0917 
0918 struct xen_netif_rx_response {
0919     uint16_t id;
0920     uint16_t offset;
0921     uint16_t flags;
0922     int16_t status;
0923 };
0924 
0925 /*
0926  * Generate xen_netif ring structures and types.
0927  */
0928 
0929 DEFINE_RING_TYPES(xen_netif_tx, struct xen_netif_tx_request,
0930           struct xen_netif_tx_response);
0931 DEFINE_RING_TYPES(xen_netif_rx, struct xen_netif_rx_request,
0932           struct xen_netif_rx_response);
0933 
0934 #define XEN_NETIF_RSP_DROPPED         -2
0935 #define XEN_NETIF_RSP_ERROR           -1
0936 #define XEN_NETIF_RSP_OKAY             0
0937 /* No response: used for auxiliary requests (e.g., xen_netif_extra_info_t). */
0938 #define XEN_NETIF_RSP_NULL             1
0939 
0940 #endif