Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6F417C352A1 for ; Wed, 7 Dec 2022 08:57:35 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0E83A8554D; Wed, 7 Dec 2022 09:55:05 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="HAfT9vfw"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8FF48855B0; Wed, 7 Dec 2022 09:54:55 +0100 (CET) Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id A5EE185565 for ; Wed, 7 Dec 2022 09:54:51 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-pl1-x62d.google.com with SMTP id p24so16439704plw.1 for ; Wed, 07 Dec 2022 00:54:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nyRaz94Legd5Udzb8UIor01QGV9ooC2AY8LwPJf8OaE=; b=HAfT9vfwZSurSJdNUe/aIYS84emplYxxMnwn90ta+oI5Bge1Y1kh/gTQNpXTFXhQfd noMQTUH8tPRnjwX+HXWlhmZEK/ZPOPsbYF3BGr232oypn7cNQdCdgDOV/hePCy4ts21h SrQGfRYVHXaM681TPGzxedyXeUfWyn0pIYJfc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nyRaz94Legd5Udzb8UIor01QGV9ooC2AY8LwPJf8OaE=; b=IrLGBbWZErPvoSxA+6V20pX2PkAL3QMcQW6/CakX8/f2KvYZ7Anbt6M+taPnYrlgwm lyjyrP7A4mAW2EVwqXFmOqakgWmuFlbES99xI9wm4zGmcXKhVCroOMe/kS4yJYqCy2/s vdXJhpv1/V/97mIhz1EJrHDu703S9OR9uewcnxyFBhk1PhZb2Y+aS87M+YCG9yr1mlfN 2TNgafhEFKTdbVugV3kw0HGnv3owbik+FMxKhb13czhv0nw+aJWu87MX/aKc09ZUs5GR gMYL1IfUxpMX+5Ek43Cvq1JH7bqbGRoWAwprncem+ktkV3LOOLvaUn0SJXwSIz5Buz7Y yIDg== X-Gm-Message-State: ANoB5pn1X25pGLtesDzngfu1FwULIjn8ylA6Y9hoWBFIYFNIVsYv9xPh 6/isMA3j5He3iugc9AXX7ASWeS6zB8Y0qNyw X-Google-Smtp-Source: AA0mqf4/cZPp4nlhhPSC/3D8KobdtFpR8lFkxYnmhtFI3+9TaZbUr0jd/yPvr5qZF4RBstHIFadXrw== X-Received: by 2002:a17:90a:bd01:b0:21a:557:bb72 with SMTP id y1-20020a17090abd0100b0021a0557bb72mr5695954pjr.46.1670403288915; Wed, 07 Dec 2022 00:54:48 -0800 (PST) Received: from localhost.localdomain ([27.110.126.54]) by smtp.gmail.com with ESMTPSA id l16-20020a170903121000b0018157b415dbsm14145514plh.63.2022.12.07.00.54.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Dec 2022 00:54:48 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: U-Boot Custodians , Simon Glass , Heinrich Schuchardt , Joe Hershberger , =?UTF-8?q?Pali=20Roh=C3=A1r?= , Ramon Fried , Stefan Roese Subject: [PATCH 17/71] sandbox: Allow ethernet to be disabled at runtime Date: Wed, 7 Dec 2022 21:50:43 +1300 Message-Id: <20221207085137.445249-18-sjg@chromium.org> X-Mailer: git-send-email 2.39.0.rc0.267.gcb52ba06e7-goog In-Reply-To: <20221207085137.445249-1-sjg@chromium.org> References: <20221207085137.445249-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean For bootstd tests it is seldom useful to have ethernet enabled. Add a way to disable it, so that ethernet operations like tftpboot do nothing. Signed-off-by: Simon Glass --- arch/sandbox/cpu/state.c | 16 ++++++++++++++++ arch/sandbox/include/asm/state.h | 1 + arch/sandbox/include/asm/test.h | 16 ++++++++++++++++ include/test/test.h | 25 +++++++++++++++++++++++++ net/net.c | 4 ++++ 5 files changed, 62 insertions(+) diff --git a/arch/sandbox/cpu/state.c b/arch/sandbox/cpu/state.c index a681e472ab6..76e65741424 100644 --- a/arch/sandbox/cpu/state.c +++ b/arch/sandbox/cpu/state.c @@ -12,6 +12,7 @@ #include #include #include +#include /* Main state record for the sandbox */ static struct sandbox_state main_state; @@ -366,6 +367,7 @@ void state_reset_for_test(struct sandbox_state *state) state->sysreset_allowed[SYSRESET_POWER_OFF] = true; state->sysreset_allowed[SYSRESET_COLD] = true; state->allow_memio = false; + sandbox_set_eth_enable(true); memset(&state->wdt, '\0', sizeof(state->wdt)); memset(state->spi, '\0', sizeof(state->spi)); @@ -444,6 +446,20 @@ int state_load_other_fdt(const char **bufp, int *sizep) return 0; } +void sandbox_set_eth_enable(bool enable) +{ + struct sandbox_state *state = state_get_current(); + + state->disable_eth = !enable; +} + +bool sandbox_eth_enabled(void) +{ + struct sandbox_state *state = state_get_current(); + + return !state->disable_eth; +} + int state_init(void) { state = &main_state; diff --git a/arch/sandbox/include/asm/state.h b/arch/sandbox/include/asm/state.h index 49ea483d332..f125fb87af7 100644 --- a/arch/sandbox/include/asm/state.h +++ b/arch/sandbox/include/asm/state.h @@ -96,6 +96,7 @@ struct sandbox_state { const char *select_unittests; /* Unit test to run */ bool handle_signals; /* Handle signals within sandbox */ bool autoboot_keyed; /* Use keyed-autoboot feature */ + bool disable_eth; /* Disable Ethernet devices */ /* Pointer to information for each SPI bus/cs */ struct sandbox_spi_info spi[CONFIG_SANDBOX_SPI_MAX_BUS] diff --git a/arch/sandbox/include/asm/test.h b/arch/sandbox/include/asm/test.h index 568738c16d5..1c522e38f3d 100644 --- a/arch/sandbox/include/asm/test.h +++ b/arch/sandbox/include/asm/test.h @@ -344,4 +344,20 @@ void sandbox_set_fake_efi_mgr_dev(struct udevice *dev, bool fake_dev); */ int sandbox_load_other_fdt(void **fdtp, int *sizep); +/** + * sandbox_set_eth_enable() - Enable / disable Ethernet + * + * Allows control of whether Ethernet packets are actually send/received + * + * @enable: true to enable Ethernet, false to disable + */ +void sandbox_set_eth_enable(bool enable); + +/** + * sandbox_eth_enabled() - Check if Ethernet is enabled + * + * Returns: true if Ethernet is enabled on sandbox, False if not + */ +bool sandbox_eth_enabled(void); + #endif diff --git a/include/test/test.h b/include/test/test.h index 4ad74614afc..76ec4d739a3 100644 --- a/include/test/test.h +++ b/include/test/test.h @@ -169,4 +169,29 @@ static inline int test_load_other_fdt(struct unit_test_state *uts) return ret; } +/** + * test_set_eth_enable() - Enable / disable Ethernet + * + * Allows control of whether Ethernet packets are actually send/received + * + * @enable: true to enable Ethernet, false to disable + */ +static inline void test_set_eth_enable(bool enable) +{ +#ifdef CONFIG_SANDBOX + sandbox_set_eth_enable(enable); +#endif +} + +/* Allow ethernet to be disabled for testing purposes */ +static inline bool test_eth_enabled(void) +{ + bool enabled = true; + +#ifdef CONFIG_SANDBOX + enabled = sandbox_eth_enabled(); +#endif + return enabled; +} + #endif /* __TEST_TEST_H */ diff --git a/net/net.c b/net/net.c index 1c39acc4936..8f7d3c3b305 100644 --- a/net/net.c +++ b/net/net.c @@ -106,6 +106,7 @@ #endif #include #include +#include #include "arp.h" #include "bootp.h" #include "cdp.h" @@ -465,6 +466,9 @@ restart: debug_cond(DEBUG_INT_STATE, "--- net_loop Init\n"); net_init_loop(); + if (!test_eth_enabled()) + return 0; + switch (net_check_prereq(protocol)) { case 1: /* network not configured */ -- 2.39.0.rc0.267.gcb52ba06e7-goog