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

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