Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp93114imn; Wed, 27 Jul 2022 00:07:57 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vVl/JxMPccwDlSjpB4EsK6ur54GUuWYkFQ4hqu7OGhiZf/UsJDEmx6SkR2mvLyRU/GPbKD X-Received: by 2002:a17:907:2cf3:b0:72b:8ac1:a21f with SMTP id hz19-20020a1709072cf300b0072b8ac1a21fmr16730964ejc.291.1658905676961; Wed, 27 Jul 2022 00:07:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658905676; cv=none; d=google.com; s=arc-20160816; b=mbfis72jnb0xq6HHcu2FFaEX5q6XihiYekn0EK1XA4Oi7cWnd3No0UwTVoOEPXpiuh iOlA1E9QRINgyqAxElS0qvF05CiyK8wonYaN9cvcvOB+VJbT9sLeOu/+NcGUyAUNM8KN NPutFUMw2VGZZL6nEKWFFU+V4w8/LvCumPYZ9ug64qrieDCruOmEKDy39ylGNet54xha cYNS+fpUY6g3LDbSnQUSPVA8uSmc1My0+doryNkTiF3rHLRD+gIyZeXVC2MR4ZNwmy++ vC8nKdaYrWVvtCMkw5TchGf7CekSLZtinJToMnLtOa899bHhj507JWFJkr3Wm0QI5W8y lfLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=9YzF/moGV0ykdIvPXLa6CisfKYdf2yrfdtDijEUJPuI=; b=cVDo3hThqkvtcseo39e9qXLNOakSXExXwbBYfI7cPyYpn2qlwS0jlkc5gc/HucTiP1 R/1iVV+1rA7Eh1Deom1oJfoIsclV1LlnSL8zDxfLkKdrBRY15T5WdSH1Tr7CEHtda1lH f05Pyv0YvYWXUojfHYwn3JUKSPUdH7GwMKpque8iDlm53WmDWrfObV8/kgA2+YwgAs8L iaZjqrvtqCulO/Lq+BNP3Uky9lrS13ZBOro40Jg/ZQ+6/4dGsVfBFSfLsTsM63ilB9Pf nvxyzTO8DyxDjmYJuXbwmzApPuYyH9bcASpIxiFU2bMbBuoWbwIcQw6aHkuHbfgT0ucW dT5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@semihalf.com header.s=google header.b=kZw2qp1f; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=semihalf.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hd31-20020a170907969f00b006f445fe1697si14201598ejc.35.2022.07.27.00.07.31; Wed, 27 Jul 2022 00:07:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@semihalf.com header.s=google header.b=kZw2qp1f; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=semihalf.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230218AbiG0Goo (ORCPT + 99 others); Wed, 27 Jul 2022 02:44:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230079AbiG0GoL (ORCPT ); Wed, 27 Jul 2022 02:44:11 -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 C4FE641995 for ; Tue, 26 Jul 2022 23:43:49 -0700 (PDT) Received: by mail-lf1-x12a.google.com with SMTP id a23so23392869lfm.10 for ; Tue, 26 Jul 2022 23:43: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=9YzF/moGV0ykdIvPXLa6CisfKYdf2yrfdtDijEUJPuI=; b=kZw2qp1fqzn/11TXztXmeboNZn+S/94NltYlqBuJzWhuN6PSawQ6kygf2qfhUEuxOn jZ39zJQCcC/KfT0/sLA8dxxzyKDDuSnxT3E4ycdOqRPKrBd+wPVSjvD4FpJ/UaYtUzfN jyD1IG61jopdRT5jfxqPJFi+zGSv0t8R0IH/YKCfNn4rGlagjYqJ9mtEHvAX/qHRAvmG LvLYTYAnJRZrviGu+JwpmjH+EQkZeBlKqEayJcfGMIg/A8DlRizFnt1BrvC+x5JaNsh/ bkS+08klYM8jOOCQfUQbi98cIG3foD7iYgmWNOQXVSU0N7NmuPFTDHsvCniJAETgzTcA 89Kg== 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=9YzF/moGV0ykdIvPXLa6CisfKYdf2yrfdtDijEUJPuI=; b=XrqhPDx6IS9E46Ttv4q1NK8DYFTDkGJTJx0tV9vJtBfLnBCSOsZ7BWpPRPrZEDLFXv qiDth3bP4U46Kvc5n/0p11jHnrPe50z1WFr4P4KOkD5GFLXFef5D6y8CXSKh/OmQ+9h6 vInDbY0KCR6cocLwMqvYDFb0vMD6O1Ray62qEz4t31DTyNEe856YsABsDFS8td4K7d76 A54vJRs40aLC46e/iMMSMTsADCoXAzc/pCB5GVNE50olTKGJ72Hc+PcJebCB9Xid615G wjYUbVhLtMOL21XYRve1+QYHl1IoRtCcuqEPhQ4rZIFVjfx1IL56gBANA/cZ5kKmdfvI 9ZKQ== X-Gm-Message-State: AJIora9pUMoDS5wr0sgKnhOOkwKJCeNO5v5e0x4NOjo/pKaT35dGkDZt qU7J3dBfdknVy7xoExQIf3sg0npsCuV1iw== X-Received: by 2002:a05:6512:39c8:b0:48a:7816:1f7f with SMTP id k8-20020a05651239c800b0048a78161f7fmr7251843lfu.571.1658904227638; Tue, 26 Jul 2022 23:43:47 -0700 (PDT) Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id w19-20020a05651234d300b0048a97a1df02sm1157231lfr.6.2022.07.26.23.43.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jul 2022 23:43: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, sean.wang@mediatek.com, Landen.Chao@mediatek.com, linus.walleij@linaro.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 v3 6/8] net: core: switch to fwnode_find_net_device_by_node() Date: Wed, 27 Jul 2022 08:43:19 +0200 Message-Id: <20220727064321.2953971-7-mw@semihalf.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20220727064321.2953971-1-mw@semihalf.com> References: <20220727064321.2953971-1-mw@semihalf.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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. For that purpose use newly added fwnode_dev_node_match helper routine. Signed-off-by: Marcin Wojtas --- include/linux/etherdevice.h | 1 + include/linux/of_net.h | 6 ----- net/core/net-sysfs.c | 25 ++++++-------------- net/dsa/dsa2.c | 3 ++- 4 files changed, 10 insertions(+), 25 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 d61afd21aab5..fc972545aaea 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -1935,38 +1936,26 @@ 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) -{ - for (; dev; dev = dev->parent) { - if (dev->of_node == data) - return 1; - } - - return 0; -} - /* - * 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 fwnode + * @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_find_parent_dev_match); if (!dev) return NULL; return to_net_dev(dev); } -EXPORT_SYMBOL(of_find_net_device_by_node); -#endif +EXPORT_SYMBOL(fwnode_find_net_device_by_node); /* 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 82fb3b009fb4..bba416eba9c2 100644 --- a/net/dsa/dsa2.c +++ b/net/dsa/dsa2.c @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -1498,7 +1499,7 @@ static int dsa_port_parse_fw(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; -- 2.29.0