From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web10.15924.1665542226696379833 for ; Tue, 11 Oct 2022 19:37:10 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=a0T5y9f4; spf=pass (domain: intel.com, ip: 134.134.136.31, mailfrom: foster.nong@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1665542230; x=1697078230; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6xhdzl1z7ZkXfY4ZJ10a6UH5gyMhoZEgApcV0J3fzgQ=; b=a0T5y9f4I8sTVft1jC0Lg31kb4mNEuTmPV8QdVGE+Wc7u765p4cJ+n8I 2siO09hlOBLZrjQClOGtMFoKbhmBFY2eshs4sVlonmmrFC4w2TGY09b13 yBsr2XZDEMnIny1VxKyv649OrEXnRktMUfaJKp9c0m8a6QUsoPlDwF0sa c/Fds1YlDpE/Y8GuOA5H7kfWVX1Yobg+gJKBAXa88FEdAUZdRNmrXX8An iEUMCDP+amD7Sk/acPSR+OPnWnuGm3JVSFJivzu5zKUfXRrbup81gNL8l HKAe1km18I3VvbWYwimBTQKsKer8HvS2LlcmUjO6Jcz898Bfa0f3H7sE2 A==; X-IronPort-AV: E=McAfee;i="6500,9779,10497"; a="366679157" X-IronPort-AV: E=Sophos;i="5.95,177,1661842800"; d="scan'208";a="366679157" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2022 19:37:09 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10497"; a="715751502" X-IronPort-AV: E=Sophos;i="5.95,177,1661842800"; d="scan'208";a="715751502" Received: from shwdeopenlab108.ccr.corp.intel.com ([10.239.56.147]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2022 19:37:08 -0700 From: Foster Nong To: devel@edk2.groups.io Cc: Foster Nong Subject: [PATCH v2 2/2] Fix bug on SRIOV ReservedBusNum when ARI enable. Date: Wed, 12 Oct 2022 10:36:56 +0800 Message-Id: <20221012023656.1565-2-foster.nong@intel.com> X-Mailer: git-send-email 2.37.1.windows.1 In-Reply-To: <20221012023656.1565-1-foster.nong@intel.com> References: <20221012023656.1565-1-foster.nong@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable If a device which support both features SR-IOV/ARI has multi functions, which maybe support 8-255. After enable ARI forwarding in the root port and ARI Capable Hierarchy in the SR-IOV PF0. The device will support and expose multi functions(0-255) with ARI ID routi= ng. In next device loop in below for() code, actually it still be in the same SR-IOV device, and just some PF which is over 8 or higher one(n*8), PciAllocateBusNumber() will allocate bus number(ReservedBusNum - TempReservedBusNum)) for this PF. if reset TempReservedBusNum as 0 in this case,it will allocate wrong bus number for this PF because TempReservedBusNum should be total previous PF's reserved bus numbers. code: for (Device =3D 0; Device <=3D PCI_MAX_DEVICE; Device++) { TempReservedBusNum =3D 0; for (Func =3D 0; Func <=3D PCI_MAX_FUNC; Func++) { // // Check to see whether a pci device is present // Status =3D PciDevicePresent ( PciRootBridgeIo, &Pci, StartBusNumber, Device, Func ); ... Status =3D PciAllocateBusNumber (PciDevice, *SubBusNumber, (UINT8)(PciDevice->ReservedBusNum - TempReservedBusNum), SubBusNumber); The solution is add a new flag IsAriEnabled to help handle this case. if ARI is enabled, then TempReservedBusNum will not be reset again during all functions(1-255) scan with checking flag IsAriEnabled. Signed-off-by: Foster Nong --- MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c | 1 + MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c | 19 +++++++++++++++= +++- MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.h | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c b/MdeMod= ulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c index bc20da1f38..8eca859695 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c @@ -2286,6 +2286,7 @@ CreatePciIoDevice ( &Data32=0D );=0D if ((Data32 & EFI_PCIE_CAPABILITY_DEVICE_CAPABILITIES_2_ARI_FORWARDI= NG) !=3D 0) {=0D + PciIoDevice->IsAriEnabled =3D TRUE;=0D //=0D // ARI forward support in bridge, so enable it.=0D //=0D diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c b/MdeModulePkg/Bus/Pci= /PciBusDxe/PciLib.c index d5e3ef4d3f..3a57c05755 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c @@ -1106,6 +1106,7 @@ PciScanBus ( EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo;=0D BOOLEAN BusPadding;=0D UINT32 TempReservedBusNum;=0D + BOOLEAN IsAriEnabled;=0D =0D PciRootBridgeIo =3D Bridge->PciRootBridgeIo;=0D SecondBus =3D 0;=0D @@ -1116,9 +1117,12 @@ PciScanBus ( BusPadding =3D FALSE;=0D PciDevice =3D NULL;=0D PciAddress =3D 0;=0D + IsAriEnabled =3D FALSE;=0D =0D for (Device =3D 0; Device <=3D PCI_MAX_DEVICE; Device++) {=0D - TempReservedBusNum =3D 0;=0D + if (!IsAriEnabled) {=0D + TempReservedBusNum =3D 0;=0D + }=0D for (Func =3D 0; Func <=3D PCI_MAX_FUNC; Func++) {=0D //=0D // Check to see whether a pci device is present=0D @@ -1157,6 +1161,19 @@ PciScanBus ( if (EFI_ERROR (Status)) {=0D continue;=0D }=0D + //=0D + // Per Pcie spec ARI Extended Capability=0D + // This capability must be implemented by each function in an ARI de= vice.=0D + // It is not applicable to a Root Port, a Switch Downstream Port, an= RCiEP, or a Root Complex Event Collector=0D + //=0D + if (((Device =3D=3D 0) && (Func =3D=3D 0)) && (PciDevice->IsAriEnabl= ed)) {=0D + IsAriEnabled =3D TRUE;=0D + }=0D + if (PciDevice->IsAriEnabled !=3D IsAriEnabled) {=0D + DEBUG ((DEBUG_ERROR, "ERROR: %02x:%02x:%02x device ARI Feature(%x)= is not consistent with others Function\n",=0D + StartBusNumber, Device, Func, PciDevice->IsAriEnabled));=0D + return EFI_DEVICE_ERROR;=0D + }=0D =0D PciAddress =3D EFI_PCI_ADDRESS (StartBusNumber, Device, Func, 0);=0D =0D diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.h b/MdeModulePkg/Bus/Pci= /PciBusDxe/PciBus.h index 4b58c3ea9b..ca5c06204d 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.h +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.h @@ -262,6 +262,7 @@ struct _PCI_IO_DEVICE { EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *BusNumberRanges;=0D =0D BOOLEAN IsPciExp;=0D + BOOLEAN IsAriEnabled;=0D //=0D // For SR-IOV=0D //=0D --=20 2.37.1.windows.1