Blame SOURCES/0163-efinet-open-Simple-Network-Protocol-exclusively.patch

f731ee
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
f731ee
From: Andrei Borzenkov <arvidjaar@gmail.com>
f731ee
Date: Thu, 7 May 2015 20:37:17 +0300
f731ee
Subject: [PATCH] efinet: open Simple Network Protocol exclusively
f731ee
f731ee
EDK2 network stack is based on Managed Network Protocol which is layered
f731ee
on top of Simple Management Protocol and does background polling. This
f731ee
polling races with grub for received (and probably trasmitted) packets
f731ee
which causes either serious slowdown or complete failure to load files.
f731ee
f731ee
Open SNP device exclusively.  This destroys all child MNP instances and
f731ee
stops background polling.
f731ee
f731ee
Exclusive open cannot be done when enumerating cards, as it would destroy
f731ee
PXE information we need to autoconfigure interface; and it cannot be done
f731ee
during autoconfiguration as we need to do it for non-PXE boot as well. So
f731ee
move SNP open to card ->open method and add matching ->close to clean up.
f731ee
f731ee
Based on patch from Mark Salter <msalter@redhat.com>
f731ee
f731ee
Also-By: Mark Salter <msalter@redhat.com>
f731ee
Closes: 41731
f731ee
---
f731ee
 grub-core/net/drivers/efi/efinet.c | 46 ++++++++++++++++++++++++++++++++++++++
f731ee
 1 file changed, 46 insertions(+)
f731ee
f731ee
diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c
f731ee
index caa7b50228b..6a1dd1f9dff 100644
f731ee
--- a/grub-core/net/drivers/efi/efinet.c
f731ee
+++ b/grub-core/net/drivers/efi/efinet.c
f731ee
@@ -142,9 +142,55 @@ get_card_packet (struct grub_net_card *dev)
f731ee
   return nb;
f731ee
 }
f731ee
 
f731ee
+static grub_err_t
f731ee
+open_card (struct grub_net_card *dev)
f731ee
+{
f731ee
+  grub_efi_simple_network_t *net;
f731ee
+
f731ee
+  /* Try to reopen SNP exlusively to close any active MNP protocol instance
f731ee
+     that may compete for packet polling
f731ee
+   */
f731ee
+  net = grub_efi_open_protocol (dev->efi_handle, &net_io_guid,
f731ee
+				GRUB_EFI_OPEN_PROTOCOL_BY_EXCLUSIVE);
f731ee
+  if (net)
f731ee
+    {
f731ee
+      if (net->mode->state == GRUB_EFI_NETWORK_STOPPED
f731ee
+	  && efi_call_1 (net->start, net) != GRUB_EFI_SUCCESS)
f731ee
+	return grub_error (GRUB_ERR_NET_NO_CARD, "%s: net start failed",
f731ee
+			   dev->name);
f731ee
+
f731ee
+      if (net->mode->state == GRUB_EFI_NETWORK_STOPPED)
f731ee
+	return grub_error (GRUB_ERR_NET_NO_CARD, "%s: card stopped",
f731ee
+			   dev->name);
f731ee
+
f731ee
+      if (net->mode->state == GRUB_EFI_NETWORK_STARTED
f731ee
+	  && efi_call_3 (net->initialize, net, 0, 0) != GRUB_EFI_SUCCESS)
f731ee
+	return grub_error (GRUB_ERR_NET_NO_CARD, "%s: net initialize failed",
f731ee
+			   dev->name);
f731ee
+
f731ee
+      efi_call_4 (grub_efi_system_table->boot_services->close_protocol,
f731ee
+		  dev->efi_net, &net_io_guid,
f731ee
+		  grub_efi_image_handle, dev->efi_handle);
f731ee
+      dev->efi_net = net;
f731ee
+    }
f731ee
+
f731ee
+  /* If it failed we just try to run as best as we can */
f731ee
+  return GRUB_ERR_NONE;
f731ee
+}
f731ee
+
f731ee
+static void
f731ee
+close_card (struct grub_net_card *dev)
f731ee
+{
f731ee
+  efi_call_4 (grub_efi_system_table->boot_services->close_protocol,
f731ee
+	      dev->efi_net, &net_io_guid,
f731ee
+	      grub_efi_image_handle, dev->efi_handle);
f731ee
+}
f731ee
+
f731ee
 static struct grub_net_card_driver efidriver =
f731ee
   {
f731ee
     .name = "efinet",
f731ee
+    .open = open_card,
f731ee
+    .close = close_card,
f731ee
     .send = send_card_buffer,
f731ee
     .recv = get_card_packet
f731ee
   };