From patchwork Thu Apr 4 11:48:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13617618 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 87B3DCD1284 for ; Thu, 4 Apr 2024 11:50:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=mzV7bmg3PRLALaaFv1RRGYLnCVfom7cRGx1C8pOQ9QY=; b=BMHPBVBrmA/nQvXQcpUtVtZLdW p1mIQff2AsD+Wueuqe2lJ+52tFhU23KRy2awSfym+whsbVYuIjdZB6+pQDAxQeWFdaK3HTrECgYvQ 457ZwKKBHIsIqG7gEa40xjc83ij3b/Eu6p9Rs95Gc00p1hTyzTyVDa3CY7+m+5ewFOMh5GEXuXE5+ eNLPLPArPwKlPSvGjA3B4hzpfc05I8XOZpOpCC3Dc4aXLEX1O1E6qbyhOuNQLGxN8oeoQezCGDfgA oAmvoLJ4i9otkODf3C7FoMbUx0KUIy1dfIqyeHsPcKrqlWLxMskSTnN1VBFvzgoB+IDplVdY9nIK/ yTvJ1IRg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rsLbi-00000002RVm-3oJK; Thu, 04 Apr 2024 11:50:14 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rsLbW-00000002ROq-0ea6; Thu, 04 Apr 2024 11:50:02 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=mzV7bmg3PRLALaaFv1RRGYLnCVfom7cRGx1C8pOQ9QY=; b=rFfG6KtoPOk9ADiG887dmX7YxP KXqHRe4zzEBJZDTt0yvgE1mJa1EDbMUrR6IB+1VPWxyZNe5uOe8vgapUqX+H5AwZKDl0GY0eGwfKr y8P0tpOfs780iBlxJpSJS2srHXB2REbQepE6JOCNJUQ3d23G38K7Y3I5pDX1peY036aGVzRummZ31 Hu7iz2qCszOTg3V/Lw/SyhQONQyzfmKj2IE7x1T4PcxTfTdE6oSLpqUSWh9ZNCh1pQwNFLhgsHrCP MUVkOJpeCyrIgUKadIKz+8m5IDkqOW/bqoaRXG1LXnD/UZAxfvg0gyNKdtENbm8JF+rPUVDtqwhH2 HfFkrYXg==; Received: from mail-ej1-f49.google.com ([209.85.218.49]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rsLbQ-0000000503v-1WAC; Thu, 04 Apr 2024 11:50:00 +0000 Received: by mail-ej1-f49.google.com with SMTP id a640c23a62f3a-a44f2d894b7so119421266b.1; Thu, 04 Apr 2024 04:49:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712231393; x=1712836193; 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=mzV7bmg3PRLALaaFv1RRGYLnCVfom7cRGx1C8pOQ9QY=; b=BhytfXx9GG0e50tnKJfRON8u4aPsZ8NkE95QCeYrmBkv+3l37q+5IXHldeJV6NhJwd h6Okje4ynZ0WexB3PsTbX7Y1xwSFsNztOdSSslehQZbCAlSgSAbmiyYC+XxHwjXsi32H o5QyUl6Hk6nO6v6ld1mX+QGEuWA/EQuQVTX60kJn+wp9vVqx4TIbNk9l/BeI8MrwXSwN yd4+kQfUXYfxL1b9FYYI74D+Scy+5nlgFkp8dCu6RfOPMFBwzHIjl5KGOcWhhqI1XfCR z58pMQEC9E0UQuYKaR2rQ4N4J6TGyudJtljLmi6kE7cBpYxOCEukGxuqeXey+p7M5tBX oD1w== X-Forwarded-Encrypted: i=1; AJvYcCXXrcnoTzGJdF/EghOY+AVG0UNwr3XGc9zhVR9hhKwFcAc65BrfOrNBZpO6liImR+aS0d2IB99QK6nsMX4YYezzLWIiYLL1gHodIdoSoq2VsjH/myrvGzyvy1vYBJ37vhiZgyIAPPHMy240N0uGYJO2fVOTuVHyDHY= X-Gm-Message-State: AOJu0YykghbMSsLatuBNnbgNCjYFaIDQd/b6/sLQn60VQ5F7RCVOaYUJ lTBG4+E1Qe0ljWZ+HDZ1oBsC3XKzbxmhoirWz0V94XsQNiPxu3Mc X-Google-Smtp-Source: AGHT+IFRwr8UkzCF3v1iCbSD58Cp7LdwDT3piXnSVvqDLYvXsgnwdp2m56Bo2luANSx21b/6GTr9Pw== X-Received: by 2002:a17:906:3017:b0:a4e:23a1:9ede with SMTP id 23-20020a170906301700b00a4e23a19edemr1357499ejz.36.1712231392669; Thu, 04 Apr 2024 04:49:52 -0700 (PDT) Received: from localhost (fwdproxy-lla-004.fbsv.net. [2a03:2880:30ff:4::face:b00c]) by smtp.gmail.com with ESMTPSA id i3-20020a170906a28300b00a4e2f966196sm7943347ejz.86.2024.04.04.04.49.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 04:49:52 -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 Cc: quic_jjohnson@quicinc.com, kvalo@kernel.org, leon@kernel.org, dennis.dalessandro@cornelisnetworks.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, Jiri Pirko , Simon Horman , Daniel Borkmann , Sebastian Andrzej Siewior Subject: [PATCH net-next v3 1/5] net: create a dummy net_device allocator Date: Thu, 4 Apr 2024 04:48:41 -0700 Message-ID: <20240404114854.2498663-2-leitao@debian.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240404114854.2498663-1-leitao@debian.org> References: <20240404114854.2498663-1-leitao@debian.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240404_124957_824723_93FD6F43 X-CRM114-Status: GOOD ( 19.10 ) X-BeenThere: linux-mediatek@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-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org It is impossible to use init_dummy_netdev together with alloc_netdev() as the 'setup' argument. This is because alloc_netdev() initializes some fields in the net_device structure, and later init_dummy_netdev() memzero them all. This causes some problems as reported here: https://lore.kernel.org/all/20240322082336.49f110cc@kernel.org/ Split the init_dummy_netdev() function in two. Create a new function called init_dummy_netdev_core() that does not memzero the net_device structure. Then have init_dummy_netdev() memzero-ing and calling init_dummy_netdev_core(), keeping the old behaviour. init_dummy_netdev_core() is the new function that could be called as an argument for alloc_netdev(). Also, create a helper to allocate and initialize dummy net devices, leveraging init_dummy_netdev_core() as the setup argument. This function basically simplify the allocation of dummy devices, by allocating and initializing it. Freeing the device continue to be done through free_netdev() Suggested-by: Jakub Kicinski Signed-off-by: Breno Leitao --- include/linux/netdevice.h | 3 +++ net/core/dev.c | 54 ++++++++++++++++++++++++++------------- 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 0c198620ac93..544767d218c0 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -4517,6 +4517,9 @@ static inline void netif_addr_unlock_bh(struct net_device *dev) void ether_setup(struct net_device *dev); +/* Allocate dummy net_device */ +struct net_device *alloc_netdev_dummy(int sizeof_priv); + /* Support for loadable net-drivers */ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name, unsigned char name_assign_type, diff --git a/net/core/dev.c b/net/core/dev.c index 818699dea9d7..4d0109f2fe80 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -10412,25 +10412,12 @@ int register_netdevice(struct net_device *dev) } EXPORT_SYMBOL(register_netdevice); -/** - * init_dummy_netdev - init a dummy network device for NAPI - * @dev: device to init - * - * This takes a network device structure and initialize the minimum - * amount of fields so it can be used to schedule NAPI polls without - * registering a full blown interface. This is to be used by drivers - * that need to tie several hardware interfaces to a single NAPI - * poll scheduler due to HW limitations. +/* Initialize the core of a dummy net device. + * This is useful if you are calling this function after alloc_netdev(), + * since it does not memset the net_device fields. */ -void init_dummy_netdev(struct net_device *dev) +static void init_dummy_netdev_core(struct net_device *dev) { - /* Clear everything. Note we don't initialize spinlocks - * are they aren't supposed to be taken by any of the - * NAPI code and this dummy netdev is supposed to be - * only ever used for NAPI polls - */ - memset(dev, 0, sizeof(struct net_device)); - /* make sure we BUG if trying to hit standard * register/unregister code path */ @@ -10451,8 +10438,28 @@ void init_dummy_netdev(struct net_device *dev) * its refcount. */ } -EXPORT_SYMBOL_GPL(init_dummy_netdev); +/** + * init_dummy_netdev - init a dummy network device for NAPI + * @dev: device to init + * + * This takes a network device structure and initialize the minimum + * amount of fields so it can be used to schedule NAPI polls without + * registering a full blown interface. This is to be used by drivers + * that need to tie several hardware interfaces to a single NAPI + * poll scheduler due to HW limitations. + */ +void init_dummy_netdev(struct net_device *dev) +{ + /* Clear everything. Note we don't initialize spinlocks + * are they aren't supposed to be taken by any of the + * NAPI code and this dummy netdev is supposed to be + * only ever used for NAPI polls + */ + memset(dev, 0, sizeof(struct net_device)); + init_dummy_netdev_core(dev); +} +EXPORT_SYMBOL_GPL(init_dummy_netdev); /** * register_netdev - register a network device @@ -11063,6 +11070,17 @@ void free_netdev(struct net_device *dev) } EXPORT_SYMBOL(free_netdev); +/** + * alloc_netdev_dummy - Allocate and initialize a dummy net device. + * @sizeof_priv: size of private data to allocate space for + */ +struct net_device *alloc_netdev_dummy(int sizeof_priv) +{ + return alloc_netdev(sizeof_priv, "dummy#", NET_NAME_UNKNOWN, + init_dummy_netdev_core); +} +EXPORT_SYMBOL_GPL(alloc_netdev_dummy); + /** * synchronize_net - Synchronize with packet receive processing * From patchwork Thu Apr 4 11:48:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13617816 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 48FD5CD1284 for ; Thu, 4 Apr 2024 13:04:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=6rK4LbBslMJoYxe1V0vNkJlOAiQK9SERrvEQRmx4wfo=; b=qOzEVhoH0s/OQeLSNHr21p0cCK o+7u/GRGhk1l+9AwtxxuvI9TPAY/AX1Ws4YUuuzPMQeKXw410SfLB2i6ms8FG2L0ivsyXvYDzVmHP v3Ig6RB9M3hz/zkR4S5XsQ9Eu+tYm+t4Oe550dcjhsJ+uQOMbg3Z5egni6Rpv4/W+I687d/N2IE7o sNE+7TNuQmYqQE/QhELqrSd72400Tb2ABInUyKdWEhFb2tCpoeFfrzlooTJvFXmK7KhQ5OEKajcK0 TS6IJv5faKKCdS51xvwLA6qNRI1OYV/MU8ZebbcgII6NtqKF6d8fe7VZ2ha8UIS/aq8cPVi1K9E4r npvSKtxg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rsMlj-00000002ksd-3YtE; Thu, 04 Apr 2024 13:04:39 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rsLbV-00000002ROe-3DD8; Thu, 04 Apr 2024 11:50:01 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=6rK4LbBslMJoYxe1V0vNkJlOAiQK9SERrvEQRmx4wfo=; b=mvPGWvJZKSlWgH6OKngbhHM28Z pZLYfLSmyE9LcWkpUPLFd/FhV1vq24gZpLcIxo5l3T0KdV5QGiEQ0B01oAqJIs6r4tTYbIwA9jUKU V4oQY8u+4Fz5nfszOVhHkOt7nkZIz81ucUPO0WoqKsEzMPoOY6+DHoecYdh6N2bZx+8qifzruuyE7 NMKPNdDI3lerVHgozwnay6+Zh5vNAwe8QpL9D/sJfDcI2VJ3sD0zXDzFNfHo+g4l+pZLBvgwIUUwA D0UaZjcK1CGvGrNzNMljalgb52YmR40X5fVQeKQF1Sazdcbs5AVRAdCoIU6BiGX548KwTU/0w64qb +MJj+Yxw==; Received: from mail-ej1-f45.google.com ([209.85.218.45]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rsLbR-0000000504G-0A5U; Thu, 04 Apr 2024 11:50:00 +0000 Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-a5193f56986so33048266b.0; Thu, 04 Apr 2024 04:49:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712231395; x=1712836195; 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=6rK4LbBslMJoYxe1V0vNkJlOAiQK9SERrvEQRmx4wfo=; b=Blq++injDubdNyC1aoCl6JSXmxE3O6gpUPChGQClmZZh8+QuVOS0ISdLVX0rypGQBK +sdwfoiEJkW6yOmYksD7/ULLlfD/4iFj/n+qDzvRSofVV8mEtkqucFmP/HIEzkngIh5p siX4dbvDjUa4v3d8MU5YuaKoW/3YtBIc8pRPRpRajZYNE0KM87vPrEmdk5E25MUVtK4m cNRD1AI5mAkBgC4JqEj6vPpYQEf56bIHJgbCqYHFrIXpI7EX5+arUuHrYrxWSCNVDYER PCLBW6/ghPGKT3O399s9HzQnHWLsa1yXArw84cRI/rpLyTl5m8ruYSNp/5n6pkGEVc9+ eL1g== X-Forwarded-Encrypted: i=1; AJvYcCXdo3UwBkKnzOJxbBnca0t6BK+Ch6rd1vl/lm2URaMPIBZAvLiegR2WJYBVlY8iK4zkN1vpqxZtj04TKejUmUFcz3fjjkNnWOPGVI6DpIgrhRfAwEXSJbykHNto9JLIEvLzTdFNu0Kwz7s6TOZBAKZ/4AXD1aJ+E6M= X-Gm-Message-State: AOJu0YxkZs/g3IRl7QsEQ1k1X2ZCjDsxAkkitcxm3MJ/ntICIZKP/2b2 IN5vxaNeN/NHqVcvgiz1lnDJPuVORKBeAe4ZqsN/d/uPSMUohPpB X-Google-Smtp-Source: AGHT+IFiS9SjmfSMSBb39k+37Klq9CVWs+kxx7A6ljynarXFtE2kNTHt2mNLj4dlY5GiGWVD+iOD9w== X-Received: by 2002:a17:906:f859:b0:a4e:8a80:92ed with SMTP id ks25-20020a170906f85900b00a4e8a8092edmr1450248ejb.39.1712231394724; Thu, 04 Apr 2024 04:49:54 -0700 (PDT) Received: from localhost (fwdproxy-lla-008.fbsv.net. [2a03:2880:30ff:8::face:b00c]) by smtp.gmail.com with ESMTPSA id wg8-20020a17090705c800b00a4722439646sm8893849ejb.117.2024.04.04.04.49.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 04:49:54 -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 Cc: quic_jjohnson@quicinc.com, kvalo@kernel.org, leon@kernel.org, dennis.dalessandro@cornelisnetworks.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH net-next v3 2/5] net: marvell: prestera: allocate dummy net_device dynamically Date: Thu, 4 Apr 2024 04:48:42 -0700 Message-ID: <20240404114854.2498663-3-leitao@debian.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240404114854.2498663-1-leitao@debian.org> References: <20240404114854.2498663-1-leitao@debian.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240404_124957_861428_81BCBB29 X-CRM114-Status: GOOD ( 11.70 ) X-BeenThere: linux-mediatek@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-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=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 --- .../net/ethernet/marvell/prestera/prestera_rxtx.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/marvell/prestera/prestera_rxtx.c b/drivers/net/ethernet/marvell/prestera/prestera_rxtx.c index cc2a9ae794be..39d9bf82c115 100644 --- a/drivers/net/ethernet/marvell/prestera/prestera_rxtx.c +++ b/drivers/net/ethernet/marvell/prestera/prestera_rxtx.c @@ -96,7 +96,7 @@ struct prestera_sdma { struct dma_pool *desc_pool; struct work_struct tx_work; struct napi_struct rx_napi; - struct net_device napi_dev; + struct net_device *napi_dev; u32 map_addr; u64 dma_mask; /* protect SDMA with concurrent access from multiple CPUs */ @@ -654,13 +654,21 @@ static int prestera_sdma_switch_init(struct prestera_switch *sw) if (err) goto err_evt_register; - init_dummy_netdev(&sdma->napi_dev); + sdma->napi_dev = alloc_netdev_dummy(0); + if (!sdma->napi_dev) { + dev_err(dev, "not able to initialize dummy device\n"); + err = -ENOMEM; + goto err_alloc_dummy; + } - netif_napi_add(&sdma->napi_dev, &sdma->rx_napi, prestera_sdma_rx_poll); + netif_napi_add(sdma->napi_dev, &sdma->rx_napi, prestera_sdma_rx_poll); napi_enable(&sdma->rx_napi); return 0; +err_alloc_dummy: + prestera_hw_event_handler_unregister(sw, PRESTERA_EVENT_TYPE_RXTX, + prestera_rxtx_handle_event); err_evt_register: err_tx_init: prestera_sdma_tx_fini(sdma); @@ -677,6 +685,7 @@ static void prestera_sdma_switch_fini(struct prestera_switch *sw) napi_disable(&sdma->rx_napi); netif_napi_del(&sdma->rx_napi); + free_netdev(sdma->napi_dev); prestera_hw_event_handler_unregister(sw, PRESTERA_EVENT_TYPE_RXTX, prestera_rxtx_handle_event); prestera_sdma_tx_fini(sdma); From patchwork Thu Apr 4 11:48:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13617619 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 64FDACD1292 for ; Thu, 4 Apr 2024 11:50:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=bGHHnAjzHXOHKZAHNwNt7Xm//rgfn0lSUB+nM5VysgU=; b=KORO7tSAykufsjBExhzEb/qdkz uzDQfaBWJ0B5WGlGh1SU1Ss/udzvXlX9lUPwym07JO+a17GGtVid1q7TYaD3JrXbQPBsoILhjks2m VM6ChzCyOoABZ90BS3orwL1ZN+7P3rOpJk2PdfubturwRPiyjJRf5AJpApE3Q05hBBTsXja8NJOFr h3cHrJX6lrVHV+srzBD4+W271D78G+szbBQoLtnxvYN2/1TtQl6Y89v8CNipcHgk2q9TzWi0aDGQ8 BZT+Dy1NkUd67QsAv20eJKfMC/S67UpVogNZpjok1NeWfpA4fVbp//Oj3RMIjce9uXUwdGvBJ996N qOw6JqiA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rsLbl-00000002RXb-319X; Thu, 04 Apr 2024 11:50:17 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rsLbW-00000002ROh-14ch; Thu, 04 Apr 2024 11:50:02 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=bGHHnAjzHXOHKZAHNwNt7Xm//rgfn0lSUB+nM5VysgU=; b=MK5pPAYEcUrBo1VXVgphWilkKU Yn2u6241mq8q0XrJlAG867LgwgfVVgMaXz2p6bOwjQdKFZNI+Tet90KLDOU1aiWQ61WuAt3n83Yln J5A3+PdJUyxaT2CImh9v60JxNr/o7w09QBybRl6nP3UiKGCbspzj5rPuxYqbBkQWEzGhW+vQE0dpQ M71Iou2d6PtTPQcpa9Nc9U1ZV/QJZ9fWLGoeEuUCJI/o/dMMR/jd3ia7G1mjrj+MXmynBCXsK25Su e9a3l38WyWavZ832EGX6acQNz1t7DYWdrINJSs/3Nwu2lEF7UOMIYmqiWZ5APKg1Bb1BiHbElCk6S GqvVaZDg==; Received: from mail-ej1-f53.google.com ([209.85.218.53]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rsLbR-0000000504a-2oqe; Thu, 04 Apr 2024 11:50:00 +0000 Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-a4715991c32so135007666b.1; Thu, 04 Apr 2024 04:49:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712231396; x=1712836196; 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=H8Zu+B7M9Vg3rxLoeGZhW4va7hzaBqgUAheWp9Mky6hAA+QFwd+7JbapPKQe/rr18u an4CWk//+cUyDI3D1yH8AMSTPzcbiETU8KvG+NBWbN84mK9R1M5HJbh/bjLijKm6rDVi vtdwiz7Lsot3r3qOP854Wr5FS8pUsjs430P7r6N7rV2LOH2vLiyLn5P3Ax82ZicVbE7w 61sb2AkZL62uPmqVFQ4crnU+h6Epeb1V6eQxU9W9AA+3eMdbYZsM8rUKceATT3w3gwmR 1rYVR8v1W8LNwAj1xH2C/MdufvDb3dWkXHJYBpE2tWFPjmaxS1fPtQTjHaRE1rm65rOV 5Kbg== X-Forwarded-Encrypted: i=1; AJvYcCXNVCSd5h00EQknP5rJOKmaQcVTJA4gn5rOAkkecPS5ah+8bozIa5RKt/91kdttGlmofm3Omz+nqBb8zjwECCq6tQs/2vq3kzadzYEweCR0dTqkBoa7kZfS5RYV3yYcN6Rgk7bZmu00VY+o4wXVjk1Zmch18wLDI5M= X-Gm-Message-State: AOJu0Yz1WtiNUhO6EEkxKpydQrls6nc7QIIw407EgED1Gs/tgRUDtUdN KZ4khdmKSa8nQRm19SxVBPymw9OP8HWliruJxe/2FXf31EWrxz8z X-Google-Smtp-Source: AGHT+IE3t+BLSiVw4qYEsUV6AW+ru3gx9jWHG3rLtC0+vGDymiwEFCGXCLHQkfj2msACqNOeoyP0iw== X-Received: by 2002:a17:906:268b:b0:a4e:6414:5afd with SMTP id t11-20020a170906268b00b00a4e64145afdmr1390682ejc.52.1712231396634; Thu, 04 Apr 2024 04:49:56 -0700 (PDT) Received: from localhost (fwdproxy-lla-007.fbsv.net. [2a03:2880:30ff:7::face:b00c]) by smtp.gmail.com with ESMTPSA id wy11-20020a170906fe0b00b00a4e4a3e69acsm6635185ejb.71.2024.04.04.04.49.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 04:49:56 -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, Matthias Brugger , AngeloGioacchino Del Regno , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend Cc: quic_jjohnson@quicinc.com, kvalo@kernel.org, leon@kernel.org, dennis.dalessandro@cornelisnetworks.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH net-next v3 3/5] net: mediatek: mtk_eth_sock: allocate dummy net_device dynamically Date: Thu, 4 Apr 2024 04:48:43 -0700 Message-ID: <20240404114854.2498663-4-leitao@debian.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240404114854.2498663-1-leitao@debian.org> References: <20240404114854.2498663-1-leitao@debian.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240404_124958_490137_95BF0819 X-CRM114-Status: GOOD ( 15.73 ) X-BeenThere: linux-mediatek@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-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=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]; From patchwork Thu Apr 4 11:48:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13617620 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 3BCADCD1296 for ; Thu, 4 Apr 2024 11:50:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Ui1DJxKv+GCSubTCimqVqNTb9BwhV0yVlSdcCwIQq1A=; b=IE+mbTwtn8KaDmRxFL+9Zjfrbg x7IeUcpjLM7VVCuIIGWfMC0Hv7tS77EyXht/Y/oJK6xkwOfcvPM/x0LkFGFx9PyOxNAo9nqCTe22C WDe8glh0HZqiSAJ/1gO1SXdZQXKDTIzi2uxRjda5KUXzCcyk8Sdy1sR8O/pKTNKVKhQpxCHvPP5Le 0ich9jXLT8ssK0eFJmSnRuTzU6z6uKBVKur9tUA6oY6/8DdPieqgdsaJHDxrEZ2e5dmGtgetEFd18 5ViKO9xqUGHQOxGcimUfEProZccR7Hm3rxXrlR1+X26s0jsC8alitVibivG9WD7avLzEk3SN+XUTM TlzqVUtQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rsLbm-00000002RYA-1q4l; Thu, 04 Apr 2024 11:50:18 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rsLbY-00000002RQq-1rRG; Thu, 04 Apr 2024 11:50:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=Ui1DJxKv+GCSubTCimqVqNTb9BwhV0yVlSdcCwIQq1A=; b=AnkMn9PuQY2oSFnGDGyESWVl5j 3OKKj/T0vZA9GgV0weG7ZorZ5noSsL6QVikrXCpXkwTCCp388i3RdbZgFCGslJLjhFOqTaGNJr/NS gM79c05E35xiFjyzvurkbyBGlfnPkt5pyp00/G9aLqPDFHiqP16d5jXTKu7879Zt1QyyKapFbXfJv A+R9QNoLxgmoxKxZ5zFoVw37KLmoRePlIkTiDVKTSr9kPeQLhAygRz4/1PIcWazKBRvWbxJhHAxbm aa0CxJe2UI9wM0sdxeBtFyarkB132f99WX+DvcOrKrTBH5HWOUChnSFuqk2ZZ1f4yAhSjHvK1GkBR Q3i6vmZg==; Received: from mail-ed1-f46.google.com ([209.85.208.46]) by casper.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rsLbU-00000007xHW-3NOv; Thu, 04 Apr 2024 11:50:03 +0000 Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-565c6cf4819so3550687a12.1; Thu, 04 Apr 2024 04:49:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712231398; x=1712836198; 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=Ui1DJxKv+GCSubTCimqVqNTb9BwhV0yVlSdcCwIQq1A=; b=JLia5ir6NyvBvVjyCULqTq8Xz6rkNWtGaHmFGx1EY4ZvIECKCWU4F+ZRh2OVCXNexP u0F/nR2rmtY5NdAYVNk2lHWjTx7LdrPCeG+RMR4UcdzESrrkHaPmkVhSZ/Vt/AeYIttZ T0EFsbZ7EQGyENx3rqEXWS1zAwVKkUo046eIQDSeDQU9ufoEnhCax79NDdgMEMl/ElY7 zFvoeUsKPhEyvdgx220bLhS0K3DETfEPcmNCDT7ixVlXnnXDAq0piRQN5sCZWQzNI54C jyRv0c/ZwIeiO7+rt0htHHtOPhvhaKPy4t3XbCdgq8SfZn0ZVnDEoA37QuujcOetg1fD M4nQ== X-Forwarded-Encrypted: i=1; AJvYcCUipFX0epa9XLs2kGPtP4kipm/Qo5p2g6eF00exy1VMoKxVBlLv0Irs9z3x0fbemZ7czIbOfPQfu3W1SeTSS8Zdokkjy11lJtbcSctkcunrqBVjAfjFjI0SHGgpylHFpSq+ZS5+Y/CqypCXbT9U0ebY+Tsd1urBxTY= X-Gm-Message-State: AOJu0YxSOszm1Uoo4xwMcAwVmrfXC1R1wM6bnY4NlZT9DvNfXURdRqsA hhRoNFI0alBJwcLABI2AJULm1JiFuZyb0SqOYF4stxasc8qlJOhSZaMm7MNY X-Google-Smtp-Source: AGHT+IGR/2cl7VV3Nm0oPydh1R3stQjygMPvAFpJJaxHSUjjTaaXgqGOaWjKnswlTpZmIr4PxMZ4eA== X-Received: by 2002:a17:906:d9c5:b0:a51:964f:c3e4 with SMTP id qk5-20020a170906d9c500b00a51964fc3e4mr178315ejb.5.1712231398570; Thu, 04 Apr 2024 04:49:58 -0700 (PDT) Received: from localhost (fwdproxy-lla-116.fbsv.net. [2a03:2880:30ff:74::face:b00c]) by smtp.gmail.com with ESMTPSA id wk8-20020a170907054800b00a4e2d7dd2d8sm8166265ejb.182.2024.04.04.04.49.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 04:49:58 -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 Cc: quic_jjohnson@quicinc.com, kvalo@kernel.org, leon@kernel.org, dennis.dalessandro@cornelisnetworks.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH net-next v3 4/5] net: ipa: allocate dummy net_device dynamically Date: Thu, 4 Apr 2024 04:48:44 -0700 Message-ID: <20240404114854.2498663-5-leitao@debian.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240404114854.2498663-1-leitao@debian.org> References: <20240404114854.2498663-1-leitao@debian.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240404_125000_863281_2A6FB03D X-CRM114-Status: GOOD ( 12.97 ) X-BeenThere: linux-mediatek@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-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=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/ipa/gsi.c | 12 ++++++++---- drivers/net/ipa/gsi.h | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/net/ipa/gsi.c b/drivers/net/ipa/gsi.c index 9a0b1fe4a93a..d70be15e95a6 100644 --- a/drivers/net/ipa/gsi.c +++ b/drivers/net/ipa/gsi.c @@ -1730,10 +1730,10 @@ static int gsi_channel_setup_one(struct gsi *gsi, u32 channel_id) gsi_channel_program(channel, true); if (channel->toward_ipa) - netif_napi_add_tx(&gsi->dummy_dev, &channel->napi, + netif_napi_add_tx(gsi->dummy_dev, &channel->napi, gsi_channel_poll); else - netif_napi_add(&gsi->dummy_dev, &channel->napi, + netif_napi_add(gsi->dummy_dev, &channel->napi, gsi_channel_poll); return 0; @@ -2369,12 +2369,14 @@ int gsi_init(struct gsi *gsi, struct platform_device *pdev, /* GSI uses NAPI on all channels. Create a dummy network device * for the channel NAPI contexts to be associated with. */ - init_dummy_netdev(&gsi->dummy_dev); + gsi->dummy_dev = alloc_netdev_dummy(0); + if (!gsi->dummy_dev) + return -ENOMEM; init_completion(&gsi->completion); ret = gsi_reg_init(gsi, pdev); if (ret) - return ret; + goto err_reg_exit; ret = gsi_irq_init(gsi, pdev); /* No matching exit required */ if (ret) @@ -2389,6 +2391,7 @@ int gsi_init(struct gsi *gsi, struct platform_device *pdev, return 0; err_reg_exit: + free_netdev(gsi->dummy_dev); gsi_reg_exit(gsi); return ret; @@ -2399,6 +2402,7 @@ void gsi_exit(struct gsi *gsi) { mutex_destroy(&gsi->mutex); gsi_channel_exit(gsi); + free_netdev(gsi->dummy_dev); gsi_reg_exit(gsi); } diff --git a/drivers/net/ipa/gsi.h b/drivers/net/ipa/gsi.h index 42063b227c18..6b7ec2a39676 100644 --- a/drivers/net/ipa/gsi.h +++ b/drivers/net/ipa/gsi.h @@ -155,7 +155,7 @@ struct gsi { struct mutex mutex; /* protects commands, programming */ struct gsi_channel channel[GSI_CHANNEL_COUNT_MAX]; struct gsi_evt_ring evt_ring[GSI_EVT_RING_COUNT_MAX]; - struct net_device dummy_dev; /* needed for NAPI */ + struct net_device *dummy_dev; /* needed for NAPI */ }; /** From patchwork Thu Apr 4 11:48:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13617621 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 EA8BBCD1292 for ; Thu, 4 Apr 2024 11:50:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=CsBGQlMm+F00sLCL/qlkhF4TnT6nst/CdHn7pOQlov8=; b=wNziIsI+P9WxBjw5s7jwxxzPd/ 9xbQEWAGj4uO3J83wT3vE0p76AVdFHGdHnTlWuq+OTsqVTxK+/le6oukaqfNyHx8tVGxrr60fm85d 1h0FtHj9UIAIMOOqYJETLQXCyw4LnbC6UwGIixIuv/glrGZ/lRJixpsma7T34HMYtX+mxAOrYFugL mbYcx3jIDTzNlSUxCKT//U1IqNra9ddv59Fuo2LnjKVHL8waxrCrXJIkNLG0nGPVdrSoj0HBJvjr3 iTRUKoET7lBD8AQ5YMTDzSk8Osbvm00IPdr27u+frmT6CBz3EFNkZmh/5xKnWDXWl0lM7694I/+Zu iy8wHkfg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rsLbz-00000002RjE-1Ve2; Thu, 04 Apr 2024 11:50:31 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rsLbm-00000002RXO-0F1K; Thu, 04 Apr 2024 11:50:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=CsBGQlMm+F00sLCL/qlkhF4TnT6nst/CdHn7pOQlov8=; b=j84fBuYSvCAW68x0F800Qs+QMu NLsl49UE1tUmPYbhG14lW2w6EdmBA72SXzh6LDFFw5Bj0HV0a/ClVatzpxUcpbJVp8Etp+8HIWf5m PWLNVcPOiQh+0L6QMdX3bIfvxYGLZXPwlYXVnWx03JogAapuz0Z4tvLUju+HpJwyesiKlWpory3Si H4i5AWSUPqkHB6jGJJcr2yndT8gsDuCVGU9gS2RT/dOAKfGjE4+kwXilhkxDjsmF39Q2VwovCOz/L Mj6SBMMbu40a8OJHUwnpjjWROWBzcpR+2SSvSOPwqJeiElUVLEpX1UKn2+imrIxVxtl9LLc8Az/iT 7oWTdgKg==; Received: from mail-ej1-f50.google.com ([209.85.218.50]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rsLbZ-00000005081-1Ann; Thu, 04 Apr 2024 11:50:07 +0000 Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-a51969e780eso12639066b.3; Thu, 04 Apr 2024 04:50:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712231404; x=1712836204; 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=CsBGQlMm+F00sLCL/qlkhF4TnT6nst/CdHn7pOQlov8=; b=C3AwvcFcjzLQNY63Rb016s180GtNhO5bNr5d7NCuS7hvLqkq8M16Mm/sTM+ekbMdi2 6gJ29OjomAjsMviKLpB7OiU8EmSASqfS7yt2dC0HtDuL/vtUEjI22Fs6Ep2KmQzf5+xr DnVT2OCyMS5h0TQCmXaclzrpHZ93xjlYq1zBYRF5+l8mmX5dzZ3IPH7e3f9dYlrcCRwN dWVW1BdUoi5IJ7C3fz6w0zC0p67ptPChX0TyxMdl6aNJJD2iSSLr/Kc3YPIEuoG88Kqf 07ScG/lfZ/WS5u6CLiFUr34S7RRfbLOvg2XvXFKUsReScZ8XFtD0PXvoGPxrukg/LVMe 6tOQ== X-Forwarded-Encrypted: i=1; AJvYcCVJJggslAsRAORaQQTS2hCKa46WrgMeWdcJls9hCJWlaGnfJNnzEEiBFxAddEBdvD5snNr9Q9zOxeb9QFfc2NfNzgQeQqFgvq4f7PRRQ+nm9jPZGTJYn4txaMhCX+CqAGe4OvjCTj0HB30+Dr8umsHCXXyaPezE1MU= X-Gm-Message-State: AOJu0YwOyjB8SqCCeUxJuL1SuwCE60tVknMBOWudpj6xui8Bv8nNukh8 i2xLnSHAoa0Kx1N5TTEbE9GicSrMXRyXKBjrX9Cypw+IxCjxgniA X-Google-Smtp-Source: AGHT+IHFg0zyk2NS23/A1etHV8JcM7ibRi4errBqUEIZrG9N7OZjtPtXrBCEmEH5SFyOsilQGUWU4Q== X-Received: by 2002:a17:906:22d6:b0:a51:9449:6fa1 with SMTP id q22-20020a17090622d600b00a5194496fa1mr328854eja.15.1712231404025; Thu, 04 Apr 2024 04:50:04 -0700 (PDT) Received: from localhost (fwdproxy-lla-119.fbsv.net. [2a03:2880:30ff:77::face:b00c]) by smtp.gmail.com with ESMTPSA id wz5-20020a170906fe4500b00a4e7a0a1c04sm4030319ejb.110.2024.04.04.04.50.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 04:50:03 -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 Cc: quic_jjohnson@quicinc.com, kvalo@kernel.org, leon@kernel.org, dennis.dalessandro@cornelisnetworks.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, Simon Horman , Rob Herring , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Christian Marangi Subject: [PATCH net-next v3 5/5] net: ibm/emac: allocate dummy net_device dynamically Date: Thu, 4 Apr 2024 04:48:45 -0700 Message-ID: <20240404114854.2498663-6-leitao@debian.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240404114854.2498663-1-leitao@debian.org> References: <20240404114854.2498663-1-leitao@debian.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240404_125005_856887_67F5037F X-CRM114-Status: GOOD ( 13.23 ) X-BeenThere: linux-mediatek@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-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=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/ibm/emac/mal.c | 14 +++++++++++--- drivers/net/ethernet/ibm/emac/mal.h | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/ibm/emac/mal.c b/drivers/net/ethernet/ibm/emac/mal.c index 2439f7e96e05..d92dd9c83031 100644 --- a/drivers/net/ethernet/ibm/emac/mal.c +++ b/drivers/net/ethernet/ibm/emac/mal.c @@ -605,9 +605,13 @@ static int mal_probe(struct platform_device *ofdev) INIT_LIST_HEAD(&mal->list); spin_lock_init(&mal->lock); - init_dummy_netdev(&mal->dummy_dev); + mal->dummy_dev = alloc_netdev_dummy(0); + if (!mal->dummy_dev) { + err = -ENOMEM; + goto fail_unmap; + } - netif_napi_add_weight(&mal->dummy_dev, &mal->napi, mal_poll, + netif_napi_add_weight(mal->dummy_dev, &mal->napi, mal_poll, CONFIG_IBM_EMAC_POLL_WEIGHT); /* Load power-on reset defaults */ @@ -637,7 +641,7 @@ static int mal_probe(struct platform_device *ofdev) GFP_KERNEL); if (mal->bd_virt == NULL) { err = -ENOMEM; - goto fail_unmap; + goto fail_dummy; } for (i = 0; i < mal->num_tx_chans; ++i) @@ -703,6 +707,8 @@ static int mal_probe(struct platform_device *ofdev) free_irq(mal->serr_irq, mal); fail2: dma_free_coherent(&ofdev->dev, bd_size, mal->bd_virt, mal->bd_dma); + fail_dummy: + free_netdev(mal->dummy_dev); fail_unmap: dcr_unmap(mal->dcr_host, 0x100); fail: @@ -734,6 +740,8 @@ static void mal_remove(struct platform_device *ofdev) mal_reset(mal); + free_netdev(mal->dummy_dev); + dma_free_coherent(&ofdev->dev, sizeof(struct mal_descriptor) * (NUM_TX_BUFF * mal->num_tx_chans + diff --git a/drivers/net/ethernet/ibm/emac/mal.h b/drivers/net/ethernet/ibm/emac/mal.h index d212373a72e7..e0ddc41186a2 100644 --- a/drivers/net/ethernet/ibm/emac/mal.h +++ b/drivers/net/ethernet/ibm/emac/mal.h @@ -205,7 +205,7 @@ struct mal_instance { int index; spinlock_t lock; - struct net_device dummy_dev; + struct net_device *dummy_dev; unsigned int features; };