From patchwork Fri May 5 10:25:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 679299 Delivered-To: patch@linaro.org Received: by 2002:a5d:4a41:0:0:0:0:0 with SMTP id v1csp283294wrs; Fri, 5 May 2023 03:51:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ44nqeoGVLZdTchNLfIJFUupnggIWVT925UM0Nlp/kmk1yFo9WXmZMpuDS3/zbc6AVMGBY8 X-Received: by 2002:a17:903:2451:b0:1ab:142a:3dd7 with SMTP id l17-20020a170903245100b001ab142a3dd7mr916020pls.68.1683283864490; Fri, 05 May 2023 03:51:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683283864; cv=none; d=google.com; s=arc-20160816; b=I9p9bWzBVQNgyVc3NmY5c01LAv/ai3I7RRgSjSZ3HxrpKg7YtyEyiHuRtfMTc9ifZd uuq6/cEtHnmC7iJg5TgvKLO/exc7ksew5uS7SZ4WvKh55qP13Kj0iayNxU5RFk1ODCku bS6a2ib8GuuJVNmVDlPHddvcEP9k9243mf45FM7cwxHkdIcx2nsbKG5BJI1pbsRsKNCi gScUpQAF2IE124v8jNJDY1ZrSUVFo/VkJEid4HxdZrDZN4B4GBfSTpQyzKgAFlDryQpr UCXQ751trnbQphhbNWiDS+gPqepczCMu/1My/yNUVFw5PRS/fVAZC45M9u04ar0RqyI+ +XzQ== 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=bGtQROW8CgSIpc8sC+xnf/7FVLmoH1qm1QTvSE8uz7Q=; b=xegyo1WXdKz3Yb8qo1uqu2cYTsazdqmir1KNy0DFlDAn1sIpRXZR8NbiPuh3aS1XWN GVFwmak/PHv4wLduCKaMMK0pNT5GvVPK03G9AmxKPBUM2q2ZGTyatJAFdDZ9WufSoZJb SXMkbU602MPZVeQpvS7pNPKi7rEWNYDPh5vEfPD4dyPTRbhwTFX/uc1C8fmTDwzpg+ld lXMPAwOqNW6/FVrE8tNGCH4sP/Ezi1ALiK+Bk/dy+ZJ8VYFCPs7JLbryRYpMZJRL1Vkr 8b1nKAPtqzVz5di1wBOIEybihaR1rIz6jz0eDVJF2F3THubNQ2K6tCV6Eh3h1vzRRFQn RjDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="O//10d4t"; 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 Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id s2-20020a170902ea0200b001a05d12eeb3si398574plg.189.2023.05.05.03.51.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 May 2023 03:51:04 -0700 (PDT) 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="O//10d4t"; 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 Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7C103847E1; Fri, 5 May 2023 12:50:35 +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="O//10d4t"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 85C7284798; Fri, 5 May 2023 12:25:42 +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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ot1-x32b.google.com (mail-ot1-x32b.google.com [IPv6:2607:f8b0:4864:20::32b]) (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 EC2C48476F for ; Fri, 5 May 2023 12:25:37 +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=maxim.uvarov@linaro.org Received: by mail-ot1-x32b.google.com with SMTP id 46e09a7af769-6a5ecdb455bso594360a34.0 for ; Fri, 05 May 2023 03:25:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1683282336; x=1685874336; 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=bGtQROW8CgSIpc8sC+xnf/7FVLmoH1qm1QTvSE8uz7Q=; b=O//10d4tXMkb4GmKCMy2ioWYEvISiHUwyV1PcvyMBqbZmQLcXPoGDszXimmVhRJoqz 20syo0F1l+fVaM/l++moM0xcyXWf+p/QDtgAo12mOfWbBFT/QY5ac++SJUYI8wrlI+PW mWirFv1AbefA4LN5nujBj5LD/LS/QLT0CG0TfJRCff4BHktvt/CEA1Ri3kldd+xlqArp XMzu/QvY0e1Wmn2t4z0x/RwMTi0or3Lq3UNBRpj0VVin8oLed6LPoRm6l5PvYTAmpii3 WEGTiJyG6ed7lFiHmXph33Wv7Xhn56g+Qlk29D6wb33UrYaTaoupvrNZFx1vm5wipvz8 B40w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683282336; x=1685874336; 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=bGtQROW8CgSIpc8sC+xnf/7FVLmoH1qm1QTvSE8uz7Q=; b=UjflSJZMdyWUSQYzeaJ1BaXcKbl8i8DI3/8Gh31Nn69Fxx+JjRF+/0MiH78KYRhh2N nG6nrvzFZvqb9RIJYh4o004xkoZ1EPiCD8/JenI33jJbfYivf70pI97BcQvV6UwGnAm/ E1RlWEWuVGvQwzRPzJ4s140uRLLr4895OHQyuvBFW3WjyoTEocTPN6a57euM4eiCGIVV BsNjMDZeKdSf3AHCo2C2wj0Uz0McdgrYAj6OSs68j7sYARVVzF0RC2jby46vTRAYK7dz u++US5jzd58bmuXzCoVwEF5Cltpd38GxbthJl8BK4TlYekP7wPdtd9Z1ppIuLTFN1kUF 2u+g== X-Gm-Message-State: AC+VfDwGtonVsymMB9gClQjWLnVFKkZS75rGoKwqKiqNPx3VpjPAXEWg 42mAhnM5vfXcLE2TEznFavJy6H1vn6mwIH2/BWyIsLKY X-Received: by 2002:a05:6830:14da:b0:6a5:dc9f:6cd9 with SMTP id t26-20020a05683014da00b006a5dc9f6cd9mr373612otq.9.1683282336340; Fri, 05 May 2023 03:25:36 -0700 (PDT) Received: from ledge.ozog.com ([2604:1380:4111:b700::1]) by smtp.gmail.com with ESMTPSA id b21-20020a056830105500b006a6169cf6b0sm635068otp.47.2023.05.05.03.25.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 May 2023 03:25:35 -0700 (PDT) From: Maxim Uvarov To: u-boot@lists.denx.de Cc: pbrobinson@redhat.com, ilias.apalodimas@linaro.org, joe.hershberger@ni.com, rfried.dev@gmail.com, Maxim Uvarov Subject: [RFC PATCH 3/5] add doc/README.lwip Date: Fri, 5 May 2023 10:25:27 +0000 Message-ID: <20230505102529.1254445-4-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.40.1.476.g69c786637d In-Reply-To: <20230505102529.1254445-1-maxim.uvarov@linaro.org> References: <20230505102529.1254445-1-maxim.uvarov@linaro.org> MIME-Version: 1.0 X-Mailman-Approved-At: Fri, 05 May 2023 12:50:31 +0200 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 Signed-off-by: Maxim Uvarov --- doc/README.lwip | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 doc/README.lwip diff --git a/doc/README.lwip b/doc/README.lwip new file mode 100644 index 0000000000..df3462ca1b --- /dev/null +++ b/doc/README.lwip @@ -0,0 +1,56 @@ + RFC LWIP IP stack intergation for U-boot + ---------------------------------------- + +Reliable and bug free IP stack is usually an issue when you are trying to write it +from scratch. It looks like not, but when addinging new features it will be chelledging. +This RFC work is a demo to enable lwIP (lightweight IP) which is a widely used open-source +TCP/IP stack designed for embedded systems for U-boot. That will allow using already +written network applications for microcontrollers. + +LwIP  license: +lwIP is licensed under a BSD-style license: http://lwip.wikia.com/wiki/License. + +Main features include: +- Protocols: IP, IPv6, ICMP, ND, MLD, UDP, TCP, IGMP, ARP, PPPoS, PPPoE +- DHCP client, DNS client (incl. mDNS hostname resolver), AutoIP/APIPA (Zeroconf), SNMP agent (v1, v2c, v3, private MIB support & MIB compiler) +- APIs: specialized APIs for enhanced performance, optional Berkeley-alike socket API +- Extended features: IP forwarding over multiple network interfaces, TCP congestion control, RTT estimation and fast recovery/fast retransmit +- Addon applications: HTTP(S) server, SNTP client, SMTP(S) client, ping, NetBIOS nameserver, mDNS responder, MQTT client, TFTP server + +U-boot implementation details: + +1. In general we can build lwIP as .a library and link it against u-boot or compile it in +the U-boot tree in the same way as other U-boot files. There are few reasons why I selected +the second variant: iwIP is very customizable with defines for features, memory size, types of +allocation, some internal types and platform specific code. And it was more easy to enable/disable + debug which is also done with defines, and is needed periodically. + +2. lwIP has 2 APIs - raw mode and sequential (as lwIP names it, or socket API as we name it in Linux). + This RFC implements only raw API as the proof of work. + +Raw IP means that the call back function for RX path is registered and will be called when packet +data passes the IP stack and is ready for the application. + +This RFC has an unmodified working ping example from lwip sources which registeres this callback. +  ping_pcb = raw_new(IP_PROTO_ICMP); +  raw_recv(ping_pcb, ping_recv, NULL); <- ping_recv is app callback. +  raw_bind(ping_pcb, IP_ADDR_ANY) + +Socket API also gives nice advantages due it will be easy to port linux socket applications to u-boot. +I.e. lwIP sockets compatible with the linux ones. But that will require RX thread running in the background. +So that means we need some kind of scheduler, locking and threading support or find some other solution. + +3.  Input and output + +RX packet path is injected to U-boot eth_rx() polling loop and TX patch is in eth_send() accordingly. +So we do not touch any drivers code and just eat packets when they are ready. + +4. Testing + +Unmodified ping example can be used. I did ping from qemu/u-boot tap device on the host: + +=> lwip init +=> lwip ping 192.168.1.2 +ping: recv 3 ms +tcpdump on the host: +5:09:10.925951 ARP, Request who-has 192.168.1.200 tell 192.168.1.200, length 28 15:09:12.114643 IP6 fe80::38e2:41ff:fec3:8bda > ip6-allrouters: ICMP6, router solicitation, length 16 15:09:20.370725 ARP, Request who-has 192.168.1.2 tell 192.168.1.200, length 28 15:09:20.370740 ARP, Reply 192.168.1.2 is-at 3a:e2:41:c3:8b:da (oui Unknown), length 28 15:09:20.372789 IP 192.168.1.200 > 192.168.1.2: ICMP echo request, id 44975, seq 1, length 40 15:09:20.372810 IP 192.168.1.2 > 192.168.1.200: ICMP echo reply, id 44975, seq 1, length 40 15:09:25.426636 ARP, Request who-has 192.168.1.200 tell 192.168.1.2, length 28 15:09:25.426870 ARP, Reply 192.168.1.200 is-at f6:11:01:02:03:04 (oui Unknown), length 28