From patchwork Tue Feb 16 22:48:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 1441142 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=jk1Oj6uh; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DgGNr3jkBz9sBy for ; Wed, 17 Feb 2021 09:49:00 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5457582709; Tue, 16 Feb 2021 23:48:44 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com 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=gmail.com header.i=@gmail.com header.b="jk1Oj6uh"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5BBD98280F; Tue, 16 Feb 2021 23:48:35 +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.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) (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 6258A82717 for ; Tue, 16 Feb 2021 23:48:32 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=olteanv@gmail.com Received: by mail-ed1-x533.google.com with SMTP id l12so14239081edt.3 for ; Tue, 16 Feb 2021 14:48:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=atAgLNsGxEJ2WYzsmUV+2pdzMF6LoGwxTgt+v7Gp+kY=; b=jk1Oj6uhdmBFBaGnWjrvHmczVL7vfB3YWqc9mDjhNc2UQBOKjPkTkRuaMSPrLkHhC0 e2U9xUKhV8kjXz/IXXyPlj8fO8NnUfqs7imm4/Y69DCO2uZ+rkW3vwHMKiuGvvip4PjU q7ADqROGWbqhziW/U1iXgxMiX0Zjg8KLPSR6rF15h4mAS8vBlhmzbwe7qLNm1SWv6bGX mPuVRuZ4M/b97zrS3c3WGQn1SwEC0EjJuKQOgfVWquMC3feDZFR+14aUKsc9iYRWSJSx e/PfNcMurmrn24T5QJvQJ+2SuomiXSY8Prp3NmAXKSDrYwmHE8wMT7+aPdmr490tJfvQ ulDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=atAgLNsGxEJ2WYzsmUV+2pdzMF6LoGwxTgt+v7Gp+kY=; b=W3VQdbyvU7h8ztq2AqjOYRyn2dxUiNPB3lX+cRsWyBX5Lemhuw2F5VmAXtLzsXgw3g bzXbWoo1/Z2E3K4/NrRiFl0AN1D2XTR2PkWMMKSptA+lyMZ69LuqRlGSQjTX0fBGHhly ZwHxPZQMr3q+srDHDybFDPT2HHyTRGLQaZ8Odr10Zu32NT8oQynTAjnpEhiZ28ti4A0O r2W529dQoa4oIDwgtGpQx6I4CYdTDydthoBsy2NXdPXl4Dqd+pCicw82R+FiTNh6M0my Sj3ASzJDsv1C0uA8KpGyg6etrfE1H31U+paJNGfflG8DYWYe1IzAHSd0PpVTiLA28nBP axvw== X-Gm-Message-State: AOAM5328OqJe4QHPuK5043MkdcIeSw79FgqRnI/XzH+D8+v7NfaEWMNV Xyu1u5z6/fis+jQ54vmSLRI= X-Google-Smtp-Source: ABdhPJyythHcPBh1fHgXWGF5fxD0QYKJA2w60zcTLDd2qTXiHoo4EIN6DBHM5qKylCTIr1ZTAomd9Q== X-Received: by 2002:a05:6402:3552:: with SMTP id f18mr23337818edd.111.1613515711980; Tue, 16 Feb 2021 14:48:31 -0800 (PST) Received: from localhost.localdomain (5-12-227-87.residential.rdsnet.ro. [5.12.227.87]) by smtp.gmail.com with ESMTPSA id bf8sm106096edb.34.2021.02.16.14.48.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Feb 2021 14:48:31 -0800 (PST) From: Vladimir Oltean To: Tom Rini , Joe Hershberger , Simon Glass , Bin Meng , u-boot@lists.denx.de Cc: Michael Walle , Alexandru Marginean , Claudiu Manoil , Priyanka Jain Subject: [PATCH 1/4] net: phy: fixed: be compatible with live OF tree Date: Wed, 17 Feb 2021 00:48:01 +0200 Message-Id: <20210216224804.3355044-2-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210216224804.3355044-1-olteanv@gmail.com> References: <20210216224804.3355044-1-olteanv@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.3 at phobos.denx.de X-Virus-Status: Clean From: Vladimir Oltean On systems that use CONFIG_OF_LIVE, the "ofnode" type is defined as const struct device_node *np, while on the flat DT systems it is defined as a long of_offset into gd->fdt_blob. It is desirable that the fixed PHY driver uses the higher-level ofnode abstraction instead of parsing gd->fdt_blob directly, because that enables it to work on live OF systems. The fixed PHY driver has used a nastyyyyy hack since its introduction in commit db40c1aa1c10 ("drivers/net/phy: add fixed-phy / fixed-link support"), which is to pass the long gd->fdt_blob offset inside int phydev->addr (a value that normally holds the MDIO bus address at which the PHY responds). Even ignoring the fact that the types were already mismatched leading to a potential truncation (flat OF offset was supposed to be a long and not an int), we really cannot extend this hack any longer, because there's no way an int will hold the other representation of ofnode, the struct device_node *np. So we unfortunately need to do the right thing, which is to use the framework introduced by Grygorii Strashko in commit eef0b8a930d1 ("net: phy: add ofnode node to struct phy_device"). This will populate phydev->node for the fixed PHY. Note that phydev->node will not be valid in the probe function, since that is called synchronously from phy_device_create and we really have no way of passing the ofnode directly through the phy_device_create API. So we do what other drivers do too: we move the OF parsing logic from the .probe to the .config method of the PHY driver. The new function will be called at phy_config() time. I do believe I've converted all the possible call paths for creating a PHY with PHY_FIXED_ID, so there is really no reason to maintain compatibility with the old logic of retrieving a flat OF tree offset from phydev->addr. We just pass 0 to phydev->addr now. Signed-off-by: Vladimir Oltean Reviewed-by: Bin Meng Tested-by: Bin Meng --- drivers/net/phy/fixed.c | 30 ++++++++++++++++++++++-------- drivers/net/phy/phy.c | 30 +++++++++++++++--------------- 2 files changed, 37 insertions(+), 23 deletions(-) diff --git a/drivers/net/phy/fixed.c b/drivers/net/phy/fixed.c index 1a38c29469a4..d67c22a7b8c7 100644 --- a/drivers/net/phy/fixed.c +++ b/drivers/net/phy/fixed.c @@ -15,15 +15,17 @@ DECLARE_GLOBAL_DATA_PTR; -int fixedphy_probe(struct phy_device *phydev) +static int fixedphy_of_init(struct phy_device *phydev) { + ofnode node = phy_get_ofnode(phydev); struct fixed_link *priv; - int ofnode = phydev->addr; u32 val; + if (!ofnode_valid(node)) + return -EINVAL; + /* check for mandatory properties within fixed-link node */ - val = fdt_getprop_u32_default_node(gd->fdt_blob, - ofnode, 0, "speed", 0); + val = ofnode_read_u32_default(node, "speed", 0); if (val != SPEED_10 && val != SPEED_100 && val != SPEED_1000 && val != SPEED_2500 && val != SPEED_10000) { printf("ERROR: no/invalid speed given in fixed-link node!"); @@ -33,14 +35,26 @@ int fixedphy_probe(struct phy_device *phydev) priv = malloc(sizeof(*priv)); if (!priv) return -ENOMEM; + memset(priv, 0, sizeof(*priv)); phydev->priv = priv; priv->link_speed = val; - priv->duplex = fdtdec_get_bool(gd->fdt_blob, ofnode, "full-duplex"); - priv->pause = fdtdec_get_bool(gd->fdt_blob, ofnode, "pause"); - priv->asym_pause = fdtdec_get_bool(gd->fdt_blob, ofnode, "asym-pause"); + priv->duplex = ofnode_read_bool(node, "full-duplex"); + priv->pause = ofnode_read_bool(node, "pause"); + priv->asym_pause = ofnode_read_bool(node, "asym-pause"); + + return 0; +} + +static int fixedphy_config(struct phy_device *phydev) +{ + int err; + + err = fixedphy_of_init(phydev); + if (err) + return err; /* fixed-link phy must not be reset by core phy code */ phydev->flags |= PHY_FLAG_BROKEN_RESET; @@ -71,7 +85,7 @@ static struct phy_driver fixedphy_driver = { .mask = 0xffffffff, .name = "Fixed PHY", .features = PHY_GBIT_FEATURES | SUPPORTED_MII, - .probe = fixedphy_probe, + .config = fixedphy_config, .startup = fixedphy_startup, .shutdown = fixedphy_shutdown, }; diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 89e3076bfd25..2feb559bba97 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -988,6 +988,7 @@ static struct phy_device *phy_connect_gmii2rgmii(struct mii_dev *bus, struct phy_device *fixed_phy_create(ofnode node) { phy_interface_t interface = PHY_INTERFACE_MODE_NONE; + struct phy_device *phydev; const char *if_str; ofnode subnode; @@ -1004,8 +1005,11 @@ struct phy_device *fixed_phy_create(ofnode node) return NULL; } - return phy_device_create(NULL, ofnode_to_offset(subnode), PHY_FIXED_ID, - false, interface); + phydev = phy_device_create(NULL, 0, PHY_FIXED_ID, false, interface); + if (phydev) + phydev->node = subnode; + + return phydev; } #ifdef CONFIG_DM_ETH @@ -1018,20 +1022,16 @@ static struct phy_device *phy_connect_fixed(struct mii_dev *bus, phy_interface_t interface) #endif { - struct phy_device *phydev = NULL; - int sn; - const char *name; + ofnode node = dev_ofnode(dev), subnode; + struct phy_device *phydev; - sn = fdt_first_subnode(gd->fdt_blob, dev_of_offset(dev)); - while (sn > 0) { - name = fdt_get_name(gd->fdt_blob, sn, NULL); - if (name && strcmp(name, "fixed-link") == 0) { - phydev = phy_device_create(bus, sn, PHY_FIXED_ID, false, - interface); - break; - } - sn = fdt_next_subnode(gd->fdt_blob, sn); - } + subnode = ofnode_find_subnode(node, "fixed-link"); + if (!ofnode_valid(subnode)) + return NULL; + + phydev = phy_device_create(bus, 0, PHY_FIXED_ID, false, interface); + if (phydev) + phydev->node = subnode; return phydev; } From patchwork Tue Feb 16 22:48:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 1441143 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=fHe0U2m7; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DgGNy0LTdz9sBy for ; Wed, 17 Feb 2021 09:49:05 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5EADB82839; Tue, 16 Feb 2021 23:48:47 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com 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=gmail.com header.i=@gmail.com header.b="fHe0U2m7"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 392A482835; Tue, 16 Feb 2021 23:48:39 +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.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) (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 43C68827CF for ; Tue, 16 Feb 2021 23:48:33 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=olteanv@gmail.com Received: by mail-ej1-x62d.google.com with SMTP id w1so10017614ejk.6 for ; Tue, 16 Feb 2021 14:48:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Nyvp8JeperVYFexyMjeCV3ZemU1FIdQ66/o+XA1lOSY=; b=fHe0U2m7/iMLsqWnZqLicqDwrZR7m6QdCMrf/gwN2pBmj368cI3J2emFJ0f3955jkS IpcyXSHrvuWVWa3hxn+ifl/eNasn6IFCTdis4Pmv6XKpTCR6vSZd8VRuGuhTrWYIjShD 0Y+ulomaPcL153y1XfFn70G/vtcUJ5NfWg6UhkUHTRJcJ7pHJYiQ1ZuMq2fNiHFHHP5j xP6TFkxL44ZOa4m5CMTgRK0zxPnr16uTv7cNLMSeTVNhVVlVDMDgp1UMV2yhin3rQaPh lzIDCZj1YZWCVboMcpkFhkDeGMHpk4JIsfr5EKMlJ7A4nkxUdZE0O+mD5Rku/ACzTeXK TmnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Nyvp8JeperVYFexyMjeCV3ZemU1FIdQ66/o+XA1lOSY=; b=rgBUjSWzwbBWluN07IPCUdRmdZ7hWQsvM7YGnUhZOpzv51aY4Qo7+jTWoFEzksdvkj +14YEZKnbNVx8Pkicg1KHYLT6+bGoluDJSzkPfUP/36bOYVyGESms/VGZBdKgfZG3Ca0 zmVpy+pDo5+WPCyeqHbqb0jWZdQemWyZkRvALB5F9VeTPMTP+iluTHzdNjVXh/703kqO 8YDCb+Xp4RG7rzpQ89NN/p0ecvJQhbQH2P+6K/Bb9z8NYTNreeMEtvPBWItLSAQi0t3K 7zrCiFCmjxUTsYtGEEB/QjopPwA6kzv+336CAxhlg5v5cvo7l6U/0VKrokTU+YGWJVgJ BIJA== X-Gm-Message-State: AOAM531kjIxhFsVG2sVATECVPa4XF3cV/b8DCCfn/MaRKiwW+ww9nrFr Kf8RzgwhWr2/p0vj1ffiaAU= X-Google-Smtp-Source: ABdhPJxIYUcv8aUKeSH7sskwhPZsfUfnyd3o80IS/vf5CumtCgoLhA/fGECBLMd/7H/t6QEDISmL8Q== X-Received: by 2002:a17:906:fc16:: with SMTP id ov22mr9354577ejb.268.1613515712978; Tue, 16 Feb 2021 14:48:32 -0800 (PST) Received: from localhost.localdomain (5-12-227-87.residential.rdsnet.ro. [5.12.227.87]) by smtp.gmail.com with ESMTPSA id bf8sm106096edb.34.2021.02.16.14.48.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Feb 2021 14:48:32 -0800 (PST) From: Vladimir Oltean To: Tom Rini , Joe Hershberger , Simon Glass , Bin Meng , u-boot@lists.denx.de Cc: Michael Walle , Alexandru Marginean , Claudiu Manoil , Priyanka Jain Subject: [PATCH 2/4] net: phy: drop #ifdef CONFIG_DM_ETH around phy_connect_fixed Date: Wed, 17 Feb 2021 00:48:02 +0200 Message-Id: <20210216224804.3355044-3-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210216224804.3355044-1-olteanv@gmail.com> References: <20210216224804.3355044-1-olteanv@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.3 at phobos.denx.de X-Virus-Status: Clean From: Vladimir Oltean In drivers/net/phy/Kconfig, CONFIG_PHY_FIXED already depends on CONFIG_DM_ETH, so the function prototype definition when CONFIG_DM_ETH=n does nothing, so it can be dropped. It is also never reachable, since the whole function is already under #ifdef CONFIG_PHY_FIXED (which again, as I said, depends on CONFIG_DM_ETH=y). Signed-off-by: Vladimir Oltean Reviewed-by: Bin Meng --- drivers/net/phy/phy.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 2feb559bba97..eae40cc0d6b7 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -1012,15 +1012,9 @@ struct phy_device *fixed_phy_create(ofnode node) return phydev; } -#ifdef CONFIG_DM_ETH static struct phy_device *phy_connect_fixed(struct mii_dev *bus, struct udevice *dev, phy_interface_t interface) -#else -static struct phy_device *phy_connect_fixed(struct mii_dev *bus, - struct eth_device *dev, - phy_interface_t interface) -#endif { ofnode node = dev_ofnode(dev), subnode; struct phy_device *phydev; From patchwork Tue Feb 16 22:48:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 1441144 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=oCB2i0IS; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DgGP921NVz9sCD for ; Wed, 17 Feb 2021 09:49:17 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 179CB82849; Tue, 16 Feb 2021 23:48:50 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com 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=gmail.com header.i=@gmail.com header.b="oCB2i0IS"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 09CCA82717; Tue, 16 Feb 2021 23:48:41 +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.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) (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 46C6C827F6 for ; Tue, 16 Feb 2021 23:48:34 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=olteanv@gmail.com Received: by mail-ej1-x632.google.com with SMTP id i23so12909005ejg.10 for ; Tue, 16 Feb 2021 14:48:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vlIsVZT1kjCITut3hhQWPPztLV1HB7MhlSwmVue5LD4=; b=oCB2i0ISSkfQtQCjpMU04Ei+xMMXXjgM+Sdnjn+cWBoIxS6pidQNRArVV5gNFVBIIM 0AIkRrMN9Vl2fatStHH5JVlBEXnAa8zK0LavP+uPs6m3Vild/uPhz12fh1yGM5ChaUzC fHB9/UHpzSa2Wo7Im7G+y5meIyPQGK39lZ8Eu+oG5YEbhf59cpv+GCLSKlYVfeYr+B/i RAq+Trndxa2PgVm+IsR8OhkWC+wrpkf8+T9apbdPB3fEvjd7NflnGrnLeF0AZgHpFFo2 jv+6lAB29aOhW3nYsNjfgsqrASzF/dgO+YhfNJ5KNTw3TPDK1KvvjLVESvAIYDmNZZst iXrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vlIsVZT1kjCITut3hhQWPPztLV1HB7MhlSwmVue5LD4=; b=GVvRU1k7z0SJcXftwlM7R6GJDZDu/x46M0jj5Et3oQoCYv+TJEeUk6YvXDdxttf/aa pPR5ZOHi5+qJwZKhRwP9+od/IHWdCwEhi+reYXfwPVTm2m5eagq+sSK906s+iWK+lAWA 51aWuuIQIngwbtNzSDDQ7qZXzlVgLRFXLFmqVDB7IML5Z7t2JXFhCKZi4V8HV3eP+5kP wiHLnjTEZuGX3yxVpOGXchQZ0BGmhdwJ40QQUeA7P62C/nK2nKoSR/tYaRrbt3EJbogn Pqj9wK0shpJmn0el1PksOIOmL90y9U1sE6Ih/d4n/E1/ewLa+KAXIpCZ50RDVwPmhjZb Snqw== X-Gm-Message-State: AOAM5328W0jC64MroNQLaa9r5VT3yoq7Zk0Lm5FqN94y0g4kvwdG6Ion yKk8iOTSY94tBBqndvgUfCg= X-Google-Smtp-Source: ABdhPJzme6u/TSL7YeOiIt2mVHmOF28dsl3ZkWTJvBQqZuFh/MzrYhTTRmRidmHHft8K9OVCLfzKzw== X-Received: by 2002:a17:906:1d44:: with SMTP id o4mr19876336ejh.130.1613515713941; Tue, 16 Feb 2021 14:48:33 -0800 (PST) Received: from localhost.localdomain (5-12-227-87.residential.rdsnet.ro. [5.12.227.87]) by smtp.gmail.com with ESMTPSA id bf8sm106096edb.34.2021.02.16.14.48.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Feb 2021 14:48:33 -0800 (PST) From: Vladimir Oltean To: Tom Rini , Joe Hershberger , Simon Glass , Bin Meng , u-boot@lists.denx.de Cc: Michael Walle , Alexandru Marginean , Claudiu Manoil , Priyanka Jain Subject: [PATCH 3/4] net: mdio: teach dm_eth_phy_connect to connect to fixed PHY Date: Wed, 17 Feb 2021 00:48:03 +0200 Message-Id: <20210216224804.3355044-4-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210216224804.3355044-1-olteanv@gmail.com> References: <20210216224804.3355044-1-olteanv@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.3 at phobos.denx.de X-Virus-Status: Clean From: Vladimir Oltean It would be desirable for top-level callers of PHYLIB to deal with as little complexity as possible, and when they call dm_eth_phy_connect, they get a struct phy_device that "just works". There is a phy_connect_fixed interception put in phy_connect, however dm_eth_phy_connect will not reach there: if will search for a phy-handle all by itself, and error out if there isn't one. So we can make callers of dm_eth_phy_connect suffer by having them call: err = dm_eth_phy_connect(); if (err) err = dm_eth_phy_connect_fixed(); or we can just add the logic in dm_eth_phy_connect() that searches for a fixed-link before searching for a phy-handle. In fact we already have an in-tree driver that can make use of this refactoring: the Freescale TSEC driver. Signed-off-by: Vladimir Oltean --- drivers/net/tsec.c | 6 +----- net/mdio-uclass.c | 12 ++++++++++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/net/tsec.c b/drivers/net/tsec.c index ec4868937257..f801d020fb65 100644 --- a/drivers/net/tsec.c +++ b/drivers/net/tsec.c @@ -707,11 +707,7 @@ static int init_phy(struct tsec_private *priv) tsec_configure_serdes(priv); #if defined(CONFIG_DM_ETH) && defined(CONFIG_DM_MDIO) - if (ofnode_valid(ofnode_find_subnode(dev_ofnode(priv->dev), - "fixed-link"))) - phydev = phy_connect(NULL, 0, priv->dev, priv->interface); - else - phydev = dm_eth_phy_connect(priv->dev); + phydev = dm_eth_phy_connect(priv->dev); #else phydev = phy_connect(priv->bus, priv->phyaddr, priv->dev, priv->interface); diff --git a/net/mdio-uclass.c b/net/mdio-uclass.c index 697e5f838d94..766d4711cc23 100644 --- a/net/mdio-uclass.c +++ b/net/mdio-uclass.c @@ -177,9 +177,10 @@ static struct phy_device *dm_eth_connect_phy_handle(struct udevice *ethdev, /* Connect to a PHY linked in eth DT node */ struct phy_device *dm_eth_phy_connect(struct udevice *ethdev) { - const char *if_str; + ofnode node = dev_ofnode(ethdev), subnode; phy_interface_t interface; struct phy_device *phy; + const char *if_str; int i; if (!dev_has_ofnode(ethdev)) { @@ -200,7 +201,14 @@ struct phy_device *dm_eth_phy_connect(struct udevice *ethdev) if (interface == PHY_INTERFACE_MODE_NONE) dev_dbg(ethdev, "can't find interface mode, default to NONE\n"); - phy = dm_eth_connect_phy_handle(ethdev, interface); + subnode = ofnode_find_subnode(node, "fixed-link"); + if (ofnode_valid(subnode)) { + phy = phy_connect(NULL, 0, ethdev, interface); + if (phy) + phy->node = subnode; + } else { + phy = dm_eth_connect_phy_handle(ethdev, interface); + } if (!phy) return NULL; From patchwork Tue Feb 16 22:48:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 1441145 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=gIX13jPA; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DgGPN1Ym2z9sBy for ; Wed, 17 Feb 2021 09:49:27 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0D6ED8284D; Tue, 16 Feb 2021 23:48:53 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com 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=gmail.com header.i=@gmail.com header.b="gIX13jPA"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D774B827CF; Tue, 16 Feb 2021 23:48:39 +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.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) (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 437348280D for ; Tue, 16 Feb 2021 23:48:35 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=olteanv@gmail.com Received: by mail-ej1-x635.google.com with SMTP id i23so12909048ejg.10 for ; Tue, 16 Feb 2021 14:48:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rJgqmRao2ImZl5lIUCnagQMPOI/DYYzVBO2ijSB/Msg=; b=gIX13jPAHvL7sPMzvem2Dvf+zV2/2yHUvZCyO2V5dqPlmJqbP1+NVnpbWFXHoNpJ9C 4ifp/4xZBpOsZ248Q/cme8sSxtQymRk/wKNsMKuH1Imv1U43nYSzWkXA1pMY4gN3Z3R8 XirjzhhBZbeQQt5zeWyUYjx9Oy6iaRXU72vPaN6LO4URN0JvpRyHfK6MPO/6MqaE2py5 wajhUfaJ0jMyt22auDnvPySGSPqmybSphXWNrDWirW5876tmLoSdt5dwkdRK7/jCNCIX wWNEJYmq8vsSz6ScZDY+0/+83M5GZcwyyu/xyxuGqtraUcy1WY3fCp26SchPMI9/T4jW CUNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rJgqmRao2ImZl5lIUCnagQMPOI/DYYzVBO2ijSB/Msg=; b=AjwxGL+MEjjVwRCWHKZkbcGR5AKxyGVXBwkSM+/QgBbJQhLw4jJL3nJXBT3h5tdYMT q8dgzO4A66vQgcwi+hSzRav7q2YVtf2JC4k1yNbE3dK6xvA4j1MeucXqJskKT6qqfLbR ElU4mS4hsIYmpzsb3oOUdvNKENihol9cpSe4RHFLnheeTGJz5vBY0XwwbDMrm9PkUaQg gKmdb12cSVXXTzYw/Ubi9ccvye4r+eR8N/jQ+jJFtbCBhqbZx4tZGxNC9L4qM6kzAvFD Ebvpt76lRSIXOgi6T8VwBeA4iSN2Pk0ToY9Y4DHT2ZATinz0r5O6T2qQalf73a7M6XLi bCSQ== X-Gm-Message-State: AOAM533f4FsIelzePKaErzWEmRZFenL4wJ2GqAesZRhrO3NJme4LPZKo 8grzOGSJZsrLgxjNH+C6Q/4= X-Google-Smtp-Source: ABdhPJzT+11cWLVFb+wymMzC+Ej5pKlu07Rb69k1cRPGD/h7jjvdPig+lL9iIdqhVrjk3Kk+4/VOhQ== X-Received: by 2002:a17:906:6943:: with SMTP id c3mr22210748ejs.133.1613515714861; Tue, 16 Feb 2021 14:48:34 -0800 (PST) Received: from localhost.localdomain (5-12-227-87.residential.rdsnet.ro. [5.12.227.87]) by smtp.gmail.com with ESMTPSA id bf8sm106096edb.34.2021.02.16.14.48.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Feb 2021 14:48:34 -0800 (PST) From: Vladimir Oltean To: Tom Rini , Joe Hershberger , Simon Glass , Bin Meng , u-boot@lists.denx.de Cc: Michael Walle , Alexandru Marginean , Claudiu Manoil , Priyanka Jain Subject: [PATCH 4/4] sandbox: add a DSA sandbox driver and unit test Date: Wed, 17 Feb 2021 00:48:04 +0200 Message-Id: <20210216224804.3355044-5-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210216224804.3355044-1-olteanv@gmail.com> References: <20210216224804.3355044-1-olteanv@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.3 at phobos.denx.de X-Virus-Status: Clean From: Claudiu Manoil The DSA sandbox driver is used for unit testing the DSA class code. It implements a simple 2 port switch plus 1 CPU port, and uses a very simple tag to identify the ports. The DSA sandbox device is connected via CPU port to a regular Ethernet sandbox device, called 'dsa-test-eth, managed by the existing eth sandbox driver. The 'dsa-test-eth' is not intended for testing the eth class code however, but it is used to emulate traffic through the 'lan0' and 'lan1' front pannel switch ports. To achieve this the dsa sandbox driver registers a tx handler for the 'dsa-test-eth' device. The switch ports, labeled as 'lan0' and 'lan1', are also registered as eth devices by the dsa class code this time. So pinging through these switch ports is as easy as: => setenv ethact lan0 => ping 1.2.3.5 Unit tests for the dsa class code were also added. The 'dsa_probe' test exercises most API functions from dsa.h. The 'dsa' unit test simply exercises ARP/ICMP traffic through the two switch ports, including tag injection and extraction, with the help of the dsa sandbox driver. I took care to minimize the impact on the existing eth unit tests, though some adjustments needed to be made with the addition of extra eth interfaces used by the dsa unit tests. The additional eth interfaces also require MAC addresses, these have been added to the sandbox default environment. Signed-off-by: Alex Marginean Signed-off-by: Claudiu Manoil Reviewed-by: Simon Glass Signed-off-by: Vladimir Oltean --- arch/Kconfig | 2 + arch/sandbox/dts/test.dts | 48 ++++++++++ drivers/net/Kconfig | 9 ++ drivers/net/Makefile | 1 + drivers/net/dsa_sandbox.c | 179 ++++++++++++++++++++++++++++++++++++++ include/configs/sandbox.h | 2 + test/dm/Makefile | 1 + test/dm/dsa.c | 82 +++++++++++++++++ test/dm/eth.c | 10 +-- 9 files changed, 329 insertions(+), 5 deletions(-) create mode 100644 drivers/net/dsa_sandbox.c create mode 100644 test/dm/dsa.c diff --git a/arch/Kconfig b/arch/Kconfig index 6c8167826cf8..f114a025fa5b 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -161,6 +161,8 @@ config SANDBOX imply CMD_CLONE imply SILENT_CONSOLE imply BOOTARGS_SUBST + imply PHY_FIXED + imply DM_DSA config SH bool "SuperH architecture" diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index e95f4631bf2f..d4ee6ddbbe4c 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -14,7 +14,9 @@ aliases { console = &uart0; eth0 = "/eth@10002000"; + eth2 = &swp_0; eth3 = ð_3; + eth4 = &dsa_eth0; eth5 = ð_5; gpio1 = &gpio_a; gpio2 = &gpio_b; @@ -432,6 +434,52 @@ fake-host-hwaddr = [00 00 66 44 22 22]; }; + dsa_eth0: dsa-test-eth { + compatible = "sandbox,eth"; + reg = <0x10006000 0x1000>; + fake-host-hwaddr = [00 00 66 44 22 66]; + }; + + dsa-test { + compatible = "sandbox,dsa"; + + ports { + #address-cells = <1>; + #size-cells = <0>; + swp_0: port@0 { + reg = <0>; + label = "lan0"; + phy-mode = "rgmii-rxid"; + + fixed-link { + speed = <100>; + full-duplex; + }; + }; + + swp_1: port@1 { + reg = <1>; + label = "lan1"; + phy-mode = "rgmii-txid"; + + fixed-link { + speed = <100>; + full-duplex; + }; + }; + + port@2 { + reg = <2>; + ethernet = <&dsa_eth0>; + + fixed-link { + speed = <1000>; + full-duplex; + }; + }; + }; + }; + firmware { sandbox_firmware: sandbox-firmware { compatible = "sandbox,firmware"; diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig index 0e84c22b5075..f96ee642494a 100644 --- a/drivers/net/Kconfig +++ b/drivers/net/Kconfig @@ -78,6 +78,15 @@ config DM_ETH_PHY help Enable driver model for Ethernet Generic PHY . +config DSA_SANDBOX + depends on DM_DSA && SANDBOX + default y + bool "Sandbox: Mocked DSA driver" + help + This driver implements a dummy DSA switch connected to a dummy sandbox + Ethernet device used as DSA master, to test DSA class code, including + exported DSA API and datapath processing of Ethernet traffic. + menuconfig NETDEVICES bool "Network device support" depends on NET diff --git a/drivers/net/Makefile b/drivers/net/Makefile index a19511aaa7ba..108138fdb972 100644 --- a/drivers/net/Makefile +++ b/drivers/net/Makefile @@ -22,6 +22,7 @@ obj-$(CONFIG_ETH_DESIGNWARE_SOCFPGA) += dwmac_socfpga.o obj-$(CONFIG_ETH_DESIGNWARE_S700) += dwmac_s700.o obj-$(CONFIG_DRIVER_DM9000) += dm9000x.o obj-$(CONFIG_DNET) += dnet.o +obj-$(CONFIG_DSA_SANDBOX) += dsa_sandbox.o obj-$(CONFIG_DM_ETH_PHY) += eth-phy-uclass.o obj-$(CONFIG_E1000) += e1000.o obj-$(CONFIG_E1000_SPI) += e1000_spi.o diff --git a/drivers/net/dsa_sandbox.c b/drivers/net/dsa_sandbox.c new file mode 100644 index 000000000000..4b62670e5d17 --- /dev/null +++ b/drivers/net/dsa_sandbox.c @@ -0,0 +1,179 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2019-2021 NXP Semiconductors + */ + +#include +#include +#include + +#define DSA_SANDBOX_MAGIC 0x00415344 +#define DSA_SANDBOX_TAG_LEN sizeof(struct dsa_sandbox_tag) + +struct dsa_sandbox_priv { + struct eth_sandbox_priv *master_priv; + int port_en_mask; +}; + +struct dsa_sandbox_tag { + u32 magic; + u32 port; +}; + +static bool sb_dsa_port_enabled(struct udevice *dev, int port) +{ + struct dsa_sandbox_priv *priv = dev_get_priv(dev); + + return priv->port_en_mask & BIT(port); +} + +static bool sb_dsa_master_enabled(struct udevice *dev) +{ + struct dsa_sandbox_priv *priv = dev_get_priv(dev); + + return !priv->master_priv->disabled; +} + +static int dsa_sandbox_port_enable(struct udevice *dev, int port, + struct phy_device *phy) +{ + struct dsa_sandbox_priv *priv = dev_get_priv(dev); + + if (!sb_dsa_master_enabled(dev)) + return -EFAULT; + + priv->port_en_mask |= BIT(port); + + return 0; +} + +static void dsa_sandbox_port_disable(struct udevice *dev, int port, + struct phy_device *phy) +{ + struct dsa_sandbox_priv *priv = dev_get_priv(dev); + + priv->port_en_mask &= ~BIT(port); +} + +static int dsa_sandbox_xmit(struct udevice *dev, int port, void *packet, + int length) +{ + struct dsa_sandbox_tag *tag = packet; + + if (!sb_dsa_master_enabled(dev)) + return -EFAULT; + + if (!sb_dsa_port_enabled(dev, port)) + return -EFAULT; + + tag->magic = DSA_SANDBOX_MAGIC; + tag->port = port; + + return 0; +} + +static int dsa_sandbox_rcv(struct udevice *dev, int *port, void *packet, + int length) +{ + struct dsa_sandbox_tag *tag = packet; + + if (!sb_dsa_master_enabled(dev)) + return -EFAULT; + + if (tag->magic != DSA_SANDBOX_MAGIC) + return -EFAULT; + + *port = tag->port; + if (!sb_dsa_port_enabled(dev, tag->port)) + return -EFAULT; + + return 0; +} + +static const struct dsa_ops dsa_sandbox_ops = { + .port_enable = dsa_sandbox_port_enable, + .port_disable = dsa_sandbox_port_disable, + .xmit = dsa_sandbox_xmit, + .rcv = dsa_sandbox_rcv, +}; + +static int sb_dsa_handler(struct udevice *dev, void *packet, + unsigned int len) +{ + struct eth_sandbox_priv *master_priv; + struct dsa_sandbox_tag *tag = packet; + struct udevice *dsa_dev; + u32 port_index; + void *rx_buf; + int i; + + /* this emulates the switch hw and the network side */ + if (tag->magic != DSA_SANDBOX_MAGIC) + return -EFAULT; + + port_index = tag->port; + master_priv = dev_get_priv(dev); + dsa_dev = master_priv->priv; + if (!sb_dsa_port_enabled(dsa_dev, port_index)) + return -EFAULT; + + packet += DSA_SANDBOX_TAG_LEN; + len -= DSA_SANDBOX_TAG_LEN; + + if (!sandbox_eth_arp_req_to_reply(dev, packet, len)) + goto dsa_tagging; + if (!sandbox_eth_ping_req_to_reply(dev, packet, len)) + goto dsa_tagging; + + return 0; + +dsa_tagging: + master_priv->recv_packets--; + i = master_priv->recv_packets; + rx_buf = master_priv->recv_packet_buffer[i]; + len = master_priv->recv_packet_length[i]; + memmove(rx_buf + DSA_SANDBOX_TAG_LEN, rx_buf, len); + + tag = rx_buf; + tag->magic = DSA_SANDBOX_MAGIC; + tag->port = port_index; + len += DSA_SANDBOX_TAG_LEN; + master_priv->recv_packet_length[i] = len; + master_priv->recv_packets++; + + return 0; +} + +static int dsa_sandbox_probe(struct udevice *dev) +{ + struct dsa_sandbox_priv *priv = dev_get_priv(dev); + struct udevice *master = dsa_get_master(dev); + struct eth_sandbox_priv *master_priv; + + if (!master) + return -ENODEV; + + dsa_set_tagging(dev, DSA_SANDBOX_TAG_LEN, 0); + + master_priv = dev_get_priv(master); + master_priv->priv = dev; + master_priv->tx_handler = sb_dsa_handler; + + priv->master_priv = master_priv; + + return 0; +} + +static const struct udevice_id dsa_sandbox_ids[] = { + { .compatible = "sandbox,dsa" }, + { } +}; + +U_BOOT_DRIVER(dsa_sandbox) = { + .name = "dsa_sandbox", + .id = UCLASS_DSA, + .of_match = dsa_sandbox_ids, + .probe = dsa_sandbox_probe, + .ops = &dsa_sandbox_ops, + .priv_auto = sizeof(struct dsa_sandbox_priv), +}; diff --git a/include/configs/sandbox.h b/include/configs/sandbox.h index e0708fe57395..91f636b2c102 100644 --- a/include/configs/sandbox.h +++ b/include/configs/sandbox.h @@ -93,7 +93,9 @@ #endif #define SANDBOX_ETH_SETTINGS "ethaddr=00:00:11:22:33:44\0" \ + "eth2addr=00:00:11:22:33:48\0" \ "eth3addr=00:00:11:22:33:45\0" \ + "eth4addr=00:00:11:22:33:48\0" \ "eth5addr=00:00:11:22:33:46\0" \ "eth6addr=00:00:11:22:33:47\0" \ "ipaddr=1.2.3.4\0" diff --git a/test/dm/Makefile b/test/dm/Makefile index e70e50f40243..42dc2d56a764 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -27,6 +27,7 @@ obj-$(CONFIG_CLK) += clk.o clk_ccf.o obj-$(CONFIG_CROS_EC) += cros_ec.o obj-$(CONFIG_DEVRES) += devres.o obj-$(CONFIG_VIDEO_MIPI_DSI) += dsi_host.o +obj-$(CONFIG_DM_DSA) += dsa.o obj-$(CONFIG_DM_ETH) += eth.o obj-$(CONFIG_FIRMWARE) += firmware.o obj-$(CONFIG_DM_GPIO) += gpio.o diff --git a/test/dm/dsa.c b/test/dm/dsa.c new file mode 100644 index 000000000000..18c1776460da --- /dev/null +++ b/test/dm/dsa.c @@ -0,0 +1,82 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright 2020-2021 NXP Semiconductors + */ + +#include +#include +#include +#include +#include +#include + +/* This test exercises the major dsa.h API functions, after making sure + * that the DSA ports and the master Eth are correctly probed. + */ +static int dm_test_dsa_probe(struct unit_test_state *uts) +{ + struct udevice *dev_dsa, *dev_port, *dev_master; + struct dsa_pdata *dsa_pdata; + enum uclass_id id; + + id = uclass_get_by_name("dsa"); + ut_assert(id == UCLASS_DSA); + + ut_assertok(uclass_find_device_by_name(UCLASS_DSA, "dsa-test", + &dev_dsa)); + ut_assertok(uclass_find_device_by_name(UCLASS_ETH, "dsa-test-eth", + &dev_master)); + ut_assertok(device_probe(dev_master)); + + ut_assertok(uclass_find_device_by_name(UCLASS_ETH, "dsa-test@0", + &dev_port)); + ut_assertok(device_probe(dev_port)); + + ut_assertok(uclass_find_device_by_name(UCLASS_ETH, "dsa-test@1", + &dev_port)); + ut_assertok(device_probe(dev_port)); + + /* exercise DSA API */ + dsa_pdata = dev_get_uclass_plat(dev_dsa); + ut_assertnonnull(dsa_pdata); + /* includes CPU port */ + ut_assert(dsa_pdata->num_ports == 3); + + ut_assertok(uclass_find_device_by_name(UCLASS_ETH, "lan0", + &dev_port)); + ut_assertok(device_probe(dev_port)); + + ut_assertok(uclass_find_device_by_name(UCLASS_ETH, "lan1", + &dev_port)); + ut_assertok(device_probe(dev_port)); + + dev_master = dsa_get_master(dev_dsa); + ut_assertnonnull(dev_master); + ut_asserteq_str("dsa-test-eth", dev_master->name); + + return 0; +} + +DM_TEST(dm_test_dsa_probe, UT_TESTF_SCAN_FDT); + +/* This test sends ping requests with the local address through each DSA port + * via the sandbox DSA master Eth. + */ +static int dm_test_dsa(struct unit_test_state *uts) +{ + net_ping_ip = string_to_ip("1.2.3.5"); + + env_set("ethact", "eth2"); + ut_assertok(net_loop(PING)); + + env_set("ethact", "lan0"); + ut_assertok(net_loop(PING)); + env_set("ethact", "lan1"); + ut_assertok(net_loop(PING)); + + env_set("ethact", ""); + + return 0; +} + +DM_TEST(dm_test_dsa, UT_TESTF_SCAN_FDT); diff --git a/test/dm/eth.c b/test/dm/eth.c index fa8a69da7013..e4ee69561064 100644 --- a/test/dm/eth.c +++ b/test/dm/eth.c @@ -53,8 +53,8 @@ static int dm_test_eth_alias(struct unit_test_state *uts) ut_assertok(net_loop(PING)); ut_asserteq_str("eth@10004000", env_get("ethact")); - /* Expected to fail since eth2 is not defined in the device tree */ - env_set("ethact", "eth2"); + /* Expected to fail since eth1 is not defined in the device tree */ + env_set("ethact", "eth1"); ut_assertok(net_loop(PING)); ut_asserteq_str("eth@10002000", env_get("ethact")); @@ -227,7 +227,7 @@ static int _dm_test_net_retry(struct unit_test_state *uts) * the active device should be eth0 */ sandbox_eth_disable_response(1, true); - env_set("ethact", "eth@10004000"); + env_set("ethact", "lan1"); env_set("netretry", "yes"); sandbox_eth_skip_timeout(); ut_assertok(net_loop(PING)); @@ -237,11 +237,11 @@ static int _dm_test_net_retry(struct unit_test_state *uts) * eth1 is disabled and netretry is no, so the ping should fail and the * active device should be eth1 */ - env_set("ethact", "eth@10004000"); + env_set("ethact", "lan1"); env_set("netretry", "no"); sandbox_eth_skip_timeout(); ut_asserteq(-ENONET, net_loop(PING)); - ut_asserteq_str("eth@10004000", env_get("ethact")); + ut_asserteq_str("lan1", env_get("ethact")); return 0; }