1 // Copyright 2021 The ChromiumOS Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 use virtio_sys::virtio_net; 6 use vmm_vhost::message::VhostUserProtocolFeatures; 7 8 use crate::virtio::vhost::user::vmm::Connection; 9 use crate::virtio::vhost::user::vmm::QueueSizes; 10 use crate::virtio::vhost::user::vmm::Result; 11 use crate::virtio::vhost::user::vmm::VhostUserVirtioDevice; 12 use crate::virtio::DeviceType; 13 14 const QUEUE_SIZE: u16 = 1024; 15 16 impl VhostUserVirtioDevice { new_net(base_features: u64, connection: Connection) -> Result<VhostUserVirtioDevice>17 pub fn new_net(base_features: u64, connection: Connection) -> Result<VhostUserVirtioDevice> { 18 // 3 = rx, tx, ctrl 19 let queue_sizes = QueueSizes::AskDevice { 20 queue_size: QUEUE_SIZE, 21 default_queues: 3, 22 }; 23 let max_queues = 3; 24 25 let allow_features = 1 << virtio_net::VIRTIO_NET_F_CSUM 26 | 1 << virtio_net::VIRTIO_NET_F_CTRL_VQ 27 | 1 << virtio_net::VIRTIO_NET_F_CTRL_GUEST_OFFLOADS 28 | 1 << virtio_net::VIRTIO_NET_F_GUEST_CSUM 29 | 1 << virtio_net::VIRTIO_NET_F_GUEST_TSO4 30 | 1 << virtio_net::VIRTIO_NET_F_GUEST_UFO 31 | 1 << virtio_net::VIRTIO_NET_F_HOST_TSO4 32 | 1 << virtio_net::VIRTIO_NET_F_HOST_UFO 33 | 1 << virtio_net::VIRTIO_NET_F_MAC 34 | 1 << virtio_net::VIRTIO_NET_F_MQ 35 | 1 << virtio_net::VIRTIO_NET_F_MTU; 36 37 let allow_protocol_features = 38 VhostUserProtocolFeatures::MQ | VhostUserProtocolFeatures::CONFIG; 39 40 VhostUserVirtioDevice::new( 41 connection, 42 DeviceType::Net, 43 queue_sizes, 44 max_queues, 45 allow_features, 46 allow_protocol_features, 47 base_features, 48 None, 49 false, 50 ) 51 } 52 } 53