Back to home page

OSCL-LXR

 
 

    


0001 #ifndef _UAPI_LINUX_VIRTIO_NET_H
0002 #define _UAPI_LINUX_VIRTIO_NET_H
0003 /* This header is BSD licensed so anyone can use the definitions to implement
0004  * compatible drivers/servers.
0005  *
0006  * Redistribution and use in source and binary forms, with or without
0007  * modification, are permitted provided that the following conditions
0008  * are met:
0009  * 1. Redistributions of source code must retain the above copyright
0010  *    notice, this list of conditions and the following disclaimer.
0011  * 2. Redistributions in binary form must reproduce the above copyright
0012  *    notice, this list of conditions and the following disclaimer in the
0013  *    documentation and/or other materials provided with the distribution.
0014  * 3. Neither the name of IBM nor the names of its contributors
0015  *    may be used to endorse or promote products derived from this software
0016  *    without specific prior written permission.
0017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
0018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0020  * ARE DISCLAIMED.  IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
0021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
0022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
0023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
0024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
0025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
0026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
0027  * SUCH DAMAGE. */
0028 #include <linux/types.h>
0029 #include <linux/virtio_ids.h>
0030 #include <linux/virtio_config.h>
0031 #include <linux/virtio_types.h>
0032 #include <linux/if_ether.h>
0033 
0034 /* The feature bitmap for virtio net */
0035 #define VIRTIO_NET_F_CSUM   0   /* Host handles pkts w/ partial csum */
0036 #define VIRTIO_NET_F_GUEST_CSUM 1   /* Guest handles pkts w/ partial csum */
0037 #define VIRTIO_NET_F_CTRL_GUEST_OFFLOADS 2 /* Dynamic offload configuration. */
0038 #define VIRTIO_NET_F_MTU    3   /* Initial MTU advice */
0039 #define VIRTIO_NET_F_MAC    5   /* Host has given MAC address. */
0040 #define VIRTIO_NET_F_GUEST_TSO4 7   /* Guest can handle TSOv4 in. */
0041 #define VIRTIO_NET_F_GUEST_TSO6 8   /* Guest can handle TSOv6 in. */
0042 #define VIRTIO_NET_F_GUEST_ECN  9   /* Guest can handle TSO[6] w/ ECN in. */
0043 #define VIRTIO_NET_F_GUEST_UFO  10  /* Guest can handle UFO in. */
0044 #define VIRTIO_NET_F_HOST_TSO4  11  /* Host can handle TSOv4 in. */
0045 #define VIRTIO_NET_F_HOST_TSO6  12  /* Host can handle TSOv6 in. */
0046 #define VIRTIO_NET_F_HOST_ECN   13  /* Host can handle TSO[6] w/ ECN in. */
0047 #define VIRTIO_NET_F_HOST_UFO   14  /* Host can handle UFO in. */
0048 #define VIRTIO_NET_F_MRG_RXBUF  15  /* Host can merge receive buffers. */
0049 #define VIRTIO_NET_F_STATUS 16  /* virtio_net_config.status available */
0050 #define VIRTIO_NET_F_CTRL_VQ    17  /* Control channel available */
0051 #define VIRTIO_NET_F_CTRL_RX    18  /* Control channel RX mode support */
0052 #define VIRTIO_NET_F_CTRL_VLAN  19  /* Control channel VLAN filtering */
0053 #define VIRTIO_NET_F_CTRL_RX_EXTRA 20   /* Extra RX mode control support */
0054 #define VIRTIO_NET_F_GUEST_ANNOUNCE 21  /* Guest can announce device on the
0055                      * network */
0056 #define VIRTIO_NET_F_MQ 22  /* Device supports Receive Flow
0057                      * Steering */
0058 #define VIRTIO_NET_F_CTRL_MAC_ADDR 23   /* Set MAC address */
0059 #define VIRTIO_NET_F_NOTF_COAL  53  /* Device supports notifications coalescing */
0060 #define VIRTIO_NET_F_HASH_REPORT  57    /* Supports hash report */
0061 #define VIRTIO_NET_F_RSS      60    /* Supports RSS RX steering */
0062 #define VIRTIO_NET_F_RSC_EXT      61    /* extended coalescing info */
0063 #define VIRTIO_NET_F_STANDBY      62    /* Act as standby for another device
0064                      * with the same MAC.
0065                      */
0066 #define VIRTIO_NET_F_SPEED_DUPLEX 63    /* Device set linkspeed and duplex */
0067 
0068 #ifndef VIRTIO_NET_NO_LEGACY
0069 #define VIRTIO_NET_F_GSO    6   /* Host handles pkts w/ any GSO type */
0070 #endif /* VIRTIO_NET_NO_LEGACY */
0071 
0072 #define VIRTIO_NET_S_LINK_UP    1   /* Link is up */
0073 #define VIRTIO_NET_S_ANNOUNCE   2   /* Announcement is needed */
0074 
0075 /* supported/enabled hash types */
0076 #define VIRTIO_NET_RSS_HASH_TYPE_IPv4          (1 << 0)
0077 #define VIRTIO_NET_RSS_HASH_TYPE_TCPv4         (1 << 1)
0078 #define VIRTIO_NET_RSS_HASH_TYPE_UDPv4         (1 << 2)
0079 #define VIRTIO_NET_RSS_HASH_TYPE_IPv6          (1 << 3)
0080 #define VIRTIO_NET_RSS_HASH_TYPE_TCPv6         (1 << 4)
0081 #define VIRTIO_NET_RSS_HASH_TYPE_UDPv6         (1 << 5)
0082 #define VIRTIO_NET_RSS_HASH_TYPE_IP_EX         (1 << 6)
0083 #define VIRTIO_NET_RSS_HASH_TYPE_TCP_EX        (1 << 7)
0084 #define VIRTIO_NET_RSS_HASH_TYPE_UDP_EX        (1 << 8)
0085 
0086 struct virtio_net_config {
0087     /* The config defining mac address (if VIRTIO_NET_F_MAC) */
0088     __u8 mac[ETH_ALEN];
0089     /* See VIRTIO_NET_F_STATUS and VIRTIO_NET_S_* above */
0090     __virtio16 status;
0091     /* Maximum number of each of transmit and receive queues;
0092      * see VIRTIO_NET_F_MQ and VIRTIO_NET_CTRL_MQ.
0093      * Legal values are between 1 and 0x8000
0094      */
0095     __virtio16 max_virtqueue_pairs;
0096     /* Default maximum transmit unit advice */
0097     __virtio16 mtu;
0098     /*
0099      * speed, in units of 1Mb. All values 0 to INT_MAX are legal.
0100      * Any other value stands for unknown.
0101      */
0102     __le32 speed;
0103     /*
0104      * 0x00 - half duplex
0105      * 0x01 - full duplex
0106      * Any other value stands for unknown.
0107      */
0108     __u8 duplex;
0109     /* maximum size of RSS key */
0110     __u8 rss_max_key_size;
0111     /* maximum number of indirection table entries */
0112     __le16 rss_max_indirection_table_length;
0113     /* bitmask of supported VIRTIO_NET_RSS_HASH_ types */
0114     __le32 supported_hash_types;
0115 } __attribute__((packed));
0116 
0117 /*
0118  * This header comes first in the scatter-gather list.  If you don't
0119  * specify GSO or CSUM features, you can simply ignore the header.
0120  *
0121  * This is bitwise-equivalent to the legacy struct virtio_net_hdr_mrg_rxbuf,
0122  * only flattened.
0123  */
0124 struct virtio_net_hdr_v1 {
0125 #define VIRTIO_NET_HDR_F_NEEDS_CSUM 1   /* Use csum_start, csum_offset */
0126 #define VIRTIO_NET_HDR_F_DATA_VALID 2   /* Csum is valid */
0127 #define VIRTIO_NET_HDR_F_RSC_INFO   4   /* rsc info in csum_ fields */
0128     __u8 flags;
0129 #define VIRTIO_NET_HDR_GSO_NONE     0   /* Not a GSO frame */
0130 #define VIRTIO_NET_HDR_GSO_TCPV4    1   /* GSO frame, IPv4 TCP (TSO) */
0131 #define VIRTIO_NET_HDR_GSO_UDP      3   /* GSO frame, IPv4 UDP (UFO) */
0132 #define VIRTIO_NET_HDR_GSO_TCPV6    4   /* GSO frame, IPv6 TCP */
0133 #define VIRTIO_NET_HDR_GSO_ECN      0x80    /* TCP has ECN set */
0134     __u8 gso_type;
0135     __virtio16 hdr_len; /* Ethernet + IP + tcp/udp hdrs */
0136     __virtio16 gso_size;    /* Bytes to append to hdr_len per frame */
0137     union {
0138         struct {
0139             __virtio16 csum_start;
0140             __virtio16 csum_offset;
0141         };
0142         /* Checksum calculation */
0143         struct {
0144             /* Position to start checksumming from */
0145             __virtio16 start;
0146             /* Offset after that to place checksum */
0147             __virtio16 offset;
0148         } csum;
0149         /* Receive Segment Coalescing */
0150         struct {
0151             /* Number of coalesced segments */
0152             __le16 segments;
0153             /* Number of duplicated acks */
0154             __le16 dup_acks;
0155         } rsc;
0156     };
0157     __virtio16 num_buffers; /* Number of merged rx buffers */
0158 };
0159 
0160 struct virtio_net_hdr_v1_hash {
0161     struct virtio_net_hdr_v1 hdr;
0162     __le32 hash_value;
0163 #define VIRTIO_NET_HASH_REPORT_NONE            0
0164 #define VIRTIO_NET_HASH_REPORT_IPv4            1
0165 #define VIRTIO_NET_HASH_REPORT_TCPv4           2
0166 #define VIRTIO_NET_HASH_REPORT_UDPv4           3
0167 #define VIRTIO_NET_HASH_REPORT_IPv6            4
0168 #define VIRTIO_NET_HASH_REPORT_TCPv6           5
0169 #define VIRTIO_NET_HASH_REPORT_UDPv6           6
0170 #define VIRTIO_NET_HASH_REPORT_IPv6_EX         7
0171 #define VIRTIO_NET_HASH_REPORT_TCPv6_EX        8
0172 #define VIRTIO_NET_HASH_REPORT_UDPv6_EX        9
0173     __le16 hash_report;
0174     __le16 padding;
0175 };
0176 
0177 #ifndef VIRTIO_NET_NO_LEGACY
0178 /* This header comes first in the scatter-gather list.
0179  * For legacy virtio, if VIRTIO_F_ANY_LAYOUT is not negotiated, it must
0180  * be the first element of the scatter-gather list.  If you don't
0181  * specify GSO or CSUM features, you can simply ignore the header. */
0182 struct virtio_net_hdr {
0183     /* See VIRTIO_NET_HDR_F_* */
0184     __u8 flags;
0185     /* See VIRTIO_NET_HDR_GSO_* */
0186     __u8 gso_type;
0187     __virtio16 hdr_len;     /* Ethernet + IP + tcp/udp hdrs */
0188     __virtio16 gso_size;        /* Bytes to append to hdr_len per frame */
0189     __virtio16 csum_start;  /* Position to start checksumming from */
0190     __virtio16 csum_offset; /* Offset after that to place checksum */
0191 };
0192 
0193 /* This is the version of the header to use when the MRG_RXBUF
0194  * feature has been negotiated. */
0195 struct virtio_net_hdr_mrg_rxbuf {
0196     struct virtio_net_hdr hdr;
0197     __virtio16 num_buffers; /* Number of merged rx buffers */
0198 };
0199 #endif /* ...VIRTIO_NET_NO_LEGACY */
0200 
0201 /*
0202  * Control virtqueue data structures
0203  *
0204  * The control virtqueue expects a header in the first sg entry
0205  * and an ack/status response in the last entry.  Data for the
0206  * command goes in between.
0207  */
0208 struct virtio_net_ctrl_hdr {
0209     __u8 class;
0210     __u8 cmd;
0211 } __attribute__((packed));
0212 
0213 typedef __u8 virtio_net_ctrl_ack;
0214 
0215 #define VIRTIO_NET_OK     0
0216 #define VIRTIO_NET_ERR    1
0217 
0218 /*
0219  * Control the RX mode, ie. promisucous, allmulti, etc...
0220  * All commands require an "out" sg entry containing a 1 byte
0221  * state value, zero = disable, non-zero = enable.  Commands
0222  * 0 and 1 are supported with the VIRTIO_NET_F_CTRL_RX feature.
0223  * Commands 2-5 are added with VIRTIO_NET_F_CTRL_RX_EXTRA.
0224  */
0225 #define VIRTIO_NET_CTRL_RX    0
0226  #define VIRTIO_NET_CTRL_RX_PROMISC      0
0227  #define VIRTIO_NET_CTRL_RX_ALLMULTI     1
0228  #define VIRTIO_NET_CTRL_RX_ALLUNI       2
0229  #define VIRTIO_NET_CTRL_RX_NOMULTI      3
0230  #define VIRTIO_NET_CTRL_RX_NOUNI        4
0231  #define VIRTIO_NET_CTRL_RX_NOBCAST      5
0232 
0233 /*
0234  * Control the MAC
0235  *
0236  * The MAC filter table is managed by the hypervisor, the guest should
0237  * assume the size is infinite.  Filtering should be considered
0238  * non-perfect, ie. based on hypervisor resources, the guest may
0239  * received packets from sources not specified in the filter list.
0240  *
0241  * In addition to the class/cmd header, the TABLE_SET command requires
0242  * two out scatterlists.  Each contains a 4 byte count of entries followed
0243  * by a concatenated byte stream of the ETH_ALEN MAC addresses.  The
0244  * first sg list contains unicast addresses, the second is for multicast.
0245  * This functionality is present if the VIRTIO_NET_F_CTRL_RX feature
0246  * is available.
0247  *
0248  * The ADDR_SET command requests one out scatterlist, it contains a
0249  * 6 bytes MAC address. This functionality is present if the
0250  * VIRTIO_NET_F_CTRL_MAC_ADDR feature is available.
0251  */
0252 struct virtio_net_ctrl_mac {
0253     __virtio32 entries;
0254     __u8 macs[][ETH_ALEN];
0255 } __attribute__((packed));
0256 
0257 #define VIRTIO_NET_CTRL_MAC    1
0258  #define VIRTIO_NET_CTRL_MAC_TABLE_SET        0
0259  #define VIRTIO_NET_CTRL_MAC_ADDR_SET         1
0260 
0261 /*
0262  * Control VLAN filtering
0263  *
0264  * The VLAN filter table is controlled via a simple ADD/DEL interface.
0265  * VLAN IDs not added may be filterd by the hypervisor.  Del is the
0266  * opposite of add.  Both commands expect an out entry containing a 2
0267  * byte VLAN ID.  VLAN filterting is available with the
0268  * VIRTIO_NET_F_CTRL_VLAN feature bit.
0269  */
0270 #define VIRTIO_NET_CTRL_VLAN       2
0271  #define VIRTIO_NET_CTRL_VLAN_ADD             0
0272  #define VIRTIO_NET_CTRL_VLAN_DEL             1
0273 
0274 /*
0275  * Control link announce acknowledgement
0276  *
0277  * The command VIRTIO_NET_CTRL_ANNOUNCE_ACK is used to indicate that
0278  * driver has recevied the notification; device would clear the
0279  * VIRTIO_NET_S_ANNOUNCE bit in the status field after it receives
0280  * this command.
0281  */
0282 #define VIRTIO_NET_CTRL_ANNOUNCE       3
0283  #define VIRTIO_NET_CTRL_ANNOUNCE_ACK         0
0284 
0285 /*
0286  * Control Receive Flow Steering
0287  */
0288 #define VIRTIO_NET_CTRL_MQ   4
0289 /*
0290  * The command VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET
0291  * enables Receive Flow Steering, specifying the number of the transmit and
0292  * receive queues that will be used. After the command is consumed and acked by
0293  * the device, the device will not steer new packets on receive virtqueues
0294  * other than specified nor read from transmit virtqueues other than specified.
0295  * Accordingly, driver should not transmit new packets  on virtqueues other than
0296  * specified.
0297  */
0298 struct virtio_net_ctrl_mq {
0299     __virtio16 virtqueue_pairs;
0300 };
0301 
0302  #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET        0
0303  #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MIN        1
0304  #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX        0x8000
0305 
0306 /*
0307  * The command VIRTIO_NET_CTRL_MQ_RSS_CONFIG has the same effect as
0308  * VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET does and additionally configures
0309  * the receive steering to use a hash calculated for incoming packet
0310  * to decide on receive virtqueue to place the packet. The command
0311  * also provides parameters to calculate a hash and receive virtqueue.
0312  */
0313 struct virtio_net_rss_config {
0314     __le32 hash_types;
0315     __le16 indirection_table_mask;
0316     __le16 unclassified_queue;
0317     __le16 indirection_table[1/* + indirection_table_mask */];
0318     __le16 max_tx_vq;
0319     __u8 hash_key_length;
0320     __u8 hash_key_data[/* hash_key_length */];
0321 };
0322 
0323  #define VIRTIO_NET_CTRL_MQ_RSS_CONFIG          1
0324 
0325 /*
0326  * The command VIRTIO_NET_CTRL_MQ_HASH_CONFIG requests the device
0327  * to include in the virtio header of the packet the value of the
0328  * calculated hash and the report type of hash. It also provides
0329  * parameters for hash calculation. The command requires feature
0330  * VIRTIO_NET_F_HASH_REPORT to be negotiated to extend the
0331  * layout of virtio header as defined in virtio_net_hdr_v1_hash.
0332  */
0333 struct virtio_net_hash_config {
0334     __le32 hash_types;
0335     /* for compatibility with virtio_net_rss_config */
0336     __le16 reserved[4];
0337     __u8 hash_key_length;
0338     __u8 hash_key_data[/* hash_key_length */];
0339 };
0340 
0341  #define VIRTIO_NET_CTRL_MQ_HASH_CONFIG         2
0342 
0343 /*
0344  * Control network offloads
0345  *
0346  * Reconfigures the network offloads that Guest can handle.
0347  *
0348  * Available with the VIRTIO_NET_F_CTRL_GUEST_OFFLOADS feature bit.
0349  *
0350  * Command data format matches the feature bit mask exactly.
0351  *
0352  * See VIRTIO_NET_F_GUEST_* for the list of offloads
0353  * that can be enabled/disabled.
0354  */
0355 #define VIRTIO_NET_CTRL_GUEST_OFFLOADS   5
0356 #define VIRTIO_NET_CTRL_GUEST_OFFLOADS_SET        0
0357 
0358 /*
0359  * Control notifications coalescing.
0360  *
0361  * Request the device to change the notifications coalescing parameters.
0362  *
0363  * Available with the VIRTIO_NET_F_NOTF_COAL feature bit.
0364  */
0365 #define VIRTIO_NET_CTRL_NOTF_COAL       6
0366 /*
0367  * Set the tx-usecs/tx-max-packets parameters.
0368  */
0369 struct virtio_net_ctrl_coal_tx {
0370     /* Maximum number of packets to send before a TX notification */
0371     __le32 tx_max_packets;
0372     /* Maximum number of usecs to delay a TX notification */
0373     __le32 tx_usecs;
0374 };
0375 
0376 #define VIRTIO_NET_CTRL_NOTF_COAL_TX_SET        0
0377 
0378 /*
0379  * Set the rx-usecs/rx-max-packets parameters.
0380  */
0381 struct virtio_net_ctrl_coal_rx {
0382     /* Maximum number of packets to receive before a RX notification */
0383     __le32 rx_max_packets;
0384     /* Maximum number of usecs to delay a RX notification */
0385     __le32 rx_usecs;
0386 };
0387 
0388 #define VIRTIO_NET_CTRL_NOTF_COAL_RX_SET        1
0389 
0390 #endif /* _UAPI_LINUX_VIRTIO_NET_H */