From patchwork Thu Mar 6 14:25:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 870822 Delivered-To: patch@linaro.org Received: by 2002:ab3:6e57:0:b0:290:25b2:841c with SMTP id w23csp455585ltm; Thu, 6 Mar 2025 06:26:16 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVi+fGKUPJuWf42J3JhIeBuE9wPwPj2MmVzfeUutewWtan1NX/uB4+IfmhAcfV76lwEJYnvlQ==@linaro.org X-Google-Smtp-Source: AGHT+IEGUlysyAQx8Qsv6e+muNKyWQfUQB/RP6fgw1MFjTboi1vvqb41LCFcOL6DrMnFm8cB53jb X-Received: by 2002:a17:90b:4a87:b0:2ff:682b:b759 with SMTP id 98e67ed59e1d1-2ff682bb96amr3910728a91.7.1741271175841; Thu, 06 Mar 2025 06:26:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1741271175; cv=none; d=google.com; s=arc-20240605; b=LS+bLENsaPueM+4CWWQ4O0SBkC5lpnyPXFIG6cRX8IB/338h490cHaqYHKKKMFko2B qY2x0v1mtiT7ExwcWMz7x3QrSmFfjUZ1FT1ueCIVypJtF2HagyzTnuwlGA+sPMbjcgib FKSudtkh8O6YD+AuT4NoIIUceqW96rdeQEePAeU3daLdbZX22PF+tsfBk6EzspAF3vQ0 YyuZE49FTTB0wrjTe0K+OVS8k12ugJ19WxqMmvpGsAfOcSJqNTV1e+tzpJev7uHmv1iF GovEfkchDr98X9pl6H8JclEomLeBbsv0KZmG0jhWQR4uiaLdgK1nmSm2zYi8mK9uz7It iNxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Ue63HpIL4s7nmj4eEoqQjm3Hf7Q+UiOFHWN8tEEsJfA=; fh=HaKHCOHL46OAAPpM3W6HDLkDmJxXWc+qggc/xnkS9u8=; b=NEItdIRGasO6XiRgaU4HKB5mDYg0ptBR4mhUmJ0lZdNPoBkgn1HQYVPUbLO3zKfD1L 5Ams5oyKQgf3GGB9PHHdC4NgdrrtC/+xmGER3eecjosNqAQCZ71EPgJno/ID8zC+eGWi I+tiTQs35V23zcrVcBBrevMrah3rICmRA6sc+j9I1lwTm9RE4ycAGYgs2DS6UJb0yyKr AvUbayL0vwStMwoQdaMxEaoAJG3AgyK2KMJVyKCw5j2GhG/PBu/FAP/jAKC7DSMlXmTU mrGa3XyhWVc24HXxmuVSKZ43/Y6UCGGFBxUBjBoU295llJKOxoJDN3o4+iL8mzN49nAI s8sQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fBd40cId; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2ff4e853c5bsi5743518a91.102.2025.03.06.06.26.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Mar 2025 06:26:15 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fBd40cId; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id CADF28141D; Thu, 6 Mar 2025 15:26:00 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="fBd40cId"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 98241808A2; Thu, 6 Mar 2025 15:25:59 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) (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 A362281253 for ; Thu, 6 Mar 2025 15:25:56 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-39130ee05b0so119069f8f.3 for ; Thu, 06 Mar 2025 06:25:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1741271156; x=1741875956; darn=lists.denx.de; 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=Ue63HpIL4s7nmj4eEoqQjm3Hf7Q+UiOFHWN8tEEsJfA=; b=fBd40cIdaJig7tlS1gjm2jISJioy7qxjnoyNTu+hyWn1vONYedRnWxrN7xY0wmOf0J yrd/dCMY7gdObJtaXGtYijDiGCerUOcriO4+YJteDUU0pSBMyR/zsnxdlVix/W+42Fx4 kOz1j4D5XodVNMKWKI+umdbvuI0b7h33R0FBTxgB3kfh8oXnPE+wlKvjAfv6iqRhfnck kwIz5UsAQqaEOlSPZPx8wZJQ+FL5QCPECLgymInID4z/GjPDlMPJ2Xg4tO6ZleM3FySS N89Sw26qcIsS6ofvqDzqj0ux57C0qrw6bFvM3dtsUaYSB/sFmp5kCE/zx9CVWiLrcxan jfzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741271156; x=1741875956; 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=Ue63HpIL4s7nmj4eEoqQjm3Hf7Q+UiOFHWN8tEEsJfA=; b=RvJlBT8wFPyuMELKk7ZWXCu8jHCGZ9Qt5zLws6S6kxjzyvFpvpLlCV/V/QrNGS9wOd xRGiu3f1/cZm8QKv2DdGtc/nQzEZnmM6MVjLOKscZMqzaSDGlIEY93cT0viE/bNqpAsK O90NvRCK+YFFP1/eIDFqur6v3c9dR0g3Kaj7XoEYmrGzVS6n/Ko7xIgQiSdbEKLx6P2/ uDSNsGVVKqaxm5GCY88jajfMt0IU5YJmjdjcFECErnxNuK+SxiMTo9IUELZJtJLdtapX /ESMAwDg/Cih12WWw8dCoJxiUwDd8k95m68L3rvxxBx7hzWp7BLR7+YWAi29SQlZ+BV1 QjLA== X-Gm-Message-State: AOJu0YzelaHlqKh3n5cYqqjjpNPPJ6R9tVAb57LnIA3SP5yMvYMzWO3S Usg3WO+MdNATZwbCnJmHW/OReV/6GCnnU3mwt8EVH+dv9tIz8yZaPOxgVLCc0JIF2Ydm4lbN7xC Y X-Gm-Gg: ASbGncsrj4ckiRbaIm20AMAWeQacza20zX2J7kejTVYdmR0rWGhBDVleF2M7SFmso7R 6WEx2trzUmac4HvcijAmdSUN+95Cd7et/6inM44g2QgT28w0rmOisLRjA/sN496tDr6ibRRdLI4 Clv4xq1Q8jHkz8zWvxxJwP/GQ6WfxxwGuZPnloZCq8Op/DIFMjb8Ywn9+xdwd+YuBeUTaZDGc+b VpeT1mCFTTV8sWgZGquRR+ZaR/NNu5vEPM8Lh21bnLdeJ52BezdvRNCun+a80ZkUoHs11UgQjku /2EMvVjTOcEEN6bCAlnhcr34KZhVZi1jsXw7oPYZDZAUSVDtFfepRg== X-Received: by 2002:a5d:47ab:0:b0:38f:4fa6:bb24 with SMTP id ffacd0b85a97d-3911f7a83cbmr7065025f8f.39.1741271155800; Thu, 06 Mar 2025 06:25:55 -0800 (PST) Received: from builder.. ([2a01:e0a:3cb:7bb0:af71:dfb2:66ef:80c3]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3912bfdfad7sm2181543f8f.26.2025.03.06.06.25.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Mar 2025 06:25:55 -0800 (PST) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Simon Glass , Tom Rini Subject: [PATCH 1/3] dm: core: add 'netif' field to struct udevice for NET_LWIP Date: Thu, 6 Mar 2025 15:25:19 +0100 Message-ID: <20250306142525.3079189-2-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250306142525.3079189-1-jerome.forissier@linaro.org> References: <20250306142525.3079189-1-jerome.forissier@linaro.org> MIME-Version: 1.0 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.8 at phobos.denx.de X-Virus-Status: Clean When NET_LWIP is enabled, the network stack operates on 'struct netif' pointers to represent network interfaces, while U-Boot natively uses struct udevice. Therefore there should be a 1:1 mapping between a (network) udevice and a netif. This association is only implemented in one way by netif::state which is a private opaque pointer that we use to store the udevice. But the udevice doesn't have any equivalent to store the netif. In the initial design of the lwIP integration it was decided to re-create a new netif each time an operation on a udevice is needed. Retrospectively, it was a bad choice since it causes needless allocations and makes debugging more difficult since netif identifiers keep changing: et0, et1, et2, etc. Therefore, introduce a 'struct netif *' field in struct udevice. A follow-up patch will use it to look up a netif from a udevice and avoid unnecessary allocations. Signed-off-by: Jerome Forissier --- include/dm/device.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/dm/device.h b/include/dm/device.h index add67f9ec06..230aceb4142 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -20,6 +20,7 @@ #include struct driver_info; +struct netif; /* Driver is active (probed). Cleared when it is removed */ #define DM_FLAG_ACTIVATED (1 << 0) @@ -166,6 +167,7 @@ enum { * @dma_offset: Offset between the physical address space (CPU's) and the * device's bus address space * @iommu: IOMMU device associated with this device + * @netif: lwIP device associated with this device */ struct udevice { const struct driver *driver; @@ -198,6 +200,9 @@ struct udevice { #if CONFIG_IS_ENABLED(IOMMU) struct udevice *iommu; #endif +#if CONFIG_IS_ENABLED(NET_LWIP) + struct netif *netif; +#endif }; static inline int dm_udevice_size(void) From patchwork Thu Mar 6 14:25:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 870824 Delivered-To: patch@linaro.org Received: by 2002:ab3:6e57:0:b0:290:25b2:841c with SMTP id w23csp455778ltm; Thu, 6 Mar 2025 06:26:38 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWaL5AiHI5JJvht2FfRGNdzVhJTg+0JTrMW/Os29dVInI917vEjayY48vvxUCQl1DVNPUWvkg==@linaro.org X-Google-Smtp-Source: AGHT+IHQKvE19CzEB0Rdh7gMaJVvqZJAJ1/QVvENrDv4ZqeiJzMaYGDP9OHYgtUVdtDD14zL0tdH X-Received: by 2002:a05:6a21:3986:b0:1ee:f19f:416b with SMTP id adf61e73a8af0-1f349594852mr14466280637.29.1741271197762; Thu, 06 Mar 2025 06:26:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1741271197; cv=none; d=google.com; s=arc-20240605; b=VcMH6jKT6kfYhuefTPmnHuvZoBjfrIktneaYA7aqU94tvFm7RtgsLygcIx43iVTtp7 G3HOWnwvvFgxvNvc+BOyN5rkDaoTc119iHxGauK0StPSgWj0CRYYr18Ahi5PDD8VZjsx s9WZMmAhu9LItqXSI20MqynALhH5U4d54xXtZqTiae3aDMMLv4efYYnGt+PMxkKj9qU4 Neir1+Tgc6ZrrDFJMute58y4w92KdXJthZz24SPBmCVOJ7tnQ7bQ2VBn3QHcXZmvtStE R6PAgx2NHE30k3elVSY/2Q64CSuc95dnPo4A0yNxJ2/cS2MakTshzmkDm0G9GwKvXRx0 YAXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=cPEAqZz4+ggwqAu6Rb0BkaEQPcAjk26CnDMWYXLY6Cw=; fh=d9hib/SvymYSAHukfuA9RRy3TqTPCEz//tQ82o5IX70=; b=Kfxoi95yDHfDOSJtp4bxLrukivItHwXkuxoCgdUeMJkqkdiIzrtPl5xcxd/VN/XUcD fuYEGnegIIQD59sgLhxjIMn/kmfUCvvU2YbFxg77p/FdPZ3Z2dE3Z1sofufVk7pqM8T/ 80GtNY/449G9fdHTWyCo6fX2sGjuGfRGGnE2yg2dew1hne0Uh5WEi+3VzDLbW1t2ms2g UIUSdyazENT7T5HWdjOwFJRXOcW0OMN64YLeTA+OCeKqADqfnGSL7BPGILEbkZsccgOS fvEUS57TxJRAYC14auo+dqnBKUDfbKjko8+jXUC27yk0+dwSHxMR2qjJvaApeCVdpvbE s1gA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Oul8sdQ9; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id 41be03b00d2f7-af28127e894si2225270a12.380.2025.03.06.06.26.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Mar 2025 06:26:37 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Oul8sdQ9; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C528E81545; Thu, 6 Mar 2025 15:26:07 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Oul8sdQ9"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C4DC681417; Thu, 6 Mar 2025 15:26:06 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) (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 47A9481253 for ; Thu, 6 Mar 2025 15:26:00 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-43bcb1a9890so13345705e9.0 for ; Thu, 06 Mar 2025 06:26:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1741271159; x=1741875959; darn=lists.denx.de; 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=cPEAqZz4+ggwqAu6Rb0BkaEQPcAjk26CnDMWYXLY6Cw=; b=Oul8sdQ9pJf8wvq82BxVtw1idgR36WPlcvZQQp7XxbwIVXO80gdsqyUmNlRSxt+P4v iYWcFV12/E/YL/PlxcaQ6KNFE5MK1mpTnS1aRonWs+oZiUJ79EpPkG9SUZ65407WE07O nqKohlK1AgPgM3112dNNzgn7h+jqkxjSEEtf2dDAAFsVYxtEY+9T0XRnzVVu0WTLTtB5 M9fx6GD5iwrFk1U0Mz4s9rtZ6Q3t5SdjXV5tT5L8iGg0Ns40IZVDF4ysa2pE6fobWV8Q iVT/YizDkmW9+uGenrfVSYltYcrMKwonHssYVYM71ERbn+xyz2iBrjZjNoBgDheaQs+j Kecg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741271159; x=1741875959; 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=cPEAqZz4+ggwqAu6Rb0BkaEQPcAjk26CnDMWYXLY6Cw=; b=jI2soNEIu1OxdBGvEeaiQmJ7D8PVC/uSSyLf82p3fqu50ZF7MjgB06ljBc2X7cyoPo sIVB971/awjW0d3lzndNUzxQXgiVL/oEK/l7kqTrEQVj3Jr6Lqm2qMoUvJ3g1ZGbthxR j5VzBZZajFc30qsv2ZQxGpsywq4algl8MWKksemyA9hT2qv5yIIyaZ7hHjLHFKAPAOzy kHU9f3nqUIr6ByZ9wSQEPyz0FhNwk7nnio5IFhx+cGCiJQ7dhZB1qh/Re9OoGxX+iPDZ vRcuWlCsaT8xJs+C6D7FzuzpbepAHqV/YuYVe1CrBWgZbrC6f2NY+VhTcZ0B4vcQSuWi CkXg== X-Gm-Message-State: AOJu0YxxWC/IKVdTS5nNzJwhGam6svNa/Av6TJYrRehAc6ODemZ/53eq oyUmnLFlNI1YhqVvu+TgOQ4Zt9054l7F2aXs1MFH2xendpQC3sZTRLdU4axD5nuPoPhd+5T7yf8 x X-Gm-Gg: ASbGnctaGv8j6PKnHrySZKZmMbyulCRBYRF/8LvRbFW9CKa7xX/ImH3hVqiuSEhihKE NesQMuiX+mt+7KPOsBXOZV4KO89fm6bzMc1jBV7izbOO072BEuFfzyt0uIjrlGdb/VRxzPIwVcQ eMV1qlAfaJ41ee+8LiXVwOyEw42v0af+ZZUhZ8x9c0p3oWHmM/PfiTYU8Rjy9sXpc+n5Zm3tMZ7 0YD1mF158Ydua0yD/XWoEcqOv3Eq0lEdORhAPIJyM6TiU8b6dPxZUf9ZSUYfIxi4KRceHxlOV51 W05ZT5wm2k4+1MMcFEfgz3oaJ0moCSdQvPUXVnRekAXAcoptz8uytg== X-Received: by 2002:a5d:5f8c:0:b0:391:3156:6be with SMTP id ffacd0b85a97d-39131560a4emr53120f8f.7.1741271159408; Thu, 06 Mar 2025 06:25:59 -0800 (PST) Received: from builder.. ([2a01:e0a:3cb:7bb0:af71:dfb2:66ef:80c3]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3912bfdfad7sm2181543f8f.26.2025.03.06.06.25.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Mar 2025 06:25:59 -0800 (PST) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Tom Rini , Joe Hershberger , Ramon Fried , Adriano Cordova , Heinrich Schuchardt , Simon Glass Subject: [PATCH 2/3] net: lwip: save struct netif in struct udevice Date: Thu, 6 Mar 2025 15:25:20 +0100 Message-ID: <20250306142525.3079189-3-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250306142525.3079189-1-jerome.forissier@linaro.org> References: <20250306142525.3079189-1-jerome.forissier@linaro.org> MIME-Version: 1.0 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.8 at phobos.denx.de X-Virus-Status: Clean Save the struct netif pointer in the corresponding struct udevice when the netif is created. This avoids needlessly re-creating devices each time the lwIP stack is entered. Replace functions net_lwip_new_netif() and net_lwip_new_netif_noip() with net_lwip_netif() and net_lwip_netif_noip() respectively since they return a new structure only the first time. Signed-off-by: Jerome Forissier --- include/net-lwip.h | 4 ++-- net/lwip/dhcp.c | 7 ++----- net/lwip/dns.c | 5 +---- net/lwip/net-lwip.c | 19 +++++++++++-------- net/lwip/ping.c | 8 ++------ net/lwip/tftp.c | 5 +---- net/lwip/wget.c | 9 ++------- 7 files changed, 21 insertions(+), 36 deletions(-) diff --git a/include/net-lwip.h b/include/net-lwip.h index 64e5c720560..58ff2bb2d43 100644 --- a/include/net-lwip.h +++ b/include/net-lwip.h @@ -11,8 +11,8 @@ enum proto_t { }; void net_lwip_set_current(void); -struct netif *net_lwip_new_netif(struct udevice *udev); -struct netif *net_lwip_new_netif_noip(struct udevice *udev); +struct netif *net_lwip_netif(struct udevice *udev); +struct netif *net_lwip_netif_noip(struct udevice *udev); void net_lwip_remove_netif(struct netif *netif); struct netif *net_lwip_get_netif(void); int net_lwip_rx(struct udevice *udev, struct netif *netif); diff --git a/net/lwip/dhcp.c b/net/lwip/dhcp.c index 3b7e4700c6e..4c621e52337 100644 --- a/net/lwip/dhcp.c +++ b/net/lwip/dhcp.c @@ -43,7 +43,7 @@ static int dhcp_loop(struct udevice *udev) return CMD_RET_FAILURE; } - netif = net_lwip_new_netif_noip(udev); + netif = net_lwip_netif_noip(udev); if (!netif) return CMD_RET_FAILURE; @@ -70,10 +70,8 @@ static int dhcp_loop(struct udevice *udev) sys_untimeout(call_lwip_dhcp_fine_tmr, NULL); - if (!bound) { - net_lwip_remove_netif(netif); + if (!bound) return CMD_RET_FAILURE; - } dhcp = netif_dhcp_data(netif); @@ -106,7 +104,6 @@ static int dhcp_loop(struct udevice *udev) printf("DHCP client bound to address %pI4 (%lu ms)\n", &dhcp->offered_ip_addr, get_timer(start)); - net_lwip_remove_netif(netif); return CMD_RET_SUCCESS; } diff --git a/net/lwip/dns.c b/net/lwip/dns.c index 149bdb784dc..65474055cff 100644 --- a/net/lwip/dns.c +++ b/net/lwip/dns.c @@ -54,7 +54,7 @@ static int dns_loop(struct udevice *udev, const char *name, const char *var) dns_cb_arg.var = var; - netif = net_lwip_new_netif(udev); + netif = net_lwip_netif(udev); if (!netif) return CMD_RET_FAILURE; @@ -74,7 +74,6 @@ static int dns_loop(struct udevice *udev, const char *name, const char *var) if (!has_server) { log_err("No valid name server (dnsip/dnsip2)\n"); - net_lwip_remove_netif(netif); return CMD_RET_FAILURE; } @@ -100,8 +99,6 @@ static int dns_loop(struct udevice *udev, const char *name, const char *var) sys_untimeout(do_dns_tmr, NULL); } - net_lwip_remove_netif(netif); - if (dns_cb_arg.done && dns_cb_arg.host_ipaddr.addr != 0) return CMD_RET_SUCCESS; diff --git a/net/lwip/net-lwip.c b/net/lwip/net-lwip.c index cab1dd7d483..77f16f8af9c 100644 --- a/net/lwip/net-lwip.c +++ b/net/lwip/net-lwip.c @@ -141,7 +141,7 @@ void net_lwip_set_current(void) eth_set_current(); } -static struct netif *new_netif(struct udevice *udev, bool with_ip) +static struct netif *get_or_create_netif(struct udevice *udev, bool with_ip) { unsigned char enetaddr[ARP_HLEN]; char hwstr[MAC_ADDR_STRLEN]; @@ -152,13 +152,14 @@ static struct netif *new_netif(struct udevice *udev, bool with_ip) if (!udev) return NULL; + if (udev->netif) + return udev->netif; + if (eth_start_udev(udev) < 0) { log_err("Could not start %s\n", udev->name); return NULL; } - netif_remove(net_lwip_get_netif()); - ip4_addr_set_zero(&ip); ip4_addr_set_zero(&mask); ip4_addr_set_zero(&gw); @@ -198,17 +199,19 @@ static struct netif *new_netif(struct udevice *udev, bool with_ip) /* Routing: use this interface to reach the default gateway */ netif_set_default(netif); + udev->netif = netif; + return netif; } -struct netif *net_lwip_new_netif(struct udevice *udev) +struct netif *net_lwip_netif(struct udevice *udev) { - return new_netif(udev, true); + return get_or_create_netif(udev, true); } -struct netif *net_lwip_new_netif_noip(struct udevice *udev) +struct netif *net_lwip_netif_noip(struct udevice *udev) { - return new_netif(udev, false); + return get_or_create_netif(udev, false); } void net_lwip_remove_netif(struct netif *netif) @@ -221,7 +224,7 @@ int net_init(void) { eth_set_current(); - net_lwip_new_netif(eth_get_dev()); + net_lwip_netif(eth_get_dev()); return 0; } diff --git a/net/lwip/ping.c b/net/lwip/ping.c index 200a702bbb5..6dc8f88782b 100644 --- a/net/lwip/ping.c +++ b/net/lwip/ping.c @@ -119,17 +119,15 @@ static int ping_loop(struct udevice *udev, const ip_addr_t *addr) struct netif *netif; int ret; - netif = net_lwip_new_netif(udev); + netif = net_lwip_netif(udev); if (!netif) return CMD_RET_FAILURE; printf("Using %s device\n", udev->name); ret = ping_raw_init(&ctx); - if (ret < 0) { - net_lwip_remove_netif(netif); + if (ret < 0) return ret; - } ctx.target = *addr; @@ -149,8 +147,6 @@ static int ping_loop(struct udevice *udev, const ip_addr_t *addr) sys_untimeout(ping_send, &ctx); ping_raw_stop(&ctx); - net_lwip_remove_netif(netif); - if (ctx.alive) return 0; diff --git a/net/lwip/tftp.c b/net/lwip/tftp.c index 123d66b5dba..aae1b3bbad3 100644 --- a/net/lwip/tftp.c +++ b/net/lwip/tftp.c @@ -119,7 +119,7 @@ static int tftp_loop(struct udevice *udev, ulong addr, char *fname, if (!srvport) srvport = TFTP_PORT; - netif = net_lwip_new_netif(udev); + netif = net_lwip_netif(udev); if (!netif) return -1; @@ -146,7 +146,6 @@ static int tftp_loop(struct udevice *udev, ulong addr, char *fname, /* might return different errors, like routing problems */ if (err != ERR_OK) { printf("tftp_get() error %d\n", err); - net_lwip_remove_netif(netif); return -1; } @@ -162,8 +161,6 @@ static int tftp_loop(struct udevice *udev, ulong addr, char *fname, tftp_cleanup(); - net_lwip_remove_netif(netif); - if (ctx.done == SUCCESS) { if (env_set_hex("fileaddr", addr)) { log_err("fileaddr not updated\n"); diff --git a/net/lwip/wget.c b/net/lwip/wget.c index 14f27d42998..b191c95e251 100644 --- a/net/lwip/wget.c +++ b/net/lwip/wget.c @@ -307,7 +307,7 @@ static int wget_loop(struct udevice *udev, ulong dst_addr, char *uri) if (parse_url(uri, ctx.server_name, &ctx.port, &path, &is_https)) return CMD_RET_USAGE; - netif = net_lwip_new_netif(udev); + netif = net_lwip_netif(udev); if (!netif) return -1; @@ -320,7 +320,6 @@ static int wget_loop(struct udevice *udev, ulong dst_addr, char *uri) if (!tls_allocator.arg) { log_err("error: Cannot create a TLS connection\n"); - net_lwip_remove_netif(netif); return -1; } @@ -332,10 +331,8 @@ static int wget_loop(struct udevice *udev, ulong dst_addr, char *uri) conn.headers_done_fn = httpc_headers_done_cb; ctx.path = path; if (httpc_get_file_dns(ctx.server_name, ctx.port, path, &conn, httpc_recv_cb, - &ctx, &state)) { - net_lwip_remove_netif(netif); + &ctx, &state)) return CMD_RET_FAILURE; - } while (!ctx.done) { net_lwip_rx(udev, netif); @@ -344,8 +341,6 @@ static int wget_loop(struct udevice *udev, ulong dst_addr, char *uri) break; } - net_lwip_remove_netif(netif); - if (ctx.done == SUCCESS) return 0; From patchwork Thu Mar 6 14:25:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 870823 Delivered-To: patch@linaro.org Received: by 2002:ab3:6e57:0:b0:290:25b2:841c with SMTP id w23csp455676ltm; Thu, 6 Mar 2025 06:26:26 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWFIoto8GsTn+0pNKFYTCl+ieHaBcJOukFrL1RJgbVui7cx1vYQ36MwkBr8+bBAtYMdnD3zmg==@linaro.org X-Google-Smtp-Source: AGHT+IHOLoVrNRdEwUQb+c8XNhlamAwhQyxOYo4fQYcBBDbg4JkCzrf1szAHQigbaX4q3ntt6ddE X-Received: by 2002:a17:90b:2dca:b0:2f9:9e64:37b1 with SMTP id 98e67ed59e1d1-2ff49814592mr11713034a91.28.1741271186605; Thu, 06 Mar 2025 06:26:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1741271186; cv=none; d=google.com; s=arc-20240605; b=Mp1P6Kuv3Fe6HseIsIxI0KLq+2v6tTIc4rEONvtDibbshwQfTLWMEapRAUX7SD4amP tcoXSUqa6MzDHoALNR0peGE5U2C7bugnuKu3gf4lO9AOcqFK8LVHACrl9PKIYV6miokx pehyejePFYZgxd4fheCO8IjeqQ1gDM10Kqm2Ofed4suHzaITKjFoxCKlzle+XPKoY8Ti Py1qu49Z5hNR4UHnPUCXlAfxXDFBQ5ImsmAkmVpe5J2/DIBGghcLf7HOgBKH9LyhXDqD ztFieFoTV9O36EBpyZyTnmiKoW6vP1kS8tIXzV2uDcc/XxzbEJuM3Rak4dInHi5nRIUC J3Iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=PcXFUhHXxwpQjhY9ngA2fYwAh5PvWFvp9h7Czg8HhxM=; fh=ZRg9BJLqT4jwel/4wcHp6uiz6+1UQkTgKs/2H+3t27M=; b=WR0gvEnXEdoto59byYEF5IxRVBw870ejuID31JrtUCibXMc6QZPIRJ/MDtFAKKIjis 0anzp+fgrx51tWhK4NQCCfMaUBBrbVjVCK3+oUH1BMqcOcvRYrdvHW4IQQPD1ILksLsG auUiH7rcdEBavw2tIWvogcM+2phrhluxicvMQh/2HGwWxai3ewOWbrMXgLqaFMblvU4d RgjBRGvcH62F1c41D3e5eFr2H2sAe2gXTcdfAFhZFu3w8p90aZV5s9MUHTF8bTog0ZuA MtBFNt8YK2cF0sdykBcGR+kj9FHPlE+iwosqA2R3ZnTE2jSSalU6u4x0fcyNyBwPclXf hglQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YalLrXMo; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2ff693eb409si2169008a91.153.2025.03.06.06.26.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Mar 2025 06:26:26 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YalLrXMo; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 563F68142D; Thu, 6 Mar 2025 15:26:05 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="YalLrXMo"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 89A3781433; Thu, 6 Mar 2025 15:26:03 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) (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 8F9AF8142D for ; Thu, 6 Mar 2025 15:26:01 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-388cae9eb9fso378701f8f.3 for ; Thu, 06 Mar 2025 06:26:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1741271161; x=1741875961; darn=lists.denx.de; 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=PcXFUhHXxwpQjhY9ngA2fYwAh5PvWFvp9h7Czg8HhxM=; b=YalLrXMoohErmLyz3pOLAwJYOflNphpcCacb6b/9JrDWeanc2Fzl6SeOVxHoj+WXKx W9nFzvjypcpBxkHfBEZ1BtohTs5nbbVEYYR8tKBcSZK5zOZnH/M+eqXSpoeipUc2Ni4L H6L1xElb4y5DZYwY6Qa55Z4jry4ZoDPYIkdkedvJpK185ke1KVuMhu/NJzrYBzJimPgB vuxFNPWk9kJf7hZ8NiIMUOKsV+6PQpcZw7azuPalklzCFTVOv5ZfYKnhVQrM9LOUqsBm I+ePzGN9GKdhGDp5Osd4sSBkTBblN+xWLiPJZtgWju4xxt7nDhJF4OpGtHYwoe2Rz+0q jU0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741271161; x=1741875961; 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=PcXFUhHXxwpQjhY9ngA2fYwAh5PvWFvp9h7Czg8HhxM=; b=Cs5QbiJmmidUubqDYpRvDHAQOXhl7esiKzYAIZHZp2GAsBZqjSnAtp1fm+OZPE8pAf n0158v9jpdMF8EisUx/zWWW47cZpVwsHEUTkD45VXWIqkxjmWW9sSnW6oVeymZOCU/y7 Ij1Sp60cRQpnX43Uc0Kpn0d6cXWc7iMHBzOkgFQG4w3oQx/Zs7tz5Y8xiqgyRuqcXVJD p54gjATh797LO9C1lQJU8CyhDJK+zUwAEgyOe6GMuvdSVwF0RJySG66Ma9AS+6ku065G GpMuNfUXVSMqaXtSP75qRVESOrhsg9PBETfSXBZ/MbRfRBA8SyFikZtzIodgWuoGSSwA tjYg== X-Gm-Message-State: AOJu0YzhMJGky/ESIeN9pu4EKI1RTKNXxN7mnvXzhj0/0cMX4O2wcs0A 3ydL4eXwCCDVVCiaNkBCfyXrlgU6VmpPxErbrSBkEkhp2U1T72Buw20pI09mxZTnD9gN1E7bpLB p X-Gm-Gg: ASbGncs5yWXeVgR26G2gQKGItpXCxkImHuPYQpKfrBI3Us3i6s0mlWMnbsIBteMwUb9 YlLfXp4xvICWeDEKJxBUgPzF3a0stn699JELFHVoPEm/V/SK6OzrjHONAZEvcpi8OVC9Rw1Qjda YVeDEXWT0ARuwQsRNJ/oAT7ii1fEHhXV7+OZKX2vz21lk+we2cLhDwXSR2rQOJzv4/Bla7/1emB FGkoBjF18ALHWfX0WBBsMo4HTpG06NOOtcFPRAAYOXkH1mf47gBel4VC7mcmOWYIYxxjKKLLiER AXYSaEE/YlNQ1U9Sz3h27IfZEkeLj8Ovt8XxxfCkKwIhGqUm6zYdsA== X-Received: by 2002:a5d:64c7:0:b0:391:2c09:bdef with SMTP id ffacd0b85a97d-3912c09bfdfmr1454266f8f.30.1741271160856; Thu, 06 Mar 2025 06:26:00 -0800 (PST) Received: from builder.. ([2a01:e0a:3cb:7bb0:af71:dfb2:66ef:80c3]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3912bfdfad7sm2181543f8f.26.2025.03.06.06.26.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Mar 2025 06:26:00 -0800 (PST) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Tom Rini , Joe Hershberger , Ramon Fried , Adriano Cordova Subject: [PATCH 3/3] net: lwip: remove net_lwip_remove_netif() Date: Thu, 6 Mar 2025 15:25:21 +0100 Message-ID: <20250306142525.3079189-4-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250306142525.3079189-1-jerome.forissier@linaro.org> References: <20250306142525.3079189-1-jerome.forissier@linaro.org> MIME-Version: 1.0 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.8 at phobos.denx.de X-Virus-Status: Clean net_lwip_remove_netif() is not used, remove it. Signed-off-by: Jerome Forissier --- include/net-lwip.h | 1 - net/lwip/net-lwip.c | 6 ------ 2 files changed, 7 deletions(-) diff --git a/include/net-lwip.h b/include/net-lwip.h index 58ff2bb2d43..36df78d61db 100644 --- a/include/net-lwip.h +++ b/include/net-lwip.h @@ -13,7 +13,6 @@ enum proto_t { void net_lwip_set_current(void); struct netif *net_lwip_netif(struct udevice *udev); struct netif *net_lwip_netif_noip(struct udevice *udev); -void net_lwip_remove_netif(struct netif *netif); struct netif *net_lwip_get_netif(void); int net_lwip_rx(struct udevice *udev, struct netif *netif); diff --git a/net/lwip/net-lwip.c b/net/lwip/net-lwip.c index 77f16f8af9c..f50cfbf27fa 100644 --- a/net/lwip/net-lwip.c +++ b/net/lwip/net-lwip.c @@ -214,12 +214,6 @@ struct netif *net_lwip_netif_noip(struct udevice *udev) return get_or_create_netif(udev, false); } -void net_lwip_remove_netif(struct netif *netif) -{ - netif_remove(netif); - free(netif); -} - int net_init(void) { eth_set_current();