Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp594607rwp; Wed, 12 Jul 2023 19:50:37 -0700 (PDT) X-Google-Smtp-Source: APBJJlH+yVGMNis+lrKN8JR5S2bS1anwbr6aSOQmYChB84LcQtxMm8LHs/cjWao0/I1wSRs5Tx4X X-Received: by 2002:a05:651c:104e:b0:2b6:c790:150a with SMTP id x14-20020a05651c104e00b002b6c790150amr167557ljm.22.1689216636951; Wed, 12 Jul 2023 19:50:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689216636; cv=none; d=google.com; s=arc-20160816; b=yUibb0I+j2pRN1bScsoFtPMdp+LAJL2zhiJe0J/B6CywYFzBMz3Yy2jIhk56C8P10z JgbHovJWsJVgvhOkhGX/fz9g/i6le8VSQY3cPmXm6Ai9XVU2XldsgrwxQLiX7hfj0MGP ZhWZ0FroYEsGhOxFhBA4OkhQSw/v6Jy6+udCF5AJN/5wmk59uZzdtOfRRGiK1Yi8U4cB NiGN8KSmFTm5lSaobRHBhegTvfyt9l2XZbPRHZ6+HWZaoC6G8IuV72LGpC1xvyjlG9GC NszektxBihgYwmGlA2PtQp2LafXY+gnzMglniGQA0yo7zPWtkKBpemjuvDVW2anlccs7 g+hg== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i12-20020a170906250c00b0097d7282c899si6231189ejb.534.2023.07.12.19.50.12; Wed, 12 Jul 2023 19:50:36 -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 S233695AbjGMCnC (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-Type: text/plain; charset=us-ascii 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 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; -- 2.41.0