From patchwork Mon Jul 2 19:47:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Hershberger X-Patchwork-Id: 938157 X-Patchwork-Delegate: joe.hershberger@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ni.com Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41KHt85f1Nz9s2g for ; Tue, 3 Jul 2018 05:50:40 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 76A12C21E62; Mon, 2 Jul 2018 19:49:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 93C05C21E8A; Mon, 2 Jul 2018 19:48:11 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 658C8C21DA6; Mon, 2 Jul 2018 19:48:07 +0000 (UTC) Received: from mx0b-00010702.pphosted.com (mx0a-00010702.pphosted.com [148.163.156.75]) by lists.denx.de (Postfix) with ESMTPS id 80014C21DAF for ; Mon, 2 Jul 2018 19:48:06 +0000 (UTC) Received: from pps.filterd (m0098781.ppops.net [127.0.0.1]) by mx0a-00010702.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w62JePYM027350; Mon, 2 Jul 2018 14:47:59 -0500 Received: from ni.com (skprod3.natinst.com [130.164.80.24]) by mx0a-00010702.pphosted.com with ESMTP id 2jx5w0wtj7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 02 Jul 2018 14:47:59 -0500 Received: from us-aus-exhub1.ni.corp.natinst.com (us-aus-exhub1.ni.corp.natinst.com [130.164.68.41]) by us-aus-skprod3.natinst.com (8.16.0.22/8.16.0.22) with ESMTPS id w62JlwgU031906 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 2 Jul 2018 14:47:58 -0500 Received: from us-aus-exch4.ni.corp.natinst.com (130.164.68.14) by us-aus-exhub1.ni.corp.natinst.com (130.164.68.41) with Microsoft SMTP Server (TLS) id 15.0.1156.6; Mon, 2 Jul 2018 14:47:58 -0500 Received: from us-aus-exhub2.ni.corp.natinst.com (130.164.68.32) by us-aus-exch4.ni.corp.natinst.com (130.164.68.14) with Microsoft SMTP Server (TLS) id 15.0.1156.6; Mon, 2 Jul 2018 14:47:58 -0500 Received: from osboxes.amer.corp.natinst.com (130.164.49.7) by us-aus-exhub2.ni.corp.natinst.com (130.164.68.32) with Microsoft SMTP Server id 15.0.1156.6 via Frontend Transport; Mon, 2 Jul 2018 14:47:58 -0500 From: Joe Hershberger To: Date: Mon, 2 Jul 2018 14:47:44 -0500 Message-ID: <20180702194754.1955-2-joe.hershberger@ni.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180702194754.1955-1-joe.hershberger@ni.com> References: <20180702194754.1955-1-joe.hershberger@ni.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-07-02_06:, , signatures=0 X-Proofpoint-Spam-Reason: safe Cc: Heinrich Schuchardt , Joe Hershberger Subject: [U-Boot] [PATCH v3 01/11] sandbox: eth-raw: Correct valid socket test in send/recv X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" In open, the socket is correctly checked to be -1 in the error case. In send and recv, we checked for 0, but that is a valid socket number. Correct this by checking for -1 as a bad socket everywhere. Signed-off-by: Joe Hershberger Reviewed-by: Simon Glass --- Changes in v3: None Changes in v2: None arch/sandbox/cpu/eth-raw-os.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/sandbox/cpu/eth-raw-os.c b/arch/sandbox/cpu/eth-raw-os.c index e054a0702a..61f23ed210 100644 --- a/arch/sandbox/cpu/eth-raw-os.c +++ b/arch/sandbox/cpu/eth-raw-os.c @@ -156,7 +156,7 @@ int sandbox_eth_raw_os_send(void *packet, int length, int retval; struct udphdr *udph = packet + sizeof(struct iphdr); - if (!priv->sd || !priv->device) + if (priv->sd < 0 || !priv->device) return -EINVAL; /* @@ -221,7 +221,7 @@ int sandbox_eth_raw_os_recv(void *packet, int *length, int retval; int saddr_size; - if (!priv->sd || !priv->device) + if (priv->sd < 0 || !priv->device) return -EINVAL; saddr_size = sizeof(struct sockaddr); retval = recvfrom(priv->sd, packet, 1536, 0, From patchwork Mon Jul 2 19:47:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Hershberger X-Patchwork-Id: 938152 X-Patchwork-Delegate: joe.hershberger@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ni.com Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41KHqS230vz9s2g for ; Tue, 3 Jul 2018 05:48:18 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 9B6CDC21ED6; Mon, 2 Jul 2018 19:48:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 525C2C21DA2; Mon, 2 Jul 2018 19:48:08 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id F3E13C21E0B; Mon, 2 Jul 2018 19:48:06 +0000 (UTC) Received: from mx0b-00010702.pphosted.com (mx0a-00010702.pphosted.com [148.163.156.75]) by lists.denx.de (Postfix) with ESMTPS id 3A6A4C21D74 for ; Mon, 2 Jul 2018 19:48:06 +0000 (UTC) Received: from pps.filterd (m0098780.ppops.net [127.0.0.1]) by mx0a-00010702.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w62JeT28020839; Mon, 2 Jul 2018 14:47:59 -0500 Received: from ni.com (skprod2.natinst.com [130.164.80.23]) by mx0a-00010702.pphosted.com with ESMTP id 2jx7cswpe7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 02 Jul 2018 14:47:59 -0500 Received: from us-aus-exch1.ni.corp.natinst.com (us-aus-exch1.ni.corp.natinst.com [130.164.68.11]) by us-aus-skprod2.natinst.com (8.16.0.22/8.16.0.22) with ESMTPS id w62JlwKI031900 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 2 Jul 2018 14:47:58 -0500 Received: from us-aus-exhub2.ni.corp.natinst.com (130.164.68.32) by us-aus-exch1.ni.corp.natinst.com (130.164.68.11) with Microsoft SMTP Server (TLS) id 15.0.1156.6; Mon, 2 Jul 2018 14:47:58 -0500 Received: from osboxes.amer.corp.natinst.com (130.164.49.7) by us-aus-exhub2.ni.corp.natinst.com (130.164.68.32) with Microsoft SMTP Server id 15.0.1156.6 via Frontend Transport; Mon, 2 Jul 2018 14:47:58 -0500 From: Joe Hershberger To: Date: Mon, 2 Jul 2018 14:47:45 -0500 Message-ID: <20180702194754.1955-3-joe.hershberger@ni.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180702194754.1955-1-joe.hershberger@ni.com> References: <20180702194754.1955-1-joe.hershberger@ni.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-07-02_06:, , signatures=0 X-Proofpoint-Spam-Reason: safe Cc: Heinrich Schuchardt , Joe Hershberger Subject: [U-Boot] [PATCH v3 02/11] sandbox: Fix format of fake-host-hwaddr in test.dts X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" test.dts specified the fake MAC address as a u32 array. Instead it should be a u8 array. Signed-off-by: Joe Hershberger Reviewed-by: Simon Glass --- Changes in v3: None Changes in v2: - New patch arch/sandbox/dts/test.dts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index 5752bf547e..1b5ef430d2 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -155,25 +155,25 @@ eth@10002000 { compatible = "sandbox,eth"; reg = <0x10002000 0x1000>; - fake-host-hwaddr = <0x00 0x00 0x66 0x44 0x22 0x00>; + fake-host-hwaddr = [00 00 66 44 22 00]; }; eth_5: eth@10003000 { compatible = "sandbox,eth"; reg = <0x10003000 0x1000>; - fake-host-hwaddr = <0x00 0x00 0x66 0x44 0x22 0x11>; + fake-host-hwaddr = [00 00 66 44 22 11]; }; eth_3: sbe5 { compatible = "sandbox,eth"; reg = <0x10005000 0x1000>; - fake-host-hwaddr = <0x00 0x00 0x66 0x44 0x22 0x33>; + fake-host-hwaddr = [00 00 66 44 22 33]; }; eth@10004000 { compatible = "sandbox,eth"; reg = <0x10004000 0x1000>; - fake-host-hwaddr = <0x00 0x00 0x66 0x44 0x22 0x22>; + fake-host-hwaddr = [00 00 66 44 22 22]; }; gpio_a: base-gpios { From patchwork Mon Jul 2 19:47:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Hershberger X-Patchwork-Id: 938160 X-Patchwork-Delegate: joe.hershberger@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ni.com Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41KHwc2SR7z9s2g for ; Tue, 3 Jul 2018 05:52:48 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 0249DC21E76; Mon, 2 Jul 2018 19:50:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 9FA59C21DCA; Mon, 2 Jul 2018 19:48:14 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id A0084C21DA2; Mon, 2 Jul 2018 19:48:07 +0000 (UTC) Received: from mx0b-00010702.pphosted.com (mx0a-00010702.pphosted.com [148.163.156.75]) by lists.denx.de (Postfix) with ESMTPS id A665FC21DD9 for ; Mon, 2 Jul 2018 19:48:06 +0000 (UTC) Received: from pps.filterd (m0098781.ppops.net [127.0.0.1]) by mx0a-00010702.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w62JeTf3027373; Mon, 2 Jul 2018 14:48:00 -0500 Received: from ni.com (skprod2.natinst.com [130.164.80.23]) by mx0a-00010702.pphosted.com with ESMTP id 2jx5w0wtj8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 02 Jul 2018 14:48:00 -0500 Received: from us-aus-exhub1.ni.corp.natinst.com (us-aus-exhub1.ni.corp.natinst.com [130.164.68.41]) by us-aus-skprod2.natinst.com (8.16.0.22/8.16.0.22) with ESMTPS id w62JlxbM031903 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 2 Jul 2018 14:47:59 -0500 Received: from us-aus-exch7.ni.corp.natinst.com (130.164.68.17) by us-aus-exhub1.ni.corp.natinst.com (130.164.68.41) with Microsoft SMTP Server (TLS) id 15.0.1156.6; Mon, 2 Jul 2018 14:47:59 -0500 Received: from us-aus-exhub2.ni.corp.natinst.com (130.164.68.32) by us-aus-exch7.ni.corp.natinst.com (130.164.68.17) with Microsoft SMTP Server (TLS) id 15.0.1156.6; Mon, 2 Jul 2018 14:47:58 -0500 Received: from osboxes.amer.corp.natinst.com (130.164.49.7) by us-aus-exhub2.ni.corp.natinst.com (130.164.68.32) with Microsoft SMTP Server id 15.0.1156.6 via Frontend Transport; Mon, 2 Jul 2018 14:47:58 -0500 From: Joe Hershberger To: Date: Mon, 2 Jul 2018 14:47:46 -0500 Message-ID: <20180702194754.1955-4-joe.hershberger@ni.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180702194754.1955-1-joe.hershberger@ni.com> References: <20180702194754.1955-1-joe.hershberger@ni.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-07-02_06:, , signatures=0 X-Proofpoint-Spam-Reason: safe Cc: Heinrich Schuchardt , Joe Hershberger Subject: [U-Boot] [PATCH v3 03/11] net: Only call halt on a driver that has been init'ed X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" With driver model, we were not checking if the state of the device was marked as active before calling the halt function. Check that the device is probed and also marked as active. This avoids the case where we were calling halt on the first device in net_init() and the driver would operate on bogus data structures causing problems. In this case, the priv was all 0, so halt() would close STDIN. Signed-off-by: Joe Hershberger Reviewed-by: Simon Glass --- Changes in v3: None Changes in v2: None net/eth-uclass.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/eth-uclass.c b/net/eth-uclass.c index e4b49229e3..fa3f5497a2 100644 --- a/net/eth-uclass.c +++ b/net/eth-uclass.c @@ -307,7 +307,7 @@ void eth_halt(void) struct eth_device_priv *priv; current = eth_get_dev(); - if (!current || !device_active(current)) + if (!current || !eth_is_active(current)) return; eth_get_ops(current)->stop(current); From patchwork Mon Jul 2 19:47:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Hershberger X-Patchwork-Id: 938156 X-Patchwork-Delegate: joe.hershberger@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ni.com Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41KHsS2sQ1z9s2g for ; Tue, 3 Jul 2018 05:50:04 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 0C3FFC21DA6; Mon, 2 Jul 2018 19:49:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id A4898C21E57; Mon, 2 Jul 2018 19:48:12 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 72819C21DAF; Mon, 2 Jul 2018 19:48:07 +0000 (UTC) Received: from mx0b-00010702.pphosted.com (mx0a-00010702.pphosted.com [148.163.156.75]) by lists.denx.de (Postfix) with ESMTPS id 6F614C21DA6 for ; Mon, 2 Jul 2018 19:48:06 +0000 (UTC) Received: from pps.filterd (m0098780.ppops.net [127.0.0.1]) by mx0a-00010702.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w62JeRNn020534; Mon, 2 Jul 2018 14:48:00 -0500 Received: from ni.com (skprod3.natinst.com [130.164.80.24]) by mx0a-00010702.pphosted.com with ESMTP id 2jx7cswpe8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 02 Jul 2018 14:48:00 -0500 Received: from us-aus-exch1.ni.corp.natinst.com (us-aus-exch1.ni.corp.natinst.com [130.164.68.11]) by us-aus-skprod3.natinst.com (8.16.0.22/8.16.0.22) with ESMTPS id w62JlxRl031909 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 2 Jul 2018 14:47:59 -0500 Received: from us-aus-exch3.ni.corp.natinst.com (130.164.68.13) by us-aus-exch1.ni.corp.natinst.com (130.164.68.11) with Microsoft SMTP Server (TLS) id 15.0.1156.6; Mon, 2 Jul 2018 14:47:58 -0500 Received: from us-aus-exhub2.ni.corp.natinst.com (130.164.68.32) by us-aus-exch3.ni.corp.natinst.com (130.164.68.13) with Microsoft SMTP Server (TLS) id 15.0.1156.6; Mon, 2 Jul 2018 14:47:58 -0500 Received: from osboxes.amer.corp.natinst.com (130.164.49.7) by us-aus-exhub2.ni.corp.natinst.com (130.164.68.32) with Microsoft SMTP Server id 15.0.1156.6 via Frontend Transport; Mon, 2 Jul 2018 14:47:58 -0500 From: Joe Hershberger To: Date: Mon, 2 Jul 2018 14:47:47 -0500 Message-ID: <20180702194754.1955-5-joe.hershberger@ni.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180702194754.1955-1-joe.hershberger@ni.com> References: <20180702194754.1955-1-joe.hershberger@ni.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-07-02_06:, , signatures=0 X-Proofpoint-Spam-Reason: safe Cc: Heinrich Schuchardt , Joe Hershberger Subject: [U-Boot] [PATCH v3 04/11] sandbox: eth-raw: Make sure descriptors are always initialized X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" If we let descriptors equal 0, we can end up closing STDIN. Make sure they start out as -1. Signed-off-by: Joe Hershberger Reviewed-by: Simon Glass --- Changes in v3: None Changes in v2: None arch/sandbox/cpu/eth-raw-os.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/sandbox/cpu/eth-raw-os.c b/arch/sandbox/cpu/eth-raw-os.c index 61f23ed210..4263d8829a 100644 --- a/arch/sandbox/cpu/eth-raw-os.c +++ b/arch/sandbox/cpu/eth-raw-os.c @@ -34,6 +34,7 @@ static int _raw_packet_start(const char *ifname, unsigned char *ethmac, int flags; /* Prepare device struct */ + priv->local_bind_sd = -1; priv->device = malloc(sizeof(struct sockaddr_ll)); if (priv->device == NULL) return -ENOMEM; @@ -103,6 +104,8 @@ static int _local_inet_start(struct eth_sandbox_raw_priv *priv) int one = 1; /* Prepare device struct */ + priv->local_bind_sd = -1; + priv->local_bind_udp_port = 0; priv->device = malloc(sizeof(struct sockaddr_in)); if (priv->device == NULL) return -ENOMEM; @@ -136,8 +139,6 @@ static int _local_inet_start(struct eth_sandbox_raw_priv *priv) strerror(errno)); return -errno; } - priv->local_bind_sd = -1; - priv->local_bind_udp_port = 0; return 0; } From patchwork Mon Jul 2 19:47:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Hershberger X-Patchwork-Id: 938158 X-Patchwork-Delegate: joe.hershberger@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ni.com Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41KHvy5czjz9s2g for ; Tue, 3 Jul 2018 05:52:14 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 762B4C21DFB; Mon, 2 Jul 2018 19:49:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id D9411C21E70; Mon, 2 Jul 2018 19:48:10 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 59281C21DA2; Mon, 2 Jul 2018 19:48:07 +0000 (UTC) Received: from mx0b-00010702.pphosted.com (mx0a-00010702.pphosted.com [148.163.156.75]) by lists.denx.de (Postfix) with ESMTPS id 56328C21DA2 for ; Mon, 2 Jul 2018 19:48:06 +0000 (UTC) Received: from pps.filterd (m0098781.ppops.net [127.0.0.1]) by mx0a-00010702.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w62JeSNs027356; Mon, 2 Jul 2018 14:48:00 -0500 Received: from ni.com (skprod2.natinst.com [130.164.80.23]) by mx0a-00010702.pphosted.com with ESMTP id 2jx5w0wtj9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 02 Jul 2018 14:48:00 -0500 Received: from us-aus-exhub2.ni.corp.natinst.com (us-aus-exhub2.ni.corp.natinst.com [130.164.68.32]) by us-aus-skprod2.natinst.com (8.16.0.22/8.16.0.22) with ESMTPS id w62Jlxcb031907 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 2 Jul 2018 14:47:59 -0500 Received: from us-aus-exch5.ni.corp.natinst.com (130.164.68.15) by us-aus-exhub2.ni.corp.natinst.com (130.164.68.32) with Microsoft SMTP Server (TLS) id 15.0.1156.6; Mon, 2 Jul 2018 14:47:59 -0500 Received: from us-aus-exhub2.ni.corp.natinst.com (130.164.68.32) by us-aus-exch5.ni.corp.natinst.com (130.164.68.15) with Microsoft SMTP Server (TLS) id 15.0.1156.6; Mon, 2 Jul 2018 14:47:59 -0500 Received: from osboxes.amer.corp.natinst.com (130.164.49.7) by us-aus-exhub2.ni.corp.natinst.com (130.164.68.32) with Microsoft SMTP Server id 15.0.1156.6 via Frontend Transport; Mon, 2 Jul 2018 14:47:59 -0500 From: Joe Hershberger To: Date: Mon, 2 Jul 2018 14:47:48 -0500 Message-ID: <20180702194754.1955-6-joe.hershberger@ni.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180702194754.1955-1-joe.hershberger@ni.com> References: <20180702194754.1955-1-joe.hershberger@ni.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-07-02_06:, , signatures=0 X-Proofpoint-Spam-Reason: safe Cc: Heinrich Schuchardt , Joe Hershberger Subject: [U-Boot] [PATCH v3 05/11] net: Correct comment in Kconfig X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" Signed-off-by: Joe Hershberger Reviewed-by: Simon Glass --- Changes in v3: - s/UC_ETH/UCLASS_ETH/ Changes in v2: None drivers/net/Kconfig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig index e88f056d84..79eef2d755 100644 --- a/drivers/net/Kconfig +++ b/drivers/net/Kconfig @@ -7,8 +7,8 @@ config DM_ETH help Enable driver model for Ethernet. - The eth_*() interface will be implemented by the UC_ETH class - This is currently implemented in net/eth.c + The eth_*() interface will be implemented by the UCLASS_ETH class + This is currently implemented in net/eth-uclass.c Look in include/net.h for details. config DRIVER_TI_CPSW From patchwork Mon Jul 2 19:47:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Hershberger X-Patchwork-Id: 938153 X-Patchwork-Delegate: joe.hershberger@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ni.com Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41KHqp1R2jz9s3C for ; Tue, 3 Jul 2018 05:48:38 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id D54C7C21E31; Mon, 2 Jul 2018 19:48:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 11212C21E2C; Mon, 2 Jul 2018 19:48:09 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 0CE8FC21D74; Mon, 2 Jul 2018 19:48:06 +0000 (UTC) Received: from mx0b-00010702.pphosted.com (mx0a-00010702.pphosted.com [148.163.156.75]) by lists.denx.de (Postfix) with ESMTPS id 4A36FC21D9A for ; Mon, 2 Jul 2018 19:48:06 +0000 (UTC) Received: from pps.filterd (m0098780.ppops.net [127.0.0.1]) by mx0a-00010702.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w62JeT29020839; Mon, 2 Jul 2018 14:48:00 -0500 Received: from ni.com (skprod2.natinst.com [130.164.80.23]) by mx0a-00010702.pphosted.com with ESMTP id 2jx7cswpe9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 02 Jul 2018 14:48:00 -0500 Received: from us-aus-exch2.ni.corp.natinst.com (us-aus-exch2.ni.corp.natinst.com [130.164.68.12]) by us-aus-skprod2.natinst.com (8.16.0.22/8.16.0.22) with ESMTPS id w62JlxtF031906 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 2 Jul 2018 14:47:59 -0500 Received: from us-aus-exhub2.ni.corp.natinst.com (130.164.68.32) by us-aus-exch2.ni.corp.natinst.com (130.164.68.12) with Microsoft SMTP Server (TLS) id 15.0.1156.6; Mon, 2 Jul 2018 14:47:59 -0500 Received: from osboxes.amer.corp.natinst.com (130.164.49.7) by us-aus-exhub2.ni.corp.natinst.com (130.164.68.32) with Microsoft SMTP Server id 15.0.1156.6 via Frontend Transport; Mon, 2 Jul 2018 14:47:59 -0500 From: Joe Hershberger To: Date: Mon, 2 Jul 2018 14:47:49 -0500 Message-ID: <20180702194754.1955-7-joe.hershberger@ni.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180702194754.1955-1-joe.hershberger@ni.com> References: <20180702194754.1955-1-joe.hershberger@ni.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-07-02_06:, , signatures=0 X-Proofpoint-Spam-Reason: safe Cc: Heinrich Schuchardt , Joe Hershberger Subject: [U-Boot] [PATCH v3 06/11] net: sandbox: Convert sandbox mock eth driver to livetree X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" Use the dev_ functions to access DT properties. Signed-off-by: Joe Hershberger Reviewed-by: Simon Glass --- Changes in v3: None Changes in v2: - go back to u8_array - move DT accesses to ofdata_to_platdata() drivers/net/sandbox.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/net/sandbox.c b/drivers/net/sandbox.c index b34712bd06..b71c8f88d9 100644 --- a/drivers/net/sandbox.c +++ b/drivers/net/sandbox.c @@ -59,10 +59,8 @@ static int sb_eth_start(struct udevice *dev) debug("eth_sandbox: Start\n"); - fdtdec_get_byte_array(gd->fdt_blob, dev_of_offset(dev), - "fake-host-hwaddr", priv->fake_host_hwaddr, - ARP_HLEN); priv->recv_packet_buffer = net_rx_packets[0]; + return 0; } @@ -203,8 +201,18 @@ static int sb_eth_remove(struct udevice *dev) static int sb_eth_ofdata_to_platdata(struct udevice *dev) { struct eth_pdata *pdata = dev_get_platdata(dev); + struct eth_sandbox_priv *priv = dev_get_priv(dev); + const u8 *mac; + + pdata->iobase = dev_read_addr(dev); + + mac = dev_read_u8_array_ptr(dev, "fake-host-hwaddr", ARP_HLEN); + if (!mac) { + printf("'fake-host-hwaddr' is missing from the DT\n"); + return -EINVAL; + } + memcpy(priv->fake_host_hwaddr, mac, ARP_HLEN); - pdata->iobase = devfdt_get_addr(dev); return 0; } From patchwork Mon Jul 2 19:47:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Hershberger X-Patchwork-Id: 938155 X-Patchwork-Delegate: joe.hershberger@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ni.com Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41KHrq57t0z9s2g for ; Tue, 3 Jul 2018 05:49:31 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 57665C21E30; Mon, 2 Jul 2018 19:48:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_FRT_STOCK2 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id CFD01C21E49; Mon, 2 Jul 2018 19:48:09 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 2E637C21D9A; Mon, 2 Jul 2018 19:48:07 +0000 (UTC) Received: from mx0b-00010702.pphosted.com (mx0a-00010702.pphosted.com [148.163.156.75]) by lists.denx.de (Postfix) with ESMTPS id 88D9DC21DCA for ; Mon, 2 Jul 2018 19:48:06 +0000 (UTC) Received: from pps.filterd (m0098781.ppops.net [127.0.0.1]) by mx0a-00010702.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w62JeSNt027356; Mon, 2 Jul 2018 14:48:00 -0500 Received: from ni.com (skprod3.natinst.com [130.164.80.24]) by mx0a-00010702.pphosted.com with ESMTP id 2jx5w0wtja-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 02 Jul 2018 14:48:00 -0500 Received: from us-aus-exhub1.ni.corp.natinst.com (us-aus-exhub1.ni.corp.natinst.com [130.164.68.41]) by us-aus-skprod3.natinst.com (8.16.0.22/8.16.0.22) with ESMTPS id w62JlxrX031912 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 2 Jul 2018 14:47:59 -0500 Received: from us-aus-exhub2.ni.corp.natinst.com (130.164.68.32) by us-aus-exhub1.ni.corp.natinst.com (130.164.68.41) with Microsoft SMTP Server (TLS) id 15.0.1156.6; Mon, 2 Jul 2018 14:47:59 -0500 Received: from osboxes.amer.corp.natinst.com (130.164.49.7) by us-aus-exhub2.ni.corp.natinst.com (130.164.68.32) with Microsoft SMTP Server id 15.0.1156.6 via Frontend Transport; Mon, 2 Jul 2018 14:47:59 -0500 From: Joe Hershberger To: Date: Mon, 2 Jul 2018 14:47:50 -0500 Message-ID: <20180702194754.1955-8-joe.hershberger@ni.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180702194754.1955-1-joe.hershberger@ni.com> References: <20180702194754.1955-1-joe.hershberger@ni.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-07-02_06:, , signatures=0 X-Proofpoint-Spam-Reason: safe Cc: Heinrich Schuchardt , Joe Hershberger Subject: [U-Boot] [PATCH v3 07/11] net: sandbox-raw: Convert raw eth driver to livetree X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" Signed-off-by: Joe Hershberger Reviewed-by: Simon Glass --- Changes in v3: None Changes in v2: - move DT accesses to ofdata_to_platdata() - store the host interface details in priv - switch to dev_read_string() arch/sandbox/cpu/eth-raw-os.c | 28 +++++++++++++++------------- arch/sandbox/include/asm/eth-raw-os.h | 10 ++++++++-- drivers/net/sandbox-raw.c | 26 ++++++++++++++++---------- 3 files changed, 39 insertions(+), 25 deletions(-) diff --git a/arch/sandbox/cpu/eth-raw-os.c b/arch/sandbox/cpu/eth-raw-os.c index 4263d8829a..82bf666886 100644 --- a/arch/sandbox/cpu/eth-raw-os.c +++ b/arch/sandbox/cpu/eth-raw-os.c @@ -25,8 +25,8 @@ #include #include -static int _raw_packet_start(const char *ifname, unsigned char *ethmac, - struct eth_sandbox_raw_priv *priv) +static int _raw_packet_start(struct eth_sandbox_raw_priv *priv, + unsigned char *ethmac) { struct sockaddr_ll *device; struct packet_mreq mr; @@ -40,7 +40,8 @@ static int _raw_packet_start(const char *ifname, unsigned char *ethmac, return -ENOMEM; device = priv->device; memset(device, 0, sizeof(struct sockaddr_ll)); - device->sll_ifindex = if_nametoindex(ifname); + device->sll_ifindex = if_nametoindex(priv->host_ifname); + priv->host_ifindex = device->sll_ifindex; device->sll_family = AF_PACKET; memcpy(device->sll_addr, ethmac, 6); device->sll_halen = htons(6); @@ -53,11 +54,11 @@ static int _raw_packet_start(const char *ifname, unsigned char *ethmac, return -errno; } /* Bind to the specified interface */ - ret = setsockopt(priv->sd, SOL_SOCKET, SO_BINDTODEVICE, ifname, - strlen(ifname) + 1); + ret = setsockopt(priv->sd, SOL_SOCKET, SO_BINDTODEVICE, + priv->host_ifname, strlen(priv->host_ifname) + 1); if (ret < 0) { - printf("Failed to bind to '%s': %d %s\n", ifname, errno, - strerror(errno)); + printf("Failed to bind to '%s': %d %s\n", priv->host_ifname, + errno, strerror(errno)); return -errno; } @@ -76,11 +77,12 @@ static int _raw_packet_start(const char *ifname, unsigned char *ethmac, printf("Failed to set promiscuous mode: %d %s\n" "Falling back to the old \"flags\" way...\n", errno, strerror(errno)); - if (strlen(ifname) >= IFNAMSIZ) { - printf("Interface name %s is too long.\n", ifname); + if (strlen(priv->host_ifname) >= IFNAMSIZ) { + printf("Interface name %s is too long.\n", + priv->host_ifname); return -EINVAL; } - strncpy(ifr.ifr_name, ifname, IFNAMSIZ); + strncpy(ifr.ifr_name, priv->host_ifname, IFNAMSIZ); if (ioctl(priv->sd, SIOCGIFFLAGS, &ifr) < 0) { printf("Failed to read flags: %d %s\n", errno, strerror(errno)); @@ -142,13 +144,13 @@ static int _local_inet_start(struct eth_sandbox_raw_priv *priv) return 0; } -int sandbox_eth_raw_os_start(const char *ifname, unsigned char *ethmac, - struct eth_sandbox_raw_priv *priv) +int sandbox_eth_raw_os_start(struct eth_sandbox_raw_priv *priv, + unsigned char *ethmac) { if (priv->local) return _local_inet_start(priv); else - return _raw_packet_start(ifname, ethmac, priv); + return _raw_packet_start(priv, ethmac); } int sandbox_eth_raw_os_send(void *packet, int length, diff --git a/arch/sandbox/include/asm/eth-raw-os.h b/arch/sandbox/include/asm/eth-raw-os.h index f986d3142d..760f5fbedd 100644 --- a/arch/sandbox/include/asm/eth-raw-os.h +++ b/arch/sandbox/include/asm/eth-raw-os.h @@ -9,10 +9,14 @@ #ifndef __ETH_RAW_OS_H #define __ETH_RAW_OS_H +#define IFNAMSIZ 16 + /** * struct eth_sandbox_raw_priv - raw socket session * * sd: socket descriptor - the open socket during a session + * host_ifname: interface name on the host to use for sending our packets + * host_ifindex: interface index number on the host * device: struct sockaddr_ll - the host interface packets move to/from * local: 1 or 0 to select the local interface ('lo') or not * local_bindsd: socket descriptor to prevent the kernel from sending @@ -22,14 +26,16 @@ */ struct eth_sandbox_raw_priv { int sd; + char host_ifname[IFNAMSIZ]; + unsigned int host_ifindex; void *device; int local; int local_bind_sd; unsigned short local_bind_udp_port; }; -int sandbox_eth_raw_os_start(const char *ifname, unsigned char *ethmac, - struct eth_sandbox_raw_priv *priv); +int sandbox_eth_raw_os_start(struct eth_sandbox_raw_priv *priv, + unsigned char *ethmac); int sandbox_eth_raw_os_send(void *packet, int length, struct eth_sandbox_raw_priv *priv); int sandbox_eth_raw_os_recv(void *packet, int *length, diff --git a/drivers/net/sandbox-raw.c b/drivers/net/sandbox-raw.c index 3f8020f629..317e964019 100644 --- a/drivers/net/sandbox-raw.c +++ b/drivers/net/sandbox-raw.c @@ -21,21 +21,16 @@ static int sb_eth_raw_start(struct udevice *dev) { struct eth_sandbox_raw_priv *priv = dev_get_priv(dev); struct eth_pdata *pdata = dev_get_platdata(dev); - const char *interface; + int ret; debug("eth_sandbox_raw: Start\n"); - interface = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), - "host-raw-interface", NULL); - if (interface == NULL) - return -EINVAL; - - if (strcmp(interface, "lo") == 0) { - priv->local = 1; + ret = sandbox_eth_raw_os_start(priv, pdata->enetaddr); + if (priv->local) { env_set("ipaddr", "127.0.0.1"); env_set("serverip", "127.0.0.1"); } - return sandbox_eth_raw_os_start(interface, pdata->enetaddr, priv); + return ret; } static int sb_eth_raw_send(struct udevice *dev, void *packet, int length) @@ -143,8 +138,19 @@ static const struct eth_ops sb_eth_raw_ops = { static int sb_eth_raw_ofdata_to_platdata(struct udevice *dev) { struct eth_pdata *pdata = dev_get_platdata(dev); + struct eth_sandbox_raw_priv *priv = dev_get_priv(dev); + const char *ifname; + + pdata->iobase = dev_read_addr(dev); + + ifname = dev_read_string(dev, "host-raw-interface"); + if (ifname) { + strncpy(priv->host_ifname, ifname, IFNAMSIZ); + printf(": Using %s from DT\n", priv->host_ifname); + if (strcmp(ifname, "lo") == 0) + priv->local = 1; + } - pdata->iobase = devfdt_get_addr(dev); return 0; } From patchwork Mon Jul 2 19:47:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Hershberger X-Patchwork-Id: 938161 X-Patchwork-Delegate: joe.hershberger@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ni.com Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41KHyD53gvz9s2g for ; Tue, 3 Jul 2018 05:54:12 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 590CFC21E52; Mon, 2 Jul 2018 19:50:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 6E6A0C21ECF; Mon, 2 Jul 2018 19:48:15 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id B424FC21DA6; Mon, 2 Jul 2018 19:48:07 +0000 (UTC) Received: from mx0b-00010702.pphosted.com (mx0a-00010702.pphosted.com [148.163.156.75]) by lists.denx.de (Postfix) with ESMTPS id D25EBC21DFB for ; Mon, 2 Jul 2018 19:48:06 +0000 (UTC) Received: from pps.filterd (m0098780.ppops.net [127.0.0.1]) by mx0a-00010702.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w62JeT2A020839; Mon, 2 Jul 2018 14:48:01 -0500 Received: from ni.com (skprod3.natinst.com [130.164.80.24]) by mx0a-00010702.pphosted.com with ESMTP id 2jx7cswpea-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 02 Jul 2018 14:48:01 -0500 Received: from us-aus-exch2.ni.corp.natinst.com (us-aus-exch2.ni.corp.natinst.com [130.164.68.12]) by us-aus-skprod3.natinst.com (8.16.0.22/8.16.0.22) with ESMTPS id w62Jm06h031915 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 2 Jul 2018 14:48:00 -0500 Received: from us-aus-exch4.ni.corp.natinst.com (130.164.68.14) by us-aus-exch2.ni.corp.natinst.com (130.164.68.12) with Microsoft SMTP Server (TLS) id 15.0.1156.6; Mon, 2 Jul 2018 14:47:59 -0500 Received: from us-aus-exhub2.ni.corp.natinst.com (130.164.68.32) by us-aus-exch4.ni.corp.natinst.com (130.164.68.14) with Microsoft SMTP Server (TLS) id 15.0.1156.6; Mon, 2 Jul 2018 14:47:59 -0500 Received: from osboxes.amer.corp.natinst.com (130.164.49.7) by us-aus-exhub2.ni.corp.natinst.com (130.164.68.32) with Microsoft SMTP Server id 15.0.1156.6 via Frontend Transport; Mon, 2 Jul 2018 14:47:59 -0500 From: Joe Hershberger To: Date: Mon, 2 Jul 2018 14:47:51 -0500 Message-ID: <20180702194754.1955-9-joe.hershberger@ni.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180702194754.1955-1-joe.hershberger@ni.com> References: <20180702194754.1955-1-joe.hershberger@ni.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-07-02_06:, , signatures=0 X-Proofpoint-Spam-Reason: safe Cc: Heinrich Schuchardt , Joe Hershberger Subject: [U-Boot] [PATCH v3 08/11] sandbox: eth-raw: Add a function to ask the host about localhost X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" Instead of doing a simple string compare against "lo", look for the flag that indicates a localhost interface. Signed-off-by: Joe Hershberger Reviewed-by: Simon Glass --- Changes in v3: None Changes in v2: None arch/sandbox/cpu/eth-raw-os.c | 27 +++++++++++++++++++++++---- arch/sandbox/include/asm/eth-raw-os.h | 8 ++++++++ drivers/net/sandbox-raw.c | 10 ++++++++-- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/arch/sandbox/cpu/eth-raw-os.c b/arch/sandbox/cpu/eth-raw-os.c index 82bf666886..12ddb345d9 100644 --- a/arch/sandbox/cpu/eth-raw-os.c +++ b/arch/sandbox/cpu/eth-raw-os.c @@ -1,9 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 /* - * Copyright (c) 2015 National Instruments - * - * (C) Copyright 2015 - * Joe Hershberger + * Copyright (c) 2015-2018 National Instruments + * Copyright (c) 2015-2018 Joe Hershberger */ #include @@ -25,6 +23,27 @@ #include #include +int sandbox_eth_raw_os_is_local(const char *ifname) +{ + int fd = socket(AF_INET, SOCK_DGRAM, 0); + struct ifreq ifr; + int ret = 0; + + if (fd < 0) + return -errno; + memset(&ifr, 0, sizeof(ifr)); + strncpy(ifr.ifr_name, ifname, IFNAMSIZ); + ret = ioctl(fd, SIOCGIFFLAGS, &ifr); + if (ret < 0) { + ret = -errno; + goto out; + } + ret = !!(ifr.ifr_flags & IFF_LOOPBACK); +out: + close(fd); + return ret; +} + static int _raw_packet_start(struct eth_sandbox_raw_priv *priv, unsigned char *ethmac) { diff --git a/arch/sandbox/include/asm/eth-raw-os.h b/arch/sandbox/include/asm/eth-raw-os.h index 760f5fbedd..edd09d2e08 100644 --- a/arch/sandbox/include/asm/eth-raw-os.h +++ b/arch/sandbox/include/asm/eth-raw-os.h @@ -34,6 +34,14 @@ struct eth_sandbox_raw_priv { unsigned short local_bind_udp_port; }; +/* + * Check if the interface named "ifname" is a localhost interface or not. + * ifname - the interface name on the host to check + * + * returns - 0 if real interface, 1 if local, negative if error + */ +int sandbox_eth_raw_os_is_local(const char *ifname); + int sandbox_eth_raw_os_start(struct eth_sandbox_raw_priv *priv, unsigned char *ethmac); int sandbox_eth_raw_os_send(void *packet, int length, diff --git a/drivers/net/sandbox-raw.c b/drivers/net/sandbox-raw.c index 317e964019..c04b94c6e1 100644 --- a/drivers/net/sandbox-raw.c +++ b/drivers/net/sandbox-raw.c @@ -29,6 +29,8 @@ static int sb_eth_raw_start(struct udevice *dev) if (priv->local) { env_set("ipaddr", "127.0.0.1"); env_set("serverip", "127.0.0.1"); + net_ip = string_to_ip("127.0.0.1"); + net_server_ip = net_ip; } return ret; } @@ -140,6 +142,7 @@ static int sb_eth_raw_ofdata_to_platdata(struct udevice *dev) struct eth_pdata *pdata = dev_get_platdata(dev); struct eth_sandbox_raw_priv *priv = dev_get_priv(dev); const char *ifname; + u32 local; pdata->iobase = dev_read_addr(dev); @@ -147,10 +150,13 @@ static int sb_eth_raw_ofdata_to_platdata(struct udevice *dev) if (ifname) { strncpy(priv->host_ifname, ifname, IFNAMSIZ); printf(": Using %s from DT\n", priv->host_ifname); - if (strcmp(ifname, "lo") == 0) - priv->local = 1; } + local = sandbox_eth_raw_os_is_local(priv->host_ifname); + if (local < 0) + return local; + priv->local = local; + return 0; } From patchwork Mon Jul 2 19:47:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Hershberger X-Patchwork-Id: 938164 X-Patchwork-Delegate: joe.hershberger@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ni.com Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41KHzN5Vgcz9s2g for ; Tue, 3 Jul 2018 05:55:12 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 660E8C21DA6; Mon, 2 Jul 2018 19:51:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 49BF0C21E73; Mon, 2 Jul 2018 19:48:16 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id C9A1DC21D9A; Mon, 2 Jul 2018 19:48:07 +0000 (UTC) Received: from mx0b-00010702.pphosted.com (mx0a-00010702.pphosted.com [148.163.156.75]) by lists.denx.de (Postfix) with ESMTPS id A95FFC21DE8 for ; Mon, 2 Jul 2018 19:48:06 +0000 (UTC) Received: from pps.filterd (m0098780.ppops.net [127.0.0.1]) by mx0a-00010702.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w62JeO7p020492; Mon, 2 Jul 2018 14:48:01 -0500 Received: from ni.com (skprod2.natinst.com [130.164.80.23]) by mx0a-00010702.pphosted.com with ESMTP id 2jx7cswpeb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 02 Jul 2018 14:48:01 -0500 Received: from us-aus-exch1.ni.corp.natinst.com (us-aus-exch1.ni.corp.natinst.com [130.164.68.11]) by us-aus-skprod2.natinst.com (8.16.0.22/8.16.0.22) with ESMTPS id w62Jm08V031912 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 2 Jul 2018 14:48:00 -0500 Received: from us-aus-exhub2.ni.corp.natinst.com (130.164.68.32) by us-aus-exch1.ni.corp.natinst.com (130.164.68.11) with Microsoft SMTP Server (TLS) id 15.0.1156.6; Mon, 2 Jul 2018 14:47:59 -0500 Received: from osboxes.amer.corp.natinst.com (130.164.49.7) by us-aus-exhub2.ni.corp.natinst.com (130.164.68.32) with Microsoft SMTP Server id 15.0.1156.6 via Frontend Transport; Mon, 2 Jul 2018 14:47:59 -0500 From: Joe Hershberger To: Date: Mon, 2 Jul 2018 14:47:52 -0500 Message-ID: <20180702194754.1955-10-joe.hershberger@ni.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180702194754.1955-1-joe.hershberger@ni.com> References: <20180702194754.1955-1-joe.hershberger@ni.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-07-02_06:, , signatures=0 X-Proofpoint-Spam-Reason: safe Cc: Heinrich Schuchardt , Joe Hershberger Subject: [U-Boot] [PATCH v3 09/11] sandbox: eth-raw: Allow interface to be specified by index X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" With systemd stable interface names, eth0 will almost never exist. Instead of using that name in the sandbox.dts, use an index. Signed-off-by: Joe Hershberger Reviewed-by: Simon Glass --- Changes in v3: None Changes in v2: None arch/sandbox/cpu/eth-raw-os.c | 7 +++++++ arch/sandbox/include/asm/eth-raw-os.h | 9 +++++++++ drivers/net/sandbox-raw.c | 11 +++++++++++ 3 files changed, 27 insertions(+) diff --git a/arch/sandbox/cpu/eth-raw-os.c b/arch/sandbox/cpu/eth-raw-os.c index 12ddb345d9..df7acaa0bc 100644 --- a/arch/sandbox/cpu/eth-raw-os.c +++ b/arch/sandbox/cpu/eth-raw-os.c @@ -44,6 +44,13 @@ out: return ret; } +int sandbox_eth_raw_os_idx_to_name(struct eth_sandbox_raw_priv *priv) +{ + if (!if_indextoname(priv->host_ifindex, priv->host_ifname)) + return -errno; + return 0; +} + static int _raw_packet_start(struct eth_sandbox_raw_priv *priv, unsigned char *ethmac) { diff --git a/arch/sandbox/include/asm/eth-raw-os.h b/arch/sandbox/include/asm/eth-raw-os.h index edd09d2e08..99f674e82e 100644 --- a/arch/sandbox/include/asm/eth-raw-os.h +++ b/arch/sandbox/include/asm/eth-raw-os.h @@ -42,6 +42,15 @@ struct eth_sandbox_raw_priv { */ int sandbox_eth_raw_os_is_local(const char *ifname); +/* + * Look up the name of the interface based on the ifindex populated in priv. + * + * Overwrite the host_ifname member in priv based on looking up host_ifindex + * + * returns - 0 if success, negative if error + */ +int sandbox_eth_raw_os_idx_to_name(struct eth_sandbox_raw_priv *priv); + int sandbox_eth_raw_os_start(struct eth_sandbox_raw_priv *priv, unsigned char *ethmac); int sandbox_eth_raw_os_send(void *packet, int length, diff --git a/drivers/net/sandbox-raw.c b/drivers/net/sandbox-raw.c index c04b94c6e1..0d1fd4d931 100644 --- a/drivers/net/sandbox-raw.c +++ b/drivers/net/sandbox-raw.c @@ -143,6 +143,7 @@ static int sb_eth_raw_ofdata_to_platdata(struct udevice *dev) struct eth_sandbox_raw_priv *priv = dev_get_priv(dev); const char *ifname; u32 local; + int ret; pdata->iobase = dev_read_addr(dev); @@ -151,6 +152,16 @@ static int sb_eth_raw_ofdata_to_platdata(struct udevice *dev) strncpy(priv->host_ifname, ifname, IFNAMSIZ); printf(": Using %s from DT\n", priv->host_ifname); } + if (dev_read_u32(dev, "host-raw-interface-idx", + &priv->host_ifindex) < 0) { + priv->host_ifindex = 0; + } else { + ret = sandbox_eth_raw_os_idx_to_name(priv); + if (ret < 0) + return ret; + printf(": Using interface index %d from DT (%s)\n", + priv->host_ifindex, priv->host_ifname); + } local = sandbox_eth_raw_os_is_local(priv->host_ifname); if (local < 0) From patchwork Mon Jul 2 19:47:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Hershberger X-Patchwork-Id: 938163 X-Patchwork-Delegate: joe.hershberger@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ni.com Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41KHyS4yk0z9s2g for ; Tue, 3 Jul 2018 05:54:24 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 70909C21E0B; Mon, 2 Jul 2018 19:51:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id D060BC21F07; Mon, 2 Jul 2018 19:48:20 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id ECCA0C21EC2; Mon, 2 Jul 2018 19:48:11 +0000 (UTC) Received: from mx0b-00010702.pphosted.com (mx0a-00010702.pphosted.com [148.163.156.75]) by lists.denx.de (Postfix) with ESMTPS id 3CB56C21D74 for ; Mon, 2 Jul 2018 19:48:08 +0000 (UTC) Received: from pps.filterd (m0098781.ppops.net [127.0.0.1]) by mx0a-00010702.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w62JeTf4027373; Mon, 2 Jul 2018 14:48:01 -0500 Received: from ni.com (skprod2.natinst.com [130.164.80.23]) by mx0a-00010702.pphosted.com with ESMTP id 2jx5w0wtjc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 02 Jul 2018 14:48:01 -0500 Received: from us-aus-exch2.ni.corp.natinst.com (us-aus-exch2.ni.corp.natinst.com [130.164.68.12]) by us-aus-skprod2.natinst.com (8.16.0.22/8.16.0.22) with ESMTPS id w62Jm00g031915 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 2 Jul 2018 14:48:00 -0500 Received: from us-aus-exch7.ni.corp.natinst.com (130.164.68.17) by us-aus-exch2.ni.corp.natinst.com (130.164.68.12) with Microsoft SMTP Server (TLS) id 15.0.1156.6; Mon, 2 Jul 2018 14:48:00 -0500 Received: from us-aus-exhub2.ni.corp.natinst.com (130.164.68.32) by us-aus-exch7.ni.corp.natinst.com (130.164.68.17) with Microsoft SMTP Server (TLS) id 15.0.1156.6; Mon, 2 Jul 2018 14:48:00 -0500 Received: from osboxes.amer.corp.natinst.com (130.164.49.7) by us-aus-exhub2.ni.corp.natinst.com (130.164.68.32) with Microsoft SMTP Server id 15.0.1156.6 via Frontend Transport; Mon, 2 Jul 2018 14:48:00 -0500 From: Joe Hershberger To: Date: Mon, 2 Jul 2018 14:47:53 -0500 Message-ID: <20180702194754.1955-11-joe.hershberger@ni.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180702194754.1955-1-joe.hershberger@ni.com> References: <20180702194754.1955-1-joe.hershberger@ni.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-07-02_06:, , signatures=0 X-Proofpoint-Spam-Reason: safe Cc: Heinrich Schuchardt , Joe Hershberger Subject: [U-Boot] [PATCH v3 10/11] sandbox: eth-raw: Make random MAC addresses available to eth-raw X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" We don't necessarily know how many MAC addresses we'll need, so implement a ROM read so we always have something valid. Signed-off-by: Joe Hershberger Reviewed-by: Simon Glass --- Changes in v3: None Changes in v2: None drivers/net/sandbox-raw.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/net/sandbox-raw.c b/drivers/net/sandbox-raw.c index 0d1fd4d931..09cc678ebd 100644 --- a/drivers/net/sandbox-raw.c +++ b/drivers/net/sandbox-raw.c @@ -130,11 +130,21 @@ static void sb_eth_raw_stop(struct udevice *dev) sandbox_eth_raw_os_stop(priv); } +static int sb_eth_raw_read_rom_hwaddr(struct udevice *dev) +{ + struct eth_pdata *pdata = dev_get_platdata(dev); + + net_random_ethaddr(pdata->enetaddr); + + return 0; +} + static const struct eth_ops sb_eth_raw_ops = { .start = sb_eth_raw_start, .send = sb_eth_raw_send, .recv = sb_eth_raw_recv, .stop = sb_eth_raw_stop, + .read_rom_hwaddr = sb_eth_raw_read_rom_hwaddr, }; static int sb_eth_raw_ofdata_to_platdata(struct udevice *dev) From patchwork Mon Jul 2 19:47:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Hershberger X-Patchwork-Id: 938159 X-Patchwork-Delegate: joe.hershberger@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ni.com Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41KHw34nNCz9s2g for ; Tue, 3 Jul 2018 05:52:19 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 5B435C21E68; Mon, 2 Jul 2018 19:51:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 1450DC21EFB; Mon, 2 Jul 2018 19:48:17 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id DE2EDC21DA2; Mon, 2 Jul 2018 19:48:07 +0000 (UTC) Received: from mx0b-00010702.pphosted.com (mx0a-00010702.pphosted.com [148.163.156.75]) by lists.denx.de (Postfix) with ESMTPS id 62214C21D74 for ; Mon, 2 Jul 2018 19:48:07 +0000 (UTC) Received: from pps.filterd (m0098780.ppops.net [127.0.0.1]) by mx0a-00010702.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w62JeO7q020492; Mon, 2 Jul 2018 14:48:01 -0500 Received: from ni.com (skprod3.natinst.com [130.164.80.24]) by mx0a-00010702.pphosted.com with ESMTP id 2jx7cswped-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 02 Jul 2018 14:48:01 -0500 Received: from us-aus-exhub2.ni.corp.natinst.com (us-aus-exhub2.ni.corp.natinst.com [130.164.68.32]) by us-aus-skprod3.natinst.com (8.16.0.22/8.16.0.22) with ESMTPS id w62Jm0Bx031918 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 2 Jul 2018 14:48:00 -0500 Received: from us-aus-exch3.ni.corp.natinst.com (130.164.68.13) by us-aus-exhub2.ni.corp.natinst.com (130.164.68.32) with Microsoft SMTP Server (TLS) id 15.0.1156.6; Mon, 2 Jul 2018 14:48:00 -0500 Received: from us-aus-exhub2.ni.corp.natinst.com (130.164.68.32) by us-aus-exch3.ni.corp.natinst.com (130.164.68.13) with Microsoft SMTP Server (TLS) id 15.0.1156.6; Mon, 2 Jul 2018 14:48:00 -0500 Received: from osboxes.amer.corp.natinst.com (130.164.49.7) by us-aus-exhub2.ni.corp.natinst.com (130.164.68.32) with Microsoft SMTP Server id 15.0.1156.6 via Frontend Transport; Mon, 2 Jul 2018 14:48:00 -0500 From: Joe Hershberger To: Date: Mon, 2 Jul 2018 14:47:54 -0500 Message-ID: <20180702194754.1955-12-joe.hershberger@ni.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180702194754.1955-1-joe.hershberger@ni.com> References: <20180702194754.1955-1-joe.hershberger@ni.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-07-02_06:, , signatures=0 X-Proofpoint-Spam-Reason: safe Cc: Heinrich Schuchardt , Joe Hershberger Subject: [U-Boot] [PATCH v3 11/11] sandbox: eth-raw: Add a SIMPLE_BUS to enumerate host interfaces X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" Ask the OS for each of its interfaces and for each one, bind a U-Boot device and then probe it. This will allocate the priv data structure that is then populated. Signed-off-by: Joe Hershberger Reviewed-by: Simon Glass --- Changes in v3: - use a string constant for host prefix - use calloc Changes in v2: None arch/sandbox/cpu/eth-raw-os.c | 10 ++++++ arch/sandbox/dts/sandbox.dts | 19 ++++------ arch/sandbox/dts/sandbox64.dts | 19 ++++------ arch/sandbox/include/asm/eth-raw-os.h | 11 ++++++ drivers/net/Makefile | 1 + drivers/net/sandbox-raw-bus.c | 66 +++++++++++++++++++++++++++++++++++ 6 files changed, 100 insertions(+), 26 deletions(-) create mode 100644 drivers/net/sandbox-raw-bus.c diff --git a/arch/sandbox/cpu/eth-raw-os.c b/arch/sandbox/cpu/eth-raw-os.c index df7acaa0bc..75bfaa4c90 100644 --- a/arch/sandbox/cpu/eth-raw-os.c +++ b/arch/sandbox/cpu/eth-raw-os.c @@ -23,6 +23,16 @@ #include #include +struct sandbox_eth_raw_if_nameindex *sandbox_eth_raw_if_nameindex(void) +{ + return (struct sandbox_eth_raw_if_nameindex *)if_nameindex(); +} + +void sandbox_eth_raw_if_freenameindex(struct sandbox_eth_raw_if_nameindex *ptr) +{ + if_freenameindex((struct if_nameindex *)ptr); +} + int sandbox_eth_raw_os_is_local(const char *ifname) { int fd = socket(AF_INET, SOCK_DGRAM, 0); diff --git a/arch/sandbox/dts/sandbox.dts b/arch/sandbox/dts/sandbox.dts index 0ea2452742..9164194023 100644 --- a/arch/sandbox/dts/sandbox.dts +++ b/arch/sandbox/dts/sandbox.dts @@ -8,7 +8,6 @@ model = "sandbox"; aliases { - eth5 = "/eth@90000000"; i2c0 = &i2c_0; pci0 = &pci; rtc0 = &rtc_0; @@ -47,24 +46,18 @@ }; }; + ethrawbus { + reg = <0 0>; + compatible = "sandbox,eth-raw-bus"; + skip-localhost = <0>; + }; + eth@10002000 { compatible = "sandbox,eth"; reg = <0x10002000 0x1000>; fake-host-hwaddr = [00 00 66 44 22 00]; }; - eth@80000000 { - compatible = "sandbox,eth-raw"; - reg = <0x80000000 0x1000>; - host-raw-interface = "eth0"; - }; - - eth@90000000 { - compatible = "sandbox,eth-raw"; - reg = <0x90000000 0x1000>; - host-raw-interface = "lo"; - }; - gpio_a: gpios@0 { gpio-controller; compatible = "sandbox,gpio"; diff --git a/arch/sandbox/dts/sandbox64.dts b/arch/sandbox/dts/sandbox64.dts index 48e420e721..4a2fa9908e 100644 --- a/arch/sandbox/dts/sandbox64.dts +++ b/arch/sandbox/dts/sandbox64.dts @@ -8,7 +8,6 @@ model = "sandbox"; aliases { - eth5 = "/eth@90000000"; i2c0 = &i2c_0; pci0 = &pci; rtc0 = &rtc_0; @@ -47,24 +46,18 @@ }; }; + ethrawbus { + reg = <0 0>; + compatible = "sandbox,eth-raw-bus"; + skip-localhost = <1>; + }; + eth@10002000 { compatible = "sandbox,eth"; reg = <0x0 0x10002000 0x0 0x1000>; fake-host-hwaddr = [00 00 66 44 22 00]; }; - eth@80000000 { - compatible = "sandbox,eth-raw"; - reg = <0x0 0x80000000 0x0 0x1000>; - host-raw-interface = "eth0"; - }; - - eth@90000000 { - compatible = "sandbox,eth-raw"; - reg = <0x0 0x90000000 0x0 0x1000>; - host-raw-interface = "lo"; - }; - gpio_a: gpios@0 { gpio-controller; compatible = "sandbox,gpio"; diff --git a/arch/sandbox/include/asm/eth-raw-os.h b/arch/sandbox/include/asm/eth-raw-os.h index 99f674e82e..0b511db70c 100644 --- a/arch/sandbox/include/asm/eth-raw-os.h +++ b/arch/sandbox/include/asm/eth-raw-os.h @@ -34,6 +34,17 @@ struct eth_sandbox_raw_priv { unsigned short local_bind_udp_port; }; +/* A struct to mimic if_nameindex but that does not depend on Linux headers */ +struct sandbox_eth_raw_if_nameindex { + unsigned int if_index; /* Index of interface (1, 2, ...) */ + char *if_name; /* Null-terminated name ("eth0", etc.) */ +}; + +/* Enumerate host network interfaces */ +struct sandbox_eth_raw_if_nameindex *sandbox_eth_raw_if_nameindex(void); +/* Free the data structure of enumerated network interfaces */ +void sandbox_eth_raw_if_freenameindex(struct sandbox_eth_raw_if_nameindex *ptr); + /* * Check if the interface named "ifname" is a localhost interface or not. * ifname - the interface name on the host to check diff --git a/drivers/net/Makefile b/drivers/net/Makefile index 058dd00768..c1ed44e21f 100644 --- a/drivers/net/Makefile +++ b/drivers/net/Makefile @@ -50,6 +50,7 @@ obj-$(CONFIG_RTL8139) += rtl8139.o obj-$(CONFIG_RTL8169) += rtl8169.o obj-$(CONFIG_ETH_SANDBOX) += sandbox.o obj-$(CONFIG_ETH_SANDBOX_RAW) += sandbox-raw.o +obj-$(CONFIG_ETH_SANDBOX_RAW) += sandbox-raw-bus.o obj-$(CONFIG_SH_ETHER) += sh_eth.o obj-$(CONFIG_RENESAS_RAVB) += ravb.o obj-$(CONFIG_SMC91111) += smc91111.o diff --git a/drivers/net/sandbox-raw-bus.c b/drivers/net/sandbox-raw-bus.c new file mode 100644 index 0000000000..76d65afe6c --- /dev/null +++ b/drivers/net/sandbox-raw-bus.c @@ -0,0 +1,66 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2018 National Instruments + * Copyright (c) 2018 Joe Hershberger + */ + +#include +#include +#include +#include +#include +#include + +static int eth_raw_bus_post_bind(struct udevice *dev) +{ + struct sandbox_eth_raw_if_nameindex *ni, *i; + struct udevice *child; + struct eth_sandbox_raw_priv *priv; + char *ub_ifname; + static const char ub_ifname_pfx[] = "host_"; + u32 skip_localhost = 0; + + ni = sandbox_eth_raw_if_nameindex(); + if (!ni) + return -EINVAL; + + dev_read_u32(dev, "skip-localhost", &skip_localhost); + for (i = ni; !(i->if_index == 0 && !i->if_name); i++) { + int local = sandbox_eth_raw_os_is_local(i->if_name); + + if (local < 0) + continue; + if (skip_localhost && local) + continue; + + ub_ifname = calloc(IFNAMSIZ + sizeof(ub_ifname_pfx), 1); + strcpy(ub_ifname, ub_ifname_pfx); + strncat(ub_ifname, i->if_name, IFNAMSIZ); + device_bind_driver(dev, "eth_sandbox_raw", ub_ifname, &child); + + device_set_name_alloced(child); + device_probe(child); + priv = dev_get_priv(child); + if (priv) { + memcpy(priv->host_ifname, i->if_name, IFNAMSIZ); + priv->host_ifindex = i->if_index; + priv->local = local; + } + } + + sandbox_eth_raw_if_freenameindex(ni); + + return 0; +} + +static const struct udevice_id sandbox_eth_raw_bus_ids[] = { + { .compatible = "sandbox,eth-raw-bus" }, + { } +}; + +U_BOOT_DRIVER(sandbox_eth_raw_bus) = { + .name = "sb_eth_raw_bus", + .id = UCLASS_SIMPLE_BUS, + .of_match = sandbox_eth_raw_bus_ids, + .bind = eth_raw_bus_post_bind, +};