From patchwork Mon Jun 20 15:02:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcin Wojtas X-Patchwork-Id: 583652 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A6B0DCCA479 for ; Mon, 20 Jun 2022 15:12:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242772AbiFTPMR (ORCPT ); Mon, 20 Jun 2022 11:12:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242437AbiFTPMH (ORCPT ); Mon, 20 Jun 2022 11:12:07 -0400 Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [IPv6:2a00:1450:4864:20::22b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 386FA15818 for ; Mon, 20 Jun 2022 08:02:47 -0700 (PDT) Received: by mail-lj1-x22b.google.com with SMTP id j22so5610275ljg.0 for ; Mon, 20 Jun 2022 08:02:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=odsCatuXRn3NiFBtyBRCzHVor61VJmIiPLvNMLhLp6I=; b=aZ2SA144QSpo6RHPerj2ftJyZhKtwm1sbmaAaXQeL8x/+FjvAw1MuVtdCiO1orB+c5 PssXfydj1OxhxMzSx5OEdScZJfG+HvDkJxx5WkSBG4es+EcPWMncU9JqCqrPGSPMTcbz muMw85qeCuumFnWW1OKyMMbnPM1C4Rix+jVgu0ta9mx2SRKIU4hEpsivzXa6TzH4xyW/ cwOez0dj6qOpr7ErEML5XyhVBcRzLLN5mwunrciIkU1gTa8ys3ekZ4fh0LNrNwudQghn ivCGgNJK73nka/wA1n8QIfPFx96JR/3yPdqHxwR+Nd53rGfsrImCxuN9gJ2ixjmVIk/G ru5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=odsCatuXRn3NiFBtyBRCzHVor61VJmIiPLvNMLhLp6I=; b=l0W0tw5UVLF/ZK6Reqgj+JWT5bttgu+t9Oz7W0w1L1Bj/al61lQO/p8oNoYRKZVeUO /1jDMcrcWBmJ65S/ZfGVLael8qv/x26ZSG5NZuCt7GoNTzLZ3Q3laYmNG8uKSjhEYbJw 1Q4ELPmMCKEi20Gr1xJjg1RixrOQz6rGzRU64EUz5IdLNFfQcv4UJM+FC/qeI94ApzUo QChmGrnBCDqEMzm2Aa1tAuXnJfOrEJYByHFvvOYi9HhqkYzOfh4wbByJjGFxDRvlO2n7 ui/J13K91Y1uR1VTUzb/xbcggbgBtQxjdoD8PCgOKGVFX3BuG7ep2ZZZXiFwHhGQGRsc KeVw== X-Gm-Message-State: AJIora94QUnfY61PObCLvExMq4o5yAG7L2zDj/eRoDMWsiYbN3DXC8Vz fsnjDheF7N+2OeH2wr+mO7Xt9w== X-Google-Smtp-Source: AGRyM1uVExzZpk82Zbw+UxgYL4S8+8n1cDZH0dX8WGn051iDAvPPamQIsf6HPyuEmJXNRZSVdWgdJA== X-Received: by 2002:a05:651c:b29:b0:255:6ecc:96f with SMTP id b41-20020a05651c0b2900b002556ecc096fmr11849054ljr.176.1655737365366; Mon, 20 Jun 2022 08:02:45 -0700 (PDT) Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id e19-20020a05651236d300b0047f79f7758asm17564lfs.22.2022.06.20.08.02.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jun 2022 08:02:44 -0700 (PDT) From: Marcin Wojtas To: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, netdev@vger.kernel.org Cc: rafael@kernel.org, andriy.shevchenko@linux.intel.com, lenb@kernel.org, andrew@lunn.ch, vivien.didelot@gmail.com, f.fainelli@gmail.com, olteanv@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux@armlinux.org.uk, hkallweit1@gmail.com, gjb@semihalf.com, mw@semihalf.com, jaz@semihalf.com, tn@semihalf.com, Samer.El-Haj-Mahmoud@arm.com, upstream@semihalf.com Subject: [net-next: PATCH 01/12] net: phy: fixed_phy: switch to fwnode_ API Date: Mon, 20 Jun 2022 17:02:14 +0200 Message-Id: <20220620150225.1307946-2-mw@semihalf.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20220620150225.1307946-1-mw@semihalf.com> References: <20220620150225.1307946-1-mw@semihalf.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org This patch allows to use fixed_phy driver and its helper functions without Device Tree dependency, by swtiching from of_ to fwnode_ API. Signed-off-by: Marcin Wojtas --- include/linux/phy_fixed.h | 4 +-- drivers/net/mdio/of_mdio.c | 2 +- drivers/net/phy/fixed_phy.c | 37 ++++++++------------ 3 files changed, 18 insertions(+), 25 deletions(-) diff --git a/include/linux/phy_fixed.h b/include/linux/phy_fixed.h index 52bc8e487ef7..449a927231ec 100644 --- a/include/linux/phy_fixed.h +++ b/include/linux/phy_fixed.h @@ -19,7 +19,7 @@ extern int fixed_phy_add(unsigned int irq, int phy_id, struct fixed_phy_status *status); extern struct phy_device *fixed_phy_register(unsigned int irq, struct fixed_phy_status *status, - struct device_node *np); + struct fwnode_handle *fwnode); extern struct phy_device * fixed_phy_register_with_gpiod(unsigned int irq, @@ -38,7 +38,7 @@ static inline int fixed_phy_add(unsigned int irq, int phy_id, } static inline struct phy_device *fixed_phy_register(unsigned int irq, struct fixed_phy_status *status, - struct device_node *np) + struct fwnode_handle *fwnode) { return ERR_PTR(-ENODEV); } diff --git a/drivers/net/mdio/of_mdio.c b/drivers/net/mdio/of_mdio.c index 9e3c815a070f..d755fe1ecdda 100644 --- a/drivers/net/mdio/of_mdio.c +++ b/drivers/net/mdio/of_mdio.c @@ -421,7 +421,7 @@ int of_phy_register_fixed_link(struct device_node *np) return -ENODEV; register_phy: - return PTR_ERR_OR_ZERO(fixed_phy_register(PHY_POLL, &status, np)); + return PTR_ERR_OR_ZERO(fixed_phy_register(PHY_POLL, &status, of_fwnode_handle(np))); } EXPORT_SYMBOL(of_phy_register_fixed_link); diff --git a/drivers/net/phy/fixed_phy.c b/drivers/net/phy/fixed_phy.c index aef739c20ac4..0dbe6c344b05 100644 --- a/drivers/net/phy/fixed_phy.c +++ b/drivers/net/phy/fixed_phy.c @@ -15,9 +15,9 @@ #include #include #include +#include #include #include -#include #include #include #include @@ -186,16 +186,15 @@ static void fixed_phy_del(int phy_addr) } } -#ifdef CONFIG_OF_GPIO -static struct gpio_desc *fixed_phy_get_gpiod(struct device_node *np) +static struct gpio_desc *fixed_phy_get_gpiod(struct fwnode_handle *fwnode) { - struct device_node *fixed_link_node; + struct fwnode_handle *fixed_link_node; struct gpio_desc *gpiod; - if (!np) + if (!fwnode) return NULL; - fixed_link_node = of_get_child_by_name(np, "fixed-link"); + fixed_link_node = fwnode_get_named_child_node(fwnode, "fixed-link"); if (!fixed_link_node) return NULL; @@ -204,7 +203,7 @@ static struct gpio_desc *fixed_phy_get_gpiod(struct device_node *np) * Linux device associated with it, we simply have obtain * the GPIO descriptor from the device tree like this. */ - gpiod = fwnode_gpiod_get_index(of_fwnode_handle(fixed_link_node), + gpiod = fwnode_gpiod_get_index(fixed_link_node, "link", 0, GPIOD_IN, "mdio"); if (IS_ERR(gpiod) && PTR_ERR(gpiod) != -EPROBE_DEFER) { if (PTR_ERR(gpiod) != -ENOENT) @@ -212,20 +211,14 @@ static struct gpio_desc *fixed_phy_get_gpiod(struct device_node *np) fixed_link_node); gpiod = NULL; } - of_node_put(fixed_link_node); + fwnode_handle_put(fixed_link_node); return gpiod; } -#else -static struct gpio_desc *fixed_phy_get_gpiod(struct device_node *np) -{ - return NULL; -} -#endif static struct phy_device *__fixed_phy_register(unsigned int irq, struct fixed_phy_status *status, - struct device_node *np, + struct fwnode_handle *fwnode, struct gpio_desc *gpiod) { struct fixed_mdio_bus *fmb = &platform_fmb; @@ -238,7 +231,7 @@ static struct phy_device *__fixed_phy_register(unsigned int irq, /* Check if we have a GPIO associated with this fixed phy */ if (!gpiod) { - gpiod = fixed_phy_get_gpiod(np); + gpiod = fixed_phy_get_gpiod(fwnode); if (IS_ERR(gpiod)) return ERR_CAST(gpiod); } @@ -269,8 +262,8 @@ static struct phy_device *__fixed_phy_register(unsigned int irq, phy->asym_pause = status->asym_pause; } - of_node_get(np); - phy->mdio.dev.of_node = np; + fwnode_handle_get(fwnode); + phy->mdio.dev.fwnode = fwnode; phy->is_pseudo_fixed_link = true; switch (status->speed) { @@ -299,7 +292,7 @@ static struct phy_device *__fixed_phy_register(unsigned int irq, ret = phy_device_register(phy); if (ret) { phy_device_free(phy); - of_node_put(np); + fwnode_handle_put(fwnode); fixed_phy_del(phy_addr); return ERR_PTR(ret); } @@ -309,9 +302,9 @@ static struct phy_device *__fixed_phy_register(unsigned int irq, struct phy_device *fixed_phy_register(unsigned int irq, struct fixed_phy_status *status, - struct device_node *np) + struct fwnode_handle *fwnode) { - return __fixed_phy_register(irq, status, np, NULL); + return __fixed_phy_register(irq, status, fwnode, NULL); } EXPORT_SYMBOL_GPL(fixed_phy_register); @@ -327,7 +320,7 @@ EXPORT_SYMBOL_GPL(fixed_phy_register_with_gpiod); void fixed_phy_unregister(struct phy_device *phy) { phy_device_remove(phy); - of_node_put(phy->mdio.dev.of_node); + fwnode_handle_put(phy->mdio.dev.fwnode); fixed_phy_del(phy->mdio.addr); } EXPORT_SYMBOL_GPL(fixed_phy_unregister); From patchwork Mon Jun 20 15:02:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcin Wojtas X-Patchwork-Id: 583651 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8BD1CCA479 for ; Mon, 20 Jun 2022 15:12:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243471AbiFTPMY (ORCPT ); Mon, 20 Jun 2022 11:12:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242945AbiFTPMI (ORCPT ); Mon, 20 Jun 2022 11:12:08 -0400 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73C6619FB8 for ; Mon, 20 Jun 2022 08:02:48 -0700 (PDT) Received: by mail-lf1-x133.google.com with SMTP id a13so7848823lfr.10 for ; Mon, 20 Jun 2022 08:02:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xFucQ3C/FYSxEEKLXgm7WEUAFTqRGfOx5PDeN0uOhvc=; b=I/l5jek5ysAPkzJhksovOM5xmWjXfNbCusHoQYicryGVeH2FpRoLLs1n7zbOGDy0w0 2JhlU2J/4rMAtZMYtqplfZSwsvgYiaLEJ0i1gdIj6W69DJ7tznZre1A5fQKR+WtgEzkf Jgfms8bXzux9le5rE4IsfakL8nt33uedbbwWUeNEkjghENjTsacOG46qJV38EP1WH7oI eReHw7Eqzr5imRh9gcg8olJHtAWHq147h0oWqlYVSyDpvi181fBSDXat/KfmQco8FoaA QdHlrunaRjrMS5tCDCnBrYKFtfrYRXxDCw6EljUXWA9R+PA1zBJen6/tkE7Gzemjk4hf YNLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xFucQ3C/FYSxEEKLXgm7WEUAFTqRGfOx5PDeN0uOhvc=; b=MBcqEfLDCKL/b7tSThDP7lICfgz4Rr8BUKGoe0AuNk4JuPbQlQ/0EroI+iSmn0GrZk R1QFSPQ/1L3A5YhV5+Y2HU4LEMU6Nb/JD36HKvK+tDuESq3ROYZuiCy03jB2wLK59nKy 60LuZJg1HLdfnuQHaCO3w4rHUXuibUQJWmahFDOqJfcmtK6HNHBKljn1sDAzFdvWSlSv EA6SKgup6J80HZVLnKbfnVzUHMZtaW5WOaP9llC0Uol7w1o0mNajfyL1LUwTjuuxtnOt LQXRLMe39ePAXrlwx9A5R4bBQwEejpcYj4ZYXPw9fIKcg23FT8IabhziAe+evxZBunr/ 7L8A== X-Gm-Message-State: AJIora+Ja4Q6EIZwUMZyu/PXwueae9aEg+S6rIESZ9FGpGqKdSXj9aw0 CPXDZiXufpnD3HxtG7PusIbAMg== X-Google-Smtp-Source: AGRyM1uP5Akkrn+zO5ywGqHgQ1zT/LsX1aQLDykb/IEqucwHpSCG6STCHEn2ODcLvYDyjcwthz1pGA== X-Received: by 2002:a05:6512:2207:b0:47f:70b3:52d with SMTP id h7-20020a056512220700b0047f70b3052dmr2566673lfu.174.1655737366560; Mon, 20 Jun 2022 08:02:46 -0700 (PDT) Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id e19-20020a05651236d300b0047f79f7758asm17564lfs.22.2022.06.20.08.02.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jun 2022 08:02:46 -0700 (PDT) From: Marcin Wojtas To: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, netdev@vger.kernel.org Cc: rafael@kernel.org, andriy.shevchenko@linux.intel.com, lenb@kernel.org, andrew@lunn.ch, vivien.didelot@gmail.com, f.fainelli@gmail.com, olteanv@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux@armlinux.org.uk, hkallweit1@gmail.com, gjb@semihalf.com, mw@semihalf.com, jaz@semihalf.com, tn@semihalf.com, Samer.El-Haj-Mahmoud@arm.com, upstream@semihalf.com Subject: [net-next: PATCH 02/12] net: mdio: switch fixed-link PHYs API to fwnode_ Date: Mon, 20 Jun 2022 17:02:15 +0200 Message-Id: <20220620150225.1307946-3-mw@semihalf.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20220620150225.1307946-1-mw@semihalf.com> References: <20220620150225.1307946-1-mw@semihalf.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org fixed-link PHYs API is used by DSA and a number of drivers and was depending on of_. Switch to fwnode_ so to make it hardware description agnostic and allow to be used in ACPI world as well. Signed-off-by: Marcin Wojtas --- include/linux/fwnode_mdio.h | 19 ++++ drivers/net/mdio/fwnode_mdio.c | 100 ++++++++++++++++++++ drivers/net/mdio/of_mdio.c | 79 +--------------- 3 files changed, 122 insertions(+), 76 deletions(-) diff --git a/include/linux/fwnode_mdio.h b/include/linux/fwnode_mdio.h index faf603c48c86..98755b8c6c8a 100644 --- a/include/linux/fwnode_mdio.h +++ b/include/linux/fwnode_mdio.h @@ -16,6 +16,11 @@ int fwnode_mdiobus_phy_device_register(struct mii_bus *mdio, int fwnode_mdiobus_register_phy(struct mii_bus *bus, struct fwnode_handle *child, u32 addr); +int fwnode_phy_register_fixed_link(struct fwnode_handle *fwnode); + +void fwnode_phy_deregister_fixed_link(struct fwnode_handle *fwnode); + +bool fwnode_phy_is_fixed_link(struct fwnode_handle *fwnode); #else /* CONFIG_FWNODE_MDIO */ int fwnode_mdiobus_phy_device_register(struct mii_bus *mdio, struct phy_device *phy, @@ -30,6 +35,20 @@ static inline int fwnode_mdiobus_register_phy(struct mii_bus *bus, { return -EINVAL; } + +static inline int fwnode_phy_register_fixed_link(struct fwnode_handle *fwnode) +{ + return -ENODEV; +} + +static inline void fwnode_phy_deregister_fixed_link(struct fwnode_handle *fwnode) +{ +} + +static inline bool fwnode_phy_is_fixed_link(struct fwnode_handle *fwnode) +{ + return false; +} #endif #endif /* __LINUX_FWNODE_MDIO_H */ diff --git a/drivers/net/mdio/fwnode_mdio.c b/drivers/net/mdio/fwnode_mdio.c index 1c1584fca632..b1c20c48b6cb 100644 --- a/drivers/net/mdio/fwnode_mdio.c +++ b/drivers/net/mdio/fwnode_mdio.c @@ -10,6 +10,7 @@ #include #include #include +#include MODULE_AUTHOR("Calvin Johnson "); MODULE_LICENSE("GPL"); @@ -147,3 +148,102 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus, return 0; } EXPORT_SYMBOL(fwnode_mdiobus_register_phy); + +/* + * fwnode_phy_is_fixed_link() and fwnode_phy_register_fixed_link() must + * support two bindings: + * - the old binding, where 'fixed-link' was a property with 5 + * cells encoding various information about the fixed PHY + * - the new binding, where 'fixed-link' is a sub-node of the + * Ethernet device. + */ +bool fwnode_phy_is_fixed_link(struct fwnode_handle *fwnode) +{ + struct fwnode_handle *fixed_link_node; + const char *managed; + int len; + + /* New binding */ + fixed_link_node = fwnode_get_named_child_node(fwnode, "fixed-link"); + if (fixed_link_node) { + fwnode_handle_put(fixed_link_node); + return true; + } + + if (fwnode_property_read_string(fwnode, "managed", &managed) == 0 && + strcmp(managed, "auto") != 0) + return true; + + /* Old binding */ + len = fwnode_property_read_u32_array(fwnode, "fixed-link", NULL, 0); + if (len == (5 * sizeof(u32))) + return true; + + return false; +} +EXPORT_SYMBOL(fwnode_phy_is_fixed_link); + +int fwnode_phy_register_fixed_link(struct fwnode_handle *fwnode) +{ + struct fixed_phy_status status = {}; + struct fwnode_handle *fixed_link_node; + u32 fixed_link_prop[5]; + const char *managed; + + if (fwnode_property_read_string(fwnode, "managed", &managed) == 0 && + strcmp(managed, "in-band-status") == 0) { + /* status is zeroed, namely its .link member */ + goto register_phy; + } + + /* New binding */ + fixed_link_node = fwnode_get_named_child_node(fwnode, "fixed-link"); + if (fixed_link_node) { + status.link = 1; + status.duplex = fwnode_property_present(fixed_link_node, + "full-duplex"); + if (fwnode_property_read_u32(fixed_link_node, "speed", + &status.speed)) { + fwnode_handle_put(fixed_link_node); + return -EINVAL; + } + status.pause = fwnode_property_present(fixed_link_node, "pause"); + status.asym_pause = fwnode_property_present(fixed_link_node, + "asym-pause"); + fwnode_handle_put(fixed_link_node); + + goto register_phy; + } + + /* Old binding */ + if (fwnode_property_read_u32_array(fwnode, "fixed-link", fixed_link_prop, + ARRAY_SIZE(fixed_link_prop)) == 0) { + status.link = 1; + status.duplex = fixed_link_prop[1]; + status.speed = fixed_link_prop[2]; + status.pause = fixed_link_prop[3]; + status.asym_pause = fixed_link_prop[4]; + goto register_phy; + } + + return -ENODEV; + +register_phy: + return PTR_ERR_OR_ZERO(fixed_phy_register(PHY_POLL, &status, fwnode)); +} +EXPORT_SYMBOL(fwnode_phy_register_fixed_link); + +void fwnode_phy_deregister_fixed_link(struct fwnode_handle *fwnode) +{ + struct phy_device *phydev; + + phydev = fwnode_phy_find_device(fwnode); + if (!phydev) + return; + + fixed_phy_unregister(phydev); + + put_device(&phydev->mdio.dev); /* fwnode_phy_find_device() */ + phy_device_free(phydev); /* fixed_phy_register() */ +} +EXPORT_SYMBOL(fwnode_phy_deregister_fixed_link); diff --git a/drivers/net/mdio/of_mdio.c b/drivers/net/mdio/of_mdio.c index d755fe1ecdda..409da6e92f7d 100644 --- a/drivers/net/mdio/of_mdio.c +++ b/drivers/net/mdio/of_mdio.c @@ -351,91 +351,18 @@ EXPORT_SYMBOL(of_phy_get_and_connect); */ bool of_phy_is_fixed_link(struct device_node *np) { - struct device_node *dn; - int len, err; - const char *managed; - - /* New binding */ - dn = of_get_child_by_name(np, "fixed-link"); - if (dn) { - of_node_put(dn); - return true; - } - - err = of_property_read_string(np, "managed", &managed); - if (err == 0 && strcmp(managed, "auto") != 0) - return true; - - /* Old binding */ - if (of_get_property(np, "fixed-link", &len) && - len == (5 * sizeof(__be32))) - return true; - - return false; + return fwnode_phy_is_fixed_link(of_fwnode_handle(np)); } EXPORT_SYMBOL(of_phy_is_fixed_link); int of_phy_register_fixed_link(struct device_node *np) { - struct fixed_phy_status status = {}; - struct device_node *fixed_link_node; - u32 fixed_link_prop[5]; - const char *managed; - - if (of_property_read_string(np, "managed", &managed) == 0 && - strcmp(managed, "in-band-status") == 0) { - /* status is zeroed, namely its .link member */ - goto register_phy; - } - - /* New binding */ - fixed_link_node = of_get_child_by_name(np, "fixed-link"); - if (fixed_link_node) { - status.link = 1; - status.duplex = of_property_read_bool(fixed_link_node, - "full-duplex"); - if (of_property_read_u32(fixed_link_node, "speed", - &status.speed)) { - of_node_put(fixed_link_node); - return -EINVAL; - } - status.pause = of_property_read_bool(fixed_link_node, "pause"); - status.asym_pause = of_property_read_bool(fixed_link_node, - "asym-pause"); - of_node_put(fixed_link_node); - - goto register_phy; - } - - /* Old binding */ - if (of_property_read_u32_array(np, "fixed-link", fixed_link_prop, - ARRAY_SIZE(fixed_link_prop)) == 0) { - status.link = 1; - status.duplex = fixed_link_prop[1]; - status.speed = fixed_link_prop[2]; - status.pause = fixed_link_prop[3]; - status.asym_pause = fixed_link_prop[4]; - goto register_phy; - } - - return -ENODEV; - -register_phy: - return PTR_ERR_OR_ZERO(fixed_phy_register(PHY_POLL, &status, of_fwnode_handle(np))); + return fwnode_phy_register_fixed_link(of_fwnode_handle(np)); } EXPORT_SYMBOL(of_phy_register_fixed_link); void of_phy_deregister_fixed_link(struct device_node *np) { - struct phy_device *phydev; - - phydev = of_phy_find_device(np); - if (!phydev) - return; - - fixed_phy_unregister(phydev); - - put_device(&phydev->mdio.dev); /* of_phy_find_device() */ - phy_device_free(phydev); /* fixed_phy_register() */ + fwnode_phy_deregister_fixed_link(of_fwnode_handle(np)); } EXPORT_SYMBOL(of_phy_deregister_fixed_link); From patchwork Mon Jun 20 15:02:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcin Wojtas X-Patchwork-Id: 583310 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CF4EAC43334 for ; Mon, 20 Jun 2022 15:12:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243478AbiFTPMZ (ORCPT ); Mon, 20 Jun 2022 11:12:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242952AbiFTPMJ (ORCPT ); Mon, 20 Jun 2022 11:12:09 -0400 Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C87EF7 for ; Mon, 20 Jun 2022 08:02:49 -0700 (PDT) Received: by mail-lj1-x22e.google.com with SMTP id g12so6165195ljk.11 for ; Mon, 20 Jun 2022 08:02:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=e2Cd3eQM+C0dmzMqQNndhsAzgMvOaojaEFbBvNt2Fic=; b=Y4nEEPRsmVHDrSrrfoAQXg2HXs8O1oRslQ0rXWFDmT1MQg4bHUJL2uHX/OOCRvZAW4 2S6o+7TVjw/ERDVOILwrSaPS//OM63T7tfMQ4K/VVBbwUrIjCmSeHYpfukvEnXSaH3GS g9RopuRsVEIfV6WG/l0vQ8Q8QjuOD79ofy6E9L+ud6q0kHSVqfMLkHrRPYzRV83RZdXv 182nkIlpjYjDUe6WaGf4cfvKkOVyzgEpWJBMRJVB5+qoNl/WL0IOIaE6l2MgkrQsuYHU C3O/mpbvUhWnVF473pNgkRNOL/MnwEH2NvhmlPAS7T0YMgj854Mca35OKYj/8+gOunDY 8qiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=e2Cd3eQM+C0dmzMqQNndhsAzgMvOaojaEFbBvNt2Fic=; b=gZdGceopd2LJOVCkUapKkU9xmDeXwu6srtCO1zdleIZO2KAGY1VKrPBEJK2hIx3Ce5 yBRxihbWpi/F4wOTUB81zpvyD7PI6Ia2Ff+upFJ74g317yRS45umaGioAiPKzQrY5YPU 5AT75cQCn69EqRGiDUZwaaGF6TbQxJd8QyFlv6JOEbVV8Os5Eq4g9O4WyVSk9CGL3aor sc0XShEKmM5KM4DOku9JrLFyQ1tulLd8mR93GV6zyXk1W2RrNA2rva3og/ov/LtQP3K0 yPqRCQas/9Mf5mGMUcZNxmCO+XIb+K5A3L7ksdBW0uUfQtBJtfZuNsOWcNl8jclmi3Mv l55w== X-Gm-Message-State: AJIora8EroqbH6j0jDPHXXm7GB0StFxfnrsPrDdoavDtg9OyrA+tVmtr MmSmsT3VeiY9qqFrGofS0gVV9A== X-Google-Smtp-Source: AGRyM1sssAdqhBLIlWixMfcjN1PbIhBI1R2jYI1eP+BdaY9z+Y9WaAwKpF25q33k5Pl/owqtSeU3RA== X-Received: by 2002:a2e:a289:0:b0:258:e917:36a4 with SMTP id k9-20020a2ea289000000b00258e91736a4mr11965710lja.510.1655737367628; Mon, 20 Jun 2022 08:02:47 -0700 (PDT) Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id e19-20020a05651236d300b0047f79f7758asm17564lfs.22.2022.06.20.08.02.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jun 2022 08:02:47 -0700 (PDT) From: Marcin Wojtas To: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, netdev@vger.kernel.org Cc: rafael@kernel.org, andriy.shevchenko@linux.intel.com, lenb@kernel.org, andrew@lunn.ch, vivien.didelot@gmail.com, f.fainelli@gmail.com, olteanv@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux@armlinux.org.uk, hkallweit1@gmail.com, gjb@semihalf.com, mw@semihalf.com, jaz@semihalf.com, tn@semihalf.com, Samer.El-Haj-Mahmoud@arm.com, upstream@semihalf.com Subject: [net-next: PATCH 03/12] net: dsa: switch to device_/fwnode_ APIs Date: Mon, 20 Jun 2022 17:02:16 +0200 Message-Id: <20220620150225.1307946-4-mw@semihalf.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20220620150225.1307946-1-mw@semihalf.com> References: <20220620150225.1307946-1-mw@semihalf.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org In order to support both ACPI and DT, modify the generic DSA code to use device_/fwnode_ equivalent routines. No functional change is introduced by this patch. Signed-off-by: Marcin Wojtas --- include/net/dsa.h | 1 + net/dsa/dsa2.c | 76 +++++++++++--------- net/dsa/port.c | 54 +++++++------- net/dsa/slave.c | 6 +- 4 files changed, 71 insertions(+), 66 deletions(-) diff --git a/include/net/dsa.h b/include/net/dsa.h index 14f07275852b..692c1dddc5f8 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -299,6 +299,7 @@ struct dsa_port { u8 setup:1; struct device_node *dn; + struct fwnode_handle *fwnode; unsigned int ageing_time; struct dsa_bridge *bridge; diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c index cac48a741f27..039022bf914b 100644 --- a/net/dsa/dsa2.c +++ b/net/dsa/dsa2.c @@ -493,7 +493,7 @@ static int dsa_port_setup(struct dsa_port *dp) break; case DSA_PORT_TYPE_USER: - of_get_mac_address(dp->dn, dp->mac); + fwnode_get_mac_address(dp->fwnode, dp->mac); err = dsa_slave_create(dp); if (err) break; @@ -853,7 +853,7 @@ static int dsa_switch_setup_tag_protocol(struct dsa_switch *ds) static int dsa_switch_setup(struct dsa_switch *ds) { struct dsa_devlink_priv *dl_priv; - struct device_node *dn; + struct fwnode_handle *fwnode; struct dsa_port *dp; int err; @@ -909,10 +909,10 @@ static int dsa_switch_setup(struct dsa_switch *ds) dsa_slave_mii_bus_init(ds); - dn = of_get_child_by_name(ds->dev->of_node, "mdio"); + fwnode = fwnode_get_named_child_node(ds->dev->fwnode, "mdio"); - err = of_mdiobus_register(ds->slave_mii_bus, dn); - of_node_put(dn); + err = of_mdiobus_register(ds->slave_mii_bus, to_of_node(fwnode)); + fwnode_handle_put(fwnode); if (err < 0) goto free_slave_mii_bus; } @@ -1482,24 +1482,34 @@ static int dsa_port_parse_cpu(struct dsa_port *dp, struct net_device *master, return 0; } -static int dsa_port_parse_of(struct dsa_port *dp, struct device_node *dn) +static int dsa_port_parse_of(struct dsa_port *dp, struct fwnode_handle *fwnode) { - struct device_node *ethernet = of_parse_phandle(dn, "ethernet", 0); - const char *name = of_get_property(dn, "label", NULL); - bool link = of_property_read_bool(dn, "link"); + struct fwnode_handle *ethernet = fwnode_find_reference(fwnode, "ethernet", 0); + bool link = fwnode_property_present(fwnode, "link"); + const char *name; + int ret; + + ret = fwnode_property_read_string(fwnode, "label", &name); + if (ret) + return ret; - dp->dn = dn; + dp->fwnode = fwnode; + dp->dn = to_of_node(fwnode); - if (ethernet) { + if (!IS_ERR(ethernet)) { struct net_device *master; const char *user_protocol; - master = of_find_net_device_by_node(ethernet); - of_node_put(ethernet); + master = of_find_net_device_by_node(to_of_node(ethernet)); + fwnode_handle_put(ethernet); if (!master) return -EPROBE_DEFER; - user_protocol = of_get_property(dn, "dsa-tag-protocol", NULL); + ret = fwnode_property_read_string(fwnode, "dsa-tag-protocol", + &user_protocol); + if (ret) + user_protocol = NULL; + return dsa_port_parse_cpu(dp, master, user_protocol); } @@ -1510,34 +1520,34 @@ static int dsa_port_parse_of(struct dsa_port *dp, struct device_node *dn) } static int dsa_switch_parse_ports_of(struct dsa_switch *ds, - struct device_node *dn) + struct fwnode_handle *fwnode) { - struct device_node *ports, *port; + struct fwnode_handle *ports, *port; struct dsa_port *dp; int err = 0; u32 reg; - ports = of_get_child_by_name(dn, "ports"); + ports = fwnode_get_named_child_node(fwnode, "ports"); if (!ports) { /* The second possibility is "ethernet-ports" */ - ports = of_get_child_by_name(dn, "ethernet-ports"); + ports = fwnode_get_named_child_node(fwnode, "ethernet-ports"); if (!ports) { dev_err(ds->dev, "no ports child node found\n"); return -EINVAL; } } - for_each_available_child_of_node(ports, port) { - err = of_property_read_u32(port, "reg", ®); + fwnode_for_each_available_child_node(ports, port) { + err = fwnode_property_read_u32(port, "reg", ®); if (err) { - of_node_put(port); + fwnode_handle_put(port); goto out_put_node; } if (reg >= ds->num_ports) { dev_err(ds->dev, "port %pOF index %u exceeds num_ports (%u)\n", port, reg, ds->num_ports); - of_node_put(port); + fwnode_handle_put(port); err = -EINVAL; goto out_put_node; } @@ -1546,24 +1556,24 @@ static int dsa_switch_parse_ports_of(struct dsa_switch *ds, err = dsa_port_parse_of(dp, port); if (err) { - of_node_put(port); + fwnode_handle_put(port); goto out_put_node; } } out_put_node: - of_node_put(ports); + fwnode_handle_put(ports); return err; } static int dsa_switch_parse_member_of(struct dsa_switch *ds, - struct device_node *dn) + struct fwnode_handle *fwnode) { u32 m[2] = { 0, 0 }; int sz; /* Don't error out if this optional property isn't found */ - sz = of_property_read_variable_u32_array(dn, "dsa,member", m, 2, 2); + sz = fwnode_property_read_u32_array(fwnode, "dsa,member", m, 2); if (sz < 0 && sz != -EINVAL) return sz; @@ -1600,11 +1610,11 @@ static int dsa_switch_touch_ports(struct dsa_switch *ds) return 0; } -static int dsa_switch_parse_of(struct dsa_switch *ds, struct device_node *dn) +static int dsa_switch_parse_of(struct dsa_switch *ds, struct fwnode_handle *fwnode) { int err; - err = dsa_switch_parse_member_of(ds, dn); + err = dsa_switch_parse_member_of(ds, fwnode); if (err) return err; @@ -1612,7 +1622,7 @@ static int dsa_switch_parse_of(struct dsa_switch *ds, struct device_node *dn) if (err) return err; - return dsa_switch_parse_ports_of(ds, dn); + return dsa_switch_parse_ports_of(ds, fwnode); } static int dsa_port_parse(struct dsa_port *dp, const char *name, @@ -1705,20 +1715,20 @@ static int dsa_switch_probe(struct dsa_switch *ds) { struct dsa_switch_tree *dst; struct dsa_chip_data *pdata; - struct device_node *np; + struct fwnode_handle *fwnode; int err; if (!ds->dev) return -ENODEV; pdata = ds->dev->platform_data; - np = ds->dev->of_node; + fwnode = ds->dev->fwnode; if (!ds->num_ports) return -EINVAL; - if (np) { - err = dsa_switch_parse_of(ds, np); + if (fwnode) { + err = dsa_switch_parse_of(ds, fwnode); if (err) dsa_switch_release_ports(ds); } else if (pdata) { diff --git a/net/dsa/port.c b/net/dsa/port.c index 3738f2d40a0b..a0e46e276de0 100644 --- a/net/dsa/port.c +++ b/net/dsa/port.c @@ -6,10 +6,9 @@ * Vivien Didelot */ +#include #include #include -#include -#include #include "dsa_priv.h" @@ -1379,20 +1378,20 @@ void dsa_port_set_tag_protocol(struct dsa_port *cpu_dp, static struct phy_device *dsa_port_get_phy_device(struct dsa_port *dp) { - struct device_node *phy_dn; + struct fwnode_handle *phy_handle; struct phy_device *phydev; - phy_dn = of_parse_phandle(dp->dn, "phy-handle", 0); - if (!phy_dn) + phy_handle = fwnode_find_reference(dp->fwnode, "phy-handle", 0); + if (IS_ERR(phy_handle)) return NULL; - phydev = of_phy_find_device(phy_dn); + phydev = fwnode_phy_find_device(phy_handle); if (!phydev) { - of_node_put(phy_dn); + fwnode_handle_put(phy_handle); return ERR_PTR(-EPROBE_DEFER); } - of_node_put(phy_dn); + fwnode_handle_put(phy_handle); return phydev; } @@ -1524,11 +1523,10 @@ static const struct phylink_mac_ops dsa_port_phylink_mac_ops = { int dsa_port_phylink_create(struct dsa_port *dp) { struct dsa_switch *ds = dp->ds; - phy_interface_t mode; - int err; + int mode; - err = of_get_phy_mode(dp->dn, &mode); - if (err) + mode = fwnode_get_phy_mode(dp->fwnode); + if (mode < 0) mode = PHY_INTERFACE_MODE_NA; /* Presence of phylink_mac_link_state or phylink_mac_an_restart is @@ -1541,7 +1539,7 @@ int dsa_port_phylink_create(struct dsa_port *dp) if (ds->ops->phylink_get_caps) ds->ops->phylink_get_caps(ds, dp->index, &dp->pl_config); - dp->pl = phylink_create(&dp->pl_config, of_fwnode_handle(dp->dn), + dp->pl = phylink_create(&dp->pl_config, dp->fwnode, mode, &dsa_port_phylink_mac_ops); if (IS_ERR(dp->pl)) { pr_err("error creating PHYLINK: %ld\n", PTR_ERR(dp->pl)); @@ -1591,14 +1589,13 @@ static int dsa_port_setup_phy_of(struct dsa_port *dp, bool enable) static int dsa_port_fixed_link_register_of(struct dsa_port *dp) { - struct device_node *dn = dp->dn; struct dsa_switch *ds = dp->ds; struct phy_device *phydev; int port = dp->index; - phy_interface_t mode; + int mode; int err; - err = of_phy_register_fixed_link(dn); + err = fwnode_phy_register_fixed_link(dp->fwnode); if (err) { dev_err(ds->dev, "failed to register the fixed PHY of port %d\n", @@ -1606,10 +1603,10 @@ static int dsa_port_fixed_link_register_of(struct dsa_port *dp) return err; } - phydev = of_phy_find_device(dn); + phydev = fwnode_phy_find_device(dp->fwnode); - err = of_get_phy_mode(dn, &mode); - if (err) + mode = fwnode_get_phy_mode(dp->fwnode); + if (mode < 0) mode = PHY_INTERFACE_MODE_NA; phydev->interface = mode; @@ -1626,7 +1623,6 @@ static int dsa_port_fixed_link_register_of(struct dsa_port *dp) static int dsa_port_phylink_register(struct dsa_port *dp) { struct dsa_switch *ds = dp->ds; - struct device_node *port_dn = dp->dn; int err; dp->pl_config.dev = ds->dev; @@ -1636,7 +1632,7 @@ static int dsa_port_phylink_register(struct dsa_port *dp) if (err) return err; - err = phylink_of_phy_connect(dp->pl, port_dn, 0); + err = phylink_fwnode_phy_connect(dp->pl, dp->fwnode, 0); if (err && err != -ENODEV) { pr_err("could not attach to PHY: %d\n", err); goto err_phy_connect; @@ -1651,27 +1647,27 @@ static int dsa_port_phylink_register(struct dsa_port *dp) int dsa_port_link_register_of(struct dsa_port *dp) { + struct fwnode_handle *phy_handle; struct dsa_switch *ds = dp->ds; - struct device_node *phy_np; int port = dp->index; if (!ds->ops->adjust_link) { - phy_np = of_parse_phandle(dp->dn, "phy-handle", 0); - if (of_phy_is_fixed_link(dp->dn) || phy_np) { + phy_handle = fwnode_find_reference(dp->fwnode, "phy-handle", 0); + if (fwnode_phy_is_fixed_link(dp->fwnode) || !IS_ERR(phy_handle)) { if (ds->ops->phylink_mac_link_down) ds->ops->phylink_mac_link_down(ds, port, MLO_AN_FIXED, PHY_INTERFACE_MODE_NA); - of_node_put(phy_np); + fwnode_handle_put(dp->fwnode); return dsa_port_phylink_register(dp); } - of_node_put(phy_np); + fwnode_handle_put(dp->fwnode); return 0; } dev_warn(ds->dev, "Using legacy PHYLIB callbacks. Please migrate to PHYLINK!\n"); - if (of_phy_is_fixed_link(dp->dn)) + if (fwnode_phy_is_fixed_link(dp->fwnode)) return dsa_port_fixed_link_register_of(dp); else return dsa_port_setup_phy_of(dp, true); @@ -1690,8 +1686,8 @@ void dsa_port_link_unregister_of(struct dsa_port *dp) return; } - if (of_phy_is_fixed_link(dp->dn)) - of_phy_deregister_fixed_link(dp->dn); + if (fwnode_phy_is_fixed_link(dp->fwnode)) + fwnode_phy_deregister_fixed_link(dp->fwnode); else dsa_port_setup_phy_of(dp, false); } diff --git a/net/dsa/slave.c b/net/dsa/slave.c index 2e1ac638d135..b801795d73a6 100644 --- a/net/dsa/slave.c +++ b/net/dsa/slave.c @@ -10,8 +10,6 @@ #include #include #include -#include -#include #include #include #include @@ -2204,7 +2202,6 @@ static int dsa_slave_phy_connect(struct net_device *slave_dev, int addr, static int dsa_slave_phy_setup(struct net_device *slave_dev) { struct dsa_port *dp = dsa_slave_to_port(slave_dev); - struct device_node *port_dn = dp->dn; struct dsa_switch *ds = dp->ds; u32 phy_flags = 0; int ret; @@ -2228,7 +2225,7 @@ static int dsa_slave_phy_setup(struct net_device *slave_dev) if (ds->ops->get_phy_flags) phy_flags = ds->ops->get_phy_flags(ds, dp->index); - ret = phylink_of_phy_connect(dp->pl, port_dn, phy_flags); + ret = phylink_fwnode_phy_connect(dp->pl, dp->fwnode, phy_flags); if (ret == -ENODEV && ds->slave_mii_bus) { /* We could not connect to a designated PHY or SFP, so try to * use the switch internal MDIO bus instead @@ -2341,6 +2338,7 @@ int dsa_slave_create(struct dsa_port *port) SET_NETDEV_DEV(slave_dev, port->ds->dev); slave_dev->dev.of_node = port->dn; + slave_dev->dev.fwnode = port->fwnode; slave_dev->vlan_features = master->vlan_features; p = netdev_priv(slave_dev); From patchwork Mon Jun 20 15:02:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcin Wojtas X-Patchwork-Id: 583309 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C37DDC433EF for ; Mon, 20 Jun 2022 15:12:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241896AbiFTPMd (ORCPT ); Mon, 20 Jun 2022 11:12:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242326AbiFTPML (ORCPT ); Mon, 20 Jun 2022 11:12:11 -0400 Received: from mail-lj1-x235.google.com (mail-lj1-x235.google.com [IPv6:2a00:1450:4864:20::235]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3707FE9A for ; Mon, 20 Jun 2022 08:02:52 -0700 (PDT) Received: by mail-lj1-x235.google.com with SMTP id n15so605604ljg.8 for ; Mon, 20 Jun 2022 08:02:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=b2AKescmGlKNcLJ4HDilF0tkENV4Ss4sdm70D7RL07I=; b=rC8BmvECl/r/bwfRj5gY7fodnhLqkpD4/oDWpi9b3OqcVG5ZUJBUxXg0eHvaiSIWpc IT0YD2Adcjo4ZMc0x840TpCxLky45HTQiPIqUJydervFxSXgtIcppzWfcZJkhi72SNWK ouR22ZiEzbdEvSDFvDiye0JCgRhLdiHKKGP+ntSIGgjXXI4ldbxIpPo4P9c8iwDSBepI 6pqwl4764R9eFoPbY170VW85np3DEMUShyv2BXRJ+7aUB/zHKPp5vSfT2bxjQzx95L3L xAeDffMP12clZd831cesX422+qx0HE/HsovbR9uhU4jPNhwKdQnrj9nw58DePoQtc9rR NbBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=b2AKescmGlKNcLJ4HDilF0tkENV4Ss4sdm70D7RL07I=; b=cMFeiTr+eMVSafFPd7Zt3/ZlW0/s+8hR6Yv4u8fIEUU4Vm6PSfycCmUbIdCVZxyBmr 38qG1lMntG5Syu1wAy/rv2bst/PFX5gqbs27urUM4zSmIBJiMiTkP7XF9jozcS4emhZr 5m8Mf2V6rnRy3G4L9TRXWACkotF2YDIfmTHJ5k8t8jdkIHpPMmyWYSfi+egomjISKjG8 V6nbYwnONSN3yfUuM6ARa0jak9LkGEpWPgVB2Nq0tzUjbxdw5OQckgqXG6znwz1KGxN9 21XnsUvzRKLKhXqvExW7w8uF2Eawk3lbB0lzrBQVxkz5Lw0kctUBOj/yLoZzhtawrpuO dttQ== X-Gm-Message-State: AJIora8bJPDQHwYrQ3e+eosGMmcQrH3qbnxtOTzyEuKAlnL0vJiZpZmE +aDldXH+xOLuDt+Mj9m33gR+MA== X-Google-Smtp-Source: AGRyM1vbXLtUNjH0AC77POL9h5Lp/wi5D1FylX8FlzNfPcENyyC4zuvZ6/whXb8+g5bZ5gWNdMZBTw== X-Received: by 2002:a05:651c:1502:b0:255:b837:a27a with SMTP id e2-20020a05651c150200b00255b837a27amr11499984ljf.284.1655737369056; Mon, 20 Jun 2022 08:02:49 -0700 (PDT) Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id e19-20020a05651236d300b0047f79f7758asm17564lfs.22.2022.06.20.08.02.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jun 2022 08:02:48 -0700 (PDT) From: Marcin Wojtas To: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, netdev@vger.kernel.org Cc: rafael@kernel.org, andriy.shevchenko@linux.intel.com, lenb@kernel.org, andrew@lunn.ch, vivien.didelot@gmail.com, f.fainelli@gmail.com, olteanv@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux@armlinux.org.uk, hkallweit1@gmail.com, gjb@semihalf.com, mw@semihalf.com, jaz@semihalf.com, tn@semihalf.com, Samer.El-Haj-Mahmoud@arm.com, upstream@semihalf.com Subject: [net-next: PATCH 04/12] net: mvpp2: initialize port fwnode pointer Date: Mon, 20 Jun 2022 17:02:17 +0200 Message-Id: <20220620150225.1307946-5-mw@semihalf.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20220620150225.1307946-1-mw@semihalf.com> References: <20220620150225.1307946-1-mw@semihalf.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org As a preparation to switch the DSA subsystem from using of_find_net_device_by_node() to its more generic fwnode_ equivalent, the port's device structure should be updated with its fwnode pointer, similarly to of_node - see analogous commit c4053ef32208 ("net: mvpp2: initialize port of_node pointer"). This patch is required to prevent a regression before updating the DSA API on boards that connect the mvpp2 port to switch, such as Clearfog GT-8K or CN913x CEx7 Evaluation Board. Signed-off-by: Marcin Wojtas --- drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c index b84128b549b4..cd2f113bb1a4 100644 --- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c @@ -6869,6 +6869,7 @@ static int mvpp2_port_probe(struct platform_device *pdev, /* 9704 == 9728 - 20 and rounding to 8 */ dev->max_mtu = MVPP2_BM_JUMBO_PKT_SIZE; dev->dev.of_node = port_node; + dev->dev.fwnode = port_fwnode; port->pcs_gmac.ops = &mvpp2_phylink_gmac_pcs_ops; port->pcs_xlg.ops = &mvpp2_phylink_xlg_pcs_ops; From patchwork Mon Jun 20 15:02:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcin Wojtas X-Patchwork-Id: 583650 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C5854CCA47C for ; Mon, 20 Jun 2022 15:12:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241371AbiFTPMZ (ORCPT ); Mon, 20 Jun 2022 11:12:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243015AbiFTPMJ (ORCPT ); Mon, 20 Jun 2022 11:12:09 -0400 Received: from mail-lj1-x230.google.com (mail-lj1-x230.google.com [IPv6:2a00:1450:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFB86B9E for ; Mon, 20 Jun 2022 08:02:50 -0700 (PDT) Received: by mail-lj1-x230.google.com with SMTP id w9so3199809lji.4 for ; Mon, 20 Jun 2022 08:02:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=t4fm7chK+9HP+V4kfjA7VXym1QH3FPQZTxUsVRysYlI=; b=GC02YJZFg88R2E6b7Wy1WLcpX7Ar2kvhBGaz/xonS8B5DjkgBc2uwF6qOcPbPkBIE/ 6bpk0yfhSgNWi0ygLzCSnaJ7KOh7HuFYVvqdVbQwX709iQGr3ro2PElbJC54njuEgtCu i2tupv/SHrxy3o9t875X8LbtPxLNGfUJqy+/ff9966/cFdEJcXB2F9v+M/mfH+exNX3N mRPMTu1qSpRGj8giJ9pmfaoSugiOKJw6BDvp/9XU5DF/uGpxrNtmrmaFr1c7kzxAxN4e davPWJ20AqSd9nu1kiPF/smDxl4EwtiozhanuxLeF9Gu4RLy7p6ta4DePU//03kyur8v nGGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=t4fm7chK+9HP+V4kfjA7VXym1QH3FPQZTxUsVRysYlI=; b=Ix4Z/JOLOBY/ddJU+95dIQ83q+GHPJz2Gf46FmZOSiXitjH7Kam3mBBZer7b6FIH8B gavDLKOlpoYMYqfK34uKPlHrBVjTKPFhpUHy29HKMNN2BOW72lwtDGLA4/Rq4VbtYWa5 f9VmGDzE5OIEjaudGkW80WlQzWKmWe5w8eylkLA7XwXE8Xtsnr30mm2WU6V4f/NMzHpZ Xob6+CzQ8zXq0qa7wBGT9IBjxr4XdMp3iMr0vx1FsUActhxs0KnG1/DPB5FnfNuojtXx Vakp8L9hXQfIq+Q4t/xnRK1M+2fEkOEbWrdLy/zTg2mE39/jgeLIJD/Rlgg+j7fc2AIK fOQw== X-Gm-Message-State: AJIora8kXBlpTt3Na7rtJ1VDWElJHme2KzcNCY53A46uy5jeNy24Agn9 6O7LzZsc1vKe2IygphNG68w7aA== X-Google-Smtp-Source: AGRyM1uYOZ02rYHZJgaSORea5LGhaa+Fo4kElEGhfJGAzyML5aZG9cH/D2CN0E16ZUk+OzgFKnWGqg== X-Received: by 2002:a05:651c:244:b0:255:32c8:dd42 with SMTP id x4-20020a05651c024400b0025532c8dd42mr11790566ljn.101.1655737370158; Mon, 20 Jun 2022 08:02:50 -0700 (PDT) Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id e19-20020a05651236d300b0047f79f7758asm17564lfs.22.2022.06.20.08.02.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jun 2022 08:02:49 -0700 (PDT) From: Marcin Wojtas To: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, netdev@vger.kernel.org Cc: rafael@kernel.org, andriy.shevchenko@linux.intel.com, lenb@kernel.org, andrew@lunn.ch, vivien.didelot@gmail.com, f.fainelli@gmail.com, olteanv@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux@armlinux.org.uk, hkallweit1@gmail.com, gjb@semihalf.com, mw@semihalf.com, jaz@semihalf.com, tn@semihalf.com, Samer.El-Haj-Mahmoud@arm.com, upstream@semihalf.com Subject: [net-next: PATCH 05/12] net: core: switch to fwnode_find_net_device_by_node() Date: Mon, 20 Jun 2022 17:02:18 +0200 Message-Id: <20220620150225.1307946-6-mw@semihalf.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20220620150225.1307946-1-mw@semihalf.com> References: <20220620150225.1307946-1-mw@semihalf.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org A helper function which allows getting the struct net_device pointer associated with a given device tree node can be more generic and also support alternative hardware description. Switch to fwnode_ and update the only existing caller in DSA subsystem. Signed-off-by: Marcin Wojtas --- include/linux/etherdevice.h | 1 + include/linux/of_net.h | 6 ------ net/core/net-sysfs.c | 18 ++++++++---------- net/dsa/dsa2.c | 3 ++- 4 files changed, 11 insertions(+), 17 deletions(-) diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h index 92b10e67d5f8..a335775af244 100644 --- a/include/linux/etherdevice.h +++ b/include/linux/etherdevice.h @@ -35,6 +35,7 @@ int nvmem_get_mac_address(struct device *dev, void *addrbuf); int device_get_mac_address(struct device *dev, char *addr); int device_get_ethdev_address(struct device *dev, struct net_device *netdev); int fwnode_get_mac_address(struct fwnode_handle *fwnode, char *addr); +struct net_device *fwnode_find_net_device_by_node(struct fwnode_handle *fwnode); u32 eth_get_headlen(const struct net_device *dev, const void *data, u32 len); __be16 eth_type_trans(struct sk_buff *skb, struct net_device *dev); diff --git a/include/linux/of_net.h b/include/linux/of_net.h index 0484b613ca64..f672f831292d 100644 --- a/include/linux/of_net.h +++ b/include/linux/of_net.h @@ -15,7 +15,6 @@ struct net_device; extern int of_get_phy_mode(struct device_node *np, phy_interface_t *interface); extern int of_get_mac_address(struct device_node *np, u8 *mac); int of_get_ethdev_address(struct device_node *np, struct net_device *dev); -extern struct net_device *of_find_net_device_by_node(struct device_node *np); #else static inline int of_get_phy_mode(struct device_node *np, phy_interface_t *interface) @@ -32,11 +31,6 @@ static inline int of_get_ethdev_address(struct device_node *np, struct net_devic { return -ENODEV; } - -static inline struct net_device *of_find_net_device_by_node(struct device_node *np) -{ - return NULL; -} #endif #endif /* __LINUX_OF_NET_H */ diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index d49fc974e630..837f67f1f3a4 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -1934,11 +1935,10 @@ static struct class net_class __ro_after_init = { .get_ownership = net_get_ownership, }; -#ifdef CONFIG_OF -static int of_dev_node_match(struct device *dev, const void *data) +static int fwnode_dev_node_match(struct device *dev, const void *data) { for (; dev; dev = dev->parent) { - if (dev->of_node == data) + if (dev->fwnode == data) return 1; } @@ -1946,26 +1946,24 @@ static int of_dev_node_match(struct device *dev, const void *data) } /* - * of_find_net_device_by_node - lookup the net device for the device node - * @np: OF device node + * fwnode_find_net_device_by_node - lookup the net device for the device node + * @fwnode: firmware node * - * Looks up the net_device structure corresponding with the device node. + * Looks up the net_device structure corresponding with the fwnode. * If successful, returns a pointer to the net_device with the embedded * struct device refcount incremented by one, or NULL on failure. The * refcount must be dropped when done with the net_device. */ -struct net_device *of_find_net_device_by_node(struct device_node *np) +struct net_device *fwnode_find_net_device_by_node(struct fwnode_handle *fwnode) { struct device *dev; - dev = class_find_device(&net_class, NULL, np, of_dev_node_match); + dev = class_find_device(&net_class, NULL, fwnode, fwnode_dev_node_match); if (!dev) return NULL; return to_net_dev(dev); } -EXPORT_SYMBOL(of_find_net_device_by_node); -#endif /* Delete sysfs entries but hold kobject reference until after all * netdev references are gone. diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c index 039022bf914b..5e11d66f9057 100644 --- a/net/dsa/dsa2.c +++ b/net/dsa/dsa2.c @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -1500,7 +1501,7 @@ static int dsa_port_parse_of(struct dsa_port *dp, struct fwnode_handle *fwnode) struct net_device *master; const char *user_protocol; - master = of_find_net_device_by_node(to_of_node(ethernet)); + master = fwnode_find_net_device_by_node(ethernet); fwnode_handle_put(ethernet); if (!master) return -EPROBE_DEFER; From patchwork Mon Jun 20 15:02:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcin Wojtas X-Patchwork-Id: 583308 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 14B3BCCA47C for ; Mon, 20 Jun 2022 15:12:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242656AbiFTPMk (ORCPT ); Mon, 20 Jun 2022 11:12:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243321AbiFTPMO (ORCPT ); Mon, 20 Jun 2022 11:12:14 -0400 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88F586140 for ; Mon, 20 Jun 2022 08:02:54 -0700 (PDT) Received: by mail-lj1-x229.google.com with SMTP id s10so12206501ljh.12 for ; Mon, 20 Jun 2022 08:02:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/EdxkH4fP0zqJATydAHLXu3mRsR+HclXmov1NWv6EHk=; b=SRAAsjAAJry/wEZv46Yv2kZoDW6yLFk+/MU0hcz/UFP8Xv4zTtmkJ4vcKqMOe9yXji 3DETO2Omf28vecJPHHw/Fr7623f1Locm4Yw//wT56jHgEG1NcFFnR9D5Ukgdu5hSrcF1 HBGPUoI/6Em9j22nofiO/Go+lz9k+aoHoN5UrWqkq0V79MEgQb56au1V2Si2LLyV8GqP +T65+SizTW9QOpqwb4acq7XAEBBFM3v5lOtfNsKJpZT/2g7lsYpxvPQeA0vB4zEels7B 8QkdtjzAZFlcIHIged0Ox9FX6X3p8cAKagYQwlHChZm9zqAENVkalOXwjY2IsWZxuzUv btWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/EdxkH4fP0zqJATydAHLXu3mRsR+HclXmov1NWv6EHk=; b=r09GYnb7Q3uxcupd8XhOu5wS4CesSVzcuvd3aV2T0BNbzLICsxX9/vF4StyxkQqJj+ ImpLuu/JjjZViGHNq7jddTnvKPpvqrsE2mTOb8o1dtuGigmQUulCKrwPW3VwjiBoCU83 h89qcO8S4eEUUNJD0YUnXhhm6p+RzpaVvjA0rXPViFX10Rc2EUSPNJoEBhz7CDsyGUA9 L5TqaDPCRoniOoXnB4IZsIZ2BslKVcskg2ZeEidShHxYmw5mGscSxOAWeemCyeWiUBT3 sPytWMW18ozMuQSxEUWR3ffS0l8+63ANICrmpptH4vUAjYQ1NJcibNp7aRgcgWotm63L wryw== X-Gm-Message-State: AJIora+NtJw17MGziDnLt+TojRPxwY4eBo2948RT1TJJElqUqC4IdGmB dta9tFbtnHoJ4SrZH3M8Ojq3yA== X-Google-Smtp-Source: AGRyM1ucPSh7wwP+2gyt89hjNQtLW/miFV9yXLuoSMYVAKWa4WBZ9gQ6SIX8q98ZpaQMBfD8re+kqg== X-Received: by 2002:a2e:a268:0:b0:255:9eaf:3422 with SMTP id k8-20020a2ea268000000b002559eaf3422mr11448243ljm.461.1655737371334; Mon, 20 Jun 2022 08:02:51 -0700 (PDT) Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id e19-20020a05651236d300b0047f79f7758asm17564lfs.22.2022.06.20.08.02.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jun 2022 08:02:50 -0700 (PDT) From: Marcin Wojtas To: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, netdev@vger.kernel.org Cc: rafael@kernel.org, andriy.shevchenko@linux.intel.com, lenb@kernel.org, andrew@lunn.ch, vivien.didelot@gmail.com, f.fainelli@gmail.com, olteanv@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux@armlinux.org.uk, hkallweit1@gmail.com, gjb@semihalf.com, mw@semihalf.com, jaz@semihalf.com, tn@semihalf.com, Samer.El-Haj-Mahmoud@arm.com, upstream@semihalf.com Subject: [net-next: PATCH 06/12] net: mdio: introduce fwnode_mdiobus_register_device() Date: Mon, 20 Jun 2022 17:02:19 +0200 Message-Id: <20220620150225.1307946-7-mw@semihalf.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20220620150225.1307946-1-mw@semihalf.com> References: <20220620150225.1307946-1-mw@semihalf.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org As a preparation patch to extend MDIO capabilities in the ACPI world, introduce fwnode_mdiobus_register_device() to register non-PHY devices on the mdiobus. While at it, also use the newly introduced fwnode operation in of_mdiobus_phy_device_register(). Signed-off-by: Marcin Wojtas --- include/linux/fwnode_mdio.h | 3 ++ drivers/net/mdio/fwnode_mdio.c | 29 ++++++++++++++++++++ drivers/net/mdio/of_mdio.c | 26 +----------------- 3 files changed, 33 insertions(+), 25 deletions(-) diff --git a/include/linux/fwnode_mdio.h b/include/linux/fwnode_mdio.h index 98755b8c6c8a..39d74c5d1bb0 100644 --- a/include/linux/fwnode_mdio.h +++ b/include/linux/fwnode_mdio.h @@ -16,6 +16,9 @@ int fwnode_mdiobus_phy_device_register(struct mii_bus *mdio, int fwnode_mdiobus_register_phy(struct mii_bus *bus, struct fwnode_handle *child, u32 addr); +int fwnode_mdiobus_register_device(struct mii_bus *mdio, + struct fwnode_handle *child, u32 addr); + int fwnode_phy_register_fixed_link(struct fwnode_handle *fwnode); void fwnode_phy_deregister_fixed_link(struct fwnode_handle *fwnode); diff --git a/drivers/net/mdio/fwnode_mdio.c b/drivers/net/mdio/fwnode_mdio.c index b1c20c48b6cb..97abfaf88030 100644 --- a/drivers/net/mdio/fwnode_mdio.c +++ b/drivers/net/mdio/fwnode_mdio.c @@ -149,6 +149,35 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus, } EXPORT_SYMBOL(fwnode_mdiobus_register_phy); +int fwnode_mdiobus_register_device(struct mii_bus *mdio, + struct fwnode_handle *child, u32 addr) +{ + struct mdio_device *mdiodev; + int rc; + + mdiodev = mdio_device_create(mdio, addr); + if (IS_ERR(mdiodev)) + return PTR_ERR(mdiodev); + + /* Associate the fwnode with the device structure so it + * can be looked up later. + */ + device_set_node(&mdiodev->dev, child); + + /* All data is now stored in the mdiodev struct; register it. */ + rc = mdio_device_register(mdiodev); + if (rc) { + mdio_device_free(mdiodev); + fwnode_handle_put(child); + return rc; + } + + dev_dbg(&mdio->dev, "registered mdio device %p fwnode at address %i\n", + child, addr); + return 0; +} +EXPORT_SYMBOL(fwnode_mdiobus_register_device); + /* * fwnode_phy_is_fixed_link() and fwnode_phy_register_fixed_link() must * support two bindings: diff --git a/drivers/net/mdio/of_mdio.c b/drivers/net/mdio/of_mdio.c index 409da6e92f7d..522dbee419fe 100644 --- a/drivers/net/mdio/of_mdio.c +++ b/drivers/net/mdio/of_mdio.c @@ -51,31 +51,7 @@ static int of_mdiobus_register_phy(struct mii_bus *mdio, static int of_mdiobus_register_device(struct mii_bus *mdio, struct device_node *child, u32 addr) { - struct fwnode_handle *fwnode = of_fwnode_handle(child); - struct mdio_device *mdiodev; - int rc; - - mdiodev = mdio_device_create(mdio, addr); - if (IS_ERR(mdiodev)) - return PTR_ERR(mdiodev); - - /* Associate the OF node with the device structure so it - * can be looked up later. - */ - fwnode_handle_get(fwnode); - device_set_node(&mdiodev->dev, fwnode); - - /* All data is now stored in the mdiodev struct; register it. */ - rc = mdio_device_register(mdiodev); - if (rc) { - mdio_device_free(mdiodev); - of_node_put(child); - return rc; - } - - dev_dbg(&mdio->dev, "registered mdio device %pOFn at address %i\n", - child, addr); - return 0; + return fwnode_mdiobus_register_device(mdio, of_fwnode_handle(child), addr); } /* The following is a list of PHY compatible strings which appear in From patchwork Mon Jun 20 15:02:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcin Wojtas X-Patchwork-Id: 583648 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B0FFC433EF for ; Mon, 20 Jun 2022 15:13:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243675AbiFTPM5 (ORCPT ); Mon, 20 Jun 2022 11:12:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243302AbiFTPMO (ORCPT ); Mon, 20 Jun 2022 11:12:14 -0400 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2B116249 for ; Mon, 20 Jun 2022 08:02:54 -0700 (PDT) Received: by mail-lf1-x134.google.com with SMTP id i18so4061127lfu.8 for ; Mon, 20 Jun 2022 08:02:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7RYmX6hwDcKGiQHQEayVLNO5diQlCW4Y4Deqwz4h8T8=; b=J7f4T8YnKHMS90UGD6gxXSuB7x2Hg6/2jTVv/VoOmma8k9lrBsmRLZDs8GHCK0fOcV BfFrqQlgSLL+Hur5zSzTBp6invCr+HxiGZaurvWwoK5F2vdD/LaRMryeUG1J0nWVAwaI ayTBVBxeU+mi5xMt73C8Z5w5Ou16ed5i/fx0KKQA1bPV5gsiMrQvsH3/D0a7QF0jJqrn WwyN8zKdC6FGDZN/rEUxI4jp+/KsTZCOOS9ajE5p1A/E47CRd35v+Fb8m/GgZGPeiT3h ZrQEcRXcFHkV+2S+f860tEg+zRuu/zxdVoGHNsbBMRHwmdwXW7UU9W+437UcF/GKLUn5 v8TA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7RYmX6hwDcKGiQHQEayVLNO5diQlCW4Y4Deqwz4h8T8=; b=vjmbdnJHOwFL5/+jjfcBUlEL2sGcPbdOiDiVXrzrhnzY3jl3W+sAjxZRSuCdn7/5kz ZS7b3Z8U6HjwuEIazHIJHspBb4XgOmT48oyjdnrIhqcwAAV+xhsTVllSRrogoxm2g4yZ FnnyPnIiVyjhvnErd7mj2RFxt2p8GXJO/TfroKjjh2dsk4iETVLYsd0JMxezTKdDWZle g7r7Sb17qXf+YL4xY7XvIEbNI6MHTYIfYbDgkmq0Y+jzhWqof6daj1DviJFtlAOaAemL 5wiev9CC2DU4ICOK86Ifg3SX1a6xWO3gXgtxy5VhdVjEjeiX8itjYg5HjoCQDIfR82gc WDsg== X-Gm-Message-State: AJIora85Lkvnt02RvnNBbQvQD8dX0zxKhg+aITRzfFCYRJj/bKWOq6Ec wrZ0XyIvGNlRsaHCCh/sIQbiAg== X-Google-Smtp-Source: AGRyM1sWO6KOjp1s3p12U7eWklYIpDeYsTWAh5PfOMGJbed42f5P8rcRGwK+1A3uhwLmCbi9uFJtjg== X-Received: by 2002:a05:6512:1684:b0:47f:5f27:b006 with SMTP id bu4-20020a056512168400b0047f5f27b006mr7010050lfb.225.1655737372485; Mon, 20 Jun 2022 08:02:52 -0700 (PDT) Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id e19-20020a05651236d300b0047f79f7758asm17564lfs.22.2022.06.20.08.02.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jun 2022 08:02:52 -0700 (PDT) From: Marcin Wojtas To: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, netdev@vger.kernel.org Cc: rafael@kernel.org, andriy.shevchenko@linux.intel.com, lenb@kernel.org, andrew@lunn.ch, vivien.didelot@gmail.com, f.fainelli@gmail.com, olteanv@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux@armlinux.org.uk, hkallweit1@gmail.com, gjb@semihalf.com, mw@semihalf.com, jaz@semihalf.com, tn@semihalf.com, Samer.El-Haj-Mahmoud@arm.com, upstream@semihalf.com Subject: [net-next: PATCH 07/12] net: mdio: allow registering non-PHY devices in ACPI world Date: Mon, 20 Jun 2022 17:02:20 +0200 Message-Id: <20220620150225.1307946-8-mw@semihalf.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20220620150225.1307946-1-mw@semihalf.com> References: <20220620150225.1307946-1-mw@semihalf.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org This patch utilizes the newly added fwnode_mdiobus_register_device function and enables registration of non-PHY MDIO devices. For that purpose a helper routine is added, allowing to determine, whether the device associated to ACPI node is a PHY. In addition to that update, allow matching child devices' drivers based on their ACPI ID. Signed-off-by: Marcin Wojtas --- drivers/net/mdio/acpi_mdio.c | 40 +++++++++++++++++++- drivers/net/phy/mdio_bus.c | 4 ++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/drivers/net/mdio/acpi_mdio.c b/drivers/net/mdio/acpi_mdio.c index d77c987fda9c..b5d7404afc5e 100644 --- a/drivers/net/mdio/acpi_mdio.c +++ b/drivers/net/mdio/acpi_mdio.c @@ -17,6 +17,41 @@ MODULE_AUTHOR("Calvin Johnson "); MODULE_LICENSE("GPL"); +/** + * acpi_mdiobus_child_is_phy - check if device associated with fwnode is a PHY. + * @fwnode: pointer to MDIO bus child fwnode and is expected to represent ACPI + * device object. + * + * The function returns true if the child node is for a PHY. + * It must comprise either: + * o Compatible string of "ethernet-phy-idX.X" + * o Compatible string of "ethernet-phy-ieee802.3-c45" + * o Compatible string of "ethernet-phy-ieee802.3-c22" + * o No _HID or _CID fields. + */ +static bool acpi_mdiobus_child_is_phy(struct fwnode_handle *child) +{ + struct acpi_device *adev = to_acpi_device_node(child); + u32 phy_id; + + if (fwnode_get_phy_id(child, &phy_id) != -EINVAL) + return true; + + if (fwnode_property_match_string(child, "compatible", + "ethernet-phy-ieee802.3-c45") == 0) + return true; + + if (fwnode_property_match_string(child, "compatible", + "ethernet-phy-ieee802.3-c22") == 0) + return true; + + /* Default to PHY if no _HID or _CID found in the fwnode. */ + if (list_empty(&adev->pnp.ids)) + return true; + + return false; +} + /** * acpi_mdiobus_register - Register mii_bus and create PHYs from the ACPI ASL. * @mdio: pointer to mii_bus structure @@ -47,7 +82,10 @@ int acpi_mdiobus_register(struct mii_bus *mdio, struct fwnode_handle *fwnode) if (ret || addr >= PHY_MAX_ADDR) continue; - ret = fwnode_mdiobus_register_phy(mdio, child, addr); + if (acpi_mdiobus_child_is_phy(child)) + ret = fwnode_mdiobus_register_phy(mdio, child, addr); + else + ret = fwnode_mdiobus_register_device(mdio, child, addr); if (ret == -ENODEV) dev_err(&mdio->dev, "MDIO device at address %d is missing.\n", diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c index 8a2dbe849866..b3c2f966be4b 100644 --- a/drivers/net/phy/mdio_bus.c +++ b/drivers/net/phy/mdio_bus.c @@ -8,6 +8,7 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt +#include #include #include #include @@ -989,6 +990,9 @@ static int mdio_bus_match(struct device *dev, struct device_driver *drv) if (of_driver_match_device(dev, drv)) return 1; + if (acpi_driver_match_device(dev, drv)) + return 1; + if (mdio->bus_match) return mdio->bus_match(dev, drv); From patchwork Mon Jun 20 15:02:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcin Wojtas X-Patchwork-Id: 583649 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E21BBC433EF for ; Mon, 20 Jun 2022 15:12:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240247AbiFTPMj (ORCPT ); Mon, 20 Jun 2022 11:12:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243277AbiFTPMO (ORCPT ); Mon, 20 Jun 2022 11:12:14 -0400 Received: from mail-lj1-x236.google.com (mail-lj1-x236.google.com [IPv6:2a00:1450:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 725D32DFD for ; Mon, 20 Jun 2022 08:02:54 -0700 (PDT) Received: by mail-lj1-x236.google.com with SMTP id a11so3446818ljb.5 for ; Mon, 20 Jun 2022 08:02:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RDW0iKUe4rl0AxxyRpSUfzqnbvrj0hO4TPTr9mwh6kI=; b=FEg3yuw9zuj0apotExwlLW1q5suVP6iGt/1G6WRjuwHmcCvuxI1Tsf0SZ2F8Cn+q2t mx4RPLR22FvnM7Q+zZurckshwY6mIap7dqn2mGeElD5DaJdpjkZT/WFzsUjq7GGitpBT YB3asvifr/wTkfhr0F6EFymDcrS9lx+famqRA53ZoPQJDNrECye82zNCvZ/ifwz2S+uV 1Z8u/fhSkEBWPMruUTO5XOWnFFrcYbR6EaVbuu8zAPTJdP/2CxT8AiliZoFLiBoCuWDG 0It84USVCUeZopmhbdIUswnZvu25VRiydCuJ2tNC1BfVu1ScHheK7q3/OsO65eqXy8h2 MEpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RDW0iKUe4rl0AxxyRpSUfzqnbvrj0hO4TPTr9mwh6kI=; b=nmi4uJiwJJrOnnapubwDwUHhWNRMc8JSloCH8aoyvfvQ2zRUbrFFEXhhJ74H52ti8Q BjXl1RsxD9nSq9I+uDvIK3IYqyUnQ5c9r4VMN5vj3iniUVN25WHl03qhm+1UP4ntMtp5 56Q3CRZKN4hhg9rDAETRlrmgjtGOI5eLPalw3KsUNnuM9sE6pUlw1T3+WpbjhtLcSFij I1Xr8bCEuwux7c5RoeeEdoDdp+QIGgYlXf5zLNFhLtYzSb3fwvHj2zMVSEBDiV4vMa54 1EdUXQaN1StmfXyY0V81ntCAYOAunn94gAgyxegRfLijjWHSzNDxynYgqE0s7bTCAp88 rVXg== X-Gm-Message-State: AJIora9GYJfkU9hSOmyJ0B0LduOneE9Xc72Yt44iR8FrGY4v2uDwShDN 2oz3QgBCzZacruPgukY8IgeEsA== X-Google-Smtp-Source: AGRyM1tbm7QFG8lIJaukpRbduMFt0tpvrn9FXfCi0u/0W1N99p3BoT6LfGzkkKNb1ZzphlH4rxS4ug== X-Received: by 2002:a2e:b0ce:0:b0:25a:6ad3:1ee7 with SMTP id g14-20020a2eb0ce000000b0025a6ad31ee7mr3842974ljl.1.1655737373671; Mon, 20 Jun 2022 08:02:53 -0700 (PDT) Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id e19-20020a05651236d300b0047f79f7758asm17564lfs.22.2022.06.20.08.02.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jun 2022 08:02:53 -0700 (PDT) From: Marcin Wojtas To: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, netdev@vger.kernel.org Cc: rafael@kernel.org, andriy.shevchenko@linux.intel.com, lenb@kernel.org, andrew@lunn.ch, vivien.didelot@gmail.com, f.fainelli@gmail.com, olteanv@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux@armlinux.org.uk, hkallweit1@gmail.com, gjb@semihalf.com, mw@semihalf.com, jaz@semihalf.com, tn@semihalf.com, Samer.El-Haj-Mahmoud@arm.com, upstream@semihalf.com Subject: [net-next: PATCH 08/12] ACPI: scan: prevent double enumeration of MDIO bus children Date: Mon, 20 Jun 2022 17:02:21 +0200 Message-Id: <20220620150225.1307946-9-mw@semihalf.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20220620150225.1307946-1-mw@semihalf.com> References: <20220620150225.1307946-1-mw@semihalf.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org The MDIO bus is responsible for probing and registering its respective children, such as PHYs or other kind of devices. It is required that ACPI scan code should not enumerate such devices, leaving this task for the generic MDIO bus routines, which are initiated by the controller driver. This patch prevents unwanted enumeration of the devices by setting 'enumeration_by_parent' flag, depending on whether their parent device is a member of a known list of MDIO controllers. For now, the Marvell MDIO controllers' IDs are added. Signed-off-by: Marcin Wojtas --- drivers/acpi/scan.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index 762b61f67e6c..d703c35dc218 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -1716,6 +1716,18 @@ static bool acpi_is_indirect_io_slave(struct acpi_device *device) return parent && !acpi_match_device_ids(parent, indirect_io_hosts); } +static bool acpi_is_mdio_child(struct acpi_device *device) +{ + struct acpi_device *parent = device->parent; + static const struct acpi_device_id mdio_controllers[] = { + {"MRVL0100", 0}, + {"MRVL0101", 0}, + {} + }; + + return parent && !acpi_match_device_ids(parent, mdio_controllers); +} + static bool acpi_device_enumeration_by_parent(struct acpi_device *device) { struct list_head resource_list; @@ -1756,6 +1768,9 @@ static bool acpi_device_enumeration_by_parent(struct acpi_device *device) if (acpi_is_indirect_io_slave(device)) return true; + if (acpi_is_mdio_child(device)) + return true; + /* Macs use device properties in lieu of _CRS resources */ if (x86_apple_machine && (fwnode_property_present(&device->fwnode, "spiSclkPeriod") || From patchwork Mon Jun 20 15:02:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcin Wojtas X-Patchwork-Id: 583307 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0CC3BC433EF for ; Mon, 20 Jun 2022 15:13:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243714AbiFTPNB (ORCPT ); Mon, 20 Jun 2022 11:13:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243356AbiFTPMP (ORCPT ); Mon, 20 Jun 2022 11:12:15 -0400 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA330FD1D for ; Mon, 20 Jun 2022 08:02:56 -0700 (PDT) Received: by mail-lf1-x12a.google.com with SMTP id c2so17755645lfk.0 for ; Mon, 20 Jun 2022 08:02:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lWuaSG6HSKcvFGFyg+g82A5w5pDsH3NkEfBqjUDTkfk=; b=U6ZqexpWMwtNfy4fgrFqttD04y6IMahzDMMf5MP3BVVrG8OG0j4iKbznvGKRVKIH3x EbRPXFceUxsEy2hVgGms7e9b4L9Hvh53LP5Ga76s+m097zlmDDUUg+lLVsqajUGMSDlq j4orC0Fc6GDqnK49q0OJTmQfKv4I53zdBQ11H9R/d0lZgqJ13ku6CQtkA/AWQaRq7aih VmynjT9xCgHmfPyGaXlgPPCFcghOwgX1qxNvJTHwpNqc4F+wW5MYZY969bwMwoER4bco /o/bW3mJpIPeXmDoMvjJyweDcd6Cmfk7liDWCYmF1jO+pGGbH8dD+y2wEAVPaxF1UvHF 7wpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lWuaSG6HSKcvFGFyg+g82A5w5pDsH3NkEfBqjUDTkfk=; b=R6NU5BDOTazI8G3XOCs3/7rH+V8HIi4WVJ8ymi+pjuZsP8hXhB/2Z3N9l/uD4HPZe9 /1qMQbaqbX3Gd+YKOZLUjah0t0rggLz7DhE4ytmj+MpecVvYUf3hodjKKH+WebPyDp0Z JStBBbYqUdOgEaz0fvOsuu7Wfv3pKtPqztFpPB/uleMsu3vXQcLK5fSkntW+t+icidgE yD7iJR5252mLAZ6CSTmbot98uSytH/we0rrcdX4HlT6ncADN7SuRYtJxtdA0GAOA/vIb v7ZCUZRQuAZvth8I96MOM5VcJueZVHPuQRsAPk+W5KRVCJcGdDGd5CB9UjweW6cB74uW Wv9Q== X-Gm-Message-State: AJIora9WxK/10E2fEJ89MJkARKxGUhRWPGd60xnz2XUnrK5JnyT2RTuc lvq9RZnuzOIDzvNdvVfKsTUbCg== X-Google-Smtp-Source: AGRyM1uTGnXuPfk4GfByLJogKz1YnhnU1O9BZc/Qm5s2OM28A/6t4nD5tutEGUS8JHtjHKclXDPDwg== X-Received: by 2002:a05:6512:3fa0:b0:47f:5758:1951 with SMTP id x32-20020a0565123fa000b0047f57581951mr8779287lfa.609.1655737374810; Mon, 20 Jun 2022 08:02:54 -0700 (PDT) Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id e19-20020a05651236d300b0047f79f7758asm17564lfs.22.2022.06.20.08.02.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jun 2022 08:02:54 -0700 (PDT) From: Marcin Wojtas To: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, netdev@vger.kernel.org Cc: rafael@kernel.org, andriy.shevchenko@linux.intel.com, lenb@kernel.org, andrew@lunn.ch, vivien.didelot@gmail.com, f.fainelli@gmail.com, olteanv@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux@armlinux.org.uk, hkallweit1@gmail.com, gjb@semihalf.com, mw@semihalf.com, jaz@semihalf.com, tn@semihalf.com, Samer.El-Haj-Mahmoud@arm.com, upstream@semihalf.com Subject: [net-next: PATCH 09/12] Documentation: ACPI: DSD: introduce DSA description Date: Mon, 20 Jun 2022 17:02:22 +0200 Message-Id: <20220620150225.1307946-10-mw@semihalf.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20220620150225.1307946-1-mw@semihalf.com> References: <20220620150225.1307946-1-mw@semihalf.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Describe the Distributed Switch Architecture (DSA) - compliant MDIO devices. In ACPI world they are represented as children of the MDIO busses, which are responsible for their enumeration based on the standard _ADR fields and description in _DSD objects under device properties UUID [1]. [1] http://www.uefi.org/sites/default/files/resources/_DSD-device-properties-UUID.pdf Signed-off-by: Marcin Wojtas --- Documentation/firmware-guide/acpi/dsd/dsa.rst | 359 ++++++++++++++++++++ Documentation/firmware-guide/acpi/index.rst | 1 + 2 files changed, 360 insertions(+) create mode 100644 Documentation/firmware-guide/acpi/dsd/dsa.rst diff --git a/Documentation/firmware-guide/acpi/dsd/dsa.rst b/Documentation/firmware-guide/acpi/dsd/dsa.rst new file mode 100644 index 000000000000..dba76d89f4e6 --- /dev/null +++ b/Documentation/firmware-guide/acpi/dsd/dsa.rst @@ -0,0 +1,359 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=========== +DSA in ACPI +=========== + +The **Distributed Switch Architecture (DSA)** devices on an MDIO bus [dsa] +are enumerated using fwnode_mdiobus_register_device() and later probed +by a dedicated driver based on the ACPI ID match result. + +In DSDT/SSDT the scope of switch device is extended by the front-panel +and one or more so called 'CPU' switch ports. Additionally +subsequent MDIO busses with attached PHYs can be described. + +This document presents the switch description with the required subnodes +and _DSD properties. + +These properties are defined in accordance with the "Device +Properties UUID For _DSD" [dsd-guide] document and the +daffd814-6eba-4d8c-8a91-bc9bbf4aa301 UUID must be used in the Device +Data Descriptors containing them. + +Switch device +============= + +The switch device is represented as a child node of the MDIO bus. +It must comprise the _HID (and optionally _CID) field, so to allow matching +with appropriate driver via ACPI ID. The other obligatory field is +_ADR with the device address on the MDIO bus [adr]. Below example +shows 'SWI0' switch device at address 0x4 on the 'SMI0' bus. + +.. code-block:: none + + Scope (\_SB.SMI0) + { + Name (_HID, "MRVL0100") + Name (_UID, 0x00) + Method (_STA) + { + Return (0xF) + } + Name (_CRS, ResourceTemplate () + { + Memory32Fixed (ReadWrite, + 0xf212a200, + 0x00000010, + ) + }) + Device (SWI0) + { + Name (_HID, "MRVL0120") + Name (_UID, 0x00) + Name (_ADR, 0x4) + <...> + } + } + +Switch MDIO bus +=============== + +A switch internal MDIO bus, please refer to 'MDIO bus and PHYs in ACPI' [phy] +document for more details. Its name must be set to **MDIO** for proper +enumeration by net/dsa API. + +Switch MDIO bus declaration example: +------------------------------------ + +.. code-block:: none + + Scope (\_SB.SMI0.SWI0) + { + Name (_HID, "MRVL0120") + Name (_UID, 0x00) + Name (_ADR, 0x4) + Device (MDIO) { + Name (_ADR, 0x0) + Device (S0P0) + { + Name (_ADR, 0x11) + } + Device (S0P1) + { + Name (_ADR, 0x12) + } + Device (S0P2) + { + Name (_ADR, 0x13) + } + Device (S0P3) + { + Name (_ADR, 0x14) + } + } + <...> + } + +Switch ports +============ + +The ports must be grouped under **PRTS** switch child device. They +should comprise a _ADR field with a port enumerator [adr] and +other properties in a standard _DSD object [dsa-properties]. + +label +----- +A property with a string value describing port's name in the OS. In case the +port is connected to the MAC ('CPU' port), its value should be set to "cpu". + +phy-handle +---------- +For each MAC node, a device property "phy-handle" is used to reference +the PHY that is registered on an MDIO bus. This is mandatory for +network interfaces that have PHYs connected to MAC via MDIO bus. +See [phy] for more details. + +ethernet +-------- +A property valid for the so called 'CPU' port and should comprise a reference +to the MAC object declared in the DSDT/SSDT. + +fixed-link +---------- +The 'fixed-link' is described by a data-only subnode of the +port, which is linked in the _DSD package via +hierarchical data extension (UUID dbb8e3e6-5886-4ba6-8795-1319f52a966b +in accordance with [dsd-guide] "_DSD Implementation Guide" document). +The subnode should comprise a required property ("speed") and +possibly the optional ones - complete list of parameters and +their values are specified in [ethernet-controller]. +See [phy] for more details. + +Switch ports' description example: +---------------------------------- + +.. code-block:: none + + Scope (\_SB.SMI0.SWI0) + { + Name (_HID, "MRVL0120") + Name (_UID, 0x00) + Name (_ADR, 0x4) + Device (PRTS) { + Name (_ADR, 0x0) + Device (PRT1) + { + Name (_ADR, 0x1) + Name (_DSD, Package () { + ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"), + Package () { + Package () { "label", "lan2"}, + Package () { "phy-handle", \_SB.SMI0.SWI0.MDIO.S0P0}, + } + }) + } + Device (PRT2) + { + Name (_ADR, 0x2) + Name (_DSD, Package () { + ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"), + Package () { + Package () { "label", "lan1"}, + }, + ToUUID("dbb8e3e6-5886-4ba6-8795-1319f52a966b"), + Package () { + Package () {"fixed-link", "LNK0"} + } + }) + Name (LNK0, Package(){ // Data-only subnode of port + ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"), + Package () { + Package () {"speed", 1000}, + Package () {"full-duplex", 1} + } + }) + } + Device (PRT3) + { + Name (_ADR, 0x3) + Name (_DSD, Package () { + ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"), + Package () { + Package () { "label", "lan4"}, + Package () { "phy-handle", \_SB.SMI0.SWI0.MDIO.S0P2}, + } + }) + } + Device (PRT4) + { + Name (_ADR, 0x4) + Name (_DSD, Package () { + ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"), + Package () { + Package () { "label", "lan3"}, + Package () { "phy-handle", \_SB.SMI0.SWI0.MDIO.S0P3}, + } + }) + } + Device (PRT5) + { + Name (_ADR, 0x5) + Name (_DSD, Package () { + ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"), + Package () { + Package () { "label", "cpu"}, + Package () { "ethernet", \_SB.PP20.ETH2}, + } + }) + } + } + <...> + } + +Full DSA description example +============================ + +Below example comprises MDIO bus ('SMI0') with a PHY at address 0x0 ('PHY0') +and a switch ('SWI0') at 0x4. The so called 'CPU' port ('PRT5') is connected to +the SoC's MAC (\_SB.PP20.ETH2). 'PRT2' port is configured as 1G fixed-link. + +.. code-block:: none + + Scope (\_SB.SMI0) + { + Name (_HID, "MRVL0100") + Name (_UID, 0x00) + Method (_STA) + { + Return (0xF) + } + Name (_CRS, ResourceTemplate () + { + Memory32Fixed (ReadWrite, + 0xf212a200, + 0x00000010, + ) + }) + Device (PHY0) + { + Name (_ADR, 0x0) + } + Device (SWI0) + { + Name (_HID, "MRVL0120") + Name (_UID, 0x00) + Name (_ADR, 0x4) + Device (PRTS) { + Name (_ADR, 0x0) + Device (PRT1) + { + Name (_ADR, 0x1) + Name (_DSD, Package () { + ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"), + Package () { + Package () { "label", "lan2"}, + Package () { "phy-handle", \_SB.SMI0.SWI0.MDIO.S0P0}, + } + }) + } + Device (PRT2) + { + Name (_ADR, 0x2) + Name (_DSD, Package () { + ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"), + Package () { + Package () { "label", "lan1"}, + }, + ToUUID("dbb8e3e6-5886-4ba6-8795-1319f52a966b"), + Package () { + Package () {"fixed-link", "LNK0"} + } + }) + Name (LNK0, Package(){ // Data-only subnode of port + ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"), + Package () { + Package () {"speed", 1000}, + Package () {"full-duplex", 1} + } + }) + } + Device (PRT3) + { + Name (_ADR, 0x3) + Name (_DSD, Package () { + ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"), + Package () { + Package () { "label", "lan4"}, + Package () { "phy-handle", \_SB.SMI0.SWI0.MDIO.S0P2}, + } + }) + } + Device (PRT4) + { + Name (_ADR, 0x4) + Name (_DSD, Package () { + ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"), + Package () { + Package () { "label", "lan3"}, + Package () { "phy-handle", \_SB.SMI0.SWI0.MDIO.S0P3}, + } + }) + } + Device (PRT5) + { + Name (_ADR, 0x5) + Name (_DSD, Package () { + ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"), + Package () { + Package () { "label", "cpu"}, + Package () { "ethernet", \_SB.PP20.ETH2}, + } + }) + } + } + Device (MDIO) { + Name (_ADR, 0x0) + Device (S0P0) + { + Name (_ADR, 0x11) + } + Device (S0P2) + { + Name (_ADR, 0x13) + } + Device (S0P3) + { + Name (_ADR, 0x14) + } + } + } + } + +TODO +==== + +* Add support for cascade switch connections via port's 'link' property [dsa-properties]. + +References +========== + +[adr] ACPI Specifications, Version 6.4 - Paragraph 6.1.1 _ADR Address + https://uefi.org/specs/ACPI/6.4/06_Device_Configuration/Device_Configuration.html#adr-address + +[dsa] + Documentation/networking/dsa/dsa.rst + +[dsa-properties] + Documentation/devicetree/bindings/net/dsa/dsa-port.yaml + +[dsd-guide] DSD Guide. + https://github.com/UEFI/DSD-Guide/blob/main/dsd-guide.adoc, referenced + 2022-06-20. + +[dsd-properties-rules] + Documentation/firmware-guide/acpi/DSD-properties-rules.rst + +[ethernet-controller] + Documentation/devicetree/bindings/net/ethernet-controller.yaml + +[phy] Documentation/networking/phy.rst diff --git a/Documentation/firmware-guide/acpi/index.rst b/Documentation/firmware-guide/acpi/index.rst index b6a42f4ffe03..a6ed5ba90cdd 100644 --- a/Documentation/firmware-guide/acpi/index.rst +++ b/Documentation/firmware-guide/acpi/index.rst @@ -10,6 +10,7 @@ ACPI Support namespace dsd/graph dsd/data-node-references + dsd/dsa dsd/leds dsd/phy enumeration From patchwork Mon Jun 20 15:02:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcin Wojtas X-Patchwork-Id: 583646 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A612CCA480 for ; Mon, 20 Jun 2022 15:14:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242928AbiFTPOr (ORCPT ); Mon, 20 Jun 2022 11:14:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243375AbiFTPMP (ORCPT ); Mon, 20 Jun 2022 11:12:15 -0400 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D735B1F634 for ; Mon, 20 Jun 2022 08:02:57 -0700 (PDT) Received: by mail-lf1-x134.google.com with SMTP id t25so17702724lfg.7 for ; Mon, 20 Jun 2022 08:02:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WfituUDSg5fEW4dKt2h3fMS4b0IrVjkU8185C8pJjBY=; b=kFdZRoBhFIxJZLPTayXCJlh5xBCUkR1K1zZ2YflpY7c0rNVWSY5swaSK9jMmPGXzxQ 1GqoSBU6NUtXhV/7NpOPU415njrI7EcPXH9XBXd4WeC09TyT7aDShPFqectxf2XnTjKY X3C+gzqVgKqrfcGzRjiq9IsokgayDx9Kp7GcauUWykhbBQlMsWd8EOV4IaSf6cl1JH9m 4LnTKNKhmnC3xGA7mV5LH3e8TIDxFESOVT9cCG43VVnWG699CI5DKudZneoExnyrS4LM ciWgtqOkaSmQjqfXB8SBoVjO9AlBPTrxQOKUvOTYOrQUx0YFbbDI3XM47H1u7DvEwL6s PPxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WfituUDSg5fEW4dKt2h3fMS4b0IrVjkU8185C8pJjBY=; b=dBh27ybR0skDDiDMEjakWIqUVdKQu/CMcpEiwLVwNpp9thedI7BUE8aqP9fV0SE3DP +aUcHjxIndCqFfdtN7P7guSx1HZ4duS2xaaulPNlG9zuNOxK7mM/WYq0hcvzE2UwefHk IZp/z5M6BYCni2adlabTh/TYf6EqnT0+8WDPPr98tnb69bD7pL+GNzA91eysdXo62bkh AU/y+UbTuAxb1Nd8nCKAE5ISxaLWn1WggqR9M18Yw+y3kxzDk8NrpKPcpDYtP35Up0p4 5iGhx8e5Yu04w8PAbFqBTHHJ7oRRHMpA4n0LwmnUcHFcKUwN+GL5JKS6h9gTMSN5WU/a AbwQ== X-Gm-Message-State: AJIora8kqKLIacnUuVqnqLkHyxzLASOoXFUkTDeQlNlc96IeAq2fLhQB cpbnWCr6ijYmXl3Ct0IJYrxBhw== X-Google-Smtp-Source: AGRyM1vqri5GOOgVM3EWWhhIHFGXwMbDMwQp2NcgRArqY1SeTMY9aLG3jE7fpVm9+Dh+PwPmgb5/Dw== X-Received: by 2002:a05:6512:214d:b0:47f:5a25:ac11 with SMTP id s13-20020a056512214d00b0047f5a25ac11mr7963474lfr.627.1655737376113; Mon, 20 Jun 2022 08:02:56 -0700 (PDT) Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id e19-20020a05651236d300b0047f79f7758asm17564lfs.22.2022.06.20.08.02.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jun 2022 08:02:55 -0700 (PDT) From: Marcin Wojtas To: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, netdev@vger.kernel.org Cc: rafael@kernel.org, andriy.shevchenko@linux.intel.com, lenb@kernel.org, andrew@lunn.ch, vivien.didelot@gmail.com, f.fainelli@gmail.com, olteanv@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux@armlinux.org.uk, hkallweit1@gmail.com, gjb@semihalf.com, mw@semihalf.com, jaz@semihalf.com, tn@semihalf.com, Samer.El-Haj-Mahmoud@arm.com, upstream@semihalf.com Subject: [net-next: PATCH 10/12] net: dsa: add ACPI support Date: Mon, 20 Jun 2022 17:02:23 +0200 Message-Id: <20220620150225.1307946-11-mw@semihalf.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20220620150225.1307946-1-mw@semihalf.com> References: <20220620150225.1307946-1-mw@semihalf.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Although the recent switch to device_/fwnode_ API covers the most of modifications required for supporting ACPI, minor additional changes should be applied: * Use different subnode names with ACPI for 'ports' and 'mdio': * Naming of the nodes in ACPI must conform the namespace constraints, with regards to the characters' type and ACPI_NAMESEG_SIZE [1]. Because of that, the 'ports' subnode name used in device tree case, is not appropriate in ACPI world. This patch updates the subnode name depending on the hardware description type in runtime. * Obtain ports indexes from _ADR fields * Same as in the MDIO PHY case, use this standard field instead of parsing 'reg' property from _DSD object. * For now cascade topology remains unsupported in ACPI world, so disable ports connected to other switch devices. [1] https://uefi.org/specs/ACPI/6.4/05_ACPI_Software_Programming_Model/ACPI_Software_Programming_Model.html#acpi-namespace Signed-off-by: Marcin Wojtas --- net/dsa/dsa2.c | 35 +++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c index 5e11d66f9057..53837dad1cca 100644 --- a/net/dsa/dsa2.c +++ b/net/dsa/dsa2.c @@ -6,6 +6,8 @@ * Copyright (c) 2016 Andrew Lunn */ +#include +#include #include #include #include @@ -854,6 +856,7 @@ static int dsa_switch_setup_tag_protocol(struct dsa_switch *ds) static int dsa_switch_setup(struct dsa_switch *ds) { struct dsa_devlink_priv *dl_priv; + char mdio_node_name[] = "mdio"; struct fwnode_handle *fwnode; struct dsa_port *dp; int err; @@ -910,9 +913,16 @@ static int dsa_switch_setup(struct dsa_switch *ds) dsa_slave_mii_bus_init(ds); - fwnode = fwnode_get_named_child_node(ds->dev->fwnode, "mdio"); + /* Update subnode name if operating in the ACPI world. */ + if (is_acpi_node(fwnode)) + strncpy(mdio_node_name, "MDIO", ACPI_NAMESEG_SIZE); - err = of_mdiobus_register(ds->slave_mii_bus, to_of_node(fwnode)); + fwnode = fwnode_get_named_child_node(ds->dev->fwnode, mdio_node_name); + + if (is_acpi_node(fwnode)) + err = acpi_mdiobus_register(ds->slave_mii_bus, fwnode); + else + err = of_mdiobus_register(ds->slave_mii_bus, to_of_node(fwnode)); fwnode_handle_put(fwnode); if (err < 0) goto free_slave_mii_bus; @@ -1374,6 +1384,15 @@ static int dsa_port_parse_user(struct dsa_port *dp, const char *name) static int dsa_port_parse_dsa(struct dsa_port *dp) { + /* Cascade switch connection is not supported in ACPI world. */ + if (is_acpi_node(dp->fwnode)) { + dev_warn(dp->ds->dev, + "DSA type is not supported with ACPI, disable port #%d\n", + dp->index); + dp->type = DSA_PORT_TYPE_UNUSED; + return 0; + } + dp->type = DSA_PORT_TYPE_DSA; return 0; @@ -1524,11 +1543,16 @@ static int dsa_switch_parse_ports_of(struct dsa_switch *ds, struct fwnode_handle *fwnode) { struct fwnode_handle *ports, *port; + char ports_node_name[] = "ports"; struct dsa_port *dp; int err = 0; u32 reg; - ports = fwnode_get_named_child_node(fwnode, "ports"); + /* Update subnode name if operating in the ACPI world. */ + if (is_acpi_node(fwnode)) + strncpy(ports_node_name, "PRTS", ACPI_NAMESEG_SIZE); + + ports = fwnode_get_named_child_node(fwnode, ports_node_name); if (!ports) { /* The second possibility is "ethernet-ports" */ ports = fwnode_get_named_child_node(fwnode, "ethernet-ports"); @@ -1539,7 +1563,10 @@ static int dsa_switch_parse_ports_of(struct dsa_switch *ds, } fwnode_for_each_available_child_node(ports, port) { - err = fwnode_property_read_u32(port, "reg", ®); + if (is_acpi_node(port)) + err = acpi_get_local_address(ACPI_HANDLE_FWNODE(port), ®); + else + err = fwnode_property_read_u32(port, "reg", ®); if (err) { fwnode_handle_put(port); goto out_put_node; From patchwork Mon Jun 20 15:02:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcin Wojtas X-Patchwork-Id: 583306 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B1C9CCA47C for ; Mon, 20 Jun 2022 15:14:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242843AbiFTPOq (ORCPT ); Mon, 20 Jun 2022 11:14:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242211AbiFTPMW (ORCPT ); Mon, 20 Jun 2022 11:12:22 -0400 Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [IPv6:2a00:1450:4864:20::22a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 037921F63C for ; Mon, 20 Jun 2022 08:02:59 -0700 (PDT) Received: by mail-lj1-x22a.google.com with SMTP id d19so12221845lji.10 for ; Mon, 20 Jun 2022 08:02:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sH5mdU0J82lSBubyPIxIw/XIt0m9sm0DajZ7R0PZmFM=; b=knaJ8eJAzYF2U1LYJ1OxeeM1p3RjFGe574cRemVmlbNHTejes4i6AYL3jRMyvOtZ7v 1fS4SAr4Ktc0OTo4P7z+pflNDq1ID5JQ5zbdvjnjbnqUlHXsw9MlMA5FczYtmZj2sHWQ O7mgMEC7mlsws04CCUl8x2lUlBCwkCGFbZFLp1jUEEl+cL/3LRPWzTOLZM9FWqk7aEMQ zvdRX+UGVNE/Iodgbp8j90mjh8ubaeFxf0o2H6gHJCxY4AmfEr6aMBzLQ5gXb7C6E78K noaqIpK0dNrMiLMvv2XiuoprCbOcqEbg1QjkDRvAjLjty+GuuiAGmy+wj+Yz1aug2bd9 TAxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sH5mdU0J82lSBubyPIxIw/XIt0m9sm0DajZ7R0PZmFM=; b=chaSr8g1G3dPbsbqDdtPk0Ln62jNhvKlERr2HQVpDZ5kSHY9zMh9CuvW4MF9xVPBOg g/U8ghvfrNkk8CqTkly/x3GKzd17l0zbAy1gheACwCxneEkQtjvoayNHjtgp3MbWd7hM I/Hal2v/JN5fwR+ycKtk8HRBZpL91OXbvfandE1DjGd+Qdk/2+AQz6rTbWAfH4Sfu1yN RCHlKjk6HzmprIg1LbvnyvreAlza/wFCSKC4LiNsfDn2jdVq6KhmFYUEKFEVKov+nESj nmsOyExUlsrU5FANRzA5vy7j9lbhiUDI4A/mdwSAu3ILsNUzshYQkFSnfjDsaCPoFarK NGUQ== X-Gm-Message-State: AJIora/piYtfLKdVc+w5ojrRuQzD/cr9aZy4DhKlqiIYS3MFeWx3zXKm 7YYjK7VfoXGB9Lrx1wrSnyvuvQ== X-Google-Smtp-Source: AGRyM1uiyaR+g5NXDERpjkMHAfHMuJYfDGHDxYxby94uVCwaSCkyGa0OMkqKgsg6hF0M/5asgijo4A== X-Received: by 2002:a05:651c:4d1:b0:255:c269:da49 with SMTP id e17-20020a05651c04d100b00255c269da49mr12310504lji.54.1655737377262; Mon, 20 Jun 2022 08:02:57 -0700 (PDT) Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id e19-20020a05651236d300b0047f79f7758asm17564lfs.22.2022.06.20.08.02.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jun 2022 08:02:56 -0700 (PDT) From: Marcin Wojtas To: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, netdev@vger.kernel.org Cc: rafael@kernel.org, andriy.shevchenko@linux.intel.com, lenb@kernel.org, andrew@lunn.ch, vivien.didelot@gmail.com, f.fainelli@gmail.com, olteanv@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux@armlinux.org.uk, hkallweit1@gmail.com, gjb@semihalf.com, mw@semihalf.com, jaz@semihalf.com, tn@semihalf.com, Samer.El-Haj-Mahmoud@arm.com, upstream@semihalf.com Subject: [net-next: PATCH 11/12] net: dsa: mv88e6xxx: switch to device_/fwnode_ APIs Date: Mon, 20 Jun 2022 17:02:24 +0200 Message-Id: <20220620150225.1307946-12-mw@semihalf.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20220620150225.1307946-1-mw@semihalf.com> References: <20220620150225.1307946-1-mw@semihalf.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org In order to support both ACPI and DT, modify the generic DSA code to use device_/fwnode_ equivalent routines. No functional change is introduced by this patch. Signed-off-by: Marcin Wojtas --- drivers/net/dsa/mv88e6xxx/chip.c | 53 ++++++++++---------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c index 0b49d243e00b..556defa4379d 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -3278,7 +3278,7 @@ static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port) static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port) { - struct device_node *phy_handle = NULL; + struct fwnode_handle *phy_handle = NULL; struct dsa_switch *ds = chip->ds; struct dsa_port *dp; int tx_amp; @@ -3475,15 +3475,15 @@ static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port) if (chip->info->ops->serdes_set_tx_amplitude) { dp = dsa_to_port(ds, port); if (dp) - phy_handle = of_parse_phandle(dp->dn, "phy-handle", 0); + phy_handle = fwnode_find_reference(dp->fwnode, "phy-handle", 0); - if (phy_handle && !of_property_read_u32(phy_handle, - "tx-p2p-microvolt", - &tx_amp)) + if (!IS_ERR(phy_handle) && !fwnode_property_read_u32(phy_handle, + "tx-p2p-microvolt", + &tx_amp)) err = chip->info->ops->serdes_set_tx_amplitude(chip, port, tx_amp); - if (phy_handle) { - of_node_put(phy_handle); + if (!IS_ERR(phy_handle)) { + fwnode_handle_put(phy_handle); if (err) return err; } @@ -3867,10 +3867,11 @@ static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val) } static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip, - struct device_node *np, + struct fwnode_handle *fwnode, bool external) { static int index; + struct device_node *np = to_of_node(fwnode); struct mv88e6xxx_mdio_bus *mdio_bus; struct mii_bus *bus; int err; @@ -3949,18 +3950,18 @@ static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip) } static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip, - struct device_node *np) + struct fwnode_handle *fwnode) { - struct device_node *child; + struct fwnode_handle *child; int err; /* Always register one mdio bus for the internal/default mdio * bus. This maybe represented in the device tree, but is * optional. */ - child = of_get_child_by_name(np, "mdio"); + child = fwnode_get_named_child_node(fwnode, "mdio"); err = mv88e6xxx_mdio_register(chip, child, false); - of_node_put(child); + fwnode_handle_put(child); if (err) return err; @@ -3968,13 +3969,13 @@ static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip, * which say they are compatible with the external mdio * bus. */ - for_each_available_child_of_node(np, child) { - if (of_device_is_compatible( - child, "marvell,mv88e6xxx-mdio-external")) { + fwnode_for_each_available_child_node(fwnode, child) { + if (fwnode_property_match_string(child, "compatible", + "marvell,mv88e6xxx-mdio-external") == 0) { err = mv88e6xxx_mdio_register(chip, child, true); if (err) { mv88e6xxx_mdios_unregister(chip); - of_node_put(child); + fwnode_handle_put(child); return err; } } @@ -6962,16 +6963,16 @@ static int mv88e6xxx_probe(struct mdio_device *mdiodev) struct dsa_mv88e6xxx_pdata *pdata = mdiodev->dev.platform_data; const struct mv88e6xxx_info *compat_info = NULL; struct device *dev = &mdiodev->dev; - struct device_node *np = dev->of_node; + struct fwnode_handle *fwnode = dev->fwnode; struct mv88e6xxx_chip *chip; int port; int err; - if (!np && !pdata) + if (!fwnode && !pdata) return -EINVAL; - if (np) - compat_info = of_device_get_match_data(dev); + if (fwnode) + compat_info = device_get_match_data(dev); if (pdata) { compat_info = pdata_device_get_match_data(dev); @@ -7030,9 +7031,9 @@ static int mv88e6xxx_probe(struct mdio_device *mdiodev) mv88e6xxx_phy_init(chip); if (chip->info->ops->get_eeprom) { - if (np) - of_property_read_u32(np, "eeprom-length", - &chip->eeprom_len); + if (fwnode) + device_property_read_u32(dev, "eeprom-length", + &chip->eeprom_len); else chip->eeprom_len = pdata->eeprom_len; } @@ -7043,8 +7044,8 @@ static int mv88e6xxx_probe(struct mdio_device *mdiodev) if (err) goto out; - if (np) { - chip->irq = of_irq_get(np, 0); + if (fwnode) { + chip->irq = fwnode_irq_get(fwnode, 0); if (chip->irq == -EPROBE_DEFER) { err = chip->irq; goto out; @@ -7082,7 +7083,7 @@ static int mv88e6xxx_probe(struct mdio_device *mdiodev) if (err) goto out_g1_atu_prob_irq; - err = mv88e6xxx_mdios_register(chip, np); + err = mv88e6xxx_mdios_register(chip, fwnode); if (err) goto out_g1_vtu_prob_irq; From patchwork Mon Jun 20 15:02:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcin Wojtas X-Patchwork-Id: 583647 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4CABACCA479 for ; Mon, 20 Jun 2022 15:14:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241912AbiFTPOp (ORCPT ); Mon, 20 Jun 2022 11:14:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243385AbiFTPMX (ORCPT ); Mon, 20 Jun 2022 11:12:23 -0400 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C9901FA4D for ; Mon, 20 Jun 2022 08:03:00 -0700 (PDT) Received: by mail-lf1-x133.google.com with SMTP id g4so5342519lfv.9 for ; Mon, 20 Jun 2022 08:02:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=79HyXuMDzSUSAqm9LJDxm1QulLKFCMJuKULtDaG7pgg=; b=nFzaIAZullAM5QpV7lhiewLkjFv18wWs2j2rGdYzDLGAKqfmRPytd4UVWA0Sfl8EJ2 9d5m4M40GMi7QHDQ9TRwYn4Z9lkJNm2cUfefT8nA9Q/zGr4agzJ1BBbVQ9jKfFyEHmtx ePBznUBHD79+Z1j+mba+bqQTBIH2bJUV38tvJfn/nNjom4f3tYypl9LBWzsfCiDgjYX/ 7p1zgdkbcrzfnDn1XpWzPxkn1j/Z1oI0UWMzZtzVwFfMLXUWB6/cXOE5cCHUSYk0sgBk AWdAp5D8krh12xI1gZlvwuFmpn7/ZqcR8oTGJ9FEQf5A2tG5dpHH6vd84+ZI5slXizXb dcMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=79HyXuMDzSUSAqm9LJDxm1QulLKFCMJuKULtDaG7pgg=; b=p96qNzbYvufLdZDSUQe51pyuBfTGto5ducwBJnJ9uTgV/fnxfC3YFP1N2tDXXAN/0d oJz+bpYILv0YZTppkBmr1KL8A4xHdBRuTQIaxM+zM/m+lDT2xk27OZWuM7MIWpAOe+W9 +8vCZKNaqUMRxt3K8CvkBZgDh1G3Ek+SmE0F/NagzvLabqJRp0Sl8ScA12fvhYtmL/o5 yqCN7CDR2wswQYdBI3Oj6jP7uxyxSIvI1iUG6tIJMYdCn8Xz8fIZgqUKolFOwHxnyelz C7C4iKmxDrgkv1WsmJYgphe2Nm+ifRj8cJl80ovYMkxG2034wGCtKIi7eRJXSg2vl43T L1gg== X-Gm-Message-State: AJIora/NhiGwDJvrG+GIG3BaOxNMK8onYswfyfUqVcRnbthfsqklHT5c DD9U0EdtxXjJA0ZIGZDrph+XiA== X-Google-Smtp-Source: AGRyM1sZjX433uIfDuDxIJjCxeAulm4JqpTHnUDqeXfKIxktT74nYmgA/6lU+5nPFAWsS0NTA+T+Pg== X-Received: by 2002:a05:6512:3c87:b0:47f:70a0:b8f2 with SMTP id h7-20020a0565123c8700b0047f70a0b8f2mr2584155lfv.407.1655737378368; Mon, 20 Jun 2022 08:02:58 -0700 (PDT) Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id e19-20020a05651236d300b0047f79f7758asm17564lfs.22.2022.06.20.08.02.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jun 2022 08:02:58 -0700 (PDT) From: Marcin Wojtas To: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, netdev@vger.kernel.org Cc: rafael@kernel.org, andriy.shevchenko@linux.intel.com, lenb@kernel.org, andrew@lunn.ch, vivien.didelot@gmail.com, f.fainelli@gmail.com, olteanv@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux@armlinux.org.uk, hkallweit1@gmail.com, gjb@semihalf.com, mw@semihalf.com, jaz@semihalf.com, tn@semihalf.com, Samer.El-Haj-Mahmoud@arm.com, upstream@semihalf.com Subject: [net-next: PATCH 12/12] net: dsa: mv88e6xxx: add ACPI support Date: Mon, 20 Jun 2022 17:02:25 +0200 Message-Id: <20220620150225.1307946-13-mw@semihalf.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20220620150225.1307946-1-mw@semihalf.com> References: <20220620150225.1307946-1-mw@semihalf.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Previous patches dropped the strict dependency on the OF_* API in both generic DSA subsystem and the mv88e6xxx driver. As a result the ACPI support can be introduced by adding the necessary ID's in the acpi_match_table and a two minor required adjustments, i.e. different mdiobus registration and MDIO subnode name, so to conform ACPI namespace requirements [1]. [1] https://uefi.org/specs/ACPI/6.4/05_ACPI_Software_Programming_Model/ACPI_Software_Programming_Model.html#acpi-namespace Signed-off-by: Marcin Wojtas --- drivers/net/dsa/mv88e6xxx/chip.c | 25 ++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c index 556defa4379d..a74e528184aa 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -10,6 +10,8 @@ * Vivien Didelot */ +#include +#include #include #include #include @@ -3913,7 +3915,10 @@ static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip, goto out; } - err = of_mdiobus_register(bus, np); + if (is_acpi_node(fwnode)) + err = acpi_mdiobus_register(bus, fwnode); + else + err = of_mdiobus_register(bus, np); if (err) { dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err); mv88e6xxx_g2_irq_mdio_free(chip, bus); @@ -3952,14 +3957,19 @@ static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip) static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip, struct fwnode_handle *fwnode) { + char mdio_node_name[] = "mdio"; struct fwnode_handle *child; int err; + /* Update subnode name if operating in the ACPI world. */ + if (is_acpi_node(fwnode)) + strncpy(mdio_node_name, "MDIO", ACPI_NAMESEG_SIZE); + /* Always register one mdio bus for the internal/default mdio * bus. This maybe represented in the device tree, but is * optional. */ - child = fwnode_get_named_child_node(fwnode, "mdio"); + child = fwnode_get_named_child_node(fwnode, mdio_node_name); err = mv88e6xxx_mdio_register(chip, child, false); fwnode_handle_put(child); if (err) @@ -7177,6 +7187,16 @@ static const struct of_device_id mv88e6xxx_of_match[] = { MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match); +#ifdef CONFIG_ACPI +static const struct acpi_device_id sdhci_mv88e6xxx_acpi_ids[] = { + { .id = "MRVL0120", (kernel_ulong_t)&mv88e6xxx_table[MV88E6085]}, + { .id = "MRVL0121", (kernel_ulong_t)&mv88e6xxx_table[MV88E6190]}, + { .id = "MRVL0122", (kernel_ulong_t)&mv88e6xxx_table[MV88E6250]}, + {} +}; +MODULE_DEVICE_TABLE(acpi, sdhci_mv88e6xxx_acpi_ids); +#endif + static struct mdio_driver mv88e6xxx_driver = { .probe = mv88e6xxx_probe, .remove = mv88e6xxx_remove, @@ -7184,6 +7204,7 @@ static struct mdio_driver mv88e6xxx_driver = { .mdiodrv.driver = { .name = "mv88e6085", .of_match_table = mv88e6xxx_of_match, + .acpi_match_table = ACPI_PTR(sdhci_mv88e6xxx_acpi_ids), .pm = &mv88e6xxx_pm_ops, }, };