From patchwork Thu Jul 13 02:42:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 119488 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp1551526vqm; Wed, 12 Jul 2023 19:51:15 -0700 (PDT) X-Google-Smtp-Source: APBJJlEjpach5fUsyQoYJGuOaR3iO2C1OMoQphZDDz480+35moXg7FuXSFDIQjlg+QQy/rmlHkb4 X-Received: by 2002:a05:6402:2048:b0:51e:d76:25b2 with SMTP id bc8-20020a056402204800b0051e0d7625b2mr462037edb.29.1689216674906; Wed, 12 Jul 2023 19:51:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689216674; cv=none; d=google.com; s=arc-20160816; b=U98p0ijeA0aJCsFqHev2uhR9MjTRmwzmFZb13urNcx3ytxR6hqhg4+R3m+qPOH5Uf1 Ii4JgT+RYuqWuQi0S0WSV9MmhN1HNfvBJnMdx+1JQwM3dkVj5of07SpSe0CvfVyaczkn 2NuwThRXsRJnpAsJuk6qG2e+Uumx0G6Ok3LrBz4i2gYZf6HC90Dc/pfeYeyaaJnEJbP6 /Zrqr0msSc1nfyx4JRruK1VMWCljLN7YmgsJwQOEEdM5FnmIO4yk9HJLz4esHRWxHOYy AmMcpX1qho+R3SGYEyRYypz5HWglmICcSTiRDH5sc+a9xJnA80bSgsxzDZhEIcCU/y5S 5d1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:to:from:date; bh=HyaZmSJtYEYMtLnTezaZD6PnC9Rr2bseCmWCH6AeN/s=; fh=8llIv963BynnbOUPgd+2pJJVHOGfqGKUzgN8jmjOkOI=; b=Sqs3lX3NP6jgE1zLOeUXsr7A5FFLwOr7XDt97PeXwcF4WdLyo2OIBPzuTugBQfWr5G 3G+VtVQpSQHrXnuVwRVtxVnsWaBcEbCStXyql+zU9jPByd+zrM2xqR1Z0UceeYPw7bQp RMs9d1cgZyC2PzlJpha9lden156/q12Sxs0/BTJdPtPp39NVtM6f1bRHflO7S7inTe28 hduv90iu2+eZN4tyygPAgf0y2QVjm9yIN0MoE0bJU7dAEhyu/zJwaYoIzBItbwYLoYSp shhCMnm2ow8DEn0a3ZqJ/g1qt3RLfX67SDRPNC/MPDMXs07kw4npIFrN2jss21eR64zp ga3Q== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w18-20020aa7cb52000000b0051e3cb37258si5762885edt.178.2023.07.12.19.50.51; Wed, 12 Jul 2023 19:51:14 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233697AbjGMCnC (ORCPT + 99 others); Wed, 12 Jul 2023 22:43:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233704AbjGMCnA (ORCPT ); Wed, 12 Jul 2023 22:43:00 -0400 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B245E7E; Wed, 12 Jul 2023 19:42:58 -0700 (PDT) Received: from local by pidgin.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.96) (envelope-from ) id 1qJmI7-0005fA-2h; Thu, 13 Jul 2023 02:42:53 +0000 Date: Thu, 13 Jul 2023 03:42:29 +0100 From: Daniel Golle To: netdev@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Felix Fietkau , John Crispin , Sean Wang , Mark Lee , Lorenzo Bianconi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Matthias Brugger , AngeloGioacchino Del Regno , Michael Lee Subject: [PATCH] net: ethernet: mtk_eth_soc: handle probe deferral Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771272064477040303 X-GMAIL-MSGID: 1771272064477040303 Move the call to of_get_ethdev_address to mtk_add_mac which is part of the probe function and can hence itself return -EPROBE_DEFER should of_get_ethdev_address return -EPROBE_DEFER. This allows us to entirely get rid of the mtk_init function. The problem of of_get_ethdev_address returning -EPROBE_DEFER surfaced in situations in which the NVMEM provider holding the MAC address has not yet be loaded at the time mtk_eth_soc is initially probed. In this case probing of mtk_eth_soc should be deferred instead of falling back to use a random MAC address, so once the NVMEM provider becomes available probing can be repeated. Fixes: 656e705243fd ("net-next: mediatek: add support for MT7623 ethernet") Signed-off-by: Daniel Golle --- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 29 ++++++++------------- 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c index 834c644b67db5..2d15342c260ae 100644 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c @@ -3846,23 +3846,6 @@ static int mtk_hw_deinit(struct mtk_eth *eth) return 0; } -static int __init mtk_init(struct net_device *dev) -{ - struct mtk_mac *mac = netdev_priv(dev); - struct mtk_eth *eth = mac->hw; - int ret; - - ret = of_get_ethdev_address(mac->of_node, dev); - if (ret) { - /* If the mac address is invalid, use random mac address */ - eth_hw_addr_random(dev); - dev_err(eth->dev, "generated random MAC address %pM\n", - dev->dev_addr); - } - - return 0; -} - static void mtk_uninit(struct net_device *dev) { struct mtk_mac *mac = netdev_priv(dev); @@ -4278,7 +4261,6 @@ static const struct ethtool_ops mtk_ethtool_ops = { }; static const struct net_device_ops mtk_netdev_ops = { - .ndo_init = mtk_init, .ndo_uninit = mtk_uninit, .ndo_open = mtk_open, .ndo_stop = mtk_stop, @@ -4340,6 +4322,17 @@ static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np) mac->hw = eth; mac->of_node = np; + err = of_get_ethdev_address(mac->of_node, eth->netdev[id]); + if (err == -EPROBE_DEFER) + return err; + + if (err) { + /* If the mac address is invalid, use random mac address */ + eth_hw_addr_random(eth->netdev[id]); + dev_err(eth->dev, "generated random MAC address %pM\n", + eth->netdev[id]->dev_addr); + } + memset(mac->hwlro_ip, 0, sizeof(mac->hwlro_ip)); mac->hwlro_ip_cnt = 0;