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: 13617628 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 F3463CD1296 for ; Thu, 4 Apr 2024 11:50:27 +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=h8OzLl8UmHs8AhO/XA10kj6AKZycqwPc5gRxhGBw1x4=; b=izutcr4p6dOqa9 UU2EiJHqiD1zsaGQWVA9OxYX8ljiL4mFTFIIZkPE5dsJYoWDxRN5c6n90gF08ntFRrOrXTtiBjN58 0t+/XscpqxceiB2PoK0MVcC3zZ6De1+KAMB6fskvWdZWMsOsin1Q/hxMCu+ex8lqLqKmSbqVppxHB hwBVtyLc/6AfHQY6wFsxgXFzNwpMqaTiLGhw4mfm55G5iBIVlttJ0lkS3bfHniRQEtMUPDLjdlOhr mEnr1EvkTUpLexAF3emE0mnJ1lB4CipsSWBXtnc3ybTCCNpqixq+WyH4v3nY0Xq3USQ3zMbL11+hz kq+HhC1g7o9/3+0y5uDA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rsLbg-00000002RUV-0e7p; Thu, 04 Apr 2024 11:50:12 +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-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 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: 13617829 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 C491CCD1292 for ; Thu, 4 Apr 2024 13:04:48 +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=eabOqvMj7PCOjLZM2UifmBR94iWJnMfEoS5bigE0VW0=; b=LGJPK+8nRHpnI1 8Bh/spKN5NTgzAzjFuEYcF8f0nwypU8TidRP59NABvQViORgd9KRg9pP+evRKEKM1B8QKKl8nbTZC Y0+G9JXJxZlLOk5GbU5KUGGIETPyrzfRwsY0Q2QypvC7tdbIlnmRduAflQVrvgz1lkovNQXZR0K+X +EzlktQOCWzDaYtqMV5CcsPuxD8QNhDz41iQxmlFMv9EFkT8vVz2gl9jMUEUQoQ4wulmDFrOlQ+v3 H/PN9WYn16K2kgdbmWY6mShS6g50aUpL7DMvNtCatfjNTWXjlFES5vbF6BtiiwfIAF0BNY0oY8BWy ZgJHvmdzGZXhUhXROrpA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rsMli-00000002krE-0vgK; Thu, 04 Apr 2024 13:04:38 +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-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 --- .../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: 13617627 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 2ADD8CD1292 for ; Thu, 4 Apr 2024 11:50:26 +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=HA72XYDtkiE007 RN2MBV4i6hHF+jtuyNvvk3ZXn3aj0+783thGfvfmhWqKcSmk5C+FOOnWkHxzRonQVaC7GFT0luwCB YSRZJzB+bCRcmaIUaOrZixmzphVOnNa5z8WxxM86ZMaQUqJeVB9eV19dW3nB+0yDcO+olI8z4yF1t z7RESUEY09QJyiZ7PhTcOrJrrvwHySUzp/Q5v0YmJF6xLnaepYVYvemf3mh46DOLCvRzHJx4ULvnq UKi6dBLOEmgYzCx9aWrUNv6KIxuSuusxbHvXxPJFeAUkGXQnlMH6XE1C/ybpMB4vqerIiwqCbXYrz rFiEzgMSt0HBT+G7R5dA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rsLbh-00000002RV3-2Nh6; Thu, 04 Apr 2024 11:50:13 +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-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]; 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: 13617629 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 4ADD2CD1296 for ; Thu, 4 Apr 2024 11:50:31 +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=VFZ4XpxXl62dVsy7qJmxK18YPs05RO2E0kd0OE+zJK0=; b=B5+cq1LxCUBr0S +m3rUiGq+eetllIsSmoPyr/nA/UdkYeGMl6AZNbM6566VOaGiM6KWJIL5sUn2jj5m4sUSw9eNBpnv yPi3zti6Fql5JD9n4OCRrH4Zufripf/ua6nJ2vq7d0joUTcCJYq0+/BO0w/RzhbTgXDMLaUzqD/1C AYJKyFISkzpieXTgirTp2x0rmXdiM9w1TIqcr8QmnY8bxJZSXHGHxOTIqlrwIBtBQT6F6lQ/afkJA BurhZVY+Vvm9a6zvdFa0Npo2MyZoecYzqTsG88vgNPq0csUwuDn6x6UY9B7KeT+RZbQCGI8tzpUOL uS1CX0NiZpEW1n3pumUQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rsLbk-00000002RWU-0hUM; Thu, 04 Apr 2024 11:50:16 +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-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/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: 13617630 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 11C46CD1292 for ; Thu, 4 Apr 2024 11:50:43 +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=MoYiEFV+E3taDdcNdqALuVhIejteldNK2Kb7HaDORRk=; b=b0kXh72egTRVCm 4b69OycCR0WCx/Fg7hT3SbF24MMNycrwRoegYghKyTK/b1hHWrAqwP5w0qyX1aBpaI4L58r298fUn 8kycoiQf7ZOseSvNDHErTQzxwws2n4W/seFvO7MylHkUtZezeUOK+BKeYFJ6l/D5Wc9G+i9qUPBTz dSH1v0gUs9WK/DebmRhAG7UobWYQ4uBeHddmXNTksLXRGoQ3HyEaqQlOyNbYZ94Hr2IvYuyni/MDy P0K90xMGJe9DC26tno3f0Ke2a4Ta4xkqIcfEzFEEQNEj4O7XRayVbGoJNrVpJcqU6Xqyi+9Oi4C64 IoibC/KcFfayhIErp45w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rsLbv-00000002Rg6-2rWx; Thu, 04 Apr 2024 11:50:28 +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-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/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; };