-
Notifications
You must be signed in to change notification settings - Fork 29
VirtIO 1.0 and multi-queue support #998
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dancrossnyc
wants to merge
1
commit into
master
Choose a base branch
from
virtio-modern
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,353
−751
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| // This Source Code Form is subject to the terms of the Mozilla Public | ||
| // License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| // file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
|
||
| #![allow(non_camel_case_types)] | ||
|
|
||
| use libc::size_t; | ||
| use std::ffi::c_void; | ||
|
|
||
| const fn vna_ioc(ioc: i32) -> i32 { | ||
| const V: i32 = b'V' as i32; | ||
| const C: i32 = b'C' as i32; | ||
| V << 16 | C << 8 | ioc | ||
| } | ||
|
|
||
| pub const VNA_IOC_CREATE: i32 = vna_ioc(0x01); | ||
| pub const VNA_IOC_DELETE: i32 = vna_ioc(0x02); | ||
| pub const VNA_IOC_VERSION: i32 = vna_ioc(0x03); | ||
| pub const VNA_IOC_DEFAULT_PARAMS: i32 = vna_ioc(0x04); | ||
|
|
||
| pub const VNA_IOC_RING_INIT: i32 = vna_ioc(0x10); | ||
| pub const VNA_IOC_RING_RESET: i32 = vna_ioc(0x11); | ||
| pub const VNA_IOC_RING_KICK: i32 = vna_ioc(0x12); | ||
| pub const VNA_IOC_RING_SET_MSI: i32 = vna_ioc(0x13); | ||
| pub const VNA_IOC_RING_INTR_CLR: i32 = vna_ioc(0x14); | ||
| pub const VNA_IOC_RING_SET_STATE: i32 = vna_ioc(0x15); | ||
| pub const VNA_IOC_RING_GET_STATE: i32 = vna_ioc(0x16); | ||
| pub const VNA_IOC_RING_PAUSE: i32 = vna_ioc(0x17); | ||
|
|
||
| pub const VNA_IOC_INTR_POLL: i32 = vna_ioc(0x20); | ||
| pub const VNA_IOC_SET_FEATURES: i32 = vna_ioc(0x21); | ||
| pub const VNA_IOC_GET_FEATURES: i32 = vna_ioc(0x22); | ||
| pub const VNA_IOC_SET_NOTIFY_IOP: i32 = vna_ioc(0x23); | ||
| pub const VNA_IOC_SET_PROMISC: i32 = vna_ioc(0x24); | ||
| pub const VNA_IOC_GET_PARAMS: i32 = vna_ioc(0x25); | ||
| pub const VNA_IOC_SET_PARAMS: i32 = vna_ioc(0x26); | ||
| pub const VNA_IOC_GET_MTU: i32 = vna_ioc(0x27); | ||
| pub const VNA_IOC_SET_MTU: i32 = vna_ioc(0x28); | ||
| pub const VNA_IOC_SET_NOTIFY_MMIO: i32 = vna_ioc(0x29); | ||
|
|
||
| /// VirtIO 1.2 queue pair support. | ||
| pub const VNA_IOC_GET_PAIRS: i32 = vna_ioc(0x30); | ||
| pub const VNA_IOC_SET_PAIRS: i32 = vna_ioc(0x31); | ||
| pub const VNA_IOC_GET_USEPAIRS: i32 = vna_ioc(0x32); | ||
| pub const VNA_IOC_SET_USEPAIRS: i32 = vna_ioc(0x33); | ||
|
|
||
| #[cfg(test)] | ||
| mod test { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn test_vna_ioc() { | ||
| assert_eq!(vna_ioc(0x22), 0x00_56_43_22); | ||
| } | ||
| } | ||
|
|
||
| /// The minimum number of queue pairs supported by a device. | ||
| pub const VIONA_MIN_QPAIRS: usize = 1; | ||
|
|
||
| /// The maximum number of queue pairs supported by a device. | ||
| /// | ||
| /// Note that the VirtIO limit is much higher (0x8000); Viona artificially | ||
| /// limits the number to 256 pairs, which makes it possible to implmeent | ||
| /// interrupt notification with a reasonably sized bitmap. | ||
| pub const VIONA_MAX_QPAIRS: usize = 0x100; | ||
|
|
||
| const fn howmany(x: usize, y: usize) -> usize { | ||
| assert!(y > 0); | ||
| x.div_ceil(y) | ||
| } | ||
|
|
||
| #[repr(C)] | ||
| pub struct vioc_create { | ||
| pub c_linkid: u32, | ||
| pub c_vmfd: i32, | ||
| } | ||
|
|
||
| #[repr(C)] | ||
| #[derive(Default)] | ||
| pub struct vioc_ring_init { | ||
| pub ri_index: u16, | ||
| pub ri_qsize: u16, | ||
| pub _pad: [u16; 2], | ||
| pub ri_qaddr_desc: u64, | ||
| pub ri_qaddr_avail: u64, | ||
| pub ri_qaddr_used: u64, | ||
| } | ||
|
|
||
| #[repr(C)] | ||
| #[derive(Default)] | ||
| pub struct vioc_ring_msi { | ||
| pub rm_index: u16, | ||
| pub _pad: [u16; 3], | ||
| pub rm_addr: u64, | ||
| pub rm_msg: u64, | ||
| } | ||
|
|
||
| #[repr(C)] | ||
| #[derive(Default)] | ||
| pub struct vioc_intr_poll { | ||
| pub vip_nrings: u16, | ||
| pub _vip_pad0: u16, | ||
| pub vip_status: [u32; howmany(VIONA_MAX_QPAIRS, 32)], | ||
citrus-it marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| #[repr(C)] | ||
| #[derive(Default)] | ||
| pub struct vioc_notify_mmio { | ||
| pub vim_address: u64, | ||
| pub vim_size: u32, | ||
| } | ||
|
|
||
| #[repr(C)] | ||
| #[derive(Default)] | ||
| pub struct vioc_ring_state { | ||
| pub vrs_index: u16, | ||
| pub vrs_avail_idx: u16, | ||
| pub vrs_used_idx: u16, | ||
| pub vrs_qsize: u16, | ||
| pub vrs_qaddr_desc: u64, | ||
| pub vrs_qaddr_avail: u64, | ||
| pub vrs_qaddr_used: u64, | ||
| } | ||
|
|
||
| pub const VIONA_PROMISC_NONE: i32 = 0; | ||
| pub const VIONA_PROMISC_MULTI: i32 = 1; | ||
| pub const VIONA_PROMISC_ALL: i32 = 2; | ||
| #[cfg(feature = "falcon")] | ||
| pub const VIONA_PROMISC_ALL_VLAN: i32 = 3; | ||
|
|
||
| #[repr(C)] | ||
| #[derive(Default)] | ||
| pub struct vioc_get_params { | ||
| pub vgp_param: *mut c_void, | ||
| pub vgp_param_sz: size_t, | ||
| } | ||
|
|
||
| #[repr(C)] | ||
| #[derive(Default)] | ||
| pub struct vioc_set_params { | ||
| pub vsp_param: *mut c_void, | ||
| pub vsp_param_sz: size_t, | ||
| pub vsp_error: *mut c_void, | ||
| pub vsp_error_sz: size_t, | ||
| } | ||
|
|
||
| /// This is the viona interface version which viona_api expects to operate | ||
| /// against. All constants and structs defined by the crate are done so in | ||
| /// terms of that specific version. | ||
| pub const VIONA_CURRENT_INTERFACE_VERSION: u32 = 6; | ||
|
|
||
| /// Maximum size of packed nvlists used in viona parameter ioctls | ||
| pub const VIONA_MAX_PARAM_NVLIST_SZ: usize = 4096; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.