From patchwork Fri Oct 6 09:14:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nambiar, Amritha" X-Patchwork-Id: 13411146 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 079A94C94 for ; Fri, 6 Oct 2023 08:59:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="DUBCclaq" Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3CE983 for ; Fri, 6 Oct 2023 01:59:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696582749; x=1728118749; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DQt2517VgoAndIGYoyeWAclvB+eZPqWs+PgfLuN9Fm4=; b=DUBCclaq7/LrantORkXESAX8e8fSNeXAUxTgoZglh1cMPjZinRPlnapB sRen65nZODb0o+LPJvcOwl7wOy3bOjd0iJPk4VmwQC/mPX2Zu0xudP38C 2X1f7LDNTm3bkzZ3vYKU/kkI1HxVXm8Kbx9lgk0+vIwu22DiT9rEgIqaU vlUhD5W2pSjnO2tfOQ0JYoljhQxAqHen/b85U065m7fVp2FJpXTBTU+sA mlna/VD0NjTK65JRYXhfbcc5X9X/tSANtW5sCCtNgGk8T/uM9dZuvRuj5 1Qd5wLxjNpuL8/ZwXOEVqnFnV7AXfSVzsXpSBwXlEnI65WS7MxVik5FHJ Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10854"; a="447897864" X-IronPort-AV: E=Sophos;i="6.03,203,1694761200"; d="scan'208";a="447897864" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Oct 2023 01:59:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10854"; a="895813038" X-IronPort-AV: E=Sophos;i="6.03,203,1694761200"; d="scan'208";a="895813038" Received: from anambiarhost.jf.intel.com ([10.166.29.163]) by fmsmga001.fm.intel.com with ESMTP; 06 Oct 2023 01:57:34 -0700 Subject: [net-next PATCH v4 02/10] net: Add queue and napi association From: Amritha Nambiar To: netdev@vger.kernel.org, kuba@kernel.org Cc: sridhar.samudrala@intel.com, amritha.nambiar@intel.com Date: Fri, 06 Oct 2023 02:14:48 -0700 Message-ID: <169658368866.3683.5936758786055991674.stgit@anambiarhost.jf.intel.com> In-Reply-To: <169658340079.3683.13049063254569592908.stgit@anambiarhost.jf.intel.com> References: <169658340079.3683.13049063254569592908.stgit@anambiarhost.jf.intel.com> User-Agent: StGit/unknown-version Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org Add the napi pointer in netdev queue for tracking the napi instance for each queue. This achieves the queue<->napi mapping. Signed-off-by: Amritha Nambiar Reviewed-by: Sridhar Samudrala --- include/linux/netdevice.h | 5 +++++ include/net/netdev_rx_queue.h | 2 ++ net/core/dev.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index e070a4540fba..264ae0bdabe8 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -645,6 +645,8 @@ struct netdev_queue { #ifdef CONFIG_XDP_SOCKETS struct xsk_buff_pool *pool; #endif + /* NAPI instance for the queue */ + struct napi_struct *napi; /* * write-mostly part */ @@ -2619,6 +2621,9 @@ static inline void *netdev_priv(const struct net_device *dev) */ #define SET_NETDEV_DEVTYPE(net, devtype) ((net)->dev.type = (devtype)) +int netif_queue_set_napi(unsigned int queue_index, enum netdev_queue_type type, + struct napi_struct *napi); + /* Default NAPI poll() weight * Device drivers are strongly advised to not use bigger value */ diff --git a/include/net/netdev_rx_queue.h b/include/net/netdev_rx_queue.h index cdcafb30d437..2e65b03d214d 100644 --- a/include/net/netdev_rx_queue.h +++ b/include/net/netdev_rx_queue.h @@ -21,6 +21,8 @@ struct netdev_rx_queue { #ifdef CONFIG_XDP_SOCKETS struct xsk_buff_pool *pool; #endif + /* NAPI instance for the queue */ + struct napi_struct *napi; } ____cacheline_aligned_in_smp; /* diff --git a/net/core/dev.c b/net/core/dev.c index 606a366cc209..9b63a7b76c01 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -6394,6 +6394,40 @@ int dev_set_threaded(struct net_device *dev, bool threaded) } EXPORT_SYMBOL(dev_set_threaded); +/** + * netif_queue_set_napi - Associate queue with the napi + * @queue_index: Index of queue + * @type: queue type as RX or TX + * @napi: NAPI context + * + * Set queue with its corresponding napi context + */ +int netif_queue_set_napi(unsigned int queue_index, enum netdev_queue_type type, + struct napi_struct *napi) +{ + struct net_device *dev = napi->dev; + struct netdev_rx_queue *rxq; + struct netdev_queue *txq; + + if (!dev) + return -EINVAL; + + switch (type) { + case NETDEV_QUEUE_TYPE_RX: + rxq = __netif_get_rx_queue(dev, queue_index); + rxq->napi = napi; + break; + case NETDEV_QUEUE_TYPE_TX: + txq = netdev_get_tx_queue(dev, queue_index); + txq->napi = napi; + break; + default: + return -EINVAL; + } + return 0; +} +EXPORT_SYMBOL(netif_queue_set_napi); + void netif_napi_add_weight(struct net_device *dev, struct napi_struct *napi, int (*poll)(struct napi_struct *, int), int weight) {