Blame SOURCES/0158-efinet-Check-for-immediate-completition.patch

f731ee
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
f731ee
From: Martin Wilck <martin.wilck@ts.fujitsu.com>
f731ee
Date: Fri, 27 Mar 2015 14:27:56 +0100
f731ee
Subject: [PATCH] efinet: Check for immediate completition.
f731ee
f731ee
This both speeds GRUB up and workarounds unexpected EFI behaviour.
f731ee
---
f731ee
 grub-core/net/drivers/efi/efinet.c | 16 ++++++++++++++--
f731ee
 1 file changed, 14 insertions(+), 2 deletions(-)
f731ee
f731ee
diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c
f731ee
index a6e4c7992f7..78df215be12 100644
f731ee
--- a/grub-core/net/drivers/efi/efinet.c
f731ee
+++ b/grub-core/net/drivers/efi/efinet.c
f731ee
@@ -37,11 +37,12 @@ send_card_buffer (struct grub_net_card *dev,
f731ee
   grub_efi_status_t st;
f731ee
   grub_efi_simple_network_t *net = dev->efi_net;
f731ee
   grub_uint64_t limit_time = grub_get_time_ms () + 4000;
f731ee
+  void *txbuf;
f731ee
 
f731ee
   if (dev->txbusy)
f731ee
     while (1)
f731ee
       {
f731ee
-	void *txbuf = NULL;
f731ee
+	txbuf = NULL;
f731ee
 	st = efi_call_3 (net->get_status, net, 0, &txbuf);
f731ee
 	if (st != GRUB_EFI_SUCCESS)
f731ee
 	  return grub_error (GRUB_ERR_IO,
f731ee
@@ -74,7 +75,18 @@ send_card_buffer (struct grub_net_card *dev,
f731ee
 		   dev->txbuf, NULL, NULL, NULL);
f731ee
   if (st != GRUB_EFI_SUCCESS)
f731ee
     return grub_error (GRUB_ERR_IO, N_("couldn't send network packet"));
f731ee
-  dev->txbusy = 1;
f731ee
+
f731ee
+  /*
f731ee
+     The card may have sent out the packet immediately - set txbusy
f731ee
+     to 0 in this case.
f731ee
+     Cases were observed where checking txbuf at the next call
f731ee
+     of send_card_buffer() is too late: 0 is returned in txbuf and
f731ee
+     we run in the GRUB_ERR_TIMEOUT case above.
f731ee
+     Perhaps a timeout in the FW has discarded the recycle buffer.
f731ee
+   */
f731ee
+  st = efi_call_3 (net->get_status, net, 0, &txbuf);
f731ee
+  dev->txbusy = !(st == GRUB_EFI_SUCCESS && txbuf == dev->txbuf);
f731ee
+
f731ee
   return GRUB_ERR_NONE;
f731ee
 }
f731ee