Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp910001rwd; Thu, 25 May 2023 05:51:49 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7KhAgcUT4h55pcE4qijBaYVO0mhzQ0Q5dnSsrKsL9V+T+pt6931KxRamxrg5W6lOd8T1nK X-Received: by 2002:a17:902:d4c5:b0:1ac:6c46:8c80 with SMTP id o5-20020a170902d4c500b001ac6c468c80mr1683598plg.53.1685019109194; Thu, 25 May 2023 05:51:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685019109; cv=none; d=google.com; s=arc-20160816; b=xXN6+sJWnVbiwz8W0ae9zrDQiAjrB5NtDyRGfCdN5LoQZ0xUQKo7dz7QxGSffixksL HgAzbVpBObzkpE+dhXPMpSFeR8ipZXPPaPStXfNCNu2kIzF2rRuFC1uThqpjDRONww4J YqddiQAhHEMmdudmm50TrIal61uJFGlnmBRQLb3q++e0HlsESeP8N4XrNKwiQmRoVLa8 pqu4kjioM4daoI9JTmWVGZAGwJ8IOCo119HpMru6mJ5YPtA8kOZprbehwqEHaJIDq87h Z3DIuecbn8oVVaslvBPrBY3c4j4lq44wLhIxeWhNDIshF/y8v1/EixH3OnDTu+s09gWF gU9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=feQW98atuVGJR2g0z3VlLS9I5fF0OgwIq8sXEMfFC28=; b=UYWjDhXrFMwThBfnhT6wtWsJ92Ahpezv3XmKG316pFK9Iez4ZgfN8l5RNFzNUHBb5P fqHkPLsWddH/yZp6a+rXbBUKIe9fJ2ZmZFNLcxfDECxbMYCkQdUSCUptYsBcO/aSlFTN /ZGDJLZXjwKygTBe5BS3DmCaczbH3K3z+NxZJMuw+dhiOIBgD8O2OnYTcZpdFLrVJKKs 4jjPIrfzrXfeFY4/0j+4zbl18byW5Wzgrw8vI3M/scguY8gasmlGt/N6zvFzdZVvacpx nhuNtXL+I1fml3oxGb4SH0YuOD3gzEzKuif5bwTsOGSn4crWZbPteSJ/n7X96wT4Ohgt dxbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=d2q9GAMD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m17-20020a170902db1100b001a97fd670d5si1524013plx.367.2023.05.25.05.51.37; Thu, 25 May 2023 05:51:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=d2q9GAMD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240892AbjEYMoK (ORCPT + 99 others); Thu, 25 May 2023 08:44:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231895AbjEYMoI (ORCPT ); Thu, 25 May 2023 08:44:08 -0400 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::226]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A4D29B; Thu, 25 May 2023 05:44:05 -0700 (PDT) X-GND-Sasl: maxime.chevallier@bootlin.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1685018644; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=feQW98atuVGJR2g0z3VlLS9I5fF0OgwIq8sXEMfFC28=; b=d2q9GAMDrDVfcZSPsOhWMuyyoXiCcYlXwPhHX3iLR80pY8cnEsNDVhuflsLM1uEys7WC3Q iEk/QVY+mnBmjDGSB3MW4JvhtiMokHVMM04OkEC1kzROmDIBxrLJlP+PlFHiSYfCN11lP3 2DZhxM4AtrVs7tWNVv/SHhSJzPEX6xUHfNdmPwz/SfBJvgbQRTwHRGohnvU9gELWmwU/kP dTXDtu5DL7U2BInP48pr7dfIWP8EzQKQV8B75aGxMr1H4hLldw8CTJcb2PjHuBxIrkqnzw SVMspbG1cBVIBsd2YXO5IzXPlnai3Hu5uq+siLA5CoF22I2JX8K+jxyZgBe8rQ== X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id A9647C0013; Thu, 25 May 2023 12:44:00 +0000 (UTC) Date: Thu, 25 May 2023 14:43:59 +0200 From: Maxime Chevallier To: Simon Horman Cc: Mark Brown , davem@davemloft.net, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, alexis.lothore@bootlin.com, thomas.petazzoni@bootlin.com, Andrew Lunn , Jakub Kicinski , Eric Dumazet , Paolo Abeni , Florian Fainelli , Heiner Kallweit , Russell King , Vladimir Oltean , Ioana Ciornei , linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, Maxime Coquelin , Jose Abreu , Alexandre Torgue , Giuseppe Cavallaro Subject: Re: [PATCH net-next v2 1/4] net: mdio: Introduce a regmap-based mdio driver Message-ID: <20230525144359.0cb16996@pc-7.home> In-Reply-To: References: <20230525101126.370108-1-maxime.chevallier@bootlin.com> <20230525101126.370108-2-maxime.chevallier@bootlin.com> Organization: Bootlin X-Mailer: Claws Mail 4.1.1 (GTK 3.24.37; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello Simon, On Thu, 25 May 2023 13:02:39 +0200 Simon Horman wrote: > On Thu, May 25, 2023 at 12:11:23PM +0200, Maxime Chevallier wrote: > > There exists several examples today of devices that embed an > > ethernet PHY or PCS directly inside an SoC. In this situation, > > either the device is controlled through a vendor-specific register > > set, or sometimes exposes the standard 802.3 registers that are > > typically accessed over MDIO. > > > > As phylib and phylink are designed to use mdiodevices, this driver > > allows creating a virtual MDIO bus, that translates mdiodev register > > accesses to regmap accesses. > > > > The reason we use regmap is because there are at least 3 such > > devices known today, 2 of them are Altera TSE PCS's, memory-mapped, > > exposed with a 4-byte stride in stmmac's dwmac-socfpga variant, and > > a 2-byte stride in altera-tse. The other one > > (nxp,sja1110-base-tx-mdio) is exposed over SPI. > > > > Signed-off-by: Maxime Chevallier > > ... > > > +struct mii_bus *devm_mdio_regmap_register(struct device *dev, > > + const struct > > mdio_regmap_config *config) +{ > > + struct mdio_regmap_config *mrc; > > + struct mii_bus *mii; > > + int rc; > > + > > + if (!config->parent) > > + return ERR_PTR(-EINVAL); > > + > > + mii = devm_mdiobus_alloc_size(config->parent, > > sizeof(*mrc)); > > + if (!mii) > > + return ERR_PTR(-ENOMEM); > > + > > + mrc = mii->priv; > > + memcpy(mrc, config, sizeof(*mrc)); > > + > > + mrc->regmap = config->regmap; > > + mrc->valid_addr = config->valid_addr; > > + > > + mii->name = DRV_NAME; > > + strscpy(mii->id, config->name, MII_BUS_ID_SIZE); > > + mii->parent = config->parent; > > + mii->read = mdio_regmap_read_c22; > > + mii->write = mdio_regmap_write_c22; > > + > > + if (config->autoscan) > > + mii->phy_mask = ~BIT(config->valid_addr); > > + else > > + mii->phy_mask = ~0UL; > > Hi Maxime, > > phy_mask is a u32. > But 0UL may be either 32 or 64 bits wide. Right > I think a better approach would be to use U32_MAX. I guess ~0 would also work, and this would also align with what fixed-phy and sfp do for their internal MDIO bus. I'll fix that for next revision Thanks, Maxime > > + > > + rc = devm_mdiobus_register(dev, mii); > > + if (rc) { > > + dev_err(config->parent, "Cannot register MDIO > > bus![%s] (%d)\n", mii->id, rc); > > + return ERR_PTR(rc); > > + } > > + > > + return mii; > > +} > > +EXPORT_SYMBOL_GPL(devm_mdio_regmap_register); > > + > > +MODULE_DESCRIPTION("MDIO API over regmap"); > > +MODULE_AUTHOR("Maxime Chevallier "); > > +MODULE_LICENSE("GPL");