From patchwork Wed Aug 7 17:11:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 817419 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e11:0:b0:367:895a:4699 with SMTP id p17csp493782wrt; Wed, 7 Aug 2024 10:14:53 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUD2gHTaZXsxJpbi+crH1w36Ks1iqULs7ZG9ATtmeTX9zsxhGJLB9c+0zJE2scsDHvEvbcZAabC2u6KNp1C+48l X-Google-Smtp-Source: AGHT+IGBxmsF3JRudoRJCeoMEWdbjoVFSx2VV+yKXLxBeXlmRnN7lQ555UqRy4l7jhNsksfy3Y5y X-Received: by 2002:a17:907:847:b0:a72:5f3f:27a2 with SMTP id a640c23a62f3a-a8079104adcmr285204866b.26.1723050893611; Wed, 07 Aug 2024 10:14:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1723050893; cv=none; d=google.com; s=arc-20160816; b=O3F//77bYwwqjvEGOerAOeFUo5biprbOJMlAG3Ziwq/79/orKSkY0XKrH6N0yoB4i1 mVL6AZmfIcKPSa1qjg7TKYlyWDWaEgvnJsZnXvePPDqYRsBXw5CNX1ubBm3peQBWVwpa XuSaOJcR1j5kUadEvfx0osFS3qY+JVdy9vW824GMRKE4ok0pgJ4RWPT/0uCqLiXEz0v3 aCeQg5lGBvOIIoMp4Et5FzimL8jhu5Lbv3yvf5x7aQ+39yPUIC22J6f9M88CSbTQgLTX kaBSE7AnMpsm/jxdT29NmYT+OqmQAQihJ/yZubwUzPMQJScKqi6tIYDbFtlrBanEa66L 7qpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; 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=LmceqEqwXcI8cbIx3iqWzOsMCyxujqNRD+J/4EB6unE=; fh=ypSyKgYYT5SAzXeaETVVgBhwC0wq95rogejtm7tyl74=; b=HKrgEcKKEUp3VlnsnRj0Ihet2KkXBk2rKzy8pIp0dn+5aFz0XrCzIct0AV5G03EVi0 H2C6IYV+d3ChXP4M3yf+z/aSnxERdxyozipKB9hSXWF0GiY0xgdW6aa0e64HwqgtsRsi iqRWiZ1RJjN46gMj2FcLL0fJoDwkcoR0xF3QFefKvf8qjbvGlS0KsG/yFsKnjn/WKEMk sws+tPv52FnOhpaVjbaFoJBl14NDw2E2lu8AdSZpkBRF6HjrmYE4OBMOxMG7o1ee+AHN DJWbnZ6gzi1UTZP7BGCyDQ0IW4oh7DaTEJ3B/G3G1f3m+ezoJwm6UAh8gtRg58/CjR1v K1bw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YtOcS4XF; 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 a640c23a62f3a-a7dc9f32320si686632666b.869.2024.08.07.10.14.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Aug 2024 10:14:53 -0700 (PDT) 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=YtOcS4XF; 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 1C7AD88D65; Wed, 7 Aug 2024 19:13:22 +0200 (CEST) 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="YtOcS4XF"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id EFAF988D59; Wed, 7 Aug 2024 19:13:20 +0200 (CEST) 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,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) (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 D661487873 for ; Wed, 7 Aug 2024 19:13:18 +0200 (CEST) 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-x330.google.com with SMTP id 5b1f17b1804b1-428f5c0833bso6918595e9.0 for ; Wed, 07 Aug 2024 10:13:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1723050798; x=1723655598; 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=LmceqEqwXcI8cbIx3iqWzOsMCyxujqNRD+J/4EB6unE=; b=YtOcS4XF+Tld5tmSh+RkLHFyNcFsmmFqS7ROm00vP0z3x5OLKxGme/DlDpXpMFZu1N zX2bdy5NRngmVbF26biiGGLAS90oEIF6WxZdFlxIcuCEN7MeE/qAX5j55b9UbWvg81M0 txmKM+ygi2l0U6DWsavJBAsv9uMhXY5Xx8wSPr9QtupMaSEnPMhz6rPbEZX0jNol/Jva UyxudwLIzVSSiqFpYJHgWYj9hH/+oMcBBv49/69cPdEQ5iJRI0oSDsrVVMoaTdNtllSw 5C1/6ZCDTRe6ZJdjhpCS+nmdAR2K0HTtYDOn2+6c58TzmTSS3VEKCH6+Ur0RFgFBHe9o NywQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723050798; x=1723655598; 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=LmceqEqwXcI8cbIx3iqWzOsMCyxujqNRD+J/4EB6unE=; b=KdwkTYiRIexNjrxVWCHX6XyiQFwxJvs8xodT4GsdaZ/cUdgTIZnKUVDX0Yb5+sna2t F8Rgqs7tH+ZM71Pd8MdCnEy83vtXUaJoO1yDhtgrOmof+i5tgc/bT0dSiAheu0QQePie 2frlZUxgdKacBOPIeCksHbV2Z//i0TlcVkl/E5ZTXY6dnFkxKowCkiiePy6bIyR8NJrj TIrgzVhoRMCjcPggQTZ/F+4NQPfjdhqk4eU/AFqVqA17sTj+Ynv8CoiwinL7rfRy+afU ACeaVN32qyEYqe/cnIPZubd9mKQXRtgcQH26Vh3WdK/LQJjAEpd9fazW7Y4Kx2NBcNdJ HMuA== X-Gm-Message-State: AOJu0YxLYdILu03jb2ecVVHg/rzK+AIKME9YY1Gd5gXL0iYU/RacQpr8 DMNC113i8HtjMiHXn8Oq4hDwGuZf7GwlewdRHdSBSue+3NuwdL65P73wN38hMH2aOpLwovPirQX AoqagoQiM X-Received: by 2002:a05:600c:5129:b0:426:5cc7:82f with SMTP id 5b1f17b1804b1-429052cfb3dmr22542445e9.13.1723050798110; Wed, 07 Aug 2024 10:13:18 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:bb3d:43b8:4780:757c]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36bbd0597b2sm16623781f8f.81.2024.08.07.10.13.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Aug 2024 10:13:17 -0700 (PDT) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Javier Tia , Raymond Mao , Maxim Uvarov , Tim Harvey , Jerome Forissier , Tom Rini , Simon Glass , Heinrich Schuchardt , Francis Laniel , Johan Jonker , Marek Vasut Subject: [PATCH v8 14/23] net: split cmd/net.c into cmd/net.c and cmd/net-common.c Date: Wed, 7 Aug 2024 19:11:58 +0200 Message-Id: <1264e7002019e9602f2d5c68f16a01b8b799861b.1723050310.git.jerome.forissier@linaro.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: 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 Extract some code from cmd/net.c that will be useful in a subsequent commit to implement wget with NET_LWIP. Signed-off-by: Jerome Forissier Reviewed-by: Ilias Apalodimas --- cmd/Makefile | 5 ++- cmd/net-common.c | 109 ++++++++++++++++++++++++++++++++++++++++++++ cmd/net.c | 115 ----------------------------------------------- 3 files changed, 113 insertions(+), 116 deletions(-) create mode 100644 cmd/net-common.c diff --git a/cmd/Makefile b/cmd/Makefile index fe733cf6ba9..2c3de45a074 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -130,7 +130,10 @@ obj-$(CONFIG_CMD_NAND) += nand.o ifdef CONFIG_CMD_NET obj-$(CONFIG_NET) += net.o obj-$(CONFIG_NET_LWIP) += net-lwip.o -CFLAGS_net-lwip.o := -I$(srctree)/lib/lwip/lwip/src/include -I$(srctree)/lib/lwip/u-boot +obj-$(filter y,$(CONFIG_CMD_NET) $(CONFIG_CMD_NET_LWIP)) += net-common.o +lwip-includes := -I$(srctree)/lib/lwip/lwip/src/include -I$(srctree)/lib/lwip/u-boot +CFLAGS_net-lwip.o := $(lwip-includes) +CFLAGS_net-common.o := $(lwip-includes) endif obj-$(CONFIG_ENV_SUPPORT) += nvedit.o obj-$(CONFIG_CMD_NVEDIT_EFI) += nvedit_efi.o diff --git a/cmd/net-common.c b/cmd/net-common.c new file mode 100644 index 00000000000..1c9fb83b896 --- /dev/null +++ b/cmd/net-common.c @@ -0,0 +1,109 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * (C) Copyright 2000 + * Wolfgang Denk, DENX Software Engineering, wd@denx.de. + */ + +#include +#include +#include +#include +#include +#include + +static int do_net_list(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) +{ + const struct udevice *current = eth_get_dev(); + unsigned char env_enetaddr[ARP_HLEN]; + const struct udevice *dev; + struct uclass *uc; + + uclass_id_foreach_dev(UCLASS_ETH, dev, uc) { + eth_env_get_enetaddr_by_index("eth", dev_seq(dev), env_enetaddr); + printf("eth%d : %s %pM %s\n", dev_seq(dev), dev->name, env_enetaddr, + current == dev ? "active" : ""); + } + return CMD_RET_SUCCESS; +} + +static int do_net_stats(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) +{ + int nstats, err, i, off; + struct udevice *dev; + u64 *values; + u8 *strings; + + if (argc < 2) + return CMD_RET_USAGE; + + err = uclass_get_device_by_name(UCLASS_ETH, argv[1], &dev); + if (err) { + printf("Could not find device %s\n", argv[1]); + return CMD_RET_FAILURE; + } + + if (!eth_get_ops(dev)->get_sset_count || + !eth_get_ops(dev)->get_strings || + !eth_get_ops(dev)->get_stats) { + printf("Driver does not implement stats dump!\n"); + return CMD_RET_FAILURE; + } + + nstats = eth_get_ops(dev)->get_sset_count(dev); + strings = kcalloc(nstats, ETH_GSTRING_LEN, GFP_KERNEL); + if (!strings) + return CMD_RET_FAILURE; + + values = kcalloc(nstats, sizeof(u64), GFP_KERNEL); + if (!values) + goto err_free_strings; + + eth_get_ops(dev)->get_strings(dev, strings); + eth_get_ops(dev)->get_stats(dev, values); + + off = 0; + for (i = 0; i < nstats; i++) { + printf(" %s: %llu\n", &strings[off], values[i]); + off += ETH_GSTRING_LEN; + }; + + kfree(strings); + kfree(values); + + return CMD_RET_SUCCESS; + +err_free_strings: + kfree(strings); + + return CMD_RET_FAILURE; +} + +static struct cmd_tbl cmd_net[] = { + U_BOOT_CMD_MKENT(list, 1, 0, do_net_list, "", ""), + U_BOOT_CMD_MKENT(stats, 2, 0, do_net_stats, "", ""), +}; + +static int do_net(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) +{ + struct cmd_tbl *cp; + + cp = find_cmd_tbl(argv[1], cmd_net, ARRAY_SIZE(cmd_net)); + + /* Drop the net command */ + argc--; + argv++; + + if (!cp || argc > cp->maxargs) + return CMD_RET_USAGE; + if (flag == CMD_FLAG_REPEAT && !cmd_is_repeatable(cp)) + return CMD_RET_SUCCESS; + + return cp->cmd(cmdtp, flag, argc, argv); +} + +U_BOOT_CMD( + net, 3, 1, do_net, + "NET sub-system", + "list - list available devices\n" + "stats - dump statistics for specified device\n" +); diff --git a/cmd/net.c b/cmd/net.c index 53ce2bc5d0c..c90578e1b9f 100644 --- a/cmd/net.c +++ b/cmd/net.c @@ -674,118 +674,3 @@ U_BOOT_CMD( ); #endif /* CONFIG_CMD_LINK_LOCAL */ - -static int do_net_list(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) -{ - const struct udevice *current = eth_get_dev(); - unsigned char env_enetaddr[ARP_HLEN]; - const struct udevice *dev; - struct uclass *uc; - - uclass_id_foreach_dev(UCLASS_ETH, dev, uc) { - eth_env_get_enetaddr_by_index("eth", dev_seq(dev), env_enetaddr); - printf("eth%d : %s %pM %s\n", dev_seq(dev), dev->name, env_enetaddr, - current == dev ? "active" : ""); - } - return CMD_RET_SUCCESS; -} - -static int do_net_stats(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) -{ - int nstats, err, i, off; - struct udevice *dev; - u64 *values; - u8 *strings; - - if (argc < 2) - return CMD_RET_USAGE; - - err = uclass_get_device_by_name(UCLASS_ETH, argv[1], &dev); - if (err) { - printf("Could not find device %s\n", argv[1]); - return CMD_RET_FAILURE; - } - - if (!eth_get_ops(dev)->get_sset_count || - !eth_get_ops(dev)->get_strings || - !eth_get_ops(dev)->get_stats) { - printf("Driver does not implement stats dump!\n"); - return CMD_RET_FAILURE; - } - - nstats = eth_get_ops(dev)->get_sset_count(dev); - strings = kcalloc(nstats, ETH_GSTRING_LEN, GFP_KERNEL); - if (!strings) - return CMD_RET_FAILURE; - - values = kcalloc(nstats, sizeof(u64), GFP_KERNEL); - if (!values) - goto err_free_strings; - - eth_get_ops(dev)->get_strings(dev, strings); - eth_get_ops(dev)->get_stats(dev, values); - - off = 0; - for (i = 0; i < nstats; i++) { - printf(" %s: %llu\n", &strings[off], values[i]); - off += ETH_GSTRING_LEN; - }; - - return CMD_RET_SUCCESS; - -err_free_strings: - kfree(strings); - - return CMD_RET_FAILURE; -} - -static struct cmd_tbl cmd_net[] = { - U_BOOT_CMD_MKENT(list, 1, 0, do_net_list, "", ""), - U_BOOT_CMD_MKENT(stats, 2, 0, do_net_stats, "", ""), -}; - -static int do_net(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) -{ - struct cmd_tbl *cp; - - cp = find_cmd_tbl(argv[1], cmd_net, ARRAY_SIZE(cmd_net)); - - /* Drop the net command */ - argc--; - argv++; - - if (!cp || argc > cp->maxargs) - return CMD_RET_USAGE; - if (flag == CMD_FLAG_REPEAT && !cmd_is_repeatable(cp)) - return CMD_RET_SUCCESS; - - return cp->cmd(cmdtp, flag, argc, argv); -} - -U_BOOT_CMD( - net, 3, 1, do_net, - "NET sub-system", - "list - list available devices\n" - "stats - dump statistics for specified device\n" -); - -#if defined(CONFIG_CMD_NCSI) -static int do_ncsi(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]) -{ - if (!phy_interface_is_ncsi() || !ncsi_active()) { - printf("Device not configured for NC-SI\n"); - return CMD_RET_FAILURE; - } - - if (net_loop(NCSI) < 0) - return CMD_RET_FAILURE; - - return CMD_RET_SUCCESS; -} - -U_BOOT_CMD( - ncsi, 1, 1, do_ncsi, - "Configure attached NIC via NC-SI", - "" -); -#endif /* CONFIG_CMD_NCSI */