From ea47c97bf8e67dc5827900ca19234296a33412f7 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 30 Aug 2025 19:03:54 +0200 Subject: [PATCH] Check for MSI-X before checking for MSI --- audio/ihdad/src/main.rs | 3 +-- net/rtl8139d/src/main.rs | 52 ++++++++++++++++++++-------------------- net/rtl8168d/src/main.rs | 52 ++++++++++++++++++++-------------------- xhcid/src/main.rs | 52 ++++++++++++++++++++-------------------- 4 files changed, 79 insertions(+), 80 deletions(-) diff --git a/audio/ihdad/src/main.rs b/audio/ihdad/src/main.rs index e9a91590ec..2effe88ddd 100755 --- a/audio/ihdad/src/main.rs +++ b/audio/ihdad/src/main.rs @@ -35,9 +35,8 @@ fn get_int_method(pcid_handle: &mut PciFunctionHandle) -> File { log::debug!("PCI FEATURES: {:?}", all_pci_features); let has_msi = all_pci_features.iter().any(|feature| feature.is_msi()); - let has_msix = all_pci_features.iter().any(|feature| feature.is_msix()); - if has_msi && !has_msix { + if has_msi { let capability = match pcid_handle.feature_info(PciFeature::Msi) { PciFeatureInfo::Msi(s) => s, PciFeatureInfo::MsiX(_) => panic!(), diff --git a/net/rtl8139d/src/main.rs b/net/rtl8139d/src/main.rs index 80b1091808..a8b8c2c19a 100644 --- a/net/rtl8139d/src/main.rs +++ b/net/rtl8139d/src/main.rs @@ -35,32 +35,7 @@ fn get_int_method(pcid_handle: &mut PciFunctionHandle) -> File { let has_msi = all_pci_features.iter().any(|feature| feature.is_msi()); let has_msix = all_pci_features.iter().any(|feature| feature.is_msix()); - if has_msi && !has_msix { - let capability = match pcid_handle.feature_info(PciFeature::Msi) { - PciFeatureInfo::Msi(s) => s, - PciFeatureInfo::MsiX(_) => panic!(), - }; - // TODO: Allow allocation of up to 32 vectors. - - // TODO: Find a way to abstract this away, potantially as a helper module for - // pcid_interface, so that this can be shared between nvmed, xhcid, ixgebd, etc.. - - let destination_id = read_bsp_apic_id().expect("rtl8139d: failed to read BSP apic id"); - let (msg_addr_and_data, interrupt_handle) = - allocate_single_interrupt_vector_for_msi(destination_id); - - let set_feature_info = MsiSetFeatureInfo { - multi_message_enable: Some(0), - message_address_and_data: Some(msg_addr_and_data), - mask_bits: None, - }; - pcid_handle.set_feature_info(SetFeatureInfo::Msi(set_feature_info)); - - pcid_handle.enable_feature(PciFeature::Msi); - log::info!("Enabled MSI"); - - interrupt_handle - } else if has_msix { + if has_msix { let msix_info = match pcid_handle.feature_info(PciFeature::MsiX) { PciFeatureInfo::Msi(_) => panic!(), PciFeatureInfo::MsiX(s) => s, @@ -88,6 +63,31 @@ fn get_int_method(pcid_handle: &mut PciFunctionHandle) -> File { log::info!("Enabled MSI-X"); method + } else if has_msi { + let capability = match pcid_handle.feature_info(PciFeature::Msi) { + PciFeatureInfo::Msi(s) => s, + PciFeatureInfo::MsiX(_) => panic!(), + }; + // TODO: Allow allocation of up to 32 vectors. + + // TODO: Find a way to abstract this away, potantially as a helper module for + // pcid_interface, so that this can be shared between nvmed, xhcid, ixgebd, etc.. + + let destination_id = read_bsp_apic_id().expect("rtl8139d: failed to read BSP apic id"); + let (msg_addr_and_data, interrupt_handle) = + allocate_single_interrupt_vector_for_msi(destination_id); + + let set_feature_info = MsiSetFeatureInfo { + multi_message_enable: Some(0), + message_address_and_data: Some(msg_addr_and_data), + mask_bits: None, + }; + pcid_handle.set_feature_info(SetFeatureInfo::Msi(set_feature_info)); + + pcid_handle.enable_feature(PciFeature::Msi); + log::info!("Enabled MSI"); + + interrupt_handle } else if let Some(irq) = pci_config.func.legacy_interrupt_line { // legacy INTx# interrupt pins. irq.irq_handle("rtl8139d") diff --git a/net/rtl8168d/src/main.rs b/net/rtl8168d/src/main.rs index 44c8f41859..6e9d4c1acc 100644 --- a/net/rtl8168d/src/main.rs +++ b/net/rtl8168d/src/main.rs @@ -35,32 +35,7 @@ fn get_int_method(pcid_handle: &mut PciFunctionHandle) -> File { let has_msi = all_pci_features.iter().any(|feature| feature.is_msi()); let has_msix = all_pci_features.iter().any(|feature| feature.is_msix()); - if has_msi && !has_msix { - let capability = match pcid_handle.feature_info(PciFeature::Msi) { - PciFeatureInfo::Msi(s) => s, - PciFeatureInfo::MsiX(_) => panic!(), - }; - // TODO: Allow allocation of up to 32 vectors. - - // TODO: Find a way to abstract this away, potantially as a helper module for - // pcid_interface, so that this can be shared between nvmed, xhcid, ixgebd, etc.. - - let destination_id = read_bsp_apic_id().expect("rtl8168d: failed to read BSP apic id"); - let (msg_addr_and_data, interrupt_handle) = - allocate_single_interrupt_vector_for_msi(destination_id); - - let set_feature_info = MsiSetFeatureInfo { - multi_message_enable: Some(0), - message_address_and_data: Some(msg_addr_and_data), - mask_bits: None, - }; - pcid_handle.set_feature_info(SetFeatureInfo::Msi(set_feature_info)); - - pcid_handle.enable_feature(PciFeature::Msi); - log::info!("Enabled MSI"); - - interrupt_handle - } else if has_msix { + if has_msix { let msix_info = match pcid_handle.feature_info(PciFeature::MsiX) { PciFeatureInfo::Msi(_) => panic!(), PciFeatureInfo::MsiX(s) => s, @@ -88,6 +63,31 @@ fn get_int_method(pcid_handle: &mut PciFunctionHandle) -> File { log::info!("Enabled MSI-X"); method + } else if has_msi { + let capability = match pcid_handle.feature_info(PciFeature::Msi) { + PciFeatureInfo::Msi(s) => s, + PciFeatureInfo::MsiX(_) => panic!(), + }; + // TODO: Allow allocation of up to 32 vectors. + + // TODO: Find a way to abstract this away, potantially as a helper module for + // pcid_interface, so that this can be shared between nvmed, xhcid, ixgebd, etc.. + + let destination_id = read_bsp_apic_id().expect("rtl8168d: failed to read BSP apic id"); + let (msg_addr_and_data, interrupt_handle) = + allocate_single_interrupt_vector_for_msi(destination_id); + + let set_feature_info = MsiSetFeatureInfo { + multi_message_enable: Some(0), + message_address_and_data: Some(msg_addr_and_data), + mask_bits: None, + }; + pcid_handle.set_feature_info(SetFeatureInfo::Msi(set_feature_info)); + + pcid_handle.enable_feature(PciFeature::Msi); + log::info!("Enabled MSI"); + + interrupt_handle } else if let Some(irq) = pci_config.func.legacy_interrupt_line { // legacy INTx# interrupt pins. irq.irq_handle("rtl8168d") diff --git a/xhcid/src/main.rs b/xhcid/src/main.rs index a7c6034105..0cc877cd1d 100644 --- a/xhcid/src/main.rs +++ b/xhcid/src/main.rs @@ -57,32 +57,7 @@ fn get_int_method(pcid_handle: &mut PciFunctionHandle) -> (Option, Interru let has_msi = all_pci_features.iter().any(|feature| feature.is_msi()); let has_msix = all_pci_features.iter().any(|feature| feature.is_msix()); - if has_msi && !has_msix { - let mut capability = match pcid_handle.feature_info(PciFeature::Msi) { - PciFeatureInfo::Msi(s) => s, - PciFeatureInfo::MsiX(_) => panic!(), - }; - // TODO: Allow allocation of up to 32 vectors. - - // TODO: Find a way to abstract this away, potantially as a helper module for - // pcid_interface, so that this can be shared between nvmed, xhcid, ixgebd, etc.. - - let destination_id = read_bsp_apic_id().expect("xhcid: failed to read BSP apic id"); - let (msg_addr_and_data, interrupt_handle) = - allocate_single_interrupt_vector_for_msi(destination_id); - - let set_feature_info = MsiSetFeatureInfo { - multi_message_enable: Some(0), - message_address_and_data: Some(msg_addr_and_data), - mask_bits: None, - }; - pcid_handle.set_feature_info(SetFeatureInfo::Msi(set_feature_info)); - - pcid_handle.enable_feature(PciFeature::Msi); - log::debug!("Enabled MSI"); - - (Some(interrupt_handle), InterruptMethod::Msi) - } else if has_msix { + if has_msix { let msix_info = match pcid_handle.feature_info(PciFeature::MsiX) { PciFeatureInfo::Msi(_) => panic!(), PciFeatureInfo::MsiX(s) => s, @@ -113,6 +88,31 @@ fn get_int_method(pcid_handle: &mut PciFunctionHandle) -> (Option, Interru log::debug!("Enabled MSI-X"); method + } else if has_msi { + let mut capability = match pcid_handle.feature_info(PciFeature::Msi) { + PciFeatureInfo::Msi(s) => s, + PciFeatureInfo::MsiX(_) => panic!(), + }; + // TODO: Allow allocation of up to 32 vectors. + + // TODO: Find a way to abstract this away, potantially as a helper module for + // pcid_interface, so that this can be shared between nvmed, xhcid, ixgebd, etc.. + + let destination_id = read_bsp_apic_id().expect("xhcid: failed to read BSP apic id"); + let (msg_addr_and_data, interrupt_handle) = + allocate_single_interrupt_vector_for_msi(destination_id); + + let set_feature_info = MsiSetFeatureInfo { + multi_message_enable: Some(0), + message_address_and_data: Some(msg_addr_and_data), + mask_bits: None, + }; + pcid_handle.set_feature_info(SetFeatureInfo::Msi(set_feature_info)); + + pcid_handle.enable_feature(PciFeature::Msi); + log::debug!("Enabled MSI"); + + (Some(interrupt_handle), InterruptMethod::Msi) } else if let Some(irq) = pci_config.func.legacy_interrupt_line { log::debug!("Legacy IRQ {}", irq);