Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 2 Feb 2016 10:39:19 +0000 (UTC)
From:      Andrew Turner <andrew@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r295144 - head/sys/boot/efi/libefi
Message-ID:  <201602021039.u12AdJxt066072@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: andrew
Date: Tue Feb  2 10:39:18 2016
New Revision: 295144
URL: https://svnweb.freebsd.org/changeset/base/295144

Log:
  Add suppor to loader.efi to load files off hte network. For this we need
  to open the device in exclusive mode as, without this, the firmware may
  also be reading packets off the interface leading to a race.
  
  Reviewed by:	emaste
  Sponsored by:	ABT Systems Ltd
  Differential Revision:	https://reviews.freebsd.org/D4132

Modified:
  head/sys/boot/efi/libefi/efinet.c

Modified: head/sys/boot/efi/libefi/efinet.c
==============================================================================
--- head/sys/boot/efi/libefi/efinet.c	Tue Feb  2 10:32:45 2016	(r295143)
+++ head/sys/boot/efi/libefi/efinet.c	Tue Feb  2 10:39:18 2016	(r295144)
@@ -184,11 +184,16 @@ efinet_init(struct iodesc *desc, void *m
 	EFI_HANDLE h;
 	EFI_STATUS status;
 
+	if (nif->nif_driver->netif_ifs[nif->nif_unit].dif_unit < 0) {
+		printf("Invalid network interface %d\n", nif->nif_unit);
+		return;
+	}
+
 	h = nif->nif_driver->netif_ifs[nif->nif_unit].dif_private;
 	status = BS->HandleProtocol(h, &sn_guid, (VOID **)&nif->nif_devdata);
 	if (status != EFI_SUCCESS) {
-		printf("net%d: cannot start interface (status=%ld)\n",
-		    nif->nif_unit, (long)status);
+		printf("net%d: cannot start interface (status=%lu)\n",
+		    nif->nif_unit, EFI_ERROR_CODE(status));
 		return;
 	}
 
@@ -288,11 +293,30 @@ efinet_dev_init()
 	stats = calloc(nifs, sizeof(struct netif_stats));
 
 	for (i = 0; i < nifs; i++) {
+		EFI_SIMPLE_NETWORK *net;
+		EFI_HANDLE h;
+
 		dif = &efinetif.netif_ifs[i];
+		dif->dif_unit = -1;
+
+		h = efi_find_handle(&efinet_dev, i);
+
+		/*
+		 * Open the network device in exclusive mode. Without this
+		 * we will be racing with the UEFI network stack. It will
+		 * pull packets off the network leading to lost packets.
+		 */
+		status = BS->OpenProtocol(h, &sn_guid, (void **)&net,
+		    IH, 0, EFI_OPEN_PROTOCOL_EXCLUSIVE);
+		if (status != EFI_SUCCESS) {
+			printf("Unable to open network interface %d\n", i);
+			continue;
+		}
+
 		dif->dif_unit = i;
 		dif->dif_nsel = 1;
 		dif->dif_stats = &stats[i];
-		dif->dif_private = efi_find_handle(&efinet_dev, i);
+		dif->dif_private = h;
 	}
 
 	return (0);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201602021039.u12AdJxt066072>