Kaynağa Gözat

Add the vsock feature bits introduced in virtio v1.2 spec (#89)

Co-authored-by: Alice Wang <aliceywang@google.com>
Alice Wang 1 yıl önce
ebeveyn
işleme
c457edd8bd
2 değiştirilmiş dosya ile 30 ekleme ve 2 silme
  1. 29 0
      src/device/socket/protocol.rs
  2. 1 2
      src/device/socket/vsock.rs

+ 29 - 0
src/device/socket/protocol.rs

@@ -2,6 +2,7 @@
 
 use super::error::{self, SocketError};
 use crate::volatile::ReadOnly;
+use bitflags::bitflags;
 use core::{
     convert::{TryFrom, TryInto},
     fmt,
@@ -17,6 +18,8 @@ use zerocopy::{
 pub enum SocketType {
     /// Stream sockets provide in-order, guaranteed, connection-oriented delivery without message boundaries.
     Stream = 1,
+    /// seqpacket socket type introduced in virtio-v1.2.
+    SeqPacket = 2,
 }
 
 impl From<SocketType> for U16<LittleEndian> {
@@ -182,3 +185,29 @@ impl fmt::Debug for VirtioVsockOp {
         }
     }
 }
+
+bitflags! {
+    #[derive(Copy, Clone, Debug, Default, Eq, PartialEq)]
+    pub(crate) struct Feature: u64 {
+        /// stream socket type is supported.
+        const STREAM = 1 << 0;
+        /// seqpacket socket type is supported.
+        const SEQ_PACKET = 1 << 1;
+
+        // device independent
+        const NOTIFY_ON_EMPTY       = 1 << 24; // legacy
+        const ANY_LAYOUT            = 1 << 27; // legacy
+        const RING_INDIRECT_DESC    = 1 << 28;
+        const RING_EVENT_IDX        = 1 << 29;
+        const UNUSED                = 1 << 30; // legacy
+        const VERSION_1             = 1 << 32; // detect legacy
+
+        // since virtio v1.1
+        const ACCESS_PLATFORM       = 1 << 33;
+        const RING_PACKED           = 1 << 34;
+        const IN_ORDER              = 1 << 35;
+        const ORDER_PLATFORM        = 1 << 36;
+        const SR_IOV                = 1 << 37;
+        const NOTIFICATION_DATA     = 1 << 38;
+    }
+}

+ 1 - 2
src/device/socket/vsock.rs

@@ -2,8 +2,7 @@
 #![deny(unsafe_op_in_unsafe_fn)]
 
 use super::error::SocketError;
-use super::protocol::{VirtioVsockConfig, VirtioVsockHdr, VirtioVsockOp, VsockAddr};
-use crate::device::common::Feature;
+use super::protocol::{Feature, VirtioVsockConfig, VirtioVsockHdr, VirtioVsockOp, VsockAddr};
 use crate::hal::Hal;
 use crate::queue::VirtQueue;
 use crate::transport::Transport;