Hi,

Update: I also rewrite the send_card_buffer function. Also add support
for tftp_block_size environment variable which allows user to specify
customized block size (default is 8192).

for example:

set tftp_block_size=16384
testspeed (tftp)/imagefile

When testing in virtual machine, try not to set block size too high
since it could cause timeouts, this is not an issue for real machine
since it normally have more nic buffer.

-- 
Best wishes
Bean
=== modified file 'grub-core/net/drivers/efi/efinet.c'
--- grub-core/net/drivers/efi/efinet.c  2012-03-10 19:41:28 +0000
+++ grub-core/net/drivers/efi/efinet.c  2012-04-29 14:44:08 +0000
@@ -36,22 +36,55 @@
 {
   grub_efi_status_t st;
   grub_efi_simple_network_t *net = dev->efi_net;
-  grub_uint64_t limit_time = grub_get_time_ms () + 4000;
-  st = efi_call_7 (net->transmit, net, 0, (pack->tail - pack->data),
-                  pack->data, NULL, NULL, NULL);
-  if (st != GRUB_EFI_SUCCESS)
-    return grub_error (GRUB_ERR_IO, N_("couldn't send network packet"));
-  while (1)
+  grub_uint32_t int_status;
+  int i;
+
+  for (i = 0; i < 3; i++)
     {
+      grub_uint64_t limit_time;      
+      
+      efi_call_3 (net->get_status, net, &int_status, 0);
+
+      limit_time = grub_get_time_ms () + 5;
+      for (;;)
+       {
+         st = efi_call_7 (net->transmit, net, 0, (pack->tail - pack->data),
+                          pack->data, NULL, NULL, NULL);
+         if (st != GRUB_EFI_NOT_READY)
+           break;
+
+         if (limit_time < grub_get_time_ms ())
+           {
+             st = GRUB_EFI_TIMEOUT;
+             break;
+           }
+       }
+
+      if (st)
+       goto quit;
+
       void *txbuf = NULL;
-      st = efi_call_3 (net->get_status, net, 0, &txbuf);
-      if (st != GRUB_EFI_SUCCESS)
-       return grub_error (GRUB_ERR_IO, N_("couldn't send network packet"));
-      if (txbuf)
-       return GRUB_ERR_NONE;
-      if (limit_time < grub_get_time_ms ())
-       return grub_error (GRUB_ERR_TIMEOUT, N_("couldn't send network 
packet"));
+      limit_time = grub_get_time_ms () + 5;
+      for (;;)
+       {                 
+         st = efi_call_3 (net->get_status, net, &int_status, &txbuf);
+
+         if (txbuf != NULL)
+           break;
+
+         if (limit_time < grub_get_time_ms ())
+           {
+             st = GRUB_EFI_TIMEOUT;
+             break;
+           }
+       }
+
+    quit:
+      if (st != GRUB_EFI_TIMEOUT)
+       break;
     }
+
+  return st;
 }
 
 static struct grub_net_buff *
@@ -63,14 +96,13 @@
   grub_efi_uintn_t bufsize = 1536;
   struct grub_net_buff *nb;
 
-  nb = grub_netbuff_alloc (bufsize);
+  nb = grub_netbuff_alloc (bufsize + 2);
   if (!nb)
     return NULL;
 
   /* Reserve 2 bytes so that 2 + 14/18 bytes of ethernet header is divisible
      by 4. So that IP header is aligned on 4 bytes. */
-  grub_netbuff_reserve (nb, 2);
-  if (!nb)
+  if (grub_netbuff_reserve (nb, 2))
     {
       grub_netbuff_free (nb);
       return NULL;
@@ -84,14 +116,13 @@
 
       bufsize = ALIGN_UP (bufsize, 32);
 
-      nb = grub_netbuff_alloc (bufsize);
+      nb = grub_netbuff_alloc (bufsize + 2);
       if (!nb)
        return NULL;
 
       /* Reserve 2 bytes so that 2 + 14/18 bytes of ethernet header is 
divisible
         by 4. So that IP header is aligned on 4 bytes. */
-      grub_netbuff_reserve (nb, 2);
-      if (!nb)
+      if (grub_netbuff_reserve (nb, 2))
        {
          grub_netbuff_free (nb);
          return NULL;

=== modified file 'grub-core/net/tftp.c'
--- grub-core/net/tftp.c        2012-02-12 18:11:06 +0000
+++ grub-core/net/tftp.c        2012-04-29 14:31:12 +0000
@@ -27,6 +27,7 @@
 #include <grub/file.h>
 #include <grub/priority_queue.h>
 #include <grub/i18n.h>
+#include <grub/env.h>
 
 GRUB_MOD_LICENSE ("GPLv3+");
 
@@ -288,6 +289,7 @@
   grub_err_t err;
   grub_uint8_t *nbd;
   grub_net_network_level_address_t addr;
+  const char *block_size;
 
   data = grub_zalloc (sizeof (*data));
   if (!data)
@@ -320,9 +322,12 @@
   rrqlen += grub_strlen ("blksize") + 1;
   rrq += grub_strlen ("blksize") + 1;
 
-  grub_strcpy (rrq, "1024");
-  rrqlen += grub_strlen ("1024") + 1;
-  rrq += grub_strlen ("1024") + 1;
+  block_size = grub_env_get ("tftp_block_size");
+  if (block_size == NULL)
+    block_size = "8192";
+  grub_strcpy (rrq, block_size);
+  rrqlen += grub_strlen (block_size) + 1;
+  rrq += grub_strlen (block_size) + 1;
 
   grub_strcpy (rrq, "tsize");
   rrqlen += grub_strlen ("tsize") + 1;

_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to