git: 48b29e9e54c5 - main - loader.efi: Retain standalone network configuration

From: Krzysztof Galazka <kgalazka_at_FreeBSD.org>
Date: Tue, 29 Sep 2026 19:57:14 UTC
The branch main has been updated by kgalazka:

URL: https://cgit.FreeBSD.org/src/commit/?id=48b29e9e54c592767fa363237e9837c90c8d7ccd

commit 48b29e9e54c592767fa363237e9837c90c8d7ccd
Author:     Krzysztof Galazka <kgalazka@FreeBSD.org>
AuthorDate: 2026-09-29 19:56:43 +0000
Commit:     Krzysztof Galazka <kgalazka@FreeBSD.org>
CommitDate: 2026-09-29 19:56:48 +0000

    loader.efi: Retain standalone network configuration
    
    DHCP initmd discovery used net_configure() to open and configure SNP,
    then immediately closed the socket and released the protocol.
    Selecting net0 as currdev subsequently required another exclusive
    SNP attach, which may hang on some EDK II firmware.
    
    Keep the configured socket available for ordinary network consumers
    so NFS boot can reuse it. Add an explicit deconfiguration operation
    and invoke it only when an initmd URL requires handing SNP back
    to the firmware network stack.
    
    Signed-off-by: Krzysztof Galazka <krzysztof.galazka@intel.com>
    
    Reviewed by:    imp
    Assisted by:    Github Copilot (GPT-5.6 Sol)
    Sponsored by:   Intel Corporation
    Differential Revision:  https://reviews.freebsd.org/D59999
---
 stand/common/dev_net.c     | 33 +++++++++++++++++++++++++++------
 stand/common/dev_net.h     |  1 +
 stand/efi/loader/memdisk.c |  2 ++
 3 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/stand/common/dev_net.c b/stand/common/dev_net.c
index aecb5bcde81c..3c13ad99ec5a 100644
--- a/stand/common/dev_net.c
+++ b/stand/common/dev_net.c
@@ -176,21 +176,42 @@ net_open(struct open_file *f, ...)
 int
 net_configure(struct devdesc *dev)
 {
-	int error, sock;
+	int error;
 
-	sock = netif_open(dev);
-	if (sock < 0)
+	if (netdev_sock >= 0)
+		return (0);
+
+	netdev_sock = netif_open(dev);
+	if (netdev_sock < 0)
 		return (ENXIO);
 
 	error = 0;
 	if (rootip.s_addr == 0)
-		error = net_getparams(sock);
+		error = net_getparams(netdev_sock);
 	if (error == 0)
-		net_setparams(sock);
-	netif_close(sock);
+		net_setparams(netdev_sock);
+	if (error != 0) {
+		netif_close(netdev_sock);
+		netdev_sock = -1;
+		return (error);
+	}
+
+	netdev_name = strdup(dev->d_dev->dv_name);
+	if (netdev_name == NULL) {
+		netif_close(netdev_sock);
+		netdev_sock = -1;
+		return (ENOMEM);
+	}
 	return (error);
 }
 
+void
+net_deconfigure(void)
+{
+
+	net_cleanup();
+}
+
 static int
 net_close(struct open_file *f)
 {
diff --git a/stand/common/dev_net.h b/stand/common/dev_net.h
index 5cf6652c96af..a216f745e219 100644
--- a/stand/common/dev_net.h
+++ b/stand/common/dev_net.h
@@ -30,6 +30,7 @@
 extern struct devsw netdev;
 
 int net_configure(struct devdesc *);
+void net_deconfigure(void);
 uint32_t net_parse_rootpath(void);
 
 #endif
diff --git a/stand/efi/loader/memdisk.c b/stand/efi/loader/memdisk.c
index 8990f9393e85..6a4fb5b31f45 100644
--- a/stand/efi/loader/memdisk.c
+++ b/stand/efi/loader/memdisk.c
@@ -245,6 +245,8 @@ maybe_download_initmd(void)
 	if (url == NULL || *url == '\0')
 		return;
 
+	/* Release SNP so the firmware network stack can fetch the image. */
+	net_deconfigure();
 	printf("Downloading initmd from %s\n", url);
 	error = download_md_image(url);
 	if (error != 0 && error != ECANCELED)