Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3934886rdb; Thu, 14 Sep 2023 07:12:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFeu5Q0ZXpTWpf6K4CFxYsG9gtDqzBjgIBf8ppHX4b8dtySfNPhoceq7LyUUThQalk9qOVh X-Received: by 2002:a05:6808:158c:b0:3a3:37dd:e052 with SMTP id t12-20020a056808158c00b003a337dde052mr7019375oiw.5.1694700760130; Thu, 14 Sep 2023 07:12:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694700760; cv=none; d=google.com; s=arc-20160816; b=wy/ljvGuJg7HgJqdCxfH+04h6O5s6sQLoZIaBUmnO41kSUxmqeeL+AZSfAda2gvXSn PIc68Tj4QGyzI9TrB0tq0/3se6++dvsrYf44rlZD673QxrYoJ6PRBasbQg3Wj0b5o6Rv kKLWYYQnmk36OTZyZaffqTY+E0aGwohamyQBXAa7+jgDfhh/DKeyoWLLCPXA5Y3Q0EVE 6jZxmXRwMvrlh7morfPS+8iBBspX3L9yqROjon2FohoP2+Lcm7WLnoIEd0bqdka2Kiki sC3l0lCC6y3+uopNvVQEUWmrsqGxngNKLWc8/XBes5fjxa4JgkU0P+yH/dIQ6WU+Sv+S Q7LQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=ciHMb1B//dKYKVhvHN/ElUPQ1d4JFUIN8eqN3Lc9YR0=; fh=FjmeYwS9K443RpdugL10G2cNBQS+EBzzNsg9+4D52rA=; b=zAx3r5jXayfeKMFJokfCak5iWGvnYXrBA1oDCnmZfo0H0K6LJS9ZTNdhYQZjlppvzx YV+Q8VvN2XuZp3eKD0TGoSjtwY3ZJkWYGta7Si7/RhGmoWJ3lKBRmD4cE4YHxVCqk/jI eEVE7rAiQkEigHaoL9pD/lBdoiq76wECAxq3R9KbpVHX3ASmEDd6PlX9gWUhw0uuAGG3 ku1+nwYo8ncpVFqDM/mYDYfbRmLmswf8vbmRkkrafzkS6+sRk5NbxcPF9SOtHnz3Hbce gwbkkRttqZso6ic7B1Fc1+MRsd0CVRhMNvHq22k2OuIgKaASnRdn1PlmzqFId7OON1uS 9OAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=pU3PggMd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id j70-20020a638b49000000b00563e23a5520si1596445pge.353.2023.09.14.07.12.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 07:12:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=pU3PggMd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id BD03681A4FC8; Thu, 14 Sep 2023 03:31:37 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234978AbjINKba (ORCPT + 99 others); Thu, 14 Sep 2023 06:31:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230141AbjINKb3 (ORCPT ); Thu, 14 Sep 2023 06:31:29 -0400 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F123DF; Thu, 14 Sep 2023 03:31:25 -0700 (PDT) Received: by mail-ed1-x530.google.com with SMTP id 4fb4d7f45d1cf-52c88a03f99so847017a12.2; Thu, 14 Sep 2023 03:31:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694687484; x=1695292284; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=ciHMb1B//dKYKVhvHN/ElUPQ1d4JFUIN8eqN3Lc9YR0=; b=pU3PggMd1AVbWIE6DhoBW2BpxI57yg4BXGOWpnwaH7z74FGGCJIqs1P9DSWHGmKaTR s2cApyA58LhHgbu9iXJGDJi7cARarXJKddz1H7yFuK4pafuRabBE+WGYaPnAqAeyJUuw K4JJmWl0HdyXQ/bX7YNT/AoKsMG+1X5CCRBDmTyFNRrid+OZ48T7XLJEaQuxfedgD9fW iG4NVwI9ybDFMeUhJFStKR+cI8bJUjqDs7b36GJm9X5BlkJWumVozYFxP6rv3uA71ZOm 1IrpIVRq7j3Zho+fq1WTAfNT7v+nh4WzJ+MW/HCLCrKUwyGHYOhxA5PQxq4dx6eoVD8v Io4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694687484; x=1695292284; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ciHMb1B//dKYKVhvHN/ElUPQ1d4JFUIN8eqN3Lc9YR0=; b=HdHljK3jdwN4XAI88sn9k08sS3PK4RUizpoRFHfGP3x5yce5pQIhFWibd3DRpehidN QkRCz3vNaOYRL46h8z4E8CypGaMshdbWeNMZGvETJs7YII+VuEXe69c77Zu5Gqvc/+c1 Ubr05NR29Qle/qKlfkFgGAWAIEbqIwgFYHjBQup3ya168ae0FF7VGQYzLIpValPLss9L ZHD8GtZYOISFn0hbpXeU6xLgyhHb4VhLu5E7vVnfgt/hTJbtloFWizHf3Lu8FpejGdSG ywQJ1lolUlHGoIxNcXNbxJ3yqNAe2yrMhc0+p8oHYeRXwoaZxAmH95zLF2iwKBXoP47i K/Og== X-Gm-Message-State: AOJu0YwLFScXxuw/e8QqdJCOMGaGlJech1xSNFGqlllHUEDEpzJZ7vQF QEqb8GHGX77ySbJ9pGqAgFNco9WWxGfP7NUaqWs= X-Received: by 2002:a05:6402:1644:b0:522:6e3f:b65 with SMTP id s4-20020a056402164400b005226e3f0b65mr4271351edx.33.1694687483605; Thu, 14 Sep 2023 03:31:23 -0700 (PDT) MIME-Version: 1.0 References: <20230830134241.506464-1-keguang.zhang@gmail.com> <20230830134241.506464-4-keguang.zhang@gmail.com> In-Reply-To: From: Keguang Zhang Date: Thu, 14 Sep 2023 18:30:47 +0800 Message-ID: Subject: Re: [PATCH v4 3/4] net: stmmac: Add glue layer for Loongson-1 SoC To: Serge Semin Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Thomas Bogendoerfer , Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , Serge Semin Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Thu, 14 Sep 2023 03:31:38 -0700 (PDT) X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email On Tue, Sep 12, 2023 at 6:12=E2=80=AFPM Serge Semin wrote: > > On Wed, Aug 30, 2023 at 09:42:40PM +0800, Keguang Zhang wrote: > > This glue driver is created based on the arch-code > > implemented earlier with the platform-specific settings. > > > > Use syscon for SYSCON register access. > > > > Partially based on the previous work by Serge Semin. > > > > Signed-off-by: Keguang Zhang > > --- > > V3 -> V4: Drop ls1x_dwmac_syscon definition and its instances > > Drop three redundant fields from the ls1x_dwmac structure > > Drop the ls1x_dwmac_init() method. > > Some minor improvements > > V2 -> V3: Determine the device ID by physical > > base address(suggested by Serge Semin) > > Use regmap instead of regmap fields > > Use syscon_regmap_lookup_by_phandle() > > Some minor fixes > > V1 -> V2: Fix the build errors due to CONFIG_OF being unset > > Change struct reg_field definitions to const > > Rename the syscon property to "loongson,dwmac-syscon" > > Add MII PHY mode for LS1C > > > > drivers/net/ethernet/stmicro/stmmac/Kconfig | 11 + > > drivers/net/ethernet/stmicro/stmmac/Makefile | 1 + > > .../ethernet/stmicro/stmmac/dwmac-loongson1.c | 219 ++++++++++++++++++ > > 3 files changed, 231 insertions(+) > > create mode 100644 drivers/net/ethernet/stmicro/stmmac/dwmac-loongson1= .c > > > > diff --git a/drivers/net/ethernet/stmicro/stmmac/Kconfig b/drivers/net/= ethernet/stmicro/stmmac/Kconfig > > index 06c6871f8788..a2b9e289aa36 100644 > > --- a/drivers/net/ethernet/stmicro/stmmac/Kconfig > > +++ b/drivers/net/ethernet/stmicro/stmmac/Kconfig > > @@ -239,6 +239,17 @@ config DWMAC_INTEL_PLAT > > the stmmac device driver. This driver is used for the Intel Kee= m Bay > > SoC. > > > > +config DWMAC_LOONGSON1 > > + tristate "Loongson1 GMAC support" > > + default MACH_LOONGSON32 > > + depends on OF && (MACH_LOONGSON32 || COMPILE_TEST) > > + help > > + Support for ethernet controller on Loongson1 SoC. > > + > > + This selects Loongson1 SoC glue layer support for the stmmac > > + device driver. This driver is used for Loongson1-based boards > > + like Loongson LS1B/LS1C. > > + > > config DWMAC_TEGRA > > tristate "NVIDIA Tegra MGBE support" > > depends on ARCH_TEGRA || COMPILE_TEST > > diff --git a/drivers/net/ethernet/stmicro/stmmac/Makefile b/drivers/net= /ethernet/stmicro/stmmac/Makefile > > index 5b57aee19267..80e598bd4255 100644 > > --- a/drivers/net/ethernet/stmicro/stmmac/Makefile > > +++ b/drivers/net/ethernet/stmicro/stmmac/Makefile > > @@ -29,6 +29,7 @@ obj-$(CONFIG_DWMAC_SUNXI) +=3D dwmac-sunxi.o > > obj-$(CONFIG_DWMAC_SUN8I) +=3D dwmac-sun8i.o > > obj-$(CONFIG_DWMAC_DWC_QOS_ETH) +=3D dwmac-dwc-qos-eth.o > > obj-$(CONFIG_DWMAC_INTEL_PLAT) +=3D dwmac-intel-plat.o > > +obj-$(CONFIG_DWMAC_LOONGSON1) +=3D dwmac-loongson1.o > > obj-$(CONFIG_DWMAC_GENERIC) +=3D dwmac-generic.o > > obj-$(CONFIG_DWMAC_IMX8) +=3D dwmac-imx.o > > obj-$(CONFIG_DWMAC_TEGRA) +=3D dwmac-tegra.o > > diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson1.c b/dr= ivers/net/ethernet/stmicro/stmmac/dwmac-loongson1.c > > new file mode 100644 > > index 000000000000..f1732f15ff87 > > --- /dev/null > > +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson1.c > > @@ -0,0 +1,219 @@ > > +// SPDX-License-Identifier: GPL-2.0-or-later > > +/* > > + * Loongson-1 DWMAC glue layer > > + * > > + * Copyright (C) 2011-2023 Keguang Zhang > > + */ > > + > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > + > > +#include "stmmac.h" > > +#include "stmmac_platform.h" > > + > > > +#define LS1B_GMAC0_BASE (0x1fe10000) > > I was talking about the LS1B_GMAC1_BASE macro only. Since both LS1B > and LS1C have GMAC0 at the same base address I would preserve > LS1X_GMAC0_BASE name here. But seeing it's unused for the LS1C anyway > it's not that a big deal. > > > +#define LS1B_GMAC1_BASE (0x1fe20000) > > + > > +/* Loongson-1 SYSCON Registers */ > > +#define LS1X_SYSCON0 (0x0) > > +#define LS1X_SYSCON1 (0x4) > > + > > +/* Loongson-1B SYSCON Register Bits */ > > +#define GMAC1_USE_UART1 BIT(4) > > +#define GMAC1_USE_UART0 BIT(3) > > + > > +#define GMAC1_SHUT BIT(13) > > +#define GMAC0_SHUT BIT(12) > > + > > +#define GMAC1_USE_TXCLK BIT(3) > > +#define GMAC0_USE_TXCLK BIT(2) > > +#define GMAC1_USE_PWM23 BIT(1) > > +#define GMAC0_USE_PWM01 BIT(0) > > + > > +/* Loongson-1C SYSCON Register Bits */ > > +#define GMAC_SHUT BIT(6) > > + > > +#define PHY_INTF_SELI GENMASK(30, 28) > > +#define PHY_INTF_MII FIELD_PREP(PHY_INTF_SELI, 0) > > +#define PHY_INTF_RMII FIELD_PREP(PHY_INTF_SELI, 4) > > + > > +struct ls1x_dwmac { > > + struct plat_stmmacenet_data *plat_dat; > > + struct regmap *regmap; > > +}; > > + > > +static int ls1b_dwmac_syscon_init(struct platform_device *pdev, void *= priv) > > +{ > > + struct ls1x_dwmac *dwmac =3D priv; > > + struct plat_stmmacenet_data *plat =3D dwmac->plat_dat; > > + struct regmap *regmap =3D dwmac->regmap; > > + struct resource *res; > > + unsigned long reg_base; > > + > > + res =3D platform_get_resource(pdev, IORESOURCE_MEM, 0); > > + if (!res) { > > + dev_err(&pdev->dev, "Could not get IO_MEM resources\n"); > > + return -EINVAL; > > + } > > + reg_base =3D (unsigned long)res->start; > > + > > + if (reg_base =3D=3D LS1B_GMAC0_BASE) { > > + switch (plat->phy_interface) { > > + case PHY_INTERFACE_MODE_RGMII_ID: > > + regmap_update_bits(regmap, LS1X_SYSCON0, > > + GMAC0_USE_TXCLK | GMAC0_USE_PW= M01, > > + 0); > > + break; > > + case PHY_INTERFACE_MODE_MII: > > + regmap_update_bits(regmap, LS1X_SYSCON0, > > + GMAC0_USE_TXCLK | GMAC0_USE_PW= M01, > > + GMAC0_USE_TXCLK | GMAC0_USE_PW= M01); > > + break; > > + default: > > + dev_err(&pdev->dev, "Unsupported PHY mode %u\n", > > + plat->phy_interface); > > + return -EOPNOTSUPP; > > + } > > + > > + regmap_update_bits(regmap, LS1X_SYSCON0, GMAC0_SHUT, 0); > > + } else if (reg_base =3D=3D LS1B_GMAC1_BASE) { > > + regmap_update_bits(regmap, LS1X_SYSCON0, > > + GMAC1_USE_UART1 | GMAC1_USE_UART0, > > + GMAC1_USE_UART1 | GMAC1_USE_UART0); > > + > > + switch (plat->phy_interface) { > > + case PHY_INTERFACE_MODE_RGMII_ID: > > + regmap_update_bits(regmap, LS1X_SYSCON1, > > + GMAC1_USE_TXCLK | GMAC1_USE_PW= M23, > > + 0); > > + > > + break; > > + case PHY_INTERFACE_MODE_MII: > > + regmap_update_bits(regmap, LS1X_SYSCON1, > > + GMAC1_USE_TXCLK | GMAC1_USE_PW= M23, > > + GMAC1_USE_TXCLK | GMAC1_USE_PW= M23); > > + break; > > + default: > > + dev_err(&pdev->dev, "Unsupported PHY mode %u\n", > > + plat->phy_interface); > > + return -EOPNOTSUPP; > > + } > > + > > + regmap_update_bits(regmap, LS1X_SYSCON1, GMAC1_SHUT, 0); > > + } else { > > + dev_err(&pdev->dev, "Invalid Ethernet MAC base address %l= x", > > + reg_base); > > + return -EINVAL; > > + } > > + > > + return 0; > > +} > > + > > +static int ls1c_dwmac_syscon_init(struct platform_device *pdev, void *= priv) > > +{ > > + struct ls1x_dwmac *dwmac =3D priv; > > + struct plat_stmmacenet_data *plat =3D dwmac->plat_dat; > > + struct regmap *regmap =3D dwmac->regmap; > > + > > + switch (plat->phy_interface) { > > + case PHY_INTERFACE_MODE_MII: > > + regmap_update_bits(regmap, LS1X_SYSCON1, PHY_INTF_SELI, > > + PHY_INTF_MII); > > + break; > > + case PHY_INTERFACE_MODE_RMII: > > + regmap_update_bits(regmap, LS1X_SYSCON1, PHY_INTF_SELI, > > + PHY_INTF_RMII); > > + break; > > + default: > > + dev_err(&pdev->dev, "Unsupported PHY-mode %u\n", > > + plat->phy_interface); > > + return -EOPNOTSUPP; > > + } > > + > > + regmap_update_bits(regmap, LS1X_SYSCON0, GMAC0_SHUT, 0); > > + > > + return 0; > > +} > > + > > +static int ls1x_dwmac_probe(struct platform_device *pdev) > > +{ > > + struct plat_stmmacenet_data *plat_dat; > > + struct stmmac_resources stmmac_res; > > + struct regmap *regmap; > > + struct ls1x_dwmac *dwmac; > > + int (*init)(struct platform_device *pdev, void *priv); > > + int ret; > > + > > + ret =3D stmmac_get_platform_resources(pdev, &stmmac_res); > > + if (ret) > > + return ret; > > + > > + /* Probe syscon */ > > + regmap =3D syscon_regmap_lookup_by_phandle(pdev->dev.of_node, > > + "loongson,ls1-syscon"); > > + if (IS_ERR(regmap)) > > + return dev_err_probe(&pdev->dev, PTR_ERR(regmap), > > + "Unable to find syscon\n"); > > + > > + init =3D of_device_get_match_data(&pdev->dev); > > + if (!init) { > > + dev_err(&pdev->dev, "No of match data provided\n"); > > + return -EINVAL; > > + } > > + > > + dwmac =3D devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL); > > + if (!dwmac) > > + return -ENOMEM; > > + > > > + plat_dat =3D stmmac_probe_config_dt(pdev, stmmac_res.mac); > > This can be replaced with devm_stmmac_probe_config_dt() and ... > > > + if (IS_ERR(plat_dat)) > > + return dev_err_probe(&pdev->dev, PTR_ERR(plat_dat), > > + "dt configuration failed\n"); > > + > > + plat_dat->bsp_priv =3D dwmac; > > + plat_dat->init =3D init; > > + dwmac->plat_dat =3D plat_dat; > > + dwmac->regmap =3D regmap; > > + > > > + ret =3D stmmac_pltfr_probe(pdev, plat_dat, &stmmac_res); > > ... this can be replaced with devm_stmmac_pltfr_probe() thus ... > > > + if (ret) > > + goto err_remove_config_dt; > > + > > + return 0; > > + > > > +err_remove_config_dt: > > + stmmac_remove_config_dt(pdev, plat_dat); > > + > > + return ret; > > ... this could have been omitted and ... > > > +} > > + > > +static const struct of_device_id ls1x_dwmac_match[] =3D { > > + { > > + .compatible =3D "loongson,ls1b-gmac", > > + .data =3D &ls1b_dwmac_syscon_init, > > + }, > > + { > > + .compatible =3D "loongson,ls1c-emac", > > + .data =3D &ls1c_dwmac_syscon_init, > > + }, > > + { } > > +}; > > +MODULE_DEVICE_TABLE(of, ls1x_dwmac_match); > > + > > +static struct platform_driver ls1x_dwmac_driver =3D { > > + .probe =3D ls1x_dwmac_probe, > > > + .remove_new =3D stmmac_pltfr_remove, > > ... this could have been dropped. > Will do all the above changes. Thanks! > -Serge(y) > > > + .driver =3D { > > + .name =3D "loongson1-dwmac", > > + .of_match_table =3D ls1x_dwmac_match, > > + }, > > +}; > > +module_platform_driver(ls1x_dwmac_driver); > > + > > +MODULE_AUTHOR("Keguang Zhang "); > > +MODULE_DESCRIPTION("Loongson-1 DWMAC glue layer"); > > +MODULE_LICENSE("GPL"); > > -- > > 2.39.2 > > > > --=20 Best regards, Keguang Zhang