#[derive(Debug)]
enum DriverProfileChoice
{
LinuxOnly
{
linux: &'static DriverProfile,
},
LinuxOrIntel
{
linux: &'static DriverProfile,
intel: &'static DriverProfile,
}
}
impl DriverProfileChoice
{
#[inline(always)]
fn find_driver_profile(linux_kernel_version: &LinuxKernelVersion, driver_name: &ObjectName32, driver_version: &ObjectName32, pci_vendor_and_device: PciVendorAndDevice) -> Option<&'static DriverProfile>
{
use self::DriverProfileChoice::*;
lazy_static!
{
static ref DriverProfiles: DriverProfilesMap = DriverProfileChoice::driver_profiles_map();
};
let key = (driver_name.clone(), pci_vendor_and_device);
let driver_profiles_map: &DriverProfilesMap = DriverProfiles.deref();
driver_profiles_map.get(&key).map(|driver_profile_fork| match driver_profile_fork
{
&LinuxOnly { linux } => linux,
&LinuxOrIntel { linux, intel } => if Self::is_intel_fork(linux_kernel_version, driver_name, driver_version)
{
intel
}
else
{
linux
},
})
}
#[doc(hidden)]
#[inline(always)]
fn driver_profiles_map() -> DriverProfilesMap
{
lazy_static!
{
static ref amazon_ena: DriverProfile = DriverProfile::amazon_ena();
static ref intel_ixgbevf_linux_fork: DriverProfile = DriverProfile::intel_ixgbevf_linux_fork();
static ref intel_ixgbevf_intel_fork_x540_or_earlier: DriverProfile = DriverProfile::intel_ixgbevf_intel_fork_x540_or_earlier();
static ref intel_ixgbevf_intel_fork_x550_or_later: DriverProfile = DriverProfile::intel_ixgbevf_intel_fork_x550_or_later();
static ref virtio_net: DriverProfile = DriverProfile::virtio_net();
}
fast_secure_hash_map!
[
(Self::ena(), PciVendorAndDevice::Amazon_Ena_RESRV0) => Self::linux_only(&amazon_ena),
(Self::ena(), PciVendorAndDevice::Amazon_Ena_PF) => Self::linux_only(&amazon_ena),
(Self::ena(), PciVendorAndDevice::Amazon_Ena_LLQ_PF) => Self::linux_only(&amazon_ena),
(Self::ena(), PciVendorAndDevice::Amazon_Ena_VF) => Self::linux_only(&amazon_ena),
(Self::ena(), PciVendorAndDevice::Amazon_Ena_LLQ_VF) => Self::linux_only(&amazon_ena),
(Self::ixgbevf(), PciVendorAndDevice::Intel_Ixgbe_Virtual_82599_VF) => Self::linux_or_intel(&intel_ixgbevf_linux_fork, &intel_ixgbevf_intel_fork_x540_or_earlier),
(Self::ixgbevf(), PciVendorAndDevice::Intel_Ixgbe_Virtual_82599_VF_HV) => Self::linux_or_intel(&intel_ixgbevf_linux_fork, &intel_ixgbevf_intel_fork_x540_or_earlier),
(Self::ixgbevf(), PciVendorAndDevice::Intel_Ixgbe_Virtual_X540_VF) => Self::linux_or_intel(&intel_ixgbevf_linux_fork, &intel_ixgbevf_intel_fork_x540_or_earlier),
(Self::ixgbevf(), PciVendorAndDevice::Intel_Ixgbe_Virtual_X540_VF_HV) => Self::linux_or_intel(&intel_ixgbevf_linux_fork, &intel_ixgbevf_intel_fork_x540_or_earlier),
(Self::ixgbevf(), PciVendorAndDevice::Intel_Ixgbe_Virtual_X550_VF) => Self::linux_or_intel(&intel_ixgbevf_linux_fork, &intel_ixgbevf_intel_fork_x550_or_later),
(Self::ixgbevf(), PciVendorAndDevice::Intel_Ixgbe_Virtual_X550_VF_HV) => Self::linux_or_intel(&intel_ixgbevf_linux_fork, &intel_ixgbevf_intel_fork_x550_or_later),
(Self::ixgbevf(), PciVendorAndDevice::Intel_Ixgbe_Virtual_X550EM_X_VF) => Self::linux_or_intel(&intel_ixgbevf_linux_fork, &intel_ixgbevf_intel_fork_x550_or_later),
(Self::ixgbevf(), PciVendorAndDevice::Intel_Ixgbe_Virtual_X550EM_X_VF_HV) => Self::linux_or_intel(&intel_ixgbevf_linux_fork, &intel_ixgbevf_intel_fork_x550_or_later),
(Self::ixgbevf(), PciVendorAndDevice::Intel_Ixgbe_Virtual_X550EM_A_VF) => Self::linux_or_intel(&intel_ixgbevf_linux_fork, &intel_ixgbevf_intel_fork_x550_or_later),
(Self::ixgbevf(), PciVendorAndDevice::Intel_Ixgbe_Virtual_X550EM_A_VF_HV) => Self::linux_or_intel(&intel_ixgbevf_linux_fork, &intel_ixgbevf_intel_fork_x550_or_later),
(Self::virtio_net(), PciVendorAndDevice::VirtIO_Network) => Self::linux_only(&virtio_net),
(Self::virtio_net(), PciVendorAndDevice::VirtIO_NewNetwork) => Self::linux_only(&virtio_net),
]
}
#[doc(hidden)]
#[inline(always)]
fn is_intel_fork(linux_kernel_version: &LinuxKernelVersion, driver_name: &ObjectName32, driver_version: &ObjectName32) -> bool
{
let driver_name_bytes: &[u8] = driver_name.as_ref();
match driver_name_bytes
{
Self::ixgbevf_bytes =>
{
let driver_version_bytes: &[u8] = driver_version.as_ref();
if &linux_kernel_version.release[..] == driver_version_bytes
{
true
}
else if driver_version_bytes.ends_with(b"-k")
{
true
}
else
{
false
}
},
_ => false,
}
}
#[doc(hidden)]
#[inline(always)]
const fn linux_only(linux: &'static DriverProfile) -> Self
{
DriverProfileChoice::LinuxOnly
{
linux
}
}
#[doc(hidden)]
#[inline(always)]
const fn linux_or_intel(linux: &'static DriverProfile, intel: &'static DriverProfile) -> Self
{
DriverProfileChoice::LinuxOrIntel
{
linux,
intel,
}
}
const ena_bytes: &'static [u8] = b"ena";
#[doc(hidden)]
pub fn ena() -> ObjectName32
{
ObjectName32::try_from(Self::ena_bytes).unwrap()
}
const ixgbevf_bytes: &'static [u8] = b"ixgbevf";
#[doc(hidden)]
pub fn ixgbevf() -> ObjectName32
{
ObjectName32::try_from(Self::ixgbevf_bytes).unwrap()
}
const virtio_net_bytes: &'static [u8] = b"virtio_net";
#[doc(hidden)]
pub fn virtio_net() -> ObjectName32
{
ObjectName32::try_from(Self::virtio_net_bytes).unwrap()
}
}