Blame SOURCES/0001-efi-perform-cable-detection-at-NII-initialization-on-HPE-557SFP.patch

4c8dc9
From 2de005e9ac399f7064968a2611f266dc86a96700 Mon Sep 17 00:00:00 2001
4c8dc9
From: Laszlo Ersek <lersek@redhat.com>
4c8dc9
Date: Fri, 24 Jul 2020 19:15:28 +0200
4c8dc9
Subject: [PATCH] [efi] perform cable detection at NII initialization on HPE
4c8dc9
 557SFP+
4c8dc9
4c8dc9
Commit c0b61bad99ba ("[efi] Work around bugs in Emulex NII driver",
4c8dc9
2015-08-17) added PXE_OPFLAGS_INITIALIZE_DETECT_CABLE to nii_open() for
4c8dc9
working around Emulex NII driver bugs.
4c8dc9
4c8dc9
That broke some Mellanox drivers, so commit 6324227dcaa8 ("[efi] Skip
4c8dc9
cable detection at initialisation where possible", 2017-03-19) predicated
4c8dc9
PXE_OPFLAGS_INITIALIZE_DETECT_CABLE on the NII driver's *inability* to
4c8dc9
report link status.
4c8dc9
4c8dc9
This in turn breaks the NII driver on (some?) HPE 557SFP+ cards, as those
4c8dc9
drivers are capable of reporting link status, but they still need cable
4c8dc9
detection.
4c8dc9
4c8dc9
So check for this card (through PCI vendor / device / subsys vendor /
4c8dc9
subsys device identifiers), and opt for cable detection regardless of link
4c8dc9
status reporting.
4c8dc9
4c8dc9
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1740827
4c8dc9
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
4c8dc9
---
4c8dc9
 src/drivers/net/efi/nii.c | 43 ++++++++++++++++++++++++++++++++++++---
4c8dc9
 1 file changed, 40 insertions(+), 3 deletions(-)
4c8dc9
4c8dc9
diff --git a/src/drivers/net/efi/nii.c b/src/drivers/net/efi/nii.c
4c8dc9
index 2d87e0c63f14..0cf065e0818f 100644
4c8dc9
--- a/src/drivers/net/efi/nii.c
4c8dc9
+++ b/src/drivers/net/efi/nii.c
4c8dc9
@@ -193,6 +193,9 @@ struct nii_nic {
4c8dc9
 
4c8dc9
 	/** Mapping list */
4c8dc9
 	struct list_head mappings;
4c8dc9
+
4c8dc9
+	/** quirk needed for HPE 557SFP+ */
4c8dc9
+	int quirk_hpe557sfpp;
4c8dc9
 };
4c8dc9
 
4c8dc9
 /** Maximum number of received packets per poll */
4c8dc9
@@ -219,6 +222,7 @@ static int nii_pci_open ( struct nii_nic *nii ) {
4c8dc9
 	int bar;
4c8dc9
 	EFI_STATUS efirc;
4c8dc9
 	int rc;
4c8dc9
+	uint16_t vid, did, subsys_vid, subsys_did;
4c8dc9
 
4c8dc9
 	/* Locate PCI I/O protocol */
4c8dc9
 	if ( ( rc = efi_locate_device ( device, &efi_pci_io_protocol_guid,
4c8dc9
@@ -255,7 +259,7 @@ static int nii_pci_open ( struct nii_nic *nii ) {
4c8dc9
 			rc = -EEFI ( efirc );
4c8dc9
 			DBGC ( nii, "NII %s could not get BAR %d attributes: "
4c8dc9
 			       "%s\n", nii->dev.name, bar, strerror ( rc ) );
4c8dc9
-			goto err_get_bar_attributes;
4c8dc9
+			goto err_pci;
4c8dc9
 		}
4c8dc9
 		if ( desc.acpi->ResType == ACPI_ADDRESS_SPACE_TYPE_MEM ) {
4c8dc9
 			nii->mem_bar = bar;
4c8dc9
@@ -276,9 +280,36 @@ static int nii_pci_open ( struct nii_nic *nii ) {
4c8dc9
 		DBGC ( nii, "no I/O BAR\n" );
4c8dc9
 	}
4c8dc9
 
4c8dc9
+	/* Check if HPE 557SFP+ quirk is needed */
4c8dc9
+	if ( ( efirc = nii->pci_io->Pci.Read ( nii->pci_io,
4c8dc9
+					       EfiPciIoWidthUint16,
4c8dc9
+					       PCI_VENDOR_ID, 1,
4c8dc9
+					       &vid ) ) != 0 ||
4c8dc9
+	     ( efirc = nii->pci_io->Pci.Read ( nii->pci_io,
4c8dc9
+					       EfiPciIoWidthUint16,
4c8dc9
+					       PCI_DEVICE_ID, 1,
4c8dc9
+					       &did ) ) != 0 ||
4c8dc9
+	     ( efirc = nii->pci_io->Pci.Read ( nii->pci_io,
4c8dc9
+					       EfiPciIoWidthUint16,
4c8dc9
+					       PCI_SUBSYSTEM_VENDOR_ID, 1,
4c8dc9
+					       &subsys_vid ) ) != 0 ||
4c8dc9
+	     ( efirc = nii->pci_io->Pci.Read ( nii->pci_io,
4c8dc9
+					       EfiPciIoWidthUint16,
4c8dc9
+					       PCI_SUBSYSTEM_ID, 1,
4c8dc9
+					       &subsys_did ) ) != 0 ) {
4c8dc9
+		rc = -EEFI ( efirc );
4c8dc9
+		DBGC ( nii, "NII %s could not read PCI config space: %s\n",
4c8dc9
+		       nii->dev.name, strerror ( rc ) );
4c8dc9
+		goto err_pci;
4c8dc9
+	}
4c8dc9
+
4c8dc9
+	nii->quirk_hpe557sfpp = ( vid == 0x10df &&
4c8dc9
+				  did == 0x0720 &&
4c8dc9
+				  subsys_vid == 0x103c &&
4c8dc9
+				  subsys_did == 0x803f );
4c8dc9
 	return 0;
4c8dc9
 
4c8dc9
- err_get_bar_attributes:
4c8dc9
+ err_pci:
4c8dc9
 	bs->CloseProtocol ( pci_device, &efi_pci_io_protocol_guid,
4c8dc9
 			    efi_image_handle, device );
4c8dc9
  err_open:
4c8dc9
@@ -1144,8 +1175,14 @@ static int nii_open ( struct net_device *netdev ) {
4c8dc9
 	 * cable detection at this point if any only if the driver is
4c8dc9
 	 * not capable of reporting link status changes at runtime via
4c8dc9
 	 * PXE_OPCODE_GET_STATUS.
4c8dc9
+	 *
4c8dc9
+	 * HPE 557SFP+ seems to break with
4c8dc9
+	 * PXE_OPFLAGS_INITIALIZE_DO_NOT_DETECT_CABLE, but works with
4c8dc9
+	 * PXE_OPFLAGS_INITIALIZE_DETECT_CABLE, so ignore link status reporting
4c8dc9
+	 * for that NIC, and always request cable detection.
4c8dc9
 	 */
4c8dc9
-	flags = ( nii->media ? PXE_OPFLAGS_INITIALIZE_DO_NOT_DETECT_CABLE
4c8dc9
+	flags = ( ( ! nii->quirk_hpe557sfpp ) && nii->media
4c8dc9
+		  ? PXE_OPFLAGS_INITIALIZE_DO_NOT_DETECT_CABLE
4c8dc9
 		  : PXE_OPFLAGS_INITIALIZE_DETECT_CABLE );
4c8dc9
 	if ( ( rc = nii_initialise_flags ( nii, flags ) ) != 0 )
4c8dc9
 		goto err_initialise;
4c8dc9
4c8dc9
base-commit: b76052335788d0ad2c4b0bded116c3b02dd4bbc2
4c8dc9
-- 
4c8dc9
2.19.1.3.g30247aa5d201
4c8dc9