135e7012eSMaxime Coquelin /* SPDX-License-Identifier: BSD-3-Clause 235e7012eSMaxime Coquelin * Copyright(c) 2010-2015 Intel Corporation 335e7012eSMaxime Coquelin */ 435e7012eSMaxime Coquelin 535e7012eSMaxime Coquelin #ifndef _VIRTIO_CVQ_H_ 635e7012eSMaxime Coquelin #define _VIRTIO_CVQ_H_ 735e7012eSMaxime Coquelin 835e7012eSMaxime Coquelin #include <rte_ether.h> 935e7012eSMaxime Coquelin 104dd3477cSMaxime Coquelin struct virtqueue; 114dd3477cSMaxime Coquelin 1235e7012eSMaxime Coquelin /** 1335e7012eSMaxime Coquelin * Control the RX mode, ie. promiscuous, allmulti, etc... 1435e7012eSMaxime Coquelin * All commands require an "out" sg entry containing a 1 byte 1535e7012eSMaxime Coquelin * state value, zero = disable, non-zero = enable. Commands 1635e7012eSMaxime Coquelin * 0 and 1 are supported with the VIRTIO_NET_F_CTRL_RX feature. 1735e7012eSMaxime Coquelin * Commands 2-5 are added with VIRTIO_NET_F_CTRL_RX_EXTRA. 1835e7012eSMaxime Coquelin */ 1935e7012eSMaxime Coquelin #define VIRTIO_NET_CTRL_RX 0 2035e7012eSMaxime Coquelin #define VIRTIO_NET_CTRL_RX_PROMISC 0 2135e7012eSMaxime Coquelin #define VIRTIO_NET_CTRL_RX_ALLMULTI 1 2235e7012eSMaxime Coquelin #define VIRTIO_NET_CTRL_RX_ALLUNI 2 2335e7012eSMaxime Coquelin #define VIRTIO_NET_CTRL_RX_NOMULTI 3 2435e7012eSMaxime Coquelin #define VIRTIO_NET_CTRL_RX_NOUNI 4 2535e7012eSMaxime Coquelin #define VIRTIO_NET_CTRL_RX_NOBCAST 5 2635e7012eSMaxime Coquelin 2735e7012eSMaxime Coquelin /** 2835e7012eSMaxime Coquelin * Control the MAC 2935e7012eSMaxime Coquelin * 3035e7012eSMaxime Coquelin * The MAC filter table is managed by the hypervisor, the guest should 3135e7012eSMaxime Coquelin * assume the size is infinite. Filtering should be considered 3235e7012eSMaxime Coquelin * non-perfect, ie. based on hypervisor resources, the guest may 3335e7012eSMaxime Coquelin * received packets from sources not specified in the filter list. 3435e7012eSMaxime Coquelin * 3535e7012eSMaxime Coquelin * In addition to the class/cmd header, the TABLE_SET command requires 3635e7012eSMaxime Coquelin * two out scatterlists. Each contains a 4 byte count of entries followed 3735e7012eSMaxime Coquelin * by a concatenated byte stream of the ETH_ALEN MAC addresses. The 3835e7012eSMaxime Coquelin * first sg list contains unicast addresses, the second is for multicast. 3935e7012eSMaxime Coquelin * This functionality is present if the VIRTIO_NET_F_CTRL_RX feature 4035e7012eSMaxime Coquelin * is available. 4135e7012eSMaxime Coquelin * 4235e7012eSMaxime Coquelin * The ADDR_SET command requests one out scatterlist, it contains a 4335e7012eSMaxime Coquelin * 6 bytes MAC address. This functionality is present if the 4435e7012eSMaxime Coquelin * VIRTIO_NET_F_CTRL_MAC_ADDR feature is available. 4535e7012eSMaxime Coquelin */ 46*e7750639SAndre Muezerie struct __rte_packed_begin virtio_net_ctrl_mac { 4735e7012eSMaxime Coquelin uint32_t entries; 4835e7012eSMaxime Coquelin uint8_t macs[][RTE_ETHER_ADDR_LEN]; 49*e7750639SAndre Muezerie } __rte_packed_end; 5035e7012eSMaxime Coquelin 5135e7012eSMaxime Coquelin #define VIRTIO_NET_CTRL_MAC 1 5235e7012eSMaxime Coquelin #define VIRTIO_NET_CTRL_MAC_TABLE_SET 0 5335e7012eSMaxime Coquelin #define VIRTIO_NET_CTRL_MAC_ADDR_SET 1 5435e7012eSMaxime Coquelin 5535e7012eSMaxime Coquelin /** 5635e7012eSMaxime Coquelin * Control VLAN filtering 5735e7012eSMaxime Coquelin * 5835e7012eSMaxime Coquelin * The VLAN filter table is controlled via a simple ADD/DEL interface. 5935e7012eSMaxime Coquelin * VLAN IDs not added may be filtered by the hypervisor. Del is the 6035e7012eSMaxime Coquelin * opposite of add. Both commands expect an out entry containing a 2 6135e7012eSMaxime Coquelin * byte VLAN ID. VLAN filtering is available with the 6235e7012eSMaxime Coquelin * VIRTIO_NET_F_CTRL_VLAN feature bit. 6335e7012eSMaxime Coquelin */ 6435e7012eSMaxime Coquelin #define VIRTIO_NET_CTRL_VLAN 2 6535e7012eSMaxime Coquelin #define VIRTIO_NET_CTRL_VLAN_ADD 0 6635e7012eSMaxime Coquelin #define VIRTIO_NET_CTRL_VLAN_DEL 1 6735e7012eSMaxime Coquelin 6835e7012eSMaxime Coquelin /** 6935e7012eSMaxime Coquelin * RSS control 7035e7012eSMaxime Coquelin * 7135e7012eSMaxime Coquelin * The RSS feature configuration message is sent by the driver when 7235e7012eSMaxime Coquelin * VIRTIO_NET_F_RSS has been negotiated. It provides the device with 7335e7012eSMaxime Coquelin * hash types to use, hash key and indirection table. In this 7435e7012eSMaxime Coquelin * implementation, the driver only supports fixed key length (40B) 7535e7012eSMaxime Coquelin * and indirection table size (128 entries). 7635e7012eSMaxime Coquelin */ 7735e7012eSMaxime Coquelin #define VIRTIO_NET_RSS_RETA_SIZE 128 7835e7012eSMaxime Coquelin #define VIRTIO_NET_RSS_KEY_SIZE 40 7935e7012eSMaxime Coquelin 8035e7012eSMaxime Coquelin struct virtio_net_ctrl_rss { 8135e7012eSMaxime Coquelin uint32_t hash_types; 8235e7012eSMaxime Coquelin uint16_t indirection_table_mask; 8335e7012eSMaxime Coquelin uint16_t unclassified_queue; 8435e7012eSMaxime Coquelin uint16_t indirection_table[VIRTIO_NET_RSS_RETA_SIZE]; 8535e7012eSMaxime Coquelin uint16_t max_tx_vq; 8635e7012eSMaxime Coquelin uint8_t hash_key_length; 8735e7012eSMaxime Coquelin uint8_t hash_key_data[VIRTIO_NET_RSS_KEY_SIZE]; 8835e7012eSMaxime Coquelin }; 8935e7012eSMaxime Coquelin 9035e7012eSMaxime Coquelin /* 9135e7012eSMaxime Coquelin * Control link announce acknowledgment 9235e7012eSMaxime Coquelin * 9335e7012eSMaxime Coquelin * The command VIRTIO_NET_CTRL_ANNOUNCE_ACK is used to indicate that 9435e7012eSMaxime Coquelin * driver has received the notification; device would clear the 9535e7012eSMaxime Coquelin * VIRTIO_NET_S_ANNOUNCE bit in the status field after it receives 9635e7012eSMaxime Coquelin * this command. 9735e7012eSMaxime Coquelin */ 9835e7012eSMaxime Coquelin #define VIRTIO_NET_CTRL_ANNOUNCE 3 9935e7012eSMaxime Coquelin #define VIRTIO_NET_CTRL_ANNOUNCE_ACK 0 10035e7012eSMaxime Coquelin 101*e7750639SAndre Muezerie struct __rte_packed_begin virtio_net_ctrl_hdr { 10235e7012eSMaxime Coquelin uint8_t class; 10335e7012eSMaxime Coquelin uint8_t cmd; 104*e7750639SAndre Muezerie } __rte_packed_end; 10535e7012eSMaxime Coquelin 10635e7012eSMaxime Coquelin typedef uint8_t virtio_net_ctrl_ack; 10735e7012eSMaxime Coquelin 10835e7012eSMaxime Coquelin struct virtnet_ctl { 109a632f0f6SMaxime Coquelin const struct rte_memzone *hdr_mz; /**< memzone to populate hdr. */ 110a632f0f6SMaxime Coquelin rte_iova_t hdr_mem; /**< hdr for each xmit packet */ 11135e7012eSMaxime Coquelin rte_spinlock_t lock; /**< spinlock for control queue. */ 1124dd3477cSMaxime Coquelin void (*notify_queue)(struct virtqueue *vq, void *cookie); /**< notify ops. */ 1134dd3477cSMaxime Coquelin void *notify_cookie; /**< cookie for notify ops */ 11435e7012eSMaxime Coquelin }; 11535e7012eSMaxime Coquelin 11635e7012eSMaxime Coquelin #define VIRTIO_MAX_CTRL_DATA 2048 11735e7012eSMaxime Coquelin 11835e7012eSMaxime Coquelin struct virtio_pmd_ctrl { 11935e7012eSMaxime Coquelin struct virtio_net_ctrl_hdr hdr; 12035e7012eSMaxime Coquelin virtio_net_ctrl_ack status; 12135e7012eSMaxime Coquelin uint8_t data[VIRTIO_MAX_CTRL_DATA]; 12235e7012eSMaxime Coquelin }; 12335e7012eSMaxime Coquelin 12435e7012eSMaxime Coquelin int 12535e7012eSMaxime Coquelin virtio_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl, int *dlen, int pkt_num); 12635e7012eSMaxime Coquelin 12735e7012eSMaxime Coquelin #endif /* _VIRTIO_RXTX_H_ */ 128