1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2010-2015 Intel Corporation 3 */ 4 5 #ifndef _VIRTIO_CVQ_H_ 6 #define _VIRTIO_CVQ_H_ 7 8 #include <rte_ether.h> 9 10 struct virtqueue; 11 12 /** 13 * Control the RX mode, ie. promiscuous, allmulti, etc... 14 * All commands require an "out" sg entry containing a 1 byte 15 * state value, zero = disable, non-zero = enable. Commands 16 * 0 and 1 are supported with the VIRTIO_NET_F_CTRL_RX feature. 17 * Commands 2-5 are added with VIRTIO_NET_F_CTRL_RX_EXTRA. 18 */ 19 #define VIRTIO_NET_CTRL_RX 0 20 #define VIRTIO_NET_CTRL_RX_PROMISC 0 21 #define VIRTIO_NET_CTRL_RX_ALLMULTI 1 22 #define VIRTIO_NET_CTRL_RX_ALLUNI 2 23 #define VIRTIO_NET_CTRL_RX_NOMULTI 3 24 #define VIRTIO_NET_CTRL_RX_NOUNI 4 25 #define VIRTIO_NET_CTRL_RX_NOBCAST 5 26 27 /** 28 * Control the MAC 29 * 30 * The MAC filter table is managed by the hypervisor, the guest should 31 * assume the size is infinite. Filtering should be considered 32 * non-perfect, ie. based on hypervisor resources, the guest may 33 * received packets from sources not specified in the filter list. 34 * 35 * In addition to the class/cmd header, the TABLE_SET command requires 36 * two out scatterlists. Each contains a 4 byte count of entries followed 37 * by a concatenated byte stream of the ETH_ALEN MAC addresses. The 38 * first sg list contains unicast addresses, the second is for multicast. 39 * This functionality is present if the VIRTIO_NET_F_CTRL_RX feature 40 * is available. 41 * 42 * The ADDR_SET command requests one out scatterlist, it contains a 43 * 6 bytes MAC address. This functionality is present if the 44 * VIRTIO_NET_F_CTRL_MAC_ADDR feature is available. 45 */ 46 struct __rte_packed_begin virtio_net_ctrl_mac { 47 uint32_t entries; 48 uint8_t macs[][RTE_ETHER_ADDR_LEN]; 49 } __rte_packed_end; 50 51 #define VIRTIO_NET_CTRL_MAC 1 52 #define VIRTIO_NET_CTRL_MAC_TABLE_SET 0 53 #define VIRTIO_NET_CTRL_MAC_ADDR_SET 1 54 55 /** 56 * Control VLAN filtering 57 * 58 * The VLAN filter table is controlled via a simple ADD/DEL interface. 59 * VLAN IDs not added may be filtered by the hypervisor. Del is the 60 * opposite of add. Both commands expect an out entry containing a 2 61 * byte VLAN ID. VLAN filtering is available with the 62 * VIRTIO_NET_F_CTRL_VLAN feature bit. 63 */ 64 #define VIRTIO_NET_CTRL_VLAN 2 65 #define VIRTIO_NET_CTRL_VLAN_ADD 0 66 #define VIRTIO_NET_CTRL_VLAN_DEL 1 67 68 /** 69 * RSS control 70 * 71 * The RSS feature configuration message is sent by the driver when 72 * VIRTIO_NET_F_RSS has been negotiated. It provides the device with 73 * hash types to use, hash key and indirection table. In this 74 * implementation, the driver only supports fixed key length (40B) 75 * and indirection table size (128 entries). 76 */ 77 #define VIRTIO_NET_RSS_RETA_SIZE 128 78 #define VIRTIO_NET_RSS_KEY_SIZE 40 79 80 struct virtio_net_ctrl_rss { 81 uint32_t hash_types; 82 uint16_t indirection_table_mask; 83 uint16_t unclassified_queue; 84 uint16_t indirection_table[VIRTIO_NET_RSS_RETA_SIZE]; 85 uint16_t max_tx_vq; 86 uint8_t hash_key_length; 87 uint8_t hash_key_data[VIRTIO_NET_RSS_KEY_SIZE]; 88 }; 89 90 /* 91 * Control link announce acknowledgment 92 * 93 * The command VIRTIO_NET_CTRL_ANNOUNCE_ACK is used to indicate that 94 * driver has received the notification; device would clear the 95 * VIRTIO_NET_S_ANNOUNCE bit in the status field after it receives 96 * this command. 97 */ 98 #define VIRTIO_NET_CTRL_ANNOUNCE 3 99 #define VIRTIO_NET_CTRL_ANNOUNCE_ACK 0 100 101 struct __rte_packed_begin virtio_net_ctrl_hdr { 102 uint8_t class; 103 uint8_t cmd; 104 } __rte_packed_end; 105 106 typedef uint8_t virtio_net_ctrl_ack; 107 108 struct virtnet_ctl { 109 const struct rte_memzone *hdr_mz; /**< memzone to populate hdr. */ 110 rte_iova_t hdr_mem; /**< hdr for each xmit packet */ 111 rte_spinlock_t lock; /**< spinlock for control queue. */ 112 void (*notify_queue)(struct virtqueue *vq, void *cookie); /**< notify ops. */ 113 void *notify_cookie; /**< cookie for notify ops */ 114 }; 115 116 #define VIRTIO_MAX_CTRL_DATA 2048 117 118 struct virtio_pmd_ctrl { 119 struct virtio_net_ctrl_hdr hdr; 120 virtio_net_ctrl_ack status; 121 uint8_t data[VIRTIO_MAX_CTRL_DATA]; 122 }; 123 124 int 125 virtio_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl, int *dlen, int pkt_num); 126 127 #endif /* _VIRTIO_RXTX_H_ */ 128