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

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