From patchwork Wed Apr 10 13:13:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13624481 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6DCF5CD11C2 for ; Wed, 10 Apr 2024 13:20:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=nuTmGGQtVFSwFhYBZRnqccdMgMO0olpCQkm+/RhU/A0=; b=jBazXY82gi+7Tf FdtZGv9zRXb/J9//Nugm1/StCM3kLOcft4jJSvooNcBKAjzmlPl2dn+8iQy5uCujWzKevJ+Flfos4 A/PF1m9ymNtzm5jClHv11uvM1ZW4K8PbVWYiaprHi9f7sPxeZY6d2V1/qiH40zncLC8UPOZITMPyw Q87/9AV69x7+xd6Aw8LAhy1Qd5kk+oGZBxZwDCT/jw4vwYhMWU2I1qs+Ct9fIYqS4nl3Hn5z3TYh/ WLKMPbpzevo3sAUn/6JIlUtclyDHxPmxFaahjsimMwKirovvo0d+3ep+yKHl+QB5XQPopGahzxdzU v86RHdN0tEuMrSi22MWA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1ruXrs-000000076v4-1BgL; Wed, 10 Apr 2024 13:20:00 +0000 Received: from mail-ed1-f48.google.com ([209.85.208.48]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1ruXq6-000000075Nj-0k0V; Wed, 10 Apr 2024 13:18:13 +0000 Received: by mail-ed1-f48.google.com with SMTP id 4fb4d7f45d1cf-56e6acb39d4so3741317a12.1; Wed, 10 Apr 2024 06:18:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712755087; x=1713359887; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bGHHnAjzHXOHKZAHNwNt7Xm//rgfn0lSUB+nM5VysgU=; b=AB3zekimdsBObnZip6LA4zOTC8tDSLjVvH4NZ1Qfvl1gB2AwY47JseBma8vjBKacD4 1qd8aHDyiz5QCqD+JnGXfFEgJIaupqdbMHrIN/6wN+Y3uHHpxgIL2787yOG7BFKD8iD7 tBvx1BeUtA8k7a3gyogyDKNWRFo0xFGtnsbiZWQlU1kYoiSzHa1vyGrLg/F4XboviOiV edav9U0ZTMu0ODBTPpQcyy4E+0OCQ29fKDbhE/OId2e2BjwH+9dK5rgraingB6PExq37 Yd0fpiyW+vQUawxq8AYGNo/itxoBGqOPv4udDvtlGKn4frjZwVkLILhd4OWUh+OXMDtE XgyA== X-Forwarded-Encrypted: i=1; AJvYcCXDoIlCfknGD6tw/PyABMq0SK+SWQG6q1H2jfw6lLPNu6bLaNYtTS7VWmOtaHbds6jJnBnLwZcc9bCvxfUR9gpyU5gRG46TfBQglyFoCv4Yk+nMMZO/qGX939RaYuYYCyU5V+Y13vW6OIuXFtvVDF1NJQiFGO0n0dQk/MGCmyiHVXJLBjIUAgSpP9y9bywf+UJidxheRwDwhs0SjUUdSuui2rXvFOfTQmGdS/V/ZcpqJA== X-Gm-Message-State: AOJu0YxNT2RDAqDha0KbStubZix5dje+d7LcD7g9iTle+/Y53GQDJ6Vp ZP7taK+HL3DYeiDNH952Q5pcA88l+LypZsSH7LJWiPJVMP3f1Msk X-Google-Smtp-Source: AGHT+IHfRDKViblgpUPyWrUAnhST+TBB6wSl0qe87VqUsLBU1kMLXMG9TkoSj5KDLOwo8qX+Dgkttg== X-Received: by 2002:a50:9e27:0:b0:56e:23e3:bdc3 with SMTP id z36-20020a509e27000000b0056e23e3bdc3mr434260ede.16.1712755087472; Wed, 10 Apr 2024 06:18:07 -0700 (PDT) Received: from localhost (fwdproxy-lla-118.fbsv.net. [2a03:2880:30ff:76::face:b00c]) by smtp.gmail.com with ESMTPSA id h1-20020a0564020e8100b005682a0e915fsm6433736eda.76.2024.04.10.06.18.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 06:18:06 -0700 (PDT) From: Breno Leitao To: aleksander.lobakin@intel.com, kuba@kernel.org, davem@davemloft.net, pabeni@redhat.com, edumazet@google.com, elder@kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, nbd@nbd.name, sean.wang@mediatek.com, Mark-MC.Lee@mediatek.com, lorenzo@kernel.org, taras.chornyi@plvision.eu, ath11k@lists.infradead.org, ath10k@lists.infradead.org, linux-wireless@vger.kernel.org, geomatsi@gmail.com, kvalo@kernel.org, Matthias Brugger , AngeloGioacchino Del Regno , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend Cc: quic_jjohnson@quicinc.com, leon@kernel.org, dennis.dalessandro@cornelisnetworks.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, idosch@idosch.org, leitao@debian.org Subject: [PATCH net-next v5 05/10] net: mediatek: mtk_eth_sock: allocate dummy net_device dynamically Date: Wed, 10 Apr 2024 06:13:46 -0700 Message-ID: <20240410131407.3897251-6-leitao@debian.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240410131407.3897251-1-leitao@debian.org> References: <20240410131407.3897251-1-leitao@debian.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240410_061810_392252_1401C208 X-CRM114-Status: GOOD ( 15.44 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Embedding net_device into structures prohibits the usage of flexible arrays in the net_device structure. For more details, see the discussion at [1]. Un-embed the net_device from the private struct by converting it into a pointer. Then use the leverage the new alloc_netdev_dummy() helper to allocate and initialize dummy devices. [1] https://lore.kernel.org/all/20240229225910.79e224cf@kernel.org/ Signed-off-by: Breno Leitao --- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 17 +++++++++++++---- drivers/net/ethernet/mediatek/mtk_eth_soc.h | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c index caa13b9cedff..d7a96dc11c07 100644 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c @@ -1710,7 +1710,7 @@ static struct page_pool *mtk_create_page_pool(struct mtk_eth *eth, if (IS_ERR(pp)) return pp; - err = __xdp_rxq_info_reg(xdp_q, ð->dummy_dev, id, + err = __xdp_rxq_info_reg(xdp_q, eth->dummy_dev, id, eth->rx_napi.napi_id, PAGE_SIZE); if (err < 0) goto err_free_pp; @@ -4188,6 +4188,8 @@ static int mtk_free_dev(struct mtk_eth *eth) metadata_dst_free(eth->dsa_meta[i]); } + free_netdev(eth->dummy_dev); + return 0; } @@ -4983,9 +4985,14 @@ static int mtk_probe(struct platform_device *pdev) /* we run 2 devices on the same DMA ring so we need a dummy device * for NAPI to work */ - init_dummy_netdev(ð->dummy_dev); - netif_napi_add(ð->dummy_dev, ð->tx_napi, mtk_napi_tx); - netif_napi_add(ð->dummy_dev, ð->rx_napi, mtk_napi_rx); + eth->dummy_dev = alloc_netdev_dummy(0); + if (!eth->dummy_dev) { + err = -ENOMEM; + dev_err(eth->dev, "failed to allocated dummy device\n"); + goto err_unreg_netdev; + } + netif_napi_add(eth->dummy_dev, ð->tx_napi, mtk_napi_tx); + netif_napi_add(eth->dummy_dev, ð->rx_napi, mtk_napi_rx); platform_set_drvdata(pdev, eth); schedule_delayed_work(ð->reset.monitor_work, @@ -4993,6 +5000,8 @@ static int mtk_probe(struct platform_device *pdev) return 0; +err_unreg_netdev: + mtk_unreg_dev(eth); err_deinit_ppe: mtk_ppe_deinit(eth); mtk_mdio_cleanup(eth); diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.h b/drivers/net/ethernet/mediatek/mtk_eth_soc.h index 9ae3b8a71d0e..723fc637027c 100644 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h @@ -1242,7 +1242,7 @@ struct mtk_eth { spinlock_t page_lock; spinlock_t tx_irq_lock; spinlock_t rx_irq_lock; - struct net_device dummy_dev; + struct net_device *dummy_dev; struct net_device *netdev[MTK_MAX_DEVS]; struct mtk_mac *mac[MTK_MAX_DEVS]; int irq[3];