public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] MdeModulePkg: Handle InitialVFs=0 case for SR-IOV
@ 2022-09-29  8:49 Bob Feng
  2022-09-29  8:54 ` [edk2-devel] " Ni, Ray
  0 siblings, 1 reply; 2+ messages in thread
From: Bob Feng @ 2022-09-29  8:49 UTC (permalink / raw)
  To: devel; +Cc: Foster Nong

From: Foster Nong <foster.nong@intel.com>

Per SR-IOV spec,InitialVFs minimum is 0. Below code which use to calculate SR-IOV bus number,
if InitialVFs =0, it maybe calculate the wrong bus number.

LastVF = PFRid + FirstVFOffset + (PciIoDevice->InitialVFs - 1) * VFStride
we can fix it with below code:
 if (PciIoDevice->InitialVFs == 0) {
 PciIoDevice->ReservedBusNum = 0;
} else {
PFRid  = EFI_PCI_RID (Bus, Device, Func);
 LastVF = PFRid + FirstVFOffset + (PciIoDevice->InitialVFs - 1) * VFStride;
//
// Calculate ReservedBusNum for this PF
//
PciIoDevice->ReservedBusNum = (UINT16)(EFI_PCI_BUS_OF_RID (LastVF) - Bus + 1);
//
 // Calculate ReservedBusNum for this PF
//
 PciIoDevice->ReservedBusNum = (UINT16)(EFI_PCI_BUS_OF_RID (LastVF) - Bus + 1);
}

https://bugzilla.tianocore.org/show_bug.cgi?id=4069

Signed-off-by: Foster Nong <foster.nong@intel.com>
---
 .../Bus/Pci/PciBusDxe/PciEnumeratorSupport.c     | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c
index 509f828b62..eb250f6f7b 100644
--- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c
+++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c
@@ -2416,13 +2416,17 @@ CreatePciIoDevice (
       //
       // Calculate LastVF
       //
-      PFRid  = EFI_PCI_RID (Bus, Device, Func);
-      LastVF = PFRid + FirstVFOffset + (PciIoDevice->InitialVFs - 1) * VFStride;
+      if (PciIoDevice->InitialVFs == 0) {
+        PciIoDevice->ReservedBusNum = 0;
+      } else {
+        PFRid  = EFI_PCI_RID (Bus, Device, Func);
+        LastVF = PFRid + FirstVFOffset + (PciIoDevice->InitialVFs - 1) * VFStride;
 
-      //
-      // Calculate ReservedBusNum for this PF
-      //
-      PciIoDevice->ReservedBusNum = (UINT16)(EFI_PCI_BUS_OF_RID (LastVF) - Bus + 1);
+        //
+        // Calculate ReservedBusNum for this PF
+        //
+        PciIoDevice->ReservedBusNum = (UINT16)(EFI_PCI_BUS_OF_RID (LastVF) - Bus + 1);
+      }
 
       DEBUG ((
         DEBUG_INFO,
-- 
2.37.1.windows.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [edk2-devel] [PATCH] MdeModulePkg: Handle InitialVFs=0 case for SR-IOV
  2022-09-29  8:49 [PATCH] MdeModulePkg: Handle InitialVFs=0 case for SR-IOV Bob Feng
@ 2022-09-29  8:54 ` Ni, Ray
  0 siblings, 0 replies; 2+ messages in thread
From: Ni, Ray @ 2022-09-29  8:54 UTC (permalink / raw)
  To: devel@edk2.groups.io, Feng, Bob C; +Cc: Nong, Foster

Foster,
Can you please include the SRIOV spec content in comments?

> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Bob
> Feng
> Sent: Thursday, September 29, 2022 4:50 PM
> To: devel@edk2.groups.io
> Cc: Nong, Foster <foster.nong@intel.com>
> Subject: [edk2-devel] [PATCH] MdeModulePkg: Handle InitialVFs=0 case for
> SR-IOV
> 
> From: Foster Nong <foster.nong@intel.com>
> 
> Per SR-IOV spec,InitialVFs minimum is 0. Below code which use to calculate
> SR-IOV bus number,
> if InitialVFs =0, it maybe calculate the wrong bus number.
> 
> LastVF = PFRid + FirstVFOffset + (PciIoDevice->InitialVFs - 1) * VFStride
> we can fix it with below code:
>  if (PciIoDevice->InitialVFs == 0) {
>  PciIoDevice->ReservedBusNum = 0;
> } else {
> PFRid  = EFI_PCI_RID (Bus, Device, Func);
>  LastVF = PFRid + FirstVFOffset + (PciIoDevice->InitialVFs - 1) * VFStride;
> //
> // Calculate ReservedBusNum for this PF
> //
> PciIoDevice->ReservedBusNum = (UINT16)(EFI_PCI_BUS_OF_RID (LastVF) -
> Bus + 1);
> //
>  // Calculate ReservedBusNum for this PF
> //
>  PciIoDevice->ReservedBusNum = (UINT16)(EFI_PCI_BUS_OF_RID (LastVF) -
> Bus + 1);
> }
> 
> https://bugzilla.tianocore.org/show_bug.cgi?id=4069
> 
> Signed-off-by: Foster Nong <foster.nong@intel.com>
> ---
>  .../Bus/Pci/PciBusDxe/PciEnumeratorSupport.c     | 16 ++++++++++------
>  1 file changed, 10 insertions(+), 6 deletions(-)
> 
> diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c
> b/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c
> index 509f828b62..eb250f6f7b 100644
> --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c
> +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c
> @@ -2416,13 +2416,17 @@ CreatePciIoDevice (
>        //
>        // Calculate LastVF
>        //
> -      PFRid  = EFI_PCI_RID (Bus, Device, Func);
> -      LastVF = PFRid + FirstVFOffset + (PciIoDevice->InitialVFs - 1) * VFStride;
> +      if (PciIoDevice->InitialVFs == 0) {
> +        PciIoDevice->ReservedBusNum = 0;
> +      } else {
> +        PFRid  = EFI_PCI_RID (Bus, Device, Func);
> +        LastVF = PFRid + FirstVFOffset + (PciIoDevice->InitialVFs - 1) * VFStride;
> 
> -      //
> -      // Calculate ReservedBusNum for this PF
> -      //
> -      PciIoDevice->ReservedBusNum = (UINT16)(EFI_PCI_BUS_OF_RID
> (LastVF) - Bus + 1);
> +        //
> +        // Calculate ReservedBusNum for this PF
> +        //
> +        PciIoDevice->ReservedBusNum = (UINT16)(EFI_PCI_BUS_OF_RID
> (LastVF) - Bus + 1);
> +      }
> 
>        DEBUG ((
>          DEBUG_INFO,
> --
> 2.37.1.windows.1
> 
> 
> 
> 
> 


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-09-29  8:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-29  8:49 [PATCH] MdeModulePkg: Handle InitialVFs=0 case for SR-IOV Bob Feng
2022-09-29  8:54 ` [edk2-devel] " Ni, Ray

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox