Received: from list by lists.gnu.org with archive (Exim 4.71) id 1ZNPJ2-0008Hl-8O for mharc-grub-devel@gnu.org; Thu, 06 Aug 2015 13:50:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35890) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZNPIx-0008F0-C5 for grub-devel@gnu.org; Thu, 06 Aug 2015 13:50:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZNPIs-0002c3-DC for grub-devel@gnu.org; Thu, 06 Aug 2015 13:50:11 -0400 Received: from 66-220-155-178.intmwg.facebook.com ([66.220.155.178]:13335 helo=mx-out.facebook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZNPIs-0002bQ-9l for grub-devel@gnu.org; Thu, 06 Aug 2015 13:50:06 -0400 Received: from facebook.com (2401:db00:2040:5012:face:0:9:0) by mx-out.facebook.com (10.223.100.97) with ESMTP id 924b9d1c3c6311e5bd7824be0593f280-d73f32b0 for ; Thu, 06 Aug 2015 10:50:05 -0700 Received: by devbig041.ash4.facebook.com (Postfix, from userid 8730) id C338D4542063; Thu, 6 Aug 2015 10:50:05 -0700 (PDT) From: Josef Bacik To: grub-devel@gnu.org, arvidjaar@gmail.com, phcoder@gmail.com Subject: [PATCH V2] efinet: handle get_status() on buggy firmware properly Date: Thu, 6 Aug 2015 10:49:46 -0700 Message-Id: <1438883386-3043513-1-git-send-email-jbacik@fb.com> X-Mailer: git-send-email 1.8.1 In-Reply-To: <1438799799-32097-1-git-send-email-jbacik@fb.com> References: <1438799799-32097-1-git-send-email-jbacik@fb.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 66.220.155.178 Cc: Josef Bacik X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 06 Aug 2015 17:50:12 -0000 The EFI spec indicates that get_status() should return the address of the buffer we passed into transmit to indicate the the buffer was transmitted. However we have boxes where the firmware returns some arbitrary address instead, which makes grub think that we've not sent anything. So since we have the SNP stuff opened in exclusive mode just assume any non-NULL txbuf means that our transmit occurred properly. This makes grub able to do its networking stuff properly on our broken firmware. Thanks, cc: Peter Jones Signed-off-by: Josef Bacik --- V1->V2: -updated the changelog to be more clear about what we are fixing. -added a comment to the code to indicate why it is safe to only check for non-NULL txbufs and why we need to do it. grub-core/net/drivers/efi/efinet.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c index f27a117..692d5ad 100644 --- a/grub-core/net/drivers/efi/efinet.c +++ b/grub-core/net/drivers/efi/efinet.c @@ -47,19 +47,19 @@ send_card_buffer (struct grub_net_card *dev, if (st != GRUB_EFI_SUCCESS) return grub_error (GRUB_ERR_IO, N_("couldn't send network packet")); - if (txbuf == dev->txbuf) + /* + Some buggy firmware could return an arbitrary address instead of the + txbuf address we trasmitted, so just check that txbuf is non NULL + for success. This is ok because we open the SNP protocol in + exclusive mode so we know we're the only ones transmitting on this + box and since we only transmit one packet at a time we know our + transmit was successfull. + */ + if (txbuf) { dev->txbusy = 0; break; } - if (txbuf) - { - st = efi_call_7 (net->transmit, net, 0, dev->last_pkt_size, - dev->txbuf, NULL, NULL, NULL); - if (st != GRUB_EFI_SUCCESS) - return grub_error (GRUB_ERR_IO, - N_("couldn't send network packet")); - } if (limit_time < grub_get_time_ms ()) return grub_error (GRUB_ERR_TIMEOUT, N_("couldn't send network packet")); @@ -84,8 +84,9 @@ send_card_buffer (struct grub_net_card *dev, we run in the GRUB_ERR_TIMEOUT case above. Perhaps a timeout in the FW has discarded the recycle buffer. */ + txbuf = NULL; st = efi_call_3 (net->get_status, net, 0, &txbuf); - dev->txbusy = !(st == GRUB_EFI_SUCCESS && txbuf == dev->txbuf); + dev->txbusy = !(st == GRUB_EFI_SUCCESS && txbuf); return GRUB_ERR_NONE; } -- 1.8.1