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 696C0C63797 for ; Sun, 8 Jan 2023 02:55:31 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 220DF856C0; Sun, 8 Jan 2023 03:52:34 +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="UzQuVwJL"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6692D856C3; Sun, 8 Jan 2023 03:52:01 +0100 (CET) Received: from mail-il1-x130.google.com (mail-il1-x130.google.com [IPv6:2607:f8b0:4864:20::130]) (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 60A958562A for ; Sun, 8 Jan 2023 03:51:11 +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-il1-x130.google.com with SMTP id c20so3284445ilj.10 for ; Sat, 07 Jan 2023 18:51:11 -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=DoWcwJ6+5gXE2AGBWR+dNE2WU159yLgrJNQLhxZlUMA=; b=UzQuVwJLdg7nVLKxBRqFcrIWqaNwU3/0ZR3eDRms2fPEfajL42fBrInFu8GxcTSz1e 0k7dfCZyaXV+OopjIqTL6q+CuYkqroeFYe8RTW/v8aJAJ+yR98VTPSUEn1SJwLYhM8Zl uajnZxszHdV0jqj7anpwh1OTdHr1BFxieEFqc= 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=DoWcwJ6+5gXE2AGBWR+dNE2WU159yLgrJNQLhxZlUMA=; b=4hzkAsFTS4EoeiXHVokXyTM53QtZJYiMYhGXJMbNcYixdIzT/U16a0IyyTaDGyX22R xYUZU3aDULC0MbJVnTKhM2d4MKmFr8zwt/8Lb2zf8XRUX+acX4RbZ7ofCsW/jZli0CjA KbXWanAYDThBERSMfT7OUStRenv9Y3+bZAULlSVgWiOf73ykqM4gnAoms1gNpRud0Lef 7289MHM7uwpYyknutjOM7IBa9Sjdo/hh6pUhO+OSgNHYpP8qAD6a/6WpX0Ob4OWAeyLU m4UQNTFX/ffRXJ0G7cc+yVb9lnDNprAsQiq0Nw6eQ7yufHxxsULt2AkPBd484tstd4PE kI/A== X-Gm-Message-State: AFqh2kpI5evjnT8R5i7+6PdYRGxLr8SHzN7+dAWnnVtsDZv1eO5o2ebc wwT5VMB7VsU3ZB3rWo9nsmdV6sEwZYyKEcD0 X-Google-Smtp-Source: AMrXdXvl9GzVir1fjlQmxPENj7DCfa4uHFKBC/Dm5xyUzTbHxiVV36ne7KY6msu9Q+F9J5Vb/Rj2MA== X-Received: by 2002:a92:c90b:0:b0:302:392c:5878 with SMTP id t11-20020a92c90b000000b00302392c5878mr41044662ilp.13.1673146270876; Sat, 07 Jan 2023 18:51:10 -0800 (PST) Received: from sjg1.roam.corp.google.com (c-71-56-217-229.hsd1.co.comcast.net. [71.56.217.229]) by smtp.gmail.com with ESMTPSA id c17-20020a92bd11000000b00302a00aaefasm1622174ile.26.2023.01.07.18.51.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Jan 2023 18:51:10 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: U-Boot Custodians , Simon Glass Subject: [PATCH v2 17/71] sandbox: Allow ethernet to be disabled at runtime Date: Sat, 7 Jan 2023 19:49:53 -0700 Message-Id: <20230108025047.522240-18-sjg@chromium.org> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog In-Reply-To: <20230108025047.522240-1-sjg@chromium.org> References: <20230108025047.522240-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 --- (no changes since v1) 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 57da9bda85a..c9a749f6cc8 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.314.g84b9a713c41-goog