From nobody Sat Feb 7 18:21:19 2026 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 83A1E20C00D; Fri, 25 Apr 2025 10:53:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745578440; cv=none; b=otahyHSF2TTVQdibUxFXo390h/sYPWK3ny0Rg+qjq4FZSQKp+4ctEMt1VnAr+z5mLT0uBtyk+sl1GRGWL9erQeBXDXLJZXIRx77uI+r03oGEpMgNrYTwMzcR7zhpeIwlKZ2zbykZ1m9/s6jQDPBjWMkZnOlHv9HnsBlSyFgK4cA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745578440; c=relaxed/simple; bh=2AZkdIkyg21yJJX6xmtAvk29MUvdsF3Y1TBzUwl65p4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=cJ7p8zINljdOaKRfYob8UL2Fh3E0xD8BYkHNW4cBVOC75TRbBEtPLCJ8JBD6nBFcGaKS8oupei7Mu//2vvFXOEXKsfZ6QN6EDbRqL6GIaUt7r6fYE+kGogG9NhUTOWj9sFZwEJiGpCRWQH9bCxMnuakgkyutRO6lOwlVwpHoyD0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=bC/2qPEe; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="bC/2qPEe" Received: by linux.microsoft.com (Postfix, from userid 1134) id 2654E2020957; Fri, 25 Apr 2025 03:53:59 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 2654E2020957 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1745578439; bh=wjWgDPCnELNadsZ7+gw9v/eGHhdmMPk6cFIpWvfy7OE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bC/2qPEe6+Tm+Q0Qq71Tmak2ma2YmEeuJ2BoikloFa6HQfH7WF6rzmG3PJHjDx7KV IQZVFj0kBErTLevPX0lZF0VFHLh1m9Y8ykEnp5HY39FkS/Kp/FWVaXq09IivEhuV1M 0MK/tciHh7AV5fuP6TOXGQjyUhUJfxveDDBe53yA= From: Shradha Gupta To: linux-hyperv@vger.kernel.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Nipun Gupta , Yury Norov , Jason Gunthorpe , Jonathan Cameron , Anna-Maria Behnsen , Shradha Gupta , Kevin Tian , Long Li , Thomas Gleixner , Bjorn Helgaas , Rob Herring , Manivannan Sadhasivam , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Lorenzo Pieralisi , Dexuan Cui , Wei Liu , Haiyang Zhang , "K. Y. Srinivasan" , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Konstantin Taranov , Simon Horman , Leon Romanovsky , Maxim Levitsky , Erni Sri Satya Vennela , Peter Zijlstra , netdev@vger.kernel.org, linux-rdma@vger.kernel.org, Paul Rosswurm Cc: Shradha Gupta Subject: [PATCH v2 1/3] PCI: Export pci_msix_prepare_desc() for dynamic MSI-X alloc Date: Fri, 25 Apr 2025 03:53:57 -0700 Message-Id: <1745578437-14878-1-git-send-email-shradhagupta@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1745578407-14689-1-git-send-email-shradhagupta@linux.microsoft.com> References: <1745578407-14689-1-git-send-email-shradhagupta@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" For supporting dynamic MSI-X vector allocation by PCI controllers, enabling the flag MSI_FLAG_PCI_MSIX_ALLOC_DYN is not enough, msix_prepare_msi_desc() to prepare the desc is also needed. Export pci_msix_prepare_desc() to allow PCI controllers to support dynamic MSI-X vector allocation. Signed-off-by: Shradha Gupta Reviewed-by: Haiyang Zhang Reviewed-by: Thomas Gleixner --- drivers/pci/msi/irqdomain.c | 5 +++-- include/linux/msi.h | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/pci/msi/irqdomain.c b/drivers/pci/msi/irqdomain.c index d7ba8795d60f..43129aa6d6c7 100644 --- a/drivers/pci/msi/irqdomain.c +++ b/drivers/pci/msi/irqdomain.c @@ -222,13 +222,14 @@ static void pci_irq_unmask_msix(struct irq_data *data) pci_msix_unmask(irq_data_get_msi_desc(data)); } =20 -static void pci_msix_prepare_desc(struct irq_domain *domain, msi_alloc_inf= o_t *arg, - struct msi_desc *desc) +void pci_msix_prepare_desc(struct irq_domain *domain, msi_alloc_info_t *ar= g, + struct msi_desc *desc) { /* Don't fiddle with preallocated MSI descriptors */ if (!desc->pci.mask_base) msix_prepare_msi_desc(to_pci_dev(desc->dev), desc); } +EXPORT_SYMBOL_GPL(pci_msix_prepare_desc); =20 static const struct msi_domain_template pci_msix_template =3D { .chip =3D { diff --git a/include/linux/msi.h b/include/linux/msi.h index 86e42742fd0f..d5864d5e75c2 100644 --- a/include/linux/msi.h +++ b/include/linux/msi.h @@ -691,6 +691,8 @@ struct irq_domain *pci_msi_create_irq_domain(struct fwn= ode_handle *fwnode, struct irq_domain *parent); u32 pci_msi_domain_get_msi_rid(struct irq_domain *domain, struct pci_dev *= pdev); struct irq_domain *pci_msi_get_device_domain(struct pci_dev *pdev); +void pci_msix_prepare_desc(struct irq_domain *domain, msi_alloc_info_t *ar= g, + struct msi_desc *desc); #else /* CONFIG_PCI_MSI */ static inline struct irq_domain *pci_msi_get_device_domain(struct pci_dev = *pdev) { --=20 2.34.1 From nobody Sat Feb 7 18:21:19 2026 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B4E8623F291; Fri, 25 Apr 2025 10:54:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745578463; cv=none; b=Td5NMK+WM8T8pC6L9drG1cm+laowe+dwz2DBXyIQfVwy6i/b65fi7Cu3pD1EoKXJR+BrE11RTP7Q40w2nQ6zrZJfQqQjyb8xB6vaH7N8u/Gf/bfDRibV7tLP6wddjNazOlghQcI4xvkicVMFmRviSdVDJ6tChjJAPTO53pC7IUY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745578463; c=relaxed/simple; bh=xm/l0LBXRRC3O+XjK4qdRF0SDIkwF7Yuz+CMVMni0+E=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=gT2+OJzBd7VNNt+mbfleOTrES8EaPzONWWY+3N6kz79+0SkH1JHrLwKc+SZohYhAlod3wW+LU5WOnOEMvRoziNPvDQGKpaG/tG21a0fnj+xc+hBa7x9LkSmLoCqAdSphFaA4UcR7bYWeyCCrx71iSTHinhJfzfBTXX2lrSeqhpA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=PBl4NX38; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="PBl4NX38" Received: by linux.microsoft.com (Postfix, from userid 1134) id 5A42B2020957; Fri, 25 Apr 2025 03:54:21 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 5A42B2020957 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1745578461; bh=Q1I1rZep87fjsOhFJmwl3GYR2qXH5ffLe7tbt73M3+c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PBl4NX38aGWJEZIBAbWLLX82b6xYx74arlGwbYrsu4r2sLrfwhz9kw4NfIow2gEGh hnIgzrIdDV41f4d0RGtiJBwHYjOy57YVErcUko8U7Lrm5Fid46II907cdbl6DogX7x bggjIc6fZNctz14qf7Z81+pAPgFJSRuy3g6iHl+M= From: Shradha Gupta To: linux-hyperv@vger.kernel.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Nipun Gupta , Yury Norov , Jason Gunthorpe , Jonathan Cameron , Anna-Maria Behnsen , Shradha Gupta , Kevin Tian , Long Li , Thomas Gleixner , Bjorn Helgaas , Rob Herring , Manivannan Sadhasivam , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Lorenzo Pieralisi , Dexuan Cui , Wei Liu , Haiyang Zhang , "K. Y. Srinivasan" , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Konstantin Taranov , Simon Horman , Leon Romanovsky , Maxim Levitsky , Erni Sri Satya Vennela , Peter Zijlstra , netdev@vger.kernel.org, linux-rdma@vger.kernel.org, Paul Rosswurm Cc: Shradha Gupta Subject: [PATCH v2 2/3] PCI: hv: Allow dynamic MSI-X vector allocation Date: Fri, 25 Apr 2025 03:54:19 -0700 Message-Id: <1745578459-15084-1-git-send-email-shradhagupta@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1745578407-14689-1-git-send-email-shradhagupta@linux.microsoft.com> References: <1745578407-14689-1-git-send-email-shradhagupta@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Allow dynamic MSI-X vector allocation for pci_hyperv PCI controller by adding support for the flag MSI_FLAG_PCI_MSIX_ALLOC_DYN and using pci_msix_prepare_desc() to prepare the descriptors. Signed-off-by: Shradha Gupta Reviewed-by: Haiyang Zhang --- Changes in v2: * split the patch to keep changes in PCI and pci_hyperv controller seperate * replace strings "pci vectors" by "MSI-X vectors" --- drivers/pci/controller/pci-hyperv.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/p= ci-hyperv.c index ac27bda5ba26..f2fa6bdb6bb8 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -598,7 +598,8 @@ static unsigned int hv_msi_get_int_vector(struct irq_da= ta *data) return cfg->vector; } =20 -#define hv_msi_prepare pci_msi_prepare +#define hv_msi_prepare pci_msi_prepare +#define hv_msix_prepare_desc pci_msix_prepare_desc =20 /** * hv_arch_irq_unmask() - "Unmask" the IRQ by setting its current @@ -727,6 +728,7 @@ static void hv_arch_irq_unmask(struct irq_data *data) #define FLOW_HANDLER NULL #define FLOW_NAME NULL #define hv_msi_prepare NULL +#define hv_msix_prepare_desc NULL =20 struct hv_pci_chip_data { DECLARE_BITMAP(spi_map, HV_PCI_MSI_SPI_NR); @@ -2063,6 +2065,7 @@ static struct irq_chip hv_msi_irq_chip =3D { static struct msi_domain_ops hv_msi_ops =3D { .msi_prepare =3D hv_msi_prepare, .msi_free =3D hv_msi_free, + .prepare_desc =3D hv_msix_prepare_desc, }; =20 /** @@ -2084,7 +2087,7 @@ static int hv_pcie_init_irq_domain(struct hv_pcibus_d= evice *hbus) hbus->msi_info.ops =3D &hv_msi_ops; hbus->msi_info.flags =3D (MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS | MSI_FLAG_MULTI_PCI_MSI | - MSI_FLAG_PCI_MSIX); + MSI_FLAG_PCI_MSIX | MSI_FLAG_PCI_MSIX_ALLOC_DYN); hbus->msi_info.handler =3D FLOW_HANDLER; hbus->msi_info.handler_name =3D FLOW_NAME; hbus->msi_info.data =3D hbus; --=20 2.34.1 From nobody Sat Feb 7 18:21:19 2026 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0A8C323F40C; Fri, 25 Apr 2025 10:54:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745578481; cv=none; b=A8dUliVxQerXW/VXz0WUuXgld0GhAf9/BlPvEJGWES5LicPDFK/FStP+2OXXWGyZp/MW0jwrtvkptccXHNCVBLUw9cO6O+xSIPTlr60p1pdto3+39VLX0oRABy5Ci47Tg1jWxnGWowvvk06hoDr9ZO742GwUigZucvqVgoXDGh8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745578481; c=relaxed/simple; bh=mN5AqyxO+T3uiyOtkXmn5HBh9JEOO9Gl7XTVyxwWbJE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=ZRNV96+Oy74n4ot8F/+AwhB4K98r/6MzUuia3og7oS6AGLNdq9BicCd13u8479lZcX1vjRpthGGkFzcZdL2XsAVGftpHmtBDdiLl1Sne9dx7W9vznBnrIJs4FOHtgLfb118rDUbpoqJdNQQG63ooXiHjSlc33zSpk8mg5+QOQFE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=GKiSS5ez; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="GKiSS5ez" Received: by linux.microsoft.com (Postfix, from userid 1134) id 9F29E2020955; Fri, 25 Apr 2025 03:54:39 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 9F29E2020955 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1745578479; bh=bn9bL9WMh0TAZHBtn1eCg8QX2VMwsGPB7lZ7AUoUJOQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GKiSS5ezK/IKLZ10q6GcuUv4WwICTCc3eSwVxWarpEbkD7CYL503+7qRoKTuzHRez +xJmfdmHt5g1JrIzPn5mvxVB5b7xMDCMHJLHhyD0NCoYvciJ4FawPBSzLvpsx9WE8B E8WU2F8JEsaeorcIsDAzXBOJ5iqPvhY8LEgT86s0= From: Shradha Gupta To: linux-hyperv@vger.kernel.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Nipun Gupta , Yury Norov , Jason Gunthorpe , Jonathan Cameron , Anna-Maria Behnsen , Shradha Gupta , Kevin Tian , Long Li , Thomas Gleixner , Bjorn Helgaas , Rob Herring , Manivannan Sadhasivam , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Lorenzo Pieralisi , Dexuan Cui , Wei Liu , Haiyang Zhang , "K. Y. Srinivasan" , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Konstantin Taranov , Simon Horman , Leon Romanovsky , Maxim Levitsky , Erni Sri Satya Vennela , Peter Zijlstra , netdev@vger.kernel.org, linux-rdma@vger.kernel.org, Paul Rosswurm Cc: Shradha Gupta Subject: [PATCH v2 3/3] net: mana: Allocate MSI-X vectors dynamically as required Date: Fri, 25 Apr 2025 03:54:38 -0700 Message-Id: <1745578478-15195-1-git-send-email-shradhagupta@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1745578407-14689-1-git-send-email-shradhagupta@linux.microsoft.com> References: <1745578407-14689-1-git-send-email-shradhagupta@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Currently, the MANA driver allocates MSI-X vectors statically based on MANA_MAX_NUM_QUEUES and num_online_cpus() values and in some cases ends up allocating more vectors than it needs. This is because, by this time we do not have a HW channel and do not know how many IRQs should be allocated. To avoid this, we allocate 1 MSI-X vector during the creation of HWC and after getting the value supported by hardware, dynamically add the remaining MSI-X vectors. Signed-off-by: Shradha Gupta Reviewed-by: Haiyang Zhang --- Changes in v2: * Use string 'MSI-X vectors' instead of 'pci vectors' * make skip-cpu a bool instead of int * rearrange the comment arout skip_cpu variable appropriately * update the capability bit for driver indicating dynamic IRQ allocation * enforced max line length to 80 * enforced RCT convention * initialized gic to NULL, for when there is a possibility of gic not being populated correctly --- .../net/ethernet/microsoft/mana/gdma_main.c | 323 ++++++++++++++---- include/net/mana/gdma.h | 11 +- 2 files changed, 269 insertions(+), 65 deletions(-) diff --git a/drivers/net/ethernet/microsoft/mana/gdma_main.c b/drivers/net/= ethernet/microsoft/mana/gdma_main.c index 4ffaf7588885..753b0208e574 100644 --- a/drivers/net/ethernet/microsoft/mana/gdma_main.c +++ b/drivers/net/ethernet/microsoft/mana/gdma_main.c @@ -6,6 +6,9 @@ #include #include #include +#include +#include +#include =20 #include =20 @@ -80,8 +83,15 @@ static int mana_gd_query_max_resources(struct pci_dev *p= dev) return err ? err : -EPROTO; } =20 - if (gc->num_msix_usable > resp.max_msix) - gc->num_msix_usable =3D resp.max_msix; + if (!pci_msix_can_alloc_dyn(pdev)) { + if (gc->num_msix_usable > resp.max_msix) + gc->num_msix_usable =3D resp.max_msix; + } else { + /* If dynamic allocation is enabled we have already allocated + * hwc msi + */ + gc->num_msix_usable =3D min(resp.max_msix, num_online_cpus() + 1); + } =20 if (gc->num_msix_usable <=3D 1) return -ENOSPC; @@ -462,12 +472,13 @@ static int mana_gd_register_irq(struct gdma_queue *qu= eue, const struct gdma_queue_spec *spec) { struct gdma_dev *gd =3D queue->gdma_dev; - struct gdma_irq_context *gic; + struct gdma_irq_context *gic =3D NULL; + unsigned long flags, flag_irq; struct gdma_context *gc; unsigned int msi_index; - unsigned long flags; + struct list_head *pos; struct device *dev; - int err =3D 0; + int err =3D 0, count; =20 gc =3D gd->gdma_context; dev =3D gc->dev; @@ -482,7 +493,23 @@ static int mana_gd_register_irq(struct gdma_queue *que= ue, } =20 queue->eq.msix_index =3D msi_index; - gic =3D &gc->irq_contexts[msi_index]; + + /* get the msi_index value from the list*/ + count =3D 0; + spin_lock_irqsave(&gc->irq_ctxs_lock, flag_irq); + list_for_each(pos, &gc->irq_contexts) { + if (count =3D=3D msi_index) { + gic =3D list_entry(pos, struct gdma_irq_context, + gic_list); + break; + } + + count++; + } + spin_unlock_irqrestore(&gc->irq_ctxs_lock, flag_irq); + + if (!gic) + return -1; =20 spin_lock_irqsave(&gic->lock, flags); list_add_rcu(&queue->entry, &gic->eq_list); @@ -494,11 +521,13 @@ static int mana_gd_register_irq(struct gdma_queue *qu= eue, static void mana_gd_deregiser_irq(struct gdma_queue *queue) { struct gdma_dev *gd =3D queue->gdma_dev; - struct gdma_irq_context *gic; + struct gdma_irq_context *gic =3D NULL; + unsigned long flags, flag_irq; struct gdma_context *gc; unsigned int msix_index; - unsigned long flags; + struct list_head *pos; struct gdma_queue *eq; + int count; =20 gc =3D gd->gdma_context; =20 @@ -507,7 +536,23 @@ static void mana_gd_deregiser_irq(struct gdma_queue *q= ueue) if (WARN_ON(msix_index >=3D gc->num_msix_usable)) return; =20 - gic =3D &gc->irq_contexts[msix_index]; + /* get the msi_index value from the list*/ + count =3D 0; + spin_lock_irqsave(&gc->irq_ctxs_lock, flag_irq); + list_for_each(pos, &gc->irq_contexts) { + if (count =3D=3D msix_index) { + gic =3D list_entry(pos, struct gdma_irq_context, + gic_list); + break; + } + + count++; + } + spin_unlock_irqrestore(&gc->irq_ctxs_lock, flag_irq); + + if (!gic) + return; + spin_lock_irqsave(&gic->lock, flags); list_for_each_entry_rcu(eq, &gic->eq_list, entry) { if (queue =3D=3D eq) { @@ -1288,7 +1333,8 @@ void mana_gd_free_res_map(struct gdma_resource *r) r->size =3D 0; } =20 -static int irq_setup(unsigned int *irqs, unsigned int len, int node) +static int irq_setup(unsigned int *irqs, unsigned int len, int node, + bool skip_first_cpu) { const struct cpumask *next, *prev =3D cpu_none_mask; cpumask_var_t cpus __free(free_cpumask_var); @@ -1303,9 +1349,20 @@ static int irq_setup(unsigned int *irqs, unsigned in= t len, int node) while (weight > 0) { cpumask_andnot(cpus, next, prev); for_each_cpu(cpu, cpus) { + /* + * if the CPU sibling set is to be skipped we + * just move on to the next CPUs without len-- + */ + if (unlikely(skip_first_cpu)) { + skip_first_cpu =3D false; + goto next_cpumask; + } + if (len-- =3D=3D 0) goto done; + irq_set_affinity_and_hint(*irqs++, topology_sibling_cpumask(cpu)); +next_cpumask: cpumask_andnot(cpus, cpus, topology_sibling_cpumask(cpu)); --weight; } @@ -1317,29 +1374,99 @@ static int irq_setup(unsigned int *irqs, unsigned i= nt len, int node) return 0; } =20 -static int mana_gd_setup_irqs(struct pci_dev *pdev) +static int mana_gd_setup_dyn_irqs(struct pci_dev *pdev, int nvec) { struct gdma_context *gc =3D pci_get_drvdata(pdev); - unsigned int max_queues_per_port; struct gdma_irq_context *gic; - unsigned int max_irqs, cpu; - int start_irq_index =3D 1; - int nvec, *irqs, irq; + bool skip_first_cpu =3D false; + unsigned long flags; int err, i =3D 0, j; + int *irqs, irq; =20 cpus_read_lock(); - max_queues_per_port =3D num_online_cpus(); - if (max_queues_per_port > MANA_MAX_NUM_QUEUES) - max_queues_per_port =3D MANA_MAX_NUM_QUEUES; + spin_lock_irqsave(&gc->irq_ctxs_lock, flags); + irqs =3D kmalloc_array(nvec, sizeof(int), GFP_KERNEL); + if (!irqs) { + err =3D -ENOMEM; + goto free_irq_vector; + } =20 - /* Need 1 interrupt for the Hardware communication Channel (HWC) */ - max_irqs =3D max_queues_per_port + 1; + for (i =3D 0; i < nvec; i++) { + gic =3D kcalloc(1, sizeof(struct gdma_irq_context), GFP_KERNEL); + if (!gic) { + err =3D -ENOMEM; + goto free_irq; + } + gic->handler =3D mana_gd_process_eq_events; + INIT_LIST_HEAD(&gic->eq_list); + spin_lock_init(&gic->lock); =20 - nvec =3D pci_alloc_irq_vectors(pdev, 2, max_irqs, PCI_IRQ_MSIX); - if (nvec < 0) { - cpus_read_unlock(); - return nvec; + snprintf(gic->name, MANA_IRQ_NAME_SZ, "mana_q%d@pci:%s", + i, pci_name(pdev)); + + /* one pci vector is already allocated for HWC */ + irqs[i] =3D pci_irq_vector(pdev, i + 1); + if (irqs[i] < 0) { + err =3D irqs[i]; + goto free_current_gic; + } + + err =3D request_irq(irqs[i], mana_gd_intr, 0, gic->name, gic); + if (err) + goto free_current_gic; + + list_add_tail(&gic->gic_list, &gc->irq_contexts); } + + /* + * When calling irq_setup() for dynamically added IRQs, if number of + * IRQs is more than or equal to allocated MSI-X, we need to skip the + * first CPU sibling group since they are already affinitized to HWC IRQ + */ + if (gc->num_msix_usable <=3D num_online_cpus()) + skip_first_cpu =3D true; + + err =3D irq_setup(irqs, nvec, gc->numa_node, skip_first_cpu); + if (err) + goto free_irq; + + spin_unlock_irqrestore(&gc->irq_ctxs_lock, flags); + cpus_read_unlock(); + kfree(irqs); + return 0; + +free_current_gic: + kfree(gic); +free_irq: + for (j =3D i - 1; j >=3D 0; j--) { + irq =3D pci_irq_vector(pdev, j + 1); + gic =3D list_last_entry(&gc->irq_contexts, + struct gdma_irq_context, gic_list); + irq_update_affinity_hint(irq, NULL); + free_irq(irq, gic); + list_del(&gic->gic_list); + kfree(gic); + } + kfree(irqs); +free_irq_vector: + spin_unlock_irqrestore(&gc->irq_ctxs_lock, flags); + cpus_read_unlock(); + return err; +} + +static int mana_gd_setup_irqs(struct pci_dev *pdev, int nvec) +{ + struct gdma_context *gc =3D pci_get_drvdata(pdev); + struct gdma_irq_context *gic; + int start_irq_index =3D 1; + unsigned long flags; + unsigned int cpu; + int *irqs, irq; + int err, i =3D 0, j; + + cpus_read_lock(); + spin_lock_irqsave(&gc->irq_ctxs_lock, flags); + if (nvec <=3D num_online_cpus()) start_irq_index =3D 0; =20 @@ -1349,15 +1476,12 @@ static int mana_gd_setup_irqs(struct pci_dev *pdev) goto free_irq_vector; } =20 - gc->irq_contexts =3D kcalloc(nvec, sizeof(struct gdma_irq_context), - GFP_KERNEL); - if (!gc->irq_contexts) { - err =3D -ENOMEM; - goto free_irq_array; - } - for (i =3D 0; i < nvec; i++) { - gic =3D &gc->irq_contexts[i]; + gic =3D kcalloc(1, sizeof(struct gdma_irq_context), GFP_KERNEL); + if (!gic) { + err =3D -ENOMEM; + goto free_irq; + } gic->handler =3D mana_gd_process_eq_events; INIT_LIST_HEAD(&gic->eq_list); spin_lock_init(&gic->lock); @@ -1372,22 +1496,14 @@ static int mana_gd_setup_irqs(struct pci_dev *pdev) irq =3D pci_irq_vector(pdev, i); if (irq < 0) { err =3D irq; - goto free_irq; + goto free_current_gic; } =20 if (!i) { err =3D request_irq(irq, mana_gd_intr, 0, gic->name, gic); if (err) - goto free_irq; - - /* If number of IRQ is one extra than number of online CPUs, - * then we need to assign IRQ0 (hwc irq) and IRQ1 to - * same CPU. - * Else we will use different CPUs for IRQ0 and IRQ1. - * Also we are using cpumask_local_spread instead of - * cpumask_first for the node, because the node can be - * mem only. - */ + goto free_current_gic; + if (start_irq_index) { cpu =3D cpumask_local_spread(i, gc->numa_node); irq_set_affinity_and_hint(irq, cpumask_of(cpu)); @@ -1396,39 +1512,108 @@ static int mana_gd_setup_irqs(struct pci_dev *pdev) } } else { irqs[i - start_irq_index] =3D irq; - err =3D request_irq(irqs[i - start_irq_index], mana_gd_intr, 0, - gic->name, gic); + err =3D request_irq(irqs[i - start_irq_index], + mana_gd_intr, 0, gic->name, gic); if (err) - goto free_irq; + goto free_current_gic; } + + list_add_tail(&gic->gic_list, &gc->irq_contexts); } =20 - err =3D irq_setup(irqs, (nvec - start_irq_index), gc->numa_node); + err =3D irq_setup(irqs, nvec - start_irq_index, gc->numa_node, false); if (err) goto free_irq; =20 - gc->max_num_msix =3D nvec; - gc->num_msix_usable =3D nvec; + spin_unlock_irqrestore(&gc->irq_ctxs_lock, flags); cpus_read_unlock(); kfree(irqs); return 0; =20 +free_current_gic: + kfree(gic); free_irq: for (j =3D i - 1; j >=3D 0; j--) { irq =3D pci_irq_vector(pdev, j); - gic =3D &gc->irq_contexts[j]; - + gic =3D list_last_entry(&gc->irq_contexts, + struct gdma_irq_context, gic_list); irq_update_affinity_hint(irq, NULL); free_irq(irq, gic); + list_del(&gic->gic_list); + kfree(gic); } - - kfree(gc->irq_contexts); - gc->irq_contexts =3D NULL; -free_irq_array: kfree(irqs); free_irq_vector: + spin_unlock_irqrestore(&gc->irq_ctxs_lock, flags); cpus_read_unlock(); - pci_free_irq_vectors(pdev); + return err; +} + +static int mana_gd_setup_hwc_irqs(struct pci_dev *pdev) +{ + struct gdma_context *gc =3D pci_get_drvdata(pdev); + unsigned int max_irqs, min_irqs; + int max_queues_per_port; + int nvec, err; + + if (pci_msix_can_alloc_dyn(pdev)) { + max_irqs =3D 1; + min_irqs =3D 1; + } else { + max_queues_per_port =3D num_online_cpus(); + if (max_queues_per_port > MANA_MAX_NUM_QUEUES) + max_queues_per_port =3D MANA_MAX_NUM_QUEUES; + /* Need 1 interrupt for HWC */ + max_irqs =3D max_queues_per_port + 1; + min_irqs =3D 2; + } + + nvec =3D pci_alloc_irq_vectors(pdev, min_irqs, max_irqs, PCI_IRQ_MSIX); + if (nvec < 0) + return nvec; + + err =3D mana_gd_setup_irqs(pdev, nvec); + if (err) { + pci_free_irq_vectors(pdev); + return err; + } + + gc->num_msix_usable =3D nvec; + gc->max_num_msix =3D nvec; + + return err; +} + +static int mana_gd_setup_remaining_irqs(struct pci_dev *pdev) +{ + struct gdma_context *gc =3D pci_get_drvdata(pdev); + int max_irqs, i, err =3D 0; + struct msi_map irq_map; + + if (!pci_msix_can_alloc_dyn(pdev)) + /* remain irqs are already allocated with HWC IRQ */ + return 0; + + /* allocate only remaining IRQs*/ + max_irqs =3D gc->num_msix_usable - 1; + + for (i =3D 1; i <=3D max_irqs; i++) { + irq_map =3D pci_msix_alloc_irq_at(pdev, i, NULL); + if (!irq_map.virq) { + err =3D irq_map.index; + /* caller will handle cleaning up all allocated + * irqs, after HWC is destroyed + */ + return err; + } + } + + err =3D mana_gd_setup_dyn_irqs(pdev, max_irqs); + if (err) + return err; + + gc->max_num_msix =3D gc->max_num_msix + max_irqs; + return err; } =20 @@ -1436,29 +1621,34 @@ static void mana_gd_remove_irqs(struct pci_dev *pde= v) { struct gdma_context *gc =3D pci_get_drvdata(pdev); struct gdma_irq_context *gic; - int irq, i; + struct list_head *pos, *n; + unsigned long flags; + int irq, i =3D 0; =20 if (gc->max_num_msix < 1) return; =20 - for (i =3D 0; i < gc->max_num_msix; i++) { + spin_lock_irqsave(&gc->irq_ctxs_lock, flags); + list_for_each_safe(pos, n, &gc->irq_contexts) { irq =3D pci_irq_vector(pdev, i); if (irq < 0) continue; =20 - gic =3D &gc->irq_contexts[i]; + gic =3D list_entry(pos, struct gdma_irq_context, gic_list); =20 /* Need to clear the hint before free_irq */ irq_update_affinity_hint(irq, NULL); free_irq(irq, gic); + list_del(pos); + kfree(gic); + i++; } + spin_unlock_irqrestore(&gc->irq_ctxs_lock, flags); =20 pci_free_irq_vectors(pdev); =20 gc->max_num_msix =3D 0; gc->num_msix_usable =3D 0; - kfree(gc->irq_contexts); - gc->irq_contexts =3D NULL; } =20 static int mana_gd_setup(struct pci_dev *pdev) @@ -1469,9 +1659,10 @@ static int mana_gd_setup(struct pci_dev *pdev) mana_gd_init_registers(pdev); mana_smc_init(&gc->shm_channel, gc->dev, gc->shm_base); =20 - err =3D mana_gd_setup_irqs(pdev); + err =3D mana_gd_setup_hwc_irqs(pdev); if (err) { - dev_err(gc->dev, "Failed to setup IRQs: %d\n", err); + dev_err(gc->dev, "Failed to setup IRQs for HWC creation: %d\n", + err); return err; } =20 @@ -1487,6 +1678,10 @@ static int mana_gd_setup(struct pci_dev *pdev) if (err) goto destroy_hwc; =20 + err =3D mana_gd_setup_remaining_irqs(pdev); + if (err) + goto destroy_hwc; + err =3D mana_gd_detect_devices(pdev); if (err) goto destroy_hwc; @@ -1563,6 +1758,8 @@ static int mana_gd_probe(struct pci_dev *pdev, const = struct pci_device_id *ent) gc->is_pf =3D mana_is_pf(pdev->device); gc->bar0_va =3D bar0_va; gc->dev =3D &pdev->dev; + INIT_LIST_HEAD(&gc->irq_contexts); + spin_lock_init(&gc->irq_ctxs_lock); =20 if (gc->is_pf) gc->mana_pci_debugfs =3D debugfs_create_dir("0", mana_debugfs_root); diff --git a/include/net/mana/gdma.h b/include/net/mana/gdma.h index 228603bf03f2..6ef4785c63b4 100644 --- a/include/net/mana/gdma.h +++ b/include/net/mana/gdma.h @@ -363,6 +363,7 @@ struct gdma_irq_context { spinlock_t lock; struct list_head eq_list; char name[MANA_IRQ_NAME_SZ]; + struct list_head gic_list; }; =20 struct gdma_context { @@ -373,7 +374,9 @@ struct gdma_context { unsigned int max_num_queues; unsigned int max_num_msix; unsigned int num_msix_usable; - struct gdma_irq_context *irq_contexts; + struct list_head irq_contexts; + /* Protect the irq_contexts list */ + spinlock_t irq_ctxs_lock; =20 /* L2 MTU */ u16 adapter_mtu; @@ -558,12 +561,16 @@ enum { /* Driver can handle holes (zeros) in the device list */ #define GDMA_DRV_CAP_FLAG_1_DEV_LIST_HOLES_SUP BIT(11) =20 +/* Driver supports dynamic MSI-X vector allocation */ +#define GDMA_DRV_CAP_FLAG_1_DYNAMIC_IRQ_ALLOC_SUPPORT BIT(13) + #define GDMA_DRV_CAP_FLAGS1 \ (GDMA_DRV_CAP_FLAG_1_EQ_SHARING_MULTI_VPORT | \ GDMA_DRV_CAP_FLAG_1_NAPI_WKDONE_FIX | \ GDMA_DRV_CAP_FLAG_1_HWC_TIMEOUT_RECONFIG | \ GDMA_DRV_CAP_FLAG_1_VARIABLE_INDIRECTION_TABLE_SUPPORT | \ - GDMA_DRV_CAP_FLAG_1_DEV_LIST_HOLES_SUP) + GDMA_DRV_CAP_FLAG_1_DEV_LIST_HOLES_SUP | \ + GDMA_DRV_CAP_FLAG_1_DYNAMIC_IRQ_ALLOC_SUPPORT) =20 #define GDMA_DRV_CAP_FLAGS2 0 =20 --=20 2.34.1